@jxsuite/schema 0.29.0 → 0.30.1
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/package.json +3 -3
- package/src/schema.ts +30 -6
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"dependencies": {
|
|
3
|
-
"@webref/css": "^8.
|
|
3
|
+
"@webref/css": "^8.6.0",
|
|
4
4
|
"@webref/elements": "^2.7.1",
|
|
5
|
-
"@webref/idl": "^3.81.
|
|
5
|
+
"@webref/idl": "^3.81.1"
|
|
6
6
|
},
|
|
7
7
|
"description": "JSON Schema 2020-12 meta-schema generator for Jx documents",
|
|
8
8
|
"exports": {
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"upgrade": "bunx npm-check-updates -u && bun install"
|
|
40
40
|
},
|
|
41
41
|
"type": "module",
|
|
42
|
-
"version": "0.
|
|
42
|
+
"version": "0.30.1",
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"json-schema-to-ts": "^3.1.1"
|
|
45
45
|
}
|
package/src/schema.ts
CHANGED
|
@@ -96,7 +96,24 @@ import { projectConfigSchema } from "../defs/project-config.schema";
|
|
|
96
96
|
|
|
97
97
|
// ─── Web standards data loader ────────────────────────────────────────────────
|
|
98
98
|
|
|
99
|
-
|
|
99
|
+
let webDataCache: Promise<{
|
|
100
|
+
cssProps: string[];
|
|
101
|
+
eventHandlers: string[];
|
|
102
|
+
tagExamples: string[];
|
|
103
|
+
}> | null = null;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Web-standards parsing (WebIDL / CSS / HTML elements) is expensive and the data is static for the
|
|
107
|
+
* Process, so memoize it. generateSchema runs several times across a build or test run, and
|
|
108
|
+
* Re-parsing on each call made the validateDocument / CLI tests load-sensitive (occasionally past
|
|
109
|
+
* The 5s test timeout under full-suite CPU contention).
|
|
110
|
+
*/
|
|
111
|
+
function loadWebData() {
|
|
112
|
+
webDataCache ??= computeWebData();
|
|
113
|
+
return webDataCache;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
async function computeWebData() {
|
|
100
117
|
const [elementsData, cssData, idlData] = await Promise.all([
|
|
101
118
|
listElements(),
|
|
102
119
|
css.listAll(),
|
|
@@ -488,7 +505,7 @@ export async function generateSchemaString() {
|
|
|
488
505
|
}
|
|
489
506
|
|
|
490
507
|
// Minimal structural types for the optional `ajv` / `ajv-formats` peer deps
|
|
491
|
-
// (
|
|
508
|
+
// (no direct dependency, and shipping no types usable from here).
|
|
492
509
|
interface AjvValidateFn {
|
|
493
510
|
(doc: unknown): boolean;
|
|
494
511
|
errors?: unknown[] | null;
|
|
@@ -506,8 +523,9 @@ type AddFormatsFn = (ajv: AjvInstance) => void;
|
|
|
506
523
|
export async function validateDocument(doc: Record<string, unknown>) {
|
|
507
524
|
let Ajv: AjvCtor, addFormats: AddFormatsFn;
|
|
508
525
|
try {
|
|
509
|
-
//
|
|
510
|
-
(
|
|
526
|
+
// The generated schema is JSON Schema 2020-12, so use the matching Ajv build
|
|
527
|
+
// (the default `ajv` export is draft-07 and can't compile a 2020-12 schema).
|
|
528
|
+
({ default: Ajv } = (await import("ajv/dist/2020")) as { default: AjvCtor });
|
|
511
529
|
// @ts-expect-error — optional peer dependency
|
|
512
530
|
({ default: addFormats } = (await import("ajv-formats")) as { default: AddFormatsFn });
|
|
513
531
|
} catch {
|
|
@@ -526,11 +544,11 @@ export async function validateDocument(doc: Record<string, unknown>) {
|
|
|
526
544
|
|
|
527
545
|
// ─── CLI ──────────────────────────────────────────────────────────────────────
|
|
528
546
|
|
|
529
|
-
|
|
547
|
+
async function runSchemaCli() {
|
|
530
548
|
const { writeFileSync } = await import("node:fs");
|
|
531
549
|
const { resolve, dirname } = await import("node:path");
|
|
532
550
|
|
|
533
|
-
const schemaDir = dirname(resolve(process.argv[1], ".."));
|
|
551
|
+
const schemaDir = dirname(resolve(process.argv[1] as string, ".."));
|
|
534
552
|
|
|
535
553
|
const componentSchema = await generateSchema();
|
|
536
554
|
const projectSchema = generateProjectSchema();
|
|
@@ -555,3 +573,9 @@ if (process.argv[1] && process.argv[1].endsWith("schema.ts")) {
|
|
|
555
573
|
console.error(" class-schema.json");
|
|
556
574
|
}
|
|
557
575
|
}
|
|
576
|
+
|
|
577
|
+
// Runs when invoked as a script or driven by a test that stages argv[1]. The build lives in an async
|
|
578
|
+
// Function rather than a top-level await: Bun's test runtime drops a dynamically-imported module's
|
|
579
|
+
// Top-level-await continuation on Windows. `ready` lets tests await the same sequence.
|
|
580
|
+
// oxlint-disable-next-line unicorn/prefer-top-level-await
|
|
581
|
+
export const ready = process.argv[1]?.endsWith("schema.ts") ? runSchemaCli() : undefined;
|