@xyo-network/bridge-http 2.111.2 → 3.0.0
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/index-browser.d.ts +105 -3
- package/dist/browser/index-browser.mjs.map +1 -1
- package/dist/neutral/index-browser.d.ts +105 -3
- package/dist/neutral/index-browser.mjs.map +1 -1
- package/dist/node/index.d.ts +128 -3
- package/dist/node/index.mjs +55 -85
- package/dist/node/index.mjs.map +1 -1
- package/package.json +32 -41
- package/src/HttpBridgeBase.ts +2 -1
- package/src/HttpBridgeClientOnly.ts +0 -1
- package/src/HttpBridgeFull.ts +0 -1
- package/dist/browser/HttpBridgeBase.d.cts +0 -45
- package/dist/browser/HttpBridgeBase.d.cts.map +0 -1
- package/dist/browser/HttpBridgeBase.d.mts +0 -45
- package/dist/browser/HttpBridgeBase.d.mts.map +0 -1
- package/dist/browser/HttpBridgeBase.d.ts +0 -45
- package/dist/browser/HttpBridgeBase.d.ts.map +0 -1
- package/dist/browser/HttpBridgeClientOnly.d.cts +0 -9
- package/dist/browser/HttpBridgeClientOnly.d.cts.map +0 -1
- package/dist/browser/HttpBridgeClientOnly.d.mts +0 -9
- package/dist/browser/HttpBridgeClientOnly.d.mts.map +0 -1
- package/dist/browser/HttpBridgeClientOnly.d.ts +0 -9
- package/dist/browser/HttpBridgeClientOnly.d.ts.map +0 -1
- package/dist/browser/HttpBridgeConfig.d.cts +0 -19
- package/dist/browser/HttpBridgeConfig.d.cts.map +0 -1
- package/dist/browser/HttpBridgeConfig.d.mts +0 -19
- package/dist/browser/HttpBridgeConfig.d.mts.map +0 -1
- package/dist/browser/HttpBridgeConfig.d.ts +0 -19
- package/dist/browser/HttpBridgeConfig.d.ts.map +0 -1
- package/dist/browser/HttpBridgeFull.d.cts +0 -35
- package/dist/browser/HttpBridgeFull.d.cts.map +0 -1
- package/dist/browser/HttpBridgeFull.d.mts +0 -35
- package/dist/browser/HttpBridgeFull.d.mts.map +0 -1
- package/dist/browser/HttpBridgeFull.d.ts +0 -35
- package/dist/browser/HttpBridgeFull.d.ts.map +0 -1
- package/dist/browser/HttpBridgeModuleResolver.d.cts +0 -32
- package/dist/browser/HttpBridgeModuleResolver.d.cts.map +0 -1
- package/dist/browser/HttpBridgeModuleResolver.d.mts +0 -32
- package/dist/browser/HttpBridgeModuleResolver.d.mts.map +0 -1
- package/dist/browser/HttpBridgeModuleResolver.d.ts +0 -32
- package/dist/browser/HttpBridgeModuleResolver.d.ts.map +0 -1
- package/dist/browser/ModuleProxy/ModuleProxy.d.cts +0 -27
- package/dist/browser/ModuleProxy/ModuleProxy.d.cts.map +0 -1
- package/dist/browser/ModuleProxy/ModuleProxy.d.mts +0 -27
- package/dist/browser/ModuleProxy/ModuleProxy.d.mts.map +0 -1
- package/dist/browser/ModuleProxy/ModuleProxy.d.ts +0 -27
- package/dist/browser/ModuleProxy/ModuleProxy.d.ts.map +0 -1
- package/dist/browser/ModuleProxy/index.d.cts +0 -2
- package/dist/browser/ModuleProxy/index.d.cts.map +0 -1
- package/dist/browser/ModuleProxy/index.d.mts +0 -2
- package/dist/browser/ModuleProxy/index.d.mts.map +0 -1
- package/dist/browser/ModuleProxy/index.d.ts +0 -2
- package/dist/browser/ModuleProxy/index.d.ts.map +0 -1
- package/dist/browser/index-browser.cjs +0 -416
- package/dist/browser/index-browser.cjs.map +0 -1
- package/dist/browser/index-browser.d.cts +0 -3
- package/dist/browser/index-browser.d.cts.map +0 -1
- package/dist/browser/index-browser.d.mts +0 -3
- package/dist/browser/index-browser.d.mts.map +0 -1
- package/dist/browser/index-browser.d.ts.map +0 -1
- package/dist/browser/index.d.cts +0 -3
- package/dist/browser/index.d.cts.map +0 -1
- package/dist/browser/index.d.mts +0 -3
- package/dist/browser/index.d.mts.map +0 -1
- package/dist/browser/index.d.ts +0 -3
- package/dist/browser/index.d.ts.map +0 -1
- package/dist/neutral/HttpBridgeBase.d.cts +0 -45
- package/dist/neutral/HttpBridgeBase.d.cts.map +0 -1
- package/dist/neutral/HttpBridgeBase.d.mts +0 -45
- package/dist/neutral/HttpBridgeBase.d.mts.map +0 -1
- package/dist/neutral/HttpBridgeBase.d.ts +0 -45
- package/dist/neutral/HttpBridgeBase.d.ts.map +0 -1
- package/dist/neutral/HttpBridgeClientOnly.d.cts +0 -9
- package/dist/neutral/HttpBridgeClientOnly.d.cts.map +0 -1
- package/dist/neutral/HttpBridgeClientOnly.d.mts +0 -9
- package/dist/neutral/HttpBridgeClientOnly.d.mts.map +0 -1
- package/dist/neutral/HttpBridgeClientOnly.d.ts +0 -9
- package/dist/neutral/HttpBridgeClientOnly.d.ts.map +0 -1
- package/dist/neutral/HttpBridgeConfig.d.cts +0 -19
- package/dist/neutral/HttpBridgeConfig.d.cts.map +0 -1
- package/dist/neutral/HttpBridgeConfig.d.mts +0 -19
- package/dist/neutral/HttpBridgeConfig.d.mts.map +0 -1
- package/dist/neutral/HttpBridgeConfig.d.ts +0 -19
- package/dist/neutral/HttpBridgeConfig.d.ts.map +0 -1
- package/dist/neutral/HttpBridgeFull.d.cts +0 -35
- package/dist/neutral/HttpBridgeFull.d.cts.map +0 -1
- package/dist/neutral/HttpBridgeFull.d.mts +0 -35
- package/dist/neutral/HttpBridgeFull.d.mts.map +0 -1
- package/dist/neutral/HttpBridgeFull.d.ts +0 -35
- package/dist/neutral/HttpBridgeFull.d.ts.map +0 -1
- package/dist/neutral/HttpBridgeModuleResolver.d.cts +0 -32
- package/dist/neutral/HttpBridgeModuleResolver.d.cts.map +0 -1
- package/dist/neutral/HttpBridgeModuleResolver.d.mts +0 -32
- package/dist/neutral/HttpBridgeModuleResolver.d.mts.map +0 -1
- package/dist/neutral/HttpBridgeModuleResolver.d.ts +0 -32
- package/dist/neutral/HttpBridgeModuleResolver.d.ts.map +0 -1
- package/dist/neutral/ModuleProxy/ModuleProxy.d.cts +0 -27
- package/dist/neutral/ModuleProxy/ModuleProxy.d.cts.map +0 -1
- package/dist/neutral/ModuleProxy/ModuleProxy.d.mts +0 -27
- package/dist/neutral/ModuleProxy/ModuleProxy.d.mts.map +0 -1
- package/dist/neutral/ModuleProxy/ModuleProxy.d.ts +0 -27
- package/dist/neutral/ModuleProxy/ModuleProxy.d.ts.map +0 -1
- package/dist/neutral/ModuleProxy/index.d.cts +0 -2
- package/dist/neutral/ModuleProxy/index.d.cts.map +0 -1
- package/dist/neutral/ModuleProxy/index.d.mts +0 -2
- package/dist/neutral/ModuleProxy/index.d.mts.map +0 -1
- package/dist/neutral/ModuleProxy/index.d.ts +0 -2
- package/dist/neutral/ModuleProxy/index.d.ts.map +0 -1
- package/dist/neutral/index-browser.cjs +0 -416
- package/dist/neutral/index-browser.cjs.map +0 -1
- package/dist/neutral/index-browser.d.cts +0 -3
- package/dist/neutral/index-browser.d.cts.map +0 -1
- package/dist/neutral/index-browser.d.mts +0 -3
- package/dist/neutral/index-browser.d.mts.map +0 -1
- package/dist/neutral/index-browser.d.ts.map +0 -1
- package/dist/neutral/index.d.cts +0 -3
- package/dist/neutral/index.d.cts.map +0 -1
- package/dist/neutral/index.d.mts +0 -3
- package/dist/neutral/index.d.mts.map +0 -1
- package/dist/neutral/index.d.ts +0 -3
- package/dist/neutral/index.d.ts.map +0 -1
- package/dist/node/HttpBridgeBase.d.cts +0 -45
- package/dist/node/HttpBridgeBase.d.cts.map +0 -1
- package/dist/node/HttpBridgeBase.d.mts +0 -45
- package/dist/node/HttpBridgeBase.d.mts.map +0 -1
- package/dist/node/HttpBridgeBase.d.ts +0 -45
- package/dist/node/HttpBridgeBase.d.ts.map +0 -1
- package/dist/node/HttpBridgeClientOnly.d.cts +0 -9
- package/dist/node/HttpBridgeClientOnly.d.cts.map +0 -1
- package/dist/node/HttpBridgeClientOnly.d.mts +0 -9
- package/dist/node/HttpBridgeClientOnly.d.mts.map +0 -1
- package/dist/node/HttpBridgeClientOnly.d.ts +0 -9
- package/dist/node/HttpBridgeClientOnly.d.ts.map +0 -1
- package/dist/node/HttpBridgeConfig.d.cts +0 -19
- package/dist/node/HttpBridgeConfig.d.cts.map +0 -1
- package/dist/node/HttpBridgeConfig.d.mts +0 -19
- package/dist/node/HttpBridgeConfig.d.mts.map +0 -1
- package/dist/node/HttpBridgeConfig.d.ts +0 -19
- package/dist/node/HttpBridgeConfig.d.ts.map +0 -1
- package/dist/node/HttpBridgeFull.d.cts +0 -35
- package/dist/node/HttpBridgeFull.d.cts.map +0 -1
- package/dist/node/HttpBridgeFull.d.mts +0 -35
- package/dist/node/HttpBridgeFull.d.mts.map +0 -1
- package/dist/node/HttpBridgeFull.d.ts +0 -35
- package/dist/node/HttpBridgeFull.d.ts.map +0 -1
- package/dist/node/HttpBridgeModuleResolver.d.cts +0 -32
- package/dist/node/HttpBridgeModuleResolver.d.cts.map +0 -1
- package/dist/node/HttpBridgeModuleResolver.d.mts +0 -32
- package/dist/node/HttpBridgeModuleResolver.d.mts.map +0 -1
- package/dist/node/HttpBridgeModuleResolver.d.ts +0 -32
- package/dist/node/HttpBridgeModuleResolver.d.ts.map +0 -1
- package/dist/node/ModuleProxy/ModuleProxy.d.cts +0 -27
- package/dist/node/ModuleProxy/ModuleProxy.d.cts.map +0 -1
- package/dist/node/ModuleProxy/ModuleProxy.d.mts +0 -27
- package/dist/node/ModuleProxy/ModuleProxy.d.mts.map +0 -1
- package/dist/node/ModuleProxy/ModuleProxy.d.ts +0 -27
- package/dist/node/ModuleProxy/ModuleProxy.d.ts.map +0 -1
- package/dist/node/ModuleProxy/index.d.cts +0 -2
- package/dist/node/ModuleProxy/index.d.cts.map +0 -1
- package/dist/node/ModuleProxy/index.d.mts +0 -2
- package/dist/node/ModuleProxy/index.d.mts.map +0 -1
- package/dist/node/ModuleProxy/index.d.ts +0 -2
- package/dist/node/ModuleProxy/index.d.ts.map +0 -1
- package/dist/node/index-browser.d.cts +0 -3
- package/dist/node/index-browser.d.cts.map +0 -1
- package/dist/node/index-browser.d.mts +0 -3
- package/dist/node/index-browser.d.mts.map +0 -1
- package/dist/node/index-browser.d.ts +0 -3
- package/dist/node/index-browser.d.ts.map +0 -1
- package/dist/node/index.cjs +0 -631
- package/dist/node/index.cjs.map +0 -1
- package/dist/node/index.d.cts +0 -3
- package/dist/node/index.d.cts.map +0 -1
- package/dist/node/index.d.mts +0 -3
- package/dist/node/index.d.mts.map +0 -1
- package/dist/node/index.d.ts.map +0 -1
package/dist/node/index.d.ts
CHANGED
|
@@ -1,3 +1,128 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import * as _xylabs_object from '@xylabs/object';
|
|
2
|
+
import { EmptyObject } from '@xylabs/object';
|
|
3
|
+
import { BridgeConfig, BridgeModule, BridgeExposeOptions, BridgeUnexposeOptions, BridgeParams } from '@xyo-network/bridge-model';
|
|
4
|
+
import * as _store__types_express_serve_static_core_npm_4_19_5_6a71bb1fe8_package from '.store/@types-express-serve-static-core-npm-4.19.5-6a71bb1fe8/package';
|
|
5
|
+
import { Server } from 'node:http';
|
|
6
|
+
import { Address } from '@xylabs/hex';
|
|
7
|
+
import { QueryBoundWitness } from '@xyo-network/boundwitness-model';
|
|
8
|
+
import * as _xyo_network_module_model from '@xyo-network/module-model';
|
|
9
|
+
import { ModuleQueryResult, ModuleInstance, ModuleIdentifier, ModuleFilterOptions, AnyConfigSchema } from '@xyo-network/module-model';
|
|
10
|
+
import * as _xyo_network_payload_model from '@xyo-network/payload-model';
|
|
11
|
+
import { Payload, Schema } from '@xyo-network/payload-model';
|
|
12
|
+
import express, { Application, Request, Response } from 'express';
|
|
13
|
+
import * as _xyo_network_account from '@xyo-network/account';
|
|
14
|
+
import { ModuleProxyParams, BridgeModuleResolverParams, AbstractBridgeModuleResolver, AbstractBridge } from '@xyo-network/bridge-abstract';
|
|
15
|
+
import { Mutex, Semaphore } from 'async-mutex';
|
|
16
|
+
import { LRUCache } from 'lru-cache';
|
|
17
|
+
import { AxiosJson } from '@xylabs/axios';
|
|
18
|
+
import { Promisable } from '@xylabs/promise';
|
|
19
|
+
|
|
20
|
+
type HttpBridgeConfigSchema = 'network.xyo.bridge.http.config';
|
|
21
|
+
declare const HttpBridgeConfigSchema: HttpBridgeConfigSchema;
|
|
22
|
+
type HttpBridgeConfig<TConfig extends EmptyObject = EmptyObject, TSchema extends string | void = void> = BridgeConfig<{
|
|
23
|
+
client?: BridgeConfig['client'] & {
|
|
24
|
+
url: string;
|
|
25
|
+
};
|
|
26
|
+
failureRetryTime?: number;
|
|
27
|
+
failureTimeCacheMax?: number;
|
|
28
|
+
host?: {
|
|
29
|
+
port: number;
|
|
30
|
+
};
|
|
31
|
+
maxConnections?: number;
|
|
32
|
+
maxPayloadSizeWarning?: number;
|
|
33
|
+
nodeUrl?: string;
|
|
34
|
+
schema: HttpBridgeConfigSchema;
|
|
35
|
+
} & TConfig, TSchema extends string ? TSchema : HttpBridgeConfigSchema>;
|
|
36
|
+
|
|
37
|
+
interface BridgeQuerySender {
|
|
38
|
+
sendBridgeQuery: <TOut extends Payload = Payload, TQuery extends QueryBoundWitness = QueryBoundWitness, TIn extends Payload = Payload>(targetAddress: Address, query: TQuery, payloads?: TIn[]) => Promise<ModuleQueryResult<TOut>>;
|
|
39
|
+
}
|
|
40
|
+
type HttpModuleProxyParams = ModuleProxyParams & {
|
|
41
|
+
querySender: BridgeQuerySender;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
interface HttpBridgeModuleResolverParams extends BridgeModuleResolverParams {
|
|
45
|
+
querySender: BridgeQuerySender;
|
|
46
|
+
rootUrl: string;
|
|
47
|
+
}
|
|
48
|
+
declare class HttpBridgeModuleResolver<T extends HttpBridgeModuleResolverParams = HttpBridgeModuleResolverParams> extends AbstractBridgeModuleResolver<T> {
|
|
49
|
+
protected _resolvedCache: LRUCache<Lowercase<string>, ModuleInstance<_xylabs_object.BaseParamsFields & {
|
|
50
|
+
account?: _xyo_network_account.AccountInstance | "random";
|
|
51
|
+
addToResolvers?: boolean;
|
|
52
|
+
additionalSigners?: _xyo_network_account.AccountInstance[];
|
|
53
|
+
allowNameResolution?: boolean;
|
|
54
|
+
config: _xyo_network_payload_model.SchemaFields & _xyo_network_payload_model.PayloadFields & Omit<_xyo_network_module_model.ArchivingModuleConfig & _xyo_network_module_model.ModuleConfigFields & _xyo_network_payload_model.SchemaFields & _xyo_network_payload_model.PayloadFields & {
|
|
55
|
+
schema: "network.xyo.module.config";
|
|
56
|
+
}, "schema"> & {
|
|
57
|
+
schema: string;
|
|
58
|
+
};
|
|
59
|
+
ephemeralQueryAccountEnabled?: boolean;
|
|
60
|
+
moduleIdentifierTransformers?: _xyo_network_module_model.ModuleIdentifierTransformer[];
|
|
61
|
+
}, _xyo_network_module_model.ModuleEventData<object>> | {
|
|
62
|
+
notFound: boolean;
|
|
63
|
+
}, unknown>;
|
|
64
|
+
protected _resolvedCacheMutex: Mutex;
|
|
65
|
+
get querySender(): BridgeQuerySender;
|
|
66
|
+
moduleUrl(address: Address): URL;
|
|
67
|
+
resolveHandler<T extends ModuleInstance = ModuleInstance>(id: ModuleIdentifier, options?: ModuleFilterOptions<T>, params?: Partial<HttpModuleProxyParams>): Promise<T[]>;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
interface HttpBridgeParams$1 extends BridgeParams<AnyConfigSchema<HttpBridgeConfig>> {
|
|
71
|
+
axios?: AxiosJson;
|
|
72
|
+
}
|
|
73
|
+
declare class HttpBridgeBase<TParams extends HttpBridgeParams$1> extends AbstractBridge<TParams> implements BridgeModule<TParams>, BridgeQuerySender {
|
|
74
|
+
static axios: AxiosJson;
|
|
75
|
+
static readonly configSchemas: Schema[];
|
|
76
|
+
static readonly defaultConfigSchema: Schema;
|
|
77
|
+
static defaultFailureRetryTime: number;
|
|
78
|
+
static defaultMaxConnections: number;
|
|
79
|
+
static defaultMaxPayloadSizeWarning: number;
|
|
80
|
+
static maxFailureCacheSize: number;
|
|
81
|
+
private _axios?;
|
|
82
|
+
private _discoverRootsMutex;
|
|
83
|
+
private _failureTimeCache;
|
|
84
|
+
private _querySemaphore?;
|
|
85
|
+
private _resolver?;
|
|
86
|
+
get axios(): AxiosJson;
|
|
87
|
+
get clientUrl(): string;
|
|
88
|
+
get failureRetryTime(): number;
|
|
89
|
+
get maxConnections(): number;
|
|
90
|
+
get maxPayloadSizeWarning(): number;
|
|
91
|
+
get querySemaphore(): Semaphore;
|
|
92
|
+
get resolver(): HttpBridgeModuleResolver<HttpBridgeModuleResolverParams>;
|
|
93
|
+
exposeHandler(_id: string, _options?: BridgeExposeOptions | undefined): Promisable<ModuleInstance[]>;
|
|
94
|
+
exposedHandler(): Promisable<Address[]>;
|
|
95
|
+
getRoots(force?: boolean): Promise<ModuleInstance[]>;
|
|
96
|
+
moduleUrl(address: Address): URL;
|
|
97
|
+
sendBridgeQuery<TOut extends Payload = Payload, TQuery extends QueryBoundWitness = QueryBoundWitness, TIn extends Payload = Payload>(targetAddress: Address, query: TQuery, payloads?: TIn[]): Promise<ModuleQueryResult<TOut>>;
|
|
98
|
+
unexposeHandler(_id: string, _options?: BridgeUnexposeOptions | undefined): Promisable<ModuleInstance[]>;
|
|
99
|
+
private getRootState;
|
|
100
|
+
private resolveRootNode;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
type AddressPathParams = {
|
|
104
|
+
address: Address;
|
|
105
|
+
};
|
|
106
|
+
type PostAddressRequestBody = [QueryBoundWitness, undefined | Payload[]];
|
|
107
|
+
interface HttpBridgeParams extends BridgeParams<AnyConfigSchema<HttpBridgeConfig>> {
|
|
108
|
+
}
|
|
109
|
+
declare class HttpBridge<TParams extends HttpBridgeParams> extends HttpBridgeBase<TParams> {
|
|
110
|
+
protected _app?: Application;
|
|
111
|
+
protected _exposedModules: WeakRef<ModuleInstance>[];
|
|
112
|
+
protected _server?: Server;
|
|
113
|
+
protected get app(): express.Application;
|
|
114
|
+
exposeChild(mod: ModuleInstance, options?: BridgeExposeOptions | undefined): Promise<ModuleInstance[]>;
|
|
115
|
+
exposeHandler(address: Address, options?: BridgeExposeOptions | undefined): Promise<ModuleInstance[]>;
|
|
116
|
+
exposedHandler(): Address[];
|
|
117
|
+
startHandler(): Promise<boolean>;
|
|
118
|
+
stopHandler(_timeout?: number | undefined): Promise<boolean>;
|
|
119
|
+
unexposeHandler(address: Address, options?: BridgeUnexposeOptions | undefined): Promise<ModuleInstance[]>;
|
|
120
|
+
protected callLocalModule(address: Address, query: QueryBoundWitness, payloads: Payload[]): Promise<ModuleQueryResult | null>;
|
|
121
|
+
protected handleGet(req: Request<AddressPathParams, ModuleQueryResult, PostAddressRequestBody>, res: Response): Promise<void>;
|
|
122
|
+
protected handlePost(req: Request<AddressPathParams, ModuleQueryResult, PostAddressRequestBody>, res: Response): Promise<express.Response<any, Record<string, any>> | undefined>;
|
|
123
|
+
protected initializeApp(): _store__types_express_serve_static_core_npm_4_19_5_6a71bb1fe8_package.Express;
|
|
124
|
+
protected startHttpServer(): Promise<boolean>;
|
|
125
|
+
protected stopHttpServer(): Promise<boolean>;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export { HttpBridge, type HttpBridgeConfig, HttpBridgeConfigSchema, type HttpBridgeParams };
|
package/dist/node/index.mjs
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
3
|
-
var __reflectGet = Reflect.get;
|
|
4
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
5
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
7
|
-
var __superGet = (cls, obj, key) => __reflectGet(__getProtoOf(cls), key, obj);
|
|
8
3
|
|
|
9
4
|
// src/HttpBridgeConfig.ts
|
|
10
5
|
var HttpBridgeConfigSchema = "network.xyo.bridge.http.config";
|
|
@@ -50,7 +45,11 @@ import { forget } from "@xylabs/forget";
|
|
|
50
45
|
import { isAddress } from "@xylabs/hex";
|
|
51
46
|
import { AbstractModuleProxy } from "@xyo-network/bridge-abstract";
|
|
52
47
|
import { ResolveHelper } from "@xyo-network/module-model";
|
|
53
|
-
var
|
|
48
|
+
var HttpModuleProxy = class _HttpModuleProxy extends AbstractModuleProxy {
|
|
49
|
+
static {
|
|
50
|
+
__name(this, "HttpModuleProxy");
|
|
51
|
+
}
|
|
52
|
+
static createCount = 0;
|
|
54
53
|
constructor(params) {
|
|
55
54
|
_HttpModuleProxy.createCount = _HttpModuleProxy.createCount + 1;
|
|
56
55
|
super(params);
|
|
@@ -98,7 +97,7 @@ var _HttpModuleProxy = class _HttpModuleProxy extends AbstractModuleProxy {
|
|
|
98
97
|
const address = isAddress(first) ? first : this.id === first ? this.address : this.childAddressByName(first);
|
|
99
98
|
if (!address) return void 0;
|
|
100
99
|
const firstInstance = await this.params.host.resolve(address);
|
|
101
|
-
return remainingPath ? await
|
|
100
|
+
return remainingPath ? await firstInstance?.resolve(remainingPath) : firstInstance;
|
|
102
101
|
}
|
|
103
102
|
case "object": {
|
|
104
103
|
return (await ResolveHelper.resolve(config, idOrFilter, options)).filter((mod) => mod.address !== this.address);
|
|
@@ -109,15 +108,15 @@ var _HttpModuleProxy = class _HttpModuleProxy extends AbstractModuleProxy {
|
|
|
109
108
|
}
|
|
110
109
|
}
|
|
111
110
|
};
|
|
112
|
-
__name(_HttpModuleProxy, "HttpModuleProxy");
|
|
113
|
-
__publicField(_HttpModuleProxy, "createCount", 0);
|
|
114
|
-
var HttpModuleProxy = _HttpModuleProxy;
|
|
115
111
|
|
|
116
112
|
// src/HttpBridgeModuleResolver.ts
|
|
117
113
|
var NotFoundModule = {
|
|
118
114
|
notFound: true
|
|
119
115
|
};
|
|
120
|
-
var
|
|
116
|
+
var HttpBridgeModuleResolver = class extends AbstractBridgeModuleResolver {
|
|
117
|
+
static {
|
|
118
|
+
__name(this, "HttpBridgeModuleResolver");
|
|
119
|
+
}
|
|
121
120
|
_resolvedCache = new LRUCache({
|
|
122
121
|
max: 1e3
|
|
123
122
|
});
|
|
@@ -139,13 +138,12 @@ var _HttpBridgeModuleResolver = class _HttpBridgeModuleResolver extends Abstract
|
|
|
139
138
|
assertEx2(isAddress2(firstPart), () => `Invalid module address: ${firstPart}`);
|
|
140
139
|
const remainderParts = idParts.join(":");
|
|
141
140
|
const instance = await this._resolvedCacheMutex.runExclusive(async () => {
|
|
142
|
-
var _a, _b, _c, _d, _e;
|
|
143
141
|
const cachedMod = this._resolvedCache.get(firstPart);
|
|
144
142
|
if (cachedMod) {
|
|
145
143
|
if (isModuleInstance(cachedMod)) {
|
|
146
144
|
const result2 = idParts.length <= 0 ? cachedMod : cachedMod.resolve(remainderParts, {
|
|
147
145
|
...options,
|
|
148
|
-
maxDepth: (
|
|
146
|
+
maxDepth: (options?.maxDepth ?? 5) - 1
|
|
149
147
|
});
|
|
150
148
|
return result2;
|
|
151
149
|
} else {
|
|
@@ -166,37 +164,35 @@ var _HttpBridgeModuleResolver = class _HttpBridgeModuleResolver extends Abstract
|
|
|
166
164
|
querySender: this.params.querySender,
|
|
167
165
|
...params
|
|
168
166
|
};
|
|
169
|
-
|
|
167
|
+
this.logger?.debug(`creating HttpProxy [${firstPart}] ${id}`);
|
|
170
168
|
const proxy = new HttpModuleProxy(finalParams);
|
|
171
169
|
let state;
|
|
172
170
|
try {
|
|
173
171
|
state = await proxy.state();
|
|
174
172
|
} catch (ex) {
|
|
175
173
|
const error = ex;
|
|
176
|
-
|
|
174
|
+
this.logger?.log(error.message);
|
|
177
175
|
}
|
|
178
176
|
if (!state) {
|
|
179
177
|
this._resolvedCache.set(firstPart, NotFoundModule);
|
|
180
178
|
return;
|
|
181
179
|
}
|
|
182
|
-
const configSchema =
|
|
180
|
+
const configSchema = state.find((payload) => payload.schema === ConfigSchema)?.config;
|
|
183
181
|
const config = assertEx2(state.find((payload) => payload.schema === configSchema), () => "Unable to locate config");
|
|
184
182
|
proxy.setConfig(config);
|
|
185
|
-
|
|
186
|
-
await
|
|
183
|
+
this.logger?.log(`created HttpProxy [${firstPart}] ${proxy.id}`);
|
|
184
|
+
await proxy.start?.();
|
|
187
185
|
const wrapped = wrapModuleWithType(proxy, account);
|
|
188
186
|
assertEx2(asModuleInstance(wrapped, {}), () => `Failed to asModuleInstance [${id}]`);
|
|
189
187
|
this._resolvedCache.set(wrapped.address, wrapped);
|
|
190
188
|
return wrapped;
|
|
191
189
|
});
|
|
192
|
-
const result = remainderParts.length > 0 ? await
|
|
190
|
+
const result = remainderParts.length > 0 ? await instance?.resolve(remainderParts, options) : instance;
|
|
193
191
|
return result ? [
|
|
194
192
|
result
|
|
195
193
|
] : [];
|
|
196
194
|
}
|
|
197
195
|
};
|
|
198
|
-
__name(_HttpBridgeModuleResolver, "HttpBridgeModuleResolver");
|
|
199
|
-
var HttpBridgeModuleResolver = _HttpBridgeModuleResolver;
|
|
200
196
|
|
|
201
197
|
// src/HttpBridgeBase.ts
|
|
202
198
|
function _ts_decorate(decorators, target, key, desc) {
|
|
@@ -206,7 +202,20 @@ function _ts_decorate(decorators, target, key, desc) {
|
|
|
206
202
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
207
203
|
}
|
|
208
204
|
__name(_ts_decorate, "_ts_decorate");
|
|
209
|
-
var
|
|
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;
|
|
210
219
|
_axios;
|
|
211
220
|
_discoverRootsMutex = new Mutex2();
|
|
212
221
|
_failureTimeCache = new LRUCache2({
|
|
@@ -219,8 +228,7 @@ var _HttpBridgeBase = class _HttpBridgeBase extends AbstractBridge {
|
|
|
219
228
|
return this._axios;
|
|
220
229
|
}
|
|
221
230
|
get clientUrl() {
|
|
222
|
-
|
|
223
|
-
return assertEx3(((_a = this.config.client) == null ? void 0 : _a.url) ?? this.config.nodeUrl, () => "No Url Set");
|
|
231
|
+
return assertEx3(this.config.client?.url ?? this.config.nodeUrl, () => "No Url Set");
|
|
224
232
|
}
|
|
225
233
|
get failureRetryTime() {
|
|
226
234
|
return this.config.failureRetryTime ?? _HttpBridgeBase.defaultFailureRetryTime;
|
|
@@ -270,14 +278,13 @@ var _HttpBridgeBase = class _HttpBridgeBase extends AbstractBridge {
|
|
|
270
278
|
}
|
|
271
279
|
async getRoots(force) {
|
|
272
280
|
return await this._discoverRootsMutex.runExclusive(async () => {
|
|
273
|
-
var _a, _b;
|
|
274
281
|
if (this._roots === void 0 || force) {
|
|
275
282
|
const state = await this.getRootState();
|
|
276
|
-
|
|
277
|
-
const nodeManifest = state
|
|
283
|
+
this.logger?.debug(`HttpBridge:discoverRoots.state [${state?.length}]`);
|
|
284
|
+
const nodeManifest = state?.find(isPayloadOfSchemaType(NodeManifestPayloadSchema));
|
|
278
285
|
if (nodeManifest) {
|
|
279
286
|
const mods = (await this.resolveRootNode(nodeManifest)).filter(exists2);
|
|
280
|
-
|
|
287
|
+
this.logger?.debug(`HttpBridge:discoverRoots [${mods.length}]`);
|
|
281
288
|
this._roots = mods;
|
|
282
289
|
} else {
|
|
283
290
|
this._roots = [];
|
|
@@ -290,7 +297,6 @@ var _HttpBridgeBase = class _HttpBridgeBase extends AbstractBridge {
|
|
|
290
297
|
return new URL(address, this.clientUrl);
|
|
291
298
|
}
|
|
292
299
|
async sendBridgeQuery(targetAddress, query, payloads) {
|
|
293
|
-
var _a, _b, _c, _d;
|
|
294
300
|
const lastFailureTime = this._failureTimeCache.get(targetAddress);
|
|
295
301
|
if (lastFailureTime !== void 0) {
|
|
296
302
|
const now = Date.now();
|
|
@@ -307,7 +313,7 @@ var _HttpBridgeBase = class _HttpBridgeBase extends AbstractBridge {
|
|
|
307
313
|
payloads
|
|
308
314
|
]).length;
|
|
309
315
|
if (payloadSize > this.maxPayloadSizeWarning) {
|
|
310
|
-
|
|
316
|
+
this.logger?.warn(`Large targetQuery being sent: ${payloadSize} bytes [${this.address}][${this.moduleAddress}] [${query.schema}] [${payloads?.length}]`);
|
|
311
317
|
}
|
|
312
318
|
const moduleUrl = this.moduleUrl(targetAddress).href;
|
|
313
319
|
const result = await this.axios.post(moduleUrl, [
|
|
@@ -318,13 +324,13 @@ var _HttpBridgeBase = class _HttpBridgeBase extends AbstractBridge {
|
|
|
318
324
|
throw `target module not found [${moduleUrl}] [${result.status}]`;
|
|
319
325
|
}
|
|
320
326
|
if (result.status >= 400) {
|
|
321
|
-
|
|
327
|
+
this.logger?.error(`targetQuery failed [${moduleUrl}]`);
|
|
322
328
|
throw `targetQuery failed [${moduleUrl}] [${result.status}]`;
|
|
323
329
|
}
|
|
324
|
-
return
|
|
330
|
+
return result.data?.data;
|
|
325
331
|
} catch (ex) {
|
|
326
332
|
const error = ex;
|
|
327
|
-
|
|
333
|
+
this.logger?.error(`Error: ${toJsonString(error)}`);
|
|
328
334
|
throw error;
|
|
329
335
|
} finally {
|
|
330
336
|
this.querySemaphore.release();
|
|
@@ -334,7 +340,6 @@ var _HttpBridgeBase = class _HttpBridgeBase extends AbstractBridge {
|
|
|
334
340
|
throw new Error("Unsupported");
|
|
335
341
|
}
|
|
336
342
|
async getRootState() {
|
|
337
|
-
var _a;
|
|
338
343
|
const queryPayload = {
|
|
339
344
|
schema: ModuleStateQuerySchema
|
|
340
345
|
};
|
|
@@ -351,17 +356,13 @@ var _HttpBridgeBase = class _HttpBridgeBase extends AbstractBridge {
|
|
|
351
356
|
return payloads;
|
|
352
357
|
} catch (ex) {
|
|
353
358
|
const error = ex;
|
|
354
|
-
|
|
359
|
+
this.logger?.warn(`Unable to connect to remote node: ${error.message} [${this.clientUrl}]`);
|
|
355
360
|
}
|
|
356
361
|
}
|
|
357
362
|
async resolveRootNode(nodeManifest) {
|
|
358
|
-
|
|
359
|
-
const rootModule = assertEx3((await this.resolver.resolveHandler(assertEx3((_a = nodeManifest.status) == null ? void 0 : _a.address, () => "Root has no address"), void 0, {
|
|
363
|
+
const rootModule = assertEx3((await this.resolver.resolveHandler(assertEx3(nodeManifest.status?.address, () => "Root has no address"), void 0, {
|
|
360
364
|
manifest: nodeManifest
|
|
361
|
-
})).at(0), () => {
|
|
362
|
-
var _a2;
|
|
363
|
-
return `Root not found [${(_a2 = nodeManifest.status) == null ? void 0 : _a2.address}]`;
|
|
364
|
-
});
|
|
365
|
+
})).at(0), () => `Root not found [${nodeManifest.status?.address}]`);
|
|
365
366
|
assertEx3(rootModule.constructor.name !== "HttpModuleProxy", () => "rootModule is not a Wrapper");
|
|
366
367
|
const rootNode = asAttachableNodeInstance(rootModule, "Root modules is not a node");
|
|
367
368
|
if (rootNode) {
|
|
@@ -374,18 +375,6 @@ var _HttpBridgeBase = class _HttpBridgeBase extends AbstractBridge {
|
|
|
374
375
|
return [];
|
|
375
376
|
}
|
|
376
377
|
};
|
|
377
|
-
__name(_HttpBridgeBase, "HttpBridgeBase");
|
|
378
|
-
__publicField(_HttpBridgeBase, "axios", new AxiosJson());
|
|
379
|
-
__publicField(_HttpBridgeBase, "configSchemas", [
|
|
380
|
-
...__superGet(_HttpBridgeBase, _HttpBridgeBase, "configSchemas"),
|
|
381
|
-
HttpBridgeConfigSchema
|
|
382
|
-
]);
|
|
383
|
-
__publicField(_HttpBridgeBase, "defaultConfigSchema", HttpBridgeConfigSchema);
|
|
384
|
-
__publicField(_HttpBridgeBase, "defaultFailureRetryTime", 1e3 * 60);
|
|
385
|
-
__publicField(_HttpBridgeBase, "defaultMaxConnections", 4);
|
|
386
|
-
__publicField(_HttpBridgeBase, "defaultMaxPayloadSizeWarning", 256 * 256);
|
|
387
|
-
__publicField(_HttpBridgeBase, "maxFailureCacheSize", 1e3);
|
|
388
|
-
var HttpBridgeBase = _HttpBridgeBase;
|
|
389
378
|
HttpBridgeBase = _ts_decorate([
|
|
390
379
|
creatableModule()
|
|
391
380
|
], HttpBridgeBase);
|
|
@@ -398,7 +387,10 @@ function _ts_decorate2(decorators, target, key, desc) {
|
|
|
398
387
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
399
388
|
}
|
|
400
389
|
__name(_ts_decorate2, "_ts_decorate");
|
|
401
|
-
var
|
|
390
|
+
var HttpBridge = class extends HttpBridgeBase {
|
|
391
|
+
static {
|
|
392
|
+
__name(this, "HttpBridge");
|
|
393
|
+
}
|
|
402
394
|
_app;
|
|
403
395
|
_exposedModules = [];
|
|
404
396
|
_server;
|
|
@@ -407,11 +399,10 @@ var _HttpBridge = class _HttpBridge extends HttpBridgeBase {
|
|
|
407
399
|
return assertEx4(this._app, () => "App not initialized");
|
|
408
400
|
}
|
|
409
401
|
async exposeChild(mod, options) {
|
|
410
|
-
var _a, _b;
|
|
411
402
|
const { maxDepth = 5 } = options ?? {};
|
|
412
403
|
assertEx4(this.config.host, () => "Not configured as a host");
|
|
413
404
|
this._exposedModules.push(new WeakRef(mod));
|
|
414
|
-
const children = maxDepth > 0 ? await
|
|
405
|
+
const children = maxDepth > 0 ? await mod.publicChildren?.() ?? [] : [];
|
|
415
406
|
this.logger.log(`childrenToExpose [${mod.id}][${mod.address}]: ${toJsonString2(children.map((child) => child.id))}`);
|
|
416
407
|
const exposedChildren = (await Promise.all(children.map((child) => this.exposeChild(child, {
|
|
417
408
|
maxDepth: maxDepth - 1,
|
|
@@ -421,7 +412,7 @@ var _HttpBridge = class _HttpBridge extends HttpBridgeBase {
|
|
|
421
412
|
mod,
|
|
422
413
|
...exposedChildren
|
|
423
414
|
];
|
|
424
|
-
for (const exposedMod of allExposed)
|
|
415
|
+
for (const exposedMod of allExposed) this.logger?.log(`exposed: ${exposedMod.address} [${mod.id}]`);
|
|
425
416
|
return allExposed;
|
|
426
417
|
}
|
|
427
418
|
async exposeHandler(address, options) {
|
|
@@ -436,10 +427,7 @@ var _HttpBridge = class _HttpBridge extends HttpBridgeBase {
|
|
|
436
427
|
return [];
|
|
437
428
|
}
|
|
438
429
|
exposedHandler() {
|
|
439
|
-
return this._exposedModules.map((ref) =>
|
|
440
|
-
var _a;
|
|
441
|
-
return (_a = ref.deref()) == null ? void 0 : _a.address;
|
|
442
|
-
}).filter(exists3);
|
|
430
|
+
return this._exposedModules.map((ref) => ref.deref()?.address).filter(exists3);
|
|
443
431
|
}
|
|
444
432
|
async startHandler() {
|
|
445
433
|
return await super.startHandler() && await this.startHttpServer();
|
|
@@ -448,20 +436,13 @@ var _HttpBridge = class _HttpBridge extends HttpBridgeBase {
|
|
|
448
436
|
return await super.stopHandler() && await this.stopHttpServer();
|
|
449
437
|
}
|
|
450
438
|
async unexposeHandler(address, options) {
|
|
451
|
-
var _a, _b;
|
|
452
439
|
const { maxDepth = 2, required = true } = options ?? {};
|
|
453
440
|
assertEx4(this.config.host, () => "Not configured as a host");
|
|
454
|
-
const mod =
|
|
455
|
-
var _a2;
|
|
456
|
-
return ((_a2 = ref.deref()) == null ? void 0 : _a2.address) === address;
|
|
457
|
-
})) == null ? void 0 : _a.deref();
|
|
441
|
+
const mod = this._exposedModules.find((ref) => ref.deref()?.address === address)?.deref();
|
|
458
442
|
assertEx4(!required || mod, () => `Module not exposed: ${address}`);
|
|
459
|
-
this._exposedModules = this._exposedModules.filter((ref) =>
|
|
460
|
-
var _a2;
|
|
461
|
-
return ((_a2 = ref.deref()) == null ? void 0 : _a2.address) !== address;
|
|
462
|
-
});
|
|
443
|
+
this._exposedModules = this._exposedModules.filter((ref) => ref.deref()?.address !== address);
|
|
463
444
|
if (mod) {
|
|
464
|
-
const children = maxDepth > 0 ? await
|
|
445
|
+
const children = maxDepth > 0 ? await mod.publicChildren?.() ?? [] : [];
|
|
465
446
|
const exposedChildren = (await Promise.all(children.map((child) => this.unexposeHandler(child.address, {
|
|
466
447
|
maxDepth: maxDepth - 1,
|
|
467
448
|
required: false
|
|
@@ -474,24 +455,16 @@ var _HttpBridge = class _HttpBridge extends HttpBridgeBase {
|
|
|
474
455
|
return [];
|
|
475
456
|
}
|
|
476
457
|
async callLocalModule(address, query, payloads) {
|
|
477
|
-
|
|
478
|
-
const mod = (_a = this._exposedModules.find((ref) => {
|
|
479
|
-
var _a2;
|
|
480
|
-
return ((_a2 = ref.deref()) == null ? void 0 : _a2.address) === address;
|
|
481
|
-
})) == null ? void 0 : _a.deref();
|
|
458
|
+
const mod = this._exposedModules.find((ref) => ref.deref()?.address === address)?.deref();
|
|
482
459
|
return mod ? await mod.query(query, payloads) : null;
|
|
483
460
|
}
|
|
484
461
|
async handleGet(req, res) {
|
|
485
|
-
var _a;
|
|
486
462
|
const { address } = req.params;
|
|
487
463
|
try {
|
|
488
464
|
if (address == this.address) {
|
|
489
465
|
res.json(await this.stateQuery(this.account));
|
|
490
466
|
} else {
|
|
491
|
-
const mod =
|
|
492
|
-
var _a2;
|
|
493
|
-
return ((_a2 = ref.deref()) == null ? void 0 : _a2.address) === address;
|
|
494
|
-
})) == null ? void 0 : _a.deref();
|
|
467
|
+
const mod = this._exposedModules.find((ref) => ref.deref()?.address === address)?.deref();
|
|
495
468
|
if (mod) {
|
|
496
469
|
res.json(await mod.stateQuery(this.account));
|
|
497
470
|
} else {
|
|
@@ -559,10 +532,9 @@ var _HttpBridge = class _HttpBridge extends HttpBridgeBase {
|
|
|
559
532
|
return app;
|
|
560
533
|
}
|
|
561
534
|
startHttpServer() {
|
|
562
|
-
var _a;
|
|
563
535
|
if (this.config.host) {
|
|
564
536
|
assertEx4(!this._server, () => "Server already started");
|
|
565
|
-
this._server = this.app.listen(
|
|
537
|
+
this._server = this.app.listen(this.config.host?.port ?? 3030);
|
|
566
538
|
}
|
|
567
539
|
return Promise.resolve(true);
|
|
568
540
|
}
|
|
@@ -584,8 +556,6 @@ var _HttpBridge = class _HttpBridge extends HttpBridgeBase {
|
|
|
584
556
|
return Promise.resolve(true);
|
|
585
557
|
}
|
|
586
558
|
};
|
|
587
|
-
__name(_HttpBridge, "HttpBridge");
|
|
588
|
-
var HttpBridge = _HttpBridge;
|
|
589
559
|
HttpBridge = _ts_decorate2([
|
|
590
560
|
creatableModule2()
|
|
591
561
|
], HttpBridge);
|