UNPKG

@syngrisi/syngrisi

Version:
908 lines (891 loc) 26.3 kB
"use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; 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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); 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 = []; options.sortBy.split(",").forEach((sortOption) => { const [key, order] = sortOption.split(":"); sortingCriteria.push((order === "desc" ? "-" : "") + key); }); 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 countPromise = 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/models/plugins/paginateDistinct.plugin.ts var import_bson, paginateDistinct, paginateDistinct_plugin_default; var init_paginateDistinct_plugin = __esm({ "src/server/models/plugins/paginateDistinct.plugin.ts"() { "use strict"; import_bson = require("bson"); paginateDistinct = (schema) => { schema.statics.paginateDistinct = async function(filter, options) { let sort; if (options.sortBy) { options.sortBy.split(",").forEach((sortOption) => { const [key, order] = sortOption.split(":"); sort[key] = order === "desc" ? -1 : 1; }); } else { sort = { _id: -1 }; } let limit = options.limit && parseInt(options.limit.toString(), 10) >= 0 ? parseInt(options.limit.toString(), 10) : 10; limit = limit === 0 ? 9007199254740991 : 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 documentsCount = (await this.aggregate([groupAggregateObj]).exec()).length; const aggregateArr = [ { $match: import_bson.EJSON.parse(filter.filter || "{}") }, groupAggregateObj, { $sort: sort }, { $skip: skip }, { $limit: limit } ]; const aggregatedDocs = (await this.aggregate(aggregateArr)).filter((x) => x._id).map((x) => { if (x[options.field]) { return x[options.field][0]; } return { name: x._id }; }); return Promise.all([documentsCount, aggregatedDocs]).then((values) => { const [totalResults, results] = values; const totalPages = Math.ceil(totalResults / limit); const result = { results, page, limit, totalPages, totalResults, timestamp: (/* @__PURE__ */ new Date()).getTime() }; return Promise.resolve(result); }); }; }; paginateDistinct_plugin_default = paginateDistinct; } }); // 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 var import_mongoose, CheckSchema, Check, Check_model_default; var init_Check_model = __esm({ "src/server/models/Check.model.ts"() { "use strict"; import_mongoose = __toESM(require("mongoose")); init_plugins(); CheckSchema = new import_mongoose.Schema({ name: { type: String, required: [true, 'CheckSchema: The "name" field must be required'] }, test: { type: import_mongoose.Schema.Types.ObjectId, ref: "VRSTest", required: [true, 'CheckSchema: The "test" field must be required'] }, suite: { type: import_mongoose.Schema.Types.ObjectId, ref: "VRSSuite", required: [true, 'CheckSchema: The "suite" field must be required'] }, app: { type: import_mongoose.Schema.Types.ObjectId, ref: "VRSApp", required: [true, 'CheckSchema: The "app" field must be required'] }, branch: { type: String }, realBaselineId: { type: import_mongoose.Schema.Types.ObjectId, ref: "VRSBaseline" }, baselineId: { type: import_mongoose.Schema.Types.ObjectId, ref: "VRSSnapshot" }, actualSnapshotId: { type: import_mongoose.Schema.Types.ObjectId, ref: "VRSSnapshot" }, diffId: { type: import_mongoose.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: import_mongoose.Schema.Types.ObjectId }, markedAs: { type: String, enum: ["bug", "accepted"] }, markedDate: { type: Date }, markedById: { type: import_mongoose.Schema.Types.ObjectId, ref: "VRSUser" }, markedByUsername: { type: String }, markedBugComment: { type: String }, creatorId: { type: import_mongoose.Schema.Types.ObjectId, ref: "VRSUser" }, creatorUsername: { type: String }, failReasons: { type: [String] }, vOffset: { type: String }, topStablePixels: { type: String }, meta: { type: Object } }); CheckSchema.plugin(toJSON_plugin_default); CheckSchema.plugin(paginate_plugin_default); Check = import_mongoose.default.model("VRSCheck", CheckSchema); Check_model_default = Check; } }); // src/server/models/Log.model.ts var import_mongoose2, LogSchema, Log, Log_model_default; var init_Log_model = __esm({ "src/server/models/Log.model.ts"() { "use strict"; import_mongoose2 = __toESM(require("mongoose")); init_plugins(); LogSchema = new import_mongoose2.Schema({ 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 = import_mongoose2.default.model("VRSLog", LogSchema); Log_model_default = Log; } }); // src/server/models/App.model.ts var import_mongoose3, AppSchema, App, App_model_default; var init_App_model = __esm({ "src/server/models/App.model.ts"() { "use strict"; import_mongoose3 = __toESM(require("mongoose")); init_plugins(); AppSchema = new import_mongoose3.Schema({ 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 = import_mongoose3.default.model("VRSApp", AppSchema); App_model_default = App; } }); // src/server/models/Snapshot.model.ts var import_mongoose4, SnapshotSchema, Snapshot, Snapshot_model_default; var init_Snapshot_model = __esm({ "src/server/models/Snapshot.model.ts"() { "use strict"; import_mongoose4 = __toESM(require("mongoose")); init_plugins(); SnapshotSchema = new import_mongoose4.Schema({ 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 = import_mongoose4.default.model("VRSSnapshot", SnapshotSchema); Snapshot_model_default = Snapshot; } }); // src/server/models/AppSettings.model.ts var import_mongoose5, AppSettingsSchema, AppSettings, AppSettings_model_default; var init_AppSettings_model = __esm({ "src/server/models/AppSettings.model.ts"() { "use strict"; import_mongoose5 = __toESM(require("mongoose")); init_plugins(); AppSettingsSchema = new import_mongoose5.Schema({ 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: import_mongoose5.Schema.Types.Mixed, required: [true, 'AppSettingsSchema: The "value" field must be required'] }, env_variable: { type: String }, enabled: { type: Boolean } }); AppSettingsSchema.plugin(toJSON_plugin_default); AppSettings = import_mongoose5.default.model("VRSAppSettings", AppSettingsSchema); AppSettings_model_default = AppSettings; } }); // src/server/models/Suite.model.ts var import_mongoose6, SuiteSchema, Suite, Suite_model_default; var init_Suite_model = __esm({ "src/server/models/Suite.model.ts"() { "use strict"; import_mongoose6 = __toESM(require("mongoose")); init_plugins(); SuiteSchema = new import_mongoose6.Schema({ name: { type: String, default: "Others", unique: true, required: [true, 'SuiteSchema: The "name" field must be required'] }, tags: { type: [String] }, app: { type: import_mongoose6.Schema.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 = import_mongoose6.default.model("VRSSuite", SuiteSchema); Suite_model_default = Suite; } }); // src/server/models/Run.model.ts var import_mongoose7, RunSchema, Run, Run_model_default; var init_Run_model = __esm({ "src/server/models/Run.model.ts"() { "use strict"; import_mongoose7 = __toESM(require("mongoose")); init_plugins(); RunSchema = new import_mongoose7.Schema({ name: { type: String, required: [true, 'RunSchema: The "name" field must be required'] }, app: { type: import_mongoose7.Schema.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 = import_mongoose7.default.model("VRSRun", RunSchema); Run_model_default = Run; } }); // src/server/models/User.model.ts var import_mongoose8, import_passport_local_mongoose, UserSchema, User, User_model_default; var init_User_model = __esm({ "src/server/models/User.model.ts"() { "use strict"; import_mongoose8 = __toESM(require("mongoose")); import_passport_local_mongoose = __toESM(require("passport-local-mongoose")); init_plugins(); UserSchema = new import_mongoose8.Schema({ 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'] }, password: { type: String }, token: { type: String }, apiKey: { type: String }, 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(import_passport_local_mongoose.default, { hashField: "password" }); User = import_mongoose8.default.model("VRSUser", UserSchema); User_model_default = User; } }); // src/server/models/Baseline.model.ts var import_mongoose9, BaselineSchema, Baseline, Baseline_model_default; var init_Baseline_model = __esm({ "src/server/models/Baseline.model.ts"() { "use strict"; import_mongoose9 = __toESM(require("mongoose")); init_plugins(); BaselineSchema = new import_mongoose9.Schema({ snapshootId: { type: import_mongoose9.Schema.Types.ObjectId }, name: { type: String, required: [true, 'VRSBaselineSchema: The "name" field must be required'] }, app: { type: import_mongoose9.Schema.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: import_mongoose9.Schema.Types.ObjectId, ref: "VRSUser" }, markedByUsername: { type: String }, ignoreRegions: { type: String }, boundRegions: { type: String }, matchType: { type: String, enum: ["antialiasing", "nothing", "colors"] }, meta: { type: Object } }); BaselineSchema.plugin(toJSON_plugin_default); BaselineSchema.plugin(paginate_plugin_default); Baseline = import_mongoose9.default.model("VRSBaseline", BaselineSchema); Baseline_model_default = Baseline; } }); // src/server/models/Test.model.ts var import_mongoose10, TestSchema, Test, Test_model_default; var init_Test_model = __esm({ "src/server/models/Test.model.ts"() { "use strict"; import_mongoose10 = __toESM(require("mongoose")); init_plugins(); TestSchema = new import_mongoose10.Schema( { 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: import_mongoose10.Schema.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: import_mongoose10.default.Schema.Types.ObjectId, ref: "VRSCheck" } ], suite: { type: import_mongoose10.Schema.Types.ObjectId, ref: "VRSSuite" }, run: { type: import_mongoose10.Schema.Types.ObjectId, ref: "VRSRun" }, markedAs: { type: String, enum: ["Bug", "Accepted", "Unaccepted", "Partially"] }, creatorId: { type: import_mongoose10.Schema.Types.ObjectId, ref: "VRSUser" }, creatorUsername: { type: String }, meta: { type: Object } }, { strictQuery: true } ); TestSchema.plugin(toJSON_plugin_default); TestSchema.plugin(paginate_plugin_default); TestSchema.plugin(paginateDistinct_plugin_default); Test = import_mongoose10.default.model("VRSTest", TestSchema); Test_model_default = Test; } }); // 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, 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_models = __esm({ "src/server/models/index.ts"() { "use strict"; init_Check_model(); 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(); } }); // 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_models(); } }); // 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