@xyo-network/module-abstract 2.99.2 → 2.99.4

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 (99) hide show
  1. package/dist/browser/AbstractModule.d.cts +2 -2
  2. package/dist/browser/AbstractModule.d.cts.map +1 -1
  3. package/dist/browser/AbstractModule.d.mts +2 -2
  4. package/dist/browser/AbstractModule.d.mts.map +1 -1
  5. package/dist/browser/AbstractModule.d.ts +2 -2
  6. package/dist/browser/AbstractModule.d.ts.map +1 -1
  7. package/dist/browser/Error.d.cts +3 -0
  8. package/dist/browser/Error.d.cts.map +1 -1
  9. package/dist/browser/Error.d.mts +3 -0
  10. package/dist/browser/Error.d.mts.map +1 -1
  11. package/dist/browser/Error.d.ts +3 -0
  12. package/dist/browser/Error.d.ts.map +1 -1
  13. package/dist/browser/index.cjs +9 -2
  14. package/dist/browser/index.cjs.map +1 -1
  15. package/dist/browser/index.js +9 -2
  16. package/dist/browser/index.js.map +1 -1
  17. package/dist/neutral/AbstractModule.d.cts +108 -0
  18. package/dist/neutral/AbstractModule.d.cts.map +1 -0
  19. package/dist/neutral/AbstractModule.d.mts +108 -0
  20. package/dist/neutral/AbstractModule.d.mts.map +1 -0
  21. package/dist/neutral/AbstractModule.d.ts +108 -0
  22. package/dist/neutral/AbstractModule.d.ts.map +1 -0
  23. package/dist/neutral/AbstractModuleInstance.d.cts +53 -0
  24. package/dist/neutral/AbstractModuleInstance.d.cts.map +1 -0
  25. package/dist/neutral/AbstractModuleInstance.d.mts +53 -0
  26. package/dist/neutral/AbstractModuleInstance.d.mts.map +1 -0
  27. package/dist/neutral/AbstractModuleInstance.d.ts +53 -0
  28. package/dist/neutral/AbstractModuleInstance.d.ts.map +1 -0
  29. package/dist/neutral/BaseEmitter.d.cts +17 -0
  30. package/dist/neutral/BaseEmitter.d.cts.map +1 -0
  31. package/dist/neutral/BaseEmitter.d.mts +17 -0
  32. package/dist/neutral/BaseEmitter.d.mts.map +1 -0
  33. package/dist/neutral/BaseEmitter.d.ts +17 -0
  34. package/dist/neutral/BaseEmitter.d.ts.map +1 -0
  35. package/dist/neutral/Error.d.cts +19 -0
  36. package/dist/neutral/Error.d.cts.map +1 -0
  37. package/dist/neutral/Error.d.mts +19 -0
  38. package/dist/neutral/Error.d.mts.map +1 -0
  39. package/dist/neutral/Error.d.ts +19 -0
  40. package/dist/neutral/Error.d.ts.map +1 -0
  41. package/dist/neutral/QueryValidator/ModuleConfigQueryValidator.d.cts +17 -0
  42. package/dist/neutral/QueryValidator/ModuleConfigQueryValidator.d.cts.map +1 -0
  43. package/dist/neutral/QueryValidator/ModuleConfigQueryValidator.d.mts +17 -0
  44. package/dist/neutral/QueryValidator/ModuleConfigQueryValidator.d.mts.map +1 -0
  45. package/dist/neutral/QueryValidator/ModuleConfigQueryValidator.d.ts +17 -0
  46. package/dist/neutral/QueryValidator/ModuleConfigQueryValidator.d.ts.map +1 -0
  47. package/dist/neutral/QueryValidator/QueryValidator.d.cts +8 -0
  48. package/dist/neutral/QueryValidator/QueryValidator.d.cts.map +1 -0
  49. package/dist/neutral/QueryValidator/QueryValidator.d.mts +8 -0
  50. package/dist/neutral/QueryValidator/QueryValidator.d.mts.map +1 -0
  51. package/dist/neutral/QueryValidator/QueryValidator.d.ts +8 -0
  52. package/dist/neutral/QueryValidator/QueryValidator.d.ts.map +1 -0
  53. package/dist/neutral/QueryValidator/SupportedQueryValidator.d.cts +22 -0
  54. package/dist/neutral/QueryValidator/SupportedQueryValidator.d.cts.map +1 -0
  55. package/dist/neutral/QueryValidator/SupportedQueryValidator.d.mts +22 -0
  56. package/dist/neutral/QueryValidator/SupportedQueryValidator.d.mts.map +1 -0
  57. package/dist/neutral/QueryValidator/SupportedQueryValidator.d.ts +22 -0
  58. package/dist/neutral/QueryValidator/SupportedQueryValidator.d.ts.map +1 -0
  59. package/dist/neutral/QueryValidator/index.d.cts +4 -0
  60. package/dist/neutral/QueryValidator/index.d.cts.map +1 -0
  61. package/dist/neutral/QueryValidator/index.d.mts +4 -0
  62. package/dist/neutral/QueryValidator/index.d.mts.map +1 -0
  63. package/dist/neutral/QueryValidator/index.d.ts +4 -0
  64. package/dist/neutral/QueryValidator/index.d.ts.map +1 -0
  65. package/dist/neutral/determineAccount.d.cts +14 -0
  66. package/dist/neutral/determineAccount.d.cts.map +1 -0
  67. package/dist/neutral/determineAccount.d.mts +14 -0
  68. package/dist/neutral/determineAccount.d.mts.map +1 -0
  69. package/dist/neutral/determineAccount.d.ts +14 -0
  70. package/dist/neutral/determineAccount.d.ts.map +1 -0
  71. package/dist/neutral/index.cjs +1066 -0
  72. package/dist/neutral/index.cjs.map +1 -0
  73. package/dist/neutral/index.d.cts +6 -0
  74. package/dist/neutral/index.d.cts.map +1 -0
  75. package/dist/neutral/index.d.mts +6 -0
  76. package/dist/neutral/index.d.mts.map +1 -0
  77. package/dist/neutral/index.d.ts +6 -0
  78. package/dist/neutral/index.d.ts.map +1 -0
  79. package/dist/neutral/index.js +1045 -0
  80. package/dist/neutral/index.js.map +1 -0
  81. package/dist/node/AbstractModule.d.cts +2 -2
  82. package/dist/node/AbstractModule.d.cts.map +1 -1
  83. package/dist/node/AbstractModule.d.mts +2 -2
  84. package/dist/node/AbstractModule.d.mts.map +1 -1
  85. package/dist/node/AbstractModule.d.ts +2 -2
  86. package/dist/node/AbstractModule.d.ts.map +1 -1
  87. package/dist/node/Error.d.cts +3 -0
  88. package/dist/node/Error.d.cts.map +1 -1
  89. package/dist/node/Error.d.mts +3 -0
  90. package/dist/node/Error.d.mts.map +1 -1
  91. package/dist/node/Error.d.ts +3 -0
  92. package/dist/node/Error.d.ts.map +1 -1
  93. package/dist/node/index.cjs +9 -2
  94. package/dist/node/index.cjs.map +1 -1
  95. package/dist/node/index.js +9 -2
  96. package/dist/node/index.js.map +1 -1
  97. package/package.json +27 -27
  98. package/src/AbstractModule.ts +5 -2
  99. package/src/Error.ts +8 -0
@@ -0,0 +1,1066 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/index.ts
22
+ var src_exports = {};
23
+ __export(src_exports, {
24
+ AbstractModule: () => AbstractModule,
25
+ AbstractModuleInstance: () => AbstractModuleInstance,
26
+ BaseEmitter: () => BaseEmitter,
27
+ ModuleConfigQueryValidator: () => ModuleConfigQueryValidator,
28
+ ModuleErrorBuilder: () => ModuleErrorBuilder,
29
+ SupportedQueryValidator: () => SupportedQueryValidator,
30
+ isQuerySupportedByModule: () => isQuerySupportedByModule
31
+ });
32
+ module.exports = __toCommonJS(src_exports);
33
+
34
+ // src/AbstractModule.ts
35
+ var import_assert2 = require("@xylabs/assert");
36
+ var import_error = require("@xylabs/error");
37
+ var import_exists = require("@xylabs/exists");
38
+ var import_lodash = require("@xylabs/lodash");
39
+ var import_logger = require("@xylabs/logger");
40
+ var import_object2 = require("@xylabs/object");
41
+ var import_promise = require("@xylabs/promise");
42
+ var import_account2 = require("@xyo-network/account");
43
+ var import_address_payload_plugin = require("@xyo-network/address-payload-plugin");
44
+ var import_archivist_model = require("@xyo-network/archivist-model");
45
+ var import_boundwitness_builder = require("@xyo-network/boundwitness-builder");
46
+ var import_boundwitness_wrapper3 = require("@xyo-network/boundwitness-wrapper");
47
+ var import_config_payload_plugin = require("@xyo-network/config-payload-plugin");
48
+ var import_module_model = require("@xyo-network/module-model");
49
+ var import_payload_builder2 = require("@xyo-network/payload-builder");
50
+ var import_query_payload_plugin = require("@xyo-network/query-payload-plugin");
51
+ var import_lru_cache = require("lru-cache");
52
+
53
+ // src/BaseEmitter.ts
54
+ var import_object = require("@xylabs/object");
55
+ var import_module_events = require("@xyo-network/module-events");
56
+ var BaseEmitter = class extends import_object.Base {
57
+ static {
58
+ __name(this, "BaseEmitter");
59
+ }
60
+ //just here to query types
61
+ eventData = {};
62
+ events;
63
+ constructor(params) {
64
+ super(params);
65
+ this.events = new import_module_events.Events();
66
+ }
67
+ clearListeners(eventNames) {
68
+ return this.events.clearListeners(eventNames);
69
+ }
70
+ emit(eventName, eventArgs) {
71
+ return this.events.emit(eventName, eventArgs);
72
+ }
73
+ emitSerial(eventName, eventArgs) {
74
+ return this.events.emitSerial(eventName, eventArgs);
75
+ }
76
+ listenerCount(eventNames) {
77
+ return this.events.listenerCount(eventNames);
78
+ }
79
+ off(eventNames, listener) {
80
+ return this.events.off(eventNames, listener);
81
+ }
82
+ offAny(listener) {
83
+ return this.events.offAny(listener);
84
+ }
85
+ on(eventNames, listener) {
86
+ return this.events.on(eventNames, listener);
87
+ }
88
+ onAny(listener) {
89
+ return this.events.onAny(listener);
90
+ }
91
+ once(eventName, listener) {
92
+ return this.events.once(eventName, listener);
93
+ }
94
+ };
95
+
96
+ // src/determineAccount.ts
97
+ var import_assert = require("@xylabs/assert");
98
+ var import_account = require("@xyo-network/account");
99
+ var isDetermineAccountFromAccountParams = /* @__PURE__ */ __name((params) => {
100
+ (0, import_assert.assertEx)(!params.accountPath, () => "accountPath may not be provided when account is provided");
101
+ return !!params.account;
102
+ }, "isDetermineAccountFromAccountParams");
103
+ var isDetermineAccountFromWalletParams = /* @__PURE__ */ __name((params) => {
104
+ return !!params.wallet;
105
+ }, "isDetermineAccountFromWalletParams");
106
+ async function determineAccount(params, allowRandomAccount = true) {
107
+ if (isDetermineAccountFromAccountParams(params)) {
108
+ if (params.account === "random") {
109
+ (0, import_assert.assertEx)(allowRandomAccount, () => "Random address not allowed");
110
+ return import_account.Account.randomSync();
111
+ }
112
+ return params.account;
113
+ }
114
+ if (isDetermineAccountFromWalletParams(params)) {
115
+ return (0, import_assert.assertEx)(params.accountPath ? await params.wallet.derivePath(params.accountPath) : params.wallet, () => "Failed to derive account from path");
116
+ }
117
+ console.warn("AbstractModule.determineAccount: No account or wallet provided - Creating Random account");
118
+ return import_account.Account.randomSync();
119
+ }
120
+ __name(determineAccount, "determineAccount");
121
+
122
+ // src/Error.ts
123
+ var import_payload_builder = require("@xyo-network/payload-builder");
124
+ var import_payload_model = require("@xyo-network/payload-model");
125
+ var ModuleErrorBuilder = class extends import_payload_builder.PayloadBuilder {
126
+ static {
127
+ __name(this, "ModuleErrorBuilder");
128
+ }
129
+ _details;
130
+ _message;
131
+ _name;
132
+ _query;
133
+ _sources;
134
+ constructor() {
135
+ super({
136
+ schema: import_payload_model.ModuleErrorSchema
137
+ });
138
+ }
139
+ build() {
140
+ this.fields({
141
+ details: this._details,
142
+ message: this._message,
143
+ name: this._name,
144
+ query: this._query,
145
+ schema: import_payload_model.ModuleErrorSchema,
146
+ sources: this._sources
147
+ });
148
+ return super.build();
149
+ }
150
+ details(details) {
151
+ this._details = details;
152
+ return this;
153
+ }
154
+ message(message) {
155
+ this._message = message;
156
+ return this;
157
+ }
158
+ name(name) {
159
+ this._name = name;
160
+ return this;
161
+ }
162
+ query(query) {
163
+ this._query = query;
164
+ return this;
165
+ }
166
+ sources(sources) {
167
+ this._sources = sources;
168
+ return this;
169
+ }
170
+ };
171
+
172
+ // src/QueryValidator/ModuleConfigQueryValidator.ts
173
+ var import_boundwitness_wrapper = require("@xyo-network/boundwitness-wrapper");
174
+ var delimiter = "";
175
+ var ModuleConfigQueryValidator = class {
176
+ static {
177
+ __name(this, "ModuleConfigQueryValidator");
178
+ }
179
+ allowed = {};
180
+ disallowed = {};
181
+ hasAllowedRules;
182
+ hasDisallowedRules;
183
+ hasRules;
184
+ constructor(config) {
185
+ if (config?.security?.allowed) {
186
+ for (const [schema, addresses] of Object.entries(config.security?.allowed)) {
187
+ this.allowed[schema] = addresses.map(toAddressesString);
188
+ }
189
+ }
190
+ if (config?.security?.disallowed) {
191
+ for (const [schema, addresses] of Object.entries(config.security?.disallowed)) {
192
+ this.disallowed[schema] = addresses.map(toAddressesString);
193
+ }
194
+ }
195
+ this.hasAllowedRules = Object.keys(this.allowed).length > 0;
196
+ this.hasDisallowedRules = Object.keys(this.disallowed).length > 0;
197
+ this.hasRules = this.hasAllowedRules || this.hasDisallowedRules;
198
+ }
199
+ queryable = async (query, payloads) => {
200
+ if (!this.hasRules)
201
+ return true;
202
+ const addresses = query.addresses;
203
+ if (addresses.length === 0)
204
+ return false;
205
+ const wrapper = await import_boundwitness_wrapper.QueryBoundWitnessWrapper.parseQuery(query, payloads);
206
+ const schema = (await wrapper.getQuery()).schema;
207
+ return this.queryAllowed(schema, addresses) && !this.queryDisallowed(schema, addresses);
208
+ };
209
+ queryAllowed = (schema, addresses) => {
210
+ if (!this.hasAllowedRules)
211
+ return true;
212
+ if (addresses.length > 1) {
213
+ const signatories = toAddressesString(addresses);
214
+ const validCosigners = this.allowed?.[schema]?.includes(signatories);
215
+ if (validCosigners)
216
+ return true;
217
+ }
218
+ return addresses.every((address) => this.allowed?.[schema]?.includes(address) || false);
219
+ };
220
+ queryDisallowed = (schema, addresses) => {
221
+ if (!this.hasDisallowedRules)
222
+ return false;
223
+ return addresses.some((address) => this.disallowed?.[schema]?.includes(address));
224
+ };
225
+ };
226
+ var toAddressesString = /* @__PURE__ */ __name((addresses) => {
227
+ return Array.isArray(addresses) ? addresses.sort().map((address) => address.toLowerCase()).join(delimiter) : addresses.toLowerCase();
228
+ }, "toAddressesString");
229
+
230
+ // src/QueryValidator/SupportedQueryValidator.ts
231
+ var import_boundwitness_wrapper2 = require("@xyo-network/boundwitness-wrapper");
232
+ var isQuerySupportedByModule = /* @__PURE__ */ __name(async (mod, query, payloads) => {
233
+ const wrapper = await import_boundwitness_wrapper2.QueryBoundWitnessWrapper.parseQuery(query, payloads);
234
+ const schema = (await wrapper.getQuery()).schema;
235
+ return mod.queries.includes(schema);
236
+ }, "isQuerySupportedByModule");
237
+ var SupportedQueryValidator = class {
238
+ static {
239
+ __name(this, "SupportedQueryValidator");
240
+ }
241
+ mod;
242
+ constructor(mod) {
243
+ this.mod = mod;
244
+ this.queryable = (query, payloads) => {
245
+ return isQuerySupportedByModule(this.mod, query, payloads);
246
+ };
247
+ }
248
+ queryable;
249
+ };
250
+
251
+ // src/AbstractModule.ts
252
+ var AbstractModule = class _AbstractModule extends BaseEmitter {
253
+ static {
254
+ __name(this, "AbstractModule");
255
+ }
256
+ static allowRandomAccount = true;
257
+ static configSchemas = [
258
+ import_module_model.ModuleConfigSchema
259
+ ];
260
+ static defaultConfigSchema = import_module_model.ModuleConfigSchema;
261
+ static defaultLogger = new import_logger.ConsoleLogger(import_logger.LogLevel.warn);
262
+ static enableLazyLoad = false;
263
+ static labels = {};
264
+ static uniqueName = (0, import_object2.globallyUnique)("AbstractModule", _AbstractModule, "xyo");
265
+ static privateConstructorKey = Date.now().toString();
266
+ _account = void 0;
267
+ _baseModuleQueryAccountPaths = {
268
+ [import_module_model.ModuleAddressQuerySchema]: "1",
269
+ [import_module_model.ModuleManifestQuerySchema]: "5",
270
+ [import_module_model.ModuleStateQuerySchema]: "6",
271
+ [import_module_model.ModuleSubscribeQuerySchema]: "3"
272
+ };
273
+ //cache manifest based on maxDepth
274
+ _cachedManifests = new import_lru_cache.LRUCache({
275
+ max: 10,
276
+ ttl: 1e3 * 60 * 5
277
+ });
278
+ _lastError;
279
+ _queryAccounts = {
280
+ [import_module_model.ModuleAddressQuerySchema]: void 0,
281
+ [import_module_model.ModuleManifestQuerySchema]: void 0,
282
+ [import_module_model.ModuleStateQuerySchema]: void 0,
283
+ [import_module_model.ModuleSubscribeQuerySchema]: void 0
284
+ };
285
+ _startPromise = void 0;
286
+ _started = void 0;
287
+ moduleConfigQueryValidator;
288
+ supportedQueryValidator;
289
+ _busyCount = 0;
290
+ _status = "stopped";
291
+ constructor(privateConstructorKey, params, account) {
292
+ (0, import_assert2.assertEx)(_AbstractModule.privateConstructorKey === privateConstructorKey, () => "Use create function instead of constructor");
293
+ const mutatedParams = {
294
+ ...params
295
+ };
296
+ super(mutatedParams);
297
+ this._account = account;
298
+ this.supportedQueryValidator = new SupportedQueryValidator(this).queryable;
299
+ this.moduleConfigQueryValidator = new ModuleConfigQueryValidator(mutatedParams?.config).queryable;
300
+ }
301
+ get account() {
302
+ return (0, import_assert2.assertEx)(this._account, () => "Missing account");
303
+ }
304
+ get address() {
305
+ return this.account.address;
306
+ }
307
+ get allowAnonymous() {
308
+ return !!this.config.security?.allowAnonymous;
309
+ }
310
+ get allowNameResolution() {
311
+ return this.params.allowNameResolution ?? true;
312
+ }
313
+ get archiving() {
314
+ return this.config.archiving;
315
+ }
316
+ get archivist() {
317
+ return this.config.archivist;
318
+ }
319
+ get config() {
320
+ return this.params.config;
321
+ }
322
+ get dead() {
323
+ return this.status === "dead";
324
+ }
325
+ get ephemeralQueryAccountEnabled() {
326
+ return !!this.params.ephemeralQueryAccountEnabled;
327
+ }
328
+ get id() {
329
+ return this.config.name ?? this.address;
330
+ }
331
+ get logger() {
332
+ return this.params?.logger ?? _AbstractModule.defaultLogger ?? import_object2.Base.defaultLogger;
333
+ }
334
+ get priority() {
335
+ return import_module_model.ObjectResolverPriority.Normal;
336
+ }
337
+ get queries() {
338
+ return [
339
+ import_module_model.ModuleAddressQuerySchema,
340
+ import_module_model.ModuleSubscribeQuerySchema,
341
+ import_module_model.ModuleManifestQuerySchema,
342
+ import_module_model.ModuleStateQuerySchema
343
+ ];
344
+ }
345
+ get queryAccountPaths() {
346
+ return {
347
+ ...this._baseModuleQueryAccountPaths,
348
+ ...this._queryAccountPaths
349
+ };
350
+ }
351
+ get queryAccounts() {
352
+ return this._queryAccounts;
353
+ }
354
+ get status() {
355
+ return this._status;
356
+ }
357
+ get timestamp() {
358
+ return this.config.timestamp ?? false;
359
+ }
360
+ get baseModuleQueryAccountPaths() {
361
+ return this._baseModuleQueryAccountPaths;
362
+ }
363
+ set status(value) {
364
+ if (this._status !== "dead") {
365
+ this._status = value;
366
+ }
367
+ }
368
+ static _getRootFunction(funcName) {
369
+ let anyThis = this;
370
+ while (anyThis.__proto__[funcName]) {
371
+ anyThis = anyThis.__proto__;
372
+ }
373
+ return anyThis[funcName];
374
+ }
375
+ static _noOverride(functionName) {
376
+ const thisFunc = this[functionName];
377
+ const rootFunc = this._getRootFunction(functionName);
378
+ (0, import_assert2.assertEx)(thisFunc === rootFunc, () => `Override not allowed for [${functionName}] - override ${functionName}Handler instead`);
379
+ }
380
+ static async create(params) {
381
+ this._noOverride("create");
382
+ if (!this.configSchemas || this.configSchemas.length === 0) {
383
+ throw new Error(`Missing configSchema [${params?.config?.schema}][${this.name}]`);
384
+ }
385
+ if (!this.defaultConfigSchema) {
386
+ throw new Error(`Missing defaultConfigSchema [${params?.config?.schema}][${this.name}]`);
387
+ }
388
+ (0, import_assert2.assertEx)(params?.config?.name === void 0 || (0, import_module_model.isModuleName)(params.config.name), () => `Invalid module name: ${params?.config?.name}`);
389
+ const { account } = params ?? {};
390
+ const schema = params?.config?.schema ?? this.defaultConfigSchema;
391
+ const allowedSchemas = this.configSchemas;
392
+ (0, import_assert2.assertEx)(allowedSchemas.includes(schema), () => `Bad Config Schema [Received ${schema}] [Expected ${JSON.stringify(allowedSchemas)}]`);
393
+ const mutatedConfig = {
394
+ ...params?.config,
395
+ schema
396
+ };
397
+ params?.logger?.debug(`config: ${JSON.stringify(mutatedConfig, null, 2)}`);
398
+ const mutatedParams = {
399
+ ...params,
400
+ config: mutatedConfig
401
+ };
402
+ const activeLogger = params?.logger ?? _AbstractModule.defaultLogger;
403
+ const generatedAccount = await _AbstractModule.determineAccount({
404
+ account
405
+ });
406
+ const address = generatedAccount.address;
407
+ mutatedParams.logger = activeLogger ? new import_logger.IdLogger(activeLogger, () => `0x${address}`) : void 0;
408
+ const newModule = new this(_AbstractModule.privateConstructorKey, mutatedParams, generatedAccount);
409
+ if (!_AbstractModule.enableLazyLoad) {
410
+ await newModule.start?.();
411
+ }
412
+ return newModule;
413
+ }
414
+ static async determineAccount(params) {
415
+ return await determineAccount(params, this.allowRandomAccount);
416
+ }
417
+ static factory(params) {
418
+ return import_module_model.ModuleFactory.withParams(this, params);
419
+ }
420
+ _getRootFunction(funcName) {
421
+ let anyThis = this;
422
+ while (anyThis.__proto__[funcName]) {
423
+ anyThis = anyThis.__proto__;
424
+ }
425
+ return anyThis[funcName];
426
+ }
427
+ async busy(closure) {
428
+ if (this._busyCount <= 0) {
429
+ this._busyCount = 0;
430
+ const args = {
431
+ busy: true,
432
+ module: this
433
+ };
434
+ await this.emit("moduleBusy", args);
435
+ }
436
+ this._busyCount++;
437
+ try {
438
+ return await closure();
439
+ } finally {
440
+ this._busyCount--;
441
+ if (this._busyCount <= 0) {
442
+ this._busyCount = 0;
443
+ const args = {
444
+ busy: false,
445
+ module: this
446
+ };
447
+ await this.emit("moduleBusy", args);
448
+ }
449
+ }
450
+ }
451
+ emit(eventName, eventArgs) {
452
+ return super.emit(eventName, eventArgs);
453
+ }
454
+ previousHash() {
455
+ this._checkDead();
456
+ return this.account.previousHash;
457
+ }
458
+ async query(query, payloads, queryConfig) {
459
+ this._checkDead();
460
+ this._noOverride("query");
461
+ const sourceQuery = await import_payload_builder2.PayloadBuilder.build((0, import_assert2.assertEx)(import_boundwitness_wrapper3.QueryBoundWitnessWrapper.unwrap(query), () => "Invalid query"));
462
+ return await this.busy(async () => {
463
+ const resultPayloads = [];
464
+ const errorPayloads = [];
465
+ const queryAccount = this.ephemeralQueryAccountEnabled ? import_account2.Account.randomSync() : void 0;
466
+ try {
467
+ await this.started("throw");
468
+ if (!this.allowAnonymous && query.addresses.length === 0) {
469
+ throw new Error(`Anonymous Queries not allowed, but running anyway [${this.config.name}], [${this.address}]`);
470
+ }
471
+ if (queryConfig?.allowedQueries) {
472
+ (0, import_assert2.assertEx)(queryConfig?.allowedQueries.includes(sourceQuery.schema), () => `Query not allowed [${sourceQuery.schema}]`);
473
+ }
474
+ resultPayloads.push(...await this.queryHandler(sourceQuery, payloads, queryConfig));
475
+ } catch (ex) {
476
+ await (0, import_error.handleErrorAsync)(ex, async (err) => {
477
+ const error = err;
478
+ this._lastError = error;
479
+ errorPayloads.push(await new ModuleErrorBuilder().sources([
480
+ sourceQuery.$hash
481
+ ]).name(this.config.name ?? "<Unknown>").query(sourceQuery.schema).details(error.details).message(error.message).build());
482
+ });
483
+ }
484
+ if (this.timestamp) {
485
+ const timestamp = {
486
+ schema: "network.xyo.timestamp",
487
+ timestamp: Date.now()
488
+ };
489
+ resultPayloads.push(timestamp);
490
+ }
491
+ const result = await this.bindQueryResult(sourceQuery, resultPayloads, queryAccount ? [
492
+ queryAccount
493
+ ] : [], errorPayloads);
494
+ const args = {
495
+ module: this,
496
+ payloads,
497
+ query: sourceQuery,
498
+ result
499
+ };
500
+ await this.emit("moduleQueried", args);
501
+ return result;
502
+ });
503
+ }
504
+ async queryable(query, payloads, queryConfig) {
505
+ if (this.dead) {
506
+ return false;
507
+ }
508
+ if (!await this.started("warn"))
509
+ return false;
510
+ const configValidator = queryConfig ? new ModuleConfigQueryValidator(Object.assign({}, this.config, queryConfig)).queryable : this.moduleConfigQueryValidator;
511
+ const validators = [
512
+ this.supportedQueryValidator,
513
+ configValidator
514
+ ];
515
+ return validators.every((validator) => validator(query, payloads));
516
+ }
517
+ start(_timeout) {
518
+ this._startPromise = this._startPromise ?? this.startHandler();
519
+ const result = this._startPromise;
520
+ this.status = result ? "started" : "dead";
521
+ return result;
522
+ }
523
+ async started(notStartedAction = "log", tryStart = true) {
524
+ const started = await this._started;
525
+ if (started === true) {
526
+ return true;
527
+ }
528
+ if (!started) {
529
+ this._started = (async () => {
530
+ if (tryStart) {
531
+ try {
532
+ await this.start();
533
+ return true;
534
+ } catch (ex) {
535
+ (0, import_error.handleError)(ex, (error) => {
536
+ this.logger?.warn(`Autostart of Module Failed: ${error.message})`);
537
+ this._started = void 0;
538
+ });
539
+ }
540
+ }
541
+ switch (notStartedAction) {
542
+ case "throw": {
543
+ throw new Error(`Module not Started [${this.address}]`);
544
+ }
545
+ case "warn": {
546
+ this.logger?.warn("Module not started");
547
+ break;
548
+ }
549
+ case "error": {
550
+ this.logger?.error("Module not started");
551
+ break;
552
+ }
553
+ case "none": {
554
+ break;
555
+ }
556
+ default: {
557
+ this.logger?.log("Module not started");
558
+ break;
559
+ }
560
+ }
561
+ return false;
562
+ })();
563
+ }
564
+ if (!this._started) {
565
+ throw "Failed to create start promise";
566
+ }
567
+ return await this._started;
568
+ }
569
+ async stop(_timeout) {
570
+ return await this.busy(async () => {
571
+ const result = await this.stopHandler();
572
+ this._started = void 0;
573
+ this._startPromise = void 0;
574
+ this.status = result ? "stopped" : "dead";
575
+ return result;
576
+ });
577
+ }
578
+ _checkDead() {
579
+ if (this.dead) {
580
+ throw new import_module_model.DeadModuleError(this.id, this._lastError);
581
+ }
582
+ }
583
+ _noOverride(functionName) {
584
+ const thisFunc = this[functionName];
585
+ const rootFunc = this._getRootFunction(functionName);
586
+ (0, import_assert2.assertEx)(thisFunc === rootFunc, () => `Override not allowed for [${functionName}] - override ${functionName}Handler instead`);
587
+ }
588
+ async archivistInstance(required = false) {
589
+ const archivist = this.archivist;
590
+ if (!archivist) {
591
+ if (required) {
592
+ throw new Error("No archivist specified");
593
+ }
594
+ return void 0;
595
+ }
596
+ const resolved = await this.upResolver.resolve(archivist) ?? await this.downResolver.resolve(archivist);
597
+ if (required) {
598
+ (0, import_assert2.assertEx)(resolved, () => `Unable to resolve archivist [${archivist}]`);
599
+ }
600
+ return resolved ? (0, import_archivist_model.asArchivistInstance)(resolved, () => `Specified archivist is not an Archivist [${archivist}]`) : void 0;
601
+ }
602
+ bindHashes(hashes, schema, account) {
603
+ const promise = new import_promise.PromiseEx((resolve) => {
604
+ const result = this.bindHashesInternal(hashes, schema, account);
605
+ resolve?.(result);
606
+ return result;
607
+ }, account);
608
+ return promise;
609
+ }
610
+ async bindHashesInternal(hashes, schema, account) {
611
+ const builder = new import_boundwitness_builder.BoundWitnessBuilder().hashes(hashes, schema).witness(this.account);
612
+ const result = (await (account ? builder.witness(account) : builder).build())[0];
613
+ this.logger?.debug(`result: ${JSON.stringify(result, null, 2)}`);
614
+ return result;
615
+ }
616
+ bindQuery(query, payloads, account) {
617
+ const promise = new import_promise.PromiseEx(async (resolve) => {
618
+ const result = await this.bindQueryInternal(query, payloads, account);
619
+ resolve?.(result);
620
+ return result;
621
+ }, account);
622
+ return promise;
623
+ }
624
+ async bindQueryInternal(query, payloads, account) {
625
+ const builder = await new import_boundwitness_builder.QueryBoundWitnessBuilder().payloads(payloads).witness(this.account).query(query);
626
+ const result = await (account ? builder.witness(account) : builder).build();
627
+ return result;
628
+ }
629
+ async bindQueryResult(query, payloads, additionalWitnesses = [], errors) {
630
+ const builder = new import_boundwitness_builder.BoundWitnessBuilder().payloads(payloads).errors(errors).sourceQuery(query.$hash);
631
+ const queryWitnessAccount = this.queryAccounts[query.schema];
632
+ const witnesses = [
633
+ this.account,
634
+ queryWitnessAccount,
635
+ ...additionalWitnesses
636
+ ].filter(import_exists.exists);
637
+ builder.witnesses(witnesses);
638
+ const result = [
639
+ (await builder.build())[0],
640
+ await Promise.all(payloads.map((payload) => import_payload_builder2.PayloadBuilder.build(payload))),
641
+ await Promise.all((errors ?? [])?.map((error) => import_payload_builder2.PayloadBuilder.build(error)))
642
+ ];
643
+ if (this.archiving && this.isAllowedArchivingQuery(query.schema)) {
644
+ await this.storeToArchivists(result.flat());
645
+ }
646
+ return result;
647
+ }
648
+ async generateConfigAndAddress(_maxDepth) {
649
+ const config = await import_payload_builder2.PayloadBuilder.build(this.config);
650
+ const address = await new import_payload_builder2.PayloadBuilder({
651
+ schema: import_address_payload_plugin.AddressSchema
652
+ }).fields({
653
+ address: this.address,
654
+ name: this.config?.name
655
+ }).build();
656
+ const queries = await Promise.all(this.queries.map(async (query) => {
657
+ return await new import_payload_builder2.PayloadBuilder({
658
+ schema: import_query_payload_plugin.QuerySchema
659
+ }).fields({
660
+ query
661
+ }).build();
662
+ }));
663
+ const configSchema = await import_payload_builder2.PayloadBuilder.build({
664
+ config: config.schema,
665
+ schema: import_config_payload_plugin.ConfigSchema
666
+ });
667
+ return (0, import_lodash.compact)([
668
+ config,
669
+ configSchema,
670
+ address,
671
+ ...queries
672
+ ]);
673
+ }
674
+ async generateDescribe() {
675
+ const description = {
676
+ address: this.address,
677
+ queries: this.queries,
678
+ schema: import_module_model.ModuleDescriptionSchema
679
+ };
680
+ if (this.config?.name) {
681
+ description.name = this.config.name;
682
+ }
683
+ const discover = await this.generateConfigAndAddress();
684
+ description.children = (0, import_lodash.compact)(discover?.map((payload) => {
685
+ const address = payload.schema === import_address_payload_plugin.AddressSchema ? payload.address : void 0;
686
+ return address == this.address ? void 0 : address;
687
+ }) ?? []);
688
+ return description;
689
+ }
690
+ /** @deprecated use archivistInstance() instead */
691
+ async getArchivist() {
692
+ return await this.archivistInstance();
693
+ }
694
+ async initializeQueryAccounts() {
695
+ const paths = Object.values(this.queryAccountPaths).filter(import_exists.exists);
696
+ const distinctPaths = new Set(paths);
697
+ (0, import_assert2.assertEx)(distinctPaths.size === paths.length, () => `${this.config?.name ? this.config.name + ": " : ""}Duplicate query account paths`);
698
+ const wallet = this.account;
699
+ if (wallet?.derivePath) {
700
+ for (const key in this.queryAccountPaths) {
701
+ if (Object.prototype.hasOwnProperty.call(this.queryAccountPaths, key)) {
702
+ const query = key;
703
+ const queryAccountPath = this.queryAccountPaths[query];
704
+ if (queryAccountPath) {
705
+ this._queryAccounts[query] = await wallet.derivePath?.(queryAccountPath);
706
+ }
707
+ }
708
+ }
709
+ }
710
+ }
711
+ manifestHandler(_maxDepth = 1, _ignoreAddresses = []) {
712
+ throw new Error("Not supported");
713
+ }
714
+ moduleAddressHandler() {
715
+ const queryAccounts = Object.entries(this.queryAccounts).filter((value) => {
716
+ return (0, import_exists.exists)(value[1]);
717
+ }).map(([name2, account]) => {
718
+ const address2 = account.address;
719
+ const previousHash2 = account.previousHash;
720
+ return [
721
+ {
722
+ address: address2,
723
+ name: name2,
724
+ schema: import_address_payload_plugin.AddressSchema
725
+ },
726
+ {
727
+ address: address2,
728
+ previousHash: previousHash2,
729
+ schema: import_module_model.AddressPreviousHashSchema
730
+ }
731
+ ];
732
+ });
733
+ const address = this.address;
734
+ const name = this.config.name;
735
+ const previousHash = this.address;
736
+ const moduleAccount = name ? {
737
+ address,
738
+ name,
739
+ schema: import_address_payload_plugin.AddressSchema
740
+ } : {
741
+ address,
742
+ schema: import_address_payload_plugin.AddressSchema
743
+ };
744
+ const moduleAccountPreviousHash = previousHash ? {
745
+ address,
746
+ previousHash,
747
+ schema: import_module_model.AddressPreviousHashSchema
748
+ } : {
749
+ address,
750
+ schema: import_module_model.AddressPreviousHashSchema
751
+ };
752
+ return [
753
+ moduleAccount,
754
+ moduleAccountPreviousHash,
755
+ ...queryAccounts
756
+ ].flat();
757
+ }
758
+ async queryHandler(query, payloads, queryConfig) {
759
+ await this.started("throw");
760
+ const wrapper = await import_boundwitness_wrapper3.QueryBoundWitnessWrapper.parseQuery(query, payloads);
761
+ const queryPayload = await wrapper.getQuery();
762
+ (0, import_assert2.assertEx)(await this.queryable(query, payloads, queryConfig));
763
+ const resultPayloads = [];
764
+ switch (queryPayload.schema) {
765
+ case import_module_model.ModuleManifestQuerySchema: {
766
+ resultPayloads.push(await this.manifestHandler(queryPayload.maxDepth));
767
+ break;
768
+ }
769
+ case import_module_model.ModuleAddressQuerySchema: {
770
+ resultPayloads.push(...await this.moduleAddressHandler());
771
+ break;
772
+ }
773
+ case import_module_model.ModuleStateQuerySchema: {
774
+ resultPayloads.push(...await this.stateHandler());
775
+ break;
776
+ }
777
+ case import_module_model.ModuleSubscribeQuerySchema: {
778
+ this.subscribeHandler();
779
+ break;
780
+ }
781
+ default: {
782
+ throw new Error(`Unsupported Query [${queryPayload.schema}]`);
783
+ }
784
+ }
785
+ return resultPayloads;
786
+ }
787
+ async startHandler() {
788
+ this.validateConfig();
789
+ await this.initializeQueryAccounts();
790
+ this._started = true;
791
+ return true;
792
+ }
793
+ async stateHandler() {
794
+ return [
795
+ await this.manifestHandler(),
796
+ ...await this.generateConfigAndAddress(),
797
+ await this.generateDescribe()
798
+ ];
799
+ }
800
+ stopHandler(_timeout) {
801
+ this._started = void 0;
802
+ return true;
803
+ }
804
+ subscribeHandler() {
805
+ return;
806
+ }
807
+ validateConfig(config, parents = []) {
808
+ return Object.entries(config ?? this.config ?? {}).reduce((valid, [key, value]) => {
809
+ switch (typeof value) {
810
+ case "function": {
811
+ this.logger?.warn(`Fields of type function not allowed in config [${parents?.join(".")}.${key}]`);
812
+ return false;
813
+ }
814
+ case "object": {
815
+ if (Array.isArray(value)) {
816
+ return (
817
+ // eslint-disable-next-line unicorn/no-array-reduce
818
+ value.reduce((valid2, value2) => {
819
+ return this.validateConfig(value2, [
820
+ ...parents,
821
+ key
822
+ ]) && valid2;
823
+ }, true) && valid
824
+ );
825
+ }
826
+ if (!(0, import_module_model.serializableField)(value)) {
827
+ this.logger?.warn(`Fields that are not serializable to JSON are not allowed in config [${parents?.join(".")}.${key}]`);
828
+ return false;
829
+ }
830
+ return value ? this.validateConfig(value, [
831
+ ...parents,
832
+ key
833
+ ]) && valid : true;
834
+ }
835
+ default: {
836
+ return valid;
837
+ }
838
+ }
839
+ }, true);
840
+ }
841
+ isAllowedArchivingQuery(schema) {
842
+ const queries = this.archiving?.queries;
843
+ if (queries) {
844
+ return queries.includes(schema);
845
+ }
846
+ return true;
847
+ }
848
+ };
849
+
850
+ // src/AbstractModuleInstance.ts
851
+ var import_assert3 = require("@xylabs/assert");
852
+ var import_lodash2 = require("@xylabs/lodash");
853
+ var import_object3 = require("@xylabs/object");
854
+ var import_archivist_model2 = require("@xyo-network/archivist-model");
855
+ var import_manifest_model = require("@xyo-network/manifest-model");
856
+ var import_module_model2 = require("@xyo-network/module-model");
857
+ var import_module_resolver = require("@xyo-network/module-resolver");
858
+ var AbstractModuleInstance = class _AbstractModuleInstance extends AbstractModule {
859
+ static {
860
+ __name(this, "AbstractModuleInstance");
861
+ }
862
+ static uniqueName = (0, import_object3.globallyUnique)("AbstractModuleInstance", _AbstractModuleInstance, "xyo");
863
+ _downResolver;
864
+ _parents = [];
865
+ _privateResolver;
866
+ _upResolver;
867
+ constructor(privateConstructorKey, params, account) {
868
+ (0, import_assert3.assertEx)(AbstractModule.privateConstructorKey === privateConstructorKey, () => "Use create function instead of constructor");
869
+ const mutatedParams = {
870
+ ...params
871
+ };
872
+ const addToResolvers = mutatedParams.addToResolvers ?? true;
873
+ super(privateConstructorKey, mutatedParams, account);
874
+ if (addToResolvers) {
875
+ this.upResolver.add(this);
876
+ this.downResolver.add(this);
877
+ }
878
+ }
879
+ get downResolver() {
880
+ this._downResolver = this._downResolver ?? new import_module_resolver.CompositeModuleResolver({
881
+ allowNameResolution: this.allowNameResolution,
882
+ moduleIdentifierTransformers: this.params.moduleIdentifierTransformers,
883
+ root: this
884
+ });
885
+ return this._downResolver;
886
+ }
887
+ get localName() {
888
+ return this.config.name;
889
+ }
890
+ get moduleIdentifierTransformers() {
891
+ return this.params.moduleIdentifierTransformers ?? import_module_model2.ResolveHelper.transformers;
892
+ }
893
+ get privateResolver() {
894
+ this._privateResolver = this._privateResolver ?? new import_module_resolver.CompositeModuleResolver({
895
+ allowNameResolution: this.allowNameResolution,
896
+ moduleIdentifierTransformers: this.params.moduleIdentifierTransformers,
897
+ root: this
898
+ });
899
+ return this._privateResolver;
900
+ }
901
+ get root() {
902
+ return this;
903
+ }
904
+ get upResolver() {
905
+ this._upResolver = this._upResolver ?? new import_module_resolver.CompositeModuleResolver({
906
+ allowNameResolution: this.allowNameResolution,
907
+ moduleIdentifierTransformers: this.params.moduleIdentifierTransformers,
908
+ root: this
909
+ });
910
+ return this._upResolver;
911
+ }
912
+ addParent(module2) {
913
+ const existingEntry = this._parents.find((parent) => parent.address === module2.address);
914
+ if (!existingEntry) {
915
+ this._parents.push(module2);
916
+ }
917
+ }
918
+ manifest(maxDepth) {
919
+ this._checkDead();
920
+ return this.busy(async () => {
921
+ return await this.manifestHandler(maxDepth);
922
+ });
923
+ }
924
+ async manifestQuery(account, maxDepth) {
925
+ const queryPayload = {
926
+ schema: import_module_model2.ModuleManifestQuerySchema,
927
+ ...maxDepth === void 0 ? {} : {
928
+ maxDepth
929
+ }
930
+ };
931
+ return await this.sendQueryRaw(queryPayload, void 0, account);
932
+ }
933
+ moduleAddress() {
934
+ this._checkDead();
935
+ return this.busy(async () => {
936
+ return await this.moduleAddressHandler();
937
+ });
938
+ }
939
+ parents() {
940
+ return this._parents;
941
+ }
942
+ privateChildren() {
943
+ return [];
944
+ }
945
+ publicChildren() {
946
+ return [];
947
+ }
948
+ removeParent(address) {
949
+ this._parents = this._parents.filter((item) => item.address !== address);
950
+ }
951
+ async resolve(idOrFilter = "*", options = {}) {
952
+ const config = {
953
+ address: this.address,
954
+ dead: this.dead,
955
+ downResolver: this.downResolver,
956
+ logger: this.logger,
957
+ module: this,
958
+ transformers: this.moduleIdentifierTransformers,
959
+ upResolver: this.upResolver
960
+ };
961
+ if (idOrFilter === "*") {
962
+ return (await import_module_model2.ResolveHelper.resolve(config, idOrFilter, options)).filter((mod) => mod.address !== this.address);
963
+ }
964
+ switch (typeof idOrFilter) {
965
+ case "string": {
966
+ return await import_module_model2.ResolveHelper.resolve(config, idOrFilter, options);
967
+ }
968
+ case "object": {
969
+ return (await import_module_model2.ResolveHelper.resolve(config, idOrFilter, options)).filter((mod) => mod.address !== this.address);
970
+ }
971
+ default: {
972
+ return (await import_module_model2.ResolveHelper.resolve(config, idOrFilter, options)).filter((mod) => mod.address !== this.address);
973
+ }
974
+ }
975
+ }
976
+ resolveIdentifier(id, options) {
977
+ const { direction = "all" } = options ?? {};
978
+ switch (direction) {
979
+ case "down": {
980
+ return this.downResolver.resolveIdentifier(id, options);
981
+ }
982
+ default: {
983
+ const mutatedOptions = {
984
+ ...options,
985
+ direction: "all"
986
+ };
987
+ return this.upResolver.resolveIdentifier(id, mutatedOptions);
988
+ }
989
+ }
990
+ }
991
+ async resolvePrivate(id = "*", options = {}) {
992
+ return await this.privateResolver.resolve(id, options) ?? await this.upResolver.resolve(id, options) ?? await this.downResolver.resolve(id, options);
993
+ }
994
+ async siblings() {
995
+ return (await Promise.all((await this.parents()).map((parent) => parent.publicChildren()))).flat().filter(import_module_model2.duplicateModules);
996
+ }
997
+ state() {
998
+ this._checkDead();
999
+ return this.busy(async () => {
1000
+ return await this.stateHandler();
1001
+ });
1002
+ }
1003
+ async stateQuery(account) {
1004
+ const queryPayload = {
1005
+ schema: import_module_model2.ModuleStateQuerySchema
1006
+ };
1007
+ return await this.sendQueryRaw(queryPayload, void 0, account);
1008
+ }
1009
+ subscribe(_queryAccount) {
1010
+ this._checkDead();
1011
+ return this.subscribeHandler();
1012
+ }
1013
+ async manifestHandler(maxDepth = 1, _ignoreAddresses = []) {
1014
+ const cachedResult = this._cachedManifests.get(maxDepth);
1015
+ if (cachedResult) {
1016
+ return cachedResult;
1017
+ }
1018
+ const name = this.config.name ?? "Anonymous";
1019
+ const children = await this.publicChildren();
1020
+ const childAddressToName = {};
1021
+ for (const child of children) {
1022
+ if (child.address !== this.address) {
1023
+ childAddressToName[child.address] = child.config.name ?? null;
1024
+ }
1025
+ }
1026
+ const result = {
1027
+ config: {
1028
+ name,
1029
+ ...this.config
1030
+ },
1031
+ schema: import_manifest_model.ModuleManifestPayloadSchema,
1032
+ status: {
1033
+ address: this.address,
1034
+ children: childAddressToName
1035
+ }
1036
+ };
1037
+ this._cachedManifests.set(maxDepth, result);
1038
+ return result;
1039
+ }
1040
+ async resolveArchivingArchivists() {
1041
+ const archivists = this.config.archiving?.archivists;
1042
+ if (!archivists)
1043
+ return [];
1044
+ const resolved = await Promise.all(archivists.map((archivist) => this.resolve(archivist)));
1045
+ return (0, import_lodash2.compact)(resolved.map((mod) => (0, import_archivist_model2.asArchivistInstance)(mod)));
1046
+ }
1047
+ async sendQuery(queryPayload, payloads, account) {
1048
+ const queryResults = await this.sendQueryRaw(queryPayload, payloads, account);
1049
+ const [, resultPayloads, errors] = queryResults;
1050
+ if (errors && errors.length > 0) {
1051
+ throw errors[0];
1052
+ }
1053
+ return resultPayloads;
1054
+ }
1055
+ async sendQueryRaw(queryPayload, payloads, account) {
1056
+ const query = await this.bindQuery(queryPayload, payloads, account);
1057
+ return await this.query(query[0], query[1]);
1058
+ }
1059
+ async storeToArchivists(payloads) {
1060
+ const archivists = await this.resolveArchivingArchivists();
1061
+ return (await Promise.all(archivists.map((archivist) => {
1062
+ return archivist.insert?.(payloads);
1063
+ }))).map(([bw]) => bw);
1064
+ }
1065
+ };
1066
+ //# sourceMappingURL=index.cjs.map