@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,675 @@
1
+ // src/util/hash.ts
2
+ var utf8 = new TextEncoder();
3
+ function toBytes(input) {
4
+ return typeof input === "string" ? utf8.encode(input) : input;
5
+ }
6
+ function md5Bytes(input) {
7
+ const msg = toBytes(input);
8
+ const len = msg.length;
9
+ const withPad = (len + 8 >>> 6) + 1;
10
+ const words = new Int32Array(withPad * 16);
11
+ for (let i = 0; i < len; i++) {
12
+ const idx = i >> 2;
13
+ words[idx] = words[idx] | msg[i] << i % 4 * 8;
14
+ }
15
+ const padIdx = len >> 2;
16
+ words[padIdx] = words[padIdx] | 128 << len % 4 * 8;
17
+ words[words.length - 2] = len * 8;
18
+ let a = 1732584193, b = -271733879, c = -1732584194, d = 271733878;
19
+ const add = (x, y) => x + y | 0;
20
+ const rol = (n, s) => n << s | n >>> 32 - s;
21
+ const cmn = (q, a0, b0, x, s, t) => add(rol(add(add(a0, q), add(x, t)), s), b0);
22
+ const ff = (a0, b0, c0, d0, x, s, t) => cmn(b0 & c0 | ~b0 & d0, a0, b0, x, s, t);
23
+ const gg = (a0, b0, c0, d0, x, s, t) => cmn(b0 & d0 | c0 & ~d0, a0, b0, x, s, t);
24
+ const hh = (a0, b0, c0, d0, x, s, t) => cmn(b0 ^ c0 ^ d0, a0, b0, x, s, t);
25
+ const ii = (a0, b0, c0, d0, x, s, t) => cmn(c0 ^ (b0 | ~d0), a0, b0, x, s, t);
26
+ for (let i = 0; i < words.length; i += 16) {
27
+ const oa = a, ob = b, oc = c, od = d;
28
+ const w = (j) => words[i + j];
29
+ a = ff(a, b, c, d, w(0), 7, -680876936);
30
+ d = ff(d, a, b, c, w(1), 12, -389564586);
31
+ c = ff(c, d, a, b, w(2), 17, 606105819);
32
+ b = ff(b, c, d, a, w(3), 22, -1044525330);
33
+ a = ff(a, b, c, d, w(4), 7, -176418897);
34
+ d = ff(d, a, b, c, w(5), 12, 1200080426);
35
+ c = ff(c, d, a, b, w(6), 17, -1473231341);
36
+ b = ff(b, c, d, a, w(7), 22, -45705983);
37
+ a = ff(a, b, c, d, w(8), 7, 1770035416);
38
+ d = ff(d, a, b, c, w(9), 12, -1958414417);
39
+ c = ff(c, d, a, b, w(10), 17, -42063);
40
+ b = ff(b, c, d, a, w(11), 22, -1990404162);
41
+ a = ff(a, b, c, d, w(12), 7, 1804603682);
42
+ d = ff(d, a, b, c, w(13), 12, -40341101);
43
+ c = ff(c, d, a, b, w(14), 17, -1502002290);
44
+ b = ff(b, c, d, a, w(15), 22, 1236535329);
45
+ a = gg(a, b, c, d, w(1), 5, -165796510);
46
+ d = gg(d, a, b, c, w(6), 9, -1069501632);
47
+ c = gg(c, d, a, b, w(11), 14, 643717713);
48
+ b = gg(b, c, d, a, w(0), 20, -373897302);
49
+ a = gg(a, b, c, d, w(5), 5, -701558691);
50
+ d = gg(d, a, b, c, w(10), 9, 38016083);
51
+ c = gg(c, d, a, b, w(15), 14, -660478335);
52
+ b = gg(b, c, d, a, w(4), 20, -405537848);
53
+ a = gg(a, b, c, d, w(9), 5, 568446438);
54
+ d = gg(d, a, b, c, w(14), 9, -1019803690);
55
+ c = gg(c, d, a, b, w(3), 14, -187363961);
56
+ b = gg(b, c, d, a, w(8), 20, 1163531501);
57
+ a = gg(a, b, c, d, w(13), 5, -1444681467);
58
+ d = gg(d, a, b, c, w(2), 9, -51403784);
59
+ c = gg(c, d, a, b, w(7), 14, 1735328473);
60
+ b = gg(b, c, d, a, w(12), 20, -1926607734);
61
+ a = hh(a, b, c, d, w(5), 4, -378558);
62
+ d = hh(d, a, b, c, w(8), 11, -2022574463);
63
+ c = hh(c, d, a, b, w(11), 16, 1839030562);
64
+ b = hh(b, c, d, a, w(14), 23, -35309556);
65
+ a = hh(a, b, c, d, w(1), 4, -1530992060);
66
+ d = hh(d, a, b, c, w(4), 11, 1272893353);
67
+ c = hh(c, d, a, b, w(7), 16, -155497632);
68
+ b = hh(b, c, d, a, w(10), 23, -1094730640);
69
+ a = hh(a, b, c, d, w(13), 4, 681279174);
70
+ d = hh(d, a, b, c, w(0), 11, -358537222);
71
+ c = hh(c, d, a, b, w(3), 16, -722521979);
72
+ b = hh(b, c, d, a, w(6), 23, 76029189);
73
+ a = hh(a, b, c, d, w(9), 4, -640364487);
74
+ d = hh(d, a, b, c, w(12), 11, -421815835);
75
+ c = hh(c, d, a, b, w(15), 16, 530742520);
76
+ b = hh(b, c, d, a, w(2), 23, -995338651);
77
+ a = ii(a, b, c, d, w(0), 6, -198630844);
78
+ d = ii(d, a, b, c, w(7), 10, 1126891415);
79
+ c = ii(c, d, a, b, w(14), 15, -1416354905);
80
+ b = ii(b, c, d, a, w(5), 21, -57434055);
81
+ a = ii(a, b, c, d, w(12), 6, 1700485571);
82
+ d = ii(d, a, b, c, w(3), 10, -1894986606);
83
+ c = ii(c, d, a, b, w(10), 15, -1051523);
84
+ b = ii(b, c, d, a, w(1), 21, -2054922799);
85
+ a = ii(a, b, c, d, w(8), 6, 1873313359);
86
+ d = ii(d, a, b, c, w(15), 10, -30611744);
87
+ c = ii(c, d, a, b, w(6), 15, -1560198380);
88
+ b = ii(b, c, d, a, w(13), 21, 1309151649);
89
+ a = ii(a, b, c, d, w(4), 6, -145523070);
90
+ d = ii(d, a, b, c, w(11), 10, -1120210379);
91
+ c = ii(c, d, a, b, w(2), 15, 718787259);
92
+ b = ii(b, c, d, a, w(9), 21, -343485551);
93
+ a = add(a, oa);
94
+ b = add(b, ob);
95
+ c = add(c, oc);
96
+ d = add(d, od);
97
+ }
98
+ const out = new Uint8Array(16);
99
+ [a, b, c, d].forEach((word, wi) => {
100
+ for (let j = 0; j < 4; j++) out[wi * 4 + j] = word >>> j * 8 & 255;
101
+ });
102
+ return out;
103
+ }
104
+ function md5Hex(input) {
105
+ return toHex(md5Bytes(input));
106
+ }
107
+ function sha1Bytes(input) {
108
+ const msg = toBytes(input);
109
+ const len = msg.length;
110
+ const withLen = len + 9;
111
+ const blocks = Math.ceil(withLen / 64);
112
+ const total = blocks * 64;
113
+ const buf = new Uint8Array(total);
114
+ buf.set(msg);
115
+ buf[len] = 128;
116
+ const bitLen = len * 8;
117
+ buf[total - 4] = bitLen >>> 24 & 255;
118
+ buf[total - 3] = bitLen >>> 16 & 255;
119
+ buf[total - 2] = bitLen >>> 8 & 255;
120
+ buf[total - 1] = bitLen & 255;
121
+ let h0 = 1732584193, h1 = -271733879, h2 = -1732584194, h3 = 271733878, h4 = -1009589776;
122
+ const w = new Int32Array(80);
123
+ const rol = (n, s) => n << s | n >>> 32 - s;
124
+ for (let i = 0; i < total; i += 64) {
125
+ for (let j = 0; j < 16; j++) {
126
+ const k = i + j * 4;
127
+ w[j] = buf[k] << 24 | buf[k + 1] << 16 | buf[k + 2] << 8 | buf[k + 3];
128
+ }
129
+ for (let j = 16; j < 80; j++) w[j] = rol(w[j - 3] ^ w[j - 8] ^ w[j - 14] ^ w[j - 16], 1);
130
+ let a = h0, b = h1, c = h2, d = h3, e = h4;
131
+ for (let j = 0; j < 80; j++) {
132
+ let f, k;
133
+ if (j < 20) {
134
+ f = b & c | ~b & d;
135
+ k = 1518500249;
136
+ } else if (j < 40) {
137
+ f = b ^ c ^ d;
138
+ k = 1859775393;
139
+ } else if (j < 60) {
140
+ f = b & c | b & d | c & d;
141
+ k = -1894007588;
142
+ } else {
143
+ f = b ^ c ^ d;
144
+ k = -899497514;
145
+ }
146
+ const t = rol(a, 5) + f + e + k + w[j] | 0;
147
+ e = d;
148
+ d = c;
149
+ c = rol(b, 30);
150
+ b = a;
151
+ a = t;
152
+ }
153
+ h0 = h0 + a | 0;
154
+ h1 = h1 + b | 0;
155
+ h2 = h2 + c | 0;
156
+ h3 = h3 + d | 0;
157
+ h4 = h4 + e | 0;
158
+ }
159
+ const out = new Uint8Array(20);
160
+ [h0, h1, h2, h3, h4].forEach((h, hi) => {
161
+ out[hi * 4] = h >>> 24 & 255;
162
+ out[hi * 4 + 1] = h >>> 16 & 255;
163
+ out[hi * 4 + 2] = h >>> 8 & 255;
164
+ out[hi * 4 + 3] = h & 255;
165
+ });
166
+ return out;
167
+ }
168
+ function toHex(bytes) {
169
+ let s = "";
170
+ for (const b of bytes) s += b.toString(16).padStart(2, "0");
171
+ return s;
172
+ }
173
+ function randomBytes(n) {
174
+ const out = new Uint8Array(n);
175
+ globalThis.crypto.getRandomValues(out);
176
+ return out;
177
+ }
178
+
179
+ // src/lock/store.ts
180
+ var STORE_KEY = /* @__PURE__ */ Symbol.for("xanots.lock.overrides");
181
+ function getStore() {
182
+ return globalThis[STORE_KEY];
183
+ }
184
+ function seedLockOverrides(lock) {
185
+ const entries = /* @__PURE__ */ new Map();
186
+ for (const [key, entry] of Object.entries(lock.objects)) {
187
+ entries.set(key, { ...entry });
188
+ }
189
+ globalThis[STORE_KEY] = { entries };
190
+ }
191
+ function resetLockOverrides() {
192
+ delete globalThis[STORE_KEY];
193
+ }
194
+ function isLockSeeded() {
195
+ return getStore() !== void 0;
196
+ }
197
+ function getLockedGuid(key) {
198
+ return getStore()?.entries.get(key)?.guid;
199
+ }
200
+ function getLockedCanonical(key) {
201
+ return getStore()?.entries.get(key)?.canonical;
202
+ }
203
+
204
+ // src/refs/guid.ts
205
+ var REFERENCEABLE_KIND_PAYLOAD_KEYS = {
206
+ function: "function",
207
+ query: "query",
208
+ tool: "tool",
209
+ // MCP servers and agents are distinct kinds that both persist as
210
+ // obj_type=toolset — they share the "toolset" migrate type, so both derive
211
+ // md5("toolset:"+name) and a same-name pair correctly collides. A trigger
212
+ // binds either by resolving against this same "toolset" migrate type.
213
+ mcp_server: "toolset",
214
+ agent: "toolset",
215
+ task: "task",
216
+ trigger: "trigger",
217
+ middleware: "middleware",
218
+ addon: "addon",
219
+ table: "dbo",
220
+ api_group: "app",
221
+ // Realtime: `realtime_server` -> `channel` -> `message`. Kind names match the
222
+ // engine's object types (the authoring factories carry the `realtime` prefix
223
+ // instead). Channel and message names are NOT workspace-unique, so their
224
+ // seeds are composed — see {@link realtimeChannelSeedName}.
225
+ realtime_server: "realtime_server",
226
+ channel: "channel",
227
+ message: "message",
228
+ // A container workload. Nothing in a stack resolves it by guid — `s.microservice.request`
229
+ // addresses one by NAME — but it is listed here because it is a top-level
230
+ // guid-tracked object, and the codegen index only places objects it recognises.
231
+ microservice: "microservice",
232
+ // An end-to-end test: a named stack of runs plus `expect` assertions. Kind
233
+ // name and migrate type are the same string, so the mapping is identity.
234
+ // Membership here is load-bearing twice over: `s.workflow_test.call` already
235
+ // resolves its target through this map, and `Xano#encodeOne` stamps a guid
236
+ // only for kinds in `REFERENCEABLE_KINDS` — and the engine REFUSES to export a
237
+ // workflow test that has none ("Missing workflow test guid."), a failure that
238
+ // surfaces only against a live instance.
239
+ workflow_test: "workflow_test"
240
+ };
241
+ var REFERENCEABLE_KINDS = new Set(Object.keys(REFERENCEABLE_KIND_PAYLOAD_KEYS));
242
+ var SEED_SEP = "|";
243
+ function seedPart(kind, label, value) {
244
+ if (!value) {
245
+ throw new Error(`realtime ${kind} identity: \`${label}\` is required to derive a stable guid.`);
246
+ }
247
+ if (value.includes(SEED_SEP)) {
248
+ throw new Error(
249
+ `realtime ${kind} identity: \`${label}\` must not contain "${SEED_SEP}" (got "${value}") \u2014 it separates the components of the guid seed, so a name carrying it could collide with a different object.`
250
+ );
251
+ }
252
+ return value;
253
+ }
254
+ function realtimeChannelSeedName(server, path) {
255
+ return [seedPart("channel", "server", server), seedPart("channel", "path", path)].join(SEED_SEP);
256
+ }
257
+ function realtimeMessageSeedName(server, channelPath, name) {
258
+ return [
259
+ seedPart("message", "server", server),
260
+ seedPart("message", "channel", channelPath),
261
+ seedPart("message", "name", name)
262
+ ].join(SEED_SEP);
263
+ }
264
+ function rawDeriveGuid(seed) {
265
+ return md5Hex(seed);
266
+ }
267
+ function deriveGuid(type, name) {
268
+ const seed = `${type}:${name}`;
269
+ const guid = getLockedGuid(seed) ?? rawDeriveGuid(seed);
270
+ SEEN_SEEDS.set(guid, seed);
271
+ return guid;
272
+ }
273
+ var SEEN_SEEDS = /* @__PURE__ */ new Map();
274
+ function guidSeedHint(guid) {
275
+ return SEEN_SEEDS.get(guid);
276
+ }
277
+ function resolveRef(type, target) {
278
+ if (typeof target !== "string" && target.guid) {
279
+ if (target.name) SEEN_SEEDS.set(target.guid, `${type}:${target.name}`);
280
+ return target.guid;
281
+ }
282
+ const name = typeof target === "string" ? target : target.name;
283
+ if (!name) {
284
+ throw new Error(`Cannot resolve ${type} reference: target has no name or guid.`);
285
+ }
286
+ return deriveGuid(type, name);
287
+ }
288
+
289
+ // src/lock/lock.ts
290
+ var LOCK_VERSION = 1;
291
+ var WORKSPACE_KEY = "workspace";
292
+ var RETIRED_KEYS = /* @__PURE__ */ new Map([
293
+ [
294
+ "workspace:realtime",
295
+ "the legacy workspace-level realtime block is no longer modelled; realtime servers and channels lock under their own keys"
296
+ ]
297
+ ]);
298
+ var LOCK_PAYLOAD_KEYS = new Set(Object.values(REFERENCEABLE_KIND_PAYLOAD_KEYS));
299
+ var CANONICAL_PAYLOAD_KEYS = /* @__PURE__ */ new Set(["app", "toolset", "realtime_server"]);
300
+ var KIND_ALIASES = Object.fromEntries(
301
+ Object.entries(REFERENCEABLE_KIND_PAYLOAD_KEYS).filter(([name, key]) => name !== key)
302
+ );
303
+ function resolvePayloadKey(kindOrPayloadKey) {
304
+ if (LOCK_PAYLOAD_KEYS.has(kindOrPayloadKey)) return kindOrPayloadKey;
305
+ const key = REFERENCEABLE_KIND_PAYLOAD_KEYS[kindOrPayloadKey];
306
+ if (key === void 0) {
307
+ throw new Error(
308
+ `Unknown object kind "${kindOrPayloadKey}". Expected one of: ${[...LOCK_PAYLOAD_KEYS].join(", ")} (or the aliases ${Object.keys(KIND_ALIASES).join(", ")}).`
309
+ );
310
+ }
311
+ return key;
312
+ }
313
+ function lockKey(payloadKey, name) {
314
+ return `${payloadKey}:${name}`;
315
+ }
316
+ function emptyLock() {
317
+ return { version: LOCK_VERSION, objects: {} };
318
+ }
319
+ function findDuplicateRawKey(text) {
320
+ const stack = [];
321
+ let i = 0;
322
+ while (i < text.length) {
323
+ const ch = text[i];
324
+ if (ch === "{") {
325
+ stack.push(/* @__PURE__ */ new Set());
326
+ i++;
327
+ } else if (ch === "[") {
328
+ stack.push(null);
329
+ i++;
330
+ } else if (ch === "}" || ch === "]") {
331
+ stack.pop();
332
+ i++;
333
+ } else if (ch === '"') {
334
+ let j = i + 1;
335
+ let value = "";
336
+ while (j < text.length && text[j] !== '"') {
337
+ if (text[j] === "\\") {
338
+ value += text[j] + (text[j + 1] ?? "");
339
+ j += 2;
340
+ } else {
341
+ value += text[j];
342
+ j++;
343
+ }
344
+ }
345
+ j++;
346
+ let k = j;
347
+ while (k < text.length && /\s/.test(text[k])) k++;
348
+ if (text[k] === ":") {
349
+ const scope = stack[stack.length - 1];
350
+ if (scope) {
351
+ let decoded = value;
352
+ try {
353
+ decoded = JSON.parse(`"${value}"`);
354
+ } catch {
355
+ }
356
+ if (scope.has(decoded)) return decoded;
357
+ scope.add(decoded);
358
+ }
359
+ }
360
+ i = j;
361
+ } else {
362
+ i++;
363
+ }
364
+ }
365
+ return void 0;
366
+ }
367
+ function fail(path, message) {
368
+ throw new Error(`Invalid lock file ${path}: ${message}`);
369
+ }
370
+ function parseLock(text, path = "xano.lock") {
371
+ const dup = findDuplicateRawKey(text);
372
+ if (dup !== void 0) {
373
+ fail(
374
+ path,
375
+ `duplicate key "${dup}" in the raw text (likely a bad merge \u2014 JSON keeps only the last one silently). Resolve the duplicate and re-run.`
376
+ );
377
+ }
378
+ let data;
379
+ try {
380
+ data = JSON.parse(text);
381
+ } catch (err) {
382
+ fail(path, `unparseable JSON (${err instanceof Error ? err.message : String(err)}).`);
383
+ }
384
+ if (!data || typeof data !== "object" || Array.isArray(data)) {
385
+ fail(path, "expected a top-level object.");
386
+ }
387
+ const obj = data;
388
+ if (obj.version !== LOCK_VERSION) {
389
+ fail(
390
+ path,
391
+ `unknown version ${JSON.stringify(obj.version)} (this XanoTS reads version ${LOCK_VERSION}). Upgrade XanoTS to a release that understands this lock format.`
392
+ );
393
+ }
394
+ if (!obj.objects || typeof obj.objects !== "object" || Array.isArray(obj.objects)) {
395
+ fail(path, "expected an `objects` map.");
396
+ }
397
+ return { version: LOCK_VERSION, objects: validateLockObjects(obj.objects, path) };
398
+ }
399
+ function validateLockModel(lock, label) {
400
+ validateLockObjects(lock.objects, label);
401
+ }
402
+ function validateLockObjects(raw, path) {
403
+ const objects = {};
404
+ const guidOwners = /* @__PURE__ */ new Map();
405
+ const canonicalOwners = /* @__PURE__ */ new Map();
406
+ for (const [key, entryRaw] of Object.entries(raw)) {
407
+ validateKey(key, path);
408
+ if (!entryRaw || typeof entryRaw !== "object" || Array.isArray(entryRaw)) {
409
+ fail(path, `entry "${key}" must be an object.`);
410
+ }
411
+ const { guid, canonical } = entryRaw;
412
+ if (guid !== void 0 && (typeof guid !== "string" || guid === "")) {
413
+ fail(path, `entry "${key}" has a non-string or empty \`guid\`.`);
414
+ }
415
+ if (canonical !== void 0 && (typeof canonical !== "string" || canonical === "")) {
416
+ fail(path, `entry "${key}" has a non-string or empty \`canonical\`.`);
417
+ }
418
+ if (guid === void 0 && canonical === void 0) {
419
+ fail(path, `entry "${key}" carries neither \`guid\` nor \`canonical\`.`);
420
+ }
421
+ const isWorkspaceKey = key === WORKSPACE_KEY;
422
+ if (isWorkspaceKey && guid !== void 0) {
423
+ fail(path, `entry "${key}" cannot carry a \`guid\` (workspace identities are canonical-only).`);
424
+ }
425
+ if (!isWorkspaceKey && canonical !== void 0) {
426
+ const prefix = key.slice(0, key.indexOf(":"));
427
+ if (!CANONICAL_PAYLOAD_KEYS.has(prefix)) {
428
+ fail(
429
+ path,
430
+ `entry "${key}" cannot carry a \`canonical\` \u2014 only ${[...CANONICAL_PAYLOAD_KEYS].join("/")} objects and the workspace key have one.`
431
+ );
432
+ }
433
+ }
434
+ if (typeof guid === "string") {
435
+ const owner = guidOwners.get(guid);
436
+ if (owner !== void 0) {
437
+ fail(path, `entries "${owner}" and "${key}" share the same guid (${guid}).`);
438
+ }
439
+ guidOwners.set(guid, key);
440
+ }
441
+ if (typeof canonical === "string") {
442
+ const owner = canonicalOwners.get(canonical);
443
+ if (owner !== void 0) {
444
+ fail(path, `entries "${owner}" and "${key}" share the same canonical (${canonical}).`);
445
+ }
446
+ canonicalOwners.set(canonical, key);
447
+ }
448
+ const entry = {};
449
+ if (typeof guid === "string") entry.guid = guid;
450
+ if (typeof canonical === "string") entry.canonical = canonical;
451
+ objects[key] = entry;
452
+ }
453
+ return objects;
454
+ }
455
+ function validateKey(key, path) {
456
+ if (key === WORKSPACE_KEY) return;
457
+ const retired = RETIRED_KEYS.get(key);
458
+ if (retired !== void 0) {
459
+ fail(path, `key "${key}" is retired \u2014 ${retired}. Remove the entry.`);
460
+ }
461
+ const idx = key.indexOf(":");
462
+ const prefix = idx === -1 ? key : key.slice(0, idx);
463
+ const name = idx === -1 ? "" : key.slice(idx + 1);
464
+ if (prefix === "workspace") {
465
+ fail(
466
+ path,
467
+ `key "${key}" is not a lockable workspace identity (only "${WORKSPACE_KEY}" exists).`
468
+ );
469
+ }
470
+ if (idx === -1 || name === "" || !LOCK_PAYLOAD_KEYS.has(prefix)) {
471
+ fail(
472
+ path,
473
+ `key "${key}" is not \`<payloadKey>:<name>\` with a known payload key (${[...LOCK_PAYLOAD_KEYS].join(", ")}).`
474
+ );
475
+ }
476
+ }
477
+ function serializeLock(lock) {
478
+ const objects = {};
479
+ for (const key of Object.keys(lock.objects).sort()) {
480
+ const src = lock.objects[key];
481
+ const entry = {};
482
+ if (src.guid !== void 0) entry.guid = src.guid;
483
+ if (src.canonical !== void 0) entry.canonical = src.canonical;
484
+ objects[key] = entry;
485
+ }
486
+ return JSON.stringify({ version: lock.version, objects }, null, 2) + "\n";
487
+ }
488
+ function mintCanonical() {
489
+ let bin = "";
490
+ for (const b of randomBytes(6)) bin += String.fromCharCode(b);
491
+ return btoa(bin).replace(/\+/g, "-").replace(/\//g, "_");
492
+ }
493
+ function createLockContext(lock = emptyLock()) {
494
+ return { lock, observed: {} };
495
+ }
496
+ function recordObserved(ctx, key, identity) {
497
+ const prior = ctx.observed[key];
498
+ if (prior?.guid !== void 0 && identity.guid !== void 0 && prior.guid !== identity.guid) {
499
+ throw new Error(
500
+ `Two exported objects collapse onto lock key "${key}" with different guids (${prior.guid} vs ${identity.guid}) \u2014 two same-kind objects sharing a name: a query verb pair pinning explicit guids, or a kind whose identity is composed from more than the name (a realtime channel is unique per server, a message per channel). The lock keys identity by (type, name) and cannot track both; rename one of the objects.`
501
+ );
502
+ }
503
+ const entry = ctx.lock.objects[key];
504
+ if (identity.guid !== void 0 && entry?.guid !== void 0 && identity.guid !== entry.guid) {
505
+ if (identity.guid === rawDeriveGuid(key)) {
506
+ throw new Error(
507
+ `"${key}" emitted its name-derived guid (${identity.guid}) but xano.lock pins ${entry.guid}. The lock overrides were not seeded before the workspace module loaded \u2014 programmatic exports must call seedLockOverrides(lock) before importing any def module (the CLI does this automatically).`
508
+ );
509
+ }
510
+ throw new Error(
511
+ `"${key}" has an explicit guid (${identity.guid}) that differs from its xano.lock entry (${entry.guid}), so references resolved through the lock would split from the object itself. Update the xano.lock entry to the explicit guid, or remove the explicit guid from code, then re-export.`
512
+ );
513
+ }
514
+ ctx.observed[key] = { ...ctx.observed[key], ...identity };
515
+ }
516
+ function renameLockEntry(lock, payloadKey, oldName, newName) {
517
+ const oldKey = lockKey(payloadKey, oldName);
518
+ const newKey = lockKey(payloadKey, newName);
519
+ const entry = lock.objects[oldKey];
520
+ if (entry === void 0) {
521
+ throw new Error(
522
+ `No lock entry "${oldKey}". \`lock rename\` moves an existing entry \u2014 check the kind and old name (kinds accept payload keys or the aliases table/api_group).`
523
+ );
524
+ }
525
+ const objects = { ...lock.objects };
526
+ let discardedNewcomer;
527
+ const existing = objects[newKey];
528
+ if (existing !== void 0) {
529
+ if (existing.guid !== rawDeriveGuid(newKey)) {
530
+ throw new Error(
531
+ `Lock entry "${newKey}" already exists and is not the fresh name-derivation (it pins ${existing.guid ?? "a canonical"}). Refusing to overwrite a real identity \u2014 resolve the conflict by hand-editing xano.lock if this is intended.`
532
+ );
533
+ }
534
+ discardedNewcomer = existing;
535
+ }
536
+ delete objects[oldKey];
537
+ objects[newKey] = { ...entry };
538
+ return { lock: { version: lock.version, objects }, discardedNewcomer };
539
+ }
540
+ function adoptFromBundle(lock, bundle, bundlePath) {
541
+ if (!bundle || typeof bundle !== "object" || Array.isArray(bundle)) {
542
+ throw new Error(`${bundlePath} is not a packageExport bundle (expected a top-level object).`);
543
+ }
544
+ const payload = bundle.payload;
545
+ if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
546
+ throw new Error(`${bundlePath} is not a packageExport bundle (missing \`payload\`).`);
547
+ }
548
+ const sections = payload;
549
+ const objects = { ...lock.objects };
550
+ for (const key of Object.keys(objects)) objects[key] = { ...objects[key] };
551
+ const added = [];
552
+ const changed = [];
553
+ let canonicalsSeen = false;
554
+ const applyEntry = (key, incoming) => {
555
+ const before = objects[key];
556
+ const after = { ...before, ...incoming };
557
+ if (before === void 0) {
558
+ objects[key] = after;
559
+ added.push(key);
560
+ } else if (before.guid !== after.guid || before.canonical !== after.canonical) {
561
+ changed.push({ key, before, after });
562
+ objects[key] = after;
563
+ }
564
+ };
565
+ for (const payloadKey of LOCK_PAYLOAD_KEYS) {
566
+ const arr = sections[payloadKey];
567
+ if (!Array.isArray(arr)) continue;
568
+ const namesSeen = /* @__PURE__ */ new Set();
569
+ for (const obj of arr) {
570
+ if (!obj || typeof obj !== "object") continue;
571
+ const o = obj;
572
+ if (typeof o.name !== "string" || typeof o.guid !== "string" || o.guid === "") continue;
573
+ if (namesSeen.has(o.name)) {
574
+ throw new Error(
575
+ `${bundlePath} contains two "${payloadKey}" objects named "${o.name}" (a query verb pair, most likely). The lock keys by (type, name) and cannot represent both \u2014 adoption aborted. Rename one of them engine-side so names are unique, then re-export and re-adopt.`
576
+ );
577
+ }
578
+ namesSeen.add(o.name);
579
+ const incoming = { guid: o.guid };
580
+ if (typeof o.canonical === "string" && o.canonical !== "") {
581
+ incoming.canonical = o.canonical;
582
+ canonicalsSeen = true;
583
+ }
584
+ applyEntry(lockKey(payloadKey, o.name), incoming);
585
+ }
586
+ }
587
+ const ws = sections["workspace"];
588
+ if (ws && typeof ws === "object" && !Array.isArray(ws)) {
589
+ const w = ws;
590
+ if (typeof w.canonical === "string" && w.canonical !== "") {
591
+ canonicalsSeen = true;
592
+ applyEntry(WORKSPACE_KEY, { canonical: w.canonical });
593
+ }
594
+ }
595
+ const vault = sections["vault"];
596
+ const vaultCount = Array.isArray(vault) ? vault.length : 0;
597
+ const merged = {
598
+ version: lock.version,
599
+ objects: validateLockObjects(objects, "the adopted lock")
600
+ };
601
+ return { lock: merged, added: added.sort(), changed, canonicalsSeen, vaultCount };
602
+ }
603
+ function mergeObserved(lock, observed) {
604
+ const objects = {};
605
+ for (const [key, identity] of Object.entries(observed)) {
606
+ objects[key] = { ...lock.objects[key], ...identity };
607
+ }
608
+ const liveGuids = new Set(Object.values(objects).map((e) => e.guid).filter(Boolean));
609
+ const liveCanonicals = new Set(
610
+ Object.values(objects).map((e) => e.canonical).filter(Boolean)
611
+ );
612
+ const orphans = [];
613
+ const dropped = [];
614
+ const cededCanonicals = [];
615
+ for (const [key, entry] of Object.entries(lock.objects)) {
616
+ if (key in objects) continue;
617
+ if (entry.guid !== void 0 && liveGuids.has(entry.guid)) {
618
+ dropped.push(key);
619
+ continue;
620
+ }
621
+ if (entry.canonical !== void 0 && liveCanonicals.has(entry.canonical)) {
622
+ const kept = { ...entry };
623
+ delete kept.canonical;
624
+ if (kept.guid === void 0) {
625
+ dropped.push(key);
626
+ continue;
627
+ }
628
+ objects[key] = kept;
629
+ orphans.push(key);
630
+ cededCanonicals.push(key);
631
+ continue;
632
+ }
633
+ objects[key] = entry;
634
+ orphans.push(key);
635
+ }
636
+ return {
637
+ lock: { version: lock.version, objects },
638
+ orphans: orphans.sort(),
639
+ dropped: dropped.sort(),
640
+ cededCanonicals: cededCanonicals.sort()
641
+ };
642
+ }
643
+
644
+ export {
645
+ sha1Bytes,
646
+ seedLockOverrides,
647
+ resetLockOverrides,
648
+ isLockSeeded,
649
+ getLockedGuid,
650
+ getLockedCanonical,
651
+ REFERENCEABLE_KIND_PAYLOAD_KEYS,
652
+ REFERENCEABLE_KINDS,
653
+ realtimeChannelSeedName,
654
+ realtimeMessageSeedName,
655
+ deriveGuid,
656
+ guidSeedHint,
657
+ resolveRef,
658
+ LOCK_VERSION,
659
+ WORKSPACE_KEY,
660
+ LOCK_PAYLOAD_KEYS,
661
+ CANONICAL_PAYLOAD_KEYS,
662
+ resolvePayloadKey,
663
+ lockKey,
664
+ emptyLock,
665
+ parseLock,
666
+ validateLockModel,
667
+ serializeLock,
668
+ mintCanonical,
669
+ createLockContext,
670
+ recordObserved,
671
+ renameLockEntry,
672
+ adoptFromBundle,
673
+ mergeObserved
674
+ };
675
+ //# sourceMappingURL=chunk-4HT3BNZ7.js.map
@@ -0,0 +1,23 @@
1
+ // src/function/define.ts
2
+ function defineFunction(def) {
3
+ if (!def.name || typeof def.name !== "string") {
4
+ throw new Error("defineFunction: `name` is required and must be a non-empty string.");
5
+ }
6
+ return def;
7
+ }
8
+
9
+ // src/fields/file-url.ts
10
+ function fileUrl(file, baseUrl) {
11
+ if (!file) return null;
12
+ if (typeof file.path === "string" && file.path !== "") {
13
+ const base = baseUrl.replace(/\/+$/, "");
14
+ return file.path.startsWith("/") ? base + file.path : `${base}/${file.path}`;
15
+ }
16
+ return typeof file.url === "string" && file.url !== "" ? file.url : null;
17
+ }
18
+
19
+ export {
20
+ defineFunction,
21
+ fileUrl
22
+ };
23
+ //# sourceMappingURL=chunk-4YMD2OOZ.js.map