@tsed/ajv 8.15.0 → 8.16.0-rc.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.
@@ -1,5 +1,4 @@
1
- import { StoreSet, useDecorators } from "@tsed/core";
2
- import { Injectable } from "@tsed/di";
1
+ import { formats } from "../fn/formats.js";
3
2
  /**
4
3
  * Create a new custom formats validator
5
4
  * @param name
@@ -8,10 +7,7 @@ import { Injectable } from "@tsed/di";
8
7
  * @ajv
9
8
  */
10
9
  export function Formats(name, options = {}) {
11
- return useDecorators(Injectable({
12
- type: "ajv:formats"
13
- }), StoreSet("ajv:formats", {
14
- name,
15
- options
16
- }));
10
+ return (target) => {
11
+ formats(target, name, options);
12
+ };
17
13
  }
@@ -1,5 +1,4 @@
1
- import { StoreSet, useDecorators } from "@tsed/core";
2
- import { Injectable } from "@tsed/di";
1
+ import { keyword } from "../fn/keyword.js";
3
2
  /**
4
3
  * Create new keyword custom validator
5
4
  * @param options
@@ -7,10 +6,7 @@ import { Injectable } from "@tsed/di";
7
6
  * @ajv
8
7
  */
9
8
  export function Keyword(options) {
10
- return useDecorators(Injectable({
11
- type: "ajv:keyword"
12
- }), StoreSet("ajv:keyword", {
13
- ...options,
14
- metaSchema: options.metaSchema && options.metaSchema.toJSON ? options.metaSchema.toJSON() : options.metaSchema
15
- }));
9
+ return (target) => {
10
+ keyword(target, options);
11
+ };
16
12
  }
@@ -0,0 +1,14 @@
1
+ import { injectable } from "@tsed/di";
2
+ /**
3
+ * Create a new custom formats validator
4
+ * @param token
5
+ * @param name
6
+ * @param options
7
+ * @ajv
8
+ */
9
+ export function formats(token, name, options = {}) {
10
+ return injectable(token, { type: "ajv:formats" }).set("ajv:formats", {
11
+ name,
12
+ options
13
+ });
14
+ }
@@ -0,0 +1,16 @@
1
+ import { injectable } from "@tsed/di";
2
+ /**
3
+ * Create a new keyword custom validator
4
+ * @param token
5
+ * @param options
6
+ * @decorator
7
+ * @ajv
8
+ */
9
+ export function keyword(token, options) {
10
+ return injectable(token)
11
+ .type("ajv:keyword")
12
+ .set("ajv:keyword", {
13
+ ...options,
14
+ metaSchema: options.metaSchema && options.metaSchema.toJSON ? options.metaSchema.toJSON() : options.metaSchema
15
+ });
16
+ }
package/lib/esm/index.js CHANGED
@@ -4,9 +4,11 @@
4
4
  export * from "./decorators/formats.js";
5
5
  export * from "./decorators/keyword.js";
6
6
  export * from "./errors/AjvValidationError.js";
7
+ export * from "./fn/formats.js";
8
+ export * from "./fn/keyword.js";
7
9
  export * from "./fn/validate.js";
10
+ export * from "./interfaces/AjvSettings.js";
8
11
  export * from "./interfaces/FormatsMethods.js";
9
- export * from "./interfaces/IAjvSettings.js";
10
12
  export * from "./interfaces/interfaces.js";
11
13
  export * from "./interfaces/KeywordMethods.js";
12
14
  export * from "./services/Ajv.js";
@@ -1,5 +1,4 @@
1
- import { AsyncFormatDefinition, FormatDefinition } from "ajv";
2
- export type FormatsOptions = Omit<FormatDefinition<any>, "validate" | "compare"> | Omit<AsyncFormatDefinition<any>, "validate" | "compare">;
1
+ import { type FormatsOptions } from "../fn/formats.js";
3
2
  /**
4
3
  * Create a new custom formats validator
5
4
  * @param name
@@ -1,8 +1,4 @@
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
- };
1
+ import { type KeywordOptions } from "../fn/keyword.js";
6
2
  /**
7
3
  * Create new keyword custom validator
8
4
  * @param options
@@ -0,0 +1,11 @@
1
+ import { injectable, type TokenProvider } from "@tsed/di";
2
+ import { AsyncFormatDefinition, FormatDefinition } from "ajv";
3
+ export type FormatsOptions = Omit<FormatDefinition<any>, "validate" | "compare"> | Omit<AsyncFormatDefinition<any>, "validate" | "compare">;
4
+ /**
5
+ * Create a new custom formats validator
6
+ * @param token
7
+ * @param name
8
+ * @param options
9
+ * @ajv
10
+ */
11
+ export declare function formats(token: TokenProvider, name: string, options?: FormatsOptions): ReturnType<typeof injectable>;
@@ -0,0 +1,14 @@
1
+ import { injectable, type TokenProvider } from "@tsed/di";
2
+ import { JsonSchema } from "@tsed/schema";
3
+ import type { AnySchemaObject, KeywordDefinition } from "ajv";
4
+ export type KeywordOptions = Partial<Omit<KeywordDefinition, "metaSchema">> & {
5
+ metaSchema?: AnySchemaObject | JsonSchema;
6
+ };
7
+ /**
8
+ * Create a new keyword custom validator
9
+ * @param token
10
+ * @param options
11
+ * @decorator
12
+ * @ajv
13
+ */
14
+ export declare function keyword(token: TokenProvider, options: KeywordOptions): ReturnType<typeof injectable>;
@@ -4,9 +4,11 @@
4
4
  export * from "./decorators/formats.js";
5
5
  export * from "./decorators/keyword.js";
6
6
  export * from "./errors/AjvValidationError.js";
7
+ export * from "./fn/formats.js";
8
+ export * from "./fn/keyword.js";
7
9
  export * from "./fn/validate.js";
10
+ export * from "./interfaces/AjvSettings.js";
8
11
  export * from "./interfaces/FormatsMethods.js";
9
- export * from "./interfaces/IAjvSettings.js";
10
12
  export * from "./interfaces/interfaces.js";
11
13
  export * from "./interfaces/KeywordMethods.js";
12
14
  export * from "./services/Ajv.js";
@@ -13,7 +13,7 @@ export type ErrorFormatter = (error: AjvErrorObject) => string;
13
13
  /**
14
14
  *
15
15
  */
16
- export interface IAjvSettings extends Options {
16
+ export interface AjvSettings extends Options {
17
17
  Ajv?: any;
18
18
  errorFormatter?: ErrorFormatter;
19
19
  returnsCoercedValues?: boolean;
@@ -1,8 +1,8 @@
1
- import { IAjvSettings } from "./IAjvSettings.js";
1
+ import { AjvSettings } from "./AjvSettings.js";
2
2
  declare global {
3
3
  namespace TsED {
4
4
  interface Configuration {
5
- ajv?: IAjvSettings;
5
+ ajv?: AjvSettings;
6
6
  }
7
7
  }
8
8
  }
@@ -3,7 +3,7 @@ import { Type } from "@tsed/core";
3
3
  import { JsonSchema, JsonSchemaObject } from "@tsed/schema";
4
4
  import { Ajv, ErrorObject } from "ajv";
5
5
  import { AjvValidationError } from "../errors/AjvValidationError.js";
6
- import { AjvErrorObject, ErrorFormatter } from "../interfaces/IAjvSettings.js";
6
+ import { AjvErrorObject, ErrorFormatter } from "../interfaces/AjvSettings.js";
7
7
  export interface AjvValidateOptions extends Record<string, any> {
8
8
  schema?: JsonSchema | Partial<JsonSchemaObject>;
9
9
  type?: Type<any> | any;
@@ -1,4 +1,4 @@
1
- import { AjvErrorObject } from "../interfaces/IAjvSettings.js";
1
+ import { AjvErrorObject } from "../interfaces/AjvSettings.js";
2
2
  export declare function defaultErrorFormatter(error: AjvErrorObject & {
3
3
  dataPath: string;
4
4
  }): string;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@tsed/ajv",
3
3
  "description": "AJV package for Ts.ED framework",
4
4
  "type": "module",
5
- "version": "8.15.0",
5
+ "version": "8.16.0-rc.1",
6
6
  "source": "./src/index.ts",
7
7
  "main": "./lib/esm/index.js",
8
8
  "module": "./lib/esm/index.js",
@@ -29,12 +29,12 @@
29
29
  "tslib": "2.7.0"
30
30
  },
31
31
  "devDependencies": {
32
- "@tsed/barrels": "8.15.0",
33
- "@tsed/core": "8.15.0",
34
- "@tsed/di": "8.15.0",
35
- "@tsed/exceptions": "8.15.0",
36
- "@tsed/schema": "8.15.0",
37
- "@tsed/typescript": "8.15.0",
32
+ "@tsed/barrels": "8.16.0-rc.1",
33
+ "@tsed/core": "8.16.0-rc.1",
34
+ "@tsed/di": "8.16.0-rc.1",
35
+ "@tsed/exceptions": "8.16.0-rc.1",
36
+ "@tsed/schema": "8.16.0-rc.1",
37
+ "@tsed/typescript": "8.16.0-rc.1",
38
38
  "ajv": "^8.17.1",
39
39
  "eslint": "9.12.0",
40
40
  "typescript": "5.4.5",
@@ -69,5 +69,8 @@
69
69
  },
70
70
  "homepage": "https://github.com/tsedio/tsed/tree/production/packages/specs/ajv",
71
71
  "author": "Romain Lenzotti",
72
- "license": "MIT"
72
+ "license": "MIT",
73
+ "publishConfig": {
74
+ "tag": "rc"
75
+ }
73
76
  }