@query-farm/vgi 0.15.0 → 0.18.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/README.md +53 -0
- package/dist/cache-control.d.ts +90 -0
- package/dist/catalog/descriptors.d.ts +13 -7
- package/dist/client-entry.js +3862 -1
- package/dist/client-entry.js.map +34 -3
- package/dist/functions/table.d.ts +12 -0
- package/dist/generated/vgi-client.d.ts +1 -1
- package/dist/http/fetch.d.ts +35 -0
- package/dist/index.core.d.ts +1 -0
- package/dist/index.js +225 -11
- package/dist/index.js.map +11 -9
- package/dist/serve-entry.d.ts +84 -0
- package/dist/serve-entry.js +6428 -0
- package/dist/serve-entry.js.map +62 -0
- package/dist/worker-cf-entry.d.ts +4 -22
- package/dist/worker-cf-entry.js +466 -34
- package/dist/worker-cf-entry.js.map +12 -9
- package/package.json +18 -6
- package/src/cache-control.ts +133 -0
- package/src/catalog/descriptors.ts +13 -7
- package/src/catalog/read-only.ts +22 -14
- package/src/functions/table.ts +25 -1
- package/src/generated/vgi-client.ts +2 -2
- package/src/generated/vgi-protocol-schemas.ts +2 -2
- package/src/http/fetch.ts +80 -0
- package/src/index.core.ts +21 -0
- package/src/serve-entry.ts +233 -0
- package/src/worker-cf-entry.ts +7 -51
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { CatalogInterface } from "./catalog/interface.js";
|
|
2
|
+
import type { FunctionRegistry } from "./functions/registry.js";
|
|
3
|
+
/** Environment variables `serveVgiWorker` reads. Injectable for testing. */
|
|
4
|
+
export interface ServeEnv {
|
|
5
|
+
PORT?: string;
|
|
6
|
+
VGI_SIGNING_KEY?: string;
|
|
7
|
+
VGI_TOKEN_TTL?: string;
|
|
8
|
+
CORS_ORIGINS?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare const DEFAULT_PORT = 8787;
|
|
11
|
+
export declare const DEFAULT_TOKEN_TTL = 3600;
|
|
12
|
+
/** Bytes of HMAC key `createHttpHandler` expects; 64 hex characters. */
|
|
13
|
+
export declare const SIGNING_KEY_BYTES = 32;
|
|
14
|
+
export interface ServeVgiWorkerOptions {
|
|
15
|
+
/** Short worker name shown on the landing page, e.g. "ishares". */
|
|
16
|
+
name: string;
|
|
17
|
+
/** One-line description of what the worker serves. */
|
|
18
|
+
doc: string;
|
|
19
|
+
/** Worker version string shown on the landing page. */
|
|
20
|
+
version: string;
|
|
21
|
+
/** Functions the worker serves, already registered. */
|
|
22
|
+
registry: FunctionRegistry;
|
|
23
|
+
/** Catalog DuckDB attaches to. */
|
|
24
|
+
catalogInterface: CatalogInterface;
|
|
25
|
+
/** Public source-repository URL, linked from the landing page. */
|
|
26
|
+
repositoryUrl?: string;
|
|
27
|
+
/** Overrides `$PORT` (default 8787). Pass 0 to bind an ephemeral port. */
|
|
28
|
+
port?: number;
|
|
29
|
+
/** Overrides `$VGI_SIGNING_KEY`. 32 bytes. */
|
|
30
|
+
signingKey?: Uint8Array;
|
|
31
|
+
/** Overrides `$VGI_TOKEN_TTL` (default 3600 seconds). */
|
|
32
|
+
tokenTtl?: number;
|
|
33
|
+
/** Overrides `$CORS_ORIGINS` (default "*"). Pass `null` to disable CORS. */
|
|
34
|
+
corsOrigins?: string | null;
|
|
35
|
+
/** Server ID for state-token attribution (default: `name`). */
|
|
36
|
+
serverId?: string;
|
|
37
|
+
/** Mount point for the VGI endpoints (default "", the origin root). */
|
|
38
|
+
prefix?: string;
|
|
39
|
+
/** Suppress the startup banner on stdout. */
|
|
40
|
+
quiet?: boolean;
|
|
41
|
+
/** Environment source (default `process.env`). */
|
|
42
|
+
env?: ServeEnv;
|
|
43
|
+
}
|
|
44
|
+
/** The slice of `Bun.serve`'s return value this module uses. */
|
|
45
|
+
export interface VgiHttpServer {
|
|
46
|
+
readonly port: number;
|
|
47
|
+
readonly url: URL;
|
|
48
|
+
stop(closeActiveConnections?: boolean): void;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Decode a 32-byte signing key from its hex representation.
|
|
52
|
+
*
|
|
53
|
+
* Throws on anything that is not exactly 64 hex characters. A silent truncate
|
|
54
|
+
* or zero-pad here would produce a worker that starts happily with a key far
|
|
55
|
+
* weaker than the operator believed they supplied.
|
|
56
|
+
*/
|
|
57
|
+
export declare function parseSigningKeyHex(hex: string): Uint8Array;
|
|
58
|
+
/**
|
|
59
|
+
* Resolve the state-token signing key: explicit option, then `$VGI_SIGNING_KEY`,
|
|
60
|
+
* then a fresh random key.
|
|
61
|
+
*
|
|
62
|
+
* The random fallback is safe but ephemeral, and that tradeoff is why it warns:
|
|
63
|
+
* state tokens minted under it stop validating after a restart, and never
|
|
64
|
+
* validate across a second instance behind a load balancer. It exists so
|
|
65
|
+
* `bun run scripts/serve.ts` works with no setup, not so deployments can skip
|
|
66
|
+
* the key.
|
|
67
|
+
*/
|
|
68
|
+
export declare function resolveSigningKey(explicit: Uint8Array | undefined, env: ServeEnv, warn?: (msg: string) => void): Uint8Array;
|
|
69
|
+
/**
|
|
70
|
+
* Build the fetch handler a VGI worker serves over HTTP, with the standardized
|
|
71
|
+
* landing surface mounted at `prefix`.
|
|
72
|
+
*
|
|
73
|
+
* Exposed separately from {@link serveVgiWorker} so a worker can put the VGI
|
|
74
|
+
* routes inside its own Bun/Hono/Elysia server, or drive them from a test
|
|
75
|
+
* without binding a port.
|
|
76
|
+
*/
|
|
77
|
+
export declare function createVgiWorkerFetch(opts: ServeVgiWorkerOptions): (req: Request) => Promise<Response>;
|
|
78
|
+
/**
|
|
79
|
+
* Serve a VGI worker over HTTP on Bun and return the running server.
|
|
80
|
+
*
|
|
81
|
+
* Reads `PORT`, `VGI_SIGNING_KEY`, `VGI_TOKEN_TTL`, and `CORS_ORIGINS` from the
|
|
82
|
+
* environment; every one has an explicit option that takes precedence.
|
|
83
|
+
*/
|
|
84
|
+
export declare function serveVgiWorker(opts: ServeVgiWorkerOptions): VgiHttpServer;
|