@orpc/openapi 2.0.0-beta.49 → 2.0.0-beta.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapters/aws-lambda/index.d.ts +3 -15
- package/dist/adapters/aws-lambda/index.js +1 -1
- package/dist/adapters/aws-lambda/openapi-handler.d.ts +8 -9
- package/dist/adapters/aws-lambda/openapi-handler.js +19 -17
- package/dist/adapters/fastify/index.d.ts +2 -1
- package/dist/adapters/fastify/index.js +1 -1
- package/dist/adapters/fastify/openapi-handler.d.ts +8 -9
- package/dist/adapters/fastify/openapi-handler.js +16 -14
- package/dist/adapters/fetch/index.d.ts +3 -2
- package/dist/adapters/fetch/index.js +2 -2
- package/dist/adapters/fetch/openapi-handler.d.ts +8 -9
- package/dist/adapters/fetch/openapi-handler.js +16 -14
- package/dist/adapters/fetch/openapi-link.d.ts +9 -10
- package/dist/adapters/fetch/openapi-link.js +21 -19
- package/dist/adapters/node/index.d.ts +2 -1
- package/dist/adapters/node/index.js +1 -1
- package/dist/adapters/node/openapi-handler.d.ts +8 -9
- package/dist/adapters/node/openapi-handler.js +16 -14
- package/dist/adapters/standard/index.d.ts +4 -3
- package/dist/adapters/standard/index.js +3 -3
- package/dist/adapters/standard/openapi-handler-codec.d.ts +56 -57
- package/dist/adapters/standard/openapi-handler-codec.js +143 -205
- package/dist/adapters/standard/openapi-link-codec.d.ts +55 -59
- package/dist/adapters/standard/openapi-link-codec.js +262 -377
- package/dist/adapters/standard/openapi-matcher.d.ts +26 -26
- package/dist/adapters/standard/openapi-matcher.js +78 -108
- package/dist/adapters/standard/utils.js +28 -44
- package/dist/bracket-notation.d.ts +22 -22
- package/dist/bracket-notation.js +123 -173
- package/dist/client-factory.d.ts +12 -12
- package/dist/client-factory.js +13 -11
- package/dist/constants.d.ts +1 -4
- package/dist/constants.js +5 -4
- package/dist/extensions/route.d.ts +36 -36
- package/dist/extensions/route.js +7 -6
- package/dist/helpers/form-data.d.ts +1 -1
- package/dist/helpers/form-data.js +74 -86
- package/dist/helpers/index.d.ts +2 -1
- package/dist/helpers/index.js +1 -1
- package/dist/index.d.ts +15 -13
- package/dist/index.js +11 -11
- package/dist/meta.d.ts +298 -298
- package/dist/meta.js +54 -72
- package/dist/openapi-generator-components.d.ts +2 -31
- package/dist/openapi-generator-components.js +200 -248
- package/dist/openapi-generator-operation.d.ts +12 -33
- package/dist/openapi-generator-operation.js +369 -437
- package/dist/openapi-generator.d.ts +75 -80
- package/dist/openapi-generator.js +114 -142
- package/dist/openapi-json-serializer.d.ts +65 -65
- package/dist/openapi-json-serializer.js +218 -257
- package/dist/openapi-serializer.d.ts +31 -32
- package/dist/openapi-serializer.js +68 -92
- package/dist/plugins/index.d.ts +2 -1
- package/dist/plugins/index.js +1 -1
- package/dist/plugins/openapi-reference.d.ts +99 -102
- package/dist/plugins/openapi-reference.js +109 -132
- package/dist/router-utils.d.ts +7 -10
- package/dist/router-utils.js +30 -34
- package/dist/types.d.ts +8 -12
- package/dist/utils.d.ts +5 -10
- package/dist/utils.js +39 -42
- package/package.json +12 -12
- package/dist/adapters/standard/utils.d.ts +0 -4
- package/dist/types.js +0 -1
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import { Value } from "@orpc/shared";
|
|
2
|
+
import { AnyProcedureContract } from "@orpc/contract";
|
|
3
|
+
import { AnyProcedure, AnyRouter } from "@orpc/server";
|
|
4
4
|
export interface OpenAPIMatcherOptions {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Filter which procedures are exposed for matching. Return `false` to exclude.
|
|
7
|
+
*
|
|
8
|
+
* @default true
|
|
9
|
+
*/
|
|
10
|
+
filter?: Value<boolean, [contract: AnyProcedureContract | AnyProcedure, path: string[]]> | undefined;
|
|
11
11
|
}
|
|
12
12
|
export declare class OpenAPIMatcher {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
13
|
+
private readonly filter;
|
|
14
|
+
private readonly rootRouter;
|
|
15
|
+
private readonly tree;
|
|
16
|
+
private readonly pendingLazyRouters;
|
|
17
|
+
constructor(router: AnyRouter, options?: OpenAPIMatcherOptions);
|
|
18
|
+
private index;
|
|
19
|
+
match(method: string, pathname: `/${string}`, prefix: `/${string}` | undefined): Promise<{
|
|
20
|
+
path: string[];
|
|
21
|
+
procedure: AnyProcedure;
|
|
22
|
+
params?: Record<string, string> | undefined;
|
|
23
|
+
} | undefined>;
|
|
24
|
+
private resolvePendingLazyRouters;
|
|
25
|
+
private loadPendingLazyRouters;
|
|
26
|
+
private loadPendingLazyRouter;
|
|
27
|
+
private indexPendingLazyRouter;
|
|
28
|
+
private resolveProcedure;
|
|
29
|
+
}
|
|
@@ -1,108 +1,78 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import { mergeHttpPath, pathToHttpPath, value } from
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
async loadPendingLazyRouters(pathname) {
|
|
82
|
-
for (const pending of this.pendingLazyRouters) {
|
|
83
|
-
if (pending.matcher === undefined || pending.matcher(pathname)) {
|
|
84
|
-
await this.loadPendingLazyRouter(pending);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
loadPendingLazyRouter(pending) {
|
|
89
|
-
if (pending.loading === undefined) {
|
|
90
|
-
pending.loading = this.indexPendingLazyRouter(pending).catch((error) => {
|
|
91
|
-
pending.loading = undefined;
|
|
92
|
-
throw error;
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
return pending.loading;
|
|
96
|
-
}
|
|
97
|
-
async indexPendingLazyRouter(pending) {
|
|
98
|
-
const { default: router } = await unlazy(pending.router);
|
|
99
|
-
this.index(router, pending.path);
|
|
100
|
-
// removed only once indexed, so a concurrent match never observes this router as
|
|
101
|
-
// neither pending nor indexed
|
|
102
|
-
this.pendingLazyRouters.delete(pending);
|
|
103
|
-
}
|
|
104
|
-
async resolveProcedure(entry) {
|
|
105
|
-
entry.procedure = await resolveContractProcedure(this.rootRouter, entry.contract, entry.path);
|
|
106
|
-
return entry.procedure;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
1
|
+
import "../../constants.js";
|
|
2
|
+
import { getOpenAPIMeta } from "../../meta.js";
|
|
3
|
+
import { mergeHttpPath, pathToHttpPath, stripHttpPathPrefix, value } from "@orpc/shared";
|
|
4
|
+
import { Procedure, resolveContractProcedure, unlazy, walkProcedureContractsSync } from "@orpc/server";
|
|
5
|
+
import { Router as Router$1, createPrefixMatcher } from "@openapi-spec/router";
|
|
6
|
+
// src/adapters/standard/openapi-matcher.ts
|
|
7
|
+
var OpenAPIMatcher = class {
|
|
8
|
+
filter;
|
|
9
|
+
rootRouter;
|
|
10
|
+
tree = new Router$1();
|
|
11
|
+
pendingLazyRouters = /* @__PURE__ */ new Set();
|
|
12
|
+
constructor(router, options = {}) {
|
|
13
|
+
this.filter = options.filter ?? true;
|
|
14
|
+
this.rootRouter = router;
|
|
15
|
+
this.index(router);
|
|
16
|
+
}
|
|
17
|
+
index(router, path = []) {
|
|
18
|
+
const lazyResults = walkProcedureContractsSync(router, (contract, path) => {
|
|
19
|
+
if (!value(this.filter, contract, path)) return;
|
|
20
|
+
const meta = getOpenAPIMeta(contract);
|
|
21
|
+
const method = meta?.method ?? "POST";
|
|
22
|
+
const postHttpPath = meta?.path ?? pathToHttpPath(path);
|
|
23
|
+
const httpPath = meta?.prefix ? mergeHttpPath(meta.prefix, postHttpPath) : postHttpPath;
|
|
24
|
+
this.tree.add(method, httpPath, {
|
|
25
|
+
path,
|
|
26
|
+
contract,
|
|
27
|
+
procedure: contract instanceof Procedure ? contract : void 0
|
|
28
|
+
});
|
|
29
|
+
}, path);
|
|
30
|
+
for (const result of lazyResults) {
|
|
31
|
+
const prefix = getOpenAPIMeta(result.router)?.prefix;
|
|
32
|
+
this.pendingLazyRouters.add({
|
|
33
|
+
...result,
|
|
34
|
+
matcher: prefix ? createPrefixMatcher(prefix) : void 0
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
async match(method, pathname, prefix) {
|
|
39
|
+
if (prefix) {
|
|
40
|
+
const stripped = stripHttpPathPrefix(pathname, prefix);
|
|
41
|
+
if (stripped === void 0) return;
|
|
42
|
+
pathname = stripped;
|
|
43
|
+
}
|
|
44
|
+
const loading = this.resolvePendingLazyRouters(pathname);
|
|
45
|
+
if (loading !== void 0) await loading;
|
|
46
|
+
const match = this.tree.match(method, pathname);
|
|
47
|
+
if (match === void 0) return;
|
|
48
|
+
const entry = match.data;
|
|
49
|
+
return {
|
|
50
|
+
path: entry.path,
|
|
51
|
+
procedure: entry.procedure ?? await this.resolveProcedure(entry),
|
|
52
|
+
params: match.params
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
resolvePendingLazyRouters(pathname) {
|
|
56
|
+
for (const pending of this.pendingLazyRouters) if (pending.matcher === void 0 || pending.matcher(pathname)) return this.loadPendingLazyRouters(pathname);
|
|
57
|
+
}
|
|
58
|
+
async loadPendingLazyRouters(pathname) {
|
|
59
|
+
for (const pending of this.pendingLazyRouters) if (pending.matcher === void 0 || pending.matcher(pathname)) await this.loadPendingLazyRouter(pending);
|
|
60
|
+
}
|
|
61
|
+
loadPendingLazyRouter(pending) {
|
|
62
|
+
if (pending.loading === void 0) pending.loading = this.indexPendingLazyRouter(pending).catch((error) => {
|
|
63
|
+
pending.loading = void 0;
|
|
64
|
+
throw error;
|
|
65
|
+
});
|
|
66
|
+
return pending.loading;
|
|
67
|
+
}
|
|
68
|
+
async indexPendingLazyRouter(pending) {
|
|
69
|
+
const { default: router } = await unlazy(pending.router);
|
|
70
|
+
this.index(router, pending.path);
|
|
71
|
+
this.pendingLazyRouters.delete(pending);
|
|
72
|
+
}
|
|
73
|
+
async resolveProcedure(entry) {
|
|
74
|
+
entry.procedure = await resolveContractProcedure(this.rootRouter, entry.contract, entry.path);
|
|
75
|
+
return entry.procedure;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
export { OpenAPIMatcher };
|
|
@@ -1,47 +1,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return result;
|
|
1
|
+
import { NullProtoObj, isNonPrimitive } from "@orpc/shared";
|
|
2
|
+
// src/adapters/standard/utils.ts
|
|
3
|
+
function serializeHeaders(headers, serializer) {
|
|
4
|
+
const result = new NullProtoObj();
|
|
5
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
6
|
+
/**
|
|
7
|
+
* Only an actual array value represents a multi-value header (sent as multiple lines).
|
|
8
|
+
* Serialization can turn non-array values into arrays (e.g. Set, Map, custom handlers),
|
|
9
|
+
* and those must stay a single line, so the structure is checked before serializing.
|
|
10
|
+
*/
|
|
11
|
+
if (Array.isArray(value)) {
|
|
12
|
+
const lines = [];
|
|
13
|
+
for (const item of value) {
|
|
14
|
+
const line = serializeHeaderValue(item, serializer);
|
|
15
|
+
if (line !== void 0) lines.push(line);
|
|
16
|
+
}
|
|
17
|
+
result[key] = lines;
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
const line = serializeHeaderValue(value, serializer);
|
|
21
|
+
if (line !== void 0) result[key] = line;
|
|
22
|
+
}
|
|
23
|
+
return result;
|
|
27
24
|
}
|
|
28
25
|
function serializeHeaderValue(value, serializer) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
.map(String)
|
|
34
|
-
.join(',');
|
|
35
|
-
}
|
|
36
|
-
if (isNonPrimitive(serialized)) {
|
|
37
|
-
return Object.entries(serialized)
|
|
38
|
-
.filter(([, val]) => val !== undefined && val !== null)
|
|
39
|
-
.map(([key, val]) => `${key},${String(val)}`)
|
|
40
|
-
.join(',');
|
|
41
|
-
}
|
|
42
|
-
if (serialized !== undefined && serialized !== null) {
|
|
43
|
-
// oxlint-disable-next-line typescript/no-base-to-string
|
|
44
|
-
return String(serialized);
|
|
45
|
-
}
|
|
46
|
-
return undefined;
|
|
26
|
+
const serialized = serializer.serializeJson(value).json;
|
|
27
|
+
if (Array.isArray(serialized)) return serialized.filter((item) => item !== void 0 && item !== null).map(String).join(",");
|
|
28
|
+
if (isNonPrimitive(serialized)) return Object.entries(serialized).filter(([, val]) => val !== void 0 && val !== null).map(([key, val]) => `${key},${String(val)}`).join(",");
|
|
29
|
+
if (serialized !== void 0 && serialized !== null) return String(serialized);
|
|
47
30
|
}
|
|
31
|
+
export { serializeHeaders };
|
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Segment } from "@orpc/shared";
|
|
2
2
|
export type BracketNotationSerializeResult = [string, unknown][];
|
|
3
3
|
export interface BracketNotationSerializerOptions {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Maximum number of empty slots that explicit array indexes may leave in total during deserialization
|
|
6
|
+
* (e.g., `a[0]=x&a[3]=y` leaves 2). An index that would exceed it turns its array into an object
|
|
7
|
+
* instead (e.g., `?arr[5000]=x` becomes `{ arr: { 5000: 'x' } }`).
|
|
8
|
+
*
|
|
9
|
+
* Empty slots take memory (a lone `?arr[999]=x` takes ~12KB in V8), and code iterating an array walks
|
|
10
|
+
* every one of them, so this keeps both in line with the input.
|
|
11
|
+
*
|
|
12
|
+
* NOTE: Append-style notation (e.g., `arr[]`) never leaves empty slots.
|
|
13
|
+
*
|
|
14
|
+
* @default 1_000
|
|
15
|
+
*/
|
|
16
|
+
maxDeserializingEmptySlots?: number | undefined;
|
|
17
17
|
}
|
|
18
18
|
export declare class BracketNotationSerializer {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
19
|
+
private readonly maxDeserializingEmptySlots;
|
|
20
|
+
constructor(options?: BracketNotationSerializerOptions);
|
|
21
|
+
serialize(data: unknown): BracketNotationSerializeResult;
|
|
22
|
+
private internalSerialize;
|
|
23
|
+
deserialize(serialized: BracketNotationSerializeResult): Record<string, unknown>;
|
|
24
|
+
stringifyPath(segments: readonly Segment[]): string;
|
|
25
|
+
parsePath(path: string): string[];
|
|
26
|
+
}
|