@jxsuite/schema 0.28.2 → 0.28.3

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/types.ts CHANGED
@@ -1,31 +1,32 @@
1
1
  import type { FromSchema } from "json-schema-to-ts";
2
2
 
3
- import { headEntrySchema } from "./defs/head-entry.schema";
4
- import { imageConfigSchema } from "./defs/image-config.schema";
5
- import { cemParameterSchema, cemEventSchema } from "./defs/cem.schema";
6
- import { contentTypeDefSchema } from "./defs/content-type-def.schema";
7
- import { projectConfigSchema } from "./defs/project-config.schema";
8
- import { refObjectSchema } from "./defs/ref-object.schema";
9
- import { styleObjectSchema } from "./defs/style-object.schema";
10
- import { elementDefSchema } from "./defs/element-def.schema";
11
- import { functionDefSchema } from "./defs/function-def.schema";
12
- import { externalClassDefSchema } from "./defs/external-class-def.schema";
13
- import { typedStateDefSchema } from "./defs/typed-state-def.schema";
14
- import { pureTypeDefSchema } from "./defs/pure-type-def.schema";
15
- import { expressionNodeSchema, expressionEntrySchema } from "./defs/expression-node.schema";
16
- import { stateEntrySchema, stateMapSchema, defsMapSchema } from "./defs/state-entry.schema";
17
- import {
3
+ import type { headEntrySchema } from "./defs/head-entry.schema";
4
+ import type { imageConfigSchema } from "./defs/image-config.schema";
5
+ import type { cemEventSchema, cemParameterSchema } from "./defs/cem.schema";
6
+ import type { contentTypeDefSchema } from "./defs/content-type-def.schema";
7
+ import type { projectConfigSchema } from "./defs/project-config.schema";
8
+ import type { refObjectSchema } from "./defs/ref-object.schema";
9
+ import type { styleObjectSchema } from "./defs/style-object.schema";
10
+ import type { elementDefSchema } from "./defs/element-def.schema";
11
+ import type { functionDefSchema } from "./defs/function-def.schema";
12
+ import type { externalClassDefSchema } from "./defs/external-class-def.schema";
13
+ import type { typedStateDefSchema } from "./defs/typed-state-def.schema";
14
+ import type { pureTypeDefSchema } from "./defs/pure-type-def.schema";
15
+ import type { expressionEntrySchema, expressionNodeSchema } from "./defs/expression-node.schema";
16
+ import type { defsMapSchema, stateEntrySchema, stateMapSchema } from "./defs/state-entry.schema";
17
+ import type {
18
+ classConstructorDefSchema,
18
19
  classDefSchema,
19
20
  classFieldDefSchema,
20
21
  classMethodDefSchema,
21
22
  classParameterDefSchema,
22
- classConstructorDefSchema,
23
23
  } from "./defs/class-def.schema";
24
24
 
25
25
  // ─── Strict Schema-Derived Types ────────────────────────────────────────────────
26
26
  // These are the precise types derived from the JSON Schema defs via FromSchema.
27
27
  // Use these when you need exact schema conformance (e.g., validation, serialization).
28
28
 
29
+ // oxlint-disable typescript/no-namespace, no-shadow -- type-only grouping of schema-derived types whose members intentionally mirror the loose top-level type names (Strict.ImageConfig vs ImageConfig); an ES module split would fragment the schema package's public surface
29
30
  export namespace Strict {
30
31
  export type HeadEntry = FromSchema<typeof headEntrySchema>;
31
32
  export type ImageConfig = FromSchema<typeof imageConfigSchema>;
@@ -51,10 +52,102 @@ export namespace Strict {
51
52
  export type ClassConstructorDef = FromSchema<typeof classConstructorDefSchema>;
52
53
  export type ProjectConfig = FromSchema<typeof projectConfigSchema>;
53
54
  }
55
+ // oxlint-enable typescript/no-namespace, no-shadow
56
+
57
+ // ─── JSON Value Model ───────────────────────────────────────────────────────────
58
+ // Jx documents are JSON. These types describe what can actually appear in one,
59
+ // As opposed to `unknown` (nothing known) or `any` (checking disabled).
60
+
61
+ export type JsonPrimitive = string | number | boolean | null;
62
+ export type JsonValue = JsonPrimitive | JsonValue[] | JsonObject;
63
+ export interface JsonObject {
64
+ [key: string]: JsonValue;
65
+ }
66
+
67
+ // ─── Binding Model ──────────────────────────────────────────────────────────────
68
+ // Any bindable position in a document holds either a literal value or a JSON
69
+ // Pointer reference into the reactive scope.
70
+
71
+ /**
72
+ * A JSON Pointer reference into document state, e.g. `{ $ref: "#/state/count" }`. (A type literal
73
+ * rather than an interface so it stays assignable to JsonValue.)
74
+ */
75
+ export interface JxRef {
76
+ $ref: string;
77
+ }
78
+
79
+ /** A value that may be given literally or bound via `$ref`. */
80
+ export type Bindable<T> = T | JxRef;
81
+
82
+ // ─── Expression Model ───────────────────────────────────────────────────────────
83
+ // Declarative expressions: operator + target (+ value), with operands that are
84
+ // Pointers, literals, or nested expression nodes.
85
+
86
+ export type JxExpressionOperand =
87
+ | JxRef
88
+ | JxExpressionNode
89
+ | string
90
+ | number
91
+ | boolean
92
+ | null
93
+ | JxExpressionOperand[];
94
+
95
+ export interface JxExpressionNode {
96
+ operator: string;
97
+ target: JxExpressionOperand;
98
+ value?: JxExpressionOperand;
99
+ initial?: JxExpressionOperand;
100
+ }
101
+
102
+ /** A state entry (or event binding) whose value is computed from a declarative expression. */
103
+ export interface JxExpressionDef {
104
+ $expression: JxExpressionNode;
105
+ [key: string]: unknown;
106
+ }
107
+
108
+ // ─── State Definition Model ─────────────────────────────────────────────────────
109
+ // The shapes a `state` entry can take, mirroring the runtime's five-shape
110
+ // Detection algorithm in buildScope(). Use the guards in `@jxsuite/schema/guards`
111
+ // To discriminate.
112
+
113
+ /** A function declaration: inline `body` or external `$src`/`$export`. */
114
+ export interface JxFunctionDef {
115
+ $prototype: "Function";
116
+ /** Inline function body. The reactive scope is the implicit first parameter. */
117
+ body?: string;
118
+ /** Parameters after the implicit scope parameter: bare names or CEM parameter objects. */
119
+ parameters?: (string | CemParameter)[];
120
+ /** Explicit function name; defaults to the state key. */
121
+ name?: string;
122
+ /** External module specifier; mutually exclusive with `body`. */
123
+ $src?: string;
124
+ /** Named export within `$src`; defaults to the state key. */
125
+ $export?: string;
126
+ /** Legacy alias for `parameters` (bare names only). */
127
+ arguments?: string[];
128
+ timing?: "compiler" | "server" | "client";
129
+ debounce?: number;
130
+ emits?: CemEvent[];
131
+ description?: string;
132
+ deprecated?: string | boolean;
133
+ [key: string]: unknown;
134
+ }
135
+
136
+ /** A `timing: "server"` function proxy — executed server-side, no `$prototype`. */
137
+ export interface JxServerFnDef {
138
+ timing: "server";
139
+ $src: string;
140
+ $export: string;
141
+ parameters?: (string | CemParameter)[];
142
+ /** Named arguments forwarded to the server function: literals or `$ref` bindings. */
143
+ arguments?: Record<string, JsonValue>;
144
+ debounce?: number;
145
+ [key: string]: unknown;
146
+ }
54
147
 
55
148
  // ─── Consumer-Friendly Types ────────────────────────────────────────────────────
56
149
  // Relaxed types for everyday use in the runtime/compiler/studio. These add an index
57
- // signature for dynamic property access while preserving the known property structure.
150
+ // Signature for dynamic property access while preserving the known property structure.
58
151
 
59
152
  export interface JxHeadEntry {
60
153
  tagName: string;
@@ -75,24 +168,39 @@ export interface ImageConfig {
75
168
  remoteDomains?: string[];
76
169
  }
77
170
 
78
- export type CemParameter = FromSchema<typeof cemParameterSchema>;
79
- export type CemEvent = FromSchema<typeof cemEventSchema>;
171
+ /** A CEM-compatible function parameter. JSON-precise (assignable to JsonValue). */
172
+ export interface CemParameter {
173
+ name: string;
174
+ /** Parameter type — JSON Schema or CEM `{ text }` format. */
175
+ type?: JsonValue;
176
+ description?: string;
177
+ optional?: boolean;
178
+ default?: JsonValue;
179
+ }
180
+
181
+ /** A CEM-compatible event a function dispatches. JSON-precise (assignable to JsonValue). */
182
+ export interface CemEvent {
183
+ name: string;
184
+ type?: JsonValue;
185
+ description?: string;
186
+ deprecated?: boolean | string;
187
+ }
80
188
 
81
189
  export type ContentTypeDef = FromSchema<typeof contentTypeDefSchema>;
82
190
 
83
191
  export type RefObject = FromSchema<typeof refObjectSchema>;
84
192
 
85
- export type JxStyle = {
193
+ export interface JxStyle {
86
194
  [property: string]: string | number | JxStyle | undefined;
87
- };
195
+ }
88
196
 
89
197
  export interface JxElement {
90
198
  tagName?: string;
91
- textContent?: string | null;
199
+ textContent?: string | null | JxRef;
92
200
  innerHTML?: string;
93
201
  children?: (JxElement | string)[] | JxMappedArray;
94
202
  style?: JxStyle;
95
- attributes?: Record<string, unknown>;
203
+ attributes?: Record<string, JxAttributeValue>;
96
204
  className?: string;
97
205
  id?: string;
98
206
  hidden?: boolean;
@@ -101,8 +209,8 @@ export interface JxElement {
101
209
  lang?: string;
102
210
  dir?: string;
103
211
  $ref?: string;
104
- $props?: Record<string, unknown>;
105
- $switch?: { $ref: string };
212
+ $props?: Record<string, JsonValue>;
213
+ $switch?: string | JxRef;
106
214
  cases?: Record<string, JxElement>;
107
215
  $prototype?: string;
108
216
  $static?: boolean;
@@ -117,18 +225,20 @@ export interface JxElement {
117
225
 
118
226
  export interface JxMappedArray {
119
227
  $prototype: "Array";
120
- items: { $ref: string } | unknown;
228
+ items: Bindable<JsonValue[]>;
121
229
  map?: JxElement;
122
- filter?: { $ref: string } | unknown;
123
- sort?: { $ref: string } | unknown;
230
+ filter?: Bindable<string>;
231
+ sort?: Bindable<string>;
124
232
  }
125
233
 
126
234
  export interface JxDocument extends JxElement {
127
235
  state?: Record<string, JxStateDefinition>;
236
+ $layout?: string | false;
237
+ $paths?: JxPathsDef;
128
238
  $elements?: (JxElement | string)[];
129
239
  $head?: JxHeadEntry[];
130
240
  $media?: Record<string, string>;
131
- $defs?: Record<string, unknown>;
241
+ $defs?: Record<string, JsonValue>;
132
242
  imports?: Record<string, string>;
133
243
  }
134
244
 
@@ -143,35 +253,88 @@ export type PureTypeDef = FromSchema<typeof pureTypeDefSchema>;
143
253
  export type ExpressionNode = FromSchema<typeof expressionNodeSchema>;
144
254
  export type ExpressionEntry = FromSchema<typeof expressionEntrySchema>;
145
255
 
146
- export type JxStateDefinition = string | number | boolean | null | JxStateObject | JxPrototypeDef;
256
+ /**
257
+ * Every shape a `state` entry can take — the runtime's five-shape detection algorithm: naked values
258
+ * (Shape 1), expanded signals / pure type defs (Shape 2/2b), function declarations (Shape 4),
259
+ * expressions (Shape 5), prototype instances, and server function proxies. Discriminate with the
260
+ * guards in `@jxsuite/schema/guards`.
261
+ */
262
+ export type JxStateDefinition =
263
+ | JsonPrimitive
264
+ | JsonValue[]
265
+ | JxFunctionDef
266
+ | JxPrototypeDef
267
+ | JxExpressionDef
268
+ | JxServerFnDef
269
+ | JxStateObject;
147
270
 
271
+ /** An expanded signal (`{ default }`), pure type definition, or naked plain object. */
148
272
  export interface JxStateObject {
149
273
  type?: string;
150
- default?: unknown;
151
- properties?: Record<string, unknown>;
152
- items?: unknown;
153
- enum?: unknown[];
274
+ default?: JsonValue;
275
+ properties?: Record<string, JxStateObject>;
276
+ items?: JxStateObject | JxStateObject[];
277
+ enum?: JsonValue[];
278
+ description?: string;
279
+ /** Linked HTML attribute name for CEM extraction. */
280
+ attribute?: string;
281
+ /** Whether property changes reflect back to the HTML attribute. */
282
+ reflects?: boolean;
283
+ deprecated?: string | boolean;
154
284
  [key: string]: unknown;
155
285
  }
156
286
 
287
+ /** A `$prototype` instance entry (Request, Storage, ContentCollection, custom classes, …). */
157
288
  export interface JxPrototypeDef {
158
289
  $prototype: string;
159
290
  $src?: string;
160
291
  $export?: string;
161
- body?: string;
162
- parameters?: string[];
292
+ /** Function body (Function entries) or request body (Request entries). */
293
+ body?: string | JsonObject;
294
+ parameters?: (string | CemParameter)[];
163
295
  arguments?: string[];
164
296
  timing?: "compiler" | "server" | "client";
165
- default?: unknown;
297
+ default?: JsonValue;
166
298
  debounce?: number;
167
299
  contentType?: string;
168
- filter?: Record<string, unknown>;
300
+ filter?: Record<string, JsonValue>;
169
301
  sort?: { field: string; order?: string };
170
302
  limit?: number;
171
- id?: string | { $ref: string };
303
+ id?: Bindable<string>;
304
+ /** Request prototype config. */
305
+ url?: string;
306
+ method?: string;
307
+ manual?: boolean;
308
+ headers?: Record<string, string>;
309
+ /** Storage prototype config (LocalStorage / SessionStorage key). */
310
+ key?: string;
311
+ /** Cookie prototype config. */
312
+ name?: string;
313
+ maxAge?: number;
314
+ path?: string;
315
+ domain?: string;
316
+ secure?: boolean;
317
+ sameSite?: string;
318
+ /** IndexedDB prototype config. */
319
+ database?: string;
320
+ store?: string;
321
+ version?: number;
322
+ keyPath?: string;
323
+ autoIncrement?: boolean;
324
+ indexes?: { name: string; keyPath: string; unique?: boolean }[];
325
+ /** FormData prototype config. */
326
+ fields?: Record<string, JsonValue>;
172
327
  [key: string]: unknown;
173
328
  }
174
329
 
330
+ // ─── Event Binding Model ────────────────────────────────────────────────────────
331
+
332
+ /**
333
+ * The value of an `on*` document key: a `$ref` to a state function, an inline function declaration,
334
+ * or a declarative expression.
335
+ */
336
+ export type JxEventBinding = JxRef | JxFunctionDef | JxExpressionDef;
337
+
175
338
  export type StateMap = FromSchema<typeof stateMapSchema>;
176
339
  export type DefsMap = FromSchema<typeof defsMapSchema>;
177
340
 
@@ -181,6 +344,84 @@ export type ClassMethodDef = FromSchema<typeof classMethodDefSchema>;
181
344
  export type ClassParameterDef = FromSchema<typeof classParameterDefSchema>;
182
345
  export type ClassConstructorDef = FromSchema<typeof classConstructorDefSchema>;
183
346
 
347
+ // ─── Class Definition Model (consumer-friendly) ────────────────────────────────
348
+ // Working types for .class.json schema-defined classes, mirroring class-def.schema.
349
+
350
+ /** A typed parameter definition (or a `$ref` into `$defs/parameters`). */
351
+ export interface JxClassParamDef {
352
+ identifier?: string;
353
+ $ref?: string;
354
+ type?: unknown;
355
+ format?: string;
356
+ default?: JsonValue;
357
+ description?: string;
358
+ [key: string]: unknown;
359
+ }
360
+
361
+ export interface JxClassFieldDef {
362
+ role?: "field";
363
+ access?: "public" | "private" | "protected";
364
+ scope?: "instance" | "static";
365
+ identifier?: string;
366
+ type?: unknown;
367
+ $prototype?: string;
368
+ initializer?: JsonValue;
369
+ default?: JsonValue;
370
+ description?: string;
371
+ [key: string]: unknown;
372
+ }
373
+
374
+ export interface JxClassCtorDef {
375
+ role?: "constructor";
376
+ $prototype?: "Function";
377
+ parameters?: JxClassParamDef[];
378
+ superCall?: { arguments?: string[] };
379
+ body?: string | string[];
380
+ description?: string;
381
+ [key: string]: unknown;
382
+ }
383
+
384
+ export interface JxClassMethodDef {
385
+ role?: "method" | "accessor" | "parse" | "serialize" | "discover" | "load";
386
+ $prototype?: "Function";
387
+ access?: "public" | "private" | "protected";
388
+ scope?: "instance" | "static";
389
+ identifier?: string;
390
+ timing?: ("compiler" | "server" | "client")[];
391
+ parameters?: JxClassParamDef[];
392
+ returnType?: { $ref?: string };
393
+ body?: string | string[];
394
+ getter?: { body?: string };
395
+ setter?: { parameters?: JxClassParamDef[]; body?: string };
396
+ description?: string;
397
+ [key: string]: unknown;
398
+ }
399
+
400
+ /** A .class.json document: `$prototype: "Class"` with fields/constructor/methods in `$defs`. */
401
+ export interface JxClassDef {
402
+ $prototype: "Class";
403
+ $schema?: string;
404
+ $id?: string;
405
+ title?: string;
406
+ description?: string;
407
+ extends?: string | JxRef;
408
+ $implementation?: string;
409
+ $defs?: {
410
+ fields?: Record<string, JxClassFieldDef>;
411
+ /**
412
+ * The constructor definition. On objects parsed from JSON without an explicit "constructor"
413
+ * key, plain property access yields `Object.prototype.constructor` (a Function) — narrow with
414
+ * `typeof === "object"` before use.
415
+ */
416
+ // oxlint-disable-next-line typescript/ban-types, typescript/no-unsafe-function-type -- only `Function` absorbs the inherited Object.prototype.constructor on plain object literals
417
+ constructor?: JxClassCtorDef | Function;
418
+ methods?: Record<string, JxClassMethodDef>;
419
+ parameters?: Record<string, JxClassParamDef>;
420
+ [key: string]: unknown;
421
+ };
422
+ [key: string]: unknown;
423
+ }
424
+
184
425
  export interface ProjectConfig {
185
426
  name?: string;
186
427
  url?: string;
@@ -193,36 +434,73 @@ export interface ProjectConfig {
193
434
  images?: ImageConfig;
194
435
  imports?: Record<string, string>;
195
436
  contentTypes?: Record<string, ContentTypeDef>;
196
- defaults?: { layout?: string; lang?: string; charset?: string; [key: string]: unknown };
437
+ /** Redirect map: source path → destination (or destination with HTTP status). */
438
+ redirects?: Record<string, string | { destination: string; status?: number }>;
439
+ defaults?: {
440
+ /** Default layout path; `null` means explicitly no layout. */
441
+ layout?: string | null;
442
+ lang?: string;
443
+ charset?: string;
444
+ [key: string]: unknown;
445
+ };
197
446
  style?: JxStyle;
198
447
  [key: string]: unknown;
199
448
  }
200
449
 
201
450
  // ─── Editor/Mutation Types ──────────────────────────────────────────────────────
202
451
 
452
+ /** The value of an HTML attribute in a document: a literal or a `$ref` binding. */
453
+ export type JxAttributeValue = Bindable<string | number | boolean>;
454
+
455
+ /**
456
+ * A dynamic-route path source (spec §4.3): content-type based, explicit values, data-file ref, or a
457
+ * legacy array of param objects.
458
+ */
459
+ export type JxPathsDef =
460
+ | { contentType: string; param?: string; field?: string }
461
+ | { values: JsonValue[]; param?: string }
462
+ | { $ref: string; param?: string; field?: string }
463
+ | Record<string, JsonValue>[];
464
+
465
+ /**
466
+ * The editor's working representation of a document node. Known properties are fully typed;
467
+ * unrecognized keys (open schema) surface as `unknown` and must be narrowed with the guards in
468
+ * `@jxsuite/schema/guards` before use.
469
+ */
203
470
  export interface JxMutableNode {
204
471
  tagName?: string;
205
- textContent?: string | null;
472
+ textContent?: string | null | JxRef;
206
473
  innerHTML?: string;
207
- children?: (JxMutableNode | string)[];
208
- style?: Record<string, any>;
209
- attributes?: Record<string, any>;
474
+ children?: (JxMutableNode | string)[] | JxMappedArray;
475
+ style?: JxStyle;
476
+ attributes?: Record<string, JxAttributeValue>;
210
477
  className?: string;
211
478
  id?: string;
479
+ title?: string;
212
480
  $ref?: string;
213
- $props?: Record<string, unknown>;
214
- $switch?: string | { $ref: string };
481
+ $props?: Record<string, JsonValue>;
482
+ $switch?: string | JxRef;
215
483
  cases?: Record<string, JxMutableNode>;
216
484
  $prototype?: string;
217
485
  $title?: string;
218
486
  $id?: string;
219
487
  $src?: string;
220
- state?: Record<string, any>;
221
- $elements?: (JxMutableNode | string | { $ref: string })[];
488
+ $layout?: string | false;
489
+ $static?: boolean;
490
+ $paths?: JxPathsDef;
491
+ state?: Record<string, JxStateDefinition>;
492
+ /** Repeater fields when this node is a mapped-array container. */
493
+ items?: Bindable<JsonValue[]>;
494
+ filter?: Bindable<string>;
495
+ sort?: Bindable<string>;
496
+ map?: JxMutableNode;
497
+ $elements?: (JxMutableNode | string | JxRef)[];
222
498
  $head?: JxHeadEntry[];
223
499
  $media?: Record<string, string>;
224
- $defs?: Record<string, any>;
225
- [key: string]: any;
500
+ $defs?: Record<string, JsonValue>;
501
+ imports?: Record<string, string>;
502
+ observedAttributes?: string[];
503
+ [key: string]: unknown;
226
504
  }
227
505
 
228
506
  // ─── Paths ──────────────────────────────────────────────────────────────────────
@@ -231,8 +509,19 @@ export type JxPath = (string | number)[];
231
509
 
232
510
  // ─── Content Type Schema ────────────────────────────────────────────────────────
233
511
 
512
+ /** One field within a content-type JSON schema; recursive for nested objects. */
513
+ export interface ContentTypeSchemaField {
514
+ type?: string;
515
+ $ref?: string;
516
+ properties?: Record<string, ContentTypeSchemaField>;
517
+ items?: ContentTypeSchemaField;
518
+ required?: string[];
519
+ description?: string;
520
+ [key: string]: unknown;
521
+ }
522
+
234
523
  export interface ContentTypeSchema {
235
- properties?: Record<string, any>;
524
+ properties?: Record<string, ContentTypeSchemaField>;
236
525
  required?: string[];
237
526
  [key: string]: unknown;
238
527
  }