@delma/fylo 2.0.1 → 2.1.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 +206 -261
- package/dist/adapters/cipher.js +155 -0
- package/dist/adapters/cipher.js.map +1 -0
- package/dist/core/collection.js +6 -0
- package/dist/core/collection.js.map +1 -0
- package/dist/core/directory.js +48 -0
- package/dist/core/directory.js.map +1 -0
- package/dist/core/doc-id.js +15 -0
- package/dist/core/doc-id.js.map +1 -0
- package/dist/core/extensions.js +16 -0
- package/dist/core/extensions.js.map +1 -0
- package/dist/core/format.js +355 -0
- package/dist/core/format.js.map +1 -0
- package/dist/core/parser.js +764 -0
- package/dist/core/parser.js.map +1 -0
- package/dist/core/query.js +47 -0
- package/dist/core/query.js.map +1 -0
- package/dist/engines/s3-files/documents.js +62 -0
- package/dist/engines/s3-files/documents.js.map +1 -0
- package/dist/engines/s3-files/filesystem.js +165 -0
- package/dist/engines/s3-files/filesystem.js.map +1 -0
- package/dist/engines/s3-files/query.js +235 -0
- package/dist/engines/s3-files/query.js.map +1 -0
- package/dist/engines/s3-files/types.js +2 -0
- package/dist/engines/s3-files/types.js.map +1 -0
- package/dist/engines/s3-files.js +629 -0
- package/dist/engines/s3-files.js.map +1 -0
- package/dist/engines/types.js +2 -0
- package/dist/engines/types.js.map +1 -0
- package/dist/index.js +562 -0
- package/dist/index.js.map +1 -0
- package/dist/sync.js +18 -0
- package/dist/sync.js.map +1 -0
- package/dist/types/fylo.d.ts +179 -0
- package/{src → dist}/types/node-runtime.d.ts +1 -0
- package/package.json +3 -6
- package/.env.example +0 -16
- package/.github/copilot-instructions.md +0 -3
- package/.github/prompts/release.prompt.md +0 -10
- package/.github/workflows/ci.yml +0 -37
- package/.github/workflows/publish.yml +0 -91
- package/.prettierrc +0 -7
- package/AGENTS.md +0 -3
- package/CLAUDE.md +0 -3
- package/eslint.config.js +0 -32
- package/src/CLI +0 -39
- package/src/adapters/cipher.ts +0 -180
- package/src/adapters/redis.ts +0 -487
- package/src/adapters/s3.ts +0 -61
- package/src/core/collection.ts +0 -5
- package/src/core/directory.ts +0 -387
- package/src/core/extensions.ts +0 -21
- package/src/core/format.ts +0 -457
- package/src/core/parser.ts +0 -901
- package/src/core/query.ts +0 -53
- package/src/core/walker.ts +0 -174
- package/src/core/write-queue.ts +0 -59
- package/src/engines/s3-files.ts +0 -1068
- package/src/engines/types.ts +0 -21
- package/src/index.ts +0 -1727
- package/src/migrate-cli.ts +0 -22
- package/src/migrate.ts +0 -74
- package/src/types/fylo.d.ts +0 -261
- package/src/types/write-queue.ts +0 -42
- package/src/worker.ts +0 -18
- package/src/workers/write-worker.ts +0 -120
- package/tests/collection/truncate.test.js +0 -35
- package/tests/data.js +0 -97
- package/tests/index.js +0 -14
- package/tests/integration/aws-s3-files.canary.test.js +0 -22
- package/tests/integration/create.test.js +0 -39
- package/tests/integration/delete.test.js +0 -95
- package/tests/integration/edge-cases.test.js +0 -158
- package/tests/integration/encryption.test.js +0 -131
- package/tests/integration/export.test.js +0 -46
- package/tests/integration/join-modes.test.js +0 -154
- package/tests/integration/migration.test.js +0 -38
- package/tests/integration/nested.test.js +0 -142
- package/tests/integration/operators.test.js +0 -122
- package/tests/integration/queue.test.js +0 -83
- package/tests/integration/read.test.js +0 -119
- package/tests/integration/rollback.test.js +0 -60
- package/tests/integration/s3-files.test.js +0 -192
- package/tests/integration/update.test.js +0 -99
- package/tests/mocks/cipher.js +0 -40
- package/tests/mocks/redis.js +0 -123
- package/tests/mocks/s3.js +0 -80
- package/tests/schemas/album.d.ts +0 -5
- package/tests/schemas/album.json +0 -5
- package/tests/schemas/comment.d.ts +0 -7
- package/tests/schemas/comment.json +0 -7
- package/tests/schemas/photo.d.ts +0 -7
- package/tests/schemas/photo.json +0 -7
- package/tests/schemas/post.d.ts +0 -6
- package/tests/schemas/post.json +0 -6
- package/tests/schemas/tip.d.ts +0 -7
- package/tests/schemas/tip.json +0 -7
- package/tests/schemas/todo.d.ts +0 -6
- package/tests/schemas/todo.json +0 -6
- package/tests/schemas/user.d.ts +0 -23
- package/tests/schemas/user.json +0 -23
- package/tsconfig.json +0 -21
- package/tsconfig.typecheck.json +0 -31
- /package/{src → dist}/types/bun-runtime.d.ts +0 -0
- /package/{src → dist}/types/index.d.ts +0 -0
- /package/{src → dist}/types/query.d.ts +0 -0
- /package/{src → dist}/types/vendor-modules.d.ts +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/engines/types.ts"],"names":[],"mappings":""}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,562 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
|
2
|
+
import { lookup } from 'node:dns/promises';
|
|
3
|
+
import { readFile } from 'node:fs/promises';
|
|
4
|
+
import { isIP } from 'node:net';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import { Parser } from './core/parser';
|
|
7
|
+
import TTID from '@delma/ttid';
|
|
8
|
+
import Gen from '@delma/chex';
|
|
9
|
+
import { Cipher } from './adapters/cipher';
|
|
10
|
+
import { S3FilesEngine } from './engines/s3-files';
|
|
11
|
+
import { validateDocId } from './core/doc-id';
|
|
12
|
+
import './core/format';
|
|
13
|
+
import './core/extensions';
|
|
14
|
+
export { FyloSyncError } from './sync';
|
|
15
|
+
export default class Fylo {
|
|
16
|
+
static LOGGING = process.env.LOGGING;
|
|
17
|
+
static MAX_CPUS = navigator.hardwareConcurrency;
|
|
18
|
+
static STRICT = process.env.STRICT;
|
|
19
|
+
static ttidLock = Promise.resolve();
|
|
20
|
+
static DEFAULT_IMPORT_MAX_BYTES = 50 * 1024 * 1024;
|
|
21
|
+
/** Collections whose schema `$encrypted` config has already been loaded. */
|
|
22
|
+
static loadedEncryption = new Set();
|
|
23
|
+
engine;
|
|
24
|
+
constructor(options = {}) {
|
|
25
|
+
this.engine = new S3FilesEngine(options.root ?? options.s3FilesRoot ?? Fylo.defaultRoot(), {
|
|
26
|
+
sync: options.sync,
|
|
27
|
+
syncMode: options.syncMode
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
static defaultRoot() {
|
|
31
|
+
return (process.env.FYLO_ROOT ??
|
|
32
|
+
process.env.FYLO_S3FILES_ROOT ??
|
|
33
|
+
path.join(process.cwd(), '.fylo-data'));
|
|
34
|
+
}
|
|
35
|
+
static get defaultEngine() {
|
|
36
|
+
return new S3FilesEngine(Fylo.defaultRoot());
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Executes a SQL query and returns the results.
|
|
40
|
+
* @param SQL The SQL query to execute.
|
|
41
|
+
* @returns The results of the query.
|
|
42
|
+
*/
|
|
43
|
+
async executeSQL(SQL) {
|
|
44
|
+
const op = SQL.match(/^(SELECT|INSERT|UPDATE|DELETE|CREATE|DROP)/i);
|
|
45
|
+
if (!op)
|
|
46
|
+
throw new Error('Missing SQL Operation');
|
|
47
|
+
switch (op.shift()) {
|
|
48
|
+
case 'CREATE':
|
|
49
|
+
return await this.createCollection(Parser.parse(SQL).$collection);
|
|
50
|
+
case 'DROP':
|
|
51
|
+
return await this.dropCollection(Parser.parse(SQL).$collection);
|
|
52
|
+
case 'SELECT': {
|
|
53
|
+
const query = Parser.parse(SQL);
|
|
54
|
+
if (SQL.includes('JOIN'))
|
|
55
|
+
return await this.joinDocs(query);
|
|
56
|
+
const selCol = query.$collection;
|
|
57
|
+
delete query.$collection;
|
|
58
|
+
let docs = query.$onlyIds ? [] : {};
|
|
59
|
+
for await (const data of this.findDocs(selCol, query).collect()) {
|
|
60
|
+
if (typeof data === 'object')
|
|
61
|
+
docs = Object.appendGroup(docs, data);
|
|
62
|
+
else
|
|
63
|
+
docs.push(data);
|
|
64
|
+
}
|
|
65
|
+
return docs;
|
|
66
|
+
}
|
|
67
|
+
case 'INSERT': {
|
|
68
|
+
const insert = Parser.parse(SQL);
|
|
69
|
+
const insCol = insert.$collection;
|
|
70
|
+
delete insert.$collection;
|
|
71
|
+
return await this.putData(insCol, insert.$values);
|
|
72
|
+
}
|
|
73
|
+
case 'UPDATE': {
|
|
74
|
+
const update = Parser.parse(SQL);
|
|
75
|
+
const updateCol = update.$collection;
|
|
76
|
+
delete update.$collection;
|
|
77
|
+
return await this.patchDocs(updateCol, update);
|
|
78
|
+
}
|
|
79
|
+
case 'DELETE': {
|
|
80
|
+
const del = Parser.parse(SQL);
|
|
81
|
+
const delCol = del.$collection;
|
|
82
|
+
delete del.$collection;
|
|
83
|
+
return await this.delDocs(delCol, del);
|
|
84
|
+
}
|
|
85
|
+
default:
|
|
86
|
+
throw new Error('Invalid Operation');
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Creates a new collection on the configured filesystem root.
|
|
91
|
+
* @param collection The name of the collection.
|
|
92
|
+
*/
|
|
93
|
+
static async createCollection(collection) {
|
|
94
|
+
await Fylo.defaultEngine.createCollection(collection);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Drops an existing collection from the configured filesystem root.
|
|
98
|
+
* @param collection The name of the collection.
|
|
99
|
+
*/
|
|
100
|
+
static async dropCollection(collection) {
|
|
101
|
+
await Fylo.defaultEngine.dropCollection(collection);
|
|
102
|
+
}
|
|
103
|
+
async createCollection(collection) {
|
|
104
|
+
return await this.engine.createCollection(collection);
|
|
105
|
+
}
|
|
106
|
+
async dropCollection(collection) {
|
|
107
|
+
return await this.engine.dropCollection(collection);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Loads encrypted field config from a collection's JSON schema if not already loaded.
|
|
111
|
+
* Reads the `$encrypted` array from the schema and registers fields with Cipher.
|
|
112
|
+
* Auto-configures the Cipher key from `ENCRYPTION_KEY` env var on first use.
|
|
113
|
+
*/
|
|
114
|
+
static async loadEncryption(collection) {
|
|
115
|
+
if (Fylo.loadedEncryption.has(collection))
|
|
116
|
+
return;
|
|
117
|
+
const schemaDir = process.env.SCHEMA_DIR;
|
|
118
|
+
if (!schemaDir) {
|
|
119
|
+
Fylo.loadedEncryption.add(collection);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
const schemaPath = path.join(schemaDir, `${collection}.json`);
|
|
123
|
+
let schema;
|
|
124
|
+
try {
|
|
125
|
+
schema = JSON.parse(await readFile(schemaPath, 'utf8'));
|
|
126
|
+
}
|
|
127
|
+
catch (err) {
|
|
128
|
+
if (err.code === 'ENOENT') {
|
|
129
|
+
Fylo.loadedEncryption.add(collection);
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
throw err;
|
|
133
|
+
}
|
|
134
|
+
const encrypted = schema.$encrypted;
|
|
135
|
+
if (encrypted !== undefined && !Array.isArray(encrypted))
|
|
136
|
+
throw new Error(`Schema $encrypted for ${collection} must be an array of field names`);
|
|
137
|
+
if (Array.isArray(encrypted) && encrypted.length > 0) {
|
|
138
|
+
if (!encrypted.every((field) => typeof field === 'string' && field.length > 0))
|
|
139
|
+
throw new Error(`Schema $encrypted for ${collection} must only contain strings`);
|
|
140
|
+
if (!Cipher.isConfigured()) {
|
|
141
|
+
const secret = process.env.ENCRYPTION_KEY;
|
|
142
|
+
if (!secret)
|
|
143
|
+
throw new Error('Schema declares $encrypted fields but ENCRYPTION_KEY env var is not set');
|
|
144
|
+
if (secret.length < 32)
|
|
145
|
+
throw new Error('ENCRYPTION_KEY must be at least 32 characters long');
|
|
146
|
+
await Cipher.configure(secret);
|
|
147
|
+
}
|
|
148
|
+
Cipher.registerFields(collection, encrypted);
|
|
149
|
+
}
|
|
150
|
+
Fylo.loadedEncryption.add(collection);
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Compatibility helper. FYLO now writes synchronously to the filesystem,
|
|
154
|
+
* so there is no queued transactional rollback path to execute.
|
|
155
|
+
*/
|
|
156
|
+
async rollback() { }
|
|
157
|
+
getDoc(collection, _id, onlyId = false) {
|
|
158
|
+
validateDocId(_id);
|
|
159
|
+
return this.engine.getDoc(collection, _id, onlyId);
|
|
160
|
+
}
|
|
161
|
+
findDocs(collection, query) {
|
|
162
|
+
return this.engine.findDocs(collection, query);
|
|
163
|
+
}
|
|
164
|
+
async joinDocs(join) {
|
|
165
|
+
return await this.engine.joinDocs(join);
|
|
166
|
+
}
|
|
167
|
+
async *exportBulkData(collection) {
|
|
168
|
+
yield* this.engine.exportBulkData(collection);
|
|
169
|
+
}
|
|
170
|
+
unsupportedLegacyApi(feature) {
|
|
171
|
+
throw new Error(`${feature} was removed. FYLO now writes synchronously to the filesystem and expects external sync tooling for cloud replication.`);
|
|
172
|
+
}
|
|
173
|
+
async getJobStatus(_jobId) {
|
|
174
|
+
return this.unsupportedLegacyApi('getJobStatus');
|
|
175
|
+
}
|
|
176
|
+
async getDocStatus(_collection, _docId) {
|
|
177
|
+
return this.unsupportedLegacyApi('getDocStatus');
|
|
178
|
+
}
|
|
179
|
+
async getDeadLetters(_count = 10) {
|
|
180
|
+
return this.unsupportedLegacyApi('getDeadLetters');
|
|
181
|
+
}
|
|
182
|
+
async getQueueStats() {
|
|
183
|
+
return this.unsupportedLegacyApi('getQueueStats');
|
|
184
|
+
}
|
|
185
|
+
async replayDeadLetter(_streamId) {
|
|
186
|
+
return this.unsupportedLegacyApi('replayDeadLetter');
|
|
187
|
+
}
|
|
188
|
+
async processQueuedWrites(_count = 1, _recover = false) {
|
|
189
|
+
return this.unsupportedLegacyApi('processQueuedWrites');
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Imports data from a URL into a collection.
|
|
193
|
+
* @param collection The name of the collection.
|
|
194
|
+
* @param url The URL of the data to import.
|
|
195
|
+
* @param limit The maximum number of documents to import.
|
|
196
|
+
*/
|
|
197
|
+
static normalizeImportOptions(limitOrOptions) {
|
|
198
|
+
const options = typeof limitOrOptions === 'number' ? { limit: limitOrOptions } : limitOrOptions;
|
|
199
|
+
return {
|
|
200
|
+
limit: options?.limit,
|
|
201
|
+
maxBytes: options?.maxBytes ?? Fylo.DEFAULT_IMPORT_MAX_BYTES,
|
|
202
|
+
allowedProtocols: options?.allowedProtocols ?? ['https:', 'http:', 'data:'],
|
|
203
|
+
allowedHosts: options?.allowedHosts,
|
|
204
|
+
allowPrivateNetwork: options?.allowPrivateNetwork ?? false
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
static isPrivateAddress(address) {
|
|
208
|
+
const normalized = address
|
|
209
|
+
.toLowerCase()
|
|
210
|
+
.replace(/^\[|\]$/g, '')
|
|
211
|
+
.split('%')[0];
|
|
212
|
+
const ipv4 = normalized.startsWith('::ffff:')
|
|
213
|
+
? normalized.slice('::ffff:'.length)
|
|
214
|
+
: normalized;
|
|
215
|
+
if (isIP(ipv4) === 4) {
|
|
216
|
+
const [first = 0, second = 0] = ipv4.split('.').map((part) => Number(part));
|
|
217
|
+
return (first === 0 ||
|
|
218
|
+
first === 10 ||
|
|
219
|
+
first === 127 ||
|
|
220
|
+
(first === 169 && second === 254) ||
|
|
221
|
+
(first === 172 && second >= 16 && second <= 31) ||
|
|
222
|
+
(first === 192 && second === 168) ||
|
|
223
|
+
(first === 100 && second >= 64 && second <= 127));
|
|
224
|
+
}
|
|
225
|
+
if (isIP(normalized) === 6) {
|
|
226
|
+
if (normalized === '::1' || normalized === '::')
|
|
227
|
+
return true;
|
|
228
|
+
const firstSegment = Number.parseInt(normalized.split(':')[0] || '0', 16);
|
|
229
|
+
return (firstSegment & 0xfe00) === 0xfc00 || (firstSegment & 0xffc0) === 0xfe80;
|
|
230
|
+
}
|
|
231
|
+
return false;
|
|
232
|
+
}
|
|
233
|
+
static hostAllowed(hostname, allowedHosts) {
|
|
234
|
+
if (!allowedHosts?.length)
|
|
235
|
+
return true;
|
|
236
|
+
const host = hostname.toLowerCase();
|
|
237
|
+
return allowedHosts.some((allowed) => {
|
|
238
|
+
const candidate = allowed.toLowerCase();
|
|
239
|
+
return host === candidate || host.endsWith(`.${candidate}`);
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
static async assertImportUrlAllowed(url, options) {
|
|
243
|
+
if (!options.allowedProtocols.includes(url.protocol))
|
|
244
|
+
throw new Error(`Import URL protocol is not allowed: ${url.protocol}`);
|
|
245
|
+
if (url.protocol !== 'http:' && url.protocol !== 'https:')
|
|
246
|
+
return;
|
|
247
|
+
if (!Fylo.hostAllowed(url.hostname, options.allowedHosts))
|
|
248
|
+
throw new Error(`Import URL host is not allowed: ${url.hostname}`);
|
|
249
|
+
if (options.allowPrivateNetwork)
|
|
250
|
+
return;
|
|
251
|
+
const hostname = url.hostname.toLowerCase();
|
|
252
|
+
if (hostname === 'localhost' || hostname.endsWith('.localhost'))
|
|
253
|
+
throw new Error(`Import URL resolves to a private address: ${url.hostname}`);
|
|
254
|
+
const addresses = isIP(hostname) === 0
|
|
255
|
+
? (await lookup(hostname, { all: true })).map((result) => result.address)
|
|
256
|
+
: [hostname];
|
|
257
|
+
if (addresses.some((address) => Fylo.isPrivateAddress(address)))
|
|
258
|
+
throw new Error(`Import URL resolves to a private address: ${url.hostname}`);
|
|
259
|
+
}
|
|
260
|
+
async importBulkData(collection, url, limitOrOptions) {
|
|
261
|
+
const importOptions = Fylo.normalizeImportOptions(limitOrOptions);
|
|
262
|
+
const limit = importOptions.limit;
|
|
263
|
+
if (limit !== undefined && limit <= 0)
|
|
264
|
+
return 0;
|
|
265
|
+
await Fylo.assertImportUrlAllowed(url, importOptions);
|
|
266
|
+
const res = await fetch(url);
|
|
267
|
+
if (!res.ok)
|
|
268
|
+
throw new Error(`Import request failed with status ${res.status}`);
|
|
269
|
+
if (!res.headers.get('content-type')?.includes('application/json'))
|
|
270
|
+
throw new Error('Response is not JSON');
|
|
271
|
+
if (!res.body)
|
|
272
|
+
throw new Error('Response body is empty');
|
|
273
|
+
let count = 0;
|
|
274
|
+
let batchNum = 0;
|
|
275
|
+
const flush = async (batch) => {
|
|
276
|
+
if (!batch.length)
|
|
277
|
+
return;
|
|
278
|
+
const items = limit !== undefined && count + batch.length > limit
|
|
279
|
+
? batch.slice(0, limit - count)
|
|
280
|
+
: batch;
|
|
281
|
+
if (!items.length)
|
|
282
|
+
return;
|
|
283
|
+
batchNum++;
|
|
284
|
+
const start = Date.now();
|
|
285
|
+
await this.batchPutData(collection, items);
|
|
286
|
+
count += items.length;
|
|
287
|
+
if (count % 10000 === 0)
|
|
288
|
+
console.log('Count:', count);
|
|
289
|
+
if (Fylo.LOGGING) {
|
|
290
|
+
const bytes = JSON.stringify(items).length;
|
|
291
|
+
const elapsed = Date.now() - start;
|
|
292
|
+
const bytesPerSec = (bytes / (elapsed / 1000)).toFixed(2);
|
|
293
|
+
console.log(`Batch ${batchNum} of ${bytes} bytes took ${elapsed === Infinity ? 'Infinity' : elapsed}ms (${bytesPerSec} bytes/sec)`);
|
|
294
|
+
}
|
|
295
|
+
};
|
|
296
|
+
let isJsonArray = null;
|
|
297
|
+
const jsonArrayChunks = [];
|
|
298
|
+
let jsonArrayLength = 0;
|
|
299
|
+
let pending = new Uint8Array(0);
|
|
300
|
+
let batch = [];
|
|
301
|
+
let totalBytes = 0;
|
|
302
|
+
for await (const chunk of res.body) {
|
|
303
|
+
totalBytes += chunk.length;
|
|
304
|
+
if (totalBytes > importOptions.maxBytes)
|
|
305
|
+
throw new Error(`Import response exceeded ${importOptions.maxBytes} bytes`);
|
|
306
|
+
if (isJsonArray === null)
|
|
307
|
+
isJsonArray = chunk[0] === 0x5b;
|
|
308
|
+
if (isJsonArray) {
|
|
309
|
+
jsonArrayChunks.push(chunk);
|
|
310
|
+
jsonArrayLength += chunk.length;
|
|
311
|
+
continue;
|
|
312
|
+
}
|
|
313
|
+
const merged = new Uint8Array(pending.length + chunk.length);
|
|
314
|
+
merged.set(pending);
|
|
315
|
+
merged.set(chunk, pending.length);
|
|
316
|
+
const { values, read } = Bun.JSONL.parseChunk(merged);
|
|
317
|
+
pending = merged.subarray(read);
|
|
318
|
+
for (const item of values) {
|
|
319
|
+
batch.push(item);
|
|
320
|
+
if (batch.length === Fylo.MAX_CPUS) {
|
|
321
|
+
await flush(batch);
|
|
322
|
+
batch = [];
|
|
323
|
+
if (limit !== undefined && count >= limit)
|
|
324
|
+
return count;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
if (isJsonArray) {
|
|
329
|
+
const body = new Uint8Array(jsonArrayLength);
|
|
330
|
+
let offset = 0;
|
|
331
|
+
for (const c of jsonArrayChunks) {
|
|
332
|
+
body.set(c, offset);
|
|
333
|
+
offset += c.length;
|
|
334
|
+
}
|
|
335
|
+
const data = JSON.parse(new TextDecoder().decode(body));
|
|
336
|
+
const items = Array.isArray(data) ? data : [data];
|
|
337
|
+
for (let i = 0; i < items.length; i += Fylo.MAX_CPUS) {
|
|
338
|
+
if (limit !== undefined && count >= limit)
|
|
339
|
+
break;
|
|
340
|
+
await flush(items.slice(i, i + Fylo.MAX_CPUS));
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
else {
|
|
344
|
+
if (pending.length > 0) {
|
|
345
|
+
const { values } = Bun.JSONL.parseChunk(pending);
|
|
346
|
+
for (const item of values)
|
|
347
|
+
batch.push(item);
|
|
348
|
+
}
|
|
349
|
+
if (batch.length > 0)
|
|
350
|
+
await flush(batch);
|
|
351
|
+
}
|
|
352
|
+
return count;
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Gets an exported stream of documents from a collection.
|
|
356
|
+
*/
|
|
357
|
+
static async *exportBulkData(collection) {
|
|
358
|
+
yield* Fylo.defaultEngine.exportBulkData(collection);
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* Gets a document from a collection.
|
|
362
|
+
* @param collection The name of the collection.
|
|
363
|
+
* @param _id The ID of the document.
|
|
364
|
+
* @param onlyId Whether to only return the ID of the document.
|
|
365
|
+
* @returns The document or the ID of the document.
|
|
366
|
+
*/
|
|
367
|
+
static getDoc(collection, _id, onlyId = false) {
|
|
368
|
+
validateDocId(_id);
|
|
369
|
+
return Fylo.defaultEngine.getDoc(collection, _id, onlyId);
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Puts multiple documents into a collection.
|
|
373
|
+
* @param collection The name of the collection.
|
|
374
|
+
* @param batch The documents to put.
|
|
375
|
+
* @returns The IDs of the documents.
|
|
376
|
+
*/
|
|
377
|
+
async batchPutData(collection, batch) {
|
|
378
|
+
const batches = [];
|
|
379
|
+
const ids = [];
|
|
380
|
+
if (batch.length > navigator.hardwareConcurrency) {
|
|
381
|
+
for (let i = 0; i < batch.length; i += navigator.hardwareConcurrency) {
|
|
382
|
+
batches.push(batch.slice(i, i + navigator.hardwareConcurrency));
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
else
|
|
386
|
+
batches.push(batch);
|
|
387
|
+
for (const itemBatch of batches) {
|
|
388
|
+
const res = await Promise.allSettled(itemBatch.map((data) => this.putData(collection, data)));
|
|
389
|
+
for (const _id of res
|
|
390
|
+
.filter((item) => item.status === 'fulfilled')
|
|
391
|
+
.map((item) => item.value)) {
|
|
392
|
+
ids.push(_id);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
return ids;
|
|
396
|
+
}
|
|
397
|
+
async queuePutData(_collection, _data) {
|
|
398
|
+
return this.unsupportedLegacyApi('queuePutData');
|
|
399
|
+
}
|
|
400
|
+
async queuePatchDoc(_collection, _newDoc, _oldDoc = {}) {
|
|
401
|
+
return this.unsupportedLegacyApi('queuePatchDoc');
|
|
402
|
+
}
|
|
403
|
+
async queueDelDoc(_collection, _id) {
|
|
404
|
+
return this.unsupportedLegacyApi('queueDelDoc');
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* Puts a document into a collection.
|
|
408
|
+
* @param collection The name of the collection.
|
|
409
|
+
* @param data The document to put.
|
|
410
|
+
* @returns The ID of the document.
|
|
411
|
+
*/
|
|
412
|
+
static async uniqueTTID(existingId) {
|
|
413
|
+
let _id;
|
|
414
|
+
const prev = Fylo.ttidLock;
|
|
415
|
+
Fylo.ttidLock = prev.then(async () => {
|
|
416
|
+
_id = existingId ? TTID.generate(existingId) : TTID.generate();
|
|
417
|
+
});
|
|
418
|
+
await Fylo.ttidLock;
|
|
419
|
+
return _id;
|
|
420
|
+
}
|
|
421
|
+
async prepareInsert(collection, data) {
|
|
422
|
+
await Fylo.loadEncryption(collection);
|
|
423
|
+
const currId = Object.keys(data).shift();
|
|
424
|
+
const _id = TTID.isTTID(currId)
|
|
425
|
+
? await Fylo.uniqueTTID(currId)
|
|
426
|
+
: await Fylo.uniqueTTID(undefined);
|
|
427
|
+
let doc = TTID.isTTID(currId) ? Object.values(data).shift() : data;
|
|
428
|
+
if (Fylo.STRICT)
|
|
429
|
+
doc = (await Gen.validateData(collection, doc));
|
|
430
|
+
return { _id, doc };
|
|
431
|
+
}
|
|
432
|
+
async executePutDataDirect(collection, _id, doc) {
|
|
433
|
+
await this.engine.putDocument(collection, _id, doc);
|
|
434
|
+
if (Fylo.LOGGING)
|
|
435
|
+
console.log(`Finished Writing ${_id}`);
|
|
436
|
+
return _id;
|
|
437
|
+
}
|
|
438
|
+
async executePatchDocDirect(collection, newDoc, oldDoc = {}) {
|
|
439
|
+
await Fylo.loadEncryption(collection);
|
|
440
|
+
const _id = Object.keys(newDoc).shift();
|
|
441
|
+
if (!_id)
|
|
442
|
+
throw new Error('this document does not contain an TTID');
|
|
443
|
+
validateDocId(_id);
|
|
444
|
+
let existingDoc = oldDoc[_id];
|
|
445
|
+
if (!existingDoc) {
|
|
446
|
+
const existing = await this.engine.getDoc(collection, _id).once();
|
|
447
|
+
existingDoc = existing[_id];
|
|
448
|
+
}
|
|
449
|
+
if (!existingDoc)
|
|
450
|
+
return _id;
|
|
451
|
+
const currData = { ...existingDoc, ...newDoc[_id] };
|
|
452
|
+
let docToWrite = currData;
|
|
453
|
+
const _newId = await Fylo.uniqueTTID(_id);
|
|
454
|
+
if (Fylo.STRICT)
|
|
455
|
+
docToWrite = (await Gen.validateData(collection, currData));
|
|
456
|
+
const nextId = await this.engine.patchDocument(collection, _id, _newId, docToWrite, existingDoc);
|
|
457
|
+
if (Fylo.LOGGING)
|
|
458
|
+
console.log(`Finished Updating ${_id} to ${nextId}`);
|
|
459
|
+
return nextId;
|
|
460
|
+
}
|
|
461
|
+
async executeDelDocDirect(collection, _id) {
|
|
462
|
+
validateDocId(_id);
|
|
463
|
+
await this.engine.deleteDocument(collection, _id);
|
|
464
|
+
if (Fylo.LOGGING)
|
|
465
|
+
console.log(`Finished Deleting ${_id}`);
|
|
466
|
+
}
|
|
467
|
+
async putData(collection, data, options = {}) {
|
|
468
|
+
if (options.wait === false) {
|
|
469
|
+
this.unsupportedLegacyApi('putData(..., { wait: false })');
|
|
470
|
+
}
|
|
471
|
+
const { _id, doc } = await this.prepareInsert(collection, data);
|
|
472
|
+
await this.executePutDataDirect(collection, _id, doc);
|
|
473
|
+
return _id;
|
|
474
|
+
}
|
|
475
|
+
/**
|
|
476
|
+
* Patches a document in a collection.
|
|
477
|
+
* @param collection The name of the collection.
|
|
478
|
+
* @param newDoc The new document data.
|
|
479
|
+
* @param oldDoc The old document data.
|
|
480
|
+
* @returns The number of documents patched.
|
|
481
|
+
*/
|
|
482
|
+
async patchDoc(collection, newDoc, oldDoc = {}, options = {}) {
|
|
483
|
+
if (options.wait === false) {
|
|
484
|
+
this.unsupportedLegacyApi('patchDoc(..., { wait: false })');
|
|
485
|
+
}
|
|
486
|
+
return await this.executePatchDocDirect(collection, newDoc, oldDoc);
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* Patches documents in a collection.
|
|
490
|
+
* @param collection The name of the collection.
|
|
491
|
+
* @param updateSchema The update schema.
|
|
492
|
+
* @returns The number of documents patched.
|
|
493
|
+
*/
|
|
494
|
+
async patchDocs(collection, updateSchema) {
|
|
495
|
+
await Fylo.loadEncryption(collection);
|
|
496
|
+
let count = 0;
|
|
497
|
+
const promises = [];
|
|
498
|
+
for await (const value of this.findDocs(collection, updateSchema.$where).collect()) {
|
|
499
|
+
if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
|
|
500
|
+
const [_id, current] = Object.entries(value)[0] ?? [];
|
|
501
|
+
if (_id && current) {
|
|
502
|
+
promises.push(this.patchDoc(collection, { [_id]: updateSchema.$set }, { [_id]: current }));
|
|
503
|
+
count++;
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
await Promise.all(promises);
|
|
508
|
+
return count;
|
|
509
|
+
}
|
|
510
|
+
/**
|
|
511
|
+
* Deletes a document from a collection.
|
|
512
|
+
* @param collection The name of the collection.
|
|
513
|
+
* @param _id The ID of the document.
|
|
514
|
+
* @returns The number of documents deleted.
|
|
515
|
+
*/
|
|
516
|
+
async delDoc(collection, _id, options = {}) {
|
|
517
|
+
if (options.wait === false) {
|
|
518
|
+
this.unsupportedLegacyApi('delDoc(..., { wait: false })');
|
|
519
|
+
}
|
|
520
|
+
await this.executeDelDocDirect(collection, _id);
|
|
521
|
+
}
|
|
522
|
+
/**
|
|
523
|
+
* Deletes documents from a collection.
|
|
524
|
+
* @param collection The name of the collection.
|
|
525
|
+
* @param deleteSchema The delete schema.
|
|
526
|
+
* @returns The number of documents deleted.
|
|
527
|
+
*/
|
|
528
|
+
async delDocs(collection, deleteSchema) {
|
|
529
|
+
await Fylo.loadEncryption(collection);
|
|
530
|
+
let count = 0;
|
|
531
|
+
const promises = [];
|
|
532
|
+
for await (const value of this.findDocs(collection, deleteSchema).collect()) {
|
|
533
|
+
if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
|
|
534
|
+
const _id = Object.keys(value).find((docId) => TTID.isTTID(docId));
|
|
535
|
+
if (_id) {
|
|
536
|
+
promises.push(this.delDoc(collection, _id));
|
|
537
|
+
count++;
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
await Promise.all(promises);
|
|
542
|
+
return count;
|
|
543
|
+
}
|
|
544
|
+
/**
|
|
545
|
+
* Joins documents from two collections.
|
|
546
|
+
* @param join The join schema.
|
|
547
|
+
* @returns The joined documents.
|
|
548
|
+
*/
|
|
549
|
+
static async joinDocs(join) {
|
|
550
|
+
return await Fylo.defaultEngine.joinDocs(join);
|
|
551
|
+
}
|
|
552
|
+
/**
|
|
553
|
+
* Finds documents in a collection.
|
|
554
|
+
* @param collection The name of the collection.
|
|
555
|
+
* @param query The query schema.
|
|
556
|
+
* @returns The found documents.
|
|
557
|
+
*/
|
|
558
|
+
static findDocs(collection, query) {
|
|
559
|
+
return Fylo.defaultEngine.findDocs(collection, query);
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAA;AAC/B,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AACtC,OAAO,IAAI,MAAM,aAAa,CAAA;AAC9B,OAAO,GAAG,MAAM,aAAa,CAAA;AAC7B,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAE7C,OAAO,eAAe,CAAA;AACtB,OAAO,mBAAmB,CAAA;AAE1B,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAA;AAyBtC,MAAM,CAAC,OAAO,OAAO,IAAI;IACb,MAAM,CAAC,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,OAAO,CAAA;IAEpC,MAAM,CAAC,QAAQ,GAAG,SAAS,CAAC,mBAAmB,CAAA;IAE/C,MAAM,CAAU,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,CAAA;IAE3C,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AI,CAAC,MAAM,CAAC,KAAK,CAAC,CACrB,CAAA;gBACD,IAAI,GAAG,EAAE,CAAC;oBACN,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC,CAAA;oBAC3C,KAAK,EAAE,CAAA;gBACX,CAAC;YACL,CAAC;QACL,CAAC;QAED,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;QAE3B,OAAO,KAAK,CAAA;IAChB,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,KAAK,CAAC,QAAQ,CACjB,IAAiB;QAEjB,OAAO,MAAM,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;IAClD,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,QAAQ,CAAgC,UAAkB,EAAE,KAAsB;QACrF,OAAO,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAI,UAAU,EAAE,KAAK,CAAC,CAAA;IAC5D,CAAC"}
|
package/dist/sync.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export class FyloSyncError extends Error {
|
|
2
|
+
collection;
|
|
3
|
+
docId;
|
|
4
|
+
path;
|
|
5
|
+
operation;
|
|
6
|
+
constructor(args) {
|
|
7
|
+
super(`FYLO sync failed after the local filesystem operation succeeded for ${args.operation} ${args.collection}/${args.docId}. Local state is already committed at ${args.path}.`, { cause: args.cause });
|
|
8
|
+
this.name = 'FyloSyncError';
|
|
9
|
+
this.collection = args.collection;
|
|
10
|
+
this.docId = args.docId;
|
|
11
|
+
this.path = args.path;
|
|
12
|
+
this.operation = args.operation;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export function resolveSyncMode(syncMode) {
|
|
16
|
+
return syncMode ?? 'await-sync';
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=sync.js.map
|
package/dist/sync.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sync.js","sourceRoot":"","sources":["../src/sync.ts"],"names":[],"mappings":"AA8BA,MAAM,OAAO,aAAc,SAAQ,KAAK;IAC3B,UAAU,CAAQ;IAClB,KAAK,CAAO;IACZ,IAAI,CAAQ;IACZ,SAAS,CAAQ;IAE1B,YAAY,IAMX;QACG,KAAK,CACD,uEAAuE,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,KAAK,yCAAyC,IAAI,CAAC,IAAI,GAAG,EAC3K,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CACxB,CAAA;QACD,IAAI,CAAC,IAAI,GAAG,eAAe,CAAA;QAC3B,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAA;QACjC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAA;QACvB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAA;QACrB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAA;IACnC,CAAC;CACJ;AAED,MAAM,UAAU,eAAe,CAAC,QAAuB;IACnD,OAAO,QAAQ,IAAI,YAAY,CAAA;AACnC,CAAC"}
|