@sera4/essentia 1.1.65 → 3.0.6

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.
Files changed (112) hide show
  1. package/README.md +352 -8
  2. package/dist/ts/cache/index.d.ts +33 -0
  3. package/dist/ts/cache/index.js +171 -0
  4. package/dist/ts/cache/index.js.map +1 -0
  5. package/dist/ts/configurations/server-config.d.ts +4 -0
  6. package/dist/ts/configurations/server-config.js +2 -0
  7. package/dist/ts/configurations/server-config.js.map +1 -0
  8. package/dist/ts/constants/index.d.ts +7 -0
  9. package/{constants → dist/ts/constants}/index.js +5 -6
  10. package/dist/ts/constants/index.js.map +1 -0
  11. package/dist/ts/cycle/index.d.ts +53 -0
  12. package/dist/ts/cycle/index.js +169 -0
  13. package/dist/ts/cycle/index.js.map +1 -0
  14. package/dist/ts/dns/DnsCache.d.ts +50 -0
  15. package/dist/ts/dns/DnsCache.js +137 -0
  16. package/dist/ts/dns/DnsCache.js.map +1 -0
  17. package/dist/ts/dns/index.d.ts +4 -0
  18. package/dist/ts/dns/index.js +4 -0
  19. package/dist/ts/dns/index.js.map +1 -0
  20. package/dist/ts/formatter/index.d.ts +44 -0
  21. package/dist/ts/formatter/index.js +76 -0
  22. package/dist/ts/formatter/index.js.map +1 -0
  23. package/dist/ts/hal/index.d.ts +26 -0
  24. package/dist/ts/hal/index.js +70 -0
  25. package/dist/ts/hal/index.js.map +1 -0
  26. package/dist/ts/health/index.d.ts +53 -0
  27. package/dist/ts/health/index.js +165 -0
  28. package/dist/ts/health/index.js.map +1 -0
  29. package/dist/ts/helpers/index.d.ts +1 -0
  30. package/dist/ts/helpers/index.js +2 -0
  31. package/dist/ts/helpers/index.js.map +1 -0
  32. package/dist/ts/helpers/test-server-wrapper.d.ts +56 -0
  33. package/dist/ts/helpers/test-server-wrapper.js +144 -0
  34. package/dist/ts/helpers/test-server-wrapper.js.map +1 -0
  35. package/dist/ts/index.d.ts +21 -0
  36. package/dist/ts/index.js +25 -0
  37. package/dist/ts/index.js.map +1 -0
  38. package/dist/ts/last-commit/index.d.ts +12 -0
  39. package/dist/ts/last-commit/index.js +82 -0
  40. package/dist/ts/last-commit/index.js.map +1 -0
  41. package/dist/ts/logger/index.d.ts +3 -0
  42. package/dist/ts/logger/index.js +4 -0
  43. package/dist/ts/logger/index.js.map +1 -0
  44. package/dist/ts/logger/s4-logger.d.ts +23 -0
  45. package/dist/ts/logger/s4-logger.js +103 -0
  46. package/dist/ts/logger/s4-logger.js.map +1 -0
  47. package/dist/ts/paginator/index.d.ts +2 -0
  48. package/dist/ts/paginator/index.js +3 -0
  49. package/dist/ts/paginator/index.js.map +1 -0
  50. package/dist/ts/paginator/s4-pagination.d.ts +26 -0
  51. package/dist/ts/paginator/s4-pagination.js +49 -0
  52. package/dist/ts/paginator/s4-pagination.js.map +1 -0
  53. package/dist/ts/paginator/sql-pagination.d.ts +52 -0
  54. package/dist/ts/paginator/sql-pagination.js +157 -0
  55. package/dist/ts/paginator/sql-pagination.js.map +1 -0
  56. package/dist/ts/paper-trail/helpers.d.ts +14 -0
  57. package/dist/ts/paper-trail/helpers.js +74 -0
  58. package/dist/ts/paper-trail/helpers.js.map +1 -0
  59. package/dist/ts/paper-trail/index.d.ts +54 -0
  60. package/dist/ts/paper-trail/index.js +236 -0
  61. package/dist/ts/paper-trail/index.js.map +1 -0
  62. package/dist/ts/prompts/index.d.ts +21 -0
  63. package/dist/ts/prompts/index.js +68 -0
  64. package/dist/ts/prompts/index.js.map +1 -0
  65. package/dist/ts/queue/index.d.ts +196 -0
  66. package/dist/ts/queue/index.js +371 -0
  67. package/dist/ts/queue/index.js.map +1 -0
  68. package/dist/ts/queue/publisher.d.ts +41 -0
  69. package/dist/ts/queue/publisher.js +84 -0
  70. package/dist/ts/queue/publisher.js.map +1 -0
  71. package/dist/ts/queue/queue-logger.d.ts +10 -0
  72. package/dist/ts/queue/queue-logger.js +35 -0
  73. package/dist/ts/queue/queue-logger.js.map +1 -0
  74. package/dist/ts/queue/subscriber.d.ts +55 -0
  75. package/dist/ts/queue/subscriber.js +98 -0
  76. package/dist/ts/queue/subscriber.js.map +1 -0
  77. package/dist/ts/safe-proxy/index.d.ts +35 -0
  78. package/dist/ts/safe-proxy/index.js +54 -0
  79. package/dist/ts/safe-proxy/index.js.map +1 -0
  80. package/dist/ts/serializer/index.d.ts +52 -0
  81. package/dist/ts/serializer/index.js +83 -0
  82. package/dist/ts/serializer/index.js.map +1 -0
  83. package/dist/ts/utils/index.d.ts +49 -0
  84. package/dist/ts/utils/index.js +157 -0
  85. package/dist/ts/utils/index.js.map +1 -0
  86. package/package.json +52 -11
  87. package/package.tar.gz +0 -0
  88. package/cache/index.js +0 -188
  89. package/formatter/index.js +0 -81
  90. package/hal/README.md +0 -54
  91. package/hal/index.js +0 -75
  92. package/health/health-logger.js +0 -40
  93. package/health/index.js +0 -188
  94. package/helpers/index.js +0 -1
  95. package/helpers/test-server-wrapper.js +0 -196
  96. package/last-commit.js +0 -12
  97. package/last_commit/index.js +0 -82
  98. package/logger/s4-logger.js +0 -128
  99. package/paginator/README.md +0 -183
  100. package/paginator/s4-pagination.js +0 -51
  101. package/paginator/sql-pagination.js +0 -178
  102. package/paper-trail/README.md +0 -68
  103. package/paper-trail/helpers.js +0 -99
  104. package/paper-trail/index.js +0 -842
  105. package/prompts/index.js +0 -78
  106. package/queue/index.js +0 -414
  107. package/queue/publisher.js +0 -96
  108. package/queue/queue-logger.js +0 -40
  109. package/queue/subscriber.js +0 -107
  110. package/safe_proxy/index.js +0 -61
  111. package/serializer/index.js +0 -90
  112. package/utils/index.js +0 -74
@@ -0,0 +1,236 @@
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
@@ -0,0 +1 @@
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,CAAC;QAC7B,gEAAgE;QAChE,6BAA6B;QAC7B,MAAM,OAAO,GAAG,CAAC,CAAC,SAAS,CAAC,UAAU,IAAI,EAAE,CAAC,CAAC;QAE9C,MAAM,cAAc,GAAsB;YACxC,KAAK,EAAE,KAAK;YACZ,GAAG,EAAE,IAAI;YACT,OAAO,EAAE;gBACP,IAAI;gBACJ,WAAW;gBACX,WAAW;gBACX,WAAW;gBACX,YAAY;gBACZ,YAAY;gBACZ,YAAY;gBACZ,cAAc;gBACd,UAAU;aACX;YACD,iDAAiD;YACjD,aAAa,EAAE,EAAE;YACjB,wBAAwB,EAAE,IAAI,EAAE,iCAAiC;YACjE,MAAM,EAAE,CAAC,UAAU,EAAE,eAAe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AS,CAAC,OAAO;gBACvB,SAAS,EAAE,IAAI;aAChB;YACD,SAAS,EAAE;gBACT,IAAI,EAAE,SAAS,CAAC,IAAI;gBACpB,SAAS,EAAE,KAAK;aACjB;SACF,EAAE;YACD,SAAS,EAAE,WAAW;YACtB,UAAU,EAAE,KAAK;SAClB,CAAC,CAAC;QAEH,mDAAmD;QACnD,IAAI,EAAE,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;YACnB,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,UAAU,EAAE,QAAQ,EAAE,CAAC,CAAC;QAC/D,CAAC;QAED,IAAI,EAAE,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;YACrB,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE,CAAC,CAAC;QACnE,CAAC;QAED,QAAQ,CAAC,SAAS,GAAG,SAAS,SAAS,CAAC,MAAW;YACjD,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC;gBAChB,QAAQ,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,UAAU,EAAE,QAAQ,EAAE,CAAC,CAAC;YAC5D,CAAC;YACD,IAAI,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"}
@@ -0,0 +1,21 @@
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 };
@@ -0,0 +1,68 @@
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
@@ -0,0 +1 @@
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,yD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,EAGd,CAAC"}
@@ -0,0 +1,196 @@
1
+ interface ConnectionOptions {
2
+ connectionUrl: string;
3
+ logEnabled?: boolean;
4
+ retryInterval?: number;
5
+ }
6
+ interface Exchange {
7
+ name: string;
8
+ type: string;
9
+ options?: any;
10
+ }
11
+ interface PublisherOptions {
12
+ exchange: Exchange;
13
+ }
14
+ interface SubscriberOptions {
15
+ exchange: Exchange;
16
+ queue: {
17
+ name: string;
18
+ options?: any;
19
+ };
20
+ key: string;
21
+ }
22
+ interface UnregisterSubscriberOptions {
23
+ exchange: Exchange;
24
+ queue: {
25
+ name: string;
26
+ };
27
+ key: string;
28
+ }
29
+ type MessageListener = (payload: any, error?: any) => void;
30
+ /**
31
+ * An interface to AMQP service
32
+ */
33
+ declare class S4Queue {
34
+ private connection;
35
+ private connectionTestChannel;
36
+ private retry;
37
+ private pubs;
38
+ private subs;
39
+ constructor();
40
+ /**
41
+ * Tests the connection to the service.
42
+ * Internally, the same connection is used for test
43
+ * and production code, but a separate channel is opened.
44
+ * Once the channel is obtained, there is an assert on the
45
+ * existence of a topic exchange called '--health-check--'.
46
+ * The following must be satisfied for the test to pass
47
+ * 1. must be connected
48
+ * 2. must have a test channel
49
+ * 3. must assert the exchange
50
+ */
51
+ testConnection(): Promise<void>;
52
+ /**
53
+ * Opens a connection to AMQP server.
54
+ * @param options Connection parameters. At the very least options.connectionUrl must be present.
55
+ */
56
+ openConnection(options: ConnectionOptions): Promise<void>;
57
+ /**
58
+ * Closes the connection to AMQP server
59
+ * and clears the registered publishers
60
+ * and subscribers
61
+ */
62
+ closeConnection(): Promise<void>;
63
+ /**
64
+ * Returns whether we have an active connection
65
+ * or not.
66
+ */
67
+ isConnected(): boolean;
68
+ /**
69
+ * @deprecated Use registerPublisher
70
+ * Registers a new direct publisher on the given exchange.
71
+ * If exchange doesn't exist, one will be created.
72
+ * @param exchange the name of the exchange on AMQP service.
73
+ */
74
+ registerDirectPublisher(exchange: string): Promise<void>;
75
+ /**
76
+ * @deprecated Use registerPublisher
77
+ * Registers a new topic publisher on the given exchange.
78
+ * If exchange doesn't exist, one will be created.
79
+ * @param exchange the name of the exchange on AMQP service.
80
+ */
81
+ registerTopicPublisher(exchange: string): Promise<void>;
82
+ /**
83
+ * @deprecated Use registerPublisher
84
+ * Registers a new fanout publisher on the given exchange.
85
+ * If exchange doesn't exist, one will be created.
86
+ * @param exchange the name of the exchange on AMQP service.
87
+ */
88
+ registerFanoutPublisher(exchange: string): Promise<void>;
89
+ /**
90
+ * Registers a new publisher
91
+ * @param options connection options.
92
+ */
93
+ registerPublisher(options: PublisherOptions): Promise<void>;
94
+ /**
95
+ * Checks whether or not a publisher with given parameters
96
+ * has been registered already
97
+ * @param exchange the name of the exchange.
98
+ * @returns true if registered already, false otherwise
99
+ */
100
+ hasPublisher(exchange: string): boolean;
101
+ /**
102
+ * Removes a previously registered publisher
103
+ * @param options
104
+ */
105
+ unregisterPublisher(options: PublisherOptions): Promise<void>;
106
+ /**
107
+ * @deprecated Use registerSubscriber
108
+ * Registers a new direct subscriber on a given exchange and queue.
109
+ * If exchange and queue don't exists, they'll be created
110
+ * and bound through the provided routing key.
111
+ * @param exchange the name of the exchange.
112
+ * @param queue the name of the queue.
113
+ * @param key the name of the routing key.
114
+ */
115
+ registerDirectSubscriber(exchange: string, queue: string, key: string): Promise<void>;
116
+ /**
117
+ * @deprecated Use registerSubscriber
118
+ * Registers a new topic subscriber on a given exchange and queue.
119
+ * If exchange and queue don't exists, they'll be created
120
+ * and bound through the provided routing key.
121
+ * @param exchange the name of the exchange.
122
+ * @param queue the name of the queue.
123
+ * @param key the name of the routing key.
124
+ */
125
+ registerTopicSubscriber(exchange: string, queue: string, key: string): Promise<void>;
126
+ /**
127
+ * An overloaded version of registering a subscriber
128
+ * allowing for more fine tuned parameters
129
+ * @param options subscribing options
130
+ */
131
+ registerSubscriber(options: SubscriberOptions): Promise<void>;
132
+ /**
133
+ * Checks whether or not a subscriber with given parameters
134
+ * has been registered already
135
+ * @param exchange the name of the exchange.
136
+ * @param queue the name of the queue.
137
+ * @param key the name of the routing key.
138
+ * @returns true if registered already, false otherwise
139
+ */
140
+ hasSubscriber(exchange: string, queue: string, key: string): boolean;
141
+ /**
142
+ * Removes a previously registered subscriber
143
+ * @param options
144
+ */
145
+ unregisterSubscriber(options: UnregisterSubscriberOptions): Promise<void>;
146
+ /**
147
+ * Publishes a message on a given exchange with routing key.
148
+ * @param exchange the name of the exchange.
149
+ * @param key the name of the routing key.
150
+ * @param msg a JSON object as the message.
151
+ */
152
+ publishDirectMessage(exchange: string, key: string, msg: any): Promise<string>;
153
+ /**
154
+ * Publishes a message on a given exchange with a topic.
155
+ * @param exchange the name of the exchange.
156
+ * @param topic the name of the topic.
157
+ * @param msg a JSON object as the message.
158
+ */
159
+ publishTopicMessage(exchange: string, topic: string, msg: any): Promise<string>;
160
+ /**
161
+ * Publish a message to the exchange
162
+ * @param exchange name of exchange
163
+ * @param key name of the key or topic
164
+ * @param msg payload to be published
165
+ */
166
+ publishMessage(exchange: string, key: string, msg: any): Promise<string>;
167
+ /**
168
+ * Binds an exchange to a queue
169
+ * @param exchange the name of the exchange.
170
+ * @param queue the name of the queue.
171
+ * @param pattern (optional) pattern for routing key
172
+ */
173
+ bindQueueToExchange(exchange: string, queue: string, pattern?: string): Promise<void>;
174
+ /**
175
+ * Adds a listener for a specific key.
176
+ * If a subscriber that was registered was found
177
+ * with that key, the listener is added, otherwise
178
+ * it's ignored
179
+ * @param key AMQP routing key
180
+ * @param listener callback
181
+ */
182
+ addMessageListener(key: string, listener: MessageListener): void;
183
+ /**
184
+ * Updates the connection reference to all the previously
185
+ * registered publishers and subscribers.
186
+ * After we successfully establish a connection and register pubs/subs,
187
+ * it's possible for the connection to break. This object will try
188
+ * to re-establish a new connection every 3 seconds (or whatever configuration is set)
189
+ * and if a new connection is established, we need to pass that connection to
190
+ * all our pubs/subs, otherwise they'll be operating with old/stale references
191
+ * @param connRef a new connection reference to the AMQP service
192
+ */
193
+ updatePubsAndSubsConnectionRef(connRef: any): void;
194
+ }
195
+ declare const queue: S4Queue;
196
+ export default queue;