@stone-js/validation 0.8.10 → 0.8.11
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/decorators/ValidationSchema.d.ts +22 -12
- package/dist/index.d.ts +4 -4
- package/dist/index.js +33 -13
- package/package.json +4 -4
|
@@ -1,18 +1,28 @@
|
|
|
1
|
+
import { ClassType } from '@stone-js/core';
|
|
1
2
|
/**
|
|
2
|
-
*
|
|
3
|
+
* Declare a class as a rule set.
|
|
3
4
|
*
|
|
4
|
-
*
|
|
5
|
-
* @ValidationSchema('createUser')
|
|
6
|
-
* export class CreateUserSchema implements IValidationSchema { rules () { … } }
|
|
7
|
-
* ```
|
|
5
|
+
* Three statements in one, which is why nothing has to be wired by hand:
|
|
8
6
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
7
|
+
* 1. **It is a service.** The container builds it, as a singleton, so its constructor is auto-wired
|
|
8
|
+
* like any other class: a repository, a client, a translator, whatever it destructures is resolved
|
|
9
|
+
* for it. That is what lets a rule set depend on the application instead of on constants.
|
|
10
|
+
* 2. **It is reachable by name.** The alias is bound as `schema:<name>`, prefixed on purpose: an
|
|
11
|
+
* application is free to bind its own service under a plain word, and a declaration named after a
|
|
12
|
+
* domain concept must not compete for that name.
|
|
13
|
+
* 3. **It activates the module.** The blueprint comes with the decorator, so declaring this is the
|
|
14
|
+
* whole setup, and a route naming it resolves to this class.
|
|
13
15
|
*
|
|
14
|
-
* @param alias - The name
|
|
15
|
-
* discovery middleware fills in, since it is the one holding the class.
|
|
16
|
+
* @param alias - The name a route refers to it by. Defaults to the class name.
|
|
16
17
|
* @returns A class decorator.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* @ValidationSchema('createUser')
|
|
22
|
+
* export class CreateUser {
|
|
23
|
+
* constructor (private readonly users: UserRepository) {}
|
|
24
|
+
* rules (): RouteValidationRules { return { body: { email: { rules: 'email' } } } }
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
17
27
|
*/
|
|
18
|
-
export declare const ValidationSchema: (alias?: string) => ClassDecorator;
|
|
28
|
+
export declare const ValidationSchema: <T extends ClassType = ClassType>(alias?: string) => ClassDecorator;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
export * from './ValidationServiceProvider.js';
|
|
2
|
-
export * from './Validator.js';
|
|
3
1
|
export * from './adapters/standardSchema.js';
|
|
4
2
|
export * from './adapters/zod.js';
|
|
5
3
|
export * from './declarations.js';
|
|
4
|
+
export * from './decorators/constants.js';
|
|
6
5
|
export * from './decorators/Validate.js';
|
|
7
6
|
export * from './decorators/Validation.js';
|
|
8
7
|
export * from './decorators/ValidationSchema.js';
|
|
9
|
-
export * from './decorators/constants.js';
|
|
10
8
|
export * from './errors/ValidationError.js';
|
|
11
9
|
export * from './middleware/BlueprintMiddleware.js';
|
|
12
|
-
export * from './middleware/ValidateRouteMiddleware.js';
|
|
13
10
|
export * from './middleware/validate.js';
|
|
11
|
+
export * from './middleware/ValidateRouteMiddleware.js';
|
|
14
12
|
export * from './options/ValidationBlueprint.js';
|
|
15
13
|
export * from './schema.js';
|
|
16
14
|
export * from './schemaClass.js';
|
|
17
15
|
export * from './sources.js';
|
|
18
16
|
export * from './validateEvent.js';
|
|
17
|
+
export * from './ValidationServiceProvider.js';
|
|
18
|
+
export * from './Validator.js';
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IntegrationError, methodDecoratorLegacyWrapper, addMetadata, hasMetadata, getMetadata, classDecoratorLegacyWrapper, addBlueprint,
|
|
1
|
+
import { IntegrationError, methodDecoratorLegacyWrapper, addMetadata, hasMetadata, getMetadata, classDecoratorLegacyWrapper, addBlueprint, setMetadata, SERVICE_KEY } from '@stone-js/core';
|
|
2
2
|
import { cloneValue } from '@stone-js/config';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -693,24 +693,44 @@ const Validation = (options = {}) => {
|
|
|
693
693
|
};
|
|
694
694
|
|
|
695
695
|
/**
|
|
696
|
-
*
|
|
696
|
+
* Declare a class as a rule set.
|
|
697
697
|
*
|
|
698
|
-
*
|
|
699
|
-
* @ValidationSchema('createUser')
|
|
700
|
-
* export class CreateUserSchema implements IValidationSchema { rules () { … } }
|
|
701
|
-
* ```
|
|
698
|
+
* Three statements in one, which is why nothing has to be wired by hand:
|
|
702
699
|
*
|
|
703
|
-
*
|
|
704
|
-
*
|
|
705
|
-
*
|
|
706
|
-
*
|
|
700
|
+
* 1. **It is a service.** The container builds it, as a singleton, so its constructor is auto-wired
|
|
701
|
+
* like any other class: a repository, a client, a translator, whatever it destructures is resolved
|
|
702
|
+
* for it. That is what lets a rule set depend on the application instead of on constants.
|
|
703
|
+
* 2. **It is reachable by name.** The alias is bound as `schema:<name>`, prefixed on purpose: an
|
|
704
|
+
* application is free to bind its own service under a plain word, and a declaration named after a
|
|
705
|
+
* domain concept must not compete for that name.
|
|
706
|
+
* 3. **It activates the module.** The blueprint comes with the decorator, so declaring this is the
|
|
707
|
+
* whole setup, and a route naming it resolves to this class.
|
|
707
708
|
*
|
|
708
|
-
* @param alias - The name
|
|
709
|
-
* discovery middleware fills in, since it is the one holding the class.
|
|
709
|
+
* @param alias - The name a route refers to it by. Defaults to the class name.
|
|
710
710
|
* @returns A class decorator.
|
|
711
|
+
*
|
|
712
|
+
* @example
|
|
713
|
+
* ```ts
|
|
714
|
+
* @ValidationSchema('createUser')
|
|
715
|
+
* export class CreateUser {
|
|
716
|
+
* constructor (private readonly users: UserRepository) {}
|
|
717
|
+
* rules (): RouteValidationRules { return { body: { email: { rules: 'email' } } } }
|
|
718
|
+
* }
|
|
719
|
+
* ```
|
|
711
720
|
*/
|
|
712
721
|
const ValidationSchema = (alias) => {
|
|
713
|
-
return
|
|
722
|
+
return classDecoratorLegacyWrapper((target, context) => {
|
|
723
|
+
const name = alias ?? target.name;
|
|
724
|
+
setMetadata(context, VALIDATION_SCHEMA_KEY, { alias: name });
|
|
725
|
+
setMetadata(context, SERVICE_KEY, { singleton: true, isClass: true, alias: `schema:${name}` });
|
|
726
|
+
addBlueprint(target, context, validationBlueprint, {
|
|
727
|
+
stone: {
|
|
728
|
+
validation: {
|
|
729
|
+
schemas: { [name]: target }
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
});
|
|
733
|
+
});
|
|
714
734
|
};
|
|
715
735
|
|
|
716
736
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stone-js/validation",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.11",
|
|
4
4
|
"description": "Framework-agnostic input validation for Stone.js. Define a schema once (Zod, Valibot, ArkType — anything Standard Schema) and validate it identically on the backend and the frontend.",
|
|
5
5
|
"author": "Mr. Stone <evensstone@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"node": ">=18.17.0"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
|
-
"@stone-js/core": "0.8.
|
|
43
|
+
"@stone-js/core": "0.8.11"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@commitlint/cli": "^19.8.1",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"typescript": "^5.6.3",
|
|
63
63
|
"vitest": "^3.2.4",
|
|
64
64
|
"zod": "^3.24.1",
|
|
65
|
-
"@stone-js/core": "0.8.
|
|
65
|
+
"@stone-js/core": "0.8.11"
|
|
66
66
|
},
|
|
67
67
|
"ts-standard": {
|
|
68
68
|
"globals": [
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
]
|
|
76
76
|
},
|
|
77
77
|
"dependencies": {
|
|
78
|
-
"@stone-js/config": "0.8.
|
|
78
|
+
"@stone-js/config": "0.8.11"
|
|
79
79
|
},
|
|
80
80
|
"scripts": {
|
|
81
81
|
"lint": "ts-standard src",
|