@flighthq/ipc 0.5.1-edge.1059.c56d3cd → 0.5.1-edge.1350.8ce488b
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 +2 -2
- package/dist/ipc.d.ts +7 -7
- package/dist/ipc.d.ts.map +1 -1
- package/dist/ipc.js +15 -21
- package/dist/ipc.js.map +1 -1
- package/package.json +2 -2
- package/src/ipc.test.ts +45 -49
package/README.md
CHANGED
|
@@ -13,5 +13,5 @@ Import the supported application-facing API from `@flighthq/ipc`. The `@flighthq
|
|
|
13
13
|
This package is part of the locked-version Flight SDK graph. Applications may instead install and import `@flighthq/sdk` when package-level tree shaking is sufficient.
|
|
14
14
|
|
|
15
15
|
- [Flight project](https://github.com/flighthq/flight)
|
|
16
|
-
- [Source for @flighthq/ipc@0.5.1-edge.
|
|
17
|
-
- [License](https://github.com/flighthq/flight/blob/
|
|
16
|
+
- [Source for @flighthq/ipc@0.5.1-edge.1350.8ce488b](https://github.com/flighthq/flight/tree/8ce488bfe444eded2fb281e7b9696e5ce7fabdc0/packages/ipc)
|
|
17
|
+
- [License](https://github.com/flighthq/flight/blob/8ce488bfe444eded2fb281e7b9696e5ce7fabdc0/LICENSE.md)
|
package/dist/ipc.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare function invokeIpc(
|
|
3
|
-
export declare function onceIpcMessage(
|
|
4
|
-
export declare function onIpcInvoke(
|
|
5
|
-
export declare function onIpcMessage(
|
|
6
|
-
export declare function sendIpcMessage(
|
|
7
|
-
export declare function sendIpcMessageTo<Target>(
|
|
1
|
+
import type { HostIpcHandleProvider, HostIpcInvokeProvider, HostIpcMessageProvider, HostIpcSendProvider, HostIpcTargetedSendProvider } from '@flighthq/types/contract';
|
|
2
|
+
export declare function invokeIpc(hostIpcInvoke: Readonly<HostIpcInvokeProvider>, channel: string, ...args: readonly unknown[]): Promise<unknown>;
|
|
3
|
+
export declare function onceIpcMessage(hostIpcMessage: Readonly<HostIpcMessageProvider>, channel: string, listener: (...args: readonly unknown[]) => void): () => void;
|
|
4
|
+
export declare function onIpcInvoke(hostIpcHandle: Readonly<HostIpcHandleProvider>, channel: string, handler: (...args: readonly unknown[]) => unknown | Promise<unknown>): () => void;
|
|
5
|
+
export declare function onIpcMessage(hostIpcMessage: Readonly<HostIpcMessageProvider>, channel: string, listener: (...args: readonly unknown[]) => void): () => void;
|
|
6
|
+
export declare function sendIpcMessage(hostIpcSend: Readonly<HostIpcSendProvider>, channel: string, ...args: readonly unknown[]): void;
|
|
7
|
+
export declare function sendIpcMessageTo<Target>(hostIpcTargetedSend: Readonly<HostIpcTargetedSendProvider<Target>>, target: NoInfer<Target>, channel: string, ...args: readonly unknown[]): void;
|
|
8
8
|
//# sourceMappingURL=ipc.d.ts.map
|
package/dist/ipc.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ipc.d.ts","sourceRoot":"","sources":["../src/ipc.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,
|
|
1
|
+
{"version":3,"file":"ipc.d.ts","sourceRoot":"","sources":["../src/ipc.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,qBAAqB,EACrB,qBAAqB,EACrB,sBAAsB,EACtB,mBAAmB,EACnB,2BAA2B,EAC5B,MAAM,0BAA0B,CAAC;AAMlC,wBAAgB,SAAS,CACvB,aAAa,EAAE,QAAQ,CAAC,qBAAqB,CAAC,EAC9C,OAAO,EAAE,MAAM,EACf,GAAG,IAAI,EAAE,SAAS,OAAO,EAAE,GAC1B,OAAO,CAAC,OAAO,CAAC,CAElB;AAOD,wBAAgB,cAAc,CAC5B,cAAc,EAAE,QAAQ,CAAC,sBAAsB,CAAC,EAChD,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,SAAS,OAAO,EAAE,KAAK,IAAI,GAC9C,MAAM,IAAI,CAiBZ;AAGD,wBAAgB,WAAW,CACzB,aAAa,EAAE,QAAQ,CAAC,qBAAqB,CAAC,EAC9C,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,CAAC,GAAG,IAAI,EAAE,SAAS,OAAO,EAAE,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,GACnE,MAAM,IAAI,CAEZ;AAID,wBAAgB,YAAY,CAC1B,cAAc,EAAE,QAAQ,CAAC,sBAAsB,CAAC,EAChD,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,SAAS,OAAO,EAAE,KAAK,IAAI,GAC9C,MAAM,IAAI,CAEZ;AAED,wBAAgB,cAAc,CAC5B,WAAW,EAAE,QAAQ,CAAC,mBAAmB,CAAC,EAC1C,OAAO,EAAE,MAAM,EACf,GAAG,IAAI,EAAE,SAAS,OAAO,EAAE,GAC1B,IAAI,CAEN;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EACrC,mBAAmB,EAAE,QAAQ,CAAC,2BAA2B,CAAC,MAAM,CAAC,CAAC,EAClE,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,EACvB,OAAO,EAAE,MAAM,EACf,GAAG,IAAI,EAAE,SAAS,OAAO,EAAE,GAC1B,IAAI,CAEN"}
|
package/dist/ipc.js
CHANGED
|
@@ -1,21 +1,15 @@
|
|
|
1
|
-
// Inter-process messaging over explicitly supplied, operation-tight Host
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
// resetIpcBackendForTest / observeIpcHostResult / explainIpcBackend / explainIpcOperation /
|
|
7
|
-
// hasIpcBackend / hasIpcOperation, plus the module-scoped _custom/_host/_hostConflict/_hostObservation/
|
|
8
|
-
// _sentinel/_listeners registry. The sentinel in particular answered every operation, so a caller could
|
|
9
|
-
// not tell an installed backend from nothing at all.
|
|
10
|
-
export function invokeIpc(host, channel, ...args) {
|
|
11
|
-
return host.ipc.invoke.invoke(channel, args);
|
|
1
|
+
// Inter-process messaging over explicitly supplied, operation-tight Host providers. Every operation
|
|
2
|
+
// takes its own provider directly: there is no aggregate resolver, installed state, or runtime
|
|
3
|
+
// missing-provider arm. A caller without the exact provider cannot compile the call.
|
|
4
|
+
export function invokeIpc(hostIpcInvoke, channel, ...args) {
|
|
5
|
+
return hostIpcInvoke.invoke(channel, args);
|
|
12
6
|
}
|
|
13
7
|
// Subscribes to messages on `channel` for the NEXT message only, then releases the subscription.
|
|
14
8
|
// Returns the unsubscribe, so a caller that never receives a message can still stop listening.
|
|
15
9
|
//
|
|
16
10
|
// The unsubscribe is idempotent and ORIGIN-PINNED: it releases exactly the subscription this call
|
|
17
11
|
// opened, whether it runs after the first message or before any arrives.
|
|
18
|
-
export function onceIpcMessage(
|
|
12
|
+
export function onceIpcMessage(hostIpcMessage, channel, listener) {
|
|
19
13
|
let unsubscribe = null;
|
|
20
14
|
let done = false;
|
|
21
15
|
const release = () => {
|
|
@@ -26,7 +20,7 @@ export function onceIpcMessage(host, channel, listener) {
|
|
|
26
20
|
// below releases in that case, so neither ordering leaks a subscription.
|
|
27
21
|
unsubscribe?.();
|
|
28
22
|
};
|
|
29
|
-
unsubscribe =
|
|
23
|
+
unsubscribe = hostIpcMessage.subscribe(channel, (args) => {
|
|
30
24
|
if (done)
|
|
31
25
|
return;
|
|
32
26
|
release();
|
|
@@ -37,18 +31,18 @@ export function onceIpcMessage(host, channel, listener) {
|
|
|
37
31
|
return release;
|
|
38
32
|
}
|
|
39
33
|
// Registers an invoke responder on `channel`. The returned release belongs to this registration.
|
|
40
|
-
export function onIpcInvoke(
|
|
41
|
-
return
|
|
34
|
+
export function onIpcInvoke(hostIpcHandle, channel, handler) {
|
|
35
|
+
return hostIpcHandle.handle(channel, handler);
|
|
42
36
|
}
|
|
43
37
|
// Subscribes to every message on `channel`. Returns the unsubscribe for THIS subscription alone —
|
|
44
38
|
// releasing one listener never disturbs another on the same channel.
|
|
45
|
-
export function onIpcMessage(
|
|
46
|
-
return
|
|
39
|
+
export function onIpcMessage(hostIpcMessage, channel, listener) {
|
|
40
|
+
return hostIpcMessage.subscribe(channel, (args) => listener(...args));
|
|
47
41
|
}
|
|
48
|
-
export function sendIpcMessage(
|
|
49
|
-
|
|
42
|
+
export function sendIpcMessage(hostIpcSend, channel, ...args) {
|
|
43
|
+
hostIpcSend.send(channel, args);
|
|
50
44
|
}
|
|
51
|
-
export function sendIpcMessageTo(
|
|
52
|
-
|
|
45
|
+
export function sendIpcMessageTo(hostIpcTargetedSend, target, channel, ...args) {
|
|
46
|
+
hostIpcTargetedSend.send(target, channel, args);
|
|
53
47
|
}
|
|
54
48
|
//# sourceMappingURL=ipc.js.map
|
package/dist/ipc.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ipc.js","sourceRoot":"","sources":["../src/ipc.ts"],"names":[],"mappings":"AAQA,
|
|
1
|
+
{"version":3,"file":"ipc.js","sourceRoot":"","sources":["../src/ipc.ts"],"names":[],"mappings":"AAQA,oGAAoG;AACpG,+FAA+F;AAC/F,qFAAqF;AAErF,MAAM,UAAU,SAAS,CACvB,aAA8C,EAC9C,OAAe,EACf,GAAG,IAAwB;IAE3B,OAAO,aAAa,CAAC,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;AAC7C,CAAC;AAED,iGAAiG;AACjG,+FAA+F;AAC/F,EAAE;AACF,kGAAkG;AAClG,yEAAyE;AACzE,MAAM,UAAU,cAAc,CAC5B,cAAgD,EAChD,OAAe,EACf,QAA+C;IAE/C,IAAI,WAAW,GAAwB,IAAI,CAAC;IAC5C,IAAI,IAAI,GAAG,KAAK,CAAC;IACjB,MAAM,OAAO,GAAG,GAAS,EAAE;QACzB,IAAI,IAAI;YAAE,OAAO;QACjB,IAAI,GAAG,IAAI,CAAC;QACZ,iGAAiG;QACjG,yEAAyE;QACzE,WAAW,EAAE,EAAE,CAAC;IAClB,CAAC,CAAC;IACF,WAAW,GAAG,cAAc,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE;QACvD,IAAI,IAAI;YAAE,OAAO;QACjB,OAAO,EAAE,CAAC;QACV,QAAQ,CAAC,GAAG,IAAI,CAAC,CAAC;IACpB,CAAC,CAAC,CAAC;IACH,IAAI,IAAI;QAAE,WAAW,EAAE,CAAC;IACxB,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,iGAAiG;AACjG,MAAM,UAAU,WAAW,CACzB,aAA8C,EAC9C,OAAe,EACf,OAAoE;IAEpE,OAAO,aAAa,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;AAChD,CAAC;AAED,kGAAkG;AAClG,qEAAqE;AACrE,MAAM,UAAU,YAAY,CAC1B,cAAgD,EAChD,OAAe,EACf,QAA+C;IAE/C,OAAO,cAAc,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;AACxE,CAAC;AAED,MAAM,UAAU,cAAc,CAC5B,WAA0C,EAC1C,OAAe,EACf,GAAG,IAAwB;IAE3B,WAAW,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;AAClC,CAAC;AAED,MAAM,UAAU,gBAAgB,CAC9B,mBAAkE,EAClE,MAAuB,EACvB,OAAe,EACf,GAAG,IAAwB;IAE3B,mBAAmB,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;AAClD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flighthq/ipc",
|
|
3
|
-
"version": "0.5.1-edge.
|
|
3
|
+
"version": "0.5.1-edge.1350.8ce488b",
|
|
4
4
|
"author": "Joshua Granick and other contributors",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"clean:dist": "tsx ../../scripts/clean-package-dist.ts"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@flighthq/types": "0.5.1-edge.
|
|
41
|
+
"@flighthq/types": "0.5.1-edge.1350.8ce488b"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@flighthq/entity": "*",
|
package/src/ipc.test.ts
CHANGED
|
@@ -1,23 +1,18 @@
|
|
|
1
1
|
import { allocateEntity, finishEntity } from '@flighthq/entity/contract';
|
|
2
2
|
import type {
|
|
3
3
|
EntityWithoutRuntime,
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
IpcHandleBackend,
|
|
10
|
-
IpcInvokeBackend,
|
|
11
|
-
IpcMessageBackend,
|
|
12
|
-
IpcSendBackend,
|
|
13
|
-
IpcTargetedSendBackend,
|
|
4
|
+
HostIpcHandleProvider,
|
|
5
|
+
HostIpcInvokeProvider,
|
|
6
|
+
HostIpcMessageProvider,
|
|
7
|
+
HostIpcSendProvider,
|
|
8
|
+
HostIpcTargetedSendProvider,
|
|
14
9
|
} from '@flighthq/types/contract';
|
|
15
10
|
|
|
16
11
|
import { invokeIpc, onIpcInvoke, onIpcMessage, onceIpcMessage, sendIpcMessage, sendIpcMessageTo } from './ipc';
|
|
17
12
|
|
|
18
13
|
// A host carrying a recording message provider. Nothing installs anywhere, so two hosts can be live at
|
|
19
14
|
// once — the property the ambient seam could not express.
|
|
20
|
-
function messageHost():
|
|
15
|
+
function messageHost(): { readonly ipc: { readonly message: HostIpcMessageProvider } } & {
|
|
21
16
|
deliver(channel: string, ...args: readonly unknown[]): void;
|
|
22
17
|
subscriberCount(channel: string): number;
|
|
23
18
|
} {
|
|
@@ -48,19 +43,20 @@ interface TestIpcTarget {
|
|
|
48
43
|
readonly id: number;
|
|
49
44
|
}
|
|
50
45
|
|
|
51
|
-
function operationHost():
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
46
|
+
function operationHost(): { readonly ipc: { readonly handle: HostIpcHandleProvider } } & {
|
|
47
|
+
readonly ipc: { readonly invoke: HostIpcInvokeProvider };
|
|
48
|
+
} & { readonly ipc: { readonly send: HostIpcSendProvider } } & {
|
|
49
|
+
readonly ipc: { readonly targetedSend: HostIpcTargetedSendProvider<TestIpcTarget> };
|
|
50
|
+
} & {
|
|
51
|
+
readonly handlers: Map<string, (...args: readonly unknown[]) => unknown | Promise<unknown>>;
|
|
52
|
+
readonly invocations: Array<{ readonly args: readonly unknown[]; readonly channel: string }>;
|
|
53
|
+
readonly sent: Array<{ readonly args: readonly unknown[]; readonly channel: string }>;
|
|
54
|
+
readonly sentTo: Array<{
|
|
55
|
+
readonly args: readonly unknown[];
|
|
56
|
+
readonly channel: string;
|
|
57
|
+
readonly target: TestIpcTarget;
|
|
58
|
+
}>;
|
|
59
|
+
} {
|
|
64
60
|
const handlers = new Map<string, (...args: readonly unknown[]) => unknown | Promise<unknown>>();
|
|
65
61
|
const invocations: Array<{ readonly args: readonly unknown[]; readonly channel: string }> = [];
|
|
66
62
|
const sent: Array<{ readonly args: readonly unknown[]; readonly channel: string }> = [];
|
|
@@ -74,7 +70,7 @@ function operationHost(): HasIpcHandle &
|
|
|
74
70
|
invocations,
|
|
75
71
|
ipc: {
|
|
76
72
|
handle: (() => {
|
|
77
|
-
const out = allocateEntity<
|
|
73
|
+
const out = allocateEntity<HostIpcHandleProvider>();
|
|
78
74
|
out.handle = (channel: string, handler: (...args: readonly unknown[]) => unknown | Promise<unknown>) => {
|
|
79
75
|
handlers.set(channel, handler);
|
|
80
76
|
return () => {
|
|
@@ -84,7 +80,7 @@ function operationHost(): HasIpcHandle &
|
|
|
84
80
|
return finishEntity(out);
|
|
85
81
|
})(),
|
|
86
82
|
invoke: (() => {
|
|
87
|
-
const out = allocateEntity<
|
|
83
|
+
const out = allocateEntity<HostIpcInvokeProvider>();
|
|
88
84
|
out.invoke = (channel: string, args: readonly unknown[]) => {
|
|
89
85
|
invocations.push({ args, channel });
|
|
90
86
|
return Promise.resolve({ args, channel });
|
|
@@ -92,14 +88,14 @@ function operationHost(): HasIpcHandle &
|
|
|
92
88
|
return finishEntity(out);
|
|
93
89
|
})(),
|
|
94
90
|
send: (() => {
|
|
95
|
-
const out = allocateEntity<
|
|
91
|
+
const out = allocateEntity<HostIpcSendProvider>();
|
|
96
92
|
out.send = (channel: string, args: readonly unknown[]) => {
|
|
97
93
|
sent.push({ args, channel });
|
|
98
94
|
};
|
|
99
95
|
return finishEntity(out);
|
|
100
96
|
})(),
|
|
101
97
|
targetedSend: (() => {
|
|
102
|
-
const out = allocateEntity<
|
|
98
|
+
const out = allocateEntity<HostIpcTargetedSendProvider<TestIpcTarget>>();
|
|
103
99
|
out.send = (target: TestIpcTarget, channel: string, args: readonly unknown[]) => {
|
|
104
100
|
sentTo.push({ args, channel, target });
|
|
105
101
|
};
|
|
@@ -113,10 +109,10 @@ function operationHost(): HasIpcHandle &
|
|
|
113
109
|
|
|
114
110
|
describe('invokeIpc', () => {
|
|
115
111
|
it('requires the invoke capability and returns its response', async () => {
|
|
116
|
-
expectTypeOf(invokeIpc).parameter(0).toEqualTypeOf<
|
|
112
|
+
expectTypeOf(invokeIpc).parameter(0).toEqualTypeOf<Readonly<HostIpcInvokeProvider>>();
|
|
117
113
|
const host = operationHost();
|
|
118
114
|
|
|
119
|
-
const response = await invokeIpc(host, 'compute', 1, 2);
|
|
115
|
+
const response = await invokeIpc(host.ipc.invoke, 'compute', 1, 2);
|
|
120
116
|
|
|
121
117
|
expect(response).toEqual({ args: [1, 2], channel: 'compute' });
|
|
122
118
|
expect(host.invocations).toEqual([{ args: [1, 2], channel: 'compute' }]);
|
|
@@ -127,7 +123,7 @@ describe('onceIpcMessage', () => {
|
|
|
127
123
|
it('delivers the first message and then releases the subscription', () => {
|
|
128
124
|
const host = messageHost();
|
|
129
125
|
const seen: (readonly unknown[])[] = [];
|
|
130
|
-
onceIpcMessage(host, 'ping', (...args) => seen.push(args));
|
|
126
|
+
onceIpcMessage(host.ipc.message, 'ping', (...args) => seen.push(args));
|
|
131
127
|
host.deliver('ping', 1);
|
|
132
128
|
host.deliver('ping', 2);
|
|
133
129
|
expect(seen).toEqual([[1]]);
|
|
@@ -138,7 +134,7 @@ describe('onceIpcMessage', () => {
|
|
|
138
134
|
it('returns an unsubscribe that works before any message arrives', () => {
|
|
139
135
|
const host = messageHost();
|
|
140
136
|
let count = 0;
|
|
141
|
-
const stop = onceIpcMessage(host, 'ping', () => count++);
|
|
137
|
+
const stop = onceIpcMessage(host.ipc.message, 'ping', () => count++);
|
|
142
138
|
stop();
|
|
143
139
|
expect(host.subscriberCount('ping')).toBe(0);
|
|
144
140
|
host.deliver('ping');
|
|
@@ -147,7 +143,7 @@ describe('onceIpcMessage', () => {
|
|
|
147
143
|
|
|
148
144
|
it('releases exactly once across repeated stop calls', () => {
|
|
149
145
|
let releases = 0;
|
|
150
|
-
const host:
|
|
146
|
+
const host: { readonly ipc: { readonly message: HostIpcMessageProvider } } = {
|
|
151
147
|
ipc: {
|
|
152
148
|
message: (() => {
|
|
153
149
|
const out = allocateEntity<any>();
|
|
@@ -158,7 +154,7 @@ describe('onceIpcMessage', () => {
|
|
|
158
154
|
})(),
|
|
159
155
|
},
|
|
160
156
|
};
|
|
161
|
-
const stop = onceIpcMessage(host, 'ping', () => {});
|
|
157
|
+
const stop = onceIpcMessage(host.ipc.message, 'ping', () => {});
|
|
162
158
|
stop();
|
|
163
159
|
stop();
|
|
164
160
|
expect(releases).toBe(1);
|
|
@@ -169,10 +165,10 @@ describe('onceIpcMessage', () => {
|
|
|
169
165
|
// anything to release.
|
|
170
166
|
it('releases even when the provider delivers during subscribe', () => {
|
|
171
167
|
let released = false;
|
|
172
|
-
const host:
|
|
168
|
+
const host: { readonly ipc: { readonly message: HostIpcMessageProvider } } = {
|
|
173
169
|
ipc: {
|
|
174
170
|
message: (() => {
|
|
175
|
-
const out = allocateEntity<
|
|
171
|
+
const out = allocateEntity<HostIpcMessageProvider>();
|
|
176
172
|
out.subscribe = (_channel: string, listener: (args: readonly unknown[]) => void): (() => void) => {
|
|
177
173
|
listener([42]);
|
|
178
174
|
return () => (released = true);
|
|
@@ -182,7 +178,7 @@ describe('onceIpcMessage', () => {
|
|
|
182
178
|
},
|
|
183
179
|
};
|
|
184
180
|
const seen: (readonly unknown[])[] = [];
|
|
185
|
-
onceIpcMessage(host, 'ping', (...args) => seen.push(args));
|
|
181
|
+
onceIpcMessage(host.ipc.message, 'ping', (...args) => seen.push(args));
|
|
186
182
|
expect(seen).toEqual([[42]]);
|
|
187
183
|
expect(released).toBe(true);
|
|
188
184
|
});
|
|
@@ -190,9 +186,9 @@ describe('onceIpcMessage', () => {
|
|
|
190
186
|
|
|
191
187
|
describe('onIpcInvoke', () => {
|
|
192
188
|
it('requires the handle capability, spreads arguments, and returns its release', async () => {
|
|
193
|
-
expectTypeOf(onIpcInvoke).parameter(0).toEqualTypeOf<
|
|
189
|
+
expectTypeOf(onIpcInvoke).parameter(0).toEqualTypeOf<Readonly<HostIpcHandleProvider>>();
|
|
194
190
|
const host = operationHost();
|
|
195
|
-
const stop = onIpcInvoke(host, 'double', (value) => (value as number) * 2);
|
|
191
|
+
const stop = onIpcInvoke(host.ipc.handle, 'double', (value) => (value as number) * 2);
|
|
196
192
|
|
|
197
193
|
expect(await host.handlers.get('double')?.(4)).toBe(8);
|
|
198
194
|
|
|
@@ -205,7 +201,7 @@ describe('onIpcMessage', () => {
|
|
|
205
201
|
it('delivers every message on its channel with the sent arguments', () => {
|
|
206
202
|
const host = messageHost();
|
|
207
203
|
const seen: (readonly unknown[])[] = [];
|
|
208
|
-
onIpcMessage(host, 'ping', (...args) => seen.push(args));
|
|
204
|
+
onIpcMessage(host.ipc.message, 'ping', (...args) => seen.push(args));
|
|
209
205
|
host.deliver('ping', 1, 'two');
|
|
210
206
|
host.deliver('ping', 3);
|
|
211
207
|
expect(seen).toEqual([[1, 'two'], [3]]);
|
|
@@ -214,7 +210,7 @@ describe('onIpcMessage', () => {
|
|
|
214
210
|
it('delivers only its own channel', () => {
|
|
215
211
|
const host = messageHost();
|
|
216
212
|
let count = 0;
|
|
217
|
-
onIpcMessage(host, 'wanted', () => count++);
|
|
213
|
+
onIpcMessage(host.ipc.message, 'wanted', () => count++);
|
|
218
214
|
host.deliver('other', 1);
|
|
219
215
|
expect(count).toBe(0);
|
|
220
216
|
});
|
|
@@ -223,8 +219,8 @@ describe('onIpcMessage', () => {
|
|
|
223
219
|
it('unsubscribes exactly its own subscription', () => {
|
|
224
220
|
const host = messageHost();
|
|
225
221
|
const kept: unknown[] = [];
|
|
226
|
-
const stopDropped = onIpcMessage(host, 'shared', () => kept.push('dropped'));
|
|
227
|
-
onIpcMessage(host, 'shared', () => kept.push('kept'));
|
|
222
|
+
const stopDropped = onIpcMessage(host.ipc.message, 'shared', () => kept.push('dropped'));
|
|
223
|
+
onIpcMessage(host.ipc.message, 'shared', () => kept.push('kept'));
|
|
228
224
|
stopDropped();
|
|
229
225
|
host.deliver('shared');
|
|
230
226
|
expect(kept).toEqual(['kept']);
|
|
@@ -237,8 +233,8 @@ describe('onIpcMessage', () => {
|
|
|
237
233
|
const first = messageHost();
|
|
238
234
|
const second = messageHost();
|
|
239
235
|
const seen: string[] = [];
|
|
240
|
-
onIpcMessage(first, 'c', () => seen.push('first'));
|
|
241
|
-
onIpcMessage(second, 'c', () => seen.push('second'));
|
|
236
|
+
onIpcMessage(first.ipc.message, 'c', () => seen.push('first'));
|
|
237
|
+
onIpcMessage(second.ipc.message, 'c', () => seen.push('second'));
|
|
242
238
|
second.deliver('c');
|
|
243
239
|
first.deliver('c');
|
|
244
240
|
expect(seen).toEqual(['second', 'first']);
|
|
@@ -247,10 +243,10 @@ describe('onIpcMessage', () => {
|
|
|
247
243
|
|
|
248
244
|
describe('sendIpcMessage', () => {
|
|
249
245
|
it('requires the send capability and forwards the arguments', () => {
|
|
250
|
-
expectTypeOf(sendIpcMessage).parameter(0).toEqualTypeOf<
|
|
246
|
+
expectTypeOf(sendIpcMessage).parameter(0).toEqualTypeOf<Readonly<HostIpcSendProvider>>();
|
|
251
247
|
const host = operationHost();
|
|
252
248
|
|
|
253
|
-
sendIpcMessage(host, 'log', 'hello', 7);
|
|
249
|
+
sendIpcMessage(host.ipc.send, 'log', 'hello', 7);
|
|
254
250
|
|
|
255
251
|
expect(host.sent).toEqual([{ args: ['hello', 7], channel: 'log' }]);
|
|
256
252
|
});
|
|
@@ -260,11 +256,11 @@ describe('sendIpcMessageTo', () => {
|
|
|
260
256
|
it('requires a capability for the target type and forwards that target unchanged', () => {
|
|
261
257
|
expectTypeOf(sendIpcMessageTo<TestIpcTarget>)
|
|
262
258
|
.parameter(0)
|
|
263
|
-
.toEqualTypeOf<
|
|
259
|
+
.toEqualTypeOf<Readonly<HostIpcTargetedSendProvider<TestIpcTarget>>>();
|
|
264
260
|
const host = operationHost();
|
|
265
261
|
const target = { id: 7 };
|
|
266
262
|
|
|
267
|
-
sendIpcMessageTo(host, target, 'log', 'hello');
|
|
263
|
+
sendIpcMessageTo(host.ipc.targetedSend, target, 'log', 'hello');
|
|
268
264
|
|
|
269
265
|
expect(host.sentTo).toEqual([{ args: ['hello'], channel: 'log', target }]);
|
|
270
266
|
expect(host.sentTo[0].target).toBe(target);
|