@orpc/openapi 0.17.0 → 0.19.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.
@@ -0,0 +1,107 @@
1
+ // src/json-serializer.ts
2
+ import { isPlainObject } from "@orpc/shared";
3
+ var JSONSerializer = class {
4
+ serialize(payload) {
5
+ if (payload instanceof Set)
6
+ return this.serialize([...payload]);
7
+ if (payload instanceof Map)
8
+ return this.serialize([...payload.entries()]);
9
+ if (Array.isArray(payload)) {
10
+ return payload.map((v) => v === void 0 ? "undefined" : this.serialize(v));
11
+ }
12
+ if (Number.isNaN(payload))
13
+ return "NaN";
14
+ if (typeof payload === "bigint")
15
+ return payload.toString();
16
+ if (payload instanceof Date && Number.isNaN(payload.getTime())) {
17
+ return "Invalid Date";
18
+ }
19
+ if (payload instanceof RegExp)
20
+ return payload.toString();
21
+ if (payload instanceof URL)
22
+ return payload.toString();
23
+ if (!isPlainObject(payload))
24
+ return payload;
25
+ return Object.keys(payload).reduce(
26
+ (carry, key) => {
27
+ const val = payload[key];
28
+ carry[key] = this.serialize(val);
29
+ return carry;
30
+ },
31
+ {}
32
+ );
33
+ }
34
+ };
35
+
36
+ // src/utils.ts
37
+ import { isContractProcedure } from "@orpc/contract";
38
+ import { getRouterContract, isLazy, isProcedure, unlazy } from "@orpc/server";
39
+ function forEachContractProcedure(options, callback, result = [], isCurrentRouterContract = false) {
40
+ const hiddenContract = getRouterContract(options.router);
41
+ if (!isCurrentRouterContract && hiddenContract) {
42
+ return forEachContractProcedure(
43
+ {
44
+ path: options.path,
45
+ router: hiddenContract
46
+ },
47
+ callback,
48
+ result,
49
+ true
50
+ );
51
+ }
52
+ if (isLazy(options.router)) {
53
+ result.push({
54
+ router: options.router,
55
+ path: options.path
56
+ });
57
+ } else if (isProcedure(options.router)) {
58
+ callback({
59
+ contract: options.router["~orpc"].contract,
60
+ path: options.path
61
+ });
62
+ } else if (isContractProcedure(options.router)) {
63
+ callback({
64
+ contract: options.router,
65
+ path: options.path
66
+ });
67
+ } else {
68
+ for (const key in options.router) {
69
+ forEachContractProcedure(
70
+ {
71
+ router: options.router[key],
72
+ path: [...options.path, key]
73
+ },
74
+ callback,
75
+ result
76
+ );
77
+ }
78
+ }
79
+ return result;
80
+ }
81
+ async function forEachAllContractProcedure(router, callback) {
82
+ const pending = [{
83
+ path: [],
84
+ router
85
+ }];
86
+ for (const item of pending) {
87
+ const lazies = forEachContractProcedure(item, callback);
88
+ for (const lazy of lazies) {
89
+ const { default: router2 } = await unlazy(lazy.router);
90
+ pending.push({
91
+ path: lazy.path,
92
+ router: router2
93
+ });
94
+ }
95
+ }
96
+ }
97
+ function standardizeHTTPPath(path) {
98
+ return `/${path.replace(/\/{2,}/g, "/").replace(/^\/|\/$/g, "")}`;
99
+ }
100
+
101
+ export {
102
+ JSONSerializer,
103
+ forEachContractProcedure,
104
+ forEachAllContractProcedure,
105
+ standardizeHTTPPath
106
+ };
107
+ //# sourceMappingURL=chunk-KNYXLM77.js.map