llmz 0.6.0 → 0.6.2

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 (110) hide show
  1. package/DOCS.md +1 -3
  2. package/dist/_baseForOwn-CFhWe_W6.js +48 -0
  3. package/dist/_baseForOwn-buOZDFbK.cjs +103 -0
  4. package/dist/_baseIteratee-CF4qP2a8.cjs +2377 -0
  5. package/dist/_baseIteratee-P_firB7b.js +2138 -0
  6. package/dist/_getPrototype-CG7Dxrrz.js +6 -0
  7. package/dist/_getPrototype-DQDlNVVM.cjs +10 -0
  8. package/dist/_overArg-C5Hy7oCi.cjs +196 -0
  9. package/dist/_overArg-CRYbj1NH.js +155 -0
  10. package/dist/citations.d.ts +11 -11
  11. package/dist/component-BwixNVH8.cjs +73 -0
  12. package/dist/component-DGG7d_Mz.js +44 -0
  13. package/dist/context.d.ts +8 -8
  14. package/dist/custom-client-BPmEoWKu.cjs +2618 -0
  15. package/dist/custom-client-NUoxrFQh.js +2547 -0
  16. package/dist/dual-modes-D_p-jedw.js +2750 -0
  17. package/dist/dual-modes-wAOAlaBS.cjs +2840 -0
  18. package/dist/errors-C962uJdS.cjs +220 -0
  19. package/dist/errors-Cg1G0Awu.js +161 -0
  20. package/dist/execute-BEaq3jkV.cjs +1003 -0
  21. package/dist/execute-DYvFRs54.js +1001 -0
  22. package/dist/exit-BGi0Kk0y.cjs +428 -0
  23. package/dist/exit-CDdxDBRT.js +417 -0
  24. package/dist/index.cjs +1786 -1489
  25. package/dist/index.d.ts +10 -9
  26. package/dist/index.js +1721 -1479
  27. package/dist/index.workerd.js +17534 -16875
  28. package/dist/isEmpty-BhJRCqIF.js +52 -0
  29. package/dist/isEmpty-LY533Wmh.cjs +57 -0
  30. package/dist/isPlainObject-CSxXVKCk.cjs +56 -0
  31. package/dist/isPlainObject-D39AzPO2.js +51 -0
  32. package/dist/jsx-BWvT6ukg.cjs +75 -0
  33. package/dist/jsx-CIgdGGVs.js +52 -0
  34. package/dist/jsx.d.ts +2 -2
  35. package/dist/prompts/chat-mode/system.md.d.ts +1 -1
  36. package/dist/prompts/chat-mode/user.md.d.ts +1 -1
  37. package/dist/prompts/worker-mode/system.md.d.ts +1 -1
  38. package/dist/prompts/worker-mode/user.md.d.ts +1 -1
  39. package/dist/quickjs-variant-BYhMBpwU.js +45 -0
  40. package/dist/quickjs-variant-CsIwTVFC.cjs +56 -0
  41. package/dist/quickjs-variant.workerd.d.ts +1 -1
  42. package/dist/result.d.ts +12 -12
  43. package/dist/rolldown-runtime-EAsCxrDo.js +14 -0
  44. package/dist/runtime/interpret-result.d.ts +1 -1
  45. package/dist/snapshots.d.ts +5 -5
  46. package/dist/stack-traces-BIE_5Xwf.js +21 -0
  47. package/dist/stack-traces-ntw_qhoy.cjs +26 -0
  48. package/dist/tool-CAo-BQHs.js +643 -0
  49. package/dist/tool-DdPZb0JW.cjs +654 -0
  50. package/dist/tool.d.ts +3 -3
  51. package/dist/truncator-B6aaJaN1.cjs +276 -0
  52. package/dist/truncator-DZqEqnpD.js +253 -0
  53. package/dist/typings-BwAz_TM9.cjs +784 -0
  54. package/dist/typings-CrBa7Tyy.js +743 -0
  55. package/dist/uniq-BYQ7GWwb.js +183 -0
  56. package/dist/uniq-G872RWmE.cjs +200 -0
  57. package/dist/utils-UBeAFeEI.js +950 -0
  58. package/dist/utils-ZpJm00ed.cjs +1075 -0
  59. package/dist/vm/errors.d.ts +2 -2
  60. package/dist/vm-BjkJqSQH.cjs +3438 -0
  61. package/dist/vm-C5vf1LH3.js +3436 -0
  62. package/package.json +7 -7
  63. package/dist/chunk-34GJUS6U.js +0 -3266
  64. package/dist/chunk-3UZKLXAD.cjs +0 -3249
  65. package/dist/chunk-4POZJQXN.js +0 -1530
  66. package/dist/chunk-5WBNTV42.cjs +0 -1530
  67. package/dist/chunk-5ZF6NTYI.cjs +0 -33
  68. package/dist/chunk-72ZWBNZV.js +0 -173
  69. package/dist/chunk-DDSJTR6Q.cjs +0 -257
  70. package/dist/chunk-GDJTKI7J.js +0 -792
  71. package/dist/chunk-GLXADNTR.js +0 -199
  72. package/dist/chunk-GOWPACSK.cjs +0 -199
  73. package/dist/chunk-HB2G32AK.js +0 -257
  74. package/dist/chunk-HC2QZTVT.cjs +0 -3266
  75. package/dist/chunk-HEAQAEFZ.cjs +0 -173
  76. package/dist/chunk-HMMM32RG.cjs +0 -792
  77. package/dist/chunk-I56MPOVG.cjs +0 -62
  78. package/dist/chunk-KIN7Y247.cjs +0 -32
  79. package/dist/chunk-KTDBAJBB.cjs +0 -1685
  80. package/dist/chunk-KWQTYXAT.js +0 -62
  81. package/dist/chunk-LOX7GOR6.js +0 -1685
  82. package/dist/chunk-PK72FAKD.cjs +0 -175
  83. package/dist/chunk-PZE6PIPG.cjs +0 -621
  84. package/dist/chunk-RGUG3UMF.cjs +0 -26
  85. package/dist/chunk-TDALRNGL.js +0 -621
  86. package/dist/chunk-UGHFNCPD.js +0 -26
  87. package/dist/chunk-WSVDMGMR.js +0 -175
  88. package/dist/chunk-XTEHT2TK.js +0 -33
  89. package/dist/chunk-YEAWWJSJ.js +0 -32
  90. package/dist/chunk-YRS7KRKP.js +0 -3249
  91. package/dist/component-2NYFY6CW.cjs +0 -14
  92. package/dist/component-ASNZHQUR.js +0 -14
  93. package/dist/dual-modes-S5TJ5JVJ.js +0 -10
  94. package/dist/dual-modes-TCMWBZIH.cjs +0 -10
  95. package/dist/execute-FF7D46TY.js +0 -1109
  96. package/dist/execute-IK6O4SU2.cjs +0 -1109
  97. package/dist/exit-MX56VN2C.cjs +0 -8
  98. package/dist/exit-UQ3EUX5D.js +0 -8
  99. package/dist/jsx-DDZ63UUF.js +0 -13
  100. package/dist/jsx-ULPWX5TW.cjs +0 -13
  101. package/dist/tool-KD7FL45V.js +0 -11
  102. package/dist/tool-VE2YHIY2.cjs +0 -11
  103. package/dist/truncator-73RCL52Y.js +0 -12
  104. package/dist/truncator-FZNLYSDL.cjs +0 -12
  105. package/dist/typings-E2RROCLT.js +0 -10
  106. package/dist/typings-LQOBZXSO.cjs +0 -10
  107. package/dist/utils-IATCUNKF.js +0 -43
  108. package/dist/utils-ITB4NEL7.cjs +0 -43
  109. package/dist/vm-6D3IIIU7.cjs +0 -12
  110. package/dist/vm-QO5FSGPN.js +0 -12
@@ -1,792 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } var _class;
2
-
3
- var _chunkPK72FAKDcjs = require('./chunk-PK72FAKD.cjs');
4
-
5
-
6
-
7
-
8
- var _chunkGOWPACSKcjs = require('./chunk-GOWPACSK.cjs');
9
-
10
- // src/typings.ts
11
- var _zui = require('@bpinternal/zui');
12
-
13
- // src/typings-formatter.ts
14
- var WIDTH = 80;
15
- var INDENT = " ";
16
- var isGroup = (n) => n.kind === "group";
17
- var isPunct = (n, text) => !isGroup(n) && n.kind === "punct" && n.text === text;
18
- var WORD_CHAR = /[A-Za-z0-9_$.]/;
19
- function tokenize(src) {
20
- const toks = [];
21
- let i = 0;
22
- let nl = 0;
23
- const len = src.length;
24
- while (i < len) {
25
- const c = src[i];
26
- if (c === "\n") {
27
- nl++;
28
- i++;
29
- continue;
30
- }
31
- if (c === " " || c === " " || c === "\r") {
32
- i++;
33
- continue;
34
- }
35
- if (c === "/" && src[i + 1] === "*") {
36
- const end = src.indexOf("*/", i + 2);
37
- if (end === -1) {
38
- throw new Error("unterminated block comment");
39
- }
40
- toks.push({ kind: "block-comment", text: src.slice(i, end + 2), nl });
41
- nl = 0;
42
- i = end + 2;
43
- continue;
44
- }
45
- if (c === "/" && src[i + 1] === "/") {
46
- let end = src.indexOf("\n", i);
47
- if (end === -1) {
48
- end = len;
49
- }
50
- toks.push({ kind: "line-comment", text: src.slice(i, end).trimEnd(), nl });
51
- nl = 0;
52
- i = end;
53
- continue;
54
- }
55
- if (c === "'" || c === '"' || c === "`") {
56
- let j = i + 1;
57
- while (j < len && src[j] !== c) {
58
- j += src[j] === "\\" ? 2 : 1;
59
- }
60
- if (j >= len) {
61
- throw new Error("unterminated string");
62
- }
63
- toks.push({ kind: "string", text: src.slice(i, j + 1), nl });
64
- nl = 0;
65
- i = j + 1;
66
- continue;
67
- }
68
- if (c === "=" && src[i + 1] === ">") {
69
- toks.push({ kind: "punct", text: "=>", nl });
70
- nl = 0;
71
- i += 2;
72
- continue;
73
- }
74
- if (WORD_CHAR.test(c) || c === "-" && /\d/.test(_nullishCoalesce(src[i + 1], () => ( "")))) {
75
- let j = i + 1;
76
- while (j < len && WORD_CHAR.test(src[j])) {
77
- j++;
78
- }
79
- toks.push({ kind: "word", text: src.slice(i, j), nl });
80
- nl = 0;
81
- i = j;
82
- continue;
83
- }
84
- toks.push({ kind: "punct", text: c, nl });
85
- nl = 0;
86
- i++;
87
- }
88
- return toks;
89
- }
90
- var CLOSER = { "{": "}", "(": ")", "[": "]", "<": ">" };
91
- function parse(toks) {
92
- const root = [];
93
- const stack = [];
94
- const siblings = () => stack.length ? stack[stack.length - 1].children : root;
95
- for (const t of toks) {
96
- if (t.kind === "punct" && (t.text === "{" || t.text === "(" || t.text === "[")) {
97
- const g = { kind: "group", open: t.text, close: CLOSER[t.text], children: [], nl: t.nl };
98
- siblings().push(g);
99
- stack.push(g);
100
- continue;
101
- }
102
- if (t.kind === "punct" && t.text === "<") {
103
- const prev = siblings()[siblings().length - 1];
104
- if (prev && !isGroup(prev) && prev.kind === "word") {
105
- const g = { kind: "group", open: "<", close: ">", children: [], nl: t.nl };
106
- siblings().push(g);
107
- stack.push(g);
108
- continue;
109
- }
110
- siblings().push(t);
111
- continue;
112
- }
113
- if (t.kind === "punct" && (t.text === "}" || t.text === ")" || t.text === "]" || t.text === ">")) {
114
- const g = stack[stack.length - 1];
115
- if (t.text === ">" && (!g || g.open !== "<")) {
116
- siblings().push(t);
117
- continue;
118
- }
119
- if (!g || g.close !== t.text) {
120
- throw new Error("unbalanced brackets");
121
- }
122
- stack.pop();
123
- continue;
124
- }
125
- siblings().push(t);
126
- }
127
- if (stack.length) {
128
- throw new Error("unbalanced brackets");
129
- }
130
- return root;
131
- }
132
- function normalize(nodes) {
133
- for (let i = 0; i < nodes.length; i++) {
134
- const n = nodes[i];
135
- if (!isGroup(n)) {
136
- const key = n.kind === "string" && /^["']([A-Za-z_$][A-Za-z0-9_$]*)["']$/.exec(n.text);
137
- const next2 = nodes[i + 1];
138
- if (key && next2 && isPunct(next2, ":")) {
139
- nodes[i] = { kind: "word", text: key[1], nl: n.nl };
140
- }
141
- continue;
142
- }
143
- normalize(n.children);
144
- while (n.children.length && (isPunct(n.children[n.children.length - 1], ",") || isPunct(n.children[n.children.length - 1], ";"))) {
145
- n.children.pop();
146
- }
147
- const prev = nodes[i - 1];
148
- const next = nodes[i + 1];
149
- const wrapsWholeValue = next === void 0 || isPunct(next, ";") || isPunct(next, ",");
150
- const isFunctionType = n.children.some((c) => isPunct(c, "=>"));
151
- if (n.open === "(" && n.children.length > 0 && prev && isPunct(prev, ":") && wrapsWholeValue && !isFunctionType) {
152
- n.children[0].nl = n.nl;
153
- nodes.splice(i, 1, ...n.children);
154
- i--;
155
- }
156
- }
157
- }
158
- function isMemberEnd(n) {
159
- if (isGroup(n)) {
160
- return true;
161
- }
162
- return n.kind === "word" || n.kind === "string" || n.kind === "block-comment" || n.kind === "line-comment" || n.text === "?";
163
- }
164
- function isMemberStart(n) {
165
- if (isGroup(n)) {
166
- return false;
167
- }
168
- return n.kind === "word" || n.kind === "string" || n.kind === "block-comment" || n.kind === "line-comment";
169
- }
170
- function splitMembers(nodes, splitOnComma) {
171
- const members = [];
172
- let cur = [];
173
- let hasSeparators = false;
174
- let usedComma = false;
175
- const push = () => {
176
- if (cur.length) {
177
- members.push(cur);
178
- }
179
- cur = [];
180
- };
181
- for (const n of nodes) {
182
- if (isPunct(n, ";") || splitOnComma && isPunct(n, ",")) {
183
- hasSeparators = true;
184
- usedComma ||= n.text === ",";
185
- push();
186
- continue;
187
- }
188
- const isTrailingLineComment = !isGroup(n) && n.kind === "line-comment" && n.nl === 0;
189
- if (isTrailingLineComment && !cur.length && members.length) {
190
- members[members.length - 1].push(n);
191
- continue;
192
- }
193
- if (cur.length) {
194
- const prev = cur[cur.length - 1];
195
- const prevIsLineComment = !isGroup(prev) && prev.kind === "line-comment";
196
- if (prevIsLineComment || n.nl > 0 && !isTrailingLineComment && isMemberEnd(prev) && isMemberStart(n)) {
197
- push();
198
- }
199
- }
200
- cur.push(n);
201
- }
202
- push();
203
- for (let i = members.length - 2; i >= 0; i--) {
204
- const onlyComments = members[i].every((n) => !isGroup(n) && n.kind === "block-comment");
205
- if (onlyComments) {
206
- members[i + 1].unshift(...members[i]);
207
- members.splice(i, 1);
208
- }
209
- }
210
- return { members, hasSeparators, usedComma };
211
- }
212
- function hasMultilineComment(nodes) {
213
- return nodes.some((n) => !isGroup(n) && n.kind === "block-comment" && n.text.includes("\n"));
214
- }
215
- function hasLineComment(nodes) {
216
- return nodes.some((n) => !isGroup(n) && n.kind === "line-comment");
217
- }
218
- function mustBreak(g) {
219
- if (hasLineComment(g.children) || hasMultilineComment(g.children)) {
220
- return true;
221
- }
222
- const { members, hasSeparators } = splitMembers(g.children, true);
223
- if (members.length > 1 && !hasSeparators) {
224
- return true;
225
- }
226
- if ((g.open === "{" || g.open === "(") && members.some((m) => !isGroup(m[0]) && m[0].kind === "block-comment")) {
227
- return true;
228
- }
229
- return g.children.some((c) => isGroup(c) && mustBreak(c));
230
- }
231
- function needSpace(a, b) {
232
- if (!a) {
233
- return false;
234
- }
235
- if (a.kind === "open" && b.kind === "close") {
236
- return false;
237
- }
238
- if (b.kind === "punct" && (b.text === "," || b.text === ";" || b.text === ":" || b.text === "?")) {
239
- return false;
240
- }
241
- if (b.kind === "close") {
242
- return b.text === "}";
243
- }
244
- if (a.kind === "open") {
245
- return a.text === "{";
246
- }
247
- if (b.kind === "open") {
248
- if (b.text === "(" || b.text === "[") {
249
- return !(a.kind === "word" || a.kind === "string" || a.kind === "close");
250
- }
251
- if (b.text === "<") {
252
- return false;
253
- }
254
- return true;
255
- }
256
- return true;
257
- }
258
- function flatAtoms(nodes) {
259
- const out = [];
260
- for (const n of nodes) {
261
- if (isGroup(n)) {
262
- out.push({ kind: "open", text: n.open });
263
- out.push(...flatAtoms(n.children));
264
- out.push({ kind: "close", text: n.close });
265
- } else {
266
- out.push({ kind: n.kind, text: n.text });
267
- }
268
- }
269
- return out;
270
- }
271
- function joinAtoms(atoms) {
272
- let s = "";
273
- let prev = null;
274
- for (const a of atoms) {
275
- if (needSpace(prev, a)) {
276
- s += " ";
277
- }
278
- s += a.text;
279
- prev = a;
280
- }
281
- return s;
282
- }
283
- var canFlatten = (nodes) => !hasLineComment(nodes) && !hasMultilineComment(nodes) && !nodes.some((n) => isGroup(n) && mustBreak(n));
284
- var Printer = (_class = class {constructor() { _class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this); }
285
- __init() {this._lines = []}
286
- __init2() {this._cur = ""}
287
- __init3() {this._prev = null}
288
- atom(a) {
289
- if (this._prev && this._cur !== "" && needSpace(this._prev, a)) {
290
- this._cur += " ";
291
- }
292
- this._cur += a.text;
293
- this._prev = a;
294
- }
295
- flat(nodes) {
296
- for (const a of flatAtoms(nodes)) {
297
- this.atom(a);
298
- }
299
- }
300
- newline(level) {
301
- this._lines.push(this._cur);
302
- this._cur = INDENT.repeat(level);
303
- this._prev = null;
304
- }
305
- blankLine(level) {
306
- this._lines.push(this._cur);
307
- this._lines.push("");
308
- this._cur = INDENT.repeat(level);
309
- this._prev = null;
310
- }
311
- get column() {
312
- return this._cur.length;
313
- }
314
- get lineIsEmpty() {
315
- return this._cur.trim() === "";
316
- }
317
- comment(text, level) {
318
- const lines = text.split("\n").map((l) => l.trim());
319
- for (let i = 0; i < lines.length; i++) {
320
- if (i > 0) {
321
- this.newline(level);
322
- this._cur += lines[i].startsWith("*") ? " " : "";
323
- this._cur += lines[i];
324
- } else {
325
- this.atom({ kind: "block-comment", text: lines[i] });
326
- }
327
- this._prev = { kind: "block-comment", text: lines[i] };
328
- }
329
- }
330
- toString() {
331
- this._lines.push(this._cur);
332
- const out = this._lines.map((l) => l.trim() === "" ? "" : l).join("\n").replace(/\n{3,}/g, "\n\n");
333
- this._lines.pop();
334
- return out.trim();
335
- }
336
- }, _class);
337
- function flatWidth(nodes) {
338
- if (!canFlatten(nodes)) {
339
- return null;
340
- }
341
- return joinAtoms(flatAtoms(nodes)).length;
342
- }
343
- function fitsFlat(p, nodes) {
344
- const width = flatWidth(nodes);
345
- return width !== null && p.column + width + 1 <= WIDTH;
346
- }
347
- function walk(p, nodes, level, tailWidth = 0) {
348
- for (let i = 0; i < nodes.length; i++) {
349
- const n = nodes[i];
350
- if (isGroup(n)) {
351
- const own = mustBreak(n) ? null : flatWidth([n]);
352
- let restNodes = nodes.slice(i + 1);
353
- const lineCommentIdx = restNodes.findIndex((x) => !isGroup(x) && x.kind === "line-comment");
354
- if (lineCommentIdx !== -1) {
355
- restNodes = restNodes.slice(0, lineCommentIdx);
356
- }
357
- const rest = flatWidth(restNodes);
358
- const after = rest === null ? 0 : rest + tailWidth;
359
- if (own !== null && p.column + 1 + own + after <= WIDTH) {
360
- p.flat([n]);
361
- } else {
362
- breakGroup(p, n, level, after);
363
- }
364
- continue;
365
- }
366
- if (n.kind === "block-comment" && n.text.includes("\n")) {
367
- if (!p.lineIsEmpty) {
368
- p.newline(level);
369
- }
370
- p.comment(n.text, level);
371
- p.newline(level);
372
- continue;
373
- }
374
- if (n.kind === "line-comment") {
375
- p.atom({ kind: "line-comment", text: n.text });
376
- continue;
377
- }
378
- p.atom({ kind: n.kind, text: n.text });
379
- }
380
- }
381
- function breakGroup(p, g, level, tailWidth = 0) {
382
- if (g.open === "<") {
383
- p.atom({ kind: "open", text: "<" });
384
- walk(p, g.children, level, tailWidth + 1);
385
- p.atom({ kind: "close", text: ">" });
386
- return;
387
- }
388
- const { members, usedComma } = splitMembers(g.children, true);
389
- const hasLeadingComment = members.some((m) => !isGroup(m[0]) && m[0].kind === "block-comment");
390
- const single = members.length === 1 ? members[0] : null;
391
- const endsInObject = !!single && isGroup(single[single.length - 1]) && single[single.length - 1].open === "{";
392
- const hasUnion = !!single && single.some((n) => isPunct(n, "|"));
393
- if (g.open === "(" && endsInObject && !hasUnion && !hasLeadingComment) {
394
- p.atom({ kind: "open", text: "(" });
395
- walk(p, g.children, level, tailWidth + 1);
396
- p.atom({ kind: "close", text: ")" });
397
- return;
398
- }
399
- const separator = g.open === "(" || g.open === "[" ? "," : usedComma ? "," : null;
400
- const trailingSeparator = g.open === "(" || g.open === "[";
401
- p.atom({ kind: "open", text: g.open });
402
- for (let i = 0; i < members.length; i++) {
403
- p.newline(level + 1);
404
- renderMember(p, members[i], level + 1);
405
- if (separator && (trailingSeparator || i < members.length - 1)) {
406
- p.atom({ kind: "punct", text: separator });
407
- }
408
- }
409
- p.newline(level);
410
- p.atom({ kind: "close", text: g.close });
411
- }
412
- function renderMember(p, nodes, level) {
413
- let rest = nodes;
414
- while (rest.length && !isGroup(rest[0]) && rest[0].kind === "block-comment") {
415
- const c = rest[0];
416
- p.comment(c.text, level);
417
- rest = rest.slice(1);
418
- if (rest.length) {
419
- p.newline(level);
420
- }
421
- }
422
- if (!rest.length) {
423
- return;
424
- }
425
- if (fitsFlat(p, rest)) {
426
- p.flat(rest);
427
- return;
428
- }
429
- const pipeIdx = rest.findIndex((n) => isPunct(n, "|"));
430
- const parenIdx = rest.findIndex((n) => isGroup(n) && n.open === "(");
431
- if (pipeIdx !== -1 && (parenIdx === -1 || pipeIdx < parenIdx)) {
432
- let colonIdx = -1;
433
- for (let i = 0; i < pipeIdx; i++) {
434
- if (isPunct(rest[i], ":") || isPunct(rest[i], "=")) {
435
- colonIdx = i;
436
- }
437
- }
438
- const prefix = rest.slice(0, colonIdx + 1);
439
- const tail = rest.slice(colonIdx + 1);
440
- if (!prefix.length || fitsFlat(p, prefix)) {
441
- p.flat(prefix);
442
- const options = [];
443
- let cur = [];
444
- for (const n of tail) {
445
- if (isPunct(n, "|")) {
446
- options.push(cur);
447
- cur = [];
448
- } else {
449
- cur.push(n);
450
- }
451
- }
452
- options.push(cur);
453
- const optionLevel = prefix.length ? level + 1 : level;
454
- let first = true;
455
- for (const option of options) {
456
- if (!option.length) {
457
- continue;
458
- }
459
- if (!first || prefix.length) {
460
- p.newline(optionLevel);
461
- }
462
- first = false;
463
- p.atom({ kind: "punct", text: "|" });
464
- walk(p, option, optionLevel + 1);
465
- }
466
- return;
467
- }
468
- }
469
- const eqIdx = rest.findIndex((n) => isPunct(n, "="));
470
- if (eqIdx !== -1) {
471
- const prefix = rest.slice(0, eqIdx + 1);
472
- if (fitsFlat(p, prefix)) {
473
- p.flat(prefix);
474
- walk(p, rest.slice(eqIdx + 1), level);
475
- return;
476
- }
477
- }
478
- walk(p, rest, level);
479
- }
480
- function renderStatements(p, nodes, level) {
481
- const { members: statements } = splitMembers(nodes, false);
482
- for (let i = 0; i < statements.length; i++) {
483
- const stmt = statements[i];
484
- if (i > 0) {
485
- if ((_nullishCoalesce(stmt[0].nl, () => ( 0))) >= 2) {
486
- p.blankLine(level);
487
- } else {
488
- p.newline(level);
489
- }
490
- }
491
- renderStatement(p, stmt, level);
492
- }
493
- }
494
- function renderStatement(p, stmt, level) {
495
- while (stmt.length && !isGroup(stmt[0]) && stmt[0].kind === "block-comment") {
496
- p.comment(stmt[0].text, level);
497
- stmt = stmt.slice(1);
498
- if (stmt.length) {
499
- p.newline(level);
500
- }
501
- }
502
- if (!stmt.length) {
503
- return;
504
- }
505
- const nsIdx = stmt.findIndex(
506
- (n) => !isGroup(n) && n.kind === "word" && (n.text === "namespace" || n.text === "module")
507
- );
508
- const bodyIdx = stmt.findIndex((n) => isGroup(n) && n.open === "{");
509
- if (nsIdx !== -1 && bodyIdx > nsIdx) {
510
- const body = stmt[bodyIdx];
511
- p.flat(stmt.slice(0, bodyIdx));
512
- p.atom({ kind: "open", text: "{" });
513
- if (body.children.length) {
514
- p.newline(level + 1);
515
- renderStatements(p, body.children, level + 1);
516
- p.newline(level);
517
- }
518
- p.atom({ kind: "close", text: "}" });
519
- walk(p, stmt.slice(bodyIdx + 1), level);
520
- return;
521
- }
522
- renderMember(p, stmt, level);
523
- }
524
- function formatTypingsUnsafe(typings) {
525
- const tokens = tokenize(typings);
526
- if (!tokens.length) {
527
- return "";
528
- }
529
- const nodes = parse(tokens);
530
- normalize(nodes);
531
- const printer = new Printer();
532
- renderStatements(printer, nodes, 0);
533
- return printer.toString();
534
- }
535
-
536
- // src/formatting.ts
537
- async function formatTypings(typings, options) {
538
- try {
539
- return formatTypingsUnsafe(typings);
540
- } catch (err) {
541
- if (_nullishCoalesce((options == null ? void 0 : options.throwOnError), () => ( true))) {
542
- throw new (0, _chunkPK72FAKDcjs.CodeFormattingError)(err instanceof Error ? err.message : _nullishCoalesce((err == null ? void 0 : err.toString()), () => ( "Unknown Error")), typings);
543
- }
544
- return typings;
545
- }
546
- }
547
-
548
- // src/typings.ts
549
- var Primitives = [
550
- "string",
551
- "number",
552
- "boolean",
553
- "unknown",
554
- "void",
555
- "any",
556
- "null",
557
- "undefined",
558
- "never",
559
- "bigint",
560
- "symbol",
561
- "object"
562
- ];
563
- var LARGE_DECLARATION_LINES = 5;
564
- var isPrimitive = (type) => Primitives.includes(type);
565
- var isArrayOfPrimitives = (type) => Primitives.map((p) => `${p}[]`).includes(type);
566
- var stripSpaces = (typings) => typings.replace(/ +/g, " ").trim();
567
- var KeyValue = class {
568
- constructor(key, value) {
569
- this.key = key;
570
- this.value = value;
571
- }
572
- };
573
- var FnParameters = class {
574
- constructor(schema) {
575
- this.schema = schema;
576
- }
577
- };
578
- var FnReturn = class {
579
- constructor(schema) {
580
- this.schema = schema;
581
- }
582
- };
583
- var Declaration = class {
584
- constructor(schema, identifier) {
585
- this.schema = schema;
586
- this.identifier = identifier;
587
- }
588
- };
589
- async function getTypings(schema, options) {
590
- options ??= {};
591
- options.declaration ??= false;
592
- let wrappedSchema = schema;
593
- if ((options == null ? void 0 : options.declaration) && _zui.z.is.zuiType(schema)) {
594
- const title = "title" in schema.ui ? schema.ui.title : null;
595
- if (!title) {
596
- throw new Error('Only schemas with "title" Zui property can be declared.');
597
- }
598
- wrappedSchema = new Declaration(schema, title);
599
- }
600
- let dts = await sUnwrapZodRecursive(wrappedSchema, { ...options });
601
- dts = await formatTypings(dts, { throwOnError: false });
602
- return dts;
603
- }
604
- async function sUnwrapZodRecursive(schema, options) {
605
- return sUnwrapZod(schema, options);
606
- }
607
- async function sUnwrapZod(schema, options) {
608
- var _a, _b;
609
- const newOptions = {
610
- ...options,
611
- declaration: false,
612
- parent: schema
613
- };
614
- if (schema instanceof Declaration) {
615
- const description = _chunkGOWPACSKcjs.getMultilineComment.call(void 0, schema.schema.description);
616
- const withoutDesc = schema.schema.describe("");
617
- const typings = await sUnwrapZodRecursive(withoutDesc, { ...newOptions, declaration: true });
618
- const isLargeDeclaration = typings.split("\n").length >= LARGE_DECLARATION_LINES;
619
- const closingTag = isLargeDeclaration ? `// end of ${schema.identifier}` : "";
620
- if (_zui.z.is.zuiFunction(schema.schema)) {
621
- return stripSpaces(`${description}
622
- declare function ${schema.identifier}${typings};${closingTag}`);
623
- }
624
- return stripSpaces(`${description}
625
- declare const ${schema.identifier}: ${typings};${closingTag}`);
626
- }
627
- if (schema instanceof KeyValue) {
628
- if (_zui.z.is.zuiOptional(schema.value) || _zui.z.is.zuiDefault(schema.value)) {
629
- let innerType = schema.value._def.innerType;
630
- if (_zui.z.is.zuiType(innerType) && !innerType.description && schema.value.description) {
631
- innerType = innerType == null ? void 0 : innerType.describe(schema.value.description);
632
- }
633
- const optionalToken = schema.key.endsWith("?") ? "" : "?";
634
- return sUnwrapZodRecursive(new KeyValue(schema.key + optionalToken, innerType), newOptions);
635
- }
636
- const description = _chunkGOWPACSKcjs.getMultilineComment.call(void 0, schema.value._def.description || schema.value.description);
637
- const delimiter = (description == null ? void 0 : description.trim().length) > 0 ? "\n" : "";
638
- const withoutDesc = schema.value.describe("");
639
- return `${delimiter}${description}${delimiter}${schema.key}: ${await sUnwrapZodRecursive(withoutDesc, newOptions)}${delimiter}`;
640
- }
641
- if (schema instanceof FnParameters) {
642
- if (_zui.z.is.zuiTuple(schema.schema)) {
643
- let args = "";
644
- for (let i = 0; i < schema.schema.items.length; i++) {
645
- const argName = _nullishCoalesce(((_b = (_a = schema.schema.items[i]) == null ? void 0 : _a.ui) == null ? void 0 : _b.title), () => ( `arg${i}`));
646
- const item = schema.schema.items[i];
647
- args += `${await sUnwrapZodRecursive(new KeyValue(_chunkGOWPACSKcjs.toPropertyKey.call(void 0, argName), item), newOptions)}, `;
648
- }
649
- return args;
650
- }
651
- const isLiteral = _zui.z.is.zuiLiteral(schema.schema.naked());
652
- const typings = (await sUnwrapZodRecursive(schema.schema, newOptions)).trim();
653
- const startsWithPairs = typings.startsWith("{") && typings.endsWith("}") || typings.startsWith("[") && typings.endsWith("]") || typings.startsWith("(") && typings.endsWith(")") || typings.startsWith("Array<") && typings.endsWith(">") || typings.startsWith("Record<") && typings.endsWith(">") || isArrayOfPrimitives(typings);
654
- if (startsWithPairs || isLiteral) {
655
- return `args: ${typings}`;
656
- } else {
657
- return typings;
658
- }
659
- }
660
- if (schema instanceof FnReturn) {
661
- if (_zui.z.is.zuiOptional(schema.schema)) {
662
- return `${await sUnwrapZodRecursive(schema.schema.unwrap(), newOptions)} | undefined`;
663
- }
664
- return sUnwrapZodRecursive(schema.schema, newOptions);
665
- }
666
- if (schema === null) {
667
- return "unknown";
668
- }
669
- schema;
670
- if (_zui.z.is.zuiDefault(schema)) {
671
- return sUnwrapZodRecursive(schema._def.innerType, options);
672
- }
673
- if (_zui.z.is.zuiVoid(schema)) {
674
- return "void";
675
- }
676
- if (_zui.z.is.zuiUnknown(schema)) {
677
- return "unknown";
678
- }
679
- if (_zui.z.is.zuiAny(schema)) {
680
- return "any";
681
- }
682
- if (_zui.z.is.zuiPromise(schema)) {
683
- return `Promise<${await sUnwrapZodRecursive(schema.unwrap(), newOptions)}>`;
684
- }
685
- if (_zui.z.is.zuiFunction(schema)) {
686
- const description = _chunkGOWPACSKcjs.getMultilineComment.call(void 0, schema._def.description);
687
- const input = await sUnwrapZodRecursive(new FnParameters(schema._def.args), newOptions);
688
- const output = await sUnwrapZodRecursive(new FnReturn(schema._def.returns), newOptions);
689
- if (options == null ? void 0 : options.declaration) {
690
- return `${description}
691
- (${input}): ${output}`;
692
- }
693
- return `${description}
694
- (${input}) => ${output}`;
695
- }
696
- if (_zui.z.is.zuiArray(schema)) {
697
- const item = await sUnwrapZodRecursive(schema._def.type, newOptions);
698
- if (isPrimitive(item)) {
699
- return `${item}[]`;
700
- }
701
- return `Array<${item}>`;
702
- }
703
- if (_zui.z.is.zuiEnum(schema)) {
704
- const values = schema._def.values.map(_chunkGOWPACSKcjs.escapeString);
705
- return values.join(" | ");
706
- }
707
- if (_zui.z.is.zuiTuple(schema)) {
708
- if (schema.items.length === 0) {
709
- return "[]";
710
- }
711
- const items = await Promise.all(schema.items.map((i) => sUnwrapZodRecursive(i, newOptions)));
712
- return `[${items.join(", ")}]`;
713
- }
714
- if (_zui.z.is.zuiNullable(schema)) {
715
- return `${await sUnwrapZodRecursive(schema.unwrap(), options)} | null`;
716
- }
717
- if (_zui.z.is.zuiOptional(schema)) {
718
- if ((options == null ? void 0 : options.declaration) || _zui.z.is.zuiType(options == null ? void 0 : options.parent) && options.parent.typeName === "ZodRecord") {
719
- return `${await sUnwrapZodRecursive(schema._def.innerType, newOptions)} | undefined`;
720
- }
721
- const optionalToken = options.parent instanceof KeyValue ? "| undefined" : "";
722
- const val = `${await sUnwrapZodRecursive(schema._def.innerType, newOptions)}${optionalToken}`;
723
- return val;
724
- }
725
- if (_zui.z.is.zuiObject(schema)) {
726
- const props = await Promise.all(
727
- Object.entries(schema.shape).map(async ([key, value]) => {
728
- if (_zui.z.is.zuiType(value)) {
729
- return sUnwrapZodRecursive(new KeyValue(_chunkGOWPACSKcjs.toPropertyKey.call(void 0, key), value), newOptions);
730
- }
731
- return `${key}: unknown`;
732
- })
733
- );
734
- return `{ ${props.join("; ")} }`;
735
- }
736
- if (_zui.z.is.zuiString(schema)) {
737
- const description = _chunkGOWPACSKcjs.getMultilineComment.call(void 0, schema._def.description);
738
- return `${description} string`.trim();
739
- }
740
- if (_zui.z.is.zuiUnion(schema)) {
741
- const description = _chunkGOWPACSKcjs.getMultilineComment.call(void 0, schema._def.description);
742
- const options2 = await Promise.all(
743
- schema.options.map(async (option) => {
744
- return sUnwrapZodRecursive(option, newOptions);
745
- })
746
- );
747
- return `${description}
748
- ${options2.join(" | ")}`;
749
- }
750
- if (_zui.z.is.zuiLiteral(schema)) {
751
- const description = _chunkGOWPACSKcjs.getMultilineComment.call(void 0, schema._def.description);
752
- return `${description}
753
- ${typeof schema.value === "string" ? _chunkGOWPACSKcjs.escapeString.call(void 0, schema.value) : String(schema.value)}`.trim();
754
- }
755
- if (_zui.z.is.zuiNumber(schema)) {
756
- const description = _chunkGOWPACSKcjs.getMultilineComment.call(void 0, schema._def.description);
757
- return `${description} number`.trim();
758
- }
759
- if (_zui.z.is.zuiBoolean(schema)) {
760
- const description = _chunkGOWPACSKcjs.getMultilineComment.call(void 0, schema._def.description);
761
- return `${description} boolean`.trim();
762
- }
763
- if (_zui.z.is.zuiCatch(schema)) {
764
- return sUnwrapZodRecursive(schema.removeCatch(), newOptions);
765
- }
766
- if (_zui.z.is.zuiLazy(schema)) {
767
- return sUnwrapZodRecursive(schema._def.getter(), newOptions);
768
- }
769
- if (_zui.z.is.zuiRecord(schema)) {
770
- const description = _chunkGOWPACSKcjs.getMultilineComment.call(void 0, schema._def.description);
771
- const keyType = await sUnwrapZodRecursive(schema._def.keyType, newOptions);
772
- const valueType = await sUnwrapZodRecursive(schema._def.valueType, newOptions);
773
- return `${description} { [key: (${keyType})]: (${valueType}) }`;
774
- }
775
- try {
776
- let typings = schema == null ? void 0 : schema.toTypescriptType({ treatDefaultAsOptional: true });
777
- typings ??= "unknown";
778
- return stripSpaces(typings);
779
- } catch (error) {
780
- console.error("Error in sUnwrapZod", { error, schema, parent: options == null ? void 0 : options.parent });
781
- return "unknown";
782
- }
783
- }
784
-
785
-
786
-
787
-
788
-
789
-
790
-
791
-
792
- exports.isGroup = isGroup; exports.isPunct = isPunct; exports.tokenize = tokenize; exports.parse = parse; exports.formatTypings = formatTypings; exports.getTypings = getTypings;