@modern-js/bff-runtime 1.1.0 → 1.2.1
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/CHANGELOG.md +27 -67
- package/dist/js/modern/index.js +0 -1
- package/dist/js/modern/request.js +0 -1
- package/dist/js/node/index.js +0 -9
- package/dist/js/treeshaking/index.js +0 -1
- package/dist/js/treeshaking/request.js +0 -1
- package/dist/types/index.d.ts +0 -1
- package/jest.config.js +8 -0
- package/modern.config.js +1 -14
- package/package.json +11 -7
- package/tests/match.test.ts +2 -2
- package/tests/tsconfig.json +1 -3
- package/tsconfig.json +1 -3
- package/src/compatible.ts +0 -8
- package/src/index.ts +0 -17
- package/src/match.ts +0 -146
- package/src/request.ts +0 -103
- package/src/response.ts +0 -41
package/CHANGELOG.md
CHANGED
|
@@ -1,85 +1,45 @@
|
|
|
1
1
|
# @modern-js/bff-runtime
|
|
2
2
|
|
|
3
|
-
## 1.1
|
|
4
|
-
|
|
5
|
-
### Minor Changes
|
|
6
|
-
|
|
7
|
-
- 96119db2: Relese v1.1.0
|
|
8
|
-
|
|
9
|
-
1. 全面支持 Windows 平台
|
|
10
|
-
|
|
11
|
-
ISSUE:
|
|
12
|
-
|
|
13
|
-
- [182](https://github.com/modern-js-dev/modern.js/issues/182)
|
|
14
|
-
- [236](https://github.com/modern-js-dev/modern.js/issues/236)
|
|
15
|
-
|
|
16
|
-
PR
|
|
17
|
-
|
|
18
|
-
- [219](https://github.com/modern-js-dev/modern.js/pull/219)
|
|
19
|
-
- [247](https://github.com/modern-js-dev/modern.js/pull/247)
|
|
20
|
-
- [249](https://github.com/modern-js-dev/modern.js/pull/249)
|
|
21
|
-
- [253](https://github.com/modern-js-dev/modern.js/pull/253)
|
|
22
|
-
- [268](https://github.com/modern-js-dev/modern.js/pull/268)
|
|
23
|
-
- [270](https://github.com/modern-js-dev/modern.js/pull/270)
|
|
24
|
-
- [273](https://github.com/modern-js-dev/modern.js/pull/273)
|
|
25
|
-
- [276](https://github.com/modern-js-dev/modern.js/pull/276)
|
|
26
|
-
|
|
27
|
-
2. 修复 Unbundled 模式启用问题
|
|
28
|
-
|
|
29
|
-
ISSUE
|
|
30
|
-
|
|
31
|
-
- [186](https://github.com/modern-js-dev/modern.js/issues/186)
|
|
32
|
-
- [224](https://github.com/modern-js-dev/modern.js/issues/224)
|
|
33
|
-
- [225](https://github.com/modern-js-dev/modern.js/issues/225)
|
|
34
|
-
- [238](https://github.com/modern-js-dev/modern.js/issues/238)
|
|
35
|
-
|
|
36
|
-
PR
|
|
37
|
-
|
|
38
|
-
- [226](https://github.com/modern-js-dev/modern.js/pull/226)
|
|
39
|
-
- [264](https://github.com/modern-js-dev/modern.js/pull/264)
|
|
40
|
-
- [codesmith-12](https://github.com/modern-js-dev/codesmith/pull/12)
|
|
3
|
+
## 1.2.1
|
|
41
4
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
ISSUE
|
|
45
|
-
|
|
46
|
-
- [198](https://github.com/modern-js-dev/modern.js/issues/198)
|
|
47
|
-
|
|
48
|
-
PR
|
|
49
|
-
|
|
50
|
-
- [209](https://github.com/modern-js-dev/modern.js/pull/209)
|
|
51
|
-
|
|
52
|
-
4. 修复 Storybook 使用时浏览器打开页面报错
|
|
53
|
-
|
|
54
|
-
ISSUE
|
|
55
|
-
|
|
56
|
-
- [228](https://github.com/modern-js-dev/modern.js/issues/228)
|
|
5
|
+
### Patch Changes
|
|
57
6
|
|
|
58
|
-
|
|
7
|
+
- 83166714: change .npmignore
|
|
8
|
+
- Updated dependencies [83166714]
|
|
9
|
+
- @modern-js/server-utils@1.2.1
|
|
59
10
|
|
|
60
|
-
|
|
11
|
+
## 1.2.0
|
|
61
12
|
|
|
62
|
-
|
|
13
|
+
### Minor Changes
|
|
63
14
|
|
|
64
|
-
|
|
15
|
+
- cfe11628: Make Modern.js self bootstraping
|
|
65
16
|
|
|
66
|
-
|
|
67
|
-
- [257](https://github.com/modern-js-dev/modern.js/issues/257)
|
|
17
|
+
### Patch Changes
|
|
68
18
|
|
|
69
|
-
|
|
19
|
+
- 146dcd85: modify server framework plugin hook types and hook context
|
|
20
|
+
- 146dcd85: modify server framework plugin hook types
|
|
21
|
+
- 146dcd85: fix test case in babel compiler
|
|
22
|
+
- Updated dependencies [146dcd85]
|
|
23
|
+
- Updated dependencies [cfe11628]
|
|
24
|
+
- Updated dependencies [146dcd85]
|
|
25
|
+
- Updated dependencies [146dcd85]
|
|
26
|
+
- Updated dependencies [1ebc7ee2]
|
|
27
|
+
- @modern-js/server-utils@1.2.0
|
|
70
28
|
|
|
71
|
-
|
|
72
|
-
- [271](https://github.com/modern-js-dev/modern.js/pull/271)
|
|
29
|
+
## 1.1.1
|
|
73
30
|
|
|
74
|
-
|
|
31
|
+
### Patch Changes
|
|
75
32
|
|
|
76
|
-
|
|
33
|
+
- 0fa83663: support more .env files
|
|
34
|
+
- Updated dependencies [b011e0c5]
|
|
35
|
+
- Updated dependencies [0fa83663]
|
|
36
|
+
- @modern-js/server-utils@1.1.1
|
|
77
37
|
|
|
78
|
-
|
|
38
|
+
## 1.1.0
|
|
79
39
|
|
|
80
|
-
|
|
40
|
+
### Minor Changes
|
|
81
41
|
|
|
82
|
-
|
|
42
|
+
- 96119db2: Relese v1.1.0
|
|
83
43
|
|
|
84
44
|
### Patch Changes
|
|
85
45
|
|
package/dist/js/modern/index.js
CHANGED
package/dist/js/node/index.js
CHANGED
|
@@ -4,17 +4,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
var _exportNames = {
|
|
7
|
-
hook: true,
|
|
8
7
|
match: true,
|
|
9
8
|
isHandler: true,
|
|
10
9
|
isSchemaHandler: true
|
|
11
10
|
};
|
|
12
|
-
Object.defineProperty(exports, "hook", {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: function () {
|
|
15
|
-
return _serverUtils.hook;
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
11
|
Object.defineProperty(exports, "isHandler", {
|
|
19
12
|
enumerable: true,
|
|
20
13
|
get: function () {
|
|
@@ -76,6 +69,4 @@ Object.keys(_farrowPipeline).forEach(function (key) {
|
|
|
76
69
|
});
|
|
77
70
|
});
|
|
78
71
|
|
|
79
|
-
var _serverUtils = require("@modern-js/server-utils");
|
|
80
|
-
|
|
81
72
|
var _match = require("./match");
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
export * from 'farrow-schema';
|
|
2
2
|
export * from 'farrow-api';
|
|
3
3
|
export * from 'farrow-pipeline';
|
|
4
|
-
export { hook } from '@modern-js/server-utils';
|
|
5
4
|
export { match, isHandler, isSchemaHandler } from './match';
|
|
6
5
|
export type { Handler, SchemaHandler } from './match';
|
|
7
6
|
export type { RequestSchema, TypeOfRequestSchema, InputType } from './request';
|
package/jest.config.js
ADDED
package/modern.config.js
CHANGED
|
@@ -1,15 +1,2 @@
|
|
|
1
1
|
/** @type {import('@modern-js/module-tools').UserConfig} */
|
|
2
|
-
module.exports = {
|
|
3
|
-
testing: {
|
|
4
|
-
jest: {
|
|
5
|
-
collectCoverage: true,
|
|
6
|
-
collectCoverageFrom: ['src/**/*.ts'],
|
|
7
|
-
coveragePathIgnorePatterns: ['/node_modules/'],
|
|
8
|
-
moduleFileExtensions: ['js', 'jsx', 'ts', 'tsx', 'json'],
|
|
9
|
-
testEnvironment: 'jsdom',
|
|
10
|
-
transform: {
|
|
11
|
-
'^.+\\.tsx?$': 'ts-jest',
|
|
12
|
-
},
|
|
13
|
-
},
|
|
14
|
-
},
|
|
15
|
-
};
|
|
2
|
+
module.exports = {};
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "1.1
|
|
14
|
+
"version": "1.2.1",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./dist/types/index.d.ts",
|
|
17
17
|
"main": "./dist/js/node/index.js",
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
"exports": {
|
|
21
21
|
".": {
|
|
22
22
|
"node": {
|
|
23
|
+
"jsnext:source": "./src/index.ts",
|
|
23
24
|
"import": "./dist/js/modern/index.js",
|
|
24
25
|
"require": "./dist/js/node/index.js"
|
|
25
26
|
},
|
|
@@ -28,7 +29,7 @@
|
|
|
28
29
|
},
|
|
29
30
|
"dependencies": {
|
|
30
31
|
"@babel/runtime": "^7",
|
|
31
|
-
"@modern-js/server-utils": "^1.1
|
|
32
|
+
"@modern-js/server-utils": "^1.2.1",
|
|
32
33
|
"farrow-api": "^1.10.8",
|
|
33
34
|
"farrow-http": "^1.10.8",
|
|
34
35
|
"farrow-pipeline": "^1.10.6",
|
|
@@ -41,16 +42,19 @@
|
|
|
41
42
|
"@types/react-dom": "^17",
|
|
42
43
|
"ts-jest": "^27.0.5",
|
|
43
44
|
"typescript": "^4",
|
|
44
|
-
"@
|
|
45
|
-
"
|
|
45
|
+
"@scripts/build": "0.0.0",
|
|
46
|
+
"jest": "^27",
|
|
47
|
+
"@scripts/jest-config": "0.0.0"
|
|
46
48
|
},
|
|
47
49
|
"publishConfig": {
|
|
48
50
|
"registry": "https://registry.npmjs.org/",
|
|
49
|
-
"access": "public"
|
|
51
|
+
"access": "public",
|
|
52
|
+
"types": "./dist/types/index.d.ts"
|
|
50
53
|
},
|
|
51
54
|
"scripts": {
|
|
52
55
|
"new": "modern new",
|
|
53
56
|
"build": "modern build",
|
|
54
|
-
"test": "
|
|
55
|
-
}
|
|
57
|
+
"test": "jest --passWithNoTests"
|
|
58
|
+
},
|
|
59
|
+
"readme": "\n<p align=\"center\">\n <a href=\"https://modernjs.dev\" target=\"blank\"><img src=\"https://lf3-static.bytednsdoc.com/obj/eden-cn/ylaelkeh7nuhfnuhf/modernjs-cover.png\" width=\"300\" alt=\"Modern.js Logo\" /></a>\n</p>\n<p align=\"center\">\n现代 Web 工程体系\n <br/>\n <a href=\"https://modernjs.dev\" target=\"blank\">\n modernjs.dev\n </a>\n</p>\n<p align=\"center\">\n The meta-framework suite designed from scratch for frontend-focused modern web development\n</p>\n\n# Introduction\n\n> The doc site ([modernjs.dev](https://modernjs.dev)) and articles are only available in Chinese for now, we are planning to add English versions soon.\n\n- [Modern.js: Hello, World!](https://zhuanlan.zhihu.com/p/426707646)\n\n## Getting Started\n\n- [Quick Start](https://modernjs.dev/docs/start)\n- [Guides](https://modernjs.dev/docs/guides)\n- [API References](https://modernjs.dev/docs/apis)\n\n## Contributing\n\n- [Contributing Guide](https://github.com/modern-js-dev/modern.js/blob/main/CONTRIBUTING.md)\n"
|
|
56
60
|
}
|
package/tests/match.test.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import assert from 'assert';
|
|
2
|
-
import { baseMatch } from '
|
|
3
|
-
import { match, isHandler, isSchemaHandler, Any } from '
|
|
2
|
+
import { baseMatch } from '../src/match';
|
|
3
|
+
import { match, isHandler, isSchemaHandler, Any } from '../src';
|
|
4
4
|
|
|
5
5
|
describe('match', () => {
|
|
6
6
|
it('should work well', async () => {
|
package/tests/tsconfig.json
CHANGED
package/tsconfig.json
CHANGED
package/src/compatible.ts
DELETED
package/src/index.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export * from 'farrow-schema';
|
|
2
|
-
export * from 'farrow-api';
|
|
3
|
-
export * from 'farrow-pipeline';
|
|
4
|
-
export { hook } from '@modern-js/server-utils';
|
|
5
|
-
|
|
6
|
-
export { match, isHandler, isSchemaHandler } from './match';
|
|
7
|
-
|
|
8
|
-
export type { Handler, SchemaHandler } from './match';
|
|
9
|
-
export type { RequestSchema, TypeOfRequestSchema, InputType } from './request';
|
|
10
|
-
export type {
|
|
11
|
-
HandleResult,
|
|
12
|
-
HandleSuccess,
|
|
13
|
-
InputValidationError,
|
|
14
|
-
OutputValidationError,
|
|
15
|
-
} from './response';
|
|
16
|
-
|
|
17
|
-
export type { RequestOption } from './compatible';
|
package/src/match.ts
DELETED
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
import { TypeOfRouterRequestField } from 'farrow-http/dist/router';
|
|
2
|
-
import {
|
|
3
|
-
FieldDescriptors,
|
|
4
|
-
SchemaCtorInput,
|
|
5
|
-
toSchemaCtor,
|
|
6
|
-
Struct,
|
|
7
|
-
NonStrict,
|
|
8
|
-
} from 'farrow-schema';
|
|
9
|
-
import { MaybeAsync } from 'farrow-pipeline';
|
|
10
|
-
import {
|
|
11
|
-
createSchemaValidator,
|
|
12
|
-
Validator,
|
|
13
|
-
ValidationError,
|
|
14
|
-
} from 'farrow-schema/validator';
|
|
15
|
-
|
|
16
|
-
import {
|
|
17
|
-
RequestSchema,
|
|
18
|
-
TypeOfRequestSchema,
|
|
19
|
-
PureTypeOfRequestSchema,
|
|
20
|
-
} from './request';
|
|
21
|
-
import {
|
|
22
|
-
HandleResult,
|
|
23
|
-
HandleSuccess,
|
|
24
|
-
InputValidationError,
|
|
25
|
-
OutputValidationError,
|
|
26
|
-
} from './response';
|
|
27
|
-
|
|
28
|
-
export type NormalHandler = (...args: any[]) => any;
|
|
29
|
-
export type Handler<I, O> = (input: I) => MaybeAsync<O>;
|
|
30
|
-
|
|
31
|
-
export type Schema<Req extends RequestSchema, Res extends SchemaCtorInput> = {
|
|
32
|
-
request: Req;
|
|
33
|
-
response: Res;
|
|
34
|
-
description?: string;
|
|
35
|
-
deprecated?: string;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
const getErrorMessage = (error: ValidationError) => {
|
|
39
|
-
let { message } = error;
|
|
40
|
-
|
|
41
|
-
if (Array.isArray(error.path) && error.path.length > 0) {
|
|
42
|
-
message = `path: ${JSON.stringify(error.path)}\n${message}`;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return message;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const HANDLER_WITH_SCHEMA = 'HANDLER_WITH_SCHEMA';
|
|
49
|
-
|
|
50
|
-
export type BaseSchemaHandler<
|
|
51
|
-
Req extends RequestSchema,
|
|
52
|
-
Res extends SchemaCtorInput,
|
|
53
|
-
> = ((
|
|
54
|
-
input: TypeOfRequestSchema<Req>,
|
|
55
|
-
) => Promise<HandleResult<TypeOfRouterRequestField<Res>>>) & {
|
|
56
|
-
schema: Schema<Req, Res>;
|
|
57
|
-
[HANDLER_WITH_SCHEMA]: true;
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
export type SchemaHandler<
|
|
61
|
-
Req extends RequestSchema,
|
|
62
|
-
Res extends SchemaCtorInput,
|
|
63
|
-
> = ((
|
|
64
|
-
input: TypeOfRequestSchema<Req>,
|
|
65
|
-
) => Promise<TypeOfRouterRequestField<Res>>) & {
|
|
66
|
-
schema: Schema<Req, Res>;
|
|
67
|
-
[HANDLER_WITH_SCHEMA]: true;
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
export const isSchemaHandler = (input: any): input is SchemaHandler<any, any> =>
|
|
71
|
-
input && input?.[HANDLER_WITH_SCHEMA] === true;
|
|
72
|
-
|
|
73
|
-
export const isHandler = (input: any): input is Handler<any, any> =>
|
|
74
|
-
input && typeof input === 'function';
|
|
75
|
-
|
|
76
|
-
export const baseMatch = <
|
|
77
|
-
Req extends RequestSchema,
|
|
78
|
-
Res extends SchemaCtorInput,
|
|
79
|
-
>(
|
|
80
|
-
schema: Schema<Req, Res>,
|
|
81
|
-
handler: Handler<TypeOfRequestSchema<Req>, TypeOfRouterRequestField<Res>>,
|
|
82
|
-
): BaseSchemaHandler<Req, Res> => {
|
|
83
|
-
const validateApiInput = createRequestSchemaValidator(schema.request);
|
|
84
|
-
|
|
85
|
-
const validateApiOutput = createSchemaValidator(
|
|
86
|
-
toSchemaCtor(schema.response),
|
|
87
|
-
);
|
|
88
|
-
|
|
89
|
-
const handle = async (
|
|
90
|
-
input: TypeOfRequestSchema<Req>,
|
|
91
|
-
): Promise<HandleResult<TypeOfRouterRequestField<Res>>> => {
|
|
92
|
-
const inputResult = validateApiInput(input);
|
|
93
|
-
if (inputResult.isErr) {
|
|
94
|
-
return InputValidationError(getErrorMessage(inputResult.value));
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const output = await handler(input);
|
|
98
|
-
|
|
99
|
-
const outputResult = validateApiOutput(output);
|
|
100
|
-
if (outputResult.isErr) {
|
|
101
|
-
return OutputValidationError(getErrorMessage(outputResult.value));
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
return HandleSuccess(output);
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
return Object.assign(handle, {
|
|
108
|
-
schema,
|
|
109
|
-
[HANDLER_WITH_SCHEMA]: true as const,
|
|
110
|
-
});
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
export const match: <Req extends RequestSchema, Res extends SchemaCtorInput>(
|
|
114
|
-
schema: Schema<Req, Res>,
|
|
115
|
-
handler: Handler<PureTypeOfRequestSchema<Req>, TypeOfRouterRequestField<Res>>,
|
|
116
|
-
) => SchemaHandler<Req, Res> = baseMatch as any;
|
|
117
|
-
|
|
118
|
-
const createRequestSchemaValidator = <T extends RequestSchema>(schema: T) => {
|
|
119
|
-
const descriptors: FieldDescriptors = {};
|
|
120
|
-
|
|
121
|
-
if (schema.params) {
|
|
122
|
-
descriptors.params = schema.params;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
if (schema.query) {
|
|
126
|
-
descriptors.query = schema.query;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
if (schema.data) {
|
|
130
|
-
descriptors.data = schema.data;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
if (schema.headers) {
|
|
134
|
-
descriptors.headers = schema.headers;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
if (schema.cookies) {
|
|
138
|
-
descriptors.cookies = schema.cookies;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
const RequestStruct = Struct(descriptors);
|
|
142
|
-
|
|
143
|
-
return createSchemaValidator(NonStrict(RequestStruct) as any) as Validator<
|
|
144
|
-
TypeOfRequestSchema<T>
|
|
145
|
-
>;
|
|
146
|
-
};
|
package/src/request.ts
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import { RouterSchemaDescriptor } from 'farrow-http/dist/router';
|
|
2
|
-
import { MarkReadOnlyDeep } from 'farrow-http/dist/types';
|
|
3
|
-
import {
|
|
4
|
-
TypeOfFieldDescriptor,
|
|
5
|
-
TypeOfFieldDescriptors,
|
|
6
|
-
FieldDescriptor,
|
|
7
|
-
FieldDescriptors,
|
|
8
|
-
} from 'farrow-schema';
|
|
9
|
-
|
|
10
|
-
export type RequestBaseSchema = {
|
|
11
|
-
params?: RouterSchemaDescriptor;
|
|
12
|
-
query?: RouterSchemaDescriptor;
|
|
13
|
-
headers?: RouterSchemaDescriptor;
|
|
14
|
-
cookies?: RouterSchemaDescriptor;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export type RequestDataSchema = {
|
|
18
|
-
data?: RouterSchemaDescriptor;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export type RequestBodyType = {
|
|
22
|
-
body?: string;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export type PureRequestFormDataType = {
|
|
26
|
-
formData?: Record<string, any>;
|
|
27
|
-
};
|
|
28
|
-
export type RequestFormDataType = {
|
|
29
|
-
formData?: FormData;
|
|
30
|
-
};
|
|
31
|
-
export type RequestFormUrlencodedType = {
|
|
32
|
-
// eslint-disable-next-line node/prefer-global/url-search-params,node/no-unsupported-features/node-builtins
|
|
33
|
-
formUrlencoded?: URLSearchParams | Record<string, string> | string;
|
|
34
|
-
};
|
|
35
|
-
export type PureRequestFormUrlencodedType = {
|
|
36
|
-
formUrlencoded?: Record<string, string>;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
export type RequestExtraType = RequestBodyType &
|
|
40
|
-
RequestFormDataType &
|
|
41
|
-
RequestFormUrlencodedType;
|
|
42
|
-
|
|
43
|
-
export type PureRequestExtraType = RequestBodyType &
|
|
44
|
-
PureRequestFormDataType &
|
|
45
|
-
PureRequestFormUrlencodedType;
|
|
46
|
-
|
|
47
|
-
export type RequestSchema = RequestBaseSchema & RequestDataSchema;
|
|
48
|
-
|
|
49
|
-
export type TypeOfRequestField<T> = T extends string
|
|
50
|
-
? string
|
|
51
|
-
: T extends FormData
|
|
52
|
-
? FormData
|
|
53
|
-
: T extends FieldDescriptor
|
|
54
|
-
? TypeOfFieldDescriptor<T>
|
|
55
|
-
: T extends FieldDescriptors
|
|
56
|
-
? TypeOfFieldDescriptors<T>
|
|
57
|
-
: never;
|
|
58
|
-
|
|
59
|
-
export type TypeOfRequestDataSchema<T extends RequestDataSchema> =
|
|
60
|
-
MarkReadOnlyDeep<
|
|
61
|
-
T extends { data: any }
|
|
62
|
-
? Pick<
|
|
63
|
-
{
|
|
64
|
-
[key in keyof T]: TypeOfRequestField<T[key]>;
|
|
65
|
-
},
|
|
66
|
-
'data'
|
|
67
|
-
>
|
|
68
|
-
: RequestExtraType
|
|
69
|
-
>;
|
|
70
|
-
|
|
71
|
-
export type TypeOfRequestSchema<T extends RequestSchema> = MarkReadOnlyDeep<
|
|
72
|
-
Omit<
|
|
73
|
-
{
|
|
74
|
-
[key in keyof T]: TypeOfRequestField<T[key]>;
|
|
75
|
-
},
|
|
76
|
-
'data'
|
|
77
|
-
> &
|
|
78
|
-
TypeOfRequestDataSchema<T>
|
|
79
|
-
>;
|
|
80
|
-
|
|
81
|
-
export type PureTypeOfRequestDataSchema<T extends RequestDataSchema> =
|
|
82
|
-
MarkReadOnlyDeep<
|
|
83
|
-
T extends { data: any }
|
|
84
|
-
? Pick<
|
|
85
|
-
{
|
|
86
|
-
[key in keyof T]: TypeOfRequestField<T[key]>;
|
|
87
|
-
},
|
|
88
|
-
'data'
|
|
89
|
-
>
|
|
90
|
-
: PureRequestExtraType
|
|
91
|
-
>;
|
|
92
|
-
|
|
93
|
-
export type PureTypeOfRequestSchema<T extends RequestSchema> = MarkReadOnlyDeep<
|
|
94
|
-
Omit<
|
|
95
|
-
{
|
|
96
|
-
[key in keyof T]: TypeOfRequestField<T[key]>;
|
|
97
|
-
},
|
|
98
|
-
'data'
|
|
99
|
-
> &
|
|
100
|
-
PureTypeOfRequestDataSchema<T>
|
|
101
|
-
>;
|
|
102
|
-
|
|
103
|
-
export type InputType = TypeOfRequestSchema<RequestSchema>;
|
package/src/response.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
export type HandleSuccess<T> = {
|
|
2
|
-
type: 'HandleSuccess';
|
|
3
|
-
value: T;
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
|
7
|
-
export const HandleSuccess = <T>(output: T): HandleSuccess<T> => ({
|
|
8
|
-
type: 'HandleSuccess',
|
|
9
|
-
value: output,
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
export type InputValidationError = {
|
|
13
|
-
type: 'InputValidationError';
|
|
14
|
-
message: string;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
|
18
|
-
export const InputValidationError = (
|
|
19
|
-
message: string,
|
|
20
|
-
): InputValidationError => ({
|
|
21
|
-
type: 'InputValidationError',
|
|
22
|
-
message,
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
export type OutputValidationError = {
|
|
26
|
-
type: 'OutputValidationError';
|
|
27
|
-
message: string;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
|
31
|
-
export const OutputValidationError = (
|
|
32
|
-
message: string,
|
|
33
|
-
): OutputValidationError => ({
|
|
34
|
-
type: 'OutputValidationError',
|
|
35
|
-
message,
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
export type HandleResult<T> =
|
|
39
|
-
| HandleSuccess<T>
|
|
40
|
-
| InputValidationError
|
|
41
|
-
| OutputValidationError;
|