@tsed/ajv 7.79.4 → 7.80.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.
@@ -6,7 +6,7 @@ import Ajv from "ajv";
6
6
  import { AjvValidationError } from "../errors/AjvValidationError.js";
7
7
  import { defaultErrorFormatter } from "../utils/defaultErrorFormatter.js";
8
8
  import { getPath } from "../utils/getPath.js";
9
- import "./Ajv.js";
9
+ import "./Ajv";
10
10
  let AjvService = class AjvService {
11
11
  errorFormatter;
12
12
  returnsCoercedValues;
@@ -0,0 +1,10 @@
1
+ import { AsyncFormatDefinition, FormatDefinition } from "ajv";
2
+ export type FormatsOptions = Omit<FormatDefinition<any>, "validate" | "compare"> | Omit<AsyncFormatDefinition<any>, "validate" | "compare">;
3
+ /**
4
+ * Create a new custom formats validator
5
+ * @param name
6
+ * @param options
7
+ * @decorator
8
+ * @ajv
9
+ */
10
+ export declare function Formats(name: string, options?: FormatsOptions): ClassDecorator;
@@ -0,0 +1,12 @@
1
+ import { JsonSchema } from "@tsed/schema";
2
+ import { AnySchemaObject, KeywordDefinition } from "ajv";
3
+ export type KeywordOptions = Partial<Omit<KeywordDefinition, "metaSchema">> & {
4
+ metaSchema?: AnySchemaObject | JsonSchema;
5
+ };
6
+ /**
7
+ * Create new keyword custom validator
8
+ * @param options
9
+ * @decorator
10
+ * @ajv
11
+ */
12
+ export declare function Keyword(options: KeywordOptions): ClassDecorator;
@@ -0,0 +1,6 @@
1
+ import { BadRequest } from "@tsed/exceptions";
2
+ export declare class AjvValidationError extends BadRequest {
3
+ name: string;
4
+ errors: any[];
5
+ constructor(message: string, errors?: any[]);
6
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * @file Automatically generated by @tsed/barrels.
3
+ */
4
+ export * from "./decorators/formats.js";
5
+ export * from "./decorators/keyword.js";
6
+ export * from "./errors/AjvValidationError.js";
7
+ export * from "./interfaces/FormatsMethods.js";
8
+ export * from "./interfaces/IAjvSettings.js";
9
+ export * from "./interfaces/interfaces.js";
10
+ export * from "./interfaces/KeywordMethods.js";
11
+ export * from "./services/Ajv.js";
12
+ export * from "./services/AjvService.js";
13
+ export * from "./utils/defaultErrorFormatter.js";
14
+ export * from "./utils/getPath.js";
@@ -0,0 +1,4 @@
1
+ export interface FormatsMethods<T extends string | number> {
2
+ compare?: (data1: T, data2: T) => number | undefined;
3
+ validate(data: T): boolean;
4
+ }
@@ -0,0 +1,20 @@
1
+ import { ErrorObject, Options } from "ajv";
2
+ /**
3
+ *
4
+ */
5
+ export interface AjvErrorObject extends ErrorObject {
6
+ modelName: string;
7
+ collectionName?: string;
8
+ }
9
+ /**
10
+ *
11
+ */
12
+ export type ErrorFormatter = (error: AjvErrorObject) => string;
13
+ /**
14
+ *
15
+ */
16
+ export interface IAjvSettings extends Options {
17
+ Ajv?: any;
18
+ errorFormatter?: ErrorFormatter;
19
+ returnsCoercedValues?: boolean;
20
+ }
@@ -0,0 +1,23 @@
1
+ import { AnySchemaObject, KeywordCxt, SchemaObjCxt, ValidateFunction } from "ajv";
2
+ export interface AjvDataValidationCtx<T extends string | number = string | number> {
3
+ dataPath: string;
4
+ parentData: {
5
+ [K in T]: any;
6
+ };
7
+ parentDataProperty: T;
8
+ rootData: Record<string, any> | any[];
9
+ dynamicAnchors: {
10
+ [Ref in string]?: ValidateFunction;
11
+ };
12
+ }
13
+ export interface AjvDataValidateFunction {
14
+ (...args: Parameters<ValidateFunction>): boolean | Promise<any>;
15
+ }
16
+ export interface AjvSchemaValidateFunction {
17
+ (schema: any, data: any, parentSchema?: AnySchemaObject, dataCxt?: AjvDataValidationCtx): boolean | Promise<any>;
18
+ }
19
+ export interface KeywordMethods {
20
+ code?: (cxt: KeywordCxt, ruleType?: string) => void;
21
+ compile?: (schema: any, parentSchema: AnySchemaObject, it: SchemaObjCxt) => AjvDataValidateFunction;
22
+ validate?: AjvSchemaValidateFunction | AjvDataValidateFunction;
23
+ }
@@ -0,0 +1,8 @@
1
+ import { IAjvSettings } from "./IAjvSettings.js";
2
+ declare global {
3
+ namespace TsED {
4
+ interface Configuration {
5
+ ajv?: IAjvSettings;
6
+ }
7
+ }
8
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,20 @@
1
+ import { Type } from "@tsed/core";
2
+ import { JsonSchema, JsonSchemaObject } from "@tsed/schema";
3
+ import Ajv, { ErrorObject } from "ajv";
4
+ import { AjvValidationError } from "../errors/AjvValidationError.js";
5
+ import { AjvErrorObject, ErrorFormatter } from "../interfaces/IAjvSettings.js";
6
+ import "./Ajv";
7
+ export interface AjvValidateOptions extends Record<string, any> {
8
+ schema?: JsonSchema | Partial<JsonSchemaObject>;
9
+ type?: Type<any> | any;
10
+ collectionType?: Type<any> | any;
11
+ }
12
+ export declare class AjvService {
13
+ protected errorFormatter: ErrorFormatter;
14
+ protected returnsCoercedValues: boolean;
15
+ protected ajv: Ajv;
16
+ validate(value: any, options: AjvValidateOptions | JsonSchema): Promise<any>;
17
+ protected mapOptions(options: AjvValidateOptions | JsonSchema): AjvValidateOptions;
18
+ protected mapErrors(errors: ErrorObject[], options: any): AjvValidationError;
19
+ protected mapClassError(error: AjvErrorObject, targetType: Type<any>): string | undefined;
20
+ }
@@ -0,0 +1,4 @@
1
+ import { AjvErrorObject } from "../interfaces/IAjvSettings.js";
2
+ export declare function defaultErrorFormatter(error: AjvErrorObject & {
3
+ dataPath: string;
4
+ }): string;
@@ -0,0 +1,2 @@
1
+ export declare function getPath(error: any): string;
2
+ export declare function getInstancePath(error: any): string;
package/package.json CHANGED
@@ -1,22 +1,25 @@
1
1
  {
2
2
  "name": "@tsed/ajv",
3
- "version": "7.79.4",
4
3
  "description": "AJV package for Ts.ED framework",
4
+ "type": "commonjs",
5
+ "version": "7.80.1",
5
6
  "source": "./src/index.ts",
6
7
  "main": "./lib/cjs/index.js",
7
8
  "module": "./lib/esm/index.js",
8
9
  "typings": "./lib/types/index.d.ts",
9
10
  "exports": {
10
- "types": "./lib/types/index.d.ts",
11
- "import": "./lib/esm/index.js",
12
- "require": "./lib/cjs/index.js",
13
- "default": "./lib/esm/index.js"
11
+ ".": {
12
+ "types": "./lib/types/index.d.ts",
13
+ "import": "./lib/esm/index.js",
14
+ "default": "./lib/cjs/index.js"
15
+ }
14
16
  },
15
17
  "scripts": {
16
18
  "build": "yarn barrels && yarn build:ts",
17
19
  "barrels": "barrels",
18
- "test": "jest --max-workers=2 && jest-coverage-thresholds-bumper",
19
- "build:ts": "tsc --build tsconfig.json && tsc --build tsconfig.esm.json"
20
+ "test": "vitest run",
21
+ "build:ts": "tsc --build tsconfig.json",
22
+ "test:ci": "vitest run --coverage.thresholds.autoUpdate=true"
20
23
  },
21
24
  "dependencies": {
22
25
  "ajv-errors": "3.0.0",
@@ -24,21 +27,22 @@
24
27
  "tslib": "2.6.1"
25
28
  },
26
29
  "devDependencies": {
27
- "@tsed/barrels": "7.79.4",
28
- "@tsed/core": "7.79.4",
29
- "@tsed/di": "7.79.4",
30
- "@tsed/exceptions": "7.79.4",
31
- "@tsed/schema": "7.79.4",
32
- "@tsed/typescript": "7.79.4",
30
+ "@tsed/barrels": "7.80.1",
31
+ "@tsed/core": "7.80.1",
32
+ "@tsed/di": "7.80.1",
33
+ "@tsed/exceptions": "7.80.1",
34
+ "@tsed/schema": "7.80.1",
35
+ "@tsed/typescript": "7.80.1",
33
36
  "ajv": "8.12.0",
34
37
  "eslint": "^8.57.0",
35
- "jest": "^29.7.0"
38
+ "typescript": "4.9.5",
39
+ "vitest": "2.0.4"
36
40
  },
37
41
  "peerDependencies": {
38
- "@tsed/core": "7.79.4",
39
- "@tsed/di": "7.79.4",
40
- "@tsed/exceptions": "7.79.4",
41
- "@tsed/schema": "7.79.4",
42
+ "@tsed/core": "7.80.1",
43
+ "@tsed/di": "7.80.1",
44
+ "@tsed/exceptions": "7.80.1",
45
+ "@tsed/schema": "7.80.1",
42
46
  "ajv": ">=8.9.0",
43
47
  "ajv-errors": ">=3.0.0"
44
48
  },
@@ -0,0 +1,21 @@
1
+ // @ts-ignore
2
+ import {presets} from "@tsed/vitest/presets";
3
+ import {defineConfig} from "vitest/config";
4
+
5
+ export default defineConfig(
6
+ {
7
+ ...presets,
8
+ test: {
9
+ ...presets.test,
10
+ coverage: {
11
+ ...presets.test.coverage,
12
+ thresholds: {
13
+ statements: 0,
14
+ branches: 0,
15
+ functions: 0,
16
+ lines: 0
17
+ }
18
+ }
19
+ }
20
+ }
21
+ );
package/jest.config.js DELETED
@@ -1,20 +0,0 @@
1
- // For a detailed explanation regarding each configuration property, visit:
2
- // https://jestjs.io/docs/en/configuration.html
3
-
4
- const config = require("@tsed/jest-config");
5
- module.exports = {
6
- ...config,
7
- roots: ["<rootDir>/src", "<rootDir>/test"],
8
- moduleNameMapper: {
9
- ...config.moduleNameMapper,
10
- "@tsed/ajv": "<rootDir>/src/index.ts"
11
- },
12
- coverageThreshold: {
13
- global: {
14
- branches: 95.89,
15
- functions: 100,
16
- lines: 100,
17
- statements: 100
18
- }
19
- }
20
- };
@@ -1,3 +0,0 @@
1
- {
2
- "type": "commonjs"
3
- }
@@ -1,3 +0,0 @@
1
- {
2
- "type": "module"
3
- }
package/tsconfig.esm.json DELETED
@@ -1,42 +0,0 @@
1
- {
2
- "extends": "@tsed/typescript/tsconfig.node.json",
3
- "compilerOptions": {
4
- "baseUrl": ".",
5
- "module": "ES2020",
6
- "rootDir": "src",
7
- "outDir": "./lib/esm",
8
- "declaration": true,
9
- "declarationDir": "./lib/types",
10
- "composite": true,
11
- "noEmit": false
12
- },
13
- "include": ["src", "src/**/*.json"],
14
- "exclude": [
15
- "node_modules",
16
- "test",
17
- "lib",
18
- "benchmark",
19
- "coverage",
20
- "spec",
21
- "**/*.benchmark.ts",
22
- "**/*.spec.ts",
23
- "keys",
24
- "jest.config.js",
25
- "**/__mock__/**",
26
- "webpack.config.js"
27
- ],
28
- "references": [
29
- {
30
- "path": "../../core"
31
- },
32
- {
33
- "path": "../../di"
34
- },
35
- {
36
- "path": "../exceptions"
37
- },
38
- {
39
- "path": "../schema"
40
- }
41
- ]
42
- }