SQL-for-Data-Analytics
Perform fast and efficient data analysis with the power of SQL
- 303
- Jupyter Notebook
- MIT
- 2 y ago

TypeScript SDK for the VGI (Vector Gateway Interface) protocol — host DuckDB scalar, table, aggregate, and table-in-out functions in an external worker over Arrow IPC.
Repo Query-farm/vgi-typescript, read from GitHub 1 min ago. Query-farm has not joined Take My Repo.
Query-farm/vgi-typescript is a public repo on GitHub by Query-farm. TypeScript SDK for the VGI (Vector Gateway Interface) protocol — host DuckDB scalar, table, aggregate, and table-in-out functions in an external worker over Arrow IPC. It declares no license on GitHub. Public does not mean open source: without a license, nobody is granted the right to reuse it. It is written mainly in TypeScript, has 1 stars and last changed on 2026-11-21. Nobody has reviewed it on Take My Repo yet, which says nothing about its quality. Read from GitHub on 2026-11-23.
In the maintainer's words. Shown from GitHub; Take My Repo does not keep a copy.
Add your own functions and tables to DuckDB with TypeScript and Apache Arrow.
Built by 🚜 Query.Farm
TypeScript framework for extending DuckDB with user-defined functions written in TypeScript, served to DuckDB over the Vector Gateway Interface (VGI) — an Apache Arrow IPC protocol.
You write scalar, table, aggregate, and table-in-out functions (plus catalogs) in
TypeScript; a worker exposes them; DuckDB attaches to the worker and calls them as
if they were native. It is wire-compatible with vgi-python,
so a worker written in either language is interchangeable.
LOAD vgi; ATTACH 'demo' AS demo (TYPE vgi, LOCATION '/path/to/your-worker'); SELECT demo.upper_case(name) FROM users;
The fastest way to a new TypeScript worker is the
vgi-starter-typescript template: a complete,
tested worker with a scalar, a table function and a paginated REST API example, recipes for
common data-engineering tasks, SQL and unit tests, metadata that scores 100 on
vgi-lint, CI, Docker, signed release workflows,
and an AGENTS.md for coding agents.
gh repo create my-worker --template Query-farm/vgi-starter-typescript --private --clone cd my-worker make init NAME=my_worker # rename the catalog, package and binary make check # everything CI runs
Or click Use this template on GitHub. See starter templates for details. The rest of this README covers the SDK itself.
npm install @query-farm/vgi
# or: bun add @query-farm/vgiRequires Node.js ≥ 22.15 or Bun.
This branch uses vgi.v3 / 3.3.0 and requires a matching VGI
extension. Existing vgi.v2 extensions need SDK 0.46.x; upgrade the engine-side
extension and workers together. This release prepares the shared protocol for
DuckDB 2.0; it does not require upgrading DuckDB itself. See
the migration notes.
Peer dependencies (since 0.3.0).
@query-farm/apache-arrow(^21.1.1) and@query-farm/vgi-rpc(^0.29.2) are peerDependencies — install them directly alongside@query-farm/vgi:npm install @query-farm/vgi @query-farm/apache-arrow @query-farm/vgi-rpcThe SDK bundles both as external, so a single shared instance avoids duplicate-type errors — notably the
vgi-rpcProtocolclash you hit when you also importcreateHttpHandler(or anyvgi-rpctype) directly and two copies get installed. SeeMIGRATION.md.
Using VGI from DuckDB also requires the vgi DuckDB extension. The easiest way to
get it is via Haybarn — Query Farm's distribution of
DuckDB — which publishes the extension (and a DuckDB-Wasm engine) as prebuilt npm
packages, so there's no C++ toolchain or manual INSTALL/compile step:
# The vgi extension as prebuilt binaries, from npm: npm install @haybarn/ext-vgi-h1-5-3 # built for Haybarn / DuckDB 1.5.3 # Haybarn's DuckDB-Wasm engine, for running VGI in the browser / Cloudflare Workers: npm install @haybarn/haybarn-wasm
The @haybarn/ext-* packages are meta-packages: npm pulls only the prebuilt binary
matching your platform (native leaves for linux/darwin/win, plus
wasm-mvp/wasm-eh/wasm-threads variants for DuckDB-Wasm). The Wasm engine is what
lets VGI run in the browser and on Cloudflare Workers — see
Runtimes & entry points.
Types are plain aliases (str, int, float, bool, bytes, …) and the input
arrives as a columnar Arrow batch:
// worker.ts import { Worker, defineScalarFunction, str, int } from "@query-farm/vgi"; const upperCase = defineScalarFunction({ name: "upper_case", // SQL name → demo.upper_case(...) description: "Convert a string to uppercase", // Declares the argument types *and order*. DuckDB calls scalar functions // positionally, so the keys are just parameter names (for docs/metadata) — // inside compute you read the input columns by position, not by this name. // Type aliases: str, int, int32, float, float32, bool, bytes — or any Arrow // DataType (e.g. `new Decimal(18, 2)`). params: { value: str }, // Static output type. For a type that depends on the input, omit `returns` // and use `outputType: (bind) => <DataType>` (may be async). returns: str, // compute runs once per input batch. Read each argument as a column by // position (column 0 = first arg); return one output value per row (null ok). // Full signature: compute(batch, consts, info) where // consts → values of any `constParams` (literals folded at bind time) // info → { settings, secrets, auth, bindCall } — session settings, // secrets, caller, and the bind request (its attach_opaque_data // carries the catalog's attach-time state, already unsealed) // compute may be async: return a Promise to call a service per batch. compute: (batch) => { const values = batch.getChildAt(0)!; // first positional argument return Array.from(values, (v) => v == null ? null : String(v).toUpperCase(), ); }, // Other optional fields: constParams, nullHandling, stability (volatility), // argumentMonotonicity, // examples, categories, tags, requiredSettings, requiredSecrets, maxWorkers. }); // A two-argument scalar — the args are positional, so column 0 is the first // argument and column 1 is the second (the param keys are just names). const multiply = defineScalarFunction({ name: "multiply", description: "Multiply two numbers", params: { a: int, b: int }, // two positional arguments returns: int, // int = Int64 → values are bigint compute: (batch) => { const a = batch.getChildAt(0)!; // first argument const b = batch.getChildAt(1)!; // second argument return Array.from({ length: batch.numRows }, (_, i) => { const x = a.get(i); const y = b.get(i); return x == null || y == null ? null : x * y; // NULL in → NULL out }); }, }); // Functions are served through a catalog — that's what DuckDB ATTACHes to. // `name` is the catalog DuckDB sees (matches the ATTACH target below). new Worker({ catalog: { name: "demo", schemas: [{ name: "main", functions: [upperCase, multiply] }] }, }).run();
A worker speaks Arrow IPC over stdin/stdout (or AF_UNIX / HTTP — see Transports). It is not interactive; DuckDB drives it.
Table functions are incremental producers: build a schema with toSchema, keep your
own state, and emit batches until you finish. DuckDB pulls lazily, so this
streams without materializing everything up front:
import { Worker, defineTableFunction, batchFromColumns, toSchema, int } from "@query-farm/vgi"; const schema = toSchema({ n: int }); // output columns → n BIGINT const sequence = defineTableFunction({ name: "sequence", description: "Emit integers 0..n-1, streamed in batches of 1000", // Positional args by name. Also available: argDefaults, varargs, argDocs. args: { n: int }, // onBind runs once at plan time → declare the output schema. May be async, // and may also return opaqueData / secret + scope lookups for the call. onBind: () => ({ outputSchema: schema }), // Per-execution mutable state, built from the bound args. initialState: ({ args }) => ({ i: 0, n: Number(args.n) }), // process is the pull loop. DuckDB calls it repeatedly and consumes lazily: // emit zero or more batches per call, then finish() to signal end-of-stream. // You never have to materialize the whole result. May be async. process: (_params, state, out) => { if (state.i >= state.n) return out.finish(); // end-of-stream const end = Math.min(state.i + 1000, state.n); const ns: bigint[] = []; for (let k = state.i; k < end; k++) ns.push(BigInt(k)); out.emit(batchFromColumns({ n: ns }, schema)); // hand a batch to DuckDB state.i = end; }, // Optional optimizer/runtime hooks — all omittable: // cardinality: (bind) => ({ estimate, max }) row-count hints // statistics: (bind) => ColumnStatistics[] min/max → filter folding // projectionPushdown / filterPushdown / autoApplyFilters // dynamicToString: (...) => Record<string,string> EXPLAIN ANALYZE counters // onInit + shared storage for partitioned producers / work queues // partitionKind, preservesOrder, lateMaterialization, samplingPushdown, … }); // Serve every function from the same catalog. new Worker({ catalog: { name: "demo", schemas: [{ name: "main", functions: [upperCase, multiply, sequence] }] }, }).run();
The LOCATION is a shell command DuckDB runs to spawn the worker. For Bun:
LOAD vgi; ATTACH 'demo' AS demo (TYPE vgi, LOCATION 'bun run /abs/path/to/worker.ts'); SELECT demo.upper_case('hello'); -- HELLO SELECT demo.multiply(6, 7); -- 42 SELECT * FROM demo.sequence(5); -- 0,1,2,3,4
A function gets only the secrets it asks for. Declare them in requiredSecrets:
a bare type string means "a secret of this type", and an object adds a scope or a name.
requiredSecrets: [ "brave", // a brave secret (unscoped) { secretType: "s3", scope: "s3://my-bucket/" }, // the s3 secret for this prefix { secretType: "http", secretName: "corp_api" }, // one secret, by its DuckDB name ],
An entry in any other shape throws when the function is defined, so a typo can't
quietly declare nothing. Resolved secrets arrive on params.secrets, keyed by each
secret's DuckDB name, not its type. An unnamed CREATE SECRET (TYPE brave, ...)
arrives as __default_brave, so params.secrets.brave is usually undefined. Use the
selectors instead:
| Selector | Picks |
|---|---|
secretOfType(secrets, type) |
the unscoped secret of type, else the first one of type |
requireSecretOfType(secrets, type) |
the same, but throws an error naming the type when there is none (call it in onBind) |
secretsOfType(secrets, type) |
every secret of type |
secretByName(secrets, name, type?) |
the secret named name, if its type matches |
secretForScopeOfType(secrets, path, type) |
the secret of type whose scope is the longest prefix of path, else an unscoped one, else none |
Five factories, each mapping to a DuckDB function shape with its own lifecycle:
defineScalarFunction — row-in / row-out (SELECT f(x)). DuckDB hands you a
columnar batch; you return one output value per input row. For transforms,
parsing, formatting, crypto, encoding, per-row lookups.defineTableFunction — a set-returning producer (SELECT * FROM f(...)). You
keep your own state and emit batches until finish, and DuckDB pulls lazily.
The richest type: projection / filter / sampling pushdown, cardinality and
per-column statistics for the optimizer, Hive-style partitioning, late
materialization, and EXPLAIN ANALYZE counters.defineAggregate — aggregate / window function (f(x) … GROUP BY). Implement
initialState / update / combine / finalize; combine lets DuckDB
aggregate partitions in parallel and merge the results.defineTableInOutFunction — table-in / table-out
(SELECT * FROM f(TABLE t, …)). Per-partition state, a streaming process per
input batch, and a finalize that sees every worker's state — for windowing,
reshaping, enrichment, sessionization. defineRowTransformFunction is its
blended form, whose positional args are per-row input columns
(FROM t, f(t.x)); inputRowsPerCall caps the input rows one call receives.
Either can answer one input with several replies (an upstream API read a page
at a time): emit each reply but the last with moreOutputMetadata(true), and
implement resume(params, state, out), which the framework calls for each
next reply. It continues from initialState's state alone, which over HTTP
rides the stream's state token, so keep positions there, not rows.defineTableBufferingFunction — table-in / table-out that must observe all
input before producing output (global sort, top-N, pivot). Sink (process) →
combine → source (finalize), with explicit sink/source ordering controls.| Capability | Scalar | Table | Aggregate | Table-in-out | Buffering |
|---|---|---|---|---|---|
| Columnar input rows | ✓ | — | ✓ | ✓ | ✓ |
Streaming output (emit / finish) |
— | ✓ | — | ✓ | ✓ |
| Per-group / per-partition state | — | — | ✓ | ✓ | ✓ |
Parallel merge (combine) |
— | — | ✓ | — | ✓ |
| Bind-time dynamic output type | ✓ | ✓ | ✓ | ✓ | ✓ |
| Named args · defaults · varargs | ✓¹ | ✓ | ✓ | ✓ | ✓ |
| Constant (bind-folded) params | ✓ | ✓² | ✓ | ✓² | ✓² |
| Cardinality hints | — | ✓ | — | — | ✓ |
| Column statistics (optimizer) | — | ✓ | — | — | — |
| Projection pushdown | — | ✓ | — | ✓ | ✓ |
| Filter pushdown (+ auto-apply) | — | ✓ | — | ✓ | ✓ |
| Sampling pushdown | — | ✓ | — | — | — |
| Late materialization | — | ✓ | — | — | — |
| Hive-style partitioning | — | ✓ | — | — | — |
| Batch-index threading | — | ✓ | — | — | ✓ |
| Order preservation / dependence | — | ✓ | — | — | ✓³ |
| EXPLAIN ANALYZE diagnostics | — | ✓ | — | — | — |
| Shared storage (work queues, cross-worker state) | — | ✓ | — | ✓ | ✓ |
| Settings & secrets access | ✓ | ✓ | — | ✓ | ✓ |
| Volatility / stability hint | ✓ | ✓ | — | ✓ | ✓ |
| NULL-handling control | ✓ | ✓ | ✓ | ✓ | ✓ |
| Async lifecycle | bind⁴ | ✓ | bind⁴ | ✓ | ✓ |
¹ via the ordered parameters form. ² supplied as bind-time args.
³ via sinkOrderDependent / sourceOrderDependent. ⁴ onBind / outputType
may be async; compute / update / finalize run synchronously.
Workers can also expose a catalog (schemas, tables, views, macros, secrets) via
ReadOnlyCatalogInterface / CompositeCatalogInterface, so an ATTACHed worker
presents browsable database objects, not just functions.
Every value DuckDB exchanges with a worker has an Arrow type, and each Arrow type maps to exactly one JS value shape. A single codec layer is the only authority for that mapping: it converts between the JS value you read/write and an internal canonical pivot (the raw Arrow wire unit), identically across both Arrow backends.
There are two author-facing representations, selected per scalar function with
repr:
rich (the default) — the ergonomic shape. Identical to the canonical wire
unit for every type except date32 / date64, which surface as a JS Date.
Sub-second temporal types (time, timestamp, duration) stay numeric/bigint,
because Date cannot hold microsecond/nanosecond precision losslessly.raw (opt-in) — the canonical wire unit with a branded TypeScript type that
carries the unit (e.g. TimestampMicros, Date32, UnscaledDecimal). At runtime a
branded value is the underlying number/bigint; the brand exists only at compile
time so a wrong-unit mix-up is a type error.| Arrow type | rich JS value |
raw branded type |
|---|---|---|
bool |
boolean |
boolean |
int8 / int16 / int32 |
number |
number |
uint8 / uint16 / uint32 |
number |
number |
int64 |
bigint |
Int64 |
uint64 |
bigint |
Uint64 (exported as Uint64Raw) |
float16 / float32 / float64 |
number |
number |
utf8 / largeUtf8 |
string |
string |
binary / largeBinary / fixedSizeBinary |
Uint8Array |
Uint8Array |
date32 |
Date |
Date32 (days since epoch, number) |
date64 |
Date |
Date64Ms (ms since epoch, bigint) |
time32[s] / time32[ms] |
number (raw unit) |
Time32S / Time32Ms |
time64[us] / time64[ns] |
bigint (raw unit) |
Time64Us / Time64Ns |
timestamp[s/ms/us/ns] |
bigint (raw unit) |
TimestampSeconds / TimestampMillis / TimestampMicros / TimestampNanos |
duration[s/ms/us/ns] |
bigint (raw unit) |
DurationSeconds / DurationMillis / DurationMicros / DurationNanos |
decimal128 / decimal256 |
bigint (UNSCALED integer) |
UnscaledDecimal |
struct |
{ field: richValue } |
{ field: rawValue } |
list / largeList / fixedSizeList |
Array<richValue | null> |
Array<rawValue | null> |
map |
Array<[richKey, richValue]> |
Array<[rawKey, rawValue]> |
dictionary |
the decoded value's rich |
the decoded value's raw |
date32 / date64 are the only types where rich differs from the canonical
wire unit. Everywhere else, rich is the canonical value and raw is the same
value with a branded type. null / undefined pass through as null in every type.
Notes:
Discriminate Arrow types by typeId / predicates, never constructor.name.
The factories return Arrow type instances, not classes named after the factory.
dateDay() returns an arrow-js Date_ instance with typeId === Type.Date and
unit === DateUnit.DAY — there is no class named DateDay, so a check like
type.constructor.name === "DateDay" will always fail (and is brittle across the
two Arrow backends and minified builds). Use the exported isDate(type) predicate,
or compare type.typeId (to Type.Date / the backend-agnostic TypeId.Date) and
type.unit (to DateUnit.DAY / DateUnit.MILLISECOND) to distinguish day vs.
millisecond dates:
import { dateDay, isDate, DateUnit, TypeId } from "@query-farm/vgi"; const t = dateDay(); isDate(t); // ✓ true — backend-agnostic predicate t.typeId === TypeId.Date; // ✓ true t.unit === DateUnit.DAY; // ✓ true — day-resolution date32 t.constructor.name === "DateDay" // ✗ NEVER — no such class; this is always false
Decimals are unscaled. A decimal128(18, 2) value of 123.45 is the bigint
12345n; apply the scale yourself (Number(v) / 100). The declared
precision/scale travel with the column type, not the value.
Temporal units are lossless bigint. A timestamp[us] round-trips as the
exact microsecond count — no Date narrowing, no precision loss.
Reads and writes are symmetric: a value read from a column rebuilds into the same
column. build(read(x)) round-trips, in either representation —
iterRows(batch) (and scalar inputs) return rich values, and a rich value fed
back through batchFromColumns/a scalar compute return rebuilds the original
column (pass "raw" / repr: 'raw' on both ends for the branded form).
The codec validates and throws on invalid or lossy input: a non-integer where an
integer is required, a bigint that overflows the declared width or the safe-integer
range when narrowing to number, an out-of-range Date, the wrong number of bytes
for a fixedSizeBinary, etc. You get a clear codec[<type>]: … TypeError at build
time rather than silently corrupt data on the wire.
Declare params and returns (or args) with the typed factories and compute is
statically typed end to end — the input columns and the return value are checked
against the declared Arrow types and the chosen representation:
import { Worker, defineScalarFunction, timestampMicros, int64 } from "@query-farm/vgi"; // rich (default): timestamp values are plain bigint microsecond counts. const addHour = defineScalarFunction({ name: "add_hour", params: { ts: timestampMicros }, // input column: bigint (us) returns: timestampMicros, // output: bigint (us) compute: (batch) => { const ts = batch.getChildAt(0)!; return Array.from(ts, (v: bigint | null) => v == null ? null : v + 3_600_000_000n, // +1h in microseconds ); // returning a Date here is a COMPILE error }, });
argumentMonotonicity is optional and scalar-only. If supplied, it must have
one entry per ordered parameter declaration. Fixed, defaulted, and constant
parameters each use one slot; a vararg declaration uses one slot regardless of
call-time expansion. Named invocation order does not reorder the metadata.
import { Worker, defineScalarFunction, timestampMicros, asTimestampMicros, type TimestampMicros, } from "@query-farm/vgi"; // raw mode: outputs are branded units, constructed with `asTimestampMicros`. const epoch = defineScalarFunction({ name: "epoch_us", params: { ts: timestampMicros }, returns: timestampMicros, repr: "raw", // opt in to branded raw units compute: (batch) => { const ts = batch.getChildAt(0)!; return Array.from(ts, (v: TimestampMicros | null) => v == null ? null : asTimestampMicros(v + 1n), // branded in, branded out ); }, });
For manual conversions outside a function, codecFor(type) returns the codec with
richToCanonical / canonicalToRich / rawToCanonical / canonicalToRaw.
Four names — int, int32, float32, bool — mean different things depending on
which entry point you import from:
| Import from | int is |
Write |
|---|---|---|
@query-farm/vgi |
a ready-made Int64 type, re-exported from vgi-rpc |
params: { n: int } |
@query-farm/vgi/worker-cf |
the typed factory int(bitWidth?, signed?) |
params: { n: int() } |
The package root also re-exports float, str and bytes as ready-made types;
the Cloudflare entry does not have them at all (use float64(), utf8(),
binary()).
Everything else in the typed factory set — int8/int16/int64, uint*,
float16/float64, utf8, decimal*, dateDay, timestampMicros, struct,
list, map, … — is a factory on both entry points and is exported from the
package root as usual.
Prefer the explicit factories in portable code. int64() means the same thing
everywhere; int does not, so moving a worker to Cloudflare Workers can turn a
correct declaration into a wrong one with no other edit. Since 0.29.0 that mistake
is caught at definition time rather than silently registering a Function as an
argument type:
defineScalarFunction("double"): params.n is a type factory, not an Arrow type — call it: int64().
This is a pre-1.0 breaking change to how columnar values are represented in and out of functions. The contract is now uniform across both Arrow backends and both directions (read and write). For consumers upgrading:
date32 / date64 columns are now JS Date in and out by default.
Previously dates were inconsistent — a day-number went in but a Date came back
out. Both directions are now Date under the default rich representation.iterRows, scalar inputs, and setting/secret reads
all surface the rich value for their type.bigint raw units. time64, timestamp,
and duration are the exact bigint count in their declared unit (us, ns, …) — no
Date, no precision loss.bigint. A decimal(18,2) of 123.45 is 12345n.repr: 'raw' for branded, unit-tagged raw units everywhere (including
date32/date64 as plain day-number / ms-bigint rather than Date).Before / after for the common date case:
// BEFORE (old, inconsistent): wrote a day-number, read back a Date. returns: dateDay, compute: () => [20000], // 20000 days since epoch // AFTER (rich, default): write a Date, read a Date — symmetric. returns: dateDay, compute: () => [new Date("2024-10-19")], // AFTER (raw): opt in to the branded day-number. returns: dateDay, repr: "raw", compute: () => [asDate32(20000)], // branded number, not a Date
A worker serves the same functions over any of:
--unix <path>), reused across calls.--tcp [HOST:]PORT) and caller-provided byte streams (worker.serveStream).Transport handling lives in @query-farm/vgi-rpc.
Don't hand-roll the HTTP wiring. @query-farm/vgi/serve assembles the protocol, the
signed state-token key, CORS, and the standardized landing surface, then binds the port:
// scripts/serve.ts import { serveVgiWorker } from "@query-farm/vgi/serve"; import { makeWorkerParts } from "../src/parts.js"; const { registry, catalogInterface } = makeWorkerParts(); serveVgiWorker({ name: "ishares", doc: "iShares (BlackRock) US fund data.", version: "0.1.0", repositoryUrl: "https://github.com/Query-farm/vgi-etf-ishares", registry, catalogInterface, });
$ PORT=8787 bun run scripts/serve.tsMounted at the origin root, so DuckDB attaches the bare URL:
ATTACH 'ishares' AS ishares (TYPE vgi, LOCATION 'http://localhost:8787');
It also serves GET / (landing page), GET /describe.json (catalog contract), and
GET /health.
| Variable | Default | Meaning |
|---|---|---|
PORT |
8787 |
Listen port. 0 binds an ephemeral port. |
VGI_SIGNING_KEY |
random | State-token HMAC key, 64 hex chars (openssl rand -hex 32). |
VGI_TOKEN_TTL |
3600 |
State-token lifetime in seconds. |
CORS_ORIGINS |
* |
Allowed origins. Pass corsOrigins: null to disable CORS. |
Every variable has an explicit option that takes precedence over it.
With no VGI_SIGNING_KEY, a random key is generated and a warning is printed: state
tokens then stop validating after a restart, and never validate across two instances
behind a load balancer. Set it for any real deployment. A key that isn't exactly 64 hex
characters is rejected rather than silently truncated.
To mount the VGI routes inside a server you already own, use createVgiWorkerFetch,
which returns the fetch handler without binding a port. On Cloudflare Workers use
createVgiFetch from @query-farm/vgi/worker-cf; both share one implementation.
createVgiFetch requires landingInfo: { name, doc, version } — the identity the
landing page and its JSON status document display. serveVgiWorker builds it from
its own required name/doc/version, so only the Cloudflare entry passes it
explicitly. Without it there is no landing page and no /vgi-client.js; see
MIGRATION.md.
A worker can serve other vgi-rpc
protocols beside vgi.v3, on the same listener, through the hostedProtocols hook:
import { Protocol, str } from "@query-farm/vgi-rpc"; const reports = new Protocol("acme.Reports.v1").unary("render", { params: { id: str }, result: { result: str }, handler: ({ id }) => ({ result: `report ${id}` }), }); new Worker({ functions, hostedProtocols: () => [reports] }).run(); // …or serveVgiWorker({ …, hostedProtocols: () => [reports] }), // …or createVgiFetch({ …, hostedProtocols: () => [reports] }) on Cloudflare Workers.
serveStream, HTTP), after vgi.v3, in the order returned. Every
transport builds its server through one function, buildRpcServer.vgi.v3 or start with the reserved
vgi_rpc.. Violations are a startup error naming hostedProtocols().vgi_rpc.protocol key, so hosting more protocols never
changes how DuckDB's vgi.v3 calls are dispatched.vgi_rpc.Identity.v2)A worker opts into vgi_rpc.Identity.v2 by supplying resolveToken and/or
mintGrant (accepted by Worker, serveVgiWorker, createVgiWorkerFetch and
createVgiFetch). It is hosted on HTTP only — the transport that authenticates
callers — and only the methods whose hooks exist are hosted; with neither, the
protocol is absent.
import { AuthUnavailableError } from "@query-farm/vgi"; serveVgiWorker({ // … resolveToken: async (token) => { let row; try { row = await apiKeys.lookup(token); } catch (err) { // "I could not find out" -- an outage, not a refusal. throw new AuthUnavailableError("key store unreachable", 5); } return row ? { principal: row.principal, tokenName: row.label } : null; // null = unknown }, introspectPrincipals: ["edge-proxy"], // or VGI_INTROSPECT_PRINCIPALS=edge-proxy });
Enabling introspection without an allowlist refuses to start. Authenticating
and introspecting are different capabilities; "any authenticated caller" would let
any user resolve any other user's credential to its owner. Set
introspectPrincipals or VGI_INTROSPECT_PRINCIPALS (comma-separated). mintGrant
alone needs no allowlist.
Transient failures: throw AuthUnavailableError (re-exported here from
@query-farm/vgi-rpc) from resolveToken or mintGrant when the answer is not
knowable — a store or sidecar outage, a timeout, a 5xx. The framework translates it
to identity_unavailable (code UNAVAILABLE) carrying that error's retry hint as
vgi_rpc.RetryInfo, so a caller retries instead of caching a refusal.
IdentityUnavailableError works too. Never throw a plain Error for an outage, and
never return null for one: both read as a definitive answer. Return null only
when the store answered and the credential is unknown; throw GrantRefusedError to
decline a grant.
issue_grant mints a credential meant for unattended automation to present later
as an ordinary bearer. Configure grant keys and the worker both mints and
accepts them, with no storage and no code:
$ VGI_RPC_GRANT_KEYS="$(openssl rand -base64 32)" bun run scripts/serve.ts # or: bun run scripts/serve.ts --grant-key "$(openssl rand -base64 32)"
VGI_RPC_GRANT_KEYS: comma-separated standard base64, exactly 32 bytes each. The
first mints; every key verifies. Rotate by adding the new key first and removing
the old one once its grants have expired. --grant-key KEY (repeatable) on
serveVgiWorker, or the grantKeys option (GrantKeys.parse([...]), required on
Cloudflare Workers, where there is no process environment) work too.VGI_RPC_GRANT_AUDIENCE (bind grants to this deployment) and
VGI_RPC_GRANT_MAX_TTL_SECONDS (default 7 days).issue_grant (minted by the framework unless you supply
mintGrant) and the worker's HTTP authentication accepts vgig1. grants after
your own authenticate, as the grant's owner (domain grant). A caller
authenticated by a grant has no auth_time, so it cannot mint another grant.resolveToken also has bearers your authenticate did not
accept resolved through it (domain token); an AuthUnavailableError from the hook
is a 503 with Retry-After, never a 401.authenticate must throw (not return anonymous) for a bearer it does not
recognise, or the chain ends before grants are tried.A catalog declares its ATTACH options (attachOptions on the descriptor, or
attachOptionSpecs()); a credential is declared secret: true. Every function call
and transaction hook of an attach reads the options with attachOptions(), secret
values included. The framework carries them for you, so you never pack options (and
never a credential) into your own attach_opaque_data:
import { attachOptions, ReadOnlyCatalogInterface, type CatalogAttachResult } from "@query-farm/vgi"; // In any function (bind, or init/process via params.initCall.bind_call): const { api_key, region } = attachOptions(params.bindCall.attach_opaque_data); // In a catalog method or transaction hook: class MyCatalog extends ReadOnlyCatalogInterface { override async attach(name: string, options?: Record<string, unknown>): Promise<CatalogAttachResult> { const result = await super.attach(name, options); return { ...result, supports_transactions: options?.transactional === true }; // no options in the bytes } override async transactionCommit(attach: Uint8Array, tx: Uint8Array) { const { api_key } = this.attachOptions(attach); // ... } }
How it works: catalog_attach appends the options to the catalog's attach bytes and
encrypts the secret ones (XChaCha20-Poly1305, a fresh random nonce each time) under
HKDF-SHA256(root, info "vgi.attach_secret_options.v1"), with the attach's
framework UUID as associated data — a blob copied into another attach value does not
open (attach_opaque_data not recognized). The framework strips all of it before
your code sees the attach bytes. A secret value is never in plaintext in any opaque
value, on any transport (the sealing spec's rule 5).
The root key is, in order:
attachSecretKey (Worker, serveVgiWorker, or protocol on createVgiFetch),VGI_SIGNING_KEY, or the one the worker minted at startup),$VGI_ATTACH_SECRET_KEY_FILE, else $XDG_RUNTIME_DIR/vgi/attach-secret-options.key,
else <tmpdir>/vgi-<user>/attach-secret-options.key — 32 random bytes, created
atomically on first use with mode 0600 in a 0700 directory, refused if anyone else
can read it. It is read only when a secret option actually has a value.Every process that may receive a given attach must have the same root key (a
multi-instance HTTP deployment sets VGI_SIGNING_KEY). A runtime with no filesystem
(browser, Workers) and no signing key cannot accept a secret option: the ATTACH fails
and says so. Secret values, the key and the blob are never logged.
vgi.attach_tickets.v1)A grant says who attaches; an attach ticket says what. While a user is attached and logged in, the client asks the worker to seal the options it attached with, secret ones included, into a ticket only this worker can open. A runner holding that user's grant later reattaches with one option and never sees the others:
-- as the runner, authenticated by `Authorization: Bearer <grant>` ATTACH 'ticket_probe' AS p (TYPE vgi, LOCATION 'https://worker.example.com', vgi_attach_ticket 'vgia1.…');
seal_attach(request: SealAttachRequest) -> AttachTicket is hosted on
HTTP only, and only when both halves of an unattended session can be issued:
VGI_SIGNING_KEY (or the signingKey option) is configured explicitly — the
generated fallback key never counts, since every ticket would die on restart — and
the worker can issue grants (grant keys configured, or its own mintGrant).
Otherwise the protocol is absent, so a client learns this from reflection.
createVgiFetch (Cloudflare Workers) requires its key and so counts it as
configured; pass signingKeyConfigured: false for a key you generate per isolate.action_denied); no
fresh login is needed. Options are checked against the catalog's declared attach
options (invalid_request with one BadRequest violation per field). The lifetime
is capped at the grant maximum (VGI_RPC_GRANT_MAX_TTL_SECONDS, default 7 days with
grant keys); ttl_seconds: 0 asks for the maximum.
The reply's expires_at is a nullable timestamp[us, tz=UTC] (Date | null in
TypeScript), null when the worker sets no maximum lifetime; protocol version
2.0.0 (1.0.0 carried float64 unix seconds with +inf for "no expiry").catalog_attach redeems a vgi_attach_ticket option (any letter
case) before any catalog code runs: it must be the only option (invalid_request),
it opens only under the caller's principal and this worker's key
(attach_ticket_invalid) and only within its lifetime (attach_ticket_expired),
and the attach then proceeds exactly as the user typed it — the sealed catalog name,
options and version specs. A CompositeCatalogInterface routes on the sealed name.
The ticket binds the principal only, not the login domain, so a ticket sealed under
a JWT login opens under that user's grant.vgi_attach_ticket (any case); a worker that does refuses to serve.VGI_SIGNING_KEY invalidates every ticket. A ticket carries no authority:
without a grant or login for the same principal it attaches nothing. Neither the
ticket nor a restored option is ever logged.Normative spec: vgi-python docs/protocol/vgi-attach-tickets.md. The example HTTP
worker serves the cross-SDK ticket_probe fixture catalog and hosts tickets when
started with both VGI_SIGNING_KEY and VGI_RPC_GRANT_KEYS.
The package ships a backend-agnostic Arrow facade and selects an implementation at build time per runtime, so the same source runs on servers, Cloudflare Workers, and browsers:
| Runtime | Arrow backend |
|---|---|
| Node.js / Bun | @query-farm/apache-arrow (arrow-js) |
Cloudflare Workers (workerd) / browser |
@query-farm/flechette |
Subpath exports:
@query-farm/vgi — main API (define functions, Worker, VgiClient, catalogs).@query-farm/vgi/client — client-only entry (no server-side code).@query-farm/vgi/worker-cf — Cloudflare Workers entry (workerd/browser bundle).vgi extension (and others) as prebuilt npm packages
(@haybarn/haybarn-wasm,
@haybarn/ext-vgi-h1-5-3).
The host side: it runs the DuckDB engine that attaches to your worker.@query-farm/vgi-rpc —
the RPC layer: protocol, server, transports, Arrow IPC framing. A runtime
dependency of this package.vgi-python — the reference implementation. This package is a wire-compatible
TypeScript port; workers from either side interoperate.See Iroh operations for native Node/Bun and browser clients, and identity-preserving worker bridge setup.
make install # bun install make build # types + JS bundles make test # integration tests (launcher transport) make -j8 test-all # launcher + HTTP suites in parallel
See CLAUDE.md for the full build/test reference.
Copyright © 2025, 2026 Query Farm LLC — https://query.farm
Distributed under the Query Farm Source-Available License, Version 1.0. Use,
modification, redistribution, and non-production use are permitted; some production
uses (notably competing offerings and commercial marketplaces) require a separate
commercial license. Each version converts to Apache-2.0 ten years after its release.
See LICENSE for the full terms, or contact hello@query.farm for
commercial licensing.
Query-farm/vgi-typescript is a public repo on GitHub by Query-farm. TypeScript SDK for the VGI (Vector Gateway Interface) protocol — host DuckDB scalar, table, aggregate, and table-in-out functions in an external worker over Arrow IPC.
It declares no license on GitHub. Public does not mean open source: without a license, nobody is granted the right to reuse it.
Its maker tagged it for macOS, Windows and Linux, or as Docker or cross-platform. That is declared by the maker; Take My Repo has not tested it.
Open "Take it" on its page: Take My Repo writes an install plan for your machine and hands it to your AI agent (Claude Code, Codex or Cursor), which asks you before each step. Take My Repo has not tested it on any machine.
Perform fast and efficient data analysis with the power of SQL
Its last change on GitHub was on 2026-11-21. GitHub counts 0 open issues and pull requests. Take My Repo does not judge from that whether it is maintained.
Nobody has reviewed it on Take My Repo yet, which says nothing about its quality.
QuestDB is a high performance, open-source, time-series database

Fast data transport : Apache Arrow, Protobuf and Message Pack data on the one stream. Measured faster than Arrow Flight on all open benchmarks. HTTP, TCP, QUIC, Websocket, Webtransport, Stdio, UDS, all interchangeable, with 64-byte SIMD compatibilty maintained over the network and to/from disk via custom Arrow Mmap and Parquet Readers and Writers
The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
Stop renting your intelligence. Own it with AnythingLLM. Everything you need for a powerful local-first agent experience
DuckDB extension for querying, modifying, and storing data through Apache Arrow Flight servers.
DuckDB extension for serving SQL queries over HTTP and returning JSON results.
DuckDB extension for reading from and writing to Unix shell pipelines through file operations.
Experimental DuckDB extension for making HTTP GET and POST requests directly from SQL.
DuckDB extension for encoding and decoding multidimensional values with Hilbert and Morton (Z-order) space-filling curves.
Experimental DuckDB extension for prompting LLMs from SQL through OpenAI-compatible APIs, including Ollama.
This page is also available as structured data, with the same sources and dates.
/api/v1/resources/gh/Query-farm/vgi-typescriptTake My Repo has not tested this on your machine. Requirements come from the project's own documentation.