@golemui/schemas 1.2.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.
@@ -0,0 +1,219 @@
1
+ const $ = "https://json-schema.org/draft/2020-12/schema", S = "src/lib/widget-manifest.ts", T = "npm run generate:schemas";
2
+ function E(e) {
3
+ return {
4
+ manifestPath: e.manifestPath ?? S,
5
+ regenerateCommand: e.regenerateCommand ?? T
6
+ };
7
+ }
8
+ function g(e) {
9
+ const { manifestPath: t, regenerateCommand: n } = E(e);
10
+ return `GENERATED by ${e.generatorPath} from ${t}. DO NOT EDIT. Regenerate with \`${n}\`.`;
11
+ }
12
+ function y(e) {
13
+ return e.filter(
14
+ (t) => t.schemaFile !== void 0
15
+ );
16
+ }
17
+ function F(e) {
18
+ const t = y(e.manifest), n = e.includeSchemalessTypesInKnownWidgetTypes ? e.manifest : t;
19
+ return {
20
+ $schema: $,
21
+ $id: `${e.idBase}widgets.schema.json`,
22
+ $comment: g(e),
23
+ title: `Golem ${e.implementation} widgets`,
24
+ $defs: {
25
+ knownWidgetTypes: {
26
+ description: "Built-in widget `type` identifiers. Used to exclude built-ins from the custom-widget fallback so every widget matches exactly one schema. Types listed here without a component schema are not expressible in JSON and are rejected entirely instead of validating as custom widgets.",
27
+ enum: n.map((s) => s.type)
28
+ },
29
+ formWidget: {
30
+ description: "A form widget: one of the built-in component schemas, the custom-widget fallback, or a reference to an external chunk file.",
31
+ oneOf: [
32
+ ...t.map((s) => ({ $ref: `./components/${s.schemaFile}` })),
33
+ ...e.includeCustomWidgetFallback ? [{ $ref: "./components/custom.schema.json" }] : [],
34
+ { $ref: "./core/common.schema.json#/$defs/chunkRef" }
35
+ ]
36
+ }
37
+ }
38
+ };
39
+ }
40
+ function _(e) {
41
+ return {
42
+ $schema: $,
43
+ $id: `${e.idBase}form.schema.json`,
44
+ $comment: g(e),
45
+ title: e.formTitle,
46
+ type: "object",
47
+ properties: {
48
+ $schema: {
49
+ type: "string"
50
+ },
51
+ states: {
52
+ type: "object",
53
+ description: e.statesDescription,
54
+ additionalProperties: {
55
+ $ref: "./core/common.schema.json#/$defs/reactiveExpression"
56
+ }
57
+ },
58
+ form: {
59
+ type: "array",
60
+ description: "The ordered list of widgets that make up the form body",
61
+ items: {
62
+ $ref: "./widgets.schema.json#/$defs/formWidget"
63
+ }
64
+ },
65
+ autocomplete: {
66
+ type: "string",
67
+ description: "HTML `autocomplete` attribute applied to the `<form>` element (e.g. `on`, `off`)"
68
+ }
69
+ },
70
+ required: ["form"],
71
+ additionalProperties: !1
72
+ };
73
+ }
74
+ function I(e) {
75
+ const t = y(e.manifest).filter(
76
+ (n) => n.kind === "layout"
77
+ );
78
+ if (t.length === 0)
79
+ throw new Error(
80
+ `The ${e.implementation} manifest has no layout entries with a schema file, so layout-widget.schema.json cannot be generated: an empty oneOf is invalid JSON Schema.`
81
+ );
82
+ return {
83
+ $schema: $,
84
+ $id: `${e.idBase}layout-widget.schema.json`,
85
+ $comment: g(e),
86
+ title: "Golem Layout Widget",
87
+ oneOf: t.map((n) => ({ $ref: `./components/${n.schemaFile}` }))
88
+ };
89
+ }
90
+ const b = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
91
+ function u(e) {
92
+ const o = `${e.replace(/\.schema\.json$/, "").split(/[^A-Za-z0-9_$]+/).filter((a) => a.length > 0).map((a, m) => m === 0 ? a : a.charAt(0).toUpperCase() + a.slice(1)).join("")}Schema`;
93
+ if (!b.test(o))
94
+ throw new Error(
95
+ `Cannot derive a TypeScript identifier from schema file name "${e}" (got "${o}").`
96
+ );
97
+ return o;
98
+ }
99
+ function j(e) {
100
+ return b.test(e) ? e : `'${e}'`;
101
+ }
102
+ function P(e) {
103
+ const t = y(e.manifest), n = [
104
+ { name: "commonSchema", path: "core/common.schema.json" },
105
+ ...e.libRootSchemaFiles.map((r) => ({
106
+ name: u(r),
107
+ path: r
108
+ })),
109
+ { name: "formSchema", path: "form.schema.json" },
110
+ { name: "layoutWidgetSchema", path: "layout-widget.schema.json" },
111
+ { name: "widgetsSchema", path: "widgets.schema.json" },
112
+ ...t.map((r) => ({
113
+ name: u(r.schemaFile),
114
+ path: `components/${r.schemaFile}`
115
+ })),
116
+ ...e.includeCustomWidgetFallback ? [{ name: "customSchema", path: "components/custom.schema.json" }] : []
117
+ ], s = /* @__PURE__ */ new Map();
118
+ for (const { name: r, path: i } of n) {
119
+ const c = s.get(r);
120
+ if (c !== void 0)
121
+ throw new Error(
122
+ `Duplicate export name "${r}", derived from both "${c}" and "${i}".`
123
+ );
124
+ s.set(r, i);
125
+ }
126
+ const o = t.map(
127
+ (r) => ` ${j(r.type)}: ${u(r.schemaFile)},`
128
+ ), { manifestPath: a, regenerateCommand: m } = E(e);
129
+ return [
130
+ `// GENERATED by ${e.generatorPath} from ${a}. DO NOT EDIT.`,
131
+ `// Regenerate with \`${m}\`.`,
132
+ ...n.map(({ name: r, path: i }) => `import ${r}Json from './lib/${i}';`),
133
+ "",
134
+ ...n.map(
135
+ ({ name: r }) => `export const ${r}: Record<string, unknown> = ${r}Json;`
136
+ ),
137
+ "",
138
+ "/** Component schemas keyed by widget `type`. Excludes the custom fallback and schema-less types. */",
139
+ "export const COMPONENT_SCHEMAS_BY_TYPE = {",
140
+ ...o,
141
+ "} as const;"
142
+ ].join(`
143
+ `) + `
144
+ `;
145
+ }
146
+ const A = "https://json-schema.org/draft/2020-12/schema", w = "form.schema.json", k = "form.editor.schema.json", D = /* @__PURE__ */ new Set([
147
+ "$defs",
148
+ "definitions",
149
+ "properties",
150
+ "patternProperties",
151
+ "dependentSchemas"
152
+ ]);
153
+ function l(e) {
154
+ return e.split("/").pop().replace(/\.schema\.json$/, "");
155
+ }
156
+ function N(e, t) {
157
+ const n = e.split("/").slice(0, -1);
158
+ for (const s of t.split("/"))
159
+ s === "." || s === "" || (s === ".." ? n.pop() : n.push(s));
160
+ return n.join("/");
161
+ }
162
+ function O(e, t, n) {
163
+ if (e.startsWith("#"))
164
+ return `#/$defs/${l(t)}${e.slice(1)}`;
165
+ const s = e.indexOf("#"), o = s === -1 ? e : e.slice(0, s), a = s === -1 ? "" : e.slice(s + 1), m = N(t, o);
166
+ return n.push(m), `#/$defs/${l(m)}${a}`;
167
+ }
168
+ function d(e, t, n) {
169
+ if (Array.isArray(e))
170
+ return e.map((o) => d(o, t, n));
171
+ if (e === null || typeof e != "object")
172
+ return e;
173
+ const s = {};
174
+ for (const [o, a] of Object.entries(e))
175
+ o === "$ref" && typeof a == "string" ? s[o] = O(a, t, n) : D.has(o) && a !== null && typeof a == "object" ? s[o] = C(
176
+ a,
177
+ t,
178
+ n
179
+ ) : s[o] = d(a, t, n);
180
+ return s;
181
+ }
182
+ function C(e, t, n) {
183
+ const s = {};
184
+ for (const [o, a] of Object.entries(e))
185
+ s[o] = d(a, t, n);
186
+ return s;
187
+ }
188
+ function x(e, t) {
189
+ const { manifestPath: n, regenerateCommand: s } = E(e), o = {}, a = /* @__PURE__ */ new Map(), m = [w];
190
+ for (; m.length > 0; ) {
191
+ const i = m.shift(), c = l(i), f = a.get(c);
192
+ if (f === i)
193
+ continue;
194
+ if (f !== void 0)
195
+ throw new Error(
196
+ `Cannot bundle: "${f}" and "${i}" both use the $defs key "${c}". Rename one of them.`
197
+ );
198
+ a.set(c, i);
199
+ const h = { ...t(i) };
200
+ delete h.$schema, delete h.$id, delete h.$comment, o[c] = d(h, i, m);
201
+ }
202
+ const p = l(w), r = o[p];
203
+ return {
204
+ $schema: A,
205
+ $comment: `GENERATED by ${e.generatorPath} from ${n}. DO NOT EDIT. Regenerate with \`${s}\`. Self-contained copy of the schema tree for editors, which cannot resolve the published $ids offline.`,
206
+ title: `${r.title} (editor bundle)`,
207
+ $ref: `#/$defs/${p}`,
208
+ $defs: o
209
+ };
210
+ }
211
+ export {
212
+ k as E,
213
+ _ as a,
214
+ F as b,
215
+ I as c,
216
+ x as d,
217
+ P as e,
218
+ w as f
219
+ };
@@ -0,0 +1,3 @@
1
+ "use strict";const E="https://json-schema.org/draft/2020-12/schema",S="src/lib/widget-manifest.ts",T="npm run generate:schemas";function g(e){return{manifestPath:e.manifestPath??S,regenerateCommand:e.regenerateCommand??T}}function y(e){const{manifestPath:t,regenerateCommand:n}=g(e);return`GENERATED by ${e.generatorPath} from ${t}. DO NOT EDIT. Regenerate with \`${n}\`.`}function w(e){return e.filter(t=>t.schemaFile!==void 0)}function j(e){const t=w(e.manifest),n=e.includeSchemalessTypesInKnownWidgetTypes?e.manifest:t;return{$schema:E,$id:`${e.idBase}widgets.schema.json`,$comment:y(e),title:`Golem ${e.implementation} widgets`,$defs:{knownWidgetTypes:{description:"Built-in widget `type` identifiers. Used to exclude built-ins from the custom-widget fallback so every widget matches exactly one schema. Types listed here without a component schema are not expressible in JSON and are rejected entirely instead of validating as custom widgets.",enum:n.map(s=>s.type)},formWidget:{description:"A form widget: one of the built-in component schemas, the custom-widget fallback, or a reference to an external chunk file.",oneOf:[...t.map(s=>({$ref:`./components/${s.schemaFile}`})),...e.includeCustomWidgetFallback?[{$ref:"./components/custom.schema.json"}]:[],{$ref:"./core/common.schema.json#/$defs/chunkRef"}]}}}}function D(e){return{$schema:E,$id:`${e.idBase}form.schema.json`,$comment:y(e),title:e.formTitle,type:"object",properties:{$schema:{type:"string"},states:{type:"object",description:e.statesDescription,additionalProperties:{$ref:"./core/common.schema.json#/$defs/reactiveExpression"}},form:{type:"array",description:"The ordered list of widgets that make up the form body",items:{$ref:"./widgets.schema.json#/$defs/formWidget"}},autocomplete:{type:"string",description:"HTML `autocomplete` attribute applied to the `<form>` element (e.g. `on`, `off`)"}},required:["form"],additionalProperties:!1}}function _(e){const t=w(e.manifest).filter(n=>n.kind==="layout");if(t.length===0)throw new Error(`The ${e.implementation} manifest has no layout entries with a schema file, so layout-widget.schema.json cannot be generated: an empty oneOf is invalid JSON Schema.`);return{$schema:E,$id:`${e.idBase}layout-widget.schema.json`,$comment:y(e),title:"Golem Layout Widget",oneOf:t.map(n=>({$ref:`./components/${n.schemaFile}`}))}}const b=/^[A-Za-z_$][A-Za-z0-9_$]*$/;function f(e){const o=`${e.replace(/\.schema\.json$/,"").split(/[^A-Za-z0-9_$]+/).filter(a=>a.length>0).map((a,m)=>m===0?a:a.charAt(0).toUpperCase()+a.slice(1)).join("")}Schema`;if(!b.test(o))throw new Error(`Cannot derive a TypeScript identifier from schema file name "${e}" (got "${o}").`);return o}function N(e){return b.test(e)?e:`'${e}'`}function F(e){const t=w(e.manifest),n=[{name:"commonSchema",path:"core/common.schema.json"},...e.libRootSchemaFiles.map(r=>({name:f(r),path:r})),{name:"formSchema",path:"form.schema.json"},{name:"layoutWidgetSchema",path:"layout-widget.schema.json"},{name:"widgetsSchema",path:"widgets.schema.json"},...t.map(r=>({name:f(r.schemaFile),path:`components/${r.schemaFile}`})),...e.includeCustomWidgetFallback?[{name:"customSchema",path:"components/custom.schema.json"}]:[]],s=new Map;for(const{name:r,path:i}of n){const c=s.get(r);if(c!==void 0)throw new Error(`Duplicate export name "${r}", derived from both "${c}" and "${i}".`);s.set(r,i)}const o=t.map(r=>` ${N(r.type)}: ${f(r.schemaFile)},`),{manifestPath:a,regenerateCommand:m}=g(e);return[`// GENERATED by ${e.generatorPath} from ${a}. DO NOT EDIT.`,`// Regenerate with \`${m}\`.`,...n.map(({name:r,path:i})=>`import ${r}Json from './lib/${i}';`),"",...n.map(({name:r})=>`export const ${r}: Record<string, unknown> = ${r}Json;`),"","/** Component schemas keyed by widget `type`. Excludes the custom fallback and schema-less types. */","export const COMPONENT_SCHEMAS_BY_TYPE = {",...o,"} as const;"].join(`
2
+ `)+`
3
+ `}const O="https://json-schema.org/draft/2020-12/schema",$="form.schema.json",A="form.editor.schema.json",C=new Set(["$defs","definitions","properties","patternProperties","dependentSchemas"]);function l(e){return e.split("/").pop().replace(/\.schema\.json$/,"")}function I(e,t){const n=e.split("/").slice(0,-1);for(const s of t.split("/"))s==="."||s===""||(s===".."?n.pop():n.push(s));return n.join("/")}function R(e,t,n){if(e.startsWith("#"))return`#/$defs/${l(t)}${e.slice(1)}`;const s=e.indexOf("#"),o=s===-1?e:e.slice(0,s),a=s===-1?"":e.slice(s+1),m=I(t,o);return n.push(m),`#/$defs/${l(m)}${a}`}function d(e,t,n){if(Array.isArray(e))return e.map(o=>d(o,t,n));if(e===null||typeof e!="object")return e;const s={};for(const[o,a]of Object.entries(e))o==="$ref"&&typeof a=="string"?s[o]=R(a,t,n):C.has(o)&&a!==null&&typeof a=="object"?s[o]=P(a,t,n):s[o]=d(a,t,n);return s}function P(e,t,n){const s={};for(const[o,a]of Object.entries(e))s[o]=d(a,t,n);return s}function k(e,t){const{manifestPath:n,regenerateCommand:s}=g(e),o={},a=new Map,m=[$];for(;m.length>0;){const i=m.shift(),c=l(i),p=a.get(c);if(p===i)continue;if(p!==void 0)throw new Error(`Cannot bundle: "${p}" and "${i}" both use the $defs key "${c}". Rename one of them.`);a.set(c,i);const h={...t(i)};delete h.$schema,delete h.$id,delete h.$comment,o[c]=d(h,i,m)}const u=l($),r=o[u];return{$schema:O,$comment:`GENERATED by ${e.generatorPath} from ${n}. DO NOT EDIT. Regenerate with \`${s}\`. Self-contained copy of the schema tree for editors, which cannot resolve the published $ids offline.`,title:`${r.title} (editor bundle)`,$ref:`#/$defs/${u}`,$defs:o}}exports.EDITOR_BUNDLE_ENTRY_FILE=$;exports.EDITOR_BUNDLE_FILE=A;exports.buildEditorBundle=k;exports.buildFormEnvelope=D;exports.buildLayoutWidgetSchema=_;exports.buildSchemasPackageIndex=F;exports.buildWidgetsSchema=j;
@@ -0,0 +1,2 @@
1
+ "use strict";var E=Object.create;var g=Object.defineProperty;var F=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var v=Object.getPrototypeOf,I=Object.prototype.hasOwnProperty;var L=(e,t,n,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of x(t))!I.call(e,o)&&o!==n&&g(e,o,{get:()=>t[o],enumerable:!(s=F(t,o))||s.enumerable});return e};var N=(e,t,n)=>(n=e!=null?E(v(e)):{},L(t||!e||!e.__esModule?g(n,"default",{value:e,enumerable:!0}):n,e));const c=require("node:fs"),i=require("node:path"),O=require("node:url"),d=require("./editor-bundle-yoVhdYIT.cjs");var f=typeof document<"u"?document.currentScript:null;async function _(){try{return await import("prettier")}catch{return null}}async function b(e){const t=await _();if(t===null)return null;const n=await t.resolveConfig(e);return n===null?null:{prettier:t,options:n}}async function j(e,t){const n=await b(t);return n===null?JSON.stringify(e,null,2)+`
2
+ `:n.prettier.format(JSON.stringify(e),{...n.options,filepath:t})}async function $(e,t){const n=await b(t);return n===null?e:n.prettier.format(e,{...n.options,filepath:t})}function m(e){return c.readdirSync(e).filter(t=>t.endsWith(".schema.json")).sort()}function B(e){let t=e;for(;;){if(c.existsSync(i.join(t,"package.json")))return t;const n=i.dirname(t);if(n===t)throw new Error(`No package.json above ${e}, cannot locate @golemui/schemas.`);t=n}}function C(){const e=B(i.dirname(O.fileURLToPath(typeof document>"u"?require("url").pathToFileURL(__filename).href:f&&f.tagName.toUpperCase()==="SCRIPT"&&f.src||new URL("generate-implementation-schemas-D57DzM2J.cjs",document.baseURI).href))),t=[i.join(e,"src","lib","core"),i.join(e,"schemas","core")],n=t.find(s=>c.existsSync(s)&&m(s).length>0);if(n===void 0)throw new Error(`Cannot find the @golemui/schemas core schemas. Looked in: ${t.join(", ")}.`);return n}function J(e,t,n){const s=/"\$id":\s*"[^"]*"/g,o=e.match(s);if(o?.length!==1)throw new Error(`Expected exactly one $id in ${n}, found ${o?.length??0}.`);return e.replace(s,()=>`"$id": "${t}"`)}async function P(e,t){const n=i.join(t,"src","lib"),s=C(),o=[],l=new Map;async function h(r,a){const u=i.join(n,r);l.set(r,a),o.push({path:u,content:await j(a,u)})}await h("widgets.schema.json",d.buildWidgetsSchema(e)),await h("form.schema.json",d.buildFormEnvelope(e)),await h("layout-widget.schema.json",d.buildLayoutWidgetSchema(e));const p=m(s);for(const r of p){const a=`core/${r}`,u=i.join(n,a),S=J(c.readFileSync(i.join(s,r),"utf-8"),`${e.idBase}core/${r}`,r);l.set(a,JSON.parse(S)),o.push({path:u,content:await $(S,u)})}if(e.emitEditorBundle===!0){const r=i.join(n,d.EDITOR_BUNDLE_FILE),a=d.buildEditorBundle(e,u=>U(n,u,l));o.push({path:r,content:await j(a,r)})}const w=i.join(t,"src","index.ts");o.push({path:w,content:await $(d.buildSchemasPackageIndex(e),w)}),c.mkdirSync(i.join(n,"core"),{recursive:!0});const y=m(i.join(n,"core")).filter(r=>!p.includes(r));if(y.length>0)throw new Error(`Vendored core files without a @golemui/schemas source: ${y.join(", ")}. Delete them from ${i.relative(t,i.join(n,"core"))}.`);for(const r of o)c.writeFileSync(r.path,r.content,"utf-8"),console.log(`Wrote ${i.relative(t,r.path)} (${r.content.length} bytes)`);console.log(`Generated ${o.length} files from ${e.manifest.length} manifest entries.`)}function U(e,t,n){const s=n.get(t);if(s!==void 0)return s;const o=i.join(e,t);if(!c.existsSync(o))throw new Error(`Cannot build the editor bundle: ${t} is referenced by the schema tree but does not exist. Expected it at ${o}.`);return JSON.parse(c.readFileSync(o,"utf-8"))}exports.generateImplementationSchemas=P;
@@ -0,0 +1,116 @@
1
+ import { readFileSync as b, mkdirSync as x, writeFileSync as F, existsSync as f, readdirSync as j } from "node:fs";
2
+ import { join as i, relative as y, dirname as S } from "node:path";
3
+ import { fileURLToPath as O } from "node:url";
4
+ import { b as v, a as N, c as B, E as J, d as L, e as D } from "./editor-bundle-Jb3IVFC3.js";
5
+ async function I() {
6
+ try {
7
+ return await import("prettier");
8
+ } catch {
9
+ return null;
10
+ }
11
+ }
12
+ async function E(e) {
13
+ const t = await I();
14
+ if (t === null)
15
+ return null;
16
+ const n = await t.resolveConfig(e);
17
+ return n === null ? null : { prettier: t, options: n };
18
+ }
19
+ async function g(e, t) {
20
+ const n = await E(t);
21
+ return n === null ? JSON.stringify(e, null, 2) + `
22
+ ` : n.prettier.format(JSON.stringify(e), {
23
+ ...n.options,
24
+ filepath: t
25
+ });
26
+ }
27
+ async function $(e, t) {
28
+ const n = await E(t);
29
+ return n === null ? e : n.prettier.format(e, { ...n.options, filepath: t });
30
+ }
31
+ function d(e) {
32
+ return j(e).filter((t) => t.endsWith(".schema.json")).sort();
33
+ }
34
+ function P(e) {
35
+ let t = e;
36
+ for (; ; ) {
37
+ if (f(i(t, "package.json")))
38
+ return t;
39
+ const n = S(t);
40
+ if (n === t)
41
+ throw new Error(`No package.json above ${e}, cannot locate @golemui/schemas.`);
42
+ t = n;
43
+ }
44
+ }
45
+ function k() {
46
+ const e = P(S(O(import.meta.url))), t = [
47
+ i(e, "src", "lib", "core"),
48
+ i(e, "schemas", "core")
49
+ ], n = t.find(
50
+ (s) => f(s) && d(s).length > 0
51
+ );
52
+ if (n === void 0)
53
+ throw new Error(
54
+ `Cannot find the @golemui/schemas core schemas. Looked in: ${t.join(", ")}.`
55
+ );
56
+ return n;
57
+ }
58
+ function C(e, t, n) {
59
+ const s = /"\$id":\s*"[^"]*"/g, r = e.match(s);
60
+ if (r?.length !== 1)
61
+ throw new Error(`Expected exactly one $id in ${n}, found ${r?.length ?? 0}.`);
62
+ return e.replace(s, () => `"$id": "${t}"`);
63
+ }
64
+ async function G(e, t) {
65
+ const n = i(t, "src", "lib"), s = k(), r = [], u = /* @__PURE__ */ new Map();
66
+ async function l(o, a) {
67
+ const c = i(n, o);
68
+ u.set(o, a), r.push({ path: c, content: await g(a, c) });
69
+ }
70
+ await l("widgets.schema.json", v(e)), await l("form.schema.json", N(e)), await l("layout-widget.schema.json", B(e));
71
+ const h = d(s);
72
+ for (const o of h) {
73
+ const a = `core/${o}`, c = i(n, a), w = C(
74
+ b(i(s, o), "utf-8"),
75
+ `${e.idBase}core/${o}`,
76
+ o
77
+ );
78
+ u.set(a, JSON.parse(w)), r.push({ path: c, content: await $(w, c) });
79
+ }
80
+ if (e.emitEditorBundle === !0) {
81
+ const o = i(n, J), a = L(
82
+ e,
83
+ (c) => W(n, c, u)
84
+ );
85
+ r.push({ path: o, content: await g(a, o) });
86
+ }
87
+ const m = i(t, "src", "index.ts");
88
+ r.push({
89
+ path: m,
90
+ content: await $(D(e), m)
91
+ }), x(i(n, "core"), { recursive: !0 });
92
+ const p = d(i(n, "core")).filter(
93
+ (o) => !h.includes(o)
94
+ );
95
+ if (p.length > 0)
96
+ throw new Error(
97
+ `Vendored core files without a @golemui/schemas source: ${p.join(", ")}. Delete them from ${y(t, i(n, "core"))}.`
98
+ );
99
+ for (const o of r)
100
+ F(o.path, o.content, "utf-8"), console.log(`Wrote ${y(t, o.path)} (${o.content.length} bytes)`);
101
+ console.log(`Generated ${r.length} files from ${e.manifest.length} manifest entries.`);
102
+ }
103
+ function W(e, t, n) {
104
+ const s = n.get(t);
105
+ if (s !== void 0)
106
+ return s;
107
+ const r = i(e, t);
108
+ if (!f(r))
109
+ throw new Error(
110
+ `Cannot build the editor bundle: ${t} is referenced by the schema tree but does not exist. Expected it at ${r}.`
111
+ );
112
+ return JSON.parse(b(r, "utf-8"));
113
+ }
114
+ export {
115
+ G as g
116
+ };
package/generator.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./generate-implementation-schemas-D57DzM2J.cjs");exports.generateImplementationSchemas=e.generateImplementationSchemas;
package/generator.d.ts ADDED
@@ -0,0 +1 @@
1
+ export { generateImplementationSchemas } from './lib/generator/generate-implementation-schemas.js';
package/generator.js ADDED
@@ -0,0 +1,4 @@
1
+ import { g as m } from "./generate-implementation-schemas-DxCUi0Jr.js";
2
+ export {
3
+ m as generateImplementationSchemas
4
+ };
package/index.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./editor-bundle-yoVhdYIT.cjs"),t="https://json-schema.org/draft/2020-12/schema",i="https://golemui.com/schemas/core/common.schema.json",s="Owned by @golemui/schemas (libs/schemas/src/lib/core/). Implementation trees contain a generated vendored copy, identical apart from an `$id` rebased onto the implementation's own tree. Edit the source file, then run `npm run generate:schemas`.",n="Golem Common Definitions",a={reactiveExpression:{type:"string",description:"A reactive expression string. Use `$form` to access form data e.g. `$form.termsAccepted === true`"},dotPath:{type:"string",description:"A dot-separated path to a property in the form data"},uid:{type:"string",description:"Unique identifier for the widget"},chunkRef:{type:"object",description:"A reference to an external chunk file whose widget array will be inlined at this position in the form",properties:{$ref:{type:"string",description:"Relative path to a JSON chunk file"}},required:["$ref"],additionalProperties:!1},localizable:{description:"A value that can be a plain string or an i18n key object. Use a plain string for static text, or `{key, default, params}` to reference a translation key.",oneOf:[{type:"string"},{type:"object",properties:{key:{type:"string",description:"The i18n translation key"},default:{type:"string",description:"Fallback text shown when the translation key is not found"},params:{type:"object",description:"Interpolation parameters passed to the translation function"}},required:["key"],additionalProperties:!1}]},include:{description:"Show this widget only in certain form states (`{in: [stateNames]}`) or when a reactive expression is true (`{when: expr}`). If omitted the widget is always shown.",oneOf:[{type:"object",properties:{in:{type:"array",items:{type:"string"},description:"List of state names (defined in the form `states` map) in which this widget should be visible"}},required:["in"],additionalProperties:!1},{type:"object",properties:{when:{$ref:"#/$defs/reactiveExpression"}},required:["when"],additionalProperties:!1}]},exclude:{description:"Hide this widget in certain form states (`{from: [stateNames]}`) or when a reactive expression is true (`{when: expr}`). If omitted the widget is never hidden.",oneOf:[{type:"object",properties:{from:{type:"array",items:{type:"string"},description:"List of state names (defined in the form `states` map) in which this widget should be hidden"}},required:["from"],additionalProperties:!1},{type:"object",properties:{when:{$ref:"#/$defs/reactiveExpression"}},required:["when"],additionalProperties:!1}]},boolOrWhen:{description:"A static boolean or a conditional `{when: reactiveExpression}` object evaluated at runtime. Use `{when: '$form.someField === true'}` for dynamic behavior.",oneOf:[{type:"boolean"},{type:"object",properties:{when:{$ref:"#/$defs/reactiveExpression"}},required:["when"],additionalProperties:!1}]},on:{type:"object",description:'Event handlers for this widget. Values are action names dispatched to the form\'s event bus. Each key also accepts a state-suffixed variant (`"click.<stateName>"`) that overrides the base handler when the named state is active.',properties:{load:{type:"string",description:"Action dispatched when the widget is first mounted"},click:{type:"string",description:"Action dispatched when the user clicks the widget"},change:{type:"string",description:"Action dispatched when the widget value changes"},filter:{type:"string",description:"Action dispatched on search/filter input, typically used with async data sources"},blur:{type:"string",description:"Action dispatched when the widget loses focus"}},patternProperties:{"^load\\.[^.]+$":{type:"string",description:'State-suffixed load handler: used instead of `load` when the named state is active (e.g. `"load.myState"`)'},"^click\\.[^.]+$":{type:"string",description:'State-suffixed click handler: used instead of `click` when the named state is active (e.g. `"click.myState"`)'},"^change\\.[^.]+$":{type:"string",description:'State-suffixed change handler: used instead of `change` when the named state is active (e.g. `"change.myState"`)'},"^filter\\.[^.]+$":{type:"string",description:'State-suffixed filter handler: used instead of `filter` when the named state is active (e.g. `"filter.myState"`)'},"^blur\\.[^.]+$":{type:"string",description:'State-suffixed blur handler: used instead of `blur` when the named state is active (e.g. `"blur.myState"`)'}},additionalProperties:!1},baseWidget:{type:"object",description:'Base properties shared by all widgets. Root-level props that support state-suffixing (e.g. `"label.myState"`) are: `label`, `disabled`, `readonly`, `validator`, `size`. Any key inside `props` can also be suffixed. State names must be declared in the form `states` map.',properties:{$schema:{type:"string"},uid:{$ref:"#/$defs/uid"},type:{type:"string"},size:{type:"number",description:"Column span in the form grid (1-12). Defaults to full width when omitted.",minimum:1,maximum:12},include:{$ref:"#/$defs/include"},exclude:{$ref:"#/$defs/exclude"}},required:["type"]}},r={$schema:t,$id:i,$comment:s,title:n,$defs:a},o=r;exports.EDITOR_BUNDLE_ENTRY_FILE=e.EDITOR_BUNDLE_ENTRY_FILE;exports.EDITOR_BUNDLE_FILE=e.EDITOR_BUNDLE_FILE;exports.buildEditorBundle=e.buildEditorBundle;exports.buildFormEnvelope=e.buildFormEnvelope;exports.buildLayoutWidgetSchema=e.buildLayoutWidgetSchema;exports.buildSchemasPackageIndex=e.buildSchemasPackageIndex;exports.buildWidgetsSchema=e.buildWidgetsSchema;exports.commonSchema=o;
package/index.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ /** The shared core `$defs` resource, published as `schemas/core/common.schema.json`. */
2
+ export declare const commonSchema: Record<string, unknown>;
3
+ export type { ImplementationSchemaConfig, WidgetKind, WidgetManifestEntry, } from './lib/manifest.types.js';
4
+ export { buildFormEnvelope, buildLayoutWidgetSchema, buildSchemasPackageIndex, buildWidgetsSchema, } from './lib/generator/builders.js';
5
+ export type { SchemaObject } from './lib/generator/builders.js';
6
+ export { buildEditorBundle, EDITOR_BUNDLE_ENTRY_FILE, EDITOR_BUNDLE_FILE, } from './lib/generator/editor-bundle.js';
package/index.js ADDED
@@ -0,0 +1,18 @@
1
+ import { f as c, E as p, d as l, a as h, c as f, e as m, b as u } from "./editor-bundle-Jb3IVFC3.js";
2
+ const e = "https://json-schema.org/draft/2020-12/schema", t = "https://golemui.com/schemas/core/common.schema.json", i = "Owned by @golemui/schemas (libs/schemas/src/lib/core/). Implementation trees contain a generated vendored copy, identical apart from an `$id` rebased onto the implementation's own tree. Edit the source file, then run `npm run generate:schemas`.", s = "Golem Common Definitions", a = { reactiveExpression: { type: "string", description: "A reactive expression string. Use `$form` to access form data e.g. `$form.termsAccepted === true`" }, dotPath: { type: "string", description: "A dot-separated path to a property in the form data" }, uid: { type: "string", description: "Unique identifier for the widget" }, chunkRef: { type: "object", description: "A reference to an external chunk file whose widget array will be inlined at this position in the form", properties: { $ref: { type: "string", description: "Relative path to a JSON chunk file" } }, required: ["$ref"], additionalProperties: !1 }, localizable: { description: "A value that can be a plain string or an i18n key object. Use a plain string for static text, or `{key, default, params}` to reference a translation key.", oneOf: [{ type: "string" }, { type: "object", properties: { key: { type: "string", description: "The i18n translation key" }, default: { type: "string", description: "Fallback text shown when the translation key is not found" }, params: { type: "object", description: "Interpolation parameters passed to the translation function" } }, required: ["key"], additionalProperties: !1 }] }, include: { description: "Show this widget only in certain form states (`{in: [stateNames]}`) or when a reactive expression is true (`{when: expr}`). If omitted the widget is always shown.", oneOf: [{ type: "object", properties: { in: { type: "array", items: { type: "string" }, description: "List of state names (defined in the form `states` map) in which this widget should be visible" } }, required: ["in"], additionalProperties: !1 }, { type: "object", properties: { when: { $ref: "#/$defs/reactiveExpression" } }, required: ["when"], additionalProperties: !1 }] }, exclude: { description: "Hide this widget in certain form states (`{from: [stateNames]}`) or when a reactive expression is true (`{when: expr}`). If omitted the widget is never hidden.", oneOf: [{ type: "object", properties: { from: { type: "array", items: { type: "string" }, description: "List of state names (defined in the form `states` map) in which this widget should be hidden" } }, required: ["from"], additionalProperties: !1 }, { type: "object", properties: { when: { $ref: "#/$defs/reactiveExpression" } }, required: ["when"], additionalProperties: !1 }] }, boolOrWhen: { description: "A static boolean or a conditional `{when: reactiveExpression}` object evaluated at runtime. Use `{when: '$form.someField === true'}` for dynamic behavior.", oneOf: [{ type: "boolean" }, { type: "object", properties: { when: { $ref: "#/$defs/reactiveExpression" } }, required: ["when"], additionalProperties: !1 }] }, on: { type: "object", description: 'Event handlers for this widget. Values are action names dispatched to the form\'s event bus. Each key also accepts a state-suffixed variant (`"click.<stateName>"`) that overrides the base handler when the named state is active.', properties: { load: { type: "string", description: "Action dispatched when the widget is first mounted" }, click: { type: "string", description: "Action dispatched when the user clicks the widget" }, change: { type: "string", description: "Action dispatched when the widget value changes" }, filter: { type: "string", description: "Action dispatched on search/filter input, typically used with async data sources" }, blur: { type: "string", description: "Action dispatched when the widget loses focus" } }, patternProperties: { "^load\\.[^.]+$": { type: "string", description: 'State-suffixed load handler: used instead of `load` when the named state is active (e.g. `"load.myState"`)' }, "^click\\.[^.]+$": { type: "string", description: 'State-suffixed click handler: used instead of `click` when the named state is active (e.g. `"click.myState"`)' }, "^change\\.[^.]+$": { type: "string", description: 'State-suffixed change handler: used instead of `change` when the named state is active (e.g. `"change.myState"`)' }, "^filter\\.[^.]+$": { type: "string", description: 'State-suffixed filter handler: used instead of `filter` when the named state is active (e.g. `"filter.myState"`)' }, "^blur\\.[^.]+$": { type: "string", description: 'State-suffixed blur handler: used instead of `blur` when the named state is active (e.g. `"blur.myState"`)' } }, additionalProperties: !1 }, baseWidget: { type: "object", description: 'Base properties shared by all widgets. Root-level props that support state-suffixing (e.g. `"label.myState"`) are: `label`, `disabled`, `readonly`, `validator`, `size`. Any key inside `props` can also be suffixed. State names must be declared in the form `states` map.', properties: { $schema: { type: "string" }, uid: { $ref: "#/$defs/uid" }, type: { type: "string" }, size: { type: "number", description: "Column span in the form grid (1-12). Defaults to full width when omitted.", minimum: 1, maximum: 12 }, include: { $ref: "#/$defs/include" }, exclude: { $ref: "#/$defs/exclude" } }, required: ["type"] } }, n = {
3
+ $schema: e,
4
+ $id: t,
5
+ $comment: i,
6
+ title: s,
7
+ $defs: a
8
+ }, r = n;
9
+ export {
10
+ c as EDITOR_BUNDLE_ENTRY_FILE,
11
+ p as EDITOR_BUNDLE_FILE,
12
+ l as buildEditorBundle,
13
+ h as buildFormEnvelope,
14
+ f as buildLayoutWidgetSchema,
15
+ m as buildSchemasPackageIndex,
16
+ u as buildWidgetsSchema,
17
+ r as commonSchema
18
+ };
@@ -0,0 +1,41 @@
1
+ import { ImplementationSchemaConfig } from '../manifest.types.js';
2
+ /** A plain JSON schema object as produced by the builders. */
3
+ export type SchemaObject = Record<string, unknown>;
4
+ /** Where the marker says the manifest lives, and how to rerun the generator. */
5
+ export declare function generatedFileOrigin(config: ImplementationSchemaConfig): {
6
+ manifestPath: string;
7
+ regenerateCommand: string;
8
+ };
9
+ /**
10
+ * Builds the implementation's `widgets.schema.json`: the `formWidget` union and
11
+ * the `knownWidgetTypes` enum, derived from one manifest so they cannot disagree.
12
+ * @param config - The implementation's schema configuration.
13
+ * @returns The schema object, ready to be serialized.
14
+ */
15
+ export declare function buildWidgetsSchema(config: ImplementationSchemaConfig): SchemaObject;
16
+ /**
17
+ * Builds the implementation's `form.schema.json` envelope: the document root a
18
+ * form definition file validates against.
19
+ * @param config - The implementation's schema configuration.
20
+ * @returns The schema object, ready to be serialized.
21
+ */
22
+ export declare function buildFormEnvelope(config: ImplementationSchemaConfig): SchemaObject;
23
+ /**
24
+ * Builds the implementation's `layout-widget.schema.json`: the union of the
25
+ * layout-kind manifest entries, used by chunk files and repeater templates.
26
+ * @param config - The implementation's schema configuration.
27
+ * @returns The schema object, ready to be serialized.
28
+ */
29
+ export declare function buildLayoutWidgetSchema(config: ImplementationSchemaConfig): SchemaObject;
30
+ /**
31
+ * Builds the source of the implementation schema package's `src/index.ts`:
32
+ * schema imports, re-exports, and the `COMPONENT_SCHEMAS_BY_TYPE` map.
33
+ *
34
+ * Every schema is imported as `<name>Json` and re-exported as an annotated
35
+ * `<name>` constant. The annotation keeps `.json` imports out of the emitted
36
+ * `index.d.ts`, so a consumer of the published package needs neither
37
+ * `resolveJsonModule` nor a `type: "json"` import attribute.
38
+ * @param config - The implementation's schema configuration.
39
+ * @returns The TypeScript source text (unformatted, run it through prettier).
40
+ */
41
+ export declare function buildSchemasPackageIndex(config: ImplementationSchemaConfig): string;
@@ -0,0 +1,18 @@
1
+ import { ImplementationSchemaConfig } from '../manifest.types.js';
2
+ import { SchemaObject } from './builders.js';
3
+ /** The file the walk starts from, relative to the implementation's `src/lib`. */
4
+ export declare const EDITOR_BUNDLE_ENTRY_FILE = "form.schema.json";
5
+ /** Output file name, relative to the implementation's `src/lib`. */
6
+ export declare const EDITOR_BUNDLE_FILE = "form.editor.schema.json";
7
+ /**
8
+ * Builds the self-contained editor schema by walking the `$ref` graph from the form
9
+ * envelope. Every reachable file is inlined, so the result loads with no network access.
10
+ * @param config - The implementation's schema configuration.
11
+ * @param readSchema - Returns the parsed schema at a lib-relative path, e.g. `components/flex.schema.json`.
12
+ * @returns The bundle, ready to be serialized.
13
+ * @example
14
+ * const bundle = buildEditorBundle(config, (path) =>
15
+ * JSON.parse(readFileSync(join(libDir, path), 'utf-8')),
16
+ * );
17
+ */
18
+ export declare function buildEditorBundle(config: ImplementationSchemaConfig, readSchema: (libRelativePath: string) => SchemaObject): SchemaObject;
@@ -0,0 +1,14 @@
1
+ import { ImplementationSchemaConfig } from '../manifest.types.js';
2
+ /**
3
+ * Generates one implementation's schema tree into its package directory.
4
+ * @param config - The implementation's schema configuration.
5
+ * @param packageRoot - Absolute path of the implementation package, the directory holding its `src/`.
6
+ * @returns Resolves when every output file is written. Callers own error handling.
7
+ * @example
8
+ * // The implementation package's generator entry point:
9
+ * generateImplementationSchemas(kendoSchemaConfig, join(__dirname, '..')).catch((error) => {
10
+ * console.error(error);
11
+ * process.exitCode = 1;
12
+ * });
13
+ */
14
+ export declare function generateImplementationSchemas(config: ImplementationSchemaConfig, packageRoot: string): Promise<void>;
@@ -0,0 +1,86 @@
1
+ /** The widget categories shared by every implementation, matching the runtime widget `kind` field. */
2
+ export type WidgetKind = 'input' | 'layout' | 'display' | 'action';
3
+ /**
4
+ * One widget type in an implementation's manifest, the single source of truth
5
+ * for the generated aggregate schema files.
6
+ * @example
7
+ * const entry: WidgetManifestEntry = {
8
+ * type: 'dateTimeCalendar',
9
+ * schemaFile: 'datetimecalendar.schema.json',
10
+ * kind: 'input',
11
+ * };
12
+ */
13
+ export interface WidgetManifestEntry {
14
+ /** The widget `type` const used in JSON form definitions, e.g. `dateTimeCalendar`. */
15
+ readonly type: string;
16
+ /**
17
+ * Component schema file name inside the implementation's `components/` directory.
18
+ * Absent for widget types that JSON cannot express (e.g. props holding a function).
19
+ */
20
+ readonly schemaFile?: string;
21
+ /** The widget category. Entries with kind `layout` form the layout-widget union. */
22
+ readonly kind: WidgetKind;
23
+ }
24
+ /**
25
+ * Everything the schema builders need to generate one implementation's
26
+ * aggregate schema files.
27
+ * @example
28
+ * const config: ImplementationSchemaConfig = {
29
+ * implementation: 'gui',
30
+ * idBase: 'https://golemui.com/schemas/gui/',
31
+ * generatorPath: 'libs/gui/schemas/tools/generate-schemas.ts',
32
+ * formTitle: 'Golem Form DSL',
33
+ * statesDescription: 'Named boolean conditions keyed by state name, ...',
34
+ * manifest: guiWidgetManifest,
35
+ * libRootSchemaFiles: ['ranges.schema.json', 'validators.schema.json'],
36
+ * includeSchemalessTypesInKnownWidgetTypes: true,
37
+ * includeCustomWidgetFallback: true,
38
+ * };
39
+ */
40
+ export interface ImplementationSchemaConfig {
41
+ /** Implementation name, e.g. `gui`. Used in generated titles. */
42
+ readonly implementation: string;
43
+ /** Absolute base URL of the implementation's published schema tree, with a trailing slash. */
44
+ readonly idBase: string;
45
+ /** Repo-relative path of the implementation's generator entry point, used in the generated-file markers. */
46
+ readonly generatorPath: string;
47
+ /**
48
+ * Path of the file holding the manifest, named in the generated-file markers.
49
+ * Defaults to `src/lib/widget-manifest.ts`, where the in-repo implementations keep it.
50
+ */
51
+ readonly manifestPath?: string;
52
+ /**
53
+ * Command that regenerates the tree, named in the generated-file markers.
54
+ * Defaults to `npm run generate:schemas`.
55
+ */
56
+ readonly regenerateCommand?: string;
57
+ /** `title` of the generated form envelope. */
58
+ readonly formTitle: string;
59
+ /** Description of the form envelope's `states` property, naming the implementation's suffixable root props. */
60
+ readonly statesDescription: string;
61
+ /** The implementation's widget manifest. */
62
+ readonly manifest: readonly WidgetManifestEntry[];
63
+ /**
64
+ * Handwritten schema files at the implementation package's `src/lib/` root,
65
+ * e.g. `validators.schema.json`. Each is re-exported from the generated index
66
+ * under its derived name (`validators.schema.json` exports `validatorsSchema`).
67
+ */
68
+ readonly libRootSchemaFiles: readonly string[];
69
+ /**
70
+ * When true, schema-less widget types are still listed in `knownWidgetTypes`,
71
+ * so their `type` fails validation instead of matching the custom fallback.
72
+ */
73
+ readonly includeSchemalessTypesInKnownWidgetTypes: boolean;
74
+ /**
75
+ * When true, the `formWidget` union includes `components/custom.schema.json`
76
+ * and the generated index exports it as `customSchema`. Turn off for an
77
+ * implementation without a custom-widget fallback.
78
+ */
79
+ readonly includeCustomWidgetFallback: boolean;
80
+ /**
81
+ * When true, also emit `src/lib/form.editor.schema.json`, a self-contained copy of
82
+ * the tree for editors, which cannot resolve the published `$id`s offline. Point a
83
+ * form file's `$schema` at it. Off by default.
84
+ */
85
+ readonly emitEditorBundle?: boolean;
86
+ }
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "@golemui/schemas",
3
+ "version": "1.2.1",
4
+ "license": "MIT",
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "type": "module",
9
+ "bin": {
10
+ "golemui-schemas": "./cli.js"
11
+ },
12
+ "main": "./index.cjs",
13
+ "module": "./index.js",
14
+ "types": "./index.d.ts",
15
+ "exports": {
16
+ ".": {
17
+ "types": "./index.d.ts",
18
+ "import": "./index.js",
19
+ "require": "./index.cjs"
20
+ },
21
+ "./generator": {
22
+ "types": "./generator.d.ts",
23
+ "import": "./generator.js",
24
+ "require": "./generator.cjs"
25
+ },
26
+ "./schemas/*.schema.json": "./schemas/*.schema.json",
27
+ "./package.json": "./package.json"
28
+ },
29
+ "files": [
30
+ "lib",
31
+ "schemas",
32
+ "*.js",
33
+ "*.cjs",
34
+ "*.d.ts",
35
+ "*.md"
36
+ ],
37
+ "dependencies": {},
38
+ "peerDependencies": {
39
+ "prettier": "^3.0.0"
40
+ },
41
+ "peerDependenciesMeta": {
42
+ "prettier": {
43
+ "optional": true
44
+ }
45
+ },
46
+ "repository": {
47
+ "type": "git",
48
+ "url": "https://github.com/golemui/golemui.git",
49
+ "directory": "libs/schemas"
50
+ }
51
+ }