forked from i-dalgo/loopback-timestamp-mixin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtime-stamp.js.map
1 lines (1 loc) · 6.54 KB
/
time-stamp.js.map
1
{"version":3,"sources":["time-stamp.js"],"names":["debug","warn","log","console","bind","Model","bootOptions","modelName","options","createdAt","updatedAt","deletedAt","required","validateUpsert","silenceWarnings","enabled","settings","pluralModelName","defineProperty","type","Date","defaultFn","mysql","columnName","dataType","dataLength","dataPrecision","dataScale","nullable","observe","ctx","next","skipUpdatedAt","instance","id","where","data","updateAll","then","query","isDeleted","JSON","stringify","indexOf","module","exports","default"],"mappings":";;;;;;;;AAAA;;;;;;;;AAEA,IAAMA,QAAQ,sBAAd;AACA,IAAMC,OAAO,sBAAb,C,CAAuB;AACvBA,KAAKC,GAAL,GAAWC,QAAQF,IAAR,CAAaG,IAAb,CAAkBD,OAAlB,CAAX,C,CAAuC;;kBAExB,UAACE,KAAD,EAA6B;AAAA,MAArBC,WAAqB,uEAAP,EAAO;;AAC1CN,QAAM,8BAAN,EAAsCK,MAAME,SAA5C;;AAEA,MAAMC,UAAU,SAAc;AAC5BC,eAAW,WADiB;AAE5BC,eAAW,WAFiB;AAG5BC,eAAW,WAHiB;AAI5BC,cAAU,IAJkB;AAK5BC,oBAAgB,KALY,EAKL;AACvBC,qBAAiB;AANW,GAAd,EAObR,WAPa,CAAhB;;AASAN,QAAM,SAAN,EAAiBQ,OAAjB;;AAEA;AACAP,OAAKc,OAAL,GAAe,CAACP,QAAQM,eAAxB;;AAEA,MAAI,CAACN,QAAQK,cAAT,IAA2BR,MAAMW,QAAN,CAAeH,cAA9C,EAA8D;AAC5DR,UAAMW,QAAN,CAAeH,cAAf,GAAgC,KAAhC;AACAZ,SAAQI,MAAMY,eAAd;AACD;;AAED,MAAIZ,MAAMW,QAAN,CAAeH,cAAf,IAAiCL,QAAQI,QAA7C,EAAuD;AACrDX,0BAAoBI,MAAMY,eAA1B;AAED;;AAEDZ,QAAMa,cAAN,CAAqBV,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,EACoDoB,IAAIK,KADxD;AAEAL,UAAIM,IAAJ,CAAS5B,QAAQE,SAAjB,IAA8B,IAAIU,IAAJ,EAA9B;AACD;AACD,WAAOW,MAAP;AACD,GAbD;;AAeA;;;;;AAKA1B,QAAMwB,OAAN,CAAc,eAAd,EAA+B,UAACC,GAAD,EAAMC,IAAN,EAAe;AAC5C1B,UAAMgC,SAAN,CAAgBP,IAAIK,KAApB,sBAA8B3B,QAAQG,SAAtC,EAAkD,IAAIS,IAAJ,EAAlD,GAAgEkB,IAAhE,CAAqE,YAAM;AACzEP,WAAK,IAAL;AACD,KAFD;AAGD,GAJD;;AAMA;;;;AAIA1B,QAAMwB,OAAN,CAAc,QAAd,EAAwB,UAACC,GAAD,EAAMC,IAAN,EAAe;AACrC;AACA,QAAID,IAAIS,KAAJ,CAAUC,SAAd,EAAyB,OAAOT,MAAP;AACzB,QAAID,IAAIS,KAAJ,CAAUJ,KAAV,IAAmBM,KAAKC,SAAL,CAAeZ,IAAIS,KAAJ,CAAUJ,KAAzB,EAAgCQ,OAAhC,CAAwC,WAAxC,MAAyD,CAAhF,EAAmF,OAAOZ,MAAP;AACnF;AACA,QAAI,CAACD,IAAIS,KAAJ,CAAUJ,KAAf,EAAsBL,IAAIS,KAAJ,CAAUJ,KAAV,GAAkB,EAAlB;AACtBL,QAAIS,KAAJ,CAAUJ,KAAV,CAAgB3B,QAAQG,SAAxB,IAAqC,IAArC;AACAoB;AACD,GARD;AASD,C;;AAEDa,OAAOC,OAAP,GAAiBA,QAAQC,OAAzB","file":"time-stamp.js","sourcesContent":["import _debug from './debug';\n\nconst debug = _debug();\nconst warn = _debug(); // create a namespaced warning\nwarn.log = console.warn.bind(console); // eslint-disable-line no-console\n\nexport default (Model, bootOptions = {}) => {\n debug('TimeStamp mixin for Model %s', Model.modelName);\n\n const options = Object.assign({\n createdAt: 'createdAt',\n updatedAt: 'updatedAt',\n deletedAt: 'deletedAt',\n required: true,\n validateUpsert: false, // default to turning validation off\n silenceWarnings: false,\n }, bootOptions);\n\n debug('options', options);\n\n // enable our warnings via the options\n warn.enabled = !options.silenceWarnings;\n\n if (!options.validateUpsert && Model.settings.validateUpsert) {\n Model.settings.validateUpsert = false;\n warn(`${Model.pluralModelName} settings.validateUpsert was overriden to false`);\n }\n\n if (Model.settings.validateUpsert && options.required) {\n warn(`Upserts for ${Model.pluralModelName} will fail when\n validation is turned on and time stamps are required`);\n }\n\n Model.defineProperty(options.createdAt, {\n type: Date,\n required: options.required,\n defaultFn: 'now',\n mysql: {\n columnName: 'created_at',\n dataType: 'timestamp',\n },\n });\n\n Model.defineProperty(options.updatedAt, {\n type: Date,\n required: false,\n mysql: {\n columnName: 'updated_at',\n dataType: 'timestamp',\n dataLength: null,\n dataPrecision: null,\n dataScale: null,\n nullable: 'Y',\n },\n });\n\n Model.defineProperty(options.deletedAt, {\n type: Date,\n required: false,\n mysql: {\n columnName: 'deleted_at',\n dataType: 'timestamp',\n dataLength: null,\n dataPrecision: null,\n dataScale: null,\n nullable: 'Y',\n },\n });\n\n Model.observe('before save', (ctx, next) => {\n debug('ctx.options', ctx.options);\n if (ctx.options && ctx.options.skipUpdatedAt) { return next(); }\n if (ctx.instance) {\n debug('%s.%s before save: %s', ctx.Model.modelName, options.updatedAt, ctx.instance.id);\n ctx.instance[options.updatedAt] = new Date();\n ctx.instance[options.deletedAt] = null;\n } else {\n debug('%s.%s before update matching %j',\n ctx.Model.pluralModelName, options.updatedAt, ctx.where);\n ctx.data[options.updatedAt] = new Date();\n }\n return next();\n });\n\n /**\n * Watches destroyAll(), deleteAll(), destroyById() , deleteById(), prototype.destroy(),\n * prototype.delete() methods\n * and instead of deleting object, sets properties deletedAt and isDeleted.\n */\n Model.observe('before delete', (ctx, next) => {\n Model.updateAll(ctx.where, { [options.deletedAt]: new Date() }).then(() => {\n next(null);\n });\n });\n\n /**\n * When ever model tries to access data, we add by default isDeleted: false to where query\n * if there is already in query isDeleted property, then we do not modify query\n */\n Model.observe('access', (ctx, next) => {\n // If we want the deleted ones\n if (ctx.query.isDeleted) return next()\n if (ctx.query.where && JSON.stringify(ctx.query.where).indexOf('isDeleted') === 1) return next()\n // By defaut set deletedAt to null\n if (!ctx.query.where) ctx.query.where = {};\n ctx.query.where[options.deletedAt] = null;\n next();\n });\n};\n\nmodule.exports = exports.default;\n"],"sourceRoot":"/mnt/c/Users/clovis/www/__helpers/loopback-timestamp-mixin/es6"}