@sera4/essentia 1.1.22 → 1.1.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/package.tar.gz +0 -0
- package/paper-trail/index.js +26 -4
package/package.json
CHANGED
package/package.tar.gz
CHANGED
|
Binary file
|
package/paper-trail/index.js
CHANGED
|
@@ -40,9 +40,12 @@ paperTrail.init = (sequelize, sequelizePackage, optionsArg) => {
|
|
|
40
40
|
mixedDocumentReference: false,
|
|
41
41
|
underscored: false,
|
|
42
42
|
underscoredAttributes: false,
|
|
43
|
+
// always store these keys in a reference value if seen
|
|
44
|
+
includeReferences: [],
|
|
43
45
|
defaultAttributes: {
|
|
44
46
|
documentId: 'documentId',
|
|
45
47
|
revisionId: 'revisionId',
|
|
48
|
+
autoGenerated: 'autoGenerated'
|
|
46
49
|
},
|
|
47
50
|
als: null,
|
|
48
51
|
userModel: false,
|
|
@@ -220,6 +223,7 @@ paperTrail.init = (sequelize, sequelizePackage, optionsArg) => {
|
|
|
220
223
|
}
|
|
221
224
|
|
|
222
225
|
const destroyOperation = operation === 'destroy';
|
|
226
|
+
const createOperation = operation === 'create';
|
|
223
227
|
|
|
224
228
|
if (
|
|
225
229
|
instance.context &&
|
|
@@ -269,9 +273,6 @@ paperTrail.init = (sequelize, sequelizePackage, optionsArg) => {
|
|
|
269
273
|
);
|
|
270
274
|
currentVersion = _.omit(currentVersion, options.exclude);
|
|
271
275
|
|
|
272
|
-
if (!options.als)
|
|
273
|
-
options.als = asyncLocalStorage;
|
|
274
|
-
|
|
275
276
|
const store = options.als && options.als.getStore()
|
|
276
277
|
if (store && !store.has(options.continuationKey)) {
|
|
277
278
|
if (failHard)
|
|
@@ -280,7 +281,20 @@ paperTrail.init = (sequelize, sequelizePackage, optionsArg) => {
|
|
|
280
281
|
);
|
|
281
282
|
}
|
|
282
283
|
|
|
283
|
-
let document
|
|
284
|
+
let document;
|
|
285
|
+
if (destroyOperation) {
|
|
286
|
+
document = { oldValues: currentVersion };
|
|
287
|
+
} else if (createOperation) {
|
|
288
|
+
document = { newValues: currentVersion };
|
|
289
|
+
} else {
|
|
290
|
+
document = { oldValues: previousVersion, newValues: currentVersion };
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
const references = _.pick(instance.dataValues, options.includeReferences);
|
|
294
|
+
|
|
295
|
+
if (Object.keys(references).length) {
|
|
296
|
+
document['references'] = references;
|
|
297
|
+
}
|
|
284
298
|
|
|
285
299
|
if (options.mysql) {
|
|
286
300
|
document = JSON.stringify(document);
|
|
@@ -321,6 +335,8 @@ paperTrail.init = (sequelize, sequelizePackage, optionsArg) => {
|
|
|
321
335
|
}
|
|
322
336
|
}
|
|
323
337
|
|
|
338
|
+
query[options.defaultAttributes.autoGenerated] = opt.autoGenerated;
|
|
339
|
+
|
|
324
340
|
// in case of custom user models that are not 'userId'
|
|
325
341
|
query[options.userModelAttribute] =
|
|
326
342
|
(store && store.get(options.continuationKey)) || opt.userId;
|
|
@@ -547,6 +563,12 @@ paperTrail.init = (sequelize, sequelizePackage, optionsArg) => {
|
|
|
547
563
|
allowNull: false,
|
|
548
564
|
};
|
|
549
565
|
|
|
566
|
+
attributes[options.defaultAttributes.autoGenerated] = {
|
|
567
|
+
type: Sequelize.BOOLEAN,
|
|
568
|
+
defaultValue: false,
|
|
569
|
+
allowNull: false,
|
|
570
|
+
};
|
|
571
|
+
|
|
550
572
|
attributes[options.revisionAttribute] = {
|
|
551
573
|
type: Sequelize.INTEGER,
|
|
552
574
|
allowNull: false,
|