@replit/river 0.18.5 → 0.19.2
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-VH3NGOXQ.js → chunk-D5PVGZPQ.js} +5 -3
- package/dist/{chunk-K7CUSLWL.js → chunk-JH275HID.js} +1 -1
- package/dist/{chunk-WER2DWCP.js → chunk-NBE3D667.js} +0 -4
- package/dist/{chunk-6Q3MSICL.js → chunk-SR4DBLJ6.js} +11 -3
- package/dist/{chunk-UABIFWM7.js → chunk-YFPVQTWL.js} +220 -105
- package/dist/{chunk-PUX3U2SZ.js → chunk-ZWPEZS27.js} +1 -1
- package/dist/{connection-893bd769.d.ts → connection-aa0ea000.d.ts} +1 -1
- package/dist/{connection-89918b74.d.ts → connection-cfec12e6.d.ts} +1 -1
- package/dist/index-e2513701.d.ts +342 -0
- package/dist/logging/index.cjs +0 -4
- package/dist/logging/index.d.cts +2 -1
- package/dist/logging/index.d.ts +2 -1
- package/dist/logging/index.js +1 -1
- package/dist/router/index.cjs +11 -2
- package/dist/router/index.d.cts +7 -383
- package/dist/router/index.d.ts +7 -383
- package/dist/router/index.js +3 -3
- package/dist/services-4bba42d8.d.ts +736 -0
- package/dist/services-5fc5712d.d.ts +736 -0
- package/dist/transport/impls/uds/client.cjs +80 -53
- package/dist/transport/impls/uds/client.d.cts +5 -5
- package/dist/transport/impls/uds/client.d.ts +5 -5
- package/dist/transport/impls/uds/client.js +4 -4
- package/dist/transport/impls/uds/server.cjs +151 -62
- package/dist/transport/impls/uds/server.d.cts +4 -4
- package/dist/transport/impls/uds/server.d.ts +4 -4
- package/dist/transport/impls/uds/server.js +4 -4
- package/dist/transport/impls/ws/client.cjs +80 -53
- package/dist/transport/impls/ws/client.d.cts +3 -3
- package/dist/transport/impls/ws/client.d.ts +3 -3
- package/dist/transport/impls/ws/client.js +4 -4
- package/dist/transport/impls/ws/server.cjs +151 -62
- package/dist/transport/impls/ws/server.d.cts +4 -4
- package/dist/transport/impls/ws/server.d.ts +4 -4
- package/dist/transport/impls/ws/server.js +4 -4
- package/dist/transport/index.cjs +188 -71
- package/dist/transport/index.d.cts +295 -3
- package/dist/transport/index.d.ts +295 -3
- package/dist/transport/index.js +3 -4
- package/dist/util/testHelpers.cjs +410 -401
- package/dist/util/testHelpers.d.cts +3 -3
- package/dist/util/testHelpers.d.ts +3 -3
- package/dist/util/testHelpers.js +4 -5
- package/package.json +1 -1
- package/dist/chunk-RPIDSIQG.js +0 -0
- package/dist/index-46ed19d8.d.ts +0 -111
- package/dist/index-d412ca83.d.ts +0 -420
- package/dist/procedures-bfffcb0b.d.ts +0 -324
|
@@ -1,324 +0,0 @@
|
|
|
1
|
-
import { TObject, TUnion, TString, TSchema, TNever, TLiteral, Static } from '@sinclair/typebox';
|
|
2
|
-
import { Pushable } from 'it-pushable';
|
|
3
|
-
import { T as TransportClientId } from './index-46ed19d8.js';
|
|
4
|
-
import { a as Session, C as Connection } from './index-d412ca83.js';
|
|
5
|
-
|
|
6
|
-
type TLiteralString = TLiteral<string>;
|
|
7
|
-
type RiverErrorSchema = TObject<{
|
|
8
|
-
code: TLiteralString | TUnion<Array<TLiteralString>>;
|
|
9
|
-
message: TLiteralString | TString;
|
|
10
|
-
}> | TObject<{
|
|
11
|
-
code: TLiteralString | TUnion<Array<TLiteralString>>;
|
|
12
|
-
message: TLiteralString | TString;
|
|
13
|
-
extras: TSchema;
|
|
14
|
-
}>;
|
|
15
|
-
type RiverError = TUnion<Array<RiverErrorSchema>> | RiverErrorSchema | TNever;
|
|
16
|
-
declare const UNCAUGHT_ERROR = "UNCAUGHT_ERROR";
|
|
17
|
-
declare const RiverUncaughtSchema: TObject<{
|
|
18
|
-
code: TUnion<[TLiteral<"UNCAUGHT_ERROR">, TLiteral<"UNEXPECTED_DISCONNECT">]>;
|
|
19
|
-
message: TString;
|
|
20
|
-
}>;
|
|
21
|
-
type Result<T, E> = {
|
|
22
|
-
ok: true;
|
|
23
|
-
payload: T;
|
|
24
|
-
} | {
|
|
25
|
-
ok: false;
|
|
26
|
-
payload: E;
|
|
27
|
-
};
|
|
28
|
-
declare function Ok<const T, const E>(payload: T): Result<T, E>;
|
|
29
|
-
declare function Err<const T, const E>(error: E): Result<T, E>;
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* The context for services/procedures. This is used only on
|
|
33
|
-
* the server.
|
|
34
|
-
*
|
|
35
|
-
* An important detail is that the state prop is always on
|
|
36
|
-
* this interface and it shouldn't be changed, removed, or
|
|
37
|
-
* extended. This prop is for the state of a service.
|
|
38
|
-
*
|
|
39
|
-
* You should use declaration merging to extend this interface
|
|
40
|
-
* with whatever you need. For example, if you need to access
|
|
41
|
-
* a database, you could do:
|
|
42
|
-
*
|
|
43
|
-
* ```ts
|
|
44
|
-
* declare module '@replit/river' {
|
|
45
|
-
* interface ServiceContext {
|
|
46
|
-
* db: Database;
|
|
47
|
-
* }
|
|
48
|
-
* }
|
|
49
|
-
* ```
|
|
50
|
-
*/
|
|
51
|
-
|
|
52
|
-
interface ServiceContext {
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* The {@link ServiceContext} with state. This is what is passed to procedures.
|
|
56
|
-
*/
|
|
57
|
-
type ServiceContextWithState<State> = ServiceContext & {
|
|
58
|
-
state: State;
|
|
59
|
-
};
|
|
60
|
-
type ServiceContextWithTransportInfo<State> = ServiceContext & {
|
|
61
|
-
state: Omit<State, typeof Symbol.dispose>;
|
|
62
|
-
to: TransportClientId;
|
|
63
|
-
from: TransportClientId;
|
|
64
|
-
streamId: string;
|
|
65
|
-
session: Session<Connection>;
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Brands a type to prevent it from being directly constructed.
|
|
70
|
-
*/
|
|
71
|
-
type Branded<T> = T & {
|
|
72
|
-
readonly __BRAND_DO_NOT_USE: unique symbol;
|
|
73
|
-
};
|
|
74
|
-
/**
|
|
75
|
-
* Unbrands a {@link Branded} type.
|
|
76
|
-
*/
|
|
77
|
-
type Unbranded<T> = T extends Branded<infer U> ? U : never;
|
|
78
|
-
/**
|
|
79
|
-
* The valid {@link Procedure} types. The `stream` and `upload` types can optionally have a
|
|
80
|
-
* different type for the very first initialization message. The suffixless types correspond to
|
|
81
|
-
* gRPC's four combinations of stream / non-stream in each direction.
|
|
82
|
-
*/
|
|
83
|
-
type ValidProcType = 'rpc' | 'upload' | 'subscription' | 'stream';
|
|
84
|
-
/**
|
|
85
|
-
* Represents the payload type for {@link Procedure}s.
|
|
86
|
-
*/
|
|
87
|
-
type PayloadType = TSchema;
|
|
88
|
-
/**
|
|
89
|
-
* Represents results from a {@link Procedure}. Might come from inside a stream or
|
|
90
|
-
* from a single message.
|
|
91
|
-
*/
|
|
92
|
-
type ProcedureResult<O extends PayloadType, E extends RiverError> = Result<Static<O>, Static<E> | Static<typeof RiverUncaughtSchema>>;
|
|
93
|
-
/**
|
|
94
|
-
* Procedure for a single message in both directions (1:1).
|
|
95
|
-
*
|
|
96
|
-
* @template State - The context state object.
|
|
97
|
-
* @template I - The TypeBox schema of the input object.
|
|
98
|
-
* @template O - The TypeBox schema of the output object.
|
|
99
|
-
* @template E - The TypeBox schema of the error object.
|
|
100
|
-
*/
|
|
101
|
-
interface RPCProcedure<State, I extends PayloadType, O extends PayloadType, E extends RiverError> {
|
|
102
|
-
type: 'rpc';
|
|
103
|
-
input: I;
|
|
104
|
-
output: O;
|
|
105
|
-
errors: E;
|
|
106
|
-
description?: string;
|
|
107
|
-
handler(context: ServiceContextWithTransportInfo<State>, input: Static<I>): Promise<ProcedureResult<O, E>>;
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Procedure for a client-stream (potentially preceded by an initialization message),
|
|
111
|
-
* single message from server (n:1).
|
|
112
|
-
*
|
|
113
|
-
* @template State - The context state object.
|
|
114
|
-
* @template I - The TypeBox schema of the input object.
|
|
115
|
-
* @template O - The TypeBox schema of the output object.
|
|
116
|
-
* @template E - The TypeBox schema of the error object.
|
|
117
|
-
* @template Init - The TypeBox schema of the input initialization object, if any.
|
|
118
|
-
*/
|
|
119
|
-
type UploadProcedure<State, I extends PayloadType, O extends PayloadType, E extends RiverError, Init extends PayloadType | null = null> = Init extends PayloadType ? {
|
|
120
|
-
type: 'upload';
|
|
121
|
-
init: Init;
|
|
122
|
-
input: I;
|
|
123
|
-
output: O;
|
|
124
|
-
errors: E;
|
|
125
|
-
description?: string;
|
|
126
|
-
handler(context: ServiceContextWithTransportInfo<State>, init: Static<Init>, input: AsyncIterableIterator<Static<I>>): Promise<ProcedureResult<O, E>>;
|
|
127
|
-
} : {
|
|
128
|
-
type: 'upload';
|
|
129
|
-
input: I;
|
|
130
|
-
output: O;
|
|
131
|
-
errors: E;
|
|
132
|
-
description?: string;
|
|
133
|
-
handler(context: ServiceContextWithTransportInfo<State>, input: AsyncIterableIterator<Static<I>>): Promise<ProcedureResult<O, E>>;
|
|
134
|
-
};
|
|
135
|
-
/**
|
|
136
|
-
* Procedure for a single message from client, stream from server (1:n).
|
|
137
|
-
*
|
|
138
|
-
* @template State - The context state object.
|
|
139
|
-
* @template I - The TypeBox schema of the input object.
|
|
140
|
-
* @template O - The TypeBox schema of the output object.
|
|
141
|
-
* @template E - The TypeBox schema of the error object.
|
|
142
|
-
*/
|
|
143
|
-
interface SubscriptionProcedure<State, I extends PayloadType, O extends PayloadType, E extends RiverError> {
|
|
144
|
-
type: 'subscription';
|
|
145
|
-
input: I;
|
|
146
|
-
output: O;
|
|
147
|
-
errors: E;
|
|
148
|
-
description?: string;
|
|
149
|
-
handler(context: ServiceContextWithTransportInfo<State>, input: Static<I>, output: Pushable<ProcedureResult<O, E>>): Promise<(() => void) | void>;
|
|
150
|
-
}
|
|
151
|
-
/**
|
|
152
|
-
* Procedure for a bidirectional stream (potentially preceded by an initialization message),
|
|
153
|
-
* (n:n).
|
|
154
|
-
*
|
|
155
|
-
* @template State - The context state object.
|
|
156
|
-
* @template I - The TypeBox schema of the input object.
|
|
157
|
-
* @template O - The TypeBox schema of the output object.
|
|
158
|
-
* @template E - The TypeBox schema of the error object.
|
|
159
|
-
* @template Init - The TypeBox schema of the input initialization object, if any.
|
|
160
|
-
*/
|
|
161
|
-
type StreamProcedure<State, I extends PayloadType, O extends PayloadType, E extends RiverError, Init extends PayloadType | null = null> = Init extends PayloadType ? {
|
|
162
|
-
type: 'stream';
|
|
163
|
-
init: Init;
|
|
164
|
-
input: I;
|
|
165
|
-
output: O;
|
|
166
|
-
errors: E;
|
|
167
|
-
description?: string;
|
|
168
|
-
handler(context: ServiceContextWithTransportInfo<State>, init: Static<Init>, input: AsyncIterableIterator<Static<I>>, output: Pushable<ProcedureResult<O, E>>): Promise<(() => void) | void>;
|
|
169
|
-
} : {
|
|
170
|
-
type: 'stream';
|
|
171
|
-
input: I;
|
|
172
|
-
output: O;
|
|
173
|
-
errors: E;
|
|
174
|
-
description?: string;
|
|
175
|
-
handler(context: ServiceContextWithTransportInfo<State>, input: AsyncIterableIterator<Static<I>>, output: Pushable<ProcedureResult<O, E>>): Promise<(() => void) | void>;
|
|
176
|
-
};
|
|
177
|
-
/**
|
|
178
|
-
* Represents any {@link Procedure} type.
|
|
179
|
-
*
|
|
180
|
-
* @template State - The context state object. You can provide this to constrain
|
|
181
|
-
* the type of procedures.
|
|
182
|
-
*/
|
|
183
|
-
type AnyProcedure<State = object> = Procedure<State, ValidProcType, PayloadType, PayloadType, RiverError, PayloadType | null>;
|
|
184
|
-
/**
|
|
185
|
-
* Represents a map of {@link Procedure}s.
|
|
186
|
-
*
|
|
187
|
-
* @template State - The context state object. You can provide this to constrain
|
|
188
|
-
* the type of procedures.
|
|
189
|
-
*/
|
|
190
|
-
type ProcedureMap<State = object> = Record<string, AnyProcedure<State>>;
|
|
191
|
-
/**
|
|
192
|
-
* Creates an {@link RPCProcedure}.
|
|
193
|
-
*/
|
|
194
|
-
declare function rpc<State, I extends PayloadType, O extends PayloadType>(def: {
|
|
195
|
-
input: I;
|
|
196
|
-
output: O;
|
|
197
|
-
errors?: never;
|
|
198
|
-
description?: string;
|
|
199
|
-
handler: RPCProcedure<State, I, O, TNever>['handler'];
|
|
200
|
-
}): Branded<RPCProcedure<State, I, O, TNever>>;
|
|
201
|
-
declare function rpc<State, I extends PayloadType, O extends PayloadType, E extends RiverError>(def: {
|
|
202
|
-
input: I;
|
|
203
|
-
output: O;
|
|
204
|
-
errors: E;
|
|
205
|
-
description?: string;
|
|
206
|
-
handler: RPCProcedure<State, I, O, E>['handler'];
|
|
207
|
-
}): Branded<RPCProcedure<State, I, O, E>>;
|
|
208
|
-
/**
|
|
209
|
-
* Creates an {@link UploadProcedure}, optionally with an initialization message.
|
|
210
|
-
*/
|
|
211
|
-
declare function upload<State, I extends PayloadType, O extends PayloadType, Init extends PayloadType>(def: {
|
|
212
|
-
init: Init;
|
|
213
|
-
input: I;
|
|
214
|
-
output: O;
|
|
215
|
-
errors?: never;
|
|
216
|
-
description?: string;
|
|
217
|
-
handler: UploadProcedure<State, I, O, TNever, Init>['handler'];
|
|
218
|
-
}): Branded<UploadProcedure<State, I, O, TNever, Init>>;
|
|
219
|
-
declare function upload<State, I extends PayloadType, O extends PayloadType, E extends RiverError, Init extends PayloadType>(def: {
|
|
220
|
-
init: Init;
|
|
221
|
-
input: I;
|
|
222
|
-
output: O;
|
|
223
|
-
errors: E;
|
|
224
|
-
description?: string;
|
|
225
|
-
handler: UploadProcedure<State, I, O, E, Init>['handler'];
|
|
226
|
-
}): Branded<UploadProcedure<State, I, O, E, Init>>;
|
|
227
|
-
declare function upload<State, I extends PayloadType, O extends PayloadType>(def: {
|
|
228
|
-
init?: never;
|
|
229
|
-
input: I;
|
|
230
|
-
output: O;
|
|
231
|
-
errors?: never;
|
|
232
|
-
description?: string;
|
|
233
|
-
handler: UploadProcedure<State, I, O, TNever>['handler'];
|
|
234
|
-
}): Branded<UploadProcedure<State, I, O, TNever>>;
|
|
235
|
-
declare function upload<State, I extends PayloadType, O extends PayloadType, E extends RiverError>(def: {
|
|
236
|
-
init?: never;
|
|
237
|
-
input: I;
|
|
238
|
-
output: O;
|
|
239
|
-
errors: E;
|
|
240
|
-
description?: string;
|
|
241
|
-
handler: UploadProcedure<State, I, O, E>['handler'];
|
|
242
|
-
}): Branded<UploadProcedure<State, I, O, E>>;
|
|
243
|
-
/**
|
|
244
|
-
* Creates a {@link SubscriptionProcedure}.
|
|
245
|
-
*/
|
|
246
|
-
declare function subscription<State, I extends PayloadType, O extends PayloadType>(def: {
|
|
247
|
-
input: I;
|
|
248
|
-
output: O;
|
|
249
|
-
errors?: never;
|
|
250
|
-
description?: string;
|
|
251
|
-
handler: SubscriptionProcedure<State, I, O, TNever>['handler'];
|
|
252
|
-
}): Branded<SubscriptionProcedure<State, I, O, TNever>>;
|
|
253
|
-
declare function subscription<State, I extends PayloadType, O extends PayloadType, E extends RiverError>(def: {
|
|
254
|
-
input: I;
|
|
255
|
-
output: O;
|
|
256
|
-
errors: E;
|
|
257
|
-
description?: string;
|
|
258
|
-
handler: SubscriptionProcedure<State, I, O, E>['handler'];
|
|
259
|
-
}): Branded<SubscriptionProcedure<State, I, O, E>>;
|
|
260
|
-
/**
|
|
261
|
-
* Creates a {@link StreamProcedure}, optionally with an initialization message.
|
|
262
|
-
*/
|
|
263
|
-
declare function stream<State, I extends PayloadType, O extends PayloadType, Init extends PayloadType>(def: {
|
|
264
|
-
init: Init;
|
|
265
|
-
input: I;
|
|
266
|
-
output: O;
|
|
267
|
-
errors?: never;
|
|
268
|
-
description?: string;
|
|
269
|
-
handler: StreamProcedure<State, I, O, TNever, Init>['handler'];
|
|
270
|
-
}): Branded<StreamProcedure<State, I, O, TNever, Init>>;
|
|
271
|
-
declare function stream<State, I extends PayloadType, O extends PayloadType, E extends RiverError, Init extends PayloadType>(def: {
|
|
272
|
-
init: Init;
|
|
273
|
-
input: I;
|
|
274
|
-
output: O;
|
|
275
|
-
errors: E;
|
|
276
|
-
description?: string;
|
|
277
|
-
handler: StreamProcedure<State, I, O, E, Init>['handler'];
|
|
278
|
-
}): Branded<StreamProcedure<State, I, O, E, Init>>;
|
|
279
|
-
declare function stream<State, I extends PayloadType, O extends PayloadType>(def: {
|
|
280
|
-
init?: never;
|
|
281
|
-
input: I;
|
|
282
|
-
output: O;
|
|
283
|
-
errors?: never;
|
|
284
|
-
description?: string;
|
|
285
|
-
handler: StreamProcedure<State, I, O, TNever>['handler'];
|
|
286
|
-
}): Branded<StreamProcedure<State, I, O, TNever>>;
|
|
287
|
-
declare function stream<State, I extends PayloadType, O extends PayloadType, E extends RiverError>(def: {
|
|
288
|
-
init?: never;
|
|
289
|
-
input: I;
|
|
290
|
-
output: O;
|
|
291
|
-
errors: E;
|
|
292
|
-
description?: string;
|
|
293
|
-
handler: StreamProcedure<State, I, O, E>['handler'];
|
|
294
|
-
}): Branded<StreamProcedure<State, I, O, E>>;
|
|
295
|
-
/**
|
|
296
|
-
* Defines a Procedure type that can be a:
|
|
297
|
-
* - {@link RPCProcedure} for a single message in both directions (1:1)
|
|
298
|
-
* - {@link UploadProcedure} for a client-stream (potentially preceded by an
|
|
299
|
-
* initialization message)
|
|
300
|
-
* - {@link SubscriptionProcedure} for a single message from client, stream from server (1:n)
|
|
301
|
-
* - {@link StreamProcedure} for a bidirectional stream (potentially preceded by an
|
|
302
|
-
* initialization message)
|
|
303
|
-
*
|
|
304
|
-
* @template State - The TypeBox schema of the state object.
|
|
305
|
-
* @template Ty - The type of the procedure.
|
|
306
|
-
* @template I - The TypeBox schema of the input object.
|
|
307
|
-
* @template O - The TypeBox schema of the output object.
|
|
308
|
-
* @template Init - The TypeBox schema of the input initialization object, if any.
|
|
309
|
-
*/
|
|
310
|
-
type Procedure<State, Ty extends ValidProcType, I extends PayloadType, O extends PayloadType, E extends RiverError, Init extends PayloadType | null = null> = {
|
|
311
|
-
type: Ty;
|
|
312
|
-
} & (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);
|
|
313
|
-
/**
|
|
314
|
-
* Holds the {@link Procedure} creation functions. Use these to create
|
|
315
|
-
* procedures for services. You aren't allowed to create procedures directly.
|
|
316
|
-
*/
|
|
317
|
-
declare const Procedure: {
|
|
318
|
-
rpc: typeof rpc;
|
|
319
|
-
upload: typeof upload;
|
|
320
|
-
subscription: typeof subscription;
|
|
321
|
-
stream: typeof stream;
|
|
322
|
-
};
|
|
323
|
-
|
|
324
|
-
export { AnyProcedure as A, Branded as B, Err as E, Ok as O, PayloadType as P, RiverError as R, ServiceContext as S, Unbranded as U, ValidProcType as V, Procedure as a, Result as b, RiverUncaughtSchema as c, ProcedureResult as d, ProcedureMap as e, RPCProcedure as f, UploadProcedure as g, SubscriptionProcedure as h, StreamProcedure as i, ServiceContextWithState as j, ServiceContextWithTransportInfo as k, UNCAUGHT_ERROR as l, RiverErrorSchema as m };
|