mirror of
https://github.com/trezor/trezor-suite.git
synced 2026-03-21 14:47:12 +01:00
chore(connect): update @sinclair/typebox 0.31.28=>0.33.7
This commit is contained in:
committed by
Tomáš Martykán
parent
e3141139a9
commit
43ae2975b3
@@ -15,7 +15,7 @@
|
||||
"dependencies": {
|
||||
"@codemirror/state": "^6.4.1",
|
||||
"@hbsnow/rehype-sectionize": "^1.0.7",
|
||||
"@sinclair/typebox": "^0.31.28",
|
||||
"@sinclair/typebox": "^0.33.7",
|
||||
"@trezor/components": "workspace:^",
|
||||
"@trezor/connect": "workspace:^",
|
||||
"@trezor/connect-explorer-theme": "workspace:^",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
|
||||
import styled from 'styled-components';
|
||||
import { Type, TSchema } from '@sinclair/typebox';
|
||||
import { Object, type TSchema } from '@sinclair/typebox';
|
||||
|
||||
import { CollapsibleBox, Select, Switch, variables } from '@trezor/components';
|
||||
import { spacingsPx } from '@trezor/theme';
|
||||
@@ -108,7 +108,7 @@ export const ApiPlayground = ({ options }: ApiPlaygroundProps) => {
|
||||
actions.onSetMethod(option.legacyConfig);
|
||||
} else {
|
||||
const { method, schema } = option;
|
||||
actions.onSetSchema(method, schema ?? Type.Object({}));
|
||||
actions.onSetSchema(method, schema ?? Object({}));
|
||||
}
|
||||
}, [actions, options, selectedOption]);
|
||||
useEffect(() => {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import React from 'react';
|
||||
|
||||
import { Kind, Optional, TIntersect, TObject, TSchema } from '@sinclair/typebox';
|
||||
import { Kind, OptionalKind, TIntersect, TObject, TSchema } from '@sinclair/typebox';
|
||||
|
||||
import { Param } from './Param';
|
||||
import { getTypeName } from '../utils/getTypeName';
|
||||
@@ -54,7 +54,7 @@ const SingleParam = ({
|
||||
let isRequired: boolean | undefined;
|
||||
if (schema?.required?.includes(name)) {
|
||||
isRequired = true;
|
||||
} else if (value[Optional] === 'Optional') {
|
||||
} else if (value[OptionalKind] === 'Optional') {
|
||||
isRequired = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Optional, Kind, TSchema } from '@sinclair/typebox';
|
||||
import { TSchema, Kind, OptionalKind } from '@sinclair/typebox';
|
||||
|
||||
import type TrezorConnect from '@trezor/connect-web';
|
||||
|
||||
@@ -32,7 +32,7 @@ const schemaToFields = (schema: TSchema, name = ''): Field<any>[] => {
|
||||
const output = {
|
||||
...field,
|
||||
name: [key, field.name].filter(v => v).join('.'),
|
||||
optional: field.optional || schema[Optional] === 'Optional',
|
||||
optional: field.optional || schema[OptionalKind] === 'Optional',
|
||||
};
|
||||
// If the array is optional, set the items to an empty array by default
|
||||
if (output.type === 'array') {
|
||||
@@ -57,7 +57,7 @@ const schemaToFields = (schema: TSchema, name = ''): Field<any>[] => {
|
||||
fields,
|
||||
},
|
||||
],
|
||||
items: schema[Optional] === 'Optional' ? [] : [fields],
|
||||
items: schema[OptionalKind] === 'Optional' ? [] : [fields],
|
||||
},
|
||||
];
|
||||
} else if (schema[Kind] === 'Intersect') {
|
||||
@@ -75,7 +75,7 @@ const schemaToFields = (schema: TSchema, name = ''): Field<any>[] => {
|
||||
name: '',
|
||||
type: 'select',
|
||||
value: schema.default,
|
||||
optional: schema[Optional] === 'Optional',
|
||||
optional: schema[OptionalKind] === 'Optional',
|
||||
data: options.map((s: TSchema) => ({ label: s.const, value: s.const })),
|
||||
},
|
||||
];
|
||||
@@ -84,7 +84,7 @@ const schemaToFields = (schema: TSchema, name = ''): Field<any>[] => {
|
||||
if (schema.$id === 'DerivationPath' || schema.anyOf?.length == 1) {
|
||||
return schemaToFields(schema.anyOf[0]).map(field => ({
|
||||
...field,
|
||||
optional: field.optional || schema[Optional] === 'Optional',
|
||||
optional: field.optional || schema[OptionalKind] === 'Optional',
|
||||
value: !isFieldBasic(field) ? undefined : field.value ?? schema.default,
|
||||
}));
|
||||
} else if (schema.anyOf?.length > 1) {
|
||||
@@ -99,12 +99,12 @@ const schemaToFields = (schema: TSchema, name = ''): Field<any>[] => {
|
||||
field.value = field.value ?? schema.default;
|
||||
}
|
||||
if (array.length === 1) {
|
||||
field.optional = schema[Optional] === 'Optional';
|
||||
field.optional = schema[OptionalKind] === 'Optional';
|
||||
}
|
||||
|
||||
return field;
|
||||
}),
|
||||
optional: schema[Optional] === 'Optional',
|
||||
optional: schema[OptionalKind] === 'Optional',
|
||||
},
|
||||
];
|
||||
} else {
|
||||
@@ -119,7 +119,7 @@ const schemaToFields = (schema: TSchema, name = ''): Field<any>[] => {
|
||||
name: '',
|
||||
type: 'select',
|
||||
value: 'btc',
|
||||
optional: schema[Optional] === 'Optional',
|
||||
optional: schema[OptionalKind] === 'Optional',
|
||||
affect: 'path',
|
||||
data: coinsSelect.map(v => ({
|
||||
...v,
|
||||
@@ -142,7 +142,7 @@ const schemaToFields = (schema: TSchema, name = ''): Field<any>[] => {
|
||||
name: '',
|
||||
type: typeMap[schema[Kind]] ?? 'input',
|
||||
value: schema.default,
|
||||
optional: schema[Optional] === 'Optional',
|
||||
optional: schema[OptionalKind] === 'Optional',
|
||||
},
|
||||
];
|
||||
};
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
"tsx": "^4.16.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@sinclair/typebox": "^0.31.28",
|
||||
"@sinclair/typebox": "^0.33.7",
|
||||
"ts-mixer": "^6.0.3"
|
||||
},
|
||||
"peerDependencies": {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { TypeRegistry, Kind, TSchema, JavaScriptTypeBuilder } from '@sinclair/typebox';
|
||||
import { TypeRegistry, Kind, TSchema, JavaScriptTypeBuilder, CreateType } from '@sinclair/typebox';
|
||||
|
||||
export interface TArrayBuffer extends TSchema {
|
||||
[Kind]: 'ArrayBuffer';
|
||||
@@ -9,6 +9,6 @@ TypeRegistry.Set('ArrayBuffer', (_: TArrayBuffer, value: unknown) => value insta
|
||||
|
||||
export class ArrayBufferBuilder extends JavaScriptTypeBuilder {
|
||||
ArrayBuffer(options?: TSchema): TArrayBuffer {
|
||||
return this.Create({ ...options, [Kind]: 'ArrayBuffer', type: 'ArrayBuffer' });
|
||||
return CreateType({ [Kind]: 'ArrayBuffer', type: 'ArrayBuffer' }, options) as never;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { TypeRegistry, Kind, TSchema, JavaScriptTypeBuilder } from '@sinclair/typebox';
|
||||
import { TypeRegistry, Kind, TSchema, JavaScriptTypeBuilder, CreateType } from '@sinclair/typebox';
|
||||
|
||||
export interface TBuffer extends TSchema {
|
||||
[Kind]: 'Buffer';
|
||||
@@ -9,6 +9,6 @@ TypeRegistry.Set('Buffer', (_: TBuffer, value: unknown) => value instanceof Buff
|
||||
|
||||
export class BufferBuilder extends JavaScriptTypeBuilder {
|
||||
Buffer(options?: TSchema): TBuffer {
|
||||
return this.Create({ ...options, [Kind]: 'Buffer', type: 'Buffer' });
|
||||
return CreateType({ [Kind]: 'Buffer', type: 'Buffer' }, options) as never;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { TypeRegistry, Kind, TSchema, JavaScriptTypeBuilder } from '@sinclair/typebox';
|
||||
import { TypeRegistry, Kind, TSchema, JavaScriptTypeBuilder, CreateType } from '@sinclair/typebox';
|
||||
|
||||
export interface TUintOptions {
|
||||
allowNegative?: boolean;
|
||||
@@ -24,6 +24,6 @@ TypeRegistry.Set('Uint', (schema: TUint, value: unknown) => {
|
||||
|
||||
export class UintBuilder extends JavaScriptTypeBuilder {
|
||||
Uint(options?: TUintOptions): TUint {
|
||||
return this.Create({ ...options, [Kind]: 'Uint', type: 'Uint' });
|
||||
return CreateType({ [Kind]: 'Uint', type: 'Uint' }, options) as never;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,8 @@ import {
|
||||
TObject,
|
||||
Optional,
|
||||
Kind,
|
||||
TypeClone,
|
||||
OptionalKind,
|
||||
CloneType,
|
||||
} from '@sinclair/typebox';
|
||||
import { ValueErrorType, Errors, ValueError } from '@sinclair/typebox/errors';
|
||||
import { Mixin } from 'ts-mixer';
|
||||
@@ -75,7 +76,7 @@ export function Assert<T extends TSchema>(schema: T, value: unknown): asserts va
|
||||
while (error) {
|
||||
if (error.path === '/' && errors.length > 1) {
|
||||
// This might be a nested error, try to find the root cause
|
||||
} else if (error.value == null && error.schema[Optional] === 'Optional') {
|
||||
} else if (error.value == null && error.schema[OptionalKind] === 'Optional') {
|
||||
// Optional can also accept null values
|
||||
} else if (error.type === ValueErrorType.Union) {
|
||||
// Drill down into the union
|
||||
@@ -119,5 +120,5 @@ export function AssertWeak<T extends TSchema>(
|
||||
}
|
||||
|
||||
export const Type = new CustomTypeBuilder();
|
||||
export { Optional, TypeClone };
|
||||
export { Optional, CloneType };
|
||||
export type { Static, TObject, TSchema };
|
||||
|
||||
@@ -125,7 +125,7 @@ describe('complex-example', () => {
|
||||
a: 123,
|
||||
};
|
||||
expect(() => Assert(schema, invalidSchema4)).toThrow(
|
||||
'Invalid parameter "b" (= undefined): Required property',
|
||||
'Invalid parameter "b" (= undefined): Expected required property',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -36,7 +36,9 @@ describe('Assert', () => {
|
||||
try {
|
||||
Assert(schema, value);
|
||||
} catch (e) {
|
||||
expect(e.message).toEqual('Invalid parameter "type" (= undefined): Required property');
|
||||
expect(e.message).toEqual(
|
||||
'Invalid parameter "type" (= undefined): Expected required property',
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
11
yarn.lock
11
yarn.lock
@@ -8187,6 +8187,13 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@sinclair/typebox@npm:^0.33.7":
|
||||
version: 0.33.7
|
||||
resolution: "@sinclair/typebox@npm:0.33.7"
|
||||
checksum: 10/73d55197ccff7cd93e799cda37163d062e5985d4e03c21ab9d478258b2e2c84c3e19814dd3b31dccbbd01f71efb83800341611efa0e6ea17c77b6593915dbfe5
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@sindresorhus/is@npm:^4.0.0, @sindresorhus/is@npm:^4.6.0":
|
||||
version: 4.6.0
|
||||
resolution: "@sindresorhus/is@npm:4.6.0"
|
||||
@@ -11157,7 +11164,7 @@ __metadata:
|
||||
dependencies:
|
||||
"@codemirror/state": "npm:^6.4.1"
|
||||
"@hbsnow/rehype-sectionize": "npm:^1.0.7"
|
||||
"@sinclair/typebox": "npm:^0.31.28"
|
||||
"@sinclair/typebox": "npm:^0.33.7"
|
||||
"@trezor/components": "workspace:^"
|
||||
"@trezor/connect": "workspace:^"
|
||||
"@trezor/connect-explorer-theme": "workspace:^"
|
||||
@@ -11580,7 +11587,7 @@ __metadata:
|
||||
version: 0.0.0-use.local
|
||||
resolution: "@trezor/schema-utils@workspace:packages/schema-utils"
|
||||
dependencies:
|
||||
"@sinclair/typebox": "npm:^0.31.28"
|
||||
"@sinclair/typebox": "npm:^0.33.7"
|
||||
"@sinclair/typebox-codegen": "npm:^0.8.13"
|
||||
ts-mixer: "npm:^6.0.3"
|
||||
ts-node: "npm:^10.9.2"
|
||||
|
||||
Reference in New Issue
Block a user