UNPKG

@syngrisi/syngrisi

Version:
1,415 lines (1,371 loc) 39 kB
var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __esm = (fn, res) => function __init() { return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res; }; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/server/models/plugins/paginate.plugin.ts var paginate, paginate_plugin_default; var init_paginate_plugin = __esm({ "src/server/models/plugins/paginate.plugin.ts"() { "use strict"; paginate = (schema) => { schema.statics.paginate = async function(filter, options) { let sort; if (options.sortBy) { const sortingCriteria = []; let primaryOrder = "desc"; options.sortBy.split(",").forEach((sortOption, index) => { const [key, order] = sortOption.split(":"); if (index === 0) primaryOrder = order || "asc"; sortingCriteria.push((order === "desc" ? "-" : "") + key); }); if (!sortingCriteria.some((s) => s === "_id" || s === "-_id")) { sortingCriteria.push((primaryOrder === "desc" ? "-" : "") + "_id"); } sort = sortingCriteria.join(" "); } else { sort = { _id: -1 }; } const limit = options.limit && parseInt(options.limit.toString(), 10) >= 0 ? parseInt(options.limit.toString(), 10) : 10; const page = options.page && parseInt(options.page.toString(), 10) > 0 ? parseInt(options.page.toString(), 10) : 1; const skip = (page - 1) * limit; const countStrategy = options.countStrategy ?? (filter && Object.keys(filter).length === 0 ? "estimated" : "exact"); const countPromise = countStrategy === "estimated" ? this.estimatedDocumentCount().exec() : this.countDocuments(filter).exec(); let docsPromise = this.find(filter).sort(sort).skip(skip).limit(limit); if (options.populate) { options.populate.split(",").forEach((populateOption) => { docsPromise = docsPromise.populate( populateOption.split(".").reverse().reduce((a, b) => ({ path: b, populate: a })) ); }); } docsPromise = docsPromise.exec(); return Promise.all([countPromise, docsPromise]).then((values) => { const [totalResults, results] = values; const totalPages = Math.ceil(totalResults / limit); const result = { results, page, limit, totalPages, totalResults, timestamp: Number(Date.now() + String(process.hrtime()[1]).slice(3, 6)) }; return Promise.resolve(result); }); }; }; paginate_plugin_default = paginate; } }); // src/server/models/plugins/toJSON.plugin.ts var deleteAtPath, toJSON, toJSON_plugin_default; var init_toJSON_plugin = __esm({ "src/server/models/plugins/toJSON.plugin.ts"() { "use strict"; deleteAtPath = (obj, path, index) => { if (index === path.length - 1) { delete obj[path[index]]; return; } deleteAtPath(obj[path[index]], path, index + 1); }; toJSON = (schema) => { let transform; if (schema.options.toJSON && schema.options.toJSON.transform) { transform = schema.options.toJSON.transform; } schema.options.toJSON = Object.assign(schema.options.toJSON || {}, { transform(doc, ret, options) { Object.keys(schema.paths).forEach((path) => { if (schema.paths[path].options && schema.paths[path].options.private) { deleteAtPath(ret, path.split("."), 0); } }); ret.id = ret._id.toString(); delete ret.__v; delete ret.createdAt; delete ret.updatedAt; if (transform) { return transform(doc, ret, options); } } }); }; toJSON_plugin_default = toJSON; } }); // src/server/utils/pick.ts var init_pick = __esm({ "src/server/utils/pick.ts"() { "use strict"; } }); // src/server/utils/isJSON.ts var isJSON, isJSON_default; var init_isJSON = __esm({ "src/server/utils/isJSON.ts"() { "use strict"; isJSON = (text) => { if (!text) return false; const isValid = /^[\],:{}\s]*$/.test( text.replace(/\\["\\\/bfnrtu]/g, "@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, "]").replace(/(?:^|:|,)(?:\s*\[)+/g, "") ); return isValid; }; isJSON_default = isJSON; } }); // src/server/utils/catchAsync.ts var init_catchAsync = __esm({ "src/server/utils/catchAsync.ts"() { "use strict"; } }); // src/server/utils/dateToISO8601.ts var init_dateToISO8601 = __esm({ "src/server/utils/dateToISO8601.ts"() { "use strict"; } }); // src/server/utils/ProgressBar.ts var init_ProgressBar = __esm({ "src/server/utils/ProgressBar.ts"() { "use strict"; } }); // src/server/utils/ApiError.ts var init_ApiError = __esm({ "src/server/utils/ApiError.ts"() { "use strict"; } }); // src/server/utils/removeEmptyProperties.ts var init_removeEmptyProperties = __esm({ "src/server/utils/removeEmptyProperties.ts"() { "use strict"; } }); // src/server/utils/deserializeIfJSON.ts import mongoose from "mongoose"; var EJSON, EXTENDED_JSON_KEYS, containsExtendedJsonMarkers, deserializeIfJSON, deserializeIfJSON_default; var init_deserializeIfJSON = __esm({ "src/server/utils/deserializeIfJSON.ts"() { "use strict"; init_utils(); ({ EJSON } = mongoose.mongo.BSON); EXTENDED_JSON_KEYS = [ "$oid", "$date", "$numberInt", "$numberLong", "$numberDouble", "$numberDecimal", "$regularExpression", "$binary", "$timestamp" ]; containsExtendedJsonMarkers = (text) => EXTENDED_JSON_KEYS.some((marker) => text.includes(`"${marker}"`)); deserializeIfJSON = (text) => { if (isJSON_default(text)) { if (containsExtendedJsonMarkers(text)) { return EJSON.parse(text) || void 0; } return JSON.parse(text) || void 0; } return text; }; deserializeIfJSON_default = deserializeIfJSON; } }); // src/server/utils/prettyCheckParams.ts var init_prettyCheckParams = __esm({ "src/server/utils/prettyCheckParams.ts"() { "use strict"; } }); // src/server/utils/waitUntil.ts var init_waitUntil = __esm({ "src/server/utils/waitUntil.ts"() { "use strict"; } }); // src/server/utils/imageUtils.ts var init_imageUtils = __esm({ "src/server/utils/imageUtils.ts"() { "use strict"; } }); // src/server/utils/paramsGuard.ts var init_paramsGuard = __esm({ "src/server/utils/paramsGuard.ts"() { "use strict"; } }); // src/server/utils/ident.ts var init_ident = __esm({ "src/server/utils/ident.ts"() { "use strict"; } }); // src/server/utils/buildIdentObject.ts var init_buildIdentObject = __esm({ "src/server/utils/buildIdentObject.ts"() { "use strict"; init_ident(); } }); // src/server/utils/calculateAcceptedStatus.ts var init_calculateAcceptedStatus = __esm({ "src/server/utils/calculateAcceptedStatus.ts"() { "use strict"; init_models(); } }); // src/server/utils/subDays.ts var init_subDays = __esm({ "src/server/utils/subDays.ts"() { "use strict"; } }); // src/server/utils/errMsg.ts var init_errMsg = __esm({ "src/server/utils/errMsg.ts"() { "use strict"; } }); // src/server/utils/hash.ts import { createHash, randomUUID } from "crypto"; var init_hash = __esm({ "src/server/utils/hash.ts"() { "use strict"; } }); // src/server/utils/stringTable.ts var init_stringTable = __esm({ "src/server/utils/stringTable.ts"() { "use strict"; } }); // src/server/utils/colors.ts var init_colors = __esm({ "src/server/utils/colors.ts"() { "use strict"; } }); // src/server/utils/httpStatus.ts var init_httpStatus = __esm({ "src/server/utils/httpStatus.ts"() { "use strict"; } }); // src/server/utils/cookieParser.ts var init_cookieParser = __esm({ "src/server/utils/cookieParser.ts"() { "use strict"; } }); // src/server/utils/index.ts var init_utils = __esm({ "src/server/utils/index.ts"() { "use strict"; init_pick(); init_isJSON(); init_catchAsync(); init_dateToISO8601(); init_ProgressBar(); init_ApiError(); init_removeEmptyProperties(); init_deserializeIfJSON(); init_prettyCheckParams(); init_waitUntil(); init_imageUtils(); init_paramsGuard(); init_buildIdentObject(); init_calculateAcceptedStatus(); init_ident(); init_subDays(); init_errMsg(); init_hash(); init_stringTable(); init_colors(); init_httpStatus(); init_cookieParser(); } }); // src/server/models/plugins/paginateDistinct.plugin.ts var init_paginateDistinct_plugin = __esm({ "src/server/models/plugins/paginateDistinct.plugin.ts"() { "use strict"; init_utils(); } }); // src/server/models/plugins/index.ts var init_plugins = __esm({ "src/server/models/plugins/index.ts"() { "use strict"; init_paginate_plugin(); init_toJSON_plugin(); init_paginateDistinct_plugin(); } }); // src/server/models/Check.model.ts import mongoose2, { Schema } from "mongoose"; var CheckSchema, Check, Check_model_default; var init_Check_model = __esm({ "src/server/models/Check.model.ts"() { "use strict"; init_plugins(); CheckSchema = new Schema({ name: { type: String, required: [true, 'CheckSchema: The "name" field must be required'] }, test: { type: Schema.Types.ObjectId, ref: "VRSTest", required: [true, 'CheckSchema: The "test" field must be required'] }, suite: { type: Schema.Types.ObjectId, ref: "VRSSuite", required: [true, 'CheckSchema: The "suite" field must be required'] }, app: { type: Schema.Types.ObjectId, ref: "VRSApp", required: [true, 'CheckSchema: The "app" field must be required'] }, branch: { type: String }, realBaselineId: { type: Schema.Types.ObjectId, ref: "VRSBaseline" }, baselineId: { type: Schema.Types.ObjectId, ref: "VRSSnapshot" }, actualSnapshotId: { type: Schema.Types.ObjectId, ref: "VRSSnapshot" }, diffId: { type: Schema.Types.ObjectId, ref: "VRSSnapshot" }, createdDate: { type: Date, required: true, default: Date.now }, updatedDate: { type: Date }, status: { type: [{ type: String, enum: { values: ["new", "pending", "approved", "running", "passed", "failed", "aborted"], message: "status is required" } }], default: ["new"] }, browserName: { type: String }, browserVersion: { type: String }, browserFullVersion: { type: String }, viewport: { type: String }, os: { type: String }, domDump: { type: String }, result: { type: String, default: "{}" }, run: { type: Schema.Types.ObjectId }, markedAs: { type: String, enum: ["bug", "accepted"] }, markedDate: { type: Date }, markedById: { type: Schema.Types.ObjectId, ref: "VRSUser" }, markedByUsername: { type: String }, markedBugComment: { type: String }, creatorId: { type: Schema.Types.ObjectId, ref: "VRSUser" }, creatorUsername: { type: String }, failReasons: { type: [String] }, vOffset: { type: String }, topStablePixels: { type: String }, toleranceThreshold: { type: Number, min: 0, max: 100 }, meta: { type: Object } }); CheckSchema.plugin(toJSON_plugin_default); CheckSchema.plugin(paginate_plugin_default); Check = mongoose2.model("VRSCheck", CheckSchema); Check_model_default = Check; } }); // src/server/models/Log.model.ts import mongoose3, { Schema as Schema2 } from "mongoose"; var LogSchema, Log, Log_model_default; var init_Log_model = __esm({ "src/server/models/Log.model.ts"() { "use strict"; init_plugins(); LogSchema = new Schema2({ timestamp: { type: Date }, level: { type: String }, message: { type: String }, meta: { type: Object }, hostname: { type: Object } }); LogSchema.plugin(toJSON_plugin_default); LogSchema.plugin(paginate_plugin_default); Log = mongoose3.model("VRSLog", LogSchema); Log_model_default = Log; } }); // src/server/models/App.model.ts import mongoose4, { Schema as Schema3 } from "mongoose"; var AppSchema, App, App_model_default; var init_App_model = __esm({ "src/server/models/App.model.ts"() { "use strict"; init_plugins(); AppSchema = new Schema3({ name: { type: String, default: "Others", unique: true, required: [true, 'AppSchema: The "name" field must be required'] }, description: { type: String }, version: { type: String }, updatedDate: { type: Date }, createdDate: { type: Date }, meta: { type: Object } }); AppSchema.plugin(paginate_plugin_default); AppSchema.plugin(toJSON_plugin_default); App = mongoose4.model("VRSApp", AppSchema); App_model_default = App; } }); // src/server/models/Snapshot.model.ts import mongoose5, { Schema as Schema4 } from "mongoose"; var SnapshotSchema, Snapshot, Snapshot_model_default; var init_Snapshot_model = __esm({ "src/server/models/Snapshot.model.ts"() { "use strict"; init_plugins(); SnapshotSchema = new Schema4({ name: { type: String, required: [true, 'SnapshotSchema: The "name" field must be required'] }, path: { type: String }, filename: { type: String }, imghash: { type: String, required: [true, 'SnapshotSchema: The "imghash" field must be required'] }, createdDate: { type: Date, default: Date.now }, vOffset: { type: Number }, hOffset: { type: Number } }); SnapshotSchema.plugin(toJSON_plugin_default); SnapshotSchema.plugin(paginate_plugin_default); Snapshot = mongoose5.model("VRSSnapshot", SnapshotSchema); Snapshot_model_default = Snapshot; } }); // src/server/models/AppSettings.model.ts import mongoose6, { Schema as Schema5 } from "mongoose"; var AppSettingsSchema, AppSettings, AppSettings_model_default; var init_AppSettings_model = __esm({ "src/server/models/AppSettings.model.ts"() { "use strict"; init_plugins(); AppSettingsSchema = new Schema5({ name: { type: String, unique: true, required: [true, 'AppSettingsSchema: The "name" field must be required'] }, label: { type: String, required: [true, 'AppSettingsSchema: The "label" field must be required'] }, description: { type: String }, type: { type: String, required: [true, 'AppSettingsSchema: The "type" field must be required'] }, value: { type: Schema5.Types.Mixed, required: [true, 'AppSettingsSchema: The "value" field must be required'] }, env_variable: { type: String }, enabled: { type: Boolean } }); AppSettingsSchema.plugin(toJSON_plugin_default); AppSettings = mongoose6.model("VRSAppSettings", AppSettingsSchema); AppSettings_model_default = AppSettings; } }); // src/server/models/Suite.model.ts import mongoose7, { Schema as Schema6 } from "mongoose"; var SuiteSchema, Suite, Suite_model_default; var init_Suite_model = __esm({ "src/server/models/Suite.model.ts"() { "use strict"; init_plugins(); SuiteSchema = new Schema6({ name: { type: String, default: "Others", unique: true, required: [true, 'SuiteSchema: The "name" field must be required'] }, tags: { type: [String] }, app: { type: Schema6.Types.ObjectId, ref: "VRSApp", required: [true, 'SuiteSchema: The "app" field must be required'] }, description: { type: String }, updatedDate: { type: Date, default: Date.now }, createdDate: { type: Date }, meta: { type: Object } }); SuiteSchema.plugin(paginate_plugin_default); SuiteSchema.plugin(toJSON_plugin_default); Suite = mongoose7.model("VRSSuite", SuiteSchema); Suite_model_default = Suite; } }); // src/server/models/Run.model.ts import mongoose8, { Schema as Schema7 } from "mongoose"; var RunSchema, Run, Run_model_default; var init_Run_model = __esm({ "src/server/models/Run.model.ts"() { "use strict"; init_plugins(); RunSchema = new Schema7({ name: { type: String, required: [true, 'RunSchema: The "name" field must be required'] }, app: { type: Schema7.Types.ObjectId, ref: "VRSApp", required: [true, 'RunSchema: The "app" field must be required'] }, ident: { type: String, unique: true, required: [true, 'RunSchema: The "ident" field must be required'] }, description: { type: String }, updatedDate: { type: Date, default: Date.now }, createdDate: { type: Date }, parameters: { type: [String] }, meta: { type: Object } }); RunSchema.plugin(paginate_plugin_default); RunSchema.plugin(toJSON_plugin_default); Run = mongoose8.model("VRSRun", RunSchema); Run_model_default = Run; } }); // src/server/models/User.model.ts import mongoose9, { Schema as Schema8 } from "mongoose"; import plm from "passport-local-mongoose"; var passportLocalMongoose, UserSchema, User, User_model_default; var init_User_model = __esm({ "src/server/models/User.model.ts"() { "use strict"; init_plugins(); passportLocalMongoose = plm.default || plm; UserSchema = new Schema8({ username: { type: String, unique: true, required: [true, 'UserSchema: The "username" field must be required'] }, firstName: { type: String, required: [true, 'UserSchema: The "firstName" field must be required'] }, lastName: { type: String, required: [true, 'UserSchema: The "lastName" field must be required'] }, role: { type: String, enum: ["admin", "reviewer", "user"], required: [true, 'UserSchema: The "role" field must be required'] }, provider: { type: String, default: "local" }, providerId: { type: String }, password: { type: String }, token: { type: String }, apiKey: { type: String }, authSource: { type: String, enum: ["local", "jwt", "ldap", "api"], default: "local" }, createdDate: { type: Date }, updatedDate: { type: Date }, expiration: { type: Date }, meta: { type: Object } }); UserSchema.statics.isEmailTaken = async function(username, excludeUserId) { const user = await this.findOne({ username, _id: { $ne: excludeUserId } }); return !!user; }; UserSchema.plugin(toJSON_plugin_default); UserSchema.plugin(paginate_plugin_default); UserSchema.plugin(passportLocalMongoose, { hashField: "password" }); User = mongoose9.model("VRSUser", UserSchema); User_model_default = User; } }); // src/server/models/Baseline.model.ts import mongoose10, { Schema as Schema9 } from "mongoose"; var BaselineSchema, Baseline, Baseline_model_default; var init_Baseline_model = __esm({ "src/server/models/Baseline.model.ts"() { "use strict"; init_plugins(); BaselineSchema = new Schema9({ snapshootId: { type: Schema9.Types.ObjectId, ref: "VRSSnapshot" }, name: { type: String, required: [true, 'VRSBaselineSchema: The "name" field must be required'] }, app: { type: Schema9.Types.ObjectId, ref: "VRSApp", required: [true, 'VRSBaselineSchema: The "app" field must be required'] }, branch: { type: String }, browserName: { type: String }, browserVersion: { type: String }, browserFullVersion: { type: String }, viewport: { type: String }, os: { type: String }, markedAs: { type: String, enum: ["bug", "accepted"] }, lastMarkedDate: { type: Date }, createdDate: { type: Date }, updatedDate: { type: Date }, markedById: { type: Schema9.Types.ObjectId, ref: "VRSUser" }, markedByUsername: { type: String }, ignoreRegions: { type: String }, boundRegions: { type: String }, matchType: { type: String, enum: ["antialiasing", "nothing", "colors"] }, toleranceThreshold: { type: Number, default: 0, min: 0, max: 100 }, meta: { type: Object } }); BaselineSchema.set("autoIndex", false); BaselineSchema.plugin(toJSON_plugin_default); BaselineSchema.plugin(paginate_plugin_default); BaselineSchema.index({ name: 1, app: 1, branch: 1, browserName: 1, viewport: 1, os: 1, snapshootId: 1 }, { unique: true, name: "baseline_ident_snapshot_idx" }); Baseline = mongoose10.model("VRSBaseline", BaselineSchema); Baseline_model_default = Baseline; } }); // src/server/models/Test.model.ts import mongoose11, { Schema as Schema10 } from "mongoose"; var TestSchema, Test, Test_model_default; var init_Test_model = __esm({ "src/server/models/Test.model.ts"() { "use strict"; init_plugins(); init_utils(); TestSchema = new Schema10( { name: { type: String, required: "TestSchema: the test name is empty" }, description: { type: String }, status: { type: String }, browserName: { type: String }, browserVersion: { type: String }, branch: { type: String }, tags: { type: [String] }, viewport: { type: String }, calculatedViewport: { type: String }, os: { type: String }, app: { type: Schema10.Types.ObjectId, ref: "VRSApp", required: [true, 'TestSchema: The "app" field must be required'] }, blinking: { type: Number, default: 0 }, updatedDate: { type: Date }, startDate: { type: Date }, checks: [ { type: mongoose11.Schema.Types.ObjectId, ref: "VRSCheck" } ], suite: { type: Schema10.Types.ObjectId, ref: "VRSSuite" }, run: { type: Schema10.Types.ObjectId, ref: "VRSRun" }, markedAs: { type: String, enum: ["Bug", "Accepted", "Unaccepted", "Partially"] }, creatorId: { type: Schema10.Types.ObjectId, ref: "VRSUser" }, creatorUsername: { type: String }, meta: { type: Object } }, { strictQuery: true } ); TestSchema.plugin(toJSON_plugin_default); TestSchema.plugin(paginate_plugin_default); TestSchema.statics.paginateDistinct = async function(filter, options) { let sort = { _id: -1 }; if (options.sortBy) { sort = {}; options.sortBy.split(",").forEach((sortOption) => { const [key, order] = sortOption.split(":"); sort[key] = order === "desc" ? -1 : 1; }); } let limit = options.limit && parseInt(options.limit.toString(), 10) >= 0 ? parseInt(options.limit.toString(), 10) : 10; limit = limit === 0 ? Number.MAX_SAFE_INTEGER : limit; const page = options.page && parseInt(options.page.toString(), 10) > 0 ? parseInt(options.page.toString(), 10) : 1; const skip = (page - 1) * limit; const groupAggregateObj = { $group: { _id: `$${options.field}` } }; const parsedFilter = typeof filter?.filter === "string" ? deserializeIfJSON_default(filter.filter) || {} : {}; const documentsCount = (await this.aggregate([{ $match: parsedFilter }, groupAggregateObj]).exec()).length; const aggregatedDocs = (await this.aggregate([ { $match: parsedFilter }, groupAggregateObj, { $sort: sort }, { $skip: skip }, { $limit: limit } ])).filter((x) => x._id).map((x) => { const fieldValue = options.field ? x[options.field] : void 0; if (Array.isArray(fieldValue) && fieldValue.length > 0) { return fieldValue[0]; } return { name: x._id }; }); const totalPages = Math.ceil(documentsCount / limit); return { results: aggregatedDocs, page, limit, totalPages, totalResults: documentsCount, timestamp: Date.now() }; }; Test = mongoose11.model("VRSTest", TestSchema); Test_model_default = Test; } }); // src/server/models/Webhook.model.ts import mongoose12, { Schema as Schema11 } from "mongoose"; var WebhookSchema, Webhook, Webhook_model_default; var init_Webhook_model = __esm({ "src/server/models/Webhook.model.ts"() { "use strict"; init_plugins(); WebhookSchema = new Schema11({ url: { type: String, required: [true, 'WebhookSchema: The "url" field must be required'] }, events: { type: [String], default: ["check.updated", "check.created"] }, secret: { type: String }, createdDate: { type: Date, default: Date.now }, meta: { type: Object } }); WebhookSchema.plugin(paginate_plugin_default); WebhookSchema.plugin(toJSON_plugin_default); Webhook = mongoose12.model("VRSWebhook", WebhookSchema); Webhook_model_default = Webhook; } }); // src/server/models/ShareToken.model.ts import mongoose13, { Schema as Schema12 } from "mongoose"; var ShareTokenSchema, ShareToken, ShareToken_model_default; var init_ShareToken_model = __esm({ "src/server/models/ShareToken.model.ts"() { "use strict"; init_plugins(); ShareTokenSchema = new Schema12({ checkId: { type: Schema12.Types.ObjectId, ref: "VRSCheck", required: [true, 'ShareTokenSchema: The "checkId" field is required'], index: true }, token: { type: String, required: [true, 'ShareTokenSchema: The "token" field is required'], unique: true, index: true }, createdById: { type: Schema12.Types.ObjectId, ref: "VRSUser", required: [true, 'ShareTokenSchema: The "createdById" field is required'] }, createdByUsername: { type: String, required: [true, 'ShareTokenSchema: The "createdByUsername" field is required'] }, createdDate: { type: Date, required: true, default: Date.now }, isRevoked: { type: Boolean, default: false }, revokedDate: { type: Date }, revokedById: { type: Schema12.Types.ObjectId, ref: "VRSUser" }, revokedByUsername: { type: String } }); ShareTokenSchema.plugin(toJSON_plugin_default); ShareTokenSchema.plugin(paginate_plugin_default); ShareToken = mongoose13.model("VRSShareToken", ShareTokenSchema); ShareToken_model_default = ShareToken; } }); // src/server/models/DomSnapshot.model.ts import mongoose14, { Schema as Schema13 } from "mongoose"; var DomSnapshotSchema, DomSnapshot, DomSnapshot_model_default; var init_DomSnapshot_model = __esm({ "src/server/models/DomSnapshot.model.ts"() { "use strict"; init_plugins(); DomSnapshotSchema = new Schema13({ checkId: { type: Schema13.Types.ObjectId, ref: "VRSCheck", required: [true, 'DomSnapshotSchema: The "checkId" field is required'], index: true }, baselineId: { type: Schema13.Types.ObjectId, ref: "VRSBaseline", index: true }, type: { type: String, enum: ["actual", "baseline"], required: [true, 'DomSnapshotSchema: The "type" field is required'] }, filename: { type: String, required: [true, 'DomSnapshotSchema: The "filename" field is required'] }, hash: { type: String, required: [true, 'DomSnapshotSchema: The "hash" field is required'], index: true }, compressed: { type: Boolean, default: false }, originalSize: { type: Number, required: [true, 'DomSnapshotSchema: The "originalSize" field is required'] }, compressedSize: { type: Number }, createdDate: { type: Date, default: Date.now } }); DomSnapshotSchema.index({ checkId: 1, type: 1 }); DomSnapshotSchema.index({ baselineId: 1, type: 1 }); DomSnapshotSchema.plugin(toJSON_plugin_default); DomSnapshotSchema.plugin(paginate_plugin_default); DomSnapshot = mongoose14.model("VRSDomSnapshot", DomSnapshotSchema); DomSnapshot_model_default = DomSnapshot; } }); // src/server/models/PluginSettings.model.ts import mongoose15, { Schema as Schema14 } from "mongoose"; var PluginSettingSchemaDefinition, PluginSettingsSchema, PluginSettings, PluginSettings_model_default; var init_PluginSettings_model = __esm({ "src/server/models/PluginSettings.model.ts"() { "use strict"; init_plugins(); PluginSettingSchemaDefinition = new Schema14({ key: { type: String, required: true }, label: { type: String, required: true }, description: { type: String }, type: { type: String, enum: ["string", "number", "boolean", "select", "password"], required: true }, defaultValue: { type: Schema14.Types.Mixed }, envVariable: { type: String }, options: [{ value: String, label: String }], required: { type: Boolean, default: false } }, { _id: false }); PluginSettingsSchema = new Schema14({ pluginName: { type: String, unique: true, required: [true, "PluginSettings: pluginName is required"], index: true }, displayName: { type: String, required: [true, "PluginSettings: displayName is required"] }, description: { type: String }, enabled: { type: Boolean, default: false }, settings: { type: Schema14.Types.Mixed, default: {} }, settingsSchema: { type: [PluginSettingSchemaDefinition], default: [] } }, { timestamps: true }); PluginSettingsSchema.plugin(toJSON_plugin_default); PluginSettingsSchema.statics.getEffectiveConfig = async function(pluginName, envPrefix = "SYNGRISI_PLUGIN_") { const doc = await this.findOne({ pluginName }); const envPluginKey = pluginName.toUpperCase().replace(/-/g, "_"); const envEnabledKey = `${envPrefix}${envPluginKey}_ENABLED`; const envEnabled = process.env[envEnabledKey]?.toLowerCase() === "true"; const dbEnabled = doc?.enabled; const enabled = doc ? dbEnabled : envEnabled; const config = {}; const schema = doc?.settingsSchema || []; if (schema.length === 0 && doc?.settings && Object.keys(doc.settings).length > 0) { for (const [key, value] of Object.entries(doc.settings)) { config[key] = { value, source: "db" }; } return { config, enabled }; } for (const field of schema) { const envKey = field.envVariable || `${envPrefix}${envPluginKey}_${field.key.toUpperCase()}`; const envValue = process.env[envKey]; const dbValue = doc?.settings?.[field.key]; if (dbValue !== void 0) { config[field.key] = { value: dbValue, source: "db" }; } else if (envValue !== void 0) { let parsedValue = envValue; if (field.type === "boolean") { parsedValue = envValue.toLowerCase() === "true"; } else if (field.type === "number") { parsedValue = parseFloat(envValue); } config[field.key] = { value: parsedValue, source: "env" }; } else if (field.defaultValue !== void 0) { config[field.key] = { value: field.defaultValue, source: "default" }; } } return { config, enabled }; }; PluginSettingsSchema.statics.upsertSettings = async function(pluginName, updates) { return this.findOneAndUpdate( { pluginName }, { $set: updates }, { upsert: true, new: true, runValidators: true } ); }; PluginSettings = mongoose15.model( "VRSPluginSettings", PluginSettingsSchema ); PluginSettings_model_default = PluginSettings; } }); // src/server/models/index.ts var models_exports = {}; __export(models_exports, { App: () => App_model_default, AppSettings: () => AppSettings_model_default, Baseline: () => Baseline_model_default, Check: () => Check_model_default, DomSnapshot: () => DomSnapshot_model_default, Log: () => Log_model_default, PluginSettings: () => PluginSettings_model_default, Run: () => Run_model_default, ShareToken: () => ShareToken_model_default, Snapshot: () => Snapshot_model_default, Suite: () => Suite_model_default, Test: () => Test_model_default, User: () => User_model_default, Webhook: () => Webhook_model_default }); var init_models = __esm({ "src/server/models/index.ts"() { "use strict"; init_Check_model(); init_Log_model(); init_App_model(); init_Snapshot_model(); init_AppSettings_model(); init_Suite_model(); init_Run_model(); init_User_model(); init_Baseline_model(); init_Test_model(); init_Webhook_model(); init_ShareToken_model(); init_DomSnapshot_model(); init_PluginSettings_model(); } }); // src/tasks/lib/index.ts var lib_exports = {}; __export(lib_exports, { App: () => App_model_default, Baseline: () => Baseline_model_default, Check: () => Check_model_default, Log: () => Log_model_default, Run: () => Run_model_default, Snapshot: () => Snapshot_model_default, Suite: () => Suite_model_default, Test: () => Test_model_default, User: () => User_model_default }); var init_lib = __esm({ "src/tasks/lib/index.ts"() { "use strict"; init_Check_model(); init_Log_model(); init_App_model(); init_Snapshot_model(); init_Suite_model(); init_Run_model(); init_User_model(); init_Baseline_model(); init_Test_model(); } }); // src/tasks/migrations/2.0.migration.ts init_models(); var utils = (init_lib(), __toCommonJS(lib_exports)); var { Check: Check2, Test: Test2, Run: Run2, Suite: Suite2 } = (init_lib(), __toCommonJS(lib_exports)); async function task() { await utils.runMongoCode(async () => { try { console.log("\nStage: 0"); const checks = await Check2.find({}); for (const check of checks) { const testId = check.test; const test = await Test2.findOne({ _id: testId }); if (test && testId && !test.checks.map((x) => x.toString()).includes(check?._id.toString())) { const newChecksArray = test.checks || []; newChecksArray.push(check._id); await test.update({ _id: test._id }, { $set: { checks: newChecksArray } }); await test.save(); process.stdout.write("."); } else { process.stdout.write("x"); } } console.log("\nStage: 1"); const tests = await Test2.find({}); for (const test of tests) { const firstCheckId = test.checks[0]; if (firstCheckId) { const firstCheck = await Check2.findOne({ _id: test.checks[0] }); if (firstCheck) { const { suite } = firstCheck; if (suite) { test.suite = suite; await Test2.update({ _id: test._id }, { $set: { suite } }); } } } else { process.stdout.write("x"); } process.stdout.write("."); } console.log("\nStage: 2"); for (const x of tests) { const appId = x.app; await Run2.update({ _id: x.run }, { $set: { app: appId } }); await Suite2.update({ _id: x.suite }, { $set: { app: appId } }); process.stdout.write("."); } console.log("\nStage: 3"); const suites = await Suite2.find({}); for (const x of suites) { await Suite2.update({ _id: x._id }, { $set: { createdDate: x._id.getTimestamp() } }); process.stdout.write("+"); } const runs = await Run2.find({}); for (const x of runs) { await Run2.update({ _id: x._id }, { $set: { createdDate: x._id.getTimestamp() } }); process.stdout.write(">"); } } catch (err) { console.error(err); } finally { console.log("\nDone"); } }); } task(); //# sourceMappingURL=2.0.migration.js.map