@naturalcycles/backend-lib 9.52.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 { AjvSchema } from '@naturalcycles/nodejs-lib/ajv';
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 AjvSchema.create(schemaJson, { inputName: 'backend.cfg.yaml' });
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,7 +1,7 @@
1
1
  import type { CommonLogger } from '@naturalcycles/js-lib/log';
2
2
  import type { Primitive, StringMap } from '@naturalcycles/js-lib/types';
3
- import type { Breadcrumb, SeverityLevel } from '@sentry/node';
4
- import type * as SentryLib from '@sentry/node';
3
+ import type { Breadcrumb, SeverityLevel } from '@sentry/node-core/light';
4
+ import type * as SentryLib from '@sentry/node-core/light';
5
5
  export interface SentrySharedServiceCfg {
6
6
  sentry: typeof SentryLib;
7
7
  }
@@ -64,8 +64,11 @@ export function compressionMiddleware(options) {
64
64
  let length;
65
65
  let listeners = [];
66
66
  let stream;
67
+ // oxlint-disable-next-line typescript/unbound-method -- monkey-patching, rebound via .call()
67
68
  const _end = res.end;
69
+ // oxlint-disable-next-line typescript/unbound-method -- monkey-patching, rebound via .call()
68
70
  const _on = res.on;
71
+ // oxlint-disable-next-line typescript/unbound-method -- monkey-patching, rebound via .call()
69
72
  const _write = res.write;
70
73
  res.flush = function flush() {
71
74
  if (stream) {
@@ -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 ajvSchema = AjvSchema.create(schema, { ajv });
52
- const [error, output] = ajvSchema.getValidationResult(input, {
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,9 +1,9 @@
1
1
  {
2
2
  "name": "@naturalcycles/backend-lib",
3
3
  "type": "module",
4
- "version": "9.52.0",
4
+ "version": "9.54.0",
5
5
  "peerDependencies": {
6
- "@sentry/node": "^10"
6
+ "@sentry/node-core": "^10"
7
7
  },
8
8
  "dependencies": {
9
9
  "@naturalcycles/db-lib": "^10",
@@ -32,10 +32,10 @@
32
32
  "vary": "^1"
33
33
  },
34
34
  "devDependencies": {
35
- "@sentry/node": "^10",
35
+ "@sentry/node-core": "^10",
36
36
  "@typescript/native-preview": "7.0.0-dev.20260201.1",
37
37
  "fastify": "^5",
38
- "@naturalcycles/dev-lib": "18.4.2"
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 { AjvSchema } from '@naturalcycles/nodejs-lib/ajv'
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 AjvSchema.create(schemaJson, { inputName: 'backend.cfg.yaml' })
45
+ return new JSchema<BackendCfg, false>(schemaJson, { inputName: 'backend.cfg.yaml' })
46
46
  })
47
47
 
48
48
  export function getBackendCfg(projectDir = '.'): BackendCfg {
@@ -162,19 +162,16 @@ export function createAppYaml(
162
162
  .split(',')
163
163
  .filter(Boolean)
164
164
  // oxlint-disable-next-line unicorn/no-array-reduce
165
- .reduce(
166
- (map, key) => {
167
- const v = process.env[key]
168
- if (!v) {
169
- throw new Error(
170
- `appYamlPassEnv.${key} is requested, but process.env.${key} is not defined!`,
171
- )
172
- }
173
- map[key] = v
174
- return map
175
- },
176
- {} as Record<string, string>,
177
- )
165
+ .reduce<Record<string, string>>((map, key) => {
166
+ const v = process.env[key]
167
+ if (!v) {
168
+ throw new Error(
169
+ `appYamlPassEnv.${key} is requested, but process.env.${key} is not defined!`,
170
+ )
171
+ }
172
+ map[key] = v
173
+ return map
174
+ }, {})
178
175
 
179
176
  if (Object.keys(passEnv).length) {
180
177
  console.log(
@@ -3,8 +3,8 @@ import type { CommonLogger, CommonLogLevel } from '@naturalcycles/js-lib/log'
3
3
  import type { Primitive, StringMap } from '@naturalcycles/js-lib/types'
4
4
  import type { InspectAnyOptions } from '@naturalcycles/nodejs-lib'
5
5
  import { _inspect } from '@naturalcycles/nodejs-lib'
6
- import type { Breadcrumb, SeverityLevel } from '@sentry/node'
7
- import type * as SentryLib from '@sentry/node'
6
+ import type { Breadcrumb, SeverityLevel } from '@sentry/node-core/light'
7
+ import type * as SentryLib from '@sentry/node-core/light'
8
8
  import { getRequestLogger } from '../server/asyncLocalStorageMiddleware.js'
9
9
 
10
10
  export interface SentrySharedServiceCfg {
@@ -114,8 +114,11 @@ export function compressionMiddleware(options?: CompressionOptions): BackendRequ
114
114
  let listeners: [string, (...args: any[]) => void][] | null = []
115
115
  let stream: zlib.Gzip | zlib.Deflate | zlib.BrotliCompress | zlib.ZstdCompress | undefined
116
116
 
117
+ // oxlint-disable-next-line typescript/unbound-method -- monkey-patching, rebound via .call()
117
118
  const _end = res.end
119
+ // oxlint-disable-next-line typescript/unbound-method -- monkey-patching, rebound via .call()
118
120
  const _on = res.on
121
+ // oxlint-disable-next-line typescript/unbound-method -- monkey-patching, rebound via .call()
119
122
  const _write = res.write
120
123
 
121
124
  // flush
@@ -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 [error, output] = ajvSchema.getValidationResult(input, {
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,