@jxsuite/schema 0.23.1 → 0.24.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.
@@ -0,0 +1,20 @@
1
+ export const imageConfigSchema = {
2
+ description: "Image optimization configuration for the project.",
3
+ type: "object",
4
+ properties: {
5
+ optimize: { type: "boolean" },
6
+ widths: { type: "array", items: { type: "number" } },
7
+ formats: { type: "array", items: { type: "string" } },
8
+ quality: {
9
+ type: "object",
10
+ properties: {
11
+ webp: { type: "number" },
12
+ avif: { type: "number" },
13
+ jpeg: { type: "number" },
14
+ png: { type: "number" },
15
+ },
16
+ },
17
+ sizes: { type: "string" },
18
+ lazyLoad: { type: "boolean" },
19
+ },
20
+ } as const;
package/defs/index.ts ADDED
@@ -0,0 +1,76 @@
1
+ // Leaf schemas
2
+ export { tagNameSchema } from "./tag-name.schema";
3
+ export { stringOrRefSchema, boolOrRefSchema, numberOrRefSchema } from "./string-or-ref.schema";
4
+ export { headEntrySchema } from "./head-entry.schema";
5
+ export { cemParameterSchema, cemEventSchema } from "./cem.schema";
6
+ export { imageConfigSchema } from "./image-config.schema";
7
+ export { jsonSchemaTypeSchema } from "./json-schema-type.schema";
8
+
9
+ // Ref schemas
10
+ export {
11
+ internalRefSchema,
12
+ stateRefSchema,
13
+ externalRefSchema,
14
+ globalRefSchema,
15
+ parentRefSchema,
16
+ mapRefSchema,
17
+ anyRefSchema,
18
+ refObjectSchema,
19
+ externalComponentRefSchema,
20
+ } from "./ref-object.schema";
21
+
22
+ // Style & element
23
+ export { styleObjectSchema } from "./style-object.schema";
24
+ export { arrayNamespaceSchema, childrenValueSchema } from "./children-value.schema";
25
+ export {
26
+ attributesObjectSchema,
27
+ propsObjectSchema,
28
+ elementPropertyValueSchema,
29
+ switchDefSchema,
30
+ switchNodeSchema,
31
+ elementDefSchema,
32
+ } from "./element-def.schema";
33
+
34
+ // State shapes
35
+ export { typedStateDefSchema } from "./typed-state-def.schema";
36
+ export { functionDefSchema } from "./function-def.schema";
37
+ export { externalClassDefSchema, BUILT_IN_PROTOTYPES } from "./external-class-def.schema";
38
+ export { pureTypeDefSchema } from "./pure-type-def.schema";
39
+
40
+ // Expression system
41
+ export {
42
+ expressionPointerSchema,
43
+ expressionLiteralSchema,
44
+ expressionOperandSchema,
45
+ expressionNodeSchema,
46
+ expressionEntrySchema,
47
+ unaryOperatorSchema,
48
+ binaryOperatorSchema,
49
+ assignmentOperatorSchema,
50
+ noArgMethodSchema,
51
+ oneArgMethodSchema,
52
+ spliceMethodSchema,
53
+ reduceMethodSchema,
54
+ mapFilterMethodSchema,
55
+ } from "./expression-node.schema";
56
+
57
+ // State/defs maps
58
+ export {
59
+ stateEntrySchema,
60
+ stateMapSchema,
61
+ defsMapSchema,
62
+ typeDefEntrySchema,
63
+ } from "./state-entry.schema";
64
+
65
+ // Class definitions
66
+ export {
67
+ classParameterDefSchema,
68
+ classFieldDefSchema,
69
+ classConstructorDefSchema,
70
+ classMethodDefSchema,
71
+ classDefSchema,
72
+ } from "./class-def.schema";
73
+
74
+ // Content & project
75
+ export { contentTypeDefSchema } from "./content-type-def.schema";
76
+ export { projectConfigSchema } from "./project-config.schema";
@@ -0,0 +1,4 @@
1
+ export const jsonSchemaTypeSchema = {
2
+ type: "string",
3
+ enum: ["string", "number", "integer", "boolean", "array", "object", "null"],
4
+ } as const;
@@ -0,0 +1,199 @@
1
+ export const projectConfigSchema = {
2
+ description:
3
+ "Schema for Jx project.json files. " +
4
+ "A project.json file is the root anchor file for a Jx project, " +
5
+ "declaring site metadata, default settings, global styles, content types, " +
6
+ "and build configuration.",
7
+ type: "object",
8
+ properties: {
9
+ name: {
10
+ description: "Human-readable project name.",
11
+ type: "string",
12
+ default: "Jx Site",
13
+ examples: ["My Portfolio", "Jx Example Site"],
14
+ },
15
+ url: {
16
+ description: "Production URL of the deployed site.",
17
+ type: "string",
18
+ examples: ["https://example.com", "https://jxsuite.com"],
19
+ },
20
+ defaults: {
21
+ description: "Default settings applied to all pages unless overridden.",
22
+ type: "object",
23
+ properties: {
24
+ layout: {
25
+ description:
26
+ "Default layout file path applied to all pages. " +
27
+ "Set to null to render pages without a layout.",
28
+ oneOf: [{ type: "string" }, { type: "null" }],
29
+ default: null,
30
+ examples: ["./layouts/base.json"],
31
+ },
32
+ lang: {
33
+ description: "Default lang attribute for the <html> element.",
34
+ type: "string",
35
+ default: "en",
36
+ },
37
+ charset: {
38
+ description: "Default charset for the page.",
39
+ type: "string",
40
+ default: "utf-8",
41
+ },
42
+ },
43
+ },
44
+ $head: {
45
+ description:
46
+ "Global <head> entries applied to all pages. " +
47
+ "Array of element definitions for meta tags, link tags, script tags, etc.",
48
+ type: "array",
49
+ items: {
50
+ type: "object",
51
+ properties: {
52
+ tagName: { type: "string" },
53
+ attributes: {
54
+ type: "object",
55
+ additionalProperties: { type: "string" },
56
+ },
57
+ },
58
+ },
59
+ examples: [
60
+ [
61
+ { tagName: "link", attributes: { rel: "icon", href: "/favicon.svg" } },
62
+ { tagName: "meta", attributes: { name: "generator", content: "Jx" } },
63
+ ],
64
+ ],
65
+ },
66
+ $elements: {
67
+ description:
68
+ "Global custom element dependencies available to all pages. " +
69
+ "Items are $ref objects or npm package specifier strings.",
70
+ type: "array",
71
+ items: {
72
+ oneOf: [
73
+ {
74
+ type: "object",
75
+ required: ["$ref"],
76
+ properties: { $ref: { type: "string" } },
77
+ additionalProperties: false,
78
+ },
79
+ { type: "string" },
80
+ ],
81
+ },
82
+ },
83
+ imports: {
84
+ description:
85
+ "Global import map: $prototype names to .class.json file paths. " +
86
+ "Makes external classes available by name in all pages.",
87
+ type: "object",
88
+ additionalProperties: { type: "string" },
89
+ examples: [
90
+ {
91
+ MarkdownFile: "@jxsuite/parser/MarkdownFile.class.json",
92
+ MarkdownCollection: "@jxsuite/parser/MarkdownCollection.class.json",
93
+ },
94
+ ],
95
+ },
96
+ $media: {
97
+ description:
98
+ "Named media breakpoints following CSS @custom-media convention. " +
99
+ "Available in all component style objects.",
100
+ type: "object",
101
+ additionalProperties: { type: "string" },
102
+ examples: [
103
+ {
104
+ "--sm": "(min-width: 640px)",
105
+ "--md": "(min-width: 768px)",
106
+ "--lg": "(min-width: 1024px)",
107
+ },
108
+ ],
109
+ },
110
+ style: {
111
+ description:
112
+ "Global CSS styles applied to the <body> element. " +
113
+ "Uses the same camelCase CSSOM convention as component styles.",
114
+ type: "object",
115
+ additionalProperties: {
116
+ oneOf: [{ type: "string" }, { type: "number" }, { type: "object" }],
117
+ },
118
+ },
119
+ state: {
120
+ description: "Site-wide reactive state available to all pages.",
121
+ type: "object",
122
+ },
123
+ $defs: {
124
+ description: "Global type definitions available to all pages.",
125
+ type: "object",
126
+ },
127
+ contentTypes: {
128
+ description:
129
+ "Content type definitions. Each key is a content type name; " +
130
+ "the value defines the source directory, frontmatter schema, and element dependencies.",
131
+ type: "object",
132
+ additionalProperties: { $ref: "#/$defs/ContentTypeDef" },
133
+ },
134
+ redirects: {
135
+ description: "Static redirect rules. Maps source paths to destination paths.",
136
+ type: "object",
137
+ additionalProperties: { type: "string" },
138
+ examples: [{ "/old-about": "/about" }],
139
+ },
140
+ copy: {
141
+ description:
142
+ "Declarative file copy map. Keys are source paths (relative to project root), values are destination paths (relative to outDir).",
143
+ type: "object",
144
+ additionalProperties: { type: "string" },
145
+ },
146
+ build: {
147
+ description: "Build configuration.",
148
+ type: "object",
149
+ properties: {
150
+ outDir: {
151
+ description: "Output directory for compiled site.",
152
+ type: "string",
153
+ default: "./dist",
154
+ },
155
+ format: {
156
+ description: "Output format.",
157
+ type: "string",
158
+ enum: ["directory", "single"],
159
+ default: "directory",
160
+ },
161
+ trailingSlash: {
162
+ description: "Trailing slash behavior for generated URLs.",
163
+ type: "string",
164
+ enum: ["always", "never", "ignore"],
165
+ default: "always",
166
+ },
167
+ adapter: {
168
+ description: "Platform adapter for deployment-specific output.",
169
+ type: "string",
170
+ enum: ["netlify", "vercel", "cloudflare"],
171
+ },
172
+ },
173
+ },
174
+ images: { $ref: "#/$defs/ImageConfig" },
175
+ i18n: {
176
+ description: "Internationalization configuration.",
177
+ type: "object",
178
+ properties: {
179
+ defaultLocale: {
180
+ description: "Default locale code.",
181
+ type: "string",
182
+ examples: ["en"],
183
+ },
184
+ locales: {
185
+ description: "Available locale codes.",
186
+ type: "array",
187
+ items: { type: "string" },
188
+ examples: [["en", "fr", "de"]],
189
+ },
190
+ routing: {
191
+ description: "Locale routing strategy.",
192
+ type: "string",
193
+ enum: ["prefix-except-default", "prefix-always"],
194
+ },
195
+ },
196
+ },
197
+ },
198
+ additionalProperties: false,
199
+ } as const;
@@ -0,0 +1,26 @@
1
+ export const pureTypeDefSchema = {
2
+ description:
3
+ "A reusable JSON Schema type definition for tooling only. " +
4
+ "No function, no runtime artifact. " +
5
+ "Referenced from state entries via $ref. " +
6
+ "Naming convention: PascalCase.",
7
+ type: "object",
8
+ required: ["type"],
9
+ properties: {
10
+ type: { $ref: "#/$defs/JsonSchemaType" },
11
+ description: { type: "string" },
12
+ enum: { type: "array" },
13
+ minimum: { type: "number" },
14
+ maximum: { type: "number" },
15
+ minLength: { type: "integer", minimum: 0 },
16
+ maxLength: { type: "integer", minimum: 0 },
17
+ pattern: { type: "string" },
18
+ items: {},
19
+ properties: { type: "object" },
20
+ required: { type: "array", items: { type: "string" } },
21
+ examples: { type: "array" },
22
+ },
23
+ not: {
24
+ anyOf: [{ required: ["default"] }, { required: ["$prototype"] }],
25
+ },
26
+ } as const;
@@ -0,0 +1,70 @@
1
+ export const internalRefSchema = {
2
+ description: "Reference to a $defs type definition in the current component.",
3
+ type: "string",
4
+ pattern: "^#/\\$defs/",
5
+ examples: ["#/$defs/Count", "#/$defs/TodoItem", "#/$defs/Status"],
6
+ } as const;
7
+
8
+ export const stateRefSchema = {
9
+ description: "Reference to a state entry (runtime variable) in the current component.",
10
+ type: "string",
11
+ pattern: "^#/state/",
12
+ examples: ["#/state/count", "#/state/addTask", "#/state/items"],
13
+ } as const;
14
+
15
+ export const externalRefSchema = {
16
+ description: "Reference to an external Jx component file.",
17
+ type: "string",
18
+ pattern: "^(\\./|\\.\\./).*\\.json$|^https?://",
19
+ examples: ["./card.json", "https://cdn.example.com/button.json"],
20
+ } as const;
21
+
22
+ export const globalRefSchema = {
23
+ description: "Reference to a window or document global.",
24
+ type: "string",
25
+ pattern: "^(window|document)#/",
26
+ examples: ["window#/currentUser", "document#/appConfig"],
27
+ } as const;
28
+
29
+ export const parentRefSchema = {
30
+ description: "Reference to a named state entry passed via $props from a parent component.",
31
+ type: "string",
32
+ pattern: "^parent#/",
33
+ examples: ["parent#/sharedState", "parent#/theme"],
34
+ } as const;
35
+
36
+ export const mapRefSchema = {
37
+ description: "Reference to the current Array map iteration context.",
38
+ type: "string",
39
+ pattern: "^\\$map/(item|index)(/.*)?$",
40
+ examples: ["$map/item", "$map/index", "$map/item/text", "$map/item/done"],
41
+ } as const;
42
+
43
+ export const anyRefSchema = {
44
+ type: "string",
45
+ oneOf: [
46
+ { $ref: "#/$defs/InternalRef" },
47
+ { $ref: "#/$defs/StateRef" },
48
+ { $ref: "#/$defs/ExternalRef" },
49
+ { $ref: "#/$defs/GlobalRef" },
50
+ { $ref: "#/$defs/ParentRef" },
51
+ { $ref: "#/$defs/MapRef" },
52
+ ],
53
+ } as const;
54
+
55
+ export const refObjectSchema = {
56
+ description: "A $ref binding. Resolves to a state entry (reactive) or plain value (static).",
57
+ type: "object",
58
+ required: ["$ref"],
59
+ properties: { $ref: { $ref: "#/$defs/AnyRef" } },
60
+ additionalProperties: false,
61
+ } as const;
62
+
63
+ export const externalComponentRefSchema = {
64
+ type: "object",
65
+ required: ["$ref"],
66
+ properties: {
67
+ $ref: { $ref: "#/$defs/ExternalRef" },
68
+ $props: { $ref: "#/$defs/PropsObject" },
69
+ },
70
+ } as const;
@@ -0,0 +1,54 @@
1
+ export const stateEntrySchema = {
2
+ description:
3
+ "A single state entry. Shape is determined by value type: " +
4
+ "scalar/array → naked reactive property, string with ${} → computed, " +
5
+ 'object with $prototype: "Function" → function, ' +
6
+ "object with $prototype: <other> → data source, " +
7
+ "object with type and default → typed reactive property, " +
8
+ "plain object → naked object reactive property.",
9
+ oneOf: [
10
+ { type: "number" },
11
+ { type: "boolean" },
12
+ { type: "null" },
13
+ { type: "string" },
14
+ { type: "array" },
15
+ { $ref: "#/$defs/TypedStateDef" },
16
+ { $ref: "#/$defs/FunctionDef" },
17
+ { $ref: "#/$defs/ExternalClassDef" },
18
+ { $ref: "#/$defs/ExpressionEntry" },
19
+ {
20
+ type: "object",
21
+ not: {
22
+ anyOf: [
23
+ { required: ["$prototype"] },
24
+ { required: ["default"] },
25
+ { required: ["type"] },
26
+ { required: ["$expression"] },
27
+ ],
28
+ },
29
+ },
30
+ ],
31
+ } as const;
32
+
33
+ export const stateMapSchema = {
34
+ description:
35
+ "Map of runtime variables. Keys are camelCase (public) or #-prefixed (private). " +
36
+ "All entries are reactive by default.",
37
+ type: "object",
38
+ additionalProperties: { $ref: "#/$defs/StateEntry" },
39
+ } as const;
40
+
41
+ export const defsMapSchema = {
42
+ description:
43
+ "Map of reusable JSON Schema type definitions. " +
44
+ "Keys are PascalCase type names. No runtime artifacts are produced.",
45
+ type: "object",
46
+ additionalProperties: { $ref: "#/$defs/TypeDefEntry" },
47
+ } as const;
48
+
49
+ export const typeDefEntrySchema = {
50
+ description:
51
+ "A $defs type definition entry. Must be a pure JSON Schema type " +
52
+ "definition or a class definition (.class.json format).",
53
+ oneOf: [{ $ref: "#/$defs/PureTypeDef" }, { $ref: "#/$defs/ClassDef" }],
54
+ } as const;
@@ -0,0 +1,11 @@
1
+ export const stringOrRefSchema = {
2
+ oneOf: [{ type: "string" }, { $ref: "#/$defs/RefObject" }],
3
+ } as const;
4
+
5
+ export const boolOrRefSchema = {
6
+ oneOf: [{ type: "boolean" }, { $ref: "#/$defs/RefObject" }],
7
+ } as const;
8
+
9
+ export const numberOrRefSchema = {
10
+ oneOf: [{ type: "number" }, { $ref: "#/$defs/RefObject" }],
11
+ } as const;
@@ -0,0 +1,19 @@
1
+ export const styleObjectSchema = {
2
+ description:
3
+ "CSS style definition. camelCase property names follow CSSOM convention. " +
4
+ "Keys starting with :, ., &, or [ are treated as nested CSS selectors. " +
5
+ "Keys matching $media breakpoint names are treated as responsive rules.",
6
+ type: "object",
7
+ properties: {},
8
+ additionalProperties: {
9
+ oneOf: [
10
+ { type: "string" },
11
+ { type: "number" },
12
+ {
13
+ description: "Nested CSS selector or media breakpoint rules.",
14
+ type: "object",
15
+ additionalProperties: { oneOf: [{ type: "string" }, { type: "number" }] },
16
+ },
17
+ ],
18
+ },
19
+ } as const;
@@ -0,0 +1,6 @@
1
+ export const tagNameSchema = {
2
+ description:
3
+ "HTML element tag name or custom element name (must contain a hyphen per Web Components spec).",
4
+ type: "string",
5
+ minLength: 1,
6
+ } as const;
@@ -0,0 +1,31 @@
1
+ export const typedStateDefSchema = {
2
+ description:
3
+ "A typed reactive state variable with explicit type and default value. " +
4
+ "The type property is a JSON Schema or $ref to a $defs type definition. " +
5
+ "The default property is the initial runtime value.",
6
+ type: "object",
7
+ required: ["default"],
8
+ properties: {
9
+ default: { description: "Initial state value." },
10
+ type: {
11
+ description: "JSON Schema type definition, $ref to a $defs type, or JSON Schema type string.",
12
+ oneOf: [{ type: "string" }, { type: "object" }],
13
+ },
14
+ description: { type: "string" },
15
+ attribute: {
16
+ description: "Linked HTML attribute name for CEM extraction.",
17
+ type: "string",
18
+ },
19
+ reflects: {
20
+ description: "Whether property changes reflect back to the HTML attribute.",
21
+ type: "boolean",
22
+ },
23
+ deprecated: {
24
+ description: "Deprecation notice for CEM extraction.",
25
+ oneOf: [{ type: "boolean" }, { type: "string" }],
26
+ },
27
+ examples: { type: "array" },
28
+ $ref: { description: "Reference to a shared type definition.", type: "string" },
29
+ },
30
+ not: { required: ["$prototype"] },
31
+ } as const;
package/package.json CHANGED
@@ -6,12 +6,16 @@
6
6
  },
7
7
  "description": "JSON Schema 2020-12 meta-schema generator for Jx documents",
8
8
  "exports": {
9
- ".": "./src/schema.js",
9
+ ".": "./src/schema.ts",
10
+ "./types": "./types.ts",
11
+ "./defs": "./defs/index.ts",
10
12
  "./schema.json": "./schema.json",
11
13
  "./project-schema.json": "./project-schema.json"
12
14
  },
13
15
  "files": [
14
16
  "src/",
17
+ "defs/",
18
+ "types.ts",
15
19
  "*.json",
16
20
  "!package.json"
17
21
  ],
@@ -26,11 +30,14 @@
26
30
  "url": "git+https://github.com/jxsuite/jx.git"
27
31
  },
28
32
  "scripts": {
29
- "schema": "bun run src/schema.js",
30
- "test": "bun test",
31
- "test:coverage": "bun test --coverage",
33
+ "schema": "bun run src/schema.ts",
34
+ "test": "bun test --isolate",
35
+ "test:coverage": "bun test --isolate --coverage",
32
36
  "upgrade": "bunx npm-check-updates -u && bun install"
33
37
  },
34
38
  "type": "module",
35
- "version": "0.23.1"
39
+ "version": "0.24.0",
40
+ "devDependencies": {
41
+ "json-schema-to-ts": "^3.1.1"
42
+ }
36
43
  }