@clovnet/plugin-sdk 0.1.4
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 +114 -0
- package/dist/chunk-XRSKWL3A.js +1872 -0
- package/dist/chunk-XRSKWL3A.js.map +1 -0
- package/dist/index.d.ts +3658 -0
- package/dist/index.js +561 -0
- package/dist/index.js.map +1 -0
- package/dist/testing.d.ts +275 -0
- package/dist/testing.js +1010 -0
- package/dist/testing.js.map +1 -0
- package/package.json +75 -0
|
@@ -0,0 +1,1872 @@
|
|
|
1
|
+
// src/data.ts
|
|
2
|
+
var DataScopes = [
|
|
3
|
+
"players:read",
|
|
4
|
+
"players:pii",
|
|
5
|
+
"wallet:read",
|
|
6
|
+
"ledger:read",
|
|
7
|
+
"bets:read",
|
|
8
|
+
"bonus:read",
|
|
9
|
+
"affiliate:read",
|
|
10
|
+
"tenant:read",
|
|
11
|
+
"kyc:read",
|
|
12
|
+
"documents:read",
|
|
13
|
+
"limits:read",
|
|
14
|
+
"catalog:read"
|
|
15
|
+
];
|
|
16
|
+
var ReadModelRequiredScopes = {
|
|
17
|
+
"players.list": "players:read",
|
|
18
|
+
"players.byId": "players:read",
|
|
19
|
+
"wallet.balances": "wallet:read",
|
|
20
|
+
"ledger.entries": "ledger:read",
|
|
21
|
+
"bets.list": "bets:read",
|
|
22
|
+
"bets.byRound": "bets:read",
|
|
23
|
+
"tenant.info": "tenant:read",
|
|
24
|
+
"kyc.state": "kyc:read",
|
|
25
|
+
"kyc.requests": "kyc:read",
|
|
26
|
+
"kyc.documents": "documents:read",
|
|
27
|
+
"bets.byPlayer": "bets:read",
|
|
28
|
+
"gameSessions.list": "bets:read",
|
|
29
|
+
"limits.byPlayer": "limits:read",
|
|
30
|
+
"catalog.games": "catalog:read",
|
|
31
|
+
"catalog.categories": "catalog:read",
|
|
32
|
+
"catalog.providers": "catalog:read"
|
|
33
|
+
};
|
|
34
|
+
var READ_MODEL_MAX_PAGE = 200;
|
|
35
|
+
|
|
36
|
+
// src/datasets.ts
|
|
37
|
+
var PLUGIN_DATASET_LIMITS = {
|
|
38
|
+
maxIndexes: 3,
|
|
39
|
+
maxBatch: 500,
|
|
40
|
+
maxQueryLimit: 200,
|
|
41
|
+
/** Serialized record cap in bytes. */
|
|
42
|
+
maxRecordBytes: 65536,
|
|
43
|
+
/** Default per-tenant record quota when the declaration omits one. */
|
|
44
|
+
defaultMaxRecords: 1e5
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// src/jobs.ts
|
|
48
|
+
var PLUGIN_JOB_LIMITS = {
|
|
49
|
+
defaultTimeoutSec: 300,
|
|
50
|
+
maxTimeoutSec: 900,
|
|
51
|
+
/** Consecutive failures before `PLUGIN_JOB_FAILED` is emitted. */
|
|
52
|
+
failureStreakThreshold: 3
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
// src/migrations.ts
|
|
56
|
+
var PLUGIN_MIGRATION_LIMITS = {
|
|
57
|
+
batchSize: 500,
|
|
58
|
+
/** Per-step timeout (ms). */
|
|
59
|
+
stepTimeoutMs: 9e5
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
// src/catalog.ts
|
|
63
|
+
var CATALOG_IMPORT_TASK_TYPE = "catalog:import";
|
|
64
|
+
var CATALOG_ALLOWED_KINDS = ["provider", "content", "integration"];
|
|
65
|
+
var PLUGIN_CATALOG_LIMITS = {
|
|
66
|
+
/** Max rows per family per `upsertBatch` call. */
|
|
67
|
+
maxRowsPerFamily: 500
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
// src/actions.ts
|
|
71
|
+
var ACTION_KEY_RE = /^[a-z][a-zA-Z0-9]*$/;
|
|
72
|
+
function parseActionRoute(route) {
|
|
73
|
+
const match = /^([A-Z]+) (\/\S*)$/.exec(route);
|
|
74
|
+
if (!match) return null;
|
|
75
|
+
return { method: match[1], path: match[2] };
|
|
76
|
+
}
|
|
77
|
+
function fullPluginEventName(shortType) {
|
|
78
|
+
return `plugin.${shortType}`;
|
|
79
|
+
}
|
|
80
|
+
function shortPluginEventType(fullName) {
|
|
81
|
+
return fullName.startsWith("plugin.") ? fullName.slice("plugin.".length) : null;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/Options.js
|
|
85
|
+
var ignoreOverride = /* @__PURE__ */ Symbol("Let zodToJsonSchema decide on which parser to use");
|
|
86
|
+
var defaultOptions = {
|
|
87
|
+
name: void 0,
|
|
88
|
+
$refStrategy: "root",
|
|
89
|
+
basePath: ["#"],
|
|
90
|
+
effectStrategy: "input",
|
|
91
|
+
pipeStrategy: "all",
|
|
92
|
+
dateStrategy: "format:date-time",
|
|
93
|
+
mapStrategy: "entries",
|
|
94
|
+
removeAdditionalStrategy: "passthrough",
|
|
95
|
+
allowedAdditionalProperties: true,
|
|
96
|
+
rejectedAdditionalProperties: false,
|
|
97
|
+
definitionPath: "definitions",
|
|
98
|
+
target: "jsonSchema7",
|
|
99
|
+
strictUnions: false,
|
|
100
|
+
definitions: {},
|
|
101
|
+
errorMessages: false,
|
|
102
|
+
markdownDescription: false,
|
|
103
|
+
patternStrategy: "escape",
|
|
104
|
+
applyRegexFlags: false,
|
|
105
|
+
emailStrategy: "format:email",
|
|
106
|
+
base64Strategy: "contentEncoding:base64",
|
|
107
|
+
nameStrategy: "ref",
|
|
108
|
+
openAiAnyTypeName: "OpenAiAnyType"
|
|
109
|
+
};
|
|
110
|
+
var getDefaultOptions = (options) => typeof options === "string" ? {
|
|
111
|
+
...defaultOptions,
|
|
112
|
+
name: options
|
|
113
|
+
} : {
|
|
114
|
+
...defaultOptions,
|
|
115
|
+
...options
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/Refs.js
|
|
119
|
+
var getRefs = (options) => {
|
|
120
|
+
const _options = getDefaultOptions(options);
|
|
121
|
+
const currentPath = _options.name !== void 0 ? [..._options.basePath, _options.definitionPath, _options.name] : _options.basePath;
|
|
122
|
+
return {
|
|
123
|
+
..._options,
|
|
124
|
+
flags: { hasReferencedOpenAiAnyType: false },
|
|
125
|
+
currentPath,
|
|
126
|
+
propertyPath: void 0,
|
|
127
|
+
seen: new Map(Object.entries(_options.definitions).map(([name, def]) => [
|
|
128
|
+
def._def,
|
|
129
|
+
{
|
|
130
|
+
def: def._def,
|
|
131
|
+
path: [..._options.basePath, _options.definitionPath, name],
|
|
132
|
+
// Resolution of references will be forced even though seen, so it's ok that the schema is undefined here for now.
|
|
133
|
+
jsonSchema: void 0
|
|
134
|
+
}
|
|
135
|
+
]))
|
|
136
|
+
};
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/errorMessages.js
|
|
140
|
+
function addErrorMessage(res, key, errorMessage, refs) {
|
|
141
|
+
if (!refs?.errorMessages)
|
|
142
|
+
return;
|
|
143
|
+
if (errorMessage) {
|
|
144
|
+
res.errorMessage = {
|
|
145
|
+
...res.errorMessage,
|
|
146
|
+
[key]: errorMessage
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
function setResponseValueAndErrors(res, key, value, errorMessage, refs) {
|
|
151
|
+
res[key] = value;
|
|
152
|
+
addErrorMessage(res, key, errorMessage, refs);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/getRelativePath.js
|
|
156
|
+
var getRelativePath = (pathA, pathB) => {
|
|
157
|
+
let i = 0;
|
|
158
|
+
for (; i < pathA.length && i < pathB.length; i++) {
|
|
159
|
+
if (pathA[i] !== pathB[i])
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
return [(pathA.length - i).toString(), ...pathB.slice(i)].join("/");
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/selectParser.js
|
|
166
|
+
import { ZodFirstPartyTypeKind as ZodFirstPartyTypeKind3 } from "zod/v3";
|
|
167
|
+
|
|
168
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/any.js
|
|
169
|
+
function parseAnyDef(refs) {
|
|
170
|
+
if (refs.target !== "openAi") {
|
|
171
|
+
return {};
|
|
172
|
+
}
|
|
173
|
+
const anyDefinitionPath = [
|
|
174
|
+
...refs.basePath,
|
|
175
|
+
refs.definitionPath,
|
|
176
|
+
refs.openAiAnyTypeName
|
|
177
|
+
];
|
|
178
|
+
refs.flags.hasReferencedOpenAiAnyType = true;
|
|
179
|
+
return {
|
|
180
|
+
$ref: refs.$refStrategy === "relative" ? getRelativePath(anyDefinitionPath, refs.currentPath) : anyDefinitionPath.join("/")
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/array.js
|
|
185
|
+
import { ZodFirstPartyTypeKind } from "zod/v3";
|
|
186
|
+
function parseArrayDef(def, refs) {
|
|
187
|
+
const res = {
|
|
188
|
+
type: "array"
|
|
189
|
+
};
|
|
190
|
+
if (def.type?._def && def.type?._def?.typeName !== ZodFirstPartyTypeKind.ZodAny) {
|
|
191
|
+
res.items = parseDef(def.type._def, {
|
|
192
|
+
...refs,
|
|
193
|
+
currentPath: [...refs.currentPath, "items"]
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
if (def.minLength) {
|
|
197
|
+
setResponseValueAndErrors(res, "minItems", def.minLength.value, def.minLength.message, refs);
|
|
198
|
+
}
|
|
199
|
+
if (def.maxLength) {
|
|
200
|
+
setResponseValueAndErrors(res, "maxItems", def.maxLength.value, def.maxLength.message, refs);
|
|
201
|
+
}
|
|
202
|
+
if (def.exactLength) {
|
|
203
|
+
setResponseValueAndErrors(res, "minItems", def.exactLength.value, def.exactLength.message, refs);
|
|
204
|
+
setResponseValueAndErrors(res, "maxItems", def.exactLength.value, def.exactLength.message, refs);
|
|
205
|
+
}
|
|
206
|
+
return res;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/bigint.js
|
|
210
|
+
function parseBigintDef(def, refs) {
|
|
211
|
+
const res = {
|
|
212
|
+
type: "integer",
|
|
213
|
+
format: "int64"
|
|
214
|
+
};
|
|
215
|
+
if (!def.checks)
|
|
216
|
+
return res;
|
|
217
|
+
for (const check of def.checks) {
|
|
218
|
+
switch (check.kind) {
|
|
219
|
+
case "min":
|
|
220
|
+
if (refs.target === "jsonSchema7") {
|
|
221
|
+
if (check.inclusive) {
|
|
222
|
+
setResponseValueAndErrors(res, "minimum", check.value, check.message, refs);
|
|
223
|
+
} else {
|
|
224
|
+
setResponseValueAndErrors(res, "exclusiveMinimum", check.value, check.message, refs);
|
|
225
|
+
}
|
|
226
|
+
} else {
|
|
227
|
+
if (!check.inclusive) {
|
|
228
|
+
res.exclusiveMinimum = true;
|
|
229
|
+
}
|
|
230
|
+
setResponseValueAndErrors(res, "minimum", check.value, check.message, refs);
|
|
231
|
+
}
|
|
232
|
+
break;
|
|
233
|
+
case "max":
|
|
234
|
+
if (refs.target === "jsonSchema7") {
|
|
235
|
+
if (check.inclusive) {
|
|
236
|
+
setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
|
|
237
|
+
} else {
|
|
238
|
+
setResponseValueAndErrors(res, "exclusiveMaximum", check.value, check.message, refs);
|
|
239
|
+
}
|
|
240
|
+
} else {
|
|
241
|
+
if (!check.inclusive) {
|
|
242
|
+
res.exclusiveMaximum = true;
|
|
243
|
+
}
|
|
244
|
+
setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
|
|
245
|
+
}
|
|
246
|
+
break;
|
|
247
|
+
case "multipleOf":
|
|
248
|
+
setResponseValueAndErrors(res, "multipleOf", check.value, check.message, refs);
|
|
249
|
+
break;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return res;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/boolean.js
|
|
256
|
+
function parseBooleanDef() {
|
|
257
|
+
return {
|
|
258
|
+
type: "boolean"
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/branded.js
|
|
263
|
+
function parseBrandedDef(_def, refs) {
|
|
264
|
+
return parseDef(_def.type._def, refs);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/catch.js
|
|
268
|
+
var parseCatchDef = (def, refs) => {
|
|
269
|
+
return parseDef(def.innerType._def, refs);
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/date.js
|
|
273
|
+
function parseDateDef(def, refs, overrideDateStrategy) {
|
|
274
|
+
const strategy = overrideDateStrategy ?? refs.dateStrategy;
|
|
275
|
+
if (Array.isArray(strategy)) {
|
|
276
|
+
return {
|
|
277
|
+
anyOf: strategy.map((item, i) => parseDateDef(def, refs, item))
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
switch (strategy) {
|
|
281
|
+
case "string":
|
|
282
|
+
case "format:date-time":
|
|
283
|
+
return {
|
|
284
|
+
type: "string",
|
|
285
|
+
format: "date-time"
|
|
286
|
+
};
|
|
287
|
+
case "format:date":
|
|
288
|
+
return {
|
|
289
|
+
type: "string",
|
|
290
|
+
format: "date"
|
|
291
|
+
};
|
|
292
|
+
case "integer":
|
|
293
|
+
return integerDateParser(def, refs);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
var integerDateParser = (def, refs) => {
|
|
297
|
+
const res = {
|
|
298
|
+
type: "integer",
|
|
299
|
+
format: "unix-time"
|
|
300
|
+
};
|
|
301
|
+
if (refs.target === "openApi3") {
|
|
302
|
+
return res;
|
|
303
|
+
}
|
|
304
|
+
for (const check of def.checks) {
|
|
305
|
+
switch (check.kind) {
|
|
306
|
+
case "min":
|
|
307
|
+
setResponseValueAndErrors(
|
|
308
|
+
res,
|
|
309
|
+
"minimum",
|
|
310
|
+
check.value,
|
|
311
|
+
// This is in milliseconds
|
|
312
|
+
check.message,
|
|
313
|
+
refs
|
|
314
|
+
);
|
|
315
|
+
break;
|
|
316
|
+
case "max":
|
|
317
|
+
setResponseValueAndErrors(
|
|
318
|
+
res,
|
|
319
|
+
"maximum",
|
|
320
|
+
check.value,
|
|
321
|
+
// This is in milliseconds
|
|
322
|
+
check.message,
|
|
323
|
+
refs
|
|
324
|
+
);
|
|
325
|
+
break;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
return res;
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/default.js
|
|
332
|
+
function parseDefaultDef(_def, refs) {
|
|
333
|
+
return {
|
|
334
|
+
...parseDef(_def.innerType._def, refs),
|
|
335
|
+
default: _def.defaultValue()
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/effects.js
|
|
340
|
+
function parseEffectsDef(_def, refs) {
|
|
341
|
+
return refs.effectStrategy === "input" ? parseDef(_def.schema._def, refs) : parseAnyDef(refs);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/enum.js
|
|
345
|
+
function parseEnumDef(def) {
|
|
346
|
+
return {
|
|
347
|
+
type: "string",
|
|
348
|
+
enum: Array.from(def.values)
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/intersection.js
|
|
353
|
+
var isJsonSchema7AllOfType = (type) => {
|
|
354
|
+
if ("type" in type && type.type === "string")
|
|
355
|
+
return false;
|
|
356
|
+
return "allOf" in type;
|
|
357
|
+
};
|
|
358
|
+
function parseIntersectionDef(def, refs) {
|
|
359
|
+
const allOf = [
|
|
360
|
+
parseDef(def.left._def, {
|
|
361
|
+
...refs,
|
|
362
|
+
currentPath: [...refs.currentPath, "allOf", "0"]
|
|
363
|
+
}),
|
|
364
|
+
parseDef(def.right._def, {
|
|
365
|
+
...refs,
|
|
366
|
+
currentPath: [...refs.currentPath, "allOf", "1"]
|
|
367
|
+
})
|
|
368
|
+
].filter((x) => !!x);
|
|
369
|
+
let unevaluatedProperties = refs.target === "jsonSchema2019-09" ? { unevaluatedProperties: false } : void 0;
|
|
370
|
+
const mergedAllOf = [];
|
|
371
|
+
allOf.forEach((schema) => {
|
|
372
|
+
if (isJsonSchema7AllOfType(schema)) {
|
|
373
|
+
mergedAllOf.push(...schema.allOf);
|
|
374
|
+
if (schema.unevaluatedProperties === void 0) {
|
|
375
|
+
unevaluatedProperties = void 0;
|
|
376
|
+
}
|
|
377
|
+
} else {
|
|
378
|
+
let nestedSchema = schema;
|
|
379
|
+
if ("additionalProperties" in schema && schema.additionalProperties === false) {
|
|
380
|
+
const { additionalProperties, ...rest } = schema;
|
|
381
|
+
nestedSchema = rest;
|
|
382
|
+
} else {
|
|
383
|
+
unevaluatedProperties = void 0;
|
|
384
|
+
}
|
|
385
|
+
mergedAllOf.push(nestedSchema);
|
|
386
|
+
}
|
|
387
|
+
});
|
|
388
|
+
return mergedAllOf.length ? {
|
|
389
|
+
allOf: mergedAllOf,
|
|
390
|
+
...unevaluatedProperties
|
|
391
|
+
} : void 0;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/literal.js
|
|
395
|
+
function parseLiteralDef(def, refs) {
|
|
396
|
+
const parsedType = typeof def.value;
|
|
397
|
+
if (parsedType !== "bigint" && parsedType !== "number" && parsedType !== "boolean" && parsedType !== "string") {
|
|
398
|
+
return {
|
|
399
|
+
type: Array.isArray(def.value) ? "array" : "object"
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
if (refs.target === "openApi3") {
|
|
403
|
+
return {
|
|
404
|
+
type: parsedType === "bigint" ? "integer" : parsedType,
|
|
405
|
+
enum: [def.value]
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
return {
|
|
409
|
+
type: parsedType === "bigint" ? "integer" : parsedType,
|
|
410
|
+
const: def.value
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/record.js
|
|
415
|
+
import { ZodFirstPartyTypeKind as ZodFirstPartyTypeKind2 } from "zod/v3";
|
|
416
|
+
|
|
417
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/string.js
|
|
418
|
+
var emojiRegex = void 0;
|
|
419
|
+
var zodPatterns = {
|
|
420
|
+
/**
|
|
421
|
+
* `c` was changed to `[cC]` to replicate /i flag
|
|
422
|
+
*/
|
|
423
|
+
cuid: /^[cC][^\s-]{8,}$/,
|
|
424
|
+
cuid2: /^[0-9a-z]+$/,
|
|
425
|
+
ulid: /^[0-9A-HJKMNP-TV-Z]{26}$/,
|
|
426
|
+
/**
|
|
427
|
+
* `a-z` was added to replicate /i flag
|
|
428
|
+
*/
|
|
429
|
+
email: /^(?!\.)(?!.*\.\.)([a-zA-Z0-9_'+\-\.]*)[a-zA-Z0-9_+-]@([a-zA-Z0-9][a-zA-Z0-9\-]*\.)+[a-zA-Z]{2,}$/,
|
|
430
|
+
/**
|
|
431
|
+
* Constructed a valid Unicode RegExp
|
|
432
|
+
*
|
|
433
|
+
* Lazily instantiate since this type of regex isn't supported
|
|
434
|
+
* in all envs (e.g. React Native).
|
|
435
|
+
*
|
|
436
|
+
* See:
|
|
437
|
+
* https://github.com/colinhacks/zod/issues/2433
|
|
438
|
+
* Fix in Zod:
|
|
439
|
+
* https://github.com/colinhacks/zod/commit/9340fd51e48576a75adc919bff65dbc4a5d4c99b
|
|
440
|
+
*/
|
|
441
|
+
emoji: () => {
|
|
442
|
+
if (emojiRegex === void 0) {
|
|
443
|
+
emojiRegex = RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$", "u");
|
|
444
|
+
}
|
|
445
|
+
return emojiRegex;
|
|
446
|
+
},
|
|
447
|
+
/**
|
|
448
|
+
* Unused
|
|
449
|
+
*/
|
|
450
|
+
uuid: /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/,
|
|
451
|
+
/**
|
|
452
|
+
* Unused
|
|
453
|
+
*/
|
|
454
|
+
ipv4: /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,
|
|
455
|
+
ipv4Cidr: /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/,
|
|
456
|
+
/**
|
|
457
|
+
* Unused
|
|
458
|
+
*/
|
|
459
|
+
ipv6: /^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/,
|
|
460
|
+
ipv6Cidr: /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,
|
|
461
|
+
base64: /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,
|
|
462
|
+
base64url: /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,
|
|
463
|
+
nanoid: /^[a-zA-Z0-9_-]{21}$/,
|
|
464
|
+
jwt: /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/
|
|
465
|
+
};
|
|
466
|
+
function parseStringDef(def, refs) {
|
|
467
|
+
const res = {
|
|
468
|
+
type: "string"
|
|
469
|
+
};
|
|
470
|
+
if (def.checks) {
|
|
471
|
+
for (const check of def.checks) {
|
|
472
|
+
switch (check.kind) {
|
|
473
|
+
case "min":
|
|
474
|
+
setResponseValueAndErrors(res, "minLength", typeof res.minLength === "number" ? Math.max(res.minLength, check.value) : check.value, check.message, refs);
|
|
475
|
+
break;
|
|
476
|
+
case "max":
|
|
477
|
+
setResponseValueAndErrors(res, "maxLength", typeof res.maxLength === "number" ? Math.min(res.maxLength, check.value) : check.value, check.message, refs);
|
|
478
|
+
break;
|
|
479
|
+
case "email":
|
|
480
|
+
switch (refs.emailStrategy) {
|
|
481
|
+
case "format:email":
|
|
482
|
+
addFormat(res, "email", check.message, refs);
|
|
483
|
+
break;
|
|
484
|
+
case "format:idn-email":
|
|
485
|
+
addFormat(res, "idn-email", check.message, refs);
|
|
486
|
+
break;
|
|
487
|
+
case "pattern:zod":
|
|
488
|
+
addPattern(res, zodPatterns.email, check.message, refs);
|
|
489
|
+
break;
|
|
490
|
+
}
|
|
491
|
+
break;
|
|
492
|
+
case "url":
|
|
493
|
+
addFormat(res, "uri", check.message, refs);
|
|
494
|
+
break;
|
|
495
|
+
case "uuid":
|
|
496
|
+
addFormat(res, "uuid", check.message, refs);
|
|
497
|
+
break;
|
|
498
|
+
case "regex":
|
|
499
|
+
addPattern(res, check.regex, check.message, refs);
|
|
500
|
+
break;
|
|
501
|
+
case "cuid":
|
|
502
|
+
addPattern(res, zodPatterns.cuid, check.message, refs);
|
|
503
|
+
break;
|
|
504
|
+
case "cuid2":
|
|
505
|
+
addPattern(res, zodPatterns.cuid2, check.message, refs);
|
|
506
|
+
break;
|
|
507
|
+
case "startsWith":
|
|
508
|
+
addPattern(res, RegExp(`^${escapeLiteralCheckValue(check.value, refs)}`), check.message, refs);
|
|
509
|
+
break;
|
|
510
|
+
case "endsWith":
|
|
511
|
+
addPattern(res, RegExp(`${escapeLiteralCheckValue(check.value, refs)}$`), check.message, refs);
|
|
512
|
+
break;
|
|
513
|
+
case "datetime":
|
|
514
|
+
addFormat(res, "date-time", check.message, refs);
|
|
515
|
+
break;
|
|
516
|
+
case "date":
|
|
517
|
+
addFormat(res, "date", check.message, refs);
|
|
518
|
+
break;
|
|
519
|
+
case "time":
|
|
520
|
+
addFormat(res, "time", check.message, refs);
|
|
521
|
+
break;
|
|
522
|
+
case "duration":
|
|
523
|
+
addFormat(res, "duration", check.message, refs);
|
|
524
|
+
break;
|
|
525
|
+
case "length":
|
|
526
|
+
setResponseValueAndErrors(res, "minLength", typeof res.minLength === "number" ? Math.max(res.minLength, check.value) : check.value, check.message, refs);
|
|
527
|
+
setResponseValueAndErrors(res, "maxLength", typeof res.maxLength === "number" ? Math.min(res.maxLength, check.value) : check.value, check.message, refs);
|
|
528
|
+
break;
|
|
529
|
+
case "includes": {
|
|
530
|
+
addPattern(res, RegExp(escapeLiteralCheckValue(check.value, refs)), check.message, refs);
|
|
531
|
+
break;
|
|
532
|
+
}
|
|
533
|
+
case "ip": {
|
|
534
|
+
if (check.version !== "v6") {
|
|
535
|
+
addFormat(res, "ipv4", check.message, refs);
|
|
536
|
+
}
|
|
537
|
+
if (check.version !== "v4") {
|
|
538
|
+
addFormat(res, "ipv6", check.message, refs);
|
|
539
|
+
}
|
|
540
|
+
break;
|
|
541
|
+
}
|
|
542
|
+
case "base64url":
|
|
543
|
+
addPattern(res, zodPatterns.base64url, check.message, refs);
|
|
544
|
+
break;
|
|
545
|
+
case "jwt":
|
|
546
|
+
addPattern(res, zodPatterns.jwt, check.message, refs);
|
|
547
|
+
break;
|
|
548
|
+
case "cidr": {
|
|
549
|
+
if (check.version !== "v6") {
|
|
550
|
+
addPattern(res, zodPatterns.ipv4Cidr, check.message, refs);
|
|
551
|
+
}
|
|
552
|
+
if (check.version !== "v4") {
|
|
553
|
+
addPattern(res, zodPatterns.ipv6Cidr, check.message, refs);
|
|
554
|
+
}
|
|
555
|
+
break;
|
|
556
|
+
}
|
|
557
|
+
case "emoji":
|
|
558
|
+
addPattern(res, zodPatterns.emoji(), check.message, refs);
|
|
559
|
+
break;
|
|
560
|
+
case "ulid": {
|
|
561
|
+
addPattern(res, zodPatterns.ulid, check.message, refs);
|
|
562
|
+
break;
|
|
563
|
+
}
|
|
564
|
+
case "base64": {
|
|
565
|
+
switch (refs.base64Strategy) {
|
|
566
|
+
case "format:binary": {
|
|
567
|
+
addFormat(res, "binary", check.message, refs);
|
|
568
|
+
break;
|
|
569
|
+
}
|
|
570
|
+
case "contentEncoding:base64": {
|
|
571
|
+
setResponseValueAndErrors(res, "contentEncoding", "base64", check.message, refs);
|
|
572
|
+
break;
|
|
573
|
+
}
|
|
574
|
+
case "pattern:zod": {
|
|
575
|
+
addPattern(res, zodPatterns.base64, check.message, refs);
|
|
576
|
+
break;
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
break;
|
|
580
|
+
}
|
|
581
|
+
case "nanoid": {
|
|
582
|
+
addPattern(res, zodPatterns.nanoid, check.message, refs);
|
|
583
|
+
}
|
|
584
|
+
case "toLowerCase":
|
|
585
|
+
case "toUpperCase":
|
|
586
|
+
case "trim":
|
|
587
|
+
break;
|
|
588
|
+
default:
|
|
589
|
+
/* @__PURE__ */ ((_) => {
|
|
590
|
+
})(check);
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
return res;
|
|
595
|
+
}
|
|
596
|
+
function escapeLiteralCheckValue(literal, refs) {
|
|
597
|
+
return refs.patternStrategy === "escape" ? escapeNonAlphaNumeric(literal) : literal;
|
|
598
|
+
}
|
|
599
|
+
var ALPHA_NUMERIC = new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");
|
|
600
|
+
function escapeNonAlphaNumeric(source) {
|
|
601
|
+
let result = "";
|
|
602
|
+
for (let i = 0; i < source.length; i++) {
|
|
603
|
+
if (!ALPHA_NUMERIC.has(source[i])) {
|
|
604
|
+
result += "\\";
|
|
605
|
+
}
|
|
606
|
+
result += source[i];
|
|
607
|
+
}
|
|
608
|
+
return result;
|
|
609
|
+
}
|
|
610
|
+
function addFormat(schema, value, message, refs) {
|
|
611
|
+
if (schema.format || schema.anyOf?.some((x) => x.format)) {
|
|
612
|
+
if (!schema.anyOf) {
|
|
613
|
+
schema.anyOf = [];
|
|
614
|
+
}
|
|
615
|
+
if (schema.format) {
|
|
616
|
+
schema.anyOf.push({
|
|
617
|
+
format: schema.format,
|
|
618
|
+
...schema.errorMessage && refs.errorMessages && {
|
|
619
|
+
errorMessage: { format: schema.errorMessage.format }
|
|
620
|
+
}
|
|
621
|
+
});
|
|
622
|
+
delete schema.format;
|
|
623
|
+
if (schema.errorMessage) {
|
|
624
|
+
delete schema.errorMessage.format;
|
|
625
|
+
if (Object.keys(schema.errorMessage).length === 0) {
|
|
626
|
+
delete schema.errorMessage;
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
schema.anyOf.push({
|
|
631
|
+
format: value,
|
|
632
|
+
...message && refs.errorMessages && { errorMessage: { format: message } }
|
|
633
|
+
});
|
|
634
|
+
} else {
|
|
635
|
+
setResponseValueAndErrors(schema, "format", value, message, refs);
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
function addPattern(schema, regex, message, refs) {
|
|
639
|
+
if (schema.pattern || schema.allOf?.some((x) => x.pattern)) {
|
|
640
|
+
if (!schema.allOf) {
|
|
641
|
+
schema.allOf = [];
|
|
642
|
+
}
|
|
643
|
+
if (schema.pattern) {
|
|
644
|
+
schema.allOf.push({
|
|
645
|
+
pattern: schema.pattern,
|
|
646
|
+
...schema.errorMessage && refs.errorMessages && {
|
|
647
|
+
errorMessage: { pattern: schema.errorMessage.pattern }
|
|
648
|
+
}
|
|
649
|
+
});
|
|
650
|
+
delete schema.pattern;
|
|
651
|
+
if (schema.errorMessage) {
|
|
652
|
+
delete schema.errorMessage.pattern;
|
|
653
|
+
if (Object.keys(schema.errorMessage).length === 0) {
|
|
654
|
+
delete schema.errorMessage;
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
schema.allOf.push({
|
|
659
|
+
pattern: stringifyRegExpWithFlags(regex, refs),
|
|
660
|
+
...message && refs.errorMessages && { errorMessage: { pattern: message } }
|
|
661
|
+
});
|
|
662
|
+
} else {
|
|
663
|
+
setResponseValueAndErrors(schema, "pattern", stringifyRegExpWithFlags(regex, refs), message, refs);
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
function stringifyRegExpWithFlags(regex, refs) {
|
|
667
|
+
if (!refs.applyRegexFlags || !regex.flags) {
|
|
668
|
+
return regex.source;
|
|
669
|
+
}
|
|
670
|
+
const flags = {
|
|
671
|
+
i: regex.flags.includes("i"),
|
|
672
|
+
m: regex.flags.includes("m"),
|
|
673
|
+
s: regex.flags.includes("s")
|
|
674
|
+
// `.` matches newlines
|
|
675
|
+
};
|
|
676
|
+
const source = flags.i ? regex.source.toLowerCase() : regex.source;
|
|
677
|
+
let pattern = "";
|
|
678
|
+
let isEscaped = false;
|
|
679
|
+
let inCharGroup = false;
|
|
680
|
+
let inCharRange = false;
|
|
681
|
+
for (let i = 0; i < source.length; i++) {
|
|
682
|
+
if (isEscaped) {
|
|
683
|
+
pattern += source[i];
|
|
684
|
+
isEscaped = false;
|
|
685
|
+
continue;
|
|
686
|
+
}
|
|
687
|
+
if (flags.i) {
|
|
688
|
+
if (inCharGroup) {
|
|
689
|
+
if (source[i].match(/[a-z]/)) {
|
|
690
|
+
if (inCharRange) {
|
|
691
|
+
pattern += source[i];
|
|
692
|
+
pattern += `${source[i - 2]}-${source[i]}`.toUpperCase();
|
|
693
|
+
inCharRange = false;
|
|
694
|
+
} else if (source[i + 1] === "-" && source[i + 2]?.match(/[a-z]/)) {
|
|
695
|
+
pattern += source[i];
|
|
696
|
+
inCharRange = true;
|
|
697
|
+
} else {
|
|
698
|
+
pattern += `${source[i]}${source[i].toUpperCase()}`;
|
|
699
|
+
}
|
|
700
|
+
continue;
|
|
701
|
+
}
|
|
702
|
+
} else if (source[i].match(/[a-z]/)) {
|
|
703
|
+
pattern += `[${source[i]}${source[i].toUpperCase()}]`;
|
|
704
|
+
continue;
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
if (flags.m) {
|
|
708
|
+
if (source[i] === "^") {
|
|
709
|
+
pattern += `(^|(?<=[\r
|
|
710
|
+
]))`;
|
|
711
|
+
continue;
|
|
712
|
+
} else if (source[i] === "$") {
|
|
713
|
+
pattern += `($|(?=[\r
|
|
714
|
+
]))`;
|
|
715
|
+
continue;
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
if (flags.s && source[i] === ".") {
|
|
719
|
+
pattern += inCharGroup ? `${source[i]}\r
|
|
720
|
+
` : `[${source[i]}\r
|
|
721
|
+
]`;
|
|
722
|
+
continue;
|
|
723
|
+
}
|
|
724
|
+
pattern += source[i];
|
|
725
|
+
if (source[i] === "\\") {
|
|
726
|
+
isEscaped = true;
|
|
727
|
+
} else if (inCharGroup && source[i] === "]") {
|
|
728
|
+
inCharGroup = false;
|
|
729
|
+
} else if (!inCharGroup && source[i] === "[") {
|
|
730
|
+
inCharGroup = true;
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
try {
|
|
734
|
+
new RegExp(pattern);
|
|
735
|
+
} catch {
|
|
736
|
+
console.warn(`Could not convert regex pattern at ${refs.currentPath.join("/")} to a flag-independent form! Falling back to the flag-ignorant source`);
|
|
737
|
+
return regex.source;
|
|
738
|
+
}
|
|
739
|
+
return pattern;
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/record.js
|
|
743
|
+
function parseRecordDef(def, refs) {
|
|
744
|
+
if (refs.target === "openAi") {
|
|
745
|
+
console.warn("Warning: OpenAI may not support records in schemas! Try an array of key-value pairs instead.");
|
|
746
|
+
}
|
|
747
|
+
if (refs.target === "openApi3" && def.keyType?._def.typeName === ZodFirstPartyTypeKind2.ZodEnum) {
|
|
748
|
+
return {
|
|
749
|
+
type: "object",
|
|
750
|
+
required: def.keyType._def.values,
|
|
751
|
+
properties: def.keyType._def.values.reduce((acc, key) => ({
|
|
752
|
+
...acc,
|
|
753
|
+
[key]: parseDef(def.valueType._def, {
|
|
754
|
+
...refs,
|
|
755
|
+
currentPath: [...refs.currentPath, "properties", key]
|
|
756
|
+
}) ?? parseAnyDef(refs)
|
|
757
|
+
}), {}),
|
|
758
|
+
additionalProperties: refs.rejectedAdditionalProperties
|
|
759
|
+
};
|
|
760
|
+
}
|
|
761
|
+
const schema = {
|
|
762
|
+
type: "object",
|
|
763
|
+
additionalProperties: parseDef(def.valueType._def, {
|
|
764
|
+
...refs,
|
|
765
|
+
currentPath: [...refs.currentPath, "additionalProperties"]
|
|
766
|
+
}) ?? refs.allowedAdditionalProperties
|
|
767
|
+
};
|
|
768
|
+
if (refs.target === "openApi3") {
|
|
769
|
+
return schema;
|
|
770
|
+
}
|
|
771
|
+
if (def.keyType?._def.typeName === ZodFirstPartyTypeKind2.ZodString && def.keyType._def.checks?.length) {
|
|
772
|
+
const { type, ...keyType } = parseStringDef(def.keyType._def, refs);
|
|
773
|
+
return {
|
|
774
|
+
...schema,
|
|
775
|
+
propertyNames: keyType
|
|
776
|
+
};
|
|
777
|
+
} else if (def.keyType?._def.typeName === ZodFirstPartyTypeKind2.ZodEnum) {
|
|
778
|
+
return {
|
|
779
|
+
...schema,
|
|
780
|
+
propertyNames: {
|
|
781
|
+
enum: def.keyType._def.values
|
|
782
|
+
}
|
|
783
|
+
};
|
|
784
|
+
} else if (def.keyType?._def.typeName === ZodFirstPartyTypeKind2.ZodBranded && def.keyType._def.type._def.typeName === ZodFirstPartyTypeKind2.ZodString && def.keyType._def.type._def.checks?.length) {
|
|
785
|
+
const { type, ...keyType } = parseBrandedDef(def.keyType._def, refs);
|
|
786
|
+
return {
|
|
787
|
+
...schema,
|
|
788
|
+
propertyNames: keyType
|
|
789
|
+
};
|
|
790
|
+
}
|
|
791
|
+
return schema;
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/map.js
|
|
795
|
+
function parseMapDef(def, refs) {
|
|
796
|
+
if (refs.mapStrategy === "record") {
|
|
797
|
+
return parseRecordDef(def, refs);
|
|
798
|
+
}
|
|
799
|
+
const keys = parseDef(def.keyType._def, {
|
|
800
|
+
...refs,
|
|
801
|
+
currentPath: [...refs.currentPath, "items", "items", "0"]
|
|
802
|
+
}) || parseAnyDef(refs);
|
|
803
|
+
const values = parseDef(def.valueType._def, {
|
|
804
|
+
...refs,
|
|
805
|
+
currentPath: [...refs.currentPath, "items", "items", "1"]
|
|
806
|
+
}) || parseAnyDef(refs);
|
|
807
|
+
return {
|
|
808
|
+
type: "array",
|
|
809
|
+
maxItems: 125,
|
|
810
|
+
items: {
|
|
811
|
+
type: "array",
|
|
812
|
+
items: [keys, values],
|
|
813
|
+
minItems: 2,
|
|
814
|
+
maxItems: 2
|
|
815
|
+
}
|
|
816
|
+
};
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/nativeEnum.js
|
|
820
|
+
function parseNativeEnumDef(def) {
|
|
821
|
+
const object = def.values;
|
|
822
|
+
const actualKeys = Object.keys(def.values).filter((key) => {
|
|
823
|
+
return typeof object[object[key]] !== "number";
|
|
824
|
+
});
|
|
825
|
+
const actualValues = actualKeys.map((key) => object[key]);
|
|
826
|
+
const parsedTypes = Array.from(new Set(actualValues.map((values) => typeof values)));
|
|
827
|
+
return {
|
|
828
|
+
type: parsedTypes.length === 1 ? parsedTypes[0] === "string" ? "string" : "number" : ["string", "number"],
|
|
829
|
+
enum: actualValues
|
|
830
|
+
};
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/never.js
|
|
834
|
+
function parseNeverDef(refs) {
|
|
835
|
+
return refs.target === "openAi" ? void 0 : {
|
|
836
|
+
not: parseAnyDef({
|
|
837
|
+
...refs,
|
|
838
|
+
currentPath: [...refs.currentPath, "not"]
|
|
839
|
+
})
|
|
840
|
+
};
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/null.js
|
|
844
|
+
function parseNullDef(refs) {
|
|
845
|
+
return refs.target === "openApi3" ? {
|
|
846
|
+
enum: ["null"],
|
|
847
|
+
nullable: true
|
|
848
|
+
} : {
|
|
849
|
+
type: "null"
|
|
850
|
+
};
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/union.js
|
|
854
|
+
var primitiveMappings = {
|
|
855
|
+
ZodString: "string",
|
|
856
|
+
ZodNumber: "number",
|
|
857
|
+
ZodBigInt: "integer",
|
|
858
|
+
ZodBoolean: "boolean",
|
|
859
|
+
ZodNull: "null"
|
|
860
|
+
};
|
|
861
|
+
function parseUnionDef(def, refs) {
|
|
862
|
+
if (refs.target === "openApi3")
|
|
863
|
+
return asAnyOf(def, refs);
|
|
864
|
+
const options = def.options instanceof Map ? Array.from(def.options.values()) : def.options;
|
|
865
|
+
if (options.every((x) => x._def.typeName in primitiveMappings && (!x._def.checks || !x._def.checks.length))) {
|
|
866
|
+
const types = options.reduce((types2, x) => {
|
|
867
|
+
const type = primitiveMappings[x._def.typeName];
|
|
868
|
+
return type && !types2.includes(type) ? [...types2, type] : types2;
|
|
869
|
+
}, []);
|
|
870
|
+
return {
|
|
871
|
+
type: types.length > 1 ? types : types[0]
|
|
872
|
+
};
|
|
873
|
+
} else if (options.every((x) => x._def.typeName === "ZodLiteral" && !x.description)) {
|
|
874
|
+
const types = options.reduce((acc, x) => {
|
|
875
|
+
const type = typeof x._def.value;
|
|
876
|
+
switch (type) {
|
|
877
|
+
case "string":
|
|
878
|
+
case "number":
|
|
879
|
+
case "boolean":
|
|
880
|
+
return [...acc, type];
|
|
881
|
+
case "bigint":
|
|
882
|
+
return [...acc, "integer"];
|
|
883
|
+
case "object":
|
|
884
|
+
if (x._def.value === null)
|
|
885
|
+
return [...acc, "null"];
|
|
886
|
+
case "symbol":
|
|
887
|
+
case "undefined":
|
|
888
|
+
case "function":
|
|
889
|
+
default:
|
|
890
|
+
return acc;
|
|
891
|
+
}
|
|
892
|
+
}, []);
|
|
893
|
+
if (types.length === options.length) {
|
|
894
|
+
const uniqueTypes = types.filter((x, i, a) => a.indexOf(x) === i);
|
|
895
|
+
return {
|
|
896
|
+
type: uniqueTypes.length > 1 ? uniqueTypes : uniqueTypes[0],
|
|
897
|
+
enum: options.reduce((acc, x) => {
|
|
898
|
+
return acc.includes(x._def.value) ? acc : [...acc, x._def.value];
|
|
899
|
+
}, [])
|
|
900
|
+
};
|
|
901
|
+
}
|
|
902
|
+
} else if (options.every((x) => x._def.typeName === "ZodEnum")) {
|
|
903
|
+
return {
|
|
904
|
+
type: "string",
|
|
905
|
+
enum: options.reduce((acc, x) => [
|
|
906
|
+
...acc,
|
|
907
|
+
...x._def.values.filter((x2) => !acc.includes(x2))
|
|
908
|
+
], [])
|
|
909
|
+
};
|
|
910
|
+
}
|
|
911
|
+
return asAnyOf(def, refs);
|
|
912
|
+
}
|
|
913
|
+
var asAnyOf = (def, refs) => {
|
|
914
|
+
const anyOf = (def.options instanceof Map ? Array.from(def.options.values()) : def.options).map((x, i) => parseDef(x._def, {
|
|
915
|
+
...refs,
|
|
916
|
+
currentPath: [...refs.currentPath, "anyOf", `${i}`]
|
|
917
|
+
})).filter((x) => !!x && (!refs.strictUnions || typeof x === "object" && Object.keys(x).length > 0));
|
|
918
|
+
return anyOf.length ? { anyOf } : void 0;
|
|
919
|
+
};
|
|
920
|
+
|
|
921
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/nullable.js
|
|
922
|
+
function parseNullableDef(def, refs) {
|
|
923
|
+
if (["ZodString", "ZodNumber", "ZodBigInt", "ZodBoolean", "ZodNull"].includes(def.innerType._def.typeName) && (!def.innerType._def.checks || !def.innerType._def.checks.length)) {
|
|
924
|
+
if (refs.target === "openApi3") {
|
|
925
|
+
return {
|
|
926
|
+
type: primitiveMappings[def.innerType._def.typeName],
|
|
927
|
+
nullable: true
|
|
928
|
+
};
|
|
929
|
+
}
|
|
930
|
+
return {
|
|
931
|
+
type: [
|
|
932
|
+
primitiveMappings[def.innerType._def.typeName],
|
|
933
|
+
"null"
|
|
934
|
+
]
|
|
935
|
+
};
|
|
936
|
+
}
|
|
937
|
+
if (refs.target === "openApi3") {
|
|
938
|
+
const base2 = parseDef(def.innerType._def, {
|
|
939
|
+
...refs,
|
|
940
|
+
currentPath: [...refs.currentPath]
|
|
941
|
+
});
|
|
942
|
+
if (base2 && "$ref" in base2)
|
|
943
|
+
return { allOf: [base2], nullable: true };
|
|
944
|
+
return base2 && { ...base2, nullable: true };
|
|
945
|
+
}
|
|
946
|
+
const base = parseDef(def.innerType._def, {
|
|
947
|
+
...refs,
|
|
948
|
+
currentPath: [...refs.currentPath, "anyOf", "0"]
|
|
949
|
+
});
|
|
950
|
+
return base && { anyOf: [base, { type: "null" }] };
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/number.js
|
|
954
|
+
function parseNumberDef(def, refs) {
|
|
955
|
+
const res = {
|
|
956
|
+
type: "number"
|
|
957
|
+
};
|
|
958
|
+
if (!def.checks)
|
|
959
|
+
return res;
|
|
960
|
+
for (const check of def.checks) {
|
|
961
|
+
switch (check.kind) {
|
|
962
|
+
case "int":
|
|
963
|
+
res.type = "integer";
|
|
964
|
+
addErrorMessage(res, "type", check.message, refs);
|
|
965
|
+
break;
|
|
966
|
+
case "min":
|
|
967
|
+
if (refs.target === "jsonSchema7") {
|
|
968
|
+
if (check.inclusive) {
|
|
969
|
+
setResponseValueAndErrors(res, "minimum", check.value, check.message, refs);
|
|
970
|
+
} else {
|
|
971
|
+
setResponseValueAndErrors(res, "exclusiveMinimum", check.value, check.message, refs);
|
|
972
|
+
}
|
|
973
|
+
} else {
|
|
974
|
+
if (!check.inclusive) {
|
|
975
|
+
res.exclusiveMinimum = true;
|
|
976
|
+
}
|
|
977
|
+
setResponseValueAndErrors(res, "minimum", check.value, check.message, refs);
|
|
978
|
+
}
|
|
979
|
+
break;
|
|
980
|
+
case "max":
|
|
981
|
+
if (refs.target === "jsonSchema7") {
|
|
982
|
+
if (check.inclusive) {
|
|
983
|
+
setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
|
|
984
|
+
} else {
|
|
985
|
+
setResponseValueAndErrors(res, "exclusiveMaximum", check.value, check.message, refs);
|
|
986
|
+
}
|
|
987
|
+
} else {
|
|
988
|
+
if (!check.inclusive) {
|
|
989
|
+
res.exclusiveMaximum = true;
|
|
990
|
+
}
|
|
991
|
+
setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
|
|
992
|
+
}
|
|
993
|
+
break;
|
|
994
|
+
case "multipleOf":
|
|
995
|
+
setResponseValueAndErrors(res, "multipleOf", check.value, check.message, refs);
|
|
996
|
+
break;
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
return res;
|
|
1000
|
+
}
|
|
1001
|
+
|
|
1002
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/object.js
|
|
1003
|
+
function parseObjectDef(def, refs) {
|
|
1004
|
+
const forceOptionalIntoNullable = refs.target === "openAi";
|
|
1005
|
+
const result = {
|
|
1006
|
+
type: "object",
|
|
1007
|
+
properties: {}
|
|
1008
|
+
};
|
|
1009
|
+
const required = [];
|
|
1010
|
+
const shape = def.shape();
|
|
1011
|
+
for (const propName in shape) {
|
|
1012
|
+
let propDef = shape[propName];
|
|
1013
|
+
if (propDef === void 0 || propDef._def === void 0) {
|
|
1014
|
+
continue;
|
|
1015
|
+
}
|
|
1016
|
+
let propOptional = safeIsOptional(propDef);
|
|
1017
|
+
if (propOptional && forceOptionalIntoNullable) {
|
|
1018
|
+
if (propDef._def.typeName === "ZodOptional") {
|
|
1019
|
+
propDef = propDef._def.innerType;
|
|
1020
|
+
}
|
|
1021
|
+
if (!propDef.isNullable()) {
|
|
1022
|
+
propDef = propDef.nullable();
|
|
1023
|
+
}
|
|
1024
|
+
propOptional = false;
|
|
1025
|
+
}
|
|
1026
|
+
const parsedDef = parseDef(propDef._def, {
|
|
1027
|
+
...refs,
|
|
1028
|
+
currentPath: [...refs.currentPath, "properties", propName],
|
|
1029
|
+
propertyPath: [...refs.currentPath, "properties", propName]
|
|
1030
|
+
});
|
|
1031
|
+
if (parsedDef === void 0) {
|
|
1032
|
+
continue;
|
|
1033
|
+
}
|
|
1034
|
+
result.properties[propName] = parsedDef;
|
|
1035
|
+
if (!propOptional) {
|
|
1036
|
+
required.push(propName);
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
if (required.length) {
|
|
1040
|
+
result.required = required;
|
|
1041
|
+
}
|
|
1042
|
+
const additionalProperties = decideAdditionalProperties(def, refs);
|
|
1043
|
+
if (additionalProperties !== void 0) {
|
|
1044
|
+
result.additionalProperties = additionalProperties;
|
|
1045
|
+
}
|
|
1046
|
+
return result;
|
|
1047
|
+
}
|
|
1048
|
+
function decideAdditionalProperties(def, refs) {
|
|
1049
|
+
if (def.catchall._def.typeName !== "ZodNever") {
|
|
1050
|
+
return parseDef(def.catchall._def, {
|
|
1051
|
+
...refs,
|
|
1052
|
+
currentPath: [...refs.currentPath, "additionalProperties"]
|
|
1053
|
+
});
|
|
1054
|
+
}
|
|
1055
|
+
switch (def.unknownKeys) {
|
|
1056
|
+
case "passthrough":
|
|
1057
|
+
return refs.allowedAdditionalProperties;
|
|
1058
|
+
case "strict":
|
|
1059
|
+
return refs.rejectedAdditionalProperties;
|
|
1060
|
+
case "strip":
|
|
1061
|
+
return refs.removeAdditionalStrategy === "strict" ? refs.allowedAdditionalProperties : refs.rejectedAdditionalProperties;
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
function safeIsOptional(schema) {
|
|
1065
|
+
try {
|
|
1066
|
+
return schema.isOptional();
|
|
1067
|
+
} catch {
|
|
1068
|
+
return true;
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
|
|
1072
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/optional.js
|
|
1073
|
+
var parseOptionalDef = (def, refs) => {
|
|
1074
|
+
if (refs.currentPath.toString() === refs.propertyPath?.toString()) {
|
|
1075
|
+
return parseDef(def.innerType._def, refs);
|
|
1076
|
+
}
|
|
1077
|
+
const innerSchema = parseDef(def.innerType._def, {
|
|
1078
|
+
...refs,
|
|
1079
|
+
currentPath: [...refs.currentPath, "anyOf", "1"]
|
|
1080
|
+
});
|
|
1081
|
+
return innerSchema ? {
|
|
1082
|
+
anyOf: [
|
|
1083
|
+
{
|
|
1084
|
+
not: parseAnyDef(refs)
|
|
1085
|
+
},
|
|
1086
|
+
innerSchema
|
|
1087
|
+
]
|
|
1088
|
+
} : parseAnyDef(refs);
|
|
1089
|
+
};
|
|
1090
|
+
|
|
1091
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/pipeline.js
|
|
1092
|
+
var parsePipelineDef = (def, refs) => {
|
|
1093
|
+
if (refs.pipeStrategy === "input") {
|
|
1094
|
+
return parseDef(def.in._def, refs);
|
|
1095
|
+
} else if (refs.pipeStrategy === "output") {
|
|
1096
|
+
return parseDef(def.out._def, refs);
|
|
1097
|
+
}
|
|
1098
|
+
const a = parseDef(def.in._def, {
|
|
1099
|
+
...refs,
|
|
1100
|
+
currentPath: [...refs.currentPath, "allOf", "0"]
|
|
1101
|
+
});
|
|
1102
|
+
const b = parseDef(def.out._def, {
|
|
1103
|
+
...refs,
|
|
1104
|
+
currentPath: [...refs.currentPath, "allOf", a ? "1" : "0"]
|
|
1105
|
+
});
|
|
1106
|
+
return {
|
|
1107
|
+
allOf: [a, b].filter((x) => x !== void 0)
|
|
1108
|
+
};
|
|
1109
|
+
};
|
|
1110
|
+
|
|
1111
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/promise.js
|
|
1112
|
+
function parsePromiseDef(def, refs) {
|
|
1113
|
+
return parseDef(def.type._def, refs);
|
|
1114
|
+
}
|
|
1115
|
+
|
|
1116
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/set.js
|
|
1117
|
+
function parseSetDef(def, refs) {
|
|
1118
|
+
const items = parseDef(def.valueType._def, {
|
|
1119
|
+
...refs,
|
|
1120
|
+
currentPath: [...refs.currentPath, "items"]
|
|
1121
|
+
});
|
|
1122
|
+
const schema = {
|
|
1123
|
+
type: "array",
|
|
1124
|
+
uniqueItems: true,
|
|
1125
|
+
items
|
|
1126
|
+
};
|
|
1127
|
+
if (def.minSize) {
|
|
1128
|
+
setResponseValueAndErrors(schema, "minItems", def.minSize.value, def.minSize.message, refs);
|
|
1129
|
+
}
|
|
1130
|
+
if (def.maxSize) {
|
|
1131
|
+
setResponseValueAndErrors(schema, "maxItems", def.maxSize.value, def.maxSize.message, refs);
|
|
1132
|
+
}
|
|
1133
|
+
return schema;
|
|
1134
|
+
}
|
|
1135
|
+
|
|
1136
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/tuple.js
|
|
1137
|
+
function parseTupleDef(def, refs) {
|
|
1138
|
+
if (def.rest) {
|
|
1139
|
+
return {
|
|
1140
|
+
type: "array",
|
|
1141
|
+
minItems: def.items.length,
|
|
1142
|
+
items: def.items.map((x, i) => parseDef(x._def, {
|
|
1143
|
+
...refs,
|
|
1144
|
+
currentPath: [...refs.currentPath, "items", `${i}`]
|
|
1145
|
+
})).reduce((acc, x) => x === void 0 ? acc : [...acc, x], []),
|
|
1146
|
+
additionalItems: parseDef(def.rest._def, {
|
|
1147
|
+
...refs,
|
|
1148
|
+
currentPath: [...refs.currentPath, "additionalItems"]
|
|
1149
|
+
})
|
|
1150
|
+
};
|
|
1151
|
+
} else {
|
|
1152
|
+
return {
|
|
1153
|
+
type: "array",
|
|
1154
|
+
minItems: def.items.length,
|
|
1155
|
+
maxItems: def.items.length,
|
|
1156
|
+
items: def.items.map((x, i) => parseDef(x._def, {
|
|
1157
|
+
...refs,
|
|
1158
|
+
currentPath: [...refs.currentPath, "items", `${i}`]
|
|
1159
|
+
})).reduce((acc, x) => x === void 0 ? acc : [...acc, x], [])
|
|
1160
|
+
};
|
|
1161
|
+
}
|
|
1162
|
+
}
|
|
1163
|
+
|
|
1164
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/undefined.js
|
|
1165
|
+
function parseUndefinedDef(refs) {
|
|
1166
|
+
return {
|
|
1167
|
+
not: parseAnyDef(refs)
|
|
1168
|
+
};
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1171
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/unknown.js
|
|
1172
|
+
function parseUnknownDef(refs) {
|
|
1173
|
+
return parseAnyDef(refs);
|
|
1174
|
+
}
|
|
1175
|
+
|
|
1176
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/readonly.js
|
|
1177
|
+
var parseReadonlyDef = (def, refs) => {
|
|
1178
|
+
return parseDef(def.innerType._def, refs);
|
|
1179
|
+
};
|
|
1180
|
+
|
|
1181
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/selectParser.js
|
|
1182
|
+
var selectParser = (def, typeName, refs) => {
|
|
1183
|
+
switch (typeName) {
|
|
1184
|
+
case ZodFirstPartyTypeKind3.ZodString:
|
|
1185
|
+
return parseStringDef(def, refs);
|
|
1186
|
+
case ZodFirstPartyTypeKind3.ZodNumber:
|
|
1187
|
+
return parseNumberDef(def, refs);
|
|
1188
|
+
case ZodFirstPartyTypeKind3.ZodObject:
|
|
1189
|
+
return parseObjectDef(def, refs);
|
|
1190
|
+
case ZodFirstPartyTypeKind3.ZodBigInt:
|
|
1191
|
+
return parseBigintDef(def, refs);
|
|
1192
|
+
case ZodFirstPartyTypeKind3.ZodBoolean:
|
|
1193
|
+
return parseBooleanDef();
|
|
1194
|
+
case ZodFirstPartyTypeKind3.ZodDate:
|
|
1195
|
+
return parseDateDef(def, refs);
|
|
1196
|
+
case ZodFirstPartyTypeKind3.ZodUndefined:
|
|
1197
|
+
return parseUndefinedDef(refs);
|
|
1198
|
+
case ZodFirstPartyTypeKind3.ZodNull:
|
|
1199
|
+
return parseNullDef(refs);
|
|
1200
|
+
case ZodFirstPartyTypeKind3.ZodArray:
|
|
1201
|
+
return parseArrayDef(def, refs);
|
|
1202
|
+
case ZodFirstPartyTypeKind3.ZodUnion:
|
|
1203
|
+
case ZodFirstPartyTypeKind3.ZodDiscriminatedUnion:
|
|
1204
|
+
return parseUnionDef(def, refs);
|
|
1205
|
+
case ZodFirstPartyTypeKind3.ZodIntersection:
|
|
1206
|
+
return parseIntersectionDef(def, refs);
|
|
1207
|
+
case ZodFirstPartyTypeKind3.ZodTuple:
|
|
1208
|
+
return parseTupleDef(def, refs);
|
|
1209
|
+
case ZodFirstPartyTypeKind3.ZodRecord:
|
|
1210
|
+
return parseRecordDef(def, refs);
|
|
1211
|
+
case ZodFirstPartyTypeKind3.ZodLiteral:
|
|
1212
|
+
return parseLiteralDef(def, refs);
|
|
1213
|
+
case ZodFirstPartyTypeKind3.ZodEnum:
|
|
1214
|
+
return parseEnumDef(def);
|
|
1215
|
+
case ZodFirstPartyTypeKind3.ZodNativeEnum:
|
|
1216
|
+
return parseNativeEnumDef(def);
|
|
1217
|
+
case ZodFirstPartyTypeKind3.ZodNullable:
|
|
1218
|
+
return parseNullableDef(def, refs);
|
|
1219
|
+
case ZodFirstPartyTypeKind3.ZodOptional:
|
|
1220
|
+
return parseOptionalDef(def, refs);
|
|
1221
|
+
case ZodFirstPartyTypeKind3.ZodMap:
|
|
1222
|
+
return parseMapDef(def, refs);
|
|
1223
|
+
case ZodFirstPartyTypeKind3.ZodSet:
|
|
1224
|
+
return parseSetDef(def, refs);
|
|
1225
|
+
case ZodFirstPartyTypeKind3.ZodLazy:
|
|
1226
|
+
return () => def.getter()._def;
|
|
1227
|
+
case ZodFirstPartyTypeKind3.ZodPromise:
|
|
1228
|
+
return parsePromiseDef(def, refs);
|
|
1229
|
+
case ZodFirstPartyTypeKind3.ZodNaN:
|
|
1230
|
+
case ZodFirstPartyTypeKind3.ZodNever:
|
|
1231
|
+
return parseNeverDef(refs);
|
|
1232
|
+
case ZodFirstPartyTypeKind3.ZodEffects:
|
|
1233
|
+
return parseEffectsDef(def, refs);
|
|
1234
|
+
case ZodFirstPartyTypeKind3.ZodAny:
|
|
1235
|
+
return parseAnyDef(refs);
|
|
1236
|
+
case ZodFirstPartyTypeKind3.ZodUnknown:
|
|
1237
|
+
return parseUnknownDef(refs);
|
|
1238
|
+
case ZodFirstPartyTypeKind3.ZodDefault:
|
|
1239
|
+
return parseDefaultDef(def, refs);
|
|
1240
|
+
case ZodFirstPartyTypeKind3.ZodBranded:
|
|
1241
|
+
return parseBrandedDef(def, refs);
|
|
1242
|
+
case ZodFirstPartyTypeKind3.ZodReadonly:
|
|
1243
|
+
return parseReadonlyDef(def, refs);
|
|
1244
|
+
case ZodFirstPartyTypeKind3.ZodCatch:
|
|
1245
|
+
return parseCatchDef(def, refs);
|
|
1246
|
+
case ZodFirstPartyTypeKind3.ZodPipeline:
|
|
1247
|
+
return parsePipelineDef(def, refs);
|
|
1248
|
+
case ZodFirstPartyTypeKind3.ZodFunction:
|
|
1249
|
+
case ZodFirstPartyTypeKind3.ZodVoid:
|
|
1250
|
+
case ZodFirstPartyTypeKind3.ZodSymbol:
|
|
1251
|
+
return void 0;
|
|
1252
|
+
default:
|
|
1253
|
+
return /* @__PURE__ */ ((_) => void 0)(typeName);
|
|
1254
|
+
}
|
|
1255
|
+
};
|
|
1256
|
+
|
|
1257
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parseDef.js
|
|
1258
|
+
function parseDef(def, refs, forceResolution = false) {
|
|
1259
|
+
const seenItem = refs.seen.get(def);
|
|
1260
|
+
if (refs.override) {
|
|
1261
|
+
const overrideResult = refs.override?.(def, refs, seenItem, forceResolution);
|
|
1262
|
+
if (overrideResult !== ignoreOverride) {
|
|
1263
|
+
return overrideResult;
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1266
|
+
if (seenItem && !forceResolution) {
|
|
1267
|
+
const seenSchema = get$ref(seenItem, refs);
|
|
1268
|
+
if (seenSchema !== void 0) {
|
|
1269
|
+
return seenSchema;
|
|
1270
|
+
}
|
|
1271
|
+
}
|
|
1272
|
+
const newItem = { def, path: refs.currentPath, jsonSchema: void 0 };
|
|
1273
|
+
refs.seen.set(def, newItem);
|
|
1274
|
+
const jsonSchemaOrGetter = selectParser(def, def.typeName, refs);
|
|
1275
|
+
const jsonSchema = typeof jsonSchemaOrGetter === "function" ? parseDef(jsonSchemaOrGetter(), refs) : jsonSchemaOrGetter;
|
|
1276
|
+
if (jsonSchema) {
|
|
1277
|
+
addMeta(def, refs, jsonSchema);
|
|
1278
|
+
}
|
|
1279
|
+
if (refs.postProcess) {
|
|
1280
|
+
const postProcessResult = refs.postProcess(jsonSchema, def, refs);
|
|
1281
|
+
newItem.jsonSchema = jsonSchema;
|
|
1282
|
+
return postProcessResult;
|
|
1283
|
+
}
|
|
1284
|
+
newItem.jsonSchema = jsonSchema;
|
|
1285
|
+
return jsonSchema;
|
|
1286
|
+
}
|
|
1287
|
+
var get$ref = (item, refs) => {
|
|
1288
|
+
switch (refs.$refStrategy) {
|
|
1289
|
+
case "root":
|
|
1290
|
+
return { $ref: item.path.join("/") };
|
|
1291
|
+
case "relative":
|
|
1292
|
+
return { $ref: getRelativePath(refs.currentPath, item.path) };
|
|
1293
|
+
case "none":
|
|
1294
|
+
case "seen": {
|
|
1295
|
+
if (item.path.length < refs.currentPath.length && item.path.every((value, index) => refs.currentPath[index] === value)) {
|
|
1296
|
+
console.warn(`Recursive reference detected at ${refs.currentPath.join("/")}! Defaulting to any`);
|
|
1297
|
+
return parseAnyDef(refs);
|
|
1298
|
+
}
|
|
1299
|
+
return refs.$refStrategy === "seen" ? parseAnyDef(refs) : void 0;
|
|
1300
|
+
}
|
|
1301
|
+
}
|
|
1302
|
+
};
|
|
1303
|
+
var addMeta = (def, refs, jsonSchema) => {
|
|
1304
|
+
if (def.description) {
|
|
1305
|
+
jsonSchema.description = def.description;
|
|
1306
|
+
if (refs.markdownDescription) {
|
|
1307
|
+
jsonSchema.markdownDescription = def.description;
|
|
1308
|
+
}
|
|
1309
|
+
}
|
|
1310
|
+
return jsonSchema;
|
|
1311
|
+
};
|
|
1312
|
+
|
|
1313
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.25.2_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/zodToJsonSchema.js
|
|
1314
|
+
var zodToJsonSchema = (schema, options) => {
|
|
1315
|
+
const refs = getRefs(options);
|
|
1316
|
+
let definitions = typeof options === "object" && options.definitions ? Object.entries(options.definitions).reduce((acc, [name2, schema2]) => ({
|
|
1317
|
+
...acc,
|
|
1318
|
+
[name2]: parseDef(schema2._def, {
|
|
1319
|
+
...refs,
|
|
1320
|
+
currentPath: [...refs.basePath, refs.definitionPath, name2]
|
|
1321
|
+
}, true) ?? parseAnyDef(refs)
|
|
1322
|
+
}), {}) : void 0;
|
|
1323
|
+
const name = typeof options === "string" ? options : options?.nameStrategy === "title" ? void 0 : options?.name;
|
|
1324
|
+
const main = parseDef(schema._def, name === void 0 ? refs : {
|
|
1325
|
+
...refs,
|
|
1326
|
+
currentPath: [...refs.basePath, refs.definitionPath, name]
|
|
1327
|
+
}, false) ?? parseAnyDef(refs);
|
|
1328
|
+
const title = typeof options === "object" && options.name !== void 0 && options.nameStrategy === "title" ? options.name : void 0;
|
|
1329
|
+
if (title !== void 0) {
|
|
1330
|
+
main.title = title;
|
|
1331
|
+
}
|
|
1332
|
+
if (refs.flags.hasReferencedOpenAiAnyType) {
|
|
1333
|
+
if (!definitions) {
|
|
1334
|
+
definitions = {};
|
|
1335
|
+
}
|
|
1336
|
+
if (!definitions[refs.openAiAnyTypeName]) {
|
|
1337
|
+
definitions[refs.openAiAnyTypeName] = {
|
|
1338
|
+
// Skipping "object" as no properties can be defined and additionalProperties must be "false"
|
|
1339
|
+
type: ["string", "number", "integer", "boolean", "array", "null"],
|
|
1340
|
+
items: {
|
|
1341
|
+
$ref: refs.$refStrategy === "relative" ? "1" : [
|
|
1342
|
+
...refs.basePath,
|
|
1343
|
+
refs.definitionPath,
|
|
1344
|
+
refs.openAiAnyTypeName
|
|
1345
|
+
].join("/")
|
|
1346
|
+
}
|
|
1347
|
+
};
|
|
1348
|
+
}
|
|
1349
|
+
}
|
|
1350
|
+
const combined = name === void 0 ? definitions ? {
|
|
1351
|
+
...main,
|
|
1352
|
+
[refs.definitionPath]: definitions
|
|
1353
|
+
} : main : {
|
|
1354
|
+
$ref: [
|
|
1355
|
+
...refs.$refStrategy === "relative" ? [] : refs.basePath,
|
|
1356
|
+
refs.definitionPath,
|
|
1357
|
+
name
|
|
1358
|
+
].join("/"),
|
|
1359
|
+
[refs.definitionPath]: {
|
|
1360
|
+
...definitions,
|
|
1361
|
+
[name]: main
|
|
1362
|
+
}
|
|
1363
|
+
};
|
|
1364
|
+
if (refs.target === "jsonSchema7") {
|
|
1365
|
+
combined.$schema = "http://json-schema.org/draft-07/schema#";
|
|
1366
|
+
} else if (refs.target === "jsonSchema2019-09" || refs.target === "openAi") {
|
|
1367
|
+
combined.$schema = "https://json-schema.org/draft/2019-09/schema#";
|
|
1368
|
+
}
|
|
1369
|
+
if (refs.target === "openAi" && ("anyOf" in combined || "oneOf" in combined || "allOf" in combined || "type" in combined && Array.isArray(combined.type))) {
|
|
1370
|
+
console.warn("Warning: OpenAI may not support schemas with unions as roots! Try wrapping it in an object property.");
|
|
1371
|
+
}
|
|
1372
|
+
return combined;
|
|
1373
|
+
};
|
|
1374
|
+
|
|
1375
|
+
// src/action-schemas.ts
|
|
1376
|
+
function toJsonSchema(schema) {
|
|
1377
|
+
return zodToJsonSchema(schema, { target: "jsonSchema7", $refStrategy: "none" });
|
|
1378
|
+
}
|
|
1379
|
+
function inputSchemaFor(decl) {
|
|
1380
|
+
return decl.method === "GET" ? decl.input?.query : decl.input?.body;
|
|
1381
|
+
}
|
|
1382
|
+
function deriveActionSchemas(definition) {
|
|
1383
|
+
const out = {};
|
|
1384
|
+
const actions = definition.manifest.actions ?? [];
|
|
1385
|
+
const routes = definition.manifest.routes ?? [];
|
|
1386
|
+
for (const action of actions) {
|
|
1387
|
+
const ref = parseActionRoute(action.route);
|
|
1388
|
+
if (!ref) continue;
|
|
1389
|
+
const decl = routes.find((r) => r.method === ref.method && r.path === ref.path);
|
|
1390
|
+
if (!decl) continue;
|
|
1391
|
+
const doc = {};
|
|
1392
|
+
const input = inputSchemaFor(decl);
|
|
1393
|
+
if (input) doc.input = toJsonSchema(input);
|
|
1394
|
+
if (decl.output) doc.output = toJsonSchema(decl.output);
|
|
1395
|
+
out[action.key] = doc;
|
|
1396
|
+
}
|
|
1397
|
+
return out;
|
|
1398
|
+
}
|
|
1399
|
+
|
|
1400
|
+
// src/actions-validation.ts
|
|
1401
|
+
var QUERY_METHOD = "GET";
|
|
1402
|
+
var MUTATION_METHODS = /* @__PURE__ */ new Set(["POST", "PUT", "DELETE"]);
|
|
1403
|
+
var RESERVED_KEYS = /* @__PURE__ */ new Set([
|
|
1404
|
+
"break",
|
|
1405
|
+
"case",
|
|
1406
|
+
"catch",
|
|
1407
|
+
"class",
|
|
1408
|
+
"const",
|
|
1409
|
+
"continue",
|
|
1410
|
+
"debugger",
|
|
1411
|
+
"default",
|
|
1412
|
+
"delete",
|
|
1413
|
+
"do",
|
|
1414
|
+
"else",
|
|
1415
|
+
"enum",
|
|
1416
|
+
"export",
|
|
1417
|
+
"extends",
|
|
1418
|
+
"false",
|
|
1419
|
+
"finally",
|
|
1420
|
+
"for",
|
|
1421
|
+
"function",
|
|
1422
|
+
"if",
|
|
1423
|
+
"import",
|
|
1424
|
+
"in",
|
|
1425
|
+
"instanceof",
|
|
1426
|
+
"new",
|
|
1427
|
+
"null",
|
|
1428
|
+
"return",
|
|
1429
|
+
"super",
|
|
1430
|
+
"switch",
|
|
1431
|
+
"this",
|
|
1432
|
+
"throw",
|
|
1433
|
+
"true",
|
|
1434
|
+
"try",
|
|
1435
|
+
"typeof",
|
|
1436
|
+
"var",
|
|
1437
|
+
"void",
|
|
1438
|
+
"while",
|
|
1439
|
+
"with",
|
|
1440
|
+
"yield",
|
|
1441
|
+
"let",
|
|
1442
|
+
"static",
|
|
1443
|
+
"await",
|
|
1444
|
+
"async",
|
|
1445
|
+
"implements",
|
|
1446
|
+
"interface",
|
|
1447
|
+
"package",
|
|
1448
|
+
"private",
|
|
1449
|
+
"protected",
|
|
1450
|
+
"public"
|
|
1451
|
+
]);
|
|
1452
|
+
function isPlainObject(value) {
|
|
1453
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1454
|
+
}
|
|
1455
|
+
function isFlatQueryProperty(schema) {
|
|
1456
|
+
if (schema === true || schema === void 0) return false;
|
|
1457
|
+
if (!isPlainObject(schema)) return false;
|
|
1458
|
+
if (Array.isArray(schema.enum) || "const" in schema) return true;
|
|
1459
|
+
const composite = schema.anyOf ?? schema.oneOf;
|
|
1460
|
+
if (Array.isArray(composite)) return composite.every(isFlatQueryProperty);
|
|
1461
|
+
const type = schema.type;
|
|
1462
|
+
if (Array.isArray(type)) {
|
|
1463
|
+
return type.every((t) => isFlatQueryProperty({ ...schema, type: t }));
|
|
1464
|
+
}
|
|
1465
|
+
if (type === "string" || type === "number" || type === "integer" || type === "boolean" || type === "null") {
|
|
1466
|
+
return true;
|
|
1467
|
+
}
|
|
1468
|
+
if (type === "array") {
|
|
1469
|
+
return !Array.isArray(schema.items) && isFlatQueryProperty(schema.items);
|
|
1470
|
+
}
|
|
1471
|
+
return false;
|
|
1472
|
+
}
|
|
1473
|
+
function validateActionDecls(definition) {
|
|
1474
|
+
const errors = [];
|
|
1475
|
+
const warnings = [];
|
|
1476
|
+
const manifest = definition.manifest;
|
|
1477
|
+
const actions = manifest.actions ?? [];
|
|
1478
|
+
const routes = manifest.routes ?? [];
|
|
1479
|
+
const frontend = manifest.frontend;
|
|
1480
|
+
if (actions.length === 0 && !frontend && !manifest.permissions.frontendEvents?.length) {
|
|
1481
|
+
return { errors, warnings };
|
|
1482
|
+
}
|
|
1483
|
+
const emittedShort = new Set(
|
|
1484
|
+
manifest.permissions.events.emit.filter((name) => name.startsWith("plugin.")).map((name) => name.slice("plugin.".length))
|
|
1485
|
+
);
|
|
1486
|
+
const declByRef = /* @__PURE__ */ new Map();
|
|
1487
|
+
for (const route of routes) {
|
|
1488
|
+
const key = `${route.method} ${route.path}`;
|
|
1489
|
+
if (!declByRef.has(key)) declByRef.set(key, route);
|
|
1490
|
+
}
|
|
1491
|
+
const seenKeys = /* @__PURE__ */ new Set();
|
|
1492
|
+
const queryActions = /* @__PURE__ */ new Set();
|
|
1493
|
+
const mutationActions = /* @__PURE__ */ new Set();
|
|
1494
|
+
for (const action of actions) {
|
|
1495
|
+
const label = `action '${action.key}'`;
|
|
1496
|
+
if (!ACTION_KEY_RE.test(action.key)) {
|
|
1497
|
+
errors.push(`${label}: key must be camelCase (${ACTION_KEY_RE})`);
|
|
1498
|
+
} else if (RESERVED_KEYS.has(action.key)) {
|
|
1499
|
+
errors.push(`${label}: key is a reserved word \u2014 pick another (it becomes a generated function name)`);
|
|
1500
|
+
}
|
|
1501
|
+
if (seenKeys.has(action.key)) errors.push(`${label}: duplicate key`);
|
|
1502
|
+
seenKeys.add(action.key);
|
|
1503
|
+
if (!action.title || action.title.trim().length === 0) {
|
|
1504
|
+
errors.push(`${label}: title is required`);
|
|
1505
|
+
}
|
|
1506
|
+
const ref = parseActionRoute(action.route);
|
|
1507
|
+
if (!ref) {
|
|
1508
|
+
errors.push(`${label}: route '${action.route}' must look like 'POST /claim'`);
|
|
1509
|
+
continue;
|
|
1510
|
+
}
|
|
1511
|
+
const decl = declByRef.get(`${ref.method} ${ref.path}`);
|
|
1512
|
+
if (!decl) {
|
|
1513
|
+
errors.push(`${label}: route '${action.route}' does not reference a declared route`);
|
|
1514
|
+
continue;
|
|
1515
|
+
}
|
|
1516
|
+
if (decl.surface !== "public" && decl.surface !== "player") {
|
|
1517
|
+
errors.push(
|
|
1518
|
+
`${label}: route surface '${decl.surface}' is not exposable \u2014 actions may only alias public/player routes`
|
|
1519
|
+
);
|
|
1520
|
+
}
|
|
1521
|
+
if (action.kind === "query" && decl.method !== QUERY_METHOD) {
|
|
1522
|
+
errors.push(`${label}: kind 'query' requires a GET route (got ${decl.method})`);
|
|
1523
|
+
}
|
|
1524
|
+
if (action.kind === "mutation" && !MUTATION_METHODS.has(decl.method)) {
|
|
1525
|
+
errors.push(`${label}: kind 'mutation' requires POST/PUT/DELETE (got ${decl.method})`);
|
|
1526
|
+
}
|
|
1527
|
+
if (Boolean(action.idempotent) !== Boolean(decl.idempotent)) {
|
|
1528
|
+
errors.push(
|
|
1529
|
+
`${label}: idempotent flag (${Boolean(action.idempotent)}) must match the route declaration (${Boolean(decl.idempotent)})`
|
|
1530
|
+
);
|
|
1531
|
+
}
|
|
1532
|
+
if (action.kind === "query") queryActions.add(action.key);
|
|
1533
|
+
if (action.kind === "mutation") mutationActions.add(action.key);
|
|
1534
|
+
for (const emit of action.emits ?? []) {
|
|
1535
|
+
if (!emittedShort.has(emit)) {
|
|
1536
|
+
errors.push(
|
|
1537
|
+
`${label}: emits '${emit}' is not a manifest-declared emitted event (expected one of permissions.events.emit without the 'plugin.' prefix)`
|
|
1538
|
+
);
|
|
1539
|
+
}
|
|
1540
|
+
}
|
|
1541
|
+
}
|
|
1542
|
+
for (const type of manifest.permissions.frontendEvents ?? []) {
|
|
1543
|
+
if (!emittedShort.has(type)) {
|
|
1544
|
+
errors.push(
|
|
1545
|
+
`permissions.frontendEvents '${type}': not a manifest-declared emitted event (expected an entry of permissions.events.emit without the 'plugin.' prefix)`
|
|
1546
|
+
);
|
|
1547
|
+
}
|
|
1548
|
+
}
|
|
1549
|
+
const widgetKeys = /* @__PURE__ */ new Set();
|
|
1550
|
+
for (const widget of frontend?.widgets ?? []) {
|
|
1551
|
+
const label = `frontend widget '${widget.key}'`;
|
|
1552
|
+
if (widgetKeys.has(widget.key)) errors.push(`${label}: duplicate key`);
|
|
1553
|
+
widgetKeys.add(widget.key);
|
|
1554
|
+
if (!queryActions.has(widget.dataAction)) {
|
|
1555
|
+
errors.push(`${label}: dataAction '${widget.dataAction}' is not a declared query action`);
|
|
1556
|
+
}
|
|
1557
|
+
for (const key of widget.actions ?? []) {
|
|
1558
|
+
if (!mutationActions.has(key)) {
|
|
1559
|
+
errors.push(`${label}: action '${key}' is not a declared mutation action`);
|
|
1560
|
+
}
|
|
1561
|
+
}
|
|
1562
|
+
}
|
|
1563
|
+
if (actions.some((a) => a.kind === "query")) {
|
|
1564
|
+
let schemas = {};
|
|
1565
|
+
try {
|
|
1566
|
+
schemas = deriveActionSchemas(definition);
|
|
1567
|
+
} catch (err) {
|
|
1568
|
+
errors.push(`action schema derivation failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
1569
|
+
}
|
|
1570
|
+
for (const action of actions) {
|
|
1571
|
+
if (action.kind !== "query") continue;
|
|
1572
|
+
const input = schemas[action.key]?.input;
|
|
1573
|
+
if (input === void 0) continue;
|
|
1574
|
+
if (!isPlainObject(input) || input.type !== "object" || !isPlainObject(input.properties)) {
|
|
1575
|
+
errors.push(`action '${action.key}': query input must be a flat object schema`);
|
|
1576
|
+
continue;
|
|
1577
|
+
}
|
|
1578
|
+
for (const [prop, propSchema] of Object.entries(input.properties)) {
|
|
1579
|
+
if (!isFlatQueryProperty(propSchema)) {
|
|
1580
|
+
errors.push(
|
|
1581
|
+
`action '${action.key}': query input property '${prop}' must be a scalar or array of scalars (nested objects are not encodable as query parameters)`
|
|
1582
|
+
);
|
|
1583
|
+
}
|
|
1584
|
+
}
|
|
1585
|
+
}
|
|
1586
|
+
}
|
|
1587
|
+
return { errors, warnings };
|
|
1588
|
+
}
|
|
1589
|
+
|
|
1590
|
+
// src/codegen.ts
|
|
1591
|
+
function compareKeys(a, b) {
|
|
1592
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
1593
|
+
}
|
|
1594
|
+
var GENERATED_HEADER = (key, version) => `// Generated by \`cwe-plugin codegen client\` for plugin "${key}"@${version}.
|
|
1595
|
+
// DO NOT EDIT \u2014 regenerate with \`cwe-plugin codegen client\`; the doctor
|
|
1596
|
+
// fails on any drift between this directory and the plugin source.
|
|
1597
|
+
`;
|
|
1598
|
+
function pascalCase(value) {
|
|
1599
|
+
return value.split(/[-_.\s]+/).filter(Boolean).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("");
|
|
1600
|
+
}
|
|
1601
|
+
function isPlainObject2(value) {
|
|
1602
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1603
|
+
}
|
|
1604
|
+
function literalText(value) {
|
|
1605
|
+
if (typeof value === "string") return JSON.stringify(value);
|
|
1606
|
+
if (typeof value === "number" || typeof value === "boolean") return String(value);
|
|
1607
|
+
if (value === null) return "null";
|
|
1608
|
+
return "unknown";
|
|
1609
|
+
}
|
|
1610
|
+
var IDENT_RE = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
|
|
1611
|
+
function propertyKey(name) {
|
|
1612
|
+
return IDENT_RE.test(name) ? name : JSON.stringify(name);
|
|
1613
|
+
}
|
|
1614
|
+
function indent(text) {
|
|
1615
|
+
return text.split("\n").map((line) => line.length > 0 ? ` ${line}` : line).join("\n");
|
|
1616
|
+
}
|
|
1617
|
+
function jsonSchemaToTsType(schema) {
|
|
1618
|
+
if (schema === true || schema === void 0) return "unknown";
|
|
1619
|
+
if (schema === false) return "never";
|
|
1620
|
+
if (!isPlainObject2(schema)) return "unknown";
|
|
1621
|
+
if (Array.isArray(schema.enum)) {
|
|
1622
|
+
return schema.enum.map(literalText).join(" | ") || "never";
|
|
1623
|
+
}
|
|
1624
|
+
if ("const" in schema) return literalText(schema.const);
|
|
1625
|
+
const composite = schema.anyOf ?? schema.oneOf;
|
|
1626
|
+
if (Array.isArray(composite)) {
|
|
1627
|
+
const parts = composite.map(jsonSchemaToTsType);
|
|
1628
|
+
return [...new Set(parts)].join(" | ") || "unknown";
|
|
1629
|
+
}
|
|
1630
|
+
if (Array.isArray(schema.allOf)) {
|
|
1631
|
+
const parts = schema.allOf.map(jsonSchemaToTsType);
|
|
1632
|
+
return parts.join(" & ") || "unknown";
|
|
1633
|
+
}
|
|
1634
|
+
const type = schema.type;
|
|
1635
|
+
if (Array.isArray(type)) {
|
|
1636
|
+
const parts = type.map((t) => jsonSchemaToTsType({ ...schema, type: t }));
|
|
1637
|
+
return [...new Set(parts)].join(" | ") || "unknown";
|
|
1638
|
+
}
|
|
1639
|
+
switch (type) {
|
|
1640
|
+
case "string":
|
|
1641
|
+
return "string";
|
|
1642
|
+
case "number":
|
|
1643
|
+
case "integer":
|
|
1644
|
+
return "number";
|
|
1645
|
+
case "boolean":
|
|
1646
|
+
return "boolean";
|
|
1647
|
+
case "null":
|
|
1648
|
+
return "null";
|
|
1649
|
+
case "array": {
|
|
1650
|
+
if (Array.isArray(schema.items)) {
|
|
1651
|
+
const parts = schema.items.map(jsonSchemaToTsType);
|
|
1652
|
+
return `[${parts.join(", ")}]`;
|
|
1653
|
+
}
|
|
1654
|
+
const item = jsonSchemaToTsType(schema.items);
|
|
1655
|
+
return item.includes(" ") ? `Array<${item}>` : `${item}[]`;
|
|
1656
|
+
}
|
|
1657
|
+
case "object": {
|
|
1658
|
+
const props = isPlainObject2(schema.properties) ? schema.properties : void 0;
|
|
1659
|
+
const required = new Set(Array.isArray(schema.required) ? schema.required : []);
|
|
1660
|
+
const lines = [];
|
|
1661
|
+
if (props) {
|
|
1662
|
+
for (const [name, prop] of Object.entries(props)) {
|
|
1663
|
+
const optional = required.has(name) ? "" : "?";
|
|
1664
|
+
lines.push(`${propertyKey(name)}${optional}: ${jsonSchemaToTsType(prop)};`);
|
|
1665
|
+
}
|
|
1666
|
+
}
|
|
1667
|
+
const additional = schema.additionalProperties;
|
|
1668
|
+
if (isPlainObject2(additional) || additional === true) {
|
|
1669
|
+
const valueType = additional === true ? "unknown" : jsonSchemaToTsType(additional);
|
|
1670
|
+
if (lines.length === 0) return `Record<string, ${valueType}>`;
|
|
1671
|
+
lines.push(`[key: string]: unknown;`);
|
|
1672
|
+
}
|
|
1673
|
+
if (lines.length === 0) return "Record<string, never>";
|
|
1674
|
+
return `{
|
|
1675
|
+
${indent(lines.join("\n"))}
|
|
1676
|
+
}`;
|
|
1677
|
+
}
|
|
1678
|
+
default:
|
|
1679
|
+
return "unknown";
|
|
1680
|
+
}
|
|
1681
|
+
}
|
|
1682
|
+
function buildActionModels(definition) {
|
|
1683
|
+
const schemas = deriveActionSchemas(definition);
|
|
1684
|
+
const actions = [...definition.manifest.actions ?? []].sort(
|
|
1685
|
+
(a, b) => compareKeys(a.key, b.key)
|
|
1686
|
+
);
|
|
1687
|
+
return actions.filter((a) => parseActionRoute(a.route) !== null).map((decl) => {
|
|
1688
|
+
const doc = schemas[decl.key] ?? {};
|
|
1689
|
+
return {
|
|
1690
|
+
decl,
|
|
1691
|
+
inputType: doc.input !== void 0 ? jsonSchemaToTsType(doc.input) : null,
|
|
1692
|
+
outputType: doc.output !== void 0 ? jsonSchemaToTsType(doc.output) : null
|
|
1693
|
+
};
|
|
1694
|
+
});
|
|
1695
|
+
}
|
|
1696
|
+
function typesFile(definition, models) {
|
|
1697
|
+
const { key, version } = definition.manifest;
|
|
1698
|
+
const actionsName = `${pascalCase(key)}Actions`;
|
|
1699
|
+
const lines = [GENERATED_HEADER(key, version)];
|
|
1700
|
+
for (const model of models) {
|
|
1701
|
+
const base = pascalCase(model.decl.key);
|
|
1702
|
+
if (model.inputType !== null) {
|
|
1703
|
+
lines.push(`export type ${base}Input = ${model.inputType};`, "");
|
|
1704
|
+
}
|
|
1705
|
+
if (model.outputType !== null) {
|
|
1706
|
+
lines.push(`export type ${base}Output = ${model.outputType};`, "");
|
|
1707
|
+
}
|
|
1708
|
+
}
|
|
1709
|
+
lines.push(`/** Action map for \`ExtRegistry\` augmentation \u2014 keys are stable API. */`);
|
|
1710
|
+
lines.push(`export interface ${actionsName} {`);
|
|
1711
|
+
for (const model of models) {
|
|
1712
|
+
const base = pascalCase(model.decl.key);
|
|
1713
|
+
const input = model.inputType !== null ? `${base}Input` : "undefined";
|
|
1714
|
+
const output = model.outputType !== null ? `${base}Output` : "unknown";
|
|
1715
|
+
lines.push(
|
|
1716
|
+
` ${propertyKey(model.decl.key)}: { kind: ${JSON.stringify(model.decl.kind)}; input: ${input}; output: ${output} };`
|
|
1717
|
+
);
|
|
1718
|
+
}
|
|
1719
|
+
lines.push(`}`, "");
|
|
1720
|
+
const frontendEvents = [...definition.manifest.permissions.frontendEvents ?? []].sort();
|
|
1721
|
+
if (frontendEvents.length > 0) {
|
|
1722
|
+
const eventsName = `${pascalCase(key)}Event`;
|
|
1723
|
+
lines.push(`/** Realtime events on the \`ext.${key}\` channel (\`data.type\` values). */`);
|
|
1724
|
+
lines.push(
|
|
1725
|
+
`export type ${eventsName}Type = ${frontendEvents.map((e) => JSON.stringify(e)).join(" | ")};`
|
|
1726
|
+
);
|
|
1727
|
+
lines.push(
|
|
1728
|
+
`export type ${eventsName} = ${frontendEvents.map((e) => `{ type: ${JSON.stringify(e)}; payload: unknown }`).join(" | ")};`,
|
|
1729
|
+
""
|
|
1730
|
+
);
|
|
1731
|
+
}
|
|
1732
|
+
return lines.join("\n");
|
|
1733
|
+
}
|
|
1734
|
+
function clientFile(definition, models) {
|
|
1735
|
+
const { key, version } = definition.manifest;
|
|
1736
|
+
const actionsName = `${pascalCase(key)}Actions`;
|
|
1737
|
+
const lines = [GENERATED_HEADER(key, version)];
|
|
1738
|
+
lines.push(`import type { ${actionsName} } from "./types.js";`, "");
|
|
1739
|
+
lines.push(`export const PLUGIN_KEY = ${JSON.stringify(key)};`);
|
|
1740
|
+
lines.push(`/** Extension catalog protocol version this client was generated against. */`);
|
|
1741
|
+
lines.push(`export const CATALOG_VERSION = 1;`);
|
|
1742
|
+
lines.push(`/**`);
|
|
1743
|
+
lines.push(` * Plugin semver range this client is valid for. The SDK checks it against`);
|
|
1744
|
+
lines.push(` * the live catalog entry (\`assertPluginVersion\`) and throws`);
|
|
1745
|
+
lines.push(` * \`PluginVersionMismatchError\` when the installed plugin drifted.`);
|
|
1746
|
+
lines.push(` */`);
|
|
1747
|
+
lines.push(`export const expectedPluginVersion = ${JSON.stringify(`^${version}`)};`, "");
|
|
1748
|
+
lines.push(`export interface ExtCallOpts {`);
|
|
1749
|
+
lines.push(` idempotencyKey?: string;`);
|
|
1750
|
+
lines.push(` signal?: AbortSignal;`);
|
|
1751
|
+
lines.push(`}`, "");
|
|
1752
|
+
lines.push(`/**`);
|
|
1753
|
+
lines.push(` * Structural slice of \`@clovnet/casino-sdk\` \u2014 this package carries zero`);
|
|
1754
|
+
lines.push(` * transport and zero auth; every call delegates to the generic ext layer.`);
|
|
1755
|
+
lines.push(` */`);
|
|
1756
|
+
lines.push(`export interface ExtSdkLike {`);
|
|
1757
|
+
lines.push(` ext(pluginKey: string): {`);
|
|
1758
|
+
lines.push(
|
|
1759
|
+
` call<TResult = unknown>(actionKey: string, input?: unknown, opts?: ExtCallOpts): Promise<TResult>;`
|
|
1760
|
+
);
|
|
1761
|
+
lines.push(` };`);
|
|
1762
|
+
lines.push(`}`, "");
|
|
1763
|
+
for (const model of models) {
|
|
1764
|
+
const base = pascalCase(model.decl.key);
|
|
1765
|
+
const doc = [model.decl.title];
|
|
1766
|
+
if (model.decl.description) doc.push(model.decl.description);
|
|
1767
|
+
if (model.decl.deprecated) doc.push(`@deprecated ${model.decl.deprecated}`);
|
|
1768
|
+
lines.push(`/**`);
|
|
1769
|
+
for (const d of doc) lines.push(` * ${d}`);
|
|
1770
|
+
lines.push(` */`);
|
|
1771
|
+
const output = `Promise<${actionsName}[${JSON.stringify(model.decl.key)}]["output"]>`;
|
|
1772
|
+
if (model.inputType !== null) {
|
|
1773
|
+
lines.push(
|
|
1774
|
+
`export function ${model.decl.key}(sdk: ExtSdkLike, input: ${base}Input, opts?: ExtCallOpts): ${output} {`
|
|
1775
|
+
);
|
|
1776
|
+
lines.push(
|
|
1777
|
+
` return sdk.ext(PLUGIN_KEY).call(${JSON.stringify(model.decl.key)}, input, opts);`
|
|
1778
|
+
);
|
|
1779
|
+
} else {
|
|
1780
|
+
lines.push(`export function ${model.decl.key}(sdk: ExtSdkLike, opts?: ExtCallOpts): ${output} {`);
|
|
1781
|
+
lines.push(
|
|
1782
|
+
` return sdk.ext(PLUGIN_KEY).call(${JSON.stringify(model.decl.key)}, undefined, opts);`
|
|
1783
|
+
);
|
|
1784
|
+
}
|
|
1785
|
+
lines.push(`}`, "");
|
|
1786
|
+
}
|
|
1787
|
+
const usedInputs = models.filter((m) => m.inputType !== null).map((m) => `${pascalCase(m.decl.key)}Input`);
|
|
1788
|
+
if (usedInputs.length > 0) {
|
|
1789
|
+
lines[1] = `import type { ${actionsName}, ${usedInputs.join(", ")} } from "./types.js";`;
|
|
1790
|
+
}
|
|
1791
|
+
return lines.join("\n");
|
|
1792
|
+
}
|
|
1793
|
+
function augmentFile(definition) {
|
|
1794
|
+
const { key, version } = definition.manifest;
|
|
1795
|
+
const actionsName = `${pascalCase(key)}Actions`;
|
|
1796
|
+
return [
|
|
1797
|
+
GENERATED_HEADER(key, version),
|
|
1798
|
+
`import type { ${actionsName} } from "./types.js";`,
|
|
1799
|
+
``,
|
|
1800
|
+
`declare module "@clovnet/casino-sdk" {`,
|
|
1801
|
+
` interface ExtRegistry {`,
|
|
1802
|
+
` ${propertyKey(key)}: ${actionsName};`,
|
|
1803
|
+
` }`,
|
|
1804
|
+
`}`,
|
|
1805
|
+
``,
|
|
1806
|
+
`export {};`,
|
|
1807
|
+
``
|
|
1808
|
+
].join("\n");
|
|
1809
|
+
}
|
|
1810
|
+
function indexFile(definition) {
|
|
1811
|
+
const { key, version } = definition.manifest;
|
|
1812
|
+
return [
|
|
1813
|
+
GENERATED_HEADER(key, version),
|
|
1814
|
+
`import "./augment.js";`,
|
|
1815
|
+
``,
|
|
1816
|
+
`export * from "./types.js";`,
|
|
1817
|
+
`export * from "./client.js";`,
|
|
1818
|
+
``
|
|
1819
|
+
].join("\n");
|
|
1820
|
+
}
|
|
1821
|
+
function packageJsonFile(definition, opts) {
|
|
1822
|
+
const { key, version } = definition.manifest;
|
|
1823
|
+
const pkg = {
|
|
1824
|
+
name: `@cwe-plugins/${key}-client`,
|
|
1825
|
+
version,
|
|
1826
|
+
description: `Typed Casino SDK client for the "${key}" plugin. Generated by cwe-plugin codegen client \u2014 do not edit.`,
|
|
1827
|
+
license: "MIT",
|
|
1828
|
+
type: "module",
|
|
1829
|
+
sideEffects: false,
|
|
1830
|
+
exports: {
|
|
1831
|
+
".": "./src/index.ts"
|
|
1832
|
+
},
|
|
1833
|
+
files: ["src"],
|
|
1834
|
+
peerDependencies: {
|
|
1835
|
+
"@clovnet/casino-sdk": opts.sdkPeerRange ?? ">=0.3.0"
|
|
1836
|
+
}
|
|
1837
|
+
};
|
|
1838
|
+
return `${JSON.stringify(pkg, null, 2)}
|
|
1839
|
+
`;
|
|
1840
|
+
}
|
|
1841
|
+
function generateClientPackage(definition, opts = {}) {
|
|
1842
|
+
const models = buildActionModels(definition);
|
|
1843
|
+
return {
|
|
1844
|
+
"package.json": packageJsonFile(definition, opts),
|
|
1845
|
+
"src/augment.ts": augmentFile(definition),
|
|
1846
|
+
"src/client.ts": clientFile(definition, models),
|
|
1847
|
+
"src/index.ts": indexFile(definition),
|
|
1848
|
+
"src/types.ts": typesFile(definition, models)
|
|
1849
|
+
};
|
|
1850
|
+
}
|
|
1851
|
+
|
|
1852
|
+
export {
|
|
1853
|
+
DataScopes,
|
|
1854
|
+
ReadModelRequiredScopes,
|
|
1855
|
+
READ_MODEL_MAX_PAGE,
|
|
1856
|
+
PLUGIN_DATASET_LIMITS,
|
|
1857
|
+
PLUGIN_JOB_LIMITS,
|
|
1858
|
+
PLUGIN_MIGRATION_LIMITS,
|
|
1859
|
+
CATALOG_IMPORT_TASK_TYPE,
|
|
1860
|
+
CATALOG_ALLOWED_KINDS,
|
|
1861
|
+
PLUGIN_CATALOG_LIMITS,
|
|
1862
|
+
ACTION_KEY_RE,
|
|
1863
|
+
parseActionRoute,
|
|
1864
|
+
fullPluginEventName,
|
|
1865
|
+
shortPluginEventType,
|
|
1866
|
+
deriveActionSchemas,
|
|
1867
|
+
validateActionDecls,
|
|
1868
|
+
pascalCase,
|
|
1869
|
+
jsonSchemaToTsType,
|
|
1870
|
+
generateClientPackage
|
|
1871
|
+
};
|
|
1872
|
+
//# sourceMappingURL=chunk-XRSKWL3A.js.map
|