@replit/river 0.208.2 → 0.208.4

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.
@@ -117,6 +117,9 @@ function flattenErrorType(errType) {
117
117
  }
118
118
 
119
119
  // router/services.ts
120
+ function Strict(schema) {
121
+ return JSON.parse(JSON.stringify(schema));
122
+ }
120
123
  function serializeSchemaV1Compat(services, handshakeSchema) {
121
124
  const serializedServiceObject = Object.entries(services).reduce((acc, [name, value]) => {
122
125
  acc[name] = value.serializeV1Compat();
@@ -126,7 +129,7 @@ function serializeSchemaV1Compat(services, handshakeSchema) {
126
129
  services: serializedServiceObject
127
130
  };
128
131
  if (handshakeSchema) {
129
- schema.handshakeSchema = import_typebox2.Type.Strict(handshakeSchema);
132
+ schema.handshakeSchema = Strict(handshakeSchema);
130
133
  }
131
134
  return schema;
132
135
  }
@@ -139,7 +142,7 @@ function serializeSchema(services, handshakeSchema) {
139
142
  services: serializedServiceObject
140
143
  };
141
144
  if (handshakeSchema) {
142
- schema.handshakeSchema = import_typebox2.Type.Strict(handshakeSchema);
145
+ schema.handshakeSchema = Strict(handshakeSchema);
143
146
  }
144
147
  return schema;
145
148
  }
@@ -242,15 +245,15 @@ var ServiceSchema = class _ServiceSchema {
242
245
  Object.entries(this.procedures).map(([procName, procDef]) => [
243
246
  procName,
244
247
  {
245
- init: import_typebox2.Type.Strict(procDef.requestInit),
246
- output: import_typebox2.Type.Strict(procDef.responseData),
248
+ init: Strict(procDef.requestInit),
249
+ output: Strict(procDef.responseData),
247
250
  errors: getSerializedProcErrors(procDef),
248
251
  // Only add `description` field if the type declares it.
249
252
  ..."description" in procDef ? { description: procDef.description } : {},
250
253
  type: procDef.type,
251
254
  // Only add the `input` field if the type declares it.
252
255
  ..."requestData" in procDef ? {
253
- input: import_typebox2.Type.Strict(procDef.requestData)
256
+ input: Strict(procDef.requestData)
254
257
  } : {}
255
258
  }
256
259
  ])
@@ -274,8 +277,8 @@ var ServiceSchema = class _ServiceSchema {
274
277
  {
275
278
  // BACKWARDS COMPAT: map init to input for protocolv1
276
279
  // this is the only change needed to make it compatible.
277
- input: import_typebox2.Type.Strict(procDef.requestInit),
278
- output: import_typebox2.Type.Strict(procDef.responseData),
280
+ input: Strict(procDef.requestInit),
281
+ output: Strict(procDef.responseData),
279
282
  errors: getSerializedProcErrors(procDef),
280
283
  // Only add `description` field if the type declares it.
281
284
  ..."description" in procDef ? { description: procDef.description } : {},
@@ -286,13 +289,13 @@ var ServiceSchema = class _ServiceSchema {
286
289
  return [
287
290
  procName,
288
291
  {
289
- init: import_typebox2.Type.Strict(procDef.requestInit),
290
- output: import_typebox2.Type.Strict(procDef.responseData),
292
+ init: Strict(procDef.requestInit),
293
+ output: Strict(procDef.responseData),
291
294
  errors: getSerializedProcErrors(procDef),
292
295
  // Only add `description` field if the type declares it.
293
296
  ..."description" in procDef ? { description: procDef.description } : {},
294
297
  type: procDef.type,
295
- input: import_typebox2.Type.Strict(procDef.requestData)
298
+ input: Strict(procDef.requestData)
296
299
  }
297
300
  ];
298
301
  }
@@ -321,12 +324,12 @@ var ServiceSchema = class _ServiceSchema {
321
324
  };
322
325
  function getSerializedProcErrors(procDef) {
323
326
  if (!("responseError" in procDef) || procDef.responseError[import_typebox2.Kind] === "Never") {
324
- return import_typebox2.Type.Strict(ReaderErrorSchema);
327
+ return Strict(ReaderErrorSchema);
325
328
  }
326
329
  const withProtocolErrors = flattenErrorType(
327
330
  import_typebox2.Type.Union([procDef.responseError, ReaderErrorSchema])
328
331
  );
329
- return import_typebox2.Type.Strict(withProtocolErrors);
332
+ return Strict(withProtocolErrors);
330
333
  }
331
334
  var ServiceScaffold = class {
332
335
  /**
@@ -961,6 +964,9 @@ function createClient(transport, serverId, providedClientOptions = {}) {
961
964
  }, []);
962
965
  }
963
966
  function handleProc(procType, transport, serverId, init, serviceName, procedureName, abortSignal) {
967
+ if (transport.getStatus() === "closed") {
968
+ return getPreClosedReturnForProc(procType);
969
+ }
964
970
  const session = transport.sessions.get(serverId) ?? transport.createUnconnectedSession(serverId);
965
971
  const sessionScopedSend = transport.getSessionBoundSendFn(
966
972
  serverId,
@@ -1137,13 +1143,33 @@ function handleProc(procType, transport, serverId, init, serviceName, procedureN
1137
1143
  if (procClosesWithInit) {
1138
1144
  reqWritable.close();
1139
1145
  }
1146
+ return getReturnForProc(procType, resReadable, reqWritable, transport.log);
1147
+ }
1148
+ function getPreClosedReturnForProc(procType) {
1149
+ const readable = new ReadableImpl();
1150
+ const err = Err({
1151
+ code: UNEXPECTED_DISCONNECT_CODE,
1152
+ message: `transport is closed`
1153
+ });
1154
+ readable._pushValue(err);
1155
+ readable._triggerClose();
1156
+ const writable = new WritableImpl({
1157
+ writeCb: () => {
1158
+ },
1159
+ closeCb: () => {
1160
+ }
1161
+ });
1162
+ writable.close();
1163
+ return getReturnForProc(procType, readable, writable);
1164
+ }
1165
+ function getReturnForProc(procType, resReadable, reqWritable, log) {
1140
1166
  if (procType === "subscription") {
1141
1167
  return {
1142
1168
  resReadable
1143
1169
  };
1144
1170
  }
1145
1171
  if (procType === "rpc") {
1146
- return getSingleMessage(resReadable, transport.log);
1172
+ return getSingleMessage(resReadable, log);
1147
1173
  }
1148
1174
  if (procType === "upload") {
1149
1175
  let didFinalize = false;
@@ -1157,7 +1183,7 @@ function handleProc(procType, transport, serverId, init, serviceName, procedureN
1157
1183
  if (!reqWritable.isClosed()) {
1158
1184
  reqWritable.close();
1159
1185
  }
1160
- return getSingleMessage(resReadable, transport.log);
1186
+ return getSingleMessage(resReadable, log);
1161
1187
  }
1162
1188
  };
1163
1189
  }
@@ -1892,7 +1918,7 @@ function createServerHandshakeOptions(schema, validate) {
1892
1918
  }
1893
1919
 
1894
1920
  // package.json
1895
- var version = "0.208.2";
1921
+ var version = "0.208.4";
1896
1922
  // Annotate the CommonJS export names for ESM import in node:
1897
1923
  0 && (module.exports = {
1898
1924
  CANCEL_CODE,