@keetanetwork/anchor 0.0.29 → 0.0.30

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 (50) hide show
  1. package/lib/http-server-shared.d.ts +14 -0
  2. package/lib/http-server-shared.d.ts.map +1 -0
  3. package/lib/http-server-shared.js +108 -0
  4. package/lib/http-server-shared.js.map +1 -0
  5. package/lib/http-server.d.ts +62 -0
  6. package/lib/http-server.d.ts.map +1 -0
  7. package/lib/http-server.js +431 -0
  8. package/lib/http-server.js.map +1 -0
  9. package/lib/log/common.d.ts +35 -0
  10. package/lib/log/common.d.ts.map +1 -0
  11. package/lib/log/common.js +19 -0
  12. package/lib/log/common.js.map +1 -0
  13. package/lib/queue/common.d.ts +23 -0
  14. package/lib/queue/common.d.ts.map +1 -0
  15. package/lib/queue/common.js +47 -0
  16. package/lib/queue/common.js.map +1 -0
  17. package/lib/queue/drivers/queue_file.d.ts +17 -0
  18. package/lib/queue/drivers/queue_file.d.ts.map +1 -0
  19. package/lib/queue/drivers/queue_file.js +100 -0
  20. package/lib/queue/drivers/queue_file.js.map +1 -0
  21. package/lib/queue/drivers/queue_sqlite3.d.ts +28 -0
  22. package/lib/queue/drivers/queue_sqlite3.d.ts.map +1 -0
  23. package/lib/queue/drivers/queue_sqlite3.js +379 -0
  24. package/lib/queue/drivers/queue_sqlite3.js.map +1 -0
  25. package/lib/queue/index.d.ts +341 -0
  26. package/lib/queue/index.d.ts.map +1 -0
  27. package/lib/queue/index.js +940 -0
  28. package/lib/queue/index.js.map +1 -0
  29. package/lib/queue/internal.d.ts +8 -0
  30. package/lib/queue/internal.d.ts.map +1 -0
  31. package/lib/queue/internal.js +28 -0
  32. package/lib/queue/internal.js.map +1 -0
  33. package/lib/queue/pipeline.d.ts +149 -0
  34. package/lib/queue/pipeline.d.ts.map +1 -0
  35. package/lib/queue/pipeline.js +296 -0
  36. package/lib/queue/pipeline.js.map +1 -0
  37. package/lib/utils/asleep.d.ts +2 -0
  38. package/lib/utils/asleep.d.ts.map +1 -0
  39. package/lib/utils/asleep.js +3 -0
  40. package/lib/utils/asleep.js.map +1 -0
  41. package/lib/utils/defer.d.ts +3 -0
  42. package/lib/utils/defer.d.ts.map +1 -0
  43. package/lib/utils/defer.js +3 -0
  44. package/lib/utils/defer.js.map +1 -0
  45. package/npm-shrinkwrap.json +37 -1375
  46. package/package.json +1 -1
  47. package/services/asset-movement/common.d.ts +26 -5
  48. package/services/asset-movement/common.d.ts.map +1 -1
  49. package/services/asset-movement/common.js +136 -3
  50. package/services/asset-movement/common.js.map +1 -1
@@ -0,0 +1,296 @@
1
+ import { KeetaAnchorQueueRunner } from './index.js';
2
+ import { MethodLogger } from './internal.js';
3
+ /**
4
+ * A KeetaAnchorQueueRunner that uses `any` for the user types
5
+ * This is helpful for expressing pipelines where the inputs
6
+ * and outputs of various stages are not known ahead of time
7
+ */
8
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
9
+ class KeetaAnchorQueueRunnerAny extends KeetaAnchorQueueRunner {
10
+ processor() { throw (new Error('not implemented')); }
11
+ decodeRequest() { throw (new Error('not implemented')); }
12
+ decodeResponse() { throw (new Error('not implemented')); }
13
+ encodeRequest() { throw (new Error('not implemented')); }
14
+ encodeResponse() { throw (new Error('not implemented')); }
15
+ }
16
+ /**
17
+ * Abstract base class for queue advanced pipelines -- this provides
18
+ * a standardized way to implement custom processing pipelines that
19
+ * consist of multiple stages with custom behavior
20
+ */
21
+ export class KeetaAnchorQueuePipelineAdvanced {
22
+ id;
23
+ baseQueue;
24
+ logger;
25
+ queues;
26
+ initPromise;
27
+ destroyed = false;
28
+ static StageID = {
29
+ // @ts-ignore
30
+ first: Symbol('first'),
31
+ // @ts-ignore
32
+ last: Symbol('last')
33
+ };
34
+ constructor(options) {
35
+ this.logger = options.logger;
36
+ this.id = options.id ?? crypto.randomUUID();
37
+ this.baseQueue = options.baseQueue;
38
+ this.queues = [];
39
+ }
40
+ methodLogger(method) {
41
+ return (MethodLogger(this.logger, {
42
+ class: 'KeetaAnchorQueuePipelineAdvanced',
43
+ file: 'src/lib/queue/pipeline.ts',
44
+ method: method,
45
+ instanceID: this.id
46
+ }));
47
+ }
48
+ /**
49
+ * Create a new queue to use in a pipeline stage
50
+ * It will be released when the pipeline is destroyed
51
+ *
52
+ * @param name The name of the queue
53
+ * @returns The created queue
54
+ */
55
+ async createQueue(name) {
56
+ const retval = await this.baseQueue.partition(name);
57
+ this.queues.push(retval);
58
+ return (retval);
59
+ }
60
+ async init() {
61
+ const logger = this.methodLogger('init');
62
+ if (this.destroyed) {
63
+ throw (new Error('Pipeline has been destroyed'));
64
+ }
65
+ if (this.initPromise !== undefined) {
66
+ return (await this.initPromise);
67
+ }
68
+ this.initPromise = (async () => {
69
+ try {
70
+ await this.createPipeline();
71
+ }
72
+ catch (error) {
73
+ logger?.error('Error initializing pipeline:', error);
74
+ try {
75
+ await this.destroy();
76
+ }
77
+ catch {
78
+ /* Ignore */
79
+ }
80
+ throw (error);
81
+ }
82
+ })();
83
+ return (await this.initPromise);
84
+ }
85
+ async add(request) {
86
+ await this.init();
87
+ const stage1 = this.getStage(KeetaAnchorQueuePipelineAdvanced.StageID.first);
88
+ return (await stage1.add(request));
89
+ }
90
+ async get(id) {
91
+ await this.init();
92
+ const firstStage = this.getStage(KeetaAnchorQueuePipelineAdvanced.StageID.first);
93
+ const finalStage = this.getStage(KeetaAnchorQueuePipelineAdvanced.StageID.last);
94
+ const firstEntry = await firstStage.get(id);
95
+ const finalOutput = await finalStage.get(id);
96
+ if (finalOutput === null) {
97
+ return (null);
98
+ }
99
+ return ({
100
+ ...finalOutput,
101
+ request: firstEntry?.request ?? null
102
+ });
103
+ }
104
+ async run(timeoutMs) {
105
+ await this.init();
106
+ const logger = this.methodLogger('run');
107
+ const stage1 = this.getStage(KeetaAnchorQueuePipelineAdvanced.StageID.first);
108
+ let retval = true;
109
+ try {
110
+ retval = await stage1.run(timeoutMs);
111
+ }
112
+ catch (error) {
113
+ logger?.error('Error running stage processor:', error);
114
+ }
115
+ return (retval);
116
+ }
117
+ async maintain() {
118
+ await this.init();
119
+ const logger = this.methodLogger('maintain');
120
+ const stage1 = this.getStage(KeetaAnchorQueuePipelineAdvanced.StageID.first);
121
+ try {
122
+ await stage1.maintain();
123
+ }
124
+ catch (error) {
125
+ logger?.error('Error running stage maintenance:', error);
126
+ }
127
+ }
128
+ async destroy() {
129
+ const logger = this.methodLogger('destroy');
130
+ if (this.destroyed) {
131
+ return;
132
+ }
133
+ this.destroyed = true;
134
+ await this.init();
135
+ for (let index = 0; index < this.queues.length; index++) {
136
+ const queue = this.queues[index];
137
+ if (queue === undefined) {
138
+ continue;
139
+ }
140
+ try {
141
+ logger?.debug(`Destroying queue for stage "#${index}"`);
142
+ await queue.destroy();
143
+ }
144
+ catch (error) {
145
+ logger?.error(`Error destroying queue for stage "#${index}:`, error);
146
+ }
147
+ }
148
+ }
149
+ async [Symbol.asyncDispose]() {
150
+ const logger = this.methodLogger('asyncDispose');
151
+ try {
152
+ await this.destroy();
153
+ }
154
+ catch (error) {
155
+ logger?.error('Error during async dispose:', error);
156
+ }
157
+ }
158
+ }
159
+ /**
160
+ * Abstract base class for queue basic pipelines -- this provides
161
+ * a standardized way to implement custom processing pipelines that
162
+ * consist of multiple stages but do not require batching
163
+ */
164
+ export class KeetaAnchorQueuePipelineBasic extends KeetaAnchorQueuePipelineAdvanced {
165
+ stageRunners;
166
+ constructor(options) {
167
+ super(options);
168
+ /*
169
+ * We start out with no stages, but the createPipeline method
170
+ * will be run during initialization to set them up
171
+ */
172
+ // @ts-ignore
173
+ this.stageRunners = [];
174
+ }
175
+ methodLogger(method) {
176
+ return (MethodLogger(this.logger, {
177
+ class: 'KeetaAnchorQueuePipelineBasic',
178
+ file: 'src/lib/queue/pipeline.ts',
179
+ method: method,
180
+ instanceID: this.id
181
+ }));
182
+ }
183
+ getStage(stageID) {
184
+ if (this.initPromise === undefined) {
185
+ throw (new Error('Pipeline not initialized'));
186
+ }
187
+ if (stageID === KeetaAnchorQueuePipelineAdvanced.StageID.first) {
188
+ const runner = this.stageRunners[0];
189
+ if (runner !== undefined) {
190
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
191
+ return runner;
192
+ }
193
+ throw (new Error('First stage runner not found'));
194
+ }
195
+ else if (stageID === KeetaAnchorQueuePipelineAdvanced.StageID.last) {
196
+ for (let index = this.stageRunners.length - 1; index >= 0; index--) {
197
+ const runner = this.stageRunners[index];
198
+ if (runner !== undefined) {
199
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
200
+ return runner;
201
+ }
202
+ }
203
+ throw (new Error('Last stage runner not found'));
204
+ }
205
+ else {
206
+ for (let index = 0; index < this.stages.length; index++) {
207
+ const stage = this.stages[index];
208
+ if (stage?.name === stageID) {
209
+ const runner = this.stageRunners[index];
210
+ if (runner !== undefined) {
211
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
212
+ return runner;
213
+ }
214
+ }
215
+ }
216
+ return (null);
217
+ }
218
+ }
219
+ /**
220
+ * Create the pipeline from the user-defined stages
221
+ */
222
+ async createPipeline() {
223
+ const logger = this.methodLogger('init');
224
+ let lastRunner = undefined;
225
+ for (const stage of this.stages) {
226
+ if (stage === undefined) {
227
+ break;
228
+ }
229
+ try {
230
+ logger?.debug(`Initializing queue for stage "${stage.name}"`);
231
+ const queue = await this.createQueue(stage.name);
232
+ logger?.debug(`Initializing stage processor for stage "${stage.name}"`);
233
+ /**
234
+ * We have to use this type because we cannot express the relationship
235
+ * between the various generic types in the stages array and the stageRunners array
236
+ */
237
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
238
+ const runnerClass = stage.runner;
239
+ const runnerArgsFirst = stage.args?.[0];
240
+ const runnerArgs0 = {
241
+ id: `${this.id}::runner::${stage.name}`,
242
+ queue: queue,
243
+ logger: this.logger,
244
+ ...runnerArgsFirst
245
+ };
246
+ const runnerArgs = [runnerArgs0, ...(stage.args?.slice(1) ?? [])];
247
+ /*
248
+ * We check the first parameter's type above, but all the remaining
249
+ * parameters are user-defined and we cannot validate them here
250
+ * so we cast to the tuple `any` type to avoid type checking
251
+ */
252
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/consistent-type-assertions, @typescript-eslint/no-unsafe-argument
253
+ const runner = new runnerClass(...runnerArgs);
254
+ /*
255
+ * The type assertions here are necessary because we cannot
256
+ * express the relationship between the various generic
257
+ * types in the stages array and the stageRunners array
258
+ *
259
+ * The ts-ignore is necessary because TypeScript does not allow us to push to a readonly array.
260
+ */
261
+ // @ts-ignore
262
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/consistent-type-assertions, @typescript-eslint/no-unsafe-argument
263
+ this.stageRunners.push(runner);
264
+ lastRunner?.pipe(runner);
265
+ lastRunner = runner;
266
+ }
267
+ catch (error) {
268
+ logger?.error(`Error initializing stage processor for stage "${stage.name}":`, error);
269
+ this.destroy().catch(function () { });
270
+ }
271
+ }
272
+ }
273
+ async destroy() {
274
+ const logger = this.methodLogger('destroy');
275
+ if (this.destroyed) {
276
+ return;
277
+ }
278
+ this.destroyed = true;
279
+ for (let index = 0; index < this.stageRunners.length; index++) {
280
+ const runner = this.stageRunners[index];
281
+ const stage = this.stages[index] ?? { name: '' };
282
+ if (runner === undefined) {
283
+ continue;
284
+ }
285
+ try {
286
+ logger?.debug(`Destroying stage processor for stage "${stage.name}"`);
287
+ await runner.destroy();
288
+ }
289
+ catch (error) {
290
+ logger?.error(`Error destroying stage processor for stage "${stage.name}":`, error);
291
+ }
292
+ }
293
+ await super.destroy();
294
+ }
295
+ }
296
+ //# sourceMappingURL=pipeline.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pipeline.js","sourceRoot":"","sources":["../../../src/lib/queue/pipeline.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,sBAAsB,EACtB,MAAM,YAAY,CAAC;AAOpB,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAI7C;;;;GAIG;AACH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C;IAED,KAAK,CAAC,OAAO;QACZ,MAAM,MAAM,GAAG,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;QAE5C,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACpB,OAAO;QACR,CAAC;QACD,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;QAEtB,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;YAC/D,MAAM,MAAM,GAAG,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;YACxC,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;YACjD,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;gBAC1B,SAAS;YACV,CAAC;YAED,IAAI,CAAC;gBACJ,MAAM,EAAE,KAAK,CAAC,yCAAyC,KAAK,CAAC,IAAI,GAAG,CAAC,CAAC;gBACtE,MAAM,MAAM,CAAC,OAAO,EAAE,CAAC;YACxB,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBAChB,MAAM,EAAE,KAAK,CAAC,+CAA+C,KAAK,CAAC,IAAI,IAAI,EAAE,KAAK,CAAC,CAAC;YACrF,CAAC;QACF,CAAC;QAED,MAAM,KAAK,CAAC,OAAO,EAAE,CAAC;IACvB,CAAC;CACD","sourcesContent":["import {\n\tKeetaAnchorQueueRunner\n} from './index.js';\nimport type {\n\tKeetaAnchorQueueStorageDriver,\n\tKeetaAnchorQueueRequestID,\n\tKeetaAnchorQueueCommonOptions,\n\tKeetaAnchorQueueEntry\n} from './index.ts';\nimport { MethodLogger } from './internal.js';\nimport type { Logger } from '../log/index.ts';\nimport type { JSONSerializable } from '../utils/json.js';\n\n/**\n * A KeetaAnchorQueueRunner that uses `any` for the user types\n * This is helpful for expressing pipelines where the inputs\n * and outputs of various stages are not known ahead of time\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nclass KeetaAnchorQueueRunnerAny<UREQUEST = any, URESPONSE = any, REQUEST extends JSONSerializable = JSONSerializable, RESPONSE extends JSONSerializable = JSONSerializable> extends KeetaAnchorQueueRunner<UREQUEST, URESPONSE, REQUEST, RESPONSE> {\n\tprotected processor(): ReturnType<KeetaAnchorQueueRunner<UREQUEST, URESPONSE, REQUEST, RESPONSE>['processor']> { throw(new Error('not implemented')); }\n\tprotected decodeRequest(): UREQUEST { throw(new Error('not implemented')); }\n\tprotected decodeResponse(): URESPONSE | null { throw(new Error('not implemented')); }\n\tprotected encodeRequest(): REQUEST { throw(new Error('not implemented')); }\n\tprotected encodeResponse(): RESPONSE | null { throw(new Error('not implemented')); }\n\n}\n\ntype KeetaAnchorQueuePipelineStage<REQUEST, RESPONSE> = {\n\t/**\n\t * Name of the stage (must be unique within the pipeline)\n\t */\n\tname: string;\n\t/**\n\t * Constructor of the runner to use for this stage\n\t */\n\trunner: typeof KeetaAnchorQueueRunner<REQUEST, RESPONSE, JSONSerializable, JSONSerializable>;\n\t/**\n\t * Arguments to pass to the runner constructor\n\t */\n\targs?: [{ [key: string]: unknown; }?, ...unknown[]];\n};\n\nexport interface KeetaAnchorQueuePipeline<REQUEST, FINALRESPONSE> {\n\treadonly id: string;\n\n\t/**\n\t * Add a new request to the queue pipeline at the first stage\n\t *\n\t * @param request The request to add\n\t * @returns The ID of the newly added request\n\t */\n\tadd: (request: REQUEST) => Promise<KeetaAnchorQueueRequestID>;\n\t/**\n\t * Get the entry of a request at the final stage of the pipeline\n\t * stage or `null` if not in the final stage\n\t *\n\t * The original request is also returned if available\n\t *\n\t * @param id The ID of the request to get\n\t * @returns The entry at the final stage or `null` if not found, with the original request (may be `null` if not available)\n\t */\n\tget: (id: KeetaAnchorQueueRequestID) => Promise<(Omit<KeetaAnchorQueueEntry<REQUEST, FINALRESPONSE>, 'request'> & { request: REQUEST | null; }) | null>;\n\t/**\n\t * Run the pipeline processing jobs for up to the specified timeout (in milliseconds)\n\t * The process may take longer than the timeout if a job is already in progress\n\t * when the timeout is reached, in which case the process will complete the current job\n\t * before returning.\n\t *\n\t * @param timeoutMs The maximum time to run the processing jobs (in milliseconds). If not specified, runs until all available jobs are processed.\n\t * @returns `true` if there are more jobs to process, `false` otherwise\n\t */\n\trun: (timeoutMs?: number) => Promise<boolean>;\n\t/**\n\t * Run maintenance tasks for the pipeline -- this includes moving tasks from various states\n\t * and between stages of the pipeline\n\t */\n\tmaintain: () => Promise<void>;\n\t/**\n\t * Destroy the pipeline and release any resources it allocated\n\t */\n\tdestroy: () => Promise<void>;\n\t[Symbol.asyncDispose]: () => Promise<void>;\n}\n\n/**\n * Abstract base class for queue advanced pipelines -- this provides\n * a standardized way to implement custom processing pipelines that\n * consist of multiple stages with custom behavior\n */\nexport abstract class KeetaAnchorQueuePipelineAdvanced<IN1 = unknown, FINALOUT = unknown> implements KeetaAnchorQueuePipeline<IN1, FINALOUT> {\n\treadonly id: string;\n\tprotected readonly baseQueue: KeetaAnchorQueueStorageDriver<JSONSerializable, JSONSerializable>;\n\tprotected readonly logger?: Logger | undefined;\n\tprotected queues!: KeetaAnchorQueueStorageDriver<JSONSerializable, JSONSerializable>[];\n\tprotected initPromise?: Promise<void>;\n\tprotected destroyed = false;\n\n\tstatic readonly StageID: {\n\t\treadonly first: unique symbol;\n\t\treadonly last: unique symbol;\n\t} = {\n\t\t\t// @ts-ignore\n\t\t\tfirst: Symbol('first'),\n\t\t\t// @ts-ignore\n\t\t\tlast: Symbol('last')\n\t\t};\n\n\tconstructor(options: KeetaAnchorQueueCommonOptions & { baseQueue: KeetaAnchorQueueStorageDriver<JSONSerializable, JSONSerializable>; }) {\n\t\tthis.logger = options.logger;\n\t\tthis.id = options.id ?? crypto.randomUUID();\n\t\tthis.baseQueue = options.baseQueue;\n\n\t\tthis.queues = [];\n\t}\n\n\tprotected methodLogger(method: string): Logger | undefined {\n\t\treturn(MethodLogger(this.logger, {\n\t\t\tclass: 'KeetaAnchorQueuePipelineAdvanced',\n\t\t\tfile: 'src/lib/queue/pipeline.ts',\n\t\t\tmethod: method,\n\t\t\tinstanceID: this.id\n\t\t}));\n\t}\n\n\t/**\n\t * Create the pipeline stages -- will be called by the initialization process\n\t */\n\tprotected abstract createPipeline(): Promise<void>;\n\n\t/**\n\t * Get the stage runner for the specified stage name, or the first/last stage\n\t */\n\tprotected abstract getStage(stageID: typeof KeetaAnchorQueuePipelineAdvanced.StageID.first): KeetaAnchorQueueRunner<IN1, unknown>;\n\tprotected abstract getStage(stageID: typeof KeetaAnchorQueuePipelineAdvanced.StageID.last): KeetaAnchorQueueRunner<unknown, FINALOUT>;\n\tprotected abstract getStage(stageID: typeof KeetaAnchorQueuePipelineAdvanced.StageID.first | typeof KeetaAnchorQueuePipelineAdvanced.StageID.last | string): KeetaAnchorQueueRunnerAny | null;\n\n\t/**\n\t * Create a new queue to use in a pipeline stage\n\t * It will be released when the pipeline is destroyed\n\t *\n\t * @param name The name of the queue\n\t * @returns The created queue\n\t */\n\tprotected async createQueue(name: string): Promise<KeetaAnchorQueueStorageDriver<JSONSerializable, JSONSerializable>> {\n\t\tconst retval = await this.baseQueue.partition(name);\n\t\tthis.queues.push(retval);\n\t\treturn(retval);\n\t}\n\n\tprotected async init(): Promise<void> {\n\t\tconst logger = this.methodLogger('init');\n\n\t\tif (this.destroyed) {\n\t\t\tthrow(new Error('Pipeline has been destroyed'));\n\t\t}\n\n\t\tif (this.initPromise !== undefined) {\n\t\t\treturn(await this.initPromise);\n\t\t}\n\n\t\tthis.initPromise = (async () => {\n\t\t\ttry {\n\t\t\t\tawait this.createPipeline();\n\t\t\t} catch (error) {\n\t\t\t\tlogger?.error('Error initializing pipeline:', error);\n\t\t\t\ttry {\n\t\t\t\t\tawait this.destroy();\n\t\t\t\t} catch {\n\t\t\t\t\t/* Ignore */\n\t\t\t\t}\n\t\t\t\tthrow(error);\n\t\t\t}\n\t\t})();\n\n\t\treturn(await this.initPromise);\n\t}\n\n\tasync add(request: IN1): ReturnType<KeetaAnchorQueueRunner<IN1, unknown>['add']> {\n\t\tawait this.init();\n\n\t\tconst stage1 = this.getStage(KeetaAnchorQueuePipelineAdvanced.StageID.first);\n\n\t\treturn(await stage1.add(request));\n\t}\n\n\tasync get(id: KeetaAnchorQueueRequestID): Promise<(Omit<KeetaAnchorQueueEntry<IN1, FINALOUT>, 'request'> & { request: IN1 | null; }) | null> {\n\t\tawait this.init();\n\n\t\tconst firstStage = this.getStage(KeetaAnchorQueuePipelineAdvanced.StageID.first);\n\t\tconst finalStage = this.getStage(KeetaAnchorQueuePipelineAdvanced.StageID.last);\n\t\tconst firstEntry = await firstStage.get(id);\n\t\tconst finalOutput = await finalStage.get(id);\n\n\t\tif (finalOutput === null) {\n\t\t\treturn(null);\n\t\t}\n\n\t\treturn({\n\t\t\t...finalOutput,\n\t\t\trequest: firstEntry?.request ?? null\n\t\t});\n\t}\n\n\tasync run(timeoutMs?: number): Promise<boolean> {\n\t\tawait this.init();\n\n\t\tconst logger = this.methodLogger('run');\n\n\t\tconst stage1 = this.getStage(KeetaAnchorQueuePipelineAdvanced.StageID.first);\n\t\tlet retval = true;\n\t\ttry {\n\t\t\tretval = await stage1.run(timeoutMs);\n\t\t} catch (error) {\n\t\t\tlogger?.error('Error running stage processor:', error);\n\t\t}\n\n\t\treturn(retval);\n\t}\n\n\tasync maintain(): Promise<void> {\n\t\tawait this.init();\n\n\t\tconst logger = this.methodLogger('maintain');\n\n\t\tconst stage1 = this.getStage(KeetaAnchorQueuePipelineAdvanced.StageID.first);\n\t\ttry {\n\t\t\tawait stage1.maintain();\n\t\t} catch (error) {\n\t\t\tlogger?.error('Error running stage maintenance:', error);\n\t\t}\n\t}\n\n\tasync destroy(): Promise<void> {\n\t\tconst logger = this.methodLogger('destroy');\n\n\t\tif (this.destroyed) {\n\t\t\treturn;\n\t\t}\n\t\tthis.destroyed = true;\n\n\t\tawait this.init();\n\n\t\tfor (let index = 0; index < this.queues.length; index++) {\n\t\t\tconst queue = this.queues[index];\n\t\t\tif (queue === undefined) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tlogger?.debug(`Destroying queue for stage \"#${index}\"`);\n\t\t\t\tawait queue.destroy();\n\t\t\t} catch (error) {\n\t\t\t\tlogger?.error(`Error destroying queue for stage \"#${index}:`, error);\n\t\t\t}\n\t\t}\n\t}\n\n\tasync [Symbol.asyncDispose](): Promise<void> {\n\t\tconst logger = this.methodLogger('asyncDispose');\n\t\ttry {\n\t\t\tawait this.destroy();\n\t\t} catch (error) {\n\t\t\tlogger?.error('Error during async dispose:', error);\n\t\t}\n\t}\n\n}\n\ntype MapKeetaAnchorQueuePipelineStages<In extends readonly [ any, ...any[] ]> = \n\tIn extends [ infer First, ...infer Rest extends [ any, ...any[] ] ] ?\n\t\treadonly [ KeetaAnchorQueuePipelineStage<First, Rest[0]>, ...MapKeetaAnchorQueuePipelineStages<Rest> ] : [];\n\ntype MapKeetaAnchorQueueRunner<In extends readonly [ any, ...any[] ]> = \n\tIn extends [ infer First, ...infer Rest extends [ any, ...any[] ] ] ?\n\t\treadonly [ KeetaAnchorQueueRunner<First, Rest[0]>, ...MapKeetaAnchorQueueRunner<Rest> ] : [];\n\ntype FirstElement<T extends readonly any[]> = T extends [ infer First, ...any[] ] ? First : never;\ntype LastElement<T extends readonly any[]> = T extends [ ...any[], infer Last ] ? Last : never;\n\n/**\n * Abstract base class for queue basic pipelines -- this provides\n * a standardized way to implement custom processing pipelines that\n * consist of multiple stages but do not require batching\n */\nexport abstract class KeetaAnchorQueuePipelineBasic<Stages extends readonly [ any, ...any[] ]> extends KeetaAnchorQueuePipelineAdvanced<FirstElement<Stages>, LastElement<Stages>> implements KeetaAnchorQueuePipeline<FirstElement<Stages>, LastElement<Stages>> {\n\tprotected readonly abstract stages: MapKeetaAnchorQueuePipelineStages<Stages>;\n\n\tprotected stageRunners!: MapKeetaAnchorQueueRunner<Stages>;\n\n\tconstructor(options: KeetaAnchorQueueCommonOptions & { baseQueue: KeetaAnchorQueueStorageDriver<JSONSerializable, JSONSerializable>; }) {\n\t\tsuper(options);\n\n\t\t/*\n\t\t * We start out with no stages, but the createPipeline method\n\t\t * will be run during initialization to set them up\n\t\t */\n\t\t// @ts-ignore\n\t\tthis.stageRunners = [];\n\t}\n\n\tprotected methodLogger(method: string): Logger | undefined {\n\t\treturn(MethodLogger(this.logger, {\n\t\t\tclass: 'KeetaAnchorQueuePipelineBasic',\n\t\t\tfile: 'src/lib/queue/pipeline.ts',\n\t\t\tmethod: method,\n\t\t\tinstanceID: this.id\n\t\t}));\n\t}\n\n\tprotected getStage(stageID: typeof KeetaAnchorQueuePipelineAdvanced.StageID.first): KeetaAnchorQueueRunner<FirstElement<Stages>, unknown>;\n\tprotected getStage(stageID: typeof KeetaAnchorQueuePipelineAdvanced.StageID.last): KeetaAnchorQueueRunner<unknown, LastElement<Stages>>;\n\tprotected getStage(stageID: typeof KeetaAnchorQueuePipelineAdvanced.StageID.first | typeof KeetaAnchorQueuePipelineAdvanced.StageID.last | string): KeetaAnchorQueueRunnerAny | null;\n\tprotected getStage(stageID: typeof KeetaAnchorQueuePipelineAdvanced.StageID.first | typeof KeetaAnchorQueuePipelineAdvanced.StageID.last | string): KeetaAnchorQueueRunnerAny | KeetaAnchorQueueRunner<FirstElement<Stages>, unknown> | KeetaAnchorQueueRunner<unknown, LastElement<Stages>> | null {\n\t\tif (this.initPromise === undefined) {\n\t\t\tthrow(new Error('Pipeline not initialized'));\n\t\t}\n\n\t\tif (stageID === KeetaAnchorQueuePipelineAdvanced.StageID.first) {\n\t\t\tconst runner = this.stageRunners[0];\n\t\t\tif (runner !== undefined) {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\t\t\treturn(runner as unknown as KeetaAnchorQueueRunner<FirstElement<Stages>, unknown>);\n\t\t\t}\n\t\t\tthrow(new Error('First stage runner not found'));\n\t\t} else if (stageID === KeetaAnchorQueuePipelineAdvanced.StageID.last) {\n\t\t\tfor (let index = this.stageRunners.length - 1; index >= 0; index--) {\n\t\t\t\tconst runner = this.stageRunners[index];\n\t\t\t\tif (runner !== undefined) {\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\t\t\t\treturn(runner as unknown as KeetaAnchorQueueRunner<unknown, LastElement<Stages>>);\n\t\t\t\t}\n\t\t\t}\n\t\t\tthrow(new Error('Last stage runner not found'));\n\t\t} else {\n\t\t\tfor (let index = 0; index < this.stages.length; index++) {\n\t\t\t\tconst stage = this.stages[index];\n\t\t\t\tif (stage?.name === stageID) {\n\t\t\t\t\tconst runner = this.stageRunners[index];\n\t\t\t\t\tif (runner !== undefined) {\n\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\t\t\t\t\treturn(runner as KeetaAnchorQueueRunnerAny);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn(null);\n\t\t}\n\t}\n\n\t/**\n\t * Create the pipeline from the user-defined stages\n\t */\n\tprotected async createPipeline(): Promise<void> {\n\t\tconst logger = this.methodLogger('init');\n\n\t\tlet lastRunner: InstanceType<typeof KeetaAnchorQueueRunnerAny> | undefined = undefined;\n\t\tfor (const stage of this.stages) {\n\t\t\tif (stage === undefined) {\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\tlogger?.debug(`Initializing queue for stage \"${stage.name}\"`);\n\t\t\t\tconst queue = await this.createQueue(stage.name);\n\n\t\t\t\tlogger?.debug(`Initializing stage processor for stage \"${stage.name}\"`);\n\n\t\t\t\t/**\n\t\t\t\t * We have to use this type because we cannot express the relationship\n\t\t\t\t * between the various generic types in the stages array and the stageRunners array\n\t\t\t\t */\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\t\t\tconst runnerClass = stage.runner as typeof KeetaAnchorQueueRunnerAny;\n\t\t\t\tconst runnerArgsFirst = stage.args?.[0];\n\t\t\t\tconst runnerArgs0: ConstructorParameters<typeof KeetaAnchorQueueRunnerAny>[0] = {\n\t\t\t\t\tid: `${this.id}::runner::${stage.name}`,\n\t\t\t\t\tqueue: queue,\n\t\t\t\t\tlogger: this.logger,\n\t\t\t\t\t...runnerArgsFirst\n\t\t\t\t};\n\t\t\t\tconst runnerArgs = [runnerArgs0, ...(stage.args?.slice(1) ?? [])] as const;\n\n\t\t\t\t/*\n\t\t\t\t * We check the first parameter's type above, but all the remaining\n\t\t\t\t * parameters are user-defined and we cannot validate them here\n\t\t\t\t * so we cast to the tuple `any` type to avoid type checking\n\t\t\t\t */\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/consistent-type-assertions, @typescript-eslint/no-unsafe-argument\n\t\t\t\tconst runner = new runnerClass(...runnerArgs as [any]);\n\n\t\t\t\t/*\n\t\t\t\t * The type assertions here are necessary because we cannot\n\t\t\t\t * express the relationship between the various generic\n\t\t\t\t * types in the stages array and the stageRunners array\n\t\t\t\t * \n\t\t\t\t * The ts-ignore is necessary because TypeScript does not allow us to push to a readonly array.\n\t\t\t\t */\n\t\t\t\t// @ts-ignore\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/consistent-type-assertions, @typescript-eslint/no-unsafe-argument\n\t\t\t\tthis.stageRunners.push(runner as any);\n\n\t\t\t\tlastRunner?.pipe(runner);\n\n\t\t\t\tlastRunner = runner;\n\t\t\t} catch (error) {\n\t\t\t\tlogger?.error(`Error initializing stage processor for stage \"${stage.name}\":`, error);\n\t\t\t\tthis.destroy().catch(function() { /* do nothing */ });\n\t\t\t}\n\t\t}\n\t}\n\n\tasync destroy(): Promise<void> {\n\t\tconst logger = this.methodLogger('destroy');\n\n\t\tif (this.destroyed) {\n\t\t\treturn;\n\t\t}\n\t\tthis.destroyed = true;\n\n\t\tfor (let index = 0; index < this.stageRunners.length; index++) {\n\t\t\tconst runner = this.stageRunners[index];\n\t\t\tconst stage = this.stages[index] ?? { name: '' };\n\t\t\tif (runner === undefined) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\tlogger?.debug(`Destroying stage processor for stage \"${stage.name}\"`);\n\t\t\t\tawait runner.destroy();\n\t\t\t} catch (error) {\n\t\t\t\tlogger?.error(`Error destroying stage processor for stage \"${stage.name}\":`, error);\n\t\t\t}\n\t\t}\n\n\t\tawait super.destroy();\n\t}\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export declare const asleep: (ms: number) => Promise<void>;
2
+ //# sourceMappingURL=asleep.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asleep.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/asleep.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,MAAM,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAkE,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { lib as KeetaNetLib } from '@keetanetwork/keetanet-client';
2
+ export const asleep = KeetaNetLib.Utils.Helper.asleep.bind(KeetaNetLib.Utils.Helper);
3
+ //# sourceMappingURL=asleep.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asleep.js","sourceRoot":"","sources":["../../../src/lib/utils/asleep.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,IAAI,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAEnE,MAAM,CAAC,MAAM,MAAM,GAAkC,WAAW,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC","sourcesContent":["import { lib as KeetaNetLib } from '@keetanetwork/keetanet-client';\n\nexport const asleep: (ms: number) => Promise<void> = KeetaNetLib.Utils.Helper.asleep.bind(KeetaNetLib.Utils.Helper);\n"]}
@@ -0,0 +1,3 @@
1
+ import { lib as KeetaNetLib } from '@keetanetwork/keetanet-client';
2
+ export declare const AsyncDisposableStack: typeof KeetaNetLib.Utils.Helper.AsyncDisposableStack;
3
+ //# sourceMappingURL=defer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defer.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/defer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,IAAI,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAEnE,eAAO,MAAM,oBAAoB,EAAE,OAAO,WAAW,CAAC,KAAK,CAAC,MAAM,CAAC,oBAAoE,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { lib as KeetaNetLib } from '@keetanetwork/keetanet-client';
2
+ export const AsyncDisposableStack = KeetaNetLib.Utils.Helper.AsyncDisposableStack;
3
+ //# sourceMappingURL=defer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defer.js","sourceRoot":"","sources":["../../../src/lib/utils/defer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,IAAI,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAEnE,MAAM,CAAC,MAAM,oBAAoB,GAAyD,WAAW,CAAC,KAAK,CAAC,MAAM,CAAC,oBAAoB,CAAC","sourcesContent":["import { lib as KeetaNetLib } from '@keetanetwork/keetanet-client';\n\nexport const AsyncDisposableStack: typeof KeetaNetLib.Utils.Helper.AsyncDisposableStack = KeetaNetLib.Utils.Helper.AsyncDisposableStack;\n"]}