@orpc/openapi 0.0.0-next.b4e6d3a → 0.0.0-next.b825e0c

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.
@@ -5,7 +5,7 @@ var __export = (target, all) => {
5
5
  };
6
6
 
7
7
  // src/json-serializer.ts
8
- import { isObject } from "@orpc/shared";
8
+ import { isPlainObject } from "@orpc/shared";
9
9
  var JSONSerializer = class {
10
10
  serialize(payload) {
11
11
  if (payload instanceof Set)
@@ -26,7 +26,7 @@ var JSONSerializer = class {
26
26
  return payload.toString();
27
27
  if (payload instanceof URL)
28
28
  return payload.toString();
29
- if (!isObject(payload))
29
+ if (!isPlainObject(payload))
30
30
  return payload;
31
31
  return Object.keys(payload).reduce(
32
32
  (carry, key) => {
@@ -49,4 +49,4 @@ export {
49
49
  JSONSerializer,
50
50
  standardizeHTTPPath
51
51
  };
52
- //# sourceMappingURL=chunk-HC5PVG4R.js.map
52
+ //# sourceMappingURL=chunk-BHJYKXQL.js.map
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  OpenAPICodec,
3
3
  OpenAPIMatcher
4
- } from "./chunk-DRV7KYES.js";
4
+ } from "./chunk-M5HOHBLW.js";
5
5
 
6
6
  // src/adapters/fetch/openapi-handler.ts
7
7
  import { fetchRequestToStandardRequest, standardResponseToFetchResponse } from "@orpc/server/fetch";
@@ -29,4 +29,4 @@ var OpenAPIHandler = class {
29
29
  export {
30
30
  OpenAPIHandler
31
31
  };
32
- //# sourceMappingURL=chunk-NHYWV7BW.js.map
32
+ //# sourceMappingURL=chunk-HQ34JZI7.js.map
@@ -2,7 +2,7 @@ import {
2
2
  JSONSerializer,
3
3
  __export,
4
4
  standardizeHTTPPath
5
- } from "./chunk-HC5PVG4R.js";
5
+ } from "./chunk-BHJYKXQL.js";
6
6
 
7
7
  // src/adapters/standard/bracket-notation.ts
8
8
  var bracket_notation_exports = {};
@@ -13,9 +13,9 @@ __export(bracket_notation_exports, {
13
13
  serialize: () => serialize,
14
14
  stringifyPath: () => stringifyPath
15
15
  });
16
- import { isObject } from "@orpc/shared";
16
+ import { isPlainObject } from "@orpc/shared";
17
17
  function serialize(payload, parentKey = "") {
18
- if (!Array.isArray(payload) && !isObject(payload))
18
+ if (!Array.isArray(payload) && !isPlainObject(payload))
19
19
  return [["", payload]];
20
20
  const result = [];
21
21
  function helper(value, path) {
@@ -23,7 +23,7 @@ function serialize(payload, parentKey = "") {
23
23
  value.forEach((item, index) => {
24
24
  helper(item, [...path, String(index)]);
25
25
  });
26
- } else if (isObject(value)) {
26
+ } else if (isPlainObject(value)) {
27
27
  for (const [key, val] of Object.entries(value)) {
28
28
  helper(val, [...path, key]);
29
29
  }
@@ -223,7 +223,7 @@ function parsePath(path) {
223
223
 
224
224
  // src/adapters/standard/openapi-codec.ts
225
225
  import { fallbackContractConfig } from "@orpc/contract";
226
- import { isObject as isObject2 } from "@orpc/shared";
226
+ import { isPlainObject as isPlainObject2, once } from "@orpc/shared";
227
227
 
228
228
  // src/adapters/standard/openapi-serializer.ts
229
229
  import { findDeepMatches } from "@orpc/shared";
@@ -261,43 +261,54 @@ var OpenAPISerializer = class {
261
261
  }
262
262
  };
263
263
 
264
+ // src/adapters/standard/schema-coercer.ts
265
+ var CompositeSchemaCoercer = class {
266
+ constructor(coercers) {
267
+ this.coercers = coercers;
268
+ }
269
+ coerce(schema, value) {
270
+ let current = value;
271
+ for (const coercer of this.coercers) {
272
+ current = coercer.coerce(schema, current);
273
+ }
274
+ return current;
275
+ }
276
+ };
277
+
264
278
  // src/adapters/standard/openapi-codec.ts
265
279
  var OpenAPICodec = class {
266
280
  serializer;
281
+ compositeSchemaCoercer;
267
282
  constructor(options) {
268
283
  this.serializer = options?.serializer ?? new OpenAPISerializer();
284
+ this.compositeSchemaCoercer = new CompositeSchemaCoercer(options?.schemaCoercers ?? []);
269
285
  }
270
286
  async decode(request, params, procedure) {
271
287
  const inputStructure = fallbackContractConfig("defaultInputStructure", procedure["~orpc"].route.inputStructure);
272
288
  if (inputStructure === "compact") {
273
289
  const data = request.method === "GET" ? this.serializer.deserialize(request.url.searchParams) : this.serializer.deserialize(await request.body());
274
290
  if (data === void 0) {
275
- return params;
291
+ return this.compositeSchemaCoercer.coerce(procedure["~orpc"].inputSchema, params);
276
292
  }
277
- if (isObject2(data)) {
278
- return {
293
+ if (isPlainObject2(data)) {
294
+ return this.compositeSchemaCoercer.coerce(procedure["~orpc"].inputSchema, {
279
295
  ...params,
280
296
  ...data
281
- };
297
+ });
282
298
  }
283
- return data;
299
+ return this.compositeSchemaCoercer.coerce(procedure["~orpc"].inputSchema, data);
284
300
  }
285
- const deserializeSearchParams = () => {
301
+ const query = once(() => {
286
302
  return this.serializer.deserialize(request.url.searchParams);
287
- };
288
- return {
303
+ });
304
+ return this.compositeSchemaCoercer.coerce(procedure["~orpc"].inputSchema, {
289
305
  params,
290
306
  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 });
307
+ return query();
297
308
  },
298
309
  headers: request.headers,
299
310
  body: this.serializer.deserialize(await request.body())
300
- };
311
+ });
301
312
  }
302
313
  encode(output, procedure) {
303
314
  const successStatus = fallbackContractConfig("defaultSuccessStatus", procedure["~orpc"].route.successStatus);
@@ -309,7 +320,7 @@ var OpenAPICodec = class {
309
320
  body: this.serializer.serialize(output)
310
321
  };
311
322
  }
312
- if (!isObject2(output)) {
323
+ if (!isPlainObject2(output)) {
313
324
  throw new Error(
314
325
  'Invalid output structure for "detailed" output. Expected format: { body: any, headers?: Record<string, string | string[] | undefined> }'
315
326
  );
@@ -414,7 +425,8 @@ function convertOpenAPIPathToRouterPath(path) {
414
425
  export {
415
426
  bracket_notation_exports,
416
427
  OpenAPISerializer,
428
+ CompositeSchemaCoercer,
417
429
  OpenAPICodec,
418
430
  OpenAPIMatcher
419
431
  };
420
- //# sourceMappingURL=chunk-DRV7KYES.js.map
432
+ //# sourceMappingURL=chunk-M5HOHBLW.js.map
package/dist/fetch.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  OpenAPIHandler
3
- } from "./chunk-NHYWV7BW.js";
4
- import "./chunk-DRV7KYES.js";
5
- import "./chunk-HC5PVG4R.js";
3
+ } from "./chunk-HQ34JZI7.js";
4
+ import "./chunk-M5HOHBLW.js";
5
+ import "./chunk-BHJYKXQL.js";
6
6
  export {
7
7
  OpenAPIHandler
8
8
  };
package/dist/hono.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  OpenAPIHandler
3
- } from "./chunk-NHYWV7BW.js";
4
- import "./chunk-DRV7KYES.js";
5
- import "./chunk-HC5PVG4R.js";
3
+ } from "./chunk-HQ34JZI7.js";
4
+ import "./chunk-M5HOHBLW.js";
5
+ import "./chunk-BHJYKXQL.js";
6
6
  export {
7
7
  OpenAPIHandler
8
8
  };
package/dist/index.js CHANGED
@@ -1,53 +1,7 @@
1
1
  import {
2
2
  JSONSerializer,
3
3
  standardizeHTTPPath
4
- } from "./chunk-HC5PVG4R.js";
5
-
6
- // src/openapi-operation-extender.ts
7
- import { isProcedure } from "@orpc/server";
8
- var OPERATION_EXTENDER_SYMBOL = Symbol("ORPC_OPERATION_EXTENDER");
9
- function setOperationExtender(o, extend) {
10
- return new Proxy(o, {
11
- get(target, prop, receiver) {
12
- if (prop === OPERATION_EXTENDER_SYMBOL) {
13
- return extend;
14
- }
15
- return Reflect.get(target, prop, receiver);
16
- }
17
- });
18
- }
19
- function getOperationExtender(o) {
20
- return o[OPERATION_EXTENDER_SYMBOL];
21
- }
22
- function extendOperation(operation, procedure) {
23
- const operationExtenders = [];
24
- for (const errorItem of Object.values(procedure["~orpc"].errorMap)) {
25
- const maybeExtender = getOperationExtender(errorItem);
26
- if (maybeExtender) {
27
- operationExtenders.push(maybeExtender);
28
- }
29
- }
30
- if (isProcedure(procedure)) {
31
- for (const middleware of procedure["~orpc"].middlewares) {
32
- const maybeExtender = getOperationExtender(middleware);
33
- if (maybeExtender) {
34
- operationExtenders.push(maybeExtender);
35
- }
36
- }
37
- }
38
- let currentOperation = operation;
39
- for (const extender of operationExtenders) {
40
- if (typeof extender === "function") {
41
- currentOperation = extender(currentOperation, procedure);
42
- } else {
43
- currentOperation = {
44
- ...currentOperation,
45
- ...extender
46
- };
47
- }
48
- }
49
- return currentOperation;
50
- }
4
+ } from "./chunk-BHJYKXQL.js";
51
5
 
52
6
  // src/openapi.ts
53
7
  import { OpenApiBuilder } from "openapi3-ts/oas31";
@@ -229,14 +183,14 @@ var OpenAPIOutputStructureParser = class {
229
183
  };
230
184
 
231
185
  // src/openapi-parameters-builder.ts
232
- import { get, isObject, omit } from "@orpc/shared";
186
+ import { get, isPlainObject, omit } from "@orpc/shared";
233
187
  var OpenAPIParametersBuilder = class {
234
188
  build(paramIn, jsonSchema, options) {
235
189
  const parameters = [];
236
190
  for (const name in jsonSchema.properties) {
237
191
  const schema = jsonSchema.properties[name];
238
192
  const paramExamples = jsonSchema.examples?.filter((example) => {
239
- return isObject(example) && name in example;
193
+ return isPlainObject(example) && name in example;
240
194
  }).map((example) => {
241
195
  return example[name];
242
196
  });
@@ -297,7 +251,7 @@ var CompositeSchemaConverter = class {
297
251
  };
298
252
 
299
253
  // src/schema-utils.ts
300
- import { isObject as isObject2 } from "@orpc/shared";
254
+ import { isPlainObject as isPlainObject2 } from "@orpc/shared";
301
255
 
302
256
  // src/schema.ts
303
257
  import * as JSONSchema from "json-schema-typed/draft-2020-12";
@@ -359,7 +313,7 @@ var SchemaUtils = class {
359
313
  }, {});
360
314
  matched.required = schema.required?.filter((key) => separatedProperties.includes(key));
361
315
  matched.examples = schema.examples?.map((example) => {
362
- if (!isObject2(example)) {
316
+ if (!isPlainObject2(example)) {
363
317
  return example;
364
318
  }
365
319
  return Object.entries(example).reduce((acc, [key, value]) => {
@@ -375,7 +329,7 @@ var SchemaUtils = class {
375
329
  }, {});
376
330
  rest.required = schema.required?.filter((key) => !separatedProperties.includes(key));
377
331
  rest.examples = schema.examples?.map((example) => {
378
- if (!isObject2(example)) {
332
+ if (!isPlainObject2(example)) {
379
333
  return example;
380
334
  }
381
335
  return Object.entries(example).reduce((acc, [key, value]) => {
@@ -552,9 +506,8 @@ var OpenAPIGenerator = class {
552
506
  requestBody,
553
507
  responses
554
508
  };
555
- const extendedOperation = extendOperation(operation, contract);
556
509
  builder.addPath(httpPath, {
557
- [method.toLocaleLowerCase()]: extendedOperation
510
+ [method.toLocaleLowerCase()]: operation
558
511
  });
559
512
  } catch (e) {
560
513
  if (e instanceof OpenAPIError) {
@@ -576,11 +529,6 @@ var OpenAPIGenerator = class {
576
529
  return this.jsonSerializer.serialize(builder.getSpec());
577
530
  }
578
531
  };
579
-
580
- // src/index.ts
581
- var oo = {
582
- spec: setOperationExtender
583
- };
584
532
  export {
585
533
  CompositeSchemaConverter,
586
534
  JSONSchema,
@@ -593,10 +541,6 @@ export {
593
541
  OpenAPIPathParser,
594
542
  OpenApiBuilder,
595
543
  SchemaUtils,
596
- extendOperation,
597
- getOperationExtender,
598
- oo,
599
- setOperationExtender,
600
544
  standardizeHTTPPath
601
545
  };
602
546
  //# sourceMappingURL=index.js.map
package/dist/next.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  OpenAPIHandler
3
- } from "./chunk-NHYWV7BW.js";
4
- import "./chunk-DRV7KYES.js";
5
- import "./chunk-HC5PVG4R.js";
3
+ } from "./chunk-HQ34JZI7.js";
4
+ import "./chunk-M5HOHBLW.js";
5
+ import "./chunk-BHJYKXQL.js";
6
6
  export {
7
7
  OpenAPIHandler
8
8
  };
package/dist/node.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  OpenAPICodec,
3
3
  OpenAPIMatcher
4
- } from "./chunk-DRV7KYES.js";
5
- import "./chunk-HC5PVG4R.js";
4
+ } from "./chunk-M5HOHBLW.js";
5
+ import "./chunk-BHJYKXQL.js";
6
6
 
7
7
  // src/adapters/node/openapi-handler.ts
8
8
  import { nodeHttpResponseSendStandardResponse, nodeHttpToStandardRequest } from "@orpc/server/node";
@@ -1,11 +1,10 @@
1
1
  import type { Context, Router } from '@orpc/server';
2
2
  import type { FetchHandler, FetchHandleResult } from '@orpc/server/fetch';
3
- import type { StandardHandleOptions } from '@orpc/server/standard';
4
- import type { MaybeOptionalOptions } from '@orpc/shared';
3
+ import type { StandardHandleRest } from '@orpc/server/standard';
5
4
  import type { OpenAPIHandlerOptions } from '../standard';
6
5
  export declare class OpenAPIHandler<T extends Context> implements FetchHandler<T> {
7
6
  private readonly standardHandler;
8
7
  constructor(router: Router<T, any>, options?: NoInfer<OpenAPIHandlerOptions<T>>);
9
- handle(request: Request, ...rest: MaybeOptionalOptions<StandardHandleOptions<T>>): Promise<FetchHandleResult>;
8
+ handle(request: Request, ...rest: StandardHandleRest<T>): Promise<FetchHandleResult>;
10
9
  }
11
10
  //# sourceMappingURL=openapi-handler.d.ts.map
@@ -1,11 +1,10 @@
1
1
  import type { Context, Router } from '@orpc/server';
2
2
  import type { NodeHttpHandler, NodeHttpHandleResult, NodeHttpRequest, NodeHttpResponse } from '@orpc/server/node';
3
- import type { StandardHandleOptions } from '@orpc/server/standard';
4
- import type { MaybeOptionalOptions } from '@orpc/shared';
3
+ import type { StandardHandleRest } from '@orpc/server/standard';
5
4
  import type { OpenAPIHandlerOptions } from '../standard';
6
5
  export declare class OpenAPIHandler<T extends Context> implements NodeHttpHandler<T> {
7
6
  private readonly standardHandler;
8
7
  constructor(router: Router<T, any>, options?: NoInfer<OpenAPIHandlerOptions<T>>);
9
- handle(req: NodeHttpRequest, res: NodeHttpResponse, ...rest: MaybeOptionalOptions<StandardHandleOptions<T>>): Promise<NodeHttpHandleResult>;
8
+ handle(req: NodeHttpRequest, res: NodeHttpResponse, ...rest: StandardHandleRest<T>): Promise<NodeHttpHandleResult>;
10
9
  }
11
10
  //# sourceMappingURL=openapi-handler.d.ts.map
@@ -3,4 +3,5 @@ export * from './openapi-codec';
3
3
  export * from './openapi-handler';
4
4
  export * from './openapi-matcher';
5
5
  export * from './openapi-serializer';
6
+ export * from './schema-coercer';
6
7
  //# sourceMappingURL=index.d.ts.map
@@ -2,11 +2,14 @@ import type { AnyProcedure } from '@orpc/server';
2
2
  import type { StandardCodec, StandardParams, StandardRequest, StandardResponse } from '@orpc/server/standard';
3
3
  import { type ORPCError } from '@orpc/contract';
4
4
  import { OpenAPISerializer } from './openapi-serializer';
5
+ import { type SchemaCoercer } from './schema-coercer';
5
6
  export interface OpenAPICodecOptions {
6
7
  serializer?: OpenAPISerializer;
8
+ schemaCoercers?: SchemaCoercer[];
7
9
  }
8
10
  export declare class OpenAPICodec implements StandardCodec {
9
11
  private readonly serializer;
12
+ private readonly compositeSchemaCoercer;
10
13
  constructor(options?: OpenAPICodecOptions);
11
14
  decode(request: StandardRequest, params: StandardParams | undefined, procedure: AnyProcedure): Promise<unknown>;
12
15
  encode(output: unknown, procedure: AnyProcedure): StandardResponse;
@@ -0,0 +1,10 @@
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
@@ -1,17 +1,12 @@
1
1
  /** unnoq */
2
- import { setOperationExtender } from './openapi-operation-extender';
3
2
  export * from './json-serializer';
4
3
  export * from './openapi';
5
4
  export * from './openapi-content-builder';
6
5
  export * from './openapi-generator';
7
- export * from './openapi-operation-extender';
8
6
  export * from './openapi-parameters-builder';
9
7
  export * from './openapi-path-parser';
10
8
  export * from './schema';
11
9
  export * from './schema-converter';
12
10
  export * from './schema-utils';
13
11
  export * from './utils';
14
- export declare const oo: {
15
- spec: typeof setOperationExtender;
16
- };
17
12
  //# sourceMappingURL=index.d.ts.map
package/dist/standard.js CHANGED
@@ -1,12 +1,14 @@
1
1
  import {
2
+ CompositeSchemaCoercer,
2
3
  OpenAPICodec,
3
4
  OpenAPIMatcher,
4
5
  OpenAPISerializer,
5
6
  bracket_notation_exports
6
- } from "./chunk-DRV7KYES.js";
7
- import "./chunk-HC5PVG4R.js";
7
+ } from "./chunk-M5HOHBLW.js";
8
+ import "./chunk-BHJYKXQL.js";
8
9
  export {
9
10
  bracket_notation_exports as BracketNotation,
11
+ CompositeSchemaCoercer,
10
12
  OpenAPICodec,
11
13
  OpenAPIMatcher,
12
14
  OpenAPISerializer
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/openapi",
3
3
  "type": "module",
4
- "version": "0.0.0-next.b4e6d3a",
4
+ "version": "0.0.0-next.b825e0c",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -54,15 +54,18 @@
54
54
  "dist"
55
55
  ],
56
56
  "dependencies": {
57
+ "@standard-schema/spec": "1.0.0-beta.4",
58
+ "@types/content-disposition": "^0.5.8",
59
+ "content-disposition": "^0.5.4",
57
60
  "escape-string-regexp": "^5.0.0",
58
61
  "fast-content-type-parse": "^2.0.0",
59
62
  "json-schema-typed": "^8.0.1",
60
63
  "openapi3-ts": "^4.4.0",
61
64
  "rou3": "^0.5.1",
62
65
  "wildcard-match": "^5.1.3",
63
- "@orpc/contract": "0.0.0-next.b4e6d3a",
64
- "@orpc/server": "0.0.0-next.b4e6d3a",
65
- "@orpc/shared": "0.0.0-next.b4e6d3a"
66
+ "@orpc/contract": "0.0.0-next.b825e0c",
67
+ "@orpc/server": "0.0.0-next.b825e0c",
68
+ "@orpc/shared": "0.0.0-next.b825e0c"
66
69
  },
67
70
  "devDependencies": {
68
71
  "@readme/openapi-parser": "^2.6.0",
@@ -1,7 +0,0 @@
1
- import type { AnyContractProcedure } from '@orpc/contract';
2
- import type { OpenAPI } from './openapi';
3
- export type OverrideOperationValue = OpenAPI.OperationObject | ((current: OpenAPI.OperationObject, procedure: AnyContractProcedure) => OpenAPI.OperationObject);
4
- export declare function setOperationExtender<T extends object>(o: T, extend: OverrideOperationValue): T;
5
- export declare function getOperationExtender(o: object): OverrideOperationValue | undefined;
6
- export declare function extendOperation(operation: OpenAPI.OperationObject, procedure: AnyContractProcedure): OpenAPI.OperationObject;
7
- //# sourceMappingURL=openapi-operation-extender.d.ts.map