UNPKG

mongo-seeding

Version:

The ultimate Node.js library for populating your MongoDB database.

52 lines 1.83 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DefaultTransformers = void 0; /** * Rewrites `id` property to `_id` for every document in given collection. * * @param collection Collection details */ const replaceDocumentIdWithUnderscoreId = (collection) => { const documents = collection.documents.map((document) => { if (typeof document.id === 'undefined') { return document; } const documentToInsert = Object.assign(Object.assign({}, document), { _id: document.id }); delete documentToInsert.id; return documentToInsert; }); return Object.assign(Object.assign({}, collection), { documents }); }; /** * Set createdAt timestamp for every document in given collection. * * @param collection Collection details */ const setCreatedAtTimestamp = (collection) => { const documents = collection.documents.map((document) => { const documentToInsert = Object.assign(Object.assign({}, document), { createdAt: new Date() }); return documentToInsert; }); return Object.assign(Object.assign({}, collection), { documents }); }; /** * Set updatedAt timestamp for every document in given collection. * * @param collection Collection details */ const setUpdatedAtTimestamp = (collection) => { const documents = collection.documents.map((document) => { const documentToInsert = Object.assign(Object.assign({}, document), { updatedAt: new Date() }); return documentToInsert; }); return Object.assign(Object.assign({}, collection), { documents }); }; /** * Contains default transformer functions. */ exports.DefaultTransformers = { replaceDocumentIdWithUnderscoreId, setCreatedAtTimestamp, setUpdatedAtTimestamp, }; //# sourceMappingURL=transformer-functions.js.map