@gscdump/cloudflare 0.40.1 → 1.0.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.
package/dist/index.d.mts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { ParquetCodec, QueryExecutor, Row, createStorageEngine } from "@gscdump/engine";
2
- import { H3Event } from "h3";
3
2
  interface AnalyticsEnv {
4
3
  /** R2 bucket holding parquet + rollup + entity data. Required in origin mode. */
5
4
  R2_DATA?: R2Bucket;
@@ -43,18 +42,7 @@ interface AnalyticsEnv {
43
42
  R2_ACCESS_KEY_ID?: string;
44
43
  R2_SECRET_ACCESS_KEY?: string;
45
44
  CLOUDFLARE_ACCOUNT_ID?: string;
46
- /** Secret used by size-hint-sig.ts to HMAC-sign size hints. Rotating it invalidates cached hints. */
47
- TOKEN_ENCRYPTION_SECRET?: string;
48
45
  }
49
- /**
50
- * Resolve the AnalyticsEnv for the current request.
51
- *
52
- * Looks for, in order:
53
- * 1. `event.context.analyticsEnv` — host plugin sets this explicitly.
54
- * 2. `event.context.cloudflare?.env` — Cloudflare adapter convention.
55
- * 3. Throws. The layer has no way to fabricate an env; the host must wire it.
56
- */
57
- declare function useAnalyticsEnv(event: H3Event): AnalyticsEnv;
58
46
  /**
59
47
  * Optional per-request hooks for telemetry / tracing. Hosts wire these in
60
48
  * to bridge engine activity into their own metrics pipeline.
@@ -68,7 +56,6 @@ interface AnalyticsEngineHooks {
68
56
  interface AnalyticsEngineRuntime {
69
57
  getEngine: (env: AnalyticsEnv, db: any, hooks?: AnalyticsEngineHooks) => ReturnType<typeof createStorageEngine> | null;
70
58
  }
71
- declare function createAnalyticsEngineRuntime(): AnalyticsEngineRuntime;
72
59
  declare function getAnalyticsEngine(env: AnalyticsEnv, db: any, hooks?: AnalyticsEngineHooks): ReturnType<typeof createStorageEngine> | null;
73
60
  interface InflightDedupe<T> {
74
61
  dedupe: (key: string, run: () => Promise<T>) => Promise<T>;
@@ -84,8 +71,6 @@ interface HostedR2QueryKeyInput {
84
71
  comparisonFilter?: string;
85
72
  }
86
73
  declare function getHostedR2QueryKey(input: HostedR2QueryKeyInput): string;
87
- declare function signSizeHint(env: AnalyticsEnv, key: string, bytes: number): Promise<string>;
88
- declare function verifySizeHint(env: AnalyticsEnv, key: string, bytes: number, providedHex: string): Promise<boolean>;
89
74
  declare function createDucklingsCodec(_env: AnalyticsEnv): ParquetCodec;
90
75
  interface DucklingsRowCache {
91
76
  clear: () => void;
@@ -102,4 +87,4 @@ interface DucklingsExecutorOptions {
102
87
  rowCache?: DucklingsRowCache;
103
88
  }
104
89
  declare function createDucklingsExecutor(env: AnalyticsEnv, opts?: DucklingsExecutorOptions): QueryExecutor;
105
- export { type AnalyticsEngineHooks, type AnalyticsEngineRuntime, type AnalyticsEnv, type DucklingsRowCache, type HostedR2QueryKeyInput, type InflightDedupe, createAnalyticsEngineRuntime, createDucklingsCodec, createDucklingsExecutor, createDucklingsRowCache, createInflightDedupe, getAnalyticsEngine, getHostedR2QueryKey, signSizeHint, useAnalyticsEnv, verifySizeHint };
90
+ export { type AnalyticsEngineHooks, type AnalyticsEngineRuntime, type AnalyticsEnv, type DucklingsRowCache, type HostedR2QueryKeyInput, type InflightDedupe, createDucklingsCodec, createDucklingsExecutor, createDucklingsRowCache, createInflightDedupe, getAnalyticsEngine, getHostedR2QueryKey };
package/dist/index.mjs CHANGED
@@ -3,7 +3,6 @@ import { createD1ManifestStore } from "@gscdump/engine-sqlite";
3
3
  import { createR2DataSource } from "@gscdump/engine/r2";
4
4
  import { createHyparquetCodec, decodeParquetToRows } from "@gscdump/engine/hyparquet";
5
5
  import { float64, int32, int64, tableFromArrays, tableToIPC, utf8 } from "@uwdata/flechette";
6
- import { createError } from "h3";
7
6
  function arrowTypeForColumn(type) {
8
7
  switch (type) {
9
8
  case "VARCHAR":
@@ -436,16 +435,6 @@ function getAnalyticsEngine(env, db, hooks = {}) {
436
435
  sharedRuntime ??= createAnalyticsEngineRuntime();
437
436
  return sharedRuntime.getEngine(env, db, hooks);
438
437
  }
439
- function useAnalyticsEnv(event) {
440
- const fromCtx = event.context.analyticsEnv;
441
- if (fromCtx) return fromCtx;
442
- const fromCf = event.context.cloudflare?.env;
443
- if (fromCf) return fromCf;
444
- throw createError({
445
- statusCode: 500,
446
- statusMessage: "AnalyticsEnv not available — host must populate event.context.analyticsEnv or use the Cloudflare adapter"
447
- });
448
- }
449
438
  function createInflightDedupe() {
450
439
  const inflight = /* @__PURE__ */ new Map();
451
440
  return {
@@ -482,44 +471,4 @@ function getHostedR2QueryKey(input) {
482
471
  input.comparisonFilter ?? null
483
472
  ]);
484
473
  }
485
- const SIG_HEX_LEN = 64;
486
- const keyCache = /* @__PURE__ */ new WeakMap();
487
- const stringKeyCache = /* @__PURE__ */ new Map();
488
- async function getKey(env) {
489
- const secret = env.TOKEN_ENCRYPTION_SECRET;
490
- if (!secret) throw new Error("size-hint-sig: TOKEN_ENCRYPTION_SECRET not configured");
491
- let cached = keyCache.get(env);
492
- if (!cached) {
493
- cached = stringKeyCache.get(secret);
494
- if (!cached) {
495
- cached = crypto.subtle.importKey("raw", new TextEncoder().encode(secret).slice().buffer, {
496
- name: "HMAC",
497
- hash: "SHA-256"
498
- }, false, ["sign", "verify"]);
499
- stringKeyCache.set(secret, cached);
500
- }
501
- keyCache.set(env, cached);
502
- }
503
- return cached;
504
- }
505
- function toHex(buf, chars) {
506
- const bytes = new Uint8Array(buf);
507
- let hex = "";
508
- for (let i = 0; i < chars / 2; i++) hex += bytes[i].toString(16).padStart(2, "0");
509
- return hex;
510
- }
511
- function payload(key, bytes) {
512
- return new TextEncoder().encode(`${key}\0${bytes}`).slice().buffer;
513
- }
514
- async function signSizeHint(env, key, bytes) {
515
- const cryptoKey = await getKey(env);
516
- return toHex(await crypto.subtle.sign("HMAC", cryptoKey, payload(key, bytes)), SIG_HEX_LEN);
517
- }
518
- async function verifySizeHint(env, key, bytes, providedHex) {
519
- if (providedHex.length !== SIG_HEX_LEN) return false;
520
- const expected = await signSizeHint(env, key, bytes);
521
- let diff = 0;
522
- for (let i = 0; i < SIG_HEX_LEN; i++) diff |= expected.charCodeAt(i) ^ providedHex.charCodeAt(i);
523
- return diff === 0;
524
- }
525
- export { createAnalyticsEngineRuntime, createDucklingsCodec, createDucklingsExecutor, createDucklingsRowCache, createInflightDedupe, getAnalyticsEngine, getHostedR2QueryKey, signSizeHint, useAnalyticsEnv, verifySizeHint };
474
+ export { createDucklingsCodec, createDucklingsExecutor, createDucklingsRowCache, createInflightDedupe, getAnalyticsEngine, getHostedR2QueryKey };
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@gscdump/cloudflare",
3
3
  "type": "module",
4
- "version": "0.40.1",
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.",
4
+ "version": "1.0.0",
5
+ "description": "Cloudflare-Workers-flavored helpers for the gscdump analytics stack: AnalyticsEnv binding contract, R2 SigV4 presigner, DuckDB Workers shims, engine factory.",
6
6
  "author": {
7
7
  "name": "Harlan Wilton",
8
8
  "email": "harlan@harlanzw.com",
@@ -38,22 +38,18 @@
38
38
  "dist"
39
39
  ],
40
40
  "engines": {
41
- "node": ">=18"
42
- },
43
- "peerDependencies": {
44
- "h3": "^1.15.0"
41
+ "node": ">=22"
45
42
  },
46
43
  "dependencies": {
47
44
  "@uwdata/flechette": "^2.5.0",
48
- "@gscdump/contracts": "0.40.1",
49
- "@gscdump/engine": "0.40.1",
50
- "@gscdump/engine-sqlite": "0.40.1",
51
- "gscdump": "0.40.1"
45
+ "@gscdump/engine-sqlite": "^1.0.0",
46
+ "@gscdump/contracts": "^1.0.0",
47
+ "@gscdump/engine": "^1.0.0",
48
+ "gscdump": "^1.0.0"
52
49
  },
53
50
  "devDependencies": {
54
51
  "@cloudflare/vitest-pool-workers": "^0.18.6",
55
52
  "@cloudflare/workers-types": "^5.20260718.1",
56
- "h3": "^1.15.11",
57
53
  "typescript": "^6.0.3",
58
54
  "wrangler": "^4.112.0"
59
55
  },