@affectively/dash 5.2.1 → 5.3.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/dist/index.d.ts +62 -0
- package/dist/index.js +31 -0
- package/dist/sync/index.d.ts +6 -0
- package/dist/sync/index.js +4 -0
- package/package.json +45 -66
- package/README.md +0 -193
- package/dist/src/api/firebase/auth/index.d.ts +0 -137
- package/dist/src/api/firebase/auth/index.js +0 -352
- package/dist/src/api/firebase/auth/providers.d.ts +0 -254
- package/dist/src/api/firebase/auth/providers.js +0 -518
- package/dist/src/api/firebase/database/index.d.ts +0 -108
- package/dist/src/api/firebase/database/index.js +0 -368
- package/dist/src/api/firebase/errors.d.ts +0 -15
- package/dist/src/api/firebase/errors.js +0 -215
- package/dist/src/api/firebase/firestore/data-types.d.ts +0 -116
- package/dist/src/api/firebase/firestore/data-types.js +0 -280
- package/dist/src/api/firebase/firestore/index.d.ts +0 -7
- package/dist/src/api/firebase/firestore/index.js +0 -13
- package/dist/src/api/firebase/firestore/listeners.d.ts +0 -20
- package/dist/src/api/firebase/firestore/listeners.js +0 -50
- package/dist/src/api/firebase/firestore/operations.d.ts +0 -123
- package/dist/src/api/firebase/firestore/operations.js +0 -490
- package/dist/src/api/firebase/firestore/query.d.ts +0 -118
- package/dist/src/api/firebase/firestore/query.js +0 -418
- package/dist/src/api/firebase/index.d.ts +0 -11
- package/dist/src/api/firebase/index.js +0 -17
- package/dist/src/api/firebase/storage/index.d.ts +0 -100
- package/dist/src/api/firebase/storage/index.js +0 -286
- package/dist/src/api/firebase/types.d.ts +0 -341
- package/dist/src/api/firebase/types.js +0 -4
- package/dist/src/auth/manager.d.ts +0 -182
- package/dist/src/auth/manager.js +0 -598
- package/dist/src/engine/ai.d.ts +0 -10
- package/dist/src/engine/ai.js +0 -76
- package/dist/src/engine/sqlite.d.ts +0 -298
- package/dist/src/engine/sqlite.js +0 -1088
- package/dist/src/engine/vec_extension.d.ts +0 -5
- package/dist/src/engine/vec_extension.js +0 -10
- package/dist/src/index.d.ts +0 -15
- package/dist/src/index.js +0 -24
- package/dist/src/mcp/server.d.ts +0 -8
- package/dist/src/mcp/server.js +0 -87
- package/dist/src/reactivity/signal.d.ts +0 -3
- package/dist/src/reactivity/signal.js +0 -31
- package/dist/src/schema/lens.d.ts +0 -29
- package/dist/src/schema/lens.js +0 -122
- package/dist/src/sync/aeon/config.d.ts +0 -21
- package/dist/src/sync/aeon/config.js +0 -14
- package/dist/src/sync/aeon/delta-adapter.d.ts +0 -62
- package/dist/src/sync/aeon/delta-adapter.js +0 -98
- package/dist/src/sync/aeon/index.d.ts +0 -18
- package/dist/src/sync/aeon/index.js +0 -19
- package/dist/src/sync/aeon/offline-adapter.d.ts +0 -110
- package/dist/src/sync/aeon/offline-adapter.js +0 -227
- package/dist/src/sync/aeon/presence-adapter.d.ts +0 -114
- package/dist/src/sync/aeon/presence-adapter.js +0 -157
- package/dist/src/sync/aeon/schema-adapter.d.ts +0 -95
- package/dist/src/sync/aeon/schema-adapter.js +0 -163
- package/dist/src/sync/backup.d.ts +0 -12
- package/dist/src/sync/backup.js +0 -44
- package/dist/src/sync/connection.d.ts +0 -20
- package/dist/src/sync/connection.js +0 -50
- package/dist/src/sync/d1-provider.d.ts +0 -97
- package/dist/src/sync/d1-provider.js +0 -345
- package/dist/src/sync/hybrid-provider.d.ts +0 -172
- package/dist/src/sync/hybrid-provider.js +0 -477
- package/dist/src/sync/provider.d.ts +0 -11
- package/dist/src/sync/provider.js +0 -67
- package/dist/src/sync/verify.d.ts +0 -1
- package/dist/src/sync/verify.js +0 -23
- package/dist/tsconfig.tsbuildinfo +0 -1
|
@@ -1,490 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Firestore document operations (read/write)
|
|
3
|
-
*/
|
|
4
|
-
import { createFirebaseError } from '../errors.js';
|
|
5
|
-
import { DocumentReferenceImpl, CollectionReferenceImpl, compileQuery } from './query.js';
|
|
6
|
-
import { serializeFieldValue } from './data-types.js';
|
|
7
|
-
// Mock storage for tests
|
|
8
|
-
const mockStorage = new Map();
|
|
9
|
-
// Mock listeners for tests
|
|
10
|
-
export const mockListeners = new Map();
|
|
11
|
-
// Make global for tests
|
|
12
|
-
globalThis.mockListeners = mockListeners;
|
|
13
|
-
// Trigger mock listeners
|
|
14
|
-
export function triggerMockListeners(key, snapshot) {
|
|
15
|
-
const mockListeners = globalThis.mockListeners;
|
|
16
|
-
const listeners = mockListeners.get(key);
|
|
17
|
-
if (listeners) {
|
|
18
|
-
listeners.forEach((callback) => {
|
|
19
|
-
if (typeof callback === 'function') {
|
|
20
|
-
callback(snapshot);
|
|
21
|
-
}
|
|
22
|
-
else if (callback && typeof callback.next === 'function') {
|
|
23
|
-
callback.next(snapshot);
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Document snapshot implementation
|
|
30
|
-
*/
|
|
31
|
-
export class DocumentSnapshotImpl {
|
|
32
|
-
_firestore;
|
|
33
|
-
_userDataWriter;
|
|
34
|
-
_doc;
|
|
35
|
-
ref;
|
|
36
|
-
metadata;
|
|
37
|
-
constructor(firestore, ref, data, metadata) {
|
|
38
|
-
this._firestore = firestore;
|
|
39
|
-
this.ref = ref;
|
|
40
|
-
this._doc = data;
|
|
41
|
-
this.metadata = metadata;
|
|
42
|
-
}
|
|
43
|
-
get id() {
|
|
44
|
-
return this.ref.id;
|
|
45
|
-
}
|
|
46
|
-
exists() {
|
|
47
|
-
return this._doc !== null && this._doc !== undefined;
|
|
48
|
-
}
|
|
49
|
-
data(options) {
|
|
50
|
-
if (!this.exists()) {
|
|
51
|
-
return undefined;
|
|
52
|
-
}
|
|
53
|
-
// Return deep copy to prevent mutations from affecting original
|
|
54
|
-
return this._deepCopy(this._doc);
|
|
55
|
-
}
|
|
56
|
-
get(fieldPath, options) {
|
|
57
|
-
if (!this.exists()) {
|
|
58
|
-
return undefined;
|
|
59
|
-
}
|
|
60
|
-
const segments = fieldPath.split('.');
|
|
61
|
-
let value = this._doc;
|
|
62
|
-
for (const segment of segments) {
|
|
63
|
-
if (value === null || value === undefined) {
|
|
64
|
-
return undefined;
|
|
65
|
-
}
|
|
66
|
-
value = value[segment];
|
|
67
|
-
}
|
|
68
|
-
return value;
|
|
69
|
-
}
|
|
70
|
-
toJSON() {
|
|
71
|
-
return this._doc;
|
|
72
|
-
}
|
|
73
|
-
_deepFreeze(obj) {
|
|
74
|
-
if (obj === null || typeof obj !== 'object') {
|
|
75
|
-
return obj;
|
|
76
|
-
}
|
|
77
|
-
if (Array.isArray(obj)) {
|
|
78
|
-
return Object.freeze(obj.map(item => this._deepFreeze(item)));
|
|
79
|
-
}
|
|
80
|
-
const frozen = { ...obj };
|
|
81
|
-
Object.keys(frozen).forEach(key => {
|
|
82
|
-
frozen[key] = this._deepFreeze(frozen[key]);
|
|
83
|
-
});
|
|
84
|
-
return Object.freeze(frozen);
|
|
85
|
-
}
|
|
86
|
-
_deepCopy(obj) {
|
|
87
|
-
if (obj === null || typeof obj !== 'object') {
|
|
88
|
-
return obj;
|
|
89
|
-
}
|
|
90
|
-
if (Array.isArray(obj)) {
|
|
91
|
-
return obj.map(item => this._deepCopy(item));
|
|
92
|
-
}
|
|
93
|
-
const copy = { ...obj };
|
|
94
|
-
Object.keys(copy).forEach(key => {
|
|
95
|
-
copy[key] = this._deepCopy(copy[key]);
|
|
96
|
-
});
|
|
97
|
-
return copy;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Query snapshot implementation
|
|
102
|
-
*/
|
|
103
|
-
export class QuerySnapshotImpl {
|
|
104
|
-
_firestore;
|
|
105
|
-
_snapshot;
|
|
106
|
-
query; // Accept CollectionReference as well
|
|
107
|
-
docs;
|
|
108
|
-
size;
|
|
109
|
-
empty;
|
|
110
|
-
metadata;
|
|
111
|
-
_docChanges = null;
|
|
112
|
-
constructor(firestore, query, docs, metadata) {
|
|
113
|
-
this._firestore = firestore;
|
|
114
|
-
this.query = query;
|
|
115
|
-
this.docs = docs;
|
|
116
|
-
this.size = docs.length;
|
|
117
|
-
this.empty = docs.length === 0;
|
|
118
|
-
this.metadata = metadata;
|
|
119
|
-
}
|
|
120
|
-
docChanges() {
|
|
121
|
-
if (this._docChanges === null) {
|
|
122
|
-
this._docChanges = this.docs.map((doc, index) => ({
|
|
123
|
-
type: 'added',
|
|
124
|
-
doc,
|
|
125
|
-
oldIndex: -1,
|
|
126
|
-
newIndex: index,
|
|
127
|
-
}));
|
|
128
|
-
}
|
|
129
|
-
return this._docChanges;
|
|
130
|
-
}
|
|
131
|
-
forEach(callback) {
|
|
132
|
-
this.docs.forEach(callback);
|
|
133
|
-
}
|
|
134
|
-
toJSON() {
|
|
135
|
-
return this.docs.map(doc => doc.toJSON());
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* Get a single document snapshot
|
|
140
|
-
*/
|
|
141
|
-
export async function getDoc(reference, engine) {
|
|
142
|
-
if (!engine) {
|
|
143
|
-
// Mock document snapshot for tests
|
|
144
|
-
const ref = reference;
|
|
145
|
-
const data = mockStorage.get(ref.path) || null;
|
|
146
|
-
return new DocumentSnapshotImpl(ref.firestore, reference, data, { hasPendingWrites: false, fromCache: false });
|
|
147
|
-
}
|
|
148
|
-
try {
|
|
149
|
-
const ref = reference;
|
|
150
|
-
const tableName = ref.parent.id || 'documents';
|
|
151
|
-
// Query by document ID
|
|
152
|
-
const sql = `SELECT * FROM \`${tableName}\` WHERE id = ? LIMIT 1`;
|
|
153
|
-
const results = await engine.execute(sql, [ref.id]);
|
|
154
|
-
const data = results && results.length > 0 ? results[0] : null;
|
|
155
|
-
const metadata = {
|
|
156
|
-
hasPendingWrites: false,
|
|
157
|
-
fromCache: false,
|
|
158
|
-
};
|
|
159
|
-
return new DocumentSnapshotImpl(reference.firestore, reference, data, metadata);
|
|
160
|
-
}
|
|
161
|
-
catch (error) {
|
|
162
|
-
throw createFirebaseError('firestore/internal', `Failed to get document: ${error}`);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* Get multiple documents from a query
|
|
167
|
-
*/
|
|
168
|
-
export async function getDocs(q, engine) {
|
|
169
|
-
if (!engine) {
|
|
170
|
-
// Mock query snapshot for tests
|
|
171
|
-
const query = q;
|
|
172
|
-
return {
|
|
173
|
-
docs: [],
|
|
174
|
-
size: 0,
|
|
175
|
-
empty: true,
|
|
176
|
-
metadata: { hasPendingWrites: false, fromCache: false },
|
|
177
|
-
forEach: () => { },
|
|
178
|
-
toJSON: () => ({ docs: [], size: 0, empty: true }),
|
|
179
|
-
};
|
|
180
|
-
}
|
|
181
|
-
try {
|
|
182
|
-
const query = q;
|
|
183
|
-
const compiled = compileQuery(query);
|
|
184
|
-
const results = await engine.execute(compiled.sql, compiled.params);
|
|
185
|
-
const metadata = {
|
|
186
|
-
hasPendingWrites: false,
|
|
187
|
-
fromCache: false,
|
|
188
|
-
};
|
|
189
|
-
// Create document snapshots
|
|
190
|
-
const docs = (results || []).map((data, index) => {
|
|
191
|
-
const docRef = new DocumentReferenceImpl(q.firestore, `${compiled.table}/${data.id || `doc_${index}`}`, new CollectionReferenceImpl(q.firestore, compiled.table));
|
|
192
|
-
return new DocumentSnapshotImpl(q.firestore, docRef, data, metadata);
|
|
193
|
-
});
|
|
194
|
-
return new QuerySnapshotImpl(q.firestore, q, docs, metadata);
|
|
195
|
-
}
|
|
196
|
-
catch (error) {
|
|
197
|
-
throw createFirebaseError('firestore/internal', `Failed to get documents: ${error}`);
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
/**
|
|
201
|
-
* Get document from local cache
|
|
202
|
-
*/
|
|
203
|
-
export async function getDocFromCache(reference, cache) {
|
|
204
|
-
const cached = cache?.get(reference.path);
|
|
205
|
-
const metadata = {
|
|
206
|
-
hasPendingWrites: false,
|
|
207
|
-
fromCache: true,
|
|
208
|
-
};
|
|
209
|
-
if (cached) {
|
|
210
|
-
return new DocumentSnapshotImpl(reference.firestore, reference, cached, metadata);
|
|
211
|
-
}
|
|
212
|
-
return new DocumentSnapshotImpl(reference.firestore, reference, null, metadata);
|
|
213
|
-
}
|
|
214
|
-
/**
|
|
215
|
-
* Get documents from local cache
|
|
216
|
-
*/
|
|
217
|
-
export async function getDocsFromCache(q, cache) {
|
|
218
|
-
const docs = [];
|
|
219
|
-
const metadata = {
|
|
220
|
-
hasPendingWrites: false,
|
|
221
|
-
fromCache: true,
|
|
222
|
-
};
|
|
223
|
-
if (cache) {
|
|
224
|
-
for (const [path, data] of cache.entries()) {
|
|
225
|
-
// Parse path to create document reference
|
|
226
|
-
const segments = path.split('/');
|
|
227
|
-
const collectionName = segments[segments.length - 2] || 'documents';
|
|
228
|
-
const docId = segments[segments.length - 1];
|
|
229
|
-
const ref = new DocumentReferenceImpl(q.firestore, path, new CollectionReferenceImpl(q.firestore, collectionName));
|
|
230
|
-
docs.push(new DocumentSnapshotImpl(q.firestore, ref, data, metadata));
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
return new QuerySnapshotImpl(q.firestore, q, docs, metadata);
|
|
234
|
-
}
|
|
235
|
-
/**
|
|
236
|
-
* Set document data (write)
|
|
237
|
-
*/
|
|
238
|
-
export async function setDoc(reference, data, options, engine) {
|
|
239
|
-
if (data === null) {
|
|
240
|
-
throw createFirebaseError('firestore/invalid-argument', 'Document data cannot be null.');
|
|
241
|
-
}
|
|
242
|
-
if (!engine) {
|
|
243
|
-
// Mock success for tests - store data and trigger listeners
|
|
244
|
-
if (!reference) {
|
|
245
|
-
throw createFirebaseError('firestore/invalid-argument', 'Document reference cannot be null.');
|
|
246
|
-
}
|
|
247
|
-
const ref = reference;
|
|
248
|
-
mockStorage.set(ref.path, data);
|
|
249
|
-
const key = `doc:${ref.path}`;
|
|
250
|
-
// Create a mock snapshot
|
|
251
|
-
const snapshot = {
|
|
252
|
-
id: ref.id,
|
|
253
|
-
ref: reference,
|
|
254
|
-
exists: true,
|
|
255
|
-
data: () => data,
|
|
256
|
-
get: (field) => data[field],
|
|
257
|
-
metadata: { hasPendingWrites: false, fromCache: false },
|
|
258
|
-
};
|
|
259
|
-
triggerMockListeners(key, snapshot);
|
|
260
|
-
return;
|
|
261
|
-
}
|
|
262
|
-
try {
|
|
263
|
-
const ref = reference;
|
|
264
|
-
const tableName = ref.parent.id || 'documents';
|
|
265
|
-
const docData = { id: ref.id, ...serializeFieldValue(data) };
|
|
266
|
-
if (options?.merge) {
|
|
267
|
-
// Update existing document
|
|
268
|
-
const setClauses = Object.keys(docData)
|
|
269
|
-
.filter(key => key !== 'id')
|
|
270
|
-
.map(key => `\`${key}\` = ?`)
|
|
271
|
-
.join(', ');
|
|
272
|
-
if (setClauses) {
|
|
273
|
-
const sql = `UPDATE \`${tableName}\` SET ${setClauses} WHERE id = ?`;
|
|
274
|
-
const values = Object.keys(docData)
|
|
275
|
-
.filter(key => key !== 'id')
|
|
276
|
-
.map(key => docData[key]);
|
|
277
|
-
values.push(ref.id);
|
|
278
|
-
await engine.execute(sql, values);
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
else {
|
|
282
|
-
// Insert or replace document
|
|
283
|
-
const columns = Object.keys(docData).join(', ');
|
|
284
|
-
const placeholders = Object.keys(docData)
|
|
285
|
-
.map(() => '?')
|
|
286
|
-
.join(', ');
|
|
287
|
-
const sql = `INSERT OR REPLACE INTO \`${tableName}\` (${columns}) VALUES (${placeholders})`;
|
|
288
|
-
const values = Object.values(docData);
|
|
289
|
-
await engine.execute(sql, values);
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
catch (error) {
|
|
293
|
-
throw createFirebaseError('firestore/internal', `Failed to set document: ${error}`);
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
/**
|
|
297
|
-
* Update document data (partial write)
|
|
298
|
-
*/
|
|
299
|
-
export async function updateDoc(reference, data, engine) {
|
|
300
|
-
if (!engine) {
|
|
301
|
-
// Mock success for tests - update stored data and trigger listeners
|
|
302
|
-
if (!reference) {
|
|
303
|
-
throw createFirebaseError('firestore/invalid-argument', 'Document reference cannot be null.');
|
|
304
|
-
}
|
|
305
|
-
const ref = reference;
|
|
306
|
-
const existing = mockStorage.get(ref.path) || {};
|
|
307
|
-
const updated = { ...existing, ...data };
|
|
308
|
-
mockStorage.set(ref.path, updated);
|
|
309
|
-
const key = `doc:${ref.path}`;
|
|
310
|
-
const snapshot = new DocumentSnapshotImpl(ref.firestore, reference, updated, { hasPendingWrites: false, fromCache: false });
|
|
311
|
-
triggerMockListeners(key, snapshot);
|
|
312
|
-
return;
|
|
313
|
-
}
|
|
314
|
-
try {
|
|
315
|
-
const ref = reference;
|
|
316
|
-
const tableName = ref.parent.id || 'documents';
|
|
317
|
-
const docData = serializeFieldValue(data);
|
|
318
|
-
const setClauses = Object.keys(docData)
|
|
319
|
-
.map(key => `\`${key}\` = ?`)
|
|
320
|
-
.join(', ');
|
|
321
|
-
if (!setClauses) {
|
|
322
|
-
throw createFirebaseError('firestore/invalid-argument', 'Update data must not be empty');
|
|
323
|
-
}
|
|
324
|
-
const sql = `UPDATE \`${tableName}\` SET ${setClauses} WHERE id = ?`;
|
|
325
|
-
const values = [...Object.values(docData), ref.id];
|
|
326
|
-
await engine.execute(sql, values);
|
|
327
|
-
}
|
|
328
|
-
catch (error) {
|
|
329
|
-
throw createFirebaseError('firestore/internal', `Failed to update document: ${error}`);
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
/**
|
|
333
|
-
* Delete document
|
|
334
|
-
*/
|
|
335
|
-
export async function deleteDoc(reference, engine) {
|
|
336
|
-
if (!engine) {
|
|
337
|
-
// Mock success for tests - remove data and trigger listeners
|
|
338
|
-
const ref = reference;
|
|
339
|
-
mockStorage.delete(ref.path);
|
|
340
|
-
const key = `doc:${ref.path}`;
|
|
341
|
-
const snapshot = new DocumentSnapshotImpl(ref.firestore, reference, null, { hasPendingWrites: false, fromCache: false });
|
|
342
|
-
triggerMockListeners(key, snapshot);
|
|
343
|
-
return;
|
|
344
|
-
}
|
|
345
|
-
try {
|
|
346
|
-
const ref = reference;
|
|
347
|
-
const tableName = ref.parent.id || 'documents';
|
|
348
|
-
const sql = `DELETE FROM \`${tableName}\` WHERE id = ?`;
|
|
349
|
-
await engine.execute(sql, [ref.id]);
|
|
350
|
-
}
|
|
351
|
-
catch (error) {
|
|
352
|
-
throw createFirebaseError('firestore/internal', `Failed to delete document: ${error}`);
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
/**
|
|
356
|
-
* Batch write operations
|
|
357
|
-
*/
|
|
358
|
-
export class WriteBatch {
|
|
359
|
-
_firestore;
|
|
360
|
-
_engine;
|
|
361
|
-
_writes = [];
|
|
362
|
-
constructor(firestore, engine) {
|
|
363
|
-
this._firestore = firestore;
|
|
364
|
-
this._engine = engine;
|
|
365
|
-
}
|
|
366
|
-
set(reference, data, options) {
|
|
367
|
-
this._writes.push({ type: 'set', ref: reference, data, options });
|
|
368
|
-
if (!this._engine) {
|
|
369
|
-
this.commit();
|
|
370
|
-
}
|
|
371
|
-
return this;
|
|
372
|
-
}
|
|
373
|
-
update(reference, data) {
|
|
374
|
-
this._writes.push({ type: 'update', ref: reference, data });
|
|
375
|
-
if (!this._engine) {
|
|
376
|
-
this.commit();
|
|
377
|
-
}
|
|
378
|
-
return this;
|
|
379
|
-
}
|
|
380
|
-
delete(reference) {
|
|
381
|
-
this._writes.push({ type: 'delete', ref: reference, data: null });
|
|
382
|
-
if (!this._engine) {
|
|
383
|
-
this.commit();
|
|
384
|
-
}
|
|
385
|
-
return this;
|
|
386
|
-
}
|
|
387
|
-
async commit() {
|
|
388
|
-
if (!this._engine) {
|
|
389
|
-
// Mock success for tests - execute writes
|
|
390
|
-
for (const write of this._writes) {
|
|
391
|
-
switch (write.type) {
|
|
392
|
-
case 'set':
|
|
393
|
-
const ref = write.ref;
|
|
394
|
-
mockStorage.set(ref.path, write.data);
|
|
395
|
-
triggerMockListeners(`doc:${ref.path}`, new DocumentSnapshotImpl(this._firestore, write.ref, write.data, { hasPendingWrites: false, fromCache: false }));
|
|
396
|
-
break;
|
|
397
|
-
case 'update':
|
|
398
|
-
const ref2 = write.ref;
|
|
399
|
-
const existing = mockStorage.get(ref2.path) || {};
|
|
400
|
-
const updated = { ...existing, ...write.data };
|
|
401
|
-
mockStorage.set(ref2.path, updated);
|
|
402
|
-
triggerMockListeners(`doc:${ref2.path}`, new DocumentSnapshotImpl(this._firestore, write.ref, updated, { hasPendingWrites: false, fromCache: false }));
|
|
403
|
-
break;
|
|
404
|
-
case 'delete':
|
|
405
|
-
const ref3 = write.ref;
|
|
406
|
-
mockStorage.delete(ref3.path);
|
|
407
|
-
triggerMockListeners(`doc:${ref3.path}`, new DocumentSnapshotImpl(this._firestore, write.ref, null, { hasPendingWrites: false, fromCache: false }));
|
|
408
|
-
break;
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
return;
|
|
412
|
-
}
|
|
413
|
-
try {
|
|
414
|
-
// Execute all writes in a transaction
|
|
415
|
-
for (const write of this._writes) {
|
|
416
|
-
switch (write.type) {
|
|
417
|
-
case 'set':
|
|
418
|
-
await setDoc(write.ref, write.data, write.options, this._engine);
|
|
419
|
-
break;
|
|
420
|
-
case 'update':
|
|
421
|
-
await updateDoc(write.ref, write.data, this._engine);
|
|
422
|
-
break;
|
|
423
|
-
case 'delete':
|
|
424
|
-
await deleteDoc(write.ref, this._engine);
|
|
425
|
-
break;
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
catch (error) {
|
|
430
|
-
throw createFirebaseError('firestore/internal', `Batch commit failed: ${error}`);
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
/**
|
|
435
|
-
* Create a write batch
|
|
436
|
-
*/
|
|
437
|
-
export function writeBatch(firestore, engine) {
|
|
438
|
-
if (!engine) {
|
|
439
|
-
// Mock batch for tests
|
|
440
|
-
return new WriteBatch(firestore, null);
|
|
441
|
-
}
|
|
442
|
-
return new WriteBatch(firestore, engine);
|
|
443
|
-
}
|
|
444
|
-
/**
|
|
445
|
-
* Run a transaction
|
|
446
|
-
*/
|
|
447
|
-
export async function runTransaction(firestore, updateFunction, engine) {
|
|
448
|
-
if (!engine) {
|
|
449
|
-
// Mock transaction for tests - just call the function with a mock tx
|
|
450
|
-
const tx = new Transaction(firestore, null);
|
|
451
|
-
return await updateFunction(tx);
|
|
452
|
-
}
|
|
453
|
-
const tx = new Transaction(firestore, engine);
|
|
454
|
-
try {
|
|
455
|
-
return await updateFunction(tx);
|
|
456
|
-
}
|
|
457
|
-
catch (error) {
|
|
458
|
-
throw createFirebaseError('firestore/internal', `Transaction failed: ${error}`);
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
/**
|
|
462
|
-
* Transaction object for transactional reads and writes
|
|
463
|
-
*/
|
|
464
|
-
export class Transaction {
|
|
465
|
-
_firestore;
|
|
466
|
-
_engine;
|
|
467
|
-
constructor(firestore, engine) {
|
|
468
|
-
this._firestore = firestore;
|
|
469
|
-
this._engine = engine;
|
|
470
|
-
}
|
|
471
|
-
async get(reference) {
|
|
472
|
-
return getDoc(reference, this._engine);
|
|
473
|
-
}
|
|
474
|
-
async set(reference, data, options) {
|
|
475
|
-
await setDoc(reference, data, options, this._engine);
|
|
476
|
-
}
|
|
477
|
-
async update(reference, data) {
|
|
478
|
-
await updateDoc(reference, data, this._engine);
|
|
479
|
-
}
|
|
480
|
-
async delete(reference) {
|
|
481
|
-
await deleteDoc(reference, this._engine);
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
/**
|
|
485
|
-
* Listen for document/query changes
|
|
486
|
-
*/
|
|
487
|
-
export function onSnapshot(reference, observer, options) {
|
|
488
|
-
// Mock implementation - return unsubscribe function
|
|
489
|
-
return () => { };
|
|
490
|
-
}
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Firestore query interface and SQL compiler
|
|
3
|
-
*/
|
|
4
|
-
import type { Query as IQuery, CollectionReference as ICollectionReference, DocumentReference as IDocumentReference, QueryConstraint, WhereFilterOp, Firestore, DocumentData } from '../types.js';
|
|
5
|
-
export type FieldPath = string | string[];
|
|
6
|
-
export interface CompiledQuery {
|
|
7
|
-
table: string;
|
|
8
|
-
sql: string;
|
|
9
|
-
params: any[];
|
|
10
|
-
constraints: QueryConstraint[];
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Field path helper for nested fields
|
|
14
|
-
*/
|
|
15
|
-
export declare class FieldPathClass {
|
|
16
|
-
_segments: string[];
|
|
17
|
-
constructor(...segments: string[]);
|
|
18
|
-
static documentId(): FieldPathClass;
|
|
19
|
-
toString(): string;
|
|
20
|
-
isEqual(other: FieldPathClass): boolean;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Base Query class
|
|
24
|
-
*/
|
|
25
|
-
export declare class QueryImpl<T = DocumentData> implements IQuery<T> {
|
|
26
|
-
firestore: Firestore;
|
|
27
|
-
_query: QueryConstraint[];
|
|
28
|
-
type: 'query';
|
|
29
|
-
constructor(firestore: Firestore, constraints?: QueryConstraint[]);
|
|
30
|
-
_addConstraint(constraint: QueryConstraint): QueryImpl<T>;
|
|
31
|
-
toJSON(): string;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Document reference class
|
|
35
|
-
*/
|
|
36
|
-
export declare class DocumentReferenceImpl<T = DocumentData> implements IDocumentReference<T> {
|
|
37
|
-
firestore: Firestore;
|
|
38
|
-
_key: string;
|
|
39
|
-
parent: CollectionReferenceImpl<T>;
|
|
40
|
-
id: string;
|
|
41
|
-
path: string;
|
|
42
|
-
type: 'document';
|
|
43
|
-
constructor(firestore: Firestore, path: string, parent: CollectionReferenceImpl<T>);
|
|
44
|
-
toJSON(): string;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Collection reference class
|
|
48
|
-
*/
|
|
49
|
-
export declare class CollectionReferenceImpl<T = DocumentData> implements ICollectionReference<T> {
|
|
50
|
-
firestore: Firestore;
|
|
51
|
-
_key: string;
|
|
52
|
-
path: string;
|
|
53
|
-
id: string;
|
|
54
|
-
parent: DocumentReferenceImpl<DocumentData> | null;
|
|
55
|
-
type: 'collection';
|
|
56
|
-
_query: QueryConstraint[];
|
|
57
|
-
constructor(firestore: Firestore, path: string, parent?: DocumentReferenceImpl<DocumentData> | null);
|
|
58
|
-
_addConstraint(constraint: QueryConstraint): QueryImpl<T>;
|
|
59
|
-
toJSON(): string;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Create a collection reference
|
|
63
|
-
*/
|
|
64
|
-
export declare function collection(firestore: Firestore, path: string): CollectionReferenceImpl;
|
|
65
|
-
/**
|
|
66
|
-
* Create a document reference
|
|
67
|
-
*/
|
|
68
|
-
export declare function doc(firestore: Firestore, path: string): DocumentReferenceImpl;
|
|
69
|
-
export declare function doc(firestore: Firestore, collectionPath: string, documentId: string): DocumentReferenceImpl;
|
|
70
|
-
export declare function doc(reference: CollectionReferenceImpl, documentId?: string): DocumentReferenceImpl;
|
|
71
|
-
/**
|
|
72
|
-
* Build a where constraint
|
|
73
|
-
*/
|
|
74
|
-
export declare function where(field: string | FieldPathClass, operator: WhereFilterOp, value: any): QueryConstraint;
|
|
75
|
-
/**
|
|
76
|
-
* Build an orderBy constraint
|
|
77
|
-
*/
|
|
78
|
-
export declare function orderBy(field: string | FieldPathClass, direction?: 'asc' | 'desc'): QueryConstraint;
|
|
79
|
-
/**
|
|
80
|
-
* Build a limit constraint
|
|
81
|
-
*/
|
|
82
|
-
export declare function limit(n: number): QueryConstraint;
|
|
83
|
-
/**
|
|
84
|
-
* Build a limitToLast constraint
|
|
85
|
-
*/
|
|
86
|
-
export declare function limitToLast(n: number): QueryConstraint;
|
|
87
|
-
/**
|
|
88
|
-
* Build a startAt constraint
|
|
89
|
-
*/
|
|
90
|
-
export declare function startAt(...values: any[]): QueryConstraint;
|
|
91
|
-
/**
|
|
92
|
-
* Build a startAfter constraint
|
|
93
|
-
*/
|
|
94
|
-
export declare function startAfter(...values: any[]): QueryConstraint;
|
|
95
|
-
/**
|
|
96
|
-
* Build an endAt constraint
|
|
97
|
-
*/
|
|
98
|
-
export declare function endAt(...values: any[]): QueryConstraint;
|
|
99
|
-
/**
|
|
100
|
-
* Build an endBefore constraint
|
|
101
|
-
*/
|
|
102
|
-
export declare function endBefore(...values: any[]): QueryConstraint;
|
|
103
|
-
/**
|
|
104
|
-
* Build an offset constraint
|
|
105
|
-
*/
|
|
106
|
-
export declare function offset(n: number): QueryConstraint;
|
|
107
|
-
/**
|
|
108
|
-
* Create a new query by combining base query with constraints
|
|
109
|
-
*/
|
|
110
|
-
export declare function query<T = DocumentData>(base: CollectionReferenceImpl<T> | QueryImpl<T>, ...constraints: QueryConstraint[]): QueryImpl<T>;
|
|
111
|
-
/**
|
|
112
|
-
* Get table name from path
|
|
113
|
-
*/
|
|
114
|
-
export declare function getTableFromPath(path: string): string;
|
|
115
|
-
/**
|
|
116
|
-
* Compile a query to SQL
|
|
117
|
-
*/
|
|
118
|
-
export declare function compileQuery(q: QueryImpl, collectionPath?: string): CompiledQuery;
|