@orpc/contract 0.31.0 → 0.32.0

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/dist/index.js CHANGED
@@ -208,6 +208,18 @@ var ContractRouterBuilder = class _ContractRouterBuilder {
208
208
 
209
209
  // src/builder.ts
210
210
  var ContractBuilder = class _ContractBuilder extends ContractProcedure {
211
+ constructor(def) {
212
+ super(def);
213
+ }
214
+ config(config) {
215
+ return new _ContractBuilder({
216
+ ...this["~orpc"],
217
+ config: {
218
+ ...this["~orpc"].config,
219
+ ...config
220
+ }
221
+ });
222
+ }
211
223
  errors(errors) {
212
224
  return new _ContractBuilder({
213
225
  ...this["~orpc"],
@@ -219,7 +231,10 @@ var ContractBuilder = class _ContractBuilder extends ContractProcedure {
219
231
  }
220
232
  route(route) {
221
233
  return new ContractProcedureBuilder({
222
- route,
234
+ route: {
235
+ ...this["~orpc"].config.initialRoute,
236
+ ...route
237
+ },
223
238
  InputSchema: void 0,
224
239
  OutputSchema: void 0,
225
240
  errorMap: this["~orpc"].errorMap
@@ -227,6 +242,7 @@ var ContractBuilder = class _ContractBuilder extends ContractProcedure {
227
242
  }
228
243
  input(schema, example) {
229
244
  return new ContractProcedureBuilderWithInput({
245
+ route: this["~orpc"].config.initialRoute,
230
246
  InputSchema: schema,
231
247
  inputExample: example,
232
248
  OutputSchema: void 0,
@@ -235,6 +251,7 @@ var ContractBuilder = class _ContractBuilder extends ContractProcedure {
235
251
  }
236
252
  output(schema, example) {
237
253
  return new ContractProcedureBuilderWithOutput({
254
+ route: this["~orpc"].config.initialRoute,
238
255
  OutputSchema: schema,
239
256
  outputExample: example,
240
257
  InputSchema: void 0,
@@ -423,20 +440,9 @@ var DEFAULT_CONFIG = {
423
440
  defaultInputStructure: "compact",
424
441
  defaultOutputStructure: "compact"
425
442
  };
426
- var GLOBAL_CONFIG_REF = { value: DEFAULT_CONFIG };
427
- function configGlobal(config) {
428
- if (config.defaultSuccessStatus !== void 0 && (config.defaultSuccessStatus < 200 || config.defaultSuccessStatus > 299)) {
429
- throw new Error("[configGlobal] The defaultSuccessStatus must be between 200 and 299");
430
- }
431
- GLOBAL_CONFIG_REF.value = config;
432
- }
433
- function fallbackToGlobalConfig(key, value) {
443
+ function fallbackContractConfig(key, value) {
434
444
  if (value === void 0) {
435
- const fallback = GLOBAL_CONFIG_REF.value[key];
436
- if (fallback === void 0) {
437
- return DEFAULT_CONFIG[key];
438
- }
439
- return fallback;
445
+ return DEFAULT_CONFIG[key];
440
446
  }
441
447
  return value;
442
448
  }
@@ -470,7 +476,8 @@ function type(...[map]) {
470
476
  var oc = new ContractBuilder({
471
477
  errorMap: {},
472
478
  InputSchema: void 0,
473
- OutputSchema: void 0
479
+ OutputSchema: void 0,
480
+ config: {}
474
481
  });
475
482
  export {
476
483
  COMMON_ORPC_ERROR_DEFS,
@@ -483,10 +490,9 @@ export {
483
490
  DecoratedContractProcedure,
484
491
  ORPCError,
485
492
  ValidationError,
486
- configGlobal,
493
+ fallbackContractConfig,
487
494
  fallbackORPCErrorMessage,
488
495
  fallbackORPCErrorStatus,
489
- fallbackToGlobalConfig,
490
496
  isContractProcedure,
491
497
  isDefinedError,
492
498
  oc,
@@ -1,16 +1,23 @@
1
1
  import type { ErrorMap, ErrorMapGuard, ErrorMapSuggestions, StrictErrorMap } from './error-map';
2
+ import type { ContractProcedureDef, RouteOptions } from './procedure';
2
3
  import type { ContractRouter } from './router';
3
4
  import type { AdaptedContractRouter } from './router-builder';
4
5
  import type { HTTPPath, Schema, SchemaInput, SchemaOutput } from './types';
5
- import { ContractProcedure, type RouteOptions } from './procedure';
6
+ import { ContractProcedure } from './procedure';
6
7
  import { ContractProcedureBuilder } from './procedure-builder';
7
8
  import { ContractProcedureBuilderWithInput } from './procedure-builder-with-input';
8
9
  import { ContractProcedureBuilderWithOutput } from './procedure-builder-with-output';
9
10
  import { ContractRouterBuilder } from './router-builder';
10
- export type ContractBuilderDef<TErrorMap extends ErrorMap> = {
11
- errorMap: TErrorMap;
12
- };
11
+ export interface ContractBuilderConfig {
12
+ initialRoute?: RouteOptions;
13
+ }
14
+ export interface ContractBuilderDef<TErrorMap extends ErrorMap> extends ContractProcedureDef<undefined, undefined, TErrorMap> {
15
+ config: ContractBuilderConfig;
16
+ }
13
17
  export declare class ContractBuilder<TErrorMap extends ErrorMap> extends ContractProcedure<undefined, undefined, TErrorMap> {
18
+ '~orpc': ContractBuilderDef<TErrorMap>;
19
+ constructor(def: ContractBuilderDef<TErrorMap>);
20
+ config(config: ContractBuilderConfig): ContractBuilder<TErrorMap>;
14
21
  errors<const U extends ErrorMap & ErrorMapGuard<TErrorMap> & ErrorMapSuggestions>(errors: U): ContractBuilder<U & TErrorMap>;
15
22
  route(route: RouteOptions): ContractProcedureBuilder<TErrorMap>;
16
23
  input<U extends Schema>(schema: U, example?: SchemaInput<U>): ContractProcedureBuilderWithInput<U, TErrorMap>;
@@ -1,36 +1,10 @@
1
1
  import type { HTTPMethod, InputStructure } from './types';
2
- export interface ORPCConfig {
3
- /**
4
- * @default 'POST'
5
- */
6
- defaultMethod?: HTTPMethod;
7
- /**
8
- *
9
- * @default 200
10
- */
11
- defaultSuccessStatus?: number;
12
- /**
13
- *
14
- * @default 'OK'
15
- */
16
- defaultSuccessDescription?: string;
17
- /**
18
- *
19
- * @default 'compact'
20
- */
21
- defaultInputStructure?: InputStructure;
22
- /**
23
- *
24
- * @default 'compact'
25
- */
26
- defaultOutputStructure?: InputStructure;
2
+ export interface ContractConfig {
3
+ defaultMethod: HTTPMethod;
4
+ defaultSuccessStatus: number;
5
+ defaultSuccessDescription: string;
6
+ defaultInputStructure: InputStructure;
7
+ defaultOutputStructure: InputStructure;
27
8
  }
28
- /**
29
- * Set the global configuration, this configuration can effect entire project
30
- */
31
- export declare function configGlobal(config: ORPCConfig): void;
32
- /**
33
- * Fallback the value to the global config if it is undefined
34
- */
35
- export declare function fallbackToGlobalConfig<T extends keyof ORPCConfig>(key: T, value: ORPCConfig[T]): Exclude<ORPCConfig[T], undefined>;
9
+ export declare function fallbackContractConfig<T extends keyof ContractConfig>(key: T, value: ContractConfig[T] | undefined): ContractConfig[T];
36
10
  //# sourceMappingURL=config.d.ts.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/contract",
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": {
@@ -30,7 +30,7 @@
30
30
  ],
31
31
  "dependencies": {
32
32
  "@standard-schema/spec": "1.0.0-beta.4",
33
- "@orpc/shared": "0.31.0"
33
+ "@orpc/shared": "0.32.0"
34
34
  },
35
35
  "devDependencies": {
36
36
  "arktype": "2.0.0-rc.26",