@naturalcycles/backend-lib 9.34.1 → 9.35.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.
@@ -40,7 +40,7 @@ export class BaseAdminService {
40
40
  /**
41
41
  * To be extended.
42
42
  */
43
- // eslint-disable-next-line max-params
43
+ // oxlint-disable-next-line max-params
44
44
  async onPermissionCheck(req, email, reqPermissions, required, granted, meta = {}) {
45
45
  req.log(`${dimGrey(email)} ${required ? 'required' : 'optional'} permissions check [${dimGrey(reqPermissions.join(', '))}]: ${granted ? green('GRANTED') : red('DENIED')}`, meta);
46
46
  }
@@ -15,7 +15,7 @@ const runQueryInputSchema = objectSchema({
15
15
  });
16
16
  const saveBatchInputSchema = objectSchema({
17
17
  table: stringSchema,
18
- rows: arraySchema(anyObjectSchema),
18
+ rows: arraySchema(anyObjectSchema()),
19
19
  opt: commonDBSaveOptionsSchema.optional(),
20
20
  });
21
21
  /**
@@ -110,7 +110,7 @@ export function createAppYaml(backendCfg, deployInfo, projectDir, appYamlPassEnv
110
110
  const passEnv = appYamlPassEnv
111
111
  .split(',')
112
112
  .filter(Boolean)
113
- // eslint-disable-next-line unicorn/no-array-reduce
113
+ // oxlint-disable-next-line unicorn/no-array-reduce
114
114
  .reduce((map, key) => {
115
115
  const v = process.env[key];
116
116
  if (!v) {
@@ -1,11 +1,10 @@
1
- import type { ZodType } from '@naturalcycles/js-lib/zod';
2
- import { AjvSchema, type AjvValidationError } from '@naturalcycles/nodejs-lib/ajv';
1
+ import { type AjvValidationError, type SchemaHandledByAjv } from '@naturalcycles/nodejs-lib/ajv';
3
2
  import type { BackendRequest } from '../../server/server.model.js';
4
3
  import { type ReqValidationOptions } from '../validateRequest.util.js';
5
4
  declare class AjvValidateRequest {
6
- body<T>(req: BackendRequest, schema: AjvSchema<T> | ZodType<T>, opt?: ReqValidationOptions<AjvValidationError>): T;
7
- query<T>(req: BackendRequest, schema: AjvSchema<T> | ZodType<T>, opt?: ReqValidationOptions<AjvValidationError>): T;
8
- params<T>(req: BackendRequest, schema: AjvSchema<T> | ZodType<T>, opt?: ReqValidationOptions<AjvValidationError>): T;
5
+ body<T>(req: BackendRequest, schema: SchemaHandledByAjv<T>, opt?: ReqValidationOptions<AjvValidationError>): T;
6
+ query<T>(req: BackendRequest, schema: SchemaHandledByAjv<T>, opt?: ReqValidationOptions<AjvValidationError>): T;
7
+ params<T>(req: BackendRequest, schema: SchemaHandledByAjv<T>, opt?: ReqValidationOptions<AjvValidationError>): T;
9
8
  /**
10
9
  * Does NOT mutate `req.headers`,
11
10
  * but returns validated/transformed headers.
@@ -14,7 +13,7 @@ declare class AjvValidateRequest {
14
13
  * We want to non-mutate the `req.headers`, because we anticipate that
15
14
  * there may be additional consumers for `req.headers` (e.g middlewares, etc).
16
15
  */
17
- headers<T>(req: BackendRequest, schema: AjvSchema<T>, opt?: ReqValidationOptions<AjvValidationError>): T;
16
+ headers<T>(req: BackendRequest, schema: SchemaHandledByAjv<T>, opt?: ReqValidationOptions<AjvValidationError>): T;
18
17
  private validate;
19
18
  }
20
19
  export declare const ajvValidateRequest: AjvValidateRequest;
@@ -1,5 +1,5 @@
1
1
  import { _deepCopy } from '@naturalcycles/js-lib/object';
2
- import { AjvSchema } from '@naturalcycles/nodejs-lib/ajv';
2
+ import { AjvSchema, } from '@naturalcycles/nodejs-lib/ajv';
3
3
  import { handleValidationError } from '../validateRequest.util.js';
4
4
  class AjvValidateRequest {
5
5
  body(req, schema, opt = {}) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@naturalcycles/backend-lib",
3
3
  "type": "module",
4
- "version": "9.34.1",
4
+ "version": "9.35.0",
5
5
  "peerDependencies": {
6
6
  "@sentry/node": "^10"
7
7
  },
@@ -71,7 +71,7 @@ export class BaseAdminService {
71
71
  /**
72
72
  * To be extended.
73
73
  */
74
- // eslint-disable-next-line max-params
74
+ // oxlint-disable-next-line max-params
75
75
  protected async onPermissionCheck(
76
76
  req: BackendRequest,
77
77
  email: string,
@@ -47,7 +47,7 @@ export interface SaveBatchInput {
47
47
 
48
48
  const saveBatchInputSchema = objectSchema<SaveBatchInput>({
49
49
  table: stringSchema,
50
- rows: arraySchema(anyObjectSchema),
50
+ rows: arraySchema(anyObjectSchema()),
51
51
  opt: commonDBSaveOptionsSchema.optional(),
52
52
  })
53
53
 
@@ -161,7 +161,7 @@ export function createAppYaml(
161
161
  const passEnv = appYamlPassEnv
162
162
  .split(',')
163
163
  .filter(Boolean)
164
- // eslint-disable-next-line unicorn/no-array-reduce
164
+ // oxlint-disable-next-line unicorn/no-array-reduce
165
165
  .reduce(
166
166
  (map, key) => {
167
167
  const v = process.env[key]
@@ -1,13 +1,16 @@
1
1
  import { _deepCopy } from '@naturalcycles/js-lib/object'
2
- import type { ZodType } from '@naturalcycles/js-lib/zod'
3
- import { AjvSchema, type AjvValidationError } from '@naturalcycles/nodejs-lib/ajv'
2
+ import {
3
+ AjvSchema,
4
+ type AjvValidationError,
5
+ type SchemaHandledByAjv,
6
+ } from '@naturalcycles/nodejs-lib/ajv'
4
7
  import type { BackendRequest } from '../../server/server.model.js'
5
8
  import { handleValidationError, type ReqValidationOptions } from '../validateRequest.util.js'
6
9
 
7
10
  class AjvValidateRequest {
8
11
  body<T>(
9
12
  req: BackendRequest,
10
- schema: AjvSchema<T> | ZodType<T>,
13
+ schema: SchemaHandledByAjv<T>,
11
14
  opt: ReqValidationOptions<AjvValidationError> = {},
12
15
  ): T {
13
16
  return this.validate(req, 'body', schema, opt)
@@ -15,7 +18,7 @@ class AjvValidateRequest {
15
18
 
16
19
  query<T>(
17
20
  req: BackendRequest,
18
- schema: AjvSchema<T> | ZodType<T>,
21
+ schema: SchemaHandledByAjv<T>,
19
22
  opt: ReqValidationOptions<AjvValidationError> = {},
20
23
  ): T {
21
24
  return this.validate(req, 'query', schema, opt)
@@ -23,7 +26,7 @@ class AjvValidateRequest {
23
26
 
24
27
  params<T>(
25
28
  req: BackendRequest,
26
- schema: AjvSchema<T> | ZodType<T>,
29
+ schema: SchemaHandledByAjv<T>,
27
30
  opt: ReqValidationOptions<AjvValidationError> = {},
28
31
  ): T {
29
32
  return this.validate(req, 'params', schema, opt)
@@ -39,7 +42,7 @@ class AjvValidateRequest {
39
42
  */
40
43
  headers<T>(
41
44
  req: BackendRequest,
42
- schema: AjvSchema<T>,
45
+ schema: SchemaHandledByAjv<T>,
43
46
  opt: ReqValidationOptions<AjvValidationError> = {},
44
47
  ): T {
45
48
  const originalHeaders = _deepCopy(req.headers)
@@ -51,7 +54,7 @@ class AjvValidateRequest {
51
54
  private validate<T>(
52
55
  req: BackendRequest,
53
56
  reqProperty: 'body' | 'params' | 'query' | 'headers',
54
- schema: AjvSchema<T> | ZodType<T>,
57
+ schema: SchemaHandledByAjv<T>,
55
58
  opt: ReqValidationOptions<AjvValidationError> = {},
56
59
  ): T {
57
60
  const input: T = req[reqProperty] || {}