@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
|
@@ -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 {
|
|
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";
|
package/dist/worker-cf-entry.js
CHANGED
|
@@ -7296,7 +7296,7 @@ function createVgiFetch(opts) {
|
|
|
7296
7296
|
stateSerializer: arrowStateSerializer,
|
|
7297
7297
|
corsOrigins: opts.corsOrigins,
|
|
7298
7298
|
repositoryUrl: opts.repositoryUrl,
|
|
7299
|
-
|
|
7299
|
+
landingInfo: opts.landingInfo
|
|
7300
7300
|
});
|
|
7301
7301
|
return async (req) => handler(req);
|
|
7302
7302
|
}
|
|
@@ -8116,6 +8116,55 @@ function resolveMetadata(func) {
|
|
|
8116
8116
|
};
|
|
8117
8117
|
}
|
|
8118
8118
|
|
|
8119
|
+
// src/catalog/attach-option.ts
|
|
8120
|
+
init_arrow();
|
|
8121
|
+
var SPEC_SCHEMA = schema2([
|
|
8122
|
+
field2("name", utf82(), false),
|
|
8123
|
+
field2("description", utf82(), false),
|
|
8124
|
+
field2("type", binary2(), false),
|
|
8125
|
+
field2("default_value", binary2(), true),
|
|
8126
|
+
field2("required", bool2(), true)
|
|
8127
|
+
]);
|
|
8128
|
+
function serializeAttachOptionSpec(spec) {
|
|
8129
|
+
if (spec.required && spec.default !== undefined && spec.default !== null) {
|
|
8130
|
+
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.");
|
|
8131
|
+
}
|
|
8132
|
+
const typeSchema = schema2([field2("value", spec.type, true)]);
|
|
8133
|
+
const typeBytes = serializeSchema(typeSchema);
|
|
8134
|
+
let defaultBytes = null;
|
|
8135
|
+
if (spec.default !== undefined && spec.default !== null) {
|
|
8136
|
+
const defaultBatch = batchFromColumns({ value: [spec.default] }, typeSchema);
|
|
8137
|
+
defaultBytes = serializeBatch(defaultBatch);
|
|
8138
|
+
}
|
|
8139
|
+
const batch = batchFromColumns({
|
|
8140
|
+
name: [spec.name],
|
|
8141
|
+
description: [spec.description],
|
|
8142
|
+
type: [typeBytes],
|
|
8143
|
+
default_value: [defaultBytes],
|
|
8144
|
+
required: [spec.required ?? false]
|
|
8145
|
+
}, SPEC_SCHEMA);
|
|
8146
|
+
return serializeBatch(batch);
|
|
8147
|
+
}
|
|
8148
|
+
function serializeAttachOptionSpecs(specs) {
|
|
8149
|
+
return Array.from(specs, serializeAttachOptionSpec);
|
|
8150
|
+
}
|
|
8151
|
+
class MissingAttachOptionsError extends Error {
|
|
8152
|
+
missing;
|
|
8153
|
+
constructor(catalogName, missing) {
|
|
8154
|
+
const joined = missing.map((name) => `'${name}'`).join(", ");
|
|
8155
|
+
super(`Catalog '${catalogName}' cannot be attached without the required ` + `option${missing.length > 1 ? "s" : ""} ${joined}.`);
|
|
8156
|
+
this.name = "MissingAttachOptionsError";
|
|
8157
|
+
this.missing = missing;
|
|
8158
|
+
}
|
|
8159
|
+
}
|
|
8160
|
+
function validateRequiredAttachOptions(catalogName, specs, options) {
|
|
8161
|
+
const supplied = new Set(Object.keys(options).map((key) => key.toLowerCase()));
|
|
8162
|
+
const missing = Array.from(specs).filter((spec) => spec.required && !supplied.has(spec.name.toLowerCase())).map((spec) => spec.name);
|
|
8163
|
+
if (missing.length > 0) {
|
|
8164
|
+
throw new MissingAttachOptionsError(catalogName, missing);
|
|
8165
|
+
}
|
|
8166
|
+
}
|
|
8167
|
+
|
|
8119
8168
|
// src/catalog/read-only.ts
|
|
8120
8169
|
class ReadOnlyCatalogInterface extends CatalogInterface {
|
|
8121
8170
|
_descriptor;
|
|
@@ -8141,6 +8190,9 @@ class ReadOnlyCatalogInterface extends CatalogInterface {
|
|
|
8141
8190
|
catalogs() {
|
|
8142
8191
|
return [this._descriptor.name];
|
|
8143
8192
|
}
|
|
8193
|
+
attachOptionSpecs(_name) {
|
|
8194
|
+
return [];
|
|
8195
|
+
}
|
|
8144
8196
|
catalogsInfo() {
|
|
8145
8197
|
return [{
|
|
8146
8198
|
name: this._descriptor.name,
|
|
@@ -8155,6 +8207,7 @@ class ReadOnlyCatalogInterface extends CatalogInterface {
|
|
|
8155
8207
|
if (!this.catalogs().includes(name)) {
|
|
8156
8208
|
throw new Error(`No worker handles catalog '${name}'`);
|
|
8157
8209
|
}
|
|
8210
|
+
validateRequiredAttachOptions(name, this.attachOptionSpecs(name), options ?? {});
|
|
8158
8211
|
const attachOpaqueData = new Uint8Array(16);
|
|
8159
8212
|
crypto.getRandomValues(attachOpaqueData);
|
|
8160
8213
|
this._attachments.set(name, attachOpaqueData);
|
|
@@ -9164,443 +9217,6 @@ class FunctionRegistry {
|
|
|
9164
9217
|
return result;
|
|
9165
9218
|
}
|
|
9166
9219
|
}
|
|
9167
|
-
// src/catalog/attach-option.ts
|
|
9168
|
-
init_arrow();
|
|
9169
|
-
var SPEC_SCHEMA = schema2([
|
|
9170
|
-
field2("name", utf82(), false),
|
|
9171
|
-
field2("description", utf82(), false),
|
|
9172
|
-
field2("type", binary2(), false),
|
|
9173
|
-
field2("default_value", binary2(), true)
|
|
9174
|
-
]);
|
|
9175
|
-
function serializeAttachOptionSpec(spec) {
|
|
9176
|
-
const typeSchema = schema2([field2("value", spec.type, true)]);
|
|
9177
|
-
const typeBytes = serializeSchema(typeSchema);
|
|
9178
|
-
let defaultBytes = null;
|
|
9179
|
-
if (spec.default !== undefined && spec.default !== null) {
|
|
9180
|
-
const defaultBatch = batchFromColumns({ value: [spec.default] }, typeSchema);
|
|
9181
|
-
defaultBytes = serializeBatch(defaultBatch);
|
|
9182
|
-
}
|
|
9183
|
-
const batch = batchFromColumns({
|
|
9184
|
-
name: [spec.name],
|
|
9185
|
-
description: [spec.description],
|
|
9186
|
-
type: [typeBytes],
|
|
9187
|
-
default_value: [defaultBytes]
|
|
9188
|
-
}, SPEC_SCHEMA);
|
|
9189
|
-
return serializeBatch(batch);
|
|
9190
|
-
}
|
|
9191
|
-
function serializeAttachOptionSpecs(specs) {
|
|
9192
|
-
return Array.from(specs, serializeAttachOptionSpec);
|
|
9193
|
-
}
|
|
9194
|
-
// src/http/describe-json.ts
|
|
9195
|
-
init_arrow();
|
|
9196
|
-
var LANDING_SCHEMA_VERSION2 = 1;
|
|
9197
|
-
var CUPOLA_BASE2 = "https://cupola.query-farm.services";
|
|
9198
|
-
var STRING_TAGS = {
|
|
9199
|
-
title: "vgi.title",
|
|
9200
|
-
doc_md: "vgi.doc_md",
|
|
9201
|
-
source_url: "vgi.source_url",
|
|
9202
|
-
license: "vgi.license",
|
|
9203
|
-
author: "vgi.author",
|
|
9204
|
-
copyright: "vgi.copyright",
|
|
9205
|
-
support_contact: "vgi.support_contact",
|
|
9206
|
-
support_policy_url: "vgi.support_policy_url"
|
|
9207
|
-
};
|
|
9208
|
-
var KEYWORDS_TAG = "vgi.keywords";
|
|
9209
|
-
function typeToString(type) {
|
|
9210
|
-
if (isNull(type))
|
|
9211
|
-
return "NULL";
|
|
9212
|
-
if (isUtf8(type))
|
|
9213
|
-
return "VARCHAR";
|
|
9214
|
-
if (isBinary(type))
|
|
9215
|
-
return "BLOB";
|
|
9216
|
-
if (isBool(type))
|
|
9217
|
-
return "BOOLEAN";
|
|
9218
|
-
if (isInt(type)) {
|
|
9219
|
-
const bw = type.bitWidth ?? 32;
|
|
9220
|
-
return bw === 64 ? "BIGINT" : "INTEGER";
|
|
9221
|
-
}
|
|
9222
|
-
if (isFloat(type)) {
|
|
9223
|
-
const precision = type.precision ?? 2;
|
|
9224
|
-
return precision === 1 ? "FLOAT" : "DOUBLE";
|
|
9225
|
-
}
|
|
9226
|
-
const s = type.toString?.();
|
|
9227
|
-
return s ?? String(type.typeId);
|
|
9228
|
-
}
|
|
9229
|
-
function arrowTypeString(type) {
|
|
9230
|
-
if (isNull(type))
|
|
9231
|
-
return "null";
|
|
9232
|
-
if (isBool(type))
|
|
9233
|
-
return "bool";
|
|
9234
|
-
if (isUtf8(type))
|
|
9235
|
-
return "string";
|
|
9236
|
-
if (isBinary(type))
|
|
9237
|
-
return "binary";
|
|
9238
|
-
if (isInt(type)) {
|
|
9239
|
-
const bw = type.bitWidth ?? 32;
|
|
9240
|
-
const signed = type.isSigned ?? type.signed ?? true;
|
|
9241
|
-
return `${signed ? "" : "u"}int${bw}`;
|
|
9242
|
-
}
|
|
9243
|
-
if (isFloat(type)) {
|
|
9244
|
-
const precision = type.precision ?? 2;
|
|
9245
|
-
return precision === 0 ? "halffloat" : precision === 1 ? "float" : "double";
|
|
9246
|
-
}
|
|
9247
|
-
const s = type.toString?.();
|
|
9248
|
-
return (s ?? String(type.typeId)).toLowerCase();
|
|
9249
|
-
}
|
|
9250
|
-
function fieldMeta(field4, key) {
|
|
9251
|
-
return field4.metadata.get(key);
|
|
9252
|
-
}
|
|
9253
|
-
function fieldToColumn(field4) {
|
|
9254
|
-
const col = { name: field4.name, type: typeToString(field4.type) };
|
|
9255
|
-
const comment = fieldMeta(field4, "comment") ?? fieldMeta(field4, VGI_DOC_KEY);
|
|
9256
|
-
if (comment)
|
|
9257
|
-
col.comment = comment;
|
|
9258
|
-
return col;
|
|
9259
|
-
}
|
|
9260
|
-
function readSchemaSafe(bytes2) {
|
|
9261
|
-
if (!bytes2 || bytes2.length === 0)
|
|
9262
|
-
return null;
|
|
9263
|
-
try {
|
|
9264
|
-
return deserializeSchema(bytes2);
|
|
9265
|
-
} catch {
|
|
9266
|
-
return null;
|
|
9267
|
-
}
|
|
9268
|
-
}
|
|
9269
|
-
function functionDisplayType(fn) {
|
|
9270
|
-
const t = String(fn.function_type).toUpperCase();
|
|
9271
|
-
if (t === "SCALAR")
|
|
9272
|
-
return "scalar";
|
|
9273
|
-
if (t === "AGGREGATE")
|
|
9274
|
-
return "aggregate";
|
|
9275
|
-
if (fn.has_finalize)
|
|
9276
|
-
return "table_in_out";
|
|
9277
|
-
return "table";
|
|
9278
|
-
}
|
|
9279
|
-
function functionReturns(fn) {
|
|
9280
|
-
const schema4 = readSchemaSafe(fn.output_schema);
|
|
9281
|
-
if (schema4 === null || schema4.fields.length === 0)
|
|
9282
|
-
return;
|
|
9283
|
-
const t = String(fn.function_type).toUpperCase();
|
|
9284
|
-
if (t === "SCALAR" || t === "AGGREGATE") {
|
|
9285
|
-
return typeToString(schema4.fields[0].type);
|
|
9286
|
-
}
|
|
9287
|
-
const cols = schema4.fields.map((f) => `${f.name} ${typeToString(f.type)}`).join(", ");
|
|
9288
|
-
return `TABLE(${cols})`;
|
|
9289
|
-
}
|
|
9290
|
-
function functionArgs(fn) {
|
|
9291
|
-
const schema4 = readSchemaSafe(fn.arguments);
|
|
9292
|
-
if (schema4 === null)
|
|
9293
|
-
return [];
|
|
9294
|
-
const args = [];
|
|
9295
|
-
for (const field4 of schema4.fields) {
|
|
9296
|
-
if (fieldMeta(field4, VGI_TYPE_KEY) === VGI_TYPE_TABLE)
|
|
9297
|
-
continue;
|
|
9298
|
-
const arg = { name: field4.name, type: typeToString(field4.type) };
|
|
9299
|
-
if (fieldMeta(field4, VGI_ARG_KEY) === VGI_ARG_NAMED)
|
|
9300
|
-
arg.named = true;
|
|
9301
|
-
const doc = fieldMeta(field4, VGI_DOC_KEY);
|
|
9302
|
-
if (doc)
|
|
9303
|
-
arg.desc = doc;
|
|
9304
|
-
const rawDefault = fieldMeta(field4, VGI_DEFAULT_KEY);
|
|
9305
|
-
if (rawDefault !== undefined) {
|
|
9306
|
-
try {
|
|
9307
|
-
arg.default = JSON.stringify(JSON.parse(rawDefault));
|
|
9308
|
-
} catch {
|
|
9309
|
-
arg.default = rawDefault;
|
|
9310
|
-
}
|
|
9311
|
-
}
|
|
9312
|
-
args.push(arg);
|
|
9313
|
-
}
|
|
9314
|
-
return args;
|
|
9315
|
-
}
|
|
9316
|
-
function macroDisplayType(m) {
|
|
9317
|
-
return String(m.macro_type).toUpperCase() === "SCALAR" ? "scalar" : "table";
|
|
9318
|
-
}
|
|
9319
|
-
function macroDefaultJson(value) {
|
|
9320
|
-
if (typeof value === "bigint")
|
|
9321
|
-
return value.toString();
|
|
9322
|
-
try {
|
|
9323
|
-
return JSON.stringify(value);
|
|
9324
|
-
} catch {
|
|
9325
|
-
return String(value);
|
|
9326
|
-
}
|
|
9327
|
-
}
|
|
9328
|
-
function macroArgs(m) {
|
|
9329
|
-
const defaults = new Map;
|
|
9330
|
-
const defBytes = m.parameter_default_values;
|
|
9331
|
-
if (defBytes && defBytes.length > 0) {
|
|
9332
|
-
try {
|
|
9333
|
-
const batch = deserializeBatch(defBytes);
|
|
9334
|
-
for (const field4 of batch.schema.fields) {
|
|
9335
|
-
try {
|
|
9336
|
-
defaults.set(field4.name, batch.getChild(field4.name)?.get(0));
|
|
9337
|
-
} catch {}
|
|
9338
|
-
}
|
|
9339
|
-
} catch {}
|
|
9340
|
-
}
|
|
9341
|
-
const schema4 = readSchemaSafe(m.arguments_schema);
|
|
9342
|
-
const fields = schema4 ? schema4.fields : null;
|
|
9343
|
-
const fieldByName = new Map;
|
|
9344
|
-
if (fields)
|
|
9345
|
-
for (const f of fields)
|
|
9346
|
-
fieldByName.set(f.name, f);
|
|
9347
|
-
const names = fields ? fields.map((f) => f.name) : m.parameters;
|
|
9348
|
-
const args = [];
|
|
9349
|
-
for (const name of names) {
|
|
9350
|
-
const field4 = fieldByName.get(name);
|
|
9351
|
-
const arg = field4 !== undefined && !isNull(field4.type) ? { name, type: arrowTypeString(field4.type) } : { name, type: "ANY" };
|
|
9352
|
-
const doc = field4 !== undefined ? fieldMeta(field4, VGI_DOC_KEY) : undefined;
|
|
9353
|
-
if (doc)
|
|
9354
|
-
arg.desc = doc;
|
|
9355
|
-
if (defaults.has(name)) {
|
|
9356
|
-
arg.named = true;
|
|
9357
|
-
arg.default = macroDefaultJson(defaults.get(name));
|
|
9358
|
-
}
|
|
9359
|
-
args.push(arg);
|
|
9360
|
-
}
|
|
9361
|
-
return args;
|
|
9362
|
-
}
|
|
9363
|
-
function macroToObject(m) {
|
|
9364
|
-
return {
|
|
9365
|
-
name: m.name,
|
|
9366
|
-
type: macroDisplayType(m),
|
|
9367
|
-
doc: m.comment ?? "",
|
|
9368
|
-
args: macroArgs(m)
|
|
9369
|
-
};
|
|
9370
|
-
}
|
|
9371
|
-
async function schemaContents(iface, aod, name, kind) {
|
|
9372
|
-
try {
|
|
9373
|
-
if (kind === "TABLE") {
|
|
9374
|
-
return await iface.schemaContentsTables(aod, name);
|
|
9375
|
-
}
|
|
9376
|
-
return await iface.schemaContentsViews(aod, name);
|
|
9377
|
-
} catch {
|
|
9378
|
-
return [];
|
|
9379
|
-
}
|
|
9380
|
-
}
|
|
9381
|
-
async function schemaFunctions(iface, aod, name) {
|
|
9382
|
-
const out = [];
|
|
9383
|
-
for (const kind of ["SCALAR_FUNCTION", "TABLE_FUNCTION", "AGGREGATE_FUNCTION"]) {
|
|
9384
|
-
try {
|
|
9385
|
-
out.push(...await iface.schemaContentsFunctions(aod, name, kind));
|
|
9386
|
-
} catch {}
|
|
9387
|
-
}
|
|
9388
|
-
return out;
|
|
9389
|
-
}
|
|
9390
|
-
async function schemaMacros(iface, aod, name) {
|
|
9391
|
-
const out = [];
|
|
9392
|
-
for (const kind of ["SCALAR_MACRO", "TABLE_MACRO"]) {
|
|
9393
|
-
try {
|
|
9394
|
-
out.push(...await iface.schemaContentsMacros(aod, name, kind));
|
|
9395
|
-
} catch {}
|
|
9396
|
-
}
|
|
9397
|
-
return out;
|
|
9398
|
-
}
|
|
9399
|
-
async function buildSchemas(iface, aod) {
|
|
9400
|
-
let schemaInfos;
|
|
9401
|
-
try {
|
|
9402
|
-
schemaInfos = await iface.schemas(aod);
|
|
9403
|
-
} catch {
|
|
9404
|
-
return { schemas: [], counts: { schemas: 0, tables: 0, views: 0, functions: 0 } };
|
|
9405
|
-
}
|
|
9406
|
-
const schemas = [];
|
|
9407
|
-
const counts = { schemas: 0, tables: 0, views: 0, functions: 0 };
|
|
9408
|
-
for (const si of schemaInfos) {
|
|
9409
|
-
const tablesRaw = await schemaContents(iface, aod, si.name, "TABLE");
|
|
9410
|
-
const viewsRaw = await schemaContents(iface, aod, si.name, "VIEW");
|
|
9411
|
-
const funcsRaw = await schemaFunctions(iface, aod, si.name);
|
|
9412
|
-
const macrosRaw = await schemaMacros(iface, aod, si.name);
|
|
9413
|
-
const tables = tablesRaw.map((t) => {
|
|
9414
|
-
const schema4 = readSchemaSafe(t.columns);
|
|
9415
|
-
return { name: t.name, cols: schema4 ? schema4.fields.length : 0, comment: t.comment ?? "" };
|
|
9416
|
-
});
|
|
9417
|
-
const views = viewsRaw.map((v) => ({
|
|
9418
|
-
name: v.name,
|
|
9419
|
-
cols: Object.keys(v.column_comments ?? {}).length,
|
|
9420
|
-
comment: v.comment ?? "",
|
|
9421
|
-
def: v.definition
|
|
9422
|
-
}));
|
|
9423
|
-
const functions = funcsRaw.map((fn) => {
|
|
9424
|
-
const obj = {
|
|
9425
|
-
name: fn.name,
|
|
9426
|
-
type: functionDisplayType(fn),
|
|
9427
|
-
doc: fn.description ?? "",
|
|
9428
|
-
args: functionArgs(fn)
|
|
9429
|
-
};
|
|
9430
|
-
const ret = functionReturns(fn);
|
|
9431
|
-
if (ret)
|
|
9432
|
-
obj.returns = ret;
|
|
9433
|
-
return obj;
|
|
9434
|
-
});
|
|
9435
|
-
functions.push(...macrosRaw.map((m) => macroToObject(m)));
|
|
9436
|
-
functions.sort((a, b) => String(a.type).localeCompare(String(b.type)) || String(a.name).localeCompare(String(b.name)));
|
|
9437
|
-
const schemaObj = { name: si.name };
|
|
9438
|
-
if (si.comment)
|
|
9439
|
-
schemaObj.doc = si.comment;
|
|
9440
|
-
schemaObj.tables = tables;
|
|
9441
|
-
schemaObj.views = views;
|
|
9442
|
-
schemaObj.functions = functions;
|
|
9443
|
-
schemas.push(schemaObj);
|
|
9444
|
-
counts.schemas += 1;
|
|
9445
|
-
counts.tables += tables.length;
|
|
9446
|
-
counts.views += views.length;
|
|
9447
|
-
counts.functions += functions.length;
|
|
9448
|
-
}
|
|
9449
|
-
return { schemas, counts };
|
|
9450
|
-
}
|
|
9451
|
-
function catalogTags(result) {
|
|
9452
|
-
const tags = result?.tags;
|
|
9453
|
-
if (!tags)
|
|
9454
|
-
return {};
|
|
9455
|
-
const out = {};
|
|
9456
|
-
for (const [key, tag] of Object.entries(STRING_TAGS)) {
|
|
9457
|
-
const val = tags[tag];
|
|
9458
|
-
if (val)
|
|
9459
|
-
out[key] = val;
|
|
9460
|
-
}
|
|
9461
|
-
const kw = tags[KEYWORDS_TAG];
|
|
9462
|
-
if (kw) {
|
|
9463
|
-
try {
|
|
9464
|
-
const parsed = JSON.parse(kw);
|
|
9465
|
-
if (Array.isArray(parsed))
|
|
9466
|
-
out.keywords = parsed.map((k) => String(k));
|
|
9467
|
-
} catch {}
|
|
9468
|
-
}
|
|
9469
|
-
return out;
|
|
9470
|
-
}
|
|
9471
|
-
function decodeAttachOption(bytes2) {
|
|
9472
|
-
try {
|
|
9473
|
-
const batch = deserializeBatch(bytes2);
|
|
9474
|
-
if (batch.numRows === 0)
|
|
9475
|
-
return null;
|
|
9476
|
-
const name = String(batch.getChild("name")?.get(0) ?? "");
|
|
9477
|
-
const description = String(batch.getChild("description")?.get(0) ?? "");
|
|
9478
|
-
const typeBytes = batch.getChild("type")?.get(0);
|
|
9479
|
-
let type = "";
|
|
9480
|
-
const typeSchema = readSchemaSafe(typeBytes ?? null);
|
|
9481
|
-
if (typeSchema && typeSchema.fields.length > 0)
|
|
9482
|
-
type = typeToString(typeSchema.fields[0].type);
|
|
9483
|
-
let defaultStr = "";
|
|
9484
|
-
const defBytes = batch.getChild("default_value")?.get(0);
|
|
9485
|
-
if (defBytes) {
|
|
9486
|
-
try {
|
|
9487
|
-
const defBatch = deserializeBatch(defBytes);
|
|
9488
|
-
if (defBatch.numRows > 0) {
|
|
9489
|
-
const v = defBatch.getChild("value")?.get(0);
|
|
9490
|
-
defaultStr = v == null ? "" : String(v);
|
|
9491
|
-
}
|
|
9492
|
-
} catch {}
|
|
9493
|
-
}
|
|
9494
|
-
return { name, type, default: defaultStr, description };
|
|
9495
|
-
} catch {
|
|
9496
|
-
return null;
|
|
9497
|
-
}
|
|
9498
|
-
}
|
|
9499
|
-
async function attachCatalog(iface, name) {
|
|
9500
|
-
try {
|
|
9501
|
-
return await iface.attach(name, {}, null, null);
|
|
9502
|
-
} catch {
|
|
9503
|
-
return null;
|
|
9504
|
-
}
|
|
9505
|
-
}
|
|
9506
|
-
async function buildCatalog(iface, name, info) {
|
|
9507
|
-
const result = await attachCatalog(iface, name);
|
|
9508
|
-
const attachOptions = (info?.attach_option_specs ?? []).map((b) => decodeAttachOption(b)).filter((o) => o !== null);
|
|
9509
|
-
const dataVersions = (info?.releases ?? []).map((r) => r.summary ? { spec: r.version, label: r.summary } : { spec: r.version });
|
|
9510
|
-
let impl = info?.implementation_version ?? null;
|
|
9511
|
-
let dvs = info?.data_version_spec ?? null;
|
|
9512
|
-
if (result) {
|
|
9513
|
-
impl = result.resolved_implementation_version ?? impl;
|
|
9514
|
-
dvs = result.resolved_data_version ?? dvs;
|
|
9515
|
-
}
|
|
9516
|
-
let schemas = [];
|
|
9517
|
-
let counts = { schemas: 0, tables: 0, views: 0, functions: 0 };
|
|
9518
|
-
if (result) {
|
|
9519
|
-
const built = await buildSchemas(iface, result.attach_opaque_data);
|
|
9520
|
-
schemas = built.schemas;
|
|
9521
|
-
counts = built.counts;
|
|
9522
|
-
}
|
|
9523
|
-
return {
|
|
9524
|
-
name,
|
|
9525
|
-
implementation_version: impl,
|
|
9526
|
-
data_version_spec: dvs,
|
|
9527
|
-
data_versions: dataVersions,
|
|
9528
|
-
attach_options: attachOptions,
|
|
9529
|
-
tags: catalogTags(result),
|
|
9530
|
-
counts,
|
|
9531
|
-
schemas
|
|
9532
|
-
};
|
|
9533
|
-
}
|
|
9534
|
-
async function catalogInfoByName(iface) {
|
|
9535
|
-
const map4 = new Map;
|
|
9536
|
-
if (typeof iface.catalogsInfo === "function") {
|
|
9537
|
-
try {
|
|
9538
|
-
const infos = await iface.catalogsInfo();
|
|
9539
|
-
for (const info of infos)
|
|
9540
|
-
map4.set(info.name, info);
|
|
9541
|
-
} catch {}
|
|
9542
|
-
}
|
|
9543
|
-
return map4;
|
|
9544
|
-
}
|
|
9545
|
-
async function buildDescribeJson2(iface, worker, opts = {}) {
|
|
9546
|
-
const infos = await catalogInfoByName(iface);
|
|
9547
|
-
let names;
|
|
9548
|
-
try {
|
|
9549
|
-
names = iface.catalogs();
|
|
9550
|
-
} catch {
|
|
9551
|
-
names = [];
|
|
9552
|
-
}
|
|
9553
|
-
const catalogs = [];
|
|
9554
|
-
for (const name of names) {
|
|
9555
|
-
catalogs.push(await buildCatalog(iface, name, infos.get(name)));
|
|
9556
|
-
}
|
|
9557
|
-
return {
|
|
9558
|
-
landing_schema_version: LANDING_SCHEMA_VERSION2,
|
|
9559
|
-
worker: {
|
|
9560
|
-
name: worker.name,
|
|
9561
|
-
doc: worker.doc ?? "",
|
|
9562
|
-
version: worker.version ?? "unknown",
|
|
9563
|
-
lang: "typescript"
|
|
9564
|
-
},
|
|
9565
|
-
server_id: opts.serverId ?? "",
|
|
9566
|
-
oauth: opts.oauth ?? false,
|
|
9567
|
-
cupola_base: opts.cupolaBase ?? CUPOLA_BASE2,
|
|
9568
|
-
catalogs
|
|
9569
|
-
};
|
|
9570
|
-
}
|
|
9571
|
-
async function buildColumnsJson2(iface, catalog, schema4, table) {
|
|
9572
|
-
const result = await attachCatalog(iface, catalog);
|
|
9573
|
-
if (!result)
|
|
9574
|
-
return null;
|
|
9575
|
-
const aod = result.attach_opaque_data;
|
|
9576
|
-
const tables = await schemaContents(iface, aod, schema4, "TABLE");
|
|
9577
|
-
for (const t of tables) {
|
|
9578
|
-
if (t.name === table) {
|
|
9579
|
-
const arrow = readSchemaSafe(t.columns);
|
|
9580
|
-
return { columns: (arrow?.fields ?? []).map((f) => fieldToColumn(f)) };
|
|
9581
|
-
}
|
|
9582
|
-
}
|
|
9583
|
-
const views = await schemaContents(iface, aod, schema4, "VIEW");
|
|
9584
|
-
for (const v of views) {
|
|
9585
|
-
if (v.name === table) {
|
|
9586
|
-
return {
|
|
9587
|
-
columns: Object.entries(v.column_comments ?? {}).map(([name, comment]) => ({
|
|
9588
|
-
name,
|
|
9589
|
-
type: "",
|
|
9590
|
-
comment
|
|
9591
|
-
}))
|
|
9592
|
-
};
|
|
9593
|
-
}
|
|
9594
|
-
}
|
|
9595
|
-
return null;
|
|
9596
|
-
}
|
|
9597
|
-
function createLandingDescribe2(iface, worker, opts = {}) {
|
|
9598
|
-
return {
|
|
9599
|
-
describe: (ctx) => buildDescribeJson2(iface, worker, { ...ctx, cupolaBase: opts.cupolaBase }),
|
|
9600
|
-
columns: (catalog, schema4, table) => buildColumnsJson2(iface, catalog, schema4, table)
|
|
9601
|
-
};
|
|
9602
|
-
}
|
|
9603
|
-
|
|
9604
9220
|
// src/worker-cf-entry.ts
|
|
9605
9221
|
init_arrow();
|
|
9606
9222
|
import { OutputCollector as OutputCollector2, AuthContext as AuthContext2 } from "@query-farm/vgi-rpc";
|
|
@@ -9683,7 +9299,6 @@ export {
|
|
|
9683
9299
|
dateDay2 as dateDay,
|
|
9684
9300
|
date2 as date,
|
|
9685
9301
|
createVgiFetch,
|
|
9686
|
-
createLandingDescribe2 as createLandingDescribe,
|
|
9687
9302
|
columnFromArray,
|
|
9688
9303
|
buildStatisticsBatch,
|
|
9689
9304
|
bool2 as bool,
|
|
@@ -9712,4 +9327,4 @@ export {
|
|
|
9712
9327
|
Arguments
|
|
9713
9328
|
};
|
|
9714
9329
|
|
|
9715
|
-
//# debugId=
|
|
9330
|
+
//# debugId=3225E125CCD893FA64756E2164756E21
|