@modern-js/bff-core 3.11.0 → 3.11.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/dist/cjs/errors/http.js +3 -3
- package/dist/cjs/operators/http.js +4 -1
- package/dist/cjs/operators/standardSchema.js +18 -0
- package/dist/cjs/router/index.js +2 -2
- package/dist/cjs/types.js +6 -7
- package/dist/esm/operators/http.mjs +4 -1
- package/dist/esm/operators/standardSchema.mjs +0 -0
- package/dist/esm-node/operators/http.mjs +4 -1
- package/dist/esm-node/operators/standardSchema.mjs +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/operators/http.d.ts +16 -16
- package/dist/types/operators/standardSchema.d.ts +52 -0
- package/package.json +5 -5
package/dist/cjs/errors/http.js
CHANGED
|
@@ -39,9 +39,9 @@ class ValidationError extends HttpError {
|
|
|
39
39
|
this.code = 'VALIDATION_ERROR';
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
43
|
-
HttpError:
|
|
44
|
-
ValidationError:
|
|
42
|
+
__webpack_require__.d(__webpack_exports__, {}, {
|
|
43
|
+
HttpError: HttpError,
|
|
44
|
+
ValidationError: ValidationError
|
|
45
45
|
});
|
|
46
46
|
exports.HttpError = __webpack_exports__.HttpError;
|
|
47
47
|
exports.ValidationError = __webpack_exports__.ValidationError;
|
|
@@ -50,12 +50,15 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
50
50
|
const http_js_namespaceObject = require("../errors/http.js");
|
|
51
51
|
const external_types_js_namespaceObject = require("../types.js");
|
|
52
52
|
const validateInput = async (schema, input)=>{
|
|
53
|
-
try {
|
|
53
|
+
if ('function' == typeof schema.parseAsync) try {
|
|
54
54
|
return await schema.parseAsync(input);
|
|
55
55
|
} catch (error) {
|
|
56
56
|
if ('name' in error && 'ZodError' === error.name) throw new http_js_namespaceObject.ValidationError(400, error.message);
|
|
57
57
|
throw error;
|
|
58
58
|
}
|
|
59
|
+
const result = await schema['~standard'].validate(input);
|
|
60
|
+
if (result.issues) throw new http_js_namespaceObject.ValidationError(400, JSON.stringify(result.issues, null, 2));
|
|
61
|
+
return result.value;
|
|
59
62
|
};
|
|
60
63
|
const createHttpOperator = (method)=>(urlPath)=>({
|
|
61
64
|
name: method,
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.r = (exports1)=>{
|
|
5
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
6
|
+
value: 'Module'
|
|
7
|
+
});
|
|
8
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
9
|
+
value: true
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
})();
|
|
13
|
+
var __webpack_exports__ = {};
|
|
14
|
+
__webpack_require__.r(__webpack_exports__);
|
|
15
|
+
for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
16
|
+
Object.defineProperty(exports, '__esModule', {
|
|
17
|
+
value: true
|
|
18
|
+
});
|
package/dist/cjs/router/index.js
CHANGED
|
@@ -277,8 +277,8 @@ var __webpack_exports__ = {};
|
|
|
277
277
|
(0, _utils__rspack_import_4.debug)("apiDir:", this.apiDir, "lambdaDir:", this.lambdaDir);
|
|
278
278
|
}
|
|
279
279
|
}
|
|
280
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
281
|
-
ApiRouter:
|
|
280
|
+
__webpack_require__.d(__webpack_exports__, {}, {
|
|
281
|
+
ApiRouter: ApiRouter
|
|
282
282
|
});
|
|
283
283
|
})();
|
|
284
284
|
exports.ApiRouter = __webpack_exports__.ApiRouter;
|
package/dist/cjs/types.js
CHANGED
|
@@ -65,13 +65,12 @@ var HttpMethod = /*#__PURE__*/ function(HttpMethod) {
|
|
|
65
65
|
return HttpMethod;
|
|
66
66
|
}({});
|
|
67
67
|
const httpMethods = Object.values(HttpMethod);
|
|
68
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
69
|
-
HttpMetadata:
|
|
70
|
-
HttpMethod:
|
|
71
|
-
OperatorType:
|
|
72
|
-
ResponseMetaType:
|
|
73
|
-
TriggerType:
|
|
74
|
-
}, {
|
|
68
|
+
__webpack_require__.d(__webpack_exports__, {}, {
|
|
69
|
+
HttpMetadata: HttpMetadata,
|
|
70
|
+
HttpMethod: HttpMethod,
|
|
71
|
+
OperatorType: OperatorType,
|
|
72
|
+
ResponseMetaType: ResponseMetaType,
|
|
73
|
+
TriggerType: TriggerType,
|
|
75
74
|
httpMethods: httpMethods
|
|
76
75
|
});
|
|
77
76
|
exports.HttpMetadata = __webpack_exports__.HttpMetadata;
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { ValidationError } from "../errors/http.mjs";
|
|
2
2
|
import { HttpMetadata, HttpMethod, OperatorType, ResponseMetaType, TriggerType } from "../types.mjs";
|
|
3
3
|
const validateInput = async (schema, input)=>{
|
|
4
|
-
try {
|
|
4
|
+
if ('function' == typeof schema.parseAsync) try {
|
|
5
5
|
return await schema.parseAsync(input);
|
|
6
6
|
} catch (error) {
|
|
7
7
|
if ('name' in error && 'ZodError' === error.name) throw new ValidationError(400, error.message);
|
|
8
8
|
throw error;
|
|
9
9
|
}
|
|
10
|
+
const result = await schema['~standard'].validate(input);
|
|
11
|
+
if (result.issues) throw new ValidationError(400, JSON.stringify(result.issues, null, 2));
|
|
12
|
+
return result.value;
|
|
10
13
|
};
|
|
11
14
|
const createHttpOperator = (method)=>(urlPath)=>({
|
|
12
15
|
name: method,
|
|
File without changes
|
|
@@ -2,12 +2,15 @@ import "node:module";
|
|
|
2
2
|
import { ValidationError } from "../errors/http.mjs";
|
|
3
3
|
import { HttpMetadata, HttpMethod, OperatorType, ResponseMetaType, TriggerType } from "../types.mjs";
|
|
4
4
|
const validateInput = async (schema, input)=>{
|
|
5
|
-
try {
|
|
5
|
+
if ('function' == typeof schema.parseAsync) try {
|
|
6
6
|
return await schema.parseAsync(input);
|
|
7
7
|
} catch (error) {
|
|
8
8
|
if ('name' in error && 'ZodError' === error.name) throw new ValidationError(400, error.message);
|
|
9
9
|
throw error;
|
|
10
10
|
}
|
|
11
|
+
const result = await schema['~standard'].validate(input);
|
|
12
|
+
if (result.issues) throw new ValidationError(400, JSON.stringify(result.issues, null, 2));
|
|
13
|
+
return result.value;
|
|
11
14
|
};
|
|
12
15
|
const createHttpOperator = (method)=>(urlPath)=>({
|
|
13
16
|
name: method,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "node:module";
|
package/dist/types/index.d.ts
CHANGED
|
@@ -4,5 +4,6 @@ export * from './router/index.js';
|
|
|
4
4
|
export * from './types.js';
|
|
5
5
|
export * from './client/index.js';
|
|
6
6
|
export * from './operators/http.js';
|
|
7
|
+
export type * from './operators/standardSchema.js';
|
|
7
8
|
export { getRelativeRuntimePath, HANDLER_WITH_META, isWithMetaHandler, INPUT_PARAMS_DECIDER, isInputParamsDeciderHandler, createStorage, registerPaths, } from './utils/index.js';
|
|
8
9
|
export type * from './compatible.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { z } from 'zod';
|
|
2
1
|
import { HttpMethod, type Operator, ResponseMetaType } from '../types.js';
|
|
2
|
+
import type { InferSchemaInput, InferSchemaOutput, ValidationSchema } from './standardSchema.js';
|
|
3
3
|
export interface ResponseMeta {
|
|
4
4
|
type: ResponseMetaType;
|
|
5
5
|
value: unknown;
|
|
@@ -14,31 +14,31 @@ export declare const Trace: (urlPath: string) => Operator<void>;
|
|
|
14
14
|
export declare const Patch: (urlPath: string) => Operator<void>;
|
|
15
15
|
export declare const Options: (urlPath: string) => Operator<void>;
|
|
16
16
|
export declare const Head: (urlPath: string) => Operator<void>;
|
|
17
|
-
export declare const Data: <Schema extends
|
|
18
|
-
data:
|
|
17
|
+
export declare const Data: <Schema extends ValidationSchema>(schema: Schema) => Operator<{
|
|
18
|
+
data: InferSchemaInput<Schema>;
|
|
19
19
|
}, {
|
|
20
|
-
data:
|
|
20
|
+
data: InferSchemaOutput<Schema>;
|
|
21
21
|
}>;
|
|
22
|
-
export declare const Query: <Schema extends
|
|
23
|
-
query:
|
|
22
|
+
export declare const Query: <Schema extends ValidationSchema>(schema: Schema) => Operator<{
|
|
23
|
+
query: InferSchemaInput<Schema>;
|
|
24
24
|
}, {
|
|
25
|
-
query:
|
|
25
|
+
query: InferSchemaOutput<Schema>;
|
|
26
26
|
}>;
|
|
27
|
-
export declare const Params: <Schema extends
|
|
28
|
-
params:
|
|
27
|
+
export declare const Params: <Schema extends ValidationSchema>(schema: Schema) => Operator<{
|
|
28
|
+
params: InferSchemaInput<Schema>;
|
|
29
29
|
}, {
|
|
30
|
-
params:
|
|
30
|
+
params: InferSchemaOutput<Schema>;
|
|
31
31
|
}>;
|
|
32
|
-
export declare const Headers: <Schema extends
|
|
33
|
-
headers:
|
|
32
|
+
export declare const Headers: <Schema extends ValidationSchema>(schema: Schema) => Operator<{
|
|
33
|
+
headers: InferSchemaInput<Schema>;
|
|
34
34
|
}, {
|
|
35
|
-
headers:
|
|
35
|
+
headers: InferSchemaOutput<Schema>;
|
|
36
36
|
}>;
|
|
37
37
|
export declare const HttpCode: (statusCode: number) => Operator<void>;
|
|
38
38
|
export declare const SetHeaders: (headers: Record<string, string>) => Operator<void>;
|
|
39
39
|
export declare const Redirect: (url: string) => Operator<void>;
|
|
40
|
-
export declare const Upload: <Schema extends
|
|
41
|
-
files:
|
|
40
|
+
export declare const Upload: <Schema extends ValidationSchema>(urlPath: string, schema?: Schema) => Operator<{
|
|
41
|
+
files: InferSchemaInput<Schema>;
|
|
42
42
|
}, {
|
|
43
|
-
formData:
|
|
43
|
+
formData: InferSchemaOutput<Schema>;
|
|
44
44
|
}>;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Standard Schema interface (https://standardschema.dev), implemented by
|
|
3
|
+
* Zod 3.24+ and Zod 4.
|
|
4
|
+
*
|
|
5
|
+
* Operator types are written against this interface instead of `zod` so they
|
|
6
|
+
* don't depend on which `zod` copy the package manager links next to
|
|
7
|
+
* bff-core. A Zod 3 schema must type-check even when bff-core resolves Zod 4,
|
|
8
|
+
* and the other way round.
|
|
9
|
+
*/
|
|
10
|
+
export interface StandardSchemaV1<Input = unknown, Output = Input> {
|
|
11
|
+
readonly '~standard': StandardSchemaProps<Input, Output>;
|
|
12
|
+
}
|
|
13
|
+
export interface StandardSchemaProps<Input = unknown, Output = Input> {
|
|
14
|
+
readonly version: 1;
|
|
15
|
+
readonly vendor: string;
|
|
16
|
+
readonly validate: (value: unknown) => StandardSchemaResult<Output> | Promise<StandardSchemaResult<Output>>;
|
|
17
|
+
readonly types?: StandardSchemaTypes<Input, Output> | undefined;
|
|
18
|
+
}
|
|
19
|
+
export type StandardSchemaResult<Output> = StandardSchemaSuccessResult<Output> | StandardSchemaFailureResult;
|
|
20
|
+
export interface StandardSchemaSuccessResult<Output> {
|
|
21
|
+
readonly value: Output;
|
|
22
|
+
readonly issues?: undefined;
|
|
23
|
+
}
|
|
24
|
+
export interface StandardSchemaFailureResult {
|
|
25
|
+
readonly issues: ReadonlyArray<StandardSchemaIssue>;
|
|
26
|
+
}
|
|
27
|
+
export interface StandardSchemaIssue {
|
|
28
|
+
readonly message: string;
|
|
29
|
+
readonly path?: ReadonlyArray<PropertyKey | {
|
|
30
|
+
readonly key: PropertyKey;
|
|
31
|
+
}> | undefined;
|
|
32
|
+
}
|
|
33
|
+
export interface StandardSchemaTypes<Input = unknown, Output = Input> {
|
|
34
|
+
readonly input: Input;
|
|
35
|
+
readonly output: Output;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Zod schemas created before Standard Schema support (Zod < 3.24) only expose
|
|
39
|
+
* `_input`, `_output` and `parseAsync`.
|
|
40
|
+
*/
|
|
41
|
+
export interface ZodLikeSchema<Input = unknown, Output = Input> {
|
|
42
|
+
readonly _input: Input;
|
|
43
|
+
readonly _output: Output;
|
|
44
|
+
parseAsync(data: unknown): Promise<Output>;
|
|
45
|
+
}
|
|
46
|
+
export type ValidationSchema = StandardSchemaV1 | ZodLikeSchema;
|
|
47
|
+
export type InferSchemaInput<Schema extends ValidationSchema> = Schema extends StandardSchemaV1 ? NonNullable<Schema['~standard']['types']>['input'] : Schema extends {
|
|
48
|
+
readonly _input: infer Input;
|
|
49
|
+
} ? Input : unknown;
|
|
50
|
+
export type InferSchemaOutput<Schema extends ValidationSchema> = Schema extends StandardSchemaV1 ? NonNullable<Schema['~standard']['types']>['output'] : Schema extends {
|
|
51
|
+
readonly _output: infer Output;
|
|
52
|
+
} ? Output : unknown;
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "3.11.
|
|
18
|
+
"version": "3.11.1",
|
|
19
19
|
"types": "./dist/types/index.d.ts",
|
|
20
20
|
"main": "./dist/cjs/index.js",
|
|
21
21
|
"exports": {
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"koa-compose": "^4.1.0",
|
|
34
34
|
"reflect-metadata": "^0.2.2",
|
|
35
35
|
"type-fest": "2.19.0",
|
|
36
|
-
"@modern-js/utils": "3.11.
|
|
36
|
+
"@modern-js/utils": "3.11.1"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@types/koa-compose": "^3.2.9",
|
|
@@ -42,9 +42,9 @@
|
|
|
42
42
|
"tsconfig-paths": "^4.2.0",
|
|
43
43
|
"typescript": "^5",
|
|
44
44
|
"zod": "^4.0.0",
|
|
45
|
-
"@modern-js/rslib": "3.11.
|
|
46
|
-
"@modern-js/types": "3.11.
|
|
47
|
-
"@scripts/rstest-config": "2.66.
|
|
45
|
+
"@modern-js/rslib": "3.11.1",
|
|
46
|
+
"@modern-js/types": "3.11.1",
|
|
47
|
+
"@scripts/rstest-config": "2.66.5"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
50
|
"ts-node": "^10.9.2",
|