@statelyai/sdk 0.39.1 → 0.41.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/README.md +10 -0
- package/dist/assetStorage.d.mts +1 -1
- package/dist/chunk-D1OLi6Wq.mjs +46 -0
- package/dist/editorHostProtocol.d.mts +3 -3
- package/dist/embed.d.mts +4 -3
- package/dist/embed.mjs +10 -3
- package/dist/{graph-CfWCJS4m.d.mts → graph-DbZdSisK.d.mts} +1 -1
- package/dist/graph.d.mts +1 -1
- package/dist/{index-DfMkVP94.d.mts → index-DqF1xP8P.d.mts} +50 -406
- package/dist/index.d.mts +5 -5
- package/dist/index.mjs +3 -3
- package/dist/{inspect-DXtP_tPO.mjs → inspect-CDjr4saL.mjs} +1 -1
- package/dist/{inspect-JNvMtuzC.d.mts → inspect-ruD95iBM.d.mts} +1 -1
- package/dist/inspect.d.mts +2 -2
- package/dist/inspect.mjs +2 -2
- package/dist/machineGraph-DYtFKHlq-BpWpGU22.mjs +3 -0
- package/dist/machineGraph-DYtFKHlq-ChbeTHlv.mjs +1023 -0
- package/dist/patchTypes.d.mts +1 -1
- package/dist/{protocol-D3XQmmmv.d.mts → protocol-BvElOcXs.d.mts} +17 -5
- package/dist/protocol.d.mts +1 -1
- package/dist/relay.d.mts +1 -1
- package/dist/rolldown-runtime-95iHPtFO-Bo6l7CbO.mjs +114 -0
- package/dist/{studio-DL0yj2Pi.mjs → schemas-DsQ8UYlM.mjs} +36 -1642
- package/dist/sourceCoverage.d.mts +101 -0
- package/dist/sourceCoverage.mjs +3572 -0
- package/dist/studio-DH7OeLao.mjs +1604 -0
- package/dist/{studio-ClBs4caM.d.mts → studio-DRw9sxCm.d.mts} +20 -2
- package/dist/studio.d.mts +1 -1
- package/dist/studio.mjs +1 -1
- package/dist/{version-gEUUpYtd.mjs → version-eag6cuvm.mjs} +1 -1
- package/dist/xstateSource-BUCx2xA4-CWteIFJn.d.mts +451 -0
- package/dist/xstateSource-JvwXWv6G-KnMMoZlG.mjs +151753 -0
- package/package.json +9 -5
- /package/dist/{editor-sync-types-Ch5P5XRj.d.mts → editor-sync-types-BjgSBGxf.d.mts} +0 -0
- /package/dist/{patchTypes-BZ7gzwAP.d.mts → patchTypes-BFlvJTDJ.d.mts} +0 -0
|
@@ -0,0 +1,1604 @@
|
|
|
1
|
+
import { r as __exportAll, t as __commonJSMin } from "./chunk-D1OLi6Wq.mjs";
|
|
2
|
+
import { $ as ZodString, $n as uuid, $r as _property, $t as int, A as ZodJWT, An as preprocess, Ar as _coercedDate, At as boolean$1, B as ZodNull, Bn as stringbool, Br as _lte, Bt as discriminatedUnion, C as ZodExactOptional, Ci as config, Cn as nullish, Cr as iso_exports, Ct as _undefined, D as ZodIPv4, Dn as partialRecord, Dr as TimePrecision, Dt as base64, E as ZodGUID, En as optional, Er as toJSONSchema, Et as array, F as ZodMap, Fn as schemas_exports, Fr as _gte, Ft as cuid, G as ZodOptional, Gn as transform, Gr as _minSize, Gt as file, H as ZodNumber, Hn as superRefine, Hr as _maxSize, Ht as email, I as ZodNaN, In as set, Ir as _includes, It as cuid2, J as ZodPreprocess, Jn as uint64, Jr as _nonnegative, Jt as guid, K as ZodPipe, Kn as tuple, Kr as _multipleOf, Kt as float32, L as ZodNanoID, Ln as strictObject, Lr as _length, Lt as custom, M as ZodLazy, Mn as readonly, Mr as _coercedString, Mt as cidrv4, N as ZodLiteral, Nn as record, Nr as _endsWith, Nt as cidrv6, O as ZodIPv6, On as pipe, Or as _coercedBigint, Ot as base64url, P as ZodMAC, Pn as refine, Pr as _gt, Pt as codec, Q as ZodSet, Qn as url, Qr as _positive, Qt as httpUrl, R as ZodNever, Rn as string$1, Rr as _lowercase, Rt as date$1, S as ZodEnum, Si as NEVER, Sn as nullable, Sr as ZodISOTime, St as _null, T as ZodFunction, Tn as object, Tr as core_exports, Tt as any, U as ZodNumberFormat, Un as symbol, Ur as _mime, Ut as emoji, V as ZodNullable, Vn as success, Vr as _maxLength, Vt as e164, W as ZodObject, Wn as templateLiteral, Wr as _minLength, Wt as exactOptional, X as ZodReadonly, Xn as union, Xr as _normalize, Xt as hex, Y as ZodPromise, Yn as ulid, Yr as _nonpositive, Yt as hash, Z as ZodRecord, Zn as unknown, Zr as _overwrite, Zt as hostname, _ as ZodDefault, _i as prettifyError, _n as nan, _r as ZodError, _t as _catch, a as ZodBigInt, ai as _toUpperCase, an as ipv6, ar as decode, at as ZodTuple, b as ZodEmail, bi as util_exports, bn as never, br as ZodISODateTime, bt as _function, c as ZodCIDRv4, ci as $input, cn as keyof, cr as encodeAsync, ct as ZodURL, d as ZodCUID2, di as registry, dn as literal, dr as safeDecode, dt as ZodUnion, ei as _regex, en as int32, er as uuidv4, et as ZodStringFormat, f as ZodCatch, fi as locales_exports, fn as looseObject, fr as safeDecodeAsync, ft as ZodUnknown, g as ZodDate, gi as formatError, gn as meta, gr as safeParseAsync, gt as _ZodString, h as ZodCustomStringFormat, hi as flattenError, hn as map, hr as safeParse, ht as ZodXor, i as ZodBase64URL, ii as _toLowerCase, in as ipv4, ir as xor, it as ZodTransform, j as ZodKSUID, jn as promise, jr as _coercedNumber, jt as check, k as ZodIntersection, kn as prefault, kr as _coercedBoolean, kt as bigint$1, l as ZodCIDRv6, li as $output, ln as ksuid, lr as parse, lt as ZodUUID, m as ZodCustom, mi as regexes_exports, mn as mac, mr as safeEncodeAsync, mt as ZodXID, n as ZodArray, ni as _slugify, nn as intersection, nr as uuidv7, nt as ZodSymbol, o as ZodBigIntFormat, oi as _trim, on as json, or as decodeAsync, ot as ZodType, p as ZodCodec, pi as en_default, pn as looseRecord, pr as safeEncode, pt as ZodVoid, q as ZodPrefault, qn as uint32, qr as _negative, qt as float64, r as ZodBase64, ri as _startsWith, rn as invertCodec, rr as xid, rt as ZodTemplateLiteral, s as ZodBoolean, si as _uppercase, sn as jwt, sr as encode, st as ZodULID, t as ZodAny, ti as _size, tn as int64, tr as uuidv6, tt as ZodSuccess, u as ZodCUID, ui as globalRegistry, un as lazy, ur as parseAsync, ut as ZodUndefined, v as ZodDiscriminatedUnion, vi as treeifyError, vn as nanoid, vr as ZodRealError, vt as _default, w as ZodFile, wn as number$1, wr as checks_exports, wt as _void, x as ZodEmoji, xi as $brand, xn as nonoptional, xr as ZodISODuration, xt as _instanceof, y as ZodE164, yi as clone, yn as nativeEnum, yr as ZodISODate, yt as _enum, z as ZodNonOptional, zn as stringFormat, zr as _lt, zt as describe } from "./schemas-DsQ8UYlM.mjs";
|
|
3
|
+
import { createAuthorizationHeader, getCredentialToken } from "./auth.mjs";
|
|
4
|
+
|
|
5
|
+
//#region ../../node_modules/.pnpm/@asteasolutions+zod-to-openapi@8.5.0_zod@4.4.3/node_modules/@asteasolutions/zod-to-openapi/dist/index.cjs
|
|
6
|
+
var require_dist = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
7
|
+
/******************************************************************************
|
|
8
|
+
Copyright (c) Microsoft Corporation.
|
|
9
|
+
|
|
10
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
11
|
+
purpose with or without fee is hereby granted.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
14
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
15
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
16
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
17
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
18
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
19
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
20
|
+
***************************************************************************** */
|
|
21
|
+
function __rest(s, e) {
|
|
22
|
+
var t = {};
|
|
23
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
|
24
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function") {
|
|
25
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
|
26
|
+
}
|
|
27
|
+
return t;
|
|
28
|
+
}
|
|
29
|
+
const ZodTypeKeys = {
|
|
30
|
+
ZodAny: "any",
|
|
31
|
+
ZodArray: "array",
|
|
32
|
+
ZodBigInt: "bigint",
|
|
33
|
+
ZodBoolean: "boolean",
|
|
34
|
+
ZodDefault: "default",
|
|
35
|
+
ZodPrefault: "prefault",
|
|
36
|
+
ZodTransform: "transform",
|
|
37
|
+
ZodEnum: "enum",
|
|
38
|
+
ZodIntersection: "intersection",
|
|
39
|
+
ZodLazy: "lazy",
|
|
40
|
+
ZodLiteral: "literal",
|
|
41
|
+
ZodNever: "never",
|
|
42
|
+
ZodNull: "null",
|
|
43
|
+
ZodNullable: "nullable",
|
|
44
|
+
ZodNumber: "number",
|
|
45
|
+
ZodNonOptional: "nonoptional",
|
|
46
|
+
ZodObject: "object",
|
|
47
|
+
ZodOptional: "optional",
|
|
48
|
+
ZodPipe: "pipe",
|
|
49
|
+
ZodReadonly: "readonly",
|
|
50
|
+
ZodRecord: "record",
|
|
51
|
+
ZodString: "string",
|
|
52
|
+
ZodTuple: "tuple",
|
|
53
|
+
ZodType: "type",
|
|
54
|
+
ZodUnion: "union",
|
|
55
|
+
ZodDiscriminatedUnion: "union",
|
|
56
|
+
ZodUnknown: "unknown",
|
|
57
|
+
ZodVoid: "void",
|
|
58
|
+
ZodDate: "date",
|
|
59
|
+
ZodTemplateLiteral: "template_literal"
|
|
60
|
+
};
|
|
61
|
+
function isZodType(schema, typeNames) {
|
|
62
|
+
return (Array.isArray(typeNames) ? typeNames : [typeNames]).some((typeName) => {
|
|
63
|
+
var _a;
|
|
64
|
+
const typeNameMatch = ((_a = schema === null || schema === void 0 ? void 0 : schema.def) === null || _a === void 0 ? void 0 : _a.type) === ZodTypeKeys[typeName];
|
|
65
|
+
if (typeName === "ZodDiscriminatedUnion") return typeNameMatch && "discriminator" in schema.def;
|
|
66
|
+
return typeNameMatch;
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
function isAnyZodType(schema) {
|
|
70
|
+
return schema && "def" in schema;
|
|
71
|
+
}
|
|
72
|
+
var $ZodRegistry = class {
|
|
73
|
+
constructor() {
|
|
74
|
+
this._map = /* @__PURE__ */ new Map();
|
|
75
|
+
this._idmap = /* @__PURE__ */ new Map();
|
|
76
|
+
}
|
|
77
|
+
add(schema, ..._meta) {
|
|
78
|
+
const meta = _meta[0];
|
|
79
|
+
this._map.set(schema, meta);
|
|
80
|
+
if (meta && typeof meta === "object" && "id" in meta) {
|
|
81
|
+
if (this._idmap.has(meta.id)) throw new Error(`ID ${meta.id} already exists in the registry`);
|
|
82
|
+
this._idmap.set(meta.id, schema);
|
|
83
|
+
}
|
|
84
|
+
return this;
|
|
85
|
+
}
|
|
86
|
+
clear() {
|
|
87
|
+
this._map = /* @__PURE__ */ new Map();
|
|
88
|
+
this._idmap = /* @__PURE__ */ new Map();
|
|
89
|
+
return this;
|
|
90
|
+
}
|
|
91
|
+
remove(schema) {
|
|
92
|
+
const meta = this._map.get(schema);
|
|
93
|
+
if (meta && typeof meta === "object" && "id" in meta) this._idmap.delete(meta.id);
|
|
94
|
+
this._map.delete(schema);
|
|
95
|
+
return this;
|
|
96
|
+
}
|
|
97
|
+
get(schema) {
|
|
98
|
+
const p = schema._zod.parent;
|
|
99
|
+
if (p) {
|
|
100
|
+
const pm = { ...this.get(p) ?? {} };
|
|
101
|
+
delete pm.id;
|
|
102
|
+
return {
|
|
103
|
+
...pm,
|
|
104
|
+
...this._map.get(schema)
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
return this._map.get(schema);
|
|
108
|
+
}
|
|
109
|
+
has(schema) {
|
|
110
|
+
return this._map.has(schema);
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
function registry() {
|
|
114
|
+
return new $ZodRegistry();
|
|
115
|
+
}
|
|
116
|
+
function isUndefined(value) {
|
|
117
|
+
return value === void 0;
|
|
118
|
+
}
|
|
119
|
+
function omit(object, keys) {
|
|
120
|
+
const result = {};
|
|
121
|
+
Object.entries(object).forEach(([key, value]) => {
|
|
122
|
+
if (!keys.some((keyToOmit) => keyToOmit === key)) result[key] = value;
|
|
123
|
+
});
|
|
124
|
+
return result;
|
|
125
|
+
}
|
|
126
|
+
function omitBy(object, predicate) {
|
|
127
|
+
const result = {};
|
|
128
|
+
Object.entries(object).forEach(([key, value]) => {
|
|
129
|
+
if (!predicate(value, key)) result[key] = value;
|
|
130
|
+
});
|
|
131
|
+
return result;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* @deprecated This is not really deprecated but this should always be used with
|
|
135
|
+
* caution. Using it may alter the behavior of the library and the generated schemas.
|
|
136
|
+
*/
|
|
137
|
+
const zodToOpenAPIRegistry = registry();
|
|
138
|
+
var Metadata = class {
|
|
139
|
+
static collectMetadata(schema, metadata) {
|
|
140
|
+
const currentMetadata = this.getMetadataFromRegistry(schema);
|
|
141
|
+
const _internal = Object.assign(Object.assign({}, currentMetadata === null || currentMetadata === void 0 ? void 0 : currentMetadata._internal), metadata === null || metadata === void 0 ? void 0 : metadata._internal);
|
|
142
|
+
const param = Object.assign(Object.assign({}, currentMetadata === null || currentMetadata === void 0 ? void 0 : currentMetadata.param), metadata === null || metadata === void 0 ? void 0 : metadata.param);
|
|
143
|
+
const totalMetadata = Object.assign(Object.assign(Object.assign(Object.assign({}, Object.keys(_internal).length > 0 ? { _internal } : {}), currentMetadata), metadata), Object.keys(param).length > 0 ? { param } : {});
|
|
144
|
+
if (isZodType(schema, [
|
|
145
|
+
"ZodOptional",
|
|
146
|
+
"ZodNullable",
|
|
147
|
+
"ZodDefault",
|
|
148
|
+
"ZodPrefault",
|
|
149
|
+
"ZodReadonly",
|
|
150
|
+
"ZodNonOptional"
|
|
151
|
+
]) && isAnyZodType(schema._zod.def.innerType)) return this.collectMetadata(schema._zod.def.innerType, totalMetadata);
|
|
152
|
+
if (isZodType(schema, "ZodPipe")) {
|
|
153
|
+
const inSchema = schema._zod.def.in;
|
|
154
|
+
const outSchema = schema._zod.def.out;
|
|
155
|
+
if (isZodType(inSchema, "ZodTransform") && isAnyZodType(outSchema)) return this.collectMetadata(outSchema, totalMetadata);
|
|
156
|
+
if (isAnyZodType(inSchema)) return this.collectMetadata(inSchema, totalMetadata);
|
|
157
|
+
}
|
|
158
|
+
return totalMetadata;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* @deprecated Use one of `getOpenApiMetadata` or `getInternalMetadata` instead
|
|
162
|
+
*/
|
|
163
|
+
static getMetadata(zodSchema) {
|
|
164
|
+
return this.collectMetadata(zodSchema);
|
|
165
|
+
}
|
|
166
|
+
static getOpenApiMetadata(zodSchema) {
|
|
167
|
+
const metadata = this.collectMetadata(zodSchema);
|
|
168
|
+
const _a = metadata !== null && metadata !== void 0 ? metadata : {}, { _internal } = _a;
|
|
169
|
+
return __rest(_a, ["_internal"]);
|
|
170
|
+
}
|
|
171
|
+
static getInternalMetadata(zodSchema) {
|
|
172
|
+
var _a;
|
|
173
|
+
return (_a = this.collectMetadata(zodSchema)) === null || _a === void 0 ? void 0 : _a._internal;
|
|
174
|
+
}
|
|
175
|
+
static getParamMetadata(zodSchema) {
|
|
176
|
+
const metadata = this.collectMetadata(zodSchema);
|
|
177
|
+
return Object.assign(Object.assign({}, metadata), { param: Object.assign(Object.assign({}, (metadata === null || metadata === void 0 ? void 0 : metadata.description) ? { description: metadata.description } : {}), metadata === null || metadata === void 0 ? void 0 : metadata.param) });
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* A method that omits all custom keys added to the regular OpenAPI
|
|
181
|
+
* metadata properties
|
|
182
|
+
*/
|
|
183
|
+
static buildSchemaMetadata(metadata) {
|
|
184
|
+
return omitBy(omit(metadata, ["param", "_internal"]), isUndefined);
|
|
185
|
+
}
|
|
186
|
+
static buildParameterMetadata(metadata) {
|
|
187
|
+
return omitBy(metadata, isUndefined);
|
|
188
|
+
}
|
|
189
|
+
static applySchemaMetadata(initialData, metadata) {
|
|
190
|
+
return omitBy(Object.assign(Object.assign({}, initialData), this.buildSchemaMetadata(metadata)), isUndefined);
|
|
191
|
+
}
|
|
192
|
+
static getRefId(zodSchema) {
|
|
193
|
+
var _a;
|
|
194
|
+
return (_a = this.getInternalMetadata(zodSchema)) === null || _a === void 0 ? void 0 : _a.refId;
|
|
195
|
+
}
|
|
196
|
+
static unwrapChained(schema) {
|
|
197
|
+
return this.unwrapUntil(schema);
|
|
198
|
+
}
|
|
199
|
+
static getDefaultValue(zodSchema) {
|
|
200
|
+
var _a;
|
|
201
|
+
const unwrapped = (_a = this.unwrapUntil(zodSchema, "ZodDefault")) !== null && _a !== void 0 ? _a : this.unwrapUntil(zodSchema, "ZodPrefault");
|
|
202
|
+
return unwrapped === null || unwrapped === void 0 ? void 0 : unwrapped._zod.def.defaultValue;
|
|
203
|
+
}
|
|
204
|
+
static unwrapUntil(schema, typeName) {
|
|
205
|
+
if (typeName && isZodType(schema, typeName)) return schema;
|
|
206
|
+
if (isZodType(schema, [
|
|
207
|
+
"ZodOptional",
|
|
208
|
+
"ZodNullable",
|
|
209
|
+
"ZodDefault",
|
|
210
|
+
"ZodPrefault",
|
|
211
|
+
"ZodReadonly",
|
|
212
|
+
"ZodNonOptional"
|
|
213
|
+
]) && isAnyZodType(schema._zod.def.innerType)) return this.unwrapUntil(schema._zod.def.innerType, typeName);
|
|
214
|
+
if (isZodType(schema, "ZodPipe")) {
|
|
215
|
+
const inSchema = schema._zod.def.in;
|
|
216
|
+
const outSchema = schema._zod.def.out;
|
|
217
|
+
if (isZodType(inSchema, "ZodTransform") && isAnyZodType(outSchema)) return this.unwrapUntil(outSchema, typeName);
|
|
218
|
+
if (isAnyZodType(inSchema)) return this.unwrapUntil(inSchema, typeName);
|
|
219
|
+
}
|
|
220
|
+
return typeName ? void 0 : schema;
|
|
221
|
+
}
|
|
222
|
+
static getMetadataFromInternalRegistry(zodSchema) {
|
|
223
|
+
return zodToOpenAPIRegistry.get(zodSchema);
|
|
224
|
+
}
|
|
225
|
+
static getMetadataFromRegistry(zodSchema) {
|
|
226
|
+
const internal = this.getMetadataFromInternalRegistry(zodSchema);
|
|
227
|
+
const general = zodSchema.meta();
|
|
228
|
+
if (!internal) return general;
|
|
229
|
+
const { _internal } = internal, rest = __rest(internal, ["_internal"]);
|
|
230
|
+
const _a = general !== null && general !== void 0 ? general : {}, { id, title } = _a, restGeneral = __rest(_a, ["id", "title"]);
|
|
231
|
+
return Object.assign(Object.assign(Object.assign({ _internal: Object.assign(Object.assign({}, id ? { refId: id } : {}), _internal) }, rest), title ? { description: title } : {}), restGeneral);
|
|
232
|
+
}
|
|
233
|
+
static setMetadataInRegistry(zodSchema, metadata) {
|
|
234
|
+
zodToOpenAPIRegistry.add(zodSchema, metadata);
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
function preserveMetadataFromModifier(zodSchema, modifier) {
|
|
238
|
+
const zodModifier = zodSchema[modifier];
|
|
239
|
+
if (typeof zodModifier !== "function") return;
|
|
240
|
+
zodSchema[modifier] = function(...args) {
|
|
241
|
+
const result = zodModifier.apply(this, args);
|
|
242
|
+
const meta = Metadata.getMetadataFromRegistry(this);
|
|
243
|
+
if (meta) Metadata.setMetadataInRegistry(result, meta);
|
|
244
|
+
return result;
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
function extendZodWithOpenApi(zod) {
|
|
248
|
+
if (typeof zod.ZodType.prototype.openapi !== "undefined") return;
|
|
249
|
+
zod.ZodType.prototype.openapi = function(...args) {
|
|
250
|
+
const { refId, metadata, options } = getOpenApiConfiguration(...args);
|
|
251
|
+
const _a = metadata !== null && metadata !== void 0 ? metadata : {}, { param } = _a, restOfOpenApi = __rest(_a, ["param"]);
|
|
252
|
+
const allMetadata = Metadata.getMetadataFromRegistry(this);
|
|
253
|
+
const _b = allMetadata !== null && allMetadata !== void 0 ? allMetadata : {}, { _internal: internalMetadata } = _b, currentMetadata = __rest(_b, ["_internal"]);
|
|
254
|
+
const _internal = Object.assign(Object.assign(Object.assign({}, internalMetadata), options), refId ? { refId } : void 0);
|
|
255
|
+
const resultMetadata = Object.assign(Object.assign(Object.assign({}, currentMetadata), restOfOpenApi), (currentMetadata === null || currentMetadata === void 0 ? void 0 : currentMetadata.param) || param ? { param: Object.assign(Object.assign({}, currentMetadata === null || currentMetadata === void 0 ? void 0 : currentMetadata.param), param) } : void 0);
|
|
256
|
+
const result = new this.constructor(this._def);
|
|
257
|
+
function setMetadata(schema) {
|
|
258
|
+
Metadata.setMetadataInRegistry(schema, Object.assign(Object.assign({}, Object.keys(_internal).length > 0 ? { _internal } : void 0), resultMetadata));
|
|
259
|
+
}
|
|
260
|
+
setMetadata(result);
|
|
261
|
+
/**
|
|
262
|
+
* In order to handle z.json() which is implemented as:
|
|
263
|
+
*
|
|
264
|
+
* const jsonSchema = lazy(() => { return union([ ... ]) });
|
|
265
|
+
* return jsonSchema;
|
|
266
|
+
*
|
|
267
|
+
* We need to not only set the metadata to the resulting schema (which would be different
|
|
268
|
+
* from `jsonSchema`), but also to the original lazy schema so that the _internal metadata (refId)
|
|
269
|
+
* is also present in the internally used `jsonSchema`.
|
|
270
|
+
*/
|
|
271
|
+
if (isZodType(result, "ZodLazy")) setMetadata(this);
|
|
272
|
+
if (isZodType(result, "ZodObject")) {
|
|
273
|
+
const currentMetadata = Metadata.getMetadataFromRegistry(result);
|
|
274
|
+
const originalExtend = result.extend;
|
|
275
|
+
result.extend = function(...args) {
|
|
276
|
+
const extendedResult = originalExtend.apply(result, args);
|
|
277
|
+
const _a = currentMetadata !== null && currentMetadata !== void 0 ? currentMetadata : {}, { _internal } = _a, rest = __rest(_a, ["_internal"]);
|
|
278
|
+
Metadata.setMetadataInRegistry(extendedResult, { _internal: { extendedFrom: (_internal === null || _internal === void 0 ? void 0 : _internal.refId) ? {
|
|
279
|
+
refId: _internal.refId,
|
|
280
|
+
schema: result
|
|
281
|
+
} : _internal === null || _internal === void 0 ? void 0 : _internal.extendedFrom } });
|
|
282
|
+
return extendedResult.openapi(rest);
|
|
283
|
+
};
|
|
284
|
+
preserveMetadataFromModifier(result, "catchall");
|
|
285
|
+
}
|
|
286
|
+
preserveMetadataFromModifier(result, "optional");
|
|
287
|
+
preserveMetadataFromModifier(result, "nullable");
|
|
288
|
+
preserveMetadataFromModifier(result, "default");
|
|
289
|
+
preserveMetadataFromModifier(result, "transform");
|
|
290
|
+
preserveMetadataFromModifier(result, "refine");
|
|
291
|
+
preserveMetadataFromModifier(result, "length");
|
|
292
|
+
preserveMetadataFromModifier(result, "min");
|
|
293
|
+
preserveMetadataFromModifier(result, "max");
|
|
294
|
+
const originalMeta = result.meta;
|
|
295
|
+
result.meta = function(...args) {
|
|
296
|
+
const result = originalMeta.apply(this, args);
|
|
297
|
+
if (args[0]) {
|
|
298
|
+
const meta = Metadata.getMetadataFromInternalRegistry(this);
|
|
299
|
+
if (meta) Metadata.setMetadataInRegistry(result, Object.assign(Object.assign({}, meta), args[0]));
|
|
300
|
+
}
|
|
301
|
+
return result;
|
|
302
|
+
};
|
|
303
|
+
return result;
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
function getOpenApiConfiguration(refOrOpenapi, metadataOrOptions, options) {
|
|
307
|
+
if (typeof refOrOpenapi === "string") return {
|
|
308
|
+
refId: refOrOpenapi,
|
|
309
|
+
metadata: metadataOrOptions,
|
|
310
|
+
options
|
|
311
|
+
};
|
|
312
|
+
return {
|
|
313
|
+
refId: void 0,
|
|
314
|
+
metadata: refOrOpenapi,
|
|
315
|
+
options: metadataOrOptions
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
exports.extendZodWithOpenApi = extendZodWithOpenApi;
|
|
319
|
+
}));
|
|
320
|
+
|
|
321
|
+
//#endregion
|
|
322
|
+
//#region ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/classic/compat.js
|
|
323
|
+
/** @deprecated Use the raw string literal codes instead, e.g. "invalid_type". */
|
|
324
|
+
const ZodIssueCode = {
|
|
325
|
+
invalid_type: "invalid_type",
|
|
326
|
+
too_big: "too_big",
|
|
327
|
+
too_small: "too_small",
|
|
328
|
+
invalid_format: "invalid_format",
|
|
329
|
+
not_multiple_of: "not_multiple_of",
|
|
330
|
+
unrecognized_keys: "unrecognized_keys",
|
|
331
|
+
invalid_union: "invalid_union",
|
|
332
|
+
invalid_key: "invalid_key",
|
|
333
|
+
invalid_element: "invalid_element",
|
|
334
|
+
invalid_value: "invalid_value",
|
|
335
|
+
custom: "custom"
|
|
336
|
+
};
|
|
337
|
+
/** @deprecated Use `z.config(params)` instead. */
|
|
338
|
+
function setErrorMap(map) {
|
|
339
|
+
config({ customError: map });
|
|
340
|
+
}
|
|
341
|
+
/** @deprecated Use `z.config()` instead. */
|
|
342
|
+
function getErrorMap() {
|
|
343
|
+
return config().customError;
|
|
344
|
+
}
|
|
345
|
+
/** @deprecated Do not use. Stub definition, only included for zod-to-json-schema compatibility. */
|
|
346
|
+
var ZodFirstPartyTypeKind;
|
|
347
|
+
(function(ZodFirstPartyTypeKind) {})(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
|
|
348
|
+
|
|
349
|
+
//#endregion
|
|
350
|
+
//#region ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/classic/from-json-schema.js
|
|
351
|
+
const z = {
|
|
352
|
+
...schemas_exports,
|
|
353
|
+
...checks_exports,
|
|
354
|
+
iso: iso_exports
|
|
355
|
+
};
|
|
356
|
+
const RECOGNIZED_KEYS = /* @__PURE__ */ new Set([
|
|
357
|
+
"$schema",
|
|
358
|
+
"$ref",
|
|
359
|
+
"$defs",
|
|
360
|
+
"definitions",
|
|
361
|
+
"$id",
|
|
362
|
+
"id",
|
|
363
|
+
"$comment",
|
|
364
|
+
"$anchor",
|
|
365
|
+
"$vocabulary",
|
|
366
|
+
"$dynamicRef",
|
|
367
|
+
"$dynamicAnchor",
|
|
368
|
+
"type",
|
|
369
|
+
"enum",
|
|
370
|
+
"const",
|
|
371
|
+
"anyOf",
|
|
372
|
+
"oneOf",
|
|
373
|
+
"allOf",
|
|
374
|
+
"not",
|
|
375
|
+
"properties",
|
|
376
|
+
"required",
|
|
377
|
+
"additionalProperties",
|
|
378
|
+
"patternProperties",
|
|
379
|
+
"propertyNames",
|
|
380
|
+
"minProperties",
|
|
381
|
+
"maxProperties",
|
|
382
|
+
"items",
|
|
383
|
+
"prefixItems",
|
|
384
|
+
"additionalItems",
|
|
385
|
+
"minItems",
|
|
386
|
+
"maxItems",
|
|
387
|
+
"uniqueItems",
|
|
388
|
+
"contains",
|
|
389
|
+
"minContains",
|
|
390
|
+
"maxContains",
|
|
391
|
+
"minLength",
|
|
392
|
+
"maxLength",
|
|
393
|
+
"pattern",
|
|
394
|
+
"format",
|
|
395
|
+
"minimum",
|
|
396
|
+
"maximum",
|
|
397
|
+
"exclusiveMinimum",
|
|
398
|
+
"exclusiveMaximum",
|
|
399
|
+
"multipleOf",
|
|
400
|
+
"description",
|
|
401
|
+
"default",
|
|
402
|
+
"contentEncoding",
|
|
403
|
+
"contentMediaType",
|
|
404
|
+
"contentSchema",
|
|
405
|
+
"unevaluatedItems",
|
|
406
|
+
"unevaluatedProperties",
|
|
407
|
+
"if",
|
|
408
|
+
"then",
|
|
409
|
+
"else",
|
|
410
|
+
"dependentSchemas",
|
|
411
|
+
"dependentRequired",
|
|
412
|
+
"nullable",
|
|
413
|
+
"readOnly"
|
|
414
|
+
]);
|
|
415
|
+
function detectVersion(schema, defaultTarget) {
|
|
416
|
+
const $schema = schema.$schema;
|
|
417
|
+
if ($schema === "https://json-schema.org/draft/2020-12/schema") return "draft-2020-12";
|
|
418
|
+
if ($schema === "http://json-schema.org/draft-07/schema#") return "draft-7";
|
|
419
|
+
if ($schema === "http://json-schema.org/draft-04/schema#") return "draft-4";
|
|
420
|
+
return defaultTarget ?? "draft-2020-12";
|
|
421
|
+
}
|
|
422
|
+
function resolveRef(ref, ctx) {
|
|
423
|
+
if (!ref.startsWith("#")) throw new Error("External $ref is not supported, only local refs (#/...) are allowed");
|
|
424
|
+
const path = ref.slice(1).split("/").filter(Boolean);
|
|
425
|
+
if (path.length === 0) return ctx.rootSchema;
|
|
426
|
+
const defsKey = ctx.version === "draft-2020-12" ? "$defs" : "definitions";
|
|
427
|
+
if (path[0] === defsKey) {
|
|
428
|
+
const key = path[1];
|
|
429
|
+
if (!key || !ctx.defs[key]) throw new Error(`Reference not found: ${ref}`);
|
|
430
|
+
return ctx.defs[key];
|
|
431
|
+
}
|
|
432
|
+
throw new Error(`Reference not found: ${ref}`);
|
|
433
|
+
}
|
|
434
|
+
function convertBaseSchema(schema, ctx) {
|
|
435
|
+
if (schema.not !== void 0) {
|
|
436
|
+
if (typeof schema.not === "object" && Object.keys(schema.not).length === 0) return z.never();
|
|
437
|
+
throw new Error("not is not supported in Zod (except { not: {} } for never)");
|
|
438
|
+
}
|
|
439
|
+
if (schema.unevaluatedItems !== void 0) throw new Error("unevaluatedItems is not supported");
|
|
440
|
+
if (schema.unevaluatedProperties !== void 0) throw new Error("unevaluatedProperties is not supported");
|
|
441
|
+
if (schema.if !== void 0 || schema.then !== void 0 || schema.else !== void 0) throw new Error("Conditional schemas (if/then/else) are not supported");
|
|
442
|
+
if (schema.dependentSchemas !== void 0 || schema.dependentRequired !== void 0) throw new Error("dependentSchemas and dependentRequired are not supported");
|
|
443
|
+
if (schema.$ref) {
|
|
444
|
+
const refPath = schema.$ref;
|
|
445
|
+
if (ctx.refs.has(refPath)) return ctx.refs.get(refPath);
|
|
446
|
+
if (ctx.processing.has(refPath)) return z.lazy(() => {
|
|
447
|
+
if (!ctx.refs.has(refPath)) throw new Error(`Circular reference not resolved: ${refPath}`);
|
|
448
|
+
return ctx.refs.get(refPath);
|
|
449
|
+
});
|
|
450
|
+
ctx.processing.add(refPath);
|
|
451
|
+
const zodSchema = convertSchema(resolveRef(refPath, ctx), ctx);
|
|
452
|
+
ctx.refs.set(refPath, zodSchema);
|
|
453
|
+
ctx.processing.delete(refPath);
|
|
454
|
+
return zodSchema;
|
|
455
|
+
}
|
|
456
|
+
if (schema.enum !== void 0) {
|
|
457
|
+
const enumValues = schema.enum;
|
|
458
|
+
if (ctx.version === "openapi-3.0" && schema.nullable === true && enumValues.length === 1 && enumValues[0] === null) return z.null();
|
|
459
|
+
if (enumValues.length === 0) return z.never();
|
|
460
|
+
if (enumValues.length === 1) return z.literal(enumValues[0]);
|
|
461
|
+
if (enumValues.every((v) => typeof v === "string")) return z.enum(enumValues);
|
|
462
|
+
const literalSchemas = enumValues.map((v) => z.literal(v));
|
|
463
|
+
if (literalSchemas.length < 2) return literalSchemas[0];
|
|
464
|
+
return z.union([
|
|
465
|
+
literalSchemas[0],
|
|
466
|
+
literalSchemas[1],
|
|
467
|
+
...literalSchemas.slice(2)
|
|
468
|
+
]);
|
|
469
|
+
}
|
|
470
|
+
if (schema.const !== void 0) return z.literal(schema.const);
|
|
471
|
+
const type = schema.type;
|
|
472
|
+
if (Array.isArray(type)) {
|
|
473
|
+
const typeSchemas = type.map((t) => {
|
|
474
|
+
return convertBaseSchema({
|
|
475
|
+
...schema,
|
|
476
|
+
type: t
|
|
477
|
+
}, ctx);
|
|
478
|
+
});
|
|
479
|
+
if (typeSchemas.length === 0) return z.never();
|
|
480
|
+
if (typeSchemas.length === 1) return typeSchemas[0];
|
|
481
|
+
return z.union(typeSchemas);
|
|
482
|
+
}
|
|
483
|
+
if (!type) return z.any();
|
|
484
|
+
let zodSchema;
|
|
485
|
+
switch (type) {
|
|
486
|
+
case "string": {
|
|
487
|
+
let stringSchema = z.string();
|
|
488
|
+
if (schema.format) {
|
|
489
|
+
const format = schema.format;
|
|
490
|
+
if (format === "email") stringSchema = stringSchema.check(z.email());
|
|
491
|
+
else if (format === "uri" || format === "uri-reference") stringSchema = stringSchema.check(z.url());
|
|
492
|
+
else if (format === "uuid" || format === "guid") stringSchema = stringSchema.check(z.uuid());
|
|
493
|
+
else if (format === "date-time") stringSchema = stringSchema.check(z.iso.datetime());
|
|
494
|
+
else if (format === "date") stringSchema = stringSchema.check(z.iso.date());
|
|
495
|
+
else if (format === "time") stringSchema = stringSchema.check(z.iso.time());
|
|
496
|
+
else if (format === "duration") stringSchema = stringSchema.check(z.iso.duration());
|
|
497
|
+
else if (format === "ipv4") stringSchema = stringSchema.check(z.ipv4());
|
|
498
|
+
else if (format === "ipv6") stringSchema = stringSchema.check(z.ipv6());
|
|
499
|
+
else if (format === "mac") stringSchema = stringSchema.check(z.mac());
|
|
500
|
+
else if (format === "cidr") stringSchema = stringSchema.check(z.cidrv4());
|
|
501
|
+
else if (format === "cidr-v6") stringSchema = stringSchema.check(z.cidrv6());
|
|
502
|
+
else if (format === "base64") stringSchema = stringSchema.check(z.base64());
|
|
503
|
+
else if (format === "base64url") stringSchema = stringSchema.check(z.base64url());
|
|
504
|
+
else if (format === "e164") stringSchema = stringSchema.check(z.e164());
|
|
505
|
+
else if (format === "jwt") stringSchema = stringSchema.check(z.jwt());
|
|
506
|
+
else if (format === "emoji") stringSchema = stringSchema.check(z.emoji());
|
|
507
|
+
else if (format === "nanoid") stringSchema = stringSchema.check(z.nanoid());
|
|
508
|
+
else if (format === "cuid") stringSchema = stringSchema.check(z.cuid());
|
|
509
|
+
else if (format === "cuid2") stringSchema = stringSchema.check(z.cuid2());
|
|
510
|
+
else if (format === "ulid") stringSchema = stringSchema.check(z.ulid());
|
|
511
|
+
else if (format === "xid") stringSchema = stringSchema.check(z.xid());
|
|
512
|
+
else if (format === "ksuid") stringSchema = stringSchema.check(z.ksuid());
|
|
513
|
+
}
|
|
514
|
+
if (typeof schema.minLength === "number") stringSchema = stringSchema.min(schema.minLength);
|
|
515
|
+
if (typeof schema.maxLength === "number") stringSchema = stringSchema.max(schema.maxLength);
|
|
516
|
+
if (schema.pattern) stringSchema = stringSchema.regex(new RegExp(schema.pattern));
|
|
517
|
+
zodSchema = stringSchema;
|
|
518
|
+
break;
|
|
519
|
+
}
|
|
520
|
+
case "number":
|
|
521
|
+
case "integer": {
|
|
522
|
+
let numberSchema = type === "integer" ? z.number().int() : z.number();
|
|
523
|
+
if (typeof schema.minimum === "number") numberSchema = numberSchema.min(schema.minimum);
|
|
524
|
+
if (typeof schema.maximum === "number") numberSchema = numberSchema.max(schema.maximum);
|
|
525
|
+
if (typeof schema.exclusiveMinimum === "number") numberSchema = numberSchema.gt(schema.exclusiveMinimum);
|
|
526
|
+
else if (schema.exclusiveMinimum === true && typeof schema.minimum === "number") numberSchema = numberSchema.gt(schema.minimum);
|
|
527
|
+
if (typeof schema.exclusiveMaximum === "number") numberSchema = numberSchema.lt(schema.exclusiveMaximum);
|
|
528
|
+
else if (schema.exclusiveMaximum === true && typeof schema.maximum === "number") numberSchema = numberSchema.lt(schema.maximum);
|
|
529
|
+
if (typeof schema.multipleOf === "number") numberSchema = numberSchema.multipleOf(schema.multipleOf);
|
|
530
|
+
zodSchema = numberSchema;
|
|
531
|
+
break;
|
|
532
|
+
}
|
|
533
|
+
case "boolean":
|
|
534
|
+
zodSchema = z.boolean();
|
|
535
|
+
break;
|
|
536
|
+
case "null":
|
|
537
|
+
zodSchema = z.null();
|
|
538
|
+
break;
|
|
539
|
+
case "object": {
|
|
540
|
+
const shape = {};
|
|
541
|
+
const properties = schema.properties || {};
|
|
542
|
+
const requiredSet = new Set(schema.required || []);
|
|
543
|
+
for (const [key, propSchema] of Object.entries(properties)) {
|
|
544
|
+
const propZodSchema = convertSchema(propSchema, ctx);
|
|
545
|
+
shape[key] = requiredSet.has(key) ? propZodSchema : propZodSchema.optional();
|
|
546
|
+
}
|
|
547
|
+
if (schema.propertyNames) {
|
|
548
|
+
const keySchema = convertSchema(schema.propertyNames, ctx);
|
|
549
|
+
const valueSchema = schema.additionalProperties && typeof schema.additionalProperties === "object" ? convertSchema(schema.additionalProperties, ctx) : z.any();
|
|
550
|
+
if (Object.keys(shape).length === 0) {
|
|
551
|
+
zodSchema = z.record(keySchema, valueSchema);
|
|
552
|
+
break;
|
|
553
|
+
}
|
|
554
|
+
const objectSchema = z.object(shape).passthrough();
|
|
555
|
+
const recordSchema = z.looseRecord(keySchema, valueSchema);
|
|
556
|
+
zodSchema = z.intersection(objectSchema, recordSchema);
|
|
557
|
+
break;
|
|
558
|
+
}
|
|
559
|
+
if (schema.patternProperties) {
|
|
560
|
+
const patternProps = schema.patternProperties;
|
|
561
|
+
const patternKeys = Object.keys(patternProps);
|
|
562
|
+
const looseRecords = [];
|
|
563
|
+
for (const pattern of patternKeys) {
|
|
564
|
+
const patternValue = convertSchema(patternProps[pattern], ctx);
|
|
565
|
+
const keySchema = z.string().regex(new RegExp(pattern));
|
|
566
|
+
looseRecords.push(z.looseRecord(keySchema, patternValue));
|
|
567
|
+
}
|
|
568
|
+
const schemasToIntersect = [];
|
|
569
|
+
if (Object.keys(shape).length > 0) schemasToIntersect.push(z.object(shape).passthrough());
|
|
570
|
+
schemasToIntersect.push(...looseRecords);
|
|
571
|
+
if (schemasToIntersect.length === 0) zodSchema = z.object({}).passthrough();
|
|
572
|
+
else if (schemasToIntersect.length === 1) zodSchema = schemasToIntersect[0];
|
|
573
|
+
else {
|
|
574
|
+
let result = z.intersection(schemasToIntersect[0], schemasToIntersect[1]);
|
|
575
|
+
for (let i = 2; i < schemasToIntersect.length; i++) result = z.intersection(result, schemasToIntersect[i]);
|
|
576
|
+
zodSchema = result;
|
|
577
|
+
}
|
|
578
|
+
break;
|
|
579
|
+
}
|
|
580
|
+
const objectSchema = z.object(shape);
|
|
581
|
+
if (schema.additionalProperties === false) zodSchema = objectSchema.strict();
|
|
582
|
+
else if (typeof schema.additionalProperties === "object") zodSchema = objectSchema.catchall(convertSchema(schema.additionalProperties, ctx));
|
|
583
|
+
else zodSchema = objectSchema.passthrough();
|
|
584
|
+
break;
|
|
585
|
+
}
|
|
586
|
+
case "array": {
|
|
587
|
+
const prefixItems = schema.prefixItems;
|
|
588
|
+
const items = schema.items;
|
|
589
|
+
if (prefixItems && Array.isArray(prefixItems)) {
|
|
590
|
+
const tupleItems = prefixItems.map((item) => convertSchema(item, ctx));
|
|
591
|
+
const rest = items && typeof items === "object" && !Array.isArray(items) ? convertSchema(items, ctx) : void 0;
|
|
592
|
+
if (rest) zodSchema = z.tuple(tupleItems).rest(rest);
|
|
593
|
+
else zodSchema = z.tuple(tupleItems);
|
|
594
|
+
if (typeof schema.minItems === "number") zodSchema = zodSchema.check(z.minLength(schema.minItems));
|
|
595
|
+
if (typeof schema.maxItems === "number") zodSchema = zodSchema.check(z.maxLength(schema.maxItems));
|
|
596
|
+
} else if (Array.isArray(items)) {
|
|
597
|
+
const tupleItems = items.map((item) => convertSchema(item, ctx));
|
|
598
|
+
const rest = schema.additionalItems && typeof schema.additionalItems === "object" ? convertSchema(schema.additionalItems, ctx) : void 0;
|
|
599
|
+
if (rest) zodSchema = z.tuple(tupleItems).rest(rest);
|
|
600
|
+
else zodSchema = z.tuple(tupleItems);
|
|
601
|
+
if (typeof schema.minItems === "number") zodSchema = zodSchema.check(z.minLength(schema.minItems));
|
|
602
|
+
if (typeof schema.maxItems === "number") zodSchema = zodSchema.check(z.maxLength(schema.maxItems));
|
|
603
|
+
} else if (items !== void 0) {
|
|
604
|
+
const element = convertSchema(items, ctx);
|
|
605
|
+
let arraySchema = z.array(element);
|
|
606
|
+
if (typeof schema.minItems === "number") arraySchema = arraySchema.min(schema.minItems);
|
|
607
|
+
if (typeof schema.maxItems === "number") arraySchema = arraySchema.max(schema.maxItems);
|
|
608
|
+
zodSchema = arraySchema;
|
|
609
|
+
} else zodSchema = z.array(z.any());
|
|
610
|
+
break;
|
|
611
|
+
}
|
|
612
|
+
default: throw new Error(`Unsupported type: ${type}`);
|
|
613
|
+
}
|
|
614
|
+
return zodSchema;
|
|
615
|
+
}
|
|
616
|
+
function convertSchema(schema, ctx) {
|
|
617
|
+
if (typeof schema === "boolean") return schema ? z.any() : z.never();
|
|
618
|
+
let baseSchema = convertBaseSchema(schema, ctx);
|
|
619
|
+
const hasExplicitType = schema.type || schema.enum !== void 0 || schema.const !== void 0;
|
|
620
|
+
if (schema.anyOf && Array.isArray(schema.anyOf)) {
|
|
621
|
+
const options = schema.anyOf.map((s) => convertSchema(s, ctx));
|
|
622
|
+
const anyOfUnion = z.union(options);
|
|
623
|
+
baseSchema = hasExplicitType ? z.intersection(baseSchema, anyOfUnion) : anyOfUnion;
|
|
624
|
+
}
|
|
625
|
+
if (schema.oneOf && Array.isArray(schema.oneOf)) {
|
|
626
|
+
const options = schema.oneOf.map((s) => convertSchema(s, ctx));
|
|
627
|
+
const oneOfUnion = z.xor(options);
|
|
628
|
+
baseSchema = hasExplicitType ? z.intersection(baseSchema, oneOfUnion) : oneOfUnion;
|
|
629
|
+
}
|
|
630
|
+
if (schema.allOf && Array.isArray(schema.allOf)) if (schema.allOf.length === 0) baseSchema = hasExplicitType ? baseSchema : z.any();
|
|
631
|
+
else {
|
|
632
|
+
let result = hasExplicitType ? baseSchema : convertSchema(schema.allOf[0], ctx);
|
|
633
|
+
const startIdx = hasExplicitType ? 0 : 1;
|
|
634
|
+
for (let i = startIdx; i < schema.allOf.length; i++) result = z.intersection(result, convertSchema(schema.allOf[i], ctx));
|
|
635
|
+
baseSchema = result;
|
|
636
|
+
}
|
|
637
|
+
if (schema.nullable === true && ctx.version === "openapi-3.0") baseSchema = z.nullable(baseSchema);
|
|
638
|
+
if (schema.readOnly === true) baseSchema = z.readonly(baseSchema);
|
|
639
|
+
if (schema.default !== void 0) baseSchema = baseSchema.default(schema.default);
|
|
640
|
+
const extraMeta = {};
|
|
641
|
+
for (const key of [
|
|
642
|
+
"$id",
|
|
643
|
+
"id",
|
|
644
|
+
"$comment",
|
|
645
|
+
"$anchor",
|
|
646
|
+
"$vocabulary",
|
|
647
|
+
"$dynamicRef",
|
|
648
|
+
"$dynamicAnchor"
|
|
649
|
+
]) if (key in schema) extraMeta[key] = schema[key];
|
|
650
|
+
for (const key of [
|
|
651
|
+
"contentEncoding",
|
|
652
|
+
"contentMediaType",
|
|
653
|
+
"contentSchema"
|
|
654
|
+
]) if (key in schema) extraMeta[key] = schema[key];
|
|
655
|
+
for (const key of Object.keys(schema)) if (!RECOGNIZED_KEYS.has(key)) extraMeta[key] = schema[key];
|
|
656
|
+
if (Object.keys(extraMeta).length > 0) ctx.registry.add(baseSchema, extraMeta);
|
|
657
|
+
if (schema.description) baseSchema = baseSchema.describe(schema.description);
|
|
658
|
+
return baseSchema;
|
|
659
|
+
}
|
|
660
|
+
/**
|
|
661
|
+
* Converts a JSON Schema to a Zod schema. This function should be considered semi-experimental. It's behavior is liable to change. */
|
|
662
|
+
function fromJSONSchema(schema, params) {
|
|
663
|
+
if (typeof schema === "boolean") return schema ? z.any() : z.never();
|
|
664
|
+
let normalized;
|
|
665
|
+
try {
|
|
666
|
+
normalized = JSON.parse(JSON.stringify(schema));
|
|
667
|
+
} catch {
|
|
668
|
+
throw new Error("fromJSONSchema input is not valid JSON (possibly cyclic); use $defs/$ref for recursive schemas");
|
|
669
|
+
}
|
|
670
|
+
const ctx = {
|
|
671
|
+
version: detectVersion(normalized, params?.defaultTarget),
|
|
672
|
+
defs: normalized.$defs || normalized.definitions || {},
|
|
673
|
+
refs: /* @__PURE__ */ new Map(),
|
|
674
|
+
processing: /* @__PURE__ */ new Set(),
|
|
675
|
+
rootSchema: normalized,
|
|
676
|
+
registry: params?.registry ?? globalRegistry
|
|
677
|
+
};
|
|
678
|
+
return convertSchema(normalized, ctx);
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
//#endregion
|
|
682
|
+
//#region ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/classic/coerce.js
|
|
683
|
+
var coerce_exports = /* @__PURE__ */ __exportAll({
|
|
684
|
+
bigint: () => bigint,
|
|
685
|
+
boolean: () => boolean,
|
|
686
|
+
date: () => date,
|
|
687
|
+
number: () => number,
|
|
688
|
+
string: () => string
|
|
689
|
+
});
|
|
690
|
+
function string(params) {
|
|
691
|
+
return _coercedString(ZodString, params);
|
|
692
|
+
}
|
|
693
|
+
function number(params) {
|
|
694
|
+
return _coercedNumber(ZodNumber, params);
|
|
695
|
+
}
|
|
696
|
+
function boolean(params) {
|
|
697
|
+
return _coercedBoolean(ZodBoolean, params);
|
|
698
|
+
}
|
|
699
|
+
function bigint(params) {
|
|
700
|
+
return _coercedBigint(ZodBigInt, params);
|
|
701
|
+
}
|
|
702
|
+
function date(params) {
|
|
703
|
+
return _coercedDate(ZodDate, params);
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
//#endregion
|
|
707
|
+
//#region ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/classic/external.js
|
|
708
|
+
var external_exports = /* @__PURE__ */ __exportAll({
|
|
709
|
+
$brand: () => $brand,
|
|
710
|
+
$input: () => $input,
|
|
711
|
+
$output: () => $output,
|
|
712
|
+
NEVER: () => NEVER,
|
|
713
|
+
TimePrecision: () => TimePrecision,
|
|
714
|
+
ZodAny: () => ZodAny,
|
|
715
|
+
ZodArray: () => ZodArray,
|
|
716
|
+
ZodBase64: () => ZodBase64,
|
|
717
|
+
ZodBase64URL: () => ZodBase64URL,
|
|
718
|
+
ZodBigInt: () => ZodBigInt,
|
|
719
|
+
ZodBigIntFormat: () => ZodBigIntFormat,
|
|
720
|
+
ZodBoolean: () => ZodBoolean,
|
|
721
|
+
ZodCIDRv4: () => ZodCIDRv4,
|
|
722
|
+
ZodCIDRv6: () => ZodCIDRv6,
|
|
723
|
+
ZodCUID: () => ZodCUID,
|
|
724
|
+
ZodCUID2: () => ZodCUID2,
|
|
725
|
+
ZodCatch: () => ZodCatch,
|
|
726
|
+
ZodCodec: () => ZodCodec,
|
|
727
|
+
ZodCustom: () => ZodCustom,
|
|
728
|
+
ZodCustomStringFormat: () => ZodCustomStringFormat,
|
|
729
|
+
ZodDate: () => ZodDate,
|
|
730
|
+
ZodDefault: () => ZodDefault,
|
|
731
|
+
ZodDiscriminatedUnion: () => ZodDiscriminatedUnion,
|
|
732
|
+
ZodE164: () => ZodE164,
|
|
733
|
+
ZodEmail: () => ZodEmail,
|
|
734
|
+
ZodEmoji: () => ZodEmoji,
|
|
735
|
+
ZodEnum: () => ZodEnum,
|
|
736
|
+
ZodError: () => ZodError,
|
|
737
|
+
ZodExactOptional: () => ZodExactOptional,
|
|
738
|
+
ZodFile: () => ZodFile,
|
|
739
|
+
ZodFirstPartyTypeKind: () => ZodFirstPartyTypeKind,
|
|
740
|
+
ZodFunction: () => ZodFunction,
|
|
741
|
+
ZodGUID: () => ZodGUID,
|
|
742
|
+
ZodIPv4: () => ZodIPv4,
|
|
743
|
+
ZodIPv6: () => ZodIPv6,
|
|
744
|
+
ZodISODate: () => ZodISODate,
|
|
745
|
+
ZodISODateTime: () => ZodISODateTime,
|
|
746
|
+
ZodISODuration: () => ZodISODuration,
|
|
747
|
+
ZodISOTime: () => ZodISOTime,
|
|
748
|
+
ZodIntersection: () => ZodIntersection,
|
|
749
|
+
ZodIssueCode: () => ZodIssueCode,
|
|
750
|
+
ZodJWT: () => ZodJWT,
|
|
751
|
+
ZodKSUID: () => ZodKSUID,
|
|
752
|
+
ZodLazy: () => ZodLazy,
|
|
753
|
+
ZodLiteral: () => ZodLiteral,
|
|
754
|
+
ZodMAC: () => ZodMAC,
|
|
755
|
+
ZodMap: () => ZodMap,
|
|
756
|
+
ZodNaN: () => ZodNaN,
|
|
757
|
+
ZodNanoID: () => ZodNanoID,
|
|
758
|
+
ZodNever: () => ZodNever,
|
|
759
|
+
ZodNonOptional: () => ZodNonOptional,
|
|
760
|
+
ZodNull: () => ZodNull,
|
|
761
|
+
ZodNullable: () => ZodNullable,
|
|
762
|
+
ZodNumber: () => ZodNumber,
|
|
763
|
+
ZodNumberFormat: () => ZodNumberFormat,
|
|
764
|
+
ZodObject: () => ZodObject,
|
|
765
|
+
ZodOptional: () => ZodOptional,
|
|
766
|
+
ZodPipe: () => ZodPipe,
|
|
767
|
+
ZodPrefault: () => ZodPrefault,
|
|
768
|
+
ZodPreprocess: () => ZodPreprocess,
|
|
769
|
+
ZodPromise: () => ZodPromise,
|
|
770
|
+
ZodReadonly: () => ZodReadonly,
|
|
771
|
+
ZodRealError: () => ZodRealError,
|
|
772
|
+
ZodRecord: () => ZodRecord,
|
|
773
|
+
ZodSet: () => ZodSet,
|
|
774
|
+
ZodString: () => ZodString,
|
|
775
|
+
ZodStringFormat: () => ZodStringFormat,
|
|
776
|
+
ZodSuccess: () => ZodSuccess,
|
|
777
|
+
ZodSymbol: () => ZodSymbol,
|
|
778
|
+
ZodTemplateLiteral: () => ZodTemplateLiteral,
|
|
779
|
+
ZodTransform: () => ZodTransform,
|
|
780
|
+
ZodTuple: () => ZodTuple,
|
|
781
|
+
ZodType: () => ZodType,
|
|
782
|
+
ZodULID: () => ZodULID,
|
|
783
|
+
ZodURL: () => ZodURL,
|
|
784
|
+
ZodUUID: () => ZodUUID,
|
|
785
|
+
ZodUndefined: () => ZodUndefined,
|
|
786
|
+
ZodUnion: () => ZodUnion,
|
|
787
|
+
ZodUnknown: () => ZodUnknown,
|
|
788
|
+
ZodVoid: () => ZodVoid,
|
|
789
|
+
ZodXID: () => ZodXID,
|
|
790
|
+
ZodXor: () => ZodXor,
|
|
791
|
+
_ZodString: () => _ZodString,
|
|
792
|
+
_default: () => _default,
|
|
793
|
+
_function: () => _function,
|
|
794
|
+
any: () => any,
|
|
795
|
+
array: () => array,
|
|
796
|
+
base64: () => base64,
|
|
797
|
+
base64url: () => base64url,
|
|
798
|
+
bigint: () => bigint$1,
|
|
799
|
+
boolean: () => boolean$1,
|
|
800
|
+
catch: () => _catch,
|
|
801
|
+
check: () => check,
|
|
802
|
+
cidrv4: () => cidrv4,
|
|
803
|
+
cidrv6: () => cidrv6,
|
|
804
|
+
clone: () => clone,
|
|
805
|
+
codec: () => codec,
|
|
806
|
+
coerce: () => coerce_exports,
|
|
807
|
+
config: () => config,
|
|
808
|
+
core: () => core_exports,
|
|
809
|
+
cuid: () => cuid,
|
|
810
|
+
cuid2: () => cuid2,
|
|
811
|
+
custom: () => custom,
|
|
812
|
+
date: () => date$1,
|
|
813
|
+
decode: () => decode,
|
|
814
|
+
decodeAsync: () => decodeAsync,
|
|
815
|
+
describe: () => describe,
|
|
816
|
+
discriminatedUnion: () => discriminatedUnion,
|
|
817
|
+
e164: () => e164,
|
|
818
|
+
email: () => email,
|
|
819
|
+
emoji: () => emoji,
|
|
820
|
+
encode: () => encode,
|
|
821
|
+
encodeAsync: () => encodeAsync,
|
|
822
|
+
endsWith: () => _endsWith,
|
|
823
|
+
enum: () => _enum,
|
|
824
|
+
exactOptional: () => exactOptional,
|
|
825
|
+
file: () => file,
|
|
826
|
+
flattenError: () => flattenError,
|
|
827
|
+
float32: () => float32,
|
|
828
|
+
float64: () => float64,
|
|
829
|
+
formatError: () => formatError,
|
|
830
|
+
fromJSONSchema: () => fromJSONSchema,
|
|
831
|
+
function: () => _function,
|
|
832
|
+
getErrorMap: () => getErrorMap,
|
|
833
|
+
globalRegistry: () => globalRegistry,
|
|
834
|
+
gt: () => _gt,
|
|
835
|
+
gte: () => _gte,
|
|
836
|
+
guid: () => guid,
|
|
837
|
+
hash: () => hash,
|
|
838
|
+
hex: () => hex,
|
|
839
|
+
hostname: () => hostname,
|
|
840
|
+
httpUrl: () => httpUrl,
|
|
841
|
+
includes: () => _includes,
|
|
842
|
+
instanceof: () => _instanceof,
|
|
843
|
+
int: () => int,
|
|
844
|
+
int32: () => int32,
|
|
845
|
+
int64: () => int64,
|
|
846
|
+
intersection: () => intersection,
|
|
847
|
+
invertCodec: () => invertCodec,
|
|
848
|
+
ipv4: () => ipv4,
|
|
849
|
+
ipv6: () => ipv6,
|
|
850
|
+
iso: () => iso_exports,
|
|
851
|
+
json: () => json,
|
|
852
|
+
jwt: () => jwt,
|
|
853
|
+
keyof: () => keyof,
|
|
854
|
+
ksuid: () => ksuid,
|
|
855
|
+
lazy: () => lazy,
|
|
856
|
+
length: () => _length,
|
|
857
|
+
literal: () => literal,
|
|
858
|
+
locales: () => locales_exports,
|
|
859
|
+
looseObject: () => looseObject,
|
|
860
|
+
looseRecord: () => looseRecord,
|
|
861
|
+
lowercase: () => _lowercase,
|
|
862
|
+
lt: () => _lt,
|
|
863
|
+
lte: () => _lte,
|
|
864
|
+
mac: () => mac,
|
|
865
|
+
map: () => map,
|
|
866
|
+
maxLength: () => _maxLength,
|
|
867
|
+
maxSize: () => _maxSize,
|
|
868
|
+
meta: () => meta,
|
|
869
|
+
mime: () => _mime,
|
|
870
|
+
minLength: () => _minLength,
|
|
871
|
+
minSize: () => _minSize,
|
|
872
|
+
multipleOf: () => _multipleOf,
|
|
873
|
+
nan: () => nan,
|
|
874
|
+
nanoid: () => nanoid,
|
|
875
|
+
nativeEnum: () => nativeEnum,
|
|
876
|
+
negative: () => _negative,
|
|
877
|
+
never: () => never,
|
|
878
|
+
nonnegative: () => _nonnegative,
|
|
879
|
+
nonoptional: () => nonoptional,
|
|
880
|
+
nonpositive: () => _nonpositive,
|
|
881
|
+
normalize: () => _normalize,
|
|
882
|
+
null: () => _null,
|
|
883
|
+
nullable: () => nullable,
|
|
884
|
+
nullish: () => nullish,
|
|
885
|
+
number: () => number$1,
|
|
886
|
+
object: () => object,
|
|
887
|
+
optional: () => optional,
|
|
888
|
+
overwrite: () => _overwrite,
|
|
889
|
+
parse: () => parse,
|
|
890
|
+
parseAsync: () => parseAsync,
|
|
891
|
+
partialRecord: () => partialRecord,
|
|
892
|
+
pipe: () => pipe,
|
|
893
|
+
positive: () => _positive,
|
|
894
|
+
prefault: () => prefault,
|
|
895
|
+
preprocess: () => preprocess,
|
|
896
|
+
prettifyError: () => prettifyError,
|
|
897
|
+
promise: () => promise,
|
|
898
|
+
property: () => _property,
|
|
899
|
+
readonly: () => readonly,
|
|
900
|
+
record: () => record,
|
|
901
|
+
refine: () => refine,
|
|
902
|
+
regex: () => _regex,
|
|
903
|
+
regexes: () => regexes_exports,
|
|
904
|
+
registry: () => registry,
|
|
905
|
+
safeDecode: () => safeDecode,
|
|
906
|
+
safeDecodeAsync: () => safeDecodeAsync,
|
|
907
|
+
safeEncode: () => safeEncode,
|
|
908
|
+
safeEncodeAsync: () => safeEncodeAsync,
|
|
909
|
+
safeParse: () => safeParse,
|
|
910
|
+
safeParseAsync: () => safeParseAsync,
|
|
911
|
+
set: () => set,
|
|
912
|
+
setErrorMap: () => setErrorMap,
|
|
913
|
+
size: () => _size,
|
|
914
|
+
slugify: () => _slugify,
|
|
915
|
+
startsWith: () => _startsWith,
|
|
916
|
+
strictObject: () => strictObject,
|
|
917
|
+
string: () => string$1,
|
|
918
|
+
stringFormat: () => stringFormat,
|
|
919
|
+
stringbool: () => stringbool,
|
|
920
|
+
success: () => success,
|
|
921
|
+
superRefine: () => superRefine,
|
|
922
|
+
symbol: () => symbol,
|
|
923
|
+
templateLiteral: () => templateLiteral,
|
|
924
|
+
toJSONSchema: () => toJSONSchema,
|
|
925
|
+
toLowerCase: () => _toLowerCase,
|
|
926
|
+
toUpperCase: () => _toUpperCase,
|
|
927
|
+
transform: () => transform,
|
|
928
|
+
treeifyError: () => treeifyError,
|
|
929
|
+
trim: () => _trim,
|
|
930
|
+
tuple: () => tuple,
|
|
931
|
+
uint32: () => uint32,
|
|
932
|
+
uint64: () => uint64,
|
|
933
|
+
ulid: () => ulid,
|
|
934
|
+
undefined: () => _undefined,
|
|
935
|
+
union: () => union,
|
|
936
|
+
unknown: () => unknown,
|
|
937
|
+
uppercase: () => _uppercase,
|
|
938
|
+
url: () => url,
|
|
939
|
+
util: () => util_exports,
|
|
940
|
+
uuid: () => uuid,
|
|
941
|
+
uuidv4: () => uuidv4,
|
|
942
|
+
uuidv6: () => uuidv6,
|
|
943
|
+
uuidv7: () => uuidv7,
|
|
944
|
+
void: () => _void,
|
|
945
|
+
xid: () => xid,
|
|
946
|
+
xor: () => xor
|
|
947
|
+
});
|
|
948
|
+
config(en_default());
|
|
949
|
+
|
|
950
|
+
//#endregion
|
|
951
|
+
//#region ../api-contract/dist/openapi.mjs
|
|
952
|
+
var import_dist = require_dist();
|
|
953
|
+
(0, import_dist.extendZodWithOpenApi)(external_exports);
|
|
954
|
+
|
|
955
|
+
//#endregion
|
|
956
|
+
//#region ../api-contract/dist/errors.mjs
|
|
957
|
+
/**
|
|
958
|
+
* Error shape returned by every `/api/v1` machine operation (and by the shared
|
|
959
|
+
* auth guard). Each operation registers its own error schema component in the
|
|
960
|
+
* OpenAPI document, so this is a factory rather than a single shared instance.
|
|
961
|
+
*/
|
|
962
|
+
function createApiErrorResponseSchema() {
|
|
963
|
+
return object({
|
|
964
|
+
error: string$1(),
|
|
965
|
+
issues: array(unknown()).optional()
|
|
966
|
+
});
|
|
967
|
+
}
|
|
968
|
+
const apiErrorResponseSchema = createApiErrorResponseSchema();
|
|
969
|
+
/**
|
|
970
|
+
* Canonical error codes for the `/api/v1` resource operations. Machine
|
|
971
|
+
* operations keep the flat `{ error: string }` shape above unchanged; the
|
|
972
|
+
* nested envelope below applies to resource operations only.
|
|
973
|
+
*/
|
|
974
|
+
const resourceErrorCodeSchema = _enum([
|
|
975
|
+
"bad_request",
|
|
976
|
+
"unauthenticated",
|
|
977
|
+
"forbidden",
|
|
978
|
+
"machine_locked",
|
|
979
|
+
"not_found",
|
|
980
|
+
"conflict",
|
|
981
|
+
"payload_too_large",
|
|
982
|
+
"rate_limited",
|
|
983
|
+
"capability_disabled",
|
|
984
|
+
"upstream_error",
|
|
985
|
+
"internal_error"
|
|
986
|
+
]);
|
|
987
|
+
/** Factory, matching `createApiErrorResponseSchema`, for per-route OpenAPI components. */
|
|
988
|
+
function createResourceApiErrorResponseSchema() {
|
|
989
|
+
return object({ error: object({
|
|
990
|
+
code: resourceErrorCodeSchema,
|
|
991
|
+
message: string$1(),
|
|
992
|
+
issues: array(unknown()).optional(),
|
|
993
|
+
retryable: boolean$1().optional()
|
|
994
|
+
}) });
|
|
995
|
+
}
|
|
996
|
+
const resourceApiErrorResponseSchema = createResourceApiErrorResponseSchema();
|
|
997
|
+
|
|
998
|
+
//#endregion
|
|
999
|
+
//#region ../api-contract/dist/xgraph.mjs
|
|
1000
|
+
const looseRecordSchema = record(string$1(), unknown());
|
|
1001
|
+
const pointSchema = object({
|
|
1002
|
+
x: number$1(),
|
|
1003
|
+
y: number$1()
|
|
1004
|
+
});
|
|
1005
|
+
const graphModeSchema = _enum([
|
|
1006
|
+
"directed",
|
|
1007
|
+
"undirected",
|
|
1008
|
+
"bidirectional"
|
|
1009
|
+
]);
|
|
1010
|
+
const nodeDataSchema = looseRecordSchema.refine((data) => !("parentId" in data), "XGraph node data must not contain parentId; use node.parentId.");
|
|
1011
|
+
const xgraphNodeSchema = object({
|
|
1012
|
+
id: string$1(),
|
|
1013
|
+
type: string$1().optional(),
|
|
1014
|
+
parentId: string$1().nullable().optional(),
|
|
1015
|
+
sourceId: string$1().optional(),
|
|
1016
|
+
targetId: string$1().optional(),
|
|
1017
|
+
label: string$1().nullable().optional(),
|
|
1018
|
+
data: nodeDataSchema.optional(),
|
|
1019
|
+
x: number$1().optional(),
|
|
1020
|
+
y: number$1().optional(),
|
|
1021
|
+
width: number$1().optional(),
|
|
1022
|
+
height: number$1().optional(),
|
|
1023
|
+
position: pointSchema.optional(),
|
|
1024
|
+
dx: number$1().optional(),
|
|
1025
|
+
dy: number$1().optional()
|
|
1026
|
+
}).passthrough();
|
|
1027
|
+
const xgraphEdgeSchema = object({
|
|
1028
|
+
id: string$1(),
|
|
1029
|
+
type: string$1().optional(),
|
|
1030
|
+
sourceId: string$1(),
|
|
1031
|
+
targetId: string$1(),
|
|
1032
|
+
mode: graphModeSchema.optional(),
|
|
1033
|
+
label: string$1().nullable().optional(),
|
|
1034
|
+
data: unknown().optional(),
|
|
1035
|
+
x: number$1().optional(),
|
|
1036
|
+
y: number$1().optional(),
|
|
1037
|
+
width: number$1().optional(),
|
|
1038
|
+
height: number$1().optional(),
|
|
1039
|
+
position: pointSchema.optional(),
|
|
1040
|
+
dx: number$1().optional(),
|
|
1041
|
+
dy: number$1().optional()
|
|
1042
|
+
}).passthrough();
|
|
1043
|
+
/** XGraph wire shape accepted and emitted at API boundaries. */
|
|
1044
|
+
const xgraphSchema = object({
|
|
1045
|
+
xgraphSchemaVersion: literal("1.0.0").optional(),
|
|
1046
|
+
id: string$1().optional(),
|
|
1047
|
+
type: string$1().optional(),
|
|
1048
|
+
mode: graphModeSchema.optional(),
|
|
1049
|
+
parentId: string$1().nullable().optional(),
|
|
1050
|
+
initialNodeId: string$1().nullable().optional(),
|
|
1051
|
+
nodes: array(xgraphNodeSchema),
|
|
1052
|
+
edges: array(xgraphEdgeSchema),
|
|
1053
|
+
data: unknown().optional(),
|
|
1054
|
+
layout: unknown().nullable().optional(),
|
|
1055
|
+
annotations: array(unknown()).optional(),
|
|
1056
|
+
direction: _enum([
|
|
1057
|
+
"up",
|
|
1058
|
+
"down",
|
|
1059
|
+
"left",
|
|
1060
|
+
"right"
|
|
1061
|
+
]).optional(),
|
|
1062
|
+
style: looseRecordSchema.optional()
|
|
1063
|
+
}).passthrough();
|
|
1064
|
+
|
|
1065
|
+
//#endregion
|
|
1066
|
+
//#region ../api-contract/dist/resources.mjs
|
|
1067
|
+
/**
|
|
1068
|
+
* Canonical schemas for persistent `/api/v1` resources plus the owned,
|
|
1069
|
+
* deterministic code-extraction operation.
|
|
1070
|
+
*
|
|
1071
|
+
* These models are canonical, not upstream-shaped: providers (e.g. the Stately
|
|
1072
|
+
* Registry adapter) are responsible for translating upstream envelopes,
|
|
1073
|
+
* identifier quirks and casing into these shapes. No `{ data }` envelope
|
|
1074
|
+
* appears anywhere; all timestamps are ISO strings.
|
|
1075
|
+
*/
|
|
1076
|
+
/**
|
|
1077
|
+
* XState major versions the editor targets (see
|
|
1078
|
+
* `packages/editor/src/formats/xstate.ts`).
|
|
1079
|
+
*/
|
|
1080
|
+
const xstateVersionSchema = union([literal(5), literal(6)]);
|
|
1081
|
+
const projectVisibilitySchema = _enum([
|
|
1082
|
+
"public",
|
|
1083
|
+
"unlisted",
|
|
1084
|
+
"private"
|
|
1085
|
+
]);
|
|
1086
|
+
const verifyResultSchema = object({
|
|
1087
|
+
valid: literal(true),
|
|
1088
|
+
tokenScope: _enum(["user", "project"])
|
|
1089
|
+
});
|
|
1090
|
+
/**
|
|
1091
|
+
* Entitlements for the authenticated caller.
|
|
1092
|
+
*
|
|
1093
|
+
* Internal contract: this is not published as an `/api/v1` operation. Editor
|
|
1094
|
+
* feature gating resolves it server-side through the resource provider and
|
|
1095
|
+
* hands the mapped result to the client (see
|
|
1096
|
+
* `packages/editor/src/entitlements`).
|
|
1097
|
+
*
|
|
1098
|
+
* `entitlements` is an open set of provider-defined strings; unknown values are
|
|
1099
|
+
* ignored rather than rejected.
|
|
1100
|
+
*/
|
|
1101
|
+
const entitlementsResultSchema = object({
|
|
1102
|
+
subscription: object({
|
|
1103
|
+
tier: string$1(),
|
|
1104
|
+
status: string$1()
|
|
1105
|
+
}).nullable(),
|
|
1106
|
+
entitlements: array(string$1())
|
|
1107
|
+
});
|
|
1108
|
+
/**
|
|
1109
|
+
* Which editor format a machine's stored definition is in: `digraph` is the
|
|
1110
|
+
* original (legacy) editor's format, `xgraph` the current one.
|
|
1111
|
+
*/
|
|
1112
|
+
const machineDefinitionFormatSchema = _enum(["digraph", "xgraph"]);
|
|
1113
|
+
/**
|
|
1114
|
+
* `name` and timestamps are optional: some upstream project envelopes only
|
|
1115
|
+
* return machine ids. Providers that can supply them cheaply should.
|
|
1116
|
+
*/
|
|
1117
|
+
const projectMachineSummarySchema = object({
|
|
1118
|
+
machineId: string$1(),
|
|
1119
|
+
name: string$1().optional(),
|
|
1120
|
+
createdAt: string$1().optional(),
|
|
1121
|
+
updatedAt: string$1().optional(),
|
|
1122
|
+
format: machineDefinitionFormatSchema.optional(),
|
|
1123
|
+
locked: boolean$1().optional()
|
|
1124
|
+
});
|
|
1125
|
+
/**
|
|
1126
|
+
* A project list row. It carries the project's machine roster, not just its
|
|
1127
|
+
* metadata, so a client can mount a whole workspace from one `projects.list`
|
|
1128
|
+
* response and fetch definitions lazily.
|
|
1129
|
+
*/
|
|
1130
|
+
const projectSummarySchema = object({
|
|
1131
|
+
projectId: string$1(),
|
|
1132
|
+
projectVersionId: string$1(),
|
|
1133
|
+
name: string$1(),
|
|
1134
|
+
ownership: _enum(["personal", "team"]).optional(),
|
|
1135
|
+
description: string$1().nullable(),
|
|
1136
|
+
visibility: projectVisibilitySchema,
|
|
1137
|
+
createdAt: string$1(),
|
|
1138
|
+
updatedAt: string$1(),
|
|
1139
|
+
rootMachineId: string$1().nullable().optional(),
|
|
1140
|
+
machines: array(projectMachineSummarySchema).optional(),
|
|
1141
|
+
permissions: object({ canEdit: boolean$1() }).optional(),
|
|
1142
|
+
allowedVisibility: array(projectVisibilitySchema).optional()
|
|
1143
|
+
});
|
|
1144
|
+
const projectSchema = projectSummarySchema.extend({
|
|
1145
|
+
rootMachineId: string$1().nullable(),
|
|
1146
|
+
machines: array(projectMachineSummarySchema),
|
|
1147
|
+
permissions: object({ canEdit: boolean$1() })
|
|
1148
|
+
});
|
|
1149
|
+
const machineSchema = object({
|
|
1150
|
+
machineId: string$1(),
|
|
1151
|
+
name: string$1(),
|
|
1152
|
+
projectId: string$1().optional(),
|
|
1153
|
+
projectVersionId: string$1(),
|
|
1154
|
+
definition: unknown(),
|
|
1155
|
+
graph: xgraphSchema.optional(),
|
|
1156
|
+
createdAt: string$1().optional(),
|
|
1157
|
+
updatedAt: string$1().optional(),
|
|
1158
|
+
format: machineDefinitionFormatSchema.optional(),
|
|
1159
|
+
locked: boolean$1().optional()
|
|
1160
|
+
});
|
|
1161
|
+
const machineVersionSchema = object({
|
|
1162
|
+
machineVersionId: string$1(),
|
|
1163
|
+
machineId: string$1(),
|
|
1164
|
+
versionNumber: number$1(),
|
|
1165
|
+
name: string$1(),
|
|
1166
|
+
definition: unknown(),
|
|
1167
|
+
createdAt: string$1(),
|
|
1168
|
+
updatedAt: string$1(),
|
|
1169
|
+
format: machineDefinitionFormatSchema.optional()
|
|
1170
|
+
});
|
|
1171
|
+
/** Version-history row without the definition payload. */
|
|
1172
|
+
const machineVersionSummarySchema = object({
|
|
1173
|
+
machineVersionId: string$1(),
|
|
1174
|
+
machineId: string$1(),
|
|
1175
|
+
versionNumber: number$1(),
|
|
1176
|
+
name: string$1().nullable(),
|
|
1177
|
+
status: string$1(),
|
|
1178
|
+
parentVersionId: string$1().nullable(),
|
|
1179
|
+
createdAt: string$1(),
|
|
1180
|
+
updatedAt: string$1(),
|
|
1181
|
+
format: machineDefinitionFormatSchema.optional()
|
|
1182
|
+
});
|
|
1183
|
+
/** Result of converting a machine's stored definition to XGraph in place. */
|
|
1184
|
+
const machinesConvertResultSchema = object({
|
|
1185
|
+
machine: machineSchema,
|
|
1186
|
+
created: boolean$1(),
|
|
1187
|
+
version: object({
|
|
1188
|
+
machineVersionId: string$1(),
|
|
1189
|
+
versionNumber: number$1(),
|
|
1190
|
+
name: string$1().nullable()
|
|
1191
|
+
})
|
|
1192
|
+
});
|
|
1193
|
+
/**
|
|
1194
|
+
* A project the caller may fork a machine into, with the version ids a fork
|
|
1195
|
+
* can target. `projectVersionIds` is ordered as the provider reports it.
|
|
1196
|
+
*/
|
|
1197
|
+
const projectDestinationProjectSchema = object({
|
|
1198
|
+
projectId: string$1(),
|
|
1199
|
+
name: string$1(),
|
|
1200
|
+
visibility: projectVisibilitySchema,
|
|
1201
|
+
projectVersionIds: array(string$1())
|
|
1202
|
+
});
|
|
1203
|
+
/**
|
|
1204
|
+
* Fork destinations grouped by owner. The caller's personal projects are one
|
|
1205
|
+
* owner alongside each team; `ownerId` is opaque and provider-defined.
|
|
1206
|
+
*/
|
|
1207
|
+
const projectDestinationSchema = object({
|
|
1208
|
+
ownerId: string$1(),
|
|
1209
|
+
name: string$1(),
|
|
1210
|
+
projects: array(projectDestinationProjectSchema)
|
|
1211
|
+
});
|
|
1212
|
+
/** Result of forking a machine into a new or existing project version. */
|
|
1213
|
+
const machinesForkResultSchema = object({
|
|
1214
|
+
machine: machineSchema,
|
|
1215
|
+
projectVersionId: string$1(),
|
|
1216
|
+
projectId: string$1()
|
|
1217
|
+
});
|
|
1218
|
+
/**
|
|
1219
|
+
* The version holding a machine's pre-conversion (legacy editor) definition.
|
|
1220
|
+
* `versionId` is `null` when the machine has no such version, which is the
|
|
1221
|
+
* signal that the legacy editor cannot be re-entered for it.
|
|
1222
|
+
*/
|
|
1223
|
+
const machineLegacyVersionSchema = object({ versionId: string$1().nullable() });
|
|
1224
|
+
/** Result of restoring a machine's legacy-editor definition. */
|
|
1225
|
+
const machinesRestoreLegacyResultSchema = object({
|
|
1226
|
+
machine: machineSchema,
|
|
1227
|
+
version: object({
|
|
1228
|
+
machineVersionId: string$1(),
|
|
1229
|
+
versionNumber: number$1(),
|
|
1230
|
+
name: string$1().nullable()
|
|
1231
|
+
})
|
|
1232
|
+
});
|
|
1233
|
+
/**
|
|
1234
|
+
* Result of restoring a machine to one of its own versions.
|
|
1235
|
+
*
|
|
1236
|
+
* `capturedVersion` is the new version holding the machine's *pre-restore*
|
|
1237
|
+
* definition, so the restore itself is undoable. It is `null` when the restore
|
|
1238
|
+
* was a no-op (the machine already held that version's definition), which is
|
|
1239
|
+
* the signal that no history row was added.
|
|
1240
|
+
*/
|
|
1241
|
+
const machinesRestoreVersionResultSchema = object({
|
|
1242
|
+
machine: machineSchema,
|
|
1243
|
+
capturedVersion: machineVersionSummarySchema.nullable()
|
|
1244
|
+
});
|
|
1245
|
+
const extractedMachinesSchema = object({ machines: array(object({
|
|
1246
|
+
config: record(string$1(), unknown()),
|
|
1247
|
+
machineIndex: number$1().int().nonnegative().optional()
|
|
1248
|
+
})) });
|
|
1249
|
+
const projectsCreateRequestSchema = object({
|
|
1250
|
+
name: string$1().min(1),
|
|
1251
|
+
visibility: projectVisibilitySchema
|
|
1252
|
+
});
|
|
1253
|
+
const projectsUpdateRequestSchema = object({
|
|
1254
|
+
name: string$1().min(1).optional(),
|
|
1255
|
+
description: string$1().nullable().optional(),
|
|
1256
|
+
visibility: projectVisibilitySchema.optional()
|
|
1257
|
+
}).refine((value) => value.name !== void 0 || value.description !== void 0 || value.visibility !== void 0, { message: "At least one of `name`, `description` or `visibility` is required." });
|
|
1258
|
+
const machinesCreateRequestSchema = object({
|
|
1259
|
+
projectVersionId: string$1().min(1),
|
|
1260
|
+
xstateVersion: xstateVersionSchema,
|
|
1261
|
+
name: string$1().min(1).optional(),
|
|
1262
|
+
definition: unknown().optional()
|
|
1263
|
+
});
|
|
1264
|
+
const machinesUpdateRequestSchema = object({
|
|
1265
|
+
name: string$1().min(1).optional(),
|
|
1266
|
+
definition: unknown().optional(),
|
|
1267
|
+
expectedUpdatedAt: string$1().min(1).optional()
|
|
1268
|
+
}).refine((value) => value.name !== void 0 || value.definition !== void 0, { message: "At least one of `name` or `definition` is required." });
|
|
1269
|
+
/**
|
|
1270
|
+
* `status` is canonical lowercase; providers map it to their own casing.
|
|
1271
|
+
* Omitting `definition` snapshots the machine's current definition.
|
|
1272
|
+
*/
|
|
1273
|
+
const machineVersionsCreateRequestSchema = object({
|
|
1274
|
+
name: string$1().min(1).optional(),
|
|
1275
|
+
definition: unknown().optional(),
|
|
1276
|
+
status: _enum(["committed", "auto"]).optional(),
|
|
1277
|
+
parentVersionId: string$1().min(1).optional()
|
|
1278
|
+
});
|
|
1279
|
+
const machinesConvertRequestSchema = object({
|
|
1280
|
+
definition: xgraphSchema,
|
|
1281
|
+
expectedUpdatedAt: string$1().min(1),
|
|
1282
|
+
keepOriginalVersion: boolean$1().optional()
|
|
1283
|
+
});
|
|
1284
|
+
/**
|
|
1285
|
+
* Fork a machine into exactly one target: an existing project version, or a
|
|
1286
|
+
* new project to create for it. Both, or neither, is a client bug.
|
|
1287
|
+
*/
|
|
1288
|
+
const machinesForkRequestSchema = object({
|
|
1289
|
+
targetProjectVersionId: string$1().min(1).optional(),
|
|
1290
|
+
targetProject: object({
|
|
1291
|
+
name: string$1().min(1),
|
|
1292
|
+
visibility: projectVisibilitySchema,
|
|
1293
|
+
teamId: string$1().min(1).optional()
|
|
1294
|
+
}).optional(),
|
|
1295
|
+
machineName: string$1().min(1).optional(),
|
|
1296
|
+
xstateVersion: xstateVersionSchema.optional()
|
|
1297
|
+
}).refine((value) => value.targetProjectVersionId === void 0 !== (value.targetProject === void 0), { message: "Exactly one of `targetProjectVersionId` or `targetProject` is required." });
|
|
1298
|
+
const machinesRestoreLegacyRequestSchema = object({
|
|
1299
|
+
versionId: string$1().min(1).optional(),
|
|
1300
|
+
expectedUpdatedAt: string$1().min(1),
|
|
1301
|
+
reason: string$1().optional()
|
|
1302
|
+
});
|
|
1303
|
+
const machinesRestoreVersionRequestSchema = object({ expectedUpdatedAt: string$1().min(1).optional() });
|
|
1304
|
+
const codeExtractMachinesRequestSchema = object({
|
|
1305
|
+
code: string$1().min(1),
|
|
1306
|
+
xstateVersion: xstateVersionSchema.optional()
|
|
1307
|
+
});
|
|
1308
|
+
const authVerifyResponseSchema = verifyResultSchema;
|
|
1309
|
+
const projectsListResponseSchema = array(projectSummarySchema);
|
|
1310
|
+
const projectsGetResponseSchema = projectSchema;
|
|
1311
|
+
const projectsCreateResponseSchema = projectSchema;
|
|
1312
|
+
const projectsUpdateResponseSchema = projectSchema;
|
|
1313
|
+
const projectsDeleteResponseSchema = object({ projectId: string$1() });
|
|
1314
|
+
const projectsListMachinesResponseSchema = array(projectMachineSummarySchema);
|
|
1315
|
+
const projectsDestinationsResponseSchema = array(projectDestinationSchema);
|
|
1316
|
+
const machinesCreateResponseSchema = machineSchema;
|
|
1317
|
+
const machinesGetResponseSchema = machineSchema;
|
|
1318
|
+
const machinesUpdateResponseSchema = machineSchema;
|
|
1319
|
+
const machinesGetVersionResponseSchema = machineVersionSchema;
|
|
1320
|
+
const machineVersionsListResponseSchema = array(machineVersionSummarySchema);
|
|
1321
|
+
const machineVersionsCreateResponseSchema = machineVersionSchema;
|
|
1322
|
+
const machinesConvertDefinitionResponseSchema = machinesConvertResultSchema;
|
|
1323
|
+
const machinesForkResponseSchema = machinesForkResultSchema;
|
|
1324
|
+
const machinesGetLegacyVersionResponseSchema = machineLegacyVersionSchema;
|
|
1325
|
+
const machinesRestoreLegacyResponseSchema = machinesRestoreLegacyResultSchema;
|
|
1326
|
+
const machinesRestoreVersionResponseSchema = machinesRestoreVersionResultSchema;
|
|
1327
|
+
const codeExtractMachinesResponseSchema = extractedMachinesSchema;
|
|
1328
|
+
/**
|
|
1329
|
+
* Request/response schema pairs keyed by resource capability name. Kept here
|
|
1330
|
+
* rather than on the `Capability` metadata entries so that the capability
|
|
1331
|
+
* registry stays plain, serialisable data.
|
|
1332
|
+
*/
|
|
1333
|
+
const resourceOperationSchemas = {
|
|
1334
|
+
"auth.verify": { response: authVerifyResponseSchema },
|
|
1335
|
+
"projects.list": { response: projectsListResponseSchema },
|
|
1336
|
+
"projects.create": {
|
|
1337
|
+
request: projectsCreateRequestSchema,
|
|
1338
|
+
response: projectsCreateResponseSchema
|
|
1339
|
+
},
|
|
1340
|
+
"projects.get": { response: projectsGetResponseSchema },
|
|
1341
|
+
"projects.update": {
|
|
1342
|
+
request: projectsUpdateRequestSchema,
|
|
1343
|
+
response: projectsUpdateResponseSchema
|
|
1344
|
+
},
|
|
1345
|
+
"projects.delete": { response: projectsDeleteResponseSchema },
|
|
1346
|
+
"projects.listMachines": { response: projectsListMachinesResponseSchema },
|
|
1347
|
+
"projects.destinations": { response: projectsDestinationsResponseSchema },
|
|
1348
|
+
"machines.create": {
|
|
1349
|
+
request: machinesCreateRequestSchema,
|
|
1350
|
+
response: machinesCreateResponseSchema
|
|
1351
|
+
},
|
|
1352
|
+
"machines.get": { response: machinesGetResponseSchema },
|
|
1353
|
+
"machines.getVersion": { response: machinesGetVersionResponseSchema },
|
|
1354
|
+
"machines.update": {
|
|
1355
|
+
request: machinesUpdateRequestSchema,
|
|
1356
|
+
response: machinesUpdateResponseSchema
|
|
1357
|
+
},
|
|
1358
|
+
"machines.versions.list": { response: machineVersionsListResponseSchema },
|
|
1359
|
+
"machines.versions.create": {
|
|
1360
|
+
request: machineVersionsCreateRequestSchema,
|
|
1361
|
+
response: machineVersionsCreateResponseSchema
|
|
1362
|
+
},
|
|
1363
|
+
"machines.convertDefinition": {
|
|
1364
|
+
request: machinesConvertRequestSchema,
|
|
1365
|
+
response: machinesConvertDefinitionResponseSchema
|
|
1366
|
+
},
|
|
1367
|
+
"machines.fork": {
|
|
1368
|
+
request: machinesForkRequestSchema,
|
|
1369
|
+
response: machinesForkResponseSchema
|
|
1370
|
+
},
|
|
1371
|
+
"machines.getLegacyVersion": { response: machinesGetLegacyVersionResponseSchema },
|
|
1372
|
+
"machines.restoreLegacy": {
|
|
1373
|
+
request: machinesRestoreLegacyRequestSchema,
|
|
1374
|
+
response: machinesRestoreLegacyResponseSchema
|
|
1375
|
+
},
|
|
1376
|
+
"machines.restoreVersion": {
|
|
1377
|
+
request: machinesRestoreVersionRequestSchema,
|
|
1378
|
+
response: machinesRestoreVersionResponseSchema
|
|
1379
|
+
}
|
|
1380
|
+
};
|
|
1381
|
+
/** Provider-independent operations implemented by this repository. */
|
|
1382
|
+
const codeOperationSchemas = { "code.extractMachines": {
|
|
1383
|
+
request: codeExtractMachinesRequestSchema,
|
|
1384
|
+
response: codeExtractMachinesResponseSchema
|
|
1385
|
+
} };
|
|
1386
|
+
/** Every owned API operation with a canonical request/response contract. */
|
|
1387
|
+
const operationSchemas = {
|
|
1388
|
+
...resourceOperationSchemas,
|
|
1389
|
+
...codeOperationSchemas
|
|
1390
|
+
};
|
|
1391
|
+
|
|
1392
|
+
//#endregion
|
|
1393
|
+
//#region src/studio.ts
|
|
1394
|
+
/**
|
|
1395
|
+
* Remote client for the owned Stately resource contract (`/api/v1/*`).
|
|
1396
|
+
*
|
|
1397
|
+
* Every method targets our own routes (never the legacy Registry API), sends
|
|
1398
|
+
* JSON bodies with a bearer credential, and validates responses against the
|
|
1399
|
+
* canonical Zod schemas from `@statelyai/api-contract`. Responses are canonical
|
|
1400
|
+
* values directly: there is no `{ data }` envelope. Errors use the nested
|
|
1401
|
+
* envelope `{ error: { code, message, issues?, retryable? } }`.
|
|
1402
|
+
*/
|
|
1403
|
+
/** Default base URL of the editor/API deployment hosting `/api/v1`. */
|
|
1404
|
+
const DEFAULT_STATELY_BASE_URL = "https://editor.stately.ai";
|
|
1405
|
+
var StudioApiError = class extends Error {
|
|
1406
|
+
status;
|
|
1407
|
+
/** Canonical resource error code, when the server sent one. */
|
|
1408
|
+
code;
|
|
1409
|
+
issues;
|
|
1410
|
+
retryable;
|
|
1411
|
+
constructor(message, status, options = {}) {
|
|
1412
|
+
super(message);
|
|
1413
|
+
this.name = "StudioApiError";
|
|
1414
|
+
this.status = status;
|
|
1415
|
+
this.code = options.code;
|
|
1416
|
+
this.issues = options.issues;
|
|
1417
|
+
this.retryable = options.retryable;
|
|
1418
|
+
}
|
|
1419
|
+
};
|
|
1420
|
+
function getFetch(fetchImpl) {
|
|
1421
|
+
const resolvedFetch = fetchImpl ?? globalThis.fetch;
|
|
1422
|
+
if (!resolvedFetch) throw new Error("No fetch implementation available. Pass one via createStatelyClient({ fetch }).");
|
|
1423
|
+
return resolvedFetch;
|
|
1424
|
+
}
|
|
1425
|
+
function joinApiUrl(baseUrl, path) {
|
|
1426
|
+
return `${baseUrl.replace(/\/+$/, "")}/api/v1${path}`;
|
|
1427
|
+
}
|
|
1428
|
+
async function parseJson(response) {
|
|
1429
|
+
if (!response.headers.get("content-type")?.includes("application/json")) return null;
|
|
1430
|
+
return response.json().catch(() => null);
|
|
1431
|
+
}
|
|
1432
|
+
function toApiError(data, status) {
|
|
1433
|
+
const parsed = resourceApiErrorResponseSchema.safeParse(data);
|
|
1434
|
+
if (parsed.success) {
|
|
1435
|
+
const { code, message, issues, retryable } = parsed.data.error;
|
|
1436
|
+
return new StudioApiError(message, status, {
|
|
1437
|
+
code,
|
|
1438
|
+
issues,
|
|
1439
|
+
retryable
|
|
1440
|
+
});
|
|
1441
|
+
}
|
|
1442
|
+
if (typeof data === "object" && data !== null && "error" in data && typeof data.error === "string") return new StudioApiError(data.error, status);
|
|
1443
|
+
return new StudioApiError(`HTTP ${status}`, status);
|
|
1444
|
+
}
|
|
1445
|
+
function normalizeVisibility(visibility) {
|
|
1446
|
+
return visibility.toLowerCase();
|
|
1447
|
+
}
|
|
1448
|
+
function normalizeXStateVersion(xstateVersion) {
|
|
1449
|
+
return xstateVersion === void 0 || xstateVersion === 4 ? 5 : xstateVersion;
|
|
1450
|
+
}
|
|
1451
|
+
function normalizeExtractXStateVersion(xstateVersion) {
|
|
1452
|
+
return xstateVersion === 4 ? 5 : xstateVersion;
|
|
1453
|
+
}
|
|
1454
|
+
function withMachineAlias(machine) {
|
|
1455
|
+
return {
|
|
1456
|
+
...machine,
|
|
1457
|
+
definition: machine.definition,
|
|
1458
|
+
id: machine.machineId
|
|
1459
|
+
};
|
|
1460
|
+
}
|
|
1461
|
+
function withProjectAlias(project) {
|
|
1462
|
+
return {
|
|
1463
|
+
...project,
|
|
1464
|
+
id: project.projectVersionId
|
|
1465
|
+
};
|
|
1466
|
+
}
|
|
1467
|
+
function isCredentialLike(value) {
|
|
1468
|
+
if (typeof value === "string") return true;
|
|
1469
|
+
return typeof value === "object" && value !== null && "type" in value && (value.type === "api_key" || value.type === "oauth");
|
|
1470
|
+
}
|
|
1471
|
+
function createStatelyClient(options = {}) {
|
|
1472
|
+
const baseUrl = options.baseUrl ?? DEFAULT_STATELY_BASE_URL;
|
|
1473
|
+
const fetchImpl = getFetch(options.fetch);
|
|
1474
|
+
const defaultCredential = options.credential ?? (options.apiKey ? {
|
|
1475
|
+
type: "api_key",
|
|
1476
|
+
token: options.apiKey
|
|
1477
|
+
} : void 0);
|
|
1478
|
+
const defaultAuthMode = options.authMode ?? "auto";
|
|
1479
|
+
async function request(path, init, schema, requestOptions = {}) {
|
|
1480
|
+
const headers = new Headers(init.headers);
|
|
1481
|
+
const authMode = requestOptions.authMode ?? defaultAuthMode;
|
|
1482
|
+
const credential = requestOptions.credential ?? defaultCredential;
|
|
1483
|
+
if (authMode !== "none") {
|
|
1484
|
+
const token = getCredentialToken(credential);
|
|
1485
|
+
if (authMode === "bearer" && (!token || !credential)) throw new StudioApiError("No Stately credential configured. Pass createStatelyClient({ credential }) or use authMode: \"auto\" to let the server decide whether authentication is required.", 401, { code: "unauthenticated" });
|
|
1486
|
+
if (token && credential) headers.set("Authorization", createAuthorizationHeader(credential));
|
|
1487
|
+
}
|
|
1488
|
+
const response = await fetchImpl(joinApiUrl(baseUrl, path), {
|
|
1489
|
+
...init,
|
|
1490
|
+
headers,
|
|
1491
|
+
...requestOptions.signal ? { signal: requestOptions.signal } : {}
|
|
1492
|
+
});
|
|
1493
|
+
const data = await parseJson(response);
|
|
1494
|
+
if (!response.ok) throw toApiError(data, response.status);
|
|
1495
|
+
const parsed = schema.safeParse(data);
|
|
1496
|
+
if (!parsed.success) throw new StudioApiError(`Unexpected response for ${path}: ${parsed.error.message}`, response.status, {
|
|
1497
|
+
code: "internal_error",
|
|
1498
|
+
issues: [...parsed.error.issues]
|
|
1499
|
+
});
|
|
1500
|
+
return parsed.data;
|
|
1501
|
+
}
|
|
1502
|
+
function jsonInit(method, body) {
|
|
1503
|
+
return {
|
|
1504
|
+
method,
|
|
1505
|
+
headers: { "Content-Type": "application/json" },
|
|
1506
|
+
body: JSON.stringify(body)
|
|
1507
|
+
};
|
|
1508
|
+
}
|
|
1509
|
+
const projects = {
|
|
1510
|
+
list(requestOptions) {
|
|
1511
|
+
return request("/projects", { method: "GET" }, projectsListResponseSchema, requestOptions);
|
|
1512
|
+
},
|
|
1513
|
+
create(input, requestOptions) {
|
|
1514
|
+
return request("/projects", jsonInit("POST", {
|
|
1515
|
+
name: input.name,
|
|
1516
|
+
visibility: normalizeVisibility(input.visibility)
|
|
1517
|
+
}), projectSchema, requestOptions).then(withProjectAlias);
|
|
1518
|
+
},
|
|
1519
|
+
get(projectId, requestOptions) {
|
|
1520
|
+
return request(`/projects/${encodeURIComponent(projectId)}`, { method: "GET" }, projectSchema, requestOptions).then(withProjectAlias);
|
|
1521
|
+
},
|
|
1522
|
+
update(projectId, input, requestOptions) {
|
|
1523
|
+
return request(`/projects/${encodeURIComponent(projectId)}`, jsonInit("PATCH", {
|
|
1524
|
+
...input.name !== void 0 ? { name: input.name } : {},
|
|
1525
|
+
...input.description !== void 0 ? { description: input.description } : {},
|
|
1526
|
+
...input.visibility !== void 0 ? { visibility: normalizeVisibility(input.visibility) } : {}
|
|
1527
|
+
}), projectSchema, requestOptions).then(withProjectAlias);
|
|
1528
|
+
},
|
|
1529
|
+
delete(projectId, requestOptions) {
|
|
1530
|
+
return request(`/projects/${encodeURIComponent(projectId)}`, { method: "DELETE" }, projectsDeleteResponseSchema, requestOptions);
|
|
1531
|
+
},
|
|
1532
|
+
listMachines(projectId, requestOptions) {
|
|
1533
|
+
return request(`/projects/${encodeURIComponent(projectId)}/machines`, { method: "GET" }, projectsListMachinesResponseSchema, requestOptions);
|
|
1534
|
+
},
|
|
1535
|
+
async ensure(input, requestOptions) {
|
|
1536
|
+
if (input.matchConnectedRepo !== false) {
|
|
1537
|
+
const match = (await projects.list(requestOptions)).find((candidate) => candidate.name === input.name);
|
|
1538
|
+
if (match) return projects.get(match.projectId, requestOptions);
|
|
1539
|
+
}
|
|
1540
|
+
return projects.create(input, requestOptions);
|
|
1541
|
+
}
|
|
1542
|
+
};
|
|
1543
|
+
const machines = {
|
|
1544
|
+
create(input, requestOptions) {
|
|
1545
|
+
return request("/machines", jsonInit("POST", {
|
|
1546
|
+
projectVersionId: input.projectVersionId,
|
|
1547
|
+
xstateVersion: normalizeXStateVersion(input.xstateVersion),
|
|
1548
|
+
...input.name !== void 0 ? { name: input.name } : {},
|
|
1549
|
+
...input.definition !== void 0 ? { definition: input.definition } : {}
|
|
1550
|
+
}), machineSchema, requestOptions).then((machine) => withMachineAlias(machine));
|
|
1551
|
+
},
|
|
1552
|
+
async createMany(input, requestOptions) {
|
|
1553
|
+
return [await machines.create(input, requestOptions)];
|
|
1554
|
+
},
|
|
1555
|
+
get(machineId, getOptions = {}) {
|
|
1556
|
+
return request(`/machines/${encodeURIComponent(machineId)}`, { method: "GET" }, machineSchema, getOptions).then((machine) => withMachineAlias(machine));
|
|
1557
|
+
},
|
|
1558
|
+
getVersion(machineId, versionId, requestOptions) {
|
|
1559
|
+
return request(`/machines/${encodeURIComponent(machineId)}/versions/${encodeURIComponent(versionId)}`, { method: "GET" }, machineVersionSchema, requestOptions);
|
|
1560
|
+
},
|
|
1561
|
+
update(machineIdOrInput, inputOrOptions, maybeOptions) {
|
|
1562
|
+
const machineId = typeof machineIdOrInput === "string" ? machineIdOrInput : machineIdOrInput.machineId ?? machineIdOrInput.id;
|
|
1563
|
+
if (!machineId) throw new StudioApiError("machines.update requires a machine id.", 400, { code: "bad_request" });
|
|
1564
|
+
const input = (typeof machineIdOrInput === "string" ? inputOrOptions : machineIdOrInput) ?? {};
|
|
1565
|
+
const requestOptions = typeof machineIdOrInput === "string" ? maybeOptions : inputOrOptions;
|
|
1566
|
+
return request(`/machines/${encodeURIComponent(machineId)}`, jsonInit("PATCH", {
|
|
1567
|
+
...input.name !== void 0 ? { name: input.name } : {},
|
|
1568
|
+
...input.definition !== void 0 ? { definition: input.definition } : {},
|
|
1569
|
+
...input.expectedUpdatedAt !== void 0 ? { expectedUpdatedAt: input.expectedUpdatedAt } : {}
|
|
1570
|
+
}), machineSchema, requestOptions).then((machine) => withMachineAlias(machine));
|
|
1571
|
+
}
|
|
1572
|
+
};
|
|
1573
|
+
return {
|
|
1574
|
+
auth: { verify(credentialOrOptions, verifyOptions) {
|
|
1575
|
+
return request("/auth/verify", { method: "GET" }, verifyResultSchema, isCredentialLike(credentialOrOptions) ? {
|
|
1576
|
+
...verifyOptions,
|
|
1577
|
+
credential: credentialOrOptions
|
|
1578
|
+
} : credentialOrOptions ?? verifyOptions ?? {});
|
|
1579
|
+
} },
|
|
1580
|
+
projects,
|
|
1581
|
+
machines,
|
|
1582
|
+
code: { extractMachines(codeOrInput, extractOptions = {}) {
|
|
1583
|
+
const input = typeof codeOrInput === "string" ? {
|
|
1584
|
+
code: codeOrInput,
|
|
1585
|
+
xstateVersion: extractOptions.xstateVersion
|
|
1586
|
+
} : codeOrInput;
|
|
1587
|
+
const legacyOptions = extractOptions;
|
|
1588
|
+
const credential = legacyOptions.credential ?? (legacyOptions.apiKey ? {
|
|
1589
|
+
type: "api_key",
|
|
1590
|
+
token: legacyOptions.apiKey
|
|
1591
|
+
} : void 0);
|
|
1592
|
+
return request("/code/extract-machines", jsonInit("POST", {
|
|
1593
|
+
code: input.code,
|
|
1594
|
+
xstateVersion: normalizeExtractXStateVersion(input.xstateVersion)
|
|
1595
|
+
}), extractedMachinesSchema, {
|
|
1596
|
+
...extractOptions,
|
|
1597
|
+
credential
|
|
1598
|
+
});
|
|
1599
|
+
} }
|
|
1600
|
+
};
|
|
1601
|
+
}
|
|
1602
|
+
|
|
1603
|
+
//#endregion
|
|
1604
|
+
export { StudioApiError as n, createStatelyClient as r, DEFAULT_STATELY_BASE_URL as t };
|