@object-ui/core 0.3.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/CHANGELOG.md +42 -0
- package/LICENSE +21 -0
- package/README.md +84 -0
- package/dist/builder/schema-builder.d.ts +287 -0
- package/dist/builder/schema-builder.js +505 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +7 -0
- package/dist/registry/Registry.d.ts +49 -0
- package/dist/registry/Registry.js +36 -0
- package/dist/types/index.d.ts +12 -0
- package/dist/types/index.js +1 -0
- package/dist/validation/schema-validator.d.ts +87 -0
- package/dist/validation/schema-validator.js +280 -0
- package/package.json +22 -0
- package/src/builder/schema-builder.d.ts +287 -0
- package/src/builder/schema-builder.js +505 -0
- package/src/builder/schema-builder.ts +576 -0
- package/src/index.d.ts +4 -0
- package/src/index.js +7 -0
- package/src/index.test.ts +7 -0
- package/src/index.ts +8 -0
- package/src/registry/Registry.d.ts +49 -0
- package/src/registry/Registry.js +36 -0
- package/src/registry/Registry.ts +77 -0
- package/src/types/index.d.ts +12 -0
- package/src/types/index.js +1 -0
- package/src/types/index.ts +13 -0
- package/src/validation/schema-validator.d.ts +87 -0
- package/src/validation/schema-validator.js +280 -0
- package/src/validation/schema-validator.ts +336 -0
- package/tsconfig.json +15 -0
- package/tsconfig.tsbuildinfo +1 -0
|
@@ -0,0 +1,505 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @object-ui/core - Schema Builder
|
|
3
|
+
*
|
|
4
|
+
* Fluent API for building schemas programmatically.
|
|
5
|
+
* Provides type-safe builder functions for common schema patterns.
|
|
6
|
+
*
|
|
7
|
+
* @module builder
|
|
8
|
+
* @packageDocumentation
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Base builder class
|
|
12
|
+
*/
|
|
13
|
+
class SchemaBuilder {
|
|
14
|
+
constructor(type) {
|
|
15
|
+
Object.defineProperty(this, "schema", {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
configurable: true,
|
|
18
|
+
writable: true,
|
|
19
|
+
value: void 0
|
|
20
|
+
});
|
|
21
|
+
this.schema = { type };
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Set the ID
|
|
25
|
+
*/
|
|
26
|
+
id(id) {
|
|
27
|
+
this.schema.id = id;
|
|
28
|
+
return this;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Set the className
|
|
32
|
+
*/
|
|
33
|
+
className(className) {
|
|
34
|
+
this.schema.className = className;
|
|
35
|
+
return this;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Set visibility
|
|
39
|
+
*/
|
|
40
|
+
visible(visible) {
|
|
41
|
+
this.schema.visible = visible;
|
|
42
|
+
return this;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Set conditional visibility
|
|
46
|
+
*/
|
|
47
|
+
visibleOn(expression) {
|
|
48
|
+
this.schema.visibleOn = expression;
|
|
49
|
+
return this;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Set disabled state
|
|
53
|
+
*/
|
|
54
|
+
disabled(disabled) {
|
|
55
|
+
this.schema.disabled = disabled;
|
|
56
|
+
return this;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Set test ID
|
|
60
|
+
*/
|
|
61
|
+
testId(testId) {
|
|
62
|
+
this.schema.testId = testId;
|
|
63
|
+
return this;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Build the final schema
|
|
67
|
+
*/
|
|
68
|
+
build() {
|
|
69
|
+
return this.schema;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Form builder
|
|
74
|
+
*/
|
|
75
|
+
export class FormBuilder extends SchemaBuilder {
|
|
76
|
+
constructor() {
|
|
77
|
+
super('form');
|
|
78
|
+
this.schema.fields = [];
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Add a field to the form
|
|
82
|
+
*/
|
|
83
|
+
field(field) {
|
|
84
|
+
this.schema.fields = [...(this.schema.fields || []), field];
|
|
85
|
+
return this;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Add multiple fields
|
|
89
|
+
*/
|
|
90
|
+
fields(fields) {
|
|
91
|
+
this.schema.fields = fields;
|
|
92
|
+
return this;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Set default values
|
|
96
|
+
*/
|
|
97
|
+
defaultValues(values) {
|
|
98
|
+
this.schema.defaultValues = values;
|
|
99
|
+
return this;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Set submit label
|
|
103
|
+
*/
|
|
104
|
+
submitLabel(label) {
|
|
105
|
+
this.schema.submitLabel = label;
|
|
106
|
+
return this;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Set form layout
|
|
110
|
+
*/
|
|
111
|
+
layout(layout) {
|
|
112
|
+
this.schema.layout = layout;
|
|
113
|
+
return this;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Set number of columns
|
|
117
|
+
*/
|
|
118
|
+
columns(columns) {
|
|
119
|
+
this.schema.columns = columns;
|
|
120
|
+
return this;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Set submit handler
|
|
124
|
+
*/
|
|
125
|
+
onSubmit(handler) {
|
|
126
|
+
this.schema.onSubmit = handler;
|
|
127
|
+
return this;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* CRUD builder
|
|
132
|
+
*/
|
|
133
|
+
export class CRUDBuilder extends SchemaBuilder {
|
|
134
|
+
constructor() {
|
|
135
|
+
super('crud');
|
|
136
|
+
this.schema.columns = [];
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Set resource name
|
|
140
|
+
*/
|
|
141
|
+
resource(resource) {
|
|
142
|
+
this.schema.resource = resource;
|
|
143
|
+
return this;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Set API endpoint
|
|
147
|
+
*/
|
|
148
|
+
api(api) {
|
|
149
|
+
this.schema.api = api;
|
|
150
|
+
return this;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Set title
|
|
154
|
+
*/
|
|
155
|
+
title(title) {
|
|
156
|
+
this.schema.title = title;
|
|
157
|
+
return this;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Set description
|
|
161
|
+
*/
|
|
162
|
+
description(description) {
|
|
163
|
+
this.schema.description = description;
|
|
164
|
+
return this;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Add a column
|
|
168
|
+
*/
|
|
169
|
+
column(column) {
|
|
170
|
+
this.schema.columns = [...(this.schema.columns || []), column];
|
|
171
|
+
return this;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Set all columns
|
|
175
|
+
*/
|
|
176
|
+
columns(columns) {
|
|
177
|
+
this.schema.columns = columns;
|
|
178
|
+
return this;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Set form fields
|
|
182
|
+
*/
|
|
183
|
+
fields(fields) {
|
|
184
|
+
this.schema.fields = fields;
|
|
185
|
+
return this;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Enable create operation
|
|
189
|
+
*/
|
|
190
|
+
enableCreate(label) {
|
|
191
|
+
if (!this.schema.operations)
|
|
192
|
+
this.schema.operations = {};
|
|
193
|
+
this.schema.operations.create = {
|
|
194
|
+
enabled: true,
|
|
195
|
+
label: label || 'Create',
|
|
196
|
+
api: this.schema.api,
|
|
197
|
+
method: 'POST'
|
|
198
|
+
};
|
|
199
|
+
return this;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Enable update operation
|
|
203
|
+
*/
|
|
204
|
+
enableUpdate(label) {
|
|
205
|
+
if (!this.schema.operations)
|
|
206
|
+
this.schema.operations = {};
|
|
207
|
+
this.schema.operations.update = {
|
|
208
|
+
enabled: true,
|
|
209
|
+
label: label || 'Update',
|
|
210
|
+
api: `${this.schema.api}/\${id}`,
|
|
211
|
+
method: 'PUT'
|
|
212
|
+
};
|
|
213
|
+
return this;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Enable delete operation
|
|
217
|
+
*/
|
|
218
|
+
enableDelete(label, confirmText) {
|
|
219
|
+
if (!this.schema.operations)
|
|
220
|
+
this.schema.operations = {};
|
|
221
|
+
this.schema.operations.delete = {
|
|
222
|
+
enabled: true,
|
|
223
|
+
label: label || 'Delete',
|
|
224
|
+
api: `${this.schema.api}/\${id}`,
|
|
225
|
+
method: 'DELETE',
|
|
226
|
+
confirmText: confirmText || 'Are you sure?'
|
|
227
|
+
};
|
|
228
|
+
return this;
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Set pagination
|
|
232
|
+
*/
|
|
233
|
+
pagination(pageSize = 20) {
|
|
234
|
+
this.schema.pagination = {
|
|
235
|
+
enabled: true,
|
|
236
|
+
pageSize,
|
|
237
|
+
pageSizeOptions: [10, 20, 50, 100],
|
|
238
|
+
showTotal: true,
|
|
239
|
+
showSizeChanger: true
|
|
240
|
+
};
|
|
241
|
+
return this;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Enable row selection
|
|
245
|
+
*/
|
|
246
|
+
selectable(mode = 'multiple') {
|
|
247
|
+
this.schema.selectable = mode;
|
|
248
|
+
return this;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Add a batch action
|
|
252
|
+
*/
|
|
253
|
+
batchAction(action) {
|
|
254
|
+
this.schema.batchActions = [...(this.schema.batchActions || []), action];
|
|
255
|
+
return this;
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Add a row action
|
|
259
|
+
*/
|
|
260
|
+
rowAction(action) {
|
|
261
|
+
this.schema.rowActions = [...(this.schema.rowActions || []), action];
|
|
262
|
+
return this;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Button builder
|
|
267
|
+
*/
|
|
268
|
+
export class ButtonBuilder extends SchemaBuilder {
|
|
269
|
+
constructor() {
|
|
270
|
+
super('button');
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Set button label
|
|
274
|
+
*/
|
|
275
|
+
label(label) {
|
|
276
|
+
this.schema.label = label;
|
|
277
|
+
return this;
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Set button variant
|
|
281
|
+
*/
|
|
282
|
+
variant(variant) {
|
|
283
|
+
this.schema.variant = variant;
|
|
284
|
+
return this;
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Set button size
|
|
288
|
+
*/
|
|
289
|
+
size(size) {
|
|
290
|
+
this.schema.size = size;
|
|
291
|
+
return this;
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Set button icon
|
|
295
|
+
*/
|
|
296
|
+
icon(icon) {
|
|
297
|
+
this.schema.icon = icon;
|
|
298
|
+
return this;
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Set click handler
|
|
302
|
+
*/
|
|
303
|
+
onClick(handler) {
|
|
304
|
+
this.schema.onClick = handler;
|
|
305
|
+
return this;
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Set loading state
|
|
309
|
+
*/
|
|
310
|
+
loading(loading) {
|
|
311
|
+
this.schema.loading = loading;
|
|
312
|
+
return this;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Input builder
|
|
317
|
+
*/
|
|
318
|
+
export class InputBuilder extends SchemaBuilder {
|
|
319
|
+
constructor() {
|
|
320
|
+
super('input');
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Set field name
|
|
324
|
+
*/
|
|
325
|
+
name(name) {
|
|
326
|
+
this.schema.name = name;
|
|
327
|
+
return this;
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Set label
|
|
331
|
+
*/
|
|
332
|
+
label(label) {
|
|
333
|
+
this.schema.label = label;
|
|
334
|
+
return this;
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Set placeholder
|
|
338
|
+
*/
|
|
339
|
+
placeholder(placeholder) {
|
|
340
|
+
this.schema.placeholder = placeholder;
|
|
341
|
+
return this;
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Set input type
|
|
345
|
+
*/
|
|
346
|
+
inputType(type) {
|
|
347
|
+
this.schema.inputType = type;
|
|
348
|
+
return this;
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* Mark as required
|
|
352
|
+
*/
|
|
353
|
+
required(required = true) {
|
|
354
|
+
this.schema.required = required;
|
|
355
|
+
return this;
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Set default value
|
|
359
|
+
*/
|
|
360
|
+
defaultValue(value) {
|
|
361
|
+
this.schema.defaultValue = value;
|
|
362
|
+
return this;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Card builder
|
|
367
|
+
*/
|
|
368
|
+
export class CardBuilder extends SchemaBuilder {
|
|
369
|
+
constructor() {
|
|
370
|
+
super('card');
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Set card title
|
|
374
|
+
*/
|
|
375
|
+
title(title) {
|
|
376
|
+
this.schema.title = title;
|
|
377
|
+
return this;
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Set card description
|
|
381
|
+
*/
|
|
382
|
+
description(description) {
|
|
383
|
+
this.schema.description = description;
|
|
384
|
+
return this;
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* Set card content
|
|
388
|
+
*/
|
|
389
|
+
content(content) {
|
|
390
|
+
this.schema.content = content;
|
|
391
|
+
return this;
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* Set card variant
|
|
395
|
+
*/
|
|
396
|
+
variant(variant) {
|
|
397
|
+
this.schema.variant = variant;
|
|
398
|
+
return this;
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Make card hoverable
|
|
402
|
+
*/
|
|
403
|
+
hoverable(hoverable = true) {
|
|
404
|
+
this.schema.hoverable = hoverable;
|
|
405
|
+
return this;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
/**
|
|
409
|
+
* Grid builder
|
|
410
|
+
*/
|
|
411
|
+
export class GridBuilder extends SchemaBuilder {
|
|
412
|
+
constructor() {
|
|
413
|
+
super('grid');
|
|
414
|
+
this.schema.children = [];
|
|
415
|
+
}
|
|
416
|
+
/**
|
|
417
|
+
* Set number of columns
|
|
418
|
+
*/
|
|
419
|
+
columns(columns) {
|
|
420
|
+
this.schema.columns = columns;
|
|
421
|
+
return this;
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* Set gap
|
|
425
|
+
*/
|
|
426
|
+
gap(gap) {
|
|
427
|
+
this.schema.gap = gap;
|
|
428
|
+
return this;
|
|
429
|
+
}
|
|
430
|
+
/**
|
|
431
|
+
* Add a child
|
|
432
|
+
*/
|
|
433
|
+
child(child) {
|
|
434
|
+
const children = Array.isArray(this.schema.children) ? this.schema.children : [];
|
|
435
|
+
this.schema.children = [...children, child];
|
|
436
|
+
return this;
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* Set all children
|
|
440
|
+
*/
|
|
441
|
+
children(children) {
|
|
442
|
+
this.schema.children = children;
|
|
443
|
+
return this;
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
/**
|
|
447
|
+
* Flex builder
|
|
448
|
+
*/
|
|
449
|
+
export class FlexBuilder extends SchemaBuilder {
|
|
450
|
+
constructor() {
|
|
451
|
+
super('flex');
|
|
452
|
+
this.schema.children = [];
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* Set flex direction
|
|
456
|
+
*/
|
|
457
|
+
direction(direction) {
|
|
458
|
+
this.schema.direction = direction;
|
|
459
|
+
return this;
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* Set justify content
|
|
463
|
+
*/
|
|
464
|
+
justify(justify) {
|
|
465
|
+
this.schema.justify = justify;
|
|
466
|
+
return this;
|
|
467
|
+
}
|
|
468
|
+
/**
|
|
469
|
+
* Set align items
|
|
470
|
+
*/
|
|
471
|
+
align(align) {
|
|
472
|
+
this.schema.align = align;
|
|
473
|
+
return this;
|
|
474
|
+
}
|
|
475
|
+
/**
|
|
476
|
+
* Set gap
|
|
477
|
+
*/
|
|
478
|
+
gap(gap) {
|
|
479
|
+
this.schema.gap = gap;
|
|
480
|
+
return this;
|
|
481
|
+
}
|
|
482
|
+
/**
|
|
483
|
+
* Add a child
|
|
484
|
+
*/
|
|
485
|
+
child(child) {
|
|
486
|
+
const children = Array.isArray(this.schema.children) ? this.schema.children : [];
|
|
487
|
+
this.schema.children = [...children, child];
|
|
488
|
+
return this;
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* Set all children
|
|
492
|
+
*/
|
|
493
|
+
children(children) {
|
|
494
|
+
this.schema.children = children;
|
|
495
|
+
return this;
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
// Export factory functions
|
|
499
|
+
export const form = () => new FormBuilder();
|
|
500
|
+
export const crud = () => new CRUDBuilder();
|
|
501
|
+
export const button = () => new ButtonBuilder();
|
|
502
|
+
export const input = () => new InputBuilder();
|
|
503
|
+
export const card = () => new CardBuilder();
|
|
504
|
+
export const grid = () => new GridBuilder();
|
|
505
|
+
export const flex = () => new FlexBuilder();
|