@replit/river 0.9.3 → 0.10.1

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 (129) hide show
  1. package/dist/{router/builder.d.ts → builder-3c4485f0.d.ts} +82 -28
  2. package/dist/chunk-7WJ6YLE5.js +683 -0
  3. package/dist/chunk-AJQU4AZG.js +284 -0
  4. package/dist/chunk-ORAG7IAU.js +0 -0
  5. package/dist/chunk-PC65ZFWJ.js +29 -0
  6. package/dist/chunk-R6H2BIMC.js +49 -0
  7. package/dist/chunk-RGMHF6PF.js +65 -0
  8. package/dist/chunk-SLUSVGQH.js +30 -0
  9. package/dist/chunk-UU2Z7LDR.js +113 -0
  10. package/dist/chunk-WVT5QXMZ.js +20 -0
  11. package/dist/chunk-ZE4MX7DF.js +75 -0
  12. package/dist/codec/index.cjs +94 -0
  13. package/dist/codec/index.d.cts +15 -0
  14. package/dist/codec/index.d.ts +15 -4
  15. package/dist/codec/index.js +10 -2
  16. package/dist/connection-8e19874c.d.ts +11 -0
  17. package/dist/connection-f7688cc1.d.ts +11 -0
  18. package/dist/logging/index.cjs +56 -0
  19. package/dist/logging/index.d.cts +28 -0
  20. package/dist/logging/index.d.ts +6 -6
  21. package/dist/logging/index.js +9 -40
  22. package/dist/router/index.cjs +770 -0
  23. package/dist/router/index.d.cts +114 -0
  24. package/dist/router/index.d.ts +114 -10
  25. package/dist/router/index.js +24 -4
  26. package/dist/transport/impls/ws/client.cjs +505 -0
  27. package/dist/transport/impls/ws/client.d.cts +42 -0
  28. package/dist/transport/impls/ws/client.d.ts +9 -12
  29. package/dist/transport/impls/ws/client.js +10 -101
  30. package/dist/transport/impls/ws/server.cjs +457 -0
  31. package/dist/transport/impls/ws/server.d.cts +21 -0
  32. package/dist/transport/impls/ws/server.d.ts +14 -10
  33. package/dist/transport/impls/ws/server.js +11 -47
  34. package/dist/transport/index.cjs +362 -0
  35. package/dist/transport/{transport.d.ts → index.d.cts} +119 -7
  36. package/dist/transport/index.d.ts +273 -13
  37. package/dist/transport/index.js +20 -23
  38. package/dist/{codec/types.d.ts → types-3e5768ec.d.ts} +3 -2
  39. package/dist/util/testHelpers.cjs +731 -0
  40. package/dist/util/testHelpers.d.cts +79 -0
  41. package/dist/util/testHelpers.d.ts +34 -108
  42. package/dist/util/testHelpers.js +137 -320
  43. package/package.json +52 -23
  44. package/dist/__tests__/bandwidth.bench.d.ts +0 -2
  45. package/dist/__tests__/bandwidth.bench.d.ts.map +0 -1
  46. package/dist/__tests__/bandwidth.bench.js +0 -90
  47. package/dist/__tests__/e2e.test.d.ts +0 -2
  48. package/dist/__tests__/e2e.test.d.ts.map +0 -1
  49. package/dist/__tests__/e2e.test.js +0 -316
  50. package/dist/__tests__/fixtures/cleanup.d.ts +0 -12
  51. package/dist/__tests__/fixtures/cleanup.d.ts.map +0 -1
  52. package/dist/__tests__/fixtures/cleanup.js +0 -39
  53. package/dist/__tests__/fixtures/largePayload.json +0 -33
  54. package/dist/__tests__/fixtures/observable.d.ts +0 -26
  55. package/dist/__tests__/fixtures/observable.d.ts.map +0 -1
  56. package/dist/__tests__/fixtures/observable.js +0 -38
  57. package/dist/__tests__/fixtures/observable.test.d.ts +0 -2
  58. package/dist/__tests__/fixtures/observable.test.d.ts.map +0 -1
  59. package/dist/__tests__/fixtures/observable.test.js +0 -39
  60. package/dist/__tests__/fixtures/services.d.ts +0 -288
  61. package/dist/__tests__/fixtures/services.d.ts.map +0 -1
  62. package/dist/__tests__/fixtures/services.js +0 -224
  63. package/dist/__tests__/handler.test.d.ts +0 -2
  64. package/dist/__tests__/handler.test.d.ts.map +0 -1
  65. package/dist/__tests__/handler.test.js +0 -121
  66. package/dist/__tests__/invariants.test.d.ts +0 -2
  67. package/dist/__tests__/invariants.test.d.ts.map +0 -1
  68. package/dist/__tests__/invariants.test.js +0 -138
  69. package/dist/__tests__/serialize.test.d.ts +0 -2
  70. package/dist/__tests__/serialize.test.d.ts.map +0 -1
  71. package/dist/__tests__/serialize.test.js +0 -208
  72. package/dist/__tests__/typescript-stress.test.d.ts +0 -1583
  73. package/dist/__tests__/typescript-stress.test.d.ts.map +0 -1
  74. package/dist/__tests__/typescript-stress.test.js +0 -123
  75. package/dist/codec/binary.d.ts +0 -7
  76. package/dist/codec/binary.d.ts.map +0 -1
  77. package/dist/codec/binary.js +0 -20
  78. package/dist/codec/codec.test.d.ts +0 -5
  79. package/dist/codec/codec.test.d.ts.map +0 -1
  80. package/dist/codec/codec.test.js +0 -41
  81. package/dist/codec/index.d.ts.map +0 -1
  82. package/dist/codec/json.d.ts +0 -7
  83. package/dist/codec/json.d.ts.map +0 -1
  84. package/dist/codec/json.js +0 -51
  85. package/dist/codec/types.d.ts.map +0 -1
  86. package/dist/codec/types.js +0 -1
  87. package/dist/logging/index.d.ts.map +0 -1
  88. package/dist/router/builder.d.ts.map +0 -1
  89. package/dist/router/builder.js +0 -91
  90. package/dist/router/client.d.ts +0 -68
  91. package/dist/router/client.d.ts.map +0 -1
  92. package/dist/router/client.js +0 -159
  93. package/dist/router/context.d.ts +0 -30
  94. package/dist/router/context.d.ts.map +0 -1
  95. package/dist/router/context.js +0 -1
  96. package/dist/router/index.d.ts.map +0 -1
  97. package/dist/router/result.d.ts +0 -25
  98. package/dist/router/result.d.ts.map +0 -1
  99. package/dist/router/result.js +0 -18
  100. package/dist/router/server.d.ts +0 -39
  101. package/dist/router/server.d.ts.map +0 -1
  102. package/dist/router/server.js +0 -217
  103. package/dist/transport/events.d.ts +0 -19
  104. package/dist/transport/events.d.ts.map +0 -1
  105. package/dist/transport/events.js +0 -26
  106. package/dist/transport/impls/stdio/stdio.d.ts +0 -33
  107. package/dist/transport/impls/stdio/stdio.d.ts.map +0 -1
  108. package/dist/transport/impls/stdio/stdio.js +0 -75
  109. package/dist/transport/impls/stdio/stdio.test.d.ts +0 -2
  110. package/dist/transport/impls/stdio/stdio.test.d.ts.map +0 -1
  111. package/dist/transport/impls/stdio/stdio.test.js +0 -25
  112. package/dist/transport/impls/ws/client.d.ts.map +0 -1
  113. package/dist/transport/impls/ws/connection.d.ts +0 -11
  114. package/dist/transport/impls/ws/connection.d.ts.map +0 -1
  115. package/dist/transport/impls/ws/connection.js +0 -23
  116. package/dist/transport/impls/ws/server.d.ts.map +0 -1
  117. package/dist/transport/impls/ws/ws.test.d.ts +0 -2
  118. package/dist/transport/impls/ws/ws.test.d.ts.map +0 -1
  119. package/dist/transport/impls/ws/ws.test.js +0 -117
  120. package/dist/transport/index.d.ts.map +0 -1
  121. package/dist/transport/message.d.ts +0 -143
  122. package/dist/transport/message.d.ts.map +0 -1
  123. package/dist/transport/message.js +0 -113
  124. package/dist/transport/message.test.d.ts +0 -2
  125. package/dist/transport/message.test.d.ts.map +0 -1
  126. package/dist/transport/message.test.js +0 -52
  127. package/dist/transport/transport.d.ts.map +0 -1
  128. package/dist/transport/transport.js +0 -281
  129. package/dist/util/testHelpers.d.ts.map +0 -1
@@ -1,117 +0,0 @@
1
- import http from 'http';
2
- import { describe, test, expect, afterAll } from 'vitest';
3
- import { createWebSocketServer, createWsTransports, createDummyTransportMessage, onServerReady, createLocalWebSocketClient, } from '../../../util/testHelpers';
4
- import { msg, waitForMessage } from '../..';
5
- import { WebSocketServerTransport } from './server';
6
- import { WebSocketClientTransport } from './client';
7
- import { testFinishesCleanly } from '../../../__tests__/fixtures/cleanup';
8
- describe('sending and receiving across websockets works', async () => {
9
- const server = http.createServer();
10
- const port = await onServerReady(server);
11
- const wss = await createWebSocketServer(server);
12
- afterAll(() => {
13
- wss.close();
14
- server.close();
15
- });
16
- test('basic send/receive', async () => {
17
- const [clientTransport, serverTransport] = createWsTransports(port, wss);
18
- const msg = createDummyTransportMessage();
19
- clientTransport.send(msg);
20
- await expect(waitForMessage(serverTransport, (recv) => recv.id === msg.id)).resolves.toStrictEqual(msg.payload);
21
- await testFinishesCleanly({
22
- clientTransports: [clientTransport],
23
- serverTransport,
24
- });
25
- });
26
- test('sending respects to/from fields', async () => {
27
- const makeDummyMessage = (from, to, message) => {
28
- return msg(from, to, 'stream', {
29
- msg: message,
30
- }, 'service', 'proc');
31
- };
32
- const clientId1 = 'client1';
33
- const clientId2 = 'client2';
34
- const serverId = 'SERVER';
35
- const serverTransport = new WebSocketServerTransport(wss, serverId);
36
- const initClient = async (id) => {
37
- const client = new WebSocketClientTransport(() => createLocalWebSocketClient(port), id, 'SERVER');
38
- const initMsg = makeDummyMessage(id, serverId, 'hello server');
39
- client.send(initMsg);
40
- await expect(waitForMessage(serverTransport, (recv) => recv.id === initMsg.id)).resolves.toStrictEqual(initMsg.payload);
41
- return client;
42
- };
43
- const client1 = await initClient(clientId1);
44
- const client2 = await initClient(clientId2);
45
- // sending messages from server to client shouldn't leak between clients
46
- const msg1 = makeDummyMessage('SERVER', 'client1', 'hello client1');
47
- const msg2 = makeDummyMessage('SERVER', 'client2', 'hello client1');
48
- const promises = Promise.all([
49
- // true means reject if we receive any message that isn't the one we are expecting
50
- waitForMessage(client2, (recv) => recv.id === msg2.id, true),
51
- waitForMessage(client1, (recv) => recv.id === msg1.id, true),
52
- ]);
53
- serverTransport.send(msg1);
54
- serverTransport.send(msg2);
55
- await expect(promises).resolves.toStrictEqual([msg1.payload, msg2.payload]);
56
- await testFinishesCleanly({
57
- clientTransports: [client1, client2],
58
- serverTransport,
59
- });
60
- });
61
- });
62
- describe('retry logic', async () => {
63
- const server = http.createServer();
64
- const port = await onServerReady(server);
65
- const wss = await createWebSocketServer(server);
66
- afterAll(() => {
67
- wss.close();
68
- server.close();
69
- });
70
- // TODO: right now, we only test client-side disconnects, we probably
71
- // need to also write tests for server-side crashes (but this involves clearing/restoring state)
72
- // not going to worry about this rn but for future
73
- test('ws transport is recreated after clean disconnect', async () => {
74
- const [clientTransport, serverTransport] = createWsTransports(port, wss);
75
- const msg1 = createDummyTransportMessage();
76
- const msg2 = createDummyTransportMessage();
77
- clientTransport.send(msg1);
78
- await expect(waitForMessage(serverTransport, (recv) => recv.id === msg1.id)).resolves.toStrictEqual(msg1.payload);
79
- clientTransport.connections.forEach((conn) => conn.ws.close());
80
- clientTransport.send(msg2);
81
- // by this point the client should have reconnected
82
- await expect(waitForMessage(serverTransport, (recv) => recv.id === msg2.id)).resolves.toStrictEqual(msg2.payload);
83
- await testFinishesCleanly({
84
- clientTransports: [clientTransport],
85
- serverTransport,
86
- });
87
- });
88
- test('ws transport is recreated after unclean disconnect', async () => {
89
- const [clientTransport, serverTransport] = createWsTransports(port, wss);
90
- const msg1 = createDummyTransportMessage();
91
- const msg2 = createDummyTransportMessage();
92
- clientTransport.send(msg1);
93
- await expect(waitForMessage(serverTransport, (recv) => recv.id === msg1.id)).resolves.toStrictEqual(msg1.payload);
94
- clientTransport.connections.forEach((conn) => conn.ws.terminate());
95
- clientTransport.send(msg2);
96
- // by this point the client should have reconnected
97
- await expect(waitForMessage(serverTransport, (recv) => recv.id === msg2.id)).resolves.toStrictEqual(msg2.payload);
98
- // this is not expected to be clean because we destroyed the transport
99
- await testFinishesCleanly({
100
- clientTransports: [clientTransport],
101
- serverTransport,
102
- });
103
- });
104
- test('ws transport is not recreated after destroy', async () => {
105
- const [clientTransport, serverTransport] = createWsTransports(port, wss);
106
- const msg1 = createDummyTransportMessage();
107
- const msg2 = createDummyTransportMessage();
108
- clientTransport.send(msg1);
109
- await expect(waitForMessage(serverTransport, (recv) => recv.id === msg1.id)).resolves.toStrictEqual(msg1.payload);
110
- clientTransport.destroy();
111
- expect(() => clientTransport.send(msg2)).toThrow(new Error('transport is destroyed, cant send'));
112
- // this is not expected to be clean because we destroyed the transport
113
- expect(clientTransport.state).toEqual('destroyed');
114
- await clientTransport.close();
115
- await serverTransport.close();
116
- });
117
- });
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../transport/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGpD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EACL,sBAAsB,EACtB,4BAA4B,EAC5B,GAAG,EACH,KAAK,GACN,MAAM,WAAW,CAAC;AACnB,YAAY,EACV,gBAAgB,EAChB,SAAS,EACT,sBAAsB,EACtB,iBAAiB,EACjB,YAAY,EACZ,aAAa,GACd,MAAM,WAAW,CAAC;AAEnB;;;;;GAKG;AACH,wBAAsB,cAAc,CAClC,CAAC,EAAE,SAAS,CAAC,UAAU,CAAC,EACxB,MAAM,CAAC,EAAE,CAAC,GAAG,EAAE,sBAAsB,KAAK,OAAO,EACjD,cAAc,CAAC,EAAE,OAAO,oBAczB"}
@@ -1,143 +0,0 @@
1
- import { TSchema } from '@sinclair/typebox';
2
- /**
3
- * Control flags for transport messages.
4
- * An RPC message is coded with StreamOpenBit | StreamClosedBit.
5
- * Streams are expected to start with StreamOpenBit sent and the client SHOULD send an empty
6
- * message with StreamClosedBit to close the stream handler on the server, indicating that
7
- * it will not be using the stream anymore.
8
- */
9
- export declare const enum ControlFlags {
10
- AckBit = 1,
11
- StreamOpenBit = 2,
12
- StreamClosedBit = 4
13
- }
14
- /**
15
- * Generic Typebox schema for a transport message.
16
- * @template T The type of the payload.
17
- * @param {T} t The payload schema.
18
- * @returns The transport message schema.
19
- */
20
- export declare const TransportMessageSchema: <T extends TSchema>(t: T) => import("@sinclair/typebox").TObject<{
21
- id: import("@sinclair/typebox").TString;
22
- from: import("@sinclair/typebox").TString;
23
- to: import("@sinclair/typebox").TString;
24
- serviceName: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TNull]>>;
25
- procedureName: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TNull]>>;
26
- streamId: import("@sinclair/typebox").TString;
27
- controlFlags: import("@sinclair/typebox").TInteger;
28
- payload: T;
29
- }>;
30
- /**
31
- * Defines the schema for a transport acknowledgement message. This is never constructed manually
32
- * and is only used internally by the library for tracking inflight messages.
33
- * @returns The transport message schema.
34
- */
35
- export declare const TransportAckSchema: import("@sinclair/typebox").TObject<{
36
- id: import("@sinclair/typebox").TString;
37
- from: import("@sinclair/typebox").TString;
38
- to: import("@sinclair/typebox").TString;
39
- serviceName: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TNull]>>;
40
- procedureName: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TNull]>>;
41
- streamId: import("@sinclair/typebox").TString;
42
- controlFlags: import("@sinclair/typebox").TInteger;
43
- payload: import("@sinclair/typebox").TObject<{
44
- ack: import("@sinclair/typebox").TString;
45
- }>;
46
- }>;
47
- export declare const ControlMessagePayloadSchema: import("@sinclair/typebox").TObject<{
48
- type: import("@sinclair/typebox").TLiteral<"CLOSE">;
49
- }>;
50
- /**
51
- * Defines the schema for an opaque transport message that is agnostic to any
52
- * procedure/service.
53
- * @returns The transport message schema.
54
- */
55
- export declare const OpaqueTransportMessageSchema: import("@sinclair/typebox").TObject<{
56
- id: import("@sinclair/typebox").TString;
57
- from: import("@sinclair/typebox").TString;
58
- to: import("@sinclair/typebox").TString;
59
- serviceName: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TNull]>>;
60
- procedureName: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TNull]>>;
61
- streamId: import("@sinclair/typebox").TString;
62
- controlFlags: import("@sinclair/typebox").TInteger;
63
- payload: import("@sinclair/typebox").TUnknown;
64
- }>;
65
- /**
66
- * Represents a transport message. This is the same type as {@link TransportMessageSchema} but
67
- * we can't statically infer generics from generic Typebox schemas so we have to define it again here.
68
- *
69
- * TypeScript can't enforce types when a bitmask is involved, so these are the semantics of
70
- * `controlFlags`:
71
- * * If `controlFlags & StreamOpenBit == StreamOpenBit`, `streamId` must be set to a unique value
72
- * (suggestion: use `nanoid`).
73
- * * `serviceName` and `procedureName` must be set only when `controlFlags & StreamOpenBit ==
74
- * StreamOpenBit`.
75
- * * If `controlFlags & StreamClosedBit` is set and the kind is `stream` or `subscription`,
76
- * `payload` can be a control message.
77
- * @template Payload The type of the payload.
78
- */
79
- export type TransportMessage<Payload extends Record<string, unknown> | unknown = Record<string, unknown>> = {
80
- id: string;
81
- from: string;
82
- to: string;
83
- serviceName?: string;
84
- procedureName?: string;
85
- streamId: string;
86
- controlFlags: number;
87
- payload: Payload;
88
- };
89
- export type MessageId = string;
90
- /**
91
- * A type alias for a transport message with an opaque payload.
92
- * @template T - The type of the opaque payload.
93
- */
94
- export type OpaqueTransportMessage = TransportMessage<unknown>;
95
- export type TransportClientId = string;
96
- /**
97
- * Creates a transport message with the given parameters. You shouldn't need to call this manually unless
98
- * you're writing a test.
99
- * @param from The sender of the message.
100
- * @param to The intended recipient of the message.
101
- * @param service The name of the service the message is intended for.
102
- * @param proc The name of the procedure the message is intended for.
103
- * @param stream The ID of the stream the message is intended for.
104
- * @param payload The payload of the message.
105
- * @returns A TransportMessage object with the given parameters.
106
- */
107
- export declare function msg<Payload extends object>(from: string, to: string, streamId: string, payload: Payload, serviceName?: string, procedureName?: string): TransportMessage<Payload>;
108
- /**
109
- * Creates a new transport message as a response to the given message.
110
- * @param msg The original message to respond to.
111
- * @param response The payload of the response message.
112
- * @returns A new transport message with appropriate to, from, and payload fields
113
- */
114
- export declare function reply<Payload extends object>(msg: OpaqueTransportMessage, response: Payload): TransportMessage<Payload>;
115
- /**
116
- * Create a request to close a stream
117
- * @param from The ID of the client initiating the close.
118
- * @param to The ID of the client being closed.
119
- * @param respondTo The transport message to respond to.
120
- * @returns The close message
121
- */
122
- export declare function closeStream(from: TransportClientId, to: TransportClientId, stream: string): TransportMessage<{
123
- type: "CLOSE";
124
- }>;
125
- /**
126
- * Checks if the given control flag (usually found in msg.controlFlag) is an ack message.
127
- * @param controlFlag - The control flag to check.
128
- * @returns True if the control flag contains the AckBit, false otherwise.
129
- */
130
- export declare function isAck(controlFlag: number): boolean;
131
- /**
132
- * Checks if the given control flag (usually found in msg.controlFlag) is a stream open message.
133
- * @param controlFlag - The control flag to check.
134
- * @returns True if the control flag contains the StreamOpenBit, false otherwise.
135
- */
136
- export declare function isStreamOpen(controlFlag: number): boolean;
137
- /**
138
- * Checks if the given control flag (usually found in msg.controlFlag) is a stream close message.
139
- * @param controlFlag - The control flag to check.
140
- * @returns True if the control flag contains the StreamCloseBit, false otherwise.
141
- */
142
- export declare function isStreamClose(controlFlag: number): boolean;
143
- //# sourceMappingURL=message.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../../transport/message.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,OAAO,EAAU,MAAM,mBAAmB,CAAC;AAG1D;;;;;;GAMG;AACH,0BAAkB,YAAY;IAC5B,MAAM,IAAS;IACf,aAAa,IAAS;IACtB,eAAe,IAAS;CACzB;AAED;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB;;;;;;;;;EAU/B,CAAC;AAEL;;;;GAIG;AACH,eAAO,MAAM,kBAAkB;;;;;;;;;;;EAI9B,CAAC;AAEF,eAAO,MAAM,2BAA2B;;EAEtC,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,4BAA4B;;;;;;;;;EAExC,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,gBAAgB,CAC1B,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IACzE;IACF,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC;AAE/B;;;GAGG;AACH,MAAM,MAAM,sBAAsB,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC;AAC/D,MAAM,MAAM,iBAAiB,GAAG,MAAM,CAAC;AAEvC;;;;;;;;;;GAUG;AACH,wBAAgB,GAAG,CAAC,OAAO,SAAS,MAAM,EACxC,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,EACV,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,OAAO,EAChB,WAAW,CAAC,EAAE,MAAM,EACpB,aAAa,CAAC,EAAE,MAAM,GACrB,gBAAgB,CAAC,OAAO,CAAC,CAW3B;AAED;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,OAAO,SAAS,MAAM,EAC1C,GAAG,EAAE,sBAAsB,EAC3B,QAAQ,EAAE,OAAO,GAChB,gBAAgB,CAAC,OAAO,CAAC,CAS3B;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CACzB,IAAI,EAAE,iBAAiB,EACvB,EAAE,EAAE,iBAAiB,EACrB,MAAM,EAAE,MAAM;;GAOf;AAED;;;;GAIG;AACH,wBAAgB,KAAK,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAElD;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAIzD;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAK1D"}
@@ -1,113 +0,0 @@
1
- import { Type } from '@sinclair/typebox';
2
- import { nanoid } from 'nanoid';
3
- /**
4
- * Generic Typebox schema for a transport message.
5
- * @template T The type of the payload.
6
- * @param {T} t The payload schema.
7
- * @returns The transport message schema.
8
- */
9
- export const TransportMessageSchema = (t) => Type.Object({
10
- id: Type.String(),
11
- from: Type.String(),
12
- to: Type.String(),
13
- serviceName: Type.Optional(Type.Union([Type.String(), Type.Null()])),
14
- procedureName: Type.Optional(Type.Union([Type.String(), Type.Null()])),
15
- streamId: Type.String(),
16
- controlFlags: Type.Integer(),
17
- payload: t,
18
- });
19
- /**
20
- * Defines the schema for a transport acknowledgement message. This is never constructed manually
21
- * and is only used internally by the library for tracking inflight messages.
22
- * @returns The transport message schema.
23
- */
24
- export const TransportAckSchema = TransportMessageSchema(Type.Object({
25
- ack: Type.String(),
26
- }));
27
- export const ControlMessagePayloadSchema = Type.Object({
28
- type: Type.Literal('CLOSE'),
29
- });
30
- /**
31
- * Defines the schema for an opaque transport message that is agnostic to any
32
- * procedure/service.
33
- * @returns The transport message schema.
34
- */
35
- export const OpaqueTransportMessageSchema = TransportMessageSchema(Type.Unknown());
36
- /**
37
- * Creates a transport message with the given parameters. You shouldn't need to call this manually unless
38
- * you're writing a test.
39
- * @param from The sender of the message.
40
- * @param to The intended recipient of the message.
41
- * @param service The name of the service the message is intended for.
42
- * @param proc The name of the procedure the message is intended for.
43
- * @param stream The ID of the stream the message is intended for.
44
- * @param payload The payload of the message.
45
- * @returns A TransportMessage object with the given parameters.
46
- */
47
- export function msg(from, to, streamId, payload, serviceName, procedureName) {
48
- return {
49
- id: nanoid(),
50
- to,
51
- from,
52
- serviceName,
53
- procedureName,
54
- streamId,
55
- controlFlags: 0,
56
- payload,
57
- };
58
- }
59
- /**
60
- * Creates a new transport message as a response to the given message.
61
- * @param msg The original message to respond to.
62
- * @param response The payload of the response message.
63
- * @returns A new transport message with appropriate to, from, and payload fields
64
- */
65
- export function reply(msg, response) {
66
- return {
67
- id: nanoid(),
68
- streamId: msg.streamId,
69
- controlFlags: 0,
70
- to: msg.from,
71
- from: msg.to,
72
- payload: response,
73
- };
74
- }
75
- /**
76
- * Create a request to close a stream
77
- * @param from The ID of the client initiating the close.
78
- * @param to The ID of the client being closed.
79
- * @param respondTo The transport message to respond to.
80
- * @returns The close message
81
- */
82
- export function closeStream(from, to, stream) {
83
- const closeMessage = msg(from, to, stream, {
84
- type: 'CLOSE',
85
- });
86
- closeMessage.controlFlags |= 4 /* ControlFlags.StreamClosedBit */;
87
- return closeMessage;
88
- }
89
- /**
90
- * Checks if the given control flag (usually found in msg.controlFlag) is an ack message.
91
- * @param controlFlag - The control flag to check.
92
- * @returns True if the control flag contains the AckBit, false otherwise.
93
- */
94
- export function isAck(controlFlag) {
95
- return (controlFlag & 1 /* ControlFlags.AckBit */) === 1 /* ControlFlags.AckBit */;
96
- }
97
- /**
98
- * Checks if the given control flag (usually found in msg.controlFlag) is a stream open message.
99
- * @param controlFlag - The control flag to check.
100
- * @returns True if the control flag contains the StreamOpenBit, false otherwise.
101
- */
102
- export function isStreamOpen(controlFlag) {
103
- return ((controlFlag & 2 /* ControlFlags.StreamOpenBit */) === 2 /* ControlFlags.StreamOpenBit */);
104
- }
105
- /**
106
- * Checks if the given control flag (usually found in msg.controlFlag) is a stream close message.
107
- * @param controlFlag - The control flag to check.
108
- * @returns True if the control flag contains the StreamCloseBit, false otherwise.
109
- */
110
- export function isStreamClose(controlFlag) {
111
- return ((controlFlag & 4 /* ControlFlags.StreamClosedBit */) ===
112
- 4 /* ControlFlags.StreamClosedBit */);
113
- }
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=message.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"message.test.d.ts","sourceRoot":"","sources":["../../transport/message.test.ts"],"names":[],"mappings":""}
@@ -1,52 +0,0 @@
1
- import { isAck, isStreamClose, isStreamOpen, msg, reply, } from './message';
2
- import { describe, test, expect } from 'vitest';
3
- describe('message helpers', () => {
4
- test('ack', () => {
5
- const m = msg('a', 'b', 'stream', { test: 1 }, 'svc', 'proc');
6
- m.controlFlags |= 1 /* ControlFlags.AckBit */;
7
- expect(m).toHaveProperty('controlFlags');
8
- expect(isAck(m.controlFlags)).toBe(true);
9
- expect(isStreamOpen(m.controlFlags)).toBe(false);
10
- expect(isStreamClose(m.controlFlags)).toBe(false);
11
- });
12
- test('streamOpen', () => {
13
- const m = msg('a', 'b', 'stream', { test: 1 }, 'svc', 'proc');
14
- m.controlFlags |= 2 /* ControlFlags.StreamOpenBit */;
15
- expect(m).toHaveProperty('controlFlags');
16
- expect(isAck(m.controlFlags)).toBe(false);
17
- expect(isStreamOpen(m.controlFlags)).toBe(true);
18
- expect(isStreamClose(m.controlFlags)).toBe(false);
19
- });
20
- test('streamClose', () => {
21
- const m = msg('a', 'b', 'stream', { test: 1 }, 'svc', 'proc');
22
- m.controlFlags |= 4 /* ControlFlags.StreamClosedBit */;
23
- expect(m).toHaveProperty('controlFlags');
24
- expect(isAck(m.controlFlags)).toBe(false);
25
- expect(isStreamOpen(m.controlFlags)).toBe(false);
26
- expect(isStreamClose(m.controlFlags)).toBe(true);
27
- });
28
- test('reply', () => {
29
- const m = msg('a', 'b', 'stream', { test: 1 }, 'svc', 'proc');
30
- const payload = { cool: 2 };
31
- const resp = reply(m, payload);
32
- expect(resp.id).not.toBe(m.id);
33
- expect(resp.payload).toEqual(payload);
34
- expect(resp.from).toBe('b');
35
- expect(resp.to).toBe('a');
36
- });
37
- test('default message has no control flags set', () => {
38
- const m = msg('a', 'b', 'stream', { test: 1 }, 'svc', 'proc');
39
- expect(isAck(m.controlFlags)).toBe(false);
40
- expect(isStreamOpen(m.controlFlags)).toBe(false);
41
- expect(isStreamClose(m.controlFlags)).toBe(false);
42
- });
43
- test('combining control flags works', () => {
44
- const m = msg('a', 'b', 'stream', { test: 1 }, 'svc', 'proc');
45
- m.controlFlags |= 2 /* ControlFlags.StreamOpenBit */;
46
- expect(isStreamOpen(m.controlFlags)).toBe(true);
47
- expect(isStreamClose(m.controlFlags)).toBe(false);
48
- m.controlFlags |= 4 /* ControlFlags.StreamClosedBit */;
49
- expect(isStreamOpen(m.controlFlags)).toBe(true);
50
- expect(isStreamClose(m.controlFlags)).toBe(true);
51
- });
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