@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/edge.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/edge.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/edge.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";
@@ -1044,6 +1044,374 @@ function computeSchemaDiff(apiSchema, localSchema) {
1044
1044
  return { newTables, removedTables, changedTables };
1045
1045
  }
1046
1046
 
1047
+ // src/helpers/query-formatters.ts
1048
+ var DEFAULT_TABLE_OPTIONS = {
1049
+ headers: true,
1050
+ maxColumnWidth: 80,
1051
+ flattenNestedObjects: false,
1052
+ nestedSeparator: ".",
1053
+ nullValue: ""
1054
+ };
1055
+ var DEFAULT_TREE_OPTIONS = {
1056
+ rootLabel: "results",
1057
+ keyField: "",
1058
+ includeRoot: true,
1059
+ maxDepth: Number.POSITIVE_INFINITY,
1060
+ nullValue: ""
1061
+ };
1062
+ var DEFAULT_CSV_OPTIONS = {
1063
+ headers: true,
1064
+ delimiter: ",",
1065
+ quote: '"',
1066
+ escape: '"',
1067
+ newline: "\n",
1068
+ flattenNestedObjects: true,
1069
+ nestedSeparator: ".",
1070
+ nullValue: ""
1071
+ };
1072
+ var DEFAULT_JSON_OPTIONS = {
1073
+ pretty: true,
1074
+ indent: 2
1075
+ };
1076
+ function isDate(value) {
1077
+ return value instanceof Date;
1078
+ }
1079
+ function isRecord(value) {
1080
+ return value !== null && typeof value === "object" && !Array.isArray(value) && !isDate(value);
1081
+ }
1082
+ function normalizeRecord(value) {
1083
+ if (isRecord(value)) {
1084
+ return value;
1085
+ }
1086
+ return { value };
1087
+ }
1088
+ function normalizeScalar(value, nullValue) {
1089
+ if (value == null) return nullValue;
1090
+ if (isDate(value)) return value.toISOString();
1091
+ if (typeof value === "string") return value;
1092
+ if (typeof value === "bigint") return value.toString();
1093
+ if (typeof value === "number" || typeof value === "boolean") return String(value);
1094
+ return JSON.stringify(value);
1095
+ }
1096
+ function inlineValue(value, nullValue) {
1097
+ if (value == null) return nullValue;
1098
+ if (isDate(value)) return value.toISOString();
1099
+ if (Array.isArray(value)) {
1100
+ return value.length === 0 ? "[]" : `[${value.map((entry) => inlineValue(entry, nullValue)).join(", ")}]`;
1101
+ }
1102
+ if (isRecord(value)) {
1103
+ const entries = Object.entries(value);
1104
+ if (entries.length === 0) return "{}";
1105
+ return entries.map(([key, entry]) => `${key}=${inlineValue(entry, nullValue)}`).join(", ");
1106
+ }
1107
+ if (typeof value === "bigint") return value.toString();
1108
+ return String(value);
1109
+ }
1110
+ function escapeTableCell(value) {
1111
+ return value.replace(/\r/g, "\\r").replace(/\n/g, "\\n");
1112
+ }
1113
+ function truncate(value, maxWidth) {
1114
+ if (maxWidth < 1) return "";
1115
+ if (value.length <= maxWidth) return value;
1116
+ if (maxWidth <= 3) return ".".repeat(maxWidth);
1117
+ return `${value.slice(0, Math.max(0, maxWidth - 3))}...`;
1118
+ }
1119
+ function padRight(value, width) {
1120
+ if (value.length >= width) return value;
1121
+ return value + " ".repeat(width - value.length);
1122
+ }
1123
+ function flattenValue(value, separator, prefix, out) {
1124
+ if (isRecord(value)) {
1125
+ const entries = Object.entries(value);
1126
+ if (entries.length === 0) {
1127
+ out[prefix] = {};
1128
+ return;
1129
+ }
1130
+ for (const [key, entry] of entries) {
1131
+ const path = prefix ? `${prefix}${separator}${key}` : key;
1132
+ flattenValue(entry, separator, path, out);
1133
+ }
1134
+ return;
1135
+ }
1136
+ if (Array.isArray(value)) {
1137
+ if (value.length === 0) {
1138
+ out[prefix] = [];
1139
+ return;
1140
+ }
1141
+ value.forEach((entry, index) => {
1142
+ const path = prefix ? `${prefix}${separator}${index}` : String(index);
1143
+ flattenValue(entry, separator, path, out);
1144
+ });
1145
+ return;
1146
+ }
1147
+ out[prefix] = value;
1148
+ }
1149
+ function toFlatRow(record, separator) {
1150
+ const out = {};
1151
+ for (const [key, value] of Object.entries(record)) {
1152
+ flattenValue(value, separator, key, out);
1153
+ }
1154
+ return out;
1155
+ }
1156
+ function discoveredColumns(rows) {
1157
+ const columns = [];
1158
+ const seen = /* @__PURE__ */ new Set();
1159
+ for (const row of rows) {
1160
+ for (const key of Object.keys(row)) {
1161
+ if (!seen.has(key)) {
1162
+ seen.add(key);
1163
+ columns.push(key);
1164
+ }
1165
+ }
1166
+ }
1167
+ return columns;
1168
+ }
1169
+ function orderColumns(discovered, preferred, flattenNestedObjects, separator) {
1170
+ if (!preferred || preferred.length === 0) return discovered;
1171
+ const ordered = [];
1172
+ const seen = /* @__PURE__ */ new Set();
1173
+ const addColumn = (column) => {
1174
+ if (!seen.has(column)) {
1175
+ seen.add(column);
1176
+ ordered.push(column);
1177
+ }
1178
+ };
1179
+ for (const field of preferred) {
1180
+ if (flattenNestedObjects) {
1181
+ let matched = false;
1182
+ for (const column of discovered) {
1183
+ if (column === field || column.startsWith(`${field}${separator}`)) {
1184
+ addColumn(column);
1185
+ matched = true;
1186
+ }
1187
+ }
1188
+ if (!matched) {
1189
+ addColumn(field);
1190
+ }
1191
+ continue;
1192
+ }
1193
+ addColumn(field);
1194
+ }
1195
+ for (const column of discovered) {
1196
+ addColumn(column);
1197
+ }
1198
+ return ordered;
1199
+ }
1200
+ function normalizeTableRows(records, preferredColumns, options) {
1201
+ const normalized = records.map(normalizeRecord);
1202
+ if (options.flattenNestedObjects) {
1203
+ const flatRows = normalized.map((record) => toFlatRow(record, options.nestedSeparator));
1204
+ const columns2 = orderColumns(
1205
+ discoveredColumns(flatRows),
1206
+ preferredColumns,
1207
+ true,
1208
+ options.nestedSeparator
1209
+ );
1210
+ const rows2 = flatRows.map((row) => columns2.map((column) => escapeTableCell(truncate(
1211
+ inlineValue(row[column], options.nullValue),
1212
+ options.maxColumnWidth
1213
+ ))));
1214
+ return { columns: columns2, rows: rows2 };
1215
+ }
1216
+ const topLevelRows = normalized.map((record) => ({ ...record }));
1217
+ const columns = orderColumns(
1218
+ discoveredColumns(topLevelRows),
1219
+ preferredColumns,
1220
+ false,
1221
+ options.nestedSeparator
1222
+ );
1223
+ const rows = topLevelRows.map((row) => columns.map((column) => escapeTableCell(truncate(
1224
+ inlineValue(row[column], options.nullValue),
1225
+ options.maxColumnWidth
1226
+ ))));
1227
+ return { columns, rows };
1228
+ }
1229
+ function formatQueryResultsAsTable(records, options, preferredColumns) {
1230
+ const final = { ...DEFAULT_TABLE_OPTIONS, ...options };
1231
+ const { columns, rows } = normalizeTableRows(records, preferredColumns, final);
1232
+ if (columns.length === 0) return "";
1233
+ const headerCells = columns.map((column) => truncate(column, final.maxColumnWidth));
1234
+ const widths = columns.map((_, index) => {
1235
+ const headerWidth = final.headers ? headerCells[index].length : 0;
1236
+ const rowWidth = rows.reduce((max2, row) => Math.max(max2, row[index].length), 0);
1237
+ return Math.max(headerWidth, rowWidth);
1238
+ });
1239
+ const border = (left, join, right) => `${left}${widths.map((width) => "\u2500".repeat(width + 2)).join(join)}${right}`;
1240
+ const renderRow = (cells) => `\u2502 ${cells.map((cell, index) => padRight(cell, widths[index])).join(" \u2502 ")} \u2502`;
1241
+ const lines = [border("\u250C", "\u252C", "\u2510")];
1242
+ if (final.headers) {
1243
+ lines.push(renderRow(headerCells));
1244
+ lines.push(border("\u251C", "\u253C", "\u2524"));
1245
+ }
1246
+ for (const row of rows) {
1247
+ lines.push(renderRow(row));
1248
+ }
1249
+ lines.push(border("\u2514", "\u2534", "\u2518"));
1250
+ return lines.join("\n");
1251
+ }
1252
+ function encodeCsvCell(value, options) {
1253
+ const escapedQuote = `${options.escape}${options.quote}`;
1254
+ const escaped = value.split(options.quote).join(escapedQuote);
1255
+ const needsQuoting = escaped.includes(options.delimiter) || escaped.includes(options.quote) || escaped.includes("\n") || escaped.includes("\r");
1256
+ if (!needsQuoting) return escaped;
1257
+ return `${options.quote}${escaped}${options.quote}`;
1258
+ }
1259
+ function normalizeCsvRows(records, preferredColumns, options) {
1260
+ const normalized = records.map(normalizeRecord);
1261
+ if (options.flattenNestedObjects) {
1262
+ const flatRows = normalized.map((record) => toFlatRow(record, options.nestedSeparator));
1263
+ const columns2 = orderColumns(
1264
+ discoveredColumns(flatRows),
1265
+ preferredColumns,
1266
+ true,
1267
+ options.nestedSeparator
1268
+ );
1269
+ const rows2 = flatRows.map((row) => columns2.map((column) => normalizeScalar(row[column], options.nullValue)));
1270
+ return { columns: columns2, rows: rows2 };
1271
+ }
1272
+ const topLevelRows = normalized.map((record) => ({ ...record }));
1273
+ const columns = orderColumns(
1274
+ discoveredColumns(topLevelRows),
1275
+ preferredColumns,
1276
+ false,
1277
+ options.nestedSeparator
1278
+ );
1279
+ const rows = topLevelRows.map((row) => columns.map((column) => inlineValue(row[column], options.nullValue)));
1280
+ return { columns, rows };
1281
+ }
1282
+ function formatQueryResultsAsCsv(records, options, preferredColumns) {
1283
+ const final = { ...DEFAULT_CSV_OPTIONS, ...options };
1284
+ const { columns, rows } = normalizeCsvRows(records, preferredColumns, final);
1285
+ const lines = [];
1286
+ if (final.headers && columns.length > 0) {
1287
+ lines.push(columns.map((column) => encodeCsvCell(column, final)).join(final.delimiter));
1288
+ }
1289
+ for (const row of rows) {
1290
+ lines.push(row.map((cell) => encodeCsvCell(cell, final)).join(final.delimiter));
1291
+ }
1292
+ return lines.join(final.newline);
1293
+ }
1294
+ function normalizeJsonValue(value) {
1295
+ if (value === void 0) return null;
1296
+ if (value === null) return null;
1297
+ if (isDate(value)) return value.toISOString();
1298
+ if (typeof value === "bigint") return value.toString();
1299
+ if (Array.isArray(value)) return value.map((entry) => normalizeJsonValue(entry));
1300
+ if (isRecord(value)) {
1301
+ const out = {};
1302
+ for (const [key, entry] of Object.entries(value)) {
1303
+ out[key] = normalizeJsonValue(entry);
1304
+ }
1305
+ return out;
1306
+ }
1307
+ return value;
1308
+ }
1309
+ function formatQueryResultsAsJson(records, options) {
1310
+ const final = { ...DEFAULT_JSON_OPTIONS, ...options };
1311
+ const normalized = records.map((record) => normalizeJsonValue(normalizeRecord(record)));
1312
+ return final.pretty ? JSON.stringify(normalized, null, final.indent) : JSON.stringify(normalized);
1313
+ }
1314
+ function findDefaultTreeKeyField(record) {
1315
+ for (const candidate of ["code", "id", "name"]) {
1316
+ if (candidate in record) return candidate;
1317
+ }
1318
+ const keys = Object.keys(record);
1319
+ return keys.length > 0 ? keys[0] : void 0;
1320
+ }
1321
+ function buildTreeNodesFromValue(value, options, depth) {
1322
+ if (depth >= options.maxDepth) {
1323
+ return [{ label: inlineValue(value, options.nullValue) }];
1324
+ }
1325
+ if (Array.isArray(value)) {
1326
+ return value.map((entry, index) => {
1327
+ if (!isRecord(entry) && !Array.isArray(entry)) {
1328
+ return { label: `[${index}]: ${inlineValue(entry, options.nullValue)}` };
1329
+ }
1330
+ return {
1331
+ label: `[${index}]`,
1332
+ children: buildTreeNodesFromValue(entry, options, depth + 1)
1333
+ };
1334
+ });
1335
+ }
1336
+ return Object.entries(value).map(([key, entry]) => {
1337
+ if (isRecord(entry) || Array.isArray(entry)) {
1338
+ if (depth + 1 >= options.maxDepth) {
1339
+ return { label: `${key}: ${inlineValue(entry, options.nullValue)}` };
1340
+ }
1341
+ return {
1342
+ label: key,
1343
+ children: buildTreeNodesFromValue(entry, options, depth + 1)
1344
+ };
1345
+ }
1346
+ return { label: `${key}: ${inlineValue(entry, options.nullValue)}` };
1347
+ });
1348
+ }
1349
+ function buildRecordTreeNode(record, index, options) {
1350
+ const keyField = options.keyField || findDefaultTreeKeyField(record);
1351
+ const entries = Object.entries(record);
1352
+ if (!keyField || !(keyField in record)) {
1353
+ return {
1354
+ label: `row ${index + 1}`,
1355
+ children: buildTreeNodesFromValue(record, options, 0)
1356
+ };
1357
+ }
1358
+ const labelValue = inlineValue(record[keyField], options.nullValue);
1359
+ const childEntries = entries.filter(([key]) => key !== keyField);
1360
+ return {
1361
+ label: labelValue,
1362
+ children: childEntries.length > 0 ? childEntries.map(([key, value]) => {
1363
+ if (isRecord(value) || Array.isArray(value)) {
1364
+ if (1 > options.maxDepth) {
1365
+ return { label: `${key}: ${inlineValue(value, options.nullValue)}` };
1366
+ }
1367
+ return {
1368
+ label: key,
1369
+ children: buildTreeNodesFromValue(value, options, 1)
1370
+ };
1371
+ }
1372
+ return { label: `${key}: ${inlineValue(value, options.nullValue)}` };
1373
+ }) : void 0
1374
+ };
1375
+ }
1376
+ function renderTreeNodes(nodes, prefix = "") {
1377
+ const lines = [];
1378
+ nodes.forEach((node, index) => {
1379
+ const isLast = index === nodes.length - 1;
1380
+ const branch = isLast ? "\u2514\u2500 " : "\u251C\u2500 ";
1381
+ lines.push(`${prefix}${branch}${node.label}`);
1382
+ if (node.children && node.children.length > 0) {
1383
+ const childPrefix = `${prefix}${isLast ? " " : "\u2502 "}`;
1384
+ lines.push(...renderTreeNodes(node.children, childPrefix));
1385
+ }
1386
+ });
1387
+ return lines;
1388
+ }
1389
+ function formatQueryResultsAsTree(records, options) {
1390
+ const final = { ...DEFAULT_TREE_OPTIONS, ...options };
1391
+ const nodes = records.map((record, index) => buildRecordTreeNode(normalizeRecord(record), index, final));
1392
+ if (!final.includeRoot) {
1393
+ return renderTreeNodes(nodes).join("\n");
1394
+ }
1395
+ const lines = [final.rootLabel];
1396
+ if (nodes.length > 0) {
1397
+ lines.push(...renderTreeNodes(nodes));
1398
+ }
1399
+ return lines.join("\n");
1400
+ }
1401
+ async function collectAllQueryRecords(getPage, initialNextPage) {
1402
+ const records = [];
1403
+ let nextPage = initialNextPage;
1404
+ while (true) {
1405
+ const page = await getPage(nextPage);
1406
+ if (Array.isArray(page.records)) {
1407
+ records.push(...page.records);
1408
+ }
1409
+ if (!page.nextPage) break;
1410
+ nextPage = page.nextPage;
1411
+ }
1412
+ return records;
1413
+ }
1414
+
1047
1415
  // src/impl/onyx-core.ts
1048
1416
  var DEFAULT_CACHE_TTL = 5 * 60 * 1e3;
1049
1417
  function toSingleCondition(criteria) {
@@ -1277,6 +1645,27 @@ var OnyxDatabaseImpl = class {
1277
1645
  const { http } = await this.ensureAiClient();
1278
1646
  return http.request("POST", "/api/script-approvals", input);
1279
1647
  }
1648
+ async predict(publishedModelId, inputs) {
1649
+ const { http, databaseId } = await this.ensureClient();
1650
+ const path = `/data/${encodeURIComponent(
1651
+ databaseId
1652
+ )}/model-builder/published-model/${encodeURIComponent(publishedModelId)}/predict`;
1653
+ return http.request(
1654
+ "POST",
1655
+ path,
1656
+ serializeDates({ inputs })
1657
+ );
1658
+ }
1659
+ async predictFromScript(publishedModelId, scriptId, scriptParameters = {}) {
1660
+ const { http, databaseId } = await this.ensureClient();
1661
+ const path = `/data/${encodeURIComponent(
1662
+ databaseId
1663
+ )}/model-builder/published-model/${encodeURIComponent(publishedModelId)}/predict/script`;
1664
+ return http.request("POST", path, {
1665
+ scriptId,
1666
+ scriptParameters
1667
+ });
1668
+ }
1280
1669
  from(table) {
1281
1670
  return new QueryBuilderImpl(this, String(table), this.defaultPartition);
1282
1671
  }
@@ -1551,7 +1940,7 @@ var OnyxDatabaseImpl = class {
1551
1940
  };
1552
1941
  var QueryBuilderImpl = class {
1553
1942
  db;
1554
- table;
1943
+ tableName;
1555
1944
  fields = null;
1556
1945
  resolvers = null;
1557
1946
  conditions = null;
@@ -1570,12 +1959,12 @@ var QueryBuilderImpl = class {
1570
1959
  onItemListener = null;
1571
1960
  constructor(db, table, partition) {
1572
1961
  this.db = db;
1573
- this.table = table;
1962
+ this.tableName = table;
1574
1963
  this.partitionValue = partition;
1575
1964
  }
1576
1965
  ensureTable() {
1577
- if (!this.table) throw new Error("Table is not defined. Call from(<table>) first.");
1578
- return this.table;
1966
+ if (!this.tableName) throw new Error("Table is not defined. Call from(<table>) first.");
1967
+ return this.tableName;
1579
1968
  }
1580
1969
  serializableConditions() {
1581
1970
  return normalizeCondition(this.conditions);
@@ -1583,7 +1972,7 @@ var QueryBuilderImpl = class {
1583
1972
  toSelectQuery() {
1584
1973
  return {
1585
1974
  type: "SelectQuery",
1586
- table: this.table,
1975
+ table: this.tableName,
1587
1976
  fields: this.fields,
1588
1977
  conditions: this.serializableConditions(),
1589
1978
  sort: this.sort,
@@ -1604,13 +1993,25 @@ var QueryBuilderImpl = class {
1604
1993
  partition: this.partitionValue ?? null
1605
1994
  };
1606
1995
  }
1996
+ async getAllRecordsForFormatting() {
1997
+ if (this.mode !== "select") throw new Error("Formatting is only applicable in select mode.");
1998
+ const table = this.ensureTable();
1999
+ const select = this.toSelectQuery();
2000
+ const pageSize = this.pageSizeValue ?? void 0;
2001
+ const initialNextPage = this.nextPageValue ?? void 0;
2002
+ return collectAllQueryRecords((nextPage) => this.db._queryPage(table, select, {
2003
+ pageSize,
2004
+ nextPage,
2005
+ partition: this.partitionValue
2006
+ }), initialNextPage);
2007
+ }
1607
2008
  toSerializableQueryObject() {
1608
2009
  const table = this.ensureTable();
1609
2010
  const payload = this.mode === "update" ? this.toUpdateQuery() : this.toSelectQuery();
1610
2011
  return { ...payload, table };
1611
2012
  }
1612
2013
  from(table) {
1613
- this.table = table;
2014
+ this.tableName = table;
1614
2015
  return this;
1615
2016
  }
1616
2017
  select(...fields) {
@@ -1742,6 +2143,26 @@ var QueryBuilderImpl = class {
1742
2143
  async one() {
1743
2144
  return this.firstOrNull();
1744
2145
  }
2146
+ async table(options) {
2147
+ return formatQueryResultsAsTable(
2148
+ await this.getAllRecordsForFormatting(),
2149
+ options,
2150
+ this.fields ?? void 0
2151
+ );
2152
+ }
2153
+ async tree(options) {
2154
+ return formatQueryResultsAsTree(await this.getAllRecordsForFormatting(), options);
2155
+ }
2156
+ async csv(options) {
2157
+ return formatQueryResultsAsCsv(
2158
+ await this.getAllRecordsForFormatting(),
2159
+ options,
2160
+ this.fields ?? void 0
2161
+ );
2162
+ }
2163
+ async json(options) {
2164
+ return formatQueryResultsAsJson(await this.getAllRecordsForFormatting(), options);
2165
+ }
1745
2166
  async delete() {
1746
2167
  if (this.mode !== "select") throw new Error("delete() is only applicable in select mode.");
1747
2168
  const table = this.ensureTable();