@query-farm/vgi 0.50.1 → 0.52.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 +45 -3
- package/dist/client-entry.js +833 -775
- package/dist/client-entry.js.map +10 -10
- package/dist/functions/aggregate.d.ts +25 -21
- package/dist/functions/execution-cache.d.ts +11 -0
- package/dist/functions/storage-blobs.d.ts +173 -0
- package/dist/functions/storage-cf-do.d.ts +50 -0
- package/dist/functions/storage-seal.d.ts +27 -0
- package/dist/functions/storage.d.ts +71 -1
- package/dist/functions/table-buffering.d.ts +30 -0
- package/dist/functions/table.d.ts +6 -1
- package/dist/generated/vgi-client.d.ts +7 -1
- package/dist/generated/vgi-protocol-schemas.d.ts +10 -9
- package/dist/generated/vgi-protocol-types.d.ts +244 -2
- package/dist/generated/vgi-service.d.ts +1 -1
- package/dist/hosted.d.ts +117 -0
- package/dist/http/blob-vendor.d.ts +33 -0
- package/dist/http/fetch.d.ts +60 -2
- package/dist/http/hosted-auth.d.ts +45 -0
- package/dist/index.core.d.ts +11 -3
- package/dist/index.js +8661 -6677
- package/dist/index.js.map +52 -34
- package/dist/protocol/arguments-ref.d.ts +107 -0
- package/dist/protocol/dispatch.d.ts +12 -2
- package/dist/protocol/handlers/aggregate.d.ts +1 -1
- package/dist/protocol/handlers/catalog/shared.d.ts +10 -0
- package/dist/protocol/handlers/function.d.ts +23 -0
- package/dist/protocol/handlers/table-buffering.d.ts +1 -1
- package/dist/protocol/serialize.d.ts +1 -1
- package/dist/protocol/serializers/bind.d.ts +27 -1
- package/dist/protocol/serializers/cardinality.d.ts +1 -1
- package/dist/protocol/serializers/splits.d.ts +7 -0
- package/dist/protocol/state-serializer.d.ts +8 -7
- package/dist/protocol/stream-init.d.ts +17 -0
- package/dist/protocol/types.d.ts +32 -0
- package/dist/secrets/lookups.d.ts +31 -0
- package/dist/serve-entry.d.ts +41 -6
- package/dist/serve-entry.js +8531 -6302
- package/dist/serve-entry.js.map +52 -35
- package/dist/worker-cf-entry.d.ts +5 -0
- package/dist/worker-cf-entry.js +7191 -4990
- package/dist/worker-cf-entry.js.map +59 -41
- package/package.json +5 -4
- package/src/functions/aggregate.ts +101 -152
- package/src/functions/copy-from.ts +2 -2
- package/src/functions/execution-cache.ts +59 -0
- package/src/functions/storage-blobs.ts +654 -0
- package/src/functions/storage-cf-do.ts +176 -22
- package/src/functions/storage-seal.ts +208 -0
- package/src/functions/storage.ts +174 -8
- package/src/functions/table-buffering.ts +104 -18
- package/src/functions/table-in-out.ts +3 -1
- package/src/functions/table.ts +12 -8
- package/src/generated/vgi-client.ts +9 -2
- package/src/generated/vgi-protocol-schemas.ts +115 -107
- package/src/generated/vgi-protocol-types.ts +640 -3
- package/src/generated/vgi-service.ts +2 -2
- package/src/hosted.ts +254 -0
- package/src/http/blob-vendor.ts +80 -0
- package/src/http/fetch.ts +179 -8
- package/src/http/hosted-auth.ts +326 -0
- package/src/index.core.ts +66 -1
- package/src/protocol/arguments-ref.ts +260 -0
- package/src/protocol/dispatch.ts +15 -4
- package/src/protocol/handlers/aggregate.ts +123 -82
- package/src/protocol/handlers/catalog/shared.ts +20 -0
- package/src/protocol/handlers/function.ts +135 -59
- package/src/protocol/handlers/table-buffering.ts +49 -32
- package/src/protocol/serialize.ts +3 -0
- package/src/protocol/serializers/bind.ts +96 -69
- package/src/protocol/serializers/cardinality.ts +4 -7
- package/src/protocol/serializers/init.ts +5 -11
- package/src/protocol/serializers/splits.ts +31 -4
- package/src/protocol/state-serializer.ts +27 -39
- package/src/protocol/stream-init.ts +87 -0
- package/src/protocol/types.ts +33 -0
- package/src/secrets/lookups.ts +53 -0
- package/src/serve-entry.ts +138 -11
- package/src/worker-cf-entry.ts +33 -0
- package/src/worker.ts +25 -0
- package/dist/protocol/carried-init-request.d.ts +0 -28
- package/dist/util/zstd-sync.d.ts +0 -7
- package/src/protocol/carried-init-request.ts +0 -139
- package/src/util/zstd-sync.ts +0 -50
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { StatusError } from "@query-farm/vgi-rpc";
|
|
2
|
+
import { Arguments } from "../arguments/arguments.js";
|
|
3
|
+
import type { BindRequest } from "./types.js";
|
|
4
|
+
/** The capability header telling the client this worker accepts argument references, and above how many bytes of arguments IPC to use one. */
|
|
5
|
+
export declare const ARGUMENTS_REF_BYTES_HEADER = "VGI-Arguments-Ref-Bytes";
|
|
6
|
+
/** Operator override of the advertised value. */
|
|
7
|
+
export declare const ARGUMENTS_REF_BYTES_ENV = "VGI_ARGUMENTS_REF_BYTES";
|
|
8
|
+
/** The default advertised value: 4 MiB. */
|
|
9
|
+
export declare const DEFAULT_ARGUMENTS_REF_BYTES: number;
|
|
10
|
+
/**
|
|
11
|
+
* Test switch: the HTTP server stops sending the header (the extension's
|
|
12
|
+
* `arguments_ref_fallback.test`), behaving like a worker without argument
|
|
13
|
+
* references while still vending upload URLs.
|
|
14
|
+
*/
|
|
15
|
+
export declare const DISABLE_ARGUMENTS_REF_ENV = "VGI_TEST_DISABLE_ARGUMENTS_REF";
|
|
16
|
+
/** Kind of the refusal for a bind that does not set exactly one of `arguments` / `arguments_location`. */
|
|
17
|
+
export declare const INVALID_BIND_REQUEST_KIND = "invalid_bind_request";
|
|
18
|
+
/** Its exact message (large-values spec §2). */
|
|
19
|
+
export declare const INVALID_BIND_REQUEST_MESSAGE = "BindRequest must set exactly one of 'arguments' and 'arguments_location'";
|
|
20
|
+
/** Kind of the refusal for a malformed or unopenable argument reference. */
|
|
21
|
+
export declare const INVALID_ARGUMENTS_REF_KIND = "invalid_arguments_ref";
|
|
22
|
+
/** Kind of the refusal for an argument object storage reports gone. */
|
|
23
|
+
export declare const ARGUMENTS_REF_MISSING_KIND = "arguments_ref_missing";
|
|
24
|
+
/**
|
|
25
|
+
* The exact message for it (large-values spec §5a, "Prepared statements"):
|
|
26
|
+
* argument objects live about a day, so a prepared statement's large argument
|
|
27
|
+
* can expire, and there is no transparent rebind. Same text as vgi-python.
|
|
28
|
+
*/
|
|
29
|
+
export declare const ARGUMENTS_REF_MISSING_MESSAGE = "this prepared statement's large argument has expired; prepare it again";
|
|
30
|
+
/** `invalid_bind_request` (`INVALID_ARGUMENT`). */
|
|
31
|
+
export declare function invalidBindRequest(): StatusError;
|
|
32
|
+
/**
|
|
33
|
+
* `invalid_arguments_ref` (`INVALID_ARGUMENT`). The message names the kind
|
|
34
|
+
* too: a client that shows only "<type>: <message>" (the DuckDB extension)
|
|
35
|
+
* would otherwise never show the reason a caller can act on.
|
|
36
|
+
*/
|
|
37
|
+
export declare function invalidArgumentsRef(message: string): StatusError;
|
|
38
|
+
/**
|
|
39
|
+
* The `arguments` of a bind call decoded with an `arguments_location`, until
|
|
40
|
+
* the framework resolves it. Every read throws `arguments_not_resolved`, so a
|
|
41
|
+
* path that forgot to resolve fails loudly instead of running the function
|
|
42
|
+
* with zero arguments (what a 3.3 worker silently did with a 3.4 bind).
|
|
43
|
+
*/
|
|
44
|
+
export declare function unresolvedArguments(): Arguments;
|
|
45
|
+
/** Whether `bindCall.arguments` holds a value (inline, or already resolved). */
|
|
46
|
+
export declare function argumentsResolved(bindCall: BindRequest): boolean;
|
|
47
|
+
/** What resolution needs from a call context (vgi-rpc's CallContext, StreamInitContext and OutputCollector all have it). */
|
|
48
|
+
export interface ArgumentRefResolver {
|
|
49
|
+
resolveArgumentRef(ref: Uint8Array, location: {
|
|
50
|
+
size: number;
|
|
51
|
+
sha256: string;
|
|
52
|
+
}): Promise<Uint8Array>;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Resolve a bind call's `arguments_location` in place, at the request's
|
|
56
|
+
* entry: open the sealed reference under this request's principal and check
|
|
57
|
+
* its size and SHA-256 equal the location's; look the object up in vgi-rpc's
|
|
58
|
+
* object cache by `object_id`; on a miss fetch it once (single-flight); verify
|
|
59
|
+
* its length and SHA-256; decode it as the arguments IPC stream.
|
|
60
|
+
*
|
|
61
|
+
* Only `arguments` changes; `arguments_location` and the received bytes stay,
|
|
62
|
+
* so the bind call still re-encodes as the reference. A bind call whose
|
|
63
|
+
* arguments came inline (or are already resolved) is returned untouched.
|
|
64
|
+
*
|
|
65
|
+
* @throws StatusError `invalid_arguments_ref` (`INVALID_ARGUMENT`) for a
|
|
66
|
+
* reference that does not open or match, no storage, or no context;
|
|
67
|
+
* `arguments_ref_integrity` (`DATA_LOSS`) for fetched bytes that differ;
|
|
68
|
+
* `arguments_ref_missing` (`NOT_FOUND`) with the prepared-statement message
|
|
69
|
+
* when storage reports the object gone. vgi-rpc's `storage_unavailable`
|
|
70
|
+
* passes through for transient storage failures.
|
|
71
|
+
*/
|
|
72
|
+
export declare function resolveBindCall<B extends BindRequest>(bindCall: B, ctx: ArgumentRefResolver | null | undefined): Promise<B>;
|
|
73
|
+
/** Resolve the bind call a request embeds (`request.bind_call`), in place. */
|
|
74
|
+
export declare function resolveRequestArguments<R extends {
|
|
75
|
+
bind_call: BindRequest;
|
|
76
|
+
}>(request: R, ctx: ArgumentRefResolver | null | undefined): Promise<R>;
|
|
77
|
+
type EnvLike = Readonly<Record<string, string | undefined>>;
|
|
78
|
+
/**
|
|
79
|
+
* The `VGI-Arguments-Ref-Bytes` value to advertise: `VGI_ARGUMENTS_REF_BYTES`
|
|
80
|
+
* when set, else 4 MiB.
|
|
81
|
+
*
|
|
82
|
+
* @throws Error when the variable is not a positive decimal integer of at most
|
|
83
|
+
* 19 digits (the header's grammar), so a typo stops startup instead of
|
|
84
|
+
* silently advertising nothing.
|
|
85
|
+
*/
|
|
86
|
+
export declare function argumentsRefBytesFromEnv(env?: EnvLike): number;
|
|
87
|
+
/**
|
|
88
|
+
* The `VGI-Arguments-Ref-Bytes` value an HTTP server advertises, or `null`
|
|
89
|
+
* when it advertises nothing.
|
|
90
|
+
*
|
|
91
|
+
* The header is the mandatory capability signal (large-values spec §5): sent
|
|
92
|
+
* whenever the server vends upload URLs (the grant) AND its storage can fetch
|
|
93
|
+
* the uploaded object back by id (vgi-rpc `ObjectStore`), never otherwise.
|
|
94
|
+
* `VGI_TEST_DISABLE_ARGUMENTS_REF=1` turns it off (the extension's fallback
|
|
95
|
+
* test).
|
|
96
|
+
*
|
|
97
|
+
* @param explicit A server option overriding `VGI_ARGUMENTS_REF_BYTES`.
|
|
98
|
+
*/
|
|
99
|
+
export declare function argumentsRefHeaderValue(opts: {
|
|
100
|
+
uploadUrlProvider?: unknown;
|
|
101
|
+
externalLocation?: {
|
|
102
|
+
storage?: unknown;
|
|
103
|
+
} | null | undefined;
|
|
104
|
+
explicit?: number | undefined;
|
|
105
|
+
env?: EnvLike;
|
|
106
|
+
}): number | null;
|
|
107
|
+
export {};
|
|
@@ -24,6 +24,15 @@ export interface ProtocolConfig {
|
|
|
24
24
|
* receive a given attach must use the same key.
|
|
25
25
|
*/
|
|
26
26
|
attachSecretKey?: Uint8Array | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* Input key material for sealed framework storage payloads
|
|
29
|
+
* (src/functions/storage-seal.ts). The cross-SDK v1 rule is the UTF-8 bytes
|
|
30
|
+
* of `VGI_SIGNING_KEY` exactly as configured (not its hex-decoded form), so a
|
|
31
|
+
* deployment's one key derives the same payload key in every SDK. Defaults
|
|
32
|
+
* to `signingKey` (bytes passed as bytes are used unchanged); with neither,
|
|
33
|
+
* the host-local key file. The attach / state-token keys are unaffected.
|
|
34
|
+
*/
|
|
35
|
+
storageSealKey?: Uint8Array | undefined;
|
|
27
36
|
}
|
|
28
37
|
/**
|
|
29
38
|
* Wire name of the VGI protocol: the `vgi_rpc.protocol` routing key and the
|
|
@@ -61,9 +70,10 @@ export { VGI_PROTOCOL_NAME };
|
|
|
61
70
|
* hash covers method names, types and the params/result/header schemas only
|
|
62
71
|
* (WIRE_PROTOCOL.md §14).
|
|
63
72
|
*
|
|
64
|
-
* It changes only with vgi.v3's
|
|
73
|
+
* It changes only with vgi.v3's method surface (3.3 removed
|
|
65
74
|
* catalog_table_scan_function_get and gave catalog_table_create a `created`
|
|
66
|
-
* result
|
|
75
|
+
* result; 3.4.0 changed the transport's upload URLs, not the surface, so the
|
|
76
|
+
* hash is unchanged). Asserted
|
|
67
77
|
* by src/protocol/__tests__/vgi-v3-hash.test.ts; if that test fails, the
|
|
68
78
|
* surface drifted from the reference -- fix the schemas, do not bump this.
|
|
69
79
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { VgiService } from "../../generated/vgi-service.js";
|
|
2
2
|
import type { FunctionRegistry } from "../../functions/registry.js";
|
|
3
3
|
/** The aggregate lifecycle's `vgi.v3` handlers. */
|
|
4
|
-
export declare function aggregateHandlers(registry: FunctionRegistry): Partial<VgiService>;
|
|
4
|
+
export declare function aggregateHandlers(registry: FunctionRegistry, signingKey?: Uint8Array, attachSecretKey?: Uint8Array, storageSealKey?: Uint8Array | undefined): Partial<VgiService>;
|
|
@@ -45,6 +45,16 @@ export declare function openAttachFull(envelope: Uint8Array, auth: AuthContext |
|
|
|
45
45
|
* storage routing uses openAttachFull / deriveShardKey to reach the UUID.
|
|
46
46
|
*/
|
|
47
47
|
export declare function openAttach(envelope: Uint8Array, auth: AuthContext | undefined, signingKey: Uint8Array | undefined, attachSecretKey?: Uint8Array): Promise<Uint8Array>;
|
|
48
|
+
/**
|
|
49
|
+
* Open an attach envelope once, returning both what the function body sees
|
|
50
|
+
* (the catalog's own bytes, UUID and options trailer stripped) and the
|
|
51
|
+
* FunctionStorage shard key of its framework UUID. An empty / absent attach
|
|
52
|
+
* yields `{ attach: <as given>, shardKey: "" }`.
|
|
53
|
+
*/
|
|
54
|
+
export declare function openAttachWithShard(envelope: Uint8Array | null | undefined, auth: AuthContext | undefined, signingKey: Uint8Array | undefined, attachSecretKey?: Uint8Array): Promise<{
|
|
55
|
+
attach: Uint8Array | null;
|
|
56
|
+
shardKey: string;
|
|
57
|
+
}>;
|
|
48
58
|
/**
|
|
49
59
|
* deriveShardKey returns the Cloudflare-DO routing key for an attach:
|
|
50
60
|
* "att-" + hex(the 16-byte framework UUID at the head of the unwrapped attach).
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { AuthContext } from "@query-farm/vgi-rpc";
|
|
1
2
|
import { type VgiService } from "../../generated/vgi-service.js";
|
|
2
3
|
import type { FunctionRegistry } from "../../functions/registry.js";
|
|
3
4
|
export interface FunctionHandlerConfig {
|
|
@@ -5,6 +6,8 @@ export interface FunctionHandlerConfig {
|
|
|
5
6
|
signingKey?: Uint8Array | undefined;
|
|
6
7
|
/** Explicit root key for secret ATTACH options (see attach-secret-options.ts). */
|
|
7
8
|
attachSecretKey?: Uint8Array | undefined;
|
|
9
|
+
/** Seal ikm for framework storage payloads (see ProtocolConfig.storageSealKey). */
|
|
10
|
+
storageSealKey?: Uint8Array | undefined;
|
|
8
11
|
/**
|
|
9
12
|
* Used to map a bind's `attach_opaque_data` to its catalog, so resolution can
|
|
10
13
|
* be scoped when two catalogs declare the same schema and function name.
|
|
@@ -25,5 +28,25 @@ export interface FunctionHandlerConfig {
|
|
|
25
28
|
version?(attach: Uint8Array, txn?: Uint8Array): number | Promise<number>;
|
|
26
29
|
} | undefined;
|
|
27
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Unseal a decoded bind call's opaque values in place, as the catalog handlers
|
|
33
|
+
* do: the transaction first (its envelope binds the *sealed* attach), then the
|
|
34
|
+
* attach, and stamp the storage shard of the attach's framework UUID (in
|
|
35
|
+
* memory only, never serialized) so every BoundStorage the function builds
|
|
36
|
+
* routes to this attach's shard. Every function-side request goes through
|
|
37
|
+
* this, so function bodies see the same transaction plaintext that
|
|
38
|
+
* transactionCommit/Rollback get.
|
|
39
|
+
*
|
|
40
|
+
* Rule 11 of the raw-preserving wrapper (vgi docs/large-values-3.4.md §3.3):
|
|
41
|
+
* the opened plaintext lives on the domain object, BESIDE the received bytes,
|
|
42
|
+
* never in them. A decoded bind call re-encodes as exactly what the client
|
|
43
|
+
* sent (`bindCallBytes`), sealed envelopes included, so nothing opened here
|
|
44
|
+
* can reach the wire, a state token or storage.
|
|
45
|
+
*/
|
|
46
|
+
export declare function openBindCallOpaque(bindCall: {
|
|
47
|
+
attach_opaque_data?: Uint8Array | null;
|
|
48
|
+
transaction_opaque_data?: Uint8Array | null;
|
|
49
|
+
storage_shard_key?: string | null;
|
|
50
|
+
}, auth: AuthContext | undefined, signingKey: Uint8Array | undefined, attachSecretKey?: Uint8Array): Promise<void>;
|
|
28
51
|
/** The per-function lifecycle's `vgi.v3` handlers. */
|
|
29
52
|
export declare function functionHandlers(config: FunctionHandlerConfig): Partial<VgiService>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { VgiService } from "../../generated/vgi-service.js";
|
|
2
2
|
import type { FunctionRegistry } from "../../functions/registry.js";
|
|
3
3
|
/** The table_buffering lifecycle's `vgi.v3` handlers. */
|
|
4
|
-
export declare function tableBufferingHandlers(registry: FunctionRegistry, signingKey?: Uint8Array, attachSecretKey?: Uint8Array): Partial<VgiService>;
|
|
4
|
+
export declare function tableBufferingHandlers(registry: FunctionRegistry, signingKey?: Uint8Array, attachSecretKey?: Uint8Array, storageSealKey?: Uint8Array | undefined): Partial<VgiService>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { serializeArguments, deserializeArguments } from "./serializers/arguments.js";
|
|
2
|
-
export { serializeBindRequest, deserializeBindRequest, serializeBindResponse, deserializeBindResponse, } from "./serializers/bind.js";
|
|
2
|
+
export { serializeBindRequest, deserializeBindRequest, decodeBindCall, bindCallBytes, receivedBindCall, serializeBindResponse, deserializeBindResponse, } from "./serializers/bind.js";
|
|
3
3
|
export { serializeInitRequest, deserializeInitRequest, serializeGlobalInitResponse, deserializeGlobalInitResponse, } from "./serializers/init.js";
|
|
4
4
|
export { deserializeCardinalityRequest, serializeTableCardinality, } from "./serializers/cardinality.js";
|
|
@@ -1,8 +1,34 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { VgiSchema, VgiBatch } from "../../arrow/index.js";
|
|
2
2
|
import type { BindRequest, BindResponse, BindRepeatability } from "../types.js";
|
|
3
|
+
import { type BindRequest as WireBindRequest, type Nested } from "../../generated/vgi-protocol-types.js";
|
|
3
4
|
declare const BIND_REQUEST_SCHEMA: VgiSchema;
|
|
5
|
+
/** The wrapper holding the bytes `bindCall` was decoded from, or `undefined` for one built from fields. */
|
|
6
|
+
export declare function receivedBindCall(bindCall: BindRequest): Nested<WireBindRequest> | undefined;
|
|
7
|
+
/** The bind call's wire bytes: the bytes it was received as, else a fresh serialization of its fields. */
|
|
8
|
+
export declare function bindCallBytes(bindCall: BindRequest): Uint8Array;
|
|
4
9
|
export declare function serializeBindRequest(req: BindRequest): VgiBatch;
|
|
10
|
+
/**
|
|
11
|
+
* Decode a bind request from a dict of its wire columns (the generated
|
|
12
|
+
* decoder's record, or `batchToScalarDict` of the one-row batch).
|
|
13
|
+
*
|
|
14
|
+
* Exactly one of `arguments` and `arguments_location` must be set (protocol
|
|
15
|
+
* 3.4); anything else is refused with `invalid_bind_request`. When the
|
|
16
|
+
* arguments came by reference the returned bind call's `arguments` is a
|
|
17
|
+
* placeholder that throws until the framework resolves it at the turn's entry
|
|
18
|
+
* (`resolveBindCall`, protocol/arguments-ref.ts); `arguments_location` keeps
|
|
19
|
+
* the location it arrived with.
|
|
20
|
+
*/
|
|
5
21
|
export declare function deserializeBindRequest(params: Record<string, any>): BindRequest;
|
|
22
|
+
/**
|
|
23
|
+
* Decode a received bind call from its bytes through the generated
|
|
24
|
+
* raw-preserving wrapper: the domain object re-encodes as exactly these bytes
|
|
25
|
+
* ({@link bindCallBytes}) for as long as it lives, whatever the framework opens
|
|
26
|
+
* on it in place.
|
|
27
|
+
*
|
|
28
|
+
* @param source The bind call's bytes, or a wrapper already holding them.
|
|
29
|
+
* @param path The field path decode errors name (`InitRequest.bind_call`).
|
|
30
|
+
*/
|
|
31
|
+
export declare function decodeBindCall(source: Uint8Array | Nested<WireBindRequest>, path?: string): BindRequest;
|
|
6
32
|
/** Validate required wire enum values, including rejecting NULL and absent values. */
|
|
7
33
|
export declare function parseBindRepeatability(value: unknown): BindRepeatability;
|
|
8
34
|
/** Only omitted provider declarations default; explicit NULL remains invalid. */
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type VgiSchema } from "../../arrow/index.js";
|
|
2
2
|
import type { TableFunctionCardinalityRequest, TableCardinality } from "../types.js";
|
|
3
3
|
declare const TABLE_FUNCTION_CARDINALITY_REQUEST_SCHEMA: VgiSchema;
|
|
4
|
-
export declare function deserializeCardinalityRequest(params: Record<string, any
|
|
4
|
+
export declare function deserializeCardinalityRequest(params: Record<string, any>, path?: string): TableFunctionCardinalityRequest;
|
|
5
5
|
export declare function serializeTableCardinality(card: TableCardinality): {
|
|
6
6
|
estimate: bigint | null;
|
|
7
7
|
max: bigint | null;
|
|
@@ -153,6 +153,13 @@ export declare function deserializePlanRequest(params: Record<string, any>): Tab
|
|
|
153
153
|
* that minted a token and the init that redeems it. A decoded-then-re-encoded
|
|
154
154
|
* argument list is not guaranteed to round-trip to identical bytes; the wire
|
|
155
155
|
* bytes are.
|
|
156
|
+
*
|
|
157
|
+
* `args` is tagged (large-values spec §5a, "Split-token fingerprints"):
|
|
158
|
+
* inline arguments contribute `0x00 || u64le(len) || IPC bytes`; an argument
|
|
159
|
+
* reference contributes `0x01 || u64le(size) || sha256[32]`, never the sealed
|
|
160
|
+
* `ref` (it holds a random nonce). Without the location branch every bind of
|
|
161
|
+
* externalized arguments would fingerprint the same empty bytes, and a split
|
|
162
|
+
* token would redeem across different large arguments.
|
|
156
163
|
*/
|
|
157
164
|
export declare function fingerprintInputs(bindCallBytes: Uint8Array): {
|
|
158
165
|
schemaPath: string[];
|
|
@@ -37,13 +37,14 @@ export declare function deserializeUserState(bytes: Uint8Array | null): any;
|
|
|
37
37
|
* {@link EXCHANGE_STATE_SCHEMA} names; `user_state` stays Arrow IPC inside the
|
|
38
38
|
* frame, because it carries typed user values.
|
|
39
39
|
*
|
|
40
|
-
* Layout (little-endian): `u8 version | u8 flags |
|
|
41
|
-
* bytes
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
40
|
+
* Layout (little-endian): `u8 version | u8 flags | bytes function_name |
|
|
41
|
+
* bytes init | [bytes user_state] [bytes filter_history]`, where `bytes` is
|
|
42
|
+
* `u32 length, payload` and a bracketed field is present only when its flag
|
|
43
|
+
* bit is set. `init` is the encoded vgi-rpc StateRef the init handler created
|
|
44
|
+
* (`StateRef.toBytes()`; vgi-rpc decides its form while minting the token and
|
|
45
|
+
* caches the encoding, so continuations re-emit the same bytes). The frame
|
|
46
|
+
* never leaves this worker unsealed, so the version byte exists to turn a
|
|
47
|
+
* token minted by another build into a clean refusal rather than a misread.
|
|
47
48
|
*
|
|
48
49
|
* The name is kept for API stability; the Arrow in it is the user state.
|
|
49
50
|
*/
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** What an HTTP stream's `init` StateRef holds. */
|
|
2
|
+
export interface StreamInit {
|
|
3
|
+
/** The init request's IPC bytes exactly as received (the `request` column of the init call). */
|
|
4
|
+
initRequestIpc: Uint8Array;
|
|
5
|
+
/** The worker's init response. */
|
|
6
|
+
executionId: Uint8Array;
|
|
7
|
+
maxWorkers: number;
|
|
8
|
+
opaqueData: Uint8Array | null;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Encode the `init` value: `u8 version | u8 flags | f64 max_workers |
|
|
12
|
+
* bytes init_request | bytes execution_id | [bytes opaque_data]`, `bytes`
|
|
13
|
+
* being `u32 length (LE), payload`.
|
|
14
|
+
*/
|
|
15
|
+
export declare function encodeStreamInit(init: StreamInit): Uint8Array;
|
|
16
|
+
/** Decode an `init` value written by {@link encodeStreamInit}. */
|
|
17
|
+
export declare function decodeStreamInit(bytes: Uint8Array): StreamInit;
|
package/dist/protocol/types.d.ts
CHANGED
|
@@ -41,8 +41,25 @@ export interface CopyToContext {
|
|
|
41
41
|
/** The destination path from the `COPY ... TO 'path'` statement. */
|
|
42
42
|
file_path: string;
|
|
43
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* Where a bind's externalized arguments live (protocol 3.4 argument
|
|
46
|
+
* references, vgi docs/large-values-3.4.md §2). The client uploaded the
|
|
47
|
+
* arguments IPC stream once through this worker's `__upload_url__` grant;
|
|
48
|
+
* `ref` is the grant's sealed reference, `size` / `sha256` describe exactly
|
|
49
|
+
* the uploaded bytes. Mirrors vgi-python's `protocol.ArgumentsLocation`.
|
|
50
|
+
*/
|
|
51
|
+
export interface ArgumentsLocation {
|
|
52
|
+
ref: Uint8Array;
|
|
53
|
+
size: number;
|
|
54
|
+
sha256: string;
|
|
55
|
+
}
|
|
44
56
|
export interface BindRequest {
|
|
45
57
|
function_name: string;
|
|
58
|
+
/**
|
|
59
|
+
* The bound arguments. When the bind arrived by reference
|
|
60
|
+
* (`arguments_location`), the framework resolves them at the entry of every
|
|
61
|
+
* request before any function code runs, so this always holds the value.
|
|
62
|
+
*/
|
|
46
63
|
arguments: Arguments;
|
|
47
64
|
function_type: FunctionType;
|
|
48
65
|
input_schema: VgiSchema | null;
|
|
@@ -51,6 +68,14 @@ export interface BindRequest {
|
|
|
51
68
|
attach_opaque_data: Uint8Array | null;
|
|
52
69
|
transaction_opaque_data: Uint8Array | null;
|
|
53
70
|
resolved_secrets_provided: boolean;
|
|
71
|
+
/**
|
|
72
|
+
* Framework-derived, never on the wire: the FunctionStorage shard key
|
|
73
|
+
* (`att-<uuid hex>`) of this call's attach, stamped when the framework opens
|
|
74
|
+
* the attach and strips its UUID (which the function body never sees).
|
|
75
|
+
* Absent / "" when the call is not bound to an ATTACH. Read it with
|
|
76
|
+
* `shardKeyOf(bindCall)`; `BoundStorage` routes and seals by it.
|
|
77
|
+
*/
|
|
78
|
+
storage_shard_key?: string | null;
|
|
54
79
|
/**
|
|
55
80
|
* COPY ... FROM context — `null`/absent unless this bind/init opens a
|
|
56
81
|
* COPY-FROM scan. Additive + name-keyed, so ordinary scans (which omit it on
|
|
@@ -87,6 +112,13 @@ export interface BindRequest {
|
|
|
87
112
|
* named varargs retain the caller-provided name. `null` means unavailable.
|
|
88
113
|
*/
|
|
89
114
|
argument_names?: (string | null)[] | null;
|
|
115
|
+
/**
|
|
116
|
+
* Protocol 3.4: the location the arguments arrived by, when the client sent
|
|
117
|
+
* them as an argument reference instead of inline; `null`/absent for inline
|
|
118
|
+
* arguments. `arguments` still holds the resolved value; this is what the
|
|
119
|
+
* bind call re-serializes as (never the value).
|
|
120
|
+
*/
|
|
121
|
+
arguments_location?: ArgumentsLocation | null;
|
|
90
122
|
}
|
|
91
123
|
/** Equivalent scans of one bound state within a query; independent binds may differ. */
|
|
92
124
|
export type BindRepeatability = "UNKNOWN" | "STABLE_WITHIN_QUERY";
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The secret-lookup fields an `onBind` may return to ask DuckDB for secrets.
|
|
3
|
+
*
|
|
4
|
+
* The three lists are parallel: entry `i` requests a secret of type
|
|
5
|
+
* `lookupSecretTypes[i]`, optionally narrowed by `lookupScopes[i]` and
|
|
6
|
+
* `lookupNames[i]` (`""` or a missing entry = unset). A lookup without a type
|
|
7
|
+
* cannot be expressed, so `lookupSecretTypes` drives the request.
|
|
8
|
+
*/
|
|
9
|
+
export interface SecretLookupFields {
|
|
10
|
+
lookupSecretTypes?: string[];
|
|
11
|
+
lookupScopes?: string[];
|
|
12
|
+
lookupNames?: string[];
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Check an `onBind` result's secret-lookup lists before they go on the wire.
|
|
16
|
+
*
|
|
17
|
+
* The extension reads one lookup per `lookupSecretTypes` entry, so a scope or
|
|
18
|
+
* name with no type at the same index was silently dropped: returning
|
|
19
|
+
* `lookupNames: ["prod"]` alone requested nothing and the secret arrived
|
|
20
|
+
* missing. That is now a bind error naming the fix.
|
|
21
|
+
*
|
|
22
|
+
* @param fnName function name, for the error message.
|
|
23
|
+
* @param result the `onBind` return value.
|
|
24
|
+
* @returns the three lists for `BindResponse`.
|
|
25
|
+
* @throws Error when `lookupScopes` or `lookupNames` is longer than `lookupSecretTypes`.
|
|
26
|
+
*/
|
|
27
|
+
export declare function secretLookupWire(fnName: string, result: SecretLookupFields): {
|
|
28
|
+
lookup_secret_types: string[] | undefined;
|
|
29
|
+
lookup_scopes: string[] | undefined;
|
|
30
|
+
lookup_names: string[] | undefined;
|
|
31
|
+
};
|
package/dist/serve-entry.d.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import type { CatalogInterface } from "./catalog/interface.js";
|
|
2
2
|
import type { FunctionRegistry } from "./functions/registry.js";
|
|
3
3
|
import { type AuthenticateFn, type PeerResolutionOptions } from "@query-farm/vgi-rpc";
|
|
4
|
+
import { type BlobVendorEnv, type BlobVendorHttpConfig } from "./http/blob-vendor.js";
|
|
4
5
|
import { type HostingOptions } from "./rpc-server.js";
|
|
6
|
+
export { HOSTED_ENV, HOSTED_CHALLENGE, HOSTED_AUTH_DOMAIN, OrchardHostedConfigError, hostedModeEnabled, resolveHostedConfig, orchardHostedFromEnv, checkHostedEnvironment, checkHostedSigningKey, type HostedConfig, type HostedEnv, } from "./hosted.js";
|
|
7
|
+
export { hostedAuthenticate, isHostedAuthenticate, type HostedVerifierDeps } from "./http/hosted-auth.js";
|
|
5
8
|
/** Environment variables `serveVgiWorker` reads. Injectable for testing. */
|
|
6
|
-
export interface ServeEnv {
|
|
9
|
+
export interface ServeEnv extends BlobVendorEnv {
|
|
7
10
|
PORT?: string;
|
|
8
11
|
VGI_SIGNING_KEY?: string;
|
|
9
12
|
VGI_TOKEN_TTL?: string;
|
|
@@ -16,9 +19,20 @@ export interface ServeEnv {
|
|
|
16
19
|
VGI_RPC_GRANT_MAX_TTL_SECONDS?: string;
|
|
17
20
|
/** Principals allowed to call `introspect_token`, comma-separated. */
|
|
18
21
|
VGI_INTROSPECT_PRINCIPALS?: string;
|
|
22
|
+
/** `1` turns on Orchard hosted mode (see `docs/orchard-hosted.md`). */
|
|
23
|
+
VGI_ORCHARD_HOSTED?: string;
|
|
24
|
+
/** Hosted mode: the Front Desk issuer, exactly one value. */
|
|
25
|
+
VGI_JWT_ISSUER?: string;
|
|
26
|
+
/** Hosted mode: the canonical Desk Address, exactly one value. */
|
|
27
|
+
VGI_JWT_AUDIENCE?: string;
|
|
28
|
+
/** Hosted mode: the Front Desk's JWKS URL, exactly one value. */
|
|
29
|
+
VGI_JWT_JWKS_URI?: string;
|
|
30
|
+
/** Hosted mode: accepted Pass algorithms (default ES256; never none/HS*). */
|
|
31
|
+
VGI_JWT_ALGORITHMS?: string;
|
|
19
32
|
}
|
|
20
33
|
export declare const DEFAULT_PORT = 8787;
|
|
21
|
-
|
|
34
|
+
/** Default state-token TTL: 6 h (vgi-rpc STATE_REF_V1.md, protocol 3.4). */
|
|
35
|
+
export declare const DEFAULT_TOKEN_TTL = 21600;
|
|
22
36
|
/** Bytes of HMAC key `createHttpHandler` expects; 64 hex characters. */
|
|
23
37
|
export declare const SIGNING_KEY_BYTES = 32;
|
|
24
38
|
/** HTTP trust boundary for a colocated `vgi-iroh-bridge`. */
|
|
@@ -35,7 +49,14 @@ export interface IrohHttpBridgeOptions {
|
|
|
35
49
|
*/
|
|
36
50
|
peerResolutionContext?: ((request: Request) => PeerResolutionOptions | Promise<PeerResolutionOptions>) | undefined;
|
|
37
51
|
}
|
|
38
|
-
|
|
52
|
+
/**
|
|
53
|
+
* The external-location fields ({@link BlobVendorHttpConfig}) default to the
|
|
54
|
+
* blob-vendor environment (`VGI_BLOB_VENDOR_URL`, `VGI_BLOB_VENDOR_TOKEN`,
|
|
55
|
+
* `VGI_RPC_EXTERNALIZE_THRESHOLD_BYTES`, `VGI_RPC_EXTERNAL_COMPRESSION`,
|
|
56
|
+
* `VGI_RPC_MAX_REQUEST_BYTES`, `VGI_RPC_MAX_UPLOAD_BYTES`); an explicit option
|
|
57
|
+
* wins.
|
|
58
|
+
*/
|
|
59
|
+
export interface ServeVgiWorkerOptions extends HostingOptions, BlobVendorHttpConfig {
|
|
39
60
|
/** Short worker name shown on the landing page, e.g. "ishares". */
|
|
40
61
|
name: string;
|
|
41
62
|
/** One-line description of what the worker serves. */
|
|
@@ -52,14 +73,18 @@ export interface ServeVgiWorkerOptions extends HostingOptions {
|
|
|
52
73
|
port?: number | undefined;
|
|
53
74
|
/** Bind address. Iroh bridge mode defaults to loopback; otherwise Bun's default. */
|
|
54
75
|
hostname?: string | undefined;
|
|
55
|
-
/**
|
|
56
|
-
|
|
76
|
+
/**
|
|
77
|
+
* Overrides `$VGI_SIGNING_KEY`: 32 bytes, or the same 64-hex-character string
|
|
78
|
+
* the env var takes. A string's UTF-8 bytes are also the storage-seal ikm
|
|
79
|
+
* (see {@link resolveStorageSealKey}); bytes are used unchanged.
|
|
80
|
+
*/
|
|
81
|
+
signingKey?: Uint8Array | string | undefined;
|
|
57
82
|
/**
|
|
58
83
|
* Optional root key for secret ATTACH options (encrypted inside
|
|
59
84
|
* `attach_opaque_data` for `attachOptions()`). Defaults to the signing key.
|
|
60
85
|
*/
|
|
61
86
|
attachSecretKey?: Uint8Array | undefined;
|
|
62
|
-
/** Overrides `$VGI_TOKEN_TTL` (default
|
|
87
|
+
/** Overrides `$VGI_TOKEN_TTL` (default 21600 seconds, 6 h). */
|
|
63
88
|
tokenTtl?: number | undefined;
|
|
64
89
|
/** Overrides `$CORS_ORIGINS` (default "*"). Pass `null` to disable CORS. */
|
|
65
90
|
corsOrigins?: string | null | undefined;
|
|
@@ -109,6 +134,16 @@ export declare function parseSigningKeyHex(hex: string): Uint8Array;
|
|
|
109
134
|
* the key.
|
|
110
135
|
*/
|
|
111
136
|
export declare function resolveSigningKey(explicit: Uint8Array | undefined, env: ServeEnv, warn?: (msg: string) => void): Uint8Array;
|
|
137
|
+
/**
|
|
138
|
+
* The ikm for sealed framework storage payloads (cross-SDK v1): the UTF-8 bytes
|
|
139
|
+
* of the signing key *as configured* -- an explicit string option, else the raw
|
|
140
|
+
* `$VGI_SIGNING_KEY` value, unmodified, exactly as vgi-python and vgi-java read
|
|
141
|
+
* it -- so one deployment key derives one payload key in every SDK. Explicit
|
|
142
|
+
* bytes are used unchanged; a generated key's bytes are used as-is (it is
|
|
143
|
+
* process-local anyway). Only the storage seal uses this; state tokens and
|
|
144
|
+
* opaque-data envelopes keep the hex-decoded key.
|
|
145
|
+
*/
|
|
146
|
+
export declare function resolveStorageSealKey(explicit: Uint8Array | string | undefined, env: ServeEnv, resolvedSigningKey: Uint8Array): Uint8Array;
|
|
112
147
|
/**
|
|
113
148
|
* Build the fetch handler a VGI worker serves over HTTP, with the standardized
|
|
114
149
|
* landing surface mounted at `prefix`.
|