schemata-validator 0.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.
Files changed (63) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +119 -0
  3. package/bin/cli.js +5 -0
  4. package/data/classes.json +3748 -0
  5. package/data/properties.json +8274 -0
  6. package/dist/cli.d.ts +4 -0
  7. package/dist/cli.js +24 -0
  8. package/dist/cli.js.map +1 -0
  9. package/dist/constants.d.ts +46 -0
  10. package/dist/constants.js +47 -0
  11. package/dist/constants.js.map +1 -0
  12. package/dist/format-parsers/html-parser.d.ts +15 -0
  13. package/dist/format-parsers/html-parser.js +32 -0
  14. package/dist/format-parsers/html-parser.js.map +1 -0
  15. package/dist/format-parsers/json-ld-parser.d.ts +34 -0
  16. package/dist/format-parsers/json-ld-parser.js +96 -0
  17. package/dist/format-parsers/json-ld-parser.js.map +1 -0
  18. package/dist/index.d.ts +2 -0
  19. package/dist/index.js +3 -0
  20. package/dist/index.js.map +1 -0
  21. package/dist/schemata-validator.d.ts +19 -0
  22. package/dist/schemata-validator.js +69 -0
  23. package/dist/schemata-validator.js.map +1 -0
  24. package/dist/types.d.ts +59 -0
  25. package/dist/types.js +2 -0
  26. package/dist/types.js.map +1 -0
  27. package/dist/utils/browse-folders.d.ts +6 -0
  28. package/dist/utils/browse-folders.js +18 -0
  29. package/dist/utils/browse-folders.js.map +1 -0
  30. package/dist/utils/display-cli-flags.d.ts +5 -0
  31. package/dist/utils/display-cli-flags.js +24 -0
  32. package/dist/utils/display-cli-flags.js.map +1 -0
  33. package/dist/utils/display-reporting.d.ts +7 -0
  34. package/dist/utils/display-reporting.js +38 -0
  35. package/dist/utils/display-reporting.js.map +1 -0
  36. package/dist/utils/dry-run-notice.d.ts +4 -0
  37. package/dist/utils/dry-run-notice.js +8 -0
  38. package/dist/utils/dry-run-notice.js.map +1 -0
  39. package/dist/utils/get-file-content.d.ts +6 -0
  40. package/dist/utils/get-file-content.js +10 -0
  41. package/dist/utils/get-file-content.js.map +1 -0
  42. package/dist/utils/get-files-to-validate.d.ts +9 -0
  43. package/dist/utils/get-files-to-validate.js +37 -0
  44. package/dist/utils/get-files-to-validate.js.map +1 -0
  45. package/dist/utils/parse-args.d.ts +7 -0
  46. package/dist/utils/parse-args.js +47 -0
  47. package/dist/utils/parse-args.js.map +1 -0
  48. package/dist/utils/pattern-to-regex.d.ts +6 -0
  49. package/dist/utils/pattern-to-regex.js +15 -0
  50. package/dist/utils/pattern-to-regex.js.map +1 -0
  51. package/dist/utils/prepare-reporting.d.ts +8 -0
  52. package/dist/utils/prepare-reporting.js +22 -0
  53. package/dist/utils/prepare-reporting.js.map +1 -0
  54. package/dist/utils/show-help.d.ts +4 -0
  55. package/dist/utils/show-help.js +13 -0
  56. package/dist/utils/show-help.js.map +1 -0
  57. package/dist/utils/show-version.d.ts +4 -0
  58. package/dist/utils/show-version.js +8 -0
  59. package/dist/utils/show-version.js.map +1 -0
  60. package/dist/validator/schema-graph-validator.d.ts +46 -0
  61. package/dist/validator/schema-graph-validator.js +164 -0
  62. package/dist/validator/schema-graph-validator.js.map +1 -0
  63. package/package.json +60 -0
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Gets the content of the file.
3
+ * @param file - The file to get the content of.
4
+ * @return The content of the file.
5
+ */
6
+ export declare const getFileContent: (file: string) => string;
@@ -0,0 +1,10 @@
1
+ import fs from "node:fs";
2
+ /**
3
+ * Gets the content of the file.
4
+ * @param file - The file to get the content of.
5
+ * @return The content of the file.
6
+ */
7
+ export const getFileContent = (file) => {
8
+ return fs.readFileSync(file, "utf-8");
9
+ };
10
+ //# sourceMappingURL=get-file-content.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-file-content.js","sourceRoot":"","sources":["../../src/utils/get-file-content.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AAEzB;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,IAAY,EAAU,EAAE;IACrD,OAAO,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AACxC,CAAC,CAAC"}
@@ -0,0 +1,9 @@
1
+ import type { SchemataValidatorOptions } from "../types.js";
2
+ /**
3
+ * Gets the files to validate from the specified options.
4
+ *
5
+ * The `files` option takes precedence over the other options.
6
+ * @param [options] - The options to use.
7
+ * @return An array of the files to validate.
8
+ */
9
+ export declare const getFilesToValidate: (options?: SchemataValidatorOptions) => Promise<string[]>;
@@ -0,0 +1,37 @@
1
+ import fs from "node:fs/promises";
2
+ import path from "node:path";
3
+ import { cwd } from "node:process";
4
+ import { browseFolders } from "./browse-folders.js";
5
+ import { patternToRegex } from "./pattern-to-regex.js";
6
+ /**
7
+ * Gets the files to validate from the specified options.
8
+ *
9
+ * The `files` option takes precedence over the other options.
10
+ * @param [options] - The options to use.
11
+ * @return An array of the files to validate.
12
+ */
13
+ export const getFilesToValidate = async (options = {}) => {
14
+ const { files, paths, exclude } = options;
15
+ if (files)
16
+ return files.map(file => path.resolve(cwd(), file));
17
+ const excludeRegexps = (exclude ?? []).map(patternToRegex);
18
+ const folders = (await browseFolders(cwd())).map(async (folder) => {
19
+ const isFolderExcluded = [...excludeRegexps, /node_modules/].some(regex => regex.test(folder));
20
+ if (isFolderExcluded || (paths && !paths.some(path => folder.startsWith(`${cwd()}/${path}`)))) {
21
+ return [];
22
+ }
23
+ const files = await fs.readdir(folder);
24
+ const filesToValidate = [];
25
+ const extensions = [".html", ".htm"];
26
+ for (const file of files) {
27
+ const fileStat = await fs.stat(path.join(folder, file));
28
+ const isFileExcluded = excludeRegexps.some(regex => regex.test(file));
29
+ if (fileStat.isFile() && extensions.includes(path.extname(file)) && !isFileExcluded) {
30
+ filesToValidate.push(path.join(folder, file));
31
+ }
32
+ }
33
+ return filesToValidate;
34
+ });
35
+ return (await Promise.all(folders)).filter(folder => folder.length).flat();
36
+ };
37
+ //# sourceMappingURL=get-files-to-validate.js.map
@@ -0,0 +1 @@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,GAAG,MAAM,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QACvC,MAAM,eAAe,GAAa,EAAE,CAAC;QACrC,MAAM,UAAU,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QACrC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,MAAM,QAAQ,GAAG,MAAM,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC;YACxD,MAAM,cAAc,GAAG,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;YACtE,IAAI,QAAQ,CAAC,MAAM,EAAE,IAAI,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC;gBACpF,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC;YAChD,CAAC;QACH,CAAC;QACD,OAAO,eAAe,CAAC;IACzB,CAAC,CAAC,CAAC;IACH,OAAO,CAAC,MAAM,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC;AAC7E,CAAC,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { SchemataValidatorOptions } from "../types.js";
2
+ /**
3
+ * Parses the command-line arguments into an object of options.
4
+ * @param args - The command-line arguments to parse.
5
+ * @return An object of options.
6
+ */
7
+ export declare const parseArgs: (args: string[]) => SchemataValidatorOptions;
@@ -0,0 +1,47 @@
1
+ import { AVAILABLE_CLI_FLAGS } from "../constants.js";
2
+ /**
3
+ * Parses the command-line arguments into an object of options.
4
+ * @param args - The command-line arguments to parse.
5
+ * @return An object of options.
6
+ */
7
+ export const parseArgs = (args) => {
8
+ if (args.length) {
9
+ const options = {};
10
+ const flagMap = Object.entries(AVAILABLE_CLI_FLAGS)
11
+ .filter(([key]) => key !== "version" && key !== "help")
12
+ .reduce((map, [key, { flag, alias }]) => {
13
+ if (flag)
14
+ map.set(flag, key);
15
+ if (alias)
16
+ map.set(alias, key);
17
+ return map;
18
+ }, new Map());
19
+ let currentKey = null;
20
+ for (const arg of args) {
21
+ if (arg.startsWith("-")) {
22
+ const isValidKey = flagMap.has(arg);
23
+ if (isValidKey) {
24
+ currentKey = flagMap.get(arg) ?? null;
25
+ if (currentKey) {
26
+ if (currentKey === "dryRun")
27
+ options[currentKey] = true;
28
+ else
29
+ options[currentKey] = [];
30
+ }
31
+ }
32
+ }
33
+ else {
34
+ if (currentKey && currentKey in options) {
35
+ if (currentKey !== "dryRun") {
36
+ const values = options[currentKey] ?? [];
37
+ values.push(arg);
38
+ options[currentKey] = values;
39
+ }
40
+ }
41
+ }
42
+ }
43
+ return options;
44
+ }
45
+ return {};
46
+ };
47
+ //# sourceMappingURL=parse-args.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse-args.js","sourceRoot":"","sources":["../../src/utils/parse-args.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEtD;;;;GAIG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,IAAc,EAA4B,EAAE;IACpE,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;QAChB,MAAM,OAAO,GAA6B,EAAE,CAAC;QAC7C,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,mBAAmB,CAAC;aAChD,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,GAAG,KAAK,SAAS,IAAI,GAAG,KAAK,MAAM,CAAC;aACtD,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC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param pattern - The pattern to convert.
4
+ * @return The regular expression corresponding to the pattern.
5
+ */
6
+ export declare const patternToRegex: (pattern: string) => RegExp;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Converts a pattern with globs to a regular expression.
3
+ * @param pattern - The pattern to convert.
4
+ * @return The regular expression corresponding to the pattern.
5
+ */
6
+ export const patternToRegex = (pattern) => {
7
+ const regex = pattern
8
+ .replace(/\\/g, "\\\\")
9
+ .replace(/\//g, "\\/")
10
+ .replace(/\./g, "\\.")
11
+ .replace(/\*{2}/g, ".*")
12
+ .replace(/(?<!\.)\*/g, "[^/]*");
13
+ return new RegExp(regex);
14
+ };
15
+ //# sourceMappingURL=pattern-to-regex.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pattern-to-regex.js","sourceRoot":"","sources":["../../src/utils/pattern-to-regex.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,OAAe,EAAU,EAAE;IACxD,MAAM,KAAK,GAAG,OAAO;SAClB,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC;SACtB,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC;SACrB,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC;SACrB,OAAO,CAAC,QAAQ,EAAE,IAAI,CAAC;SACvB,OAAO,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;IAClC,OAAO,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC;AAC3B,CAAC,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { ValidationReporting, ValidationResult } from "../types.js";
2
+ /**
3
+ * Prepares the reporting for the given file.
4
+ * @param resource - The resource requested for validation.
5
+ * @param result - The result of the validation.
6
+ * @return The prepared reporting.
7
+ */
8
+ export declare const prepareReporting: (resource: string, result: ValidationResult[]) => ValidationReporting;
@@ -0,0 +1,22 @@
1
+ import { cwd } from "node:process";
2
+ /**
3
+ * Prepares the reporting for the given file.
4
+ * @param resource - The resource requested for validation.
5
+ * @param result - The result of the validation.
6
+ * @return The prepared reporting.
7
+ */
8
+ export const prepareReporting = (resource, result) => {
9
+ const reporting = {
10
+ status: "pass",
11
+ resource: resource.endsWith(".html") ? resource.replace(`${cwd()}/`, "") : resource
12
+ };
13
+ if (result.length) {
14
+ reporting.result = result;
15
+ const hasErrorMessages = result.some(resultItem => resultItem.type === "error");
16
+ if (hasErrorMessages)
17
+ Object.assign(reporting, { status: "fail" });
18
+ return reporting;
19
+ }
20
+ return reporting;
21
+ };
22
+ //# sourceMappingURL=prepare-reporting.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prepare-reporting.js","sourceRoot":"","sources":["../../src/utils/prepare-reporting.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAEnC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC9B,QAAgB,EAChB,MAA0B,EACL,EAAE;IACvB,MAAM,SAAS,GAAwB;QACrC,MAAM,EAAE,MAAM;QACd,QAAQ,EAAE,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,QAAQ;KACpF,CAAC;IACF,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;QAClB,SAAS,CAAC,MAAM,GAAG,MAAM,CAAC;QAC1B,MAAM,gBAAgB,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC;QAChF,IAAI,gBAAgB;YAAE,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;QACnE,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC"}
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Displays the help content for the CLI.
3
+ */
4
+ export declare const showHelp: () => void;
@@ -0,0 +1,13 @@
1
+ import { displayCliFlags } from "./display-cli-flags.js";
2
+ import { TAB, WORKSPACE_NAME } from "../constants.js";
3
+ /**
4
+ * Displays the help content for the CLI.
5
+ */
6
+ export const showHelp = () => {
7
+ const intro = "Checks validity of Schema.org vocabulary";
8
+ const usage = `Usage:\n${TAB}${WORKSPACE_NAME} [flags]`;
9
+ const cliFlags = displayCliFlags();
10
+ const output = [intro, usage, cliFlags].join("\n".repeat(2));
11
+ console.log(output);
12
+ };
13
+ //# sourceMappingURL=show-help.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"show-help.js","sourceRoot":"","sources":["../../src/utils/show-help.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,OAAO,EAAE,GAAG,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEtD;;GAEG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,GAAS,EAAE;IACjC,MAAM,KAAK,GAAG,0CAA0C,CAAC;IACzD,MAAM,KAAK,GAAG,WAAW,GAAG,GAAG,cAAc,UAAU,CAAC;IACxD,MAAM,QAAQ,GAAG,eAAe,EAAE,CAAC;IACnC,MAAM,MAAM,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IAC7D,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;AACtB,CAAC,CAAC"}
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Shows the version of the package.
3
+ */
4
+ export declare const showVersion: () => void;
@@ -0,0 +1,8 @@
1
+ import packageManifest from "../../package.json" with { type: "json" };
2
+ /**
3
+ * Shows the version of the package.
4
+ */
5
+ export const showVersion = () => {
6
+ console.log(packageManifest.version);
7
+ };
8
+ //# sourceMappingURL=show-version.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"show-version.js","sourceRoot":"","sources":["../../src/utils/show-version.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,MAAM,oBAAoB,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AAEvE;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,GAAS,EAAE;IACpC,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;AACvC,CAAC,CAAC"}
@@ -0,0 +1,46 @@
1
+ import type { ClassDefinition, PropertyDefinition, SchemaGraph, SchemaNode, SchemaValue, ValidationResult } from "../types.js";
2
+ export declare class SchemaGraphValidator {
3
+ private readonly schemaGraph;
4
+ /**
5
+ * Constructs an instance of the SchemaGraphValidator class.
6
+ * @param schemaGraph - The schema graph to validate.
7
+ */
8
+ constructor(schemaGraph: SchemaGraph);
9
+ /**
10
+ * Gets the class definition from the type.
11
+ * @param type - The type of the class.
12
+ * @return The class definition if it exists, `null` otherwise.
13
+ */
14
+ getClassDefinition(type: string): ClassDefinition | null;
15
+ /**
16
+ * Gets the property definition from the property.
17
+ *
18
+ * When the property is `id`, the definition is always returned.
19
+ * @param property - The property.
20
+ * @return The property definition if it exists, `null` otherwise.
21
+ */
22
+ getPropertyDefinition(property: string): PropertyDefinition | null;
23
+ /**
24
+ * Gets the extended classes from the type.
25
+ * @param type - The type of the class.
26
+ * @return An array of extended classes if they exist, `null` otherwise.
27
+ */
28
+ getExtendedClasses(type: string): string[] | null;
29
+ /**
30
+ * Validates the schema values.
31
+ * @param property - The property name.
32
+ * @param schemaValues - The schema values to validate.
33
+ * @return An array of validation reports.
34
+ */
35
+ validateValues(property: string, schemaValues: SchemaValue[]): ValidationResult[];
36
+ /**
37
+ * Validates the schema node.
38
+ * @param node - The schema node to validate.
39
+ * @return An array of validation reports.
40
+ */
41
+ validateNode(node: SchemaNode): ValidationResult[];
42
+ /**
43
+ * Validates the schema graph.
44
+ */
45
+ validate(): ValidationResult[];
46
+ }
@@ -0,0 +1,164 @@
1
+ import classes from "../../data/classes.json" with { type: "json" };
2
+ import properties from "../../data/properties.json" with { type: "json" };
3
+ export class SchemaGraphValidator {
4
+ schemaGraph;
5
+ /**
6
+ * Constructs an instance of the SchemaGraphValidator class.
7
+ * @param schemaGraph - The schema graph to validate.
8
+ */
9
+ constructor(schemaGraph) {
10
+ this.schemaGraph = schemaGraph;
11
+ }
12
+ /**
13
+ * Gets the class definition from the type.
14
+ * @param type - The type of the class.
15
+ * @return The class definition if it exists, `null` otherwise.
16
+ */
17
+ getClassDefinition(type) {
18
+ if (type in classes)
19
+ return classes[type];
20
+ return null;
21
+ }
22
+ /**
23
+ * Gets the property definition from the property.
24
+ *
25
+ * When the property is `id`, the definition is always returned.
26
+ * @param property - The property.
27
+ * @return The property definition if it exists, `null` otherwise.
28
+ */
29
+ getPropertyDefinition(property) {
30
+ if (property === "id")
31
+ return { isPending: false };
32
+ if (property in properties)
33
+ return properties[property];
34
+ return null;
35
+ }
36
+ /**
37
+ * Gets the extended classes from the type.
38
+ * @param type - The type of the class.
39
+ * @return An array of extended classes if they exist, `null` otherwise.
40
+ */
41
+ getExtendedClasses(type) {
42
+ const classesSet = new Set();
43
+ const classDefinition = this.getClassDefinition(type);
44
+ if (classDefinition) {
45
+ const { extends: extendsClasses } = classDefinition;
46
+ if (extendsClasses) {
47
+ for (const className of extendsClasses) {
48
+ classesSet.add(className);
49
+ const extendedClasses = this.getExtendedClasses(className);
50
+ if (extendedClasses) {
51
+ for (const extendedClass of extendedClasses) {
52
+ classesSet.add(extendedClass);
53
+ }
54
+ }
55
+ }
56
+ }
57
+ return [...classesSet];
58
+ }
59
+ return null;
60
+ }
61
+ /**
62
+ * Validates the schema values.
63
+ * @param property - The property name.
64
+ * @param schemaValues - The schema values to validate.
65
+ * @return An array of validation reports.
66
+ */
67
+ validateValues(property, schemaValues) {
68
+ const result = [];
69
+ const propertyDefinition = this.getPropertyDefinition(property);
70
+ for (const schemaValue of schemaValues) {
71
+ const { kind } = schemaValue;
72
+ const jsonLDPath = kind === "node" ? schemaValue.linkLocation.jsonLDPath : schemaValue.location.jsonLDPath;
73
+ if (propertyDefinition) {
74
+ const { isPending, supersededBy } = propertyDefinition;
75
+ if (supersededBy) {
76
+ result.push({
77
+ type: "error",
78
+ path: jsonLDPath ?? "",
79
+ message: `The property \`${property}\` has been superseded: use \`${supersededBy}\` instead.`
80
+ });
81
+ }
82
+ if (isPending) {
83
+ result.push({
84
+ type: "warning",
85
+ path: jsonLDPath ?? "",
86
+ message: `The property \`${property}\` is part of terms which are not yet part of the Schema.org vocabulary. Pending terms are subject to change and should be used with caution.`
87
+ });
88
+ }
89
+ if (kind === "node") {
90
+ const { node } = schemaValue;
91
+ const { type } = node;
92
+ const { type: typesInPropertyDefinition } = propertyDefinition;
93
+ const extendsTypes = this.getExtendedClasses(type)?.some(className => typesInPropertyDefinition?.includes(className));
94
+ if (!typesInPropertyDefinition?.includes(type) && !extendsTypes) {
95
+ result.push({
96
+ type: "error",
97
+ path: jsonLDPath ?? "",
98
+ message: `\`${type}\` is not a valid type for the property \`${property}\`.`
99
+ });
100
+ }
101
+ result.push(...this.validateNode(node));
102
+ }
103
+ }
104
+ else {
105
+ result.push({
106
+ type: "error",
107
+ path: jsonLDPath ?? "",
108
+ message: `The property \`${property}\` does not exist in the Schema.org vocabulary.`
109
+ });
110
+ }
111
+ }
112
+ return result;
113
+ }
114
+ /**
115
+ * Validates the schema node.
116
+ * @param node - The schema node to validate.
117
+ * @return An array of validation reports.
118
+ */
119
+ validateNode(node) {
120
+ const { type, location: { jsonLDPath }, properties } = node;
121
+ const result = [];
122
+ const classDefinition = this.getClassDefinition(type);
123
+ if (classDefinition) {
124
+ const { isPending, supersededBy } = classDefinition;
125
+ if (supersededBy) {
126
+ result.push({
127
+ type: "error",
128
+ path: jsonLDPath ?? "",
129
+ message: `The type \`${type}\` has been superseded: use \`${supersededBy}\` instead.`
130
+ });
131
+ }
132
+ if (isPending) {
133
+ result.push({
134
+ type: "warning",
135
+ path: jsonLDPath ?? "",
136
+ message: `The type \`${type}\` is part of terms which are not yet part of the Schema.org vocabulary. Pending terms are subject to change and should be used with caution.`
137
+ });
138
+ }
139
+ for (const [property, schemaValues] of properties) {
140
+ result.push(...this.validateValues(property, schemaValues));
141
+ }
142
+ }
143
+ else {
144
+ result.push({
145
+ type: "error",
146
+ path: jsonLDPath ?? "",
147
+ message: `The type \`${type}\` does not exist in the Schema.org vocabulary.`
148
+ });
149
+ }
150
+ return result;
151
+ }
152
+ /**
153
+ * Validates the schema graph.
154
+ */
155
+ validate() {
156
+ const { roots } = this.schemaGraph;
157
+ const result = [];
158
+ for (const root of roots) {
159
+ result.push(...this.validateNode(root));
160
+ }
161
+ return result;
162
+ }
163
+ }
164
+ //# sourceMappingURL=schema-graph-validator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema-graph-validator.js","sourceRoot":"","sources":["../../src/validator/schema-graph-validator.ts"],"names":[],"mappings":"AASA,OAAO,OAAO,MAAM,yBAAyB,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AACpE,OAAO,UAAU,MAAM,4BAA4B,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AAE1E,MAAM,OAAO,oBAAoB;IACd,WAAW,CAAc;IAE1C;;;OAGG;IACH,YAAY,WAAwB;QAClC,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IACjC,CAAC;IAED;;;;OAIG;IACH,kBAAkB,CAAC,IAAY;QAC7B,IAAI,IAAI,IAAI,OAAO;YAAE,OAAO,OAAO,CAAC,IAA4B,CAAC,CAAC;QAClE,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;;OAMG;IACH,qBAAqB,CAAC,QAAgB;QACpC,IAAI,QAAQ,KAAK,IAAI;YAAE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;QACnD,IAAI,QAAQ,IAAI,UAAU;YAAE,OAAO,UAAU,CAAC,QAAmC,CAAC,CAAC;QACnF,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QACL,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IAED;;OAEG;IACH,QAAQ;QACN,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,WAAW,CAAC;QACnC,MAAM,MAAM,GAAuB,EAAE,CAAC;QACtC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC;QAC1C,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF"}
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "schemata-validator",
3
+ "version": "0.1.0",
4
+ "description": "Check the validity of Schema.org vocabulary used in JSON-LD data",
5
+ "keywords": [
6
+ "json-ld",
7
+ "schema-org",
8
+ "web-semantic",
9
+ "validator"
10
+ ],
11
+ "homepage": "https://github.com/webdevbynight/schemata-validator",
12
+ "bugs": {
13
+ "url": "https://github.com/webdevbynight/schemata-validator/issues"
14
+ },
15
+ "author": "Victor Brito (https://victor-brito.dev)",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/webdevbynight/schemata-validator.git"
19
+ },
20
+ "type": "module",
21
+ "license": "MIT",
22
+ "files": [
23
+ "data",
24
+ "dist"
25
+ ],
26
+ "exports": {
27
+ "import": "./dist/index.js",
28
+ "types": "./dist/index.d.ts"
29
+ },
30
+ "bin": {
31
+ "schemata-validator": "./bin/cli.js"
32
+ },
33
+ "engines": {
34
+ "node": "^20.18.3 || ^22.12.0 || ^24.0.0",
35
+ "npm": ">=10.8.2",
36
+ "pnpm": ">=10.32.1"
37
+ },
38
+ "devDependencies": {
39
+ "@biomejs/biome": "2.4.8",
40
+ "@commitlint/cli": "20.5.0",
41
+ "@commitlint/config-conventional": "20.5.0",
42
+ "@types/node": "24.12.0",
43
+ "husky": "9.1.7",
44
+ "typescript": "5.9.3",
45
+ "vitest": "4.1.0"
46
+ },
47
+ "scripts": {
48
+ "biome": "biome check --write .",
49
+ "biome:check": "biome check .",
50
+ "biome:format": "biome format --write .",
51
+ "biome:format:check": "biome format .",
52
+ "biome:lint": "biome lint --write .",
53
+ "biome:lint:check": "biome lint .",
54
+ "build": "tsc",
55
+ "dev": "pnpm tsc:watch & pnpm test:watch",
56
+ "test": "vitest run",
57
+ "test:watch": "vitest",
58
+ "tsc:watch": "tsc --watch --preserveWatchOutput"
59
+ }
60
+ }