@orpc/contract 0.0.0-next.5d3da98 → 0.0.0-next.6083cd9
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 +30 -0
- package/dist/src/config.d.ts +31 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/procedure.d.ts +51 -1
- package/dist/src/types.d.ts +2 -0
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -3,6 +3,9 @@ var ContractProcedure = class {
|
|
|
3
3
|
"~type" = "ContractProcedure";
|
|
4
4
|
"~orpc";
|
|
5
5
|
constructor(def) {
|
|
6
|
+
if (def.route?.successStatus && (def.route.successStatus < 200 || def.route?.successStatus > 299)) {
|
|
7
|
+
throw new Error("[ContractProcedure] The successStatus must be between 200 and 299");
|
|
8
|
+
}
|
|
6
9
|
this["~orpc"] = def;
|
|
7
10
|
}
|
|
8
11
|
};
|
|
@@ -142,6 +145,31 @@ var ContractBuilder = class {
|
|
|
142
145
|
}
|
|
143
146
|
};
|
|
144
147
|
|
|
148
|
+
// src/config.ts
|
|
149
|
+
var DEFAULT_CONFIG = {
|
|
150
|
+
defaultMethod: "POST",
|
|
151
|
+
defaultSuccessStatus: 200,
|
|
152
|
+
defaultInputStructure: "compact",
|
|
153
|
+
defaultOutputStructure: "compact"
|
|
154
|
+
};
|
|
155
|
+
var GLOBAL_CONFIG_REF = { value: DEFAULT_CONFIG };
|
|
156
|
+
function configGlobal(config) {
|
|
157
|
+
if (config.defaultSuccessStatus !== void 0 && (config.defaultSuccessStatus < 200 || config.defaultSuccessStatus > 299)) {
|
|
158
|
+
throw new Error("[configGlobal] The defaultSuccessStatus must be between 200 and 299");
|
|
159
|
+
}
|
|
160
|
+
GLOBAL_CONFIG_REF.value = config;
|
|
161
|
+
}
|
|
162
|
+
function fallbackToGlobalConfig(key, value) {
|
|
163
|
+
if (value === void 0) {
|
|
164
|
+
const fallback = GLOBAL_CONFIG_REF.value[key];
|
|
165
|
+
if (fallback === void 0) {
|
|
166
|
+
return DEFAULT_CONFIG[key];
|
|
167
|
+
}
|
|
168
|
+
return fallback;
|
|
169
|
+
}
|
|
170
|
+
return value;
|
|
171
|
+
}
|
|
172
|
+
|
|
145
173
|
// src/index.ts
|
|
146
174
|
var oc = new ContractBuilder();
|
|
147
175
|
export {
|
|
@@ -149,6 +177,8 @@ export {
|
|
|
149
177
|
ContractProcedure,
|
|
150
178
|
ContractRouterBuilder,
|
|
151
179
|
DecoratedContractProcedure,
|
|
180
|
+
configGlobal,
|
|
181
|
+
fallbackToGlobalConfig,
|
|
152
182
|
isContractProcedure,
|
|
153
183
|
oc
|
|
154
184
|
};
|
|
@@ -0,0 +1,31 @@
|
|
|
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 'compact'
|
|
15
|
+
*/
|
|
16
|
+
defaultInputStructure?: InputStructure;
|
|
17
|
+
/**
|
|
18
|
+
*
|
|
19
|
+
* @default 'compact'
|
|
20
|
+
*/
|
|
21
|
+
defaultOutputStructure?: InputStructure;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Set the global configuration, this configuration can effect entire project
|
|
25
|
+
*/
|
|
26
|
+
export declare function configGlobal(config: ORPCConfig): void;
|
|
27
|
+
/**
|
|
28
|
+
* Fallback the value to the global config if it is undefined
|
|
29
|
+
*/
|
|
30
|
+
export declare function fallbackToGlobalConfig<T extends keyof ORPCConfig>(key: T, value: ORPCConfig[T]): Exclude<ORPCConfig[T], undefined>;
|
|
31
|
+
//# sourceMappingURL=config.d.ts.map
|
package/dist/src/index.d.ts
CHANGED
package/dist/src/procedure.d.ts
CHANGED
|
@@ -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;
|
|
@@ -6,6 +6,56 @@ export interface RouteOptions {
|
|
|
6
6
|
description?: string;
|
|
7
7
|
deprecated?: boolean;
|
|
8
8
|
tags?: readonly string[];
|
|
9
|
+
/**
|
|
10
|
+
* The status code of the response when the procedure is successful.
|
|
11
|
+
*
|
|
12
|
+
* @default 200
|
|
13
|
+
*/
|
|
14
|
+
successStatus?: number;
|
|
15
|
+
/**
|
|
16
|
+
* Determines how the input should be structured based on `params`, `query`, `headers`, and `body`.
|
|
17
|
+
*
|
|
18
|
+
* @option 'compact'
|
|
19
|
+
* Combines `params` and either `query` or `body` (depending on the HTTP method) into a single object.
|
|
20
|
+
*
|
|
21
|
+
* @option 'detailed'
|
|
22
|
+
* Keeps each part of the request (`params`, `query`, `headers`, and `body`) as separate fields in the input object.
|
|
23
|
+
*
|
|
24
|
+
* Example:
|
|
25
|
+
* ```ts
|
|
26
|
+
* const input = {
|
|
27
|
+
* params: { id: 1 },
|
|
28
|
+
* query: { search: 'hello' },
|
|
29
|
+
* headers: { 'Content-Type': 'application/json' },
|
|
30
|
+
* body: { name: 'John' },
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @default 'compact'
|
|
35
|
+
*/
|
|
36
|
+
inputStructure?: InputStructure;
|
|
37
|
+
/**
|
|
38
|
+
* Determines how the response should be structured based on the output.
|
|
39
|
+
*
|
|
40
|
+
* @option 'compact'
|
|
41
|
+
* Includes only the body data, encoded directly in the response.
|
|
42
|
+
*
|
|
43
|
+
* @option 'detailed'
|
|
44
|
+
* Separates the output into `headers` and `body` fields.
|
|
45
|
+
* - `headers`: Custom headers to merge with the response headers.
|
|
46
|
+
* - `body`: The response data.
|
|
47
|
+
*
|
|
48
|
+
* Example:
|
|
49
|
+
* ```ts
|
|
50
|
+
* const output = {
|
|
51
|
+
* headers: { 'x-custom-header': 'value' },
|
|
52
|
+
* body: { message: 'Hello, world!' },
|
|
53
|
+
* };
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* @default 'compact'
|
|
57
|
+
*/
|
|
58
|
+
outputStructure?: OutputStructure;
|
|
9
59
|
}
|
|
10
60
|
export interface ContractProcedureDef<TInputSchema extends Schema, TOutputSchema extends Schema> {
|
|
11
61
|
route?: RouteOptions;
|
package/dist/src/types.d.ts
CHANGED
|
@@ -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.0.0-next.
|
|
4
|
+
"version": "0.0.0-next.6083cd9",
|
|
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.0.0-next.
|
|
33
|
+
"@orpc/shared": "0.0.0-next.6083cd9"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"arktype": "2.0.0-rc.26",
|