@xnetjs/cli 0.0.2
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/LICENSE +21 -0
- package/README.md +49 -0
- package/dist/chunk-IUOECMVU.js +314 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +890 -0
- package/dist/index.d.ts +120 -0
- package/dist/index.js +8 -0
- package/package.json +50 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { Schema } from '@xnetjs/data';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Schema Diff Utility - Compare two schema versions and identify changes.
|
|
5
|
+
*
|
|
6
|
+
* This utility analyzes the differences between two schema definitions
|
|
7
|
+
* and classifies changes by risk level for migration planning.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* const changes = diffSchemas(oldSchema, newSchema)
|
|
12
|
+
* for (const change of changes) {
|
|
13
|
+
* console.log(`${change.risk}: ${change.description}`)
|
|
14
|
+
* }
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Extended property definition that includes optional select options.
|
|
20
|
+
* This is a superset of the base PropertyDefinition from @xnetjs/data
|
|
21
|
+
* to handle select/multiSelect options which may be stored in config or directly.
|
|
22
|
+
*/
|
|
23
|
+
interface ExtendedPropertyDefinition {
|
|
24
|
+
'@id': string;
|
|
25
|
+
name: string;
|
|
26
|
+
type: string;
|
|
27
|
+
required: boolean;
|
|
28
|
+
config?: Record<string, unknown>;
|
|
29
|
+
/** Select options (may be in config or directly on definition) */
|
|
30
|
+
options?: Array<{
|
|
31
|
+
value: string;
|
|
32
|
+
label?: string;
|
|
33
|
+
}>;
|
|
34
|
+
}
|
|
35
|
+
type SchemaChangeType = 'add' | 'remove' | 'modify' | 'rename';
|
|
36
|
+
type RiskLevel = 'safe' | 'caution' | 'breaking';
|
|
37
|
+
/**
|
|
38
|
+
* A single change between two schema versions.
|
|
39
|
+
*/
|
|
40
|
+
interface SchemaChange {
|
|
41
|
+
/** Type of change */
|
|
42
|
+
type: SchemaChangeType;
|
|
43
|
+
/** Property name (or old name for renames) */
|
|
44
|
+
property: string;
|
|
45
|
+
/** New property name (for renames) */
|
|
46
|
+
newProperty?: string;
|
|
47
|
+
/** Risk level of this change */
|
|
48
|
+
risk: RiskLevel;
|
|
49
|
+
/** Human-readable description */
|
|
50
|
+
description: string;
|
|
51
|
+
/** Suggested lens operation (if applicable) */
|
|
52
|
+
suggestedLens?: string;
|
|
53
|
+
/** Old property definition (for modifications/removals) */
|
|
54
|
+
oldDefinition?: ExtendedPropertyDefinition;
|
|
55
|
+
/** New property definition (for additions/modifications) */
|
|
56
|
+
newDefinition?: ExtendedPropertyDefinition;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Result of schema comparison.
|
|
60
|
+
*/
|
|
61
|
+
interface SchemaDiffResult {
|
|
62
|
+
/** Old schema version */
|
|
63
|
+
fromVersion: string;
|
|
64
|
+
/** New schema version */
|
|
65
|
+
toVersion: string;
|
|
66
|
+
/** List of changes detected */
|
|
67
|
+
changes: SchemaChange[];
|
|
68
|
+
/** Overall risk level (highest of all changes) */
|
|
69
|
+
overallRisk: RiskLevel;
|
|
70
|
+
/** Whether automatic migration is possible */
|
|
71
|
+
autoMigratable: boolean;
|
|
72
|
+
/** Summary of changes by category */
|
|
73
|
+
summary: {
|
|
74
|
+
safe: number;
|
|
75
|
+
caution: number;
|
|
76
|
+
breaking: number;
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Compare two schema versions and identify all changes.
|
|
81
|
+
*
|
|
82
|
+
* @param oldSchema - The source schema version
|
|
83
|
+
* @param newSchema - The target schema version
|
|
84
|
+
* @returns Detailed diff result with changes and risk assessment
|
|
85
|
+
*/
|
|
86
|
+
declare function diffSchemas(oldSchema: Schema, newSchema: Schema): SchemaDiffResult;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Lens Code Generator - Generate migration lens code from schema diff.
|
|
90
|
+
*
|
|
91
|
+
* This utility generates TypeScript code for schema migration lenses
|
|
92
|
+
* based on the detected changes between two schema versions.
|
|
93
|
+
*/
|
|
94
|
+
|
|
95
|
+
interface GenerateLensOptions {
|
|
96
|
+
/** The schema diff result */
|
|
97
|
+
diff: SchemaDiffResult;
|
|
98
|
+
/** Source schema IRI */
|
|
99
|
+
sourceIRI: string;
|
|
100
|
+
/** Target schema IRI */
|
|
101
|
+
targetIRI: string;
|
|
102
|
+
/** Whether to include comments */
|
|
103
|
+
includeComments?: boolean;
|
|
104
|
+
/** Whether to include TODO markers for manual fixes */
|
|
105
|
+
includeTodos?: boolean;
|
|
106
|
+
}
|
|
107
|
+
interface GeneratedLens {
|
|
108
|
+
/** The generated TypeScript code */
|
|
109
|
+
code: string;
|
|
110
|
+
/** Whether the generated lens is complete (no TODOs) */
|
|
111
|
+
isComplete: boolean;
|
|
112
|
+
/** List of items that need manual attention */
|
|
113
|
+
manualItems: string[];
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Generate migration lens code from a schema diff.
|
|
117
|
+
*/
|
|
118
|
+
declare function generateLensCode(options: GenerateLensOptions): GeneratedLens;
|
|
119
|
+
|
|
120
|
+
export { type GenerateLensOptions, type RiskLevel, type SchemaChange, type SchemaChangeType, diffSchemas, generateLensCode };
|
package/dist/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@xnetjs/cli",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "xNet CLI - Schema migrations, diagnostics, and development tools",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/crs48/xNet"
|
|
9
|
+
},
|
|
10
|
+
"type": "module",
|
|
11
|
+
"main": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"bin": {
|
|
14
|
+
"xnet": "./dist/cli.js"
|
|
15
|
+
},
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"import": "./dist/index.js",
|
|
19
|
+
"types": "./dist/index.d.ts"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist",
|
|
24
|
+
"README.md",
|
|
25
|
+
"LICENSE"
|
|
26
|
+
],
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public",
|
|
29
|
+
"provenance": true
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"chalk": "^5.3.0",
|
|
33
|
+
"commander": "^12.0.0",
|
|
34
|
+
"@xnetjs/data": "0.0.2",
|
|
35
|
+
"@xnetjs/sync": "0.0.2"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"tsup": "^8.0.0",
|
|
39
|
+
"tsx": "^4.0.0",
|
|
40
|
+
"typescript": "^5.4.0",
|
|
41
|
+
"vitest": "^4.0.0"
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"dev": "tsx src/cli.ts",
|
|
45
|
+
"build": "tsup src/index.ts src/cli.ts --format esm --dts",
|
|
46
|
+
"test": "vitest run",
|
|
47
|
+
"typecheck": "tsc --noEmit",
|
|
48
|
+
"clean": "rm -rf dist"
|
|
49
|
+
}
|
|
50
|
+
}
|