speckeeper 0.18.2 → 0.19.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.
- package/README.md +21 -15
- package/cli-contract.yaml +12 -50
- package/dist/{config-api-Cb0MQ5Z3.d.ts → config-api-BVPg8Ewm.d.ts} +1 -11
- package/dist/dsl/index.d.ts +2 -2
- package/dist/external/insight-provider.d.ts +1 -1
- package/dist/external/insight-provider.js +3 -3
- package/dist/index.d.ts +5 -4
- package/dist/index.js +15 -82
- package/dist/{relation-C3TpA8D3.d.ts → relation-FGdEl6Yg.d.ts} +2 -1
- package/dist/speckeeper.bundle.mjs +4260 -90961
- package/docs/cli-reference.md +10 -14
- package/docs/design/cli-commands.md +10 -20
- package/docs/design/functional-requirements.md +3 -3
- package/docs/design/nonfunctional-requirements.md +3 -2
- package/docs/design/test-refs.md +28 -3
- package/docs/design/usecases.md +2 -2
- package/docs/framework_requirements_spec.md +15 -18
- package/docs/model-guide.md +4 -12
- package/package.json +4 -5
- package/specs/index.json +96 -80
package/README.md
CHANGED
|
@@ -142,7 +142,7 @@ export default defineSpecs(
|
|
|
142
142
|
npx speckeeper lint
|
|
143
143
|
|
|
144
144
|
# Check test coverage against requirements
|
|
145
|
-
npx speckeeper check
|
|
145
|
+
npx speckeeper check --coverage
|
|
146
146
|
|
|
147
147
|
# Analyze change impact
|
|
148
148
|
npx speckeeper impact FR-001
|
|
@@ -166,7 +166,7 @@ npx speckeeper audit-requirements --adapter openai
|
|
|
166
166
|
| `speckeeper build` | Generate `docs/` and `specs/` from TypeScript models |
|
|
167
167
|
| `speckeeper lint` | Validate design integrity (ID uniqueness, references, phase gates) |
|
|
168
168
|
| `speckeeper check` | Verify consistency with external SSOT |
|
|
169
|
-
| `speckeeper check
|
|
169
|
+
| `speckeeper check --coverage` | Verify test coverage for requirements |
|
|
170
170
|
| `speckeeper drift` | Detect manual edits to generated `docs/` files |
|
|
171
171
|
| `speckeeper impact <id>` | Analyze change impact for a specific element |
|
|
172
172
|
| `speckeeper new <type>` | Create a new element with auto-generated ID |
|
|
@@ -313,7 +313,8 @@ Checks include:
|
|
|
313
313
|
- **ID uniqueness** — No duplicate IDs within model types
|
|
314
314
|
- **ID conventions** — Enforce naming patterns (e.g., `FR-001`, `COMP-AUTH`)
|
|
315
315
|
- **Reference integrity** — All referenced IDs must exist
|
|
316
|
-
- **
|
|
316
|
+
- **Relation level constraints** — Each relation type allows only some model levels for its source and target (see [Relation Types](#relation-types))
|
|
317
|
+
- **Circular dependency detection** — No cycle through one-way relations (`relatedTo` and `traces` link both ways and are not followed)
|
|
317
318
|
- **Phase gates** — Ensure TBD items are resolved by target phase
|
|
318
319
|
- **Custom lint rules** — Define model-specific validation
|
|
319
320
|
|
|
@@ -506,7 +507,7 @@ The check exits 1 when the transitive coverage, or any per-model coverage checke
|
|
|
506
507
|
(it would otherwise measure nothing and pass).
|
|
507
508
|
|
|
508
509
|
```bash
|
|
509
|
-
$ npx speckeeper check
|
|
510
|
+
$ npx speckeeper check --coverage
|
|
510
511
|
|
|
511
512
|
Transitive coverage (via satisfies)
|
|
512
513
|
─────────────────────────────────────
|
|
@@ -542,17 +543,22 @@ FR-001 (Requirement)
|
|
|
542
543
|
|
|
543
544
|
### Relation Types
|
|
544
545
|
|
|
545
|
-
| Relation |
|
|
546
|
-
|
|
547
|
-
| `implements` |
|
|
548
|
-
| `
|
|
549
|
-
| `
|
|
550
|
-
| `
|
|
551
|
-
| `
|
|
552
|
-
| `dependsOn` |
|
|
553
|
-
| `
|
|
554
|
-
|
|
555
|
-
|
|
546
|
+
| Relation | Levels lint allows (source → target) | Description |
|
|
547
|
+
|----------|--------------------------------------|-------------|
|
|
548
|
+
| `implements` | more concrete → L1 | Design or implementation implements a requirement |
|
|
549
|
+
| `satisfies` | same or more concrete → L0, L1 | Satisfies a use case or requirement |
|
|
550
|
+
| `refines` | more concrete → L0, L1 | Refines a more abstract element (not one of the same level) |
|
|
551
|
+
| `verifies` | any → L0, L1 | Test verifies a requirement or use case |
|
|
552
|
+
| `verifiedBy` | any → L2, L3 | Spec is verified by test code |
|
|
553
|
+
| `dependsOn` | same or more concrete → any | Dependency, including between elements of the same level |
|
|
554
|
+
| `uses` | any → any | Runtime reference |
|
|
555
|
+
| `includes` | same level | A whole contains its part |
|
|
556
|
+
| `traces` | any → any | Tracking link, both ways |
|
|
557
|
+
| `relatedTo` | any → any | Association, both ways |
|
|
558
|
+
|
|
559
|
+
The levels are the `modelLevel` of the models (L0 business, L1 requirements, L2 design, L3 detailed design and implementation); a relation that touches a model without a level is not checked.
|
|
560
|
+
|
|
561
|
+
See [FR-701 in the framework specification](./docs/framework_requirements_spec.md#fr-701-inter-model-relations) for the level model and the cycle rules.
|
|
556
562
|
|
|
557
563
|
## Customizing Models
|
|
558
564
|
|
package/cli-contract.yaml
CHANGED
|
@@ -3,7 +3,7 @@ cli_contracts: 0.1.0
|
|
|
3
3
|
|
|
4
4
|
info:
|
|
5
5
|
title: speckeeper CLI
|
|
6
|
-
version: 0.
|
|
6
|
+
version: 0.19.0
|
|
7
7
|
description: >-
|
|
8
8
|
TypeScript-first specification validation framework — validate design
|
|
9
9
|
consistency, external SSOT integrity, and traceability with type-safe
|
|
@@ -120,12 +120,11 @@ command_sets:
|
|
|
120
120
|
build:
|
|
121
121
|
summary: Generate docs/ and specs/ from TypeScript models.
|
|
122
122
|
description: >-
|
|
123
|
-
Loads the design TypeScript models and generates machine-readable
|
|
124
|
-
specs/
|
|
125
|
-
markdown, JSON, or both formats.
|
|
123
|
+
Loads the design TypeScript models and generates the machine-readable
|
|
124
|
+
specs/ and the human-readable docs/ output.
|
|
126
125
|
usage:
|
|
127
126
|
- speckeeper build
|
|
128
|
-
- speckeeper build --
|
|
127
|
+
- speckeeper build --output ./out
|
|
129
128
|
- speckeeper build --verbose
|
|
130
129
|
|
|
131
130
|
effects:
|
|
@@ -150,30 +149,12 @@ command_sets:
|
|
|
150
149
|
|
|
151
150
|
- name: output
|
|
152
151
|
aliases: [o]
|
|
153
|
-
description: Base
|
|
152
|
+
description: Base directory the docs/ and specs/ trees are written under.
|
|
154
153
|
value_name: path
|
|
155
154
|
schema:
|
|
156
155
|
type: string
|
|
157
156
|
default: "."
|
|
158
157
|
|
|
159
|
-
- name: format
|
|
160
|
-
aliases: [f]
|
|
161
|
-
description: "Output format: markdown, json, both."
|
|
162
|
-
value_name: format
|
|
163
|
-
schema:
|
|
164
|
-
type: string
|
|
165
|
-
default: both
|
|
166
|
-
enum: [markdown, json, both]
|
|
167
|
-
|
|
168
|
-
- name: watch
|
|
169
|
-
aliases: [w]
|
|
170
|
-
description: Watch for changes and auto-regenerate.
|
|
171
|
-
schema:
|
|
172
|
-
type: boolean
|
|
173
|
-
default: false
|
|
174
|
-
effects:
|
|
175
|
-
executionMode: watch
|
|
176
|
-
|
|
177
158
|
- name: verbose
|
|
178
159
|
aliases: [v]
|
|
179
160
|
description: Show detailed output.
|
|
@@ -324,18 +305,18 @@ command_sets:
|
|
|
324
305
|
Sources include OpenAPI, DDL, annotations, and custom scanners.
|
|
325
306
|
usage:
|
|
326
307
|
- speckeeper check
|
|
327
|
-
- speckeeper check
|
|
328
|
-
- speckeeper check
|
|
308
|
+
- speckeeper check openapi --verbose
|
|
309
|
+
- speckeeper check --coverage
|
|
329
310
|
|
|
330
311
|
arguments:
|
|
331
312
|
- name: type
|
|
332
313
|
index: 0
|
|
333
314
|
required: false
|
|
334
315
|
description: >-
|
|
335
|
-
|
|
316
|
+
Source type to scan: the type of a configured source (built in:
|
|
317
|
+
openapi, ddl, annotation), or all, the default.
|
|
336
318
|
schema:
|
|
337
319
|
type: string
|
|
338
|
-
enum: [external-ssot, openapi, ddl, iac, custom, all, test]
|
|
339
320
|
|
|
340
321
|
options:
|
|
341
322
|
- name: config
|
|
@@ -404,19 +385,11 @@ command_sets:
|
|
|
404
385
|
index: 0
|
|
405
386
|
required: true
|
|
406
387
|
description: >-
|
|
407
|
-
Element type to create.
|
|
388
|
+
Element type to create: the ID of a model the config registers.
|
|
408
389
|
schema:
|
|
409
390
|
type: string
|
|
410
|
-
enum: [requirement, usecase, entity, component, screen, flow, error-case, term]
|
|
411
391
|
|
|
412
392
|
options:
|
|
413
|
-
- name: kind
|
|
414
|
-
aliases: [k]
|
|
415
|
-
description: Sub-kind (e.g. functional, non-functional for requirements).
|
|
416
|
-
value_name: kind
|
|
417
|
-
schema:
|
|
418
|
-
type: string
|
|
419
|
-
|
|
420
393
|
- name: name
|
|
421
394
|
aliases: [n]
|
|
422
395
|
description: Name of the element.
|
|
@@ -431,17 +404,6 @@ command_sets:
|
|
|
431
404
|
schema:
|
|
432
405
|
type: string
|
|
433
406
|
|
|
434
|
-
- name: template
|
|
435
|
-
aliases: [t]
|
|
436
|
-
description: Path to template file.
|
|
437
|
-
value_name: path
|
|
438
|
-
schema:
|
|
439
|
-
type: string
|
|
440
|
-
file:
|
|
441
|
-
mode: read
|
|
442
|
-
exists: true
|
|
443
|
-
encoding: utf-8
|
|
444
|
-
|
|
445
407
|
- name: dry-run
|
|
446
408
|
description: Preview generated file content without writing.
|
|
447
409
|
schema:
|
|
@@ -455,7 +417,7 @@ command_sets:
|
|
|
455
417
|
format: text
|
|
456
418
|
|
|
457
419
|
'1':
|
|
458
|
-
description: Creation failed.
|
|
420
|
+
description: Creation failed (the type is not a model the config registers, or the file exists).
|
|
459
421
|
stderr:
|
|
460
422
|
format: text
|
|
461
423
|
|
|
@@ -1064,7 +1026,7 @@ command_sets:
|
|
|
1064
1026
|
format: text
|
|
1065
1027
|
|
|
1066
1028
|
'2':
|
|
1067
|
-
description:
|
|
1029
|
+
description: Input error (no input on stdin, or an invalid argument).
|
|
1068
1030
|
stderr:
|
|
1069
1031
|
format: text
|
|
1070
1032
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z, ZodType } from 'zod';
|
|
2
|
-
import { M as ModelLevel
|
|
2
|
+
import { M as ModelLevel } from './relation-FGdEl6Yg.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* The output a judge returns for one packet.
|
|
@@ -450,16 +450,6 @@ declare abstract class Model<TSchema extends ZodType> {
|
|
|
450
450
|
* Execute lint for multiple specs
|
|
451
451
|
*/
|
|
452
452
|
lintAll(specs: z.infer<TSchema>[]): LintResult[];
|
|
453
|
-
/**
|
|
454
|
-
* Validate level constraints of relations
|
|
455
|
-
* @param spec - Spec instance (if it has relations property)
|
|
456
|
-
* @returns Array of validation errors
|
|
457
|
-
*/
|
|
458
|
-
validateRelations(spec: z.infer<TSchema>): RelationValidationError[];
|
|
459
|
-
/**
|
|
460
|
-
* Validate relations of multiple specs (including circular reference check)
|
|
461
|
-
*/
|
|
462
|
-
validateAllRelations(specs: z.infer<TSchema>[]): RelationValidationError[];
|
|
463
453
|
/**
|
|
464
454
|
* Export in specified format (single spec)
|
|
465
455
|
*/
|
package/dist/dsl/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { L as LintRule, E as Exporter, C as CoverageChecker, A as ArtifactConfig, S as SourceMatch, a as SourceScanner, D as DeepValidationConfig, b as CheckResult, c as SourceConfig } from '../config-api-
|
|
3
|
-
import '../relation-
|
|
2
|
+
import { L as LintRule, E as Exporter, C as CoverageChecker, A as ArtifactConfig, S as SourceMatch, a as SourceScanner, D as DeepValidationConfig, b as CheckResult, c as SourceConfig } from '../config-api-BVPg8Ewm.js';
|
|
3
|
+
import '../relation-FGdEl6Yg.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Core DSL — Base spec schema
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { readFileSync, existsSync } from 'fs';
|
|
2
2
|
import { resolve, relative, dirname, join } from 'path';
|
|
3
|
-
import { fileURLToPath } from 'url';
|
|
3
|
+
import { fileURLToPath, pathToFileURL } from 'url';
|
|
4
4
|
import { parse } from 'yaml';
|
|
5
5
|
import { z } from 'zod';
|
|
6
6
|
|
|
@@ -146,7 +146,7 @@ function mergeOverDefaults(parsed, resolvedPath) {
|
|
|
146
146
|
return { ...defaultConfig, ...parsed };
|
|
147
147
|
}
|
|
148
148
|
async function loadConfig(configPath, cwd = process.cwd()) {
|
|
149
|
-
const resolvedPath = configPath
|
|
149
|
+
const resolvedPath = configPath !== void 0 ? resolve(cwd, configPath) : findConfigFile(cwd);
|
|
150
150
|
if (!resolvedPath) {
|
|
151
151
|
return { ...defaultConfig };
|
|
152
152
|
}
|
|
@@ -161,7 +161,7 @@ async function loadConfig(configPath, cwd = process.cwd()) {
|
|
|
161
161
|
return mergeOverDefaults(JSON.parse(content), resolvedPath);
|
|
162
162
|
}
|
|
163
163
|
if (ext === "ts" || ext === "js") {
|
|
164
|
-
const module = await import(resolvedPath);
|
|
164
|
+
const module = await import(pathToFileURL(resolvedPath).href);
|
|
165
165
|
return mergeOverDefaults(module.default ?? module, resolvedPath);
|
|
166
166
|
}
|
|
167
167
|
} catch (error) {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { d as CheckContext, e as CheckResult, f as ExportContext, M as ModelDefinition, g as MetaModelRegistry, h as LintContext, i as LintRule, j as LintIssue, R as ReferenceGraphEdge, k as ContextProvider, c as SourceConfig, P as Phase, l as SpecEntry, m as SpeckeeperConfigInput } from './config-api-
|
|
2
|
-
export { n as APIRefId, o as ActorId, A as ArtifactConfig, B as BaseModelInstance, p as BatchRefId, q as BoundaryId, r as CheckError, s as CheckErrorSchema, b as CheckResult, t as CheckResultSchema, u as CheckWarning, v as CheckWarningSchema, w as ComponentId, x as ConcretizationSlot, y as ConcretizationSlotSchema, z as ConcretizationSlotsFieldSchema, F as ContextResult, C as CoverageChecker, G as CoverageResult, H as DDLValidationMapping, I as DTORequirementId, D as DeepValidationConfig, J as DeepValidationRule, K as EntityId, N as ErrorCaseId, O as EventRequirementId, E as Exporter, Q as ExternalChecker, T as ExternalConstraint, U as ExternalSsotPaths, V as FormId, W as ID_PATTERNS, X as IaCRefId, Y as InferModelType, Z as JsonSchemaExporter, _ as LayerId, $ as Link, a0 as LinkSchema, a1 as LintIssueSchema, a2 as LintResult, L as LintRule, a3 as LookupKeyConfig, a4 as MarkdownExporter, a5 as MergedDesign, a6 as MermaidExporter, a7 as MetaModelConfig, a8 as Model, a9 as ModelDefinitionInput, aa as ModelRegistrySchema, ab as OpenAPIValidationMapping, ac as PhaseSchema, ad as Priority, ae as PrioritySchema, af as ProcessFlowId, ag as ReachedSpec, ah as ReferenceDefinition, ai as ReferenceDefinitionSchema, aj as ReferenceDirection, ak as ReferenceGraph, al as ReferenceGraphNode, am as RelationId, an as RenderContext, ao as Renderer, ap as RequirementId, aq as ResolvedSpeckeeperConfig, ar as ReviewAdapterName, as as ReviewCheck, at as ReviewConfigInput, au as ReviewFinding, av as ReviewGateConfig, aw as ReviewGateSeverity, ax as ReviewModelClass, ay as ReviewOutputDefinition, az as ReviewPrompt, aA as ReviewRegistry, aB as ReviewRule, aC as ReviewTarget, aD as RuleId, aE as ScanReporter, aF as ScreenId, aG as Severity, S as SourceMatch, a as SourceScanner, aH as SpecModule, aI as StateId, aJ as TableRefId, aK as TermId, aL as TransitionId, aM as UIComponentId, aN as UseCaseId, aO as ValidationError, aP as ValidationResult, aQ as buildRegistryFromConfig, aR as createAPIRefId, aS as createActorId, aT as createBatchRefId, aU as createBoundaryId, aV as createComponentId, aW as createDTORequirementId, aX as createEntityId, aY as createErrorCaseId, aZ as createEventRequirementId, a_ as createFormId, a$ as createIaCRefId, b0 as createLayerId, b1 as createLintRule, b2 as createMarkdownExporter, b3 as createMermaidExporter, b4 as createProcessFlowId, b5 as createRelationId, b6 as createRequirementId, b7 as createRuleId, b8 as createScreenId, b9 as createStateId, ba as createTableRefId, bb as createTermId, bc as createTransitionId, bd as createUIComponentId, be as createUseCaseId, bf as defineConfig, bg as defineModel, bh as defineReviewOutput, bi as defineSpecs, bj as findModelTypeFromConfig, bk as getPhaseIndex, bl as getSpecsFromConfig, bm as isSlotUnresolved, bn as loadYamlDir, bo as loadYamlSpecs, bp as mergeSpecs, bq as traverseReferenceGraph } from './config-api-
|
|
3
|
-
export { M as ModelLevel, a as RELATION_CONSTRAINTS, b as RELATION_TYPES, R as Relation, c as RelationSchema, d as RelationValidationError, e as RelationsFieldSchema, f as detectCycles, g as getLevelIndex, i as inferModelIdFromSpecId, v as validateRelationLevel } from './relation-
|
|
1
|
+
import { d as CheckContext, e as CheckResult, f as ExportContext, M as ModelDefinition, g as MetaModelRegistry, h as LintContext, i as LintRule, j as LintIssue, R as ReferenceGraphEdge, k as ContextProvider, c as SourceConfig, P as Phase, l as SpecEntry, m as SpeckeeperConfigInput } from './config-api-BVPg8Ewm.js';
|
|
2
|
+
export { n as APIRefId, o as ActorId, A as ArtifactConfig, B as BaseModelInstance, p as BatchRefId, q as BoundaryId, r as CheckError, s as CheckErrorSchema, b as CheckResult, t as CheckResultSchema, u as CheckWarning, v as CheckWarningSchema, w as ComponentId, x as ConcretizationSlot, y as ConcretizationSlotSchema, z as ConcretizationSlotsFieldSchema, F as ContextResult, C as CoverageChecker, G as CoverageResult, H as DDLValidationMapping, I as DTORequirementId, D as DeepValidationConfig, J as DeepValidationRule, K as EntityId, N as ErrorCaseId, O as EventRequirementId, E as Exporter, Q as ExternalChecker, T as ExternalConstraint, U as ExternalSsotPaths, V as FormId, W as ID_PATTERNS, X as IaCRefId, Y as InferModelType, Z as JsonSchemaExporter, _ as LayerId, $ as Link, a0 as LinkSchema, a1 as LintIssueSchema, a2 as LintResult, L as LintRule, a3 as LookupKeyConfig, a4 as MarkdownExporter, a5 as MergedDesign, a6 as MermaidExporter, a7 as MetaModelConfig, a8 as Model, a9 as ModelDefinitionInput, aa as ModelRegistrySchema, ab as OpenAPIValidationMapping, ac as PhaseSchema, ad as Priority, ae as PrioritySchema, af as ProcessFlowId, ag as ReachedSpec, ah as ReferenceDefinition, ai as ReferenceDefinitionSchema, aj as ReferenceDirection, ak as ReferenceGraph, al as ReferenceGraphNode, am as RelationId, an as RenderContext, ao as Renderer, ap as RequirementId, aq as ResolvedSpeckeeperConfig, ar as ReviewAdapterName, as as ReviewCheck, at as ReviewConfigInput, au as ReviewFinding, av as ReviewGateConfig, aw as ReviewGateSeverity, ax as ReviewModelClass, ay as ReviewOutputDefinition, az as ReviewPrompt, aA as ReviewRegistry, aB as ReviewRule, aC as ReviewTarget, aD as RuleId, aE as ScanReporter, aF as ScreenId, aG as Severity, S as SourceMatch, a as SourceScanner, aH as SpecModule, aI as StateId, aJ as TableRefId, aK as TermId, aL as TransitionId, aM as UIComponentId, aN as UseCaseId, aO as ValidationError, aP as ValidationResult, aQ as buildRegistryFromConfig, aR as createAPIRefId, aS as createActorId, aT as createBatchRefId, aU as createBoundaryId, aV as createComponentId, aW as createDTORequirementId, aX as createEntityId, aY as createErrorCaseId, aZ as createEventRequirementId, a_ as createFormId, a$ as createIaCRefId, b0 as createLayerId, b1 as createLintRule, b2 as createMarkdownExporter, b3 as createMermaidExporter, b4 as createProcessFlowId, b5 as createRelationId, b6 as createRequirementId, b7 as createRuleId, b8 as createScreenId, b9 as createStateId, ba as createTableRefId, bb as createTermId, bc as createTransitionId, bd as createUIComponentId, be as createUseCaseId, bf as defineConfig, bg as defineModel, bh as defineReviewOutput, bi as defineSpecs, bj as findModelTypeFromConfig, bk as getPhaseIndex, bl as getSpecsFromConfig, bm as isSlotUnresolved, bn as loadYamlDir, bo as loadYamlSpecs, bp as mergeSpecs, bq as traverseReferenceGraph } from './config-api-BVPg8Ewm.js';
|
|
3
|
+
export { M as ModelLevel, a as RELATION_CONSTRAINTS, b as RELATION_TYPES, R as Relation, c as RelationSchema, d as RelationValidationError, e as RelationsFieldSchema, f as detectCycles, g as getLevelIndex, i as inferModelIdFromSpecId, v as validateRelationLevel } from './relation-FGdEl6Yg.js';
|
|
4
4
|
import { z } from 'zod';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -187,7 +187,8 @@ declare function findConfigFile(startDir?: string): string | null;
|
|
|
187
187
|
*
|
|
188
188
|
* Returns the built-in defaults only when no config file exists. A config file
|
|
189
189
|
* that exists but cannot be loaded throws, so callers fail instead of reporting
|
|
190
|
-
* success against settings that were never applied.
|
|
190
|
+
* success against settings that were never applied. A relative `configPath` is
|
|
191
|
+
* relative to `cwd`.
|
|
191
192
|
*/
|
|
192
193
|
declare function loadConfig(configPath?: string, cwd?: string): Promise<SpeckeeperConfig>;
|
|
193
194
|
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,7 @@ import { z } from 'zod';
|
|
|
2
2
|
import { readFileSync, readdirSync, statSync, existsSync, mkdirSync, writeFileSync } from 'fs';
|
|
3
3
|
import { extname, join, dirname, resolve } from 'path';
|
|
4
4
|
import YAML, { parse } from 'yaml';
|
|
5
|
+
import { pathToFileURL } from 'url';
|
|
5
6
|
import { createHash } from 'crypto';
|
|
6
7
|
import { glob } from 'glob';
|
|
7
8
|
|
|
@@ -268,30 +269,22 @@ function detectCycles(relations) {
|
|
|
268
269
|
visited.add(node);
|
|
269
270
|
recursionStack.add(node);
|
|
270
271
|
cyclePath.push(node);
|
|
271
|
-
const
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
type: "cycle_detected",
|
|
284
|
-
message: `Circular reference detected: ${cycle.join(" \u2192 ")}`,
|
|
285
|
-
relation: relationMap.get(`${node}\u2192${neighbor}`),
|
|
286
|
-
sourceId: node
|
|
287
|
-
});
|
|
288
|
-
return true;
|
|
289
|
-
}
|
|
272
|
+
for (const neighbor of graph.get(node) ?? []) {
|
|
273
|
+
if (!visited.has(neighbor)) {
|
|
274
|
+
dfs(neighbor);
|
|
275
|
+
} else if (recursionStack.has(neighbor)) {
|
|
276
|
+
const cycle = cyclePath.slice(cyclePath.indexOf(neighbor));
|
|
277
|
+
cycle.push(neighbor);
|
|
278
|
+
errors.push({
|
|
279
|
+
type: "cycle_detected",
|
|
280
|
+
message: `Circular reference detected: ${cycle.join(" \u2192 ")}`,
|
|
281
|
+
relation: relationMap.get(`${node}\u2192${neighbor}`),
|
|
282
|
+
sourceId: node
|
|
283
|
+
});
|
|
290
284
|
}
|
|
291
285
|
}
|
|
292
286
|
cyclePath.pop();
|
|
293
287
|
recursionStack.delete(node);
|
|
294
|
-
return false;
|
|
295
288
|
}
|
|
296
289
|
for (const node of graph.keys()) {
|
|
297
290
|
if (!visited.has(node)) {
|
|
@@ -406,62 +399,6 @@ var Model = class {
|
|
|
406
399
|
lintAll(specs) {
|
|
407
400
|
return specs.flatMap((spec) => this.lint(spec));
|
|
408
401
|
}
|
|
409
|
-
/**
|
|
410
|
-
* Validate level constraints of relations
|
|
411
|
-
* @param spec - Spec instance (if it has relations property)
|
|
412
|
-
* @returns Array of validation errors
|
|
413
|
-
*/
|
|
414
|
-
validateRelations(spec) {
|
|
415
|
-
const errors = [];
|
|
416
|
-
const specWithRelations = spec;
|
|
417
|
-
if (!specWithRelations.relations || !specWithRelations.id) {
|
|
418
|
-
return errors;
|
|
419
|
-
}
|
|
420
|
-
const allModels = getAllModels();
|
|
421
|
-
const modelLevelMap = /* @__PURE__ */ new Map();
|
|
422
|
-
for (const model of allModels) {
|
|
423
|
-
modelLevelMap.set(model.id, model.level);
|
|
424
|
-
}
|
|
425
|
-
for (const relation of specWithRelations.relations) {
|
|
426
|
-
const targetModelId = inferModelIdFromSpecId(relation.target);
|
|
427
|
-
if (!targetModelId) {
|
|
428
|
-
continue;
|
|
429
|
-
}
|
|
430
|
-
const targetLevel = modelLevelMap.get(targetModelId);
|
|
431
|
-
const error = validateRelationLevel(
|
|
432
|
-
this.level,
|
|
433
|
-
specWithRelations.id,
|
|
434
|
-
relation,
|
|
435
|
-
targetLevel
|
|
436
|
-
);
|
|
437
|
-
if (error) {
|
|
438
|
-
errors.push(error);
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
return errors;
|
|
442
|
-
}
|
|
443
|
-
/**
|
|
444
|
-
* Validate relations of multiple specs (including circular reference check)
|
|
445
|
-
*/
|
|
446
|
-
validateAllRelations(specs) {
|
|
447
|
-
const errors = [];
|
|
448
|
-
const allRelations = [];
|
|
449
|
-
for (const spec of specs) {
|
|
450
|
-
errors.push(...this.validateRelations(spec));
|
|
451
|
-
const specWithRelations = spec;
|
|
452
|
-
if (specWithRelations.relations && specWithRelations.id) {
|
|
453
|
-
for (const rel of specWithRelations.relations) {
|
|
454
|
-
allRelations.push({
|
|
455
|
-
sourceId: specWithRelations.id,
|
|
456
|
-
targetId: rel.target,
|
|
457
|
-
type: rel.type
|
|
458
|
-
});
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
errors.push(...detectCycles(allRelations));
|
|
463
|
-
return errors;
|
|
464
|
-
}
|
|
465
402
|
/**
|
|
466
403
|
* Export in specified format (single spec)
|
|
467
404
|
*/
|
|
@@ -611,10 +548,6 @@ var Model = class {
|
|
|
611
548
|
}
|
|
612
549
|
};
|
|
613
550
|
var specStore = /* @__PURE__ */ new Map();
|
|
614
|
-
var modelRegistry = /* @__PURE__ */ new Map();
|
|
615
|
-
function getAllModels() {
|
|
616
|
-
return Array.from(modelRegistry.values());
|
|
617
|
-
}
|
|
618
551
|
function defineSpecs(...entries) {
|
|
619
552
|
return {
|
|
620
553
|
entries: entries.map(([model, data]) => ({ model, data }))
|
|
@@ -1192,7 +1125,7 @@ function mergeOverDefaults(parsed, resolvedPath) {
|
|
|
1192
1125
|
return { ...defaultConfig, ...parsed };
|
|
1193
1126
|
}
|
|
1194
1127
|
async function loadConfig(configPath, cwd = process.cwd()) {
|
|
1195
|
-
const resolvedPath = configPath
|
|
1128
|
+
const resolvedPath = configPath !== void 0 ? resolve(cwd, configPath) : findConfigFile(cwd);
|
|
1196
1129
|
if (!resolvedPath) {
|
|
1197
1130
|
return { ...defaultConfig };
|
|
1198
1131
|
}
|
|
@@ -1207,7 +1140,7 @@ async function loadConfig(configPath, cwd = process.cwd()) {
|
|
|
1207
1140
|
return mergeOverDefaults(JSON.parse(content), resolvedPath);
|
|
1208
1141
|
}
|
|
1209
1142
|
if (ext === "ts" || ext === "js") {
|
|
1210
|
-
const module = await import(resolvedPath);
|
|
1143
|
+
const module = await import(pathToFileURL(resolvedPath).href);
|
|
1211
1144
|
return mergeOverDefaults(module.default ?? module, resolvedPath);
|
|
1212
1145
|
}
|
|
1213
1146
|
} catch (error) {
|
|
@@ -104,7 +104,8 @@ interface RelationValidationError {
|
|
|
104
104
|
*/
|
|
105
105
|
declare function validateRelationLevel(sourceLevel: ModelLevel | undefined, sourceSpecId: string, relation: Relation, targetLevel: ModelLevel | undefined): RelationValidationError | null;
|
|
106
106
|
/**
|
|
107
|
-
* Detect circular references
|
|
107
|
+
* Detect circular references: one error for every relation that closes a
|
|
108
|
+
* cycle, naming the path of that cycle
|
|
108
109
|
*/
|
|
109
110
|
declare function detectCycles(relations: Array<{
|
|
110
111
|
sourceId: string;
|