@firela/billclaw-core 0.1.3
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/LICENSE +21 -0
- package/README.md +109 -0
- package/dist/billclaw.d.ts +76 -0
- package/dist/billclaw.d.ts.map +1 -0
- package/dist/billclaw.js +205 -0
- package/dist/billclaw.js.map +1 -0
- package/dist/credentials/index.d.ts +8 -0
- package/dist/credentials/index.d.ts.map +1 -0
- package/dist/credentials/index.js +8 -0
- package/dist/credentials/index.js.map +1 -0
- package/dist/credentials/keychain.d.ts +92 -0
- package/dist/credentials/keychain.d.ts.map +1 -0
- package/dist/credentials/keychain.js +172 -0
- package/dist/credentials/keychain.js.map +1 -0
- package/dist/credentials/store.d.ts +76 -0
- package/dist/credentials/store.d.ts.map +1 -0
- package/dist/credentials/store.js +144 -0
- package/dist/credentials/store.js.map +1 -0
- package/dist/errors/errors.d.ts +92 -0
- package/dist/errors/errors.d.ts.map +1 -0
- package/dist/errors/errors.js +315 -0
- package/dist/errors/errors.js.map +1 -0
- package/dist/errors/index.d.ts +7 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +7 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/exporters/beancount.d.ts +42 -0
- package/dist/exporters/beancount.d.ts.map +1 -0
- package/dist/exporters/beancount.js +141 -0
- package/dist/exporters/beancount.js.map +1 -0
- package/dist/exporters/index.d.ts +8 -0
- package/dist/exporters/index.d.ts.map +1 -0
- package/dist/exporters/index.js +8 -0
- package/dist/exporters/index.js.map +1 -0
- package/dist/exporters/ledger.d.ts +42 -0
- package/dist/exporters/ledger.d.ts.map +1 -0
- package/dist/exporters/ledger.js +139 -0
- package/dist/exporters/ledger.js.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +34 -0
- package/dist/index.js.map +1 -0
- package/dist/models/config.d.ts +552 -0
- package/dist/models/config.d.ts.map +1 -0
- package/dist/models/config.js +168 -0
- package/dist/models/config.js.map +1 -0
- package/dist/models/index.d.ts +7 -0
- package/dist/models/index.d.ts.map +1 -0
- package/dist/models/index.js +8 -0
- package/dist/models/index.js.map +1 -0
- package/dist/runtime/index.d.ts +7 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +7 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/runtime/types.d.ts +110 -0
- package/dist/runtime/types.d.ts.map +1 -0
- package/dist/runtime/types.js +85 -0
- package/dist/runtime/types.js.map +1 -0
- package/dist/security/audit.d.ts +148 -0
- package/dist/security/audit.d.ts.map +1 -0
- package/dist/security/audit.js +286 -0
- package/dist/security/audit.js.map +1 -0
- package/dist/security/index.d.ts +7 -0
- package/dist/security/index.d.ts.map +1 -0
- package/dist/security/index.js +7 -0
- package/dist/security/index.js.map +1 -0
- package/dist/services/event-emitter.d.ts +171 -0
- package/dist/services/event-emitter.d.ts.map +1 -0
- package/dist/services/event-emitter.js +287 -0
- package/dist/services/event-emitter.js.map +1 -0
- package/dist/services/index.d.ts +8 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +8 -0
- package/dist/services/index.js.map +1 -0
- package/dist/sources/gmail/bill-recognizer.d.ts +71 -0
- package/dist/sources/gmail/bill-recognizer.d.ts.map +1 -0
- package/dist/sources/gmail/bill-recognizer.js +341 -0
- package/dist/sources/gmail/bill-recognizer.js.map +1 -0
- package/dist/sources/gmail/email-parser.d.ts +68 -0
- package/dist/sources/gmail/email-parser.d.ts.map +1 -0
- package/dist/sources/gmail/email-parser.js +238 -0
- package/dist/sources/gmail/email-parser.js.map +1 -0
- package/dist/sources/gmail/gmail-fetch.d.ts +54 -0
- package/dist/sources/gmail/gmail-fetch.d.ts.map +1 -0
- package/dist/sources/gmail/gmail-fetch.js +300 -0
- package/dist/sources/gmail/gmail-fetch.js.map +1 -0
- package/dist/sources/gmail/index.d.ts +7 -0
- package/dist/sources/gmail/index.d.ts.map +1 -0
- package/dist/sources/gmail/index.js +7 -0
- package/dist/sources/gmail/index.js.map +1 -0
- package/dist/sources/index.d.ts +8 -0
- package/dist/sources/index.d.ts.map +1 -0
- package/dist/sources/index.js +8 -0
- package/dist/sources/index.js.map +1 -0
- package/dist/sources/plaid/index.d.ts +7 -0
- package/dist/sources/plaid/index.d.ts.map +1 -0
- package/dist/sources/plaid/index.js +7 -0
- package/dist/sources/plaid/index.js.map +1 -0
- package/dist/sources/plaid/plaid-sync.d.ts +42 -0
- package/dist/sources/plaid/plaid-sync.d.ts.map +1 -0
- package/dist/sources/plaid/plaid-sync.js +182 -0
- package/dist/sources/plaid/plaid-sync.js.map +1 -0
- package/dist/storage/cache.d.ts +134 -0
- package/dist/storage/cache.d.ts.map +1 -0
- package/dist/storage/cache.js +239 -0
- package/dist/storage/cache.js.map +1 -0
- package/dist/storage/index.d.ts +11 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/index.js +11 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/storage/indexes.d.ts +136 -0
- package/dist/storage/indexes.d.ts.map +1 -0
- package/dist/storage/indexes.js +294 -0
- package/dist/storage/indexes.js.map +1 -0
- package/dist/storage/locking.d.ts +103 -0
- package/dist/storage/locking.d.ts.map +1 -0
- package/dist/storage/locking.js +158 -0
- package/dist/storage/locking.js.map +1 -0
- package/dist/storage/streaming.d.ts +102 -0
- package/dist/storage/streaming.d.ts.map +1 -0
- package/dist/storage/streaming.js +245 -0
- package/dist/storage/streaming.js.map +1 -0
- package/dist/storage/transaction-storage.d.ts +101 -0
- package/dist/storage/transaction-storage.d.ts.map +1 -0
- package/dist/storage/transaction-storage.js +193 -0
- package/dist/storage/transaction-storage.js.map +1 -0
- package/dist/sync/index.d.ts +7 -0
- package/dist/sync/index.d.ts.map +1 -0
- package/dist/sync/index.js +7 -0
- package/dist/sync/index.js.map +1 -0
- package/dist/sync/sync-service.d.ts +42 -0
- package/dist/sync/sync-service.d.ts.map +1 -0
- package/dist/sync/sync-service.js +112 -0
- package/dist/sync/sync-service.js.map +1 -0
- package/dist/test-fixtures.d.ts +38 -0
- package/dist/test-fixtures.d.ts.map +1 -0
- package/dist/test-fixtures.js +137 -0
- package/dist/test-fixtures.js.map +1 -0
- package/package.json +68 -0
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Query indexes for BillClaw
|
|
3
|
+
*
|
|
4
|
+
* Provides in-memory indexes for common query patterns:
|
|
5
|
+
* - Date-based queries (transactions by date range)
|
|
6
|
+
* - Category-based queries
|
|
7
|
+
* - Merchant-based queries
|
|
8
|
+
* - Amount-based queries
|
|
9
|
+
*
|
|
10
|
+
* Indexes improve query performance from O(n) to O(log n) or O(1).
|
|
11
|
+
*/
|
|
12
|
+
import type { Transaction } from "./transaction-storage.js";
|
|
13
|
+
import type { Logger } from "../errors/errors.js";
|
|
14
|
+
/**
|
|
15
|
+
* Index configuration
|
|
16
|
+
*/
|
|
17
|
+
export interface IndexConfig {
|
|
18
|
+
rebuildThreshold?: number;
|
|
19
|
+
logger?: Logger;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Transaction indexes
|
|
23
|
+
*/
|
|
24
|
+
export declare class TransactionIndexes {
|
|
25
|
+
private indexes;
|
|
26
|
+
private config;
|
|
27
|
+
constructor(config?: IndexConfig);
|
|
28
|
+
/**
|
|
29
|
+
* Build indexes for a set of transactions
|
|
30
|
+
*
|
|
31
|
+
* @param transactions - Transactions to index
|
|
32
|
+
* @param indexType - Type of index to build
|
|
33
|
+
*/
|
|
34
|
+
buildIndex(transactions: Transaction[], indexType: IndexType): void;
|
|
35
|
+
/**
|
|
36
|
+
* Get the index key for a transaction
|
|
37
|
+
*/
|
|
38
|
+
private getIndexKey;
|
|
39
|
+
/**
|
|
40
|
+
* Query transactions by index key
|
|
41
|
+
*
|
|
42
|
+
* @param indexType - Type of index to query
|
|
43
|
+
* @param _key - Key to look up (not used in simplified implementation)
|
|
44
|
+
* @returns Set of transaction IDs matching the key
|
|
45
|
+
*/
|
|
46
|
+
query(indexType: IndexType, _key: string): Set<string>;
|
|
47
|
+
/**
|
|
48
|
+
* Clear all indexes
|
|
49
|
+
*/
|
|
50
|
+
clear(): void;
|
|
51
|
+
/**
|
|
52
|
+
* Get index statistics
|
|
53
|
+
*/
|
|
54
|
+
getStats(): Record<string, number>;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Index types
|
|
58
|
+
*/
|
|
59
|
+
export declare enum IndexType {
|
|
60
|
+
/** Index by transaction date */
|
|
61
|
+
DATE = "date",
|
|
62
|
+
/** Index by primary category */
|
|
63
|
+
CATEGORY = "category",
|
|
64
|
+
/** Index by merchant name */
|
|
65
|
+
MERCHANT = "merchant",
|
|
66
|
+
/** Index by amount range (buckets) */
|
|
67
|
+
AMOUNT_RANGE = "amount_range",
|
|
68
|
+
/** Index by pending status */
|
|
69
|
+
PENDING = "pending"
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Query builder for filtering transactions
|
|
73
|
+
*/
|
|
74
|
+
export declare class TransactionQueryBuilder {
|
|
75
|
+
private filters;
|
|
76
|
+
/**
|
|
77
|
+
* Filter by date range
|
|
78
|
+
*/
|
|
79
|
+
dateRange(start: Date, end: Date): this;
|
|
80
|
+
/**
|
|
81
|
+
* Filter by category
|
|
82
|
+
*/
|
|
83
|
+
category(category: string): this;
|
|
84
|
+
/**
|
|
85
|
+
* Filter by merchant name (partial match)
|
|
86
|
+
*/
|
|
87
|
+
merchant(merchant: string): this;
|
|
88
|
+
/**
|
|
89
|
+
* Filter by amount range (in cents)
|
|
90
|
+
*/
|
|
91
|
+
amountRange(min: number, max: number): this;
|
|
92
|
+
/**
|
|
93
|
+
* Filter by pending status
|
|
94
|
+
*/
|
|
95
|
+
pending(isPending: boolean): this;
|
|
96
|
+
/**
|
|
97
|
+
* Apply all filters to a set of transactions
|
|
98
|
+
*/
|
|
99
|
+
apply(transactions: Transaction[]): Transaction[];
|
|
100
|
+
/**
|
|
101
|
+
* Clear all filters
|
|
102
|
+
*/
|
|
103
|
+
clear(): this;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Inverted index for full-text search
|
|
107
|
+
*/
|
|
108
|
+
export declare class FullTextIndex {
|
|
109
|
+
private index;
|
|
110
|
+
private transactionData;
|
|
111
|
+
/**
|
|
112
|
+
* Add a transaction to the index
|
|
113
|
+
*/
|
|
114
|
+
add(transaction: Transaction): void;
|
|
115
|
+
/**
|
|
116
|
+
* Index a document
|
|
117
|
+
*/
|
|
118
|
+
private indexDocument;
|
|
119
|
+
/**
|
|
120
|
+
* Search for transactions matching a query
|
|
121
|
+
*/
|
|
122
|
+
search(query: string): Transaction[];
|
|
123
|
+
/**
|
|
124
|
+
* Clear the index
|
|
125
|
+
*/
|
|
126
|
+
clear(): void;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Create a query builder
|
|
130
|
+
*/
|
|
131
|
+
export declare function createQueryBuilder(): TransactionQueryBuilder;
|
|
132
|
+
/**
|
|
133
|
+
* Create a full-text index
|
|
134
|
+
*/
|
|
135
|
+
export declare function createFullTextIndex(): FullTextIndex;
|
|
136
|
+
//# sourceMappingURL=indexes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"indexes.d.ts","sourceRoot":"","sources":["../../src/storage/indexes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AAC3D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAWjD;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAeD;;GAEG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,OAAO,CAAgC;IAC/C,OAAO,CAAC,MAAM,CAAuB;gBAEzB,MAAM,GAAE,WAAgB;IAQ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AAW,GAAG,IAAI;IAcnC;;OAEG;IACH,OAAO,CAAC,aAAa;IAcrB;;OAEG;IACH,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW,EAAE;IAoDpC;;OAEG;IACH,KAAK,IAAI,IAAI;CAId;AAED;;GAEG;AACH,wBAAgB,kBAAkB,IAAI,uBAAuB,CAE5D;AAED;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,aAAa,CAEnD"}
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Query indexes for BillClaw
|
|
3
|
+
*
|
|
4
|
+
* Provides in-memory indexes for common query patterns:
|
|
5
|
+
* - Date-based queries (transactions by date range)
|
|
6
|
+
* - Category-based queries
|
|
7
|
+
* - Merchant-based queries
|
|
8
|
+
* - Amount-based queries
|
|
9
|
+
*
|
|
10
|
+
* Indexes improve query performance from O(n) to O(log n) or O(1).
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Default index configuration
|
|
14
|
+
*/
|
|
15
|
+
const DEFAULT_INDEX_CONFIG = {
|
|
16
|
+
rebuildThreshold: 0.1, // 10% change threshold
|
|
17
|
+
logger: {
|
|
18
|
+
info: () => { },
|
|
19
|
+
error: () => { },
|
|
20
|
+
warn: () => { },
|
|
21
|
+
debug: () => { },
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Transaction indexes
|
|
26
|
+
*/
|
|
27
|
+
export class TransactionIndexes {
|
|
28
|
+
indexes = new Map();
|
|
29
|
+
config;
|
|
30
|
+
constructor(config = {}) {
|
|
31
|
+
this.config = {
|
|
32
|
+
rebuildThreshold: config.rebuildThreshold ?? DEFAULT_INDEX_CONFIG.rebuildThreshold,
|
|
33
|
+
logger: config.logger ?? DEFAULT_INDEX_CONFIG.logger,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Build indexes for a set of transactions
|
|
38
|
+
*
|
|
39
|
+
* @param transactions - Transactions to index
|
|
40
|
+
* @param indexType - Type of index to build
|
|
41
|
+
*/
|
|
42
|
+
buildIndex(transactions, indexType) {
|
|
43
|
+
const index = {
|
|
44
|
+
key: indexType,
|
|
45
|
+
transactionIds: new Set(),
|
|
46
|
+
updatedAt: Date.now(),
|
|
47
|
+
};
|
|
48
|
+
for (const txn of transactions) {
|
|
49
|
+
const key = this.getIndexKey(txn, indexType);
|
|
50
|
+
if (key) {
|
|
51
|
+
index.transactionIds.add(txn.transactionId);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
this.indexes.set(indexType, index);
|
|
55
|
+
this.config.logger?.debug?.(`Built index: ${indexType} (${index.transactionIds.size} entries)`);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Get the index key for a transaction
|
|
59
|
+
*/
|
|
60
|
+
getIndexKey(transaction, indexType) {
|
|
61
|
+
switch (indexType) {
|
|
62
|
+
case IndexType.DATE:
|
|
63
|
+
return transaction.date;
|
|
64
|
+
case IndexType.CATEGORY:
|
|
65
|
+
return transaction.category?.[0] || "uncategorized";
|
|
66
|
+
case IndexType.MERCHANT:
|
|
67
|
+
return transaction.merchantName || "unknown";
|
|
68
|
+
case IndexType.AMOUNT_RANGE:
|
|
69
|
+
// Bucket amounts into ranges
|
|
70
|
+
const amount = Math.abs(transaction.amount);
|
|
71
|
+
if (amount < 1000)
|
|
72
|
+
return "0-10"; // <$10
|
|
73
|
+
if (amount < 5000)
|
|
74
|
+
return "10-50"; // $10-$50
|
|
75
|
+
if (amount < 10000)
|
|
76
|
+
return "50-100"; // $50-$100
|
|
77
|
+
if (amount < 50000)
|
|
78
|
+
return "100-500"; // $100-$500
|
|
79
|
+
return "500+"; // >$500
|
|
80
|
+
case IndexType.PENDING:
|
|
81
|
+
return transaction.pending ? "pending" : "posted";
|
|
82
|
+
default:
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Query transactions by index key
|
|
88
|
+
*
|
|
89
|
+
* @param indexType - Type of index to query
|
|
90
|
+
* @param _key - Key to look up (not used in simplified implementation)
|
|
91
|
+
* @returns Set of transaction IDs matching the key
|
|
92
|
+
*/
|
|
93
|
+
query(indexType, _key) {
|
|
94
|
+
const index = this.indexes.get(indexType);
|
|
95
|
+
if (!index) {
|
|
96
|
+
this.config.logger?.warn?.(`Index not found: ${indexType}`);
|
|
97
|
+
return new Set();
|
|
98
|
+
}
|
|
99
|
+
// For now, return all IDs in the index
|
|
100
|
+
// A full implementation would need to store key -> IDs mapping
|
|
101
|
+
return index.transactionIds;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Clear all indexes
|
|
105
|
+
*/
|
|
106
|
+
clear() {
|
|
107
|
+
this.indexes.clear();
|
|
108
|
+
this.config.logger?.debug?.("Indexes cleared");
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Get index statistics
|
|
112
|
+
*/
|
|
113
|
+
getStats() {
|
|
114
|
+
const stats = {};
|
|
115
|
+
for (const [key, entry] of this.indexes.entries()) {
|
|
116
|
+
stats[key] = entry.transactionIds.size;
|
|
117
|
+
}
|
|
118
|
+
return stats;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Index types
|
|
123
|
+
*/
|
|
124
|
+
export var IndexType;
|
|
125
|
+
(function (IndexType) {
|
|
126
|
+
/** Index by transaction date */
|
|
127
|
+
IndexType["DATE"] = "date";
|
|
128
|
+
/** Index by primary category */
|
|
129
|
+
IndexType["CATEGORY"] = "category";
|
|
130
|
+
/** Index by merchant name */
|
|
131
|
+
IndexType["MERCHANT"] = "merchant";
|
|
132
|
+
/** Index by amount range (buckets) */
|
|
133
|
+
IndexType["AMOUNT_RANGE"] = "amount_range";
|
|
134
|
+
/** Index by pending status */
|
|
135
|
+
IndexType["PENDING"] = "pending";
|
|
136
|
+
})(IndexType || (IndexType = {}));
|
|
137
|
+
/**
|
|
138
|
+
* Query builder for filtering transactions
|
|
139
|
+
*/
|
|
140
|
+
export class TransactionQueryBuilder {
|
|
141
|
+
filters = [];
|
|
142
|
+
/**
|
|
143
|
+
* Filter by date range
|
|
144
|
+
*/
|
|
145
|
+
dateRange(start, end) {
|
|
146
|
+
this.filters.push((txn) => {
|
|
147
|
+
const txnDate = new Date(txn.date);
|
|
148
|
+
return txnDate >= start && txnDate <= end;
|
|
149
|
+
});
|
|
150
|
+
return this;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Filter by category
|
|
154
|
+
*/
|
|
155
|
+
category(category) {
|
|
156
|
+
this.filters.push((txn) => txn.category?.some((c) => c.toLowerCase() === category.toLowerCase()));
|
|
157
|
+
return this;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Filter by merchant name (partial match)
|
|
161
|
+
*/
|
|
162
|
+
merchant(merchant) {
|
|
163
|
+
this.filters.push((txn) => txn.merchantName?.toLowerCase().includes(merchant.toLowerCase()));
|
|
164
|
+
return this;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Filter by amount range (in cents)
|
|
168
|
+
*/
|
|
169
|
+
amountRange(min, max) {
|
|
170
|
+
this.filters.push((txn) => txn.amount >= min && txn.amount <= max);
|
|
171
|
+
return this;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Filter by pending status
|
|
175
|
+
*/
|
|
176
|
+
pending(isPending) {
|
|
177
|
+
this.filters.push((txn) => txn.pending === isPending);
|
|
178
|
+
return this;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Apply all filters to a set of transactions
|
|
182
|
+
*/
|
|
183
|
+
apply(transactions) {
|
|
184
|
+
return transactions.filter((txn) => this.filters.every((filter) => filter(txn)));
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Clear all filters
|
|
188
|
+
*/
|
|
189
|
+
clear() {
|
|
190
|
+
this.filters = [];
|
|
191
|
+
return this;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Inverted index for full-text search
|
|
196
|
+
*/
|
|
197
|
+
export class FullTextIndex {
|
|
198
|
+
index = new Map();
|
|
199
|
+
transactionData = new Map();
|
|
200
|
+
/**
|
|
201
|
+
* Add a transaction to the index
|
|
202
|
+
*/
|
|
203
|
+
add(transaction) {
|
|
204
|
+
this.transactionData.set(transaction.transactionId, transaction);
|
|
205
|
+
// Index merchant name
|
|
206
|
+
if (transaction.merchantName) {
|
|
207
|
+
this.indexDocument(transaction.transactionId, transaction.merchantName);
|
|
208
|
+
}
|
|
209
|
+
// Index categories
|
|
210
|
+
for (const category of transaction.category || []) {
|
|
211
|
+
this.indexDocument(transaction.transactionId, category);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Index a document
|
|
216
|
+
*/
|
|
217
|
+
indexDocument(transactionId, text) {
|
|
218
|
+
const words = text.toLowerCase().split(/\s+/);
|
|
219
|
+
for (const word of words) {
|
|
220
|
+
if (word.length < 2)
|
|
221
|
+
continue; // Skip very short words
|
|
222
|
+
if (!this.index.has(word)) {
|
|
223
|
+
this.index.set(word, new Set());
|
|
224
|
+
}
|
|
225
|
+
this.index.get(word).add(transactionId);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Search for transactions matching a query
|
|
230
|
+
*/
|
|
231
|
+
search(query) {
|
|
232
|
+
const words = query
|
|
233
|
+
.toLowerCase()
|
|
234
|
+
.split(/\s+/)
|
|
235
|
+
.filter((w) => w.length >= 2);
|
|
236
|
+
if (words.length === 0) {
|
|
237
|
+
return [];
|
|
238
|
+
}
|
|
239
|
+
// Find transactions matching all words (AND query)
|
|
240
|
+
let matchingIds = null;
|
|
241
|
+
for (const word of words) {
|
|
242
|
+
const ids = this.index.get(word);
|
|
243
|
+
if (!ids) {
|
|
244
|
+
// Word not found, no results
|
|
245
|
+
return [];
|
|
246
|
+
}
|
|
247
|
+
if (!matchingIds) {
|
|
248
|
+
matchingIds = new Set(ids);
|
|
249
|
+
}
|
|
250
|
+
else {
|
|
251
|
+
// Intersect with current results
|
|
252
|
+
const existingIds = matchingIds;
|
|
253
|
+
matchingIds = new Set();
|
|
254
|
+
for (const id of existingIds) {
|
|
255
|
+
if (ids.has(id)) {
|
|
256
|
+
matchingIds.add(id);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
if (matchingIds.size === 0) {
|
|
261
|
+
return [];
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
// Convert IDs to transactions
|
|
265
|
+
const results = [];
|
|
266
|
+
for (const id of matchingIds || []) {
|
|
267
|
+
const txn = this.transactionData.get(id);
|
|
268
|
+
if (txn) {
|
|
269
|
+
results.push(txn);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
return results;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Clear the index
|
|
276
|
+
*/
|
|
277
|
+
clear() {
|
|
278
|
+
this.index.clear();
|
|
279
|
+
this.transactionData.clear();
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Create a query builder
|
|
284
|
+
*/
|
|
285
|
+
export function createQueryBuilder() {
|
|
286
|
+
return new TransactionQueryBuilder();
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Create a full-text index
|
|
290
|
+
*/
|
|
291
|
+
export function createFullTextIndex() {
|
|
292
|
+
return new FullTextIndex();
|
|
293
|
+
}
|
|
294
|
+
//# sourceMappingURL=indexes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"indexes.js","sourceRoot":"","sources":["../../src/storage/indexes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAsBH;;GAEG;AACH,MAAM,oBAAoB,GAA0B;IAClD,gBAAgB,EAAE,GAAG,EAAE,uBAAuB;IAC9C,MAAM,EAAE;QACN,IAAI,EAAE,GAAG,EAAE,GAAE,CAAC;QACd,KAAK,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AAE,CAAA;QAClB,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,CAAA;IAC9B,CAAC;CACF;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB;IAChC,OAAO,IAAI,uBAAuB,EAAE,CAAA;AACtC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,mBAAmB;IACjC,OAAO,IAAI,aAAa,EAAE,CAAA;AAC5B,CAAC"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File locking for BillClaw
|
|
3
|
+
*
|
|
4
|
+
* Provides inter-process file locking to prevent concurrent write conflicts.
|
|
5
|
+
* Uses proper-lockfile for cross-platform file locking.
|
|
6
|
+
*
|
|
7
|
+
* Use cases:
|
|
8
|
+
* - Preventing concurrent sync operations
|
|
9
|
+
* - Protecting credential writes
|
|
10
|
+
* - Coordinating between multiple processes
|
|
11
|
+
*/
|
|
12
|
+
import type { Logger } from "../errors/errors.js";
|
|
13
|
+
/**
|
|
14
|
+
* Lock options
|
|
15
|
+
*/
|
|
16
|
+
export interface LockOptions {
|
|
17
|
+
/**
|
|
18
|
+
* Lock stale time in milliseconds
|
|
19
|
+
* If a lock is older than this, it will be considered stale and released
|
|
20
|
+
*/
|
|
21
|
+
stale?: number;
|
|
22
|
+
/**
|
|
23
|
+
* Retry options
|
|
24
|
+
*/
|
|
25
|
+
retries?: {
|
|
26
|
+
/**
|
|
27
|
+
* Number of retries to acquire the lock
|
|
28
|
+
*/
|
|
29
|
+
count?: number;
|
|
30
|
+
/**
|
|
31
|
+
* Delay between retries in milliseconds
|
|
32
|
+
*/
|
|
33
|
+
min?: number;
|
|
34
|
+
max?: number;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Logger for debug output
|
|
38
|
+
*/
|
|
39
|
+
logger?: Logger;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Lock handle
|
|
43
|
+
*/
|
|
44
|
+
export interface Lock {
|
|
45
|
+
/**
|
|
46
|
+
* Release the lock
|
|
47
|
+
*/
|
|
48
|
+
release(): Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Check if the lock is still held
|
|
51
|
+
*/
|
|
52
|
+
isLocked(): Promise<boolean>;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Acquire a file lock
|
|
56
|
+
*
|
|
57
|
+
* @param filePath - Path to the file to lock
|
|
58
|
+
* @param options - Lock options
|
|
59
|
+
* @returns Lock handle that must be released when done
|
|
60
|
+
*/
|
|
61
|
+
export declare function acquireLock(filePath: string, options?: LockOptions): Promise<Lock>;
|
|
62
|
+
/**
|
|
63
|
+
* Execute a function while holding a lock
|
|
64
|
+
*
|
|
65
|
+
* @param filePath - Path to the file to lock
|
|
66
|
+
* @param fn - Function to execute while holding the lock
|
|
67
|
+
* @param options - Lock options
|
|
68
|
+
* @returns Result of the function
|
|
69
|
+
*/
|
|
70
|
+
export declare function withLock<T>(filePath: string, fn: () => Promise<T>, options?: LockOptions): Promise<T>;
|
|
71
|
+
/**
|
|
72
|
+
* Check if a file is locked
|
|
73
|
+
*
|
|
74
|
+
* @param filePath - Path to the file to check
|
|
75
|
+
* @returns true if the file is locked
|
|
76
|
+
*/
|
|
77
|
+
export declare function isLocked(filePath: string): Promise<boolean>;
|
|
78
|
+
/**
|
|
79
|
+
* Lock names for common operations
|
|
80
|
+
*/
|
|
81
|
+
export declare const LockNames: {
|
|
82
|
+
/**
|
|
83
|
+
* Global sync lock (prevents concurrent sync operations)
|
|
84
|
+
*/
|
|
85
|
+
SYNC: string;
|
|
86
|
+
/**
|
|
87
|
+
* Account-specific sync lock
|
|
88
|
+
*/
|
|
89
|
+
accountSync(accountId: string): string;
|
|
90
|
+
/**
|
|
91
|
+
* Credential lock (protects credential writes)
|
|
92
|
+
*/
|
|
93
|
+
CREDENTIALS: string;
|
|
94
|
+
/**
|
|
95
|
+
* Account-specific credential lock
|
|
96
|
+
*/
|
|
97
|
+
accountCredentials(accountId: string): string;
|
|
98
|
+
/**
|
|
99
|
+
* Export lock (protects data export operations)
|
|
100
|
+
*/
|
|
101
|
+
EXPORT: string;
|
|
102
|
+
};
|
|
103
|
+
//# sourceMappingURL=locking.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"locking.d.ts","sourceRoot":"","sources":["../../src/storage/locking.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAqBjD;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IAEd;;OAEG;IACH,OAAO,CAAC,EAAE;QACR;;WAEG;QACH,KAAK,CAAC,EAAE,MAAM,CAAA;QAEd;;WAEG;QACH,GAAG,CAAC,EAAE,MAAM,CAAA;QACZ,GAAG,CAAC,EAAE,MAAM,CAAA;KACb,CAAA;IAED;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAcD;;GAEG;AACH,MAAM,WAAW,IAAI;IACnB;;OAEG;IACH,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;IAExB;;OAEG;IACH,QAAQ,IAAI,OAAO,CAAC,OAAO,CAAC,CAAA;CAC7B;AAwCD;;;;;;GAMG;AACH,wBAAsB,WAAW,CAC/B,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE,WAAgB,GACxB,OAAO,CAAC,IAAI,CAAC,CA0Bf;AAED;;;;;;;GAOG;AACH,wBAAsB,QAAQ,CAAC,CAAC,EAC9B,QAAQ,EAAE,MAAM,EAChB,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACpB,OAAO,GAAE,WAAgB,GACxB,OAAO,CAAC,CAAC,CAAC,CAQZ;AAED;;;;;GAKG;AACH,wBAAsB,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAGjE;AAED;;GAEG;AACH,eAAO,MAAM,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