@toolproof-core/genesis 1.0.50 → 1.0.52
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/generated-src/implementations/tools.ts +214 -214
- package/generated-src/metadata/Core.json +78 -0
- package/package.json +11 -12
- package/src/declarations/booleans.json +3 -3
- package/src/declarations/naturals.json +12 -12
- package/src/declarations/resourceTypes/resourceTypeShells.json +52 -52
- package/src/declarations/resourceTypes/schemas.json +1838 -1838
- package/src/declarations/tools.json +704 -704
- package/src/implementations/tools.ts +214 -214
- package/src/index.ts +131 -131
- package/src/utils/constantsAndMappings.ts +194 -194
- package/src/utils/coreProjection.ts +52 -52
- package/src/utils/resourceTypes.ts +70 -70
- package/src/utils/schemaDependencies.ts +114 -114
- package/src/utils/schemaObjectNormalization.ts +70 -70
- package/src/utils/schemaRefNormalization.ts +82 -82
- package/src/utils/schemaShims.ts +16 -16
- package/src/utils/standaloneSchemas.ts +113 -113
- package/src/utils/standaloneTypes.ts +27 -27
- package/src/utils/standaloneZodSchemas.ts +71 -71
- package/src/utils/timestampedResources.ts +41 -41
- package/src/utils/typeGeneration.ts +30 -30
- package/src/utils/typeGenerationPostProcess.ts +245 -245
- package/src/utils/typeGenerationPreflight.ts +118 -118
- package/src/utils/zodCodegen.ts +548 -548
- package/toolproof.json +18 -18
|
@@ -1,119 +1,119 @@
|
|
|
1
|
-
import { normalizeAllOfSiblingObjectKeywords } from './schemaObjectNormalization.js';
|
|
2
|
-
|
|
3
|
-
function formatPath(pathSegments: Array<string | number>): string {
|
|
4
|
-
let out = '';
|
|
5
|
-
for (const seg of pathSegments) {
|
|
6
|
-
if (typeof seg === 'number') {
|
|
7
|
-
out += `[${seg}]`;
|
|
8
|
-
continue;
|
|
9
|
-
}
|
|
10
|
-
out = out ? `${out}.${seg}` : seg;
|
|
11
|
-
}
|
|
12
|
-
return out || '<root>';
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function validateSchemaArrayKeywords(node: any, parentKey?: string, pathSegments: Array<string | number> = []): string[] {
|
|
16
|
-
if (Array.isArray(node)) {
|
|
17
|
-
const issues: string[] = [];
|
|
18
|
-
for (let i = 0; i < node.length; i++) {
|
|
19
|
-
issues.push(...validateSchemaArrayKeywords(node[i], parentKey, pathSegments.concat([i])));
|
|
20
|
-
}
|
|
21
|
-
return issues;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
if (!node || typeof node !== 'object') return [];
|
|
25
|
-
|
|
26
|
-
const isPropertyNameMap =
|
|
27
|
-
parentKey === 'properties' ||
|
|
28
|
-
parentKey === 'patternProperties' ||
|
|
29
|
-
parentKey === '$defs' ||
|
|
30
|
-
parentKey === 'dependentSchemas' ||
|
|
31
|
-
parentKey === 'dependentRequired';
|
|
32
|
-
|
|
33
|
-
const arrayKeys = ['anyOf', 'allOf', 'oneOf', 'required', 'enum'] as const;
|
|
34
|
-
const issues: string[] = [];
|
|
35
|
-
|
|
36
|
-
for (const [key, value] of Object.entries(node)) {
|
|
37
|
-
if (key === 'properties' || key === 'patternProperties' || key === '$defs' || key === 'dependentSchemas') {
|
|
38
|
-
if (value === null || typeof value !== 'object' || Array.isArray(value)) {
|
|
39
|
-
issues.push(
|
|
40
|
-
`${formatPath(pathSegments.concat([key]))}: expected \`${key}\` to be an object map, got ${value === null ? 'null' : Array.isArray(value) ? 'array' : typeof value}`,
|
|
41
|
-
);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if (key === 'dependentRequired') {
|
|
46
|
-
if (value === null || typeof value !== 'object' || Array.isArray(value)) {
|
|
47
|
-
issues.push(
|
|
48
|
-
`${formatPath(pathSegments.concat([key]))}: expected \`dependentRequired\` to be an object map, got ${value === null ? 'null' : Array.isArray(value) ? 'array' : typeof value}`,
|
|
49
|
-
);
|
|
50
|
-
} else {
|
|
51
|
-
for (const [depKey, depVal] of Object.entries(value as any)) {
|
|
52
|
-
if (!Array.isArray(depVal)) {
|
|
53
|
-
issues.push(
|
|
54
|
-
`${formatPath(pathSegments.concat([key, depKey]))}: expected dependentRequired entries to be string arrays, got ${depVal === null ? 'null' : typeof depVal}`,
|
|
55
|
-
);
|
|
56
|
-
continue;
|
|
57
|
-
}
|
|
58
|
-
for (let i = 0; i < depVal.length; i++) {
|
|
59
|
-
if (typeof depVal[i] !== 'string') {
|
|
60
|
-
issues.push(
|
|
61
|
-
`${formatPath(pathSegments.concat([key, depKey, i]))}: expected dependentRequired entries to be strings, got ${depVal[i] === null ? 'null' : typeof depVal[i]}`,
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (!isPropertyNameMap && (arrayKeys as readonly string[]).includes(key) && Object.prototype.hasOwnProperty.call(node, key)) {
|
|
70
|
-
if (!Array.isArray(value)) {
|
|
71
|
-
issues.push(
|
|
72
|
-
`${formatPath(pathSegments.concat([key]))}: expected \`${key}\` to be an array, got ${value === null ? 'null' : typeof value}`,
|
|
73
|
-
);
|
|
74
|
-
} else {
|
|
75
|
-
if ((key === 'anyOf' || key === 'allOf' || key === 'oneOf') && value.length === 0) {
|
|
76
|
-
issues.push(`${formatPath(pathSegments.concat([key]))}: expected \`${key}\` to be a non-empty array`);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
if (key === 'anyOf' || key === 'allOf' || key === 'oneOf') {
|
|
80
|
-
for (let i = 0; i < value.length; i++) {
|
|
81
|
-
const item = value[i];
|
|
82
|
-
const ok =
|
|
83
|
-
typeof item === 'boolean' ||
|
|
84
|
-
(item !== null && typeof item === 'object' && !Array.isArray(item));
|
|
85
|
-
if (!ok) {
|
|
86
|
-
issues.push(
|
|
87
|
-
`${formatPath(pathSegments.concat([key, i]))}: expected a schema (object or boolean), got ${item === null ? 'null' : Array.isArray(item) ? 'array' : typeof item}`,
|
|
88
|
-
);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
if (key === 'required') {
|
|
94
|
-
const seen = new Set<string>();
|
|
95
|
-
for (let i = 0; i < value.length; i++) {
|
|
96
|
-
if (typeof value[i] !== 'string') {
|
|
97
|
-
issues.push(
|
|
98
|
-
`${formatPath(pathSegments.concat([key, i]))}: expected \`required\` entries to be strings, got ${value[i] === null ? 'null' : typeof value[i]}`,
|
|
99
|
-
);
|
|
100
|
-
continue;
|
|
101
|
-
}
|
|
102
|
-
if (seen.has(value[i])) {
|
|
103
|
-
issues.push(`${formatPath(pathSegments.concat([key]))}: duplicate required entry \`${value[i]}\``);
|
|
104
|
-
}
|
|
105
|
-
seen.add(value[i]);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
issues.push(...validateSchemaArrayKeywords(value, key, pathSegments.concat([key])));
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
return issues;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
export function normalizeSchemaForGenerator(schema: any): any {
|
|
118
|
-
return normalizeAllOfSiblingObjectKeywords(schema);
|
|
1
|
+
import { normalizeAllOfSiblingObjectKeywords } from './schemaObjectNormalization.js';
|
|
2
|
+
|
|
3
|
+
function formatPath(pathSegments: Array<string | number>): string {
|
|
4
|
+
let out = '';
|
|
5
|
+
for (const seg of pathSegments) {
|
|
6
|
+
if (typeof seg === 'number') {
|
|
7
|
+
out += `[${seg}]`;
|
|
8
|
+
continue;
|
|
9
|
+
}
|
|
10
|
+
out = out ? `${out}.${seg}` : seg;
|
|
11
|
+
}
|
|
12
|
+
return out || '<root>';
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function validateSchemaArrayKeywords(node: any, parentKey?: string, pathSegments: Array<string | number> = []): string[] {
|
|
16
|
+
if (Array.isArray(node)) {
|
|
17
|
+
const issues: string[] = [];
|
|
18
|
+
for (let i = 0; i < node.length; i++) {
|
|
19
|
+
issues.push(...validateSchemaArrayKeywords(node[i], parentKey, pathSegments.concat([i])));
|
|
20
|
+
}
|
|
21
|
+
return issues;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (!node || typeof node !== 'object') return [];
|
|
25
|
+
|
|
26
|
+
const isPropertyNameMap =
|
|
27
|
+
parentKey === 'properties' ||
|
|
28
|
+
parentKey === 'patternProperties' ||
|
|
29
|
+
parentKey === '$defs' ||
|
|
30
|
+
parentKey === 'dependentSchemas' ||
|
|
31
|
+
parentKey === 'dependentRequired';
|
|
32
|
+
|
|
33
|
+
const arrayKeys = ['anyOf', 'allOf', 'oneOf', 'required', 'enum'] as const;
|
|
34
|
+
const issues: string[] = [];
|
|
35
|
+
|
|
36
|
+
for (const [key, value] of Object.entries(node)) {
|
|
37
|
+
if (key === 'properties' || key === 'patternProperties' || key === '$defs' || key === 'dependentSchemas') {
|
|
38
|
+
if (value === null || typeof value !== 'object' || Array.isArray(value)) {
|
|
39
|
+
issues.push(
|
|
40
|
+
`${formatPath(pathSegments.concat([key]))}: expected \`${key}\` to be an object map, got ${value === null ? 'null' : Array.isArray(value) ? 'array' : typeof value}`,
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (key === 'dependentRequired') {
|
|
46
|
+
if (value === null || typeof value !== 'object' || Array.isArray(value)) {
|
|
47
|
+
issues.push(
|
|
48
|
+
`${formatPath(pathSegments.concat([key]))}: expected \`dependentRequired\` to be an object map, got ${value === null ? 'null' : Array.isArray(value) ? 'array' : typeof value}`,
|
|
49
|
+
);
|
|
50
|
+
} else {
|
|
51
|
+
for (const [depKey, depVal] of Object.entries(value as any)) {
|
|
52
|
+
if (!Array.isArray(depVal)) {
|
|
53
|
+
issues.push(
|
|
54
|
+
`${formatPath(pathSegments.concat([key, depKey]))}: expected dependentRequired entries to be string arrays, got ${depVal === null ? 'null' : typeof depVal}`,
|
|
55
|
+
);
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
for (let i = 0; i < depVal.length; i++) {
|
|
59
|
+
if (typeof depVal[i] !== 'string') {
|
|
60
|
+
issues.push(
|
|
61
|
+
`${formatPath(pathSegments.concat([key, depKey, i]))}: expected dependentRequired entries to be strings, got ${depVal[i] === null ? 'null' : typeof depVal[i]}`,
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (!isPropertyNameMap && (arrayKeys as readonly string[]).includes(key) && Object.prototype.hasOwnProperty.call(node, key)) {
|
|
70
|
+
if (!Array.isArray(value)) {
|
|
71
|
+
issues.push(
|
|
72
|
+
`${formatPath(pathSegments.concat([key]))}: expected \`${key}\` to be an array, got ${value === null ? 'null' : typeof value}`,
|
|
73
|
+
);
|
|
74
|
+
} else {
|
|
75
|
+
if ((key === 'anyOf' || key === 'allOf' || key === 'oneOf') && value.length === 0) {
|
|
76
|
+
issues.push(`${formatPath(pathSegments.concat([key]))}: expected \`${key}\` to be a non-empty array`);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (key === 'anyOf' || key === 'allOf' || key === 'oneOf') {
|
|
80
|
+
for (let i = 0; i < value.length; i++) {
|
|
81
|
+
const item = value[i];
|
|
82
|
+
const ok =
|
|
83
|
+
typeof item === 'boolean' ||
|
|
84
|
+
(item !== null && typeof item === 'object' && !Array.isArray(item));
|
|
85
|
+
if (!ok) {
|
|
86
|
+
issues.push(
|
|
87
|
+
`${formatPath(pathSegments.concat([key, i]))}: expected a schema (object or boolean), got ${item === null ? 'null' : Array.isArray(item) ? 'array' : typeof item}`,
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (key === 'required') {
|
|
94
|
+
const seen = new Set<string>();
|
|
95
|
+
for (let i = 0; i < value.length; i++) {
|
|
96
|
+
if (typeof value[i] !== 'string') {
|
|
97
|
+
issues.push(
|
|
98
|
+
`${formatPath(pathSegments.concat([key, i]))}: expected \`required\` entries to be strings, got ${value[i] === null ? 'null' : typeof value[i]}`,
|
|
99
|
+
);
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
if (seen.has(value[i])) {
|
|
103
|
+
issues.push(`${formatPath(pathSegments.concat([key]))}: duplicate required entry \`${value[i]}\``);
|
|
104
|
+
}
|
|
105
|
+
seen.add(value[i]);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
issues.push(...validateSchemaArrayKeywords(value, key, pathSegments.concat([key])));
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return issues;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export function normalizeSchemaForGenerator(schema: any): any {
|
|
118
|
+
return normalizeAllOfSiblingObjectKeywords(schema);
|
|
119
119
|
}
|