@messagevisor/core 0.0.1 → 0.1.0
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/CHANGELOG.md +16 -0
- package/LICENSE +21 -0
- package/README.md +7 -0
- package/jest.config.js +8 -0
- package/lib/benchmark/index.d.ts +2 -0
- package/lib/benchmark/index.js +417 -0
- package/lib/benchmark/index.js.map +1 -0
- package/lib/builder/index.d.ts +70 -0
- package/lib/builder/index.js +831 -0
- package/lib/builder/index.js.map +1 -0
- package/lib/cli/index.d.ts +28 -0
- package/lib/cli/index.js +182 -0
- package/lib/cli/index.js.map +1 -0
- package/lib/config/index.d.ts +61 -0
- package/lib/config/index.js +255 -0
- package/lib/config/index.js.map +1 -0
- package/lib/create/index.d.ts +2 -0
- package/lib/create/index.js +405 -0
- package/lib/create/index.js.map +1 -0
- package/lib/datasource/filesystemAdapter.d.ts +44 -0
- package/lib/datasource/filesystemAdapter.js +424 -0
- package/lib/datasource/filesystemAdapter.js.map +1 -0
- package/lib/datasource/index.d.ts +39 -0
- package/lib/datasource/index.js +96 -0
- package/lib/datasource/index.js.map +1 -0
- package/lib/error.d.ts +6 -0
- package/lib/error.js +49 -0
- package/lib/error.js.map +1 -0
- package/lib/evaluate/cli.d.ts +8 -0
- package/lib/evaluate/cli.js +179 -0
- package/lib/evaluate/cli.js.map +1 -0
- package/lib/evaluate/index.d.ts +10 -0
- package/lib/evaluate/index.js +131 -0
- package/lib/evaluate/index.js.map +1 -0
- package/lib/examples/coerceExampleIsoDates.d.ts +12 -0
- package/lib/examples/coerceExampleIsoDates.js +81 -0
- package/lib/examples/coerceExampleIsoDates.js.map +1 -0
- package/lib/examples/index.d.ts +63 -0
- package/lib/examples/index.js +713 -0
- package/lib/examples/index.js.map +1 -0
- package/lib/exporter/index.d.ts +60 -0
- package/lib/exporter/index.js +610 -0
- package/lib/exporter/index.js.map +1 -0
- package/lib/find-duplicates/index.d.ts +41 -0
- package/lib/find-duplicates/index.js +297 -0
- package/lib/find-duplicates/index.js.map +1 -0
- package/lib/generate-code/index.d.ts +11 -0
- package/lib/generate-code/index.js +157 -0
- package/lib/generate-code/index.js.map +1 -0
- package/lib/generate-code/typescript.d.ts +14 -0
- package/lib/generate-code/typescript.js +307 -0
- package/lib/generate-code/typescript.js.map +1 -0
- package/lib/importer/index.d.ts +64 -0
- package/lib/importer/index.js +1092 -0
- package/lib/importer/index.js.map +1 -0
- package/lib/index.d.ts +18 -0
- package/lib/index.js +35 -0
- package/lib/index.js.map +1 -0
- package/lib/info/index.d.ts +17 -0
- package/lib/info/index.js +132 -0
- package/lib/info/index.js.map +1 -0
- package/lib/init/index.d.ts +30 -0
- package/lib/init/index.js +348 -0
- package/lib/init/index.js.map +1 -0
- package/lib/lint/index.d.ts +1 -0
- package/lib/lint/index.js +6 -0
- package/lib/lint/index.js.map +1 -0
- package/lib/linter/attributeSchema.d.ts +7 -0
- package/lib/linter/attributeSchema.js +36 -0
- package/lib/linter/attributeSchema.js.map +1 -0
- package/lib/linter/checkLocaleCircularDependency.d.ts +7 -0
- package/lib/linter/checkLocaleCircularDependency.js +42 -0
- package/lib/linter/checkLocaleCircularDependency.js.map +1 -0
- package/lib/linter/conditionSchema.d.ts +3 -0
- package/lib/linter/conditionSchema.js +283 -0
- package/lib/linter/conditionSchema.js.map +1 -0
- package/lib/linter/formatSchema.d.ts +325 -0
- package/lib/linter/formatSchema.js +165 -0
- package/lib/linter/formatSchema.js.map +1 -0
- package/lib/linter/icuStyleLint.d.ts +6 -0
- package/lib/linter/icuStyleLint.js +226 -0
- package/lib/linter/icuStyleLint.js.map +1 -0
- package/lib/linter/index.d.ts +34 -0
- package/lib/linter/index.js +557 -0
- package/lib/linter/index.js.map +1 -0
- package/lib/linter/localeSchema.d.ts +672 -0
- package/lib/linter/localeSchema.js +50 -0
- package/lib/linter/localeSchema.js.map +1 -0
- package/lib/linter/messageSchema.d.ts +35 -0
- package/lib/linter/messageSchema.js +115 -0
- package/lib/linter/messageSchema.js.map +1 -0
- package/lib/linter/printError.d.ts +8 -0
- package/lib/linter/printError.js +41 -0
- package/lib/linter/printError.js.map +1 -0
- package/lib/linter/schema.d.ts +33 -0
- package/lib/linter/schema.js +192 -0
- package/lib/linter/schema.js.map +1 -0
- package/lib/linter/segmentSchema.d.ts +8 -0
- package/lib/linter/segmentSchema.js +18 -0
- package/lib/linter/segmentSchema.js.map +1 -0
- package/lib/linter/targetSchema.d.ts +337 -0
- package/lib/linter/targetSchema.js +39 -0
- package/lib/linter/targetSchema.js.map +1 -0
- package/lib/linter/testSchema.d.ts +71 -0
- package/lib/linter/testSchema.js +165 -0
- package/lib/linter/testSchema.js.map +1 -0
- package/lib/linter/zodHelpers.d.ts +2 -0
- package/lib/linter/zodHelpers.js +15 -0
- package/lib/linter/zodHelpers.js.map +1 -0
- package/lib/list/index.d.ts +8 -0
- package/lib/list/index.js +524 -0
- package/lib/list/index.js.map +1 -0
- package/lib/matrix.d.ts +4 -0
- package/lib/matrix.js +66 -0
- package/lib/matrix.js.map +1 -0
- package/lib/promoter/index.d.ts +65 -0
- package/lib/promoter/index.js +1208 -0
- package/lib/promoter/index.js.map +1 -0
- package/lib/prune/index.d.ts +37 -0
- package/lib/prune/index.js +673 -0
- package/lib/prune/index.js.map +1 -0
- package/lib/sets.d.ts +10 -0
- package/lib/sets.js +120 -0
- package/lib/sets.js.map +1 -0
- package/lib/tester/cliFormat.d.ts +8 -0
- package/lib/tester/cliFormat.js +15 -0
- package/lib/tester/cliFormat.js.map +1 -0
- package/lib/tester/index.d.ts +35 -0
- package/lib/tester/index.js +713 -0
- package/lib/tester/index.js.map +1 -0
- package/lib/tester/matrix.d.ts +14 -0
- package/lib/tester/matrix.js +76 -0
- package/lib/tester/matrix.js.map +1 -0
- package/lib/tester/prettyDuration.d.ts +1 -0
- package/lib/tester/prettyDuration.js +30 -0
- package/lib/tester/prettyDuration.js.map +1 -0
- package/lib/tester/printTestResult.d.ts +2 -0
- package/lib/tester/printTestResult.js +32 -0
- package/lib/tester/printTestResult.js.map +1 -0
- package/lib/tester/types.d.ts +29 -0
- package/lib/tester/types.js +3 -0
- package/lib/tester/types.js.map +1 -0
- package/package.json +41 -13
- package/src/benchmark/index.spec.ts +375 -0
- package/src/benchmark/index.ts +433 -0
- package/src/builder/index.spec.ts +822 -0
- package/src/builder/index.ts +920 -0
- package/src/cli/index.spec.ts +54 -0
- package/src/cli/index.ts +150 -0
- package/src/config/index.spec.ts +70 -0
- package/src/config/index.ts +259 -0
- package/src/create/index.spec.ts +272 -0
- package/src/create/index.ts +295 -0
- package/src/datasource/filesystemAdapter.ts +313 -0
- package/src/datasource/index.ts +135 -0
- package/src/error.ts +33 -0
- package/src/evaluate/cli.spec.ts +368 -0
- package/src/evaluate/cli.ts +130 -0
- package/src/evaluate/index.ts +161 -0
- package/src/examples/coerceExampleIsoDates.spec.ts +81 -0
- package/src/examples/coerceExampleIsoDates.ts +98 -0
- package/src/examples/index.spec.ts +453 -0
- package/src/examples/index.ts +854 -0
- package/src/exporter/index.spec.ts +443 -0
- package/src/exporter/index.ts +643 -0
- package/src/find-duplicates/index.spec.ts +289 -0
- package/src/find-duplicates/index.ts +314 -0
- package/src/generate-code/index.ts +92 -0
- package/src/generate-code/typescript.spec.ts +241 -0
- package/src/generate-code/typescript.ts +284 -0
- package/src/importer/index.spec.ts +1101 -0
- package/src/importer/index.ts +1190 -0
- package/src/index.ts +18 -0
- package/src/info/index.ts +67 -0
- package/src/init/index.spec.ts +279 -0
- package/src/init/index.ts +292 -0
- package/src/lint/index.ts +1 -0
- package/src/linter/attributeSchema.ts +38 -0
- package/src/linter/checkLocaleCircularDependency.ts +51 -0
- package/src/linter/conditionSchema.ts +386 -0
- package/src/linter/formatSchema.ts +170 -0
- package/src/linter/icuStyleLint.ts +312 -0
- package/src/linter/index.spec.ts +824 -0
- package/src/linter/index.ts +460 -0
- package/src/linter/localeSchema.ts +70 -0
- package/src/linter/messageSchema.ts +152 -0
- package/src/linter/printError.ts +52 -0
- package/src/linter/schema.ts +230 -0
- package/src/linter/segmentSchema.ts +15 -0
- package/src/linter/targetSchema.ts +50 -0
- package/src/linter/testSchema.spec.ts +405 -0
- package/src/linter/testSchema.ts +239 -0
- package/src/linter/zodHelpers.ts +16 -0
- package/src/list/index.spec.ts +431 -0
- package/src/list/index.ts +463 -0
- package/src/matrix.ts +69 -0
- package/src/promoter/index.spec.ts +584 -0
- package/src/promoter/index.ts +1267 -0
- package/src/prune/index.spec.ts +418 -0
- package/src/prune/index.ts +693 -0
- package/src/sets.ts +74 -0
- package/src/tester/cliFormat.ts +11 -0
- package/src/tester/featurevisorIntegration.spec.ts +101 -0
- package/src/tester/index.spec.ts +577 -0
- package/src/tester/index.ts +679 -0
- package/src/tester/matrix.ts +106 -0
- package/src/tester/prettyDuration.ts +34 -0
- package/src/tester/printTestResult.ts +40 -0
- package/src/tester/types.ts +32 -0
- package/tsconfig.cjs.json +11 -0
- package/tsconfig.typecheck.json +4 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { ZodError, ZodIssue } from "zod";
|
|
2
|
+
|
|
3
|
+
export interface LintIssueFromZod {
|
|
4
|
+
message: string;
|
|
5
|
+
path: (string | number)[];
|
|
6
|
+
code?: string;
|
|
7
|
+
value?: unknown;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function normalizePath(path: PropertyKey[]): (string | number)[] {
|
|
11
|
+
return path.map((segment) => (typeof segment === "symbol" ? String(segment) : segment));
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function getInvalidUnionIssue(issue: ZodIssue): ZodIssue | undefined {
|
|
15
|
+
if (issue.code !== "invalid_union" || issue.path.length > 0) {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const unionErrors = (issue as any).unionErrors as ZodError[] | undefined;
|
|
20
|
+
if (Array.isArray(unionErrors) && unionErrors.length > 0) {
|
|
21
|
+
return unionErrors[unionErrors.length - 1].issues[0];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const errors = (issue as any).errors as ZodIssue[][] | undefined;
|
|
25
|
+
if (Array.isArray(errors) && errors.length > 0) {
|
|
26
|
+
return errors[errors.length - 1][0];
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function getLintIssuesFromZodError(error: ZodError): LintIssueFromZod[] {
|
|
31
|
+
return error.issues
|
|
32
|
+
.map((issue) => {
|
|
33
|
+
const nestedIssue = getInvalidUnionIssue(issue);
|
|
34
|
+
|
|
35
|
+
if (nestedIssue) {
|
|
36
|
+
return {
|
|
37
|
+
message: nestedIssue.message,
|
|
38
|
+
path: normalizePath(nestedIssue.path),
|
|
39
|
+
code: nestedIssue.code,
|
|
40
|
+
value: (nestedIssue as any).received,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
message: issue.message,
|
|
46
|
+
path: normalizePath(issue.path),
|
|
47
|
+
code: issue.code,
|
|
48
|
+
value: (issue as any).received,
|
|
49
|
+
};
|
|
50
|
+
})
|
|
51
|
+
.filter(Boolean);
|
|
52
|
+
}
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
export const primitiveValueZodSchema = z.union([
|
|
4
|
+
z.string(),
|
|
5
|
+
z.number(),
|
|
6
|
+
z.boolean(),
|
|
7
|
+
z.date(),
|
|
8
|
+
z.null(),
|
|
9
|
+
z.undefined(),
|
|
10
|
+
]);
|
|
11
|
+
|
|
12
|
+
export const valueZodSchema: z.ZodType<unknown> = z.lazy(() =>
|
|
13
|
+
z.union([primitiveValueZodSchema, z.array(valueZodSchema), z.record(z.string(), valueZodSchema)]),
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
export const attributeTypeEnum = z.enum([
|
|
17
|
+
"boolean",
|
|
18
|
+
"string",
|
|
19
|
+
"integer",
|
|
20
|
+
"double",
|
|
21
|
+
"date",
|
|
22
|
+
"object",
|
|
23
|
+
"array",
|
|
24
|
+
]);
|
|
25
|
+
|
|
26
|
+
type SchemaLike = {
|
|
27
|
+
type?: string;
|
|
28
|
+
enum?: unknown[];
|
|
29
|
+
const?: unknown;
|
|
30
|
+
minimum?: number;
|
|
31
|
+
maximum?: number;
|
|
32
|
+
minLength?: number;
|
|
33
|
+
maxLength?: number;
|
|
34
|
+
pattern?: string;
|
|
35
|
+
minItems?: number;
|
|
36
|
+
maxItems?: number;
|
|
37
|
+
uniqueItems?: boolean;
|
|
38
|
+
items?: unknown;
|
|
39
|
+
properties?: Record<string, unknown>;
|
|
40
|
+
additionalProperties?: unknown;
|
|
41
|
+
required?: string[];
|
|
42
|
+
oneOf?: unknown[];
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
function valueMatchesType(value: unknown, type: string): boolean {
|
|
46
|
+
switch (type) {
|
|
47
|
+
case "string":
|
|
48
|
+
case "date":
|
|
49
|
+
return typeof value === "string" || value instanceof Date;
|
|
50
|
+
case "boolean":
|
|
51
|
+
return typeof value === "boolean";
|
|
52
|
+
case "integer":
|
|
53
|
+
return typeof value === "number" && Number.isInteger(value);
|
|
54
|
+
case "double":
|
|
55
|
+
return typeof value === "number";
|
|
56
|
+
case "object":
|
|
57
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
58
|
+
case "array":
|
|
59
|
+
return Array.isArray(value) && value.every((entry) => typeof entry === "string");
|
|
60
|
+
default:
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function visitNested(
|
|
66
|
+
schema: SchemaLike,
|
|
67
|
+
pathPrefix: (string | number)[],
|
|
68
|
+
visitor: (schema: SchemaLike, path: (string | number)[]) => void,
|
|
69
|
+
) {
|
|
70
|
+
if (!schema || typeof schema !== "object") return;
|
|
71
|
+
|
|
72
|
+
visitor(schema, pathPrefix);
|
|
73
|
+
|
|
74
|
+
if (schema.items && typeof schema.items === "object") {
|
|
75
|
+
visitNested(schema.items as SchemaLike, [...pathPrefix, "items"], visitor);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (schema.properties && typeof schema.properties === "object") {
|
|
79
|
+
for (const key of Object.keys(schema.properties)) {
|
|
80
|
+
visitNested(
|
|
81
|
+
schema.properties[key] as SchemaLike,
|
|
82
|
+
[...pathPrefix, "properties", key],
|
|
83
|
+
visitor,
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (schema.additionalProperties && typeof schema.additionalProperties === "object") {
|
|
89
|
+
visitNested(
|
|
90
|
+
schema.additionalProperties as SchemaLike,
|
|
91
|
+
[...pathPrefix, "additionalProperties"],
|
|
92
|
+
visitor,
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (schema.oneOf && Array.isArray(schema.oneOf)) {
|
|
97
|
+
schema.oneOf.forEach((branch, index) => {
|
|
98
|
+
if (branch && typeof branch === "object") {
|
|
99
|
+
visitNested(branch as SchemaLike, [...pathPrefix, "oneOf", index], visitor);
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function refineSchemaSemantics(schema: SchemaLike, ctx: z.RefinementCtx): void {
|
|
106
|
+
visitNested(schema, [], (current, path) => {
|
|
107
|
+
if (current.type && Array.isArray(current.enum)) {
|
|
108
|
+
current.enum.forEach((value, index) => {
|
|
109
|
+
if (!valueMatchesType(value, current.type as string)) {
|
|
110
|
+
ctx.addIssue({
|
|
111
|
+
code: z.ZodIssueCode.custom,
|
|
112
|
+
message: `Enum value at index ${index} (${JSON.stringify(value)}) does not match type "${current.type}".`,
|
|
113
|
+
path: [...path, "enum", index],
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (
|
|
120
|
+
current.type &&
|
|
121
|
+
current.const !== undefined &&
|
|
122
|
+
!valueMatchesType(current.const, current.type)
|
|
123
|
+
) {
|
|
124
|
+
ctx.addIssue({
|
|
125
|
+
code: z.ZodIssueCode.custom,
|
|
126
|
+
message: `\`const\` value does not match type "${current.type}".`,
|
|
127
|
+
path: [...path, "const"],
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (
|
|
132
|
+
(current.type === "integer" || current.type === "double") &&
|
|
133
|
+
current.minimum !== undefined &&
|
|
134
|
+
current.maximum !== undefined &&
|
|
135
|
+
current.minimum > current.maximum
|
|
136
|
+
) {
|
|
137
|
+
ctx.addIssue({
|
|
138
|
+
code: z.ZodIssueCode.custom,
|
|
139
|
+
message: `\`minimum\` (${current.minimum}) must be less than or equal to \`maximum\` (${current.maximum}).`,
|
|
140
|
+
path: [...path, "minimum"],
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (
|
|
145
|
+
(current.type === "string" || current.type === "date") &&
|
|
146
|
+
current.minLength !== undefined &&
|
|
147
|
+
current.maxLength !== undefined &&
|
|
148
|
+
current.minLength > current.maxLength
|
|
149
|
+
) {
|
|
150
|
+
ctx.addIssue({
|
|
151
|
+
code: z.ZodIssueCode.custom,
|
|
152
|
+
message: `\`minLength\` (${current.minLength}) must be less than or equal to \`maxLength\` (${current.maxLength}).`,
|
|
153
|
+
path: [...path, "minLength"],
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
if ((current.type === "string" || current.type === "date") && current.pattern !== undefined) {
|
|
158
|
+
try {
|
|
159
|
+
new RegExp(current.pattern);
|
|
160
|
+
} catch {
|
|
161
|
+
ctx.addIssue({
|
|
162
|
+
code: z.ZodIssueCode.custom,
|
|
163
|
+
message: `\`pattern\` must be a valid ECMA-262 regular expression.`,
|
|
164
|
+
path: [...path, "pattern"],
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (current.type === "array" && current.items && typeof current.items === "object") {
|
|
170
|
+
const itemSchema = current.items as SchemaLike;
|
|
171
|
+
if (itemSchema.type !== "string") {
|
|
172
|
+
ctx.addIssue({
|
|
173
|
+
code: z.ZodIssueCode.custom,
|
|
174
|
+
message: `Attribute arrays must contain strings only. \`items.type\` must be "string".`,
|
|
175
|
+
path: [...path, "items", "type"],
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (current.type === "object" && Array.isArray(current.required) && current.properties) {
|
|
181
|
+
const allowedKeys = Object.keys(current.properties);
|
|
182
|
+
current.required.forEach((key, index) => {
|
|
183
|
+
if (!allowedKeys.includes(key)) {
|
|
184
|
+
ctx.addIssue({
|
|
185
|
+
code: z.ZodIssueCode.custom,
|
|
186
|
+
message: `Unknown required field "${key}". Required fields must exist in \`properties\`.`,
|
|
187
|
+
path: [...path, "required", index],
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if (current.type === "object" && current.properties) {
|
|
194
|
+
for (const key of Object.keys(current.properties)) {
|
|
195
|
+
const property = current.properties[key] as SchemaLike;
|
|
196
|
+
if (property.type === "object") {
|
|
197
|
+
ctx.addIssue({
|
|
198
|
+
code: z.ZodIssueCode.custom,
|
|
199
|
+
message: `Object attributes must stay flat. Property "${key}" cannot be of type "object".`,
|
|
200
|
+
path: [...path, "properties", key, "type"],
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export const attributePropertyZodSchema: z.ZodType<any> = z.lazy(() =>
|
|
209
|
+
z
|
|
210
|
+
.object({
|
|
211
|
+
description: z.string().optional(),
|
|
212
|
+
type: attributeTypeEnum.optional(),
|
|
213
|
+
enum: z.array(valueZodSchema).optional(),
|
|
214
|
+
const: valueZodSchema.optional(),
|
|
215
|
+
maximum: z.number().optional(),
|
|
216
|
+
minimum: z.number().optional(),
|
|
217
|
+
maxLength: z.number().int().nonnegative().optional(),
|
|
218
|
+
minLength: z.number().int().nonnegative().optional(),
|
|
219
|
+
pattern: z.string().optional(),
|
|
220
|
+
items: attributePropertyZodSchema.optional(),
|
|
221
|
+
maxItems: z.number().int().nonnegative().optional(),
|
|
222
|
+
minItems: z.number().int().nonnegative().optional(),
|
|
223
|
+
uniqueItems: z.boolean().optional(),
|
|
224
|
+
required: z.array(z.string()).optional(),
|
|
225
|
+
properties: z.record(z.string(), attributePropertyZodSchema).optional(),
|
|
226
|
+
additionalProperties: attributePropertyZodSchema.optional(),
|
|
227
|
+
oneOf: z.array(attributePropertyZodSchema).min(2).optional(),
|
|
228
|
+
})
|
|
229
|
+
.strict(),
|
|
230
|
+
);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
export function getSegmentZodSchema(conditionsZodSchema: z.ZodTypeAny) {
|
|
4
|
+
return z
|
|
5
|
+
.object({
|
|
6
|
+
key: z.string().optional(),
|
|
7
|
+
archived: z.boolean().optional(),
|
|
8
|
+
promotable: z.boolean().optional(),
|
|
9
|
+
description: z.string({
|
|
10
|
+
error: (issue) => (issue.input === undefined ? "Required" : undefined),
|
|
11
|
+
}),
|
|
12
|
+
conditions: conditionsZodSchema,
|
|
13
|
+
})
|
|
14
|
+
.strict();
|
|
15
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
import { formatPresetsZodSchema } from "./formatSchema";
|
|
4
|
+
import { refineWithMessage } from "./zodHelpers";
|
|
5
|
+
|
|
6
|
+
export function getTargetZodSchema(localeKeys: string[]) {
|
|
7
|
+
return z
|
|
8
|
+
.object({
|
|
9
|
+
key: z.string().optional(),
|
|
10
|
+
promotable: z.boolean().optional(),
|
|
11
|
+
stringify: z.boolean().optional(),
|
|
12
|
+
pretty: z.boolean().optional(),
|
|
13
|
+
revisionFromHash: z.boolean().optional(),
|
|
14
|
+
description: z.string({
|
|
15
|
+
error: (issue) => (issue.input === undefined ? "Required" : undefined),
|
|
16
|
+
}),
|
|
17
|
+
includeMessages: z.array(z.string()).optional(),
|
|
18
|
+
excludeMessages: z.array(z.string()).optional(),
|
|
19
|
+
locales: z
|
|
20
|
+
.array(
|
|
21
|
+
refineWithMessage(
|
|
22
|
+
z.string(),
|
|
23
|
+
(value) => localeKeys.includes(value),
|
|
24
|
+
(value) => `Unknown locale "${value}"`,
|
|
25
|
+
),
|
|
26
|
+
)
|
|
27
|
+
.optional(),
|
|
28
|
+
context: z.record(z.string(), z.unknown()).optional(),
|
|
29
|
+
formats: z
|
|
30
|
+
.record(
|
|
31
|
+
refineWithMessage(
|
|
32
|
+
z.string(),
|
|
33
|
+
(value) => localeKeys.includes(value),
|
|
34
|
+
(value) => `Unknown locale "${value}"`,
|
|
35
|
+
),
|
|
36
|
+
formatPresetsZodSchema,
|
|
37
|
+
)
|
|
38
|
+
.optional(),
|
|
39
|
+
})
|
|
40
|
+
.strict()
|
|
41
|
+
.superRefine((data, ctx) => {
|
|
42
|
+
if (!data.includeMessages || data.includeMessages.length === 0) {
|
|
43
|
+
ctx.addIssue({
|
|
44
|
+
code: z.ZodIssueCode.custom,
|
|
45
|
+
message: "Target must include at least one message pattern.",
|
|
46
|
+
path: ["includeMessages"],
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|