@stone-js/validation 0.8.13 → 0.8.14
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 +38 -38
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -196,44 +196,6 @@ class Validator {
|
|
|
196
196
|
}
|
|
197
197
|
}
|
|
198
198
|
|
|
199
|
-
/**
|
|
200
|
-
* Registers the {@link Validator} service (singleton) in the container, aliased as
|
|
201
|
-
* `validator`/`Validator`, so middleware, handlers and services can resolve it.
|
|
202
|
-
*
|
|
203
|
-
* It also binds whatever schema engines the application declared under
|
|
204
|
-
* `stone.validation.engines`, so a schema class can take its engine through its constructor:
|
|
205
|
-
* `constructor ({ zod })`. That is more elegant than importing the library at every schema, and more
|
|
206
|
-
* testable, since a test hands the class a fake instead of mocking a module.
|
|
207
|
-
*
|
|
208
|
-
* The application names the engine; this module never imports one. That is what keeps it agnostic:
|
|
209
|
-
* Zod, Valibot and ArkType arrive through Standard Schema, and a native schema needs no engine at all.
|
|
210
|
-
*/
|
|
211
|
-
class ValidationServiceProvider {
|
|
212
|
-
container;
|
|
213
|
-
/**
|
|
214
|
-
* @param container - The service container.
|
|
215
|
-
*/
|
|
216
|
-
constructor(container) {
|
|
217
|
-
this.container = container;
|
|
218
|
-
}
|
|
219
|
-
/**
|
|
220
|
-
* Register the validation service and any declared schema engine.
|
|
221
|
-
*/
|
|
222
|
-
register() {
|
|
223
|
-
this.container
|
|
224
|
-
.singletonIf(Validator, () => Validator.create())
|
|
225
|
-
.alias(Validator, ['validator', 'Validator']);
|
|
226
|
-
const engines = this.container
|
|
227
|
-
.make('blueprint')
|
|
228
|
-
.get('stone.validation', {})
|
|
229
|
-
.engines ?? {};
|
|
230
|
-
for (const [name, engine] of Object.entries(engines)) {
|
|
231
|
-
// `instanceIf` so an application that already bound the name keeps its own binding.
|
|
232
|
-
this.container.instanceIf(name, engine);
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
|
|
237
199
|
/**
|
|
238
200
|
* Whether a value is a schema rather than a map of schemas.
|
|
239
201
|
*
|
|
@@ -395,6 +357,44 @@ function validateEvent(event, rules, validator = Validator.create()) {
|
|
|
395
357
|
return parsed;
|
|
396
358
|
}
|
|
397
359
|
|
|
360
|
+
/**
|
|
361
|
+
* Registers the {@link Validator} service (singleton) in the container, aliased as
|
|
362
|
+
* `validator`/`Validator`, so middleware, handlers and services can resolve it.
|
|
363
|
+
*
|
|
364
|
+
* It also binds whatever schema engines the application declared under
|
|
365
|
+
* `stone.validation.engines`, so a schema class can take its engine through its constructor:
|
|
366
|
+
* `constructor ({ zod })`. That is more elegant than importing the library at every schema, and more
|
|
367
|
+
* testable, since a test hands the class a fake instead of mocking a module.
|
|
368
|
+
*
|
|
369
|
+
* The application names the engine; this module never imports one. That is what keeps it agnostic:
|
|
370
|
+
* Zod, Valibot and ArkType arrive through Standard Schema, and a native schema needs no engine at all.
|
|
371
|
+
*/
|
|
372
|
+
class ValidationServiceProvider {
|
|
373
|
+
container;
|
|
374
|
+
/**
|
|
375
|
+
* @param container - The service container.
|
|
376
|
+
*/
|
|
377
|
+
constructor(container) {
|
|
378
|
+
this.container = container;
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Register the validation service and any declared schema engine.
|
|
382
|
+
*/
|
|
383
|
+
register() {
|
|
384
|
+
this.container
|
|
385
|
+
.singletonIf(Validator, () => Validator.create())
|
|
386
|
+
.alias(Validator, ['validator', 'Validator']);
|
|
387
|
+
const engines = this.container
|
|
388
|
+
.make('blueprint')
|
|
389
|
+
.get('stone.validation', {})
|
|
390
|
+
.engines ?? {};
|
|
391
|
+
for (const [name, engine] of Object.entries(engines)) {
|
|
392
|
+
// `instanceIf` so an application that already bound the name keeps its own binding.
|
|
393
|
+
this.container.instanceIf(name, engine);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
|
|
398
398
|
/**
|
|
399
399
|
* Metadata key carrying what a handler method declared with `@Validate`.
|
|
400
400
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stone-js/validation",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.14",
|
|
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.14"
|
|
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.14"
|
|
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.14"
|
|
79
79
|
},
|
|
80
80
|
"scripts": {
|
|
81
81
|
"lint": "ts-standard src",
|