@supacloud/lite 0.9.2 → 0.11.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.js CHANGED
@@ -85,7 +85,7 @@ function randomToken(bytes = 32) {
85
85
  // package.json
86
86
  var package_default = {
87
87
  name: "@supacloud/lite",
88
- version: "0.9.2",
88
+ version: "0.11.0",
89
89
  description: "Bun-native, single-project Supabase-compatible backend powered by PGlite or native PostgreSQL",
90
90
  type: "module",
91
91
  license: "Apache-2.0",
@@ -135,11 +135,13 @@ var package_default = {
135
135
  },
136
136
  dependencies: {
137
137
  "@electric-sql/pglite": "0.5.8",
138
+ "@supacloud/db": "^0.1.0",
138
139
  tar: "^7.5.22"
139
140
  },
140
141
  devDependencies: {
141
142
  "@supabase/supabase-js": "^2.112.4",
142
143
  "@types/bun": "^1.4.0",
144
+ elysia: "^1.4.30",
143
145
  typescript: "^7.0.2"
144
146
  },
145
147
  engines: {
@@ -2528,8 +2530,99 @@ function resetCapturedHandler() {
2528
2530
  captured.handler = undefined;
2529
2531
  }
2530
2532
 
2531
- // src/runtime/functions/pgredis.ts
2533
+ // src/runtime/functions/edge-runtime-shim.ts
2532
2534
  import { AsyncLocalStorage as AsyncLocalStorage2 } from "async_hooks";
2535
+ var scopeStore = new AsyncLocalStorage2;
2536
+ var NOT_ENABLED_MESSAGE = "EdgeRuntime.waitUntil is not enabled by the Function capability policy";
2537
+ var installed;
2538
+ function installEdgeRuntimeShim() {
2539
+ if (installed)
2540
+ return;
2541
+ const runtime = {
2542
+ waitUntil(promise) {
2543
+ const scope = scopeStore.getStore();
2544
+ if (scope && !scope.allowed) {
2545
+ throw new Error(NOT_ENABLED_MESSAGE);
2546
+ }
2547
+ const task = Promise.resolve(promise).catch((error) => {
2548
+ console.error("[EdgeRuntime.waitUntil] background task failed", error);
2549
+ });
2550
+ scope?.tasks.push(task);
2551
+ }
2552
+ };
2553
+ installed = runtime;
2554
+ globalThis.EdgeRuntime = runtime;
2555
+ }
2556
+ function runWithBackgroundTasks(options, fn) {
2557
+ installEdgeRuntimeShim();
2558
+ const scope = { allowed: options.allowed, tasks: [] };
2559
+ return scopeStore.run(scope, async () => {
2560
+ try {
2561
+ return await fn();
2562
+ } finally {
2563
+ flushBackgroundTasks(scope.tasks, options.timeoutMs);
2564
+ }
2565
+ });
2566
+ }
2567
+ async function flushBackgroundTasks(tasks, timeoutMs) {
2568
+ if (tasks.length === 0)
2569
+ return;
2570
+ const drain = (async () => {
2571
+ while (tasks.length > 0) {
2572
+ const batch = tasks.splice(0);
2573
+ await Promise.allSettled(batch);
2574
+ }
2575
+ })();
2576
+ if (timeoutMs === undefined) {
2577
+ await drain;
2578
+ return;
2579
+ }
2580
+ const timedOut = await Promise.race([
2581
+ drain.then(() => false),
2582
+ new Promise((resolve) => setTimeout(() => resolve(true), timeoutMs))
2583
+ ]);
2584
+ if (timedOut) {
2585
+ console.warn(`[EdgeRuntime.waitUntil] background tasks did not settle within ${timeoutMs}ms; no longer waiting`);
2586
+ }
2587
+ }
2588
+
2589
+ // src/runtime/functions/fetch-policy.ts
2590
+ import { AsyncLocalStorage as AsyncLocalStorage3 } from "async_hooks";
2591
+ var policyStore = new AsyncLocalStorage3;
2592
+ var LOOPBACK_HOSTS = new Set(["localhost", "127.0.0.1", "::1"]);
2593
+ var installed2 = false;
2594
+ function installFetchPolicyShim() {
2595
+ if (installed2)
2596
+ return;
2597
+ installed2 = true;
2598
+ const original = globalThis.fetch;
2599
+ globalThis.fetch = async (input, init) => {
2600
+ const allowed = policyStore.getStore();
2601
+ if (!allowed)
2602
+ return original(input, init);
2603
+ const host = hostOf(input);
2604
+ if (host !== undefined && !LOOPBACK_HOSTS.has(host) && !allowed.has(host)) {
2605
+ throw new Error(`outbound host not allowed: ${host}`);
2606
+ }
2607
+ return original(input, init);
2608
+ };
2609
+ }
2610
+ function runWithFetchPolicy(allowedHosts, fn) {
2611
+ installFetchPolicyShim();
2612
+ return policyStore.run(new Set(allowedHosts), fn);
2613
+ }
2614
+ function hostOf(input) {
2615
+ try {
2616
+ const raw = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
2617
+ const host = new URL(raw).hostname;
2618
+ return host.startsWith("[") && host.endsWith("]") ? host.slice(1, -1) : host;
2619
+ } catch {
2620
+ return;
2621
+ }
2622
+ }
2623
+
2624
+ // src/runtime/functions/pgredis.ts
2625
+ import { AsyncLocalStorage as AsyncLocalStorage4 } from "async_hooks";
2533
2626
  var CACHE_NAMESPACE = "supacloud-edge-runtime";
2534
2627
  var CACHE_TABLE = "public.supacloud_pgredis_kv";
2535
2628
  var MAX_KEY_CHARACTERS = 512;
@@ -2622,7 +2715,7 @@ class PgredisCache {
2622
2715
  });
2623
2716
  }
2624
2717
  }
2625
- var cacheContexts = new AsyncLocalStorage2;
2718
+ var cacheContexts = new AsyncLocalStorage4;
2626
2719
  var cacheFacade = Object.freeze({
2627
2720
  get: async (key) => activeCache().get(key),
2628
2721
  set: async (key, cacheValue, ttlMs) => activeCache().set(key, cacheValue, ttlMs),
@@ -2696,6 +2789,51 @@ async function upsertWithoutTtl(query, key, serializedValue) {
2696
2789
  }
2697
2790
 
2698
2791
  // src/runtime/functions/handler.ts
2792
+ var VERIFIED_JWT_SUBJECT_HEADER = "x-supacloud-jwt-sub";
2793
+ var UNSAFE_VERIFIED_JWT_SUBJECT = /[\u0000-\u001F\u007F-\u009F\u0100-\u{10FFFF}]/u;
2794
+ function verifiedSubject(value) {
2795
+ if (typeof value !== "string" || value.length === 0 || value.length > 1024)
2796
+ return null;
2797
+ if (value.trim() !== value || UNSAFE_VERIFIED_JWT_SUBJECT.test(value))
2798
+ return null;
2799
+ return value;
2800
+ }
2801
+ function withVerifiedJwtSubject(request, ctx) {
2802
+ const trustedRequest = request.clone();
2803
+ trustedRequest.headers.delete(VERIFIED_JWT_SUBJECT_HEADER);
2804
+ const subject = verifiedSubject(ctx.claims?.sub);
2805
+ if (subject !== null)
2806
+ trustedRequest.headers.set(VERIFIED_JWT_SUBJECT_HEADER, subject);
2807
+ return trustedRequest;
2808
+ }
2809
+ function isLoadedFunction(value) {
2810
+ return typeof value === "object" && value !== null && "handler" in value;
2811
+ }
2812
+ function normalizeEntry(value) {
2813
+ return isLoadedFunction(value) ? value : { handler: value };
2814
+ }
2815
+ function isFrameworkRouterHandler(handler) {
2816
+ if (!handler || typeof handler !== "object")
2817
+ return false;
2818
+ const candidate = handler;
2819
+ if (candidate.__supacloud?.routeAware === true)
2820
+ return true;
2821
+ return Array.isArray(candidate.routes) && (typeof candidate.handle === "function" || typeof candidate.fetch === "function");
2822
+ }
2823
+ function toFunctionLocalUrl(requestUrl) {
2824
+ const url = new URL(requestUrl);
2825
+ const publicRoute = url.pathname.match(/^\/functions\/v1\/[^/]+(\/.*)?$/);
2826
+ if (publicRoute) {
2827
+ url.pathname = publicRoute[1] || "/";
2828
+ return url.toString();
2829
+ }
2830
+ const internalRoute = url.pathname.match(/^\/[^/]+(\/.*)?$/);
2831
+ if (internalRoute) {
2832
+ url.pathname = internalRoute[1] || "/";
2833
+ }
2834
+ return url.toString();
2835
+ }
2836
+
2699
2837
  class FunctionsHandler {
2700
2838
  functions;
2701
2839
  env;
@@ -2716,22 +2854,130 @@ class FunctionsHandler {
2716
2854
  if (!name) {
2717
2855
  return json2(404, { error: "function name required: /functions/v1/<name>" });
2718
2856
  }
2719
- const fn = this.functions.get(name);
2720
- if (!fn) {
2857
+ const value = this.functions.get(name);
2858
+ if (!value) {
2721
2859
  return json2(404, { error: `function "${name}" not found` });
2722
2860
  }
2861
+ const entry = normalizeEntry(value);
2862
+ const limits = entry.limits;
2863
+ const capabilities = entry.capabilities;
2864
+ const maxBody = limits?.maxRequestBodyBytes;
2865
+ let request = req;
2866
+ if (maxBody !== undefined) {
2867
+ const contentLength = req.headers.get("content-length");
2868
+ if (contentLength !== null && Number(contentLength) > maxBody) {
2869
+ return json2(413, { error: `function "${name}" request body exceeded ${maxBody} bytes` });
2870
+ }
2871
+ if (contentLength === null && req.body) {
2872
+ request = withCountedBody(request, maxBody);
2873
+ }
2874
+ }
2875
+ const routeAware = entry.framework !== undefined && entry.framework !== "fetch" || isFrameworkRouterHandler(entry.handler);
2876
+ request = withVerifiedJwtSubject(request, ctx);
2877
+ if (routeAware)
2878
+ request = new Request(toFunctionLocalUrl(request.url), request);
2879
+ const timeoutMs = limits?.timeoutMs;
2880
+ const abort = timeoutMs !== undefined ? new AbortController : undefined;
2881
+ if (abort)
2882
+ request = withSignal(request, abort.signal);
2723
2883
  try {
2724
- const invoke = () => Promise.resolve(fn(req, { auth: ctx, env: this.env }));
2725
- const res = await runWithDenoEnv(this.env, () => runWithPgredisCache(this.pgredis, invoke));
2884
+ const env = capabilities?.secrets ? filterSecretsEnv(this.env, capabilities.secrets) : this.env;
2885
+ const invoke = () => this.invoke(entry.handler, request, ctx, env);
2886
+ const inner = () => runWithDenoEnv(env, () => runWithPgredisCache(this.pgredis, invoke));
2887
+ const run = capabilities?.outboundHosts ? () => runWithFetchPolicy(capabilities.outboundHosts, inner) : inner;
2888
+ const invokeWithBackground = () => runWithBackgroundTasks({ allowed: capabilities?.background !== false, timeoutMs: limits?.waitUntilTimeoutMs }, run);
2889
+ const res = timeoutMs !== undefined ? await this.withTimeout(name, timeoutMs, invokeWithBackground, abort) : await invokeWithBackground();
2726
2890
  if (!(res instanceof Response)) {
2727
2891
  return json2(500, { error: `function "${name}" did not return a Response` });
2728
2892
  }
2729
- return res;
2893
+ const maxResponse = limits?.maxResponseBodyBytes;
2894
+ return maxResponse !== undefined ? withResponseLimit(name, res, maxResponse) : res;
2730
2895
  } catch (e) {
2731
2896
  const message = e instanceof Error ? e.message : String(e);
2732
2897
  return json2(500, { error: message });
2733
2898
  }
2734
2899
  }
2900
+ async withTimeout(name, timeoutMs, run, abort) {
2901
+ let timer;
2902
+ const pending = run();
2903
+ try {
2904
+ const winner = await Promise.race([
2905
+ pending.then((res) => ({ timedOut: false, res })),
2906
+ new Promise((resolve) => {
2907
+ timer = setTimeout(() => resolve({ timedOut: true }), timeoutMs);
2908
+ })
2909
+ ]);
2910
+ if (winner.timedOut) {
2911
+ abort.abort();
2912
+ pending.then(() => {}, () => {});
2913
+ return json2(504, { error: `function "${name}" timed out after ${timeoutMs}ms` });
2914
+ }
2915
+ return winner.res;
2916
+ } finally {
2917
+ if (timer)
2918
+ clearTimeout(timer);
2919
+ }
2920
+ }
2921
+ invoke(handler, req, ctx, env) {
2922
+ if (typeof handler === "function") {
2923
+ return Promise.resolve(handler(req, { auth: ctx, env }));
2924
+ }
2925
+ if (typeof handler.handle === "function") {
2926
+ return Promise.resolve(handler.handle.call(handler, req));
2927
+ }
2928
+ if (typeof handler.fetch === "function") {
2929
+ return Promise.resolve(handler.fetch.call(handler, req));
2930
+ }
2931
+ throw new Error("function handler must be a function or an object with handle()/fetch()");
2932
+ }
2933
+ }
2934
+ var BASE_ENV_KEYS = ["SUPABASE_URL", "SUPABASE_ANON_KEY", "SUPABASE_SERVICE_ROLE_KEY"];
2935
+ function filterSecretsEnv(env, secrets) {
2936
+ const out = {};
2937
+ for (const key of BASE_ENV_KEYS)
2938
+ out[key] = env[key];
2939
+ for (const key of secrets) {
2940
+ if (env[key] !== undefined)
2941
+ out[key] = env[key];
2942
+ }
2943
+ return out;
2944
+ }
2945
+ function withCountedBody(req, limit) {
2946
+ let seen = 0;
2947
+ const counter = new TransformStream({
2948
+ transform(chunk, controller) {
2949
+ seen += chunk.byteLength;
2950
+ if (seen > limit) {
2951
+ controller.error(new Error(`request body exceeded ${limit} bytes`));
2952
+ return;
2953
+ }
2954
+ controller.enqueue(chunk);
2955
+ }
2956
+ });
2957
+ return new Request(req, { body: req.body.pipeThrough(counter), duplex: "half" });
2958
+ }
2959
+ function withResponseLimit(name, res, limit) {
2960
+ const contentLength = res.headers.get("content-length");
2961
+ if (contentLength !== null && Number(contentLength) > limit) {
2962
+ return json2(502, { error: `function "${name}" response exceeded ${limit} bytes` });
2963
+ }
2964
+ if (!res.body)
2965
+ return res;
2966
+ let seen = 0;
2967
+ const counter = new TransformStream({
2968
+ transform(chunk, controller) {
2969
+ seen += chunk.byteLength;
2970
+ if (seen > limit) {
2971
+ controller.error(new Error(`function "${name}" response exceeded ${limit} bytes`));
2972
+ return;
2973
+ }
2974
+ controller.enqueue(chunk);
2975
+ }
2976
+ });
2977
+ return new Response(res.body.pipeThrough(counter), res);
2978
+ }
2979
+ function withSignal(req, signal) {
2980
+ return new Request(req, { signal, ...req.body ? { duplex: "half" } : {} });
2735
2981
  }
2736
2982
  function json2(status, body) {
2737
2983
  return new Response(JSON.stringify(body), {
@@ -9968,9 +10214,9 @@ class RetentionService {
9968
10214
  }
9969
10215
 
9970
10216
  // src/runtime/security.ts
9971
- var LOOPBACK_HOSTS = new Set(["127.0.0.1", "localhost", "::1", "", undefined]);
10217
+ var LOOPBACK_HOSTS2 = new Set(["127.0.0.1", "localhost", "::1", "", undefined]);
9972
10218
  function isNetworkExposed(host) {
9973
- return !LOOPBACK_HOSTS.has(host);
10219
+ return !LOOPBACK_HOSTS2.has(host);
9974
10220
  }
9975
10221
  function assertSecretsSafe(input) {
9976
10222
  const { host, jwtSecret, vaultKeyDerived, warn } = input;
@@ -12404,6 +12650,35 @@ function readFunctions(root) {
12404
12650
  const entrypoint = getString(t, "entrypoint");
12405
12651
  if (entrypoint !== undefined)
12406
12652
  opts.entrypoint = entrypoint;
12653
+ const framework = getString(t, "framework");
12654
+ if (framework !== undefined) {
12655
+ if (framework === "fetch" || framework === "elysia" || framework === "hono") {
12656
+ opts.framework = framework;
12657
+ } else {
12658
+ console.warn(` warning: [functions.${name}] framework "${framework}" is not one of fetch/elysia/hono; falling back to fetch`);
12659
+ }
12660
+ }
12661
+ const timeoutMs = getInt(t, "timeout_ms");
12662
+ if (timeoutMs !== undefined && timeoutMs > 0)
12663
+ opts.timeoutMs = timeoutMs;
12664
+ const maxRequestBodyBytes = getInt(t, "max_request_body_bytes");
12665
+ if (maxRequestBodyBytes !== undefined && maxRequestBodyBytes > 0)
12666
+ opts.maxRequestBodyBytes = maxRequestBodyBytes;
12667
+ const maxResponseBodyBytes = getInt(t, "max_response_body_bytes");
12668
+ if (maxResponseBodyBytes !== undefined && maxResponseBodyBytes > 0)
12669
+ opts.maxResponseBodyBytes = maxResponseBodyBytes;
12670
+ const waitUntilTimeoutMs = getInt(t, "wait_until_timeout_ms");
12671
+ if (waitUntilTimeoutMs !== undefined && waitUntilTimeoutMs > 0)
12672
+ opts.waitUntilTimeoutMs = waitUntilTimeoutMs;
12673
+ const outboundHosts = getStringArray(t, "outbound_hosts");
12674
+ if (outboundHosts !== undefined)
12675
+ opts.outboundHosts = outboundHosts;
12676
+ const secrets = getStringArray(t, "secrets");
12677
+ if (secrets !== undefined)
12678
+ opts.secrets = secrets;
12679
+ const background = getBool(t, "background");
12680
+ if (background !== undefined)
12681
+ opts.background = background;
12407
12682
  out[name] = opts;
12408
12683
  }
12409
12684
  return out;
@@ -12514,6 +12789,15 @@ async function loadFunctionEnv(projectDir) {
12514
12789
  }
12515
12790
  return env;
12516
12791
  }
12792
+ var FUNCTION_FRAMEWORKS = new Set(["fetch", "elysia", "hono"]);
12793
+ function resolveFramework(name, value) {
12794
+ if (value === undefined)
12795
+ return;
12796
+ if (FUNCTION_FRAMEWORKS.has(value))
12797
+ return value;
12798
+ console.warn(` warning: function "${name}" has unsupported framework "${value}", expected one of fetch/elysia/hono; falling back to fetch`);
12799
+ return;
12800
+ }
12517
12801
  var loadQueue = Promise.resolve();
12518
12802
  async function loadFunctions2(projectDir, options = {}) {
12519
12803
  let releaseQueue;
@@ -12568,11 +12852,28 @@ async function loadFunctionsUnlocked(projectDir, options) {
12568
12852
  const mod = await import(importUrl);
12569
12853
  const denoHandler = takeCapturedHandler();
12570
12854
  const defaultExport = mod.default;
12571
- const handler = typeof defaultExport === "function" ? defaultExport : defaultExport && typeof defaultExport.fetch === "function" ? defaultExport.fetch.bind(defaultExport) : denoHandler ? (req) => denoHandler(req) : undefined;
12855
+ const handler = typeof defaultExport === "function" ? defaultExport : defaultExport && (typeof defaultExport.handle === "function" || typeof defaultExport.fetch === "function") ? defaultExport : denoHandler ? (req) => denoHandler(req) : undefined;
12572
12856
  if (handler) {
12573
- functions.set(name, handler);
12857
+ const opts = options[name];
12858
+ const limits = opts && (opts.timeoutMs !== undefined || opts.maxRequestBodyBytes !== undefined || opts.maxResponseBodyBytes !== undefined || opts.waitUntilTimeoutMs !== undefined) ? {
12859
+ ...opts.timeoutMs !== undefined ? { timeoutMs: opts.timeoutMs } : {},
12860
+ ...opts.maxRequestBodyBytes !== undefined ? { maxRequestBodyBytes: opts.maxRequestBodyBytes } : {},
12861
+ ...opts.maxResponseBodyBytes !== undefined ? { maxResponseBodyBytes: opts.maxResponseBodyBytes } : {},
12862
+ ...opts.waitUntilTimeoutMs !== undefined ? { waitUntilTimeoutMs: opts.waitUntilTimeoutMs } : {}
12863
+ } : undefined;
12864
+ const capabilities = opts && (opts.outboundHosts !== undefined || opts.secrets !== undefined || opts.background !== undefined) ? {
12865
+ ...opts.outboundHosts !== undefined ? { outboundHosts: opts.outboundHosts } : {},
12866
+ ...opts.secrets !== undefined ? { secrets: opts.secrets } : {},
12867
+ ...opts.background !== undefined ? { background: opts.background } : {}
12868
+ } : undefined;
12869
+ functions.set(name, {
12870
+ handler,
12871
+ framework: resolveFramework(name, opts?.framework),
12872
+ ...limits ? { limits } : {},
12873
+ ...capabilities ? { capabilities } : {}
12874
+ });
12574
12875
  } else {
12575
- console.warn(` warning: function "${name}" has no default function, fetch object, or Deno.serve() handler, skipped`);
12876
+ console.warn(` warning: function "${name}" has no default function, handle/fetch object, or Deno.serve() handler, skipped`);
12576
12877
  }
12577
12878
  } catch (e) {
12578
12879
  const msg = e instanceof Error ? e.message : String(e);
@@ -0,0 +1,15 @@
1
+ /** Install globalThis.EdgeRuntime.waitUntil once per process (idempotent). */
2
+ export declare function installEdgeRuntimeShim(): void;
3
+ /**
4
+ * Run `fn` with an EdgeRuntime.waitUntil scope. When `fn` settles, its
5
+ * background tasks are flushed without blocking the returned value: the flush
6
+ * waits for allSettled up to `timeoutMs` (wait_until_timeout_ms), after which
7
+ * it stops waiting and warns - like production, abandoned tasks keep running.
8
+ * Lite backend close() does not wait for in-flight background tasks; tasks
9
+ * still drifting at shutdown are dropped with the process.
10
+ */
11
+ export declare function runWithBackgroundTasks<T>(options: {
12
+ allowed: boolean;
13
+ timeoutMs?: number;
14
+ }, fn: () => Promise<T>): Promise<T>;
15
+ //# sourceMappingURL=edge-runtime-shim.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"edge-runtime-shim.d.ts","sourceRoot":"","sources":["../../../src/runtime/functions/edge-runtime-shim.ts"],"names":[],"mappings":"AA2CA,8EAA8E;AAC9E,wBAAgB,sBAAsB,IAAI,IAAI,CAiB7C;AAED;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,EACtC,OAAO,EAAE;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,EACjD,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GACnB,OAAO,CAAC,CAAC,CAAC,CAWZ"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Run `fn` with fetch restricted to `allowedHosts` (plus loopback). The
3
+ * binding lives in an async-context store, so it stays correct across awaits
4
+ * and never leaks into other invocations - there is nothing to restore.
5
+ */
6
+ export declare function runWithFetchPolicy<T>(allowedHosts: string[], fn: () => Promise<T>): Promise<T>;
7
+ //# sourceMappingURL=fetch-policy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch-policy.d.ts","sourceRoot":"","sources":["../../../src/runtime/functions/fetch-policy.ts"],"names":[],"mappings":"AAsCA;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,YAAY,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAG9F"}
@@ -2,14 +2,82 @@
2
2
  * Edge Functions (/functions/v1/*) - supabase.functions.invoke() support.
3
3
  *
4
4
  * A "function" is any fetch handler: (Request) => Response | Promise<Response>.
5
+ * Framework router objects (Elysia `app.handle()`, Hono `app.fetch()`) are
6
+ * supported too, aligned with the SupaCloud Edge Runtime contract: route-aware
7
+ * handlers receive a function-local URL (`/functions/v1/<name>/a/b` -> `/a/b`).
5
8
  * The core takes a name → handler map (portable, works in the browser); the
6
9
  * Node CLI populates it from supabase/functions/<name>/index.{ts,js,mjs}
7
- * modules that `export default` a fetch handler.
10
+ * modules that `export default` a handler.
8
11
  */
9
12
  import type { RequestContext } from '../types.js';
10
13
  import { type PgredisCache } from './pgredis.js';
11
14
  /** An edge function: a fetch handler invoked with the resolved request context. */
12
15
  export type EdgeFunction = (req: Request, ctx: FunctionContext) => Response | Promise<Response>;
16
+ /** Frameworks whose router objects own the path below /functions/v1/<name>. */
17
+ export type FunctionFramework = 'fetch' | 'elysia' | 'hono';
18
+ /**
19
+ * A framework router export, e.g. an Elysia instance (`handle()`) or a Hono /
20
+ * Itty router (`fetch()`). Object handlers receive only the Request.
21
+ */
22
+ export interface FrameworkObjectHandler {
23
+ handle?: (req: Request) => Response | Promise<Response>;
24
+ fetch?: (req: Request) => Response | Promise<Response>;
25
+ /** Router route table (Elysia exposes one); marks the handler route-aware. */
26
+ routes?: unknown;
27
+ /** Explicit marker emitted by framework adapters. */
28
+ __supacloud?: {
29
+ routeAware?: boolean;
30
+ };
31
+ }
32
+ /** Anything registerable as a function: plain fetch handler or router object. */
33
+ export type FunctionHandler = EdgeFunction | FrameworkObjectHandler;
34
+ /**
35
+ * Per-invocation resource limits, aligned with the Edge Runtime Manifest v2
36
+ * `limits` block (timeout_ms / max_request_body_bytes /
37
+ * max_response_body_bytes / wait_until_timeout_ms). Lite defaults to no
38
+ * limit when undeclared; production caps at 900s / 30MB.
39
+ */
40
+ export interface FunctionLimits {
41
+ /** limits.timeout_ms: max wall time per invocation; on expiry the request is aborted and a 504 returned. */
42
+ timeoutMs?: number;
43
+ /** limits.max_request_body_bytes: max inbound body size; oversized bodies get a 413. */
44
+ maxRequestBodyBytes?: number;
45
+ /** limits.max_response_body_bytes: max outbound body size; oversized responses get a 502 / cut stream. */
46
+ maxResponseBodyBytes?: number;
47
+ /** limits.wait_until_timeout_ms: max time to wait for EdgeRuntime.waitUntil tasks after the response. */
48
+ waitUntilTimeoutMs?: number;
49
+ }
50
+ /**
51
+ * Declared capabilities, aligned with the Edge Runtime Manifest v2
52
+ * `capabilities` block (secrets / outbound_hosts / background). Undeclared
53
+ * means unrestricted (back-compat).
54
+ */
55
+ export interface FunctionCapabilities {
56
+ /** capabilities.secrets: env keys (beyond the SUPABASE_* base trio) visible to the function. */
57
+ secrets?: string[];
58
+ /** capabilities.outbound_hosts: exact fetch host allowlist (no port); loopback is always allowed. */
59
+ outboundHosts?: string[];
60
+ /**
61
+ * capabilities.background: whether EdgeRuntime.waitUntil is enabled. Lite
62
+ * defaults to allowed (local back-compat); only an explicit `false` takes
63
+ * the production error path.
64
+ */
65
+ background?: boolean;
66
+ }
67
+ /** A loaded function plus its declared framework profile, limits, and capabilities. */
68
+ export interface LoadedFunction {
69
+ handler: FunctionHandler;
70
+ /** config.toml [functions.<name>].framework; `fetch` keeps legacy routing. */
71
+ framework?: FunctionFramework;
72
+ /** config.toml [functions.<name>] timeout_ms / max_request_body_bytes / max_response_body_bytes / wait_until_timeout_ms. */
73
+ limits?: FunctionLimits;
74
+ /** config.toml [functions.<name>] secrets / outbound_hosts / background. */
75
+ capabilities?: FunctionCapabilities;
76
+ }
77
+ /** Registry value: a bare handler or a {@link LoadedFunction} entry. */
78
+ export type FunctionRegistryValue = FunctionHandler | LoadedFunction;
79
+ /** Header written only after Lite has verified the request JWT. */
80
+ export declare const VERIFIED_JWT_SUBJECT_HEADER = "x-supacloud-jwt-sub";
13
81
  /** Second argument passed to every {@link EdgeFunction} invocation. */
14
82
  export interface FunctionContext {
15
83
  /** verified request context (role + JWT claims) resolved by the router */
@@ -22,17 +90,34 @@ export interface FunctionContext {
22
90
  [key: string]: string;
23
91
  };
24
92
  }
93
+ /** Mirrors the Edge Runtime: router objects and marked handlers own sub-paths. */
94
+ export declare function isFrameworkRouterHandler(handler: unknown): boolean;
95
+ /**
96
+ * Strip the function prefix so framework routers see their own route table:
97
+ * /functions/v1/<name>/a/b -> /a/b (and /functions/v1/<name> -> /).
98
+ * Matches the Edge Runtime's toFunctionLocalUrl().
99
+ */
100
+ export declare function toFunctionLocalUrl(requestUrl: string): string;
25
101
  /** Registry and dispatcher for edge functions, backing supabase.functions.invoke(). */
26
102
  export declare class FunctionsHandler {
27
103
  private functions;
28
104
  private env;
29
105
  private pgredis;
30
- constructor(functions: Map<string, EdgeFunction>, env: FunctionContext['env'], pgredis: PgredisCache);
106
+ constructor(functions: Map<string, FunctionRegistryValue>, env: FunctionContext['env'], pgredis: PgredisCache);
31
107
  /** Register (or replace) a function under `name`, served at /functions/v1/<name>. */
32
- register(name: string, fn: EdgeFunction): void;
108
+ register(name: string, fn: FunctionRegistryValue): void;
33
109
  /** Names of all registered functions. */
34
110
  list(): string[];
35
- /** Dispatch a /functions/v1/<name> request to its handler, returning a 404 when unknown and a 500 when the handler throws or returns a non-Response. */
111
+ /**
112
+ * Dispatch a /functions/v1/<name> request to its handler, returning a 404 when
113
+ * unknown and a 500 when the handler throws or returns a non-Response.
114
+ * Declared limits/capabilities are enforced in order: request body size (413),
115
+ * invocation timeout (504), outbound host allowlist, secrets allowlist,
116
+ * EdgeRuntime.waitUntil background scope, response body size (502).
117
+ */
36
118
  handle(req: Request, ctx: RequestContext, url: URL): Promise<Response>;
119
+ /** Race the invocation against `timeoutMs`; on timeout abort the request and answer 504. */
120
+ private withTimeout;
121
+ private invoke;
37
122
  }
38
123
  //# sourceMappingURL=handler.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../../src/runtime/functions/handler.ts"],"names":[],"mappings":"AAAA;;;;;;;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,EAAE,cAAc,EAAE,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,QAAQ,CAAC,CA2E3E;IAED,4FAA4F;YAC9E,WAAW;IA4BzB,OAAO,CAAC,MAAM;CAiBf"}
@@ -18,10 +18,11 @@ export { SmsInbox, type SmsInboxEntry } from './auth/sms-inbox.js';
18
18
  export { LogBuffer, type LogEntry, type LogLevel } from './log-buffer.js';
19
19
  export { RealtimeEngine, type RealtimeSocketLike } from './realtime/engine.js';
20
20
  export { signJwt, verifyJwt, decodeJwt } from './jwt.js';
21
- export { FunctionsHandler, type EdgeFunction, type FunctionContext } from './functions/handler.js';
21
+ export { FunctionsHandler, VERIFIED_JWT_SUBJECT_HEADER, isFrameworkRouterHandler, toFunctionLocalUrl, type EdgeFunction, type FrameworkObjectHandler, type FunctionCapabilities, type FunctionContext, type FunctionFramework, type FunctionHandler, type FunctionLimits, type FunctionRegistryValue, type LoadedFunction, } from './functions/handler.js';
22
22
  export { type PgredisCacheBinding } from './functions/pgredis.js';
23
23
  export { generateTypes } from './gen-types.js';
24
24
  export { installDenoShim } from './functions/deno-shim.js';
25
+ export { installEdgeRuntimeShim } from './functions/edge-runtime-shim.js';
25
26
  export { WebhooksService, type WebhookConfig, type WebhookDelivery } from './webhooks/service.js';
26
27
  export { CronService, cronMatches } from './cron/service.js';
27
28
  export { NetService, type NetDelivery } from './net/service.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAE9C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,gBAAgB,EAAqB,MAAM,wBAAwB,CAAA;AAG5E,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAE3C,OAAO,EAAE,cAAc,EAAE,MA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A;IACxB,6EAA6E;IAC7E,SAAS,EAAE,gBAAgB,CAAA;IAC3B,qEAAqE;IACrE,QAAQ,EAAE,eAAe,CAAA;IACzB,mCAAmC;IACnC,IAAI,EAAE,WAAW,CAAA;IACjB,wDAAwD;IACxD,GAAG,EAAE,UAAU,CAAA;IACf,6EAA6E;IAC7E,SAAS,EAAE,gBAAgB,CAAA;IAC3B,gEAAgE;IAChE,OAAO,EAAE,MAAM,CAAA;IACf,+CAA+C;IAC/C,cAAc,EAAE,MAAM,CAAA;IACtB,oFAAoF;IACpF,SAAS,EAAE,MAAM,CAAA;IACjB,kEAAkE;IAClE,IAAI,EAAE,SAAS,CAAA;IACf,4FAA4F;IAC5F,KAAK,EAAE,WAAW,GAAG,IAAI,CAAA;IACzB,gHAAgH;IAChH,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAA;IACzB,8CAA8C;IAC9C,OAAO,EAAE,CAAC,UAAU,EAAE,aAAa,EAAE,EAAE,OAAO,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,EAAE,CAAC,CAAA;IAC7E,gGAAgG;IAChG,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAC3B;AAWD;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,aAAa,CAAC,MAAM,GAAE,aAAkB,GAAG,OAAO,CAAC,oBAAoB,CAAC,CA+W7F"}
@@ -76,6 +76,22 @@ export interface FunctionOptions {
76
76
  verifyJwt?: boolean;
77
77
  /** [functions.<name>].entrypoint, relative to the project root */
78
78
  entrypoint?: string;
79
+ /** [functions.<name>].framework: fetch (default), elysia, or hono */
80
+ framework?: import('../functions/handler.js').FunctionFramework;
81
+ /** [functions.<name>].timeout_ms: invocation timeout (Edge Runtime limits.timeout_ms) */
82
+ timeoutMs?: number;
83
+ /** [functions.<name>].max_request_body_bytes (Edge Runtime limits.max_request_body_bytes) */
84
+ maxRequestBodyBytes?: number;
85
+ /** [functions.<name>].max_response_body_bytes (Edge Runtime limits.max_response_body_bytes) */
86
+ maxResponseBodyBytes?: number;
87
+ /** [functions.<name>].wait_until_timeout_ms (Edge Runtime limits.wait_until_timeout_ms) */
88
+ waitUntilTimeoutMs?: number;
89
+ /** [functions.<name>].outbound_hosts: fetch host allowlist (Edge Runtime capabilities.outbound_hosts) */
90
+ outboundHosts?: string[];
91
+ /** [functions.<name>].secrets: env keys exposed to the function (Edge Runtime capabilities.secrets) */
92
+ secrets?: string[];
93
+ /** [functions.<name>].background: EdgeRuntime.waitUntil gate (Edge Runtime capabilities.background); lite defaults to true */
94
+ background?: boolean;
79
95
  }
80
96
  /** Parse supabase/config.toml once and project it into a {@link ProjectConfig}. */
81
97
  export declare function loadProjectConfig(projectDir: string, env?: Environment): ProjectConfig;
@@ -1 +1 @@
1
- {"version":3,"file":"load-config.d.ts","sourceRoot":"","sources":["../../../src/runtime/node/load-config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AACvD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAA;AAC3D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AAC1D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,EAUL,KAAK,WAAW,EACjB,MAAM,kBAAkB,CAAA;AAEzB,oFAAoF;AACpF,MAAM,WAAW,aAAa;IAC5B,0EAA0E;IAC1E,IAAI,EAAE,UAAU,CAAA;IAChB,mDAAmD;IACnD,GAAG,EAAE,SAAS,CAAA;IACd,kEAAkE;IAClE,OAAO,EAAE,aAAa,CAAA;IACtB,gDAAgD;IAChD,IAAI,EAAE,UAAU,CAAA;IAChB,uEAAuE;IACvE,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAA;CAC3C;AAED,yFAAyF;AACzF,MAAM,WAAW,UAAU;IACzB,uDAAuD;IACvD,OAAO,CAAC,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