@onereach/state-machine-validation-ajv 1.0.0-framework.2
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.
- package/README.md +3 -0
- package/dist/index.d.mts +16 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +46 -0
package/README.md
ADDED
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Ajv } from "ajv";
|
|
2
|
+
import { JsonSchema, JsonSchemaValidatorCompiler, SchemaValidator } from "@onereach/state-machine-core";
|
|
3
|
+
//#region src/compiler/types.d.ts
|
|
4
|
+
interface AjvJsonSchemaValidatorCompilerOptions {
|
|
5
|
+
ajv?: Ajv;
|
|
6
|
+
}
|
|
7
|
+
//#endregion
|
|
8
|
+
//#region src/compiler/compiler.d.ts
|
|
9
|
+
declare class AjvJsonSchemaValidatorCompiler implements JsonSchemaValidatorCompiler {
|
|
10
|
+
private readonly ajv;
|
|
11
|
+
constructor(options?: AjvJsonSchemaValidatorCompilerOptions);
|
|
12
|
+
compile<T = unknown>(schema: JsonSchema): SchemaValidator<T>;
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
export { AjvJsonSchemaValidatorCompiler, type AjvJsonSchemaValidatorCompilerOptions };
|
|
16
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/compiler/types.ts","../src/compiler/compiler.ts"],"mappings":";;;UAEiB;EACf,MAAM;;;;cCIK,0CAA0C;mBACpC;EAEL,YAAA,UAAS;EASd,QAAQ,aAAa,QAAQ,aAAa,gBAAgB"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{Ajv as e}from"ajv";var t=class{lastIssues=[];validator;constructor(e){this.validator=e}validate(e){let t=this.validator(e);return this.lastIssues=t?[]:n(this.validator.errors),t}get issues(){return this.lastIssues}};function n(e){return e?e.map(e=>({path:e.instancePath,message:e.message,keyword:e.keyword,schemaPath:e.schemaPath,params:e.params})):[]}var r=class{ajv;constructor(t={}){this.ajv=t.ajv??new e({allErrors:!0,strict:!0})}compile(e){return new t(this.ajv.compile(e))}};export{r as AjvJsonSchemaValidatorCompiler};
|
|
2
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/validator/validator.ts","../src/compiler/compiler.ts"],"sourcesContent":["import type { SchemaValidationIssue, SchemaValidator } from '@onereach/state-machine-core';\nimport type { ErrorObject, ValidateFunction } from 'ajv';\n\n/*\n--------------------------------------------------------------------------\n*/\n/*\nAJV validator wrapper\n*/\n/*\n--------------------------------------------------------------------------\n*/\n\nexport class AjvSchemaValidator<T = unknown> implements SchemaValidator<T> {\n private lastIssues: readonly SchemaValidationIssue[] = [];\n private readonly validator: ValidateFunction<T>;\n\n constructor(validator: ValidateFunction<T>) {\n this.validator = validator;\n }\n\n validate(value: unknown): value is T {\n const isValid = this.validator(value);\n\n this.lastIssues = isValid ? [] : normalizeErrors(this.validator.errors);\n\n return isValid;\n }\n\n get issues(): readonly SchemaValidationIssue[] {\n return this.lastIssues;\n }\n}\n\n/*\n--------------------------------------------------------------------------\n*/\n/*\nError normalization\n*/\n/*\n--------------------------------------------------------------------------\n*/\n\nfunction normalizeErrors(errors: ErrorObject[] | null | undefined): readonly SchemaValidationIssue[] {\n if (!errors) return [];\n\n return errors.map((error) => ({\n path: error.instancePath,\n message: error.message,\n keyword: error.keyword,\n schemaPath: error.schemaPath,\n params: error.params,\n }));\n}\n","import type { JsonSchema, JsonSchemaValidatorCompiler, SchemaValidator } from '@onereach/state-machine-core';\nimport { Ajv } from 'ajv';\n\nimport { AjvSchemaValidator } from '../validator/validator.ts';\n\nimport type { AjvJsonSchemaValidatorCompilerOptions } from './types.ts';\n\nexport class AjvJsonSchemaValidatorCompiler implements JsonSchemaValidatorCompiler {\n private readonly ajv: Ajv;\n\n constructor(options: AjvJsonSchemaValidatorCompilerOptions = {}) {\n this.ajv =\n options.ajv ??\n new Ajv({\n allErrors: true,\n strict: true,\n });\n }\n\n public compile<T = unknown>(schema: JsonSchema): SchemaValidator<T> {\n return new AjvSchemaValidator<T>(this.ajv.compile<T>(schema));\n }\n}\n"],"mappings":"0BAaA,IAAa,EAAb,KAA2E,CACzE,WAAuD,CAAC,EACxD,UAEA,YAAY,EAAgC,CAC1C,KAAK,UAAY,CACnB,CAEA,SAAS,EAA4B,CACnC,IAAM,EAAU,KAAK,UAAU,CAAK,EAIpC,MAFA,MAAK,WAAa,EAAU,CAAC,EAAI,EAAgB,KAAK,UAAU,MAAM,EAE/D,CACT,CAEA,IAAI,QAA2C,CAC7C,OAAO,KAAK,UACd,CACF,EAYA,SAAS,EAAgB,EAA4E,CAGnG,OAFK,EAEE,EAAO,IAAK,IAAW,CAC5B,KAAM,EAAM,aACZ,QAAS,EAAM,QACf,QAAS,EAAM,QACf,WAAY,EAAM,WAClB,OAAQ,EAAM,MAChB,EAAE,EARkB,CAAC,CASvB,CC/CA,IAAa,EAAb,KAAmF,CACjF,IAEA,YAAY,EAAiD,CAAC,EAAG,CAC/D,KAAK,IACH,EAAQ,KACR,IAAI,EAAI,CACN,UAAW,GACX,OAAQ,EACV,CAAC,CACL,CAEA,QAA4B,EAAwC,CAClE,OAAO,IAAI,EAAsB,KAAK,IAAI,QAAW,CAAM,CAAC,CAC9D,CACF"}
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@onereach/state-machine-validation-ajv",
|
|
3
|
+
"version": "1.0.0-framework.2",
|
|
4
|
+
"description": "State Machine template validation using AJV",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"onereach",
|
|
7
|
+
"toolkit",
|
|
8
|
+
"state-machine"
|
|
9
|
+
],
|
|
10
|
+
"author": "OneReach Development Team <dev.team@onereach.ai>",
|
|
11
|
+
"license": "Apache-2.0",
|
|
12
|
+
"type": "module",
|
|
13
|
+
"publishConfig": {
|
|
14
|
+
"access": "public"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"!dist/metafile*.json"
|
|
19
|
+
],
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@arethetypeswrong/core": "^0.18.5",
|
|
22
|
+
"@types/source-map-support": "^0.5.10",
|
|
23
|
+
"publint": "^0.3.24",
|
|
24
|
+
"rollup-plugin-visualizer": "^7.1.1",
|
|
25
|
+
"tsdown": "^0.22.14",
|
|
26
|
+
"typescript": "^6.0.3"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@onereach/state-machine-core": "1.0.0-framework.2",
|
|
30
|
+
"ajv": "^8.20.0"
|
|
31
|
+
},
|
|
32
|
+
"exports": {
|
|
33
|
+
".": "./dist/index.mjs",
|
|
34
|
+
"./package.json": "./package.json"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "tsdown --config tsdown.config.mts",
|
|
38
|
+
"build:visualize": "VISUALIZE=1 pnpm build",
|
|
39
|
+
"typecheck": "tsc --noEmit",
|
|
40
|
+
"preversion_": "pnpm build && pnpm test",
|
|
41
|
+
"publish:rc": "pnpm version prerelease --preid rc && pnpm publish --tag rc",
|
|
42
|
+
"test": "pnpm run unit",
|
|
43
|
+
"unit": "vitest run",
|
|
44
|
+
"preversion": "pnpm build"
|
|
45
|
+
}
|
|
46
|
+
}
|