tinbase 0.11.0 → 0.11.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.
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal `Deno` global shim so Supabase-style edge functions run unchanged
|
|
3
|
+
* under Node/Bun. Supabase functions are written for Deno:
|
|
4
|
+
*
|
|
5
|
+
* Deno.serve((req) => new Response(...))
|
|
6
|
+
* const url = Deno.env.get('SUPABASE_URL')
|
|
7
|
+
*
|
|
8
|
+
* Instead of starting a server, our `Deno.serve` captures the handler so the
|
|
9
|
+
* FunctionsHandler can invoke it per request; `Deno.env` reads only the
|
|
10
|
+
* injected SUPABASE_* vars and declared function secrets (never the host
|
|
11
|
+
* process.env).
|
|
12
|
+
*
|
|
13
|
+
* Not resolved: `npm:` / `jsr:` / URL import specifiers and the Deno std lib -
|
|
14
|
+
* a function using those needs a bundling step. Functions that stick to Web
|
|
15
|
+
* APIs (fetch/Request/Response) + Deno.serve/Deno.env work as-is.
|
|
16
|
+
*/
|
|
1
17
|
type DenoHandler = (req: Request) => Response | Promise<Response>;
|
|
2
18
|
/**
|
|
3
19
|
* Run `fn` with the shim's Deno.env bound to `env`. The binding lives in an
|
|
@@ -1,28 +1,46 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Minimal `Deno` global shim so Supabase-style edge functions run unchanged
|
|
3
|
-
* under Node/Bun. Supabase functions are written for Deno:
|
|
4
|
-
*
|
|
5
|
-
* Deno.serve((req) => new Response(...))
|
|
6
|
-
* const url = Deno.env.get('SUPABASE_URL')
|
|
7
|
-
*
|
|
8
|
-
* Instead of starting a server, our `Deno.serve` captures the handler so the
|
|
9
|
-
* FunctionsHandler can invoke it per request; `Deno.env` reads only the
|
|
10
|
-
* injected SUPABASE_* vars and declared function secrets (never the host
|
|
11
|
-
* process.env).
|
|
12
|
-
*
|
|
13
|
-
* Not resolved: `npm:` / `jsr:` / URL import specifiers and the Deno std lib -
|
|
14
|
-
* a function using those needs a bundling step. Functions that stick to Web
|
|
15
|
-
* APIs (fetch/Request/Response) + Deno.serve/Deno.env work as-is.
|
|
16
|
-
*/
|
|
17
|
-
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
18
1
|
const captured = {};
|
|
19
2
|
// The Deno global is installed once per process, but each backend (and each
|
|
20
|
-
// in-flight invocation) has its own function env.
|
|
21
|
-
// the env to the invocation's async context, so it stays correct across
|
|
22
|
-
// even when two invocations interleave on the event loop - a
|
|
23
|
-
// was swapped around `await` would let a later call
|
|
24
|
-
// env mid-flight.
|
|
25
|
-
|
|
3
|
+
// in-flight invocation) has its own function env. On Node an AsyncLocalStorage
|
|
4
|
+
// scopes the env to the invocation's async context, so it stays correct across
|
|
5
|
+
// awaits even when two invocations interleave on the event loop - a
|
|
6
|
+
// module-global that was swapped around `await` would let a later call
|
|
7
|
+
// overwrite an earlier call's env mid-flight.
|
|
8
|
+
//
|
|
9
|
+
// This module is reachable from the package root, which browser apps bundle to
|
|
10
|
+
// run tinbase in-page (pg-mem previews) - so it must not statically import
|
|
11
|
+
// `node:async_hooks`, a Node-only builtin that client bundlers refuse to
|
|
12
|
+
// resolve. `process.getBuiltinModule` (Node >= 22.3, within our engines range)
|
|
13
|
+
// loads it synchronously without an import statement bundlers can see. A
|
|
14
|
+
// Deno.env read outside any invocation sees an empty env.
|
|
15
|
+
function createEnvStore() {
|
|
16
|
+
const proc = globalThis.process;
|
|
17
|
+
const hooks = proc?.getBuiltinModule?.('node:async_hooks');
|
|
18
|
+
if (hooks?.AsyncLocalStorage)
|
|
19
|
+
return new hooks.AsyncLocalStorage();
|
|
20
|
+
// Non-Node runtime: bind the env for the duration of the returned promise.
|
|
21
|
+
// Unlike AsyncLocalStorage this can't isolate interleaved invocations from
|
|
22
|
+
// each other, but browser previews invoke functions one at a time.
|
|
23
|
+
let current;
|
|
24
|
+
return {
|
|
25
|
+
getStore: () => current,
|
|
26
|
+
run(env, fn) {
|
|
27
|
+
const prev = current;
|
|
28
|
+
current = env;
|
|
29
|
+
let result;
|
|
30
|
+
try {
|
|
31
|
+
result = fn();
|
|
32
|
+
}
|
|
33
|
+
catch (e) {
|
|
34
|
+
current = prev;
|
|
35
|
+
throw e;
|
|
36
|
+
}
|
|
37
|
+
return Promise.resolve(result).finally(() => {
|
|
38
|
+
current = prev;
|
|
39
|
+
});
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
const envStore = createEnvStore();
|
|
26
44
|
/**
|
|
27
45
|
* Run `fn` with the shim's Deno.env bound to `env`. The binding lives in an
|
|
28
46
|
* async-context store, so concurrent invocations each read their own env and
|
|
@@ -66,7 +84,7 @@ export function installDenoShim() {
|
|
|
66
84
|
toObject: () => ({ ...(envStore.getStore() ?? {}) }),
|
|
67
85
|
},
|
|
68
86
|
// enough of the surface that idiomatic functions don't crash on reference
|
|
69
|
-
cwd: () => process
|
|
87
|
+
cwd: () => globalThis.process?.cwd?.() ?? '/',
|
|
70
88
|
// a function must not be able to terminate the whole server; throw instead
|
|
71
89
|
// of calling process.exit.
|
|
72
90
|
exit: (code) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deno-shim.js","sourceRoot":"","sources":["../../src/functions/deno-shim.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"deno-shim.js","sourceRoot":"","sources":["../../src/functions/deno-shim.ts"],"names":[],"mappings":"AAkBA,MAAM,QAAQ,GAA8B,EAAE,CAAA;AAS9C,4EAA4E;AAC5E,+EAA+E;AAC/E,+EAA+E;AAC/E,oEAAoE;AACpE,uEAAuE;AACvE,8CAA8C;AAC9C,EAAE;AACF,+EAA+E;AAC/E,2EAA2E;AAC3E,yEAAyE;AACzE,+EAA+E;AAC/E,yEAAyE;AACzE,0DAA0D;AAC1D,SAAS,cAAc;IACrB,MAAM,IAAI,GAAI,UAA2E,CAAC,OAAO,CAAA;IACjG,MAAM,KAAK,GAAG,IAAI,EAAE,gBAAgB,E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O,EAAE,GAAG,EAAE,EAAE,IAAI,GAAG;QACvF,2EAA2E;QAC3E,2BAA2B;QAC3B,IAAI,EAAE,CAAC,IAAa,EAAE,EAAE;YACtB,MAAM,IAAI,KAAK,CAAC,aAAa,IAAI,IAAI,CAAC,wCAAwC,CAAC,CAAA;QACjF,CAAC;KACF,CAAA;AACH,CAAC;AAED,kFAAkF;AAClF,MAAM,UAAU,mBAAmB;IACjC,MAAM,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAA;IAC1B,QAAQ,CAAC,OAAO,GAAG,SAAS,CAAA;IAC5B,OAAO,CAAC,CAAA;AACV,CAAC;AAED,wEAAwE;AACxE,MAAM,UAAU,oBAAoB;IAClC,QAAQ,CAAC,OAAO,GAAG,SAAS,CAAA;AAC9B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tinbase",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.1",
|
|
4
4
|
"description": "A Docker-free, Supabase-compatible local backend — real Postgres (embedded native or PGlite/WASM), wire-compatible with supabase-js.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "Sanket Sahu",
|