speckeeper 0.2.0 → 0.2.1

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
@@ -879,6 +879,30 @@ declare function getAllModels(): Model<any>[];
879
879
  * Clear registry
880
880
  */
881
881
  declare function clearModelRegistry(): void;
882
+ /**
883
+ * Register model instances from config.models array.
884
+ * Filters out non-Model values. Call this once after config is loaded.
885
+ */
886
+ declare function registerModelsFromConfig(models: unknown[]): void;
887
+ /**
888
+ * Get specs for a given model ID from specStore
889
+ */
890
+ declare function getSpecs(modelId: string): unknown[];
891
+ /**
892
+ * Get all spec IDs across all models
893
+ */
894
+ declare function getAllSpecIds(): Set<string>;
895
+ /**
896
+ * Find which model type a spec ID belongs to
897
+ */
898
+ declare function findModelTypeBySpecId(specId: string): string | null;
899
+ /**
900
+ * Get a spec by ID (searches all models)
901
+ */
902
+ declare function getSpecById(specId: string): {
903
+ modelId: string;
904
+ spec: unknown;
905
+ } | null;
882
906
 
883
907
  /**
884
908
  * Register model definition
@@ -1318,65 +1342,4 @@ declare function findDefinitionFiles(srcDir: string, subDir: string): Promise<st
1318
1342
  declare function generateDocsPath(baseDir: string, category: string, filename: string): string;
1319
1343
  declare function generateSpecsPath(baseDir: string, category: string, filename: string): string;
1320
1344
 
1321
- /**
1322
- * Model Loader
1323
- *
1324
- * Load models and specs from design/ directory.
1325
- * Spec registration is done explicitly via Model.register() in each spec file.
1326
- */
1327
-
1328
- /**
1329
- * Model registry - stores all loaded spec data.
1330
- * Keys are model IDs (e.g. 'functional-requirement', 'usecase').
1331
- * Values are Maps of spec ID -> spec data.
1332
- */
1333
- type ModelRegistry = Record<string, Map<string, unknown>>;
1334
- /**
1335
- * Dynamically import TS files from specified directory.
1336
- * Model class instances found in exports are registered to core registry.
1337
- * Spec data is registered via Model.register() side effects during import.
1338
- */
1339
- declare function loadModelsFromDirectory(dirPath: string, options?: {
1340
- recursive?: boolean;
1341
- }): Promise<string[]>;
1342
- /**
1343
- * Load all models and specs based on configuration.
1344
- *
1345
- * 1. Reset spec store and model registry
1346
- * 2. Register Model class instances from config.models
1347
- * 3. Scan design/ files (triggers Model.register() calls as side effects)
1348
- * 4. Build registry from specStore
1349
- */
1350
- declare function loadAllModels(config: SpeckeeperConfig, cwd?: string): Promise<{
1351
- registry: ModelRegistry;
1352
- loadedFiles: string[];
1353
- errors: Array<{
1354
- file: string;
1355
- error: unknown;
1356
- }>;
1357
- }>;
1358
- /**
1359
- * Get specs from registry for a given model ID
1360
- */
1361
- declare function getSpecsFromRegistry(registry: ModelRegistry, modelId: string): unknown[];
1362
- /**
1363
- * Get registry statistics
1364
- */
1365
- declare function getRegistryStats(registry: ModelRegistry): Record<string, number>;
1366
- /**
1367
- * Get all IDs in registry
1368
- */
1369
- declare function getAllIds(registry: ModelRegistry): Set<string>;
1370
- /**
1371
- * Identify model type from ID
1372
- */
1373
- declare function findModelType(registry: ModelRegistry, id: string): string | null;
1374
- /**
1375
- * Get model by ID
1376
- */
1377
- declare function getModelById(registry: ModelRegistry, id: string): {
1378
- type: string;
1379
- model: unknown;
1380
- } | null;
1381
-
1382
- 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 ModelRegistry, 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, findModelType, findTypeScriptFiles, generateDocsPath, generateSpecsPath, getAllIds, getAllInstances, getAllModelDefinitions, getAllModelInstances, getAllModels, getExpectedOutputDirs, getGlobalModelRegistry, getLevelIndex, getModel, getModelById, getModelDefinition, getModelInstance, getModelRegistryStats, getOutputPaths, getRegistryStats, getSpecStore, getSpecsFromRegistry, inferModelIdFromSpecId, lintAllModels, lintModel, loadAllModels, loadConfig, loadModelsFromDirectory, loadSpeckeeperConfig, registerModel, registerModelDefinition, registerModelDefinitions, registerModelInstance, resetModelInstances, resetModelRegistry, resetSpecStore, resolveReference, validateConfig, validateOutputPaths, validateRelationLevel, writeFile, writeJsonFile };
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 };
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { z } from 'zod';
2
- import { existsSync, readFileSync, mkdirSync, writeFileSync, readdirSync, statSync } from 'fs';
3
- import { resolve, join, dirname, extname, basename } from 'path';
2
+ import { existsSync, readFileSync, mkdirSync, writeFileSync } from 'fs';
3
+ import { resolve, join, dirname } from 'path';
4
4
  import { parse } from 'yaml';
5
5
  import { createHash } from 'crypto';
6
6
  import { glob } from 'glob';
@@ -580,6 +580,38 @@ function getAllModels() {
580
580
  function clearModelRegistry() {
581
581
  modelRegistry.clear();
582
582
  }
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);
587
+ }
588
+ }
589
+ }
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);
600
+ }
601
+ }
602
+ return ids;
603
+ }
604
+ function findModelTypeBySpecId(specId) {
605
+ for (const [modelId, map] of specStore) {
606
+ if (map.has(specId)) return modelId;
607
+ }
608
+ return null;
609
+ }
610
+ function getSpecById(specId) {
611
+ const modelId = findModelTypeBySpecId(specId);
612
+ if (!modelId) return null;
613
+ return { modelId, spec: specStore.get(modelId).get(specId) };
614
+ }
583
615
 
584
616
  // src/core/model-registry.ts
585
617
  var globalRegistry = {
@@ -1114,133 +1146,7 @@ function generateDocsPath(baseDir, category, filename) {
1114
1146
  function generateSpecsPath(baseDir, category, filename) {
1115
1147
  return join(baseDir, category, filename);
1116
1148
  }
1117
- function isModelInstance(value) {
1118
- if (!value || typeof value !== "object") return false;
1119
- const obj = value;
1120
- return typeof obj.id === "string" && typeof obj.name === "string" && typeof obj.idPrefix === "string" && obj.schema !== void 0 && typeof obj.validate === "function" && typeof obj.lint === "function";
1121
- }
1122
- function registerExportedModelInstances(module) {
1123
- for (const [, exportValue] of Object.entries(module)) {
1124
- if (!exportValue || typeof exportValue !== "object") continue;
1125
- if (isModelInstance(exportValue)) {
1126
- registerModel(exportValue);
1127
- }
1128
- }
1129
- }
1130
- async function loadModelsFromDirectory(dirPath, options = {}) {
1131
- const loadedFiles = [];
1132
- if (!existsSync(dirPath)) {
1133
- return loadedFiles;
1134
- }
1135
- const entries = readdirSync(dirPath);
1136
- for (const entry of entries) {
1137
- const fullPath = join(dirPath, entry);
1138
- const stat = statSync(fullPath);
1139
- if (stat.isDirectory() && options.recursive) {
1140
- const subFiles = await loadModelsFromDirectory(fullPath, options);
1141
- loadedFiles.push(...subFiles);
1142
- } else if (stat.isFile()) {
1143
- const ext = extname(entry);
1144
- if ([".ts", ".js", ".mts", ".mjs"].includes(ext) && !entry.endsWith(".d.ts")) {
1145
- if (basename(entry, ext) === "index") {
1146
- continue;
1147
- }
1148
- try {
1149
- const module = await import(fullPath);
1150
- loadedFiles.push(fullPath);
1151
- registerExportedModelInstances(module);
1152
- } catch (error) {
1153
- console.error(`Failed to load from ${fullPath}:`, error);
1154
- }
1155
- }
1156
- }
1157
- }
1158
- return loadedFiles;
1159
- }
1160
- async function loadAllModels(config, cwd = process.cwd()) {
1161
- resetSpecStore();
1162
- clearModelRegistry();
1163
- const loadedFiles = [];
1164
- const errors = [];
1165
- if (config.models && Array.isArray(config.models)) {
1166
- for (const model of config.models) {
1167
- if (isModelInstance(model)) {
1168
- registerModel(model);
1169
- }
1170
- }
1171
- }
1172
- const designDir = resolve(cwd, config.designDir || "design");
1173
- const modelDirs = [
1174
- { path: join(designDir, "_models") },
1175
- { path: join(designDir, "requirements") },
1176
- { path: join(designDir, "usecases") },
1177
- { path: join(designDir, "architecture") },
1178
- { path: join(designDir, "data-model") },
1179
- { path: join(designDir, "screens") },
1180
- { path: join(designDir, "flows") },
1181
- { path: join(designDir, "glossary") },
1182
- { path: designDir }
1183
- ];
1184
- for (const { path: dirPath } of modelDirs) {
1185
- if (!existsSync(dirPath)) {
1186
- continue;
1187
- }
1188
- try {
1189
- const files = await loadModelsFromDirectory(dirPath, { recursive: true });
1190
- loadedFiles.push(...files);
1191
- } catch (error) {
1192
- errors.push({ file: dirPath, error });
1193
- }
1194
- }
1195
- const store = getSpecStore();
1196
- const registry = {};
1197
- for (const [modelId, specMap] of store) {
1198
- registry[modelId] = specMap;
1199
- }
1200
- return {
1201
- registry,
1202
- loadedFiles,
1203
- errors
1204
- };
1205
- }
1206
- function getSpecsFromRegistry(registry, modelId) {
1207
- const map = registry[modelId];
1208
- if (!map) return [];
1209
- return Array.from(map.values());
1210
- }
1211
- function getRegistryStats(registry) {
1212
- const stats = {};
1213
- for (const [key, map] of Object.entries(registry)) {
1214
- stats[key] = map.size;
1215
- }
1216
- return stats;
1217
- }
1218
- function getAllIds(registry) {
1219
- const allIds = /* @__PURE__ */ new Set();
1220
- for (const map of Object.values(registry)) {
1221
- for (const id of map.keys()) {
1222
- allIds.add(id);
1223
- }
1224
- }
1225
- return allIds;
1226
- }
1227
- function findModelType(registry, id) {
1228
- for (const [type, map] of Object.entries(registry)) {
1229
- if (map.has(id)) {
1230
- return type;
1231
- }
1232
- }
1233
- return null;
1234
- }
1235
- function getModelById(registry, id) {
1236
- const type = findModelType(registry, id);
1237
- if (!type) return null;
1238
- return {
1239
- type,
1240
- model: registry[type].get(id)
1241
- };
1242
- }
1243
1149
 
1244
- 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, findModelType, findTypeScriptFiles, generateDocsPath, generateSpecsPath, getAllIds, getAllInstances, getAllModelDefinitions, getAllModelInstances, getAllModels, getExpectedOutputDirs, getGlobalModelRegistry, getLevelIndex, getModel, getModelById, getModelDefinition, getModelInstance, getModelRegistryStats, getOutputPaths, getRegistryStats, getSpecStore, getSpecsFromRegistry, inferModelIdFromSpecId, lintAllModels, lintModel, loadAllModels, loadConfig, loadModelsFromDirectory, loadSpeckeeperConfig, registerModel, registerModelDefinition, registerModelDefinitions, registerModelInstance, resetModelInstances, resetModelRegistry, resetSpecStore, resolveReference, validateConfig, validateOutputPaths, validateRelationLevel, writeFile, writeJsonFile };
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 };
1245
1151
  //# sourceMappingURL=index.js.map
1246
1152
  //# sourceMappingURL=index.js.map