@replit/river 0.208.4 → 0.209.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/README.md +36 -1
- package/dist/{adapter-ChksXKVN.d.ts → adapter-Cp7_gIVA.d.ts} +1 -1
- package/dist/{adapter-Cuc4JtfV.d.cts → adapter-DjiEwOYi.d.cts} +1 -1
- package/dist/{chunk-N62U4PDY.js → chunk-2AV3IIW5.js} +174 -168
- package/dist/chunk-2AV3IIW5.js.map +1 -0
- package/dist/{chunk-NJNR3MK5.js → chunk-2DRHPFKM.js} +2 -2
- package/dist/{chunk-7TKRCDKJ.js → chunk-UC4MQ5FP.js} +2 -2
- package/dist/{chunk-7TKRCDKJ.js.map → chunk-UC4MQ5FP.js.map} +1 -1
- package/dist/client-CRY4aeRv.d.cts +54 -0
- package/dist/client-Cvl0bF5y.d.ts +54 -0
- package/dist/codec/index.d.cts +3 -3
- package/dist/codec/index.d.ts +3 -3
- package/dist/codec/index.js +2 -2
- package/dist/common-MmS1PQN7.d.cts +577 -0
- package/dist/common-yodP-WNy.d.ts +577 -0
- package/dist/{connection-BF4zg6Qv.d.cts → connection-BVE0wfE7.d.cts} +3 -3
- package/dist/{connection-Donr3JRB.d.ts → connection-BphUYGjL.d.ts} +3 -3
- package/dist/{index-D8IOd3LG.d.ts → index-CSM8soK7.d.ts} +1 -1
- package/dist/{index-C9tpZjBN.d.cts → index-D9R6UTMl.d.cts} +1 -1
- package/dist/logging/index.d.cts +2 -2
- package/dist/logging/index.d.ts +2 -2
- package/dist/{message-Di94OL80.d.cts → message-Dlsh5WDF.d.cts} +1 -1
- package/dist/{message-Di94OL80.d.ts → message-Dlsh5WDF.d.ts} +1 -1
- package/dist/router/index.cjs +174 -168
- package/dist/router/index.cjs.map +1 -1
- package/dist/router/index.d.cts +21 -18
- package/dist/router/index.d.ts +21 -18
- package/dist/router/index.js +3 -3
- package/dist/server-BKZTIlAc.d.cts +72 -0
- package/dist/server-hDGOXIRA.d.ts +72 -0
- package/dist/services-9I3wdkpy.d.cts +1010 -0
- package/dist/services-BFGny14R.d.ts +1010 -0
- package/dist/testUtil/index.cjs +1 -1
- package/dist/testUtil/index.cjs.map +1 -1
- package/dist/testUtil/index.d.cts +9 -7
- package/dist/testUtil/index.d.ts +9 -7
- package/dist/testUtil/index.js +2 -2
- package/dist/testUtil/index.js.map +1 -1
- package/dist/transport/impls/ws/client.cjs +1 -1
- package/dist/transport/impls/ws/client.cjs.map +1 -1
- package/dist/transport/impls/ws/client.d.cts +6 -5
- package/dist/transport/impls/ws/client.d.ts +6 -5
- package/dist/transport/impls/ws/client.js +3 -3
- package/dist/transport/impls/ws/server.cjs +1 -1
- package/dist/transport/impls/ws/server.cjs.map +1 -1
- package/dist/transport/impls/ws/server.d.cts +8 -8
- package/dist/transport/impls/ws/server.d.ts +8 -8
- package/dist/transport/impls/ws/server.js +3 -3
- package/dist/transport/impls/ws/server.js.map +1 -1
- package/dist/transport/index.cjs +1 -1
- package/dist/transport/index.cjs.map +1 -1
- package/dist/transport/index.d.cts +7 -74
- package/dist/transport/index.d.ts +7 -74
- package/dist/transport/index.js +2 -2
- package/package.json +1 -1
- package/dist/chunk-N62U4PDY.js.map +0 -1
- package/dist/transport-CCaWx1Rb.d.cts +0 -1566
- package/dist/transport-CZb3vdB4.d.ts +0 -1566
- /package/dist/{chunk-NJNR3MK5.js.map → chunk-2DRHPFKM.js.map} +0 -0
package/README.md
CHANGED
|
@@ -272,4 +272,39 @@ You can find more service examples in the [E2E test fixtures](https://github.com
|
|
|
272
272
|
- `npm run check` -- lint
|
|
273
273
|
- `npm run format` -- format
|
|
274
274
|
- `npm run test` -- run tests
|
|
275
|
-
- `npm run
|
|
275
|
+
- `npm run release` -- cut a new release (should bump version in package.json first)
|
|
276
|
+
|
|
277
|
+
## Releasing
|
|
278
|
+
|
|
279
|
+
River uses an automated release process with [Release Drafter](https://github.com/release-drafter/release-drafter) for version management and NPM publishing.
|
|
280
|
+
|
|
281
|
+
### Automated Release Process (Recommended)
|
|
282
|
+
|
|
283
|
+
1. **Merge PRs to main** - Release Drafter automatically:
|
|
284
|
+
|
|
285
|
+
- Updates the draft release notes with PR titles
|
|
286
|
+
- You can view the draft at [GitHub Releases](../../releases)
|
|
287
|
+
|
|
288
|
+
2. **When ready to release, create a version bump PR**:
|
|
289
|
+
|
|
290
|
+
- Create a PR that bumps the version in `package.json` and `package-lock.json`. You can run `pnpm version --no-git-tag-version <version>` to bump the version.
|
|
291
|
+
- Use semantic versioning:
|
|
292
|
+
- `patch` - Bug fixes, small improvements (e.g., 0.208.4 → 0.208.5)
|
|
293
|
+
- `minor` - New features, backwards compatible (e.g., 0.208.4 → 0.209.0)
|
|
294
|
+
- `major` - Breaking changes (e.g., 0.208.4 → 1.0.0)
|
|
295
|
+
- Merge the PR to main
|
|
296
|
+
|
|
297
|
+
3. **Publish the GitHub release**:
|
|
298
|
+
|
|
299
|
+
- Go to [GitHub Releases](../../releases)
|
|
300
|
+
- Find the draft release and click "Edit"
|
|
301
|
+
- Update the tag to match your new version (e.g., `v0.209.0`)
|
|
302
|
+
- Click "Publish release"
|
|
303
|
+
|
|
304
|
+
4. **Automation takes over**:
|
|
305
|
+
|
|
306
|
+
- Publishing the release automatically triggers the "Build and Publish" workflow
|
|
307
|
+
- The `river` package is published to NPM
|
|
308
|
+
|
|
309
|
+
5. **Manual npm release**:
|
|
310
|
+
- If the auto-publish workflow failed, you can run `npm run release` locally
|
|
@@ -107,182 +107,184 @@ function serializeSchema(services, handshakeSchema) {
|
|
|
107
107
|
}
|
|
108
108
|
return schema;
|
|
109
109
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
if (
|
|
190
|
-
|
|
110
|
+
function createServiceSchema() {
|
|
111
|
+
return class ServiceSchema {
|
|
112
|
+
/**
|
|
113
|
+
* Factory function for creating a fresh state.
|
|
114
|
+
*/
|
|
115
|
+
initializeState;
|
|
116
|
+
/**
|
|
117
|
+
* The procedures for this service.
|
|
118
|
+
*/
|
|
119
|
+
procedures;
|
|
120
|
+
/**
|
|
121
|
+
* @param config - The configuration for this service.
|
|
122
|
+
* @param procedures - The procedures for this service.
|
|
123
|
+
*/
|
|
124
|
+
constructor(config, procedures) {
|
|
125
|
+
this.initializeState = config.initializeState;
|
|
126
|
+
this.procedures = procedures;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Creates a {@link ServiceScaffold}, which can be used to define procedures
|
|
130
|
+
* that can then be merged into a {@link ServiceSchema}, via the scaffold's
|
|
131
|
+
* `finalize` method.
|
|
132
|
+
*
|
|
133
|
+
* There are two patterns that work well with this method. The first is using
|
|
134
|
+
* it to separate the definition of procedures from the definition of the
|
|
135
|
+
* service's configuration:
|
|
136
|
+
* ```ts
|
|
137
|
+
* const MyServiceScaffold = ServiceSchema.scaffold({
|
|
138
|
+
* initializeState: () => ({ count: 0 }),
|
|
139
|
+
* });
|
|
140
|
+
*
|
|
141
|
+
* const incrementProcedures = MyServiceScaffold.procedures({
|
|
142
|
+
* increment: Procedure.rpc({
|
|
143
|
+
* requestInit: Type.Object({ amount: Type.Number() }),
|
|
144
|
+
* responseData: Type.Object({ current: Type.Number() }),
|
|
145
|
+
* async handler(ctx, init) {
|
|
146
|
+
* ctx.state.count += init.amount;
|
|
147
|
+
* return Ok({ current: ctx.state.count });
|
|
148
|
+
* }
|
|
149
|
+
* }),
|
|
150
|
+
* })
|
|
151
|
+
*
|
|
152
|
+
* const MyService = MyServiceScaffold.finalize({
|
|
153
|
+
* ...incrementProcedures,
|
|
154
|
+
* // you can also directly define procedures here
|
|
155
|
+
* });
|
|
156
|
+
* ```
|
|
157
|
+
* This might be really handy if you have a very large service and you're
|
|
158
|
+
* wanting to split it over multiple files. You can define the scaffold
|
|
159
|
+
* in one file, and then import that scaffold in other files where you
|
|
160
|
+
* define procedures - and then finally import the scaffolds and your
|
|
161
|
+
* procedure objects in a final file where you finalize the scaffold into
|
|
162
|
+
* a service schema.
|
|
163
|
+
*
|
|
164
|
+
* The other way is to use it like in a builder pattern:
|
|
165
|
+
* ```ts
|
|
166
|
+
* const MyService = ServiceSchema
|
|
167
|
+
* .scaffold({ initializeState: () => ({ count: 0 }) })
|
|
168
|
+
* .finalize({
|
|
169
|
+
* increment: Procedure.rpc({
|
|
170
|
+
* requestInit: Type.Object({ amount: Type.Number() }),
|
|
171
|
+
* responseData: Type.Object({ current: Type.Number() }),
|
|
172
|
+
* async handler(ctx, init) {
|
|
173
|
+
* ctx.state.count += init.amount;
|
|
174
|
+
* return Ok({ current: ctx.state.count });
|
|
175
|
+
* }
|
|
176
|
+
* }),
|
|
177
|
+
* })
|
|
178
|
+
* ```
|
|
179
|
+
* Depending on your preferences, this may be a more appealing way to define
|
|
180
|
+
* a schema versus using the {@link ServiceSchema.define} method.
|
|
181
|
+
*/
|
|
182
|
+
static scaffold(config) {
|
|
183
|
+
return new ServiceScaffold(config);
|
|
184
|
+
}
|
|
185
|
+
// actual implementation
|
|
186
|
+
static define(configOrProcedures, maybeProcedures) {
|
|
187
|
+
let config;
|
|
188
|
+
let procedures;
|
|
189
|
+
if ("initializeState" in configOrProcedures && typeof configOrProcedures.initializeState === "function") {
|
|
190
|
+
if (!maybeProcedures) {
|
|
191
|
+
throw new Error("Expected procedures to be defined");
|
|
192
|
+
}
|
|
193
|
+
config = configOrProcedures;
|
|
194
|
+
procedures = maybeProcedures;
|
|
195
|
+
} else {
|
|
196
|
+
config = { initializeState: () => ({}) };
|
|
197
|
+
procedures = configOrProcedures;
|
|
191
198
|
}
|
|
192
|
-
config
|
|
193
|
-
procedures = maybeProcedures;
|
|
194
|
-
} else {
|
|
195
|
-
config = { initializeState: () => ({}) };
|
|
196
|
-
procedures = configOrProcedures;
|
|
199
|
+
return new ServiceSchema(config, procedures);
|
|
197
200
|
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
201
|
+
/**
|
|
202
|
+
* Serializes this schema's procedures into a plain object that is JSON compatible.
|
|
203
|
+
*/
|
|
204
|
+
serialize() {
|
|
205
|
+
return {
|
|
206
|
+
procedures: Object.fromEntries(
|
|
207
|
+
Object.entries(this.procedures).map(([procName, procDef]) => [
|
|
208
|
+
procName,
|
|
209
|
+
{
|
|
210
|
+
init: Strict(procDef.requestInit),
|
|
211
|
+
output: Strict(procDef.responseData),
|
|
212
|
+
errors: getSerializedProcErrors(procDef),
|
|
213
|
+
// Only add `description` field if the type declares it.
|
|
214
|
+
..."description" in procDef ? { description: procDef.description } : {},
|
|
215
|
+
type: procDef.type,
|
|
216
|
+
// Only add the `input` field if the type declares it.
|
|
217
|
+
..."requestData" in procDef ? {
|
|
218
|
+
input: Strict(procDef.requestData)
|
|
219
|
+
} : {}
|
|
220
|
+
}
|
|
221
|
+
])
|
|
222
|
+
)
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
// TODO remove once clients migrate to v2
|
|
226
|
+
/**
|
|
227
|
+
* Same as {@link ServiceSchema.serialize}, but with a format that is compatible with
|
|
228
|
+
* protocol v1. This is useful to be able to continue to generate schemas for older
|
|
229
|
+
* clients as they are still supported.
|
|
230
|
+
*/
|
|
231
|
+
serializeV1Compat() {
|
|
232
|
+
return {
|
|
233
|
+
procedures: Object.fromEntries(
|
|
234
|
+
Object.entries(this.procedures).map(
|
|
235
|
+
([procName, procDef]) => {
|
|
236
|
+
if (procDef.type === "rpc" || procDef.type === "subscription") {
|
|
237
|
+
return [
|
|
238
|
+
procName,
|
|
239
|
+
{
|
|
240
|
+
// BACKWARDS COMPAT: map init to input for protocolv1
|
|
241
|
+
// this is the only change needed to make it compatible.
|
|
242
|
+
input: Strict(procDef.requestInit),
|
|
243
|
+
output: Strict(procDef.responseData),
|
|
244
|
+
errors: getSerializedProcErrors(procDef),
|
|
245
|
+
// Only add `description` field if the type declares it.
|
|
246
|
+
..."description" in procDef ? { description: procDef.description } : {},
|
|
247
|
+
type: procDef.type
|
|
248
|
+
}
|
|
249
|
+
];
|
|
250
|
+
}
|
|
236
251
|
return [
|
|
237
252
|
procName,
|
|
238
253
|
{
|
|
239
|
-
|
|
240
|
-
// this is the only change needed to make it compatible.
|
|
241
|
-
input: Strict(procDef.requestInit),
|
|
254
|
+
init: Strict(procDef.requestInit),
|
|
242
255
|
output: Strict(procDef.responseData),
|
|
243
256
|
errors: getSerializedProcErrors(procDef),
|
|
244
257
|
// Only add `description` field if the type declares it.
|
|
245
258
|
..."description" in procDef ? { description: procDef.description } : {},
|
|
246
|
-
type: procDef.type
|
|
259
|
+
type: procDef.type,
|
|
260
|
+
input: Strict(procDef.requestData)
|
|
247
261
|
}
|
|
248
262
|
];
|
|
249
263
|
}
|
|
250
|
-
|
|
251
|
-
procName,
|
|
252
|
-
{
|
|
253
|
-
init: Strict(procDef.requestInit),
|
|
254
|
-
output: Strict(procDef.responseData),
|
|
255
|
-
errors: getSerializedProcErrors(procDef),
|
|
256
|
-
// Only add `description` field if the type declares it.
|
|
257
|
-
..."description" in procDef ? { description: procDef.description } : {},
|
|
258
|
-
type: procDef.type,
|
|
259
|
-
input: Strict(procDef.requestData)
|
|
260
|
-
}
|
|
261
|
-
];
|
|
262
|
-
}
|
|
264
|
+
)
|
|
263
265
|
)
|
|
264
|
-
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
}
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Instantiates this schema into a {@link Service} object.
|
|
270
|
+
*
|
|
271
|
+
* You probably don't need this, usually the River server will handle this
|
|
272
|
+
* for you.
|
|
273
|
+
*/
|
|
274
|
+
instantiate(extendedContext) {
|
|
275
|
+
const state = this.initializeState(extendedContext);
|
|
276
|
+
const dispose = async () => {
|
|
277
|
+
await state[Symbol.asyncDispose]?.();
|
|
278
|
+
state[Symbol.dispose]?.();
|
|
279
|
+
};
|
|
280
|
+
return Object.freeze({
|
|
281
|
+
state,
|
|
282
|
+
procedures: this.procedures,
|
|
283
|
+
[Symbol.asyncDispose]: dispose
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
}
|
|
286
288
|
function getSerializedProcErrors(procDef) {
|
|
287
289
|
if (!("responseError" in procDef) || procDef.responseError[Kind2] === "Never") {
|
|
288
290
|
return Strict(ReaderErrorSchema);
|
|
@@ -345,7 +347,10 @@ var ServiceScaffold = class {
|
|
|
345
347
|
* ```
|
|
346
348
|
*/
|
|
347
349
|
finalize(procedures) {
|
|
348
|
-
return
|
|
350
|
+
return createServiceSchema().define(
|
|
351
|
+
this.config,
|
|
352
|
+
procedures
|
|
353
|
+
);
|
|
349
354
|
}
|
|
350
355
|
};
|
|
351
356
|
|
|
@@ -1289,8 +1294,9 @@ var RiverServer = class {
|
|
|
1289
1294
|
this.middlewares = middlewares;
|
|
1290
1295
|
this.services = instances;
|
|
1291
1296
|
this.contextMap = /* @__PURE__ */ new Map();
|
|
1297
|
+
extendedContext = extendedContext ?? {};
|
|
1292
1298
|
for (const [name, service] of Object.entries(services)) {
|
|
1293
|
-
const instance = service.instantiate(extendedContext
|
|
1299
|
+
const instance = service.instantiate(extendedContext);
|
|
1294
1300
|
instances[name] = instance;
|
|
1295
1301
|
this.contextMap.set(instance, {
|
|
1296
1302
|
...extendedContext,
|
|
@@ -1973,7 +1979,7 @@ function createServerHandshakeOptions(schema, validate) {
|
|
|
1973
1979
|
}
|
|
1974
1980
|
|
|
1975
1981
|
// package.json
|
|
1976
|
-
var version = "0.
|
|
1982
|
+
var version = "0.209.1";
|
|
1977
1983
|
|
|
1978
1984
|
export {
|
|
1979
1985
|
generateId,
|
|
@@ -1997,7 +2003,7 @@ export {
|
|
|
1997
2003
|
flattenErrorType,
|
|
1998
2004
|
serializeSchemaV1Compat,
|
|
1999
2005
|
serializeSchema,
|
|
2000
|
-
|
|
2006
|
+
createServiceSchema,
|
|
2001
2007
|
Procedure,
|
|
2002
2008
|
Ok,
|
|
2003
2009
|
Err,
|
|
@@ -2012,4 +2018,4 @@ export {
|
|
|
2012
2018
|
createConnectionTelemetryInfo,
|
|
2013
2019
|
getTracer
|
|
2014
2020
|
};
|
|
2015
|
-
//# sourceMappingURL=chunk-
|
|
2021
|
+
//# sourceMappingURL=chunk-2AV3IIW5.js.map
|