@naturalcycles/backend-lib 9.53.0 → 9.54.0
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.
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { _lazyValue } from '@naturalcycles/js-lib';
|
|
2
|
-
import {
|
|
2
|
+
import { JSchema } from '@naturalcycles/nodejs-lib/ajv';
|
|
3
3
|
import { fs2 } from '@naturalcycles/nodejs-lib/fs2';
|
|
4
4
|
import { yaml2 } from '@naturalcycles/nodejs-lib/yaml2';
|
|
5
5
|
import { resourcesDir } from '../paths.cnst.js';
|
|
6
6
|
const getBackendCfgSchema = _lazyValue(() => {
|
|
7
7
|
const schemaJson = fs2.readJson(`${resourcesDir}/backendCfg.schema.json`);
|
|
8
|
-
return
|
|
8
|
+
return new JSchema(schemaJson, { inputName: 'backend.cfg.yaml' });
|
|
9
9
|
});
|
|
10
10
|
export function getBackendCfg(projectDir = '.') {
|
|
11
11
|
const backendCfgYamlPath = `${projectDir}/backend.cfg.yaml`;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AjvSchema, getCoercingAjv } from '@naturalcycles/nodejs-lib/ajv';
|
|
1
|
+
import { AjvSchema, getCoercingAjv, JSchema } from '@naturalcycles/nodejs-lib/ajv';
|
|
2
2
|
import { handleValidationError } from '../validateRequest.util.js';
|
|
3
3
|
class AjvValidateRequest {
|
|
4
4
|
body(req, schema, opt = {}) {
|
|
@@ -48,8 +48,11 @@ class AjvValidateRequest {
|
|
|
48
48
|
const input = req[reqProperty] || {};
|
|
49
49
|
const { coerceTypes, mutateInput } = opt;
|
|
50
50
|
const ajv = coerceTypes ? getCoercingAjv() : undefined;
|
|
51
|
-
const
|
|
52
|
-
|
|
51
|
+
const validatable = schema instanceof JSchema || schema instanceof AjvSchema
|
|
52
|
+
? schema
|
|
53
|
+
: new JSchema(schema);
|
|
54
|
+
const [error, output] = validatable.getValidationResult(input, {
|
|
55
|
+
ajv,
|
|
53
56
|
inputName: `request.${reqProperty}`,
|
|
54
57
|
getOriginalInput,
|
|
55
58
|
mutateInput,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naturalcycles/backend-lib",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "9.
|
|
4
|
+
"version": "9.54.0",
|
|
5
5
|
"peerDependencies": {
|
|
6
6
|
"@sentry/node-core": "^10"
|
|
7
7
|
},
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"@sentry/node-core": "^10",
|
|
36
36
|
"@typescript/native-preview": "7.0.0-dev.20260201.1",
|
|
37
37
|
"fastify": "^5",
|
|
38
|
-
"@naturalcycles/dev-lib": "
|
|
38
|
+
"@naturalcycles/dev-lib": "20.36.0"
|
|
39
39
|
},
|
|
40
40
|
"exports": {
|
|
41
41
|
".": "./dist/index.js",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { _lazyValue } from '@naturalcycles/js-lib'
|
|
2
2
|
import type { StringMap } from '@naturalcycles/js-lib/types'
|
|
3
|
-
import {
|
|
3
|
+
import { JSchema } from '@naturalcycles/nodejs-lib/ajv'
|
|
4
4
|
import type { JsonSchema } from '@naturalcycles/nodejs-lib/ajv'
|
|
5
5
|
import { fs2 } from '@naturalcycles/nodejs-lib/fs2'
|
|
6
6
|
import { yaml2 } from '@naturalcycles/nodejs-lib/yaml2'
|
|
@@ -42,7 +42,7 @@ export interface BackendCfg {
|
|
|
42
42
|
|
|
43
43
|
const getBackendCfgSchema = _lazyValue(() => {
|
|
44
44
|
const schemaJson = fs2.readJson<JsonSchema<BackendCfg>>(`${resourcesDir}/backendCfg.schema.json`)
|
|
45
|
-
return
|
|
45
|
+
return new JSchema<BackendCfg, false>(schemaJson, { inputName: 'backend.cfg.yaml' })
|
|
46
46
|
})
|
|
47
47
|
|
|
48
48
|
export function getBackendCfg(projectDir = '.'): BackendCfg {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AjvSchema, getCoercingAjv } from '@naturalcycles/nodejs-lib/ajv'
|
|
1
|
+
import { AjvSchema, getCoercingAjv, JSchema } from '@naturalcycles/nodejs-lib/ajv'
|
|
2
2
|
import type { AjvValidationError, SchemaHandledByAjv } from '@naturalcycles/nodejs-lib/ajv'
|
|
3
3
|
import type { BackendRequest } from '../../server/server.model.js'
|
|
4
4
|
import { handleValidationError } from '../validateRequest.util.js'
|
|
@@ -85,9 +85,14 @@ class AjvValidateRequest {
|
|
|
85
85
|
|
|
86
86
|
const { coerceTypes, mutateInput } = opt
|
|
87
87
|
const ajv = coerceTypes ? getCoercingAjv() : undefined
|
|
88
|
-
const ajvSchema = AjvSchema.create(schema, { ajv })
|
|
89
88
|
|
|
90
|
-
const
|
|
89
|
+
const validatable =
|
|
90
|
+
schema instanceof JSchema || schema instanceof AjvSchema
|
|
91
|
+
? schema
|
|
92
|
+
: new JSchema<OUT, false>(schema)
|
|
93
|
+
|
|
94
|
+
const [error, output] = validatable.getValidationResult(input, {
|
|
95
|
+
ajv,
|
|
91
96
|
inputName: `request.${reqProperty}`,
|
|
92
97
|
getOriginalInput,
|
|
93
98
|
mutateInput,
|