@xyo-network/module-abstract 7.0.9 → 7.0.10
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/neutral/index.d.ts +1 -5
- package/dist/neutral/index.d.ts.map +1 -1
- package/dist/neutral/index.mjs +2 -919
- package/dist/neutral/index.mjs.map +4 -4
- package/package.json +8 -13
- package/dist/neutral/AbstractModule.d.ts +0 -110
- package/dist/neutral/AbstractModule.d.ts.map +0 -1
- package/dist/neutral/AbstractModuleInstance.d.ts +0 -49
- package/dist/neutral/AbstractModuleInstance.d.ts.map +0 -1
- package/dist/neutral/Error.d.ts +0 -16
- package/dist/neutral/Error.d.ts.map +0 -1
- package/dist/neutral/LoggerModuleStatusReporter.d.ts +0 -9
- package/dist/neutral/LoggerModuleStatusReporter.d.ts.map +0 -1
- package/dist/neutral/QueryValidator/ModuleConfigQueryValidator.d.ts +0 -16
- package/dist/neutral/QueryValidator/ModuleConfigQueryValidator.d.ts.map +0 -1
- package/dist/neutral/QueryValidator/QueryValidator.d.ts +0 -7
- package/dist/neutral/QueryValidator/QueryValidator.d.ts.map +0 -1
- package/dist/neutral/QueryValidator/SupportedQueryValidator.d.ts +0 -10
- package/dist/neutral/QueryValidator/SupportedQueryValidator.d.ts.map +0 -1
- package/dist/neutral/QueryValidator/index.d.ts +0 -4
- package/dist/neutral/QueryValidator/index.d.ts.map +0 -1
- package/dist/neutral/determineAccount.d.ts +0 -16
- package/dist/neutral/determineAccount.d.ts.map +0 -1
package/dist/neutral/index.mjs
CHANGED
|
@@ -1,920 +1,3 @@
|
|
|
1
|
-
// src/
|
|
2
|
-
|
|
3
|
-
AbstractCreatable,
|
|
4
|
-
assertEx as assertEx2,
|
|
5
|
-
ConsoleLogger,
|
|
6
|
-
exists,
|
|
7
|
-
forget,
|
|
8
|
-
globallyUnique,
|
|
9
|
-
handleErrorAsync,
|
|
10
|
-
IdLogger,
|
|
11
|
-
isDefined as isDefined2,
|
|
12
|
-
isObject,
|
|
13
|
-
isString as isString2,
|
|
14
|
-
isUndefined as isUndefined2,
|
|
15
|
-
LevelLogger,
|
|
16
|
-
LogLevel,
|
|
17
|
-
PromiseEx
|
|
18
|
-
} from "@ariestools/sdk";
|
|
19
|
-
import { asArchivistInstance } from "@xyo-network/archivist-model";
|
|
20
|
-
import {
|
|
21
|
-
AddressPreviousHashSchema,
|
|
22
|
-
AddressSchema,
|
|
23
|
-
DeadModuleError,
|
|
24
|
-
isModuleName,
|
|
25
|
-
isSerializable,
|
|
26
|
-
ModuleAddressQuerySchema,
|
|
27
|
-
ModuleConfigSchema,
|
|
28
|
-
ModuleDescriptionSchema,
|
|
29
|
-
ModuleFactory,
|
|
30
|
-
ModuleManifestQuerySchema,
|
|
31
|
-
ModuleStateQuerySchema,
|
|
32
|
-
ModuleSubscribeQuerySchema,
|
|
33
|
-
ObjectResolverPriority
|
|
34
|
-
} from "@xyo-network/module-model";
|
|
35
|
-
import {
|
|
36
|
-
Account as Account2,
|
|
37
|
-
asSchema as asSchema2,
|
|
38
|
-
BoundWitnessBuilder,
|
|
39
|
-
ConfigSchema,
|
|
40
|
-
isAccountInstance,
|
|
41
|
-
isQueryBoundWitness,
|
|
42
|
-
PayloadBuilder as PayloadBuilder2,
|
|
43
|
-
QueryBoundWitnessBuilder,
|
|
44
|
-
QueryBoundWitnessWrapper as QueryBoundWitnessWrapper3,
|
|
45
|
-
QuerySchema
|
|
46
|
-
} from "@xyo-network/sdk-protocol";
|
|
47
|
-
import { Mutex } from "async-mutex";
|
|
48
|
-
import { LRUCache } from "lru-cache";
|
|
49
|
-
|
|
50
|
-
// src/determineAccount.ts
|
|
51
|
-
import {
|
|
52
|
-
assertEx,
|
|
53
|
-
isDefined,
|
|
54
|
-
isString,
|
|
55
|
-
isUndefined
|
|
56
|
-
} from "@ariestools/sdk";
|
|
57
|
-
import { Account } from "@xyo-network/sdk-protocol";
|
|
58
|
-
var isDetermineAccountFromAccountParams = (params) => {
|
|
59
|
-
assertEx(isUndefined(params.accountPath), () => "accountPath may not be provided when account is provided");
|
|
60
|
-
return isDefined(params.account);
|
|
61
|
-
};
|
|
62
|
-
var isDetermineAccountFromWalletParams = (params) => {
|
|
63
|
-
return isDefined(params.wallet);
|
|
64
|
-
};
|
|
65
|
-
async function determineAccount(params, allowRandomAccount = true) {
|
|
66
|
-
if (isDetermineAccountFromAccountParams(params)) {
|
|
67
|
-
if (params.account === "random") {
|
|
68
|
-
assertEx(allowRandomAccount, () => "Random address not allowed");
|
|
69
|
-
return await Account.random();
|
|
70
|
-
}
|
|
71
|
-
return params.account;
|
|
72
|
-
}
|
|
73
|
-
if (isDetermineAccountFromWalletParams(params)) {
|
|
74
|
-
return assertEx(
|
|
75
|
-
isString(params.accountPath) ? await params.wallet.derivePath(params.accountPath) : params.wallet,
|
|
76
|
-
() => "Failed to derive account from path"
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
console.warn("AbstractModule.determineAccount: No account or wallet provided - Creating Random account");
|
|
80
|
-
return await Account.random();
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// src/Error.ts
|
|
84
|
-
import { ModuleErrorSchema, PayloadBuilder } from "@xyo-network/sdk-protocol";
|
|
85
|
-
var ModuleErrorBuilder = class extends PayloadBuilder {
|
|
86
|
-
_details;
|
|
87
|
-
_message;
|
|
88
|
-
_name;
|
|
89
|
-
_query;
|
|
90
|
-
constructor() {
|
|
91
|
-
super({ schema: ModuleErrorSchema });
|
|
92
|
-
}
|
|
93
|
-
build() {
|
|
94
|
-
this.fields({
|
|
95
|
-
details: this._details,
|
|
96
|
-
message: this._message,
|
|
97
|
-
name: this._name,
|
|
98
|
-
query: this._query
|
|
99
|
-
});
|
|
100
|
-
return super.build();
|
|
101
|
-
}
|
|
102
|
-
details(details) {
|
|
103
|
-
this._details = details;
|
|
104
|
-
return this;
|
|
105
|
-
}
|
|
106
|
-
message(message) {
|
|
107
|
-
this._message = message;
|
|
108
|
-
return this;
|
|
109
|
-
}
|
|
110
|
-
name(name) {
|
|
111
|
-
this._name = name;
|
|
112
|
-
return this;
|
|
113
|
-
}
|
|
114
|
-
query(query) {
|
|
115
|
-
this._query = query;
|
|
116
|
-
return this;
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
// src/QueryValidator/ModuleConfigQueryValidator.ts
|
|
121
|
-
import { QueryBoundWitnessWrapper } from "@xyo-network/sdk-protocol";
|
|
122
|
-
import {
|
|
123
|
-
asSchema
|
|
124
|
-
} from "@xyo-network/sdk-protocol";
|
|
125
|
-
var delimiter = "";
|
|
126
|
-
var ModuleConfigQueryValidator = class {
|
|
127
|
-
allowed = {};
|
|
128
|
-
disallowed = {};
|
|
129
|
-
hasAllowedRules;
|
|
130
|
-
hasDisallowedRules;
|
|
131
|
-
hasRules;
|
|
132
|
-
constructor(config) {
|
|
133
|
-
if (config?.security?.allowed) {
|
|
134
|
-
for (const [schema, addresses] of Object.entries(config.security?.allowed)) {
|
|
135
|
-
const typedSchema = asSchema(schema, true);
|
|
136
|
-
this.allowed[typedSchema] = addresses.map(toAddressesString);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
if (config?.security?.disallowed) {
|
|
140
|
-
for (const [schema, addresses] of Object.entries(config.security?.disallowed)) {
|
|
141
|
-
const typedSchema = asSchema(schema, true);
|
|
142
|
-
this.disallowed[typedSchema] = addresses.map(toAddressesString);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
this.hasAllowedRules = Object.keys(this.allowed).length > 0;
|
|
146
|
-
this.hasDisallowedRules = Object.keys(this.disallowed).length > 0;
|
|
147
|
-
this.hasRules = this.hasAllowedRules || this.hasDisallowedRules;
|
|
148
|
-
}
|
|
149
|
-
queryable = async (query, payloads) => {
|
|
150
|
-
if (!this.hasRules) return true;
|
|
151
|
-
const addresses = query.addresses;
|
|
152
|
-
if (addresses.length === 0) return false;
|
|
153
|
-
const wrapper = QueryBoundWitnessWrapper.parseQuery(query, payloads);
|
|
154
|
-
const schema = (await wrapper.getQuery()).schema;
|
|
155
|
-
return this.queryAllowed(schema, addresses) && !this.queryDisallowed(schema, addresses);
|
|
156
|
-
};
|
|
157
|
-
queryAllowed = (schema, addresses) => {
|
|
158
|
-
if (!this.hasAllowedRules) return true;
|
|
159
|
-
if (addresses.length > 1) {
|
|
160
|
-
const signatories = toAddressesString(addresses);
|
|
161
|
-
const validCosigners = this.allowed?.[schema]?.includes(signatories);
|
|
162
|
-
if (validCosigners) return true;
|
|
163
|
-
}
|
|
164
|
-
return addresses.every((address) => this.allowed?.[schema]?.includes(address) || false);
|
|
165
|
-
};
|
|
166
|
-
queryDisallowed = (schema, addresses) => {
|
|
167
|
-
if (!this.hasDisallowedRules) return false;
|
|
168
|
-
return addresses.some((address) => this.disallowed?.[schema]?.includes(address));
|
|
169
|
-
};
|
|
170
|
-
};
|
|
171
|
-
var toAddressesString = (addresses) => {
|
|
172
|
-
return Array.isArray(addresses) ? addresses.toSorted().map((address) => address.toLowerCase()).join(delimiter) : addresses.toLowerCase();
|
|
173
|
-
};
|
|
174
|
-
|
|
175
|
-
// src/QueryValidator/SupportedQueryValidator.ts
|
|
176
|
-
import { QueryBoundWitnessWrapper as QueryBoundWitnessWrapper2 } from "@xyo-network/sdk-protocol";
|
|
177
|
-
var isQuerySupportedByModule = async (mod, query, payloads) => {
|
|
178
|
-
const wrapper = QueryBoundWitnessWrapper2.parseQuery(query, payloads);
|
|
179
|
-
const schema = (await wrapper.getQuery()).schema;
|
|
180
|
-
return mod.queries.includes(schema);
|
|
181
|
-
};
|
|
182
|
-
var SupportedQueryValidator = class {
|
|
183
|
-
mod;
|
|
184
|
-
constructor(mod) {
|
|
185
|
-
this.mod = mod;
|
|
186
|
-
}
|
|
187
|
-
queryable = (query, payloads) => {
|
|
188
|
-
return isQuerySupportedByModule(this.mod, query, payloads);
|
|
189
|
-
};
|
|
190
|
-
};
|
|
191
|
-
|
|
192
|
-
// src/AbstractModule.ts
|
|
193
|
-
var DefaultModuleQueries = [ModuleAddressQuerySchema, ModuleSubscribeQuerySchema, ModuleManifestQuerySchema, ModuleStateQuerySchema];
|
|
194
|
-
var AbstractModule = class _AbstractModule extends AbstractCreatable {
|
|
195
|
-
static allowRandomAccount = true;
|
|
196
|
-
static configSchemas = [ModuleConfigSchema];
|
|
197
|
-
static defaultConfigSchema = ModuleConfigSchema;
|
|
198
|
-
static defaultLogger = new ConsoleLogger(LogLevel.warn);
|
|
199
|
-
static enableLazyLoad = false;
|
|
200
|
-
static labels = {};
|
|
201
|
-
static uniqueName = globallyUnique("AbstractModule", _AbstractModule, "xyo");
|
|
202
|
-
static privateConstructorKey = Date.now().toString();
|
|
203
|
-
_account;
|
|
204
|
-
// cache manifest based on maxDepth
|
|
205
|
-
_cachedManifests = new LRUCache({ max: 10, ttl: 1e3 * 60 * 5 });
|
|
206
|
-
_globalReentrancyMutex;
|
|
207
|
-
_lastError;
|
|
208
|
-
_moduleConfigQueryValidator;
|
|
209
|
-
_supportedQueryValidator;
|
|
210
|
-
_busyCount = 0;
|
|
211
|
-
_logger = void 0;
|
|
212
|
-
get account() {
|
|
213
|
-
return assertEx2(this._account, () => "Missing account");
|
|
214
|
-
}
|
|
215
|
-
get additionalSigners() {
|
|
216
|
-
return this.params.additionalSigners ?? [];
|
|
217
|
-
}
|
|
218
|
-
get address() {
|
|
219
|
-
return this.account.address;
|
|
220
|
-
}
|
|
221
|
-
get allowAnonymous() {
|
|
222
|
-
return !!this.config.security?.allowAnonymous;
|
|
223
|
-
}
|
|
224
|
-
get allowNameResolution() {
|
|
225
|
-
return this.params.allowNameResolution ?? true;
|
|
226
|
-
}
|
|
227
|
-
get archiving() {
|
|
228
|
-
return this.config.archiving;
|
|
229
|
-
}
|
|
230
|
-
get archivist() {
|
|
231
|
-
return this.config.archivist;
|
|
232
|
-
}
|
|
233
|
-
get config() {
|
|
234
|
-
return { ...this.params.config, schema: this.params.config.schema ?? ModuleConfigSchema };
|
|
235
|
-
}
|
|
236
|
-
get dead() {
|
|
237
|
-
return this.status === "error";
|
|
238
|
-
}
|
|
239
|
-
get ephemeralQueryAccountEnabled() {
|
|
240
|
-
return !!this.params.ephemeralQueryAccountEnabled;
|
|
241
|
-
}
|
|
242
|
-
get globalReentrancyMutex() {
|
|
243
|
-
this._globalReentrancyMutex = this._globalReentrancyMutex ?? (this.reentrancy?.scope === "global" ? new Mutex() : void 0);
|
|
244
|
-
return this._globalReentrancyMutex;
|
|
245
|
-
}
|
|
246
|
-
get id() {
|
|
247
|
-
return this.modName ?? this.address;
|
|
248
|
-
}
|
|
249
|
-
get logger() {
|
|
250
|
-
if (isUndefined2(this._logger)) {
|
|
251
|
-
const logLevel = this.config.logLevel;
|
|
252
|
-
const newLogger = this._logger ?? (this.params?.logger ? new IdLogger(this.params.logger, () => `${this.constructor.name}[${this.id}]`) : null);
|
|
253
|
-
this._logger = isObject(newLogger) && isDefined2(logLevel) ? new LevelLogger(newLogger, logLevel) : newLogger;
|
|
254
|
-
}
|
|
255
|
-
return this._logger ?? void 0;
|
|
256
|
-
}
|
|
257
|
-
get modName() {
|
|
258
|
-
return this.config.name;
|
|
259
|
-
}
|
|
260
|
-
get priority() {
|
|
261
|
-
return ObjectResolverPriority.Normal;
|
|
262
|
-
}
|
|
263
|
-
get queries() {
|
|
264
|
-
return [...DefaultModuleQueries];
|
|
265
|
-
}
|
|
266
|
-
get reentrancy() {
|
|
267
|
-
return this.config.reentrancy;
|
|
268
|
-
}
|
|
269
|
-
get statusReporter() {
|
|
270
|
-
return this.params.statusReporter;
|
|
271
|
-
}
|
|
272
|
-
get timestamp() {
|
|
273
|
-
return this.config.timestamp ?? false;
|
|
274
|
-
}
|
|
275
|
-
get moduleConfigQueryValidator() {
|
|
276
|
-
return assertEx2(this._moduleConfigQueryValidator, () => "ModuleConfigQueryValidator not initialized");
|
|
277
|
-
}
|
|
278
|
-
get supportedQueryValidator() {
|
|
279
|
-
return assertEx2(this._supportedQueryValidator, () => "SupportedQueryValidator not initialized");
|
|
280
|
-
}
|
|
281
|
-
/* eslint-disable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-return */
|
|
282
|
-
static _getRootFunction(funcName) {
|
|
283
|
-
let anyThis = this;
|
|
284
|
-
while (anyThis.__proto__[funcName]) {
|
|
285
|
-
anyThis = anyThis.__proto__;
|
|
286
|
-
}
|
|
287
|
-
return anyThis[funcName];
|
|
288
|
-
}
|
|
289
|
-
static _noOverride(functionName) {
|
|
290
|
-
const thisFunc = this[functionName];
|
|
291
|
-
const rootFunc = this._getRootFunction(functionName);
|
|
292
|
-
assertEx2(thisFunc === rootFunc, () => `Override not allowed for [${functionName}] - override ${functionName}Handler instead`);
|
|
293
|
-
}
|
|
294
|
-
/* eslint-enable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-return */
|
|
295
|
-
static async createHandler(inInstance) {
|
|
296
|
-
const instance = await super.createHandler(inInstance);
|
|
297
|
-
if (instance instanceof _AbstractModule) {
|
|
298
|
-
if (this.configSchemas.length === 0) {
|
|
299
|
-
throw new Error(`No allowed config schemas for [${this.name}]`);
|
|
300
|
-
}
|
|
301
|
-
const schema = instance.config.schema ?? this.defaultConfigSchema;
|
|
302
|
-
const allowedSchemas = this.configSchemas;
|
|
303
|
-
assertEx2(this.isAllowedSchema(schema), () => `Bad Config Schema [Received ${schema}] [Expected ${JSON.stringify(allowedSchemas)}]`);
|
|
304
|
-
} else {
|
|
305
|
-
throw new TypeError(`Invalid instance type [${instance.constructor.name}] for [${this.name}]`);
|
|
306
|
-
}
|
|
307
|
-
return instance;
|
|
308
|
-
}
|
|
309
|
-
static async determineAccount(params) {
|
|
310
|
-
return await determineAccount(params, this.allowRandomAccount);
|
|
311
|
-
}
|
|
312
|
-
static factory(params) {
|
|
313
|
-
return ModuleFactory.withParams(this, params);
|
|
314
|
-
}
|
|
315
|
-
static isAllowedSchema(schema) {
|
|
316
|
-
return this.configSchemas.includes(schema);
|
|
317
|
-
}
|
|
318
|
-
static async paramsHandler(inParams = {}) {
|
|
319
|
-
const superParams = await super.paramsHandler(inParams);
|
|
320
|
-
const params = {
|
|
321
|
-
...superParams,
|
|
322
|
-
account: await this.determineAccount(superParams),
|
|
323
|
-
config: { schema: this.defaultConfigSchema, ...superParams.config },
|
|
324
|
-
logger: superParams.logger ?? this.defaultLogger
|
|
325
|
-
};
|
|
326
|
-
return params;
|
|
327
|
-
}
|
|
328
|
-
/* eslint-disable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-return */
|
|
329
|
-
_getRootFunction(funcName) {
|
|
330
|
-
let anyThis = this;
|
|
331
|
-
while (anyThis.__proto__[funcName]) {
|
|
332
|
-
anyThis = anyThis.__proto__;
|
|
333
|
-
}
|
|
334
|
-
return anyThis[funcName];
|
|
335
|
-
}
|
|
336
|
-
/* eslint-enable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-return */
|
|
337
|
-
async busy(closure) {
|
|
338
|
-
if (this._busyCount <= 0) {
|
|
339
|
-
this._busyCount = 0;
|
|
340
|
-
const args = { busy: true, mod: this };
|
|
341
|
-
await this.emit("moduleBusy", args);
|
|
342
|
-
}
|
|
343
|
-
this._busyCount++;
|
|
344
|
-
try {
|
|
345
|
-
return await closure();
|
|
346
|
-
} finally {
|
|
347
|
-
this._busyCount--;
|
|
348
|
-
if (this._busyCount <= 0) {
|
|
349
|
-
this._busyCount = 0;
|
|
350
|
-
const args = { busy: false, mod: this };
|
|
351
|
-
await this.emit("moduleBusy", args);
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
async createHandler() {
|
|
356
|
-
await super.createHandler();
|
|
357
|
-
assertEx2(this.name === void 0 || isModuleName(this.name), () => `Invalid module name: ${this.name}`);
|
|
358
|
-
if (this.params.account === "random") {
|
|
359
|
-
this._account = await Account2.random();
|
|
360
|
-
} else if (isAccountInstance(this.params.account)) {
|
|
361
|
-
this._account = this.params.account;
|
|
362
|
-
}
|
|
363
|
-
assertEx2(isAccountInstance(this._account), () => `Invalid account instance: ${JSON.stringify(this._account)}`);
|
|
364
|
-
this._supportedQueryValidator = new SupportedQueryValidator(this).queryable;
|
|
365
|
-
this._moduleConfigQueryValidator = new ModuleConfigQueryValidator(this.config).queryable;
|
|
366
|
-
if (!_AbstractModule.enableLazyLoad) {
|
|
367
|
-
setTimeout(() => forget(this.start()), 200);
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
emit(eventName, eventArgs) {
|
|
371
|
-
return super.emit(eventName, eventArgs);
|
|
372
|
-
}
|
|
373
|
-
isSupportedQuery(query, assert = false) {
|
|
374
|
-
if (!this.queries.includes(query)) {
|
|
375
|
-
if (assert !== false) {
|
|
376
|
-
assertEx2(false, () => `Query not supported [${isString2(assert) ? assert : query}] on [${this.modName}, ${this.address}] (queries list)`);
|
|
377
|
-
}
|
|
378
|
-
return false;
|
|
379
|
-
}
|
|
380
|
-
const supported = Array.isArray(this.config.allowedQueries) ? this.config.allowedQueries.includes(query) : true;
|
|
381
|
-
if (assert !== false) {
|
|
382
|
-
assertEx2(supported, () => `Query not supported [${isString2(assert) ? assert : query}] on [${this.modName}, ${this.address}] (config)`);
|
|
383
|
-
}
|
|
384
|
-
return supported;
|
|
385
|
-
}
|
|
386
|
-
previousHash() {
|
|
387
|
-
this._checkDead();
|
|
388
|
-
return this.account.previousHash;
|
|
389
|
-
}
|
|
390
|
-
async query(query, payloads, queryConfig) {
|
|
391
|
-
this._checkDead();
|
|
392
|
-
this._noOverride("query");
|
|
393
|
-
return await this.spanAsync("query", async () => {
|
|
394
|
-
const sourceQuery = assertEx2(isQueryBoundWitness(query) ? query : void 0, () => "Unable to parse query");
|
|
395
|
-
return await this.busy(async () => {
|
|
396
|
-
const resultPayloads = [];
|
|
397
|
-
const errorPayloads = [];
|
|
398
|
-
const queryAccount = this.ephemeralQueryAccountEnabled ? await Account2.random() : void 0;
|
|
399
|
-
try {
|
|
400
|
-
await this.startedAsync("throw");
|
|
401
|
-
if (!this.allowAnonymous && query.addresses.length === 0) {
|
|
402
|
-
throw new Error(`Anonymous Queries not allowed, but running anyway [${this.modName}], [${this.address}]`);
|
|
403
|
-
}
|
|
404
|
-
if (queryConfig?.allowedQueries) {
|
|
405
|
-
assertEx2(queryConfig?.allowedQueries.includes(sourceQuery.schema), () => `Query not allowed [${sourceQuery.schema}]`);
|
|
406
|
-
}
|
|
407
|
-
resultPayloads.push(...await this.queryHandler(sourceQuery, payloads, queryConfig));
|
|
408
|
-
} catch (ex) {
|
|
409
|
-
await handleErrorAsync(ex, async (err) => {
|
|
410
|
-
const error = err;
|
|
411
|
-
this._lastError = error;
|
|
412
|
-
errorPayloads.push(
|
|
413
|
-
new ModuleErrorBuilder().meta({ $sources: [await PayloadBuilder2.dataHash(sourceQuery)] }).name(this.modName ?? "<Unknown>").query(sourceQuery.schema).details(error.details).message(error.message).build()
|
|
414
|
-
);
|
|
415
|
-
});
|
|
416
|
-
}
|
|
417
|
-
if (this.timestamp) {
|
|
418
|
-
const timestamp = { schema: asSchema2("network.xyo.timestamp", true), timestamp: Date.now() };
|
|
419
|
-
resultPayloads.push(timestamp);
|
|
420
|
-
}
|
|
421
|
-
const result = await this.bindQueryResult(sourceQuery, resultPayloads, queryAccount ? [queryAccount] : [], errorPayloads);
|
|
422
|
-
const args = {
|
|
423
|
-
mod: this,
|
|
424
|
-
payloads,
|
|
425
|
-
query: sourceQuery,
|
|
426
|
-
result
|
|
427
|
-
};
|
|
428
|
-
await this.emit("moduleQueried", args);
|
|
429
|
-
return result;
|
|
430
|
-
});
|
|
431
|
-
}, { timeBudgetLimit: 200 });
|
|
432
|
-
}
|
|
433
|
-
async queryable(query, payloads, queryConfig) {
|
|
434
|
-
if (this.dead) {
|
|
435
|
-
return false;
|
|
436
|
-
}
|
|
437
|
-
if (!this.started("warn")) return false;
|
|
438
|
-
const configValidator = queryConfig ? new ModuleConfigQueryValidator(Object.assign({}, this.config, queryConfig)).queryable : this.moduleConfigQueryValidator;
|
|
439
|
-
const validators = [this.supportedQueryValidator, configValidator];
|
|
440
|
-
const results = await Promise.all(validators.map((validator) => validator(query, payloads)));
|
|
441
|
-
for (const result of results) {
|
|
442
|
-
if (!result) {
|
|
443
|
-
return false;
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
return true;
|
|
447
|
-
}
|
|
448
|
-
_checkDead() {
|
|
449
|
-
if (this.dead) {
|
|
450
|
-
throw new DeadModuleError(this.id, this._lastError);
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
async archivistInstance(required = false) {
|
|
454
|
-
const archivist = this.archivist;
|
|
455
|
-
if (isUndefined2(archivist)) {
|
|
456
|
-
if (required) {
|
|
457
|
-
throw new Error("No archivist specified");
|
|
458
|
-
}
|
|
459
|
-
return void 0;
|
|
460
|
-
}
|
|
461
|
-
const resolved = await this.upResolver.resolve(archivist) ?? await this.downResolver.resolve(archivist);
|
|
462
|
-
if (required) {
|
|
463
|
-
assertEx2(resolved, () => `Unable to resolve archivist [${archivist}]`);
|
|
464
|
-
}
|
|
465
|
-
return resolved ? asArchivistInstance(resolved, () => `Specified archivist is not an Archivist [${archivist}]`) : void 0;
|
|
466
|
-
}
|
|
467
|
-
bindHashes(hashes, schema, account) {
|
|
468
|
-
return new PromiseEx((resolve) => {
|
|
469
|
-
const result = this.bindHashesInternal(hashes, schema, account);
|
|
470
|
-
resolve?.(result);
|
|
471
|
-
return result;
|
|
472
|
-
}, account);
|
|
473
|
-
}
|
|
474
|
-
async bindHashesInternal(hashes, schema, account = this.account) {
|
|
475
|
-
const builder = new BoundWitnessBuilder().hashes(hashes, schema).signer(account);
|
|
476
|
-
const result = (await builder.build())[0];
|
|
477
|
-
this.logger?.debug(`result: ${JSON.stringify(result, null, 2)}`);
|
|
478
|
-
return result;
|
|
479
|
-
}
|
|
480
|
-
bindQuery(query, payloads, account, additionalSigners) {
|
|
481
|
-
return new PromiseEx(async (resolve) => {
|
|
482
|
-
const result = await this.bindQueryInternal(query, payloads, account, additionalSigners);
|
|
483
|
-
resolve?.(result);
|
|
484
|
-
return result;
|
|
485
|
-
}, account);
|
|
486
|
-
}
|
|
487
|
-
async bindQueryInternal(query, payloads, account = this.account, additionalSigners = []) {
|
|
488
|
-
const accounts = [account, ...additionalSigners].filter(exists);
|
|
489
|
-
const builder = new QueryBoundWitnessBuilder().payloads(payloads).signers(accounts).query(query);
|
|
490
|
-
const [bw, payloadsOut, errors] = await builder.build();
|
|
491
|
-
return [bw, [...payloadsOut], errors];
|
|
492
|
-
}
|
|
493
|
-
async bindQueryResult(query, payloads, additionalWitnesses = [], errors) {
|
|
494
|
-
const queryDataHash = await PayloadBuilder2.dataHash(query);
|
|
495
|
-
const builder = new BoundWitnessBuilder().payloads(payloads).errors(errors).sourceQuery(queryDataHash);
|
|
496
|
-
const witnesses = [this.account, ...additionalWitnesses].filter(exists);
|
|
497
|
-
builder.signers(witnesses);
|
|
498
|
-
const result = [
|
|
499
|
-
PayloadBuilder2.omitPrivateStorageMeta((await builder.build())[0]),
|
|
500
|
-
PayloadBuilder2.omitPrivateStorageMeta(payloads),
|
|
501
|
-
PayloadBuilder2.omitPrivateStorageMeta(errors ?? [])
|
|
502
|
-
];
|
|
503
|
-
if (this.archiving && this.isAllowedArchivingQuery(query.schema)) {
|
|
504
|
-
forget(this.storeToArchivists(result.flat()));
|
|
505
|
-
}
|
|
506
|
-
return result;
|
|
507
|
-
}
|
|
508
|
-
generateConfigAndAddress(_maxDepth) {
|
|
509
|
-
const config = this.config;
|
|
510
|
-
const address = { schema: AddressSchema, address: this.address };
|
|
511
|
-
const queries = this.queries.map((query) => {
|
|
512
|
-
return { schema: QuerySchema, query };
|
|
513
|
-
});
|
|
514
|
-
const configSchema = {
|
|
515
|
-
config: config.schema,
|
|
516
|
-
schema: ConfigSchema
|
|
517
|
-
};
|
|
518
|
-
return [config, configSchema, address, ...queries].filter(exists);
|
|
519
|
-
}
|
|
520
|
-
async generateDescribe() {
|
|
521
|
-
const description = {
|
|
522
|
-
address: this.address,
|
|
523
|
-
name: this.modName ?? `Unnamed ${this.constructor.name}`,
|
|
524
|
-
queries: this.queries,
|
|
525
|
-
schema: ModuleDescriptionSchema
|
|
526
|
-
};
|
|
527
|
-
const discover = await this.generateConfigAndAddress();
|
|
528
|
-
description.children = (discover?.map((payload) => {
|
|
529
|
-
const address = payload.schema === AddressSchema ? payload.address : void 0;
|
|
530
|
-
return address == this.address ? void 0 : address;
|
|
531
|
-
}) ?? []).filter(exists);
|
|
532
|
-
return description;
|
|
533
|
-
}
|
|
534
|
-
/** @deprecated use archivistInstance() instead */
|
|
535
|
-
async getArchivist() {
|
|
536
|
-
return await this.archivistInstance();
|
|
537
|
-
}
|
|
538
|
-
isAllowedArchivingQuery(schema) {
|
|
539
|
-
const queries = this.archiving?.queries;
|
|
540
|
-
if (queries) {
|
|
541
|
-
return queries.includes(schema);
|
|
542
|
-
}
|
|
543
|
-
return true;
|
|
544
|
-
}
|
|
545
|
-
manifestHandler(_maxDepth = 1, _ignoreAddresses = []) {
|
|
546
|
-
throw new Error("Not supported");
|
|
547
|
-
}
|
|
548
|
-
moduleAddressHandler() {
|
|
549
|
-
const address = this.address;
|
|
550
|
-
const name = this.modName;
|
|
551
|
-
const previousHash = this.account.previousHash;
|
|
552
|
-
const moduleAccount = isDefined2(name) ? {
|
|
553
|
-
address,
|
|
554
|
-
name,
|
|
555
|
-
schema: AddressSchema
|
|
556
|
-
} : { address, schema: AddressSchema };
|
|
557
|
-
const moduleAccountPreviousHash = isDefined2(previousHash) ? {
|
|
558
|
-
address,
|
|
559
|
-
previousHash,
|
|
560
|
-
schema: AddressPreviousHashSchema
|
|
561
|
-
} : { address, schema: AddressSchema };
|
|
562
|
-
return [moduleAccount, moduleAccountPreviousHash];
|
|
563
|
-
}
|
|
564
|
-
async queryHandler(query, payloads, queryConfig) {
|
|
565
|
-
await this.startedAsync("throw");
|
|
566
|
-
const wrapper = QueryBoundWitnessWrapper3.parseQuery(query, payloads);
|
|
567
|
-
const queryPayload = await wrapper.getQuery();
|
|
568
|
-
assertEx2(await this.queryable(query, payloads, queryConfig));
|
|
569
|
-
const resultPayloads = [];
|
|
570
|
-
switch (queryPayload.schema) {
|
|
571
|
-
case ModuleManifestQuerySchema: {
|
|
572
|
-
const typedQueryPayload = queryPayload;
|
|
573
|
-
resultPayloads.push(await this.manifestHandler(typedQueryPayload.maxDepth));
|
|
574
|
-
break;
|
|
575
|
-
}
|
|
576
|
-
case ModuleAddressQuerySchema: {
|
|
577
|
-
resultPayloads.push(...await this.moduleAddressHandler());
|
|
578
|
-
break;
|
|
579
|
-
}
|
|
580
|
-
case ModuleStateQuerySchema: {
|
|
581
|
-
resultPayloads.push(...await this.stateHandler());
|
|
582
|
-
break;
|
|
583
|
-
}
|
|
584
|
-
case ModuleSubscribeQuerySchema: {
|
|
585
|
-
this.subscribeHandler();
|
|
586
|
-
break;
|
|
587
|
-
}
|
|
588
|
-
default: {
|
|
589
|
-
throw new Error(`Unsupported Query [${queryPayload.schema}]`);
|
|
590
|
-
}
|
|
591
|
-
}
|
|
592
|
-
return PayloadBuilder2.omitPrivateStorageMeta(resultPayloads);
|
|
593
|
-
}
|
|
594
|
-
async startHandler() {
|
|
595
|
-
this.validateConfig();
|
|
596
|
-
await super.startHandler();
|
|
597
|
-
}
|
|
598
|
-
async stateHandler() {
|
|
599
|
-
return [await this.manifestHandler(), ...await this.generateConfigAndAddress(), await this.generateDescribe()];
|
|
600
|
-
}
|
|
601
|
-
async stopHandler() {
|
|
602
|
-
await super.stopHandler();
|
|
603
|
-
this._startPromise = void 0;
|
|
604
|
-
}
|
|
605
|
-
subscribeHandler() {
|
|
606
|
-
return;
|
|
607
|
-
}
|
|
608
|
-
validateConfig(config, parents = []) {
|
|
609
|
-
return Object.entries(config ?? this.config ?? {}).reduce((valid, [key, value]) => {
|
|
610
|
-
switch (typeof value) {
|
|
611
|
-
case "function": {
|
|
612
|
-
this.logger?.warn(`Fields of type function not allowed in config [${parents?.join(".")}.${key}]`);
|
|
613
|
-
return false;
|
|
614
|
-
}
|
|
615
|
-
case "object": {
|
|
616
|
-
if (Array.isArray(value)) {
|
|
617
|
-
return value.reduce(
|
|
618
|
-
(valid2, value2) => (
|
|
619
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
620
|
-
this.validateConfig(value2, [...parents, key]) && valid2
|
|
621
|
-
),
|
|
622
|
-
true
|
|
623
|
-
) && valid;
|
|
624
|
-
}
|
|
625
|
-
if (!isSerializable(value)) {
|
|
626
|
-
this.logger?.warn(`Fields that are not serializable to JSON are not allowed in config [${parents?.join(".")}.${key}]`);
|
|
627
|
-
return false;
|
|
628
|
-
}
|
|
629
|
-
return value ? this.validateConfig(value, [...parents, key]) && valid : true;
|
|
630
|
-
}
|
|
631
|
-
default: {
|
|
632
|
-
return valid;
|
|
633
|
-
}
|
|
634
|
-
}
|
|
635
|
-
}, true);
|
|
636
|
-
}
|
|
637
|
-
};
|
|
638
|
-
|
|
639
|
-
// src/AbstractModuleInstance.ts
|
|
640
|
-
import {
|
|
641
|
-
exists as exists2,
|
|
642
|
-
globallyUnique as globallyUnique2,
|
|
643
|
-
isDefined as isDefined3
|
|
644
|
-
} from "@ariestools/sdk";
|
|
645
|
-
import { asArchivistInstance as asArchivistInstance2 } from "@xyo-network/archivist-model";
|
|
646
|
-
import {
|
|
647
|
-
duplicateModules,
|
|
648
|
-
ModuleManifestQuerySchema as ModuleManifestQuerySchema2,
|
|
649
|
-
ModuleStateQuerySchema as ModuleStateQuerySchema2
|
|
650
|
-
} from "@xyo-network/module-model";
|
|
651
|
-
import {
|
|
652
|
-
CompositeModuleResolver,
|
|
653
|
-
resolveAll,
|
|
654
|
-
resolveAllDown,
|
|
655
|
-
resolveAllUp,
|
|
656
|
-
ResolveHelper,
|
|
657
|
-
resolvePathToInstance
|
|
658
|
-
} from "@xyo-network/module-resolver";
|
|
659
|
-
import { asNodeInstance } from "@xyo-network/node-model";
|
|
660
|
-
import { ModuleManifestPayloadSchema } from "@xyo-network/sdk-protocol";
|
|
661
|
-
function filterIdentity(mod, identityFunc) {
|
|
662
|
-
if (Array.isArray(mod)) {
|
|
663
|
-
if (identityFunc) {
|
|
664
|
-
return mod.map((m) => identityFunc(m)).filter(exists2);
|
|
665
|
-
}
|
|
666
|
-
return mod;
|
|
667
|
-
}
|
|
668
|
-
return (mod ? identityFunc ? identityFunc(mod) : true : false) ? mod : void 0;
|
|
669
|
-
}
|
|
670
|
-
var AbstractModuleInstance = class _AbstractModuleInstance extends AbstractModule {
|
|
671
|
-
static uniqueName = globallyUnique2("AbstractModuleInstance", _AbstractModuleInstance, "xyo");
|
|
672
|
-
// switches between old and new resolution system
|
|
673
|
-
static useNewResolver = false;
|
|
674
|
-
_downResolver;
|
|
675
|
-
_parents = [];
|
|
676
|
-
_privateResolver;
|
|
677
|
-
_upResolver;
|
|
678
|
-
get downResolver() {
|
|
679
|
-
this._downResolver = this._downResolver ?? new CompositeModuleResolver({
|
|
680
|
-
allowNameResolution: this.allowNameResolution,
|
|
681
|
-
moduleIdentifierTransformers: this.params.moduleIdentifierTransformers,
|
|
682
|
-
root: this
|
|
683
|
-
});
|
|
684
|
-
return this._downResolver;
|
|
685
|
-
}
|
|
686
|
-
get modName() {
|
|
687
|
-
return super.modName;
|
|
688
|
-
}
|
|
689
|
-
get moduleIdentifierTransformers() {
|
|
690
|
-
return this.params.moduleIdentifierTransformers ?? ResolveHelper.transformers;
|
|
691
|
-
}
|
|
692
|
-
get privateResolver() {
|
|
693
|
-
this._privateResolver = this._privateResolver ?? new CompositeModuleResolver({
|
|
694
|
-
allowNameResolution: this.allowNameResolution,
|
|
695
|
-
moduleIdentifierTransformers: this.params.moduleIdentifierTransformers,
|
|
696
|
-
root: this
|
|
697
|
-
});
|
|
698
|
-
return this._privateResolver;
|
|
699
|
-
}
|
|
700
|
-
get root() {
|
|
701
|
-
return this;
|
|
702
|
-
}
|
|
703
|
-
get timeBudget() {
|
|
704
|
-
return this.config.timeBudget;
|
|
705
|
-
}
|
|
706
|
-
get upResolver() {
|
|
707
|
-
this._upResolver = this._upResolver ?? new CompositeModuleResolver({
|
|
708
|
-
allowNameResolution: this.allowNameResolution,
|
|
709
|
-
moduleIdentifierTransformers: this.params.moduleIdentifierTransformers,
|
|
710
|
-
root: this
|
|
711
|
-
});
|
|
712
|
-
return this._upResolver;
|
|
713
|
-
}
|
|
714
|
-
addParent(mod) {
|
|
715
|
-
const hasExistingEntry = this._parents.some((parent) => parent.address === mod.address);
|
|
716
|
-
if (!hasExistingEntry) {
|
|
717
|
-
this._parents.push(asNodeInstance(mod, "Only NodeInstances can be parents", { required: true }));
|
|
718
|
-
}
|
|
719
|
-
}
|
|
720
|
-
async certifyParents() {
|
|
721
|
-
const parents = await this.parents();
|
|
722
|
-
return (await Promise.all(
|
|
723
|
-
parents.map(async (parent) => {
|
|
724
|
-
const [bw, payloads, errors] = await parent.certifyQuery(this.address);
|
|
725
|
-
return errors.length === 0 ? [bw, ...payloads] : [];
|
|
726
|
-
})
|
|
727
|
-
)).flat();
|
|
728
|
-
}
|
|
729
|
-
async createHandler() {
|
|
730
|
-
await super.createHandler();
|
|
731
|
-
const addToResolvers = this.params.addToResolvers ?? true;
|
|
732
|
-
if (addToResolvers) {
|
|
733
|
-
this.upResolver.add(this);
|
|
734
|
-
this.downResolver.add(this);
|
|
735
|
-
}
|
|
736
|
-
}
|
|
737
|
-
manifest(maxDepth) {
|
|
738
|
-
this._checkDead();
|
|
739
|
-
return this.busy(async () => {
|
|
740
|
-
return await this.manifestHandler(maxDepth);
|
|
741
|
-
});
|
|
742
|
-
}
|
|
743
|
-
async manifestQuery(account, maxDepth) {
|
|
744
|
-
const queryPayload = { schema: ModuleManifestQuerySchema2, ...maxDepth === void 0 ? {} : { maxDepth } };
|
|
745
|
-
return await this.sendQueryRaw(queryPayload, void 0, account);
|
|
746
|
-
}
|
|
747
|
-
moduleAddress() {
|
|
748
|
-
this._checkDead();
|
|
749
|
-
return this.busy(async () => {
|
|
750
|
-
return await this.moduleAddressHandler();
|
|
751
|
-
});
|
|
752
|
-
}
|
|
753
|
-
parents() {
|
|
754
|
-
return this._parents;
|
|
755
|
-
}
|
|
756
|
-
privateChildren() {
|
|
757
|
-
return [...this.params.privateChildren ?? []];
|
|
758
|
-
}
|
|
759
|
-
publicChildren() {
|
|
760
|
-
return [...this.params.publicChildren ?? []];
|
|
761
|
-
}
|
|
762
|
-
removeParent(address) {
|
|
763
|
-
this._parents = this._parents.filter((item) => item.address !== address);
|
|
764
|
-
}
|
|
765
|
-
async resolve(id = "*", options = {}) {
|
|
766
|
-
if (_AbstractModuleInstance.useNewResolver) {
|
|
767
|
-
if (id === "*") {
|
|
768
|
-
const { maxDepth = 10, direction } = options;
|
|
769
|
-
if (direction === "down") {
|
|
770
|
-
return filterIdentity(await resolveAllDown(this, maxDepth) ?? [], options.identity);
|
|
771
|
-
}
|
|
772
|
-
if (direction === "up") {
|
|
773
|
-
return filterIdentity(await resolveAllUp(this, maxDepth) ?? [], options.identity);
|
|
774
|
-
}
|
|
775
|
-
return filterIdentity(await resolveAll(this, maxDepth) ?? [], options.identity);
|
|
776
|
-
} else if (typeof id === "string") {
|
|
777
|
-
return filterIdentity(await resolvePathToInstance(this, id, true), options.identity);
|
|
778
|
-
} else {
|
|
779
|
-
throw new TypeError("Invalid id type");
|
|
780
|
-
}
|
|
781
|
-
} else {
|
|
782
|
-
const config = {
|
|
783
|
-
address: this.address,
|
|
784
|
-
dead: this.dead,
|
|
785
|
-
downResolver: this.downResolver,
|
|
786
|
-
logger: this.logger,
|
|
787
|
-
mod: this,
|
|
788
|
-
transformers: this.moduleIdentifierTransformers,
|
|
789
|
-
upResolver: this.upResolver
|
|
790
|
-
};
|
|
791
|
-
if (id === "*") {
|
|
792
|
-
return filterIdentity(await ResolveHelper.resolve(config, "*", options) ?? [], options.identity);
|
|
793
|
-
}
|
|
794
|
-
return filterIdentity(await ResolveHelper.resolve(config, id, options), options.identity);
|
|
795
|
-
}
|
|
796
|
-
}
|
|
797
|
-
resolveIdentifier(id, options) {
|
|
798
|
-
const { direction = "all" } = options ?? {};
|
|
799
|
-
switch (direction) {
|
|
800
|
-
case "down": {
|
|
801
|
-
return this.downResolver.resolveIdentifier(id, options);
|
|
802
|
-
}
|
|
803
|
-
default: {
|
|
804
|
-
const mutatedOptions = { ...options, direction: "all" };
|
|
805
|
-
return this.upResolver.resolveIdentifier(id, mutatedOptions);
|
|
806
|
-
}
|
|
807
|
-
}
|
|
808
|
-
}
|
|
809
|
-
async resolvePrivate(id = "*", options = {}) {
|
|
810
|
-
return await this.privateResolver.resolve(id, options) ?? await this.upResolver.resolve(id, options) ?? await this.downResolver.resolve(id, options);
|
|
811
|
-
}
|
|
812
|
-
async siblings() {
|
|
813
|
-
return (await Promise.all((await this.parents()).map((parent) => parent.publicChildren()))).flat().filter(duplicateModules);
|
|
814
|
-
}
|
|
815
|
-
state() {
|
|
816
|
-
this._checkDead();
|
|
817
|
-
return this.busy(async () => {
|
|
818
|
-
return await this.stateHandler();
|
|
819
|
-
});
|
|
820
|
-
}
|
|
821
|
-
async stateQuery(account) {
|
|
822
|
-
const queryPayload = { schema: ModuleStateQuerySchema2 };
|
|
823
|
-
return await this.sendQueryRaw(queryPayload, void 0, account);
|
|
824
|
-
}
|
|
825
|
-
subscribe(_queryAccount) {
|
|
826
|
-
this._checkDead();
|
|
827
|
-
return this.subscribeHandler();
|
|
828
|
-
}
|
|
829
|
-
async manifestHandler(maxDepth = 1, _ignoreAddresses = []) {
|
|
830
|
-
const cachedResult = this._cachedManifests.get(maxDepth);
|
|
831
|
-
if (cachedResult) {
|
|
832
|
-
return cachedResult;
|
|
833
|
-
}
|
|
834
|
-
const modName = this.modName ?? "<Anonymous>";
|
|
835
|
-
const children = await this.publicChildren();
|
|
836
|
-
const childAddressToName = {};
|
|
837
|
-
for (const child of children) {
|
|
838
|
-
if (child.address !== this.address) {
|
|
839
|
-
childAddressToName[child.address] = child.modName ?? null;
|
|
840
|
-
}
|
|
841
|
-
}
|
|
842
|
-
const result = {
|
|
843
|
-
config: { name: modName, ...this.config },
|
|
844
|
-
name: modName,
|
|
845
|
-
schema: ModuleManifestPayloadSchema,
|
|
846
|
-
status: { address: this.address, children: childAddressToName }
|
|
847
|
-
};
|
|
848
|
-
this._cachedManifests.set(maxDepth, result);
|
|
849
|
-
return result;
|
|
850
|
-
}
|
|
851
|
-
async resolveArchivingArchivists() {
|
|
852
|
-
const archivists = this.archiving?.archivists;
|
|
853
|
-
if (!archivists) return [];
|
|
854
|
-
const resolved = await Promise.all(archivists.map((archivist) => this.resolve(archivist)));
|
|
855
|
-
return resolved.map((mod) => asArchivistInstance2(mod)).filter(exists2);
|
|
856
|
-
}
|
|
857
|
-
async sendQuery(queryPayload, payloads, account) {
|
|
858
|
-
const queryResults = await this.sendQueryRaw(queryPayload, payloads, account);
|
|
859
|
-
const [, resultPayloads, errors] = queryResults;
|
|
860
|
-
if (isDefined3(errors) && errors.length > 0) {
|
|
861
|
-
throw new Error(JSON.stringify(errors[0]));
|
|
862
|
-
}
|
|
863
|
-
return resultPayloads;
|
|
864
|
-
}
|
|
865
|
-
async sendQueryRaw(queryPayload, payloads, account) {
|
|
866
|
-
const query = await this.bindQuery(queryPayload, payloads, account, this.additionalSigners);
|
|
867
|
-
return await this.query(query[0], query[1]);
|
|
868
|
-
}
|
|
869
|
-
startHandler() {
|
|
870
|
-
this._checkDead();
|
|
871
|
-
return this.busy(async () => {
|
|
872
|
-
if (this.status === "started" || this.status === "creating") {
|
|
873
|
-
return;
|
|
874
|
-
}
|
|
875
|
-
await super.startHandler();
|
|
876
|
-
});
|
|
877
|
-
}
|
|
878
|
-
async storeToArchivists(payloads) {
|
|
879
|
-
try {
|
|
880
|
-
const archivists = await this.resolveArchivingArchivists();
|
|
881
|
-
const results = await Promise.all(
|
|
882
|
-
// eslint-disable-next-line @typescript-eslint/await-thenable
|
|
883
|
-
archivists.map((archivist) => {
|
|
884
|
-
return archivist.insert?.(payloads);
|
|
885
|
-
})
|
|
886
|
-
);
|
|
887
|
-
return results.map(([bw]) => bw);
|
|
888
|
-
} catch (ex) {
|
|
889
|
-
const error = ex;
|
|
890
|
-
this.logger?.error(`Error storing to archivists: ${error.message}`);
|
|
891
|
-
return [];
|
|
892
|
-
}
|
|
893
|
-
}
|
|
894
|
-
};
|
|
895
|
-
|
|
896
|
-
// src/LoggerModuleStatusReporter.ts
|
|
897
|
-
var LoggerModuleStatusReporter = class {
|
|
898
|
-
logger;
|
|
899
|
-
statusMap = {};
|
|
900
|
-
constructor(logger) {
|
|
901
|
-
this.logger = logger;
|
|
902
|
-
}
|
|
903
|
-
report(name, status, progress) {
|
|
904
|
-
this.statusMap[name] = status;
|
|
905
|
-
const starting = Object.entries(this.statusMap).map(([, value]) => value === "starting" ? 1 : 0).reduce((a, b) => a + b, 0);
|
|
906
|
-
const started = Object.entries(this.statusMap).map(([, value]) => value === "started" ? 1 : 0).reduce((a, b) => a + b, 0);
|
|
907
|
-
this.logger.log(`${started}/${starting + started} ${name} status: ${status}`, { progress });
|
|
908
|
-
}
|
|
909
|
-
};
|
|
910
|
-
export {
|
|
911
|
-
AbstractModule,
|
|
912
|
-
AbstractModuleInstance,
|
|
913
|
-
DefaultModuleQueries,
|
|
914
|
-
LoggerModuleStatusReporter,
|
|
915
|
-
ModuleConfigQueryValidator,
|
|
916
|
-
ModuleErrorBuilder,
|
|
917
|
-
SupportedQueryValidator,
|
|
918
|
-
isQuerySupportedByModule
|
|
919
|
-
};
|
|
1
|
+
// src/index.ts
|
|
2
|
+
export * from "@xyo-network/sdk/module-abstract";
|
|
920
3
|
//# sourceMappingURL=index.mjs.map
|