@rivetkit/supabase 2.3.0-rc.13
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/README.md +41 -0
- package/dist/mod.d.mts +33 -0
- package/dist/mod.d.ts +33 -0
- package/dist/mod.js +76 -0
- package/dist/mod.js.map +1 -0
- package/dist/mod.mjs +76 -0
- package/dist/mod.mjs.map +1 -0
- package/package.json +49 -0
package/README.md
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# @rivetkit/supabase
|
|
2
|
+
|
|
3
|
+
Supabase Edge Functions integration for [RivetKit](https://rivet.dev) actors.
|
|
4
|
+
|
|
5
|
+
Host Rivet Actors in a Supabase Edge Function (Deno) with a single import. The
|
|
6
|
+
wasm runtime and wasm binary loading are wired automatically.
|
|
7
|
+
|
|
8
|
+
```ts
|
|
9
|
+
import { actor } from "rivetkit";
|
|
10
|
+
import { serve } from "@rivetkit/supabase";
|
|
11
|
+
|
|
12
|
+
const counter = actor({
|
|
13
|
+
state: { count: 0 },
|
|
14
|
+
actions: {
|
|
15
|
+
increment: (c, amount = 1) => (c.state.count += amount),
|
|
16
|
+
getCount: (c) => c.state.count,
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
await serve({ use: { counter } });
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Set `RIVET_ENDPOINT` as a function secret (namespace and token may be embedded
|
|
24
|
+
in the URL as `https://namespace:token@host`).
|
|
25
|
+
|
|
26
|
+
## Mounting your own routes
|
|
27
|
+
|
|
28
|
+
Pass `fetch` to handle everything outside the Rivet manager API path:
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
await serve({ use: { counter } }, {
|
|
32
|
+
fetch: (request) => {
|
|
33
|
+
if (new URL(request.url).pathname.endsWith("/health")) {
|
|
34
|
+
return new Response("ok");
|
|
35
|
+
}
|
|
36
|
+
return new Response("not found", { status: 404 });
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Learn more at https://rivet.dev/docs.
|
package/dist/mod.d.mts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { RegistryActors, RegistryConfigInput, Registry } from 'rivetkit';
|
|
2
|
+
|
|
3
|
+
/** Config passed to `setup` / `serve`. The wasm runtime is wired automatically. */
|
|
4
|
+
type SupabaseSetupConfig<A extends RegistryActors> = Omit<RegistryConfigInput<A>, "runtime" | "wasm">;
|
|
5
|
+
/**
|
|
6
|
+
* Wraps rivetkit's `setup` with the Supabase Edge Functions WebAssembly runtime
|
|
7
|
+
* wired in. Returns a typed `Registry`, so you can derive a typed client with
|
|
8
|
+
* `createClient<typeof registry>(...)` and pass the same registry to `serve`.
|
|
9
|
+
*
|
|
10
|
+
* The wasm binary is loaded by `serve` (Deno reads it asynchronously), so this
|
|
11
|
+
* stays synchronous.
|
|
12
|
+
*/
|
|
13
|
+
declare function setup<A extends RegistryActors>(config: SupabaseSetupConfig<A>): Registry<A>;
|
|
14
|
+
interface ServeOptions {
|
|
15
|
+
/** Path the Rivet manager API is mounted at. Defaults to `/api/rivet`. */
|
|
16
|
+
managerPath?: string;
|
|
17
|
+
/** Handler for requests that fall outside the Rivet manager API path. */
|
|
18
|
+
fetch?: (request: Request) => Response | Promise<Response>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Serves Rivet Actors from a Supabase Edge Function (Deno) on the wasm runtime.
|
|
22
|
+
* Accepts either a registry from this package's `setup` or a setup config (which
|
|
23
|
+
* is wired through `setup` for you).
|
|
24
|
+
*
|
|
25
|
+
* The Rivet manager API is mounted at the configured `serverless.basePath`
|
|
26
|
+
* (or `managerPath`, default `/api/rivet`). Requests outside that path are
|
|
27
|
+
* routed to `options.fetch` if provided. The engine endpoint is read from
|
|
28
|
+
* `RIVET_ENDPOINT` (with `RIVET_NAMESPACE`, `RIVET_TOKEN`, `RIVET_POOL` optional)
|
|
29
|
+
* unless set in the config.
|
|
30
|
+
*/
|
|
31
|
+
declare function serve<A extends RegistryActors>(registryOrConfig: Registry<A> | SupabaseSetupConfig<A>, options?: ServeOptions): Promise<void>;
|
|
32
|
+
|
|
33
|
+
export { type ServeOptions, type SupabaseSetupConfig, serve, setup };
|
package/dist/mod.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { RegistryActors, RegistryConfigInput, Registry } from 'rivetkit';
|
|
2
|
+
|
|
3
|
+
/** Config passed to `setup` / `serve`. The wasm runtime is wired automatically. */
|
|
4
|
+
type SupabaseSetupConfig<A extends RegistryActors> = Omit<RegistryConfigInput<A>, "runtime" | "wasm">;
|
|
5
|
+
/**
|
|
6
|
+
* Wraps rivetkit's `setup` with the Supabase Edge Functions WebAssembly runtime
|
|
7
|
+
* wired in. Returns a typed `Registry`, so you can derive a typed client with
|
|
8
|
+
* `createClient<typeof registry>(...)` and pass the same registry to `serve`.
|
|
9
|
+
*
|
|
10
|
+
* The wasm binary is loaded by `serve` (Deno reads it asynchronously), so this
|
|
11
|
+
* stays synchronous.
|
|
12
|
+
*/
|
|
13
|
+
declare function setup<A extends RegistryActors>(config: SupabaseSetupConfig<A>): Registry<A>;
|
|
14
|
+
interface ServeOptions {
|
|
15
|
+
/** Path the Rivet manager API is mounted at. Defaults to `/api/rivet`. */
|
|
16
|
+
managerPath?: string;
|
|
17
|
+
/** Handler for requests that fall outside the Rivet manager API path. */
|
|
18
|
+
fetch?: (request: Request) => Response | Promise<Response>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Serves Rivet Actors from a Supabase Edge Function (Deno) on the wasm runtime.
|
|
22
|
+
* Accepts either a registry from this package's `setup` or a setup config (which
|
|
23
|
+
* is wired through `setup` for you).
|
|
24
|
+
*
|
|
25
|
+
* The Rivet manager API is mounted at the configured `serverless.basePath`
|
|
26
|
+
* (or `managerPath`, default `/api/rivet`). Requests outside that path are
|
|
27
|
+
* routed to `options.fetch` if provided. The engine endpoint is read from
|
|
28
|
+
* `RIVET_ENDPOINT` (with `RIVET_NAMESPACE`, `RIVET_TOKEN`, `RIVET_POOL` optional)
|
|
29
|
+
* unless set in the config.
|
|
30
|
+
*/
|
|
31
|
+
declare function serve<A extends RegistryActors>(registryOrConfig: Registry<A> | SupabaseSetupConfig<A>, options?: ServeOptions): Promise<void>;
|
|
32
|
+
|
|
33
|
+
export { type ServeOptions, type SupabaseSetupConfig, serve, setup };
|
package/dist/mod.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }// src/mod.ts
|
|
2
|
+
var _rivetkitwasm = require('@rivetkit/rivetkit-wasm'); var wasmBindings = _interopRequireWildcard(_rivetkitwasm);
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _rivetkit = require('rivetkit');
|
|
7
|
+
var DEFAULT_MANAGER_PATH = "/api/rivet";
|
|
8
|
+
function setup(config) {
|
|
9
|
+
return _rivetkit.setup.call(void 0, {
|
|
10
|
+
runtime: "wasm",
|
|
11
|
+
wasm: { bindings: wasmBindings },
|
|
12
|
+
noWelcome: true,
|
|
13
|
+
...config
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
var resolveWasmUrl = () => new URL(
|
|
17
|
+
import.meta.resolve("@rivetkit/rivetkit-wasm/rivetkit_wasm_bg.wasm")
|
|
18
|
+
);
|
|
19
|
+
function applyEnv(config, managerPath) {
|
|
20
|
+
var _a, _b;
|
|
21
|
+
if (!config.endpoint) {
|
|
22
|
+
const endpoint = Deno.env.get("RIVET_ENDPOINT");
|
|
23
|
+
if (endpoint) config.endpoint = endpoint;
|
|
24
|
+
}
|
|
25
|
+
if (!config.namespace) {
|
|
26
|
+
const namespace = Deno.env.get("RIVET_NAMESPACE");
|
|
27
|
+
if (namespace) config.namespace = namespace;
|
|
28
|
+
}
|
|
29
|
+
if (!config.token) {
|
|
30
|
+
const token = Deno.env.get("RIVET_TOKEN");
|
|
31
|
+
if (token) config.token = token;
|
|
32
|
+
}
|
|
33
|
+
const poolName = Deno.env.get("RIVET_POOL");
|
|
34
|
+
if (poolName && !((_a = config.envoy) == null ? void 0 : _a.poolName)) {
|
|
35
|
+
config.envoy = { ...config.envoy, poolName };
|
|
36
|
+
}
|
|
37
|
+
if (!((_b = config.serverless) == null ? void 0 : _b.basePath)) {
|
|
38
|
+
config.serverless = { ...config.serverless, basePath: managerPath };
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
async function serve(registryOrConfig, options = {}) {
|
|
42
|
+
var _a;
|
|
43
|
+
const registry = registryOrConfig instanceof _rivetkit.Registry ? registryOrConfig : setup(registryOrConfig);
|
|
44
|
+
const wasmModule = await Deno.readFile(resolveWasmUrl());
|
|
45
|
+
const config = registry.config;
|
|
46
|
+
config.wasm = {
|
|
47
|
+
...config.wasm,
|
|
48
|
+
bindings: wasmBindings,
|
|
49
|
+
initInput: wasmModule
|
|
50
|
+
};
|
|
51
|
+
const managerPath = _nullishCoalesce(_nullishCoalesce(((_a = config.serverless) == null ? void 0 : _a.basePath), () => ( options.managerPath)), () => ( DEFAULT_MANAGER_PATH));
|
|
52
|
+
applyEnv(config, managerPath);
|
|
53
|
+
const managerSegment = `${managerPath}/`;
|
|
54
|
+
Deno.serve((request) => {
|
|
55
|
+
const url = new URL(request.url);
|
|
56
|
+
if (url.pathname === managerPath || url.pathname.startsWith(managerSegment)) {
|
|
57
|
+
return registry.handler(request);
|
|
58
|
+
}
|
|
59
|
+
const prefixedIndex = url.pathname.indexOf(managerSegment);
|
|
60
|
+
if (prefixedIndex > 0) {
|
|
61
|
+
url.pathname = url.pathname.slice(prefixedIndex);
|
|
62
|
+
return registry.handler(new Request(url, request));
|
|
63
|
+
}
|
|
64
|
+
if (options.fetch) {
|
|
65
|
+
return options.fetch(request);
|
|
66
|
+
}
|
|
67
|
+
return new Response(
|
|
68
|
+
"This is a RivetKit server.\n\nLearn more at https://rivet.dev\n"
|
|
69
|
+
);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
exports.serve = serve; exports.setup = setup;
|
|
76
|
+
//# sourceMappingURL=mod.js.map
|
package/dist/mod.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/rivet/rivet/rivetkit-typescript/packages/supabase/dist/mod.js","../src/mod.ts"],"names":[],"mappings":"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","file":"/home/runner/work/rivet/rivet/rivetkit-typescript/packages/supabase/dist/mod.js","sourcesContent":[null,"import * as wasmBindings from \"@rivetkit/rivetkit-wasm\";\nimport {\n\tRegistry,\n\ttype RegistryActors,\n\ttype RegistryConfigInput,\n\tsetup as rivetkitSetup,\n} from \"rivetkit\";\n\nconst DEFAULT_MANAGER_PATH = \"/api/rivet\";\n\n/** Config passed to `setup` / `serve`. The wasm runtime is wired automatically. */\nexport type SupabaseSetupConfig<A extends RegistryActors> = Omit<\n\tRegistryConfigInput<A>,\n\t\"runtime\" | \"wasm\"\n>;\n\n/**\n * Wraps rivetkit's `setup` with the Supabase Edge Functions WebAssembly runtime\n * wired in. Returns a typed `Registry`, so you can derive a typed client with\n * `createClient<typeof registry>(...)` and pass the same registry to `serve`.\n *\n * The wasm binary is loaded by `serve` (Deno reads it asynchronously), so this\n * stays synchronous.\n */\nexport function setup<A extends RegistryActors>(\n\tconfig: SupabaseSetupConfig<A>,\n): Registry<A> {\n\treturn rivetkitSetup<A>({\n\t\truntime: \"wasm\",\n\t\twasm: { bindings: wasmBindings },\n\t\tnoWelcome: true,\n\t\t...config,\n\t} as RegistryConfigInput<A>);\n}\n\nexport interface ServeOptions {\n\t/** Path the Rivet manager API is mounted at. Defaults to `/api/rivet`. */\n\tmanagerPath?: string;\n\t/** Handler for requests that fall outside the Rivet manager API path. */\n\tfetch?: (request: Request) => Response | Promise<Response>;\n}\n\nconst resolveWasmUrl = (): URL =>\n\tnew URL(\n\t\t(\n\t\t\timport.meta as unknown as { resolve(specifier: string): string }\n\t\t).resolve(\"@rivetkit/rivetkit-wasm/rivetkit_wasm_bg.wasm\"),\n\t);\n\nfunction applyEnv(\n\tconfig: RegistryConfigInput<RegistryActors>,\n\tmanagerPath: string,\n): void {\n\tif (!config.endpoint) {\n\t\tconst endpoint = Deno.env.get(\"RIVET_ENDPOINT\");\n\t\tif (endpoint) config.endpoint = endpoint;\n\t}\n\tif (!config.namespace) {\n\t\tconst namespace = Deno.env.get(\"RIVET_NAMESPACE\");\n\t\tif (namespace) config.namespace = namespace;\n\t}\n\tif (!config.token) {\n\t\tconst token = Deno.env.get(\"RIVET_TOKEN\");\n\t\tif (token) config.token = token;\n\t}\n\tconst poolName = Deno.env.get(\"RIVET_POOL\");\n\tif (poolName && !config.envoy?.poolName) {\n\t\tconfig.envoy = { ...config.envoy, poolName };\n\t}\n\tif (!config.serverless?.basePath) {\n\t\tconfig.serverless = { ...config.serverless, basePath: managerPath };\n\t}\n}\n\n/**\n * Serves Rivet Actors from a Supabase Edge Function (Deno) on the wasm runtime.\n * Accepts either a registry from this package's `setup` or a setup config (which\n * is wired through `setup` for you).\n *\n * The Rivet manager API is mounted at the configured `serverless.basePath`\n * (or `managerPath`, default `/api/rivet`). Requests outside that path are\n * routed to `options.fetch` if provided. The engine endpoint is read from\n * `RIVET_ENDPOINT` (with `RIVET_NAMESPACE`, `RIVET_TOKEN`, `RIVET_POOL` optional)\n * unless set in the config.\n */\nexport async function serve<A extends RegistryActors>(\n\tregistryOrConfig: Registry<A> | SupabaseSetupConfig<A>,\n\toptions: ServeOptions = {},\n): Promise<void> {\n\tconst registry =\n\t\tregistryOrConfig instanceof Registry\n\t\t\t? registryOrConfig\n\t\t\t: setup(registryOrConfig);\n\n\tconst wasmModule = await Deno.readFile(resolveWasmUrl());\n\tconst config = registry.config as RegistryConfigInput<RegistryActors>;\n\tconfig.wasm = {\n\t\t...config.wasm,\n\t\tbindings: wasmBindings,\n\t\tinitInput: wasmModule,\n\t};\n\n\tconst managerPath =\n\t\tconfig.serverless?.basePath ??\n\t\toptions.managerPath ??\n\t\tDEFAULT_MANAGER_PATH;\n\tapplyEnv(config, managerPath);\n\n\tconst managerSegment = `${managerPath}/`;\n\n\tDeno.serve((request) => {\n\t\tconst url = new URL(request.url);\n\n\t\t// Manager request arriving at the configured base path.\n\t\tif (\n\t\t\turl.pathname === managerPath ||\n\t\t\turl.pathname.startsWith(managerSegment)\n\t\t) {\n\t\t\treturn registry.handler(request);\n\t\t}\n\n\t\t// Supabase mounts the function under `/functions/v1/<name>`, so the\n\t\t// manager API can arrive under a prefix (e.g. `/<name>/api/rivet/...`).\n\t\t// Strip any prefix before the manager path before handing off, so the\n\t\t// example does not need to configure a Supabase-specific base path.\n\t\tconst prefixedIndex = url.pathname.indexOf(managerSegment);\n\t\tif (prefixedIndex > 0) {\n\t\t\turl.pathname = url.pathname.slice(prefixedIndex);\n\t\t\treturn registry.handler(new Request(url, request));\n\t\t}\n\n\t\tif (options.fetch) {\n\t\t\treturn options.fetch(request);\n\t\t}\n\n\t\treturn new Response(\n\t\t\t\"This is a RivetKit server.\\n\\nLearn more at https://rivet.dev\\n\",\n\t\t);\n\t});\n}\n"]}
|
package/dist/mod.mjs
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// src/mod.ts
|
|
2
|
+
import * as wasmBindings from "@rivetkit/rivetkit-wasm";
|
|
3
|
+
import {
|
|
4
|
+
Registry,
|
|
5
|
+
setup as rivetkitSetup
|
|
6
|
+
} from "rivetkit";
|
|
7
|
+
var DEFAULT_MANAGER_PATH = "/api/rivet";
|
|
8
|
+
function setup(config) {
|
|
9
|
+
return rivetkitSetup({
|
|
10
|
+
runtime: "wasm",
|
|
11
|
+
wasm: { bindings: wasmBindings },
|
|
12
|
+
noWelcome: true,
|
|
13
|
+
...config
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
var resolveWasmUrl = () => new URL(
|
|
17
|
+
import.meta.resolve("@rivetkit/rivetkit-wasm/rivetkit_wasm_bg.wasm")
|
|
18
|
+
);
|
|
19
|
+
function applyEnv(config, managerPath) {
|
|
20
|
+
var _a, _b;
|
|
21
|
+
if (!config.endpoint) {
|
|
22
|
+
const endpoint = Deno.env.get("RIVET_ENDPOINT");
|
|
23
|
+
if (endpoint) config.endpoint = endpoint;
|
|
24
|
+
}
|
|
25
|
+
if (!config.namespace) {
|
|
26
|
+
const namespace = Deno.env.get("RIVET_NAMESPACE");
|
|
27
|
+
if (namespace) config.namespace = namespace;
|
|
28
|
+
}
|
|
29
|
+
if (!config.token) {
|
|
30
|
+
const token = Deno.env.get("RIVET_TOKEN");
|
|
31
|
+
if (token) config.token = token;
|
|
32
|
+
}
|
|
33
|
+
const poolName = Deno.env.get("RIVET_POOL");
|
|
34
|
+
if (poolName && !((_a = config.envoy) == null ? void 0 : _a.poolName)) {
|
|
35
|
+
config.envoy = { ...config.envoy, poolName };
|
|
36
|
+
}
|
|
37
|
+
if (!((_b = config.serverless) == null ? void 0 : _b.basePath)) {
|
|
38
|
+
config.serverless = { ...config.serverless, basePath: managerPath };
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
async function serve(registryOrConfig, options = {}) {
|
|
42
|
+
var _a;
|
|
43
|
+
const registry = registryOrConfig instanceof Registry ? registryOrConfig : setup(registryOrConfig);
|
|
44
|
+
const wasmModule = await Deno.readFile(resolveWasmUrl());
|
|
45
|
+
const config = registry.config;
|
|
46
|
+
config.wasm = {
|
|
47
|
+
...config.wasm,
|
|
48
|
+
bindings: wasmBindings,
|
|
49
|
+
initInput: wasmModule
|
|
50
|
+
};
|
|
51
|
+
const managerPath = ((_a = config.serverless) == null ? void 0 : _a.basePath) ?? options.managerPath ?? DEFAULT_MANAGER_PATH;
|
|
52
|
+
applyEnv(config, managerPath);
|
|
53
|
+
const managerSegment = `${managerPath}/`;
|
|
54
|
+
Deno.serve((request) => {
|
|
55
|
+
const url = new URL(request.url);
|
|
56
|
+
if (url.pathname === managerPath || url.pathname.startsWith(managerSegment)) {
|
|
57
|
+
return registry.handler(request);
|
|
58
|
+
}
|
|
59
|
+
const prefixedIndex = url.pathname.indexOf(managerSegment);
|
|
60
|
+
if (prefixedIndex > 0) {
|
|
61
|
+
url.pathname = url.pathname.slice(prefixedIndex);
|
|
62
|
+
return registry.handler(new Request(url, request));
|
|
63
|
+
}
|
|
64
|
+
if (options.fetch) {
|
|
65
|
+
return options.fetch(request);
|
|
66
|
+
}
|
|
67
|
+
return new Response(
|
|
68
|
+
"This is a RivetKit server.\n\nLearn more at https://rivet.dev\n"
|
|
69
|
+
);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
export {
|
|
73
|
+
serve,
|
|
74
|
+
setup
|
|
75
|
+
};
|
|
76
|
+
//# sourceMappingURL=mod.mjs.map
|
package/dist/mod.mjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/mod.ts"],"sourcesContent":["import * as wasmBindings from \"@rivetkit/rivetkit-wasm\";\nimport {\n\tRegistry,\n\ttype RegistryActors,\n\ttype RegistryConfigInput,\n\tsetup as rivetkitSetup,\n} from \"rivetkit\";\n\nconst DEFAULT_MANAGER_PATH = \"/api/rivet\";\n\n/** Config passed to `setup` / `serve`. The wasm runtime is wired automatically. */\nexport type SupabaseSetupConfig<A extends RegistryActors> = Omit<\n\tRegistryConfigInput<A>,\n\t\"runtime\" | \"wasm\"\n>;\n\n/**\n * Wraps rivetkit's `setup` with the Supabase Edge Functions WebAssembly runtime\n * wired in. Returns a typed `Registry`, so you can derive a typed client with\n * `createClient<typeof registry>(...)` and pass the same registry to `serve`.\n *\n * The wasm binary is loaded by `serve` (Deno reads it asynchronously), so this\n * stays synchronous.\n */\nexport function setup<A extends RegistryActors>(\n\tconfig: SupabaseSetupConfig<A>,\n): Registry<A> {\n\treturn rivetkitSetup<A>({\n\t\truntime: \"wasm\",\n\t\twasm: { bindings: wasmBindings },\n\t\tnoWelcome: true,\n\t\t...config,\n\t} as RegistryConfigInput<A>);\n}\n\nexport interface ServeOptions {\n\t/** Path the Rivet manager API is mounted at. Defaults to `/api/rivet`. */\n\tmanagerPath?: string;\n\t/** Handler for requests that fall outside the Rivet manager API path. */\n\tfetch?: (request: Request) => Response | Promise<Response>;\n}\n\nconst resolveWasmUrl = (): URL =>\n\tnew URL(\n\t\t(\n\t\t\timport.meta as unknown as { resolve(specifier: string): string }\n\t\t).resolve(\"@rivetkit/rivetkit-wasm/rivetkit_wasm_bg.wasm\"),\n\t);\n\nfunction applyEnv(\n\tconfig: RegistryConfigInput<RegistryActors>,\n\tmanagerPath: string,\n): void {\n\tif (!config.endpoint) {\n\t\tconst endpoint = Deno.env.get(\"RIVET_ENDPOINT\");\n\t\tif (endpoint) config.endpoint = endpoint;\n\t}\n\tif (!config.namespace) {\n\t\tconst namespace = Deno.env.get(\"RIVET_NAMESPACE\");\n\t\tif (namespace) config.namespace = namespace;\n\t}\n\tif (!config.token) {\n\t\tconst token = Deno.env.get(\"RIVET_TOKEN\");\n\t\tif (token) config.token = token;\n\t}\n\tconst poolName = Deno.env.get(\"RIVET_POOL\");\n\tif (poolName && !config.envoy?.poolName) {\n\t\tconfig.envoy = { ...config.envoy, poolName };\n\t}\n\tif (!config.serverless?.basePath) {\n\t\tconfig.serverless = { ...config.serverless, basePath: managerPath };\n\t}\n}\n\n/**\n * Serves Rivet Actors from a Supabase Edge Function (Deno) on the wasm runtime.\n * Accepts either a registry from this package's `setup` or a setup config (which\n * is wired through `setup` for you).\n *\n * The Rivet manager API is mounted at the configured `serverless.basePath`\n * (or `managerPath`, default `/api/rivet`). Requests outside that path are\n * routed to `options.fetch` if provided. The engine endpoint is read from\n * `RIVET_ENDPOINT` (with `RIVET_NAMESPACE`, `RIVET_TOKEN`, `RIVET_POOL` optional)\n * unless set in the config.\n */\nexport async function serve<A extends RegistryActors>(\n\tregistryOrConfig: Registry<A> | SupabaseSetupConfig<A>,\n\toptions: ServeOptions = {},\n): Promise<void> {\n\tconst registry =\n\t\tregistryOrConfig instanceof Registry\n\t\t\t? registryOrConfig\n\t\t\t: setup(registryOrConfig);\n\n\tconst wasmModule = await Deno.readFile(resolveWasmUrl());\n\tconst config = registry.config as RegistryConfigInput<RegistryActors>;\n\tconfig.wasm = {\n\t\t...config.wasm,\n\t\tbindings: wasmBindings,\n\t\tinitInput: wasmModule,\n\t};\n\n\tconst managerPath =\n\t\tconfig.serverless?.basePath ??\n\t\toptions.managerPath ??\n\t\tDEFAULT_MANAGER_PATH;\n\tapplyEnv(config, managerPath);\n\n\tconst managerSegment = `${managerPath}/`;\n\n\tDeno.serve((request) => {\n\t\tconst url = new URL(request.url);\n\n\t\t// Manager request arriving at the configured base path.\n\t\tif (\n\t\t\turl.pathname === managerPath ||\n\t\t\turl.pathname.startsWith(managerSegment)\n\t\t) {\n\t\t\treturn registry.handler(request);\n\t\t}\n\n\t\t// Supabase mounts the function under `/functions/v1/<name>`, so the\n\t\t// manager API can arrive under a prefix (e.g. `/<name>/api/rivet/...`).\n\t\t// Strip any prefix before the manager path before handing off, so the\n\t\t// example does not need to configure a Supabase-specific base path.\n\t\tconst prefixedIndex = url.pathname.indexOf(managerSegment);\n\t\tif (prefixedIndex > 0) {\n\t\t\turl.pathname = url.pathname.slice(prefixedIndex);\n\t\t\treturn registry.handler(new Request(url, request));\n\t\t}\n\n\t\tif (options.fetch) {\n\t\t\treturn options.fetch(request);\n\t\t}\n\n\t\treturn new Response(\n\t\t\t\"This is a RivetKit server.\\n\\nLearn more at https://rivet.dev\\n\",\n\t\t);\n\t});\n}\n"],"mappings":";AAAA,YAAY,kBAAkB;AAC9B;AAAA,EACC;AAAA,EAGA,SAAS;AAAA,OACH;AAEP,IAAM,uBAAuB;AAgBtB,SAAS,MACf,QACc;AACd,SAAO,cAAiB;AAAA,IACvB,SAAS;AAAA,IACT,MAAM,EAAE,UAAU,aAAa;AAAA,IAC/B,WAAW;AAAA,IACX,GAAG;AAAA,EACJ,CAA2B;AAC5B;AASA,IAAM,iBAAiB,MACtB,IAAI;AAAA,EAEF,YACC,QAAQ,+CAA+C;AAC1D;AAED,SAAS,SACR,QACA,aACO;AApDR;AAqDC,MAAI,CAAC,OAAO,UAAU;AACrB,UAAM,WAAW,KAAK,IAAI,IAAI,gBAAgB;AAC9C,QAAI,SAAU,QAAO,WAAW;AAAA,EACjC;AACA,MAAI,CAAC,OAAO,WAAW;AACtB,UAAM,YAAY,KAAK,IAAI,IAAI,iBAAiB;AAChD,QAAI,UAAW,QAAO,YAAY;AAAA,EACnC;AACA,MAAI,CAAC,OAAO,OAAO;AAClB,UAAM,QAAQ,KAAK,IAAI,IAAI,aAAa;AACxC,QAAI,MAAO,QAAO,QAAQ;AAAA,EAC3B;AACA,QAAM,WAAW,KAAK,IAAI,IAAI,YAAY;AAC1C,MAAI,YAAY,GAAC,YAAO,UAAP,mBAAc,WAAU;AACxC,WAAO,QAAQ,EAAE,GAAG,OAAO,OAAO,SAAS;AAAA,EAC5C;AACA,MAAI,GAAC,YAAO,eAAP,mBAAmB,WAAU;AACjC,WAAO,aAAa,EAAE,GAAG,OAAO,YAAY,UAAU,YAAY;AAAA,EACnE;AACD;AAaA,eAAsB,MACrB,kBACA,UAAwB,CAAC,GACT;AAxFjB;AAyFC,QAAM,WACL,4BAA4B,WACzB,mBACA,MAAM,gBAAgB;AAE1B,QAAM,aAAa,MAAM,KAAK,SAAS,eAAe,CAAC;AACvD,QAAM,SAAS,SAAS;AACxB,SAAO,OAAO;AAAA,IACb,GAAG,OAAO;AAAA,IACV,UAAU;AAAA,IACV,WAAW;AAAA,EACZ;AAEA,QAAM,gBACL,YAAO,eAAP,mBAAmB,aACnB,QAAQ,eACR;AACD,WAAS,QAAQ,WAAW;AAE5B,QAAM,iBAAiB,GAAG,WAAW;AAErC,OAAK,MAAM,CAAC,YAAY;AACvB,UAAM,MAAM,IAAI,IAAI,QAAQ,GAAG;AAG/B,QACC,IAAI,aAAa,eACjB,IAAI,SAAS,WAAW,cAAc,GACrC;AACD,aAAO,SAAS,QAAQ,OAAO;AAAA,IAChC;AAMA,UAAM,gBAAgB,IAAI,SAAS,QAAQ,cAAc;AACzD,QAAI,gBAAgB,GAAG;AACtB,UAAI,WAAW,IAAI,SAAS,MAAM,aAAa;AAC/C,aAAO,SAAS,QAAQ,IAAI,QAAQ,KAAK,OAAO,CAAC;AAAA,IAClD;AAEA,QAAI,QAAQ,OAAO;AAClB,aAAO,QAAQ,MAAM,OAAO;AAAA,IAC7B;AAEA,WAAO,IAAI;AAAA,MACV;AAAA,IACD;AAAA,EACD,CAAC;AACF;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rivetkit/supabase",
|
|
3
|
+
"version": "2.3.0-rc.13",
|
|
4
|
+
"description": "Supabase Edge Functions integration for RivetKit actors",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"rivetkit",
|
|
8
|
+
"supabase",
|
|
9
|
+
"supabase-functions",
|
|
10
|
+
"edge-functions",
|
|
11
|
+
"deno",
|
|
12
|
+
"serverless",
|
|
13
|
+
"edge",
|
|
14
|
+
"wasm",
|
|
15
|
+
"actor",
|
|
16
|
+
"microservices"
|
|
17
|
+
],
|
|
18
|
+
"sideEffects": false,
|
|
19
|
+
"files": [
|
|
20
|
+
"dist",
|
|
21
|
+
"package.json"
|
|
22
|
+
],
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"import": {
|
|
26
|
+
"types": "./dist/mod.d.mts",
|
|
27
|
+
"default": "./dist/mod.mjs"
|
|
28
|
+
},
|
|
29
|
+
"require": {
|
|
30
|
+
"types": "./dist/mod.d.ts",
|
|
31
|
+
"default": "./dist/mod.js"
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "tsup src/mod.ts",
|
|
37
|
+
"check-types": "tsc --noEmit"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@rivetkit/rivetkit-wasm": "2.3.0-rc.13",
|
|
41
|
+
"rivetkit": "2.3.0-rc.13"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@types/node": "^22.0.0",
|
|
45
|
+
"tsup": "^8.4.0",
|
|
46
|
+
"typescript": "^5.5.2"
|
|
47
|
+
},
|
|
48
|
+
"stableVersion": "0.8.0"
|
|
49
|
+
}
|