@query-farm/vgi 0.24.1 → 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.
- package/dist/catalog/attach-option.d.ts +40 -0
- package/dist/catalog/read-only.d.ts +11 -0
- package/dist/client-entry.d.ts +2 -0
- package/dist/client-entry.js +76 -1
- package/dist/client-entry.js.map +5 -4
- package/dist/http/fetch.d.ts +5 -5
- package/dist/index.core.d.ts +2 -2
- package/dist/index.js +84 -442
- package/dist/index.js.map +6 -7
- package/dist/serve-entry.js +7 -446
- package/dist/serve-entry.js.map +5 -7
- package/dist/worker-cf-entry.d.ts +1 -2
- package/dist/worker-cf-entry.js +55 -440
- package/dist/worker-cf-entry.js.map +7 -8
- package/package.json +3 -3
- package/src/catalog/attach-option.ts +128 -0
- package/src/catalog/read-only.ts +20 -0
- package/src/client-entry.ts +11 -0
- package/src/http/fetch.ts +6 -6
- package/src/index.core.ts +6 -13
- package/src/serve-entry.ts +2 -7
- package/src/worker-cf-entry.ts +4 -4
- package/dist/http/describe-json.d.ts +0 -62
- package/src/http/describe-json.ts +0 -644
package/dist/http/fetch.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ProtocolConfig } from "../protocol/dispatch.js";
|
|
2
|
-
import type {
|
|
2
|
+
import type { LandingInfo } from "@query-farm/vgi-rpc";
|
|
3
3
|
export interface VgiFetchOptions {
|
|
4
4
|
/** Wire-protocol config (registry + catalogInterface). */
|
|
5
5
|
protocol: Omit<ProtocolConfig, "recoverExchangeState">;
|
|
@@ -21,10 +21,10 @@ export interface VgiFetchOptions {
|
|
|
21
21
|
/** Public source-repository URL, surfaced on the landing page. */
|
|
22
22
|
repositoryUrl?: string;
|
|
23
23
|
/** Enables the standardized VGI landing surface: `GET /` serves the shared
|
|
24
|
-
* landing.html
|
|
25
|
-
* `GET /
|
|
26
|
-
*
|
|
27
|
-
|
|
24
|
+
* landing.html plus a JSON status document carrying this identity, and
|
|
25
|
+
* `GET /vgi-client.js` serves the browser client build the page reads the
|
|
26
|
+
* catalog with. */
|
|
27
|
+
landingInfo?: LandingInfo;
|
|
28
28
|
}
|
|
29
29
|
/**
|
|
30
30
|
* Build a fetch handler suitable for `export default { fetch }` in a CF
|
package/dist/index.core.d.ts
CHANGED
|
@@ -24,9 +24,9 @@ export { metadatasToArrow, arrowToMetadatas } from "./metadata/serialize.js";
|
|
|
24
24
|
export { PushdownFilters, FilteringOutputCollector, deserializeFilters, buildJoinKeysLookup, ComparisonOp, type Filter, type ConstantFilter, type IsNullFilter, type IsNotNullFilter, type InFilter, type AndFilter, type OrFilter, type StructFilter, formatPushedFilters, reprPushedFilters, } from "./filter-pushdown/index.js";
|
|
25
25
|
export { arrowStateSerializer, EXCHANGE_STATE_SCHEMA, serializeUserState, deserializeUserState } from "./protocol/state-serializer.js";
|
|
26
26
|
export { buildVgiProtocol, type ProtocolConfig } from "./protocol/dispatch.js";
|
|
27
|
-
export
|
|
27
|
+
export type { LandingInfo } from "@query-farm/vgi-rpc";
|
|
28
28
|
export { BindResultSchema, ScanFunctionResultSchema } from "./generated/vgi-protocol-schemas.js";
|
|
29
|
-
export { type AttachOptionSpec, serializeAttachOptionSpec, serializeAttachOptionSpecs } from "./catalog/attach-option.js";
|
|
29
|
+
export { type AttachOptionSpec, serializeAttachOptionSpec, serializeAttachOptionSpecs, deserializeAttachOptionSpec, deserializeAttachOptionSpecs } from "./catalog/attach-option.js";
|
|
30
30
|
export { type ColumnStatistics, serializeColumnStatistics } from "./util/statistics.js";
|
|
31
31
|
export { toUint8Array } from "./util/bytes.js";
|
|
32
32
|
export { iterRows, batchFromRows, batchFromColumns, emptyBatch, filterBatch, projectSchema, projectBatch, batchToScalarDict, batchToSecretDict, safeNumber, } from "./util/arrow/index.js";
|
package/dist/index.js
CHANGED
|
@@ -7022,6 +7022,83 @@ function resolveMetadata(func) {
|
|
|
7022
7022
|
};
|
|
7023
7023
|
}
|
|
7024
7024
|
|
|
7025
|
+
// src/catalog/attach-option.ts
|
|
7026
|
+
init_arrow();
|
|
7027
|
+
var SPEC_SCHEMA = schema2([
|
|
7028
|
+
field2("name", utf82(), false),
|
|
7029
|
+
field2("description", utf82(), false),
|
|
7030
|
+
field2("type", binary2(), false),
|
|
7031
|
+
field2("default_value", binary2(), true),
|
|
7032
|
+
field2("required", bool2(), true)
|
|
7033
|
+
]);
|
|
7034
|
+
function serializeAttachOptionSpec(spec) {
|
|
7035
|
+
if (spec.required && spec.default !== undefined && spec.default !== null) {
|
|
7036
|
+
throw new Error(`Attach option '${spec.name}' is required but also declares a default ` + `(${JSON.stringify(spec.default)}); an option with a default is always ` + "satisfiable without the caller. Drop one.");
|
|
7037
|
+
}
|
|
7038
|
+
const typeSchema = schema2([field2("value", spec.type, true)]);
|
|
7039
|
+
const typeBytes = serializeSchema(typeSchema);
|
|
7040
|
+
let defaultBytes = null;
|
|
7041
|
+
if (spec.default !== undefined && spec.default !== null) {
|
|
7042
|
+
const defaultBatch = batchFromColumns({ value: [spec.default] }, typeSchema);
|
|
7043
|
+
defaultBytes = serializeBatch(defaultBatch);
|
|
7044
|
+
}
|
|
7045
|
+
const batch = batchFromColumns({
|
|
7046
|
+
name: [spec.name],
|
|
7047
|
+
description: [spec.description],
|
|
7048
|
+
type: [typeBytes],
|
|
7049
|
+
default_value: [defaultBytes],
|
|
7050
|
+
required: [spec.required ?? false]
|
|
7051
|
+
}, SPEC_SCHEMA);
|
|
7052
|
+
return serializeBatch(batch);
|
|
7053
|
+
}
|
|
7054
|
+
function serializeAttachOptionSpecs(specs) {
|
|
7055
|
+
return Array.from(specs, serializeAttachOptionSpec);
|
|
7056
|
+
}
|
|
7057
|
+
function deserializeAttachOptionSpec(bytes) {
|
|
7058
|
+
const row = [...iterRows(deserializeBatch(bytes))][0];
|
|
7059
|
+
if (row === undefined) {
|
|
7060
|
+
throw new Error("Cannot deserialize AttachOptionSpec from an empty batch");
|
|
7061
|
+
}
|
|
7062
|
+
const typeSchema = deserializeSchema(toUint8Array(row.type));
|
|
7063
|
+
const type = typeSchema.fields[0].type;
|
|
7064
|
+
let value;
|
|
7065
|
+
const defaultBytes = row.default_value;
|
|
7066
|
+
if (defaultBytes != null) {
|
|
7067
|
+
const asBytes = toUint8Array(defaultBytes);
|
|
7068
|
+
if (asBytes.length > 0) {
|
|
7069
|
+
const defaultRow = [...iterRows(deserializeBatch(asBytes))][0];
|
|
7070
|
+
value = defaultRow?.value;
|
|
7071
|
+
}
|
|
7072
|
+
}
|
|
7073
|
+
return {
|
|
7074
|
+
name: String(row.name),
|
|
7075
|
+
description: String(row.description ?? ""),
|
|
7076
|
+
type,
|
|
7077
|
+
...value === undefined || value === null ? {} : { default: value },
|
|
7078
|
+
required: row.required === true
|
|
7079
|
+
};
|
|
7080
|
+
}
|
|
7081
|
+
function deserializeAttachOptionSpecs(specs) {
|
|
7082
|
+
return Array.from(specs, deserializeAttachOptionSpec);
|
|
7083
|
+
}
|
|
7084
|
+
|
|
7085
|
+
class MissingAttachOptionsError extends Error {
|
|
7086
|
+
missing;
|
|
7087
|
+
constructor(catalogName, missing) {
|
|
7088
|
+
const joined = missing.map((name) => `'${name}'`).join(", ");
|
|
7089
|
+
super(`Catalog '${catalogName}' cannot be attached without the required ` + `option${missing.length > 1 ? "s" : ""} ${joined}.`);
|
|
7090
|
+
this.name = "MissingAttachOptionsError";
|
|
7091
|
+
this.missing = missing;
|
|
7092
|
+
}
|
|
7093
|
+
}
|
|
7094
|
+
function validateRequiredAttachOptions(catalogName, specs, options) {
|
|
7095
|
+
const supplied = new Set(Object.keys(options).map((key) => key.toLowerCase()));
|
|
7096
|
+
const missing = Array.from(specs).filter((spec) => spec.required && !supplied.has(spec.name.toLowerCase())).map((spec) => spec.name);
|
|
7097
|
+
if (missing.length > 0) {
|
|
7098
|
+
throw new MissingAttachOptionsError(catalogName, missing);
|
|
7099
|
+
}
|
|
7100
|
+
}
|
|
7101
|
+
|
|
7025
7102
|
// src/catalog/read-only.ts
|
|
7026
7103
|
class ReadOnlyCatalogInterface extends CatalogInterface {
|
|
7027
7104
|
_descriptor;
|
|
@@ -7047,6 +7124,9 @@ class ReadOnlyCatalogInterface extends CatalogInterface {
|
|
|
7047
7124
|
catalogs() {
|
|
7048
7125
|
return [this._descriptor.name];
|
|
7049
7126
|
}
|
|
7127
|
+
attachOptionSpecs(_name) {
|
|
7128
|
+
return [];
|
|
7129
|
+
}
|
|
7050
7130
|
catalogsInfo() {
|
|
7051
7131
|
return [{
|
|
7052
7132
|
name: this._descriptor.name,
|
|
@@ -7061,6 +7141,7 @@ class ReadOnlyCatalogInterface extends CatalogInterface {
|
|
|
7061
7141
|
if (!this.catalogs().includes(name)) {
|
|
7062
7142
|
throw new Error(`No worker handles catalog '${name}'`);
|
|
7063
7143
|
}
|
|
7144
|
+
validateRequiredAttachOptions(name, this.attachOptionSpecs(name), options ?? {});
|
|
7064
7145
|
const attachOpaqueData = new Uint8Array(16);
|
|
7065
7146
|
crypto.getRandomValues(attachOpaqueData);
|
|
7066
7147
|
this._attachments.set(name, attachOpaqueData);
|
|
@@ -10452,442 +10533,6 @@ function buildVgiProtocol(config) {
|
|
|
10452
10533
|
registerCatalogMethods(protocol, config.catalogInterface, config.catalogName, config.signingKey);
|
|
10453
10534
|
return protocol;
|
|
10454
10535
|
}
|
|
10455
|
-
// src/http/describe-json.ts
|
|
10456
|
-
init_arrow();
|
|
10457
|
-
var LANDING_SCHEMA_VERSION = 1;
|
|
10458
|
-
var CUPOLA_BASE = "https://cupola.query-farm.services";
|
|
10459
|
-
var STRING_TAGS = {
|
|
10460
|
-
title: "vgi.title",
|
|
10461
|
-
doc_md: "vgi.doc_md",
|
|
10462
|
-
source_url: "vgi.source_url",
|
|
10463
|
-
license: "vgi.license",
|
|
10464
|
-
author: "vgi.author",
|
|
10465
|
-
copyright: "vgi.copyright",
|
|
10466
|
-
support_contact: "vgi.support_contact",
|
|
10467
|
-
support_policy_url: "vgi.support_policy_url"
|
|
10468
|
-
};
|
|
10469
|
-
var KEYWORDS_TAG = "vgi.keywords";
|
|
10470
|
-
function typeToString(type) {
|
|
10471
|
-
if (isNull(type))
|
|
10472
|
-
return "NULL";
|
|
10473
|
-
if (isUtf8(type))
|
|
10474
|
-
return "VARCHAR";
|
|
10475
|
-
if (isBinary(type))
|
|
10476
|
-
return "BLOB";
|
|
10477
|
-
if (isBool(type))
|
|
10478
|
-
return "BOOLEAN";
|
|
10479
|
-
if (isInt(type)) {
|
|
10480
|
-
const bw = type.bitWidth ?? 32;
|
|
10481
|
-
return bw === 64 ? "BIGINT" : "INTEGER";
|
|
10482
|
-
}
|
|
10483
|
-
if (isFloat(type)) {
|
|
10484
|
-
const precision = type.precision ?? 2;
|
|
10485
|
-
return precision === 1 ? "FLOAT" : "DOUBLE";
|
|
10486
|
-
}
|
|
10487
|
-
const s = type.toString?.();
|
|
10488
|
-
return s ?? String(type.typeId);
|
|
10489
|
-
}
|
|
10490
|
-
function arrowTypeString(type) {
|
|
10491
|
-
if (isNull(type))
|
|
10492
|
-
return "null";
|
|
10493
|
-
if (isBool(type))
|
|
10494
|
-
return "bool";
|
|
10495
|
-
if (isUtf8(type))
|
|
10496
|
-
return "string";
|
|
10497
|
-
if (isBinary(type))
|
|
10498
|
-
return "binary";
|
|
10499
|
-
if (isInt(type)) {
|
|
10500
|
-
const bw = type.bitWidth ?? 32;
|
|
10501
|
-
const signed = type.isSigned ?? type.signed ?? true;
|
|
10502
|
-
return `${signed ? "" : "u"}int${bw}`;
|
|
10503
|
-
}
|
|
10504
|
-
if (isFloat(type)) {
|
|
10505
|
-
const precision = type.precision ?? 2;
|
|
10506
|
-
return precision === 0 ? "halffloat" : precision === 1 ? "float" : "double";
|
|
10507
|
-
}
|
|
10508
|
-
const s = type.toString?.();
|
|
10509
|
-
return (s ?? String(type.typeId)).toLowerCase();
|
|
10510
|
-
}
|
|
10511
|
-
function fieldMeta(field3, key) {
|
|
10512
|
-
return field3.metadata.get(key);
|
|
10513
|
-
}
|
|
10514
|
-
function fieldToColumn(field3) {
|
|
10515
|
-
const col = { name: field3.name, type: typeToString(field3.type) };
|
|
10516
|
-
const comment = fieldMeta(field3, "comment") ?? fieldMeta(field3, VGI_DOC_KEY);
|
|
10517
|
-
if (comment)
|
|
10518
|
-
col.comment = comment;
|
|
10519
|
-
return col;
|
|
10520
|
-
}
|
|
10521
|
-
function readSchemaSafe(bytes) {
|
|
10522
|
-
if (!bytes || bytes.length === 0)
|
|
10523
|
-
return null;
|
|
10524
|
-
try {
|
|
10525
|
-
return deserializeSchema(bytes);
|
|
10526
|
-
} catch {
|
|
10527
|
-
return null;
|
|
10528
|
-
}
|
|
10529
|
-
}
|
|
10530
|
-
function functionDisplayType(fn) {
|
|
10531
|
-
const t = String(fn.function_type).toUpperCase();
|
|
10532
|
-
if (t === "SCALAR")
|
|
10533
|
-
return "scalar";
|
|
10534
|
-
if (t === "AGGREGATE")
|
|
10535
|
-
return "aggregate";
|
|
10536
|
-
if (fn.has_finalize)
|
|
10537
|
-
return "table_in_out";
|
|
10538
|
-
return "table";
|
|
10539
|
-
}
|
|
10540
|
-
function functionReturns(fn) {
|
|
10541
|
-
const schema3 = readSchemaSafe(fn.output_schema);
|
|
10542
|
-
if (schema3 === null || schema3.fields.length === 0)
|
|
10543
|
-
return;
|
|
10544
|
-
const t = String(fn.function_type).toUpperCase();
|
|
10545
|
-
if (t === "SCALAR" || t === "AGGREGATE") {
|
|
10546
|
-
return typeToString(schema3.fields[0].type);
|
|
10547
|
-
}
|
|
10548
|
-
const cols = schema3.fields.map((f) => `${f.name} ${typeToString(f.type)}`).join(", ");
|
|
10549
|
-
return `TABLE(${cols})`;
|
|
10550
|
-
}
|
|
10551
|
-
function functionArgs(fn) {
|
|
10552
|
-
const schema3 = readSchemaSafe(fn.arguments);
|
|
10553
|
-
if (schema3 === null)
|
|
10554
|
-
return [];
|
|
10555
|
-
const args = [];
|
|
10556
|
-
for (const field3 of schema3.fields) {
|
|
10557
|
-
if (fieldMeta(field3, VGI_TYPE_KEY) === VGI_TYPE_TABLE)
|
|
10558
|
-
continue;
|
|
10559
|
-
const arg = { name: field3.name, type: typeToString(field3.type) };
|
|
10560
|
-
if (fieldMeta(field3, VGI_ARG_KEY) === VGI_ARG_NAMED)
|
|
10561
|
-
arg.named = true;
|
|
10562
|
-
const doc = fieldMeta(field3, VGI_DOC_KEY);
|
|
10563
|
-
if (doc)
|
|
10564
|
-
arg.desc = doc;
|
|
10565
|
-
const rawDefault = fieldMeta(field3, VGI_DEFAULT_KEY);
|
|
10566
|
-
if (rawDefault !== undefined) {
|
|
10567
|
-
try {
|
|
10568
|
-
arg.default = JSON.stringify(JSON.parse(rawDefault));
|
|
10569
|
-
} catch {
|
|
10570
|
-
arg.default = rawDefault;
|
|
10571
|
-
}
|
|
10572
|
-
}
|
|
10573
|
-
args.push(arg);
|
|
10574
|
-
}
|
|
10575
|
-
return args;
|
|
10576
|
-
}
|
|
10577
|
-
function macroDisplayType(m) {
|
|
10578
|
-
return String(m.macro_type).toUpperCase() === "SCALAR" ? "scalar" : "table";
|
|
10579
|
-
}
|
|
10580
|
-
function macroDefaultJson(value) {
|
|
10581
|
-
if (typeof value === "bigint")
|
|
10582
|
-
return value.toString();
|
|
10583
|
-
try {
|
|
10584
|
-
return JSON.stringify(value);
|
|
10585
|
-
} catch {
|
|
10586
|
-
return String(value);
|
|
10587
|
-
}
|
|
10588
|
-
}
|
|
10589
|
-
function macroArgs(m) {
|
|
10590
|
-
const defaults = new Map;
|
|
10591
|
-
const defBytes = m.parameter_default_values;
|
|
10592
|
-
if (defBytes && defBytes.length > 0) {
|
|
10593
|
-
try {
|
|
10594
|
-
const batch = deserializeBatch(defBytes);
|
|
10595
|
-
for (const field3 of batch.schema.fields) {
|
|
10596
|
-
try {
|
|
10597
|
-
defaults.set(field3.name, batch.getChild(field3.name)?.get(0));
|
|
10598
|
-
} catch {}
|
|
10599
|
-
}
|
|
10600
|
-
} catch {}
|
|
10601
|
-
}
|
|
10602
|
-
const schema3 = readSchemaSafe(m.arguments_schema);
|
|
10603
|
-
const fields = schema3 ? schema3.fields : null;
|
|
10604
|
-
const fieldByName = new Map;
|
|
10605
|
-
if (fields)
|
|
10606
|
-
for (const f of fields)
|
|
10607
|
-
fieldByName.set(f.name, f);
|
|
10608
|
-
const names = fields ? fields.map((f) => f.name) : m.parameters;
|
|
10609
|
-
const args = [];
|
|
10610
|
-
for (const name of names) {
|
|
10611
|
-
const field3 = fieldByName.get(name);
|
|
10612
|
-
const arg = field3 !== undefined && !isNull(field3.type) ? { name, type: arrowTypeString(field3.type) } : { name, type: "ANY" };
|
|
10613
|
-
const doc = field3 !== undefined ? fieldMeta(field3, VGI_DOC_KEY) : undefined;
|
|
10614
|
-
if (doc)
|
|
10615
|
-
arg.desc = doc;
|
|
10616
|
-
if (defaults.has(name)) {
|
|
10617
|
-
arg.named = true;
|
|
10618
|
-
arg.default = macroDefaultJson(defaults.get(name));
|
|
10619
|
-
}
|
|
10620
|
-
args.push(arg);
|
|
10621
|
-
}
|
|
10622
|
-
return args;
|
|
10623
|
-
}
|
|
10624
|
-
function macroToObject(m) {
|
|
10625
|
-
return {
|
|
10626
|
-
name: m.name,
|
|
10627
|
-
type: macroDisplayType(m),
|
|
10628
|
-
doc: m.comment ?? "",
|
|
10629
|
-
args: macroArgs(m)
|
|
10630
|
-
};
|
|
10631
|
-
}
|
|
10632
|
-
async function schemaContents(iface, aod, name, kind) {
|
|
10633
|
-
try {
|
|
10634
|
-
if (kind === "TABLE") {
|
|
10635
|
-
return await iface.schemaContentsTables(aod, name);
|
|
10636
|
-
}
|
|
10637
|
-
return await iface.schemaContentsViews(aod, name);
|
|
10638
|
-
} catch {
|
|
10639
|
-
return [];
|
|
10640
|
-
}
|
|
10641
|
-
}
|
|
10642
|
-
async function schemaFunctions(iface, aod, name) {
|
|
10643
|
-
const out = [];
|
|
10644
|
-
for (const kind of ["SCALAR_FUNCTION", "TABLE_FUNCTION", "AGGREGATE_FUNCTION"]) {
|
|
10645
|
-
try {
|
|
10646
|
-
out.push(...await iface.schemaContentsFunctions(aod, name, kind));
|
|
10647
|
-
} catch {}
|
|
10648
|
-
}
|
|
10649
|
-
return out;
|
|
10650
|
-
}
|
|
10651
|
-
async function schemaMacros(iface, aod, name) {
|
|
10652
|
-
const out = [];
|
|
10653
|
-
for (const kind of ["SCALAR_MACRO", "TABLE_MACRO"]) {
|
|
10654
|
-
try {
|
|
10655
|
-
out.push(...await iface.schemaContentsMacros(aod, name, kind));
|
|
10656
|
-
} catch {}
|
|
10657
|
-
}
|
|
10658
|
-
return out;
|
|
10659
|
-
}
|
|
10660
|
-
async function buildSchemas(iface, aod) {
|
|
10661
|
-
let schemaInfos;
|
|
10662
|
-
try {
|
|
10663
|
-
schemaInfos = await iface.schemas(aod);
|
|
10664
|
-
} catch {
|
|
10665
|
-
return { schemas: [], counts: { schemas: 0, tables: 0, views: 0, functions: 0 } };
|
|
10666
|
-
}
|
|
10667
|
-
const schemas = [];
|
|
10668
|
-
const counts = { schemas: 0, tables: 0, views: 0, functions: 0 };
|
|
10669
|
-
for (const si of schemaInfos) {
|
|
10670
|
-
const tablesRaw = await schemaContents(iface, aod, si.name, "TABLE");
|
|
10671
|
-
const viewsRaw = await schemaContents(iface, aod, si.name, "VIEW");
|
|
10672
|
-
const funcsRaw = await schemaFunctions(iface, aod, si.name);
|
|
10673
|
-
const macrosRaw = await schemaMacros(iface, aod, si.name);
|
|
10674
|
-
const tables = tablesRaw.map((t) => {
|
|
10675
|
-
const schema3 = readSchemaSafe(t.columns);
|
|
10676
|
-
return { name: t.name, cols: schema3 ? schema3.fields.length : 0, comment: t.comment ?? "" };
|
|
10677
|
-
});
|
|
10678
|
-
const views = viewsRaw.map((v) => ({
|
|
10679
|
-
name: v.name,
|
|
10680
|
-
cols: Object.keys(v.column_comments ?? {}).length,
|
|
10681
|
-
comment: v.comment ?? "",
|
|
10682
|
-
def: v.definition
|
|
10683
|
-
}));
|
|
10684
|
-
const functions = funcsRaw.map((fn) => {
|
|
10685
|
-
const obj = {
|
|
10686
|
-
name: fn.name,
|
|
10687
|
-
type: functionDisplayType(fn),
|
|
10688
|
-
doc: fn.description ?? "",
|
|
10689
|
-
args: functionArgs(fn)
|
|
10690
|
-
};
|
|
10691
|
-
const ret = functionReturns(fn);
|
|
10692
|
-
if (ret)
|
|
10693
|
-
obj.returns = ret;
|
|
10694
|
-
return obj;
|
|
10695
|
-
});
|
|
10696
|
-
functions.push(...macrosRaw.map((m) => macroToObject(m)));
|
|
10697
|
-
functions.sort((a, b) => String(a.type).localeCompare(String(b.type)) || String(a.name).localeCompare(String(b.name)));
|
|
10698
|
-
const schemaObj = { name: si.name };
|
|
10699
|
-
if (si.comment)
|
|
10700
|
-
schemaObj.doc = si.comment;
|
|
10701
|
-
schemaObj.tables = tables;
|
|
10702
|
-
schemaObj.views = views;
|
|
10703
|
-
schemaObj.functions = functions;
|
|
10704
|
-
schemas.push(schemaObj);
|
|
10705
|
-
counts.schemas += 1;
|
|
10706
|
-
counts.tables += tables.length;
|
|
10707
|
-
counts.views += views.length;
|
|
10708
|
-
counts.functions += functions.length;
|
|
10709
|
-
}
|
|
10710
|
-
return { schemas, counts };
|
|
10711
|
-
}
|
|
10712
|
-
function catalogTags(result) {
|
|
10713
|
-
const tags = result?.tags;
|
|
10714
|
-
if (!tags)
|
|
10715
|
-
return {};
|
|
10716
|
-
const out = {};
|
|
10717
|
-
for (const [key, tag] of Object.entries(STRING_TAGS)) {
|
|
10718
|
-
const val = tags[tag];
|
|
10719
|
-
if (val)
|
|
10720
|
-
out[key] = val;
|
|
10721
|
-
}
|
|
10722
|
-
const kw = tags[KEYWORDS_TAG];
|
|
10723
|
-
if (kw) {
|
|
10724
|
-
try {
|
|
10725
|
-
const parsed = JSON.parse(kw);
|
|
10726
|
-
if (Array.isArray(parsed))
|
|
10727
|
-
out.keywords = parsed.map((k) => String(k));
|
|
10728
|
-
} catch {}
|
|
10729
|
-
}
|
|
10730
|
-
return out;
|
|
10731
|
-
}
|
|
10732
|
-
function decodeAttachOption(bytes) {
|
|
10733
|
-
try {
|
|
10734
|
-
const batch = deserializeBatch(bytes);
|
|
10735
|
-
if (batch.numRows === 0)
|
|
10736
|
-
return null;
|
|
10737
|
-
const name = String(batch.getChild("name")?.get(0) ?? "");
|
|
10738
|
-
const description = String(batch.getChild("description")?.get(0) ?? "");
|
|
10739
|
-
const typeBytes = batch.getChild("type")?.get(0);
|
|
10740
|
-
let type = "";
|
|
10741
|
-
const typeSchema = readSchemaSafe(typeBytes ?? null);
|
|
10742
|
-
if (typeSchema && typeSchema.fields.length > 0)
|
|
10743
|
-
type = typeToString(typeSchema.fields[0].type);
|
|
10744
|
-
let defaultStr = "";
|
|
10745
|
-
const defBytes = batch.getChild("default_value")?.get(0);
|
|
10746
|
-
if (defBytes) {
|
|
10747
|
-
try {
|
|
10748
|
-
const defBatch = deserializeBatch(defBytes);
|
|
10749
|
-
if (defBatch.numRows > 0) {
|
|
10750
|
-
const v = defBatch.getChild("value")?.get(0);
|
|
10751
|
-
defaultStr = v == null ? "" : String(v);
|
|
10752
|
-
}
|
|
10753
|
-
} catch {}
|
|
10754
|
-
}
|
|
10755
|
-
return { name, type, default: defaultStr, description };
|
|
10756
|
-
} catch {
|
|
10757
|
-
return null;
|
|
10758
|
-
}
|
|
10759
|
-
}
|
|
10760
|
-
async function attachCatalog(iface, name) {
|
|
10761
|
-
try {
|
|
10762
|
-
return await iface.attach(name, {}, null, null);
|
|
10763
|
-
} catch {
|
|
10764
|
-
return null;
|
|
10765
|
-
}
|
|
10766
|
-
}
|
|
10767
|
-
async function buildCatalog(iface, name, info) {
|
|
10768
|
-
const result = await attachCatalog(iface, name);
|
|
10769
|
-
const attachOptions = (info?.attach_option_specs ?? []).map((b) => decodeAttachOption(b)).filter((o) => o !== null);
|
|
10770
|
-
const dataVersions = (info?.releases ?? []).map((r) => r.summary ? { spec: r.version, label: r.summary } : { spec: r.version });
|
|
10771
|
-
let impl = info?.implementation_version ?? null;
|
|
10772
|
-
let dvs = info?.data_version_spec ?? null;
|
|
10773
|
-
if (result) {
|
|
10774
|
-
impl = result.resolved_implementation_version ?? impl;
|
|
10775
|
-
dvs = result.resolved_data_version ?? dvs;
|
|
10776
|
-
}
|
|
10777
|
-
let schemas = [];
|
|
10778
|
-
let counts = { schemas: 0, tables: 0, views: 0, functions: 0 };
|
|
10779
|
-
if (result) {
|
|
10780
|
-
const built = await buildSchemas(iface, result.attach_opaque_data);
|
|
10781
|
-
schemas = built.schemas;
|
|
10782
|
-
counts = built.counts;
|
|
10783
|
-
}
|
|
10784
|
-
return {
|
|
10785
|
-
name,
|
|
10786
|
-
implementation_version: impl,
|
|
10787
|
-
data_version_spec: dvs,
|
|
10788
|
-
data_versions: dataVersions,
|
|
10789
|
-
attach_options: attachOptions,
|
|
10790
|
-
tags: catalogTags(result),
|
|
10791
|
-
counts,
|
|
10792
|
-
schemas
|
|
10793
|
-
};
|
|
10794
|
-
}
|
|
10795
|
-
async function catalogInfoByName(iface) {
|
|
10796
|
-
const map3 = new Map;
|
|
10797
|
-
if (typeof iface.catalogsInfo === "function") {
|
|
10798
|
-
try {
|
|
10799
|
-
const infos = await iface.catalogsInfo();
|
|
10800
|
-
for (const info of infos)
|
|
10801
|
-
map3.set(info.name, info);
|
|
10802
|
-
} catch {}
|
|
10803
|
-
}
|
|
10804
|
-
return map3;
|
|
10805
|
-
}
|
|
10806
|
-
async function buildDescribeJson(iface, worker, opts = {}) {
|
|
10807
|
-
const infos = await catalogInfoByName(iface);
|
|
10808
|
-
let names;
|
|
10809
|
-
try {
|
|
10810
|
-
names = iface.catalogs();
|
|
10811
|
-
} catch {
|
|
10812
|
-
names = [];
|
|
10813
|
-
}
|
|
10814
|
-
const catalogs = [];
|
|
10815
|
-
for (const name of names) {
|
|
10816
|
-
catalogs.push(await buildCatalog(iface, name, infos.get(name)));
|
|
10817
|
-
}
|
|
10818
|
-
return {
|
|
10819
|
-
landing_schema_version: LANDING_SCHEMA_VERSION,
|
|
10820
|
-
worker: {
|
|
10821
|
-
name: worker.name,
|
|
10822
|
-
doc: worker.doc ?? "",
|
|
10823
|
-
version: worker.version ?? "unknown",
|
|
10824
|
-
lang: "typescript"
|
|
10825
|
-
},
|
|
10826
|
-
server_id: opts.serverId ?? "",
|
|
10827
|
-
oauth: opts.oauth ?? false,
|
|
10828
|
-
cupola_base: opts.cupolaBase ?? CUPOLA_BASE,
|
|
10829
|
-
catalogs
|
|
10830
|
-
};
|
|
10831
|
-
}
|
|
10832
|
-
async function buildColumnsJson(iface, catalog, schema3, table) {
|
|
10833
|
-
const result = await attachCatalog(iface, catalog);
|
|
10834
|
-
if (!result)
|
|
10835
|
-
return null;
|
|
10836
|
-
const aod = result.attach_opaque_data;
|
|
10837
|
-
const tables = await schemaContents(iface, aod, schema3, "TABLE");
|
|
10838
|
-
for (const t of tables) {
|
|
10839
|
-
if (t.name === table) {
|
|
10840
|
-
const arrow = readSchemaSafe(t.columns);
|
|
10841
|
-
return { columns: (arrow?.fields ?? []).map((f) => fieldToColumn(f)) };
|
|
10842
|
-
}
|
|
10843
|
-
}
|
|
10844
|
-
const views = await schemaContents(iface, aod, schema3, "VIEW");
|
|
10845
|
-
for (const v of views) {
|
|
10846
|
-
if (v.name === table) {
|
|
10847
|
-
return {
|
|
10848
|
-
columns: Object.entries(v.column_comments ?? {}).map(([name, comment]) => ({
|
|
10849
|
-
name,
|
|
10850
|
-
type: "",
|
|
10851
|
-
comment
|
|
10852
|
-
}))
|
|
10853
|
-
};
|
|
10854
|
-
}
|
|
10855
|
-
}
|
|
10856
|
-
return null;
|
|
10857
|
-
}
|
|
10858
|
-
function createLandingDescribe(iface, worker, opts = {}) {
|
|
10859
|
-
return {
|
|
10860
|
-
describe: (ctx) => buildDescribeJson(iface, worker, { ...ctx, cupolaBase: opts.cupolaBase }),
|
|
10861
|
-
columns: (catalog, schema3, table) => buildColumnsJson(iface, catalog, schema3, table)
|
|
10862
|
-
};
|
|
10863
|
-
}
|
|
10864
|
-
// src/catalog/attach-option.ts
|
|
10865
|
-
init_arrow();
|
|
10866
|
-
var SPEC_SCHEMA = schema2([
|
|
10867
|
-
field2("name", utf82(), false),
|
|
10868
|
-
field2("description", utf82(), false),
|
|
10869
|
-
field2("type", binary2(), false),
|
|
10870
|
-
field2("default_value", binary2(), true)
|
|
10871
|
-
]);
|
|
10872
|
-
function serializeAttachOptionSpec(spec) {
|
|
10873
|
-
const typeSchema = schema2([field2("value", spec.type, true)]);
|
|
10874
|
-
const typeBytes = serializeSchema(typeSchema);
|
|
10875
|
-
let defaultBytes = null;
|
|
10876
|
-
if (spec.default !== undefined && spec.default !== null) {
|
|
10877
|
-
const defaultBatch = batchFromColumns({ value: [spec.default] }, typeSchema);
|
|
10878
|
-
defaultBytes = serializeBatch(defaultBatch);
|
|
10879
|
-
}
|
|
10880
|
-
const batch = batchFromColumns({
|
|
10881
|
-
name: [spec.name],
|
|
10882
|
-
description: [spec.description],
|
|
10883
|
-
type: [typeBytes],
|
|
10884
|
-
default_value: [defaultBytes]
|
|
10885
|
-
}, SPEC_SCHEMA);
|
|
10886
|
-
return serializeBatch(batch);
|
|
10887
|
-
}
|
|
10888
|
-
function serializeAttachOptionSpecs(specs) {
|
|
10889
|
-
return Array.from(specs, serializeAttachOptionSpec);
|
|
10890
|
-
}
|
|
10891
10536
|
// src/secrets/helpers.ts
|
|
10892
10537
|
function scalarStr(v) {
|
|
10893
10538
|
if (v === null || v === undefined)
|
|
@@ -12045,6 +11690,8 @@ export {
|
|
|
12045
11690
|
deserializeSchema,
|
|
12046
11691
|
deserializeFilters,
|
|
12047
11692
|
deserializeBatch,
|
|
11693
|
+
deserializeAttachOptionSpecs,
|
|
11694
|
+
deserializeAttachOptionSpec,
|
|
12048
11695
|
denseUnion2 as denseUnion,
|
|
12049
11696
|
defineTableInOutFunction,
|
|
12050
11697
|
defineTableFunction,
|
|
@@ -12067,7 +11714,6 @@ export {
|
|
|
12067
11714
|
dateMillisecond2 as dateMillisecond,
|
|
12068
11715
|
dateDay2 as dateDay,
|
|
12069
11716
|
date2 as date,
|
|
12070
|
-
createLandingDescribe,
|
|
12071
11717
|
constraintSpecFields,
|
|
12072
11718
|
columnFromArray,
|
|
12073
11719
|
codecFor,
|
|
@@ -12076,8 +11722,6 @@ export {
|
|
|
12076
11722
|
buildVgiProtocol,
|
|
12077
11723
|
buildScanBranchesResult,
|
|
12078
11724
|
buildJoinKeysLookup,
|
|
12079
|
-
buildDescribeJson,
|
|
12080
|
-
buildColumnsJson,
|
|
12081
11725
|
bool3 as bool,
|
|
12082
11726
|
binary2 as binary,
|
|
12083
11727
|
batchToSecretDict,
|
|
@@ -12125,7 +11769,6 @@ export {
|
|
|
12125
11769
|
OrderDependence,
|
|
12126
11770
|
NullHandling,
|
|
12127
11771
|
NoCatalogError,
|
|
12128
|
-
LANDING_SCHEMA_VERSION,
|
|
12129
11772
|
IntervalUnit2 as IntervalUnit,
|
|
12130
11773
|
GROUP_COLUMN_NAME,
|
|
12131
11774
|
FunctionType,
|
|
@@ -12146,7 +11789,6 @@ export {
|
|
|
12146
11789
|
CatalogInterface,
|
|
12147
11790
|
CatalogFunctionType,
|
|
12148
11791
|
CatalogAlreadyExistsError,
|
|
12149
|
-
CUPOLA_BASE,
|
|
12150
11792
|
CACHE_TTL_KEY,
|
|
12151
11793
|
CACHE_STALE_WHILE_REVALIDATE_KEY,
|
|
12152
11794
|
CACHE_STALE_IF_ERROR_KEY,
|
|
@@ -12170,4 +11812,4 @@ export {
|
|
|
12170
11812
|
ArgumentValidationError
|
|
12171
11813
|
};
|
|
12172
11814
|
|
|
12173
|
-
//# debugId=
|
|
11815
|
+
//# debugId=DE208C45586A782664756E2164756E21
|