@unispechq/unispec-core 0.2.5 → 0.2.6
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/dist/cjs/validator/index.js +19 -3
- package/dist/validator/index.js +19 -3
- package/package.json +1 -1
|
@@ -27,11 +27,26 @@ function getThisModuleUrl() {
|
|
|
27
27
|
throw new Error("Cannot determine current module URL for createRequire()");
|
|
28
28
|
}
|
|
29
29
|
function getLocalRequire() {
|
|
30
|
-
if (typeof require !== "undefined") {
|
|
31
|
-
return require;
|
|
32
|
-
}
|
|
33
30
|
return (0, module_1.createRequire)(getThisModuleUrl());
|
|
34
31
|
}
|
|
32
|
+
function assertValidSchemaDir(schemaDir) {
|
|
33
|
+
const requiredFiles = [
|
|
34
|
+
path_1.default.join(schemaDir, "types", "service.schema.json"),
|
|
35
|
+
path_1.default.join(schemaDir, "unispec-tests.schema.json"),
|
|
36
|
+
];
|
|
37
|
+
const missing = requiredFiles.filter((p) => !fs_1.default.existsSync(p));
|
|
38
|
+
if (missing.length === 0) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const hints = [
|
|
42
|
+
`UniSpec schema directory is invalid or incomplete: ${schemaDir}`,
|
|
43
|
+
`Missing schema files:`,
|
|
44
|
+
...missing.map((p) => `- ${p}`),
|
|
45
|
+
`You can override the schema directory via ValidateOptions.schemaDir or UNISPEC_SCHEMA_DIR env var.`,
|
|
46
|
+
`In bundled environments (e.g. Next.js), module resolution can be altered; make sure @unispechq/unispec-schema is installed and accessible at runtime.`,
|
|
47
|
+
];
|
|
48
|
+
throw new Error(hints.join("\n"));
|
|
49
|
+
}
|
|
35
50
|
function findPackageRoot(startFilePath) {
|
|
36
51
|
let dir = path_1.default.dirname(startFilePath);
|
|
37
52
|
for (let i = 0; i < 50; i++) {
|
|
@@ -66,6 +81,7 @@ function getUniSpecSchemaDir(options = {}) {
|
|
|
66
81
|
const validatorCache = new Map();
|
|
67
82
|
function getCompiledValidator(options = {}) {
|
|
68
83
|
const schemaDir = getUniSpecSchemaDir(options);
|
|
84
|
+
assertValidSchemaDir(schemaDir);
|
|
69
85
|
const cached = validatorCache.get(schemaDir);
|
|
70
86
|
if (cached) {
|
|
71
87
|
return cached;
|
package/dist/validator/index.js
CHANGED
|
@@ -20,11 +20,26 @@ function getThisModuleUrl() {
|
|
|
20
20
|
throw new Error("Cannot determine current module URL for createRequire()");
|
|
21
21
|
}
|
|
22
22
|
function getLocalRequire() {
|
|
23
|
-
if (typeof require !== "undefined") {
|
|
24
|
-
return require;
|
|
25
|
-
}
|
|
26
23
|
return createRequire(getThisModuleUrl());
|
|
27
24
|
}
|
|
25
|
+
function assertValidSchemaDir(schemaDir) {
|
|
26
|
+
const requiredFiles = [
|
|
27
|
+
path.join(schemaDir, "types", "service.schema.json"),
|
|
28
|
+
path.join(schemaDir, "unispec-tests.schema.json"),
|
|
29
|
+
];
|
|
30
|
+
const missing = requiredFiles.filter((p) => !fs.existsSync(p));
|
|
31
|
+
if (missing.length === 0) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const hints = [
|
|
35
|
+
`UniSpec schema directory is invalid or incomplete: ${schemaDir}`,
|
|
36
|
+
`Missing schema files:`,
|
|
37
|
+
...missing.map((p) => `- ${p}`),
|
|
38
|
+
`You can override the schema directory via ValidateOptions.schemaDir or UNISPEC_SCHEMA_DIR env var.`,
|
|
39
|
+
`In bundled environments (e.g. Next.js), module resolution can be altered; make sure @unispechq/unispec-schema is installed and accessible at runtime.`,
|
|
40
|
+
];
|
|
41
|
+
throw new Error(hints.join("\n"));
|
|
42
|
+
}
|
|
28
43
|
function findPackageRoot(startFilePath) {
|
|
29
44
|
let dir = path.dirname(startFilePath);
|
|
30
45
|
for (let i = 0; i < 50; i++) {
|
|
@@ -59,6 +74,7 @@ function getUniSpecSchemaDir(options = {}) {
|
|
|
59
74
|
const validatorCache = new Map();
|
|
60
75
|
function getCompiledValidator(options = {}) {
|
|
61
76
|
const schemaDir = getUniSpecSchemaDir(options);
|
|
77
|
+
assertValidSchemaDir(schemaDir);
|
|
62
78
|
const cached = validatorCache.get(schemaDir);
|
|
63
79
|
if (cached) {
|
|
64
80
|
return cached;
|
package/package.json
CHANGED