@query-farm/vgi 0.45.0 → 0.47.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.
Files changed (102) hide show
  1. package/README.md +19 -6
  2. package/dist/arrow/impl-arrowjs/index.d.ts +1 -1
  3. package/dist/arrow/impl-arrowjs/iterate.d.ts +2 -0
  4. package/dist/arrow/impl-flechette/canonical.d.ts +1 -1
  5. package/dist/arrow/impl-flechette/index.d.ts +1 -1
  6. package/dist/arrow/impl-flechette/iterate.d.ts +2 -0
  7. package/dist/arrow/impl-flechette/schema.d.ts +19 -5
  8. package/dist/arrow/index.d.ts +1 -1
  9. package/dist/catalog/column-expressions.d.ts +8 -0
  10. package/dist/catalog/column-metadata.d.ts +11 -0
  11. package/dist/catalog/composite.d.ts +2 -1
  12. package/dist/catalog/descriptors.d.ts +21 -29
  13. package/dist/catalog/interface.d.ts +15 -20
  14. package/dist/catalog/macro-overloads.d.ts +4 -0
  15. package/dist/catalog/read-only.d.ts +1 -1
  16. package/dist/catalog/unconstrained-columns.d.ts +2 -0
  17. package/dist/client/client.d.ts +38 -14
  18. package/dist/client-entry.js +806 -115
  19. package/dist/client-entry.js.map +18 -14
  20. package/dist/functions/continuation.d.ts +69 -0
  21. package/dist/functions/projection.d.ts +18 -0
  22. package/dist/functions/table-in-out.d.ts +51 -7
  23. package/dist/functions/table.d.ts +6 -1
  24. package/dist/functions/types.d.ts +21 -0
  25. package/dist/generated/vgi-client.d.ts +178 -36
  26. package/dist/generated/vgi-protocol-schemas.d.ts +51 -1
  27. package/dist/generated/vgi-protocol-types.d.ts +317 -3
  28. package/dist/generated/vgi-service.d.ts +266 -29
  29. package/dist/index.core.d.ts +3 -1
  30. package/dist/index.js +1747 -320
  31. package/dist/index.js.map +45 -37
  32. package/dist/protocol/dispatch.d.ts +9 -9
  33. package/dist/protocol/handlers/aggregate.d.ts +1 -1
  34. package/dist/protocol/handlers/catalog/index.d.ts +1 -1
  35. package/dist/protocol/handlers/catalog/metadata.d.ts +1 -0
  36. package/dist/protocol/handlers/function.d.ts +1 -1
  37. package/dist/protocol/handlers/table-buffering.d.ts +1 -1
  38. package/dist/protocol/handlers/unimplemented.d.ts +1 -1
  39. package/dist/protocol/serializers/bind.d.ts +5 -1
  40. package/dist/protocol/types.d.ts +5 -0
  41. package/dist/rpc-server.d.ts +6 -6
  42. package/dist/serve-entry.js +1607 -436
  43. package/dist/serve-entry.js.map +33 -27
  44. package/dist/util/arrow/index.d.ts +1 -1
  45. package/dist/util/parent-rows.d.ts +8 -0
  46. package/dist/worker-cf-entry.d.ts +1 -1
  47. package/dist/worker-cf-entry.js +1901 -526
  48. package/dist/worker-cf-entry.js.map +45 -37
  49. package/dist/worker.d.ts +1 -1
  50. package/package.json +8 -7
  51. package/src/arrow/impl-arrowjs/index.ts +1 -1
  52. package/src/arrow/impl-arrowjs/iterate.ts +9 -1
  53. package/src/arrow/impl-arrowjs/project.ts +1 -1
  54. package/src/arrow/impl-flechette/canonical.ts +7 -5
  55. package/src/arrow/impl-flechette/index.ts +1 -1
  56. package/src/arrow/impl-flechette/ipc.ts +12 -0
  57. package/src/arrow/impl-flechette/iterate.ts +5 -0
  58. package/src/arrow/impl-flechette/project.ts +6 -8
  59. package/src/arrow/index.ts +1 -1
  60. package/src/catalog/column-expressions.ts +224 -0
  61. package/src/catalog/column-metadata.ts +151 -0
  62. package/src/catalog/composite.ts +5 -1
  63. package/src/catalog/contents-codec.ts +6 -1
  64. package/src/catalog/descriptors.ts +21 -29
  65. package/src/catalog/interface.ts +70 -55
  66. package/src/catalog/macro-overloads.ts +44 -0
  67. package/src/catalog/read-only.ts +69 -71
  68. package/src/catalog/unconstrained-columns.ts +23 -0
  69. package/src/client/client.ts +180 -69
  70. package/src/codec/asd.ts +3 -1
  71. package/src/filter-pushdown/collector.ts +17 -1
  72. package/src/functions/continuation.ts +202 -0
  73. package/src/functions/projection.ts +207 -0
  74. package/src/functions/table-in-out.ts +131 -56
  75. package/src/functions/table.ts +10 -0
  76. package/src/functions/types.ts +21 -0
  77. package/src/generated/vgi-client.ts +200 -37
  78. package/src/generated/vgi-protocol-schemas.ts +456 -41
  79. package/src/generated/vgi-protocol-types.ts +879 -5
  80. package/src/generated/vgi-service.ts +514 -42
  81. package/src/http/client-bundle.ts +1 -1
  82. package/src/http/fetch.ts +1 -1
  83. package/src/index.core.ts +10 -0
  84. package/src/protocol/dispatch.ts +9 -9
  85. package/src/protocol/handlers/aggregate.ts +1 -1
  86. package/src/protocol/handlers/catalog/admin.ts +10 -5
  87. package/src/protocol/handlers/catalog/index.ts +2 -2
  88. package/src/protocol/handlers/catalog/macro.ts +6 -5
  89. package/src/protocol/handlers/catalog/metadata.ts +16 -0
  90. package/src/protocol/handlers/catalog/table.ts +72 -26
  91. package/src/protocol/handlers/catalog/view.ts +24 -3
  92. package/src/protocol/handlers/function.ts +79 -1
  93. package/src/protocol/handlers/table-buffering.ts +1 -1
  94. package/src/protocol/handlers/unimplemented.ts +6 -6
  95. package/src/protocol/serializers/bind.ts +17 -1
  96. package/src/protocol/state-serializer.ts +7 -1
  97. package/src/protocol/types.ts +6 -0
  98. package/src/rpc-server.ts +9 -9
  99. package/src/util/arrow/index.ts +1 -1
  100. package/src/util/parent-rows.ts +41 -0
  101. package/src/worker-cf-entry.ts +3 -0
  102. package/src/worker.ts +1 -1
@@ -0,0 +1,23 @@
1
+ // Copyright 2026 Query Farm LLC - https://query.farm
2
+ import { MethodNotImplementedError } from "@query-farm/vgi-rpc";
3
+ import { deserializeSchema, isStruct, type VgiField } from "../arrow/index.js";
4
+
5
+ /** No constraint authority means every SQL user field must remain nullable. */
6
+ export function requireUnconstrainedColumns(columns: Uint8Array): void {
7
+ const visit = (field: VgiField, top: boolean, depth: number): void => {
8
+ if (depth > 64) throw new MethodNotImplementedError("catalog_table_create: column nesting exceeds supported depth");
9
+ if (top && field.metadata?.has("is_row_id")) return;
10
+ for (const key of field.metadata?.keys() ?? []) {
11
+ if (key === "ARROW:extension:name" || key.startsWith("vgi.logical_type.")) {
12
+ throw new MethodNotImplementedError("catalog_table_create: logical column types require negotiation");
13
+ }
14
+ }
15
+ if (!field.nullable) {
16
+ throw new MethodNotImplementedError("catalog_table_create: nonnullable user columns require canonical constraints");
17
+ }
18
+ if (isStruct(field.type)) {
19
+ for (const child of (field.type as VgiField["type"] & { children: readonly VgiField[] }).children) visit(child, false, depth + 1);
20
+ }
21
+ };
22
+ for (const field of deserializeSchema(columns).fields) visit(field, true, 0);
23
+ }
@@ -7,7 +7,9 @@ import { type VgiSchema, schema as schema_, type VgiField, field, type VgiBatch,
7
7
  // emits `import {} from "@query-farm/vgi-rpc"`, a side-effect import of the
8
8
  // package root — which re-exports the whole framework, server included, into
9
9
  // every browser bundle. See the note in ./errors.
10
- import type { RpcClient, StreamSession } from "@query-farm/vgi-rpc";
10
+ import type { RawStreamSession, RpcClient, StreamSession } from "@query-farm/vgi-rpc";
11
+ import { CACHE_NOT_MODIFIED_KEY } from "../cache-control.js";
12
+ import { CONTINUE, HAVE_MORE_OUTPUT, STATUS_KEY } from "../functions/continuation.js";
11
13
  import {
12
14
  serializeBindRequest,
13
15
  deserializeBindResponse,
@@ -25,6 +27,7 @@ import { Arguments } from "../arguments/arguments.js";
25
27
  import {
26
28
  batchFromRows,
27
29
  batchFromColumns,
30
+ emptyBatch,
28
31
  iterRows,
29
32
  } from "../util/arrow/index.js";
30
33
  import {
@@ -56,7 +59,7 @@ import { serializeAttachOptions } from "../catalog/attach-options.js";
56
59
  import { VgiClientError, wrapRpcWithErrorEnrichment } from "./errors.js";
57
60
  import { normalizeSchemaPath } from "../schema-path.js";
58
61
  import { encodeASD } from "../codec/asd.js";
59
- import { ClientCapabilitiesSchema, MacroCreateRequestSchema } from "../generated/vgi-protocol-schemas.js";
62
+ import { ClientCapabilitiesSchema, MacroCreateRequestSchema, TableCreateRequestSchema } from "../generated/vgi-protocol-schemas.js";
60
63
  import { decodeCatalogStreams } from "../catalog/contents-codec.js";
61
64
  import { decodeCatalogContentsResponse } from "../generated/vgi-protocol-types.js";
62
65
  import { deserializeInfoList, deserializeTags, toAsyncIterator } from "./helpers.js";
@@ -86,6 +89,74 @@ function onConflictName(onConflict: OnCreateConflict): string {
86
89
  return String(onConflict).toUpperCase();
87
90
  }
88
91
 
92
+ /** Whether reply metadata carries `vgi.cache.not_modified` set. */
93
+ function isNotModified(md: Map<string, string>): boolean {
94
+ const v = md.get(CACHE_NOT_MODIFIED_KEY);
95
+ return v != null && v !== "0" && v.toLowerCase() !== "false";
96
+ }
97
+
98
+ /**
99
+ * Send one input batch on a table-in-out exchange and yield the rows of every
100
+ * reply it gets (continued output, docs/table_in_out.md "Continued Output").
101
+ *
102
+ * A reply saying `vgi.status: HAVE_MORE_OUTPUT` has more output for the same
103
+ * input: ask for the next with a continuation tick (a zero-row batch of the
104
+ * input schema carrying `vgi.status: CONTINUE`) until a reply stops saying
105
+ * more. Only then may the next input go out, or the input close. The row-level
106
+ * `StreamSession.exchange` drops reply metadata, so this uses the raw exchange
107
+ * every transport's session implements.
108
+ *
109
+ * Refused, as the extension refuses them: `not_modified` on a reply that says
110
+ * more or answers a tick (a 304 stands for an input's whole output), and the
111
+ * worker ending the stream while output is pending.
112
+ *
113
+ * Exported for tests only (not re-exported from the package entry points).
114
+ * @internal
115
+ */
116
+ export async function* exchangeContinued(
117
+ session: StreamSession,
118
+ functionName: string,
119
+ input: VgiBatch,
120
+ ): AsyncGenerator<Record<string, any>[]> {
121
+ const raw = session as unknown as Partial<Pick<RawStreamSession, "exchangeRaw">>;
122
+ if (typeof raw.exchangeRaw !== "function") {
123
+ throw new VgiClientError(
124
+ `tableInOutFunction(${functionName}): the transport's stream session has no exchangeRaw(), ` +
125
+ `which continued output needs to read each reply's vgi.status`,
126
+ );
127
+ }
128
+ const exchangeRaw = raw.exchangeRaw.bind(session);
129
+ let tick = false;
130
+ let reply = await exchangeRaw({ batch: input as any, metadata: new Map() });
131
+ for (;;) {
132
+ if (reply === null) {
133
+ if (tick) {
134
+ throw new VgiClientError(
135
+ `tableInOutFunction(${functionName}): the worker ended the stream while output was pending`,
136
+ );
137
+ }
138
+ return;
139
+ }
140
+ const md = new Map<string, string>([...((reply.batch as any).metadata ?? []), ...reply.metadata]);
141
+ const more = md.get(STATUS_KEY) === HAVE_MORE_OUTPUT;
142
+ if (isNotModified(md) && (more || tick)) {
143
+ throw new VgiClientError(
144
+ `tableInOutFunction(${functionName}): the worker answered not_modified on a continued reply ` +
145
+ `(${tick ? "answering a continuation tick" : "one saying HAVE_MORE_OUTPUT"}); ` +
146
+ `not_modified must be an input's only reply`,
147
+ );
148
+ }
149
+ const rows = [...iterRows(reply.batch as unknown as VgiBatch)];
150
+ if (rows.length > 0) yield rows;
151
+ if (!more) return;
152
+ tick = true;
153
+ reply = await exchangeRaw({
154
+ batch: emptyBatch(input.schema) as any,
155
+ metadata: new Map([[STATUS_KEY, CONTINUE]]),
156
+ });
157
+ }
158
+ }
159
+
89
160
  /**
90
161
  * High-level client for calling VGI worker functions and catalog API.
91
162
  *
@@ -426,12 +497,9 @@ export class VgiClient {
426
497
  );
427
498
 
428
499
  try {
429
- const outRows = await inputSession.exchange([...iterRows(firstBatch)]);
430
- if (outRows.length > 0) yield outRows;
431
-
500
+ yield* exchangeContinued(inputSession, opts.functionName, firstBatch);
432
501
  for await (const batch of { [Symbol.asyncIterator]: () => inputIter }) {
433
- const result = await inputSession.exchange([...iterRows(batch)]);
434
- if (result.length > 0) yield result;
502
+ yield* exchangeContinued(inputSession, opts.functionName, batch);
435
503
  }
436
504
  } finally {
437
505
  inputSession.close();
@@ -507,12 +575,13 @@ export class VgiClient {
507
575
 
508
576
  const outputSchema = bindResp.output_schema;
509
577
  try {
510
- const outRows = await inputSession.exchange([...iterRows(firstBatch)]);
511
- if (outRows.length > 0) yield batchFromRows(outRows, outputSchema);
512
-
578
+ for await (const rows of exchangeContinued(inputSession, opts.functionName, firstBatch)) {
579
+ yield batchFromRows(rows, outputSchema);
580
+ }
513
581
  for await (const batch of { [Symbol.asyncIterator]: () => inputIter }) {
514
- const result = await inputSession.exchange([...iterRows(batch)]);
515
- if (result.length > 0) yield batchFromRows(result, outputSchema);
582
+ for await (const rows of exchangeContinued(inputSession, opts.functionName, batch)) {
583
+ yield batchFromRows(rows, outputSchema);
584
+ }
516
585
  }
517
586
  } finally {
518
587
  inputSession.close();
@@ -674,7 +743,7 @@ export class VgiClient {
674
743
  catalog_version_frozen: inner.catalog_version_frozen ?? false,
675
744
  catalog_version: Number(inner.catalog_version ?? 0),
676
745
  attach_opaque_data_required: inner.attach_opaque_data_required ?? true,
677
- default_schema: inner.default_schema ?? "main",
746
+ default_schema: inner.default_schema ?? null,
678
747
  settings: inner.settings
679
748
  ? (Array.isArray(inner.settings) ? inner.settings : [...inner.settings]).map(toUint8Array)
680
749
  : [],
@@ -1120,21 +1189,19 @@ export class VgiClient {
1120
1189
  name: string,
1121
1190
  columns: Uint8Array,
1122
1191
  onConflict: OnCreateConflict,
1123
- notNullConstraints?: number[],
1124
- uniqueConstraints?: number[][],
1125
- checkConstraints?: string[],
1192
+ constraintDefinitions: Uint8Array[] = [],
1126
1193
  transactionOpaqueData?: TransactionOpaqueData,
1127
1194
  ): Promise<void> {
1128
1195
  await this.rpc.call("catalog_table_create", {
1196
+ request: encodeASD(TableCreateRequestSchema, {
1129
1197
  attach_opaque_data: attachOpaqueData,
1130
1198
  schema_path: normalizeSchemaPath(schemaPath),
1131
1199
  name,
1132
1200
  columns,
1133
1201
  on_conflict: onConflictName(onConflict),
1134
- not_null_constraints: notNullConstraints ?? null,
1135
- unique_constraints: uniqueConstraints ?? null,
1136
- check_constraints: checkConstraints ?? null,
1202
+ constraint_definitions: constraintDefinitions,
1137
1203
  transaction_opaque_data: transactionOpaqueData ?? null,
1204
+ }),
1138
1205
  });
1139
1206
  }
1140
1207
 
@@ -1225,20 +1292,20 @@ export class VgiClient {
1225
1292
  attachOpaqueData: AttachOpaqueData,
1226
1293
  schemaPath: string[] | string,
1227
1294
  name: string,
1228
- columnName: string,
1229
- columnType: string,
1230
- defaultValue?: string | null,
1231
- ignoreNotFound?: boolean,
1295
+ columnPath: string[],
1296
+ columnDefinition: Uint8Array,
1297
+ ignoreNotFound: boolean = false,
1298
+ ifColumnNotExists: boolean = false,
1232
1299
  transactionOpaqueData?: TransactionOpaqueData,
1233
1300
  ): Promise<void> {
1234
1301
  await this.rpc.call("catalog_table_column_add", {
1235
1302
  attach_opaque_data: attachOpaqueData,
1236
1303
  schema_path: normalizeSchemaPath(schemaPath),
1237
1304
  name,
1238
- column_name: columnName,
1239
- column_type: columnType,
1240
- default_value: defaultValue ?? null,
1241
- ignore_not_found: ignoreNotFound ?? null,
1305
+ column_path: columnPath,
1306
+ column_definition: columnDefinition,
1307
+ ignore_not_found: ignoreNotFound,
1308
+ if_column_not_exists: ifColumnNotExists,
1242
1309
  transaction_opaque_data: transactionOpaqueData ?? null,
1243
1310
  });
1244
1311
  }
@@ -1248,16 +1315,20 @@ export class VgiClient {
1248
1315
  attachOpaqueData: AttachOpaqueData,
1249
1316
  schemaPath: string[] | string,
1250
1317
  name: string,
1251
- columnName: string,
1252
- ignoreNotFound?: boolean,
1318
+ columnPath: string[],
1319
+ ignoreNotFound: boolean = false,
1320
+ ifColumnExists: boolean = false,
1321
+ cascade: boolean = false,
1253
1322
  transactionOpaqueData?: TransactionOpaqueData,
1254
1323
  ): Promise<void> {
1255
1324
  await this.rpc.call("catalog_table_column_drop", {
1256
1325
  attach_opaque_data: attachOpaqueData,
1257
1326
  schema_path: normalizeSchemaPath(schemaPath),
1258
1327
  name,
1259
- column_name: columnName,
1260
- ignore_not_found: ignoreNotFound ?? null,
1328
+ column_path: columnPath,
1329
+ ignore_not_found: ignoreNotFound,
1330
+ if_column_exists: ifColumnExists,
1331
+ cascade: cascade,
1261
1332
  transaction_opaque_data: transactionOpaqueData ?? null,
1262
1333
  });
1263
1334
  }
@@ -1267,39 +1338,60 @@ export class VgiClient {
1267
1338
  attachOpaqueData: AttachOpaqueData,
1268
1339
  schemaPath: string[] | string,
1269
1340
  name: string,
1270
- columnName: string,
1271
- newName: string,
1272
- ignoreNotFound?: boolean,
1341
+ columnPath: string[],
1342
+ newColumnName: string,
1343
+ ignoreNotFound: boolean = false,
1273
1344
  transactionOpaqueData?: TransactionOpaqueData,
1274
1345
  ): Promise<void> {
1275
1346
  await this.rpc.call("catalog_table_column_rename", {
1276
1347
  attach_opaque_data: attachOpaqueData,
1277
1348
  schema_path: normalizeSchemaPath(schemaPath),
1278
1349
  name,
1279
- column_name: columnName,
1280
- new_name: newName,
1281
- ignore_not_found: ignoreNotFound ?? null,
1350
+ column_path: columnPath,
1351
+ new_column_name: newColumnName,
1352
+ ignore_not_found: ignoreNotFound,
1282
1353
  transaction_opaque_data: transactionOpaqueData ?? null,
1283
1354
  });
1284
1355
  }
1285
1356
 
1286
- /** Set the default value for a column. */
1357
+ /** Set or clear the comment on a column. */
1358
+ async tableColumnCommentSet(
1359
+ attachOpaqueData: AttachOpaqueData,
1360
+ schemaPath: string[] | string,
1361
+ name: string,
1362
+ columnPath: string[],
1363
+ comment: string | null,
1364
+ ignoreNotFound: boolean = false,
1365
+ transactionOpaqueData?: TransactionOpaqueData,
1366
+ ): Promise<void> {
1367
+ await this.rpc.call("catalog_table_column_comment_set", {
1368
+ attach_opaque_data: attachOpaqueData,
1369
+ schema_path: normalizeSchemaPath(schemaPath),
1370
+ name,
1371
+ column_path: columnPath,
1372
+ comment,
1373
+ ignore_not_found: ignoreNotFound,
1374
+ transaction_opaque_data: transactionOpaqueData ?? null,
1375
+ });
1376
+ }
1377
+
1378
+ /** Set the default using a serialized canonical SqlExpression record. */
1287
1379
  async tableColumnDefaultSet(
1288
1380
  attachOpaqueData: AttachOpaqueData,
1289
1381
  schemaPath: string[] | string,
1290
1382
  name: string,
1291
- columnName: string,
1292
- defaultValue: string,
1293
- ignoreNotFound?: boolean,
1383
+ columnPath: string[],
1384
+ expression: Uint8Array,
1385
+ ignoreNotFound: boolean = false,
1294
1386
  transactionOpaqueData?: TransactionOpaqueData,
1295
1387
  ): Promise<void> {
1296
1388
  await this.rpc.call("catalog_table_column_default_set", {
1297
1389
  attach_opaque_data: attachOpaqueData,
1298
1390
  schema_path: normalizeSchemaPath(schemaPath),
1299
1391
  name,
1300
- column_name: columnName,
1301
- default_value: defaultValue,
1302
- ignore_not_found: ignoreNotFound ?? null,
1392
+ column_path: columnPath,
1393
+ expression: expression,
1394
+ ignore_not_found: ignoreNotFound,
1303
1395
  transaction_opaque_data: transactionOpaqueData ?? null,
1304
1396
  });
1305
1397
  }
@@ -1309,16 +1401,16 @@ export class VgiClient {
1309
1401
  attachOpaqueData: AttachOpaqueData,
1310
1402
  schemaPath: string[] | string,
1311
1403
  name: string,
1312
- columnName: string,
1313
- ignoreNotFound?: boolean,
1404
+ columnPath: string[],
1405
+ ignoreNotFound: boolean = false,
1314
1406
  transactionOpaqueData?: TransactionOpaqueData,
1315
1407
  ): Promise<void> {
1316
1408
  await this.rpc.call("catalog_table_column_default_drop", {
1317
1409
  attach_opaque_data: attachOpaqueData,
1318
1410
  schema_path: normalizeSchemaPath(schemaPath),
1319
1411
  name,
1320
- column_name: columnName,
1321
- ignore_not_found: ignoreNotFound ?? null,
1412
+ column_path: columnPath,
1413
+ ignore_not_found: ignoreNotFound,
1322
1414
  transaction_opaque_data: transactionOpaqueData ?? null,
1323
1415
  });
1324
1416
  }
@@ -1328,24 +1420,27 @@ export class VgiClient {
1328
1420
  *
1329
1421
  * `columnDefinition` is a serialized Arrow Schema with a single field whose
1330
1422
  * name identifies the target column and whose type is the new column type.
1331
- * `expression` is an optional SQL expression used to convert existing values.
1423
+ * `expression` is a serialized canonical SqlExpression for USING, or null
1424
+ * when no conversion expression was supplied.
1332
1425
  */
1333
1426
  async tableColumnTypeChange(
1334
1427
  attachOpaqueData: AttachOpaqueData,
1335
1428
  schemaPath: string[] | string,
1336
1429
  name: string,
1430
+ columnPath: string[],
1337
1431
  columnDefinition: Uint8Array,
1338
- expression?: string | null,
1339
- ignoreNotFound?: boolean,
1432
+ expression: Uint8Array | null = null,
1433
+ ignoreNotFound: boolean = false,
1340
1434
  transactionOpaqueData?: TransactionOpaqueData,
1341
1435
  ): Promise<void> {
1342
1436
  await this.rpc.call("catalog_table_column_type_change", {
1343
1437
  attach_opaque_data: attachOpaqueData,
1344
1438
  schema_path: normalizeSchemaPath(schemaPath),
1345
1439
  name,
1440
+ column_path: columnPath,
1346
1441
  column_definition: columnDefinition,
1347
- expression: expression ?? null,
1348
- ignore_not_found: ignoreNotFound ?? false,
1442
+ expression: expression,
1443
+ ignore_not_found: ignoreNotFound,
1349
1444
  transaction_opaque_data: transactionOpaqueData ?? null,
1350
1445
  });
1351
1446
  }
@@ -1355,16 +1450,16 @@ export class VgiClient {
1355
1450
  attachOpaqueData: AttachOpaqueData,
1356
1451
  schemaPath: string[] | string,
1357
1452
  name: string,
1358
- columnName: string,
1359
- ignoreNotFound?: boolean,
1453
+ columnPath: string[],
1454
+ ignoreNotFound: boolean = false,
1360
1455
  transactionOpaqueData?: TransactionOpaqueData,
1361
1456
  ): Promise<void> {
1362
1457
  await this.rpc.call("catalog_table_not_null_set", {
1363
1458
  attach_opaque_data: attachOpaqueData,
1364
1459
  schema_path: normalizeSchemaPath(schemaPath),
1365
1460
  name,
1366
- column_name: columnName,
1367
- ignore_not_found: ignoreNotFound ?? null,
1461
+ column_path: columnPath,
1462
+ ignore_not_found: ignoreNotFound,
1368
1463
  transaction_opaque_data: transactionOpaqueData ?? null,
1369
1464
  });
1370
1465
  }
@@ -1374,16 +1469,16 @@ export class VgiClient {
1374
1469
  attachOpaqueData: AttachOpaqueData,
1375
1470
  schemaPath: string[] | string,
1376
1471
  name: string,
1377
- columnName: string,
1378
- ignoreNotFound?: boolean,
1472
+ columnPath: string[],
1473
+ ignoreNotFound: boolean = false,
1379
1474
  transactionOpaqueData?: TransactionOpaqueData,
1380
1475
  ): Promise<void> {
1381
1476
  await this.rpc.call("catalog_table_not_null_drop", {
1382
1477
  attach_opaque_data: attachOpaqueData,
1383
1478
  schema_path: normalizeSchemaPath(schemaPath),
1384
1479
  name,
1385
- column_name: columnName,
1386
- ignore_not_found: ignoreNotFound ?? null,
1480
+ column_path: columnPath,
1481
+ ignore_not_found: ignoreNotFound,
1387
1482
  transaction_opaque_data: transactionOpaqueData ?? null,
1388
1483
  });
1389
1484
  }
@@ -1415,12 +1510,22 @@ export class VgiClient {
1415
1510
  definition: string,
1416
1511
  onConflict: OnCreateConflict,
1417
1512
  transactionOpaqueData?: TransactionOpaqueData,
1513
+ aliases?: string[],
1514
+ security: "regular" | "barrier" = "regular",
1515
+ comment?: string | null,
1516
+ tags?: Record<string, string> | null,
1517
+ columnComments?: Record<string, string> | null,
1418
1518
  ): Promise<void> {
1419
1519
  await this.rpc.call("catalog_view_create", {
1420
1520
  attach_opaque_data: attachOpaqueData,
1421
1521
  schema_path: normalizeSchemaPath(schemaPath),
1422
1522
  name,
1423
1523
  definition,
1524
+ aliases: aliases ?? null,
1525
+ security,
1526
+ comment: comment ?? null,
1527
+ tags: tags ?? null,
1528
+ column_comments: columnComments ?? null,
1424
1529
  on_conflict: onConflictName(onConflict),
1425
1530
  transaction_opaque_data: transactionOpaqueData ?? null,
1426
1531
  });
@@ -1487,6 +1592,18 @@ export class VgiClient {
1487
1592
  // Macro Catalog API
1488
1593
  // ==========================================================================
1489
1594
 
1595
+ /** Set or clear a comment on one raw view output name. */
1596
+ async viewColumnCommentSet(
1597
+ attachOpaqueData: AttachOpaqueData, schemaPath: string[] | string, name: string, columnPath: string[],
1598
+ comment?: string | null, ignoreNotFound = false, transactionOpaqueData?: TransactionOpaqueData,
1599
+ ): Promise<void> {
1600
+ await this.rpc.call("catalog_view_column_comment_set", {
1601
+ attach_opaque_data: attachOpaqueData, schema_path: normalizeSchemaPath(schemaPath), name,
1602
+ column_path: columnPath, comment: comment ?? null, ignore_not_found: ignoreNotFound,
1603
+ transaction_opaque_data: transactionOpaqueData ?? null,
1604
+ });
1605
+ }
1606
+
1490
1607
  /** Get a macro by name, or null if not found. */
1491
1608
  async macroGet(
1492
1609
  attachOpaqueData: AttachOpaqueData,
@@ -1530,11 +1647,8 @@ export class VgiClient {
1530
1647
  schemaPath: string[] | string,
1531
1648
  name: string,
1532
1649
  macroType: MacroType,
1533
- parameters: string[],
1534
- definition: string,
1650
+ overloads: import("../generated/vgi-client.js").MacroOverload[],
1535
1651
  onConflict: OnCreateConflict,
1536
- parameterDefaultValues?: Uint8Array | null,
1537
- argumentsSchema?: Uint8Array | null,
1538
1652
  transactionOpaqueData?: TransactionOpaqueData,
1539
1653
  ): Promise<void> {
1540
1654
  const innerBatch = batchFromColumns(
@@ -1543,11 +1657,8 @@ export class VgiClient {
1543
1657
  schema_path: [normalizeSchemaPath(schemaPath)],
1544
1658
  name: [name],
1545
1659
  macro_type: [macroType],
1546
- parameters: [parameters],
1547
- definition: [definition],
1660
+ overloads: [overloads],
1548
1661
  on_conflict: [onConflictName(onConflict)],
1549
- parameter_default_values: [parameterDefaultValues ?? null],
1550
- arguments_schema: [argumentsSchema ?? null],
1551
1662
  transaction_opaque_data: [transactionOpaqueData ?? null],
1552
1663
  },
1553
1664
  MacroCreateRequestSchema,
package/src/codec/asd.ts CHANGED
@@ -189,7 +189,9 @@ function normalizeValue(raw: any, type: VgiDataType): any {
189
189
  const valueType = ((entries as any).children as VgiField[])[1].type;
190
190
  const out: Record<string, any> = {};
191
191
  const put = (k: unknown, v: unknown): void => {
192
- out[String(k)] = normalizeValue(v, valueType);
192
+ Object.defineProperty(out, String(k), {
193
+ value: normalizeValue(v, valueType), enumerable: true, writable: true, configurable: true,
194
+ });
193
195
  };
194
196
  // arrow-js MapRow is iterable of [k,v]; flechette returns [[k,v],...] arrays.
195
197
  if (raw[Symbol.iterator]) {
@@ -5,7 +5,8 @@
5
5
 
6
6
  import { type VgiBatch, type VgiSchema, isBatch } from "../arrow/index.js";
7
7
  import type { OutputCollector } from "@query-farm/vgi-rpc";
8
- import { batchFromColumns } from "../util/arrow/index.js";
8
+ import { batchFromColumns, filterBatch } from "../util/arrow/index.js";
9
+ import { decodeParentRows, encodeParentRows, PARENT_ROW_METADATA_KEY } from "../util/parent-rows.js";
9
10
  import { ComparisonOp, type FilterExpression } from "./types.js";
10
11
  import { expressionToSql, PushdownFilters } from "./evaluate.js";
11
12
 
@@ -108,6 +109,21 @@ export class FilteringOutputCollector {
108
109
  } else {
109
110
  batch = batchFromColumns(batchOrColumns as Record<string, any[]>, this.inner.outputSchema as any);
110
111
  }
112
+ const encoded = metadata?.get(PARENT_ROW_METADATA_KEY);
113
+ if (encoded !== undefined && batch.numRows > 0 && this.filters.filters.length > 0) {
114
+ // Provenance is per output row, so it must lose the rows the filter
115
+ // does: filter both with one mask. Mirrors vgi-python's
116
+ // _FilteringOutputCollector.
117
+ const mask = this.filters.evaluate(batch as any);
118
+ const parents = decodeParentRows(encoded);
119
+ const kept: number[] = [];
120
+ for (let i = 0; i < parents.length; i++) if (mask[i]) kept.push(parents[i]);
121
+ const md = new Map(metadata);
122
+ if (kept.length > 0) md.set(PARENT_ROW_METADATA_KEY, encodeParentRows(kept));
123
+ else md.delete(PARENT_ROW_METADATA_KEY);
124
+ this.inner.emit(filterBatch(batch as any, mask) as any, md);
125
+ return;
126
+ }
111
127
  const filtered = this.filters.apply(batch as any);
112
128
  this.inner.emit(filtered as any, metadata);
113
129
  }