driftdetect-core 0.4.6 → 0.5.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/call-graph/extractors/csharp-data-access-extractor.d.ts +8 -0
- package/dist/call-graph/extractors/csharp-data-access-extractor.d.ts.map +1 -1
- package/dist/call-graph/extractors/csharp-data-access-extractor.js +8 -0
- package/dist/call-graph/extractors/csharp-data-access-extractor.js.map +1 -1
- package/dist/call-graph/extractors/csharp-extractor.d.ts +35 -0
- package/dist/call-graph/extractors/csharp-extractor.d.ts.map +1 -1
- package/dist/call-graph/extractors/csharp-extractor.js +362 -4
- package/dist/call-graph/extractors/csharp-extractor.js.map +1 -1
- package/dist/call-graph/extractors/csharp-hybrid-extractor.d.ts +37 -0
- package/dist/call-graph/extractors/csharp-hybrid-extractor.d.ts.map +1 -0
- package/dist/call-graph/extractors/csharp-hybrid-extractor.js +408 -0
- package/dist/call-graph/extractors/csharp-hybrid-extractor.js.map +1 -0
- package/dist/call-graph/extractors/hybrid-extractor-base.d.ts +102 -0
- package/dist/call-graph/extractors/hybrid-extractor-base.d.ts.map +1 -0
- package/dist/call-graph/extractors/hybrid-extractor-base.js +289 -0
- package/dist/call-graph/extractors/hybrid-extractor-base.js.map +1 -0
- package/dist/call-graph/extractors/index.d.ts +17 -13
- package/dist/call-graph/extractors/index.d.ts.map +1 -1
- package/dist/call-graph/extractors/index.js +24 -23
- package/dist/call-graph/extractors/index.js.map +1 -1
- package/dist/call-graph/extractors/java-data-access-extractor.d.ts +8 -0
- package/dist/call-graph/extractors/java-data-access-extractor.d.ts.map +1 -1
- package/dist/call-graph/extractors/java-data-access-extractor.js +8 -0
- package/dist/call-graph/extractors/java-data-access-extractor.js.map +1 -1
- package/dist/call-graph/extractors/java-extractor.d.ts +15 -0
- package/dist/call-graph/extractors/java-extractor.d.ts.map +1 -1
- package/dist/call-graph/extractors/java-extractor.js +120 -4
- package/dist/call-graph/extractors/java-extractor.js.map +1 -1
- package/dist/call-graph/extractors/java-hybrid-extractor.d.ts +36 -0
- package/dist/call-graph/extractors/java-hybrid-extractor.d.ts.map +1 -0
- package/dist/call-graph/extractors/java-hybrid-extractor.js +426 -0
- package/dist/call-graph/extractors/java-hybrid-extractor.js.map +1 -0
- package/dist/call-graph/extractors/php-data-access-extractor.d.ts +8 -0
- package/dist/call-graph/extractors/php-data-access-extractor.d.ts.map +1 -1
- package/dist/call-graph/extractors/php-data-access-extractor.js +8 -0
- package/dist/call-graph/extractors/php-data-access-extractor.js.map +1 -1
- package/dist/call-graph/extractors/php-extractor.d.ts +48 -1
- package/dist/call-graph/extractors/php-extractor.d.ts.map +1 -1
- package/dist/call-graph/extractors/php-extractor.js +460 -6
- package/dist/call-graph/extractors/php-extractor.js.map +1 -1
- package/dist/call-graph/extractors/php-hybrid-extractor.d.ts +35 -0
- package/dist/call-graph/extractors/php-hybrid-extractor.d.ts.map +1 -0
- package/dist/call-graph/extractors/php-hybrid-extractor.js +393 -0
- package/dist/call-graph/extractors/php-hybrid-extractor.js.map +1 -0
- package/dist/call-graph/extractors/python-data-access-extractor.d.ts +8 -0
- package/dist/call-graph/extractors/python-data-access-extractor.d.ts.map +1 -1
- package/dist/call-graph/extractors/python-data-access-extractor.js +8 -0
- package/dist/call-graph/extractors/python-data-access-extractor.js.map +1 -1
- package/dist/call-graph/extractors/python-hybrid-extractor.d.ts +85 -0
- package/dist/call-graph/extractors/python-hybrid-extractor.d.ts.map +1 -0
- package/dist/call-graph/extractors/python-hybrid-extractor.js +462 -0
- package/dist/call-graph/extractors/python-hybrid-extractor.js.map +1 -0
- package/dist/call-graph/extractors/regex/base-regex-extractor.d.ts +154 -0
- package/dist/call-graph/extractors/regex/base-regex-extractor.d.ts.map +1 -0
- package/dist/call-graph/extractors/regex/base-regex-extractor.js +346 -0
- package/dist/call-graph/extractors/regex/base-regex-extractor.js.map +1 -0
- package/dist/call-graph/extractors/regex/csharp-regex.d.ts +34 -0
- package/dist/call-graph/extractors/regex/csharp-regex.d.ts.map +1 -0
- package/dist/call-graph/extractors/regex/csharp-regex.js +393 -0
- package/dist/call-graph/extractors/regex/csharp-regex.js.map +1 -0
- package/dist/call-graph/extractors/regex/index.d.ts +25 -0
- package/dist/call-graph/extractors/regex/index.d.ts.map +1 -0
- package/dist/call-graph/extractors/regex/index.js +66 -0
- package/dist/call-graph/extractors/regex/index.js.map +1 -0
- package/dist/call-graph/extractors/regex/java-regex.d.ts +34 -0
- package/dist/call-graph/extractors/regex/java-regex.d.ts.map +1 -0
- package/dist/call-graph/extractors/regex/java-regex.js +327 -0
- package/dist/call-graph/extractors/regex/java-regex.js.map +1 -0
- package/dist/call-graph/extractors/regex/php-regex.d.ts +30 -0
- package/dist/call-graph/extractors/regex/php-regex.d.ts.map +1 -0
- package/dist/call-graph/extractors/regex/php-regex.js +333 -0
- package/dist/call-graph/extractors/regex/php-regex.js.map +1 -0
- package/dist/call-graph/extractors/regex/python-regex.d.ts +46 -0
- package/dist/call-graph/extractors/regex/python-regex.d.ts.map +1 -0
- package/dist/call-graph/extractors/regex/python-regex.js +380 -0
- package/dist/call-graph/extractors/regex/python-regex.js.map +1 -0
- package/dist/call-graph/extractors/regex/typescript-regex.d.ts +27 -0
- package/dist/call-graph/extractors/regex/typescript-regex.d.ts.map +1 -0
- package/dist/call-graph/extractors/regex/typescript-regex.js +349 -0
- package/dist/call-graph/extractors/regex/typescript-regex.js.map +1 -0
- package/dist/call-graph/extractors/semantic-data-access-scanner.d.ts +7 -0
- package/dist/call-graph/extractors/semantic-data-access-scanner.d.ts.map +1 -1
- package/dist/call-graph/extractors/semantic-data-access-scanner.js +7 -0
- package/dist/call-graph/extractors/semantic-data-access-scanner.js.map +1 -1
- package/dist/call-graph/extractors/types.d.ts +111 -0
- package/dist/call-graph/extractors/types.d.ts.map +1 -0
- package/dist/call-graph/extractors/types.js +68 -0
- package/dist/call-graph/extractors/types.js.map +1 -0
- package/dist/call-graph/extractors/typescript-data-access-extractor.d.ts +8 -0
- package/dist/call-graph/extractors/typescript-data-access-extractor.d.ts.map +1 -1
- package/dist/call-graph/extractors/typescript-data-access-extractor.js +8 -0
- package/dist/call-graph/extractors/typescript-data-access-extractor.js.map +1 -1
- package/dist/call-graph/extractors/typescript-hybrid-extractor.d.ts +116 -0
- package/dist/call-graph/extractors/typescript-hybrid-extractor.d.ts.map +1 -0
- package/dist/call-graph/extractors/typescript-hybrid-extractor.js +635 -0
- package/dist/call-graph/extractors/typescript-hybrid-extractor.js.map +1 -0
- package/dist/error-handling/error-handling-analyzer.d.ts +73 -0
- package/dist/error-handling/error-handling-analyzer.d.ts.map +1 -0
- package/dist/error-handling/error-handling-analyzer.js +706 -0
- package/dist/error-handling/error-handling-analyzer.js.map +1 -0
- package/dist/error-handling/index.d.ts +8 -0
- package/dist/error-handling/index.d.ts.map +1 -0
- package/dist/error-handling/index.js +8 -0
- package/dist/error-handling/index.js.map +1 -0
- package/dist/error-handling/types.d.ts +307 -0
- package/dist/error-handling/types.d.ts.map +1 -0
- package/dist/error-handling/types.js +7 -0
- package/dist/error-handling/types.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +29 -0
- package/dist/index.js.map +1 -1
- package/dist/lake/pattern-shard-store.d.ts +6 -0
- package/dist/lake/pattern-shard-store.d.ts.map +1 -1
- package/dist/lake/pattern-shard-store.js +6 -0
- package/dist/lake/pattern-shard-store.js.map +1 -1
- package/dist/module-coupling/coupling-analyzer.d.ts +73 -0
- package/dist/module-coupling/coupling-analyzer.d.ts.map +1 -0
- package/dist/module-coupling/coupling-analyzer.js +668 -0
- package/dist/module-coupling/coupling-analyzer.js.map +1 -0
- package/dist/module-coupling/index.d.ts +9 -0
- package/dist/module-coupling/index.d.ts.map +1 -0
- package/dist/module-coupling/index.js +9 -0
- package/dist/module-coupling/index.js.map +1 -0
- package/dist/module-coupling/types.d.ts +273 -0
- package/dist/module-coupling/types.d.ts.map +1 -0
- package/dist/module-coupling/types.js +8 -0
- package/dist/module-coupling/types.js.map +1 -0
- package/dist/patterns/adapters/index.d.ts +11 -0
- package/dist/patterns/adapters/index.d.ts.map +1 -0
- package/dist/patterns/adapters/index.js +11 -0
- package/dist/patterns/adapters/index.js.map +1 -0
- package/dist/patterns/adapters/pattern-store-adapter.d.ts +59 -0
- package/dist/patterns/adapters/pattern-store-adapter.d.ts.map +1 -0
- package/dist/patterns/adapters/pattern-store-adapter.js +468 -0
- package/dist/patterns/adapters/pattern-store-adapter.js.map +1 -0
- package/dist/patterns/adapters/service-factory.d.ts +40 -0
- package/dist/patterns/adapters/service-factory.d.ts.map +1 -0
- package/dist/patterns/adapters/service-factory.js +144 -0
- package/dist/patterns/adapters/service-factory.js.map +1 -0
- package/dist/patterns/errors.d.ts +32 -0
- package/dist/patterns/errors.d.ts.map +1 -0
- package/dist/patterns/errors.js +45 -0
- package/dist/patterns/errors.js.map +1 -0
- package/dist/patterns/impl/cached-repository.d.ts +79 -0
- package/dist/patterns/impl/cached-repository.d.ts.map +1 -0
- package/dist/patterns/impl/cached-repository.js +296 -0
- package/dist/patterns/impl/cached-repository.js.map +1 -0
- package/dist/patterns/impl/file-repository.d.ts +75 -0
- package/dist/patterns/impl/file-repository.d.ts.map +1 -0
- package/dist/patterns/impl/file-repository.js +507 -0
- package/dist/patterns/impl/file-repository.js.map +1 -0
- package/dist/patterns/impl/index.d.ts +16 -0
- package/dist/patterns/impl/index.d.ts.map +1 -0
- package/dist/patterns/impl/index.js +21 -0
- package/dist/patterns/impl/index.js.map +1 -0
- package/dist/patterns/impl/memory-repository.d.ts +56 -0
- package/dist/patterns/impl/memory-repository.d.ts.map +1 -0
- package/dist/patterns/impl/memory-repository.js +323 -0
- package/dist/patterns/impl/memory-repository.js.map +1 -0
- package/dist/patterns/impl/pattern-service.d.ts +52 -0
- package/dist/patterns/impl/pattern-service.d.ts.map +1 -0
- package/dist/patterns/impl/pattern-service.js +382 -0
- package/dist/patterns/impl/pattern-service.js.map +1 -0
- package/dist/patterns/impl/repository-factory.d.ts +44 -0
- package/dist/patterns/impl/repository-factory.d.ts.map +1 -0
- package/dist/patterns/impl/repository-factory.js +140 -0
- package/dist/patterns/impl/repository-factory.js.map +1 -0
- package/dist/patterns/impl/unified-file-repository.d.ts +111 -0
- package/dist/patterns/impl/unified-file-repository.d.ts.map +1 -0
- package/dist/patterns/impl/unified-file-repository.js +677 -0
- package/dist/patterns/impl/unified-file-repository.js.map +1 -0
- package/dist/patterns/index.d.ts +23 -0
- package/dist/patterns/index.d.ts.map +1 -0
- package/dist/patterns/index.js +41 -0
- package/dist/patterns/index.js.map +1 -0
- package/dist/patterns/repository.d.ts +241 -0
- package/dist/patterns/repository.d.ts.map +1 -0
- package/dist/patterns/repository.js +23 -0
- package/dist/patterns/repository.js.map +1 -0
- package/dist/patterns/service.d.ts +245 -0
- package/dist/patterns/service.d.ts.map +1 -0
- package/dist/patterns/service.js +25 -0
- package/dist/patterns/service.js.map +1 -0
- package/dist/patterns/types.d.ts +227 -0
- package/dist/patterns/types.d.ts.map +1 -0
- package/dist/patterns/types.js +117 -0
- package/dist/patterns/types.js.map +1 -0
- package/dist/store/pattern-store.d.ts +6 -0
- package/dist/store/pattern-store.d.ts.map +1 -1
- package/dist/store/pattern-store.js +6 -0
- package/dist/store/pattern-store.js.map +1 -1
- package/dist/test-topology/extractors/base-test-extractor.d.ts +89 -0
- package/dist/test-topology/extractors/base-test-extractor.d.ts.map +1 -0
- package/dist/test-topology/extractors/base-test-extractor.js +187 -0
- package/dist/test-topology/extractors/base-test-extractor.js.map +1 -0
- package/dist/test-topology/extractors/csharp-test-extractor.d.ts +23 -0
- package/dist/test-topology/extractors/csharp-test-extractor.d.ts.map +1 -0
- package/dist/test-topology/extractors/csharp-test-extractor.js +367 -0
- package/dist/test-topology/extractors/csharp-test-extractor.js.map +1 -0
- package/dist/test-topology/extractors/index.d.ts +12 -0
- package/dist/test-topology/extractors/index.d.ts.map +1 -0
- package/dist/test-topology/extractors/index.js +12 -0
- package/dist/test-topology/extractors/index.js.map +1 -0
- package/dist/test-topology/extractors/java-test-extractor.d.ts +20 -0
- package/dist/test-topology/extractors/java-test-extractor.d.ts.map +1 -0
- package/dist/test-topology/extractors/java-test-extractor.js +275 -0
- package/dist/test-topology/extractors/java-test-extractor.js.map +1 -0
- package/dist/test-topology/extractors/php-test-extractor.d.ts +24 -0
- package/dist/test-topology/extractors/php-test-extractor.d.ts.map +1 -0
- package/dist/test-topology/extractors/php-test-extractor.js +409 -0
- package/dist/test-topology/extractors/php-test-extractor.js.map +1 -0
- package/dist/test-topology/extractors/python-test-extractor.d.ts +23 -0
- package/dist/test-topology/extractors/python-test-extractor.d.ts.map +1 -0
- package/dist/test-topology/extractors/python-test-extractor.js +342 -0
- package/dist/test-topology/extractors/python-test-extractor.js.map +1 -0
- package/dist/test-topology/extractors/regex/csharp-test-regex.d.ts +51 -0
- package/dist/test-topology/extractors/regex/csharp-test-regex.d.ts.map +1 -0
- package/dist/test-topology/extractors/regex/csharp-test-regex.js +383 -0
- package/dist/test-topology/extractors/regex/csharp-test-regex.js.map +1 -0
- package/dist/test-topology/extractors/regex/index.d.ts +18 -0
- package/dist/test-topology/extractors/regex/index.d.ts.map +1 -0
- package/dist/test-topology/extractors/regex/index.js +43 -0
- package/dist/test-topology/extractors/regex/index.js.map +1 -0
- package/dist/test-topology/extractors/regex/java-test-regex.d.ts +50 -0
- package/dist/test-topology/extractors/regex/java-test-regex.d.ts.map +1 -0
- package/dist/test-topology/extractors/regex/java-test-regex.js +370 -0
- package/dist/test-topology/extractors/regex/java-test-regex.js.map +1 -0
- package/dist/test-topology/extractors/regex/php-test-regex.d.ts +56 -0
- package/dist/test-topology/extractors/regex/php-test-regex.d.ts.map +1 -0
- package/dist/test-topology/extractors/regex/php-test-regex.js +503 -0
- package/dist/test-topology/extractors/regex/php-test-regex.js.map +1 -0
- package/dist/test-topology/extractors/regex/python-test-regex.d.ts +57 -0
- package/dist/test-topology/extractors/regex/python-test-regex.d.ts.map +1 -0
- package/dist/test-topology/extractors/regex/python-test-regex.js +381 -0
- package/dist/test-topology/extractors/regex/python-test-regex.js.map +1 -0
- package/dist/test-topology/extractors/regex/typescript-test-regex.d.ts +60 -0
- package/dist/test-topology/extractors/regex/typescript-test-regex.d.ts.map +1 -0
- package/dist/test-topology/extractors/regex/typescript-test-regex.js +368 -0
- package/dist/test-topology/extractors/regex/typescript-test-regex.js.map +1 -0
- package/dist/test-topology/extractors/typescript-test-extractor.d.ts +24 -0
- package/dist/test-topology/extractors/typescript-test-extractor.d.ts.map +1 -0
- package/dist/test-topology/extractors/typescript-test-extractor.js +266 -0
- package/dist/test-topology/extractors/typescript-test-extractor.js.map +1 -0
- package/dist/test-topology/hybrid-test-topology-analyzer.d.ts +98 -0
- package/dist/test-topology/hybrid-test-topology-analyzer.d.ts.map +1 -0
- package/dist/test-topology/hybrid-test-topology-analyzer.js +555 -0
- package/dist/test-topology/hybrid-test-topology-analyzer.js.map +1 -0
- package/dist/test-topology/index.d.ts +16 -0
- package/dist/test-topology/index.d.ts.map +1 -0
- package/dist/test-topology/index.js +19 -0
- package/dist/test-topology/index.js.map +1 -0
- package/dist/test-topology/test-topology-analyzer.d.ts +85 -0
- package/dist/test-topology/test-topology-analyzer.d.ts.map +1 -0
- package/dist/test-topology/test-topology-analyzer.js +538 -0
- package/dist/test-topology/test-topology-analyzer.js.map +1 -0
- package/dist/test-topology/types.d.ts +300 -0
- package/dist/test-topology/types.d.ts.map +1 -0
- package/dist/test-topology/types.js +7 -0
- package/dist/test-topology/types.js.map +1 -0
- package/dist/wrappers/clustering/clusterer.d.ts +43 -0
- package/dist/wrappers/clustering/clusterer.d.ts.map +1 -0
- package/dist/wrappers/clustering/clusterer.js +374 -0
- package/dist/wrappers/clustering/clusterer.js.map +1 -0
- package/dist/wrappers/clustering/exclusions.d.ts +47 -0
- package/dist/wrappers/clustering/exclusions.d.ts.map +1 -0
- package/dist/wrappers/clustering/exclusions.js +318 -0
- package/dist/wrappers/clustering/exclusions.js.map +1 -0
- package/dist/wrappers/clustering/index.d.ts +6 -0
- package/dist/wrappers/clustering/index.d.ts.map +1 -0
- package/dist/wrappers/clustering/index.js +6 -0
- package/dist/wrappers/clustering/index.js.map +1 -0
- package/dist/wrappers/detection/detector.d.ts +69 -0
- package/dist/wrappers/detection/detector.d.ts.map +1 -0
- package/dist/wrappers/detection/detector.js +279 -0
- package/dist/wrappers/detection/detector.js.map +1 -0
- package/dist/wrappers/detection/index.d.ts +5 -0
- package/dist/wrappers/detection/index.d.ts.map +1 -0
- package/dist/wrappers/detection/index.js +5 -0
- package/dist/wrappers/detection/index.js.map +1 -0
- package/dist/wrappers/export/index.d.ts +5 -0
- package/dist/wrappers/export/index.d.ts.map +1 -0
- package/dist/wrappers/export/index.js +5 -0
- package/dist/wrappers/export/index.js.map +1 -0
- package/dist/wrappers/export/json.d.ts +127 -0
- package/dist/wrappers/export/json.d.ts.map +1 -0
- package/dist/wrappers/export/json.js +160 -0
- package/dist/wrappers/export/json.js.map +1 -0
- package/dist/wrappers/index.d.ts +56 -0
- package/dist/wrappers/index.d.ts.map +1 -0
- package/dist/wrappers/index.js +159 -0
- package/dist/wrappers/index.js.map +1 -0
- package/dist/wrappers/integration/adapter.d.ts +52 -0
- package/dist/wrappers/integration/adapter.d.ts.map +1 -0
- package/dist/wrappers/integration/adapter.js +209 -0
- package/dist/wrappers/integration/adapter.js.map +1 -0
- package/dist/wrappers/integration/index.d.ts +9 -0
- package/dist/wrappers/integration/index.d.ts.map +1 -0
- package/dist/wrappers/integration/index.js +12 -0
- package/dist/wrappers/integration/index.js.map +1 -0
- package/dist/wrappers/integration/pattern-adapter.d.ts +52 -0
- package/dist/wrappers/integration/pattern-adapter.d.ts.map +1 -0
- package/dist/wrappers/integration/pattern-adapter.js +192 -0
- package/dist/wrappers/integration/pattern-adapter.js.map +1 -0
- package/dist/wrappers/integration/scanner.d.ts +85 -0
- package/dist/wrappers/integration/scanner.d.ts.map +1 -0
- package/dist/wrappers/integration/scanner.js +367 -0
- package/dist/wrappers/integration/scanner.js.map +1 -0
- package/dist/wrappers/primitives/discovery.d.ts +57 -0
- package/dist/wrappers/primitives/discovery.d.ts.map +1 -0
- package/dist/wrappers/primitives/discovery.js +389 -0
- package/dist/wrappers/primitives/discovery.js.map +1 -0
- package/dist/wrappers/primitives/index.d.ts +6 -0
- package/dist/wrappers/primitives/index.d.ts.map +1 -0
- package/dist/wrappers/primitives/index.js +6 -0
- package/dist/wrappers/primitives/index.js.map +1 -0
- package/dist/wrappers/primitives/registry.d.ts +63 -0
- package/dist/wrappers/primitives/registry.d.ts.map +1 -0
- package/dist/wrappers/primitives/registry.js +447 -0
- package/dist/wrappers/primitives/registry.js.map +1 -0
- package/dist/wrappers/types.d.ts +137 -0
- package/dist/wrappers/types.d.ts.map +1 -0
- package/dist/wrappers/types.js +7 -0
- package/dist/wrappers/types.js.map +1 -0
- package/package.json +5 -1
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pattern Service Implementation
|
|
3
|
+
*
|
|
4
|
+
* High-level service for pattern operations. This is the recommended
|
|
5
|
+
* interface for all consumers (MCP tools, CLI, Dashboard).
|
|
6
|
+
*
|
|
7
|
+
* @module patterns/impl/pattern-service
|
|
8
|
+
*/
|
|
9
|
+
import * as fs from 'node:fs/promises';
|
|
10
|
+
import * as path from 'node:path';
|
|
11
|
+
import { PATTERN_CATEGORIES, toPatternSummary } from '../types.js';
|
|
12
|
+
import { DEFAULT_SERVICE_CONFIG } from '../service.js';
|
|
13
|
+
// ============================================================================
|
|
14
|
+
// Language Detection
|
|
15
|
+
// ============================================================================
|
|
16
|
+
const LANGUAGE_EXTENSIONS = {
|
|
17
|
+
'.ts': 'typescript',
|
|
18
|
+
'.tsx': 'typescript',
|
|
19
|
+
'.js': 'javascript',
|
|
20
|
+
'.jsx': 'javascript',
|
|
21
|
+
'.py': 'python',
|
|
22
|
+
'.java': 'java',
|
|
23
|
+
'.cs': 'csharp',
|
|
24
|
+
'.php': 'php',
|
|
25
|
+
'.rb': 'ruby',
|
|
26
|
+
'.go': 'go',
|
|
27
|
+
'.rs': 'rust',
|
|
28
|
+
'.swift': 'swift',
|
|
29
|
+
'.kt': 'kotlin',
|
|
30
|
+
'.scala': 'scala',
|
|
31
|
+
'.css': 'css',
|
|
32
|
+
'.scss': 'scss',
|
|
33
|
+
'.less': 'less',
|
|
34
|
+
'.html': 'html',
|
|
35
|
+
'.vue': 'vue',
|
|
36
|
+
'.svelte': 'svelte',
|
|
37
|
+
'.json': 'json',
|
|
38
|
+
'.yaml': 'yaml',
|
|
39
|
+
'.yml': 'yaml',
|
|
40
|
+
'.md': 'markdown',
|
|
41
|
+
'.sql': 'sql',
|
|
42
|
+
};
|
|
43
|
+
function detectLanguage(filePath) {
|
|
44
|
+
const ext = path.extname(filePath).toLowerCase();
|
|
45
|
+
return LANGUAGE_EXTENSIONS[ext] ?? 'text';
|
|
46
|
+
}
|
|
47
|
+
// ============================================================================
|
|
48
|
+
// Pattern Service Implementation
|
|
49
|
+
// ============================================================================
|
|
50
|
+
/**
|
|
51
|
+
* Pattern Service implementation.
|
|
52
|
+
*
|
|
53
|
+
* Provides high-level operations on top of the pattern repository.
|
|
54
|
+
*/
|
|
55
|
+
export class PatternService {
|
|
56
|
+
repository;
|
|
57
|
+
config;
|
|
58
|
+
rootDir;
|
|
59
|
+
// Simple in-memory cache for status
|
|
60
|
+
statusCache = null;
|
|
61
|
+
constructor(repository, rootDir, config = {}) {
|
|
62
|
+
this.repository = repository;
|
|
63
|
+
this.rootDir = rootDir;
|
|
64
|
+
this.config = { ...DEFAULT_SERVICE_CONFIG, ...config };
|
|
65
|
+
}
|
|
66
|
+
// ==========================================================================
|
|
67
|
+
// Discovery (instant, lightweight)
|
|
68
|
+
// ==========================================================================
|
|
69
|
+
async getStatus() {
|
|
70
|
+
// Check cache
|
|
71
|
+
if (this.config.enableCache &&
|
|
72
|
+
this.statusCache &&
|
|
73
|
+
Date.now() < this.statusCache.expiresAt) {
|
|
74
|
+
return this.statusCache.value;
|
|
75
|
+
}
|
|
76
|
+
const patterns = await this.repository.getAll();
|
|
77
|
+
// Compute status
|
|
78
|
+
const byStatus = {
|
|
79
|
+
discovered: 0,
|
|
80
|
+
approved: 0,
|
|
81
|
+
ignored: 0,
|
|
82
|
+
};
|
|
83
|
+
const byCategory = {};
|
|
84
|
+
for (const cat of PATTERN_CATEGORIES) {
|
|
85
|
+
byCategory[cat] = 0;
|
|
86
|
+
}
|
|
87
|
+
const byConfidence = {
|
|
88
|
+
high: 0,
|
|
89
|
+
medium: 0,
|
|
90
|
+
low: 0,
|
|
91
|
+
uncertain: 0,
|
|
92
|
+
};
|
|
93
|
+
let lastScanAt = null;
|
|
94
|
+
for (const pattern of patterns) {
|
|
95
|
+
byStatus[pattern.status]++;
|
|
96
|
+
byCategory[pattern.category]++;
|
|
97
|
+
byConfidence[pattern.confidenceLevel]++;
|
|
98
|
+
const lastSeen = new Date(pattern.lastSeen);
|
|
99
|
+
if (!lastScanAt || lastSeen > lastScanAt) {
|
|
100
|
+
lastScanAt = lastSeen;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
// Compute health score (0-100)
|
|
104
|
+
const healthScore = this.computeHealthScore(patterns, byStatus, byConfidence);
|
|
105
|
+
const status = {
|
|
106
|
+
totalPatterns: patterns.length,
|
|
107
|
+
byStatus,
|
|
108
|
+
byCategory,
|
|
109
|
+
byConfidence,
|
|
110
|
+
lastScanAt,
|
|
111
|
+
healthScore,
|
|
112
|
+
};
|
|
113
|
+
// Cache the result
|
|
114
|
+
if (this.config.enableCache) {
|
|
115
|
+
this.statusCache = {
|
|
116
|
+
value: status,
|
|
117
|
+
expiresAt: Date.now() + this.config.cacheTtlMs,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
return status;
|
|
121
|
+
}
|
|
122
|
+
computeHealthScore(patterns, byStatus, byConfidence) {
|
|
123
|
+
if (patterns.length === 0)
|
|
124
|
+
return 100;
|
|
125
|
+
// Factors:
|
|
126
|
+
// 1. Approval rate (40% weight)
|
|
127
|
+
const approvalRate = byStatus.approved / patterns.length;
|
|
128
|
+
const approvalScore = approvalRate * 40;
|
|
129
|
+
// 2. High confidence rate (30% weight)
|
|
130
|
+
const highConfidenceRate = byConfidence.high / patterns.length;
|
|
131
|
+
const confidenceScore = highConfidenceRate * 30;
|
|
132
|
+
// 3. Low outlier rate (30% weight)
|
|
133
|
+
const totalOutliers = patterns.reduce((sum, p) => sum + p.outliers.length, 0);
|
|
134
|
+
const totalLocations = patterns.reduce((sum, p) => sum + p.locations.length, 0);
|
|
135
|
+
const outlierRate = totalLocations > 0 ? totalOutliers / totalLocations : 0;
|
|
136
|
+
const outlierScore = (1 - Math.min(outlierRate, 1)) * 30;
|
|
137
|
+
return Math.round(approvalScore + confidenceScore + outlierScore);
|
|
138
|
+
}
|
|
139
|
+
async getCategories() {
|
|
140
|
+
const patterns = await this.repository.getAll();
|
|
141
|
+
const summaries = new Map();
|
|
142
|
+
for (const cat of PATTERN_CATEGORIES) {
|
|
143
|
+
summaries.set(cat, {
|
|
144
|
+
category: cat,
|
|
145
|
+
count: 0,
|
|
146
|
+
approvedCount: 0,
|
|
147
|
+
discoveredCount: 0,
|
|
148
|
+
highConfidenceCount: 0,
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
for (const pattern of patterns) {
|
|
152
|
+
const summary = summaries.get(pattern.category);
|
|
153
|
+
summary.count++;
|
|
154
|
+
if (pattern.status === 'approved')
|
|
155
|
+
summary.approvedCount++;
|
|
156
|
+
if (pattern.status === 'discovered')
|
|
157
|
+
summary.discoveredCount++;
|
|
158
|
+
if (pattern.confidenceLevel === 'high')
|
|
159
|
+
summary.highConfidenceCount++;
|
|
160
|
+
}
|
|
161
|
+
// Return only categories with patterns
|
|
162
|
+
return Array.from(summaries.values()).filter((s) => s.count > 0);
|
|
163
|
+
}
|
|
164
|
+
// ==========================================================================
|
|
165
|
+
// Exploration (paginated)
|
|
166
|
+
// ==========================================================================
|
|
167
|
+
async listPatterns(options) {
|
|
168
|
+
const queryOptions = this.listOptionsToQueryOptions(options);
|
|
169
|
+
const result = await this.repository.query(queryOptions);
|
|
170
|
+
return {
|
|
171
|
+
items: result.patterns.map(toPatternSummary),
|
|
172
|
+
total: result.total,
|
|
173
|
+
hasMore: result.hasMore,
|
|
174
|
+
offset: options?.offset ?? 0,
|
|
175
|
+
limit: options?.limit ?? 20,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
async listByCategory(category, options) {
|
|
179
|
+
const queryOptions = this.listOptionsToQueryOptions(options);
|
|
180
|
+
queryOptions.filter = {
|
|
181
|
+
...queryOptions.filter,
|
|
182
|
+
categories: [category],
|
|
183
|
+
};
|
|
184
|
+
const result = await this.repository.query(queryOptions);
|
|
185
|
+
return {
|
|
186
|
+
items: result.patterns.map(toPatternSummary),
|
|
187
|
+
total: result.total,
|
|
188
|
+
hasMore: result.hasMore,
|
|
189
|
+
offset: options?.offset ?? 0,
|
|
190
|
+
limit: options?.limit ?? 20,
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
async listByStatus(status, options) {
|
|
194
|
+
const queryOptions = this.listOptionsToQueryOptions(options);
|
|
195
|
+
queryOptions.filter = {
|
|
196
|
+
...queryOptions.filter,
|
|
197
|
+
statuses: [status],
|
|
198
|
+
};
|
|
199
|
+
const result = await this.repository.query(queryOptions);
|
|
200
|
+
return {
|
|
201
|
+
items: result.patterns.map(toPatternSummary),
|
|
202
|
+
total: result.total,
|
|
203
|
+
hasMore: result.hasMore,
|
|
204
|
+
offset: options?.offset ?? 0,
|
|
205
|
+
limit: options?.limit ?? 20,
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
listOptionsToQueryOptions(options) {
|
|
209
|
+
const queryOptions = {
|
|
210
|
+
filter: {},
|
|
211
|
+
pagination: {
|
|
212
|
+
offset: options?.offset ?? 0,
|
|
213
|
+
limit: options?.limit ?? 20,
|
|
214
|
+
},
|
|
215
|
+
};
|
|
216
|
+
if (options?.sortBy) {
|
|
217
|
+
queryOptions.sort = {
|
|
218
|
+
field: options.sortBy,
|
|
219
|
+
direction: options.sortDirection ?? 'desc',
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
return queryOptions;
|
|
223
|
+
}
|
|
224
|
+
// ==========================================================================
|
|
225
|
+
// Detail (focused)
|
|
226
|
+
// ==========================================================================
|
|
227
|
+
async getPattern(id) {
|
|
228
|
+
return this.repository.get(id);
|
|
229
|
+
}
|
|
230
|
+
async getPatternWithExamples(id, maxExamples = 3) {
|
|
231
|
+
const pattern = await this.repository.get(id);
|
|
232
|
+
if (!pattern)
|
|
233
|
+
return null;
|
|
234
|
+
// Extract code examples from locations
|
|
235
|
+
const codeExamples = await this.extractCodeExamples(pattern.locations, maxExamples);
|
|
236
|
+
// Find related patterns (same category and subcategory)
|
|
237
|
+
const relatedResult = await this.repository.query({
|
|
238
|
+
filter: {
|
|
239
|
+
categories: [pattern.category],
|
|
240
|
+
},
|
|
241
|
+
pagination: { offset: 0, limit: 5 },
|
|
242
|
+
});
|
|
243
|
+
const relatedPatterns = relatedResult.patterns
|
|
244
|
+
.filter((p) => p.id !== pattern.id)
|
|
245
|
+
.slice(0, 4)
|
|
246
|
+
.map(toPatternSummary);
|
|
247
|
+
return {
|
|
248
|
+
...pattern,
|
|
249
|
+
codeExamples,
|
|
250
|
+
relatedPatterns,
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
async extractCodeExamples(locations, maxExamples) {
|
|
254
|
+
const examples = [];
|
|
255
|
+
const contextLines = this.config.codeExampleContextLines;
|
|
256
|
+
// Take up to maxExamples locations
|
|
257
|
+
const selectedLocations = locations.slice(0, maxExamples);
|
|
258
|
+
for (const location of selectedLocations) {
|
|
259
|
+
try {
|
|
260
|
+
const filePath = path.join(this.rootDir, location.file);
|
|
261
|
+
const content = await fs.readFile(filePath, 'utf-8');
|
|
262
|
+
const lines = content.split('\n');
|
|
263
|
+
const startLine = Math.max(1, location.line - contextLines);
|
|
264
|
+
const endLine = Math.min(lines.length, (location.endLine ?? location.line) + contextLines);
|
|
265
|
+
const code = lines.slice(startLine - 1, endLine).join('\n');
|
|
266
|
+
examples.push({
|
|
267
|
+
file: location.file,
|
|
268
|
+
startLine,
|
|
269
|
+
endLine,
|
|
270
|
+
code,
|
|
271
|
+
language: detectLanguage(location.file),
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
catch {
|
|
275
|
+
// File not found or unreadable, skip
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
return examples;
|
|
279
|
+
}
|
|
280
|
+
async getPatternsByFile(file) {
|
|
281
|
+
return this.repository.getByFile(file);
|
|
282
|
+
}
|
|
283
|
+
// ==========================================================================
|
|
284
|
+
// Actions
|
|
285
|
+
// ==========================================================================
|
|
286
|
+
async approvePattern(id, approvedBy) {
|
|
287
|
+
this.invalidateStatusCache();
|
|
288
|
+
return this.repository.approve(id, approvedBy);
|
|
289
|
+
}
|
|
290
|
+
async ignorePattern(id) {
|
|
291
|
+
this.invalidateStatusCache();
|
|
292
|
+
return this.repository.ignore(id);
|
|
293
|
+
}
|
|
294
|
+
async approveMany(ids, approvedBy) {
|
|
295
|
+
this.invalidateStatusCache();
|
|
296
|
+
const results = [];
|
|
297
|
+
for (const id of ids) {
|
|
298
|
+
const pattern = await this.repository.approve(id, approvedBy);
|
|
299
|
+
results.push(pattern);
|
|
300
|
+
}
|
|
301
|
+
return results;
|
|
302
|
+
}
|
|
303
|
+
async ignoreMany(ids) {
|
|
304
|
+
this.invalidateStatusCache();
|
|
305
|
+
const results = [];
|
|
306
|
+
for (const id of ids) {
|
|
307
|
+
const pattern = await this.repository.ignore(id);
|
|
308
|
+
results.push(pattern);
|
|
309
|
+
}
|
|
310
|
+
return results;
|
|
311
|
+
}
|
|
312
|
+
invalidateStatusCache() {
|
|
313
|
+
this.statusCache = null;
|
|
314
|
+
}
|
|
315
|
+
// ==========================================================================
|
|
316
|
+
// Search
|
|
317
|
+
// ==========================================================================
|
|
318
|
+
async search(query, options) {
|
|
319
|
+
const filter = {
|
|
320
|
+
search: query,
|
|
321
|
+
};
|
|
322
|
+
if (options?.categories) {
|
|
323
|
+
filter.categories = options.categories;
|
|
324
|
+
}
|
|
325
|
+
if (options?.statuses) {
|
|
326
|
+
filter.statuses = options.statuses;
|
|
327
|
+
}
|
|
328
|
+
if (options?.minConfidence !== undefined) {
|
|
329
|
+
filter.minConfidence = options.minConfidence;
|
|
330
|
+
}
|
|
331
|
+
const result = await this.repository.query({
|
|
332
|
+
filter,
|
|
333
|
+
pagination: {
|
|
334
|
+
offset: 0,
|
|
335
|
+
limit: options?.limit ?? 20,
|
|
336
|
+
},
|
|
337
|
+
});
|
|
338
|
+
return result.patterns.map(toPatternSummary);
|
|
339
|
+
}
|
|
340
|
+
// ==========================================================================
|
|
341
|
+
// Advanced Queries
|
|
342
|
+
// ==========================================================================
|
|
343
|
+
async query(options) {
|
|
344
|
+
return this.repository.query(options);
|
|
345
|
+
}
|
|
346
|
+
// ==========================================================================
|
|
347
|
+
// Write Operations (for producers like scan)
|
|
348
|
+
// ==========================================================================
|
|
349
|
+
async addPattern(pattern) {
|
|
350
|
+
this.invalidateStatusCache();
|
|
351
|
+
await this.repository.add(pattern);
|
|
352
|
+
}
|
|
353
|
+
async addPatterns(patterns) {
|
|
354
|
+
this.invalidateStatusCache();
|
|
355
|
+
await this.repository.addMany(patterns);
|
|
356
|
+
}
|
|
357
|
+
async updatePattern(id, updates) {
|
|
358
|
+
this.invalidateStatusCache();
|
|
359
|
+
return this.repository.update(id, updates);
|
|
360
|
+
}
|
|
361
|
+
async deletePattern(id) {
|
|
362
|
+
this.invalidateStatusCache();
|
|
363
|
+
return this.repository.delete(id);
|
|
364
|
+
}
|
|
365
|
+
async save() {
|
|
366
|
+
await this.repository.saveAll();
|
|
367
|
+
}
|
|
368
|
+
async clear() {
|
|
369
|
+
this.invalidateStatusCache();
|
|
370
|
+
await this.repository.clear();
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
// ============================================================================
|
|
374
|
+
// Factory Function
|
|
375
|
+
// ============================================================================
|
|
376
|
+
/**
|
|
377
|
+
* Create a new PatternService instance.
|
|
378
|
+
*/
|
|
379
|
+
export function createPatternService(repository, rootDir, config) {
|
|
380
|
+
return new PatternService(repository, rootDir, config);
|
|
381
|
+
}
|
|
382
|
+
//# sourceMappingURL=pattern-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pattern-service.js","sourceRoot":"","sources":["../../../src/patterns/impl/pattern-service.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AASlC,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAYnE,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAGvD,+EAA+E;AAC/E,qBAAqB;AACrB,+EAA+E;AAE/E,MAAM,mBAAmB,GAA2B;IAClD,KAAK,EAAE,YAAY;IACnB,MAAM,EAAE,YAAY;IACpB,KAAK,EAAE,YAAY;IACnB,MAAM,EAAE,YAAY;IACpB,KAAK,EAAE,QAAQ;IACf,OAAO,EAAE,MAAM;IACf,KAAK,EAAE,QAAQ;IACf,MAAM,EAAE,KAAK;IACb,KAAK,EAAE,MAAM;IACb,KAAK,EAAE,IAAI;IACX,KAAK,EAAE,MAAM;IACb,QAAQ,EAAE,OAAO;IACjB,KAAK,EAAE,QAAQ;IACf,QAAQ,EAAE,OAAO;IACjB,MAAM,EAAE,KAAK;IACb,OAAO,EAAE,MAAM;IACf,OAAO,EAAE,MAAM;IACf,OAAO,EAAE,MAAM;IACf,MAAM,EAAE,KAAK;IACb,SAAS,EAAE,QAAQ;IACnB,OAAO,EAAE,MAAM;IACf,OAAO,EAAE,MAAM;IACf,MAAM,EAAE,MAAM;IACd,KAAK,EAAE,UAAU;IACjB,MAAM,EAA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E,CAAC;QAC7B,MAAM,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACrC,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,QAAmB;QACnC,IAAI,CAAC,qBAAqB,EAAE,CAAC;QAC7B,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC1C,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,EAAU,EAAE,OAAyB;QACvD,IAAI,CAAC,qBAAqB,EAAE,CAAC;QAC7B,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;IAC7C,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,EAAU;QAC5B,IAAI,CAAC,qBAAqB,EAAE,CAAC;QAC7B,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IACpC,CAAC;IAED,KAAK,CAAC,IAAI;QACR,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;IAClC,CAAC;IAED,KAAK,CAAC,KAAK;QACT,IAAI,CAAC,qBAAqB,EAAE,CAAC;QAC7B,MAAM,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;IAChC,CAAC;CACF;AAED,+EAA+E;AAC/E,mBAAmB;AACnB,+EAA+E;AAE/E;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAClC,UAA8B,EAC9B,OAAe,EACf,MAAsC;IAEtC,OAAO,IAAI,cAAc,CAAC,UAAU,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;AACzD,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pattern Repository Factory
|
|
3
|
+
*
|
|
4
|
+
* Creates the appropriate pattern repository based on the storage format
|
|
5
|
+
* detected in the project. Handles automatic migration and format detection.
|
|
6
|
+
*
|
|
7
|
+
* @module patterns/impl/repository-factory
|
|
8
|
+
*/
|
|
9
|
+
import type { IPatternRepository, PatternRepositoryConfig } from '../repository.js';
|
|
10
|
+
import { type UnifiedRepositoryConfig } from './unified-file-repository.js';
|
|
11
|
+
export type StorageFormat = 'unified' | 'legacy' | 'none';
|
|
12
|
+
export interface RepositoryFactoryConfig extends Partial<UnifiedRepositoryConfig> {
|
|
13
|
+
/** Prefer unified format even if legacy exists */
|
|
14
|
+
preferUnified?: boolean;
|
|
15
|
+
/** Auto-migrate legacy to unified on create */
|
|
16
|
+
autoMigrate?: boolean;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Detect the storage format used in a project
|
|
20
|
+
*/
|
|
21
|
+
export declare function detectStorageFormat(rootDir: string): Promise<StorageFormat>;
|
|
22
|
+
/**
|
|
23
|
+
* Create a pattern repository with automatic format detection.
|
|
24
|
+
*
|
|
25
|
+
* - If unified format exists, uses UnifiedFilePatternRepository
|
|
26
|
+
* - If legacy format exists and autoMigrate is true, migrates to unified
|
|
27
|
+
* - If legacy format exists and autoMigrate is false, uses FilePatternRepository
|
|
28
|
+
* - If no format exists, creates new UnifiedFilePatternRepository
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* const repository = await createPatternRepository({ rootDir: '/path/to/project' });
|
|
33
|
+
* await repository.initialize();
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare function createPatternRepository(config?: Partial<RepositoryFactoryConfig>): Promise<IPatternRepository>;
|
|
37
|
+
/**
|
|
38
|
+
* Create a pattern repository synchronously (uses unified format by default).
|
|
39
|
+
*
|
|
40
|
+
* This is useful when you can't use async/await but need a repository.
|
|
41
|
+
* Note: This always creates UnifiedFilePatternRepository with autoMigrate enabled.
|
|
42
|
+
*/
|
|
43
|
+
export declare function createPatternRepositorySync(config?: Partial<PatternRepositoryConfig>): IPatternRepository;
|
|
44
|
+
//# sourceMappingURL=repository-factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repository-factory.d.ts","sourceRoot":"","sources":["../../../src/patterns/impl/repository-factory.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH,OAAO,KAAK,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAEpF,OAAO,EAAgC,KAAK,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAM1G,MAAM,MAAM,aAAa,GAAG,SAAS,GAAG,QAAQ,GAAG,MAAM,CAAC;AAE1D,MAAM,WAAW,uBAAwB,SAAQ,OAAO,CAAC,uBAAuB,CAAC;IAC/E,kDAAkD;IAClD,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,+CAA+C;IAC/C,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAyBD;;GAEG;AACH,wBAAsB,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CA8BjF;AAMD;;;;;;;;;;;;;GAaG;AACH,wBAAsB,uBAAuB,CAC3C,MAAM,GAAE,OAAO,CAAC,uBAAuB,CAAM,GAC5C,OAAO,CAAC,kBAAkB,CAAC,CA6C7B;AAED;;;;;GAKG;AACH,wBAAgB,2BAA2B,CACzC,MAAM,GAAE,OAAO,CAAC,uBAAuB,CAAM,GAC5C,kBAAkB,CAMpB"}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pattern Repository Factory
|
|
3
|
+
*
|
|
4
|
+
* Creates the appropriate pattern repository based on the storage format
|
|
5
|
+
* detected in the project. Handles automatic migration and format detection.
|
|
6
|
+
*
|
|
7
|
+
* @module patterns/impl/repository-factory
|
|
8
|
+
*/
|
|
9
|
+
import * as fs from 'node:fs/promises';
|
|
10
|
+
import * as path from 'node:path';
|
|
11
|
+
import { FilePatternRepository } from './file-repository.js';
|
|
12
|
+
import { UnifiedFilePatternRepository } from './unified-file-repository.js';
|
|
13
|
+
const DEFAULT_FACTORY_CONFIG = {
|
|
14
|
+
rootDir: process.cwd(),
|
|
15
|
+
autoSave: true,
|
|
16
|
+
autoSaveDelayMs: 1000,
|
|
17
|
+
validateSchema: true,
|
|
18
|
+
preferUnified: true,
|
|
19
|
+
autoMigrate: true,
|
|
20
|
+
keepLegacyFiles: true,
|
|
21
|
+
};
|
|
22
|
+
// ============================================================================
|
|
23
|
+
// Format Detection
|
|
24
|
+
// ============================================================================
|
|
25
|
+
async function fileExists(filePath) {
|
|
26
|
+
try {
|
|
27
|
+
await fs.access(filePath);
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Detect the storage format used in a project
|
|
36
|
+
*/
|
|
37
|
+
export async function detectStorageFormat(rootDir) {
|
|
38
|
+
const patternsDir = path.join(rootDir, '.drift', 'patterns');
|
|
39
|
+
// Check for unified format (category files with version 2.x)
|
|
40
|
+
const categories = ['api', 'auth', 'security', 'errors', 'structural'];
|
|
41
|
+
for (const category of categories) {
|
|
42
|
+
const filePath = path.join(patternsDir, `${category}.json`);
|
|
43
|
+
if (await fileExists(filePath)) {
|
|
44
|
+
try {
|
|
45
|
+
const content = await fs.readFile(filePath, 'utf-8');
|
|
46
|
+
const data = JSON.parse(content);
|
|
47
|
+
if (data.version?.startsWith('2.')) {
|
|
48
|
+
return 'unified';
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
// Not valid unified format
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
// Check for legacy format (status directories)
|
|
57
|
+
const legacyDirs = ['discovered', 'approved', 'ignored'];
|
|
58
|
+
for (const dir of legacyDirs) {
|
|
59
|
+
const statusDir = path.join(patternsDir, dir);
|
|
60
|
+
if (await fileExists(statusDir)) {
|
|
61
|
+
return 'legacy';
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return 'none';
|
|
65
|
+
}
|
|
66
|
+
// ============================================================================
|
|
67
|
+
// Factory Functions
|
|
68
|
+
// ============================================================================
|
|
69
|
+
/**
|
|
70
|
+
* Create a pattern repository with automatic format detection.
|
|
71
|
+
*
|
|
72
|
+
* - If unified format exists, uses UnifiedFilePatternRepository
|
|
73
|
+
* - If legacy format exists and autoMigrate is true, migrates to unified
|
|
74
|
+
* - If legacy format exists and autoMigrate is false, uses FilePatternRepository
|
|
75
|
+
* - If no format exists, creates new UnifiedFilePatternRepository
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```typescript
|
|
79
|
+
* const repository = await createPatternRepository({ rootDir: '/path/to/project' });
|
|
80
|
+
* await repository.initialize();
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
export async function createPatternRepository(config = {}) {
|
|
84
|
+
const fullConfig = { ...DEFAULT_FACTORY_CONFIG, ...config };
|
|
85
|
+
const format = await detectStorageFormat(fullConfig.rootDir);
|
|
86
|
+
switch (format) {
|
|
87
|
+
case 'unified':
|
|
88
|
+
// Already using unified format
|
|
89
|
+
return new UnifiedFilePatternRepository({
|
|
90
|
+
rootDir: fullConfig.rootDir,
|
|
91
|
+
autoSave: fullConfig.autoSave,
|
|
92
|
+
autoSaveDelayMs: fullConfig.autoSaveDelayMs,
|
|
93
|
+
autoMigrate: false, // Already unified
|
|
94
|
+
});
|
|
95
|
+
case 'legacy':
|
|
96
|
+
if (fullConfig.autoMigrate && fullConfig.preferUnified) {
|
|
97
|
+
// Migrate to unified format
|
|
98
|
+
console.log('[RepositoryFactory] Migrating from legacy to unified format...');
|
|
99
|
+
return new UnifiedFilePatternRepository({
|
|
100
|
+
rootDir: fullConfig.rootDir,
|
|
101
|
+
autoSave: fullConfig.autoSave,
|
|
102
|
+
autoSaveDelayMs: fullConfig.autoSaveDelayMs,
|
|
103
|
+
autoMigrate: true,
|
|
104
|
+
keepLegacyFiles: fullConfig.keepLegacyFiles,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
// Use legacy format
|
|
109
|
+
console.warn('[RepositoryFactory] Using legacy storage format. Run `drift migrate-storage` to upgrade.');
|
|
110
|
+
return new FilePatternRepository({
|
|
111
|
+
rootDir: fullConfig.rootDir,
|
|
112
|
+
autoSave: fullConfig.autoSave,
|
|
113
|
+
autoSaveDelayMs: fullConfig.autoSaveDelayMs,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
case 'none':
|
|
117
|
+
default:
|
|
118
|
+
// No existing format, create new unified
|
|
119
|
+
return new UnifiedFilePatternRepository({
|
|
120
|
+
rootDir: fullConfig.rootDir,
|
|
121
|
+
autoSave: fullConfig.autoSave,
|
|
122
|
+
autoSaveDelayMs: fullConfig.autoSaveDelayMs,
|
|
123
|
+
autoMigrate: false,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Create a pattern repository synchronously (uses unified format by default).
|
|
129
|
+
*
|
|
130
|
+
* This is useful when you can't use async/await but need a repository.
|
|
131
|
+
* Note: This always creates UnifiedFilePatternRepository with autoMigrate enabled.
|
|
132
|
+
*/
|
|
133
|
+
export function createPatternRepositorySync(config = {}) {
|
|
134
|
+
return new UnifiedFilePatternRepository({
|
|
135
|
+
...config,
|
|
136
|
+
autoMigrate: true,
|
|
137
|
+
keepLegacyFiles: true,
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
//# sourceMappingURL=repository-factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repository-factory.js","sourceRoot":"","sources":["../../../src/patterns/impl/repository-factory.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAGlC,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,4BAA4B,EAAgC,MAAM,8BAA8B,CAAC;AAe1G,MAAM,sB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