Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions __tests__/invalid-request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,10 @@ describe('cancels invalid request', () => {
totalErrors: 2,
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
firstValidationErrors: expect.arrayContaining([
{ path: '/mustSendThings', message: 'Required property' },
{
path: '/mustSendThings',
message: 'Expected required property',
},
{ path: '/mustSendThings', message: 'Expected string' },
]),
},
Expand Down Expand Up @@ -595,7 +598,10 @@ describe('cancels invalid request', () => {
totalErrors: 2,
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
firstValidationErrors: expect.arrayContaining([
{ path: '/newRequiredField', message: 'Required property' },
{
path: '/newRequiredField',
message: 'Expected required property',
},
{ path: '/newRequiredField', message: 'Expected string' },
]),
},
Expand Down
28 changes: 15 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@replit/river",
"description": "It's like tRPC but... with JSON Schema Support, duplex streaming and support for service multiplexing. Transport agnostic!",
"version": "0.208.2",
"version": "0.208.3",
"type": "module",
"exports": {
".": {
Expand Down Expand Up @@ -54,12 +54,14 @@
},
"peerDependencies": {
"@opentelemetry/api": "^1.7.0",
"@sinclair/typebox": "~0.32.8 || ~0.34.0"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also add these peers to dev dependencies since they're used in tests..etc

"@sinclair/typebox": "~0.34.0"
},
"devDependencies": {
"@opentelemetry/api": "^1.7.0",
"@opentelemetry/context-async-hooks": "^1.26.0",
"@opentelemetry/core": "^1.7.0",
"@opentelemetry/sdk-trace-base": "^1.24.1",
"@sinclair/typebox": "~0.34.0",
"@stylistic/eslint-plugin": "^2.6.4",
"@types/ws": "^8.5.5",
"@typescript-eslint/eslint-plugin": "^7.8.0",
Expand Down
33 changes: 21 additions & 12 deletions router/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,15 @@ export interface SerializedServerSchemaProtocolv1 {
services: Record<string, SerializedServiceSchemaProtocolv1>;
}

/**
* Omits compositing symbols from this schema.
* The same approach that was previously used in the deprecated Type.Strict function.
* https://github.com/sinclairzx81/typebox/blob/master/changelog/0.34.0.md#strict
*/
export function Strict<T extends TSchema>(schema: T): T {
return JSON.parse(JSON.stringify(schema)) as T;
}

// TODO remove once clients migrate to v2
/**
* Same as {@link serializeSchema} but with a format that is compatible with
Expand All @@ -183,7 +192,7 @@ export function serializeSchemaV1Compat(
};

if (handshakeSchema) {
schema.handshakeSchema = Type.Strict(handshakeSchema);
schema.handshakeSchema = Strict(handshakeSchema);
}

return schema;
Expand Down Expand Up @@ -226,7 +235,7 @@ export function serializeSchema(
};

if (handshakeSchema) {
schema.handshakeSchema = Type.Strict(handshakeSchema);
schema.handshakeSchema = Strict(handshakeSchema);
}

return schema;
Expand Down Expand Up @@ -439,8 +448,8 @@ export class ServiceSchema<
Object.entries(this.procedures).map(([procName, procDef]) => [
procName,
{
init: Type.Strict(procDef.requestInit),
output: Type.Strict(procDef.responseData),
init: Strict(procDef.requestInit),
output: Strict(procDef.responseData),
errors: getSerializedProcErrors(procDef),
// Only add `description` field if the type declares it.
...('description' in procDef
Expand All @@ -450,7 +459,7 @@ export class ServiceSchema<
// Only add the `input` field if the type declares it.
...('requestData' in procDef
? {
input: Type.Strict(procDef.requestData),
input: Strict(procDef.requestData),
}
: {}),
},
Expand Down Expand Up @@ -479,8 +488,8 @@ export class ServiceSchema<
{
// BACKWARDS COMPAT: map init to input for protocolv1
// this is the only change needed to make it compatible.
input: Type.Strict(procDef.requestInit),
output: Type.Strict(procDef.responseData),
input: Strict(procDef.requestInit),
output: Strict(procDef.responseData),
errors: getSerializedProcErrors(procDef),
// Only add `description` field if the type declares it.
...('description' in procDef
Expand All @@ -496,15 +505,15 @@ export class ServiceSchema<
return [
procName,
{
init: Type.Strict(procDef.requestInit),
output: Type.Strict(procDef.responseData),
init: Strict(procDef.requestInit),
output: Strict(procDef.responseData),
errors: getSerializedProcErrors(procDef),
// Only add `description` field if the type declares it.
...('description' in procDef
? { description: procDef.description }
: {}),
type: procDef.type,
input: Type.Strict(procDef.requestData),
input: Strict(procDef.requestData),
},
];
},
Expand Down Expand Up @@ -541,14 +550,14 @@ function getSerializedProcErrors(
!('responseError' in procDef) ||
procDef.responseError[Kind] === 'Never'
) {
return Type.Strict(ReaderErrorSchema);
return Strict(ReaderErrorSchema);
}

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

return Type.Strict(withProtocolErrors);
return Strict(withProtocolErrors);
}

/**
Expand Down