vovk-ajv 0.0.0-beta.5 → 0.0.0-beta.7

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.
Files changed (3) hide show
  1. package/index.d.ts +3 -4
  2. package/index.js +20 -20
  3. package/package.json +9 -3
package/index.d.ts CHANGED
@@ -1,7 +1,6 @@
1
- import { Options } from 'ajv';
2
- import ajvLocalize from 'ajv-i18n';
3
- import { type VovkValidateOnClient } from 'vovk';
4
- type Lang = keyof typeof ajvLocalize;
1
+ import { type Options } from 'ajv';
2
+ import { type VovkValidateOnClient } from 'vovk/createValidateOnClient';
3
+ type Lang = 'en' | 'ar' | 'ca' | 'cs' | 'de' | 'es' | 'fi' | 'fr' | 'hu' | 'id' | 'it' | 'ja' | 'ko' | 'nb' | 'nl' | 'pl' | 'pt-BR' | 'ru' | 'sk' | 'sv' | 'th' | 'zh' | 'zh-TW';
5
4
  export type VovkAjvConfig = {
6
5
  options?: Options;
7
6
  localize?: Lang;
package/index.js CHANGED
@@ -1,20 +1,20 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.validateOnClient = void 0;
7
- const ajv_1 = require("ajv");
8
- const _2020_1 = __importDefault(require("ajv/dist/2020"));
9
- const ajv_formats_1 = __importDefault(require("ajv-formats"));
10
- const ajv_i18n_1 = __importDefault(require("ajv-i18n"));
11
- const ajv_errors_1 = __importDefault(require("ajv-errors"));
12
- const vovk_1 = require("vovk");
1
+ import { Ajv } from 'ajv';
2
+ import _Ajv2020 from 'ajv/dist/2020.js';
3
+ import _ajvFormats from 'ajv-formats';
4
+ import _ajvLocalize from 'ajv-i18n';
5
+ import _ajvErrors from 'ajv-errors';
6
+ import { createValidateOnClient, HttpException, HttpStatus, } from 'vovk/createValidateOnClient';
7
+ // Handle ESM/CJS interop - these packages export CJS and may have .default wrapper
8
+ const Ajv2020 = (_Ajv2020.default ?? _Ajv2020);
9
+ const ajvFormats = (_ajvFormats.default ?? _ajvFormats);
10
+ const ajvErrors = (_ajvErrors.default ?? _ajvErrors);
11
+ const ajvLocalize = (_ajvLocalize.default ??
12
+ _ajvLocalize);
13
13
  const createAjv = (options, target) => {
14
- const AjvClass = target === 'draft-2020-12' ? _2020_1.default : ajv_1.Ajv;
14
+ const AjvClass = target === 'draft-2020-12' ? Ajv2020 : Ajv;
15
15
  const ajv = new AjvClass({ allErrors: true, ...options });
16
- (0, ajv_formats_1.default)(ajv);
17
- (0, ajv_errors_1.default)(ajv);
16
+ ajvFormats(ajv);
17
+ ajvErrors(ajv);
18
18
  ajv.addKeyword('x-isForm');
19
19
  ajv.addKeyword('x-tsType');
20
20
  return ajv;
@@ -60,8 +60,8 @@ const validate = ({ input, schema, localize = 'en', type, endpoint, options, tar
60
60
  }
61
61
  const isValid = ajv.validate(schema, input);
62
62
  if (!isValid) {
63
- ajv_i18n_1.default[localize](ajv.errors);
64
- throw new vovk_1.HttpException(vovk_1.HttpStatus.NULL, `Client-side validation failed. Invalid ${isFormData ? 'form' : type} on client: ${ajv.errorsText()}`, { input, errors: ajv.errors, endpoint });
63
+ ajvLocalize[localize](ajv.errors);
64
+ throw new HttpException(HttpStatus.NULL, `Client-side validation failed. Invalid ${isFormData ? 'form' : type} on client: ${ajv.errorsText()}`, { input, errors: ajv.errors, endpoint });
65
65
  }
66
66
  }
67
67
  };
@@ -72,7 +72,7 @@ const getConfig = (schema) => {
72
72
  const target = config?.target;
73
73
  return { options, localize, target };
74
74
  };
75
- const validateOnClientAjv = (0, vovk_1.createValidateOnClient)({
75
+ const validateOnClientAjv = createValidateOnClient({
76
76
  validate: (input, schema, { endpoint, type, fullSchema }) => {
77
77
  const { options, localize, target } = getConfig(fullSchema);
78
78
  validate({
@@ -86,7 +86,7 @@ const validateOnClientAjv = (0, vovk_1.createValidateOnClient)({
86
86
  });
87
87
  },
88
88
  });
89
- const configure = ({ options: givenOptions, localize: givenLocalize, target: givenTarget, }) => (0, vovk_1.createValidateOnClient)({
89
+ const configure = ({ options: givenOptions, localize: givenLocalize, target: givenTarget, }) => createValidateOnClient({
90
90
  validate: (input, schema, { endpoint, type, fullSchema }) => {
91
91
  const { options, localize, target } = getConfig(fullSchema);
92
92
  validate({
@@ -100,6 +100,6 @@ const configure = ({ options: givenOptions, localize: givenLocalize, target: giv
100
100
  });
101
101
  },
102
102
  });
103
- exports.validateOnClient = Object.assign(validateOnClientAjv, {
103
+ export const validateOnClient = Object.assign(validateOnClientAjv, {
104
104
  configure,
105
105
  });
package/package.json CHANGED
@@ -1,8 +1,14 @@
1
1
  {
2
2
  "name": "vovk-ajv",
3
- "version": "0.0.0-beta.5",
3
+ "version": "0.0.0-beta.7",
4
4
  "description": "Client-side JSON Schema validation library for Vovk.ts",
5
- "main": "index.js",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "default": "./index.mjs",
9
+ "types": "./index.d.mts"
10
+ }
11
+ },
6
12
  "scripts": {
7
13
  "build": "tsc",
8
14
  "tsc": "tsc --noEmit",
@@ -26,7 +32,7 @@
26
32
  },
27
33
  "homepage": "https://vovk.dev/imports",
28
34
  "peerDependencies": {
29
- "vovk": "^3.0.0-beta.98"
35
+ "vovk": "^3.0.0-beta.108"
30
36
  },
31
37
  "dependencies": {
32
38
  "ajv": "^8.17.1",