@toolproof-npm/schema 0.1.47 → 0.1.48

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.
@@ -1,56 +1,3 @@
1
1
  // Auto-generated strict composite type. Do not edit.
2
- export type Resource_Job = ResourceMetaBase & {
3
- extractedData: Job;
4
- };
5
- export type ResourceMetaBase = ResourceBase &
6
- CreationContextWrapper &
7
- ResourceKind & {
8
- kind: "materialized";
9
- } & Timestamp &
10
- Path;
11
- export type ResourceBase = {
12
- identity: string;
13
- resourceTypeRef: string;
14
- };
15
- export type Job = {
16
- identity: string;
17
- implementationUri: string;
18
- } & Documented &
19
- RolesWrapper;
20
- export type Documented = Named & Described;
21
- export type ResourceRoleValue = {
22
- resourceTypeRef: string;
23
- } & Documented;
24
-
25
- export interface CreationContextWrapper {
26
- creationContext: CreationContext;
27
- }
28
- export interface CreationContext {
29
- executionRef: string;
30
- resourceRoleRef: string;
31
- }
32
- export interface ResourceKind {
33
- kind: "missing" | "potential-input" | "potential-output" | "materialized";
34
- }
35
- export interface Timestamp {
36
- timestamp: string;
37
- }
38
- export interface Path {
39
- path: string;
40
- }
41
- export interface Named {
42
- name: string;
43
- }
44
- export interface Described {
45
- description: string;
46
- }
47
- export interface RolesWrapper {
48
- roles: Roles;
49
- }
50
- export interface Roles {
51
- inputMap: RoleMap;
52
- outputMap: RoleMap;
53
- }
54
- export interface RoleMap {
55
- [k: string]: ResourceRoleValue;
56
- }
2
+ import type { ResourceMetaBase, Job as ExtractedData } from './types.js';
3
+ export type Resource_Job = ResourceMetaBase & { extractedData: ExtractedData };
@@ -1,41 +1,3 @@
1
1
  // Auto-generated strict composite type. Do not edit.
2
- export type Resource_ResourceFormat = ResourceMetaBase & {
3
- extractedData: ResourceFormat;
4
- };
5
- export type ResourceMetaBase = ResourceBase &
6
- CreationContextWrapper &
7
- ResourceKind & {
8
- kind: "materialized";
9
- } & Timestamp &
10
- Path;
11
- export type ResourceBase = {
12
- identity: string;
13
- resourceTypeRef: string;
14
- };
15
- export type ResourceFormat = {
16
- identity: string;
17
- } & Documented;
18
- export type Documented = Named & Described;
19
-
20
- export interface CreationContextWrapper {
21
- creationContext: CreationContext;
22
- }
23
- export interface CreationContext {
24
- executionRef: string;
25
- resourceRoleRef: string;
26
- }
27
- export interface ResourceKind {
28
- kind: "missing" | "potential-input" | "potential-output" | "materialized";
29
- }
30
- export interface Timestamp {
31
- timestamp: string;
32
- }
33
- export interface Path {
34
- path: string;
35
- }
36
- export interface Named {
37
- name: string;
38
- }
39
- export interface Described {
40
- description: string;
41
- }
2
+ import type { ResourceMetaBase, ResourceFormat as ExtractedData } from './types.js';
3
+ export type Resource_ResourceFormat = ResourceMetaBase & { extractedData: ExtractedData };
@@ -1,62 +1,3 @@
1
1
  // Auto-generated strict composite type. Do not edit.
2
- export type Resource_ResourceType = ResourceMetaBase & {
3
- extractedData: ResourceType;
4
- };
5
- export type ResourceMetaBase = ResourceBase &
6
- CreationContextWrapper &
7
- ResourceKind & {
8
- kind: "materialized";
9
- } & Timestamp &
10
- Path;
11
- export type ResourceBase = {
12
- identity: string;
13
- resourceTypeRef: string;
14
- };
15
- export type ResourceType = {
16
- identity: string;
17
- resourceFormatRef: string;
18
- } & Documented &
19
- ExtractionSchemaWrapper & {
20
- };
21
- export type Documented = Named & Described;
22
- export type ExtractionSchema = {
23
- } & {
24
- $schema: "https://json-schema.org/draft/2020-12/schema";
25
- $defs?: {
26
- };
27
- type: "object";
28
- allOf?: {
29
- }[];
30
- properties?: {
31
- };
32
- required?: string[];
33
- additionalProperties?: false;
34
- unevaluatedProperties?: false;
35
- $anchor: string;
36
- };
37
-
38
- export interface CreationContextWrapper {
39
- creationContext: CreationContext;
40
- }
41
- export interface CreationContext {
42
- executionRef: string;
43
- resourceRoleRef: string;
44
- }
45
- export interface ResourceKind {
46
- kind: "missing" | "potential-input" | "potential-output" | "materialized";
47
- }
48
- export interface Timestamp {
49
- timestamp: string;
50
- }
51
- export interface Path {
52
- path: string;
53
- }
54
- export interface Named {
55
- name: string;
56
- }
57
- export interface Described {
58
- description: string;
59
- }
60
- export interface ExtractionSchemaWrapper {
61
- extractionSchema: ExtractionSchema;
62
- }
2
+ import type { ResourceMetaBase, ResourceType as ExtractedData } from './types.js';
3
+ export type Resource_ResourceType = ResourceMetaBase & { extractedData: ExtractedData };
@@ -1,80 +1,3 @@
1
1
  // Auto-generated strict composite type. Do not edit.
2
- export type Resource_StatelessStrategy = ResourceMetaBase & {
3
- extractedData: StatelessStrategy;
4
- };
5
- export type ResourceMetaBase = ResourceBase &
6
- CreationContextWrapper &
7
- ResourceKind & {
8
- kind: "materialized";
9
- } & Timestamp &
10
- Path;
11
- export type ResourceBase = {
12
- identity: string;
13
- resourceTypeRef: string;
14
- };
15
- export type StatelessStrategy = {
16
- identity: string;
17
- steps: Step[];
18
- };
19
- export type Step = WorkStep | BranchStep | WhileStep | ForStep;
20
- export type WorkStep = StepKind & {
21
- execution: Execution;
22
- identity: string;
23
- kind: "work";
24
- };
25
- export type Execution = {
26
- identity: string;
27
- jobRef: string;
28
- } & RoleBindingsWrapper;
29
- export type BranchStep = StepKind & {
30
- /**
31
- * @minItems 1
32
- */
33
- cases: [Conditional, ...Conditional[]];
34
- identity: string;
35
- kind: "branch";
36
- };
37
- export type WhileStep = StepKind & {
38
- case: Conditional;
39
- identity: string;
40
- kind: "while";
41
- };
42
- export type ForStep = StepKind & {
43
- case: Conditional;
44
- identity: string;
45
- kind: "for";
46
- };
47
-
48
- export interface CreationContextWrapper {
49
- creationContext: CreationContext;
50
- }
51
- export interface CreationContext {
52
- executionRef: string;
53
- resourceRoleRef: string;
54
- }
55
- export interface ResourceKind {
56
- kind: "missing" | "potential-input" | "potential-output" | "materialized";
57
- }
58
- export interface Timestamp {
59
- timestamp: string;
60
- }
61
- export interface Path {
62
- path: string;
63
- }
64
- export interface StepKind {
65
- kind: "work" | "branch" | "while" | "for";
66
- }
67
- export interface RoleBindingsWrapper {
68
- roleBindings: RoleBindings;
69
- }
70
- export interface RoleBindings {
71
- inputBindingMap: RoleBindingMap;
72
- outputBindingMap: RoleBindingMap;
73
- }
74
- export interface RoleBindingMap {
75
- [k: string]: string;
76
- }
77
- export interface Conditional {
78
- what: WorkStep;
79
- when: WorkStep;
80
- }
2
+ import type { ResourceMetaBase, StatelessStrategy as ExtractedData } from './types.js';
3
+ export type Resource_StatelessStrategy = ResourceMetaBase & { extractedData: ExtractedData };
@@ -1,6 +1,4 @@
1
1
  import fs from 'fs';
2
- import path from 'path';
3
- import { compileFromFile } from 'json-schema-to-typescript';
4
2
  import { getConfig } from './_lib/config.js';
5
3
  /**
6
4
  * Generate a typed Resource variant where `extractedData` is typed to a specific schema
@@ -15,8 +13,6 @@ async function main() {
15
13
  console.error('Missing --name <SchemaBasename> argument');
16
14
  process.exit(1);
17
15
  }
18
- const projectRoot = config.getRoot();
19
- const schemasDir = config.getOutputDir();
20
16
  const inPath = config.getOutputPath(`${name}.json`);
21
17
  if (!fs.existsSync(inPath)) {
22
18
  console.error(`Schema file not found: ${inPath}`);
@@ -46,73 +42,33 @@ async function main() {
46
42
  const outPath = config.getTypesSrcPath(outName);
47
43
  const outJsName = `Resource_${name}.js`;
48
44
  const outJsPath = config.getTypesSrcPath(outJsName);
49
- // Build a composite schema in output directory so that local $ref paths are simple
50
- const schemasOutDir = config.getOutputDir();
51
- const compositePath = path.join(schemasOutDir, `.composite.Resource_${name}.json`);
52
- const compositeSchema = {
53
- $schema: 'https://json-schema.org/draft/2020-12/schema',
54
- title: `Resource_${name}`,
55
- type: 'object',
56
- allOf: [
57
- { $ref: `./${config.getSourceFile()}#/$defs/ResourceMetaBase` },
58
- {
59
- type: 'object',
60
- required: ['extractedData'],
61
- properties: {
62
- extractedData: { $ref: `./${name}.json` }
63
- },
64
- unevaluatedProperties: false
65
- }
66
- ],
67
- unevaluatedProperties: false
68
- };
69
- // Write composite schema
70
- fs.writeFileSync(compositePath, JSON.stringify(compositeSchema, null, 2), 'utf8');
71
- try {
72
- // Compile to TypeScript declarations
73
- let ts = await compileFromFile(compositePath, {
74
- bannerComment: '',
75
- declareExternallyReferenced: true,
76
- unreachableDefinitions: true,
77
- $refOptions: {
78
- resolve: {
79
- file: { order: 1 },
80
- http: false,
81
- https: false
82
- }
83
- }
84
- });
85
- // Remove noisy index signatures that make types too permissive
86
- ts = ts.replace(/\n\s*\[k:\s*string\]:\s*unknown;\n/g, '\n');
87
- // Ensure it is a module
88
- if (!/\bexport\b/.test(ts)) {
89
- ts += '\nexport {}\n';
90
- }
91
- const header = '// Auto-generated strict composite type. Do not edit.\n';
92
- fs.writeFileSync(outPath, header + ts, 'utf8');
93
- console.log(`Wrote ${outPath}`);
94
- // Ensure a runtime-resolvable JS shim exists alongside the .d.ts for NodeNext resolution
95
- if (!fs.existsSync(outJsPath)) {
96
- fs.writeFileSync(outJsPath, 'export {}\n', 'utf8');
97
- console.log(`Wrote ${outJsPath}`);
98
- }
99
- // Also copy both files into dist so consumers can resolve the module and its types
100
- const distLibDir = config.getTypesDistDir();
101
- fs.mkdirSync(distLibDir, { recursive: true });
102
- const distDtsPath = config.getTypesDistPath(outName);
103
- const distJsPath = config.getTypesDistPath(outJsName);
104
- fs.writeFileSync(distDtsPath, header + ts, 'utf8');
105
- fs.writeFileSync(distJsPath, 'export {}\n', 'utf8');
106
- console.log(`Wrote ${distDtsPath}`);
107
- console.log(`Wrote ${distJsPath}`);
108
- }
109
- finally {
110
- // Cleanup composite schema file
111
- try {
112
- fs.unlinkSync(compositePath);
113
- }
114
- catch { }
45
+ // IMPORTANT:
46
+ // We intentionally do NOT re-run json-schema-to-typescript here.
47
+ // That path produces self-contained types that degrade schema-patterned identities/refs
48
+ // into plain `string`, which then becomes incompatible with our canonical branded
49
+ // identity types in `types.d.ts` (e.g. `ResourceIdentity = `RESOURCE-${string}``).
50
+ //
51
+ // Instead, we generate a tiny module that composes the canonical types:
52
+ // Resource_<Name> = ResourceMetaBase & { extractedData: <Name> }
53
+ const header = '// Auto-generated strict composite type. Do not edit.\n';
54
+ const ts = `import type { ResourceMetaBase, ${name} as ExtractedData } from './types.js';\n` +
55
+ `export type Resource_${name} = ResourceMetaBase & { extractedData: ExtractedData };\n`;
56
+ fs.writeFileSync(outPath, header + ts, 'utf8');
57
+ console.log(`Wrote ${outPath}`);
58
+ // Ensure a runtime-resolvable JS shim exists alongside the .d.ts for NodeNext resolution
59
+ if (!fs.existsSync(outJsPath)) {
60
+ fs.writeFileSync(outJsPath, 'export {}\n', 'utf8');
61
+ console.log(`Wrote ${outJsPath}`);
115
62
  }
63
+ // Also copy both files into dist so consumers can resolve the module and its types
64
+ const distLibDir = config.getTypesDistDir();
65
+ fs.mkdirSync(distLibDir, { recursive: true });
66
+ const distDtsPath = config.getTypesDistPath(outName);
67
+ const distJsPath = config.getTypesDistPath(outJsName);
68
+ fs.writeFileSync(distDtsPath, header + ts, 'utf8');
69
+ fs.writeFileSync(distJsPath, 'export {}\n', 'utf8');
70
+ console.log(`Wrote ${distDtsPath}`);
71
+ console.log(`Wrote ${distJsPath}`);
116
72
  }
117
73
  function parseArgs(args) {
118
74
  let name;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toolproof-npm/schema",
3
- "version": "0.1.47",
3
+ "version": "0.1.48",
4
4
  "description": "JSON schemas and TypeScript types for ToolProof",
5
5
  "keywords": [
6
6
  "toolproof",