@usestatemachines/cli 0.0.0-stage → 0.1.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 +34 -2
- package/dist/agents/bundled.d.ts +5 -0
- package/dist/agents/bundled.js +6 -0
- package/dist/agents/destinations.d.ts +13 -0
- package/dist/agents/destinations.js +16 -0
- package/dist/api-internal.d.ts +62 -0
- package/dist/api-internal.js +348 -0
- package/dist/bin.d.ts +2 -0
- package/dist/bin.js +4 -0
- package/dist/command.d.ts +119 -0
- package/dist/command.js +195 -0
- package/dist/commands/api/command.d.ts +15 -0
- package/dist/commands/api/command.js +38 -0
- package/dist/commands/api/run.d.ts +4 -0
- package/dist/commands/api/run.js +24 -0
- package/dist/commands/apps/command.d.ts +19 -0
- package/dist/commands/apps/command.js +29 -0
- package/dist/commands/apps/list.d.ts +8 -0
- package/dist/commands/apps/list.js +10 -0
- package/dist/commands/connect/command.d.ts +34 -0
- package/dist/commands/connect/command.js +70 -0
- package/dist/commands/connect/run.d.ts +10 -0
- package/dist/commands/connect/run.js +71 -0
- package/dist/commands/doctor/command.d.ts +29 -0
- package/dist/commands/doctor/command.js +36 -0
- package/dist/commands/doctor/run.d.ts +13 -0
- package/dist/commands/doctor/run.js +12 -0
- package/dist/commands/env/command.d.ts +5 -0
- package/dist/commands/env/command.js +19 -0
- package/dist/commands/env/pull.d.ts +6 -0
- package/dist/commands/env/pull.js +6 -0
- package/dist/commands/environments/command.d.ts +121 -0
- package/dist/commands/environments/command.js +170 -0
- package/dist/commands/environments/create.d.ts +9 -0
- package/dist/commands/environments/create.js +42 -0
- package/dist/commands/environments/delete.d.ts +7 -0
- package/dist/commands/environments/delete.js +48 -0
- package/dist/commands/environments/get.d.ts +39 -0
- package/dist/commands/environments/get.js +5 -0
- package/dist/commands/environments/list.d.ts +41 -0
- package/dist/commands/environments/list.js +18 -0
- package/dist/commands/environments/wait.d.ts +39 -0
- package/dist/commands/environments/wait.js +21 -0
- package/dist/commands/init/command.d.ts +68 -0
- package/dist/commands/init/command.js +90 -0
- package/dist/commands/init/run.d.ts +8 -0
- package/dist/commands/init/run.js +422 -0
- package/dist/commands/link/command.d.ts +13 -0
- package/dist/commands/link/command.js +32 -0
- package/dist/commands/link/run.d.ts +12 -0
- package/dist/commands/link/run.js +7 -0
- package/dist/commands/login/command.d.ts +1 -0
- package/dist/commands/login/command.js +43 -0
- package/dist/commands/login/run.d.ts +30 -0
- package/dist/commands/login/run.js +43 -0
- package/dist/commands/login/schema.d.ts +33 -0
- package/dist/commands/login/schema.js +33 -0
- package/dist/commands/logout/command.d.ts +1 -0
- package/dist/commands/logout/command.js +24 -0
- package/dist/commands/logout/run.d.ts +10 -0
- package/dist/commands/logout/run.js +19 -0
- package/dist/commands/logout/schema.d.ts +10 -0
- package/dist/commands/logout/schema.js +10 -0
- package/dist/commands/profiles/command.d.ts +2 -0
- package/dist/commands/profiles/command.js +29 -0
- package/dist/commands/profiles/list.d.ts +20 -0
- package/dist/commands/profiles/list.js +10 -0
- package/dist/commands/profiles/schema.d.ts +24 -0
- package/dist/commands/profiles/schema.js +19 -0
- package/dist/commands/profiles/use.d.ts +7 -0
- package/dist/commands/profiles/use.js +7 -0
- package/dist/commands/requests/command.d.ts +39 -0
- package/dist/commands/requests/command.js +65 -0
- package/dist/commands/requests/get.d.ts +32 -0
- package/dist/commands/requests/get.js +15 -0
- package/dist/commands/requests/list.d.ts +27 -0
- package/dist/commands/requests/list.js +25 -0
- package/dist/commands/snapshots/command.d.ts +48 -0
- package/dist/commands/snapshots/command.js +80 -0
- package/dist/commands/snapshots/create.d.ts +7 -0
- package/dist/commands/snapshots/create.js +26 -0
- package/dist/commands/snapshots/delete.d.ts +34 -0
- package/dist/commands/snapshots/delete.js +8 -0
- package/dist/commands/snapshots/get.d.ts +35 -0
- package/dist/commands/snapshots/get.js +5 -0
- package/dist/commands/snapshots/list.d.ts +37 -0
- package/dist/commands/snapshots/list.js +10 -0
- package/dist/commands/unlink/command.d.ts +1 -0
- package/dist/commands/unlink/command.js +15 -0
- package/dist/commands/unlink/run.d.ts +7 -0
- package/dist/commands/unlink/run.js +8 -0
- package/dist/commands/whoami/command.d.ts +28 -0
- package/dist/commands/whoami/command.js +44 -0
- package/dist/commands/whoami/run.d.ts +5 -0
- package/dist/commands/whoami/run.js +39 -0
- package/dist/commands/workspaces/command.d.ts +33 -0
- package/dist/commands/workspaces/command.js +73 -0
- package/dist/commands/workspaces/list.d.ts +5 -0
- package/dist/commands/workspaces/list.js +42 -0
- package/dist/commands/workspaces/use.d.ts +5 -0
- package/dist/commands/workspaces/use.js +18 -0
- package/dist/config/project.d.ts +21 -0
- package/dist/config/project.js +105 -0
- package/dist/config/schema.d.ts +616 -0
- package/dist/config/schema.js +282 -0
- package/dist/context-types.d.ts +89 -0
- package/dist/context-types.js +56 -0
- package/dist/context.d.ts +13 -0
- package/dist/context.js +290 -0
- package/dist/credentials/sealing.d.ts +10 -0
- package/dist/credentials/sealing.js +72 -0
- package/dist/credentials/store.d.ts +17 -0
- package/dist/credentials/store.js +156 -0
- package/dist/doctor.d.ts +4 -0
- package/dist/doctor.js +239 -0
- package/dist/env-file.d.ts +10 -0
- package/dist/env-file.js +254 -0
- package/dist/errors.d.ts +784 -0
- package/dist/errors.js +459 -0
- package/dist/flags.d.ts +22 -0
- package/dist/flags.js +56 -0
- package/dist/generated/internal.d.ts +138 -0
- package/dist/generated/internal.js +2627 -0
- package/dist/generated/retry.d.ts +1 -0
- package/dist/generated/retry.js +11 -0
- package/dist/help.d.ts +408 -0
- package/dist/help.js +220 -0
- package/dist/io-types.d.ts +127 -0
- package/dist/io-types.js +1 -0
- package/dist/io.d.ts +13 -0
- package/dist/io.js +1017 -0
- package/dist/keys.d.ts +50 -0
- package/dist/keys.js +691 -0
- package/dist/link.d.ts +6 -0
- package/dist/link.js +58 -0
- package/dist/login.d.ts +92 -0
- package/dist/login.js +965 -0
- package/dist/main.d.ts +2 -0
- package/dist/main.js +126 -0
- package/dist/native-helper.d.ts +1 -0
- package/dist/native-helper.js +2 -0
- package/dist/output.d.ts +8 -0
- package/dist/output.js +135 -0
- package/dist/parser.d.ts +28 -0
- package/dist/parser.js +250 -0
- package/dist/program-types.d.ts +67 -0
- package/dist/program-types.js +14 -0
- package/dist/programs.d.ts +2 -0
- package/dist/programs.js +44 -0
- package/dist/project-roots.d.ts +3 -0
- package/dist/project-roots.js +26 -0
- package/dist/prompt.d.ts +3 -0
- package/dist/prompt.js +61 -0
- package/dist/registry.d.ts +2 -0
- package/dist/registry.js +44 -0
- package/dist/resources/create.d.ts +9 -0
- package/dist/resources/create.js +55 -0
- package/dist/resources/read.d.ts +15 -0
- package/dist/resources/read.js +69 -0
- package/dist/resources/schema.d.ts +177 -0
- package/dist/resources/schema.js +158 -0
- package/dist/text.d.ts +3 -0
- package/dist/text.js +19 -0
- package/dist/update.d.ts +22 -0
- package/dist/update.js +126 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.js +2 -0
- package/package.json +52 -3
|
@@ -0,0 +1,2627 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
8
|
+
try {
|
|
9
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
10
|
+
} catch (e) {
|
|
11
|
+
throw mod = 0, e;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
var __copyProps = (to, from, except, desc) => {
|
|
15
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
16
|
+
for (let key of __getOwnPropNames(from))
|
|
17
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
18
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
23
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
24
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
25
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
26
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
27
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
28
|
+
mod
|
|
29
|
+
));
|
|
30
|
+
|
|
31
|
+
// node_modules/.pnpm/@asteasolutions+zod-to-openapi@9.1.0_zod@4.6.5/node_modules/@asteasolutions/zod-to-openapi/dist/index.cjs
|
|
32
|
+
var require_dist = __commonJS({
|
|
33
|
+
"node_modules/.pnpm/@asteasolutions+zod-to-openapi@9.1.0_zod@4.6.5/node_modules/@asteasolutions/zod-to-openapi/dist/index.cjs"(exports) {
|
|
34
|
+
"use strict";
|
|
35
|
+
function __rest(s, e) {
|
|
36
|
+
var t = {};
|
|
37
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
38
|
+
t[p] = s[p];
|
|
39
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
40
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
41
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
42
|
+
t[p[i]] = s[p[i]];
|
|
43
|
+
}
|
|
44
|
+
return t;
|
|
45
|
+
}
|
|
46
|
+
var ZodTypeKeys = {
|
|
47
|
+
ZodAny: "any",
|
|
48
|
+
ZodArray: "array",
|
|
49
|
+
ZodBigInt: "bigint",
|
|
50
|
+
ZodBoolean: "boolean",
|
|
51
|
+
ZodDefault: "default",
|
|
52
|
+
ZodPrefault: "prefault",
|
|
53
|
+
ZodTransform: "transform",
|
|
54
|
+
ZodEnum: "enum",
|
|
55
|
+
ZodIntersection: "intersection",
|
|
56
|
+
ZodLazy: "lazy",
|
|
57
|
+
ZodLiteral: "literal",
|
|
58
|
+
ZodNever: "never",
|
|
59
|
+
ZodNull: "null",
|
|
60
|
+
ZodNullable: "nullable",
|
|
61
|
+
ZodNumber: "number",
|
|
62
|
+
ZodNonOptional: "nonoptional",
|
|
63
|
+
ZodObject: "object",
|
|
64
|
+
ZodOptional: "optional",
|
|
65
|
+
ZodPipe: "pipe",
|
|
66
|
+
ZodReadonly: "readonly",
|
|
67
|
+
ZodRecord: "record",
|
|
68
|
+
ZodString: "string",
|
|
69
|
+
ZodTuple: "tuple",
|
|
70
|
+
ZodType: "type",
|
|
71
|
+
ZodUnion: "union",
|
|
72
|
+
ZodDiscriminatedUnion: "union",
|
|
73
|
+
ZodUnknown: "unknown",
|
|
74
|
+
ZodVoid: "void",
|
|
75
|
+
ZodDate: "date",
|
|
76
|
+
ZodTemplateLiteral: "template_literal"
|
|
77
|
+
};
|
|
78
|
+
function isZodType(schema, typeNames) {
|
|
79
|
+
const typeNamesArray = Array.isArray(typeNames) ? typeNames : [typeNames];
|
|
80
|
+
return typeNamesArray.some((typeName) => {
|
|
81
|
+
var _a;
|
|
82
|
+
const typeNameMatch = ((_a = schema === null || schema === void 0 ? void 0 : schema.def) === null || _a === void 0 ? void 0 : _a.type) === ZodTypeKeys[typeName];
|
|
83
|
+
if (typeName === "ZodDiscriminatedUnion") {
|
|
84
|
+
return typeNameMatch && "discriminator" in schema.def;
|
|
85
|
+
}
|
|
86
|
+
return typeNameMatch;
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
function isAnyZodType(schema) {
|
|
90
|
+
return schema && "def" in schema;
|
|
91
|
+
}
|
|
92
|
+
function isNullableSchema(schema) {
|
|
93
|
+
return schema.safeParse(null).success;
|
|
94
|
+
}
|
|
95
|
+
function isOptionalSchema(schema) {
|
|
96
|
+
return schema.safeParse(void 0).success;
|
|
97
|
+
}
|
|
98
|
+
var $ZodRegistry = class {
|
|
99
|
+
constructor() {
|
|
100
|
+
this._map = /* @__PURE__ */ new Map();
|
|
101
|
+
this._idmap = /* @__PURE__ */ new Map();
|
|
102
|
+
}
|
|
103
|
+
add(schema, ..._meta) {
|
|
104
|
+
const meta = _meta[0];
|
|
105
|
+
this._map.set(schema, meta);
|
|
106
|
+
if (meta && typeof meta === "object" && "id" in meta) {
|
|
107
|
+
if (this._idmap.has(meta.id)) {
|
|
108
|
+
throw new Error(`ID ${meta.id} already exists in the registry`);
|
|
109
|
+
}
|
|
110
|
+
this._idmap.set(meta.id, schema);
|
|
111
|
+
}
|
|
112
|
+
return this;
|
|
113
|
+
}
|
|
114
|
+
clear() {
|
|
115
|
+
this._map = /* @__PURE__ */ new Map();
|
|
116
|
+
this._idmap = /* @__PURE__ */ new Map();
|
|
117
|
+
return this;
|
|
118
|
+
}
|
|
119
|
+
remove(schema) {
|
|
120
|
+
const meta = this._map.get(schema);
|
|
121
|
+
if (meta && typeof meta === "object" && "id" in meta) {
|
|
122
|
+
this._idmap.delete(meta.id);
|
|
123
|
+
}
|
|
124
|
+
this._map.delete(schema);
|
|
125
|
+
return this;
|
|
126
|
+
}
|
|
127
|
+
get(schema) {
|
|
128
|
+
const p = schema._zod.parent;
|
|
129
|
+
if (p) {
|
|
130
|
+
const pm = { ...this.get(p) ?? {} };
|
|
131
|
+
delete pm.id;
|
|
132
|
+
return { ...pm, ...this._map.get(schema) };
|
|
133
|
+
}
|
|
134
|
+
return this._map.get(schema);
|
|
135
|
+
}
|
|
136
|
+
has(schema) {
|
|
137
|
+
return this._map.has(schema);
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
function registry() {
|
|
141
|
+
return new $ZodRegistry();
|
|
142
|
+
}
|
|
143
|
+
function isEqual(x, y) {
|
|
144
|
+
if (x === null || x === void 0 || y === null || y === void 0) {
|
|
145
|
+
return x === y;
|
|
146
|
+
}
|
|
147
|
+
if (x === y || x.valueOf() === y.valueOf()) {
|
|
148
|
+
return true;
|
|
149
|
+
}
|
|
150
|
+
if (Array.isArray(x)) {
|
|
151
|
+
if (!Array.isArray(y)) {
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
if (x.length !== y.length) {
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
if (!(x instanceof Object) || !(y instanceof Object)) {
|
|
159
|
+
return false;
|
|
160
|
+
}
|
|
161
|
+
const keysX = Object.keys(x);
|
|
162
|
+
return Object.keys(y).every((keyY) => keysX.indexOf(keyY) !== -1) && keysX.every((key) => isEqual(x[key], y[key]));
|
|
163
|
+
}
|
|
164
|
+
var ObjectSet = class {
|
|
165
|
+
constructor() {
|
|
166
|
+
this.buckets = /* @__PURE__ */ new Map();
|
|
167
|
+
}
|
|
168
|
+
put(value) {
|
|
169
|
+
const hashCode = this.hashCodeOf(value);
|
|
170
|
+
const itemsByCode = this.buckets.get(hashCode);
|
|
171
|
+
if (!itemsByCode) {
|
|
172
|
+
this.buckets.set(hashCode, [value]);
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
const alreadyHasItem = itemsByCode.some((_) => isEqual(_, value));
|
|
176
|
+
if (!alreadyHasItem) {
|
|
177
|
+
itemsByCode.push(value);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
contains(value) {
|
|
181
|
+
const hashCode = this.hashCodeOf(value);
|
|
182
|
+
const itemsByCode = this.buckets.get(hashCode);
|
|
183
|
+
if (!itemsByCode) {
|
|
184
|
+
return false;
|
|
185
|
+
}
|
|
186
|
+
return itemsByCode.some((_) => isEqual(_, value));
|
|
187
|
+
}
|
|
188
|
+
values() {
|
|
189
|
+
return [...this.buckets.values()].flat();
|
|
190
|
+
}
|
|
191
|
+
stats() {
|
|
192
|
+
let totalBuckets = 0;
|
|
193
|
+
let totalValues = 0;
|
|
194
|
+
let collisions = 0;
|
|
195
|
+
for (const bucket of this.buckets.values()) {
|
|
196
|
+
totalBuckets += 1;
|
|
197
|
+
totalValues += bucket.length;
|
|
198
|
+
if (bucket.length > 1) {
|
|
199
|
+
collisions += 1;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
const hashEffectiveness = totalBuckets / totalValues;
|
|
203
|
+
return { totalBuckets, collisions, totalValues, hashEffectiveness };
|
|
204
|
+
}
|
|
205
|
+
hashCodeOf(object2) {
|
|
206
|
+
let hashCode = 0;
|
|
207
|
+
if (Array.isArray(object2)) {
|
|
208
|
+
for (let i = 0; i < object2.length; i++) {
|
|
209
|
+
hashCode ^= this.hashCodeOf(object2[i]) * i;
|
|
210
|
+
}
|
|
211
|
+
return hashCode;
|
|
212
|
+
}
|
|
213
|
+
if (typeof object2 === "string") {
|
|
214
|
+
for (let i = 0; i < object2.length; i++) {
|
|
215
|
+
hashCode ^= object2.charCodeAt(i) * i;
|
|
216
|
+
}
|
|
217
|
+
return hashCode;
|
|
218
|
+
}
|
|
219
|
+
if (typeof object2 === "number") {
|
|
220
|
+
return object2;
|
|
221
|
+
}
|
|
222
|
+
if (typeof object2 === "object") {
|
|
223
|
+
for (const [key, value] of Object.entries(object2)) {
|
|
224
|
+
hashCode ^= this.hashCodeOf(key) + this.hashCodeOf(value !== null && value !== void 0 ? value : "");
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return hashCode;
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
function isUndefined(value) {
|
|
231
|
+
return value === void 0;
|
|
232
|
+
}
|
|
233
|
+
function mapValues(object2, mapper) {
|
|
234
|
+
const result = {};
|
|
235
|
+
Object.entries(object2).forEach(([key, value]) => {
|
|
236
|
+
result[key] = mapper(value);
|
|
237
|
+
});
|
|
238
|
+
return result;
|
|
239
|
+
}
|
|
240
|
+
function omit(object2, keys) {
|
|
241
|
+
const result = {};
|
|
242
|
+
Object.entries(object2).forEach(([key, value]) => {
|
|
243
|
+
if (!keys.some((keyToOmit) => keyToOmit === key)) {
|
|
244
|
+
result[key] = value;
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
return result;
|
|
248
|
+
}
|
|
249
|
+
function omitBy(object2, predicate) {
|
|
250
|
+
const result = {};
|
|
251
|
+
Object.entries(object2).forEach(([key, value]) => {
|
|
252
|
+
if (!predicate(value, key)) {
|
|
253
|
+
result[key] = value;
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
return result;
|
|
257
|
+
}
|
|
258
|
+
function compact(arr) {
|
|
259
|
+
return arr.filter((elem) => !isUndefined(elem));
|
|
260
|
+
}
|
|
261
|
+
var objectEquals = isEqual;
|
|
262
|
+
function uniq(values) {
|
|
263
|
+
const set = new ObjectSet();
|
|
264
|
+
values.forEach((value) => set.put(value));
|
|
265
|
+
return [...set.values()];
|
|
266
|
+
}
|
|
267
|
+
function isString(val) {
|
|
268
|
+
return typeof val === "string";
|
|
269
|
+
}
|
|
270
|
+
function sortObjectByKeys(obj) {
|
|
271
|
+
return Object.fromEntries(Object.entries(obj).sort(([leftKey], [rightKey]) => leftKey.localeCompare(rightKey)));
|
|
272
|
+
}
|
|
273
|
+
var zodToOpenAPIRegistry = registry();
|
|
274
|
+
var Metadata = class {
|
|
275
|
+
static collectMetadata(schema, metadata2) {
|
|
276
|
+
const currentMetadata = this.getMetadataFromRegistry(schema);
|
|
277
|
+
const _internal = Object.assign(Object.assign({}, currentMetadata === null || currentMetadata === void 0 ? void 0 : currentMetadata._internal), metadata2 === null || metadata2 === void 0 ? void 0 : metadata2._internal);
|
|
278
|
+
const param = Object.assign(Object.assign({}, currentMetadata === null || currentMetadata === void 0 ? void 0 : currentMetadata.param), metadata2 === null || metadata2 === void 0 ? void 0 : metadata2.param);
|
|
279
|
+
const totalMetadata = Object.assign(Object.assign(Object.assign(Object.assign({}, Object.keys(_internal).length > 0 ? { _internal } : {}), currentMetadata), metadata2), Object.keys(param).length > 0 ? { param } : {});
|
|
280
|
+
if (isZodType(schema, [
|
|
281
|
+
"ZodOptional",
|
|
282
|
+
"ZodNullable",
|
|
283
|
+
"ZodDefault",
|
|
284
|
+
"ZodPrefault",
|
|
285
|
+
"ZodReadonly",
|
|
286
|
+
"ZodNonOptional"
|
|
287
|
+
]) && isAnyZodType(schema._zod.def.innerType)) {
|
|
288
|
+
return this.collectMetadata(schema._zod.def.innerType, totalMetadata);
|
|
289
|
+
}
|
|
290
|
+
if (isZodType(schema, "ZodPipe")) {
|
|
291
|
+
const inSchema = schema._zod.def.in;
|
|
292
|
+
const outSchema = schema._zod.def.out;
|
|
293
|
+
if (isZodType(inSchema, "ZodTransform") && isAnyZodType(outSchema)) {
|
|
294
|
+
return this.collectMetadata(outSchema, totalMetadata);
|
|
295
|
+
}
|
|
296
|
+
if (isAnyZodType(inSchema)) {
|
|
297
|
+
return this.collectMetadata(inSchema, totalMetadata);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
return totalMetadata;
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* @deprecated Use one of `getOpenApiMetadata` or `getInternalMetadata` instead
|
|
304
|
+
*/
|
|
305
|
+
static getMetadata(zodSchema) {
|
|
306
|
+
return this.collectMetadata(zodSchema);
|
|
307
|
+
}
|
|
308
|
+
static getOpenApiMetadata(zodSchema) {
|
|
309
|
+
const metadata2 = this.collectMetadata(zodSchema);
|
|
310
|
+
const _a = metadata2 !== null && metadata2 !== void 0 ? metadata2 : {}, { _internal } = _a, rest = __rest(_a, ["_internal"]);
|
|
311
|
+
return rest;
|
|
312
|
+
}
|
|
313
|
+
static getInternalMetadata(zodSchema) {
|
|
314
|
+
var _a;
|
|
315
|
+
return (_a = this.collectMetadata(zodSchema)) === null || _a === void 0 ? void 0 : _a._internal;
|
|
316
|
+
}
|
|
317
|
+
static getParamMetadata(zodSchema) {
|
|
318
|
+
const metadata2 = this.collectMetadata(zodSchema);
|
|
319
|
+
return Object.assign(Object.assign({}, metadata2), {
|
|
320
|
+
// A description provided from .openapi() should be taken with higher precedence
|
|
321
|
+
param: Object.assign(Object.assign({}, (metadata2 === null || metadata2 === void 0 ? void 0 : metadata2.description) ? { description: metadata2.description } : {}), metadata2 === null || metadata2 === void 0 ? void 0 : metadata2.param)
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* A method that omits all custom keys added to the regular OpenAPI
|
|
326
|
+
* metadata properties
|
|
327
|
+
*/
|
|
328
|
+
static buildSchemaMetadata(metadata2) {
|
|
329
|
+
return omitBy(omit(metadata2, ["param", "_internal"]), isUndefined);
|
|
330
|
+
}
|
|
331
|
+
static buildParameterMetadata(metadata2) {
|
|
332
|
+
return omitBy(metadata2, isUndefined);
|
|
333
|
+
}
|
|
334
|
+
static applySchemaMetadata(initialData, metadata2) {
|
|
335
|
+
return omitBy(Object.assign(Object.assign({}, initialData), this.buildSchemaMetadata(metadata2)), isUndefined);
|
|
336
|
+
}
|
|
337
|
+
static getRefId(zodSchema) {
|
|
338
|
+
var _a;
|
|
339
|
+
return (_a = this.getInternalMetadata(zodSchema)) === null || _a === void 0 ? void 0 : _a.refId;
|
|
340
|
+
}
|
|
341
|
+
static unwrapChained(schema) {
|
|
342
|
+
return this.unwrapUntil(schema);
|
|
343
|
+
}
|
|
344
|
+
static getDefaultValue(zodSchema) {
|
|
345
|
+
var _a;
|
|
346
|
+
const unwrapped = (_a = this.unwrapUntil(zodSchema, "ZodDefault")) !== null && _a !== void 0 ? _a : this.unwrapUntil(zodSchema, "ZodPrefault");
|
|
347
|
+
return unwrapped === null || unwrapped === void 0 ? void 0 : unwrapped._zod.def.defaultValue;
|
|
348
|
+
}
|
|
349
|
+
static unwrapUntil(schema, typeName) {
|
|
350
|
+
if (typeName && isZodType(schema, typeName)) {
|
|
351
|
+
return schema;
|
|
352
|
+
}
|
|
353
|
+
if (isZodType(schema, [
|
|
354
|
+
"ZodOptional",
|
|
355
|
+
"ZodNullable",
|
|
356
|
+
"ZodDefault",
|
|
357
|
+
"ZodPrefault",
|
|
358
|
+
"ZodReadonly",
|
|
359
|
+
"ZodNonOptional"
|
|
360
|
+
]) && isAnyZodType(schema._zod.def.innerType)) {
|
|
361
|
+
return this.unwrapUntil(schema._zod.def.innerType, typeName);
|
|
362
|
+
}
|
|
363
|
+
if (isZodType(schema, "ZodPipe")) {
|
|
364
|
+
const inSchema = schema._zod.def.in;
|
|
365
|
+
const outSchema = schema._zod.def.out;
|
|
366
|
+
if (isZodType(inSchema, "ZodTransform") && isAnyZodType(outSchema)) {
|
|
367
|
+
return this.unwrapUntil(outSchema, typeName);
|
|
368
|
+
}
|
|
369
|
+
if (isAnyZodType(inSchema)) {
|
|
370
|
+
return this.unwrapUntil(inSchema, typeName);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
return typeName ? void 0 : schema;
|
|
374
|
+
}
|
|
375
|
+
static getMetadataFromInternalRegistry(zodSchema) {
|
|
376
|
+
return zodToOpenAPIRegistry.get(zodSchema);
|
|
377
|
+
}
|
|
378
|
+
static getMetadataFromRegistry(zodSchema) {
|
|
379
|
+
const internal = this.getMetadataFromInternalRegistry(zodSchema);
|
|
380
|
+
const general = zodSchema.meta();
|
|
381
|
+
if (!internal) {
|
|
382
|
+
return general;
|
|
383
|
+
}
|
|
384
|
+
const { _internal } = internal, rest = __rest(internal, ["_internal"]);
|
|
385
|
+
const _a = general !== null && general !== void 0 ? general : {}, { id, title } = _a, restGeneral = __rest(_a, ["id", "title"]);
|
|
386
|
+
return Object.assign(Object.assign(Object.assign({ _internal: Object.assign(Object.assign({}, id ? { refId: id } : {}), _internal) }, rest), title ? { description: title } : {}), restGeneral);
|
|
387
|
+
}
|
|
388
|
+
static setMetadataInRegistry(zodSchema, metadata2) {
|
|
389
|
+
zodToOpenAPIRegistry.add(zodSchema, metadata2);
|
|
390
|
+
}
|
|
391
|
+
};
|
|
392
|
+
function preserveMetadataFromModifier(zodSchema, modifier) {
|
|
393
|
+
const zodModifier = zodSchema[modifier];
|
|
394
|
+
if (typeof zodModifier !== "function") {
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
zodSchema[modifier] = function(...args) {
|
|
398
|
+
const result = zodModifier.apply(this, args);
|
|
399
|
+
const meta = Metadata.getMetadataFromRegistry(this);
|
|
400
|
+
if (meta) {
|
|
401
|
+
Metadata.setMetadataInRegistry(result, meta);
|
|
402
|
+
}
|
|
403
|
+
return result;
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
function extendZodWithOpenApi2(zod) {
|
|
407
|
+
if (typeof zod.ZodType.prototype.openapi !== "undefined") {
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
410
|
+
zod.ZodType.prototype.openapi = function(...args) {
|
|
411
|
+
const { refId, metadata: metadata2, options } = getOpenApiConfiguration(...args);
|
|
412
|
+
const _a = metadata2 !== null && metadata2 !== void 0 ? metadata2 : {}, { param } = _a, restOfOpenApi = __rest(_a, ["param"]);
|
|
413
|
+
const allMetadata = Metadata.getMetadataFromRegistry(this);
|
|
414
|
+
const _b = allMetadata !== null && allMetadata !== void 0 ? allMetadata : {}, { _internal: internalMetadata } = _b, currentMetadata = __rest(_b, ["_internal"]);
|
|
415
|
+
const _internal = Object.assign(Object.assign(Object.assign({}, internalMetadata), options), refId ? { refId } : void 0);
|
|
416
|
+
const resultMetadata = Object.assign(Object.assign(Object.assign({}, currentMetadata), restOfOpenApi), (currentMetadata === null || currentMetadata === void 0 ? void 0 : currentMetadata.param) || param ? {
|
|
417
|
+
param: Object.assign(Object.assign({}, currentMetadata === null || currentMetadata === void 0 ? void 0 : currentMetadata.param), param)
|
|
418
|
+
} : void 0);
|
|
419
|
+
const result = new this.constructor(this._def);
|
|
420
|
+
function setMetadata(schema) {
|
|
421
|
+
Metadata.setMetadataInRegistry(schema, Object.assign(Object.assign({}, Object.keys(_internal).length > 0 ? { _internal } : void 0), resultMetadata));
|
|
422
|
+
}
|
|
423
|
+
setMetadata(result);
|
|
424
|
+
if (isZodType(result, "ZodLazy")) {
|
|
425
|
+
setMetadata(this);
|
|
426
|
+
}
|
|
427
|
+
if (isZodType(result, "ZodObject")) {
|
|
428
|
+
const currentMetadata2 = Metadata.getMetadataFromRegistry(result);
|
|
429
|
+
const originalExtend = result.extend;
|
|
430
|
+
result.extend = function(...args2) {
|
|
431
|
+
const extendedResult = originalExtend.apply(result, args2);
|
|
432
|
+
const _a2 = currentMetadata2 !== null && currentMetadata2 !== void 0 ? currentMetadata2 : {}, { _internal: _internal2 } = _a2, rest = __rest(_a2, ["_internal"]);
|
|
433
|
+
Metadata.setMetadataInRegistry(extendedResult, {
|
|
434
|
+
_internal: {
|
|
435
|
+
extendedFrom: (_internal2 === null || _internal2 === void 0 ? void 0 : _internal2.refId) ? { refId: _internal2.refId, schema: result } : _internal2 === null || _internal2 === void 0 ? void 0 : _internal2.extendedFrom
|
|
436
|
+
}
|
|
437
|
+
});
|
|
438
|
+
return extendedResult.openapi(rest);
|
|
439
|
+
};
|
|
440
|
+
preserveMetadataFromModifier(result, "catchall");
|
|
441
|
+
}
|
|
442
|
+
preserveMetadataFromModifier(result, "optional");
|
|
443
|
+
preserveMetadataFromModifier(result, "nullable");
|
|
444
|
+
preserveMetadataFromModifier(result, "default");
|
|
445
|
+
preserveMetadataFromModifier(result, "transform");
|
|
446
|
+
preserveMetadataFromModifier(result, "refine");
|
|
447
|
+
preserveMetadataFromModifier(result, "length");
|
|
448
|
+
preserveMetadataFromModifier(result, "min");
|
|
449
|
+
preserveMetadataFromModifier(result, "max");
|
|
450
|
+
const originalMeta = result.meta;
|
|
451
|
+
result.meta = function(...args2) {
|
|
452
|
+
const result2 = originalMeta.apply(this, args2);
|
|
453
|
+
if (args2[0]) {
|
|
454
|
+
const meta = Metadata.getMetadataFromInternalRegistry(this);
|
|
455
|
+
if (meta) {
|
|
456
|
+
Metadata.setMetadataInRegistry(result2, Object.assign(Object.assign({}, meta), args2[0]));
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
return result2;
|
|
460
|
+
};
|
|
461
|
+
return result;
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
function getOpenApiConfiguration(refOrOpenapi, metadataOrOptions, options) {
|
|
465
|
+
if (typeof refOrOpenapi === "string") {
|
|
466
|
+
return {
|
|
467
|
+
refId: refOrOpenapi,
|
|
468
|
+
metadata: metadataOrOptions,
|
|
469
|
+
options
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
return {
|
|
473
|
+
refId: void 0,
|
|
474
|
+
metadata: refOrOpenapi,
|
|
475
|
+
options: metadataOrOptions
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
function getOpenApiMetadata2(zodSchema) {
|
|
479
|
+
var _a;
|
|
480
|
+
return omitBy((_a = Metadata.getOpenApiMetadata(zodSchema)) !== null && _a !== void 0 ? _a : {}, isUndefined);
|
|
481
|
+
}
|
|
482
|
+
function getRefId(zodSchema) {
|
|
483
|
+
return Metadata.getRefId(zodSchema);
|
|
484
|
+
}
|
|
485
|
+
var OpenAPIRegistry2 = class {
|
|
486
|
+
constructor(parents) {
|
|
487
|
+
this.parents = parents;
|
|
488
|
+
this._definitions = [];
|
|
489
|
+
}
|
|
490
|
+
get definitions() {
|
|
491
|
+
var _a, _b;
|
|
492
|
+
const parentDefinitions = (_b = (_a = this.parents) === null || _a === void 0 ? void 0 : _a.flatMap((par) => par._definitions)) !== null && _b !== void 0 ? _b : [];
|
|
493
|
+
return [...parentDefinitions, ...this._definitions];
|
|
494
|
+
}
|
|
495
|
+
/**
|
|
496
|
+
* Registers a new component schema under /components/schemas/${name}
|
|
497
|
+
*/
|
|
498
|
+
register(refId, zodSchema) {
|
|
499
|
+
const schemaWithRefId = this.schemaWithRefId(refId, zodSchema);
|
|
500
|
+
this._definitions.push({ type: "schema", schema: schemaWithRefId });
|
|
501
|
+
return schemaWithRefId;
|
|
502
|
+
}
|
|
503
|
+
/**
|
|
504
|
+
* Registers a new parameter schema under /components/parameters/${name}
|
|
505
|
+
*/
|
|
506
|
+
registerParameter(refId, zodSchema) {
|
|
507
|
+
var _a, _b, _c;
|
|
508
|
+
const schemaWithRefId = this.schemaWithRefId(refId, zodSchema);
|
|
509
|
+
const currentMetadata = (_a = Metadata.getOpenApiMetadata(schemaWithRefId)) !== null && _a !== void 0 ? _a : {};
|
|
510
|
+
const schemaWithMetadata = schemaWithRefId.openapi(Object.assign(Object.assign({}, currentMetadata), { param: Object.assign(Object.assign({}, currentMetadata === null || currentMetadata === void 0 ? void 0 : currentMetadata.param), { name: (_c = (_b = currentMetadata === null || currentMetadata === void 0 ? void 0 : currentMetadata.param) === null || _b === void 0 ? void 0 : _b.name) !== null && _c !== void 0 ? _c : refId }) }));
|
|
511
|
+
this._definitions.push({
|
|
512
|
+
type: "parameter",
|
|
513
|
+
schema: schemaWithMetadata
|
|
514
|
+
});
|
|
515
|
+
return schemaWithMetadata;
|
|
516
|
+
}
|
|
517
|
+
/**
|
|
518
|
+
* Registers a new path that would be generated under paths:
|
|
519
|
+
*/
|
|
520
|
+
registerPath(route) {
|
|
521
|
+
this._definitions.push({
|
|
522
|
+
type: "route",
|
|
523
|
+
route
|
|
524
|
+
});
|
|
525
|
+
}
|
|
526
|
+
/**
|
|
527
|
+
* Registers a new webhook that would be generated under webhooks:
|
|
528
|
+
*/
|
|
529
|
+
registerWebhook(webhook) {
|
|
530
|
+
this._definitions.push({
|
|
531
|
+
type: "webhook",
|
|
532
|
+
webhook
|
|
533
|
+
});
|
|
534
|
+
}
|
|
535
|
+
/**
|
|
536
|
+
* Registers a raw OpenAPI component. Use this if you have a simple object instead of a Zod schema.
|
|
537
|
+
*
|
|
538
|
+
* @param type The component type, e.g. `schemas`, `responses`, `securitySchemes`, etc.
|
|
539
|
+
* @param name The name of the object, it is the key under the component
|
|
540
|
+
* type in the resulting OpenAPI document
|
|
541
|
+
* @param component The actual object to put there
|
|
542
|
+
*/
|
|
543
|
+
registerComponent(type, name, component) {
|
|
544
|
+
this._definitions.push({
|
|
545
|
+
type: "component",
|
|
546
|
+
componentType: type,
|
|
547
|
+
name,
|
|
548
|
+
component
|
|
549
|
+
});
|
|
550
|
+
return {
|
|
551
|
+
name,
|
|
552
|
+
ref: { $ref: `#/components/${type}/${name}` }
|
|
553
|
+
};
|
|
554
|
+
}
|
|
555
|
+
schemaWithRefId(refId, zodSchema) {
|
|
556
|
+
return zodSchema.openapi(refId);
|
|
557
|
+
}
|
|
558
|
+
};
|
|
559
|
+
var ZodToOpenAPIError = class {
|
|
560
|
+
constructor(message) {
|
|
561
|
+
this.message = message;
|
|
562
|
+
}
|
|
563
|
+
};
|
|
564
|
+
var ConflictError = class extends ZodToOpenAPIError {
|
|
565
|
+
constructor(message, data) {
|
|
566
|
+
super(message);
|
|
567
|
+
this.data = data;
|
|
568
|
+
}
|
|
569
|
+
};
|
|
570
|
+
var MissingParameterDataError = class extends ZodToOpenAPIError {
|
|
571
|
+
constructor(data) {
|
|
572
|
+
super(`Missing parameter data, please specify \`${data.missingField}\` and other OpenAPI parameter props using the \`param\` field of \`schema.openapi\``);
|
|
573
|
+
this.data = data;
|
|
574
|
+
}
|
|
575
|
+
};
|
|
576
|
+
function enhanceMissingParametersError(action, paramsToAdd) {
|
|
577
|
+
try {
|
|
578
|
+
return action();
|
|
579
|
+
} catch (error2) {
|
|
580
|
+
if (error2 instanceof MissingParameterDataError) {
|
|
581
|
+
throw new MissingParameterDataError(Object.assign(Object.assign({}, error2.data), paramsToAdd));
|
|
582
|
+
}
|
|
583
|
+
throw error2;
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
var UnknownZodTypeError = class extends ZodToOpenAPIError {
|
|
587
|
+
constructor(data) {
|
|
588
|
+
super(`Unknown zod object type, please specify \`type\` and other OpenAPI props using \`schema.openapi\`.`);
|
|
589
|
+
this.data = data;
|
|
590
|
+
}
|
|
591
|
+
};
|
|
592
|
+
var ArrayTransformer = class {
|
|
593
|
+
transform(zodSchema, mapNullableType, mapItems) {
|
|
594
|
+
var _a, _b, _c, _d;
|
|
595
|
+
const itemType = zodSchema.def.element;
|
|
596
|
+
const minItems = (_b = (_a = zodSchema.def.checks) === null || _a === void 0 ? void 0 : _a.find((check) => check._zod.def.check === "min_length")) === null || _b === void 0 ? void 0 : _b._zod.def.minimum;
|
|
597
|
+
const maxItems = (_d = (_c = zodSchema.def.checks) === null || _c === void 0 ? void 0 : _c.find((check) => check._zod.def.check === "max_length")) === null || _d === void 0 ? void 0 : _d._zod.def.maximum;
|
|
598
|
+
return Object.assign(Object.assign({}, mapNullableType("array")), {
|
|
599
|
+
items: isAnyZodType(itemType) ? mapItems(itemType) : {},
|
|
600
|
+
minItems,
|
|
601
|
+
maxItems
|
|
602
|
+
});
|
|
603
|
+
}
|
|
604
|
+
};
|
|
605
|
+
var BigIntTransformer = class {
|
|
606
|
+
transform(mapNullableType) {
|
|
607
|
+
return Object.assign(Object.assign({}, mapNullableType("string")), { pattern: `^\\d+$` });
|
|
608
|
+
}
|
|
609
|
+
};
|
|
610
|
+
var DiscriminatedUnionTransformer = class {
|
|
611
|
+
transform(zodSchema, isNullable, mapNullableOfArray, mapItem, generateSchemaRef) {
|
|
612
|
+
const options = zodSchema.def.options.filter(isAnyZodType);
|
|
613
|
+
const optionSchema = options.map(mapItem);
|
|
614
|
+
if (isNullable) {
|
|
615
|
+
return {
|
|
616
|
+
oneOf: mapNullableOfArray(optionSchema, isNullable)
|
|
617
|
+
};
|
|
618
|
+
}
|
|
619
|
+
const discriminator = zodSchema._zod.def.discriminator;
|
|
620
|
+
if (!discriminator) {
|
|
621
|
+
return {
|
|
622
|
+
oneOf: optionSchema
|
|
623
|
+
};
|
|
624
|
+
}
|
|
625
|
+
return {
|
|
626
|
+
oneOf: optionSchema,
|
|
627
|
+
discriminator: this.mapDiscriminator(options, discriminator, generateSchemaRef)
|
|
628
|
+
};
|
|
629
|
+
}
|
|
630
|
+
mapDiscriminator(schemas, discriminator, generateSchemaRef) {
|
|
631
|
+
if (schemas.some((schema) => Metadata.getRefId(schema) === void 0)) {
|
|
632
|
+
return void 0;
|
|
633
|
+
}
|
|
634
|
+
const mapping = {};
|
|
635
|
+
for (const schema of schemas) {
|
|
636
|
+
const refId = Metadata.getRefId(schema);
|
|
637
|
+
const values = this.getDiscriminatorValues(schema, discriminator);
|
|
638
|
+
for (const value of values) {
|
|
639
|
+
mapping[value] = generateSchemaRef(refId);
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
return {
|
|
643
|
+
propertyName: discriminator,
|
|
644
|
+
mapping
|
|
645
|
+
};
|
|
646
|
+
}
|
|
647
|
+
getDiscriminatorValues(schema, discriminator) {
|
|
648
|
+
var _a;
|
|
649
|
+
if (isZodType(schema, "ZodObject")) {
|
|
650
|
+
const value = (_a = schema.def.shape) === null || _a === void 0 ? void 0 : _a[discriminator];
|
|
651
|
+
if (!value) {
|
|
652
|
+
return [];
|
|
653
|
+
}
|
|
654
|
+
if (isZodType(value, "ZodEnum")) {
|
|
655
|
+
return Object.values(value._zod.def.entries).filter(isString);
|
|
656
|
+
}
|
|
657
|
+
if (isZodType(value, "ZodLiteral")) {
|
|
658
|
+
return value.def.values.filter(isString);
|
|
659
|
+
}
|
|
660
|
+
return [];
|
|
661
|
+
}
|
|
662
|
+
if (isZodType(schema, "ZodDiscriminatedUnion")) {
|
|
663
|
+
const nestedOptions = schema.def.options.filter(isAnyZodType);
|
|
664
|
+
return [
|
|
665
|
+
...new Set(nestedOptions.flatMap((option) => this.getDiscriminatorValues(option, discriminator)))
|
|
666
|
+
];
|
|
667
|
+
}
|
|
668
|
+
return [];
|
|
669
|
+
}
|
|
670
|
+
};
|
|
671
|
+
function enumInfo(enumObject) {
|
|
672
|
+
const keysExceptReverseMappings = Object.keys(enumObject).filter((key) => typeof enumObject[enumObject[key]] !== "number");
|
|
673
|
+
const values = keysExceptReverseMappings.map((key) => enumObject[key]);
|
|
674
|
+
const numericCount = values.filter((_) => typeof _ === "number").length;
|
|
675
|
+
const type = numericCount === 0 ? "string" : numericCount === values.length ? "numeric" : "mixed";
|
|
676
|
+
return { values, type };
|
|
677
|
+
}
|
|
678
|
+
var EnumTransformer = class {
|
|
679
|
+
transform(zodSchema, isNullable, mapNullableType) {
|
|
680
|
+
const { type, values } = enumInfo(zodSchema._zod.def.entries);
|
|
681
|
+
if (type === "mixed") {
|
|
682
|
+
throw new ZodToOpenAPIError("Enum has mixed string and number values, please specify the OpenAPI type manually");
|
|
683
|
+
}
|
|
684
|
+
return Object.assign(Object.assign({}, mapNullableType(type === "numeric" ? "integer" : "string")), { enum: isNullable ? [...values, null] : values });
|
|
685
|
+
}
|
|
686
|
+
};
|
|
687
|
+
var IntersectionTransformer = class {
|
|
688
|
+
transform(zodSchema, isNullable, mapNullableOfArray, mapItem) {
|
|
689
|
+
const subtypes = this.flattenIntersectionTypes(zodSchema);
|
|
690
|
+
const allOfSchema = {
|
|
691
|
+
allOf: subtypes.map(mapItem)
|
|
692
|
+
};
|
|
693
|
+
if (isNullable) {
|
|
694
|
+
return {
|
|
695
|
+
anyOf: mapNullableOfArray([allOfSchema], isNullable)
|
|
696
|
+
};
|
|
697
|
+
}
|
|
698
|
+
return allOfSchema;
|
|
699
|
+
}
|
|
700
|
+
flattenIntersectionTypes(schema) {
|
|
701
|
+
if (!isZodType(schema, "ZodIntersection")) {
|
|
702
|
+
return [schema];
|
|
703
|
+
}
|
|
704
|
+
const leftSubTypes = isAnyZodType(schema._zod.def.left) ? this.flattenIntersectionTypes(schema._zod.def.left) : [];
|
|
705
|
+
const rightSubTypes = isAnyZodType(schema._zod.def.right) ? this.flattenIntersectionTypes(schema._zod.def.right) : [];
|
|
706
|
+
return [...leftSubTypes, ...rightSubTypes];
|
|
707
|
+
}
|
|
708
|
+
};
|
|
709
|
+
var LiteralTransformer = class {
|
|
710
|
+
constructor() {
|
|
711
|
+
this.bigIntTransformer = new BigIntTransformer();
|
|
712
|
+
}
|
|
713
|
+
transform(zodSchema, mapNullableType) {
|
|
714
|
+
const type = typeof zodSchema.def.values[0];
|
|
715
|
+
if (type === "boolean" || type === "number" || type === "string" || type === "object") {
|
|
716
|
+
return Object.assign(Object.assign({}, mapNullableType(type)), { enum: [zodSchema.def.values[0]] });
|
|
717
|
+
}
|
|
718
|
+
if (type === "bigint") {
|
|
719
|
+
return this.bigIntTransformer.transform(mapNullableType);
|
|
720
|
+
}
|
|
721
|
+
return mapNullableType("null");
|
|
722
|
+
}
|
|
723
|
+
};
|
|
724
|
+
var NumberTransformer = class {
|
|
725
|
+
transform(zodSchema, mapNullableType, getNumberChecks) {
|
|
726
|
+
var _a;
|
|
727
|
+
return Object.assign(Object.assign(Object.assign({}, mapNullableType("number")), mapNullableType(zodSchema.format === "safeint" ? "integer" : "number")), getNumberChecks((_a = zodSchema.def.checks) !== null && _a !== void 0 ? _a : []));
|
|
728
|
+
}
|
|
729
|
+
};
|
|
730
|
+
var ObjectTransformer = class {
|
|
731
|
+
transform(zodSchema, defaultValue, mapNullableType, mapItem) {
|
|
732
|
+
var _a;
|
|
733
|
+
const extendedFrom = (_a = Metadata.getInternalMetadata(zodSchema)) === null || _a === void 0 ? void 0 : _a.extendedFrom;
|
|
734
|
+
const required = this.requiredKeysOf(zodSchema);
|
|
735
|
+
const properties = mapValues(zodSchema.def.shape, mapItem);
|
|
736
|
+
if (!extendedFrom) {
|
|
737
|
+
return Object.assign(Object.assign(Object.assign(Object.assign({}, mapNullableType("object")), { properties, default: defaultValue }), required.length > 0 ? { required } : {}), this.generateAdditionalProperties(zodSchema, mapItem));
|
|
738
|
+
}
|
|
739
|
+
const parent = extendedFrom.schema;
|
|
740
|
+
mapItem(parent);
|
|
741
|
+
const keysRequiredByParent = this.requiredKeysOf(parent);
|
|
742
|
+
const propsOfParent = mapValues(parent === null || parent === void 0 ? void 0 : parent.def.shape, mapItem);
|
|
743
|
+
const propertiesToAdd = Object.fromEntries(Object.entries(properties).filter(([key, type]) => {
|
|
744
|
+
return !objectEquals(propsOfParent[key], type);
|
|
745
|
+
}));
|
|
746
|
+
const additionallyRequired = required.filter((prop) => !keysRequiredByParent.includes(prop));
|
|
747
|
+
const objectData = Object.assign(Object.assign(Object.assign(Object.assign({}, mapNullableType("object")), { default: defaultValue, properties: propertiesToAdd }), additionallyRequired.length > 0 ? { required: additionallyRequired } : {}), this.generateAdditionalProperties(zodSchema, mapItem));
|
|
748
|
+
return {
|
|
749
|
+
allOf: [
|
|
750
|
+
{ $ref: `#/components/schemas/${extendedFrom.refId}` },
|
|
751
|
+
objectData
|
|
752
|
+
]
|
|
753
|
+
};
|
|
754
|
+
}
|
|
755
|
+
generateAdditionalProperties(zodSchema, mapItem) {
|
|
756
|
+
const catchallSchema = zodSchema.def.catchall;
|
|
757
|
+
if (!catchallSchema) {
|
|
758
|
+
return {};
|
|
759
|
+
}
|
|
760
|
+
if (isZodType(catchallSchema, "ZodNever")) {
|
|
761
|
+
return { additionalProperties: false };
|
|
762
|
+
}
|
|
763
|
+
if (isAnyZodType(catchallSchema)) {
|
|
764
|
+
return { additionalProperties: mapItem(catchallSchema) };
|
|
765
|
+
}
|
|
766
|
+
return {};
|
|
767
|
+
}
|
|
768
|
+
requiredKeysOf(objectSchema) {
|
|
769
|
+
return Object.entries(objectSchema.def.shape).filter(([_key, type]) => !isOptionalSchema(type)).map(([key, _type]) => key);
|
|
770
|
+
}
|
|
771
|
+
};
|
|
772
|
+
var RecordTransformer = class {
|
|
773
|
+
transform(zodSchema, mapNullableType, mapItem) {
|
|
774
|
+
const propertiesType = zodSchema.valueType;
|
|
775
|
+
const keyType = zodSchema.keyType;
|
|
776
|
+
const propertiesSchema = isAnyZodType(propertiesType) ? mapItem(propertiesType) : {};
|
|
777
|
+
if (isZodType(keyType, "ZodEnum")) {
|
|
778
|
+
const keys = Object.values(keyType._zod.def.entries).filter(isString);
|
|
779
|
+
const properties = keys.reduce((acc, curr) => Object.assign(Object.assign({}, acc), { [curr]: propertiesSchema }), {});
|
|
780
|
+
return Object.assign(Object.assign({}, mapNullableType("object")), { properties });
|
|
781
|
+
}
|
|
782
|
+
return Object.assign(Object.assign({}, mapNullableType("object")), { additionalProperties: propertiesSchema });
|
|
783
|
+
}
|
|
784
|
+
};
|
|
785
|
+
function isZodCheckLengthEquals(check) {
|
|
786
|
+
return check._zod.def.check === "length_equals";
|
|
787
|
+
}
|
|
788
|
+
function isZodCheckRegex(check) {
|
|
789
|
+
return check._zod.def.check === "string_format" && check._zod.def.format === "regex";
|
|
790
|
+
}
|
|
791
|
+
var StringTransformer = class {
|
|
792
|
+
transform(zodSchema, mapNullableType) {
|
|
793
|
+
var _a, _b, _c, _d;
|
|
794
|
+
const regexCheck = (_a = zodSchema.def.checks) === null || _a === void 0 ? void 0 : _a.find(isZodCheckRegex);
|
|
795
|
+
const pattern = regexCheck === null || regexCheck === void 0 ? void 0 : regexCheck._zod.def.pattern.toString().replace(/^\/|\/$/g, "");
|
|
796
|
+
const check = (_b = zodSchema.def.checks) === null || _b === void 0 ? void 0 : _b.find(isZodCheckLengthEquals);
|
|
797
|
+
const length = check === null || check === void 0 ? void 0 : check._zod.def.length;
|
|
798
|
+
const maxLength = Number.isFinite(zodSchema.minLength) ? (_c = zodSchema.minLength) !== null && _c !== void 0 ? _c : void 0 : void 0;
|
|
799
|
+
const minLength = Number.isFinite(zodSchema.maxLength) ? (_d = zodSchema.maxLength) !== null && _d !== void 0 ? _d : void 0 : void 0;
|
|
800
|
+
return Object.assign(Object.assign({}, mapNullableType("string")), {
|
|
801
|
+
// FIXME: https://github.com/colinhacks/zod/commit/d78047e9f44596a96d637abb0ce209cd2732d88c
|
|
802
|
+
minLength: length !== null && length !== void 0 ? length : maxLength,
|
|
803
|
+
maxLength: length !== null && length !== void 0 ? length : minLength,
|
|
804
|
+
format: this.mapStringFormat(zodSchema),
|
|
805
|
+
pattern
|
|
806
|
+
});
|
|
807
|
+
}
|
|
808
|
+
/**
|
|
809
|
+
* Attempts to map Zod strings to known formats
|
|
810
|
+
* https://json-schema.org/understanding-json-schema/reference/string.html#built-in-formats
|
|
811
|
+
* New mappings should use values from the OpenAPI format registry:
|
|
812
|
+
* https://spec.openapis.org/registry/format/
|
|
813
|
+
*/
|
|
814
|
+
mapStringFormat(zodString) {
|
|
815
|
+
if (zodString.format === "uuid")
|
|
816
|
+
return "uuid";
|
|
817
|
+
if (zodString.format === "guid")
|
|
818
|
+
return "uuid";
|
|
819
|
+
if (zodString.format === "email")
|
|
820
|
+
return "email";
|
|
821
|
+
if (zodString.format === "url")
|
|
822
|
+
return "uri";
|
|
823
|
+
if (zodString.format === "date")
|
|
824
|
+
return "date";
|
|
825
|
+
if (zodString.format === "datetime")
|
|
826
|
+
return "date-time";
|
|
827
|
+
if (zodString.format === "time")
|
|
828
|
+
return "time";
|
|
829
|
+
if (zodString.format === "duration")
|
|
830
|
+
return "duration";
|
|
831
|
+
if (zodString.format === "cuid")
|
|
832
|
+
return "cuid";
|
|
833
|
+
if (zodString.format === "cuid2")
|
|
834
|
+
return "cuid2";
|
|
835
|
+
if (zodString.format === "ulid")
|
|
836
|
+
return "ulid";
|
|
837
|
+
if (zodString.format === "ipv4")
|
|
838
|
+
return "ip";
|
|
839
|
+
if (zodString.format === "ipv6")
|
|
840
|
+
return "ip";
|
|
841
|
+
if (zodString.format === "cidrv4")
|
|
842
|
+
return "ipv4-cidr";
|
|
843
|
+
if (zodString.format === "cidrv6")
|
|
844
|
+
return "ipv6-cidr";
|
|
845
|
+
if (zodString.format === "base64url")
|
|
846
|
+
return "base64url";
|
|
847
|
+
if (zodString.format === "emoji")
|
|
848
|
+
return "emoji";
|
|
849
|
+
return void 0;
|
|
850
|
+
}
|
|
851
|
+
};
|
|
852
|
+
var TupleTransformer = class {
|
|
853
|
+
constructor(versionSpecifics) {
|
|
854
|
+
this.versionSpecifics = versionSpecifics;
|
|
855
|
+
}
|
|
856
|
+
transform(zodSchema, mapNullableType, mapItem) {
|
|
857
|
+
const items = zodSchema._zod.def.items;
|
|
858
|
+
const schemas = items.map((item) => isAnyZodType(item) ? mapItem(item) : {});
|
|
859
|
+
return Object.assign(Object.assign({}, mapNullableType("array")), this.versionSpecifics.mapTupleItems(schemas));
|
|
860
|
+
}
|
|
861
|
+
};
|
|
862
|
+
var UnionTransformer = class {
|
|
863
|
+
constructor(options) {
|
|
864
|
+
this.options = options;
|
|
865
|
+
}
|
|
866
|
+
transform(zodSchema, mapNullableOfArray, mapItem) {
|
|
867
|
+
var _a, _b, _c;
|
|
868
|
+
const internalMetadata = Metadata.getInternalMetadata(zodSchema);
|
|
869
|
+
const preferredType = (_c = (_a = internalMetadata === null || internalMetadata === void 0 ? void 0 : internalMetadata.unionPreferredType) !== null && _a !== void 0 ? _a : (_b = this.options) === null || _b === void 0 ? void 0 : _b.unionPreferredType) !== null && _c !== void 0 ? _c : "anyOf";
|
|
870
|
+
const options = this.flattenUnionTypes(zodSchema);
|
|
871
|
+
const schemas = options.map((schema) => {
|
|
872
|
+
const optionToGenerate = this.unwrapNullable(schema);
|
|
873
|
+
return mapItem(optionToGenerate);
|
|
874
|
+
});
|
|
875
|
+
return {
|
|
876
|
+
[preferredType]: mapNullableOfArray(schemas)
|
|
877
|
+
};
|
|
878
|
+
}
|
|
879
|
+
flattenUnionTypes(schema) {
|
|
880
|
+
if (!isZodType(schema, "ZodUnion")) {
|
|
881
|
+
return [schema];
|
|
882
|
+
}
|
|
883
|
+
const options = schema.def.options;
|
|
884
|
+
return options.flatMap((option) => isAnyZodType(option) ? this.flattenUnionTypes(option) : []);
|
|
885
|
+
}
|
|
886
|
+
unwrapNullable(schema) {
|
|
887
|
+
if (isZodType(schema, "ZodNullable")) {
|
|
888
|
+
const unwrapped = schema.unwrap();
|
|
889
|
+
if (isAnyZodType(unwrapped)) {
|
|
890
|
+
return this.unwrapNullable(unwrapped);
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
return schema;
|
|
894
|
+
}
|
|
895
|
+
};
|
|
896
|
+
var DateTransformer = class {
|
|
897
|
+
transform(mapNullableType) {
|
|
898
|
+
return Object.assign(Object.assign({}, mapNullableType("string")), { format: "date-time" });
|
|
899
|
+
}
|
|
900
|
+
};
|
|
901
|
+
var LazyTransformer = class _LazyTransformer {
|
|
902
|
+
transform(zodSchema, mapItem, mapNullableType, mapNullableRef) {
|
|
903
|
+
const result = mapItem(zodSchema._zod.def.getter());
|
|
904
|
+
return _LazyTransformer.mapRecursive(result, mapNullableType, mapNullableRef);
|
|
905
|
+
}
|
|
906
|
+
static mapRecursive(schema, mapNullableType, mapNullableRef) {
|
|
907
|
+
if ("$ref" in schema) {
|
|
908
|
+
return mapNullableRef(schema);
|
|
909
|
+
}
|
|
910
|
+
if (schema.type) {
|
|
911
|
+
return Object.assign(Object.assign({}, schema), mapNullableType(schema.type));
|
|
912
|
+
}
|
|
913
|
+
return schema;
|
|
914
|
+
}
|
|
915
|
+
};
|
|
916
|
+
var TemplateLiteralTransformer = class {
|
|
917
|
+
transform(zodSchema, mapNullableType) {
|
|
918
|
+
const parts = zodSchema.def.parts;
|
|
919
|
+
const contentPattern = parts.map((part) => this.generatePattern(part)).join("");
|
|
920
|
+
return Object.assign(Object.assign({}, mapNullableType("string")), { pattern: `^${contentPattern}$` });
|
|
921
|
+
}
|
|
922
|
+
generatePattern(part) {
|
|
923
|
+
if (typeof part === "string" || typeof part === "number" || typeof part === "boolean" || typeof part === "bigint" || part === null || part === void 0) {
|
|
924
|
+
return this.escapeRegex(String(part));
|
|
925
|
+
}
|
|
926
|
+
if (isZodType(part, "ZodLiteral")) {
|
|
927
|
+
const value = part.def.values[0];
|
|
928
|
+
return this.escapeRegex(String(value));
|
|
929
|
+
}
|
|
930
|
+
if (isZodType(part, "ZodNumber")) {
|
|
931
|
+
return "[+-]?\\d+(\\.\\d+)?";
|
|
932
|
+
}
|
|
933
|
+
if (isZodType(part, "ZodBoolean")) {
|
|
934
|
+
return "(true|false)";
|
|
935
|
+
}
|
|
936
|
+
if (isZodType(part, "ZodEnum")) {
|
|
937
|
+
const { values } = enumInfo(part.def.entries);
|
|
938
|
+
return `(${values.map((v) => this.escapeRegex(String(v))).join("|")})`;
|
|
939
|
+
}
|
|
940
|
+
return ".*";
|
|
941
|
+
}
|
|
942
|
+
escapeRegex(str) {
|
|
943
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
944
|
+
}
|
|
945
|
+
};
|
|
946
|
+
var OpenApiTransformer = class {
|
|
947
|
+
constructor(versionSpecifics, options) {
|
|
948
|
+
this.versionSpecifics = versionSpecifics;
|
|
949
|
+
this.objectTransformer = new ObjectTransformer();
|
|
950
|
+
this.stringTransformer = new StringTransformer();
|
|
951
|
+
this.numberTransformer = new NumberTransformer();
|
|
952
|
+
this.bigIntTransformer = new BigIntTransformer();
|
|
953
|
+
this.dateTransformer = new DateTransformer();
|
|
954
|
+
this.lazyTransformer = new LazyTransformer();
|
|
955
|
+
this.literalTransformer = new LiteralTransformer();
|
|
956
|
+
this.templateLiteralTransformer = new TemplateLiteralTransformer();
|
|
957
|
+
this.enumTransformer = new EnumTransformer();
|
|
958
|
+
this.arrayTransformer = new ArrayTransformer();
|
|
959
|
+
this.discriminatedUnionTransformer = new DiscriminatedUnionTransformer();
|
|
960
|
+
this.intersectionTransformer = new IntersectionTransformer();
|
|
961
|
+
this.recordTransformer = new RecordTransformer();
|
|
962
|
+
this.tupleTransformer = new TupleTransformer(versionSpecifics);
|
|
963
|
+
this.unionTransformer = new UnionTransformer(options);
|
|
964
|
+
}
|
|
965
|
+
transform(zodSchema, isNullable, mapItem, generateSchemaRef, defaultValue) {
|
|
966
|
+
if (isZodType(zodSchema, "ZodNull")) {
|
|
967
|
+
return this.versionSpecifics.nullType;
|
|
968
|
+
}
|
|
969
|
+
if (isZodType(zodSchema, "ZodUnknown") || isZodType(zodSchema, "ZodAny")) {
|
|
970
|
+
return this.versionSpecifics.mapNullableType(void 0, isNullable);
|
|
971
|
+
}
|
|
972
|
+
if (isZodType(zodSchema, "ZodObject")) {
|
|
973
|
+
return this.objectTransformer.transform(
|
|
974
|
+
zodSchema,
|
|
975
|
+
defaultValue,
|
|
976
|
+
// verified on TS level from input
|
|
977
|
+
// verified on TS level from input
|
|
978
|
+
(_) => this.versionSpecifics.mapNullableType(_, isNullable),
|
|
979
|
+
mapItem
|
|
980
|
+
);
|
|
981
|
+
}
|
|
982
|
+
const schema = this.transformSchemaWithoutDefault(zodSchema, isNullable, mapItem, generateSchemaRef);
|
|
983
|
+
return Object.assign(Object.assign({}, schema), { default: defaultValue });
|
|
984
|
+
}
|
|
985
|
+
transformSchemaWithoutDefault(zodSchema, isNullable, mapItem, generateSchemaRef) {
|
|
986
|
+
if (isZodType(zodSchema, "ZodUnknown") || isZodType(zodSchema, "ZodAny")) {
|
|
987
|
+
return this.versionSpecifics.mapNullableType(void 0, isNullable);
|
|
988
|
+
}
|
|
989
|
+
if (isZodType(zodSchema, "ZodString")) {
|
|
990
|
+
return this.stringTransformer.transform(zodSchema, (schema) => this.versionSpecifics.mapNullableType(schema, isNullable));
|
|
991
|
+
}
|
|
992
|
+
if (isZodType(zodSchema, "ZodNumber")) {
|
|
993
|
+
return this.numberTransformer.transform(zodSchema, (schema) => this.versionSpecifics.mapNullableType(schema, isNullable), (_) => this.versionSpecifics.getNumberChecks(_));
|
|
994
|
+
}
|
|
995
|
+
if (isZodType(zodSchema, "ZodBigInt")) {
|
|
996
|
+
return this.bigIntTransformer.transform((schema) => this.versionSpecifics.mapNullableType(schema, isNullable));
|
|
997
|
+
}
|
|
998
|
+
if (isZodType(zodSchema, "ZodBoolean")) {
|
|
999
|
+
return this.versionSpecifics.mapNullableType("boolean", isNullable);
|
|
1000
|
+
}
|
|
1001
|
+
if (isZodType(zodSchema, "ZodLazy")) {
|
|
1002
|
+
return this.lazyTransformer.transform(zodSchema, mapItem, (schema) => this.versionSpecifics.mapNullableType(schema, isNullable), (schema) => this.versionSpecifics.mapNullableOfRef(schema, isNullable));
|
|
1003
|
+
}
|
|
1004
|
+
if (isZodType(zodSchema, "ZodLiteral")) {
|
|
1005
|
+
return this.literalTransformer.transform(zodSchema, (schema) => this.versionSpecifics.mapNullableType(schema, isNullable));
|
|
1006
|
+
}
|
|
1007
|
+
if (isZodType(zodSchema, "ZodTemplateLiteral")) {
|
|
1008
|
+
return this.templateLiteralTransformer.transform(zodSchema, (schema) => this.versionSpecifics.mapNullableType(schema, isNullable));
|
|
1009
|
+
}
|
|
1010
|
+
if (isZodType(zodSchema, "ZodEnum")) {
|
|
1011
|
+
return this.enumTransformer.transform(zodSchema, isNullable, (schema) => this.versionSpecifics.mapNullableType(schema, isNullable));
|
|
1012
|
+
}
|
|
1013
|
+
if (isZodType(zodSchema, "ZodArray")) {
|
|
1014
|
+
return this.arrayTransformer.transform(zodSchema, (_) => this.versionSpecifics.mapNullableType(_, isNullable), mapItem);
|
|
1015
|
+
}
|
|
1016
|
+
if (isZodType(zodSchema, "ZodTuple")) {
|
|
1017
|
+
return this.tupleTransformer.transform(zodSchema, (_) => this.versionSpecifics.mapNullableType(_, isNullable), mapItem);
|
|
1018
|
+
}
|
|
1019
|
+
if (isZodType(zodSchema, "ZodDiscriminatedUnion")) {
|
|
1020
|
+
return this.discriminatedUnionTransformer.transform(zodSchema, isNullable, (_) => this.versionSpecifics.mapNullableOfArray(_, isNullable), mapItem, generateSchemaRef);
|
|
1021
|
+
}
|
|
1022
|
+
if (isZodType(zodSchema, "ZodUnion")) {
|
|
1023
|
+
return this.unionTransformer.transform(zodSchema, (_) => this.versionSpecifics.mapNullableOfArray(_, isNullable), mapItem);
|
|
1024
|
+
}
|
|
1025
|
+
if (isZodType(zodSchema, "ZodIntersection")) {
|
|
1026
|
+
return this.intersectionTransformer.transform(zodSchema, isNullable, (_) => this.versionSpecifics.mapNullableOfArray(_, isNullable), mapItem);
|
|
1027
|
+
}
|
|
1028
|
+
if (isZodType(zodSchema, "ZodRecord")) {
|
|
1029
|
+
return this.recordTransformer.transform(zodSchema, (_) => this.versionSpecifics.mapNullableType(_, isNullable), mapItem);
|
|
1030
|
+
}
|
|
1031
|
+
if (isZodType(zodSchema, "ZodDate")) {
|
|
1032
|
+
return this.dateTransformer.transform((_) => this.versionSpecifics.mapNullableType(_, isNullable));
|
|
1033
|
+
}
|
|
1034
|
+
const refId = Metadata.getRefId(zodSchema);
|
|
1035
|
+
throw new UnknownZodTypeError({
|
|
1036
|
+
currentSchema: zodSchema.def,
|
|
1037
|
+
schemaName: refId
|
|
1038
|
+
});
|
|
1039
|
+
}
|
|
1040
|
+
};
|
|
1041
|
+
var OpenAPIGenerator = class {
|
|
1042
|
+
constructor(definitions, versionSpecifics, options) {
|
|
1043
|
+
this.definitions = definitions;
|
|
1044
|
+
this.versionSpecifics = versionSpecifics;
|
|
1045
|
+
this.options = options;
|
|
1046
|
+
this.schemaRefs = {};
|
|
1047
|
+
this.paramRefs = {};
|
|
1048
|
+
this.pathRefs = {};
|
|
1049
|
+
this.rawComponents = [];
|
|
1050
|
+
this.openApiTransformer = new OpenApiTransformer(versionSpecifics, options);
|
|
1051
|
+
this.sortDefinitions();
|
|
1052
|
+
}
|
|
1053
|
+
generateDocumentData() {
|
|
1054
|
+
this.definitions.forEach((definition) => this.generateSingle(definition));
|
|
1055
|
+
return {
|
|
1056
|
+
components: this.buildComponents(),
|
|
1057
|
+
paths: this.pathRefs
|
|
1058
|
+
};
|
|
1059
|
+
}
|
|
1060
|
+
generateComponents() {
|
|
1061
|
+
this.definitions.forEach((definition) => this.generateSingle(definition));
|
|
1062
|
+
return {
|
|
1063
|
+
components: this.buildComponents()
|
|
1064
|
+
};
|
|
1065
|
+
}
|
|
1066
|
+
buildComponents() {
|
|
1067
|
+
var _a, _b, _c, _d;
|
|
1068
|
+
const rawComponents = {};
|
|
1069
|
+
this.rawComponents.forEach(({ componentType, name, component }) => {
|
|
1070
|
+
var _a2;
|
|
1071
|
+
(_a2 = rawComponents[componentType]) !== null && _a2 !== void 0 ? _a2 : rawComponents[componentType] = {};
|
|
1072
|
+
rawComponents[componentType][name] = component;
|
|
1073
|
+
});
|
|
1074
|
+
const rawSchemas = (_a = rawComponents["schemas"]) !== null && _a !== void 0 ? _a : {};
|
|
1075
|
+
const allSchemas = Object.assign(Object.assign({}, rawSchemas), this.filteredSchemaRefs);
|
|
1076
|
+
const schemas = ((_b = this.options) === null || _b === void 0 ? void 0 : _b.sortComponents) === "alphabetically" ? sortObjectByKeys(allSchemas) : allSchemas;
|
|
1077
|
+
const rawParameters = (_c = rawComponents["parameters"]) !== null && _c !== void 0 ? _c : {};
|
|
1078
|
+
const allParameters = Object.assign(Object.assign({}, rawParameters), this.paramRefs);
|
|
1079
|
+
const parameters = ((_d = this.options) === null || _d === void 0 ? void 0 : _d.sortComponents) === "alphabetically" ? sortObjectByKeys(allParameters) : allParameters;
|
|
1080
|
+
return Object.assign(Object.assign({}, rawComponents), { schemas, parameters });
|
|
1081
|
+
}
|
|
1082
|
+
isNotPendingRefEntry(entry) {
|
|
1083
|
+
return entry[1] !== "pending";
|
|
1084
|
+
}
|
|
1085
|
+
get filteredSchemaRefs() {
|
|
1086
|
+
const filtered = Object.entries(this.schemaRefs).filter(this.isNotPendingRefEntry);
|
|
1087
|
+
return Object.fromEntries(filtered);
|
|
1088
|
+
}
|
|
1089
|
+
sortDefinitions() {
|
|
1090
|
+
const generationOrder = [
|
|
1091
|
+
"schema",
|
|
1092
|
+
"parameter",
|
|
1093
|
+
"component",
|
|
1094
|
+
"route",
|
|
1095
|
+
"webhook"
|
|
1096
|
+
];
|
|
1097
|
+
this.definitions.sort((left, right) => {
|
|
1098
|
+
if (!("type" in left)) {
|
|
1099
|
+
if (!("type" in right)) {
|
|
1100
|
+
return 0;
|
|
1101
|
+
}
|
|
1102
|
+
return -1;
|
|
1103
|
+
}
|
|
1104
|
+
if (!("type" in right)) {
|
|
1105
|
+
return 1;
|
|
1106
|
+
}
|
|
1107
|
+
const leftIndex = generationOrder.findIndex((type) => type === left.type);
|
|
1108
|
+
const rightIndex = generationOrder.findIndex((type) => type === right.type);
|
|
1109
|
+
return leftIndex - rightIndex;
|
|
1110
|
+
});
|
|
1111
|
+
}
|
|
1112
|
+
generateSingle(definition) {
|
|
1113
|
+
if (!("type" in definition)) {
|
|
1114
|
+
this.generateSchemaWithRef(definition);
|
|
1115
|
+
return;
|
|
1116
|
+
}
|
|
1117
|
+
switch (definition.type) {
|
|
1118
|
+
case "parameter":
|
|
1119
|
+
this.generateParameterDefinition(definition.schema);
|
|
1120
|
+
return;
|
|
1121
|
+
case "schema":
|
|
1122
|
+
this.generateSchemaWithRef(definition.schema);
|
|
1123
|
+
return;
|
|
1124
|
+
case "route":
|
|
1125
|
+
this.generateSingleRoute(definition.route);
|
|
1126
|
+
return;
|
|
1127
|
+
case "component":
|
|
1128
|
+
this.rawComponents.push(definition);
|
|
1129
|
+
return;
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
generateParameterDefinition(zodSchema) {
|
|
1133
|
+
const refId = Metadata.getRefId(zodSchema);
|
|
1134
|
+
const result = this.generateParameter(zodSchema);
|
|
1135
|
+
if (refId) {
|
|
1136
|
+
this.paramRefs[refId] = result;
|
|
1137
|
+
}
|
|
1138
|
+
return result;
|
|
1139
|
+
}
|
|
1140
|
+
getParameterRef(schema, external) {
|
|
1141
|
+
const metadata2 = Metadata.getOpenApiMetadata(schema);
|
|
1142
|
+
const internalMetadata = Metadata.getInternalMetadata(schema);
|
|
1143
|
+
const parameterMetadata = metadata2 === null || metadata2 === void 0 ? void 0 : metadata2.param;
|
|
1144
|
+
const existingRef = (internalMetadata === null || internalMetadata === void 0 ? void 0 : internalMetadata.refId) ? this.paramRefs[internalMetadata.refId] : void 0;
|
|
1145
|
+
if (!(internalMetadata === null || internalMetadata === void 0 ? void 0 : internalMetadata.refId) || !existingRef) {
|
|
1146
|
+
return void 0;
|
|
1147
|
+
}
|
|
1148
|
+
if (parameterMetadata && existingRef.in !== parameterMetadata.in || (external === null || external === void 0 ? void 0 : external.in) && existingRef.in !== external.in) {
|
|
1149
|
+
throw new ConflictError(`Conflicting location for parameter ${existingRef.name}`, {
|
|
1150
|
+
key: "in",
|
|
1151
|
+
values: compact([
|
|
1152
|
+
existingRef.in,
|
|
1153
|
+
external === null || external === void 0 ? void 0 : external.in,
|
|
1154
|
+
parameterMetadata === null || parameterMetadata === void 0 ? void 0 : parameterMetadata.in
|
|
1155
|
+
])
|
|
1156
|
+
});
|
|
1157
|
+
}
|
|
1158
|
+
if (parameterMetadata && existingRef.name !== parameterMetadata.name || (external === null || external === void 0 ? void 0 : external.name) && existingRef.name !== (external === null || external === void 0 ? void 0 : external.name)) {
|
|
1159
|
+
throw new ConflictError(`Conflicting names for parameter`, {
|
|
1160
|
+
key: "name",
|
|
1161
|
+
values: compact([
|
|
1162
|
+
existingRef.name,
|
|
1163
|
+
external === null || external === void 0 ? void 0 : external.name,
|
|
1164
|
+
parameterMetadata === null || parameterMetadata === void 0 ? void 0 : parameterMetadata.name
|
|
1165
|
+
])
|
|
1166
|
+
});
|
|
1167
|
+
}
|
|
1168
|
+
return {
|
|
1169
|
+
$ref: `#/components/parameters/${internalMetadata.refId}`
|
|
1170
|
+
};
|
|
1171
|
+
}
|
|
1172
|
+
generateInlineParameters(zodSchema, location) {
|
|
1173
|
+
const metadata2 = Metadata.getOpenApiMetadata(zodSchema);
|
|
1174
|
+
const parameterMetadata = metadata2 === null || metadata2 === void 0 ? void 0 : metadata2.param;
|
|
1175
|
+
const referencedSchema = this.getParameterRef(zodSchema, { in: location });
|
|
1176
|
+
if (referencedSchema) {
|
|
1177
|
+
return [referencedSchema];
|
|
1178
|
+
}
|
|
1179
|
+
if (isZodType(zodSchema, "ZodObject")) {
|
|
1180
|
+
const propTypes = zodSchema.def.shape;
|
|
1181
|
+
const parameters = Object.entries(propTypes).map(([key, schema]) => {
|
|
1182
|
+
var _a;
|
|
1183
|
+
const innerMetadata = Metadata.getOpenApiMetadata(schema);
|
|
1184
|
+
const referencedSchema2 = this.getParameterRef(schema, {
|
|
1185
|
+
in: location,
|
|
1186
|
+
name: key
|
|
1187
|
+
});
|
|
1188
|
+
if (referencedSchema2) {
|
|
1189
|
+
return referencedSchema2;
|
|
1190
|
+
}
|
|
1191
|
+
const innerParameterMetadata = innerMetadata === null || innerMetadata === void 0 ? void 0 : innerMetadata.param;
|
|
1192
|
+
if ((innerParameterMetadata === null || innerParameterMetadata === void 0 ? void 0 : innerParameterMetadata.name) && innerParameterMetadata.name !== key) {
|
|
1193
|
+
throw new ConflictError(`Conflicting names for parameter`, {
|
|
1194
|
+
key: "name",
|
|
1195
|
+
values: [key, innerParameterMetadata.name]
|
|
1196
|
+
});
|
|
1197
|
+
}
|
|
1198
|
+
if ((innerParameterMetadata === null || innerParameterMetadata === void 0 ? void 0 : innerParameterMetadata.in) && innerParameterMetadata.in !== location) {
|
|
1199
|
+
throw new ConflictError(`Conflicting location for parameter ${(_a = innerParameterMetadata.name) !== null && _a !== void 0 ? _a : key}`, {
|
|
1200
|
+
key: "in",
|
|
1201
|
+
values: [location, innerParameterMetadata.in]
|
|
1202
|
+
});
|
|
1203
|
+
}
|
|
1204
|
+
return this.generateParameter(schema, { name: key, in: location });
|
|
1205
|
+
});
|
|
1206
|
+
return parameters;
|
|
1207
|
+
}
|
|
1208
|
+
if ((parameterMetadata === null || parameterMetadata === void 0 ? void 0 : parameterMetadata.in) && parameterMetadata.in !== location) {
|
|
1209
|
+
throw new ConflictError(`Conflicting location for parameter ${parameterMetadata.name}`, {
|
|
1210
|
+
key: "in",
|
|
1211
|
+
values: [location, parameterMetadata.in]
|
|
1212
|
+
});
|
|
1213
|
+
}
|
|
1214
|
+
return [this.generateParameter(zodSchema, { in: location })];
|
|
1215
|
+
}
|
|
1216
|
+
generateSimpleParameter(zodSchema, externalParamMetadata) {
|
|
1217
|
+
const metadata2 = Metadata.getParamMetadata(zodSchema);
|
|
1218
|
+
const paramMetadata = metadata2 === null || metadata2 === void 0 ? void 0 : metadata2.param;
|
|
1219
|
+
const mergedParamMetadata = Object.assign(Object.assign({}, paramMetadata), externalParamMetadata);
|
|
1220
|
+
const required = !isOptionalSchema(zodSchema) && !isNullableSchema(zodSchema);
|
|
1221
|
+
const schema = this.generateSchemaWithRef(zodSchema);
|
|
1222
|
+
return Object.assign({
|
|
1223
|
+
schema,
|
|
1224
|
+
required
|
|
1225
|
+
}, Object.keys(mergedParamMetadata).length > 0 ? Metadata.buildParameterMetadata(mergedParamMetadata) : {});
|
|
1226
|
+
}
|
|
1227
|
+
generateParameter(zodSchema, externalParamMetadata) {
|
|
1228
|
+
var _a, _b;
|
|
1229
|
+
const metadata2 = Metadata.getOpenApiMetadata(zodSchema);
|
|
1230
|
+
const paramMetadata = metadata2 === null || metadata2 === void 0 ? void 0 : metadata2.param;
|
|
1231
|
+
const paramName = (_a = externalParamMetadata === null || externalParamMetadata === void 0 ? void 0 : externalParamMetadata.name) !== null && _a !== void 0 ? _a : paramMetadata === null || paramMetadata === void 0 ? void 0 : paramMetadata.name;
|
|
1232
|
+
const paramLocation = (_b = externalParamMetadata === null || externalParamMetadata === void 0 ? void 0 : externalParamMetadata.in) !== null && _b !== void 0 ? _b : paramMetadata === null || paramMetadata === void 0 ? void 0 : paramMetadata.in;
|
|
1233
|
+
if (!paramName) {
|
|
1234
|
+
throw new MissingParameterDataError({ missingField: "name" });
|
|
1235
|
+
}
|
|
1236
|
+
if (!paramLocation) {
|
|
1237
|
+
throw new MissingParameterDataError({
|
|
1238
|
+
missingField: "in",
|
|
1239
|
+
paramName
|
|
1240
|
+
});
|
|
1241
|
+
}
|
|
1242
|
+
const baseParameter = this.generateSimpleParameter(zodSchema, externalParamMetadata);
|
|
1243
|
+
return Object.assign(Object.assign({}, baseParameter), { in: paramLocation, name: paramName });
|
|
1244
|
+
}
|
|
1245
|
+
generateSchemaWithMetadata(zodSchema) {
|
|
1246
|
+
const innerSchema = Metadata.unwrapChained(zodSchema);
|
|
1247
|
+
const metadata2 = Metadata.getOpenApiMetadata(zodSchema);
|
|
1248
|
+
const defaultValue = Metadata.getDefaultValue(zodSchema);
|
|
1249
|
+
const refId = Metadata.getRefId(zodSchema);
|
|
1250
|
+
if (refId && typeof this.schemaRefs[refId] === "object") {
|
|
1251
|
+
return this.schemaRefs[refId];
|
|
1252
|
+
}
|
|
1253
|
+
if (refId && this.schemaRefs[refId] === "pending") {
|
|
1254
|
+
const refSchema = { $ref: this.generateSchemaRef(refId) };
|
|
1255
|
+
return this.versionSpecifics.mapNullableOfRef(refSchema, isNullableSchema(zodSchema));
|
|
1256
|
+
}
|
|
1257
|
+
if (refId && !this.schemaRefs[refId]) {
|
|
1258
|
+
this.schemaRefs[refId] = "pending";
|
|
1259
|
+
}
|
|
1260
|
+
const result = (metadata2 === null || metadata2 === void 0 ? void 0 : metadata2.type) ? { type: metadata2.type } : this.toOpenAPISchema(innerSchema, isNullableSchema(zodSchema), defaultValue);
|
|
1261
|
+
return metadata2 ? Metadata.applySchemaMetadata(result, metadata2) : omitBy(result, isUndefined);
|
|
1262
|
+
}
|
|
1263
|
+
/**
|
|
1264
|
+
* Same as above but applies nullable
|
|
1265
|
+
*/
|
|
1266
|
+
constructReferencedOpenAPISchema(zodSchema) {
|
|
1267
|
+
const metadata2 = Metadata.getOpenApiMetadata(zodSchema);
|
|
1268
|
+
const innerSchema = Metadata.unwrapChained(zodSchema);
|
|
1269
|
+
const defaultValue = Metadata.getDefaultValue(zodSchema);
|
|
1270
|
+
const isNullable = isNullableSchema(zodSchema);
|
|
1271
|
+
if (metadata2 === null || metadata2 === void 0 ? void 0 : metadata2.type) {
|
|
1272
|
+
return this.versionSpecifics.mapNullableType(metadata2.type, isNullable);
|
|
1273
|
+
}
|
|
1274
|
+
const refId = Metadata.getRefId(zodSchema);
|
|
1275
|
+
if (refId && typeof this.schemaRefs[refId] === "object") {
|
|
1276
|
+
return LazyTransformer.mapRecursive(this.schemaRefs[refId], (schema) => this.versionSpecifics.mapNullableType(schema, isNullable), (schema) => this.versionSpecifics.mapNullableOfRef(schema, isNullable));
|
|
1277
|
+
}
|
|
1278
|
+
if (refId && this.schemaRefs[refId] === "pending") {
|
|
1279
|
+
const refSchema = { $ref: this.generateSchemaRef(refId) };
|
|
1280
|
+
return this.versionSpecifics.mapNullableOfRef(refSchema, isNullable);
|
|
1281
|
+
}
|
|
1282
|
+
if (refId && !this.schemaRefs[refId]) {
|
|
1283
|
+
this.schemaRefs[refId] = "pending";
|
|
1284
|
+
}
|
|
1285
|
+
return this.toOpenAPISchema(innerSchema, isNullable, defaultValue);
|
|
1286
|
+
}
|
|
1287
|
+
/**
|
|
1288
|
+
* Generates an OpenAPI SchemaObject or a ReferenceObject with all the provided metadata applied
|
|
1289
|
+
*/
|
|
1290
|
+
generateSimpleSchema(zodSchema) {
|
|
1291
|
+
const metadata2 = Metadata.getOpenApiMetadata(zodSchema);
|
|
1292
|
+
const refId = Metadata.getRefId(zodSchema);
|
|
1293
|
+
if (!refId || !this.schemaRefs[refId]) {
|
|
1294
|
+
return this.generateSchemaWithMetadata(zodSchema);
|
|
1295
|
+
}
|
|
1296
|
+
const schemaRef = this.schemaRefs[refId];
|
|
1297
|
+
const referenceObject = {
|
|
1298
|
+
$ref: this.generateSchemaRef(refId)
|
|
1299
|
+
};
|
|
1300
|
+
if (this.schemaRefs[refId] === "pending") {
|
|
1301
|
+
return this.versionSpecifics.mapNullableOfRef(referenceObject, isNullableSchema(zodSchema));
|
|
1302
|
+
}
|
|
1303
|
+
const newMetadata = omitBy(Metadata.buildSchemaMetadata(metadata2 !== null && metadata2 !== void 0 ? metadata2 : {}), (value, key) => value === void 0 || objectEquals(value, schemaRef[key]));
|
|
1304
|
+
if (newMetadata.type) {
|
|
1305
|
+
return {
|
|
1306
|
+
allOf: [referenceObject, newMetadata]
|
|
1307
|
+
};
|
|
1308
|
+
}
|
|
1309
|
+
const newSchemaMetadata = omitBy(this.constructReferencedOpenAPISchema(zodSchema), (value, key) => value === void 0 || objectEquals(value, schemaRef[key]));
|
|
1310
|
+
const appliedMetadata = Metadata.applySchemaMetadata(newSchemaMetadata, newMetadata);
|
|
1311
|
+
if (Object.keys(appliedMetadata).length > 0) {
|
|
1312
|
+
return {
|
|
1313
|
+
allOf: [referenceObject, appliedMetadata]
|
|
1314
|
+
};
|
|
1315
|
+
}
|
|
1316
|
+
return referenceObject;
|
|
1317
|
+
}
|
|
1318
|
+
/**
|
|
1319
|
+
* Same as `generateSchema` but if the new schema is added into the
|
|
1320
|
+
* referenced schemas, it would return a ReferenceObject and not the
|
|
1321
|
+
* whole result.
|
|
1322
|
+
*
|
|
1323
|
+
* Should be used for nested objects, arrays, etc.
|
|
1324
|
+
*/
|
|
1325
|
+
generateSchemaWithRef(zodSchema) {
|
|
1326
|
+
const refId = Metadata.getRefId(zodSchema);
|
|
1327
|
+
if (refId && !this.schemaRefs[refId]) {
|
|
1328
|
+
this.schemaRefs[refId] = this.generateSimpleSchema(zodSchema);
|
|
1329
|
+
return { $ref: this.generateSchemaRef(refId) };
|
|
1330
|
+
}
|
|
1331
|
+
return this.generateSimpleSchema(zodSchema);
|
|
1332
|
+
}
|
|
1333
|
+
generateSchemaRef(refId) {
|
|
1334
|
+
return `#/components/schemas/${refId}`;
|
|
1335
|
+
}
|
|
1336
|
+
getRequestBody(requestBody) {
|
|
1337
|
+
if (!requestBody) {
|
|
1338
|
+
return;
|
|
1339
|
+
}
|
|
1340
|
+
const { content } = requestBody, rest = __rest(requestBody, ["content"]);
|
|
1341
|
+
const requestBodyContent = this.getBodyContent(content);
|
|
1342
|
+
return Object.assign(Object.assign({}, rest), { content: requestBodyContent });
|
|
1343
|
+
}
|
|
1344
|
+
getParameters(request) {
|
|
1345
|
+
if (!request) {
|
|
1346
|
+
return [];
|
|
1347
|
+
}
|
|
1348
|
+
const { headers } = request;
|
|
1349
|
+
const query = this.cleanParameter(request.query);
|
|
1350
|
+
const params = this.cleanParameter(request.params);
|
|
1351
|
+
const cookies = this.cleanParameter(request.cookies);
|
|
1352
|
+
const queryParameters = enhanceMissingParametersError(() => query ? this.generateInlineParameters(query, "query") : [], { location: "query" });
|
|
1353
|
+
const pathParameters = enhanceMissingParametersError(() => params ? this.generateInlineParameters(params, "path") : [], { location: "path" });
|
|
1354
|
+
const cookieParameters = enhanceMissingParametersError(() => cookies ? this.generateInlineParameters(cookies, "cookie") : [], { location: "cookie" });
|
|
1355
|
+
const headerParameters = enhanceMissingParametersError(() => {
|
|
1356
|
+
if (Array.isArray(headers)) {
|
|
1357
|
+
return headers.flatMap((header) => this.generateInlineParameters(header, "header"));
|
|
1358
|
+
}
|
|
1359
|
+
const cleanHeaders = this.cleanParameter(headers);
|
|
1360
|
+
return cleanHeaders ? this.generateInlineParameters(cleanHeaders, "header") : [];
|
|
1361
|
+
}, { location: "header" });
|
|
1362
|
+
return [
|
|
1363
|
+
...pathParameters,
|
|
1364
|
+
...queryParameters,
|
|
1365
|
+
...headerParameters,
|
|
1366
|
+
...cookieParameters
|
|
1367
|
+
];
|
|
1368
|
+
}
|
|
1369
|
+
cleanParameter(schema) {
|
|
1370
|
+
if (!schema) {
|
|
1371
|
+
return void 0;
|
|
1372
|
+
}
|
|
1373
|
+
if (isZodType(schema, "ZodPipe")) {
|
|
1374
|
+
const inSchema = schema._zod.def.in;
|
|
1375
|
+
const outSchema = schema._zod.def.out;
|
|
1376
|
+
if (isZodType(inSchema, "ZodObject")) {
|
|
1377
|
+
return this.cleanParameter(inSchema);
|
|
1378
|
+
}
|
|
1379
|
+
if (isZodType(outSchema, "ZodObject")) {
|
|
1380
|
+
return this.cleanParameter(outSchema);
|
|
1381
|
+
}
|
|
1382
|
+
return void 0;
|
|
1383
|
+
}
|
|
1384
|
+
return schema;
|
|
1385
|
+
}
|
|
1386
|
+
generatePath(route) {
|
|
1387
|
+
const { method, path, request, responses } = route, pathItemConfig = __rest(route, ["method", "path", "request", "responses"]);
|
|
1388
|
+
const generatedResponses = mapValues(responses, (response) => {
|
|
1389
|
+
return this.getResponse(response);
|
|
1390
|
+
});
|
|
1391
|
+
const parameters = enhanceMissingParametersError(() => this.getParameters(request), { route: `${method} ${path}` });
|
|
1392
|
+
const requestBody = this.getRequestBody(request === null || request === void 0 ? void 0 : request.body);
|
|
1393
|
+
const routeDoc = {
|
|
1394
|
+
[method]: Object.assign(Object.assign(Object.assign(Object.assign({}, pathItemConfig), parameters.length > 0 ? {
|
|
1395
|
+
parameters: [...pathItemConfig.parameters || [], ...parameters]
|
|
1396
|
+
} : {}), requestBody ? { requestBody } : {}), { responses: generatedResponses })
|
|
1397
|
+
};
|
|
1398
|
+
return routeDoc;
|
|
1399
|
+
}
|
|
1400
|
+
generateSingleRoute(route) {
|
|
1401
|
+
const routeDoc = this.generatePath(route);
|
|
1402
|
+
this.pathRefs[route.path] = Object.assign(Object.assign({}, this.pathRefs[route.path]), routeDoc);
|
|
1403
|
+
return routeDoc;
|
|
1404
|
+
}
|
|
1405
|
+
getResponse(response) {
|
|
1406
|
+
if (this.isReferenceObject(response)) {
|
|
1407
|
+
return response;
|
|
1408
|
+
}
|
|
1409
|
+
const { content, headers } = response, rest = __rest(response, ["content", "headers"]);
|
|
1410
|
+
const responseContent = content ? { content: this.getBodyContent(content) } : {};
|
|
1411
|
+
if (!headers) {
|
|
1412
|
+
return Object.assign(Object.assign({}, rest), responseContent);
|
|
1413
|
+
}
|
|
1414
|
+
const responseHeaders = isZodType(headers, "ZodObject") ? this.getResponseHeaders(headers) : (
|
|
1415
|
+
// This is input data so it is okay to cast in the common generator
|
|
1416
|
+
// since this is the user's responsibility to keep it correct
|
|
1417
|
+
headers
|
|
1418
|
+
);
|
|
1419
|
+
return Object.assign(Object.assign(Object.assign({}, rest), { headers: responseHeaders }), responseContent);
|
|
1420
|
+
}
|
|
1421
|
+
isReferenceObject(schema) {
|
|
1422
|
+
return "$ref" in schema;
|
|
1423
|
+
}
|
|
1424
|
+
getResponseHeaders(headers) {
|
|
1425
|
+
const schemaShape = headers.def.shape;
|
|
1426
|
+
const responseHeaders = mapValues(schemaShape, (_) => this.generateSimpleParameter(_));
|
|
1427
|
+
return responseHeaders;
|
|
1428
|
+
}
|
|
1429
|
+
getBodyContent(content) {
|
|
1430
|
+
return mapValues(content, (config) => {
|
|
1431
|
+
if (!config) {
|
|
1432
|
+
return config;
|
|
1433
|
+
}
|
|
1434
|
+
if ("$ref" in config) {
|
|
1435
|
+
return config;
|
|
1436
|
+
}
|
|
1437
|
+
const { schema: configSchema, itemSchema: configItemSchema } = config, rest = __rest(config, ["schema", "itemSchema"]);
|
|
1438
|
+
const schema = typeof configSchema === "object" && isAnyZodType(configSchema) ? this.generateSchemaWithRef(configSchema) : configSchema;
|
|
1439
|
+
const itemSchema = typeof configItemSchema === "object" && isAnyZodType(configItemSchema) ? this.generateSchemaWithRef(configItemSchema) : configItemSchema;
|
|
1440
|
+
return Object.assign(Object.assign(Object.assign({}, rest), schema !== void 0 ? { schema } : {}), itemSchema !== void 0 ? { itemSchema } : {});
|
|
1441
|
+
});
|
|
1442
|
+
}
|
|
1443
|
+
toOpenAPISchema(zodSchema, isNullable, defaultValue) {
|
|
1444
|
+
const result = this.openApiTransformer.transform(zodSchema, isNullable, (_) => this.generateSchemaWithRef(_), (_) => this.generateSchemaRef(_), defaultValue);
|
|
1445
|
+
return result;
|
|
1446
|
+
}
|
|
1447
|
+
};
|
|
1448
|
+
var OpenApiGeneratorV30Specifics = class {
|
|
1449
|
+
get nullType() {
|
|
1450
|
+
return { nullable: true };
|
|
1451
|
+
}
|
|
1452
|
+
mapNullableOfArray(objects, isNullable) {
|
|
1453
|
+
if (isNullable && !objects.some((object2) => objectEquals(object2, this.nullType))) {
|
|
1454
|
+
return [...objects, this.nullType];
|
|
1455
|
+
}
|
|
1456
|
+
return objects;
|
|
1457
|
+
}
|
|
1458
|
+
mapNullableType(type, isNullable) {
|
|
1459
|
+
return Object.assign(Object.assign({}, type ? { type } : void 0), isNullable ? this.nullType : void 0);
|
|
1460
|
+
}
|
|
1461
|
+
mapNullableOfRef(ref, isNullable) {
|
|
1462
|
+
if (isNullable) {
|
|
1463
|
+
return {
|
|
1464
|
+
allOf: [ref, this.nullType]
|
|
1465
|
+
};
|
|
1466
|
+
}
|
|
1467
|
+
return ref;
|
|
1468
|
+
}
|
|
1469
|
+
mapTupleItems(schemas) {
|
|
1470
|
+
const uniqueSchemas = uniq(schemas);
|
|
1471
|
+
return {
|
|
1472
|
+
items: uniqueSchemas.length === 1 ? uniqueSchemas[0] : { anyOf: uniqueSchemas },
|
|
1473
|
+
minItems: schemas.length,
|
|
1474
|
+
maxItems: schemas.length
|
|
1475
|
+
};
|
|
1476
|
+
}
|
|
1477
|
+
getNumberChecks(checks) {
|
|
1478
|
+
return Object.assign({}, ...checks.map((check) => {
|
|
1479
|
+
switch (check._zod.def.check) {
|
|
1480
|
+
case "greater_than": {
|
|
1481
|
+
const greaterThanCheck = check;
|
|
1482
|
+
return greaterThanCheck._zod.def.inclusive ? { minimum: Number(greaterThanCheck._zod.def.value) } : {
|
|
1483
|
+
minimum: Number(greaterThanCheck._zod.def.value),
|
|
1484
|
+
exclusiveMinimum: true
|
|
1485
|
+
};
|
|
1486
|
+
}
|
|
1487
|
+
case "less_than": {
|
|
1488
|
+
const lessThanCheck = check;
|
|
1489
|
+
return lessThanCheck._zod.def.inclusive ? { maximum: Number(lessThanCheck._zod.def.value) } : {
|
|
1490
|
+
maximum: Number(lessThanCheck._zod.def.value),
|
|
1491
|
+
exclusiveMaximum: !lessThanCheck._zod.def.inclusive
|
|
1492
|
+
};
|
|
1493
|
+
}
|
|
1494
|
+
default:
|
|
1495
|
+
return {};
|
|
1496
|
+
}
|
|
1497
|
+
}));
|
|
1498
|
+
}
|
|
1499
|
+
};
|
|
1500
|
+
var OpenApiGeneratorV32 = class {
|
|
1501
|
+
constructor(definitions, options) {
|
|
1502
|
+
const specifics = new OpenApiGeneratorV30Specifics();
|
|
1503
|
+
this.generator = new OpenAPIGenerator(definitions, specifics, options);
|
|
1504
|
+
}
|
|
1505
|
+
generateDocument(config) {
|
|
1506
|
+
const baseData = this.generator.generateDocumentData();
|
|
1507
|
+
return Object.assign(Object.assign({}, config), baseData);
|
|
1508
|
+
}
|
|
1509
|
+
generateComponents() {
|
|
1510
|
+
return this.generator.generateComponents();
|
|
1511
|
+
}
|
|
1512
|
+
};
|
|
1513
|
+
var OpenApiGeneratorV31Specifics = class {
|
|
1514
|
+
get nullType() {
|
|
1515
|
+
return { type: "null" };
|
|
1516
|
+
}
|
|
1517
|
+
mapNullableOfArray(objects, isNullable) {
|
|
1518
|
+
if (isNullable && !objects.some((object2) => objectEquals(object2, this.nullType))) {
|
|
1519
|
+
return [...objects, this.nullType];
|
|
1520
|
+
}
|
|
1521
|
+
return objects;
|
|
1522
|
+
}
|
|
1523
|
+
mapNullableType(type, isNullable) {
|
|
1524
|
+
if (!type) {
|
|
1525
|
+
return {};
|
|
1526
|
+
}
|
|
1527
|
+
if (isNullable) {
|
|
1528
|
+
const typeArray = Array.isArray(type) ? type : [type];
|
|
1529
|
+
const nullableType = uniq([...typeArray, "null"]);
|
|
1530
|
+
return { type: nullableType };
|
|
1531
|
+
}
|
|
1532
|
+
return { type };
|
|
1533
|
+
}
|
|
1534
|
+
mapNullableOfRef(ref, isNullable) {
|
|
1535
|
+
if (isNullable) {
|
|
1536
|
+
return {
|
|
1537
|
+
oneOf: [ref, this.nullType]
|
|
1538
|
+
};
|
|
1539
|
+
}
|
|
1540
|
+
return ref;
|
|
1541
|
+
}
|
|
1542
|
+
mapTupleItems(schemas) {
|
|
1543
|
+
return {
|
|
1544
|
+
prefixItems: schemas
|
|
1545
|
+
};
|
|
1546
|
+
}
|
|
1547
|
+
getNumberChecks(checks) {
|
|
1548
|
+
return Object.assign({}, ...checks.map((check) => {
|
|
1549
|
+
switch (check._zod.def.check) {
|
|
1550
|
+
case "greater_than": {
|
|
1551
|
+
const greaterThanCheck = check;
|
|
1552
|
+
return greaterThanCheck._zod.def.inclusive ? { minimum: Number(greaterThanCheck._zod.def.value) } : { exclusiveMinimum: Number(greaterThanCheck._zod.def.value) };
|
|
1553
|
+
}
|
|
1554
|
+
case "less_than": {
|
|
1555
|
+
const lessThanCheck = check;
|
|
1556
|
+
return lessThanCheck._zod.def.inclusive ? { maximum: Number(lessThanCheck._zod.def.value) } : { exclusiveMaximum: Number(lessThanCheck._zod.def.value) };
|
|
1557
|
+
}
|
|
1558
|
+
default:
|
|
1559
|
+
return {};
|
|
1560
|
+
}
|
|
1561
|
+
}));
|
|
1562
|
+
}
|
|
1563
|
+
};
|
|
1564
|
+
function isWebhookDefinition$1(definition) {
|
|
1565
|
+
return "type" in definition && definition.type === "webhook";
|
|
1566
|
+
}
|
|
1567
|
+
var OpenApiGeneratorV312 = class {
|
|
1568
|
+
constructor(definitions, options) {
|
|
1569
|
+
this.definitions = definitions;
|
|
1570
|
+
this.webhookRefs = {};
|
|
1571
|
+
const specifics = new OpenApiGeneratorV31Specifics();
|
|
1572
|
+
this.generator = new OpenAPIGenerator(this.definitions, specifics, options);
|
|
1573
|
+
}
|
|
1574
|
+
generateDocument(config) {
|
|
1575
|
+
this.generateWebhooks();
|
|
1576
|
+
const baseDocument = this.generator.generateDocumentData();
|
|
1577
|
+
return Object.assign(Object.assign(Object.assign({}, config), baseDocument), { webhooks: this.webhookRefs });
|
|
1578
|
+
}
|
|
1579
|
+
generateComponents() {
|
|
1580
|
+
return this.generator.generateComponents();
|
|
1581
|
+
}
|
|
1582
|
+
generateWebhooks() {
|
|
1583
|
+
this.webhookRefs = {};
|
|
1584
|
+
this.definitions.filter(isWebhookDefinition$1).forEach((definition) => this.generateSingleWebhook(definition.webhook));
|
|
1585
|
+
}
|
|
1586
|
+
generateSingleWebhook(route) {
|
|
1587
|
+
const routeDoc = this.generator.generatePath(route);
|
|
1588
|
+
this.webhookRefs[route.path] = Object.assign(Object.assign({}, this.webhookRefs[route.path]), routeDoc);
|
|
1589
|
+
return routeDoc;
|
|
1590
|
+
}
|
|
1591
|
+
};
|
|
1592
|
+
function isWebhookDefinition(definition) {
|
|
1593
|
+
return "type" in definition && definition.type === "webhook";
|
|
1594
|
+
}
|
|
1595
|
+
var OpenApiGeneratorV322 = class {
|
|
1596
|
+
constructor(definitions, options) {
|
|
1597
|
+
this.definitions = definitions;
|
|
1598
|
+
this.webhookRefs = {};
|
|
1599
|
+
const specifics = new OpenApiGeneratorV31Specifics();
|
|
1600
|
+
this.generator = new OpenAPIGenerator(this.definitions, specifics, options);
|
|
1601
|
+
}
|
|
1602
|
+
generateDocument(config) {
|
|
1603
|
+
this.generateWebhooks();
|
|
1604
|
+
const baseDocument = this.generator.generateDocumentData();
|
|
1605
|
+
return Object.assign(Object.assign(Object.assign({}, config), baseDocument), { webhooks: this.webhookRefs });
|
|
1606
|
+
}
|
|
1607
|
+
generateComponents() {
|
|
1608
|
+
return this.generator.generateComponents();
|
|
1609
|
+
}
|
|
1610
|
+
generateWebhooks() {
|
|
1611
|
+
this.webhookRefs = {};
|
|
1612
|
+
this.definitions.filter(isWebhookDefinition).forEach((definition) => this.generateSingleWebhook(definition.webhook));
|
|
1613
|
+
}
|
|
1614
|
+
generateSingleWebhook(route) {
|
|
1615
|
+
const routeDoc = this.generator.generatePath(route);
|
|
1616
|
+
this.webhookRefs[route.path] = Object.assign(Object.assign({}, this.webhookRefs[route.path]), routeDoc);
|
|
1617
|
+
return routeDoc;
|
|
1618
|
+
}
|
|
1619
|
+
};
|
|
1620
|
+
exports.OpenAPIRegistry = OpenAPIRegistry2;
|
|
1621
|
+
exports.OpenApiGeneratorV3 = OpenApiGeneratorV32;
|
|
1622
|
+
exports.OpenApiGeneratorV31 = OpenApiGeneratorV312;
|
|
1623
|
+
exports.OpenApiGeneratorV32 = OpenApiGeneratorV322;
|
|
1624
|
+
exports.extendZodWithOpenApi = extendZodWithOpenApi2;
|
|
1625
|
+
exports.getOpenApiMetadata = getOpenApiMetadata2;
|
|
1626
|
+
exports.getRefId = getRefId;
|
|
1627
|
+
exports.zodToOpenAPIRegistry = zodToOpenAPIRegistry;
|
|
1628
|
+
}
|
|
1629
|
+
});
|
|
1630
|
+
|
|
1631
|
+
// packages/cli/contracts/internal.ts
|
|
1632
|
+
import { z as z7 } from "zod";
|
|
1633
|
+
|
|
1634
|
+
// node_modules/.pnpm/@hono+zod-openapi@1.6.3_hono@4.13.8_zod@4.6.5/node_modules/@hono/zod-openapi/dist/index.mjs
|
|
1635
|
+
var import_zod_to_openapi = __toESM(require_dist(), 1);
|
|
1636
|
+
|
|
1637
|
+
// node_modules/.pnpm/hono@4.13.8/node_modules/hono/dist/utils/url.js
|
|
1638
|
+
var tryDecode = (str, decoder) => {
|
|
1639
|
+
try {
|
|
1640
|
+
return decoder(str);
|
|
1641
|
+
} catch {
|
|
1642
|
+
return str.replace(/(?:%[0-9A-Fa-f]{2})+/g, (match2) => {
|
|
1643
|
+
try {
|
|
1644
|
+
return decoder(match2);
|
|
1645
|
+
} catch {
|
|
1646
|
+
return match2;
|
|
1647
|
+
}
|
|
1648
|
+
});
|
|
1649
|
+
}
|
|
1650
|
+
};
|
|
1651
|
+
var tryDecodeURIComponent = (str) => str.indexOf("%") !== -1 ? tryDecode(str, decodeURIComponent_) : str;
|
|
1652
|
+
var _decodeURI = (value) => {
|
|
1653
|
+
if (value.indexOf("+") !== -1) {
|
|
1654
|
+
value = value.replace(/\+/g, " ");
|
|
1655
|
+
}
|
|
1656
|
+
return tryDecodeURIComponent(value);
|
|
1657
|
+
};
|
|
1658
|
+
var _getQueryParam = (url, key, multiple) => {
|
|
1659
|
+
const hashIndex = url.indexOf("#", 8);
|
|
1660
|
+
if (hashIndex !== -1) {
|
|
1661
|
+
url = url.slice(0, hashIndex);
|
|
1662
|
+
}
|
|
1663
|
+
let encoded;
|
|
1664
|
+
if (!multiple && key && key.indexOf("%") === -1 && key.indexOf("+") === -1) {
|
|
1665
|
+
let keyIndex2 = url.indexOf("?", 8);
|
|
1666
|
+
if (keyIndex2 === -1) {
|
|
1667
|
+
return void 0;
|
|
1668
|
+
}
|
|
1669
|
+
if (!url.startsWith(key, keyIndex2 + 1)) {
|
|
1670
|
+
keyIndex2 = url.indexOf(`&${key}`, keyIndex2 + 1);
|
|
1671
|
+
}
|
|
1672
|
+
while (keyIndex2 !== -1) {
|
|
1673
|
+
const trailingKeyCode = url.charCodeAt(keyIndex2 + key.length + 1);
|
|
1674
|
+
if (trailingKeyCode === 61) {
|
|
1675
|
+
const valueIndex = keyIndex2 + key.length + 2;
|
|
1676
|
+
const endIndex = url.indexOf("&", valueIndex);
|
|
1677
|
+
return _decodeURI(url.slice(valueIndex, endIndex === -1 ? void 0 : endIndex));
|
|
1678
|
+
} else if (trailingKeyCode == 38 || isNaN(trailingKeyCode)) {
|
|
1679
|
+
return "";
|
|
1680
|
+
}
|
|
1681
|
+
keyIndex2 = url.indexOf(`&${key}`, keyIndex2 + 1);
|
|
1682
|
+
}
|
|
1683
|
+
encoded = /[%+]/.test(url);
|
|
1684
|
+
if (!encoded) {
|
|
1685
|
+
return void 0;
|
|
1686
|
+
}
|
|
1687
|
+
}
|
|
1688
|
+
const results = /* @__PURE__ */ Object.create(null);
|
|
1689
|
+
encoded ??= /[%+]/.test(url);
|
|
1690
|
+
let keyIndex = url.indexOf("?", 8);
|
|
1691
|
+
while (keyIndex !== -1) {
|
|
1692
|
+
const nextKeyIndex = url.indexOf("&", keyIndex + 1);
|
|
1693
|
+
let valueIndex = url.indexOf("=", keyIndex);
|
|
1694
|
+
if (valueIndex > nextKeyIndex && nextKeyIndex !== -1) {
|
|
1695
|
+
valueIndex = -1;
|
|
1696
|
+
}
|
|
1697
|
+
let name = url.slice(
|
|
1698
|
+
keyIndex + 1,
|
|
1699
|
+
valueIndex === -1 ? nextKeyIndex === -1 ? void 0 : nextKeyIndex : valueIndex
|
|
1700
|
+
);
|
|
1701
|
+
if (encoded) {
|
|
1702
|
+
name = _decodeURI(name);
|
|
1703
|
+
}
|
|
1704
|
+
keyIndex = nextKeyIndex;
|
|
1705
|
+
if (name === "") {
|
|
1706
|
+
continue;
|
|
1707
|
+
}
|
|
1708
|
+
let value;
|
|
1709
|
+
if (valueIndex === -1) {
|
|
1710
|
+
value = "";
|
|
1711
|
+
} else {
|
|
1712
|
+
value = url.slice(valueIndex + 1, nextKeyIndex === -1 ? void 0 : nextKeyIndex);
|
|
1713
|
+
if (encoded) {
|
|
1714
|
+
value = _decodeURI(value);
|
|
1715
|
+
}
|
|
1716
|
+
}
|
|
1717
|
+
if (multiple) {
|
|
1718
|
+
if (!(results[name] && Array.isArray(results[name]))) {
|
|
1719
|
+
results[name] = [];
|
|
1720
|
+
}
|
|
1721
|
+
;
|
|
1722
|
+
results[name].push(value);
|
|
1723
|
+
} else {
|
|
1724
|
+
results[name] ??= value;
|
|
1725
|
+
}
|
|
1726
|
+
}
|
|
1727
|
+
return key ? results[key] : results;
|
|
1728
|
+
};
|
|
1729
|
+
var getQueryParam = _getQueryParam;
|
|
1730
|
+
var getQueryParams = (url, key) => {
|
|
1731
|
+
return _getQueryParam(url, key, true);
|
|
1732
|
+
};
|
|
1733
|
+
var decodeURIComponent_ = decodeURIComponent;
|
|
1734
|
+
|
|
1735
|
+
// node_modules/.pnpm/hono@4.13.8/node_modules/hono/dist/utils/buffer.js
|
|
1736
|
+
var bufferToFormData = (arrayBuffer, contentType) => {
|
|
1737
|
+
const response = new Response(arrayBuffer, {
|
|
1738
|
+
headers: {
|
|
1739
|
+
// Normalize the media type (case-insensitive) while keeping parameters like the boundary
|
|
1740
|
+
"Content-Type": contentType.replace(/^[^;]+/, (mediaType) => mediaType.toLowerCase())
|
|
1741
|
+
}
|
|
1742
|
+
});
|
|
1743
|
+
return response.formData();
|
|
1744
|
+
};
|
|
1745
|
+
|
|
1746
|
+
// node_modules/.pnpm/hono@4.13.8/node_modules/hono/dist/request/constants.js
|
|
1747
|
+
var GET_MATCH_RESULT = /* @__PURE__ */ Symbol();
|
|
1748
|
+
|
|
1749
|
+
// node_modules/.pnpm/hono@4.13.8/node_modules/hono/dist/utils/body.js
|
|
1750
|
+
var MAX_NESTING_DEPTH = 32;
|
|
1751
|
+
var MAX_NESTED_OBJECTS = 1e4;
|
|
1752
|
+
var isRawRequest = (request) => "headers" in request;
|
|
1753
|
+
var parseBody = async (request, options = /* @__PURE__ */ Object.create(null)) => {
|
|
1754
|
+
const { all = false, dot = false } = options;
|
|
1755
|
+
const headers = isRawRequest(request) ? request.headers : request.raw.headers;
|
|
1756
|
+
const contentType = headers.get("Content-Type");
|
|
1757
|
+
const mediaType = contentType?.split(";")[0].trim().toLowerCase();
|
|
1758
|
+
if (mediaType === "multipart/form-data" || mediaType === "application/x-www-form-urlencoded") {
|
|
1759
|
+
return parseFormData(request, { all, dot });
|
|
1760
|
+
}
|
|
1761
|
+
return {};
|
|
1762
|
+
};
|
|
1763
|
+
async function parseFormData(request, options) {
|
|
1764
|
+
if (!isRawRequest(request) && request.bodyCache.formData) {
|
|
1765
|
+
return convertFormDataToBodyData(
|
|
1766
|
+
await request.bodyCache.formData,
|
|
1767
|
+
options
|
|
1768
|
+
);
|
|
1769
|
+
}
|
|
1770
|
+
const headers = isRawRequest(request) ? request.headers : request.raw.headers;
|
|
1771
|
+
const arrayBuffer = await request.arrayBuffer();
|
|
1772
|
+
const formDataPromise = bufferToFormData(arrayBuffer, headers.get("Content-Type") || "");
|
|
1773
|
+
if (!isRawRequest(request)) {
|
|
1774
|
+
request.bodyCache.formData = formDataPromise;
|
|
1775
|
+
}
|
|
1776
|
+
const formData = await formDataPromise;
|
|
1777
|
+
if (formData) {
|
|
1778
|
+
return convertFormDataToBodyData(formData, options);
|
|
1779
|
+
}
|
|
1780
|
+
return {};
|
|
1781
|
+
}
|
|
1782
|
+
function convertFormDataToBodyData(formData, options) {
|
|
1783
|
+
const form = /* @__PURE__ */ Object.create(null);
|
|
1784
|
+
const nestingState = { count: 0 };
|
|
1785
|
+
formData.forEach((value, key) => {
|
|
1786
|
+
const shouldParseAllValues = options.all || key.endsWith("[]");
|
|
1787
|
+
if (!shouldParseAllValues) {
|
|
1788
|
+
form[key] = value;
|
|
1789
|
+
} else {
|
|
1790
|
+
handleParsingAllValues(form, key, value);
|
|
1791
|
+
}
|
|
1792
|
+
});
|
|
1793
|
+
if (options.dot) {
|
|
1794
|
+
Object.entries(form).forEach(([key, value]) => {
|
|
1795
|
+
const shouldParseDotValues = key.includes(".");
|
|
1796
|
+
if (shouldParseDotValues) {
|
|
1797
|
+
handleParsingNestedValues(form, key, value, nestingState);
|
|
1798
|
+
delete form[key];
|
|
1799
|
+
}
|
|
1800
|
+
});
|
|
1801
|
+
}
|
|
1802
|
+
return form;
|
|
1803
|
+
}
|
|
1804
|
+
var handleParsingAllValues = (form, key, value) => {
|
|
1805
|
+
if (form[key] !== void 0) {
|
|
1806
|
+
if (Array.isArray(form[key])) {
|
|
1807
|
+
;
|
|
1808
|
+
form[key].push(value);
|
|
1809
|
+
} else {
|
|
1810
|
+
form[key] = [form[key], value];
|
|
1811
|
+
}
|
|
1812
|
+
} else {
|
|
1813
|
+
if (!key.endsWith("[]")) {
|
|
1814
|
+
form[key] = value;
|
|
1815
|
+
} else {
|
|
1816
|
+
form[key] = [value];
|
|
1817
|
+
}
|
|
1818
|
+
}
|
|
1819
|
+
};
|
|
1820
|
+
var handleParsingNestedValues = (form, key, value, state) => {
|
|
1821
|
+
if (/(?:^|\.)__proto__\./.test(key)) {
|
|
1822
|
+
return;
|
|
1823
|
+
}
|
|
1824
|
+
let nestedForm = form;
|
|
1825
|
+
const keys = key.split(".", MAX_NESTING_DEPTH + 2);
|
|
1826
|
+
if (keys.length > MAX_NESTING_DEPTH + 1) {
|
|
1827
|
+
throwNestingLimitExceeded();
|
|
1828
|
+
}
|
|
1829
|
+
keys.forEach((key2, index) => {
|
|
1830
|
+
if (index === keys.length - 1) {
|
|
1831
|
+
nestedForm[key2] = value;
|
|
1832
|
+
} else {
|
|
1833
|
+
if (!nestedForm[key2] || typeof nestedForm[key2] !== "object" || Array.isArray(nestedForm[key2]) || nestedForm[key2] instanceof File) {
|
|
1834
|
+
if (state.count++ >= MAX_NESTED_OBJECTS) {
|
|
1835
|
+
throwNestingLimitExceeded();
|
|
1836
|
+
}
|
|
1837
|
+
nestedForm[key2] = /* @__PURE__ */ Object.create(null);
|
|
1838
|
+
}
|
|
1839
|
+
nestedForm = nestedForm[key2];
|
|
1840
|
+
}
|
|
1841
|
+
});
|
|
1842
|
+
};
|
|
1843
|
+
var throwNestingLimitExceeded = () => {
|
|
1844
|
+
throw new Error("Nesting limit exceeded");
|
|
1845
|
+
};
|
|
1846
|
+
|
|
1847
|
+
// node_modules/.pnpm/hono@4.13.8/node_modules/hono/dist/request.js
|
|
1848
|
+
var HonoRequest = class {
|
|
1849
|
+
/**
|
|
1850
|
+
* `.raw` can get the raw Request object.
|
|
1851
|
+
*
|
|
1852
|
+
* @see {@link https://hono.dev/docs/api/request#raw}
|
|
1853
|
+
*
|
|
1854
|
+
* @example
|
|
1855
|
+
* ```ts
|
|
1856
|
+
* // For Cloudflare Workers
|
|
1857
|
+
* app.post('/', async (c) => {
|
|
1858
|
+
* const metadata = c.req.raw.cf?.hostMetadata?
|
|
1859
|
+
* ...
|
|
1860
|
+
* })
|
|
1861
|
+
* ```
|
|
1862
|
+
*/
|
|
1863
|
+
raw;
|
|
1864
|
+
#validatedData;
|
|
1865
|
+
// Short name of validatedData
|
|
1866
|
+
#matchResult;
|
|
1867
|
+
routeIndex = 0;
|
|
1868
|
+
/**
|
|
1869
|
+
* `.path` can get the pathname of the request.
|
|
1870
|
+
*
|
|
1871
|
+
* @see {@link https://hono.dev/docs/api/request#path}
|
|
1872
|
+
*
|
|
1873
|
+
* @example
|
|
1874
|
+
* ```ts
|
|
1875
|
+
* app.get('/about/me', (c) => {
|
|
1876
|
+
* const pathname = c.req.path // `/about/me`
|
|
1877
|
+
* })
|
|
1878
|
+
* ```
|
|
1879
|
+
*/
|
|
1880
|
+
path;
|
|
1881
|
+
bodyCache = {};
|
|
1882
|
+
constructor(request, path = "/", matchResult = [[]]) {
|
|
1883
|
+
this.raw = request;
|
|
1884
|
+
this.path = path;
|
|
1885
|
+
this.#matchResult = matchResult;
|
|
1886
|
+
}
|
|
1887
|
+
param(key) {
|
|
1888
|
+
return key ? this.#getDecodedParam(key) : this.#getAllDecodedParams();
|
|
1889
|
+
}
|
|
1890
|
+
#getDecodedParam(key) {
|
|
1891
|
+
const paramKey = this.#matchResult[0][this.routeIndex]?.[1][key];
|
|
1892
|
+
const param = this.#getParamValue(paramKey);
|
|
1893
|
+
return param && tryDecodeURIComponent(param);
|
|
1894
|
+
}
|
|
1895
|
+
#getAllDecodedParams() {
|
|
1896
|
+
const decoded = {};
|
|
1897
|
+
const keys = Object.keys(this.#matchResult[0][this.routeIndex]?.[1] ?? {});
|
|
1898
|
+
for (const key of keys) {
|
|
1899
|
+
const value = this.#getParamValue(this.#matchResult[0][this.routeIndex][1][key]);
|
|
1900
|
+
if (value !== void 0) {
|
|
1901
|
+
decoded[key] = tryDecodeURIComponent(value);
|
|
1902
|
+
}
|
|
1903
|
+
}
|
|
1904
|
+
return decoded;
|
|
1905
|
+
}
|
|
1906
|
+
#getParamValue(paramKey) {
|
|
1907
|
+
return this.#matchResult[1] ? this.#matchResult[1][paramKey] : paramKey;
|
|
1908
|
+
}
|
|
1909
|
+
query(key) {
|
|
1910
|
+
return getQueryParam(this.url, key);
|
|
1911
|
+
}
|
|
1912
|
+
queries(key) {
|
|
1913
|
+
return getQueryParams(this.url, key);
|
|
1914
|
+
}
|
|
1915
|
+
header(name) {
|
|
1916
|
+
if (name) {
|
|
1917
|
+
return this.raw.headers.get(name) ?? void 0;
|
|
1918
|
+
}
|
|
1919
|
+
const headerData = /* @__PURE__ */ Object.create(null);
|
|
1920
|
+
this.raw.headers.forEach((value, key) => {
|
|
1921
|
+
headerData[key] = value;
|
|
1922
|
+
});
|
|
1923
|
+
return headerData;
|
|
1924
|
+
}
|
|
1925
|
+
async parseBody(options) {
|
|
1926
|
+
return parseBody(this, options);
|
|
1927
|
+
}
|
|
1928
|
+
#cachedBody = (key) => {
|
|
1929
|
+
const { bodyCache, raw } = this;
|
|
1930
|
+
const cachedBody = bodyCache[key];
|
|
1931
|
+
if (cachedBody) {
|
|
1932
|
+
return cachedBody;
|
|
1933
|
+
}
|
|
1934
|
+
for (const anyCachedKey in bodyCache) {
|
|
1935
|
+
return bodyCache[anyCachedKey].then((body) => {
|
|
1936
|
+
if (anyCachedKey === "json") {
|
|
1937
|
+
body = JSON.stringify(body);
|
|
1938
|
+
}
|
|
1939
|
+
const contentType = anyCachedKey === "formData" ? void 0 : raw.headers.get("content-type");
|
|
1940
|
+
return new Response(body, {
|
|
1941
|
+
headers: contentType ? { "Content-Type": contentType } : void 0
|
|
1942
|
+
})[key]();
|
|
1943
|
+
});
|
|
1944
|
+
}
|
|
1945
|
+
return bodyCache[key] = raw[key]();
|
|
1946
|
+
};
|
|
1947
|
+
/**
|
|
1948
|
+
* `.json()` can parse Request body of type `application/json`
|
|
1949
|
+
*
|
|
1950
|
+
* @see {@link https://hono.dev/docs/api/request#json}
|
|
1951
|
+
*
|
|
1952
|
+
* @example
|
|
1953
|
+
* ```ts
|
|
1954
|
+
* app.post('/entry', async (c) => {
|
|
1955
|
+
* const body = await c.req.json()
|
|
1956
|
+
* })
|
|
1957
|
+
* ```
|
|
1958
|
+
*/
|
|
1959
|
+
json() {
|
|
1960
|
+
return this.#cachedBody("text").then((text) => JSON.parse(text));
|
|
1961
|
+
}
|
|
1962
|
+
/**
|
|
1963
|
+
* `.text()` can parse Request body of type `text/plain`
|
|
1964
|
+
*
|
|
1965
|
+
* @see {@link https://hono.dev/docs/api/request#text}
|
|
1966
|
+
*
|
|
1967
|
+
* @example
|
|
1968
|
+
* ```ts
|
|
1969
|
+
* app.post('/entry', async (c) => {
|
|
1970
|
+
* const body = await c.req.text()
|
|
1971
|
+
* })
|
|
1972
|
+
* ```
|
|
1973
|
+
*/
|
|
1974
|
+
text() {
|
|
1975
|
+
return this.#cachedBody("text");
|
|
1976
|
+
}
|
|
1977
|
+
/**
|
|
1978
|
+
* `.arrayBuffer()` parse Request body as an `ArrayBuffer`
|
|
1979
|
+
*
|
|
1980
|
+
* @see {@link https://hono.dev/docs/api/request#arraybuffer}
|
|
1981
|
+
*
|
|
1982
|
+
* @example
|
|
1983
|
+
* ```ts
|
|
1984
|
+
* app.post('/entry', async (c) => {
|
|
1985
|
+
* const body = await c.req.arrayBuffer()
|
|
1986
|
+
* })
|
|
1987
|
+
* ```
|
|
1988
|
+
*/
|
|
1989
|
+
arrayBuffer() {
|
|
1990
|
+
return this.#cachedBody("arrayBuffer");
|
|
1991
|
+
}
|
|
1992
|
+
/**
|
|
1993
|
+
* `.bytes()` parses the request body as a `Uint8Array`.
|
|
1994
|
+
*
|
|
1995
|
+
* @see {@link https://hono.dev/docs/api/request#bytes}
|
|
1996
|
+
*
|
|
1997
|
+
* @example
|
|
1998
|
+
* ```ts
|
|
1999
|
+
* app.post('/entry', async (c) => {
|
|
2000
|
+
* const body = await c.req.bytes()
|
|
2001
|
+
* })
|
|
2002
|
+
* ```
|
|
2003
|
+
*/
|
|
2004
|
+
bytes() {
|
|
2005
|
+
return this.#cachedBody("arrayBuffer").then((buffer) => new Uint8Array(buffer));
|
|
2006
|
+
}
|
|
2007
|
+
/**
|
|
2008
|
+
* Parses the request body as a `Blob`.
|
|
2009
|
+
* @example
|
|
2010
|
+
* ```ts
|
|
2011
|
+
* app.post('/entry', async (c) => {
|
|
2012
|
+
* const body = await c.req.blob();
|
|
2013
|
+
* });
|
|
2014
|
+
* ```
|
|
2015
|
+
* @see https://hono.dev/docs/api/request#blob
|
|
2016
|
+
*/
|
|
2017
|
+
blob() {
|
|
2018
|
+
return this.#cachedBody("blob");
|
|
2019
|
+
}
|
|
2020
|
+
/**
|
|
2021
|
+
* Parses the request body as `FormData`.
|
|
2022
|
+
* @example
|
|
2023
|
+
* ```ts
|
|
2024
|
+
* app.post('/entry', async (c) => {
|
|
2025
|
+
* const body = await c.req.formData();
|
|
2026
|
+
* });
|
|
2027
|
+
* ```
|
|
2028
|
+
* @see https://hono.dev/docs/api/request#formdata
|
|
2029
|
+
*/
|
|
2030
|
+
formData() {
|
|
2031
|
+
return this.#cachedBody("formData");
|
|
2032
|
+
}
|
|
2033
|
+
/**
|
|
2034
|
+
* Adds validated data to the request.
|
|
2035
|
+
*
|
|
2036
|
+
* @param target - The target of the validation.
|
|
2037
|
+
* @param data - The validated data to add.
|
|
2038
|
+
*/
|
|
2039
|
+
addValidatedData(target, data) {
|
|
2040
|
+
;
|
|
2041
|
+
(this.#validatedData ??= {})[target] = data;
|
|
2042
|
+
}
|
|
2043
|
+
valid(target) {
|
|
2044
|
+
return this.#validatedData?.[target];
|
|
2045
|
+
}
|
|
2046
|
+
/**
|
|
2047
|
+
* `.url()` can get the request url strings.
|
|
2048
|
+
*
|
|
2049
|
+
* @see {@link https://hono.dev/docs/api/request#url}
|
|
2050
|
+
*
|
|
2051
|
+
* @example
|
|
2052
|
+
* ```ts
|
|
2053
|
+
* app.get('/about/me', (c) => {
|
|
2054
|
+
* const url = c.req.url // `http://localhost:8787/about/me`
|
|
2055
|
+
* ...
|
|
2056
|
+
* })
|
|
2057
|
+
* ```
|
|
2058
|
+
*/
|
|
2059
|
+
get url() {
|
|
2060
|
+
return this.raw.url;
|
|
2061
|
+
}
|
|
2062
|
+
/**
|
|
2063
|
+
* `.method()` can get the method name of the request.
|
|
2064
|
+
*
|
|
2065
|
+
* @see {@link https://hono.dev/docs/api/request#method}
|
|
2066
|
+
*
|
|
2067
|
+
* @example
|
|
2068
|
+
* ```ts
|
|
2069
|
+
* app.get('/about/me', (c) => {
|
|
2070
|
+
* const method = c.req.method // `GET`
|
|
2071
|
+
* })
|
|
2072
|
+
* ```
|
|
2073
|
+
*/
|
|
2074
|
+
get method() {
|
|
2075
|
+
return this.raw.method;
|
|
2076
|
+
}
|
|
2077
|
+
get [GET_MATCH_RESULT]() {
|
|
2078
|
+
return this.#matchResult;
|
|
2079
|
+
}
|
|
2080
|
+
/**
|
|
2081
|
+
* `.matchedRoutes()` can return a matched route in the handler
|
|
2082
|
+
*
|
|
2083
|
+
* @deprecated
|
|
2084
|
+
*
|
|
2085
|
+
* Use matchedRoutes helper defined in "hono/route" instead.
|
|
2086
|
+
*
|
|
2087
|
+
* @see {@link https://hono.dev/docs/api/request#matchedroutes}
|
|
2088
|
+
*
|
|
2089
|
+
* @example
|
|
2090
|
+
* ```ts
|
|
2091
|
+
* app.use('*', async function logger(c, next) {
|
|
2092
|
+
* await next()
|
|
2093
|
+
* c.req.matchedRoutes.forEach(({ handler, method, path }, i) => {
|
|
2094
|
+
* const name = handler.name || (handler.length < 2 ? '[handler]' : '[middleware]')
|
|
2095
|
+
* console.log(
|
|
2096
|
+
* method,
|
|
2097
|
+
* ' ',
|
|
2098
|
+
* path,
|
|
2099
|
+
* ' '.repeat(Math.max(10 - path.length, 0)),
|
|
2100
|
+
* name,
|
|
2101
|
+
* i === c.req.routeIndex ? '<- respond from here' : ''
|
|
2102
|
+
* )
|
|
2103
|
+
* })
|
|
2104
|
+
* })
|
|
2105
|
+
* ```
|
|
2106
|
+
*/
|
|
2107
|
+
get matchedRoutes() {
|
|
2108
|
+
return this.#matchResult[0].map(([[, route]]) => route);
|
|
2109
|
+
}
|
|
2110
|
+
/**
|
|
2111
|
+
* `routePath()` can retrieve the path registered within the handler
|
|
2112
|
+
*
|
|
2113
|
+
* @deprecated
|
|
2114
|
+
*
|
|
2115
|
+
* Use routePath helper defined in "hono/route" instead.
|
|
2116
|
+
*
|
|
2117
|
+
* @see {@link https://hono.dev/docs/api/request#routepath}
|
|
2118
|
+
*
|
|
2119
|
+
* @example
|
|
2120
|
+
* ```ts
|
|
2121
|
+
* app.get('/posts/:id', (c) => {
|
|
2122
|
+
* return c.json({ path: c.req.routePath })
|
|
2123
|
+
* })
|
|
2124
|
+
* ```
|
|
2125
|
+
*/
|
|
2126
|
+
get routePath() {
|
|
2127
|
+
return this.#matchResult[0].map(([[, route]]) => route)[this.routeIndex].path;
|
|
2128
|
+
}
|
|
2129
|
+
};
|
|
2130
|
+
|
|
2131
|
+
// node_modules/.pnpm/hono@4.13.8/node_modules/hono/dist/router/utils.js
|
|
2132
|
+
var createNullObject = () => /* @__PURE__ */ Object.create(null);
|
|
2133
|
+
|
|
2134
|
+
// node_modules/.pnpm/hono@4.13.8/node_modules/hono/dist/router/reg-exp-router/node.js
|
|
2135
|
+
var regExpMetaChars = new Set(".\\+*[^]$()");
|
|
2136
|
+
|
|
2137
|
+
// node_modules/.pnpm/hono@4.13.8/node_modules/hono/dist/router/reg-exp-router/router.js
|
|
2138
|
+
var wildcardRegExpCache = createNullObject();
|
|
2139
|
+
|
|
2140
|
+
// node_modules/.pnpm/hono@4.13.8/node_modules/hono/dist/router/trie-router/node.js
|
|
2141
|
+
var emptyParams = createNullObject();
|
|
2142
|
+
|
|
2143
|
+
// node_modules/.pnpm/@hono+zod-openapi@1.6.3_hono@4.13.8_zod@4.6.5/node_modules/@hono/zod-openapi/dist/index.mjs
|
|
2144
|
+
import { z } from "zod";
|
|
2145
|
+
(0, import_zod_to_openapi.extendZodWithOpenApi)(z);
|
|
2146
|
+
|
|
2147
|
+
// apps/api/src/config/permissions.ts
|
|
2148
|
+
var apiKeyPermissionNames = [
|
|
2149
|
+
"environments:read",
|
|
2150
|
+
"environments:write",
|
|
2151
|
+
"environments:connect",
|
|
2152
|
+
"snapshots:read",
|
|
2153
|
+
"snapshots:write"
|
|
2154
|
+
];
|
|
2155
|
+
var permissionNames = [
|
|
2156
|
+
...apiKeyPermissionNames,
|
|
2157
|
+
"workspaces:write",
|
|
2158
|
+
"api_keys:read",
|
|
2159
|
+
"api_keys:write",
|
|
2160
|
+
"members:read",
|
|
2161
|
+
"members:write"
|
|
2162
|
+
];
|
|
2163
|
+
var cliTokenPermissionNames = [
|
|
2164
|
+
...apiKeyPermissionNames,
|
|
2165
|
+
"api_keys:read",
|
|
2166
|
+
"api_keys:write"
|
|
2167
|
+
];
|
|
2168
|
+
|
|
2169
|
+
// packages/runtime/src/protocol-profiles.ts
|
|
2170
|
+
var SERVICE_ID_PATTERN = /^[a-z][a-z0-9-]{0,39}$/;
|
|
2171
|
+
var MAX_DECLARABLE_REQUEST_BYTES = 64 * 1024 * 1024;
|
|
2172
|
+
|
|
2173
|
+
// apps/api/src/utils/api-error.ts
|
|
2174
|
+
var statuses = {
|
|
2175
|
+
invalid_request: 400,
|
|
2176
|
+
unauthenticated: 401,
|
|
2177
|
+
forbidden: 403,
|
|
2178
|
+
not_found: 404,
|
|
2179
|
+
invalid_status: 409,
|
|
2180
|
+
snapshot_in_progress: 409,
|
|
2181
|
+
idempotency_key_reused: 409,
|
|
2182
|
+
name_taken: 409,
|
|
2183
|
+
last_owner: 409,
|
|
2184
|
+
last_workspace: 409,
|
|
2185
|
+
workspace_archived: 409,
|
|
2186
|
+
version_in_use: 409,
|
|
2187
|
+
body_too_large: 413,
|
|
2188
|
+
version_unavailable: 422,
|
|
2189
|
+
environment_limit_reached: 429,
|
|
2190
|
+
rate_limited: 429,
|
|
2191
|
+
internal_error: 500,
|
|
2192
|
+
unavailable: 503
|
|
2193
|
+
};
|
|
2194
|
+
var errorCodes = Object.keys(statuses);
|
|
2195
|
+
|
|
2196
|
+
// apps/api/src/api/schemas/common.ts
|
|
2197
|
+
var idSchema = z.string().regex(/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/);
|
|
2198
|
+
var serviceIdSchema = z.string().regex(SERVICE_ID_PATTERN);
|
|
2199
|
+
var nameSchema = z.string().trim().min(1).max(120);
|
|
2200
|
+
var timestampSchema = z.iso.datetime();
|
|
2201
|
+
var principalSchema = z.object({
|
|
2202
|
+
type: z.enum(["member", "api_key", "system"]),
|
|
2203
|
+
id: z.string().nullable(),
|
|
2204
|
+
name: z.string().nullable()
|
|
2205
|
+
}).openapi("Principal");
|
|
2206
|
+
function jsonbTextBytes(value) {
|
|
2207
|
+
const text = (item) => {
|
|
2208
|
+
if (Array.isArray(item)) {
|
|
2209
|
+
return `[${item.map(text).join(", ")}]`;
|
|
2210
|
+
}
|
|
2211
|
+
if (item !== null && typeof item === "object") {
|
|
2212
|
+
return `{${Object.entries(item).map(([key, entry]) => `${JSON.stringify(key)}: ${text(entry)}`).join(", ")}}`;
|
|
2213
|
+
}
|
|
2214
|
+
return JSON.stringify(item);
|
|
2215
|
+
};
|
|
2216
|
+
return Buffer.byteLength(text(value));
|
|
2217
|
+
}
|
|
2218
|
+
var labelsSchema = z.preprocess(
|
|
2219
|
+
(value, context) => {
|
|
2220
|
+
if (value && typeof value === "object" && Object.keys(value).some(
|
|
2221
|
+
(key) => ["__proto__", "constructor", "prototype"].includes(key)
|
|
2222
|
+
)) {
|
|
2223
|
+
context.addIssue({
|
|
2224
|
+
code: "custom",
|
|
2225
|
+
message: "Reserved label keys are not allowed."
|
|
2226
|
+
});
|
|
2227
|
+
}
|
|
2228
|
+
return value;
|
|
2229
|
+
},
|
|
2230
|
+
z.record(
|
|
2231
|
+
z.string().min(1).max(63).regex(/^[A-Za-z0-9][A-Za-z0-9._/-]*$/),
|
|
2232
|
+
z.string().max(256)
|
|
2233
|
+
)
|
|
2234
|
+
).refine((value) => Object.keys(value).length <= 32, "At most 32 labels.").refine(
|
|
2235
|
+
(value) => !Object.keys(value).some(
|
|
2236
|
+
(key) => key.startsWith("usestatemachines.com/")
|
|
2237
|
+
),
|
|
2238
|
+
"The usestatemachines.com/ prefix is reserved."
|
|
2239
|
+
).refine(
|
|
2240
|
+
(value) => jsonbTextBytes(value) <= 8192,
|
|
2241
|
+
"Labels must fit within 8 KiB."
|
|
2242
|
+
);
|
|
2243
|
+
var errorSchema = z.object({
|
|
2244
|
+
error: z.object({
|
|
2245
|
+
code: z.enum(errorCodes),
|
|
2246
|
+
message: z.string(),
|
|
2247
|
+
requestId: z.string(),
|
|
2248
|
+
fields: z.record(z.string(), z.array(z.string())).optional(),
|
|
2249
|
+
status: z.string().optional()
|
|
2250
|
+
})
|
|
2251
|
+
}).openapi("Error");
|
|
2252
|
+
var pageQuerySchema = z.object({
|
|
2253
|
+
limit: z.coerce.number().int().min(1).max(100).default(50),
|
|
2254
|
+
cursor: z.string().max(2048).optional()
|
|
2255
|
+
});
|
|
2256
|
+
var idempotencyHeaderSchema = z.object({
|
|
2257
|
+
"idempotency-key": z.string().min(8).max(128).regex(/^[A-Za-z0-9._:-]+$/).optional()
|
|
2258
|
+
});
|
|
2259
|
+
function pageSchema(schema) {
|
|
2260
|
+
return z.object({ data: z.array(schema), nextCursor: z.string().nullable() });
|
|
2261
|
+
}
|
|
2262
|
+
var error = (description) => ({
|
|
2263
|
+
description,
|
|
2264
|
+
content: { "application/json": { schema: errorSchema } }
|
|
2265
|
+
});
|
|
2266
|
+
var standardErrors = {
|
|
2267
|
+
400: error("Invalid request"),
|
|
2268
|
+
401: error("Authentication required"),
|
|
2269
|
+
403: error("Permission denied"),
|
|
2270
|
+
404: error("Resource not found"),
|
|
2271
|
+
409: error("Conflicting request"),
|
|
2272
|
+
413: error("Request body too large"),
|
|
2273
|
+
422: error("Version unavailable"),
|
|
2274
|
+
429: error("Limit reached"),
|
|
2275
|
+
500: error("Unexpected failure"),
|
|
2276
|
+
503: error("Dependency unavailable")
|
|
2277
|
+
};
|
|
2278
|
+
|
|
2279
|
+
// apps/api/src/api/schemas/api-keys.ts
|
|
2280
|
+
var apiKeyPermissionSchema = z.enum(apiKeyPermissionNames).openapi("ApiKeyPermission");
|
|
2281
|
+
var apiKeySchema = z.object({
|
|
2282
|
+
id: idSchema,
|
|
2283
|
+
workspaceId: idSchema,
|
|
2284
|
+
name: z.string(),
|
|
2285
|
+
displayValue: z.string(),
|
|
2286
|
+
/** From WorkOS, the authority. A revoke answers what the key held; a revoked key holds none. */
|
|
2287
|
+
permissions: z.array(apiKeyPermissionSchema),
|
|
2288
|
+
createdBy: principalSchema,
|
|
2289
|
+
createdAt: timestampSchema,
|
|
2290
|
+
lastUsedAt: timestampSchema.nullable(),
|
|
2291
|
+
revokedAt: timestampSchema.nullable(),
|
|
2292
|
+
kind: z.enum(["dashboard", "cli_run", "env_pull"]),
|
|
2293
|
+
expiresAt: timestampSchema.nullable()
|
|
2294
|
+
}).openapi("ApiKey");
|
|
2295
|
+
var apiKeyListQuerySchema = pageQuerySchema.extend({
|
|
2296
|
+
workspaceId: idSchema
|
|
2297
|
+
});
|
|
2298
|
+
var createApiKeySchema = z.object({
|
|
2299
|
+
workspaceId: idSchema,
|
|
2300
|
+
name: nameSchema,
|
|
2301
|
+
permissions: z.array(apiKeyPermissionSchema).min(1).max(5),
|
|
2302
|
+
kind: z.enum(["cli_run", "env_pull"]).optional()
|
|
2303
|
+
});
|
|
2304
|
+
var createdApiKeySchema = z.object({
|
|
2305
|
+
apiKey: apiKeySchema,
|
|
2306
|
+
secret: z.string().optional()
|
|
2307
|
+
});
|
|
2308
|
+
var apiKeyIdSchema = z.object({ apiKeyId: idSchema });
|
|
2309
|
+
|
|
2310
|
+
// apps/api/src/auth/cli-sealing.ts
|
|
2311
|
+
import { z as z2 } from "zod";
|
|
2312
|
+
var sealedCliTokenSchema = z2.object({
|
|
2313
|
+
v: z2.literal(1),
|
|
2314
|
+
serverPublicKey: z2.string(),
|
|
2315
|
+
nonce: z2.string(),
|
|
2316
|
+
ciphertext: z2.string(),
|
|
2317
|
+
tag: z2.string()
|
|
2318
|
+
});
|
|
2319
|
+
|
|
2320
|
+
// apps/api/src/api/schemas/cli-logins.ts
|
|
2321
|
+
var cliUserCodeSchema = z.string().trim().toUpperCase().regex(/^[BCDFGHJKLMNPQRSTVWXZ]{4}-?[BCDFGHJKLMNPQRSTVWXZ]{4}$/).transform((value) => value.replace("-", ""));
|
|
2322
|
+
var printable = /^[^\p{Cc}\u061c\u200e\u200f\u202a-\u202e\u2066-\u2069]*$/u;
|
|
2323
|
+
var metadata = (max) => z.string().trim().min(1).max(max).regex(printable);
|
|
2324
|
+
var startCliLoginSchema = z.object({
|
|
2325
|
+
publicKey: z.string().max(128),
|
|
2326
|
+
cliVersion: metadata(32),
|
|
2327
|
+
hostname: metadata(64),
|
|
2328
|
+
platform: metadata(32)
|
|
2329
|
+
});
|
|
2330
|
+
var startedCliLoginSchema = z.object({
|
|
2331
|
+
loginId: idSchema,
|
|
2332
|
+
deviceCode: z.string(),
|
|
2333
|
+
userCode: z.string(),
|
|
2334
|
+
verificationUrl: z.url(),
|
|
2335
|
+
expiresIn: z.number().int(),
|
|
2336
|
+
interval: z.number().int()
|
|
2337
|
+
});
|
|
2338
|
+
var cliLoginDetailsSchema = z.discriminatedUnion("status", [
|
|
2339
|
+
z.object({
|
|
2340
|
+
loginId: idSchema,
|
|
2341
|
+
userCode: z.string(),
|
|
2342
|
+
status: z.literal("pending"),
|
|
2343
|
+
hostname: z.string(),
|
|
2344
|
+
platform: z.string(),
|
|
2345
|
+
cliVersion: z.string(),
|
|
2346
|
+
location: z.string().nullable(),
|
|
2347
|
+
createdAt: timestampSchema,
|
|
2348
|
+
expiresAt: timestampSchema,
|
|
2349
|
+
permissions: z.array(z.enum(cliTokenPermissionNames))
|
|
2350
|
+
}),
|
|
2351
|
+
z.object({
|
|
2352
|
+
loginId: idSchema,
|
|
2353
|
+
userCode: z.string(),
|
|
2354
|
+
status: z.enum(["approved", "collected", "denied"])
|
|
2355
|
+
})
|
|
2356
|
+
]);
|
|
2357
|
+
var cliLoginDecisionSchema = z.object({ userCode: cliUserCodeSchema });
|
|
2358
|
+
var cliLoginLookupSchema = z.object({ userCode: cliUserCodeSchema });
|
|
2359
|
+
var cliLoginIdSchema = z.object({
|
|
2360
|
+
loginId: z.string().regex(/^cli_login_[0-9a-z]{16}$/)
|
|
2361
|
+
});
|
|
2362
|
+
var approvedCliLoginSchema = z.object({
|
|
2363
|
+
loginId: idSchema,
|
|
2364
|
+
status: z.literal("approved")
|
|
2365
|
+
});
|
|
2366
|
+
var deniedCliLoginSchema = z.object({
|
|
2367
|
+
loginId: idSchema,
|
|
2368
|
+
status: z.literal("denied")
|
|
2369
|
+
});
|
|
2370
|
+
var collectedCliLoginSchema = z.object({
|
|
2371
|
+
loginId: idSchema,
|
|
2372
|
+
status: z.literal("collected")
|
|
2373
|
+
});
|
|
2374
|
+
var pollCliLoginSchema = z.object({
|
|
2375
|
+
deviceCode: z.string().regex(/^[A-Za-z0-9_-]{43}$/)
|
|
2376
|
+
});
|
|
2377
|
+
var cliLoginPollErrorSchema = z.object({
|
|
2378
|
+
error: z.enum([
|
|
2379
|
+
"authorization_pending",
|
|
2380
|
+
"slow_down",
|
|
2381
|
+
"access_denied",
|
|
2382
|
+
"expired_token"
|
|
2383
|
+
]),
|
|
2384
|
+
interval: z.number().int()
|
|
2385
|
+
});
|
|
2386
|
+
var cliLoginTokenSchema = z.object({
|
|
2387
|
+
envelope: sealedCliTokenSchema,
|
|
2388
|
+
tokenId: idSchema,
|
|
2389
|
+
idleExpiresAt: timestampSchema,
|
|
2390
|
+
expiresAt: timestampSchema,
|
|
2391
|
+
organization: z.object({ id: z.string(), name: z.string() }),
|
|
2392
|
+
user: z.object({ email: z.string() })
|
|
2393
|
+
});
|
|
2394
|
+
|
|
2395
|
+
// apps/api/src/api/schemas/cli-tokens.ts
|
|
2396
|
+
var cliTokenSchema = z.object({
|
|
2397
|
+
id: idSchema,
|
|
2398
|
+
name: z.string(),
|
|
2399
|
+
createdAt: timestampSchema,
|
|
2400
|
+
lastUsedAt: timestampSchema.nullable(),
|
|
2401
|
+
idleExpiresAt: timestampSchema,
|
|
2402
|
+
expiresAt: timestampSchema,
|
|
2403
|
+
revokedAt: timestampSchema.nullable()
|
|
2404
|
+
});
|
|
2405
|
+
var cliTokenListSchema = pageSchema(cliTokenSchema);
|
|
2406
|
+
|
|
2407
|
+
// apps/api/src/auth/analytics-source.ts
|
|
2408
|
+
import { z as z3 } from "zod";
|
|
2409
|
+
var cliAgentSchema = z3.enum([
|
|
2410
|
+
"claude_code",
|
|
2411
|
+
"codex_cli",
|
|
2412
|
+
"cursor",
|
|
2413
|
+
"cursor-cli",
|
|
2414
|
+
"gemini_cli",
|
|
2415
|
+
"github-copilot"
|
|
2416
|
+
]);
|
|
2417
|
+
var cliVersionSchema = z3.string().max(32).regex(/^[0-9]+\.[0-9]+\.[0-9]+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/);
|
|
2418
|
+
|
|
2419
|
+
// packages/http/src/environment-token.ts
|
|
2420
|
+
var ENVIRONMENT_TOKEN_HEADER = "StateMachines-Environment-Token";
|
|
2421
|
+
var TOKEN_PATTERN = "[A-Za-z0-9_-]{1,256}";
|
|
2422
|
+
var COMBINED_BEARER_PREFIX = "state_app_";
|
|
2423
|
+
var COMBINED = new RegExp(
|
|
2424
|
+
`^${COMBINED_BEARER_PREFIX}(${TOKEN_PATTERN})\\.(${TOKEN_PATTERN})$`
|
|
2425
|
+
);
|
|
2426
|
+
|
|
2427
|
+
// packages/http/src/credential-variables.ts
|
|
2428
|
+
var HTTP_TOKEN = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/;
|
|
2429
|
+
var NAMED_HEADERS = /* @__PURE__ */ new Map([
|
|
2430
|
+
[ENVIRONMENT_TOKEN_HEADER.toLowerCase(), "ENVIRONMENT_TOKEN"],
|
|
2431
|
+
["authorization", "AUTHORIZATION"]
|
|
2432
|
+
]);
|
|
2433
|
+
function variablePart(value) {
|
|
2434
|
+
return value.toUpperCase().replace(/[^A-Z0-9]/g, "_");
|
|
2435
|
+
}
|
|
2436
|
+
function serviceVariable(appName, serviceId, slot) {
|
|
2437
|
+
return `STATEMACHINES_${variablePart(appName)}_${variablePart(serviceId)}_${slot}`;
|
|
2438
|
+
}
|
|
2439
|
+
function mcpServerVariable(appName, serviceId, serverName) {
|
|
2440
|
+
return `STATEMACHINES_${variablePart(appName)}_${variablePart(serviceId)}_MCP_${variablePart(serverName)}_URL`;
|
|
2441
|
+
}
|
|
2442
|
+
function actorTokenVariable(appName) {
|
|
2443
|
+
return `STATEMACHINES_${variablePart(appName)}_ACTOR_TOKEN`;
|
|
2444
|
+
}
|
|
2445
|
+
function uniqueHeaders(headers) {
|
|
2446
|
+
const byName = /* @__PURE__ */ new Map();
|
|
2447
|
+
for (const [name, value] of Object.entries(headers)) {
|
|
2448
|
+
if (!HTTP_TOKEN.test(name)) {
|
|
2449
|
+
continue;
|
|
2450
|
+
}
|
|
2451
|
+
const earlier = byName.get(name.toLowerCase());
|
|
2452
|
+
byName.set(
|
|
2453
|
+
name.toLowerCase(),
|
|
2454
|
+
earlier ? { ...earlier, value: `${earlier.value}, ${value}` } : { name, value }
|
|
2455
|
+
);
|
|
2456
|
+
}
|
|
2457
|
+
return [...byName.values()];
|
|
2458
|
+
}
|
|
2459
|
+
function headerVariables(appName, serviceId, headers) {
|
|
2460
|
+
return uniqueHeaders(headers).map(({ name, value }, index) => {
|
|
2461
|
+
const slot = NAMED_HEADERS.get(name.toLowerCase()) ?? `HEADER_${index + 1}`;
|
|
2462
|
+
return {
|
|
2463
|
+
name,
|
|
2464
|
+
value,
|
|
2465
|
+
slot,
|
|
2466
|
+
variable: serviceVariable(appName, serviceId, slot)
|
|
2467
|
+
};
|
|
2468
|
+
});
|
|
2469
|
+
}
|
|
2470
|
+
|
|
2471
|
+
// packages/sdk/esm/models/error.js
|
|
2472
|
+
import * as z6 from "zod/v4-mini";
|
|
2473
|
+
|
|
2474
|
+
// packages/sdk/esm/types/enums.js
|
|
2475
|
+
import * as z4 from "zod/v4-mini";
|
|
2476
|
+
|
|
2477
|
+
// packages/sdk/esm/types/unrecognized.js
|
|
2478
|
+
function unrecognized(value) {
|
|
2479
|
+
globalCount++;
|
|
2480
|
+
return value;
|
|
2481
|
+
}
|
|
2482
|
+
var globalCount = 0;
|
|
2483
|
+
|
|
2484
|
+
// packages/sdk/esm/types/enums.js
|
|
2485
|
+
function inboundSchema(enumObj) {
|
|
2486
|
+
const options = Object.values(enumObj);
|
|
2487
|
+
return z4.union([
|
|
2488
|
+
...options.map((x) => z4.literal(x)),
|
|
2489
|
+
z4.pipe(z4.string(), z4.transform((x) => unrecognized(x)))
|
|
2490
|
+
]);
|
|
2491
|
+
}
|
|
2492
|
+
|
|
2493
|
+
// packages/sdk/esm/types/primitives.js
|
|
2494
|
+
import * as z5 from "zod/v4-mini";
|
|
2495
|
+
|
|
2496
|
+
// packages/sdk/esm/types/default-to-zero-value.js
|
|
2497
|
+
var globalCount2 = 0;
|
|
2498
|
+
function defaultToZeroValue(value) {
|
|
2499
|
+
globalCount2++;
|
|
2500
|
+
return unrecognized(value);
|
|
2501
|
+
}
|
|
2502
|
+
|
|
2503
|
+
// packages/sdk/esm/types/primitives.js
|
|
2504
|
+
function string3() {
|
|
2505
|
+
return z5.union([
|
|
2506
|
+
z5.string(),
|
|
2507
|
+
// Null or undefined -> ""
|
|
2508
|
+
zodDefaultToZeroValue(""),
|
|
2509
|
+
// Any other value -> String(x)
|
|
2510
|
+
z5.pipe(z5.any(), z5.transform((x) => unrecognized(JSON.stringify(x))))
|
|
2511
|
+
]);
|
|
2512
|
+
}
|
|
2513
|
+
function optional2(t) {
|
|
2514
|
+
return z5.optional(z5.union([
|
|
2515
|
+
// Null -> undefined
|
|
2516
|
+
z5.pipe(z5.null(), z5.transform(() => unrecognized(void 0))),
|
|
2517
|
+
t
|
|
2518
|
+
]));
|
|
2519
|
+
}
|
|
2520
|
+
function zodDefaultToZeroValue(value) {
|
|
2521
|
+
return z5.pipe(z5.any(), z5.transform((input, ctx) => {
|
|
2522
|
+
if (input === void 0)
|
|
2523
|
+
return defaultToZeroValue(value);
|
|
2524
|
+
if (input === null)
|
|
2525
|
+
return defaultToZeroValue(value);
|
|
2526
|
+
ctx.issues.push({
|
|
2527
|
+
input,
|
|
2528
|
+
code: "invalid_type",
|
|
2529
|
+
expected: "undefined",
|
|
2530
|
+
received: "unknown"
|
|
2531
|
+
});
|
|
2532
|
+
return z5.NEVER;
|
|
2533
|
+
}));
|
|
2534
|
+
}
|
|
2535
|
+
|
|
2536
|
+
// packages/sdk/esm/models/error.js
|
|
2537
|
+
var ErrorCode = {
|
|
2538
|
+
InvalidRequest: "invalid_request",
|
|
2539
|
+
Unauthenticated: "unauthenticated",
|
|
2540
|
+
Forbidden: "forbidden",
|
|
2541
|
+
NotFound: "not_found",
|
|
2542
|
+
InvalidStatus: "invalid_status",
|
|
2543
|
+
SnapshotInProgress: "snapshot_in_progress",
|
|
2544
|
+
IdempotencyKeyReused: "idempotency_key_reused",
|
|
2545
|
+
NameTaken: "name_taken",
|
|
2546
|
+
LastOwner: "last_owner",
|
|
2547
|
+
LastWorkspace: "last_workspace",
|
|
2548
|
+
WorkspaceArchived: "workspace_archived",
|
|
2549
|
+
VersionInUse: "version_in_use",
|
|
2550
|
+
BodyTooLarge: "body_too_large",
|
|
2551
|
+
VersionUnavailable: "version_unavailable",
|
|
2552
|
+
EnvironmentLimitReached: "environment_limit_reached",
|
|
2553
|
+
RateLimited: "rate_limited",
|
|
2554
|
+
InternalError: "internal_error",
|
|
2555
|
+
Unavailable: "unavailable"
|
|
2556
|
+
};
|
|
2557
|
+
var ErrorCode$inboundSchema = inboundSchema(ErrorCode);
|
|
2558
|
+
var ErrorT$inboundSchema = z6.object({
|
|
2559
|
+
code: ErrorCode$inboundSchema,
|
|
2560
|
+
fields: optional2(z6.record(z6.string(), z6.array(string3()))),
|
|
2561
|
+
message: string3(),
|
|
2562
|
+
requestId: string3(),
|
|
2563
|
+
status: optional2(string3())
|
|
2564
|
+
});
|
|
2565
|
+
|
|
2566
|
+
// packages/cli/contracts/internal.ts
|
|
2567
|
+
var parseStartLogin = (input) => startCliLoginSchema.parse(input);
|
|
2568
|
+
var parseStartedLogin = (input) => startedCliLoginSchema.parse(input);
|
|
2569
|
+
var parseLoginToken = (input) => cliLoginTokenSchema.parse(input);
|
|
2570
|
+
var parsePollError = (input) => cliLoginPollErrorSchema.parse(input);
|
|
2571
|
+
var parseCollected = (input) => collectedCliLoginSchema.parse(input);
|
|
2572
|
+
var parseCreateKey = (input) => createApiKeySchema.parse(input);
|
|
2573
|
+
var keyPolicy = {
|
|
2574
|
+
permissions: createApiKeySchema.shape.permissions.element.options,
|
|
2575
|
+
maxNameLength: createApiKeySchema.shape.name.maxLength
|
|
2576
|
+
};
|
|
2577
|
+
var parseEnvironmentLabels = (input) => labelsSchema.parse(input);
|
|
2578
|
+
var parseCreatedKey = (input) => createdApiKeySchema.parse(input);
|
|
2579
|
+
var parseKey = (input) => apiKeySchema.parse(input);
|
|
2580
|
+
var parseKeyListQuery = (input) => apiKeyListQuerySchema.parse(input);
|
|
2581
|
+
var parseKeyList = (input) => pageSchema(apiKeySchema).parse(input);
|
|
2582
|
+
var parseTokenList = (input) => cliTokenListSchema.parse(input);
|
|
2583
|
+
var parseAgent = (input) => {
|
|
2584
|
+
const result = cliAgentSchema.safeParse(input);
|
|
2585
|
+
return result.success ? result.data : null;
|
|
2586
|
+
};
|
|
2587
|
+
function parseApiError(input) {
|
|
2588
|
+
const envelope = z7.object({ error: z7.unknown() }).parse(input);
|
|
2589
|
+
const error2 = ErrorT$inboundSchema.parse(envelope.error);
|
|
2590
|
+
return {
|
|
2591
|
+
code: error2.code,
|
|
2592
|
+
message: error2.message,
|
|
2593
|
+
requestId: error2.requestId,
|
|
2594
|
+
fields: error2.fields ?? null
|
|
2595
|
+
};
|
|
2596
|
+
}
|
|
2597
|
+
var credentialVariables = (appName, actorToken, services) => [
|
|
2598
|
+
...services.flatMap(({ id, url, headers, servers }) => [
|
|
2599
|
+
[serviceVariable(appName, id, "URL"), url],
|
|
2600
|
+
...headerVariables(appName, id, headers).map(
|
|
2601
|
+
({ variable, value }) => [variable, value]
|
|
2602
|
+
),
|
|
2603
|
+
...(servers ?? []).map(({ name, url: url2 }) => [
|
|
2604
|
+
mcpServerVariable(appName, id, name),
|
|
2605
|
+
url2
|
|
2606
|
+
])
|
|
2607
|
+
]),
|
|
2608
|
+
[actorTokenVariable(appName), actorToken]
|
|
2609
|
+
];
|
|
2610
|
+
export {
|
|
2611
|
+
credentialVariables,
|
|
2612
|
+
keyPolicy,
|
|
2613
|
+
parseAgent,
|
|
2614
|
+
parseApiError,
|
|
2615
|
+
parseCollected,
|
|
2616
|
+
parseCreateKey,
|
|
2617
|
+
parseCreatedKey,
|
|
2618
|
+
parseEnvironmentLabels,
|
|
2619
|
+
parseKey,
|
|
2620
|
+
parseKeyList,
|
|
2621
|
+
parseKeyListQuery,
|
|
2622
|
+
parseLoginToken,
|
|
2623
|
+
parsePollError,
|
|
2624
|
+
parseStartLogin,
|
|
2625
|
+
parseStartedLogin,
|
|
2626
|
+
parseTokenList
|
|
2627
|
+
};
|