@yuhere/js-jsonrpc2 2.1.12 → 2.1.14
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/dist/cli/cli.d.ts +0 -1
- package/dist/cli/cli.js +0 -1
- package/dist/cli/demo-methods.d.ts +0 -1
- package/dist/cli/demo-methods.js +0 -1
- package/dist/cli/express.d.ts +0 -1
- package/dist/cli/express.js +0 -1
- package/dist/cli/stdio.d.ts +0 -1
- package/dist/cli/stdio.js +0 -1
- package/dist/core/Repository.d.ts +0 -1
- package/dist/core/Repository.js +0 -1
- package/dist/core/convert.d.ts +0 -1
- package/dist/core/convert.js +0 -1
- package/dist/core/descriptor.d.ts +0 -1
- package/dist/core/descriptor.js +0 -1
- package/dist/core/index.d.ts +0 -1
- package/dist/core/index.js +0 -1
- package/dist/core/llm-tools.d.ts +0 -1
- package/dist/core/llm-tools.js +41 -43
- package/dist/core/permission.d.ts +0 -1
- package/dist/core/permission.js +0 -1
- package/dist/core/spec-check.d.ts +0 -1
- package/dist/core/spec-check.js +0 -1
- package/dist/core/system-methods.d.ts +0 -1
- package/dist/core/system-methods.js +0 -1
- package/dist/errors/RPCError.d.ts +0 -1
- package/dist/errors/RPCError.js +0 -1
- package/dist/errors/codes.d.ts +0 -1
- package/dist/errors/codes.js +0 -1
- package/dist/errors/index.d.ts +0 -1
- package/dist/errors/index.js +0 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/metrics/memory.d.ts +0 -1
- package/dist/metrics/memory.js +0 -1
- package/dist/metrics/prom.d.ts +0 -1
- package/dist/metrics/prom.js +0 -1
- package/dist/schema/json/index.d.ts +1 -2
- package/dist/schema/json/index.js +0 -1
- package/dist/schema/json/marker.d.ts +0 -1
- package/dist/schema/json/marker.js +0 -1
- package/dist/schema/json/primitives.d.ts +49 -70
- package/dist/schema/json/primitives.js +70 -77
- package/dist/schema/z/protocol.d.ts +1 -2
- package/dist/schema/z/protocol.js +0 -1
- package/dist/schema/z/register.d.ts +0 -1
- package/dist/schema/z/register.js +0 -1
- package/dist/stream/stringify-stream.d.ts +0 -1
- package/dist/stream/stringify-stream.js +94 -70
- package/dist/transport/express/body.d.ts +0 -1
- package/dist/transport/express/body.js +0 -1
- package/dist/transport/express/index.d.ts +0 -1
- package/dist/transport/express/index.js +0 -1
- package/dist/transport/express/middleware.d.ts +0 -1
- package/dist/transport/express/middleware.js +0 -1
- package/dist/transport/express/respond.d.ts +0 -1
- package/dist/transport/express/respond.js +0 -1
- package/dist/transport/stdio/index.d.ts +0 -1
- package/dist/transport/stdio/index.js +0 -1
- package/dist/transport/stdio/middleware.d.ts +0 -1
- package/dist/transport/stdio/middleware.js +0 -1
- package/dist/transport/ws/index.d.ts +0 -1
- package/dist/transport/ws/index.js +0 -1
- package/dist/transport/ws/middleware.d.ts +0 -1
- package/dist/transport/ws/middleware.js +0 -1
- package/dist/transport/ws/standalone.d.ts +0 -1
- package/dist/transport/ws/standalone.js +0 -1
- package/dist/types.d.ts +0 -1
- package/dist/types.js +0 -1
- package/dist/webclient/webui/src/client/httpTransport.d.ts +8 -0
- package/dist/webclient/webui/src/client/httpTransport.js +114 -0
- package/dist/webclient/webui/src/client/index.d.ts +4 -0
- package/dist/webclient/webui/src/client/index.js +2 -0
- package/dist/webclient/webui/src/client/rpc.d.ts +24 -0
- package/dist/webclient/webui/src/client/rpc.js +32 -0
- package/dist/webclient/webui/src/client/types.d.ts +14 -0
- package/dist/webclient/webui/src/client/types.js +1 -0
- package/dist/webclient/webui/src/client/wsTransport.d.ts +8 -0
- package/{webui/src/api/wsTransport.ts → dist/webclient/webui/src/client/wsTransport.js} +263 -305
- package/htdoc/assets/favicon-CXdFuLlv.png +0 -0
- package/{webui/src/styles/geek.css → htdoc/assets/index-Rq1yIwo2.css} +58 -0
- package/htdoc/assets/{index-Cr0Jnrgb.js → index-mYqtDOwe.js} +1344 -398
- package/htdoc/assets/index-mYqtDOwe.js.map +1 -0
- package/htdoc/index.html +4 -2
- package/package.json +10 -7
- package/dist/cli/cli.d.ts.map +0 -1
- package/dist/cli/cli.js.map +0 -1
- package/dist/cli/demo-methods.d.ts.map +0 -1
- package/dist/cli/demo-methods.js.map +0 -1
- package/dist/cli/express.d.ts.map +0 -1
- package/dist/cli/express.js.map +0 -1
- package/dist/cli/stdio.d.ts.map +0 -1
- package/dist/cli/stdio.js.map +0 -1
- package/dist/core/Repository.d.ts.map +0 -1
- package/dist/core/Repository.js.map +0 -1
- package/dist/core/convert.d.ts.map +0 -1
- package/dist/core/convert.js.map +0 -1
- package/dist/core/descriptor.d.ts.map +0 -1
- package/dist/core/descriptor.js.map +0 -1
- package/dist/core/index.d.ts.map +0 -1
- package/dist/core/index.js.map +0 -1
- package/dist/core/llm-tools.d.ts.map +0 -1
- package/dist/core/llm-tools.js.map +0 -1
- package/dist/core/permission.d.ts.map +0 -1
- package/dist/core/permission.js.map +0 -1
- package/dist/core/spec-check.d.ts.map +0 -1
- package/dist/core/spec-check.js.map +0 -1
- package/dist/core/system-methods.d.ts.map +0 -1
- package/dist/core/system-methods.js.map +0 -1
- package/dist/errors/RPCError.d.ts.map +0 -1
- package/dist/errors/RPCError.js.map +0 -1
- package/dist/errors/codes.d.ts.map +0 -1
- package/dist/errors/codes.js.map +0 -1
- package/dist/errors/index.d.ts.map +0 -1
- package/dist/errors/index.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/metrics/memory.d.ts.map +0 -1
- package/dist/metrics/memory.js.map +0 -1
- package/dist/metrics/prom.d.ts.map +0 -1
- package/dist/metrics/prom.js.map +0 -1
- package/dist/schema/json/index.d.ts.map +0 -1
- package/dist/schema/json/index.js.map +0 -1
- package/dist/schema/json/marker.d.ts.map +0 -1
- package/dist/schema/json/marker.js.map +0 -1
- package/dist/schema/json/primitives.d.ts.map +0 -1
- package/dist/schema/json/primitives.js.map +0 -1
- package/dist/schema/z/protocol.d.ts.map +0 -1
- package/dist/schema/z/protocol.js.map +0 -1
- package/dist/schema/z/register.d.ts.map +0 -1
- package/dist/schema/z/register.js.map +0 -1
- package/dist/stream/stringify-stream.d.ts.map +0 -1
- package/dist/stream/stringify-stream.js.map +0 -1
- package/dist/transport/express/body.d.ts.map +0 -1
- package/dist/transport/express/body.js.map +0 -1
- package/dist/transport/express/index.d.ts.map +0 -1
- package/dist/transport/express/index.js.map +0 -1
- package/dist/transport/express/middleware.d.ts.map +0 -1
- package/dist/transport/express/middleware.js.map +0 -1
- package/dist/transport/express/respond.d.ts.map +0 -1
- package/dist/transport/express/respond.js.map +0 -1
- package/dist/transport/stdio/index.d.ts.map +0 -1
- package/dist/transport/stdio/index.js.map +0 -1
- package/dist/transport/stdio/middleware.d.ts.map +0 -1
- package/dist/transport/stdio/middleware.js.map +0 -1
- package/dist/transport/ws/index.d.ts.map +0 -1
- package/dist/transport/ws/index.js.map +0 -1
- package/dist/transport/ws/middleware.d.ts.map +0 -1
- package/dist/transport/ws/middleware.js.map +0 -1
- package/dist/transport/ws/standalone.d.ts.map +0 -1
- package/dist/transport/ws/standalone.js.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js.map +0 -1
- package/htdoc/assets/index-Ck-39Igh.css +0 -963
- package/htdoc/assets/index-Cr0Jnrgb.js.map +0 -1
- package/webui/index.html +0 -12
- package/webui/src/App.tsx +0 -164
- package/webui/src/api/docGen.ts +0 -188
- package/webui/src/api/glob.ts +0 -90
- package/webui/src/api/httpTransport.ts +0 -148
- package/webui/src/api/metrics.ts +0 -135
- package/webui/src/api/paramForm.ts +0 -80
- package/webui/src/api/rpc.ts +0 -57
- package/webui/src/api/schema.ts +0 -12
- package/webui/src/api/types.ts +0 -16
- package/webui/src/components/MethodDetail.tsx +0 -43
- package/webui/src/components/MethodTree.tsx +0 -118
- package/webui/src/components/MetricsPanel.md +0 -126
- package/webui/src/components/MetricsPanel.tsx +0 -290
- package/webui/src/components/SchemaForm.tsx +0 -697
- package/webui/src/components/SchemaView.tsx +0 -151
- package/webui/src/components/TestPanel.tsx +0 -322
- package/webui/src/components/Toolbar.tsx +0 -82
- package/webui/src/hooks/useMethodDetail.ts +0 -61
- package/webui/src/hooks/useMethods.ts +0 -27
- package/webui/src/hooks/useMetrics.ts +0 -91
- package/webui/src/main.tsx +0 -13
- package/webui/src/theme/ThemeProvider.tsx +0 -79
- package/webui/src/vite-env.d.ts +0 -1
- package/webui/tsconfig.json +0 -34
- package/webui/tsconfig.node.json +0 -13
- package/webui/vite.config.ts +0 -15
package/dist/cli/cli.d.ts
CHANGED
package/dist/cli/cli.js
CHANGED
package/dist/cli/demo-methods.js
CHANGED
package/dist/cli/express.d.ts
CHANGED
package/dist/cli/express.js
CHANGED
package/dist/cli/stdio.d.ts
CHANGED
package/dist/cli/stdio.js
CHANGED
|
@@ -2,4 +2,3 @@ import { createRepository, serveStdio, s } from '../index.js';
|
|
|
2
2
|
const repository = createRepository();
|
|
3
3
|
repository.register({ namespace: 'echo', signature: [s.string(), s.string()] }, (v) => v);
|
|
4
4
|
await serveStdio({ repository, framing: 'lines' });
|
|
5
|
-
//# sourceMappingURL=stdio.js.map
|
package/dist/core/Repository.js
CHANGED
package/dist/core/convert.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import type { MethodDescriptor } from './descriptor.js';
|
|
2
2
|
import type { Injections } from '../types.js';
|
|
3
3
|
export declare function convertParams(descriptor: MethodDescriptor, params: unknown, injections: Injections): Promise<unknown[]>;
|
|
4
|
-
//# sourceMappingURL=convert.d.ts.map
|
package/dist/core/convert.js
CHANGED
|
@@ -24,4 +24,3 @@ export declare function buildDescriptor(descriptor: RPCDescriptor, fn: RPCHandle
|
|
|
24
24
|
export declare function signatureOf(descriptor: MethodDescriptor): unknown[];
|
|
25
25
|
export declare function lookup(methods: Map<string, MethodDescriptor>, method: string): MethodDescriptor;
|
|
26
26
|
export declare function invalidParams(message: string, data?: unknown): RPCError;
|
|
27
|
-
//# sourceMappingURL=descriptor.d.ts.map
|
package/dist/core/descriptor.js
CHANGED
package/dist/core/index.d.ts
CHANGED
package/dist/core/index.js
CHANGED
package/dist/core/llm-tools.d.ts
CHANGED
|
@@ -22,4 +22,3 @@ export interface JSONSchema {
|
|
|
22
22
|
}
|
|
23
23
|
export declare function listLlmTools(repository: Repository, injections: Injections, rawOptions?: unknown): Promise<LlmTools>;
|
|
24
24
|
export declare function invokeLlmTool(repository: Repository, call: LlmToolCall, injections: Injections): Promise<unknown>;
|
|
25
|
-
//# sourceMappingURL=llm-tools.d.ts.map
|
package/dist/core/llm-tools.js
CHANGED
|
@@ -50,12 +50,12 @@ function convert(desc) {
|
|
|
50
50
|
out.minItems = c.min;
|
|
51
51
|
if (c.max !== undefined)
|
|
52
52
|
out.maxItems = c.max;
|
|
53
|
-
out.items = convert(desc.
|
|
53
|
+
out.items = convert(desc.element);
|
|
54
54
|
break;
|
|
55
55
|
}
|
|
56
56
|
case 'tuple': {
|
|
57
57
|
out.type = 'array';
|
|
58
|
-
const items = desc.
|
|
58
|
+
const items = desc.elements;
|
|
59
59
|
out.items = items.map(convert);
|
|
60
60
|
out.minItems = items.length;
|
|
61
61
|
out.maxItems = items.length;
|
|
@@ -63,19 +63,19 @@ function convert(desc) {
|
|
|
63
63
|
}
|
|
64
64
|
case 'object': {
|
|
65
65
|
out.type = 'object';
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
66
|
+
const optional = new Set((desc.constraints
|
|
67
|
+
?.optionalProps) ?? []);
|
|
68
|
+
const allowUnknown = (desc.constraints
|
|
69
|
+
?.allowUnknownProps) ?? true;
|
|
70
|
+
const props = desc.properties;
|
|
69
71
|
out.properties = {};
|
|
70
72
|
for (const [k, v] of Object.entries(props))
|
|
71
73
|
out.properties[k] = convert(v);
|
|
72
|
-
|
|
73
|
-
|
|
74
|
+
const required = Object.keys(props).filter((k) => !optional.has(k));
|
|
75
|
+
if (required.length > 0)
|
|
76
|
+
out.required = required;
|
|
77
|
+
if (!allowUnknown)
|
|
74
78
|
out.additionalProperties = false;
|
|
75
|
-
}
|
|
76
|
-
else {
|
|
77
|
-
out.additionalProperties = true;
|
|
78
|
-
}
|
|
79
79
|
break;
|
|
80
80
|
}
|
|
81
81
|
case 'record': {
|
|
@@ -85,12 +85,11 @@ function convert(desc) {
|
|
|
85
85
|
out.minProperties = c.min;
|
|
86
86
|
if (c.max !== undefined)
|
|
87
87
|
out.maxProperties = c.max;
|
|
88
|
-
out.additionalProperties = convert(desc.
|
|
88
|
+
out.additionalProperties = convert(desc.value);
|
|
89
89
|
break;
|
|
90
90
|
}
|
|
91
91
|
case 'union': {
|
|
92
|
-
|
|
93
|
-
out.anyOf = options.map(convert);
|
|
92
|
+
out.anyOf = desc.options.map(convert);
|
|
94
93
|
break;
|
|
95
94
|
}
|
|
96
95
|
case 'unknown': {
|
|
@@ -101,8 +100,10 @@ function convert(desc) {
|
|
|
101
100
|
out.type = 'null';
|
|
102
101
|
break;
|
|
103
102
|
}
|
|
104
|
-
default:
|
|
105
|
-
|
|
103
|
+
default: {
|
|
104
|
+
const _exhaustive = desc;
|
|
105
|
+
throw new Error(`Unsupported schema kind for JSON Schema: ${JSON.stringify(_exhaustive)}`);
|
|
106
|
+
}
|
|
106
107
|
}
|
|
107
108
|
if (desc.nullable) {
|
|
108
109
|
if (desc.kind === 'unknown' || desc.kind === 'null') {
|
|
@@ -150,7 +151,6 @@ function renderSchema(schema, indent = 0) {
|
|
|
150
151
|
if (c)
|
|
151
152
|
head += ` \`${c}\``;
|
|
152
153
|
lines.push(head);
|
|
153
|
-
const ch = schema.children ?? {};
|
|
154
154
|
const pushChild = (label, child) => {
|
|
155
155
|
const sub = renderSchema(child, indent + 1);
|
|
156
156
|
if (sub.length) {
|
|
@@ -158,36 +158,35 @@ function renderSchema(schema, indent = 0) {
|
|
|
158
158
|
lines.push(...sub);
|
|
159
159
|
}
|
|
160
160
|
};
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
if (Array.isArray(ch.options)) {
|
|
173
|
-
ch.options.forEach((opt, i) => {
|
|
174
|
-
if (isSchema(opt))
|
|
175
|
-
pushChild(`option[${i}]`, opt);
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
if (ch.properties && typeof ch.properties === 'object') {
|
|
179
|
-
for (const [k, v] of Object.entries(ch.properties)) {
|
|
180
|
-
if (isSchema(v))
|
|
161
|
+
switch (schema.kind) {
|
|
162
|
+
case 'array': {
|
|
163
|
+
pushChild('element', schema.element);
|
|
164
|
+
break;
|
|
165
|
+
}
|
|
166
|
+
case 'record': {
|
|
167
|
+
pushChild('value', schema.value);
|
|
168
|
+
break;
|
|
169
|
+
}
|
|
170
|
+
case 'object': {
|
|
171
|
+
for (const [k, v] of Object.entries(schema.properties)) {
|
|
181
172
|
pushChild(k, v);
|
|
173
|
+
}
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
case 'union': {
|
|
177
|
+
schema.options.forEach((opt, i) => pushChild(`option[${i}]`, opt));
|
|
178
|
+
break;
|
|
182
179
|
}
|
|
180
|
+
case 'tuple': {
|
|
181
|
+
schema.elements.forEach((it, i) => pushChild(`[${i}]`, it));
|
|
182
|
+
break;
|
|
183
|
+
}
|
|
184
|
+
default:
|
|
185
|
+
// 叶子类型:无子节点。
|
|
186
|
+
break;
|
|
183
187
|
}
|
|
184
|
-
if (isSchema(ch.values))
|
|
185
|
-
pushChild('values', ch.values);
|
|
186
188
|
return lines;
|
|
187
189
|
}
|
|
188
|
-
function isSchema(v) {
|
|
189
|
-
return !!v && typeof v === 'object' && typeof v.kind === 'string';
|
|
190
|
-
}
|
|
191
190
|
/** 渲染返回值槽位(Schema / VoidMarker / StreamMarker)。 */
|
|
192
191
|
function renderReturnSlot(slot) {
|
|
193
192
|
if (slot instanceof VoidMarker)
|
|
@@ -309,4 +308,3 @@ export async function invokeLlmTool(repository, call, injections) {
|
|
|
309
308
|
})();
|
|
310
309
|
}
|
|
311
310
|
}
|
|
312
|
-
//# sourceMappingURL=llm-tools.js.map
|
|
@@ -2,4 +2,3 @@ import type { MethodDescriptor } from './descriptor.js';
|
|
|
2
2
|
import type { Injections } from '../types.js';
|
|
3
3
|
export declare function checkPermission(descriptor: MethodDescriptor, injections: Injections): Promise<void>;
|
|
4
4
|
export declare function assertAccessible(descriptor: MethodDescriptor, injections: Injections): Promise<void>;
|
|
5
|
-
//# sourceMappingURL=permission.d.ts.map
|
package/dist/core/permission.js
CHANGED
package/dist/core/spec-check.js
CHANGED
package/dist/errors/RPCError.js
CHANGED
package/dist/errors/codes.d.ts
CHANGED
package/dist/errors/codes.js
CHANGED
package/dist/errors/index.d.ts
CHANGED
package/dist/errors/index.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -15,4 +15,3 @@ export { attachWebSocket, createWebSocketServer, serveStdio };
|
|
|
15
15
|
export type { WSOptions, StandaloneWsOptions, StandaloneWsHandle } from './transport/ws/index.js';
|
|
16
16
|
export type { StdioOptions } from './transport/stdio/index.js';
|
|
17
17
|
export type { ExpressOptions } from './transport/express/index.js';
|
|
18
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -14,4 +14,3 @@ export { createExpressRouter };
|
|
|
14
14
|
import { attachWebSocket, createWebSocketServer } from './transport/ws/index.js';
|
|
15
15
|
import { serveStdio } from './transport/stdio/index.js';
|
|
16
16
|
export { attachWebSocket, createWebSocketServer, serveStdio };
|
|
17
|
-
//# sourceMappingURL=index.js.map
|
package/dist/metrics/memory.d.ts
CHANGED
package/dist/metrics/memory.js
CHANGED
package/dist/metrics/prom.d.ts
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=prom.d.ts.map
|
package/dist/metrics/prom.js
CHANGED
|
@@ -6,7 +6,7 @@ export declare const s: {
|
|
|
6
6
|
boolean: () => import("./primitives.js").BooleanSchema;
|
|
7
7
|
literal: <const T extends import("./primitives.js").LiteralValue>(value: T) => import("./primitives.js").LiteralSchema<T>;
|
|
8
8
|
array: <T>(item: import("./primitives.js").Schema<T>) => import("./primitives.js").ArraySchema<T>;
|
|
9
|
-
object: <S extends import("./primitives.js").ObjectShape>(shape: S) => import("./primitives.js").ObjectSchema<S
|
|
9
|
+
object: <S extends import("./primitives.js").ObjectShape>(shape: S) => import("./primitives.js").ObjectSchema<S>;
|
|
10
10
|
record: <T>(value: import("./primitives.js").Schema<T>) => import("./primitives.js").RecordSchema<T>;
|
|
11
11
|
union: <const S extends readonly [import("./primitives.js").Schema<unknown>, ...import("./primitives.js").Schema<unknown>[]]>(schemas: S) => import("./primitives.js").UnionSchema<S>;
|
|
12
12
|
tuple: <const S extends readonly [import("./primitives.js").Schema<unknown>, ...import("./primitives.js").Schema<unknown>[]]>(schemas: S) => import("./primitives.js").TupleSchema<S>;
|
|
@@ -17,4 +17,3 @@ export declare const s: {
|
|
|
17
17
|
injectable: <const K extends string>(key: K) => import("./marker.js").InjectableMarker<K>;
|
|
18
18
|
stream: <T>(inner: import("./primitives.js").Schema<T>) => import("./marker.js").StreamMarker<T>;
|
|
19
19
|
};
|
|
20
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -9,20 +9,36 @@ export type JSONValue = JSONPrimitive | JSONValue[] | {
|
|
|
9
9
|
[key: string]: JSONValue;
|
|
10
10
|
};
|
|
11
11
|
export type SchemaKind = string;
|
|
12
|
-
export interface
|
|
12
|
+
export interface BaseSchemaDescription {
|
|
13
13
|
kind: SchemaKind;
|
|
14
14
|
description?: string;
|
|
15
|
-
/**
|
|
16
|
-
* 该值是否允许为 null。
|
|
17
|
-
*
|
|
18
|
-
* 唯一真相来源:由 `NullableSchema` 及其子类通过 `.nullable(bool)` 设置,
|
|
19
|
-
* `UnknownSchema` / `NullSchema` 不使用该字段(它们本身就接受 null)。
|
|
20
|
-
* `kind` 永远表示值的真实形状,不会被 nullability 污染。
|
|
21
|
-
*/
|
|
22
15
|
nullable?: boolean;
|
|
23
16
|
constraints?: Record<string, unknown>;
|
|
24
|
-
children?: Record<string, unknown>;
|
|
25
17
|
}
|
|
18
|
+
export interface LeafSchemaDescription extends BaseSchemaDescription {
|
|
19
|
+
kind: "string" | "number" | "boolean" | "literal" | "enum" | "unknown" | "null";
|
|
20
|
+
}
|
|
21
|
+
export interface ObjectSchemaDescription extends BaseSchemaDescription {
|
|
22
|
+
kind: "object";
|
|
23
|
+
properties: Record<string, SchemaDescription>;
|
|
24
|
+
}
|
|
25
|
+
export interface ArraySchemaDescription extends BaseSchemaDescription {
|
|
26
|
+
kind: "array";
|
|
27
|
+
element: SchemaDescription;
|
|
28
|
+
}
|
|
29
|
+
export interface RecordSchemaDescription extends BaseSchemaDescription {
|
|
30
|
+
kind: "record";
|
|
31
|
+
value: SchemaDescription;
|
|
32
|
+
}
|
|
33
|
+
export interface UnionSchemaDescription extends BaseSchemaDescription {
|
|
34
|
+
kind: "union";
|
|
35
|
+
options: SchemaDescription[];
|
|
36
|
+
}
|
|
37
|
+
export interface TupleSchemaDescription extends BaseSchemaDescription {
|
|
38
|
+
kind: "tuple";
|
|
39
|
+
elements: SchemaDescription[];
|
|
40
|
+
}
|
|
41
|
+
export type SchemaDescription = LeafSchemaDescription | ObjectSchemaDescription | ArraySchemaDescription | RecordSchemaDescription | UnionSchemaDescription | TupleSchemaDescription;
|
|
26
42
|
export declare class SchemaValidationError extends Error {
|
|
27
43
|
readonly path: string[];
|
|
28
44
|
constructor(message: string, path?: string[]);
|
|
@@ -36,14 +52,13 @@ export declare class SchemaValidationError extends Error {
|
|
|
36
52
|
*/
|
|
37
53
|
export declare abstract class Schema<T> {
|
|
38
54
|
abstract readonly kind: SchemaKind;
|
|
39
|
-
private description
|
|
40
|
-
constructor(description?: string);
|
|
55
|
+
private description;
|
|
41
56
|
describe(description: string): this;
|
|
42
57
|
/**
|
|
43
58
|
* 创建保留原型和现有字段的新实例,供不可变链式方法使用。
|
|
44
59
|
*/
|
|
45
60
|
protected cloneWith(updates: Record<string, unknown>): this;
|
|
46
|
-
getDescription(): string
|
|
61
|
+
getDescription(): string;
|
|
47
62
|
parse(input: unknown): T;
|
|
48
63
|
safeParse(input: unknown): {
|
|
49
64
|
success: true;
|
|
@@ -84,7 +99,7 @@ export declare class StringSchema<K extends string = "string"> extends NullableS
|
|
|
84
99
|
min(value: number): this;
|
|
85
100
|
max(value: number): this;
|
|
86
101
|
protected _parseValue(input: unknown, path: string[]): string;
|
|
87
|
-
protected _describe():
|
|
102
|
+
protected _describe(): LeafSchemaDescription;
|
|
88
103
|
protected validateBound(value: number): void;
|
|
89
104
|
}
|
|
90
105
|
export declare class NumberSchema extends NullableSchema<number> {
|
|
@@ -95,28 +110,22 @@ export declare class NumberSchema extends NullableSchema<number> {
|
|
|
95
110
|
min(value: number): this;
|
|
96
111
|
max(value: number): this;
|
|
97
112
|
protected _parseValue(input: unknown, path: string[]): number;
|
|
98
|
-
protected _describe():
|
|
113
|
+
protected _describe(): LeafSchemaDescription;
|
|
99
114
|
protected validateBound(value: number): void;
|
|
100
115
|
}
|
|
101
116
|
export declare class BooleanSchema extends NullableSchema<boolean> {
|
|
102
117
|
readonly kind: "boolean";
|
|
103
118
|
constructor();
|
|
104
119
|
protected _parseValue(input: unknown, path: string[]): boolean;
|
|
105
|
-
protected _describe():
|
|
120
|
+
protected _describe(): LeafSchemaDescription;
|
|
106
121
|
}
|
|
107
|
-
/**
|
|
108
|
-
* 字面量只支持 string / number / boolean。
|
|
109
|
-
*
|
|
110
|
-
* null 由 `s.null()` 表达;需要「该字面量或 null」时,对字面量调用
|
|
111
|
-
* `.nullable()`。`literal(null)` 会抛 TypeError。
|
|
112
|
-
*/
|
|
113
122
|
export type LiteralValue = string | number | boolean;
|
|
114
123
|
export declare class LiteralSchema<const T extends LiteralValue> extends NullableSchema<T> {
|
|
115
124
|
private readonly expected;
|
|
116
125
|
readonly kind: "literal";
|
|
117
126
|
constructor(expected: T);
|
|
118
127
|
protected _parseValue(input: unknown, path: string[]): T;
|
|
119
|
-
protected _describe():
|
|
128
|
+
protected _describe(): LeafSchemaDescription;
|
|
120
129
|
}
|
|
121
130
|
export declare class ArraySchema<T> extends NullableSchema<T[]> {
|
|
122
131
|
private readonly itemSchema;
|
|
@@ -127,28 +136,25 @@ export declare class ArraySchema<T> extends NullableSchema<T[]> {
|
|
|
127
136
|
min(value: number): this;
|
|
128
137
|
max(value: number): this;
|
|
129
138
|
protected _parseValue(input: unknown, path: string[]): T[];
|
|
130
|
-
protected _describe():
|
|
139
|
+
protected _describe(): ArraySchemaDescription;
|
|
131
140
|
protected validateBound(value: number): void;
|
|
132
141
|
}
|
|
133
142
|
export type ObjectShape = Record<string, Schema<unknown>>;
|
|
134
143
|
type SchemaValue<S> = S extends Schema<infer T> ? T : never;
|
|
135
|
-
type
|
|
136
|
-
[K in keyof S]: SchemaValue<S[K]>;
|
|
137
|
-
};
|
|
138
|
-
type OptionalShapeOutput<S extends ObjectShape> = {
|
|
144
|
+
export type ObjectOutput<S extends ObjectShape> = {
|
|
139
145
|
[K in keyof S]?: SchemaValue<S[K]>;
|
|
140
146
|
};
|
|
141
|
-
export declare class ObjectSchema<S extends ObjectShape
|
|
147
|
+
export declare class ObjectSchema<S extends ObjectShape> extends NullableSchema<ObjectOutput<S>> {
|
|
142
148
|
private readonly shape;
|
|
143
149
|
readonly kind: "object";
|
|
144
|
-
private
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
strict():
|
|
150
|
-
protected _parseValue(input: unknown, path: string[]):
|
|
151
|
-
protected _describe():
|
|
150
|
+
private optionalProps;
|
|
151
|
+
private allowUnknownProps;
|
|
152
|
+
constructor(shape: S);
|
|
153
|
+
optionalProperties(keys: string[]): this;
|
|
154
|
+
allowUnknownProperties(value?: boolean): this;
|
|
155
|
+
strict(value?: boolean): this;
|
|
156
|
+
protected _parseValue(input: unknown, path: string[]): ObjectOutput<S>;
|
|
157
|
+
protected _describe(): ObjectSchemaDescription;
|
|
152
158
|
}
|
|
153
159
|
export declare class RecordSchema<T> extends NullableSchema<Record<string, T>> {
|
|
154
160
|
private readonly valueSchema;
|
|
@@ -159,68 +165,42 @@ export declare class RecordSchema<T> extends NullableSchema<Record<string, T>> {
|
|
|
159
165
|
min(value: number): this;
|
|
160
166
|
max(value: number): this;
|
|
161
167
|
protected _parseValue(input: unknown, path: string[]): Record<string, T>;
|
|
162
|
-
protected _describe():
|
|
168
|
+
protected _describe(): RecordSchemaDescription;
|
|
163
169
|
protected validateBound(value: number): void;
|
|
164
170
|
}
|
|
165
|
-
/**
|
|
166
|
-
* 联合。
|
|
167
|
-
*
|
|
168
|
-
* 传入的 member schemas 会被 clone 并 `nullable(false)`——因为「某个
|
|
169
|
-
* 分支允许 null」这件事在 union 层面没有意义:null 是否允许应通过
|
|
170
|
-
* `union(...).nullable()` 统一表达。
|
|
171
|
-
*/
|
|
172
171
|
export declare class UnionSchema<const S extends readonly [Schema<unknown>, ...Schema<unknown>[]]> extends NullableSchema<SchemaValue<S[number]>> {
|
|
173
172
|
readonly kind: "union";
|
|
174
173
|
private readonly options;
|
|
175
174
|
constructor(schemas: S);
|
|
176
175
|
protected _parseValue(input: unknown, path: string[]): SchemaValue<S[number]>;
|
|
177
|
-
protected _describe():
|
|
176
|
+
protected _describe(): UnionSchemaDescription;
|
|
178
177
|
}
|
|
179
178
|
export declare class TupleSchema<const S extends readonly [Schema<unknown>, ...Schema<unknown>[]]> extends NullableSchema<SchemaValue<S[number]>[]> {
|
|
180
179
|
private readonly schemas;
|
|
181
180
|
readonly kind: "tuple";
|
|
182
181
|
constructor(schemas: S);
|
|
183
182
|
protected _parseValue(input: unknown, path: string[]): SchemaValue<S[number]>[];
|
|
184
|
-
protected _describe():
|
|
183
|
+
protected _describe(): TupleSchemaDescription;
|
|
185
184
|
}
|
|
186
|
-
/**
|
|
187
|
-
* 字符串枚举。
|
|
188
|
-
*
|
|
189
|
-
* 继承 `NullableSchema`,因此可以 `s.enum([...]).nullable()`;
|
|
190
|
-
* 它不包含嵌套 schema,所以不需要像 union 那样处理成员 nullability。
|
|
191
|
-
*/
|
|
192
185
|
export declare class EnumSchema<const T extends readonly [string, ...string[]]> extends NullableSchema<T[number]> {
|
|
193
186
|
private readonly values;
|
|
194
187
|
readonly kind: "enum";
|
|
195
188
|
private readonly allowedValues;
|
|
196
189
|
constructor(values: T);
|
|
197
190
|
protected _parseValue(input: unknown, path: string[]): T[number];
|
|
198
|
-
protected _describe():
|
|
191
|
+
protected _describe(): LeafSchemaDescription;
|
|
199
192
|
}
|
|
200
|
-
/**
|
|
201
|
-
* 校验任意 JSON 值。
|
|
202
|
-
*
|
|
203
|
-
* 不允许 undefined、非有限数字、循环引用等非 JSON 数据。
|
|
204
|
-
* null 本身就在接受范围内,因此不继承 `NullableSchema`,也不提供
|
|
205
|
-
* `.nullable()`——那是冗余的。
|
|
206
|
-
*/
|
|
207
193
|
export declare class UnknownSchema extends Schema<JSONValue> {
|
|
208
194
|
readonly kind: "unknown";
|
|
209
195
|
constructor();
|
|
210
196
|
protected _parse(input: unknown, path: string[]): JSONValue;
|
|
211
|
-
protected _describe():
|
|
197
|
+
protected _describe(): LeafSchemaDescription;
|
|
212
198
|
}
|
|
213
|
-
/**
|
|
214
|
-
* 精确的 null 值。
|
|
215
|
-
*
|
|
216
|
-
* 与 `UnknownSchema` 一样天然表达 null,不需要 `.nullable()`。
|
|
217
|
-
* 想表达「某类型或 null」用 `.nullable()`;想表达「就是 null」用 `s.null()`。
|
|
218
|
-
*/
|
|
219
199
|
export declare class NullSchema extends Schema<null> {
|
|
220
200
|
readonly kind: "null";
|
|
221
201
|
constructor();
|
|
222
202
|
protected _parse(input: unknown, path: string[]): null;
|
|
223
|
-
protected _describe():
|
|
203
|
+
protected _describe(): LeafSchemaDescription;
|
|
224
204
|
}
|
|
225
205
|
export type Infer<T extends Schema<unknown>> = T extends Schema<infer U> ? U : never;
|
|
226
206
|
export declare const primitives: {
|
|
@@ -229,7 +209,7 @@ export declare const primitives: {
|
|
|
229
209
|
boolean: () => BooleanSchema;
|
|
230
210
|
literal: <const T extends LiteralValue>(value: T) => LiteralSchema<T>;
|
|
231
211
|
array: <T>(item: Schema<T>) => ArraySchema<T>;
|
|
232
|
-
object: <S extends ObjectShape>(shape: S) => ObjectSchema<S
|
|
212
|
+
object: <S extends ObjectShape>(shape: S) => ObjectSchema<S>;
|
|
233
213
|
record: <T>(value: Schema<T>) => RecordSchema<T>;
|
|
234
214
|
union: <const S extends readonly [Schema<unknown>, ...Schema<unknown>[]]>(schemas: S) => UnionSchema<S>;
|
|
235
215
|
tuple: <const S extends readonly [Schema<unknown>, ...Schema<unknown>[]]>(schemas: S) => TupleSchema<S>;
|
|
@@ -238,4 +218,3 @@ export declare const primitives: {
|
|
|
238
218
|
null: () => NullSchema;
|
|
239
219
|
};
|
|
240
220
|
export {};
|
|
241
|
-
//# sourceMappingURL=primitives.d.ts.map
|