@powerlines/engine 0.47.4 → 0.49.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (249) hide show
  1. package/dist/api/build.cjs +66 -0
  2. package/dist/api/build.d.cts +14 -0
  3. package/dist/api/build.d.cts.map +1 -0
  4. package/dist/api/build.d.mts +14 -0
  5. package/dist/api/build.d.mts.map +1 -0
  6. package/dist/api/build.mjs +64 -0
  7. package/dist/api/build.mjs.map +1 -0
  8. package/dist/api/clean.cjs +28 -0
  9. package/dist/api/clean.d.cts +14 -0
  10. package/dist/api/clean.d.cts.map +1 -0
  11. package/dist/api/clean.d.mts +14 -0
  12. package/dist/api/clean.d.mts.map +1 -0
  13. package/dist/api/clean.mjs +28 -0
  14. package/dist/api/clean.mjs.map +1 -0
  15. package/dist/api/create.cjs +59 -0
  16. package/dist/api/create.d.cts +14 -0
  17. package/dist/api/create.d.cts.map +1 -0
  18. package/dist/api/create.d.mts +14 -0
  19. package/dist/api/create.d.mts.map +1 -0
  20. package/dist/api/create.mjs +57 -0
  21. package/dist/api/create.mjs.map +1 -0
  22. package/dist/api/deploy.cjs +24 -0
  23. package/dist/api/deploy.d.cts +17 -0
  24. package/dist/api/deploy.d.cts.map +1 -0
  25. package/dist/api/deploy.d.mts +17 -0
  26. package/dist/api/deploy.d.mts.map +1 -0
  27. package/dist/api/deploy.mjs +24 -0
  28. package/dist/api/deploy.mjs.map +1 -0
  29. package/dist/api/docs.cjs +24 -0
  30. package/dist/api/docs.d.cts +17 -0
  31. package/dist/api/docs.d.cts.map +1 -0
  32. package/dist/api/docs.d.mts +17 -0
  33. package/dist/api/docs.d.mts.map +1 -0
  34. package/dist/api/docs.mjs +24 -0
  35. package/dist/api/docs.mjs.map +1 -0
  36. package/dist/api/lint.cjs +27 -0
  37. package/dist/api/lint.d.cts +17 -0
  38. package/dist/api/lint.d.cts.map +1 -0
  39. package/dist/api/lint.d.mts +17 -0
  40. package/dist/api/lint.d.mts.map +1 -0
  41. package/dist/api/lint.mjs +27 -0
  42. package/dist/api/lint.mjs.map +1 -0
  43. package/dist/api/prepare.cjs +68 -0
  44. package/dist/api/prepare.d.cts +14 -0
  45. package/dist/api/prepare.d.cts.map +1 -0
  46. package/dist/api/prepare.d.mts +14 -0
  47. package/dist/api/prepare.d.mts.map +1 -0
  48. package/dist/api/prepare.mjs +68 -0
  49. package/dist/api/prepare.mjs.map +1 -0
  50. package/dist/api/test.cjs +27 -0
  51. package/dist/api/test.d.cts +17 -0
  52. package/dist/api/test.d.cts.map +1 -0
  53. package/dist/api/test.d.mts +17 -0
  54. package/dist/api/test.d.mts.map +1 -0
  55. package/dist/api/test.mjs +27 -0
  56. package/dist/api/test.mjs.map +1 -0
  57. package/dist/api/types.cjs +70 -0
  58. package/dist/api/types.d.cts +17 -0
  59. package/dist/api/types.d.cts.map +1 -0
  60. package/dist/api/types.d.mts +17 -0
  61. package/dist/api/types.d.mts.map +1 -0
  62. package/dist/api/types.mjs +70 -0
  63. package/dist/api/types.mjs.map +1 -0
  64. package/dist/api-BgyEi2hF.d.mts +138 -0
  65. package/dist/api-BgyEi2hF.d.mts.map +1 -0
  66. package/dist/api-DcHfCjQK.d.cts +138 -0
  67. package/dist/api-DcHfCjQK.d.cts.map +1 -0
  68. package/dist/api.cjs +39 -1268
  69. package/dist/api.d.cts +11 -300
  70. package/dist/api.d.cts.map +1 -1
  71. package/dist/api.d.mts +11 -300
  72. package/dist/api.d.mts.map +1 -1
  73. package/dist/api.mjs +31 -1264
  74. package/dist/api.mjs.map +1 -1
  75. package/dist/config-ByLyzMI0.d.mts +204 -0
  76. package/dist/config-ByLyzMI0.d.mts.map +1 -0
  77. package/dist/config-DKEmqMrh.d.cts +204 -0
  78. package/dist/config-DKEmqMrh.d.cts.map +1 -0
  79. package/dist/context/engine-context.cjs +177 -0
  80. package/dist/context/engine-context.d.cts +2 -0
  81. package/dist/context/engine-context.d.mts +2 -0
  82. package/dist/context/engine-context.mjs +175 -0
  83. package/dist/context/engine-context.mjs.map +1 -0
  84. package/dist/context/index.cjs +2 -9
  85. package/dist/context/index.d.cts +2 -150
  86. package/dist/context/index.d.mts +2 -150
  87. package/dist/context/index.mjs +2 -4
  88. package/dist/context-D0_a0kRO.d.cts +149 -0
  89. package/dist/context-D0_a0kRO.d.cts.map +1 -0
  90. package/dist/context-DcXV6_GL.d.mts +149 -0
  91. package/dist/context-DcXV6_GL.d.mts.map +1 -0
  92. package/dist/engine-Dz6BvkFY.cjs +590 -0
  93. package/dist/engine-context-B8K6Jtkk.d.cts +53 -0
  94. package/dist/engine-context-B8K6Jtkk.d.cts.map +1 -0
  95. package/dist/engine-context-DKlA5Pgu.d.mts +53 -0
  96. package/dist/engine-context-DKlA5Pgu.d.mts.map +1 -0
  97. package/dist/engine-q6YKXXcB.mjs +571 -0
  98. package/dist/engine-q6YKXXcB.mjs.map +1 -0
  99. package/dist/engine.cjs +6 -0
  100. package/dist/engine.d.cts +143 -0
  101. package/dist/engine.d.cts.map +1 -0
  102. package/dist/engine.d.mts +143 -0
  103. package/dist/engine.d.mts.map +1 -0
  104. package/dist/engine.mjs +3 -0
  105. package/dist/helpers/create-execution-host.cjs +57 -0
  106. package/dist/helpers/create-execution-host.d.cts +20 -0
  107. package/dist/helpers/create-execution-host.d.cts.map +1 -0
  108. package/dist/helpers/create-execution-host.d.mts +20 -0
  109. package/dist/helpers/create-execution-host.d.mts.map +1 -0
  110. package/dist/helpers/create-execution-host.mjs +57 -0
  111. package/dist/helpers/create-execution-host.mjs.map +1 -0
  112. package/dist/helpers/finalize.cjs +26 -0
  113. package/dist/helpers/finalize.d.cts +12 -0
  114. package/dist/helpers/finalize.d.cts.map +1 -0
  115. package/dist/helpers/finalize.d.mts +12 -0
  116. package/dist/helpers/finalize.d.mts.map +1 -0
  117. package/dist/helpers/finalize.mjs +26 -0
  118. package/dist/helpers/finalize.mjs.map +1 -0
  119. package/dist/helpers/index.cjs +12 -0
  120. package/dist/helpers/index.d.cts +5 -0
  121. package/dist/helpers/index.d.mts +5 -0
  122. package/dist/helpers/index.mjs +6 -0
  123. package/dist/helpers/rpc.cjs +139 -0
  124. package/dist/helpers/rpc.d.cts +7 -0
  125. package/dist/helpers/rpc.d.cts.map +1 -0
  126. package/dist/helpers/rpc.d.mts +7 -0
  127. package/dist/helpers/rpc.d.mts.map +1 -0
  128. package/dist/helpers/rpc.mjs +139 -0
  129. package/dist/helpers/rpc.mjs.map +1 -0
  130. package/dist/helpers/stream.cjs +119 -0
  131. package/dist/helpers/stream.d.cts +45 -0
  132. package/dist/helpers/stream.d.cts.map +1 -0
  133. package/dist/helpers/stream.d.mts +45 -0
  134. package/dist/helpers/stream.d.mts.map +1 -0
  135. package/dist/helpers/stream.mjs +117 -0
  136. package/dist/helpers/stream.mjs.map +1 -0
  137. package/dist/index-BVVgDSdq.d.cts +1 -0
  138. package/dist/index-BVVgDSdq.d.mts +1 -0
  139. package/dist/index.cjs +8 -748
  140. package/dist/index.d.cts +6 -140
  141. package/dist/index.d.mts +6 -140
  142. package/dist/index.mjs +4 -747
  143. package/package.json +102 -132
  144. package/dist/_internal/worker.cjs +0 -5192
  145. package/dist/_internal/worker.d.cts +0 -46
  146. package/dist/_internal/worker.d.cts.map +0 -1
  147. package/dist/_internal/worker.d.mts +0 -46
  148. package/dist/_internal/worker.d.mts.map +0 -1
  149. package/dist/_internal/worker.mjs +0 -5153
  150. package/dist/_internal/worker.mjs.map +0 -1
  151. package/dist/base-context-DLemGRbd.cjs +0 -322
  152. package/dist/base-context-DUha4Lz-.mjs +0 -315
  153. package/dist/base-context-DUha4Lz-.mjs.map +0 -1
  154. package/dist/context/index.d.cts.map +0 -1
  155. package/dist/context/index.d.mts.map +0 -1
  156. package/dist/engine-context-BfFiKN53.mjs +0 -86
  157. package/dist/engine-context-BfFiKN53.mjs.map +0 -1
  158. package/dist/engine-context-D0y88i_J.cjs +0 -91
  159. package/dist/execution-context-CE5H90Um.mjs +0 -2845
  160. package/dist/execution-context-CE5H90Um.mjs.map +0 -1
  161. package/dist/execution-context-CnyaM3Ul.cjs +0 -2889
  162. package/dist/execution-context-NyDjVZ6T.d.cts +0 -647
  163. package/dist/execution-context-NyDjVZ6T.d.cts.map +0 -1
  164. package/dist/execution-context-YrjFeD9k.d.mts +0 -647
  165. package/dist/execution-context-YrjFeD9k.d.mts.map +0 -1
  166. package/dist/fs-CeEdzPKE.cjs +0 -262
  167. package/dist/fs-Dcle8lUp.mjs +0 -226
  168. package/dist/fs-Dcle8lUp.mjs.map +0 -1
  169. package/dist/index.d.cts.map +0 -1
  170. package/dist/index.d.mts.map +0 -1
  171. package/dist/index.mjs.map +0 -1
  172. package/dist/rpc/client.cjs +0 -74
  173. package/dist/rpc/client.d.cts +0 -31
  174. package/dist/rpc/client.d.cts.map +0 -1
  175. package/dist/rpc/client.d.mts +0 -31
  176. package/dist/rpc/client.d.mts.map +0 -1
  177. package/dist/rpc/client.mjs +0 -71
  178. package/dist/rpc/client.mjs.map +0 -1
  179. package/dist/rpc/serialization.cjs +0 -82
  180. package/dist/rpc/serialization.d.cts +0 -46
  181. package/dist/rpc/serialization.d.cts.map +0 -1
  182. package/dist/rpc/serialization.d.mts +0 -46
  183. package/dist/rpc/serialization.d.mts.map +0 -1
  184. package/dist/rpc/serialization.mjs +0 -76
  185. package/dist/rpc/serialization.mjs.map +0 -1
  186. package/dist/rpc/server.cjs +0 -69
  187. package/dist/rpc/server.d.cts +0 -29
  188. package/dist/rpc/server.d.cts.map +0 -1
  189. package/dist/rpc/server.d.mts +0 -29
  190. package/dist/rpc/server.d.mts.map +0 -1
  191. package/dist/rpc/server.mjs +0 -66
  192. package/dist/rpc/server.mjs.map +0 -1
  193. package/dist/rpc/types.cjs +0 -0
  194. package/dist/rpc/types.d.cts +0 -70
  195. package/dist/rpc/types.d.cts.map +0 -1
  196. package/dist/rpc/types.d.mts +0 -70
  197. package/dist/rpc/types.d.mts.map +0 -1
  198. package/dist/rpc/types.mjs +0 -1
  199. package/dist/schemas.cjs +0 -9
  200. package/dist/schemas.d.cts +0 -127
  201. package/dist/schemas.d.cts.map +0 -1
  202. package/dist/schemas.d.mts +0 -127
  203. package/dist/schemas.d.mts.map +0 -1
  204. package/dist/schemas.mjs +0 -3
  205. package/dist/storage/base.cjs +0 -216
  206. package/dist/storage/base.d.cts +0 -199
  207. package/dist/storage/base.d.cts.map +0 -1
  208. package/dist/storage/base.d.mts +0 -199
  209. package/dist/storage/base.d.mts.map +0 -1
  210. package/dist/storage/base.mjs +0 -215
  211. package/dist/storage/base.mjs.map +0 -1
  212. package/dist/storage/file-system.cjs +0 -180
  213. package/dist/storage/file-system.d.cts +0 -127
  214. package/dist/storage/file-system.d.cts.map +0 -1
  215. package/dist/storage/file-system.d.mts +0 -127
  216. package/dist/storage/file-system.d.mts.map +0 -1
  217. package/dist/storage/file-system.mjs +0 -179
  218. package/dist/storage/file-system.mjs.map +0 -1
  219. package/dist/storage/helpers.cjs +0 -37
  220. package/dist/storage/helpers.d.cts +0 -25
  221. package/dist/storage/helpers.d.cts.map +0 -1
  222. package/dist/storage/helpers.d.mts +0 -25
  223. package/dist/storage/helpers.d.mts.map +0 -1
  224. package/dist/storage/helpers.mjs +0 -34
  225. package/dist/storage/helpers.mjs.map +0 -1
  226. package/dist/storage/index.cjs +0 -12
  227. package/dist/storage/index.d.cts +0 -5
  228. package/dist/storage/index.d.mts +0 -5
  229. package/dist/storage/index.mjs +0 -6
  230. package/dist/storage/virtual.cjs +0 -98
  231. package/dist/storage/virtual.d.cts +0 -80
  232. package/dist/storage/virtual.d.cts.map +0 -1
  233. package/dist/storage/virtual.d.mts +0 -80
  234. package/dist/storage/virtual.d.mts.map +0 -1
  235. package/dist/storage/virtual.mjs +0 -97
  236. package/dist/storage/virtual.mjs.map +0 -1
  237. package/dist/ts-morph-BbM83PT9.cjs +0 -114
  238. package/dist/ts-morph-C6YBNc46.mjs +0 -102
  239. package/dist/ts-morph-C6YBNc46.mjs.map +0 -1
  240. package/dist/tsconfig-DeKMGasE.cjs +0 -198
  241. package/dist/tsconfig-HzJsMUrr.mjs +0 -155
  242. package/dist/tsconfig-HzJsMUrr.mjs.map +0 -1
  243. package/dist/typescript/index.cjs +0 -13
  244. package/dist/typescript/index.d.cts +0 -106
  245. package/dist/typescript/index.d.cts.map +0 -1
  246. package/dist/typescript/index.d.mts +0 -106
  247. package/dist/typescript/index.d.mts.map +0 -1
  248. package/dist/typescript/index.mjs +0 -4
  249. /package/dist/{chunk-C0xms8kb.cjs → chunk-C_NdSu1c.cjs} +0 -0
@@ -1,74 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_chunk = require('../chunk-C0xms8kb.cjs');
3
- const require_rpc_serialization = require('./serialization.cjs');
4
- let birpc = require("birpc");
5
- let structured_clone_es = require("structured-clone-es");
6
-
7
- //#region src/rpc/client.ts
8
- function createRpcClient(functions, options) {
9
- const { channel, rpcOptions = {} } = options;
10
- return (0, birpc.createBirpc)(functions, {
11
- ...channel,
12
- timeout: -1,
13
- ...rpcOptions,
14
- proxify: false
15
- });
16
- }
17
- function NOOP() {}
18
- const EMPTY_DEFS = /* @__PURE__ */ new Map();
19
- /**
20
- * Build a birpc `ChannelOptions` object backed by a browser `WebSocket`.
21
- * Pass the result straight to `createRpcClient`'s `channel` option.
22
- */
23
- function createWsRpcChannel(options) {
24
- let url = options.url;
25
- if (options.authToken) url = `${url}?vite_devtools_auth_token=${encodeURIComponent(options.authToken)}`;
26
- const ws = new WebSocket(url);
27
- const { onConnected = NOOP, onError = NOOP, onDisconnected = NOOP, definitions = EMPTY_DEFS } = options;
28
- ws.addEventListener("open", (e) => {
29
- onConnected(e);
30
- });
31
- ws.addEventListener("error", (e) => {
32
- onError(e instanceof Error ? e : new Error(e.type));
33
- });
34
- ws.addEventListener("close", (e) => {
35
- onDisconnected(e);
36
- });
37
- const pendingRequestMethods = /* @__PURE__ */ new Map();
38
- return {
39
- on: (handler) => {
40
- ws.addEventListener("message", (e) => {
41
- handler(e.data);
42
- });
43
- },
44
- post: (data) => {
45
- if (ws.readyState === WebSocket.OPEN) ws.send(data);
46
- else {
47
- function handler() {
48
- ws.send(data);
49
- ws.removeEventListener("open", handler);
50
- }
51
- ws.addEventListener("open", handler);
52
- }
53
- },
54
- serialize: (msg) => {
55
- let method;
56
- if (msg.t === "q") method = msg.m;
57
- else {
58
- method = pendingRequestMethods.get(msg.i);
59
- pendingRequestMethods.delete(msg.i);
60
- }
61
- if (!!method && definitions.get(method)?.jsonSerializable === true) return require_rpc_serialization.strictJsonStringify(msg, method ?? "");
62
- return `${"s:"}${(0, structured_clone_es.stringify)(msg)}`;
63
- },
64
- deserialize: (raw) => {
65
- const msg = raw.startsWith("s:") ? (0, structured_clone_es.parse)(raw.slice("s:".length)) : JSON.parse(raw);
66
- if (msg.t === "q" && msg.i && msg.m) pendingRequestMethods.set(msg.i, msg.m);
67
- return msg;
68
- }
69
- };
70
- }
71
-
72
- //#endregion
73
- exports.createRpcClient = createRpcClient;
74
- exports.createWsRpcChannel = createWsRpcChannel;
@@ -1,31 +0,0 @@
1
- import { RpcFunctionDefinitionAny } from "./types.cjs";
2
- import { BirpcOptions, BirpcReturn, ChannelOptions } from "birpc";
3
-
4
- //#region src/rpc/client.d.ts
5
- declare function createRpcClient<ServerFunctions extends object = Record<string, never>, ClientFunctions extends object = Record<string, never>>(functions: ClientFunctions, options: {
6
- channel: ChannelOptions;
7
- rpcOptions?: Partial<BirpcOptions<ServerFunctions, ClientFunctions, boolean>>;
8
- }): BirpcReturn<ServerFunctions, ClientFunctions, false>;
9
- interface WsRpcChannelOptions {
10
- url: string;
11
- onConnected?: (e: Event) => void;
12
- onError?: (e: Error) => void;
13
- onDisconnected?: (e: CloseEvent) => void;
14
- authToken?: string;
15
- /**
16
- * RPC function definitions (or just the `jsonSerializable` flag per
17
- * method) used to dispatch the per-call wire serializer. Pass an
18
- * empty / partial map on clients that don't have the full registry —
19
- * encoding falls back to structured-clone (the safer superset) and
20
- * decoding still routes correctly via the wire prefix.
21
- */
22
- definitions?: ReadonlyMap<string, Pick<RpcFunctionDefinitionAny, "jsonSerializable">>;
23
- }
24
- /**
25
- * Build a birpc `ChannelOptions` object backed by a browser `WebSocket`.
26
- * Pass the result straight to `createRpcClient`'s `channel` option.
27
- */
28
- declare function createWsRpcChannel(options: WsRpcChannelOptions): ChannelOptions;
29
- //#endregion
30
- export { WsRpcChannelOptions, createRpcClient, createWsRpcChannel };
31
- //# sourceMappingURL=client.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"client.d.cts","names":[],"sources":["../../src/rpc/client.ts"],"mappings":";;;;iBA4BgB,eAAA,kCACmB,MAAA,kDACA,MAAA,gBAAA,CAEjC,SAAA,EAAW,eAAA,EACX,OAAA;EACE,OAAA,EAAS,cAAA;EACT,UAAA,GAAa,OAAA,CACX,YAAA,CAAa,eAAA,EAAiB,eAAA;AAAA,IAGjC,WAAA,CAAY,eAAA,EAAiB,eAAA;AAAA,UAWf,mBAAA;EACf,GAAA;EACA,WAAA,IAAe,CAAA,EAAG,KAAA;EAClB,OAAA,IAAW,CAAA,EAAG,KAAA;EACd,cAAA,IAAkB,CAAA,EAAG,UAAA;EACrB,SAAA;EAnBkC;;;;;;;EA2BlC,WAAA,GAAc,WAAA,SAEZ,IAAA,CAAK,wBAAA;AAAA;;;;;iBAeO,kBAAA,CACd,OAAA,EAAS,mBAAA,GACR,cAAA"}
@@ -1,31 +0,0 @@
1
- import { RpcFunctionDefinitionAny } from "./types.mjs";
2
- import { BirpcOptions, BirpcReturn, ChannelOptions } from "birpc";
3
-
4
- //#region src/rpc/client.d.ts
5
- declare function createRpcClient<ServerFunctions extends object = Record<string, never>, ClientFunctions extends object = Record<string, never>>(functions: ClientFunctions, options: {
6
- channel: ChannelOptions;
7
- rpcOptions?: Partial<BirpcOptions<ServerFunctions, ClientFunctions, boolean>>;
8
- }): BirpcReturn<ServerFunctions, ClientFunctions, false>;
9
- interface WsRpcChannelOptions {
10
- url: string;
11
- onConnected?: (e: Event) => void;
12
- onError?: (e: Error) => void;
13
- onDisconnected?: (e: CloseEvent) => void;
14
- authToken?: string;
15
- /**
16
- * RPC function definitions (or just the `jsonSerializable` flag per
17
- * method) used to dispatch the per-call wire serializer. Pass an
18
- * empty / partial map on clients that don't have the full registry —
19
- * encoding falls back to structured-clone (the safer superset) and
20
- * decoding still routes correctly via the wire prefix.
21
- */
22
- definitions?: ReadonlyMap<string, Pick<RpcFunctionDefinitionAny, "jsonSerializable">>;
23
- }
24
- /**
25
- * Build a birpc `ChannelOptions` object backed by a browser `WebSocket`.
26
- * Pass the result straight to `createRpcClient`'s `channel` option.
27
- */
28
- declare function createWsRpcChannel(options: WsRpcChannelOptions): ChannelOptions;
29
- //#endregion
30
- export { WsRpcChannelOptions, createRpcClient, createWsRpcChannel };
31
- //# sourceMappingURL=client.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"client.d.mts","names":[],"sources":["../../src/rpc/client.ts"],"mappings":";;;;iBA4BgB,eAAA,kCACmB,MAAA,kDACA,MAAA,gBAAA,CAEjC,SAAA,EAAW,eAAA,EACX,OAAA;EACE,OAAA,EAAS,cAAA;EACT,UAAA,GAAa,OAAA,CACX,YAAA,CAAa,eAAA,EAAiB,eAAA;AAAA,IAGjC,WAAA,CAAY,eAAA,EAAiB,eAAA;AAAA,UAWf,mBAAA;EACf,GAAA;EACA,WAAA,IAAe,CAAA,EAAG,KAAA;EAClB,OAAA,IAAW,CAAA,EAAG,KAAA;EACd,cAAA,IAAkB,CAAA,EAAG,UAAA;EACrB,SAAA;EAnBkC;;;;;;;EA2BlC,WAAA,GAAc,WAAA,SAEZ,IAAA,CAAK,wBAAA;AAAA;;;;;iBAeO,kBAAA,CACd,OAAA,EAAS,mBAAA,GACR,cAAA"}
@@ -1,71 +0,0 @@
1
- import { STRUCTURED_CLONE_PREFIX, strictJsonStringify, structuredCloneParse, structuredCloneStringify } from "./serialization.mjs";
2
- import { createBirpc } from "birpc";
3
-
4
- //#region src/rpc/client.ts
5
- function createRpcClient(functions, options) {
6
- const { channel, rpcOptions = {} } = options;
7
- return createBirpc(functions, {
8
- ...channel,
9
- timeout: -1,
10
- ...rpcOptions,
11
- proxify: false
12
- });
13
- }
14
- function NOOP() {}
15
- const EMPTY_DEFS = /* @__PURE__ */ new Map();
16
- /**
17
- * Build a birpc `ChannelOptions` object backed by a browser `WebSocket`.
18
- * Pass the result straight to `createRpcClient`'s `channel` option.
19
- */
20
- function createWsRpcChannel(options) {
21
- let url = options.url;
22
- if (options.authToken) url = `${url}?vite_devtools_auth_token=${encodeURIComponent(options.authToken)}`;
23
- const ws = new WebSocket(url);
24
- const { onConnected = NOOP, onError = NOOP, onDisconnected = NOOP, definitions = EMPTY_DEFS } = options;
25
- ws.addEventListener("open", (e) => {
26
- onConnected(e);
27
- });
28
- ws.addEventListener("error", (e) => {
29
- onError(e instanceof Error ? e : new Error(e.type));
30
- });
31
- ws.addEventListener("close", (e) => {
32
- onDisconnected(e);
33
- });
34
- const pendingRequestMethods = /* @__PURE__ */ new Map();
35
- return {
36
- on: (handler) => {
37
- ws.addEventListener("message", (e) => {
38
- handler(e.data);
39
- });
40
- },
41
- post: (data) => {
42
- if (ws.readyState === WebSocket.OPEN) ws.send(data);
43
- else {
44
- function handler() {
45
- ws.send(data);
46
- ws.removeEventListener("open", handler);
47
- }
48
- ws.addEventListener("open", handler);
49
- }
50
- },
51
- serialize: (msg) => {
52
- let method;
53
- if (msg.t === "q") method = msg.m;
54
- else {
55
- method = pendingRequestMethods.get(msg.i);
56
- pendingRequestMethods.delete(msg.i);
57
- }
58
- if (!!method && definitions.get(method)?.jsonSerializable === true) return strictJsonStringify(msg, method ?? "");
59
- return `${"s:"}${structuredCloneStringify(msg)}`;
60
- },
61
- deserialize: (raw) => {
62
- const msg = raw.startsWith("s:") ? structuredCloneParse(raw.slice("s:".length)) : JSON.parse(raw);
63
- if (msg.t === "q" && msg.i && msg.m) pendingRequestMethods.set(msg.i, msg.m);
64
- return msg;
65
- }
66
- };
67
- }
68
-
69
- //#endregion
70
- export { createRpcClient, createWsRpcChannel };
71
- //# sourceMappingURL=client.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"client.mjs","names":[],"sources":["../../src/rpc/client.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport type { BirpcOptions, BirpcReturn, ChannelOptions } from \"birpc\";\nimport { createBirpc } from \"birpc\";\nimport {\n strictJsonStringify,\n STRUCTURED_CLONE_PREFIX,\n structuredCloneParse,\n structuredCloneStringify\n} from \"./serialization\";\nimport type { RpcFunctionDefinitionAny } from \"./types\";\n\nexport function createRpcClient<\n ServerFunctions extends object = Record<string, never>,\n ClientFunctions extends object = Record<string, never>\n>(\n functions: ClientFunctions,\n options: {\n channel: ChannelOptions;\n rpcOptions?: Partial<\n BirpcOptions<ServerFunctions, ClientFunctions, boolean>\n >;\n }\n): BirpcReturn<ServerFunctions, ClientFunctions, false> {\n const { channel, rpcOptions = {} } = options;\n\n return createBirpc<ServerFunctions, ClientFunctions, false>(functions, {\n ...channel,\n timeout: -1,\n ...rpcOptions,\n proxify: false\n });\n}\n\nexport interface WsRpcChannelOptions {\n url: string;\n onConnected?: (e: Event) => void;\n onError?: (e: Error) => void;\n onDisconnected?: (e: CloseEvent) => void;\n authToken?: string;\n /**\n * RPC function definitions (or just the `jsonSerializable` flag per\n * method) used to dispatch the per-call wire serializer. Pass an\n * empty / partial map on clients that don't have the full registry —\n * encoding falls back to structured-clone (the safer superset) and\n * decoding still routes correctly via the wire prefix.\n */\n definitions?: ReadonlyMap<\n string,\n Pick<RpcFunctionDefinitionAny, \"jsonSerializable\">\n >;\n}\n\nfunction NOOP() {}\n\nconst EMPTY_DEFS: ReadonlyMap<\n string,\n Pick<RpcFunctionDefinitionAny, \"jsonSerializable\">\n> = new Map();\n\n/**\n * Build a birpc `ChannelOptions` object backed by a browser `WebSocket`.\n * Pass the result straight to `createRpcClient`'s `channel` option.\n */\nexport function createWsRpcChannel(\n options: WsRpcChannelOptions\n): ChannelOptions {\n let url = options.url;\n if (options.authToken) {\n url = `${url}?vite_devtools_auth_token=${encodeURIComponent(options.authToken)}`;\n }\n const ws = new WebSocket(url);\n const {\n onConnected = NOOP,\n onError = NOOP,\n onDisconnected = NOOP,\n definitions = EMPTY_DEFS\n } = options;\n\n ws.addEventListener(\"open\", e => {\n onConnected(e);\n });\n\n ws.addEventListener(\"error\", e => {\n const _e = e instanceof Error ? e : new Error(e.type);\n onError(_e);\n });\n\n ws.addEventListener(\"close\", e => {\n onDisconnected(e);\n });\n\n // Per-channel state: maps an incoming request id to its method name\n // so the matching outgoing response can independently look the\n // method up in `definitions` and pick the right encoder.\n const pendingRequestMethods = new Map<string, string>();\n\n return {\n on: (handler: (data: string) => void) => {\n ws.addEventListener(\"message\", e => {\n handler(e.data);\n });\n },\n post: (data: string) => {\n if (ws.readyState === WebSocket.OPEN) {\n ws.send(data);\n } else {\n function handler() {\n ws.send(data);\n ws.removeEventListener(\"open\", handler);\n }\n ws.addEventListener(\"open\", handler);\n }\n },\n serialize: (msg: any): string => {\n let method: string | undefined;\n if (msg.t === \"q\") {\n method = msg.m;\n } else {\n method = pendingRequestMethods.get(msg.i);\n pendingRequestMethods.delete(msg.i);\n }\n const useJson =\n !!method && definitions.get(method)?.jsonSerializable === true;\n if (useJson) return strictJsonStringify(msg, method ?? \"\");\n return `${STRUCTURED_CLONE_PREFIX}${structuredCloneStringify(msg)}`;\n },\n deserialize: (raw: string): any => {\n const msg: any = raw.startsWith(STRUCTURED_CLONE_PREFIX)\n ? structuredCloneParse(raw.slice(STRUCTURED_CLONE_PREFIX.length))\n : JSON.parse(raw);\n if (msg.t === \"q\" && msg.i && msg.m)\n pendingRequestMethods.set(msg.i, msg.m);\n return msg;\n }\n };\n}\n"],"mappings":";;;;AA4BA,SAAgB,gBAId,WACA,SAMsD;CACtD,MAAM,EAAE,SAAS,aAAa,EAAE,KAAK;AAErC,QAAO,YAAqD,WAAW;EACrE,GAAG;EACH,SAAS;EACT,GAAG;EACH,SAAS;EACV,CAAC;;AAsBJ,SAAS,OAAO;AAEhB,MAAM,6BAGF,IAAI,KAAK;;;;;AAMb,SAAgB,mBACd,SACgB;CAChB,IAAI,MAAM,QAAQ;AAClB,KAAI,QAAQ,UACV,OAAM,GAAG,IAAI,4BAA4B,mBAAmB,QAAQ,UAAU;CAEhF,MAAM,KAAK,IAAI,UAAU,IAAI;CAC7B,MAAM,EACJ,cAAc,MACd,UAAU,MACV,iBAAiB,MACjB,cAAc,eACZ;AAEJ,IAAG,iBAAiB,SAAQ,MAAK;AAC/B,cAAY,EAAE;GACd;AAEF,IAAG,iBAAiB,UAAS,MAAK;AAEhC,UADW,aAAa,QAAQ,IAAI,IAAI,MAAM,EAAE,KAAK,CAC1C;GACX;AAEF,IAAG,iBAAiB,UAAS,MAAK;AAChC,iBAAe,EAAE;GACjB;CAKF,MAAM,wCAAwB,IAAI,KAAqB;AAEvD,QAAO;EACL,KAAK,YAAoC;AACvC,MAAG,iBAAiB,YAAW,MAAK;AAClC,YAAQ,EAAE,KAAK;KACf;;EAEJ,OAAO,SAAiB;AACtB,OAAI,GAAG,eAAe,UAAU,KAC9B,IAAG,KAAK,KAAK;QACR;IACL,SAAS,UAAU;AACjB,QAAG,KAAK,KAAK;AACb,QAAG,oBAAoB,QAAQ,QAAQ;;AAEzC,OAAG,iBAAiB,QAAQ,QAAQ;;;EAGxC,YAAY,QAAqB;GAC/B,IAAI;AACJ,OAAI,IAAI,MAAM,IACZ,UAAS,IAAI;QACR;AACL,aAAS,sBAAsB,IAAI,IAAI,EAAE;AACzC,0BAAsB,OAAO,IAAI,EAAE;;AAIrC,OADE,CAAC,CAAC,UAAU,YAAY,IAAI,OAAO,EAAE,qBAAqB,KAC/C,QAAO,oBAAoB,KAAK,UAAU,GAAG;AAC1D,UAAO,UAA6B,yBAAyB,IAAI;;EAEnE,cAAc,QAAqB;GACjC,MAAM,MAAW,IAAI,gBAAmC,GACpD,qBAAqB,IAAI,WAA8B,OAAO,CAAC,GAC/D,KAAK,MAAM,IAAI;AACnB,OAAI,IAAI,MAAM,OAAO,IAAI,KAAK,IAAI,EAChC,uBAAsB,IAAI,IAAI,GAAG,IAAI,EAAE;AACzC,UAAO;;EAEV"}
@@ -1,82 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_chunk = require('../chunk-C0xms8kb.cjs');
3
- let structured_clone_es = require("structured-clone-es");
4
-
5
- //#region src/rpc/serialization.ts
6
- /**
7
- * Wire format used by the WS RPC transport.
8
- *
9
- * - **JSON (default, unprefixed):** payload is plain JSON text. Used when
10
- * the dispatched method is declared `jsonSerializable: true`. Encoded
11
- * via {@link strictJsonStringify} (rejects non-JSON values), decoded
12
- * via `JSON.parse`.
13
- * - **Structured-clone (`s:` prefix):** payload is `s:` followed by
14
- * `structured-clone-es` text. Used when the method is declared
15
- * `jsonSerializable: false` (or omitted, the default). Round-trips
16
- * `Map`, `Set`, `Date`, `BigInt`, cycles, and class instances.
17
- *
18
- * birpc envelopes always start with `{`, so a leading byte that is not
19
- * `s` is unambiguously JSON. Each direction independently chooses its
20
- * encoding from local definitions — request and response are not
21
- * coupled by a mirror rule.
22
- */
23
- const STRUCTURED_CLONE_PREFIX = "s:";
24
- /**
25
- * `JSON.stringify` with a single-pass strict replacer.
26
- *
27
- * Throws `DF0020` synchronously when the value contains a type JSON
28
- * cannot round-trip losslessly: `Map`, `Set`, `Date`, `BigInt`, class
29
- * instances, or `undefined` inside an array (silently becomes `null`).
30
- *
31
- * Native pass-throughs (no extra work needed):
32
- * - circular references — `JSON.stringify` raises `TypeError`.
33
- * - `BigInt` at top level — caught here for a friendlier error path.
34
- *
35
- * Lenient cases (allowed without throwing):
36
- * - `undefined` as an object property — legitimate optional field;
37
- * JSON.stringify just omits it.
38
- * - `undefined` at the root — legitimate "action returned nothing".
39
- * - `Symbol` / `Function` values — semantically "drop me" in JSON.
40
- *
41
- * `fnName` is used only for the diagnostic message — pass the RPC
42
- * function name when calling from a wire serializer / dump writer so
43
- * the error points at the offending function.
44
- */
45
- function strictJsonStringify(value, fnName = "") {
46
- return JSON.stringify(value, function strictReplacer(key, val) {
47
- const holder = this;
48
- const original = holder != null ? holder[key] : val;
49
- if (original === void 0) {
50
- if (Array.isArray(holder)) throw nonJsonAt(fnName, "undefined", holder, key);
51
- return val;
52
- }
53
- if (original === null) return val;
54
- if (typeof original === "bigint") throw nonJsonAt(fnName, "BigInt", holder, key);
55
- if (typeof original === "object") {
56
- if (original instanceof Map) throw nonJsonAt(fnName, "Map", holder, key);
57
- if (original instanceof Set) throw nonJsonAt(fnName, "Set", holder, key);
58
- if (original instanceof Date) throw nonJsonAt(fnName, "Date", holder, key);
59
- if (Array.isArray(original)) return val;
60
- const proto = Object.getPrototypeOf(original);
61
- if (proto !== null && proto !== Object.prototype) throw nonJsonAt(fnName, original.constructor?.name ?? "class instance", holder, key);
62
- }
63
- return val;
64
- });
65
- }
66
- function nonJsonAt(fnName, type, parent, key) {
67
- const path = formatPath(parent, key);
68
- return /* @__PURE__ */ new Error(`Serialization error: ${fnName || "<anonymous>"} - ${type} at ${path}`);
69
- }
70
- function formatPath(parent, key) {
71
- if (Array.isArray(parent)) return `[${key}]`;
72
- if (key === "") return "<root>";
73
- return key;
74
- }
75
-
76
- //#endregion
77
- exports.STRUCTURED_CLONE_PREFIX = STRUCTURED_CLONE_PREFIX;
78
- exports.strictJsonStringify = strictJsonStringify;
79
- exports.structuredCloneDeserialize = structured_clone_es.deserialize;
80
- exports.structuredCloneParse = structured_clone_es.parse;
81
- exports.structuredCloneSerialize = structured_clone_es.serialize;
82
- exports.structuredCloneStringify = structured_clone_es.stringify;
@@ -1,46 +0,0 @@
1
- import { deserialize as structuredCloneDeserialize, parse as structuredCloneParse, serialize as structuredCloneSerialize, stringify as structuredCloneStringify } from "structured-clone-es";
2
-
3
- //#region src/rpc/serialization.d.ts
4
- /**
5
- * Wire format used by the WS RPC transport.
6
- *
7
- * - **JSON (default, unprefixed):** payload is plain JSON text. Used when
8
- * the dispatched method is declared `jsonSerializable: true`. Encoded
9
- * via {@link strictJsonStringify} (rejects non-JSON values), decoded
10
- * via `JSON.parse`.
11
- * - **Structured-clone (`s:` prefix):** payload is `s:` followed by
12
- * `structured-clone-es` text. Used when the method is declared
13
- * `jsonSerializable: false` (or omitted, the default). Round-trips
14
- * `Map`, `Set`, `Date`, `BigInt`, cycles, and class instances.
15
- *
16
- * birpc envelopes always start with `{`, so a leading byte that is not
17
- * `s` is unambiguously JSON. Each direction independently chooses its
18
- * encoding from local definitions — request and response are not
19
- * coupled by a mirror rule.
20
- */
21
- declare const STRUCTURED_CLONE_PREFIX = "s:";
22
- /**
23
- * `JSON.stringify` with a single-pass strict replacer.
24
- *
25
- * Throws `DF0020` synchronously when the value contains a type JSON
26
- * cannot round-trip losslessly: `Map`, `Set`, `Date`, `BigInt`, class
27
- * instances, or `undefined` inside an array (silently becomes `null`).
28
- *
29
- * Native pass-throughs (no extra work needed):
30
- * - circular references — `JSON.stringify` raises `TypeError`.
31
- * - `BigInt` at top level — caught here for a friendlier error path.
32
- *
33
- * Lenient cases (allowed without throwing):
34
- * - `undefined` as an object property — legitimate optional field;
35
- * JSON.stringify just omits it.
36
- * - `undefined` at the root — legitimate "action returned nothing".
37
- * - `Symbol` / `Function` values — semantically "drop me" in JSON.
38
- *
39
- * `fnName` is used only for the diagnostic message — pass the RPC
40
- * function name when calling from a wire serializer / dump writer so
41
- * the error points at the offending function.
42
- */
43
- declare function strictJsonStringify(value: unknown, fnName?: string): string;
44
- //#endregion
45
- export { STRUCTURED_CLONE_PREFIX, strictJsonStringify, structuredCloneDeserialize, structuredCloneParse, structuredCloneSerialize, structuredCloneStringify };
46
- //# sourceMappingURL=serialization.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"serialization.d.cts","names":[],"sources":["../../src/rpc/serialization.ts"],"mappings":";;;;AAiDA;;;;;AAuBA;;;;;;;;;;;cAvBa,uBAAA;;;;;;;;;;;;;;;;;;;;;;iBAuBG,mBAAA,CACd,KAAA,WACA,MAAA"}
@@ -1,46 +0,0 @@
1
- import { deserialize as structuredCloneDeserialize, parse as structuredCloneParse, serialize as structuredCloneSerialize, stringify as structuredCloneStringify } from "structured-clone-es";
2
-
3
- //#region src/rpc/serialization.d.ts
4
- /**
5
- * Wire format used by the WS RPC transport.
6
- *
7
- * - **JSON (default, unprefixed):** payload is plain JSON text. Used when
8
- * the dispatched method is declared `jsonSerializable: true`. Encoded
9
- * via {@link strictJsonStringify} (rejects non-JSON values), decoded
10
- * via `JSON.parse`.
11
- * - **Structured-clone (`s:` prefix):** payload is `s:` followed by
12
- * `structured-clone-es` text. Used when the method is declared
13
- * `jsonSerializable: false` (or omitted, the default). Round-trips
14
- * `Map`, `Set`, `Date`, `BigInt`, cycles, and class instances.
15
- *
16
- * birpc envelopes always start with `{`, so a leading byte that is not
17
- * `s` is unambiguously JSON. Each direction independently chooses its
18
- * encoding from local definitions — request and response are not
19
- * coupled by a mirror rule.
20
- */
21
- declare const STRUCTURED_CLONE_PREFIX = "s:";
22
- /**
23
- * `JSON.stringify` with a single-pass strict replacer.
24
- *
25
- * Throws `DF0020` synchronously when the value contains a type JSON
26
- * cannot round-trip losslessly: `Map`, `Set`, `Date`, `BigInt`, class
27
- * instances, or `undefined` inside an array (silently becomes `null`).
28
- *
29
- * Native pass-throughs (no extra work needed):
30
- * - circular references — `JSON.stringify` raises `TypeError`.
31
- * - `BigInt` at top level — caught here for a friendlier error path.
32
- *
33
- * Lenient cases (allowed without throwing):
34
- * - `undefined` as an object property — legitimate optional field;
35
- * JSON.stringify just omits it.
36
- * - `undefined` at the root — legitimate "action returned nothing".
37
- * - `Symbol` / `Function` values — semantically "drop me" in JSON.
38
- *
39
- * `fnName` is used only for the diagnostic message — pass the RPC
40
- * function name when calling from a wire serializer / dump writer so
41
- * the error points at the offending function.
42
- */
43
- declare function strictJsonStringify(value: unknown, fnName?: string): string;
44
- //#endregion
45
- export { STRUCTURED_CLONE_PREFIX, strictJsonStringify, structuredCloneDeserialize, structuredCloneParse, structuredCloneSerialize, structuredCloneStringify };
46
- //# sourceMappingURL=serialization.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"serialization.d.mts","names":[],"sources":["../../src/rpc/serialization.ts"],"mappings":";;;;AAiDA;;;;;AAuBA;;;;;;;;;;;cAvBa,uBAAA;;;;;;;;;;;;;;;;;;;;;;iBAuBG,mBAAA,CACd,KAAA,WACA,MAAA"}
@@ -1,76 +0,0 @@
1
- import { deserialize as structuredCloneDeserialize, parse as structuredCloneParse, serialize as structuredCloneSerialize, stringify as structuredCloneStringify } from "structured-clone-es";
2
-
3
- //#region src/rpc/serialization.ts
4
- /**
5
- * Wire format used by the WS RPC transport.
6
- *
7
- * - **JSON (default, unprefixed):** payload is plain JSON text. Used when
8
- * the dispatched method is declared `jsonSerializable: true`. Encoded
9
- * via {@link strictJsonStringify} (rejects non-JSON values), decoded
10
- * via `JSON.parse`.
11
- * - **Structured-clone (`s:` prefix):** payload is `s:` followed by
12
- * `structured-clone-es` text. Used when the method is declared
13
- * `jsonSerializable: false` (or omitted, the default). Round-trips
14
- * `Map`, `Set`, `Date`, `BigInt`, cycles, and class instances.
15
- *
16
- * birpc envelopes always start with `{`, so a leading byte that is not
17
- * `s` is unambiguously JSON. Each direction independently chooses its
18
- * encoding from local definitions — request and response are not
19
- * coupled by a mirror rule.
20
- */
21
- const STRUCTURED_CLONE_PREFIX = "s:";
22
- /**
23
- * `JSON.stringify` with a single-pass strict replacer.
24
- *
25
- * Throws `DF0020` synchronously when the value contains a type JSON
26
- * cannot round-trip losslessly: `Map`, `Set`, `Date`, `BigInt`, class
27
- * instances, or `undefined` inside an array (silently becomes `null`).
28
- *
29
- * Native pass-throughs (no extra work needed):
30
- * - circular references — `JSON.stringify` raises `TypeError`.
31
- * - `BigInt` at top level — caught here for a friendlier error path.
32
- *
33
- * Lenient cases (allowed without throwing):
34
- * - `undefined` as an object property — legitimate optional field;
35
- * JSON.stringify just omits it.
36
- * - `undefined` at the root — legitimate "action returned nothing".
37
- * - `Symbol` / `Function` values — semantically "drop me" in JSON.
38
- *
39
- * `fnName` is used only for the diagnostic message — pass the RPC
40
- * function name when calling from a wire serializer / dump writer so
41
- * the error points at the offending function.
42
- */
43
- function strictJsonStringify(value, fnName = "") {
44
- return JSON.stringify(value, function strictReplacer(key, val) {
45
- const holder = this;
46
- const original = holder != null ? holder[key] : val;
47
- if (original === void 0) {
48
- if (Array.isArray(holder)) throw nonJsonAt(fnName, "undefined", holder, key);
49
- return val;
50
- }
51
- if (original === null) return val;
52
- if (typeof original === "bigint") throw nonJsonAt(fnName, "BigInt", holder, key);
53
- if (typeof original === "object") {
54
- if (original instanceof Map) throw nonJsonAt(fnName, "Map", holder, key);
55
- if (original instanceof Set) throw nonJsonAt(fnName, "Set", holder, key);
56
- if (original instanceof Date) throw nonJsonAt(fnName, "Date", holder, key);
57
- if (Array.isArray(original)) return val;
58
- const proto = Object.getPrototypeOf(original);
59
- if (proto !== null && proto !== Object.prototype) throw nonJsonAt(fnName, original.constructor?.name ?? "class instance", holder, key);
60
- }
61
- return val;
62
- });
63
- }
64
- function nonJsonAt(fnName, type, parent, key) {
65
- const path = formatPath(parent, key);
66
- return /* @__PURE__ */ new Error(`Serialization error: ${fnName || "<anonymous>"} - ${type} at ${path}`);
67
- }
68
- function formatPath(parent, key) {
69
- if (Array.isArray(parent)) return `[${key}]`;
70
- if (key === "") return "<root>";
71
- return key;
72
- }
73
-
74
- //#endregion
75
- export { STRUCTURED_CLONE_PREFIX, strictJsonStringify, structuredCloneDeserialize, structuredCloneParse, structuredCloneSerialize, structuredCloneStringify };
76
- //# sourceMappingURL=serialization.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"serialization.mjs","names":[],"sources":["../../src/rpc/serialization.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport {\n deserialize as structuredCloneDeserialize,\n parse as structuredCloneParse,\n serialize as structuredCloneSerialize,\n stringify as structuredCloneStringify\n} from \"structured-clone-es\";\n\nexport {\n structuredCloneDeserialize,\n structuredCloneParse,\n structuredCloneSerialize,\n structuredCloneStringify\n};\n\n/**\n * Wire format used by the WS RPC transport.\n *\n * - **JSON (default, unprefixed):** payload is plain JSON text. Used when\n * the dispatched method is declared `jsonSerializable: true`. Encoded\n * via {@link strictJsonStringify} (rejects non-JSON values), decoded\n * via `JSON.parse`.\n * - **Structured-clone (`s:` prefix):** payload is `s:` followed by\n * `structured-clone-es` text. Used when the method is declared\n * `jsonSerializable: false` (or omitted, the default). Round-trips\n * `Map`, `Set`, `Date`, `BigInt`, cycles, and class instances.\n *\n * birpc envelopes always start with `{`, so a leading byte that is not\n * `s` is unambiguously JSON. Each direction independently chooses its\n * encoding from local definitions — request and response are not\n * coupled by a mirror rule.\n */\nexport const STRUCTURED_CLONE_PREFIX = \"s:\";\n\n/**\n * `JSON.stringify` with a single-pass strict replacer.\n *\n * Throws `DF0020` synchronously when the value contains a type JSON\n * cannot round-trip losslessly: `Map`, `Set`, `Date`, `BigInt`, class\n * instances, or `undefined` inside an array (silently becomes `null`).\n *\n * Native pass-throughs (no extra work needed):\n * - circular references — `JSON.stringify` raises `TypeError`.\n * - `BigInt` at top level — caught here for a friendlier error path.\n *\n * Lenient cases (allowed without throwing):\n * - `undefined` as an object property — legitimate optional field;\n * JSON.stringify just omits it.\n * - `undefined` at the root — legitimate \"action returned nothing\".\n * - `Symbol` / `Function` values — semantically \"drop me\" in JSON.\n *\n * `fnName` is used only for the diagnostic message — pass the RPC\n * function name when calling from a wire serializer / dump writer so\n * the error points at the offending function.\n */\nexport function strictJsonStringify(\n value: unknown,\n fnName: string = \"\"\n): string {\n return JSON.stringify(\n value,\n function strictReplacer(this: unknown, key: string, val: unknown): unknown {\n // The replacer receives the value AFTER any `toJSON()` coercion\n // (e.g. `Date` already became an ISO string). To detect raw types,\n // peek at the holder's original property via `this[key]`. At the\n // root, `this` is the wrapper `{ '': value }` so `this['']` is the\n // raw root value.\n const holder = this as Record<string, unknown> | unknown[] | undefined;\n const original = holder != null ? (holder as any)[key] : val;\n\n if (original === undefined) {\n if (Array.isArray(holder))\n throw nonJsonAt(fnName, \"undefined\", holder, key);\n return val;\n }\n if (original === null) return val;\n\n if (typeof original === \"bigint\")\n throw nonJsonAt(fnName, \"BigInt\", holder, key);\n\n if (typeof original === \"object\") {\n if (original instanceof Map)\n throw nonJsonAt(fnName, \"Map\", holder, key);\n if (original instanceof Set)\n throw nonJsonAt(fnName, \"Set\", holder, key);\n if (original instanceof Date)\n throw nonJsonAt(fnName, \"Date\", holder, key);\n if (Array.isArray(original)) return val;\n const proto = Object.getPrototypeOf(original);\n if (proto !== null && proto !== Object.prototype) {\n const ctorName =\n (original as { constructor?: { name?: string } }).constructor\n ?.name ?? \"class instance\";\n throw nonJsonAt(fnName, ctorName, holder, key);\n }\n }\n\n return val;\n }\n );\n}\n\nfunction nonJsonAt(\n fnName: string,\n type: string,\n parent: unknown,\n key: string\n): Error {\n const path = formatPath(parent, key);\n\n return new Error(\n `Serialization error: ${fnName || \"<anonymous>\"} - ${type} at ${path}`\n );\n}\n\nfunction formatPath(parent: unknown, key: string): string {\n if (Array.isArray(parent)) return `[${key}]`;\n if (key === \"\") return \"<root>\";\n return key;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAiDA,MAAa,0BAA0B;;;;;;;;;;;;;;;;;;;;;;AAuBvC,SAAgB,oBACd,OACA,SAAiB,IACT;AACR,QAAO,KAAK,UACV,OACA,SAAS,eAA8B,KAAa,KAAuB;EAMzE,MAAM,SAAS;EACf,MAAM,WAAW,UAAU,OAAQ,OAAe,OAAO;AAEzD,MAAI,aAAa,QAAW;AAC1B,OAAI,MAAM,QAAQ,OAAO,CACvB,OAAM,UAAU,QAAQ,aAAa,QAAQ,IAAI;AACnD,UAAO;;AAET,MAAI,aAAa,KAAM,QAAO;AAE9B,MAAI,OAAO,aAAa,SACtB,OAAM,UAAU,QAAQ,UAAU,QAAQ,IAAI;AAEhD,MAAI,OAAO,aAAa,UAAU;AAChC,OAAI,oBAAoB,IACtB,OAAM,UAAU,QAAQ,OAAO,QAAQ,IAAI;AAC7C,OAAI,oBAAoB,IACtB,OAAM,UAAU,QAAQ,OAAO,QAAQ,IAAI;AAC7C,OAAI,oBAAoB,KACtB,OAAM,UAAU,QAAQ,QAAQ,QAAQ,IAAI;AAC9C,OAAI,MAAM,QAAQ,SAAS,CAAE,QAAO;GACpC,MAAM,QAAQ,OAAO,eAAe,SAAS;AAC7C,OAAI,UAAU,QAAQ,UAAU,OAAO,UAIrC,OAAM,UAAU,QAFb,SAAiD,aAC9C,QAAQ,kBACoB,QAAQ,IAAI;;AAIlD,SAAO;GAEV;;AAGH,SAAS,UACP,QACA,MACA,QACA,KACO;CACP,MAAM,OAAO,WAAW,QAAQ,IAAI;AAEpC,wBAAO,IAAI,MACT,wBAAwB,UAAU,cAAc,KAAK,KAAK,MAAM,OACjE;;AAGH,SAAS,WAAW,QAAiB,KAAqB;AACxD,KAAI,MAAM,QAAQ,OAAO,CAAE,QAAO,IAAI,IAAI;AAC1C,KAAI,QAAQ,GAAI,QAAO;AACvB,QAAO"}
@@ -1,69 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_chunk = require('../chunk-C0xms8kb.cjs');
3
- const require_rpc_serialization = require('./serialization.cjs');
4
- let birpc = require("birpc");
5
- let structured_clone_es = require("structured-clone-es");
6
-
7
- //#region src/rpc/server.ts
8
- function createRpcServer(functions, options = {}) {
9
- return (0, birpc.createBirpcGroup)(functions, [], {
10
- ...options.rpcOptions,
11
- proxify: false
12
- });
13
- }
14
- function NOOP() {}
15
- const EMPTY_DEFS = /* @__PURE__ */ new Map();
16
- /**
17
- * Build a birpc `ChannelOptions` object backed by a browser `WebSocket`.
18
- * Pass the result straight to `createRpcClient`'s `channel` option.
19
- */
20
- function createWsRpcChannel(options) {
21
- const { onConnected = NOOP, onError = NOOP, onDisconnected = NOOP, definitions = EMPTY_DEFS } = options;
22
- const ws = new WebSocket(options.url);
23
- ws.addEventListener("open", (e) => {
24
- onConnected(e);
25
- });
26
- ws.addEventListener("error", (e) => {
27
- onError(e instanceof Error ? e : new Error(e.type));
28
- });
29
- ws.addEventListener("close", (e) => {
30
- onDisconnected(e);
31
- });
32
- const pendingRequestMethods = /* @__PURE__ */ new Map();
33
- return {
34
- on: (handler) => {
35
- ws.addEventListener("message", (e) => {
36
- handler(e.data);
37
- });
38
- },
39
- post: (data) => {
40
- if (ws.readyState === WebSocket.OPEN) ws.send(data);
41
- else {
42
- function handler() {
43
- ws.send(data);
44
- ws.removeEventListener("open", handler);
45
- }
46
- ws.addEventListener("open", handler);
47
- }
48
- },
49
- serialize: (msg) => {
50
- let method;
51
- if (msg.t === "q") method = msg.m;
52
- else {
53
- method = pendingRequestMethods.get(msg.i);
54
- pendingRequestMethods.delete(msg.i);
55
- }
56
- if (!!method && definitions.get(method)?.jsonSerializable === true) return require_rpc_serialization.strictJsonStringify(msg, method ?? "");
57
- return `${"s:"}${(0, structured_clone_es.stringify)(msg)}`;
58
- },
59
- deserialize: (raw) => {
60
- const msg = raw.startsWith("s:") ? (0, structured_clone_es.parse)(raw.slice("s:".length)) : JSON.parse(raw);
61
- if (msg.t === "q" && msg.i && msg.m) pendingRequestMethods.set(msg.i, msg.m);
62
- return msg;
63
- }
64
- };
65
- }
66
-
67
- //#endregion
68
- exports.createRpcServer = createRpcServer;
69
- exports.createWsRpcChannel = createWsRpcChannel;
@@ -1,29 +0,0 @@
1
- import { RpcFunctionDefinitionAny } from "./types.cjs";
2
- import { BirpcGroup, ChannelOptions, EventOptions } from "birpc";
3
-
4
- //#region src/rpc/server.d.ts
5
- declare function createRpcServer<ClientFunctions extends object = Record<string, never>, ServerFunctions extends object = Record<string, never>>(functions: ServerFunctions, options?: {
6
- rpcOptions?: EventOptions<ClientFunctions, ServerFunctions, false>;
7
- }): BirpcGroup<ClientFunctions, ServerFunctions, false>;
8
- interface WsRpcChannelOptions {
9
- url: string;
10
- onConnected?: (e: Event) => void;
11
- onError?: (e: Error) => void;
12
- onDisconnected?: (e: CloseEvent) => void;
13
- /**
14
- * RPC function definitions (or just the `jsonSerializable` flag per
15
- * method) used to dispatch the per-call wire serializer. Pass an
16
- * empty / partial map on clients that don't have the full registry —
17
- * encoding falls back to structured-clone (the safer superset) and
18
- * decoding still routes correctly via the wire prefix.
19
- */
20
- definitions?: ReadonlyMap<string, Pick<RpcFunctionDefinitionAny, "jsonSerializable">>;
21
- }
22
- /**
23
- * Build a birpc `ChannelOptions` object backed by a browser `WebSocket`.
24
- * Pass the result straight to `createRpcClient`'s `channel` option.
25
- */
26
- declare function createWsRpcChannel(options: WsRpcChannelOptions): ChannelOptions;
27
- //#endregion
28
- export { WsRpcChannelOptions, createRpcServer, createWsRpcChannel };
29
- //# sourceMappingURL=server.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"server.d.cts","names":[],"sources":["../../src/rpc/server.ts"],"mappings":";;;;iBA4BgB,eAAA,kCACmB,MAAA,kDACA,MAAA,gBAAA,CAEjC,SAAA,EAAW,eAAA,EACX,OAAA;EACE,UAAA,GAAa,YAAA,CAAa,eAAA,EAAiB,eAAA;AAAA,IAE5C,UAAA,CAAW,eAAA,EAAiB,eAAA;AAAA,UAWd,mBAAA;EACf,GAAA;EACA,WAAA,IAAe,CAAA,EAAG,KAAA;EAClB,OAAA,IAAW,CAAA,EAAG,KAAA;EACd,cAAA,IAAkB,CAAA,EAAG,UAAA;EAjBO;;;;;;;EAyB5B,WAAA,GAAc,WAAA,SAEZ,IAAA,CAAK,wBAAA;AAAA;;;;;iBAeO,kBAAA,CACd,OAAA,EAAS,mBAAA,GACR,cAAA"}
@@ -1,29 +0,0 @@
1
- import { RpcFunctionDefinitionAny } from "./types.mjs";
2
- import { BirpcGroup, ChannelOptions, EventOptions } from "birpc";
3
-
4
- //#region src/rpc/server.d.ts
5
- declare function createRpcServer<ClientFunctions extends object = Record<string, never>, ServerFunctions extends object = Record<string, never>>(functions: ServerFunctions, options?: {
6
- rpcOptions?: EventOptions<ClientFunctions, ServerFunctions, false>;
7
- }): BirpcGroup<ClientFunctions, ServerFunctions, false>;
8
- interface WsRpcChannelOptions {
9
- url: string;
10
- onConnected?: (e: Event) => void;
11
- onError?: (e: Error) => void;
12
- onDisconnected?: (e: CloseEvent) => void;
13
- /**
14
- * RPC function definitions (or just the `jsonSerializable` flag per
15
- * method) used to dispatch the per-call wire serializer. Pass an
16
- * empty / partial map on clients that don't have the full registry —
17
- * encoding falls back to structured-clone (the safer superset) and
18
- * decoding still routes correctly via the wire prefix.
19
- */
20
- definitions?: ReadonlyMap<string, Pick<RpcFunctionDefinitionAny, "jsonSerializable">>;
21
- }
22
- /**
23
- * Build a birpc `ChannelOptions` object backed by a browser `WebSocket`.
24
- * Pass the result straight to `createRpcClient`'s `channel` option.
25
- */
26
- declare function createWsRpcChannel(options: WsRpcChannelOptions): ChannelOptions;
27
- //#endregion
28
- export { WsRpcChannelOptions, createRpcServer, createWsRpcChannel };
29
- //# sourceMappingURL=server.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"server.d.mts","names":[],"sources":["../../src/rpc/server.ts"],"mappings":";;;;iBA4BgB,eAAA,kCACmB,MAAA,kDACA,MAAA,gBAAA,CAEjC,SAAA,EAAW,eAAA,EACX,OAAA;EACE,UAAA,GAAa,YAAA,CAAa,eAAA,EAAiB,eAAA;AAAA,IAE5C,UAAA,CAAW,eAAA,EAAiB,eAAA;AAAA,UAWd,mBAAA;EACf,GAAA;EACA,WAAA,IAAe,CAAA,EAAG,KAAA;EAClB,OAAA,IAAW,CAAA,EAAG,KAAA;EACd,cAAA,IAAkB,CAAA,EAAG,UAAA;EAjBO;;;;;;;EAyB5B,WAAA,GAAc,WAAA,SAEZ,IAAA,CAAK,wBAAA;AAAA;;;;;iBAeO,kBAAA,CACd,OAAA,EAAS,mBAAA,GACR,cAAA"}