@toolproof-core/schema 1.0.9 → 1.0.10

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.
Files changed (54) hide show
  1. package/dist/generated/artifacts/constants.d.ts +120 -0
  2. package/dist/generated/artifacts/constants.js +120 -0
  3. package/dist/generated/artifacts/mappings.d.ts +23 -0
  4. package/dist/generated/artifacts/mappings.js +23 -0
  5. package/dist/generated/normalized/Genesis.json +67 -53
  6. package/dist/generated/resources/Genesis.json +424 -236
  7. package/dist/generated/schemas/Genesis.json +56 -42
  8. package/dist/generated/schemas/standalone/Job.json +2 -0
  9. package/dist/generated/schemas/standalone/RawStrategy.json +86 -110
  10. package/dist/generated/schemas/standalone/RunnableStrategy.json +108 -132
  11. package/dist/generated/schemas/standalone/StrategyRun.json +86 -110
  12. package/dist/generated/types/types.d.ts +34 -34
  13. package/dist/index.d.ts +6 -3
  14. package/dist/index.js +5 -2
  15. package/dist/scripts/_lib/config.d.ts +3 -5
  16. package/dist/scripts/_lib/config.js +8 -14
  17. package/dist/scripts/generateConstantsAndMappings.d.ts +31 -0
  18. package/dist/scripts/generateConstantsAndMappings.js +243 -0
  19. package/dist/scripts/generateDependencies.js +1 -1
  20. package/dist/scripts/generateTerminals.js +2 -2
  21. package/dist/scripts/generateTypes.js +47 -2
  22. package/dist/scripts/wrapResourceTypesWithResourceShells.js +7 -3
  23. package/package.json +9 -10
  24. package/src/Genesis.json +1847 -1833
  25. package/src/generated/artifacts/constants.ts +121 -0
  26. package/src/generated/{dependencies → artifacts}/dependencyMap.json +16 -18
  27. package/src/generated/artifacts/mappings.ts +24 -0
  28. package/src/generated/{dependencies → artifacts}/terminals.json +1 -0
  29. package/src/generated/normalized/Genesis.json +1760 -1746
  30. package/src/generated/resources/Genesis.json +2796 -2608
  31. package/src/generated/schemas/Genesis.json +1329 -1315
  32. package/src/generated/schemas/standalone/Job.json +2 -0
  33. package/src/generated/schemas/standalone/RawStrategy.json +580 -604
  34. package/src/generated/schemas/standalone/RunnableStrategy.json +645 -669
  35. package/src/generated/schemas/standalone/StrategyRun.json +913 -937
  36. package/src/generated/types/types.d.ts +709 -709
  37. package/src/index.ts +75 -70
  38. package/src/scripts/_lib/config.ts +207 -215
  39. package/src/scripts/extractSchemasFromResourceTypeShells.ts +261 -261
  40. package/src/scripts/generateConstantsAndMappings.ts +309 -0
  41. package/src/scripts/generateDependencies.ts +121 -121
  42. package/src/scripts/generateSchemaShims.ts +127 -127
  43. package/src/scripts/generateStandaloneSchema.ts +185 -185
  44. package/src/scripts/generateStandaloneType.ts +127 -127
  45. package/src/scripts/generateTerminals.ts +73 -73
  46. package/src/scripts/generateTypes.ts +587 -531
  47. package/src/scripts/normalizeAnchorsToPointers.ts +141 -141
  48. package/src/scripts/wrapResourceTypesWithResourceShells.ts +86 -82
  49. package/dist/generated/constants/constants.d.ts +0 -60
  50. package/dist/generated/constants/constants.js +0 -60
  51. package/dist/scripts/generateConstants.d.ts +0 -12
  52. package/dist/scripts/generateConstants.js +0 -179
  53. package/src/generated/constants/constants.ts +0 -61
  54. package/src/scripts/generateConstants.ts +0 -217
@@ -1,179 +0,0 @@
1
- import fs from 'fs';
2
- import path from 'path';
3
- import { getConfig } from './_lib/config.js';
4
- // PURE: Attempt to derive a canonical identity prefix from a canonical identity regex pattern.
5
- function deriveIdentityPrefixFromPattern(pattern) {
6
- // Canonical (currently used across schemas): ^PREFIX-.+$
7
- const match = /^\^([^$]+)\.\+\$$/.exec(pattern);
8
- if (!match)
9
- return undefined;
10
- const prefix = match[1];
11
- if (!prefix || /[`\n\r]/.test(prefix))
12
- return undefined;
13
- return prefix;
14
- }
15
- // PURE: Extract all identity prefixes from `$defs/*Identity` string-pattern definitions.
16
- export function extractIdentityPrefixes(schema) {
17
- if (!schema || typeof schema !== 'object')
18
- return {};
19
- const defs = schema.$defs;
20
- if (!defs || typeof defs !== 'object')
21
- return {};
22
- const defEntries = Object.entries(defs);
23
- defEntries.sort(([a], [b]) => a.localeCompare(b));
24
- const out = {};
25
- for (const [defName, defVal] of defEntries) {
26
- if (!/Identity$/.test(defName))
27
- continue;
28
- if (!defVal || typeof defVal !== 'object' || Array.isArray(defVal))
29
- continue;
30
- const v = defVal;
31
- if (v.type !== 'string')
32
- continue;
33
- if (typeof v.pattern !== 'string')
34
- continue;
35
- const prefix = deriveIdentityPrefixFromPattern(v.pattern);
36
- if (!prefix)
37
- continue;
38
- out[defName] = prefix;
39
- }
40
- return out;
41
- }
42
- // PURE: Derive identifiables from extracted Identity def names.
43
- // Example: { BranchStepIdentity: 'BRANCH_STEP-' } => { BranchStep: 'BranchStep' }
44
- export function deriveIdentifiablesFromIdentityPrefixes(identityPrefixes) {
45
- const keys = Object.keys(identityPrefixes).sort((a, b) => a.localeCompare(b));
46
- const out = {};
47
- for (const key of keys) {
48
- if (!key.endsWith('Identity'))
49
- continue;
50
- const name = key.slice(0, -'Identity'.length);
51
- if (!name)
52
- continue;
53
- out[name] = name;
54
- }
55
- return out;
56
- }
57
- // PURE: Extract all string enums from `$defs/*Kind|*Status` definitions.
58
- // Shape: { StepKind: { job: 'job', ... }, ResourceKind: { inputPotential': 'inputPotential', ... } }
59
- export function extractEnums(schema) {
60
- if (!schema || typeof schema !== 'object')
61
- return {};
62
- const defs = schema.$defs;
63
- if (!defs || typeof defs !== 'object')
64
- return {};
65
- const defEntries = Object.entries(defs);
66
- defEntries.sort(([a], [b]) => a.localeCompare(b));
67
- const out = {};
68
- for (const [defName, defVal] of defEntries) {
69
- if (!/(Kind|Status)$/.test(defName))
70
- continue;
71
- if (!defVal || typeof defVal !== 'object' || Array.isArray(defVal))
72
- continue;
73
- const v = defVal;
74
- if (v.type !== 'string')
75
- continue;
76
- if (!Array.isArray(v.enum) || v.enum.length === 0)
77
- continue;
78
- if (v.enum.some((x) => typeof x !== 'string'))
79
- continue;
80
- const members = {};
81
- for (const member of v.enum) {
82
- members[member] = member;
83
- }
84
- out[defName] = members;
85
- }
86
- return out;
87
- }
88
- // PURE: Extract all generated constants from a parsed schema.
89
- export function extractConstants(schema) {
90
- const identityPrefixes = extractIdentityPrefixes(schema);
91
- const identifiables = deriveIdentifiablesFromIdentityPrefixes(identityPrefixes);
92
- const enums = extractEnums(schema);
93
- return {
94
- IDENTIFIABLES: {
95
- PREFIXES: identityPrefixes,
96
- NAMES: identifiables,
97
- },
98
- ENUMS: enums,
99
- };
100
- }
101
- // PURE: Render helpers for TS keys/strings.
102
- function escapeTsString(value) {
103
- return value
104
- .replace(/\\/g, '\\\\')
105
- .replace(/\r/g, '\\r')
106
- .replace(/\n/g, '\\n')
107
- .replace(/\t/g, '\\t')
108
- .replace(/'/g, "\\'");
109
- }
110
- function renderTsStringLiteral(value) {
111
- return `'${escapeTsString(value)}'`;
112
- }
113
- function isValidTsIdentifier(key) {
114
- return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(key);
115
- }
116
- function renderTsKey(key) {
117
- return isValidTsIdentifier(key) ? key : renderTsStringLiteral(key);
118
- }
119
- // PURE: Render constants TypeScript source.
120
- export function renderConstantsTs(constants) {
121
- const prefixKeys = Object.keys(constants.IDENTIFIABLES.PREFIXES).sort((a, b) => a.localeCompare(b));
122
- const nameKeys = Object.keys(constants.IDENTIFIABLES.NAMES).sort((a, b) => a.localeCompare(b));
123
- const enumKeys = Object.keys(constants.ENUMS).sort((a, b) => a.localeCompare(b));
124
- const lines = [];
125
- lines.push('const CONSTANTS = {');
126
- lines.push(' IDENTIFIABLES: {');
127
- lines.push(' PREFIXES: {');
128
- for (const key of prefixKeys) {
129
- const value = constants.IDENTIFIABLES.PREFIXES[key] ?? '';
130
- lines.push(` ${renderTsKey(key)}: ${renderTsStringLiteral(value)},`);
131
- }
132
- lines.push(' },');
133
- lines.push(' NAMES: {');
134
- for (const key of nameKeys) {
135
- const value = constants.IDENTIFIABLES.NAMES[key] ?? '';
136
- lines.push(` ${renderTsKey(key)}: ${renderTsStringLiteral(value)},`);
137
- }
138
- lines.push(' },');
139
- lines.push(' },');
140
- lines.push(' ENUMS: {');
141
- for (const key of enumKeys) {
142
- const members = constants.ENUMS[key] ?? {};
143
- lines.push(` ${renderTsKey(key)}: {`);
144
- for (const memberKey of Object.keys(members)) {
145
- const value = members[memberKey] ?? '';
146
- lines.push(` ${renderTsKey(memberKey)}: ${renderTsStringLiteral(value)},`);
147
- }
148
- lines.push(' },');
149
- }
150
- lines.push(' }');
151
- lines.push('} as const;');
152
- lines.push('');
153
- lines.push('export default CONSTANTS;');
154
- lines.push('');
155
- return lines.join('\n');
156
- }
157
- // IMPURE: Script entrypoint (config + filesystem I/O + console + process exit code).
158
- function main() {
159
- try {
160
- const config = getConfig();
161
- const inPath = config.getSchemaPath('Genesis.json');
162
- const outPath = config.getConstantsPath('constants.ts');
163
- if (!fs.existsSync(inPath)) {
164
- throw new Error(`Genesis schema not found at ${inPath}. Run extractSchemasFromResourceTypeShells first.`);
165
- }
166
- const raw = fs.readFileSync(inPath, 'utf8');
167
- const doc = JSON.parse(raw);
168
- const constants = extractConstants(doc);
169
- const ts = renderConstantsTs(constants);
170
- fs.mkdirSync(path.dirname(outPath), { recursive: true });
171
- fs.writeFileSync(outPath, ts, 'utf8');
172
- console.log(`Wrote constants to ${outPath}`);
173
- }
174
- catch (error) {
175
- console.error(`Error generating constants: ${error?.message ?? error}`);
176
- process.exitCode = 1;
177
- }
178
- }
179
- main();
@@ -1,61 +0,0 @@
1
- const CONSTANTS = {
2
- IDENTIFIABLES: {
3
- PREFIXES: {
4
- BranchStepIdentity: 'BRANCH_STEP-',
5
- ForStepIdentity: 'FOR_STEP-',
6
- GoalIdentity: 'GOAL-',
7
- JobIdentity: 'JOB-',
8
- JobStepIdentity: 'JOB_STEP-',
9
- ResourceIdentity: 'RESOURCE-',
10
- ResourceRoleIdentity: 'ROLE-',
11
- ResourceTypeIdentity: 'TYPE-',
12
- RunnableStrategyIdentity: 'RUNNABLE_STRATEGY-',
13
- StrategyRunIdentity: 'STRATEGY_RUN-',
14
- StrategyThreadIdentity: 'STRATEGY_THREAD-',
15
- WhileStepIdentity: 'WHILE_STEP-',
16
- },
17
- NAMES: {
18
- BranchStep: 'BranchStep',
19
- ForStep: 'ForStep',
20
- Goal: 'Goal',
21
- Job: 'Job',
22
- JobStep: 'JobStep',
23
- Resource: 'Resource',
24
- ResourceRole: 'ResourceRole',
25
- ResourceType: 'ResourceType',
26
- RunnableStrategy: 'RunnableStrategy',
27
- StrategyRun: 'StrategyRun',
28
- StrategyThread: 'StrategyThread',
29
- WhileStep: 'WhileStep',
30
- },
31
- },
32
- ENUMS: {
33
- ResourceKind: {
34
- missing: 'missing',
35
- inputPotential: 'inputPotential',
36
- outputPotential: 'outputPotential',
37
- materialized: 'materialized',
38
- },
39
- RunEventKind: {
40
- graph_start: 'graph_start',
41
- tick: 'tick',
42
- interrupt: 'interrupt',
43
- graph_end: 'graph_end',
44
- },
45
- RunnableStrategyStatus: {
46
- pending: 'pending',
47
- running: 'running',
48
- completed: 'completed',
49
- failed: 'failed',
50
- cancelled: 'cancelled',
51
- },
52
- StepKind: {
53
- job: 'job',
54
- branch: 'branch',
55
- while: 'while',
56
- for: 'for',
57
- },
58
- }
59
- } as const;
60
-
61
- export default CONSTANTS;
@@ -1,217 +0,0 @@
1
- import fs from 'fs';
2
- import path from 'path';
3
- import { getConfig } from './_lib/config.js';
4
-
5
- type JSONValue = null | boolean | number | string | JSONValue[] | { [k: string]: JSONValue };
6
-
7
- export type GeneratedConstants = {
8
- IDENTIFIABLES: {
9
- PREFIXES: Record<string, string>;
10
- NAMES: Record<string, string>;
11
- };
12
- ENUMS: Record<string, Record<string, string>>;
13
- };
14
-
15
- // PURE: Attempt to derive a canonical identity prefix from a canonical identity regex pattern.
16
- function deriveIdentityPrefixFromPattern(pattern: string): string | undefined {
17
- // Canonical (currently used across schemas): ^PREFIX-.+$
18
- const match = /^\^([^$]+)\.\+\$$/.exec(pattern);
19
- if (!match) return undefined;
20
-
21
- const prefix = match[1];
22
- if (!prefix || /[`\n\r]/.test(prefix)) return undefined;
23
-
24
- return prefix;
25
- }
26
-
27
- // PURE: Extract all identity prefixes from `$defs/*Identity` string-pattern definitions.
28
- export function extractIdentityPrefixes(schema: unknown): Record<string, string> {
29
- if (!schema || typeof schema !== 'object') return {};
30
-
31
- const defs = (schema as any).$defs;
32
- if (!defs || typeof defs !== 'object') return {};
33
-
34
- const defEntries = Object.entries(defs as Record<string, unknown>);
35
- defEntries.sort(([a], [b]) => a.localeCompare(b));
36
-
37
- const out: Record<string, string> = {};
38
-
39
- for (const [defName, defVal] of defEntries) {
40
- if (!/Identity$/.test(defName)) continue;
41
- if (!defVal || typeof defVal !== 'object' || Array.isArray(defVal)) continue;
42
-
43
- const v: any = defVal;
44
- if (v.type !== 'string') continue;
45
- if (typeof v.pattern !== 'string') continue;
46
-
47
- const prefix = deriveIdentityPrefixFromPattern(v.pattern);
48
- if (!prefix) continue;
49
-
50
- out[defName] = prefix;
51
- }
52
-
53
- return out;
54
- }
55
-
56
- // PURE: Derive identifiables from extracted Identity def names.
57
- // Example: { BranchStepIdentity: 'BRANCH_STEP-' } => { BranchStep: 'BranchStep' }
58
- export function deriveIdentifiablesFromIdentityPrefixes(identityPrefixes: Record<string, string>): Record<string, string> {
59
- const keys = Object.keys(identityPrefixes).sort((a, b) => a.localeCompare(b));
60
- const out: Record<string, string> = {};
61
-
62
- for (const key of keys) {
63
- if (!key.endsWith('Identity')) continue;
64
- const name = key.slice(0, -'Identity'.length);
65
- if (!name) continue;
66
- out[name] = name;
67
- }
68
-
69
- return out;
70
- }
71
-
72
- // PURE: Extract all string enums from `$defs/*Kind|*Status` definitions.
73
- // Shape: { StepKind: { job: 'job', ... }, ResourceKind: { inputPotential': 'inputPotential', ... } }
74
- export function extractEnums(schema: unknown): Record<string, Record<string, string>> {
75
- if (!schema || typeof schema !== 'object') return {};
76
-
77
- const defs = (schema as any).$defs;
78
- if (!defs || typeof defs !== 'object') return {};
79
-
80
- const defEntries = Object.entries(defs as Record<string, unknown>);
81
- defEntries.sort(([a], [b]) => a.localeCompare(b));
82
-
83
- const out: Record<string, Record<string, string>> = {};
84
-
85
- for (const [defName, defVal] of defEntries) {
86
- if (!/(Kind|Status)$/.test(defName)) continue;
87
- if (!defVal || typeof defVal !== 'object' || Array.isArray(defVal)) continue;
88
-
89
- const v: any = defVal;
90
- if (v.type !== 'string') continue;
91
- if (!Array.isArray(v.enum) || v.enum.length === 0) continue;
92
- if (v.enum.some((x: unknown) => typeof x !== 'string')) continue;
93
-
94
- const members: Record<string, string> = {};
95
- for (const member of v.enum as readonly string[]) {
96
- members[member] = member;
97
- }
98
-
99
- out[defName] = members;
100
- }
101
-
102
- return out;
103
- }
104
-
105
- // PURE: Extract all generated constants from a parsed schema.
106
- export function extractConstants(schema: unknown): GeneratedConstants {
107
- const identityPrefixes = extractIdentityPrefixes(schema);
108
- const identifiables = deriveIdentifiablesFromIdentityPrefixes(identityPrefixes);
109
- const enums = extractEnums(schema);
110
- return {
111
- IDENTIFIABLES: {
112
- PREFIXES: identityPrefixes,
113
- NAMES: identifiables,
114
- },
115
- ENUMS: enums,
116
- };
117
- }
118
-
119
- // PURE: Render helpers for TS keys/strings.
120
- function escapeTsString(value: string): string {
121
- return value
122
- .replace(/\\/g, '\\\\')
123
- .replace(/\r/g, '\\r')
124
- .replace(/\n/g, '\\n')
125
- .replace(/\t/g, '\\t')
126
- .replace(/'/g, "\\'");
127
- }
128
-
129
- function renderTsStringLiteral(value: string): string {
130
- return `'${escapeTsString(value)}'`;
131
- }
132
-
133
- function isValidTsIdentifier(key: string): boolean {
134
- return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(key);
135
- }
136
-
137
- function renderTsKey(key: string): string {
138
- return isValidTsIdentifier(key) ? key : renderTsStringLiteral(key);
139
- }
140
-
141
- // PURE: Render constants TypeScript source.
142
- export function renderConstantsTs(constants: GeneratedConstants): string {
143
- const prefixKeys = Object.keys(constants.IDENTIFIABLES.PREFIXES).sort((a, b) => a.localeCompare(b));
144
- const nameKeys = Object.keys(constants.IDENTIFIABLES.NAMES).sort((a, b) => a.localeCompare(b));
145
- const enumKeys = Object.keys(constants.ENUMS).sort((a, b) => a.localeCompare(b));
146
-
147
- const lines: string[] = [];
148
- lines.push('const CONSTANTS = {');
149
- lines.push(' IDENTIFIABLES: {');
150
- lines.push(' PREFIXES: {');
151
-
152
- for (const key of prefixKeys) {
153
- const value = constants.IDENTIFIABLES.PREFIXES[key] ?? '';
154
- lines.push(` ${renderTsKey(key)}: ${renderTsStringLiteral(value)},`);
155
- }
156
-
157
- lines.push(' },');
158
- lines.push(' NAMES: {');
159
-
160
- for (const key of nameKeys) {
161
- const value = constants.IDENTIFIABLES.NAMES[key] ?? '';
162
- lines.push(` ${renderTsKey(key)}: ${renderTsStringLiteral(value)},`);
163
- }
164
-
165
- lines.push(' },');
166
- lines.push(' },');
167
- lines.push(' ENUMS: {');
168
-
169
- for (const key of enumKeys) {
170
- const members = constants.ENUMS[key] ?? {};
171
- lines.push(` ${renderTsKey(key)}: {`);
172
-
173
- for (const memberKey of Object.keys(members)) {
174
- const value = members[memberKey] ?? '';
175
- lines.push(` ${renderTsKey(memberKey)}: ${renderTsStringLiteral(value)},`);
176
- }
177
-
178
- lines.push(' },');
179
- }
180
-
181
- lines.push(' }');
182
- lines.push('} as const;');
183
- lines.push('');
184
- lines.push('export default CONSTANTS;');
185
- lines.push('');
186
-
187
- return lines.join('\n');
188
- }
189
-
190
- // IMPURE: Script entrypoint (config + filesystem I/O + console + process exit code).
191
- function main() {
192
- try {
193
- const config = getConfig();
194
-
195
- const inPath = config.getSchemaPath('Genesis.json');
196
- const outPath = config.getConstantsPath('constants.ts');
197
-
198
- if (!fs.existsSync(inPath)) {
199
- throw new Error(`Genesis schema not found at ${inPath}. Run extractSchemasFromResourceTypeShells first.`);
200
- }
201
-
202
- const raw = fs.readFileSync(inPath, 'utf8');
203
- const doc: JSONValue = JSON.parse(raw);
204
-
205
- const constants = extractConstants(doc);
206
- const ts = renderConstantsTs(constants);
207
-
208
- fs.mkdirSync(path.dirname(outPath), { recursive: true });
209
- fs.writeFileSync(outPath, ts, 'utf8');
210
- console.log(`Wrote constants to ${outPath}`);
211
- } catch (error: any) {
212
- console.error(`Error generating constants: ${error?.message ?? error}`);
213
- process.exitCode = 1;
214
- }
215
- }
216
-
217
- main();