@gscdump/cloudflare 0.25.9 → 0.25.11

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.
@@ -86,8 +86,8 @@ declare function createDuckDbIcebergExecutor(config: DuckDbIcebergExecutorConfig
86
86
  interface R2SqlClientConfig {
87
87
  /** Cloudflare account id. */
88
88
  accountId: string;
89
- /** R2 Data Catalog warehouse name (`<bucket>` or `<account>_<bucket>`). */
90
- warehouse: string;
89
+ /** R2 bucket backing the Iceberg catalog R2 SQL addresses the catalog by bucket. */
90
+ bucket: string;
91
91
  /** Iceberg namespace the 5 fact tables live in. */
92
92
  namespace: string;
93
93
  /** Cloudflare API token with R2 Data Catalog read scope. */
@@ -349,8 +349,12 @@ var R2SqlTimeoutError = class extends Error {
349
349
  super(`R2 SQL query exceeded ${timeoutMs}ms deadline`);
350
350
  }
351
351
  };
352
- const DEFAULT_API_BASE = "https://api.cloudflare.com/client/v4";
352
+ const DEFAULT_API_BASE = "https://api.sql.cloudflarestorage.com/api/v1";
353
353
  const DEFAULT_TIMEOUT_MS = 25e3;
354
+ const PARTITION_PREDICATE_RE = /\b(site_id|search_type)(\s*=)/g;
355
+ function workaroundPartitionEquality(sql) {
356
+ return sql.replace(PARTITION_PREDICATE_RE, (_m, col, eq) => `CONCAT(${col}, '')${eq}`);
357
+ }
354
358
  function escapeSqlValue(value) {
355
359
  if (value === null || value === void 0) return "NULL";
356
360
  if (typeof value === "number") {
@@ -406,7 +410,7 @@ function createR2SqlClient(config) {
406
410
  const fetchImpl = config.fetchImpl ?? globalThis.fetch;
407
411
  const apiBase = config.apiBase ?? DEFAULT_API_BASE;
408
412
  const timeoutMs = config.timeoutMs ?? DEFAULT_TIMEOUT_MS;
409
- const endpoint = `${apiBase}/accounts/${config.accountId}/r2-catalog/${config.warehouse}/sql`;
413
+ const endpoint = `${apiBase}/accounts/${config.accountId}/r2-sql/query/${config.bucket}`;
410
414
  async function query(sql) {
411
415
  const started = Date.now();
412
416
  const controller = new AbortController();
@@ -417,7 +421,8 @@ function createR2SqlClient(config) {
417
421
  method: "POST",
418
422
  headers: {
419
423
  "authorization": `Bearer ${config.token}`,
420
- "content-type": "application/json"
424
+ "content-type": "application/json",
425
+ "user-agent": "gscdump-cloudflare-r2sql/1.0"
421
426
  },
422
427
  body: JSON.stringify({ query: sql }),
423
428
  signal: controller.signal
@@ -442,7 +447,7 @@ function createR2SqlClient(config) {
442
447
  }
443
448
  function runPlan(plan) {
444
449
  const tableRef = r2TableRef(config.namespace, plan.table);
445
- return query(inlineParams(plan.sql.split(TABLE_PLACEHOLDER).join(tableRef), plan.params));
450
+ return query(workaroundPartitionEquality(inlineParams(plan.sql.split(TABLE_PLACEHOLDER).join(tableRef), plan.params)));
446
451
  }
447
452
  function runArchetype(archetypeQuery) {
448
453
  return runPlan(buildArchetypeSql(archetypeQuery));
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@gscdump/cloudflare",
3
3
  "type": "module",
4
- "version": "0.25.9",
4
+ "version": "0.25.11",
5
5
  "description": "Cloudflare-Workers-flavored helpers for the gscdump analytics stack: AnalyticsEnv binding contract, R2 SigV4 presigner, size-hint HMAC, DuckDB Workers shims, engine factory.",
6
6
  "author": {
7
7
  "name": "Harlan Wilton",
@@ -46,11 +46,11 @@
46
46
  "dependencies": {
47
47
  "@uwdata/flechette": "^2.5.0",
48
48
  "aws4fetch": "^1.0.20",
49
- "@gscdump/contracts": "0.25.9",
50
- "@gscdump/engine-sqlite": "0.25.9",
51
- "@gscdump/sdk": "0.25.9",
52
- "@gscdump/engine": "0.25.9",
53
- "gscdump": "0.25.9"
49
+ "@gscdump/engine": "0.25.11",
50
+ "@gscdump/contracts": "0.25.11",
51
+ "@gscdump/sdk": "0.25.11",
52
+ "gscdump": "0.25.11",
53
+ "@gscdump/engine-sqlite": "0.25.11"
54
54
  },
55
55
  "devDependencies": {
56
56
  "@cloudflare/vitest-pool-workers": "^0.16.10",