@gscdump/engine 0.7.5 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,578 +0,0 @@
1
- import { r as currentSchemaVersion, t as SCHEMAS } from "./schema.mjs";
2
- import { i as inferSearchType, n as dayPartition, s as objectKey, u as tenantPrefix } from "./storage.mjs";
3
- import { a as compactTieredImpl, i as substituteNamedFiles, n as compileLogicalQueryPlan, o as enumeratePartitions } from "./compiler.mjs";
4
- import { sqlEscape } from "../sql-bind.mjs";
5
- import { g as resolveComparisonSQL, m as buildTotalsSql, p as buildExtrasQueries, t as createParquetResolverAdapter } from "./pg-adapter.mjs";
6
- import { buildLogicalPlan } from "gscdump/query/plan";
7
- import { normalizeUrl } from "gscdump/normalize";
8
- async function encodeBytes(db, table, rows) {
9
- const inName = db.makeTempPath("json");
10
- const outName = db.makeTempPath("parquet");
11
- const jsonBytes = new TextEncoder().encode(JSON.stringify(rows));
12
- const registered = [];
13
- await db.registerFileBuffer(inName, jsonBytes);
14
- registered.push(inName);
15
- try {
16
- const sql = rows.length === 0 ? `COPY (SELECT * FROM ${emptyTableSchema(table)} WHERE FALSE) TO '${sqlEscape(outName)}' (FORMAT PARQUET)` : `COPY (SELECT * FROM read_json_auto('${sqlEscape(inName)}', format='array', columns=${columnsJson(table)})) TO '${sqlEscape(outName)}' (FORMAT PARQUET)`;
17
- await db.query(sql);
18
- registered.push(outName);
19
- return await db.copyFileToBuffer(outName);
20
- } finally {
21
- await db.dropFiles(registered);
22
- }
23
- }
24
- async function decodeBytes(db, bytes, table) {
25
- const name = db.makeTempPath("parquet");
26
- await db.registerFileBuffer(name, bytes);
27
- try {
28
- return await db.query(`SELECT * ${dateReplaceClause(table)} FROM read_parquet('${sqlEscape(name)}')`);
29
- } finally {
30
- await db.dropFiles([name]);
31
- }
32
- }
33
- function createDuckDBCodec(factory) {
34
- return {
35
- async writeRows(ctx, rows, key, dataSource) {
36
- const bytes = await encodeBytes(await factory.getDuckDB(), ctx.table, rows);
37
- await dataSource.write(key, bytes);
38
- return {
39
- bytes: bytes.byteLength,
40
- rowCount: rows.length
41
- };
42
- },
43
- async readRows(ctx, key, dataSource) {
44
- return decodeBytes(await factory.getDuckDB(), await dataSource.read(key), ctx.table);
45
- },
46
- async compactRows(ctx, inputKeys, outputKey, dataSource) {
47
- const db = await factory.getDuckDB();
48
- if (inputKeys.length === 0) {
49
- const bytes = await encodeBytes(db, ctx.table, []);
50
- await dataSource.write(outputKey, bytes);
51
- return {
52
- bytes: bytes.byteLength,
53
- rowCount: 0
54
- };
55
- }
56
- const inputUris = inputKeys.map((k) => dataSource.uri?.(k));
57
- if (inputUris.every((u) => u !== void 0)) {
58
- const outName = db.makeTempPath("parquet");
59
- const fileList = inputUris.map((u) => `'${sqlEscape(u)}'`).join(", ");
60
- try {
61
- await db.query(`COPY (SELECT * FROM read_parquet([${fileList}], union_by_name=true)) TO '${sqlEscape(outName)}' (FORMAT PARQUET)`);
62
- const bytes = await db.copyFileToBuffer(outName);
63
- const countRows = await db.query(`SELECT count(*)::BIGINT AS n FROM read_parquet('${sqlEscape(outName)}')`);
64
- const rowCount = Number(countRows[0]?.n ?? 0);
65
- await dataSource.write(outputKey, bytes);
66
- return {
67
- bytes: bytes.byteLength,
68
- rowCount
69
- };
70
- } finally {
71
- await db.dropFiles([outName]);
72
- }
73
- }
74
- const inputs = await Promise.all(inputKeys.map((k) => dataSource.read(k)));
75
- const inNames = [];
76
- const outName = db.makeTempPath("parquet");
77
- const registered = [];
78
- for (let i = 0; i < inputs.length; i++) {
79
- const name = db.makeTempPath("parquet");
80
- await db.registerFileBuffer(name, inputs[i]);
81
- inNames.push(name);
82
- registered.push(name);
83
- }
84
- try {
85
- const fileList = inNames.map((n) => `'${sqlEscape(n)}'`).join(", ");
86
- await db.query(`COPY (SELECT * FROM read_parquet([${fileList}], union_by_name = true)) TO '${sqlEscape(outName)}' (FORMAT PARQUET)`);
87
- registered.push(outName);
88
- const bytes = await db.copyFileToBuffer(outName);
89
- const countRows = await db.query(`SELECT count(*)::BIGINT AS n FROM read_parquet('${sqlEscape(outName)}')`);
90
- const rowCount = Number(countRows[0]?.n ?? 0);
91
- await dataSource.write(outputKey, bytes);
92
- return {
93
- bytes: bytes.byteLength,
94
- rowCount
95
- };
96
- } finally {
97
- await db.dropFiles(registered);
98
- }
99
- }
100
- };
101
- }
102
- function rewriteEmptyFileSets(sql, placeholders, table) {
103
- const emptyFallback = `(SELECT * FROM ${emptyTableSchema(table)} WHERE FALSE)`;
104
- let out = sql;
105
- for (const [name, keys] of Object.entries(placeholders)) {
106
- if (keys.length > 0) continue;
107
- const pattern = new RegExp(`read_parquet\\(\\s*\\{\\{${name}\\}\\}\\s*(?:,\\s*union_by_name\\s*=\\s*true\\s*)?\\)`, "g");
108
- out = out.replace(pattern, emptyFallback);
109
- }
110
- return out;
111
- }
112
- function createDuckDBExecutor(factory) {
113
- return { async execute({ sql, params, fileKeys, dataSource, table, signal }) {
114
- signal?.throwIfAborted();
115
- const db = await factory.getDuckDB();
116
- const placeholders = {};
117
- const registered = [];
118
- for (const [name, keys] of Object.entries(fileKeys)) {
119
- const resolved = [];
120
- for (const key of keys) {
121
- const uri = dataSource.uri?.(key);
122
- if (uri !== void 0) resolved.push(uri);
123
- else {
124
- const bytes = await dataSource.read(key, void 0, signal);
125
- await db.registerFileBuffer(key, bytes);
126
- registered.push(key);
127
- resolved.push(key);
128
- }
129
- }
130
- placeholders[name] = resolved;
131
- }
132
- try {
133
- signal?.throwIfAborted();
134
- const finalSql = substituteNamedFiles(rewriteEmptyFileSets(sql, placeholders, table), placeholders);
135
- return {
136
- rows: await db.query(finalSql, params),
137
- sql: finalSql
138
- };
139
- } finally {
140
- if (registered.length > 0) await db.dropFiles(registered);
141
- }
142
- } };
143
- }
144
- function emptyTableSchema(table) {
145
- return `(FROM (VALUES ${placeholderValues(table)}) t(${columnList(table)}))`;
146
- }
147
- function canonicalEmptyParquetSchema(table) {
148
- return emptyTableSchema(table);
149
- }
150
- function dateReplaceClause(table) {
151
- if (!table) return "";
152
- const dateCols = SCHEMAS[table].columns.filter((c) => c.type === "DATE").map((c) => c.name);
153
- if (dateCols.length === 0) return "";
154
- return `REPLACE (${dateCols.map((n) => `strftime(${n}, '%Y-%m-%d') AS ${n}`).join(", ")})`;
155
- }
156
- function columnList(table) {
157
- return SCHEMAS[table].columns.map((c) => c.name).join(", ");
158
- }
159
- function placeholderValues(table) {
160
- return `(${SCHEMAS[table].columns.map((c) => defaultForType(c.type)).join(", ")})`;
161
- }
162
- function defaultForType(t) {
163
- if (t === "VARCHAR") return "''";
164
- if (t === "DATE") return "DATE '1970-01-01'";
165
- if (t === "INTEGER" || t === "BIGINT") return "0";
166
- if (t === "DOUBLE") return "CAST(0 AS DOUBLE)";
167
- return "NULL";
168
- }
169
- function columnsJson(table) {
170
- return `{${SCHEMAS[table].columns.map((c) => `'${c.name}': '${c.type}'`).join(", ")}}`;
171
- }
172
- const VERSION_RE = /__v(\d+)\.parquet$/;
173
- function parseLockScope(key) {
174
- const match = VERSION_RE.exec(key);
175
- if (!match) return void 0;
176
- const parts = key.slice(0, match.index).split("/");
177
- if (parts.length < 4) return void 0;
178
- const userPart = parts[0];
179
- if (!userPart.startsWith("u_")) return void 0;
180
- const userId = userPart.slice(2);
181
- const partition = parts.slice(-2).join("/");
182
- const table = parts[parts.length - 3];
183
- return {
184
- userId,
185
- siteId: parts.length >= 5 ? parts.slice(1, -3).join("/") : void 0,
186
- table,
187
- partition
188
- };
189
- }
190
- async function gcOrphansImpl(deps, now, graceMs, opts = {}) {
191
- const cutoff = now - graceMs;
192
- const retired = await deps.manifestStore.listRetired(cutoff);
193
- if (retired.length > 0) {
194
- await deps.dataSource.delete(retired.map((e) => e.objectKey));
195
- await deps.manifestStore.delete(retired);
196
- }
197
- let sweptOrphans = 0;
198
- if (opts.userId) {
199
- const prefix = tenantPrefix({
200
- userId: opts.userId,
201
- siteId: opts.siteId
202
- });
203
- const knownEntries = await deps.manifestStore.listAll({
204
- userId: opts.userId,
205
- siteId: opts.siteId
206
- });
207
- const knownSet = new Set(knownEntries.map((e) => e.objectKey));
208
- const orphans = [];
209
- const keyStream = deps.dataSource.streamList ? deps.dataSource.streamList(prefix) : async function* () {
210
- const all = await deps.dataSource.list(prefix);
211
- for (const k of all) yield k;
212
- }();
213
- for await (const key of keyStream) {
214
- if (knownSet.has(key)) continue;
215
- const match = VERSION_RE.exec(key);
216
- if (!match) continue;
217
- if (Number(match[1]) <= cutoff) orphans.push(key);
218
- }
219
- const byScope = /* @__PURE__ */ new Map();
220
- for (const key of orphans) {
221
- const scope = parseLockScope(key);
222
- if (!scope) continue;
223
- const sk = `${scope.userId}|${scope.siteId ?? ""}|${scope.table}|${scope.partition}`;
224
- const bucket = byScope.get(sk) ?? {
225
- scope,
226
- keys: []
227
- };
228
- bucket.keys.push(key);
229
- byScope.set(sk, bucket);
230
- }
231
- for (const { scope, keys } of byScope.values()) await deps.manifestStore.withLock(scope, async () => {
232
- const known = await deps.manifestStore.listAll({
233
- userId: scope.userId,
234
- siteId: scope.siteId,
235
- table: scope.table,
236
- partitions: [scope.partition]
237
- });
238
- const knownInScope = new Set(known.map((e) => e.objectKey));
239
- const stillOrphans = keys.filter((k) => !knownInScope.has(k));
240
- if (stillOrphans.length > 0) {
241
- await deps.dataSource.delete(stillOrphans);
242
- sweptOrphans += stillOrphans.length;
243
- }
244
- });
245
- }
246
- return { deleted: retired.length + sweptOrphans };
247
- }
248
- const URL_PURGE_TABLES = ["pages", "page_keywords"];
249
- const MAX_DAY_BYTES = 100 * 1024 * 1024;
250
- const URL_COLUMNS = /* @__PURE__ */ new Set();
251
- for (const t of Object.keys(SCHEMAS)) for (const col of SCHEMAS[t].columns) if (col.name === "url") URL_COLUMNS.add(`${t}:url`);
252
- function normalizeRow(table, row) {
253
- if (!URL_COLUMNS.has(`${table}:url`)) return row;
254
- const url = row.url;
255
- if (typeof url !== "string") return row;
256
- const normalized = normalizeUrl(url);
257
- if (normalized === url) return row;
258
- return {
259
- ...row,
260
- url: normalized
261
- };
262
- }
263
- function createStorageEngine(opts) {
264
- const { dataSource, manifestStore, codec, executor } = opts;
265
- const defaultNow = opts.now ?? (() => Date.now());
266
- async function writeDay(ctx, rows) {
267
- if (!ctx.date) throw new Error("writeDay requires ctx.date");
268
- const date = ctx.date;
269
- const now = (ctx.now ?? defaultNow)();
270
- const partition = dayPartition(date);
271
- const searchType = ctx.searchType;
272
- return manifestStore.withLock({
273
- userId: ctx.userId,
274
- siteId: ctx.siteId,
275
- table: ctx.table,
276
- partition
277
- }, async () => {
278
- const superseding = (await manifestStore.listLive({
279
- userId: ctx.userId,
280
- siteId: ctx.siteId,
281
- table: ctx.table,
282
- partitions: [partition]
283
- })).filter((e) => inferSearchType(e) === inferSearchType({ searchType }));
284
- const normalizedRows = rows.map((r) => normalizeRow(ctx.table, r));
285
- const key = objectKey(ctx, ctx.table, partition, now, searchType);
286
- const { bytes: writtenBytes, rowCount } = await codec.writeRows({ table: ctx.table }, normalizedRows, key, dataSource);
287
- let bytes = writtenBytes;
288
- if (bytes === 0 && rowCount > 0 && dataSource.head) {
289
- const probed = await dataSource.head(key);
290
- if (probed) bytes = probed.bytes;
291
- }
292
- if (bytes > 104857600) {
293
- await dataSource.delete([key]).catch(() => {});
294
- throw new Error(`writeDay payload ${bytes} bytes exceeds ${MAX_DAY_BYTES} hard ceiling (table=${ctx.table}, key=${key})`);
295
- }
296
- const entry = {
297
- userId: ctx.userId,
298
- siteId: ctx.siteId,
299
- table: ctx.table,
300
- partition,
301
- objectKey: key,
302
- rowCount,
303
- bytes,
304
- createdAt: now,
305
- schemaVersion: currentSchemaVersion(ctx.table),
306
- tier: "raw",
307
- ...searchType !== void 0 ? { searchType } : {}
308
- };
309
- await manifestStore.registerVersion(entry, superseding);
310
- await manifestStore.bumpWatermark({
311
- userId: ctx.userId,
312
- siteId: ctx.siteId,
313
- table: ctx.table
314
- }, date, now);
315
- });
316
- }
317
- async function runSQL(opts) {
318
- opts.signal?.throwIfAborted();
319
- const entries = Object.entries(opts.fileSets);
320
- const perSet = await Promise.all(entries.map(async ([name, ref]) => {
321
- return [name, (await manifestStore.listLive({
322
- userId: opts.ctx.userId,
323
- siteId: opts.ctx.siteId,
324
- table: ref.table,
325
- partitions: ref.partitions
326
- })).map((e) => e.objectKey)];
327
- }));
328
- opts.signal?.throwIfAborted();
329
- const fileKeys = {};
330
- for (const [name, keys] of perSet) fileKeys[name] = keys;
331
- const uniqueKeys = [...new Set(perSet.flatMap(([, keys]) => keys))];
332
- let table = opts.table;
333
- if (!table) {
334
- if (new Set(entries.map(([, ref]) => ref.table)).size > 1) throw new Error("runSQL requires explicit ctx.table when fileSets reference multiple tables.");
335
- table = entries[0]?.[1].table;
336
- }
337
- if (!table) throw new Error("runSQL requires at least one fileSet or an explicit table");
338
- const result = await executor.execute({
339
- sql: opts.sql,
340
- params: opts.params ?? [],
341
- fileKeys,
342
- dataSource,
343
- table,
344
- signal: opts.signal
345
- });
346
- return {
347
- rows: result.rows,
348
- sql: result.sql,
349
- objectKeys: uniqueKeys
350
- };
351
- }
352
- async function query(ctx, state) {
353
- const plan = buildLogicalPlan(state, { regex: true });
354
- const table = ctx.table ?? plan.dataset;
355
- const resolved = compileLogicalQueryPlan(plan, table);
356
- return runSQL({
357
- ctx: {
358
- userId: ctx.userId,
359
- siteId: ctx.siteId
360
- },
361
- table,
362
- fileSets: { FILES: {
363
- table,
364
- partitions: resolved.partitions
365
- } },
366
- sql: resolved.sql,
367
- params: resolved.params,
368
- signal: ctx.signal
369
- });
370
- }
371
- async function queryComparison(ctx, current, previous, filter) {
372
- const adapter = createParquetResolverAdapter();
373
- const currentPlan = buildLogicalPlan(current, adapter.capabilities);
374
- const previousPlan = buildLogicalPlan(previous, adapter.capabilities);
375
- if (currentPlan.dataset !== previousPlan.dataset) throw new Error(`queryComparison: current (${currentPlan.dataset}) and previous (${previousPlan.dataset}) must resolve to the same table`);
376
- const table = ctx.table ?? currentPlan.dataset;
377
- const comparison = resolveComparisonSQL(current, previous, {
378
- adapter,
379
- siteId: void 0
380
- }, filter);
381
- const totals = buildTotalsSql(current, {
382
- adapter,
383
- siteId: void 0
384
- });
385
- const fileSets = { FILES: {
386
- table,
387
- partitions: enumeratePartitions(currentPlan.dateRange.startDate < previousPlan.dateRange.startDate ? currentPlan.dateRange.startDate : previousPlan.dateRange.startDate, currentPlan.dateRange.endDate > previousPlan.dateRange.endDate ? currentPlan.dateRange.endDate : previousPlan.dateRange.endDate)
388
- } };
389
- const baseCtx = {
390
- userId: ctx.userId,
391
- siteId: ctx.siteId
392
- };
393
- const [main, count, totalsRow] = await Promise.all([
394
- runSQL({
395
- ctx: baseCtx,
396
- table,
397
- fileSets,
398
- sql: comparison.sql,
399
- params: comparison.params,
400
- signal: ctx.signal
401
- }),
402
- runSQL({
403
- ctx: baseCtx,
404
- table,
405
- fileSets,
406
- sql: comparison.countSql,
407
- params: comparison.countParams,
408
- signal: ctx.signal
409
- }),
410
- runSQL({
411
- ctx: baseCtx,
412
- table,
413
- fileSets,
414
- sql: totals.sql,
415
- params: totals.params,
416
- signal: ctx.signal
417
- })
418
- ]);
419
- return {
420
- rows: main.rows,
421
- totalCount: Number(count.rows[0]?.total ?? 0),
422
- totals: totalsRow.rows[0] ?? {}
423
- };
424
- }
425
- async function queryExtras(ctx, state) {
426
- const adapter = createParquetResolverAdapter();
427
- const extras = buildExtrasQueries(state, {
428
- adapter,
429
- siteId: void 0
430
- });
431
- if (extras.length === 0) return [];
432
- const plan = buildLogicalPlan(state, adapter.capabilities);
433
- const table = ctx.table ?? plan.dataset;
434
- const fileSets = { FILES: {
435
- table,
436
- partitions: enumeratePartitions(plan.dateRange.startDate, plan.dateRange.endDate)
437
- } };
438
- const baseCtx = {
439
- userId: ctx.userId,
440
- siteId: ctx.siteId
441
- };
442
- const results = await Promise.all(extras.map((e) => runSQL({
443
- ctx: baseCtx,
444
- table,
445
- fileSets,
446
- sql: e.sql,
447
- params: e.params,
448
- signal: ctx.signal
449
- })));
450
- return extras.map((e, i) => ({
451
- key: e.key,
452
- rows: results[i].rows
453
- }));
454
- }
455
- async function compactTiered(ctx, thresholds) {
456
- return compactTieredImpl({
457
- dataSource,
458
- manifestStore,
459
- codec
460
- }, ctx, (ctx.now ?? defaultNow)(), thresholds);
461
- }
462
- async function gcOrphans(ctx, graceMs) {
463
- return gcOrphansImpl({
464
- dataSource,
465
- manifestStore
466
- }, (ctx.now ?? defaultNow)(), graceMs, {
467
- userId: ctx.userId,
468
- siteId: ctx.siteId
469
- });
470
- }
471
- async function purgeTenant(ctx) {
472
- const prefix = tenantPrefix(ctx);
473
- const keys = [];
474
- const keyStream = dataSource.streamList ? dataSource.streamList(prefix) : async function* () {
475
- for (const k of await dataSource.list(prefix)) yield k;
476
- }();
477
- for await (const key of keyStream) keys.push(key);
478
- if (keys.length > 0) await dataSource.delete(keys);
479
- const manifestResult = await manifestStore.purgeTenant({
480
- userId: ctx.userId,
481
- siteId: ctx.siteId
482
- });
483
- return {
484
- userId: ctx.userId,
485
- siteId: ctx.siteId,
486
- prefix,
487
- objectsDeleted: keys.length,
488
- entriesRemoved: manifestResult.entriesRemoved,
489
- watermarksRemoved: manifestResult.watermarksRemoved,
490
- syncStatesRemoved: manifestResult.syncStatesRemoved,
491
- at: defaultNow()
492
- };
493
- }
494
- async function purgeUrls(ctx, urls) {
495
- const now = defaultNow();
496
- const urlSet = new Set(urls);
497
- let entriesRewritten = 0;
498
- let rowsRemoved = 0;
499
- let bytesAfter = 0;
500
- if (urlSet.size === 0) return {
501
- userId: ctx.userId,
502
- siteId: ctx.siteId,
503
- urlsRequested: 0,
504
- entriesRewritten: 0,
505
- rowsRemoved: 0,
506
- bytesAfter: 0,
507
- at: now
508
- };
509
- for (const table of URL_PURGE_TABLES) {
510
- const entries = await manifestStore.listLive({
511
- userId: ctx.userId,
512
- siteId: ctx.siteId,
513
- table
514
- });
515
- for (const entry of entries) await manifestStore.withLock({
516
- userId: entry.userId,
517
- siteId: entry.siteId,
518
- table,
519
- partition: entry.partition
520
- }, async () => {
521
- const rows = await codec.readRows({ table }, entry.objectKey, dataSource);
522
- const kept = rows.filter((r) => typeof r.url !== "string" || !urlSet.has(r.url));
523
- const removed = rows.length - kept.length;
524
- if (removed === 0) return;
525
- const searchType = entry.searchType;
526
- const newKey = objectKey({
527
- userId: entry.userId,
528
- siteId: entry.siteId
529
- }, table, entry.partition, now, searchType);
530
- const { bytes, rowCount } = await codec.writeRows({ table }, kept, newKey, dataSource);
531
- const newEntry = {
532
- userId: entry.userId,
533
- siteId: entry.siteId,
534
- table,
535
- partition: entry.partition,
536
- objectKey: newKey,
537
- rowCount,
538
- bytes,
539
- createdAt: now,
540
- schemaVersion: entry.schemaVersion ?? currentSchemaVersion(table),
541
- ...entry.tier !== void 0 ? { tier: entry.tier } : {},
542
- ...searchType !== void 0 ? { searchType } : {}
543
- };
544
- await manifestStore.registerVersion(newEntry, [entry]);
545
- entriesRewritten++;
546
- rowsRemoved += removed;
547
- bytesAfter += bytes;
548
- });
549
- }
550
- return {
551
- userId: ctx.userId,
552
- siteId: ctx.siteId,
553
- urlsRequested: urlSet.size,
554
- entriesRewritten,
555
- rowsRemoved,
556
- bytesAfter,
557
- at: now
558
- };
559
- }
560
- return {
561
- writeDay,
562
- query,
563
- queryComparison,
564
- queryExtras,
565
- runSQL,
566
- compactTiered,
567
- gcOrphans,
568
- purgeTenant,
569
- purgeUrls,
570
- listLive: (filter) => manifestStore.listLive(filter),
571
- listAll: (filter) => manifestStore.listAll(filter),
572
- getWatermarks: (filter) => manifestStore.getWatermarks(filter),
573
- getSyncStates: (filter) => manifestStore.getSyncStates(filter),
574
- setSyncState: (scope, state, detail) => manifestStore.setSyncState(scope, state, detail),
575
- readObject: (key) => dataSource.read(key)
576
- };
577
- }
578
- export { createDuckDBExecutor as a, createDuckDBCodec as i, createStorageEngine as n, canonicalEmptyParquetSchema as r, MAX_DAY_BYTES as t };
@@ -1,35 +0,0 @@
1
- import { a as DataSource, m as ManifestStore } from "../_chunks/storage.mjs";
2
- interface HttpDataSourceOptions {
3
- /**
4
- * Base URL to prefix each object key with. MUST NOT have a trailing slash.
5
- * E.g. `https://pub-abcdef.r2.dev/gscdump-data`.
6
- */
7
- baseUrl: string;
8
- /**
9
- * Optional transformer that produces the final URL for a key. Use this when
10
- * keys need signing (pre-signed URLs, per-request tokens, etc.). If omitted,
11
- * the default is `${baseUrl}/${encodeKey(key)}` where forward slashes in the
12
- * key are preserved.
13
- */
14
- signUrl?: (key: string) => string;
15
- /**
16
- * Whether `uri(key)` should return the HTTPS URL so DuckDB's httpfs can
17
- * fetch directly. Default true (browser, Workers, anywhere httpfs is
18
- * loaded). Set to false for environments where httpfs isn't available —
19
- * the executor will fall back to `read(key)` and buffer the bytes itself.
20
- */
21
- useDuckDBHttpfs?: boolean;
22
- }
23
- declare function createHttpDataSource(opts: HttpDataSourceOptions): DataSource;
24
- interface HttpManifestStoreOptions {
25
- /**
26
- * URL of a JSON manifest snapshot. The response MUST be:
27
- * { version: 1, entries: ManifestEntry[], watermarks?: Watermark[] }
28
- * (Matches the on-disk layout produced by the filesystem adapter.)
29
- */
30
- manifestUrl: string;
31
- /** Override fetch for tests / custom origins. */
32
- fetchImpl?: typeof fetch;
33
- }
34
- declare function createHttpManifestStore(opts: HttpManifestStoreOptions): ManifestStore;
35
- export { HttpDataSourceOptions, HttpManifestStoreOptions, createHttpDataSource, createHttpManifestStore };