sqlew 1.0.0 → 1.1.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/CHANGELOG.md +49 -0
- package/README.md +98 -10
- package/assets/schema.sql +104 -108
- package/dist/constants.d.ts +8 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +11 -0
- package/dist/constants.js.map +1 -1
- package/dist/database.d.ts +41 -0
- package/dist/database.d.ts.map +1 -1
- package/dist/database.js +140 -18
- package/dist/database.js.map +1 -1
- package/dist/index.js +112 -3
- package/dist/index.js.map +1 -1
- package/dist/migrations/add-table-prefixes.d.ts +29 -0
- package/dist/migrations/add-table-prefixes.d.ts.map +1 -0
- package/dist/migrations/add-table-prefixes.js +134 -0
- package/dist/migrations/add-table-prefixes.js.map +1 -0
- package/dist/schema.d.ts +1 -1
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +19 -14
- package/dist/schema.js.map +1 -1
- package/dist/tools/config.d.ts +35 -0
- package/dist/tools/config.d.ts.map +1 -0
- package/dist/tools/config.js +61 -0
- package/dist/tools/config.js.map +1 -0
- package/dist/tools/constraints.d.ts +3 -3
- package/dist/tools/constraints.js +15 -15
- package/dist/tools/constraints.js.map +1 -1
- package/dist/tools/context.d.ts +7 -7
- package/dist/tools/context.js +41 -41
- package/dist/tools/context.js.map +1 -1
- package/dist/tools/files.d.ts.map +1 -1
- package/dist/tools/files.js +13 -10
- package/dist/tools/files.js.map +1 -1
- package/dist/tools/messaging.d.ts.map +1 -1
- package/dist/tools/messaging.js +8 -5
- package/dist/tools/messaging.js.map +1 -1
- package/dist/tools/utils.d.ts +5 -2
- package/dist/tools/utils.d.ts.map +1 -1
- package/dist/tools/utils.js +48 -35
- package/dist/tools/utils.js.map +1 -1
- package/dist/utils/cleanup.d.ts +45 -0
- package/dist/utils/cleanup.d.ts.map +1 -0
- package/dist/utils/cleanup.js +63 -0
- package/dist/utils/cleanup.js.map +1 -0
- package/dist/utils/retention.d.ts +47 -0
- package/dist/utils/retention.d.ts.map +1 -0
- package/dist/utils/retention.js +125 -0
- package/dist/utils/retention.js.map +1 -0
- package/package.json +2 -2
package/dist/tools/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/tools/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/tools/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAS1D,OAAO,EAAE,sBAAsB,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AAC1F,OAAO,EAAE,0BAA0B,EAAE,MAAM,qBAAqB,CAAC;AAEjE;;;;;GAKG;AACH,MAAM,UAAU,eAAe;IAC7B,MAAM,EAAE,GAAG,WAAW,EAAE,CAAC;IAEzB,IAAI,CAAC;QACH,gDAAgD;QAChD,MAAM,IAAI,GAAG,EAAE,CAAC,OAAO,CAAC;;;;;;;;KAQvB,CAAC,CAAC;QAEH,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,EAAoB,CAAC;QAE7C,OAAO;YACL,OAAO;SACR,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACvE,MAAM,IAAI,KAAK,CAAC,gCAAgC,OAAO,EAAE,CAAC,CAAC;IAC7D,CAAC;AACH,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,YAAY,CAAC,MAA2B;IACtD,MAAM,EAAE,GAAG,WAAW,EAAE,CAAC;IAEzB,IAAI,CAA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AAC;QAE9C,eAAe;QACf,MAAM,YAAY,GAAG,QAAQ,CAAC,gBAAgB,CAAC,CAAC;QAEhD,gCAAgC;QAChC,MAAM,kBAAkB,GAAG,QAAQ,CAAC,eAAe,EAAE,YAAY,CAAC,CAAC;QACnE,MAAM,iBAAiB,GAAG,QAAQ,CAAC,eAAe,CAAC,CAAC;QAEpD,WAAW;QACX,MAAM,IAAI,GAAG,QAAQ,CAAC,QAAQ,CAAC,CAAC;QAChC,MAAM,MAAM,GAAG,QAAQ,CAAC,UAAU,CAAC,CAAC;QACpC,MAAM,MAAM,GAAG,QAAQ,CAAC,UAAU,CAAC,CAAC;QAEpC,OAAO;YACL,MAAM;YACN,KAAK;YACL,YAAY;YACZ,gBAAgB;YAChB,eAAe;YACf,QAAQ;YACR,YAAY;YACZ,kBAAkB;YAClB,iBAAiB;YACjB,IAAI;YACJ,MAAM;YACN,MAAM;SACP,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACvE,MAAM,IAAI,KAAK,CAAC,sCAAsC,OAAO,EAAE,CAAC,CAAC;IACnE,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Programmatic cleanup utilities for old messages and file changes
|
|
3
|
+
* Replaces the automatic triggers with weekend-aware logic
|
|
4
|
+
*/
|
|
5
|
+
import { Database } from '../types.js';
|
|
6
|
+
/**
|
|
7
|
+
* Perform automatic cleanup of old data
|
|
8
|
+
* Deletes old messages and file changes based on m_config settings
|
|
9
|
+
*
|
|
10
|
+
* @param db - Database instance
|
|
11
|
+
* @returns Object with counts of deleted records
|
|
12
|
+
*/
|
|
13
|
+
export declare function performAutoCleanup(db: Database): {
|
|
14
|
+
messagesDeleted: number;
|
|
15
|
+
fileChangesDeleted: number;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Delete old messages before the cutoff timestamp
|
|
19
|
+
*
|
|
20
|
+
* @param db - Database instance
|
|
21
|
+
* @param cutoffTimestamp - Unix timestamp (seconds) for cutoff
|
|
22
|
+
* @returns Number of messages deleted
|
|
23
|
+
*/
|
|
24
|
+
export declare function cleanupMessages(db: Database, cutoffTimestamp: number): number;
|
|
25
|
+
/**
|
|
26
|
+
* Delete old file changes before the cutoff timestamp
|
|
27
|
+
*
|
|
28
|
+
* @param db - Database instance
|
|
29
|
+
* @param cutoffTimestamp - Unix timestamp (seconds) for cutoff
|
|
30
|
+
* @returns Number of file changes deleted
|
|
31
|
+
*/
|
|
32
|
+
export declare function cleanupFileChanges(db: Database, cutoffTimestamp: number): number;
|
|
33
|
+
/**
|
|
34
|
+
* Cleanup with custom retention periods (overrides config)
|
|
35
|
+
*
|
|
36
|
+
* @param db - Database instance
|
|
37
|
+
* @param messageHours - Message retention in hours (optional)
|
|
38
|
+
* @param fileChangeDays - File change retention in days (optional)
|
|
39
|
+
* @returns Object with counts of deleted records
|
|
40
|
+
*/
|
|
41
|
+
export declare function cleanupWithCustomRetention(db: Database, messageHours?: number, fileChangeDays?: number): {
|
|
42
|
+
messagesDeleted: number;
|
|
43
|
+
fileChangesDeleted: number;
|
|
44
|
+
};
|
|
45
|
+
//# sourceMappingURL=cleanup.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cleanup.d.ts","sourceRoot":"","sources":["../../src/utils/cleanup.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAGvC;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,QAAQ,GAAG;IAAE,eAAe,EAAE,MAAM,CAAC;IAAC,kBAAkB,EAAE,MAAM,CAAA;CAAE,CAQxG;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,EAAE,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,GAAG,MAAM,CAG7E;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,GAAG,MAAM,CAGhF;AAED;;;;;;;GAOG;AACH,wBAAgB,0BAA0B,CACxC,EAAE,EAAE,QAAQ,EACZ,YAAY,CAAC,EAAE,MAAM,EACrB,cAAc,CAAC,EAAE,MAAM,GACtB;IAAE,eAAe,EAAE,MAAM,CAAC;IAAC,kBAAkB,EAAE,MAAM,CAAA;CAAE,CAezD"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Programmatic cleanup utilities for old messages and file changes
|
|
3
|
+
* Replaces the automatic triggers with weekend-aware logic
|
|
4
|
+
*/
|
|
5
|
+
import { calculateMessageCutoff, calculateFileChangeCutoff } from './retention.js';
|
|
6
|
+
/**
|
|
7
|
+
* Perform automatic cleanup of old data
|
|
8
|
+
* Deletes old messages and file changes based on m_config settings
|
|
9
|
+
*
|
|
10
|
+
* @param db - Database instance
|
|
11
|
+
* @returns Object with counts of deleted records
|
|
12
|
+
*/
|
|
13
|
+
export function performAutoCleanup(db) {
|
|
14
|
+
const messageCutoff = calculateMessageCutoff(db);
|
|
15
|
+
const fileChangeCutoff = calculateFileChangeCutoff(db);
|
|
16
|
+
const messagesDeleted = cleanupMessages(db, messageCutoff);
|
|
17
|
+
const fileChangesDeleted = cleanupFileChanges(db, fileChangeCutoff);
|
|
18
|
+
return { messagesDeleted, fileChangesDeleted };
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Delete old messages before the cutoff timestamp
|
|
22
|
+
*
|
|
23
|
+
* @param db - Database instance
|
|
24
|
+
* @param cutoffTimestamp - Unix timestamp (seconds) for cutoff
|
|
25
|
+
* @returns Number of messages deleted
|
|
26
|
+
*/
|
|
27
|
+
export function cleanupMessages(db, cutoffTimestamp) {
|
|
28
|
+
const result = db.prepare('DELETE FROM t_agent_messages WHERE ts < ?').run(cutoffTimestamp);
|
|
29
|
+
return result.changes;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Delete old file changes before the cutoff timestamp
|
|
33
|
+
*
|
|
34
|
+
* @param db - Database instance
|
|
35
|
+
* @param cutoffTimestamp - Unix timestamp (seconds) for cutoff
|
|
36
|
+
* @returns Number of file changes deleted
|
|
37
|
+
*/
|
|
38
|
+
export function cleanupFileChanges(db, cutoffTimestamp) {
|
|
39
|
+
const result = db.prepare('DELETE FROM t_file_changes WHERE ts < ?').run(cutoffTimestamp);
|
|
40
|
+
return result.changes;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Cleanup with custom retention periods (overrides config)
|
|
44
|
+
*
|
|
45
|
+
* @param db - Database instance
|
|
46
|
+
* @param messageHours - Message retention in hours (optional)
|
|
47
|
+
* @param fileChangeDays - File change retention in days (optional)
|
|
48
|
+
* @returns Object with counts of deleted records
|
|
49
|
+
*/
|
|
50
|
+
export function cleanupWithCustomRetention(db, messageHours, fileChangeDays) {
|
|
51
|
+
let messagesDeleted = 0;
|
|
52
|
+
let fileChangesDeleted = 0;
|
|
53
|
+
if (messageHours !== undefined) {
|
|
54
|
+
const messageCutoff = Math.floor(Date.now() / 1000) - (messageHours * 3600);
|
|
55
|
+
messagesDeleted = cleanupMessages(db, messageCutoff);
|
|
56
|
+
}
|
|
57
|
+
if (fileChangeDays !== undefined) {
|
|
58
|
+
const fileChangeCutoff = Math.floor(Date.now() / 1000) - (fileChangeDays * 86400);
|
|
59
|
+
fileChangesDeleted = cleanupFileChanges(db, fileChangeCutoff);
|
|
60
|
+
}
|
|
61
|
+
return { messagesDeleted, fileChangesDeleted };
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=cleanup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cleanup.js","sourceRoot":"","sources":["../../src/utils/cleanup.ts"],"names":[],"mappings":"AAAA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GAAG,eAAe,CAAC,EAAE,EAAE,aAAa,CAAC,CAAC;IACvD,CAAC;IAED,IAAI,cAAc,KAAK,SAAS,EAAE,CAAC;QACjC,MAAM,gBAAgB,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,cAAc,GAAG,KAAK,CAAC,CAAC;QAClF,kBAAkB,GAAG,kBAAkB,CAAC,EAAE,EAAE,gBAAgB,CAAC,CAAC;IAChE,CAAC;IAED,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,CAAC;AACjD,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Weekend-aware retention logic for auto-deletion
|
|
3
|
+
* Calculates cutoff timestamps that skip weekends when configured
|
|
4
|
+
*/
|
|
5
|
+
import { Database } from '../types.js';
|
|
6
|
+
/**
|
|
7
|
+
* Calculate cutoff timestamp for message retention
|
|
8
|
+
* Respects weekend-awareness configuration
|
|
9
|
+
*
|
|
10
|
+
* @param db - Database instance
|
|
11
|
+
* @returns Unix timestamp (seconds) for cutoff
|
|
12
|
+
*/
|
|
13
|
+
export declare function calculateMessageCutoff(db: Database): number;
|
|
14
|
+
/**
|
|
15
|
+
* Calculate cutoff timestamp for file change retention
|
|
16
|
+
* Respects weekend-awareness configuration
|
|
17
|
+
*
|
|
18
|
+
* @param db - Database instance
|
|
19
|
+
* @returns Unix timestamp (seconds) for cutoff
|
|
20
|
+
*/
|
|
21
|
+
export declare function calculateFileChangeCutoff(db: Database): number;
|
|
22
|
+
/**
|
|
23
|
+
* Calculate cutoff timestamp with optional weekend-awareness
|
|
24
|
+
*
|
|
25
|
+
* @param retention - Retention period (hours or days)
|
|
26
|
+
* @param ignoreWeekends - Whether to skip weekends in calculation
|
|
27
|
+
* @param unit - Time unit ('hours' or 'days')
|
|
28
|
+
* @returns Unix timestamp (seconds) for cutoff
|
|
29
|
+
*/
|
|
30
|
+
export declare function calculateCutoffTimestamp(retention: number, ignoreWeekends: boolean, unit: 'hours' | 'days'): number;
|
|
31
|
+
/**
|
|
32
|
+
* Count the number of weekend days between two dates (inclusive)
|
|
33
|
+
*
|
|
34
|
+
* @param startDate - Start date
|
|
35
|
+
* @param endDate - End date
|
|
36
|
+
* @returns Number of weekend days (Saturdays and Sundays)
|
|
37
|
+
*/
|
|
38
|
+
export declare function countWeekendDays(startDate: Date, endDate: Date): number;
|
|
39
|
+
/**
|
|
40
|
+
* Add business days to a date (skipping weekends)
|
|
41
|
+
*
|
|
42
|
+
* @param date - Starting date
|
|
43
|
+
* @param days - Number of business days to add
|
|
44
|
+
* @returns New date with business days added
|
|
45
|
+
*/
|
|
46
|
+
export declare function addBusinessDays(date: Date, days: number): Date;
|
|
47
|
+
//# sourceMappingURL=retention.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retention.d.ts","sourceRoot":"","sources":["../../src/utils/retention.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAIvC;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,EAAE,EAAE,QAAQ,GAAG,MAAM,CAK3D;AAED;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CAAC,EAAE,EAAE,QAAQ,GAAG,MAAM,CAK9D;AAED;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CACtC,SAAS,EAAE,MAAM,EACjB,cAAc,EAAE,OAAO,EACvB,IAAI,EAAE,OAAO,GAAG,MAAM,GACrB,MAAM,CAYR;AA4CD;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,GAAG,MAAM,CAavE;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAe9D"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Weekend-aware retention logic for auto-deletion
|
|
3
|
+
* Calculates cutoff timestamps that skip weekends when configured
|
|
4
|
+
*/
|
|
5
|
+
import { getConfigBool, getConfigInt } from '../database.js';
|
|
6
|
+
import { CONFIG_KEYS } from '../constants.js';
|
|
7
|
+
/**
|
|
8
|
+
* Calculate cutoff timestamp for message retention
|
|
9
|
+
* Respects weekend-awareness configuration
|
|
10
|
+
*
|
|
11
|
+
* @param db - Database instance
|
|
12
|
+
* @returns Unix timestamp (seconds) for cutoff
|
|
13
|
+
*/
|
|
14
|
+
export function calculateMessageCutoff(db) {
|
|
15
|
+
const ignoreWeekends = getConfigBool(db, CONFIG_KEYS.AUTODELETE_IGNORE_WEEKEND, false);
|
|
16
|
+
const retentionHours = getConfigInt(db, CONFIG_KEYS.AUTODELETE_MESSAGE_HOURS, 24);
|
|
17
|
+
return calculateCutoffTimestamp(retentionHours, ignoreWeekends, 'hours');
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Calculate cutoff timestamp for file change retention
|
|
21
|
+
* Respects weekend-awareness configuration
|
|
22
|
+
*
|
|
23
|
+
* @param db - Database instance
|
|
24
|
+
* @returns Unix timestamp (seconds) for cutoff
|
|
25
|
+
*/
|
|
26
|
+
export function calculateFileChangeCutoff(db) {
|
|
27
|
+
const ignoreWeekends = getConfigBool(db, CONFIG_KEYS.AUTODELETE_IGNORE_WEEKEND, false);
|
|
28
|
+
const retentionDays = getConfigInt(db, CONFIG_KEYS.AUTODELETE_FILE_HISTORY_DAYS, 7);
|
|
29
|
+
return calculateCutoffTimestamp(retentionDays, ignoreWeekends, 'days');
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Calculate cutoff timestamp with optional weekend-awareness
|
|
33
|
+
*
|
|
34
|
+
* @param retention - Retention period (hours or days)
|
|
35
|
+
* @param ignoreWeekends - Whether to skip weekends in calculation
|
|
36
|
+
* @param unit - Time unit ('hours' or 'days')
|
|
37
|
+
* @returns Unix timestamp (seconds) for cutoff
|
|
38
|
+
*/
|
|
39
|
+
export function calculateCutoffTimestamp(retention, ignoreWeekends, unit) {
|
|
40
|
+
const now = new Date();
|
|
41
|
+
if (!ignoreWeekends) {
|
|
42
|
+
// Simple calculation: just subtract the retention period
|
|
43
|
+
const milliseconds = unit === 'hours' ? retention * 60 * 60 * 1000 : retention * 24 * 60 * 60 * 1000;
|
|
44
|
+
return Math.floor((now.getTime() - milliseconds) / 1000);
|
|
45
|
+
}
|
|
46
|
+
// Weekend-aware calculation
|
|
47
|
+
const targetDate = subtractBusinessTime(now, retention, unit);
|
|
48
|
+
return Math.floor(targetDate.getTime() / 1000);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Subtract business time (skipping weekends) from a date
|
|
52
|
+
*
|
|
53
|
+
* @param date - Starting date
|
|
54
|
+
* @param amount - Amount to subtract
|
|
55
|
+
* @param unit - Time unit ('hours' or 'days')
|
|
56
|
+
* @returns New date with business time subtracted
|
|
57
|
+
*/
|
|
58
|
+
function subtractBusinessTime(date, amount, unit) {
|
|
59
|
+
const result = new Date(date);
|
|
60
|
+
if (unit === 'days') {
|
|
61
|
+
// Subtract days, skipping weekends
|
|
62
|
+
let daysToSubtract = amount;
|
|
63
|
+
while (daysToSubtract > 0) {
|
|
64
|
+
result.setDate(result.getDate() - 1);
|
|
65
|
+
// Only count weekdays (Monday=1, Sunday=0)
|
|
66
|
+
const dayOfWeek = result.getDay();
|
|
67
|
+
if (dayOfWeek !== 0 && dayOfWeek !== 6) {
|
|
68
|
+
daysToSubtract--;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
// Subtract hours, skipping weekends
|
|
74
|
+
let hoursToSubtract = amount;
|
|
75
|
+
while (hoursToSubtract > 0) {
|
|
76
|
+
result.setHours(result.getHours() - 1);
|
|
77
|
+
// Only count weekday hours (Monday=1, Sunday=0)
|
|
78
|
+
const dayOfWeek = result.getDay();
|
|
79
|
+
if (dayOfWeek !== 0 && dayOfWeek !== 6) {
|
|
80
|
+
hoursToSubtract--;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return result;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Count the number of weekend days between two dates (inclusive)
|
|
88
|
+
*
|
|
89
|
+
* @param startDate - Start date
|
|
90
|
+
* @param endDate - End date
|
|
91
|
+
* @returns Number of weekend days (Saturdays and Sundays)
|
|
92
|
+
*/
|
|
93
|
+
export function countWeekendDays(startDate, endDate) {
|
|
94
|
+
let count = 0;
|
|
95
|
+
const current = new Date(startDate);
|
|
96
|
+
while (current <= endDate) {
|
|
97
|
+
const dayOfWeek = current.getDay();
|
|
98
|
+
if (dayOfWeek === 0 || dayOfWeek === 6) {
|
|
99
|
+
count++;
|
|
100
|
+
}
|
|
101
|
+
current.setDate(current.getDate() + 1);
|
|
102
|
+
}
|
|
103
|
+
return count;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Add business days to a date (skipping weekends)
|
|
107
|
+
*
|
|
108
|
+
* @param date - Starting date
|
|
109
|
+
* @param days - Number of business days to add
|
|
110
|
+
* @returns New date with business days added
|
|
111
|
+
*/
|
|
112
|
+
export function addBusinessDays(date, days) {
|
|
113
|
+
const result = new Date(date);
|
|
114
|
+
let daysToAdd = days;
|
|
115
|
+
while (daysToAdd > 0) {
|
|
116
|
+
result.setDate(result.getDate() + 1);
|
|
117
|
+
// Only count weekdays (Monday=1, Sunday=0)
|
|
118
|
+
const dayOfWeek = result.getDay();
|
|
119
|
+
if (dayOfWeek !== 0 && dayOfWeek !== 6) {
|
|
120
|
+
daysToAdd--;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return result;
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=retention.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retention.js","sourceRoot":"","sources":["../../src/utils/retention.ts"],"names":[],"m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AAC,SAAe,EAAE,OAAa;IAC7D,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,MAAM,OAAO,GAAG,IAAI,IAAI,CAAC,SAAS,CAAC,CAAC;IAEpC,OAAO,OAAO,IAAI,OAAO,EAAE,CAAC;QAC1B,MAAM,SAAS,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;QACnC,IAAI,SAAS,KAAK,CAAC,IAAI,SAAS,KAAK,CAAC,EAAE,CAAC;YACvC,KAAK,EAAE,CAAC;QACV,CAAC;QACD,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC;IACzC,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,eAAe,CAAC,IAAU,EAAE,IAAY;IACtD,MAAM,MAAM,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC;IAC9B,IAAI,SAAS,GAAG,IAAI,CAAC;IAErB,OAAO,SAAS,GAAG,CAAC,EAAE,CAAC;QACrB,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC;QAErC,2CAA2C;QAC3C,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC;QAClC,IAAI,SAAS,KAAK,CAAC,IAAI,SAAS,KAAK,CAAC,EAAE,CAAC;YACvC,SAAS,EAAE,CAAC;QACd,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sqlew",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "MCP server for efficient context sharing between Claude Code sub-agents with 72% token reduction",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"bin": {
|
|
8
|
-
"sqlew": "
|
|
8
|
+
"sqlew": "dist/index.js"
|
|
9
9
|
},
|
|
10
10
|
"files": [
|
|
11
11
|
"dist/",
|