@temporary-name/server 1.9.3-alpha.ec3bfb9dce56198911349c322c970208b21b50db → 1.9.3-alpha.edd373b82156a10608d43b19a44b75ae72e72de7
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/dist/adapters/aws-lambda/index.d.mts +2 -2
- package/dist/adapters/aws-lambda/index.d.ts +2 -2
- package/dist/adapters/aws-lambda/index.mjs +3 -3
- package/dist/adapters/fetch/index.d.mts +2 -2
- package/dist/adapters/fetch/index.d.ts +2 -2
- package/dist/adapters/fetch/index.mjs +3 -3
- package/dist/adapters/node/index.d.mts +2 -2
- package/dist/adapters/node/index.d.ts +2 -2
- package/dist/adapters/node/index.mjs +3 -3
- package/dist/adapters/standard/index.d.mts +2 -2
- package/dist/adapters/standard/index.d.ts +2 -2
- package/dist/adapters/standard/index.mjs +3 -3
- package/dist/index.d.mts +268 -16
- package/dist/index.d.ts +268 -16
- package/dist/index.mjs +379 -71
- package/dist/openapi/index.d.mts +11 -30
- package/dist/openapi/index.d.ts +11 -30
- package/dist/openapi/index.mjs +338 -295
- package/dist/shared/{server.Cza0RB3u.mjs → server.BCY45g2x.mjs} +1 -1
- package/dist/shared/{server.ChOv1yG3.mjs → server.BETu17rq.mjs} +1 -1
- package/dist/shared/server.B_oW_rPl.mjs +525 -0
- package/dist/shared/server.CjPiuQYH.d.mts +51 -0
- package/dist/shared/server.CjPiuQYH.d.ts +51 -0
- package/dist/shared/{server.CYa9puL2.mjs → server.Cq7SBLD5.mjs} +2 -2
- package/dist/shared/{server.CVhIyQ4x.d.mts → server.DGH2Bq4t.d.mts} +1 -1
- package/dist/shared/{server.D8RAzJ_p.d.ts → server.nQoUObAJ.d.ts} +1 -1
- package/dist/shared/{server.Cj3_Lp61.d.ts → server.zsKBRxsz.d.mts} +26 -11
- package/dist/shared/{server.Cj3_Lp61.d.mts → server.zsKBRxsz.d.ts} +26 -11
- package/package.json +8 -8
- package/dist/shared/server.YUvuxHty.mjs +0 -48
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { resolveMaybeOptionalOptions, toArray, value, runWithSpan, isAsyncIteratorObject, overlayProxy, asyncIteratorWithSpan, ORPCError } from '@temporary-name/shared';
|
|
2
2
|
import { HibernationEventIterator, mapEventIterator } from '@temporary-name/standard-server';
|
|
3
3
|
import { safeDecodeAsync, safeEncodeAsync } from '@temporary-name/zod';
|
|
4
|
-
import { u as unlazy, V as ValidationError } from './server.
|
|
4
|
+
import { u as unlazy, V as ValidationError } from './server.BETu17rq.mjs';
|
|
5
5
|
|
|
6
6
|
function mergeCurrentContext(context, other) {
|
|
7
7
|
return { ...context, ...other };
|
|
@@ -316,4 +316,4 @@ function parseEndpointDefinition(stringsOrEndpoint, values) {
|
|
|
316
316
|
return { method, path, pathSchema };
|
|
317
317
|
}
|
|
318
318
|
|
|
319
|
-
export { Contract as C, LAZY_SYMBOL as L, Procedure as P, ValidationError as V, mergeTags as a, mergeRoute as b, prefixRoute as c, addMiddleware as d, enhanceRouter as e, getLazyMeta as f, getDynamicParams as g,
|
|
319
|
+
export { Contract as C, LAZY_SYMBOL as L, Procedure as P, ValidationError as V, mergeTags as a, mergeRoute as b, prefixRoute as c, addMiddleware as d, enhanceRouter as e, getLazyMeta as f, getDynamicParams as g, lazy as h, isProcedure as i, isLazy as j, isStartWithMiddlewares as k, lazyInternal as l, mergePrefix as m, mergeMiddlewares as n, getRouter as o, parseEndpointDefinition as p, createAccessibleLazyRouter as q, resolveContractProcedures as r, standardizeHTTPPath as s, traverseContractProcedures as t, unlazy as u, unlazyRouter as v, endpointRegex as w };
|
|
@@ -0,0 +1,525 @@
|
|
|
1
|
+
import { isAsyncIteratorObject, ORPCError, toArray } from '@temporary-name/shared';
|
|
2
|
+
import { mapEventIterator } from '@temporary-name/standard-server';
|
|
3
|
+
import { custom, safeParseAsync } from '@temporary-name/zod';
|
|
4
|
+
import { V as ValidationError } from './server.BETu17rq.mjs';
|
|
5
|
+
import { JSONSchemaFormat, JSONSchemaContentEncoding } from '@temporary-name/server/openapi';
|
|
6
|
+
import { registry, globalRegistry } from 'zod/v4/core';
|
|
7
|
+
|
|
8
|
+
const EVENT_ITERATOR_DETAILS_SYMBOL = Symbol("ORPC_EVENT_ITERATOR_DETAILS");
|
|
9
|
+
function eventIterator(yields, returns) {
|
|
10
|
+
const schema = custom(
|
|
11
|
+
(iterator) => isAsyncIteratorObject(iterator)
|
|
12
|
+
).transform((iterator) => {
|
|
13
|
+
const mapped = mapEventIterator(iterator, {
|
|
14
|
+
async value(value, done) {
|
|
15
|
+
const schema2 = done ? returns : yields;
|
|
16
|
+
if (!schema2) {
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
const result = await safeParseAsync(schema2, value);
|
|
20
|
+
if (result.success) {
|
|
21
|
+
return result.data;
|
|
22
|
+
} else {
|
|
23
|
+
throw new ORPCError("EVENT_ITERATOR_VALIDATION_FAILED", {
|
|
24
|
+
message: "Event iterator validation failed",
|
|
25
|
+
cause: new ValidationError({
|
|
26
|
+
issues: result.error.issues,
|
|
27
|
+
message: "Event iterator validation failed",
|
|
28
|
+
data: value
|
|
29
|
+
})
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
error: async (error) => error
|
|
34
|
+
});
|
|
35
|
+
return mapped;
|
|
36
|
+
});
|
|
37
|
+
schema[EVENT_ITERATOR_DETAILS_SYMBOL] = {
|
|
38
|
+
yields,
|
|
39
|
+
returns
|
|
40
|
+
};
|
|
41
|
+
return schema;
|
|
42
|
+
}
|
|
43
|
+
function getEventIteratorSchemaDetails(schema) {
|
|
44
|
+
if (schema === void 0) {
|
|
45
|
+
return void 0;
|
|
46
|
+
}
|
|
47
|
+
return schema[EVENT_ITERATOR_DETAILS_SYMBOL];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
var JsonSchemaXNativeType = /* @__PURE__ */ ((JsonSchemaXNativeType2) => {
|
|
51
|
+
JsonSchemaXNativeType2["BigInt"] = "bigint";
|
|
52
|
+
JsonSchemaXNativeType2["RegExp"] = "regexp";
|
|
53
|
+
JsonSchemaXNativeType2["Date"] = "date";
|
|
54
|
+
JsonSchemaXNativeType2["Url"] = "url";
|
|
55
|
+
JsonSchemaXNativeType2["Set"] = "set";
|
|
56
|
+
JsonSchemaXNativeType2["Map"] = "map";
|
|
57
|
+
return JsonSchemaXNativeType2;
|
|
58
|
+
})(JsonSchemaXNativeType || {});
|
|
59
|
+
|
|
60
|
+
const JSON_SCHEMA_REGISTRY = registry();
|
|
61
|
+
const JSON_SCHEMA_INPUT_REGISTRY = registry();
|
|
62
|
+
const JSON_SCHEMA_OUTPUT_REGISTRY = registry();
|
|
63
|
+
|
|
64
|
+
class ZodToJsonSchemaConverter {
|
|
65
|
+
maxLazyDepth;
|
|
66
|
+
maxStructureDepth;
|
|
67
|
+
anyJsonSchema;
|
|
68
|
+
unsupportedJsonSchema;
|
|
69
|
+
undefinedJsonSchema;
|
|
70
|
+
constructor(options = {}) {
|
|
71
|
+
this.maxLazyDepth = options.maxLazyDepth ?? 2;
|
|
72
|
+
this.maxStructureDepth = options.maxStructureDepth ?? 10;
|
|
73
|
+
this.anyJsonSchema = options.anyJsonSchema ?? {};
|
|
74
|
+
this.unsupportedJsonSchema = options.unsupportedJsonSchema ?? { not: {} };
|
|
75
|
+
this.undefinedJsonSchema = options.undefinedJsonSchema ?? { not: {} };
|
|
76
|
+
}
|
|
77
|
+
convert = (schema, options) => {
|
|
78
|
+
return this.#convert(schema, options, 0, 0);
|
|
79
|
+
};
|
|
80
|
+
#convert(schema, options, lazyDepth, structureDepth, isHandledCustomJSONSchema = false) {
|
|
81
|
+
if (structureDepth > this.maxStructureDepth) {
|
|
82
|
+
return [false, this.anyJsonSchema];
|
|
83
|
+
}
|
|
84
|
+
if (!options.minStructureDepthForRef || options.minStructureDepthForRef <= structureDepth) {
|
|
85
|
+
const components = toArray(options.components);
|
|
86
|
+
for (const component of components) {
|
|
87
|
+
if (component.schema === schema && component.allowedStrategies.includes(options.strategy)) {
|
|
88
|
+
return [component.required, { $ref: component.ref }];
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (!isHandledCustomJSONSchema) {
|
|
93
|
+
const customJSONSchema = this.#getCustomJsonSchema(schema, options);
|
|
94
|
+
if (customJSONSchema) {
|
|
95
|
+
const [required, json] = this.#convert(schema, options, lazyDepth, structureDepth, true);
|
|
96
|
+
return [required, { ...json, ...customJSONSchema }];
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
switch (schema._zod.def.type) {
|
|
100
|
+
case "string": {
|
|
101
|
+
const string = schema;
|
|
102
|
+
const json = { type: "string" };
|
|
103
|
+
const { minimum, maximum, format, patterns, contentEncoding } = string._zod.bag;
|
|
104
|
+
if (typeof minimum === "number") {
|
|
105
|
+
json.minLength = minimum;
|
|
106
|
+
}
|
|
107
|
+
if (typeof maximum === "number") {
|
|
108
|
+
json.maxLength = maximum;
|
|
109
|
+
}
|
|
110
|
+
if (typeof contentEncoding === "string") {
|
|
111
|
+
json.contentEncoding = this.#handleContentEncoding(contentEncoding);
|
|
112
|
+
}
|
|
113
|
+
if (typeof format === "string" && format !== "regex" && json.contentEncoding === void 0) {
|
|
114
|
+
json.format = this.#handleStringFormat(format);
|
|
115
|
+
}
|
|
116
|
+
if (patterns instanceof Set && json.contentEncoding === void 0 && json.format === void 0) {
|
|
117
|
+
for (const pattern of patterns) {
|
|
118
|
+
if (json.pattern === void 0) {
|
|
119
|
+
json.pattern = pattern.source;
|
|
120
|
+
} else {
|
|
121
|
+
json.allOf ??= [];
|
|
122
|
+
json.allOf.push({ pattern: pattern.source });
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
if (format === "jwt" && json.contentEncoding === void 0 && json.format === void 0 && json.pattern === void 0) {
|
|
127
|
+
json.pattern = /^[\w-]+\.[\w-]+\.[\w-]+$/.source;
|
|
128
|
+
}
|
|
129
|
+
return [true, json];
|
|
130
|
+
}
|
|
131
|
+
case "number": {
|
|
132
|
+
const number = schema;
|
|
133
|
+
const json = { type: "number" };
|
|
134
|
+
const { minimum, maximum, format, multipleOf, exclusiveMaximum, exclusiveMinimum } = number._zod.bag;
|
|
135
|
+
if (typeof format === "string" && format?.includes("int")) {
|
|
136
|
+
json.type = "integer";
|
|
137
|
+
}
|
|
138
|
+
if (typeof minimum === "number") {
|
|
139
|
+
json.minimum = minimum;
|
|
140
|
+
}
|
|
141
|
+
if (typeof maximum === "number") {
|
|
142
|
+
json.maximum = maximum;
|
|
143
|
+
}
|
|
144
|
+
if (typeof exclusiveMinimum === "number") {
|
|
145
|
+
json.exclusiveMinimum = exclusiveMinimum;
|
|
146
|
+
}
|
|
147
|
+
if (typeof exclusiveMaximum === "number") {
|
|
148
|
+
json.exclusiveMaximum = exclusiveMaximum;
|
|
149
|
+
}
|
|
150
|
+
if (typeof multipleOf === "number") {
|
|
151
|
+
json.multipleOf = multipleOf;
|
|
152
|
+
}
|
|
153
|
+
return [true, json];
|
|
154
|
+
}
|
|
155
|
+
case "boolean": {
|
|
156
|
+
return [true, { type: "boolean" }];
|
|
157
|
+
}
|
|
158
|
+
case "bigint": {
|
|
159
|
+
return [
|
|
160
|
+
true,
|
|
161
|
+
{
|
|
162
|
+
type: "string",
|
|
163
|
+
pattern: "^-?[0-9]+$",
|
|
164
|
+
"x-native-type": JsonSchemaXNativeType.BigInt
|
|
165
|
+
}
|
|
166
|
+
];
|
|
167
|
+
}
|
|
168
|
+
case "date": {
|
|
169
|
+
return [
|
|
170
|
+
true,
|
|
171
|
+
{
|
|
172
|
+
type: "string",
|
|
173
|
+
format: JSONSchemaFormat.DateTime,
|
|
174
|
+
"x-native-type": JsonSchemaXNativeType.Date
|
|
175
|
+
}
|
|
176
|
+
];
|
|
177
|
+
}
|
|
178
|
+
case "null": {
|
|
179
|
+
return [true, { type: "null" }];
|
|
180
|
+
}
|
|
181
|
+
case "undefined":
|
|
182
|
+
case "void": {
|
|
183
|
+
return [false, this.undefinedJsonSchema];
|
|
184
|
+
}
|
|
185
|
+
case "any": {
|
|
186
|
+
return [false, this.anyJsonSchema];
|
|
187
|
+
}
|
|
188
|
+
case "unknown": {
|
|
189
|
+
return [false, this.anyJsonSchema];
|
|
190
|
+
}
|
|
191
|
+
case "never": {
|
|
192
|
+
return [true, this.unsupportedJsonSchema];
|
|
193
|
+
}
|
|
194
|
+
case "array": {
|
|
195
|
+
const array = schema;
|
|
196
|
+
const json = { type: "array" };
|
|
197
|
+
const { minimum, maximum } = array._zod.bag;
|
|
198
|
+
if (typeof minimum === "number") {
|
|
199
|
+
json.minItems = minimum;
|
|
200
|
+
}
|
|
201
|
+
if (typeof maximum === "number") {
|
|
202
|
+
json.maxItems = maximum;
|
|
203
|
+
}
|
|
204
|
+
json.items = this.#handleArrayItemJsonSchema(
|
|
205
|
+
this.#convert(array._zod.def.element, options, lazyDepth, structureDepth + 1),
|
|
206
|
+
options
|
|
207
|
+
);
|
|
208
|
+
return [true, json];
|
|
209
|
+
}
|
|
210
|
+
case "object": {
|
|
211
|
+
const object = schema;
|
|
212
|
+
const json = { type: "object" };
|
|
213
|
+
for (const [key, value] of Object.entries(object._zod.def.shape)) {
|
|
214
|
+
const [itemRequired, itemJson] = this.#convert(value, options, lazyDepth, structureDepth + 1);
|
|
215
|
+
json.properties ??= {};
|
|
216
|
+
json.properties[key] = itemJson;
|
|
217
|
+
if (itemRequired) {
|
|
218
|
+
json.required ??= [];
|
|
219
|
+
json.required.push(key);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
if (object._zod.def.catchall) {
|
|
223
|
+
if (object._zod.def.catchall._zod.def.type === "never") {
|
|
224
|
+
json.additionalProperties = false;
|
|
225
|
+
} else {
|
|
226
|
+
const [_, addJson] = this.#convert(
|
|
227
|
+
object._zod.def.catchall,
|
|
228
|
+
options,
|
|
229
|
+
lazyDepth,
|
|
230
|
+
structureDepth + 1
|
|
231
|
+
);
|
|
232
|
+
json.additionalProperties = addJson;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
return [true, json];
|
|
236
|
+
}
|
|
237
|
+
case "union": {
|
|
238
|
+
const union = schema;
|
|
239
|
+
const anyOf = [];
|
|
240
|
+
let required = true;
|
|
241
|
+
for (const item of union._zod.def.options) {
|
|
242
|
+
const [itemRequired, itemJson] = this.#convert(item, options, lazyDepth, structureDepth);
|
|
243
|
+
if (!itemRequired) {
|
|
244
|
+
required = false;
|
|
245
|
+
}
|
|
246
|
+
if (options.strategy === "input") {
|
|
247
|
+
if (itemJson !== this.undefinedJsonSchema && itemJson !== this.unsupportedJsonSchema) {
|
|
248
|
+
anyOf.push(itemJson);
|
|
249
|
+
}
|
|
250
|
+
} else {
|
|
251
|
+
if (itemJson !== this.undefinedJsonSchema) {
|
|
252
|
+
anyOf.push(itemJson);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
return [required, anyOf.length === 1 ? anyOf[0] : { anyOf }];
|
|
257
|
+
}
|
|
258
|
+
case "intersection": {
|
|
259
|
+
const intersection = schema;
|
|
260
|
+
const json = { allOf: [] };
|
|
261
|
+
let required = false;
|
|
262
|
+
for (const item of [intersection._zod.def.left, intersection._zod.def.right]) {
|
|
263
|
+
const [itemRequired, itemJson] = this.#convert(item, options, lazyDepth, structureDepth);
|
|
264
|
+
json.allOf.push(itemJson);
|
|
265
|
+
if (itemRequired) {
|
|
266
|
+
required = true;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
return [required, json];
|
|
270
|
+
}
|
|
271
|
+
case "tuple": {
|
|
272
|
+
const tuple = schema;
|
|
273
|
+
const json = { type: "array", prefixItems: [] };
|
|
274
|
+
for (const item of tuple._zod.def.items) {
|
|
275
|
+
json.prefixItems.push(
|
|
276
|
+
this.#handleArrayItemJsonSchema(
|
|
277
|
+
this.#convert(item, options, lazyDepth, structureDepth + 1),
|
|
278
|
+
options
|
|
279
|
+
)
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
if (tuple._zod.def.rest) {
|
|
283
|
+
json.items = this.#handleArrayItemJsonSchema(
|
|
284
|
+
this.#convert(tuple._zod.def.rest, options, lazyDepth, structureDepth + 1),
|
|
285
|
+
options
|
|
286
|
+
);
|
|
287
|
+
}
|
|
288
|
+
const { minimum, maximum } = tuple._zod.bag;
|
|
289
|
+
if (typeof minimum === "number") {
|
|
290
|
+
json.minItems = minimum;
|
|
291
|
+
}
|
|
292
|
+
if (typeof maximum === "number") {
|
|
293
|
+
json.maxItems = maximum;
|
|
294
|
+
}
|
|
295
|
+
return [true, json];
|
|
296
|
+
}
|
|
297
|
+
case "record": {
|
|
298
|
+
const record = schema;
|
|
299
|
+
const json = { type: "object" };
|
|
300
|
+
json.propertyNames = this.#convert(
|
|
301
|
+
record._zod.def.keyType,
|
|
302
|
+
options,
|
|
303
|
+
lazyDepth,
|
|
304
|
+
structureDepth + 1
|
|
305
|
+
)[1];
|
|
306
|
+
json.additionalProperties = this.#convert(
|
|
307
|
+
record._zod.def.valueType,
|
|
308
|
+
options,
|
|
309
|
+
lazyDepth,
|
|
310
|
+
structureDepth + 1
|
|
311
|
+
)[1];
|
|
312
|
+
return [true, json];
|
|
313
|
+
}
|
|
314
|
+
case "map": {
|
|
315
|
+
const map = schema;
|
|
316
|
+
return [
|
|
317
|
+
true,
|
|
318
|
+
{
|
|
319
|
+
type: "array",
|
|
320
|
+
items: {
|
|
321
|
+
type: "array",
|
|
322
|
+
prefixItems: [
|
|
323
|
+
this.#handleArrayItemJsonSchema(
|
|
324
|
+
this.#convert(map._zod.def.keyType, options, lazyDepth, structureDepth + 1),
|
|
325
|
+
options
|
|
326
|
+
),
|
|
327
|
+
this.#handleArrayItemJsonSchema(
|
|
328
|
+
this.#convert(map._zod.def.valueType, options, lazyDepth, structureDepth + 1),
|
|
329
|
+
options
|
|
330
|
+
)
|
|
331
|
+
],
|
|
332
|
+
maxItems: 2,
|
|
333
|
+
minItems: 2
|
|
334
|
+
},
|
|
335
|
+
"x-native-type": JsonSchemaXNativeType.Map
|
|
336
|
+
}
|
|
337
|
+
];
|
|
338
|
+
}
|
|
339
|
+
case "set": {
|
|
340
|
+
const set = schema;
|
|
341
|
+
return [
|
|
342
|
+
true,
|
|
343
|
+
{
|
|
344
|
+
type: "array",
|
|
345
|
+
uniqueItems: true,
|
|
346
|
+
items: this.#handleArrayItemJsonSchema(
|
|
347
|
+
this.#convert(set._zod.def.valueType, options, lazyDepth, structureDepth + 1),
|
|
348
|
+
options
|
|
349
|
+
),
|
|
350
|
+
"x-native-type": JsonSchemaXNativeType.Set
|
|
351
|
+
}
|
|
352
|
+
];
|
|
353
|
+
}
|
|
354
|
+
case "enum": {
|
|
355
|
+
const enum_ = schema;
|
|
356
|
+
return [true, { enum: Object.values(enum_._zod.def.entries) }];
|
|
357
|
+
}
|
|
358
|
+
case "literal": {
|
|
359
|
+
const literal = schema;
|
|
360
|
+
let required = true;
|
|
361
|
+
const values = /* @__PURE__ */ new Set();
|
|
362
|
+
for (const value of literal._zod.def.values) {
|
|
363
|
+
if (value === void 0) {
|
|
364
|
+
required = false;
|
|
365
|
+
} else {
|
|
366
|
+
values.add(typeof value === "bigint" ? value.toString() : value);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
const json = values.size === 0 ? this.undefinedJsonSchema : values.size === 1 ? { const: values.values().next().value } : { enum: Array.from(values) };
|
|
370
|
+
return [required, json];
|
|
371
|
+
}
|
|
372
|
+
case "file": {
|
|
373
|
+
const file = schema;
|
|
374
|
+
const oneOf = [];
|
|
375
|
+
const { mime } = file._zod.bag;
|
|
376
|
+
if (mime === void 0 || Array.isArray(mime) && mime.every((m) => typeof m === "string")) {
|
|
377
|
+
for (const type of mime ?? ["*/*"]) {
|
|
378
|
+
oneOf.push({
|
|
379
|
+
type: "string",
|
|
380
|
+
contentMediaType: type
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
return [true, oneOf.length === 1 ? oneOf[0] : { anyOf: oneOf }];
|
|
385
|
+
}
|
|
386
|
+
case "transform": {
|
|
387
|
+
return [false, this.anyJsonSchema];
|
|
388
|
+
}
|
|
389
|
+
case "nullable": {
|
|
390
|
+
const nullable = schema;
|
|
391
|
+
const [required, json] = this.#convert(
|
|
392
|
+
nullable._zod.def.innerType,
|
|
393
|
+
options,
|
|
394
|
+
lazyDepth,
|
|
395
|
+
structureDepth
|
|
396
|
+
);
|
|
397
|
+
return [required, { anyOf: [json, { type: "null" }] }];
|
|
398
|
+
}
|
|
399
|
+
case "nonoptional": {
|
|
400
|
+
const nonoptional = schema;
|
|
401
|
+
const [, json] = this.#convert(nonoptional._zod.def.innerType, options, lazyDepth, structureDepth);
|
|
402
|
+
return [true, json];
|
|
403
|
+
}
|
|
404
|
+
case "success": {
|
|
405
|
+
return [true, { type: "boolean" }];
|
|
406
|
+
}
|
|
407
|
+
case "default":
|
|
408
|
+
case "prefault": {
|
|
409
|
+
const default_ = schema;
|
|
410
|
+
const [, json] = this.#convert(default_._zod.def.innerType, options, lazyDepth, structureDepth);
|
|
411
|
+
return [
|
|
412
|
+
false,
|
|
413
|
+
{
|
|
414
|
+
...json,
|
|
415
|
+
default: default_._zod.def.defaultValue
|
|
416
|
+
}
|
|
417
|
+
];
|
|
418
|
+
}
|
|
419
|
+
case "catch": {
|
|
420
|
+
const catch_ = schema;
|
|
421
|
+
return this.#convert(catch_._zod.def.innerType, options, lazyDepth, structureDepth);
|
|
422
|
+
}
|
|
423
|
+
case "nan": {
|
|
424
|
+
return [true, options.strategy === "input" ? this.unsupportedJsonSchema : { type: "null" }];
|
|
425
|
+
}
|
|
426
|
+
case "pipe": {
|
|
427
|
+
const pipe = schema;
|
|
428
|
+
return this.#convert(
|
|
429
|
+
options.strategy === "input" ? pipe._zod.def.in : pipe._zod.def.out,
|
|
430
|
+
options,
|
|
431
|
+
lazyDepth,
|
|
432
|
+
structureDepth
|
|
433
|
+
);
|
|
434
|
+
}
|
|
435
|
+
case "readonly": {
|
|
436
|
+
const readonly_ = schema;
|
|
437
|
+
const [required, json] = this.#convert(
|
|
438
|
+
readonly_._zod.def.innerType,
|
|
439
|
+
options,
|
|
440
|
+
lazyDepth,
|
|
441
|
+
structureDepth
|
|
442
|
+
);
|
|
443
|
+
return [required, { ...json, readOnly: true }];
|
|
444
|
+
}
|
|
445
|
+
case "template_literal": {
|
|
446
|
+
const templateLiteral = schema;
|
|
447
|
+
return [
|
|
448
|
+
true,
|
|
449
|
+
{
|
|
450
|
+
type: "string",
|
|
451
|
+
pattern: templateLiteral._zod.pattern.source
|
|
452
|
+
}
|
|
453
|
+
];
|
|
454
|
+
}
|
|
455
|
+
case "optional": {
|
|
456
|
+
const optional = schema;
|
|
457
|
+
const [, json] = this.#convert(optional._zod.def.innerType, options, lazyDepth, structureDepth);
|
|
458
|
+
return [false, json];
|
|
459
|
+
}
|
|
460
|
+
case "lazy": {
|
|
461
|
+
const lazy = schema;
|
|
462
|
+
const currentLazyDepth = lazyDepth + 1;
|
|
463
|
+
if (currentLazyDepth > this.maxLazyDepth) {
|
|
464
|
+
return [false, this.anyJsonSchema];
|
|
465
|
+
}
|
|
466
|
+
return this.#convert(lazy._zod.def.getter(), options, currentLazyDepth, structureDepth);
|
|
467
|
+
}
|
|
468
|
+
default: {
|
|
469
|
+
schema._zod.def.type;
|
|
470
|
+
return [true, this.unsupportedJsonSchema];
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
#getCustomJsonSchema(schema, options) {
|
|
475
|
+
if (options.strategy === "input" && JSON_SCHEMA_INPUT_REGISTRY.has(schema)) {
|
|
476
|
+
return JSON_SCHEMA_INPUT_REGISTRY.get(schema);
|
|
477
|
+
}
|
|
478
|
+
if (options.strategy === "output" && JSON_SCHEMA_OUTPUT_REGISTRY.has(schema)) {
|
|
479
|
+
return JSON_SCHEMA_OUTPUT_REGISTRY.get(schema);
|
|
480
|
+
}
|
|
481
|
+
if (JSON_SCHEMA_REGISTRY.has(schema)) {
|
|
482
|
+
return JSON_SCHEMA_REGISTRY.get(schema);
|
|
483
|
+
}
|
|
484
|
+
const global = globalRegistry.get(schema);
|
|
485
|
+
if (global) {
|
|
486
|
+
return {
|
|
487
|
+
title: global.title,
|
|
488
|
+
description: global.description,
|
|
489
|
+
examples: Array.isArray(global.examples) ? global.examples : void 0
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
#handleArrayItemJsonSchema([required, schema], options) {
|
|
494
|
+
if (required || options.strategy === "input" || schema.default !== void 0) {
|
|
495
|
+
return schema;
|
|
496
|
+
}
|
|
497
|
+
if (schema === this.undefinedJsonSchema) {
|
|
498
|
+
return { type: "null" };
|
|
499
|
+
}
|
|
500
|
+
return {
|
|
501
|
+
anyOf: [
|
|
502
|
+
// schema can contain { type: 'null' } so we should use anyOf instead of oneOf
|
|
503
|
+
schema,
|
|
504
|
+
{ type: "null" }
|
|
505
|
+
]
|
|
506
|
+
};
|
|
507
|
+
}
|
|
508
|
+
#handleStringFormat(format) {
|
|
509
|
+
if (format === "guid") {
|
|
510
|
+
return JSONSchemaFormat.UUID;
|
|
511
|
+
}
|
|
512
|
+
if (format === "url") {
|
|
513
|
+
return JSONSchemaFormat.URI;
|
|
514
|
+
}
|
|
515
|
+
if (format === "datetime") {
|
|
516
|
+
return JSONSchemaFormat.DateTime;
|
|
517
|
+
}
|
|
518
|
+
return Object.values(JSONSchemaFormat).includes(format) ? format : void 0;
|
|
519
|
+
}
|
|
520
|
+
#handleContentEncoding(contentEncoding) {
|
|
521
|
+
return Object.values(JSONSchemaContentEncoding).includes(contentEncoding) ? contentEncoding : void 0;
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
export { JsonSchemaXNativeType as J, ZodToJsonSchemaConverter as Z, JSON_SCHEMA_REGISTRY as a, JSON_SCHEMA_INPUT_REGISTRY as b, JSON_SCHEMA_OUTPUT_REGISTRY as c, eventIterator as e, getEventIteratorSchemaDetails as g };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { JSONSchema, SchemaConverter } from '@temporary-name/server/openapi';
|
|
2
|
+
|
|
3
|
+
interface ZodToJsonSchemaConverterOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Max depth of lazy type.
|
|
6
|
+
*
|
|
7
|
+
* Used anyJsonSchema (`{}`) when exceed max depth
|
|
8
|
+
*
|
|
9
|
+
* @default 2
|
|
10
|
+
*/
|
|
11
|
+
maxLazyDepth?: number;
|
|
12
|
+
/**
|
|
13
|
+
* Max depth of nested types.
|
|
14
|
+
*
|
|
15
|
+
* Used anyJsonSchema (`{}`) when exceed max depth
|
|
16
|
+
*
|
|
17
|
+
* @default 10
|
|
18
|
+
*/
|
|
19
|
+
maxStructureDepth?: number;
|
|
20
|
+
/**
|
|
21
|
+
* The schema to be used to represent the any | unknown type.
|
|
22
|
+
*
|
|
23
|
+
* @default { }
|
|
24
|
+
*/
|
|
25
|
+
anyJsonSchema?: Exclude<JSONSchema, boolean>;
|
|
26
|
+
/**
|
|
27
|
+
* The schema to be used when the Zod schema is unsupported.
|
|
28
|
+
*
|
|
29
|
+
* @default { not: {} }
|
|
30
|
+
*/
|
|
31
|
+
unsupportedJsonSchema?: Exclude<JSONSchema, boolean>;
|
|
32
|
+
/**
|
|
33
|
+
* The schema to be used to represent the undefined type.
|
|
34
|
+
*
|
|
35
|
+
* @default { not: {} }
|
|
36
|
+
*/
|
|
37
|
+
undefinedJsonSchema?: Exclude<JSONSchema, boolean>;
|
|
38
|
+
}
|
|
39
|
+
declare class ZodToJsonSchemaConverter {
|
|
40
|
+
#private;
|
|
41
|
+
private readonly maxLazyDepth;
|
|
42
|
+
private readonly maxStructureDepth;
|
|
43
|
+
private readonly anyJsonSchema;
|
|
44
|
+
private readonly unsupportedJsonSchema;
|
|
45
|
+
private readonly undefinedJsonSchema;
|
|
46
|
+
constructor(options?: ZodToJsonSchemaConverterOptions);
|
|
47
|
+
convert: SchemaConverter;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export { ZodToJsonSchemaConverter as a };
|
|
51
|
+
export type { ZodToJsonSchemaConverterOptions as Z };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { JSONSchema, SchemaConverter } from '@temporary-name/server/openapi';
|
|
2
|
+
|
|
3
|
+
interface ZodToJsonSchemaConverterOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Max depth of lazy type.
|
|
6
|
+
*
|
|
7
|
+
* Used anyJsonSchema (`{}`) when exceed max depth
|
|
8
|
+
*
|
|
9
|
+
* @default 2
|
|
10
|
+
*/
|
|
11
|
+
maxLazyDepth?: number;
|
|
12
|
+
/**
|
|
13
|
+
* Max depth of nested types.
|
|
14
|
+
*
|
|
15
|
+
* Used anyJsonSchema (`{}`) when exceed max depth
|
|
16
|
+
*
|
|
17
|
+
* @default 10
|
|
18
|
+
*/
|
|
19
|
+
maxStructureDepth?: number;
|
|
20
|
+
/**
|
|
21
|
+
* The schema to be used to represent the any | unknown type.
|
|
22
|
+
*
|
|
23
|
+
* @default { }
|
|
24
|
+
*/
|
|
25
|
+
anyJsonSchema?: Exclude<JSONSchema, boolean>;
|
|
26
|
+
/**
|
|
27
|
+
* The schema to be used when the Zod schema is unsupported.
|
|
28
|
+
*
|
|
29
|
+
* @default { not: {} }
|
|
30
|
+
*/
|
|
31
|
+
unsupportedJsonSchema?: Exclude<JSONSchema, boolean>;
|
|
32
|
+
/**
|
|
33
|
+
* The schema to be used to represent the undefined type.
|
|
34
|
+
*
|
|
35
|
+
* @default { not: {} }
|
|
36
|
+
*/
|
|
37
|
+
undefinedJsonSchema?: Exclude<JSONSchema, boolean>;
|
|
38
|
+
}
|
|
39
|
+
declare class ZodToJsonSchemaConverter {
|
|
40
|
+
#private;
|
|
41
|
+
private readonly maxLazyDepth;
|
|
42
|
+
private readonly maxStructureDepth;
|
|
43
|
+
private readonly anyJsonSchema;
|
|
44
|
+
private readonly unsupportedJsonSchema;
|
|
45
|
+
private readonly undefinedJsonSchema;
|
|
46
|
+
constructor(options?: ZodToJsonSchemaConverterOptions);
|
|
47
|
+
convert: SchemaConverter;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export { ZodToJsonSchemaConverter as a };
|
|
51
|
+
export type { ZodToJsonSchemaConverterOptions as Z };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { isObject, NullProtoObj, isAsyncIteratorObject, isORPCErrorJson, createORPCErrorFromJson, toORPCError, fallbackContractConfig, stringifyJSON, isORPCErrorStatus, tryDecodeURIComponent, toHttpPath, runWithSpan, ORPC_NAME, asyncIteratorWithSpan, setSpanError, ORPCError } from '@temporary-name/shared';
|
|
2
|
-
import { c as createProcedureClient } from './server.
|
|
2
|
+
import { c as createProcedureClient } from './server.BCY45g2x.mjs';
|
|
3
3
|
import { mapEventIterator, ErrorEvent } from '@temporary-name/standard-server';
|
|
4
4
|
import { j as jsonSerialize } from './server.CQIFwyhc.mjs';
|
|
5
5
|
import { traverseContractProcedures, getLazyMeta, unlazy } from '@temporary-name/server';
|
|
6
6
|
import { createRouter, addRoute, findRoute } from 'rou3';
|
|
7
|
-
import { s as standardizeHTTPPath } from './server.
|
|
7
|
+
import { s as standardizeHTTPPath } from './server.BETu17rq.mjs';
|
|
8
8
|
|
|
9
9
|
function bracketNotationSerialize(data, segments = [], result = []) {
|
|
10
10
|
if (Array.isArray(data)) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { HTTPPath, StandardResponse, StandardLazyRequest } from '@temporary-name/shared';
|
|
2
|
-
import { C as Context,
|
|
2
|
+
import { C as Context, l as Router } from './server.zsKBRxsz.mjs';
|
|
3
3
|
|
|
4
4
|
interface StandardHandleOptions<T extends Context> {
|
|
5
5
|
prefix?: HTTPPath;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { HTTPPath, StandardResponse, StandardLazyRequest } from '@temporary-name/shared';
|
|
2
|
-
import { C as Context,
|
|
2
|
+
import { C as Context, l as Router } from './server.zsKBRxsz.js';
|
|
3
3
|
|
|
4
4
|
interface StandardHandleOptions<T extends Context> {
|
|
5
5
|
prefix?: HTTPPath;
|