@redush/sysconst-validator 1.0.0

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.
@@ -0,0 +1,204 @@
1
+ /**
2
+ * EvoSpec DSL Validator Types
3
+ */
4
+ type StableId = string;
5
+ type NodeKind = 'System' | 'Module' | 'Entity' | 'Enum' | 'Value' | 'Interface' | 'Command' | 'Event' | 'Query' | 'Process' | 'Step' | 'Policy' | 'Scenario' | 'Contract';
6
+ interface Meta {
7
+ title?: string;
8
+ description?: string;
9
+ tags?: string[];
10
+ }
11
+ interface Field {
12
+ type: string;
13
+ required?: boolean;
14
+ default?: unknown;
15
+ description?: string;
16
+ }
17
+ interface Relation {
18
+ to: StableId;
19
+ type: 'one-to-one' | 'one-to-many' | 'many-to-one' | 'many-to-many';
20
+ }
21
+ interface Contract {
22
+ type?: string;
23
+ invariant?: string;
24
+ temporal?: string;
25
+ rule?: string;
26
+ level?: 'hard' | 'soft';
27
+ }
28
+ interface Hook {
29
+ id: StableId;
30
+ location: {
31
+ file: string;
32
+ anchorStart: string;
33
+ anchorEnd: string;
34
+ };
35
+ contract?: {
36
+ signature?: string;
37
+ purity?: boolean;
38
+ async?: boolean;
39
+ throws?: boolean;
40
+ };
41
+ }
42
+ interface Node {
43
+ kind: NodeKind;
44
+ id: StableId;
45
+ meta?: Meta;
46
+ spec: Record<string, unknown>;
47
+ impl?: Record<string, unknown>;
48
+ facets?: Record<string, unknown>;
49
+ children?: (string | Node)[];
50
+ contracts?: Contract[];
51
+ hooks?: Hook[];
52
+ }
53
+ interface Project {
54
+ id: StableId;
55
+ name?: string;
56
+ versioning: {
57
+ strategy: 'semver';
58
+ current: string;
59
+ compatibility?: {
60
+ data?: 'forward-only' | 'bidirectional';
61
+ api?: 'no-breaking-in-minor' | 'breaking-allowed';
62
+ processes?: 'instance-pinned' | 'auto-migrate';
63
+ };
64
+ };
65
+ }
66
+ interface Structure {
67
+ root: string;
68
+ }
69
+ interface Domain {
70
+ nodes: Node[];
71
+ }
72
+ interface Zone {
73
+ path: string;
74
+ mode: 'overwrite' | 'anchored' | 'preserve' | 'spec-controlled';
75
+ }
76
+ interface Pipeline {
77
+ cmd: string;
78
+ }
79
+ interface Generation {
80
+ monorepo?: {
81
+ layout?: {
82
+ apps?: Record<string, string>;
83
+ libs?: Record<string, string>;
84
+ };
85
+ };
86
+ zones?: Zone[];
87
+ hooks?: Hook[];
88
+ pipelines?: {
89
+ build?: Pipeline;
90
+ test?: Pipeline;
91
+ e2e?: Pipeline;
92
+ migrate?: Pipeline;
93
+ lint?: Pipeline;
94
+ };
95
+ verification?: {
96
+ required?: string[];
97
+ optional?: string[];
98
+ };
99
+ }
100
+ interface Change {
101
+ op: string;
102
+ target: StableId;
103
+ field?: string;
104
+ type?: string;
105
+ required?: boolean;
106
+ from?: string;
107
+ to?: string;
108
+ }
109
+ interface MigrationStep {
110
+ backfill?: {
111
+ entity: StableId;
112
+ set: Record<string, unknown>;
113
+ };
114
+ sql?: string;
115
+ script?: string;
116
+ }
117
+ interface Migration {
118
+ id: StableId;
119
+ kind: 'data' | 'schema' | 'process';
120
+ steps: MigrationStep[];
121
+ validate?: {
122
+ assert: string;
123
+ }[];
124
+ }
125
+ interface HistoryEntry {
126
+ version: string;
127
+ basedOn: string | null;
128
+ changes: Change[];
129
+ migrations: Migration[];
130
+ notes?: string;
131
+ }
132
+ interface Tests {
133
+ scenarios?: string[];
134
+ }
135
+ interface DocPack {
136
+ id: StableId;
137
+ include: Record<string, unknown>;
138
+ }
139
+ interface Docs {
140
+ packs?: DocPack[];
141
+ }
142
+ interface EvoSpec {
143
+ spec: 'sysconst/v1';
144
+ project: Project;
145
+ structure: Structure;
146
+ domain: Domain;
147
+ generation?: Generation;
148
+ history?: HistoryEntry[];
149
+ tests?: Tests;
150
+ docs?: Docs;
151
+ }
152
+ type ErrorCode = 'STRUCTURAL_ERROR' | 'MISSING_SPEC_VERSION' | 'INVALID_SPEC_VERSION' | 'MISSING_PROJECT' | 'MISSING_PROJECT_ID' | 'MISSING_VERSIONING' | 'MISSING_CURRENT_VERSION' | 'MISSING_STRUCTURE' | 'MISSING_STRUCTURE_ROOT' | 'MISSING_DOMAIN' | 'MISSING_DOMAIN_NODES' | 'INVALID_NODE' | 'MISSING_NODE_KIND' | 'INVALID_NODE_KIND' | 'MISSING_NODE_ID' | 'INVALID_NODE_ID' | 'MISSING_NODE_SPEC' | 'DUPLICATE_NODE_ID' | 'REFERENCE_ERROR' | 'UNRESOLVED_NODEREF' | 'UNRESOLVED_ROOT' | 'INVALID_ROOT_KIND' | 'CIRCULAR_CHILDREN' | 'MISSING_RENAME_OP' | 'MISSING_REMOVE_OP' | 'SEMANTIC_ERROR' | 'ENTITY_MISSING_FIELDS' | 'FIELD_MISSING_TYPE' | 'INVALID_FIELD_TYPE' | 'UNRESOLVED_REF_TYPE' | 'UNRESOLVED_ENUM_TYPE' | 'COMMAND_MISSING_INPUT' | 'EVENT_MISSING_PAYLOAD' | 'QUERY_MISSING_INPUT' | 'QUERY_MISSING_OUTPUT' | 'PROCESS_MISSING_TRIGGER' | 'INVALID_PROCESS_TRIGGER' | 'INVALID_PROCESS_CHILDREN' | 'SCENARIO_MISSING_GIVEN' | 'SCENARIO_MISSING_WHEN' | 'SCENARIO_MISSING_THEN' | 'INVALID_CONTRACT' | 'INVALID_INVARIANT' | 'INVALID_TEMPORAL' | 'UNRESOLVED_EFFECT_EVENT' | 'UNRESOLVED_EFFECT_ENTITY' | 'EVOLUTION_ERROR' | 'INVALID_HISTORY_START' | 'BROKEN_HISTORY_CHAIN' | 'VERSION_MISMATCH' | 'UNDECLARED_CHANGE' | 'MISSING_MIGRATION' | 'INVALID_MIGRATION' | 'MIGRATION_MISSING_ID' | 'MIGRATION_MISSING_KIND' | 'MIGRATION_MISSING_STEPS' | 'INVALID_MIGRATION_KIND' | 'MIGRATION_VIOLATES_INVARIANT' | 'GENERATION_ERROR' | 'UNCOVERED_FILE' | 'OVERLAPPING_ZONES' | 'PRESERVE_ZONE_MODIFIED' | 'HOOK_IN_OVERWRITE' | 'DUPLICATE_HOOK_ID' | 'INVALID_HOOK_ANCHORS' | 'HOOK_CONTENT_MODIFIED' | 'HOOK_ANCHOR_DELETED' | 'HOOK_CONTRACT_VIOLATED' | 'VERIFICATION_ERROR' | 'MISSING_BUILD_PIPELINE' | 'MISSING_TEST_PIPELINE' | 'MISSING_MIGRATE_PIPELINE' | 'EMPTY_PIPELINE_CMD' | 'SCENARIO_INVALID_ENTITY' | 'SCENARIO_INVALID_COMMAND' | 'SCENARIO_INVALID_EVENT' | 'LOW_SCENARIO_COVERAGE' | 'UNVERIFIED_CONTRACT' | 'CONTRACT_VIOLATION' | 'INVARIANT_VIOLATION' | 'TEMPORAL_VIOLATION' | 'API_COMPAT_VIOLATION' | 'POLICY_VIOLATION';
153
+ type ErrorLevel = 'hard' | 'soft';
154
+ type ValidationPhase = 1 | 2 | 3 | 4 | 5 | 6;
155
+ interface ValidationError {
156
+ code: ErrorCode;
157
+ phase: ValidationPhase;
158
+ level: ErrorLevel;
159
+ message: string;
160
+ location: string;
161
+ suggestion?: string;
162
+ context?: Record<string, unknown>;
163
+ }
164
+ interface ValidationResult {
165
+ ok: boolean;
166
+ errors: ValidationError[];
167
+ warnings: ValidationError[];
168
+ phase: ValidationPhase;
169
+ }
170
+ interface ValidateOptions {
171
+ phases?: ValidationPhase[];
172
+ strict?: boolean;
173
+ }
174
+
175
+ /**
176
+ * EvoSpec DSL Validator
177
+ *
178
+ * Validates EvoSpec specifications through 6 phases:
179
+ * 1. Structural - syntax and required fields
180
+ * 2. Referential - references and identity
181
+ * 3. Semantic - kind-specific rules
182
+ * 4. Evolution - version history and migrations
183
+ * 5. Generation - code generation safety
184
+ * 6. Verifiability - pipelines and scenarios
185
+ */
186
+
187
+ /**
188
+ * Validate an EvoSpec specification
189
+ */
190
+ declare function validate(spec: unknown, options?: ValidateOptions): ValidationResult;
191
+ /**
192
+ * Validate a specific phase only
193
+ */
194
+ declare function validatePhase(spec: unknown, phase: ValidationPhase): ValidationError[];
195
+ /**
196
+ * Parse YAML string to spec object
197
+ */
198
+ declare function parseSpec(yaml: string): unknown;
199
+ /**
200
+ * Validate YAML string
201
+ */
202
+ declare function validateYaml(yaml: string, options?: ValidateOptions): ValidationResult;
203
+
204
+ export { type Change, type Contract, type DocPack, type Docs, type Domain, type ErrorCode, type ErrorLevel, type EvoSpec, type Field, type Generation, type HistoryEntry, type Hook, type Meta, type Migration, type MigrationStep, type Node, type NodeKind, type Pipeline, type Project, type Relation, type StableId, type Structure, type Tests, type ValidateOptions, type ValidationError, type ValidationPhase, type ValidationResult, type Zone, parseSpec, validate, validatePhase, validateYaml };
@@ -0,0 +1,204 @@
1
+ /**
2
+ * EvoSpec DSL Validator Types
3
+ */
4
+ type StableId = string;
5
+ type NodeKind = 'System' | 'Module' | 'Entity' | 'Enum' | 'Value' | 'Interface' | 'Command' | 'Event' | 'Query' | 'Process' | 'Step' | 'Policy' | 'Scenario' | 'Contract';
6
+ interface Meta {
7
+ title?: string;
8
+ description?: string;
9
+ tags?: string[];
10
+ }
11
+ interface Field {
12
+ type: string;
13
+ required?: boolean;
14
+ default?: unknown;
15
+ description?: string;
16
+ }
17
+ interface Relation {
18
+ to: StableId;
19
+ type: 'one-to-one' | 'one-to-many' | 'many-to-one' | 'many-to-many';
20
+ }
21
+ interface Contract {
22
+ type?: string;
23
+ invariant?: string;
24
+ temporal?: string;
25
+ rule?: string;
26
+ level?: 'hard' | 'soft';
27
+ }
28
+ interface Hook {
29
+ id: StableId;
30
+ location: {
31
+ file: string;
32
+ anchorStart: string;
33
+ anchorEnd: string;
34
+ };
35
+ contract?: {
36
+ signature?: string;
37
+ purity?: boolean;
38
+ async?: boolean;
39
+ throws?: boolean;
40
+ };
41
+ }
42
+ interface Node {
43
+ kind: NodeKind;
44
+ id: StableId;
45
+ meta?: Meta;
46
+ spec: Record<string, unknown>;
47
+ impl?: Record<string, unknown>;
48
+ facets?: Record<string, unknown>;
49
+ children?: (string | Node)[];
50
+ contracts?: Contract[];
51
+ hooks?: Hook[];
52
+ }
53
+ interface Project {
54
+ id: StableId;
55
+ name?: string;
56
+ versioning: {
57
+ strategy: 'semver';
58
+ current: string;
59
+ compatibility?: {
60
+ data?: 'forward-only' | 'bidirectional';
61
+ api?: 'no-breaking-in-minor' | 'breaking-allowed';
62
+ processes?: 'instance-pinned' | 'auto-migrate';
63
+ };
64
+ };
65
+ }
66
+ interface Structure {
67
+ root: string;
68
+ }
69
+ interface Domain {
70
+ nodes: Node[];
71
+ }
72
+ interface Zone {
73
+ path: string;
74
+ mode: 'overwrite' | 'anchored' | 'preserve' | 'spec-controlled';
75
+ }
76
+ interface Pipeline {
77
+ cmd: string;
78
+ }
79
+ interface Generation {
80
+ monorepo?: {
81
+ layout?: {
82
+ apps?: Record<string, string>;
83
+ libs?: Record<string, string>;
84
+ };
85
+ };
86
+ zones?: Zone[];
87
+ hooks?: Hook[];
88
+ pipelines?: {
89
+ build?: Pipeline;
90
+ test?: Pipeline;
91
+ e2e?: Pipeline;
92
+ migrate?: Pipeline;
93
+ lint?: Pipeline;
94
+ };
95
+ verification?: {
96
+ required?: string[];
97
+ optional?: string[];
98
+ };
99
+ }
100
+ interface Change {
101
+ op: string;
102
+ target: StableId;
103
+ field?: string;
104
+ type?: string;
105
+ required?: boolean;
106
+ from?: string;
107
+ to?: string;
108
+ }
109
+ interface MigrationStep {
110
+ backfill?: {
111
+ entity: StableId;
112
+ set: Record<string, unknown>;
113
+ };
114
+ sql?: string;
115
+ script?: string;
116
+ }
117
+ interface Migration {
118
+ id: StableId;
119
+ kind: 'data' | 'schema' | 'process';
120
+ steps: MigrationStep[];
121
+ validate?: {
122
+ assert: string;
123
+ }[];
124
+ }
125
+ interface HistoryEntry {
126
+ version: string;
127
+ basedOn: string | null;
128
+ changes: Change[];
129
+ migrations: Migration[];
130
+ notes?: string;
131
+ }
132
+ interface Tests {
133
+ scenarios?: string[];
134
+ }
135
+ interface DocPack {
136
+ id: StableId;
137
+ include: Record<string, unknown>;
138
+ }
139
+ interface Docs {
140
+ packs?: DocPack[];
141
+ }
142
+ interface EvoSpec {
143
+ spec: 'sysconst/v1';
144
+ project: Project;
145
+ structure: Structure;
146
+ domain: Domain;
147
+ generation?: Generation;
148
+ history?: HistoryEntry[];
149
+ tests?: Tests;
150
+ docs?: Docs;
151
+ }
152
+ type ErrorCode = 'STRUCTURAL_ERROR' | 'MISSING_SPEC_VERSION' | 'INVALID_SPEC_VERSION' | 'MISSING_PROJECT' | 'MISSING_PROJECT_ID' | 'MISSING_VERSIONING' | 'MISSING_CURRENT_VERSION' | 'MISSING_STRUCTURE' | 'MISSING_STRUCTURE_ROOT' | 'MISSING_DOMAIN' | 'MISSING_DOMAIN_NODES' | 'INVALID_NODE' | 'MISSING_NODE_KIND' | 'INVALID_NODE_KIND' | 'MISSING_NODE_ID' | 'INVALID_NODE_ID' | 'MISSING_NODE_SPEC' | 'DUPLICATE_NODE_ID' | 'REFERENCE_ERROR' | 'UNRESOLVED_NODEREF' | 'UNRESOLVED_ROOT' | 'INVALID_ROOT_KIND' | 'CIRCULAR_CHILDREN' | 'MISSING_RENAME_OP' | 'MISSING_REMOVE_OP' | 'SEMANTIC_ERROR' | 'ENTITY_MISSING_FIELDS' | 'FIELD_MISSING_TYPE' | 'INVALID_FIELD_TYPE' | 'UNRESOLVED_REF_TYPE' | 'UNRESOLVED_ENUM_TYPE' | 'COMMAND_MISSING_INPUT' | 'EVENT_MISSING_PAYLOAD' | 'QUERY_MISSING_INPUT' | 'QUERY_MISSING_OUTPUT' | 'PROCESS_MISSING_TRIGGER' | 'INVALID_PROCESS_TRIGGER' | 'INVALID_PROCESS_CHILDREN' | 'SCENARIO_MISSING_GIVEN' | 'SCENARIO_MISSING_WHEN' | 'SCENARIO_MISSING_THEN' | 'INVALID_CONTRACT' | 'INVALID_INVARIANT' | 'INVALID_TEMPORAL' | 'UNRESOLVED_EFFECT_EVENT' | 'UNRESOLVED_EFFECT_ENTITY' | 'EVOLUTION_ERROR' | 'INVALID_HISTORY_START' | 'BROKEN_HISTORY_CHAIN' | 'VERSION_MISMATCH' | 'UNDECLARED_CHANGE' | 'MISSING_MIGRATION' | 'INVALID_MIGRATION' | 'MIGRATION_MISSING_ID' | 'MIGRATION_MISSING_KIND' | 'MIGRATION_MISSING_STEPS' | 'INVALID_MIGRATION_KIND' | 'MIGRATION_VIOLATES_INVARIANT' | 'GENERATION_ERROR' | 'UNCOVERED_FILE' | 'OVERLAPPING_ZONES' | 'PRESERVE_ZONE_MODIFIED' | 'HOOK_IN_OVERWRITE' | 'DUPLICATE_HOOK_ID' | 'INVALID_HOOK_ANCHORS' | 'HOOK_CONTENT_MODIFIED' | 'HOOK_ANCHOR_DELETED' | 'HOOK_CONTRACT_VIOLATED' | 'VERIFICATION_ERROR' | 'MISSING_BUILD_PIPELINE' | 'MISSING_TEST_PIPELINE' | 'MISSING_MIGRATE_PIPELINE' | 'EMPTY_PIPELINE_CMD' | 'SCENARIO_INVALID_ENTITY' | 'SCENARIO_INVALID_COMMAND' | 'SCENARIO_INVALID_EVENT' | 'LOW_SCENARIO_COVERAGE' | 'UNVERIFIED_CONTRACT' | 'CONTRACT_VIOLATION' | 'INVARIANT_VIOLATION' | 'TEMPORAL_VIOLATION' | 'API_COMPAT_VIOLATION' | 'POLICY_VIOLATION';
153
+ type ErrorLevel = 'hard' | 'soft';
154
+ type ValidationPhase = 1 | 2 | 3 | 4 | 5 | 6;
155
+ interface ValidationError {
156
+ code: ErrorCode;
157
+ phase: ValidationPhase;
158
+ level: ErrorLevel;
159
+ message: string;
160
+ location: string;
161
+ suggestion?: string;
162
+ context?: Record<string, unknown>;
163
+ }
164
+ interface ValidationResult {
165
+ ok: boolean;
166
+ errors: ValidationError[];
167
+ warnings: ValidationError[];
168
+ phase: ValidationPhase;
169
+ }
170
+ interface ValidateOptions {
171
+ phases?: ValidationPhase[];
172
+ strict?: boolean;
173
+ }
174
+
175
+ /**
176
+ * EvoSpec DSL Validator
177
+ *
178
+ * Validates EvoSpec specifications through 6 phases:
179
+ * 1. Structural - syntax and required fields
180
+ * 2. Referential - references and identity
181
+ * 3. Semantic - kind-specific rules
182
+ * 4. Evolution - version history and migrations
183
+ * 5. Generation - code generation safety
184
+ * 6. Verifiability - pipelines and scenarios
185
+ */
186
+
187
+ /**
188
+ * Validate an EvoSpec specification
189
+ */
190
+ declare function validate(spec: unknown, options?: ValidateOptions): ValidationResult;
191
+ /**
192
+ * Validate a specific phase only
193
+ */
194
+ declare function validatePhase(spec: unknown, phase: ValidationPhase): ValidationError[];
195
+ /**
196
+ * Parse YAML string to spec object
197
+ */
198
+ declare function parseSpec(yaml: string): unknown;
199
+ /**
200
+ * Validate YAML string
201
+ */
202
+ declare function validateYaml(yaml: string, options?: ValidateOptions): ValidationResult;
203
+
204
+ export { type Change, type Contract, type DocPack, type Docs, type Domain, type ErrorCode, type ErrorLevel, type EvoSpec, type Field, type Generation, type HistoryEntry, type Hook, type Meta, type Migration, type MigrationStep, type Node, type NodeKind, type Pipeline, type Project, type Relation, type StableId, type Structure, type Tests, type ValidateOptions, type ValidationError, type ValidationPhase, type ValidationResult, type Zone, parseSpec, validate, validatePhase, validateYaml };