@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.
Files changed (95) hide show
  1. package/dist/arguments/argument-spec.d.ts +17 -11
  2. package/dist/catalog/descriptors.d.ts +2 -2
  3. package/dist/catalog/publication.d.ts +7 -7
  4. package/dist/client/client.d.ts +9 -3
  5. package/dist/client/errors.d.ts +2 -2
  6. package/dist/client/types.d.ts +21 -0
  7. package/dist/client-entry.d.ts +1 -1
  8. package/dist/client-entry.js +31 -7
  9. package/dist/client-entry.js.map +20 -20
  10. package/dist/filter-pushdown/deserialize.d.ts +1 -1
  11. package/dist/filter-pushdown/types.d.ts +10 -10
  12. package/dist/functions/scalar.d.ts +1 -1
  13. package/dist/functions/table-buffering.d.ts +20 -20
  14. package/dist/functions/table-in-out.d.ts +4 -4
  15. package/dist/functions/table.d.ts +7 -7
  16. package/dist/functions/types.d.ts +47 -47
  17. package/dist/http/fetch.d.ts +10 -10
  18. package/dist/index.core.d.ts +1 -1
  19. package/dist/index.js +155 -94
  20. package/dist/index.js.map +53 -52
  21. package/dist/protocol/dispatch.d.ts +3 -3
  22. package/dist/protocol/handlers/function.d.ts +2 -2
  23. package/dist/protocol/serializers/cardinality.d.ts +4 -1
  24. package/dist/protocol/types.d.ts +5 -5
  25. package/dist/rpc-server.d.ts +6 -6
  26. package/dist/serve-entry.d.ts +16 -16
  27. package/dist/serve-entry.js +42 -21
  28. package/dist/serve-entry.js.map +38 -37
  29. package/dist/split-token.d.ts +6 -6
  30. package/dist/types.d.ts +9 -2
  31. package/dist/util/defined.d.ts +21 -0
  32. package/dist/worker-cf-entry.js +120 -85
  33. package/dist/worker-cf-entry.js.map +51 -50
  34. package/dist/worker.d.ts +2 -2
  35. package/package.json +6 -4
  36. package/src/arguments/argument-spec.ts +17 -11
  37. package/src/arrow/codec/registry.ts +2 -2
  38. package/src/arrow/impl-arrowjs/build.ts +1 -1
  39. package/src/arrow/impl-arrowjs/canonical.ts +23 -23
  40. package/src/arrow/impl-arrowjs/empty.ts +2 -2
  41. package/src/arrow/impl-arrowjs/ipc.ts +2 -2
  42. package/src/arrow/impl-arrowjs/iterate.ts +2 -2
  43. package/src/arrow/impl-arrowjs/project.ts +2 -2
  44. package/src/arrow/impl-flechette/build.ts +2 -1
  45. package/src/arrow/impl-flechette/canonical.ts +10 -9
  46. package/src/arrow/impl-flechette/compat.ts +3 -3
  47. package/src/arrow/impl-flechette/message-meta.ts +5 -4
  48. package/src/arrow/impl-flechette/statistics.ts +2 -2
  49. package/src/attach-ticket.ts +2 -2
  50. package/src/catalog/column-metadata.ts +1 -1
  51. package/src/catalog/composite.ts +2 -2
  52. package/src/catalog/constraints.ts +9 -9
  53. package/src/catalog/descriptors.ts +1 -1
  54. package/src/catalog/interface.ts +12 -12
  55. package/src/catalog/publication.ts +9 -8
  56. package/src/catalog/read-only.ts +9 -8
  57. package/src/catalog/sql-grammar.ts +6 -6
  58. package/src/client/client.ts +52 -15
  59. package/src/client/errors.ts +1 -1
  60. package/src/client/types.ts +23 -0
  61. package/src/client-entry.ts +2 -0
  62. package/src/codec/asd.ts +3 -3
  63. package/src/codec/conform.ts +3 -3
  64. package/src/filter-pushdown/collector.ts +1 -1
  65. package/src/filter-pushdown/deserialize.ts +13 -10
  66. package/src/filter-pushdown/evaluate.ts +3 -2
  67. package/src/filter-pushdown/history.ts +3 -2
  68. package/src/filter-pushdown/types.ts +10 -10
  69. package/src/functions/continuation.ts +1 -1
  70. package/src/functions/projection.ts +1 -1
  71. package/src/functions/registry.ts +14 -14
  72. package/src/functions/scalar.ts +3 -3
  73. package/src/functions/storage-cf-do.ts +2 -2
  74. package/src/functions/table-buffering.ts +25 -21
  75. package/src/functions/table-in-out.ts +8 -8
  76. package/src/functions/table.ts +27 -25
  77. package/src/functions/types.ts +47 -47
  78. package/src/generated/vgi-service.ts +5 -3
  79. package/src/http/fetch.ts +17 -12
  80. package/src/index.core.ts +2 -0
  81. package/src/protocol/carried-init-request.ts +1 -1
  82. package/src/protocol/dispatch.ts +3 -3
  83. package/src/protocol/handlers/aggregate.ts +8 -7
  84. package/src/protocol/handlers/catalog/shared.ts +1 -1
  85. package/src/protocol/handlers/function.ts +2 -2
  86. package/src/protocol/serializers/cardinality.ts +16 -3
  87. package/src/protocol/state-serializer.ts +1 -1
  88. package/src/protocol/types.ts +5 -5
  89. package/src/rpc-server.ts +13 -12
  90. package/src/serve-entry.ts +18 -18
  91. package/src/split-token.ts +10 -9
  92. package/src/types.ts +9 -2
  93. package/src/util/defined.ts +30 -0
  94. package/src/util/parent-rows.ts +2 -2
  95. package/src/worker.ts +15 -14
@@ -4,15 +4,15 @@ import type { CatalogInterface } from "../catalog/interface.js";
4
4
  import { VGI_PROTOCOL_NAME, type VgiService } from "../generated/vgi-service.js";
5
5
  export interface ProtocolConfig {
6
6
  registry: FunctionRegistry;
7
- catalogInterface?: CatalogInterface;
8
- catalogName?: string;
7
+ catalogInterface?: CatalogInterface | undefined;
8
+ catalogName?: string | undefined;
9
9
  /**
10
10
  * AEAD signing key for sealing catalog opaque-data envelopes. Pass the same
11
11
  * 32-byte key used for HTTP state tokens. When omitted (subprocess / unix
12
12
  * transports) attach_opaque_data / transaction_opaque_data pass through
13
13
  * unsealed — OS process ownership already enforces identity there.
14
14
  */
15
- signingKey?: Uint8Array;
15
+ signingKey?: Uint8Array | undefined;
16
16
  }
17
17
  /**
18
18
  * Wire name of the VGI protocol: the `vgi_rpc.protocol` routing key and the
@@ -2,7 +2,7 @@ import { type VgiService } from "../../generated/vgi-service.js";
2
2
  import type { FunctionRegistry } from "../../functions/registry.js";
3
3
  export interface FunctionHandlerConfig {
4
4
  registry: FunctionRegistry;
5
- signingKey?: Uint8Array;
5
+ signingKey?: Uint8Array | undefined;
6
6
  /**
7
7
  * Used to map a bind's `attach_opaque_data` to its catalog, so resolution can
8
8
  * be scoped when two catalogs declare the same schema and function name.
@@ -21,7 +21,7 @@ export interface FunctionHandlerConfig {
21
21
  * livelock returning no rows, blaming the data for moving when it has not.
22
22
  */
23
23
  version?(attach: Uint8Array, txn?: Uint8Array): number | Promise<number>;
24
- };
24
+ } | undefined;
25
25
  }
26
26
  /** The per-function lifecycle's `vgi.v3` handlers. */
27
27
  export declare function functionHandlers(config: FunctionHandlerConfig): Partial<VgiService>;
@@ -2,5 +2,8 @@ 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
4
  export declare function deserializeCardinalityRequest(params: Record<string, any>): TableFunctionCardinalityRequest;
5
- export declare function serializeTableCardinality(card: TableCardinality): Record<string, any>;
5
+ export declare function serializeTableCardinality(card: TableCardinality): {
6
+ estimate: bigint | null;
7
+ max: bigint | null;
8
+ };
6
9
  export { TABLE_FUNCTION_CARDINALITY_REQUEST_SCHEMA };
@@ -92,13 +92,13 @@ export interface BindRequest {
92
92
  export type BindRepeatability = "UNKNOWN" | "STABLE_WITHIN_QUERY";
93
93
  export interface BindResponse {
94
94
  /** Omitted provider values serialize as UNKNOWN. Wire values are required. */
95
- repeatability?: BindRepeatability;
96
- projection_expression_profiles?: string[];
95
+ repeatability?: BindRepeatability | undefined;
96
+ projection_expression_profiles?: string[] | undefined;
97
97
  output_schema: VgiSchema;
98
98
  opaque_data: Uint8Array | null;
99
- lookup_secret_types?: string[];
100
- lookup_scopes?: string[];
101
- lookup_names?: string[];
99
+ lookup_secret_types?: string[] | undefined;
100
+ lookup_scopes?: string[] | undefined;
101
+ lookup_names?: string[] | undefined;
102
102
  }
103
103
  export interface InitRequest {
104
104
  bind_call: BindRequest;
@@ -34,7 +34,7 @@ export interface HostingOptions {
34
34
  * `vgi_rpc.Identity.v2` is enabled through {@link resolveToken} /
35
35
  * {@link mintGrant}. Violations are a startup error naming this hook.
36
36
  */
37
- hostedProtocols?: () => Iterable<Protocol>;
37
+ hostedProtocols?: (() => Iterable<Protocol>) | undefined;
38
38
  /**
39
39
  * Resolve an opaque bearer credential to the identity it authenticates as.
40
40
  * Supplying it hosts `vgi_rpc.Identity.v2`'s `introspect_token` -- on HTTP,
@@ -54,7 +54,7 @@ export interface HostingOptions {
54
54
  * Requires {@link introspectPrincipals} (or `VGI_INTROSPECT_PRINCIPALS`);
55
55
  * there is no permissive default, and a worker without one refuses to start.
56
56
  */
57
- resolveToken?: TokenResolver;
57
+ resolveToken?: TokenResolver | undefined;
58
58
  /**
59
59
  * Mint a standing delegation credential for the *calling* user. Supplying
60
60
  * it hosts `issue_grant` (HTTP only). Throw `GrantRefusedError` to decline,
@@ -62,16 +62,16 @@ export interface HostingOptions {
62
62
  * {@link resolveToken}). Needs no allowlist: it is not an oracle about
63
63
  * anybody else.
64
64
  */
65
- mintGrant?: GrantMinter;
65
+ mintGrant?: GrantMinter | undefined;
66
66
  /**
67
67
  * Principals permitted to call `introspect_token`. When omitted,
68
68
  * `VGI_INTROSPECT_PRINCIPALS` (comma-separated) is read. Only consulted when
69
69
  * {@link resolveToken} is supplied.
70
70
  */
71
- introspectPrincipals?: Iterable<string>;
71
+ introspectPrincipals?: Iterable<string> | undefined;
72
72
  /** Maximum age of the caller's authentication for `issue_grant`, in
73
73
  * seconds. vgi-rpc's default when omitted. */
74
- maxAuthAge?: number;
74
+ maxAuthAge?: number | undefined;
75
75
  /**
76
76
  * Sealed-grant keys (vgi-rpc `GrantKeys`), turning on the framework's own
77
77
  * grants on HTTP: `issue_grant` mints `vgig1.` tokens (unless
@@ -84,7 +84,7 @@ export interface HostingOptions {
84
84
  * malformed key refuses to start. `null` turns grants off regardless of the
85
85
  * environment.
86
86
  */
87
- grantKeys?: GrantKeys | null;
87
+ grantKeys?: GrantKeys | null | undefined;
88
88
  }
89
89
  /** Server-level options passed through to `VgiRpcServer`. */
90
90
  export interface BuildRpcServerOptions {
@@ -26,14 +26,14 @@ export interface IrohHttpBridgeOptions {
26
26
  /** Worker-local namespace for EndpointId principals. */
27
27
  issuer: string;
28
28
  /** Exact bridge IP addresses. No CIDRs or hostnames. */
29
- trustedProxyAddresses?: readonly string[];
29
+ trustedProxyAddresses?: readonly string[] | undefined;
30
30
  /** Authenticate the EndpointId (default) or expose evidence only. */
31
- authenticate?: boolean;
31
+ authenticate?: boolean | undefined;
32
32
  /**
33
33
  * Host-specific physical peer and raw-header adapter. Required because a
34
34
  * Fetch Request alone does not preserve duplicate header fields.
35
35
  */
36
- peerResolutionContext?: (request: Request) => PeerResolutionOptions | Promise<PeerResolutionOptions>;
36
+ peerResolutionContext?: ((request: Request) => PeerResolutionOptions | Promise<PeerResolutionOptions>) | undefined;
37
37
  }
38
38
  export interface ServeVgiWorkerOptions extends HostingOptions {
39
39
  /** Short worker name shown on the landing page, e.g. "ishares". */
@@ -47,34 +47,34 @@ export interface ServeVgiWorkerOptions extends HostingOptions {
47
47
  /** Catalog DuckDB attaches to. */
48
48
  catalogInterface: CatalogInterface;
49
49
  /** Public source-repository URL, linked from the landing page. */
50
- repositoryUrl?: string;
50
+ repositoryUrl?: string | undefined;
51
51
  /** Overrides `$PORT` (default 8787). Pass 0 to bind an ephemeral port. */
52
- port?: number;
52
+ port?: number | undefined;
53
53
  /** Bind address. Iroh bridge mode defaults to loopback; otherwise Bun's default. */
54
- hostname?: string;
54
+ hostname?: string | undefined;
55
55
  /** Overrides `$VGI_SIGNING_KEY`. 32 bytes. */
56
- signingKey?: Uint8Array;
56
+ signingKey?: Uint8Array | undefined;
57
57
  /** Overrides `$VGI_TOKEN_TTL` (default 3600 seconds). */
58
- tokenTtl?: number;
58
+ tokenTtl?: number | undefined;
59
59
  /** Overrides `$CORS_ORIGINS` (default "*"). Pass `null` to disable CORS. */
60
- corsOrigins?: string | null;
60
+ corsOrigins?: string | null | undefined;
61
61
  /** Server ID for state-token attribution (default: `name`). */
62
- serverId?: string;
62
+ serverId?: string | undefined;
63
63
  /** Mount point for the VGI endpoints (default "", the origin root). */
64
- prefix?: string;
64
+ prefix?: string | undefined;
65
65
  /** Suppress the startup banner on stdout. */
66
- quiet?: boolean;
66
+ quiet?: boolean | undefined;
67
67
  /** Environment source (default `process.env`). */
68
- env?: ServeEnv;
68
+ env?: ServeEnv | undefined;
69
69
  /** Command-line arguments to read `--grant-key KEY` (repeatable, first mints)
70
70
  * from. Default `process.argv.slice(2)`. A key here takes precedence over
71
71
  * `VGI_RPC_GRANT_KEYS`; an explicit {@link grantKeys} over both. */
72
- argv?: readonly string[];
72
+ argv?: readonly string[] | undefined;
73
73
  /** Authenticates each request, returning the caller's `AuthContext`.
74
74
  * Omit for an anonymous worker (the default). */
75
- authenticate?: AuthenticateFn;
75
+ authenticate?: AuthenticateFn | undefined;
76
76
  /** Preserve authenticated Iroh identity forwarded by an adjacent HTTP bridge. */
77
- irohBridge?: IrohHttpBridgeOptions;
77
+ irohBridge?: IrohHttpBridgeOptions | undefined;
78
78
  }
79
79
  /** The slice of `Bun.serve`'s return value this module uses. */
80
80
  export interface VgiHttpServer {
@@ -626,6 +626,16 @@ import {
626
626
  GrantKeys as GrantKeys2
627
627
  } from "@query-farm/vgi-rpc";
628
628
 
629
+ // src/util/defined.ts
630
+ function omitUndefined(obj) {
631
+ const out = {};
632
+ for (const [k, v] of Object.entries(obj)) {
633
+ if (v !== undefined)
634
+ out[k] = v;
635
+ }
636
+ return out;
637
+ }
638
+
629
639
  // src/http/fetch.ts
630
640
  import {
631
641
  AuthContext,
@@ -3133,10 +3143,19 @@ function deserializeCardinalityRequest(params) {
3133
3143
  bind_opaque_data: params.bind_opaque_data ? toUint8Array2(params.bind_opaque_data) : null
3134
3144
  };
3135
3145
  }
3146
+ function cardinalityValue(name, v) {
3147
+ if (v === null || v === undefined)
3148
+ return null;
3149
+ if (typeof v === "bigint")
3150
+ return v;
3151
+ if (typeof v === "number" && Number.isInteger(v))
3152
+ return BigInt(v);
3153
+ throw new TypeError(`TableCardinality.${name} must be an integer number, a bigint, or null (got ${typeof v}: ${String(v)})`);
3154
+ }
3136
3155
  function serializeTableCardinality(card) {
3137
3156
  return {
3138
- estimate: card.estimate,
3139
- max: card.max
3157
+ estimate: cardinalityValue("estimate", card.estimate),
3158
+ max: cardinalityValue("max", card.max)
3140
3159
  };
3141
3160
  }
3142
3161
  // src/protocol/carried-init-request.ts
@@ -4857,9 +4876,9 @@ function registerVgiService(protocol, service) {
4857
4876
  const common = {
4858
4877
  params: m.params,
4859
4878
  outputSchema: stream.outputSchema,
4860
- headerSchema: m.header ?? undefined,
4861
- headerInit: stream.headerInit,
4862
- onCancel: stream.onCancel,
4879
+ ...m.header ? { headerSchema: m.header } : {},
4880
+ ...stream.headerInit ? { headerInit: stream.headerInit } : {},
4881
+ ...stream.onCancel ? { onCancel: stream.onCancel } : {},
4863
4882
  doc: m.doc
4864
4883
  };
4865
4884
  if (stream.kind === "exchange") {
@@ -9206,6 +9225,7 @@ function extractArgMap(cfg, args) {
9206
9225
  }
9207
9226
  }
9208
9227
  for (let i = 0;i < constNames.length; i++) {
9228
+ const name = constNames[i];
9209
9229
  let v;
9210
9230
  try {
9211
9231
  v = args.get(i);
@@ -9220,16 +9240,16 @@ function extractArgMap(cfg, args) {
9220
9240
  v = Number(v);
9221
9241
  }
9222
9242
  } catch {
9223
- const def = cfg.argDefaults?.[constNames[i]];
9243
+ const def = cfg.argDefaults?.[name];
9224
9244
  if (def !== undefined)
9225
- out[constNames[i]] = def;
9245
+ out[name] = def;
9226
9246
  continue;
9227
9247
  }
9228
- const constraints = cfg.argConstraints?.[constNames[i]];
9248
+ const constraints = cfg.argConstraints?.[name];
9229
9249
  if (constraints !== undefined) {
9230
- validateConstConstraints(constNames[i], constraints, v);
9250
+ validateConstConstraints(name, constraints, v);
9231
9251
  }
9232
- out[constNames[i]] = v;
9252
+ out[name] = v;
9233
9253
  }
9234
9254
  if (cfg.argDefaults) {
9235
9255
  for (const [name, def] of Object.entries(cfg.argDefaults)) {
@@ -10205,15 +10225,16 @@ class CatalogSnapshotManager {
10205
10225
  validateCatalogPublicationEnvelope(bytes);
10206
10226
  }
10207
10227
  });
10208
- if (resolved.numRows !== 1 || resolved.schema.fields.length !== 1 || resolved.schema.fields[0].name !== "result" || typeSignature(resolved.schema.fields[0].type) !== typeSignature(binary2()) || resolved.schema.fields[0].nullable)
10228
+ const resultField = resolved.schema.fields.length === 1 ? resolved.schema.fields[0] : undefined;
10229
+ if (resolved.numRows !== 1 || !resultField || resultField.name !== "result" || typeSignature(resultField.type) !== typeSignature(binary2()) || resultField.nullable)
10209
10230
  throw new Error("invalid published RPC envelope");
10210
10231
  const bytes = resolved.getChild("result")?.get(0);
10211
10232
  if (!(bytes instanceof Uint8Array))
10212
10233
  throw new Error("published catalog has no result bytes");
10213
10234
  const decoded = decodeASDCollection(CatalogContentsResultSchema, bytes);
10214
- if (decoded.length !== 1)
10235
+ const response = decoded.length === 1 ? decoded[0] : undefined;
10236
+ if (!response)
10215
10237
  throw new Error("published catalog must contain exactly one response row");
10216
- const response = decoded[0];
10217
10238
  if (response.not_modified || Number(response.catalog_version) !== identity.catalogVersion || response.etag !== m.etag)
10218
10239
  throw new Error("published catalog version or ETag mismatch");
10219
10240
  decodeCatalogStreams(response);
@@ -11589,12 +11610,12 @@ function buildRpcServer(primary, hosting, options) {
11589
11610
  if (tickets)
11590
11611
  protocols.push(tickets);
11591
11612
  }
11592
- return new VgiRpcServer(primary, {
11613
+ return new VgiRpcServer(primary, omitUndefined({
11593
11614
  serverId: options.serverId,
11594
11615
  protocols,
11595
11616
  identity,
11596
11617
  grantKeys: null
11597
- });
11618
+ }));
11598
11619
  }
11599
11620
  function validatedHostedProtocols(hosting, primary) {
11600
11621
  if (hosting.hostedProtocols === undefined)
@@ -11638,13 +11659,13 @@ function buildIdentity(hosting, grantKeys, env) {
11638
11659
  const { resolveToken, mintGrant } = hosting;
11639
11660
  if (!resolveToken && !mintGrant && !grantKeys)
11640
11661
  return;
11641
- return new IdentityImpl({
11662
+ return new IdentityImpl(omitUndefined({
11642
11663
  resolveToken,
11643
11664
  mintGrant,
11644
11665
  grantKeys: grantKeys ?? undefined,
11645
11666
  introspectPrincipals: resolveToken ? resolveIntrospectPrincipals(hosting.introspectPrincipals, env) : undefined,
11646
11667
  maxAuthAge: hosting.maxAuthAge
11647
- });
11668
+ }));
11648
11669
  }
11649
11670
  function buildAttachTickets(hosting, grantKeys, config, env) {
11650
11671
  if (!config || !config.signingKeyConfigured || !config.signingKey)
@@ -11743,7 +11764,7 @@ function createVgiFetch(opts) {
11743
11764
  });
11744
11765
  const reservedCheck = checkReservedAttachOptions(opts.protocol.catalogInterface);
11745
11766
  reservedCheck.catch((e) => console.error(`VGI worker refused to serve: ${e.message}`));
11746
- const handler = createHttpHandler(server, {
11767
+ const handler = createHttpHandler(server, omitUndefined({
11747
11768
  prefix,
11748
11769
  serverId,
11749
11770
  tokenKey: opts.signingKey,
@@ -11758,7 +11779,7 @@ function createVgiFetch(opts) {
11758
11779
  repositoryUrl: opts.repositoryUrl,
11759
11780
  extraRoutes: createLandingRoutes(opts.landingInfo),
11760
11781
  enableLandingPage: false
11761
- });
11782
+ }));
11762
11783
  return async (req) => {
11763
11784
  await reservedCheck;
11764
11785
  const storage = await ensureRequestAuthStorage();
@@ -11875,7 +11896,7 @@ function serveVgiWorker(opts) {
11875
11896
  const immediatePeer = server.requestIP?.(request)?.address;
11876
11897
  const forwarded = request.headers.get(IROH_FORWARDED_ENDPOINT_HEADER);
11877
11898
  return {
11878
- immediatePeer,
11899
+ ...immediatePeer !== undefined ? { immediatePeer } : {},
11879
11900
  headers: forwarded === null ? {} : { [IROH_FORWARDED_ENDPOINT_HEADER]: [forwarded] }
11880
11901
  };
11881
11902
  }
@@ -11902,4 +11923,4 @@ export {
11902
11923
  serveVgiWorker
11903
11924
  };
11904
11925
 
11905
- //# debugId=C9BDB2DE50B86FAE64756E2164756E21
11926
+ //# debugId=7B9431FBBB6E4B0564756E2164756E21