initial commit
This commit is contained in:
1 parent
2d023de568
commit
4018125224
6 files changed
+113
-1
No files matched your search
@@ -11,6 +11,8 @@ import type {
|
|||||||
CheckMemoryInfo,
|
CheckMemoryInfo,
|
||||||
CheckMetadata,
|
CheckMetadata,
|
||||||
CheckNetworkInterfaceInfo,
|
CheckNetworkInterfaceInfo,
|
||||||
|
GeoCheckResult,
|
||||||
|
GeoCheckTimings,
|
||||||
GotTimings,
|
GotTimings,
|
||||||
ILighthouseAudit,
|
ILighthouseAudit,
|
||||||
} from "@/types/check.js";
|
} from "@/types/check.js";
|
||||||
@@ -175,6 +177,34 @@ const auditsSchema = new Schema<CheckAudits>(
|
|||||||
{ _id: false }
|
{ _id: false }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const geoCheckTimingsSchema = new Schema<GeoCheckTimings>(
|
||||||
|
{
|
||||||
|
total: { type: Number, required: true },
|
||||||
|
dns: { type: Number },
|
||||||
|
tcp: { type: Number },
|
||||||
|
tls: { type: Number },
|
||||||
|
firstByte: { type: Number },
|
||||||
|
download: { type: Number },
|
||||||
|
},
|
||||||
|
{ _id: false }
|
||||||
|
);
|
||||||
|
|
||||||
|
const geoCheckResultSchema = new Schema<GeoCheckResult>(
|
||||||
|
{
|
||||||
|
continent: { type: String, required: true },
|
||||||
|
region: { type: String },
|
||||||
|
country: { type: String, required: true },
|
||||||
|
state: { type: String },
|
||||||
|
city: { type: String, required: true },
|
||||||
|
longitude: { type: Number, required: true },
|
||||||
|
latitude: { type: Number, required: true },
|
||||||
|
status: { type: Boolean, required: true },
|
||||||
|
statusCode: { type: Number, required: true },
|
||||||
|
timings: { type: geoCheckTimingsSchema, required: true },
|
||||||
|
},
|
||||||
|
{ _id: false }
|
||||||
|
);
|
||||||
|
|
||||||
const metadataSchema = new Schema<CheckMetadataDocument>(
|
const metadataSchema = new Schema<CheckMetadataDocument>(
|
||||||
{
|
{
|
||||||
monitorId: {
|
monitorId: {
|
||||||
@@ -281,6 +311,10 @@ const CheckSchema = new Schema<CheckDocument>(
|
|||||||
type: auditsSchema,
|
type: auditsSchema,
|
||||||
default: undefined,
|
default: undefined,
|
||||||
},
|
},
|
||||||
|
geoResults: {
|
||||||
|
type: [geoCheckResultSchema],
|
||||||
|
default: undefined,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
timestamps: true,
|
timestamps: true,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Schema, model, Types, type UpdateQuery } from "mongoose";
|
import { Schema, model, Types, type UpdateQuery } from "mongoose";
|
||||||
import type { Monitor, MonitorMatchMethod, CheckSnapshot } from "@/types/monitor.js";
|
import type { Monitor, MonitorMatchMethod, CheckSnapshot } from "@/types/monitor.js";
|
||||||
import { MonitorTypes, MonitorStatuses } from "@/types/monitor.js";
|
import { MonitorTypes, MonitorStatuses, GeoCheckLocations } from "@/types/monitor.js";
|
||||||
|
|
||||||
type CheckSnapshotDocument = Omit<CheckSnapshot, "createdAt"> & { createdAt: Date };
|
type CheckSnapshotDocument = Omit<CheckSnapshot, "createdAt"> & { createdAt: Date };
|
||||||
|
|
||||||
@@ -169,6 +169,19 @@ const MonitorSchema = new Schema<MonitorDocument>(
|
|||||||
return value && value.trim() ? value.trim() : null;
|
return value && value.trim() ? value.trim() : null;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
geoCheckEnabled: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
geoCheckLocations: {
|
||||||
|
type: [String],
|
||||||
|
enum: GeoCheckLocations,
|
||||||
|
default: [],
|
||||||
|
},
|
||||||
|
geoCheckInterval: {
|
||||||
|
type: Number,
|
||||||
|
default: 5,
|
||||||
|
},
|
||||||
recentChecks: {
|
recentChecks: {
|
||||||
type: [checkSnapshotSchema],
|
type: [checkSnapshotSchema],
|
||||||
default: [],
|
default: [],
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ import type {
|
|||||||
CheckMemoryInfo,
|
CheckMemoryInfo,
|
||||||
CheckMetadata,
|
CheckMetadata,
|
||||||
CheckNetworkInterfaceInfo,
|
CheckNetworkInterfaceInfo,
|
||||||
|
GeoCheckResult,
|
||||||
|
GeoCheckTimings,
|
||||||
GotTimings,
|
GotTimings,
|
||||||
MonitorType,
|
MonitorType,
|
||||||
} from "@/types/index.js";
|
} from "@/types/index.js";
|
||||||
@@ -165,6 +167,33 @@ class MongoChecksRepository implements IChecksRepository {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const mapGeoTimings = (timings?: GeoCheckTimings): GeoCheckTimings => ({
|
||||||
|
total: timings?.total ?? 0,
|
||||||
|
dns: timings?.dns,
|
||||||
|
tcp: timings?.tcp,
|
||||||
|
tls: timings?.tls,
|
||||||
|
firstByte: timings?.firstByte,
|
||||||
|
download: timings?.download,
|
||||||
|
});
|
||||||
|
|
||||||
|
const mapGeoResults = (geoResults?: GeoCheckResult[]): GeoCheckResult[] | undefined => {
|
||||||
|
if (!geoResults?.length) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
return geoResults.map((result) => ({
|
||||||
|
continent: result.continent ?? "",
|
||||||
|
region: result.region,
|
||||||
|
country: result.country ?? "",
|
||||||
|
state: result.state,
|
||||||
|
city: result.city ?? "",
|
||||||
|
longitude: result.longitude ?? 0,
|
||||||
|
latitude: result.latitude ?? 0,
|
||||||
|
status: result.status ?? false,
|
||||||
|
statusCode: result.statusCode ?? 0,
|
||||||
|
timings: mapGeoTimings(result.timings),
|
||||||
|
}));
|
||||||
|
};
|
||||||
|
|
||||||
const mapMetadata = (metadata: CheckDocument["metadata"]): CheckMetadata => ({
|
const mapMetadata = (metadata: CheckDocument["metadata"]): CheckMetadata => ({
|
||||||
monitorId: toStringId(metadata.monitorId),
|
monitorId: toStringId(metadata.monitorId),
|
||||||
teamId: toStringId(metadata.teamId),
|
teamId: toStringId(metadata.teamId),
|
||||||
@@ -194,6 +223,7 @@ class MongoChecksRepository implements IChecksRepository {
|
|||||||
seo: doc.seo,
|
seo: doc.seo,
|
||||||
performance: doc.performance,
|
performance: doc.performance,
|
||||||
audits: mapAudits(doc.audits),
|
audits: mapAudits(doc.audits),
|
||||||
|
geoResults: mapGeoResults(doc.geoResults),
|
||||||
__v: doc.__v ?? 0,
|
__v: doc.__v ?? 0,
|
||||||
createdAt: toDateString(doc.createdAt),
|
createdAt: toDateString(doc.createdAt),
|
||||||
updatedAt: toDateString(doc.updatedAt),
|
updatedAt: toDateString(doc.updatedAt),
|
||||||
|
|||||||
@@ -353,6 +353,9 @@ class MongoMonitorsRepository implements IMonitorsRepository {
|
|||||||
selectedDisks: doc.selectedDisks ?? [],
|
selectedDisks: doc.selectedDisks ?? [],
|
||||||
gameId: doc.gameId ?? undefined,
|
gameId: doc.gameId ?? undefined,
|
||||||
group: doc.group ?? null,
|
group: doc.group ?? null,
|
||||||
|
geoCheckEnabled: doc.geoCheckEnabled ?? false,
|
||||||
|
geoCheckLocations: doc.geoCheckLocations ?? [],
|
||||||
|
geoCheckInterval: doc.geoCheckInterval ?? 5,
|
||||||
recentChecks: (doc.recentChecks ?? []).map((check: any) => this.toCheckSnapshot(check)),
|
recentChecks: (doc.recentChecks ?? []).map((check: any) => this.toCheckSnapshot(check)),
|
||||||
createdAt: toDateString(doc.createdAt),
|
createdAt: toDateString(doc.createdAt),
|
||||||
updatedAt: toDateString(doc.updatedAt),
|
updatedAt: toDateString(doc.updatedAt),
|
||||||
@@ -408,6 +411,9 @@ class MongoMonitorsRepository implements IMonitorsRepository {
|
|||||||
selectedDisks: doc.selectedDisks ?? [],
|
selectedDisks: doc.selectedDisks ?? [],
|
||||||
gameId: doc.gameId ?? undefined,
|
gameId: doc.gameId ?? undefined,
|
||||||
group: doc.group ?? null,
|
group: doc.group ?? null,
|
||||||
|
geoCheckEnabled: doc.geoCheckEnabled ?? false,
|
||||||
|
geoCheckLocations: doc.geoCheckLocations ?? [],
|
||||||
|
geoCheckInterval: doc.geoCheckInterval ?? 5,
|
||||||
recentChecks: (doc.recentChecks ?? []).map((check: any) => this.toCheckSnapshot(check)),
|
recentChecks: (doc.recentChecks ?? []).map((check: any) => this.toCheckSnapshot(check)),
|
||||||
createdAt: toDateString(doc.createdAt),
|
createdAt: toDateString(doc.createdAt),
|
||||||
updatedAt: toDateString(doc.updatedAt),
|
updatedAt: toDateString(doc.updatedAt),
|
||||||
|
|||||||
@@ -90,6 +90,28 @@ export interface ILighthouseAudit {
|
|||||||
numericUnit?: string;
|
numericUnit?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface GeoCheckTimings {
|
||||||
|
total: number;
|
||||||
|
dns?: number;
|
||||||
|
tcp?: number;
|
||||||
|
tls?: number;
|
||||||
|
firstByte?: number;
|
||||||
|
download?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface GeoCheckResult {
|
||||||
|
continent: string;
|
||||||
|
region?: string;
|
||||||
|
country: string;
|
||||||
|
state?: string;
|
||||||
|
city: string;
|
||||||
|
longitude: number;
|
||||||
|
latitude: number;
|
||||||
|
status: boolean;
|
||||||
|
statusCode: number;
|
||||||
|
timings: GeoCheckTimings;
|
||||||
|
}
|
||||||
|
|
||||||
export interface Check {
|
export interface Check {
|
||||||
id: string;
|
id: string;
|
||||||
metadata: CheckMetadata;
|
metadata: CheckMetadata;
|
||||||
@@ -113,6 +135,7 @@ export interface Check {
|
|||||||
seo?: number;
|
seo?: number;
|
||||||
performance?: number;
|
performance?: number;
|
||||||
audits?: CheckAudits;
|
audits?: CheckAudits;
|
||||||
|
geoResults?: GeoCheckResult[];
|
||||||
__v: number;
|
__v: number;
|
||||||
createdAt: string;
|
createdAt: string;
|
||||||
updatedAt: string;
|
updatedAt: string;
|
||||||
|
|||||||
@@ -7,6 +7,9 @@ export type MonitorType = (typeof MonitorTypes)[number];
|
|||||||
export const MonitorStatuses = ["up", "down", "paused", "initializing", "maintenance", "breached"] as const;
|
export const MonitorStatuses = ["up", "down", "paused", "initializing", "maintenance", "breached"] as const;
|
||||||
export type MonitorStatus = (typeof MonitorStatuses)[number];
|
export type MonitorStatus = (typeof MonitorStatuses)[number];
|
||||||
|
|
||||||
|
export const GeoCheckLocations = ["EU", "NA", "AS", "SA", "AF", "OC"] as const;
|
||||||
|
export type GeoCheckLocation = (typeof GeoCheckLocations)[number];
|
||||||
|
|
||||||
export type MonitorMatchMethod = "equal" | "include" | "regex" | "";
|
export type MonitorMatchMethod = "equal" | "include" | "regex" | "";
|
||||||
|
|
||||||
export interface Monitor {
|
export interface Monitor {
|
||||||
@@ -43,6 +46,9 @@ export interface Monitor {
|
|||||||
selectedDisks: string[];
|
selectedDisks: string[];
|
||||||
gameId?: string;
|
gameId?: string;
|
||||||
group: string | null;
|
group: string | null;
|
||||||
|
geoCheckEnabled?: boolean;
|
||||||
|
geoCheckLocations?: GeoCheckLocation[];
|
||||||
|
geoCheckInterval?: number;
|
||||||
recentChecks: CheckSnapshot[];
|
recentChecks: CheckSnapshot[];
|
||||||
createdAt: string;
|
createdAt: string;
|
||||||
updatedAt: string;
|
updatedAt: string;
|
||||||
|
|||||||
Reference in new issue
Block a user