@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.
@@ -1,53 +1,53 @@
1
- import * as path from 'node:path';
2
-
3
- export type CoreProjectionNode = CoreProjectionDirectoryNode | CoreProjectionFileNode;
4
-
5
- export interface CoreProjectionBaseNode {
6
- kind: 'directory' | 'file';
7
- name: string;
8
- path: string;
9
- }
10
-
11
- export interface CoreProjectionDirectoryNode extends CoreProjectionBaseNode {
12
- kind: 'directory';
13
- children: CoreProjectionNode[];
14
- }
15
-
16
- export interface CoreProjectionFileNode extends CoreProjectionBaseNode {
17
- kind: 'file';
18
- }
19
-
20
- const EXCLUDED_DIRECTORY_NAMES = new Set([
21
- '.git',
22
- '.next',
23
- 'dist',
24
- 'node_modules',
25
- ]);
26
-
27
- export function toPosixPath(value: string): string {
28
- return value.split(path.sep).join('/');
29
- }
30
-
31
- export function shouldExclude(relativePath: string, isDirectory: boolean, excludedRelativePathPrefixes: string[]): boolean {
32
- if (!relativePath || relativePath === '.') {
33
- return false;
34
- }
35
-
36
- const normalizedPath = toPosixPath(relativePath);
37
- const baseName = path.posix.basename(normalizedPath);
38
-
39
- if (isDirectory && EXCLUDED_DIRECTORY_NAMES.has(baseName)) {
40
- return true;
41
- }
42
-
43
- return excludedRelativePathPrefixes.some((prefix) => {
44
- return normalizedPath === prefix || normalizedPath.startsWith(`${prefix}/`);
45
- });
46
- }
47
-
48
- export function compareNodes(a: CoreProjectionNode, b: CoreProjectionNode): number {
49
- if (a.kind !== b.kind) {
50
- return a.kind === 'directory' ? -1 : 1;
51
- }
52
- return a.name.localeCompare(b.name);
1
+ import * as path from 'node:path';
2
+
3
+ export type CoreProjectionNode = CoreProjectionDirectoryNode | CoreProjectionFileNode;
4
+
5
+ export interface CoreProjectionBaseNode {
6
+ kind: 'directory' | 'file';
7
+ name: string;
8
+ path: string;
9
+ }
10
+
11
+ export interface CoreProjectionDirectoryNode extends CoreProjectionBaseNode {
12
+ kind: 'directory';
13
+ children: CoreProjectionNode[];
14
+ }
15
+
16
+ export interface CoreProjectionFileNode extends CoreProjectionBaseNode {
17
+ kind: 'file';
18
+ }
19
+
20
+ const EXCLUDED_DIRECTORY_NAMES = new Set([
21
+ '.git',
22
+ '.next',
23
+ 'dist',
24
+ 'node_modules',
25
+ ]);
26
+
27
+ export function toPosixPath(value: string): string {
28
+ return value.split(path.sep).join('/');
29
+ }
30
+
31
+ export function shouldExclude(relativePath: string, isDirectory: boolean, excludedRelativePathPrefixes: string[]): boolean {
32
+ if (!relativePath || relativePath === '.') {
33
+ return false;
34
+ }
35
+
36
+ const normalizedPath = toPosixPath(relativePath);
37
+ const baseName = path.posix.basename(normalizedPath);
38
+
39
+ if (isDirectory && EXCLUDED_DIRECTORY_NAMES.has(baseName)) {
40
+ return true;
41
+ }
42
+
43
+ return excludedRelativePathPrefixes.some((prefix) => {
44
+ return normalizedPath === prefix || normalizedPath.startsWith(`${prefix}/`);
45
+ });
46
+ }
47
+
48
+ export function compareNodes(a: CoreProjectionNode, b: CoreProjectionNode): number {
49
+ if (a.kind !== b.kind) {
50
+ return a.kind === 'directory' ? -1 : 1;
51
+ }
52
+ return a.name.localeCompare(b.name);
53
53
  }
@@ -1,71 +1,71 @@
1
- type JsonObject = Record<string, unknown>;
2
-
3
- type SchemasDocument = {
4
- $defs?: Record<string, JsonObject>;
5
- };
6
-
7
- type ResourceTypeShell = JsonObject & {
8
- handle?: unknown;
9
- name?: unknown;
10
- description?: unknown;
11
- ingestorToolInputSchema?: unknown;
12
- };
13
-
14
- type ResourceTypeShellByName = Record<string, ResourceTypeShell>;
15
-
16
- export function generateResourceTypes(
17
- schemasDocument: SchemasDocument,
18
- resourceTypeShells: ResourceTypeShellByName,
19
- ): ResourceTypeShell[] {
20
- if (!schemasDocument.$defs || typeof schemasDocument.$defs !== 'object') {
21
- throw new Error('Schema document must have root $defs');
22
- }
23
-
24
- const resourceTypes: ResourceTypeShell[] = [];
25
-
26
- for (const [resourceTypeName, resourceTypeShell] of Object.entries(resourceTypeShells)) {
27
- const projectionSchema = schemasDocument.$defs[resourceTypeName];
28
- const ingestorToolInputSchemaDefName = resourceTypeShell.ingestorToolInputSchema;
29
-
30
- if (!projectionSchema || typeof projectionSchema !== 'object' || Array.isArray(projectionSchema)) {
31
- throw new Error(`Missing matching schema for resource type record ${resourceTypeName}`);
32
- }
33
-
34
- if (
35
- ingestorToolInputSchemaDefName !== undefined &&
36
- typeof ingestorToolInputSchemaDefName !== 'string'
37
- ) {
38
- throw new Error(
39
- `ingestorToolInputSchema for resource type record ${resourceTypeName} must be a schema definition name when present`,
40
- );
41
- }
42
-
43
- const ingestorToolInputSchema =
44
- typeof ingestorToolInputSchemaDefName === 'string'
45
- ? schemasDocument.$defs[ingestorToolInputSchemaDefName]
46
- : undefined;
47
-
48
- if (typeof ingestorToolInputSchemaDefName === 'string' && !ingestorToolInputSchema) {
49
- throw new Error(
50
- `Missing ingestor input schema ${ingestorToolInputSchemaDefName} for resource type record ${resourceTypeName}`,
51
- );
52
- }
53
-
54
- if (
55
- ingestorToolInputSchema !== undefined &&
56
- (typeof ingestorToolInputSchema !== 'object' || Array.isArray(ingestorToolInputSchema))
57
- ) {
58
- throw new Error(
59
- `Ingestor input schema ${ingestorToolInputSchemaDefName} for resource type record ${resourceTypeName} must be an object`,
60
- );
61
- }
62
-
63
- resourceTypes.push({
64
- ...resourceTypeShell,
65
- projectionSchema,
66
- ...(ingestorToolInputSchema ? { ingestorToolInputSchema } : {}),
67
- });
68
- }
69
-
70
- return resourceTypes;
1
+ type JsonObject = Record<string, unknown>;
2
+
3
+ type SchemasDocument = {
4
+ $defs?: Record<string, JsonObject>;
5
+ };
6
+
7
+ type ResourceTypeShell = JsonObject & {
8
+ handle?: unknown;
9
+ name?: unknown;
10
+ description?: unknown;
11
+ ingestorToolInputSchema?: unknown;
12
+ };
13
+
14
+ type ResourceTypeShellByName = Record<string, ResourceTypeShell>;
15
+
16
+ export function generateResourceTypes(
17
+ schemasDocument: SchemasDocument,
18
+ resourceTypeShells: ResourceTypeShellByName,
19
+ ): ResourceTypeShell[] {
20
+ if (!schemasDocument.$defs || typeof schemasDocument.$defs !== 'object') {
21
+ throw new Error('Schema document must have root $defs');
22
+ }
23
+
24
+ const resourceTypes: ResourceTypeShell[] = [];
25
+
26
+ for (const [resourceTypeName, resourceTypeShell] of Object.entries(resourceTypeShells)) {
27
+ const projectionSchema = schemasDocument.$defs[resourceTypeName];
28
+ const ingestorToolInputSchemaDefName = resourceTypeShell.ingestorToolInputSchema;
29
+
30
+ if (!projectionSchema || typeof projectionSchema !== 'object' || Array.isArray(projectionSchema)) {
31
+ throw new Error(`Missing matching schema for resource type record ${resourceTypeName}`);
32
+ }
33
+
34
+ if (
35
+ ingestorToolInputSchemaDefName !== undefined &&
36
+ typeof ingestorToolInputSchemaDefName !== 'string'
37
+ ) {
38
+ throw new Error(
39
+ `ingestorToolInputSchema for resource type record ${resourceTypeName} must be a schema definition name when present`,
40
+ );
41
+ }
42
+
43
+ const ingestorToolInputSchema =
44
+ typeof ingestorToolInputSchemaDefName === 'string'
45
+ ? schemasDocument.$defs[ingestorToolInputSchemaDefName]
46
+ : undefined;
47
+
48
+ if (typeof ingestorToolInputSchemaDefName === 'string' && !ingestorToolInputSchema) {
49
+ throw new Error(
50
+ `Missing ingestor input schema ${ingestorToolInputSchemaDefName} for resource type record ${resourceTypeName}`,
51
+ );
52
+ }
53
+
54
+ if (
55
+ ingestorToolInputSchema !== undefined &&
56
+ (typeof ingestorToolInputSchema !== 'object' || Array.isArray(ingestorToolInputSchema))
57
+ ) {
58
+ throw new Error(
59
+ `Ingestor input schema ${ingestorToolInputSchemaDefName} for resource type record ${resourceTypeName} must be an object`,
60
+ );
61
+ }
62
+
63
+ resourceTypes.push({
64
+ ...resourceTypeShell,
65
+ projectionSchema,
66
+ ...(ingestorToolInputSchema ? { ingestorToolInputSchema } : {}),
67
+ });
68
+ }
69
+
70
+ return resourceTypes;
71
71
  }
@@ -1,115 +1,115 @@
1
- type JSONValue = null | boolean | number | string | JSONValue[] | { [k: string]: JSONValue };
2
-
3
- export type DependencyMap = Record<string, string[]>;
4
-
5
- export function decodeJsonPointerSegment(segment: string): string {
6
- return segment.replace(/~1/g, '/').replace(/~0/g, '~');
7
- }
8
-
9
- export function collectRefs(node: unknown, out: Set<string>): void {
10
- if (Array.isArray(node)) {
11
- for (const item of node) collectRefs(item, out);
12
- return;
13
- }
14
- if (!node || typeof node !== 'object') return;
15
-
16
- const obj = node as Record<string, unknown>;
17
- const ref = obj.$ref;
18
- if (typeof ref === 'string') out.add(ref);
19
-
20
- for (const value of Object.values(obj)) {
21
- collectRefs(value, out);
22
- }
23
- }
24
-
25
- export function resolveInternalRefToDefKey(
26
- ref: string,
27
- defKeys: Set<string>,
28
- anchorToDef: Record<string, string>,
29
- ): string | null {
30
- if (!ref.startsWith('#')) return null;
31
-
32
- const defsPrefix = '#/$defs/';
33
- if (ref.startsWith(defsPrefix)) {
34
- const rest = ref.slice(defsPrefix.length);
35
- const firstSegment = rest.split('/')[0] ?? '';
36
- const defKey = decodeJsonPointerSegment(firstSegment);
37
- return defKeys.has(defKey) ? defKey : null;
38
- }
39
-
40
- if (!ref.startsWith('#/')) {
41
- const anchor = ref.slice(1);
42
- const mapped = anchorToDef[anchor];
43
- if (mapped && defKeys.has(mapped)) return mapped;
44
- if (defKeys.has(anchor)) return anchor;
45
- }
46
-
47
- return null;
48
- }
49
-
50
- export function generateDependencyMap(doc: { $defs?: Record<string, JSONValue> } | null | undefined): DependencyMap {
51
- const defs: Record<string, JSONValue> = doc?.$defs && typeof doc.$defs === 'object' ? doc.$defs : {};
52
- const defKeys = new Set(Object.keys(defs));
53
-
54
- const anchorToDef: Record<string, string> = {};
55
- for (const [defKey, defSchema] of Object.entries(defs)) {
56
- if (!defSchema || typeof defSchema !== 'object' || Array.isArray(defSchema)) continue;
57
- const anchor = (defSchema as { $anchor?: unknown }).$anchor;
58
- if (typeof anchor === 'string' && !(anchor in anchorToDef)) {
59
- anchorToDef[anchor] = defKey;
60
- }
61
- }
62
-
63
- const dependencyMap: DependencyMap = {};
64
-
65
- for (const [defKey, defSchema] of Object.entries(defs)) {
66
- const refs = new Set<string>();
67
- collectRefs(defSchema, refs);
68
-
69
- const deps = new Set<string>();
70
- for (const ref of refs) {
71
- const depKey = resolveInternalRefToDefKey(ref, defKeys, anchorToDef);
72
- if (!depKey || depKey === defKey) continue;
73
- deps.add(depKey);
74
- }
75
-
76
- dependencyMap[defKey] = Array.from(deps);
77
- }
78
-
79
- return dependencyMap;
80
- }
81
-
82
- export function normalizeDependencyMap(value: unknown): DependencyMap {
83
- if (!value || typeof value !== 'object' || Array.isArray(value)) {
84
- throw new Error('Invalid dependencyMap.json: expected an object');
85
- }
86
-
87
- const input = value as Record<string, unknown>;
88
- const out: DependencyMap = {};
89
-
90
- for (const [key, rawDeps] of Object.entries(input)) {
91
- if (rawDeps == null) {
92
- out[key] = [];
93
- continue;
94
- }
95
- if (!Array.isArray(rawDeps)) {
96
- throw new Error(`Invalid dependencyMap.json: value for ${key} must be an array`);
97
- }
98
- out[key] = rawDeps.filter((dep): dep is string => typeof dep === 'string');
99
- }
100
-
101
- return out;
102
- }
103
-
104
- export function computeTerminalsInKeyOrder(dependencyMap: DependencyMap): string[] {
105
- const keys = Object.keys(dependencyMap);
106
- const dependedUpon = new Set<string>();
107
-
108
- for (const key of keys) {
109
- for (const dep of dependencyMap[key] ?? []) {
110
- dependedUpon.add(dep);
111
- }
112
- }
113
-
114
- return keys.filter((key) => !dependedUpon.has(key));
1
+ type JSONValue = null | boolean | number | string | JSONValue[] | { [k: string]: JSONValue };
2
+
3
+ export type DependencyMap = Record<string, string[]>;
4
+
5
+ export function decodeJsonPointerSegment(segment: string): string {
6
+ return segment.replace(/~1/g, '/').replace(/~0/g, '~');
7
+ }
8
+
9
+ export function collectRefs(node: unknown, out: Set<string>): void {
10
+ if (Array.isArray(node)) {
11
+ for (const item of node) collectRefs(item, out);
12
+ return;
13
+ }
14
+ if (!node || typeof node !== 'object') return;
15
+
16
+ const obj = node as Record<string, unknown>;
17
+ const ref = obj.$ref;
18
+ if (typeof ref === 'string') out.add(ref);
19
+
20
+ for (const value of Object.values(obj)) {
21
+ collectRefs(value, out);
22
+ }
23
+ }
24
+
25
+ export function resolveInternalRefToDefKey(
26
+ ref: string,
27
+ defKeys: Set<string>,
28
+ anchorToDef: Record<string, string>,
29
+ ): string | null {
30
+ if (!ref.startsWith('#')) return null;
31
+
32
+ const defsPrefix = '#/$defs/';
33
+ if (ref.startsWith(defsPrefix)) {
34
+ const rest = ref.slice(defsPrefix.length);
35
+ const firstSegment = rest.split('/')[0] ?? '';
36
+ const defKey = decodeJsonPointerSegment(firstSegment);
37
+ return defKeys.has(defKey) ? defKey : null;
38
+ }
39
+
40
+ if (!ref.startsWith('#/')) {
41
+ const anchor = ref.slice(1);
42
+ const mapped = anchorToDef[anchor];
43
+ if (mapped && defKeys.has(mapped)) return mapped;
44
+ if (defKeys.has(anchor)) return anchor;
45
+ }
46
+
47
+ return null;
48
+ }
49
+
50
+ export function generateDependencyMap(doc: { $defs?: Record<string, JSONValue> } | null | undefined): DependencyMap {
51
+ const defs: Record<string, JSONValue> = doc?.$defs && typeof doc.$defs === 'object' ? doc.$defs : {};
52
+ const defKeys = new Set(Object.keys(defs));
53
+
54
+ const anchorToDef: Record<string, string> = {};
55
+ for (const [defKey, defSchema] of Object.entries(defs)) {
56
+ if (!defSchema || typeof defSchema !== 'object' || Array.isArray(defSchema)) continue;
57
+ const anchor = (defSchema as { $anchor?: unknown }).$anchor;
58
+ if (typeof anchor === 'string' && !(anchor in anchorToDef)) {
59
+ anchorToDef[anchor] = defKey;
60
+ }
61
+ }
62
+
63
+ const dependencyMap: DependencyMap = {};
64
+
65
+ for (const [defKey, defSchema] of Object.entries(defs)) {
66
+ const refs = new Set<string>();
67
+ collectRefs(defSchema, refs);
68
+
69
+ const deps = new Set<string>();
70
+ for (const ref of refs) {
71
+ const depKey = resolveInternalRefToDefKey(ref, defKeys, anchorToDef);
72
+ if (!depKey || depKey === defKey) continue;
73
+ deps.add(depKey);
74
+ }
75
+
76
+ dependencyMap[defKey] = Array.from(deps);
77
+ }
78
+
79
+ return dependencyMap;
80
+ }
81
+
82
+ export function normalizeDependencyMap(value: unknown): DependencyMap {
83
+ if (!value || typeof value !== 'object' || Array.isArray(value)) {
84
+ throw new Error('Invalid dependencyMap.json: expected an object');
85
+ }
86
+
87
+ const input = value as Record<string, unknown>;
88
+ const out: DependencyMap = {};
89
+
90
+ for (const [key, rawDeps] of Object.entries(input)) {
91
+ if (rawDeps == null) {
92
+ out[key] = [];
93
+ continue;
94
+ }
95
+ if (!Array.isArray(rawDeps)) {
96
+ throw new Error(`Invalid dependencyMap.json: value for ${key} must be an array`);
97
+ }
98
+ out[key] = rawDeps.filter((dep): dep is string => typeof dep === 'string');
99
+ }
100
+
101
+ return out;
102
+ }
103
+
104
+ export function computeTerminalsInKeyOrder(dependencyMap: DependencyMap): string[] {
105
+ const keys = Object.keys(dependencyMap);
106
+ const dependedUpon = new Set<string>();
107
+
108
+ for (const key of keys) {
109
+ for (const dep of dependencyMap[key] ?? []) {
110
+ dependedUpon.add(dep);
111
+ }
112
+ }
113
+
114
+ return keys.filter((key) => !dependedUpon.has(key));
115
115
  }
@@ -1,71 +1,71 @@
1
- export function normalizeAllOfSiblingObjectKeywords(node: any): any {
2
- if (Array.isArray(node)) {
3
- let changed = false;
4
- const out = node.map((item) => {
5
- const next = normalizeAllOfSiblingObjectKeywords(item);
6
- if (next !== item) changed = true;
7
- return next;
8
- });
9
- return changed ? out : node;
10
- }
11
- if (!node || typeof node !== 'object') return node;
12
-
13
- const hasAllOf = Array.isArray((node as any).allOf) && (node as any).allOf.length > 0;
14
- const looksLikeObjectSchema =
15
- (node as any).type === 'object' ||
16
- (node as any).properties !== undefined ||
17
- (node as any).required !== undefined ||
18
- (node as any).unevaluatedProperties !== undefined ||
19
- (node as any).additionalProperties !== undefined ||
20
- (node as any).propertyNames !== undefined;
21
-
22
- const siblingKeys = [
23
- 'type',
24
- 'properties',
25
- 'required',
26
- 'additionalProperties',
27
- 'unevaluatedProperties',
28
- 'propertyNames',
29
- 'patternProperties',
30
- 'dependentRequired',
31
- 'dependentSchemas',
32
- 'minProperties',
33
- 'maxProperties',
34
- ] as const;
35
-
36
- let localNode: any = node;
37
- if (hasAllOf && looksLikeObjectSchema) {
38
- const hasSiblingObjectKeywords = siblingKeys.some((key) => key in localNode);
39
- if (hasSiblingObjectKeywords) {
40
- const overlay: any = {};
41
- const nextNode: any = { ...localNode };
42
-
43
- for (const key of siblingKeys) {
44
- if (key in nextNode) {
45
- overlay[key] = nextNode[key];
46
- delete nextNode[key];
47
- }
48
- }
49
-
50
- nextNode.allOf = [overlay, ...(nextNode.allOf as any[])];
51
- localNode = nextNode;
52
- }
53
- }
54
-
55
- let changed = localNode !== node;
56
- const out: Record<string, any> = localNode === node ? ({} as any) : { ...localNode };
57
- for (const [key, value] of Object.entries(localNode)) {
58
- const next = normalizeAllOfSiblingObjectKeywords(value);
59
- if (next !== value) {
60
- if (!changed) {
61
- changed = true;
62
- Object.assign(out, localNode);
63
- }
64
- out[key] = next;
65
- } else if (changed) {
66
- out[key] = value;
67
- }
68
- }
69
-
70
- return changed ? out : node;
1
+ export function normalizeAllOfSiblingObjectKeywords(node: any): any {
2
+ if (Array.isArray(node)) {
3
+ let changed = false;
4
+ const out = node.map((item) => {
5
+ const next = normalizeAllOfSiblingObjectKeywords(item);
6
+ if (next !== item) changed = true;
7
+ return next;
8
+ });
9
+ return changed ? out : node;
10
+ }
11
+ if (!node || typeof node !== 'object') return node;
12
+
13
+ const hasAllOf = Array.isArray((node as any).allOf) && (node as any).allOf.length > 0;
14
+ const looksLikeObjectSchema =
15
+ (node as any).type === 'object' ||
16
+ (node as any).properties !== undefined ||
17
+ (node as any).required !== undefined ||
18
+ (node as any).unevaluatedProperties !== undefined ||
19
+ (node as any).additionalProperties !== undefined ||
20
+ (node as any).propertyNames !== undefined;
21
+
22
+ const siblingKeys = [
23
+ 'type',
24
+ 'properties',
25
+ 'required',
26
+ 'additionalProperties',
27
+ 'unevaluatedProperties',
28
+ 'propertyNames',
29
+ 'patternProperties',
30
+ 'dependentRequired',
31
+ 'dependentSchemas',
32
+ 'minProperties',
33
+ 'maxProperties',
34
+ ] as const;
35
+
36
+ let localNode: any = node;
37
+ if (hasAllOf && looksLikeObjectSchema) {
38
+ const hasSiblingObjectKeywords = siblingKeys.some((key) => key in localNode);
39
+ if (hasSiblingObjectKeywords) {
40
+ const overlay: any = {};
41
+ const nextNode: any = { ...localNode };
42
+
43
+ for (const key of siblingKeys) {
44
+ if (key in nextNode) {
45
+ overlay[key] = nextNode[key];
46
+ delete nextNode[key];
47
+ }
48
+ }
49
+
50
+ nextNode.allOf = [overlay, ...(nextNode.allOf as any[])];
51
+ localNode = nextNode;
52
+ }
53
+ }
54
+
55
+ let changed = localNode !== node;
56
+ const out: Record<string, any> = localNode === node ? ({} as any) : { ...localNode };
57
+ for (const [key, value] of Object.entries(localNode)) {
58
+ const next = normalizeAllOfSiblingObjectKeywords(value);
59
+ if (next !== value) {
60
+ if (!changed) {
61
+ changed = true;
62
+ Object.assign(out, localNode);
63
+ }
64
+ out[key] = next;
65
+ } else if (changed) {
66
+ out[key] = value;
67
+ }
68
+ }
69
+
70
+ return changed ? out : node;
71
71
  }