@xyo-network/bridge-http 3.6.8 → 3.6.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/browser/HttpBridgeConfig.d.ts +2 -2
- package/dist/browser/HttpBridgeConfig.d.ts.map +1 -1
- package/dist/browser/HttpBridgeFull.d.ts +1 -1
- package/dist/browser/index-browser.mjs +81 -111
- package/dist/browser/index-browser.mjs.map +1 -1
- package/dist/neutral/HttpBridgeConfig.d.ts +2 -2
- package/dist/neutral/HttpBridgeConfig.d.ts.map +1 -1
- package/dist/neutral/HttpBridgeFull.d.ts +1 -1
- package/dist/neutral/index-browser.mjs +81 -111
- package/dist/neutral/index-browser.mjs.map +1 -1
- package/dist/node/HttpBridgeConfig.d.ts +2 -2
- package/dist/node/HttpBridgeConfig.d.ts.map +1 -1
- package/dist/node/HttpBridgeFull.d.ts +1 -1
- package/dist/node/index.mjs +113 -148
- package/dist/node/index.mjs.map +1 -1
- package/package.json +31 -31
- package/src/HttpBridgeBase.ts +15 -15
- package/src/HttpBridgeConfig.ts +2 -2
package/dist/node/index.mjs
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
|
-
var
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
|
+
var __reflectGet = Reflect.get;
|
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
7
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
8
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
9
|
+
if (decorator = decorators[i])
|
|
10
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
11
|
+
if (kind && result) __defProp(target, key, result);
|
|
12
|
+
return result;
|
|
13
|
+
};
|
|
14
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
15
|
+
var __superGet = (cls, obj, key) => __reflectGet(__getProtoOf(cls), key, obj);
|
|
3
16
|
|
|
4
17
|
// src/HttpBridgeConfig.ts
|
|
5
18
|
var HttpBridgeConfigSchema = "network.xyo.bridge.http.config";
|
|
@@ -8,9 +21,20 @@ var HttpBridgeConfigSchema = "network.xyo.bridge.http.config";
|
|
|
8
21
|
import { assertEx as assertEx4 } from "@xylabs/assert";
|
|
9
22
|
import { exists as exists3 } from "@xylabs/exists";
|
|
10
23
|
import { toJsonString as toJsonString2 } from "@xylabs/object";
|
|
11
|
-
import {
|
|
24
|
+
import {
|
|
25
|
+
asyncHandler,
|
|
26
|
+
customPoweredByHeader,
|
|
27
|
+
disableCaseSensitiveRouting,
|
|
28
|
+
disableExpressDefaultPoweredByHeader,
|
|
29
|
+
jsonBodyParser,
|
|
30
|
+
responseProfiler,
|
|
31
|
+
useRequestCounters
|
|
32
|
+
} from "@xylabs/sdk-api-express-ecs";
|
|
12
33
|
import { isQueryBoundWitness } from "@xyo-network/boundwitness-model";
|
|
13
|
-
import {
|
|
34
|
+
import {
|
|
35
|
+
creatableModule as creatableModule2,
|
|
36
|
+
resolveAddressToInstanceUp
|
|
37
|
+
} from "@xyo-network/module-model";
|
|
14
38
|
import express from "express";
|
|
15
39
|
import { StatusCodes } from "http-status-codes";
|
|
16
40
|
|
|
@@ -21,10 +45,17 @@ import { exists as exists2 } from "@xylabs/exists";
|
|
|
21
45
|
import { forget as forget2 } from "@xylabs/forget";
|
|
22
46
|
import { toJsonString } from "@xylabs/object";
|
|
23
47
|
import { AbstractBridge } from "@xyo-network/bridge-abstract";
|
|
24
|
-
import {
|
|
25
|
-
|
|
48
|
+
import {
|
|
49
|
+
NodeManifestPayloadSchema
|
|
50
|
+
} from "@xyo-network/manifest-model";
|
|
51
|
+
import {
|
|
52
|
+
creatableModule,
|
|
53
|
+
ModuleStateQuerySchema
|
|
54
|
+
} from "@xyo-network/module-model";
|
|
26
55
|
import { asAttachableNodeInstance } from "@xyo-network/node-model";
|
|
27
|
-
import {
|
|
56
|
+
import {
|
|
57
|
+
isPayloadOfSchemaType
|
|
58
|
+
} from "@xyo-network/payload-model";
|
|
28
59
|
import { Mutex as Mutex2, Semaphore } from "async-mutex";
|
|
29
60
|
import { LRUCache as LRUCache2 } from "lru-cache";
|
|
30
61
|
|
|
@@ -34,7 +65,12 @@ import { isAddress as isAddress2 } from "@xylabs/hex";
|
|
|
34
65
|
import { Account } from "@xyo-network/account";
|
|
35
66
|
import { AbstractBridgeModuleResolver, wrapModuleWithType } from "@xyo-network/bridge-abstract";
|
|
36
67
|
import { ConfigSchema } from "@xyo-network/config-payload-plugin";
|
|
37
|
-
import {
|
|
68
|
+
import {
|
|
69
|
+
asModuleInstance,
|
|
70
|
+
isModuleInstance,
|
|
71
|
+
ModuleConfigSchema,
|
|
72
|
+
ResolveHelper as ResolveHelper2
|
|
73
|
+
} from "@xyo-network/module-model";
|
|
38
74
|
import { Mutex } from "async-mutex";
|
|
39
75
|
import { LRUCache } from "lru-cache";
|
|
40
76
|
|
|
@@ -46,9 +82,6 @@ import { isAddress } from "@xylabs/hex";
|
|
|
46
82
|
import { AbstractModuleProxy } from "@xyo-network/bridge-abstract";
|
|
47
83
|
import { ResolveHelper } from "@xyo-network/module-model";
|
|
48
84
|
var HttpModuleProxy = class _HttpModuleProxy extends AbstractModuleProxy {
|
|
49
|
-
static {
|
|
50
|
-
__name(this, "HttpModuleProxy");
|
|
51
|
-
}
|
|
52
85
|
static createCount = 0;
|
|
53
86
|
constructor(params) {
|
|
54
87
|
_HttpModuleProxy.createCount = _HttpModuleProxy.createCount + 1;
|
|
@@ -59,10 +92,7 @@ var HttpModuleProxy = class _HttpModuleProxy extends AbstractModuleProxy {
|
|
|
59
92
|
}
|
|
60
93
|
async proxyQueryHandler(query, payloads = []) {
|
|
61
94
|
if (this.archiving && this.isAllowedArchivingQuery(query.schema)) {
|
|
62
|
-
forget(this.storeToArchivists([
|
|
63
|
-
query,
|
|
64
|
-
...payloads ?? []
|
|
65
|
-
]));
|
|
95
|
+
forget(this.storeToArchivists([query, ...payloads ?? []]));
|
|
66
96
|
}
|
|
67
97
|
const result = await this.params.querySender.sendBridgeQuery(this.params.moduleAddress, query, payloads);
|
|
68
98
|
if (this.archiving && this.isAllowedArchivingQuery(query.schema)) {
|
|
@@ -71,7 +101,9 @@ var HttpModuleProxy = class _HttpModuleProxy extends AbstractModuleProxy {
|
|
|
71
101
|
return result;
|
|
72
102
|
}
|
|
73
103
|
async publicChildren() {
|
|
74
|
-
return (await Promise.all(
|
|
104
|
+
return (await Promise.all(
|
|
105
|
+
Object.values(await this.childAddressMap()).filter(exists).map((address) => this.resolve(address))
|
|
106
|
+
)).filter(exists);
|
|
75
107
|
}
|
|
76
108
|
async resolve(idOrFilter = "*", options = {}) {
|
|
77
109
|
const config = {
|
|
@@ -84,10 +116,7 @@ var HttpModuleProxy = class _HttpModuleProxy extends AbstractModuleProxy {
|
|
|
84
116
|
upResolver: this.upResolver
|
|
85
117
|
};
|
|
86
118
|
if (idOrFilter === "*") {
|
|
87
|
-
return [
|
|
88
|
-
...await this.publicChildren(),
|
|
89
|
-
await this.params.host.resolve(this.address)
|
|
90
|
-
];
|
|
119
|
+
return [...await this.publicChildren(), await this.params.host.resolve(this.address)];
|
|
91
120
|
}
|
|
92
121
|
switch (typeof idOrFilter) {
|
|
93
122
|
case "string": {
|
|
@@ -110,16 +139,9 @@ var HttpModuleProxy = class _HttpModuleProxy extends AbstractModuleProxy {
|
|
|
110
139
|
};
|
|
111
140
|
|
|
112
141
|
// src/HttpBridgeModuleResolver.ts
|
|
113
|
-
var NotFoundModule = {
|
|
114
|
-
notFound: true
|
|
115
|
-
};
|
|
142
|
+
var NotFoundModule = { notFound: true };
|
|
116
143
|
var HttpBridgeModuleResolver = class extends AbstractBridgeModuleResolver {
|
|
117
|
-
|
|
118
|
-
__name(this, "HttpBridgeModuleResolver");
|
|
119
|
-
}
|
|
120
|
-
_resolvedCache = new LRUCache({
|
|
121
|
-
max: 1e3
|
|
122
|
-
});
|
|
144
|
+
_resolvedCache = new LRUCache({ max: 1e3 });
|
|
123
145
|
_resolvedCacheMutex = new Mutex();
|
|
124
146
|
get querySender() {
|
|
125
147
|
return this.params.querySender;
|
|
@@ -141,10 +163,7 @@ var HttpBridgeModuleResolver = class extends AbstractBridgeModuleResolver {
|
|
|
141
163
|
const cachedMod = this._resolvedCache.get(firstPart);
|
|
142
164
|
if (cachedMod) {
|
|
143
165
|
if (isModuleInstance(cachedMod)) {
|
|
144
|
-
const result2 = idParts.length <= 0 ? cachedMod : cachedMod.resolve(remainderParts, {
|
|
145
|
-
...options,
|
|
146
|
-
maxDepth: (options?.maxDepth ?? 5) - 1
|
|
147
|
-
});
|
|
166
|
+
const result2 = idParts.length <= 0 ? cachedMod : cachedMod.resolve(remainderParts, { ...options, maxDepth: (options?.maxDepth ?? 5) - 1 });
|
|
148
167
|
return result2;
|
|
149
168
|
} else {
|
|
150
169
|
return;
|
|
@@ -154,9 +173,7 @@ var HttpBridgeModuleResolver = class extends AbstractBridgeModuleResolver {
|
|
|
154
173
|
const finalParams = {
|
|
155
174
|
account,
|
|
156
175
|
archiving: this.params.archiving,
|
|
157
|
-
config: {
|
|
158
|
-
schema: ModuleConfigSchema
|
|
159
|
-
},
|
|
176
|
+
config: { schema: ModuleConfigSchema },
|
|
160
177
|
host: this,
|
|
161
178
|
moduleAddress: firstPart,
|
|
162
179
|
onQuerySendFinished: this.params.onQuerySendFinished,
|
|
@@ -178,7 +195,10 @@ var HttpBridgeModuleResolver = class extends AbstractBridgeModuleResolver {
|
|
|
178
195
|
return;
|
|
179
196
|
}
|
|
180
197
|
const configSchema = state.find((payload) => payload.schema === ConfigSchema)?.config;
|
|
181
|
-
const config = assertEx2(
|
|
198
|
+
const config = assertEx2(
|
|
199
|
+
state.find((payload) => payload.schema === configSchema),
|
|
200
|
+
() => "Unable to locate config"
|
|
201
|
+
);
|
|
182
202
|
proxy.setConfig(config);
|
|
183
203
|
this.logger?.log(`created HttpProxy [${firstPart}] ${proxy.id}`);
|
|
184
204
|
await proxy.start?.();
|
|
@@ -188,56 +208,32 @@ var HttpBridgeModuleResolver = class extends AbstractBridgeModuleResolver {
|
|
|
188
208
|
return wrapped;
|
|
189
209
|
});
|
|
190
210
|
const result = remainderParts.length > 0 ? await instance?.resolve(remainderParts, options) : instance;
|
|
191
|
-
return result ? [
|
|
192
|
-
result
|
|
193
|
-
] : [];
|
|
211
|
+
return result ? [result] : [];
|
|
194
212
|
}
|
|
195
213
|
};
|
|
196
214
|
|
|
197
215
|
// src/HttpBridgeBase.ts
|
|
198
|
-
|
|
199
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
200
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
201
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
202
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
203
|
-
}
|
|
204
|
-
__name(_ts_decorate, "_ts_decorate");
|
|
205
|
-
var HttpBridgeBase = class _HttpBridgeBase extends AbstractBridge {
|
|
206
|
-
static {
|
|
207
|
-
__name(this, "HttpBridgeBase");
|
|
208
|
-
}
|
|
209
|
-
static axios = new AxiosJson();
|
|
210
|
-
static configSchemas = [
|
|
211
|
-
...super.configSchemas,
|
|
212
|
-
HttpBridgeConfigSchema
|
|
213
|
-
];
|
|
214
|
-
static defaultConfigSchema = HttpBridgeConfigSchema;
|
|
215
|
-
static defaultFailureRetryTime = 1e3 * 60;
|
|
216
|
-
static defaultMaxConnections = 4;
|
|
217
|
-
static defaultMaxPayloadSizeWarning = 256 * 256;
|
|
218
|
-
static maxFailureCacheSize = 1e3;
|
|
216
|
+
var HttpBridgeBase = class extends AbstractBridge {
|
|
219
217
|
_axios;
|
|
220
218
|
_discoverRootsMutex = new Mutex2();
|
|
221
|
-
_failureTimeCache = new LRUCache2({
|
|
222
|
-
max: _HttpBridgeBase.maxFailureCacheSize
|
|
223
|
-
});
|
|
219
|
+
_failureTimeCache = new LRUCache2({ max: HttpBridgeBase.maxFailureCacheSize });
|
|
224
220
|
_querySemaphore;
|
|
225
221
|
_resolver;
|
|
226
222
|
get axios() {
|
|
227
|
-
this._axios = this._axios ?? this.params.axios ??
|
|
223
|
+
this._axios = this._axios ?? this.params.axios ?? HttpBridgeBase.axios;
|
|
228
224
|
return this._axios;
|
|
229
225
|
}
|
|
230
226
|
get clientUrl() {
|
|
231
227
|
return assertEx3(this.config.client?.url ?? this.config.nodeUrl, () => "No Url Set");
|
|
232
228
|
}
|
|
233
229
|
get failureRetryTime() {
|
|
234
|
-
return this.config.failureRetryTime ??
|
|
230
|
+
return this.config.failureRetryTime ?? HttpBridgeBase.defaultFailureRetryTime;
|
|
235
231
|
}
|
|
236
232
|
get maxConnections() {
|
|
237
|
-
return this.config.maxConnections ??
|
|
233
|
+
return this.config.maxConnections ?? HttpBridgeBase.defaultMaxConnections;
|
|
238
234
|
}
|
|
239
235
|
get maxPayloadSizeWarning() {
|
|
240
|
-
return this.config.maxPayloadSizeWarning ??
|
|
236
|
+
return this.config.maxPayloadSizeWarning ?? HttpBridgeBase.defaultMaxPayloadSizeWarning;
|
|
241
237
|
}
|
|
242
238
|
get querySemaphore() {
|
|
243
239
|
this._querySemaphore = this._querySemaphore ?? new Semaphore(this.maxConnections);
|
|
@@ -246,23 +242,14 @@ var HttpBridgeBase = class _HttpBridgeBase extends AbstractBridge {
|
|
|
246
242
|
get resolver() {
|
|
247
243
|
this._resolver = this._resolver ?? new HttpBridgeModuleResolver({
|
|
248
244
|
additionalSigners: this.additionalSigners,
|
|
249
|
-
archiving: {
|
|
250
|
-
...this.archiving,
|
|
251
|
-
resolveArchivists: this.resolveArchivingArchivists.bind(this)
|
|
252
|
-
},
|
|
245
|
+
archiving: { ...this.archiving, resolveArchivists: this.resolveArchivingArchivists.bind(this) },
|
|
253
246
|
bridge: this,
|
|
254
|
-
onQuerySendFinished:
|
|
255
|
-
forget2(this.emit("querySendFinished", {
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
}));
|
|
259
|
-
},
|
|
260
|
-
onQuerySendStarted: /* @__PURE__ */ __name((args) => {
|
|
261
|
-
forget2(this.emit("querySendStarted", {
|
|
262
|
-
mod: this,
|
|
263
|
-
...args
|
|
264
|
-
}));
|
|
265
|
-
}, "onQuerySendStarted"),
|
|
247
|
+
onQuerySendFinished: (args) => {
|
|
248
|
+
forget2(this.emit("querySendFinished", { mod: this, ...args }));
|
|
249
|
+
},
|
|
250
|
+
onQuerySendStarted: (args) => {
|
|
251
|
+
forget2(this.emit("querySendStarted", { mod: this, ...args }));
|
|
252
|
+
},
|
|
266
253
|
querySender: this,
|
|
267
254
|
root: this,
|
|
268
255
|
rootUrl: this.clientUrl,
|
|
@@ -308,18 +295,14 @@ var HttpBridgeBase = class _HttpBridgeBase extends AbstractBridge {
|
|
|
308
295
|
}
|
|
309
296
|
try {
|
|
310
297
|
await this.querySemaphore.acquire();
|
|
311
|
-
const payloadSize = JSON.stringify([
|
|
312
|
-
query,
|
|
313
|
-
payloads
|
|
314
|
-
]).length;
|
|
298
|
+
const payloadSize = JSON.stringify([query, payloads]).length;
|
|
315
299
|
if (payloadSize > this.maxPayloadSizeWarning) {
|
|
316
|
-
this.logger?.warn(
|
|
300
|
+
this.logger?.warn(
|
|
301
|
+
`Large targetQuery being sent: ${payloadSize} bytes [${this.address}][${this.moduleAddress}] [${query.schema}] [${payloads?.length}]`
|
|
302
|
+
);
|
|
317
303
|
}
|
|
318
304
|
const moduleUrl = this.moduleUrl(targetAddress).href;
|
|
319
|
-
const result = await this.axios.post(moduleUrl, [
|
|
320
|
-
query,
|
|
321
|
-
payloads
|
|
322
|
-
]);
|
|
305
|
+
const result = await this.axios.post(moduleUrl, [query, payloads]);
|
|
323
306
|
if (result.status === 404) {
|
|
324
307
|
throw `target module not found [${moduleUrl}] [${result.status}]`;
|
|
325
308
|
}
|
|
@@ -340,9 +323,7 @@ var HttpBridgeBase = class _HttpBridgeBase extends AbstractBridge {
|
|
|
340
323
|
throw new Error("Unsupported");
|
|
341
324
|
}
|
|
342
325
|
async getRootState() {
|
|
343
|
-
const queryPayload = {
|
|
344
|
-
schema: ModuleStateQuerySchema
|
|
345
|
-
};
|
|
326
|
+
const queryPayload = { schema: ModuleStateQuerySchema };
|
|
346
327
|
const boundQuery = await this.bindQuery(queryPayload);
|
|
347
328
|
try {
|
|
348
329
|
const response = await this.axios.post(this.clientUrl.toString(), boundQuery);
|
|
@@ -360,37 +341,37 @@ var HttpBridgeBase = class _HttpBridgeBase extends AbstractBridge {
|
|
|
360
341
|
}
|
|
361
342
|
}
|
|
362
343
|
async resolveRootNode(nodeManifest) {
|
|
363
|
-
const rootModule = assertEx3(
|
|
364
|
-
|
|
365
|
-
|
|
344
|
+
const rootModule = assertEx3(
|
|
345
|
+
(await this.resolver.resolveHandler(
|
|
346
|
+
assertEx3(nodeManifest.status?.address, () => "Root has no address"),
|
|
347
|
+
void 0,
|
|
348
|
+
{ manifest: nodeManifest }
|
|
349
|
+
)).at(0),
|
|
350
|
+
() => `Root not found [${nodeManifest.status?.address}]`
|
|
351
|
+
);
|
|
366
352
|
assertEx3(rootModule.constructor.name !== "HttpModuleProxy", () => "rootModule is not a Wrapper");
|
|
367
353
|
const rootNode = asAttachableNodeInstance(rootModule, "Root modules is not a node");
|
|
368
354
|
if (rootNode) {
|
|
369
355
|
this.logger.debug(`rootNode: ${rootNode.id}`);
|
|
370
356
|
this.downResolver.addResolver(rootNode);
|
|
371
|
-
return [
|
|
372
|
-
rootNode
|
|
373
|
-
];
|
|
357
|
+
return [rootNode];
|
|
374
358
|
}
|
|
375
359
|
return [];
|
|
376
360
|
}
|
|
377
361
|
};
|
|
378
|
-
HttpBridgeBase
|
|
362
|
+
__publicField(HttpBridgeBase, "axios", new AxiosJson());
|
|
363
|
+
__publicField(HttpBridgeBase, "configSchemas", [...__superGet(HttpBridgeBase, HttpBridgeBase, "configSchemas"), HttpBridgeConfigSchema]);
|
|
364
|
+
__publicField(HttpBridgeBase, "defaultConfigSchema", HttpBridgeConfigSchema);
|
|
365
|
+
__publicField(HttpBridgeBase, "defaultFailureRetryTime", 1e3 * 60);
|
|
366
|
+
__publicField(HttpBridgeBase, "defaultMaxConnections", 4);
|
|
367
|
+
__publicField(HttpBridgeBase, "defaultMaxPayloadSizeWarning", 256 * 256);
|
|
368
|
+
__publicField(HttpBridgeBase, "maxFailureCacheSize", 1e3);
|
|
369
|
+
HttpBridgeBase = __decorateClass([
|
|
379
370
|
creatableModule()
|
|
380
371
|
], HttpBridgeBase);
|
|
381
372
|
|
|
382
373
|
// src/HttpBridgeFull.ts
|
|
383
|
-
function _ts_decorate2(decorators, target, key, desc) {
|
|
384
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
385
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
386
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
387
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
388
|
-
}
|
|
389
|
-
__name(_ts_decorate2, "_ts_decorate");
|
|
390
374
|
var HttpBridge = class extends HttpBridgeBase {
|
|
391
|
-
static {
|
|
392
|
-
__name(this, "HttpBridge");
|
|
393
|
-
}
|
|
394
375
|
_app;
|
|
395
376
|
_exposedModules = [];
|
|
396
377
|
_server;
|
|
@@ -404,14 +385,8 @@ var HttpBridge = class extends HttpBridgeBase {
|
|
|
404
385
|
this._exposedModules.push(new WeakRef(mod));
|
|
405
386
|
const children = maxDepth > 0 ? await mod.publicChildren?.() ?? [] : [];
|
|
406
387
|
this.logger.log(`childrenToExpose [${mod.id}][${mod.address}]: ${toJsonString2(children.map((child) => child.id))}`);
|
|
407
|
-
const exposedChildren = (await Promise.all(children.map((child) => this.exposeChild(child, {
|
|
408
|
-
|
|
409
|
-
required: false
|
|
410
|
-
})))).flat().filter(exists3);
|
|
411
|
-
const allExposed = [
|
|
412
|
-
mod,
|
|
413
|
-
...exposedChildren
|
|
414
|
-
];
|
|
388
|
+
const exposedChildren = (await Promise.all(children.map((child) => this.exposeChild(child, { maxDepth: maxDepth - 1, required: false })))).flat().filter(exists3);
|
|
389
|
+
const allExposed = [mod, ...exposedChildren];
|
|
415
390
|
for (const exposedMod of allExposed) this.logger?.log(`exposed: ${exposedMod.address} [${mod.id}]`);
|
|
416
391
|
return allExposed;
|
|
417
392
|
}
|
|
@@ -443,14 +418,8 @@ var HttpBridge = class extends HttpBridgeBase {
|
|
|
443
418
|
this._exposedModules = this._exposedModules.filter((ref) => ref.deref()?.address !== address);
|
|
444
419
|
if (mod) {
|
|
445
420
|
const children = maxDepth > 0 ? await mod.publicChildren?.() ?? [] : [];
|
|
446
|
-
const exposedChildren = (await Promise.all(children.map((child) => this.unexposeHandler(child.address, {
|
|
447
|
-
|
|
448
|
-
required: false
|
|
449
|
-
})))).flat().filter(exists3);
|
|
450
|
-
return [
|
|
451
|
-
mod,
|
|
452
|
-
...exposedChildren
|
|
453
|
-
];
|
|
421
|
+
const exposedChildren = (await Promise.all(children.map((child) => this.unexposeHandler(child.address, { maxDepth: maxDepth - 1, required: false })))).flat().filter(exists3);
|
|
422
|
+
return [mod, ...exposedChildren];
|
|
454
423
|
}
|
|
455
424
|
return [];
|
|
456
425
|
}
|
|
@@ -468,15 +437,11 @@ var HttpBridge = class extends HttpBridgeBase {
|
|
|
468
437
|
if (mod) {
|
|
469
438
|
res.json(await mod.stateQuery(this.account));
|
|
470
439
|
} else {
|
|
471
|
-
res.status(StatusCodes.NOT_FOUND).json({
|
|
472
|
-
error: "Module not found"
|
|
473
|
-
});
|
|
440
|
+
res.status(StatusCodes.NOT_FOUND).json({ error: "Module not found" });
|
|
474
441
|
}
|
|
475
442
|
}
|
|
476
443
|
} catch (ex) {
|
|
477
|
-
res.status(StatusCodes.INTERNAL_SERVER_ERROR).json({
|
|
478
|
-
error: ex.message
|
|
479
|
-
});
|
|
444
|
+
res.status(StatusCodes.INTERNAL_SERVER_ERROR).json({ error: ex.message });
|
|
480
445
|
}
|
|
481
446
|
}
|
|
482
447
|
async handlePost(req, res) {
|
|
@@ -484,9 +449,7 @@ var HttpBridge = class extends HttpBridgeBase {
|
|
|
484
449
|
const [bw, payloads = []] = Array.isArray(req.body) ? req.body : [];
|
|
485
450
|
const query = isQueryBoundWitness(bw) ? bw : void 0;
|
|
486
451
|
if (!query) {
|
|
487
|
-
res.status(StatusCodes.BAD_REQUEST).json({
|
|
488
|
-
error: "No query provided"
|
|
489
|
-
});
|
|
452
|
+
res.status(StatusCodes.BAD_REQUEST).json({ error: "No query provided" });
|
|
490
453
|
return;
|
|
491
454
|
}
|
|
492
455
|
try {
|
|
@@ -496,17 +459,13 @@ var HttpBridge = class extends HttpBridgeBase {
|
|
|
496
459
|
} else {
|
|
497
460
|
const result = await this.callLocalModule(address, query, payloads);
|
|
498
461
|
if (result === null) {
|
|
499
|
-
res.status(StatusCodes.NOT_FOUND).json({
|
|
500
|
-
error: "Module not found"
|
|
501
|
-
});
|
|
462
|
+
res.status(StatusCodes.NOT_FOUND).json({ error: "Module not found" });
|
|
502
463
|
} else {
|
|
503
464
|
res.json(result);
|
|
504
465
|
}
|
|
505
466
|
}
|
|
506
467
|
} catch (ex) {
|
|
507
|
-
res.status(StatusCodes.INTERNAL_SERVER_ERROR).json({
|
|
508
|
-
error: ex.message
|
|
509
|
-
});
|
|
468
|
+
res.status(StatusCodes.INTERNAL_SERVER_ERROR).json({ error: ex.message });
|
|
510
469
|
}
|
|
511
470
|
}
|
|
512
471
|
initializeApp() {
|
|
@@ -519,10 +478,16 @@ var HttpBridge = class extends HttpBridgeBase {
|
|
|
519
478
|
useRequestCounters(app);
|
|
520
479
|
app.get("/", (_req, res) => res.redirect(StatusCodes.MOVED_TEMPORARILY, `/${this.address}`));
|
|
521
480
|
app.post("/", (_req, res) => res.redirect(StatusCodes.TEMPORARY_REDIRECT, `/${this.address}`));
|
|
522
|
-
app.get(
|
|
523
|
-
|
|
524
|
-
await this.
|
|
525
|
-
|
|
481
|
+
app.get(
|
|
482
|
+
"/:address",
|
|
483
|
+
asyncHandler(async (req, res) => await this.handleGet(req, res))
|
|
484
|
+
);
|
|
485
|
+
app.post(
|
|
486
|
+
"/:address",
|
|
487
|
+
asyncHandler(async (req, res) => {
|
|
488
|
+
await this.handlePost(req, res);
|
|
489
|
+
})
|
|
490
|
+
);
|
|
526
491
|
return app;
|
|
527
492
|
}
|
|
528
493
|
startHttpServer() {
|
|
@@ -550,7 +515,7 @@ var HttpBridge = class extends HttpBridgeBase {
|
|
|
550
515
|
return Promise.resolve(true);
|
|
551
516
|
}
|
|
552
517
|
};
|
|
553
|
-
HttpBridge =
|
|
518
|
+
HttpBridge = __decorateClass([
|
|
554
519
|
creatableModule2()
|
|
555
520
|
], HttpBridge);
|
|
556
521
|
export {
|