@blankways/remote 0.0.0-stage → 0.1.0-alpha.2
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/classes.d.ts +6 -0
- package/dist/classes.js +7 -0
- package/dist/classes.js.map +1 -0
- package/dist/functions/api.d.ts +48 -0
- package/dist/functions/api.js +43 -0
- package/dist/functions/api.js.map +1 -0
- package/dist/functions/index.d.ts +4 -0
- package/dist/functions/index.js +5 -0
- package/dist/functions/index.js.map +1 -0
- package/dist/functions/pointers/creation.d.ts +12 -0
- package/dist/functions/pointers/creation.js +24 -0
- package/dist/functions/pointers/creation.js.map +1 -0
- package/dist/functions/pointers/emission.d.ts +15 -0
- package/dist/functions/pointers/emission.js +64 -0
- package/dist/functions/pointers/emission.js.map +1 -0
- package/dist/functions/pointers/index.d.ts +4 -0
- package/dist/functions/pointers/index.js +5 -0
- package/dist/functions/pointers/index.js.map +1 -0
- package/dist/functions/pointers/reception.d.ts +10 -0
- package/dist/functions/pointers/reception.js +54 -0
- package/dist/functions/pointers/reception.js.map +1 -0
- package/dist/functions/pointers/resource.d.ts +8 -0
- package/dist/functions/pointers/resource.js +134 -0
- package/dist/functions/pointers/resource.js.map +1 -0
- package/dist/functions/state.d.ts +13 -0
- package/dist/functions/state.js +27 -0
- package/dist/functions/state.js.map +1 -0
- package/dist/functions/transport.d.ts +4 -0
- package/dist/functions/transport.js +26 -0
- package/dist/functions/transport.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/libraries/events/classes.d.ts +7 -0
- package/dist/libraries/events/classes.js +8 -0
- package/dist/libraries/events/classes.js.map +1 -0
- package/dist/libraries/events/functions.d.ts +9 -0
- package/dist/libraries/events/functions.js +81 -0
- package/dist/libraries/events/functions.js.map +1 -0
- package/dist/libraries/events/index.d.ts +3 -0
- package/dist/libraries/events/index.js +4 -0
- package/dist/libraries/events/index.js.map +1 -0
- package/dist/libraries/events/runtime.d.ts +4 -0
- package/dist/libraries/events/runtime.js +9 -0
- package/dist/libraries/events/runtime.js.map +1 -0
- package/dist/libraries/events/types.d.ts +10 -0
- package/dist/libraries/events/types.js +2 -0
- package/dist/libraries/events/types.js.map +1 -0
- package/dist/libraries/result/classes.d.ts +5 -0
- package/dist/libraries/result/classes.js +6 -0
- package/dist/libraries/result/classes.js.map +1 -0
- package/dist/libraries/result/functions.d.ts +3 -0
- package/dist/libraries/result/functions.js +9 -0
- package/dist/libraries/result/functions.js.map +1 -0
- package/dist/libraries/result/index.d.ts +6 -0
- package/dist/libraries/result/index.js +5 -0
- package/dist/libraries/result/index.js.map +1 -0
- package/dist/libraries/result/types.d.ts +15 -0
- package/dist/libraries/result/types.js +2 -0
- package/dist/libraries/result/types.js.map +1 -0
- package/dist/runtime/common.d.ts +9 -0
- package/dist/runtime/common.js +117 -0
- package/dist/runtime/common.js.map +1 -0
- package/dist/runtime/context.d.ts +40 -0
- package/dist/runtime/context.js +33 -0
- package/dist/runtime/context.js.map +1 -0
- package/dist/runtime/index.d.ts +4 -0
- package/dist/runtime/index.js +5 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/runtime/prefabs.d.ts +5 -0
- package/dist/runtime/prefabs.js +34 -0
- package/dist/runtime/prefabs.js.map +1 -0
- package/dist/runtime/resource.d.ts +5 -0
- package/dist/runtime/resource.js +6 -0
- package/dist/runtime/resource.js.map +1 -0
- package/dist/runtime/schemas.d.ts +13 -0
- package/dist/runtime/schemas.js +15 -0
- package/dist/runtime/schemas.js.map +1 -0
- package/dist/runtime/transport.d.ts +1 -0
- package/dist/runtime/transport.js +3 -0
- package/dist/runtime/transport.js.map +1 -0
- package/dist/types/common.d.ts +14 -0
- package/dist/types/common.js +2 -0
- package/dist/types/common.js.map +1 -0
- package/dist/types/errors.d.ts +14 -0
- package/dist/types/errors.js +2 -0
- package/dist/types/errors.js.map +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.js +4 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/pointers/call.d.ts +15 -0
- package/dist/types/pointers/call.js +2 -0
- package/dist/types/pointers/call.js.map +1 -0
- package/dist/types/pointers/index.d.ts +2 -0
- package/dist/types/pointers/index.js +3 -0
- package/dist/types/pointers/index.js.map +1 -0
- package/dist/types/pointers/resource.d.ts +4 -0
- package/dist/types/pointers/resource.js +2 -0
- package/dist/types/pointers/resource.js.map +1 -0
- package/dist/types/pointers/schema.d.ts +10 -0
- package/dist/types/pointers/schema.js +2 -0
- package/dist/types/pointers/schema.js.map +1 -0
- package/dist/types/state.d.ts +2 -0
- package/dist/types/state.js +2 -0
- package/dist/types/state.js.map +1 -0
- package/package.json +52 -3
- package/README.md +0 -3
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { createChannel, listenChannel, notifyChannel, dispose } from './functions.js';
|
|
2
|
+
export class Events {
|
|
3
|
+
static channel = createChannel;
|
|
4
|
+
static from = listenChannel;
|
|
5
|
+
static to = notifyChannel;
|
|
6
|
+
static dispose = dispose;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=classes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"classes.js","sourceRoot":"","sources":["../../../source/libraries/events/classes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAErF,MAAM,OAAO,MAAM;IACf,MAAM,CAAU,OAAO,GAAG,aAAa,CAAA;IACvC,MAAM,CAAU,IAAI,GAAG,aAAa,CAAA;IACpC,MAAM,CAAU,EAAE,GAAG,aAAa,CAAA;IAClC,MAAM,CAAU,OAAO,GAAG,OAAO,CAAA;CACpC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type ChannelId, type ListenerId, type UnknownFunction } from './types.js';
|
|
2
|
+
import { Result } from '../result/index.js';
|
|
3
|
+
export declare function createChannel<Function extends UnknownFunction>(): ChannelId<Function>;
|
|
4
|
+
export declare function listenChannel<Function extends UnknownFunction>(channel: ChannelId<Function>, fn: Function): Result<ListenerId>;
|
|
5
|
+
export declare function notifyChannel<Function extends UnknownFunction>(channel: ChannelId<Function>, ...args: Parameters<Function>): void;
|
|
6
|
+
export declare function disposeChannel(channel: ChannelId<UnknownFunction>): void;
|
|
7
|
+
export declare function disposeListener(channel: ChannelId<UnknownFunction>, listener: ListenerId): void;
|
|
8
|
+
export declare function dispose(channel: ChannelId<UnknownFunction>): void;
|
|
9
|
+
export declare function dispose(channel: ChannelId<UnknownFunction>, listener: ListenerId): void;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { Identity } from '@blankways/identity';
|
|
2
|
+
import { ChannelFamily, ListenerFamily } from './runtime.js';
|
|
3
|
+
import { runtime } from './runtime.js';
|
|
4
|
+
import { Result } from '../result/index.js';
|
|
5
|
+
export function createChannel() {
|
|
6
|
+
const id = Identity.Identifier.create(ChannelFamily);
|
|
7
|
+
runtime.managed.add(id);
|
|
8
|
+
runtime.channelListeners.set(id, []);
|
|
9
|
+
return id;
|
|
10
|
+
}
|
|
11
|
+
export function listenChannel(channel, fn) {
|
|
12
|
+
if (!runtime.managed.has(channel))
|
|
13
|
+
return Result.fail();
|
|
14
|
+
const id = Identity.Identifier.create(ListenerFamily);
|
|
15
|
+
const listeners = runtime.channelListeners.get(channel);
|
|
16
|
+
if (listeners === undefined)
|
|
17
|
+
return Result.fail();
|
|
18
|
+
let index = 0;
|
|
19
|
+
while (index < listeners.length && listeners[index] !== undefined)
|
|
20
|
+
index += 2;
|
|
21
|
+
if (index === listeners.length)
|
|
22
|
+
listeners.push(id, fn);
|
|
23
|
+
else {
|
|
24
|
+
listeners[index] = id;
|
|
25
|
+
listeners[index + 1] = fn;
|
|
26
|
+
}
|
|
27
|
+
runtime.latestListenerId = id;
|
|
28
|
+
return Result.success(id);
|
|
29
|
+
}
|
|
30
|
+
export function notifyChannel(channel, ...args) {
|
|
31
|
+
if (!runtime.managed.has(channel))
|
|
32
|
+
return;
|
|
33
|
+
const listeners = runtime.channelListeners.get(channel);
|
|
34
|
+
if (listeners === undefined)
|
|
35
|
+
throw new Error('Bridge channel is missing its listener list.');
|
|
36
|
+
const latestListenerIdAtStart = runtime.latestListenerId;
|
|
37
|
+
const listenerCount = listeners.length;
|
|
38
|
+
for (let index = 0; index < listenerCount; index += 2) {
|
|
39
|
+
if (!runtime.managed.has(channel))
|
|
40
|
+
return;
|
|
41
|
+
const id = listeners[index];
|
|
42
|
+
if (typeof id !== 'number' || (latestListenerIdAtStart !== -1 && id > latestListenerIdAtStart))
|
|
43
|
+
continue;
|
|
44
|
+
const fn = listeners[index + 1];
|
|
45
|
+
if (typeof fn === 'function')
|
|
46
|
+
fn.apply(undefined, args);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
export function disposeChannel(channel) {
|
|
50
|
+
if (!runtime.managed.delete(channel))
|
|
51
|
+
return;
|
|
52
|
+
const listeners = runtime.channelListeners.get(channel);
|
|
53
|
+
if (listeners !== undefined)
|
|
54
|
+
listeners.length = 0;
|
|
55
|
+
runtime.channelListeners.delete(channel);
|
|
56
|
+
}
|
|
57
|
+
export function disposeListener(channel, listener) {
|
|
58
|
+
if (!runtime.managed.has(channel))
|
|
59
|
+
return;
|
|
60
|
+
if (!Identity.Identifier.validate(ListenerFamily, listener))
|
|
61
|
+
return;
|
|
62
|
+
const listeners = runtime.channelListeners.get(channel);
|
|
63
|
+
if (listeners === undefined)
|
|
64
|
+
throw new Error('Bridge channel is missing its listener list.');
|
|
65
|
+
for (let index = 0; index < listeners.length; index += 2) {
|
|
66
|
+
if (listeners[index] !== listener)
|
|
67
|
+
continue;
|
|
68
|
+
delete listeners[index];
|
|
69
|
+
delete listeners[index + 1];
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
export function dispose(channel, listener) {
|
|
74
|
+
if (listener === undefined) {
|
|
75
|
+
disposeChannel(channel);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
disposeListener(channel, listener);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=functions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"functions.js","sourceRoot":"","sources":["../../../source/libraries/events/functions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAE9C,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAC5D,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAA;AAEpD,MAAM,UAAU,aAAa;IACzB,MAAM,EAAE,GAAG,QAAQ,CAAC,UAAU,CAAC,MAAM,CAAiC,aAAa,CAAC,CAAA;IAEpF,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,EAAgC,CAAC,CAAA;IACrD,OAAO,CAAC,gBAAgB,CAAC,GAAG,CAAC,EAAgC,EAAE,EAAE,CAAC,CAAA;IAElE,OAAO,EAAE,CAAA;AACb,CAAC;AAED,MAAM,UAAU,aAAa,CAAmC,OAA4B,EAAE,EAAY;IACtG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,OAAqC,CAAC;QAC3D,OAAO,MAAM,CAAC,IAAI,EAAE,CAAA;IAExB,MAAM,EAAE,GAAG,QAAQ,CAAC,UAAU,CAAC,MAAM,CAAC,cAAc,CAAC,CAAA;IACrD,MAAM,SAAS,GAAG,OAAO,CAAC,gBAAgB,CAAC,GAAG,CAAC,OAAqC,CAAC,CAAA;IACrF,IAAI,SAAS,KAAK,SAAS;QACvB,OAAO,MAAM,CAAC,IAAI,EAAE,CAAA;IAExB,IAAI,KAAK,GAAG,CAAC,CAAA;IACb,OAAO,KAAK,GAAG,SAAS,CAAC,MAAM,IAAI,SAAS,CAAC,KAAK,CAAC,KAAK,SAAS;QAC7D,KAAK,IA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,CAAA;IAC3B,CAAC;SAAM,CAAC;QACJ,eAAe,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAA;IACtC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../source/libraries/events/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AACrC,cAAc,YAAY,CAAA;AAC1B,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Runtime } from './types.js';
|
|
2
|
+
export declare const ChannelFamily: import("@blankways/identity").Family<"@blankways/bridge(channel)">;
|
|
3
|
+
export declare const ListenerFamily: import("@blankways/identity").Family<"@blankways/bridge(listener)">;
|
|
4
|
+
export declare const runtime: Runtime;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Identity } from '@blankways/identity';
|
|
2
|
+
export const ChannelFamily = Identity.Family.create();
|
|
3
|
+
export const ListenerFamily = Identity.Family.create();
|
|
4
|
+
export const runtime = {
|
|
5
|
+
managed: new Set(),
|
|
6
|
+
channelListeners: new Map(),
|
|
7
|
+
latestListenerId: -1,
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../../../source/libraries/events/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAG9C,MAAM,CAAC,MAAM,aAAa,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAgC,CAAA;AACnF,MAAM,CAAC,MAAM,cAAc,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAiC,CAAA;AAErF,MAAM,CAAC,MAAM,OAAO,GAAY;IAC5B,OAAO,EAAE,IAAI,GAAG,EAAE;IAClB,gBAAgB,EAAE,IAAI,GAAG,EAAE;IAC3B,gBAAgB,EAAE,CAAC,CAAC;CACvB,CAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Identifier } from '@blankways/identity';
|
|
2
|
+
import type { ChannelFamily, ListenerFamily } from './runtime.js';
|
|
3
|
+
export type UnknownFunction = (...args: never[]) => unknown;
|
|
4
|
+
export type ChannelId<Function extends UnknownFunction> = Identifier<typeof ChannelFamily, Function>;
|
|
5
|
+
export type ListenerId = Identifier<typeof ListenerFamily>;
|
|
6
|
+
export interface Runtime {
|
|
7
|
+
readonly managed: Set<ChannelId<UnknownFunction>>;
|
|
8
|
+
readonly channelListeners: Map<ChannelId<UnknownFunction>, (ListenerId | UnknownFunction | undefined)[]>;
|
|
9
|
+
latestListenerId: ListenerId | -1;
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../source/libraries/events/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"classes.js","sourceRoot":"","sources":["../../../source/libraries/result/classes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAE9C,MAAM,OAAO,MAAM;IACf,MAAM,CAAU,OAAO,GAAG,OAAO,CAAA;IACjC,MAAM,CAAU,IAAI,GAAG,IAAI,CAAA;CAC9B"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
const EMPTY_SUCCESS = Object.freeze({});
|
|
2
|
+
const EMPTY_FAIL = Object.freeze({ error: true });
|
|
3
|
+
export function success(value) {
|
|
4
|
+
return (value === undefined ? EMPTY_SUCCESS : { value });
|
|
5
|
+
}
|
|
6
|
+
export function fail(info) {
|
|
7
|
+
return (info === undefined ? EMPTY_FAIL : { error: true, info });
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=functions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"functions.js","sourceRoot":"","sources":["../../../source/libraries/result/functions.ts"],"names":[],"mappings":"AAEA,MAAM,aAAa,GAAmB,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;AACvD,MAAM,UAAU,GAAgB,MAAM,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAA;AAE9D,MAAM,UAAU,OAAO,CAAe,KAAY;IAC9C,OAAO,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAA6B,CAAA;AACxF,CAAC;AAED,MAAM,UAAU,IAAI,CAAe,IAAW;IAC1C,OAAO,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,CAA0B,CAAA;AAC7F,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Result as ResultValue } from './classes.js';
|
|
2
|
+
import type { Result as ResultType } from './types.js';
|
|
3
|
+
export declare const Result: typeof ResultValue;
|
|
4
|
+
export type Result<Type = never, Info = never> = ResultType<Type, Info>;
|
|
5
|
+
export * from './classes.js';
|
|
6
|
+
export * from './types.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../source/libraries/result/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,WAAW,EAAE,MAAM,cAAc,CAAA;AAGpD,MAAM,CAAC,MAAM,MAAM,GAAG,WAAW,CAAA;AAGjC,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type Success<Type = never> = [Type] extends [never] ? {
|
|
2
|
+
value?: never;
|
|
3
|
+
error?: never;
|
|
4
|
+
info?: never;
|
|
5
|
+
} : {
|
|
6
|
+
value: Type;
|
|
7
|
+
error?: never;
|
|
8
|
+
info?: never;
|
|
9
|
+
};
|
|
10
|
+
export type Fail<Info = never> = {
|
|
11
|
+
value?: never;
|
|
12
|
+
error: true;
|
|
13
|
+
info?: Info;
|
|
14
|
+
};
|
|
15
|
+
export type Result<Type = never, Info = never> = Success<Type> | Fail<Info>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../source/libraries/result/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type PacketEntry, type Schema, type SchemaEntry } from '@blankways/serial';
|
|
2
|
+
import type { PeerId, PointerId, RequestId } from '../types/common.js';
|
|
3
|
+
import type { SchemaPointer } from '../types/pointers/schema.js';
|
|
4
|
+
import type { RemoteRuntime } from './context.js';
|
|
5
|
+
export declare function readPacket(schema: Schema, packet: ArrayBuffer): PacketEntry;
|
|
6
|
+
export declare function connectTransport(runtime: RemoteRuntime): void;
|
|
7
|
+
export declare function registerRemoteCallPointer(runtime: RemoteRuntime, pointer: PointerId<unknown>, entrySchema: SchemaPointer<SchemaEntry>, resultSchemas: readonly PointerId<unknown>[]): void;
|
|
8
|
+
export declare function respondInternal(runtime: RemoteRuntime, peer: PeerId | undefined, requestId: RequestId, pointer: PointerId<unknown>, id: SchemaPointer<SchemaEntry>, info: string): void;
|
|
9
|
+
export declare function registerDispatch(runtime: RemoteRuntime): void;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { Serial } from '@blankways/serial';
|
|
2
|
+
import { Events } from '../libraries/events/index.js';
|
|
3
|
+
import { isInternalSchema } from './prefabs.js';
|
|
4
|
+
import { HeaderSchema, CallHeaderSchema, CALL_PACKET } from './schemas.js';
|
|
5
|
+
export function readPacket(schema, packet) {
|
|
6
|
+
const fields = Object.keys(schema);
|
|
7
|
+
const values = Serial.get(schema, packet, fields);
|
|
8
|
+
const entry = {};
|
|
9
|
+
for (let index = 0; index < fields.length; index += 1)
|
|
10
|
+
entry[fields[index]] = values[index];
|
|
11
|
+
return entry;
|
|
12
|
+
}
|
|
13
|
+
export function connectTransport(runtime) {
|
|
14
|
+
runtime.connected = true;
|
|
15
|
+
}
|
|
16
|
+
export function registerRemoteCallPointer(runtime, pointer, entrySchema, resultSchemas) {
|
|
17
|
+
runtime.callPointers.add(pointer);
|
|
18
|
+
runtime.callEntrySchemas[pointer] = entrySchema;
|
|
19
|
+
runtime.callResultSchemas.set(pointer, new Set(resultSchemas));
|
|
20
|
+
}
|
|
21
|
+
export function respondInternal(runtime, peer, requestId, pointer, id, info) {
|
|
22
|
+
if (peer === undefined)
|
|
23
|
+
return;
|
|
24
|
+
const schema = runtime.schemas.get(id);
|
|
25
|
+
if (!schema)
|
|
26
|
+
return;
|
|
27
|
+
let packet;
|
|
28
|
+
try {
|
|
29
|
+
packet = Serial.packet(schema, {
|
|
30
|
+
id,
|
|
31
|
+
requestId,
|
|
32
|
+
type: CALL_PACKET.response,
|
|
33
|
+
pointer,
|
|
34
|
+
info
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
runtime.outboundResponses.add(requestId);
|
|
41
|
+
// Deferred to avoid the transport echo guard while dispatching an inbound packet.
|
|
42
|
+
void Promise.resolve().then(() => Events.to(runtime.rootChannel, peer, packet));
|
|
43
|
+
}
|
|
44
|
+
export function registerDispatch(runtime) {
|
|
45
|
+
Events.from(runtime.rootChannel, (peer, packet) => {
|
|
46
|
+
const id = Serial.get(HeaderSchema, packet, HeaderSchema.id);
|
|
47
|
+
if (!runtime.schemas.has(id))
|
|
48
|
+
return;
|
|
49
|
+
let header;
|
|
50
|
+
try {
|
|
51
|
+
header = Serial.get(CallHeaderSchema, packet, [
|
|
52
|
+
CallHeaderSchema.requestId,
|
|
53
|
+
CallHeaderSchema.type,
|
|
54
|
+
CallHeaderSchema.pointer
|
|
55
|
+
]);
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const [requestId, type, pointer] = header;
|
|
61
|
+
if (!runtime.callPointers.has(pointer))
|
|
62
|
+
return;
|
|
63
|
+
if (type === CALL_PACKET.request) {
|
|
64
|
+
if (runtime.outboundRequests.delete(requestId))
|
|
65
|
+
return;
|
|
66
|
+
if (isInternalSchema(runtime, id)) {
|
|
67
|
+
const errorHandler = runtime.callErrorHandlers.get(pointer);
|
|
68
|
+
const schema = runtime.schemas.get(id);
|
|
69
|
+
if (errorHandler && schema) {
|
|
70
|
+
try {
|
|
71
|
+
errorHandler(readPacket(schema, packet));
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
// The registered error handler must not break the dispatch loop.
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const channel = runtime.callChannels.get(pointer);
|
|
80
|
+
const schemaPointer = runtime.callEntrySchemas[pointer];
|
|
81
|
+
const schema = schemaPointer === undefined ? undefined : runtime.schemas.get(schemaPointer);
|
|
82
|
+
if (!channel || !schema)
|
|
83
|
+
return;
|
|
84
|
+
let entry;
|
|
85
|
+
try {
|
|
86
|
+
entry = readPacket(schema, packet);
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
respondInternal(runtime, peer, requestId, pointer, runtime.InvalidInput, 'invalid input packet');
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
Events.to(channel, peer, entry, requestId);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
if (type === CALL_PACKET.response) {
|
|
96
|
+
if (runtime.outboundResponses.delete(requestId))
|
|
97
|
+
return;
|
|
98
|
+
const resolver = runtime.pendingCalls.get(requestId);
|
|
99
|
+
const allowed = runtime.callResultSchemas.get(pointer);
|
|
100
|
+
if (!resolver || !runtime.schemas.has(id))
|
|
101
|
+
return;
|
|
102
|
+
if (!isInternalSchema(runtime, id) && allowed && !allowed.has(id))
|
|
103
|
+
return;
|
|
104
|
+
const schema = runtime.schemas.get(id);
|
|
105
|
+
let entry;
|
|
106
|
+
try {
|
|
107
|
+
entry = readPacket(schema, packet);
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
runtime.pendingCalls.delete(requestId);
|
|
113
|
+
resolver(entry);
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=common.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../source/runtime/common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAmD,MAAM,mBAAmB,CAAA;AAC3F,OAAO,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAA;AAKpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAC/C,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAE1E,MAAM,UAAU,UAAU,CAAC,MAAc,EAAE,MAAmB;IAC1D,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IAClC,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAA;IACjD,MAAM,KAAK,GAA4B,EAAE,CAAA;IAEzC,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,IAAI,CAAC;QACjD,KAAK,CAAC,MAAM,CAAC,KAAK,CAAE,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAA;IAEzC,OAAO,KAAoB,CAAA;AAC/B,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,OAAsB;IACnD,OAAO,CAAC,SAAS,GAAG,IAAI,CAAA;AAC5B,CAAC;AAED,MAAM,UAAU,yBAAyB,CACrC,OAAsB,EACtB,OAA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,IAAI,CAAC;gBACD,KAAK,GAAG,UAAU,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;YACtC,CAAC;YAAC,MAAM,CAAC;gBACL,OAAM;YACV,CAAC;YAED,OAAO,CAAC,YAAY,CAAC,MAAM,CAAC,SAAsB,CAAC,CAAA;YACnD,QAAQ,CAAC,KAAK,CAAC,CAAA;QACnB,CAAC;IACL,CAAC,CAAC,CAAA;AACN,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Serial, type Schema, type SchemaEntry } from '@blankways/serial';
|
|
2
|
+
import type { ChannelId } from '../libraries/events/types.js';
|
|
3
|
+
import type { PeerId, PointerFamilyType, PointerId, RequestFamilyType, RequestId } from '../types/common.js';
|
|
4
|
+
import type { ErrorHandler, InternalSchema } from '../types/errors.js';
|
|
5
|
+
import type { ResourcePointer, ResourceTypes } from '../types/pointers/resource.js';
|
|
6
|
+
import type { CallListener, CallResolver } from '../types/pointers/call.js';
|
|
7
|
+
import type { AnyTypeDefinition, SchemaPointer } from '../types/pointers/schema.js';
|
|
8
|
+
export type CallSchema = SchemaPointer<{
|
|
9
|
+
[Key in string]: AnyTypeDefinition;
|
|
10
|
+
} & {
|
|
11
|
+
id: typeof Serial.u32;
|
|
12
|
+
}>;
|
|
13
|
+
export type ResourceSchemas = {
|
|
14
|
+
entry: CallSchema;
|
|
15
|
+
result: CallSchema;
|
|
16
|
+
};
|
|
17
|
+
export type RemoteRuntime = {
|
|
18
|
+
PointerFamily: PointerFamilyType;
|
|
19
|
+
RequestFamily: RequestFamilyType;
|
|
20
|
+
rootChannel: ChannelId<(peer: PeerId, data: ArrayBuffer) => void>;
|
|
21
|
+
connected: boolean;
|
|
22
|
+
schemas: Map<SchemaPointer<SchemaEntry>, Schema>;
|
|
23
|
+
callPointers: Set<PointerId<unknown>>;
|
|
24
|
+
callEntrySchemas: unknown[];
|
|
25
|
+
callResultSchemas: Map<PointerId<unknown>, Set<PointerId<unknown>>>;
|
|
26
|
+
callChannels: Map<PointerId<unknown>, ChannelId<CallListener>>;
|
|
27
|
+
callErrorHandlers: Map<PointerId<unknown>, ErrorHandler>;
|
|
28
|
+
pendingCalls: Map<RequestId, CallResolver>;
|
|
29
|
+
outboundRequests: Set<RequestId>;
|
|
30
|
+
outboundResponses: Set<RequestId>;
|
|
31
|
+
InvalidInput: InternalSchema;
|
|
32
|
+
InvalidOutput: InternalSchema;
|
|
33
|
+
InterruptedCommunication: InternalSchema;
|
|
34
|
+
INTERNAL_SCHEMAS: readonly InternalSchema[];
|
|
35
|
+
internalSet: Set<unknown>;
|
|
36
|
+
resourceDefaults: Map<ResourcePointer, ResourceTypes>;
|
|
37
|
+
resourceSchemas: Map<ResourcePointer, ResourceSchemas>;
|
|
38
|
+
resourceSubscribers: Map<ResourcePointer, Map<PeerId, PointerId<unknown>>>;
|
|
39
|
+
};
|
|
40
|
+
export declare function createRuntime(): RemoteRuntime;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Identity } from '@blankways/identity';
|
|
2
|
+
import { Events } from '../libraries/events/index.js';
|
|
3
|
+
import { registerDispatch } from './common.js';
|
|
4
|
+
import { createInternalSchemas } from './prefabs.js';
|
|
5
|
+
export function createRuntime() {
|
|
6
|
+
const runtime = {
|
|
7
|
+
PointerFamily: Identity.Family.create(),
|
|
8
|
+
RequestFamily: Identity.Family.create(),
|
|
9
|
+
rootChannel: Events.channel(),
|
|
10
|
+
connected: false,
|
|
11
|
+
schemas: new Map(),
|
|
12
|
+
callPointers: new Set(),
|
|
13
|
+
callEntrySchemas: [],
|
|
14
|
+
callResultSchemas: new Map(),
|
|
15
|
+
callChannels: new Map(),
|
|
16
|
+
callErrorHandlers: new Map(),
|
|
17
|
+
pendingCalls: new Map(),
|
|
18
|
+
outboundRequests: new Set(),
|
|
19
|
+
outboundResponses: new Set(),
|
|
20
|
+
InvalidInput: undefined,
|
|
21
|
+
InvalidOutput: undefined,
|
|
22
|
+
InterruptedCommunication: undefined,
|
|
23
|
+
INTERNAL_SCHEMAS: [],
|
|
24
|
+
internalSet: new Set(),
|
|
25
|
+
resourceDefaults: new Map(),
|
|
26
|
+
resourceSchemas: new Map(),
|
|
27
|
+
resourceSubscribers: new Map()
|
|
28
|
+
};
|
|
29
|
+
createInternalSchemas(runtime);
|
|
30
|
+
registerDispatch(runtime);
|
|
31
|
+
return runtime;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../source/runtime/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAE9C,OAAO,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAA;AAOpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAA;AAiCpD,MAAM,UAAU,aAAa;IACzB,MAAM,OAAO,GAAkB;QAC3B,aAAa,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAc;QACnD,aAAa,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAc;QACnD,WAAW,EAAE,MAAM,CAAC,OAAO,EAA6C;QACxE,SAAS,EAAE,KAAK;QAChB,OAAO,EAAE,IAAI,GAAG,EAAE;QAClB,YAAY,EAAE,IAAI,GAAG,EAAE;QACvB,gBAAgB,EAAE,EAAE;QACpB,iBAAiB,EAAE,IAAI,GAAG,EAAE;QAC5B,YAAY,EAAE,IAAI,GAAG,EAAE;QACvB,iBAAiB,EAAE,IAAI,GAAG,EAAE;QAC5B,YAAY,EAAE,IAAI,GAAG,EAAE;QACvB,gBAAgB,EAAE,IAAI,GAAG,EAAE;QAC3B,iBAAiB,EAAE,IAAI,GAAG,EAAE;QAC5B,YAAY,EAAE,SAAsC;QACpD,aAAa,EAAE,SAAsC;QACrD,wBAAwB,EAAE,SAAsC;QAChE,gBAAgB,EAAE,EAAE;QACpB,WAAW,EAAE,IAAI,GAAG,EAAE;QACtB,gBAAgB,EAAE,IAAI,GAAG,EAAE;QAC3B,eAAe,EAAE,IAAI,GAAG,EAAE;QAC1B,mBAAmB,EAAE,IAAI,GAAG,EAAE;KACjC,CAAA;IAED,qBAAqB,CAAC,OAAO,CAAC,CAAA;IAC9B,gBAAgB,CAAC,OAAO,CAAC,CAAA;IAEzB,OAAO,OAAO,CAAA;AAClB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/runtime/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { InternalErrorPacket, InternalSchema } from '../types/errors.js';
|
|
2
|
+
import type { RemoteRuntime } from './context.js';
|
|
3
|
+
export declare function createInternalSchemas(runtime: RemoteRuntime): void;
|
|
4
|
+
export declare function isInternalSchema(runtime: RemoteRuntime, id: unknown): id is InternalSchema;
|
|
5
|
+
export declare function internalPacket<Schema extends InternalSchema>(id: Schema, info: string): InternalErrorPacket;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Identity } from '@blankways/identity';
|
|
2
|
+
import { Serial } from '@blankways/serial';
|
|
3
|
+
import { CALL_PACKET } from './schemas.js';
|
|
4
|
+
function createInternalSchema(runtime, entry) {
|
|
5
|
+
const id = Identity.Identifier.create(runtime.PointerFamily);
|
|
6
|
+
runtime.schemas.set(id, Serial.schema({
|
|
7
|
+
id: Serial.u32,
|
|
8
|
+
requestId: Serial.u32,
|
|
9
|
+
type: Serial.u8,
|
|
10
|
+
pointer: Serial.u32,
|
|
11
|
+
...entry
|
|
12
|
+
}));
|
|
13
|
+
return id;
|
|
14
|
+
}
|
|
15
|
+
export function createInternalSchemas(runtime) {
|
|
16
|
+
runtime.InvalidInput = createInternalSchema(runtime, { info: Serial.string });
|
|
17
|
+
runtime.InvalidOutput = createInternalSchema(runtime, { info: Serial.string });
|
|
18
|
+
runtime.InterruptedCommunication = createInternalSchema(runtime, { info: Serial.string });
|
|
19
|
+
runtime.INTERNAL_SCHEMAS = [runtime.InvalidInput, runtime.InvalidOutput, runtime.InterruptedCommunication];
|
|
20
|
+
runtime.internalSet = new Set(runtime.INTERNAL_SCHEMAS);
|
|
21
|
+
}
|
|
22
|
+
export function isInternalSchema(runtime, id) {
|
|
23
|
+
return runtime.internalSet.has(id);
|
|
24
|
+
}
|
|
25
|
+
export function internalPacket(id, info) {
|
|
26
|
+
return {
|
|
27
|
+
id,
|
|
28
|
+
requestId: 0,
|
|
29
|
+
type: CALL_PACKET.response,
|
|
30
|
+
pointer: 0,
|
|
31
|
+
info
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=prefabs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prefabs.js","sourceRoot":"","sources":["../../source/runtime/prefabs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAC9C,OAAO,EAAE,MAAM,EAAsC,MAAM,mBAAmB,CAAA;AAK9E,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAE1C,SAAS,oBAAoB,CAAkC,OAAsB,EAAE,KAAY;IAC/F,MAAM,EAAE,GAAG,QAAQ,CAAC,UAAU,CAAC,MAAM,CAAuD,OAAO,CAAC,aAAa,CAAC,CAAA;IAElH,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,EAAgC,EAAE,MAAM,CAAC,MAAM,CAAC;QAChE,EAAE,EAAE,MAAM,CAAC,GAAG;QACd,SAAS,EAAE,MAAM,CAAC,GAAG;QACrB,IAAI,EAAE,MAAM,CAAC,EAAE;QACf,OAAO,EAAE,MAAM,CAAC,GAAG;QACnB,GAAG,KAAK;KACX,CAAC,CAAC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
|
|
|
1
|
+
export declare const HeaderSchema: import("@blankways/serial").Schema<{
|
|
2
|
+
id: import("@blankways/serial").TypeDefinition<number>;
|
|
3
|
+
}>;
|
|
4
|
+
export declare const CallHeaderSchema: import("@blankways/serial").Schema<{
|
|
5
|
+
id: import("@blankways/serial").TypeDefinition<number>;
|
|
6
|
+
requestId: import("@blankways/serial").TypeDefinition<number>;
|
|
7
|
+
type: import("@blankways/serial").TypeDefinition<number>;
|
|
8
|
+
pointer: import("@blankways/serial").TypeDefinition<number>;
|
|
9
|
+
}>;
|
|
10
|
+
export declare const CALL_PACKET: Readonly<{
|
|
11
|
+
request: 0;
|
|
12
|
+
response: 1;
|
|
13
|
+
}>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Serial } from '@blankways/serial';
|
|
2
|
+
export const HeaderSchema = Serial.schema({
|
|
3
|
+
id: Serial.u32
|
|
4
|
+
});
|
|
5
|
+
export const CallHeaderSchema = Serial.schema({
|
|
6
|
+
id: Serial.u32,
|
|
7
|
+
requestId: Serial.u32,
|
|
8
|
+
type: Serial.u8,
|
|
9
|
+
pointer: Serial.u32
|
|
10
|
+
});
|
|
11
|
+
export const CALL_PACKET = Object.freeze({
|
|
12
|
+
request: 0,
|
|
13
|
+
response: 1
|
|
14
|
+
});
|
|
15
|
+
//# sourceMappingURL=schemas.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemas.js","sourceRoot":"","sources":["../../source/runtime/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAE1C,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC;IACtC,EAAE,EAAE,MAAM,CAAC,GAAG;CACjB,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,CAAC;IAC1C,EAAE,EAAE,MAAM,CAAC,GAAG;IACd,SAAS,EAAE,MAAM,CAAC,GAAG;IACrB,IAAI,EAAE,MAAM,CAAC,EAAE;IACf,OAAO,EAAE,MAAM,CAAC,GAAG;CACtB,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC;IACrC,OAAO,EAAE,CAAC;IACV,QAAQ,EAAE,CAAC;CACd,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const PeerFamily: import("@blankways/identity").Family<"@blankways/remote(peer)">;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport.js","sourceRoot":"","sources":["../../source/runtime/transport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAG9C,MAAM,CAAC,MAAM,UAAU,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAW,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Family, Identifier } from '@blankways/identity';
|
|
2
|
+
export * from './pointers/index.js';
|
|
3
|
+
export type PointerTag = '@blankways/remote(pointer)';
|
|
4
|
+
export type PointerFamilyType = Family<PointerTag>;
|
|
5
|
+
export type PointerId<Type> = Identifier<PointerFamilyType, Type>;
|
|
6
|
+
export type PeerTag = '@blankways/remote(peer)';
|
|
7
|
+
export type PeerFamilyType = Family<PeerTag>;
|
|
8
|
+
export type PeerId = Identifier<PeerFamilyType>;
|
|
9
|
+
export type RequestTag = '@blankways/remote(request)';
|
|
10
|
+
export type RequestFamilyType = Family<RequestTag>;
|
|
11
|
+
export type RequestId = Identifier<RequestFamilyType>;
|
|
12
|
+
export type InFn = (callback: (peer: PeerId, data: ArrayBuffer) => void) => void;
|
|
13
|
+
export type OutFn = (peer: PeerId, data: ArrayBuffer) => void;
|
|
14
|
+
export type Transport = [InFn, OutFn];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../source/types/common.ts"],"names":[],"mappings":"AAEA,cAAc,qBAAqB,CAAA"}
|