@onyx.dev/onyx-database 2.1.1 → 2.4.1

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/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { O as OnyxFacade } from './aggregates-BFOBBZkW.cjs';
2
- export { t as AiChatClient, l as AiChatCompletionChoice, q as AiChatCompletionChunk, p as AiChatCompletionChunkChoice, o as AiChatCompletionChunkDelta, j as AiChatCompletionRequest, m as AiChatCompletionResponse, r as AiChatCompletionStream, k as AiChatCompletionUsage, f as AiChatMessage, s as AiChatOptions, c as AiChatRole, B as AiClient, z as AiErrorResponse, y as AiModel, x as AiModelsResponse, A as AiRequestOptions, u as AiScriptApprovalRequest, w as AiScriptApprovalResponse, h as AiTool, e as AiToolCall, d as AiToolCallFunction, i as AiToolChoice, g as AiToolFunction, aa as FetchImpl, a9 as FetchResponse, F as FullTextQuery, aj as ICascadeBuilder, ak as ICascadeRelationshipBuilder, ag as IConditionBuilder, I as IOnyxDatabase, ah as IQueryBuilder, ai as ISaveBuilder, a5 as LogicalOperator, b as OnyxConfig, a8 as OnyxDocument, ac as QueryCondition, ab as QueryCriteria, a4 as QueryCriteriaOperator, af as QueryPage, Q as QueryResults, a as QueryResultsPromise, R as RetryOptions, K as SchemaAttribute, _ as SchemaAttributeChange, G as SchemaDataType, a3 as SchemaDiff, U as SchemaEntity, X as SchemaHistoryEntry, J as SchemaIdentifier, H as SchemaIdentifierGenerator, M as SchemaIndex, $ as SchemaIndexChange, L as SchemaIndexType, N as SchemaResolver, a0 as SchemaResolverChange, W as SchemaRevision, V as SchemaRevisionMetadata, a2 as SchemaTableDiff, T as SchemaTrigger, a1 as SchemaTriggerChange, P as SchemaTriggerEvent, Y as SchemaUpsertRequest, Z as SchemaValidationResult, S as SecretMetadata, C as SecretRecord, E as SecretSaveRequest, D as SecretsListResponse, ad as SelectQuery, a6 as Sort, a7 as StreamAction, ae as UpdateQuery, al as asc, aL as avg, at as between, aD as contains, aE as containsIgnoreCase, aN as count, am as desc, an as eq, aX as format, au as gt, av as gte, ap as inOp, aJ as isNull, aB as like, aU as lower, aw as lt, ax as lte, ay as matches, aP as max, aS as median, aO as min, ao as neq, aF as notContains, aG as notContainsIgnoreCase, ar as notIn, aC as notLike, aA as notMatches, aK as notNull, aI as notStartsWith, as as notWithin, aY as percentile, aW as replace, n as sdkName, v as sdkVersion, az as search, aH as startsWith, aQ as std, aV as substring, aM as sum, aT as upper, aR as variance, aq as within } from './aggregates-BFOBBZkW.cjs';
1
+ import { O as OnyxFacade } from './aggregates-COLPYBfv.cjs';
2
+ export { A as AiChatClient, a as AiChatCompletionChoice, b as AiChatCompletionChunk, c as AiChatCompletionChunkChoice, d as AiChatCompletionChunkDelta, e as AiChatCompletionRequest, f as AiChatCompletionResponse, g as AiChatCompletionStream, h as AiChatCompletionUsage, i as AiChatMessage, j as AiChatOptions, k as AiChatRole, l as AiClient, m as AiErrorResponse, n as AiModel, o as AiModelsResponse, p as AiRequestOptions, q as AiScriptApprovalRequest, r as AiScriptApprovalResponse, s as AiTool, t as AiToolCall, u as AiToolCallFunction, v as AiToolChoice, w as AiToolFunction, C as CsvFormatOptions, F as FetchImpl, x as FetchResponse, y as FullTextQuery, I as ICascadeBuilder, z as ICascadeRelationshipBuilder, B as IConditionBuilder, D as IOnyxDatabase, E as IQueryBuilder, G as ISaveBuilder, J as JsonFormatOptions, L as LogicalOperator, H as OnyxConfig, K as OnyxDocument, P as PublishedModelPredictionInput, M as PublishedModelPredictionInputs, N as PublishedModelPredictionResponse, Q as PublishedModelRawPredictionRequest, R as PublishedModelScriptPredictionRequest, S as QueryCondition, T as QueryCriteria, U as QueryCriteriaOperator, V as QueryPage, W as QueryResults, X as QueryResultsPromise, Y as RetryOptions, Z as SchemaAttribute, _ as SchemaAttributeChange, $ as SchemaDataType, a0 as SchemaDiff, a1 as SchemaEntity, a2 as SchemaHistoryEntry, a3 as SchemaIdentifier, a4 as SchemaIdentifierGenerator, a5 as SchemaIndex, a6 as SchemaIndexChange, a7 as SchemaIndexType, a8 as SchemaResolver, a9 as SchemaResolverChange, aa as SchemaRevision, ab as SchemaRevisionMetadata, ac as SchemaTableDiff, ad as SchemaTrigger, ae as SchemaTriggerChange, af as SchemaTriggerEvent, ag as SchemaUpsertRequest, ah as SchemaValidationResult, ai as SecretMetadata, aj as SecretRecord, ak as SecretSaveRequest, al as SecretsListResponse, am as SelectQuery, an as Sort, ao as StreamAction, ap as TableFormatOptions, aq as TreeFormatOptions, ar as UpdateQuery, as as asc, at as avg, au as between, av as contains, aw as containsIgnoreCase, ax as count, ay as desc, az as eq, aA as format, aB as gt, aC as gte, aD as inOp, aE as isNull, aF as like, aG as lower, aH as lt, aI as lte, aJ as matches, aK as max, aL as median, aM as min, aN as neq, aO as notContains, aP as notContainsIgnoreCase, aQ as notIn, aR as notLike, aS as notMatches, aT as notNull, aU as notStartsWith, aV as notWithin, aW as percentile, aX as replace, aY as sdkName, aZ as sdkVersion, a_ as search, a$ as startsWith, b0 as std, b1 as substring, b2 as sum, b3 as upper, b4 as variance, b5 as within } from './aggregates-COLPYBfv.cjs';
3
3
 
4
4
  declare const onyx: OnyxFacade;
5
5
 
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { O as OnyxFacade } from './aggregates-BFOBBZkW.js';
2
- export { t as AiChatClient, l as AiChatCompletionChoice, q as AiChatCompletionChunk, p as AiChatCompletionChunkChoice, o as AiChatCompletionChunkDelta, j as AiChatCompletionRequest, m as AiChatCompletionResponse, r as AiChatCompletionStream, k as AiChatCompletionUsage, f as AiChatMessage, s as AiChatOptions, c as AiChatRole, B as AiClient, z as AiErrorResponse, y as AiModel, x as AiModelsResponse, A as AiRequestOptions, u as AiScriptApprovalRequest, w as AiScriptApprovalResponse, h as AiTool, e as AiToolCall, d as AiToolCallFunction, i as AiToolChoice, g as AiToolFunction, aa as FetchImpl, a9 as FetchResponse, F as FullTextQuery, aj as ICascadeBuilder, ak as ICascadeRelationshipBuilder, ag as IConditionBuilder, I as IOnyxDatabase, ah as IQueryBuilder, ai as ISaveBuilder, a5 as LogicalOperator, b as OnyxConfig, a8 as OnyxDocument, ac as QueryCondition, ab as QueryCriteria, a4 as QueryCriteriaOperator, af as QueryPage, Q as QueryResults, a as QueryResultsPromise, R as RetryOptions, K as SchemaAttribute, _ as SchemaAttributeChange, G as SchemaDataType, a3 as SchemaDiff, U as SchemaEntity, X as SchemaHistoryEntry, J as SchemaIdentifier, H as SchemaIdentifierGenerator, M as SchemaIndex, $ as SchemaIndexChange, L as SchemaIndexType, N as SchemaResolver, a0 as SchemaResolverChange, W as SchemaRevision, V as SchemaRevisionMetadata, a2 as SchemaTableDiff, T as SchemaTrigger, a1 as SchemaTriggerChange, P as SchemaTriggerEvent, Y as SchemaUpsertRequest, Z as SchemaValidationResult, S as SecretMetadata, C as SecretRecord, E as SecretSaveRequest, D as SecretsListResponse, ad as SelectQuery, a6 as Sort, a7 as StreamAction, ae as UpdateQuery, al as asc, aL as avg, at as between, aD as contains, aE as containsIgnoreCase, aN as count, am as desc, an as eq, aX as format, au as gt, av as gte, ap as inOp, aJ as isNull, aB as like, aU as lower, aw as lt, ax as lte, ay as matches, aP as max, aS as median, aO as min, ao as neq, aF as notContains, aG as notContainsIgnoreCase, ar as notIn, aC as notLike, aA as notMatches, aK as notNull, aI as notStartsWith, as as notWithin, aY as percentile, aW as replace, n as sdkName, v as sdkVersion, az as search, aH as startsWith, aQ as std, aV as substring, aM as sum, aT as upper, aR as variance, aq as within } from './aggregates-BFOBBZkW.js';
1
+ import { O as OnyxFacade } from './aggregates-COLPYBfv.js';
2
+ export { A as AiChatClient, a as AiChatCompletionChoice, b as AiChatCompletionChunk, c as AiChatCompletionChunkChoice, d as AiChatCompletionChunkDelta, e as AiChatCompletionRequest, f as AiChatCompletionResponse, g as AiChatCompletionStream, h as AiChatCompletionUsage, i as AiChatMessage, j as AiChatOptions, k as AiChatRole, l as AiClient, m as AiErrorResponse, n as AiModel, o as AiModelsResponse, p as AiRequestOptions, q as AiScriptApprovalRequest, r as AiScriptApprovalResponse, s as AiTool, t as AiToolCall, u as AiToolCallFunction, v as AiToolChoice, w as AiToolFunction, C as CsvFormatOptions, F as FetchImpl, x as FetchResponse, y as FullTextQuery, I as ICascadeBuilder, z as ICascadeRelationshipBuilder, B as IConditionBuilder, D as IOnyxDatabase, E as IQueryBuilder, G as ISaveBuilder, J as JsonFormatOptions, L as LogicalOperator, H as OnyxConfig, K as OnyxDocument, P as PublishedModelPredictionInput, M as PublishedModelPredictionInputs, N as PublishedModelPredictionResponse, Q as PublishedModelRawPredictionRequest, R as PublishedModelScriptPredictionRequest, S as QueryCondition, T as QueryCriteria, U as QueryCriteriaOperator, V as QueryPage, W as QueryResults, X as QueryResultsPromise, Y as RetryOptions, Z as SchemaAttribute, _ as SchemaAttributeChange, $ as SchemaDataType, a0 as SchemaDiff, a1 as SchemaEntity, a2 as SchemaHistoryEntry, a3 as SchemaIdentifier, a4 as SchemaIdentifierGenerator, a5 as SchemaIndex, a6 as SchemaIndexChange, a7 as SchemaIndexType, a8 as SchemaResolver, a9 as SchemaResolverChange, aa as SchemaRevision, ab as SchemaRevisionMetadata, ac as SchemaTableDiff, ad as SchemaTrigger, ae as SchemaTriggerChange, af as SchemaTriggerEvent, ag as SchemaUpsertRequest, ah as SchemaValidationResult, ai as SecretMetadata, aj as SecretRecord, ak as SecretSaveRequest, al as SecretsListResponse, am as SelectQuery, an as Sort, ao as StreamAction, ap as TableFormatOptions, aq as TreeFormatOptions, ar as UpdateQuery, as as asc, at as avg, au as between, av as contains, aw as containsIgnoreCase, ax as count, ay as desc, az as eq, aA as format, aB as gt, aC as gte, aD as inOp, aE as isNull, aF as like, aG as lower, aH as lt, aI as lte, aJ as matches, aK as max, aL as median, aM as min, aN as neq, aO as notContains, aP as notContainsIgnoreCase, aQ as notIn, aR as notLike, aS as notMatches, aT as notNull, aU as notStartsWith, aV as notWithin, aW as percentile, aX as replace, aY as sdkName, aZ as sdkVersion, a_ as search, a$ as startsWith, b0 as std, b1 as substring, b2 as sum, b3 as upper, b4 as variance, b5 as within } from './aggregates-COLPYBfv.js';
3
3
 
4
4
  declare const onyx: OnyxFacade;
5
5
 
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // package.json
2
2
  var name = "@onyx.dev/onyx-database";
3
- var version = "2.1.1";
3
+ var version = "2.4.1";
4
4
 
5
5
  // src/config/defaults.ts
6
6
  var DEFAULT_BASE_URL = "https://api.onyx.dev";
@@ -1192,6 +1192,374 @@ function computeSchemaDiff(apiSchema, localSchema) {
1192
1192
  return { newTables, removedTables, changedTables };
1193
1193
  }
1194
1194
 
1195
+ // src/helpers/query-formatters.ts
1196
+ var DEFAULT_TABLE_OPTIONS = {
1197
+ headers: true,
1198
+ maxColumnWidth: 80,
1199
+ flattenNestedObjects: false,
1200
+ nestedSeparator: ".",
1201
+ nullValue: ""
1202
+ };
1203
+ var DEFAULT_TREE_OPTIONS = {
1204
+ rootLabel: "results",
1205
+ keyField: "",
1206
+ includeRoot: true,
1207
+ maxDepth: Number.POSITIVE_INFINITY,
1208
+ nullValue: ""
1209
+ };
1210
+ var DEFAULT_CSV_OPTIONS = {
1211
+ headers: true,
1212
+ delimiter: ",",
1213
+ quote: '"',
1214
+ escape: '"',
1215
+ newline: "\n",
1216
+ flattenNestedObjects: true,
1217
+ nestedSeparator: ".",
1218
+ nullValue: ""
1219
+ };
1220
+ var DEFAULT_JSON_OPTIONS = {
1221
+ pretty: true,
1222
+ indent: 2
1223
+ };
1224
+ function isDate(value) {
1225
+ return value instanceof Date;
1226
+ }
1227
+ function isRecord(value) {
1228
+ return value !== null && typeof value === "object" && !Array.isArray(value) && !isDate(value);
1229
+ }
1230
+ function normalizeRecord(value) {
1231
+ if (isRecord(value)) {
1232
+ return value;
1233
+ }
1234
+ return { value };
1235
+ }
1236
+ function normalizeScalar(value, nullValue) {
1237
+ if (value == null) return nullValue;
1238
+ if (isDate(value)) return value.toISOString();
1239
+ if (typeof value === "string") return value;
1240
+ if (typeof value === "bigint") return value.toString();
1241
+ if (typeof value === "number" || typeof value === "boolean") return String(value);
1242
+ return JSON.stringify(value);
1243
+ }
1244
+ function inlineValue(value, nullValue) {
1245
+ if (value == null) return nullValue;
1246
+ if (isDate(value)) return value.toISOString();
1247
+ if (Array.isArray(value)) {
1248
+ return value.length === 0 ? "[]" : `[${value.map((entry) => inlineValue(entry, nullValue)).join(", ")}]`;
1249
+ }
1250
+ if (isRecord(value)) {
1251
+ const entries = Object.entries(value);
1252
+ if (entries.length === 0) return "{}";
1253
+ return entries.map(([key, entry]) => `${key}=${inlineValue(entry, nullValue)}`).join(", ");
1254
+ }
1255
+ if (typeof value === "bigint") return value.toString();
1256
+ return String(value);
1257
+ }
1258
+ function escapeTableCell(value) {
1259
+ return value.replace(/\r/g, "\\r").replace(/\n/g, "\\n");
1260
+ }
1261
+ function truncate(value, maxWidth) {
1262
+ if (maxWidth < 1) return "";
1263
+ if (value.length <= maxWidth) return value;
1264
+ if (maxWidth <= 3) return ".".repeat(maxWidth);
1265
+ return `${value.slice(0, Math.max(0, maxWidth - 3))}...`;
1266
+ }
1267
+ function padRight(value, width) {
1268
+ if (value.length >= width) return value;
1269
+ return value + " ".repeat(width - value.length);
1270
+ }
1271
+ function flattenValue(value, separator, prefix, out) {
1272
+ if (isRecord(value)) {
1273
+ const entries = Object.entries(value);
1274
+ if (entries.length === 0) {
1275
+ out[prefix] = {};
1276
+ return;
1277
+ }
1278
+ for (const [key, entry] of entries) {
1279
+ const path = prefix ? `${prefix}${separator}${key}` : key;
1280
+ flattenValue(entry, separator, path, out);
1281
+ }
1282
+ return;
1283
+ }
1284
+ if (Array.isArray(value)) {
1285
+ if (value.length === 0) {
1286
+ out[prefix] = [];
1287
+ return;
1288
+ }
1289
+ value.forEach((entry, index) => {
1290
+ const path = prefix ? `${prefix}${separator}${index}` : String(index);
1291
+ flattenValue(entry, separator, path, out);
1292
+ });
1293
+ return;
1294
+ }
1295
+ out[prefix] = value;
1296
+ }
1297
+ function toFlatRow(record, separator) {
1298
+ const out = {};
1299
+ for (const [key, value] of Object.entries(record)) {
1300
+ flattenValue(value, separator, key, out);
1301
+ }
1302
+ return out;
1303
+ }
1304
+ function discoveredColumns(rows) {
1305
+ const columns = [];
1306
+ const seen = /* @__PURE__ */ new Set();
1307
+ for (const row of rows) {
1308
+ for (const key of Object.keys(row)) {
1309
+ if (!seen.has(key)) {
1310
+ seen.add(key);
1311
+ columns.push(key);
1312
+ }
1313
+ }
1314
+ }
1315
+ return columns;
1316
+ }
1317
+ function orderColumns(discovered, preferred, flattenNestedObjects, separator) {
1318
+ if (!preferred || preferred.length === 0) return discovered;
1319
+ const ordered = [];
1320
+ const seen = /* @__PURE__ */ new Set();
1321
+ const addColumn = (column) => {
1322
+ if (!seen.has(column)) {
1323
+ seen.add(column);
1324
+ ordered.push(column);
1325
+ }
1326
+ };
1327
+ for (const field of preferred) {
1328
+ if (flattenNestedObjects) {
1329
+ let matched = false;
1330
+ for (const column of discovered) {
1331
+ if (column === field || column.startsWith(`${field}${separator}`)) {
1332
+ addColumn(column);
1333
+ matched = true;
1334
+ }
1335
+ }
1336
+ if (!matched) {
1337
+ addColumn(field);
1338
+ }
1339
+ continue;
1340
+ }
1341
+ addColumn(field);
1342
+ }
1343
+ for (const column of discovered) {
1344
+ addColumn(column);
1345
+ }
1346
+ return ordered;
1347
+ }
1348
+ function normalizeTableRows(records, preferredColumns, options) {
1349
+ const normalized = records.map(normalizeRecord);
1350
+ if (options.flattenNestedObjects) {
1351
+ const flatRows = normalized.map((record) => toFlatRow(record, options.nestedSeparator));
1352
+ const columns2 = orderColumns(
1353
+ discoveredColumns(flatRows),
1354
+ preferredColumns,
1355
+ true,
1356
+ options.nestedSeparator
1357
+ );
1358
+ const rows2 = flatRows.map((row) => columns2.map((column) => escapeTableCell(truncate(
1359
+ inlineValue(row[column], options.nullValue),
1360
+ options.maxColumnWidth
1361
+ ))));
1362
+ return { columns: columns2, rows: rows2 };
1363
+ }
1364
+ const topLevelRows = normalized.map((record) => ({ ...record }));
1365
+ const columns = orderColumns(
1366
+ discoveredColumns(topLevelRows),
1367
+ preferredColumns,
1368
+ false,
1369
+ options.nestedSeparator
1370
+ );
1371
+ const rows = topLevelRows.map((row) => columns.map((column) => escapeTableCell(truncate(
1372
+ inlineValue(row[column], options.nullValue),
1373
+ options.maxColumnWidth
1374
+ ))));
1375
+ return { columns, rows };
1376
+ }
1377
+ function formatQueryResultsAsTable(records, options, preferredColumns) {
1378
+ const final = { ...DEFAULT_TABLE_OPTIONS, ...options };
1379
+ const { columns, rows } = normalizeTableRows(records, preferredColumns, final);
1380
+ if (columns.length === 0) return "";
1381
+ const headerCells = columns.map((column) => truncate(column, final.maxColumnWidth));
1382
+ const widths = columns.map((_, index) => {
1383
+ const headerWidth = final.headers ? headerCells[index].length : 0;
1384
+ const rowWidth = rows.reduce((max2, row) => Math.max(max2, row[index].length), 0);
1385
+ return Math.max(headerWidth, rowWidth);
1386
+ });
1387
+ const border = (left, join, right) => `${left}${widths.map((width) => "\u2500".repeat(width + 2)).join(join)}${right}`;
1388
+ const renderRow = (cells) => `\u2502 ${cells.map((cell, index) => padRight(cell, widths[index])).join(" \u2502 ")} \u2502`;
1389
+ const lines = [border("\u250C", "\u252C", "\u2510")];
1390
+ if (final.headers) {
1391
+ lines.push(renderRow(headerCells));
1392
+ lines.push(border("\u251C", "\u253C", "\u2524"));
1393
+ }
1394
+ for (const row of rows) {
1395
+ lines.push(renderRow(row));
1396
+ }
1397
+ lines.push(border("\u2514", "\u2534", "\u2518"));
1398
+ return lines.join("\n");
1399
+ }
1400
+ function encodeCsvCell(value, options) {
1401
+ const escapedQuote = `${options.escape}${options.quote}`;
1402
+ const escaped = value.split(options.quote).join(escapedQuote);
1403
+ const needsQuoting = escaped.includes(options.delimiter) || escaped.includes(options.quote) || escaped.includes("\n") || escaped.includes("\r");
1404
+ if (!needsQuoting) return escaped;
1405
+ return `${options.quote}${escaped}${options.quote}`;
1406
+ }
1407
+ function normalizeCsvRows(records, preferredColumns, options) {
1408
+ const normalized = records.map(normalizeRecord);
1409
+ if (options.flattenNestedObjects) {
1410
+ const flatRows = normalized.map((record) => toFlatRow(record, options.nestedSeparator));
1411
+ const columns2 = orderColumns(
1412
+ discoveredColumns(flatRows),
1413
+ preferredColumns,
1414
+ true,
1415
+ options.nestedSeparator
1416
+ );
1417
+ const rows2 = flatRows.map((row) => columns2.map((column) => normalizeScalar(row[column], options.nullValue)));
1418
+ return { columns: columns2, rows: rows2 };
1419
+ }
1420
+ const topLevelRows = normalized.map((record) => ({ ...record }));
1421
+ const columns = orderColumns(
1422
+ discoveredColumns(topLevelRows),
1423
+ preferredColumns,
1424
+ false,
1425
+ options.nestedSeparator
1426
+ );
1427
+ const rows = topLevelRows.map((row) => columns.map((column) => inlineValue(row[column], options.nullValue)));
1428
+ return { columns, rows };
1429
+ }
1430
+ function formatQueryResultsAsCsv(records, options, preferredColumns) {
1431
+ const final = { ...DEFAULT_CSV_OPTIONS, ...options };
1432
+ const { columns, rows } = normalizeCsvRows(records, preferredColumns, final);
1433
+ const lines = [];
1434
+ if (final.headers && columns.length > 0) {
1435
+ lines.push(columns.map((column) => encodeCsvCell(column, final)).join(final.delimiter));
1436
+ }
1437
+ for (const row of rows) {
1438
+ lines.push(row.map((cell) => encodeCsvCell(cell, final)).join(final.delimiter));
1439
+ }
1440
+ return lines.join(final.newline);
1441
+ }
1442
+ function normalizeJsonValue(value) {
1443
+ if (value === void 0) return null;
1444
+ if (value === null) return null;
1445
+ if (isDate(value)) return value.toISOString();
1446
+ if (typeof value === "bigint") return value.toString();
1447
+ if (Array.isArray(value)) return value.map((entry) => normalizeJsonValue(entry));
1448
+ if (isRecord(value)) {
1449
+ const out = {};
1450
+ for (const [key, entry] of Object.entries(value)) {
1451
+ out[key] = normalizeJsonValue(entry);
1452
+ }
1453
+ return out;
1454
+ }
1455
+ return value;
1456
+ }
1457
+ function formatQueryResultsAsJson(records, options) {
1458
+ const final = { ...DEFAULT_JSON_OPTIONS, ...options };
1459
+ const normalized = records.map((record) => normalizeJsonValue(normalizeRecord(record)));
1460
+ return final.pretty ? JSON.stringify(normalized, null, final.indent) : JSON.stringify(normalized);
1461
+ }
1462
+ function findDefaultTreeKeyField(record) {
1463
+ for (const candidate of ["code", "id", "name"]) {
1464
+ if (candidate in record) return candidate;
1465
+ }
1466
+ const keys = Object.keys(record);
1467
+ return keys.length > 0 ? keys[0] : void 0;
1468
+ }
1469
+ function buildTreeNodesFromValue(value, options, depth) {
1470
+ if (depth >= options.maxDepth) {
1471
+ return [{ label: inlineValue(value, options.nullValue) }];
1472
+ }
1473
+ if (Array.isArray(value)) {
1474
+ return value.map((entry, index) => {
1475
+ if (!isRecord(entry) && !Array.isArray(entry)) {
1476
+ return { label: `[${index}]: ${inlineValue(entry, options.nullValue)}` };
1477
+ }
1478
+ return {
1479
+ label: `[${index}]`,
1480
+ children: buildTreeNodesFromValue(entry, options, depth + 1)
1481
+ };
1482
+ });
1483
+ }
1484
+ return Object.entries(value).map(([key, entry]) => {
1485
+ if (isRecord(entry) || Array.isArray(entry)) {
1486
+ if (depth + 1 >= options.maxDepth) {
1487
+ return { label: `${key}: ${inlineValue(entry, options.nullValue)}` };
1488
+ }
1489
+ return {
1490
+ label: key,
1491
+ children: buildTreeNodesFromValue(entry, options, depth + 1)
1492
+ };
1493
+ }
1494
+ return { label: `${key}: ${inlineValue(entry, options.nullValue)}` };
1495
+ });
1496
+ }
1497
+ function buildRecordTreeNode(record, index, options) {
1498
+ const keyField = options.keyField || findDefaultTreeKeyField(record);
1499
+ const entries = Object.entries(record);
1500
+ if (!keyField || !(keyField in record)) {
1501
+ return {
1502
+ label: `row ${index + 1}`,
1503
+ children: buildTreeNodesFromValue(record, options, 0)
1504
+ };
1505
+ }
1506
+ const labelValue = inlineValue(record[keyField], options.nullValue);
1507
+ const childEntries = entries.filter(([key]) => key !== keyField);
1508
+ return {
1509
+ label: labelValue,
1510
+ children: childEntries.length > 0 ? childEntries.map(([key, value]) => {
1511
+ if (isRecord(value) || Array.isArray(value)) {
1512
+ if (1 > options.maxDepth) {
1513
+ return { label: `${key}: ${inlineValue(value, options.nullValue)}` };
1514
+ }
1515
+ return {
1516
+ label: key,
1517
+ children: buildTreeNodesFromValue(value, options, 1)
1518
+ };
1519
+ }
1520
+ return { label: `${key}: ${inlineValue(value, options.nullValue)}` };
1521
+ }) : void 0
1522
+ };
1523
+ }
1524
+ function renderTreeNodes(nodes, prefix = "") {
1525
+ const lines = [];
1526
+ nodes.forEach((node, index) => {
1527
+ const isLast = index === nodes.length - 1;
1528
+ const branch = isLast ? "\u2514\u2500 " : "\u251C\u2500 ";
1529
+ lines.push(`${prefix}${branch}${node.label}`);
1530
+ if (node.children && node.children.length > 0) {
1531
+ const childPrefix = `${prefix}${isLast ? " " : "\u2502 "}`;
1532
+ lines.push(...renderTreeNodes(node.children, childPrefix));
1533
+ }
1534
+ });
1535
+ return lines;
1536
+ }
1537
+ function formatQueryResultsAsTree(records, options) {
1538
+ const final = { ...DEFAULT_TREE_OPTIONS, ...options };
1539
+ const nodes = records.map((record, index) => buildRecordTreeNode(normalizeRecord(record), index, final));
1540
+ if (!final.includeRoot) {
1541
+ return renderTreeNodes(nodes).join("\n");
1542
+ }
1543
+ const lines = [final.rootLabel];
1544
+ if (nodes.length > 0) {
1545
+ lines.push(...renderTreeNodes(nodes));
1546
+ }
1547
+ return lines.join("\n");
1548
+ }
1549
+ async function collectAllQueryRecords(getPage, initialNextPage) {
1550
+ const records = [];
1551
+ let nextPage = initialNextPage;
1552
+ while (true) {
1553
+ const page = await getPage(nextPage);
1554
+ if (Array.isArray(page.records)) {
1555
+ records.push(...page.records);
1556
+ }
1557
+ if (!page.nextPage) break;
1558
+ nextPage = page.nextPage;
1559
+ }
1560
+ return records;
1561
+ }
1562
+
1195
1563
  // src/impl/onyx-core.ts
1196
1564
  var DEFAULT_CACHE_TTL = 5 * 60 * 1e3;
1197
1565
  function toSingleCondition(criteria) {
@@ -1425,6 +1793,27 @@ var OnyxDatabaseImpl = class {
1425
1793
  const { http } = await this.ensureAiClient();
1426
1794
  return http.request("POST", "/api/script-approvals", input);
1427
1795
  }
1796
+ async predict(publishedModelId, inputs) {
1797
+ const { http, databaseId } = await this.ensureClient();
1798
+ const path = `/data/${encodeURIComponent(
1799
+ databaseId
1800
+ )}/model-builder/published-model/${encodeURIComponent(publishedModelId)}/predict`;
1801
+ return http.request(
1802
+ "POST",
1803
+ path,
1804
+ serializeDates({ inputs })
1805
+ );
1806
+ }
1807
+ async predictFromScript(publishedModelId, scriptId, scriptParameters = {}) {
1808
+ const { http, databaseId } = await this.ensureClient();
1809
+ const path = `/data/${encodeURIComponent(
1810
+ databaseId
1811
+ )}/model-builder/published-model/${encodeURIComponent(publishedModelId)}/predict/script`;
1812
+ return http.request("POST", path, {
1813
+ scriptId,
1814
+ scriptParameters
1815
+ });
1816
+ }
1428
1817
  from(table) {
1429
1818
  return new QueryBuilderImpl(this, String(table), this.defaultPartition);
1430
1819
  }
@@ -1699,7 +2088,7 @@ var OnyxDatabaseImpl = class {
1699
2088
  };
1700
2089
  var QueryBuilderImpl = class {
1701
2090
  db;
1702
- table;
2091
+ tableName;
1703
2092
  fields = null;
1704
2093
  resolvers = null;
1705
2094
  conditions = null;
@@ -1718,12 +2107,12 @@ var QueryBuilderImpl = class {
1718
2107
  onItemListener = null;
1719
2108
  constructor(db, table, partition) {
1720
2109
  this.db = db;
1721
- this.table = table;
2110
+ this.tableName = table;
1722
2111
  this.partitionValue = partition;
1723
2112
  }
1724
2113
  ensureTable() {
1725
- if (!this.table) throw new Error("Table is not defined. Call from(<table>) first.");
1726
- return this.table;
2114
+ if (!this.tableName) throw new Error("Table is not defined. Call from(<table>) first.");
2115
+ return this.tableName;
1727
2116
  }
1728
2117
  serializableConditions() {
1729
2118
  return normalizeCondition(this.conditions);
@@ -1731,7 +2120,7 @@ var QueryBuilderImpl = class {
1731
2120
  toSelectQuery() {
1732
2121
  return {
1733
2122
  type: "SelectQuery",
1734
- table: this.table,
2123
+ table: this.tableName,
1735
2124
  fields: this.fields,
1736
2125
  conditions: this.serializableConditions(),
1737
2126
  sort: this.sort,
@@ -1752,13 +2141,25 @@ var QueryBuilderImpl = class {
1752
2141
  partition: this.partitionValue ?? null
1753
2142
  };
1754
2143
  }
2144
+ async getAllRecordsForFormatting() {
2145
+ if (this.mode !== "select") throw new Error("Formatting is only applicable in select mode.");
2146
+ const table = this.ensureTable();
2147
+ const select = this.toSelectQuery();
2148
+ const pageSize = this.pageSizeValue ?? void 0;
2149
+ const initialNextPage = this.nextPageValue ?? void 0;
2150
+ return collectAllQueryRecords((nextPage) => this.db._queryPage(table, select, {
2151
+ pageSize,
2152
+ nextPage,
2153
+ partition: this.partitionValue
2154
+ }), initialNextPage);
2155
+ }
1755
2156
  toSerializableQueryObject() {
1756
2157
  const table = this.ensureTable();
1757
2158
  const payload = this.mode === "update" ? this.toUpdateQuery() : this.toSelectQuery();
1758
2159
  return { ...payload, table };
1759
2160
  }
1760
2161
  from(table) {
1761
- this.table = table;
2162
+ this.tableName = table;
1762
2163
  return this;
1763
2164
  }
1764
2165
  select(...fields) {
@@ -1890,6 +2291,26 @@ var QueryBuilderImpl = class {
1890
2291
  async one() {
1891
2292
  return this.firstOrNull();
1892
2293
  }
2294
+ async table(options) {
2295
+ return formatQueryResultsAsTable(
2296
+ await this.getAllRecordsForFormatting(),
2297
+ options,
2298
+ this.fields ?? void 0
2299
+ );
2300
+ }
2301
+ async tree(options) {
2302
+ return formatQueryResultsAsTree(await this.getAllRecordsForFormatting(), options);
2303
+ }
2304
+ async csv(options) {
2305
+ return formatQueryResultsAsCsv(
2306
+ await this.getAllRecordsForFormatting(),
2307
+ options,
2308
+ this.fields ?? void 0
2309
+ );
2310
+ }
2311
+ async json(options) {
2312
+ return formatQueryResultsAsJson(await this.getAllRecordsForFormatting(), options);
2313
+ }
1893
2314
  async delete() {
1894
2315
  if (this.mode !== "select") throw new Error("delete() is only applicable in select mode.");
1895
2316
  const table = this.ensureTable();