@flighthq/ipc 0.5.1-next.820.97b3830 → 0.5.1-next.903.f434bc2

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 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-next.820.97b3830](https://github.com/flighthq/flight/tree/97b3830e843209d92da169e02a52c0574efe5c09/packages/ipc)
17
- - [License](https://github.com/flighthq/flight/blob/97b3830e843209d92da169e02a52c0574efe5c09/LICENSE.md)
16
+ - [Source for @flighthq/ipc@0.5.1-next.903.f434bc2](https://github.com/flighthq/flight/tree/f434bc233778d75aeea61995df3a8cfaec459a85/packages/ipc)
17
+ - [License](https://github.com/flighthq/flight/blob/f434bc233778d75aeea61995df3a8cfaec459a85/LICENSE.md)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flighthq/ipc",
3
- "version": "0.5.1-next.820.97b3830",
3
+ "version": "0.5.1-next.903.f434bc2",
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-next.820.97b3830"
41
+ "@flighthq/types": "0.5.1-next.903.f434bc2"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@flighthq/entity": "*",
package/src/ipc.test.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { createEntity } from '@flighthq/entity/contract';
1
+ import { allocateEntity, finishEntity } from '@flighthq/entity/contract';
2
2
  import type {
3
3
  EntityWithoutRuntime,
4
4
  HasIpcHandle,
@@ -27,14 +27,16 @@ function messageHost(): HasIpcMessage & {
27
27
  for (const listener of [...(channels.get(channel) ?? [])]) listener(args);
28
28
  },
29
29
  ipc: {
30
- message: createEntity<EntityWithoutRuntime<IpcMessageBackend>>({
31
- subscribe(channel: string, listener: (args: readonly unknown[]) => void): () => void {
30
+ message: (() => {
31
+ const out = allocateEntity<any>();
32
+ out.subscribe = (channel: string, listener: (args: readonly unknown[]) => void): (() => void) => {
32
33
  const set = channels.get(channel) ?? new Set();
33
34
  channels.set(channel, set);
34
35
  set.add(listener);
35
36
  return () => set.delete(listener);
36
- },
37
- }),
37
+ };
38
+ return finishEntity(out);
39
+ })(),
38
40
  },
39
41
  subscriberCount(channel: string): number {
40
42
  return channels.get(channel)?.size ?? 0;
@@ -71,30 +73,38 @@ function operationHost(): HasIpcHandle &
71
73
  handlers,
72
74
  invocations,
73
75
  ipc: {
74
- handle: createEntity<EntityWithoutRuntime<IpcHandleBackend>>({
75
- handle(channel, handler) {
76
+ handle: (() => {
77
+ const out = allocateEntity<IpcHandleBackend>();
78
+ out.handle = (channel: string, handler: (...args: readonly unknown[]) => unknown | Promise<unknown>) => {
76
79
  handlers.set(channel, handler);
77
80
  return () => {
78
81
  if (handlers.get(channel) === handler) handlers.delete(channel);
79
82
  };
80
- },
81
- }),
82
- invoke: createEntity<EntityWithoutRuntime<IpcInvokeBackend>>({
83
- invoke(channel, args) {
83
+ };
84
+ return finishEntity(out);
85
+ })(),
86
+ invoke: (() => {
87
+ const out = allocateEntity<IpcInvokeBackend>();
88
+ out.invoke = (channel: string, args: readonly unknown[]) => {
84
89
  invocations.push({ args, channel });
85
90
  return Promise.resolve({ args, channel });
86
- },
87
- }),
88
- send: createEntity<EntityWithoutRuntime<IpcSendBackend>>({
89
- send(channel, args) {
91
+ };
92
+ return finishEntity(out);
93
+ })(),
94
+ send: (() => {
95
+ const out = allocateEntity<IpcSendBackend>();
96
+ out.send = (channel: string, args: readonly unknown[]) => {
90
97
  sent.push({ args, channel });
91
- },
92
- }),
93
- targetedSend: createEntity<EntityWithoutRuntime<IpcTargetedSendBackend<TestIpcTarget>>>({
94
- send(target, channel, args) {
98
+ };
99
+ return finishEntity(out);
100
+ })(),
101
+ targetedSend: (() => {
102
+ const out = allocateEntity<IpcTargetedSendBackend<TestIpcTarget>>();
103
+ out.send = (target: TestIpcTarget, channel: string, args: readonly unknown[]) => {
95
104
  sentTo.push({ args, channel, target });
96
- },
97
- }),
105
+ };
106
+ return finishEntity(out);
107
+ })(),
98
108
  },
99
109
  sent,
100
110
  sentTo,
@@ -139,11 +149,13 @@ describe('onceIpcMessage', () => {
139
149
  let releases = 0;
140
150
  const host: HasIpcMessage = {
141
151
  ipc: {
142
- message: createEntity<EntityWithoutRuntime<IpcMessageBackend>>({
143
- subscribe(): () => void {
152
+ message: (() => {
153
+ const out = allocateEntity<any>();
154
+ out.subscribe = (): (() => void) => {
144
155
  return () => releases++;
145
- },
146
- }),
156
+ };
157
+ return finishEntity(out);
158
+ })(),
147
159
  },
148
160
  };
149
161
  const stop = onceIpcMessage(host, 'ping', () => {});
@@ -159,12 +171,14 @@ describe('onceIpcMessage', () => {
159
171
  let released = false;
160
172
  const host: HasIpcMessage = {
161
173
  ipc: {
162
- message: createEntity<EntityWithoutRuntime<IpcMessageBackend>>({
163
- subscribe(_channel, listener): () => void {
174
+ message: (() => {
175
+ const out = allocateEntity<IpcMessageBackend>();
176
+ out.subscribe = (_channel: string, listener: (args: readonly unknown[]) => void): (() => void) => {
164
177
  listener([42]);
165
178
  return () => (released = true);
166
- },
167
- }),
179
+ };
180
+ return finishEntity(out);
181
+ })(),
168
182
  },
169
183
  };
170
184
  const seen: (readonly unknown[])[] = [];