@replit/river 0.22.0 → 0.23.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/dist/{chunk-S3YKQT4J.js → chunk-DZOATC6M.js} +2 -2
- package/dist/{chunk-ZPBWKBM5.js → chunk-MJUFKPBT.js} +82 -86
- package/dist/chunk-MJUFKPBT.js.map +1 -0
- package/dist/{chunk-3MFX6NXA.js → chunk-PCKHBAVP.js} +2 -2
- package/dist/chunk-PCKHBAVP.js.map +1 -0
- package/dist/{chunk-GCLEWC26.js → chunk-VOJVLWVX.js} +34 -18
- package/dist/chunk-VOJVLWVX.js.map +1 -0
- package/dist/{chunk-HUBFYN37.js → chunk-ZF2UFTNN.js} +2 -2
- package/dist/{connection-8b059ac4.d.ts → connection-5685d817.d.ts} +1 -1
- package/dist/{connection-bbfe1147.d.ts → connection-7582fb92.d.ts} +1 -1
- package/dist/{index-2ece5234.d.ts → index-a6fe0edd.d.ts} +40 -53
- package/dist/logging/index.d.cts +1 -1
- package/dist/logging/index.d.ts +1 -1
- package/dist/router/index.cjs +33 -17
- package/dist/router/index.cjs.map +1 -1
- package/dist/router/index.d.cts +11 -6
- package/dist/router/index.d.ts +11 -6
- package/dist/router/index.js +2 -2
- package/dist/{services-cb01a7a8.d.ts → services-be91b485.d.ts} +21 -52
- package/dist/{services-acbcc441.d.ts → services-eb9326a1.d.ts} +21 -52
- package/dist/transport/impls/uds/client.cjs +12 -11
- package/dist/transport/impls/uds/client.cjs.map +1 -1
- package/dist/transport/impls/uds/client.d.cts +2 -2
- package/dist/transport/impls/uds/client.d.ts +2 -2
- package/dist/transport/impls/uds/client.js +3 -3
- package/dist/transport/impls/uds/server.cjs +70 -81
- package/dist/transport/impls/uds/server.cjs.map +1 -1
- package/dist/transport/impls/uds/server.d.cts +2 -2
- package/dist/transport/impls/uds/server.d.ts +2 -2
- package/dist/transport/impls/uds/server.js +3 -3
- package/dist/transport/impls/ws/client.cjs +12 -11
- package/dist/transport/impls/ws/client.cjs.map +1 -1
- package/dist/transport/impls/ws/client.d.cts +2 -2
- package/dist/transport/impls/ws/client.d.ts +2 -2
- package/dist/transport/impls/ws/client.js +3 -3
- package/dist/transport/impls/ws/server.cjs +70 -81
- package/dist/transport/impls/ws/server.cjs.map +1 -1
- package/dist/transport/impls/ws/server.d.cts +2 -2
- package/dist/transport/impls/ws/server.d.ts +2 -2
- package/dist/transport/impls/ws/server.js +3 -3
- package/dist/transport/index.cjs +81 -85
- package/dist/transport/index.cjs.map +1 -1
- package/dist/transport/index.d.cts +22 -11
- package/dist/transport/index.d.ts +22 -11
- package/dist/transport/index.js +2 -2
- package/dist/util/testHelpers.cjs +3 -8
- package/dist/util/testHelpers.cjs.map +1 -1
- package/dist/util/testHelpers.d.cts +2 -2
- package/dist/util/testHelpers.d.ts +2 -2
- package/dist/util/testHelpers.js +5 -4
- package/dist/util/testHelpers.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-3MFX6NXA.js.map +0 -1
- package/dist/chunk-GCLEWC26.js.map +0 -1
- package/dist/chunk-ZPBWKBM5.js.map +0 -1
- /package/dist/{chunk-S3YKQT4J.js.map → chunk-DZOATC6M.js.map} +0 -0
- /package/dist/{chunk-HUBFYN37.js.map → chunk-ZF2UFTNN.js.map} +0 -0
package/dist/router/index.d.cts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { A as AnyServiceSchemaMap, I as InstantiatedServiceSchemaMap, P as PayloadType, b as Result, R as RiverError
|
|
2
|
-
export { C as Client, E as Err, O as Ok,
|
|
3
|
-
import { Static } from '@sinclair/typebox';
|
|
1
|
+
import { A as AnyServiceSchemaMap, I as InstantiatedServiceSchemaMap, P as PayloadType, b as Result, R as RiverError } from '../services-eb9326a1.js';
|
|
2
|
+
export { C as Client, E as Err, O as Ok, x as Output, j as ProcErrors, f as ProcHandler, g as ProcInit, h as ProcInput, i as ProcOutput, k as ProcType, a as Procedure, n as ProcedureMap, d as ProcedureResult, o as RPCProcedure, w as ResultUnwrapErr, v as ResultUnwrapOk, u as RiverErrorSchema, c as RiverUncaughtSchema, m as SerializedServerSchema, S as Service, e as ServiceConfiguration, l as ServiceSchema, q as StreamProcedure, p as SubscriptionProcedure, t as UNCAUGHT_ERROR, U as UploadProcedure, V as ValidProcType, r as createClient, s as serializeSchema } from '../services-eb9326a1.js';
|
|
3
|
+
import { Static, TSchema } from '@sinclair/typebox';
|
|
4
4
|
import { ServerTransport } from '../transport/index.cjs';
|
|
5
5
|
import { Pushable } from 'it-pushable';
|
|
6
|
-
import { C as Connection } from '../index-
|
|
6
|
+
import { C as Connection, c as ServerHandshakeOptions, a as ServiceContext } from '../index-a6fe0edd.js';
|
|
7
|
+
export { d as ServiceContextWithState, e as ServiceContextWithTransportInfo } from '../index-a6fe0edd.js';
|
|
7
8
|
import '../types-3e5768ec.js';
|
|
8
9
|
import '@opentelemetry/api';
|
|
9
10
|
|
|
@@ -32,11 +33,15 @@ interface ProcStream {
|
|
|
32
33
|
* The server tracks the state of each service along with open streams and the extended context object.
|
|
33
34
|
* @param transport - The transport to listen to.
|
|
34
35
|
* @param services - An object containing all the services to be registered on the server.
|
|
36
|
+
* @param handshakeOptions - An optional object containing additional handshake options to be passed to the transport.
|
|
35
37
|
* @param extendedContext - An optional object containing additional context to be passed to all services.
|
|
36
38
|
* @returns A promise that resolves to a server instance with the registered services.
|
|
37
39
|
*/
|
|
38
|
-
declare function createServer<Services extends AnyServiceSchemaMap>(transport: ServerTransport<Connection>, services: Services,
|
|
40
|
+
declare function createServer<Services extends AnyServiceSchemaMap, MetadataSchema extends TSchema = TSchema>(transport: ServerTransport<Connection, MetadataSchema>, services: Services, providedServerOptions?: Partial<{
|
|
41
|
+
handshakeOptions?: ServerHandshakeOptions<MetadataSchema>;
|
|
42
|
+
extendedContext?: Omit<ServiceContext, 'state'>;
|
|
43
|
+
}>): Server<Services>;
|
|
39
44
|
|
|
40
|
-
var version = "0.
|
|
45
|
+
var version = "0.23.0";
|
|
41
46
|
|
|
42
47
|
export { PayloadType, version as RIVER_VERSION, Result, RiverError, Server, ServiceContext, createServer };
|
package/dist/router/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { A as AnyServiceSchemaMap, I as InstantiatedServiceSchemaMap, P as PayloadType, b as Result, R as RiverError
|
|
2
|
-
export { C as Client, E as Err, O as Ok,
|
|
3
|
-
import { Static } from '@sinclair/typebox';
|
|
1
|
+
import { A as AnyServiceSchemaMap, I as InstantiatedServiceSchemaMap, P as PayloadType, b as Result, R as RiverError } from '../services-be91b485.js';
|
|
2
|
+
export { C as Client, E as Err, O as Ok, x as Output, j as ProcErrors, f as ProcHandler, g as ProcInit, h as ProcInput, i as ProcOutput, k as ProcType, a as Procedure, n as ProcedureMap, d as ProcedureResult, o as RPCProcedure, w as ResultUnwrapErr, v as ResultUnwrapOk, u as RiverErrorSchema, c as RiverUncaughtSchema, m as SerializedServerSchema, S as Service, e as ServiceConfiguration, l as ServiceSchema, q as StreamProcedure, p as SubscriptionProcedure, t as UNCAUGHT_ERROR, U as UploadProcedure, V as ValidProcType, r as createClient, s as serializeSchema } from '../services-be91b485.js';
|
|
3
|
+
import { Static, TSchema } from '@sinclair/typebox';
|
|
4
4
|
import { ServerTransport } from '../transport/index.js';
|
|
5
5
|
import { Pushable } from 'it-pushable';
|
|
6
|
-
import { C as Connection } from '../index-
|
|
6
|
+
import { C as Connection, c as ServerHandshakeOptions, a as ServiceContext } from '../index-a6fe0edd.js';
|
|
7
|
+
export { d as ServiceContextWithState, e as ServiceContextWithTransportInfo } from '../index-a6fe0edd.js';
|
|
7
8
|
import '../types-3e5768ec.js';
|
|
8
9
|
import '@opentelemetry/api';
|
|
9
10
|
|
|
@@ -32,11 +33,15 @@ interface ProcStream {
|
|
|
32
33
|
* The server tracks the state of each service along with open streams and the extended context object.
|
|
33
34
|
* @param transport - The transport to listen to.
|
|
34
35
|
* @param services - An object containing all the services to be registered on the server.
|
|
36
|
+
* @param handshakeOptions - An optional object containing additional handshake options to be passed to the transport.
|
|
35
37
|
* @param extendedContext - An optional object containing additional context to be passed to all services.
|
|
36
38
|
* @returns A promise that resolves to a server instance with the registered services.
|
|
37
39
|
*/
|
|
38
|
-
declare function createServer<Services extends AnyServiceSchemaMap>(transport: ServerTransport<Connection>, services: Services,
|
|
40
|
+
declare function createServer<Services extends AnyServiceSchemaMap, MetadataSchema extends TSchema = TSchema>(transport: ServerTransport<Connection, MetadataSchema>, services: Services, providedServerOptions?: Partial<{
|
|
41
|
+
handshakeOptions?: ServerHandshakeOptions<MetadataSchema>;
|
|
42
|
+
extendedContext?: Omit<ServiceContext, 'state'>;
|
|
43
|
+
}>): Server<Services>;
|
|
39
44
|
|
|
40
|
-
var version = "0.
|
|
45
|
+
var version = "0.23.0";
|
|
41
46
|
|
|
42
47
|
export { PayloadType, version as RIVER_VERSION, Result, RiverError, Server, ServiceContext, createServer };
|
package/dist/router/index.js
CHANGED
|
@@ -8,10 +8,10 @@ import {
|
|
|
8
8
|
createClient,
|
|
9
9
|
createServer,
|
|
10
10
|
serializeSchema
|
|
11
|
-
} from "../chunk-
|
|
11
|
+
} from "../chunk-VOJVLWVX.js";
|
|
12
12
|
import {
|
|
13
13
|
version
|
|
14
|
-
} from "../chunk-
|
|
14
|
+
} from "../chunk-PCKHBAVP.js";
|
|
15
15
|
import "../chunk-OTQNCLFH.js";
|
|
16
16
|
export {
|
|
17
17
|
Err,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Static, TObject, TUnion, TString,
|
|
1
|
+
import { TSchema, Static, TObject, TUnion, TString, TNever, TLiteral } from '@sinclair/typebox';
|
|
2
2
|
import { ClientTransport } from './transport/index.js';
|
|
3
3
|
import { Pushable } from 'it-pushable';
|
|
4
|
-
import { C as Connection, T as TransportClientId,
|
|
4
|
+
import { C as Connection, T as TransportClientId, f as ClientHandshakeOptions, e as ServiceContextWithTransportInfo } from './index-a6fe0edd.js';
|
|
5
5
|
|
|
6
6
|
type AsyncIter<T> = AsyncGenerator<T, T>;
|
|
7
7
|
/**
|
|
@@ -63,9 +63,13 @@ interface ClientOptions {
|
|
|
63
63
|
*
|
|
64
64
|
* @template Srv - The type of the server.
|
|
65
65
|
* @param {Transport} transport - The transport to use for communication.
|
|
66
|
+
* @param {TransportClientId} serverId - The ID of the server to connect to.
|
|
67
|
+
* @param {Partial<ClientOptions>} providedClientOptions - The options for the client.
|
|
66
68
|
* @returns The client for the server.
|
|
67
69
|
*/
|
|
68
|
-
declare
|
|
70
|
+
declare function createClient<ServiceSchemaMap extends AnyServiceSchemaMap, MetadataSchema extends TSchema = TSchema>(transport: ClientTransport<Connection, MetadataSchema>, serverId: TransportClientId, providedClientOptions?: Partial<ClientOptions & {
|
|
71
|
+
handshakeOptions: ClientHandshakeOptions<MetadataSchema>;
|
|
72
|
+
}>): Client<ServiceSchemaMap>;
|
|
69
73
|
|
|
70
74
|
type TLiteralString = TLiteral<string>;
|
|
71
75
|
type RiverErrorSchema = TObject<{
|
|
@@ -127,44 +131,6 @@ type Output<RiverClient, ServiceName extends keyof RiverClient, ProcedureName ex
|
|
|
127
131
|
infer __SubscriptionCloseHandle
|
|
128
132
|
] ? SubscriptionOutputMessage : never : never : never : never;
|
|
129
133
|
|
|
130
|
-
/**
|
|
131
|
-
* The context for services/procedures. This is used only on
|
|
132
|
-
* the server.
|
|
133
|
-
*
|
|
134
|
-
* An important detail is that the state prop is always on
|
|
135
|
-
* this interface and it shouldn't be changed, removed, or
|
|
136
|
-
* extended. This prop is for the state of a service.
|
|
137
|
-
*
|
|
138
|
-
* You should use declaration merging to extend this interface
|
|
139
|
-
* with whatever you need. For example, if you need to access
|
|
140
|
-
* a database, you could do:
|
|
141
|
-
*
|
|
142
|
-
* ```ts
|
|
143
|
-
* declare module '@replit/river' {
|
|
144
|
-
* interface ServiceContext {
|
|
145
|
-
* db: Database;
|
|
146
|
-
* }
|
|
147
|
-
* }
|
|
148
|
-
* ```
|
|
149
|
-
*/
|
|
150
|
-
interface ServiceContext {
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* The {@link ServiceContext} with state. This is what is passed to procedures.
|
|
154
|
-
*/
|
|
155
|
-
type ServiceContextWithState<State> = ServiceContext & {
|
|
156
|
-
state: State;
|
|
157
|
-
};
|
|
158
|
-
type ServiceContextWithTransportInfo<State> = ServiceContext & {
|
|
159
|
-
state: Omit<State, typeof Symbol.dispose>;
|
|
160
|
-
to: TransportClientId;
|
|
161
|
-
from: TransportClientId;
|
|
162
|
-
streamId: string;
|
|
163
|
-
session: Session<Connection> & {
|
|
164
|
-
metadata: ParsedHandshakeMetadata;
|
|
165
|
-
};
|
|
166
|
-
};
|
|
167
|
-
|
|
168
134
|
/**
|
|
169
135
|
* Brands a type to prevent it from being directly constructed.
|
|
170
136
|
*/
|
|
@@ -198,7 +164,7 @@ type ProcedureResult<O extends PayloadType, E extends RiverError> = Result<Stati
|
|
|
198
164
|
* @template O - The TypeBox schema of the output object.
|
|
199
165
|
* @template E - The TypeBox schema of the error object.
|
|
200
166
|
*/
|
|
201
|
-
interface
|
|
167
|
+
interface RpcProcedure<State, I extends PayloadType, O extends PayloadType, E extends RiverError> {
|
|
202
168
|
type: 'rpc';
|
|
203
169
|
input: I;
|
|
204
170
|
output: O;
|
|
@@ -289,22 +255,22 @@ type AnyProcedure<State = object> = Procedure<State, ValidProcType, PayloadType,
|
|
|
289
255
|
*/
|
|
290
256
|
type ProcedureMap<State = object> = Record<string, AnyProcedure<State>>;
|
|
291
257
|
/**
|
|
292
|
-
* Creates an {@link
|
|
258
|
+
* Creates an {@link RpcProcedure}.
|
|
293
259
|
*/
|
|
294
260
|
declare function rpc<State, I extends PayloadType, O extends PayloadType>(def: {
|
|
295
261
|
input: I;
|
|
296
262
|
output: O;
|
|
297
263
|
errors?: never;
|
|
298
264
|
description?: string;
|
|
299
|
-
handler:
|
|
300
|
-
}): Branded<
|
|
265
|
+
handler: RpcProcedure<State, I, O, TNever>['handler'];
|
|
266
|
+
}): Branded<RpcProcedure<State, I, O, TNever>>;
|
|
301
267
|
declare function rpc<State, I extends PayloadType, O extends PayloadType, E extends RiverError>(def: {
|
|
302
268
|
input: I;
|
|
303
269
|
output: O;
|
|
304
270
|
errors: E;
|
|
305
271
|
description?: string;
|
|
306
|
-
handler:
|
|
307
|
-
}): Branded<
|
|
272
|
+
handler: RpcProcedure<State, I, O, E>['handler'];
|
|
273
|
+
}): Branded<RpcProcedure<State, I, O, E>>;
|
|
308
274
|
/**
|
|
309
275
|
* Creates an {@link UploadProcedure}, optionally with an initialization message.
|
|
310
276
|
*/
|
|
@@ -394,7 +360,7 @@ declare function stream<State, I extends PayloadType, O extends PayloadType, E e
|
|
|
394
360
|
}): Branded<StreamProcedure<State, I, O, E>>;
|
|
395
361
|
/**
|
|
396
362
|
* Defines a Procedure type that can be a:
|
|
397
|
-
* - {@link
|
|
363
|
+
* - {@link RpcProcedure} for a single message in both directions (1:1)
|
|
398
364
|
* - {@link UploadProcedure} for a client-stream (potentially preceded by an
|
|
399
365
|
* initialization message)
|
|
400
366
|
* - {@link SubscriptionProcedure} for a single message from client, stream from server (1:n)
|
|
@@ -409,7 +375,7 @@ declare function stream<State, I extends PayloadType, O extends PayloadType, E e
|
|
|
409
375
|
*/
|
|
410
376
|
type Procedure<State, Ty extends ValidProcType, I extends PayloadType, O extends PayloadType, E extends RiverError, Init extends PayloadType | null = null> = {
|
|
411
377
|
type: Ty;
|
|
412
|
-
} & (Init extends PayloadType ? Ty extends 'upload' ? UploadProcedure<State, I, O, E, Init> : Ty extends 'stream' ? StreamProcedure<State, I, O, E, Init> : never : Ty extends 'rpc' ?
|
|
378
|
+
} & (Init extends PayloadType ? Ty extends 'upload' ? UploadProcedure<State, I, O, E, Init> : Ty extends 'stream' ? StreamProcedure<State, I, O, E, Init> : never : Ty extends 'rpc' ? RpcProcedure<State, I, O, E> : Ty extends 'upload' ? UploadProcedure<State, I, O, E> : Ty extends 'subscription' ? SubscriptionProcedure<State, I, O, E> : Ty extends 'stream' ? StreamProcedure<State, I, O, E> : never);
|
|
413
379
|
/**
|
|
414
380
|
* Holds the {@link Procedure} creation functions. Use these to create
|
|
415
381
|
* procedures for services. You aren't allowed to create procedures directly.
|
|
@@ -518,8 +484,11 @@ interface SerializedServiceSchema {
|
|
|
518
484
|
init?: PayloadType;
|
|
519
485
|
}>;
|
|
520
486
|
}
|
|
521
|
-
|
|
522
|
-
|
|
487
|
+
interface SerializedServerSchema {
|
|
488
|
+
handshakeSchema?: TSchema;
|
|
489
|
+
services: Record<string, SerializedServiceSchema>;
|
|
490
|
+
}
|
|
491
|
+
declare function serializeSchema(services: AnyServiceSchemaMap, handshakeSchema?: TSchema): SerializedServerSchema;
|
|
523
492
|
/**
|
|
524
493
|
* The schema for a {@link Service}. This is used to define a service, specifically
|
|
525
494
|
* its initial state and procedures.
|
|
@@ -733,4 +702,4 @@ declare class ServiceScaffold<State extends object> {
|
|
|
733
702
|
}>;
|
|
734
703
|
}
|
|
735
704
|
|
|
736
|
-
export { AnyServiceSchemaMap as A,
|
|
705
|
+
export { AnyServiceSchemaMap as A, Client as C, Err as E, InstantiatedServiceSchemaMap as I, Ok as O, PayloadType as P, RiverError as R, Service as S, UploadProcedure as U, ValidProcType as V, Procedure as a, Result as b, RiverUncaughtSchema as c, ProcedureResult as d, ServiceConfiguration as e, ProcHandler as f, ProcInit as g, ProcInput as h, ProcOutput as i, ProcErrors as j, ProcType as k, ServiceSchema as l, SerializedServerSchema as m, ProcedureMap as n, RpcProcedure as o, SubscriptionProcedure as p, StreamProcedure as q, createClient as r, serializeSchema as s, UNCAUGHT_ERROR as t, RiverErrorSchema as u, ResultUnwrapOk as v, ResultUnwrapErr as w, Output as x };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Static, TObject, TUnion, TString,
|
|
1
|
+
import { TSchema, Static, TObject, TUnion, TString, TNever, TLiteral } from '@sinclair/typebox';
|
|
2
2
|
import { ClientTransport } from './transport/index.cjs';
|
|
3
3
|
import { Pushable } from 'it-pushable';
|
|
4
|
-
import { C as Connection, T as TransportClientId,
|
|
4
|
+
import { C as Connection, T as TransportClientId, f as ClientHandshakeOptions, e as ServiceContextWithTransportInfo } from './index-a6fe0edd.js';
|
|
5
5
|
|
|
6
6
|
type AsyncIter<T> = AsyncGenerator<T, T>;
|
|
7
7
|
/**
|
|
@@ -63,9 +63,13 @@ interface ClientOptions {
|
|
|
63
63
|
*
|
|
64
64
|
* @template Srv - The type of the server.
|
|
65
65
|
* @param {Transport} transport - The transport to use for communication.
|
|
66
|
+
* @param {TransportClientId} serverId - The ID of the server to connect to.
|
|
67
|
+
* @param {Partial<ClientOptions>} providedClientOptions - The options for the client.
|
|
66
68
|
* @returns The client for the server.
|
|
67
69
|
*/
|
|
68
|
-
declare
|
|
70
|
+
declare function createClient<ServiceSchemaMap extends AnyServiceSchemaMap, MetadataSchema extends TSchema = TSchema>(transport: ClientTransport<Connection, MetadataSchema>, serverId: TransportClientId, providedClientOptions?: Partial<ClientOptions & {
|
|
71
|
+
handshakeOptions: ClientHandshakeOptions<MetadataSchema>;
|
|
72
|
+
}>): Client<ServiceSchemaMap>;
|
|
69
73
|
|
|
70
74
|
type TLiteralString = TLiteral<string>;
|
|
71
75
|
type RiverErrorSchema = TObject<{
|
|
@@ -127,44 +131,6 @@ type Output<RiverClient, ServiceName extends keyof RiverClient, ProcedureName ex
|
|
|
127
131
|
infer __SubscriptionCloseHandle
|
|
128
132
|
] ? SubscriptionOutputMessage : never : never : never : never;
|
|
129
133
|
|
|
130
|
-
/**
|
|
131
|
-
* The context for services/procedures. This is used only on
|
|
132
|
-
* the server.
|
|
133
|
-
*
|
|
134
|
-
* An important detail is that the state prop is always on
|
|
135
|
-
* this interface and it shouldn't be changed, removed, or
|
|
136
|
-
* extended. This prop is for the state of a service.
|
|
137
|
-
*
|
|
138
|
-
* You should use declaration merging to extend this interface
|
|
139
|
-
* with whatever you need. For example, if you need to access
|
|
140
|
-
* a database, you could do:
|
|
141
|
-
*
|
|
142
|
-
* ```ts
|
|
143
|
-
* declare module '@replit/river' {
|
|
144
|
-
* interface ServiceContext {
|
|
145
|
-
* db: Database;
|
|
146
|
-
* }
|
|
147
|
-
* }
|
|
148
|
-
* ```
|
|
149
|
-
*/
|
|
150
|
-
interface ServiceContext {
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* The {@link ServiceContext} with state. This is what is passed to procedures.
|
|
154
|
-
*/
|
|
155
|
-
type ServiceContextWithState<State> = ServiceContext & {
|
|
156
|
-
state: State;
|
|
157
|
-
};
|
|
158
|
-
type ServiceContextWithTransportInfo<State> = ServiceContext & {
|
|
159
|
-
state: Omit<State, typeof Symbol.dispose>;
|
|
160
|
-
to: TransportClientId;
|
|
161
|
-
from: TransportClientId;
|
|
162
|
-
streamId: string;
|
|
163
|
-
session: Session<Connection> & {
|
|
164
|
-
metadata: ParsedHandshakeMetadata;
|
|
165
|
-
};
|
|
166
|
-
};
|
|
167
|
-
|
|
168
134
|
/**
|
|
169
135
|
* Brands a type to prevent it from being directly constructed.
|
|
170
136
|
*/
|
|
@@ -198,7 +164,7 @@ type ProcedureResult<O extends PayloadType, E extends RiverError> = Result<Stati
|
|
|
198
164
|
* @template O - The TypeBox schema of the output object.
|
|
199
165
|
* @template E - The TypeBox schema of the error object.
|
|
200
166
|
*/
|
|
201
|
-
interface
|
|
167
|
+
interface RpcProcedure<State, I extends PayloadType, O extends PayloadType, E extends RiverError> {
|
|
202
168
|
type: 'rpc';
|
|
203
169
|
input: I;
|
|
204
170
|
output: O;
|
|
@@ -289,22 +255,22 @@ type AnyProcedure<State = object> = Procedure<State, ValidProcType, PayloadType,
|
|
|
289
255
|
*/
|
|
290
256
|
type ProcedureMap<State = object> = Record<string, AnyProcedure<State>>;
|
|
291
257
|
/**
|
|
292
|
-
* Creates an {@link
|
|
258
|
+
* Creates an {@link RpcProcedure}.
|
|
293
259
|
*/
|
|
294
260
|
declare function rpc<State, I extends PayloadType, O extends PayloadType>(def: {
|
|
295
261
|
input: I;
|
|
296
262
|
output: O;
|
|
297
263
|
errors?: never;
|
|
298
264
|
description?: string;
|
|
299
|
-
handler:
|
|
300
|
-
}): Branded<
|
|
265
|
+
handler: RpcProcedure<State, I, O, TNever>['handler'];
|
|
266
|
+
}): Branded<RpcProcedure<State, I, O, TNever>>;
|
|
301
267
|
declare function rpc<State, I extends PayloadType, O extends PayloadType, E extends RiverError>(def: {
|
|
302
268
|
input: I;
|
|
303
269
|
output: O;
|
|
304
270
|
errors: E;
|
|
305
271
|
description?: string;
|
|
306
|
-
handler:
|
|
307
|
-
}): Branded<
|
|
272
|
+
handler: RpcProcedure<State, I, O, E>['handler'];
|
|
273
|
+
}): Branded<RpcProcedure<State, I, O, E>>;
|
|
308
274
|
/**
|
|
309
275
|
* Creates an {@link UploadProcedure}, optionally with an initialization message.
|
|
310
276
|
*/
|
|
@@ -394,7 +360,7 @@ declare function stream<State, I extends PayloadType, O extends PayloadType, E e
|
|
|
394
360
|
}): Branded<StreamProcedure<State, I, O, E>>;
|
|
395
361
|
/**
|
|
396
362
|
* Defines a Procedure type that can be a:
|
|
397
|
-
* - {@link
|
|
363
|
+
* - {@link RpcProcedure} for a single message in both directions (1:1)
|
|
398
364
|
* - {@link UploadProcedure} for a client-stream (potentially preceded by an
|
|
399
365
|
* initialization message)
|
|
400
366
|
* - {@link SubscriptionProcedure} for a single message from client, stream from server (1:n)
|
|
@@ -409,7 +375,7 @@ declare function stream<State, I extends PayloadType, O extends PayloadType, E e
|
|
|
409
375
|
*/
|
|
410
376
|
type Procedure<State, Ty extends ValidProcType, I extends PayloadType, O extends PayloadType, E extends RiverError, Init extends PayloadType | null = null> = {
|
|
411
377
|
type: Ty;
|
|
412
|
-
} & (Init extends PayloadType ? Ty extends 'upload' ? UploadProcedure<State, I, O, E, Init> : Ty extends 'stream' ? StreamProcedure<State, I, O, E, Init> : never : Ty extends 'rpc' ?
|
|
378
|
+
} & (Init extends PayloadType ? Ty extends 'upload' ? UploadProcedure<State, I, O, E, Init> : Ty extends 'stream' ? StreamProcedure<State, I, O, E, Init> : never : Ty extends 'rpc' ? RpcProcedure<State, I, O, E> : Ty extends 'upload' ? UploadProcedure<State, I, O, E> : Ty extends 'subscription' ? SubscriptionProcedure<State, I, O, E> : Ty extends 'stream' ? StreamProcedure<State, I, O, E> : never);
|
|
413
379
|
/**
|
|
414
380
|
* Holds the {@link Procedure} creation functions. Use these to create
|
|
415
381
|
* procedures for services. You aren't allowed to create procedures directly.
|
|
@@ -518,8 +484,11 @@ interface SerializedServiceSchema {
|
|
|
518
484
|
init?: PayloadType;
|
|
519
485
|
}>;
|
|
520
486
|
}
|
|
521
|
-
|
|
522
|
-
|
|
487
|
+
interface SerializedServerSchema {
|
|
488
|
+
handshakeSchema?: TSchema;
|
|
489
|
+
services: Record<string, SerializedServiceSchema>;
|
|
490
|
+
}
|
|
491
|
+
declare function serializeSchema(services: AnyServiceSchemaMap, handshakeSchema?: TSchema): SerializedServerSchema;
|
|
523
492
|
/**
|
|
524
493
|
* The schema for a {@link Service}. This is used to define a service, specifically
|
|
525
494
|
* its initial state and procedures.
|
|
@@ -733,4 +702,4 @@ declare class ServiceScaffold<State extends object> {
|
|
|
733
702
|
}>;
|
|
734
703
|
}
|
|
735
704
|
|
|
736
|
-
export { AnyServiceSchemaMap as A,
|
|
705
|
+
export { AnyServiceSchemaMap as A, Client as C, Err as E, InstantiatedServiceSchemaMap as I, Ok as O, PayloadType as P, RiverError as R, Service as S, UploadProcedure as U, ValidProcType as V, Procedure as a, Result as b, RiverUncaughtSchema as c, ProcedureResult as d, ServiceConfiguration as e, ProcHandler as f, ProcInit as g, ProcInput as h, ProcOutput as i, ProcErrors as j, ProcType as k, ServiceSchema as l, SerializedServerSchema as m, ProcedureMap as n, RpcProcedure as o, SubscriptionProcedure as p, StreamProcedure as q, createClient as r, serializeSchema as s, UNCAUGHT_ERROR as t, RiverErrorSchema as u, ResultUnwrapOk as v, ResultUnwrapErr as w, Output as x };
|
|
@@ -113,7 +113,7 @@ function isAck(controlFlag) {
|
|
|
113
113
|
var import_api = require("@opentelemetry/api");
|
|
114
114
|
|
|
115
115
|
// package.json
|
|
116
|
-
var version = "0.
|
|
116
|
+
var version = "0.23.0";
|
|
117
117
|
|
|
118
118
|
// tracing/index.ts
|
|
119
119
|
function getPropagationContext(ctx) {
|
|
@@ -192,12 +192,6 @@ var Session = class {
|
|
|
192
192
|
* for this session.
|
|
193
193
|
*/
|
|
194
194
|
advertisedSessionId;
|
|
195
|
-
/**
|
|
196
|
-
* The metadata for this session, as parsed from the handshake.
|
|
197
|
-
*
|
|
198
|
-
* Will only ever be populated on the server side.
|
|
199
|
-
*/
|
|
200
|
-
metadata;
|
|
201
195
|
/**
|
|
202
196
|
* Number of messages we've sent along this session (excluding handshake and acks)
|
|
203
197
|
*/
|
|
@@ -1002,6 +996,10 @@ var ClientTransport = class extends Transport {
|
|
|
1002
996
|
* tests or a special case where you don't want to reconnect.
|
|
1003
997
|
*/
|
|
1004
998
|
reconnectOnConnectionDrop = true;
|
|
999
|
+
/**
|
|
1000
|
+
* Optional handshake options for this client.
|
|
1001
|
+
*/
|
|
1002
|
+
handshakeExtensions;
|
|
1005
1003
|
constructor(clientId, providedOptions) {
|
|
1006
1004
|
super(clientId, providedOptions);
|
|
1007
1005
|
this.options = {
|
|
@@ -1011,6 +1009,9 @@ var ClientTransport = class extends Transport {
|
|
|
1011
1009
|
this.inflightConnectionPromises = /* @__PURE__ */ new Map();
|
|
1012
1010
|
this.retryBudget = new LeakyBucketRateLimit(this.options);
|
|
1013
1011
|
}
|
|
1012
|
+
extendHandshake(options) {
|
|
1013
|
+
this.handshakeExtensions = options;
|
|
1014
|
+
}
|
|
1014
1015
|
handleConnection(conn, to) {
|
|
1015
1016
|
if (this.state !== "open")
|
|
1016
1017
|
return;
|
|
@@ -1234,10 +1235,10 @@ var ClientTransport = class extends Transport {
|
|
|
1234
1235
|
}
|
|
1235
1236
|
async sendHandshake(to, conn) {
|
|
1236
1237
|
let metadata;
|
|
1237
|
-
if (this.
|
|
1238
|
-
metadata = await this.
|
|
1239
|
-
if (!import_value.Value.Check(this.
|
|
1240
|
-
log?.error(`handshake metadata did not match schema`, {
|
|
1238
|
+
if (this.handshakeExtensions) {
|
|
1239
|
+
metadata = await this.handshakeExtensions.construct();
|
|
1240
|
+
if (!import_value.Value.Check(this.handshakeExtensions.schema, metadata)) {
|
|
1241
|
+
log?.error(`constructed handshake metadata did not match schema`, {
|
|
1241
1242
|
clientId: this.clientId,
|
|
1242
1243
|
connectedTo: to,
|
|
1243
1244
|
tags: ["invariant-violation"]
|