@xanots/sdk 0.0.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.
Files changed (106) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +384 -0
  3. package/dist/agent-file-refresh-7XCACU34.js +95 -0
  4. package/dist/bin.d.ts +1 -0
  5. package/dist/bin.js +184 -0
  6. package/dist/capture-HUV5BNTC.js +32 -0
  7. package/dist/chunk-26CNBZE2.js +963 -0
  8. package/dist/chunk-33ND6LKO.js +78 -0
  9. package/dist/chunk-3DUAGYGP.js +1550 -0
  10. package/dist/chunk-3IGNIP6R.js +89 -0
  11. package/dist/chunk-47WDWMBJ.js +14 -0
  12. package/dist/chunk-4BXJGVZ3.js +318 -0
  13. package/dist/chunk-4HT3BNZ7.js +675 -0
  14. package/dist/chunk-4YMD2OOZ.js +23 -0
  15. package/dist/chunk-5WGEURVI.js +156 -0
  16. package/dist/chunk-5YTBTF25.js +29 -0
  17. package/dist/chunk-6DHBYBTO.js +166 -0
  18. package/dist/chunk-76QBEIGO.js +66 -0
  19. package/dist/chunk-7DKX2SPN.js +100 -0
  20. package/dist/chunk-7REDODS2.js +468 -0
  21. package/dist/chunk-C56BC2FY.js +254 -0
  22. package/dist/chunk-DGSF2Q5H.js +60 -0
  23. package/dist/chunk-EMCAWMHC.js +3982 -0
  24. package/dist/chunk-EZG76F7R.js +159 -0
  25. package/dist/chunk-FJ6ZS5KB.js +3607 -0
  26. package/dist/chunk-GNPVYOPB.js +17 -0
  27. package/dist/chunk-HJPTWBLH.js +38 -0
  28. package/dist/chunk-IZW6MK3U.js +248 -0
  29. package/dist/chunk-LH6Z6KFV.js +247 -0
  30. package/dist/chunk-MZUI3JNX.js +93 -0
  31. package/dist/chunk-NDZFBZHC.js +167 -0
  32. package/dist/chunk-NOO35BQ2.js +37 -0
  33. package/dist/chunk-NUQCEOKA.js +13 -0
  34. package/dist/chunk-QTNO2WD6.js +56 -0
  35. package/dist/chunk-RVB7ITKN.js +49 -0
  36. package/dist/chunk-TRU5OHQ5.js +6904 -0
  37. package/dist/chunk-VKFQJEMW.js +814 -0
  38. package/dist/chunk-VTIL47DT.js +125 -0
  39. package/dist/chunk-WHOJWOSV.js +112 -0
  40. package/dist/chunk-WKP4D5MO.js +1692 -0
  41. package/dist/chunk-X4DVXBFY.js +38 -0
  42. package/dist/chunk-XQ22GLYS.js +118 -0
  43. package/dist/chunk-YDZYMZBE.js +670 -0
  44. package/dist/chunk-YGPIY3WT.js +1146 -0
  45. package/dist/chunk-YYRDLFSJ.js +602 -0
  46. package/dist/chunk-ZUTSMMAG.js +46 -0
  47. package/dist/cli.d.ts +331 -0
  48. package/dist/cli.js +33 -0
  49. package/dist/codegen-command-OOKK6AZK.js +40 -0
  50. package/dist/codegen.d.ts +114 -0
  51. package/dist/codegen.js +71 -0
  52. package/dist/completion-TIPPZN7H.js +298 -0
  53. package/dist/config-NL33PN4D.js +84 -0
  54. package/dist/deploy-command-4EQ7XX5G.js +451 -0
  55. package/dist/env-target-IFJ5QDHC.js +16 -0
  56. package/dist/ephemeral-command-3X3I4ULC.js +242 -0
  57. package/dist/index.d.ts +4477 -0
  58. package/dist/index.js +300 -0
  59. package/dist/init-command-R6H7ZXW5.js +27 -0
  60. package/dist/internal.d.ts +74 -0
  61. package/dist/internal.js +2065 -0
  62. package/dist/io-AMIKRLPC.js +11 -0
  63. package/dist/live-diff-Y3AKETHE.js +196 -0
  64. package/dist/lock-3CVKALKT.js +37 -0
  65. package/dist/lock-commands-XTR2YKLY.js +232 -0
  66. package/dist/login-command-ACJF6KWQ.js +167 -0
  67. package/dist/logout-command-MX3MJS5U.js +68 -0
  68. package/dist/loop-OM3P2Z6O.js +93 -0
  69. package/dist/marketplace-command-RATXTKXN.js +379 -0
  70. package/dist/meta-client-OW5WKWW7.js +170 -0
  71. package/dist/node.d.ts +59 -0
  72. package/dist/node.js +442 -0
  73. package/dist/profile-command-SWJ3SPKR.js +77 -0
  74. package/dist/release-command-VV5UVZKL.js +427 -0
  75. package/dist/response-CVAE2kMj.d.ts +1915 -0
  76. package/dist/routes-manifest-SP3ZXLMR.js +244 -0
  77. package/dist/runtime-V4C3AC3A.js +13 -0
  78. package/dist/sandbox-details-command-HJE5SPVG.js +18 -0
  79. package/dist/sandbox-export-command-QCJY4GMV.js +24 -0
  80. package/dist/static-host-D6KS7X45.js +138 -0
  81. package/dist/store-BQ97nKIF.d.ts +7760 -0
  82. package/dist/test-command-TSPBQHBM.js +383 -0
  83. package/dist/validate-command-4ERHJSCO.js +122 -0
  84. package/dist/verify-rollout-FAVQ6EJY.js +40 -0
  85. package/dist/workspace-K72NP7SX.js +49 -0
  86. package/dist/workspace-command-OF23DPNI.js +156 -0
  87. package/dist/workspace-export-AJMGN3CQ.js +10 -0
  88. package/llms/fields.md +104 -0
  89. package/llms/filters.md +183 -0
  90. package/llms/kinds-agent-mcp.md +11 -0
  91. package/llms/kinds-core.md +68 -0
  92. package/llms/kinds-realtime.md +76 -0
  93. package/llms/lambda.md +111 -0
  94. package/llms/legacy.md +43 -0
  95. package/llms/object-kinds.md +31 -0
  96. package/llms/statements-calls.md +23 -0
  97. package/llms/statements-catalog.md +309 -0
  98. package/llms/statements-data.md +58 -0
  99. package/llms/statements-runtime.md +48 -0
  100. package/llms/tests.md +58 -0
  101. package/llms/triggers.md +22 -0
  102. package/llms/values.md +29 -0
  103. package/llms-full.txt +1672 -0
  104. package/llms.txt +483 -0
  105. package/manifest.json +9592 -0
  106. package/package.json +110 -0
@@ -0,0 +1,1146 @@
1
+ import {
2
+ UsageError,
3
+ extraArguments,
4
+ missingArgument,
5
+ removedSubcommand,
6
+ renderGlobalHelp,
7
+ renderHelpFor,
8
+ unknownCommand,
9
+ unknownFlag,
10
+ unknownHelpTopic,
11
+ unknownSubcommand
12
+ } from "./chunk-IZW6MK3U.js";
13
+ import {
14
+ detail,
15
+ info,
16
+ stdoutStyle,
17
+ warn
18
+ } from "./chunk-EZG76F7R.js";
19
+ import {
20
+ Xano,
21
+ assertSeedIds,
22
+ coerceSeedRowValues
23
+ } from "./chunk-3DUAGYGP.js";
24
+ import {
25
+ getCommand,
26
+ getSubcommand,
27
+ isCommand,
28
+ suggest
29
+ } from "./chunk-YYRDLFSJ.js";
30
+ import {
31
+ FILTER_NAMES,
32
+ SEED_FILE,
33
+ buildContentEnvelope,
34
+ emit,
35
+ emitBundle,
36
+ isQueryExpressionFilter,
37
+ isSeedFileSource,
38
+ pathSegment,
39
+ serializeBundle,
40
+ tableColumns
41
+ } from "./chunk-EMCAWMHC.js";
42
+ import {
43
+ readLockFile,
44
+ writeLockFile
45
+ } from "./chunk-HJPTWBLH.js";
46
+ import {
47
+ WORKSPACE_KEY,
48
+ createLockContext,
49
+ emptyLock,
50
+ lockKey,
51
+ mergeObserved,
52
+ resetLockOverrides,
53
+ resolveRef,
54
+ seedLockOverrides,
55
+ serializeLock,
56
+ validateLockModel
57
+ } from "./chunk-4HT3BNZ7.js";
58
+
59
+ // src/emit/cli.ts
60
+ import { pathToFileURL as pathToFileURL2, fileURLToPath as fileURLToPath2 } from "url";
61
+ import { existsSync, readdirSync, readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "fs";
62
+ import { basename, dirname, join, relative, resolve } from "path";
63
+ import { createRequire } from "module";
64
+
65
+ // src/workspace/seed.ts
66
+ import { createHash } from "crypto";
67
+ import { readFileSync } from "fs";
68
+ import { fileURLToPath, pathToFileURL } from "url";
69
+ var SEED_PAGE_TARGET_BYTES = 512 * 1024;
70
+ async function resolveSeedRows(source) {
71
+ if (isSeedFileSource(source)) return readSeedFile(source[SEED_FILE]);
72
+ const resolved = typeof source === "function" ? await source() : source;
73
+ const rows = Array.isArray(resolved) ? resolved : unwrapDefaultExport(resolved);
74
+ if (!Array.isArray(rows)) {
75
+ throw new Error(`seed source did not resolve to an array of rows (got ${typeof resolved}).`);
76
+ }
77
+ return rows;
78
+ }
79
+ function readSeedFile(ref) {
80
+ const where = `seedFile("${ref.path}")`;
81
+ const base = /^[a-z][a-z0-9+.-]*:/i.test(ref.base) ? ref.base : pathToFileURL(ref.base).href;
82
+ const file = fileURLToPath(new URL(ref.path, base));
83
+ let text;
84
+ try {
85
+ text = readFileSync(file, "utf8");
86
+ } catch (cause) {
87
+ throw new Error(
88
+ `${where}: cannot read "${file}". The path is resolved relative to the module that declares the table (the \`import.meta.url\` you passed as \`base\`).`,
89
+ { cause }
90
+ );
91
+ }
92
+ let parsed;
93
+ try {
94
+ parsed = JSON.parse(text);
95
+ } catch (cause) {
96
+ throw new Error(`${where}: "${file}" is not valid JSON \u2014 ${cause.message}`, {
97
+ cause
98
+ });
99
+ }
100
+ const rows = Array.isArray(parsed) ? parsed : unwrapDefaultExport(parsed);
101
+ if (!Array.isArray(rows)) {
102
+ throw new Error(
103
+ `${where}: "${file}" must hold an array of seed rows (got ${typeof parsed}).`
104
+ );
105
+ }
106
+ return rows;
107
+ }
108
+ function unwrapDefaultExport(value) {
109
+ if (value === null || typeof value !== "object") return value;
110
+ const fallback = value.default;
111
+ return Array.isArray(fallback) ? fallback : value;
112
+ }
113
+ function coerceSeedRows(tableName, columns, rows) {
114
+ const coerced = coerceSeedRowValues(tableName, columns, rows);
115
+ assignPrimaryKeys(tableName, columns, coerced);
116
+ return coerced;
117
+ }
118
+ function assignPrimaryKeys(tableName, columns, rows) {
119
+ if (!assertSeedIds(tableName, columns, rows)) return;
120
+ const idType = columns.find((c) => c.name === "id")?.type;
121
+ rows.forEach((r, i) => {
122
+ r.id = idType === "int" ? i + 1 : seedUuid(tableName, i);
123
+ });
124
+ }
125
+ function seedUuid(tableName, index) {
126
+ const h = createHash("sha256").update(`xanots:seed-id:${tableName}:${index}`).digest("hex");
127
+ const version5 = `5${h.slice(13, 16)}`;
128
+ const variant = (parseInt(h.slice(16, 17), 16) & 3 | 8).toString(16) + h.slice(17, 20);
129
+ return `${h.slice(0, 8)}-${h.slice(8, 12)}-${version5}-${variant}-${h.slice(20, 32)}`;
130
+ }
131
+ function paginateRows(rows, budgetBytes = SEED_PAGE_TARGET_BYTES) {
132
+ const pages = [];
133
+ let page = [];
134
+ let size = 0;
135
+ for (const row of rows) {
136
+ const rowBytes = Buffer.byteLength(JSON.stringify(row), "utf8");
137
+ if (page.length > 0 && size + rowBytes > budgetBytes) {
138
+ pages.push(page);
139
+ page = [];
140
+ size = 0;
141
+ }
142
+ page.push(row);
143
+ size += rowBytes;
144
+ }
145
+ if (page.length > 0) pages.push(page);
146
+ return pages;
147
+ }
148
+ async function buildSeedContentFiles(tableDefs) {
149
+ const files = [];
150
+ for (const def of tableDefs) {
151
+ if (def.seed === void 0) continue;
152
+ const rows = await resolveSeedRows(def.seed);
153
+ if (rows.length === 0) continue;
154
+ const coerced = coerceSeedRows(def.name, tableColumns(def), rows);
155
+ const guid = resolveRef("dbo", def);
156
+ const pages = paginateRows(coerced);
157
+ pages.forEach((page, i) => {
158
+ files.push({ name: `content/${guid}-${i + 1}.json`, content: JSON.stringify(buildContentEnvelope(page)) });
159
+ });
160
+ }
161
+ return files;
162
+ }
163
+ var MIN_SCANNABLE_LENGTH = 6;
164
+ async function collectNonPublicSeedValues(tableDefs) {
165
+ const found = [];
166
+ for (const def of tableDefs) {
167
+ if (def.seed === void 0) continue;
168
+ const guarded = tableColumns(def).filter(
169
+ (col) => col.access === "internal" || col.sensitive === true
170
+ );
171
+ if (guarded.length === 0) continue;
172
+ const rows = await resolveSeedRows(def.seed);
173
+ for (const row of rows) {
174
+ for (const col of guarded) {
175
+ const value = row[col.name];
176
+ if (value === void 0 || value === null) continue;
177
+ const scannable = typeof value === "string" && value.length >= MIN_SCANNABLE_LENGTH;
178
+ found.push({ table: def.name, column: col.name, value: String(value), scannable });
179
+ }
180
+ }
181
+ }
182
+ return found;
183
+ }
184
+
185
+ // src/emit/write.ts
186
+ import { writeFileSync } from "fs";
187
+ function writeArtifact(fn, path, opts = {}) {
188
+ writeFileSync(path, emit(fn, opts) + "\n", "utf8");
189
+ }
190
+ function writeBundle(xano, path, opts = {}) {
191
+ writeFileSync(path, emitBundle(xano, opts) + "\n", "utf8");
192
+ }
193
+
194
+ // src/validate/filter-names.ts
195
+ var RESOLVABLE = new Set(FILTER_NAMES);
196
+ var QUERY_EXPRESSION_KEYS = /* @__PURE__ */ new Set(["eval", "search", "sort", "aggregate"]);
197
+ function editDistance(a, b) {
198
+ let prev = Array.from({ length: b.length + 1 }, (_, j) => j);
199
+ for (let i = 1; i <= a.length; i++) {
200
+ const curr = [i];
201
+ for (let j = 1; j <= b.length; j++) {
202
+ const cost = a[i - 1] === b[j - 1] ? 0 : 1;
203
+ curr[j] = Math.min(prev[j] + 1, curr[j - 1] + 1, prev[j - 1] + cost);
204
+ }
205
+ prev = curr;
206
+ }
207
+ return prev[b.length];
208
+ }
209
+ function suggestFilterNames(name) {
210
+ const AFFIX_MAX = 6;
211
+ const affix = (long, short) => (long.startsWith(short) || long.endsWith(short)) && long.length - short.length <= AFFIX_MAX;
212
+ const substr = FILTER_NAMES.filter(
213
+ (r) => name.length >= r.length ? affix(name, r) : affix(r, name)
214
+ ).sort((a, b) => Math.abs(a.length - name.length) - Math.abs(b.length - name.length));
215
+ if (substr.length) return substr.slice(0, 2);
216
+ const near = (d) => d === 1 || d === 2 && name.length >= 6;
217
+ return FILTER_NAMES.map((r) => ({ r, d: editDistance(name, r) })).filter((x) => near(x.d)).sort((a, b) => a.d - b.d).slice(0, 2).map((x) => x.r);
218
+ }
219
+ function findUnresolvableFilters(bundle) {
220
+ const findings = [];
221
+ const seen = /* @__PURE__ */ new Set();
222
+ const walk = (node, context, inQuery = false) => {
223
+ if (Array.isArray(node)) {
224
+ for (const item of node) walk(item, context, inQuery);
225
+ return;
226
+ }
227
+ if (node === null || typeof node !== "object") return;
228
+ const obj = node;
229
+ const nm = obj.name;
230
+ const nextContext = typeof nm === "string" && nm !== "" && !nm.includes(":") ? nm : context;
231
+ const filters = obj.filters;
232
+ if (Array.isArray(filters)) {
233
+ for (const f of filters) {
234
+ const fname = f?.name;
235
+ const resolvable = typeof fname === "string" && (RESOLVABLE.has(fname) || inQuery && isQueryExpressionFilter(fname));
236
+ if (typeof fname === "string" && fname !== "" && !resolvable) {
237
+ const key = `${fname}@${nextContext}`;
238
+ if (!seen.has(key)) {
239
+ seen.add(key);
240
+ findings.push({ name: fname, location: nextContext || "(unknown)", suggestions: suggestFilterNames(fname) });
241
+ }
242
+ }
243
+ }
244
+ }
245
+ for (const [key, value] of Object.entries(obj)) {
246
+ walk(value, nextContext, inQuery || QUERY_EXPRESSION_KEYS.has(key));
247
+ }
248
+ };
249
+ walk(bundle, "");
250
+ return findings;
251
+ }
252
+
253
+ // src/emit/cli.ts
254
+ function parsePort(raw) {
255
+ const n = Number(raw);
256
+ if (!Number.isInteger(n) || n < 0 || n > 65535) {
257
+ throw new Error(`--port must be an integer 0-65535 (got "${raw ?? ""}").`);
258
+ }
259
+ return n;
260
+ }
261
+ var NOUN_COMMANDS = /* @__PURE__ */ new Set(["sandbox", "profile", "ephemeral", "workspace", "marketplace", "test"]);
262
+ function helpTargetFor(command, subcommand) {
263
+ if (command === void 0 || !isCommand(command)) return void 0;
264
+ return subcommand !== void 0 && getSubcommand(command, subcommand) !== void 0 ? { command, subcommand } : { command };
265
+ }
266
+ function maxPositionals(args) {
267
+ if (args === void 0) return 0;
268
+ return args.some((a) => a.variadic === true) ? Number.POSITIVE_INFINITY : args.length;
269
+ }
270
+ function positionalBudget(command, subcommand, positionals) {
271
+ const spec = getCommand(command);
272
+ if (spec === void 0 || spec.removed !== void 0) return void 0;
273
+ if (spec.subcommands === void 0) {
274
+ return { max: maxPositionals(spec.args), given: positionals, offset: 0, target: { command } };
275
+ }
276
+ const offset = command === "lock" ? 1 : 0;
277
+ const verb = offset === 1 ? positionals[0] : subcommand;
278
+ if (verb === void 0) return void 0;
279
+ const sub = getSubcommand(command, verb);
280
+ if (sub === void 0 || sub.removed !== void 0) return void 0;
281
+ return {
282
+ max: maxPositionals(sub.args),
283
+ given: positionals.slice(offset),
284
+ offset,
285
+ target: { command, subcommand: verb }
286
+ };
287
+ }
288
+ function parseArgs(argv) {
289
+ const [command, ...afterCommand] = argv;
290
+ let subcommand;
291
+ let rest = afterCommand;
292
+ if (command !== void 0 && NOUN_COMMANDS.has(command)) {
293
+ subcommand = afterCommand[0];
294
+ rest = afterCommand.slice(1);
295
+ }
296
+ let out;
297
+ let lock = false;
298
+ let lockPath;
299
+ let entryPath;
300
+ let frozenLock = false;
301
+ let strict = false;
302
+ let yes = false;
303
+ let bundle;
304
+ let reset = false;
305
+ let dest;
306
+ let kind;
307
+ let concurrency;
308
+ let test = false;
309
+ let expiresHours;
310
+ let staticDir;
311
+ let staticHost;
312
+ let staticRouting;
313
+ const staticEnv = {};
314
+ let authHost;
315
+ let authFile;
316
+ let useLocal = false;
317
+ let allWorkspaces = false;
318
+ let guest = false;
319
+ let urlOnly = false;
320
+ let prompt = false;
321
+ let port;
322
+ let scope;
323
+ let runtime = false;
324
+ let capture = false;
325
+ let verbose = false;
326
+ let instance;
327
+ let format;
328
+ let path;
329
+ let name;
330
+ const ai = [];
331
+ let framework;
332
+ let force = false;
333
+ let noInstall = false;
334
+ let noVerify = false;
335
+ let requireMicroservices = false;
336
+ let report;
337
+ let allowSeedInStatic = false;
338
+ let dryRun = false;
339
+ let prune = false;
340
+ let resetData = false;
341
+ let seed = false;
342
+ let replace = false;
343
+ let emit2;
344
+ let json = false;
345
+ let open = false;
346
+ const positionals = [];
347
+ const positionalAt = [];
348
+ const unknownFlags = [];
349
+ for (let i = 0; i < rest.length; i++) {
350
+ const arg = rest[i];
351
+ if (arg === "--out" || arg === "-o") {
352
+ out = rest[++i];
353
+ } else if (arg === "--emit") {
354
+ emit2 = rest[++i];
355
+ } else if (arg.startsWith("--emit=")) {
356
+ emit2 = arg.slice("--emit=".length);
357
+ } else if (arg === "--lock") {
358
+ lock = true;
359
+ } else if (arg.startsWith("--lock=")) {
360
+ lock = true;
361
+ lockPath = arg.slice("--lock=".length);
362
+ } else if (arg === "--entry") {
363
+ entryPath = rest[++i];
364
+ } else if (arg.startsWith("--entry=")) {
365
+ entryPath = arg.slice("--entry=".length);
366
+ } else if (arg === "--frozen-lock") {
367
+ frozenLock = true;
368
+ } else if (arg === "--strict") {
369
+ strict = true;
370
+ } else if (arg === "--yes" || arg === "-y") {
371
+ yes = true;
372
+ } else if (arg === "--bundle") {
373
+ bundle = rest[++i];
374
+ } else if (arg.startsWith("--bundle=")) {
375
+ bundle = arg.slice("--bundle=".length);
376
+ } else if (arg === "--reset") {
377
+ reset = true;
378
+ } else if (arg === "--dest") {
379
+ dest = parseDest(rest[++i]);
380
+ } else if (arg.startsWith("--dest=")) {
381
+ dest = parseDest(arg.slice("--dest=".length));
382
+ } else if (arg === "--kind") {
383
+ kind = parseKind(rest[++i]);
384
+ } else if (arg.startsWith("--kind=")) {
385
+ kind = parseKind(arg.slice("--kind=".length));
386
+ } else if (arg === "--concurrency") {
387
+ concurrency = parseConcurrency(rest[++i]);
388
+ } else if (arg.startsWith("--concurrency=")) {
389
+ concurrency = parseConcurrency(arg.slice("--concurrency=".length));
390
+ } else if (arg === "--test") {
391
+ test = true;
392
+ } else if (arg === "--expires-hours") {
393
+ expiresHours = parseExpiresHours(rest[++i]);
394
+ } else if (arg.startsWith("--expires-hours=")) {
395
+ expiresHours = parseExpiresHours(arg.slice("--expires-hours=".length));
396
+ } else if (arg === "--static-env" || arg.startsWith("--static-env=")) {
397
+ const kv = arg === "--static-env" ? rest[++i] : arg.slice("--static-env=".length);
398
+ const eq = kv?.indexOf("=") ?? -1;
399
+ if (kv === void 0 || eq <= 0) {
400
+ throw new Error(`--static-env expects KEY=VALUE (got "${kv ?? ""}").`);
401
+ }
402
+ staticEnv[kv.slice(0, eq)] = kv.slice(eq + 1);
403
+ } else if (arg === "--static-host") {
404
+ staticHost = rest[++i];
405
+ } else if (arg.startsWith("--static-host=")) {
406
+ staticHost = arg.slice("--static-host=".length);
407
+ } else if (arg === "--static-routing" || arg.startsWith("--static-routing=")) {
408
+ const v = arg === "--static-routing" ? rest[++i] : arg.slice("--static-routing=".length);
409
+ if (v !== "spa" && v !== "multipage") {
410
+ throw new Error(`--static-routing expects "spa" or "multipage" (got "${v ?? ""}").`);
411
+ }
412
+ staticRouting = v;
413
+ } else if (arg === "--static") {
414
+ staticDir = rest[++i];
415
+ } else if (arg.startsWith("--static=")) {
416
+ staticDir = arg.slice("--static=".length);
417
+ } else if (arg === "--origin") {
418
+ authHost = rest[++i];
419
+ } else if (arg.startsWith("--origin=")) {
420
+ authHost = arg.slice("--origin=".length);
421
+ } else if (arg === "--config") {
422
+ authFile = rest[++i];
423
+ } else if (arg.startsWith("--config=")) {
424
+ authFile = arg.slice("--config=".length);
425
+ } else if (arg === "--local") {
426
+ useLocal = true;
427
+ } else if (arg === "--all-workspaces") {
428
+ allWorkspaces = true;
429
+ } else if (arg === "--guest" || arg === "-g") {
430
+ guest = true;
431
+ } else if (arg === "--url-only" || arg === "-u") {
432
+ urlOnly = true;
433
+ } else if (arg === "--prompt") {
434
+ prompt = true;
435
+ } else if (arg === "--port") {
436
+ port = parsePort(rest[++i]);
437
+ } else if (arg.startsWith("--port=")) {
438
+ port = parsePort(arg.slice("--port=".length));
439
+ } else if (arg === "--scope") {
440
+ scope = rest[++i];
441
+ } else if (arg.startsWith("--scope=")) {
442
+ scope = arg.slice("--scope=".length);
443
+ } else if (arg === "--runtime") {
444
+ runtime = true;
445
+ } else if (arg === "--capture") {
446
+ capture = true;
447
+ } else if (arg === "--verbose") {
448
+ verbose = true;
449
+ } else if (arg === "--instance") {
450
+ instance = rest[++i];
451
+ } else if (arg.startsWith("--instance=")) {
452
+ instance = arg.slice("--instance=".length);
453
+ } else if (arg === "--format") {
454
+ format = parseFormat(rest[++i]);
455
+ } else if (arg.startsWith("--format=")) {
456
+ format = parseFormat(arg.slice("--format=".length));
457
+ } else if (arg === "--path") {
458
+ path = rest[++i];
459
+ } else if (arg.startsWith("--path=")) {
460
+ path = arg.slice("--path=".length);
461
+ } else if (arg === "--report") {
462
+ report = rest[++i];
463
+ } else if (arg.startsWith("--report=")) {
464
+ report = arg.slice("--report=".length);
465
+ } else if (arg === "--name") {
466
+ name = rest[++i];
467
+ } else if (arg.startsWith("--name=")) {
468
+ name = arg.slice("--name=".length);
469
+ } else if (arg === "--framework") {
470
+ framework = rest[++i];
471
+ } else if (arg.startsWith("--framework=")) {
472
+ framework = arg.slice("--framework=".length);
473
+ } else if (arg === "--ai" || arg.startsWith("--ai=")) {
474
+ const raw = arg === "--ai" ? rest[++i] : arg.slice("--ai=".length);
475
+ for (const p of (raw ?? "").split(",")) {
476
+ const preset = p.trim();
477
+ if (preset !== "") ai.push(preset);
478
+ }
479
+ } else if (arg === "--force") {
480
+ force = true;
481
+ } else if (arg === "--no-install") {
482
+ noInstall = true;
483
+ } else if (arg === "--allow-seed-in-static") {
484
+ allowSeedInStatic = true;
485
+ } else if (arg === "--no-verify") {
486
+ noVerify = true;
487
+ } else if (arg === "--require-microservices") {
488
+ requireMicroservices = true;
489
+ } else if (arg === "--dry-run") {
490
+ dryRun = true;
491
+ } else if (arg === "--prune" && command === "release") {
492
+ prune = true;
493
+ } else if (arg === "--reset-data") {
494
+ resetData = true;
495
+ } else if (arg === "--seed") {
496
+ seed = true;
497
+ } else if (arg === "--replace") {
498
+ replace = true;
499
+ } else if (arg === "--json") {
500
+ json = true;
501
+ } else if (arg === "--open") {
502
+ open = true;
503
+ } else if (arg === "--profile" || arg.startsWith("--profile=")) {
504
+ throw new UsageError(
505
+ `\`--profile\` was removed \u2014 deploy now authenticates via OAuth. Run \`xanots login\` once (or set XANO_REFRESH_TOKEN for CI).`,
506
+ { helpFor: helpTargetFor(command, subcommand) }
507
+ );
508
+ } else if (arg === "--workspace" || arg.startsWith("--workspace=")) {
509
+ throw new UsageError(
510
+ `\`--workspace\` was removed. Every command acts on the workspace its credential is bound to \u2014 pinned at \`xanots login\`, or set as \`workspace_id\` in a meta API token credential. Run \`xanots workspace details\` to see which one that is.`,
511
+ { helpFor: helpTargetFor(command, subcommand) }
512
+ );
513
+ } else if (arg === "--prune" || arg === "--confirm-workspace" || arg.startsWith("--confirm-workspace=") || arg === "--adopt-workspace") {
514
+ const flag = arg.split("=")[0];
515
+ throw new UsageError(
516
+ `\`${flag}\` was removed along with \`xanots workspace deploy\` \u2014 deploy targets are selected with \`xanots deploy --dest <ephemeral|sandbox>\`.`,
517
+ { helpFor: helpTargetFor(command, subcommand) }
518
+ );
519
+ } else if (arg === "--help" || arg === "-h") {
520
+ continue;
521
+ } else if (arg.startsWith("-") && arg !== "-") {
522
+ unknownFlags.push(arg);
523
+ } else {
524
+ positionals.push(arg);
525
+ positionalAt.push(i);
526
+ }
527
+ }
528
+ if (unknownFlags.length > 0) {
529
+ throw unknownFlag(unknownFlags, helpTargetFor(command, subcommand));
530
+ }
531
+ const budget = command === void 0 ? void 0 : positionalBudget(command, subcommand, positionals);
532
+ if (budget !== void 0 && budget.given.length > budget.max) {
533
+ const lockValue = positionals.findIndex((_, n) => rest[(positionalAt[n] ?? 0) - 1] === "--lock");
534
+ const extras = lockValue >= budget.offset ? [positionals[lockValue]] : budget.given.slice(budget.max);
535
+ throw extraArguments(extras, budget.target, budget.max, lockValue >= budget.offset ? "--lock" : void 0);
536
+ }
537
+ return {
538
+ command,
539
+ subcommand,
540
+ file: positionals[0],
541
+ out,
542
+ positionals,
543
+ lock,
544
+ lockPath,
545
+ entryPath,
546
+ frozenLock,
547
+ strict,
548
+ yes,
549
+ bundle,
550
+ reset,
551
+ dest,
552
+ kind,
553
+ concurrency,
554
+ test,
555
+ expiresHours,
556
+ static: staticDir,
557
+ staticHost,
558
+ staticRouting,
559
+ staticEnv,
560
+ authHost,
561
+ authFile,
562
+ local: useLocal,
563
+ allWorkspaces,
564
+ guest,
565
+ urlOnly,
566
+ prompt,
567
+ port,
568
+ scope,
569
+ runtime,
570
+ capture,
571
+ verbose,
572
+ instance,
573
+ format,
574
+ path,
575
+ name,
576
+ ai,
577
+ force,
578
+ noInstall,
579
+ framework,
580
+ noVerify,
581
+ requireMicroservices,
582
+ report,
583
+ allowSeedInStatic,
584
+ dryRun,
585
+ prune,
586
+ resetData,
587
+ seed,
588
+ replace,
589
+ emit: emit2,
590
+ json,
591
+ open,
592
+ unknownFlags
593
+ };
594
+ }
595
+ function resolveHelpRequest(argv) {
596
+ const asVerb = argv[0] === "help";
597
+ if (!asVerb && !argv.some((a) => a === "--help" || a === "-h")) return void 0;
598
+ const tokens = (asVerb ? argv.slice(1) : argv).filter((a) => !a.startsWith("-"));
599
+ const command = tokens[0];
600
+ if (command === void 0 || !isCommand(command)) {
601
+ return asVerb && command !== void 0 ? { unknownTopic: command } : {};
602
+ }
603
+ const sub = tokens[1];
604
+ return sub !== void 0 && getSubcommand(command, sub) !== void 0 ? { command, subcommand: sub } : { command };
605
+ }
606
+ function parseFormat(raw) {
607
+ if (raw === "json" || raw === "multidoc") return raw;
608
+ throw new Error(`--format must be "json" or "multidoc" (got "${raw ?? ""}").`);
609
+ }
610
+ function parseDest(raw) {
611
+ if (raw === "sandbox" || raw === "ephemeral" || raw === "workspace") return raw;
612
+ throw new Error(`--dest must be "ephemeral", "sandbox" or "workspace" (got "${raw ?? ""}").`);
613
+ }
614
+ function parseKind(raw) {
615
+ if (raw === "unit" || raw === "workflow") return raw;
616
+ throw new Error(`--kind must be "unit" or "workflow" (got "${raw ?? ""}").`);
617
+ }
618
+ function parseConcurrency(raw) {
619
+ const n = Number(raw);
620
+ if (!Number.isInteger(n) || n < 1 || n > 32) {
621
+ throw new Error(`--concurrency must be a whole number from 1 to 32 (got "${raw ?? ""}").`);
622
+ }
623
+ return n;
624
+ }
625
+ function parseExpiresHours(raw) {
626
+ const n = Number(raw);
627
+ if (!Number.isInteger(n) || n < 1 || n > 72) {
628
+ throw new Error(`--expires-hours must be an integer 1\u201372 (got "${raw ?? ""}").`);
629
+ }
630
+ return n;
631
+ }
632
+ async function importTsxApi(file) {
633
+ try {
634
+ const requireFromEntry = createRequire(pathToFileURL2(resolve(file)));
635
+ const apiPath = requireFromEntry.resolve("tsx/esm/api");
636
+ return await import(pathToFileURL2(apiPath).href);
637
+ } catch {
638
+ return await import("tsx/esm/api");
639
+ }
640
+ }
641
+ async function tryImportTsxApi(file) {
642
+ try {
643
+ return await importTsxApi(file);
644
+ } catch {
645
+ return void 0;
646
+ }
647
+ }
648
+ function entryIsCommonJs(file) {
649
+ const path = resolve(file);
650
+ if (/\.mts$/.test(path)) return false;
651
+ if (/\.cts$/.test(path)) return true;
652
+ let dir = dirname(path);
653
+ for (; ; ) {
654
+ const manifest = join(dir, "package.json");
655
+ if (existsSync(manifest)) {
656
+ try {
657
+ const pkg = JSON.parse(readFileSync2(manifest, "utf8"));
658
+ return pkg.type !== "module";
659
+ } catch {
660
+ return false;
661
+ }
662
+ }
663
+ const parent = dirname(dir);
664
+ if (parent === dir) return false;
665
+ dir = parent;
666
+ }
667
+ }
668
+ function commonJsEntryError(file, cause) {
669
+ return new Error(
670
+ `Cannot load "${file}": it is being evaluated as CommonJS, but xanots workspace files are ES modules. Add \`"type": "module"\` to the nearest package.json, or rename the entry to \`.mts\`.`,
671
+ cause !== void 0 ? { cause } : void 0
672
+ );
673
+ }
674
+ function suggestSiblingFile(path) {
675
+ try {
676
+ return suggest(basename(path), readdirSync(dirname(path)));
677
+ } catch {
678
+ return void 0;
679
+ }
680
+ }
681
+ async function loadDefault(file) {
682
+ const path = resolve(file);
683
+ if (!existsSync(path)) {
684
+ throw new UsageError(`Cannot find entry file "${file}" (resolved to ${path}).`, {
685
+ suggestion: suggestSiblingFile(path)
686
+ });
687
+ }
688
+ const url = pathToFileURL2(path).href;
689
+ const isTypeScript = /\.[mc]?ts$/.test(file);
690
+ if (isTypeScript) {
691
+ if (entryIsCommonJs(file)) throw commonJsEntryError(file);
692
+ const tsx = await tryImportTsxApi(file);
693
+ if (tsx) {
694
+ const unregister = tsx.register();
695
+ try {
696
+ const mod = await import(url);
697
+ return mod.default;
698
+ } finally {
699
+ unregister();
700
+ }
701
+ }
702
+ }
703
+ try {
704
+ const mod = await import(url);
705
+ return mod.default;
706
+ } catch (err) {
707
+ if (!isTypeScript) throw err;
708
+ const code = err?.code;
709
+ if (code === "ERR_UNKNOWN_FILE_EXTENSION" || code === "ERR_MODULE_NOT_FOUND") {
710
+ throw new Error(
711
+ `Loading a TypeScript entry ("${file}") requires \`tsx\`. Install it in your project (\`npm i -D tsx\`) or precompile the file to .js first.`,
712
+ { cause: err }
713
+ );
714
+ }
715
+ if (err instanceof SyntaxError && /import statement outside a module/.test(err.message)) {
716
+ throw commonJsEntryError(file, err);
717
+ }
718
+ throw err;
719
+ }
720
+ }
721
+ function readVersion() {
722
+ let dir = dirname(fileURLToPath2(import.meta.url));
723
+ for (let i = 0; i < 6; i++) {
724
+ const p = join(dir, "package.json");
725
+ if (existsSync(p)) {
726
+ try {
727
+ const pkg = JSON.parse(readFileSync2(p, "utf8"));
728
+ if (pkg.name === "@xanots/sdk" && typeof pkg.version === "string") return pkg.version;
729
+ } catch {
730
+ }
731
+ }
732
+ const up = dirname(dir);
733
+ if (up === dir) break;
734
+ dir = up;
735
+ }
736
+ return "unknown";
737
+ }
738
+ function printHelp() {
739
+ process.stdout.write(renderGlobalHelp(stdoutStyle(), readVersion()));
740
+ }
741
+ function shellName(name) {
742
+ return /[^\w.@/-]/.test(name) ? JSON.stringify(name) : name;
743
+ }
744
+ function warnOrphans(orphans, dropped, cededCanonicals, previous, observed) {
745
+ for (const key of orphans) {
746
+ if (key === WORKSPACE_KEY) {
747
+ warn(
748
+ `xano.lock entry "${key}" matched nothing this export (no workspace canonical emitted). Run \`xanots lock prune\` if that is intentional.`
749
+ );
750
+ continue;
751
+ }
752
+ const sep = key.indexOf(":");
753
+ const payloadKey = key.slice(0, sep);
754
+ const name = key.slice(sep + 1);
755
+ const newcomers = Object.keys(observed).filter((k) => k.startsWith(`${payloadKey}:`) && !(k in previous.objects)).map((k) => k.slice(payloadKey.length + 1));
756
+ const hint = newcomers.length > 0 ? ` (new ${payloadKey} names this export: ${newcomers.join(", ")})` : "";
757
+ warn(
758
+ `xano.lock entry "${key}" matches no exported object \u2014 if this was a rename, the next sync would delete+create unless the entry moves with it.`
759
+ );
760
+ detail(`renamed? run: xanots lock rename ${payloadKey} ${shellName(name)} <new-name>${hint}`);
761
+ detail("deleted? run: xanots lock prune");
762
+ }
763
+ for (const key of dropped) {
764
+ warn(
765
+ `Dropped stale lock entry "${key}" \u2014 its identity reappeared under a live name (a reverted rename).`
766
+ );
767
+ }
768
+ for (const key of cededCanonicals) {
769
+ warn(
770
+ `Lock entry "${key}" kept its guid but ceded its canonical to a live object that now emits it (an explicit in-code canonical). If "${key}" was renamed, run the \`xanots lock rename\` fix-up shown above.`
771
+ );
772
+ }
773
+ }
774
+ async function run(argv) {
775
+ const helpRequest = resolveHelpRequest(argv);
776
+ if (helpRequest) {
777
+ if (helpRequest.unknownTopic !== void 0) throw unknownHelpTopic(helpRequest.unknownTopic);
778
+ process.stdout.write(renderHelpFor(helpRequest, stdoutStyle(), readVersion()));
779
+ return;
780
+ }
781
+ const args = parseArgs(argv);
782
+ const { command, out } = args;
783
+ if (command === void 0) {
784
+ printHelp();
785
+ return;
786
+ }
787
+ if (command === "version" || command === "--version" || command === "-v") {
788
+ process.stdout.write(`${readVersion()}
789
+ `);
790
+ return;
791
+ }
792
+ if (command === "init") {
793
+ const { runInitCommand } = await import("./init-command-R6H7ZXW5.js");
794
+ return runInitCommand(args);
795
+ }
796
+ if (command === "completion") {
797
+ const { isCompletionShell, runCompletionCommand, COMPLETION_SHELLS } = await import("./completion-TIPPZN7H.js");
798
+ const shell = args.positionals[0];
799
+ if (shell === void 0 || !isCompletionShell(shell)) {
800
+ throw new UsageError(
801
+ shell === void 0 ? `\`xanots completion\`: missing required <shell>.` : `\`xanots completion\`: unknown shell "${shell}". Supported: ${COMPLETION_SHELLS.join(", ")}.`,
802
+ { helpFor: { command: "completion" }, suggestion: suggest(shell ?? "", COMPLETION_SHELLS) }
803
+ );
804
+ }
805
+ return runCompletionCommand(shell);
806
+ }
807
+ if (command === "lock") {
808
+ const { runLockCommand } = await import("./lock-commands-XTR2YKLY.js");
809
+ return runLockCommand(args);
810
+ }
811
+ if (command === "login") {
812
+ const { runLoginCommand } = await import("./login-command-ACJF6KWQ.js");
813
+ return runLoginCommand(args);
814
+ }
815
+ if (command === "logout") {
816
+ const { runLogoutCommand } = await import("./logout-command-MX3MJS5U.js");
817
+ return runLogoutCommand(args);
818
+ }
819
+ if (command === "deploy") {
820
+ const { runDeployCommand } = await import("./deploy-command-4EQ7XX5G.js");
821
+ return runDeployCommand(args);
822
+ }
823
+ if (command === "ephemeral") {
824
+ const { runEphemeralCommand } = await import("./ephemeral-command-3X3I4ULC.js");
825
+ return runEphemeralCommand(args);
826
+ }
827
+ if (command === "release") {
828
+ const { runReleaseCommand } = await import("./release-command-VV5UVZKL.js");
829
+ return runReleaseCommand(args);
830
+ }
831
+ if (command === "sandbox") {
832
+ if (args.subcommand === "deploy") {
833
+ throw removedSubcommand("sandbox", "deploy");
834
+ }
835
+ if (args.subcommand === "details") {
836
+ const { runSandboxDetailsCommand } = await import("./sandbox-details-command-HJE5SPVG.js");
837
+ return runSandboxDetailsCommand(args);
838
+ }
839
+ if (args.subcommand === "export") {
840
+ const { runSandboxExportCommand } = await import("./sandbox-export-command-QCJY4GMV.js");
841
+ return runSandboxExportCommand(args);
842
+ }
843
+ if (args.subcommand === "codegen") {
844
+ const { runCodegenCommand } = await import("./codegen-command-OOKK6AZK.js");
845
+ return runCodegenCommand(args, { kind: "sandbox" });
846
+ }
847
+ throw unknownSubcommand("sandbox", args.subcommand);
848
+ }
849
+ if (command === "test") {
850
+ const { runTestCommand } = await import("./test-command-TSPBQHBM.js");
851
+ return runTestCommand(args);
852
+ }
853
+ if (command === "workspace") {
854
+ const { runWorkspaceCommand } = await import("./workspace-command-OF23DPNI.js");
855
+ return runWorkspaceCommand(args);
856
+ }
857
+ if (command === "codegen") {
858
+ const { runCodegenCommand } = await import("./codegen-command-OOKK6AZK.js");
859
+ return runCodegenCommand(args, { kind: "file" });
860
+ }
861
+ if (command === "profile") {
862
+ if (args.subcommand !== "me") {
863
+ throw unknownSubcommand("profile", args.subcommand);
864
+ }
865
+ const { runProfileCommand } = await import("./profile-command-SWJ3SPKR.js");
866
+ return runProfileCommand(args);
867
+ }
868
+ if (command === "whoami") {
869
+ const { runProfileCommand } = await import("./profile-command-SWJ3SPKR.js");
870
+ return runProfileCommand(args);
871
+ }
872
+ if (command === "marketplace") {
873
+ if (!["list", "search", "details", "install"].includes(args.subcommand ?? "")) {
874
+ throw unknownSubcommand("marketplace", args.subcommand);
875
+ }
876
+ const marketplace = await import("./marketplace-command-RATXTKXN.js");
877
+ if (args.subcommand === "list") return marketplace.runMarketplaceListCommand(args);
878
+ if (args.subcommand === "search") return marketplace.runMarketplaceSearchCommand(args);
879
+ if (args.subcommand === "details") return marketplace.runMarketplaceDetailsCommand(args);
880
+ return marketplace.runMarketplaceInstallCommand(args);
881
+ }
882
+ if (command === "push") {
883
+ throw unknownCommand("push");
884
+ }
885
+ if (command === "validate") {
886
+ const { runValidateCommand } = await import("./validate-command-4ERHJSCO.js");
887
+ return runValidateCommand(args);
888
+ }
889
+ if (command !== "compile" && command !== "export" && command !== "paths" && command !== "routes") {
890
+ throw unknownCommand(command);
891
+ }
892
+ if (!args.file) {
893
+ throw missingArgument("file", { command });
894
+ }
895
+ if (command === "compile") {
896
+ return runCompile(args);
897
+ }
898
+ if (command === "paths" || command === "routes") {
899
+ return runPaths(args);
900
+ }
901
+ const { bundle: json, omittedSeedTables } = await compileBundle(args);
902
+ if (omittedSeedTables.length > 0) {
903
+ const names = omittedSeedTables.map((n) => `"${n}"`).join(", ");
904
+ info(
905
+ `Exported bundle omits seed rows for ${omittedSeedTables.length} table(s): ${names}. Seed is applied only by \`xanots deploy <entry>\` \u2014 deploying this bundle via \`--bundle\` ships schema without seed data.`
906
+ );
907
+ }
908
+ if (out) {
909
+ writeFileSync2(out, json + "\n", "utf8");
910
+ process.stdout.write(`Wrote ${out}
911
+ `);
912
+ } else {
913
+ process.stdout.write(json + "\n");
914
+ }
915
+ }
916
+ async function refreshAgentGuidance() {
917
+ try {
918
+ const { refreshAgentFiles } = await import("./agent-file-refresh-7XCACU34.js");
919
+ const refreshed = refreshAgentFiles({
920
+ projectDir: process.cwd(),
921
+ sdkVersion: readVersion()
922
+ });
923
+ for (const path of refreshed) {
924
+ process.stderr.write(`Refreshed ${path} for @xanots/sdk ${readVersion()}.
925
+ `);
926
+ }
927
+ } catch {
928
+ }
929
+ }
930
+ function resolveLockPath(args, file) {
931
+ return args.lockPath !== void 0 ? resolve(args.lockPath) : join(dirname(resolve(file)), "xano.lock");
932
+ }
933
+ function describeDefaultExport(def) {
934
+ if (def === void 0) return "no default export";
935
+ if (def === null) return "null";
936
+ if (Array.isArray(def)) return "an array (export one def, not a list)";
937
+ if (typeof def !== "object") return `a ${typeof def}`;
938
+ return "an object with no `name`";
939
+ }
940
+ async function runCompile(args) {
941
+ const file = args.file;
942
+ const lockPath = resolveLockPath(args, file);
943
+ resetLockOverrides();
944
+ if (existsSync(lockPath)) {
945
+ seedLockOverrides(readLockFile(lockPath));
946
+ }
947
+ const def = await loadDefault(file);
948
+ if (Xano.isXano(def)) {
949
+ throw new Error(
950
+ `Module "${file}" default-exports a workspace \u2014 use \`xanots export\` (or \`xanots paths\`) for a workspace entry. \`compile\` takes a single object def (a query, function, table, \u2026) and prints its JSON artifact.`
951
+ );
952
+ }
953
+ if (!def || typeof def !== "object" || typeof def.name !== "string") {
954
+ throw new Error(
955
+ `Module "${file}" must default-export a single object def (a query, function, table, \u2026) \u2014 one object with a \`name\`. Got: ${describeDefaultExport(def)}.`
956
+ );
957
+ }
958
+ const fn = def;
959
+ if (args.out) {
960
+ writeArtifact(fn, args.out);
961
+ process.stdout.write(`Wrote ${args.out}
962
+ `);
963
+ } else {
964
+ process.stdout.write(emit(fn) + "\n");
965
+ }
966
+ }
967
+ async function runPaths(args) {
968
+ const file = args.file;
969
+ const lockPath = resolveLockPath(args, file);
970
+ resetLockOverrides();
971
+ const lockModel = existsSync(lockPath) ? readLockFile(lockPath) : void 0;
972
+ const def = await loadDefault(file);
973
+ if (!Xano.isXano(def)) {
974
+ throw new Error(`Module "${file}" must default-export a Xano registry for \`paths\`.`);
975
+ }
976
+ const bundle = def.export({ strict: args.strict });
977
+ const payload = bundle.payload;
978
+ const queries = payload.query ?? [];
979
+ const apps = payload.app ?? [];
980
+ const realtimeServers = payload.realtime_server ?? [];
981
+ const channels = payload.channel ?? [];
982
+ const canonicalByGuid = /* @__PURE__ */ new Map();
983
+ for (const a of apps) {
984
+ if (typeof a.guid !== "string") continue;
985
+ const inCode = typeof a.canonical === "string" && a.canonical !== "" ? a.canonical : void 0;
986
+ const locked = typeof a.name === "string" ? lockModel?.objects[lockKey("app", a.name)]?.canonical : void 0;
987
+ const resolved2 = inCode ?? locked;
988
+ if (resolved2) canonicalByGuid.set(a.guid, resolved2);
989
+ }
990
+ if (queries.length === 0 && !(args.emit !== void 0 && realtimeServers.length > 0)) {
991
+ info("No API queries registered in this workspace.");
992
+ return;
993
+ }
994
+ const rows = queries.map((q) => ({
995
+ verb: q.verb,
996
+ // already an uppercase HttpVerb in the bundle
997
+ // Match getPath(): the path segment drops any leading slash on the name.
998
+ name: pathSegment(q.name),
999
+ canonical: q.app?.id ? canonicalByGuid.get(q.app.id) : void 0
1000
+ }));
1001
+ rows.sort((a, b) => (a.canonical ?? "").localeCompare(b.canonical ?? "") || a.name.localeCompare(b.name));
1002
+ const unresolved = rows.filter((r) => !r.canonical);
1003
+ const resolved = rows.filter((r) => r.canonical);
1004
+ if (args.emit !== void 0) {
1005
+ const serverNameByGuid = /* @__PURE__ */ new Map();
1006
+ const serverRows = realtimeServers.flatMap((s) => {
1007
+ if (typeof s.name !== "string" || s.name === "") return [];
1008
+ if (typeof s.guid === "string") serverNameByGuid.set(s.guid, s.name);
1009
+ const inCode = typeof s.canonical === "string" && s.canonical !== "" ? s.canonical : void 0;
1010
+ const locked = lockModel?.objects[lockKey("realtime_server", s.name)]?.canonical;
1011
+ return [{ name: s.name, canonical: inCode ?? locked }];
1012
+ });
1013
+ const describable = new Set(serverRows.filter((s) => s.canonical).map((s) => s.name));
1014
+ const unresolvedServers = serverRows.filter((s) => !s.canonical);
1015
+ const channelRows = channels.flatMap((c) => {
1016
+ if (typeof c.name !== "string" || c.name === "") return [];
1017
+ const server = c.server?.id ? serverNameByGuid.get(c.server.id) : void 0;
1018
+ if (server === void 0 || !describable.has(server)) return [];
1019
+ return [{ name: c.name, server }];
1020
+ });
1021
+ if (unresolvedServers.length > 0) {
1022
+ warn(
1023
+ `${args.emit}: leaving out ${unresolvedServers.length} realtime server(s) \u2014 ${unresolvedServers.map((s) => `"${s.name}"`).join(", ")} \u2014 whose canonical URL token resolves nowhere, along with their channels. Set an explicit \`realtimeServer({ canonical })\`, or run \`xanots export ${file} --lock\` once (it mints a unique canonical and freezes it in xano.lock) beside the entry, then re-run to include them.`
1024
+ );
1025
+ }
1026
+ const describableServers = serverRows.flatMap(
1027
+ (s) => s.canonical ? [{ name: s.name, canonical: s.canonical }] : []
1028
+ );
1029
+ if (resolved.length === 0 && describableServers.length === 0) {
1030
+ info(`Nothing to write to ${args.emit} yet.`);
1031
+ return;
1032
+ }
1033
+ if (unresolved.length === 0) {
1034
+ const { renderRouteManifest } = await import("./routes-manifest-SP3ZXLMR.js");
1035
+ const source = renderRouteManifest(
1036
+ resolved.map((r) => ({ name: r.name, verb: r.verb, canonical: r.canonical })),
1037
+ describableServers.length > 0 ? { servers: describableServers, channels: channelRows } : void 0
1038
+ );
1039
+ const routeCount = resolved.length === 1 ? "1 route" : `${resolved.length} routes`;
1040
+ const channelCount = channelRows.length === 1 ? "1 channel" : `${channelRows.length} channels`;
1041
+ const count = describableServers.length > 0 ? `${routeCount}, ${channelCount}` : routeCount;
1042
+ if (args.strict) {
1043
+ const current = existsSync(args.emit) ? readFileSync2(args.emit, "utf8") : void 0;
1044
+ if (current !== source) {
1045
+ throw new Error(
1046
+ `--strict: ${args.emit} is ${current === void 0 ? "missing" : "out of date"}. Run \`xanots paths <entry> --emit ${args.emit}\` and commit the result \u2014 a stale route manifest keeps compiling while the endpoints have moved.`
1047
+ );
1048
+ }
1049
+ info(`${args.emit} is up to date (${count}).`);
1050
+ } else {
1051
+ writeFileSync2(args.emit, source, "utf8");
1052
+ info(`Wrote ${args.emit} (${count}).`);
1053
+ }
1054
+ }
1055
+ } else {
1056
+ const verbWidth = Math.max(0, ...resolved.map((r) => r.verb.length));
1057
+ for (const r of resolved) {
1058
+ const path = `/api:${r.canonical}/${r.name}`;
1059
+ process.stdout.write(`${r.verb.padEnd(verbWidth)} ${path} api:${r.canonical}/${r.name}
1060
+ `);
1061
+ }
1062
+ }
1063
+ if (unresolved.length > 0) {
1064
+ const names = unresolved.map((r) => `"${r.name}"`).join(", ");
1065
+ throw new Error(
1066
+ `paths: cannot resolve the api group's canonical URL token for ${unresolved.length} query(ies): ${names}. Set an explicit \`apiGroup({ canonical })\`, or run \`xanots export ${file} --lock\` once (it mints a unique canonical and freezes it in xano.lock) beside the entry, then re-run \`xanots paths\`.`
1067
+ );
1068
+ }
1069
+ }
1070
+ async function exportBundleJson(args) {
1071
+ return (await compileBundle(args)).bundle;
1072
+ }
1073
+ async function compileBundle(args, opts = {}) {
1074
+ const file = args.file;
1075
+ const lockPath = resolveLockPath(args, file);
1076
+ const lockExists = existsSync(lockPath);
1077
+ resetLockOverrides();
1078
+ let lockCtx;
1079
+ let originalSerialized;
1080
+ if (lockExists || args.lock) {
1081
+ const lockModel = lockExists ? readLockFile(lockPath) : emptyLock();
1082
+ if (lockExists) originalSerialized = serializeLock(lockModel);
1083
+ seedLockOverrides(lockModel);
1084
+ lockCtx = createLockContext(lockModel);
1085
+ } else if (args.frozenLock) {
1086
+ throw new Error(
1087
+ `--frozen-lock: no xano.lock found at ${lockPath}. Create one with \`xanots export ${file} --lock\` and commit it.`
1088
+ );
1089
+ }
1090
+ await refreshAgentGuidance();
1091
+ const def = await loadDefault(file);
1092
+ if (!Xano.isXano(def)) {
1093
+ throw new Error(`Module "${file}" must default-export a Xano registry for \`export\`.`);
1094
+ }
1095
+ const bundle = def.export({ ...lockCtx ? { lock: lockCtx } : {}, strict: args.strict });
1096
+ if (lockCtx) {
1097
+ const { lock: merged, orphans, dropped, cededCanonicals } = mergeObserved(
1098
+ lockCtx.lock,
1099
+ lockCtx.observed
1100
+ );
1101
+ validateLockModel(merged, lockPath);
1102
+ const changed = originalSerialized === void 0 || serializeLock(merged) !== originalSerialized;
1103
+ if (args.frozenLock && changed) {
1104
+ throw new Error(
1105
+ `--frozen-lock: this export would ${lockExists ? "change" : "create"} ${lockPath}. Run \`xanots export\` locally, commit the updated xano.lock, and retry \u2014 a canonical minted here would be discarded, permanently diverging public URLs.`
1106
+ );
1107
+ }
1108
+ writeLockFile(lockPath, merged);
1109
+ if (!lockExists) info(`Wrote ${relative(process.cwd(), lockPath) || lockPath} (commit this).`);
1110
+ warnOrphans(orphans, dropped, cededCanonicals, lockCtx.lock, lockCtx.observed);
1111
+ }
1112
+ checkFilterNames(bundle, args.strict);
1113
+ const resolvedContent = await buildSeedContentFiles(def.tables());
1114
+ const content = opts.seed ? resolvedContent : [];
1115
+ const nonPublicSeedValues = opts.seed ? await collectNonPublicSeedValues(def.tables()) : [];
1116
+ const omittedSeedTables = opts.seed ? [] : def.tables().filter((t) => t.seed !== void 0).map((t) => t.name);
1117
+ return { bundle: serializeBundle(bundle), content, omittedSeedTables, nonPublicSeedValues };
1118
+ }
1119
+ function checkFilterNames(bundle, strict) {
1120
+ const findings = findUnresolvableFilters(bundle);
1121
+ if (findings.length === 0) return;
1122
+ for (const f of findings) {
1123
+ const hint = f.suggestions.length ? ` \u2014 did you mean ${f.suggestions.map((s) => `\`${s}\``).join(" or ")}?` : "";
1124
+ warn(`Filter "${f.name}" (in ${f.location}) is not engine-resolvable and will 500 at runtime${hint}`);
1125
+ }
1126
+ if (strict) {
1127
+ throw new Error(
1128
+ `--strict: ${findings.length} unresolvable filter name(s). Replace them with resolvable names (see \`fl.*\` / llms.txt) or drop the raw \`filter()\` call.`
1129
+ );
1130
+ }
1131
+ }
1132
+
1133
+ export {
1134
+ writeArtifact,
1135
+ writeBundle,
1136
+ parseArgs,
1137
+ resolveHelpRequest,
1138
+ loadDefault,
1139
+ readVersion,
1140
+ printHelp,
1141
+ run,
1142
+ resolveLockPath,
1143
+ exportBundleJson,
1144
+ compileBundle
1145
+ };
1146
+ //# sourceMappingURL=chunk-YGPIY3WT.js.map