@naturalcycles/backend-lib 9.54.0 → 9.55.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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@naturalcycles/backend-lib",
3
3
  "type": "module",
4
- "version": "9.54.0",
4
+ "version": "9.55.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": "20.36.0"
38
+ "@naturalcycles/dev-lib": "18.4.2"
39
39
  },
40
40
  "exports": {
41
41
  ".": "./dist/index.js",
@@ -46,7 +46,6 @@
46
46
  "./deploy/*.js": "./dist/deploy/*.js",
47
47
  "./express/*.js": "./dist/express/*.js",
48
48
  "./validateRequest": "./dist/validation/ajv/validateRequest.js",
49
- "./zodValidateRequest": "./dist/validation/zod/zodValidateRequest.js",
50
49
  "./onFinished": "./dist/onFinished.js",
51
50
  "./testing": "./dist/testing/index.js"
52
51
  },
@@ -1,21 +0,0 @@
1
- import type { ZodType, ZodValidationError } from '@naturalcycles/js-lib/zod';
2
- import type { BackendRequest } from '../../server/server.model.js';
3
- import type { ReqValidationOptions } from '../validateRequest.util.js';
4
- declare class ZodValidateRequest {
5
- body<T>(req: BackendRequest, schema: ZodType<T>, opt?: ReqValidationOptions<ZodValidationError>): T;
6
- query<T>(req: BackendRequest, schema: ZodType<T>, opt?: ReqValidationOptions<ZodValidationError>): T;
7
- params<T>(req: BackendRequest, schema: ZodType<T>, opt?: ReqValidationOptions<ZodValidationError>): T;
8
- /**
9
- * Validates `req.headers` against the provided schema.
10
- *
11
- * Note: as opposed to other methods, this method does not mutate `req.headers` in case of success,
12
- * i.e. schemas that cast values will not have any effect.
13
- *
14
- * If you wish to mutate `req.headers` with the validated value, use `keepOriginal: false` option.
15
- * Keep in mind that this will also remove all values that are not in the schema.
16
- */
17
- headers<T>(req: BackendRequest, schema: ZodType<T>, opt?: ReqValidationOptions<ZodValidationError>): T;
18
- private validate;
19
- }
20
- export declare const zodValidateRequest: ZodValidateRequest;
21
- export {};
@@ -1,39 +0,0 @@
1
- import { zSafeValidate } from '@naturalcycles/js-lib/zod';
2
- import { handleValidationError } from '../validateRequest.util.js';
3
- class ZodValidateRequest {
4
- body(req, schema, opt = {}) {
5
- return this.validate(req, 'body', schema, opt);
6
- }
7
- query(req, schema, opt = {}) {
8
- return this.validate(req, 'query', schema, opt);
9
- }
10
- params(req, schema, opt = {}) {
11
- return this.validate(req, 'params', schema, opt);
12
- }
13
- /**
14
- * Validates `req.headers` against the provided schema.
15
- *
16
- * Note: as opposed to other methods, this method does not mutate `req.headers` in case of success,
17
- * i.e. schemas that cast values will not have any effect.
18
- *
19
- * If you wish to mutate `req.headers` with the validated value, use `keepOriginal: false` option.
20
- * Keep in mind that this will also remove all values that are not in the schema.
21
- */
22
- headers(req, schema, opt = {}) {
23
- return this.validate(req, 'headers', schema, opt);
24
- }
25
- validate(req, reqProperty, schema, opt = {}) {
26
- const originalProperty = (req[reqProperty] || {});
27
- // Zod does not mutate the input
28
- const [error, data] = zSafeValidate(originalProperty, schema
29
- // opt2?.itemName,
30
- );
31
- if (error) {
32
- handleValidationError(error, originalProperty, opt);
33
- }
34
- // Kirill: decide to not do it, let's see
35
- // req[reqProperty] = data
36
- return data;
37
- }
38
- }
39
- export const zodValidateRequest = new ZodValidateRequest();
@@ -1,75 +0,0 @@
1
- import { zSafeValidate } from '@naturalcycles/js-lib/zod'
2
- import type { ZodType, ZodValidationError } from '@naturalcycles/js-lib/zod'
3
- import type { BackendRequest } from '../../server/server.model.js'
4
- import { handleValidationError } from '../validateRequest.util.js'
5
- import type { ReqValidationOptions } from '../validateRequest.util.js'
6
-
7
- class ZodValidateRequest {
8
- body<T>(
9
- req: BackendRequest,
10
- schema: ZodType<T>,
11
- opt: ReqValidationOptions<ZodValidationError> = {},
12
- ): T {
13
- return this.validate(req, 'body', schema, opt)
14
- }
15
-
16
- query<T>(
17
- req: BackendRequest,
18
- schema: ZodType<T>,
19
- opt: ReqValidationOptions<ZodValidationError> = {},
20
- ): T {
21
- return this.validate(req, 'query', schema, opt)
22
- }
23
-
24
- params<T>(
25
- req: BackendRequest,
26
- schema: ZodType<T>,
27
- opt: ReqValidationOptions<ZodValidationError> = {},
28
- ): T {
29
- return this.validate(req, 'params', schema, opt)
30
- }
31
-
32
- /**
33
- * Validates `req.headers` against the provided schema.
34
- *
35
- * Note: as opposed to other methods, this method does not mutate `req.headers` in case of success,
36
- * i.e. schemas that cast values will not have any effect.
37
- *
38
- * If you wish to mutate `req.headers` with the validated value, use `keepOriginal: false` option.
39
- * Keep in mind that this will also remove all values that are not in the schema.
40
- */
41
- headers<T>(
42
- req: BackendRequest,
43
- schema: ZodType<T>,
44
- opt: ReqValidationOptions<ZodValidationError> = {},
45
- ): T {
46
- return this.validate(req, 'headers', schema, opt)
47
- }
48
-
49
- private validate<T>(
50
- req: BackendRequest,
51
- reqProperty: 'body' | 'params' | 'query' | 'headers',
52
- schema: ZodType<T>,
53
- opt: ReqValidationOptions<ZodValidationError> = {},
54
- ): T {
55
- const originalProperty = (req[reqProperty] || {}) as T
56
-
57
- // Zod does not mutate the input
58
- const [error, data] = zSafeValidate(
59
- originalProperty,
60
- schema,
61
- // opt2?.itemName,
62
- )
63
-
64
- if (error) {
65
- handleValidationError(error, originalProperty, opt)
66
- }
67
-
68
- // Kirill: decide to not do it, let's see
69
- // req[reqProperty] = data
70
-
71
- return data
72
- }
73
- }
74
-
75
- export const zodValidateRequest = new ZodValidateRequest()