@temporary-name/server 1.9.3-alpha.fb7b7d19964e1b2def7056f4345b63d6fcacce10 → 1.9.3-alpha.fb7e3a67f82deaeffad5063e136b2f3c03c4b5b3

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.
Files changed (32) hide show
  1. package/dist/adapters/aws-lambda/index.d.mts +4 -4
  2. package/dist/adapters/aws-lambda/index.d.ts +4 -4
  3. package/dist/adapters/aws-lambda/index.mjs +5 -6
  4. package/dist/adapters/fetch/index.d.mts +4 -4
  5. package/dist/adapters/fetch/index.d.ts +4 -4
  6. package/dist/adapters/fetch/index.mjs +5 -6
  7. package/dist/adapters/node/index.d.mts +5 -5
  8. package/dist/adapters/node/index.d.ts +5 -5
  9. package/dist/adapters/node/index.mjs +5 -6
  10. package/dist/{adapters/standard → handler}/index.d.mts +4 -5
  11. package/dist/{adapters/standard → handler}/index.d.ts +4 -5
  12. package/dist/handler/index.mjs +8 -0
  13. package/dist/index.d.mts +273 -34
  14. package/dist/index.d.ts +273 -34
  15. package/dist/index.mjs +347 -35
  16. package/dist/openapi/index.d.mts +3 -2
  17. package/dist/openapi/index.d.ts +3 -2
  18. package/dist/openapi/index.mjs +64 -13
  19. package/dist/shared/server.-tR-4rQ5.mjs +523 -0
  20. package/dist/shared/{server.DXPMDozZ.d.mts → server.BwcJq6aP.d.mts} +462 -42
  21. package/dist/shared/{server.DXPMDozZ.d.ts → server.BwcJq6aP.d.ts} +462 -42
  22. package/dist/shared/server.CjPiuQYH.d.mts +51 -0
  23. package/dist/shared/server.CjPiuQYH.d.ts +51 -0
  24. package/dist/shared/{server.Cza0RB3u.mjs → server.D2NXNHIf.mjs} +5 -9
  25. package/dist/shared/{server.B0LJ_wu-.d.ts → server.Deg5phAY.d.ts} +4 -6
  26. package/dist/shared/{server.ChOv1yG3.mjs → server.DvgWQUGK.mjs} +189 -12
  27. package/dist/shared/{server.BQZMQrPe.d.mts → server.hAH-LVh_.d.mts} +4 -6
  28. package/dist/shared/{server.CYa9puL2.mjs → server.n1y5fcVQ.mjs} +24 -112
  29. package/package.json +11 -12
  30. package/dist/adapters/standard/index.mjs +0 -9
  31. package/dist/shared/server.CQIFwyhc.mjs +0 -40
  32. package/dist/shared/server.YUvuxHty.mjs +0 -48
package/dist/index.mjs CHANGED
@@ -1,19 +1,23 @@
1
- import { assertNever, splitFirst, ORPCError, onError, resolveMaybeOptionalOptions, isTypescriptObject, isPropertyKey } from '@temporary-name/shared';
2
- export { AsyncIteratorClass, EventPublisher, ORPCError, asyncIteratorToStream as eventIteratorToStream, isDefinedError, onError, onFinish, onStart, onSuccess, streamToAsyncIteratorClass as streamToEventIterator } from '@temporary-name/shared';
1
+ import { assertNever, splitFirst, onError, isObject, toArray, guard, resolveMaybeOptionalOptions, isTypescriptObject, isPropertyKey } from '@temporary-name/shared';
2
+ export { AsyncIteratorClass, EventPublisher, asyncIteratorToStream as eventIteratorToStream, onError, onFinish, onStart, onSuccess, streamToAsyncIteratorClass as streamToEventIterator } from '@temporary-name/shared';
3
3
  import * as z from '@temporary-name/zod';
4
4
  import { SchemaClass, object, core, gatingContext } from '@temporary-name/zod';
5
+ export { z as baseZ };
6
+ import { U as UnauthorizedError, P as Procedure, m as mergePrefix, a as mergeTags, b as enhanceRouter, C as Contract, p as parseEndpointDefinition, c as mergeRoute, d as prefixRoute, f as addMiddleware, l as lazyInternal, h as getLazyMeta, u as unlazy, j as isProcedure } from './shared/server.DvgWQUGK.mjs';
7
+ export { A as APIError, B as BadRequestError, F as ForbiddenError, I as InternalServerError, L as LAZY_SYMBOL, N as NotFoundError, V as ValidationError, x as createAccessibleLazyRouter, e as encodeError, D as endpointRegex, g as getDynamicParams, w as getRouter, i as isAPIErrorStatus, E as isDevelopment, o as isLazy, q as isStartWithMiddlewares, n as lazy, k as makeErrors, v as mergeMiddlewares, r as resolveContractProcedures, s as standardizeHTTPPath, t as toAPIError, y as traverseContractProcedures, z as unlazyRouter } from './shared/server.DvgWQUGK.mjs';
5
8
  import { g as getCookie } from './shared/server.C1RJffw4.mjs';
6
- import { P as Procedure, m as mergePrefix, a as mergeTags, e as enhanceRouter, C as Contract, p as parseEndpointDefinition, b as mergeRoute, c as prefixRoute, d as addMiddleware, l as lazyInternal, f as getLazyMeta, u as unlazy, i as isProcedure, h as isLazy, j as getRouter } from './shared/server.ChOv1yG3.mjs';
7
- export { L as LAZY_SYMBOL, V as ValidationError, q as createAccessibleLazyRouter, w as endpointRegex, g as getDynamicParams, n as isStartWithMiddlewares, k as lazy, o as mergeMiddlewares, r as resolveContractProcedures, s as standardizeHTTPPath, t as traverseContractProcedures, v as unlazyRouter } from './shared/server.ChOv1yG3.mjs';
8
- import { c as createProcedureClient } from './shared/server.Cza0RB3u.mjs';
9
- export { m as mergeCurrentContext, a as middlewareOutputFn } from './shared/server.Cza0RB3u.mjs';
10
- export { e as eventIterator, g as getEventIteratorSchemaDetails } from './shared/server.YUvuxHty.mjs';
9
+ import { c as createProcedureClient } from './shared/server.D2NXNHIf.mjs';
10
+ export { m as mergeCurrentContext, a as middlewareOutputFn } from './shared/server.D2NXNHIf.mjs';
11
+ import { J as JsonSchemaXNativeType } from './shared/server.-tR-4rQ5.mjs';
12
+ export { b as JSON_SCHEMA_INPUT_REGISTRY, c as JSON_SCHEMA_OUTPUT_REGISTRY, a as JSON_SCHEMA_REGISTRY, Z as ZodToJsonSchemaConverter, e as eventIterator, g as getEventIteratorSchemaDetails } from './shared/server.-tR-4rQ5.mjs';
11
13
  export { getEventMeta, withEventMeta } from '@temporary-name/standard-server';
12
14
  import 'cookie';
15
+ import '@temporary-name/server/openapi';
16
+ import 'zod/v4/core';
13
17
 
14
18
  function validateTokenPrefix(prefix, token) {
15
19
  if (prefix && !token.startsWith(prefix)) {
16
- throw new ORPCError("UNAUTHORIZED", { message: `Invalid auth token. It must start with "${prefix}"` });
20
+ throw new UnauthorizedError({ message: `Invalid auth token. It must start with "${prefix}"` });
17
21
  }
18
22
  }
19
23
  function validateTokenAuth(config, token, options) {
@@ -185,6 +189,12 @@ class ProcedureBuilder extends Contract {
185
189
  middlewares: addMiddleware(this["~orpc"].middlewares, middleware)
186
190
  });
187
191
  }
192
+ useErrors(errorMap) {
193
+ return new this.constructor({
194
+ ...this["~orpc"],
195
+ errorMap
196
+ });
197
+ }
188
198
  // The default of false for ValidatedAuthContext is used when you pass in the type 'none'. We use false
189
199
  // because we can't use null or undefined (see ValidatedAuthContext) but we still want it to be falsy.
190
200
  useAuth(config) {
@@ -199,7 +209,7 @@ class ProcedureBuilder extends Contract {
199
209
  if (authConfigs.length > 1) {
200
210
  authDescriptions = `one of: ${authDescriptions}`;
201
211
  }
202
- throw new ORPCError("UNAUTHORIZED", {
212
+ throw new UnauthorizedError({
203
213
  message: `Authentication required. You must provide ${authDescriptions}`
204
214
  });
205
215
  }
@@ -305,6 +315,7 @@ class Builder extends BuilderWithMiddlewares {
305
315
  const baseApi = new Builder({
306
316
  route: {},
307
317
  meta: {},
318
+ errorMap: {},
308
319
  inputValidationIndex: 0,
309
320
  outputValidationIndex: 0,
310
321
  middlewares: [
@@ -319,6 +330,332 @@ const baseApi = new Builder({
319
330
  authConfigs: []
320
331
  });
321
332
 
333
+ const FLEXIBLE_DATE_FORMAT_REGEX = /^[^-]+-[^-]+-[^-]+$/;
334
+ class experimental_JsonSchemaCoercer {
335
+ coerce(schema, value, options = {}) {
336
+ const [, coerced] = this.#coerce(schema, value, options);
337
+ return coerced;
338
+ }
339
+ #coerce(schema, originalValue, options) {
340
+ if (typeof schema === "boolean") {
341
+ return [schema, originalValue];
342
+ }
343
+ if (Array.isArray(schema.type)) {
344
+ return this.#coerce(
345
+ {
346
+ anyOf: schema.type.map((type) => ({ ...schema, type }))
347
+ },
348
+ originalValue,
349
+ options
350
+ );
351
+ }
352
+ let coerced = originalValue;
353
+ let satisfied = true;
354
+ if (typeof schema.$ref === "string") {
355
+ const refSchema = options?.components?.[schema.$ref];
356
+ if (refSchema !== void 0) {
357
+ const [subSatisfied, subCoerced] = this.#coerce(refSchema, coerced, options);
358
+ coerced = subCoerced;
359
+ satisfied = subSatisfied;
360
+ }
361
+ }
362
+ const enumValues = schema.const !== void 0 ? [schema.const] : schema.enum;
363
+ if (enumValues !== void 0 && !enumValues.includes(coerced)) {
364
+ if (typeof coerced === "string") {
365
+ const numberValue = this.#stringToNumber(coerced);
366
+ if (enumValues.includes(numberValue)) {
367
+ coerced = numberValue;
368
+ } else {
369
+ const booleanValue = this.#stringToBoolean(coerced);
370
+ if (enumValues.includes(booleanValue)) {
371
+ coerced = booleanValue;
372
+ } else {
373
+ satisfied = false;
374
+ }
375
+ }
376
+ } else {
377
+ satisfied = false;
378
+ }
379
+ }
380
+ if (typeof schema.type === "string") {
381
+ switch (schema.type) {
382
+ case "null": {
383
+ if (coerced !== null) {
384
+ satisfied = false;
385
+ }
386
+ break;
387
+ }
388
+ case "string": {
389
+ if (typeof coerced !== "string") {
390
+ satisfied = false;
391
+ }
392
+ break;
393
+ }
394
+ case "number": {
395
+ if (typeof coerced === "string") {
396
+ coerced = this.#stringToNumber(coerced);
397
+ }
398
+ if (typeof coerced !== "number") {
399
+ satisfied = false;
400
+ }
401
+ break;
402
+ }
403
+ case "integer": {
404
+ if (typeof coerced === "string") {
405
+ coerced = this.#stringToInteger(coerced);
406
+ }
407
+ if (typeof coerced !== "number" || !Number.isInteger(coerced)) {
408
+ satisfied = false;
409
+ }
410
+ break;
411
+ }
412
+ case "boolean": {
413
+ if (typeof coerced === "string") {
414
+ coerced = this.#stringToBoolean(coerced);
415
+ }
416
+ if (typeof coerced !== "boolean") {
417
+ satisfied = false;
418
+ }
419
+ break;
420
+ }
421
+ case "array": {
422
+ if (Array.isArray(coerced)) {
423
+ const prefixItemSchemas = "prefixItems" in schema ? toArray(schema.prefixItems) : Array.isArray(schema.items) ? schema.items : [];
424
+ const itemSchema = Array.isArray(schema.items) ? schema.additionalItems : schema.items;
425
+ let shouldUseCoercedItems = false;
426
+ const coercedItems = coerced.map((item, i) => {
427
+ const subSchema = prefixItemSchemas[i] ?? itemSchema;
428
+ if (subSchema === void 0) {
429
+ satisfied = false;
430
+ return item;
431
+ }
432
+ const [subSatisfied, subCoerced] = this.#coerce(subSchema, item, options);
433
+ if (!subSatisfied) {
434
+ satisfied = false;
435
+ }
436
+ if (subCoerced !== item) {
437
+ shouldUseCoercedItems = true;
438
+ }
439
+ return subCoerced;
440
+ });
441
+ if (coercedItems.length < prefixItemSchemas.length) {
442
+ satisfied = false;
443
+ }
444
+ if (shouldUseCoercedItems) {
445
+ coerced = coercedItems;
446
+ }
447
+ } else {
448
+ satisfied = false;
449
+ }
450
+ break;
451
+ }
452
+ case "object": {
453
+ if (Array.isArray(coerced)) {
454
+ coerced = { ...coerced };
455
+ }
456
+ if (isObject(coerced)) {
457
+ let shouldUseCoercedItems = false;
458
+ const coercedItems = {};
459
+ const patternProperties = Object.entries(schema.patternProperties ?? {}).map(
460
+ ([key, value]) => [new RegExp(key), value]
461
+ );
462
+ for (const key in coerced) {
463
+ const value = coerced[key];
464
+ const subSchema = schema.properties?.[key] ?? patternProperties.find(([pattern]) => pattern.test(key))?.[1] ?? schema.additionalProperties;
465
+ if (value === void 0 && !schema.required?.includes(key)) {
466
+ coercedItems[key] = value;
467
+ } else if (subSchema === void 0) {
468
+ coercedItems[key] = value;
469
+ satisfied = false;
470
+ } else {
471
+ const [subSatisfied, subCoerced] = this.#coerce(subSchema, value, options);
472
+ coercedItems[key] = subCoerced;
473
+ if (!subSatisfied) {
474
+ satisfied = false;
475
+ }
476
+ if (subCoerced !== value) {
477
+ shouldUseCoercedItems = true;
478
+ }
479
+ }
480
+ }
481
+ if (schema.required?.some((key) => !Object.hasOwn(coercedItems, key))) {
482
+ satisfied = false;
483
+ }
484
+ if (shouldUseCoercedItems) {
485
+ coerced = coercedItems;
486
+ }
487
+ } else {
488
+ satisfied = false;
489
+ }
490
+ break;
491
+ }
492
+ }
493
+ }
494
+ if ("x-native-type" in schema && typeof schema["x-native-type"] === "string") {
495
+ switch (schema["x-native-type"]) {
496
+ case JsonSchemaXNativeType.Date: {
497
+ if (typeof coerced === "string") {
498
+ coerced = this.#stringToDate(coerced);
499
+ }
500
+ if (!(coerced instanceof Date)) {
501
+ satisfied = false;
502
+ }
503
+ break;
504
+ }
505
+ case JsonSchemaXNativeType.BigInt: {
506
+ switch (typeof coerced) {
507
+ case "string":
508
+ coerced = this.#stringToBigInt(coerced);
509
+ break;
510
+ case "number":
511
+ coerced = this.#numberToBigInt(coerced);
512
+ break;
513
+ }
514
+ if (typeof coerced !== "bigint") {
515
+ satisfied = false;
516
+ }
517
+ break;
518
+ }
519
+ case JsonSchemaXNativeType.RegExp: {
520
+ if (typeof coerced === "string") {
521
+ coerced = this.#stringToRegExp(coerced);
522
+ }
523
+ if (!(coerced instanceof RegExp)) {
524
+ satisfied = false;
525
+ }
526
+ break;
527
+ }
528
+ case JsonSchemaXNativeType.Url: {
529
+ if (typeof coerced === "string") {
530
+ coerced = this.#stringToURL(coerced);
531
+ }
532
+ if (!(coerced instanceof URL)) {
533
+ satisfied = false;
534
+ }
535
+ break;
536
+ }
537
+ case JsonSchemaXNativeType.Set: {
538
+ if (Array.isArray(coerced)) {
539
+ coerced = this.#arrayToSet(coerced);
540
+ }
541
+ if (!(coerced instanceof Set)) {
542
+ satisfied = false;
543
+ }
544
+ break;
545
+ }
546
+ case JsonSchemaXNativeType.Map: {
547
+ if (Array.isArray(coerced)) {
548
+ coerced = this.#arrayToMap(coerced);
549
+ }
550
+ if (!(coerced instanceof Map)) {
551
+ satisfied = false;
552
+ }
553
+ break;
554
+ }
555
+ }
556
+ }
557
+ if (schema.allOf) {
558
+ for (const subSchema of schema.allOf) {
559
+ const [subSatisfied, subCoerced] = this.#coerce(subSchema, coerced, options);
560
+ coerced = subCoerced;
561
+ if (!subSatisfied) {
562
+ satisfied = false;
563
+ }
564
+ }
565
+ }
566
+ for (const key of ["anyOf", "oneOf"]) {
567
+ if (schema[key]) {
568
+ let bestOptions;
569
+ for (const subSchema of schema[key]) {
570
+ const [subSatisfied, subCoerced] = this.#coerce(subSchema, coerced, options);
571
+ if (subSatisfied) {
572
+ if (!bestOptions || subCoerced === coerced) {
573
+ bestOptions = { coerced: subCoerced, satisfied: subSatisfied };
574
+ }
575
+ if (subCoerced === coerced) {
576
+ break;
577
+ }
578
+ }
579
+ }
580
+ coerced = bestOptions ? bestOptions.coerced : coerced;
581
+ satisfied = bestOptions ? bestOptions.satisfied : false;
582
+ }
583
+ }
584
+ if (typeof schema.not !== "undefined") {
585
+ const [notSatisfied] = this.#coerce(schema.not, coerced, options);
586
+ if (notSatisfied) {
587
+ satisfied = false;
588
+ }
589
+ }
590
+ return [satisfied, coerced];
591
+ }
592
+ #stringToNumber(value) {
593
+ const num = Number.parseFloat(value);
594
+ if (Number.isNaN(num) || num !== Number(value)) {
595
+ return value;
596
+ }
597
+ return num;
598
+ }
599
+ #stringToInteger(value) {
600
+ const num = Number.parseInt(value);
601
+ if (Number.isNaN(num) || num !== Number(value)) {
602
+ return value;
603
+ }
604
+ return num;
605
+ }
606
+ #stringToBoolean(value) {
607
+ const lower = value.toLowerCase();
608
+ if (lower === "false" || lower === "off") {
609
+ return false;
610
+ }
611
+ if (lower === "true" || lower === "on") {
612
+ return true;
613
+ }
614
+ return value;
615
+ }
616
+ #stringToBigInt(value) {
617
+ return guard(() => BigInt(value)) ?? value;
618
+ }
619
+ #numberToBigInt(value) {
620
+ return guard(() => BigInt(value)) ?? value;
621
+ }
622
+ #stringToDate(value) {
623
+ const date = new Date(value);
624
+ if (Number.isNaN(date.getTime()) || !FLEXIBLE_DATE_FORMAT_REGEX.test(value)) {
625
+ return value;
626
+ }
627
+ return date;
628
+ }
629
+ #stringToRegExp(value) {
630
+ const match = value.match(/^\/(.*)\/([a-z]*)$/);
631
+ if (match) {
632
+ const [, pattern, flags] = match;
633
+ return guard(() => new RegExp(pattern, flags)) ?? value;
634
+ }
635
+ return value;
636
+ }
637
+ #stringToURL(value) {
638
+ return guard(() => new URL(value)) ?? value;
639
+ }
640
+ #arrayToSet(value) {
641
+ const set = new Set(value);
642
+ if (set.size !== value.length) {
643
+ return value;
644
+ }
645
+ return set;
646
+ }
647
+ #arrayToMap(value) {
648
+ if (value.some((item) => !Array.isArray(item) || item.length !== 2)) {
649
+ return value;
650
+ }
651
+ const result = new Map(value);
652
+ if (result.size !== value.length) {
653
+ return value;
654
+ }
655
+ return result;
656
+ }
657
+ }
658
+
322
659
  function createAssertedLazyProcedure(lazied) {
323
660
  const lazyProcedure = lazyInternal(async () => {
324
661
  const { default: maybeProcedure } = await unlazy(lazied);
@@ -338,31 +675,6 @@ function call(procedure, input, ...rest) {
338
675
  return createProcedureClient(procedure, options)(input, options);
339
676
  }
340
677
 
341
- function createRouterClient(router, ...rest) {
342
- const options = resolveMaybeOptionalOptions(rest);
343
- if (isProcedure(router)) {
344
- const caller = createProcedureClient(router, options);
345
- return caller;
346
- }
347
- const procedureCaller = isLazy(router) ? createProcedureClient(createAssertedLazyProcedure(router), options) : {};
348
- const recursive = new Proxy(procedureCaller, {
349
- get(target, key) {
350
- if (typeof key !== "string") {
351
- return Reflect.get(target, key);
352
- }
353
- const next = getRouter(router, [key]);
354
- if (!next) {
355
- return Reflect.get(target, key);
356
- }
357
- return createRouterClient(next, {
358
- ...rest[0],
359
- path: [...rest[0]?.path ?? [], key]
360
- });
361
- }
362
- });
363
- return recursive;
364
- }
365
-
366
678
  function isSchemaIssue(issue) {
367
679
  if (!isTypescriptObject(issue) || typeof issue.message !== "string") {
368
680
  return false;
@@ -380,4 +692,4 @@ function isSchemaIssue(issue) {
380
692
  return true;
381
693
  }
382
694
 
383
- export { Builder, BuilderWithMiddlewares, Contract, DecoratedProcedure, Procedure, ProcedureBuilder, addMiddleware, baseApi, call, createAssertedLazyProcedure, createProcedureClient, createRouterClient, decorateMiddleware, enhanceRouter, getLazyMeta, getRouter, initialSchemas, isLazy, isProcedure, isSchemaIssue, lazyInternal, mergeMeta, parseEndpointDefinition, unlazy };
695
+ export { Builder, BuilderWithMiddlewares, Contract, DecoratedProcedure, JsonSchemaXNativeType, Procedure, ProcedureBuilder, UnauthorizedError, addMiddleware, baseApi, call, createAssertedLazyProcedure, createProcedureClient, decorateMiddleware, enhanceRouter, experimental_JsonSchemaCoercer, getLazyMeta, initialSchemas, isProcedure, isSchemaIssue, lazyInternal, mergeMeta, parseEndpointDefinition, unlazy };
@@ -1,10 +1,11 @@
1
1
  import { Contract } from '@temporary-name/server';
2
2
  import { OpenAPI, Promisable, Value, HTTPPath, HTTPMethod } from '@temporary-name/shared';
3
3
  export { OpenAPI } from '@temporary-name/shared';
4
- import { ZodToJsonSchemaConverterOptions } from '@temporary-name/json-schema';
5
- import { d as AnySchema, b as Contract$1, a9 as TraverseContractProcedureCallbackOptions, $ as ContractRouter, u as AnyRouter } from '../shared/server.DXPMDozZ.mjs';
4
+ import { Z as ZodToJsonSchemaConverterOptions } from '../shared/server.CjPiuQYH.mjs';
5
+ import { d as AnySchema, b as Contract$1, ao as TraverseContractProcedureCallbackOptions, ac as ContractRouter, ad as AnyRouter } from '../shared/server.BwcJq6aP.mjs';
6
6
  import { JSONSchema } from '@temporary-name/interop/json-schema-typed/draft-2020-12';
7
7
  export { JSONSchema, ContentEncoding as JSONSchemaContentEncoding, Format as JSONSchemaFormat, TypeName as JSONSchemaTypeName } from '@temporary-name/interop/json-schema-typed/draft-2020-12';
8
+ import '@temporary-name/server/openapi';
8
9
  import '@temporary-name/zod';
9
10
 
10
11
  type OverrideOperationValue = Partial<OpenAPI.OperationObject> | ((current: OpenAPI.OperationObject, procedure: Contract) => OpenAPI.OperationObject);
@@ -1,10 +1,11 @@
1
1
  import { Contract } from '@temporary-name/server';
2
2
  import { OpenAPI, Promisable, Value, HTTPPath, HTTPMethod } from '@temporary-name/shared';
3
3
  export { OpenAPI } from '@temporary-name/shared';
4
- import { ZodToJsonSchemaConverterOptions } from '@temporary-name/json-schema';
5
- import { d as AnySchema, b as Contract$1, a9 as TraverseContractProcedureCallbackOptions, $ as ContractRouter, u as AnyRouter } from '../shared/server.DXPMDozZ.js';
4
+ import { Z as ZodToJsonSchemaConverterOptions } from '../shared/server.CjPiuQYH.js';
5
+ import { d as AnySchema, b as Contract$1, ao as TraverseContractProcedureCallbackOptions, ac as ContractRouter, ad as AnyRouter } from '../shared/server.BwcJq6aP.js';
6
6
  import { JSONSchema } from '@temporary-name/interop/json-schema-typed/draft-2020-12';
7
7
  export { JSONSchema, ContentEncoding as JSONSchemaContentEncoding, Format as JSONSchemaFormat, TypeName as JSONSchemaTypeName } from '@temporary-name/interop/json-schema-typed/draft-2020-12';
8
+ import '@temporary-name/server/openapi';
8
9
  import '@temporary-name/zod';
9
10
 
10
11
  type OverrideOperationValue = Partial<OpenAPI.OperationObject> | ((current: OpenAPI.OperationObject, procedure: Contract) => OpenAPI.OperationObject);
@@ -1,12 +1,12 @@
1
- import { ZodToJsonSchemaConverter } from '@temporary-name/json-schema';
2
- import { isObject, stringifyJSON, findDeepMatches, clone, value, fallbackContractConfig, toHttpPath, assertNever, isORPCErrorStatus } from '@temporary-name/shared';
3
- import { j as jsonSerialize } from '../shared/server.CQIFwyhc.mjs';
4
- import '@temporary-name/standard-server';
5
- import { g as getEventIteratorSchemaDetails } from '../shared/server.YUvuxHty.mjs';
6
- import { s as standardizeHTTPPath, r as resolveContractProcedures, g as getDynamicParams } from '../shared/server.ChOv1yG3.mjs';
1
+ import { isObject, stringifyJSON, findDeepMatches, clone, value, fallbackContractConfig, toHttpPath, assertNever } from '@temporary-name/shared';
2
+ import * as z from '@temporary-name/zod';
3
+ import { s as standardizeHTTPPath, r as resolveContractProcedures, g as getDynamicParams, i as isAPIErrorStatus } from '../shared/server.DvgWQUGK.mjs';
4
+ import { Z as ZodToJsonSchemaConverter, g as getEventIteratorSchemaDetails } from '../shared/server.-tR-4rQ5.mjs';
7
5
  import { TypeName } from '@temporary-name/interop/json-schema-typed/draft-2020-12';
8
6
  export { ContentEncoding as JSONSchemaContentEncoding, Format as JSONSchemaFormat, TypeName as JSONSchemaTypeName } from '@temporary-name/interop/json-schema-typed/draft-2020-12';
9
- import '@temporary-name/zod';
7
+ import '@temporary-name/standard-server';
8
+ import '@temporary-name/server/openapi';
9
+ import 'zod/v4/core';
10
10
 
11
11
  const OPERATION_EXTENDER_SYMBOL = Symbol("ORPC_OPERATION_EXTENDER");
12
12
  function customOpenAPIOperation(o, extend) {
@@ -425,6 +425,7 @@ async function generateOpenApiSpec(router, options = {}) {
425
425
  }
426
426
  await handleRequest(doc, operationObjectRef, def, baseSchemaConvertOptions, converter);
427
427
  await handleSuccessResponse(doc, operationObjectRef, def, baseSchemaConvertOptions, converter);
428
+ await handleErrorResponse(doc, operationObjectRef, def, baseSchemaConvertOptions, converter);
428
429
  }
429
430
  if (typeof def.route.spec === "function") {
430
431
  operationObjectRef = def.route.spec(operationObjectRef);
@@ -449,19 +450,18 @@ ${e.message}`
449
450
  ${errors.join("\n\n")}`
450
451
  );
451
452
  }
452
- return jsonSerialize(doc)[0];
453
+ return doc;
453
454
  }
454
455
  async function resolveCommonSchemas(doc, commonSchemas, converter) {
455
456
  let undefinedErrorJsonSchema = {
456
457
  type: "object",
457
458
  properties: {
458
- defined: { const: false },
459
459
  code: { type: "string" },
460
460
  status: { type: "number" },
461
461
  message: { type: "string" },
462
462
  data: {}
463
463
  },
464
- required: ["defined", "code", "status", "message"]
464
+ required: ["code", "status", "message"]
465
465
  };
466
466
  const baseSchemaConvertOptions = {};
467
467
  if (commonSchemas) {
@@ -539,11 +539,9 @@ async function handleRequest(doc, ref, def, baseSchemaConvertOptions, converter)
539
539
  } else {
540
540
  const error = new OpenAPIGeneratorError("Params set via path do not match those on the route");
541
541
  if (!isObjectSchema(pathSchema)) {
542
- console.log("FOO", pathSchema);
543
542
  throw error;
544
543
  }
545
544
  if (!checkParamsSchema(pathSchema, [])) {
546
- console.log("BAR", pathSchema);
547
545
  throw error;
548
546
  }
549
547
  }
@@ -641,7 +639,7 @@ async function handleSuccessResponse(doc, ref, def, baseSchemaConvertOptions, co
641
639
  let schemaDescription;
642
640
  if (item.properties?.status !== void 0) {
643
641
  const statusSchema = resolveOpenAPIJsonSchemaRef(doc, item.properties.status);
644
- if (typeof statusSchema !== "object" || statusSchema.const === void 0 || typeof statusSchema.const !== "number" || !Number.isInteger(statusSchema.const) || isORPCErrorStatus(statusSchema.const)) {
642
+ if (typeof statusSchema !== "object" || statusSchema.const === void 0 || typeof statusSchema.const !== "number" || !Number.isInteger(statusSchema.const) || isAPIErrorStatus(statusSchema.const)) {
645
643
  throw error;
646
644
  }
647
645
  schemaStatus = statusSchema.const;
@@ -723,6 +721,59 @@ function authConfigToSecurityScheme(authConfig) {
723
721
  assertNever(authConfig, `Unsupported auth config type: ${authConfig.type}`);
724
722
  }
725
723
  }
724
+ async function handleErrorResponse(doc, ref, def, baseSchemaConvertOptions, converter) {
725
+ const errorMap = def.errorMap;
726
+ const errorResponsesByStatus = {};
727
+ for (const code in errorMap) {
728
+ const errorClass = errorMap[code];
729
+ if (!errorClass) {
730
+ continue;
731
+ }
732
+ const status = errorClass.status;
733
+ const type = errorClass.type;
734
+ const defaultMessage = errorClass.defaultMessage;
735
+ errorResponsesByStatus[status] ??= { status, errorSchemaVariants: [] };
736
+ const extraZod = z.object(errorClass.extraSchema).strict();
737
+ const [, extraSchema] = await converter(extraZod, {
738
+ ...baseSchemaConvertOptions,
739
+ strategy: "output"
740
+ });
741
+ if (!isObjectSchema(extraSchema)) {
742
+ throw new OpenAPIGeneratorError(
743
+ `Error response extra schema must be an object, but got: ${stringifyJSON(extraSchema)}`
744
+ );
745
+ }
746
+ errorResponsesByStatus[status].errorSchemaVariants.push({
747
+ type: "object",
748
+ properties: {
749
+ type: { const: type },
750
+ message: { type: "string", default: defaultMessage },
751
+ ...extraSchema.properties
752
+ },
753
+ required: ["type", "message", ...extraSchema.required ?? []]
754
+ });
755
+ }
756
+ ref.responses ??= {};
757
+ for (const statusString in errorResponsesByStatus) {
758
+ const errorResponse = errorResponsesByStatus[statusString];
759
+ if (statusString === "500") {
760
+ console.log(
761
+ errorResponse.errorSchemaVariants,
762
+ toOpenAPIContent({
763
+ oneOf: errorResponse.errorSchemaVariants
764
+ })
765
+ );
766
+ }
767
+ ref.responses[statusString] = {
768
+ description: statusString,
769
+ content: toOpenAPIContent(
770
+ errorResponse.errorSchemaVariants.length === 1 ? errorResponse.errorSchemaVariants[0] : {
771
+ oneOf: errorResponse.errorSchemaVariants
772
+ }
773
+ )
774
+ };
775
+ }
776
+ }
726
777
 
727
778
  const oo = {
728
779
  spec: customOpenAPIOperation