@rpcbase/server 0.475.0 → 0.477.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 (47) hide show
  1. package/dist/email-DEw8keax.js +8041 -0
  2. package/dist/{handler-xi0XKR-Y.js → handler-BOTZftAB.js} +29 -29
  3. package/dist/handler-B_mMDLBO.js +437 -0
  4. package/dist/{handler-BYVnU9H-.js → handler-Cl-0-832.js} +1 -1
  5. package/dist/{handler-CTL2iQCj.js → handler-Dd20DHyz.js} +15 -11
  6. package/dist/index.d.ts +0 -1
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +169 -8191
  9. package/dist/notifications/api/notifications/handler.d.ts +4 -0
  10. package/dist/notifications/api/notifications/handler.d.ts.map +1 -0
  11. package/dist/notifications/api/notifications/index.d.ts +168 -0
  12. package/dist/notifications/api/notifications/index.d.ts.map +1 -0
  13. package/dist/notifications/api/notifications/shared.d.ts +6 -0
  14. package/dist/notifications/api/notifications/shared.d.ts.map +1 -0
  15. package/dist/notifications/createNotification.d.ts +13 -0
  16. package/dist/notifications/createNotification.d.ts.map +1 -0
  17. package/dist/notifications/digest.d.ts +13 -0
  18. package/dist/notifications/digest.d.ts.map +1 -0
  19. package/dist/notifications/routes.d.ts +2 -0
  20. package/dist/notifications/routes.d.ts.map +1 -0
  21. package/dist/notifications.d.ts +4 -0
  22. package/dist/notifications.d.ts.map +1 -0
  23. package/dist/notifications.js +126 -0
  24. package/dist/rts/api/changes/handler.d.ts.map +1 -1
  25. package/dist/rts/index.d.ts +3 -1
  26. package/dist/rts/index.d.ts.map +1 -1
  27. package/dist/{index-Ckx0UHs6.js → rts/index.js} +99 -32
  28. package/dist/{schemas-CyxqObur.js → schemas-D5T9tDtI.js} +712 -4
  29. package/dist/{shared-Chfrv8o6.js → shared-UGuDRAKK.js} +16 -30
  30. package/dist/uploads/api/file-uploads/handlers/completeUpload.d.ts.map +1 -1
  31. package/dist/uploads/api/file-uploads/handlers/getStatus.d.ts.map +1 -1
  32. package/dist/uploads/api/file-uploads/handlers/uploadChunk.d.ts.map +1 -1
  33. package/dist/uploads/api/file-uploads/shared.d.ts +3 -0
  34. package/dist/uploads/api/file-uploads/shared.d.ts.map +1 -1
  35. package/dist/uploads.js +1 -1
  36. package/package.json +9 -4
  37. package/dist/passwordHashStorage.test.d.ts +0 -2
  38. package/dist/passwordHashStorage.test.d.ts.map +0 -1
  39. package/dist/rts/api/changes/handler.test.d.ts +0 -2
  40. package/dist/rts/api/changes/handler.test.d.ts.map +0 -1
  41. package/dist/rts/index.ws.test.d.ts +0 -2
  42. package/dist/rts/index.ws.test.d.ts.map +0 -1
  43. package/dist/rts.d.ts +0 -3
  44. package/dist/rts.d.ts.map +0 -1
  45. package/dist/rts.js +0 -13
  46. package/dist/uploads/api/files/handlers/getFile.test.d.ts +0 -2
  47. 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;
@@ -1898,6 +1898,104 @@ function handleIntersectionResults(result, left, right) {
1898
1898
  result.value = merged.data;
1899
1899
  return result;
1900
1900
  }
1901
+ const $ZodRecord = /* @__PURE__ */ $constructor("$ZodRecord", (inst, def) => {
1902
+ $ZodType.init(inst, def);
1903
+ inst._zod.parse = (payload, ctx) => {
1904
+ const input = payload.value;
1905
+ if (!isPlainObject(input)) {
1906
+ payload.issues.push({
1907
+ expected: "record",
1908
+ code: "invalid_type",
1909
+ input,
1910
+ inst
1911
+ });
1912
+ return payload;
1913
+ }
1914
+ const proms = [];
1915
+ const values = def.keyType._zod.values;
1916
+ if (values) {
1917
+ payload.value = {};
1918
+ const recordKeys = /* @__PURE__ */ new Set();
1919
+ for (const key of values) {
1920
+ if (typeof key === "string" || typeof key === "number" || typeof key === "symbol") {
1921
+ recordKeys.add(typeof key === "number" ? key.toString() : key);
1922
+ const result = def.valueType._zod.run({ value: input[key], issues: [] }, ctx);
1923
+ if (result instanceof Promise) {
1924
+ proms.push(result.then((result2) => {
1925
+ if (result2.issues.length) {
1926
+ payload.issues.push(...prefixIssues(key, result2.issues));
1927
+ }
1928
+ payload.value[key] = result2.value;
1929
+ }));
1930
+ } else {
1931
+ if (result.issues.length) {
1932
+ payload.issues.push(...prefixIssues(key, result.issues));
1933
+ }
1934
+ payload.value[key] = result.value;
1935
+ }
1936
+ }
1937
+ }
1938
+ let unrecognized;
1939
+ for (const key in input) {
1940
+ if (!recordKeys.has(key)) {
1941
+ unrecognized = unrecognized ?? [];
1942
+ unrecognized.push(key);
1943
+ }
1944
+ }
1945
+ if (unrecognized && unrecognized.length > 0) {
1946
+ payload.issues.push({
1947
+ code: "unrecognized_keys",
1948
+ input,
1949
+ inst,
1950
+ keys: unrecognized
1951
+ });
1952
+ }
1953
+ } else {
1954
+ payload.value = {};
1955
+ for (const key of Reflect.ownKeys(input)) {
1956
+ if (key === "__proto__")
1957
+ continue;
1958
+ const keyResult = def.keyType._zod.run({ value: key, issues: [] }, ctx);
1959
+ if (keyResult instanceof Promise) {
1960
+ throw new Error("Async schemas not supported in object keys currently");
1961
+ }
1962
+ if (keyResult.issues.length) {
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
+ }
1975
+ continue;
1976
+ }
1977
+ const result = def.valueType._zod.run({ value: input[key], issues: [] }, ctx);
1978
+ if (result instanceof Promise) {
1979
+ proms.push(result.then((result2) => {
1980
+ if (result2.issues.length) {
1981
+ payload.issues.push(...prefixIssues(key, result2.issues));
1982
+ }
1983
+ payload.value[keyResult.value] = result2.value;
1984
+ }));
1985
+ } else {
1986
+ if (result.issues.length) {
1987
+ payload.issues.push(...prefixIssues(key, result.issues));
1988
+ }
1989
+ payload.value[keyResult.value] = result.value;
1990
+ }
1991
+ }
1992
+ }
1993
+ if (proms.length) {
1994
+ return Promise.all(proms).then(() => payload);
1995
+ }
1996
+ return payload;
1997
+ };
1998
+ });
1901
1999
  const $ZodEnum = /* @__PURE__ */ $constructor("$ZodEnum", (inst, def) => {
1902
2000
  $ZodType.init(inst, def);
1903
2001
  const values = getEnumValues(def.entries);
@@ -2672,6 +2770,572 @@ function _check(fn, params) {
2672
2770
  ch._zod.check = fn;
2673
2771
  return ch;
2674
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
+ };
2675
3339
  const ZodISODateTime = /* @__PURE__ */ $constructor("ZodISODateTime", (inst, def) => {
2676
3340
  $ZodISODateTime.init(inst, def);
2677
3341
  ZodStringFormat.init(inst, def);
@@ -2751,6 +3415,13 @@ const safeEncodeAsync = /* @__PURE__ */ _safeEncodeAsync(ZodRealError);
2751
3415
  const safeDecodeAsync = /* @__PURE__ */ _safeDecodeAsync(ZodRealError);
2752
3416
  const ZodType = /* @__PURE__ */ $constructor("ZodType", (inst, def) => {
2753
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, {});
2754
3425
  inst.def = def;
2755
3426
  inst.type = def.type;
2756
3427
  Object.defineProperty(inst, "_def", { value: def });
@@ -2823,6 +3494,7 @@ const ZodType = /* @__PURE__ */ $constructor("ZodType", (inst, def) => {
2823
3494
  const _ZodString = /* @__PURE__ */ $constructor("_ZodString", (inst, def) => {
2824
3495
  $ZodString.init(inst, def);
2825
3496
  ZodType.init(inst, def);
3497
+ inst._zod.processJSONSchema = (ctx, json, params) => stringProcessor(inst, ctx, json);
2826
3498
  const bag = inst._zod.bag;
2827
3499
  inst.format = bag.format ?? null;
2828
3500
  inst.minLength = bag.minimum ?? null;
@@ -2960,6 +3632,7 @@ const ZodJWT = /* @__PURE__ */ $constructor("ZodJWT", (inst, def) => {
2960
3632
  const ZodNumber = /* @__PURE__ */ $constructor("ZodNumber", (inst, def) => {
2961
3633
  $ZodNumber.init(inst, def);
2962
3634
  ZodType.init(inst, def);
3635
+ inst._zod.processJSONSchema = (ctx, json, params) => numberProcessor(inst, ctx, json);
2963
3636
  inst.gt = (value, params) => inst.check(_gt(value, params));
2964
3637
  inst.gte = (value, params) => inst.check(_gte(value, params));
2965
3638
  inst.min = (value, params) => inst.check(_gte(value, params));
@@ -2995,6 +3668,7 @@ function int(params) {
2995
3668
  const ZodBoolean = /* @__PURE__ */ $constructor("ZodBoolean", (inst, def) => {
2996
3669
  $ZodBoolean.init(inst, def);
2997
3670
  ZodType.init(inst, def);
3671
+ inst._zod.processJSONSchema = (ctx, json, params) => booleanProcessor(inst, ctx, json);
2998
3672
  });
2999
3673
  function boolean(params) {
3000
3674
  return _boolean(ZodBoolean, params);
@@ -3002,6 +3676,7 @@ function boolean(params) {
3002
3676
  const ZodUnknown = /* @__PURE__ */ $constructor("ZodUnknown", (inst, def) => {
3003
3677
  $ZodUnknown.init(inst, def);
3004
3678
  ZodType.init(inst, def);
3679
+ inst._zod.processJSONSchema = (ctx, json, params) => unknownProcessor();
3005
3680
  });
3006
3681
  function unknown() {
3007
3682
  return _unknown(ZodUnknown);
@@ -3009,6 +3684,7 @@ function unknown() {
3009
3684
  const ZodNever = /* @__PURE__ */ $constructor("ZodNever", (inst, def) => {
3010
3685
  $ZodNever.init(inst, def);
3011
3686
  ZodType.init(inst, def);
3687
+ inst._zod.processJSONSchema = (ctx, json, params) => neverProcessor(inst, ctx, json);
3012
3688
  });
3013
3689
  function never(params) {
3014
3690
  return _never(ZodNever, params);
@@ -3016,6 +3692,7 @@ function never(params) {
3016
3692
  const ZodArray = /* @__PURE__ */ $constructor("ZodArray", (inst, def) => {
3017
3693
  $ZodArray.init(inst, def);
3018
3694
  ZodType.init(inst, def);
3695
+ inst._zod.processJSONSchema = (ctx, json, params) => arrayProcessor(inst, ctx, json, params);
3019
3696
  inst.element = def.element;
3020
3697
  inst.min = (minLength, params) => inst.check(_minLength(minLength, params));
3021
3698
  inst.nonempty = (params) => inst.check(_minLength(1, params));
@@ -3029,6 +3706,7 @@ function array(element, params) {
3029
3706
  const ZodObject = /* @__PURE__ */ $constructor("ZodObject", (inst, def) => {
3030
3707
  $ZodObjectJIT.init(inst, def);
3031
3708
  ZodType.init(inst, def);
3709
+ inst._zod.processJSONSchema = (ctx, json, params) => objectProcessor(inst, ctx, json, params);
3032
3710
  defineLazy(inst, "shape", () => {
3033
3711
  return def.shape;
3034
3712
  });
@@ -3061,6 +3739,7 @@ function object(shape, params) {
3061
3739
  const ZodUnion = /* @__PURE__ */ $constructor("ZodUnion", (inst, def) => {
3062
3740
  $ZodUnion.init(inst, def);
3063
3741
  ZodType.init(inst, def);
3742
+ inst._zod.processJSONSchema = (ctx, json, params) => unionProcessor(inst, ctx, json, params);
3064
3743
  inst.options = def.options;
3065
3744
  });
3066
3745
  function union(options, params) {
@@ -3073,6 +3752,7 @@ function union(options, params) {
3073
3752
  const ZodIntersection = /* @__PURE__ */ $constructor("ZodIntersection", (inst, def) => {
3074
3753
  $ZodIntersection.init(inst, def);
3075
3754
  ZodType.init(inst, def);
3755
+ inst._zod.processJSONSchema = (ctx, json, params) => intersectionProcessor(inst, ctx, json, params);
3076
3756
  });
3077
3757
  function intersection(left, right) {
3078
3758
  return new ZodIntersection({
@@ -3081,9 +3761,25 @@ function intersection(left, right) {
3081
3761
  right
3082
3762
  });
3083
3763
  }
3764
+ const ZodRecord = /* @__PURE__ */ $constructor("ZodRecord", (inst, def) => {
3765
+ $ZodRecord.init(inst, def);
3766
+ ZodType.init(inst, def);
3767
+ inst._zod.processJSONSchema = (ctx, json, params) => recordProcessor(inst, ctx, json, params);
3768
+ inst.keyType = def.keyType;
3769
+ inst.valueType = def.valueType;
3770
+ });
3771
+ function record(keyType, valueType, params) {
3772
+ return new ZodRecord({
3773
+ type: "record",
3774
+ keyType,
3775
+ valueType,
3776
+ ...normalizeParams(params)
3777
+ });
3778
+ }
3084
3779
  const ZodEnum = /* @__PURE__ */ $constructor("ZodEnum", (inst, def) => {
3085
3780
  $ZodEnum.init(inst, def);
3086
3781
  ZodType.init(inst, def);
3782
+ inst._zod.processJSONSchema = (ctx, json, params) => enumProcessor(inst, ctx, json);
3087
3783
  inst.enum = def.entries;
3088
3784
  inst.options = Object.values(def.entries);
3089
3785
  const keys = new Set(Object.keys(def.entries));
@@ -3129,6 +3825,7 @@ function _enum(values, params) {
3129
3825
  const ZodTransform = /* @__PURE__ */ $constructor("ZodTransform", (inst, def) => {
3130
3826
  $ZodTransform.init(inst, def);
3131
3827
  ZodType.init(inst, def);
3828
+ inst._zod.processJSONSchema = (ctx, json, params) => transformProcessor(inst, ctx);
3132
3829
  inst._zod.parse = (payload, _ctx) => {
3133
3830
  if (_ctx.direction === "backward") {
3134
3831
  throw new $ZodEncodeError(inst.constructor.name);
@@ -3166,6 +3863,7 @@ function transform(fn) {
3166
3863
  const ZodOptional = /* @__PURE__ */ $constructor("ZodOptional", (inst, def) => {
3167
3864
  $ZodOptional.init(inst, def);
3168
3865
  ZodType.init(inst, def);
3866
+ inst._zod.processJSONSchema = (ctx, json, params) => optionalProcessor(inst, ctx, json, params);
3169
3867
  inst.unwrap = () => inst._zod.def.innerType;
3170
3868
  });
3171
3869
  function optional(innerType) {
@@ -3177,6 +3875,7 @@ function optional(innerType) {
3177
3875
  const ZodNullable = /* @__PURE__ */ $constructor("ZodNullable", (inst, def) => {
3178
3876
  $ZodNullable.init(inst, def);
3179
3877
  ZodType.init(inst, def);
3878
+ inst._zod.processJSONSchema = (ctx, json, params) => nullableProcessor(inst, ctx, json, params);
3180
3879
  inst.unwrap = () => inst._zod.def.innerType;
3181
3880
  });
3182
3881
  function nullable(innerType) {
@@ -3188,6 +3887,7 @@ function nullable(innerType) {
3188
3887
  const ZodDefault = /* @__PURE__ */ $constructor("ZodDefault", (inst, def) => {
3189
3888
  $ZodDefault.init(inst, def);
3190
3889
  ZodType.init(inst, def);
3890
+ inst._zod.processJSONSchema = (ctx, json, params) => defaultProcessor(inst, ctx, json, params);
3191
3891
  inst.unwrap = () => inst._zod.def.innerType;
3192
3892
  inst.removeDefault = inst.unwrap;
3193
3893
  });
@@ -3203,6 +3903,7 @@ function _default(innerType, defaultValue) {
3203
3903
  const ZodPrefault = /* @__PURE__ */ $constructor("ZodPrefault", (inst, def) => {
3204
3904
  $ZodPrefault.init(inst, def);
3205
3905
  ZodType.init(inst, def);
3906
+ inst._zod.processJSONSchema = (ctx, json, params) => prefaultProcessor(inst, ctx, json, params);
3206
3907
  inst.unwrap = () => inst._zod.def.innerType;
3207
3908
  });
3208
3909
  function prefault(innerType, defaultValue) {
@@ -3217,6 +3918,7 @@ function prefault(innerType, defaultValue) {
3217
3918
  const ZodNonOptional = /* @__PURE__ */ $constructor("ZodNonOptional", (inst, def) => {
3218
3919
  $ZodNonOptional.init(inst, def);
3219
3920
  ZodType.init(inst, def);
3921
+ inst._zod.processJSONSchema = (ctx, json, params) => nonoptionalProcessor(inst, ctx, json, params);
3220
3922
  inst.unwrap = () => inst._zod.def.innerType;
3221
3923
  });
3222
3924
  function nonoptional(innerType, params) {
@@ -3229,6 +3931,7 @@ function nonoptional(innerType, params) {
3229
3931
  const ZodCatch = /* @__PURE__ */ $constructor("ZodCatch", (inst, def) => {
3230
3932
  $ZodCatch.init(inst, def);
3231
3933
  ZodType.init(inst, def);
3934
+ inst._zod.processJSONSchema = (ctx, json, params) => catchProcessor(inst, ctx, json, params);
3232
3935
  inst.unwrap = () => inst._zod.def.innerType;
3233
3936
  inst.removeCatch = inst.unwrap;
3234
3937
  });
@@ -3242,6 +3945,7 @@ function _catch(innerType, catchValue) {
3242
3945
  const ZodPipe = /* @__PURE__ */ $constructor("ZodPipe", (inst, def) => {
3243
3946
  $ZodPipe.init(inst, def);
3244
3947
  ZodType.init(inst, def);
3948
+ inst._zod.processJSONSchema = (ctx, json, params) => pipeProcessor(inst, ctx, json, params);
3245
3949
  inst.in = def.in;
3246
3950
  inst.out = def.out;
3247
3951
  });
@@ -3256,6 +3960,7 @@ function pipe(in_, out) {
3256
3960
  const ZodReadonly = /* @__PURE__ */ $constructor("ZodReadonly", (inst, def) => {
3257
3961
  $ZodReadonly.init(inst, def);
3258
3962
  ZodType.init(inst, def);
3963
+ inst._zod.processJSONSchema = (ctx, json, params) => readonlyProcessor(inst, ctx, json, params);
3259
3964
  inst.unwrap = () => inst._zod.def.innerType;
3260
3965
  });
3261
3966
  function readonly(innerType) {
@@ -3267,6 +3972,7 @@ function readonly(innerType) {
3267
3972
  const ZodCustom = /* @__PURE__ */ $constructor("ZodCustom", (inst, def) => {
3268
3973
  $ZodCustom.init(inst, def);
3269
3974
  ZodType.init(inst, def);
3975
+ inst._zod.processJSONSchema = (ctx, json, params) => customProcessor(inst, ctx);
3270
3976
  });
3271
3977
  function refine(fn, _params = {}) {
3272
3978
  return _refine(ZodCustom, fn, _params);
@@ -3280,5 +3986,7 @@ export {
3280
3986
  boolean as b,
3281
3987
  number as n,
3282
3988
  object as o,
3283
- string as s
3989
+ record as r,
3990
+ string as s,
3991
+ unknown as u
3284
3992
  };