llmz 0.1.5 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +185 -98
- package/dist/chat.d.ts +34 -0
- package/dist/chunk-665O7CAN.js +788 -0
- package/dist/chunk-DD4AZSP5.cjs +788 -0
- package/dist/{chunk-EFEF2AL7.js → chunk-DH35WO5G.js} +93 -556
- package/dist/chunk-E5NHK3FS.js +1637 -0
- package/dist/{chunk-WODK7Y4J.cjs → chunk-ETYFOCWC.cjs} +2 -2
- package/dist/{chunk-IRCB4FRM.js → chunk-GC5IQDGV.js} +1 -1
- package/dist/{chunk-L74UZONX.js → chunk-HM5H556L.js} +3 -1
- package/dist/chunk-I56MPOVG.cjs +62 -0
- package/dist/chunk-KWQTYXAT.js +62 -0
- package/dist/{chunk-C7T6OJB4.cjs → chunk-MY26EAOP.cjs} +146 -88
- package/dist/{chunk-JXD2KJVB.cjs → chunk-WWZ2W4WR.cjs} +103 -566
- package/dist/chunk-YGKQEVQQ.cjs +1637 -0
- package/dist/{chunk-ZPHRTTQX.cjs → chunk-YQT5G77W.cjs} +3 -1
- package/dist/{chunk-TIZWOIDF.js → chunk-ZWUWCRHG.js} +135 -77
- package/dist/compiler/compiler.d.ts +7 -2
- package/dist/compiler/index.d.ts +1 -1
- package/dist/compiler/plugins/async-wrapper.d.ts +11 -0
- package/dist/component-2NYFY6CW.cjs +14 -0
- package/dist/{component-2Z3KLWLX.js → component-ASNZHQUR.js} +3 -7
- package/dist/component.d.ts +3 -10
- package/dist/context.d.ts +88 -2
- package/dist/{dual-modes-HEXPFVUE.js → dual-modes-RMF7V7ZQ.js} +2 -4
- package/dist/dual-modes-ZZY6QPYT.cjs +10 -0
- package/dist/{execute-22PSGL7P.cjs → execute-2AGZ5QUN.cjs} +333 -89
- package/dist/{execute-ZENBZBWL.js → execute-LNUBLVMZ.js} +323 -79
- package/dist/formatting.d.ts +1 -2
- package/dist/index.cjs +511 -36
- package/dist/index.d.ts +8 -5
- package/dist/index.js +495 -20
- package/dist/message-stream/index.d.ts +9 -0
- package/dist/message-stream/instructions.d.ts +22 -0
- package/dist/message-stream/normalizer.d.ts +21 -0
- package/dist/message-stream/parser.d.ts +81 -0
- package/dist/message-stream/registry.d.ts +14 -0
- package/dist/message-stream/replayable.d.ts +27 -0
- package/dist/message-stream/sanitize.d.ts +10 -0
- package/dist/message-stream/stream.d.ts +54 -0
- package/dist/message-stream/types.d.ts +96 -0
- package/dist/message-stream/validator.d.ts +23 -0
- package/dist/message-stream/validator.test.d.ts +1 -0
- package/dist/prompts/chat-mode/system.md.d.ts +1 -1
- package/dist/prompts/chat-mode/user.md.d.ts +1 -1
- package/dist/prompts/common.d.ts +5 -5
- package/dist/prompts/prompt.d.ts +43 -6
- package/dist/prompts/protocol.d.ts +18 -0
- package/dist/prompts/worker-mode/system.md.d.ts +1 -1
- package/dist/prompts/worker-mode/user.md.d.ts +1 -1
- package/dist/result.d.ts +31 -0
- package/dist/runtime/execute.test.d.ts +1 -0
- package/dist/runtime/generate.d.ts +24 -1
- package/dist/runtime/interpret-result.d.ts +10 -0
- package/dist/runtime/types.d.ts +29 -4
- package/dist/{tool-DNHVW3KC.js → tool-HTAYKIA2.js} +2 -2
- package/dist/{tool-GJ6ZXWS2.cjs → tool-V55GD2FS.cjs} +3 -3
- package/dist/truncator-7PGEGCHV.cjs +12 -0
- package/dist/{truncator-3U2QUUJJ.js → truncator-OZOBNYON.js} +3 -1
- package/dist/truncator.d.ts +2 -0
- package/dist/types.d.ts +8 -1
- package/dist/{typings-ZTFPPA5W.cjs → typings-S6I6IPTG.cjs} +2 -2
- package/dist/{typings-3YV3RDMP.js → typings-SCKZCAPN.js} +1 -1
- package/dist/typings-formatter.d.ts +15 -0
- package/dist/typings-formatter.test.d.ts +1 -0
- package/dist/vm/drivers/quickjs.d.ts +2 -0
- package/dist/vm/index.d.ts +7 -0
- package/dist/vm/instrument.d.ts +1 -1
- package/dist/{vm-PYCKS77H.js → vm-44H4UKI2.js} +5 -4
- package/dist/{vm-VHB67FVH.cjs → vm-A3OTQVIR.cjs} +4 -3
- package/package.json +6 -7
- package/dist/chunk-2O3UTPVH.js +0 -813
- package/dist/chunk-3T5IU7OU.js +0 -186
- package/dist/chunk-7LMIOS6H.cjs +0 -287
- package/dist/chunk-BBX2LDZE.cjs +0 -813
- package/dist/chunk-CQ3UJW76.cjs +0 -186
- package/dist/chunk-TOGYDN6U.js +0 -287
- package/dist/compiler/plugins/async-iterator.d.ts +0 -6
- package/dist/compiler/plugins/braces-tsx.d.ts +0 -3
- package/dist/compiler/plugins/html-to-markdown.d.ts +0 -21
- package/dist/compiler/plugins/jsx-preserve-newlines.d.ts +0 -5
- package/dist/compiler/plugins/jsx-undefined-vars.d.ts +0 -14
- package/dist/component-NNHBHD72.cjs +0 -18
- package/dist/dual-modes-LLIWZCHC.cjs +0 -12
- package/dist/truncator-3ZN7W6NB.cjs +0 -10
- /package/dist/{compiler/plugins/html-to-markdown.test.d.ts → message-stream/instructions.test.d.ts} +0 -0
- /package/dist/{compiler/plugins/jsx-undefined-vars.test.d.ts → message-stream/normalizer.test.d.ts} +0 -0
- /package/dist/{component.test.d.ts → message-stream/parser.test.d.ts} +0 -0
- /package/dist/{vm/vm-jsx.test.d.ts → message-stream/stream.test.d.ts} +0 -0
package/dist/chunk-3T5IU7OU.js
DELETED
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createJsxComponent,
|
|
3
|
-
isAnyJsxComponent,
|
|
4
|
-
isJsxComponent
|
|
5
|
-
} from "./chunk-XTEHT2TK.js";
|
|
6
|
-
|
|
7
|
-
// src/component.ts
|
|
8
|
-
import { z } from "@bpinternal/zui";
|
|
9
|
-
function assertValidComponent(component) {
|
|
10
|
-
if (!component.name) {
|
|
11
|
-
throw new Error("Component must have a name");
|
|
12
|
-
}
|
|
13
|
-
const nameRegex = /^[A-Z]{3,50}$/i;
|
|
14
|
-
if (!nameRegex.test(component.name)) {
|
|
15
|
-
throw new Error(
|
|
16
|
-
`Component name "${component.name}" must be 3-50 characters long and start with an uppercase letter`
|
|
17
|
-
);
|
|
18
|
-
}
|
|
19
|
-
if (component.aliases) {
|
|
20
|
-
for (const alias of component.aliases) {
|
|
21
|
-
if (!nameRegex.test(alias)) {
|
|
22
|
-
throw new Error(`Alias "${alias}" must be 3-50 characters long and start with an uppercase letter`);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
if (!component.description) {
|
|
27
|
-
throw new Error("Component must have a description");
|
|
28
|
-
}
|
|
29
|
-
if (!component.examples || component.examples.length === 0) {
|
|
30
|
-
throw new Error("Component must have at least one example");
|
|
31
|
-
}
|
|
32
|
-
if (component.type === "default" && !component.default) {
|
|
33
|
-
throw new Error("Default component must have default props and children");
|
|
34
|
-
}
|
|
35
|
-
if (component.type === "leaf" && !component.leaf) {
|
|
36
|
-
throw new Error("Leaf component must have leaf props");
|
|
37
|
-
}
|
|
38
|
-
if (component.type === "container" && !component.container) {
|
|
39
|
-
throw new Error("Container component must have container props and children");
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
var getDefaultValue = (schema) => {
|
|
43
|
-
if (schema._def.defaultValue !== void 0) {
|
|
44
|
-
if (typeof schema._def.defaultValue === "function") {
|
|
45
|
-
return String(schema._def.defaultValue()).toString();
|
|
46
|
-
} else {
|
|
47
|
-
return String(schema._def.defaultValue);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return "";
|
|
51
|
-
};
|
|
52
|
-
function getComponentReference(component) {
|
|
53
|
-
let doc = `### <${component.name}>
|
|
54
|
-
|
|
55
|
-
`;
|
|
56
|
-
doc += `${component.description}
|
|
57
|
-
|
|
58
|
-
`;
|
|
59
|
-
const getPropsDoc = (props) => {
|
|
60
|
-
const shape = props.shape;
|
|
61
|
-
if (Object.keys(shape).length === 0)
|
|
62
|
-
return "_No props._\n\n";
|
|
63
|
-
const zodTypeToTsType = {
|
|
64
|
-
ZodString: "string",
|
|
65
|
-
ZodNumber: "number",
|
|
66
|
-
ZodBoolean: "boolean",
|
|
67
|
-
ZodEnum: "enum",
|
|
68
|
-
ZodArray: "array",
|
|
69
|
-
ZodObject: "object",
|
|
70
|
-
ZodDate: "date",
|
|
71
|
-
ZodBigInt: "bigint",
|
|
72
|
-
ZodSymbol: "symbol",
|
|
73
|
-
ZodUndefined: "undefined",
|
|
74
|
-
ZodNull: "null",
|
|
75
|
-
ZodVoid: "void",
|
|
76
|
-
ZodNever: "never",
|
|
77
|
-
ZodUnknown: "unknown",
|
|
78
|
-
ZodAny: "any"
|
|
79
|
-
};
|
|
80
|
-
return Object.entries(shape).map(([name, schema]) => {
|
|
81
|
-
const naked = schema.naked();
|
|
82
|
-
const zodType = naked._def.typeName;
|
|
83
|
-
const defValue = getDefaultValue(schema);
|
|
84
|
-
const typings = z.is.zuiEnum(naked) ? naked._def.values.map((x) => `"${x}"`).join(" | ") : zodTypeToTsType[zodType] || zodType;
|
|
85
|
-
const required = !schema.isOptional() ? "**(required)**" : "(optional)";
|
|
86
|
-
const def = defValue ? ` _Default: \`${defValue}\`_` : "";
|
|
87
|
-
const description = schema.description || schema.naked().description || (schema == null ? void 0 : schema._def.description) || "";
|
|
88
|
-
return `- \`${name}: ${typings}\` ${required} \u2014 ${description}${def}`;
|
|
89
|
-
}).join("\n") + "\n\n";
|
|
90
|
-
};
|
|
91
|
-
const getChildrenDoc = (children) => {
|
|
92
|
-
if (children.length === 0)
|
|
93
|
-
return "_None allowed._\n\n";
|
|
94
|
-
return "Can contain:\n" + children.map((child) => `- ${child.description} \u2014 \`<${child.component.name}>\``).join("\n") + "\n\n";
|
|
95
|
-
};
|
|
96
|
-
const getExamplesDoc = (examples) => {
|
|
97
|
-
if (!examples.length)
|
|
98
|
-
return "";
|
|
99
|
-
return "**Examples:**\n\n" + examples.map((example) => `**${example.name}** \u2014 ${example.description}
|
|
100
|
-
|
|
101
|
-
\`\`\`tsx
|
|
102
|
-
${example.code.trim()}
|
|
103
|
-
\`\`\`
|
|
104
|
-
`).join("\n");
|
|
105
|
-
};
|
|
106
|
-
switch (component.type) {
|
|
107
|
-
case "leaf":
|
|
108
|
-
doc += "**Props:**\n\n";
|
|
109
|
-
doc += getPropsDoc(component.leaf.props);
|
|
110
|
-
doc += "**Children:**\n\n";
|
|
111
|
-
doc += getChildrenDoc([]);
|
|
112
|
-
doc += getExamplesDoc(component.examples);
|
|
113
|
-
break;
|
|
114
|
-
case "container":
|
|
115
|
-
doc += "**Props:**\n\n";
|
|
116
|
-
doc += getPropsDoc(component.container.props);
|
|
117
|
-
doc += "**Children:**\n\n";
|
|
118
|
-
doc += getChildrenDoc(component.container.children);
|
|
119
|
-
doc += getExamplesDoc(component.examples);
|
|
120
|
-
break;
|
|
121
|
-
case "default":
|
|
122
|
-
default:
|
|
123
|
-
doc += "**Props:**\n\n";
|
|
124
|
-
doc += getPropsDoc(component.default.props);
|
|
125
|
-
doc += getExamplesDoc(component.examples);
|
|
126
|
-
break;
|
|
127
|
-
}
|
|
128
|
-
return doc.trim();
|
|
129
|
-
}
|
|
130
|
-
var Component = class {
|
|
131
|
-
definition;
|
|
132
|
-
propsType;
|
|
133
|
-
// phantom type for inference
|
|
134
|
-
constructor(definition) {
|
|
135
|
-
assertValidComponent(definition);
|
|
136
|
-
this.definition = definition;
|
|
137
|
-
}
|
|
138
|
-
render(props, children = []) {
|
|
139
|
-
return createJsxComponent({ type: this.definition.name, props, children });
|
|
140
|
-
}
|
|
141
|
-
};
|
|
142
|
-
function isComponent(rendered, component) {
|
|
143
|
-
return isJsxComponent(component.definition.name, rendered);
|
|
144
|
-
}
|
|
145
|
-
function isAnyComponent(message) {
|
|
146
|
-
return isAnyJsxComponent(message);
|
|
147
|
-
}
|
|
148
|
-
function renderToTsx(component) {
|
|
149
|
-
const props = Object.entries(component.props).map(([key, value]) => {
|
|
150
|
-
if (typeof value === "string") {
|
|
151
|
-
return `${key}="${value}"`;
|
|
152
|
-
}
|
|
153
|
-
if (typeof value === "boolean") {
|
|
154
|
-
return value ? key : "";
|
|
155
|
-
}
|
|
156
|
-
if (typeof value === "number") {
|
|
157
|
-
return `${key}={${value}}`;
|
|
158
|
-
}
|
|
159
|
-
if (value === null || value === void 0) {
|
|
160
|
-
return "";
|
|
161
|
-
}
|
|
162
|
-
if (typeof value === "object") {
|
|
163
|
-
return `${key}={${JSON.stringify(value)}}`;
|
|
164
|
-
}
|
|
165
|
-
return `${key}={${String(value)}}`;
|
|
166
|
-
}).filter(Boolean).join(" ");
|
|
167
|
-
const children = component.children.map((child) => {
|
|
168
|
-
if (typeof child === "string") {
|
|
169
|
-
return child;
|
|
170
|
-
}
|
|
171
|
-
if (isAnyComponent(child)) {
|
|
172
|
-
return renderToTsx(child);
|
|
173
|
-
}
|
|
174
|
-
return String(child);
|
|
175
|
-
}).join("");
|
|
176
|
-
return `<${component.type}${props ? " " + props : ""}>${children}</${component.type}>`;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
export {
|
|
180
|
-
assertValidComponent,
|
|
181
|
-
getComponentReference,
|
|
182
|
-
Component,
|
|
183
|
-
isComponent,
|
|
184
|
-
isAnyComponent,
|
|
185
|
-
renderToTsx
|
|
186
|
-
};
|
package/dist/chunk-7LMIOS6H.cjs
DELETED
|
@@ -1,287 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
2
|
-
|
|
3
|
-
var _chunkPK72FAKDcjs = require('./chunk-PK72FAKD.cjs');
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var _chunkFPLSJF4Scjs = require('./chunk-FPLSJF4S.cjs');
|
|
9
|
-
|
|
10
|
-
// src/typings.ts
|
|
11
|
-
var _zui = require('@bpinternal/zui');
|
|
12
|
-
|
|
13
|
-
// src/formatting.ts
|
|
14
|
-
var _lrucache = require('lru-cache');
|
|
15
|
-
var _babel = require('prettier/plugins/babel'); var _babel2 = _interopRequireDefault(_babel);
|
|
16
|
-
var _estree = require('prettier/plugins/estree'); var _estree2 = _interopRequireDefault(_estree);
|
|
17
|
-
var _typescript = require('prettier/plugins/typescript'); var _typescript2 = _interopRequireDefault(_typescript);
|
|
18
|
-
var _standalone = require('prettier/standalone');
|
|
19
|
-
var cache = new (0, _lrucache.LRUCache)({ max: 1e3 });
|
|
20
|
-
async function formatTypings(typings, options) {
|
|
21
|
-
if (cache.has(typings)) {
|
|
22
|
-
return cache.get(typings);
|
|
23
|
-
}
|
|
24
|
-
try {
|
|
25
|
-
options ??= {};
|
|
26
|
-
options.throwOnError ??= true;
|
|
27
|
-
const result = (await _standalone.format.call(void 0, typings, {
|
|
28
|
-
singleAttributePerLine: true,
|
|
29
|
-
bracketSameLine: true,
|
|
30
|
-
semi: false,
|
|
31
|
-
...options,
|
|
32
|
-
embeddedLanguageFormatting: "off",
|
|
33
|
-
plugins: [_estree2.default, _babel2.default, _typescript2.default],
|
|
34
|
-
parser: "typescript",
|
|
35
|
-
filepath: "tools.d.ts"
|
|
36
|
-
})).trim();
|
|
37
|
-
cache.set(typings, result);
|
|
38
|
-
return result;
|
|
39
|
-
} catch (err) {
|
|
40
|
-
if (options == null ? void 0 : options.throwOnError) {
|
|
41
|
-
throw new (0, _chunkPK72FAKDcjs.CodeFormattingError)(err instanceof Error ? err.message : _nullishCoalesce((err == null ? void 0 : err.toString()), () => ( "Unknown Error")), typings);
|
|
42
|
-
}
|
|
43
|
-
return typings;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// src/typings.ts
|
|
48
|
-
var Primitives = [
|
|
49
|
-
"string",
|
|
50
|
-
"number",
|
|
51
|
-
"boolean",
|
|
52
|
-
"unknown",
|
|
53
|
-
"void",
|
|
54
|
-
"any",
|
|
55
|
-
"null",
|
|
56
|
-
"undefined",
|
|
57
|
-
"never",
|
|
58
|
-
"bigint",
|
|
59
|
-
"symbol",
|
|
60
|
-
"object"
|
|
61
|
-
];
|
|
62
|
-
var LARGE_DECLARATION_LINES = 5;
|
|
63
|
-
var isPrimitive = (type) => Primitives.includes(type);
|
|
64
|
-
var isArrayOfPrimitives = (type) => Primitives.map((p) => `${p}[]`).includes(type);
|
|
65
|
-
var stripSpaces = (typings) => typings.replace(/ +/g, " ").trim();
|
|
66
|
-
var KeyValue = class {
|
|
67
|
-
constructor(key, value) {
|
|
68
|
-
this.key = key;
|
|
69
|
-
this.value = value;
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
var FnParameters = class {
|
|
73
|
-
constructor(schema) {
|
|
74
|
-
this.schema = schema;
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
var FnReturn = class {
|
|
78
|
-
constructor(schema) {
|
|
79
|
-
this.schema = schema;
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
var Declaration = class {
|
|
83
|
-
constructor(schema, identifier) {
|
|
84
|
-
this.schema = schema;
|
|
85
|
-
this.identifier = identifier;
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
async function getTypings(schema, options) {
|
|
89
|
-
options ??= {};
|
|
90
|
-
options.declaration ??= false;
|
|
91
|
-
let wrappedSchema = schema;
|
|
92
|
-
if ((options == null ? void 0 : options.declaration) && _zui.z.is.zuiType(schema)) {
|
|
93
|
-
const title = "title" in schema.ui ? schema.ui.title : null;
|
|
94
|
-
if (!title) {
|
|
95
|
-
throw new Error('Only schemas with "title" Zui property can be declared.');
|
|
96
|
-
}
|
|
97
|
-
wrappedSchema = new Declaration(schema, title);
|
|
98
|
-
}
|
|
99
|
-
let dts = await sUnwrapZodRecursive(wrappedSchema, { ...options });
|
|
100
|
-
dts = await formatTypings(dts, { throwOnError: false });
|
|
101
|
-
return dts;
|
|
102
|
-
}
|
|
103
|
-
async function sUnwrapZodRecursive(schema, options) {
|
|
104
|
-
return sUnwrapZod(schema, options);
|
|
105
|
-
}
|
|
106
|
-
async function sUnwrapZod(schema, options) {
|
|
107
|
-
var _a, _b;
|
|
108
|
-
const newOptions = {
|
|
109
|
-
...options,
|
|
110
|
-
declaration: false,
|
|
111
|
-
parent: schema
|
|
112
|
-
};
|
|
113
|
-
if (schema instanceof Declaration) {
|
|
114
|
-
const description = _chunkFPLSJF4Scjs.getMultilineComment.call(void 0, schema.schema.description);
|
|
115
|
-
const withoutDesc = schema.schema.describe("");
|
|
116
|
-
const typings = await sUnwrapZodRecursive(withoutDesc, { ...newOptions, declaration: true });
|
|
117
|
-
const isLargeDeclaration = typings.split("\n").length >= LARGE_DECLARATION_LINES;
|
|
118
|
-
const closingTag = isLargeDeclaration ? `// end of ${schema.identifier}` : "";
|
|
119
|
-
if (_zui.z.is.zuiFunction(schema.schema)) {
|
|
120
|
-
return stripSpaces(`${description}
|
|
121
|
-
declare function ${schema.identifier}${typings};${closingTag}`);
|
|
122
|
-
}
|
|
123
|
-
return stripSpaces(`${description}
|
|
124
|
-
declare const ${schema.identifier}: ${typings};${closingTag}`);
|
|
125
|
-
}
|
|
126
|
-
if (schema instanceof KeyValue) {
|
|
127
|
-
if (_zui.z.is.zuiOptional(schema.value) || _zui.z.is.zuiDefault(schema.value)) {
|
|
128
|
-
let innerType = schema.value._def.innerType;
|
|
129
|
-
if (_zui.z.is.zuiType(innerType) && !innerType.description && schema.value.description) {
|
|
130
|
-
innerType = innerType == null ? void 0 : innerType.describe(schema.value.description);
|
|
131
|
-
}
|
|
132
|
-
const optionalToken = schema.key.endsWith("?") ? "" : "?";
|
|
133
|
-
return sUnwrapZodRecursive(new KeyValue(schema.key + optionalToken, innerType), newOptions);
|
|
134
|
-
}
|
|
135
|
-
const description = _chunkFPLSJF4Scjs.getMultilineComment.call(void 0, schema.value._def.description || schema.value.description);
|
|
136
|
-
const delimiter = (description == null ? void 0 : description.trim().length) > 0 ? "\n" : "";
|
|
137
|
-
const withoutDesc = schema.value.describe("");
|
|
138
|
-
return `${delimiter}${description}${delimiter}${schema.key}: ${await sUnwrapZodRecursive(withoutDesc, newOptions)}${delimiter}`;
|
|
139
|
-
}
|
|
140
|
-
if (schema instanceof FnParameters) {
|
|
141
|
-
if (_zui.z.is.zuiTuple(schema.schema)) {
|
|
142
|
-
let args = "";
|
|
143
|
-
for (let i = 0; i < schema.schema.items.length; i++) {
|
|
144
|
-
const argName = _nullishCoalesce(((_b = (_a = schema.schema.items[i]) == null ? void 0 : _a.ui) == null ? void 0 : _b.title), () => ( `arg${i}`));
|
|
145
|
-
const item = schema.schema.items[i];
|
|
146
|
-
args += `${await sUnwrapZodRecursive(new KeyValue(_chunkFPLSJF4Scjs.toPropertyKey.call(void 0, argName), item), newOptions)}, `;
|
|
147
|
-
}
|
|
148
|
-
return args;
|
|
149
|
-
}
|
|
150
|
-
const isLiteral = _zui.z.is.zuiLiteral(schema.schema.naked());
|
|
151
|
-
const typings = (await sUnwrapZodRecursive(schema.schema, newOptions)).trim();
|
|
152
|
-
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);
|
|
153
|
-
if (startsWithPairs || isLiteral) {
|
|
154
|
-
return `args: ${typings}`;
|
|
155
|
-
} else {
|
|
156
|
-
return typings;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
if (schema instanceof FnReturn) {
|
|
160
|
-
if (_zui.z.is.zuiOptional(schema.schema)) {
|
|
161
|
-
return `${await sUnwrapZodRecursive(schema.schema.unwrap(), newOptions)} | undefined`;
|
|
162
|
-
}
|
|
163
|
-
return sUnwrapZodRecursive(schema.schema, newOptions);
|
|
164
|
-
}
|
|
165
|
-
if (schema === null) {
|
|
166
|
-
return "unknown";
|
|
167
|
-
}
|
|
168
|
-
schema;
|
|
169
|
-
if (_zui.z.is.zuiDefault(schema)) {
|
|
170
|
-
return sUnwrapZodRecursive(schema._def.innerType, options);
|
|
171
|
-
}
|
|
172
|
-
if (_zui.z.is.zuiVoid(schema)) {
|
|
173
|
-
return "void";
|
|
174
|
-
}
|
|
175
|
-
if (_zui.z.is.zuiUnknown(schema)) {
|
|
176
|
-
return "unknown";
|
|
177
|
-
}
|
|
178
|
-
if (_zui.z.is.zuiAny(schema)) {
|
|
179
|
-
return "any";
|
|
180
|
-
}
|
|
181
|
-
if (_zui.z.is.zuiPromise(schema)) {
|
|
182
|
-
return `Promise<${await sUnwrapZodRecursive(schema.unwrap(), newOptions)}>`;
|
|
183
|
-
}
|
|
184
|
-
if (_zui.z.is.zuiFunction(schema)) {
|
|
185
|
-
const description = _chunkFPLSJF4Scjs.getMultilineComment.call(void 0, schema._def.description);
|
|
186
|
-
const input = await sUnwrapZodRecursive(new FnParameters(schema._def.args), newOptions);
|
|
187
|
-
const output = await sUnwrapZodRecursive(new FnReturn(schema._def.returns), newOptions);
|
|
188
|
-
if (options == null ? void 0 : options.declaration) {
|
|
189
|
-
return `${description}
|
|
190
|
-
(${input}): ${output}`;
|
|
191
|
-
}
|
|
192
|
-
return `${description}
|
|
193
|
-
(${input}) => ${output}`;
|
|
194
|
-
}
|
|
195
|
-
if (_zui.z.is.zuiArray(schema)) {
|
|
196
|
-
const item = await sUnwrapZodRecursive(schema._def.type, newOptions);
|
|
197
|
-
if (isPrimitive(item)) {
|
|
198
|
-
return `${item}[]`;
|
|
199
|
-
}
|
|
200
|
-
return `Array<${item}>`;
|
|
201
|
-
}
|
|
202
|
-
if (_zui.z.is.zuiEnum(schema)) {
|
|
203
|
-
const values = schema._def.values.map(_chunkFPLSJF4Scjs.escapeString);
|
|
204
|
-
return values.join(" | ");
|
|
205
|
-
}
|
|
206
|
-
if (_zui.z.is.zuiTuple(schema)) {
|
|
207
|
-
if (schema.items.length === 0) {
|
|
208
|
-
return "[]";
|
|
209
|
-
}
|
|
210
|
-
const items = await Promise.all(schema.items.map((i) => sUnwrapZodRecursive(i, newOptions)));
|
|
211
|
-
return `[${items.join(", ")}]`;
|
|
212
|
-
}
|
|
213
|
-
if (_zui.z.is.zuiNullable(schema)) {
|
|
214
|
-
return `${await sUnwrapZodRecursive(schema.unwrap(), options)} | null`;
|
|
215
|
-
}
|
|
216
|
-
if (_zui.z.is.zuiOptional(schema)) {
|
|
217
|
-
if ((options == null ? void 0 : options.declaration) || _zui.z.is.zuiType(options == null ? void 0 : options.parent) && options.parent.typeName === "ZodRecord") {
|
|
218
|
-
return `${await sUnwrapZodRecursive(schema._def.innerType, newOptions)} | undefined`;
|
|
219
|
-
}
|
|
220
|
-
const optionalToken = options.parent instanceof KeyValue ? "| undefined" : "";
|
|
221
|
-
const val = `${await sUnwrapZodRecursive(schema._def.innerType, newOptions)}${optionalToken}`;
|
|
222
|
-
return val;
|
|
223
|
-
}
|
|
224
|
-
if (_zui.z.is.zuiObject(schema)) {
|
|
225
|
-
const props = await Promise.all(
|
|
226
|
-
Object.entries(schema.shape).map(async ([key, value]) => {
|
|
227
|
-
if (_zui.z.is.zuiType(value)) {
|
|
228
|
-
return sUnwrapZodRecursive(new KeyValue(_chunkFPLSJF4Scjs.toPropertyKey.call(void 0, key), value), newOptions);
|
|
229
|
-
}
|
|
230
|
-
return `${key}: unknown`;
|
|
231
|
-
})
|
|
232
|
-
);
|
|
233
|
-
return `{ ${props.join("; ")} }`;
|
|
234
|
-
}
|
|
235
|
-
if (_zui.z.is.zuiString(schema)) {
|
|
236
|
-
const description = _chunkFPLSJF4Scjs.getMultilineComment.call(void 0, schema._def.description);
|
|
237
|
-
return `${description} string`.trim();
|
|
238
|
-
}
|
|
239
|
-
if (_zui.z.is.zuiUnion(schema)) {
|
|
240
|
-
const description = _chunkFPLSJF4Scjs.getMultilineComment.call(void 0, schema._def.description);
|
|
241
|
-
const options2 = await Promise.all(
|
|
242
|
-
schema.options.map(async (option) => {
|
|
243
|
-
return sUnwrapZodRecursive(option, newOptions);
|
|
244
|
-
})
|
|
245
|
-
);
|
|
246
|
-
return `${description}
|
|
247
|
-
${options2.join(" | ")}`;
|
|
248
|
-
}
|
|
249
|
-
if (_zui.z.is.zuiLiteral(schema)) {
|
|
250
|
-
const description = _chunkFPLSJF4Scjs.getMultilineComment.call(void 0, schema._def.description);
|
|
251
|
-
return `${description}
|
|
252
|
-
${typeof schema.value === "string" ? _chunkFPLSJF4Scjs.escapeString.call(void 0, schema.value) : String(schema.value)}`.trim();
|
|
253
|
-
}
|
|
254
|
-
if (_zui.z.is.zuiNumber(schema)) {
|
|
255
|
-
const description = _chunkFPLSJF4Scjs.getMultilineComment.call(void 0, schema._def.description);
|
|
256
|
-
return `${description} number`.trim();
|
|
257
|
-
}
|
|
258
|
-
if (_zui.z.is.zuiBoolean(schema)) {
|
|
259
|
-
const description = _chunkFPLSJF4Scjs.getMultilineComment.call(void 0, schema._def.description);
|
|
260
|
-
return `${description} boolean`.trim();
|
|
261
|
-
}
|
|
262
|
-
if (_zui.z.is.zuiCatch(schema)) {
|
|
263
|
-
return sUnwrapZodRecursive(schema.removeCatch(), newOptions);
|
|
264
|
-
}
|
|
265
|
-
if (_zui.z.is.zuiLazy(schema)) {
|
|
266
|
-
return sUnwrapZodRecursive(schema._def.getter(), newOptions);
|
|
267
|
-
}
|
|
268
|
-
if (_zui.z.is.zuiRecord(schema)) {
|
|
269
|
-
const description = _chunkFPLSJF4Scjs.getMultilineComment.call(void 0, schema._def.description);
|
|
270
|
-
const keyType = await sUnwrapZodRecursive(schema._def.keyType, newOptions);
|
|
271
|
-
const valueType = await sUnwrapZodRecursive(schema._def.valueType, newOptions);
|
|
272
|
-
return `${description} { [key: (${keyType})]: (${valueType}) }`;
|
|
273
|
-
}
|
|
274
|
-
try {
|
|
275
|
-
let typings = schema == null ? void 0 : schema.toTypescriptType({ treatDefaultAsOptional: true });
|
|
276
|
-
typings ??= "unknown";
|
|
277
|
-
return stripSpaces(typings);
|
|
278
|
-
} catch (error) {
|
|
279
|
-
console.error("Error in sUnwrapZod", { error, schema, parent: options == null ? void 0 : options.parent });
|
|
280
|
-
return "unknown";
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
exports.formatTypings = formatTypings; exports.getTypings = getTypings;
|