@antcde/connect-ts 0.4.18-rc.6a3e1ae → 0.4.18-rc.77e4e54
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/build/comms/client.d.ts +9 -12
- package/build/comms/client.d.ts.map +1 -1
- package/build/comms/client.js +67 -158
- package/build/comms/compat.d.ts +18 -0
- package/build/comms/compat.d.ts.map +1 -0
- package/build/comms/compat.js +80 -0
- package/build/comms/host.d.ts +5 -18
- package/build/comms/host.d.ts.map +1 -1
- package/build/comms/host.js +88 -161
- package/build/comms/hostAPI.d.ts +48 -0
- package/build/comms/hostAPI.d.ts.map +1 -0
- package/build/comms/hostAPI.js +47 -0
- package/build/comms/python-schema.d.ts +4 -0
- package/build/comms/python-schema.d.ts.map +1 -0
- package/build/comms/python-schema.js +4 -0
- package/build/comms/signal.d.ts +5 -321
- package/build/comms/signal.d.ts.map +1 -1
- package/build/comms/signal.js +5 -9
- package/build/comms/signalChangeTypes.d.ts +47 -0
- package/build/comms/signalChangeTypes.d.ts.map +1 -0
- package/build/comms/signalChangeTypes.js +1 -0
- package/build/comms/signalTypes.d.ts +262 -0
- package/build/comms/signalTypes.d.ts.map +1 -0
- package/build/comms/signalTypes.js +6 -0
- package/build/comms/transport.d.ts +16 -0
- package/build/comms/transport.d.ts.map +1 -0
- package/build/comms/transport.js +51 -0
- package/build/comms/utils.d.ts +3 -35
- package/build/comms/utils.d.ts.map +1 -1
- package/build/comms/utils.js +6 -79
- package/build/index.d.ts +3 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +3 -1
- package/build/utils.d.ts +2 -0
- package/build/utils.d.ts.map +1 -0
- package/build/utils.js +6 -0
- package/package.json +7 -3
package/build/comms/client.d.ts
CHANGED
|
@@ -1,24 +1,23 @@
|
|
|
1
1
|
import type { AxiosRequestConfig } from 'axios';
|
|
2
2
|
import type { Observable } from 'rxjs';
|
|
3
|
-
import type { AppManifest } from "../services/AppService";
|
|
4
3
|
import type { Context, Notepad, Notifications, Toolbar } from './models';
|
|
5
4
|
import type { SignalReceiver, SignalSender } from './signal';
|
|
6
|
-
import type { Scope } from './utils';
|
|
7
5
|
import type { AntConnect } from "../AntConnect";
|
|
6
|
+
import type { AppManifest } from "../services/AppService";
|
|
8
7
|
import { Subscription } from 'rxjs';
|
|
8
|
+
type AxiosRequestProps = ['url', 'method', 'headers', 'params', 'data'];
|
|
9
|
+
export type AxiosRequest<T = any> = Pick<AxiosRequestConfig<T>, AxiosRequestProps[number]>;
|
|
9
10
|
export interface ClientParams {
|
|
10
11
|
parent: Window;
|
|
11
12
|
connect?: AntConnect;
|
|
12
|
-
/** Optional app manifest (app-config.json) sent to the host during handshake. */
|
|
13
13
|
manifest?: AppManifest;
|
|
14
|
+
/** Pre-established connection for nested iframe clients (e.g. Streamlit). Pass `port` for Comlink transport. */
|
|
15
|
+
initialConnection?: {
|
|
16
|
+
clientId: string;
|
|
17
|
+
context: Context;
|
|
18
|
+
port?: MessagePort;
|
|
19
|
+
};
|
|
14
20
|
}
|
|
15
|
-
interface Box {
|
|
16
|
-
clientIdChanges: Observable<string>;
|
|
17
|
-
scope: Scope;
|
|
18
|
-
parent: Window;
|
|
19
|
-
}
|
|
20
|
-
type AxiosRequestProps = ['url', 'method', 'headers', 'params', 'data'];
|
|
21
|
-
export type AxiosRequest<T> = Pick<AxiosRequestConfig<T>, AxiosRequestProps[number]>;
|
|
22
21
|
export interface Client extends Subscription {
|
|
23
22
|
notepad: Notepad;
|
|
24
23
|
notifications: Notifications;
|
|
@@ -36,7 +35,5 @@ export interface Client extends Subscription {
|
|
|
36
35
|
request: <T, R>(request: AxiosRequest<T>, controller?: AbortController) => Promise<R>;
|
|
37
36
|
}
|
|
38
37
|
export declare function newCommsClient(params: ClientParams): Client;
|
|
39
|
-
export declare function newNotepad({ scope, parent, clientIdChanges }: Box): Notepad;
|
|
40
|
-
export declare function newNotifications({ parent, scope, clientIdChanges }: Box): Notifications;
|
|
41
38
|
export {};
|
|
42
39
|
//# sourceMappingURL=client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/comms/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAA;AAC/C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/comms/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAA;AAC/C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,MAAM,CAAA;AAEtC,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AACxE,OAAO,KAAK,EAAU,cAAc,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAEpE,OAAO,KAAK,EAAE,UAAU,EAAE,sBAAoB;AAC9C,OAAO,KAAK,EAAE,WAAW,EAAE,+BAA6B;AAExD,OAAO,EAML,YAAY,EACb,MAAM,MAAM,CAAA;AAMb,KAAK,iBAAiB,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAA;AACvE,MAAM,MAAM,YAAY,CAAC,CAAC,GAAG,GAAG,IAAI,IAAI,CAAC,kBAAkB,CAAC,CAAC,CAAC,EAAE,iBAAiB,CAAC,MAAM,CAAC,CAAC,CAAA;AAE1F,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,UAAU,CAAA;IACpB,QAAQ,CAAC,EAAE,WAAW,CAAA;IACtB,gHAAgH;IAChH,iBAAiB,CAAC,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,OAAO,CAAC;QAAC,IAAI,CAAC,EAAE,WAAW,CAAA;KAAE,CAAA;CAC/E;AAED,MAAM,WAAW,MAAO,SAAQ,YAAY;IAC1C,OAAO,EAAE,OAAO,CAAA;IAChB,aAAa,EAAE,aAAa,CAAA;IAC5B,OAAO,EAAE,UAAU,CAAA;IACnB,OAAO,EAAE,UAAU,CAAC,OAAO,CAAC,CAAA;IAC5B,OAAO,EAAE,UAAU,CAAC,OAAO,CAAC,GAAG;QAC7B,GAAG,EAAE,CAAC,KAAK,EAAE,OAAO,GAAG,CAAC,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,GAAG,OAAO,CAAC,KAAK,IAAI,CAAA;QACpE,GAAG,EAAE,MAAM,OAAO,CAAA;KACnB,CAAA;IACD,QAAQ,EAAE,UAAU,CAAC,MAAM,CAAC,GAAG;QAC7B,GAAG,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAA;QAC1B,GAAG,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;KACtC,CAAA;IACD,MAAM,EAAE,YAAY,GAAG,cAAc,CAAA;IACrC,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,EAAE,eAAe,KAAK,OAAO,CAAC,CAAC,CAAC,CAAA;CACtF;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM,CA+F3D"}
|
package/build/comms/client.js
CHANGED
|
@@ -1,171 +1,80 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { BehaviorSubject,
|
|
1
|
+
import * as Comlink from 'comlink';
|
|
2
|
+
import { BehaviorSubject, distinctUntilChanged, map, shareReplay, Subject, Subscription, } from 'rxjs';
|
|
3
3
|
import { notificationTypes } from './models';
|
|
4
4
|
import { newSignaler } from './signal';
|
|
5
|
-
import {
|
|
5
|
+
import { receivePort, requestPort } from './transport';
|
|
6
|
+
import { newScope, takeUntilClosed } from './utils';
|
|
6
7
|
export function newCommsClient(params) {
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
.
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
return Promise.resolve({ manifest: params.manifest }); // Return value becomes ACK
|
|
35
|
-
})
|
|
36
|
-
.subscribe();
|
|
37
|
-
const clientIdChanges = initData.asObservable().pipe(filter((data) => data !== null), map(data => data.clientId), shareReplay(1));
|
|
38
|
-
// Initial context from the ready response (avoids delay waiting for separate context message)
|
|
39
|
-
const initialContext = initData.asObservable().pipe(filter((data) => data !== null), map(data => data.context), shareReplay(1));
|
|
40
|
-
const box = {
|
|
41
|
-
clientIdChanges,
|
|
42
|
-
scope,
|
|
43
|
-
parent: params.parent,
|
|
8
|
+
const subscription = newScope();
|
|
9
|
+
const contextSubject = new BehaviorSubject(params.initialConnection?.context ?? {});
|
|
10
|
+
const toolbarSubject = new BehaviorSubject({ menu: [], search: { enabled: false, input: '' }, isLoading: false });
|
|
11
|
+
const appStateSubject = new BehaviorSubject({ timestamp: 0, state: '' });
|
|
12
|
+
const incomingSignals = new Subject();
|
|
13
|
+
let resolveProxy;
|
|
14
|
+
const proxyReady = new Promise((r) => { resolveProxy = r; });
|
|
15
|
+
const bootstrap = async () => {
|
|
16
|
+
const init = params.initialConnection?.port
|
|
17
|
+
? { port: params.initialConnection.port, context: params.initialConnection.context }
|
|
18
|
+
: await receivePort();
|
|
19
|
+
contextSubject.next(init.context);
|
|
20
|
+
const proxy = Comlink.wrap(init.port);
|
|
21
|
+
subscription.add(() => { init.port.close(); proxy[Comlink.releaseProxy](); });
|
|
22
|
+
await proxy.onContext(Comlink.proxy((ctx) => contextSubject.next(ctx)));
|
|
23
|
+
await proxy.onSignal(Comlink.proxy((signals) => {
|
|
24
|
+
incomingSignals.next({ data: signals, origin: '', source: null });
|
|
25
|
+
}));
|
|
26
|
+
await proxy.onAppState(Comlink.proxy((state) => appStateSubject.next(state)));
|
|
27
|
+
await proxy.onToolbarClick(Comlink.proxy((index) => toolbarSubject.value.menu[index]?.onClick?.()));
|
|
28
|
+
await proxy.onToolbarSearch(Comlink.proxy((value) => {
|
|
29
|
+
const t = toolbarSubject.value;
|
|
30
|
+
toolbarSubject.next({ ...t, search: { ...t.search, input: value ?? '' } });
|
|
31
|
+
}));
|
|
32
|
+
await proxy.ready(params.manifest ?? null);
|
|
33
|
+
resolveProxy(proxy);
|
|
44
34
|
};
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
appState: handleAppStateChanges(box),
|
|
52
|
-
signal: getSignal(box),
|
|
53
|
-
request: getRequest(box),
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
function handleAppStateChanges({ scope, clientIdChanges, parent }) {
|
|
57
|
-
const changes = clientIdChanges.pipe(switchMap(clientId => scope.on(`ant/${clientId}/state`)), map(e => e.data.state));
|
|
58
|
-
return Object.assign(changes, {
|
|
59
|
-
get: () => firstValueFrom(clientIdChanges.pipe(take(1), concatMap(clientId => scope.send(parent, `ant/${clientId}/state/get`, {}, { fireAndForget: false })), map(e => e.data.state))),
|
|
60
|
-
set: (state) => clientIdChanges
|
|
61
|
-
.pipe(take(1), concatMap(clientId => scope.send(parent, `ant/${clientId}/state`, { timestamp: Date.now(), state })))
|
|
62
|
-
.forEach(identity),
|
|
35
|
+
requestPort(params.parent);
|
|
36
|
+
bootstrap();
|
|
37
|
+
proxyReady.then(proxy => toolbarSubject.pipe(takeUntilClosed(subscription)).subscribe(t => proxy.setToolbar({ ...t, menu: t.menu.map(({ onClick, ...item }) => item) })));
|
|
38
|
+
const signal = newSignaler({
|
|
39
|
+
send: async (signals) => (await proxyReady).sendSignal(signals),
|
|
40
|
+
receiver: incomingSignals.asObservable(),
|
|
63
41
|
});
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
toolbar.next(value(toolbar.value));
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
toolbar.next(value);
|
|
73
|
-
}
|
|
42
|
+
const notepad = {
|
|
43
|
+
show: tab => proxyReady.then(p => p.notepad('show/tab', { tab })),
|
|
44
|
+
showTask: (task, select) => proxyReady.then(p => p.notepad('show/task', { task, select })),
|
|
45
|
+
hide: () => proxyReady.then(p => p.notepad('hide', {})),
|
|
46
|
+
selectSbs: item => proxyReady.then(p => p.notepad('sbs/select', { item })),
|
|
74
47
|
};
|
|
75
|
-
|
|
76
|
-
combineLatest([
|
|
77
|
-
toolbar.asObservable(),
|
|
78
|
-
clientIdChanges,
|
|
79
|
-
])
|
|
80
|
-
.pipe(tap(([toolbar, clientId]) => send(parent, `ant/${clientId}/toolbar`, { toolbar })), takeUntilClosed(scope))
|
|
81
|
-
.subscribe();
|
|
82
|
-
// Set up listeners once per clientId — NOT inside switchMap keyed on toolbar,
|
|
83
|
-
// which would tear down and recreate listeners on every toolbar change
|
|
84
|
-
clientIdChanges
|
|
85
|
-
.pipe(switchMap(clientId => merge(scope.on(`ant/${clientId}/toolbar/click`).pipe(tap(({ data }) => {
|
|
86
|
-
toolbar.value.menu[data.index]?.onClick?.();
|
|
87
|
-
})), scope.on(`ant/${clientId}/toolbar/search`).pipe(tap(({ data }) => {
|
|
88
|
-
set(t => ({ ...t, search: { ...t.search, input: data.value ?? '' } }));
|
|
89
|
-
})))), takeUntilClosed(scope))
|
|
90
|
-
.subscribe();
|
|
91
|
-
return Object.assign(toolbar.asObservable().pipe(takeUntilClosed(scope)), { set, get: () => toolbar.value });
|
|
92
|
-
}
|
|
93
|
-
export function newNotepad({ scope, parent, clientIdChanges }) {
|
|
94
|
-
const post = async (name, data) => {
|
|
95
|
-
clientIdChanges
|
|
96
|
-
.pipe(concatMap(clientId => scope.send(parent, `ant/${clientId}/notepad`, { name, data })))
|
|
97
|
-
.subscribe();
|
|
98
|
-
};
|
|
99
|
-
return {
|
|
100
|
-
show: tab => post('show/tab', { tab }),
|
|
101
|
-
showTask: (task, select) => post(`show/task`, { task, select }),
|
|
102
|
-
hide: () => post(`hide`, {}),
|
|
103
|
-
selectSbs: item => post(`sbs/select`, { item }),
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
export function newNotifications({ parent, scope, clientIdChanges }) {
|
|
107
|
-
return notificationTypes.reduce((result, type) => Object.assign(result, {
|
|
48
|
+
const notifications = notificationTypes.reduce((result, type) => Object.assign(result, {
|
|
108
49
|
[type]: (message) => {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
.forEach(identity);
|
|
50
|
+
const promise = proxyReady.then(p => p.notify({ type, message }));
|
|
51
|
+
return Object.assign(promise, new Subscription());
|
|
112
52
|
},
|
|
113
53
|
}), {});
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
get: (_, name) => {
|
|
131
|
-
if (typeof service === 'string' && typeof name === 'string') {
|
|
132
|
-
return (...args) => {
|
|
133
|
-
const observable = clientIdChanges.pipe(concatMap((clientId) => {
|
|
134
|
-
return scope.send(parent, `ant/${clientId}/connect`, {
|
|
135
|
-
service,
|
|
136
|
-
name,
|
|
137
|
-
args,
|
|
138
|
-
});
|
|
139
|
-
}));
|
|
140
|
-
return firstValueFrom(observable).then(({ data }) => data);
|
|
141
|
-
};
|
|
142
|
-
}
|
|
54
|
+
return Object.assign(subscription, {
|
|
55
|
+
notepad,
|
|
56
|
+
notifications,
|
|
57
|
+
connect: params.connect ?? new Proxy({}, {
|
|
58
|
+
get: (_, service) => new Proxy({}, {
|
|
59
|
+
get: (_, name) => typeof service === 'string' && typeof name === 'string'
|
|
60
|
+
? (...args) => proxyReady.then(p => p.connect(service, name, args))
|
|
61
|
+
: undefined,
|
|
62
|
+
}),
|
|
63
|
+
}),
|
|
64
|
+
context: contextSubject.asObservable().pipe(shareReplay(1)),
|
|
65
|
+
toolbar: Object.assign(toolbarSubject.asObservable().pipe(takeUntilClosed(subscription)), {
|
|
66
|
+
set: (value) => {
|
|
67
|
+
const result = typeof value === 'function' ? value(toolbarSubject.value) : value;
|
|
68
|
+
if (result)
|
|
69
|
+
toolbarSubject.next(result);
|
|
143
70
|
},
|
|
71
|
+
get: () => toolbarSubject.value,
|
|
144
72
|
}),
|
|
73
|
+
appState: Object.assign(appStateSubject.pipe(map(e => e.state), distinctUntilChanged()), {
|
|
74
|
+
get: () => proxyReady.then(p => p.getAppState()).then(s => s.state),
|
|
75
|
+
set: (state) => proxyReady.then(p => p.setAppState({ timestamp: Date.now(), state })).then(() => { }),
|
|
76
|
+
}),
|
|
77
|
+
signal,
|
|
78
|
+
request: (req, _controller) => proxyReady.then(p => p.request(req)),
|
|
145
79
|
});
|
|
146
80
|
}
|
|
147
|
-
function getSignal({ clientIdChanges, scope, parent }) {
|
|
148
|
-
return newSignaler({
|
|
149
|
-
send: (signals) => {
|
|
150
|
-
return firstValueFrom(clientIdChanges.pipe(take(1), concatMap(clientId => scope.send(parent, `ant/${clientId}/signal`, signals, { fireAndForget: false })), map(e => e.data)));
|
|
151
|
-
},
|
|
152
|
-
receiver: clientIdChanges.pipe(switchMap(clientId => scope.on(`ant/${clientId}/signal`)), share()),
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
function getRequest({ clientIdChanges, scope }) {
|
|
156
|
-
return (request, controller) => {
|
|
157
|
-
const id = newId();
|
|
158
|
-
const subscription = new Subscription();
|
|
159
|
-
const result = new Promise((next, error) => {
|
|
160
|
-
subscription.add(clientIdChanges
|
|
161
|
-
.pipe(switchMap(clientId => scope.on(`ant/${clientId}/request`)), filter(e => e.data.id === id), first(), map(message => message.data.response), takeUntilClosed(scope))
|
|
162
|
-
.subscribe({ next, error }));
|
|
163
|
-
});
|
|
164
|
-
subscription.add(clientIdChanges
|
|
165
|
-
.pipe(take(1), switchMap(clientId => scope.send(parent, `ant/${clientId}/request`, { id, request })), takeUntilClosed(scope))
|
|
166
|
-
.subscribe());
|
|
167
|
-
controller?.signal?.addEventListener('abort', () => subscription.unsubscribe());
|
|
168
|
-
scope.add(subscription);
|
|
169
|
-
return result;
|
|
170
|
-
};
|
|
171
|
-
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { BehaviorSubject, Observable, ReplaySubject, Subject, Subscription } from 'rxjs';
|
|
2
|
+
import type { HostAPI, HostCallbacks } from './hostAPI';
|
|
3
|
+
import type { Context } from './models';
|
|
4
|
+
import type { AppStateData } from './utils';
|
|
5
|
+
import type { AppManifest } from "../services/AppService";
|
|
6
|
+
export interface CompatParams {
|
|
7
|
+
clientId: string;
|
|
8
|
+
scope: Subscription;
|
|
9
|
+
windowChanges: Observable<Window>;
|
|
10
|
+
contextChanges: BehaviorSubject<Context>;
|
|
11
|
+
hostAPI: HostAPI;
|
|
12
|
+
connectionInitialized: Subject<void>;
|
|
13
|
+
manifestSubject: ReplaySubject<AppManifest | null>;
|
|
14
|
+
callbacks: HostCallbacks;
|
|
15
|
+
appState: BehaviorSubject<AppStateData>;
|
|
16
|
+
}
|
|
17
|
+
export declare function installCompat(params: CompatParams): void;
|
|
18
|
+
//# sourceMappingURL=compat.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compat.d.ts","sourceRoot":"","sources":["../../src/comms/compat.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,aAAa,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAC7F,OAAO,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AACvD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AACvC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAC3C,OAAO,KAAK,EAAE,WAAW,EAAE,+BAA6B;AAKxD,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,MAAM,CAAA;IAChB,KAAK,EAAE,YAAY,CAAA;IACnB,aAAa,EAAE,UAAU,CAAC,MAAM,CAAC,CAAA;IACjC,cAAc,EAAE,eAAe,CAAC,OAAO,CAAC,CAAA;IACxC,OAAO,EAAE,OAAO,CAAA;IAChB,qBAAqB,EAAE,OAAO,CAAC,IAAI,CAAC,CAAA;IACpC,eAAe,EAAE,aAAa,CAAC,WAAW,GAAG,IAAI,CAAC,CAAA;IAClD,SAAS,EAAE,aAAa,CAAA;IACxB,QAAQ,EAAE,eAAe,CAAC,YAAY,CAAC,CAAA;CACxC;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,YAAY,QAuFjD"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { on, send } from 'post-robot';
|
|
2
|
+
import { filter, take } from 'rxjs';
|
|
3
|
+
import { clone, takeUntilClosed } from './utils';
|
|
4
|
+
export function installCompat(params) {
|
|
5
|
+
const { clientId, scope, hostAPI, callbacks, contextChanges, connectionInitialized, manifestSubject } = params;
|
|
6
|
+
let legacyActivated = false;
|
|
7
|
+
const cancellers = [];
|
|
8
|
+
const wireCallbacks = (target) => {
|
|
9
|
+
const fire = (name, data) => send(target, name, data, { fireAndForget: true }).catch(() => { });
|
|
10
|
+
callbacks.context = ctx => fire(`ant/${clientId}/context`, { context: clone(ctx) });
|
|
11
|
+
callbacks.signal = signals => fire(`ant/${clientId}/signal`, signals);
|
|
12
|
+
callbacks.appState = state => fire(`ant/${clientId}/state`, state);
|
|
13
|
+
callbacks.toolbarClick = index => fire(`ant/${clientId}/toolbar/click`, { index });
|
|
14
|
+
callbacks.toolbarSearch = value => fire(`ant/${clientId}/toolbar/search`, { value });
|
|
15
|
+
};
|
|
16
|
+
const activate = (target) => {
|
|
17
|
+
if (legacyActivated)
|
|
18
|
+
return;
|
|
19
|
+
legacyActivated = true;
|
|
20
|
+
wireCallbacks(target);
|
|
21
|
+
console.info('connection initialized (legacy post-robot client)');
|
|
22
|
+
};
|
|
23
|
+
cancellers.push(on(`ant/${clientId}/notifications`, async ({ data }) => hostAPI.notify(data)));
|
|
24
|
+
cancellers.push(on(`ant/${clientId}/connect`, async ({ data }) => hostAPI.connect(data.service, data.name, data.args)));
|
|
25
|
+
cancellers.push(on(`ant/${clientId}/notepad`, async ({ data }) => hostAPI.notepad(data.name, data.data)));
|
|
26
|
+
cancellers.push(on(`ant/${clientId}/signal`, async ({ data }) => {
|
|
27
|
+
await hostAPI.sendSignal(data);
|
|
28
|
+
return data;
|
|
29
|
+
}));
|
|
30
|
+
cancellers.push(on(`ant/${clientId}/toolbar`, async ({ data }) => {
|
|
31
|
+
hostAPI.setToolbar(data.toolbar);
|
|
32
|
+
}));
|
|
33
|
+
cancellers.push(on(`ant/${clientId}/state`, async ({ data }) => {
|
|
34
|
+
hostAPI.setAppState(data);
|
|
35
|
+
}));
|
|
36
|
+
cancellers.push(on(`ant/${clientId}/state/get`, async () => hostAPI.getAppState()));
|
|
37
|
+
cancellers.push(on(`ant/${clientId}/request`, async ({ data, source }) => {
|
|
38
|
+
const { id: reqId, request: req } = data;
|
|
39
|
+
hostAPI.request(req)
|
|
40
|
+
.then((result) => send(source, `ant/${clientId}/request`, { id: reqId, response: result }, { fireAndForget: true }).catch(() => { }))
|
|
41
|
+
.catch(() => { });
|
|
42
|
+
return {};
|
|
43
|
+
}));
|
|
44
|
+
params.windowChanges.pipe(filter(Boolean), take(1), takeUntilClosed(scope)).subscribe((iframeWindow) => {
|
|
45
|
+
cancellers.push(on('ant/comms/ready', { window: iframeWindow }, async (event) => {
|
|
46
|
+
activate(event.source);
|
|
47
|
+
manifestSubject.next(event.data?.manifest ?? null);
|
|
48
|
+
setTimeout(() => connectionInitialized.next(undefined), 50);
|
|
49
|
+
return { clientId, context: clone(contextChanges.value) };
|
|
50
|
+
}));
|
|
51
|
+
});
|
|
52
|
+
let initTimer = null;
|
|
53
|
+
params.windowChanges.pipe(take(1), takeUntilClosed(scope)).subscribe((target) => {
|
|
54
|
+
const doInit = () => {
|
|
55
|
+
if (legacyActivated) {
|
|
56
|
+
clearInterval(initTimer);
|
|
57
|
+
initTimer = null;
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
send(target, 'ant/comms/init', { clientId, context: clone(contextChanges.value) })
|
|
61
|
+
.then((response) => {
|
|
62
|
+
activate(target);
|
|
63
|
+
manifestSubject.next(response.data?.manifest ?? null);
|
|
64
|
+
connectionInitialized.next(undefined);
|
|
65
|
+
})
|
|
66
|
+
.catch(() => { });
|
|
67
|
+
};
|
|
68
|
+
doInit();
|
|
69
|
+
initTimer = setInterval(doInit, 500);
|
|
70
|
+
connectionInitialized.pipe(take(1)).subscribe(() => {
|
|
71
|
+
clearInterval(initTimer);
|
|
72
|
+
initTimer = null;
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
scope.add(() => {
|
|
76
|
+
cancellers.forEach(c => c.cancel());
|
|
77
|
+
if (initTimer)
|
|
78
|
+
clearInterval(initTimer);
|
|
79
|
+
});
|
|
80
|
+
}
|
package/build/comms/host.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { Observable, Subject, SubscriptionLike } from 'rxjs';
|
|
2
|
-
import type {
|
|
2
|
+
import type { ConnectCallData } from './hostAPI';
|
|
3
3
|
import type { Context, Notepad, Notification, Toolbar } from './models';
|
|
4
4
|
import type { Change, ChangeSignal, Signal, SignalReceiver, SignalSender } from './signal';
|
|
5
|
-
import type { Scope } from './utils';
|
|
6
5
|
import type { AntConnect } from "../AntConnect";
|
|
6
|
+
import type { AppManifest } from "../services/AppService";
|
|
7
7
|
import { BehaviorSubject, ReplaySubject, Subscription } from 'rxjs';
|
|
8
|
+
export type { ConnectCallData } from './hostAPI';
|
|
8
9
|
export type SignalObserverFactory = (type: keyof ChangeSignal | (string & {}), id: string | undefined | null, actions: Change[], callback: (...signal: Signal[]) => void, scope?: ('project' | 'license')[]) => () => void;
|
|
9
10
|
export interface HostParams {
|
|
10
11
|
windowChanges: Observable<Window>;
|
|
@@ -18,10 +19,11 @@ export interface HostParams {
|
|
|
18
19
|
export interface Box {
|
|
19
20
|
params: HostParams;
|
|
20
21
|
clientId: string;
|
|
21
|
-
scope:
|
|
22
|
+
scope: Subscription;
|
|
22
23
|
connectionInitialized: Subject<void>;
|
|
23
24
|
manifestSubject: ReplaySubject<AppManifest | null>;
|
|
24
25
|
}
|
|
26
|
+
export type ConnectCall = (box: Box, data: ConnectCallData, next: () => Promise<any>) => Promise<any>;
|
|
25
27
|
export interface Host extends SubscriptionLike {
|
|
26
28
|
toolbar: Observable<Toolbar> & {
|
|
27
29
|
get: () => Toolbar;
|
|
@@ -40,19 +42,4 @@ export interface Host extends SubscriptionLike {
|
|
|
40
42
|
scope: Subscription;
|
|
41
43
|
}
|
|
42
44
|
export declare function newCommsHost(params: HostParams): Host;
|
|
43
|
-
export interface ConnectCallData {
|
|
44
|
-
/**
|
|
45
|
-
* the name of the service like 'records' for RecordsService and 'tasks' for TaskService
|
|
46
|
-
*/
|
|
47
|
-
service: string;
|
|
48
|
-
/**
|
|
49
|
-
* Then name of the API call.
|
|
50
|
-
*/
|
|
51
|
-
name: string;
|
|
52
|
-
/**
|
|
53
|
-
* The array of arguments for the API call
|
|
54
|
-
*/
|
|
55
|
-
args: any[];
|
|
56
|
-
}
|
|
57
|
-
export type ConnectCall = (box: Box, data: ConnectCallData, next: () => Promise<any>) => Promise<any>;
|
|
58
45
|
//# sourceMappingURL=host.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"host.d.ts","sourceRoot":"","sources":["../../src/comms/host.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,MAAM,CAAA;AACjE,OAAO,KAAK,EAAE,WAAW,
|
|
1
|
+
{"version":3,"file":"host.d.ts","sourceRoot":"","sources":["../../src/comms/host.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,MAAM,CAAA;AACjE,OAAO,KAAK,EAAE,eAAe,EAAiB,MAAM,WAAW,CAAA;AAC/D,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AACvE,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAE1F,OAAO,KAAK,EAAE,UAAU,EAAE,sBAAoB;AAC9C,OAAO,KAAK,EAAE,WAAW,EAAE,+BAA6B;AAExD,OAAO,EACL,eAAe,EAMf,aAAa,EAIb,YAAY,EAEb,MAAM,MAAM,CAAA;AAQb,YAAY,EAAE,eAAe,EAAE,MAAM,WAAW,CAAA;AAEhD,MAAM,MAAM,qBAAqB,GAAG,CAClC,IAAI,EAAE,MAAM,YAAY,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,EACxC,EAAE,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,EAC7B,OAAO,EAAE,MAAM,EAAE,EACjB,QAAQ,EAAE,CAAC,GAAG,MAAM,EAAE,MAAM,EAAE,KAAK,IAAI,EACvC,KAAK,CAAC,EAAE,CAAC,SAAS,GAAG,SAAS,CAAC,EAAE,KAC9B,MAAM,IAAI,CAAA;AAEf,MAAM,WAAW,UAAU;IACzB,aAAa,EAAE,UAAU,CAAC,MAAM,CAAC,CAAA;IACjC,cAAc,EAAE,eAAe,CAAC,OAAO,CAAC,CAAA;IACxC,eAAe,EAAE,CAAC,YAAY,EAAE,YAAY,KAAK,IAAI,CAAA;IACrD,OAAO,EAAE,UAAU,CAAA;IACnB,OAAO,EAAE,OAAO,CAAA;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,iBAAiB,EAAE,qBAAqB,CAAA;CACzC;AAED,MAAM,WAAW,GAAG;IAClB,MAAM,EAAE,UAAU,CAAA;IAClB,QAAQ,EAAE,MAAM,CAAA;IAChB,KAAK,EAAE,YAAY,CAAA;IACnB,qBAAqB,EAAE,OAAO,CAAC,IAAI,CAAC,CAAA;IACpC,eAAe,EAAE,aAAa,CAAC,WAAW,GAAG,IAAI,CAAC,CAAA;CACnD;AAED,MAAM,MAAM,WAAW,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC,KAAK,OAAO,CAAC,GAAG,CAAC,CAAA;AAErG,MAAM,WAAW,IAAK,SAAQ,gBAAgB;IAC5C,OAAO,EAAE,UAAU,CAAC,OAAO,CAAC,GAAG;QAAE,GAAG,EAAE,MAAM,OAAO,CAAC;QAAC,GAAG,EAAE;YAAE,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;SAAE,CAAA;KAAE,CAAA;IAC3G,uBAAuB,EAAE,UAAU,CAAC,OAAO,CAAC,CAAA;IAC5C,QAAQ,EAAE,UAAU,CAAC,WAAW,GAAG,IAAI,CAAC,CAAA;IACxC,MAAM,EAAE,cAAc,GAAG,YAAY,CAAA;IACrC,QAAQ,EAAE;QACR,OAAO,EAAE,UAAU,CAAC,MAAM,CAAC,CAAA;QAC3B,GAAG,EAAE,MAAM,MAAM,CAAA;QACjB,GAAG,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;KAC7B,CAAA;IACD,KAAK,EAAE,YAAY,CAAA;CACpB;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI,CAkHrD"}
|