@query-farm/vgi 0.24.2 → 0.25.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.
@@ -3,8 +3,7 @@ export type { VgiFetchOptions } from "./http/fetch.js";
3
3
  export { defineScalarFunction, defineTableFunction, defineAggregate, defineTableInOutFunction, FunctionRegistry, ReadOnlyCatalogInterface, CompositeCatalogInterface, CatalogInterface, Arguments, FunctionType, serializeAttachOptionSpec, serializeAttachOptionSpecs, serializeColumnStatistics, BindResultSchema, ScanFunctionResultSchema, } from "./index.core.js";
4
4
  export type { AttachOptionSpec, ColumnStatistics, CatalogAttachResult, CatalogDescriptor, CatalogInfo, TableInfo, AttachOpaqueData, TransactionOpaqueData, SchemaInfo, VgiFunction, TableProcessParams, } from "./index.core.js";
5
5
  export type { ProtocolConfig } from "./protocol/dispatch.js";
6
- export { createLandingDescribe } from "./http/describe-json.js";
7
- export type { LandingDescribeProvider, WorkerDescribeInfo } from "./http/describe-json.js";
6
+ export type { LandingInfo } from "@query-farm/vgi-rpc";
8
7
  export { TypeId, isNull, isInt, isFloat, isBinary, isUtf8, isBool, isDecimal, isDate, isTime, isTimestamp, isInterval, isList, isStruct, isUnion, isFixedSizeBinary, isFixedSizeList, isMap, isDuration, isDictionary, isBatch, backend, schema, field, nullType, bool, int, int8, int16, int32, int64, uint8, uint16, uint32, uint64, float16, float32, float64, utf8, binary, fixedSizeBinary, decimal, decimal128, decimal256, date, dateDay, dateMillisecond, time, timeSecond, timeMillisecond, timeMicrosecond, timeNanosecond, timestamp, duration, interval, list, fixedSizeList, struct, map, dictionary, union, sparseUnion, denseUnion, TimeUnit, DateUnit, IntervalUnit, UnionMode, emptyBatch, batchFromRows, batchFromColumns, columnFromArray, iterRows, batchToScalarDict, batchToSecretDict, safeNumber, decodeDictValue, filterBatch, projectSchema, projectBatch, serializeSchema, deserializeSchema, serializeBatch, deserializeBatch, buildStatisticsBatch, } from "./arrow/index.js";
9
8
  export type { VgiTypeId, VgiDataType, VgiField, VgiSchema, VgiColumn, VgiColumnData, VgiBatch, VgiBackendInfo, } from "./arrow/index.js";
10
9
  export { arrowStateSerializer, EXCHANGE_STATE_SCHEMA } from "./protocol/state-serializer.js";
@@ -7296,7 +7296,7 @@ function createVgiFetch(opts) {
7296
7296
  stateSerializer: arrowStateSerializer,
7297
7297
  corsOrigins: opts.corsOrigins,
7298
7298
  repositoryUrl: opts.repositoryUrl,
7299
- landingDescribe: opts.landingDescribe
7299
+ landingInfo: opts.landingInfo
7300
7300
  });
7301
7301
  return async (req) => handler(req);
7302
7302
  }
@@ -8148,7 +8148,6 @@ function serializeAttachOptionSpec(spec) {
8148
8148
  function serializeAttachOptionSpecs(specs) {
8149
8149
  return Array.from(specs, serializeAttachOptionSpec);
8150
8150
  }
8151
-
8152
8151
  class MissingAttachOptionsError extends Error {
8153
8152
  missing;
8154
8153
  constructor(catalogName, missing) {
@@ -9218,416 +9217,6 @@ class FunctionRegistry {
9218
9217
  return result;
9219
9218
  }
9220
9219
  }
9221
- // src/http/describe-json.ts
9222
- init_arrow();
9223
- var LANDING_SCHEMA_VERSION2 = 1;
9224
- var CUPOLA_BASE2 = "https://cupola.query-farm.services";
9225
- var STRING_TAGS = {
9226
- title: "vgi.title",
9227
- doc_md: "vgi.doc_md",
9228
- source_url: "vgi.source_url",
9229
- license: "vgi.license",
9230
- author: "vgi.author",
9231
- copyright: "vgi.copyright",
9232
- support_contact: "vgi.support_contact",
9233
- support_policy_url: "vgi.support_policy_url"
9234
- };
9235
- var KEYWORDS_TAG = "vgi.keywords";
9236
- function typeToString(type) {
9237
- if (isNull(type))
9238
- return "NULL";
9239
- if (isUtf8(type))
9240
- return "VARCHAR";
9241
- if (isBinary(type))
9242
- return "BLOB";
9243
- if (isBool(type))
9244
- return "BOOLEAN";
9245
- if (isInt(type)) {
9246
- const bw = type.bitWidth ?? 32;
9247
- return bw === 64 ? "BIGINT" : "INTEGER";
9248
- }
9249
- if (isFloat(type)) {
9250
- const precision = type.precision ?? 2;
9251
- return precision === 1 ? "FLOAT" : "DOUBLE";
9252
- }
9253
- const s = type.toString?.();
9254
- return s ?? String(type.typeId);
9255
- }
9256
- function arrowTypeString(type) {
9257
- if (isNull(type))
9258
- return "null";
9259
- if (isBool(type))
9260
- return "bool";
9261
- if (isUtf8(type))
9262
- return "string";
9263
- if (isBinary(type))
9264
- return "binary";
9265
- if (isInt(type)) {
9266
- const bw = type.bitWidth ?? 32;
9267
- const signed = type.isSigned ?? type.signed ?? true;
9268
- return `${signed ? "" : "u"}int${bw}`;
9269
- }
9270
- if (isFloat(type)) {
9271
- const precision = type.precision ?? 2;
9272
- return precision === 0 ? "halffloat" : precision === 1 ? "float" : "double";
9273
- }
9274
- const s = type.toString?.();
9275
- return (s ?? String(type.typeId)).toLowerCase();
9276
- }
9277
- function fieldMeta(field4, key) {
9278
- return field4.metadata.get(key);
9279
- }
9280
- function fieldToColumn(field4) {
9281
- const col = { name: field4.name, type: typeToString(field4.type) };
9282
- const comment = fieldMeta(field4, "comment") ?? fieldMeta(field4, VGI_DOC_KEY);
9283
- if (comment)
9284
- col.comment = comment;
9285
- return col;
9286
- }
9287
- function readSchemaSafe(bytes2) {
9288
- if (!bytes2 || bytes2.length === 0)
9289
- return null;
9290
- try {
9291
- return deserializeSchema(bytes2);
9292
- } catch {
9293
- return null;
9294
- }
9295
- }
9296
- function functionDisplayType(fn) {
9297
- const t = String(fn.function_type).toUpperCase();
9298
- if (t === "SCALAR")
9299
- return "scalar";
9300
- if (t === "AGGREGATE")
9301
- return "aggregate";
9302
- if (fn.has_finalize)
9303
- return "table_in_out";
9304
- return "table";
9305
- }
9306
- function functionReturns(fn) {
9307
- const schema4 = readSchemaSafe(fn.output_schema);
9308
- if (schema4 === null || schema4.fields.length === 0)
9309
- return;
9310
- const t = String(fn.function_type).toUpperCase();
9311
- if (t === "SCALAR" || t === "AGGREGATE") {
9312
- return typeToString(schema4.fields[0].type);
9313
- }
9314
- const cols = schema4.fields.map((f) => `${f.name} ${typeToString(f.type)}`).join(", ");
9315
- return `TABLE(${cols})`;
9316
- }
9317
- function functionArgs(fn) {
9318
- const schema4 = readSchemaSafe(fn.arguments);
9319
- if (schema4 === null)
9320
- return [];
9321
- const args = [];
9322
- for (const field4 of schema4.fields) {
9323
- if (fieldMeta(field4, VGI_TYPE_KEY) === VGI_TYPE_TABLE)
9324
- continue;
9325
- const arg = { name: field4.name, type: typeToString(field4.type) };
9326
- if (fieldMeta(field4, VGI_ARG_KEY) === VGI_ARG_NAMED)
9327
- arg.named = true;
9328
- const doc = fieldMeta(field4, VGI_DOC_KEY);
9329
- if (doc)
9330
- arg.desc = doc;
9331
- const rawDefault = fieldMeta(field4, VGI_DEFAULT_KEY);
9332
- if (rawDefault !== undefined) {
9333
- try {
9334
- arg.default = JSON.stringify(JSON.parse(rawDefault));
9335
- } catch {
9336
- arg.default = rawDefault;
9337
- }
9338
- }
9339
- args.push(arg);
9340
- }
9341
- return args;
9342
- }
9343
- function macroDisplayType(m) {
9344
- return String(m.macro_type).toUpperCase() === "SCALAR" ? "scalar" : "table";
9345
- }
9346
- function macroDefaultJson(value) {
9347
- if (typeof value === "bigint")
9348
- return value.toString();
9349
- try {
9350
- return JSON.stringify(value);
9351
- } catch {
9352
- return String(value);
9353
- }
9354
- }
9355
- function macroArgs(m) {
9356
- const defaults = new Map;
9357
- const defBytes = m.parameter_default_values;
9358
- if (defBytes && defBytes.length > 0) {
9359
- try {
9360
- const batch = deserializeBatch(defBytes);
9361
- for (const field4 of batch.schema.fields) {
9362
- try {
9363
- defaults.set(field4.name, batch.getChild(field4.name)?.get(0));
9364
- } catch {}
9365
- }
9366
- } catch {}
9367
- }
9368
- const schema4 = readSchemaSafe(m.arguments_schema);
9369
- const fields = schema4 ? schema4.fields : null;
9370
- const fieldByName = new Map;
9371
- if (fields)
9372
- for (const f of fields)
9373
- fieldByName.set(f.name, f);
9374
- const names = fields ? fields.map((f) => f.name) : m.parameters;
9375
- const args = [];
9376
- for (const name of names) {
9377
- const field4 = fieldByName.get(name);
9378
- const arg = field4 !== undefined && !isNull(field4.type) ? { name, type: arrowTypeString(field4.type) } : { name, type: "ANY" };
9379
- const doc = field4 !== undefined ? fieldMeta(field4, VGI_DOC_KEY) : undefined;
9380
- if (doc)
9381
- arg.desc = doc;
9382
- if (defaults.has(name)) {
9383
- arg.named = true;
9384
- arg.default = macroDefaultJson(defaults.get(name));
9385
- }
9386
- args.push(arg);
9387
- }
9388
- return args;
9389
- }
9390
- function macroToObject(m) {
9391
- return {
9392
- name: m.name,
9393
- type: macroDisplayType(m),
9394
- doc: m.comment ?? "",
9395
- args: macroArgs(m)
9396
- };
9397
- }
9398
- async function schemaContents(iface, aod, name, kind) {
9399
- try {
9400
- if (kind === "TABLE") {
9401
- return await iface.schemaContentsTables(aod, name);
9402
- }
9403
- return await iface.schemaContentsViews(aod, name);
9404
- } catch {
9405
- return [];
9406
- }
9407
- }
9408
- async function schemaFunctions(iface, aod, name) {
9409
- const out = [];
9410
- for (const kind of ["SCALAR_FUNCTION", "TABLE_FUNCTION", "AGGREGATE_FUNCTION"]) {
9411
- try {
9412
- out.push(...await iface.schemaContentsFunctions(aod, name, kind));
9413
- } catch {}
9414
- }
9415
- return out;
9416
- }
9417
- async function schemaMacros(iface, aod, name) {
9418
- const out = [];
9419
- for (const kind of ["SCALAR_MACRO", "TABLE_MACRO"]) {
9420
- try {
9421
- out.push(...await iface.schemaContentsMacros(aod, name, kind));
9422
- } catch {}
9423
- }
9424
- return out;
9425
- }
9426
- async function buildSchemas(iface, aod) {
9427
- let schemaInfos;
9428
- try {
9429
- schemaInfos = await iface.schemas(aod);
9430
- } catch {
9431
- return { schemas: [], counts: { schemas: 0, tables: 0, views: 0, functions: 0 } };
9432
- }
9433
- const schemas = [];
9434
- const counts = { schemas: 0, tables: 0, views: 0, functions: 0 };
9435
- for (const si of schemaInfos) {
9436
- const tablesRaw = await schemaContents(iface, aod, si.name, "TABLE");
9437
- const viewsRaw = await schemaContents(iface, aod, si.name, "VIEW");
9438
- const funcsRaw = await schemaFunctions(iface, aod, si.name);
9439
- const macrosRaw = await schemaMacros(iface, aod, si.name);
9440
- const tables = tablesRaw.map((t) => {
9441
- const schema4 = readSchemaSafe(t.columns);
9442
- return { name: t.name, cols: schema4 ? schema4.fields.length : 0, comment: t.comment ?? "" };
9443
- });
9444
- const views = viewsRaw.map((v) => ({
9445
- name: v.name,
9446
- cols: Object.keys(v.column_comments ?? {}).length,
9447
- comment: v.comment ?? "",
9448
- def: v.definition
9449
- }));
9450
- const functions = funcsRaw.map((fn) => {
9451
- const obj = {
9452
- name: fn.name,
9453
- type: functionDisplayType(fn),
9454
- doc: fn.description ?? "",
9455
- args: functionArgs(fn)
9456
- };
9457
- const ret = functionReturns(fn);
9458
- if (ret)
9459
- obj.returns = ret;
9460
- return obj;
9461
- });
9462
- functions.push(...macrosRaw.map((m) => macroToObject(m)));
9463
- functions.sort((a, b) => String(a.type).localeCompare(String(b.type)) || String(a.name).localeCompare(String(b.name)));
9464
- const schemaObj = { name: si.name };
9465
- if (si.comment)
9466
- schemaObj.doc = si.comment;
9467
- schemaObj.tables = tables;
9468
- schemaObj.views = views;
9469
- schemaObj.functions = functions;
9470
- schemas.push(schemaObj);
9471
- counts.schemas += 1;
9472
- counts.tables += tables.length;
9473
- counts.views += views.length;
9474
- counts.functions += functions.length;
9475
- }
9476
- return { schemas, counts };
9477
- }
9478
- function catalogTags(result) {
9479
- const tags = result?.tags;
9480
- if (!tags)
9481
- return {};
9482
- const out = {};
9483
- for (const [key, tag] of Object.entries(STRING_TAGS)) {
9484
- const val = tags[tag];
9485
- if (val)
9486
- out[key] = val;
9487
- }
9488
- const kw = tags[KEYWORDS_TAG];
9489
- if (kw) {
9490
- try {
9491
- const parsed = JSON.parse(kw);
9492
- if (Array.isArray(parsed))
9493
- out.keywords = parsed.map((k) => String(k));
9494
- } catch {}
9495
- }
9496
- return out;
9497
- }
9498
- function decodeAttachOption(bytes2) {
9499
- try {
9500
- const batch = deserializeBatch(bytes2);
9501
- if (batch.numRows === 0)
9502
- return null;
9503
- const name = String(batch.getChild("name")?.get(0) ?? "");
9504
- const description = String(batch.getChild("description")?.get(0) ?? "");
9505
- const typeBytes = batch.getChild("type")?.get(0);
9506
- let type = "";
9507
- const typeSchema = readSchemaSafe(typeBytes ?? null);
9508
- if (typeSchema && typeSchema.fields.length > 0)
9509
- type = typeToString(typeSchema.fields[0].type);
9510
- let defaultStr = "";
9511
- const defBytes = batch.getChild("default_value")?.get(0);
9512
- if (defBytes) {
9513
- try {
9514
- const defBatch = deserializeBatch(defBytes);
9515
- if (defBatch.numRows > 0) {
9516
- const v = defBatch.getChild("value")?.get(0);
9517
- defaultStr = v == null ? "" : String(v);
9518
- }
9519
- } catch {}
9520
- }
9521
- return { name, type, default: defaultStr, description };
9522
- } catch {
9523
- return null;
9524
- }
9525
- }
9526
- async function attachCatalog(iface, name) {
9527
- try {
9528
- return await iface.attach(name, {}, null, null);
9529
- } catch {
9530
- return null;
9531
- }
9532
- }
9533
- async function buildCatalog(iface, name, info) {
9534
- const result = await attachCatalog(iface, name);
9535
- const attachOptions = (info?.attach_option_specs ?? []).map((b) => decodeAttachOption(b)).filter((o) => o !== null);
9536
- const dataVersions = (info?.releases ?? []).map((r) => r.summary ? { spec: r.version, label: r.summary } : { spec: r.version });
9537
- let impl = info?.implementation_version ?? null;
9538
- let dvs = info?.data_version_spec ?? null;
9539
- if (result) {
9540
- impl = result.resolved_implementation_version ?? impl;
9541
- dvs = result.resolved_data_version ?? dvs;
9542
- }
9543
- let schemas = [];
9544
- let counts = { schemas: 0, tables: 0, views: 0, functions: 0 };
9545
- if (result) {
9546
- const built = await buildSchemas(iface, result.attach_opaque_data);
9547
- schemas = built.schemas;
9548
- counts = built.counts;
9549
- }
9550
- return {
9551
- name,
9552
- implementation_version: impl,
9553
- data_version_spec: dvs,
9554
- data_versions: dataVersions,
9555
- attach_options: attachOptions,
9556
- tags: catalogTags(result),
9557
- counts,
9558
- schemas
9559
- };
9560
- }
9561
- async function catalogInfoByName(iface) {
9562
- const map4 = new Map;
9563
- if (typeof iface.catalogsInfo === "function") {
9564
- try {
9565
- const infos = await iface.catalogsInfo();
9566
- for (const info of infos)
9567
- map4.set(info.name, info);
9568
- } catch {}
9569
- }
9570
- return map4;
9571
- }
9572
- async function buildDescribeJson2(iface, worker, opts = {}) {
9573
- const infos = await catalogInfoByName(iface);
9574
- let names;
9575
- try {
9576
- names = iface.catalogs();
9577
- } catch {
9578
- names = [];
9579
- }
9580
- const catalogs = [];
9581
- for (const name of names) {
9582
- catalogs.push(await buildCatalog(iface, name, infos.get(name)));
9583
- }
9584
- return {
9585
- landing_schema_version: LANDING_SCHEMA_VERSION2,
9586
- worker: {
9587
- name: worker.name,
9588
- doc: worker.doc ?? "",
9589
- version: worker.version ?? "unknown",
9590
- lang: "typescript"
9591
- },
9592
- server_id: opts.serverId ?? "",
9593
- oauth: opts.oauth ?? false,
9594
- cupola_base: opts.cupolaBase ?? CUPOLA_BASE2,
9595
- catalogs
9596
- };
9597
- }
9598
- async function buildColumnsJson2(iface, catalog, schema4, table) {
9599
- const result = await attachCatalog(iface, catalog);
9600
- if (!result)
9601
- return null;
9602
- const aod = result.attach_opaque_data;
9603
- const tables = await schemaContents(iface, aod, schema4, "TABLE");
9604
- for (const t of tables) {
9605
- if (t.name === table) {
9606
- const arrow = readSchemaSafe(t.columns);
9607
- return { columns: (arrow?.fields ?? []).map((f) => fieldToColumn(f)) };
9608
- }
9609
- }
9610
- const views = await schemaContents(iface, aod, schema4, "VIEW");
9611
- for (const v of views) {
9612
- if (v.name === table) {
9613
- return {
9614
- columns: Object.entries(v.column_comments ?? {}).map(([name, comment]) => ({
9615
- name,
9616
- type: "",
9617
- comment
9618
- }))
9619
- };
9620
- }
9621
- }
9622
- return null;
9623
- }
9624
- function createLandingDescribe2(iface, worker, opts = {}) {
9625
- return {
9626
- describe: (ctx) => buildDescribeJson2(iface, worker, { ...ctx, cupolaBase: opts.cupolaBase }),
9627
- columns: (catalog, schema4, table) => buildColumnsJson2(iface, catalog, schema4, table)
9628
- };
9629
- }
9630
-
9631
9220
  // src/worker-cf-entry.ts
9632
9221
  init_arrow();
9633
9222
  import { OutputCollector as OutputCollector2, AuthContext as AuthContext2 } from "@query-farm/vgi-rpc";
@@ -9710,7 +9299,6 @@ export {
9710
9299
  dateDay2 as dateDay,
9711
9300
  date2 as date,
9712
9301
  createVgiFetch,
9713
- createLandingDescribe2 as createLandingDescribe,
9714
9302
  columnFromArray,
9715
9303
  buildStatisticsBatch,
9716
9304
  bool2 as bool,
@@ -9739,4 +9327,4 @@ export {
9739
9327
  Arguments
9740
9328
  };
9741
9329
 
9742
- //# debugId=676F411DADAC67E064756E2164756E21
9330
+ //# debugId=3225E125CCD893FA64756E2164756E21