local-lite 2.0.7 → 3.0.1
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 +8 -30
- package/dist/adapters/local/index.d.ts +1 -0
- package/dist/adapters/local/index.js +1 -0
- package/dist/adapters/local/sqlite-wasm.d.ts +25 -0
- package/dist/adapters/local/sqlite-wasm.js +55 -0
- package/dist/adapters/remote/convex.d.ts +1 -1
- package/dist/adapters/remote/convex.js +25 -3
- package/dist/adapters/remote/demo.d.ts +3 -3
- package/dist/adapters/remote/demo.js +11 -3
- package/dist/adapters/remote/firestore.d.ts +1 -1
- package/dist/adapters/remote/firestore.js +57 -91
- package/dist/adapters/remote/index.d.ts +2 -1
- package/dist/adapters/remote/index.js +1 -0
- package/dist/adapters/remote/postgres.d.ts +37 -0
- package/dist/adapters/remote/postgres.js +119 -0
- package/dist/adapters/remote/self-hosted.d.ts +12 -0
- package/dist/adapters/remote/self-hosted.js +55 -4
- package/dist/adapters/remote/supabase.d.ts +1 -1
- package/dist/adapters/remote/supabase.js +22 -5
- package/dist/auth/apple.js +0 -6
- package/dist/auth/github.js +0 -3
- package/dist/auth/google.js +0 -3
- package/dist/auth/identity.d.ts +0 -5
- package/dist/auth/identity.js +0 -3
- package/dist/auth/microsoft.js +0 -3
- package/dist/auth/unified.d.ts +5 -5
- package/dist/auth/unified.js +1 -1
- package/dist/config/index.d.ts +0 -12
- package/dist/config/index.js +3 -26
- package/dist/config/types.d.ts +3 -2
- package/dist/core/audit.d.ts +52 -0
- package/dist/core/audit.js +153 -0
- package/dist/core/client.d.ts +4 -0
- package/dist/core/client.js +7 -0
- package/dist/core/conflict.d.ts +24 -0
- package/dist/core/conflict.js +77 -0
- package/dist/core/field-encryption.d.ts +25 -0
- package/dist/core/field-encryption.js +128 -0
- package/dist/core/index.d.ts +2 -0
- package/dist/core/index.js +2 -0
- package/dist/core/query-builder.d.ts +51 -0
- package/dist/core/query-builder.js +278 -35
- package/dist/core/query.js +6 -1
- package/dist/core/types.d.ts +2 -1
- package/dist/devtools/BenchmarkModal.js +285 -1
- package/dist/email/index.d.ts +1 -1
- package/dist/email/index.js +2 -2
- package/dist/index.d.ts +2 -27
- package/dist/index.js +2 -27
- package/dist/presence/index.d.ts +45 -0
- package/dist/presence/index.js +142 -0
- package/dist/reactive/event-emitter.d.ts +10 -1
- package/dist/reactive/event-emitter.js +44 -1
- package/dist/reactive/live-query.d.ts +18 -0
- package/dist/reactive/live-query.js +71 -0
- package/dist/schema/index.d.ts +1 -0
- package/dist/schema/index.js +1 -0
- package/dist/schema/typed.d.ts +38 -0
- package/dist/schema/typed.js +33 -0
- package/dist/server/dashboard.d.ts +2 -0
- package/dist/server/dashboard.js +182 -2
- package/dist/solid/index.d.ts +24 -0
- package/dist/solid/index.js +35 -0
- package/dist/storage/firebase.d.ts +3 -3
- package/dist/storage/firebase.js +40 -94
- package/dist/svelte/index.d.ts +15 -0
- package/dist/svelte/index.js +27 -0
- package/dist/testing/index.d.ts +22 -0
- package/dist/testing/index.js +74 -0
- package/dist/vue/index.d.ts +27 -0
- package/dist/vue/index.js +37 -0
- package/package.json +46 -9
- package/skills/local-lite-auth/SKILL.md +1 -1
- package/skills/local-lite-custom-adapter/SKILL.md +7 -4
- package/skills/local-lite-react/SKILL.md +1 -1
- package/skills/local-lite-setup/SKILL.md +3 -2
- package/skills/local-lite-upgrade/SKILL.md +16 -0
- package/dist/kv/index.d.ts +0 -3
- package/dist/kv/index.js +0 -19
- package/dist/kv/manager.d.ts +0 -52
- package/dist/kv/manager.js +0 -167
- package/dist/kv/store.d.ts +0 -13
- package/dist/kv/store.js +0 -85
- package/dist/kv/types.d.ts +0 -27
- package/dist/kv/types.js +0 -2
- package/dist/react/kv.d.ts +0 -9
- package/dist/react/kv.js +0 -53
package/dist/core/conflict.d.ts
CHANGED
|
@@ -3,6 +3,30 @@ export type { ConflictContext, ConflictResolution, ConflictResolver, ConflictStr
|
|
|
3
3
|
export declare const lastWriteWinsResolver: ConflictResolver;
|
|
4
4
|
export declare const serverWinsResolver: ConflictResolver;
|
|
5
5
|
export declare const clientWinsResolver: ConflictResolver;
|
|
6
|
+
export interface PNCounterState {
|
|
7
|
+
p: Record<string, number>;
|
|
8
|
+
n: Record<string, number>;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Merges two distributed PN-Counter states by taking the element-wise max of positive and negative vectors.
|
|
12
|
+
*/
|
|
13
|
+
export declare function mergePNCounter(a: PNCounterState | null | undefined, b: PNCounterState | null | undefined): PNCounterState;
|
|
14
|
+
/**
|
|
15
|
+
* Computes the net numeric value of a PN-Counter state.
|
|
16
|
+
*/
|
|
17
|
+
export declare function pnCounterValue(state: PNCounterState): number;
|
|
18
|
+
export interface LWWElementSetState {
|
|
19
|
+
add: Record<string, number>;
|
|
20
|
+
remove: Record<string, number>;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Merges two LWW-Element-Set states by taking the max timestamp for each add/remove entry.
|
|
24
|
+
*/
|
|
25
|
+
export declare function mergeLWWElementSet(a: LWWElementSetState | null | undefined, b: LWWElementSetState | null | undefined): LWWElementSetState;
|
|
26
|
+
/**
|
|
27
|
+
* Returns the active elements of an LWW-Element-Set (add timestamp >= remove timestamp).
|
|
28
|
+
*/
|
|
29
|
+
export declare function lwwElementSetValues(state: LWWElementSetState): string[];
|
|
6
30
|
/**
|
|
7
31
|
* Creates a smart 3-way field-level conflict resolver.
|
|
8
32
|
* Merges disjoint fields from both local and remote offline mutations,
|
package/dist/core/conflict.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.clientWinsResolver = exports.serverWinsResolver = exports.lastWriteWinsResolver = void 0;
|
|
4
|
+
exports.mergePNCounter = mergePNCounter;
|
|
5
|
+
exports.pnCounterValue = pnCounterValue;
|
|
6
|
+
exports.mergeLWWElementSet = mergeLWWElementSet;
|
|
7
|
+
exports.lwwElementSetValues = lwwElementSetValues;
|
|
4
8
|
exports.createFieldMergeResolver = createFieldMergeResolver;
|
|
5
9
|
exports.getConflictResolver = getConflictResolver;
|
|
6
10
|
const lastWriteWinsResolver = (context) => {
|
|
@@ -23,6 +27,55 @@ const clientWinsResolver = (context) => {
|
|
|
23
27
|
return 'apply-remote';
|
|
24
28
|
};
|
|
25
29
|
exports.clientWinsResolver = clientWinsResolver;
|
|
30
|
+
/**
|
|
31
|
+
* Merges two distributed PN-Counter states by taking the element-wise max of positive and negative vectors.
|
|
32
|
+
*/
|
|
33
|
+
function mergePNCounter(a, b) {
|
|
34
|
+
const p = { ...(a?.p ?? {}) };
|
|
35
|
+
const n = { ...(a?.n ?? {}) };
|
|
36
|
+
for (const [k, v] of Object.entries(b?.p ?? {})) {
|
|
37
|
+
p[k] = Math.max(p[k] ?? 0, v);
|
|
38
|
+
}
|
|
39
|
+
for (const [k, v] of Object.entries(b?.n ?? {})) {
|
|
40
|
+
n[k] = Math.max(n[k] ?? 0, v);
|
|
41
|
+
}
|
|
42
|
+
return { p, n };
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Computes the net numeric value of a PN-Counter state.
|
|
46
|
+
*/
|
|
47
|
+
function pnCounterValue(state) {
|
|
48
|
+
const pos = Object.values(state.p).reduce((acc, v) => acc + v, 0);
|
|
49
|
+
const neg = Object.values(state.n).reduce((acc, v) => acc + v, 0);
|
|
50
|
+
return pos - neg;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Merges two LWW-Element-Set states by taking the max timestamp for each add/remove entry.
|
|
54
|
+
*/
|
|
55
|
+
function mergeLWWElementSet(a, b) {
|
|
56
|
+
const add = { ...(a?.add ?? {}) };
|
|
57
|
+
const remove = { ...(a?.remove ?? {}) };
|
|
58
|
+
for (const [k, ts] of Object.entries(b?.add ?? {})) {
|
|
59
|
+
add[k] = Math.max(add[k] ?? 0, ts);
|
|
60
|
+
}
|
|
61
|
+
for (const [k, ts] of Object.entries(b?.remove ?? {})) {
|
|
62
|
+
remove[k] = Math.max(remove[k] ?? 0, ts);
|
|
63
|
+
}
|
|
64
|
+
return { add, remove };
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Returns the active elements of an LWW-Element-Set (add timestamp >= remove timestamp).
|
|
68
|
+
*/
|
|
69
|
+
function lwwElementSetValues(state) {
|
|
70
|
+
const result = [];
|
|
71
|
+
for (const [item, addTs] of Object.entries(state.add)) {
|
|
72
|
+
const remTs = state.remove[item] ?? -1;
|
|
73
|
+
if (addTs >= remTs) {
|
|
74
|
+
result.push(item);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return result;
|
|
78
|
+
}
|
|
26
79
|
/**
|
|
27
80
|
* Creates a smart 3-way field-level conflict resolver.
|
|
28
81
|
* Merges disjoint fields from both local and remote offline mutations,
|
|
@@ -78,6 +131,30 @@ function createFieldMergeResolver(options = {}) {
|
|
|
78
131
|
else if (rule === 'remote') {
|
|
79
132
|
merged[key] = remoteVal;
|
|
80
133
|
}
|
|
134
|
+
else if (rule === 'set-union') {
|
|
135
|
+
const remoteArr = Array.isArray(remoteVal) ? remoteVal : [];
|
|
136
|
+
const localArr = Array.isArray(localVal) ? localVal : [];
|
|
137
|
+
merged[key] = Array.from(new Set([...remoteArr, ...localArr]));
|
|
138
|
+
}
|
|
139
|
+
else if (rule === 'pn-counter') {
|
|
140
|
+
if (typeof localVal === 'object' &&
|
|
141
|
+
localVal !== null &&
|
|
142
|
+
'p' in localVal &&
|
|
143
|
+
typeof remoteVal === 'object' &&
|
|
144
|
+
remoteVal !== null &&
|
|
145
|
+
'p' in remoteVal) {
|
|
146
|
+
merged[key] = mergePNCounter(localVal, remoteVal);
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
const baseNum = typeof baseRow[key] === 'number' ? baseRow[key] : 0;
|
|
150
|
+
const localDelta = (Number(localVal) || 0) - baseNum;
|
|
151
|
+
const remoteDelta = (Number(remoteVal) || 0) - baseNum;
|
|
152
|
+
merged[key] = baseNum + localDelta + remoteDelta;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
else if (rule === 'lww-element-set') {
|
|
156
|
+
merged[key] = mergeLWWElementSet(localVal, remoteVal);
|
|
157
|
+
}
|
|
81
158
|
else {
|
|
82
159
|
const winner = rule === 'newer' ? 'newer' : defaultWinner;
|
|
83
160
|
if (winner === 'local') {
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { LocalDBAdapter } from '../adapters/local/index.js';
|
|
2
|
+
export interface FieldEncryptorOptions {
|
|
3
|
+
/** Secret key or passphrase (hashed to 256-bit AES key if not a 32-byte Uint8Array). */
|
|
4
|
+
key: string | Uint8Array;
|
|
5
|
+
/** Map of tableName -> array of column names to encrypt/decrypt transparently. */
|
|
6
|
+
encryptedColumns: Record<string, string[]>;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Transparent AES-256-GCM field-level encryptor for sensitive SQLite columns.
|
|
10
|
+
*/
|
|
11
|
+
export declare class FieldEncryptor {
|
|
12
|
+
private encryptedColumns;
|
|
13
|
+
private rawKeyBytes;
|
|
14
|
+
private cryptoKeyPromise;
|
|
15
|
+
constructor(options: FieldEncryptorOptions);
|
|
16
|
+
private getCryptoKey;
|
|
17
|
+
encryptValue(value: any): Promise<string>;
|
|
18
|
+
decryptValue(raw: any): Promise<any>;
|
|
19
|
+
encryptPayload<T extends Record<string, any>>(tableName: string, payload: T): Promise<T>;
|
|
20
|
+
decryptRow<T extends Record<string, any>>(tableName: string, row: T): Promise<T>;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Configures SQLCipher at-rest encryption key via `PRAGMA key` for compatible SQLite adapters.
|
|
24
|
+
*/
|
|
25
|
+
export declare function applySqlCipherKey(db: LocalDBAdapter, key: string): Promise<void>;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FieldEncryptor = void 0;
|
|
4
|
+
exports.applySqlCipherKey = applySqlCipherKey;
|
|
5
|
+
const sha2_js_1 = require("@noble/hashes/sha2.js");
|
|
6
|
+
const utils_js_1 = require("@noble/hashes/utils.js");
|
|
7
|
+
const crypto_js_1 = require("../utils/crypto.js");
|
|
8
|
+
const ENC_PREFIX = 'enc:v1:';
|
|
9
|
+
const IV_LENGTH = 12;
|
|
10
|
+
function toBase64(bytes) {
|
|
11
|
+
if (typeof Buffer !== 'undefined') {
|
|
12
|
+
return Buffer.from(bytes).toString('base64');
|
|
13
|
+
}
|
|
14
|
+
let bin = '';
|
|
15
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
16
|
+
bin += String.fromCharCode(bytes[i]);
|
|
17
|
+
}
|
|
18
|
+
return btoa(bin);
|
|
19
|
+
}
|
|
20
|
+
function fromBase64(b64) {
|
|
21
|
+
if (typeof Buffer !== 'undefined') {
|
|
22
|
+
return new Uint8Array(Buffer.from(b64, 'base64'));
|
|
23
|
+
}
|
|
24
|
+
const bin = atob(b64);
|
|
25
|
+
const out = new Uint8Array(bin.length);
|
|
26
|
+
for (let i = 0; i < bin.length; i++) {
|
|
27
|
+
out[i] = bin.charCodeAt(i);
|
|
28
|
+
}
|
|
29
|
+
return out;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Transparent AES-256-GCM field-level encryptor for sensitive SQLite columns.
|
|
33
|
+
*/
|
|
34
|
+
class FieldEncryptor {
|
|
35
|
+
encryptedColumns;
|
|
36
|
+
rawKeyBytes;
|
|
37
|
+
cryptoKeyPromise = null;
|
|
38
|
+
constructor(options) {
|
|
39
|
+
this.encryptedColumns = options.encryptedColumns;
|
|
40
|
+
if (options.key instanceof Uint8Array) {
|
|
41
|
+
if (options.key.length !== 32) {
|
|
42
|
+
this.rawKeyBytes = (0, sha2_js_1.sha256)(options.key);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
this.rawKeyBytes = options.key;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
if (!options.key) {
|
|
50
|
+
throw new Error('A non-empty encryption key is required.');
|
|
51
|
+
}
|
|
52
|
+
this.rawKeyBytes = (0, sha2_js_1.sha256)((0, utils_js_1.utf8ToBytes)(options.key));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
getCryptoKey() {
|
|
56
|
+
if (!this.cryptoKeyPromise) {
|
|
57
|
+
const subtle = globalThis.crypto?.subtle;
|
|
58
|
+
if (!subtle) {
|
|
59
|
+
throw new Error('Web Crypto SubtleCrypto is required for field-level encryption.');
|
|
60
|
+
}
|
|
61
|
+
this.cryptoKeyPromise = subtle.importKey('raw', this.rawKeyBytes.buffer.slice(this.rawKeyBytes.byteOffset, this.rawKeyBytes.byteOffset + this.rawKeyBytes.byteLength), { name: 'AES-GCM' }, false, ['encrypt', 'decrypt']);
|
|
62
|
+
}
|
|
63
|
+
return this.cryptoKeyPromise;
|
|
64
|
+
}
|
|
65
|
+
async encryptValue(value) {
|
|
66
|
+
if (value === null || value === undefined)
|
|
67
|
+
return value;
|
|
68
|
+
if (typeof value === 'string' && value.startsWith(ENC_PREFIX)) {
|
|
69
|
+
return value;
|
|
70
|
+
}
|
|
71
|
+
const key = await this.getCryptoKey();
|
|
72
|
+
const iv = (0, crypto_js_1.requireSecureRandomBytes)(IV_LENGTH);
|
|
73
|
+
const plainBytes = (0, utils_js_1.utf8ToBytes)(JSON.stringify(value));
|
|
74
|
+
const cipherBuf = await globalThis.crypto.subtle.encrypt({ name: 'AES-GCM', iv: iv }, key, plainBytes);
|
|
75
|
+
const cipherBytes = new Uint8Array(cipherBuf);
|
|
76
|
+
const combined = new Uint8Array(IV_LENGTH + cipherBytes.length);
|
|
77
|
+
combined.set(iv, 0);
|
|
78
|
+
combined.set(cipherBytes, IV_LENGTH);
|
|
79
|
+
return ENC_PREFIX + toBase64(combined);
|
|
80
|
+
}
|
|
81
|
+
async decryptValue(raw) {
|
|
82
|
+
if (typeof raw !== 'string' || !raw.startsWith(ENC_PREFIX)) {
|
|
83
|
+
return raw;
|
|
84
|
+
}
|
|
85
|
+
const key = await this.getCryptoKey();
|
|
86
|
+
const combined = fromBase64(raw.slice(ENC_PREFIX.length));
|
|
87
|
+
const iv = combined.slice(0, IV_LENGTH);
|
|
88
|
+
const cipherBytes = combined.slice(IV_LENGTH);
|
|
89
|
+
const plainBuf = await globalThis.crypto.subtle.decrypt({ name: 'AES-GCM', iv: iv }, key, cipherBytes);
|
|
90
|
+
const json = new TextDecoder().decode(plainBuf);
|
|
91
|
+
return JSON.parse(json);
|
|
92
|
+
}
|
|
93
|
+
async encryptPayload(tableName, payload) {
|
|
94
|
+
const cols = this.encryptedColumns[tableName];
|
|
95
|
+
if (!cols || cols.length === 0 || !payload)
|
|
96
|
+
return payload;
|
|
97
|
+
const copy = { ...payload };
|
|
98
|
+
for (const col of cols) {
|
|
99
|
+
if (col in copy && copy[col] !== null && copy[col] !== undefined) {
|
|
100
|
+
copy[col] = await this.encryptValue(copy[col]);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return copy;
|
|
104
|
+
}
|
|
105
|
+
async decryptRow(tableName, row) {
|
|
106
|
+
const cols = this.encryptedColumns[tableName];
|
|
107
|
+
if (!cols || cols.length === 0 || !row)
|
|
108
|
+
return row;
|
|
109
|
+
const copy = { ...row };
|
|
110
|
+
for (const col of cols) {
|
|
111
|
+
if (col in copy && typeof copy[col] === 'string') {
|
|
112
|
+
copy[col] = await this.decryptValue(copy[col]);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return copy;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
exports.FieldEncryptor = FieldEncryptor;
|
|
119
|
+
/**
|
|
120
|
+
* Configures SQLCipher at-rest encryption key via `PRAGMA key` for compatible SQLite adapters.
|
|
121
|
+
*/
|
|
122
|
+
async function applySqlCipherKey(db, key) {
|
|
123
|
+
if (!key) {
|
|
124
|
+
throw new Error('A non-empty SQLCipher key is required.');
|
|
125
|
+
}
|
|
126
|
+
const escaped = key.replace(/'/g, "''");
|
|
127
|
+
await db.execute(`PRAGMA key = '${escaped}'`);
|
|
128
|
+
}
|
package/dist/core/index.d.ts
CHANGED
|
@@ -9,6 +9,8 @@ export * from './table-manager.js';
|
|
|
9
9
|
export * from './schema-manager.js';
|
|
10
10
|
export * from './query-builder.js';
|
|
11
11
|
export * from './maintenance.js';
|
|
12
|
+
export * from './field-encryption.js';
|
|
13
|
+
export * from './audit.js';
|
|
12
14
|
export * from '../reactive/event-emitter.js';
|
|
13
15
|
export * from '../adapters/network/index.js';
|
|
14
16
|
export type { LocalDBAdapter, LocalTransaction, } from '../adapters/local/index.js';
|
package/dist/core/index.js
CHANGED
|
@@ -26,6 +26,8 @@ __exportStar(require("./table-manager.js"), exports);
|
|
|
26
26
|
__exportStar(require("./schema-manager.js"), exports);
|
|
27
27
|
__exportStar(require("./query-builder.js"), exports);
|
|
28
28
|
__exportStar(require("./maintenance.js"), exports);
|
|
29
|
+
__exportStar(require("./field-encryption.js"), exports);
|
|
30
|
+
__exportStar(require("./audit.js"), exports);
|
|
29
31
|
__exportStar(require("../reactive/event-emitter.js"), exports);
|
|
30
32
|
__exportStar(require("../adapters/network/index.js"), exports);
|
|
31
33
|
__exportStar(require("../utils/logger.js"), exports);
|
|
@@ -11,6 +11,26 @@ export interface JoinDefinition {
|
|
|
11
11
|
firstCol: string;
|
|
12
12
|
secondCol: string;
|
|
13
13
|
}
|
|
14
|
+
export interface WithRelationSpec {
|
|
15
|
+
/** Related table name to load. */
|
|
16
|
+
table: string;
|
|
17
|
+
/** Property name to attach on each parent row (defaults to `table`). */
|
|
18
|
+
as?: string;
|
|
19
|
+
/** Foreign key column name (auto-resolved from client.relationships if omitted). */
|
|
20
|
+
foreignKey?: string;
|
|
21
|
+
/** Local key column name (defaults to primaryKey / 'id'). */
|
|
22
|
+
localKey?: string;
|
|
23
|
+
/** Explicit cardinality; inferred from client.relationships when omitted. */
|
|
24
|
+
type?: 'hasMany' | 'belongsTo';
|
|
25
|
+
/** Optional filter applied to the related rows query. */
|
|
26
|
+
where?: WhereFilter;
|
|
27
|
+
}
|
|
28
|
+
export interface PreparedQuery<T = any> {
|
|
29
|
+
sql: string;
|
|
30
|
+
params: any[];
|
|
31
|
+
execute(overrideParams?: any[]): Promise<T[]>;
|
|
32
|
+
first(overrideParams?: any[]): Promise<T | null>;
|
|
33
|
+
}
|
|
14
34
|
export interface AggregateSpec {
|
|
15
35
|
where?: WhereFilter;
|
|
16
36
|
count?: boolean;
|
|
@@ -34,8 +54,11 @@ export declare class QueryBuilder<T = any> {
|
|
|
34
54
|
private client;
|
|
35
55
|
private tableName;
|
|
36
56
|
private selectCols;
|
|
57
|
+
private isDistinct;
|
|
37
58
|
private joins;
|
|
38
59
|
private whereConditions;
|
|
60
|
+
private havingConditions;
|
|
61
|
+
private withRelations;
|
|
39
62
|
private orderColumn?;
|
|
40
63
|
private orderDirection;
|
|
41
64
|
private limitCount?;
|
|
@@ -48,6 +71,10 @@ export declare class QueryBuilder<T = any> {
|
|
|
48
71
|
* Supports column aliases (e.g. ['id', 'contracts.rent_amount AS rent', 'houses.house_number']).
|
|
49
72
|
*/
|
|
50
73
|
select(...columns: Array<string | string[]>): this;
|
|
74
|
+
/**
|
|
75
|
+
* Adds DISTINCT to the SELECT projection.
|
|
76
|
+
*/
|
|
77
|
+
distinct(enabled?: boolean): this;
|
|
51
78
|
/**
|
|
52
79
|
* Inner joins another SQLite table on a matching column expression.
|
|
53
80
|
*/
|
|
@@ -64,6 +91,14 @@ export declare class QueryBuilder<T = any> {
|
|
|
64
91
|
* - where('end_date', '>=', today)
|
|
65
92
|
*/
|
|
66
93
|
where(columnOrFilter: string | WhereFilter, operatorOrValue?: any, value?: any): this;
|
|
94
|
+
/**
|
|
95
|
+
* Adds a negated WHERE condition ($not). Multiple calls are combined with $and.
|
|
96
|
+
*/
|
|
97
|
+
whereNot(filter: Record<string, any>): this;
|
|
98
|
+
/**
|
|
99
|
+
* Adds an OR group of filter objects to the WHERE clause.
|
|
100
|
+
*/
|
|
101
|
+
orWhere(...filters: Record<string, any>[]): this;
|
|
67
102
|
/**
|
|
68
103
|
* Orders query results by column and direction.
|
|
69
104
|
*/
|
|
@@ -72,6 +107,22 @@ export declare class QueryBuilder<T = any> {
|
|
|
72
107
|
* Groups rows by one or more columns for aggregation.
|
|
73
108
|
*/
|
|
74
109
|
groupBy(...columns: Array<string | string[]>): this;
|
|
110
|
+
/**
|
|
111
|
+
* Adds HAVING criteria to filter grouped aggregation results.
|
|
112
|
+
*/
|
|
113
|
+
having(columnOrFilter: string | Record<string, any>, operatorOrValue?: any, value?: any): this;
|
|
114
|
+
/**
|
|
115
|
+
* Eagerly preloads related records from declared client relationships or explicit relation specs.
|
|
116
|
+
*/
|
|
117
|
+
with(...relations: Array<string | WithRelationSpec>): this;
|
|
118
|
+
/**
|
|
119
|
+
* Returns a shallow-cloned QueryBuilder with independent mutable state.
|
|
120
|
+
*/
|
|
121
|
+
clone(): QueryBuilder<T>;
|
|
122
|
+
/**
|
|
123
|
+
* Compiles the query once into a reusable PreparedQuery handle.
|
|
124
|
+
*/
|
|
125
|
+
prepare(): PreparedQuery<T>;
|
|
75
126
|
/**
|
|
76
127
|
* Limits the number of returned records.
|
|
77
128
|
*/
|