@replit/river 0.10.1 → 0.10.3

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.
@@ -1,5 +1,5 @@
1
1
  import * as _sinclair_typebox from '@sinclair/typebox';
2
- import { TObject, TLiteralString, TString, TSchema, TUnion, TNever, Static } from '@sinclair/typebox';
2
+ import { TObject, TLiteralString, TUnion, TString, TSchema, TNever, Static } from '@sinclair/typebox';
3
3
  import { Pushable } from 'it-pushable';
4
4
 
5
5
  /**
@@ -33,10 +33,10 @@ type ServiceContextWithState<State extends object | unknown> = ServiceContext &
33
33
  };
34
34
 
35
35
  type RiverErrorSchema = TObject<{
36
- code: TLiteralString;
36
+ code: TLiteralString | TUnion<TLiteralString[]>;
37
37
  message: TLiteralString | TString;
38
38
  }> | TObject<{
39
- code: TLiteralString;
39
+ code: TLiteralString | TUnion<TLiteralString[]>;
40
40
  message: TLiteralString | TString;
41
41
  extras: TSchema;
42
42
  }>;
@@ -99,8 +99,289 @@ function buildServiceDefs(services) {
99
99
  }, {});
100
100
  }
101
101
 
102
+ // node_modules/p-defer/index.js
103
+ function pDefer() {
104
+ const deferred = {};
105
+ deferred.promise = new Promise((resolve, reject) => {
106
+ deferred.resolve = resolve;
107
+ deferred.reject = reject;
108
+ });
109
+ return deferred;
110
+ }
111
+
112
+ // node_modules/it-pushable/dist/src/fifo.js
113
+ var FixedFIFO = class {
114
+ buffer;
115
+ mask;
116
+ top;
117
+ btm;
118
+ next;
119
+ constructor(hwm) {
120
+ if (!(hwm > 0) || (hwm - 1 & hwm) !== 0) {
121
+ throw new Error("Max size for a FixedFIFO should be a power of two");
122
+ }
123
+ this.buffer = new Array(hwm);
124
+ this.mask = hwm - 1;
125
+ this.top = 0;
126
+ this.btm = 0;
127
+ this.next = null;
128
+ }
129
+ push(data) {
130
+ if (this.buffer[this.top] !== void 0) {
131
+ return false;
132
+ }
133
+ this.buffer[this.top] = data;
134
+ this.top = this.top + 1 & this.mask;
135
+ return true;
136
+ }
137
+ shift() {
138
+ const last = this.buffer[this.btm];
139
+ if (last === void 0) {
140
+ return void 0;
141
+ }
142
+ this.buffer[this.btm] = void 0;
143
+ this.btm = this.btm + 1 & this.mask;
144
+ return last;
145
+ }
146
+ isEmpty() {
147
+ return this.buffer[this.btm] === void 0;
148
+ }
149
+ };
150
+ var FIFO = class {
151
+ size;
152
+ hwm;
153
+ head;
154
+ tail;
155
+ constructor(options = {}) {
156
+ this.hwm = options.splitLimit ?? 16;
157
+ this.head = new FixedFIFO(this.hwm);
158
+ this.tail = this.head;
159
+ this.size = 0;
160
+ }
161
+ calculateSize(obj) {
162
+ if (obj?.byteLength != null) {
163
+ return obj.byteLength;
164
+ }
165
+ return 1;
166
+ }
167
+ push(val) {
168
+ if (val?.value != null) {
169
+ this.size += this.calculateSize(val.value);
170
+ }
171
+ if (!this.head.push(val)) {
172
+ const prev = this.head;
173
+ this.head = prev.next = new FixedFIFO(2 * this.head.buffer.length);
174
+ this.head.push(val);
175
+ }
176
+ }
177
+ shift() {
178
+ let val = this.tail.shift();
179
+ if (val === void 0 && this.tail.next != null) {
180
+ const next = this.tail.next;
181
+ this.tail.next = null;
182
+ this.tail = next;
183
+ val = this.tail.shift();
184
+ }
185
+ if (val?.value != null) {
186
+ this.size -= this.calculateSize(val.value);
187
+ }
188
+ return val;
189
+ }
190
+ isEmpty() {
191
+ return this.head.isEmpty();
192
+ }
193
+ };
194
+
195
+ // node_modules/it-pushable/dist/src/index.js
196
+ var AbortError = class extends Error {
197
+ type;
198
+ code;
199
+ constructor(message, code) {
200
+ super(message ?? "The operation was aborted");
201
+ this.type = "aborted";
202
+ this.code = code ?? "ABORT_ERR";
203
+ }
204
+ };
205
+ function pushable(options = {}) {
206
+ const getNext = (buffer) => {
207
+ const next = buffer.shift();
208
+ if (next == null) {
209
+ return { done: true };
210
+ }
211
+ if (next.error != null) {
212
+ throw next.error;
213
+ }
214
+ return {
215
+ done: next.done === true,
216
+ // @ts-expect-error if done is false, value will be present
217
+ value: next.value
218
+ };
219
+ };
220
+ return _pushable(getNext, options);
221
+ }
222
+ function _pushable(getNext, options) {
223
+ options = options ?? {};
224
+ let onEnd = options.onEnd;
225
+ let buffer = new FIFO();
226
+ let pushable2;
227
+ let onNext;
228
+ let ended;
229
+ let drain = pDefer();
230
+ const waitNext = async () => {
231
+ try {
232
+ if (!buffer.isEmpty()) {
233
+ return getNext(buffer);
234
+ }
235
+ if (ended) {
236
+ return { done: true };
237
+ }
238
+ return await new Promise((resolve, reject) => {
239
+ onNext = (next) => {
240
+ onNext = null;
241
+ buffer.push(next);
242
+ try {
243
+ resolve(getNext(buffer));
244
+ } catch (err) {
245
+ reject(err);
246
+ }
247
+ return pushable2;
248
+ };
249
+ });
250
+ } finally {
251
+ if (buffer.isEmpty()) {
252
+ queueMicrotask(() => {
253
+ drain.resolve();
254
+ drain = pDefer();
255
+ });
256
+ }
257
+ }
258
+ };
259
+ const bufferNext = (next) => {
260
+ if (onNext != null) {
261
+ return onNext(next);
262
+ }
263
+ buffer.push(next);
264
+ return pushable2;
265
+ };
266
+ const bufferError = (err) => {
267
+ buffer = new FIFO();
268
+ if (onNext != null) {
269
+ return onNext({ error: err });
270
+ }
271
+ buffer.push({ error: err });
272
+ return pushable2;
273
+ };
274
+ const push = (value) => {
275
+ if (ended) {
276
+ return pushable2;
277
+ }
278
+ if (options?.objectMode !== true && value?.byteLength == null) {
279
+ throw new Error("objectMode was not true but tried to push non-Uint8Array value");
280
+ }
281
+ return bufferNext({ done: false, value });
282
+ };
283
+ const end = (err) => {
284
+ if (ended)
285
+ return pushable2;
286
+ ended = true;
287
+ return err != null ? bufferError(err) : bufferNext({ done: true });
288
+ };
289
+ const _return = () => {
290
+ buffer = new FIFO();
291
+ end();
292
+ return { done: true };
293
+ };
294
+ const _throw = (err) => {
295
+ end(err);
296
+ return { done: true };
297
+ };
298
+ pushable2 = {
299
+ [Symbol.asyncIterator]() {
300
+ return this;
301
+ },
302
+ next: waitNext,
303
+ return: _return,
304
+ throw: _throw,
305
+ push,
306
+ end,
307
+ get readableLength() {
308
+ return buffer.size;
309
+ },
310
+ onEmpty: async (options2) => {
311
+ const signal = options2?.signal;
312
+ signal?.throwIfAborted();
313
+ if (buffer.isEmpty()) {
314
+ return;
315
+ }
316
+ let cancel;
317
+ let listener;
318
+ if (signal != null) {
319
+ cancel = new Promise((resolve, reject) => {
320
+ listener = () => {
321
+ reject(new AbortError());
322
+ };
323
+ signal.addEventListener("abort", listener);
324
+ });
325
+ }
326
+ try {
327
+ await Promise.race([
328
+ drain.promise,
329
+ cancel
330
+ ]);
331
+ } finally {
332
+ if (listener != null && signal != null) {
333
+ signal?.removeEventListener("abort", listener);
334
+ }
335
+ }
336
+ }
337
+ };
338
+ if (onEnd == null) {
339
+ return pushable2;
340
+ }
341
+ const _pushable2 = pushable2;
342
+ pushable2 = {
343
+ [Symbol.asyncIterator]() {
344
+ return this;
345
+ },
346
+ next() {
347
+ return _pushable2.next();
348
+ },
349
+ throw(err) {
350
+ _pushable2.throw(err);
351
+ if (onEnd != null) {
352
+ onEnd(err);
353
+ onEnd = void 0;
354
+ }
355
+ return { done: true };
356
+ },
357
+ return() {
358
+ _pushable2.return();
359
+ if (onEnd != null) {
360
+ onEnd();
361
+ onEnd = void 0;
362
+ }
363
+ return { done: true };
364
+ },
365
+ push,
366
+ end(err) {
367
+ _pushable2.end(err);
368
+ if (onEnd != null) {
369
+ onEnd(err);
370
+ onEnd = void 0;
371
+ }
372
+ return pushable2;
373
+ },
374
+ get readableLength() {
375
+ return _pushable2.readableLength;
376
+ },
377
+ onEmpty: (opts) => {
378
+ return _pushable2.onEmpty(opts);
379
+ }
380
+ };
381
+ return pushable2;
382
+ }
383
+
102
384
  // router/client.ts
103
- import { pushable } from "it-pushable";
104
385
  import { nanoid } from "nanoid";
105
386
 
106
387
  // router/result.ts
@@ -411,7 +692,6 @@ function handleUpload(transport, serverId, input, serviceName, procName) {
411
692
  }
412
693
 
413
694
  // router/server.ts
414
- import { pushable as pushable2 } from "it-pushable";
415
695
  import { Value } from "@sinclair/typebox/value";
416
696
  var RiverServer = class {
417
697
  transport;
@@ -499,8 +779,8 @@ var RiverServer = class {
499
779
  return;
500
780
  }
501
781
  const procedure = service.procedures[message.procedureName];
502
- const incoming = pushable2({ objectMode: true });
503
- const outgoing = pushable2({ objectMode: true });
782
+ const incoming = pushable({ objectMode: true });
783
+ const outgoing = pushable({ objectMode: true });
504
784
  const outputHandler = (
505
785
  // sending outgoing messages back to client
506
786
  (async () => {
@@ -674,6 +954,7 @@ export {
674
954
  serializeService,
675
955
  ServiceBuilder,
676
956
  buildServiceDefs,
957
+ pushable,
677
958
  UNCAUGHT_ERROR,
678
959
  RiverUncaughtSchema,
679
960
  Ok,
@@ -121,8 +121,287 @@ function buildServiceDefs(services) {
121
121
  }, {});
122
122
  }
123
123
 
124
- // router/client.ts
125
- var import_it_pushable = require("it-pushable");
124
+ // node_modules/p-defer/index.js
125
+ function pDefer() {
126
+ const deferred = {};
127
+ deferred.promise = new Promise((resolve, reject) => {
128
+ deferred.resolve = resolve;
129
+ deferred.reject = reject;
130
+ });
131
+ return deferred;
132
+ }
133
+
134
+ // node_modules/it-pushable/dist/src/fifo.js
135
+ var FixedFIFO = class {
136
+ buffer;
137
+ mask;
138
+ top;
139
+ btm;
140
+ next;
141
+ constructor(hwm) {
142
+ if (!(hwm > 0) || (hwm - 1 & hwm) !== 0) {
143
+ throw new Error("Max size for a FixedFIFO should be a power of two");
144
+ }
145
+ this.buffer = new Array(hwm);
146
+ this.mask = hwm - 1;
147
+ this.top = 0;
148
+ this.btm = 0;
149
+ this.next = null;
150
+ }
151
+ push(data) {
152
+ if (this.buffer[this.top] !== void 0) {
153
+ return false;
154
+ }
155
+ this.buffer[this.top] = data;
156
+ this.top = this.top + 1 & this.mask;
157
+ return true;
158
+ }
159
+ shift() {
160
+ const last = this.buffer[this.btm];
161
+ if (last === void 0) {
162
+ return void 0;
163
+ }
164
+ this.buffer[this.btm] = void 0;
165
+ this.btm = this.btm + 1 & this.mask;
166
+ return last;
167
+ }
168
+ isEmpty() {
169
+ return this.buffer[this.btm] === void 0;
170
+ }
171
+ };
172
+ var FIFO = class {
173
+ size;
174
+ hwm;
175
+ head;
176
+ tail;
177
+ constructor(options = {}) {
178
+ this.hwm = options.splitLimit ?? 16;
179
+ this.head = new FixedFIFO(this.hwm);
180
+ this.tail = this.head;
181
+ this.size = 0;
182
+ }
183
+ calculateSize(obj) {
184
+ if (obj?.byteLength != null) {
185
+ return obj.byteLength;
186
+ }
187
+ return 1;
188
+ }
189
+ push(val) {
190
+ if (val?.value != null) {
191
+ this.size += this.calculateSize(val.value);
192
+ }
193
+ if (!this.head.push(val)) {
194
+ const prev = this.head;
195
+ this.head = prev.next = new FixedFIFO(2 * this.head.buffer.length);
196
+ this.head.push(val);
197
+ }
198
+ }
199
+ shift() {
200
+ let val = this.tail.shift();
201
+ if (val === void 0 && this.tail.next != null) {
202
+ const next = this.tail.next;
203
+ this.tail.next = null;
204
+ this.tail = next;
205
+ val = this.tail.shift();
206
+ }
207
+ if (val?.value != null) {
208
+ this.size -= this.calculateSize(val.value);
209
+ }
210
+ return val;
211
+ }
212
+ isEmpty() {
213
+ return this.head.isEmpty();
214
+ }
215
+ };
216
+
217
+ // node_modules/it-pushable/dist/src/index.js
218
+ var AbortError = class extends Error {
219
+ type;
220
+ code;
221
+ constructor(message, code) {
222
+ super(message ?? "The operation was aborted");
223
+ this.type = "aborted";
224
+ this.code = code ?? "ABORT_ERR";
225
+ }
226
+ };
227
+ function pushable(options = {}) {
228
+ const getNext = (buffer) => {
229
+ const next = buffer.shift();
230
+ if (next == null) {
231
+ return { done: true };
232
+ }
233
+ if (next.error != null) {
234
+ throw next.error;
235
+ }
236
+ return {
237
+ done: next.done === true,
238
+ // @ts-expect-error if done is false, value will be present
239
+ value: next.value
240
+ };
241
+ };
242
+ return _pushable(getNext, options);
243
+ }
244
+ function _pushable(getNext, options) {
245
+ options = options ?? {};
246
+ let onEnd = options.onEnd;
247
+ let buffer = new FIFO();
248
+ let pushable2;
249
+ let onNext;
250
+ let ended;
251
+ let drain = pDefer();
252
+ const waitNext = async () => {
253
+ try {
254
+ if (!buffer.isEmpty()) {
255
+ return getNext(buffer);
256
+ }
257
+ if (ended) {
258
+ return { done: true };
259
+ }
260
+ return await new Promise((resolve, reject) => {
261
+ onNext = (next) => {
262
+ onNext = null;
263
+ buffer.push(next);
264
+ try {
265
+ resolve(getNext(buffer));
266
+ } catch (err) {
267
+ reject(err);
268
+ }
269
+ return pushable2;
270
+ };
271
+ });
272
+ } finally {
273
+ if (buffer.isEmpty()) {
274
+ queueMicrotask(() => {
275
+ drain.resolve();
276
+ drain = pDefer();
277
+ });
278
+ }
279
+ }
280
+ };
281
+ const bufferNext = (next) => {
282
+ if (onNext != null) {
283
+ return onNext(next);
284
+ }
285
+ buffer.push(next);
286
+ return pushable2;
287
+ };
288
+ const bufferError = (err) => {
289
+ buffer = new FIFO();
290
+ if (onNext != null) {
291
+ return onNext({ error: err });
292
+ }
293
+ buffer.push({ error: err });
294
+ return pushable2;
295
+ };
296
+ const push = (value) => {
297
+ if (ended) {
298
+ return pushable2;
299
+ }
300
+ if (options?.objectMode !== true && value?.byteLength == null) {
301
+ throw new Error("objectMode was not true but tried to push non-Uint8Array value");
302
+ }
303
+ return bufferNext({ done: false, value });
304
+ };
305
+ const end = (err) => {
306
+ if (ended)
307
+ return pushable2;
308
+ ended = true;
309
+ return err != null ? bufferError(err) : bufferNext({ done: true });
310
+ };
311
+ const _return = () => {
312
+ buffer = new FIFO();
313
+ end();
314
+ return { done: true };
315
+ };
316
+ const _throw = (err) => {
317
+ end(err);
318
+ return { done: true };
319
+ };
320
+ pushable2 = {
321
+ [Symbol.asyncIterator]() {
322
+ return this;
323
+ },
324
+ next: waitNext,
325
+ return: _return,
326
+ throw: _throw,
327
+ push,
328
+ end,
329
+ get readableLength() {
330
+ return buffer.size;
331
+ },
332
+ onEmpty: async (options2) => {
333
+ const signal = options2?.signal;
334
+ signal?.throwIfAborted();
335
+ if (buffer.isEmpty()) {
336
+ return;
337
+ }
338
+ let cancel;
339
+ let listener;
340
+ if (signal != null) {
341
+ cancel = new Promise((resolve, reject) => {
342
+ listener = () => {
343
+ reject(new AbortError());
344
+ };
345
+ signal.addEventListener("abort", listener);
346
+ });
347
+ }
348
+ try {
349
+ await Promise.race([
350
+ drain.promise,
351
+ cancel
352
+ ]);
353
+ } finally {
354
+ if (listener != null && signal != null) {
355
+ signal?.removeEventListener("abort", listener);
356
+ }
357
+ }
358
+ }
359
+ };
360
+ if (onEnd == null) {
361
+ return pushable2;
362
+ }
363
+ const _pushable2 = pushable2;
364
+ pushable2 = {
365
+ [Symbol.asyncIterator]() {
366
+ return this;
367
+ },
368
+ next() {
369
+ return _pushable2.next();
370
+ },
371
+ throw(err) {
372
+ _pushable2.throw(err);
373
+ if (onEnd != null) {
374
+ onEnd(err);
375
+ onEnd = void 0;
376
+ }
377
+ return { done: true };
378
+ },
379
+ return() {
380
+ _pushable2.return();
381
+ if (onEnd != null) {
382
+ onEnd();
383
+ onEnd = void 0;
384
+ }
385
+ return { done: true };
386
+ },
387
+ push,
388
+ end(err) {
389
+ _pushable2.end(err);
390
+ if (onEnd != null) {
391
+ onEnd(err);
392
+ onEnd = void 0;
393
+ }
394
+ return pushable2;
395
+ },
396
+ get readableLength() {
397
+ return _pushable2.readableLength;
398
+ },
399
+ onEmpty: (opts) => {
400
+ return _pushable2.onEmpty(opts);
401
+ }
402
+ };
403
+ return pushable2;
404
+ }
126
405
 
127
406
  // transport/message.ts
128
407
  var import_typebox2 = require("@sinclair/typebox");
@@ -328,8 +607,8 @@ function handleRpc(transport, serverId, input, serviceName, procName) {
328
607
  }
329
608
  function handleStream(transport, serverId, init, serviceName, procName) {
330
609
  const streamId = (0, import_nanoid2.nanoid)();
331
- const inputStream = (0, import_it_pushable.pushable)({ objectMode: true });
332
- const outputStream = (0, import_it_pushable.pushable)({ objectMode: true });
610
+ const inputStream = pushable({ objectMode: true });
611
+ const outputStream = pushable({ objectMode: true });
333
612
  let firstMessage = true;
334
613
  if (init) {
335
614
  const m = msg(
@@ -402,7 +681,7 @@ function handleSubscribe(transport, serverId, input, serviceName, procName) {
402
681
  );
403
682
  m.controlFlags |= 2 /* StreamOpenBit */;
404
683
  transport.send(m);
405
- const outputStream = (0, import_it_pushable.pushable)({ objectMode: true });
684
+ const outputStream = pushable({ objectMode: true });
406
685
  function onMessage(msg2) {
407
686
  if (msg2.streamId !== streamId) {
408
687
  return;
@@ -437,7 +716,7 @@ function handleSubscribe(transport, serverId, input, serviceName, procName) {
437
716
  }
438
717
  function handleUpload(transport, serverId, input, serviceName, procName) {
439
718
  const streamId = (0, import_nanoid2.nanoid)();
440
- const inputStream = (0, import_it_pushable.pushable)({ objectMode: true });
719
+ const inputStream = pushable({ objectMode: true });
441
720
  let firstMessage = true;
442
721
  if (input) {
443
722
  const m = msg(
@@ -492,9 +771,6 @@ function handleUpload(transport, serverId, input, serviceName, procName) {
492
771
  return [inputStream, responsePromise];
493
772
  }
494
773
 
495
- // router/server.ts
496
- var import_it_pushable2 = require("it-pushable");
497
-
498
774
  // logging/index.ts
499
775
  var log;
500
776
 
@@ -586,8 +862,8 @@ var RiverServer = class {
586
862
  return;
587
863
  }
588
864
  const procedure = service.procedures[message.procedureName];
589
- const incoming = (0, import_it_pushable2.pushable)({ objectMode: true });
590
- const outgoing = (0, import_it_pushable2.pushable)({ objectMode: true });
865
+ const incoming = pushable({ objectMode: true });
866
+ const outgoing = pushable({ objectMode: true });
591
867
  const outputHandler = (
592
868
  // sending outgoing messages back to client
593
869
  (async () => {
@@ -1,5 +1,5 @@
1
- import { A as AnyService, d as AnyProcedure, P as PayloadType, b as Result, R as RiverError, S as ServiceContext, e as ProcType, f as ProcInput, g as ProcOutput, h as ProcErrors, i as ProcHasInit, j as ProcInit } from '../builder-3c4485f0.js';
2
- export { E as Err, O as Ok, n as ProcHandler, l as ProcListing, a as Procedure, p as RiverErrorSchema, c as RiverUncaughtSchema, m as Service, k as ServiceBuilder, o as ServiceContextWithState, U as UNCAUGHT_ERROR, V as ValidProcType, s as serializeService } from '../builder-3c4485f0.js';
1
+ import { A as AnyService, d as AnyProcedure, P as PayloadType, b as Result, R as RiverError, S as ServiceContext, e as ProcType, f as ProcInput, g as ProcOutput, h as ProcErrors, i as ProcHasInit, j as ProcInit } from '../builder-87111051.js';
2
+ export { E as Err, O as Ok, n as ProcHandler, l as ProcListing, a as Procedure, p as RiverErrorSchema, c as RiverUncaughtSchema, m as Service, k as ServiceBuilder, o as ServiceContextWithState, U as UNCAUGHT_ERROR, V as ValidProcType, s as serializeService } from '../builder-87111051.js';
3
3
  import { Transport, Connection, TransportClientId } from '../transport/index.cjs';
4
4
  import { Pushable } from 'it-pushable';
5
5
  import { Static } from '@sinclair/typebox';
@@ -1,5 +1,5 @@
1
- import { A as AnyService, d as AnyProcedure, P as PayloadType, b as Result, R as RiverError, S as ServiceContext, e as ProcType, f as ProcInput, g as ProcOutput, h as ProcErrors, i as ProcHasInit, j as ProcInit } from '../builder-3c4485f0.js';
2
- export { E as Err, O as Ok, n as ProcHandler, l as ProcListing, a as Procedure, p as RiverErrorSchema, c as RiverUncaughtSchema, m as Service, k as ServiceBuilder, o as ServiceContextWithState, U as UNCAUGHT_ERROR, V as ValidProcType, s as serializeService } from '../builder-3c4485f0.js';
1
+ import { A as AnyService, d as AnyProcedure, P as PayloadType, b as Result, R as RiverError, S as ServiceContext, e as ProcType, f as ProcInput, g as ProcOutput, h as ProcErrors, i as ProcHasInit, j as ProcInit } from '../builder-87111051.js';
2
+ export { E as Err, O as Ok, n as ProcHandler, l as ProcListing, a as Procedure, p as RiverErrorSchema, c as RiverUncaughtSchema, m as Service, k as ServiceBuilder, o as ServiceContextWithState, U as UNCAUGHT_ERROR, V as ValidProcType, s as serializeService } from '../builder-87111051.js';
3
3
  import { Transport, Connection, TransportClientId } from '../transport/index.js';
4
4
  import { Pushable } from 'it-pushable';
5
5
  import { Static } from '@sinclair/typebox';
@@ -8,7 +8,7 @@ import {
8
8
  createClient,
9
9
  createServer,
10
10
  serializeService
11
- } from "../chunk-7WJ6YLE5.js";
11
+ } from "../chunk-IYRPZPSQ.js";
12
12
  import "../chunk-ZE4MX7DF.js";
13
13
  import "../chunk-SLUSVGQH.js";
14
14
  export {
@@ -535,8 +535,287 @@ var WebSocketClientTransport = class extends Transport {
535
535
  }
536
536
  };
537
537
 
538
- // util/testHelpers.ts
539
- var import_it_pushable = require("it-pushable");
538
+ // node_modules/p-defer/index.js
539
+ function pDefer() {
540
+ const deferred = {};
541
+ deferred.promise = new Promise((resolve, reject) => {
542
+ deferred.resolve = resolve;
543
+ deferred.reject = reject;
544
+ });
545
+ return deferred;
546
+ }
547
+
548
+ // node_modules/it-pushable/dist/src/fifo.js
549
+ var FixedFIFO = class {
550
+ buffer;
551
+ mask;
552
+ top;
553
+ btm;
554
+ next;
555
+ constructor(hwm) {
556
+ if (!(hwm > 0) || (hwm - 1 & hwm) !== 0) {
557
+ throw new Error("Max size for a FixedFIFO should be a power of two");
558
+ }
559
+ this.buffer = new Array(hwm);
560
+ this.mask = hwm - 1;
561
+ this.top = 0;
562
+ this.btm = 0;
563
+ this.next = null;
564
+ }
565
+ push(data) {
566
+ if (this.buffer[this.top] !== void 0) {
567
+ return false;
568
+ }
569
+ this.buffer[this.top] = data;
570
+ this.top = this.top + 1 & this.mask;
571
+ return true;
572
+ }
573
+ shift() {
574
+ const last = this.buffer[this.btm];
575
+ if (last === void 0) {
576
+ return void 0;
577
+ }
578
+ this.buffer[this.btm] = void 0;
579
+ this.btm = this.btm + 1 & this.mask;
580
+ return last;
581
+ }
582
+ isEmpty() {
583
+ return this.buffer[this.btm] === void 0;
584
+ }
585
+ };
586
+ var FIFO = class {
587
+ size;
588
+ hwm;
589
+ head;
590
+ tail;
591
+ constructor(options = {}) {
592
+ this.hwm = options.splitLimit ?? 16;
593
+ this.head = new FixedFIFO(this.hwm);
594
+ this.tail = this.head;
595
+ this.size = 0;
596
+ }
597
+ calculateSize(obj) {
598
+ if (obj?.byteLength != null) {
599
+ return obj.byteLength;
600
+ }
601
+ return 1;
602
+ }
603
+ push(val) {
604
+ if (val?.value != null) {
605
+ this.size += this.calculateSize(val.value);
606
+ }
607
+ if (!this.head.push(val)) {
608
+ const prev = this.head;
609
+ this.head = prev.next = new FixedFIFO(2 * this.head.buffer.length);
610
+ this.head.push(val);
611
+ }
612
+ }
613
+ shift() {
614
+ let val = this.tail.shift();
615
+ if (val === void 0 && this.tail.next != null) {
616
+ const next = this.tail.next;
617
+ this.tail.next = null;
618
+ this.tail = next;
619
+ val = this.tail.shift();
620
+ }
621
+ if (val?.value != null) {
622
+ this.size -= this.calculateSize(val.value);
623
+ }
624
+ return val;
625
+ }
626
+ isEmpty() {
627
+ return this.head.isEmpty();
628
+ }
629
+ };
630
+
631
+ // node_modules/it-pushable/dist/src/index.js
632
+ var AbortError = class extends Error {
633
+ type;
634
+ code;
635
+ constructor(message, code) {
636
+ super(message ?? "The operation was aborted");
637
+ this.type = "aborted";
638
+ this.code = code ?? "ABORT_ERR";
639
+ }
640
+ };
641
+ function pushable(options = {}) {
642
+ const getNext = (buffer) => {
643
+ const next = buffer.shift();
644
+ if (next == null) {
645
+ return { done: true };
646
+ }
647
+ if (next.error != null) {
648
+ throw next.error;
649
+ }
650
+ return {
651
+ done: next.done === true,
652
+ // @ts-expect-error if done is false, value will be present
653
+ value: next.value
654
+ };
655
+ };
656
+ return _pushable(getNext, options);
657
+ }
658
+ function _pushable(getNext, options) {
659
+ options = options ?? {};
660
+ let onEnd = options.onEnd;
661
+ let buffer = new FIFO();
662
+ let pushable2;
663
+ let onNext;
664
+ let ended;
665
+ let drain = pDefer();
666
+ const waitNext = async () => {
667
+ try {
668
+ if (!buffer.isEmpty()) {
669
+ return getNext(buffer);
670
+ }
671
+ if (ended) {
672
+ return { done: true };
673
+ }
674
+ return await new Promise((resolve, reject) => {
675
+ onNext = (next) => {
676
+ onNext = null;
677
+ buffer.push(next);
678
+ try {
679
+ resolve(getNext(buffer));
680
+ } catch (err) {
681
+ reject(err);
682
+ }
683
+ return pushable2;
684
+ };
685
+ });
686
+ } finally {
687
+ if (buffer.isEmpty()) {
688
+ queueMicrotask(() => {
689
+ drain.resolve();
690
+ drain = pDefer();
691
+ });
692
+ }
693
+ }
694
+ };
695
+ const bufferNext = (next) => {
696
+ if (onNext != null) {
697
+ return onNext(next);
698
+ }
699
+ buffer.push(next);
700
+ return pushable2;
701
+ };
702
+ const bufferError = (err) => {
703
+ buffer = new FIFO();
704
+ if (onNext != null) {
705
+ return onNext({ error: err });
706
+ }
707
+ buffer.push({ error: err });
708
+ return pushable2;
709
+ };
710
+ const push = (value) => {
711
+ if (ended) {
712
+ return pushable2;
713
+ }
714
+ if (options?.objectMode !== true && value?.byteLength == null) {
715
+ throw new Error("objectMode was not true but tried to push non-Uint8Array value");
716
+ }
717
+ return bufferNext({ done: false, value });
718
+ };
719
+ const end = (err) => {
720
+ if (ended)
721
+ return pushable2;
722
+ ended = true;
723
+ return err != null ? bufferError(err) : bufferNext({ done: true });
724
+ };
725
+ const _return = () => {
726
+ buffer = new FIFO();
727
+ end();
728
+ return { done: true };
729
+ };
730
+ const _throw = (err) => {
731
+ end(err);
732
+ return { done: true };
733
+ };
734
+ pushable2 = {
735
+ [Symbol.asyncIterator]() {
736
+ return this;
737
+ },
738
+ next: waitNext,
739
+ return: _return,
740
+ throw: _throw,
741
+ push,
742
+ end,
743
+ get readableLength() {
744
+ return buffer.size;
745
+ },
746
+ onEmpty: async (options2) => {
747
+ const signal = options2?.signal;
748
+ signal?.throwIfAborted();
749
+ if (buffer.isEmpty()) {
750
+ return;
751
+ }
752
+ let cancel;
753
+ let listener;
754
+ if (signal != null) {
755
+ cancel = new Promise((resolve, reject) => {
756
+ listener = () => {
757
+ reject(new AbortError());
758
+ };
759
+ signal.addEventListener("abort", listener);
760
+ });
761
+ }
762
+ try {
763
+ await Promise.race([
764
+ drain.promise,
765
+ cancel
766
+ ]);
767
+ } finally {
768
+ if (listener != null && signal != null) {
769
+ signal?.removeEventListener("abort", listener);
770
+ }
771
+ }
772
+ }
773
+ };
774
+ if (onEnd == null) {
775
+ return pushable2;
776
+ }
777
+ const _pushable2 = pushable2;
778
+ pushable2 = {
779
+ [Symbol.asyncIterator]() {
780
+ return this;
781
+ },
782
+ next() {
783
+ return _pushable2.next();
784
+ },
785
+ throw(err) {
786
+ _pushable2.throw(err);
787
+ if (onEnd != null) {
788
+ onEnd(err);
789
+ onEnd = void 0;
790
+ }
791
+ return { done: true };
792
+ },
793
+ return() {
794
+ _pushable2.return();
795
+ if (onEnd != null) {
796
+ onEnd();
797
+ onEnd = void 0;
798
+ }
799
+ return { done: true };
800
+ },
801
+ push,
802
+ end(err) {
803
+ _pushable2.end(err);
804
+ if (onEnd != null) {
805
+ onEnd(err);
806
+ onEnd = void 0;
807
+ }
808
+ return pushable2;
809
+ },
810
+ get readableLength() {
811
+ return _pushable2.readableLength;
812
+ },
813
+ onEmpty: (opts) => {
814
+ return _pushable2.onEmpty(opts);
815
+ }
816
+ };
817
+ return pushable2;
818
+ }
540
819
 
541
820
  // transport/impls/ws/server.ts
542
821
  var defaultOptions2 = {
@@ -676,8 +955,8 @@ function asClientRpc(state, proc, extendedContext) {
676
955
  };
677
956
  }
678
957
  function asClientStream(state, proc, init, extendedContext) {
679
- const input = (0, import_it_pushable.pushable)({ objectMode: true });
680
- const output = (0, import_it_pushable.pushable)({
958
+ const input = pushable({ objectMode: true });
959
+ const output = pushable({
681
960
  objectMode: true
682
961
  });
683
962
  (async () => {
@@ -692,7 +971,7 @@ function asClientStream(state, proc, init, extendedContext) {
692
971
  return [input, output];
693
972
  }
694
973
  function asClientSubscription(state, proc, extendedContext) {
695
- const output = (0, import_it_pushable.pushable)({
974
+ const output = pushable({
696
975
  objectMode: true
697
976
  });
698
977
  return async (msg2) => {
@@ -703,7 +982,7 @@ function asClientSubscription(state, proc, extendedContext) {
703
982
  };
704
983
  }
705
984
  async function asClientUpload(state, proc, init, extendedContext) {
706
- const input = (0, import_it_pushable.pushable)({ objectMode: true });
985
+ const input = pushable({ objectMode: true });
707
986
  if (init) {
708
987
  const _proc = proc;
709
988
  const result = _proc.handler({ ...extendedContext, state }, init, input).catch(catchProcError);
@@ -6,7 +6,7 @@ import { WebSocketClientTransport } from '../transport/impls/ws/client.cjs';
6
6
  import { TransportClientId, TransportMessage, OpaqueTransportMessage, Transport, Connection } from '../transport/index.cjs';
7
7
  import { C as Codec } from '../types-3e5768ec.js';
8
8
  import { WebSocketServerTransport } from '../transport/impls/ws/server.cjs';
9
- import { P as PayloadType, R as RiverError, a as Procedure, S as ServiceContext, b as Result, c as RiverUncaughtSchema } from '../builder-3c4485f0.js';
9
+ import { P as PayloadType, R as RiverError, a as Procedure, S as ServiceContext, b as Result, c as RiverUncaughtSchema } from '../builder-87111051.js';
10
10
  import { Static } from '@sinclair/typebox';
11
11
  import '../connection-f7688cc1.js';
12
12
 
@@ -6,7 +6,7 @@ import { WebSocketClientTransport } from '../transport/impls/ws/client.js';
6
6
  import { TransportClientId, TransportMessage, OpaqueTransportMessage, Transport, Connection } from '../transport/index.js';
7
7
  import { C as Codec } from '../types-3e5768ec.js';
8
8
  import { WebSocketServerTransport } from '../transport/impls/ws/server.js';
9
- import { P as PayloadType, R as RiverError, a as Procedure, S as ServiceContext, b as Result, c as RiverUncaughtSchema } from '../builder-3c4485f0.js';
9
+ import { P as PayloadType, R as RiverError, a as Procedure, S as ServiceContext, b as Result, c as RiverUncaughtSchema } from '../builder-87111051.js';
10
10
  import { Static } from '@sinclair/typebox';
11
11
  import '../connection-8e19874c.js';
12
12
 
@@ -1,6 +1,7 @@
1
1
  import {
2
- UNCAUGHT_ERROR
3
- } from "../chunk-7WJ6YLE5.js";
2
+ UNCAUGHT_ERROR,
3
+ pushable
4
+ } from "../chunk-IYRPZPSQ.js";
4
5
  import "../chunk-ORAG7IAU.js";
5
6
  import {
6
7
  WebSocketClientTransport
@@ -20,7 +21,6 @@ import "../chunk-SLUSVGQH.js";
20
21
  // util/testHelpers.ts
21
22
  import WebSocket from "isomorphic-ws";
22
23
  import { WebSocketServer } from "ws";
23
- import { pushable } from "it-pushable";
24
24
  async function createWebSocketServer(server) {
25
25
  return new WebSocketServer({ server });
26
26
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@replit/river",
3
3
  "description": "It's like tRPC but... with JSON Schema Support, duplex streaming and support for service multiplexing. Transport agnostic!",
4
- "version": "0.10.1",
4
+ "version": "0.10.3",
5
5
  "type": "module",
6
6
  "exports": {
7
7
  ".": {
@@ -45,12 +45,12 @@
45
45
  ],
46
46
  "dependencies": {
47
47
  "@msgpack/msgpack": "^3.0.0-beta2",
48
+ "it-pushable": "^3.2.3",
48
49
  "nanoid": "^4.0.2"
49
50
  },
50
51
  "peerDependencies": {
51
52
  "@sinclair/typebox": "^0.31.28",
52
53
  "isomorphic-ws": "^5.0.0",
53
- "it-pushable": "^3.2.1",
54
54
  "ws": "^8.13.0"
55
55
  },
56
56
  "devDependencies": {