@replit/river 0.208.4 → 0.209.0
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 +36 -1
- package/dist/{adapter-ChksXKVN.d.ts → adapter-Cp7_gIVA.d.ts} +1 -1
- package/dist/{adapter-Cuc4JtfV.d.cts → adapter-DjiEwOYi.d.cts} +1 -1
- package/dist/{chunk-NJNR3MK5.js → chunk-LPWARXI3.js} +2 -2
- package/dist/{chunk-N62U4PDY.js → chunk-RATCBAZE.js} +174 -168
- package/dist/chunk-RATCBAZE.js.map +1 -0
- package/dist/{chunk-7TKRCDKJ.js → chunk-TVN2TB6X.js} +2 -2
- package/dist/{chunk-7TKRCDKJ.js.map → chunk-TVN2TB6X.js.map} +1 -1
- package/dist/client-BzJwq-hg.d.ts +54 -0
- package/dist/client-aETS93z1.d.cts +54 -0
- package/dist/codec/index.d.cts +3 -3
- package/dist/codec/index.d.ts +3 -3
- package/dist/codec/index.js +2 -2
- package/dist/{connection-Donr3JRB.d.ts → connection-b1wd5XrC.d.ts} +3 -3
- package/dist/{connection-BF4zg6Qv.d.cts → connection-hUWlS-hg.d.cts} +3 -3
- package/dist/{index-D8IOd3LG.d.ts → index-CSM8soK7.d.ts} +1 -1
- package/dist/{index-C9tpZjBN.d.cts → index-D9R6UTMl.d.cts} +1 -1
- package/dist/logging/index.d.cts +2 -2
- package/dist/logging/index.d.ts +2 -2
- package/dist/{message-Di94OL80.d.cts → message-Dlsh5WDF.d.cts} +1 -1
- package/dist/{message-Di94OL80.d.ts → message-Dlsh5WDF.d.ts} +1 -1
- package/dist/router/index.cjs +174 -168
- package/dist/router/index.cjs.map +1 -1
- package/dist/router/index.d.cts +21 -18
- package/dist/router/index.d.ts +21 -18
- package/dist/router/index.js +3 -3
- package/dist/server-BBgDVOzk.d.cts +72 -0
- package/dist/server-DZ0Yzmpf.d.ts +72 -0
- package/dist/services-DBvjc-Mq.d.ts +1010 -0
- package/dist/services-DC_uol9A.d.cts +1010 -0
- package/dist/testUtil/index.cjs +1 -1
- package/dist/testUtil/index.cjs.map +1 -1
- package/dist/testUtil/index.d.cts +9 -7
- package/dist/testUtil/index.d.ts +9 -7
- package/dist/testUtil/index.js +2 -2
- package/dist/testUtil/index.js.map +1 -1
- package/dist/transport/impls/ws/client.cjs +1 -1
- package/dist/transport/impls/ws/client.cjs.map +1 -1
- package/dist/transport/impls/ws/client.d.cts +6 -5
- package/dist/transport/impls/ws/client.d.ts +6 -5
- package/dist/transport/impls/ws/client.js +3 -3
- package/dist/transport/impls/ws/server.cjs +1 -1
- package/dist/transport/impls/ws/server.cjs.map +1 -1
- package/dist/transport/impls/ws/server.d.cts +8 -8
- package/dist/transport/impls/ws/server.d.ts +8 -8
- package/dist/transport/impls/ws/server.js +3 -3
- package/dist/transport/impls/ws/server.js.map +1 -1
- package/dist/transport/index.cjs +1 -1
- package/dist/transport/index.cjs.map +1 -1
- package/dist/transport/index.d.cts +7 -74
- package/dist/transport/index.d.ts +7 -74
- package/dist/transport/index.js +2 -2
- package/dist/transport-CxjUaGhi.d.cts +577 -0
- package/dist/transport-DwEB67zY.d.ts +577 -0
- package/package.json +1 -1
- package/dist/chunk-N62U4PDY.js.map +0 -1
- package/dist/transport-CCaWx1Rb.d.cts +0 -1566
- package/dist/transport-CZb3vdB4.d.ts +0 -1566
- /package/dist/{chunk-NJNR3MK5.js.map → chunk-LPWARXI3.js.map} +0 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { C as Connection, T as Transport, m as ClientTransportOptions, L as LeakyBucketRateLimit, n as ClientHandshakeOptions, o as ClientSession, b as ProvidedClientTransportOptions, e as SessionNoConnection, f as SessionConnecting, g as SessionHandshaking, h as SessionConnected, p as SessionBackingOff } from './transport-DwEB67zY.js';
|
|
2
|
+
import { c as TransportClientId, b as OpaqueTransportMessage } from './message-Dlsh5WDF.js';
|
|
3
|
+
|
|
4
|
+
declare abstract class ClientTransport<ConnType extends Connection> extends Transport<ConnType> {
|
|
5
|
+
/**
|
|
6
|
+
* The options for this transport.
|
|
7
|
+
*/
|
|
8
|
+
protected options: ClientTransportOptions;
|
|
9
|
+
retryBudget: LeakyBucketRateLimit;
|
|
10
|
+
/**
|
|
11
|
+
* A flag indicating whether the transport should automatically reconnect
|
|
12
|
+
* when a connection is dropped.
|
|
13
|
+
* Realistically, this should always be true for clients unless you are writing
|
|
14
|
+
* tests or a special case where you don't want to reconnect.
|
|
15
|
+
*/
|
|
16
|
+
reconnectOnConnectionDrop: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Optional handshake options for this client.
|
|
19
|
+
*/
|
|
20
|
+
handshakeExtensions?: ClientHandshakeOptions;
|
|
21
|
+
sessions: Map<TransportClientId, ClientSession<ConnType>>;
|
|
22
|
+
constructor(clientId: TransportClientId, providedOptions?: ProvidedClientTransportOptions);
|
|
23
|
+
extendHandshake(options: ClientHandshakeOptions): void;
|
|
24
|
+
/**
|
|
25
|
+
* Abstract method that creates a new {@link Connection} object.
|
|
26
|
+
*
|
|
27
|
+
* @param to The client ID of the node to connect to.
|
|
28
|
+
* @returns The new connection object.
|
|
29
|
+
*/
|
|
30
|
+
protected abstract createNewOutgoingConnection(to: TransportClientId): Promise<ConnType>;
|
|
31
|
+
private tryReconnecting;
|
|
32
|
+
createUnconnectedSession(to: string): SessionNoConnection;
|
|
33
|
+
protected onConnectingFailed(session: SessionConnecting<ConnType>): SessionNoConnection;
|
|
34
|
+
protected onConnClosed(session: SessionHandshaking<ConnType> | SessionConnected<ConnType>): SessionNoConnection;
|
|
35
|
+
protected onConnectionEstablished(session: SessionConnecting<ConnType>, conn: ConnType): SessionHandshaking<ConnType>;
|
|
36
|
+
private rejectHandshakeResponse;
|
|
37
|
+
protected onHandshakeResponse(session: SessionHandshaking<ConnType>, msg: OpaqueTransportMessage): void;
|
|
38
|
+
/**
|
|
39
|
+
* Manually attempts to connect to a client.
|
|
40
|
+
* @param to The client ID of the node to connect to.
|
|
41
|
+
*/
|
|
42
|
+
connect(to: TransportClientId): void;
|
|
43
|
+
/**
|
|
44
|
+
* Manually kills all sessions to the server (including all pending state).
|
|
45
|
+
* This is useful for when you want to close all connections to a server
|
|
46
|
+
* and don't want to wait for the grace period to elapse.
|
|
47
|
+
*/
|
|
48
|
+
hardDisconnect(): void;
|
|
49
|
+
protected onBackoffFinished(session: SessionBackingOff): void;
|
|
50
|
+
private sendHandshake;
|
|
51
|
+
close(): void;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export { ClientTransport as C };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { C as Connection, T as Transport, m as ClientTransportOptions, L as LeakyBucketRateLimit, n as ClientHandshakeOptions, o as ClientSession, b as ProvidedClientTransportOptions, e as SessionNoConnection, f as SessionConnecting, g as SessionHandshaking, h as SessionConnected, p as SessionBackingOff } from './transport-CxjUaGhi.cjs';
|
|
2
|
+
import { c as TransportClientId, b as OpaqueTransportMessage } from './message-Dlsh5WDF.cjs';
|
|
3
|
+
|
|
4
|
+
declare abstract class ClientTransport<ConnType extends Connection> extends Transport<ConnType> {
|
|
5
|
+
/**
|
|
6
|
+
* The options for this transport.
|
|
7
|
+
*/
|
|
8
|
+
protected options: ClientTransportOptions;
|
|
9
|
+
retryBudget: LeakyBucketRateLimit;
|
|
10
|
+
/**
|
|
11
|
+
* A flag indicating whether the transport should automatically reconnect
|
|
12
|
+
* when a connection is dropped.
|
|
13
|
+
* Realistically, this should always be true for clients unless you are writing
|
|
14
|
+
* tests or a special case where you don't want to reconnect.
|
|
15
|
+
*/
|
|
16
|
+
reconnectOnConnectionDrop: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Optional handshake options for this client.
|
|
19
|
+
*/
|
|
20
|
+
handshakeExtensions?: ClientHandshakeOptions;
|
|
21
|
+
sessions: Map<TransportClientId, ClientSession<ConnType>>;
|
|
22
|
+
constructor(clientId: TransportClientId, providedOptions?: ProvidedClientTransportOptions);
|
|
23
|
+
extendHandshake(options: ClientHandshakeOptions): void;
|
|
24
|
+
/**
|
|
25
|
+
* Abstract method that creates a new {@link Connection} object.
|
|
26
|
+
*
|
|
27
|
+
* @param to The client ID of the node to connect to.
|
|
28
|
+
* @returns The new connection object.
|
|
29
|
+
*/
|
|
30
|
+
protected abstract createNewOutgoingConnection(to: TransportClientId): Promise<ConnType>;
|
|
31
|
+
private tryReconnecting;
|
|
32
|
+
createUnconnectedSession(to: string): SessionNoConnection;
|
|
33
|
+
protected onConnectingFailed(session: SessionConnecting<ConnType>): SessionNoConnection;
|
|
34
|
+
protected onConnClosed(session: SessionHandshaking<ConnType> | SessionConnected<ConnType>): SessionNoConnection;
|
|
35
|
+
protected onConnectionEstablished(session: SessionConnecting<ConnType>, conn: ConnType): SessionHandshaking<ConnType>;
|
|
36
|
+
private rejectHandshakeResponse;
|
|
37
|
+
protected onHandshakeResponse(session: SessionHandshaking<ConnType>, msg: OpaqueTransportMessage): void;
|
|
38
|
+
/**
|
|
39
|
+
* Manually attempts to connect to a client.
|
|
40
|
+
* @param to The client ID of the node to connect to.
|
|
41
|
+
*/
|
|
42
|
+
connect(to: TransportClientId): void;
|
|
43
|
+
/**
|
|
44
|
+
* Manually kills all sessions to the server (including all pending state).
|
|
45
|
+
* This is useful for when you want to close all connections to a server
|
|
46
|
+
* and don't want to wait for the grace period to elapse.
|
|
47
|
+
*/
|
|
48
|
+
hardDisconnect(): void;
|
|
49
|
+
protected onBackoffFinished(session: SessionBackingOff): void;
|
|
50
|
+
private sendHandshake;
|
|
51
|
+
close(): void;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export { ClientTransport as C };
|
package/dist/codec/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { C as Codec } from '../adapter-
|
|
2
|
-
export { a as CodecMessageAdapter } from '../adapter-
|
|
3
|
-
import '../message-
|
|
1
|
+
import { C as Codec } from '../adapter-DjiEwOYi.cjs';
|
|
2
|
+
export { a as CodecMessageAdapter } from '../adapter-DjiEwOYi.cjs';
|
|
3
|
+
import '../message-Dlsh5WDF.cjs';
|
|
4
4
|
import '@sinclair/typebox';
|
|
5
5
|
import '@opentelemetry/api';
|
|
6
6
|
|
package/dist/codec/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { C as Codec } from '../adapter-
|
|
2
|
-
export { a as CodecMessageAdapter } from '../adapter-
|
|
3
|
-
import '../message-
|
|
1
|
+
import { C as Codec } from '../adapter-Cp7_gIVA.js';
|
|
2
|
+
export { a as CodecMessageAdapter } from '../adapter-Cp7_gIVA.js';
|
|
3
|
+
import '../message-Dlsh5WDF.js';
|
|
4
4
|
import '@sinclair/typebox';
|
|
5
5
|
import '@opentelemetry/api';
|
|
6
6
|
|
package/dist/codec/index.js
CHANGED
|
@@ -2,9 +2,9 @@ import {
|
|
|
2
2
|
BinaryCodec,
|
|
3
3
|
CodecMessageAdapter,
|
|
4
4
|
NaiveJsonCodec
|
|
5
|
-
} from "../chunk-
|
|
5
|
+
} from "../chunk-TVN2TB6X.js";
|
|
6
6
|
import "../chunk-CC7RN7GI.js";
|
|
7
|
-
import "../chunk-
|
|
7
|
+
import "../chunk-RATCBAZE.js";
|
|
8
8
|
export {
|
|
9
9
|
BinaryCodec,
|
|
10
10
|
CodecMessageAdapter,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { T as Tags } from './index-
|
|
2
|
-
import { P as ProtocolVersion,
|
|
3
|
-
import {
|
|
1
|
+
import { T as Tags } from './index-CSM8soK7.js';
|
|
2
|
+
import { P as ProtocolVersion, b as OpaqueTransportMessage } from './message-Dlsh5WDF.js';
|
|
3
|
+
import { C as Connection } from './transport-DwEB67zY.js';
|
|
4
4
|
import { W as WsLike } from './wslike-Dng9H1C7.js';
|
|
5
5
|
|
|
6
6
|
interface ConnectionInfoExtras extends Record<string, unknown> {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { T as Tags } from './index-
|
|
2
|
-
import { P as ProtocolVersion,
|
|
3
|
-
import {
|
|
1
|
+
import { T as Tags } from './index-D9R6UTMl.cjs';
|
|
2
|
+
import { P as ProtocolVersion, b as OpaqueTransportMessage } from './message-Dlsh5WDF.cjs';
|
|
3
|
+
import { C as Connection } from './transport-CxjUaGhi.cjs';
|
|
4
4
|
import { W as WsLike } from './wslike-Dng9H1C7.cjs';
|
|
5
5
|
|
|
6
6
|
interface ConnectionInfoExtras extends Record<string, unknown> {
|
package/dist/logging/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { a as LogFn, L as Logger, M as MessageMetadata, c as coloredStringLogger, j as jsonLogger, s as stringLogger } from '../index-
|
|
2
|
-
import '../message-
|
|
1
|
+
export { a as LogFn, L as Logger, M as MessageMetadata, c as coloredStringLogger, j as jsonLogger, s as stringLogger } from '../index-D9R6UTMl.cjs';
|
|
2
|
+
import '../message-Dlsh5WDF.cjs';
|
|
3
3
|
import '@sinclair/typebox';
|
|
4
4
|
import '@opentelemetry/api';
|
package/dist/logging/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { a as LogFn, L as Logger, M as MessageMetadata, c as coloredStringLogger, j as jsonLogger, s as stringLogger } from '../index-
|
|
2
|
-
import '../message-
|
|
1
|
+
export { a as LogFn, L as Logger, M as MessageMetadata, c as coloredStringLogger, j as jsonLogger, s as stringLogger } from '../index-CSM8soK7.js';
|
|
2
|
+
import '../message-Dlsh5WDF.js';
|
|
3
3
|
import '@sinclair/typebox';
|
|
4
4
|
import '@opentelemetry/api';
|
|
@@ -105,4 +105,4 @@ declare function isStreamOpen(controlFlag: number): boolean;
|
|
|
105
105
|
*/
|
|
106
106
|
declare function isStreamClose(controlFlag: number): boolean;
|
|
107
107
|
|
|
108
|
-
export {
|
|
108
|
+
export { HandshakeErrorResponseCodes as H, OpaqueTransportMessageSchema as O, type ProtocolVersion as P, TransportMessageSchema as T, type TransportMessage as a, type OpaqueTransportMessage as b, type TransportClientId as c, isStreamClose as d, type PartialTransportMessage as e, type TelemetryInfo as f, HandshakeErrorCustomHandlerFatalResponseCodes as g, isStreamOpen as i };
|
|
@@ -105,4 +105,4 @@ declare function isStreamOpen(controlFlag: number): boolean;
|
|
|
105
105
|
*/
|
|
106
106
|
declare function isStreamClose(controlFlag: number): boolean;
|
|
107
107
|
|
|
108
|
-
export {
|
|
108
|
+
export { HandshakeErrorResponseCodes as H, OpaqueTransportMessageSchema as O, type ProtocolVersion as P, TransportMessageSchema as T, type TransportMessage as a, type OpaqueTransportMessage as b, type TransportClientId as c, isStreamClose as d, type PartialTransportMessage as e, type TelemetryInfo as f, HandshakeErrorCustomHandlerFatalResponseCodes as g, isStreamOpen as i };
|
package/dist/router/index.cjs
CHANGED
|
@@ -27,13 +27,13 @@ __export(router_exports, {
|
|
|
27
27
|
Procedure: () => Procedure,
|
|
28
28
|
RIVER_VERSION: () => version,
|
|
29
29
|
ReaderErrorSchema: () => ReaderErrorSchema,
|
|
30
|
-
ServiceSchema: () => ServiceSchema,
|
|
31
30
|
UNCAUGHT_ERROR_CODE: () => UNCAUGHT_ERROR_CODE,
|
|
32
31
|
UNEXPECTED_DISCONNECT_CODE: () => UNEXPECTED_DISCONNECT_CODE,
|
|
33
32
|
createClient: () => createClient,
|
|
34
33
|
createClientHandshakeOptions: () => createClientHandshakeOptions,
|
|
35
34
|
createServer: () => createServer,
|
|
36
35
|
createServerHandshakeOptions: () => createServerHandshakeOptions,
|
|
36
|
+
createServiceSchema: () => createServiceSchema,
|
|
37
37
|
flattenErrorType: () => flattenErrorType,
|
|
38
38
|
serializeSchema: () => serializeSchema,
|
|
39
39
|
serializeSchemaV1Compat: () => serializeSchemaV1Compat
|
|
@@ -146,182 +146,184 @@ function serializeSchema(services, handshakeSchema) {
|
|
|
146
146
|
}
|
|
147
147
|
return schema;
|
|
148
148
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
if (
|
|
229
|
-
|
|
149
|
+
function createServiceSchema() {
|
|
150
|
+
return class ServiceSchema {
|
|
151
|
+
/**
|
|
152
|
+
* Factory function for creating a fresh state.
|
|
153
|
+
*/
|
|
154
|
+
initializeState;
|
|
155
|
+
/**
|
|
156
|
+
* The procedures for this service.
|
|
157
|
+
*/
|
|
158
|
+
procedures;
|
|
159
|
+
/**
|
|
160
|
+
* @param config - The configuration for this service.
|
|
161
|
+
* @param procedures - The procedures for this service.
|
|
162
|
+
*/
|
|
163
|
+
constructor(config, procedures) {
|
|
164
|
+
this.initializeState = config.initializeState;
|
|
165
|
+
this.procedures = procedures;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Creates a {@link ServiceScaffold}, which can be used to define procedures
|
|
169
|
+
* that can then be merged into a {@link ServiceSchema}, via the scaffold's
|
|
170
|
+
* `finalize` method.
|
|
171
|
+
*
|
|
172
|
+
* There are two patterns that work well with this method. The first is using
|
|
173
|
+
* it to separate the definition of procedures from the definition of the
|
|
174
|
+
* service's configuration:
|
|
175
|
+
* ```ts
|
|
176
|
+
* const MyServiceScaffold = ServiceSchema.scaffold({
|
|
177
|
+
* initializeState: () => ({ count: 0 }),
|
|
178
|
+
* });
|
|
179
|
+
*
|
|
180
|
+
* const incrementProcedures = MyServiceScaffold.procedures({
|
|
181
|
+
* increment: Procedure.rpc({
|
|
182
|
+
* requestInit: Type.Object({ amount: Type.Number() }),
|
|
183
|
+
* responseData: Type.Object({ current: Type.Number() }),
|
|
184
|
+
* async handler(ctx, init) {
|
|
185
|
+
* ctx.state.count += init.amount;
|
|
186
|
+
* return Ok({ current: ctx.state.count });
|
|
187
|
+
* }
|
|
188
|
+
* }),
|
|
189
|
+
* })
|
|
190
|
+
*
|
|
191
|
+
* const MyService = MyServiceScaffold.finalize({
|
|
192
|
+
* ...incrementProcedures,
|
|
193
|
+
* // you can also directly define procedures here
|
|
194
|
+
* });
|
|
195
|
+
* ```
|
|
196
|
+
* This might be really handy if you have a very large service and you're
|
|
197
|
+
* wanting to split it over multiple files. You can define the scaffold
|
|
198
|
+
* in one file, and then import that scaffold in other files where you
|
|
199
|
+
* define procedures - and then finally import the scaffolds and your
|
|
200
|
+
* procedure objects in a final file where you finalize the scaffold into
|
|
201
|
+
* a service schema.
|
|
202
|
+
*
|
|
203
|
+
* The other way is to use it like in a builder pattern:
|
|
204
|
+
* ```ts
|
|
205
|
+
* const MyService = ServiceSchema
|
|
206
|
+
* .scaffold({ initializeState: () => ({ count: 0 }) })
|
|
207
|
+
* .finalize({
|
|
208
|
+
* increment: Procedure.rpc({
|
|
209
|
+
* requestInit: Type.Object({ amount: Type.Number() }),
|
|
210
|
+
* responseData: Type.Object({ current: Type.Number() }),
|
|
211
|
+
* async handler(ctx, init) {
|
|
212
|
+
* ctx.state.count += init.amount;
|
|
213
|
+
* return Ok({ current: ctx.state.count });
|
|
214
|
+
* }
|
|
215
|
+
* }),
|
|
216
|
+
* })
|
|
217
|
+
* ```
|
|
218
|
+
* Depending on your preferences, this may be a more appealing way to define
|
|
219
|
+
* a schema versus using the {@link ServiceSchema.define} method.
|
|
220
|
+
*/
|
|
221
|
+
static scaffold(config) {
|
|
222
|
+
return new ServiceScaffold(config);
|
|
223
|
+
}
|
|
224
|
+
// actual implementation
|
|
225
|
+
static define(configOrProcedures, maybeProcedures) {
|
|
226
|
+
let config;
|
|
227
|
+
let procedures;
|
|
228
|
+
if ("initializeState" in configOrProcedures && typeof configOrProcedures.initializeState === "function") {
|
|
229
|
+
if (!maybeProcedures) {
|
|
230
|
+
throw new Error("Expected procedures to be defined");
|
|
231
|
+
}
|
|
232
|
+
config = configOrProcedures;
|
|
233
|
+
procedures = maybeProcedures;
|
|
234
|
+
} else {
|
|
235
|
+
config = { initializeState: () => ({}) };
|
|
236
|
+
procedures = configOrProcedures;
|
|
230
237
|
}
|
|
231
|
-
config
|
|
232
|
-
procedures = maybeProcedures;
|
|
233
|
-
} else {
|
|
234
|
-
config = { initializeState: () => ({}) };
|
|
235
|
-
procedures = configOrProcedures;
|
|
238
|
+
return new ServiceSchema(config, procedures);
|
|
236
239
|
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
240
|
+
/**
|
|
241
|
+
* Serializes this schema's procedures into a plain object that is JSON compatible.
|
|
242
|
+
*/
|
|
243
|
+
serialize() {
|
|
244
|
+
return {
|
|
245
|
+
procedures: Object.fromEntries(
|
|
246
|
+
Object.entries(this.procedures).map(([procName, procDef]) => [
|
|
247
|
+
procName,
|
|
248
|
+
{
|
|
249
|
+
init: Strict(procDef.requestInit),
|
|
250
|
+
output: Strict(procDef.responseData),
|
|
251
|
+
errors: getSerializedProcErrors(procDef),
|
|
252
|
+
// Only add `description` field if the type declares it.
|
|
253
|
+
..."description" in procDef ? { description: procDef.description } : {},
|
|
254
|
+
type: procDef.type,
|
|
255
|
+
// Only add the `input` field if the type declares it.
|
|
256
|
+
..."requestData" in procDef ? {
|
|
257
|
+
input: Strict(procDef.requestData)
|
|
258
|
+
} : {}
|
|
259
|
+
}
|
|
260
|
+
])
|
|
261
|
+
)
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
// TODO remove once clients migrate to v2
|
|
265
|
+
/**
|
|
266
|
+
* Same as {@link ServiceSchema.serialize}, but with a format that is compatible with
|
|
267
|
+
* protocol v1. This is useful to be able to continue to generate schemas for older
|
|
268
|
+
* clients as they are still supported.
|
|
269
|
+
*/
|
|
270
|
+
serializeV1Compat() {
|
|
271
|
+
return {
|
|
272
|
+
procedures: Object.fromEntries(
|
|
273
|
+
Object.entries(this.procedures).map(
|
|
274
|
+
([procName, procDef]) => {
|
|
275
|
+
if (procDef.type === "rpc" || procDef.type === "subscription") {
|
|
276
|
+
return [
|
|
277
|
+
procName,
|
|
278
|
+
{
|
|
279
|
+
// BACKWARDS COMPAT: map init to input for protocolv1
|
|
280
|
+
// this is the only change needed to make it compatible.
|
|
281
|
+
input: Strict(procDef.requestInit),
|
|
282
|
+
output: Strict(procDef.responseData),
|
|
283
|
+
errors: getSerializedProcErrors(procDef),
|
|
284
|
+
// Only add `description` field if the type declares it.
|
|
285
|
+
..."description" in procDef ? { description: procDef.description } : {},
|
|
286
|
+
type: procDef.type
|
|
287
|
+
}
|
|
288
|
+
];
|
|
289
|
+
}
|
|
275
290
|
return [
|
|
276
291
|
procName,
|
|
277
292
|
{
|
|
278
|
-
|
|
279
|
-
// this is the only change needed to make it compatible.
|
|
280
|
-
input: Strict(procDef.requestInit),
|
|
293
|
+
init: Strict(procDef.requestInit),
|
|
281
294
|
output: Strict(procDef.responseData),
|
|
282
295
|
errors: getSerializedProcErrors(procDef),
|
|
283
296
|
// Only add `description` field if the type declares it.
|
|
284
297
|
..."description" in procDef ? { description: procDef.description } : {},
|
|
285
|
-
type: procDef.type
|
|
298
|
+
type: procDef.type,
|
|
299
|
+
input: Strict(procDef.requestData)
|
|
286
300
|
}
|
|
287
301
|
];
|
|
288
302
|
}
|
|
289
|
-
|
|
290
|
-
procName,
|
|
291
|
-
{
|
|
292
|
-
init: Strict(procDef.requestInit),
|
|
293
|
-
output: Strict(procDef.responseData),
|
|
294
|
-
errors: getSerializedProcErrors(procDef),
|
|
295
|
-
// Only add `description` field if the type declares it.
|
|
296
|
-
..."description" in procDef ? { description: procDef.description } : {},
|
|
297
|
-
type: procDef.type,
|
|
298
|
-
input: Strict(procDef.requestData)
|
|
299
|
-
}
|
|
300
|
-
];
|
|
301
|
-
}
|
|
303
|
+
)
|
|
302
304
|
)
|
|
303
|
-
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
}
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Instantiates this schema into a {@link Service} object.
|
|
309
|
+
*
|
|
310
|
+
* You probably don't need this, usually the River server will handle this
|
|
311
|
+
* for you.
|
|
312
|
+
*/
|
|
313
|
+
instantiate(extendedContext) {
|
|
314
|
+
const state = this.initializeState(extendedContext);
|
|
315
|
+
const dispose = async () => {
|
|
316
|
+
await state[Symbol.asyncDispose]?.();
|
|
317
|
+
state[Symbol.dispose]?.();
|
|
318
|
+
};
|
|
319
|
+
return Object.freeze({
|
|
320
|
+
state,
|
|
321
|
+
procedures: this.procedures,
|
|
322
|
+
[Symbol.asyncDispose]: dispose
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
};
|
|
326
|
+
}
|
|
325
327
|
function getSerializedProcErrors(procDef) {
|
|
326
328
|
if (!("responseError" in procDef) || procDef.responseError[import_typebox2.Kind] === "Never") {
|
|
327
329
|
return Strict(ReaderErrorSchema);
|
|
@@ -384,7 +386,10 @@ var ServiceScaffold = class {
|
|
|
384
386
|
* ```
|
|
385
387
|
*/
|
|
386
388
|
finalize(procedures) {
|
|
387
|
-
return
|
|
389
|
+
return createServiceSchema().define(
|
|
390
|
+
this.config,
|
|
391
|
+
procedures
|
|
392
|
+
);
|
|
388
393
|
}
|
|
389
394
|
};
|
|
390
395
|
|
|
@@ -1234,8 +1239,9 @@ var RiverServer = class {
|
|
|
1234
1239
|
this.middlewares = middlewares;
|
|
1235
1240
|
this.services = instances;
|
|
1236
1241
|
this.contextMap = /* @__PURE__ */ new Map();
|
|
1242
|
+
extendedContext = extendedContext ?? {};
|
|
1237
1243
|
for (const [name, service] of Object.entries(services)) {
|
|
1238
|
-
const instance = service.instantiate(extendedContext
|
|
1244
|
+
const instance = service.instantiate(extendedContext);
|
|
1239
1245
|
instances[name] = instance;
|
|
1240
1246
|
this.contextMap.set(instance, {
|
|
1241
1247
|
...extendedContext,
|
|
@@ -1918,7 +1924,7 @@ function createServerHandshakeOptions(schema, validate) {
|
|
|
1918
1924
|
}
|
|
1919
1925
|
|
|
1920
1926
|
// package.json
|
|
1921
|
-
var version = "0.
|
|
1927
|
+
var version = "0.209.0";
|
|
1922
1928
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1923
1929
|
0 && (module.exports = {
|
|
1924
1930
|
CANCEL_CODE,
|
|
@@ -1928,13 +1934,13 @@ var version = "0.208.4";
|
|
|
1928
1934
|
Procedure,
|
|
1929
1935
|
RIVER_VERSION,
|
|
1930
1936
|
ReaderErrorSchema,
|
|
1931
|
-
ServiceSchema,
|
|
1932
1937
|
UNCAUGHT_ERROR_CODE,
|
|
1933
1938
|
UNEXPECTED_DISCONNECT_CODE,
|
|
1934
1939
|
createClient,
|
|
1935
1940
|
createClientHandshakeOptions,
|
|
1936
1941
|
createServer,
|
|
1937
1942
|
createServerHandshakeOptions,
|
|
1943
|
+
createServiceSchema,
|
|
1938
1944
|
flattenErrorType,
|
|
1939
1945
|
serializeSchema,
|
|
1940
1946
|
serializeSchemaV1Compat
|