@query-farm/vgi 0.44.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.
- package/dist/arrow/impl-arrowjs/index.d.ts +1 -1
- package/dist/arrow/impl-arrowjs/ipc.d.ts +6 -0
- package/dist/arrow/impl-flechette/build.d.ts +2 -2
- package/dist/arrow/impl-flechette/canonical.d.ts +1 -1
- package/dist/arrow/impl-flechette/index.d.ts +1 -1
- package/dist/arrow/impl-flechette/ipc.d.ts +6 -0
- package/dist/arrow/index.d.ts +1 -1
- package/dist/catalog/contents-codec.d.ts +7 -0
- package/dist/catalog/contents-digest.d.ts +2 -1
- package/dist/catalog/interface.d.ts +3 -0
- package/dist/catalog/publication-envelope.d.ts +1 -0
- package/dist/catalog/publication.d.ts +142 -0
- package/dist/catalog/s3-publication.d.ts +38 -0
- package/dist/client-entry.js +136 -25
- package/dist/client-entry.js.map +13 -12
- package/dist/codec/asd.d.ts +4 -0
- package/dist/generated/vgi-client.d.ts +6 -14
- package/dist/generated/vgi-protocol-schemas.d.ts +2 -0
- package/dist/generated/vgi-protocol-types.d.ts +26 -3
- package/dist/generated/vgi-service.d.ts +3 -3
- package/dist/index.d.ts +4 -0
- package/dist/index.js +739 -81
- package/dist/index.js.map +24 -20
- package/dist/protocol/dispatch.d.ts +1 -1
- package/dist/protocol/handlers/catalog/contents.d.ts +4 -4
- package/dist/serve-entry.js +610 -78
- package/dist/serve-entry.js.map +19 -16
- package/dist/worker-cf-entry.js +626 -86
- package/dist/worker-cf-entry.js.map +21 -18
- package/package.json +3 -3
- package/src/arrow/impl-arrowjs/index.ts +1 -0
- package/src/arrow/impl-arrowjs/ipc.ts +23 -0
- package/src/arrow/impl-flechette/build.ts +4 -2
- package/src/arrow/impl-flechette/canonical.ts +7 -2
- package/src/arrow/impl-flechette/index.ts +1 -0
- package/src/arrow/impl-flechette/ipc.ts +19 -0
- package/src/arrow/index.ts +1 -1
- package/src/catalog/contents-codec.ts +77 -0
- package/src/catalog/contents-digest.ts +20 -17
- package/src/catalog/interface.ts +3 -0
- package/src/catalog/publication-envelope.ts +62 -0
- package/src/catalog/publication.ts +290 -0
- package/src/catalog/read-only.ts +0 -2
- package/src/catalog/s3-publication.ts +81 -0
- package/src/client/client.ts +2 -19
- package/src/codec/asd.ts +40 -1
- package/src/codec/conform.ts +2 -1
- package/src/generated/vgi-client.ts +7 -16
- package/src/generated/vgi-protocol-schemas.ts +13 -6
- package/src/generated/vgi-protocol-types.ts +39 -5
- package/src/generated/vgi-service.ts +4 -3
- package/src/index.ts +5 -0
- package/src/protocol/dispatch.ts +1 -1
- package/src/protocol/handlers/catalog/admin.ts +7 -4
- package/src/protocol/handlers/catalog/contents.ts +50 -35
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// GENERATED by vgi.codegen.ts_types. DO NOT EDIT BY HAND.
|
|
3
3
|
//
|
|
4
4
|
// Generator: python -m vgi.codegen.ts_types v1
|
|
5
|
-
// Content hash:
|
|
5
|
+
// Content hash: 65401a7ca1e1
|
|
6
6
|
//
|
|
7
7
|
// To regenerate:
|
|
8
8
|
// uv run --project ~/Development/vgi-python python scripts/regen_generated.py
|
|
@@ -14,8 +14,8 @@ import {
|
|
|
14
14
|
CatalogContentsResultSchema,
|
|
15
15
|
SchemaContentsSchema,
|
|
16
16
|
} from "./vgi-protocol-schemas.js";
|
|
17
|
-
import type { CatalogAttachResult, CatalogContentsResponse
|
|
18
|
-
export type { CatalogAttachResult, CatalogContentsResponse
|
|
17
|
+
import type { CatalogAttachResult, CatalogContentsResponse } from "./vgi-client.js";
|
|
18
|
+
export type { CatalogAttachResult, CatalogContentsResponse };
|
|
19
19
|
|
|
20
20
|
// ----------------------------------------------------------------------------
|
|
21
21
|
// CatalogAttachResult (schema: CatalogAttachResultSchema)
|
|
@@ -68,6 +68,30 @@ export const decodeCatalogAttachResult = (b: Uint8Array): CatalogAttachResult =>
|
|
|
68
68
|
// SchemaContents (schema: SchemaContentsSchema)
|
|
69
69
|
// ----------------------------------------------------------------------------
|
|
70
70
|
|
|
71
|
+
/** 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. */
|
|
72
|
+
export interface SchemaContents {
|
|
73
|
+
/** The schema path. Equals `SchemaInfo.path` inside `schema`, so a client can name the schema without decoding it. */
|
|
74
|
+
path: string[];
|
|
75
|
+
/** The schema's `SchemaInfo` item (a `catalog_schemas` entry). */
|
|
76
|
+
schema: Uint8Array;
|
|
77
|
+
/** `TableInfo` items (`catalog_schema_contents_tables`). */
|
|
78
|
+
tables: Uint8Array[];
|
|
79
|
+
/** `ViewInfo` items (`catalog_schema_contents_views`). */
|
|
80
|
+
views: Uint8Array[];
|
|
81
|
+
/** `FunctionInfo` items, `SCALAR_FUNCTION`. */
|
|
82
|
+
scalar_functions: Uint8Array[];
|
|
83
|
+
/** `FunctionInfo` items, `AGGREGATE_FUNCTION`. */
|
|
84
|
+
aggregate_functions: Uint8Array[];
|
|
85
|
+
/** `FunctionInfo` items, `TABLE_FUNCTION`. */
|
|
86
|
+
table_functions: Uint8Array[];
|
|
87
|
+
/** `MacroInfo` items, `SCALAR_MACRO`. */
|
|
88
|
+
scalar_macros: Uint8Array[];
|
|
89
|
+
/** `MacroInfo` items, `TABLE_MACRO`. */
|
|
90
|
+
table_macros: Uint8Array[];
|
|
91
|
+
/** `IndexInfo` items (`catalog_schema_contents_indexes`). */
|
|
92
|
+
indexes: Uint8Array[];
|
|
93
|
+
}
|
|
94
|
+
|
|
71
95
|
/** Fields of `SchemaContents` that have a protocol default. */
|
|
72
96
|
export type SchemaContentsDefaultedField =
|
|
73
97
|
| "tables"
|
|
@@ -108,7 +132,12 @@ export const decodeSchemaContents = (b: Uint8Array): SchemaContents => decodeASD
|
|
|
108
132
|
export type CatalogContentsResponseDefaultedField =
|
|
109
133
|
| "etag"
|
|
110
134
|
| "not_modified"
|
|
111
|
-
| "schemas"
|
|
135
|
+
| "schemas"
|
|
136
|
+
| "tables"
|
|
137
|
+
| "views"
|
|
138
|
+
| "functions"
|
|
139
|
+
| "macros"
|
|
140
|
+
| "indexes";
|
|
112
141
|
/** `CatalogContentsResponse` with every field that has a protocol default optional. */
|
|
113
142
|
export type CatalogContentsResponseInit = Omit<CatalogContentsResponse, CatalogContentsResponseDefaultedField> & Partial<Pick<CatalogContentsResponse, CatalogContentsResponseDefaultedField>>;
|
|
114
143
|
|
|
@@ -118,7 +147,12 @@ export function buildCatalogContentsResponse(init: CatalogContentsResponseInit):
|
|
|
118
147
|
catalog_version: init.catalog_version,
|
|
119
148
|
etag: init.etag ?? null,
|
|
120
149
|
not_modified: init.not_modified ?? false,
|
|
121
|
-
schemas: init.schemas ??
|
|
150
|
+
schemas: init.schemas ?? null,
|
|
151
|
+
tables: init.tables ?? null,
|
|
152
|
+
views: init.views ?? null,
|
|
153
|
+
functions: init.functions ?? null,
|
|
154
|
+
macros: init.macros ?? null,
|
|
155
|
+
indexes: init.indexes ?? null,
|
|
122
156
|
};
|
|
123
157
|
}
|
|
124
158
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// GENERATED by vgi.codegen.ts_registry. DO NOT EDIT BY HAND.
|
|
3
3
|
//
|
|
4
4
|
// Generator: python -m vgi.codegen.ts_registry v1
|
|
5
|
-
// Content hash:
|
|
5
|
+
// Content hash: 56897005f0e2
|
|
6
6
|
//
|
|
7
7
|
// To regenerate:
|
|
8
8
|
// uv run --project ~/Development/vgi-python python scripts/regen_generated.py
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
import {
|
|
11
11
|
type CallContext,
|
|
12
12
|
type ExchangeFn,
|
|
13
|
+
type ExternalRef,
|
|
13
14
|
type ExchangeInit,
|
|
14
15
|
type HeaderInit,
|
|
15
16
|
MethodNotImplementedError,
|
|
@@ -37,10 +38,10 @@ import {
|
|
|
37
38
|
export const VGI_PROTOCOL_NAME = "vgi.v2";
|
|
38
39
|
|
|
39
40
|
/** The protocol's semver, stamped on every request by a client of this protocol. */
|
|
40
|
-
export const VGI_PROTOCOL_VERSION = "2.
|
|
41
|
+
export const VGI_PROTOCOL_VERSION = "2.2.0";
|
|
41
42
|
|
|
42
43
|
/** What a unary handler returns: the result row, now or later. */
|
|
43
|
-
export type VgiReply<T> = T | Promise<T>;
|
|
44
|
+
export type VgiReply<T> = T | ExternalRef | Promise<T | ExternalRef>;
|
|
44
45
|
|
|
45
46
|
/** The result of a unary method with no `result` column. */
|
|
46
47
|
export type NoResult = Record<string, never>;
|
package/src/index.ts
CHANGED
|
@@ -9,3 +9,8 @@ export * from "./index.core.js";
|
|
|
9
9
|
|
|
10
10
|
// Worker (node/bun only — stdio + AF_UNIX launcher transport)
|
|
11
11
|
export { Worker, type WorkerConfig } from "./worker.js";
|
|
12
|
+
|
|
13
|
+
export { CatalogSnapshotManager, MemoryCatalogPublicationRepository, S3CatalogPublicationRepository } from "./catalog/publication.js";
|
|
14
|
+
export type { CatalogSnapshotPolicy, SnapshotIdentity, SnapshotRequest, CatalogPublicationManifest, CatalogPublicationRepository, CatalogManifestObjectStore } from "./catalog/publication.js";
|
|
15
|
+
export { S3CatalogObjectStorage } from "./catalog/s3-publication.js";
|
|
16
|
+
export type { CatalogS3Signer } from "./catalog/s3-publication.js";
|
package/src/protocol/dispatch.ts
CHANGED
|
@@ -69,7 +69,7 @@ export { VGI_PROTOCOL_NAME };
|
|
|
69
69
|
* hash covers method names, types and the params/result/header schemas only
|
|
70
70
|
* (WIRE_PROTOCOL.md §14).
|
|
71
71
|
*
|
|
72
|
-
* It changes only with vgi.v2's protocol version (currently 2.
|
|
72
|
+
* It changes only with vgi.v2's protocol version (currently 2.2.0). Asserted
|
|
73
73
|
* by src/protocol/__tests__/vgi-v2-hash.test.ts; if that test fails, the
|
|
74
74
|
* surface drifted from the reference -- fix the schemas, do not bump this.
|
|
75
75
|
*/
|
|
@@ -207,10 +207,13 @@ export function catalogAdminHandlers(getCatalog: GetCatalog, signingKey?: Uint8A
|
|
|
207
207
|
// the committed catalog at catalog_version. `if_none_match` revalidates a
|
|
208
208
|
// snapshot the client holds (etag / not_modified); see ./contents.ts for the
|
|
209
209
|
// rules, the content-hash etag and the frozen-catalog cache.
|
|
210
|
-
const catalogContents =
|
|
211
|
-
const
|
|
212
|
-
return
|
|
213
|
-
|
|
210
|
+
const catalogContents: VgiService["catalogContents"] = async (params, ctx) => {
|
|
211
|
+
const sealedAttach = toUint8Array(params.attach_opaque_data).slice();
|
|
212
|
+
return catalogHandler(signingKey, async (opened, context) => {
|
|
213
|
+
const ifNoneMatch = opened.if_none_match == null ? null : String(opened.if_none_match);
|
|
214
|
+
return serveCatalogContents(getCatalog(), toUint8Array(opened.attach_opaque_data), ifNoneMatch, context, sealedAttach);
|
|
215
|
+
})(params, ctx);
|
|
216
|
+
};
|
|
214
217
|
|
|
215
218
|
// catalog_copy_from_formats — catalog-level (not schema-scoped). Lists the
|
|
216
219
|
// custom COPY ... FROM formats this catalog advertises; empty list when none.
|
|
@@ -1,31 +1,24 @@
|
|
|
1
1
|
// Copyright 2025, 2026 Query Farm LLC - https://query.farm
|
|
2
2
|
// SPDX-License-Identifier: LicenseRef-QueryFarm-Source-Available-1.0
|
|
3
3
|
|
|
4
|
-
// catalog_contents: the worker side of the
|
|
4
|
+
// catalog_contents: the worker side of the wire 2.2 bulk enumeration,
|
|
5
5
|
// with etag revalidation and the frozen-catalog response cache. Mirrors
|
|
6
6
|
// vgi-python's Worker.catalog_contents / _catalog_contents_response.
|
|
7
7
|
|
|
8
|
-
import {
|
|
9
|
-
encodeSchemaInfo,
|
|
10
|
-
encodeTableInfo,
|
|
11
|
-
encodeViewInfo,
|
|
12
|
-
encodeMacroInfo,
|
|
13
|
-
encodeIndexInfo,
|
|
14
|
-
} from "../../../generated/vgi-client.js";
|
|
15
8
|
import {
|
|
16
9
|
buildCatalogContentsResponse,
|
|
17
|
-
buildSchemaContents,
|
|
18
10
|
type CatalogContentsResponse,
|
|
19
|
-
type SchemaContents,
|
|
20
11
|
} from "../../../generated/vgi-protocol-types.js";
|
|
12
|
+
import { ExternalRef, type CallContext } from "@query-farm/vgi-rpc";
|
|
13
|
+
import { CatalogSnapshotManager, type CatalogSnapshotPolicy } from "../../../catalog/publication.js";
|
|
21
14
|
import { CatalogContentsResultSchema } from "../../../generated/vgi-protocol-schemas.js";
|
|
22
|
-
import {
|
|
15
|
+
import { encodeCatalogStreams, decodeCatalogStreams } from "../../../catalog/contents-codec.js";
|
|
23
16
|
import type { AttachOpaqueData, CatalogInterface } from "../../../catalog/interface.js";
|
|
24
17
|
import { catalogContentsDigest } from "../../../catalog/contents-digest.js";
|
|
25
|
-
import { schemaPathKey } from "../../../schema-path.js";
|
|
26
18
|
import { wrapResult } from "../shared.js";
|
|
27
19
|
|
|
28
20
|
type Wire = { result: Uint8Array };
|
|
21
|
+
const schemaPathKey = (path: readonly string[]) => JSON.stringify(path.map((part) => part.toLowerCase()));
|
|
29
22
|
|
|
30
23
|
/** One cached answer per catalog instance, valid for one catalog version. */
|
|
31
24
|
interface ContentsSnapshot {
|
|
@@ -39,6 +32,8 @@ interface ContentsSnapshot {
|
|
|
39
32
|
* (weak, so a dropped catalog takes its snapshot with it). Holds the build
|
|
40
33
|
* promise, so concurrent first calls build once.
|
|
41
34
|
*/
|
|
35
|
+
const PUBLICATIONS = new WeakMap<CatalogSnapshotPolicy, CatalogSnapshotManager>();
|
|
36
|
+
|
|
42
37
|
const CACHE = new WeakMap<CatalogInterface, Promise<ContentsSnapshot>>();
|
|
43
38
|
|
|
44
39
|
/**
|
|
@@ -47,9 +42,8 @@ const CACHE = new WeakMap<CatalogInterface, Promise<ContentsSnapshot>>();
|
|
|
47
42
|
* Enforces the revalidation rules: `not_modified` needs an etag equal to
|
|
48
43
|
* `ifNoneMatch` and no schemas; a catalog with no etag never yields
|
|
49
44
|
* `not_modified` (and so ignores `ifNoneMatch`). Validates the schema paths
|
|
50
|
-
* (unique, parent present) and orders them parent-first.
|
|
51
|
-
*
|
|
52
|
-
* byte-identical to catalog_schemas / catalog_schema_contents_* items.
|
|
45
|
+
* (unique, parent present) and orders them parent-first. The six collection
|
|
46
|
+
* streams retain the fields used by the existing per-schema RPC metadata.
|
|
53
47
|
*/
|
|
54
48
|
export async function buildCatalogContents(
|
|
55
49
|
cat: CatalogInterface,
|
|
@@ -83,31 +77,17 @@ export async function buildCatalogContents(
|
|
|
83
77
|
}
|
|
84
78
|
}
|
|
85
79
|
|
|
86
|
-
|
|
87
|
-
const schemas: SchemaContents[] = infos
|
|
88
|
-
.sort((a, b) => a.schema.path.length - b.schema.path.length)
|
|
89
|
-
.map((c) =>
|
|
90
|
-
buildSchemaContents({
|
|
91
|
-
path: [...c.schema.path],
|
|
92
|
-
schema: encodeSchemaInfo(c.schema),
|
|
93
|
-
tables: c.tables.map((t) => encodeTableInfo(t)),
|
|
94
|
-
views: c.views.map((v) => encodeViewInfo(v)),
|
|
95
|
-
scalar_functions: c.scalar_functions.map((f) => encodeFunctionInfoOnce(f)),
|
|
96
|
-
aggregate_functions: c.aggregate_functions.map((f) => encodeFunctionInfoOnce(f)),
|
|
97
|
-
table_functions: c.table_functions.map((f) => encodeFunctionInfoOnce(f)),
|
|
98
|
-
scalar_macros: c.scalar_macros.map((m) => encodeMacroInfo(m)),
|
|
99
|
-
table_macros: c.table_macros.map((m) => encodeMacroInfo(m)),
|
|
100
|
-
indexes: c.indexes.map((i) => encodeIndexInfo(i)),
|
|
101
|
-
}),
|
|
102
|
-
);
|
|
80
|
+
const streams = encodeCatalogStreams(infos.sort((a, b) => a.schema.path.length - b.schema.path.length));
|
|
103
81
|
let etag = etag0;
|
|
104
82
|
if (etag === null && owner.catalogContentsEtag === "content-hash") {
|
|
105
|
-
etag = await catalogContentsDigest(
|
|
83
|
+
etag = await catalogContentsDigest(streams, version);
|
|
106
84
|
}
|
|
107
85
|
if (etag !== null && ifNoneMatch !== null && etag === ifNoneMatch) {
|
|
108
86
|
return buildCatalogContentsResponse({ catalog_version: version, etag, not_modified: true });
|
|
109
87
|
}
|
|
110
|
-
|
|
88
|
+
const response = buildCatalogContentsResponse({ catalog_version: version, etag, ...streams });
|
|
89
|
+
decodeCatalogStreams(response);
|
|
90
|
+
return response;
|
|
111
91
|
}
|
|
112
92
|
|
|
113
93
|
/**
|
|
@@ -123,9 +103,44 @@ export async function serveCatalogContents(
|
|
|
123
103
|
cat: CatalogInterface,
|
|
124
104
|
attach: AttachOpaqueData,
|
|
125
105
|
ifNoneMatch: string | null,
|
|
126
|
-
|
|
106
|
+
callContext?: CallContext,
|
|
107
|
+
sealedAttach: Uint8Array = attach,
|
|
108
|
+
): Promise<Wire | ExternalRef> {
|
|
127
109
|
const owner = cat.catalogContentsOwner(attach);
|
|
128
110
|
const version = Number(await cat.version(attach));
|
|
111
|
+
const policy = owner.catalogSnapshotPolicy;
|
|
112
|
+
if (policy?.delivery === "published") {
|
|
113
|
+
const request = { catalog: cat, attachOpaqueData: attach, callContext, catalogVersion: version };
|
|
114
|
+
const inline = (etag: string) => wrapResult(buildCatalogContentsResponse({ catalog_version: version, etag, not_modified: true }), CatalogContentsResultSchema);
|
|
115
|
+
const cheapEtag = await policy.etag?.(request);
|
|
116
|
+
if (cheapEtag != null && cheapEtag === ifNoneMatch) return inline(cheapEtag);
|
|
117
|
+
let manager = PUBLICATIONS.get(policy);
|
|
118
|
+
if (!manager) { manager = new CatalogSnapshotManager(policy); PUBLICATIONS.set(policy, manager); }
|
|
119
|
+
const scopeBytes = new Uint8Array(await crypto.subtle.digest("SHA-256", sealedAttach as BufferSource));
|
|
120
|
+
const attachmentScope = "attachment:" + Array.from(scopeBytes, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
121
|
+
const identify = async (input: typeof request) => { const id = await policy.identity(input); return { ...id, visibilityScope: id.visibilityScope ?? attachmentScope }; };
|
|
122
|
+
const identity = await identify(request);
|
|
123
|
+
if (identity.catalogVersion !== version) throw new Error("snapshot identity version differs from the attached catalog");
|
|
124
|
+
const assertCurrentIdentity = async () => {
|
|
125
|
+
const currentVersion = Number(await cat.version(attach));
|
|
126
|
+
const current = await identify({ ...request, catalogVersion: currentVersion });
|
|
127
|
+
if (currentVersion !== version || await manager!.key(identity) !== await manager!.key(current)) throw new Error("catalog changed while resolving its publication");
|
|
128
|
+
};
|
|
129
|
+
const buildSnapshot = async (validator: string | null) => {
|
|
130
|
+
const response = await buildCatalogContents(cat, owner, attach, version, validator);
|
|
131
|
+
await assertCurrentIdentity();
|
|
132
|
+
return response;
|
|
133
|
+
};
|
|
134
|
+
try {
|
|
135
|
+
const manifest = await manager.warm(identity, () => buildSnapshot(null));
|
|
136
|
+
await assertCurrentIdentity();
|
|
137
|
+
if (manifest.etag === ifNoneMatch) return inline(manifest.etag);
|
|
138
|
+
return new ExternalRef(manifest.url, manifest.sha256);
|
|
139
|
+
} catch (error) {
|
|
140
|
+
if (policy.onPublicationFailure !== "ordinary") throw error;
|
|
141
|
+
return wrapResult(await buildSnapshot(ifNoneMatch), CatalogContentsResultSchema);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
129
144
|
if (owner.catalogContentsCacheable()) {
|
|
130
145
|
let pending = CACHE.get(owner);
|
|
131
146
|
let snapshot = pending ? await pending.catch(() => null) : null;
|