@replit/river 0.21.1 → 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/README.md +1 -1
- package/dist/{chunk-FDLAPYCK.js → chunk-DZOATC6M.js} +2 -2
- package/dist/{chunk-JMXO5L2X.js → chunk-MJUFKPBT.js} +354 -398
- package/dist/chunk-MJUFKPBT.js.map +1 -0
- package/dist/{chunk-5WFL722S.js → chunk-PCKHBAVP.js} +94 -3
- package/dist/chunk-PCKHBAVP.js.map +1 -0
- package/dist/{chunk-NCXUFDVL.js → chunk-VOJVLWVX.js} +360 -516
- package/dist/chunk-VOJVLWVX.js.map +1 -0
- package/dist/chunk-ZF2UFTNN.js +60 -0
- package/dist/chunk-ZF2UFTNN.js.map +1 -0
- package/dist/{connection-76c5ed01.d.ts → connection-5685d817.d.ts} +6 -4
- package/dist/{connection-975b25c9.d.ts → connection-7582fb92.d.ts} +1 -1
- package/dist/{index-dfad460e.d.ts → index-a6fe0edd.d.ts} +55 -59
- package/dist/logging/index.d.cts +2 -1
- package/dist/logging/index.d.ts +2 -1
- package/dist/router/index.cjs +405 -502
- package/dist/router/index.cjs.map +1 -1
- package/dist/router/index.d.cts +12 -6
- package/dist/router/index.d.ts +12 -6
- package/dist/router/index.js +4 -3
- package/dist/{services-9c496c6e.d.ts → services-be91b485.d.ts} +21 -52
- package/dist/{services-7b716dcf.d.ts → services-eb9326a1.d.ts} +21 -52
- package/dist/transport/impls/uds/client.cjs +197 -155
- package/dist/transport/impls/uds/client.cjs.map +1 -1
- package/dist/transport/impls/uds/client.d.cts +3 -2
- package/dist/transport/impls/uds/client.d.ts +3 -2
- package/dist/transport/impls/uds/client.js +3 -3
- package/dist/transport/impls/uds/server.cjs +280 -266
- package/dist/transport/impls/uds/server.cjs.map +1 -1
- package/dist/transport/impls/uds/server.d.cts +3 -2
- package/dist/transport/impls/uds/server.d.ts +3 -2
- package/dist/transport/impls/uds/server.js +3 -3
- package/dist/transport/impls/ws/client.cjs +251 -214
- package/dist/transport/impls/ws/client.cjs.map +1 -1
- package/dist/transport/impls/ws/client.d.cts +6 -6
- package/dist/transport/impls/ws/client.d.ts +6 -6
- package/dist/transport/impls/ws/client.js +33 -48
- package/dist/transport/impls/ws/client.js.map +1 -1
- package/dist/transport/impls/ws/server.cjs +302 -280
- package/dist/transport/impls/ws/server.cjs.map +1 -1
- package/dist/transport/impls/ws/server.d.cts +5 -4
- package/dist/transport/impls/ws/server.d.ts +5 -4
- package/dist/transport/impls/ws/server.js +3 -3
- package/dist/transport/impls/ws/server.js.map +1 -1
- package/dist/transport/index.cjs +400 -396
- package/dist/transport/index.cjs.map +1 -1
- package/dist/transport/index.d.cts +25 -14
- package/dist/transport/index.d.ts +25 -14
- package/dist/transport/index.js +2 -2
- package/dist/util/testHelpers.cjs +59 -14
- package/dist/util/testHelpers.cjs.map +1 -1
- package/dist/util/testHelpers.d.cts +14 -5
- package/dist/util/testHelpers.d.ts +14 -5
- package/dist/util/testHelpers.js +12 -5
- package/dist/util/testHelpers.js.map +1 -1
- package/dist/wslike-e0b32dd5.d.ts +40 -0
- package/package.json +4 -5
- package/dist/chunk-3Y7AB5EB.js +0 -42
- package/dist/chunk-3Y7AB5EB.js.map +0 -1
- package/dist/chunk-5WFL722S.js.map +0 -1
- package/dist/chunk-JMXO5L2X.js.map +0 -1
- package/dist/chunk-NCXUFDVL.js.map +0 -1
- /package/dist/{chunk-FDLAPYCK.js.map → chunk-DZOATC6M.js.map} +0 -0
package/dist/router/index.d.cts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
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';
|
|
9
|
+
import '@opentelemetry/api';
|
|
8
10
|
|
|
9
11
|
/**
|
|
10
12
|
* Represents a server with a set of services. Use {@link createServer} to create it.
|
|
@@ -31,11 +33,15 @@ interface ProcStream {
|
|
|
31
33
|
* The server tracks the state of each service along with open streams and the extended context object.
|
|
32
34
|
* @param transport - The transport to listen to.
|
|
33
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.
|
|
34
37
|
* @param extendedContext - An optional object containing additional context to be passed to all services.
|
|
35
38
|
* @returns A promise that resolves to a server instance with the registered services.
|
|
36
39
|
*/
|
|
37
|
-
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>;
|
|
38
44
|
|
|
39
|
-
var version = "0.
|
|
45
|
+
var version = "0.23.0";
|
|
40
46
|
|
|
41
47
|
export { PayloadType, version as RIVER_VERSION, Result, RiverError, Server, ServiceContext, createServer };
|
package/dist/router/index.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
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';
|
|
9
|
+
import '@opentelemetry/api';
|
|
8
10
|
|
|
9
11
|
/**
|
|
10
12
|
* Represents a server with a set of services. Use {@link createServer} to create it.
|
|
@@ -31,11 +33,15 @@ interface ProcStream {
|
|
|
31
33
|
* The server tracks the state of each service along with open streams and the extended context object.
|
|
32
34
|
* @param transport - The transport to listen to.
|
|
33
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.
|
|
34
37
|
* @param extendedContext - An optional object containing additional context to be passed to all services.
|
|
35
38
|
* @returns A promise that resolves to a server instance with the registered services.
|
|
36
39
|
*/
|
|
37
|
-
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>;
|
|
38
44
|
|
|
39
|
-
var version = "0.
|
|
45
|
+
var version = "0.23.0";
|
|
40
46
|
|
|
41
47
|
export { PayloadType, version as RIVER_VERSION, Result, RiverError, Server, ServiceContext, createServer };
|
package/dist/router/index.js
CHANGED
|
@@ -7,10 +7,11 @@ import {
|
|
|
7
7
|
UNCAUGHT_ERROR,
|
|
8
8
|
createClient,
|
|
9
9
|
createServer,
|
|
10
|
-
serializeSchema
|
|
10
|
+
serializeSchema
|
|
11
|
+
} from "../chunk-VOJVLWVX.js";
|
|
12
|
+
import {
|
|
11
13
|
version
|
|
12
|
-
} from "../chunk-
|
|
13
|
-
import "../chunk-5WFL722S.js";
|
|
14
|
+
} from "../chunk-PCKHBAVP.js";
|
|
14
15
|
import "../chunk-OTQNCLFH.js";
|
|
15
16
|
export {
|
|
16
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 };
|