@orpc/contract 0.0.0-next.3b1cf14 → 0.0.0-next.3f6c426
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 +27 -0
- package/dist/src/config.d.ts +31 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/procedure.d.ts +3 -3
- package/dist/src/types.d.ts +2 -0
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -145,6 +145,31 @@ var ContractBuilder = class {
|
|
|
145
145
|
}
|
|
146
146
|
};
|
|
147
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
|
+
|
|
148
173
|
// src/index.ts
|
|
149
174
|
var oc = new ContractBuilder();
|
|
150
175
|
export {
|
|
@@ -152,6 +177,8 @@ export {
|
|
|
152
177
|
ContractProcedure,
|
|
153
178
|
ContractRouterBuilder,
|
|
154
179
|
DecoratedContractProcedure,
|
|
180
|
+
configGlobal,
|
|
181
|
+
fallbackToGlobalConfig,
|
|
155
182
|
isContractProcedure,
|
|
156
183
|
oc
|
|
157
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;
|
|
@@ -33,7 +33,7 @@ export interface RouteOptions {
|
|
|
33
33
|
*
|
|
34
34
|
* @default 'compact'
|
|
35
35
|
*/
|
|
36
|
-
inputStructure?:
|
|
36
|
+
inputStructure?: InputStructure;
|
|
37
37
|
/**
|
|
38
38
|
* Determines how the response should be structured based on the output.
|
|
39
39
|
*
|
|
@@ -55,7 +55,7 @@ export interface RouteOptions {
|
|
|
55
55
|
*
|
|
56
56
|
* @default 'compact'
|
|
57
57
|
*/
|
|
58
|
-
outputStructure?:
|
|
58
|
+
outputStructure?: OutputStructure;
|
|
59
59
|
}
|
|
60
60
|
export interface ContractProcedureDef<TInputSchema extends Schema, TOutputSchema extends Schema> {
|
|
61
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.3f6c426",
|
|
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.3f6c426"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"arktype": "2.0.0-rc.26",
|