@unispechq/unispec-core 0.2.9 → 0.2.11
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/diff/index.js +18 -5
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/loader/index.js +61 -6
- package/dist/cjs/normalizer/index.js +16 -2
- package/dist/cjs/schemas/index.js +131 -0
- package/dist/cjs/validator/generated-schemas.js +819 -0
- package/dist/cjs/validator/index.js +5 -82
- package/dist/diff/index.d.ts +18 -5
- package/dist/diff/index.js +18 -5
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/loader/index.d.ts +3 -4
- package/dist/loader/index.js +28 -6
- package/dist/normalizer/index.d.ts +16 -2
- package/dist/normalizer/index.js +16 -2
- package/dist/schemas/index.d.ts +4 -0
- package/dist/schemas/index.js +126 -0
- package/dist/validator/generated-schemas.d.ts +832 -0
- package/dist/validator/generated-schemas.js +816 -0
- package/dist/validator/index.js +5 -49
- package/package.json +8 -3
package/dist/validator/index.js
CHANGED
|
@@ -1,56 +1,12 @@
|
|
|
1
1
|
import Ajv2020 from "ajv/dist/2020.js";
|
|
2
|
+
import { GENERATED_SCHEMAS } from "./generated-schemas.js";
|
|
2
3
|
let cached = null;
|
|
3
|
-
async function tryCreateNodeSchemaProvider() {
|
|
4
|
-
try {
|
|
5
|
-
const fs = await import("node:fs/promises");
|
|
6
|
-
const path = await import("node:path");
|
|
7
|
-
const module = await import("node:module");
|
|
8
|
-
const requireBasePath = typeof __filename === "string" && __filename.length > 0
|
|
9
|
-
? __filename
|
|
10
|
-
: path.join(process.cwd(), "__unispec_core_require__.js");
|
|
11
|
-
const require = module.createRequire(requireBasePath);
|
|
12
|
-
const schemaIndexPath = require.resolve("@unispechq/unispec-schema/schema");
|
|
13
|
-
const schemaRoot = path.dirname(schemaIndexPath);
|
|
14
|
-
return {
|
|
15
|
-
getSchema: async (schemaPath) => {
|
|
16
|
-
const fullPath = path.join(schemaRoot, schemaPath);
|
|
17
|
-
const json = await fs.readFile(fullPath, "utf8");
|
|
18
|
-
return JSON.parse(json);
|
|
19
|
-
},
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
catch {
|
|
23
|
-
return undefined;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
4
|
async function loadDefaultSchemas() {
|
|
27
|
-
|
|
28
|
-
if (!schemaProvider) {
|
|
29
|
-
throw new Error("UniSpec validator: default schema loading is not available in this environment. " +
|
|
30
|
-
"Provide ValidateOptions.schemas (recommended for browsers/edge runtimes) or ValidateOptions.schemaProvider.");
|
|
31
|
-
}
|
|
32
|
-
const { manifest, unispec } = (await import("@unispechq/unispec-schema"));
|
|
33
|
-
const types = manifest?.types ?? {};
|
|
34
|
-
const typeSchemaPaths = Object.values(types).map((rel) => String(rel));
|
|
35
|
-
const subschemas = await Promise.all(typeSchemaPaths.map(async (relPath) => {
|
|
36
|
-
try {
|
|
37
|
-
return await schemaProvider.getSchema(relPath);
|
|
38
|
-
}
|
|
39
|
-
catch {
|
|
40
|
-
return null;
|
|
41
|
-
}
|
|
42
|
-
}));
|
|
43
|
-
let unispecTests;
|
|
44
|
-
try {
|
|
45
|
-
unispecTests = await schemaProvider.getSchema("unispec-tests.schema.json");
|
|
46
|
-
}
|
|
47
|
-
catch {
|
|
48
|
-
unispecTests = undefined;
|
|
49
|
-
}
|
|
5
|
+
// Always use generated schemas - they work in all environments
|
|
50
6
|
return {
|
|
51
|
-
unispec: unispec,
|
|
52
|
-
unispecTests,
|
|
53
|
-
subschemas: subschemas
|
|
7
|
+
unispec: GENERATED_SCHEMAS.unispec,
|
|
8
|
+
unispecTests: GENERATED_SCHEMAS.unispecTests,
|
|
9
|
+
subschemas: GENERATED_SCHEMAS.subschemas,
|
|
54
10
|
};
|
|
55
11
|
}
|
|
56
12
|
function createAjv(options) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unispechq/unispec-core",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.11",
|
|
4
4
|
"description": "Central UniSpec Core Engine providing parsing, validation, normalization, diffing, and conversion of UniSpec specs.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -39,19 +39,24 @@
|
|
|
39
39
|
"README.md"
|
|
40
40
|
],
|
|
41
41
|
"scripts": {
|
|
42
|
-
"build": "npm run build:esm && npm run build:cjs",
|
|
42
|
+
"build": "npm run generate-schemas && npm run build:esm && npm run build:cjs",
|
|
43
43
|
"build:esm": "tsc -p tsconfig.json",
|
|
44
44
|
"build:cjs": "tsc -p tsconfig.cjs.json && node scripts/postbuild-cjs.cjs",
|
|
45
|
+
"generate-schemas": "node scripts/generate-schemas.mjs",
|
|
45
46
|
"test": "npm run build && node --test tests/*.test.mjs",
|
|
46
47
|
"release:patch": "node scripts/release.js patch",
|
|
47
48
|
"release:minor": "node scripts/release.js minor",
|
|
48
49
|
"release:major": "node scripts/release.js major"
|
|
49
50
|
},
|
|
50
51
|
"dependencies": {
|
|
51
|
-
"@unispechq/unispec-schema": "^0.3.
|
|
52
|
+
"@unispechq/unispec-schema": "^0.3.4",
|
|
52
53
|
"ajv": "^8.12.0"
|
|
53
54
|
},
|
|
55
|
+
"optionalDependencies": {
|
|
56
|
+
"js-yaml": "^4.1.0"
|
|
57
|
+
},
|
|
54
58
|
"devDependencies": {
|
|
59
|
+
"@types/js-yaml": "^4.0.5",
|
|
55
60
|
"@types/node": "^24.10.1",
|
|
56
61
|
"typescript": "^5.0.0"
|
|
57
62
|
},
|