Skip to content

Commit 1eca7c7

Browse files
Fix Typebox to ~0.34.0 (#315)
## Why There is no need support both `~0.32.8` and `~0.34.0`. We can just use `~0.34.0` ## What changed - Fix Typebox to `~0.34.0` - Handle breaking change in `0.34.0` where `Type.Strict()` is removed. <!-- Describe the changes you made in this pull request or pointers for the reviewer --> ## Versioning - [ ] Breaking protocol change - [ ] Breaking ts/js API change <!-- Kind reminder to add tests and updated documentation if needed -->
1 parent f44a0f8 commit 1eca7c7

File tree

4 files changed

+48
-29
lines changed

4 files changed

+48
-29
lines changed

__tests__/invalid-request.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,10 @@ describe('cancels invalid request', () => {
396396
totalErrors: 2,
397397
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
398398
firstValidationErrors: expect.arrayContaining([
399-
{ path: '/mustSendThings', message: 'Required property' },
399+
{
400+
path: '/mustSendThings',
401+
message: 'Expected required property',
402+
},
400403
{ path: '/mustSendThings', message: 'Expected string' },
401404
]),
402405
},
@@ -595,7 +598,10 @@ describe('cancels invalid request', () => {
595598
totalErrors: 2,
596599
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
597600
firstValidationErrors: expect.arrayContaining([
598-
{ path: '/newRequiredField', message: 'Required property' },
601+
{
602+
path: '/newRequiredField',
603+
message: 'Expected required property',
604+
},
599605
{ path: '/newRequiredField', message: 'Expected string' },
600606
]),
601607
},

package-lock.json

Lines changed: 15 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@replit/river",
33
"description": "It's like tRPC but... with JSON Schema Support, duplex streaming and support for service multiplexing. Transport agnostic!",
4-
"version": "0.208.2",
4+
"version": "0.208.3",
55
"type": "module",
66
"exports": {
77
".": {
@@ -54,12 +54,14 @@
5454
},
5555
"peerDependencies": {
5656
"@opentelemetry/api": "^1.7.0",
57-
"@sinclair/typebox": "~0.32.8 || ~0.34.0"
57+
"@sinclair/typebox": "~0.34.0"
5858
},
5959
"devDependencies": {
60+
"@opentelemetry/api": "^1.7.0",
6061
"@opentelemetry/context-async-hooks": "^1.26.0",
6162
"@opentelemetry/core": "^1.7.0",
6263
"@opentelemetry/sdk-trace-base": "^1.24.1",
64+
"@sinclair/typebox": "~0.34.0",
6365
"@stylistic/eslint-plugin": "^2.6.4",
6466
"@types/ws": "^8.5.5",
6567
"@typescript-eslint/eslint-plugin": "^7.8.0",

router/services.ts

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,15 @@ export interface SerializedServerSchemaProtocolv1 {
160160
services: Record<string, SerializedServiceSchemaProtocolv1>;
161161
}
162162

163+
/**
164+
* Omits compositing symbols from this schema.
165+
* The same approach that was previously used in the deprecated Type.Strict function.
166+
* https://github.com/sinclairzx81/typebox/blob/master/changelog/0.34.0.md#strict
167+
*/
168+
export function Strict<T extends TSchema>(schema: T): T {
169+
return JSON.parse(JSON.stringify(schema)) as T;
170+
}
171+
163172
// TODO remove once clients migrate to v2
164173
/**
165174
* Same as {@link serializeSchema} but with a format that is compatible with
@@ -183,7 +192,7 @@ export function serializeSchemaV1Compat(
183192
};
184193

185194
if (handshakeSchema) {
186-
schema.handshakeSchema = Type.Strict(handshakeSchema);
195+
schema.handshakeSchema = Strict(handshakeSchema);
187196
}
188197

189198
return schema;
@@ -226,7 +235,7 @@ export function serializeSchema(
226235
};
227236

228237
if (handshakeSchema) {
229-
schema.handshakeSchema = Type.Strict(handshakeSchema);
238+
schema.handshakeSchema = Strict(handshakeSchema);
230239
}
231240

232241
return schema;
@@ -439,8 +448,8 @@ export class ServiceSchema<
439448
Object.entries(this.procedures).map(([procName, procDef]) => [
440449
procName,
441450
{
442-
init: Type.Strict(procDef.requestInit),
443-
output: Type.Strict(procDef.responseData),
451+
init: Strict(procDef.requestInit),
452+
output: Strict(procDef.responseData),
444453
errors: getSerializedProcErrors(procDef),
445454
// Only add `description` field if the type declares it.
446455
...('description' in procDef
@@ -450,7 +459,7 @@ export class ServiceSchema<
450459
// Only add the `input` field if the type declares it.
451460
...('requestData' in procDef
452461
? {
453-
input: Type.Strict(procDef.requestData),
462+
input: Strict(procDef.requestData),
454463
}
455464
: {}),
456465
},
@@ -479,8 +488,8 @@ export class ServiceSchema<
479488
{
480489
// BACKWARDS COMPAT: map init to input for protocolv1
481490
// this is the only change needed to make it compatible.
482-
input: Type.Strict(procDef.requestInit),
483-
output: Type.Strict(procDef.responseData),
491+
input: Strict(procDef.requestInit),
492+
output: Strict(procDef.responseData),
484493
errors: getSerializedProcErrors(procDef),
485494
// Only add `description` field if the type declares it.
486495
...('description' in procDef
@@ -496,15 +505,15 @@ export class ServiceSchema<
496505
return [
497506
procName,
498507
{
499-
init: Type.Strict(procDef.requestInit),
500-
output: Type.Strict(procDef.responseData),
508+
init: Strict(procDef.requestInit),
509+
output: Strict(procDef.responseData),
501510
errors: getSerializedProcErrors(procDef),
502511
// Only add `description` field if the type declares it.
503512
...('description' in procDef
504513
? { description: procDef.description }
505514
: {}),
506515
type: procDef.type,
507-
input: Type.Strict(procDef.requestData),
516+
input: Strict(procDef.requestData),
508517
},
509518
];
510519
},
@@ -541,14 +550,14 @@ function getSerializedProcErrors(
541550
!('responseError' in procDef) ||
542551
procDef.responseError[Kind] === 'Never'
543552
) {
544-
return Type.Strict(ReaderErrorSchema);
553+
return Strict(ReaderErrorSchema);
545554
}
546555

547556
const withProtocolErrors = flattenErrorType(
548557
Type.Union([procDef.responseError, ReaderErrorSchema]),
549558
);
550559

551-
return Type.Strict(withProtocolErrors);
560+
return Strict(withProtocolErrors);
552561
}
553562

554563
/**

0 commit comments

Comments
 (0)