ghagga-db 2.0.1 → 2.2.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/migrate.d.ts +8 -0
- package/dist/migrate.d.ts.map +1 -0
- package/dist/migrate.js +53 -0
- package/dist/migrate.js.map +1 -0
- package/dist/queries.d.ts +223 -9
- package/dist/queries.d.ts.map +1 -1
- package/dist/queries.js +365 -8
- package/dist/queries.js.map +1 -1
- package/dist/schema.d.ts +249 -19
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +31 -6
- package/dist/schema.js.map +1 -1
- package/package.json +8 -5
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrate.d.ts","sourceRoot":"","sources":["../src/migrate.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|
package/dist/migrate.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Database migration script.
|
|
3
|
+
*
|
|
4
|
+
* Runs Drizzle migrations + custom SQL (tsvector) in order.
|
|
5
|
+
* Usage: DATABASE_URL=... tsx src/migrate.ts
|
|
6
|
+
*/
|
|
7
|
+
import { drizzle } from 'drizzle-orm/node-postgres';
|
|
8
|
+
import { migrate } from 'drizzle-orm/node-postgres/migrator';
|
|
9
|
+
import pg from 'pg';
|
|
10
|
+
import { readFileSync } from 'node:fs';
|
|
11
|
+
import { join, dirname } from 'node:path';
|
|
12
|
+
import { fileURLToPath } from 'node:url';
|
|
13
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
14
|
+
async function main() {
|
|
15
|
+
const url = process.env.DATABASE_URL;
|
|
16
|
+
if (!url) {
|
|
17
|
+
console.error('❌ DATABASE_URL is required');
|
|
18
|
+
process.exit(1);
|
|
19
|
+
}
|
|
20
|
+
console.log('🔄 Running Drizzle migrations...');
|
|
21
|
+
const pool = new pg.Pool({ connectionString: url, max: 1 });
|
|
22
|
+
const db = drizzle(pool);
|
|
23
|
+
// Step 1: Run Drizzle-managed migrations
|
|
24
|
+
await migrate(db, {
|
|
25
|
+
migrationsFolder: join(__dirname, '..', 'drizzle'),
|
|
26
|
+
});
|
|
27
|
+
console.log('✅ Drizzle migrations complete');
|
|
28
|
+
// Step 2: Run custom SQL (tsvector, triggers)
|
|
29
|
+
const customSqlPath = join(__dirname, '..', 'drizzle', '0001_add_tsvector.sql');
|
|
30
|
+
try {
|
|
31
|
+
const customSql = readFileSync(customSqlPath, 'utf-8');
|
|
32
|
+
console.log('🔄 Running custom SQL (tsvector + triggers)...');
|
|
33
|
+
await pool.query(customSql);
|
|
34
|
+
console.log('✅ Custom SQL complete');
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
// If the file doesn't exist or SQL fails on "already exists", that's fine
|
|
38
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
39
|
+
if (message.includes('ENOENT')) {
|
|
40
|
+
console.log('⏭️ No custom SQL file found, skipping');
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
console.warn('⚠️ Custom SQL warning (may be safe to ignore):', message);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
await pool.end();
|
|
47
|
+
console.log('🎉 Database ready');
|
|
48
|
+
}
|
|
49
|
+
main().catch((err) => {
|
|
50
|
+
console.error('❌ Migration failed:', err);
|
|
51
|
+
process.exit(1);
|
|
52
|
+
});
|
|
53
|
+
//# sourceMappingURL=migrate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrate.js","sourceRoot":"","sources":["../src/migrate.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,oCAAoC,CAAC;AAC7D,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,OAAO,EA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AAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACvE,IAAI,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC/B,OAAO,CAAC,GAAG,CAAC,wCAAwC,CAAC,CAAC;QACxD,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,IAAI,CAAC,iDAAiD,EAAE,OAAO,CAAC,CAAC;QAC3E,CAAC;IACH,CAAC;IAED,MAAM,IAAI,CAAC,GAAG,EAAE,CAAC;IACjB,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;AACnC,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;IACnB,OAAO,CAAC,KAAK,CAAC,qBAAqB,EAAE,GAAG,CAAC,CAAC;IAC1C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
package/dist/queries.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Database } from './client.js';
|
|
2
|
-
import { type RepoSettings } from './schema.js';
|
|
2
|
+
import { type RepoSettings, type DbProviderChainEntry } from './schema.js';
|
|
3
3
|
export declare function upsertInstallation(db: Database, data: {
|
|
4
4
|
githubInstallationId: number;
|
|
5
5
|
accountLogin: string;
|
|
@@ -14,6 +14,78 @@ export declare function upsertInstallation(db: Database, data: {
|
|
|
14
14
|
updatedAt: Date;
|
|
15
15
|
}>;
|
|
16
16
|
export declare function deactivateInstallation(db: Database, githubInstallationId: number): Promise<void>;
|
|
17
|
+
export declare function getInstallationByGitHubId(db: Database, githubInstallationId: number): Promise<{
|
|
18
|
+
id: number;
|
|
19
|
+
githubInstallationId: number;
|
|
20
|
+
accountLogin: string;
|
|
21
|
+
accountType: string;
|
|
22
|
+
isActive: boolean;
|
|
23
|
+
createdAt: Date;
|
|
24
|
+
updatedAt: Date;
|
|
25
|
+
}>;
|
|
26
|
+
export declare function getInstallationsByAccountLogin(db: Database, accountLogin: string): Promise<{
|
|
27
|
+
id: number;
|
|
28
|
+
githubInstallationId: number;
|
|
29
|
+
accountLogin: string;
|
|
30
|
+
accountType: string;
|
|
31
|
+
isActive: boolean;
|
|
32
|
+
createdAt: Date;
|
|
33
|
+
updatedAt: Date;
|
|
34
|
+
}[]>;
|
|
35
|
+
export declare function getInstallationSettings(db: Database, installationId: number): Promise<{
|
|
36
|
+
id: number;
|
|
37
|
+
installationId: number;
|
|
38
|
+
providerChain: DbProviderChainEntry[];
|
|
39
|
+
aiReviewEnabled: boolean;
|
|
40
|
+
reviewMode: string;
|
|
41
|
+
settings: RepoSettings;
|
|
42
|
+
createdAt: Date;
|
|
43
|
+
updatedAt: Date;
|
|
44
|
+
}>;
|
|
45
|
+
export declare function upsertInstallationSettings(db: Database, installationId: number, updates: {
|
|
46
|
+
providerChain?: DbProviderChainEntry[];
|
|
47
|
+
aiReviewEnabled?: boolean;
|
|
48
|
+
reviewMode?: string;
|
|
49
|
+
settings?: RepoSettings;
|
|
50
|
+
}): Promise<{
|
|
51
|
+
id: number;
|
|
52
|
+
createdAt: Date;
|
|
53
|
+
updatedAt: Date;
|
|
54
|
+
installationId: number;
|
|
55
|
+
providerChain: DbProviderChainEntry[];
|
|
56
|
+
aiReviewEnabled: boolean;
|
|
57
|
+
reviewMode: string;
|
|
58
|
+
settings: RepoSettings;
|
|
59
|
+
}>;
|
|
60
|
+
export declare function getInstallationById(db: Database, installationId: number): Promise<{
|
|
61
|
+
id: number;
|
|
62
|
+
githubInstallationId: number;
|
|
63
|
+
accountLogin: string;
|
|
64
|
+
accountType: string;
|
|
65
|
+
isActive: boolean;
|
|
66
|
+
createdAt: Date;
|
|
67
|
+
updatedAt: Date;
|
|
68
|
+
}>;
|
|
69
|
+
/**
|
|
70
|
+
* Resolve the effective settings for a repository.
|
|
71
|
+
* If use_global_settings is true, returns installation-level settings.
|
|
72
|
+
* Otherwise returns the repo's own settings.
|
|
73
|
+
*/
|
|
74
|
+
export interface EffectiveSettings {
|
|
75
|
+
providerChain: DbProviderChainEntry[];
|
|
76
|
+
aiReviewEnabled: boolean;
|
|
77
|
+
reviewMode: string;
|
|
78
|
+
settings: RepoSettings;
|
|
79
|
+
source: 'global' | 'repo';
|
|
80
|
+
}
|
|
81
|
+
export declare function getEffectiveRepoSettings(db: Database, repo: {
|
|
82
|
+
installationId: number;
|
|
83
|
+
useGlobalSettings: boolean;
|
|
84
|
+
providerChain: DbProviderChainEntry[] | unknown;
|
|
85
|
+
aiReviewEnabled: boolean;
|
|
86
|
+
reviewMode: string;
|
|
87
|
+
settings: RepoSettings | unknown;
|
|
88
|
+
}): Promise<EffectiveSettings>;
|
|
17
89
|
export declare function upsertRepository(db: Database, data: {
|
|
18
90
|
githubRepoId: number;
|
|
19
91
|
installationId: number;
|
|
@@ -23,14 +95,17 @@ export declare function upsertRepository(db: Database, data: {
|
|
|
23
95
|
isActive: boolean;
|
|
24
96
|
createdAt: Date;
|
|
25
97
|
updatedAt: Date;
|
|
26
|
-
githubRepoId: number;
|
|
27
98
|
installationId: number;
|
|
28
|
-
|
|
99
|
+
providerChain: DbProviderChainEntry[];
|
|
100
|
+
aiReviewEnabled: boolean;
|
|
101
|
+
reviewMode: string;
|
|
29
102
|
settings: RepoSettings;
|
|
103
|
+
githubRepoId: number;
|
|
104
|
+
fullName: string;
|
|
105
|
+
useGlobalSettings: boolean;
|
|
30
106
|
encryptedApiKey: string | null;
|
|
31
107
|
llmProvider: string;
|
|
32
108
|
llmModel: string | null;
|
|
33
|
-
reviewMode: string;
|
|
34
109
|
}>;
|
|
35
110
|
export declare function getRepoByFullName(db: Database, fullName: string): Promise<{
|
|
36
111
|
id: number;
|
|
@@ -39,10 +114,13 @@ export declare function getRepoByFullName(db: Database, fullName: string): Promi
|
|
|
39
114
|
fullName: string;
|
|
40
115
|
isActive: boolean;
|
|
41
116
|
settings: RepoSettings;
|
|
117
|
+
reviewMode: string;
|
|
118
|
+
useGlobalSettings: boolean;
|
|
119
|
+
providerChain: DbProviderChainEntry[];
|
|
120
|
+
aiReviewEnabled: boolean;
|
|
42
121
|
encryptedApiKey: string | null;
|
|
43
122
|
llmProvider: string;
|
|
44
123
|
llmModel: string | null;
|
|
45
|
-
reviewMode: string;
|
|
46
124
|
createdAt: Date;
|
|
47
125
|
updatedAt: Date;
|
|
48
126
|
}>;
|
|
@@ -53,10 +131,13 @@ export declare function getRepoByGithubId(db: Database, githubRepoId: number): P
|
|
|
53
131
|
fullName: string;
|
|
54
132
|
isActive: boolean;
|
|
55
133
|
settings: RepoSettings;
|
|
134
|
+
reviewMode: string;
|
|
135
|
+
useGlobalSettings: boolean;
|
|
136
|
+
providerChain: DbProviderChainEntry[];
|
|
137
|
+
aiReviewEnabled: boolean;
|
|
56
138
|
encryptedApiKey: string | null;
|
|
57
139
|
llmProvider: string;
|
|
58
140
|
llmModel: string | null;
|
|
59
|
-
reviewMode: string;
|
|
60
141
|
createdAt: Date;
|
|
61
142
|
updatedAt: Date;
|
|
62
143
|
}>;
|
|
@@ -65,6 +146,9 @@ export declare function updateRepoSettings(db: Database, repoId: number, updates
|
|
|
65
146
|
llmProvider?: string;
|
|
66
147
|
llmModel?: string;
|
|
67
148
|
reviewMode?: string;
|
|
149
|
+
providerChain?: DbProviderChainEntry[];
|
|
150
|
+
aiReviewEnabled?: boolean;
|
|
151
|
+
useGlobalSettings?: boolean;
|
|
68
152
|
}): Promise<void>;
|
|
69
153
|
export declare function saveRepoApiKey(db: Database, repoId: number, encryptedKey: string): Promise<void>;
|
|
70
154
|
export declare function removeRepoApiKey(db: Database, repoId: number): Promise<void>;
|
|
@@ -75,10 +159,13 @@ export declare function getReposByInstallationId(db: Database, installationId: n
|
|
|
75
159
|
fullName: string;
|
|
76
160
|
isActive: boolean;
|
|
77
161
|
settings: RepoSettings;
|
|
162
|
+
reviewMode: string;
|
|
163
|
+
useGlobalSettings: boolean;
|
|
164
|
+
providerChain: DbProviderChainEntry[];
|
|
165
|
+
aiReviewEnabled: boolean;
|
|
78
166
|
encryptedApiKey: string | null;
|
|
79
167
|
llmProvider: string;
|
|
80
168
|
llmModel: string | null;
|
|
81
|
-
reviewMode: string;
|
|
82
169
|
createdAt: Date;
|
|
83
170
|
updatedAt: Date;
|
|
84
171
|
}[]>;
|
|
@@ -146,8 +233,11 @@ export declare function getSessionsByProject(db: Database, project: string, opti
|
|
|
146
233
|
project: string;
|
|
147
234
|
prNumber: number | null;
|
|
148
235
|
summary: string | null;
|
|
149
|
-
|
|
150
|
-
|
|
236
|
+
createdAt: Date;
|
|
237
|
+
observationCount: number;
|
|
238
|
+
criticalCount: number;
|
|
239
|
+
highCount: number;
|
|
240
|
+
mediumCount: number;
|
|
151
241
|
}[]>;
|
|
152
242
|
export declare function saveObservation(db: Database, data: {
|
|
153
243
|
sessionId?: number;
|
|
@@ -157,6 +247,7 @@ export declare function saveObservation(db: Database, data: {
|
|
|
157
247
|
content: string;
|
|
158
248
|
topicKey?: string;
|
|
159
249
|
filePaths?: string[];
|
|
250
|
+
severity?: string;
|
|
160
251
|
}): Promise<{
|
|
161
252
|
id: number;
|
|
162
253
|
createdAt: Date;
|
|
@@ -166,6 +257,7 @@ export declare function saveObservation(db: Database, data: {
|
|
|
166
257
|
type: string;
|
|
167
258
|
title: string;
|
|
168
259
|
content: string;
|
|
260
|
+
severity: string | null;
|
|
169
261
|
topicKey: string | null;
|
|
170
262
|
filePaths: string[] | null;
|
|
171
263
|
contentHash: string | null;
|
|
@@ -185,6 +277,7 @@ export declare function searchObservations(db: Database, project: string, query:
|
|
|
185
277
|
type: string;
|
|
186
278
|
title: string;
|
|
187
279
|
content: string;
|
|
280
|
+
severity: string | null;
|
|
188
281
|
topicKey: string | null;
|
|
189
282
|
filePaths: string[] | null;
|
|
190
283
|
contentHash: string | null;
|
|
@@ -199,6 +292,7 @@ export declare function getObservationsBySession(db: Database, sessionId: number
|
|
|
199
292
|
type: string;
|
|
200
293
|
title: string;
|
|
201
294
|
content: string;
|
|
295
|
+
severity: string | null;
|
|
202
296
|
topicKey: string | null;
|
|
203
297
|
filePaths: string[] | null;
|
|
204
298
|
contentHash: string | null;
|
|
@@ -206,6 +300,75 @@ export declare function getObservationsBySession(db: Database, sessionId: number
|
|
|
206
300
|
createdAt: Date;
|
|
207
301
|
updatedAt: Date;
|
|
208
302
|
}[]>;
|
|
303
|
+
/**
|
|
304
|
+
* Delete a single observation by ID, scoped to installation.
|
|
305
|
+
* Uses subquery to verify the observation's project belongs to a repository
|
|
306
|
+
* owned by the given installation. Returns true if deleted, false if not
|
|
307
|
+
* found or not authorized.
|
|
308
|
+
*/
|
|
309
|
+
export declare function deleteMemoryObservation(db: Database, installationId: number, observationId: number): Promise<boolean>;
|
|
310
|
+
/**
|
|
311
|
+
* Clear all observations for a specific project, scoped to installation.
|
|
312
|
+
* Verifies the project belongs to a repository owned by the installation.
|
|
313
|
+
* Returns the count of deleted rows.
|
|
314
|
+
*/
|
|
315
|
+
export declare function clearMemoryObservationsByProject(db: Database, installationId: number, project: string): Promise<number>;
|
|
316
|
+
/**
|
|
317
|
+
* Clear all observations for all repos belonging to an installation.
|
|
318
|
+
* Returns the count of deleted rows.
|
|
319
|
+
*/
|
|
320
|
+
export declare function clearAllMemoryObservations(db: Database, installationId: number): Promise<number>;
|
|
321
|
+
/**
|
|
322
|
+
* Get a single observation by ID, scoped to installation.
|
|
323
|
+
* Returns the observation detail or null if not found / not authorized.
|
|
324
|
+
*/
|
|
325
|
+
export declare function getMemoryObservation(db: Database, installationId: number, observationId: number): Promise<{
|
|
326
|
+
id: number;
|
|
327
|
+
sessionId: number | null;
|
|
328
|
+
project: string;
|
|
329
|
+
type: string;
|
|
330
|
+
title: string;
|
|
331
|
+
content: string;
|
|
332
|
+
severity: string | null;
|
|
333
|
+
topicKey: string | null;
|
|
334
|
+
filePaths: string[] | null;
|
|
335
|
+
contentHash: string | null;
|
|
336
|
+
revisionCount: number;
|
|
337
|
+
createdAt: Date;
|
|
338
|
+
updatedAt: Date;
|
|
339
|
+
}>;
|
|
340
|
+
/**
|
|
341
|
+
* List observations with optional filtering, scoped to installation.
|
|
342
|
+
* Supports filtering by project, type, and pagination (limit/offset).
|
|
343
|
+
*/
|
|
344
|
+
export declare function listMemoryObservations(db: Database, installationId: number, options?: {
|
|
345
|
+
project?: string;
|
|
346
|
+
type?: string;
|
|
347
|
+
limit?: number;
|
|
348
|
+
offset?: number;
|
|
349
|
+
}): Promise<any>;
|
|
350
|
+
/**
|
|
351
|
+
* Get aggregate memory statistics for an installation.
|
|
352
|
+
* Returns total count, breakdown by type and project, oldest/newest dates.
|
|
353
|
+
*/
|
|
354
|
+
export declare function getMemoryStats(db: Database, installationId: number): Promise<{
|
|
355
|
+
totalObservations: number;
|
|
356
|
+
oldestDate: Date | null;
|
|
357
|
+
newestDate: Date | null;
|
|
358
|
+
byType: {
|
|
359
|
+
type: string;
|
|
360
|
+
count: number;
|
|
361
|
+
}[];
|
|
362
|
+
byProject: {
|
|
363
|
+
project: string;
|
|
364
|
+
count: number;
|
|
365
|
+
}[];
|
|
366
|
+
}>;
|
|
367
|
+
/**
|
|
368
|
+
* Upsert a user-installation mapping using the composite key (github_user_id, installation_id).
|
|
369
|
+
* If the combination already exists, updates github_login. Otherwise inserts a new mapping.
|
|
370
|
+
* This allows the same user to have mappings to multiple installations.
|
|
371
|
+
*/
|
|
209
372
|
export declare function upsertUserMapping(db: Database, data: {
|
|
210
373
|
githubUserId: number;
|
|
211
374
|
githubLogin: string;
|
|
@@ -217,6 +380,16 @@ export declare function upsertUserMapping(db: Database, data: {
|
|
|
217
380
|
githubUserId: number;
|
|
218
381
|
githubLogin: string;
|
|
219
382
|
}>;
|
|
383
|
+
/**
|
|
384
|
+
* Get active installations for a user by their GitHub user ID.
|
|
385
|
+
*
|
|
386
|
+
* This function joins user mappings with the installations table and
|
|
387
|
+
* filters by `is_active = true`. This means it will NOT return installations
|
|
388
|
+
* that have been deactivated (uninstalled). If a user has mappings pointing
|
|
389
|
+
* to deactivated installations, those are silently excluded from the result.
|
|
390
|
+
*
|
|
391
|
+
* To get raw mappings without the active filter, use `getRawMappingsByUserId`.
|
|
392
|
+
*/
|
|
220
393
|
export declare function getInstallationsByUserId(db: Database, githubUserId: number): Promise<{
|
|
221
394
|
id: number;
|
|
222
395
|
githubInstallationId: number;
|
|
@@ -226,4 +399,45 @@ export declare function getInstallationsByUserId(db: Database, githubUserId: num
|
|
|
226
399
|
createdAt: Date;
|
|
227
400
|
updatedAt: Date;
|
|
228
401
|
}[]>;
|
|
402
|
+
/**
|
|
403
|
+
* Get raw user mappings WITHOUT filtering by active installation.
|
|
404
|
+
* Returns all mappings for a user, including those pointing to
|
|
405
|
+
* deactivated or non-existent installations.
|
|
406
|
+
*
|
|
407
|
+
* Used by the auth middleware to detect stale mappings.
|
|
408
|
+
*/
|
|
409
|
+
export declare function getRawMappingsByUserId(db: Database, githubUserId: number): Promise<Array<{
|
|
410
|
+
id: number;
|
|
411
|
+
githubUserId: number;
|
|
412
|
+
githubLogin: string;
|
|
413
|
+
installationId: number;
|
|
414
|
+
}>>;
|
|
415
|
+
/**
|
|
416
|
+
* Delete specific user mappings by their IDs.
|
|
417
|
+
* Used to clean up stale mappings that point to deactivated installations.
|
|
418
|
+
* No-op if mappingIds is empty.
|
|
419
|
+
*/
|
|
420
|
+
export declare function deleteStaleUserMappings(db: Database, mappingIds: number[]): Promise<void>;
|
|
421
|
+
/**
|
|
422
|
+
* Delete ALL user mappings for a given installation.
|
|
423
|
+
* Used by the webhook handler when an installation is deleted/uninstalled.
|
|
424
|
+
* No-op if no mappings exist for the installation.
|
|
425
|
+
*/
|
|
426
|
+
export declare function deleteMappingsByInstallationId(db: Database, installationId: number): Promise<void>;
|
|
427
|
+
/**
|
|
428
|
+
* Delete a single memory session, scoped to installation.
|
|
429
|
+
* CASCADE will handle deleting associated observations.
|
|
430
|
+
* Returns whether a session was actually deleted.
|
|
431
|
+
*/
|
|
432
|
+
export declare function deleteMemorySession(db: Database, installationId: number, sessionId: number): Promise<{
|
|
433
|
+
deleted: boolean;
|
|
434
|
+
}>;
|
|
435
|
+
/**
|
|
436
|
+
* Delete all empty memory sessions (sessions with 0 observations).
|
|
437
|
+
* Scoped to installation, with optional project filter.
|
|
438
|
+
* Returns the count of deleted sessions.
|
|
439
|
+
*/
|
|
440
|
+
export declare function clearEmptyMemorySessions(db: Database, installationId: number, project?: string): Promise<{
|
|
441
|
+
deletedCount: number;
|
|
442
|
+
}>;
|
|
229
443
|
//# sourceMappingURL=queries.d.ts.map
|
package/dist/queries.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queries.d.ts","sourceRoot":"","sources":["../src/queries.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,
|
|
1
|
+
{"version":3,"file":"queries.d.ts","sourceRoot":"","sources":["../src/queries.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EASL,KAAK,YAAY,EACjB,KAAK,oBAAoB,EAC1B,MAAM,aAAa,CAAC;AAKrB,wBAAsB,kBAAkB,CACtC,EAAE,EAAE,QAAQ,EACZ,IAAI,EAAE;IACJ,oBAAoB,EAAE,MAAM,CAAC;IAC7B,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;CACrB;;;;;;;;GAuBF;AAED,wBAAsB,sBAAsB,CAAC,EAAE,EAAE,QAAQ,EAAE,oBAAoB,EAAE,MAAM,iBAKtF;AAED,wBAAsB,yBAAyB,CAAC,EAAE,EAAE,QAAQ,EAAE,oBAAoB,EAAE,MAAM;;;;;;;;GAQzF;AAED,wBAAsB,8BAA8B,CAAC,EAAE,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM;;;;;;;;KAUtF;AAID,wBAAsB,uBAAuB,CAAC,EAAE,EAAE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