@harness-kernel/core 0.1.0-beta.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/NOTICE +3 -0
- package/README.md +12 -0
- package/dist/agent/context.d.ts +5 -0
- package/dist/agent/context.js +11 -0
- package/dist/agent/context.js.map +1 -0
- package/dist/agent/event.d.ts +3 -0
- package/dist/agent/event.js +50 -0
- package/dist/agent/event.js.map +1 -0
- package/dist/agent/hook.d.ts +6 -0
- package/dist/agent/hook.js +7 -0
- package/dist/agent/hook.js.map +1 -0
- package/dist/agent/mode.d.ts +5 -0
- package/dist/agent/mode.js +7 -0
- package/dist/agent/mode.js.map +1 -0
- package/dist/agent/role.d.ts +1 -0
- package/dist/agent/role.js +27 -0
- package/dist/agent/role.js.map +1 -0
- package/dist/agent/session.d.ts +6 -0
- package/dist/agent/session.js +13 -0
- package/dist/agent/session.js.map +1 -0
- package/dist/agent/tool.d.ts +5 -0
- package/dist/agent/tool.js +7 -0
- package/dist/agent/tool.js.map +1 -0
- package/dist/agent.d.ts +12 -0
- package/dist/agent.js +7 -0
- package/dist/agent.js.map +1 -0
- package/dist/approval-DfvjpbFs.d.ts +247 -0
- package/dist/chunk-4A2P4QU5.js +179 -0
- package/dist/chunk-4A2P4QU5.js.map +1 -0
- package/dist/chunk-4SYLFKIX.js +207 -0
- package/dist/chunk-4SYLFKIX.js.map +1 -0
- package/dist/chunk-4WWSQAWA.js +3778 -0
- package/dist/chunk-4WWSQAWA.js.map +1 -0
- package/dist/chunk-AD3BCYWU.js +37 -0
- package/dist/chunk-AD3BCYWU.js.map +1 -0
- package/dist/chunk-AZVA22HW.js +135 -0
- package/dist/chunk-AZVA22HW.js.map +1 -0
- package/dist/chunk-OBKS4AJR.js +529 -0
- package/dist/chunk-OBKS4AJR.js.map +1 -0
- package/dist/chunk-Q44U2CMM.js +239 -0
- package/dist/chunk-Q44U2CMM.js.map +1 -0
- package/dist/chunk-Q73WH5D7.js +54 -0
- package/dist/chunk-Q73WH5D7.js.map +1 -0
- package/dist/chunk-RRWJUHJG.js +9 -0
- package/dist/chunk-RRWJUHJG.js.map +1 -0
- package/dist/context-75mlon5x.d.ts +394 -0
- package/dist/event-CKV4EeZ3.d.ts +230 -0
- package/dist/events-D4xcDi53.d.ts +69 -0
- package/dist/hook-DMb9fw9Z.d.ts +20 -0
- package/dist/index.d.ts +164 -0
- package/dist/index.js +174 -0
- package/dist/index.js.map +1 -0
- package/dist/model-provider-BrZ2RRmS.d.ts +130 -0
- package/dist/role-BN6KhQxx.d.ts +68 -0
- package/dist/runner/approval.d.ts +9 -0
- package/dist/runner/approval.js +1 -0
- package/dist/runner/approval.js.map +1 -0
- package/dist/runner/event.d.ts +3 -0
- package/dist/runner/event.js +50 -0
- package/dist/runner/event.js.map +1 -0
- package/dist/runner/logging.d.ts +31 -0
- package/dist/runner/logging.js +15 -0
- package/dist/runner/logging.js.map +1 -0
- package/dist/runner/model-provider.d.ts +8 -0
- package/dist/runner/model-provider.js +11 -0
- package/dist/runner/model-provider.js.map +1 -0
- package/dist/runner/sandbox.d.ts +47 -0
- package/dist/runner/sandbox.js +13 -0
- package/dist/runner/sandbox.js.map +1 -0
- package/dist/runner/storage.d.ts +6 -0
- package/dist/runner/storage.js +17 -0
- package/dist/runner/storage.js.map +1 -0
- package/dist/runner-Dxo7ALtp.d.ts +87 -0
- package/dist/runner.d.ts +10 -0
- package/dist/runner.js +18 -0
- package/dist/runner.js.map +1 -0
- package/dist/schema.d.ts +146 -0
- package/dist/schema.js +39 -0
- package/dist/schema.js.map +1 -0
- package/dist/storage-BmOEwW-p.d.ts +118 -0
- package/dist/tool-errors-CygY1Nba.d.ts +27 -0
- package/dist/types-BPmsw-mF.d.ts +80 -0
- package/package.json +114 -0
|
@@ -0,0 +1,529 @@
|
|
|
1
|
+
// src/schema/index.ts
|
|
2
|
+
var SchemaError = class extends Error {
|
|
3
|
+
issues;
|
|
4
|
+
constructor(issues) {
|
|
5
|
+
const normalized = issues.length ? issues.map(normalizeIssue) : [issue(void 0, "custom", "Schema validation failed.")];
|
|
6
|
+
super(normalized[0]?.message ?? "Schema validation failed.");
|
|
7
|
+
this.name = "SchemaError";
|
|
8
|
+
this.issues = normalized;
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
function formatSchemaPath(path) {
|
|
12
|
+
if (Array.isArray(path)) return path.length ? path.map((part) => String(part)).join(".") : "(root)";
|
|
13
|
+
if (typeof path === "number") return String(path);
|
|
14
|
+
if (typeof path === "string" && path.trim()) return path;
|
|
15
|
+
return "(root)";
|
|
16
|
+
}
|
|
17
|
+
function joinSchemaPath(parent, child) {
|
|
18
|
+
const left = formatSchemaPath(parent);
|
|
19
|
+
const right = formatSchemaPath(child);
|
|
20
|
+
if (left === "(root)") return right;
|
|
21
|
+
if (right === "(root)") return left;
|
|
22
|
+
return `${left}.${right}`;
|
|
23
|
+
}
|
|
24
|
+
function normalizeIssue(value) {
|
|
25
|
+
if (typeof value !== "object" || value === null) {
|
|
26
|
+
return issue(void 0, "custom", String(value || "Schema validation failed."));
|
|
27
|
+
}
|
|
28
|
+
const record = value;
|
|
29
|
+
return {
|
|
30
|
+
path: formatSchemaPath(record.path),
|
|
31
|
+
code: typeof record.code === "string" ? record.code : "custom",
|
|
32
|
+
message: typeof record.message === "string" ? record.message : "Invalid value.",
|
|
33
|
+
expected: typeof record.expected === "string" ? record.expected : void 0,
|
|
34
|
+
received: typeof record.received === "string" ? record.received : void 0
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function schemaIssuesFromError(error) {
|
|
38
|
+
if (error instanceof SchemaError) return error.issues;
|
|
39
|
+
if (error && typeof error === "object" && "issues" in error && Array.isArray(error.issues)) {
|
|
40
|
+
return error.issues.map(normalizeIssue);
|
|
41
|
+
}
|
|
42
|
+
return [issue(void 0, "custom", error instanceof Error ? error.message : String(error ?? "Schema validation failed."))];
|
|
43
|
+
}
|
|
44
|
+
var Schema = class {
|
|
45
|
+
isHarnessSchema = true;
|
|
46
|
+
schemaDescription;
|
|
47
|
+
parse(input) {
|
|
48
|
+
const result = this.safeParse(input);
|
|
49
|
+
if (!result.success) throw result.error;
|
|
50
|
+
return result.data;
|
|
51
|
+
}
|
|
52
|
+
optional() {
|
|
53
|
+
return new OptionalSchema(this);
|
|
54
|
+
}
|
|
55
|
+
default(value) {
|
|
56
|
+
return new DefaultSchema(this, value);
|
|
57
|
+
}
|
|
58
|
+
describe(description) {
|
|
59
|
+
this.schemaDescription = description;
|
|
60
|
+
return this;
|
|
61
|
+
}
|
|
62
|
+
withDescription(json) {
|
|
63
|
+
return this.schemaDescription ? { ...json, description: this.schemaDescription } : json;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
function received(value) {
|
|
67
|
+
if (Array.isArray(value)) return "array";
|
|
68
|
+
if (value === null) return "null";
|
|
69
|
+
return typeof value;
|
|
70
|
+
}
|
|
71
|
+
function issue(path, code, message, expected, value) {
|
|
72
|
+
return {
|
|
73
|
+
path: formatSchemaPath(path),
|
|
74
|
+
code,
|
|
75
|
+
message,
|
|
76
|
+
expected,
|
|
77
|
+
received: value === void 0 ? void 0 : received(value)
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
function prependIssuePath(path, entry) {
|
|
81
|
+
return { ...entry, path: joinSchemaPath(path, entry.path) };
|
|
82
|
+
}
|
|
83
|
+
function ok(data) {
|
|
84
|
+
return { success: true, data };
|
|
85
|
+
}
|
|
86
|
+
function fail(issues) {
|
|
87
|
+
return { success: false, error: new SchemaError(issues) };
|
|
88
|
+
}
|
|
89
|
+
var StringSchema = class extends Schema {
|
|
90
|
+
minLength;
|
|
91
|
+
maxLength;
|
|
92
|
+
min(length) {
|
|
93
|
+
this.minLength = length;
|
|
94
|
+
return this;
|
|
95
|
+
}
|
|
96
|
+
max(length) {
|
|
97
|
+
this.maxLength = length;
|
|
98
|
+
return this;
|
|
99
|
+
}
|
|
100
|
+
safeParse(input) {
|
|
101
|
+
if (typeof input !== "string") return fail([issue(void 0, "invalid_type", "Expected string.", "string", input)]);
|
|
102
|
+
if (this.minLength !== void 0 && input.length < this.minLength) {
|
|
103
|
+
return fail([issue(void 0, "too_small", `Expected string to contain at least ${this.minLength} character(s).`, `string(min:${this.minLength})`, input)]);
|
|
104
|
+
}
|
|
105
|
+
if (this.maxLength !== void 0 && input.length > this.maxLength) {
|
|
106
|
+
return fail([issue(void 0, "too_big", `Expected string to contain at most ${this.maxLength} character(s).`, `string(max:${this.maxLength})`, input)]);
|
|
107
|
+
}
|
|
108
|
+
return ok(input);
|
|
109
|
+
}
|
|
110
|
+
toJsonSchema() {
|
|
111
|
+
return this.withDescription({
|
|
112
|
+
type: "string",
|
|
113
|
+
...this.minLength !== void 0 ? { minLength: this.minLength } : {},
|
|
114
|
+
...this.maxLength !== void 0 ? { maxLength: this.maxLength } : {}
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
var NumberSchema = class extends Schema {
|
|
119
|
+
integerOnly = false;
|
|
120
|
+
minValue;
|
|
121
|
+
maxValue;
|
|
122
|
+
exclusiveMin;
|
|
123
|
+
int() {
|
|
124
|
+
this.integerOnly = true;
|
|
125
|
+
return this;
|
|
126
|
+
}
|
|
127
|
+
min(value) {
|
|
128
|
+
this.minValue = value;
|
|
129
|
+
return this;
|
|
130
|
+
}
|
|
131
|
+
max(value) {
|
|
132
|
+
this.maxValue = value;
|
|
133
|
+
return this;
|
|
134
|
+
}
|
|
135
|
+
positive() {
|
|
136
|
+
this.exclusiveMin = 0;
|
|
137
|
+
return this;
|
|
138
|
+
}
|
|
139
|
+
safeParse(input) {
|
|
140
|
+
if (typeof input !== "number" || Number.isNaN(input)) {
|
|
141
|
+
return fail([issue(void 0, "invalid_type", "Expected number.", "number", input)]);
|
|
142
|
+
}
|
|
143
|
+
if (this.integerOnly && !Number.isInteger(input)) {
|
|
144
|
+
return fail([issue(void 0, "invalid_type", "Expected integer.", "integer", input)]);
|
|
145
|
+
}
|
|
146
|
+
if (this.exclusiveMin !== void 0 && input <= this.exclusiveMin) {
|
|
147
|
+
return fail([issue(void 0, "too_small", `Expected number to be greater than ${this.exclusiveMin}.`, `number(>${this.exclusiveMin})`, input)]);
|
|
148
|
+
}
|
|
149
|
+
if (this.minValue !== void 0 && input < this.minValue) {
|
|
150
|
+
return fail([issue(void 0, "too_small", `Expected number to be greater than or equal to ${this.minValue}.`, `number(min:${this.minValue})`, input)]);
|
|
151
|
+
}
|
|
152
|
+
if (this.maxValue !== void 0 && input > this.maxValue) {
|
|
153
|
+
return fail([issue(void 0, "too_big", `Expected number to be less than or equal to ${this.maxValue}.`, `number(max:${this.maxValue})`, input)]);
|
|
154
|
+
}
|
|
155
|
+
return ok(input);
|
|
156
|
+
}
|
|
157
|
+
toJsonSchema() {
|
|
158
|
+
return this.withDescription({
|
|
159
|
+
type: this.integerOnly ? "integer" : "number",
|
|
160
|
+
...this.minValue !== void 0 ? { minimum: this.minValue } : {},
|
|
161
|
+
...this.maxValue !== void 0 ? { maximum: this.maxValue } : {},
|
|
162
|
+
...this.exclusiveMin !== void 0 ? { exclusiveMinimum: this.exclusiveMin } : {}
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
var BooleanSchema = class extends Schema {
|
|
167
|
+
safeParse(input) {
|
|
168
|
+
return typeof input === "boolean" ? ok(input) : fail([issue(void 0, "invalid_type", "Expected boolean.", "boolean", input)]);
|
|
169
|
+
}
|
|
170
|
+
toJsonSchema() {
|
|
171
|
+
return this.withDescription({ type: "boolean" });
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
var ArraySchema = class extends Schema {
|
|
175
|
+
constructor(item) {
|
|
176
|
+
super();
|
|
177
|
+
this.item = item;
|
|
178
|
+
}
|
|
179
|
+
item;
|
|
180
|
+
safeParse(input) {
|
|
181
|
+
if (!Array.isArray(input)) return fail([issue(void 0, "invalid_type", "Expected array.", "array", input)]);
|
|
182
|
+
const issues = [];
|
|
183
|
+
const data = [];
|
|
184
|
+
input.forEach((value, index) => {
|
|
185
|
+
const result = this.item.safeParse(value);
|
|
186
|
+
if (result.success) data.push(result.data);
|
|
187
|
+
else issues.push(...result.error.issues.map((entry) => prependIssuePath(index, entry)));
|
|
188
|
+
});
|
|
189
|
+
return issues.length ? fail(issues) : ok(data);
|
|
190
|
+
}
|
|
191
|
+
toJsonSchema() {
|
|
192
|
+
return this.withDescription({ type: "array", items: this.item.toJsonSchema() });
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
var ObjectSchema = class extends Schema {
|
|
196
|
+
constructor(shape) {
|
|
197
|
+
super();
|
|
198
|
+
this.shape = shape;
|
|
199
|
+
}
|
|
200
|
+
shape;
|
|
201
|
+
safeParse(input) {
|
|
202
|
+
if (typeof input !== "object" || input === null || Array.isArray(input)) {
|
|
203
|
+
return fail([issue(void 0, "invalid_type", "Expected object.", "object", input)]);
|
|
204
|
+
}
|
|
205
|
+
const source = input;
|
|
206
|
+
const output = {};
|
|
207
|
+
const issues = [];
|
|
208
|
+
for (const [key, schema] of Object.entries(this.shape)) {
|
|
209
|
+
const result = schema.safeParse(source[key]);
|
|
210
|
+
if (result.success) {
|
|
211
|
+
if (result.data !== void 0 || Object.prototype.hasOwnProperty.call(source, key)) output[key] = result.data;
|
|
212
|
+
} else {
|
|
213
|
+
issues.push(...result.error.issues.map((entry) => prependIssuePath(key, entry)));
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
return issues.length ? fail(issues) : ok(output);
|
|
217
|
+
}
|
|
218
|
+
toJsonSchema() {
|
|
219
|
+
const properties = {};
|
|
220
|
+
const required = [];
|
|
221
|
+
for (const [key, schema] of Object.entries(this.shape)) {
|
|
222
|
+
properties[key] = schema.toJsonSchema();
|
|
223
|
+
if (!(schema instanceof OptionalSchema) && !(schema instanceof DefaultSchema)) required.push(key);
|
|
224
|
+
}
|
|
225
|
+
return this.withDescription({
|
|
226
|
+
type: "object",
|
|
227
|
+
properties,
|
|
228
|
+
additionalProperties: false,
|
|
229
|
+
...required.length ? { required } : {}
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
var RecordSchema = class extends Schema {
|
|
234
|
+
constructor(valueSchema) {
|
|
235
|
+
super();
|
|
236
|
+
this.valueSchema = valueSchema;
|
|
237
|
+
}
|
|
238
|
+
valueSchema;
|
|
239
|
+
safeParse(input) {
|
|
240
|
+
if (typeof input !== "object" || input === null || Array.isArray(input)) {
|
|
241
|
+
return fail([issue(void 0, "invalid_type", "Expected object.", "object", input)]);
|
|
242
|
+
}
|
|
243
|
+
const output = {};
|
|
244
|
+
const issues = [];
|
|
245
|
+
for (const [key, value] of Object.entries(input)) {
|
|
246
|
+
const result = this.valueSchema.safeParse(value);
|
|
247
|
+
if (result.success) output[key] = result.data;
|
|
248
|
+
else issues.push(...result.error.issues.map((entry) => prependIssuePath(key, entry)));
|
|
249
|
+
}
|
|
250
|
+
return issues.length ? fail(issues) : ok(output);
|
|
251
|
+
}
|
|
252
|
+
toJsonSchema() {
|
|
253
|
+
return this.withDescription({ type: "object", additionalProperties: this.valueSchema.toJsonSchema() });
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
var EnumSchema = class extends Schema {
|
|
257
|
+
constructor(values) {
|
|
258
|
+
super();
|
|
259
|
+
this.values = values;
|
|
260
|
+
}
|
|
261
|
+
values;
|
|
262
|
+
safeParse(input) {
|
|
263
|
+
return typeof input === "string" && this.values.includes(input) ? ok(input) : fail([issue(void 0, "invalid_enum", `Expected one of: ${this.values.join(", ")}.`, this.values.join(" | "), input)]);
|
|
264
|
+
}
|
|
265
|
+
toJsonSchema() {
|
|
266
|
+
return this.withDescription({ type: "string", enum: [...this.values] });
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
var LiteralSchema = class extends Schema {
|
|
270
|
+
constructor(value) {
|
|
271
|
+
super();
|
|
272
|
+
this.value = value;
|
|
273
|
+
}
|
|
274
|
+
value;
|
|
275
|
+
safeParse(input) {
|
|
276
|
+
return Object.is(input, this.value) ? ok(this.value) : fail([issue(void 0, "invalid_literal", `Expected literal ${JSON.stringify(this.value)}.`, JSON.stringify(this.value), input)]);
|
|
277
|
+
}
|
|
278
|
+
toJsonSchema() {
|
|
279
|
+
const type = this.value === null ? "null" : typeof this.value;
|
|
280
|
+
return this.withDescription({
|
|
281
|
+
const: this.value,
|
|
282
|
+
...type === "string" || type === "number" || type === "boolean" || type === "null" ? { type } : {}
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
var OptionalSchema = class extends Schema {
|
|
287
|
+
constructor(inner) {
|
|
288
|
+
super();
|
|
289
|
+
this.inner = inner;
|
|
290
|
+
}
|
|
291
|
+
inner;
|
|
292
|
+
safeParse(input) {
|
|
293
|
+
if (input === void 0) return ok(void 0);
|
|
294
|
+
return this.inner.safeParse(input);
|
|
295
|
+
}
|
|
296
|
+
toJsonSchema() {
|
|
297
|
+
return this.withDescription(this.inner.toJsonSchema());
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
var DefaultSchema = class extends Schema {
|
|
301
|
+
constructor(inner, value) {
|
|
302
|
+
super();
|
|
303
|
+
this.inner = inner;
|
|
304
|
+
this.value = value;
|
|
305
|
+
}
|
|
306
|
+
inner;
|
|
307
|
+
value;
|
|
308
|
+
safeParse(input) {
|
|
309
|
+
if (input === void 0) return ok(typeof this.value === "function" ? this.value() : this.value);
|
|
310
|
+
return this.inner.safeParse(input);
|
|
311
|
+
}
|
|
312
|
+
toJsonSchema() {
|
|
313
|
+
const json = this.inner.toJsonSchema();
|
|
314
|
+
return this.withDescription({
|
|
315
|
+
...json,
|
|
316
|
+
...typeof this.value === "function" ? {} : { default: this.value }
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
};
|
|
320
|
+
var UnknownSchema = class extends Schema {
|
|
321
|
+
safeParse(input) {
|
|
322
|
+
return ok(input);
|
|
323
|
+
}
|
|
324
|
+
toJsonSchema() {
|
|
325
|
+
return this.withDescription({});
|
|
326
|
+
}
|
|
327
|
+
};
|
|
328
|
+
var s = {
|
|
329
|
+
string: () => new StringSchema(),
|
|
330
|
+
number: () => new NumberSchema(),
|
|
331
|
+
boolean: () => new BooleanSchema(),
|
|
332
|
+
array: (item) => new ArraySchema(item),
|
|
333
|
+
object: (shape) => new ObjectSchema(shape),
|
|
334
|
+
record: (value) => new RecordSchema(value),
|
|
335
|
+
enum: (values) => new EnumSchema(values),
|
|
336
|
+
literal: (value) => new LiteralSchema(value),
|
|
337
|
+
unknown: () => new UnknownSchema()
|
|
338
|
+
};
|
|
339
|
+
function isHarnessSchema(value) {
|
|
340
|
+
return value instanceof Schema || typeof value === "object" && value !== null && value.isHarnessSchema === true;
|
|
341
|
+
}
|
|
342
|
+
function looksLikeJsonSchema(value) {
|
|
343
|
+
return typeof value === "object" && value !== null && ("type" in value || "properties" in value || "enum" in value || "items" in value || "const" in value || "additionalProperties" in value);
|
|
344
|
+
}
|
|
345
|
+
function looksLikeZodSchema(value) {
|
|
346
|
+
if (typeof value !== "object" || value === null) return false;
|
|
347
|
+
if (!("safeParse" in value) || typeof value.safeParse !== "function") return false;
|
|
348
|
+
const constructorName = value.constructor?.name;
|
|
349
|
+
return "_def" in value || "_zod" in value || Boolean(constructorName?.startsWith("Zod"));
|
|
350
|
+
}
|
|
351
|
+
function looksLikeStandardSchema(value) {
|
|
352
|
+
return typeof value === "object" && value !== null && "~standard" in value && typeof value["~standard"]?.validate === "function";
|
|
353
|
+
}
|
|
354
|
+
function getExternalJsonSchema(schema) {
|
|
355
|
+
if (typeof schema !== "object" || schema === null) return void 0;
|
|
356
|
+
if (typeof schema.toJsonSchema === "function") {
|
|
357
|
+
return () => schema.toJsonSchema();
|
|
358
|
+
}
|
|
359
|
+
if (typeof schema.toJSONSchema === "function") {
|
|
360
|
+
return () => schema.toJSONSchema();
|
|
361
|
+
}
|
|
362
|
+
const jsonSchema = schema.jsonSchema;
|
|
363
|
+
if (looksLikeJsonSchema(jsonSchema)) return () => jsonSchema;
|
|
364
|
+
return void 0;
|
|
365
|
+
}
|
|
366
|
+
function parseJsonSchema(schema, input, path = void 0) {
|
|
367
|
+
if (Array.isArray(schema.enum) && !schema.enum.includes(input)) {
|
|
368
|
+
throw new SchemaError([issue(path, "invalid_enum", `Expected one of: ${schema.enum.join(", ")}.`, schema.enum.join(" | "), input)]);
|
|
369
|
+
}
|
|
370
|
+
if ("const" in schema && !Object.is(schema.const, input)) {
|
|
371
|
+
throw new SchemaError([issue(path, "invalid_literal", `Expected literal ${JSON.stringify(schema.const)}.`, JSON.stringify(schema.const), input)]);
|
|
372
|
+
}
|
|
373
|
+
const type = schema.type;
|
|
374
|
+
if (type === "object" || schema.properties || schema.additionalProperties) {
|
|
375
|
+
if (typeof input !== "object" || input === null || Array.isArray(input)) {
|
|
376
|
+
throw new SchemaError([issue(path, "invalid_type", "Expected object.", "object", input)]);
|
|
377
|
+
}
|
|
378
|
+
const required = Array.isArray(schema.required) ? schema.required.map(String) : [];
|
|
379
|
+
const properties = typeof schema.properties === "object" && schema.properties !== null ? schema.properties : {};
|
|
380
|
+
const output = {};
|
|
381
|
+
const issues = [];
|
|
382
|
+
for (const key of required) {
|
|
383
|
+
if (!Object.prototype.hasOwnProperty.call(input, key)) {
|
|
384
|
+
issues.push(issue(joinSchemaPath(path, key), "invalid_type", "Required.", "defined", void 0));
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
for (const [key, child] of Object.entries(properties)) {
|
|
388
|
+
if (Object.prototype.hasOwnProperty.call(input, key)) {
|
|
389
|
+
try {
|
|
390
|
+
output[key] = parseJsonSchema(child, input[key], joinSchemaPath(path, key));
|
|
391
|
+
} catch (error) {
|
|
392
|
+
issues.push(...schemaIssuesFromError(error));
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
if (issues.length) throw new SchemaError(issues);
|
|
397
|
+
return { ...input, ...output };
|
|
398
|
+
}
|
|
399
|
+
if (type === "string" && typeof input !== "string") throw new SchemaError([issue(path, "invalid_type", "Expected string.", "string", input)]);
|
|
400
|
+
if ((type === "number" || type === "integer") && typeof input !== "number") throw new SchemaError([issue(path, "invalid_type", "Expected number.", String(type), input)]);
|
|
401
|
+
if (type === "integer" && !Number.isInteger(input)) throw new SchemaError([issue(path, "invalid_type", "Expected integer.", "integer", input)]);
|
|
402
|
+
if (type === "boolean" && typeof input !== "boolean") throw new SchemaError([issue(path, "invalid_type", "Expected boolean.", "boolean", input)]);
|
|
403
|
+
if (type === "array") {
|
|
404
|
+
if (!Array.isArray(input)) throw new SchemaError([issue(path, "invalid_type", "Expected array.", "array", input)]);
|
|
405
|
+
if (looksLikeJsonSchema(schema.items)) {
|
|
406
|
+
const issues = [];
|
|
407
|
+
const output = [];
|
|
408
|
+
input.forEach((value, index) => {
|
|
409
|
+
try {
|
|
410
|
+
output[index] = parseJsonSchema(schema.items, value, joinSchemaPath(path, index));
|
|
411
|
+
} catch (error) {
|
|
412
|
+
issues.push(...schemaIssuesFromError(error));
|
|
413
|
+
}
|
|
414
|
+
});
|
|
415
|
+
if (issues.length) throw new SchemaError(issues);
|
|
416
|
+
return output;
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
return input;
|
|
420
|
+
}
|
|
421
|
+
function normalizedFromParse(source, parse, toJsonSchema) {
|
|
422
|
+
return {
|
|
423
|
+
source,
|
|
424
|
+
parse(input) {
|
|
425
|
+
const result = this.safeParse(input);
|
|
426
|
+
if (!result.success) throw result.error;
|
|
427
|
+
return result.data;
|
|
428
|
+
},
|
|
429
|
+
safeParse(input) {
|
|
430
|
+
try {
|
|
431
|
+
return ok(parse(input));
|
|
432
|
+
} catch (error) {
|
|
433
|
+
return fail(schemaIssuesFromError(error));
|
|
434
|
+
}
|
|
435
|
+
},
|
|
436
|
+
issuesFromError: schemaIssuesFromError,
|
|
437
|
+
toJsonSchema
|
|
438
|
+
};
|
|
439
|
+
}
|
|
440
|
+
function normalizedFromSafeParse(source, safeParse, toJsonSchema) {
|
|
441
|
+
return {
|
|
442
|
+
source,
|
|
443
|
+
parse(input) {
|
|
444
|
+
const result = this.safeParse(input);
|
|
445
|
+
if (!result.success) throw result.error;
|
|
446
|
+
return result.data;
|
|
447
|
+
},
|
|
448
|
+
safeParse(input) {
|
|
449
|
+
const result = safeParse(input);
|
|
450
|
+
return result.success ? ok(result.data) : fail(schemaIssuesFromError(result.error));
|
|
451
|
+
},
|
|
452
|
+
issuesFromError: schemaIssuesFromError,
|
|
453
|
+
toJsonSchema
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
function parseStandardSchema(schema, input) {
|
|
457
|
+
const result = schema["~standard"].validate(input);
|
|
458
|
+
if (result && typeof result.then === "function") {
|
|
459
|
+
throw new Error("Async Standard Schema validation is not supported by normalizeSchema().");
|
|
460
|
+
}
|
|
461
|
+
if (result && typeof result === "object" && "issues" in result) {
|
|
462
|
+
throw new SchemaError(schemaIssuesFromError(result));
|
|
463
|
+
}
|
|
464
|
+
return result.value;
|
|
465
|
+
}
|
|
466
|
+
function normalizeSchema(schema) {
|
|
467
|
+
if (!schema) {
|
|
468
|
+
const unknown2 = new UnknownSchema();
|
|
469
|
+
return normalizedFromParse("harness", (input) => unknown2.parse(input), () => unknown2.toJsonSchema());
|
|
470
|
+
}
|
|
471
|
+
if (isHarnessSchema(schema)) {
|
|
472
|
+
return normalizedFromParse(
|
|
473
|
+
"harness",
|
|
474
|
+
(input) => schema.parse(input),
|
|
475
|
+
() => schema.toJsonSchema()
|
|
476
|
+
);
|
|
477
|
+
}
|
|
478
|
+
if (typeof schema === "object" && schema !== null && "safeParse" in schema && typeof schema.safeParse === "function") {
|
|
479
|
+
return normalizedFromSafeParse(
|
|
480
|
+
looksLikeZodSchema(schema) ? "zod" : "custom",
|
|
481
|
+
(input) => schema.safeParse(input),
|
|
482
|
+
getExternalJsonSchema(schema)
|
|
483
|
+
);
|
|
484
|
+
}
|
|
485
|
+
if (looksLikeStandardSchema(schema)) {
|
|
486
|
+
return normalizedFromParse(
|
|
487
|
+
"standard",
|
|
488
|
+
(input) => parseStandardSchema(schema, input),
|
|
489
|
+
getExternalJsonSchema(schema)
|
|
490
|
+
);
|
|
491
|
+
}
|
|
492
|
+
if (typeof schema === "object" && schema !== null && "parse" in schema && typeof schema.parse === "function") {
|
|
493
|
+
return normalizedFromParse(
|
|
494
|
+
"custom",
|
|
495
|
+
(input) => schema.parse(input),
|
|
496
|
+
getExternalJsonSchema(schema)
|
|
497
|
+
);
|
|
498
|
+
}
|
|
499
|
+
if (looksLikeJsonSchema(schema)) {
|
|
500
|
+
return normalizedFromParse(
|
|
501
|
+
"json-schema",
|
|
502
|
+
(input) => parseJsonSchema(schema, input),
|
|
503
|
+
() => schema
|
|
504
|
+
);
|
|
505
|
+
}
|
|
506
|
+
const unknown = new UnknownSchema();
|
|
507
|
+
return normalizedFromParse("custom", (input) => unknown.parse(input));
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
export {
|
|
511
|
+
SchemaError,
|
|
512
|
+
formatSchemaPath,
|
|
513
|
+
schemaIssuesFromError,
|
|
514
|
+
Schema,
|
|
515
|
+
StringSchema,
|
|
516
|
+
NumberSchema,
|
|
517
|
+
BooleanSchema,
|
|
518
|
+
ArraySchema,
|
|
519
|
+
ObjectSchema,
|
|
520
|
+
RecordSchema,
|
|
521
|
+
EnumSchema,
|
|
522
|
+
LiteralSchema,
|
|
523
|
+
OptionalSchema,
|
|
524
|
+
DefaultSchema,
|
|
525
|
+
UnknownSchema,
|
|
526
|
+
s,
|
|
527
|
+
normalizeSchema
|
|
528
|
+
};
|
|
529
|
+
//# sourceMappingURL=chunk-OBKS4AJR.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/schema/index.ts"],"sourcesContent":["export type SchemaIssueCode =\n | \"invalid_type\"\n | \"invalid_literal\"\n | \"invalid_enum\"\n | \"too_small\"\n | \"too_big\"\n | \"custom\";\n\nexport type SchemaSource = \"harness\" | \"zod\" | \"standard\" | \"json-schema\" | \"custom\";\n\nexport interface SchemaIssue {\n path: string;\n code: string;\n message: string;\n expected?: string;\n received?: string;\n}\n\nexport class SchemaError extends Error {\n readonly issues: SchemaIssue[];\n\n constructor(issues: SchemaIssue[]) {\n const normalized = issues.length ? issues.map(normalizeIssue) : [issue(undefined, \"custom\", \"Schema validation failed.\")];\n super(normalized[0]?.message ?? \"Schema validation failed.\");\n this.name = \"SchemaError\";\n this.issues = normalized;\n }\n}\n\nexport type SafeParseResult<T> =\n | { success: true; data: T }\n | { success: false; error: SchemaError };\n\nexport type JsonSchema = Record<string, unknown>;\n\ntype SchemaPathInput = string | number | Array<string | number> | undefined;\n\nexport function formatSchemaPath(path: SchemaPathInput): string {\n if (Array.isArray(path)) return path.length ? path.map((part) => String(part)).join(\".\") : \"(root)\";\n if (typeof path === \"number\") return String(path);\n if (typeof path === \"string\" && path.trim()) return path;\n return \"(root)\";\n}\n\nfunction joinSchemaPath(parent: SchemaPathInput, child: SchemaPathInput): string {\n const left = formatSchemaPath(parent);\n const right = formatSchemaPath(child);\n if (left === \"(root)\") return right;\n if (right === \"(root)\") return left;\n return `${left}.${right}`;\n}\n\nfunction normalizeIssue(value: unknown): SchemaIssue {\n if (typeof value !== \"object\" || value === null) {\n return issue(undefined, \"custom\", String(value || \"Schema validation failed.\"));\n }\n const record = value as Record<string, unknown>;\n return {\n path: formatSchemaPath(record.path as SchemaPathInput),\n code: typeof record.code === \"string\" ? record.code : \"custom\",\n message: typeof record.message === \"string\" ? record.message : \"Invalid value.\",\n expected: typeof record.expected === \"string\" ? record.expected : undefined,\n received: typeof record.received === \"string\" ? record.received : undefined,\n };\n}\n\nexport function schemaIssuesFromError(error: unknown): SchemaIssue[] {\n if (error instanceof SchemaError) return error.issues;\n if (error && typeof error === \"object\" && \"issues\" in error && Array.isArray((error as { issues?: unknown }).issues)) {\n return (error as { issues: unknown[] }).issues.map(normalizeIssue);\n }\n return [issue(undefined, \"custom\", error instanceof Error ? error.message : String(error ?? \"Schema validation failed.\"))];\n}\n\nexport abstract class Schema<TInput = unknown, TOutput = TInput> {\n readonly isHarnessSchema = true;\n private schemaDescription?: string;\n\n abstract safeParse(input: unknown): SafeParseResult<TOutput>;\n abstract toJsonSchema(): JsonSchema;\n\n parse(input: TInput): TOutput {\n const result = this.safeParse(input);\n if (!result.success) throw result.error;\n return result.data;\n }\n\n optional(): OptionalSchema<TInput | undefined, TOutput | undefined> {\n return new OptionalSchema(this);\n }\n\n default(value: TOutput | (() => TOutput)): DefaultSchema<TInput | undefined, TOutput> {\n return new DefaultSchema(this, value);\n }\n\n describe(description: string): this {\n this.schemaDescription = description;\n return this;\n }\n\n protected withDescription<TJson extends JsonSchema>(json: TJson): TJson {\n return this.schemaDescription ? { ...json, description: this.schemaDescription } : json;\n }\n}\n\nexport type InferInput<TSchema> = TSchema extends Schema<infer TInput, any> ? TInput : unknown;\nexport type InferOutput<TSchema> = TSchema extends Schema<any, infer TOutput> ? TOutput : unknown;\n\nfunction received(value: unknown): string {\n if (Array.isArray(value)) return \"array\";\n if (value === null) return \"null\";\n return typeof value;\n}\n\nfunction issue(path: SchemaPathInput, code: SchemaIssueCode | string, message: string, expected?: string, value?: unknown): SchemaIssue {\n return {\n path: formatSchemaPath(path),\n code,\n message,\n expected,\n received: value === undefined ? undefined : received(value),\n };\n}\n\nfunction prependIssuePath(path: SchemaPathInput, entry: SchemaIssue): SchemaIssue {\n return { ...entry, path: joinSchemaPath(path, entry.path) };\n}\n\nfunction ok<T>(data: T): SafeParseResult<T> {\n return { success: true, data };\n}\n\nfunction fail<T>(issues: SchemaIssue[]): SafeParseResult<T> {\n return { success: false, error: new SchemaError(issues) };\n}\n\nexport class StringSchema extends Schema<unknown, string> {\n private minLength?: number;\n private maxLength?: number;\n\n min(length: number): this {\n this.minLength = length;\n return this;\n }\n\n max(length: number): this {\n this.maxLength = length;\n return this;\n }\n\n safeParse(input: unknown): SafeParseResult<string> {\n if (typeof input !== \"string\") return fail([issue(undefined, \"invalid_type\", \"Expected string.\", \"string\", input)]);\n if (this.minLength !== undefined && input.length < this.minLength) {\n return fail([issue(undefined, \"too_small\", `Expected string to contain at least ${this.minLength} character(s).`, `string(min:${this.minLength})`, input)]);\n }\n if (this.maxLength !== undefined && input.length > this.maxLength) {\n return fail([issue(undefined, \"too_big\", `Expected string to contain at most ${this.maxLength} character(s).`, `string(max:${this.maxLength})`, input)]);\n }\n return ok(input);\n }\n\n toJsonSchema(): JsonSchema {\n return this.withDescription({\n type: \"string\",\n ...(this.minLength !== undefined ? { minLength: this.minLength } : {}),\n ...(this.maxLength !== undefined ? { maxLength: this.maxLength } : {}),\n });\n }\n}\n\nexport class NumberSchema extends Schema<unknown, number> {\n private integerOnly = false;\n private minValue?: number;\n private maxValue?: number;\n private exclusiveMin?: number;\n\n int(): this {\n this.integerOnly = true;\n return this;\n }\n\n min(value: number): this {\n this.minValue = value;\n return this;\n }\n\n max(value: number): this {\n this.maxValue = value;\n return this;\n }\n\n positive(): this {\n this.exclusiveMin = 0;\n return this;\n }\n\n safeParse(input: unknown): SafeParseResult<number> {\n if (typeof input !== \"number\" || Number.isNaN(input)) {\n return fail([issue(undefined, \"invalid_type\", \"Expected number.\", \"number\", input)]);\n }\n if (this.integerOnly && !Number.isInteger(input)) {\n return fail([issue(undefined, \"invalid_type\", \"Expected integer.\", \"integer\", input)]);\n }\n if (this.exclusiveMin !== undefined && input <= this.exclusiveMin) {\n return fail([issue(undefined, \"too_small\", `Expected number to be greater than ${this.exclusiveMin}.`, `number(>${this.exclusiveMin})`, input)]);\n }\n if (this.minValue !== undefined && input < this.minValue) {\n return fail([issue(undefined, \"too_small\", `Expected number to be greater than or equal to ${this.minValue}.`, `number(min:${this.minValue})`, input)]);\n }\n if (this.maxValue !== undefined && input > this.maxValue) {\n return fail([issue(undefined, \"too_big\", `Expected number to be less than or equal to ${this.maxValue}.`, `number(max:${this.maxValue})`, input)]);\n }\n return ok(input);\n }\n\n toJsonSchema(): JsonSchema {\n return this.withDescription({\n type: this.integerOnly ? \"integer\" : \"number\",\n ...(this.minValue !== undefined ? { minimum: this.minValue } : {}),\n ...(this.maxValue !== undefined ? { maximum: this.maxValue } : {}),\n ...(this.exclusiveMin !== undefined ? { exclusiveMinimum: this.exclusiveMin } : {}),\n });\n }\n}\n\nexport class BooleanSchema extends Schema<unknown, boolean> {\n safeParse(input: unknown): SafeParseResult<boolean> {\n return typeof input === \"boolean\"\n ? ok(input)\n : fail([issue(undefined, \"invalid_type\", \"Expected boolean.\", \"boolean\", input)]);\n }\n\n toJsonSchema(): JsonSchema {\n return this.withDescription({ type: \"boolean\" });\n }\n}\n\nexport class ArraySchema<TItem extends Schema<any, any>> extends Schema<InferInput<TItem>[], InferOutput<TItem>[]> {\n constructor(private readonly item: TItem) {\n super();\n }\n\n safeParse(input: unknown): SafeParseResult<InferOutput<TItem>[]> {\n if (!Array.isArray(input)) return fail([issue(undefined, \"invalid_type\", \"Expected array.\", \"array\", input)]);\n const issues: SchemaIssue[] = [];\n const data: InferOutput<TItem>[] = [];\n input.forEach((value, index) => {\n const result = this.item.safeParse(value);\n if (result.success) data.push(result.data);\n else issues.push(...result.error.issues.map((entry) => prependIssuePath(index, entry)));\n });\n return issues.length ? fail(issues) : ok(data);\n }\n\n toJsonSchema(): JsonSchema {\n return this.withDescription({ type: \"array\", items: this.item.toJsonSchema() });\n }\n}\n\ntype ObjectShape = Record<string, Schema<any, any>>;\ntype OptionalInputKeys<TShape extends ObjectShape> = {\n [K in keyof TShape]: undefined extends InferInput<TShape[K]> ? K : never;\n}[keyof TShape];\ntype ObjectInput<TShape extends ObjectShape> =\n & { [K in Exclude<keyof TShape, OptionalInputKeys<TShape>>]: InferInput<TShape[K]> }\n & { [K in OptionalInputKeys<TShape>]?: InferInput<TShape[K]> };\ntype OptionalOutputKeys<TShape extends ObjectShape> = {\n [K in keyof TShape]: undefined extends InferOutput<TShape[K]> ? K : never;\n}[keyof TShape];\ntype ObjectOutput<TShape extends ObjectShape> =\n & { [K in Exclude<keyof TShape, OptionalOutputKeys<TShape>>]: InferOutput<TShape[K]> }\n & { [K in OptionalOutputKeys<TShape>]?: InferOutput<TShape[K]> };\n\nexport class ObjectSchema<TShape extends ObjectShape> extends Schema<ObjectInput<TShape>, ObjectOutput<TShape>> {\n constructor(private readonly shape: TShape) {\n super();\n }\n\n safeParse(input: unknown): SafeParseResult<ObjectOutput<TShape>> {\n if (typeof input !== \"object\" || input === null || Array.isArray(input)) {\n return fail([issue(undefined, \"invalid_type\", \"Expected object.\", \"object\", input)]);\n }\n const source = input as Record<string, unknown>;\n const output: Record<string, unknown> = {};\n const issues: SchemaIssue[] = [];\n for (const [key, schema] of Object.entries(this.shape)) {\n const result = schema.safeParse(source[key]);\n if (result.success) {\n if (result.data !== undefined || Object.prototype.hasOwnProperty.call(source, key)) output[key] = result.data;\n } else {\n issues.push(...result.error.issues.map((entry) => prependIssuePath(key, entry)));\n }\n }\n return issues.length ? fail(issues) : ok(output as ObjectOutput<TShape>);\n }\n\n toJsonSchema(): JsonSchema {\n const properties: Record<string, unknown> = {};\n const required: string[] = [];\n for (const [key, schema] of Object.entries(this.shape)) {\n properties[key] = schema.toJsonSchema();\n if (!(schema instanceof OptionalSchema) && !(schema instanceof DefaultSchema)) required.push(key);\n }\n return this.withDescription({\n type: \"object\",\n properties,\n additionalProperties: false,\n ...(required.length ? { required } : {}),\n });\n }\n}\n\nexport class RecordSchema<TValue extends Schema<any, any>> extends Schema<Record<string, InferInput<TValue>>, Record<string, InferOutput<TValue>>> {\n constructor(private readonly valueSchema: TValue) {\n super();\n }\n\n safeParse(input: unknown): SafeParseResult<Record<string, InferOutput<TValue>>> {\n if (typeof input !== \"object\" || input === null || Array.isArray(input)) {\n return fail([issue(undefined, \"invalid_type\", \"Expected object.\", \"object\", input)]);\n }\n const output: Record<string, InferOutput<TValue>> = {};\n const issues: SchemaIssue[] = [];\n for (const [key, value] of Object.entries(input as Record<string, unknown>)) {\n const result = this.valueSchema.safeParse(value);\n if (result.success) output[key] = result.data;\n else issues.push(...result.error.issues.map((entry) => prependIssuePath(key, entry)));\n }\n return issues.length ? fail(issues) : ok(output);\n }\n\n toJsonSchema(): JsonSchema {\n return this.withDescription({ type: \"object\", additionalProperties: this.valueSchema.toJsonSchema() });\n }\n}\n\nexport class EnumSchema<const TValues extends readonly [string, ...string[]]> extends Schema<unknown, TValues[number]> {\n constructor(private readonly values: TValues) {\n super();\n }\n\n safeParse(input: unknown): SafeParseResult<TValues[number]> {\n return typeof input === \"string\" && (this.values as readonly string[]).includes(input)\n ? ok(input as TValues[number])\n : fail([issue(undefined, \"invalid_enum\", `Expected one of: ${this.values.join(\", \")}.`, this.values.join(\" | \"), input)]);\n }\n\n toJsonSchema(): JsonSchema {\n return this.withDescription({ type: \"string\", enum: [...this.values] });\n }\n}\n\nexport class LiteralSchema<const TValue> extends Schema<unknown, TValue> {\n constructor(private readonly value: TValue) {\n super();\n }\n\n safeParse(input: unknown): SafeParseResult<TValue> {\n return Object.is(input, this.value)\n ? ok(this.value)\n : fail([issue(undefined, \"invalid_literal\", `Expected literal ${JSON.stringify(this.value)}.`, JSON.stringify(this.value), input)]);\n }\n\n toJsonSchema(): JsonSchema {\n const type = this.value === null ? \"null\" : typeof this.value;\n return this.withDescription({\n const: this.value,\n ...(type === \"string\" || type === \"number\" || type === \"boolean\" || type === \"null\" ? { type } : {}),\n });\n }\n}\n\nexport class OptionalSchema<TInput, TOutput> extends Schema<TInput | undefined, TOutput | undefined> {\n constructor(private readonly inner: Schema<TInput, TOutput>) {\n super();\n }\n\n safeParse(input: unknown): SafeParseResult<TOutput | undefined> {\n if (input === undefined) return ok(undefined);\n return this.inner.safeParse(input);\n }\n\n toJsonSchema(): JsonSchema {\n return this.withDescription(this.inner.toJsonSchema());\n }\n}\n\nexport class DefaultSchema<TInput, TOutput> extends Schema<TInput | undefined, TOutput> {\n constructor(\n private readonly inner: Schema<TInput, TOutput>,\n private readonly value: TOutput | (() => TOutput),\n ) {\n super();\n }\n\n safeParse(input: unknown): SafeParseResult<TOutput> {\n if (input === undefined) return ok(typeof this.value === \"function\" ? (this.value as () => TOutput)() : this.value);\n return this.inner.safeParse(input);\n }\n\n toJsonSchema(): JsonSchema {\n const json = this.inner.toJsonSchema();\n return this.withDescription({\n ...json,\n ...(typeof this.value === \"function\" ? {} : { default: this.value }),\n });\n }\n}\n\nexport class UnknownSchema extends Schema<unknown, unknown> {\n safeParse(input: unknown): SafeParseResult<unknown> {\n return ok(input);\n }\n\n toJsonSchema(): JsonSchema {\n return this.withDescription({});\n }\n}\n\nexport const s = {\n string: () => new StringSchema(),\n number: () => new NumberSchema(),\n boolean: () => new BooleanSchema(),\n array: <TItem extends Schema<any, any>>(item: TItem) => new ArraySchema(item),\n object: <TShape extends ObjectShape>(shape: TShape) => new ObjectSchema(shape),\n record: <TValue extends Schema<any, any>>(value: TValue) => new RecordSchema(value),\n enum: <const TValues extends readonly [string, ...string[]]>(values: TValues) => new EnumSchema(values),\n literal: <const TValue>(value: TValue) => new LiteralSchema(value),\n unknown: () => new UnknownSchema(),\n};\n\nexport interface NormalizedSchema<TInput = unknown, TOutput = unknown> {\n source: SchemaSource;\n parse(input: TInput): TOutput;\n safeParse(input: TInput): SafeParseResult<TOutput>;\n issuesFromError(error: unknown): SchemaIssue[];\n toJsonSchema?: () => JsonSchema;\n}\n\nfunction isHarnessSchema(value: unknown): value is Schema<any, any> {\n return value instanceof Schema || (typeof value === \"object\" && value !== null && (value as { isHarnessSchema?: unknown }).isHarnessSchema === true);\n}\n\nfunction looksLikeJsonSchema(value: unknown): value is JsonSchema {\n return typeof value === \"object\" && value !== null && (\n \"type\" in value || \"properties\" in value || \"enum\" in value || \"items\" in value || \"const\" in value || \"additionalProperties\" in value\n );\n}\n\nfunction looksLikeZodSchema(value: unknown): boolean {\n if (typeof value !== \"object\" || value === null) return false;\n if (!(\"safeParse\" in value) || typeof (value as { safeParse?: unknown }).safeParse !== \"function\") return false;\n const constructorName = (value as { constructor?: { name?: string } }).constructor?.name;\n return \"_def\" in value || \"_zod\" in value || Boolean(constructorName?.startsWith(\"Zod\"));\n}\n\nfunction looksLikeStandardSchema(value: unknown): value is { \"~standard\": { validate(input: unknown): unknown } } {\n return typeof value === \"object\"\n && value !== null\n && \"~standard\" in value\n && typeof (value as { \"~standard\"?: { validate?: unknown } })[\"~standard\"]?.validate === \"function\";\n}\n\nfunction getExternalJsonSchema(schema: unknown): (() => JsonSchema) | undefined {\n if (typeof schema !== \"object\" || schema === null) return undefined;\n if (typeof (schema as { toJsonSchema?: unknown }).toJsonSchema === \"function\") {\n return () => (schema as { toJsonSchema(): JsonSchema }).toJsonSchema();\n }\n if (typeof (schema as { toJSONSchema?: unknown }).toJSONSchema === \"function\") {\n return () => (schema as { toJSONSchema(): JsonSchema }).toJSONSchema();\n }\n const jsonSchema = (schema as { jsonSchema?: unknown }).jsonSchema;\n if (looksLikeJsonSchema(jsonSchema)) return () => jsonSchema;\n return undefined;\n}\n\nfunction parseJsonSchema(schema: JsonSchema, input: unknown, path: SchemaPathInput = undefined): unknown {\n if (Array.isArray(schema.enum) && !schema.enum.includes(input)) {\n throw new SchemaError([issue(path, \"invalid_enum\", `Expected one of: ${schema.enum.join(\", \")}.`, schema.enum.join(\" | \"), input)]);\n }\n if (\"const\" in schema && !Object.is(schema.const, input)) {\n throw new SchemaError([issue(path, \"invalid_literal\", `Expected literal ${JSON.stringify(schema.const)}.`, JSON.stringify(schema.const), input)]);\n }\n\n const type = schema.type;\n if (type === \"object\" || schema.properties || schema.additionalProperties) {\n if (typeof input !== \"object\" || input === null || Array.isArray(input)) {\n throw new SchemaError([issue(path, \"invalid_type\", \"Expected object.\", \"object\", input)]);\n }\n const required = Array.isArray(schema.required) ? schema.required.map(String) : [];\n const properties = typeof schema.properties === \"object\" && schema.properties !== null\n ? schema.properties as Record<string, JsonSchema>\n : {};\n const output: Record<string, unknown> = {};\n const issues: SchemaIssue[] = [];\n for (const key of required) {\n if (!Object.prototype.hasOwnProperty.call(input, key)) {\n issues.push(issue(joinSchemaPath(path, key), \"invalid_type\", \"Required.\", \"defined\", undefined));\n }\n }\n for (const [key, child] of Object.entries(properties)) {\n if (Object.prototype.hasOwnProperty.call(input, key)) {\n try {\n output[key] = parseJsonSchema(child, (input as Record<string, unknown>)[key], joinSchemaPath(path, key));\n } catch (error) {\n issues.push(...schemaIssuesFromError(error));\n }\n }\n }\n if (issues.length) throw new SchemaError(issues);\n return { ...(input as Record<string, unknown>), ...output };\n }\n if (type === \"string\" && typeof input !== \"string\") throw new SchemaError([issue(path, \"invalid_type\", \"Expected string.\", \"string\", input)]);\n if ((type === \"number\" || type === \"integer\") && typeof input !== \"number\") throw new SchemaError([issue(path, \"invalid_type\", \"Expected number.\", String(type), input)]);\n if (type === \"integer\" && !Number.isInteger(input)) throw new SchemaError([issue(path, \"invalid_type\", \"Expected integer.\", \"integer\", input)]);\n if (type === \"boolean\" && typeof input !== \"boolean\") throw new SchemaError([issue(path, \"invalid_type\", \"Expected boolean.\", \"boolean\", input)]);\n if (type === \"array\") {\n if (!Array.isArray(input)) throw new SchemaError([issue(path, \"invalid_type\", \"Expected array.\", \"array\", input)]);\n if (looksLikeJsonSchema(schema.items)) {\n const issues: SchemaIssue[] = [];\n const output: unknown[] = [];\n input.forEach((value, index) => {\n try {\n output[index] = parseJsonSchema(schema.items as JsonSchema, value, joinSchemaPath(path, index));\n } catch (error) {\n issues.push(...schemaIssuesFromError(error));\n }\n });\n if (issues.length) throw new SchemaError(issues);\n return output;\n }\n }\n return input;\n}\n\nfunction normalizedFromParse<TInput, TOutput>(\n source: SchemaSource,\n parse: (input: TInput) => TOutput,\n toJsonSchema?: () => JsonSchema,\n): NormalizedSchema<TInput, TOutput> {\n return {\n source,\n parse(input: TInput): TOutput {\n const result = this.safeParse(input);\n if (!result.success) throw result.error;\n return result.data;\n },\n safeParse(input: TInput): SafeParseResult<TOutput> {\n try {\n return ok(parse(input));\n } catch (error) {\n return fail(schemaIssuesFromError(error));\n }\n },\n issuesFromError: schemaIssuesFromError,\n toJsonSchema,\n };\n}\n\nfunction normalizedFromSafeParse<TInput, TOutput>(\n source: SchemaSource,\n safeParse: (input: TInput) => { success: true; data: TOutput } | { success: false; error: unknown },\n toJsonSchema?: () => JsonSchema,\n): NormalizedSchema<TInput, TOutput> {\n return {\n source,\n parse(input: TInput): TOutput {\n const result = this.safeParse(input);\n if (!result.success) throw result.error;\n return result.data;\n },\n safeParse(input: TInput): SafeParseResult<TOutput> {\n const result = safeParse(input);\n return result.success ? ok(result.data) : fail(schemaIssuesFromError(result.error));\n },\n issuesFromError: schemaIssuesFromError,\n toJsonSchema,\n };\n}\n\nfunction parseStandardSchema<TInput, TOutput>(schema: { \"~standard\": { validate(input: unknown): unknown } }, input: TInput): TOutput {\n const result = schema[\"~standard\"].validate(input);\n if (result && typeof (result as { then?: unknown }).then === \"function\") {\n throw new Error(\"Async Standard Schema validation is not supported by normalizeSchema().\");\n }\n if (result && typeof result === \"object\" && \"issues\" in result) {\n throw new SchemaError(schemaIssuesFromError(result));\n }\n return (result as { value?: TOutput }).value as TOutput;\n}\n\nexport function normalizeSchema<TInput = unknown, TOutput = unknown>(schema: unknown): NormalizedSchema<TInput, TOutput> {\n if (!schema) {\n const unknown = new UnknownSchema();\n return normalizedFromParse(\"harness\", (input: TInput) => unknown.parse(input) as TOutput, () => unknown.toJsonSchema());\n }\n\n if (isHarnessSchema(schema)) {\n return normalizedFromParse(\n \"harness\",\n (input: TInput) => schema.parse(input) as TOutput,\n () => schema.toJsonSchema(),\n );\n }\n\n if (typeof schema === \"object\" && schema !== null && \"safeParse\" in schema && typeof (schema as { safeParse?: unknown }).safeParse === \"function\") {\n return normalizedFromSafeParse(\n looksLikeZodSchema(schema) ? \"zod\" : \"custom\",\n (input: TInput) => (schema as { safeParse(input: TInput): { success: true; data: TOutput } | { success: false; error: unknown } }).safeParse(input),\n getExternalJsonSchema(schema),\n );\n }\n\n if (looksLikeStandardSchema(schema)) {\n return normalizedFromParse(\n \"standard\",\n (input: TInput) => parseStandardSchema<TInput, TOutput>(schema, input),\n getExternalJsonSchema(schema),\n );\n }\n\n if (typeof schema === \"object\" && schema !== null && \"parse\" in schema && typeof (schema as { parse?: unknown }).parse === \"function\") {\n return normalizedFromParse(\n \"custom\",\n (input: TInput) => (schema as { parse(input: TInput): TOutput }).parse(input),\n getExternalJsonSchema(schema),\n );\n }\n\n if (looksLikeJsonSchema(schema)) {\n return normalizedFromParse(\n \"json-schema\",\n (input: TInput) => parseJsonSchema(schema, input) as TOutput,\n () => schema,\n );\n }\n\n const unknown = new UnknownSchema();\n return normalizedFromParse(\"custom\", (input: TInput) => unknown.parse(input) as TOutput);\n}\n"],"mappings":";AAkBO,IAAM,cAAN,cAA0B,MAAM;AAAA,EAC5B;AAAA,EAET,YAAY,QAAuB;AACjC,UAAM,aAAa,OAAO,SAAS,OAAO,IAAI,cAAc,IAAI,CAAC,MAAM,QAAW,UAAU,2BAA2B,CAAC;AACxH,UAAM,WAAW,CAAC,GAAG,WAAW,2BAA2B;AAC3D,SAAK,OAAO;AACZ,SAAK,SAAS;AAAA,EAChB;AACF;AAUO,SAAS,iBAAiB,MAA+B;AAC9D,MAAI,MAAM,QAAQ,IAAI,EAAG,QAAO,KAAK,SAAS,KAAK,IAAI,CAAC,SAAS,OAAO,IAAI,CAAC,EAAE,KAAK,GAAG,IAAI;AAC3F,MAAI,OAAO,SAAS,SAAU,QAAO,OAAO,IAAI;AAChD,MAAI,OAAO,SAAS,YAAY,KAAK,KAAK,EAAG,QAAO;AACpD,SAAO;AACT;AAEA,SAAS,eAAe,QAAyB,OAAgC;AAC/E,QAAM,OAAO,iBAAiB,MAAM;AACpC,QAAM,QAAQ,iBAAiB,KAAK;AACpC,MAAI,SAAS,SAAU,QAAO;AAC9B,MAAI,UAAU,SAAU,QAAO;AAC/B,SAAO,GAAG,IAAI,IAAI,KAAK;AACzB;AAEA,SAAS,eAAe,OAA6B;AACnD,MAAI,OAAO,UAAU,YAAY,UAAU,MAAM;AAC/C,WAAO,MAAM,QAAW,UAAU,OAAO,SAAS,2BA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