@antcde/connect-ts 0.4.16 → 0.4.17-rc.0c54737
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/README.md +377 -0
- package/build/AntConnect.d.ts +2 -0
- package/build/AntConnect.d.ts.map +1 -1
- package/build/AntConnect.js +10 -6
- package/build/AntHttpClient.js +24 -49
- package/build/comms/client.d.ts +4 -1
- package/build/comms/client.d.ts.map +1 -1
- package/build/comms/client.js +62 -37
- package/build/comms/host.d.ts +7 -4
- package/build/comms/host.d.ts.map +1 -1
- package/build/comms/host.js +57 -42
- package/build/comms/models.d.ts +1 -0
- package/build/comms/models.d.ts.map +1 -1
- package/build/comms/recordServiceCalls.js +6 -15
- package/build/comms/signal.d.ts +138 -13
- package/build/comms/signal.d.ts.map +1 -1
- package/build/comms/signal.js +12 -11
- package/build/comms/utils.js +6 -15
- package/build/index.d.ts +13 -12
- package/build/index.d.ts.map +1 -1
- package/build/index.js +2 -2
- package/build/services/AppService.d.ts +59 -10
- package/build/services/AppService.d.ts.map +1 -1
- package/build/services/AppService.js +0 -1
- package/build/services/ColumnService.d.ts +60 -3
- package/build/services/ColumnService.d.ts.map +1 -1
- package/build/services/ColumnService.js +1 -0
- package/build/services/DmsService.d.ts +122 -21
- package/build/services/DmsService.d.ts.map +1 -1
- package/build/services/DmsService.js +60 -16
- package/build/services/LabelService.d.ts +4 -2
- package/build/services/LabelService.d.ts.map +1 -1
- package/build/services/LabelService.js +6 -1
- package/build/services/LicenseService.d.ts +42 -0
- package/build/services/LicenseService.d.ts.map +1 -1
- package/build/services/LicenseService.js +1 -0
- package/build/services/ProjectService.d.ts +20 -1
- package/build/services/ProjectService.d.ts.map +1 -1
- package/build/services/PropagationService.d.ts +15 -4
- package/build/services/PropagationService.d.ts.map +1 -1
- package/build/services/PropagationService.js +2 -2
- package/build/services/RBAC/PermissionService.d.ts +10 -3
- package/build/services/RBAC/PermissionService.d.ts.map +1 -1
- package/build/services/RBAC/PermissionService.js +1 -0
- package/build/services/RecordService.d.ts +94 -3
- package/build/services/RecordService.d.ts.map +1 -1
- package/build/services/RecordService.js +24 -13
- package/build/services/ReleaseService.d.ts +18 -0
- package/build/services/ReleaseService.d.ts.map +1 -0
- package/build/services/ReleaseService.js +5 -0
- package/build/services/SbsService.js +8 -2
- package/build/services/ScriptsService.d.ts.map +1 -1
- package/build/services/ScriptsService.js +4 -3
- package/build/services/TableService.d.ts +58 -20
- package/build/services/TableService.d.ts.map +1 -1
- package/build/services/TableService.js +13 -2
- package/build/services/TaskQueryService.js +1 -1
- package/build/services/TaskService.d.ts +18 -7
- package/build/services/TaskService.d.ts.map +1 -1
- package/build/services/TaskService.js +3 -5
- package/build/services/TaskServiceQueries.d.ts +1 -1
- package/build/services/TaskServiceQueries.js +2 -2
- package/build/services/TokenService.js +5 -15
- package/build/services/UserService.d.ts +0 -2
- package/build/services/UserService.d.ts.map +1 -1
- package/build/services/Websockets/DmsEvents.d.ts +25 -0
- package/build/services/Websockets/DmsEvents.d.ts.map +1 -0
- package/build/services/Websockets/DmsEvents.js +6 -0
- package/build/services/WorkflowService.d.ts +5 -3
- package/build/services/WorkflowService.d.ts.map +1 -1
- package/build/services/WorkflowService.js +21 -20
- package/build/services/WorkflowServiceQueries.js +1 -1
- package/build/types.d.ts +169 -0
- package/build/types.d.ts.map +1 -1
- package/build/types.js +19 -1
- package/package.json +20 -21
- package/schemas/app-config.schema.json +165 -0
- package/build/tsconfig.esm.tsbuildinfo +0 -1
package/build/comms/client.js
CHANGED
|
@@ -1,23 +1,42 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
import { send } from 'post-robot';
|
|
11
|
-
import { BehaviorSubject, combineLatest, concatMap, filter, first, firstValueFrom, identity, map, share, shareReplay, Subscription, switchMap, take, tap, } from 'rxjs';
|
|
2
|
+
import { BehaviorSubject, combineLatest, concatMap, filter, first, firstValueFrom, identity, map, merge, share, shareReplay, Subscription, switchMap, take, tap, } from 'rxjs';
|
|
12
3
|
import { notificationTypes } from './models';
|
|
13
4
|
import { newSignaler } from './signal';
|
|
14
5
|
import { clone, newId, newScope, takeUntilClosed } from './utils';
|
|
15
6
|
export function newCommsClient(params) {
|
|
16
|
-
var _a;
|
|
17
7
|
const scope = newScope();
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
|
22
|
+
});
|
|
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));
|
|
21
40
|
const box = {
|
|
22
41
|
clientIdChanges,
|
|
23
42
|
scope,
|
|
@@ -26,8 +45,8 @@ export function newCommsClient(params) {
|
|
|
26
45
|
return Object.assign(scope, {
|
|
27
46
|
notepad: newNotepad(box),
|
|
28
47
|
notifications: newNotifications(box),
|
|
29
|
-
connect:
|
|
30
|
-
context:
|
|
48
|
+
connect: params.connect ?? newAntConnectFacade(box),
|
|
49
|
+
context: newContextObservableWithInitial(box, initialContext),
|
|
31
50
|
toolbar: handleToolbarChanges(box),
|
|
32
51
|
appState: handleAppStateChanges(box),
|
|
33
52
|
signal: getSignal(box),
|
|
@@ -53,32 +72,34 @@ function handleToolbarChanges({ scope, parent, clientIdChanges }) {
|
|
|
53
72
|
toolbar.next(value);
|
|
54
73
|
}
|
|
55
74
|
};
|
|
75
|
+
// Send toolbar state to host whenever toolbar or clientId changes
|
|
56
76
|
combineLatest([
|
|
57
77
|
toolbar.asObservable(),
|
|
58
78
|
clientIdChanges,
|
|
59
79
|
])
|
|
60
|
-
.pipe(tap(([toolbar, clientId]) => send(parent, `ant/${clientId}/toolbar`, { toolbar })),
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
scope.on(`ant/${clientId}/toolbar/
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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))
|
|
69
90
|
.subscribe();
|
|
70
91
|
return Object.assign(toolbar.asObservable().pipe(takeUntilClosed(scope)), { set, get: () => toolbar.value });
|
|
71
92
|
}
|
|
72
93
|
export function newNotepad({ scope, parent, clientIdChanges }) {
|
|
73
|
-
const post = (name, data) =>
|
|
94
|
+
const post = async (name, data) => {
|
|
74
95
|
clientIdChanges
|
|
75
96
|
.pipe(concatMap(clientId => scope.send(parent, `ant/${clientId}/notepad`, { name, data })))
|
|
76
97
|
.subscribe();
|
|
77
|
-
}
|
|
98
|
+
};
|
|
78
99
|
return {
|
|
79
100
|
show: tab => post('show/tab', { tab }),
|
|
80
101
|
showTask: (task, select) => post(`show/task`, { task, select }),
|
|
81
|
-
hide: () => post(`hide`,
|
|
102
|
+
hide: () => post(`hide`, {}),
|
|
82
103
|
selectSbs: item => post(`sbs/select`, { item }),
|
|
83
104
|
};
|
|
84
105
|
}
|
|
@@ -91,8 +112,17 @@ export function newNotifications({ parent, scope, clientIdChanges }) {
|
|
|
91
112
|
},
|
|
92
113
|
}), {});
|
|
93
114
|
}
|
|
94
|
-
|
|
95
|
-
|
|
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));
|
|
96
126
|
}
|
|
97
127
|
function newAntConnectFacade({ scope, parent, clientIdChanges }) {
|
|
98
128
|
return new Proxy({}, {
|
|
@@ -117,18 +147,13 @@ function newAntConnectFacade({ scope, parent, clientIdChanges }) {
|
|
|
117
147
|
function getSignal({ clientIdChanges, scope, parent }) {
|
|
118
148
|
return newSignaler({
|
|
119
149
|
send: (signals) => {
|
|
120
|
-
console.log('[client.ts] Sending signal to host:', signals);
|
|
121
150
|
return firstValueFrom(clientIdChanges.pipe(take(1), concatMap(clientId => scope.send(parent, `ant/${clientId}/signal`, signals, { fireAndForget: false })), map(e => e.data)));
|
|
122
151
|
},
|
|
123
|
-
receiver: clientIdChanges.pipe(switchMap(
|
|
124
|
-
console.log('[client.ts] Setting up receiver for clientId:', clientId);
|
|
125
|
-
return scope.on(`ant/${clientId}/signal`);
|
|
126
|
-
}), tap(msg => console.log('[client.ts] Received signal from host:', msg)), share()),
|
|
152
|
+
receiver: clientIdChanges.pipe(switchMap(clientId => scope.on(`ant/${clientId}/signal`)), share()),
|
|
127
153
|
});
|
|
128
154
|
}
|
|
129
155
|
function getRequest({ clientIdChanges, scope }) {
|
|
130
156
|
return (request, controller) => {
|
|
131
|
-
var _a;
|
|
132
157
|
const id = newId();
|
|
133
158
|
const subscription = new Subscription();
|
|
134
159
|
const result = new Promise((next, error) => {
|
|
@@ -139,7 +164,7 @@ function getRequest({ clientIdChanges, scope }) {
|
|
|
139
164
|
subscription.add(clientIdChanges
|
|
140
165
|
.pipe(take(1), switchMap(clientId => scope.send(parent, `ant/${clientId}/request`, { id, request })), takeUntilClosed(scope))
|
|
141
166
|
.subscribe());
|
|
142
|
-
|
|
167
|
+
controller?.signal?.addEventListener('abort', () => subscription.unsubscribe());
|
|
143
168
|
scope.add(subscription);
|
|
144
169
|
return result;
|
|
145
170
|
};
|
package/build/comms/host.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import type { Observable, Subject, SubscriptionLike } from 'rxjs';
|
|
2
|
+
import type { AppManifest } from "../services/AppService";
|
|
2
3
|
import type { Context, Notepad, Notification, Toolbar } from './models';
|
|
3
|
-
import type { Change, ChangeSignal, SignalReceiver, SignalSender } from './signal';
|
|
4
|
+
import type { Change, ChangeSignal, Signal, SignalReceiver, SignalSender } from './signal';
|
|
4
5
|
import type { Scope } from './utils';
|
|
5
6
|
import type { AntConnect } from "../AntConnect";
|
|
6
|
-
import { Subscription } from 'rxjs';
|
|
7
|
-
export type SignalObserverFactory =
|
|
7
|
+
import { BehaviorSubject, ReplaySubject, Subscription } from 'rxjs';
|
|
8
|
+
export type SignalObserverFactory = (type: keyof ChangeSignal | (string & {}), id: string | undefined | null, actions: Change[], callback: (...signal: Signal[]) => void, scope?: ('project' | 'license')[]) => () => void;
|
|
8
9
|
export interface HostParams {
|
|
9
10
|
windowChanges: Observable<Window>;
|
|
10
|
-
contextChanges:
|
|
11
|
+
contextChanges: BehaviorSubject<Context>;
|
|
11
12
|
addNotification: (notification: Notification) => void;
|
|
12
13
|
connect: AntConnect;
|
|
13
14
|
notepad: Notepad;
|
|
@@ -19,6 +20,7 @@ export interface Box {
|
|
|
19
20
|
clientId: string;
|
|
20
21
|
scope: Scope;
|
|
21
22
|
connectionInitialized: Subject<void>;
|
|
23
|
+
manifestSubject: ReplaySubject<AppManifest | null>;
|
|
22
24
|
}
|
|
23
25
|
export interface Host extends SubscriptionLike {
|
|
24
26
|
toolbar: Observable<Toolbar> & {
|
|
@@ -28,6 +30,7 @@ export interface Host extends SubscriptionLike {
|
|
|
28
30
|
};
|
|
29
31
|
};
|
|
30
32
|
isConnectionInitialized: Observable<boolean>;
|
|
33
|
+
manifest: Observable<AppManifest | null>;
|
|
31
34
|
signal: SignalReceiver & SignalSender;
|
|
32
35
|
appState: {
|
|
33
36
|
changes: Observable<string>;
|
|
@@ -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,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AACvE,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;
|
|
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,C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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,CAwCrD;AAqED,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,OAAO,EAAE,MAAM,CAAA;IACf;;OAEG;IACH,IAAI,EAAE,MAAM,CAAA;IACZ;;OAEG;IACH,IAAI,EAAE,GAAG,EAAE,CAAA;CACZ;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"}
|
package/build/comms/host.js
CHANGED
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
import { on, send } from 'post-robot';
|
|
11
2
|
import { BehaviorSubject, combineLatest, concatMap, delay, distinctUntilChanged, filter, firstValueFrom, from, identity, map, of, ReplaySubject, retry, share, startWith, Subscription, switchMap, take, tap, } from 'rxjs';
|
|
12
3
|
import { fromArrayLike } from 'rxjs/internal/observable/innerFrom';
|
|
@@ -17,10 +8,12 @@ export function newCommsHost(params) {
|
|
|
17
8
|
const scope = newScope();
|
|
18
9
|
const clientId = newId();
|
|
19
10
|
const connectionInitialized = new ReplaySubject(1);
|
|
20
|
-
const
|
|
11
|
+
const manifestSubject = new ReplaySubject(1);
|
|
12
|
+
const box = { scope, params, clientId, connectionInitialized, manifestSubject };
|
|
21
13
|
const toolbar = handleToolbarChanges(box);
|
|
22
14
|
const appState = handleAppStateChanges(box);
|
|
23
15
|
handleInit(box);
|
|
16
|
+
handleReady(box); // Client-initiated connection (fixes HMR and context delay)
|
|
24
17
|
handleContextChanges(box);
|
|
25
18
|
handleNotificationChanges(box);
|
|
26
19
|
handleConnectChanges(box);
|
|
@@ -28,13 +21,7 @@ export function newCommsHost(params) {
|
|
|
28
21
|
handleRequestChanges(box);
|
|
29
22
|
scope.add(connectionInitialized);
|
|
30
23
|
const signal = newSignaler({
|
|
31
|
-
send: (
|
|
32
|
-
console.log('[host.ts] newSignaler.send called with:', signals);
|
|
33
|
-
return firstValueFrom(combineLatest([params.windowChanges, connectionInitialized]).pipe(takeUntilClosed(scope), take(1), switchMap(([source]) => {
|
|
34
|
-
console.log('[host.ts] Sending to client via post-robot:', { clientId, signals });
|
|
35
|
-
return send(source, `ant/${clientId}/signal`, signals, { fireAndForget: true });
|
|
36
|
-
})));
|
|
37
|
-
},
|
|
24
|
+
send: signals => firstValueFrom(combineLatest([params.windowChanges, connectionInitialized]).pipe(takeUntilClosed(scope), take(1), switchMap(([source]) => send(source, `ant/${clientId}/signal`, signals, { fireAndForget: true })))),
|
|
38
25
|
receiver: scope.on(`ant/${clientId}/signal`).pipe(share()),
|
|
39
26
|
});
|
|
40
27
|
installSignalObservers(signal, box);
|
|
@@ -45,24 +32,54 @@ export function newCommsHost(params) {
|
|
|
45
32
|
isConnectionInitialized: connectionInitialized
|
|
46
33
|
.asObservable()
|
|
47
34
|
.pipe(map(() => true), startWith(false), takeUntilClosed(scope)),
|
|
35
|
+
manifest: manifestSubject.asObservable().pipe(takeUntilClosed(scope)),
|
|
48
36
|
scope: newScope(scope),
|
|
49
37
|
});
|
|
50
38
|
}
|
|
51
|
-
function handleInit({ scope, params, clientId, connectionInitialized }) {
|
|
52
|
-
//
|
|
39
|
+
function handleInit({ scope, params, clientId, connectionInitialized, manifestSubject }) {
|
|
40
|
+
// Init message includes context so client has it immediately (no delay waiting for separate context message)
|
|
41
|
+
// The client uses a handler in scope.once, ensuring initData.next() runs BEFORE the ACK is sent.
|
|
42
|
+
// This means all RxJS subscriptions (which set up listeners) have processed before we get here.
|
|
53
43
|
params.windowChanges
|
|
54
|
-
.pipe(switchMap(window => send(window, 'ant/comms/init', { clientId }, { fireAndForget: false })), retry({
|
|
55
|
-
delay: (error, attempt) => of(error).pipe(delay(
|
|
44
|
+
.pipe(switchMap(window => send(window, 'ant/comms/init', { clientId, context: params.contextChanges.value }, { fireAndForget: false })), retry({
|
|
45
|
+
delay: (error, attempt) => of(error).pipe(delay(500), tap(error => console.info('retrying connection initialization', { attempt, error }))),
|
|
56
46
|
}), tap(() => console.info('connection initialized')), takeUntilClosed(scope))
|
|
57
|
-
.subscribe(
|
|
47
|
+
.subscribe((response) => {
|
|
48
|
+
manifestSubject.next(response.data?.manifest ?? null);
|
|
49
|
+
connectionInitialized.next(undefined);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Client-initiated connection handler for HMR recovery.
|
|
54
|
+
* When the client sends "ant/comms/ready", respond with clientId + current context.
|
|
55
|
+
*
|
|
56
|
+
* This is scoped to our specific iframe window (via post-robot's { window } option)
|
|
57
|
+
* to prevent multiple hosts from all responding to a single client's ready message.
|
|
58
|
+
*
|
|
59
|
+
* Note: For initial load, handleInit provides context with the init message.
|
|
60
|
+
* This handler is specifically for HMR where client JS restarts but iframe doesn't reload.
|
|
61
|
+
*/
|
|
62
|
+
function handleReady({ scope, params, clientId, connectionInitialized, manifestSubject }) {
|
|
63
|
+
// Wait for window reference (from @load event), then set up HMR recovery listener
|
|
64
|
+
// The listener is scoped to our specific iframe window
|
|
65
|
+
params.windowChanges.pipe(filter(Boolean), take(1), takeUntilClosed(scope)).subscribe((iframeWindow) => {
|
|
66
|
+
const canceller = on('ant/comms/ready', { window: iframeWindow }, async (event) => {
|
|
67
|
+
console.info('ready message received (client-initiated, HMR recovery)');
|
|
68
|
+
manifestSubject.next(event.data?.manifest ?? null);
|
|
69
|
+
// Small delay to ensure client's RxJS subscriptions have processed after receiving response
|
|
70
|
+
setTimeout(() => connectionInitialized.next(undefined), 50);
|
|
71
|
+
return { clientId, context: params.contextChanges.value };
|
|
72
|
+
});
|
|
73
|
+
scope.add({ unsubscribe: () => canceller.cancel() });
|
|
74
|
+
});
|
|
58
75
|
}
|
|
59
76
|
function handleNotificationChanges({ scope, params, clientId }) {
|
|
60
77
|
scope
|
|
61
|
-
.resolve(on(`ant/${clientId}/notifications`,
|
|
78
|
+
.resolve(on(`ant/${clientId}/notifications`, async ({ data }) => {
|
|
62
79
|
const notification = data;
|
|
63
80
|
params.addNotification(notification);
|
|
64
81
|
return notification;
|
|
65
|
-
}))
|
|
82
|
+
}))
|
|
66
83
|
.catch(identity); // consume the cancellation error
|
|
67
84
|
}
|
|
68
85
|
const defaultConnectCall = ({ params }, { service, name, args }) => params.connect[service][name](...args);
|
|
@@ -81,8 +98,11 @@ function handleRequestChanges(box) {
|
|
|
81
98
|
.on(`ant/${clientId}/request`)
|
|
82
99
|
.pipe(concatMap(({ data, source }) => {
|
|
83
100
|
const { id, request } = data;
|
|
84
|
-
const
|
|
85
|
-
|
|
101
|
+
const { httpClient } = box.params.connect;
|
|
102
|
+
if (!httpClient)
|
|
103
|
+
return from(Promise.reject(new Error('No httpClient configured on AntConnect')));
|
|
104
|
+
const http = httpClient.http;
|
|
105
|
+
const config = { ...request, baseURL: httpClient.baseUrl };
|
|
86
106
|
const promise = http.request(config);
|
|
87
107
|
return from(promise).pipe(concatMap(response => scope.send(source, `ant/${clientId}/request`, { id, response: response.data })));
|
|
88
108
|
}), takeUntilClosed(scope))
|
|
@@ -90,7 +110,7 @@ function handleRequestChanges(box) {
|
|
|
90
110
|
}
|
|
91
111
|
function handleNotepadChanges({ scope, params, clientId }) {
|
|
92
112
|
scope
|
|
93
|
-
.resolve(on(`ant/${clientId}/notepad`, (e) =>
|
|
113
|
+
.resolve(on(`ant/${clientId}/notepad`, async (e) => {
|
|
94
114
|
const { name, data } = e.data;
|
|
95
115
|
switch (name) {
|
|
96
116
|
case 'hide':
|
|
@@ -102,7 +122,7 @@ function handleNotepadChanges({ scope, params, clientId }) {
|
|
|
102
122
|
case 'sbs/select':
|
|
103
123
|
return params.notepad.selectSbs(data.item);
|
|
104
124
|
}
|
|
105
|
-
}))
|
|
125
|
+
}))
|
|
106
126
|
.catch(identity); // consume the cancellation error
|
|
107
127
|
}
|
|
108
128
|
function handleContextChanges({ params, clientId, scope, connectionInitialized }) {
|
|
@@ -127,18 +147,19 @@ function handleToolbarChanges({ scope, clientId, connectionInitialized, params }
|
|
|
127
147
|
return Object.assign(toolbar.asObservable(), {
|
|
128
148
|
get: () => toolbar.value,
|
|
129
149
|
set: {
|
|
130
|
-
search: (value) =>
|
|
131
|
-
|
|
132
|
-
|
|
150
|
+
search: (value) => {
|
|
151
|
+
return combineLatest([params.windowChanges, connectionInitialized])
|
|
152
|
+
.pipe(take(1), switchMap(([source]) => send(source, `ant/${clientId}/toolbar/search`, { value })))
|
|
153
|
+
.forEach(identity);
|
|
154
|
+
},
|
|
133
155
|
},
|
|
134
156
|
});
|
|
135
157
|
}
|
|
136
158
|
function handleAppStateChanges({ scope, params, clientId, connectionInitialized }) {
|
|
137
|
-
|
|
138
|
-
const appState = new BehaviorSubject({ timestamp: 0, state: (_a = params.appState) !== null && _a !== void 0 ? _a : '' });
|
|
159
|
+
const appState = new BehaviorSubject({ timestamp: 0, state: params.appState ?? '' });
|
|
139
160
|
scope
|
|
140
161
|
.on(`ant/${clientId}/state`)
|
|
141
|
-
.subscribe(({ data }) =>
|
|
162
|
+
.subscribe(({ data }) => data.timestamp > appState.value?.timestamp && appState.next(data));
|
|
142
163
|
scope
|
|
143
164
|
.on(`ant/${clientId}/state/get`, () => appState.value)
|
|
144
165
|
.subscribe();
|
|
@@ -156,19 +177,13 @@ function installSignalObservers(signal, { scope, params }) {
|
|
|
156
177
|
const observers = {};
|
|
157
178
|
const subscription = new Subscription();
|
|
158
179
|
const unsubscribe = signal.receive((s) => {
|
|
159
|
-
var _a;
|
|
160
180
|
if (s.observe && !subscription.closed) {
|
|
161
181
|
const { actions, id, random, type, scope: observeScope } = s.observe;
|
|
162
|
-
|
|
163
|
-
const wrappedSend = (...signals) => {
|
|
164
|
-
console.log('[host.ts] signal.send called with:', signals);
|
|
165
|
-
return signal.send(...signals);
|
|
166
|
-
};
|
|
167
|
-
const unobserve = params.newSignalObserver(type, id, actions !== null && actions !== void 0 ? actions : [...changes], wrappedSend, observeScope);
|
|
182
|
+
const unobserve = params.newSignalObserver(type, id, actions ?? [...changes], signal.send, observeScope);
|
|
168
183
|
Object.assign(observers, { [random]: unobserve });
|
|
169
184
|
}
|
|
170
185
|
else if (s.unobserve) {
|
|
171
|
-
|
|
186
|
+
observers[s.unobserve.random]?.();
|
|
172
187
|
delete observers[s.unobserve.random];
|
|
173
188
|
}
|
|
174
189
|
});
|
package/build/comms/models.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../../src/comms/models.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AACxC,OAAO,KAAK,EAAE,gBAAgB,EAAE,iCAA+B;AAC/D,OAAO,KAAK,EAAE,OAAO,EAAE,mCAAiC;AACxD,OAAO,KAAK,EAAE,YAAY,EAAE,mCAAiC;AAC7D,OAAO,KAAK,EAAE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,iBAAiB,CAAC,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,YAAY,CAAC,CAAA;AAE1H,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,OAAO,iBAAiB,CAAC,MAAM,CAAC,CAAA;IACtC,OAAO,EAAE,MAAM,CAAA;CAChB"}
|
|
@@ -1,19 +1,10 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
import { firstValueFrom } from 'rxjs';
|
|
11
2
|
export const recordServiceCalls = [
|
|
12
|
-
ifRecordsService('createRecord',
|
|
13
|
-
ifRecordsService('importRecords',
|
|
14
|
-
ifRecordsService('updateRecord',
|
|
15
|
-
ifRecordsService('deleteRecord',
|
|
16
|
-
ifRecordsService('deleteRecords',
|
|
3
|
+
ifRecordsService('createRecord', async (call, box, { args }) => call(args[0], args[1], args[2] || await getSelectedTask(box))),
|
|
4
|
+
ifRecordsService('importRecords', async (call, box, { args }) => call(args[0], args[1], args[2] || await getSelectedTask(box))),
|
|
5
|
+
ifRecordsService('updateRecord', async (call, box, { args }) => call(args[0], args[1], args[2], args[3] || await getSelectedTask(box))),
|
|
6
|
+
ifRecordsService('deleteRecord', async (call, box, { args }) => call(args[0], args[1] || await getSelectedTask(box))),
|
|
7
|
+
ifRecordsService('deleteRecords', async (call, box, { args }) => call(args[0], args[1], args[2], args[3] || await getSelectedTask(box))),
|
|
17
8
|
];
|
|
18
9
|
/**
|
|
19
10
|
* If an api call from RecordService needs to be called, the callback will be triggered. Otherwise the next on will be ran.
|
|
@@ -27,5 +18,5 @@ function ifRecordsService(key, fn) {
|
|
|
27
18
|
: next();
|
|
28
19
|
}
|
|
29
20
|
function getSelectedTask(box) {
|
|
30
|
-
return firstValueFrom(box.params.contextChanges).then(e =>
|
|
21
|
+
return firstValueFrom(box.params.contextChanges).then(e => e.selectedTask?.id);
|
|
31
22
|
}
|