@xxxaz/json-rpc-schema-typing 0.9.12 → 0.10.1
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.
- package/cjs/JsonRpcException.js +17 -7
- package/cjs/JsonRpcException.js.map +1 -1
- package/cjs/JsonRpcMethod.js +21 -4
- package/cjs/JsonRpcMethod.js.map +1 -1
- package/cjs/JsonRpcValidator.js +32 -17
- package/cjs/JsonRpcValidator.js.map +1 -1
- package/cjs/WebSocketWrapper.js +24 -3
- package/cjs/WebSocketWrapper.js.map +1 -1
- package/cjs/client/JsonRpcMessagePortClient.js +1 -1
- package/cjs/client/JsonRpcMessagePortClient.js.map +1 -1
- package/cjs/client/JsonRpcWebSocketClient.js +4 -0
- package/cjs/client/JsonRpcWebSocketClient.js.map +1 -1
- package/cjs/router/FileSystemRouter.js +20 -10
- package/cjs/router/FileSystemRouter.js.map +1 -1
- package/cjs/schemas/Complex.js +9 -0
- package/cjs/schemas/Complex.js.map +1 -1
- package/cjs/schemas/Structure.js +4 -15
- package/cjs/schemas/Structure.js.map +1 -1
- package/cjs/server/JsonRpcServer.js +1 -1
- package/cjs/server/JsonRpcServer.js.map +1 -1
- package/cjs/server/JsonRpcWebSocketReceiver.js +1 -1
- package/cjs/server/JsonRpcWebSocketReceiver.js.map +1 -1
- package/cjs/utility.js +1 -1
- package/cjs/utility.js.map +1 -1
- package/esm/JsonRpcMethod.js +21 -4
- package/esm/JsonRpcMethod.js.map +1 -1
- package/esm/JsonRpcValidator.js +32 -17
- package/esm/JsonRpcValidator.js.map +1 -1
- package/esm/WebSocketWrapper.js +24 -3
- package/esm/WebSocketWrapper.js.map +1 -1
- package/esm/client/JsonRpcMessagePortClient.js +1 -1
- package/esm/client/JsonRpcMessagePortClient.js.map +1 -1
- package/esm/client/JsonRpcWebSocketClient.js +4 -0
- package/esm/client/JsonRpcWebSocketClient.js.map +1 -1
- package/esm/router/FileSystemRouter.js +3 -3
- package/esm/router/FileSystemRouter.js.map +1 -1
- package/esm/schemas/Complex.js +8 -0
- package/esm/schemas/Complex.js.map +1 -1
- package/esm/schemas/Structure.js +2 -12
- package/esm/schemas/Structure.js.map +1 -1
- package/esm/server/JsonRpcServer.js +1 -1
- package/esm/server/JsonRpcServer.js.map +1 -1
- package/esm/server/JsonRpcWebSocketReceiver.js +1 -1
- package/esm/server/JsonRpcWebSocketReceiver.js.map +1 -1
- package/esm/utility.js +1 -1
- package/esm/utility.js.map +1 -1
- package/package.json +10 -9
- package/types/JsonRpcMethod.d.ts +42 -12
- package/types/JsonRpcValidator.d.ts +5 -3
- package/types/WebSocketWrapper.d.ts +3 -0
- package/types/client/JsonRpcClient.d.ts +2 -2
- package/types/router/JsonRpcRouter.d.ts +3 -3
- package/types/schemas/Complex.d.ts +6 -0
- package/types/schemas/Structure.d.ts +5 -18
- package/types/types.d.ts +18 -1
|
@@ -1,35 +1,22 @@
|
|
|
1
|
-
import {
|
|
2
|
-
declare const $optionalKey: unique symbol;
|
|
3
|
-
type OSchema = JSONSchema & {
|
|
4
|
-
[$optionalKey]?: true;
|
|
5
|
-
};
|
|
6
|
-
export declare function $Optional<T extends JSONSchema>(item: T): T | undefined;
|
|
7
|
-
export declare namespace $Optional {
|
|
8
|
-
var key: typeof $optionalKey;
|
|
9
|
-
var is: (item: JSONSchema | undefined) => item is OSchema;
|
|
10
|
-
}
|
|
1
|
+
import { IsOptionalSchema, JSONSchema, Max, RequiredKeys } from "../types.js";
|
|
11
2
|
export declare function $Array<T extends JSONSchema>(items: T): {
|
|
12
3
|
readonly type: "array";
|
|
13
4
|
readonly items: T;
|
|
14
5
|
};
|
|
15
|
-
type
|
|
16
|
-
type RequiredLength<T extends any[]> = ExcludeUndefined<[...T, undefined]>['length'];
|
|
6
|
+
export type ExcludeOptional<T extends any[]> = T extends [...infer A, infer L] ? IsOptionalSchema<L, ExcludeOptional<A>, T> : T;
|
|
17
7
|
export declare function $Tuple<T extends JSONSchema[]>(...items: T): {
|
|
18
8
|
readonly type: "array";
|
|
19
9
|
readonly items: T;
|
|
20
|
-
readonly minItems:
|
|
10
|
+
readonly minItems: ExcludeOptional<T>["length"];
|
|
21
11
|
readonly maxItems: Max<T["length"]>;
|
|
22
12
|
};
|
|
23
13
|
type ObjectDefine = {
|
|
24
|
-
[key: string]:
|
|
25
|
-
};
|
|
26
|
-
type Properties<T extends ObjectDefine> = {
|
|
27
|
-
[K in keyof T]: Exclude<T[K], undefined>;
|
|
14
|
+
[key: string]: JSONSchema;
|
|
28
15
|
};
|
|
29
16
|
export declare function $Object<T extends ObjectDefine>(properties: T): {
|
|
30
17
|
readonly type: "object";
|
|
31
18
|
readonly additionalProperties: false;
|
|
32
19
|
readonly required: [RequiredKeys<T>];
|
|
33
|
-
readonly properties:
|
|
20
|
+
readonly properties: T;
|
|
34
21
|
};
|
|
35
22
|
export {};
|
package/types/types.d.ts
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
|
-
import { type JSONSchema as ToTsSchema } from 'json-schema-to-ts';
|
|
1
|
+
import { FromSchema as ToTsFromSchema, type JSONSchema as ToTsSchema } from 'json-schema-to-ts';
|
|
2
2
|
import { type JsonSerializable } from "@xxxaz/stream-api-json";
|
|
3
|
+
export type TupleSchema<T extends JSONSchema[]> = {
|
|
4
|
+
type: 'array';
|
|
5
|
+
items: T;
|
|
6
|
+
minItems: number;
|
|
7
|
+
maxItems: number;
|
|
8
|
+
};
|
|
9
|
+
export type IsOptionalSchema<Sch, T, F> = false extends (Sch extends {
|
|
10
|
+
oneOf: readonly ToTsSchema[];
|
|
11
|
+
} ? Sch['oneOf'][number] : never) ? T : F;
|
|
12
|
+
type FromTuples<Schemas> = Schemas extends [infer Head extends JSONSchema, ...infer Tail] ? (IsOptionalSchema<Head, [
|
|
13
|
+
t?: ToTsFromSchema<Head>,
|
|
14
|
+
...FromTuples<Tail>
|
|
15
|
+
], [
|
|
16
|
+
ToTsFromSchema<Head>,
|
|
17
|
+
...FromTuples<Tail>
|
|
18
|
+
]>) : [];
|
|
19
|
+
export type FromSchema<T extends JSONSchema> = (T extends TupleSchema<infer U> ? FromTuples<U> : ToTsFromSchema<T>) | IsOptionalSchema<T, undefined, never>;
|
|
3
20
|
export type JSONSchema = ToTsSchema & object;
|
|
4
21
|
export type JsonRpcRequest = {
|
|
5
22
|
jsonrpc: '2.0';
|