@orpc/openapi 2.0.0-beta.47 → 2.0.0-beta.48
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/README.md +2 -3
- package/dist/adapters/aws-lambda/index.d.mts +14 -26
- package/dist/adapters/aws-lambda/index.mjs +1 -21
- package/dist/adapters/aws-lambda/openapi-handler.d.mts +17 -0
- package/dist/adapters/aws-lambda/openapi-handler.mjs +11 -0
- package/dist/adapters/fastify/index.d.mts +1 -23
- package/dist/adapters/fastify/index.mjs +1 -21
- package/dist/adapters/fastify/openapi-handler.d.mts +14 -0
- package/dist/adapters/fastify/openapi-handler.mjs +11 -0
- package/dist/adapters/fetch/index.d.mts +2 -37
- package/dist/adapters/fetch/index.mjs +2 -34
- package/dist/adapters/fetch/openapi-handler.d.mts +14 -0
- package/dist/adapters/fetch/openapi-handler.mjs +11 -0
- package/dist/adapters/fetch/openapi-link.d.mts +15 -0
- package/dist/adapters/fetch/openapi-link.mjs +11 -0
- package/dist/adapters/node/index.d.mts +1 -23
- package/dist/adapters/node/index.mjs +1 -21
- package/dist/adapters/node/openapi-handler.d.mts +14 -0
- package/dist/adapters/node/openapi-handler.mjs +11 -0
- package/dist/adapters/standard/index.d.mts +3 -56
- package/dist/adapters/standard/index.mjs +3 -12
- package/dist/adapters/standard/openapi-handler-codec.d.mts +61 -0
- package/dist/adapters/standard/openapi-handler-codec.mjs +203 -0
- package/dist/adapters/standard/openapi-link-codec.d.mts +53 -0
- package/dist/adapters/standard/openapi-link-codec.mjs +356 -0
- package/dist/adapters/standard/openapi-matcher.d.mts +29 -0
- package/dist/adapters/standard/openapi-matcher.mjs +105 -0
- package/dist/adapters/standard/utils.d.mts +4 -0
- package/dist/adapters/standard/utils.mjs +36 -0
- package/dist/bracket-notation.d.mts +26 -0
- package/dist/bracket-notation.mjs +156 -0
- package/dist/client-factory.d.mts +24 -0
- package/dist/client-factory.mjs +5 -0
- package/dist/constants.d.mts +4 -0
- package/dist/constants.mjs +4 -0
- package/dist/extensions/route.d.mts +74 -39
- package/dist/extensions/route.mjs +8 -10
- package/dist/helpers/form-data.d.mts +57 -0
- package/dist/helpers/form-data.mjs +36 -0
- package/dist/helpers/index.d.mts +1 -59
- package/dist/helpers/index.mjs +1 -39
- package/dist/index.d.mts +13 -166
- package/dist/index.mjs +11 -780
- package/dist/meta.d.mts +345 -0
- package/dist/meta.mjs +56 -0
- package/dist/openapi-generator-components.d.mts +24 -0
- package/dist/openapi-generator-components.mjs +227 -0
- package/dist/openapi-generator-operation.d.mts +29 -0
- package/dist/openapi-generator-operation.mjs +447 -0
- package/dist/openapi-generator.d.mts +87 -0
- package/dist/openapi-generator.mjs +115 -0
- package/dist/openapi-json-serializer.d.mts +86 -0
- package/dist/openapi-json-serializer.mjs +229 -0
- package/dist/openapi-serializer.d.mts +43 -0
- package/dist/openapi-serializer.mjs +87 -0
- package/dist/plugins/index.d.mts +1 -121
- package/dist/plugins/index.mjs +1 -167
- package/dist/plugins/openapi-reference.d.mts +118 -0
- package/dist/plugins/openapi-reference.mjs +157 -0
- package/dist/router-utils.d.mts +18 -0
- package/dist/router-utils.mjs +29 -0
- package/dist/types.d.mts +27 -0
- package/dist/types.mjs +1 -0
- package/dist/utils.d.mts +14 -0
- package/dist/utils.mjs +40 -0
- package/package.json +15 -15
- package/dist/adapters/aws-lambda/index.d.ts +0 -27
- package/dist/adapters/fastify/index.d.ts +0 -23
- package/dist/adapters/fetch/index.d.ts +0 -37
- package/dist/adapters/node/index.d.ts +0 -23
- package/dist/adapters/standard/index.d.ts +0 -56
- package/dist/extensions/route.d.ts +0 -41
- package/dist/helpers/index.d.ts +0 -59
- package/dist/index.d.ts +0 -166
- package/dist/plugins/index.d.ts +0 -121
- package/dist/shared/openapi.B9PQzqBn.mjs +0 -49
- package/dist/shared/openapi.CQkXu1nY.mjs +0 -366
- package/dist/shared/openapi.Covi8zVE.d.mts +0 -33
- package/dist/shared/openapi.Covi8zVE.d.ts +0 -33
- package/dist/shared/openapi.DfmCR1pB.d.mts +0 -94
- package/dist/shared/openapi.DtEVcxuW.mjs +0 -149
- package/dist/shared/openapi.E3ZBiweM.mjs +0 -353
- package/dist/shared/openapi.Y4K_-I5W.d.ts +0 -94
- package/dist/shared/openapi.YMRD3b4R.d.mts +0 -157
- package/dist/shared/openapi.YMRD3b4R.d.ts +0 -157
- package/dist/shared/openapi.g7ucL05o.mjs +0 -410
- package/dist/shared/openapi.zGZlCOwp.d.mts +0 -329
- package/dist/shared/openapi.zGZlCOwp.d.ts +0 -329
|
@@ -1,366 +0,0 @@
|
|
|
1
|
-
import { MalformedResponseError, isORPCErrorJson, createORPCErrorFromJson, ResponseError } from '@orpc/client';
|
|
2
|
-
import { getRouterContract, ProcedureContract } from '@orpc/contract';
|
|
3
|
-
import { unlazy } from '@orpc/server';
|
|
4
|
-
import { value, pathToHttpPath, mergeHttpPath, isTypescriptObject, stringifyJSON, safeEncodeURIComponent } from '@orpc/shared';
|
|
5
|
-
import { mergeStandardHeaders, parseStandardUrl, flattenStandardHeader } from '@standard-server/core';
|
|
6
|
-
import { toStandardHeaders } from '@standard-server/fetch';
|
|
7
|
-
import { O as OpenAPISerializer, D as DEFAULT_OPENAPI_METHOD, a as DEFAULT_OPENAPI_INPUT_STRUCTURE, g as getDynamicPathParams, i as isBodylessMethod, b as DEFAULT_OPENAPI_OUTPUT_STRUCTURE } from './openapi.E3ZBiweM.mjs';
|
|
8
|
-
import { g as getOpenAPIMeta } from './openapi.B9PQzqBn.mjs';
|
|
9
|
-
import { s as serializeHeaders } from './openapi.g7ucL05o.mjs';
|
|
10
|
-
|
|
11
|
-
const END_SLASH_REGEX = /\/$/;
|
|
12
|
-
const DOT_SEGMENT_REGEX = /(?:^|\/)\.{1,2}(?:\/|$)/;
|
|
13
|
-
class OpenAPILinkCodec {
|
|
14
|
-
constructor(router, options = {}) {
|
|
15
|
-
this.router = router;
|
|
16
|
-
this.baseUrl = options.url ?? "/";
|
|
17
|
-
this.headers = options.headers ?? {};
|
|
18
|
-
this.serializer = options.serializer ?? new OpenAPISerializer();
|
|
19
|
-
this.errorResponseBodyDecoder = options.errorResponseBodyDecoder;
|
|
20
|
-
this.errorResponseMediaType = toMediaType(options.errorResponseContentType);
|
|
21
|
-
}
|
|
22
|
-
baseUrl;
|
|
23
|
-
headers;
|
|
24
|
-
serializer;
|
|
25
|
-
errorResponseBodyDecoder;
|
|
26
|
-
errorResponseMediaType;
|
|
27
|
-
async encodeInput(input, path, options) {
|
|
28
|
-
let headers = toResolvedStandardHeaders(await value(this.headers, options, path, input));
|
|
29
|
-
if (options.lastEventId !== void 0) {
|
|
30
|
-
headers = mergeStandardHeaders(headers, { "last-event-id": options.lastEventId });
|
|
31
|
-
}
|
|
32
|
-
const baseUrl = await value(this.baseUrl, options, path, input);
|
|
33
|
-
const procedure = await this.resolveProcedure(path);
|
|
34
|
-
const meta = getOpenAPIMeta(procedure);
|
|
35
|
-
const method = meta?.method ?? DEFAULT_OPENAPI_METHOD;
|
|
36
|
-
const inputStructure = meta?.inputStructure ?? DEFAULT_OPENAPI_INPUT_STRUCTURE;
|
|
37
|
-
let pathname = meta?.path ?? pathToHttpPath(path);
|
|
38
|
-
if (meta?.prefix) {
|
|
39
|
-
pathname = mergeHttpPath(meta.prefix, pathname);
|
|
40
|
-
}
|
|
41
|
-
const [basePathname, baseSearch, baseHash] = parseStandardUrl(baseUrl);
|
|
42
|
-
const dynamicParams = getDynamicPathParams(pathname);
|
|
43
|
-
if (inputStructure === "compact") {
|
|
44
|
-
let data = input;
|
|
45
|
-
if (dynamicParams?.length) {
|
|
46
|
-
if (!isTypescriptObject(input)) {
|
|
47
|
-
throw new TypeError(
|
|
48
|
-
`Input must be an object with "compact" input structure when the path has dynamic params (${dynamicParams.map((p) => p.parameterName).join(", ")}) in call to procedure (${path.join(".")}).`
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
const remaining = { ...input };
|
|
52
|
-
for (let i = dynamicParams.length - 1; i >= 0; i--) {
|
|
53
|
-
const param = dynamicParams[i];
|
|
54
|
-
const encoded = this.encodePathParam(input[param.parameterName], param, meta?.paramsStyles?.[param.parameterName], path);
|
|
55
|
-
pathname = `${pathname.slice(0, param.startIndex)}${encoded}${pathname.slice(param.startIndex + param.segment.length)}`;
|
|
56
|
-
delete remaining[param.parameterName];
|
|
57
|
-
}
|
|
58
|
-
data = Object.keys(remaining).length > 0 ? remaining : void 0;
|
|
59
|
-
}
|
|
60
|
-
pathname = `${basePathname.replace(END_SLASH_REGEX, "")}${pathname}`;
|
|
61
|
-
if (isBodylessMethod(method)) {
|
|
62
|
-
const queryString2 = this.serializeQueryString(data, meta?.queryStyles);
|
|
63
|
-
const search2 = combineSearch(baseSearch, queryString2);
|
|
64
|
-
const url3 = `${pathname}${search2 ?? ""}${baseHash ?? ""}`;
|
|
65
|
-
return {
|
|
66
|
-
body: void 0,
|
|
67
|
-
method,
|
|
68
|
-
headers,
|
|
69
|
-
url: url3,
|
|
70
|
-
signal: options.signal
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
const url2 = `${pathname}${baseSearch ?? ""}${baseHash ?? ""}`;
|
|
74
|
-
return {
|
|
75
|
-
url: url2,
|
|
76
|
-
method,
|
|
77
|
-
headers,
|
|
78
|
-
body: this.serializer.serialize(data),
|
|
79
|
-
signal: options.signal
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
if (!isValidDetailedInput(input)) {
|
|
83
|
-
throw new TypeError(`
|
|
84
|
-
Invalid "detailed" input structure in call to procedure (${path.join(".")}):
|
|
85
|
-
\u2022 Expected an object or undefined with optional properties:
|
|
86
|
-
- params (object, required when the path has dynamic params)
|
|
87
|
-
- query (object)
|
|
88
|
-
- headers (object)
|
|
89
|
-
- body (any)
|
|
90
|
-
|
|
91
|
-
Actual value:
|
|
92
|
-
${stringifyJSON(input)}
|
|
93
|
-
`);
|
|
94
|
-
}
|
|
95
|
-
if (dynamicParams?.length) {
|
|
96
|
-
if (!input?.params) {
|
|
97
|
-
throw new TypeError(
|
|
98
|
-
`The "params" property is required for "detailed" input when the path has dynamic params (${dynamicParams.map((p) => p.parameterName).join(", ")}) in call to procedure (${path.join(".")}).`
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
for (let i = dynamicParams.length - 1; i >= 0; i--) {
|
|
102
|
-
const param = dynamicParams[i];
|
|
103
|
-
const val = input.params[param.parameterName];
|
|
104
|
-
const encoded = this.encodePathParam(val, param, meta?.paramsStyles?.[param.parameterName], path);
|
|
105
|
-
pathname = `${pathname.slice(0, param.startIndex)}${encoded}${pathname.slice(param.startIndex + param.segment.length)}`;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
if (input?.headers) {
|
|
109
|
-
headers = mergeStandardHeaders(headers, serializeHeaders(input.headers, this.serializer));
|
|
110
|
-
}
|
|
111
|
-
pathname = `${basePathname.replace(END_SLASH_REGEX, "")}${pathname}`;
|
|
112
|
-
const queryString = this.serializeQueryString(input?.query, meta?.queryStyles);
|
|
113
|
-
const search = combineSearch(baseSearch, queryString);
|
|
114
|
-
const url = `${pathname}${search ?? ""}${baseHash ?? ""}`;
|
|
115
|
-
if (isBodylessMethod(method)) {
|
|
116
|
-
return {
|
|
117
|
-
body: void 0,
|
|
118
|
-
method,
|
|
119
|
-
headers,
|
|
120
|
-
url,
|
|
121
|
-
signal: options.signal
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
return {
|
|
125
|
-
url,
|
|
126
|
-
method,
|
|
127
|
-
headers,
|
|
128
|
-
body: this.serializer.serialize(input?.body),
|
|
129
|
-
signal: options.signal
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
encodePathParam(val, param, style, path) {
|
|
133
|
-
let encoded;
|
|
134
|
-
if (style === "comma-delimited-array" && Array.isArray(val)) {
|
|
135
|
-
encoded = val.map((val2) => this.serializer.serialize(val2)).filter((val2) => val2 !== void 0 && val2 !== null).map((val2) => safeEncodeURIComponent(String(val2))).join(",");
|
|
136
|
-
} else if (style === "comma-delimited-object" && isTypescriptObject(val)) {
|
|
137
|
-
encoded = Object.entries(val).map(([key, val2]) => [key, this.serializer.serialize(val2)]).filter(([, val2]) => val2 !== void 0 && val2 !== null).map(([key, val2]) => `${safeEncodeURIComponent(String(key))},${safeEncodeURIComponent(String(val2))}`).join(",");
|
|
138
|
-
} else {
|
|
139
|
-
const serialized = this.serializer.serialize(val);
|
|
140
|
-
if (serialized !== void 0 && serialized !== null) {
|
|
141
|
-
if (param.allowsSlash) {
|
|
142
|
-
encoded = String(serialized).split("/").map(safeEncodeURIComponent).join("/");
|
|
143
|
-
} else {
|
|
144
|
-
encoded = safeEncodeURIComponent(String(serialized));
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
if (!encoded) {
|
|
149
|
-
throw new TypeError(`Path param "${param.parameterName}" cannot be empty in call to procedure (${path.join(".")}).`);
|
|
150
|
-
}
|
|
151
|
-
if (DOT_SEGMENT_REGEX.test(encoded)) {
|
|
152
|
-
throw new TypeError(`Path param "${param.parameterName}" cannot contain "." or ".." segments in call to procedure (${path.join(".")}).`);
|
|
153
|
-
}
|
|
154
|
-
if (encoded.startsWith("/")) {
|
|
155
|
-
encoded = `%2F${encoded.slice(1)}`;
|
|
156
|
-
}
|
|
157
|
-
return encoded;
|
|
158
|
-
}
|
|
159
|
-
serializeQueryString(data, queryStyles) {
|
|
160
|
-
if (!queryStyles || !isTypescriptObject(data)) {
|
|
161
|
-
return toURLSearchParams(
|
|
162
|
-
this.serializer.serialize(data, { asFormData: true })
|
|
163
|
-
).toString();
|
|
164
|
-
}
|
|
165
|
-
const remaining = { ...data };
|
|
166
|
-
let query = "";
|
|
167
|
-
Object.entries(queryStyles).forEach(([key, style]) => {
|
|
168
|
-
if (style === void 0) {
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
171
|
-
const value2 = remaining[key];
|
|
172
|
-
delete remaining[key];
|
|
173
|
-
if (style === "primitive") {
|
|
174
|
-
const serialized = this.serializer.serialize(value2);
|
|
175
|
-
if (serialized !== void 0 && serialized !== null) {
|
|
176
|
-
query += `&${encodeURLSearchParamComponent(key)}=${encodeURLSearchParamComponent(String(serialized))}`;
|
|
177
|
-
}
|
|
178
|
-
} else if (style === "array" && Array.isArray(value2)) {
|
|
179
|
-
const encodedKey = encodeURLSearchParamComponent(key);
|
|
180
|
-
value2.forEach((v) => {
|
|
181
|
-
const s = this.serializer.serialize(v);
|
|
182
|
-
if (s !== void 0 && s !== null) {
|
|
183
|
-
query += `&${encodedKey}=${encodeURLSearchParamComponent(String(s))}`;
|
|
184
|
-
}
|
|
185
|
-
});
|
|
186
|
-
} else if (style === "json") {
|
|
187
|
-
const serialized = this.serializer.serialize(value2);
|
|
188
|
-
if (serialized !== void 0) {
|
|
189
|
-
query += `&${encodeURLSearchParamComponent(key)}=${encodeURLSearchParamComponent(stringifyJSON(serialized))}`;
|
|
190
|
-
}
|
|
191
|
-
} else if (style === "comma-delimited-array" && Array.isArray(value2)) {
|
|
192
|
-
const encodedValue = encodeDelimitedArray(
|
|
193
|
-
value2.map((v) => this.serializer.serialize(v)),
|
|
194
|
-
","
|
|
195
|
-
);
|
|
196
|
-
if (encodedValue !== void 0) {
|
|
197
|
-
query += `&${encodeURLSearchParamComponent(key)}=${encodedValue}`;
|
|
198
|
-
}
|
|
199
|
-
} else if (style === "comma-delimited-object" && isTypescriptObject(value2)) {
|
|
200
|
-
const encodedValue = encodeDelimitedObject(
|
|
201
|
-
Object.entries(value2).map(([key2, value3]) => [key2, this.serializer.serialize(value3)]),
|
|
202
|
-
","
|
|
203
|
-
);
|
|
204
|
-
if (encodedValue !== void 0) {
|
|
205
|
-
query += `&${encodeURLSearchParamComponent(key)}=${encodedValue}`;
|
|
206
|
-
}
|
|
207
|
-
} else if (style === "pipe-delimited-array" && Array.isArray(value2)) {
|
|
208
|
-
const encodedValue = encodeDelimitedArray(
|
|
209
|
-
value2.map((v) => this.serializer.serialize(v)),
|
|
210
|
-
"%7C"
|
|
211
|
-
);
|
|
212
|
-
if (encodedValue !== void 0) {
|
|
213
|
-
query += `&${encodeURLSearchParamComponent(key)}=${encodedValue}`;
|
|
214
|
-
}
|
|
215
|
-
} else if (style === "pipe-delimited-object" && isTypescriptObject(value2)) {
|
|
216
|
-
const encodedValue = encodeDelimitedObject(
|
|
217
|
-
Object.entries(value2).map(([key2, value3]) => [key2, this.serializer.serialize(value3)]),
|
|
218
|
-
"%7C"
|
|
219
|
-
);
|
|
220
|
-
if (encodedValue !== void 0) {
|
|
221
|
-
query += `&${encodeURLSearchParamComponent(key)}=${encodedValue}`;
|
|
222
|
-
}
|
|
223
|
-
} else if (style === "space-delimited-array" && Array.isArray(value2)) {
|
|
224
|
-
const encodedValue = encodeDelimitedArray(
|
|
225
|
-
value2.map((v) => this.serializer.serialize(v)),
|
|
226
|
-
"%20"
|
|
227
|
-
);
|
|
228
|
-
if (encodedValue !== void 0) {
|
|
229
|
-
query += `&${encodeURLSearchParamComponent(key)}=${encodedValue}`;
|
|
230
|
-
}
|
|
231
|
-
} else if (style === "space-delimited-object" && isTypescriptObject(value2)) {
|
|
232
|
-
const encodedValue = encodeDelimitedObject(
|
|
233
|
-
Object.entries(value2).map(([key2, value3]) => [key2, this.serializer.serialize(value3)]),
|
|
234
|
-
"%20"
|
|
235
|
-
);
|
|
236
|
-
if (encodedValue !== void 0) {
|
|
237
|
-
query += `&${encodeURLSearchParamComponent(key)}=${encodedValue}`;
|
|
238
|
-
}
|
|
239
|
-
} else {
|
|
240
|
-
const serialized = this.serializer.serialize(value2);
|
|
241
|
-
if (serialized !== void 0 && serialized !== null) {
|
|
242
|
-
query += `&${encodeURLSearchParamComponent(key)}=${encodeURLSearchParamComponent(String(serialized))}`;
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
});
|
|
246
|
-
const form = this.serializer.serialize(remaining, { asFormData: true });
|
|
247
|
-
query = `${toURLSearchParams(form).toString()}${query}`;
|
|
248
|
-
if (query.startsWith("&")) {
|
|
249
|
-
query = query.slice(1);
|
|
250
|
-
}
|
|
251
|
-
return query || void 0;
|
|
252
|
-
}
|
|
253
|
-
async decodeResponse(response, path, _options) {
|
|
254
|
-
const isOk = response.status < 400;
|
|
255
|
-
const procedure = await this.resolveProcedure(path);
|
|
256
|
-
const meta = getOpenAPIMeta(procedure);
|
|
257
|
-
const errorBodyHint = !isOk && this.errorResponseMediaType !== void 0 && toMediaType(flattenStandardHeader(response.headers["content-type"])) === this.errorResponseMediaType ? "json" : void 0;
|
|
258
|
-
const body = await response.resolveBody(isOk ? meta?.responseBodyHint : errorBodyHint);
|
|
259
|
-
const deserialized = await (async () => {
|
|
260
|
-
try {
|
|
261
|
-
return this.serializer.deserialize(body);
|
|
262
|
-
} catch (error) {
|
|
263
|
-
throw new MalformedResponseError({
|
|
264
|
-
message: "Invalid OpenAPI response format.",
|
|
265
|
-
response: { status: response.status, headers: response.headers, body },
|
|
266
|
-
cause: error
|
|
267
|
-
});
|
|
268
|
-
}
|
|
269
|
-
})();
|
|
270
|
-
if (!isOk) {
|
|
271
|
-
const customError = this.errorResponseBodyDecoder?.(deserialized, response);
|
|
272
|
-
if (customError !== void 0 && customError !== null) {
|
|
273
|
-
return { kind: "error", error: customError };
|
|
274
|
-
}
|
|
275
|
-
if (isORPCErrorJson(deserialized)) {
|
|
276
|
-
return {
|
|
277
|
-
kind: "error",
|
|
278
|
-
error: createORPCErrorFromJson(deserialized, {
|
|
279
|
-
cause: new ResponseError({ response: { status: response.status, headers: response.headers, body } })
|
|
280
|
-
})
|
|
281
|
-
};
|
|
282
|
-
}
|
|
283
|
-
throw new MalformedResponseError({ response: { headers: response.headers, status: response.status, body } });
|
|
284
|
-
}
|
|
285
|
-
const outputStructure = meta?.outputStructure ?? DEFAULT_OPENAPI_OUTPUT_STRUCTURE;
|
|
286
|
-
return outputStructure === "compact" ? { kind: "output", output: deserialized } : {
|
|
287
|
-
kind: "output",
|
|
288
|
-
output: {
|
|
289
|
-
status: response.status,
|
|
290
|
-
headers: response.headers,
|
|
291
|
-
body: deserialized
|
|
292
|
-
}
|
|
293
|
-
};
|
|
294
|
-
}
|
|
295
|
-
async resolveProcedure(path) {
|
|
296
|
-
const { default: maybeProcedure } = await unlazy(getRouterContract(this.router, path));
|
|
297
|
-
if (!(maybeProcedure instanceof ProcedureContract)) {
|
|
298
|
-
throw new TypeError(`Expected a procedure or contract at path (${path.join(".")})`);
|
|
299
|
-
}
|
|
300
|
-
return maybeProcedure;
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
function combineSearch(baseSearch, additionalSearch) {
|
|
304
|
-
if (!baseSearch && !additionalSearch) {
|
|
305
|
-
return void 0;
|
|
306
|
-
}
|
|
307
|
-
if (!additionalSearch) {
|
|
308
|
-
return baseSearch;
|
|
309
|
-
}
|
|
310
|
-
if (!baseSearch) {
|
|
311
|
-
return `?${additionalSearch}`;
|
|
312
|
-
}
|
|
313
|
-
return `${baseSearch}&${additionalSearch}`;
|
|
314
|
-
}
|
|
315
|
-
function toMediaType(contentType) {
|
|
316
|
-
return contentType?.split(";")[0]?.trim().toLowerCase();
|
|
317
|
-
}
|
|
318
|
-
function toResolvedStandardHeaders(headers) {
|
|
319
|
-
if (typeof headers.forEach === "function") {
|
|
320
|
-
return toStandardHeaders(headers);
|
|
321
|
-
}
|
|
322
|
-
return headers;
|
|
323
|
-
}
|
|
324
|
-
function isValidDetailedInput(input) {
|
|
325
|
-
if (!isTypescriptObject(input)) {
|
|
326
|
-
return input === void 0;
|
|
327
|
-
}
|
|
328
|
-
if (input.params !== void 0 && !isTypescriptObject(input.params)) {
|
|
329
|
-
return false;
|
|
330
|
-
}
|
|
331
|
-
if (input.query !== void 0 && !isTypescriptObject(input.query)) {
|
|
332
|
-
return false;
|
|
333
|
-
}
|
|
334
|
-
if (input.headers !== void 0 && !isTypescriptObject(input.headers)) {
|
|
335
|
-
return false;
|
|
336
|
-
}
|
|
337
|
-
return true;
|
|
338
|
-
}
|
|
339
|
-
function encodeURLSearchParamComponent(value2) {
|
|
340
|
-
return new URLSearchParams({ "": value2 }).toString().slice(1);
|
|
341
|
-
}
|
|
342
|
-
function toURLSearchParams(form) {
|
|
343
|
-
const params = new URLSearchParams();
|
|
344
|
-
for (const [key, value2] of form) {
|
|
345
|
-
params.append(key, String(value2));
|
|
346
|
-
}
|
|
347
|
-
return params;
|
|
348
|
-
}
|
|
349
|
-
function encodeDelimitedArray(serializedValues, encodedDelimiter) {
|
|
350
|
-
const strings = serializedValues.filter((v) => v !== null && v !== void 0).map(String);
|
|
351
|
-
if (!strings.length) {
|
|
352
|
-
return void 0;
|
|
353
|
-
}
|
|
354
|
-
return strings.map(encodeURLSearchParamComponent).join(encodedDelimiter);
|
|
355
|
-
}
|
|
356
|
-
function encodeDelimitedObject(entries, encodedDelimiter) {
|
|
357
|
-
const strings = entries.filter(([, v]) => v !== null && v !== void 0).map(([k, v]) => [k, String(v)]);
|
|
358
|
-
if (!strings.length) {
|
|
359
|
-
return void 0;
|
|
360
|
-
}
|
|
361
|
-
return strings.map(
|
|
362
|
-
([key, value2]) => `${encodeURLSearchParamComponent(key)}${encodedDelimiter}${encodeURLSearchParamComponent(value2)}`
|
|
363
|
-
).join(encodedDelimiter);
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
export { OpenAPILinkCodec as O };
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import * as OpenAPIV3_0 from '@openapi-spec/types/v3.0';
|
|
2
|
-
import * as OpenAPIV3_1 from '@openapi-spec/types/v3.1';
|
|
3
|
-
import * as OpenAPIV3_2 from '@openapi-spec/types/v3.2';
|
|
4
|
-
import { AnyNestedClient, Client, ORPCError } from '@orpc/client';
|
|
5
|
-
import { AsyncIteratorClass } from '@orpc/shared';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* An OpenAPI version `OpenAPIGenerator` can target: any `3.0.x`, `3.1.x`, or `3.2.x` value.
|
|
9
|
-
*
|
|
10
|
-
* @see {@link https://orpc.dev/docs/openapi/specification#openapi-version | OpenAPI Specification - OpenAPI Version}
|
|
11
|
-
*/
|
|
12
|
-
type OpenAPIVersion = `3.0.${number}` | `3.1.${number}` | `3.2.${number}`;
|
|
13
|
-
/**
|
|
14
|
-
* The OpenAPI document of the given version.
|
|
15
|
-
*
|
|
16
|
-
* @see {@link https://orpc.dev/docs/openapi/specification#openapi-version | OpenAPI Specification - OpenAPI Version}
|
|
17
|
-
*/
|
|
18
|
-
type OpenAPIDocument<TVersion extends OpenAPIVersion> = TVersion extends `3.0.${string}` ? OpenAPIV3_0.OpenAPIObject : TVersion extends `3.1.${string}` ? OpenAPIV3_1.OpenAPIObject : OpenAPIV3_2.OpenAPIObject;
|
|
19
|
-
type JsonifiedValue<T> = T extends string | number | boolean | null | undefined ? T : T extends Date | bigint | URL ? string : T extends ReadonlyArray<unknown> ? JsonifiedArray<T> : T extends Blob | ReadonlyMap<any, any> | ReadonlySet<any> | AsyncIteratorObject<any, any, any> | Function ? T extends File ? File : T extends Blob ? Blob : T extends ReadonlyMap<infer K, infer V> ? JsonifiedArray<[K, V][]> : T extends ReadonlySet<infer U> ? JsonifiedArray<U[]> : T extends AsyncIteratorClass<infer U, infer V> ? AsyncIteratorClass<JsonifiedValue<U>, JsonifiedValue<V>> : T extends AsyncGenerator<infer U, infer V> ? AsyncGenerator<JsonifiedValue<U>, JsonifiedValue<V>> : T extends AsyncIteratorObject<infer U, infer V> ? AsyncIteratorObject<JsonifiedValue<U>, JsonifiedValue<V>> : unknown : T extends object ? {
|
|
20
|
-
[K in keyof T]: JsonifiedValue<T[K]>;
|
|
21
|
-
} : unknown;
|
|
22
|
-
type JsonifiedArray<T extends ReadonlyArray<unknown>> = T extends readonly [] ? [] : T extends readonly [infer U, ...infer V] ? [U extends undefined ? null : JsonifiedValue<U>, ...JsonifiedArray<V>] : T extends ReadonlyArray<infer U> ? Array<JsonifiedValue<U>> : unknown;
|
|
23
|
-
type JsonifiedClientError<T> = T extends ORPCError<infer UCode, infer UData> ? ORPCError<UCode, JsonifiedValue<UData>> : T;
|
|
24
|
-
/**
|
|
25
|
-
* Client type whose outputs and error data replace types JSON cannot represent with their JSON equivalents.
|
|
26
|
-
*
|
|
27
|
-
* @see {@link https://orpc.dev/docs/openapi/link | OpenAPI Link}
|
|
28
|
-
*/
|
|
29
|
-
type JsonifiedClient<T extends AnyNestedClient> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? Client<UClientContext, UInput, JsonifiedValue<UOutput>, JsonifiedClientError<UError>> : {
|
|
30
|
-
[K in keyof T]: T[K] extends AnyNestedClient ? JsonifiedClient<T[K]> : T[K];
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export type { JsonifiedClient as J, OpenAPIDocument as O, OpenAPIVersion as a, JsonifiedArray as b, JsonifiedClientError as c, JsonifiedValue as d };
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import * as OpenAPIV3_0 from '@openapi-spec/types/v3.0';
|
|
2
|
-
import * as OpenAPIV3_1 from '@openapi-spec/types/v3.1';
|
|
3
|
-
import * as OpenAPIV3_2 from '@openapi-spec/types/v3.2';
|
|
4
|
-
import { AnyNestedClient, Client, ORPCError } from '@orpc/client';
|
|
5
|
-
import { AsyncIteratorClass } from '@orpc/shared';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* An OpenAPI version `OpenAPIGenerator` can target: any `3.0.x`, `3.1.x`, or `3.2.x` value.
|
|
9
|
-
*
|
|
10
|
-
* @see {@link https://orpc.dev/docs/openapi/specification#openapi-version | OpenAPI Specification - OpenAPI Version}
|
|
11
|
-
*/
|
|
12
|
-
type OpenAPIVersion = `3.0.${number}` | `3.1.${number}` | `3.2.${number}`;
|
|
13
|
-
/**
|
|
14
|
-
* The OpenAPI document of the given version.
|
|
15
|
-
*
|
|
16
|
-
* @see {@link https://orpc.dev/docs/openapi/specification#openapi-version | OpenAPI Specification - OpenAPI Version}
|
|
17
|
-
*/
|
|
18
|
-
type OpenAPIDocument<TVersion extends OpenAPIVersion> = TVersion extends `3.0.${string}` ? OpenAPIV3_0.OpenAPIObject : TVersion extends `3.1.${string}` ? OpenAPIV3_1.OpenAPIObject : OpenAPIV3_2.OpenAPIObject;
|
|
19
|
-
type JsonifiedValue<T> = T extends string | number | boolean | null | undefined ? T : T extends Date | bigint | URL ? string : T extends ReadonlyArray<unknown> ? JsonifiedArray<T> : T extends Blob | ReadonlyMap<any, any> | ReadonlySet<any> | AsyncIteratorObject<any, any, any> | Function ? T extends File ? File : T extends Blob ? Blob : T extends ReadonlyMap<infer K, infer V> ? JsonifiedArray<[K, V][]> : T extends ReadonlySet<infer U> ? JsonifiedArray<U[]> : T extends AsyncIteratorClass<infer U, infer V> ? AsyncIteratorClass<JsonifiedValue<U>, JsonifiedValue<V>> : T extends AsyncGenerator<infer U, infer V> ? AsyncGenerator<JsonifiedValue<U>, JsonifiedValue<V>> : T extends AsyncIteratorObject<infer U, infer V> ? AsyncIteratorObject<JsonifiedValue<U>, JsonifiedValue<V>> : unknown : T extends object ? {
|
|
20
|
-
[K in keyof T]: JsonifiedValue<T[K]>;
|
|
21
|
-
} : unknown;
|
|
22
|
-
type JsonifiedArray<T extends ReadonlyArray<unknown>> = T extends readonly [] ? [] : T extends readonly [infer U, ...infer V] ? [U extends undefined ? null : JsonifiedValue<U>, ...JsonifiedArray<V>] : T extends ReadonlyArray<infer U> ? Array<JsonifiedValue<U>> : unknown;
|
|
23
|
-
type JsonifiedClientError<T> = T extends ORPCError<infer UCode, infer UData> ? ORPCError<UCode, JsonifiedValue<UData>> : T;
|
|
24
|
-
/**
|
|
25
|
-
* Client type whose outputs and error data replace types JSON cannot represent with their JSON equivalents.
|
|
26
|
-
*
|
|
27
|
-
* @see {@link https://orpc.dev/docs/openapi/link | OpenAPI Link}
|
|
28
|
-
*/
|
|
29
|
-
type JsonifiedClient<T extends AnyNestedClient> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? Client<UClientContext, UInput, JsonifiedValue<UOutput>, JsonifiedClientError<UError>> : {
|
|
30
|
-
[K in keyof T]: T[K] extends AnyNestedClient ? JsonifiedClient<T[K]> : T[K];
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export type { JsonifiedClient as J, OpenAPIDocument as O, OpenAPIVersion as a, JsonifiedArray as b, JsonifiedClientError as c, JsonifiedValue as d };
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { AnyORPCError } from '@orpc/client';
|
|
2
|
-
import { AnyProcedure, AnyRouter, Context } from '@orpc/server';
|
|
3
|
-
import { StandardHandlerCodec, ResolvedStandardHandlerHandleOptions, StandardHandlerCodecResolvedProcedure } from '@orpc/server/standard';
|
|
4
|
-
import { Value, Public, Promisable } from '@orpc/shared';
|
|
5
|
-
import { StandardLazyRequest, StandardResponse } from '@standard-server/core';
|
|
6
|
-
import { AnyProcedureContract } from '@orpc/contract';
|
|
7
|
-
import { O as OpenAPISerializer } from './openapi.YMRD3b4R.mjs';
|
|
8
|
-
|
|
9
|
-
interface OpenAPIMatcherOptions {
|
|
10
|
-
/**
|
|
11
|
-
* Filter which procedures are exposed for matching. Return `false` to exclude.
|
|
12
|
-
*
|
|
13
|
-
* @default true
|
|
14
|
-
*/
|
|
15
|
-
filter?: Value<boolean, [contract: AnyProcedureContract | AnyProcedure, path: string[]]> | undefined;
|
|
16
|
-
}
|
|
17
|
-
declare class OpenAPIMatcher {
|
|
18
|
-
private readonly filter;
|
|
19
|
-
private readonly rootRouter;
|
|
20
|
-
private readonly tree;
|
|
21
|
-
private readonly pendingLazyRouters;
|
|
22
|
-
constructor(router: AnyRouter, options?: OpenAPIMatcherOptions);
|
|
23
|
-
private index;
|
|
24
|
-
match(method: string, pathname: `/${string}`, prefix: `/${string}` | undefined): Promise<{
|
|
25
|
-
path: string[];
|
|
26
|
-
procedure: AnyProcedure;
|
|
27
|
-
params?: Record<string, string> | undefined;
|
|
28
|
-
} | undefined>;
|
|
29
|
-
private findMatch;
|
|
30
|
-
private resolvePendingLazyRouters;
|
|
31
|
-
private loadPendingLazyRouters;
|
|
32
|
-
private loadPendingLazyRouter;
|
|
33
|
-
private indexPendingLazyRouter;
|
|
34
|
-
private resolveProcedure;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
interface OpenAPIHandlerCodecCoreOptions<_T extends Context> {
|
|
38
|
-
/**
|
|
39
|
-
* Override the default OpenAPI serializer.
|
|
40
|
-
*/
|
|
41
|
-
serializer?: Public<OpenAPISerializer> | undefined;
|
|
42
|
-
/**
|
|
43
|
-
* Mapping ORPCError Code -> HTTP Status Code
|
|
44
|
-
* The status code should be in the `4xx` or `5xx` range (must be greater than or equal to `400`).
|
|
45
|
-
* Codes missing from the map fall back to `DEFAULT_ERROR_STATUS` (400).
|
|
46
|
-
*
|
|
47
|
-
* @default COMMON_ERROR_STATUS_MAP
|
|
48
|
-
*/
|
|
49
|
-
errorStatusMap?: Record<string, number> | undefined;
|
|
50
|
-
/**
|
|
51
|
-
* Customize how an ORPC error is serialized into a response body.
|
|
52
|
-
* Use this if your API needs a different error output structure.
|
|
53
|
-
*
|
|
54
|
-
* @remarks
|
|
55
|
-
* - Return `null | undefined` to fallback to default behavior
|
|
56
|
-
*
|
|
57
|
-
* @default ((e) => e.toJSON())
|
|
58
|
-
*/
|
|
59
|
-
errorResponseBodyEncoder?: ((error: AnyORPCError) => unknown) | undefined;
|
|
60
|
-
/**
|
|
61
|
-
* The `content-type` of error responses, e.g. `application/problem+json` for RFC 9457 Problem Details.
|
|
62
|
-
*
|
|
63
|
-
* @default 'application/json'
|
|
64
|
-
*/
|
|
65
|
-
errorResponseContentType?: string | undefined;
|
|
66
|
-
}
|
|
67
|
-
declare class OpenAPIHandlerCodecCore<T extends Context> {
|
|
68
|
-
private readonly serializer;
|
|
69
|
-
private readonly errorStatusMap;
|
|
70
|
-
private readonly errorResponseBodyEncoder;
|
|
71
|
-
private readonly errorResponseContentType;
|
|
72
|
-
constructor(options?: OpenAPIHandlerCodecCoreOptions<T>);
|
|
73
|
-
decodeInput(matched: {
|
|
74
|
-
procedure: AnyProcedure;
|
|
75
|
-
params?: Record<string, string> | undefined;
|
|
76
|
-
}, request: StandardLazyRequest): Promise<unknown>;
|
|
77
|
-
/**
|
|
78
|
-
* @throws {TypeError} If `outputStructure` is "detailed" and the output doesn't match the expected structure.
|
|
79
|
-
*/
|
|
80
|
-
encodeOutput(output: unknown, procedure: AnyProcedure, path: string[]): Promisable<StandardResponse>;
|
|
81
|
-
encodeError(error: AnyORPCError): Promisable<StandardResponse>;
|
|
82
|
-
private deserializeQuery;
|
|
83
|
-
private deserializeParams;
|
|
84
|
-
}
|
|
85
|
-
interface OpenAPIHandlerCodecOptions<T extends Context> extends OpenAPIHandlerCodecCoreOptions<T>, OpenAPIMatcherOptions {
|
|
86
|
-
}
|
|
87
|
-
declare class OpenAPIHandlerCodec<T extends Context> extends OpenAPIHandlerCodecCore<T> implements StandardHandlerCodec<T> {
|
|
88
|
-
private readonly matcher;
|
|
89
|
-
constructor(router: AnyRouter, options?: OpenAPIHandlerCodecOptions<T>);
|
|
90
|
-
resolveProcedure(request: StandardLazyRequest, options: ResolvedStandardHandlerHandleOptions<T>): Promise<StandardHandlerCodecResolvedProcedure | undefined>;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export { OpenAPIHandlerCodec as a, OpenAPIHandlerCodecCore as b, OpenAPIMatcher as d };
|
|
94
|
-
export type { OpenAPIHandlerCodecOptions as O, OpenAPIHandlerCodecCoreOptions as c, OpenAPIMatcherOptions as e };
|
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
import { isPlainObject, NullProtoObj, getOwn, setOwn } from '@orpc/shared';
|
|
2
|
-
|
|
3
|
-
class BracketNotationSerializer {
|
|
4
|
-
maxDeserializingEmptySlots;
|
|
5
|
-
constructor(options = {}) {
|
|
6
|
-
this.maxDeserializingEmptySlots = options.maxDeserializingEmptySlots ?? 1e3;
|
|
7
|
-
}
|
|
8
|
-
serialize(data) {
|
|
9
|
-
const result = [];
|
|
10
|
-
this.internalSerialize(data, "", true, result);
|
|
11
|
-
return result;
|
|
12
|
-
}
|
|
13
|
-
internalSerialize(data, path, isRoot, result) {
|
|
14
|
-
if (Array.isArray(data)) {
|
|
15
|
-
data.forEach((item, i) => {
|
|
16
|
-
this.internalSerialize(item, isRoot ? i.toString() : `${path}[${i}]`, false, result);
|
|
17
|
-
});
|
|
18
|
-
} else if (isPlainObject(data)) {
|
|
19
|
-
for (const key of Object.keys(data)) {
|
|
20
|
-
this.internalSerialize(data[key], isRoot ? key : `${path}[${key}]`, false, result);
|
|
21
|
-
}
|
|
22
|
-
} else {
|
|
23
|
-
result.push([path, data]);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
deserialize(serialized) {
|
|
27
|
-
let arrayPushStyles;
|
|
28
|
-
const root = new NullProtoObj();
|
|
29
|
-
let emptySlotsLeft = this.maxDeserializingEmptySlots;
|
|
30
|
-
for (const [path, value] of serialized) {
|
|
31
|
-
const segments = this.parsePath(path);
|
|
32
|
-
let currentRef = root;
|
|
33
|
-
let nextSegment = segments[0];
|
|
34
|
-
for (let i = 1; i < segments.length; i++) {
|
|
35
|
-
const segment = segments[i];
|
|
36
|
-
const isLast = i === segments.length - 1;
|
|
37
|
-
const existing = getOwn(currentRef, nextSegment);
|
|
38
|
-
let child = existing;
|
|
39
|
-
let key = segment;
|
|
40
|
-
if (Array.isArray(child) || !isPlainObject(child)) {
|
|
41
|
-
const isArray = Array.isArray(child);
|
|
42
|
-
const isPushStyle = isArray && !!arrayPushStyles?.has(child);
|
|
43
|
-
const length = isArray ? child.length : 0;
|
|
44
|
-
const index = internalToArrayIndex(segment);
|
|
45
|
-
const emptySlots = index === void 0 ? 0 : Math.max(0, index - length);
|
|
46
|
-
const canBeArray = segment === "" ? isLast && (isPushStyle || length === 0) : index !== void 0 && !(isLast && isPushStyle) && emptySlots <= emptySlotsLeft;
|
|
47
|
-
if (canBeArray) {
|
|
48
|
-
emptySlotsLeft -= emptySlots;
|
|
49
|
-
child = isArray ? child : [];
|
|
50
|
-
key = index ?? segment;
|
|
51
|
-
} else if (isArray) {
|
|
52
|
-
arrayPushStyles?.delete(child);
|
|
53
|
-
child = isPushStyle ? internalPushStyleArrayToObject(child) : internalArrayToObject(child);
|
|
54
|
-
} else {
|
|
55
|
-
child = new NullProtoObj();
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
if (child !== existing) {
|
|
59
|
-
internalSetOwn(currentRef, nextSegment, child);
|
|
60
|
-
}
|
|
61
|
-
currentRef = child;
|
|
62
|
-
nextSegment = key;
|
|
63
|
-
}
|
|
64
|
-
if (Array.isArray(currentRef) && nextSegment === "") {
|
|
65
|
-
arrayPushStyles ??= /* @__PURE__ */ new WeakSet();
|
|
66
|
-
arrayPushStyles.add(currentRef);
|
|
67
|
-
currentRef.push(value);
|
|
68
|
-
} else if (Object.hasOwn(currentRef, nextSegment)) {
|
|
69
|
-
const current = currentRef[nextSegment];
|
|
70
|
-
if (Array.isArray(current)) {
|
|
71
|
-
current.push(value);
|
|
72
|
-
} else {
|
|
73
|
-
internalSetOwn(currentRef, nextSegment, [current, value]);
|
|
74
|
-
}
|
|
75
|
-
} else {
|
|
76
|
-
internalSetOwn(currentRef, nextSegment, value);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
return root;
|
|
80
|
-
}
|
|
81
|
-
stringifyPath(segments) {
|
|
82
|
-
if (segments.length === 0) {
|
|
83
|
-
return "";
|
|
84
|
-
}
|
|
85
|
-
let result = segments[0].toString();
|
|
86
|
-
for (let i = 1; i < segments.length; i++) {
|
|
87
|
-
result += `[${segments[i]}]`;
|
|
88
|
-
}
|
|
89
|
-
return result;
|
|
90
|
-
}
|
|
91
|
-
parsePath(path) {
|
|
92
|
-
const start = path.indexOf("[");
|
|
93
|
-
if (start === -1 || path[path.length - 1] !== "]") {
|
|
94
|
-
return [path];
|
|
95
|
-
}
|
|
96
|
-
const segments = [path.slice(0, start)];
|
|
97
|
-
let from = start + 1;
|
|
98
|
-
let to = path.indexOf("][", from);
|
|
99
|
-
while (to !== -1) {
|
|
100
|
-
segments.push(path.slice(from, to));
|
|
101
|
-
from = to + 2;
|
|
102
|
-
to = path.indexOf("][", from);
|
|
103
|
-
}
|
|
104
|
-
segments.push(path.slice(from, -1));
|
|
105
|
-
return segments;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
const MAX_ARRAY_INDEX = 2 ** 32 - 2;
|
|
109
|
-
function internalToArrayIndex(key) {
|
|
110
|
-
if (key.length === 0 || key.length > 10) {
|
|
111
|
-
return void 0;
|
|
112
|
-
}
|
|
113
|
-
let index = key.charCodeAt(0) - 48;
|
|
114
|
-
if (index < 0 || index > 9 || index === 0 && key.length > 1) {
|
|
115
|
-
return void 0;
|
|
116
|
-
}
|
|
117
|
-
for (let i = 1; i < key.length; i++) {
|
|
118
|
-
const digit = key.charCodeAt(i) - 48;
|
|
119
|
-
if (digit < 0 || digit > 9) {
|
|
120
|
-
return void 0;
|
|
121
|
-
}
|
|
122
|
-
index = index * 10 + digit;
|
|
123
|
-
}
|
|
124
|
-
return index <= MAX_ARRAY_INDEX ? index : void 0;
|
|
125
|
-
}
|
|
126
|
-
function internalArrayToObject(array) {
|
|
127
|
-
const obj = new NullProtoObj();
|
|
128
|
-
array.forEach((item, i) => {
|
|
129
|
-
obj[i] = item;
|
|
130
|
-
});
|
|
131
|
-
return obj;
|
|
132
|
-
}
|
|
133
|
-
function internalPushStyleArrayToObject(array) {
|
|
134
|
-
const obj = new NullProtoObj();
|
|
135
|
-
obj[""] = array.length === 1 ? array[0] : array;
|
|
136
|
-
return obj;
|
|
137
|
-
}
|
|
138
|
-
function internalSetOwn(container, key, value) {
|
|
139
|
-
if (typeof key === "string" && container instanceof NullProtoObj) {
|
|
140
|
-
const index = internalToArrayIndex(key);
|
|
141
|
-
if (index !== void 0 && index !== 0 && !Object.hasOwn(container, index - 1) && !Object.hasOwn(container, MAX_ARRAY_INDEX)) {
|
|
142
|
-
container[MAX_ARRAY_INDEX] = void 0;
|
|
143
|
-
delete container[MAX_ARRAY_INDEX];
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
setOwn(container, key, value);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
export { BracketNotationSerializer as B };
|