@orpc/openapi 0.0.0-next.748dfd9 → 0.0.0-next.7b09958
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/chunk-HC5PVG4R.js +52 -0
- package/dist/chunk-ICLAXOVR.js +32 -0
- package/dist/chunk-PWOV66X6.js +421 -0
- package/dist/fetch.js +5 -30
- package/dist/hono.js +5 -30
- package/dist/index.js +82 -32
- package/dist/next.js +5 -30
- package/dist/node.js +18 -34
- package/dist/src/adapters/fetch/index.d.ts +0 -8
- package/dist/src/adapters/fetch/openapi-handler.d.ts +7 -29
- package/dist/src/adapters/node/index.d.ts +0 -3
- package/dist/src/adapters/node/openapi-handler.d.ts +7 -8
- package/dist/src/adapters/standard/index.d.ts +6 -0
- package/dist/src/adapters/standard/openapi-codec.d.ts +15 -0
- package/dist/src/adapters/standard/openapi-handler.d.ts +7 -0
- package/dist/src/adapters/standard/openapi-matcher.d.ts +20 -0
- package/dist/src/adapters/standard/openapi-serializer.d.ts +11 -0
- package/dist/src/openapi-generator.d.ts +9 -2
- package/dist/src/openapi-input-structure-parser.d.ts +2 -2
- package/dist/src/openapi-output-structure-parser.d.ts +2 -2
- package/dist/src/schema-converter.d.ts +2 -2
- package/dist/src/schema.d.ts +1 -1
- package/dist/src/utils.d.ts +1 -16
- package/dist/standard.js +14 -0
- package/package.json +10 -8
- package/dist/chunk-KNYXLM77.js +0 -107
- package/dist/chunk-XYIZDXKB.js +0 -652
- package/dist/chunk-YOKECDND.js +0 -25
- package/dist/src/adapters/fetch/input-structure-compact.d.ts +0 -6
- package/dist/src/adapters/fetch/input-structure-detailed.d.ts +0 -11
- package/dist/src/adapters/fetch/openapi-handler-server.d.ts +0 -7
- package/dist/src/adapters/fetch/openapi-handler-serverless.d.ts +0 -7
- package/dist/src/adapters/fetch/openapi-payload-codec.d.ts +0 -15
- package/dist/src/adapters/fetch/openapi-procedure-matcher.d.ts +0 -19
- package/dist/src/adapters/fetch/schema-coercer.d.ts +0 -10
- package/dist/src/adapters/node/openapi-handler-server.d.ts +0 -7
- package/dist/src/adapters/node/openapi-handler-serverless.d.ts +0 -7
- package/dist/src/adapters/node/types.d.ts +0 -2
- /package/dist/src/adapters/{fetch → standard}/bracket-notation.d.ts +0 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __export = (target, all) => {
|
|
3
|
+
for (var name in all)
|
|
4
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
// src/json-serializer.ts
|
|
8
|
+
import { isObject } from "@orpc/shared";
|
|
9
|
+
var JSONSerializer = class {
|
|
10
|
+
serialize(payload) {
|
|
11
|
+
if (payload instanceof Set)
|
|
12
|
+
return this.serialize([...payload]);
|
|
13
|
+
if (payload instanceof Map)
|
|
14
|
+
return this.serialize([...payload.entries()]);
|
|
15
|
+
if (Array.isArray(payload)) {
|
|
16
|
+
return payload.map((v) => v === void 0 ? "undefined" : this.serialize(v));
|
|
17
|
+
}
|
|
18
|
+
if (Number.isNaN(payload))
|
|
19
|
+
return "NaN";
|
|
20
|
+
if (typeof payload === "bigint")
|
|
21
|
+
return payload.toString();
|
|
22
|
+
if (payload instanceof Date && Number.isNaN(payload.getTime())) {
|
|
23
|
+
return "Invalid Date";
|
|
24
|
+
}
|
|
25
|
+
if (payload instanceof RegExp)
|
|
26
|
+
return payload.toString();
|
|
27
|
+
if (payload instanceof URL)
|
|
28
|
+
return payload.toString();
|
|
29
|
+
if (!isObject(payload))
|
|
30
|
+
return payload;
|
|
31
|
+
return Object.keys(payload).reduce(
|
|
32
|
+
(carry, key) => {
|
|
33
|
+
const val = payload[key];
|
|
34
|
+
carry[key] = this.serialize(val);
|
|
35
|
+
return carry;
|
|
36
|
+
},
|
|
37
|
+
{}
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
// src/utils.ts
|
|
43
|
+
function standardizeHTTPPath(path) {
|
|
44
|
+
return `/${path.replace(/\/{2,}/g, "/").replace(/^\/|\/$/g, "")}`;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export {
|
|
48
|
+
__export,
|
|
49
|
+
JSONSerializer,
|
|
50
|
+
standardizeHTTPPath
|
|
51
|
+
};
|
|
52
|
+
//# sourceMappingURL=chunk-HC5PVG4R.js.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import {
|
|
2
|
+
OpenAPICodec,
|
|
3
|
+
OpenAPIMatcher
|
|
4
|
+
} from "./chunk-PWOV66X6.js";
|
|
5
|
+
|
|
6
|
+
// src/adapters/fetch/openapi-handler.ts
|
|
7
|
+
import { fetchRequestToStandardRequest, standardResponseToFetchResponse } from "@orpc/server/fetch";
|
|
8
|
+
import { StandardHandler } from "@orpc/server/standard";
|
|
9
|
+
var OpenAPIHandler = class {
|
|
10
|
+
standardHandler;
|
|
11
|
+
constructor(router, options) {
|
|
12
|
+
const matcher = options?.matcher ?? new OpenAPIMatcher(options);
|
|
13
|
+
const codec = options?.codec ?? new OpenAPICodec(options);
|
|
14
|
+
this.standardHandler = new StandardHandler(router, matcher, codec, options);
|
|
15
|
+
}
|
|
16
|
+
async handle(request, ...rest) {
|
|
17
|
+
const standardRequest = fetchRequestToStandardRequest(request);
|
|
18
|
+
const result = await this.standardHandler.handle(standardRequest, ...rest);
|
|
19
|
+
if (!result.matched) {
|
|
20
|
+
return result;
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
matched: true,
|
|
24
|
+
response: standardResponseToFetchResponse(result.response)
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export {
|
|
30
|
+
OpenAPIHandler
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=chunk-ICLAXOVR.js.map
|
|
@@ -0,0 +1,421 @@
|
|
|
1
|
+
import {
|
|
2
|
+
JSONSerializer,
|
|
3
|
+
__export,
|
|
4
|
+
standardizeHTTPPath
|
|
5
|
+
} from "./chunk-HC5PVG4R.js";
|
|
6
|
+
|
|
7
|
+
// src/adapters/standard/bracket-notation.ts
|
|
8
|
+
var bracket_notation_exports = {};
|
|
9
|
+
__export(bracket_notation_exports, {
|
|
10
|
+
deserialize: () => deserialize,
|
|
11
|
+
escapeSegment: () => escapeSegment,
|
|
12
|
+
parsePath: () => parsePath,
|
|
13
|
+
serialize: () => serialize,
|
|
14
|
+
stringifyPath: () => stringifyPath
|
|
15
|
+
});
|
|
16
|
+
import { isObject } from "@orpc/shared";
|
|
17
|
+
function serialize(payload, parentKey = "") {
|
|
18
|
+
if (!Array.isArray(payload) && !isObject(payload))
|
|
19
|
+
return [["", payload]];
|
|
20
|
+
const result = [];
|
|
21
|
+
function helper(value, path) {
|
|
22
|
+
if (Array.isArray(value)) {
|
|
23
|
+
value.forEach((item, index) => {
|
|
24
|
+
helper(item, [...path, String(index)]);
|
|
25
|
+
});
|
|
26
|
+
} else if (isObject(value)) {
|
|
27
|
+
for (const [key, val] of Object.entries(value)) {
|
|
28
|
+
helper(val, [...path, key]);
|
|
29
|
+
}
|
|
30
|
+
} else {
|
|
31
|
+
result.push([stringifyPath(path), value]);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
helper(payload, parentKey ? [parentKey] : []);
|
|
35
|
+
return result;
|
|
36
|
+
}
|
|
37
|
+
function deserialize(entities) {
|
|
38
|
+
if (entities.length === 0) {
|
|
39
|
+
return void 0;
|
|
40
|
+
}
|
|
41
|
+
const isRootArray = entities.every(([path]) => path === "");
|
|
42
|
+
const result = isRootArray ? [] : {};
|
|
43
|
+
const arrayPushPaths = /* @__PURE__ */ new Set();
|
|
44
|
+
for (const [path, _] of entities) {
|
|
45
|
+
const segments = parsePath(path);
|
|
46
|
+
const base = segments.slice(0, -1).join(".");
|
|
47
|
+
const last = segments[segments.length - 1];
|
|
48
|
+
if (last === "") {
|
|
49
|
+
arrayPushPaths.add(base);
|
|
50
|
+
} else {
|
|
51
|
+
arrayPushPaths.delete(base);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function setValue(obj, segments, value, fullPath) {
|
|
55
|
+
const [first, ...rest_] = segments;
|
|
56
|
+
if (Array.isArray(obj) && first === "") {
|
|
57
|
+
;
|
|
58
|
+
obj.push(value);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const objAsRecord = obj;
|
|
62
|
+
if (rest_.length === 0) {
|
|
63
|
+
objAsRecord[first] = value;
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const rest = rest_;
|
|
67
|
+
if (rest[0] === "") {
|
|
68
|
+
const pathToCheck = segments.slice(0, -1).join(".");
|
|
69
|
+
if (rest.length === 1 && arrayPushPaths.has(pathToCheck)) {
|
|
70
|
+
if (!(first in objAsRecord)) {
|
|
71
|
+
objAsRecord[first] = [];
|
|
72
|
+
}
|
|
73
|
+
if (Array.isArray(objAsRecord[first])) {
|
|
74
|
+
;
|
|
75
|
+
objAsRecord[first].push(value);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (!(first in objAsRecord)) {
|
|
80
|
+
objAsRecord[first] = {};
|
|
81
|
+
}
|
|
82
|
+
const target = objAsRecord[first];
|
|
83
|
+
target[""] = value;
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
if (!(first in objAsRecord)) {
|
|
87
|
+
objAsRecord[first] = {};
|
|
88
|
+
}
|
|
89
|
+
setValue(
|
|
90
|
+
objAsRecord[first],
|
|
91
|
+
rest,
|
|
92
|
+
value,
|
|
93
|
+
fullPath
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
for (const [path, value] of entities) {
|
|
97
|
+
const segments = parsePath(path);
|
|
98
|
+
setValue(result, segments, value, path);
|
|
99
|
+
}
|
|
100
|
+
return result;
|
|
101
|
+
}
|
|
102
|
+
function escapeSegment(segment) {
|
|
103
|
+
return segment.replace(/[\\[\]]/g, (match) => {
|
|
104
|
+
switch (match) {
|
|
105
|
+
case "\\":
|
|
106
|
+
return "\\\\";
|
|
107
|
+
case "[":
|
|
108
|
+
return "\\[";
|
|
109
|
+
case "]":
|
|
110
|
+
return "\\]";
|
|
111
|
+
default:
|
|
112
|
+
return match;
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
function stringifyPath(path) {
|
|
117
|
+
const [first, ...rest] = path;
|
|
118
|
+
const firstSegment = escapeSegment(first);
|
|
119
|
+
const base = first === "" ? "" : firstSegment;
|
|
120
|
+
return rest.reduce(
|
|
121
|
+
(result, segment) => `${result}[${escapeSegment(segment)}]`,
|
|
122
|
+
base
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
function parsePath(path) {
|
|
126
|
+
if (path === "")
|
|
127
|
+
return [""];
|
|
128
|
+
const result = [];
|
|
129
|
+
let currentSegment = "";
|
|
130
|
+
let inBracket = false;
|
|
131
|
+
let bracketContent = "";
|
|
132
|
+
let backslashCount = 0;
|
|
133
|
+
for (let i = 0; i < path.length; i++) {
|
|
134
|
+
const char = path[i];
|
|
135
|
+
if (char === "\\") {
|
|
136
|
+
backslashCount++;
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
if (backslashCount > 0) {
|
|
140
|
+
const literalBackslashes = "\\".repeat(Math.floor(backslashCount / 2));
|
|
141
|
+
if (char === "[" || char === "]") {
|
|
142
|
+
if (backslashCount % 2 === 1) {
|
|
143
|
+
if (inBracket) {
|
|
144
|
+
bracketContent += literalBackslashes + char;
|
|
145
|
+
} else {
|
|
146
|
+
currentSegment += literalBackslashes + char;
|
|
147
|
+
}
|
|
148
|
+
} else {
|
|
149
|
+
if (inBracket) {
|
|
150
|
+
bracketContent += literalBackslashes;
|
|
151
|
+
} else {
|
|
152
|
+
currentSegment += literalBackslashes;
|
|
153
|
+
}
|
|
154
|
+
if (char === "[" && !inBracket) {
|
|
155
|
+
if (currentSegment !== "" || result.length === 0) {
|
|
156
|
+
result.push(currentSegment);
|
|
157
|
+
}
|
|
158
|
+
inBracket = true;
|
|
159
|
+
bracketContent = "";
|
|
160
|
+
currentSegment = "";
|
|
161
|
+
} else if (char === "]" && inBracket) {
|
|
162
|
+
result.push(bracketContent);
|
|
163
|
+
inBracket = false;
|
|
164
|
+
bracketContent = "";
|
|
165
|
+
} else {
|
|
166
|
+
if (inBracket) {
|
|
167
|
+
bracketContent += char;
|
|
168
|
+
} else {
|
|
169
|
+
currentSegment += char;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
} else {
|
|
174
|
+
const allBackslashes = "\\".repeat(backslashCount);
|
|
175
|
+
if (inBracket) {
|
|
176
|
+
bracketContent += allBackslashes + char;
|
|
177
|
+
} else {
|
|
178
|
+
currentSegment += allBackslashes + char;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
backslashCount = 0;
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
if (char === "[" && !inBracket) {
|
|
185
|
+
if (currentSegment !== "" || result.length === 0) {
|
|
186
|
+
result.push(currentSegment);
|
|
187
|
+
}
|
|
188
|
+
inBracket = true;
|
|
189
|
+
bracketContent = "";
|
|
190
|
+
currentSegment = "";
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
if (char === "]" && inBracket) {
|
|
194
|
+
result.push(bracketContent);
|
|
195
|
+
inBracket = false;
|
|
196
|
+
bracketContent = "";
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
if (inBracket) {
|
|
200
|
+
bracketContent += char;
|
|
201
|
+
} else {
|
|
202
|
+
currentSegment += char;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
if (backslashCount > 0) {
|
|
206
|
+
const remainingBackslashes = "\\".repeat(backslashCount);
|
|
207
|
+
if (inBracket) {
|
|
208
|
+
bracketContent += remainingBackslashes;
|
|
209
|
+
} else {
|
|
210
|
+
currentSegment += remainingBackslashes;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
if (inBracket) {
|
|
214
|
+
if (currentSegment !== "" || result.length === 0) {
|
|
215
|
+
result.push(currentSegment);
|
|
216
|
+
}
|
|
217
|
+
result.push(`[${bracketContent}`);
|
|
218
|
+
} else if (currentSegment !== "" || result.length === 0) {
|
|
219
|
+
result.push(currentSegment);
|
|
220
|
+
}
|
|
221
|
+
return result;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// src/adapters/standard/openapi-codec.ts
|
|
225
|
+
import { fallbackContractConfig } from "@orpc/contract";
|
|
226
|
+
import { isObject as isObject2 } from "@orpc/shared";
|
|
227
|
+
|
|
228
|
+
// src/adapters/standard/openapi-serializer.ts
|
|
229
|
+
import { findDeepMatches } from "@orpc/shared";
|
|
230
|
+
var OpenAPISerializer = class {
|
|
231
|
+
jsonSerializer;
|
|
232
|
+
constructor(options) {
|
|
233
|
+
this.jsonSerializer = options?.jsonSerializer ?? new JSONSerializer();
|
|
234
|
+
}
|
|
235
|
+
serialize(data) {
|
|
236
|
+
if (data instanceof Blob || data === void 0) {
|
|
237
|
+
return data;
|
|
238
|
+
}
|
|
239
|
+
const serializedJSON = this.jsonSerializer.serialize(data);
|
|
240
|
+
const { values: blobs } = findDeepMatches((v) => v instanceof Blob, serializedJSON);
|
|
241
|
+
if (blobs.length === 0) {
|
|
242
|
+
return serializedJSON;
|
|
243
|
+
}
|
|
244
|
+
const form = new FormData();
|
|
245
|
+
for (const [path, value] of serialize(serializedJSON)) {
|
|
246
|
+
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
247
|
+
form.append(path, value.toString());
|
|
248
|
+
} else if (value instanceof Date) {
|
|
249
|
+
form.append(path, value.toISOString());
|
|
250
|
+
} else if (value instanceof Blob) {
|
|
251
|
+
form.append(path, value);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return form;
|
|
255
|
+
}
|
|
256
|
+
deserialize(serialized) {
|
|
257
|
+
if (serialized instanceof URLSearchParams || serialized instanceof FormData) {
|
|
258
|
+
return deserialize([...serialized.entries()]);
|
|
259
|
+
}
|
|
260
|
+
return serialized;
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
// src/adapters/standard/openapi-codec.ts
|
|
265
|
+
var OpenAPICodec = class {
|
|
266
|
+
serializer;
|
|
267
|
+
constructor(options) {
|
|
268
|
+
this.serializer = options?.serializer ?? new OpenAPISerializer();
|
|
269
|
+
}
|
|
270
|
+
async decode(request, params, procedure) {
|
|
271
|
+
const inputStructure = fallbackContractConfig("defaultInputStructure", procedure["~orpc"].route.inputStructure);
|
|
272
|
+
if (inputStructure === "compact") {
|
|
273
|
+
const data = request.method === "GET" ? this.serializer.deserialize(request.url.searchParams) : this.serializer.deserialize(await request.body());
|
|
274
|
+
if (data === void 0) {
|
|
275
|
+
return params;
|
|
276
|
+
}
|
|
277
|
+
if (isObject2(data)) {
|
|
278
|
+
return {
|
|
279
|
+
...params,
|
|
280
|
+
...data
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
return data;
|
|
284
|
+
}
|
|
285
|
+
const deserializeSearchParams = () => {
|
|
286
|
+
return this.serializer.deserialize(request.url.searchParams);
|
|
287
|
+
};
|
|
288
|
+
return {
|
|
289
|
+
params,
|
|
290
|
+
get query() {
|
|
291
|
+
const value = deserializeSearchParams();
|
|
292
|
+
Object.defineProperty(this, "query", { value, writable: true });
|
|
293
|
+
return value;
|
|
294
|
+
},
|
|
295
|
+
set query(value) {
|
|
296
|
+
Object.defineProperty(this, "query", { value, writable: true });
|
|
297
|
+
},
|
|
298
|
+
headers: request.headers,
|
|
299
|
+
body: this.serializer.deserialize(await request.body())
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
encode(output, procedure) {
|
|
303
|
+
const successStatus = fallbackContractConfig("defaultSuccessStatus", procedure["~orpc"].route.successStatus);
|
|
304
|
+
const outputStructure = fallbackContractConfig("defaultOutputStructure", procedure["~orpc"].route.outputStructure);
|
|
305
|
+
if (outputStructure === "compact") {
|
|
306
|
+
return {
|
|
307
|
+
status: successStatus,
|
|
308
|
+
headers: {},
|
|
309
|
+
body: this.serializer.serialize(output)
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
if (!isObject2(output)) {
|
|
313
|
+
throw new Error(
|
|
314
|
+
'Invalid output structure for "detailed" output. Expected format: { body: any, headers?: Record<string, string | string[] | undefined> }'
|
|
315
|
+
);
|
|
316
|
+
}
|
|
317
|
+
return {
|
|
318
|
+
status: successStatus,
|
|
319
|
+
headers: output.headers ?? {},
|
|
320
|
+
body: this.serializer.serialize(output.body)
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
encodeError(error) {
|
|
324
|
+
return {
|
|
325
|
+
status: error.status,
|
|
326
|
+
headers: {},
|
|
327
|
+
body: this.serializer.serialize(error.toJSON())
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
// src/adapters/standard/openapi-matcher.ts
|
|
333
|
+
import { fallbackContractConfig as fallbackContractConfig2 } from "@orpc/contract";
|
|
334
|
+
import { convertPathToHttpPath, createContractedProcedure, eachContractProcedure, getLazyRouterPrefix, getRouterChild, isProcedure, unlazy } from "@orpc/server";
|
|
335
|
+
import { addRoute, createRouter, findRoute } from "rou3";
|
|
336
|
+
var OpenAPIMatcher = class {
|
|
337
|
+
tree = createRouter();
|
|
338
|
+
ignoreUndefinedMethod;
|
|
339
|
+
constructor(options) {
|
|
340
|
+
this.ignoreUndefinedMethod = options?.ignoreUndefinedMethod ?? false;
|
|
341
|
+
}
|
|
342
|
+
pendingRouters = [];
|
|
343
|
+
init(router, path = []) {
|
|
344
|
+
const laziedOptions = eachContractProcedure({
|
|
345
|
+
router,
|
|
346
|
+
path
|
|
347
|
+
}, ({ path: path2, contract }) => {
|
|
348
|
+
if (!contract["~orpc"].route.method && this.ignoreUndefinedMethod) {
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
351
|
+
const method = fallbackContractConfig2("defaultMethod", contract["~orpc"].route.method);
|
|
352
|
+
const httpPath = contract["~orpc"].route.path ? convertOpenAPIPathToRouterPath(contract["~orpc"].route.path) : convertPathToHttpPath(path2);
|
|
353
|
+
if (isProcedure(contract)) {
|
|
354
|
+
addRoute(this.tree, method, httpPath, {
|
|
355
|
+
path: path2,
|
|
356
|
+
contract,
|
|
357
|
+
procedure: contract,
|
|
358
|
+
// this mean dev not used contract-first so we can used contract as procedure directly
|
|
359
|
+
router
|
|
360
|
+
});
|
|
361
|
+
} else {
|
|
362
|
+
addRoute(this.tree, method, httpPath, {
|
|
363
|
+
path: path2,
|
|
364
|
+
contract,
|
|
365
|
+
procedure: void 0,
|
|
366
|
+
router
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
});
|
|
370
|
+
this.pendingRouters.push(...laziedOptions.map((option) => ({
|
|
371
|
+
...option,
|
|
372
|
+
httpPathPrefix: convertPathToHttpPath(option.path),
|
|
373
|
+
laziedPrefix: getLazyRouterPrefix(option.lazied)
|
|
374
|
+
})));
|
|
375
|
+
}
|
|
376
|
+
async match(method, pathname) {
|
|
377
|
+
if (this.pendingRouters.length) {
|
|
378
|
+
const newPendingRouters = [];
|
|
379
|
+
for (const pendingRouter of this.pendingRouters) {
|
|
380
|
+
if (!pendingRouter.laziedPrefix || pathname.startsWith(pendingRouter.laziedPrefix) || pathname.startsWith(pendingRouter.httpPathPrefix)) {
|
|
381
|
+
const { default: router } = await unlazy(pendingRouter.lazied);
|
|
382
|
+
this.init(router, pendingRouter.path);
|
|
383
|
+
} else {
|
|
384
|
+
newPendingRouters.push(pendingRouter);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
this.pendingRouters = newPendingRouters;
|
|
388
|
+
}
|
|
389
|
+
const match = findRoute(this.tree, method, pathname);
|
|
390
|
+
if (!match) {
|
|
391
|
+
return void 0;
|
|
392
|
+
}
|
|
393
|
+
if (!match.data.procedure) {
|
|
394
|
+
const { default: maybeProcedure } = await unlazy(getRouterChild(match.data.router, ...match.data.path));
|
|
395
|
+
if (!isProcedure(maybeProcedure)) {
|
|
396
|
+
throw new Error(`
|
|
397
|
+
[Contract-First] Missing or invalid implementation for procedure at path: ${convertPathToHttpPath(match.data.path)}.
|
|
398
|
+
Ensure that the procedure is correctly defined and matches the expected contract.
|
|
399
|
+
`);
|
|
400
|
+
}
|
|
401
|
+
match.data.procedure = createContractedProcedure(match.data.contract, maybeProcedure);
|
|
402
|
+
}
|
|
403
|
+
return {
|
|
404
|
+
path: match.data.path,
|
|
405
|
+
procedure: match.data.procedure,
|
|
406
|
+
params: match.params ? { ...match.params } : void 0
|
|
407
|
+
// normalize params
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
};
|
|
411
|
+
function convertOpenAPIPathToRouterPath(path) {
|
|
412
|
+
return standardizeHTTPPath(path).replace(/\{([^}]+)\}/g, ":$1");
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
export {
|
|
416
|
+
bracket_notation_exports,
|
|
417
|
+
OpenAPISerializer,
|
|
418
|
+
OpenAPICodec,
|
|
419
|
+
OpenAPIMatcher
|
|
420
|
+
};
|
|
421
|
+
//# sourceMappingURL=chunk-PWOV66X6.js.map
|
package/dist/fetch.js
CHANGED
|
@@ -1,34 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import
|
|
6
|
-
CompositeSchemaCoercer,
|
|
7
|
-
InputStructureCompact,
|
|
8
|
-
InputStructureDetailed,
|
|
9
|
-
OpenAPIHandler,
|
|
10
|
-
OpenAPIPayloadCodec,
|
|
11
|
-
OpenAPIProcedureMatcher,
|
|
12
|
-
deserialize,
|
|
13
|
-
escapeSegment,
|
|
14
|
-
parsePath,
|
|
15
|
-
serialize,
|
|
16
|
-
stringifyPath
|
|
17
|
-
} from "./chunk-XYIZDXKB.js";
|
|
18
|
-
import "./chunk-KNYXLM77.js";
|
|
2
|
+
OpenAPIHandler
|
|
3
|
+
} from "./chunk-ICLAXOVR.js";
|
|
4
|
+
import "./chunk-PWOV66X6.js";
|
|
5
|
+
import "./chunk-HC5PVG4R.js";
|
|
19
6
|
export {
|
|
20
|
-
|
|
21
|
-
InputStructureCompact,
|
|
22
|
-
InputStructureDetailed,
|
|
23
|
-
OpenAPIHandler,
|
|
24
|
-
OpenAPIPayloadCodec,
|
|
25
|
-
OpenAPIProcedureMatcher,
|
|
26
|
-
OpenAPIServerHandler,
|
|
27
|
-
OpenAPIServerlessHandler,
|
|
28
|
-
deserialize,
|
|
29
|
-
escapeSegment,
|
|
30
|
-
parsePath,
|
|
31
|
-
serialize,
|
|
32
|
-
stringifyPath
|
|
7
|
+
OpenAPIHandler
|
|
33
8
|
};
|
|
34
9
|
//# sourceMappingURL=fetch.js.map
|
package/dist/hono.js
CHANGED
|
@@ -1,34 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import
|
|
6
|
-
CompositeSchemaCoercer,
|
|
7
|
-
InputStructureCompact,
|
|
8
|
-
InputStructureDetailed,
|
|
9
|
-
OpenAPIHandler,
|
|
10
|
-
OpenAPIPayloadCodec,
|
|
11
|
-
OpenAPIProcedureMatcher,
|
|
12
|
-
deserialize,
|
|
13
|
-
escapeSegment,
|
|
14
|
-
parsePath,
|
|
15
|
-
serialize,
|
|
16
|
-
stringifyPath
|
|
17
|
-
} from "./chunk-XYIZDXKB.js";
|
|
18
|
-
import "./chunk-KNYXLM77.js";
|
|
2
|
+
OpenAPIHandler
|
|
3
|
+
} from "./chunk-ICLAXOVR.js";
|
|
4
|
+
import "./chunk-PWOV66X6.js";
|
|
5
|
+
import "./chunk-HC5PVG4R.js";
|
|
19
6
|
export {
|
|
20
|
-
|
|
21
|
-
InputStructureCompact,
|
|
22
|
-
InputStructureDetailed,
|
|
23
|
-
OpenAPIHandler,
|
|
24
|
-
OpenAPIPayloadCodec,
|
|
25
|
-
OpenAPIProcedureMatcher,
|
|
26
|
-
OpenAPIServerHandler,
|
|
27
|
-
OpenAPIServerlessHandler,
|
|
28
|
-
deserialize,
|
|
29
|
-
escapeSegment,
|
|
30
|
-
parsePath,
|
|
31
|
-
serialize,
|
|
32
|
-
stringifyPath
|
|
7
|
+
OpenAPIHandler
|
|
33
8
|
};
|
|
34
9
|
//# sourceMappingURL=hono.js.map
|