@query-farm/vgi 0.43.0 → 0.45.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.
Files changed (73) hide show
  1. package/README.md +5 -2
  2. package/dist/arrow/impl-arrowjs/index.d.ts +1 -1
  3. package/dist/arrow/impl-arrowjs/ipc.d.ts +6 -0
  4. package/dist/arrow/impl-flechette/build.d.ts +2 -2
  5. package/dist/arrow/impl-flechette/canonical.d.ts +1 -1
  6. package/dist/arrow/impl-flechette/index.d.ts +1 -1
  7. package/dist/arrow/impl-flechette/ipc.d.ts +6 -0
  8. package/dist/arrow/index.d.ts +1 -1
  9. package/dist/attach-ticket.d.ts +18 -7
  10. package/dist/catalog/contents-codec.d.ts +7 -0
  11. package/dist/catalog/contents-digest.d.ts +2 -1
  12. package/dist/catalog/interface.d.ts +3 -0
  13. package/dist/catalog/publication-envelope.d.ts +1 -0
  14. package/dist/catalog/publication.d.ts +142 -0
  15. package/dist/catalog/s3-publication.d.ts +38 -0
  16. package/dist/client-entry.js +349 -114
  17. package/dist/client-entry.js.map +16 -14
  18. package/dist/codec/asd.d.ts +7 -1
  19. package/dist/codec/conform.d.ts +51 -0
  20. package/dist/errors.d.ts +5 -1
  21. package/dist/generated/vgi-client.d.ts +6 -14
  22. package/dist/generated/vgi-protocol-schemas.d.ts +2 -0
  23. package/dist/generated/vgi-protocol-types.d.ts +26 -3
  24. package/dist/generated/vgi-service.d.ts +3 -3
  25. package/dist/index.core.d.ts +1 -1
  26. package/dist/index.d.ts +4 -0
  27. package/dist/index.js +955 -118
  28. package/dist/index.js.map +33 -28
  29. package/dist/protocol/dispatch.d.ts +1 -1
  30. package/dist/protocol/handlers/catalog/contents.d.ts +4 -4
  31. package/dist/protocol/handlers/shared.d.ts +2 -1
  32. package/dist/protocol/serializers/shared.d.ts +2 -1
  33. package/dist/rpc-server.d.ts +2 -2
  34. package/dist/serve-entry.js +867 -165
  35. package/dist/serve-entry.js.map +26 -22
  36. package/dist/worker-cf-entry.js +825 -114
  37. package/dist/worker-cf-entry.js.map +31 -27
  38. package/package.json +3 -3
  39. package/src/arrow/impl-arrowjs/index.ts +1 -0
  40. package/src/arrow/impl-arrowjs/ipc.ts +23 -0
  41. package/src/arrow/impl-flechette/build.ts +4 -2
  42. package/src/arrow/impl-flechette/canonical.ts +7 -2
  43. package/src/arrow/impl-flechette/index.ts +1 -0
  44. package/src/arrow/impl-flechette/ipc.ts +19 -0
  45. package/src/arrow/index.ts +1 -1
  46. package/src/attach-ticket.ts +41 -13
  47. package/src/catalog/composite.ts +2 -1
  48. package/src/catalog/contents-codec.ts +77 -0
  49. package/src/catalog/contents-digest.ts +20 -17
  50. package/src/catalog/interface.ts +8 -4
  51. package/src/catalog/publication-envelope.ts +62 -0
  52. package/src/catalog/publication.ts +290 -0
  53. package/src/catalog/read-only.ts +8 -8
  54. package/src/catalog/s3-publication.ts +81 -0
  55. package/src/client/client.ts +15 -24
  56. package/src/codec/asd.ts +45 -3
  57. package/src/codec/conform.ts +194 -0
  58. package/src/errors.ts +27 -7
  59. package/src/functions/registry.ts +3 -2
  60. package/src/generated/vgi-client.ts +7 -16
  61. package/src/generated/vgi-protocol-schemas.ts +13 -6
  62. package/src/generated/vgi-protocol-types.ts +39 -5
  63. package/src/generated/vgi-service.ts +4 -3
  64. package/src/http/fetch.ts +1 -1
  65. package/src/index.core.ts +3 -1
  66. package/src/index.ts +5 -0
  67. package/src/protocol/dispatch.ts +1 -1
  68. package/src/protocol/handlers/catalog/admin.ts +7 -4
  69. package/src/protocol/handlers/catalog/contents.ts +50 -35
  70. package/src/protocol/handlers/shared.ts +8 -2
  71. package/src/protocol/serializers/bind.ts +3 -1
  72. package/src/protocol/serializers/shared.ts +5 -2
  73. package/src/rpc-server.ts +7 -7
@@ -15,7 +15,9 @@
15
15
  import { type VgiSchema } from "../arrow/index.js";
16
16
  /**
17
17
  * Encode a typed object as a single-row Arrow IPC stream using `schema`.
18
- * Matches Python's `ArrowSerializableDataclass.serialize_to_bytes()`.
18
+ * Matches Python's `ArrowSerializableDataclass.serialize_to_bytes()`, including
19
+ * its container rules: a non-nullable list/map left out or null is written as
20
+ * empty, and list items / map values are never null (see `conformRecord`).
19
21
  */
20
22
  export declare function encodeASD(schema: VgiSchema, obj: Record<string, any>): Uint8Array;
21
23
  /** Compare two strings by Unicode code point (= UTF-8 byte order). */
@@ -31,3 +33,7 @@ export declare function sortMapsForSchema(schema: VgiSchema, obj: Record<string,
31
33
  * Matches Python's `ArrowSerializableDataclass.deserialize_from_bytes()`.
32
34
  */
33
35
  export declare function decodeASD<T>(schema: VgiSchema, bytes: Uint8Array): T;
36
+ /** Encode ordinary metadata records directly, sharing one schema and dictionary per category. */
37
+ export declare function encodeASDCollection(schema: VgiSchema, records: readonly Record<string, any>[]): Uint8Array | null;
38
+ /** Decode every row of every batch and reject incompatible collection schemas. */
39
+ export declare function decodeASDCollection<T>(schema: VgiSchema, bytes: Uint8Array | null | undefined): T[];
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Wire conformance for protocol records.
3
+ *
4
+ * vgi-python is the reference for the wire shape, and two of its rules are not
5
+ * expressed by a record's Arrow schema nullability flags alone:
6
+ *
7
+ * 1. A **non-nullable list or map column is never null.** Python's dataclass
8
+ * defaults a `list[...]` / `dict[...]` field to an empty container, so an
9
+ * "absent" list goes out as `[]`. A JS caller that leaves the field out (or
10
+ * passes `null`) would otherwise put a null in a column the schema calls
11
+ * non-null — `CatalogInfo.releases`, `CatalogInfo.attach_option_specs`,
12
+ * ... — which a strict client rejects as a protocol error.
13
+ *
14
+ * 2. **List items and map values are never null** unless the Python annotation
15
+ * says so (`list[str | None]`). pyarrow marks every list item field nullable,
16
+ * so the generated schemas carry `item: nullable=true` everywhere and cannot
17
+ * tell the two apart. In the whole protocol exactly one field has optional
18
+ * items — `argument_names` on `BindRequest` / `AggregateBindRequest` (a
19
+ * positional argument has no name). Every other null item is a bug on the
20
+ * sending side (e.g. `BindResponse.lookup_names` built from an unset secret
21
+ * name, where Python sends `""`).
22
+ *
23
+ * `conformRecord` applies both rules to a record about to be encoded: a null or
24
+ * absent non-nullable list/map becomes empty, and a null list item / map value
25
+ * becomes its type's zero value (`""`, `0`, `false`, empty bytes, empty list),
26
+ * which is also what the C++ client reads such an item as. It never mutates its
27
+ * input (catalog items may be frozen and shared) and returns the input itself
28
+ * when nothing needed changing. Nullable columns, and scalars, pass through
29
+ * untouched: a null in a non-nullable scalar column has no safe default and is
30
+ * left for the caller to fix (see `wireViolations`).
31
+ */
32
+ import { type VgiSchema, type VgiDataType } from "../arrow/index.js";
33
+ /**
34
+ * Top-level / struct-child field names whose list items may legitimately be
35
+ * null (the Python annotation is `list[X | None]`). Derived from vgi-python by
36
+ * walking every protocol dataclass's type hints; keep in sync if the protocol
37
+ * adds another optional-item list.
38
+ */
39
+ export declare const OPTIONAL_ITEM_FIELDS: ReadonlySet<string>;
40
+ /** The value a non-null slot of `type` takes when the sender left it null. */
41
+ export declare function zeroValue(type: VgiDataType): unknown;
42
+ /**
43
+ * `obj` conformed to `schema`'s wire rules (see the module comment). Returns
44
+ * `obj` itself when nothing changed.
45
+ */
46
+ export declare function conformRecord<T extends Record<string, any>>(schema: VgiSchema, obj: T): T;
47
+ /**
48
+ * Column-dict form of `conformRecord` for `batchFromColumns` callers: each
49
+ * value is a one-element array holding the row's value.
50
+ */
51
+ export declare function conformColumns(schema: VgiSchema, columns: Record<string, unknown[]>): Record<string, unknown[]>;
package/dist/errors.d.ts CHANGED
@@ -1,6 +1,10 @@
1
+ import type { ErrorCode } from "@query-farm/vgi-rpc";
1
2
  export declare class VgiError extends Error {
2
- constructor(message: string);
3
+ /** Canonical code hoisted as `vgi_rpc.error_code`; unset means `UNKNOWN`. */
4
+ readonly errorCode?: ErrorCode;
5
+ constructor(message: string, code?: ErrorCode);
3
6
  }
7
+ /** A worker bug (the function returned the wrong number of rows): UNKNOWN. */
4
8
  export declare class RowCountMismatchError extends VgiError {
5
9
  constructor(expected: number, actual: number);
6
10
  }
@@ -31,7 +31,6 @@ export interface CatalogInfo {
31
31
  export interface SchemaInfo {
32
32
  comment?: string | null;
33
33
  tags: Record<string, string>;
34
- attach_opaque_data: Uint8Array;
35
34
  path: string[];
36
35
  estimated_object_count?: Record<string, number> | null;
37
36
  }
@@ -362,23 +361,16 @@ export interface CatalogAttachResult {
362
361
  export interface CatalogsResponse {
363
362
  items: CatalogInfo[];
364
363
  }
365
- export interface SchemaContents {
366
- path: string[];
367
- schema: Uint8Array;
368
- tables: Uint8Array[];
369
- views: Uint8Array[];
370
- scalar_functions: Uint8Array[];
371
- aggregate_functions: Uint8Array[];
372
- table_functions: Uint8Array[];
373
- scalar_macros: Uint8Array[];
374
- table_macros: Uint8Array[];
375
- indexes: Uint8Array[];
376
- }
377
364
  export interface CatalogContentsResponse {
378
365
  catalog_version: number;
379
366
  etag?: string | null;
380
367
  not_modified: boolean;
381
- schemas: SchemaContents[];
368
+ schemas?: Uint8Array | null;
369
+ tables?: Uint8Array | null;
370
+ views?: Uint8Array | null;
371
+ functions?: Uint8Array | null;
372
+ macros?: Uint8Array | null;
373
+ indexes?: Uint8Array | null;
382
374
  }
383
375
  export interface CopyFromFormatsResponse {
384
376
  items: Uint8Array[];
@@ -1,3 +1,5 @@
1
+ /** Canonical fingerprint of the nested catalog wire schemas. */
2
+ export declare const VGI_CATALOG_CONTRACT_HASH = "121e8fe1c074bce00a6d0fcec49d7a90f05e45498cd9ca8a5a3b4a9ae2377a2d";
1
3
  export declare const CatalogInfoSchema: import("../index.core.js").VgiSchema;
2
4
  export declare const SchemaInfoSchema: import("../index.core.js").VgiSchema;
3
5
  export declare const TableInfoSchema: import("../index.core.js").VgiSchema;
@@ -1,5 +1,5 @@
1
- import type { CatalogAttachResult, CatalogContentsResponse, SchemaContents } from "./vgi-client.js";
2
- export type { CatalogAttachResult, CatalogContentsResponse, SchemaContents };
1
+ import type { CatalogAttachResult, CatalogContentsResponse } from "./vgi-client.js";
2
+ export type { CatalogAttachResult, CatalogContentsResponse };
3
3
  /** Fields of `CatalogAttachResult` that have a protocol default. */
4
4
  export type CatalogAttachResultDefaultedField = "attach_opaque_data_required" | "default_schema" | "settings" | "secret_types" | "attach_catalogs" | "comment" | "tags" | "supports_column_statistics" | "global_functions" | "global_function_prefix" | "supports_catalog_contents";
5
5
  /** `CatalogAttachResult` with every field that has a protocol default optional. */
@@ -8,6 +8,29 @@ export type CatalogAttachResultInit = Omit<CatalogAttachResult, CatalogAttachRes
8
8
  export declare function buildCatalogAttachResult(init: CatalogAttachResultInit): CatalogAttachResult;
9
9
  export declare const encodeCatalogAttachResult: (v: CatalogAttachResult) => Uint8Array;
10
10
  export declare const decodeCatalogAttachResult: (b: Uint8Array) => CatalogAttachResult;
11
+ /** One schema and everything in it: one struct row of `CatalogContentsResponse.schemas`. Every item is byte-for-byte what the matching per-schema RPC returns in its `items` list, so a client decodes them with the decoders it already has. Each kind is complete: an empty list means the schema has none of that kind. */
12
+ export interface SchemaContents {
13
+ /** The schema path. Equals `SchemaInfo.path` inside `schema`, so a client can name the schema without decoding it. */
14
+ path: string[];
15
+ /** The schema's `SchemaInfo` item (a `catalog_schemas` entry). */
16
+ schema: Uint8Array;
17
+ /** `TableInfo` items (`catalog_schema_contents_tables`). */
18
+ tables: Uint8Array[];
19
+ /** `ViewInfo` items (`catalog_schema_contents_views`). */
20
+ views: Uint8Array[];
21
+ /** `FunctionInfo` items, `SCALAR_FUNCTION`. */
22
+ scalar_functions: Uint8Array[];
23
+ /** `FunctionInfo` items, `AGGREGATE_FUNCTION`. */
24
+ aggregate_functions: Uint8Array[];
25
+ /** `FunctionInfo` items, `TABLE_FUNCTION`. */
26
+ table_functions: Uint8Array[];
27
+ /** `MacroInfo` items, `SCALAR_MACRO`. */
28
+ scalar_macros: Uint8Array[];
29
+ /** `MacroInfo` items, `TABLE_MACRO`. */
30
+ table_macros: Uint8Array[];
31
+ /** `IndexInfo` items (`catalog_schema_contents_indexes`). */
32
+ indexes: Uint8Array[];
33
+ }
11
34
  /** Fields of `SchemaContents` that have a protocol default. */
12
35
  export type SchemaContentsDefaultedField = "tables" | "views" | "scalar_functions" | "aggregate_functions" | "table_functions" | "scalar_macros" | "table_macros" | "indexes";
13
36
  /** `SchemaContents` with every field that has a protocol default optional. */
@@ -17,7 +40,7 @@ export declare function buildSchemaContents(init: SchemaContentsInit): SchemaCon
17
40
  export declare const encodeSchemaContents: (v: SchemaContents) => Uint8Array;
18
41
  export declare const decodeSchemaContents: (b: Uint8Array) => SchemaContents;
19
42
  /** Fields of `CatalogContentsResponse` that have a protocol default. */
20
- export type CatalogContentsResponseDefaultedField = "etag" | "not_modified" | "schemas";
43
+ export type CatalogContentsResponseDefaultedField = "etag" | "not_modified" | "schemas" | "tables" | "views" | "functions" | "macros" | "indexes";
21
44
  /** `CatalogContentsResponse` with every field that has a protocol default optional. */
22
45
  export type CatalogContentsResponseInit = Omit<CatalogContentsResponse, CatalogContentsResponseDefaultedField> & Partial<Pick<CatalogContentsResponse, CatalogContentsResponseDefaultedField>>;
23
46
  /** Build a complete `CatalogContentsResponse`, filling the protocol defaults, in wire order. */
@@ -1,11 +1,11 @@
1
- import { type CallContext, type ExchangeFn, type ExchangeInit, type HeaderInit, type ProducerFn, type ProducerInit, Protocol, type SchemaLike } from "@query-farm/vgi-rpc";
1
+ import { type CallContext, type ExchangeFn, type ExternalRef, type ExchangeInit, type HeaderInit, type ProducerFn, type ProducerInit, Protocol, type SchemaLike } from "@query-farm/vgi-rpc";
2
2
  import { type VgiSchema } from "../arrow/index.js";
3
3
  /** The protocol's wire name: the `vgi_rpc.protocol` routing key and the HTTP path segment. */
4
4
  export declare const VGI_PROTOCOL_NAME = "vgi.v2";
5
5
  /** The protocol's semver, stamped on every request by a client of this protocol. */
6
- export declare const VGI_PROTOCOL_VERSION = "2.1.0";
6
+ export declare const VGI_PROTOCOL_VERSION = "2.2.0";
7
7
  /** What a unary handler returns: the result row, now or later. */
8
- export type VgiReply<T> = T | Promise<T>;
8
+ export type VgiReply<T> = T | ExternalRef | Promise<T | ExternalRef>;
9
9
  /** The result of a unary method with no `result` column. */
10
10
  export type NoResult = Record<string, never>;
11
11
  /** A `list` column's value as the Arrow backend decodes it: a vector on arrow-js, an array on flechette. */
@@ -28,7 +28,7 @@ export type { LandingInfo } from "./http/landing.js";
28
28
  export { createLandingRoutes } from "./http/landing.js";
29
29
  export { BindResultSchema, ScanFunctionResultSchema } from "./generated/vgi-protocol-schemas.js";
30
30
  export { type AttachOptionSpec, serializeAttachOptionSpec, serializeAttachOptionSpecs, deserializeAttachOptionSpec, deserializeAttachOptionSpecs, RESERVED_ATTACH_OPTION, ReservedAttachOptionError, } from "./catalog/attach-option.js";
31
- export { ATTACH_TICKET_OPTION, ATTACH_TICKET_PREFIX, ATTACH_TICKETS_PROTOCOL_NAME, ATTACH_TICKETS_PROTOCOL_VERSION, ATTACH_TICKET_SCHEMA, SEAL_ATTACH_REQUEST_SCHEMA, AttachTicketExpiredError, AttachTicketInvalidError, AttachTicketRequestError, SealAttachDeniedError, type AttachTicketClaims, type RestoredAttach, attachTicketAad, mintAttachTicket, openAttachTicket, redeemAttachTicket, } from "./attach-ticket.js";
31
+ export { ATTACH_TICKET_OPTION, ATTACH_TICKET_PREFIX, ATTACH_TICKETS_PROTOCOL_NAME, ATTACH_TICKETS_PROTOCOL_VERSION, ATTACH_TICKET_SCHEMA, SEAL_ATTACH_REQUEST_SCHEMA, AttachTicketExpiredError, AttachTicketInvalidError, AttachTicketRequestError, SealAttachDeniedError, type AttachTicket, type AttachTicketClaims, type RestoredAttach, encodeAttachTicket, attachTicketAad, mintAttachTicket, openAttachTicket, redeemAttachTicket, } from "./attach-ticket.js";
32
32
  export { type ColumnStatistics, serializeColumnStatistics } from "./util/statistics.js";
33
33
  export { toUint8Array } from "./util/bytes.js";
34
34
  export { iterRows, batchFromRows, batchFromColumns, emptyBatch, filterBatch, projectSchema, projectBatch, batchToScalarDict, batchToSecretDict, safeNumber, } from "./util/arrow/index.js";
package/dist/index.d.ts CHANGED
@@ -1,2 +1,6 @@
1
1
  export * from "./index.core.js";
2
2
  export { Worker, type WorkerConfig } from "./worker.js";
3
+ export { CatalogSnapshotManager, MemoryCatalogPublicationRepository, S3CatalogPublicationRepository } from "./catalog/publication.js";
4
+ export type { CatalogSnapshotPolicy, SnapshotIdentity, SnapshotRequest, CatalogPublicationManifest, CatalogPublicationRepository, CatalogManifestObjectStore } from "./catalog/publication.js";
5
+ export { S3CatalogObjectStorage } from "./catalog/s3-publication.js";
6
+ export type { CatalogS3Signer } from "./catalog/s3-publication.js";