@orpc/server 0.31.0 → 0.32.0

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.js CHANGED
@@ -444,7 +444,10 @@ var BuilderWithErrorsMiddlewares = class _BuilderWithErrorsMiddlewares {
444
444
  return new ProcedureBuilder({
445
445
  ...this["~orpc"],
446
446
  contract: new ContractProcedure({
447
- route,
447
+ route: {
448
+ ...this["~orpc"].config.initialRoute,
449
+ ...route
450
+ },
448
451
  InputSchema: void 0,
449
452
  OutputSchema: void 0,
450
453
  errorMap: this["~orpc"].errorMap
@@ -455,6 +458,7 @@ var BuilderWithErrorsMiddlewares = class _BuilderWithErrorsMiddlewares {
455
458
  return new ProcedureBuilderWithInput({
456
459
  ...this["~orpc"],
457
460
  contract: new ContractProcedure({
461
+ route: this["~orpc"].config.initialRoute,
458
462
  OutputSchema: void 0,
459
463
  InputSchema: schema,
460
464
  inputExample: example,
@@ -466,6 +470,7 @@ var BuilderWithErrorsMiddlewares = class _BuilderWithErrorsMiddlewares {
466
470
  return new ProcedureBuilderWithOutput({
467
471
  ...this["~orpc"],
468
472
  contract: new ContractProcedure({
473
+ route: this["~orpc"].config.initialRoute,
469
474
  InputSchema: void 0,
470
475
  OutputSchema: schema,
471
476
  outputExample: example,
@@ -477,6 +482,7 @@ var BuilderWithErrorsMiddlewares = class _BuilderWithErrorsMiddlewares {
477
482
  return new DecoratedProcedure({
478
483
  ...this["~orpc"],
479
484
  contract: new ContractProcedure({
485
+ route: this["~orpc"].config.initialRoute,
480
486
  InputSchema: void 0,
481
487
  OutputSchema: void 0,
482
488
  errorMap: this["~orpc"].errorMap
@@ -504,6 +510,18 @@ var BuilderWithErrorsMiddlewares = class _BuilderWithErrorsMiddlewares {
504
510
  }
505
511
  };
506
512
 
513
+ // src/config.ts
514
+ var DEFAULT_CONFIG = {
515
+ initialInputValidationIndex: 0,
516
+ initialOutputValidationIndex: 0
517
+ };
518
+ function fallbackConfig(key, value) {
519
+ if (value === void 0) {
520
+ return DEFAULT_CONFIG[key];
521
+ }
522
+ return value;
523
+ }
524
+
507
525
  // src/builder-with-errors.ts
508
526
  var BuilderWithErrors = class _BuilderWithErrors {
509
527
  "~type" = "BuilderWithErrors";
@@ -511,6 +529,15 @@ var BuilderWithErrors = class _BuilderWithErrors {
511
529
  constructor(def) {
512
530
  this["~orpc"] = def;
513
531
  }
532
+ config(config) {
533
+ return new _BuilderWithErrors({
534
+ ...this["~orpc"],
535
+ config: {
536
+ ...this["~orpc"].config,
537
+ ...config
538
+ }
539
+ });
540
+ }
514
541
  context() {
515
542
  return this;
516
543
  }
@@ -529,8 +556,8 @@ var BuilderWithErrors = class _BuilderWithErrors {
529
556
  use(middleware) {
530
557
  return new BuilderWithErrorsMiddlewares({
531
558
  ...this["~orpc"],
532
- inputValidationIndex: 1,
533
- outputValidationIndex: 1,
559
+ inputValidationIndex: fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex) + 1,
560
+ outputValidationIndex: fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex) + 1,
534
561
  middlewares: [middleware]
535
562
  // FIXME: I believe we can remove `as any` here
536
563
  });
@@ -538,10 +565,13 @@ var BuilderWithErrors = class _BuilderWithErrors {
538
565
  route(route) {
539
566
  return new ProcedureBuilder({
540
567
  middlewares: [],
541
- inputValidationIndex: 0,
542
- outputValidationIndex: 0,
568
+ inputValidationIndex: fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex),
569
+ outputValidationIndex: fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex),
543
570
  contract: new ContractProcedure2({
544
- route,
571
+ route: {
572
+ ...this["~orpc"].config.initialRoute,
573
+ ...route
574
+ },
545
575
  InputSchema: void 0,
546
576
  OutputSchema: void 0,
547
577
  errorMap: this["~orpc"].errorMap
@@ -551,9 +581,10 @@ var BuilderWithErrors = class _BuilderWithErrors {
551
581
  input(schema, example) {
552
582
  return new ProcedureBuilderWithInput({
553
583
  middlewares: [],
554
- inputValidationIndex: 0,
555
- outputValidationIndex: 0,
584
+ inputValidationIndex: fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex),
585
+ outputValidationIndex: fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex),
556
586
  contract: new ContractProcedure2({
587
+ route: this["~orpc"].config.initialRoute,
557
588
  OutputSchema: void 0,
558
589
  InputSchema: schema,
559
590
  inputExample: example,
@@ -564,9 +595,10 @@ var BuilderWithErrors = class _BuilderWithErrors {
564
595
  output(schema, example) {
565
596
  return new ProcedureBuilderWithOutput({
566
597
  middlewares: [],
567
- inputValidationIndex: 0,
568
- outputValidationIndex: 0,
598
+ inputValidationIndex: fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex),
599
+ outputValidationIndex: fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex),
569
600
  contract: new ContractProcedure2({
601
+ route: this["~orpc"].config.initialRoute,
570
602
  InputSchema: void 0,
571
603
  OutputSchema: schema,
572
604
  outputExample: example,
@@ -577,9 +609,10 @@ var BuilderWithErrors = class _BuilderWithErrors {
577
609
  handler(handler) {
578
610
  return new DecoratedProcedure({
579
611
  middlewares: [],
580
- inputValidationIndex: 0,
581
- outputValidationIndex: 0,
612
+ inputValidationIndex: fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex),
613
+ outputValidationIndex: fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex),
582
614
  contract: new ContractProcedure2({
615
+ route: this["~orpc"].config.initialRoute,
583
616
  InputSchema: void 0,
584
617
  OutputSchema: void 0,
585
618
  errorMap: this["~orpc"].errorMap
@@ -713,7 +746,10 @@ var BuilderWithMiddlewares = class _BuilderWithMiddlewares {
713
746
  return new ProcedureBuilder({
714
747
  ...this["~orpc"],
715
748
  contract: new ContractProcedure3({
716
- route,
749
+ route: {
750
+ ...this["~orpc"].config.initialRoute,
751
+ ...route
752
+ },
717
753
  InputSchema: void 0,
718
754
  OutputSchema: void 0,
719
755
  errorMap: {}
@@ -724,6 +760,7 @@ var BuilderWithMiddlewares = class _BuilderWithMiddlewares {
724
760
  return new ProcedureBuilderWithInput({
725
761
  ...this["~orpc"],
726
762
  contract: new ContractProcedure3({
763
+ route: this["~orpc"].config.initialRoute,
727
764
  OutputSchema: void 0,
728
765
  InputSchema: schema,
729
766
  inputExample: example,
@@ -735,6 +772,7 @@ var BuilderWithMiddlewares = class _BuilderWithMiddlewares {
735
772
  return new ProcedureBuilderWithOutput({
736
773
  ...this["~orpc"],
737
774
  contract: new ContractProcedure3({
775
+ route: this["~orpc"].config.initialRoute,
738
776
  InputSchema: void 0,
739
777
  OutputSchema: schema,
740
778
  outputExample: example,
@@ -746,6 +784,7 @@ var BuilderWithMiddlewares = class _BuilderWithMiddlewares {
746
784
  return new DecoratedProcedure({
747
785
  ...this["~orpc"],
748
786
  contract: new ContractProcedure3({
787
+ route: this["~orpc"].config.initialRoute,
749
788
  InputSchema: void 0,
750
789
  OutputSchema: void 0,
751
790
  errorMap: {}
@@ -785,12 +824,21 @@ var BuilderWithMiddlewares = class _BuilderWithMiddlewares {
785
824
  };
786
825
 
787
826
  // src/builder.ts
788
- var Builder = class {
827
+ var Builder = class _Builder {
789
828
  "~type" = "Builder";
790
829
  "~orpc";
791
830
  constructor(def) {
792
831
  this["~orpc"] = def;
793
832
  }
833
+ config(config) {
834
+ return new _Builder({
835
+ ...this["~orpc"],
836
+ config: {
837
+ ...this["~orpc"].config,
838
+ ...config
839
+ }
840
+ });
841
+ }
794
842
  context() {
795
843
  return this;
796
844
  }
@@ -799,14 +847,15 @@ var Builder = class {
799
847
  }
800
848
  errors(errors) {
801
849
  return new BuilderWithErrors({
850
+ ...this["~orpc"],
802
851
  errorMap: errors
803
852
  });
804
853
  }
805
854
  use(middleware) {
806
855
  return new BuilderWithMiddlewares({
807
856
  ...this["~orpc"],
808
- inputValidationIndex: 1,
809
- outputValidationIndex: 1,
857
+ inputValidationIndex: fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex) + 1,
858
+ outputValidationIndex: fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex) + 1,
810
859
  middlewares: [middleware]
811
860
  // FIXME: I believe we can remove `as any` here
812
861
  });
@@ -814,10 +863,13 @@ var Builder = class {
814
863
  route(route) {
815
864
  return new ProcedureBuilder({
816
865
  middlewares: [],
817
- inputValidationIndex: 0,
818
- outputValidationIndex: 0,
866
+ inputValidationIndex: fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex),
867
+ outputValidationIndex: fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex),
819
868
  contract: new ContractProcedure4({
820
- route,
869
+ route: {
870
+ ...this["~orpc"].config.initialRoute,
871
+ ...route
872
+ },
821
873
  InputSchema: void 0,
822
874
  OutputSchema: void 0,
823
875
  errorMap: {}
@@ -827,9 +879,10 @@ var Builder = class {
827
879
  input(schema, example) {
828
880
  return new ProcedureBuilderWithInput({
829
881
  middlewares: [],
830
- inputValidationIndex: 0,
831
- outputValidationIndex: 0,
882
+ inputValidationIndex: fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex),
883
+ outputValidationIndex: fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex),
832
884
  contract: new ContractProcedure4({
885
+ route: this["~orpc"].config.initialRoute,
833
886
  OutputSchema: void 0,
834
887
  InputSchema: schema,
835
888
  inputExample: example,
@@ -840,9 +893,10 @@ var Builder = class {
840
893
  output(schema, example) {
841
894
  return new ProcedureBuilderWithOutput({
842
895
  middlewares: [],
843
- inputValidationIndex: 0,
844
- outputValidationIndex: 0,
896
+ inputValidationIndex: fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex),
897
+ outputValidationIndex: fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex),
845
898
  contract: new ContractProcedure4({
899
+ route: this["~orpc"].config.initialRoute,
846
900
  InputSchema: void 0,
847
901
  OutputSchema: schema,
848
902
  outputExample: example,
@@ -853,9 +907,10 @@ var Builder = class {
853
907
  handler(handler) {
854
908
  return new DecoratedProcedure({
855
909
  middlewares: [],
856
- inputValidationIndex: 0,
857
- outputValidationIndex: 0,
910
+ inputValidationIndex: fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex),
911
+ outputValidationIndex: fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex),
858
912
  contract: new ContractProcedure4({
913
+ route: this["~orpc"].config.initialRoute,
859
914
  InputSchema: void 0,
860
915
  OutputSchema: void 0,
861
916
  errorMap: {}
@@ -946,8 +1001,10 @@ function createRouterClient(router, ...rest) {
946
1001
  }
947
1002
 
948
1003
  // src/index.ts
949
- import { configGlobal, fallbackToGlobalConfig, isDefinedError, ORPCError, safe, type } from "@orpc/contract";
950
- var os = new Builder({});
1004
+ import { isDefinedError, ORPCError, safe, type } from "@orpc/contract";
1005
+ var os = new Builder({
1006
+ config: {}
1007
+ });
951
1008
  export {
952
1009
  Builder,
953
1010
  DecoratedProcedure,
@@ -959,7 +1016,6 @@ export {
959
1016
  RouterBuilder,
960
1017
  RouterImplementer,
961
1018
  call,
962
- configGlobal,
963
1019
  createChainableImplementer,
964
1020
  createORPCErrorConstructorMap,
965
1021
  createProcedureClient,
@@ -967,7 +1023,7 @@ export {
967
1023
  decorateLazy,
968
1024
  decorateMiddleware,
969
1025
  deepSetLazyRouterPrefix,
970
- fallbackToGlobalConfig,
1026
+ fallbackConfig,
971
1027
  flatLazy,
972
1028
  getLazyRouterPrefix,
973
1029
  getRouterChild,
@@ -1,4 +1,4 @@
1
- import type { ContractRouter, ErrorMap, ErrorMapGuard, ErrorMapSuggestions, HTTPPath, RouteOptions, Schema, SchemaInput, SchemaOutput, StrictErrorMap } from '@orpc/contract';
1
+ import type { ContractBuilderConfig, ContractRouter, ErrorMap, ErrorMapGuard, ErrorMapSuggestions, HTTPPath, RouteOptions, Schema, SchemaInput, SchemaOutput, StrictErrorMap } from '@orpc/contract';
2
2
  import type { ContextGuard } from './context';
3
3
  import type { ORPCErrorConstructorMap } from './error';
4
4
  import type { FlattenLazy } from './lazy';
@@ -20,6 +20,7 @@ export interface BuilderWithErrorsMiddlewaresDef<TContext extends Context, TExtr
20
20
  middlewares: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, unknown, any, ORPCErrorConstructorMap<TErrorMap>>[];
21
21
  inputValidationIndex: number;
22
22
  outputValidationIndex: number;
23
+ config: ContractBuilderConfig;
23
24
  }
24
25
  /**
25
26
  * `BuilderWithErrorsMiddlewares` is a combination of `BuilderWithErrorsMiddlewares` and `BuilderWithErrors`.
@@ -1,4 +1,5 @@
1
- import type { ContractRouter, ErrorMap, ErrorMapGuard, ErrorMapSuggestions, HTTPPath, RouteOptions, Schema, SchemaInput, SchemaOutput, StrictErrorMap } from '@orpc/contract';
1
+ import type { ContractBuilderConfig, ContractRouter, ErrorMap, ErrorMapGuard, ErrorMapSuggestions, HTTPPath, RouteOptions, Schema, SchemaInput, SchemaOutput, StrictErrorMap } from '@orpc/contract';
2
+ import type { BuilderConfig } from './builder';
2
3
  import type { ContextGuard } from './context';
3
4
  import type { ORPCErrorConstructorMap } from './error';
4
5
  import type { FlattenLazy } from './lazy';
@@ -19,6 +20,7 @@ export interface BuilderWithErrorsDef<TContext extends Context, TErrorMap extend
19
20
  context: TContext;
20
21
  };
21
22
  errorMap: TErrorMap;
23
+ config: BuilderConfig;
22
24
  }
23
25
  /**
24
26
  * `BuilderWithErrors` is a branch of `Builder` which it has error map.
@@ -31,6 +33,7 @@ export declare class BuilderWithErrors<TContext extends Context, TErrorMap exten
31
33
  '~type': "BuilderWithErrors";
32
34
  '~orpc': BuilderWithErrorsDef<TContext, TErrorMap>;
33
35
  constructor(def: BuilderWithErrorsDef<TContext, TErrorMap>);
36
+ config(config: ContractBuilderConfig): BuilderWithErrors<TContext, TErrorMap>;
34
37
  context<UContext extends Context = TContext>(): BuilderWithErrors<UContext, TErrorMap>;
35
38
  errors<U extends ErrorMap & ErrorMapGuard<TErrorMap> & ErrorMapSuggestions>(errors: U): BuilderWithErrors<TContext, TErrorMap & U>;
36
39
  middleware<UExtraContext extends Context & ContextGuard<TContext>, TInput, TOutput = any>(middleware: Middleware<TContext, UExtraContext, TInput, TOutput, ORPCErrorConstructorMap<TErrorMap>>): DecoratedMiddleware<TContext, UExtraContext, TInput, TOutput, ORPCErrorConstructorMap<TErrorMap>>;
@@ -1,4 +1,4 @@
1
- import type { ContractRouter, ErrorMap, ErrorMapSuggestions, HTTPPath, RouteOptions, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
1
+ import type { ContractBuilderConfig, ContractRouter, ErrorMap, ErrorMapSuggestions, HTTPPath, RouteOptions, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
2
2
  import type { ContextGuard } from './context';
3
3
  import type { FlattenLazy } from './lazy';
4
4
  import type { Middleware } from './middleware';
@@ -22,6 +22,7 @@ import { RouterBuilder } from './router-builder';
22
22
  *
23
23
  */
24
24
  export interface BuilderWithMiddlewaresDef<TContext extends Context, TExtraContext extends Context> {
25
+ config: ContractBuilderConfig;
25
26
  middlewares: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, unknown, any, Record<never, never>>[];
26
27
  inputValidationIndex: number;
27
28
  outputValidationIndex: number;
@@ -1,4 +1,4 @@
1
- import type { ContractRouter, ErrorMap, ErrorMapSuggestions, HTTPPath, RouteOptions, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
1
+ import type { ContractBuilderConfig, ContractRouter, ErrorMap, ErrorMapSuggestions, HTTPPath, RouteOptions, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
2
2
  import type { ContextGuard } from './context';
3
3
  import type { FlattenLazy } from './lazy';
4
4
  import type { Middleware } from './middleware';
@@ -15,15 +15,21 @@ import { ProcedureBuilderWithInput } from './procedure-builder-with-input';
15
15
  import { ProcedureBuilderWithOutput } from './procedure-builder-with-output';
16
16
  import { DecoratedProcedure } from './procedure-decorated';
17
17
  import { RouterBuilder } from './router-builder';
18
+ export interface BuilderConfig extends ContractBuilderConfig {
19
+ initialInputValidationIndex?: number;
20
+ initialOutputValidationIndex?: number;
21
+ }
18
22
  export interface BuilderDef<TContext extends Context> {
19
23
  types?: {
20
24
  context: TContext;
21
25
  };
26
+ config: BuilderConfig;
22
27
  }
23
28
  export declare class Builder<TContext extends Context> {
24
29
  '~type': "Builder";
25
30
  '~orpc': BuilderDef<TContext>;
26
31
  constructor(def: BuilderDef<TContext>);
32
+ config(config: ContractBuilderConfig): Builder<TContext>;
27
33
  context<UContext extends Context = TContext>(): Builder<UContext>;
28
34
  middleware<UExtraContext extends Context & ContextGuard<TContext>, TInput, TOutput = any>(middleware: Middleware<TContext, UExtraContext, TInput, TOutput, Record<never, never>>): DecoratedMiddleware<TContext, UExtraContext, TInput, TOutput, Record<never, never>>;
29
35
  errors<U extends ErrorMap & ErrorMapSuggestions>(errors: U): BuilderWithErrors<TContext, U>;
@@ -0,0 +1,6 @@
1
+ export interface Config {
2
+ initialInputValidationIndex: number;
3
+ initialOutputValidationIndex: number;
4
+ }
5
+ export declare function fallbackConfig<T extends keyof Config>(key: T, value?: Config[T]): Config[T];
6
+ //# sourceMappingURL=config.d.ts.map
@@ -1,6 +1,7 @@
1
1
  import type { WELL_CONTEXT } from './types';
2
2
  import { Builder } from './builder';
3
3
  export * from './builder';
4
+ export * from './config';
4
5
  export * from './error';
5
6
  export * from './hidden';
6
7
  export * from './implementer-chainable';
@@ -20,6 +21,6 @@ export * from './router-client';
20
21
  export * from './router-implementer';
21
22
  export * from './types';
22
23
  export * from './utils';
23
- export { configGlobal, fallbackToGlobalConfig, isDefinedError, ORPCError, safe, type } from '@orpc/contract';
24
+ export { isDefinedError, ORPCError, safe, type } from '@orpc/contract';
24
25
  export declare const os: Builder<WELL_CONTEXT>;
25
26
  //# sourceMappingURL=index.d.ts.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/server",
3
3
  "type": "module",
4
- "version": "0.31.0",
4
+ "version": "0.32.0",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -53,8 +53,8 @@
53
53
  "next": ">=14.0.0"
54
54
  },
55
55
  "dependencies": {
56
- "@orpc/contract": "0.31.0",
57
- "@orpc/shared": "0.31.0"
56
+ "@orpc/contract": "0.32.0",
57
+ "@orpc/shared": "0.32.0"
58
58
  },
59
59
  "scripts": {
60
60
  "build": "tsup --onSuccess='tsc -b --noCheck'",