@sera4/essentia 1.1.16 → 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 +26 -9
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) {
|
|
@@ -595,7 +608,6 @@ paperTrail.init = (sequelize, sequelizePackage, optionsArg) => {
|
|
|
595
608
|
foreignKey: options.defaultAttributes.revisionId,
|
|
596
609
|
constraints: false,
|
|
597
610
|
});
|
|
598
|
-
paginator.paginate(Revision);
|
|
599
611
|
|
|
600
612
|
RevisionChange.belongsTo(Revision);
|
|
601
613
|
|
|
@@ -603,6 +615,8 @@ paperTrail.init = (sequelize, sequelizePackage, optionsArg) => {
|
|
|
603
615
|
db[RevisionChange.name] = RevisionChange;
|
|
604
616
|
}
|
|
605
617
|
|
|
618
|
+
paginator.paginate(Revision);
|
|
619
|
+
|
|
606
620
|
if (db)
|
|
607
621
|
db[Revision.name] = Revision;
|
|
608
622
|
|
|
@@ -614,10 +628,13 @@ paperTrail.init = (sequelize, sequelizePackage, optionsArg) => {
|
|
|
614
628
|
* association through the associate call above.
|
|
615
629
|
*/
|
|
616
630
|
if (options.userModel) {
|
|
617
|
-
Revision.belongsTo(
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
631
|
+
Revision.belongsTo(sequelize.model(options.userModel), {
|
|
632
|
+
as: "account",
|
|
633
|
+
foreignKey: {
|
|
634
|
+
fieldName: options.userModelAttribute
|
|
635
|
+
},
|
|
636
|
+
onDelete: "CASCADE"
|
|
637
|
+
});
|
|
621
638
|
}
|
|
622
639
|
|
|
623
640
|
return Revision;
|
|
@@ -633,4 +650,4 @@ paperTrail.enableFailHard = () => {
|
|
|
633
650
|
failHard = true;
|
|
634
651
|
};
|
|
635
652
|
|
|
636
|
-
export default paperTrail;
|
|
653
|
+
export default paperTrail;
|