Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 1 addition & 3 deletions __tests__/__snapshots__/serialize.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3199,9 +3199,7 @@ exports[`serialize service to jsonschema > serialize service with binary 1`] = `
},
"output": {
"properties": {
"contents": {
"type": "Uint8Array",
},
"contents": {},
},
"required": [
"contents",
Expand Down
2 changes: 1 addition & 1 deletion __tests__/cancellation.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TNever, TObject, Type } from '@sinclair/typebox';
import { TNever, TObject, Type } from 'typebox';
import { beforeEach, describe, expect, test, vi } from 'vitest';
import {
Err,
Expand Down
2 changes: 1 addition & 1 deletion __tests__/cleanup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
import { testMatrix } from '../testUtil/fixtures/matrix';
import { TestSetupHelpers } from '../testUtil/fixtures/transports';
import { ControlFlags } from '../transport/message';
import { Type } from '@sinclair/typebox';
import { Type } from 'typebox';
import { nanoid } from 'nanoid';

describe.each(testMatrix())(
Expand Down
2 changes: 1 addition & 1 deletion __tests__/context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
import { testMatrix } from '../testUtil/fixtures/matrix';
import { TestSetupHelpers } from '../testUtil/fixtures/transports';
import { Ok, Procedure, createClient, createServer } from '../router';
import { Type } from '@sinclair/typebox';
import { Type } from 'typebox';
import { createServiceSchema } from '../router/services';

describe('should handle incompatabilities', async () => {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/deferCleanup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
test,
vi,
} from 'vitest';
import { Type } from '@sinclair/typebox';
import { Type } from 'typebox';
import {
createClient,
createServer,
Expand Down
2 changes: 1 addition & 1 deletion __tests__/e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
waitFor,
} from '../testUtil/fixtures/cleanup';
import { testMatrix } from '../testUtil/fixtures/matrix';
import { Type } from '@sinclair/typebox';
import { Type } from 'typebox';
import {
Procedure,
createServiceSchema,
Expand Down
24 changes: 13 additions & 11 deletions __tests__/invalid-request.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Type } from '@sinclair/typebox';
import { Type } from 'typebox';
import { beforeEach, describe, expect, test, vi } from 'vitest';
import {
Err,
Expand Down Expand Up @@ -395,14 +395,13 @@ describe('cancels invalid request', () => {
code: INVALID_REQUEST_CODE,
message: 'message in requestData position did not match schema',
extras: {
totalErrors: 2,
totalErrors: 1,
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
firstValidationErrors: expect.arrayContaining([
{
path: '/mustSendThings',
message: 'Expected required property',
path: '',
message: 'must have required properties mustSendThings',
},
{ path: '/mustSendThings', message: 'Expected string' },
]),
},
}),
Expand Down Expand Up @@ -463,10 +462,14 @@ describe('cancels invalid request', () => {
code: INVALID_REQUEST_CODE,
message: 'message in control payload position did not match schema',
extras: {
totalErrors: 1,
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
totalErrors: expect.any(Number),
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
firstValidationErrors: expect.arrayContaining([
{ path: '', message: 'Expected union value' },
{
path: '',
message: 'must match a schema in anyOf',
},
]),
},
}),
Expand Down Expand Up @@ -597,14 +600,13 @@ describe('cancels invalid request', () => {
'message in requestData position did not match schema',
),
extras: {
totalErrors: 2,
totalErrors: 1,
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
firstValidationErrors: expect.arrayContaining([
{
path: '/newRequiredField',
message: 'Expected required property',
path: '',
message: 'must have required properties newRequiredField',
},
{ path: '/newRequiredField', message: 'Expected string' },
]),
},
}),
Expand Down
2 changes: 1 addition & 1 deletion __tests__/middleware.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
Middleware,
} from '../router';
import { createMockTransportNetwork } from '../testUtil/fixtures/mockTransport';
import { Type } from '@sinclair/typebox';
import { Type } from 'typebox';

describe('middleware test', () => {
let mockTransportNetwork: ReturnType<typeof createMockTransportNetwork>;
Expand Down
2 changes: 1 addition & 1 deletion __tests__/negative.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
handshakeRequestMessage,
} from '../transport/message';
import { NaiveJsonCodec } from '../codec';
import { Static } from '@sinclair/typebox';
import { Static } from 'typebox';
import { WebSocketClientTransport } from '../transport/impls/ws/client';
import { ProtocolError } from '../transport/events';
import NodeWs from 'ws';
Expand Down
2 changes: 1 addition & 1 deletion __tests__/serialize.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
TestServiceSchema,
} from '../testUtil/fixtures/services';
import { serializeSchema } from '../router';
import { Type } from '@sinclair/typebox';
import { Type } from 'typebox';

describe('serialize server to jsonschema', () => {
test('serialize entire service schema', () => {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/typescript-stress.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { assert, describe, expect, test } from 'vitest';
import { Procedure } from '../router/procedures';
import { createServiceSchema } from '../router/services';
import { Type } from '@sinclair/typebox';
import { Type } from 'typebox';
import { createServer } from '../router/server';
import { createClient } from '../router/client';
import {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/unserializable.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { beforeEach, describe, expect, test } from 'vitest';
import { Type } from '@sinclair/typebox';
import { Type } from 'typebox';
import {
Procedure,
createServiceSchema,
Expand Down
2 changes: 1 addition & 1 deletion codec/adapter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Value } from '@sinclair/typebox/value';
import { Value } from 'typebox/value';
import {
OpaqueTransportMessage,
OpaqueTransportMessageSchema,
Expand Down
29 changes: 15 additions & 14 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@
},
"peerDependencies": {
"@opentelemetry/api": "^1.7.0",
"@sinclair/typebox": "~0.34.0"
"typebox": "^1.1.0"
},
"devDependencies": {
"@bufbuild/buf": "^1.67.0",
"@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",
"typebox": "^1.1.38",
"@stylistic/eslint-plugin": "^2.6.4",
"@types/ws": "^8.5.5",
"@typescript-eslint/eslint-plugin": "^7.8.0",
Expand Down
2 changes: 1 addition & 1 deletion protobuf/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {
MessageInitShape,
MessageShape,
} from '@bufbuild/protobuf';
import { Value } from '@sinclair/typebox/value';
import { Value } from 'typebox/value';
import { ClientTransport } from '../transport/client';
import { Connection } from '../transport/connection';
import { EventMap } from '../transport/events';
Expand Down
18 changes: 12 additions & 6 deletions protobuf/handshake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type {
MessageInitShape,
MessageShape,
} from '@bufbuild/protobuf';
import { Static, Type } from '@sinclair/typebox';
import { type Static, Type } from 'typebox';
import {
createClientHandshakeOptions as createTransportClientHandshakeOptions,
createServerHandshakeOptions as createTransportServerHandshakeOptions,
Expand All @@ -13,11 +13,17 @@ import {
import { HandshakeErrorCustomHandlerFatalResponseCodes } from '../transport/message';
import { decodeMessageBytes, encodeMessageBytes } from './shared';

/**
* The handshake metadata for protobuf services travels as encoded protobuf bytes
* over River's existing handshake extension slot.
*/
const HandshakeBytesSchema = Type.Uint8Array();
class TUint8Array extends Type.Base<Uint8Array> {
Comment thread
jackyzha0 marked this conversation as resolved.
Outdated
public override Check(value: unknown): value is Uint8Array {
return value instanceof Uint8Array;
}

public override Clone(): TUint8Array {
return new TUint8Array();
}
}

const HandshakeBytesSchema = new TUint8Array();

type ProtobufHandshakeFailureCode = Static<
typeof HandshakeErrorCustomHandlerFatalResponseCodes
Expand Down
4 changes: 2 additions & 2 deletions protobuf/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import type {
MessageInitShape,
MessageShape,
} from '@bufbuild/protobuf';
import { TSchema } from '@sinclair/typebox';
import { Value } from '@sinclair/typebox/value';
import type { TSchema } from 'typebox';
import { Value } from 'typebox/value';
import { context as otelContext, trace, type Span } from '@opentelemetry/api';
import { Logger } from '../logging';
import { ServerHandshakeOptions } from '../router/handshake';
Expand Down
15 changes: 9 additions & 6 deletions router/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
closeStreamMessage,
cancelMessage,
} from '../transport/message';
import { Static } from '@sinclair/typebox';
import type { Static } from 'typebox';
import { Err, Result, AnyResultSchema } from './result';
import { EventMap } from '../transport/events';
import { Connection } from '../transport/connection';
Expand All @@ -28,7 +28,7 @@ import { ClientHandshakeOptions } from './handshake';
import { ClientTransport } from '../transport/client';
import { generateId } from '../transport/id';
import { Readable, ReadableImpl, Writable, WritableImpl } from './streams';
import { Value } from '@sinclair/typebox/value';
import { Value } from 'typebox/value';
import { PayloadType, ValidProcType } from './procedures';
import {
BaseErrorSchemaType,
Expand Down Expand Up @@ -450,9 +450,10 @@ function handleProc(
{
clientId: transport.clientId,
transportMessage: msg,
validationErrors: [
...Value.Errors(ReaderErrorResultSchema, msg.payload),
],
validationErrors: Value.Errors(
ReaderErrorResultSchema,
msg.payload,
).map((e) => ({ path: e.instancePath, message: e.message })),
},
);
}
Expand Down Expand Up @@ -487,7 +488,9 @@ function handleProc(
{
clientId: transport.clientId,
transportMessage: msg,
validationErrors: [...Value.Errors(AnyResultSchema, msg.payload)],
validationErrors: Value.Errors(AnyResultSchema, msg.payload).map(
(e) => ({ path: e.instancePath, message: e.message }),
),
},
);
}
Expand Down
2 changes: 1 addition & 1 deletion router/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { TransportClientId } from '../transport/message';
import { SessionId } from '../transport/sessionStateMachine/common';
import { ErrResult } from './result';
import { CancelErrorSchema } from './errors';
import { Static } from '@sinclair/typebox';
import type { Static } from 'typebox';

/**
* This is passed to every procedure handler and contains various context-level
Expand Down
Loading
Loading