@orpc/contract 0.23.0 → 0.25.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
@@ -27,7 +27,10 @@ var DecoratedContractProcedure = class _DecoratedContractProcedure extends Contr
27
27
  route(route) {
28
28
  return new _DecoratedContractProcedure({
29
29
  ...this["~orpc"],
30
- route
30
+ route: {
31
+ ...this["~orpc"].route,
32
+ ...route
33
+ }
31
34
  });
32
35
  }
33
36
  prefix(prefix) {
@@ -145,6 +148,32 @@ var ContractBuilder = class {
145
148
  }
146
149
  };
147
150
 
151
+ // src/config.ts
152
+ var DEFAULT_CONFIG = {
153
+ defaultMethod: "POST",
154
+ defaultSuccessStatus: 200,
155
+ defaultSuccessDescription: "OK",
156
+ defaultInputStructure: "compact",
157
+ defaultOutputStructure: "compact"
158
+ };
159
+ var GLOBAL_CONFIG_REF = { value: DEFAULT_CONFIG };
160
+ function configGlobal(config) {
161
+ if (config.defaultSuccessStatus !== void 0 && (config.defaultSuccessStatus < 200 || config.defaultSuccessStatus > 299)) {
162
+ throw new Error("[configGlobal] The defaultSuccessStatus must be between 200 and 299");
163
+ }
164
+ GLOBAL_CONFIG_REF.value = config;
165
+ }
166
+ function fallbackToGlobalConfig(key, value) {
167
+ if (value === void 0) {
168
+ const fallback = GLOBAL_CONFIG_REF.value[key];
169
+ if (fallback === void 0) {
170
+ return DEFAULT_CONFIG[key];
171
+ }
172
+ return fallback;
173
+ }
174
+ return value;
175
+ }
176
+
148
177
  // src/index.ts
149
178
  var oc = new ContractBuilder();
150
179
  export {
@@ -152,6 +181,8 @@ export {
152
181
  ContractProcedure,
153
182
  ContractRouterBuilder,
154
183
  DecoratedContractProcedure,
184
+ configGlobal,
185
+ fallbackToGlobalConfig,
155
186
  isContractProcedure,
156
187
  oc
157
188
  };
@@ -0,0 +1,36 @@
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;
27
+ }
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>;
36
+ //# sourceMappingURL=config.d.ts.map
@@ -1,6 +1,7 @@
1
1
  /** unnoq */
2
2
  import { ContractBuilder } from './builder';
3
3
  export * from './builder';
4
+ export * from './config';
4
5
  export * from './procedure';
5
6
  export * from './procedure-decorated';
6
7
  export * from './router';
@@ -1,4 +1,4 @@
1
- import type { HTTPMethod, HTTPPath, Schema, SchemaOutput } from './types';
1
+ import type { HTTPMethod, HTTPPath, InputStructure, OutputStructure, Schema, SchemaOutput } from './types';
2
2
  export interface RouteOptions {
3
3
  method?: HTTPMethod;
4
4
  path?: HTTPPath;
@@ -12,6 +12,12 @@ export interface RouteOptions {
12
12
  * @default 200
13
13
  */
14
14
  successStatus?: number;
15
+ /**
16
+ * The description of the response when the procedure is successful.
17
+ *
18
+ * @default 'OK'
19
+ */
20
+ successDescription?: string;
15
21
  /**
16
22
  * Determines how the input should be structured based on `params`, `query`, `headers`, and `body`.
17
23
  *
@@ -33,7 +39,7 @@ export interface RouteOptions {
33
39
  *
34
40
  * @default 'compact'
35
41
  */
36
- inputStructure?: 'compact' | 'detailed';
42
+ inputStructure?: InputStructure;
37
43
  /**
38
44
  * Determines how the response should be structured based on the output.
39
45
  *
@@ -55,7 +61,7 @@ export interface RouteOptions {
55
61
  *
56
62
  * @default 'compact'
57
63
  */
58
- outputStructure?: 'compact' | 'detailed';
64
+ outputStructure?: OutputStructure;
59
65
  }
60
66
  export interface ContractProcedureDef<TInputSchema extends Schema, TOutputSchema extends Schema> {
61
67
  route?: RouteOptions;
@@ -1,6 +1,8 @@
1
1
  import type { StandardSchemaV1 } from '@standard-schema/spec';
2
2
  export type HTTPPath = `/${string}`;
3
3
  export type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
4
+ export type InputStructure = 'compact' | 'detailed';
5
+ export type OutputStructure = 'compact' | 'detailed';
4
6
  export type Schema = StandardSchemaV1 | undefined;
5
7
  export type SchemaInput<TSchema extends Schema, TFallback = unknown> = TSchema extends undefined ? TFallback : TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferInput<TSchema> : TFallback;
6
8
  export type SchemaOutput<TSchema extends Schema, TFallback = unknown> = TSchema extends undefined ? TFallback : TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TSchema> : TFallback;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/contract",
3
3
  "type": "module",
4
- "version": "0.23.0",
4
+ "version": "0.25.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.23.0"
33
+ "@orpc/shared": "0.25.0"
34
34
  },
35
35
  "devDependencies": {
36
36
  "arktype": "2.0.0-rc.26",