speckeeper 0.2.1 → 0.4.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/dist/index.d.ts CHANGED
@@ -856,53 +856,69 @@ declare abstract class Model<TSchema extends ZodType> {
856
856
  register(specs: z.infer<TSchema>[]): void;
857
857
  }
858
858
  /**
859
- * Get the global spec store (model ID → spec ID → spec data)
859
+ * A single (Model, data[]) pair.
860
+ * Uses structural typing (not nominal Model<any>) so that
861
+ * compiled dist/ Model instances are compatible with src/ types.
860
862
  */
861
- declare function getSpecStore(): Map<string, Map<string, unknown>>;
862
- /**
863
- * Reset the spec store (clears all registered specs)
864
- */
865
- declare function resetSpecStore(): void;
866
- /**
867
- * Register model
868
- */
869
- declare function registerModel(model: Model<any>): void;
870
- /**
871
- * Get model
872
- */
873
- declare function getModel(id: string): Model<any> | undefined;
863
+ interface SpecEntry {
864
+ model: {
865
+ id: string;
866
+ register: (data: unknown[]) => void;
867
+ };
868
+ data: unknown[];
869
+ }
874
870
  /**
875
- * Get all registered models
871
+ * Common export interface for spec data files.
872
+ * Each spec file exports a SpecModule via defineSpecs().
876
873
  */
877
- declare function getAllModels(): Model<any>[];
874
+ interface SpecModule {
875
+ entries: SpecEntry[];
876
+ }
878
877
  /**
879
- * Clear registry
878
+ * Aggregated result from mergeSpecs().
880
879
  */
881
- declare function clearModelRegistry(): void;
880
+ interface MergedDesign {
881
+ models: SpecEntry['model'][];
882
+ specs: SpecEntry[];
883
+ }
882
884
  /**
883
- * Register model instances from config.models array.
884
- * Filters out non-Model values. Call this once after config is loaded.
885
+ * Define spec data in a spec file. Returns a SpecModule.
886
+ *
887
+ * @example
888
+ * ```typescript
889
+ * export default defineSpecs(
890
+ * [FunctionalRequirementModel.instance, functionalRequirements],
891
+ * [NonFunctionalRequirementModel.instance, nonFunctionalRequirements],
892
+ * );
893
+ * ```
885
894
  */
886
- declare function registerModelsFromConfig(models: unknown[]): void;
895
+ declare function defineSpecs(...entries: [SpecEntry['model'], unknown[]][]): SpecModule;
887
896
  /**
888
- * Get specs for a given model ID from specStore
897
+ * Merge multiple SpecModules into a single MergedDesign.
898
+ * Models are deduplicated by model.id.
899
+ *
900
+ * @example
901
+ * ```typescript
902
+ * // design/index.ts
903
+ * export default mergeSpecs(requirements, usecases, glossary);
904
+ * ```
889
905
  */
890
- declare function getSpecs(modelId: string): unknown[];
906
+ declare function mergeSpecs(...modules: SpecModule[]): MergedDesign;
891
907
  /**
892
- * Get all spec IDs across all models
908
+ * Build a registry (modelId -> Map<specId, spec>) from config.specs.
909
+ * Pure function — no global state.
893
910
  */
894
- declare function getAllSpecIds(): Set<string>;
911
+ declare function buildRegistryFromConfig(specs: SpecEntry[] | undefined): Record<string, Map<string, unknown>>;
895
912
  /**
896
- * Find which model type a spec ID belongs to
913
+ * Get specs for a model ID from config.specs.
914
+ * Pure function — no global state.
897
915
  */
898
- declare function findModelTypeBySpecId(specId: string): string | null;
916
+ declare function getSpecsFromConfig(specs: SpecEntry[] | undefined, modelId: string): unknown[];
899
917
  /**
900
- * Get a spec by ID (searches all models)
918
+ * Find which model type a spec ID belongs to, from config.specs.
919
+ * Pure function — no global state.
901
920
  */
902
- declare function getSpecById(specId: string): {
903
- modelId: string;
904
- spec: unknown;
905
- } | null;
921
+ declare function findModelTypeFromConfig(specs: SpecEntry[] | undefined, specId: string): string | null;
906
922
 
907
923
  /**
908
924
  * Register model definition
@@ -1021,13 +1037,6 @@ declare function getModelRegistryStats(): {
1021
1037
  totalInstances: number;
1022
1038
  };
1023
1039
 
1024
- /**
1025
- * Configuration API for speckeeper
1026
- *
1027
- * Provides `defineConfig` and `defineModel` functions for users to
1028
- * create speckeeper.config.ts files with custom model definitions.
1029
- */
1030
-
1031
1040
  /**
1032
1041
  * speckeeper configuration type
1033
1042
  */
@@ -1044,6 +1053,8 @@ interface SpeckeeperConfigInput {
1044
1053
  specsDir?: string;
1045
1054
  /** Custom model definitions (Model instances or ModelDefinition objects) */
1046
1055
  models?: any[];
1056
+ /** Spec data entries from design/index.ts via mergeSpecs() */
1057
+ specs?: SpecEntry[];
1047
1058
  /** External SSOT configuration */
1048
1059
  externalSsot?: {
1049
1060
  openapi?: {
@@ -1282,6 +1293,7 @@ interface SpeckeeperConfig {
1282
1293
  mermaidCliPath?: string;
1283
1294
  };
1284
1295
  models?: unknown[];
1296
+ specs?: SpecEntry[];
1285
1297
  }
1286
1298
  /**
1287
1299
  * Get output paths compliant with specification
@@ -1342,4 +1354,4 @@ declare function findDefinitionFiles(srcDir: string, subDir: string): Promise<st
1342
1354
  declare function generateDocsPath(baseDir: string, category: string, filename: string): string;
1343
1355
  declare function generateSpecsPath(baseDir: string, category: string, filename: string): string;
1344
1356
 
1345
- export { type APIRefId, type ActorId, type BaseModelInstance, type BatchRefId, type BatchWriteResult, type BoundaryId, type CheckContext, type CheckError, CheckErrorSchema, type CheckResult, CheckResultSchema, type CheckWarning, CheckWarningSchema, type ComponentId, type ConcretizationSlot, ConcretizationSlotSchema, type CoverageChecker, type CoverageResult, type DTORequirementId, type DriftResult, type EntityId, type ErrorCaseId, type EventRequirementId, type ExportContext, type Exporter, type ExternalChecker, type FormId, ID_PATTERNS, type IaCRefId, type InferModelType, type JsonSchemaExporter, type LayerId, type Link, LinkSchema, type LintContext, type LintIssue, LintIssueSchema, type LintResult, type LintRule, type MarkdownExporter, type MermaidExporter, type MetaModelConfig, type MetaModelRegistry, Model, type ModelDefinition, type ModelDefinitionInput, type ModelLevel, type ModelRegistrySchema, type OutputPaths, type Phase, PhaseSchema, type Priority, PrioritySchema, type ProcessFlowId, RELATION_CONSTRAINTS, RELATION_TYPES, type ReferenceDefinition, ReferenceDefinitionSchema, type Relation, type RelationId, RelationSchema, type RelationValidationError, RelationsFieldSchema, type RenderContext, type Renderer, type RequirementId, type ResolvedSpeckeeperConfig, type RuleId, type ScreenId, type Severity, type SpeckeeperConfig, type SpeckeeperConfigInput, type StateId, type TableRefId, type TermId, type TransitionId, type UIComponentId, type UseCaseId, type ValidationError, type ValidationResult, type WriteResult, batchWriteFiles, checkBatchDrift, checkExternalSsot, checkFileDrift, checkReferenceIntegrity, clearModelRegistry, computeHash, createAPIRefId, createActorId, createBatchRefId, createBoundaryId, createComponentId, createDTORequirementId, createEntityId, createErrorCaseId, createEventRequirementId, createFormId, createIaCRefId, createLayerId, createLintRule, createMarkdownExporter, createMermaidExporter, createProcessFlowId, createRelationId, createRequirementId, createRuleId, createScreenId, createStateId, createTableRefId, createTermId, createTransitionId, createUIComponentId, createUseCaseId, defineConfig, defineModel, detectCycles, ensureDir, exportAllModels, exportMarkdown, exportMermaid, findConfigFile, findDefinitionFiles, findFiles, findModelTypeBySpecId, findTypeScriptFiles, generateDocsPath, generateSpecsPath, getAllInstances, getAllModelDefinitions, getAllModelInstances, getAllModels, getAllSpecIds, getExpectedOutputDirs, getGlobalModelRegistry, getLevelIndex, getModel, getModelDefinition, getModelInstance, getModelRegistryStats, getOutputPaths, getSpecById, getSpecStore, getSpecs, inferModelIdFromSpecId, lintAllModels, lintModel, loadConfig, loadSpeckeeperConfig, registerModel, registerModelDefinition, registerModelDefinitions, registerModelInstance, registerModelsFromConfig, resetModelInstances, resetModelRegistry, resetSpecStore, resolveReference, validateConfig, validateOutputPaths, validateRelationLevel, writeFile, writeJsonFile };
1357
+ export { type APIRefId, type ActorId, type BaseModelInstance, type BatchRefId, type BatchWriteResult, type BoundaryId, type CheckContext, type CheckError, CheckErrorSchema, type CheckResult, CheckResultSchema, type CheckWarning, CheckWarningSchema, type ComponentId, type ConcretizationSlot, ConcretizationSlotSchema, type CoverageChecker, type CoverageResult, type DTORequirementId, type DriftResult, type EntityId, type ErrorCaseId, type EventRequirementId, type ExportContext, type Exporter, type ExternalChecker, type FormId, ID_PATTERNS, type IaCRefId, type InferModelType, type JsonSchemaExporter, type LayerId, type Link, LinkSchema, type LintContext, type LintIssue, LintIssueSchema, type LintResult, type LintRule, type MarkdownExporter, type MergedDesign, type MermaidExporter, type MetaModelConfig, type MetaModelRegistry, Model, type ModelDefinition, type ModelDefinitionInput, type ModelLevel, type ModelRegistrySchema, type OutputPaths, type Phase, PhaseSchema, type Priority, PrioritySchema, type ProcessFlowId, RELATION_CONSTRAINTS, RELATION_TYPES, type ReferenceDefinition, ReferenceDefinitionSchema, type Relation, type RelationId, RelationSchema, type RelationValidationError, RelationsFieldSchema, type RenderContext, type Renderer, type RequirementId, type ResolvedSpeckeeperConfig, type RuleId, type ScreenId, type Severity, type SpecEntry, type SpecModule, type SpeckeeperConfig, type SpeckeeperConfigInput, type StateId, type TableRefId, type TermId, type TransitionId, type UIComponentId, type UseCaseId, type ValidationError, type ValidationResult, type WriteResult, batchWriteFiles, buildRegistryFromConfig, checkBatchDrift, checkExternalSsot, checkFileDrift, checkReferenceIntegrity, computeHash, createAPIRefId, createActorId, createBatchRefId, createBoundaryId, createComponentId, createDTORequirementId, createEntityId, createErrorCaseId, createEventRequirementId, createFormId, createIaCRefId, createLayerId, createLintRule, createMarkdownExporter, createMermaidExporter, createProcessFlowId, createRelationId, createRequirementId, createRuleId, createScreenId, createStateId, createTableRefId, createTermId, createTransitionId, createUIComponentId, createUseCaseId, defineConfig, defineModel, defineSpecs, detectCycles, ensureDir, exportAllModels, exportMarkdown, exportMermaid, findConfigFile, findDefinitionFiles, findFiles, findModelTypeFromConfig, findTypeScriptFiles, generateDocsPath, generateSpecsPath, getAllInstances, getAllModelDefinitions, getAllModelInstances, getExpectedOutputDirs, getGlobalModelRegistry, getLevelIndex, getModelDefinition, getModelInstance, getModelRegistryStats, getOutputPaths, getSpecsFromConfig, inferModelIdFromSpecId, lintAllModels, lintModel, loadConfig, loadSpeckeeperConfig, mergeSpecs, registerModelDefinition, registerModelDefinitions, registerModelInstance, resetModelInstances, resetModelRegistry, resolveReference, validateConfig, validateOutputPaths, validateRelationLevel, writeFile, writeJsonFile };
package/dist/index.js CHANGED
@@ -561,57 +561,58 @@ var Model = class {
561
561
  }
562
562
  };
563
563
  var specStore = /* @__PURE__ */ new Map();
564
- function getSpecStore() {
565
- return specStore;
566
- }
567
- function resetSpecStore() {
568
- specStore.clear();
569
- }
570
564
  var modelRegistry = /* @__PURE__ */ new Map();
571
- function registerModel(model) {
572
- modelRegistry.set(model.id, model);
573
- }
574
- function getModel(id) {
575
- return modelRegistry.get(id);
576
- }
577
565
  function getAllModels() {
578
566
  return Array.from(modelRegistry.values());
579
567
  }
580
- function clearModelRegistry() {
581
- modelRegistry.clear();
568
+ function defineSpecs(...entries) {
569
+ return {
570
+ entries: entries.map(([model, data]) => ({ model, data }))
571
+ };
582
572
  }
583
- function registerModelsFromConfig(models) {
584
- for (const model of models) {
585
- if (model && typeof model === "object" && "id" in model && "schema" in model) {
586
- registerModel(model);
573
+ function mergeSpecs(...modules) {
574
+ const modelMap = /* @__PURE__ */ new Map();
575
+ const allSpecs = [];
576
+ for (const mod of modules) {
577
+ for (const entry of mod.entries) {
578
+ modelMap.set(entry.model.id, entry.model);
579
+ allSpecs.push(entry);
587
580
  }
588
581
  }
582
+ return {
583
+ models: Array.from(modelMap.values()),
584
+ specs: allSpecs
585
+ };
589
586
  }
590
- function getSpecs(modelId) {
591
- const map = specStore.get(modelId);
592
- if (!map) return [];
593
- return Array.from(map.values());
594
- }
595
- function getAllSpecIds() {
596
- const ids = /* @__PURE__ */ new Set();
597
- for (const map of specStore.values()) {
598
- for (const id of map.keys()) {
599
- ids.add(id);
587
+ function buildRegistryFromConfig(specs) {
588
+ const registry = {};
589
+ if (!specs) return registry;
590
+ for (const entry of specs) {
591
+ if (!registry[entry.model.id]) {
592
+ registry[entry.model.id] = /* @__PURE__ */ new Map();
593
+ }
594
+ const map = registry[entry.model.id];
595
+ for (const spec of entry.data) {
596
+ map.set(spec.id, spec);
600
597
  }
601
598
  }
602
- return ids;
599
+ return registry;
600
+ }
601
+ function getSpecsFromConfig(specs, modelId) {
602
+ if (!specs) return [];
603
+ return specs.filter((e) => e.model.id === modelId).flatMap((e) => e.data);
603
604
  }
604
- function findModelTypeBySpecId(specId) {
605
- for (const [modelId, map] of specStore) {
606
- if (map.has(specId)) return modelId;
605
+ function findModelTypeFromConfig(specs, specId) {
606
+ if (!specs) return null;
607
+ for (const entry of specs) {
608
+ for (const spec of entry.data) {
609
+ if (spec.id === specId) {
610
+ return entry.model.id;
611
+ }
612
+ }
607
613
  }
608
614
  return null;
609
615
  }
610
- function getSpecById(specId) {
611
- const modelId = findModelTypeBySpecId(specId);
612
- if (!modelId) return null;
613
- return { modelId, spec: specStore.get(modelId).get(specId) };
614
- }
615
616
 
616
617
  // src/core/model-registry.ts
617
618
  var globalRegistry = {
@@ -1147,6 +1148,6 @@ function generateSpecsPath(baseDir, category, filename) {
1147
1148
  return join(baseDir, category, filename);
1148
1149
  }
1149
1150
 
1150
- export { CheckErrorSchema, CheckResultSchema, CheckWarningSchema, ConcretizationSlotSchema, ID_PATTERNS, LinkSchema, LintIssueSchema, Model, PhaseSchema, PrioritySchema, RELATION_CONSTRAINTS, RELATION_TYPES, ReferenceDefinitionSchema, RelationSchema, RelationsFieldSchema, batchWriteFiles, checkBatchDrift, checkExternalSsot, checkFileDrift, checkReferenceIntegrity, clearModelRegistry, computeHash, createAPIRefId, createActorId, createBatchRefId, createBoundaryId, createComponentId, createDTORequirementId, createEntityId, createErrorCaseId, createEventRequirementId, createFormId, createIaCRefId, createLayerId, createLintRule, createMarkdownExporter, createMermaidExporter, createProcessFlowId, createRelationId, createRequirementId, createRuleId, createScreenId, createStateId, createTableRefId, createTermId, createTransitionId, createUIComponentId, createUseCaseId, defineConfig, defineModel, detectCycles, ensureDir, exportAllModels, exportMarkdown, exportMermaid, findConfigFile, findDefinitionFiles, findFiles, findModelTypeBySpecId, findTypeScriptFiles, generateDocsPath, generateSpecsPath, getAllInstances, getAllModelDefinitions, getAllModelInstances, getAllModels, getAllSpecIds, getExpectedOutputDirs, getGlobalModelRegistry, getLevelIndex, getModel, getModelDefinition, getModelInstance, getModelRegistryStats, getOutputPaths, getSpecById, getSpecStore, getSpecs, inferModelIdFromSpecId, lintAllModels, lintModel, loadConfig, loadSpeckeeperConfig, registerModel, registerModelDefinition, registerModelDefinitions, registerModelInstance, registerModelsFromConfig, resetModelInstances, resetModelRegistry, resetSpecStore, resolveReference, validateConfig, validateOutputPaths, validateRelationLevel, writeFile, writeJsonFile };
1151
+ export { CheckErrorSchema, CheckResultSchema, CheckWarningSchema, ConcretizationSlotSchema, ID_PATTERNS, LinkSchema, LintIssueSchema, Model, PhaseSchema, PrioritySchema, RELATION_CONSTRAINTS, RELATION_TYPES, ReferenceDefinitionSchema, RelationSchema, RelationsFieldSchema, batchWriteFiles, buildRegistryFromConfig, checkBatchDrift, checkExternalSsot, checkFileDrift, checkReferenceIntegrity, computeHash, createAPIRefId, createActorId, createBatchRefId, createBoundaryId, createComponentId, createDTORequirementId, createEntityId, createErrorCaseId, createEventRequirementId, createFormId, createIaCRefId, createLayerId, createLintRule, createMarkdownExporter, createMermaidExporter, createProcessFlowId, createRelationId, createRequirementId, createRuleId, createScreenId, createStateId, createTableRefId, createTermId, createTransitionId, createUIComponentId, createUseCaseId, defineConfig, defineModel, defineSpecs, detectCycles, ensureDir, exportAllModels, exportMarkdown, exportMermaid, findConfigFile, findDefinitionFiles, findFiles, findModelTypeFromConfig, findTypeScriptFiles, generateDocsPath, generateSpecsPath, getAllInstances, getAllModelDefinitions, getAllModelInstances, getExpectedOutputDirs, getGlobalModelRegistry, getLevelIndex, getModelDefinition, getModelInstance, getModelRegistryStats, getOutputPaths, getSpecsFromConfig, inferModelIdFromSpecId, lintAllModels, lintModel, loadConfig, loadSpeckeeperConfig, mergeSpecs, registerModelDefinition, registerModelDefinitions, registerModelInstance, resetModelInstances, resetModelRegistry, resolveReference, validateConfig, validateOutputPaths, validateRelationLevel, writeFile, writeJsonFile };
1151
1152
  //# sourceMappingURL=index.js.map
1152
1153
  //# sourceMappingURL=index.js.map