forked from clarkbw/loopback-ds-timestamp-mixin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtime-stamp.js.map
1 lines (1 loc) · 6.8 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","default","dataType","dataLength","dataPrecision","dataScale","nullable","observe","ctx","next","skipUpdatedAt","instance","isNewInstance","id","where","data","updateAll","then","query","isDeleted","JSON","stringify","indexOf","module","exports"],"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,cAA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ACAW,UAAIG,QAAJ,CAAa1B,QAAQG,SAArB,IAAkC,IAAlC;AACD,KAPD,MAOO;AACLX,YAAM,iCAAN,EACM+B,IAAI1B,KAAJ,CAAUY,eADhB,EACiCT,QAAQE,SADzC,EACoDqB,IAAIM,KADxD;AAEAN,UAAIO,IAAJ,CAAS9B,QAAQE,SAAjB,IAA8B,IAAIU,IAAJ,EAA9B;AACD;AACD,WAAOY,MAAP;AACD,GAhBD;;AAkBA;;;;;AAKA3B,QAAMyB,OAAN,CAAc,eAAd,EAA+B,UAACC,GAAD,EAAMC,IAAN,EAAe;AAC5C3B,UAAMkC,SAAN,CAAgBR,IAAIM,KAApB,sBAA8B7B,QAAQG,SAAtC,EAAkD,IAAIS,IAAJ,EAAlD,GAAgEoB,IAAhE,CAAqE,YAAM;AACzER,WAAK,IAAL;AACD,KAFD;AAGD,GAJD;;AAMA;;;;AAIA3B,QAAMyB,OAAN,CAAc,QAAd,EAAwB,UAACC,GAAD,EAAMC,IAAN,EAAe;AACrC;AACA,QAAID,IAAIU,KAAJ,CAAUC,SAAd,EAAyB,OAAOV,MAAP;AACzB,QAAID,IAAIU,KAAJ,CAAUJ,KAAV,IAAmBM,KAAKC,SAAL,CAAeb,IAAIU,KAAJ,CAAUJ,KAAzB,EAAgCQ,OAAhC,CAAwC,WAAxC,MAAyD,CAAhF,EAAmF,OAAOb,MAAP;AACnF;AACA,QAAI,CAACD,IAAIU,KAAJ,CAAUJ,KAAf,EAAsBN,IAAIU,KAAJ,CAAUJ,KAAV,GAAkB,EAAlB;AACtBN,QAAIU,KAAJ,CAAUJ,KAAV,CAAgB7B,QAAQG,SAAxB,IAAqC,IAArC;AACAqB;AACD,GARD;AASD,C;;AAEDc,OAAOC,OAAP,GAAiBA,QAAQvB,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 default: 'CURRENT_TIMESTAMP',\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 if (ctx.isNewInstance) {\n ctx.instance[options.createdAt] = new Date();\n }\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"}