@naturalcycles/backend-lib 9.50.0 → 9.51.1

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.
@@ -3,7 +3,7 @@ import { InMemoryDB } from '@naturalcycles/db-lib/inmemory';
3
3
  import { commonDBOptionsSchema, commonDBSaveOptionsSchema, dbQuerySchema, } from '@naturalcycles/db-lib/validation';
4
4
  import { j } from '@naturalcycles/nodejs-lib/ajv';
5
5
  import { getDefaultRouter } from '../express/getDefaultRouter.js';
6
- import { ajvValidateRequest } from '../validation/ajv/ajvValidateRequest.js';
6
+ import { validateRequest } from '../validation/ajv/validateRequest.js';
7
7
  const getByIdsInputSchema = j.object({
8
8
  table: j.string(),
9
9
  ids: j.array(j.string()),
@@ -49,24 +49,24 @@ export function httpDBRequestHandler(db) {
49
49
  // })
50
50
  // getByIds
51
51
  router.put('/getByIds', async (req, res) => {
52
- const { table, ids, opt } = ajvValidateRequest.body(req, getByIdsInputSchema);
52
+ const { table, ids, opt } = validateRequest.body(req, getByIdsInputSchema);
53
53
  res.json(await db.getByIds(table, ids, opt));
54
54
  });
55
55
  // runQuery
56
56
  router.put('/runQuery', async (req, res) => {
57
- const { query, opt } = ajvValidateRequest.body(req, runQueryInputSchema);
57
+ const { query, opt } = validateRequest.body(req, runQueryInputSchema);
58
58
  const q = DBQuery.fromPlainObject(query);
59
59
  res.json(await db.runQuery(q, opt));
60
60
  });
61
61
  // runQueryCount
62
62
  router.put('/runQueryCount', async (req, res) => {
63
- const { query, opt } = ajvValidateRequest.body(req, runQueryInputSchema);
63
+ const { query, opt } = validateRequest.body(req, runQueryInputSchema);
64
64
  const q = DBQuery.fromPlainObject(query);
65
65
  res.json(await db.runQueryCount(q, opt));
66
66
  });
67
67
  // saveBatch
68
68
  router.put('/saveBatch', async (req, res) => {
69
- const { table, rows, opt } = ajvValidateRequest.body(req, saveBatchInputSchema);
69
+ const { table, rows, opt } = validateRequest.body(req, saveBatchInputSchema);
70
70
  await db.saveBatch(table, rows, opt);
71
71
  res.end();
72
72
  });
@@ -77,7 +77,7 @@ export function httpDBRequestHandler(db) {
77
77
  // })
78
78
  // deleteByQuery
79
79
  router.put('/deleteByQuery', async (req, res) => {
80
- const { query, opt } = ajvValidateRequest.body(req, runQueryInputSchema);
80
+ const { query, opt } = validateRequest.body(req, runQueryInputSchema);
81
81
  const q = DBQuery.fromPlainObject(query);
82
82
  res.json(await db.deleteByQuery(q, opt));
83
83
  });
@@ -28,5 +28,5 @@ declare class AjvValidateRequest {
28
28
  headers<IN, OUT>(req: BackendRequest, schema: SchemaHandledByAjv<IN, OUT>, opt?: ReqValidationOptions<AjvValidationError>): OUT;
29
29
  private validate;
30
30
  }
31
- export declare const ajvValidateRequest: AjvValidateRequest;
31
+ export declare const validateRequest: AjvValidateRequest;
32
32
  export {};
@@ -60,4 +60,4 @@ class AjvValidateRequest {
60
60
  return output;
61
61
  }
62
62
  }
63
- export const ajvValidateRequest = new AjvValidateRequest();
63
+ export const validateRequest = new AjvValidateRequest();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@naturalcycles/backend-lib",
3
3
  "type": "module",
4
- "version": "9.50.0",
4
+ "version": "9.51.1",
5
5
  "peerDependencies": {
6
6
  "@sentry/node": "^10"
7
7
  },
@@ -45,7 +45,7 @@
45
45
  "./deploy": "./dist/deploy/index.js",
46
46
  "./deploy/*.js": "./dist/deploy/*.js",
47
47
  "./express/*.js": "./dist/express/*.js",
48
- "./ajvValidateRequest": "./dist/validation/ajv/ajvValidateRequest.js",
48
+ "./validateRequest": "./dist/validation/ajv/validateRequest.js",
49
49
  "./zodValidateRequest": "./dist/validation/zod/zodValidateRequest.js",
50
50
  "./onFinished": "./dist/onFinished.js",
51
51
  "./testing": "./dist/testing/index.js"
@@ -10,7 +10,7 @@ import type { ObjectWithId } from '@naturalcycles/js-lib/types'
10
10
  import { j } from '@naturalcycles/nodejs-lib/ajv'
11
11
  import { getDefaultRouter } from '../express/getDefaultRouter.js'
12
12
  import type { BackendRouter } from '../server/server.model.js'
13
- import { ajvValidateRequest } from '../validation/ajv/ajvValidateRequest.js'
13
+ import { validateRequest } from '../validation/ajv/validateRequest.js'
14
14
 
15
15
  export interface GetByIdsInput {
16
16
  table: string
@@ -83,27 +83,27 @@ export function httpDBRequestHandler(db: CommonDB): BackendRouter {
83
83
 
84
84
  // getByIds
85
85
  router.put('/getByIds', async (req, res) => {
86
- const { table, ids, opt } = ajvValidateRequest.body(req, getByIdsInputSchema)
86
+ const { table, ids, opt } = validateRequest.body(req, getByIdsInputSchema)
87
87
  res.json(await db.getByIds(table, ids, opt))
88
88
  })
89
89
 
90
90
  // runQuery
91
91
  router.put('/runQuery', async (req, res) => {
92
- const { query, opt } = ajvValidateRequest.body(req, runQueryInputSchema)
92
+ const { query, opt } = validateRequest.body(req, runQueryInputSchema)
93
93
  const q = DBQuery.fromPlainObject(query)
94
94
  res.json(await db.runQuery(q, opt))
95
95
  })
96
96
 
97
97
  // runQueryCount
98
98
  router.put('/runQueryCount', async (req, res) => {
99
- const { query, opt } = ajvValidateRequest.body(req, runQueryInputSchema)
99
+ const { query, opt } = validateRequest.body(req, runQueryInputSchema)
100
100
  const q = DBQuery.fromPlainObject(query)
101
101
  res.json(await db.runQueryCount(q, opt))
102
102
  })
103
103
 
104
104
  // saveBatch
105
105
  router.put('/saveBatch', async (req, res) => {
106
- const { table, rows, opt } = ajvValidateRequest.body(req, saveBatchInputSchema)
106
+ const { table, rows, opt } = validateRequest.body(req, saveBatchInputSchema)
107
107
  await db.saveBatch(table, rows, opt)
108
108
  res.end()
109
109
  })
@@ -116,7 +116,7 @@ export function httpDBRequestHandler(db: CommonDB): BackendRouter {
116
116
 
117
117
  // deleteByQuery
118
118
  router.put('/deleteByQuery', async (req, res) => {
119
- const { query, opt } = ajvValidateRequest.body(req, runQueryInputSchema)
119
+ const { query, opt } = validateRequest.body(req, runQueryInputSchema)
120
120
  const q = DBQuery.fromPlainObject(query)
121
121
  res.json(await db.deleteByQuery(q, opt))
122
122
  })
@@ -104,4 +104,4 @@ class AjvValidateRequest {
104
104
  }
105
105
  }
106
106
 
107
- export const ajvValidateRequest = new AjvValidateRequest()
107
+ export const validateRequest = new AjvValidateRequest()