autosnippet 3.3.7 → 3.3.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dashboard/dist/assets/icons-BMNb0V6L.js +1 -0
- package/dashboard/dist/assets/index-DHJ1Dj7u.css +1 -0
- package/dashboard/dist/assets/index-DV8biUkH.js +112 -0
- package/dashboard/dist/index.html +3 -3
- package/dist/bin/cli.js +7 -4
- package/dist/lib/agent/core/ChatAgentPrompts.js +57 -21
- package/dist/lib/agent/core/LoopContext.d.ts +1 -0
- package/dist/lib/agent/core/ToolExecutionPipeline.js +13 -0
- package/dist/lib/agent/memory/ActiveContext.d.ts +0 -2
- package/dist/lib/agent/memory/ActiveContext.js +0 -2
- package/dist/lib/agent/memory/MemoryEmbeddingStore.d.ts +49 -0
- package/dist/lib/agent/memory/MemoryEmbeddingStore.js +159 -0
- package/dist/lib/agent/memory/MemoryRetriever.d.ts +2 -0
- package/dist/lib/agent/memory/MemoryRetriever.js +25 -11
- package/dist/lib/agent/memory/MemoryStore.d.ts +8 -41
- package/dist/lib/agent/memory/MemoryStore.js +196 -261
- package/dist/lib/agent/memory/PersistentMemory.d.ts +2 -0
- package/dist/lib/agent/memory/PersistentMemory.js +4 -5
- package/dist/lib/agent/memory/SessionStore.d.ts +0 -2
- package/dist/lib/agent/memory/SessionStore.js +0 -2
- package/dist/lib/agent/tools/ast-graph.js +21 -19
- package/dist/lib/agent/tools/infrastructure.js +3 -2
- package/dist/lib/agent/tools/project-access.d.ts +2 -2
- package/dist/lib/agent/tools/project-access.js +5 -4
- package/dist/lib/bootstrap.js +2 -1
- package/dist/lib/cli/AiScanService.js +4 -17
- package/dist/lib/cli/KnowledgeSyncService.d.ts +7 -37
- package/dist/lib/cli/KnowledgeSyncService.js +23 -51
- package/dist/lib/core/ast/ProjectGraph.js +5 -27
- package/dist/lib/core/discovery/CustomConfigDiscoverer.d.ts +0 -2
- package/dist/lib/core/discovery/CustomConfigDiscoverer.js +0 -2
- package/dist/lib/domain/dimension/DimensionRegistry.d.ts +0 -2
- package/dist/lib/domain/dimension/DimensionRegistry.js +0 -2
- package/dist/lib/domain/dimension/DimensionSop.js +44 -33
- package/dist/lib/domain/dimension/UnifiedDimension.d.ts +0 -2
- package/dist/lib/domain/dimension/UnifiedDimension.js +0 -2
- package/dist/lib/domain/knowledge/Lifecycle.d.ts +26 -0
- package/dist/lib/domain/knowledge/Lifecycle.js +42 -0
- package/dist/lib/domain/knowledge/index.d.ts +2 -1
- package/dist/lib/domain/knowledge/index.js +1 -1
- package/dist/lib/external/mcp/handlers/bootstrap/pipeline/BootstrapSnapshot.d.ts +2 -1
- package/dist/lib/external/mcp/handlers/bootstrap/pipeline/BootstrapSnapshot.js +102 -153
- package/dist/lib/external/mcp/handlers/bootstrap/pipeline/orchestrator.js +33 -16
- package/dist/lib/external/mcp/handlers/bootstrap/shared/bootstrap-phases.d.ts +1 -1
- package/dist/lib/external/mcp/handlers/bootstrap/shared/bootstrap-phases.js +41 -37
- package/dist/lib/external/mcp/handlers/bootstrap-external.js +1 -1
- package/dist/lib/external/mcp/handlers/dimension-complete-external.js +7 -3
- package/dist/lib/external/mcp/handlers/evolve-external.d.ts +1 -0
- package/dist/lib/external/mcp/handlers/evolve-external.js +13 -16
- package/dist/lib/external/mcp/handlers/guard.js +15 -24
- package/dist/lib/external/mcp/handlers/panorama.js +9 -9
- package/dist/lib/external/mcp/handlers/rescan-external.js +7 -6
- package/dist/lib/external/mcp/handlers/rescan-internal.js +9 -5
- package/dist/lib/external/mcp/handlers/search.js +3 -1
- package/dist/lib/external/mcp/handlers/skill.js +4 -4
- package/dist/lib/external/mcp/handlers/structure.js +8 -12
- package/dist/lib/external/mcp/handlers/system.js +10 -34
- package/dist/lib/http/routes/ai.js +11 -13
- package/dist/lib/http/routes/guardReport.js +3 -5
- package/dist/lib/http/routes/panorama.js +12 -12
- package/dist/lib/http/routes/recipes.js +59 -8
- package/dist/lib/http/routes/remote.js +3 -13
- package/dist/lib/http/routes/search.js +11 -8
- package/dist/lib/infrastructure/audit/AuditLogger.d.ts +20 -3
- package/dist/lib/infrastructure/audit/AuditStore.d.ts +28 -29
- package/dist/lib/infrastructure/audit/AuditStore.js +81 -88
- package/dist/lib/infrastructure/database/drizzle/schema.d.ts +180 -2
- package/dist/lib/infrastructure/database/drizzle/schema.js +23 -3
- package/dist/lib/injection/ServiceContainer.js +7 -4
- package/dist/lib/injection/ServiceMap.d.ts +20 -0
- package/dist/lib/injection/modules/AppModule.js +2 -1
- package/dist/lib/injection/modules/GuardModule.js +5 -5
- package/dist/lib/injection/modules/InfraModule.js +60 -0
- package/dist/lib/injection/modules/KnowledgeModule.js +86 -51
- package/dist/lib/injection/modules/PanoramaModule.js +16 -10
- package/dist/lib/injection/modules/VectorModule.js +3 -0
- package/dist/lib/repository/audit/AuditRepository.d.ts +107 -0
- package/dist/lib/repository/audit/AuditRepository.js +272 -0
- package/dist/lib/repository/base/RepositoryBase.d.ts +46 -0
- package/dist/lib/repository/base/RepositoryBase.js +32 -0
- package/dist/lib/repository/bootstrap/BootstrapRepository.d.ts +94 -0
- package/dist/lib/repository/bootstrap/BootstrapRepository.js +246 -0
- package/dist/lib/repository/code/CodeEntityRepository.d.ts +91 -0
- package/dist/lib/repository/code/CodeEntityRepository.js +361 -0
- package/dist/lib/repository/delivery/DeliveryRepoAdapter.d.ts +39 -0
- package/dist/lib/repository/delivery/DeliveryRepoAdapter.js +23 -0
- package/dist/lib/repository/evolution/LifecycleEventRepository.d.ts +51 -0
- package/dist/lib/repository/evolution/LifecycleEventRepository.js +119 -0
- package/dist/lib/repository/evolution/ProposalRepository.d.ts +9 -12
- package/dist/lib/repository/evolution/ProposalRepository.js +114 -57
- package/dist/lib/repository/guard/GuardViolationRepository.d.ts +104 -0
- package/dist/lib/repository/guard/GuardViolationRepository.js +217 -0
- package/dist/lib/repository/knowledge/KnowledgeEdgeRepository.d.ts +129 -0
- package/dist/lib/repository/knowledge/KnowledgeEdgeRepository.js +475 -0
- package/dist/lib/repository/knowledge/KnowledgeFileStore.d.ts +39 -0
- package/dist/lib/repository/knowledge/KnowledgeFileStore.js +12 -0
- package/dist/lib/repository/knowledge/KnowledgeRepository.impl.d.ts +295 -11
- package/dist/lib/repository/knowledge/KnowledgeRepository.impl.js +608 -13
- package/dist/lib/repository/knowledge/KnowledgeUnitOfWork.d.ts +61 -0
- package/dist/lib/repository/knowledge/KnowledgeUnitOfWork.js +156 -0
- package/dist/lib/repository/memory/MemoryRepository.d.ts +90 -0
- package/dist/lib/repository/memory/MemoryRepository.js +260 -0
- package/dist/lib/repository/search/SearchRepoAdapter.d.ts +92 -0
- package/dist/lib/repository/search/SearchRepoAdapter.js +124 -0
- package/dist/lib/repository/session/SessionRepository.d.ts +46 -0
- package/dist/lib/repository/session/SessionRepository.js +110 -0
- package/dist/lib/repository/sourceref/RecipeSourceRefRepository.d.ts +66 -0
- package/dist/lib/repository/sourceref/RecipeSourceRefRepository.js +182 -0
- package/dist/lib/repository/sync/SyncRepoAdapter.d.ts +58 -0
- package/dist/lib/repository/sync/SyncRepoAdapter.js +58 -0
- package/dist/lib/service/bootstrap/UiStartupTasks.js +5 -6
- package/dist/lib/service/bootstrap/bootstrap-event-types.d.ts +0 -1
- package/dist/lib/service/bootstrap/bootstrap-event-types.js +0 -1
- package/dist/lib/service/cleanup/CleanupService.js +8 -4
- package/dist/lib/service/delivery/CursorDeliveryPipeline.js +6 -8
- package/dist/lib/service/evolution/ConsolidationAdvisor.d.ts +4 -9
- package/dist/lib/service/evolution/ConsolidationAdvisor.js +34 -70
- package/dist/lib/service/evolution/ContentPatcher.d.ts +4 -12
- package/dist/lib/service/evolution/ContentPatcher.js +48 -19
- package/dist/lib/service/evolution/ContradictionDetector.d.ts +3 -7
- package/dist/lib/service/evolution/ContradictionDetector.js +17 -24
- package/dist/lib/service/evolution/DecayDetector.d.ts +10 -9
- package/dist/lib/service/evolution/DecayDetector.js +63 -57
- package/dist/lib/service/evolution/EnhancementSuggester.d.ts +3 -9
- package/dist/lib/service/evolution/EnhancementSuggester.js +42 -86
- package/dist/lib/service/evolution/KnowledgeMetabolism.d.ts +4 -4
- package/dist/lib/service/evolution/KnowledgeMetabolism.js +102 -71
- package/dist/lib/service/evolution/ProposalExecutor.d.ts +5 -12
- package/dist/lib/service/evolution/ProposalExecutor.js +64 -69
- package/dist/lib/service/evolution/RecipeLifecycleSupervisor.d.ts +9 -14
- package/dist/lib/service/evolution/RecipeLifecycleSupervisor.js +94 -155
- package/dist/lib/service/evolution/RecipeRelevanceAuditor.d.ts +4 -1
- package/dist/lib/service/evolution/RecipeRelevanceAuditor.js +50 -49
- package/dist/lib/service/evolution/RedundancyAnalyzer.d.ts +3 -7
- package/dist/lib/service/evolution/RedundancyAnalyzer.js +15 -22
- package/dist/lib/service/evolution/StagingManager.d.ts +6 -15
- package/dist/lib/service/evolution/StagingManager.js +37 -95
- package/dist/lib/service/evolution/createSupersedeProposal.d.ts +1 -1
- package/dist/lib/service/evolution/createSupersedeProposal.js +7 -8
- package/dist/lib/service/guard/CoverageAnalyzer.d.ts +3 -7
- package/dist/lib/service/guard/CoverageAnalyzer.js +9 -11
- package/dist/lib/service/guard/GuardCheckEngine.d.ts +3 -0
- package/dist/lib/service/guard/GuardCheckEngine.js +14 -22
- package/dist/lib/service/guard/ReverseGuard.d.ts +4 -7
- package/dist/lib/service/guard/ReverseGuard.js +21 -31
- package/dist/lib/service/guard/ViolationsStore.d.ts +15 -21
- package/dist/lib/service/guard/ViolationsStore.js +75 -69
- package/dist/lib/service/knowledge/CodeEntityGraph.d.ts +39 -63
- package/dist/lib/service/knowledge/CodeEntityGraph.js +418 -512
- package/dist/lib/service/knowledge/ConfidenceRouter.js +18 -9
- package/dist/lib/service/knowledge/KnowledgeFileWriter.d.ts +2 -1
- package/dist/lib/service/knowledge/KnowledgeGraphService.d.ts +18 -60
- package/dist/lib/service/knowledge/KnowledgeGraphService.js +58 -109
- package/dist/lib/service/knowledge/KnowledgeService.d.ts +15 -1
- package/dist/lib/service/knowledge/KnowledgeService.js +76 -38
- package/dist/lib/service/knowledge/RecipeProductionGateway.d.ts +0 -2
- package/dist/lib/service/knowledge/RecipeProductionGateway.js +0 -2
- package/dist/lib/service/knowledge/SourceRefReconciler.d.ts +5 -13
- package/dist/lib/service/knowledge/SourceRefReconciler.js +58 -78
- package/dist/lib/service/panorama/CouplingAnalyzer.d.ts +5 -3
- package/dist/lib/service/panorama/CouplingAnalyzer.js +102 -39
- package/dist/lib/service/panorama/DimensionAnalyzer.d.ts +7 -4
- package/dist/lib/service/panorama/DimensionAnalyzer.js +72 -25
- package/dist/lib/service/panorama/LayerInferrer.js +1 -1
- package/dist/lib/service/panorama/ModuleDiscoverer.d.ts +7 -6
- package/dist/lib/service/panorama/ModuleDiscoverer.js +174 -82
- package/dist/lib/service/panorama/PanoramaAggregator.d.ts +10 -3
- package/dist/lib/service/panorama/PanoramaAggregator.js +67 -79
- package/dist/lib/service/panorama/PanoramaScanner.d.ts +5 -1
- package/dist/lib/service/panorama/PanoramaScanner.js +32 -31
- package/dist/lib/service/panorama/PanoramaService.d.ts +11 -8
- package/dist/lib/service/panorama/PanoramaService.js +41 -66
- package/dist/lib/service/panorama/PanoramaTypes.d.ts +3 -0
- package/dist/lib/service/panorama/RoleRefiner.d.ts +8 -5
- package/dist/lib/service/panorama/RoleRefiner.js +52 -283
- package/dist/lib/service/panorama/TechStackProfiler.js +7 -119
- package/dist/lib/service/quality/QualityScorer.d.ts +45 -26
- package/dist/lib/service/quality/QualityScorer.js +157 -83
- package/dist/lib/service/search/SearchEngine.d.ts +1 -0
- package/dist/lib/service/search/SearchEngine.js +32 -37
- package/dist/lib/service/signal/HitRecorder.js +5 -5
- package/dist/lib/service/skills/RuleRecallStrategy.js +7 -3
- package/dist/lib/service/skills/SignalCollector.d.ts +5 -8
- package/dist/lib/service/skills/SignalCollector.js +28 -55
- package/dist/lib/service/skills/SkillAdvisor.d.ts +7 -13
- package/dist/lib/service/skills/SkillAdvisor.js +30 -79
- package/dist/lib/service/vector/SyncCoordinator.d.ts +3 -1
- package/dist/lib/service/vector/SyncCoordinator.js +25 -3
- package/dist/lib/service/vector/VectorService.d.ts +2 -0
- package/dist/lib/service/vector/VectorService.js +3 -0
- package/dist/lib/service/wiki/WikiGenerator.js +1 -1
- package/dist/lib/shared/LanguageProfiles.d.ts +109 -0
- package/dist/lib/shared/LanguageProfiles.js +939 -0
- package/dist/lib/shared/LanguageService.d.ts +6 -0
- package/dist/lib/shared/LanguageService.js +16 -0
- package/dist/lib/shared/constants.d.ts +19 -19
- package/dist/lib/shared/constants.js +10 -10
- package/dist/lib/shared/schemas/mcp-tools.d.ts +1 -1
- package/dist/lib/types/project-snapshot-builder.d.ts +0 -1
- package/dist/lib/types/project-snapshot-builder.js +0 -1
- package/dist/lib/types/project-snapshot.d.ts +0 -1
- package/dist/lib/types/project-snapshot.js +0 -1
- package/dist/lib/types/snapshot-views.d.ts +0 -2
- package/dist/lib/types/snapshot-views.js +0 -1
- package/package.json +2 -1
- package/dashboard/dist/assets/icons-FHns2ypa.js +0 -1
- package/dashboard/dist/assets/index-BRJv5Y3r.js +0 -135
- package/dashboard/dist/assets/index-DzoB7kxK.css +0 -1
- package/dist/lib/repository/base/BaseRepository.d.ts +0 -53
- package/dist/lib/repository/base/BaseRepository.js +0 -226
|
@@ -1,226 +0,0 @@
|
|
|
1
|
-
import Logger from '../../infrastructure/logging/Logger.js';
|
|
2
|
-
import { unixNow } from '../../shared/utils/common.js';
|
|
3
|
-
/** Only allow safe SQL identifier characters: letters, digits, underscore */
|
|
4
|
-
const SAFE_IDENTIFIER_RE = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
|
|
5
|
-
/** @deprecated alias — use SAFE_IDENTIFIER_RE */
|
|
6
|
-
const SAFE_COLUMN_RE = SAFE_IDENTIFIER_RE;
|
|
7
|
-
/**
|
|
8
|
-
* BaseRepository - 基础仓储类
|
|
9
|
-
* 提供通用的 CRUD 操作和查询功能
|
|
10
|
-
*/
|
|
11
|
-
export class BaseRepository {
|
|
12
|
-
db;
|
|
13
|
-
logger;
|
|
14
|
-
tableName;
|
|
15
|
-
/** lazily-populated column whitelist */
|
|
16
|
-
#columnWhitelist = null;
|
|
17
|
-
constructor(database, tableName) {
|
|
18
|
-
// 校验 tableName 防止 SQL 注入(与列名使用相同的标识符规则)
|
|
19
|
-
if (!SAFE_IDENTIFIER_RE.test(tableName)) {
|
|
20
|
-
throw new Error(`Invalid table name: ${tableName}`);
|
|
21
|
-
}
|
|
22
|
-
this.db = database.getDb();
|
|
23
|
-
this.tableName = tableName;
|
|
24
|
-
this.logger = Logger.getInstance();
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Validate that a column name is safe for SQL interpolation.
|
|
28
|
-
* Rejects anything that doesn't match /^[a-zA-Z_]\w*$/ or
|
|
29
|
-
* is not a real column in the table.
|
|
30
|
-
*/
|
|
31
|
-
_assertSafeColumn(key) {
|
|
32
|
-
if (!SAFE_COLUMN_RE.test(key)) {
|
|
33
|
-
throw new Error(`Invalid column name: ${key}`);
|
|
34
|
-
}
|
|
35
|
-
// Lazily build column whitelist from table pragma
|
|
36
|
-
if (!this.#columnWhitelist) {
|
|
37
|
-
try {
|
|
38
|
-
const cols = this.db
|
|
39
|
-
.prepare(`PRAGMA table_info(${this.tableName})`)
|
|
40
|
-
.all();
|
|
41
|
-
this.#columnWhitelist = new Set(cols.map((c) => c.name));
|
|
42
|
-
}
|
|
43
|
-
catch {
|
|
44
|
-
this.#columnWhitelist = new Set();
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
if (this.#columnWhitelist.size > 0 && !this.#columnWhitelist.has(key)) {
|
|
48
|
-
throw new Error(`Unknown column "${key}" for table ${this.tableName}`);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
/** 创建实体 */
|
|
52
|
-
async create(entity) {
|
|
53
|
-
throw new Error('create() must be implemented in subclass');
|
|
54
|
-
}
|
|
55
|
-
/** 根据 ID 获取实体 */
|
|
56
|
-
async findById(id) {
|
|
57
|
-
try {
|
|
58
|
-
const stmt = this.db.prepare(`
|
|
59
|
-
SELECT * FROM ${this.tableName} WHERE id = ? LIMIT 1
|
|
60
|
-
`);
|
|
61
|
-
const row = stmt.get(id);
|
|
62
|
-
if (!row) {
|
|
63
|
-
return null;
|
|
64
|
-
}
|
|
65
|
-
return this._mapRowToEntity(row);
|
|
66
|
-
}
|
|
67
|
-
catch (error) {
|
|
68
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
69
|
-
this.logger.error(`Error finding by id in ${this.tableName}`, {
|
|
70
|
-
id,
|
|
71
|
-
error: message,
|
|
72
|
-
});
|
|
73
|
-
throw error;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
/** 获取所有实体 */
|
|
77
|
-
async findAll(filters = {}) {
|
|
78
|
-
try {
|
|
79
|
-
let query = `SELECT * FROM ${this.tableName}`;
|
|
80
|
-
const params = [];
|
|
81
|
-
// 添加过滤条件
|
|
82
|
-
if (Object.keys(filters).length > 0) {
|
|
83
|
-
const conditions = Object.keys(filters).map((key) => {
|
|
84
|
-
this._assertSafeColumn(key);
|
|
85
|
-
params.push(filters[key]);
|
|
86
|
-
return `${key} = ?`;
|
|
87
|
-
});
|
|
88
|
-
query += ` WHERE ${conditions.join(' AND ')}`;
|
|
89
|
-
}
|
|
90
|
-
query += ' ORDER BY created_at DESC';
|
|
91
|
-
const stmt = this.db.prepare(query);
|
|
92
|
-
const rows = stmt.all(...params);
|
|
93
|
-
return rows.map((row) => this._mapRowToEntity(row));
|
|
94
|
-
}
|
|
95
|
-
catch (error) {
|
|
96
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
97
|
-
this.logger.error(`Error finding all in ${this.tableName}`, {
|
|
98
|
-
error: message,
|
|
99
|
-
});
|
|
100
|
-
throw error;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
/** 分页查询 */
|
|
104
|
-
async findWithPagination(filters = {}, { page = 1, pageSize = 20 } = {}) {
|
|
105
|
-
try {
|
|
106
|
-
const offset = (page - 1) * pageSize;
|
|
107
|
-
let countQuery = `SELECT COUNT(*) as count FROM ${this.tableName}`;
|
|
108
|
-
let query = `SELECT * FROM ${this.tableName}`;
|
|
109
|
-
const params = [];
|
|
110
|
-
// 添加过滤条件
|
|
111
|
-
if (Object.keys(filters).length > 0) {
|
|
112
|
-
const conditions = Object.keys(filters).map((key) => {
|
|
113
|
-
this._assertSafeColumn(key);
|
|
114
|
-
params.push(filters[key]);
|
|
115
|
-
return `${key} = ?`;
|
|
116
|
-
});
|
|
117
|
-
const whereClause = ` WHERE ${conditions.join(' AND ')}`;
|
|
118
|
-
countQuery += whereClause;
|
|
119
|
-
query += whereClause;
|
|
120
|
-
}
|
|
121
|
-
// 获取总数
|
|
122
|
-
const countStmt = this.db.prepare(countQuery);
|
|
123
|
-
const countResult = countStmt.get(...params.slice(0, Object.keys(filters).length));
|
|
124
|
-
const total = countResult.count;
|
|
125
|
-
// 获取分页数据
|
|
126
|
-
query += ' ORDER BY created_at DESC LIMIT ? OFFSET ?';
|
|
127
|
-
const dataStmt = this.db.prepare(query);
|
|
128
|
-
const data = dataStmt.all(...params.slice(0, Object.keys(filters).length), pageSize, offset);
|
|
129
|
-
return {
|
|
130
|
-
data: data.map((row) => this._mapRowToEntity(row)),
|
|
131
|
-
pagination: {
|
|
132
|
-
page,
|
|
133
|
-
pageSize,
|
|
134
|
-
total,
|
|
135
|
-
pages: Math.ceil(total / pageSize),
|
|
136
|
-
},
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
catch (error) {
|
|
140
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
141
|
-
this.logger.error(`Error in pagination for ${this.tableName}`, {
|
|
142
|
-
error: message,
|
|
143
|
-
});
|
|
144
|
-
throw error;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
/** 更新实体 */
|
|
148
|
-
async update(id, updates) {
|
|
149
|
-
try {
|
|
150
|
-
const updateKeys = Object.keys(updates);
|
|
151
|
-
const updateValues = Object.values(updates);
|
|
152
|
-
for (const key of updateKeys) {
|
|
153
|
-
this._assertSafeColumn(key);
|
|
154
|
-
}
|
|
155
|
-
const setClause = updateKeys.map((key) => `${key} = ?`).join(', ');
|
|
156
|
-
const query = `
|
|
157
|
-
UPDATE ${this.tableName}
|
|
158
|
-
SET ${setClause}, updated_at = ?
|
|
159
|
-
WHERE id = ?
|
|
160
|
-
`;
|
|
161
|
-
const stmt = this.db.prepare(query);
|
|
162
|
-
stmt.run(...updateValues, unixNow(), id);
|
|
163
|
-
return this.findById(id);
|
|
164
|
-
}
|
|
165
|
-
catch (error) {
|
|
166
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
167
|
-
this.logger.error(`Error updating in ${this.tableName}`, {
|
|
168
|
-
id,
|
|
169
|
-
error: message,
|
|
170
|
-
});
|
|
171
|
-
throw error;
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
/** 删除实体 */
|
|
175
|
-
async delete(id) {
|
|
176
|
-
try {
|
|
177
|
-
const stmt = this.db.prepare(`
|
|
178
|
-
DELETE FROM ${this.tableName} WHERE id = ?
|
|
179
|
-
`);
|
|
180
|
-
const result = stmt.run(id);
|
|
181
|
-
return result.changes > 0;
|
|
182
|
-
}
|
|
183
|
-
catch (error) {
|
|
184
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
185
|
-
this.logger.error(`Error deleting from ${this.tableName}`, {
|
|
186
|
-
id,
|
|
187
|
-
error: message,
|
|
188
|
-
});
|
|
189
|
-
throw error;
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
/** 计数 */
|
|
193
|
-
async count(filters = {}) {
|
|
194
|
-
try {
|
|
195
|
-
let query = `SELECT COUNT(*) as count FROM ${this.tableName}`;
|
|
196
|
-
const params = [];
|
|
197
|
-
if (Object.keys(filters).length > 0) {
|
|
198
|
-
const conditions = Object.keys(filters).map((key) => {
|
|
199
|
-
this._assertSafeColumn(key);
|
|
200
|
-
params.push(filters[key]);
|
|
201
|
-
return `${key} = ?`;
|
|
202
|
-
});
|
|
203
|
-
query += ` WHERE ${conditions.join(' AND ')}`;
|
|
204
|
-
}
|
|
205
|
-
const stmt = this.db.prepare(query);
|
|
206
|
-
const result = stmt.get(...params);
|
|
207
|
-
return result.count;
|
|
208
|
-
}
|
|
209
|
-
catch (error) {
|
|
210
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
211
|
-
this.logger.error(`Error counting in ${this.tableName}`, {
|
|
212
|
-
error: message,
|
|
213
|
-
});
|
|
214
|
-
throw error;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
/** 映射行数据到实体(由子类实现) */
|
|
218
|
-
_mapRowToEntity(row) {
|
|
219
|
-
throw new Error('_mapRowToEntity() must be implemented in subclass');
|
|
220
|
-
}
|
|
221
|
-
/** 映射实体到行数据(由子类实现) */
|
|
222
|
-
_mapEntityToRow(entity) {
|
|
223
|
-
throw new Error('_mapEntityToRow() must be implemented in subclass');
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
export default BaseRepository;
|