@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.
Files changed (48) hide show
  1. package/dist/{chunk-VH3NGOXQ.js → chunk-D5PVGZPQ.js} +5 -3
  2. package/dist/{chunk-K7CUSLWL.js → chunk-JH275HID.js} +1 -1
  3. package/dist/{chunk-WER2DWCP.js → chunk-NBE3D667.js} +0 -4
  4. package/dist/{chunk-6Q3MSICL.js → chunk-SR4DBLJ6.js} +11 -3
  5. package/dist/{chunk-UABIFWM7.js → chunk-YFPVQTWL.js} +220 -105
  6. package/dist/{chunk-PUX3U2SZ.js → chunk-ZWPEZS27.js} +1 -1
  7. package/dist/{connection-893bd769.d.ts → connection-aa0ea000.d.ts} +1 -1
  8. package/dist/{connection-89918b74.d.ts → connection-cfec12e6.d.ts} +1 -1
  9. package/dist/index-e2513701.d.ts +342 -0
  10. package/dist/logging/index.cjs +0 -4
  11. package/dist/logging/index.d.cts +2 -1
  12. package/dist/logging/index.d.ts +2 -1
  13. package/dist/logging/index.js +1 -1
  14. package/dist/router/index.cjs +11 -2
  15. package/dist/router/index.d.cts +7 -383
  16. package/dist/router/index.d.ts +7 -383
  17. package/dist/router/index.js +3 -3
  18. package/dist/services-4bba42d8.d.ts +736 -0
  19. package/dist/services-5fc5712d.d.ts +736 -0
  20. package/dist/transport/impls/uds/client.cjs +80 -53
  21. package/dist/transport/impls/uds/client.d.cts +5 -5
  22. package/dist/transport/impls/uds/client.d.ts +5 -5
  23. package/dist/transport/impls/uds/client.js +4 -4
  24. package/dist/transport/impls/uds/server.cjs +151 -62
  25. package/dist/transport/impls/uds/server.d.cts +4 -4
  26. package/dist/transport/impls/uds/server.d.ts +4 -4
  27. package/dist/transport/impls/uds/server.js +4 -4
  28. package/dist/transport/impls/ws/client.cjs +80 -53
  29. package/dist/transport/impls/ws/client.d.cts +3 -3
  30. package/dist/transport/impls/ws/client.d.ts +3 -3
  31. package/dist/transport/impls/ws/client.js +4 -4
  32. package/dist/transport/impls/ws/server.cjs +151 -62
  33. package/dist/transport/impls/ws/server.d.cts +4 -4
  34. package/dist/transport/impls/ws/server.d.ts +4 -4
  35. package/dist/transport/impls/ws/server.js +4 -4
  36. package/dist/transport/index.cjs +188 -71
  37. package/dist/transport/index.d.cts +295 -3
  38. package/dist/transport/index.d.ts +295 -3
  39. package/dist/transport/index.js +3 -4
  40. package/dist/util/testHelpers.cjs +410 -401
  41. package/dist/util/testHelpers.d.cts +3 -3
  42. package/dist/util/testHelpers.d.ts +3 -3
  43. package/dist/util/testHelpers.js +4 -5
  44. package/package.json +1 -1
  45. package/dist/chunk-RPIDSIQG.js +0 -0
  46. package/dist/index-46ed19d8.d.ts +0 -111
  47. package/dist/index-d412ca83.d.ts +0 -420
  48. package/dist/procedures-bfffcb0b.d.ts +0 -324
@@ -1,387 +1,11 @@
1
- import { TUnion, Static } from '@sinclair/typebox';
2
- import { e as ProcedureMap, P as PayloadType, c as RiverUncaughtSchema, U as Unbranded, B as Branded, A as AnyProcedure, R as RiverError, b as Result, S as ServiceContext } from '../procedures-bfffcb0b.js';
3
- export { E as Err, O as Ok, a as Procedure, d as ProcedureResult, f as RPCProcedure, m as RiverErrorSchema, j as ServiceContextWithState, k as ServiceContextWithTransportInfo, i as StreamProcedure, h as SubscriptionProcedure, l as UNCAUGHT_ERROR, g as UploadProcedure, V as ValidProcType } from '../procedures-bfffcb0b.js';
4
- import { b as ClientTransport, C as Connection, c as ServerTransport } from '../index-d412ca83.js';
1
+ import { A as AnyServiceSchemaMap, I as InstantiatedServiceSchemaMap, P as PayloadType, b as Result, R as RiverError, S as ServiceContext } from '../services-5fc5712d.js';
2
+ export { C as Client, E as Err, O as Ok, B as Output, k as ProcErrors, g as ProcHandler, h as ProcInit, i as ProcInput, j as ProcOutput, l as ProcType, a as Procedure, o as ProcedureMap, d as ProcedureResult, p as RPCProcedure, z as ResultUnwrapErr, y as ResultUnwrapOk, x as RiverErrorSchema, c as RiverUncaughtSchema, n as SerializedServerSchema, e as Service, f as ServiceConfiguration, u as ServiceContextWithState, v as ServiceContextWithTransportInfo, m as ServiceSchema, r as StreamProcedure, q as SubscriptionProcedure, w as UNCAUGHT_ERROR, U as UploadProcedure, V as ValidProcType, t as createClient, s as serializeSchema } from '../services-5fc5712d.js';
3
+ import { Static } from '@sinclair/typebox';
4
+ import { ServerTransport } from '../transport/index.js';
5
5
  import { Pushable } from 'it-pushable';
6
- import { T as TransportClientId } from '../index-46ed19d8.js';
6
+ import { C as Connection } from '../index-e2513701.js';
7
7
  import '../types-3e5768ec.js';
8
8
 
9
- /**
10
- * An instantiated service, probably from a {@link ServiceSchema}.
11
- *
12
- * You shouldn't construct these directly, use {@link ServiceSchema} instead.
13
- */
14
- interface Service<State extends object, Procs extends ProcedureMap<State>> {
15
- readonly state: State;
16
- readonly procedures: Procs;
17
- }
18
- /**
19
- * Represents any {@link Service} object.
20
- */
21
- type AnyService = Service<object, ProcedureMap>;
22
- /**
23
- * Represents any {@link ServiceSchema} object.
24
- */
25
- type AnyServiceSchema = ServiceSchema<object, ProcedureMap>;
26
- /**
27
- * A dictionary of {@link ServiceSchema}s, where the key is the service name.
28
- */
29
- type AnyServiceSchemaMap = Record<string, AnyServiceSchema>;
30
- /**
31
- * Takes a {@link AnyServiceSchemaMap} and returns a dictionary of instantiated
32
- * services.
33
- */
34
- type InstantiatedServiceSchemaMap<T extends AnyServiceSchemaMap> = {
35
- [K in keyof T]: T[K] extends ServiceSchema<infer S, infer P> ? Service<S, P> : never;
36
- };
37
- /**
38
- * Helper to get the type definition for a specific handler of a procedure in a service.
39
- * @template S - The service.
40
- * @template ProcName - The name of the procedure.
41
- */
42
- type ProcHandler<S extends AnyService, ProcName extends keyof S['procedures']> = S['procedures'][ProcName]['handler'];
43
- /**
44
- * Helper to get whether the type definition for the procedure contains an init type.
45
- * @template S - The service.
46
- * @template ProcName - The name of the procedure.
47
- */
48
- type ProcHasInit<S extends AnyService, ProcName extends keyof S['procedures']> = S['procedures'][ProcName] extends {
49
- init: PayloadType;
50
- } ? true : false;
51
- /**
52
- * Helper to get the type definition for the procedure init type of a service.
53
- * @template S - The service.
54
- * @template ProcName - The name of the procedure.
55
- */
56
- type ProcInit<S extends AnyService, ProcName extends keyof S['procedures']> = S['procedures'][ProcName] extends {
57
- init: PayloadType;
58
- } ? S['procedures'][ProcName]['init'] : never;
59
- /**
60
- * Helper to get the type definition for the procedure input of a service.
61
- * @template S - The service.
62
- * @template ProcName - The name of the procedure.
63
- */
64
- type ProcInput<S extends AnyService, ProcName extends keyof S['procedures']> = S['procedures'][ProcName]['input'];
65
- /**
66
- * Helper to get the type definition for the procedure output of a service.
67
- * @template S - The service.
68
- * @template ProcName - The name of the procedure.
69
- */
70
- type ProcOutput<S extends AnyService, ProcName extends keyof S['procedures']> = S['procedures'][ProcName]['output'];
71
- /**
72
- * Helper to get the type definition for the procedure errors of a service.
73
- * @template S - The service.
74
- * @template ProcName - The name of the procedure.
75
- */
76
- type ProcErrors<S extends AnyService, ProcName extends keyof S['procedures']> = TUnion<[S['procedures'][ProcName]['errors'], typeof RiverUncaughtSchema]>;
77
- /**
78
- * Helper to get the type of procedure in a service.
79
- * @template S - The service.
80
- * @template ProcName - The name of the procedure.
81
- */
82
- type ProcType<S extends AnyService, ProcName extends keyof S['procedures']> = S['procedures'][ProcName]['type'];
83
- /**
84
- * A list of procedures where every procedure is "branded", as-in the procedure
85
- * was created via the {@link Procedure} constructors.
86
- */
87
- type BrandedProcedureMap<State> = Record<string, Branded<AnyProcedure<State>>>;
88
- /**
89
- * The configuration for a service.
90
- */
91
- interface ServiceConfiguration<State extends object> {
92
- /**
93
- * A factory function for creating a fresh state.
94
- */
95
- initializeState: () => State;
96
- }
97
- interface SerializedServiceSchema {
98
- procedures: Record<string, {
99
- input: PayloadType;
100
- output: PayloadType;
101
- errors?: RiverError;
102
- type: 'rpc' | 'subscription' | 'upload' | 'stream';
103
- init?: PayloadType;
104
- }>;
105
- }
106
- type SerializedServerSchema = Record<string, SerializedServiceSchema>;
107
- declare function serializeSchema(services: AnyServiceSchemaMap): SerializedServerSchema;
108
- /**
109
- * The schema for a {@link Service}. This is used to define a service, specifically
110
- * its initial state and procedures.
111
- *
112
- * There are two ways to define a service:
113
- * 1. the {@link ServiceSchema.define} static method, which takes a configuration and
114
- * a list of procedures directly. Use this to ergonomically define a service schema
115
- * in one go. Good for smaller services, especially if they're stateless.
116
- * 2. the {@link ServiceSchema.scaffold} static method, which creates a scaffold that
117
- * can be used to define procedures separately from the configuration. Use this to
118
- * better organize your service's definition, especially if it's a large service.
119
- * You can also use it in a builder pattern to define the service in a more
120
- * fluent way.
121
- *
122
- * See the static methods for more information and examples.
123
- *
124
- * When defining procedures, use the {@link Procedure} constructors to create them.
125
- */
126
- declare class ServiceSchema<State extends object, Procedures extends ProcedureMap<State>> {
127
- /**
128
- * Factory function for creating a fresh state.
129
- */
130
- protected readonly initializeState: () => State;
131
- /**
132
- * The procedures for this service.
133
- */
134
- readonly procedures: Procedures;
135
- /**
136
- * @param config - The configuration for this service.
137
- * @param procedures - The procedures for this service.
138
- */
139
- protected constructor(config: ServiceConfiguration<State>, procedures: Procedures);
140
- /**
141
- * Creates a {@link ServiceScaffold}, which can be used to define procedures
142
- * that can then be merged into a {@link ServiceSchema}, via the scaffold's
143
- * `finalize` method.
144
- *
145
- * There are two patterns that work well with this method. The first is using
146
- * it to separate the definition of procedures from the definition of the
147
- * service's configuration:
148
- * ```ts
149
- * const MyServiceScaffold = ServiceSchema.scaffold({
150
- * initializeState: () => ({ count: 0 }),
151
- * });
152
- *
153
- * const incrementProcedures = MyServiceScaffold.procedures({
154
- * increment: Procedure.rpc({
155
- * input: Type.Object({ amount: Type.Number() }),
156
- * output: Type.Object({ current: Type.Number() }),
157
- * async handler(ctx, input) {
158
- * ctx.state.count += input.amount;
159
- * return Ok({ current: ctx.state.count });
160
- * }
161
- * }),
162
- * })
163
- *
164
- * const MyService = MyServiceScaffold.finalize({
165
- * ...incrementProcedures,
166
- * // you can also directly define procedures here
167
- * });
168
- * ```
169
- * This might be really handy if you have a very large service and you're
170
- * wanting to split it over multiple files. You can define the scaffold
171
- * in one file, and then import that scaffold in other files where you
172
- * define procedures - and then finally import the scaffolds and your
173
- * procedure objects in a final file where you finalize the scaffold into
174
- * a service schema.
175
- *
176
- * The other way is to use it like in a builder pattern:
177
- * ```ts
178
- * const MyService = ServiceSchema
179
- * .scaffold({ initializeState: () => ({ count: 0 }) })
180
- * .finalize({
181
- * increment: Procedure.rpc({
182
- * input: Type.Object({ amount: Type.Number() }),
183
- * output: Type.Object({ current: Type.Number() }),
184
- * async handler(ctx, input) {
185
- * ctx.state.count += input.amount;
186
- * return Ok({ current: ctx.state.count });
187
- * }
188
- * }),
189
- * })
190
- * ```
191
- * Depending on your preferences, this may be a more appealing way to define
192
- * a schema versus using the {@link ServiceSchema.define} method.
193
- */
194
- static scaffold<State extends object>(config: ServiceConfiguration<State>): ServiceScaffold<State>;
195
- /**
196
- * Creates a new {@link ServiceSchema} with the given configuration and procedures.
197
- *
198
- * All procedures must be created with the {@link Procedure} constructors.
199
- *
200
- * NOTE: There is an overload that lets you just provide the procedures alone if your
201
- * service has no state.
202
- *
203
- * @param config - The configuration for this service.
204
- * @param procedures - The procedures for this service.
205
- *
206
- * @example
207
- * ```
208
- * const service = ServiceSchema.define(
209
- * { initializeState: () => ({ count: 0 }) },
210
- * {
211
- * increment: Procedure.rpc({
212
- * input: Type.Object({ amount: Type.Number() }),
213
- * output: Type.Object({ current: Type.Number() }),
214
- * async handler(ctx, input) {
215
- * ctx.state.count += input.amount;
216
- * return Ok({ current: ctx.state.count });
217
- * }
218
- * }),
219
- * },
220
- * );
221
- * ```
222
- */
223
- static define<State extends object, Procedures extends BrandedProcedureMap<State>>(config: ServiceConfiguration<State>, procedures: Procedures): ServiceSchema<State, {
224
- [K in keyof Procedures]: Unbranded<Procedures[K]>;
225
- }>;
226
- /**
227
- * Creates a new {@link ServiceSchema} with the given procedures.
228
- *
229
- * All procedures must be created with the {@link Procedure} constructors.
230
- *
231
- * NOTE: There is an overload that lets you provide configuration as well,
232
- * if your service has extra configuration like a state.
233
- *
234
- * @param procedures - The procedures for this service.
235
- *
236
- * @example
237
- * ```
238
- * const service = ServiceSchema.define({
239
- * add: Procedure.rpc({
240
- * input: Type.Object({ a: Type.Number(), b: Type.Number() }),
241
- * output: Type.Object({ result: Type.Number() }),
242
- * async handler(ctx, input) {
243
- * return Ok({ result: input.a + input.b });
244
- * }
245
- * }),
246
- * });
247
- */
248
- static define<Procedures extends BrandedProcedureMap<Record<string, never>>>(procedures: Procedures): ServiceSchema<Record<string, never>, {
249
- [K in keyof Procedures]: Unbranded<Procedures[K]>;
250
- }>;
251
- /**
252
- * Serializes this schema's procedures into a plain object that is JSON compatible.
253
- */
254
- serialize(): SerializedServiceSchema;
255
- /**
256
- * Instantiates this schema into a {@link Service} object.
257
- *
258
- * You probably don't need this, usually the River server will handle this
259
- * for you.
260
- */
261
- instantiate(): Service<State, Procedures>;
262
- }
263
- /**
264
- * A scaffold for defining a service's procedures.
265
- *
266
- * @see {@link ServiceSchema.scaffold}
267
- */
268
- declare class ServiceScaffold<State extends object> {
269
- /**
270
- * The configuration for this service.
271
- */
272
- protected readonly config: ServiceConfiguration<State>;
273
- /**
274
- * @param config - The configuration for this service.
275
- */
276
- constructor(config: ServiceConfiguration<State>);
277
- /**
278
- * Define procedures for this service. Use the {@link Procedure} constructors
279
- * to create them. This returns the procedures object, which can then be
280
- * passed to {@link ServiceSchema.finalize} to create a {@link ServiceSchema}.
281
- *
282
- * @example
283
- * ```
284
- * const myProcedures = MyServiceScaffold.procedures({
285
- * myRPC: Procedure.rpc({
286
- * // ...
287
- * }),
288
- * });
289
- *
290
- * const MyService = MyServiceScaffold.finalize({
291
- * ...myProcedures,
292
- * });
293
- * ```
294
- *
295
- * @param procedures - The procedures for this service.
296
- */
297
- procedures<T extends BrandedProcedureMap<State>>(procedures: T): T;
298
- /**
299
- * Finalizes the scaffold into a {@link ServiceSchema}. This is where you
300
- * provide the service's procedures and get a {@link ServiceSchema} in return.
301
- *
302
- * You can directly define procedures here, or you can define them separately
303
- * with the {@link ServiceScaffold.procedures} method, and then pass them here.
304
- *
305
- * @example
306
- * ```
307
- * const MyService = MyServiceScaffold.finalize({
308
- * myRPC: Procedure.rpc({
309
- * // ...
310
- * }),
311
- * // e.g. from the procedures method
312
- * ...myOtherProcedures,
313
- * });
314
- * ```
315
- */
316
- finalize<T extends BrandedProcedureMap<State>>(procedures: T): ServiceSchema<State, {
317
- [K in keyof T]: Unbranded<T[K]>;
318
- }>;
319
- }
320
-
321
- type AsyncIter<T> = AsyncGenerator<T, T>;
322
- /**
323
- * A helper type to transform an actual service type into a type
324
- * we can case to in the proxy.
325
- * @template Router - The type of the Router.
326
- */
327
- type ServiceClient<Router extends AnyService> = {
328
- [ProcName in keyof Router['procedures']]: ProcType<Router, ProcName> extends 'rpc' ? {
329
- rpc: (input: Static<ProcInput<Router, ProcName>>) => Promise<Result<Static<ProcOutput<Router, ProcName>>, Static<ProcErrors<Router, ProcName>>>>;
330
- } : ProcType<Router, ProcName> extends 'upload' ? ProcHasInit<Router, ProcName> extends true ? {
331
- upload: (init: Static<ProcInit<Router, ProcName>>) => Promise<[
332
- Pushable<Static<ProcInput<Router, ProcName>>>,
333
- Promise<Result<Static<ProcOutput<Router, ProcName>>, Static<ProcErrors<Router, ProcName>>>>
334
- ]>;
335
- } : {
336
- upload: () => Promise<[
337
- Pushable<Static<ProcInput<Router, ProcName>>>,
338
- Promise<Result<Static<ProcOutput<Router, ProcName>>, Static<ProcErrors<Router, ProcName>>>>
339
- ]>;
340
- } : ProcType<Router, ProcName> extends 'stream' ? ProcHasInit<Router, ProcName> extends true ? {
341
- stream: (init: Static<ProcInit<Router, ProcName>>) => Promise<[
342
- Pushable<Static<ProcInput<Router, ProcName>>>,
343
- AsyncIter<Result<Static<ProcOutput<Router, ProcName>>, Static<ProcErrors<Router, ProcName>>>>,
344
- () => void
345
- ]>;
346
- } : {
347
- stream: () => Promise<[
348
- Pushable<Static<ProcInput<Router, ProcName>>>,
349
- AsyncIter<Result<Static<ProcOutput<Router, ProcName>>, Static<ProcErrors<Router, ProcName>>>>,
350
- () => void
351
- ]>;
352
- } : ProcType<Router, ProcName> extends 'subscription' ? {
353
- subscribe: (input: Static<ProcInput<Router, ProcName>>) => Promise<[
354
- AsyncIter<Result<Static<ProcOutput<Router, ProcName>>, Static<ProcErrors<Router, ProcName>>>>,
355
- () => void
356
- ]>;
357
- } : never;
358
- };
359
- /**
360
- * Defines a type that represents a client for a server with a set of services.
361
- * @template Srv - The type of the server.
362
- */
363
- type Client<Services extends AnyServiceSchemaMap, IS extends InstantiatedServiceSchemaMap<Services> = InstantiatedServiceSchemaMap<Services>> = {
364
- [SvcName in keyof IS]: ServiceClient<IS[SvcName]>;
365
- };
366
- interface ClientOptions {
367
- connectOnInvoke: boolean;
368
- eagerlyConnect: boolean;
369
- }
370
- /**
371
- * Creates a client for a given server using the provided transport.
372
- * Note that the client only needs the type of the server, not the actual
373
- * server definition itself.
374
- *
375
- * This relies on a proxy to dynamically create the client, so the client
376
- * will be typed as if it were the actual server with the appropriate services
377
- * and procedures.
378
- *
379
- * @template Srv - The type of the server.
380
- * @param {Transport} transport - The transport to use for communication.
381
- * @returns The client for the server.
382
- */
383
- declare const createClient: <ServiceSchemaMap extends AnyServiceSchemaMap>(transport: ClientTransport<Connection>, serverId: TransportClientId, providedClientOptions?: Partial<ClientOptions>) => Client<ServiceSchemaMap, InstantiatedServiceSchemaMap<ServiceSchemaMap>>;
384
-
385
9
  /**
386
10
  * Represents a server with a set of services. Use {@link createServer} to create it.
387
11
  * @template Services - The type of services provided by the server.
@@ -412,6 +36,6 @@ interface ProcStream {
412
36
  */
413
37
  declare function createServer<Services extends AnyServiceSchemaMap>(transport: ServerTransport<Connection>, services: Services, extendedContext?: Omit<ServiceContext, 'state'>): Server<Services>;
414
38
 
415
- var version = "0.18.5";
39
+ var version = "0.19.2";
416
40
 
417
- export { Client, PayloadType, ProcErrors, ProcHandler, ProcInit, ProcInput, ProcOutput, ProcType, ProcedureMap, version as RIVER_VERSION, Result, RiverError, RiverUncaughtSchema, SerializedServerSchema, Server, Service, ServiceConfiguration, ServiceContext, ServiceSchema, createClient, createServer, serializeSchema };
41
+ export { PayloadType, version as RIVER_VERSION, Result, RiverError, Server, ServiceContext, createServer };
@@ -9,9 +9,9 @@ import {
9
9
  createServer,
10
10
  serializeSchema,
11
11
  version
12
- } from "../chunk-6Q3MSICL.js";
13
- import "../chunk-VH3NGOXQ.js";
14
- import "../chunk-WER2DWCP.js";
12
+ } from "../chunk-SR4DBLJ6.js";
13
+ import "../chunk-D5PVGZPQ.js";
14
+ import "../chunk-NBE3D667.js";
15
15
  export {
16
16
  Err,
17
17
  Ok,