@xyo-network/module-abstract 2.92.6 → 2.92.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/AbstractModule.d.cts +19 -7
- package/dist/browser/AbstractModule.d.cts.map +1 -1
- package/dist/browser/AbstractModule.d.mts +19 -7
- package/dist/browser/AbstractModule.d.mts.map +1 -1
- package/dist/browser/AbstractModule.d.ts +19 -7
- package/dist/browser/AbstractModule.d.ts.map +1 -1
- package/dist/browser/AbstractModuleInstance.d.cts +2 -1
- package/dist/browser/AbstractModuleInstance.d.cts.map +1 -1
- package/dist/browser/AbstractModuleInstance.d.mts +2 -1
- package/dist/browser/AbstractModuleInstance.d.mts.map +1 -1
- package/dist/browser/AbstractModuleInstance.d.ts +2 -1
- package/dist/browser/AbstractModuleInstance.d.ts.map +1 -1
- package/dist/browser/determineAccount.d.cts.map +1 -1
- package/dist/browser/determineAccount.d.mts.map +1 -1
- package/dist/browser/determineAccount.d.ts.map +1 -1
- package/dist/browser/index.cjs +94 -38
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.js +95 -39
- package/dist/browser/index.js.map +1 -1
- package/dist/node/AbstractModule.d.cts +19 -7
- package/dist/node/AbstractModule.d.cts.map +1 -1
- package/dist/node/AbstractModule.d.mts +19 -7
- package/dist/node/AbstractModule.d.mts.map +1 -1
- package/dist/node/AbstractModule.d.ts +19 -7
- package/dist/node/AbstractModule.d.ts.map +1 -1
- package/dist/node/AbstractModuleInstance.d.cts +2 -1
- package/dist/node/AbstractModuleInstance.d.cts.map +1 -1
- package/dist/node/AbstractModuleInstance.d.mts +2 -1
- package/dist/node/AbstractModuleInstance.d.mts.map +1 -1
- package/dist/node/AbstractModuleInstance.d.ts +2 -1
- package/dist/node/AbstractModuleInstance.d.ts.map +1 -1
- package/dist/node/determineAccount.d.cts.map +1 -1
- package/dist/node/determineAccount.d.mts.map +1 -1
- package/dist/node/determineAccount.d.ts.map +1 -1
- package/dist/node/index.cjs +101 -42
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.js +102 -43
- package/dist/node/index.js.map +1 -1
- package/package.json +25 -25
- package/src/AbstractModule.ts +111 -44
- package/src/AbstractModuleInstance.ts +9 -2
- package/src/determineAccount.ts +6 -3
package/dist/browser/index.cjs
CHANGED
|
@@ -98,7 +98,7 @@ var BaseEmitter = class extends import_object.Base {
|
|
|
98
98
|
var import_assert = require("@xylabs/assert");
|
|
99
99
|
var import_account = require("@xyo-network/account");
|
|
100
100
|
var isDetermineAccountFromAccountParams = /* @__PURE__ */ __name((params) => {
|
|
101
|
-
(0, import_assert.assertEx)(!params.accountPath, "accountPath may not be provided when account is provided");
|
|
101
|
+
(0, import_assert.assertEx)(!params.accountPath, () => "accountPath may not be provided when account is provided");
|
|
102
102
|
return !!params.account;
|
|
103
103
|
}, "isDetermineAccountFromAccountParams");
|
|
104
104
|
var isDetermineAccountFromWalletParams = /* @__PURE__ */ __name((params) => {
|
|
@@ -107,13 +107,13 @@ var isDetermineAccountFromWalletParams = /* @__PURE__ */ __name((params) => {
|
|
|
107
107
|
async function determineAccount(params, allowRandomAccount = true) {
|
|
108
108
|
if (isDetermineAccountFromAccountParams(params)) {
|
|
109
109
|
if (params.account === "random") {
|
|
110
|
-
(0, import_assert.assertEx)(allowRandomAccount, "Random address not allowed");
|
|
110
|
+
(0, import_assert.assertEx)(allowRandomAccount, () => "Random address not allowed");
|
|
111
111
|
return import_account.Account.randomSync();
|
|
112
112
|
}
|
|
113
113
|
return params.account;
|
|
114
114
|
}
|
|
115
115
|
if (isDetermineAccountFromWalletParams(params)) {
|
|
116
|
-
return (0, import_assert.assertEx)(params.accountPath ? await params.wallet.derivePath(params.accountPath) : params.wallet, "Failed to derive account from path");
|
|
116
|
+
return (0, import_assert.assertEx)(params.accountPath ? await params.wallet.derivePath(params.accountPath) : params.wallet, () => "Failed to derive account from path");
|
|
117
117
|
}
|
|
118
118
|
console.warn("AbstractModule.determineAccount: No account or wallet provided - Creating Random account");
|
|
119
119
|
return import_account.Account.randomSync();
|
|
@@ -264,6 +264,7 @@ var AbstractModule = class _AbstractModule extends BaseEmitter {
|
|
|
264
264
|
[import_module_model.ModuleStateQuerySchema]: "6",
|
|
265
265
|
[import_module_model.ModuleSubscribeQuerySchema]: "3"
|
|
266
266
|
};
|
|
267
|
+
_lastError;
|
|
267
268
|
_queryAccounts = {
|
|
268
269
|
[import_module_model.ModuleAddressQuerySchema]: void 0,
|
|
269
270
|
[import_module_model.ModuleDescribeQuerySchema]: void 0,
|
|
@@ -277,8 +278,9 @@ var AbstractModule = class _AbstractModule extends BaseEmitter {
|
|
|
277
278
|
moduleConfigQueryValidator;
|
|
278
279
|
supportedQueryValidator;
|
|
279
280
|
_busyCount = 0;
|
|
281
|
+
_status = "stopped";
|
|
280
282
|
constructor(privateConstructorKey, params, account) {
|
|
281
|
-
(0, import_assert2.assertEx)(_AbstractModule.privateConstructorKey === privateConstructorKey, "Use create function instead of constructor");
|
|
283
|
+
(0, import_assert2.assertEx)(_AbstractModule.privateConstructorKey === privateConstructorKey, () => "Use create function instead of constructor");
|
|
282
284
|
const mutatedParams = {
|
|
283
285
|
...params
|
|
284
286
|
};
|
|
@@ -291,7 +293,7 @@ var AbstractModule = class _AbstractModule extends BaseEmitter {
|
|
|
291
293
|
return this.configSchemas[0];
|
|
292
294
|
}
|
|
293
295
|
get account() {
|
|
294
|
-
return (0, import_assert2.assertEx)(this._account, "Missing account");
|
|
296
|
+
return (0, import_assert2.assertEx)(this._account, () => "Missing account");
|
|
295
297
|
}
|
|
296
298
|
get address() {
|
|
297
299
|
return this.account.address;
|
|
@@ -302,6 +304,9 @@ var AbstractModule = class _AbstractModule extends BaseEmitter {
|
|
|
302
304
|
get config() {
|
|
303
305
|
return this.params.config;
|
|
304
306
|
}
|
|
307
|
+
get dead() {
|
|
308
|
+
return this.status === "dead";
|
|
309
|
+
}
|
|
305
310
|
get ephemeralQueryAccountEnabled() {
|
|
306
311
|
return !!this.params.ephemeralQueryAccountEnabled;
|
|
307
312
|
}
|
|
@@ -327,6 +332,9 @@ var AbstractModule = class _AbstractModule extends BaseEmitter {
|
|
|
327
332
|
get queryAccounts() {
|
|
328
333
|
return this._queryAccounts;
|
|
329
334
|
}
|
|
335
|
+
get status() {
|
|
336
|
+
return this._status;
|
|
337
|
+
}
|
|
330
338
|
get timestamp() {
|
|
331
339
|
return this.config.timestamp ?? false;
|
|
332
340
|
}
|
|
@@ -336,6 +344,11 @@ var AbstractModule = class _AbstractModule extends BaseEmitter {
|
|
|
336
344
|
get logger() {
|
|
337
345
|
return this.params?.logger ?? _AbstractModule.defaultLogger ?? import_object2.Base.defaultLogger;
|
|
338
346
|
}
|
|
347
|
+
set status(value) {
|
|
348
|
+
if (this._status !== "dead") {
|
|
349
|
+
this._status = value;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
339
352
|
static _getRootFunction(funcName) {
|
|
340
353
|
let anyThis = this;
|
|
341
354
|
while (anyThis.__proto__[funcName]) {
|
|
@@ -346,14 +359,14 @@ var AbstractModule = class _AbstractModule extends BaseEmitter {
|
|
|
346
359
|
static _noOverride(functionName) {
|
|
347
360
|
const thisFunc = this[functionName];
|
|
348
361
|
const rootFunc = this._getRootFunction(functionName);
|
|
349
|
-
(0, import_assert2.assertEx)(thisFunc === rootFunc, `Override not allowed for [${functionName}] - override ${functionName}Handler instead`);
|
|
362
|
+
(0, import_assert2.assertEx)(thisFunc === rootFunc, () => `Override not allowed for [${functionName}] - override ${functionName}Handler instead`);
|
|
350
363
|
}
|
|
351
364
|
static async create(params) {
|
|
352
365
|
this._noOverride("create");
|
|
353
366
|
if (!this.configSchemas || this.configSchemas.length === 0) {
|
|
354
367
|
throw new Error(`Missing configSchema [${params?.config?.schema}][${this.name}]`);
|
|
355
368
|
}
|
|
356
|
-
(0, import_assert2.assertEx)(params?.config?.name === void 0 || (0, import_module_model.isModuleName)(params.config.name), `Invalid module name: ${params?.config?.name}`);
|
|
369
|
+
(0, import_assert2.assertEx)(params?.config?.name === void 0 || (0, import_module_model.isModuleName)(params.config.name), () => `Invalid module name: ${params?.config?.name}`);
|
|
357
370
|
const { account } = params ?? {};
|
|
358
371
|
const schema = params?.config?.schema ?? this.configSchema;
|
|
359
372
|
const allowedSchemas = this.configSchemas;
|
|
@@ -392,11 +405,6 @@ var AbstractModule = class _AbstractModule extends BaseEmitter {
|
|
|
392
405
|
}
|
|
393
406
|
return anyThis[funcName];
|
|
394
407
|
}
|
|
395
|
-
_noOverride(functionName) {
|
|
396
|
-
const thisFunc = this[functionName];
|
|
397
|
-
const rootFunc = this._getRootFunction(functionName);
|
|
398
|
-
(0, import_assert2.assertEx)(thisFunc === rootFunc, () => `Override not allowed for [${functionName}] - override ${functionName}Handler instead`);
|
|
399
|
-
}
|
|
400
408
|
async busy(closure) {
|
|
401
409
|
if (this._busyCount <= 0) {
|
|
402
410
|
this._busyCount = 0;
|
|
@@ -425,11 +433,13 @@ var AbstractModule = class _AbstractModule extends BaseEmitter {
|
|
|
425
433
|
return super.emit(eventName, eventArgs);
|
|
426
434
|
}
|
|
427
435
|
previousHash() {
|
|
436
|
+
this._checkDead();
|
|
428
437
|
return this.account.previousHash;
|
|
429
438
|
}
|
|
430
439
|
async query(query, payloads, queryConfig) {
|
|
440
|
+
this._checkDead();
|
|
431
441
|
this._noOverride("query");
|
|
432
|
-
const sourceQuery = await import_payload_builder2.PayloadBuilder.build((0, import_assert2.assertEx)(import_boundwitness_wrapper3.QueryBoundWitnessWrapper.unwrap(query), "Invalid query"));
|
|
442
|
+
const sourceQuery = await import_payload_builder2.PayloadBuilder.build((0, import_assert2.assertEx)(import_boundwitness_wrapper3.QueryBoundWitnessWrapper.unwrap(query), () => "Invalid query"));
|
|
433
443
|
return await this.busy(async () => {
|
|
434
444
|
const resultPayloads = [];
|
|
435
445
|
const errorPayloads = [];
|
|
@@ -439,9 +449,14 @@ var AbstractModule = class _AbstractModule extends BaseEmitter {
|
|
|
439
449
|
if (!this.allowAnonymous && query.addresses.length === 0) {
|
|
440
450
|
throw new Error(`Anonymous Queries not allowed, but running anyway [${this.config.name}], [${this.address}]`);
|
|
441
451
|
}
|
|
452
|
+
if (queryConfig?.allowedQueries) {
|
|
453
|
+
(0, import_assert2.assertEx)(queryConfig?.allowedQueries.includes(sourceQuery.schema), () => `Query not allowed [${sourceQuery.schema}]`);
|
|
454
|
+
}
|
|
442
455
|
resultPayloads.push(...await this.queryHandler(sourceQuery, payloads, queryConfig));
|
|
443
456
|
} catch (ex) {
|
|
444
457
|
await (0, import_error.handleErrorAsync)(ex, async (error) => {
|
|
458
|
+
this._lastError = error;
|
|
459
|
+
this.status = "dead";
|
|
445
460
|
errorPayloads.push(await new ModuleErrorBuilder().sources([
|
|
446
461
|
sourceQuery.$hash
|
|
447
462
|
]).name(this.config.name ?? "<Unknown>").query(sourceQuery.schema).message(error.message).build());
|
|
@@ -468,6 +483,9 @@ var AbstractModule = class _AbstractModule extends BaseEmitter {
|
|
|
468
483
|
});
|
|
469
484
|
}
|
|
470
485
|
async queryable(query, payloads, queryConfig) {
|
|
486
|
+
if (this.dead) {
|
|
487
|
+
return false;
|
|
488
|
+
}
|
|
471
489
|
if (!await this.started("warn"))
|
|
472
490
|
return false;
|
|
473
491
|
const configValidator = queryConfig ? new ModuleConfigQueryValidator(Object.assign({}, this.config, queryConfig)).queryable : this.moduleConfigQueryValidator;
|
|
@@ -477,7 +495,7 @@ var AbstractModule = class _AbstractModule extends BaseEmitter {
|
|
|
477
495
|
];
|
|
478
496
|
return validators.every((validator) => validator(query, payloads));
|
|
479
497
|
}
|
|
480
|
-
async resolve(idOrFilter, { required = "log", ...options } = {}) {
|
|
498
|
+
async resolve(idOrFilter = "*", { required = "log", ...options } = {}) {
|
|
481
499
|
const childOptions = {
|
|
482
500
|
...options,
|
|
483
501
|
required: false
|
|
@@ -486,41 +504,44 @@ var AbstractModule = class _AbstractModule extends BaseEmitter {
|
|
|
486
504
|
const up = direction === "up" || direction === "all";
|
|
487
505
|
const down = direction === "down" || direction === "all";
|
|
488
506
|
let result;
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
break;
|
|
507
|
+
if (idOrFilter === "*") {
|
|
508
|
+
if (this.dead) {
|
|
509
|
+
return [];
|
|
493
510
|
}
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
case "warn": {
|
|
506
|
-
this.logger.warn("resolve failed", idOrFilter);
|
|
507
|
-
break;
|
|
508
|
-
}
|
|
509
|
-
case "log": {
|
|
510
|
-
this.logger.log("resolve failed", idOrFilter);
|
|
511
|
+
return [
|
|
512
|
+
...down ? await this.downResolver.resolve("*", childOptions) : [],
|
|
513
|
+
...up ? await this.upResolver.resolve("*", childOptions) : []
|
|
514
|
+
].filter(import_module_model.duplicateModules);
|
|
515
|
+
} else {
|
|
516
|
+
switch (typeof idOrFilter) {
|
|
517
|
+
case "string": {
|
|
518
|
+
if (this.dead) {
|
|
519
|
+
return void 0;
|
|
520
|
+
}
|
|
521
|
+
result = (down ? await this.downResolver.resolve(idOrFilter, childOptions) : void 0) ?? (up ? await this.upResolver.resolve(idOrFilter, childOptions) : void 0);
|
|
511
522
|
break;
|
|
512
523
|
}
|
|
513
524
|
default: {
|
|
514
|
-
this.
|
|
525
|
+
if (this.dead) {
|
|
526
|
+
return [];
|
|
527
|
+
}
|
|
528
|
+
const filter = idOrFilter;
|
|
529
|
+
result = [
|
|
530
|
+
...down ? await this.downResolver.resolve(filter, childOptions) : [],
|
|
531
|
+
...up ? await this.upResolver.resolve(filter, childOptions) : []
|
|
532
|
+
].filter(import_module_model.duplicateModules);
|
|
515
533
|
break;
|
|
516
534
|
}
|
|
517
535
|
}
|
|
518
536
|
}
|
|
537
|
+
this.validateRequiredResolve(required, result, idOrFilter);
|
|
519
538
|
return result;
|
|
520
539
|
}
|
|
521
540
|
start(_timeout) {
|
|
522
541
|
this._startPromise = this._startPromise ?? this.startHandler();
|
|
523
|
-
|
|
542
|
+
const result = this._startPromise;
|
|
543
|
+
this.status = result ? "started" : "dead";
|
|
544
|
+
return result;
|
|
524
545
|
}
|
|
525
546
|
async started(notStartedAction = "log", tryStart = true) {
|
|
526
547
|
const started = await this._started;
|
|
@@ -573,9 +594,20 @@ var AbstractModule = class _AbstractModule extends BaseEmitter {
|
|
|
573
594
|
const result = await this.stopHandler();
|
|
574
595
|
this._started = void 0;
|
|
575
596
|
this._startPromise = void 0;
|
|
597
|
+
this.status = result ? "stopped" : "dead";
|
|
576
598
|
return result;
|
|
577
599
|
});
|
|
578
600
|
}
|
|
601
|
+
_checkDead() {
|
|
602
|
+
if (this.dead) {
|
|
603
|
+
throw new import_module_model.DeadModuleError(this.id, this._lastError);
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
_noOverride(functionName) {
|
|
607
|
+
const thisFunc = this[functionName];
|
|
608
|
+
const rootFunc = this._getRootFunction(functionName);
|
|
609
|
+
(0, import_assert2.assertEx)(thisFunc === rootFunc, () => `Override not allowed for [${functionName}] - override ${functionName}Handler instead`);
|
|
610
|
+
}
|
|
579
611
|
bindHashes(hashes, schema, account) {
|
|
580
612
|
const promise = new import_promise.PromiseEx((resolve) => {
|
|
581
613
|
const result = this.bindHashesInternal(hashes, schema, account);
|
|
@@ -849,6 +881,24 @@ var AbstractModule = class _AbstractModule extends BaseEmitter {
|
|
|
849
881
|
}
|
|
850
882
|
}, true);
|
|
851
883
|
}
|
|
884
|
+
validateRequiredResolve(required, result, idOrFilter) {
|
|
885
|
+
if (required && (result === void 0 || Array.isArray(result) && result.length > 0)) {
|
|
886
|
+
switch (required) {
|
|
887
|
+
case "warn": {
|
|
888
|
+
this.logger.warn("resolve failed", idOrFilter);
|
|
889
|
+
break;
|
|
890
|
+
}
|
|
891
|
+
case "log": {
|
|
892
|
+
this.logger.log("resolve failed", idOrFilter);
|
|
893
|
+
break;
|
|
894
|
+
}
|
|
895
|
+
default: {
|
|
896
|
+
this.logger.error("resolve failed", idOrFilter);
|
|
897
|
+
break;
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
}
|
|
852
902
|
};
|
|
853
903
|
|
|
854
904
|
// src/AbstractModuleInstance.ts
|
|
@@ -858,7 +908,7 @@ var AbstractModuleInstance = class extends AbstractModule {
|
|
|
858
908
|
__name(this, "AbstractModuleInstance");
|
|
859
909
|
}
|
|
860
910
|
constructor(privateConstructorKey, params, account) {
|
|
861
|
-
(0, import_assert3.assertEx)(AbstractModule.privateConstructorKey === privateConstructorKey, "Use create function instead of constructor");
|
|
911
|
+
(0, import_assert3.assertEx)(AbstractModule.privateConstructorKey === privateConstructorKey, () => "Use create function instead of constructor");
|
|
862
912
|
const mutatedParams = {
|
|
863
913
|
...params
|
|
864
914
|
};
|
|
@@ -867,31 +917,37 @@ var AbstractModuleInstance = class extends AbstractModule {
|
|
|
867
917
|
this.downResolver.add(this);
|
|
868
918
|
}
|
|
869
919
|
describe() {
|
|
920
|
+
this._checkDead();
|
|
870
921
|
return this.busy(async () => {
|
|
871
922
|
return await this.describeHandler();
|
|
872
923
|
});
|
|
873
924
|
}
|
|
874
925
|
discover() {
|
|
926
|
+
this._checkDead();
|
|
875
927
|
return this.busy(async () => {
|
|
876
928
|
return await this.discoverHandler();
|
|
877
929
|
});
|
|
878
930
|
}
|
|
879
931
|
manifest(maxDepth, ignoreAddresses) {
|
|
932
|
+
this._checkDead();
|
|
880
933
|
return this.busy(async () => {
|
|
881
934
|
return await this.manifestHandler(maxDepth, ignoreAddresses);
|
|
882
935
|
});
|
|
883
936
|
}
|
|
884
937
|
moduleAddress() {
|
|
938
|
+
this._checkDead();
|
|
885
939
|
return this.busy(async () => {
|
|
886
940
|
return await this.moduleAddressHandler();
|
|
887
941
|
});
|
|
888
942
|
}
|
|
889
943
|
state() {
|
|
944
|
+
this._checkDead();
|
|
890
945
|
return this.busy(async () => {
|
|
891
946
|
return await this.stateHandler();
|
|
892
947
|
});
|
|
893
948
|
}
|
|
894
949
|
subscribe(_queryAccount) {
|
|
950
|
+
this._checkDead();
|
|
895
951
|
return this.subscribeHandler();
|
|
896
952
|
}
|
|
897
953
|
};
|