fix: 修复TypeScript配置错误并更新项目文档
详细说明: - 修复了@n8n/config包的TypeScript配置错误 - 移除了不存在的jest-expect-message类型引用 - 清理了所有TypeScript构建缓存 - 更新了可行性分析文档,添加了技术实施方案 - 更新了Agent prompt文档 - 添加了会展策划工作流文档 - 包含了n8n-chinese-translation子项目 - 添加了exhibition-demo展示系统框架
This commit is contained in:
2
n8n-n8n-1.109.2/packages/@n8n/json-schema-to-zod/src/index 2.ts
Executable file
2
n8n-n8n-1.109.2/packages/@n8n/json-schema-to-zod/src/index 2.ts
Executable file
@@ -0,0 +1,2 @@
|
||||
export type * from './types';
|
||||
export { jsonSchemaToZod } from './json-schema-to-zod';
|
||||
15
n8n-n8n-1.109.2/packages/@n8n/json-schema-to-zod/src/json-schema-to-zod 2.ts
Executable file
15
n8n-n8n-1.109.2/packages/@n8n/json-schema-to-zod/src/json-schema-to-zod 2.ts
Executable file
@@ -0,0 +1,15 @@
|
||||
import type { z } from 'zod';
|
||||
|
||||
import { parseSchema } from './parsers/parse-schema';
|
||||
import type { JsonSchemaToZodOptions, JsonSchema } from './types';
|
||||
|
||||
export const jsonSchemaToZod = <T extends z.ZodTypeAny = z.ZodTypeAny>(
|
||||
schema: JsonSchema,
|
||||
options: JsonSchemaToZodOptions = {},
|
||||
): T => {
|
||||
return parseSchema(schema, {
|
||||
path: [],
|
||||
seen: new Map(),
|
||||
...options,
|
||||
}) as T;
|
||||
};
|
||||
82
n8n-n8n-1.109.2/packages/@n8n/json-schema-to-zod/src/types 2.ts
Executable file
82
n8n-n8n-1.109.2/packages/@n8n/json-schema-to-zod/src/types 2.ts
Executable file
@@ -0,0 +1,82 @@
|
||||
import type { ZodTypeAny } from 'zod';
|
||||
|
||||
export type Serializable =
|
||||
| { [key: string]: Serializable }
|
||||
| Serializable[]
|
||||
| string
|
||||
| number
|
||||
| boolean
|
||||
| null;
|
||||
|
||||
export type JsonSchema = JsonSchemaObject | boolean;
|
||||
export type JsonSchemaObject = {
|
||||
// left permissive by design
|
||||
type?: string | string[];
|
||||
|
||||
// object
|
||||
properties?: { [key: string]: JsonSchema };
|
||||
additionalProperties?: JsonSchema;
|
||||
unevaluatedProperties?: JsonSchema;
|
||||
patternProperties?: { [key: string]: JsonSchema };
|
||||
minProperties?: number;
|
||||
maxProperties?: number;
|
||||
required?: string[] | boolean;
|
||||
propertyNames?: JsonSchema;
|
||||
|
||||
// array
|
||||
items?: JsonSchema | JsonSchema[];
|
||||
additionalItems?: JsonSchema;
|
||||
minItems?: number;
|
||||
maxItems?: number;
|
||||
uniqueItems?: boolean;
|
||||
|
||||
// string
|
||||
minLength?: number;
|
||||
maxLength?: number;
|
||||
pattern?: string;
|
||||
format?: string;
|
||||
|
||||
// number
|
||||
minimum?: number;
|
||||
maximum?: number;
|
||||
exclusiveMinimum?: number | boolean;
|
||||
exclusiveMaximum?: number | boolean;
|
||||
multipleOf?: number;
|
||||
|
||||
// unions
|
||||
anyOf?: JsonSchema[];
|
||||
allOf?: JsonSchema[];
|
||||
oneOf?: JsonSchema[];
|
||||
|
||||
if?: JsonSchema;
|
||||
then?: JsonSchema;
|
||||
else?: JsonSchema;
|
||||
|
||||
// shared
|
||||
const?: Serializable;
|
||||
enum?: Serializable[];
|
||||
|
||||
errorMessage?: { [key: string]: string | undefined };
|
||||
|
||||
description?: string;
|
||||
default?: Serializable;
|
||||
readOnly?: boolean;
|
||||
not?: JsonSchema;
|
||||
contentEncoding?: string;
|
||||
nullable?: boolean;
|
||||
};
|
||||
|
||||
export type ParserSelector = (schema: JsonSchemaObject, refs: Refs) => ZodTypeAny;
|
||||
export type ParserOverride = (schema: JsonSchemaObject, refs: Refs) => ZodTypeAny | undefined;
|
||||
|
||||
export type JsonSchemaToZodOptions = {
|
||||
withoutDefaults?: boolean;
|
||||
withoutDescribes?: boolean;
|
||||
parserOverride?: ParserOverride;
|
||||
depth?: number;
|
||||
};
|
||||
|
||||
export type Refs = JsonSchemaToZodOptions & {
|
||||
path: Array<string | number>;
|
||||
seen: Map<object | boolean, { n: number; r: ZodTypeAny | undefined }>;
|
||||
};
|
||||
143
n8n-n8n-1.109.2/packages/@n8n/json-schema-to-zod/test/all 2.json
Executable file
143
n8n-n8n-1.109.2/packages/@n8n/json-schema-to-zod/test/all 2.json
Executable file
@@ -0,0 +1,143 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema",
|
||||
"properties": {
|
||||
"allOf": {
|
||||
"allOf": [
|
||||
{
|
||||
"type": "boolean"
|
||||
},
|
||||
{
|
||||
"type": "number"
|
||||
},
|
||||
{
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
"anyOf": {
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "boolean"
|
||||
},
|
||||
{
|
||||
"type": "number"
|
||||
},
|
||||
{
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
"oneOf": {
|
||||
"oneOf": [
|
||||
{
|
||||
"type": "boolean"
|
||||
},
|
||||
{
|
||||
"type": "number"
|
||||
},
|
||||
{
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
"array": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"minItems": 2,
|
||||
"maxItems": 3
|
||||
},
|
||||
"tuple": {
|
||||
"type": "array",
|
||||
"items": [
|
||||
{
|
||||
"type": "boolean"
|
||||
},
|
||||
{
|
||||
"type": "number"
|
||||
},
|
||||
{
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"minItems": 2,
|
||||
"maxItems": 3
|
||||
},
|
||||
"const": {
|
||||
"const": "xbox"
|
||||
},
|
||||
"enum": {
|
||||
"enum": ["ps4", "ps5"]
|
||||
},
|
||||
"ifThenElse": {
|
||||
"if": {
|
||||
"type": "string"
|
||||
},
|
||||
"then": {
|
||||
"const": "x"
|
||||
},
|
||||
"else": {
|
||||
"enum": [1, 2, 3]
|
||||
}
|
||||
},
|
||||
"null": {
|
||||
"type": "null"
|
||||
},
|
||||
"multiple": {
|
||||
"type": ["array", "boolean"]
|
||||
},
|
||||
"objAdditionalTrue": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"x": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"additionalProperties": true
|
||||
},
|
||||
"objAdditionalFalse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"x": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
},
|
||||
"objAdditionalNumber": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"x": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"additionalProperties": {
|
||||
"type": "number"
|
||||
}
|
||||
},
|
||||
"objAdditionalOnly": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"type": "number"
|
||||
}
|
||||
},
|
||||
"patternProps": {
|
||||
"type": "object",
|
||||
"patternProperties": {
|
||||
"^x": {
|
||||
"type": "string"
|
||||
},
|
||||
"^y": {
|
||||
"type": "number"
|
||||
}
|
||||
},
|
||||
"properties": {
|
||||
"z": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
}
|
||||
16
n8n-n8n-1.109.2/packages/@n8n/json-schema-to-zod/test/extend-expect 2.ts
Executable file
16
n8n-n8n-1.109.2/packages/@n8n/json-schema-to-zod/test/extend-expect 2.ts
Executable file
@@ -0,0 +1,16 @@
|
||||
import type { z } from 'zod';
|
||||
|
||||
expect.extend({
|
||||
toMatchZod(this: jest.MatcherContext, actual: z.ZodTypeAny, expected: z.ZodTypeAny) {
|
||||
const actualSerialized = JSON.stringify(actual._def, null, 2);
|
||||
const expectedSerialized = JSON.stringify(expected._def, null, 2);
|
||||
const pass = this.equals(actualSerialized, expectedSerialized);
|
||||
|
||||
return {
|
||||
pass,
|
||||
message: pass
|
||||
? () => `Expected ${actualSerialized} not to match ${expectedSerialized}`
|
||||
: () => `Expected ${actualSerialized} to match ${expectedSerialized}`,
|
||||
};
|
||||
},
|
||||
});
|
||||
5
n8n-n8n-1.109.2/packages/@n8n/json-schema-to-zod/test/jest.d 2.ts
Executable file
5
n8n-n8n-1.109.2/packages/@n8n/json-schema-to-zod/test/jest.d 2.ts
Executable file
@@ -0,0 +1,5 @@
|
||||
namespace jest {
|
||||
interface Matchers<R, T> {
|
||||
toMatchZod(expected: unknown): T;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
import type { JSONSchema4, JSONSchema6Definition, JSONSchema7Definition } from 'json-schema';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { jsonSchemaToZod } from '../src';
|
||||
|
||||
describe('jsonSchemaToZod', () => {
|
||||
test('should accept json schema 7 and 4', () => {
|
||||
const schema = { type: 'string' } as unknown;
|
||||
|
||||
expect(jsonSchemaToZod(schema as JSONSchema4));
|
||||
expect(jsonSchemaToZod(schema as JSONSchema6Definition));
|
||||
expect(jsonSchemaToZod(schema as JSONSchema7Definition));
|
||||
});
|
||||
|
||||
test('can exclude defaults', () => {
|
||||
expect(
|
||||
jsonSchemaToZod(
|
||||
{
|
||||
type: 'string',
|
||||
default: 'foo',
|
||||
},
|
||||
{ withoutDefaults: true },
|
||||
),
|
||||
).toMatchZod(z.string());
|
||||
});
|
||||
|
||||
test('should include describes', () => {
|
||||
expect(
|
||||
jsonSchemaToZod({
|
||||
type: 'string',
|
||||
description: 'foo',
|
||||
}),
|
||||
).toMatchZod(z.string().describe('foo'));
|
||||
});
|
||||
|
||||
test('can exclude describes', () => {
|
||||
expect(
|
||||
jsonSchemaToZod(
|
||||
{
|
||||
type: 'string',
|
||||
description: 'foo',
|
||||
},
|
||||
{
|
||||
withoutDescribes: true,
|
||||
},
|
||||
),
|
||||
).toMatchZod(z.string());
|
||||
});
|
||||
|
||||
test('will remove optionality if default is present', () => {
|
||||
expect(
|
||||
jsonSchemaToZod({
|
||||
type: 'object',
|
||||
properties: {
|
||||
prop: {
|
||||
type: 'string',
|
||||
default: 'def',
|
||||
},
|
||||
},
|
||||
}),
|
||||
).toMatchZod(z.object({ prop: z.string().default('def') }));
|
||||
});
|
||||
|
||||
test('will handle falsy defaults', () => {
|
||||
expect(
|
||||
jsonSchemaToZod({
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
}),
|
||||
).toMatchZod(z.boolean().default(false));
|
||||
});
|
||||
|
||||
test('will ignore undefined as default', () => {
|
||||
expect(
|
||||
jsonSchemaToZod({
|
||||
type: 'null',
|
||||
default: undefined,
|
||||
}),
|
||||
).toMatchZod(z.null());
|
||||
});
|
||||
|
||||
test('should be possible to define a custom parser', () => {
|
||||
expect(
|
||||
jsonSchemaToZod(
|
||||
{
|
||||
allOf: [{ type: 'string' }, { type: 'number' }, { type: 'boolean', description: 'foo' }],
|
||||
},
|
||||
{
|
||||
parserOverride: (schema, refs) => {
|
||||
if (
|
||||
refs.path.length === 2 &&
|
||||
refs.path[0] === 'allOf' &&
|
||||
refs.path[1] === 2 &&
|
||||
schema.type === 'boolean' &&
|
||||
schema.description === 'foo'
|
||||
) {
|
||||
return z.null();
|
||||
}
|
||||
|
||||
return undefined;
|
||||
},
|
||||
},
|
||||
),
|
||||
).toMatchZod(z.intersection(z.string(), z.intersection(z.number(), z.null())));
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user