speckeeper 0.7.1 → 0.8.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.
@@ -1,451 +0,0 @@
1
- import { z, ZodType } from 'zod';
2
-
3
- /**
4
- * Definition and validation of model relations
5
- */
6
-
7
- /**
8
- * Model abstraction level
9
- *
10
- * - L0: Business + Domain Analysis (Why / Problem space)
11
- * Desired outcomes/value, business flows, actors, terminology, business rules
12
- * - L1: Requirements (What)
13
- * Functional/non-functional requirements, constraints, acceptance criteria
14
- * - L2: Design (How / Direction)
15
- * Architecture, component breakdown, domain model, key sequences
16
- * - L3: Detailed Design/Implementation (How to build / Concrete artifacts)
17
- * Screen/API/DB definitions, external SSOT references
18
- */
19
- type ModelLevel = 'L0' | 'L1' | 'L2' | 'L3';
20
- /**
21
- * Get numeric index of level
22
- */
23
- declare function getLevelIndex(level: ModelLevel): number;
24
- /**
25
- * Relation types
26
- */
27
- declare const RELATION_TYPES: readonly ["dependsOn", "uses", "includes", "implements", "refines", "verifies", "verifiedBy", "satisfies", "traces", "relatedTo"];
28
- type RelationType = typeof RELATION_TYPES[number];
29
- /**
30
- * Relation schema
31
- */
32
- declare const RelationSchema: z.ZodObject<{
33
- /** Relation type */
34
- type: z.ZodEnum<["dependsOn", "uses", "includes", "implements", "refines", "verifies", "verifiedBy", "satisfies", "traces", "relatedTo"]>;
35
- /** Target ID */
36
- target: z.ZodString;
37
- /** Description (optional) */
38
- description: z.ZodOptional<z.ZodString>;
39
- }, "strip", z.ZodTypeAny, {
40
- type: "includes" | "dependsOn" | "uses" | "implements" | "refines" | "verifies" | "verifiedBy" | "satisfies" | "traces" | "relatedTo";
41
- target: string;
42
- description?: string | undefined;
43
- }, {
44
- type: "includes" | "dependsOn" | "uses" | "implements" | "refines" | "verifies" | "verifiedBy" | "satisfies" | "traces" | "relatedTo";
45
- target: string;
46
- description?: string | undefined;
47
- }>;
48
- /**
49
- * Relation field to add to model schemas
50
- * Usage: schema.extend({ relations: RelationsFieldSchema })
51
- */
52
- declare const RelationsFieldSchema: z.ZodOptional<z.ZodArray<z.ZodObject<{
53
- /** Relation type */
54
- type: z.ZodEnum<["dependsOn", "uses", "includes", "implements", "refines", "verifies", "verifiedBy", "satisfies", "traces", "relatedTo"]>;
55
- /** Target ID */
56
- target: z.ZodString;
57
- /** Description (optional) */
58
- description: z.ZodOptional<z.ZodString>;
59
- }, "strip", z.ZodTypeAny, {
60
- type: "includes" | "dependsOn" | "uses" | "implements" | "refines" | "verifies" | "verifiedBy" | "satisfies" | "traces" | "relatedTo";
61
- target: string;
62
- description?: string | undefined;
63
- }, {
64
- type: "includes" | "dependsOn" | "uses" | "implements" | "refines" | "verifies" | "verifiedBy" | "satisfies" | "traces" | "relatedTo";
65
- target: string;
66
- description?: string | undefined;
67
- }>, "many">>;
68
- type Relation = z.infer<typeof RelationSchema>;
69
- /**
70
- * Definition of relation constraints
71
- */
72
- interface RelationConstraint {
73
- /** Allowed target levels (all levels allowed if not specified) */
74
- allowedTargetLevels?: ModelLevel[];
75
- /** Level constraint rule */
76
- levelRule: 'source>target' | 'source>=target' | 'same' | 'any';
77
- /** Direction of impact propagation */
78
- propagation: 'forward' | 'backward' | 'both';
79
- }
80
- /**
81
- * Constraint definitions per relation type
82
- *
83
- * Level hierarchy:
84
- * L0 (Business) → L1 (Requirements) → L2 (Design) → L3 (Implementation)
85
- * Abstract ───────────────────────────→ Concrete
86
- */
87
- declare const RELATION_CONSTRAINTS: Record<RelationType, RelationConstraint>;
88
- /**
89
- * Relation validation error
90
- */
91
- interface RelationValidationError {
92
- type: 'level_violation' | 'target_level_violation' | 'self_reference' | 'cycle_detected';
93
- message: string;
94
- relation: Relation;
95
- sourceId: string;
96
- }
97
- /**
98
- * Validate level constraint for single relation
99
- *
100
- * @param sourceLevel - Source model level (set in _models/)
101
- * @param sourceSpecId - Source spec ID
102
- * @param relation - Relation
103
- * @param targetLevel - Target model level
104
- */
105
- declare function validateRelationLevel(sourceLevel: ModelLevel | undefined, sourceSpecId: string, relation: Relation, targetLevel: ModelLevel | undefined): RelationValidationError | null;
106
- /**
107
- * Detect circular references
108
- */
109
- declare function detectCycles(relations: Array<{
110
- sourceId: string;
111
- targetId: string;
112
- type: RelationType;
113
- }>): RelationValidationError[];
114
- /**
115
- * Infer model ID from spec ID (prefix-based)
116
- */
117
- declare function inferModelIdFromSpecId(specId: string): string | undefined;
118
-
119
- /**
120
- * Model base class
121
- *
122
- * All model definitions inherit from this class
123
- */
124
-
125
- /**
126
- * Lint rule definition
127
- */
128
- interface LintRule<T> {
129
- id: string;
130
- severity: 'error' | 'warning' | 'info';
131
- message: string;
132
- check: (spec: T) => boolean;
133
- }
134
- /**
135
- * Lint result
136
- */
137
- interface LintResult {
138
- ruleId: string;
139
- severity: 'error' | 'warning' | 'info';
140
- message: string;
141
- specId?: string;
142
- }
143
- /**
144
- * Exporter definition
145
- */
146
- interface Exporter<T> {
147
- format: 'markdown' | 'json' | 'mermaid';
148
- single?: (spec: T) => string;
149
- index?: (specs: T[]) => string;
150
- /** Subdirectory under docsDir (used with single + index/index.md) */
151
- outputDir?: string;
152
- /** Direct output file path relative to docsDir (used with index-only exporters) */
153
- outputFile?: string;
154
- filename?: (spec: T) => string;
155
- }
156
- /**
157
- * External checker definition
158
- */
159
- interface ExternalChecker<T> {
160
- targetType: string;
161
- sourcePath: (spec: T) => string;
162
- check: (spec: T, externalData: unknown) => CheckResult;
163
- }
164
- /**
165
- * Check result
166
- */
167
- interface CheckResult {
168
- success: boolean;
169
- errors: {
170
- message: string;
171
- field?: string;
172
- specId?: string;
173
- }[];
174
- warnings: {
175
- message: string;
176
- field?: string;
177
- specId?: string;
178
- }[];
179
- }
180
- /**
181
- * Coverage result
182
- */
183
- interface CoverageResult {
184
- /** Total target count */
185
- total: number;
186
- /** Covered count */
187
- covered: number;
188
- /** Uncovered count */
189
- uncovered: number;
190
- /** Coverage rate (%) */
191
- coveragePercent: number;
192
- /** Details of covered items */
193
- coveredItems: {
194
- id: string;
195
- description?: string;
196
- }[];
197
- /** Details of uncovered items */
198
- uncoveredItems: {
199
- id: string;
200
- description?: string;
201
- sourceId?: string;
202
- }[];
203
- }
204
- /**
205
- * Coverage checker definition
206
- *
207
- * Verify cross-model consistency (coverage).
208
- * Example: Whether TestRef covers acceptanceCriteria of Requirement
209
- */
210
- interface CoverageChecker<T> {
211
- /** Target model ID for coverage (e.g. 'requirement') */
212
- targetModel: string;
213
- /** Description of coverage check */
214
- description: string;
215
- /** Execute coverage check */
216
- check: (specs: T[], registry: Record<string, Map<string, unknown>>) => CoverageResult;
217
- }
218
- /**
219
- * Render context
220
- * Simplified version compatible with embedoc's EmbedContext
221
- */
222
- interface RenderContext {
223
- /** Parameters (filter conditions other than format, etc.) */
224
- params: Record<string, string | undefined>;
225
- /** Markdown helpers */
226
- markdown: {
227
- /** Generate table */
228
- table: (headers: string[], rows: (string | unknown)[][]) => string;
229
- };
230
- }
231
- /**
232
- * Renderer definition
233
- *
234
- * Model-specific rendering called from embeds
235
- */
236
- interface Renderer<T> {
237
- /** Format ID ('table', 'list', 'detail', 'spec-chapter', etc.) */
238
- format: string;
239
- /** Rendering process */
240
- render: (specs: T[], ctx: RenderContext) => string;
241
- }
242
- /**
243
- * Model base class
244
- *
245
- * @template TSchema - Zod schema type
246
- */
247
- declare abstract class Model<TSchema extends ZodType> {
248
- /** Singleton instance storage (per subclass) */
249
- private static _instances;
250
- /**
251
- * Get singleton instance of the model
252
- * Usage: RequirementModel.instance
253
- */
254
- static get instance(): Model<ZodType>;
255
- /** Model ID ('requirement', 'usecase', etc.) */
256
- abstract readonly id: string;
257
- /** Model name ('Requirement', 'UseCase', etc.) */
258
- abstract readonly name: string;
259
- /** ID prefix ('REQ', 'UC', etc.) */
260
- abstract readonly idPrefix: string;
261
- /** Zod schema */
262
- abstract readonly schema: TSchema;
263
- /** Model description (optional) */
264
- readonly description?: string;
265
- /** External SSOT type (optional, e.g. 'OpenAPI', 'DDL/Prisma') */
266
- readonly externalSsotType?: string;
267
- /** Spec instance type */
268
- protected get specType(): z.infer<TSchema>;
269
- /** Lint rules (override in subclass) */
270
- protected lintRules: LintRule<z.infer<TSchema>>[];
271
- /** Exporters (override in subclass) */
272
- protected exporters: Exporter<z.infer<TSchema>>[];
273
- /** External checker (optional) */
274
- protected externalChecker?: ExternalChecker<z.infer<TSchema>>;
275
- /** Coverage checker (optional) */
276
- protected coverageChecker?: CoverageChecker<z.infer<TSchema>>;
277
- /** Model level (set in _models/) */
278
- protected modelLevel?: ModelLevel;
279
- /** Renderers (for embeds, override in subclass) */
280
- protected renderers: Renderer<z.infer<TSchema>>[];
281
- /**
282
- * Get model level
283
- * Returns modelLevel set in _models/
284
- */
285
- get level(): ModelLevel | undefined;
286
- /**
287
- * Execute schema validation
288
- */
289
- validate(spec: unknown): z.infer<TSchema>;
290
- /**
291
- * Schema validation (safe version, returns error object on failure)
292
- */
293
- safeParse(spec: unknown): {
294
- success: true;
295
- data: z.infer<TSchema>;
296
- } | {
297
- success: false;
298
- error: z.ZodError;
299
- };
300
- /**
301
- * Execute lint
302
- */
303
- lint(spec: z.infer<TSchema>): LintResult[];
304
- /**
305
- * Execute lint for multiple specs
306
- */
307
- lintAll(specs: z.infer<TSchema>[]): LintResult[];
308
- /**
309
- * Validate level constraints of relations
310
- * @param spec - Spec instance (if it has relations property)
311
- * @returns Array of validation errors
312
- */
313
- validateRelations(spec: z.infer<TSchema>): RelationValidationError[];
314
- /**
315
- * Validate relations of multiple specs (including circular reference check)
316
- */
317
- validateAllRelations(specs: z.infer<TSchema>[]): RelationValidationError[];
318
- /**
319
- * Export in specified format (single spec)
320
- */
321
- exportSingle(spec: z.infer<TSchema>, format: string): string | null;
322
- /**
323
- * Export in specified format (index)
324
- */
325
- exportIndex(specs: z.infer<TSchema>[], format: string): string | null;
326
- /**
327
- * Get exporter output directory
328
- */
329
- getOutputDir(format: string): string | null;
330
- /**
331
- * Get filename
332
- */
333
- getFilename(spec: z.infer<TSchema>, format: string): string | null;
334
- /**
335
- * Check consistency with external SSOT
336
- */
337
- check(spec: z.infer<TSchema>, externalData: unknown): CheckResult;
338
- /**
339
- * Get external SSOT path
340
- */
341
- getExternalSourcePath(spec: z.infer<TSchema>): string | null;
342
- /**
343
- * Execute coverage check
344
- * @param specs - Array of spec instances for this model
345
- * @param registry - Registry of all models
346
- */
347
- checkCoverage(specs: z.infer<TSchema>[], registry: Record<string, Map<string, unknown>>): CoverageResult | null;
348
- /**
349
- * Get coverage checker
350
- */
351
- getCoverageChecker(): CoverageChecker<z.infer<TSchema>> | undefined;
352
- /**
353
- * Get lint rules
354
- */
355
- getLintRules(): LintRule<z.infer<TSchema>>[];
356
- /**
357
- * Get exporters
358
- */
359
- getExporters(): Exporter<z.infer<TSchema>>[];
360
- /**
361
- * Render in specified format
362
- * @param format - Format ID ('table', 'list', 'detail', etc.)
363
- * @param specs - Array of specs to render
364
- * @param ctx - Render context
365
- * @returns Rendered result (Markdown string), null if no matching renderer
366
- */
367
- render(format: string, specs: z.infer<TSchema>[], ctx: RenderContext): string | null;
368
- /**
369
- * Get list of available formats
370
- */
371
- getAvailableFormats(): string[];
372
- /**
373
- * Get renderers
374
- */
375
- getRenderers(): Renderer<z.infer<TSchema>>[];
376
- /**
377
- * Check if renderer exists for specific format
378
- */
379
- hasRenderer(format: string): boolean;
380
- /**
381
- * Register spec instances for this model.
382
- * Stores specs in the global specStore keyed by this model's id.
383
- */
384
- register(specs: z.infer<TSchema>[]): void;
385
- }
386
- /**
387
- * A single (Model, data[]) pair.
388
- * Uses structural typing (not nominal Model<any>) so that
389
- * compiled dist/ Model instances are compatible with src/ types.
390
- */
391
- interface SpecEntry {
392
- model: {
393
- id: string;
394
- register: (data: unknown[]) => void;
395
- };
396
- data: unknown[];
397
- }
398
- /**
399
- * Common export interface for spec data files.
400
- * Each spec file exports a SpecModule via defineSpecs().
401
- */
402
- interface SpecModule {
403
- entries: SpecEntry[];
404
- }
405
- /**
406
- * Aggregated result from mergeSpecs().
407
- */
408
- interface MergedDesign {
409
- models: SpecEntry['model'][];
410
- specs: SpecEntry[];
411
- }
412
- /**
413
- * Define spec data in a spec file. Returns a SpecModule.
414
- *
415
- * @example
416
- * ```typescript
417
- * export default defineSpecs(
418
- * [FunctionalRequirementModel.instance, functionalRequirements],
419
- * [NonFunctionalRequirementModel.instance, nonFunctionalRequirements],
420
- * );
421
- * ```
422
- */
423
- declare function defineSpecs(...entries: [SpecEntry['model'], unknown[]][]): SpecModule;
424
- /**
425
- * Merge multiple SpecModules into a single MergedDesign.
426
- * Models are deduplicated by model.id.
427
- *
428
- * @example
429
- * ```typescript
430
- * // design/index.ts
431
- * export default mergeSpecs(requirements, usecases, glossary);
432
- * ```
433
- */
434
- declare function mergeSpecs(...modules: SpecModule[]): MergedDesign;
435
- /**
436
- * Build a registry (modelId -> Map<specId, spec>) from config.specs.
437
- * Pure function — no global state.
438
- */
439
- declare function buildRegistryFromConfig(specs: SpecEntry[] | undefined): Record<string, Map<string, unknown>>;
440
- /**
441
- * Get specs for a model ID from config.specs.
442
- * Pure function — no global state.
443
- */
444
- declare function getSpecsFromConfig(specs: SpecEntry[] | undefined, modelId: string): unknown[];
445
- /**
446
- * Find which model type a spec ID belongs to, from config.specs.
447
- * Pure function — no global state.
448
- */
449
- declare function findModelTypeFromConfig(specs: SpecEntry[] | undefined, specId: string): string | null;
450
-
451
- export { type CheckResult as C, type Exporter as E, type LintResult as L, type MergedDesign as M, RELATION_CONSTRAINTS as R, type SpecEntry as S, type CoverageChecker as a, type CoverageResult as b, type ExternalChecker as c, type LintRule as d, Model as e, type ModelLevel as f, RELATION_TYPES as g, type Relation as h, RelationSchema as i, type RelationValidationError as j, RelationsFieldSchema as k, type RenderContext as l, type Renderer as m, type SpecModule as n, buildRegistryFromConfig as o, defineSpecs as p, detectCycles as q, findModelTypeFromConfig as r, getLevelIndex as s, getSpecsFromConfig as t, inferModelIdFromSpecId as u, mergeSpecs as v, validateRelationLevel as w };