@antcde/connect-ts 0.4.18-rc.6a3e1ae → 0.4.18-rc.70c625c

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.
Files changed (39) hide show
  1. package/build/comms/client.d.ts +10 -12
  2. package/build/comms/client.d.ts.map +1 -1
  3. package/build/comms/client.js +72 -157
  4. package/build/comms/compat.d.ts +18 -0
  5. package/build/comms/compat.d.ts.map +1 -0
  6. package/build/comms/compat.js +80 -0
  7. package/build/comms/host.d.ts +5 -18
  8. package/build/comms/host.d.ts.map +1 -1
  9. package/build/comms/host.js +88 -161
  10. package/build/comms/hostAPI.d.ts +49 -0
  11. package/build/comms/hostAPI.d.ts.map +1 -0
  12. package/build/comms/hostAPI.js +56 -0
  13. package/build/comms/python-schema.d.ts +4 -0
  14. package/build/comms/python-schema.d.ts.map +1 -0
  15. package/build/comms/python-schema.js +4 -0
  16. package/build/comms/signal.d.ts +5 -321
  17. package/build/comms/signal.d.ts.map +1 -1
  18. package/build/comms/signal.js +5 -9
  19. package/build/comms/signalChangeTypes.d.ts +47 -0
  20. package/build/comms/signalChangeTypes.d.ts.map +1 -0
  21. package/build/comms/signalChangeTypes.js +1 -0
  22. package/build/comms/signalTypes.d.ts +262 -0
  23. package/build/comms/signalTypes.d.ts.map +1 -0
  24. package/build/comms/signalTypes.js +6 -0
  25. package/build/comms/transport.d.ts +16 -0
  26. package/build/comms/transport.d.ts.map +1 -0
  27. package/build/comms/transport.js +51 -0
  28. package/build/comms/utils.d.ts +4 -36
  29. package/build/comms/utils.d.ts.map +1 -1
  30. package/build/comms/utils.js +6 -79
  31. package/build/index.d.ts +3 -1
  32. package/build/index.d.ts.map +1 -1
  33. package/build/index.js +3 -1
  34. package/build/services/RBAC/PermissionService.d.ts +2 -2
  35. package/build/services/RBAC/PermissionService.d.ts.map +1 -1
  36. package/build/utils.d.ts +2 -0
  37. package/build/utils.d.ts.map +1 -0
  38. package/build/utils.js +6 -0
  39. package/package.json +7 -3
@@ -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;
@@ -34,9 +33,8 @@ export interface Client extends Subscription {
34
33
  };
35
34
  signal: SignalSender & SignalReceiver;
36
35
  request: <T, R>(request: AxiosRequest<T>, controller?: AbortController) => Promise<R>;
36
+ deprecatedRequest?: <T, R>(request: AxiosRequest<T>, controller?: AbortController) => Promise<R>;
37
37
  }
38
38
  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
39
  export {};
42
40
  //# sourceMappingURL=client.d.ts.map
@@ -1 +1 @@
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AAE,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;IACrF,iBAAiB,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,EAAE,eAAe,KAAK,OAAO,CAAC,CAAC,CAAC,CAAA;CACjG;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM,CAsG3D"}
@@ -1,171 +1,86 @@
1
- import { send } from 'post-robot';
2
- import { BehaviorSubject, combineLatest, concatMap, filter, first, firstValueFrom, identity, map, merge, share, shareReplay, Subscription, switchMap, take, tap, } from 'rxjs';
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 { clone, newId, newScope, takeUntilClosed } from './utils';
5
+ import { receivePort, requestPort } from './transport';
6
+ import { newScope, takeUntilClosed } from './utils';
6
7
  export function newCommsClient(params) {
7
- const scope = newScope();
8
- // Two initialization paths:
9
- // 1. Initial load: Host sends 'ant/comms/init' with clientId + context after iframe @load
10
- // 2. HMR recovery: Client sends 'ready', host responds with clientId + context
11
- const initData = new BehaviorSubject(null);
12
- // Send ready message for HMR recovery (host's listener is scoped to our window)
13
- // For initial load, this will timeout (expected) because host's listener isn't set up until @load
14
- send(params.parent, 'ant/comms/ready', { manifest: params.manifest }, { fireAndForget: false })
15
- .then((response) => {
16
- const { clientId, context } = response.data;
17
- initData.next({ clientId, context });
18
- })
19
- .catch(() => {
20
- // Timeout is expected for initial load (host's ready listener sets up after @load)
21
- // The init message will come through separately
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) => {
15
+ resolveProxy = r;
22
16
  });
23
- // Listen for host-initiated init (primary method for initial load)
24
- // The init message now includes context, so we have it immediately
25
- // IMPORTANT: We use scope.once WITH a handler so that initData.next() runs
26
- // BEFORE the ACK is sent to the host. This ensures all RxJS subscriptions
27
- // (which set up post-robot listeners) have processed before the host
28
- // marks connectionInitialized and starts sending messages.
29
- scope
30
- .once('ant/comms/init', (message) => {
31
- if (!initData.value) {
32
- initData.next({ clientId: message.data.clientId, context: message.data.context ?? {} });
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,
17
+ const bootstrap = async () => {
18
+ const init = params.initialConnection?.port
19
+ ? { port: params.initialConnection.port, context: params.initialConnection.context }
20
+ : await receivePort();
21
+ contextSubject.next(init.context);
22
+ const proxy = Comlink.wrap(init.port);
23
+ subscription.add(() => {
24
+ proxy[Comlink.releaseProxy]();
25
+ init.port.close();
26
+ });
27
+ await proxy.onContext(Comlink.proxy((ctx) => contextSubject.next(ctx)));
28
+ await proxy.onSignal(Comlink.proxy((signals) => {
29
+ incomingSignals.next({ data: signals, origin: '', source: null });
30
+ }));
31
+ await proxy.onAppState(Comlink.proxy((state) => appStateSubject.next(state)));
32
+ await proxy.onToolbarClick(Comlink.proxy((index) => toolbarSubject.value.menu[index]?.onClick?.()));
33
+ await proxy.onToolbarSearch(Comlink.proxy((value) => {
34
+ const t = toolbarSubject.value;
35
+ toolbarSubject.next({ ...t, search: { ...t.search, input: value ?? '' } });
36
+ }));
37
+ await proxy.ready(params.manifest ?? null);
38
+ resolveProxy(proxy);
44
39
  };
45
- return Object.assign(scope, {
46
- notepad: newNotepad(box),
47
- notifications: newNotifications(box),
48
- connect: params.connect ?? newAntConnectFacade(box),
49
- context: newContextObservableWithInitial(box, initialContext),
50
- toolbar: handleToolbarChanges(box),
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),
40
+ requestPort(params.parent);
41
+ bootstrap();
42
+ proxyReady.then(proxy => toolbarSubject.pipe(takeUntilClosed(subscription)).subscribe(t => proxy.setToolbar({ ...t, menu: t.menu.map(({ onClick: _onClick, ...item }) => item) })));
43
+ const signal = newSignaler({
44
+ send: async (signals) => (await proxyReady).sendSignal(signals),
45
+ receiver: incomingSignals.asObservable(),
63
46
  });
64
- }
65
- function handleToolbarChanges({ scope, parent, clientIdChanges }) {
66
- const toolbar = new BehaviorSubject({ menu: [], search: { enabled: false, input: '' }, isLoading: false });
67
- const set = (value) => {
68
- if (typeof value === 'function') {
69
- toolbar.next(value(toolbar.value));
70
- }
71
- else {
72
- toolbar.next(value);
73
- }
47
+ const notepad = {
48
+ show: tab => proxyReady.then(p => p.notepad('show/tab', { tab })),
49
+ showTask: (task, select) => proxyReady.then(p => p.notepad('show/task', { task, select })),
50
+ hide: () => proxyReady.then(p => p.notepad('hide', {})),
51
+ selectSbs: item => proxyReady.then(p => p.notepad('sbs/select', { item })),
74
52
  };
75
- // Send toolbar state to host whenever toolbar or clientId changes
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, {
53
+ const notifications = notificationTypes.reduce((result, type) => Object.assign(result, {
108
54
  [type]: (message) => {
109
- return clientIdChanges
110
- .pipe(take(1), concatMap(clientId => scope.send(parent, `ant/${clientId}/notifications`, { type, message })), map(({ data }) => data))
111
- .forEach(identity);
55
+ const promise = proxyReady.then(p => p.notify({ type, message }));
56
+ return Object.assign(promise, new Subscription());
112
57
  },
113
58
  }), {});
114
- }
115
- /**
116
- * Creates a context observable that starts with initial context from the ready response,
117
- * then merges with subsequent context updates from the host.
118
- * This eliminates the delay between app start and receiving context.
119
- */
120
- function newContextObservableWithInitial(box, initialContext) {
121
- const { scope, clientIdChanges } = box;
122
- // Subsequent context updates from the host
123
- const contextUpdates = clientIdChanges.pipe(switchMap(clientId => scope.on(`ant/${clientId}/context`)), map(e => clone(e.data.context)));
124
- // Merge initial context with subsequent updates
125
- return merge(initialContext, contextUpdates).pipe(shareReplay(1));
126
- }
127
- function newAntConnectFacade({ scope, parent, clientIdChanges }) {
128
- return new Proxy({}, {
129
- get: (_, service) => new Proxy({}, {
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
- }
59
+ return Object.assign(subscription, {
60
+ notepad,
61
+ notifications,
62
+ connect: params.connect ?? new Proxy({}, {
63
+ get: (_, service) => new Proxy({}, {
64
+ get: (_, name) => typeof service === 'string' && typeof name === 'string'
65
+ ? (...args) => proxyReady.then(p => p.connect(service, name, args))
66
+ : undefined,
67
+ }),
68
+ }),
69
+ context: contextSubject.asObservable().pipe(shareReplay(1)),
70
+ toolbar: Object.assign(toolbarSubject.asObservable().pipe(takeUntilClosed(subscription)), {
71
+ set: (value) => {
72
+ const result = typeof value === 'function' ? value(toolbarSubject.value) : value;
73
+ if (result)
74
+ toolbarSubject.next(result);
143
75
  },
76
+ get: () => toolbarSubject.value,
144
77
  }),
78
+ appState: Object.assign(appStateSubject.pipe(map(e => e.state), distinctUntilChanged()), {
79
+ get: () => proxyReady.then(p => p.getAppState()).then(s => s.state),
80
+ set: (state) => proxyReady.then(p => p.setAppState({ timestamp: Date.now(), state })).then(() => { }),
81
+ }),
82
+ signal,
83
+ request: (req, _controller) => proxyReady.then(p => p.request(req)),
84
+ deprecatedRequest: (req, _controller) => proxyReady.then(p => p.deprecatedRequest(req)),
145
85
  });
146
86
  }
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
+ }
@@ -1,10 +1,11 @@
1
1
  import type { Observable, Subject, SubscriptionLike } from 'rxjs';
2
- import type { AppManifest } from "../services/AppService";
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: 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,EAAE,+BAA6B;AACxD,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;AAC1F,OAAO,KAAK,EAAgB,KAAK,EAAE,MAAM,SAAS,CAAA;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,sBAAoB;AAG9C,OAAO,EACL,eAAe,EAWf,aAAa,EAIb,YAAY,EAIb,MAAM,MAAM,CAAA;AAMb,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,K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