@rpcbase/server 0.476.0 → 0.478.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/dist/{handler-DEEir2xV.js → handler-BOTZftAB.js} +29 -29
  2. package/dist/{handler-BITFtEr_.js → handler-B_mMDLBO.js} +80 -39
  3. package/dist/{handler-BYVnU9H-.js → handler-Cl-0-832.js} +1 -1
  4. package/dist/{handler-CHuOXAtH.js → handler-Dd20DHyz.js} +15 -11
  5. package/dist/index.d.ts +0 -1
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +102 -87
  8. package/dist/notifications/api/notifications/handler.d.ts.map +1 -1
  9. package/dist/notifications.js +1 -1
  10. package/dist/rts/api/changes/handler.d.ts.map +1 -1
  11. package/dist/rts/index.d.ts +3 -1
  12. package/dist/rts/index.d.ts.map +1 -1
  13. package/dist/{index-Ckx0UHs6.js → rts/index.js} +107 -39
  14. package/dist/{schemas-DI7ewltq.js → schemas-D5T9tDtI.js} +609 -12
  15. package/dist/{shared-Chfrv8o6.js → shared-UGuDRAKK.js} +16 -30
  16. package/dist/uploads/api/file-uploads/handlers/completeUpload.d.ts.map +1 -1
  17. package/dist/uploads/api/file-uploads/handlers/getStatus.d.ts.map +1 -1
  18. package/dist/uploads/api/file-uploads/handlers/uploadChunk.d.ts.map +1 -1
  19. package/dist/uploads/api/file-uploads/shared.d.ts +3 -0
  20. package/dist/uploads/api/file-uploads/shared.d.ts.map +1 -1
  21. package/dist/uploads.js +1 -1
  22. package/package.json +4 -4
  23. package/dist/passwordHashStorage.test.d.ts +0 -2
  24. package/dist/passwordHashStorage.test.d.ts.map +0 -1
  25. package/dist/rts/api/changes/handler.test.d.ts +0 -2
  26. package/dist/rts/api/changes/handler.test.d.ts.map +0 -1
  27. package/dist/rts/index.ws.test.d.ts +0 -2
  28. package/dist/rts/index.ws.test.d.ts.map +0 -1
  29. package/dist/rts.d.ts +0 -3
  30. package/dist/rts.d.ts.map +0 -1
  31. package/dist/rts.js +0 -13
  32. package/dist/uploads/api/files/handlers/getFile.test.d.ts +0 -2
  33. package/dist/uploads/api/files/handlers/getFile.test.d.ts.map +0 -1
@@ -108,7 +108,7 @@ function floatSafeRemainder(val, step) {
108
108
  const stepInt = Number.parseInt(step.toFixed(decCount).replace(".", ""));
109
109
  return valInt % stepInt / 10 ** decCount;
110
110
  }
111
- const EVALUATING = Symbol("evaluating");
111
+ const EVALUATING = /* @__PURE__ */ Symbol("evaluating");
112
112
  function defineLazy(object2, key, getter) {
113
113
  let value = void 0;
114
114
  Object.defineProperty(object2, key, {
@@ -1051,8 +1051,8 @@ class Doc {
1051
1051
  }
1052
1052
  const version = {
1053
1053
  major: 4,
1054
- minor: 1,
1055
- patch: 13
1054
+ minor: 2,
1055
+ patch: 1
1056
1056
  };
1057
1057
  const $ZodType = /* @__PURE__ */ $constructor("$ZodType", (inst, def) => {
1058
1058
  var _a2;
@@ -1960,15 +1960,18 @@ const $ZodRecord = /* @__PURE__ */ $constructor("$ZodRecord", (inst, def) => {
1960
1960
  throw new Error("Async schemas not supported in object keys currently");
1961
1961
  }
1962
1962
  if (keyResult.issues.length) {
1963
- payload.issues.push({
1964
- code: "invalid_key",
1965
- origin: "record",
1966
- issues: keyResult.issues.map((iss) => finalizeIssue(iss, ctx, config())),
1967
- input: key,
1968
- path: [key],
1969
- inst
1970
- });
1971
- payload.value[keyResult.value] = keyResult.value;
1963
+ if (def.mode === "loose") {
1964
+ payload.value[key] = input[key];
1965
+ } else {
1966
+ payload.issues.push({
1967
+ code: "invalid_key",
1968
+ origin: "record",
1969
+ issues: keyResult.issues.map((iss) => finalizeIssue(iss, ctx, config())),
1970
+ input: key,
1971
+ path: [key],
1972
+ inst
1973
+ });
1974
+ }
1972
1975
  continue;
1973
1976
  }
1974
1977
  const result = def.valueType._zod.run({ value: input[key], issues: [] }, ctx);
@@ -2767,6 +2770,572 @@ function _check(fn, params) {
2767
2770
  ch._zod.check = fn;
2768
2771
  return ch;
2769
2772
  }
2773
+ function initializeContext(params) {
2774
+ let target = params?.target ?? "draft-2020-12";
2775
+ if (target === "draft-4")
2776
+ target = "draft-04";
2777
+ if (target === "draft-7")
2778
+ target = "draft-07";
2779
+ return {
2780
+ processors: params.processors ?? {},
2781
+ metadataRegistry: params?.metadata ?? globalRegistry,
2782
+ target,
2783
+ unrepresentable: params?.unrepresentable ?? "throw",
2784
+ override: params?.override ?? (() => {
2785
+ }),
2786
+ io: params?.io ?? "output",
2787
+ counter: 0,
2788
+ seen: /* @__PURE__ */ new Map(),
2789
+ cycles: params?.cycles ?? "ref",
2790
+ reused: params?.reused ?? "inline",
2791
+ external: params?.external ?? void 0
2792
+ };
2793
+ }
2794
+ function process(schema, ctx, _params = { path: [], schemaPath: [] }) {
2795
+ var _a2;
2796
+ const def = schema._zod.def;
2797
+ const seen = ctx.seen.get(schema);
2798
+ if (seen) {
2799
+ seen.count++;
2800
+ const isCycle = _params.schemaPath.includes(schema);
2801
+ if (isCycle) {
2802
+ seen.cycle = _params.path;
2803
+ }
2804
+ return seen.schema;
2805
+ }
2806
+ const result = { schema: {}, count: 1, cycle: void 0, path: _params.path };
2807
+ ctx.seen.set(schema, result);
2808
+ const overrideSchema = schema._zod.toJSONSchema?.();
2809
+ if (overrideSchema) {
2810
+ result.schema = overrideSchema;
2811
+ } else {
2812
+ const params = {
2813
+ ..._params,
2814
+ schemaPath: [..._params.schemaPath, schema],
2815
+ path: _params.path
2816
+ };
2817
+ const parent = schema._zod.parent;
2818
+ if (parent) {
2819
+ result.ref = parent;
2820
+ process(parent, ctx, params);
2821
+ ctx.seen.get(parent).isParent = true;
2822
+ } else if (schema._zod.processJSONSchema) {
2823
+ schema._zod.processJSONSchema(ctx, result.schema, params);
2824
+ } else {
2825
+ const _json = result.schema;
2826
+ const processor = ctx.processors[def.type];
2827
+ if (!processor) {
2828
+ throw new Error(`[toJSONSchema]: Non-representable type encountered: ${def.type}`);
2829
+ }
2830
+ processor(schema, ctx, _json, params);
2831
+ }
2832
+ }
2833
+ const meta = ctx.metadataRegistry.get(schema);
2834
+ if (meta)
2835
+ Object.assign(result.schema, meta);
2836
+ if (ctx.io === "input" && isTransforming(schema)) {
2837
+ delete result.schema.examples;
2838
+ delete result.schema.default;
2839
+ }
2840
+ if (ctx.io === "input" && result.schema._prefault)
2841
+ (_a2 = result.schema).default ?? (_a2.default = result.schema._prefault);
2842
+ delete result.schema._prefault;
2843
+ const _result = ctx.seen.get(schema);
2844
+ return _result.schema;
2845
+ }
2846
+ function extractDefs(ctx, schema) {
2847
+ const root = ctx.seen.get(schema);
2848
+ if (!root)
2849
+ throw new Error("Unprocessed schema. This is a bug in Zod.");
2850
+ const makeURI = (entry) => {
2851
+ const defsSegment = ctx.target === "draft-2020-12" ? "$defs" : "definitions";
2852
+ if (ctx.external) {
2853
+ const externalId = ctx.external.registry.get(entry[0])?.id;
2854
+ const uriGenerator = ctx.external.uri ?? ((id2) => id2);
2855
+ if (externalId) {
2856
+ return { ref: uriGenerator(externalId) };
2857
+ }
2858
+ const id = entry[1].defId ?? entry[1].schema.id ?? `schema${ctx.counter++}`;
2859
+ entry[1].defId = id;
2860
+ return { defId: id, ref: `${uriGenerator("__shared")}#/${defsSegment}/${id}` };
2861
+ }
2862
+ if (entry[1] === root) {
2863
+ return { ref: "#" };
2864
+ }
2865
+ const uriPrefix = `#`;
2866
+ const defUriPrefix = `${uriPrefix}/${defsSegment}/`;
2867
+ const defId = entry[1].schema.id ?? `__schema${ctx.counter++}`;
2868
+ return { defId, ref: defUriPrefix + defId };
2869
+ };
2870
+ const extractToDef = (entry) => {
2871
+ if (entry[1].schema.$ref) {
2872
+ return;
2873
+ }
2874
+ const seen = entry[1];
2875
+ const { ref, defId } = makeURI(entry);
2876
+ seen.def = { ...seen.schema };
2877
+ if (defId)
2878
+ seen.defId = defId;
2879
+ const schema2 = seen.schema;
2880
+ for (const key in schema2) {
2881
+ delete schema2[key];
2882
+ }
2883
+ schema2.$ref = ref;
2884
+ };
2885
+ if (ctx.cycles === "throw") {
2886
+ for (const entry of ctx.seen.entries()) {
2887
+ const seen = entry[1];
2888
+ if (seen.cycle) {
2889
+ throw new Error(`Cycle detected: #/${seen.cycle?.join("/")}/<root>
2890
+
2891
+ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`);
2892
+ }
2893
+ }
2894
+ }
2895
+ for (const entry of ctx.seen.entries()) {
2896
+ const seen = entry[1];
2897
+ if (schema === entry[0]) {
2898
+ extractToDef(entry);
2899
+ continue;
2900
+ }
2901
+ if (ctx.external) {
2902
+ const ext = ctx.external.registry.get(entry[0])?.id;
2903
+ if (schema !== entry[0] && ext) {
2904
+ extractToDef(entry);
2905
+ continue;
2906
+ }
2907
+ }
2908
+ const id = ctx.metadataRegistry.get(entry[0])?.id;
2909
+ if (id) {
2910
+ extractToDef(entry);
2911
+ continue;
2912
+ }
2913
+ if (seen.cycle) {
2914
+ extractToDef(entry);
2915
+ continue;
2916
+ }
2917
+ if (seen.count > 1) {
2918
+ if (ctx.reused === "ref") {
2919
+ extractToDef(entry);
2920
+ continue;
2921
+ }
2922
+ }
2923
+ }
2924
+ }
2925
+ function finalize(ctx, schema) {
2926
+ const root = ctx.seen.get(schema);
2927
+ if (!root)
2928
+ throw new Error("Unprocessed schema. This is a bug in Zod.");
2929
+ const flattenRef = (zodSchema) => {
2930
+ const seen = ctx.seen.get(zodSchema);
2931
+ const schema2 = seen.def ?? seen.schema;
2932
+ const _cached = { ...schema2 };
2933
+ if (seen.ref === null) {
2934
+ return;
2935
+ }
2936
+ const ref = seen.ref;
2937
+ seen.ref = null;
2938
+ if (ref) {
2939
+ flattenRef(ref);
2940
+ const refSchema = ctx.seen.get(ref).schema;
2941
+ if (refSchema.$ref && (ctx.target === "draft-07" || ctx.target === "draft-04" || ctx.target === "openapi-3.0")) {
2942
+ schema2.allOf = schema2.allOf ?? [];
2943
+ schema2.allOf.push(refSchema);
2944
+ } else {
2945
+ Object.assign(schema2, refSchema);
2946
+ Object.assign(schema2, _cached);
2947
+ }
2948
+ }
2949
+ if (!seen.isParent)
2950
+ ctx.override({
2951
+ zodSchema,
2952
+ jsonSchema: schema2,
2953
+ path: seen.path ?? []
2954
+ });
2955
+ };
2956
+ for (const entry of [...ctx.seen.entries()].reverse()) {
2957
+ flattenRef(entry[0]);
2958
+ }
2959
+ const result = {};
2960
+ if (ctx.target === "draft-2020-12") {
2961
+ result.$schema = "https://json-schema.org/draft/2020-12/schema";
2962
+ } else if (ctx.target === "draft-07") {
2963
+ result.$schema = "http://json-schema.org/draft-07/schema#";
2964
+ } else if (ctx.target === "draft-04") {
2965
+ result.$schema = "http://json-schema.org/draft-04/schema#";
2966
+ } else if (ctx.target === "openapi-3.0") ;
2967
+ else ;
2968
+ if (ctx.external?.uri) {
2969
+ const id = ctx.external.registry.get(schema)?.id;
2970
+ if (!id)
2971
+ throw new Error("Schema is missing an `id` property");
2972
+ result.$id = ctx.external.uri(id);
2973
+ }
2974
+ Object.assign(result, root.def ?? root.schema);
2975
+ const defs = ctx.external?.defs ?? {};
2976
+ for (const entry of ctx.seen.entries()) {
2977
+ const seen = entry[1];
2978
+ if (seen.def && seen.defId) {
2979
+ defs[seen.defId] = seen.def;
2980
+ }
2981
+ }
2982
+ if (ctx.external) ;
2983
+ else {
2984
+ if (Object.keys(defs).length > 0) {
2985
+ if (ctx.target === "draft-2020-12") {
2986
+ result.$defs = defs;
2987
+ } else {
2988
+ result.definitions = defs;
2989
+ }
2990
+ }
2991
+ }
2992
+ try {
2993
+ const finalized = JSON.parse(JSON.stringify(result));
2994
+ Object.defineProperty(finalized, "~standard", {
2995
+ value: {
2996
+ ...schema["~standard"],
2997
+ jsonSchema: {
2998
+ input: createStandardJSONSchemaMethod(schema, "input"),
2999
+ output: createStandardJSONSchemaMethod(schema, "output")
3000
+ }
3001
+ },
3002
+ enumerable: false,
3003
+ writable: false
3004
+ });
3005
+ return finalized;
3006
+ } catch (_err) {
3007
+ throw new Error("Error converting schema to JSON.");
3008
+ }
3009
+ }
3010
+ function isTransforming(_schema, _ctx) {
3011
+ const ctx = _ctx ?? { seen: /* @__PURE__ */ new Set() };
3012
+ if (ctx.seen.has(_schema))
3013
+ return false;
3014
+ ctx.seen.add(_schema);
3015
+ const def = _schema._zod.def;
3016
+ if (def.type === "transform")
3017
+ return true;
3018
+ if (def.type === "array")
3019
+ return isTransforming(def.element, ctx);
3020
+ if (def.type === "set")
3021
+ return isTransforming(def.valueType, ctx);
3022
+ if (def.type === "lazy")
3023
+ return isTransforming(def.getter(), ctx);
3024
+ if (def.type === "promise" || def.type === "optional" || def.type === "nonoptional" || def.type === "nullable" || def.type === "readonly" || def.type === "default" || def.type === "prefault") {
3025
+ return isTransforming(def.innerType, ctx);
3026
+ }
3027
+ if (def.type === "intersection") {
3028
+ return isTransforming(def.left, ctx) || isTransforming(def.right, ctx);
3029
+ }
3030
+ if (def.type === "record" || def.type === "map") {
3031
+ return isTransforming(def.keyType, ctx) || isTransforming(def.valueType, ctx);
3032
+ }
3033
+ if (def.type === "pipe") {
3034
+ return isTransforming(def.in, ctx) || isTransforming(def.out, ctx);
3035
+ }
3036
+ if (def.type === "object") {
3037
+ for (const key in def.shape) {
3038
+ if (isTransforming(def.shape[key], ctx))
3039
+ return true;
3040
+ }
3041
+ return false;
3042
+ }
3043
+ if (def.type === "union") {
3044
+ for (const option of def.options) {
3045
+ if (isTransforming(option, ctx))
3046
+ return true;
3047
+ }
3048
+ return false;
3049
+ }
3050
+ if (def.type === "tuple") {
3051
+ for (const item of def.items) {
3052
+ if (isTransforming(item, ctx))
3053
+ return true;
3054
+ }
3055
+ if (def.rest && isTransforming(def.rest, ctx))
3056
+ return true;
3057
+ return false;
3058
+ }
3059
+ return false;
3060
+ }
3061
+ const createToJSONSchemaMethod = (schema, processors = {}) => (params) => {
3062
+ const ctx = initializeContext({ ...params, processors });
3063
+ process(schema, ctx);
3064
+ extractDefs(ctx, schema);
3065
+ return finalize(ctx, schema);
3066
+ };
3067
+ const createStandardJSONSchemaMethod = (schema, io) => (params) => {
3068
+ const { libraryOptions, target } = params ?? {};
3069
+ const ctx = initializeContext({ ...libraryOptions ?? {}, target, io, processors: {} });
3070
+ process(schema, ctx);
3071
+ extractDefs(ctx, schema);
3072
+ return finalize(ctx, schema);
3073
+ };
3074
+ const formatMap = {
3075
+ guid: "uuid",
3076
+ url: "uri",
3077
+ datetime: "date-time",
3078
+ json_string: "json-string",
3079
+ regex: ""
3080
+ // do not set
3081
+ };
3082
+ const stringProcessor = (schema, ctx, _json, _params) => {
3083
+ const json = _json;
3084
+ json.type = "string";
3085
+ const { minimum, maximum, format, patterns, contentEncoding } = schema._zod.bag;
3086
+ if (typeof minimum === "number")
3087
+ json.minLength = minimum;
3088
+ if (typeof maximum === "number")
3089
+ json.maxLength = maximum;
3090
+ if (format) {
3091
+ json.format = formatMap[format] ?? format;
3092
+ if (json.format === "")
3093
+ delete json.format;
3094
+ }
3095
+ if (contentEncoding)
3096
+ json.contentEncoding = contentEncoding;
3097
+ if (patterns && patterns.size > 0) {
3098
+ const regexes = [...patterns];
3099
+ if (regexes.length === 1)
3100
+ json.pattern = regexes[0].source;
3101
+ else if (regexes.length > 1) {
3102
+ json.allOf = [
3103
+ ...regexes.map((regex) => ({
3104
+ ...ctx.target === "draft-07" || ctx.target === "draft-04" || ctx.target === "openapi-3.0" ? { type: "string" } : {},
3105
+ pattern: regex.source
3106
+ }))
3107
+ ];
3108
+ }
3109
+ }
3110
+ };
3111
+ const numberProcessor = (schema, ctx, _json, _params) => {
3112
+ const json = _json;
3113
+ const { minimum, maximum, format, multipleOf, exclusiveMaximum, exclusiveMinimum } = schema._zod.bag;
3114
+ if (typeof format === "string" && format.includes("int"))
3115
+ json.type = "integer";
3116
+ else
3117
+ json.type = "number";
3118
+ if (typeof exclusiveMinimum === "number") {
3119
+ if (ctx.target === "draft-04" || ctx.target === "openapi-3.0") {
3120
+ json.minimum = exclusiveMinimum;
3121
+ json.exclusiveMinimum = true;
3122
+ } else {
3123
+ json.exclusiveMinimum = exclusiveMinimum;
3124
+ }
3125
+ }
3126
+ if (typeof minimum === "number") {
3127
+ json.minimum = minimum;
3128
+ if (typeof exclusiveMinimum === "number" && ctx.target !== "draft-04") {
3129
+ if (exclusiveMinimum >= minimum)
3130
+ delete json.minimum;
3131
+ else
3132
+ delete json.exclusiveMinimum;
3133
+ }
3134
+ }
3135
+ if (typeof exclusiveMaximum === "number") {
3136
+ if (ctx.target === "draft-04" || ctx.target === "openapi-3.0") {
3137
+ json.maximum = exclusiveMaximum;
3138
+ json.exclusiveMaximum = true;
3139
+ } else {
3140
+ json.exclusiveMaximum = exclusiveMaximum;
3141
+ }
3142
+ }
3143
+ if (typeof maximum === "number") {
3144
+ json.maximum = maximum;
3145
+ if (typeof exclusiveMaximum === "number" && ctx.target !== "draft-04") {
3146
+ if (exclusiveMaximum <= maximum)
3147
+ delete json.maximum;
3148
+ else
3149
+ delete json.exclusiveMaximum;
3150
+ }
3151
+ }
3152
+ if (typeof multipleOf === "number")
3153
+ json.multipleOf = multipleOf;
3154
+ };
3155
+ const booleanProcessor = (_schema, _ctx, json, _params) => {
3156
+ json.type = "boolean";
3157
+ };
3158
+ const neverProcessor = (_schema, _ctx, json, _params) => {
3159
+ json.not = {};
3160
+ };
3161
+ const unknownProcessor = (_schema, _ctx, _json, _params) => {
3162
+ };
3163
+ const enumProcessor = (schema, _ctx, json, _params) => {
3164
+ const def = schema._zod.def;
3165
+ const values = getEnumValues(def.entries);
3166
+ if (values.every((v) => typeof v === "number"))
3167
+ json.type = "number";
3168
+ if (values.every((v) => typeof v === "string"))
3169
+ json.type = "string";
3170
+ json.enum = values;
3171
+ };
3172
+ const customProcessor = (_schema, ctx, _json, _params) => {
3173
+ if (ctx.unrepresentable === "throw") {
3174
+ throw new Error("Custom types cannot be represented in JSON Schema");
3175
+ }
3176
+ };
3177
+ const transformProcessor = (_schema, ctx, _json, _params) => {
3178
+ if (ctx.unrepresentable === "throw") {
3179
+ throw new Error("Transforms cannot be represented in JSON Schema");
3180
+ }
3181
+ };
3182
+ const arrayProcessor = (schema, ctx, _json, params) => {
3183
+ const json = _json;
3184
+ const def = schema._zod.def;
3185
+ const { minimum, maximum } = schema._zod.bag;
3186
+ if (typeof minimum === "number")
3187
+ json.minItems = minimum;
3188
+ if (typeof maximum === "number")
3189
+ json.maxItems = maximum;
3190
+ json.type = "array";
3191
+ json.items = process(def.element, ctx, { ...params, path: [...params.path, "items"] });
3192
+ };
3193
+ const objectProcessor = (schema, ctx, _json, params) => {
3194
+ const json = _json;
3195
+ const def = schema._zod.def;
3196
+ json.type = "object";
3197
+ json.properties = {};
3198
+ const shape = def.shape;
3199
+ for (const key in shape) {
3200
+ json.properties[key] = process(shape[key], ctx, {
3201
+ ...params,
3202
+ path: [...params.path, "properties", key]
3203
+ });
3204
+ }
3205
+ const allKeys = new Set(Object.keys(shape));
3206
+ const requiredKeys = new Set([...allKeys].filter((key) => {
3207
+ const v = def.shape[key]._zod;
3208
+ if (ctx.io === "input") {
3209
+ return v.optin === void 0;
3210
+ } else {
3211
+ return v.optout === void 0;
3212
+ }
3213
+ }));
3214
+ if (requiredKeys.size > 0) {
3215
+ json.required = Array.from(requiredKeys);
3216
+ }
3217
+ if (def.catchall?._zod.def.type === "never") {
3218
+ json.additionalProperties = false;
3219
+ } else if (!def.catchall) {
3220
+ if (ctx.io === "output")
3221
+ json.additionalProperties = false;
3222
+ } else if (def.catchall) {
3223
+ json.additionalProperties = process(def.catchall, ctx, {
3224
+ ...params,
3225
+ path: [...params.path, "additionalProperties"]
3226
+ });
3227
+ }
3228
+ };
3229
+ const unionProcessor = (schema, ctx, json, params) => {
3230
+ const def = schema._zod.def;
3231
+ const isExclusive = def.inclusive === false;
3232
+ const options = def.options.map((x, i) => process(x, ctx, {
3233
+ ...params,
3234
+ path: [...params.path, isExclusive ? "oneOf" : "anyOf", i]
3235
+ }));
3236
+ if (isExclusive) {
3237
+ json.oneOf = options;
3238
+ } else {
3239
+ json.anyOf = options;
3240
+ }
3241
+ };
3242
+ const intersectionProcessor = (schema, ctx, json, params) => {
3243
+ const def = schema._zod.def;
3244
+ const a = process(def.left, ctx, {
3245
+ ...params,
3246
+ path: [...params.path, "allOf", 0]
3247
+ });
3248
+ const b = process(def.right, ctx, {
3249
+ ...params,
3250
+ path: [...params.path, "allOf", 1]
3251
+ });
3252
+ const isSimpleIntersection = (val) => "allOf" in val && Object.keys(val).length === 1;
3253
+ const allOf = [
3254
+ ...isSimpleIntersection(a) ? a.allOf : [a],
3255
+ ...isSimpleIntersection(b) ? b.allOf : [b]
3256
+ ];
3257
+ json.allOf = allOf;
3258
+ };
3259
+ const recordProcessor = (schema, ctx, _json, params) => {
3260
+ const json = _json;
3261
+ const def = schema._zod.def;
3262
+ json.type = "object";
3263
+ if (ctx.target === "draft-07" || ctx.target === "draft-2020-12") {
3264
+ json.propertyNames = process(def.keyType, ctx, {
3265
+ ...params,
3266
+ path: [...params.path, "propertyNames"]
3267
+ });
3268
+ }
3269
+ json.additionalProperties = process(def.valueType, ctx, {
3270
+ ...params,
3271
+ path: [...params.path, "additionalProperties"]
3272
+ });
3273
+ };
3274
+ const nullableProcessor = (schema, ctx, json, params) => {
3275
+ const def = schema._zod.def;
3276
+ const inner = process(def.innerType, ctx, params);
3277
+ const seen = ctx.seen.get(schema);
3278
+ if (ctx.target === "openapi-3.0") {
3279
+ seen.ref = def.innerType;
3280
+ json.nullable = true;
3281
+ } else {
3282
+ json.anyOf = [inner, { type: "null" }];
3283
+ }
3284
+ };
3285
+ const nonoptionalProcessor = (schema, ctx, _json, params) => {
3286
+ const def = schema._zod.def;
3287
+ process(def.innerType, ctx, params);
3288
+ const seen = ctx.seen.get(schema);
3289
+ seen.ref = def.innerType;
3290
+ };
3291
+ const defaultProcessor = (schema, ctx, json, params) => {
3292
+ const def = schema._zod.def;
3293
+ process(def.innerType, ctx, params);
3294
+ const seen = ctx.seen.get(schema);
3295
+ seen.ref = def.innerType;
3296
+ json.default = JSON.parse(JSON.stringify(def.defaultValue));
3297
+ };
3298
+ const prefaultProcessor = (schema, ctx, json, params) => {
3299
+ const def = schema._zod.def;
3300
+ process(def.innerType, ctx, params);
3301
+ const seen = ctx.seen.get(schema);
3302
+ seen.ref = def.innerType;
3303
+ if (ctx.io === "input")
3304
+ json._prefault = JSON.parse(JSON.stringify(def.defaultValue));
3305
+ };
3306
+ const catchProcessor = (schema, ctx, json, params) => {
3307
+ const def = schema._zod.def;
3308
+ process(def.innerType, ctx, params);
3309
+ const seen = ctx.seen.get(schema);
3310
+ seen.ref = def.innerType;
3311
+ let catchValue;
3312
+ try {
3313
+ catchValue = def.catchValue(void 0);
3314
+ } catch {
3315
+ throw new Error("Dynamic catch values are not supported in JSON Schema");
3316
+ }
3317
+ json.default = catchValue;
3318
+ };
3319
+ const pipeProcessor = (schema, ctx, _json, params) => {
3320
+ const def = schema._zod.def;
3321
+ const innerType = ctx.io === "input" ? def.in._zod.def.type === "transform" ? def.out : def.in : def.out;
3322
+ process(innerType, ctx, params);
3323
+ const seen = ctx.seen.get(schema);
3324
+ seen.ref = innerType;
3325
+ };
3326
+ const readonlyProcessor = (schema, ctx, json, params) => {
3327
+ const def = schema._zod.def;
3328
+ process(def.innerType, ctx, params);
3329
+ const seen = ctx.seen.get(schema);
3330
+ seen.ref = def.innerType;
3331
+ json.readOnly = true;
3332
+ };
3333
+ const optionalProcessor = (schema, ctx, _json, params) => {
3334
+ const def = schema._zod.def;
3335
+ process(def.innerType, ctx, params);
3336
+ const seen = ctx.seen.get(schema);
3337
+ seen.ref = def.innerType;
3338
+ };
2770
3339
  const ZodISODateTime = /* @__PURE__ */ $constructor("ZodISODateTime", (inst, def) => {
2771
3340
  $ZodISODateTime.init(inst, def);
2772
3341
  ZodStringFormat.init(inst, def);
@@ -2846,6 +3415,13 @@ const safeEncodeAsync = /* @__PURE__ */ _safeEncodeAsync(ZodRealError);
2846
3415
  const safeDecodeAsync = /* @__PURE__ */ _safeDecodeAsync(ZodRealError);
2847
3416
  const ZodType = /* @__PURE__ */ $constructor("ZodType", (inst, def) => {
2848
3417
  $ZodType.init(inst, def);
3418
+ Object.assign(inst["~standard"], {
3419
+ jsonSchema: {
3420
+ input: createStandardJSONSchemaMethod(inst, "input"),
3421
+ output: createStandardJSONSchemaMethod(inst, "output")
3422
+ }
3423
+ });
3424
+ inst.toJSONSchema = createToJSONSchemaMethod(inst, {});
2849
3425
  inst.def = def;
2850
3426
  inst.type = def.type;
2851
3427
  Object.defineProperty(inst, "_def", { value: def });
@@ -2918,6 +3494,7 @@ const ZodType = /* @__PURE__ */ $constructor("ZodType", (inst, def) => {
2918
3494
  const _ZodString = /* @__PURE__ */ $constructor("_ZodString", (inst, def) => {
2919
3495
  $ZodString.init(inst, def);
2920
3496
  ZodType.init(inst, def);
3497
+ inst._zod.processJSONSchema = (ctx, json, params) => stringProcessor(inst, ctx, json);
2921
3498
  const bag = inst._zod.bag;
2922
3499
  inst.format = bag.format ?? null;
2923
3500
  inst.minLength = bag.minimum ?? null;
@@ -3055,6 +3632,7 @@ const ZodJWT = /* @__PURE__ */ $constructor("ZodJWT", (inst, def) => {
3055
3632
  const ZodNumber = /* @__PURE__ */ $constructor("ZodNumber", (inst, def) => {
3056
3633
  $ZodNumber.init(inst, def);
3057
3634
  ZodType.init(inst, def);
3635
+ inst._zod.processJSONSchema = (ctx, json, params) => numberProcessor(inst, ctx, json);
3058
3636
  inst.gt = (value, params) => inst.check(_gt(value, params));
3059
3637
  inst.gte = (value, params) => inst.check(_gte(value, params));
3060
3638
  inst.min = (value, params) => inst.check(_gte(value, params));
@@ -3090,6 +3668,7 @@ function int(params) {
3090
3668
  const ZodBoolean = /* @__PURE__ */ $constructor("ZodBoolean", (inst, def) => {
3091
3669
  $ZodBoolean.init(inst, def);
3092
3670
  ZodType.init(inst, def);
3671
+ inst._zod.processJSONSchema = (ctx, json, params) => booleanProcessor(inst, ctx, json);
3093
3672
  });
3094
3673
  function boolean(params) {
3095
3674
  return _boolean(ZodBoolean, params);
@@ -3097,6 +3676,7 @@ function boolean(params) {
3097
3676
  const ZodUnknown = /* @__PURE__ */ $constructor("ZodUnknown", (inst, def) => {
3098
3677
  $ZodUnknown.init(inst, def);
3099
3678
  ZodType.init(inst, def);
3679
+ inst._zod.processJSONSchema = (ctx, json, params) => unknownProcessor();
3100
3680
  });
3101
3681
  function unknown() {
3102
3682
  return _unknown(ZodUnknown);
@@ -3104,6 +3684,7 @@ function unknown() {
3104
3684
  const ZodNever = /* @__PURE__ */ $constructor("ZodNever", (inst, def) => {
3105
3685
  $ZodNever.init(inst, def);
3106
3686
  ZodType.init(inst, def);
3687
+ inst._zod.processJSONSchema = (ctx, json, params) => neverProcessor(inst, ctx, json);
3107
3688
  });
3108
3689
  function never(params) {
3109
3690
  return _never(ZodNever, params);
@@ -3111,6 +3692,7 @@ function never(params) {
3111
3692
  const ZodArray = /* @__PURE__ */ $constructor("ZodArray", (inst, def) => {
3112
3693
  $ZodArray.init(inst, def);
3113
3694
  ZodType.init(inst, def);
3695
+ inst._zod.processJSONSchema = (ctx, json, params) => arrayProcessor(inst, ctx, json, params);
3114
3696
  inst.element = def.element;
3115
3697
  inst.min = (minLength, params) => inst.check(_minLength(minLength, params));
3116
3698
  inst.nonempty = (params) => inst.check(_minLength(1, params));
@@ -3124,6 +3706,7 @@ function array(element, params) {
3124
3706
  const ZodObject = /* @__PURE__ */ $constructor("ZodObject", (inst, def) => {
3125
3707
  $ZodObjectJIT.init(inst, def);
3126
3708
  ZodType.init(inst, def);
3709
+ inst._zod.processJSONSchema = (ctx, json, params) => objectProcessor(inst, ctx, json, params);
3127
3710
  defineLazy(inst, "shape", () => {
3128
3711
  return def.shape;
3129
3712
  });
@@ -3156,6 +3739,7 @@ function object(shape, params) {
3156
3739
  const ZodUnion = /* @__PURE__ */ $constructor("ZodUnion", (inst, def) => {
3157
3740
  $ZodUnion.init(inst, def);
3158
3741
  ZodType.init(inst, def);
3742
+ inst._zod.processJSONSchema = (ctx, json, params) => unionProcessor(inst, ctx, json, params);
3159
3743
  inst.options = def.options;
3160
3744
  });
3161
3745
  function union(options, params) {
@@ -3168,6 +3752,7 @@ function union(options, params) {
3168
3752
  const ZodIntersection = /* @__PURE__ */ $constructor("ZodIntersection", (inst, def) => {
3169
3753
  $ZodIntersection.init(inst, def);
3170
3754
  ZodType.init(inst, def);
3755
+ inst._zod.processJSONSchema = (ctx, json, params) => intersectionProcessor(inst, ctx, json, params);
3171
3756
  });
3172
3757
  function intersection(left, right) {
3173
3758
  return new ZodIntersection({
@@ -3179,6 +3764,7 @@ function intersection(left, right) {
3179
3764
  const ZodRecord = /* @__PURE__ */ $constructor("ZodRecord", (inst, def) => {
3180
3765
  $ZodRecord.init(inst, def);
3181
3766
  ZodType.init(inst, def);
3767
+ inst._zod.processJSONSchema = (ctx, json, params) => recordProcessor(inst, ctx, json, params);
3182
3768
  inst.keyType = def.keyType;
3183
3769
  inst.valueType = def.valueType;
3184
3770
  });
@@ -3193,6 +3779,7 @@ function record(keyType, valueType, params) {
3193
3779
  const ZodEnum = /* @__PURE__ */ $constructor("ZodEnum", (inst, def) => {
3194
3780
  $ZodEnum.init(inst, def);
3195
3781
  ZodType.init(inst, def);
3782
+ inst._zod.processJSONSchema = (ctx, json, params) => enumProcessor(inst, ctx, json);
3196
3783
  inst.enum = def.entries;
3197
3784
  inst.options = Object.values(def.entries);
3198
3785
  const keys = new Set(Object.keys(def.entries));
@@ -3238,6 +3825,7 @@ function _enum(values, params) {
3238
3825
  const ZodTransform = /* @__PURE__ */ $constructor("ZodTransform", (inst, def) => {
3239
3826
  $ZodTransform.init(inst, def);
3240
3827
  ZodType.init(inst, def);
3828
+ inst._zod.processJSONSchema = (ctx, json, params) => transformProcessor(inst, ctx);
3241
3829
  inst._zod.parse = (payload, _ctx) => {
3242
3830
  if (_ctx.direction === "backward") {
3243
3831
  throw new $ZodEncodeError(inst.constructor.name);
@@ -3275,6 +3863,7 @@ function transform(fn) {
3275
3863
  const ZodOptional = /* @__PURE__ */ $constructor("ZodOptional", (inst, def) => {
3276
3864
  $ZodOptional.init(inst, def);
3277
3865
  ZodType.init(inst, def);
3866
+ inst._zod.processJSONSchema = (ctx, json, params) => optionalProcessor(inst, ctx, json, params);
3278
3867
  inst.unwrap = () => inst._zod.def.innerType;
3279
3868
  });
3280
3869
  function optional(innerType) {
@@ -3286,6 +3875,7 @@ function optional(innerType) {
3286
3875
  const ZodNullable = /* @__PURE__ */ $constructor("ZodNullable", (inst, def) => {
3287
3876
  $ZodNullable.init(inst, def);
3288
3877
  ZodType.init(inst, def);
3878
+ inst._zod.processJSONSchema = (ctx, json, params) => nullableProcessor(inst, ctx, json, params);
3289
3879
  inst.unwrap = () => inst._zod.def.innerType;
3290
3880
  });
3291
3881
  function nullable(innerType) {
@@ -3297,6 +3887,7 @@ function nullable(innerType) {
3297
3887
  const ZodDefault = /* @__PURE__ */ $constructor("ZodDefault", (inst, def) => {
3298
3888
  $ZodDefault.init(inst, def);
3299
3889
  ZodType.init(inst, def);
3890
+ inst._zod.processJSONSchema = (ctx, json, params) => defaultProcessor(inst, ctx, json, params);
3300
3891
  inst.unwrap = () => inst._zod.def.innerType;
3301
3892
  inst.removeDefault = inst.unwrap;
3302
3893
  });
@@ -3312,6 +3903,7 @@ function _default(innerType, defaultValue) {
3312
3903
  const ZodPrefault = /* @__PURE__ */ $constructor("ZodPrefault", (inst, def) => {
3313
3904
  $ZodPrefault.init(inst, def);
3314
3905
  ZodType.init(inst, def);
3906
+ inst._zod.processJSONSchema = (ctx, json, params) => prefaultProcessor(inst, ctx, json, params);
3315
3907
  inst.unwrap = () => inst._zod.def.innerType;
3316
3908
  });
3317
3909
  function prefault(innerType, defaultValue) {
@@ -3326,6 +3918,7 @@ function prefault(innerType, defaultValue) {
3326
3918
  const ZodNonOptional = /* @__PURE__ */ $constructor("ZodNonOptional", (inst, def) => {
3327
3919
  $ZodNonOptional.init(inst, def);
3328
3920
  ZodType.init(inst, def);
3921
+ inst._zod.processJSONSchema = (ctx, json, params) => nonoptionalProcessor(inst, ctx, json, params);
3329
3922
  inst.unwrap = () => inst._zod.def.innerType;
3330
3923
  });
3331
3924
  function nonoptional(innerType, params) {
@@ -3338,6 +3931,7 @@ function nonoptional(innerType, params) {
3338
3931
  const ZodCatch = /* @__PURE__ */ $constructor("ZodCatch", (inst, def) => {
3339
3932
  $ZodCatch.init(inst, def);
3340
3933
  ZodType.init(inst, def);
3934
+ inst._zod.processJSONSchema = (ctx, json, params) => catchProcessor(inst, ctx, json, params);
3341
3935
  inst.unwrap = () => inst._zod.def.innerType;
3342
3936
  inst.removeCatch = inst.unwrap;
3343
3937
  });
@@ -3351,6 +3945,7 @@ function _catch(innerType, catchValue) {
3351
3945
  const ZodPipe = /* @__PURE__ */ $constructor("ZodPipe", (inst, def) => {
3352
3946
  $ZodPipe.init(inst, def);
3353
3947
  ZodType.init(inst, def);
3948
+ inst._zod.processJSONSchema = (ctx, json, params) => pipeProcessor(inst, ctx, json, params);
3354
3949
  inst.in = def.in;
3355
3950
  inst.out = def.out;
3356
3951
  });
@@ -3365,6 +3960,7 @@ function pipe(in_, out) {
3365
3960
  const ZodReadonly = /* @__PURE__ */ $constructor("ZodReadonly", (inst, def) => {
3366
3961
  $ZodReadonly.init(inst, def);
3367
3962
  ZodType.init(inst, def);
3963
+ inst._zod.processJSONSchema = (ctx, json, params) => readonlyProcessor(inst, ctx, json, params);
3368
3964
  inst.unwrap = () => inst._zod.def.innerType;
3369
3965
  });
3370
3966
  function readonly(innerType) {
@@ -3376,6 +3972,7 @@ function readonly(innerType) {
3376
3972
  const ZodCustom = /* @__PURE__ */ $constructor("ZodCustom", (inst, def) => {
3377
3973
  $ZodCustom.init(inst, def);
3378
3974
  ZodType.init(inst, def);
3975
+ inst._zod.processJSONSchema = (ctx, json, params) => customProcessor(inst, ctx);
3379
3976
  });
3380
3977
  function refine(fn, _params = {}) {
3381
3978
  return _refine(ZodCustom, fn, _params);