@sera4/essentia 3.0.13-rc.1 → 3.0.13
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/dist/cache/index.d.ts +0 -22
- package/dist/cache/index.js +0 -166
- package/dist/cache/index.js.map +0 -1
- package/dist/constants/index.d.ts +0 -6
- package/dist/constants/index.js +0 -9
- package/dist/constants/index.js.map +0 -1
- package/dist/formatter/index.d.ts +0 -37
- package/dist/formatter/index.js +0 -75
- package/dist/formatter/index.js.map +0 -1
- package/dist/hal/index.d.ts +0 -5
- package/dist/hal/index.js +0 -69
- package/dist/hal/index.js.map +0 -1
- package/dist/health/health-logger.d.ts +0 -9
- package/dist/health/health-logger.js +0 -34
- package/dist/health/health-logger.js.map +0 -1
- package/dist/health/index.d.ts +0 -19
- package/dist/health/index.js +0 -175
- package/dist/health/index.js.map +0 -1
- package/dist/helpers/index.d.ts +0 -1
- package/dist/helpers/index.js +0 -2
- package/dist/helpers/index.js.map +0 -1
- package/dist/helpers/test-server-wrapper.d.ts +0 -120
- package/dist/helpers/test-server-wrapper.js +0 -165
- package/dist/helpers/test-server-wrapper.js.map +0 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -17
- package/dist/index.js.map +0 -1
- package/dist/last-commit.d.ts +0 -1
- package/dist/last-commit.js.map +0 -1
- package/dist/last_commit/index.d.ts +0 -7
- package/dist/last_commit/index.js +0 -83
- package/dist/last_commit/index.js.map +0 -1
- package/dist/paginator/s4-pagination.d.ts +0 -9
- package/dist/paginator/s4-pagination.js +0 -49
- package/dist/paginator/s4-pagination.js.map +0 -1
- package/dist/paginator/sql-pagination.d.ts +0 -27
- package/dist/paginator/sql-pagination.js +0 -166
- package/dist/paginator/sql-pagination.js.map +0 -1
- package/dist/paper-trail/helpers.d.ts +0 -11
- package/dist/paper-trail/helpers.js +0 -74
- package/dist/paper-trail/helpers.js.map +0 -1
- package/dist/paper-trail/index.d.ts +0 -13
- package/dist/paper-trail/index.js +0 -662
- package/dist/paper-trail/index.js.map +0 -1
- package/dist/prompts/index.d.ts +0 -14
- package/dist/prompts/index.js +0 -63
- package/dist/prompts/index.js.map +0 -1
- package/dist/queue/index.d.ts +0 -166
- package/dist/queue/index.js +0 -371
- package/dist/queue/index.js.map +0 -1
- package/dist/queue/publisher.d.ts +0 -31
- package/dist/queue/publisher.js +0 -84
- package/dist/queue/publisher.js.map +0 -1
- package/dist/queue/queue-logger.d.ts +0 -9
- package/dist/queue/queue-logger.js +0 -35
- package/dist/queue/queue-logger.js.map +0 -1
- package/dist/queue/subscriber.d.ts +0 -39
- package/dist/queue/subscriber.js +0 -97
- package/dist/queue/subscriber.js.map +0 -1
- package/dist/safe_proxy/index.d.ts +0 -13
- package/dist/safe_proxy/index.js +0 -54
- package/dist/safe_proxy/index.js.map +0 -1
- package/dist/serializer/index.d.ts +0 -5
- package/dist/serializer/index.js +0 -83
- package/dist/serializer/index.js.map +0 -1
- package/dist/ts/cache/index.d.ts +0 -33
- package/dist/ts/cache/index.js +0 -171
- package/dist/ts/cache/index.js.map +0 -1
- package/dist/ts/configurations/server-config.d.ts +0 -4
- package/dist/ts/configurations/server-config.js +0 -2
- package/dist/ts/configurations/server-config.js.map +0 -1
- package/dist/ts/constants/index.d.ts +0 -7
- package/dist/ts/constants/index.js +0 -8
- package/dist/ts/constants/index.js.map +0 -1
- package/dist/ts/cycle/index.d.ts +0 -53
- package/dist/ts/cycle/index.js +0 -169
- package/dist/ts/cycle/index.js.map +0 -1
- package/dist/ts/dns/DnsCache.d.ts +0 -50
- package/dist/ts/dns/DnsCache.js +0 -137
- package/dist/ts/dns/DnsCache.js.map +0 -1
- package/dist/ts/dns/index.d.ts +0 -4
- package/dist/ts/dns/index.js +0 -4
- package/dist/ts/dns/index.js.map +0 -1
- package/dist/ts/formatter/index.d.ts +0 -44
- package/dist/ts/formatter/index.js +0 -76
- package/dist/ts/formatter/index.js.map +0 -1
- package/dist/ts/hal/index.d.ts +0 -26
- package/dist/ts/hal/index.js +0 -70
- package/dist/ts/hal/index.js.map +0 -1
- package/dist/ts/health/index.d.ts +0 -53
- package/dist/ts/health/index.js +0 -165
- package/dist/ts/health/index.js.map +0 -1
- package/dist/ts/helpers/index.d.ts +0 -1
- package/dist/ts/helpers/index.js +0 -2
- package/dist/ts/helpers/index.js.map +0 -1
- package/dist/ts/helpers/test-server-wrapper.d.ts +0 -56
- package/dist/ts/helpers/test-server-wrapper.js +0 -144
- package/dist/ts/helpers/test-server-wrapper.js.map +0 -1
- package/dist/ts/index.d.ts +0 -22
- package/dist/ts/index.js +0 -27
- package/dist/ts/index.js.map +0 -1
- package/dist/ts/last-commit/index.d.ts +0 -12
- package/dist/ts/last-commit/index.js +0 -82
- package/dist/ts/last-commit/index.js.map +0 -1
- package/dist/ts/logger/index.d.ts +0 -3
- package/dist/ts/logger/index.js +0 -4
- package/dist/ts/logger/index.js.map +0 -1
- package/dist/ts/logger/s4-logger.d.ts +0 -23
- package/dist/ts/logger/s4-logger.js +0 -105
- package/dist/ts/logger/s4-logger.js.map +0 -1
- package/dist/ts/paginator/index.d.ts +0 -2
- package/dist/ts/paginator/index.js +0 -3
- package/dist/ts/paginator/index.js.map +0 -1
- package/dist/ts/paginator/s4-pagination.d.ts +0 -26
- package/dist/ts/paginator/s4-pagination.js +0 -49
- package/dist/ts/paginator/s4-pagination.js.map +0 -1
- package/dist/ts/paginator/sql-pagination.d.ts +0 -52
- package/dist/ts/paginator/sql-pagination.js +0 -157
- package/dist/ts/paginator/sql-pagination.js.map +0 -1
- package/dist/ts/paper-trail/helpers.d.ts +0 -14
- package/dist/ts/paper-trail/helpers.js +0 -74
- package/dist/ts/paper-trail/helpers.js.map +0 -1
- package/dist/ts/paper-trail/index.d.ts +0 -54
- package/dist/ts/paper-trail/index.js +0 -236
- package/dist/ts/paper-trail/index.js.map +0 -1
- package/dist/ts/prompts/index.d.ts +0 -21
- package/dist/ts/prompts/index.js +0 -68
- package/dist/ts/prompts/index.js.map +0 -1
- package/dist/ts/queue/index.d.ts +0 -232
- package/dist/ts/queue/index.js +0 -440
- package/dist/ts/queue/index.js.map +0 -1
- package/dist/ts/queue/publisher.d.ts +0 -41
- package/dist/ts/queue/publisher.js +0 -84
- package/dist/ts/queue/publisher.js.map +0 -1
- package/dist/ts/queue/queue-logger.d.ts +0 -10
- package/dist/ts/queue/queue-logger.js +0 -35
- package/dist/ts/queue/queue-logger.js.map +0 -1
- package/dist/ts/queue/subscriber.d.ts +0 -55
- package/dist/ts/queue/subscriber.js +0 -98
- package/dist/ts/queue/subscriber.js.map +0 -1
- package/dist/ts/safe-proxy/index.d.ts +0 -35
- package/dist/ts/safe-proxy/index.js +0 -54
- package/dist/ts/safe-proxy/index.js.map +0 -1
- package/dist/ts/serializer/index.d.ts +0 -52
- package/dist/ts/serializer/index.js +0 -83
- package/dist/ts/serializer/index.js.map +0 -1
- package/dist/ts/task-scheduler/index.d.ts +0 -130
- package/dist/ts/task-scheduler/index.js +0 -259
- package/dist/ts/task-scheduler/index.js.map +0 -1
- package/dist/ts/utils/index.d.ts +0 -49
- package/dist/ts/utils/index.js +0 -157
- package/dist/ts/utils/index.js.map +0 -1
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
interface DiffResult {
|
|
2
|
-
kind: string;
|
|
3
|
-
path: string[];
|
|
4
|
-
lhs?: any;
|
|
5
|
-
rhs?: any;
|
|
6
|
-
}
|
|
7
|
-
declare const _default: {
|
|
8
|
-
capitalizeFirstLetter: (string: string) => string;
|
|
9
|
-
toUnderscored: (obj: Record<string, string>) => Record<string, string>;
|
|
10
|
-
calcDelta: (current: Record<string, any>, next: Record<string, any>, exclude: string[], strict: boolean, DEBUG?: boolean) => DiffResult[] | null;
|
|
11
|
-
diffToString: (val: any) => string;
|
|
12
|
-
};
|
|
13
|
-
export default _default;
|
|
14
|
-
export type { DiffResult };
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import pkg from 'deep-diff';
|
|
2
|
-
import _ from 'lodash';
|
|
3
|
-
const { diff } = pkg;
|
|
4
|
-
const capitalizeFirstLetter = (string) => string.charAt(0).toUpperCase() + string.slice(1);
|
|
5
|
-
const toUnderscored = (obj) => {
|
|
6
|
-
_.forEach(obj, (k, v) => {
|
|
7
|
-
obj[k] = v
|
|
8
|
-
.replace(/(?:^|\.?)([A-Z])/g, (x, y) => `_${y.toLowerCase()}`)
|
|
9
|
-
.replace(/^_/, '');
|
|
10
|
-
});
|
|
11
|
-
return obj;
|
|
12
|
-
};
|
|
13
|
-
const calcDelta = (current, next, exclude, strict, DEBUG = false) => {
|
|
14
|
-
if (DEBUG) {
|
|
15
|
-
console.log('current', current);
|
|
16
|
-
console.log('next', next);
|
|
17
|
-
console.log('exclude', exclude);
|
|
18
|
-
}
|
|
19
|
-
const di = diff(current, next);
|
|
20
|
-
if (DEBUG) {
|
|
21
|
-
console.log('di', di);
|
|
22
|
-
let diffs2 = [];
|
|
23
|
-
if (di) {
|
|
24
|
-
diffs2 = di.map((i) => JSON.parse(JSON.stringify(i).replace('"__data",', '')));
|
|
25
|
-
}
|
|
26
|
-
console.log('diffs2', diffs2);
|
|
27
|
-
console.log('filter1', diffs2.filter(i => i.path.join(',').indexOf('_') === -1));
|
|
28
|
-
console.log('filter2', diffs2.filter(i => exclude.every(x => i.path.indexOf(x) === -1)));
|
|
29
|
-
}
|
|
30
|
-
let diffs = [];
|
|
31
|
-
if (di) {
|
|
32
|
-
diffs = di
|
|
33
|
-
.map((i) => JSON.parse(JSON.stringify(i).replace('"__data",', '')))
|
|
34
|
-
.filter((i) => {
|
|
35
|
-
if (!strict && i.kind === 'E') {
|
|
36
|
-
// eslint-disable-next-line eqeqeq
|
|
37
|
-
if (i.lhs != i.rhs)
|
|
38
|
-
return i;
|
|
39
|
-
}
|
|
40
|
-
else
|
|
41
|
-
return i;
|
|
42
|
-
return false;
|
|
43
|
-
})
|
|
44
|
-
.filter((i) => exclude.every((x) => i.path.indexOf(x) === -1));
|
|
45
|
-
}
|
|
46
|
-
if (diffs.length > 0) {
|
|
47
|
-
return diffs;
|
|
48
|
-
}
|
|
49
|
-
return null;
|
|
50
|
-
};
|
|
51
|
-
const diffToString = (val) => {
|
|
52
|
-
if (typeof val === 'undefined' || val === null)
|
|
53
|
-
return '';
|
|
54
|
-
if (val === true)
|
|
55
|
-
return '1';
|
|
56
|
-
if (val === false)
|
|
57
|
-
return '0';
|
|
58
|
-
if (typeof val === 'string')
|
|
59
|
-
return val;
|
|
60
|
-
if (!Number.isNaN(Number(val)))
|
|
61
|
-
return `${String(val)}`;
|
|
62
|
-
if ((typeof val === 'undefined' ? 'undefined' : typeof val) === 'object')
|
|
63
|
-
return `${JSON.stringify(val)}`;
|
|
64
|
-
if (Array.isArray(val))
|
|
65
|
-
return `${JSON.stringify(val)}`;
|
|
66
|
-
return '';
|
|
67
|
-
};
|
|
68
|
-
export default {
|
|
69
|
-
capitalizeFirstLetter,
|
|
70
|
-
toUnderscored,
|
|
71
|
-
calcDelta,
|
|
72
|
-
diffToString
|
|
73
|
-
};
|
|
74
|
-
//# sourceMappingURL=helpers.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../ts/paper-trail/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,WAAW,CAAC;AAC5B,OAAO,CAAC,MAAM,QAAQ,CAAC;AAEvB,MAAM,EAAE,IAAI,EAAE,GAAG,GAAG,CAAC;AASrB,MAAM,qBAAqB,GAAG,CAAC,MAAc,EAAU,EAAE,CACvD,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAEnD,MAAM,aAAa,GAAG,CAAC,GAA2B,EAA0B,EAAE;IAC5E,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAM,EAAE,CAAM,EAAE,EAAE;QAChC,GAAG,CAAC,CAA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AI,GAAG,KAAK,IAAI;QAC5C,OAAO,EAAE,CAAC;IAEZ,IAAI,GAAG,KAAK,IAAI;QACd,OAAO,GAAG,CAAC;IAEb,IAAI,GAAG,KAAK,KAAK;QACf,OAAO,GAAG,CAAC;IAEb,IAAI,OAAO,GAAG,KAAK,QAAQ;QACzB,OAAO,GAAG,CAAC;IAEb,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAC5B,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;IAE1B,IAAI,CAAC,OAAO,GAAG,KAAK,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,OAAO,GAAG,CAAC,KAAK,QAAQ;QACtE,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC;IAElC,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC;QACpB,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC;IAElC,OAAO,EAAE,CAAC;AACZ,CAAC,CAAC;AAEF,eAAe;IACb,qBAAqB;IACrB,aAAa;IACb,SAAS;IACT,YAAY;CACb,CAAC"}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
interface PaperTrailOptions {
|
|
2
|
-
debug?: boolean;
|
|
3
|
-
log?: any;
|
|
4
|
-
exclude?: string[];
|
|
5
|
-
excludeExtras?: string[];
|
|
6
|
-
excludeVirtualAttributes?: boolean;
|
|
7
|
-
censor?: string[];
|
|
8
|
-
revisionAttribute?: string;
|
|
9
|
-
revisionModel?: string;
|
|
10
|
-
revisionChangeModel?: string;
|
|
11
|
-
enableRevisionChangeModel?: boolean;
|
|
12
|
-
UUID?: boolean;
|
|
13
|
-
mixedDocumentReference?: boolean;
|
|
14
|
-
underscored?: boolean;
|
|
15
|
-
underscoredAttributes?: boolean;
|
|
16
|
-
includeReferences?: string[];
|
|
17
|
-
defaultAttributes?: {
|
|
18
|
-
documentId: string;
|
|
19
|
-
revisionId: string;
|
|
20
|
-
autoGenerated: string;
|
|
21
|
-
documentUuid?: string;
|
|
22
|
-
};
|
|
23
|
-
als?: any;
|
|
24
|
-
userModel?: boolean;
|
|
25
|
-
userModelAttribute?: string;
|
|
26
|
-
tenantModel?: boolean;
|
|
27
|
-
tenantModelAttribute?: string;
|
|
28
|
-
enableCompression?: boolean;
|
|
29
|
-
enableMigration?: boolean;
|
|
30
|
-
enableStrictDiff?: boolean;
|
|
31
|
-
continuationNamespace?: any;
|
|
32
|
-
continuationKey?: string;
|
|
33
|
-
continuationTenantKey?: string;
|
|
34
|
-
metaDataFields?: any;
|
|
35
|
-
metaDataContinuationKey?: string;
|
|
36
|
-
mysql?: boolean;
|
|
37
|
-
}
|
|
38
|
-
interface ModelInstance {
|
|
39
|
-
get: (key?: string) => Record<string, any> | any;
|
|
40
|
-
set: (key: string, value: any) => void;
|
|
41
|
-
save: () => Promise<any>;
|
|
42
|
-
[key: string]: any;
|
|
43
|
-
}
|
|
44
|
-
interface ModelOptions {
|
|
45
|
-
noPaperTrail?: boolean;
|
|
46
|
-
[key: string]: any;
|
|
47
|
-
}
|
|
48
|
-
declare const paperTrail: {
|
|
49
|
-
init: (sequelize: any, sequelizePackage: any, optionsArg?: PaperTrailOptions) => void;
|
|
50
|
-
hasPaperTrail: () => boolean;
|
|
51
|
-
defineModels: (db: any) => void;
|
|
52
|
-
};
|
|
53
|
-
export default paperTrail;
|
|
54
|
-
export type { PaperTrailOptions, ModelInstance, ModelOptions };
|
|
@@ -1,236 +0,0 @@
|
|
|
1
|
-
import _ from 'lodash';
|
|
2
|
-
import helpers from './helpers.js';
|
|
3
|
-
const censorText = "**********";
|
|
4
|
-
let failHard = false;
|
|
5
|
-
let Sequelize = null;
|
|
6
|
-
const paperTrail = {
|
|
7
|
-
init: (sequelize, sequelizePackage, optionsArg) => {
|
|
8
|
-
Sequelize = sequelizePackage;
|
|
9
|
-
// In case that options is being parsed as a readonly attribute.
|
|
10
|
-
// Or it is not passed at all
|
|
11
|
-
const optsArg = _.cloneDeep(optionsArg || {});
|
|
12
|
-
const defaultOptions = {
|
|
13
|
-
debug: false,
|
|
14
|
-
log: null,
|
|
15
|
-
exclude: [
|
|
16
|
-
'id',
|
|
17
|
-
'createdAt',
|
|
18
|
-
'updatedAt',
|
|
19
|
-
'deletedAt',
|
|
20
|
-
'created_at',
|
|
21
|
-
'updated_at',
|
|
22
|
-
'deleted_at',
|
|
23
|
-
'audit_source',
|
|
24
|
-
'revision',
|
|
25
|
-
],
|
|
26
|
-
// additional fields to exclude on a global basis
|
|
27
|
-
excludeExtras: [],
|
|
28
|
-
excludeVirtualAttributes: true, // by default do not record these
|
|
29
|
-
censor: ["password", "password_salt", "temp_secret", "mfa_totp_secret"],
|
|
30
|
-
revisionAttribute: 'revision',
|
|
31
|
-
revisionModel: 'Revision',
|
|
32
|
-
revisionChangeModel: 'RevisionChange',
|
|
33
|
-
enableRevisionChangeModel: false,
|
|
34
|
-
UUID: false,
|
|
35
|
-
// does this project use int's and UUIDs for some references (postgres)
|
|
36
|
-
mixedDocumentReference: false,
|
|
37
|
-
underscored: false,
|
|
38
|
-
underscoredAttributes: false,
|
|
39
|
-
// always store these keys in a reference value if seen
|
|
40
|
-
includeReferences: [],
|
|
41
|
-
defaultAttributes: {
|
|
42
|
-
documentId: 'documentId',
|
|
43
|
-
revisionId: 'revisionId',
|
|
44
|
-
autoGenerated: 'autoGenerated'
|
|
45
|
-
},
|
|
46
|
-
als: null,
|
|
47
|
-
userModel: false,
|
|
48
|
-
userModelAttribute: 'userId',
|
|
49
|
-
tenantModel: false,
|
|
50
|
-
tenantModelAttribute: 'tenantId',
|
|
51
|
-
enableCompression: false,
|
|
52
|
-
enableMigration: false,
|
|
53
|
-
enableStrictDiff: true,
|
|
54
|
-
continuationNamespace: null,
|
|
55
|
-
continuationKey: 'userId',
|
|
56
|
-
continuationTenantKey: 'tenantId',
|
|
57
|
-
metaDataFields: null,
|
|
58
|
-
metaDataContinuationKey: 'metaData',
|
|
59
|
-
mysql: false,
|
|
60
|
-
};
|
|
61
|
-
if (optsArg.mixedDocumentReference)
|
|
62
|
-
defaultOptions.defaultAttributes.documentUuid = "documentUuid";
|
|
63
|
-
if (optsArg.underscoredAttributes) {
|
|
64
|
-
helpers.toUnderscored(defaultOptions.defaultAttributes);
|
|
65
|
-
}
|
|
66
|
-
// deals with not wanting to overwrite the initial ones, just add some
|
|
67
|
-
if (optsArg.excludeExtras) {
|
|
68
|
-
if (optsArg.exclude) {
|
|
69
|
-
optsArg.exclude = [...optsArg.exclude, ...optsArg.excludeExtras];
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
optsArg.exclude = [...defaultOptions.exclude, ...optsArg.excludeExtras];
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
const options = _.defaults(optsArg, defaultOptions);
|
|
76
|
-
const log = options.log || console.log;
|
|
77
|
-
function createBeforeHook(operation) {
|
|
78
|
-
const beforeHook = function beforeHook(instance, opt) {
|
|
79
|
-
if (options.debug) {
|
|
80
|
-
log('beforeHook called');
|
|
81
|
-
log('instance:', instance);
|
|
82
|
-
log('opt:', opt);
|
|
83
|
-
}
|
|
84
|
-
if (opt.noPaperTrail) {
|
|
85
|
-
if (options.debug) {
|
|
86
|
-
log('noPaperTrail set, skipping');
|
|
87
|
-
}
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
// Store the original values for comparison
|
|
91
|
-
const originalValues = instance.get();
|
|
92
|
-
instance.set('_paperTrailOriginalValues', originalValues);
|
|
93
|
-
};
|
|
94
|
-
return beforeHook;
|
|
95
|
-
}
|
|
96
|
-
function createAfterHook(operation) {
|
|
97
|
-
const afterHook = function afterHook(instance, opt) {
|
|
98
|
-
if (options.debug) {
|
|
99
|
-
log('afterHook called');
|
|
100
|
-
log('instance:', instance);
|
|
101
|
-
log('opt:', opt);
|
|
102
|
-
}
|
|
103
|
-
if (opt.noPaperTrail) {
|
|
104
|
-
if (options.debug) {
|
|
105
|
-
log('noPaperTrail set, skipping');
|
|
106
|
-
}
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
// Get the original values and current values
|
|
110
|
-
const originalValues = instance.get('_paperTrailOriginalValues') || {};
|
|
111
|
-
const currentValues = instance.get();
|
|
112
|
-
// Remove the temporary field
|
|
113
|
-
delete currentValues._paperTrailOriginalValues;
|
|
114
|
-
// Calculate differences
|
|
115
|
-
const differences = helpers.calcDelta(originalValues, currentValues, options.exclude || [], options.enableStrictDiff || false, options.debug);
|
|
116
|
-
if (differences && differences.length > 0) {
|
|
117
|
-
// Create revision record
|
|
118
|
-
const revisionData = {
|
|
119
|
-
documentId: instance.get(options.defaultAttributes.documentId),
|
|
120
|
-
revision: instance.get(options.revisionAttribute),
|
|
121
|
-
document: JSON.stringify(currentValues),
|
|
122
|
-
operation: operation,
|
|
123
|
-
changes: JSON.stringify(differences),
|
|
124
|
-
createdAt: new Date()
|
|
125
|
-
};
|
|
126
|
-
// Add user information if available
|
|
127
|
-
if (options.userModel && options.als) {
|
|
128
|
-
const user = options.als.get(options.continuationKey);
|
|
129
|
-
if (user) {
|
|
130
|
-
revisionData[options.userModelAttribute] = user;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
// Add tenant information if available
|
|
134
|
-
if (options.tenantModel && options.als) {
|
|
135
|
-
const tenant = options.als.get(options.continuationTenantKey);
|
|
136
|
-
if (tenant) {
|
|
137
|
-
revisionData[options.tenantModelAttribute] = tenant;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
// Save revision
|
|
141
|
-
const Revision = sequelize.models[options.revisionModel];
|
|
142
|
-
if (Revision) {
|
|
143
|
-
Revision.create(revisionData).catch((err) => {
|
|
144
|
-
if (failHard) {
|
|
145
|
-
throw err;
|
|
146
|
-
}
|
|
147
|
-
else {
|
|
148
|
-
log('Error creating revision:', err);
|
|
149
|
-
}
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
};
|
|
154
|
-
return afterHook;
|
|
155
|
-
}
|
|
156
|
-
// Add hooks to all models
|
|
157
|
-
Object.keys(sequelize.models).forEach(modelName => {
|
|
158
|
-
const model = sequelize.models[modelName];
|
|
159
|
-
// Add before hooks
|
|
160
|
-
model.addHook('beforeCreate', createBeforeHook('create'));
|
|
161
|
-
model.addHook('beforeUpdate', createBeforeHook('update'));
|
|
162
|
-
model.addHook('beforeDestroy', createBeforeHook('destroy'));
|
|
163
|
-
// Add after hooks
|
|
164
|
-
model.addHook('afterCreate', createAfterHook('create'));
|
|
165
|
-
model.addHook('afterUpdate', createAfterHook('update'));
|
|
166
|
-
model.addHook('afterDestroy', createAfterHook('destroy'));
|
|
167
|
-
});
|
|
168
|
-
},
|
|
169
|
-
hasPaperTrail: function hasPaperTrail() {
|
|
170
|
-
return Sequelize !== null;
|
|
171
|
-
},
|
|
172
|
-
defineModels: function defineModels(db) {
|
|
173
|
-
if (!Sequelize) {
|
|
174
|
-
throw new Error('PaperTrail not initialized. Call paperTrail.init() first.');
|
|
175
|
-
}
|
|
176
|
-
const Revision = db.define('Revision', {
|
|
177
|
-
id: {
|
|
178
|
-
type: Sequelize.INTEGER,
|
|
179
|
-
primaryKey: true,
|
|
180
|
-
autoIncrement: true
|
|
181
|
-
},
|
|
182
|
-
documentId: {
|
|
183
|
-
type: Sequelize.STRING,
|
|
184
|
-
allowNull: false
|
|
185
|
-
},
|
|
186
|
-
revision: {
|
|
187
|
-
type: Sequelize.INTEGER,
|
|
188
|
-
allowNull: false
|
|
189
|
-
},
|
|
190
|
-
document: {
|
|
191
|
-
type: Sequelize.TEXT,
|
|
192
|
-
allowNull: false
|
|
193
|
-
},
|
|
194
|
-
operation: {
|
|
195
|
-
type: Sequelize.STRING,
|
|
196
|
-
allowNull: false
|
|
197
|
-
},
|
|
198
|
-
changes: {
|
|
199
|
-
type: Sequelize.TEXT,
|
|
200
|
-
allowNull: true
|
|
201
|
-
},
|
|
202
|
-
userId: {
|
|
203
|
-
type: Sequelize.INTEGER,
|
|
204
|
-
allowNull: true
|
|
205
|
-
},
|
|
206
|
-
tenantId: {
|
|
207
|
-
type: Sequelize.INTEGER,
|
|
208
|
-
allowNull: true
|
|
209
|
-
},
|
|
210
|
-
createdAt: {
|
|
211
|
-
type: Sequelize.DATE,
|
|
212
|
-
allowNull: false
|
|
213
|
-
}
|
|
214
|
-
}, {
|
|
215
|
-
tableName: 'revisions',
|
|
216
|
-
timestamps: false
|
|
217
|
-
});
|
|
218
|
-
// Add associations if user and tenant models exist
|
|
219
|
-
if (db.models.User) {
|
|
220
|
-
Revision.belongsTo(db.models.User, { foreignKey: 'userId' });
|
|
221
|
-
}
|
|
222
|
-
if (db.models.Tenant) {
|
|
223
|
-
Revision.belongsTo(db.models.Tenant, { foreignKey: 'tenantId' });
|
|
224
|
-
}
|
|
225
|
-
Revision.associate = function associate(models) {
|
|
226
|
-
if (models.User) {
|
|
227
|
-
Revision.belongsTo(models.User, { foreignKey: 'userId' });
|
|
228
|
-
}
|
|
229
|
-
if (models.Tenant) {
|
|
230
|
-
Revision.belongsTo(models.Tenant, { foreignKey: 'tenantId' });
|
|
231
|
-
}
|
|
232
|
-
};
|
|
233
|
-
}
|
|
234
|
-
};
|
|
235
|
-
export default paperTrail;
|
|
236
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../ts/paper-trail/index.ts"],"names":[],"mappings":"AACA,OAAO,CAAC,MAAM,QAAQ,CAAC;AACvB,OAAO,OAAO,MAAM,cAAc,CAAC;AAInC,MAAM,UAAU,GAAG,YAAY,CAAC;AAEhC,IAAI,QAAQ,GAAG,KAAK,CAAC;AACrB,IAAI,SAAS,GAAQ,IAAI,CAAC;AAoD1B,MAAM,UAAU,GAAG;IACjB,IAAI,EAAE,CAAC,SAAc,EAAE,gBAAqB,EAAE,UAA8B,EAAQ,EAAE;QACpF,SAAS,GAAG,gBAAgB,CAA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I,MAAM,CAAC,MAAM,EAAE,CAAC;gBAClB,QAAQ,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE,CAAC,CAAC;YAChE,CAAC;QACH,CAAC,CAAC;IACJ,CAAC;CACF,CAAC;AAEF,eAAe,UAAU,CAAC"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { ArgumentParser } from 'argparse';
|
|
2
|
-
interface CLIInitOptions {
|
|
3
|
-
asyncFcns?: (() => Promise<void>)[];
|
|
4
|
-
extraFcns?: (() => void)[];
|
|
5
|
-
sleepTime?: number;
|
|
6
|
-
}
|
|
7
|
-
interface PromptOptions {
|
|
8
|
-
[key: string]: {
|
|
9
|
-
type: string;
|
|
10
|
-
description?: string;
|
|
11
|
-
required?: boolean;
|
|
12
|
-
default?: any;
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
declare const setupCLIParser: (description: string) => ArgumentParser;
|
|
16
|
-
declare const commonCLIInit: (options?: CLIInitOptions) => Promise<void>;
|
|
17
|
-
declare const promptCLIAsync: (options: PromptOptions) => Promise<Record<string, any>>;
|
|
18
|
-
declare const waitCLIPrompt: PromptOptions;
|
|
19
|
-
declare const continueCLIPrompt: PromptOptions;
|
|
20
|
-
declare const cliSleep: (ms: number) => Promise<void>;
|
|
21
|
-
export { commonCLIInit, continueCLIPrompt, promptCLIAsync, setupCLIParser, cliSleep, waitCLIPrompt, type CLIInitOptions, type PromptOptions };
|
package/dist/ts/prompts/index.js
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
/* Essentia Common Prompt Functions */
|
|
2
|
-
// This file contains common prompt functions that are used in CLI scripts
|
|
3
|
-
// that are run in the each project. These functions are used to
|
|
4
|
-
// prompt the user for input and to wait for the user to press enter
|
|
5
|
-
// before continuing. This is useful for scripts that are run in the
|
|
6
|
-
// command line and need to wait for the user to do something before
|
|
7
|
-
// continuing.
|
|
8
|
-
import { S4Logger } from "../logger/s4-logger.js";
|
|
9
|
-
import { ArgumentParser } from 'argparse';
|
|
10
|
-
import prompt from "prompt";
|
|
11
|
-
const logger = new S4Logger();
|
|
12
|
-
// New common argument parser which makes parsing and setting up commandline options easier
|
|
13
|
-
const setupCLIParser = (description) => {
|
|
14
|
-
logger.info(description);
|
|
15
|
-
return new ArgumentParser({ description });
|
|
16
|
-
};
|
|
17
|
-
// a common init function which waits for the command prompt to be delivered
|
|
18
|
-
// a common use is for the awaiting of the queues to initialize before running
|
|
19
|
-
const commonCLIInit = async (options = {}) => {
|
|
20
|
-
//add in defaults to options if they have not been specified or object is {}
|
|
21
|
-
const defaultOptions = {
|
|
22
|
-
asyncFcns: [],
|
|
23
|
-
extraFcns: [],
|
|
24
|
-
sleepTime: 1000,
|
|
25
|
-
...options
|
|
26
|
-
};
|
|
27
|
-
// Sleep for 1 second to allow the prompt to be displayed
|
|
28
|
-
// at the end of bootstrap logs
|
|
29
|
-
await cliSleep(defaultOptions.sleepTime);
|
|
30
|
-
defaultOptions.extraFcns.forEach(fcn => {
|
|
31
|
-
fcn();
|
|
32
|
-
});
|
|
33
|
-
for (const fcn of defaultOptions.asyncFcns) {
|
|
34
|
-
await fcn();
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
const promptCLIAsync = async (options) => {
|
|
38
|
-
return new Promise((resolve, reject) => {
|
|
39
|
-
prompt.start();
|
|
40
|
-
prompt.get(options, (err, res) => {
|
|
41
|
-
if (err) {
|
|
42
|
-
reject(err);
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
resolve(res);
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
};
|
|
50
|
-
// A predefined waitPrompt for use at the end of the scripts that use
|
|
51
|
-
// message queues. Message Queues often take a bit to fire
|
|
52
|
-
const waitCLIPrompt = {
|
|
53
|
-
"Push <enter> when done": {
|
|
54
|
-
type: "boolean"
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
const continueCLIPrompt = {
|
|
58
|
-
"Push <enter> to continue": {
|
|
59
|
-
type: "boolean"
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
const cliSleep = async (ms) => {
|
|
63
|
-
return new Promise((resolve) => {
|
|
64
|
-
setTimeout(resolve, ms);
|
|
65
|
-
});
|
|
66
|
-
};
|
|
67
|
-
export { commonCLIInit, continueCLIPrompt, promptCLIAsync, setupCLIParser, cliSleep, waitCLIPrompt };
|
|
68
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../ts/prompts/index.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,0EAA0E;AAC1E,kEAAkE;AAClE,qEAAqE;AACrE,sEAAsE;AACtE,qEAAqE;AACrE,eAAe;AAEf,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,MAAM,MAAM,GAAG,IAAI,QAAQ,EAAE,CAAC;AAiB9B,2FAA2F;AAC3F,MAAM,cAAc,GAAG,CAAC,WAAmB,EAAkB,EAAE;IAC7D,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IACzB,OAAO,IAAI,cAAc,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC;AAC7C,CAAC,CAAC;AAEF,4EAA4E;AAC5E,8EAA8E;AAC9E,MAAM,aAAa,GAAG,KAAK,EAAE,UAA0B,EAAE,EAAiB,EAAE;IAC1E,4EAA4E;IAC5E,MAAM,cAAc,GAA6B;QAC/C,SAAS,EAAE,EAAE;QACb,SAAS,EAAE,EAAE;QACb,SAAS,EAAE,IAAI;QACf,GAAG,OAAO;KACX,CAAC;IAEF,yDAAyD;IACzD,+BAA+B;IAC/B,MAAM,QAAQ,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;IAEzC,cAAc,CAAC,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