@query-farm/vgi 0.43.0 → 0.45.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -2
- package/dist/arrow/impl-arrowjs/index.d.ts +1 -1
- package/dist/arrow/impl-arrowjs/ipc.d.ts +6 -0
- package/dist/arrow/impl-flechette/build.d.ts +2 -2
- package/dist/arrow/impl-flechette/canonical.d.ts +1 -1
- package/dist/arrow/impl-flechette/index.d.ts +1 -1
- package/dist/arrow/impl-flechette/ipc.d.ts +6 -0
- package/dist/arrow/index.d.ts +1 -1
- package/dist/attach-ticket.d.ts +18 -7
- package/dist/catalog/contents-codec.d.ts +7 -0
- package/dist/catalog/contents-digest.d.ts +2 -1
- package/dist/catalog/interface.d.ts +3 -0
- package/dist/catalog/publication-envelope.d.ts +1 -0
- package/dist/catalog/publication.d.ts +142 -0
- package/dist/catalog/s3-publication.d.ts +38 -0
- package/dist/client-entry.js +349 -114
- package/dist/client-entry.js.map +16 -14
- package/dist/codec/asd.d.ts +7 -1
- package/dist/codec/conform.d.ts +51 -0
- package/dist/errors.d.ts +5 -1
- package/dist/generated/vgi-client.d.ts +6 -14
- package/dist/generated/vgi-protocol-schemas.d.ts +2 -0
- package/dist/generated/vgi-protocol-types.d.ts +26 -3
- package/dist/generated/vgi-service.d.ts +3 -3
- package/dist/index.core.d.ts +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.js +955 -118
- package/dist/index.js.map +33 -28
- package/dist/protocol/dispatch.d.ts +1 -1
- package/dist/protocol/handlers/catalog/contents.d.ts +4 -4
- package/dist/protocol/handlers/shared.d.ts +2 -1
- package/dist/protocol/serializers/shared.d.ts +2 -1
- package/dist/rpc-server.d.ts +2 -2
- package/dist/serve-entry.js +867 -165
- package/dist/serve-entry.js.map +26 -22
- package/dist/worker-cf-entry.js +825 -114
- package/dist/worker-cf-entry.js.map +31 -27
- package/package.json +3 -3
- package/src/arrow/impl-arrowjs/index.ts +1 -0
- package/src/arrow/impl-arrowjs/ipc.ts +23 -0
- package/src/arrow/impl-flechette/build.ts +4 -2
- package/src/arrow/impl-flechette/canonical.ts +7 -2
- package/src/arrow/impl-flechette/index.ts +1 -0
- package/src/arrow/impl-flechette/ipc.ts +19 -0
- package/src/arrow/index.ts +1 -1
- package/src/attach-ticket.ts +41 -13
- package/src/catalog/composite.ts +2 -1
- package/src/catalog/contents-codec.ts +77 -0
- package/src/catalog/contents-digest.ts +20 -17
- package/src/catalog/interface.ts +8 -4
- package/src/catalog/publication-envelope.ts +62 -0
- package/src/catalog/publication.ts +290 -0
- package/src/catalog/read-only.ts +8 -8
- package/src/catalog/s3-publication.ts +81 -0
- package/src/client/client.ts +15 -24
- package/src/codec/asd.ts +45 -3
- package/src/codec/conform.ts +194 -0
- package/src/errors.ts +27 -7
- package/src/functions/registry.ts +3 -2
- package/src/generated/vgi-client.ts +7 -16
- package/src/generated/vgi-protocol-schemas.ts +13 -6
- package/src/generated/vgi-protocol-types.ts +39 -5
- package/src/generated/vgi-service.ts +4 -3
- package/src/http/fetch.ts +1 -1
- package/src/index.core.ts +3 -1
- package/src/index.ts +5 -0
- package/src/protocol/dispatch.ts +1 -1
- package/src/protocol/handlers/catalog/admin.ts +7 -4
- package/src/protocol/handlers/catalog/contents.ts +50 -35
- package/src/protocol/handlers/shared.ts +8 -2
- package/src/protocol/serializers/bind.ts +3 -1
- package/src/protocol/serializers/shared.ts +5 -2
- package/src/rpc-server.ts +7 -7
package/dist/client-entry.js
CHANGED
|
@@ -13,6 +13,82 @@ var __export = (target, all) => {
|
|
|
13
13
|
});
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
+
// src/arrow/impl-arrowjs/index.ts
|
|
17
|
+
var exports_impl_arrowjs = {};
|
|
18
|
+
__export(exports_impl_arrowjs, {
|
|
19
|
+
DateUnit: () => DateUnit,
|
|
20
|
+
IntervalUnit: () => IntervalUnit,
|
|
21
|
+
TimeUnit: () => TimeUnit,
|
|
22
|
+
UnionMode: () => UnionMode,
|
|
23
|
+
adoptArrowJsShape: () => adoptArrowJsShape,
|
|
24
|
+
backend: () => backend,
|
|
25
|
+
batchFromColumns: () => batchFromColumns,
|
|
26
|
+
batchFromRows: () => batchFromRows,
|
|
27
|
+
batchToScalarDict: () => batchToScalarDict,
|
|
28
|
+
batchToSecretDict: () => batchToSecretDict,
|
|
29
|
+
binary: () => binary,
|
|
30
|
+
bool: () => bool,
|
|
31
|
+
buildStatisticsBatch: () => buildStatisticsBatch,
|
|
32
|
+
columnFromArray: () => columnFromArray,
|
|
33
|
+
date: () => date,
|
|
34
|
+
dateDay: () => dateDay,
|
|
35
|
+
dateMillisecond: () => dateMillisecond,
|
|
36
|
+
decimal: () => decimal,
|
|
37
|
+
decimal128: () => decimal128,
|
|
38
|
+
decimal256: () => decimal256,
|
|
39
|
+
decodeDictValue: () => decodeDictValue,
|
|
40
|
+
denseUnion: () => denseUnion,
|
|
41
|
+
deserializeBatch: () => deserializeBatch,
|
|
42
|
+
deserializeBatches: () => deserializeBatches,
|
|
43
|
+
deserializeSchema: () => deserializeSchema,
|
|
44
|
+
dictionary: () => dictionary,
|
|
45
|
+
duration: () => duration,
|
|
46
|
+
emptyBatch: () => emptyBatch,
|
|
47
|
+
field: () => field,
|
|
48
|
+
filterBatch: () => filterBatch,
|
|
49
|
+
fixedSizeBinary: () => fixedSizeBinary,
|
|
50
|
+
fixedSizeList: () => fixedSizeList,
|
|
51
|
+
float16: () => float16,
|
|
52
|
+
float32: () => float32,
|
|
53
|
+
float64: () => float64,
|
|
54
|
+
int: () => int,
|
|
55
|
+
int16: () => int16,
|
|
56
|
+
int32: () => int32,
|
|
57
|
+
int64: () => int64,
|
|
58
|
+
int8: () => int8,
|
|
59
|
+
interval: () => interval,
|
|
60
|
+
iterRows: () => iterRows,
|
|
61
|
+
largeBinary: () => largeBinary,
|
|
62
|
+
largeUtf8: () => largeUtf8,
|
|
63
|
+
list: () => list,
|
|
64
|
+
map: () => map,
|
|
65
|
+
nullType: () => nullType,
|
|
66
|
+
projectBatch: () => projectBatch,
|
|
67
|
+
projectSchema: () => projectSchema,
|
|
68
|
+
readCanonicalValue: () => readCanonicalValue,
|
|
69
|
+
safeNumber: () => safeNumber,
|
|
70
|
+
schema: () => schema,
|
|
71
|
+
serializeBatch: () => serializeBatch,
|
|
72
|
+
serializeBatches: () => serializeBatches,
|
|
73
|
+
serializeCollectionRows: () => serializeCollectionRows,
|
|
74
|
+
serializeSchema: () => serializeSchema,
|
|
75
|
+
sparseUnion: () => sparseUnion,
|
|
76
|
+
struct: () => struct,
|
|
77
|
+
time: () => time,
|
|
78
|
+
timeMicrosecond: () => timeMicrosecond,
|
|
79
|
+
timeMillisecond: () => timeMillisecond,
|
|
80
|
+
timeNanosecond: () => timeNanosecond,
|
|
81
|
+
timeSecond: () => timeSecond,
|
|
82
|
+
timestamp: () => timestamp,
|
|
83
|
+
uint16: () => uint16,
|
|
84
|
+
uint32: () => uint32,
|
|
85
|
+
uint64: () => uint64,
|
|
86
|
+
uint8: () => uint8,
|
|
87
|
+
union: () => union,
|
|
88
|
+
utf8: () => utf8,
|
|
89
|
+
withBatchMetadata: () => withBatchMetadata
|
|
90
|
+
});
|
|
91
|
+
|
|
16
92
|
// src/arrow/predicates.ts
|
|
17
93
|
var TypeId = {
|
|
18
94
|
Null: 1,
|
|
@@ -40,9 +116,15 @@ var TypeId = {
|
|
|
40
116
|
function isInt(t) {
|
|
41
117
|
return t.typeId === TypeId.Int;
|
|
42
118
|
}
|
|
119
|
+
function isFloat(t) {
|
|
120
|
+
return t.typeId === TypeId.Float;
|
|
121
|
+
}
|
|
43
122
|
function isBinary(t) {
|
|
44
123
|
return t.typeId === TypeId.Binary || t.typeId === TypeId.LargeBinary;
|
|
45
124
|
}
|
|
125
|
+
function isUtf8(t) {
|
|
126
|
+
return t.typeId === TypeId.Utf8 || t.typeId === TypeId.LargeUtf8;
|
|
127
|
+
}
|
|
46
128
|
function isBool(t) {
|
|
47
129
|
return t.typeId === TypeId.Bool;
|
|
48
130
|
}
|
|
@@ -94,79 +176,6 @@ function typeSignature(t) {
|
|
|
94
176
|
return Array.isArray(a.children) ? `${t.typeId}<${kids()}>` : String(t.typeId);
|
|
95
177
|
}
|
|
96
178
|
}
|
|
97
|
-
// src/arrow/impl-arrowjs/index.ts
|
|
98
|
-
var exports_impl_arrowjs = {};
|
|
99
|
-
__export(exports_impl_arrowjs, {
|
|
100
|
-
DateUnit: () => DateUnit,
|
|
101
|
-
IntervalUnit: () => IntervalUnit,
|
|
102
|
-
TimeUnit: () => TimeUnit,
|
|
103
|
-
UnionMode: () => UnionMode,
|
|
104
|
-
adoptArrowJsShape: () => adoptArrowJsShape,
|
|
105
|
-
backend: () => backend,
|
|
106
|
-
batchFromColumns: () => batchFromColumns,
|
|
107
|
-
batchFromRows: () => batchFromRows,
|
|
108
|
-
batchToScalarDict: () => batchToScalarDict,
|
|
109
|
-
batchToSecretDict: () => batchToSecretDict,
|
|
110
|
-
binary: () => binary,
|
|
111
|
-
bool: () => bool,
|
|
112
|
-
buildStatisticsBatch: () => buildStatisticsBatch,
|
|
113
|
-
columnFromArray: () => columnFromArray,
|
|
114
|
-
date: () => date,
|
|
115
|
-
dateDay: () => dateDay,
|
|
116
|
-
dateMillisecond: () => dateMillisecond,
|
|
117
|
-
decimal: () => decimal,
|
|
118
|
-
decimal128: () => decimal128,
|
|
119
|
-
decimal256: () => decimal256,
|
|
120
|
-
decodeDictValue: () => decodeDictValue,
|
|
121
|
-
denseUnion: () => denseUnion,
|
|
122
|
-
deserializeBatch: () => deserializeBatch,
|
|
123
|
-
deserializeSchema: () => deserializeSchema,
|
|
124
|
-
dictionary: () => dictionary,
|
|
125
|
-
duration: () => duration,
|
|
126
|
-
emptyBatch: () => emptyBatch,
|
|
127
|
-
field: () => field,
|
|
128
|
-
filterBatch: () => filterBatch,
|
|
129
|
-
fixedSizeBinary: () => fixedSizeBinary,
|
|
130
|
-
fixedSizeList: () => fixedSizeList,
|
|
131
|
-
float16: () => float16,
|
|
132
|
-
float32: () => float32,
|
|
133
|
-
float64: () => float64,
|
|
134
|
-
int: () => int,
|
|
135
|
-
int16: () => int16,
|
|
136
|
-
int32: () => int32,
|
|
137
|
-
int64: () => int64,
|
|
138
|
-
int8: () => int8,
|
|
139
|
-
interval: () => interval,
|
|
140
|
-
iterRows: () => iterRows,
|
|
141
|
-
largeBinary: () => largeBinary,
|
|
142
|
-
largeUtf8: () => largeUtf8,
|
|
143
|
-
list: () => list,
|
|
144
|
-
map: () => map,
|
|
145
|
-
nullType: () => nullType,
|
|
146
|
-
projectBatch: () => projectBatch,
|
|
147
|
-
projectSchema: () => projectSchema,
|
|
148
|
-
readCanonicalValue: () => readCanonicalValue,
|
|
149
|
-
safeNumber: () => safeNumber,
|
|
150
|
-
schema: () => schema,
|
|
151
|
-
serializeBatch: () => serializeBatch,
|
|
152
|
-
serializeSchema: () => serializeSchema,
|
|
153
|
-
sparseUnion: () => sparseUnion,
|
|
154
|
-
struct: () => struct,
|
|
155
|
-
time: () => time,
|
|
156
|
-
timeMicrosecond: () => timeMicrosecond,
|
|
157
|
-
timeMillisecond: () => timeMillisecond,
|
|
158
|
-
timeNanosecond: () => timeNanosecond,
|
|
159
|
-
timeSecond: () => timeSecond,
|
|
160
|
-
timestamp: () => timestamp,
|
|
161
|
-
uint16: () => uint16,
|
|
162
|
-
uint32: () => uint32,
|
|
163
|
-
uint64: () => uint64,
|
|
164
|
-
uint8: () => uint8,
|
|
165
|
-
union: () => union,
|
|
166
|
-
utf8: () => utf8,
|
|
167
|
-
withBatchMetadata: () => withBatchMetadata
|
|
168
|
-
});
|
|
169
|
-
|
|
170
179
|
// src/arrow/impl-arrowjs/schema.ts
|
|
171
180
|
import {
|
|
172
181
|
Schema as A_Schema,
|
|
@@ -1726,6 +1735,24 @@ function deserializeBatch(bytes) {
|
|
|
1726
1735
|
}
|
|
1727
1736
|
return batches[0];
|
|
1728
1737
|
}
|
|
1738
|
+
function deserializeBatches(bytes) {
|
|
1739
|
+
return [...RecordBatchReader.from(bytes)];
|
|
1740
|
+
}
|
|
1741
|
+
function serializeBatches(batches, schema) {
|
|
1742
|
+
const writer = new RecordBatchStreamWriter;
|
|
1743
|
+
writer.reset(undefined, schema);
|
|
1744
|
+
for (const batch of batches)
|
|
1745
|
+
writer._writeRecordBatch(batch);
|
|
1746
|
+
writer.close();
|
|
1747
|
+
return writer.toUint8Array(true);
|
|
1748
|
+
}
|
|
1749
|
+
function serializeCollectionRows(schema, rows, maxBatchRows) {
|
|
1750
|
+
const batch = batchFromRows(rows, schema);
|
|
1751
|
+
const batches = [];
|
|
1752
|
+
for (let offset = 0;offset < batch.numRows; offset += maxBatchRows)
|
|
1753
|
+
batches.push(batch.slice(offset, offset + maxBatchRows));
|
|
1754
|
+
return serializeBatches(batches, schema);
|
|
1755
|
+
}
|
|
1729
1756
|
// src/arrow/impl-arrowjs/statistics.ts
|
|
1730
1757
|
import {
|
|
1731
1758
|
Field as Field3,
|
|
@@ -2073,6 +2100,118 @@ function toUint8Array(val) {
|
|
|
2073
2100
|
return new Uint8Array(0);
|
|
2074
2101
|
}
|
|
2075
2102
|
|
|
2103
|
+
// src/codec/conform.ts
|
|
2104
|
+
var OPTIONAL_ITEM_FIELDS = new Set(["argument_names"]);
|
|
2105
|
+
function children(type) {
|
|
2106
|
+
return type.children ?? [];
|
|
2107
|
+
}
|
|
2108
|
+
function mapValueType(type) {
|
|
2109
|
+
const entries = children(type)[0].type;
|
|
2110
|
+
return children(entries)[1].type;
|
|
2111
|
+
}
|
|
2112
|
+
function mapPairs(raw) {
|
|
2113
|
+
if (Array.isArray(raw))
|
|
2114
|
+
return raw.map((e) => Array.isArray(e) ? [e[0], e[1]] : [e?.key, e?.value]);
|
|
2115
|
+
if (raw instanceof Map)
|
|
2116
|
+
return Array.from(raw.entries());
|
|
2117
|
+
if (typeof raw[Symbol.iterator] === "function")
|
|
2118
|
+
return Array.from(raw);
|
|
2119
|
+
return Object.entries(raw);
|
|
2120
|
+
}
|
|
2121
|
+
function zeroValue(type) {
|
|
2122
|
+
if (isDictionary(type))
|
|
2123
|
+
return zeroValue(type.dictionary);
|
|
2124
|
+
if (isUtf8(type))
|
|
2125
|
+
return "";
|
|
2126
|
+
if (isBinary(type))
|
|
2127
|
+
return new Uint8Array(0);
|
|
2128
|
+
if (isBool(type))
|
|
2129
|
+
return false;
|
|
2130
|
+
if (isInt(type))
|
|
2131
|
+
return type.bitWidth === 64 ? 0n : 0;
|
|
2132
|
+
if (isFloat(type))
|
|
2133
|
+
return 0;
|
|
2134
|
+
if (isList(type) || isMap(type))
|
|
2135
|
+
return [];
|
|
2136
|
+
if (isStruct(type)) {
|
|
2137
|
+
const out = {};
|
|
2138
|
+
for (const c of children(type))
|
|
2139
|
+
out[c.name] = c.nullable ? null : conformValue(c.type, undefined, false, c.name);
|
|
2140
|
+
return out;
|
|
2141
|
+
}
|
|
2142
|
+
return null;
|
|
2143
|
+
}
|
|
2144
|
+
var HAS_CONTAINER = new WeakMap;
|
|
2145
|
+
function hasContainer(type) {
|
|
2146
|
+
const cached = HAS_CONTAINER.get(type);
|
|
2147
|
+
if (cached !== undefined)
|
|
2148
|
+
return cached;
|
|
2149
|
+
let has = isList(type) || isMap(type);
|
|
2150
|
+
if (!has && isStruct(type))
|
|
2151
|
+
has = children(type).some((c) => hasContainer(c.type));
|
|
2152
|
+
HAS_CONTAINER.set(type, has);
|
|
2153
|
+
return has;
|
|
2154
|
+
}
|
|
2155
|
+
function conformValue(type, value, nullable, name) {
|
|
2156
|
+
if (value == null) {
|
|
2157
|
+
if (nullable)
|
|
2158
|
+
return value ?? null;
|
|
2159
|
+
if (isList(type) || isMap(type))
|
|
2160
|
+
return [];
|
|
2161
|
+
return value;
|
|
2162
|
+
}
|
|
2163
|
+
if (!hasContainer(type))
|
|
2164
|
+
return value;
|
|
2165
|
+
if (isList(type)) {
|
|
2166
|
+
const itemType = children(type)[0].type;
|
|
2167
|
+
const itemsNullable = OPTIONAL_ITEM_FIELDS.has(name);
|
|
2168
|
+
const items = Array.isArray(value) ? value : Array.from(value);
|
|
2169
|
+
let changed = !Array.isArray(value);
|
|
2170
|
+
const out = items.map((item) => {
|
|
2171
|
+
const next = item == null && !itemsNullable ? zeroValue(itemType) : conformValue(itemType, item, true, name);
|
|
2172
|
+
if (next !== item)
|
|
2173
|
+
changed = true;
|
|
2174
|
+
return next;
|
|
2175
|
+
});
|
|
2176
|
+
return changed ? out : value;
|
|
2177
|
+
}
|
|
2178
|
+
if (isMap(type)) {
|
|
2179
|
+
const valueType = mapValueType(type);
|
|
2180
|
+
const pairs = mapPairs(value);
|
|
2181
|
+
let changed = false;
|
|
2182
|
+
const out = pairs.map(([k, v]) => {
|
|
2183
|
+
const next = v == null ? zeroValue(valueType) : conformValue(valueType, v, true, name);
|
|
2184
|
+
if (next !== v)
|
|
2185
|
+
changed = true;
|
|
2186
|
+
return [k, next];
|
|
2187
|
+
});
|
|
2188
|
+
return changed ? out : value;
|
|
2189
|
+
}
|
|
2190
|
+
if (isStruct(type)) {
|
|
2191
|
+
let out = null;
|
|
2192
|
+
for (const c of children(type)) {
|
|
2193
|
+
const v = value[c.name];
|
|
2194
|
+
const next = conformValue(c.type, v, c.nullable, c.name);
|
|
2195
|
+
if (next !== v) {
|
|
2196
|
+
(out ??= { ...value })[c.name] = next;
|
|
2197
|
+
}
|
|
2198
|
+
}
|
|
2199
|
+
return out ?? value;
|
|
2200
|
+
}
|
|
2201
|
+
return value;
|
|
2202
|
+
}
|
|
2203
|
+
function conformRecord(schema, obj) {
|
|
2204
|
+
let out = null;
|
|
2205
|
+
for (const f of schema.fields) {
|
|
2206
|
+
const v = obj[f.name];
|
|
2207
|
+
const next = conformValue(f.type, v, f.nullable, f.name);
|
|
2208
|
+
if (next !== v) {
|
|
2209
|
+
(out ??= { ...obj })[f.name] = next;
|
|
2210
|
+
}
|
|
2211
|
+
}
|
|
2212
|
+
return out ?? obj;
|
|
2213
|
+
}
|
|
2214
|
+
|
|
2076
2215
|
// src/protocol/serializers/shared.ts
|
|
2077
2216
|
function toUint8Array2(val) {
|
|
2078
2217
|
if (typeof val === "string")
|
|
@@ -2085,8 +2224,9 @@ function toUint8Array2(val) {
|
|
|
2085
2224
|
}
|
|
2086
2225
|
function buildSingleRowBatch(schema, values) {
|
|
2087
2226
|
const cols = {};
|
|
2227
|
+
const row = conformRecord(schema, values);
|
|
2088
2228
|
for (const f of schema.fields) {
|
|
2089
|
-
let val =
|
|
2229
|
+
let val = row[f.name];
|
|
2090
2230
|
if (isInt(f.type) && f.type.bitWidth === 64 && typeof val === "number") {
|
|
2091
2231
|
val = BigInt(val);
|
|
2092
2232
|
}
|
|
@@ -2126,7 +2266,7 @@ function serializeBindRequest(req) {
|
|
|
2126
2266
|
return buildSingleRowBatch(BIND_REQUEST_SCHEMA, {
|
|
2127
2267
|
function_name: req.function_name,
|
|
2128
2268
|
arguments: serializeArguments(req.arguments),
|
|
2129
|
-
function_type: req.function_type,
|
|
2269
|
+
function_type: req.function_type == null ? req.function_type : String(req.function_type).toUpperCase(),
|
|
2130
2270
|
input_schema: req.input_schema ? serializeSchema(req.input_schema) : null,
|
|
2131
2271
|
settings: req.settings ? serializeBatch(req.settings) : null,
|
|
2132
2272
|
secrets: req.secrets ? serializeBatch(req.secrets) : null,
|
|
@@ -2222,9 +2362,12 @@ function deserializeGlobalInitResponse(params) {
|
|
|
2222
2362
|
}
|
|
2223
2363
|
// src/errors.ts
|
|
2224
2364
|
class VgiError extends Error {
|
|
2225
|
-
|
|
2365
|
+
errorCode;
|
|
2366
|
+
constructor(message, code) {
|
|
2226
2367
|
super(message);
|
|
2227
2368
|
this.name = "VgiError";
|
|
2369
|
+
if (code !== undefined)
|
|
2370
|
+
this.errorCode = code;
|
|
2228
2371
|
}
|
|
2229
2372
|
}
|
|
2230
2373
|
|
|
@@ -2237,42 +2380,42 @@ class RowCountMismatchError extends VgiError {
|
|
|
2237
2380
|
|
|
2238
2381
|
class FunctionNotFoundError extends VgiError {
|
|
2239
2382
|
constructor(name, available) {
|
|
2240
|
-
super(`Unknown function '${name}'
|
|
2383
|
+
super(`Unknown function '${name}'`, "NOT_FOUND");
|
|
2241
2384
|
this.name = "FunctionNotFoundError";
|
|
2242
2385
|
}
|
|
2243
2386
|
}
|
|
2244
2387
|
|
|
2245
2388
|
class CatalogReadOnlyError extends VgiError {
|
|
2246
2389
|
constructor(operation) {
|
|
2247
|
-
super(`catalog is read-only: ${operation} is not supported
|
|
2390
|
+
super(`catalog is read-only: ${operation} is not supported`, "FAILED_PRECONDITION");
|
|
2248
2391
|
this.name = "CatalogReadOnlyError";
|
|
2249
2392
|
}
|
|
2250
2393
|
}
|
|
2251
2394
|
|
|
2252
2395
|
class CatalogNotFoundError extends VgiError {
|
|
2253
2396
|
constructor(entity, name) {
|
|
2254
|
-
super(`${entity} '${name}' not found
|
|
2397
|
+
super(`${entity} '${name}' not found`, "NOT_FOUND");
|
|
2255
2398
|
this.name = "CatalogNotFoundError";
|
|
2256
2399
|
}
|
|
2257
2400
|
}
|
|
2258
2401
|
|
|
2259
2402
|
class CatalogAlreadyExistsError extends VgiError {
|
|
2260
2403
|
constructor(entity, name) {
|
|
2261
|
-
super(`${entity} '${name}' already exists
|
|
2404
|
+
super(`${entity} '${name}' already exists`, "ALREADY_EXISTS");
|
|
2262
2405
|
this.name = "CatalogAlreadyExistsError";
|
|
2263
2406
|
}
|
|
2264
2407
|
}
|
|
2265
2408
|
|
|
2266
2409
|
class ArgumentValidationError extends VgiError {
|
|
2267
2410
|
constructor(message) {
|
|
2268
|
-
super(message);
|
|
2411
|
+
super(message, "INVALID_ARGUMENT");
|
|
2269
2412
|
this.name = "ArgumentValidationError";
|
|
2270
2413
|
}
|
|
2271
2414
|
}
|
|
2272
2415
|
|
|
2273
2416
|
class NoCatalogError extends VgiError {
|
|
2274
2417
|
constructor() {
|
|
2275
|
-
super("No catalog is configured for this worker");
|
|
2418
|
+
super("No catalog is configured for this worker", "UNIMPLEMENTED");
|
|
2276
2419
|
this.name = "NoCatalogError";
|
|
2277
2420
|
}
|
|
2278
2421
|
}
|
|
@@ -2284,7 +2427,7 @@ function normalizeSchemaPath(path) {
|
|
|
2284
2427
|
|
|
2285
2428
|
// src/codec/asd.ts
|
|
2286
2429
|
function encodeASD(schema, obj) {
|
|
2287
|
-
return serializeBatch(batchFromRows([sortMapsForSchema(schema, obj)], schema));
|
|
2430
|
+
return serializeBatch(batchFromRows([sortMapsForSchema(schema, conformRecord(schema, obj))], schema));
|
|
2288
2431
|
}
|
|
2289
2432
|
function compareCodePoints(a, b) {
|
|
2290
2433
|
const n = Math.min(a.length, b.length);
|
|
@@ -2301,7 +2444,7 @@ function compareCodePoints(a, b) {
|
|
|
2301
2444
|
}
|
|
2302
2445
|
return a.length - b.length;
|
|
2303
2446
|
}
|
|
2304
|
-
function
|
|
2447
|
+
function mapPairs2(raw) {
|
|
2305
2448
|
if (Array.isArray(raw))
|
|
2306
2449
|
return raw.map((e) => Array.isArray(e) ? [e[0], e[1]] : [e?.key, e?.value]);
|
|
2307
2450
|
if (raw instanceof Map)
|
|
@@ -2336,7 +2479,7 @@ function sortMapsForType(type, value) {
|
|
|
2336
2479
|
if (isMap(type)) {
|
|
2337
2480
|
const entries = type.children[0].type;
|
|
2338
2481
|
const valueType = entries.children[1].type;
|
|
2339
|
-
return
|
|
2482
|
+
return mapPairs2(value).map(([k, v]) => [k, sortMapsForType(valueType, v)]).sort((x, y) => compareKeys(x[0], y[0]));
|
|
2340
2483
|
}
|
|
2341
2484
|
if (isList(type)) {
|
|
2342
2485
|
const child = type.children[0].type;
|
|
@@ -2417,7 +2560,7 @@ function normalizeValue(raw, type) {
|
|
|
2417
2560
|
return out;
|
|
2418
2561
|
}
|
|
2419
2562
|
if (isDictionary(type)) {
|
|
2420
|
-
return raw
|
|
2563
|
+
return normalizeValue(raw, type.dictionary);
|
|
2421
2564
|
}
|
|
2422
2565
|
if (isBinary(type)) {
|
|
2423
2566
|
return toUint8Array3(raw);
|
|
@@ -2446,6 +2589,35 @@ function toUint8Array3(val) {
|
|
|
2446
2589
|
}
|
|
2447
2590
|
return new Uint8Array(0);
|
|
2448
2591
|
}
|
|
2592
|
+
function decodeASDCollection(schema, bytes) {
|
|
2593
|
+
if (bytes == null)
|
|
2594
|
+
return [];
|
|
2595
|
+
const output = [];
|
|
2596
|
+
const batches = deserializeBatches(bytes);
|
|
2597
|
+
const validateSchema = (actualSchema) => {
|
|
2598
|
+
if (actualSchema.fields.length !== schema.fields.length || schema.fields.some((field, i) => {
|
|
2599
|
+
const actual = actualSchema.fields[i];
|
|
2600
|
+
return actual.name !== field.name || actual.nullable !== field.nullable || typeSignature(actual.type) !== typeSignature(field.type);
|
|
2601
|
+
}))
|
|
2602
|
+
throw new Error("catalog collection has an incompatible metadata schema");
|
|
2603
|
+
};
|
|
2604
|
+
if (batches.length === 0)
|
|
2605
|
+
validateSchema(deserializeSchema(bytes));
|
|
2606
|
+
for (const batch of batches) {
|
|
2607
|
+
validateSchema(batch.schema);
|
|
2608
|
+
for (let row = 0;row < batch.numRows; row++) {
|
|
2609
|
+
const item = {};
|
|
2610
|
+
for (const field of schema.fields) {
|
|
2611
|
+
const value = batch.getChild(field.name)?.get(row);
|
|
2612
|
+
if (value == null && !field.nullable)
|
|
2613
|
+
throw new Error(`catalog collection has null ${field.name}`);
|
|
2614
|
+
item[field.name] = normalizeValue(value, field.type);
|
|
2615
|
+
}
|
|
2616
|
+
output.push(item);
|
|
2617
|
+
}
|
|
2618
|
+
}
|
|
2619
|
+
return output;
|
|
2620
|
+
}
|
|
2449
2621
|
|
|
2450
2622
|
// src/generated/vgi-protocol-schemas.ts
|
|
2451
2623
|
var CatalogInfoSchema = schema2([
|
|
@@ -2459,7 +2631,6 @@ var CatalogInfoSchema = schema2([
|
|
|
2459
2631
|
var SchemaInfoSchema = schema2([
|
|
2460
2632
|
field2("comment", utf82(), true),
|
|
2461
2633
|
field2("tags", map2(field2("key", utf82(), false), field2("value", utf82(), true), false), false),
|
|
2462
|
-
field2("attach_opaque_data", binary2(), false),
|
|
2463
2634
|
field2("path", list2(field2("item", utf82(), true)), false),
|
|
2464
2635
|
field2("estimated_object_count", map2(field2("key", utf82(), false), field2("value", int642(), true), false), true)
|
|
2465
2636
|
]);
|
|
@@ -2500,9 +2671,9 @@ var FunctionInfoSchema = schema2([
|
|
|
2500
2671
|
field2("name", utf82(), false),
|
|
2501
2672
|
field2("schema_path", list2(field2("item", utf82(), true)), false),
|
|
2502
2673
|
field2("function_type", dictionary2(utf82(), int162()), false),
|
|
2503
|
-
field2("arguments", binary2(), false),
|
|
2504
|
-
field2("output_schema", binary2(), false),
|
|
2505
|
-
field2("parameter_default_values", binary2(), true),
|
|
2674
|
+
field2("arguments", dictionary2(binary2(), int322()), false),
|
|
2675
|
+
field2("output_schema", dictionary2(binary2(), int322()), false),
|
|
2676
|
+
field2("parameter_default_values", dictionary2(binary2(), int322()), true),
|
|
2506
2677
|
field2("stability", dictionary2(utf82(), int162()), true),
|
|
2507
2678
|
field2("null_handling", dictionary2(utf82(), int162()), true),
|
|
2508
2679
|
field2("argument_monotonicity", list2(field2("item", utf82(), true)), true),
|
|
@@ -2963,7 +3134,12 @@ var CatalogContentsResultSchema = schema2([
|
|
|
2963
3134
|
field2("catalog_version", int642(), false),
|
|
2964
3135
|
field2("etag", utf82(), true),
|
|
2965
3136
|
field2("not_modified", bool2(), false),
|
|
2966
|
-
field2("schemas",
|
|
3137
|
+
field2("schemas", binary2(), true),
|
|
3138
|
+
field2("tables", binary2(), true),
|
|
3139
|
+
field2("views", binary2(), true),
|
|
3140
|
+
field2("functions", binary2(), true),
|
|
3141
|
+
field2("macros", binary2(), true),
|
|
3142
|
+
field2("indexes", binary2(), true)
|
|
2967
3143
|
]);
|
|
2968
3144
|
var CatalogCopyFromFormatsResultSchema = schema2([
|
|
2969
3145
|
field2("items", list2(field2("item", binary2(), true)), false)
|
|
@@ -3582,6 +3758,77 @@ function wrapRpcWithErrorEnrichment(rpc) {
|
|
|
3582
3758
|
};
|
|
3583
3759
|
}
|
|
3584
3760
|
|
|
3761
|
+
// src/catalog/contents-codec.ts
|
|
3762
|
+
var schemaPathKey = (path) => JSON.stringify(path.map((part) => part.toLowerCase()));
|
|
3763
|
+
var CATALOG_STREAM_KINDS = ["schemas", "tables", "views", "functions", "macros", "indexes"];
|
|
3764
|
+
function decodeCatalogStreams(response, ifNoneMatch) {
|
|
3765
|
+
if (response.not_modified) {
|
|
3766
|
+
if (response.etag == null || ifNoneMatch !== undefined && response.etag !== ifNoneMatch || CATALOG_STREAM_KINDS.some((kind) => response[kind] != null)) {
|
|
3767
|
+
throw new Error("invalid catalog_contents not_modified response");
|
|
3768
|
+
}
|
|
3769
|
+
return [];
|
|
3770
|
+
}
|
|
3771
|
+
const infos = decodeASDCollection(SchemaInfoSchema, response.schemas);
|
|
3772
|
+
const schemas = [];
|
|
3773
|
+
const index = new Map;
|
|
3774
|
+
for (const schema of infos) {
|
|
3775
|
+
if (!Array.isArray(schema.path) || schema.path.length === 0)
|
|
3776
|
+
throw new Error("catalog schema has an empty path");
|
|
3777
|
+
const key = schemaPathKey(schema.path);
|
|
3778
|
+
if (index.has(key))
|
|
3779
|
+
throw new Error("catalog contains duplicate schema paths");
|
|
3780
|
+
if (schema.path.length > 1 && !index.has(schemaPathKey(schema.path.slice(0, -1)))) {
|
|
3781
|
+
throw new Error("catalog schema is missing its preceding parent");
|
|
3782
|
+
}
|
|
3783
|
+
const entry = { schema, tables: [], views: [], scalar_functions: [], aggregate_functions: [], table_functions: [], scalar_macros: [], table_macros: [], indexes: [] };
|
|
3784
|
+
index.set(key, entry);
|
|
3785
|
+
schemas.push(entry);
|
|
3786
|
+
}
|
|
3787
|
+
const owner = (item) => {
|
|
3788
|
+
const entry = index.get(schemaPathKey(item.schema_path));
|
|
3789
|
+
if (!entry)
|
|
3790
|
+
throw new Error("catalog object references an absent schema");
|
|
3791
|
+
return entry;
|
|
3792
|
+
};
|
|
3793
|
+
for (const item of decodeASDCollection(TableInfoSchema, response.tables))
|
|
3794
|
+
owner(item).tables.push(item);
|
|
3795
|
+
for (const item of decodeASDCollection(ViewInfoSchema, response.views))
|
|
3796
|
+
owner(item).views.push(item);
|
|
3797
|
+
for (const item of decodeASDCollection(FunctionInfoSchema, response.functions)) {
|
|
3798
|
+
const entry = owner(item);
|
|
3799
|
+
switch (String(item.function_type).toUpperCase()) {
|
|
3800
|
+
case "SCALAR":
|
|
3801
|
+
entry.scalar_functions.push(item);
|
|
3802
|
+
break;
|
|
3803
|
+
case "AGGREGATE":
|
|
3804
|
+
entry.aggregate_functions.push(item);
|
|
3805
|
+
break;
|
|
3806
|
+
case "TABLE":
|
|
3807
|
+
case "TABLE_BUFFERING":
|
|
3808
|
+
entry.table_functions.push(item);
|
|
3809
|
+
break;
|
|
3810
|
+
default:
|
|
3811
|
+
throw new Error(`unknown catalog function type ${item.function_type}`);
|
|
3812
|
+
}
|
|
3813
|
+
}
|
|
3814
|
+
for (const item of decodeASDCollection(MacroInfoSchema, response.macros)) {
|
|
3815
|
+
const entry = owner(item);
|
|
3816
|
+
switch (String(item.macro_type).toUpperCase()) {
|
|
3817
|
+
case "SCALAR":
|
|
3818
|
+
entry.scalar_macros.push(item);
|
|
3819
|
+
break;
|
|
3820
|
+
case "TABLE":
|
|
3821
|
+
entry.table_macros.push(item);
|
|
3822
|
+
break;
|
|
3823
|
+
default:
|
|
3824
|
+
throw new Error(`unknown catalog macro type ${item.macro_type}`);
|
|
3825
|
+
}
|
|
3826
|
+
}
|
|
3827
|
+
for (const item of decodeASDCollection(IndexInfoSchema, response.indexes))
|
|
3828
|
+
owner(item).indexes.push(item);
|
|
3829
|
+
return schemas;
|
|
3830
|
+
}
|
|
3831
|
+
|
|
3585
3832
|
// src/client/helpers.ts
|
|
3586
3833
|
function deserializeInfoList(items, deserializeFn) {
|
|
3587
3834
|
if (!items)
|
|
@@ -3619,6 +3866,10 @@ function toAsyncIterator(input) {
|
|
|
3619
3866
|
}
|
|
3620
3867
|
|
|
3621
3868
|
// src/client/client.ts
|
|
3869
|
+
function onConflictName(onConflict) {
|
|
3870
|
+
return String(onConflict).toUpperCase();
|
|
3871
|
+
}
|
|
3872
|
+
|
|
3622
3873
|
class VgiClient {
|
|
3623
3874
|
rpc;
|
|
3624
3875
|
defaultAttachOpaqueData;
|
|
@@ -3951,23 +4202,7 @@ class VgiClient {
|
|
|
3951
4202
|
if (!result)
|
|
3952
4203
|
throw new VgiClientError("catalog_contents returned null");
|
|
3953
4204
|
const response = decodeCatalogContentsResponse(toUint8Array(result.result));
|
|
3954
|
-
const schemas = response
|
|
3955
|
-
const schema = decodeSchemaInfo(c.schema);
|
|
3956
|
-
if (JSON.stringify(c.path) !== JSON.stringify(schema.path)) {
|
|
3957
|
-
throw new VgiClientError(`catalog_contents: SchemaContents.path ${JSON.stringify(c.path)} != SchemaInfo.path ${JSON.stringify(schema.path)}`);
|
|
3958
|
-
}
|
|
3959
|
-
return {
|
|
3960
|
-
schema,
|
|
3961
|
-
tables: c.tables.map(decodeTableInfo),
|
|
3962
|
-
views: c.views.map(decodeViewInfo),
|
|
3963
|
-
scalar_functions: c.scalar_functions.map(decodeFunctionInfo),
|
|
3964
|
-
aggregate_functions: c.aggregate_functions.map(decodeFunctionInfo),
|
|
3965
|
-
table_functions: c.table_functions.map(decodeFunctionInfo),
|
|
3966
|
-
scalar_macros: c.scalar_macros.map(decodeMacroInfo),
|
|
3967
|
-
table_macros: c.table_macros.map(decodeMacroInfo),
|
|
3968
|
-
indexes: c.indexes.map(decodeIndexInfo)
|
|
3969
|
-
};
|
|
3970
|
-
});
|
|
4205
|
+
const schemas = decodeCatalogStreams(response, ifNoneMatch);
|
|
3971
4206
|
return {
|
|
3972
4207
|
catalog_version: Number(response.catalog_version ?? 0),
|
|
3973
4208
|
etag: response.etag ?? null,
|
|
@@ -4074,7 +4309,7 @@ class VgiClient {
|
|
|
4074
4309
|
}
|
|
4075
4310
|
await this.rpc.call("catalog_create", {
|
|
4076
4311
|
name,
|
|
4077
|
-
on_conflict: onConflict,
|
|
4312
|
+
on_conflict: onConflictName(onConflict),
|
|
4078
4313
|
options: wireOptions
|
|
4079
4314
|
});
|
|
4080
4315
|
}
|
|
@@ -4142,7 +4377,7 @@ class VgiClient {
|
|
|
4142
4377
|
await this.rpc.call("catalog_schema_create", {
|
|
4143
4378
|
attach_opaque_data: attachOpaqueData,
|
|
4144
4379
|
path: normalizeSchemaPath(path),
|
|
4145
|
-
on_conflict: opts?.onConflict ?? "error",
|
|
4380
|
+
on_conflict: onConflictName(opts?.onConflict ?? "error"),
|
|
4146
4381
|
comment: opts?.comment ?? null,
|
|
4147
4382
|
tags: tagsMap,
|
|
4148
4383
|
transaction_opaque_data: opts?.transactionOpaqueData ?? null
|
|
@@ -4221,7 +4456,7 @@ class VgiClient {
|
|
|
4221
4456
|
schema_path: normalizeSchemaPath(schemaPath),
|
|
4222
4457
|
name,
|
|
4223
4458
|
columns,
|
|
4224
|
-
on_conflict: onConflict,
|
|
4459
|
+
on_conflict: onConflictName(onConflict),
|
|
4225
4460
|
not_null_constraints: notNullConstraints ?? null,
|
|
4226
4461
|
unique_constraints: uniqueConstraints ?? null,
|
|
4227
4462
|
check_constraints: checkConstraints ?? null,
|
|
@@ -4375,7 +4610,7 @@ class VgiClient {
|
|
|
4375
4610
|
schema_path: normalizeSchemaPath(schemaPath),
|
|
4376
4611
|
name,
|
|
4377
4612
|
definition,
|
|
4378
|
-
on_conflict: onConflict,
|
|
4613
|
+
on_conflict: onConflictName(onConflict),
|
|
4379
4614
|
transaction_opaque_data: transactionOpaqueData ?? null
|
|
4380
4615
|
});
|
|
4381
4616
|
}
|
|
@@ -4442,7 +4677,7 @@ class VgiClient {
|
|
|
4442
4677
|
macro_type: [macroType],
|
|
4443
4678
|
parameters: [parameters],
|
|
4444
4679
|
definition: [definition],
|
|
4445
|
-
on_conflict: [onConflict],
|
|
4680
|
+
on_conflict: [onConflictName(onConflict)],
|
|
4446
4681
|
parameter_default_values: [parameterDefaultValues ?? null],
|
|
4447
4682
|
arguments_schema: [argumentsSchema ?? null],
|
|
4448
4683
|
transaction_opaque_data: [transactionOpaqueData ?? null]
|
|
@@ -4640,4 +4875,4 @@ export {
|
|
|
4640
4875
|
typeSignature
|
|
4641
4876
|
};
|
|
4642
4877
|
|
|
4643
|
-
//# debugId=
|
|
4878
|
+
//# debugId=D223782952AA2BC964756E2164756E21
|