@replit/river 0.10.0 → 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.
- package/dist/{router/builder.d.ts → builder-3c4485f0.d.ts} +76 -21
- package/dist/chunk-7WJ6YLE5.js +683 -0
- package/dist/chunk-AJQU4AZG.js +284 -0
- package/dist/chunk-ORAG7IAU.js +0 -0
- package/dist/chunk-PC65ZFWJ.js +29 -0
- package/dist/chunk-R6H2BIMC.js +49 -0
- package/dist/chunk-RGMHF6PF.js +65 -0
- package/dist/chunk-SLUSVGQH.js +30 -0
- package/dist/chunk-UU2Z7LDR.js +113 -0
- package/dist/chunk-WVT5QXMZ.js +20 -0
- package/dist/chunk-ZE4MX7DF.js +75 -0
- package/dist/codec/index.cjs +94 -0
- package/dist/codec/index.d.cts +15 -0
- package/dist/codec/index.d.ts +15 -4
- package/dist/codec/index.js +10 -2
- package/dist/connection-8e19874c.d.ts +11 -0
- package/dist/connection-f7688cc1.d.ts +11 -0
- package/dist/logging/index.cjs +56 -0
- package/dist/logging/index.d.cts +28 -0
- package/dist/logging/index.d.ts +6 -6
- package/dist/logging/index.js +9 -40
- package/dist/router/index.cjs +770 -0
- package/dist/router/index.d.cts +114 -0
- package/dist/router/index.d.ts +114 -12
- package/dist/router/index.js +24 -5
- package/dist/transport/impls/ws/client.cjs +505 -0
- package/dist/transport/impls/ws/client.d.cts +42 -0
- package/dist/transport/impls/ws/client.d.ts +8 -8
- package/dist/transport/impls/ws/client.js +10 -100
- package/dist/transport/impls/ws/server.cjs +457 -0
- package/dist/transport/impls/ws/server.d.cts +21 -0
- package/dist/transport/impls/ws/server.d.ts +11 -10
- package/dist/transport/impls/ws/server.js +11 -52
- package/dist/transport/index.cjs +362 -0
- package/dist/transport/{transport.d.ts → index.d.cts} +119 -7
- package/dist/transport/index.d.ts +273 -4
- package/dist/transport/index.js +20 -2
- package/dist/{codec/types.d.ts → types-3e5768ec.d.ts} +3 -2
- package/dist/util/testHelpers.cjs +731 -0
- package/dist/util/testHelpers.d.cts +79 -0
- package/dist/util/testHelpers.d.ts +22 -19
- package/dist/util/testHelpers.js +135 -163
- package/package.json +41 -13
- package/dist/__tests__/bandwidth.bench.d.ts +0 -2
- package/dist/__tests__/bandwidth.bench.d.ts.map +0 -1
- package/dist/__tests__/bandwidth.bench.js +0 -90
- package/dist/__tests__/cleanup.test.d.ts +0 -2
- package/dist/__tests__/cleanup.test.d.ts.map +0 -1
- package/dist/__tests__/cleanup.test.js +0 -165
- package/dist/__tests__/disconnects.test.d.ts +0 -2
- package/dist/__tests__/disconnects.test.d.ts.map +0 -1
- package/dist/__tests__/disconnects.test.js +0 -163
- package/dist/__tests__/e2e.test.d.ts +0 -2
- package/dist/__tests__/e2e.test.d.ts.map +0 -1
- package/dist/__tests__/e2e.test.js +0 -317
- package/dist/__tests__/fixtures/cleanup.d.ts +0 -12
- package/dist/__tests__/fixtures/cleanup.d.ts.map +0 -1
- package/dist/__tests__/fixtures/cleanup.js +0 -36
- package/dist/__tests__/fixtures/largePayload.json +0 -33
- package/dist/__tests__/fixtures/observable.d.ts +0 -26
- package/dist/__tests__/fixtures/observable.d.ts.map +0 -1
- package/dist/__tests__/fixtures/observable.js +0 -38
- package/dist/__tests__/fixtures/observable.test.d.ts +0 -2
- package/dist/__tests__/fixtures/observable.test.d.ts.map +0 -1
- package/dist/__tests__/fixtures/observable.test.js +0 -39
- package/dist/__tests__/fixtures/services.d.ts +0 -288
- package/dist/__tests__/fixtures/services.d.ts.map +0 -1
- package/dist/__tests__/fixtures/services.js +0 -207
- package/dist/__tests__/handler.test.d.ts +0 -2
- package/dist/__tests__/handler.test.d.ts.map +0 -1
- package/dist/__tests__/handler.test.js +0 -120
- package/dist/__tests__/serialize.test.d.ts +0 -2
- package/dist/__tests__/serialize.test.d.ts.map +0 -1
- package/dist/__tests__/serialize.test.js +0 -208
- package/dist/__tests__/typescript-stress.test.d.ts +0 -1583
- package/dist/__tests__/typescript-stress.test.d.ts.map +0 -1
- package/dist/__tests__/typescript-stress.test.js +0 -123
- package/dist/codec/binary.d.ts +0 -7
- package/dist/codec/binary.d.ts.map +0 -1
- package/dist/codec/binary.js +0 -20
- package/dist/codec/codec.test.d.ts +0 -5
- package/dist/codec/codec.test.d.ts.map +0 -1
- package/dist/codec/codec.test.js +0 -41
- package/dist/codec/index.d.ts.map +0 -1
- package/dist/codec/json.d.ts +0 -7
- package/dist/codec/json.d.ts.map +0 -1
- package/dist/codec/json.js +0 -51
- package/dist/codec/types.d.ts.map +0 -1
- package/dist/codec/types.js +0 -1
- package/dist/logging/index.d.ts.map +0 -1
- package/dist/router/builder.d.ts.map +0 -1
- package/dist/router/builder.js +0 -91
- package/dist/router/client.d.ts +0 -72
- package/dist/router/client.d.ts.map +0 -1
- package/dist/router/client.js +0 -257
- package/dist/router/context.d.ts +0 -30
- package/dist/router/context.d.ts.map +0 -1
- package/dist/router/context.js +0 -1
- package/dist/router/defs.d.ts +0 -16
- package/dist/router/defs.d.ts.map +0 -1
- package/dist/router/defs.js +0 -11
- package/dist/router/index.d.ts.map +0 -1
- package/dist/router/result.d.ts +0 -26
- package/dist/router/result.d.ts.map +0 -1
- package/dist/router/result.js +0 -22
- package/dist/router/server.d.ts +0 -39
- package/dist/router/server.d.ts.map +0 -1
- package/dist/router/server.js +0 -260
- package/dist/transport/events.d.ts +0 -19
- package/dist/transport/events.d.ts.map +0 -1
- package/dist/transport/events.js +0 -26
- package/dist/transport/impls/stdio/stdio.d.ts +0 -33
- package/dist/transport/impls/stdio/stdio.d.ts.map +0 -1
- package/dist/transport/impls/stdio/stdio.js +0 -75
- package/dist/transport/impls/stdio/stdio.test.d.ts +0 -2
- package/dist/transport/impls/stdio/stdio.test.d.ts.map +0 -1
- package/dist/transport/impls/stdio/stdio.test.js +0 -24
- package/dist/transport/impls/ws/client.d.ts.map +0 -1
- package/dist/transport/impls/ws/connection.d.ts +0 -11
- package/dist/transport/impls/ws/connection.d.ts.map +0 -1
- package/dist/transport/impls/ws/connection.js +0 -23
- package/dist/transport/impls/ws/server.d.ts.map +0 -1
- package/dist/transport/impls/ws/ws.test.d.ts +0 -2
- package/dist/transport/impls/ws/ws.test.d.ts.map +0 -1
- package/dist/transport/impls/ws/ws.test.js +0 -185
- package/dist/transport/index.d.ts.map +0 -1
- package/dist/transport/message.d.ts +0 -142
- package/dist/transport/message.d.ts.map +0 -1
- package/dist/transport/message.js +0 -113
- package/dist/transport/message.test.d.ts +0 -2
- package/dist/transport/message.test.d.ts.map +0 -1
- package/dist/transport/message.test.js +0 -52
- package/dist/transport/transport.d.ts.map +0 -1
- package/dist/transport/transport.js +0 -281
- package/dist/util/testHelpers.d.ts.map +0 -1
|
@@ -1,19 +1,73 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
|
|
1
|
+
import * as _sinclair_typebox from '@sinclair/typebox';
|
|
2
|
+
import { TObject, TLiteralString, TString, TSchema, TUnion, TNever, Static } from '@sinclair/typebox';
|
|
3
|
+
import { Pushable } from 'it-pushable';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The context for services/procedures. This is used only on
|
|
7
|
+
* the server.
|
|
8
|
+
*
|
|
9
|
+
* An important detail is that the state prop is always on
|
|
10
|
+
* this interface and it shouldn't be changed, removed, or
|
|
11
|
+
* extended. This prop is for the state of a service.
|
|
12
|
+
*
|
|
13
|
+
* You should use declaration merging to extend this interface
|
|
14
|
+
* with whatever you need. For example, if you need to access
|
|
15
|
+
* a database, you could do:
|
|
16
|
+
*
|
|
17
|
+
* ```ts
|
|
18
|
+
* declare module '@replit/river' {
|
|
19
|
+
* interface ServiceContext {
|
|
20
|
+
* db: Database;
|
|
21
|
+
* }
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
interface ServiceContext {
|
|
26
|
+
state: object | unknown;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The {@link ServiceContext} with state. This is what is passed to procedures.
|
|
30
|
+
*/
|
|
31
|
+
type ServiceContextWithState<State extends object | unknown> = ServiceContext & {
|
|
32
|
+
state: State;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
type RiverErrorSchema = TObject<{
|
|
36
|
+
code: TLiteralString;
|
|
37
|
+
message: TLiteralString | TString;
|
|
38
|
+
}> | TObject<{
|
|
39
|
+
code: TLiteralString;
|
|
40
|
+
message: TLiteralString | TString;
|
|
41
|
+
extras: TSchema;
|
|
42
|
+
}>;
|
|
43
|
+
type RiverError = TUnion<RiverErrorSchema[]> | RiverErrorSchema | TNever;
|
|
44
|
+
declare const UNCAUGHT_ERROR = "UNCAUGHT_ERROR";
|
|
45
|
+
declare const RiverUncaughtSchema: TObject<{
|
|
46
|
+
code: TUnion<[_sinclair_typebox.TLiteral<"UNCAUGHT_ERROR">, _sinclair_typebox.TLiteral<"UNEXPECTED_DISCONNECT">]>;
|
|
47
|
+
message: TString;
|
|
48
|
+
}>;
|
|
49
|
+
type Result<T, E> = {
|
|
50
|
+
ok: true;
|
|
51
|
+
payload: T;
|
|
52
|
+
} | {
|
|
53
|
+
ok: false;
|
|
54
|
+
payload: E;
|
|
55
|
+
};
|
|
56
|
+
declare function Ok<T, E>(payload: T): Result<T, E>;
|
|
57
|
+
declare function Err<T, E>(error: E): Result<T, E>;
|
|
58
|
+
|
|
5
59
|
/**
|
|
6
60
|
* The valid {@link Procedure} types. The `stream` and `upload` types can optionally have a
|
|
7
61
|
* different type for the very first initialization message. The suffixless types correspond to
|
|
8
62
|
* gRPC's four combinations of stream / non-stream in each direction.
|
|
9
63
|
*/
|
|
10
|
-
|
|
64
|
+
type ValidProcType = 'rpc' | 'upload' | 'subscription' | 'stream';
|
|
11
65
|
/**
|
|
12
66
|
* A generic procedure listing where the keys are the names of the procedures
|
|
13
67
|
* and the values are the {@link Procedure} definitions. This is not meant to
|
|
14
68
|
* be constructed directly, use the {@link ServiceBuilder} class instead.
|
|
15
69
|
*/
|
|
16
|
-
|
|
70
|
+
type ProcListing = Record<string, AnyProcedure>;
|
|
17
71
|
/**
|
|
18
72
|
* Represents a service with a name, state, and procedures.
|
|
19
73
|
* This is not meant to be constructed directly, use the {@link ServiceBuilder} class instead.
|
|
@@ -21,30 +75,30 @@ export type ProcListing = Record<string, AnyProcedure>;
|
|
|
21
75
|
* @template State The type of the service state.
|
|
22
76
|
* @template Procs The type of the service procedures.
|
|
23
77
|
*/
|
|
24
|
-
|
|
78
|
+
interface Service<Name extends string, State extends object, Procs extends ProcListing> {
|
|
25
79
|
name: Name;
|
|
26
80
|
state: State;
|
|
27
81
|
procedures: Procs;
|
|
28
82
|
}
|
|
29
|
-
|
|
83
|
+
type AnyService = Service<string, object, any>;
|
|
30
84
|
/**
|
|
31
85
|
* Serializes a service object into its corresponding JSON Schema Draft 7 type.
|
|
32
86
|
* @param {AnyService} s - The service object to serialize.
|
|
33
87
|
* @returns A plain object representing the serialized service.
|
|
34
88
|
*/
|
|
35
|
-
|
|
89
|
+
declare function serializeService(s: AnyService): object;
|
|
36
90
|
/**
|
|
37
91
|
* Helper to get the type definition for a specific handler of a procedure in a service.
|
|
38
92
|
* @template S - The service.
|
|
39
93
|
* @template ProcName - The name of the procedure.
|
|
40
94
|
*/
|
|
41
|
-
|
|
95
|
+
type ProcHandler<S extends AnyService, ProcName extends keyof S['procedures']> = S['procedures'][ProcName]['handler'];
|
|
42
96
|
/**
|
|
43
97
|
* Helper to get whether the type definition for the procedure contains an init type.
|
|
44
98
|
* @template S - The service.
|
|
45
99
|
* @template ProcName - The name of the procedure.
|
|
46
100
|
*/
|
|
47
|
-
|
|
101
|
+
type ProcHasInit<S extends AnyService, ProcName extends keyof S['procedures']> = S['procedures'][ProcName] extends {
|
|
48
102
|
init: any;
|
|
49
103
|
} ? true : false;
|
|
50
104
|
/**
|
|
@@ -52,32 +106,32 @@ export type ProcHasInit<S extends AnyService, ProcName extends keyof S['procedur
|
|
|
52
106
|
* @template S - The service.
|
|
53
107
|
* @template ProcName - The name of the procedure.
|
|
54
108
|
*/
|
|
55
|
-
|
|
109
|
+
type ProcInit<S extends AnyService, ProcName extends keyof S['procedures']> = S['procedures'][ProcName]['init'];
|
|
56
110
|
/**
|
|
57
111
|
* Helper to get the type definition for the procedure input of a service.
|
|
58
112
|
* @template S - The service.
|
|
59
113
|
* @template ProcName - The name of the procedure.
|
|
60
114
|
*/
|
|
61
|
-
|
|
115
|
+
type ProcInput<S extends AnyService, ProcName extends keyof S['procedures']> = S['procedures'][ProcName]['input'];
|
|
62
116
|
/**
|
|
63
117
|
* Helper to get the type definition for the procedure output of a service.
|
|
64
118
|
* @template S - The service.
|
|
65
119
|
* @template ProcName - The name of the procedure.
|
|
66
120
|
*/
|
|
67
|
-
|
|
121
|
+
type ProcOutput<S extends AnyService, ProcName extends keyof S['procedures']> = S['procedures'][ProcName]['output'];
|
|
68
122
|
/**
|
|
69
123
|
* Helper to get the type definition for the procedure errors of a service.
|
|
70
124
|
* @template S - The service.
|
|
71
125
|
* @template ProcName - The name of the procedure.
|
|
72
126
|
*/
|
|
73
|
-
|
|
127
|
+
type ProcErrors<S extends AnyService, ProcName extends keyof S['procedures']> = TUnion<[S['procedures'][ProcName]['errors'], typeof RiverUncaughtSchema]>;
|
|
74
128
|
/**
|
|
75
129
|
* Helper to get the type of procedure in a service.
|
|
76
130
|
* @template S - The service.
|
|
77
131
|
* @template ProcName - The name of the procedure.
|
|
78
132
|
*/
|
|
79
|
-
|
|
80
|
-
|
|
133
|
+
type ProcType<S extends AnyService, ProcName extends keyof S['procedures']> = S['procedures'][ProcName]['type'];
|
|
134
|
+
type PayloadType = TObject | TUnion<TObject[]>;
|
|
81
135
|
/**
|
|
82
136
|
* Defines a Procedure type that can be either an RPC or a stream procedure.
|
|
83
137
|
* @template State - The TypeBox schema of the state object.
|
|
@@ -86,7 +140,7 @@ export type PayloadType = TObject | TUnion<TObject[]>;
|
|
|
86
140
|
* @template O - The TypeBox schema of the output object.
|
|
87
141
|
* @template Init - The TypeBox schema of the input initialization object.
|
|
88
142
|
*/
|
|
89
|
-
|
|
143
|
+
type Procedure<State extends object | unknown, Ty extends ValidProcType, I extends PayloadType, O extends PayloadType, E extends RiverError, Init extends PayloadType | null = null> = Ty extends 'rpc' ? Init extends null ? {
|
|
90
144
|
input: I;
|
|
91
145
|
output: O;
|
|
92
146
|
errors: E;
|
|
@@ -125,13 +179,13 @@ export type Procedure<State extends object | unknown, Ty extends ValidProcType,
|
|
|
125
179
|
handler: (context: ServiceContextWithState<State>, input: AsyncIterableIterator<Static<I>>, output: Pushable<Result<Static<O>, Static<E>>>) => Promise<void>;
|
|
126
180
|
type: Ty;
|
|
127
181
|
} : never;
|
|
128
|
-
|
|
182
|
+
type AnyProcedure = Procedure<object, ValidProcType, PayloadType, PayloadType, RiverError, PayloadType | null>;
|
|
129
183
|
/**
|
|
130
184
|
* A builder class for creating River Services.
|
|
131
185
|
* You must call the finalize method to get the finalized schema for use in a service router.
|
|
132
186
|
* @template T The type of the service.
|
|
133
187
|
*/
|
|
134
|
-
|
|
188
|
+
declare class ServiceBuilder<T extends Service<string, object, ProcListing>> {
|
|
135
189
|
private readonly schema;
|
|
136
190
|
private constructor();
|
|
137
191
|
/**
|
|
@@ -174,4 +228,5 @@ export declare class ServiceBuilder<T extends Service<string, object, ProcListin
|
|
|
174
228
|
procedures: {};
|
|
175
229
|
}>;
|
|
176
230
|
}
|
|
177
|
-
|
|
231
|
+
|
|
232
|
+
export { AnyService as A, Err as E, Ok as O, PayloadType as P, RiverError as R, ServiceContext as S, UNCAUGHT_ERROR as U, ValidProcType as V, Procedure as a, Result as b, RiverUncaughtSchema as c, AnyProcedure as d, ProcType as e, ProcInput as f, ProcOutput as g, ProcErrors as h, ProcHasInit as i, ProcInit as j, ServiceBuilder as k, ProcListing as l, Service as m, ProcHandler as n, ServiceContextWithState as o, RiverErrorSchema as p, serializeService as s };
|