@query-farm/vgi 0.48.0 → 0.48.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.
- package/dist/arguments/argument-spec.d.ts +17 -11
- package/dist/catalog/descriptors.d.ts +2 -2
- package/dist/catalog/publication.d.ts +7 -7
- package/dist/client/client.d.ts +9 -3
- package/dist/client/errors.d.ts +2 -2
- package/dist/client/types.d.ts +21 -0
- package/dist/client-entry.d.ts +1 -1
- package/dist/client-entry.js +31 -7
- package/dist/client-entry.js.map +20 -20
- package/dist/filter-pushdown/deserialize.d.ts +1 -1
- package/dist/filter-pushdown/types.d.ts +10 -10
- package/dist/functions/scalar.d.ts +1 -1
- package/dist/functions/table-buffering.d.ts +20 -20
- package/dist/functions/table-in-out.d.ts +4 -4
- package/dist/functions/table.d.ts +7 -7
- package/dist/functions/types.d.ts +47 -47
- package/dist/http/fetch.d.ts +10 -10
- package/dist/index.core.d.ts +1 -1
- package/dist/index.js +155 -94
- package/dist/index.js.map +53 -52
- package/dist/protocol/dispatch.d.ts +3 -3
- package/dist/protocol/handlers/function.d.ts +2 -2
- package/dist/protocol/serializers/cardinality.d.ts +4 -1
- package/dist/protocol/types.d.ts +5 -5
- package/dist/rpc-server.d.ts +6 -6
- package/dist/serve-entry.d.ts +16 -16
- package/dist/serve-entry.js +42 -21
- package/dist/serve-entry.js.map +38 -37
- package/dist/split-token.d.ts +6 -6
- package/dist/types.d.ts +9 -2
- package/dist/util/defined.d.ts +21 -0
- package/dist/worker-cf-entry.js +120 -85
- package/dist/worker-cf-entry.js.map +51 -50
- package/dist/worker.d.ts +2 -2
- package/package.json +6 -4
- package/src/arguments/argument-spec.ts +17 -11
- package/src/arrow/codec/registry.ts +2 -2
- package/src/arrow/impl-arrowjs/build.ts +1 -1
- package/src/arrow/impl-arrowjs/canonical.ts +23 -23
- package/src/arrow/impl-arrowjs/empty.ts +2 -2
- package/src/arrow/impl-arrowjs/ipc.ts +2 -2
- package/src/arrow/impl-arrowjs/iterate.ts +2 -2
- package/src/arrow/impl-arrowjs/project.ts +2 -2
- package/src/arrow/impl-flechette/build.ts +2 -1
- package/src/arrow/impl-flechette/canonical.ts +10 -9
- package/src/arrow/impl-flechette/compat.ts +3 -3
- package/src/arrow/impl-flechette/message-meta.ts +5 -4
- package/src/arrow/impl-flechette/statistics.ts +2 -2
- package/src/attach-ticket.ts +2 -2
- package/src/catalog/column-metadata.ts +1 -1
- package/src/catalog/composite.ts +2 -2
- package/src/catalog/constraints.ts +9 -9
- package/src/catalog/descriptors.ts +1 -1
- package/src/catalog/interface.ts +12 -12
- package/src/catalog/publication.ts +9 -8
- package/src/catalog/read-only.ts +9 -8
- package/src/catalog/sql-grammar.ts +6 -6
- package/src/client/client.ts +52 -15
- package/src/client/errors.ts +1 -1
- package/src/client/types.ts +23 -0
- package/src/client-entry.ts +2 -0
- package/src/codec/asd.ts +3 -3
- package/src/codec/conform.ts +3 -3
- package/src/filter-pushdown/collector.ts +1 -1
- package/src/filter-pushdown/deserialize.ts +13 -10
- package/src/filter-pushdown/evaluate.ts +3 -2
- package/src/filter-pushdown/history.ts +3 -2
- package/src/filter-pushdown/types.ts +10 -10
- package/src/functions/continuation.ts +1 -1
- package/src/functions/projection.ts +1 -1
- package/src/functions/registry.ts +14 -14
- package/src/functions/scalar.ts +3 -3
- package/src/functions/storage-cf-do.ts +2 -2
- package/src/functions/table-buffering.ts +25 -21
- package/src/functions/table-in-out.ts +8 -8
- package/src/functions/table.ts +27 -25
- package/src/functions/types.ts +47 -47
- package/src/generated/vgi-service.ts +5 -3
- package/src/http/fetch.ts +17 -12
- package/src/index.core.ts +2 -0
- package/src/protocol/carried-init-request.ts +1 -1
- package/src/protocol/dispatch.ts +3 -3
- package/src/protocol/handlers/aggregate.ts +8 -7
- package/src/protocol/handlers/catalog/shared.ts +1 -1
- package/src/protocol/handlers/function.ts +2 -2
- package/src/protocol/serializers/cardinality.ts +16 -3
- package/src/protocol/state-serializer.ts +1 -1
- package/src/protocol/types.ts +5 -5
- package/src/rpc-server.ts +13 -12
- package/src/serve-entry.ts +18 -18
- package/src/split-token.ts +10 -9
- package/src/types.ts +9 -2
- package/src/util/defined.ts +30 -0
- package/src/util/parent-rows.ts +2 -2
- package/src/worker.ts +15 -14
|
@@ -3123,12 +3123,14 @@ export function registerVgiService(protocol: Protocol, service: VgiService): Pro
|
|
|
3123
3123
|
continue;
|
|
3124
3124
|
}
|
|
3125
3125
|
const stream = service[m.key] as VgiStream;
|
|
3126
|
+
// Optional members are spread in only when present, so the options bag
|
|
3127
|
+
// type-checks under exactOptionalPropertyTypes.
|
|
3126
3128
|
const common = {
|
|
3127
3129
|
params: m.params,
|
|
3128
3130
|
outputSchema: stream.outputSchema,
|
|
3129
|
-
headerSchema: m.header
|
|
3130
|
-
headerInit: stream.headerInit,
|
|
3131
|
-
onCancel: stream.onCancel,
|
|
3131
|
+
...(m.header ? { headerSchema: m.header } : {}),
|
|
3132
|
+
...(stream.headerInit ? { headerInit: stream.headerInit } : {}),
|
|
3133
|
+
...(stream.onCancel ? { onCancel: stream.onCancel } : {}),
|
|
3132
3134
|
doc: m.doc,
|
|
3133
3135
|
};
|
|
3134
3136
|
if (stream.kind === "exchange") {
|
package/src/http/fetch.ts
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
// `buildVgiProtocol` as `signingKey`, from one source. Passing different keys to
|
|
11
11
|
// those two seams produces a worker that mints tokens it cannot recover.
|
|
12
12
|
|
|
13
|
+
import { omitUndefined } from "../util/defined.js";
|
|
13
14
|
import {
|
|
14
15
|
AuthContext,
|
|
15
16
|
createHttpHandler,
|
|
@@ -41,14 +42,14 @@ export interface VgiFetchOptions extends HostingOptions {
|
|
|
41
42
|
* configured key hosts `vgi.attach_tickets.v1` (with the ability to issue
|
|
42
43
|
* grants): tickets sealed under a generated key would die on restart.
|
|
43
44
|
* Defaults to `true`, since this factory requires the key to be passed. */
|
|
44
|
-
signingKeyConfigured?: boolean;
|
|
45
|
+
signingKeyConfigured?: boolean | undefined;
|
|
45
46
|
/** State-token TTL in seconds (default 3600). */
|
|
46
|
-
tokenTtl?: number;
|
|
47
|
+
tokenTtl?: number | undefined;
|
|
47
48
|
/** URL path prefix for VGI requests (default "/vgi"). Pass "" to mount at
|
|
48
49
|
* the root, which is what a dedicated single-worker HTTP server wants. */
|
|
49
|
-
prefix?: string;
|
|
50
|
+
prefix?: string | undefined;
|
|
50
51
|
/** Server ID for state-token attribution (default "vgi-cf"). */
|
|
51
|
-
serverId?: string;
|
|
52
|
+
serverId?: string | undefined;
|
|
52
53
|
/** CORS allowed origins, added to all responses so the preflight `OPTIONS`
|
|
53
54
|
* that browser clients send before `__describe__` succeeds.
|
|
54
55
|
*
|
|
@@ -60,9 +61,9 @@ export interface VgiFetchOptions extends HostingOptions {
|
|
|
60
61
|
* always defaulted this way; this matches it so both entries agree.
|
|
61
62
|
*
|
|
62
63
|
* Pass `null` to disable CORS. */
|
|
63
|
-
corsOrigins?: string | null;
|
|
64
|
+
corsOrigins?: string | null | undefined;
|
|
64
65
|
/** Public source-repository URL, surfaced on the landing page. */
|
|
65
|
-
repositoryUrl?: string;
|
|
66
|
+
repositoryUrl?: string | undefined;
|
|
66
67
|
/** Worker identity for the standardized VGI landing surface: `GET /` serves
|
|
67
68
|
* the shared landing.html plus a JSON status document carrying this
|
|
68
69
|
* identity, and `GET /vgi-client.js` serves the browser client build the
|
|
@@ -85,13 +86,13 @@ export interface VgiFetchOptions extends HostingOptions {
|
|
|
85
86
|
* Supplying it is what makes a worker able to serve more than one principal,
|
|
86
87
|
* and the identity it returns is the one the worker seals `attach_opaque_data`
|
|
87
88
|
* and split tokens under. */
|
|
88
|
-
authenticate?: AuthenticateFn;
|
|
89
|
+
authenticate?: AuthenticateFn | undefined;
|
|
89
90
|
/** Off-wire transport identities, including a trusted Iroh HTTP bridge. */
|
|
90
|
-
peerIdentityProviders?: readonly PeerIdentityProvider[];
|
|
91
|
+
peerIdentityProviders?: readonly PeerIdentityProvider[] | undefined;
|
|
91
92
|
/** Policy composing peer evidence with application authentication. */
|
|
92
|
-
peerAuthenticationPolicy?: PeerAuthenticationPolicy;
|
|
93
|
+
peerAuthenticationPolicy?: PeerAuthenticationPolicy | undefined;
|
|
93
94
|
/** Host adapter supplying the physical peer and multiplicity-preserving headers. */
|
|
94
|
-
peerResolutionContext?: (request: Request) => PeerResolutionOptions | Promise<PeerResolutionOptions
|
|
95
|
+
peerResolutionContext?: ((request: Request) => PeerResolutionOptions | Promise<PeerResolutionOptions>) | undefined;
|
|
95
96
|
}
|
|
96
97
|
|
|
97
98
|
// ---------------------------------------------------------------------------
|
|
@@ -226,7 +227,11 @@ export function createVgiFetch(opts: VgiFetchOptions): (req: Request) => Promise
|
|
|
226
227
|
const reservedCheck = checkReservedAttachOptions(opts.protocol.catalogInterface);
|
|
227
228
|
reservedCheck.catch((e) => console.error(`VGI worker refused to serve: ${(e as Error).message}`));
|
|
228
229
|
|
|
229
|
-
|
|
230
|
+
// vgi-rpc's own types disagree under exactOptionalPropertyTypes:
|
|
231
|
+
// `VgiRpcServer.identity` is `IdentityImpl | undefined` while `ProtocolHost`
|
|
232
|
+
// declares `identity?: {...}` without `| undefined`. Both mean "may be
|
|
233
|
+
// absent"; the cast only bridges the declarations.
|
|
234
|
+
const handler = createHttpHandler(server as Parameters<typeof createHttpHandler>[0], omitUndefined({
|
|
230
235
|
prefix,
|
|
231
236
|
serverId,
|
|
232
237
|
tokenKey: opts.signingKey,
|
|
@@ -249,7 +254,7 @@ export function createVgiFetch(opts: VgiFetchOptions): (req: Request) => Promise
|
|
|
249
254
|
// no reason — a VGI worker always has the real thing.
|
|
250
255
|
extraRoutes: createLandingRoutes(opts.landingInfo),
|
|
251
256
|
enableLandingPage: false,
|
|
252
|
-
});
|
|
257
|
+
}));
|
|
253
258
|
return async (req: Request) => {
|
|
254
259
|
await reservedCheck;
|
|
255
260
|
const storage = await ensureRequestAuthStorage();
|
package/src/index.core.ts
CHANGED
|
@@ -366,6 +366,8 @@ export { VgiClient, VgiClientError } from "./client/client.js";
|
|
|
366
366
|
export type {
|
|
367
367
|
VgiClientOptions,
|
|
368
368
|
TableFunctionOptions,
|
|
369
|
+
TableFunctionRowsOptions,
|
|
370
|
+
Int64Mode,
|
|
369
371
|
ScalarFunctionOptions,
|
|
370
372
|
TableInOutFunctionOptions,
|
|
371
373
|
OnCreateConflict,
|
|
@@ -93,7 +93,7 @@ const stats = { parses: 0, hits: 0 };
|
|
|
93
93
|
function hashBytes(bytes: Uint8Array): number {
|
|
94
94
|
let h = 0x811c9dc5 ^ bytes.byteLength;
|
|
95
95
|
for (let i = 0; i < bytes.byteLength; i++) {
|
|
96
|
-
h ^= bytes[i]
|
|
96
|
+
h ^= bytes[i]!;
|
|
97
97
|
h = Math.imul(h, 0x01000193);
|
|
98
98
|
}
|
|
99
99
|
return h >>> 0;
|
package/src/protocol/dispatch.ts
CHANGED
|
@@ -21,15 +21,15 @@ import { catalogHandlers } from "./handlers/catalog/index.js";
|
|
|
21
21
|
|
|
22
22
|
export interface ProtocolConfig {
|
|
23
23
|
registry: FunctionRegistry;
|
|
24
|
-
catalogInterface?: CatalogInterface;
|
|
25
|
-
catalogName?: string;
|
|
24
|
+
catalogInterface?: CatalogInterface | undefined;
|
|
25
|
+
catalogName?: string | undefined;
|
|
26
26
|
/**
|
|
27
27
|
* AEAD signing key for sealing catalog opaque-data envelopes. Pass the same
|
|
28
28
|
* 32-byte key used for HTTP state tokens. When omitted (subprocess / unix
|
|
29
29
|
* transports) attach_opaque_data / transaction_opaque_data pass through
|
|
30
30
|
* unsealed — OS process ownership already enforces identity there.
|
|
31
31
|
*/
|
|
32
|
-
signingKey?: Uint8Array;
|
|
32
|
+
signingKey?: Uint8Array | undefined;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
/**
|
|
@@ -203,8 +203,8 @@ export function aggregateHandlers(registry: FunctionRegistry): Partial<VgiServic
|
|
|
203
203
|
}
|
|
204
204
|
const touchedTargets = new Set<bigint>();
|
|
205
205
|
for (let i = 0; i < batch.numRows; i++) {
|
|
206
|
-
const src = srcIds[i]
|
|
207
|
-
const tgt = tgtIds[i]
|
|
206
|
+
const src = srcIds[i]!;
|
|
207
|
+
const tgt = tgtIds[i]!;
|
|
208
208
|
const srcHas = exec.states.has(src);
|
|
209
209
|
const tgtHas = exec.states.has(tgt);
|
|
210
210
|
if (!srcHas && !tgtHas) continue;
|
|
@@ -307,6 +307,7 @@ function extractArgMap(
|
|
|
307
307
|
}
|
|
308
308
|
}
|
|
309
309
|
for (let i = 0; i < constNames.length; i++) {
|
|
310
|
+
const name = constNames[i]!;
|
|
310
311
|
let v: any;
|
|
311
312
|
try {
|
|
312
313
|
v = args.get(i);
|
|
@@ -325,18 +326,18 @@ function extractArgMap(
|
|
|
325
326
|
// args.get throws when the arg isn't set — fall back to the declared
|
|
326
327
|
// default so aggregates called without an explicit const value still
|
|
327
328
|
// see it in update/finalize.
|
|
328
|
-
const def = cfg.argDefaults?.[
|
|
329
|
-
if (def !== undefined) out[
|
|
329
|
+
const def = cfg.argDefaults?.[name];
|
|
330
|
+
if (def !== undefined) out[name] = def;
|
|
330
331
|
continue;
|
|
331
332
|
}
|
|
332
333
|
// Enforce declared constraints on the supplied value. This sits OUTSIDE the
|
|
333
334
|
// try above so a constraint violation propagates as a bind error rather than
|
|
334
335
|
// being swallowed and silently replaced by the default.
|
|
335
|
-
const constraints = cfg.argConstraints?.[
|
|
336
|
+
const constraints = cfg.argConstraints?.[name];
|
|
336
337
|
if (constraints !== undefined) {
|
|
337
|
-
validateConstConstraints(
|
|
338
|
+
validateConstConstraints(name, constraints, v);
|
|
338
339
|
}
|
|
339
|
-
out[
|
|
340
|
+
out[name] = v;
|
|
340
341
|
}
|
|
341
342
|
// Non-const args aren't in the wire Arguments, but users may still want
|
|
342
343
|
// defaults surfaced for `params.args` — apply them here.
|
|
@@ -81,7 +81,7 @@ export async function openAttach(
|
|
|
81
81
|
/** Hex of a byte array (lowercase). */
|
|
82
82
|
function toHex(b: Uint8Array): string {
|
|
83
83
|
let s = "";
|
|
84
|
-
for (let i = 0; i < b.length; i++) s += b[i]
|
|
84
|
+
for (let i = 0; i < b.length; i++) s += b[i]!.toString(16).padStart(2, "0");
|
|
85
85
|
return s;
|
|
86
86
|
}
|
|
87
87
|
|
|
@@ -55,7 +55,7 @@ import {
|
|
|
55
55
|
|
|
56
56
|
export interface FunctionHandlerConfig {
|
|
57
57
|
registry: FunctionRegistry;
|
|
58
|
-
signingKey?: Uint8Array;
|
|
58
|
+
signingKey?: Uint8Array | undefined;
|
|
59
59
|
/**
|
|
60
60
|
* Used to map a bind's `attach_opaque_data` to its catalog, so resolution can
|
|
61
61
|
* be scoped when two catalogs declare the same schema and function name.
|
|
@@ -74,7 +74,7 @@ export interface FunctionHandlerConfig {
|
|
|
74
74
|
* livelock returning no rows, blaming the data for moving when it has not.
|
|
75
75
|
*/
|
|
76
76
|
version?(attach: Uint8Array, txn?: Uint8Array): number | Promise<number>;
|
|
77
|
-
};
|
|
77
|
+
} | undefined;
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
/**
|
|
@@ -28,12 +28,25 @@ export function deserializeCardinalityRequest(
|
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
/** Normalise one cardinality field to the wire's int64 (`bigint`) or null. */
|
|
32
|
+
function cardinalityValue(
|
|
33
|
+
name: "estimate" | "max",
|
|
34
|
+
v: number | bigint | null | undefined,
|
|
35
|
+
): bigint | null {
|
|
36
|
+
if (v === null || v === undefined) return null;
|
|
37
|
+
if (typeof v === "bigint") return v;
|
|
38
|
+
if (typeof v === "number" && Number.isInteger(v)) return BigInt(v);
|
|
39
|
+
throw new TypeError(
|
|
40
|
+
`TableCardinality.${name} must be an integer number, a bigint, or null (got ${typeof v}: ${String(v)})`,
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
31
44
|
export function serializeTableCardinality(
|
|
32
45
|
card: TableCardinality
|
|
33
|
-
):
|
|
46
|
+
): { estimate: bigint | null; max: bigint | null } {
|
|
34
47
|
return {
|
|
35
|
-
estimate: card.estimate,
|
|
36
|
-
max: card.max,
|
|
48
|
+
estimate: cardinalityValue("estimate", card.estimate),
|
|
49
|
+
max: cardinalityValue("max", card.max),
|
|
37
50
|
};
|
|
38
51
|
}
|
|
39
52
|
|
|
@@ -274,7 +274,7 @@ export const arrowStateSerializer: StateSerializer = {
|
|
|
274
274
|
if (bytes.byteLength < 10 || bytes[0] !== STATE_FORMAT_VERSION) {
|
|
275
275
|
throw new Error("exchange state has an unknown format (minted by another build of this worker?)");
|
|
276
276
|
}
|
|
277
|
-
const flags = bytes[1]
|
|
277
|
+
const flags = bytes[1]!; // in range: byteLength >= 10 was checked above
|
|
278
278
|
const maxWorkers = view.getFloat64(2, true);
|
|
279
279
|
let offset = 10;
|
|
280
280
|
// Each field is copied out, not viewed: Arrow readers want a buffer of
|
package/src/protocol/types.ts
CHANGED
|
@@ -109,13 +109,13 @@ export type BindRepeatability = "UNKNOWN" | "STABLE_WITHIN_QUERY";
|
|
|
109
109
|
|
|
110
110
|
export interface BindResponse {
|
|
111
111
|
/** Omitted provider values serialize as UNKNOWN. Wire values are required. */
|
|
112
|
-
repeatability?: BindRepeatability;
|
|
113
|
-
projection_expression_profiles?: string[];
|
|
112
|
+
repeatability?: BindRepeatability | undefined;
|
|
113
|
+
projection_expression_profiles?: string[] | undefined;
|
|
114
114
|
output_schema: VgiSchema;
|
|
115
115
|
opaque_data: Uint8Array | null;
|
|
116
|
-
lookup_secret_types?: string[];
|
|
117
|
-
lookup_scopes?: string[];
|
|
118
|
-
lookup_names?: string[];
|
|
116
|
+
lookup_secret_types?: string[] | undefined;
|
|
117
|
+
lookup_scopes?: string[] | undefined;
|
|
118
|
+
lookup_names?: string[] | undefined;
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
export interface InitRequest {
|
package/src/rpc-server.ts
CHANGED
|
@@ -34,6 +34,7 @@ import {
|
|
|
34
34
|
} from "@query-farm/vgi-rpc";
|
|
35
35
|
import { buildAttachTicketsProtocol, resolveTicketMaxTtl } from "./attach-ticket.js";
|
|
36
36
|
import type { CatalogInterface } from "./catalog/interface.js";
|
|
37
|
+
import { omitUndefined } from "./util/defined.js";
|
|
37
38
|
|
|
38
39
|
/** The transport a server is being built for. Only `"http"` changes what is
|
|
39
40
|
* hosted (identity); the rest are recorded so the decision lives here rather
|
|
@@ -81,7 +82,7 @@ export interface HostingOptions {
|
|
|
81
82
|
* `vgi_rpc.Identity.v2` is enabled through {@link resolveToken} /
|
|
82
83
|
* {@link mintGrant}. Violations are a startup error naming this hook.
|
|
83
84
|
*/
|
|
84
|
-
hostedProtocols?: () => Iterable<Protocol
|
|
85
|
+
hostedProtocols?: (() => Iterable<Protocol>) | undefined;
|
|
85
86
|
|
|
86
87
|
/**
|
|
87
88
|
* Resolve an opaque bearer credential to the identity it authenticates as.
|
|
@@ -102,7 +103,7 @@ export interface HostingOptions {
|
|
|
102
103
|
* Requires {@link introspectPrincipals} (or `VGI_INTROSPECT_PRINCIPALS`);
|
|
103
104
|
* there is no permissive default, and a worker without one refuses to start.
|
|
104
105
|
*/
|
|
105
|
-
resolveToken?: TokenResolver;
|
|
106
|
+
resolveToken?: TokenResolver | undefined;
|
|
106
107
|
|
|
107
108
|
/**
|
|
108
109
|
* Mint a standing delegation credential for the *calling* user. Supplying
|
|
@@ -111,18 +112,18 @@ export interface HostingOptions {
|
|
|
111
112
|
* {@link resolveToken}). Needs no allowlist: it is not an oracle about
|
|
112
113
|
* anybody else.
|
|
113
114
|
*/
|
|
114
|
-
mintGrant?: GrantMinter;
|
|
115
|
+
mintGrant?: GrantMinter | undefined;
|
|
115
116
|
|
|
116
117
|
/**
|
|
117
118
|
* Principals permitted to call `introspect_token`. When omitted,
|
|
118
119
|
* `VGI_INTROSPECT_PRINCIPALS` (comma-separated) is read. Only consulted when
|
|
119
120
|
* {@link resolveToken} is supplied.
|
|
120
121
|
*/
|
|
121
|
-
introspectPrincipals?: Iterable<string
|
|
122
|
+
introspectPrincipals?: Iterable<string> | undefined;
|
|
122
123
|
|
|
123
124
|
/** Maximum age of the caller's authentication for `issue_grant`, in
|
|
124
125
|
* seconds. vgi-rpc's default when omitted. */
|
|
125
|
-
maxAuthAge?: number;
|
|
126
|
+
maxAuthAge?: number | undefined;
|
|
126
127
|
|
|
127
128
|
/**
|
|
128
129
|
* Sealed-grant keys (vgi-rpc `GrantKeys`), turning on the framework's own
|
|
@@ -136,7 +137,7 @@ export interface HostingOptions {
|
|
|
136
137
|
* malformed key refuses to start. `null` turns grants off regardless of the
|
|
137
138
|
* environment.
|
|
138
139
|
*/
|
|
139
|
-
grantKeys?: GrantKeys | null;
|
|
140
|
+
grantKeys?: GrantKeys | null | undefined;
|
|
140
141
|
}
|
|
141
142
|
|
|
142
143
|
/** Server-level options passed through to `VgiRpcServer`. */
|
|
@@ -194,14 +195,14 @@ export function buildRpcServer(
|
|
|
194
195
|
const tickets = buildAttachTickets(hosting, grantKeys, options.attachTickets, env);
|
|
195
196
|
if (tickets) protocols.push(tickets);
|
|
196
197
|
}
|
|
197
|
-
return new VgiRpcServer(primary, {
|
|
198
|
+
return new VgiRpcServer(primary, omitUndefined({
|
|
198
199
|
serverId: options.serverId,
|
|
199
200
|
protocols,
|
|
200
201
|
identity,
|
|
201
202
|
// Resolved here, per transport, rather than by vgi-rpc's own environment
|
|
202
203
|
// default: identity (and so grants) is hosted on HTTP only.
|
|
203
204
|
grantKeys: null,
|
|
204
|
-
});
|
|
205
|
+
}));
|
|
205
206
|
}
|
|
206
207
|
|
|
207
208
|
/** Call `hostedProtocols()` once and check its shape and names.
|
|
@@ -271,7 +272,7 @@ function buildIdentity(
|
|
|
271
272
|
): IdentityImpl | undefined {
|
|
272
273
|
const { resolveToken, mintGrant } = hosting;
|
|
273
274
|
if (!resolveToken && !mintGrant && !grantKeys) return undefined;
|
|
274
|
-
return new IdentityImpl({
|
|
275
|
+
return new IdentityImpl(omitUndefined({
|
|
275
276
|
resolveToken,
|
|
276
277
|
// Absent with grant keys configured, vgi-rpc mints sealed grants itself.
|
|
277
278
|
mintGrant,
|
|
@@ -280,7 +281,7 @@ function buildIdentity(
|
|
|
280
281
|
// nothing is not an oracle and needs no allowlist.
|
|
281
282
|
introspectPrincipals: resolveToken ? resolveIntrospectPrincipals(hosting.introspectPrincipals, env) : undefined,
|
|
282
283
|
maxAuthAge: hosting.maxAuthAge,
|
|
283
|
-
});
|
|
284
|
+
}));
|
|
284
285
|
}
|
|
285
286
|
|
|
286
287
|
/** Build `vgi.attach_tickets.v1`, or `undefined` when it must not be hosted.
|
|
@@ -358,10 +359,10 @@ export function grantKeysFromArgv(
|
|
|
358
359
|
): GrantKeys | undefined {
|
|
359
360
|
const keys: string[] = [];
|
|
360
361
|
for (let i = 0; i < argv.length; i++) {
|
|
361
|
-
const a = argv[i]
|
|
362
|
+
const a = argv[i]!;
|
|
362
363
|
if (a === "--grant-key") {
|
|
363
364
|
if (i + 1 >= argv.length) throw new Error("--grant-key requires a value");
|
|
364
|
-
keys.push(argv[++i]);
|
|
365
|
+
keys.push(argv[++i]!);
|
|
365
366
|
} else if (a.startsWith("--grant-key=")) {
|
|
366
367
|
keys.push(a.slice("--grant-key=".length));
|
|
367
368
|
}
|
package/src/serve-entry.ts
CHANGED
|
@@ -61,14 +61,14 @@ export interface IrohHttpBridgeOptions {
|
|
|
61
61
|
/** Worker-local namespace for EndpointId principals. */
|
|
62
62
|
issuer: string;
|
|
63
63
|
/** Exact bridge IP addresses. No CIDRs or hostnames. */
|
|
64
|
-
trustedProxyAddresses?: readonly string[];
|
|
64
|
+
trustedProxyAddresses?: readonly string[] | undefined;
|
|
65
65
|
/** Authenticate the EndpointId (default) or expose evidence only. */
|
|
66
|
-
authenticate?: boolean;
|
|
66
|
+
authenticate?: boolean | undefined;
|
|
67
67
|
/**
|
|
68
68
|
* Host-specific physical peer and raw-header adapter. Required because a
|
|
69
69
|
* Fetch Request alone does not preserve duplicate header fields.
|
|
70
70
|
*/
|
|
71
|
-
peerResolutionContext?: (request: Request) => PeerResolutionOptions | Promise<PeerResolutionOptions
|
|
71
|
+
peerResolutionContext?: ((request: Request) => PeerResolutionOptions | Promise<PeerResolutionOptions>) | undefined;
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
export interface ServeVgiWorkerOptions extends HostingOptions {
|
|
@@ -84,34 +84,34 @@ export interface ServeVgiWorkerOptions extends HostingOptions {
|
|
|
84
84
|
catalogInterface: CatalogInterface;
|
|
85
85
|
|
|
86
86
|
/** Public source-repository URL, linked from the landing page. */
|
|
87
|
-
repositoryUrl?: string;
|
|
87
|
+
repositoryUrl?: string | undefined;
|
|
88
88
|
/** Overrides `$PORT` (default 8787). Pass 0 to bind an ephemeral port. */
|
|
89
|
-
port?: number;
|
|
89
|
+
port?: number | undefined;
|
|
90
90
|
/** Bind address. Iroh bridge mode defaults to loopback; otherwise Bun's default. */
|
|
91
|
-
hostname?: string;
|
|
91
|
+
hostname?: string | undefined;
|
|
92
92
|
/** Overrides `$VGI_SIGNING_KEY`. 32 bytes. */
|
|
93
|
-
signingKey?: Uint8Array;
|
|
93
|
+
signingKey?: Uint8Array | undefined;
|
|
94
94
|
/** Overrides `$VGI_TOKEN_TTL` (default 3600 seconds). */
|
|
95
|
-
tokenTtl?: number;
|
|
95
|
+
tokenTtl?: number | undefined;
|
|
96
96
|
/** Overrides `$CORS_ORIGINS` (default "*"). Pass `null` to disable CORS. */
|
|
97
|
-
corsOrigins?: string | null;
|
|
97
|
+
corsOrigins?: string | null | undefined;
|
|
98
98
|
/** Server ID for state-token attribution (default: `name`). */
|
|
99
|
-
serverId?: string;
|
|
99
|
+
serverId?: string | undefined;
|
|
100
100
|
/** Mount point for the VGI endpoints (default "", the origin root). */
|
|
101
|
-
prefix?: string;
|
|
101
|
+
prefix?: string | undefined;
|
|
102
102
|
/** Suppress the startup banner on stdout. */
|
|
103
|
-
quiet?: boolean;
|
|
103
|
+
quiet?: boolean | undefined;
|
|
104
104
|
/** Environment source (default `process.env`). */
|
|
105
|
-
env?: ServeEnv;
|
|
105
|
+
env?: ServeEnv | undefined;
|
|
106
106
|
/** Command-line arguments to read `--grant-key KEY` (repeatable, first mints)
|
|
107
107
|
* from. Default `process.argv.slice(2)`. A key here takes precedence over
|
|
108
108
|
* `VGI_RPC_GRANT_KEYS`; an explicit {@link grantKeys} over both. */
|
|
109
|
-
argv?: readonly string[];
|
|
109
|
+
argv?: readonly string[] | undefined;
|
|
110
110
|
/** Authenticates each request, returning the caller's `AuthContext`.
|
|
111
111
|
* Omit for an anonymous worker (the default). */
|
|
112
|
-
authenticate?: AuthenticateFn;
|
|
112
|
+
authenticate?: AuthenticateFn | undefined;
|
|
113
113
|
/** Preserve authenticated Iroh identity forwarded by an adjacent HTTP bridge. */
|
|
114
|
-
irohBridge?: IrohHttpBridgeOptions;
|
|
114
|
+
irohBridge?: IrohHttpBridgeOptions | undefined;
|
|
115
115
|
}
|
|
116
116
|
|
|
117
117
|
/** The slice of `Bun.serve`'s return value this module uses. */
|
|
@@ -125,7 +125,7 @@ export interface VgiHttpServer {
|
|
|
125
125
|
interface BunLike {
|
|
126
126
|
serve(options: {
|
|
127
127
|
port: number;
|
|
128
|
-
hostname?: string;
|
|
128
|
+
hostname?: string | undefined;
|
|
129
129
|
fetch: (req: Request) => Promise<Response>;
|
|
130
130
|
}): VgiHttpServer;
|
|
131
131
|
}
|
|
@@ -302,7 +302,7 @@ export function serveVgiWorker(opts: ServeVgiWorkerOptions): VgiHttpServer {
|
|
|
302
302
|
const immediatePeer = server.requestIP?.(request)?.address;
|
|
303
303
|
const forwarded = request.headers.get(IROH_FORWARDED_ENDPOINT_HEADER);
|
|
304
304
|
return {
|
|
305
|
-
immediatePeer,
|
|
305
|
+
...(immediatePeer !== undefined ? { immediatePeer } : {}),
|
|
306
306
|
headers: forwarded === null
|
|
307
307
|
? {}
|
|
308
308
|
: { [IROH_FORWARDED_ENDPOINT_HEADER]: [forwarded] },
|
package/src/split-token.ts
CHANGED
|
@@ -95,7 +95,7 @@ function concat(...parts: Uint8Array[]): Uint8Array {
|
|
|
95
95
|
function equalBytes(a: Uint8Array, b: Uint8Array): boolean {
|
|
96
96
|
if (a.length !== b.length) return false;
|
|
97
97
|
let diff = 0;
|
|
98
|
-
for (let i = 0; i < a.length; i++) diff |= a[i] ^ b[i]
|
|
98
|
+
for (let i = 0; i < a.length; i++) diff |= a[i]! ^ b[i]!;
|
|
99
99
|
return diff === 0;
|
|
100
100
|
}
|
|
101
101
|
|
|
@@ -163,8 +163,8 @@ export async function buildSplitToken(opts: {
|
|
|
163
163
|
payload: Uint8Array;
|
|
164
164
|
fingerprint: Uint8Array;
|
|
165
165
|
anchor: Uint8Array;
|
|
166
|
-
signingKey?: Uint8Array;
|
|
167
|
-
auth?: AuthContext;
|
|
166
|
+
signingKey?: Uint8Array | undefined;
|
|
167
|
+
auth?: AuthContext | undefined;
|
|
168
168
|
}): Promise<Uint8Array> {
|
|
169
169
|
const { payload, fingerprint, anchor, signingKey, auth } = opts;
|
|
170
170
|
if (fingerprint.length !== FINGERPRINT_LEN) {
|
|
@@ -200,10 +200,10 @@ export async function buildSplitToken(opts: {
|
|
|
200
200
|
export async function openSplitToken(
|
|
201
201
|
token: Uint8Array,
|
|
202
202
|
opts: {
|
|
203
|
-
signingKey?: Uint8Array;
|
|
204
|
-
auth?: AuthContext;
|
|
205
|
-
expectedFingerprint?: Uint8Array;
|
|
206
|
-
currentAnchor?: Uint8Array;
|
|
203
|
+
signingKey?: Uint8Array | undefined;
|
|
204
|
+
auth?: AuthContext | undefined;
|
|
205
|
+
expectedFingerprint?: Uint8Array | undefined;
|
|
206
|
+
currentAnchor?: Uint8Array | undefined;
|
|
207
207
|
} = {},
|
|
208
208
|
): Promise<Uint8Array> {
|
|
209
209
|
const { signingKey, auth, expectedFingerprint, currentAnchor } = opts;
|
|
@@ -214,8 +214,9 @@ export async function openSplitToken(
|
|
|
214
214
|
`split token too short: ${token.length} bytes, need at least ${HEADER_LEN}`,
|
|
215
215
|
);
|
|
216
216
|
}
|
|
217
|
-
|
|
218
|
-
const
|
|
217
|
+
// Both in range: the length check above guarantees HEADER_LEN bytes.
|
|
218
|
+
const version = token[0]!;
|
|
219
|
+
const flags = token[1]!;
|
|
219
220
|
const view = new DataView(token.buffer, token.byteOffset, token.byteLength);
|
|
220
221
|
const anchorLen = view.getUint16(2, true);
|
|
221
222
|
|
package/src/types.ts
CHANGED
|
@@ -89,9 +89,16 @@ export const VGI_CHOICES_KEY = "vgi_choices";
|
|
|
89
89
|
export const VGI_RANGE_KEY = "vgi_range";
|
|
90
90
|
export const VGI_PATTERN_KEY = "vgi_pattern";
|
|
91
91
|
|
|
92
|
+
/**
|
|
93
|
+
* Row-count estimate/upper bound returned by a table function's `cardinality`
|
|
94
|
+
* hook. Both travel as int64 on the wire, so either a `number` (must be an
|
|
95
|
+
* integer) or a `bigint` is accepted — int64 arguments arrive as `bigint`, so
|
|
96
|
+
* `{ estimate: args.count, max: args.count }` works without a `Number(...)`
|
|
97
|
+
* conversion. `null` means unknown.
|
|
98
|
+
*/
|
|
92
99
|
export interface TableCardinality {
|
|
93
|
-
estimate: number | null;
|
|
94
|
-
max: number | null;
|
|
100
|
+
estimate: number | bigint | null;
|
|
101
|
+
max: number | bigint | null;
|
|
95
102
|
}
|
|
96
103
|
|
|
97
104
|
// Default max workers (matches Python DEFAULT_MAX_WORKERS = 99999)
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Copyright 2025, 2026 Query Farm LLC - https://query.farm
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The type of `T` with every property whose value may be `undefined` made
|
|
5
|
+
* optional and stripped of `undefined` — the shape `omitUndefined` returns.
|
|
6
|
+
* It is assignable to option bags declared `{ k?: V }` under
|
|
7
|
+
* `exactOptionalPropertyTypes`.
|
|
8
|
+
*/
|
|
9
|
+
export type OmitUndefined<T> = {
|
|
10
|
+
[K in keyof T as undefined extends T[K] ? never : K]: T[K];
|
|
11
|
+
} & {
|
|
12
|
+
[K in keyof T as undefined extends T[K] ? K : never]?: Exclude<T[K], undefined>;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Copy `obj` without the keys whose value is `undefined`.
|
|
17
|
+
*
|
|
18
|
+
* Used when forwarding optional settings to an options bag owned by another
|
|
19
|
+
* package (vgi-rpc, Bun) whose optional properties do not admit an explicit
|
|
20
|
+
* `undefined`. Readers of such bags treat an absent key and an `undefined`
|
|
21
|
+
* one identically (`??`, destructuring defaults), so this only changes the
|
|
22
|
+
* static type.
|
|
23
|
+
*/
|
|
24
|
+
export function omitUndefined<T extends object>(obj: T): OmitUndefined<T> {
|
|
25
|
+
const out: Record<string, unknown> = {};
|
|
26
|
+
for (const [k, v] of Object.entries(obj)) {
|
|
27
|
+
if (v !== undefined) out[k] = v;
|
|
28
|
+
}
|
|
29
|
+
return out as OmitUndefined<T>;
|
|
30
|
+
}
|
package/src/util/parent-rows.ts
CHANGED
|
@@ -14,13 +14,13 @@ export function encodeParentRows(parentRows: ArrayLike<number>): string {
|
|
|
14
14
|
const raw = new Uint8Array(parentRows.length * 4);
|
|
15
15
|
const dv = new DataView(raw.buffer);
|
|
16
16
|
for (let i = 0; i < parentRows.length; i++) {
|
|
17
|
-
dv.setInt32(i * 4, parentRows[i]
|
|
17
|
+
dv.setInt32(i * 4, parentRows[i]!, true);
|
|
18
18
|
}
|
|
19
19
|
if (typeof (globalThis as any).Buffer !== "undefined") {
|
|
20
20
|
return (globalThis as any).Buffer.from(raw).toString("base64");
|
|
21
21
|
}
|
|
22
22
|
let bin = "";
|
|
23
|
-
for (let i = 0; i < raw.length; i++) bin += String.fromCharCode(raw[i]);
|
|
23
|
+
for (let i = 0; i < raw.length; i++) bin += String.fromCharCode(raw[i]!);
|
|
24
24
|
return (globalThis as any).btoa(bin);
|
|
25
25
|
}
|
|
26
26
|
|