UNPKG

@syngrisi/syngrisi

Version:
187 lines (182 loc) 5.77 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 __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/Baseline.model.ts var Baseline_model_exports = {}; __export(Baseline_model_exports, { default: () => Baseline_model_default }); module.exports = __toCommonJS(Baseline_model_exports); var import_mongoose = __toESM(require("mongoose")); // src/server/models/plugins/paginate.plugin.ts var 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); }); }; }; var paginate_plugin_default = paginate; // src/server/models/plugins/toJSON.plugin.ts var deleteAtPath = (obj, path, index) => { if (index === path.length - 1) { delete obj[path[index]]; return; } deleteAtPath(obj[path[index]], path, index + 1); }; var 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); } } }); }; var toJSON_plugin_default = toJSON; // src/server/models/plugins/paginateDistinct.plugin.ts var import_bson = require("bson"); // src/server/models/Baseline.model.ts var BaselineSchema = new import_mongoose.Schema({ snapshootId: { type: import_mongoose.Schema.Types.ObjectId }, name: { type: String, required: [true, 'VRSBaselineSchema: The "name" field must be required'] }, app: { type: import_mongoose.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_mongoose.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); var Baseline = import_mongoose.default.model("VRSBaseline", BaselineSchema); var Baseline_model_default = Baseline; //# sourceMappingURL=Baseline.model.js.map