@orpc/openapi 0.0.0-next.eb37cbe → 0.0.0-next.eb3d98a
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 +99 -0
- package/dist/adapters/aws-lambda/index.d.mts +19 -0
- package/dist/adapters/aws-lambda/index.d.ts +19 -0
- package/dist/adapters/aws-lambda/index.mjs +18 -0
- package/dist/adapters/fetch/index.d.mts +19 -0
- package/dist/adapters/fetch/index.d.ts +19 -0
- package/dist/adapters/fetch/index.mjs +18 -0
- package/dist/adapters/node/index.d.mts +19 -0
- package/dist/adapters/node/index.d.ts +19 -0
- package/dist/adapters/node/index.mjs +18 -0
- package/dist/adapters/standard/index.d.mts +29 -0
- package/dist/adapters/standard/index.d.ts +29 -0
- package/dist/adapters/standard/index.mjs +9 -0
- package/dist/index.d.mts +110 -0
- package/dist/index.d.ts +110 -0
- package/dist/index.mjs +41 -0
- package/dist/plugins/index.d.mts +69 -0
- package/dist/plugins/index.d.ts +69 -0
- package/dist/plugins/index.mjs +108 -0
- package/dist/shared/openapi.BVXcB0u4.mjs +187 -0
- package/dist/shared/openapi.BtoY8ZFF.mjs +742 -0
- package/dist/shared/openapi.CQmjvnb0.d.mts +31 -0
- package/dist/shared/openapi.CQmjvnb0.d.ts +31 -0
- package/dist/shared/openapi.DPAN3GVs.d.mts +108 -0
- package/dist/shared/openapi.DPAN3GVs.d.ts +108 -0
- package/package.json +35 -25
- package/dist/chunk-KNYXLM77.js +0 -107
- package/dist/fetch.js +0 -594
- package/dist/index.js +0 -362
- package/dist/src/fetch/bracket-notation.d.ts +0 -84
- package/dist/src/fetch/index.d.ts +0 -10
- package/dist/src/fetch/input-builder-full.d.ts +0 -11
- package/dist/src/fetch/input-builder-simple.d.ts +0 -6
- package/dist/src/fetch/openapi-handler-server.d.ts +0 -7
- package/dist/src/fetch/openapi-handler-serverless.d.ts +0 -7
- package/dist/src/fetch/openapi-handler.d.ts +0 -30
- package/dist/src/fetch/openapi-payload-codec.d.ts +0 -15
- package/dist/src/fetch/openapi-procedure-matcher.d.ts +0 -19
- package/dist/src/fetch/schema-coercer.d.ts +0 -10
- package/dist/src/index.d.ts +0 -12
- package/dist/src/json-serializer.d.ts +0 -5
- package/dist/src/openapi-content-builder.d.ts +0 -10
- package/dist/src/openapi-generator.d.ts +0 -51
- package/dist/src/openapi-parameters-builder.d.ts +0 -9
- package/dist/src/openapi-path-parser.d.ts +0 -8
- package/dist/src/openapi.d.ts +0 -3
- package/dist/src/schema-converter.d.ts +0 -16
- package/dist/src/schema-utils.d.ts +0 -11
- package/dist/src/schema.d.ts +0 -12
- package/dist/src/utils.d.ts +0 -18
package/dist/index.js
DELETED
|
@@ -1,362 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
JSONSerializer,
|
|
3
|
-
forEachAllContractProcedure,
|
|
4
|
-
forEachContractProcedure,
|
|
5
|
-
standardizeHTTPPath
|
|
6
|
-
} from "./chunk-KNYXLM77.js";
|
|
7
|
-
|
|
8
|
-
// src/openapi.ts
|
|
9
|
-
import { OpenApiBuilder } from "openapi3-ts/oas31";
|
|
10
|
-
|
|
11
|
-
// src/openapi-content-builder.ts
|
|
12
|
-
import { findDeepMatches } from "@orpc/shared";
|
|
13
|
-
var OpenAPIContentBuilder = class {
|
|
14
|
-
constructor(schemaUtils) {
|
|
15
|
-
this.schemaUtils = schemaUtils;
|
|
16
|
-
}
|
|
17
|
-
build(jsonSchema, options) {
|
|
18
|
-
const isFileSchema = this.schemaUtils.isFileSchema.bind(this.schemaUtils);
|
|
19
|
-
const [matches, schema] = this.schemaUtils.filterSchemaBranches(jsonSchema, isFileSchema);
|
|
20
|
-
const files = matches;
|
|
21
|
-
const content = {};
|
|
22
|
-
for (const file of files) {
|
|
23
|
-
content[file.contentMediaType] = {
|
|
24
|
-
schema: file
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
const isStillHasFileSchema = findDeepMatches(isFileSchema, schema).values.length > 0;
|
|
28
|
-
if (schema !== void 0) {
|
|
29
|
-
content[isStillHasFileSchema ? "multipart/form-data" : "application/json"] = {
|
|
30
|
-
schema,
|
|
31
|
-
...options
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
return content;
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
// src/openapi-parameters-builder.ts
|
|
39
|
-
import { get, isPlainObject } from "@orpc/shared";
|
|
40
|
-
var OpenAPIParametersBuilder = class {
|
|
41
|
-
build(paramIn, jsonSchema, options) {
|
|
42
|
-
const parameters = [];
|
|
43
|
-
for (const name in jsonSchema.properties) {
|
|
44
|
-
const schema = jsonSchema.properties[name];
|
|
45
|
-
const paramExamples = jsonSchema.examples?.filter((example) => {
|
|
46
|
-
return isPlainObject(example) && name in example;
|
|
47
|
-
}).map((example) => {
|
|
48
|
-
return example[name];
|
|
49
|
-
});
|
|
50
|
-
const paramSchema = {
|
|
51
|
-
examples: paramExamples?.length ? paramExamples : void 0,
|
|
52
|
-
...schema === true ? {} : schema === false ? { not: {} } : schema
|
|
53
|
-
};
|
|
54
|
-
const paramExample = get(options?.example, [name]);
|
|
55
|
-
parameters.push({
|
|
56
|
-
name,
|
|
57
|
-
in: paramIn,
|
|
58
|
-
required: typeof options?.required === "boolean" ? options.required : jsonSchema.required?.includes(name) ?? false,
|
|
59
|
-
schema: paramSchema,
|
|
60
|
-
example: paramExample,
|
|
61
|
-
style: options?.style
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
return parameters;
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
// src/openapi-path-parser.ts
|
|
69
|
-
var OpenAPIPathParser = class {
|
|
70
|
-
parseDynamicParams(path) {
|
|
71
|
-
const raws = path.match(/\{([^}]+)\}/g) ?? [];
|
|
72
|
-
return raws.map((raw) => {
|
|
73
|
-
const name = raw.slice(1, -1).split(":")[0];
|
|
74
|
-
return { name, raw };
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
// src/schema-converter.ts
|
|
80
|
-
var CompositeSchemaConverter = class {
|
|
81
|
-
converters;
|
|
82
|
-
constructor(converters) {
|
|
83
|
-
this.converters = converters;
|
|
84
|
-
}
|
|
85
|
-
condition() {
|
|
86
|
-
return true;
|
|
87
|
-
}
|
|
88
|
-
convert(schema, options) {
|
|
89
|
-
for (const converter of this.converters) {
|
|
90
|
-
if (converter.condition(schema, options)) {
|
|
91
|
-
return converter.convert(schema, options);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
return {};
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
// src/schema-utils.ts
|
|
99
|
-
import { isPlainObject as isPlainObject2 } from "@orpc/shared";
|
|
100
|
-
|
|
101
|
-
// src/schema.ts
|
|
102
|
-
import * as JSONSchema from "json-schema-typed/draft-2020-12";
|
|
103
|
-
import { Format } from "json-schema-typed/draft-2020-12";
|
|
104
|
-
var NON_LOGIC_KEYWORDS = [
|
|
105
|
-
// Core Documentation Keywords
|
|
106
|
-
"$anchor",
|
|
107
|
-
"$comment",
|
|
108
|
-
"$defs",
|
|
109
|
-
"$id",
|
|
110
|
-
"title",
|
|
111
|
-
"description",
|
|
112
|
-
// Value Keywords
|
|
113
|
-
"default",
|
|
114
|
-
"deprecated",
|
|
115
|
-
"examples",
|
|
116
|
-
// Metadata Keywords
|
|
117
|
-
"$schema",
|
|
118
|
-
"definitions",
|
|
119
|
-
// Legacy, but still used
|
|
120
|
-
"readOnly",
|
|
121
|
-
"writeOnly",
|
|
122
|
-
// Display and UI Hints
|
|
123
|
-
"contentMediaType",
|
|
124
|
-
"contentEncoding",
|
|
125
|
-
"format",
|
|
126
|
-
// Custom Extensions
|
|
127
|
-
"$vocabulary",
|
|
128
|
-
"$dynamicAnchor",
|
|
129
|
-
"$dynamicRef"
|
|
130
|
-
];
|
|
131
|
-
|
|
132
|
-
// src/schema-utils.ts
|
|
133
|
-
var SchemaUtils = class {
|
|
134
|
-
isFileSchema(schema) {
|
|
135
|
-
return typeof schema === "object" && schema.type === "string" && typeof schema.contentMediaType === "string";
|
|
136
|
-
}
|
|
137
|
-
isObjectSchema(schema) {
|
|
138
|
-
return typeof schema === "object" && schema.type === "object";
|
|
139
|
-
}
|
|
140
|
-
isAnySchema(schema) {
|
|
141
|
-
return schema === true || Object.keys(schema).length === 0;
|
|
142
|
-
}
|
|
143
|
-
isUndefinableSchema(schema) {
|
|
144
|
-
const [matches] = this.filterSchemaBranches(schema, (schema2) => {
|
|
145
|
-
if (typeof schema2 === "boolean") {
|
|
146
|
-
return schema2;
|
|
147
|
-
}
|
|
148
|
-
return Object.keys(schema2).length === 0;
|
|
149
|
-
});
|
|
150
|
-
return matches.length > 0;
|
|
151
|
-
}
|
|
152
|
-
separateObjectSchema(schema, separatedProperties) {
|
|
153
|
-
const matched = { ...schema };
|
|
154
|
-
const rest = { ...schema };
|
|
155
|
-
matched.properties = Object.entries(schema.properties ?? {}).filter(([key]) => separatedProperties.includes(key)).reduce((acc, [key, value]) => {
|
|
156
|
-
acc[key] = value;
|
|
157
|
-
return acc;
|
|
158
|
-
}, {});
|
|
159
|
-
matched.required = schema.required?.filter((key) => separatedProperties.includes(key));
|
|
160
|
-
matched.examples = schema.examples?.map((example) => {
|
|
161
|
-
if (!isPlainObject2(example)) {
|
|
162
|
-
return example;
|
|
163
|
-
}
|
|
164
|
-
return Object.entries(example).reduce((acc, [key, value]) => {
|
|
165
|
-
if (separatedProperties.includes(key)) {
|
|
166
|
-
acc[key] = value;
|
|
167
|
-
}
|
|
168
|
-
return acc;
|
|
169
|
-
}, {});
|
|
170
|
-
});
|
|
171
|
-
rest.properties = Object.entries(schema.properties ?? {}).filter(([key]) => !separatedProperties.includes(key)).reduce((acc, [key, value]) => {
|
|
172
|
-
acc[key] = value;
|
|
173
|
-
return acc;
|
|
174
|
-
}, {});
|
|
175
|
-
rest.required = schema.required?.filter((key) => !separatedProperties.includes(key));
|
|
176
|
-
rest.examples = schema.examples?.map((example) => {
|
|
177
|
-
if (!isPlainObject2(example)) {
|
|
178
|
-
return example;
|
|
179
|
-
}
|
|
180
|
-
return Object.entries(example).reduce((acc, [key, value]) => {
|
|
181
|
-
if (!separatedProperties.includes(key)) {
|
|
182
|
-
acc[key] = value;
|
|
183
|
-
}
|
|
184
|
-
return acc;
|
|
185
|
-
}, {});
|
|
186
|
-
});
|
|
187
|
-
return [matched, rest];
|
|
188
|
-
}
|
|
189
|
-
filterSchemaBranches(schema, check, matches = []) {
|
|
190
|
-
if (check(schema)) {
|
|
191
|
-
matches.push(schema);
|
|
192
|
-
return [matches, void 0];
|
|
193
|
-
}
|
|
194
|
-
if (typeof schema === "boolean") {
|
|
195
|
-
return [matches, schema];
|
|
196
|
-
}
|
|
197
|
-
if (schema.anyOf && Object.keys(schema).every(
|
|
198
|
-
(k) => k === "anyOf" || NON_LOGIC_KEYWORDS.includes(k)
|
|
199
|
-
)) {
|
|
200
|
-
const anyOf = schema.anyOf.map((s) => this.filterSchemaBranches(s, check, matches)[1]).filter((v) => !!v);
|
|
201
|
-
if (anyOf.length === 1 && typeof anyOf[0] === "object") {
|
|
202
|
-
return [matches, { ...schema, anyOf: void 0, ...anyOf[0] }];
|
|
203
|
-
}
|
|
204
|
-
return [matches, { ...schema, anyOf }];
|
|
205
|
-
}
|
|
206
|
-
if (schema.oneOf && Object.keys(schema).every(
|
|
207
|
-
(k) => k === "oneOf" || NON_LOGIC_KEYWORDS.includes(k)
|
|
208
|
-
)) {
|
|
209
|
-
const oneOf = schema.oneOf.map((s) => this.filterSchemaBranches(s, check, matches)[1]).filter((v) => !!v);
|
|
210
|
-
if (oneOf.length === 1 && typeof oneOf[0] === "object") {
|
|
211
|
-
return [matches, { ...schema, oneOf: void 0, ...oneOf[0] }];
|
|
212
|
-
}
|
|
213
|
-
return [matches, { ...schema, oneOf }];
|
|
214
|
-
}
|
|
215
|
-
return [matches, schema];
|
|
216
|
-
}
|
|
217
|
-
};
|
|
218
|
-
|
|
219
|
-
// src/openapi-generator.ts
|
|
220
|
-
var OpenAPIGenerator = class {
|
|
221
|
-
constructor(options) {
|
|
222
|
-
this.options = options;
|
|
223
|
-
this.parametersBuilder = options?.parametersBuilder ?? new OpenAPIParametersBuilder();
|
|
224
|
-
this.schemaConverter = new CompositeSchemaConverter(options?.schemaConverters ?? []);
|
|
225
|
-
this.schemaUtils = options?.schemaUtils ?? new SchemaUtils();
|
|
226
|
-
this.jsonSerializer = options?.jsonSerializer ?? new JSONSerializer();
|
|
227
|
-
this.contentBuilder = options?.contentBuilder ?? new OpenAPIContentBuilder(this.schemaUtils);
|
|
228
|
-
this.pathParser = new OpenAPIPathParser();
|
|
229
|
-
}
|
|
230
|
-
contentBuilder;
|
|
231
|
-
parametersBuilder;
|
|
232
|
-
schemaConverter;
|
|
233
|
-
schemaUtils;
|
|
234
|
-
jsonSerializer;
|
|
235
|
-
pathParser;
|
|
236
|
-
async generate(router, doc) {
|
|
237
|
-
const builder = new OpenApiBuilder({
|
|
238
|
-
...doc,
|
|
239
|
-
openapi: "3.1.1"
|
|
240
|
-
});
|
|
241
|
-
const rootTags = doc.tags?.map((tag) => tag.name) ?? [];
|
|
242
|
-
await forEachAllContractProcedure(router, ({ contract, path }) => {
|
|
243
|
-
const def = contract["~orpc"];
|
|
244
|
-
if (this.options?.ignoreUndefinedPathProcedures && def.route?.path === void 0) {
|
|
245
|
-
return;
|
|
246
|
-
}
|
|
247
|
-
const method = def.route?.method ?? "POST";
|
|
248
|
-
const httpPath = def.route?.path ? standardizeHTTPPath(def.route?.path) : `/${path.map(encodeURIComponent).join("/")}`;
|
|
249
|
-
let inputSchema = this.schemaConverter.convert(def.InputSchema, { strategy: "input" });
|
|
250
|
-
const outputSchema = this.schemaConverter.convert(def.OutputSchema, { strategy: "output" });
|
|
251
|
-
const params = (() => {
|
|
252
|
-
const dynamic = this.pathParser.parseDynamicParams(httpPath);
|
|
253
|
-
if (!dynamic.length) {
|
|
254
|
-
return void 0;
|
|
255
|
-
}
|
|
256
|
-
if (this.schemaUtils.isAnySchema(inputSchema)) {
|
|
257
|
-
return void 0;
|
|
258
|
-
}
|
|
259
|
-
if (!this.schemaUtils.isObjectSchema(inputSchema)) {
|
|
260
|
-
this.handleError(
|
|
261
|
-
new Error(
|
|
262
|
-
`When path has parameters, input schema must be an object [${path.join(".")}]`
|
|
263
|
-
)
|
|
264
|
-
);
|
|
265
|
-
return void 0;
|
|
266
|
-
}
|
|
267
|
-
const [matched, rest] = this.schemaUtils.separateObjectSchema(inputSchema, dynamic.map((v) => v.name));
|
|
268
|
-
inputSchema = rest;
|
|
269
|
-
return this.parametersBuilder.build("path", matched, {
|
|
270
|
-
example: def.inputExample,
|
|
271
|
-
required: true
|
|
272
|
-
});
|
|
273
|
-
})();
|
|
274
|
-
const query = (() => {
|
|
275
|
-
if (method !== "GET" || Object.keys(inputSchema).length === 0) {
|
|
276
|
-
return void 0;
|
|
277
|
-
}
|
|
278
|
-
if (this.schemaUtils.isAnySchema(inputSchema)) {
|
|
279
|
-
return void 0;
|
|
280
|
-
}
|
|
281
|
-
if (!this.schemaUtils.isObjectSchema(inputSchema)) {
|
|
282
|
-
this.handleError(
|
|
283
|
-
new Error(
|
|
284
|
-
`When method is GET, input schema must be an object [${path.join(".")}]`
|
|
285
|
-
)
|
|
286
|
-
);
|
|
287
|
-
return void 0;
|
|
288
|
-
}
|
|
289
|
-
return this.parametersBuilder.build("query", inputSchema, {
|
|
290
|
-
example: def.inputExample
|
|
291
|
-
});
|
|
292
|
-
})();
|
|
293
|
-
const parameters = [...params ?? [], ...query ?? []];
|
|
294
|
-
const requestBody = (() => {
|
|
295
|
-
if (method === "GET") {
|
|
296
|
-
return void 0;
|
|
297
|
-
}
|
|
298
|
-
return {
|
|
299
|
-
required: this.schemaUtils.isUndefinableSchema(inputSchema),
|
|
300
|
-
content: this.contentBuilder.build(inputSchema, {
|
|
301
|
-
example: def.inputExample
|
|
302
|
-
})
|
|
303
|
-
};
|
|
304
|
-
})();
|
|
305
|
-
const successResponse = {
|
|
306
|
-
description: "OK",
|
|
307
|
-
content: this.contentBuilder.build(outputSchema, {
|
|
308
|
-
example: def.outputExample
|
|
309
|
-
})
|
|
310
|
-
};
|
|
311
|
-
if (this.options?.considerMissingTagDefinitionAsError && def.route?.tags) {
|
|
312
|
-
const missingTag = def.route?.tags.find((tag) => !rootTags.includes(tag));
|
|
313
|
-
if (missingTag !== void 0) {
|
|
314
|
-
this.handleError(
|
|
315
|
-
new Error(
|
|
316
|
-
`Tag "${missingTag}" is missing definition. Please define it in OpenAPI root tags object. [${path.join(".")}]`
|
|
317
|
-
)
|
|
318
|
-
);
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
const operation = {
|
|
322
|
-
summary: def.route?.summary,
|
|
323
|
-
description: def.route?.description,
|
|
324
|
-
deprecated: def.route?.deprecated,
|
|
325
|
-
tags: def.route?.tags ? [...def.route.tags] : void 0,
|
|
326
|
-
operationId: path.join("."),
|
|
327
|
-
parameters: parameters.length ? parameters : void 0,
|
|
328
|
-
requestBody,
|
|
329
|
-
responses: {
|
|
330
|
-
[def.route?.successStatus ?? 200]: successResponse
|
|
331
|
-
}
|
|
332
|
-
};
|
|
333
|
-
builder.addPath(httpPath, {
|
|
334
|
-
[method.toLocaleLowerCase()]: operation
|
|
335
|
-
});
|
|
336
|
-
});
|
|
337
|
-
return this.jsonSerializer.serialize(builder.getSpec());
|
|
338
|
-
}
|
|
339
|
-
handleError(error) {
|
|
340
|
-
if (this.options?.throwOnError) {
|
|
341
|
-
throw error;
|
|
342
|
-
}
|
|
343
|
-
console.error(error);
|
|
344
|
-
}
|
|
345
|
-
};
|
|
346
|
-
export {
|
|
347
|
-
CompositeSchemaConverter,
|
|
348
|
-
JSONSchema,
|
|
349
|
-
Format as JSONSchemaFormat,
|
|
350
|
-
JSONSerializer,
|
|
351
|
-
NON_LOGIC_KEYWORDS,
|
|
352
|
-
OpenAPIContentBuilder,
|
|
353
|
-
OpenAPIGenerator,
|
|
354
|
-
OpenAPIParametersBuilder,
|
|
355
|
-
OpenAPIPathParser,
|
|
356
|
-
OpenApiBuilder,
|
|
357
|
-
SchemaUtils,
|
|
358
|
-
forEachAllContractProcedure,
|
|
359
|
-
forEachContractProcedure,
|
|
360
|
-
standardizeHTTPPath
|
|
361
|
-
};
|
|
362
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Serialize an object or array into a list of [key, value] pairs.
|
|
3
|
-
* The key will express by using bracket-notation.
|
|
4
|
-
*
|
|
5
|
-
* Notice: This way cannot express the empty object or array.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```ts
|
|
9
|
-
* const payload = {
|
|
10
|
-
* name: 'John Doe',
|
|
11
|
-
* pets: ['dog', 'cat'],
|
|
12
|
-
* }
|
|
13
|
-
*
|
|
14
|
-
* const entities = serialize(payload)
|
|
15
|
-
*
|
|
16
|
-
* expect(entities).toEqual([
|
|
17
|
-
* ['name', 'John Doe'],
|
|
18
|
-
* ['name[pets][0]', 'dog'],
|
|
19
|
-
* ['name[pets][1]', 'cat'],
|
|
20
|
-
* ])
|
|
21
|
-
* ```
|
|
22
|
-
*/
|
|
23
|
-
export declare function serialize(payload: unknown, parentKey?: string): [string, unknown][];
|
|
24
|
-
/**
|
|
25
|
-
* Deserialize a list of [key, value] pairs into an object or array.
|
|
26
|
-
* The key is expressed by using bracket-notation.
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* ```ts
|
|
30
|
-
* const entities = [
|
|
31
|
-
* ['name', 'John Doe'],
|
|
32
|
-
* ['name[pets][0]', 'dog'],
|
|
33
|
-
* ['name[pets][1]', 'cat'],
|
|
34
|
-
* ['name[dogs][]', 'hello'],
|
|
35
|
-
* ['name[dogs][]', 'kitty'],
|
|
36
|
-
* ]
|
|
37
|
-
*
|
|
38
|
-
* const payload = deserialize(entities)
|
|
39
|
-
*
|
|
40
|
-
* expect(payload).toEqual({
|
|
41
|
-
* name: 'John Doe',
|
|
42
|
-
* pets: { 0: 'dog', 1: 'cat' },
|
|
43
|
-
* dogs: ['hello', 'kitty'],
|
|
44
|
-
* })
|
|
45
|
-
* ```
|
|
46
|
-
*/
|
|
47
|
-
export declare function deserialize(entities: readonly (readonly [string, unknown])[]): Record<string, unknown> | unknown[] | undefined;
|
|
48
|
-
/**
|
|
49
|
-
* Escape the `[`, `]`, and `\` chars in a path segment.
|
|
50
|
-
*
|
|
51
|
-
* @example
|
|
52
|
-
* ```ts
|
|
53
|
-
* expect(escapeSegment('name[pets')).toEqual('name\\[pets')
|
|
54
|
-
* ```
|
|
55
|
-
*/
|
|
56
|
-
export declare function escapeSegment(segment: string): string;
|
|
57
|
-
/**
|
|
58
|
-
* Convert an array of path segments into a path string using bracket-notation.
|
|
59
|
-
*
|
|
60
|
-
* For the special char `[`, `]`, and `\` will be escaped by adding `\` at start.
|
|
61
|
-
*
|
|
62
|
-
* @example
|
|
63
|
-
* ```ts
|
|
64
|
-
* expect(stringifyPath(['name', 'pets', '0'])).toEqual('name[pets][0]')
|
|
65
|
-
* ```
|
|
66
|
-
*/
|
|
67
|
-
export declare function stringifyPath(path: readonly [string, ...string[]]): string;
|
|
68
|
-
/**
|
|
69
|
-
* Convert a path string using bracket-notation into an array of path segments.
|
|
70
|
-
*
|
|
71
|
-
* For the special char `[`, `]`, and `\` you should escape by adding `\` at start.
|
|
72
|
-
* It only treats a pair `[${string}]` as a path segment.
|
|
73
|
-
* If missing or escape it will bypass and treat as normal string.
|
|
74
|
-
*
|
|
75
|
-
* @example
|
|
76
|
-
* ```ts
|
|
77
|
-
* expect(parsePath('name[pets][0]')).toEqual(['name', 'pets', '0'])
|
|
78
|
-
* expect(parsePath('name[pets][0')).toEqual(['name', 'pets', '[0'])
|
|
79
|
-
* expect(parsePath('name[pets[0]')).toEqual(['name', 'pets[0')
|
|
80
|
-
* expect(parsePath('name\\[pets][0]')).toEqual(['name[pets]', '0'])
|
|
81
|
-
* ```
|
|
82
|
-
*/
|
|
83
|
-
export declare function parsePath(path: string): [string, ...string[]];
|
|
84
|
-
//# sourceMappingURL=bracket-notation.d.ts.map
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export * from './bracket-notation';
|
|
2
|
-
export * from './input-builder-full';
|
|
3
|
-
export * from './input-builder-simple';
|
|
4
|
-
export * from './openapi-handler';
|
|
5
|
-
export * from './openapi-handler-server';
|
|
6
|
-
export * from './openapi-handler-serverless';
|
|
7
|
-
export * from './openapi-payload-codec';
|
|
8
|
-
export * from './openapi-procedure-matcher';
|
|
9
|
-
export * from './schema-coercer';
|
|
10
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { Params } from 'hono/router';
|
|
2
|
-
export declare class InputBuilderFull {
|
|
3
|
-
build(params: Params, query: unknown, headers: unknown, body: unknown): {
|
|
4
|
-
params: Params;
|
|
5
|
-
query: unknown;
|
|
6
|
-
headers: unknown;
|
|
7
|
-
body: unknown;
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
|
-
export type PublicInputBuilderFull = Pick<InputBuilderFull, keyof InputBuilderFull>;
|
|
11
|
-
//# sourceMappingURL=input-builder-full.d.ts.map
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { Params } from 'hono/router';
|
|
2
|
-
export declare class InputBuilderSimple {
|
|
3
|
-
build(params: Params, payload: unknown): unknown;
|
|
4
|
-
}
|
|
5
|
-
export type PublicInputBuilderSimple = Pick<InputBuilderSimple, keyof InputBuilderSimple>;
|
|
6
|
-
//# sourceMappingURL=input-builder-simple.d.ts.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { Context, Router } from '@orpc/server';
|
|
2
|
-
import type { OpenAPIHandlerOptions } from './openapi-handler';
|
|
3
|
-
import { OpenAPIHandler } from './openapi-handler';
|
|
4
|
-
export declare class OpenAPIServerHandler<T extends Context> extends OpenAPIHandler<T> {
|
|
5
|
-
constructor(router: Router<T, any>, options?: NoInfer<OpenAPIHandlerOptions<T>>);
|
|
6
|
-
}
|
|
7
|
-
//# sourceMappingURL=openapi-handler-server.d.ts.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { Context, Router } from '@orpc/server';
|
|
2
|
-
import type { OpenAPIHandlerOptions } from './openapi-handler';
|
|
3
|
-
import { OpenAPIHandler } from './openapi-handler';
|
|
4
|
-
export declare class OpenAPIServerlessHandler<T extends Context> extends OpenAPIHandler<T> {
|
|
5
|
-
constructor(router: Router<T, any>, options?: NoInfer<OpenAPIHandlerOptions<T>>);
|
|
6
|
-
}
|
|
7
|
-
//# sourceMappingURL=openapi-handler-serverless.d.ts.map
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { ConditionalFetchHandler, FetchOptions } from '@orpc/server/fetch';
|
|
2
|
-
import type { PublicInputBuilderSimple } from './input-builder-simple';
|
|
3
|
-
import { type Context, type Router, type WithSignal } from '@orpc/server';
|
|
4
|
-
import { type Hooks } from '@orpc/shared';
|
|
5
|
-
import { type PublicJSONSerializer } from '../json-serializer';
|
|
6
|
-
import { type PublicInputBuilderFull } from './input-builder-full';
|
|
7
|
-
import { type PublicOpenAPIPayloadCodec } from './openapi-payload-codec';
|
|
8
|
-
import { type Hono, type PublicOpenAPIProcedureMatcher } from './openapi-procedure-matcher';
|
|
9
|
-
import { type SchemaCoercer } from './schema-coercer';
|
|
10
|
-
export type OpenAPIHandlerOptions<T extends Context> = Hooks<Request, Response, T, WithSignal> & {
|
|
11
|
-
jsonSerializer?: PublicJSONSerializer;
|
|
12
|
-
procedureMatcher?: PublicOpenAPIProcedureMatcher;
|
|
13
|
-
payloadCodec?: PublicOpenAPIPayloadCodec;
|
|
14
|
-
inputBuilderSimple?: PublicInputBuilderSimple;
|
|
15
|
-
inputBuilderFull?: PublicInputBuilderFull;
|
|
16
|
-
schemaCoercers?: SchemaCoercer[];
|
|
17
|
-
};
|
|
18
|
-
export declare class OpenAPIHandler<T extends Context> implements ConditionalFetchHandler<T> {
|
|
19
|
-
private readonly options?;
|
|
20
|
-
private readonly procedureMatcher;
|
|
21
|
-
private readonly payloadCodec;
|
|
22
|
-
private readonly inputBuilderSimple;
|
|
23
|
-
private readonly inputBuilderFull;
|
|
24
|
-
private readonly compositeSchemaCoercer;
|
|
25
|
-
constructor(hono: Hono, router: Router<T, any>, options?: NoInfer<OpenAPIHandlerOptions<T>> | undefined);
|
|
26
|
-
condition(request: Request): boolean;
|
|
27
|
-
fetch(request: Request, ...[options]: [options: FetchOptions<T>] | (undefined extends T ? [] : never)): Promise<Response>;
|
|
28
|
-
private convertToORPCError;
|
|
29
|
-
}
|
|
30
|
-
//# sourceMappingURL=openapi-handler.d.ts.map
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { PublicJSONSerializer } from '../json-serializer';
|
|
2
|
-
export declare class OpenAPIPayloadCodec {
|
|
3
|
-
private readonly jsonSerializer;
|
|
4
|
-
constructor(jsonSerializer: PublicJSONSerializer);
|
|
5
|
-
encode(payload: unknown, accept?: string): {
|
|
6
|
-
body: FormData | Blob | string | undefined;
|
|
7
|
-
headers?: Headers;
|
|
8
|
-
};
|
|
9
|
-
private encodeAsJSON;
|
|
10
|
-
private encodeAsFormData;
|
|
11
|
-
private encodeAsURLSearchParams;
|
|
12
|
-
decode(re: Request | Response | Headers | URLSearchParams | FormData): Promise<unknown>;
|
|
13
|
-
}
|
|
14
|
-
export type PublicOpenAPIPayloadCodec = Pick<OpenAPIPayloadCodec, keyof OpenAPIPayloadCodec>;
|
|
15
|
-
//# sourceMappingURL=openapi-payload-codec.d.ts.map
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { Router as BaseHono, Params } from 'hono/router';
|
|
2
|
-
import { type ANY_PROCEDURE, type ANY_ROUTER } from '@orpc/server';
|
|
3
|
-
export type Hono = BaseHono<[string, string[]]>;
|
|
4
|
-
export declare class OpenAPIProcedureMatcher {
|
|
5
|
-
private readonly hono;
|
|
6
|
-
private readonly router;
|
|
7
|
-
private pendingRouters;
|
|
8
|
-
constructor(hono: Hono, router: ANY_ROUTER);
|
|
9
|
-
match(method: string, pathname: string): Promise<{
|
|
10
|
-
path: string[];
|
|
11
|
-
procedure: ANY_PROCEDURE;
|
|
12
|
-
params: Params;
|
|
13
|
-
} | undefined>;
|
|
14
|
-
private add;
|
|
15
|
-
private handlePendingRouters;
|
|
16
|
-
private convertOpenAPIPathToRouterPath;
|
|
17
|
-
}
|
|
18
|
-
export type PublicOpenAPIProcedureMatcher = Pick<OpenAPIProcedureMatcher, keyof OpenAPIProcedureMatcher>;
|
|
19
|
-
//# sourceMappingURL=openapi-procedure-matcher.d.ts.map
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { Schema } from '@orpc/contract';
|
|
2
|
-
export interface SchemaCoercer {
|
|
3
|
-
coerce: (schema: Schema, value: unknown) => unknown;
|
|
4
|
-
}
|
|
5
|
-
export declare class CompositeSchemaCoercer implements SchemaCoercer {
|
|
6
|
-
private readonly coercers;
|
|
7
|
-
constructor(coercers: SchemaCoercer[]);
|
|
8
|
-
coerce(schema: Schema, value: unknown): unknown;
|
|
9
|
-
}
|
|
10
|
-
//# sourceMappingURL=schema-coercer.d.ts.map
|
package/dist/src/index.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/** unnoq */
|
|
2
|
-
export * from './json-serializer';
|
|
3
|
-
export * from './openapi';
|
|
4
|
-
export * from './openapi-content-builder';
|
|
5
|
-
export * from './openapi-generator';
|
|
6
|
-
export * from './openapi-parameters-builder';
|
|
7
|
-
export * from './openapi-path-parser';
|
|
8
|
-
export * from './schema';
|
|
9
|
-
export * from './schema-converter';
|
|
10
|
-
export * from './schema-utils';
|
|
11
|
-
export * from './utils';
|
|
12
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { OpenAPI } from './openapi';
|
|
2
|
-
import type { JSONSchema } from './schema';
|
|
3
|
-
import type { PublicSchemaUtils } from './schema-utils';
|
|
4
|
-
export declare class OpenAPIContentBuilder {
|
|
5
|
-
private readonly schemaUtils;
|
|
6
|
-
constructor(schemaUtils: PublicSchemaUtils);
|
|
7
|
-
build(jsonSchema: JSONSchema.JSONSchema, options?: Partial<OpenAPI.MediaTypeObject>): OpenAPI.ContentObject;
|
|
8
|
-
}
|
|
9
|
-
export type PublicOpenAPIContentBuilder = Pick<OpenAPIContentBuilder, keyof OpenAPIContentBuilder>;
|
|
10
|
-
//# sourceMappingURL=openapi-content-builder.d.ts.map
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import type { ContractRouter } from '@orpc/contract';
|
|
2
|
-
import type { ANY_ROUTER } from '@orpc/server';
|
|
3
|
-
import type { PublicOpenAPIPathParser } from './openapi-path-parser';
|
|
4
|
-
import type { SchemaConverter } from './schema-converter';
|
|
5
|
-
import { type PublicJSONSerializer } from './json-serializer';
|
|
6
|
-
import { type OpenAPI } from './openapi';
|
|
7
|
-
import { type PublicOpenAPIContentBuilder } from './openapi-content-builder';
|
|
8
|
-
import { type PublicOpenAPIParametersBuilder } from './openapi-parameters-builder';
|
|
9
|
-
import { type PublicSchemaUtils } from './schema-utils';
|
|
10
|
-
export interface OpenAPIGeneratorOptions {
|
|
11
|
-
contentBuilder?: PublicOpenAPIContentBuilder;
|
|
12
|
-
parametersBuilder?: PublicOpenAPIParametersBuilder;
|
|
13
|
-
schemaConverters?: SchemaConverter[];
|
|
14
|
-
schemaUtils?: PublicSchemaUtils;
|
|
15
|
-
jsonSerializer?: PublicJSONSerializer;
|
|
16
|
-
pathParser?: PublicOpenAPIPathParser;
|
|
17
|
-
/**
|
|
18
|
-
* Throw error when you missing define tag definition on OpenAPI root tags
|
|
19
|
-
*
|
|
20
|
-
* Example: if procedure has tags ['foo', 'bar'], and OpenAPI root tags is ['foo'], then error will be thrown
|
|
21
|
-
* Because OpenAPI root tags is missing 'bar' tag
|
|
22
|
-
*
|
|
23
|
-
* @default false
|
|
24
|
-
*/
|
|
25
|
-
considerMissingTagDefinitionAsError?: boolean;
|
|
26
|
-
/**
|
|
27
|
-
* Weather ignore procedures that has no path defined.
|
|
28
|
-
*
|
|
29
|
-
* @default false
|
|
30
|
-
*/
|
|
31
|
-
ignoreUndefinedPathProcedures?: boolean;
|
|
32
|
-
/**
|
|
33
|
-
* Throw error when you have error in OpenAPI generator
|
|
34
|
-
*
|
|
35
|
-
* @default false
|
|
36
|
-
*/
|
|
37
|
-
throwOnError?: boolean;
|
|
38
|
-
}
|
|
39
|
-
export declare class OpenAPIGenerator {
|
|
40
|
-
private readonly options?;
|
|
41
|
-
private readonly contentBuilder;
|
|
42
|
-
private readonly parametersBuilder;
|
|
43
|
-
private readonly schemaConverter;
|
|
44
|
-
private readonly schemaUtils;
|
|
45
|
-
private readonly jsonSerializer;
|
|
46
|
-
private readonly pathParser;
|
|
47
|
-
constructor(options?: OpenAPIGeneratorOptions | undefined);
|
|
48
|
-
generate(router: ContractRouter | ANY_ROUTER, doc: Omit<OpenAPI.OpenAPIObject, 'openapi'>): Promise<OpenAPI.OpenAPIObject>;
|
|
49
|
-
private handleError;
|
|
50
|
-
}
|
|
51
|
-
//# sourceMappingURL=openapi-generator.d.ts.map
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { OpenAPI } from './openapi';
|
|
2
|
-
import type { JSONSchema } from './schema';
|
|
3
|
-
export declare class OpenAPIParametersBuilder {
|
|
4
|
-
build(paramIn: OpenAPI.ParameterObject['in'], jsonSchema: JSONSchema.JSONSchema & {
|
|
5
|
-
type: 'object';
|
|
6
|
-
} & object, options?: Pick<OpenAPI.ParameterObject, 'example' | 'style' | 'required'>): OpenAPI.ParameterObject[];
|
|
7
|
-
}
|
|
8
|
-
export type PublicOpenAPIParametersBuilder = Pick<OpenAPIParametersBuilder, keyof OpenAPIParametersBuilder>;
|
|
9
|
-
//# sourceMappingURL=openapi-parameters-builder.d.ts.map
|