@sera4/essentia 1.1.17 → 1.1.18
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 +24 -8
package/package.json
CHANGED
package/package.tar.gz
CHANGED
|
Binary file
|
package/paper-trail/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import paginator from "../paginator/sql-pagination.js";
|
|
|
5
5
|
|
|
6
6
|
let failHard = false;
|
|
7
7
|
let als;
|
|
8
|
-
let Sequelize = null
|
|
8
|
+
let Sequelize = null;
|
|
9
9
|
|
|
10
10
|
const paperTrail = {};
|
|
11
11
|
|
|
@@ -28,6 +28,8 @@ paperTrail.init = (sequelize, sequelizePackage, optionsArg) => {
|
|
|
28
28
|
'deleted_at',
|
|
29
29
|
'revision',
|
|
30
30
|
],
|
|
31
|
+
// additional fields to exclude on a global basis
|
|
32
|
+
excludeExtras: [],
|
|
31
33
|
revisionAttribute: 'revision',
|
|
32
34
|
revisionModel: 'Revision',
|
|
33
35
|
revisionChangeModel: 'RevisionChange',
|
|
@@ -56,6 +58,15 @@ paperTrail.init = (sequelize, sequelizePackage, optionsArg) => {
|
|
|
56
58
|
helpers.toUnderscored(defaultOptions.defaultAttributes);
|
|
57
59
|
}
|
|
58
60
|
|
|
61
|
+
// deals with not wanting to overwrite the initial ones, just add some
|
|
62
|
+
if (optsArg.excludeExtras) {
|
|
63
|
+
if (optsArg.exclude) {
|
|
64
|
+
optsArg.exclude = [...optsArg.exclude, ...optsArg.excludeExtras ]
|
|
65
|
+
} else {
|
|
66
|
+
optsArg.exclude = [...defaultOptions.exclude, ...optsArg.excludeExtras ]
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
59
70
|
const options = _.defaults(optsArg, defaultOptions);
|
|
60
71
|
|
|
61
72
|
const log = options.log || console.log;
|
|
@@ -313,7 +324,6 @@ paperTrail.init = (sequelize, sequelizePackage, optionsArg) => {
|
|
|
313
324
|
options.revisionAttribute,
|
|
314
325
|
);
|
|
315
326
|
|
|
316
|
-
// Save revision(
|
|
317
327
|
return revision
|
|
318
328
|
.save({ transaction: opt.transaction })
|
|
319
329
|
.then(objectRevision => {
|
|
@@ -521,10 +531,10 @@ paperTrail.init = (sequelize, sequelizePackage, optionsArg) => {
|
|
|
521
531
|
type: Sequelize.UUID,
|
|
522
532
|
defaultValue: Sequelize.UUIDV4,
|
|
523
533
|
};
|
|
534
|
+
|
|
524
535
|
attributes[options.defaultAttributes.documentId].type =
|
|
525
536
|
Sequelize.UUID;
|
|
526
537
|
|
|
527
|
-
console.log("userModelatribute", options.userModelAttribute)
|
|
528
538
|
attributes[options.userModelAttribute].type = Sequelize.UUID;
|
|
529
539
|
}
|
|
530
540
|
|
|
@@ -539,6 +549,9 @@ paperTrail.init = (sequelize, sequelizePackage, optionsArg) => {
|
|
|
539
549
|
{
|
|
540
550
|
underscored: options.underscored,
|
|
541
551
|
tableName: options.tableName,
|
|
552
|
+
timestamps: true,
|
|
553
|
+
createdAt: options.underscored ? "created_at" : "createdAt",
|
|
554
|
+
updatedAt: options.underscored ? "updated_at" : "updatedAt"
|
|
542
555
|
},
|
|
543
556
|
);
|
|
544
557
|
Revision.associate = function associate(models) {
|
|
@@ -615,10 +628,13 @@ paperTrail.init = (sequelize, sequelizePackage, optionsArg) => {
|
|
|
615
628
|
* association through the associate call above.
|
|
616
629
|
*/
|
|
617
630
|
if (options.userModel) {
|
|
618
|
-
Revision.belongsTo(
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
631
|
+
Revision.belongsTo(sequelize.model(options.userModel), {
|
|
632
|
+
as: "account",
|
|
633
|
+
foreignKey: {
|
|
634
|
+
fieldName: options.userModelAttribute
|
|
635
|
+
},
|
|
636
|
+
onDelete: "CASCADE"
|
|
637
|
+
});
|
|
622
638
|
}
|
|
623
639
|
|
|
624
640
|
return Revision;
|
|
@@ -634,4 +650,4 @@ paperTrail.enableFailHard = () => {
|
|
|
634
650
|
failHard = true;
|
|
635
651
|
};
|
|
636
652
|
|
|
637
|
-
export default paperTrail;
|
|
653
|
+
export default paperTrail;
|