@uxland/primary-shell 8.3.4 → 8.3.6
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 +18 -1
- package/dist/{component-Dv2Cw4dX.js → component-B4xPOzaR.js} +2 -2
- package/dist/{component-Dv2Cw4dX.js.map → component-B4xPOzaR.js.map} +1 -1
- package/dist/{index-CCC4rQo1.js → index-DsKLmCZe.js} +388 -388
- package/dist/index-DsKLmCZe.js.map +1 -0
- package/dist/index.js +1 -1
- package/dist/{plugin-D3sg1ev9.js → plugin-CRWxCmf1.js} +1058 -1055
- package/dist/plugin-CRWxCmf1.js.map +1 -0
- package/dist/primary/shell/src/api/import-data-manager/import-data-manager-impl.d.ts +3 -2
- package/dist/primary/shell/src/api/import-data-manager/import-data-manager.d.ts +6 -4
- package/package.json +6 -14
- package/dist/index-CCC4rQo1.js.map +0 -1
- package/dist/plugin-D3sg1ev9.js.map +0 -1
- package/src/UI/bootstrapper.ts +0 -14
- package/src/UI/components/bootstrapper.ts +0 -25
- package/src/UI/components/clinical-pathways-action-menu/clinical-pathways-action-menu.ts +0 -13
- package/src/UI/components/communication-action-menu/communication-action-menu.ts +0 -13
- package/src/UI/components/error-view/component.ts +0 -17
- package/src/UI/components/error-view/styles.css +0 -27
- package/src/UI/components/error-view/template.ts +0 -12
- package/src/UI/components/nav-divider/nav-divider.ts +0 -41
- package/src/UI/components/nav-divider/styles.css +0 -21
- package/src/UI/components/nav-divider/template.ts +0 -8
- package/src/UI/components/petitioner-action-menu/petitioner-action-menu.ts +0 -13
- package/src/UI/components/primaria-accordion/primaria-accordion.ts +0 -45
- package/src/UI/components/primaria-shell/constants.ts +0 -4
- package/src/UI/components/primaria-shell/primaria-shell.ts +0 -105
- package/src/UI/components/primaria-shell/shell-header/header-divider/header-divider.ts +0 -13
- package/src/UI/components/primaria-shell/shell-header/header-divider/styles.css +0 -5
- package/src/UI/components/primaria-shell/shell-header/header-divider/template.ts +0 -8
- package/src/UI/components/primaria-shell/shell-header/shell-header.ts +0 -71
- package/src/UI/components/primaria-shell/shell-header/styles.css +0 -45
- package/src/UI/components/primaria-shell/shell-header/template.ts +0 -37
- package/src/UI/components/primaria-shell/styles.css +0 -185
- package/src/UI/components/primaria-shell/template.ts +0 -72
- package/src/UI/components/sidenav-action-menu/sidenav-action-menu.ts +0 -62
- package/src/UI/components/sidenav-action-menu/styles.css +0 -25
- package/src/UI/components/sidenav-action-menu/template.ts +0 -24
- package/src/UI/fonts/fonts.css +0 -48
- package/src/UI/fonts/open-sans-v40-latin-300.woff2 +0 -0
- package/src/UI/fonts/open-sans-v40-latin-500.woff2 +0 -0
- package/src/UI/fonts/open-sans-v40-latin-600.woff2 +0 -0
- package/src/UI/fonts/open-sans-v40-latin-700.woff2 +0 -0
- package/src/UI/fonts/open-sans-v40-latin-800.woff2 +0 -0
- package/src/UI/fonts/open-sans-v40-latin-regular.woff2 +0 -0
- package/src/UI/images/Gencat_Logotip.svg +0 -70
- package/src/UI/images/Salut_Logotip.svg +0 -8
- package/src/UI/index.ts +0 -1
- package/src/UI/internal-views/administrative-nav-menu.ts +0 -302
- package/src/UI/internal-views/common-nav-menu.ts +0 -94
- package/src/UI/internal-views/doctor-nav-menu.ts +0 -297
- package/src/UI/internal-views/doctor-quick-action-menu.ts +0 -16
- package/src/UI/internal-views/handle-views.ts +0 -24
- package/src/UI/shared-components/bootstrapper.ts +0 -18
- package/src/UI/shared-components/index.ts +0 -1
- package/src/UI/shared-components/primaria-character-limit-badge/primaria-character-limit-badge.ts +0 -27
- package/src/UI/shared-components/primaria-character-limit-badge/styles.css +0 -8
- package/src/UI/shared-components/primaria-content-switcher/primaria-content-switcher.ts +0 -78
- package/src/UI/shared-components/primaria-nav-item/primaria-nav-item.ts +0 -71
- package/src/UI/shared-components/primaria-nav-item/styles.css +0 -25
- package/src/UI/shared-components/primaria-nav-item/template.ts +0 -27
- package/src/UI/shared-components/primaria-nav-tree-menu/primaria-nav-tree-menu.ts +0 -41
- package/src/UI/shared-components/primaria-nav-tree-menu/styles.css +0 -11
- package/src/UI/shared-components/primaria-nav-tree-menu/template.ts +0 -46
- package/src/UI/shared-components/primaria-region/index.ts +0 -1
- package/src/UI/shared-components/primaria-region/primaria-region.ts +0 -199
- package/src/UI/shared-components/primaria-text-editor/primaria-rich-text-editor.ts +0 -261
- package/src/UI/shared-components/primaria-text-editor/styles.css +0 -966
- package/src/UI/shared-components/primaria-text-editor/template.ts +0 -8
- package/src/UI/shared-components/primaria-text-editor/utils.ts +0 -39
- package/src/UI/shared-components/quick-action-item/quick-action-item.ts +0 -21
- package/src/UI/shared-components/quick-action-item/template.ts +0 -8
- package/src/UI/shared-components/typings.ts +0 -19
- package/src/api/activity-monitor/activity-monitor.test.ts +0 -67
- package/src/api/activity-monitor/activity-monitor.ts +0 -26
- package/src/api/api.test.ts +0 -37
- package/src/api/api.ts +0 -119
- package/src/api/broker/broker-events.ts +0 -39
- package/src/api/broker/broker-requests.ts +0 -20
- package/src/api/broker/factory.test.ts +0 -378
- package/src/api/broker/factory.ts +0 -151
- package/src/api/broker/primaria-broker.ts +0 -20
- package/src/api/context-manager/context-manager.test.ts +0 -86
- package/src/api/context-manager/context-manager.ts +0 -42
- package/src/api/ecap-event-manager/ecap-event-manager.test.ts +0 -100
- package/src/api/ecap-event-manager/ecap-event-manager.ts +0 -58
- package/src/api/ecap-event-manager/typings.ts +0 -6
- package/src/api/exit-guard-manager/exit-guard-manager.test.ts +0 -75
- package/src/api/exit-guard-manager/exit-guard-manager.ts +0 -31
- package/src/api/global-state/global-state.test.ts +0 -45
- package/src/api/global-state/global-state.ts +0 -38
- package/src/api/http-client/http-client.test.ts +0 -196
- package/src/api/http-client/http-client.ts +0 -97
- package/src/api/import-data-manager/component/component.ts +0 -29
- package/src/api/import-data-manager/component/styles.css +0 -79
- package/src/api/import-data-manager/component/template.ts +0 -49
- package/src/api/import-data-manager/import-data-manager-impl.test.ts +0 -364
- package/src/api/import-data-manager/import-data-manager-impl.ts +0 -121
- package/src/api/import-data-manager/import-data-manager.ts +0 -42
- package/src/api/import-data-manager/index.ts +0 -2
- package/src/api/interaction-service/confirmation-message.tsx +0 -5
- package/src/api/interaction-service/index.ts +0 -1
- package/src/api/interaction-service/interaction-service-impl.tsx +0 -260
- package/src/api/interaction-service/interaction-service.ts +0 -52
- package/src/api/interaction-service/modal-styles.css +0 -97
- package/src/api/localization/localization.test.ts +0 -61
- package/src/api/localization/localization.ts +0 -58
- package/src/api/notification-service/notification-service-impl.test.ts +0 -84
- package/src/api/notification-service/notification-service.ts +0 -6
- package/src/api/notification-service/notification.service-impl.ts +0 -67
- package/src/api/pdf-viewer-manager/constants.ts +0 -1
- package/src/api/pdf-viewer-manager/events.ts +0 -5
- package/src/api/pdf-viewer-manager/handle-views.ts +0 -32
- package/src/api/pdf-viewer-manager/pdf-viewer-manager.test.ts +0 -126
- package/src/api/pdf-viewer-manager/pdf-viewer-manager.ts +0 -96
- package/src/api/pdf-viewer-manager/pdf-visor/pdf-selector/pdf-selector.ts +0 -39
- package/src/api/pdf-viewer-manager/pdf-visor/pdf-selector/styles.css +0 -45
- package/src/api/pdf-viewer-manager/pdf-visor/pdf-selector/template.ts +0 -32
- package/src/api/pdf-viewer-manager/pdf-visor/pdf-visor.ts +0 -122
- package/src/api/pdf-viewer-manager/pdf-visor/styles.css +0 -29
- package/src/api/pdf-viewer-manager/pdf-visor/utils.ts +0 -16
- package/src/api/quick-action-busy-manager/quick-action-busy-manager.test.ts +0 -61
- package/src/api/quick-action-busy-manager/quick-action-busy-manager.ts +0 -45
- package/src/api/region-manager/region-manager.test.ts +0 -239
- package/src/api/region-manager/region-manager.ts +0 -263
- package/src/api/region-manager/regions.ts +0 -30
- package/src/api/region-manager/remove-view-idempotency.test.ts +0 -98
- package/src/api/session-refresh-timer/session-refresh-timer.test.ts +0 -102
- package/src/api/session-refresh-timer/session-refresh-timer.ts +0 -75
- package/src/api/token-manager/token-manager.test.ts +0 -146
- package/src/api/token-manager/token-manager.ts +0 -70
- package/src/api/user-manager/user-manager.ts +0 -79
- package/src/bootstrapper.ts +0 -41
- package/src/constants.ts +0 -1
- package/src/disposer.ts +0 -19
- package/src/features/bootstrapper.ts +0 -21
- package/src/features/exit/bootstrapper.ts +0 -17
- package/src/features/exit/handler.test.ts +0 -187
- package/src/features/exit/handler.ts +0 -58
- package/src/features/exit/request.ts +0 -10
- package/src/features/get-patient-cip/action.ts +0 -5
- package/src/features/get-user-info/backend-adapter.ts +0 -48
- package/src/features/get-user-info/bootstrapper.ts +0 -20
- package/src/features/get-user-info/handler.test.ts +0 -66
- package/src/features/get-user-info/handler.ts +0 -23
- package/src/features/get-user-info/model.ts +0 -10
- package/src/features/get-user-info/pds-token.ts +0 -28
- package/src/features/get-user-info/request.ts +0 -4
- package/src/features/get-visi-id/action.ts +0 -11
- package/src/features/navigate-to-ecap/navigate-to-ecap.ts +0 -21
- package/src/features/utils.ts +0 -27
- package/src/handle-plugins.ts +0 -82
- package/src/index.ts +0 -101
- package/src/infrastructure/ioc/container.ts +0 -14
- package/src/infrastructure/ioc/types.ts +0 -5
- package/src/locales.ts +0 -70
- package/src/types/custom.d.ts +0 -30
|
@@ -1,378 +0,0 @@
|
|
|
1
|
-
import { IEvent, IRequest } from "@uxland/harmonix";
|
|
2
|
-
import { Mock, beforeEach, describe, expect, it, vi } from "vitest";
|
|
3
|
-
import { createBroker } from "./factory";
|
|
4
|
-
import { PrimariaBroker } from "./primaria-broker";
|
|
5
|
-
|
|
6
|
-
describe("Broker test", () => {
|
|
7
|
-
let sut: PrimariaBroker;
|
|
8
|
-
|
|
9
|
-
beforeEach(() => {
|
|
10
|
-
sut = createBroker().broker;
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
describe("Event bus test", () => {
|
|
14
|
-
describe("Test by Event instance", () => {
|
|
15
|
-
class MyEvent implements IEvent {
|
|
16
|
-
constructor(public greeting: string) {}
|
|
17
|
-
}
|
|
18
|
-
describe("Given some subscriptions for an event", () => {
|
|
19
|
-
let handlers: Mock[];
|
|
20
|
-
beforeEach(() => {
|
|
21
|
-
handlers = Array.from({ length: 5 }).map(() => {
|
|
22
|
-
const handler = vi.fn();
|
|
23
|
-
sut.subscribe(MyEvent, handler);
|
|
24
|
-
return handler;
|
|
25
|
-
});
|
|
26
|
-
});
|
|
27
|
-
describe("When event is published", () => {
|
|
28
|
-
beforeEach(() => {
|
|
29
|
-
sut.publish(new MyEvent("Hello"));
|
|
30
|
-
});
|
|
31
|
-
it("Then handler is called", () => {
|
|
32
|
-
for (const handler of handlers) {
|
|
33
|
-
expect(handler).toBeCalledWith({ greeting: "Hello" });
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
describe("Test by event name", () => {
|
|
40
|
-
describe("Given some subscriptions for an event", () => {
|
|
41
|
-
let handlers: Mock[];
|
|
42
|
-
beforeEach(() => {
|
|
43
|
-
handlers = Array.from({ length: 5 }).map(() => {
|
|
44
|
-
const handler = vi.fn();
|
|
45
|
-
sut.subscribe("MyEvent", handler);
|
|
46
|
-
return handler;
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
describe("When event is published", () => {
|
|
50
|
-
beforeEach(() => {
|
|
51
|
-
sut.publish("MyEvent", { greeting: "Hello" });
|
|
52
|
-
});
|
|
53
|
-
it("Then handler is called", () => {
|
|
54
|
-
for (const handler of handlers) {
|
|
55
|
-
expect(handler).toBeCalledWith({ greeting: "Hello" });
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
describe("Given no subscriptions for an event", () => {
|
|
61
|
-
it("When event is published, Then nothing happens", () => {
|
|
62
|
-
expect(() => sut.publish("MyEvent", { greeting: "Hello" })).not.toThrow();
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
describe("Message broker test", () => {
|
|
68
|
-
describe("Test by Request instance", () => {
|
|
69
|
-
class MyRequest implements IRequest<string> {
|
|
70
|
-
constructor(public greeting: string) {}
|
|
71
|
-
}
|
|
72
|
-
describe("Given a handler for a request", () => {
|
|
73
|
-
let handler: Mock;
|
|
74
|
-
const greeting = "World!";
|
|
75
|
-
beforeEach(() => {
|
|
76
|
-
handler = vi.fn();
|
|
77
|
-
handler.mockResolvedValue(`Hello ${greeting}`);
|
|
78
|
-
sut.registerRequest(MyRequest, handler);
|
|
79
|
-
});
|
|
80
|
-
describe("When request is sent", () => {
|
|
81
|
-
let result: string;
|
|
82
|
-
beforeEach(async () => {
|
|
83
|
-
result = await sut.send(new MyRequest(greeting));
|
|
84
|
-
});
|
|
85
|
-
it("Then handler is called", () => {
|
|
86
|
-
expect(handler).toBeCalledWith({ greeting });
|
|
87
|
-
});
|
|
88
|
-
it("Then result is returned", () => {
|
|
89
|
-
expect(result).toBe(`Hello ${greeting}`);
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
});
|
|
93
|
-
it("Should fail if a request is registered twice", () => {
|
|
94
|
-
sut.registerRequest(MyRequest, () => {});
|
|
95
|
-
expect(() => sut.registerRequest(MyRequest, () => {})).toThrowError();
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
describe("Test by request name", () => {
|
|
100
|
-
const requestName = "MyRequest";
|
|
101
|
-
describe("Given a handler for a request", () => {
|
|
102
|
-
let handler: Mock;
|
|
103
|
-
const greeting = "World!";
|
|
104
|
-
|
|
105
|
-
beforeEach(() => {
|
|
106
|
-
handler = vi.fn();
|
|
107
|
-
handler.mockResolvedValue(`Hello ${greeting}`);
|
|
108
|
-
sut.registerRequest(requestName, handler);
|
|
109
|
-
});
|
|
110
|
-
describe("When request is sent", () => {
|
|
111
|
-
let result: string;
|
|
112
|
-
beforeEach(async () => {
|
|
113
|
-
result = await sut.send(requestName, { greeting });
|
|
114
|
-
});
|
|
115
|
-
it("Then handler is called", () => {
|
|
116
|
-
expect(handler).toBeCalledWith({ greeting });
|
|
117
|
-
});
|
|
118
|
-
it("Then result is returned", () => {
|
|
119
|
-
expect(result).toBe(`Hello ${greeting}`);
|
|
120
|
-
});
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
it("Should fail if a request is registered twice", () => {
|
|
124
|
-
sut.registerRequest(requestName, () => {});
|
|
125
|
-
expect(() => sut.registerRequest(requestName, () => {})).toThrowError();
|
|
126
|
-
});
|
|
127
|
-
});
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
describe("Disposal and re-registration", () => {
|
|
131
|
-
class MyRequest implements IRequest<string> {
|
|
132
|
-
constructor(public greeting: string) {}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
it("disposing a request handler lets the same request be registered again (teardown + bootstrap)", () => {
|
|
136
|
-
const disposable = sut.registerRequest(MyRequest, () => "first");
|
|
137
|
-
disposable.dispose();
|
|
138
|
-
// Re-registering after dispose must NOT throw (the dispose-bug regression).
|
|
139
|
-
expect(() => sut.registerRequest(MyRequest, () => "second")).not.toThrow();
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
it("routes to the handler registered after a dispose/re-register cycle", async () => {
|
|
143
|
-
const first = vi.fn().mockResolvedValue("first");
|
|
144
|
-
const second = vi.fn().mockResolvedValue("second");
|
|
145
|
-
const disposable = sut.registerRequest(MyRequest, first);
|
|
146
|
-
disposable.dispose();
|
|
147
|
-
sut.registerRequest(MyRequest, second);
|
|
148
|
-
|
|
149
|
-
const result = await sut.send(new MyRequest("hi"));
|
|
150
|
-
|
|
151
|
-
expect(result).toBe("second");
|
|
152
|
-
expect(first).not.toHaveBeenCalled();
|
|
153
|
-
expect(second).toHaveBeenCalledWith({ greeting: "hi" });
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
it("sending a request with no handler registered throws", async () => {
|
|
157
|
-
await expect(sut.send(new MyRequest("hi"))).rejects.toThrow();
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
it("sending after the only handler was disposed throws", async () => {
|
|
161
|
-
const disposable = sut.registerRequest(MyRequest, () => "x");
|
|
162
|
-
disposable.dispose();
|
|
163
|
-
await expect(sut.send(new MyRequest("hi"))).rejects.toThrow();
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
it("a stale disposer does not drop a newer registration for the same request", async () => {
|
|
167
|
-
const first = vi.fn().mockResolvedValue("first");
|
|
168
|
-
const second = vi.fn().mockResolvedValue("second");
|
|
169
|
-
const firstDisposable = sut.registerRequest(MyRequest, first);
|
|
170
|
-
firstDisposable.dispose();
|
|
171
|
-
sut.registerRequest(MyRequest, second);
|
|
172
|
-
// Disposing the already-disposed first handler must not remove `second`.
|
|
173
|
-
firstDisposable.dispose();
|
|
174
|
-
|
|
175
|
-
const result = await sut.send(new MyRequest("hi"));
|
|
176
|
-
expect(result).toBe("second");
|
|
177
|
-
});
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
describe("Event subscription disposal", () => {
|
|
181
|
-
class MyEvent implements IEvent {
|
|
182
|
-
constructor(public greeting: string) {}
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
it("a disposed subscriber stops receiving events while the rest keep receiving them", async () => {
|
|
186
|
-
const kept = vi.fn();
|
|
187
|
-
const removed = vi.fn();
|
|
188
|
-
sut.subscribe(MyEvent, kept);
|
|
189
|
-
const disposable = sut.subscribe(MyEvent, removed);
|
|
190
|
-
|
|
191
|
-
disposable.dispose();
|
|
192
|
-
await sut.publish(new MyEvent("Hello"));
|
|
193
|
-
|
|
194
|
-
expect(kept).toHaveBeenCalledWith({ greeting: "Hello" });
|
|
195
|
-
expect(removed).not.toHaveBeenCalled();
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
it("publishing an event instance with no subscribers does not throw", () => {
|
|
199
|
-
expect(() => sut.publish(new MyEvent("Hello"))).not.toThrow();
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
it("the same handler can re-subscribe after disposing", async () => {
|
|
203
|
-
const handler = vi.fn();
|
|
204
|
-
const disposable = sut.subscribe("MyEvent", handler);
|
|
205
|
-
disposable.dispose();
|
|
206
|
-
sut.subscribe("MyEvent", handler);
|
|
207
|
-
|
|
208
|
-
await sut.publish("MyEvent", { greeting: "Hello" });
|
|
209
|
-
|
|
210
|
-
expect(handler).toHaveBeenCalledTimes(1);
|
|
211
|
-
expect(handler).toHaveBeenCalledWith({ greeting: "Hello" });
|
|
212
|
-
});
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
describe("clear", () => {
|
|
216
|
-
class MyRequest implements IRequest<string> {}
|
|
217
|
-
|
|
218
|
-
it("removes all registrations so the registry can be reused cleanly", () => {
|
|
219
|
-
const { broker, clear } = createBroker();
|
|
220
|
-
broker.registerRequest(MyRequest, () => "x");
|
|
221
|
-
clear();
|
|
222
|
-
// After a clear, registering the same request again must not throw.
|
|
223
|
-
expect(() => broker.registerRequest(MyRequest, () => "y")).not.toThrow();
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
it("is not reachable from the broker plugins receive", () => {
|
|
227
|
-
expect("clear" in sut).toBe(false);
|
|
228
|
-
expect("_clear" in sut).toBe(false);
|
|
229
|
-
});
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
describe("Request handler semantics", () => {
|
|
233
|
-
class MyRequest implements IRequest<string> {
|
|
234
|
-
constructor(public greeting: string) {}
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
it("rejects when the handler throws synchronously", async () => {
|
|
238
|
-
sut.registerRequest(MyRequest, () => {
|
|
239
|
-
throw new Error("boom");
|
|
240
|
-
});
|
|
241
|
-
await expect(sut.send(new MyRequest("x"))).rejects.toThrow("boom");
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
it("rejects when the handler returns a rejected promise", async () => {
|
|
245
|
-
sut.registerRequest(MyRequest, async () => {
|
|
246
|
-
throw new Error("async boom");
|
|
247
|
-
});
|
|
248
|
-
await expect(sut.send(new MyRequest("x"))).rejects.toThrow("async boom");
|
|
249
|
-
});
|
|
250
|
-
|
|
251
|
-
it("resolves a synchronous (non-promise) handler return value", async () => {
|
|
252
|
-
sut.registerRequest(MyRequest, () => "sync-value");
|
|
253
|
-
await expect(sut.send(new MyRequest("x"))).resolves.toBe("sync-value");
|
|
254
|
-
});
|
|
255
|
-
});
|
|
256
|
-
|
|
257
|
-
describe("Publish semantics", () => {
|
|
258
|
-
it("resolves only after async subscribers have completed", async () => {
|
|
259
|
-
let completed = false;
|
|
260
|
-
sut.subscribe("evt", async () => {
|
|
261
|
-
await Promise.resolve();
|
|
262
|
-
completed = true;
|
|
263
|
-
});
|
|
264
|
-
await sut.publish("evt", {});
|
|
265
|
-
expect(completed).toBe(true);
|
|
266
|
-
});
|
|
267
|
-
|
|
268
|
-
it("isolates a throwing subscriber: the others are still notified and publish does not reject", async () => {
|
|
269
|
-
const errorSpy = vi.spyOn(console, "error").mockImplementation(() => {});
|
|
270
|
-
const before = vi.fn();
|
|
271
|
-
const after = vi.fn();
|
|
272
|
-
sut.subscribe("evt", before);
|
|
273
|
-
sut.subscribe("evt", () => {
|
|
274
|
-
throw new Error("bad subscriber");
|
|
275
|
-
});
|
|
276
|
-
sut.subscribe("evt", () => Promise.reject(new Error("bad async subscriber")));
|
|
277
|
-
sut.subscribe("evt", after);
|
|
278
|
-
|
|
279
|
-
await expect(sut.publish("evt", { a: 1 })).resolves.toBeUndefined();
|
|
280
|
-
|
|
281
|
-
expect(before).toHaveBeenCalledWith({ a: 1 });
|
|
282
|
-
expect(after).toHaveBeenCalledWith({ a: 1 });
|
|
283
|
-
expect(errorSpy).toHaveBeenCalledTimes(2);
|
|
284
|
-
errorSpy.mockRestore();
|
|
285
|
-
});
|
|
286
|
-
|
|
287
|
-
it("a subscriber added during dispatch is not invoked in the same round (snapshot)", async () => {
|
|
288
|
-
const added = vi.fn();
|
|
289
|
-
const adder = vi.fn(() => {
|
|
290
|
-
sut.subscribe("evt", added);
|
|
291
|
-
});
|
|
292
|
-
sut.subscribe("evt", adder);
|
|
293
|
-
|
|
294
|
-
await sut.publish("evt", {});
|
|
295
|
-
expect(adder).toHaveBeenCalledTimes(1);
|
|
296
|
-
expect(added).not.toHaveBeenCalled();
|
|
297
|
-
|
|
298
|
-
await sut.publish("evt", {});
|
|
299
|
-
expect(added).toHaveBeenCalledTimes(1);
|
|
300
|
-
});
|
|
301
|
-
|
|
302
|
-
it("a subscriber that disposes itself during dispatch is still called that round but not the next", async () => {
|
|
303
|
-
const handler = vi.fn(() => disposable.dispose());
|
|
304
|
-
const disposable = sut.subscribe("evt", handler);
|
|
305
|
-
|
|
306
|
-
await sut.publish("evt", {});
|
|
307
|
-
await sut.publish("evt", {});
|
|
308
|
-
expect(handler).toHaveBeenCalledTimes(1);
|
|
309
|
-
});
|
|
310
|
-
});
|
|
311
|
-
|
|
312
|
-
describe("Namespace isolation", () => {
|
|
313
|
-
it("event class keys and event string keys are independent", async () => {
|
|
314
|
-
class Evt implements IEvent {}
|
|
315
|
-
const classHandler = vi.fn();
|
|
316
|
-
const stringHandler = vi.fn();
|
|
317
|
-
sut.subscribe(Evt, classHandler);
|
|
318
|
-
sut.subscribe("Evt", stringHandler);
|
|
319
|
-
|
|
320
|
-
await sut.publish(new Evt());
|
|
321
|
-
expect(classHandler).toHaveBeenCalledTimes(1);
|
|
322
|
-
expect(stringHandler).not.toHaveBeenCalled();
|
|
323
|
-
|
|
324
|
-
await sut.publish("Evt", {});
|
|
325
|
-
expect(stringHandler).toHaveBeenCalledTimes(1);
|
|
326
|
-
expect(classHandler).toHaveBeenCalledTimes(1);
|
|
327
|
-
});
|
|
328
|
-
|
|
329
|
-
it("the request registry and the event registry do not collide for the same name", async () => {
|
|
330
|
-
const requestHandler = vi.fn().mockResolvedValue("r");
|
|
331
|
-
const eventHandler = vi.fn();
|
|
332
|
-
sut.registerRequest("Shared", requestHandler);
|
|
333
|
-
sut.subscribe("Shared", eventHandler);
|
|
334
|
-
|
|
335
|
-
await sut.send("Shared", { v: 1 });
|
|
336
|
-
expect(requestHandler).toHaveBeenCalledWith({ v: 1 });
|
|
337
|
-
expect(eventHandler).not.toHaveBeenCalled();
|
|
338
|
-
|
|
339
|
-
await sut.publish("Shared", { v: 2 });
|
|
340
|
-
expect(eventHandler).toHaveBeenCalledWith({ v: 2 });
|
|
341
|
-
expect(requestHandler).toHaveBeenCalledTimes(1);
|
|
342
|
-
});
|
|
343
|
-
});
|
|
344
|
-
|
|
345
|
-
describe("Constructor-identity keying", () => {
|
|
346
|
-
it("keys requests by constructor identity, not by class name (two same-named classes coexist)", async () => {
|
|
347
|
-
const makeDup = () => class Dup implements IRequest<string> {};
|
|
348
|
-
const A = makeDup();
|
|
349
|
-
const B = makeDup();
|
|
350
|
-
expect(A.name).toBe(B.name); // both named "Dup"
|
|
351
|
-
|
|
352
|
-
const handlerA = vi.fn().mockResolvedValue("A");
|
|
353
|
-
const handlerB = vi.fn().mockResolvedValue("B");
|
|
354
|
-
sut.registerRequest(A, handlerA);
|
|
355
|
-
// The old name-based registry would have thrown here; identity keying must not.
|
|
356
|
-
expect(() => sut.registerRequest(B, handlerB)).not.toThrow();
|
|
357
|
-
|
|
358
|
-
await expect(sut.send(new A())).resolves.toBe("A");
|
|
359
|
-
await expect(sut.send(new B())).resolves.toBe("B");
|
|
360
|
-
});
|
|
361
|
-
});
|
|
362
|
-
|
|
363
|
-
describe("Idempotent disposal", () => {
|
|
364
|
-
class MyRequest implements IRequest<string> {}
|
|
365
|
-
|
|
366
|
-
it("disposing a request handler twice is safe", () => {
|
|
367
|
-
const disposable = sut.registerRequest(MyRequest, () => "x");
|
|
368
|
-
disposable.dispose();
|
|
369
|
-
expect(() => disposable.dispose()).not.toThrow();
|
|
370
|
-
});
|
|
371
|
-
|
|
372
|
-
it("disposing an event subscription twice is safe", () => {
|
|
373
|
-
const disposable = sut.subscribe("evt", () => {});
|
|
374
|
-
disposable.dispose();
|
|
375
|
-
expect(() => disposable.dispose()).not.toThrow();
|
|
376
|
-
});
|
|
377
|
-
});
|
|
378
|
-
});
|
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
import { IEvent, IEventClass, IRequest, IRequestClass } from "@uxland/harmonix";
|
|
2
|
-
import { BROKER_EVENTS } from "./broker-events";
|
|
3
|
-
import { BROKER_REQUESTS } from "./broker-requests";
|
|
4
|
-
import type { BrokerDisposableHandler, PrimariaBroker } from "./primaria-broker";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* In-process message broker.
|
|
8
|
-
*
|
|
9
|
-
* The whole plugin system runs in a single JS heap (plugins are ES modules,
|
|
10
|
-
* no postMessage / workers / serialization), so dispatch is a plain map lookup.
|
|
11
|
-
*
|
|
12
|
-
* A message is keyed either by its **class constructor** (typed, intra-plugin
|
|
13
|
-
* requests/events) or by a **string name** (decoupled, cross-plugin events).
|
|
14
|
-
* Both live in the same map: `send(new Foo())` keys on `instance.constructor`,
|
|
15
|
-
* which is the very class passed to `registerRequest(Foo, …)`, so identity
|
|
16
|
-
* matches without any reflection or dynamically generated classes.
|
|
17
|
-
*
|
|
18
|
-
* - Requests (request/response): exactly one handler per key.
|
|
19
|
-
* - Events (publish/subscribe): any number of subscribers per key.
|
|
20
|
-
*
|
|
21
|
-
* Handlers receive a shallow copy of the message data (`{ ...instance }` for a
|
|
22
|
-
* class, or the raw payload for the string API), matching the previous
|
|
23
|
-
* behaviour exactly.
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
// biome-ignore lint/complexity/noBannedTypes: a class constructor is a Function, used here as a map key
|
|
27
|
-
type MessageKey = Function | string;
|
|
28
|
-
|
|
29
|
-
// biome-ignore lint/suspicious/noExplicitAny: handlers are typed at the public-interface boundary
|
|
30
|
-
type Handler = (message: any) => unknown;
|
|
31
|
-
|
|
32
|
-
class Broker implements PrimariaBroker {
|
|
33
|
-
public readonly events = BROKER_EVENTS;
|
|
34
|
-
public readonly requests = BROKER_REQUESTS;
|
|
35
|
-
|
|
36
|
-
constructor(
|
|
37
|
-
/** One handler per request type (request/response). */
|
|
38
|
-
private readonly requestHandlers: Map<MessageKey, Handler>,
|
|
39
|
-
/** Many subscribers per event type (publish/subscribe). */
|
|
40
|
-
private readonly eventSubscribers: Map<MessageKey, Set<Handler>>,
|
|
41
|
-
) {}
|
|
42
|
-
|
|
43
|
-
// ---- Request / response ---------------------------------------------------
|
|
44
|
-
|
|
45
|
-
send<TRequest extends IRequest<TResponse>, TResponse>(message: TRequest): Promise<TResponse>;
|
|
46
|
-
send<TPayload, TResponse>(requestName: string, payload: TPayload): Promise<TResponse>;
|
|
47
|
-
async send<TResponse>(request: IRequest<TResponse> | string, payload?: unknown): Promise<TResponse> {
|
|
48
|
-
const key: MessageKey = typeof request === "string" ? request : request.constructor;
|
|
49
|
-
const handler = this.requestHandlers.get(key);
|
|
50
|
-
if (!handler) {
|
|
51
|
-
const name = typeof request === "string" ? request : request.constructor?.name;
|
|
52
|
-
throw new Error(`Broker: no request handler registered for "${name}".`);
|
|
53
|
-
}
|
|
54
|
-
const message = typeof request === "string" ? { ...(payload as object) } : { ...request };
|
|
55
|
-
return (await handler(message)) as TResponse;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
registerRequest<TRequest extends IRequest<TResponse>, TResponse>(
|
|
59
|
-
request: IRequestClass<TRequest>,
|
|
60
|
-
handler: (message: TRequest) => TResponse | Promise<TResponse>,
|
|
61
|
-
): BrokerDisposableHandler;
|
|
62
|
-
registerRequest<TPayload, TResponse>(
|
|
63
|
-
requestName: string,
|
|
64
|
-
handler: (message: TPayload) => TResponse | Promise<TResponse>,
|
|
65
|
-
): BrokerDisposableHandler;
|
|
66
|
-
registerRequest(request: IRequestClass<unknown> | string, handler: Handler): BrokerDisposableHandler {
|
|
67
|
-
if (this.requestHandlers.has(request)) {
|
|
68
|
-
const name = typeof request === "string" ? request : request.name;
|
|
69
|
-
throw new Error(`Broker: a request handler is already registered for "${name}".`);
|
|
70
|
-
}
|
|
71
|
-
this.requestHandlers.set(request, handler);
|
|
72
|
-
return {
|
|
73
|
-
dispose: () => {
|
|
74
|
-
// Identity-guarded: a stale/duplicate dispose must not drop a handler
|
|
75
|
-
// registered later under the same key (after a teardown + bootstrap).
|
|
76
|
-
if (this.requestHandlers.get(request) === handler) {
|
|
77
|
-
this.requestHandlers.delete(request);
|
|
78
|
-
}
|
|
79
|
-
},
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// ---- Publish / subscribe --------------------------------------------------
|
|
84
|
-
|
|
85
|
-
publish<TEvent extends IEvent>(event: TEvent): Promise<void>;
|
|
86
|
-
publish<TPayload>(eventName: string, payload: TPayload): Promise<void>;
|
|
87
|
-
async publish(event: IEvent | string, payload?: unknown): Promise<void> {
|
|
88
|
-
const key: MessageKey = typeof event === "string" ? event : event.constructor;
|
|
89
|
-
const subscribers = this.eventSubscribers.get(key);
|
|
90
|
-
if (!subscribers || subscribers.size === 0) return;
|
|
91
|
-
const message = typeof event === "string" ? payload : { ...event };
|
|
92
|
-
const name = typeof event === "string" ? event : event.constructor?.name;
|
|
93
|
-
// Snapshot the set: a subscriber may subscribe/dispose while we iterate.
|
|
94
|
-
// Each subscriber is isolated: a throwing/rejecting subscriber is logged but
|
|
95
|
-
// never blocks the others nor rejects publish() (fire-and-forget event bus).
|
|
96
|
-
await Promise.all(
|
|
97
|
-
[...subscribers].map(async (handler) => {
|
|
98
|
-
try {
|
|
99
|
-
await handler(message);
|
|
100
|
-
} catch (error) {
|
|
101
|
-
console.error(`Broker: a subscriber for event "${name}" threw and was isolated.`, error);
|
|
102
|
-
}
|
|
103
|
-
}),
|
|
104
|
-
);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
subscribe<TEvent extends IEvent>(
|
|
108
|
-
event: IEventClass,
|
|
109
|
-
handler: (message: TEvent) => void | Promise<void>,
|
|
110
|
-
): BrokerDisposableHandler;
|
|
111
|
-
subscribe<TPayload>(eventName: string, handler: (message: TPayload) => void | Promise<void>): BrokerDisposableHandler;
|
|
112
|
-
subscribe(event: IEventClass | string, handler: Handler): BrokerDisposableHandler {
|
|
113
|
-
let subscribers = this.eventSubscribers.get(event);
|
|
114
|
-
if (!subscribers) {
|
|
115
|
-
subscribers = new Set();
|
|
116
|
-
this.eventSubscribers.set(event, subscribers);
|
|
117
|
-
}
|
|
118
|
-
subscribers.add(handler);
|
|
119
|
-
return {
|
|
120
|
-
dispose: () => {
|
|
121
|
-
const current = this.eventSubscribers.get(event);
|
|
122
|
-
if (!current) return;
|
|
123
|
-
current.delete(handler);
|
|
124
|
-
if (current.size === 0) this.eventSubscribers.delete(event);
|
|
125
|
-
},
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export interface BrokerHandle {
|
|
131
|
-
/** The broker every plugin receives. */
|
|
132
|
-
broker: PrimariaBroker;
|
|
133
|
-
/**
|
|
134
|
-
* Removes every registration. Used on shell teardown so a re-initialization
|
|
135
|
-
* starts from a clean registry (the broker is a module-level singleton).
|
|
136
|
-
* Host-only: it lives outside the broker so no plugin receives it.
|
|
137
|
-
*/
|
|
138
|
-
clear: () => void;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
export const createBroker = (): BrokerHandle => {
|
|
142
|
-
const requestHandlers = new Map<MessageKey, Handler>();
|
|
143
|
-
const eventSubscribers = new Map<MessageKey, Set<Handler>>();
|
|
144
|
-
return {
|
|
145
|
-
broker: new Broker(requestHandlers, eventSubscribers),
|
|
146
|
-
clear: () => {
|
|
147
|
-
requestHandlers.clear();
|
|
148
|
-
eventSubscribers.clear();
|
|
149
|
-
},
|
|
150
|
-
};
|
|
151
|
-
};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { HarmonixBroker } from "@uxland/harmonix";
|
|
2
|
-
import { type BrokerEvents } from "./broker-events";
|
|
3
|
-
import { type BrokerRequests } from "./broker-requests";
|
|
4
|
-
|
|
5
|
-
export interface PrimariaBroker extends HarmonixBroker {
|
|
6
|
-
/** Noms dels events: `publish` / `subscribe`. */
|
|
7
|
-
events: BrokerEvents;
|
|
8
|
-
/** Noms de les requests: `send` / `registerRequest`. */
|
|
9
|
-
requests: BrokerRequests;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export type {
|
|
13
|
-
HarmonixBroker,
|
|
14
|
-
IEvent,
|
|
15
|
-
IEventClass,
|
|
16
|
-
IRequest,
|
|
17
|
-
IRequestClass,
|
|
18
|
-
} from "@uxland/harmonix";
|
|
19
|
-
|
|
20
|
-
export type { BrokerDisposableHandler } from "@uxland/harmonix";
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach } from "vitest";
|
|
2
|
-
import { createContextManager, EcapContext } from "./context-manager";
|
|
3
|
-
|
|
4
|
-
describe("PrimariaContextManager", () => {
|
|
5
|
-
let contextManager: ReturnType<typeof createContextManager>;
|
|
6
|
-
|
|
7
|
-
beforeEach(() => {
|
|
8
|
-
contextManager = createContextManager();
|
|
9
|
-
// Reset context before each test
|
|
10
|
-
contextManager.initializeContext({});
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
describe("initializeContext", () => {
|
|
14
|
-
it("should initialize context with provided data", () => {
|
|
15
|
-
const context: EcapContext = {
|
|
16
|
-
visi_id: "12345",
|
|
17
|
-
signador: "Dr. Smith",
|
|
18
|
-
campanya: "2024-Q1",
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
contextManager.initializeContext(context);
|
|
22
|
-
|
|
23
|
-
expect(contextManager.getContext()).toEqual(context);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it("should handle partial context data", () => {
|
|
27
|
-
const context: EcapContext = {
|
|
28
|
-
visi_id: "12345",
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
contextManager.initializeContext(context);
|
|
32
|
-
const result = contextManager.getContext();
|
|
33
|
-
|
|
34
|
-
expect(result.visi_id).toBe("12345");
|
|
35
|
-
expect(result.signador).toBeUndefined();
|
|
36
|
-
expect(result.campanya).toBeUndefined();
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
describe("getContext", () => {
|
|
41
|
-
it("should return a read-only copy of context", () => {
|
|
42
|
-
const context: EcapContext = {
|
|
43
|
-
visi_id: "12345",
|
|
44
|
-
signador: "Dr. Smith",
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
contextManager.initializeContext(context);
|
|
48
|
-
const returnedContext = contextManager.getContext();
|
|
49
|
-
|
|
50
|
-
expect(returnedContext).toEqual(context);
|
|
51
|
-
expect(returnedContext).not.toBe(context); // Ensure it's a copy
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it("should return empty object if not initialized", () => {
|
|
55
|
-
const context = contextManager.getContext();
|
|
56
|
-
expect(context).toEqual({});
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
describe("context properties access", () => {
|
|
61
|
-
it("should access visit ID through context", () => {
|
|
62
|
-
contextManager.initializeContext({ visi_id: "12345" });
|
|
63
|
-
const context = contextManager.getContext();
|
|
64
|
-
expect(context.visi_id).toBe("12345");
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it("should access signador through context", () => {
|
|
68
|
-
contextManager.initializeContext({ signador: "Dr. Smith" });
|
|
69
|
-
const context = contextManager.getContext();
|
|
70
|
-
expect(context.signador).toBe("Dr. Smith");
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it("should access campanya through context", () => {
|
|
74
|
-
contextManager.initializeContext({ campanya: "2024-Q1" });
|
|
75
|
-
const context = contextManager.getContext();
|
|
76
|
-
expect(context.campanya).toBe("2024-Q1");
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
it("should return undefined for unset properties", () => {
|
|
80
|
-
const context = contextManager.getContext();
|
|
81
|
-
expect(context.visi_id).toBeUndefined();
|
|
82
|
-
expect(context.signador).toBeUndefined();
|
|
83
|
-
expect(context.campanya).toBeUndefined();
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
});
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
export interface EcapContext {
|
|
2
|
-
visi_id?: string;
|
|
3
|
-
hes_appointment_id?: string;
|
|
4
|
-
signador?: string;
|
|
5
|
-
campanya?: string;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export abstract class PrimariaContextManager {
|
|
9
|
-
abstract getContext(): Readonly<EcapContext>;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
class PrimariaContextManagerImpl implements PrimariaContextManager {
|
|
13
|
-
private context: EcapContext = {};
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Initializes the context with the provided ECAP context data.
|
|
17
|
-
* This should only be called once during shell initialization.
|
|
18
|
-
*
|
|
19
|
-
* @param {EcapContext} context - The context data from ECAP
|
|
20
|
-
* @return {void}
|
|
21
|
-
*/
|
|
22
|
-
public initializeContext(context: EcapContext): void {
|
|
23
|
-
this.context = { ...context };
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Returns a read-only copy of the entire ECAP context.
|
|
28
|
-
*
|
|
29
|
-
* @return {Readonly<EcapContext>} The context object
|
|
30
|
-
*/
|
|
31
|
-
getContext(): Readonly<EcapContext> {
|
|
32
|
-
return { ...this.context };
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
let contextManager: PrimariaContextManagerImpl;
|
|
37
|
-
|
|
38
|
-
export const createContextManager = (): PrimariaContextManagerImpl => {
|
|
39
|
-
if (contextManager) return contextManager;
|
|
40
|
-
contextManager = new PrimariaContextManagerImpl();
|
|
41
|
-
return contextManager;
|
|
42
|
-
};
|