@automatons/validator 1.0.186 → 2.1.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.
package/index.d.ts CHANGED
@@ -1,3 +1,14 @@
1
- export type { Validate } from './validator';
2
- export { validator } from './validator';
3
- //# sourceMappingURL=index.d.ts.map
1
+ type Validate = {
2
+ keyword: string;
3
+ rule: string;
4
+ location: string;
5
+ };
6
+ declare const validator: (openapi: {
7
+ openapi: string;
8
+ [key: string]: unknown;
9
+ }) => Promise<{
10
+ valid: boolean;
11
+ errors: Validate[];
12
+ }>;
13
+
14
+ export { type Validate, validator };
package/index.js CHANGED
@@ -1,6 +1,26 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validator = void 0;
4
- var validator_1 = require("./validator");
5
- Object.defineProperty(exports, "validator", { enumerable: true, get: function () { return validator_1.validator; } });
1
+ // src/validator.ts
2
+ import { validate as validateOpenapi30 } from "@hyperjump/json-schema/openapi-3-0";
3
+ import { validate as validateOpenapi31 } from "@hyperjump/json-schema/openapi-3-1";
4
+ import { BASIC } from "@hyperjump/json-schema/experimental";
5
+ var dialects = {
6
+ "3_0": { uri: "https://spec.openapis.org/oas/3.0/schema", validate: validateOpenapi30 },
7
+ "3_1": { uri: "https://spec.openapis.org/oas/3.1/schema-base", validate: validateOpenapi31 }
8
+ };
9
+ var validator = async (openapi) => {
10
+ const version = openapi.openapi.split(".").slice(0, 2).join("_");
11
+ const dialect = dialects[version];
12
+ if (!dialect) {
13
+ throw new Error("Not supported version.\nopenapi version 3.0.0 >= version < 3.2.0");
14
+ }
15
+ const output = await dialect.validate(dialect.uri, openapi, BASIC);
16
+ return { valid: output.valid, errors: errorExtractor(output) };
17
+ };
18
+ var errorExtractor = (output) => (output.errors ?? []).map((error) => ({
19
+ keyword: error.keyword?.split("/").pop() ?? "",
20
+ rule: error.absoluteKeywordLocation?.split("#")[1] ?? "",
21
+ location: error.instanceLocation ?? ""
22
+ }));
23
+ export {
24
+ validator
25
+ };
6
26
  //# sourceMappingURL=index.js.map
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AACA,yCAAsC;AAA9B,sGAAA,SAAS,OAAA"}
1
+ {"version":3,"sources":["../src/validator.ts"],"sourcesContent":["import {validate as validateOpenapi30} from \"@hyperjump/json-schema/openapi-3-0\";\nimport {validate as validateOpenapi31} from \"@hyperjump/json-schema/openapi-3-1\";\nimport {BASIC} from \"@hyperjump/json-schema/experimental\";\nimport type {Json} from \"@hyperjump/json-pointer\";\n\nexport type Validate = {\n keyword: string;\n rule: string;\n location: string;\n};\n\ntype OutputUnit = {\n valid: boolean;\n keyword?: string;\n absoluteKeywordLocation?: string;\n instanceLocation?: string;\n errors?: OutputUnit[];\n};\n\nconst dialects = {\n \"3_0\": {uri: \"https://spec.openapis.org/oas/3.0/schema\", validate: validateOpenapi30},\n \"3_1\": {uri: \"https://spec.openapis.org/oas/3.1/schema-base\", validate: validateOpenapi31},\n} as const;\n\nexport const validator = async (openapi: {openapi: string; [key: string]: unknown}) => {\n const version = openapi.openapi.split(\".\").slice(0, 2).join(\"_\");\n const dialect = dialects[version as keyof typeof dialects];\n if (!dialect) {\n throw new Error(\"Not supported version.\\nopenapi version 3.0.0 >= version < 3.2.0\");\n }\n const output = (await dialect.validate(dialect.uri, openapi as unknown as Json, BASIC)) as OutputUnit;\n return {valid: output.valid, errors: errorExtractor(output)};\n};\n\nconst errorExtractor = (output: OutputUnit): Validate[] =>\n (output.errors ?? []).map((error) => ({\n keyword: error.keyword?.split(\"/\").pop() ?? \"\",\n rule: error.absoluteKeywordLocation?.split(\"#\")[1] ?? \"\",\n location: error.instanceLocation ?? \"\",\n }));\n"],"mappings":";AAAA,SAAQ,YAAY,yBAAwB;AAC5C,SAAQ,YAAY,yBAAwB;AAC5C,SAAQ,aAAY;AAiBpB,IAAM,WAAW;AAAA,EACf,OAAO,EAAC,KAAK,4CAA4C,UAAU,kBAAiB;AAAA,EACpF,OAAO,EAAC,KAAK,iDAAiD,UAAU,kBAAiB;AAC3F;AAEO,IAAM,YAAY,OAAO,YAAuD;AACrF,QAAM,UAAU,QAAQ,QAAQ,MAAM,GAAG,EAAE,MAAM,GAAG,CAAC,EAAE,KAAK,GAAG;AAC/D,QAAM,UAAU,SAAS,OAAgC;AACzD,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,kEAAkE;AAAA,EACpF;AACA,QAAM,SAAU,MAAM,QAAQ,SAAS,QAAQ,KAAK,SAA4B,KAAK;AACrF,SAAO,EAAC,OAAO,OAAO,OAAO,QAAQ,eAAe,MAAM,EAAC;AAC7D;AAEA,IAAM,iBAAiB,CAAC,YACrB,OAAO,UAAU,CAAC,GAAG,IAAI,CAAC,WAAW;AAAA,EACpC,SAAS,MAAM,SAAS,MAAM,GAAG,EAAE,IAAI,KAAK;AAAA,EAC5C,MAAM,MAAM,yBAAyB,MAAM,GAAG,EAAE,CAAC,KAAK;AAAA,EACtD,UAAU,MAAM,oBAAoB;AACtC,EAAE;","names":[]}
package/package.json CHANGED
@@ -1,18 +1,31 @@
1
1
  {
2
2
  "name": "@automatons/validator",
3
- "version": "1.0.186",
4
- "main": "index.js",
3
+ "version": "2.1.0",
4
+ "repository": "https://github.com/openapi-automatons/validator.git",
5
5
  "author": "tanmen <yt.prog@gmail.com>",
6
6
  "license": "MIT",
7
+ "packageManager": "yarn@1.22.22",
8
+ "type": "module",
9
+ "main": "index.js",
10
+ "module": "index.js",
11
+ "types": "index.d.ts",
12
+ "exports": {
13
+ ".": {
14
+ "types": "./index.d.ts",
15
+ "import": "./index.js"
16
+ }
17
+ },
18
+ "engines": {
19
+ "node": ">=22"
20
+ },
7
21
  "scripts": {
8
- "prebuild": "depcheck && node scripts/prebuild.js",
9
- "build": "tsc && cp package.json README.md LICENSE dist",
10
- "lint": "eslint src --ext .ts,.tsx",
11
- "test": "jest",
12
- "_postinstall": "husky install && typesync && yarn check --integrity || yarn install --ignore-scripts && yarn-deduplicate",
13
- "prepublishOnly": "pinst --disable",
14
- "postpublish": "pinst --enable",
15
- "postversion": "cp package.json ../package.json"
22
+ "prebuild": "depcheck",
23
+ "build": "tsup && cp package.json README.md LICENSE dist",
24
+ "lint": "eslint src",
25
+ "test": "vitest run",
26
+ "test:watch": "vitest",
27
+ "test:coverage": "vitest run --coverage",
28
+ "prepare": "husky"
16
29
  },
17
30
  "keywords": [
18
31
  "openapi",
@@ -20,34 +33,26 @@
20
33
  "validator"
21
34
  ],
22
35
  "dependencies": {
23
- "@hyperjump/json-schema": "^0.18.5"
36
+ "@hyperjump/browser": "^1",
37
+ "@hyperjump/json-schema": "^1"
24
38
  },
25
39
  "devDependencies": {
26
- "@commitlint/cli": "^17.4.0",
27
- "@commitlint/config-conventional": "^17.4.0",
28
- "@semantic-release/changelog": "^6.0.2",
29
- "@semantic-release/git": "^10.0.0",
30
- "@semantic-release/npm": "^9.0.1",
31
- "@types/eslint": "^8.4.10",
32
- "@types/fs-extra": "^9.0.13",
33
- "@types/jest": "^27.5.0",
34
- "@types/semantic-release": "^17.2.4",
35
- "@typescript-eslint/eslint-plugin": "^5.48.0",
36
- "@typescript-eslint/parser": "^5.48.0",
37
- "cp": "^0.2.0",
38
- "depcheck": "^1.4.3",
39
- "eslint": "^8.31.0",
40
- "eslint-config-google": "^0.14.0",
41
- "fs-extra": "^11.1.0",
42
- "husky": "^8.0.3",
43
- "jest": "^27.5.1",
44
- "lint-staged": "^13.1.0",
45
- "pinst": "^3.0.0",
46
- "semantic-release": "^19.0.5",
47
- "ts-jest": "^27.1.4",
48
- "typescript": "^4.8.4",
49
- "typesync": "^0.9.2",
50
- "yarn-deduplicate": "^6.0.1"
40
+ "@commitlint/cli": "^21.0.2",
41
+ "@commitlint/config-conventional": "^21.0.2",
42
+ "@eslint/js": "^9.39.0",
43
+ "@semantic-release/changelog": "^6.0.3",
44
+ "@semantic-release/git": "^10.0.1",
45
+ "@types/node": "^24.0.0",
46
+ "@vitest/coverage-v8": "^3.2.0",
47
+ "depcheck": "^1.4.7",
48
+ "eslint": "^9.39.0",
49
+ "husky": "^9.1.7",
50
+ "lint-staged": "^17.0.7",
51
+ "semantic-release": "^25.0.3",
52
+ "tsup": "^8.5.0",
53
+ "typescript": "^6.0.3",
54
+ "typescript-eslint": "^8.46.0",
55
+ "vitest": "^3.2.0"
51
56
  },
52
57
  "publishConfig": {
53
58
  "access": "public"
package/index.d.ts.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAC,QAAQ,EAAC,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC"}