@politty/zod 0.0.0
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/LICENSE +21 -0
- package/README.md +561 -0
- package/bin/cli.mjs +3 -0
- package/dist/arg-registry-YaWTVu_x.d.ts +1025 -0
- package/dist/augment.d.ts +15 -0
- package/dist/augment.js +1 -0
- package/dist/cli-main-Dn88vIyn.js +84 -0
- package/dist/cli-run-eibUcgys.js +7 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +16 -0
- package/dist/command-k-4yAz4J.js +42 -0
- package/dist/compile-cache-Ct41pWGL.js +100 -0
- package/dist/compile-cache.d.ts +78 -0
- package/dist/compile-cache.js +3 -0
- package/dist/completion-gtWX3mwP.js +5608 -0
- package/dist/completion.d.ts +242 -0
- package/dist/completion.js +4 -0
- package/dist/docs.d.ts +770 -0
- package/dist/docs.js +3044 -0
- package/dist/field-meta-DMy5BcRr.js +146 -0
- package/dist/index-CvhsecfS.d.ts +455 -0
- package/dist/index.d.ts +799 -0
- package/dist/index.js +17 -0
- package/dist/log-collector-CoUkLVJB.js +114 -0
- package/dist/logger-i_bb-Jhc.js +133 -0
- package/dist/prompt-CEIZ-7H1.js +171 -0
- package/dist/prompt-clack.d.ts +16 -0
- package/dist/prompt-clack.js +32 -0
- package/dist/prompt-inquirer.d.ts +16 -0
- package/dist/prompt-inquirer.js +47 -0
- package/dist/prompt.d.ts +106 -0
- package/dist/prompt.js +4 -0
- package/dist/register-Bk0K83W2.js +439 -0
- package/dist/runner-D72I7wvK.js +2956 -0
- package/dist/runner-FvUwOHyE.js +3 -0
- package/dist/schema-extractor-DMSozq40.js +250 -0
- package/dist/skill.d.ts +608 -0
- package/dist/skill.js +1832 -0
- package/dist/src-KzC0g5CS.js +191 -0
- package/dist/subcommand-router-Cskpofdk.js +134 -0
- package/package.json +103 -0
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import { a as getValidatorAdapter, n as resolveFieldMeta } from "./field-meta-DMy5BcRr.js";
|
|
2
|
+
|
|
3
|
+
//#region ../core/src/adapter/internal-args.ts
|
|
4
|
+
/** Runtime brand distinguishing internal descriptors from library schemas. */
|
|
5
|
+
const INTERNAL_ARGS_BRAND = "__polittyInternalArgs";
|
|
6
|
+
/**
|
|
7
|
+
* Field builders for {@link internalArgs}. Only the shapes internal
|
|
8
|
+
* commands actually need; extend deliberately, not speculatively.
|
|
9
|
+
*/
|
|
10
|
+
const internalField = {
|
|
11
|
+
/** Required string */
|
|
12
|
+
string(meta) {
|
|
13
|
+
return {
|
|
14
|
+
kind: "string",
|
|
15
|
+
optional: false,
|
|
16
|
+
meta
|
|
17
|
+
};
|
|
18
|
+
},
|
|
19
|
+
/** Optional string (undefined when omitted) */
|
|
20
|
+
optionalString(meta) {
|
|
21
|
+
return {
|
|
22
|
+
kind: "string",
|
|
23
|
+
optional: true,
|
|
24
|
+
meta
|
|
25
|
+
};
|
|
26
|
+
},
|
|
27
|
+
/** Boolean flag defaulting to false */
|
|
28
|
+
boolean(meta) {
|
|
29
|
+
return {
|
|
30
|
+
kind: "boolean",
|
|
31
|
+
optional: false,
|
|
32
|
+
defaultValue: false,
|
|
33
|
+
meta
|
|
34
|
+
};
|
|
35
|
+
},
|
|
36
|
+
/** Required enum */
|
|
37
|
+
enum(values, meta) {
|
|
38
|
+
return {
|
|
39
|
+
kind: "enum",
|
|
40
|
+
enumValues: values,
|
|
41
|
+
optional: false,
|
|
42
|
+
meta
|
|
43
|
+
};
|
|
44
|
+
},
|
|
45
|
+
/** Optional enum (undefined when omitted) */
|
|
46
|
+
optionalEnum(values, meta) {
|
|
47
|
+
return {
|
|
48
|
+
kind: "enum",
|
|
49
|
+
enumValues: values,
|
|
50
|
+
optional: true,
|
|
51
|
+
meta
|
|
52
|
+
};
|
|
53
|
+
},
|
|
54
|
+
/** String array defaulting to [] */
|
|
55
|
+
stringArray(meta) {
|
|
56
|
+
return {
|
|
57
|
+
kind: "string-array",
|
|
58
|
+
optional: false,
|
|
59
|
+
defaultValue: [],
|
|
60
|
+
meta
|
|
61
|
+
};
|
|
62
|
+
},
|
|
63
|
+
/** Optional string array (undefined when omitted) */
|
|
64
|
+
optionalStringArray(meta) {
|
|
65
|
+
return {
|
|
66
|
+
kind: "string-array",
|
|
67
|
+
optional: true,
|
|
68
|
+
meta
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Build an internal args schema from field descriptors.
|
|
74
|
+
*/
|
|
75
|
+
function internalArgs(fields, options = {}) {
|
|
76
|
+
return {
|
|
77
|
+
[INTERNAL_ARGS_BRAND]: true,
|
|
78
|
+
fields,
|
|
79
|
+
unknownKeys: options.unknownKeys ?? "strip"
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Runtime check for the internal descriptor brand. The extract/validate
|
|
84
|
+
* facades call this before falling back to the schema-library adapter.
|
|
85
|
+
*/
|
|
86
|
+
function isInternalArgsSchema(schema) {
|
|
87
|
+
return typeof schema === "object" && schema !== null && schema[INTERNAL_ARGS_BRAND] === true;
|
|
88
|
+
}
|
|
89
|
+
const FIELD_TYPE = {
|
|
90
|
+
string: "string",
|
|
91
|
+
boolean: "boolean",
|
|
92
|
+
enum: "string",
|
|
93
|
+
"string-array": "array"
|
|
94
|
+
};
|
|
95
|
+
const extractCache = /* @__PURE__ */ new WeakMap();
|
|
96
|
+
/**
|
|
97
|
+
* Extract neutral field metadata from an internal args schema.
|
|
98
|
+
*/
|
|
99
|
+
function extractInternalFields(schema) {
|
|
100
|
+
const cached = extractCache.get(schema);
|
|
101
|
+
if (cached) return cached;
|
|
102
|
+
const result = {
|
|
103
|
+
fields: Object.entries(schema.fields).map(([name, spec]) => resolveFieldMeta(name, {
|
|
104
|
+
argMeta: spec.meta,
|
|
105
|
+
description: void 0,
|
|
106
|
+
required: !spec.optional && spec.defaultValue === void 0,
|
|
107
|
+
defaultValue: spec.defaultValue,
|
|
108
|
+
type: FIELD_TYPE[spec.kind],
|
|
109
|
+
enumValues: spec.enumValues ? [...spec.enumValues] : void 0,
|
|
110
|
+
schema: spec
|
|
111
|
+
})),
|
|
112
|
+
schema,
|
|
113
|
+
schemaType: "object",
|
|
114
|
+
unknownKeysMode: schema.unknownKeys
|
|
115
|
+
};
|
|
116
|
+
extractCache.set(schema, result);
|
|
117
|
+
return result;
|
|
118
|
+
}
|
|
119
|
+
function expectedLabel(spec) {
|
|
120
|
+
switch (spec.kind) {
|
|
121
|
+
case "enum": return `one of ${(spec.enumValues ?? []).map((v) => JSON.stringify(v)).join(" | ")}`;
|
|
122
|
+
case "string-array": return "array";
|
|
123
|
+
default: return spec.kind;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
function receivedLabel(value) {
|
|
127
|
+
if (value === null) return "null";
|
|
128
|
+
if (Array.isArray(value)) return "array";
|
|
129
|
+
return typeof value;
|
|
130
|
+
}
|
|
131
|
+
function typeError(name, spec, received) {
|
|
132
|
+
return {
|
|
133
|
+
path: [name],
|
|
134
|
+
message: `Invalid input: expected ${expectedLabel(spec)}, received ${receivedLabel(received)}`,
|
|
135
|
+
code: "invalid_type",
|
|
136
|
+
received,
|
|
137
|
+
expected: expectedLabel(spec)
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
function checkValue(name, spec, value) {
|
|
141
|
+
switch (spec.kind) {
|
|
142
|
+
case "string": return typeof value === "string" ? null : typeError(name, spec, value);
|
|
143
|
+
case "boolean": return typeof value === "boolean" ? null : typeError(name, spec, value);
|
|
144
|
+
case "enum":
|
|
145
|
+
if (typeof value !== "string" || !(spec.enumValues ?? []).includes(value)) return {
|
|
146
|
+
path: [name],
|
|
147
|
+
message: `Invalid option: expected ${expectedLabel(spec)}`,
|
|
148
|
+
code: "invalid_value",
|
|
149
|
+
received: value,
|
|
150
|
+
expected: expectedLabel(spec)
|
|
151
|
+
};
|
|
152
|
+
return null;
|
|
153
|
+
case "string-array":
|
|
154
|
+
if (!Array.isArray(value) || value.some((v) => typeof v !== "string")) return typeError(name, spec, value);
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Validate raw parsed args against an internal args schema. Mirrors the
|
|
160
|
+
* schema-library semantics the parser relies on: defaults fill missing
|
|
161
|
+
* values, optional fields stay absent, and unknown keys follow the
|
|
162
|
+
* descriptor's `unknownKeys` mode (strip by default, like z.object()).
|
|
163
|
+
*/
|
|
164
|
+
function validateInternalArgs(rawArgs, schema) {
|
|
165
|
+
const errors = [];
|
|
166
|
+
const data = {};
|
|
167
|
+
for (const [name, spec] of Object.entries(schema.fields)) {
|
|
168
|
+
const value = rawArgs[name];
|
|
169
|
+
if (value === void 0) {
|
|
170
|
+
if (spec.defaultValue !== void 0) data[name] = Array.isArray(spec.defaultValue) ? [...spec.defaultValue] : spec.defaultValue;
|
|
171
|
+
else if (!spec.optional) errors.push(typeError(name, spec, void 0));
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
const error = checkValue(name, spec, value);
|
|
175
|
+
if (error) {
|
|
176
|
+
errors.push(error);
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
data[name] = value;
|
|
180
|
+
}
|
|
181
|
+
const knownNames = new Set(Object.keys(schema.fields));
|
|
182
|
+
const unknownKeys = Object.keys(rawArgs).filter((key) => !knownNames.has(key));
|
|
183
|
+
if (unknownKeys.length > 0) {
|
|
184
|
+
if (schema.unknownKeys === "strict") errors.push({
|
|
185
|
+
path: [],
|
|
186
|
+
message: `Unrecognized key${unknownKeys.length > 1 ? "s" : ""}: ${unknownKeys.map((k) => JSON.stringify(k)).join(", ")}`,
|
|
187
|
+
code: "unrecognized_keys"
|
|
188
|
+
});
|
|
189
|
+
else if (schema.unknownKeys === "passthrough") for (const key of unknownKeys) Object.defineProperty(data, key, {
|
|
190
|
+
value: rawArgs[key],
|
|
191
|
+
enumerable: true,
|
|
192
|
+
writable: true,
|
|
193
|
+
configurable: true
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
if (errors.length > 0) return {
|
|
197
|
+
success: false,
|
|
198
|
+
errors
|
|
199
|
+
};
|
|
200
|
+
return {
|
|
201
|
+
success: true,
|
|
202
|
+
data
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
//#endregion
|
|
207
|
+
//#region ../core/src/core/schema-extractor.ts
|
|
208
|
+
/**
|
|
209
|
+
* Schema extraction facade.
|
|
210
|
+
*
|
|
211
|
+
* The neutral field-metadata shapes and naming helpers live in
|
|
212
|
+
* `adapter/field-meta.ts`; the schema-library-specific introspection lives
|
|
213
|
+
* in the registered validator adapter (e.g. `@politty/zod`). This module
|
|
214
|
+
* keeps the historical import surface (`extractFields`, `toCamelCase`, ...)
|
|
215
|
+
* stable for the rest of the codebase and for the package's public
|
|
216
|
+
* exports, and routes each schema to the implementation that understands
|
|
217
|
+
* it.
|
|
218
|
+
*/
|
|
219
|
+
/**
|
|
220
|
+
* Detect the unknown-keys handling mode of an args schema. Works for any
|
|
221
|
+
* schema politty itself attaches to a command (including internal
|
|
222
|
+
* descriptor-based commands), not just user-provided library schemas.
|
|
223
|
+
*/
|
|
224
|
+
function getUnknownKeysMode(schema) {
|
|
225
|
+
if (isInternalArgsSchema(schema)) return schema.unknownKeys;
|
|
226
|
+
return getValidatorAdapter().getUnknownKeysMode(schema);
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Extract all fields from a schema
|
|
230
|
+
*
|
|
231
|
+
* @param schema - The args schema (ZodObject, ZodDiscriminatedUnion, etc.)
|
|
232
|
+
* @returns Extracted field information
|
|
233
|
+
*/
|
|
234
|
+
function extractFields(schema) {
|
|
235
|
+
if (isInternalArgsSchema(schema)) return extractInternalFields(schema);
|
|
236
|
+
return getValidatorAdapter().extractFields(schema);
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Get extracted fields from a command
|
|
240
|
+
*
|
|
241
|
+
* @param command - The command to extract fields from
|
|
242
|
+
* @returns Extracted field information, or null if command has no args schema
|
|
243
|
+
*/
|
|
244
|
+
function getExtractedFields(command) {
|
|
245
|
+
if (!command.args) return null;
|
|
246
|
+
return extractFields(command.args);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
//#endregion
|
|
250
|
+
export { internalField as a, internalArgs as i, getExtractedFields as n, isInternalArgsSchema as o, getUnknownKeysMode as r, validateInternalArgs as s, extractFields as t };
|