@shlomoa/openui-spec 0.1.1 → 0.2.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/README.md +3 -1
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +9 -6
- package/package.json +1 -1
- package/spec/openui.json +1 -1
package/README.md
CHANGED
|
@@ -9,13 +9,15 @@ This repository contains a technology-independent specification for a Web UI fra
|
|
|
9
9
|
Contributor and developer entry points for this repository:
|
|
10
10
|
|
|
11
11
|
- [Contributing guide](CONTRIBUTING.md) — local setup and validation basics.
|
|
12
|
+
- [Changelog](CHANGELOG.md) — release notes, breaking changes, and upgrade guidance.
|
|
12
13
|
|
|
13
14
|
## OpenUI JSON API
|
|
14
15
|
|
|
15
16
|
The [`@shlomoa/openui-spec`](package.json) package provides `OpenUiJson` for
|
|
16
17
|
loading, validating, and editing an OpenUI JSON document. It bundles
|
|
17
18
|
`spec/openui.schema.json` and `spec/openui.json`; validation checks both the
|
|
18
|
-
schema and
|
|
19
|
+
schema and exact [known object type](spec/README.md#known-object-type)
|
|
20
|
+
membership in the canonical catalog.
|
|
19
21
|
|
|
20
22
|
```bash
|
|
21
23
|
npm install @shlomoa/openui-spec
|
package/dist/src/index.d.ts
CHANGED
package/dist/src/index.js
CHANGED
|
@@ -77,15 +77,15 @@ class OpenUiJson {
|
|
|
77
77
|
if (!validator(this.document)) {
|
|
78
78
|
throw new OpenUiValidationError(formatValidationErrors(validator.errors));
|
|
79
79
|
}
|
|
80
|
-
const
|
|
80
|
+
const knownTypes = this.catalogTypes(catalog);
|
|
81
81
|
const seenIds = new Set();
|
|
82
82
|
for (const node of this.walk(this.document)) {
|
|
83
83
|
if (seenIds.has(node.id)) {
|
|
84
84
|
throw new OpenUiValidationError(`duplicate object id: ${node.id}`);
|
|
85
85
|
}
|
|
86
86
|
seenIds.add(node.id);
|
|
87
|
-
if (!
|
|
88
|
-
throw new OpenUiValidationError(`
|
|
87
|
+
if (!knownTypes.has(node.type)) {
|
|
88
|
+
throw new OpenUiValidationError(`unknown OpenUI object type: ${node.type}`);
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
}
|
|
@@ -164,18 +164,21 @@ class OpenUiJson {
|
|
|
164
164
|
validateChild(child) {
|
|
165
165
|
this.validateNode(child, false);
|
|
166
166
|
const catalog = this.loadJson(this.options.catalog, this.options.catalogPath, "catalog");
|
|
167
|
-
const
|
|
167
|
+
const knownTypes = this.catalogTypes(catalog);
|
|
168
168
|
const seenIds = new Set();
|
|
169
169
|
for (const node of this.walk(child)) {
|
|
170
170
|
if (seenIds.has(node.id)) {
|
|
171
171
|
throw new OpenUiJsonError(`duplicate object id: ${node.id}`);
|
|
172
172
|
}
|
|
173
173
|
seenIds.add(node.id);
|
|
174
|
-
if (!
|
|
175
|
-
throw new OpenUiJsonError(`
|
|
174
|
+
if (!knownTypes.has(node.type)) {
|
|
175
|
+
throw new OpenUiJsonError(`unknown OpenUI object type: ${node.type}`);
|
|
176
176
|
}
|
|
177
177
|
}
|
|
178
178
|
}
|
|
179
|
+
catalogTypes(catalog) {
|
|
180
|
+
return new Set([...this.walk(catalog)].map((node) => node.type));
|
|
181
|
+
}
|
|
179
182
|
validateNode(node, isRoot) {
|
|
180
183
|
const schema = this.loadJson(this.options.schema, this.options.schemaPath, "schema");
|
|
181
184
|
const definition = isRoot ? schema : { $ref: "#/$defs/element", $defs: schema.$defs };
|
package/package.json
CHANGED