@teleporthq/teleport-uidl-validator 0.18.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.
Files changed (84) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +14 -0
  3. package/__tests__/parser/componennt-with-referenced-styles.json +111 -0
  4. package/__tests__/parser/component-parsing.ts +116 -0
  5. package/__tests__/parser/component-referenced.ts +50 -0
  6. package/__tests__/parser/component-with-primitive-values.json +61 -0
  7. package/__tests__/parser/component-with-proper-values.json +97 -0
  8. package/__tests__/parser/component-with-reusalble-styles.json +117 -0
  9. package/__tests__/validator/component-element-with-empty-name.json +36 -0
  10. package/__tests__/validator/component-invalid-sample.json +184 -0
  11. package/__tests__/validator/component-uidl-with-event-modifier-undefined.json +45 -0
  12. package/__tests__/validator/component-uidl-with-null-undefined.json +24 -0
  13. package/__tests__/validator/index.ts +216 -0
  14. package/__tests__/validator/old-project-invalid-sample.json +317 -0
  15. package/__tests__/validator/project-invalid-sample-no-route.json +667 -0
  16. package/__tests__/validator/project-invalid-sample.json +671 -0
  17. package/__tests__/validator/project-sample.json +667 -0
  18. package/dist/cjs/decoders/component-decoder.d.ts +4 -0
  19. package/dist/cjs/decoders/component-decoder.js +30 -0
  20. package/dist/cjs/decoders/component-decoder.js.map +1 -0
  21. package/dist/cjs/decoders/custom-combinators.d.ts +8 -0
  22. package/dist/cjs/decoders/custom-combinators.js +59 -0
  23. package/dist/cjs/decoders/custom-combinators.js.map +1 -0
  24. package/dist/cjs/decoders/index.d.ts +2 -0
  25. package/dist/cjs/decoders/index.js +9 -0
  26. package/dist/cjs/decoders/index.js.map +1 -0
  27. package/dist/cjs/decoders/project-decoder.d.ts +5 -0
  28. package/dist/cjs/decoders/project-decoder.js +38 -0
  29. package/dist/cjs/decoders/project-decoder.js.map +1 -0
  30. package/dist/cjs/decoders/utils.d.ts +59 -0
  31. package/dist/cjs/decoders/utils.js +305 -0
  32. package/dist/cjs/decoders/utils.js.map +1 -0
  33. package/dist/cjs/index.d.ts +7 -0
  34. package/dist/cjs/index.js +38 -0
  35. package/dist/cjs/index.js.map +1 -0
  36. package/dist/cjs/parser/index.d.ts +10 -0
  37. package/dist/cjs/parser/index.js +156 -0
  38. package/dist/cjs/parser/index.js.map +1 -0
  39. package/dist/cjs/tsconfig.tsbuildinfo +1 -0
  40. package/dist/cjs/validator/index.d.ts +15 -0
  41. package/dist/cjs/validator/index.js +94 -0
  42. package/dist/cjs/validator/index.js.map +1 -0
  43. package/dist/cjs/validator/utils.d.ts +16 -0
  44. package/dist/cjs/validator/utils.js +373 -0
  45. package/dist/cjs/validator/utils.js.map +1 -0
  46. package/dist/esm/decoders/component-decoder.d.ts +4 -0
  47. package/dist/esm/decoders/component-decoder.js +27 -0
  48. package/dist/esm/decoders/component-decoder.js.map +1 -0
  49. package/dist/esm/decoders/custom-combinators.d.ts +8 -0
  50. package/dist/esm/decoders/custom-combinators.js +56 -0
  51. package/dist/esm/decoders/custom-combinators.js.map +1 -0
  52. package/dist/esm/decoders/index.d.ts +2 -0
  53. package/dist/esm/decoders/index.js +3 -0
  54. package/dist/esm/decoders/index.js.map +1 -0
  55. package/dist/esm/decoders/project-decoder.d.ts +5 -0
  56. package/dist/esm/decoders/project-decoder.js +35 -0
  57. package/dist/esm/decoders/project-decoder.js.map +1 -0
  58. package/dist/esm/decoders/utils.d.ts +59 -0
  59. package/dist/esm/decoders/utils.js +301 -0
  60. package/dist/esm/decoders/utils.js.map +1 -0
  61. package/dist/esm/index.d.ts +7 -0
  62. package/dist/esm/index.js +8 -0
  63. package/dist/esm/index.js.map +1 -0
  64. package/dist/esm/parser/index.d.ts +10 -0
  65. package/dist/esm/parser/index.js +151 -0
  66. package/dist/esm/parser/index.js.map +1 -0
  67. package/dist/esm/tsconfig.tsbuildinfo +1 -0
  68. package/dist/esm/validator/index.d.ts +15 -0
  69. package/dist/esm/validator/index.js +73 -0
  70. package/dist/esm/validator/index.js.map +1 -0
  71. package/dist/esm/validator/utils.d.ts +16 -0
  72. package/dist/esm/validator/utils.js +359 -0
  73. package/dist/esm/validator/utils.js.map +1 -0
  74. package/package.json +32 -0
  75. package/src/decoders/component-decoder.ts +48 -0
  76. package/src/decoders/custom-combinators.ts +59 -0
  77. package/src/decoders/index.ts +2 -0
  78. package/src/decoders/project-decoder.ts +40 -0
  79. package/src/decoders/utils.ts +571 -0
  80. package/src/index.ts +9 -0
  81. package/src/parser/index.ts +227 -0
  82. package/src/validator/index.ts +105 -0
  83. package/src/validator/utils.ts +463 -0
  84. package/tsconfig.json +9 -0
@@ -0,0 +1,40 @@
1
+ import { Decoder, object, optional, string, dict, array } from '@mojotech/json-type-validation'
2
+ import { UIDLGlobalProjectValues, WebManifest, VProjectUIDL } from '@teleporthq/teleport-types'
3
+ import { globalAssetsDecoder } from './utils'
4
+ import { componentUIDLDecoder, rootComponentUIDLDecoder } from './component-decoder'
5
+
6
+ export const webManifestDecoder: Decoder<WebManifest> = object({
7
+ short_name: optional(string()),
8
+ name: optional(string()),
9
+ icons: optional(array(object({ src: string(), type: string(), sizes: string() }))),
10
+ start_url: optional(string()),
11
+ background_color: optional(string()),
12
+ display: optional(string()),
13
+ orientation: optional(string()),
14
+ scope: optional(string()),
15
+ theme_color: optional(string()),
16
+ })
17
+
18
+ export const globalProjectValuesDecoder: Decoder<UIDLGlobalProjectValues> = object({
19
+ settings: object({
20
+ title: string(),
21
+ language: string(),
22
+ }),
23
+ customCode: optional(
24
+ object({
25
+ head: optional(string()),
26
+ body: optional(string()),
27
+ })
28
+ ),
29
+ meta: array(dict(string())),
30
+ assets: array(globalAssetsDecoder),
31
+ manifest: optional(webManifestDecoder),
32
+ variables: optional(dict(string())),
33
+ })
34
+
35
+ export const projectUIDLDecoder: Decoder<VProjectUIDL> = object({
36
+ name: string(),
37
+ globals: globalProjectValuesDecoder,
38
+ root: rootComponentUIDLDecoder,
39
+ components: optional(dict(componentUIDLDecoder)),
40
+ })
@@ -0,0 +1,571 @@
1
+ import {
2
+ object,
3
+ string,
4
+ dict,
5
+ constant,
6
+ number,
7
+ Decoder,
8
+ optional,
9
+ union,
10
+ boolean,
11
+ array,
12
+ lazy,
13
+ oneOf,
14
+ intersection,
15
+ } from '@mojotech/json-type-validation'
16
+ import {
17
+ UIDLStaticValue,
18
+ ReferenceType,
19
+ UIDLDynamicReference,
20
+ UIDLPropDefinition,
21
+ UIDLStateDefinition,
22
+ UIDLStateValueDetails,
23
+ UIDLPageOptions,
24
+ UIDLComponentOutputOptions,
25
+ UIDLDependency,
26
+ UIDLStyleDefinitions,
27
+ UIDLStyleValue,
28
+ UIDLAttributeValue,
29
+ UIDLEventHandlerStatement,
30
+ UIDLNavLinkNode,
31
+ UIDLMailLinkNode,
32
+ UIDLPhoneLinkNode,
33
+ UIDLRawValue,
34
+ UIDLElementStyleStates,
35
+ UIDLStyleStateCondition,
36
+ UIDLStyleMediaQueryScreenSizeCondition,
37
+ UIDLStyleConditions,
38
+ UIDLElementNodeProjectReferencedStyle,
39
+ UIDLComponentSEO,
40
+ UIDLGlobalAsset,
41
+ UIDLExternalDependency,
42
+ UIDLLocalDependency,
43
+ UIDLPeerDependency,
44
+ UIDLImportReference,
45
+ UIDLStyleSetTokenReference,
46
+ VUIDLStyleSetDefnition,
47
+ VUIDLElement,
48
+ VUIDLSlotNode,
49
+ VUIDLConditionalNode,
50
+ VUIDLRepeatNode,
51
+ VUIDLElementNode,
52
+ VUIDLNode,
53
+ VUIDLElementNodeInlineReferencedStyle,
54
+ VUIDLSectionLinkNode,
55
+ VUIDLLinkNode,
56
+ VUIDLURLLinkNode,
57
+ VUIDLStyleSetConditions,
58
+ VUIDLStyleSetMediaCondition,
59
+ VUIDLStyleSetStateCondition,
60
+ VUIDLDesignTokens,
61
+ UIDLPropCallEvent,
62
+ UIDLStateModifierEvent,
63
+ UIDLScriptExternalAsset,
64
+ UIDLScriptInlineAsset,
65
+ UIDLStyleInlineAsset,
66
+ UIDLStyleExternalAsset,
67
+ UIDLFontAsset,
68
+ UIDLCanonicalAsset,
69
+ UIDLIconAsset,
70
+ UIDLAssetBase,
71
+ VUIDLElementNodeClassReferencedStyle,
72
+ UIDLCompDynamicReference,
73
+ } from '@teleporthq/teleport-types'
74
+ import { CustomCombinators } from './custom-combinators'
75
+
76
+ const { isValidComponentName, isValidFileName, isValidElementName, isValidNavLink } =
77
+ CustomCombinators
78
+
79
+ export const referenceTypeDecoder: Decoder<ReferenceType> = union(
80
+ constant('prop'),
81
+ constant('state'),
82
+ constant('local'),
83
+ constant('attr'),
84
+ constant('children'),
85
+ constant('token')
86
+ )
87
+
88
+ export const dynamicValueDecoder: Decoder<UIDLDynamicReference> = object({
89
+ type: constant('dynamic'),
90
+ content: object({
91
+ referenceType: referenceTypeDecoder,
92
+ id: string(),
93
+ }),
94
+ })
95
+
96
+ export const staticValueDecoder: Decoder<UIDLStaticValue> = object({
97
+ type: constant('static'),
98
+ content: union(string(), number(), boolean(), array()),
99
+ })
100
+
101
+ export const styleSetMediaConditionDecoder: Decoder<VUIDLStyleSetMediaCondition> = object({
102
+ type: constant('screen-size'),
103
+ meta: object({
104
+ maxWidth: number(),
105
+ maxHeight: optional(number()),
106
+ minHeight: optional(number()),
107
+ minWidth: optional(number()),
108
+ }),
109
+ content: dict(
110
+ union(
111
+ staticValueDecoder,
112
+ string(),
113
+ number(),
114
+ lazy(() => tokenReferenceDecoder)
115
+ )
116
+ ),
117
+ })
118
+
119
+ export const styleSetStateConditionDecoder: Decoder<VUIDLStyleSetStateCondition> = object({
120
+ type: constant('element-state'),
121
+ meta: object({
122
+ state: lazy(() => elementStateDecoder),
123
+ }),
124
+ content: dict(
125
+ union(
126
+ staticValueDecoder,
127
+ string(),
128
+ number(),
129
+ lazy(() => tokenReferenceDecoder)
130
+ )
131
+ ),
132
+ })
133
+
134
+ export const projectStyleConditionsDecoder: Decoder<VUIDLStyleSetConditions> = union(
135
+ styleSetMediaConditionDecoder,
136
+ styleSetStateConditionDecoder
137
+ )
138
+
139
+ export const tokenReferenceDecoder: Decoder<UIDLStyleSetTokenReference> = object({
140
+ type: constant('dynamic'),
141
+ content: object({
142
+ referenceType: constant('token'),
143
+ id: string(),
144
+ }),
145
+ })
146
+
147
+ export const styleSetDefinitionDecoder: Decoder<VUIDLStyleSetDefnition> = object({
148
+ type: union(constant('reusable-project-style-map'), constant('reusable-component-style-map')),
149
+ conditions: optional(array(projectStyleConditionsDecoder)),
150
+ content: dict(union(staticValueDecoder, string(), number(), tokenReferenceDecoder)),
151
+ })
152
+
153
+ // TODO: Implement decoder for () => void
154
+ export const stateOrPropDefinitionDecoder = union(
155
+ string(),
156
+ number(),
157
+ boolean(),
158
+ array(union(string(), number(), object())),
159
+ object()
160
+ )
161
+
162
+ export const pageOptionsDecoder: Decoder<UIDLPageOptions> = object({
163
+ componentName: optional(isValidComponentName() as unknown as Decoder<string>),
164
+ navLink: optional(isValidNavLink() as unknown as Decoder<string>),
165
+ fileName: optional(isValidFileName() as unknown as Decoder<string>),
166
+ })
167
+
168
+ export const globalAssetsDecoder: Decoder<UIDLGlobalAsset> = union(
169
+ lazy(() => inlineScriptAssetDecoder),
170
+ lazy(() => externalScriptAssetDecoder),
171
+ lazy(() => inlineStyletAssetDecoder),
172
+ lazy(() => externalStyleAssetDecoder),
173
+ lazy(() => fontAssetDecoder),
174
+ lazy(() => canonicalAssetDecoder),
175
+ lazy(() => iconAssetDecoder)
176
+ )
177
+
178
+ export const baseAssetDecoder: Decoder<UIDLAssetBase> = object({
179
+ options: optional(
180
+ object({
181
+ async: optional(boolean()),
182
+ defer: optional(boolean()),
183
+ target: optional(string()),
184
+ })
185
+ ),
186
+ })
187
+
188
+ export const inlineScriptAssetDecoder: Decoder<UIDLScriptInlineAsset> = intersection(
189
+ object({
190
+ type: constant('script' as const),
191
+ content: string(),
192
+ }),
193
+ optional(baseAssetDecoder)
194
+ )
195
+
196
+ export const externalScriptAssetDecoder: Decoder<UIDLScriptExternalAsset> = intersection(
197
+ object({
198
+ type: constant('script' as const),
199
+ path: string(),
200
+ }),
201
+ optional(baseAssetDecoder)
202
+ )
203
+
204
+ export const inlineStyletAssetDecoder: Decoder<UIDLStyleInlineAsset> = object({
205
+ type: constant('style' as const),
206
+ content: string(),
207
+ })
208
+
209
+ export const externalStyleAssetDecoder: Decoder<UIDLStyleExternalAsset> = object({
210
+ type: constant('style' as const),
211
+ path: string(),
212
+ })
213
+
214
+ export const fontAssetDecoder: Decoder<UIDLFontAsset> = object({
215
+ type: constant('font' as const),
216
+ path: string(),
217
+ })
218
+
219
+ export const canonicalAssetDecoder: Decoder<UIDLCanonicalAsset> = object({
220
+ type: constant('canonical' as const),
221
+ path: string(),
222
+ })
223
+
224
+ export const iconAssetDecoder: Decoder<UIDLIconAsset> = object({
225
+ type: constant('icon'),
226
+ path: string(),
227
+ options: optional(
228
+ object({
229
+ iconType: optional(string()),
230
+ iconSizes: optional(string()),
231
+ })
232
+ ),
233
+ })
234
+
235
+ export const componentSeoDecoder: Decoder<UIDLComponentSEO> = object({
236
+ title: optional(string()),
237
+ metaTags: optional(array(dict(string()))),
238
+ assets: optional(array(globalAssetsDecoder)),
239
+ })
240
+
241
+ export const stateValueDetailsDecoder: Decoder<UIDLStateValueDetails> = object({
242
+ value: union(string(), number(), boolean()),
243
+ pageOptions: optional(pageOptionsDecoder),
244
+ seo: optional(componentSeoDecoder),
245
+ })
246
+
247
+ export const propDefinitionsDecoder: Decoder<UIDLPropDefinition> = object({
248
+ type: union(
249
+ constant('string'),
250
+ constant('boolean'),
251
+ constant('number'),
252
+ constant('array'),
253
+ constant('func'),
254
+ constant('object'),
255
+ constant('children')
256
+ ),
257
+ defaultValue: optional(stateOrPropDefinitionDecoder),
258
+ isRequired: optional(boolean()),
259
+ })
260
+
261
+ export const stateDefinitionsDecoder: Decoder<UIDLStateDefinition> = object({
262
+ type: union(
263
+ constant('string'),
264
+ constant('boolean'),
265
+ constant('number'),
266
+ constant('array'),
267
+ constant('func'),
268
+ constant('object'),
269
+ constant('children')
270
+ ),
271
+ defaultValue: stateOrPropDefinitionDecoder,
272
+ values: optional(array(stateValueDetailsDecoder)),
273
+ })
274
+
275
+ export const outputOptionsDecoder: Decoder<UIDLComponentOutputOptions> = object({
276
+ componentClassName: optional(isValidComponentName() as unknown as Decoder<string>),
277
+ fileName: optional(isValidFileName() as unknown as Decoder<string>),
278
+ styleFileName: optional(isValidFileName() as unknown as Decoder<string>),
279
+ templateFileName: optional(isValidFileName() as unknown as Decoder<string>),
280
+ moduleName: optional(isValidFileName() as unknown as Decoder<string>),
281
+ folderPath: optional(array(isValidFileName() as unknown as Decoder<string>)),
282
+ })
283
+
284
+ export const peerDependencyDecoder: Decoder<UIDLPeerDependency> = object({
285
+ type: constant('package'),
286
+ version: string(),
287
+ path: string(),
288
+ })
289
+
290
+ export const externaldependencyDecoder: Decoder<UIDLExternalDependency> = object({
291
+ type: union(constant('library'), constant('package')),
292
+ path: string(),
293
+ version: string(),
294
+ meta: optional(
295
+ object({
296
+ namedImport: optional(boolean()),
297
+ originalName: optional(string()),
298
+ importJustPath: optional(boolean()),
299
+ useAsReference: optional(boolean()),
300
+ })
301
+ ),
302
+ })
303
+
304
+ export const localDependencyDecoder: Decoder<UIDLLocalDependency> = object({
305
+ type: constant('local'),
306
+ path: optional(string()),
307
+ meta: optional(
308
+ object({
309
+ namedImport: optional(boolean()),
310
+ originalName: optional(string()),
311
+ importJustPath: optional(boolean()),
312
+ })
313
+ ),
314
+ })
315
+
316
+ export const dependencyDecoder: Decoder<UIDLDependency> = union(
317
+ localDependencyDecoder,
318
+ externaldependencyDecoder
319
+ )
320
+
321
+ export const importReferenceDecoder: Decoder<UIDLImportReference> = object({
322
+ type: constant('import'),
323
+ content: object({
324
+ id: string(),
325
+ }),
326
+ })
327
+
328
+ export const attributeValueDecoder: Decoder<UIDLAttributeValue> = union(
329
+ dynamicValueDecoder,
330
+ staticValueDecoder,
331
+ importReferenceDecoder
332
+ )
333
+
334
+ export const styleValueDecoder: Decoder<UIDLStyleValue> = union(
335
+ staticValueDecoder,
336
+ dynamicValueDecoder
337
+ )
338
+
339
+ export const styleDefinitionsDecoder: Decoder<UIDLStyleDefinitions> = dict(styleValueDecoder)
340
+
341
+ export const eventHandlerStatementDecoder: Decoder<UIDLEventHandlerStatement> = union(
342
+ lazy(() => propCallEventDecoder),
343
+ lazy(() => stateChangeEventDecoder)
344
+ )
345
+
346
+ export const propCallEventDecoder: Decoder<UIDLPropCallEvent> = object({
347
+ type: constant('propCall'),
348
+ calls: string(),
349
+ args: optional(array(union(string(), number(), boolean()))),
350
+ })
351
+
352
+ export const stateChangeEventDecoder: Decoder<UIDLStateModifierEvent> = object({
353
+ type: constant('stateChange'),
354
+ modifies: string(),
355
+ newState: union(string(), number(), boolean()),
356
+ })
357
+
358
+ export const urlLinkNodeDecoder: Decoder<VUIDLURLLinkNode> = object({
359
+ type: constant('url'),
360
+ content: object({
361
+ url: union(attributeValueDecoder, string()),
362
+ newTab: boolean(),
363
+ }),
364
+ })
365
+
366
+ export const sectionLinkNodeDecoder: Decoder<VUIDLSectionLinkNode> = object({
367
+ type: constant('section'),
368
+ content: dict(string()),
369
+ })
370
+
371
+ export const navLinkNodeDecoder: Decoder<UIDLNavLinkNode> = object({
372
+ type: constant('navlink'),
373
+ content: object({
374
+ routeName: string(),
375
+ }),
376
+ })
377
+
378
+ export const uidlMailLinkNodeDecoder: Decoder<UIDLMailLinkNode> = object({
379
+ type: constant('mail'),
380
+ content: object({
381
+ mail: optional(string()),
382
+ subject: optional(string()),
383
+ body: optional(string()),
384
+ }),
385
+ })
386
+
387
+ export const phoneLinkNodeDecoder: Decoder<UIDLPhoneLinkNode> = object({
388
+ type: constant('phone'),
389
+ content: object({
390
+ phone: string(),
391
+ }),
392
+ })
393
+
394
+ export const uidlLinkNodeDecoder: Decoder<VUIDLLinkNode> = union(
395
+ urlLinkNodeDecoder,
396
+ sectionLinkNodeDecoder,
397
+ navLinkNodeDecoder,
398
+ uidlMailLinkNodeDecoder,
399
+ phoneLinkNodeDecoder
400
+ )
401
+
402
+ export const rawValueDecoder: Decoder<UIDLRawValue> = object({
403
+ type: constant('raw'),
404
+ content: string(),
405
+ })
406
+
407
+ export const elementStateDecoder: Decoder<UIDLElementStyleStates> = oneOf(
408
+ constant('hover'),
409
+ constant('active'),
410
+ constant('focus'),
411
+ constant('focus-within'),
412
+ constant('focus-visible'),
413
+ constant('disabled'),
414
+ constant('visited'),
415
+ constant('checked'),
416
+ constant('link')
417
+ )
418
+
419
+ export const elementStyleWithStateConditionDecoder: Decoder<UIDLStyleStateCondition> = object({
420
+ conditionType: constant('element-state'),
421
+ content: elementStateDecoder,
422
+ })
423
+
424
+ export const elementStyleWithMediaConditionDecoder: Decoder<UIDLStyleMediaQueryScreenSizeCondition> =
425
+ object({
426
+ conditionType: constant('screen-size'),
427
+ minHeight: optional(number()),
428
+ maxHeight: optional(number()),
429
+ minWidth: optional(number()),
430
+ maxWidth: number(),
431
+ })
432
+
433
+ export const styleConditionsDecoder: Decoder<UIDLStyleConditions> = union(
434
+ elementStyleWithMediaConditionDecoder,
435
+ elementStyleWithStateConditionDecoder
436
+ )
437
+
438
+ export const elementProjectReferencedStyle: Decoder<UIDLElementNodeProjectReferencedStyle> = object(
439
+ {
440
+ type: constant('style-map'),
441
+ content: object({
442
+ mapType: constant('project-referenced'),
443
+ conditions: optional(array(styleConditionsDecoder)),
444
+ referenceId: string(),
445
+ }),
446
+ }
447
+ )
448
+
449
+ export const elementInlineReferencedStyle: Decoder<VUIDLElementNodeInlineReferencedStyle> = object({
450
+ type: constant('style-map'),
451
+ content: object({
452
+ mapType: constant('inlined'),
453
+ conditions: array(styleConditionsDecoder),
454
+ styles: optional(dict(union(attributeValueDecoder, string(), number()))),
455
+ }),
456
+ })
457
+
458
+ export const classDynamicReferenceDecoder: Decoder<UIDLCompDynamicReference> = object({
459
+ type: constant('dynamic'),
460
+ content: object({
461
+ referenceType: union(constant('prop'), constant('comp')),
462
+ id: string(),
463
+ }),
464
+ })
465
+
466
+ export const elementComponentReferencedStyle: Decoder<VUIDLElementNodeClassReferencedStyle> =
467
+ object({
468
+ type: constant('style-map'),
469
+ content: object({
470
+ mapType: constant('component-referenced'),
471
+ content: union(string(), staticValueDecoder, classDynamicReferenceDecoder),
472
+ }),
473
+ })
474
+
475
+ export const designTokensDecoder: Decoder<VUIDLDesignTokens> = dict(
476
+ union(staticValueDecoder, string(), number())
477
+ )
478
+
479
+ export const elementDecoder: Decoder<VUIDLElement> = object({
480
+ elementType: string(),
481
+ semanticType: optional(string()),
482
+ name: optional(isValidElementName() as unknown as Decoder<string>),
483
+ key: optional(string()),
484
+ dependency: optional(dependencyDecoder),
485
+ style: optional(dict(union(attributeValueDecoder, string(), number()))),
486
+ attrs: optional(dict(union(attributeValueDecoder, string(), number()))),
487
+ events: optional(dict(array(eventHandlerStatementDecoder))),
488
+ abilities: optional(
489
+ object({
490
+ link: optional(uidlLinkNodeDecoder),
491
+ })
492
+ ),
493
+ children: optional(array(lazy(() => uidlNodeDecoder))),
494
+ referencedStyles: optional(
495
+ dict(
496
+ union(
497
+ elementInlineReferencedStyle,
498
+ elementProjectReferencedStyle,
499
+ elementComponentReferencedStyle
500
+ )
501
+ )
502
+ ),
503
+ selfClosing: optional(boolean()),
504
+ ignore: optional(boolean()),
505
+ })
506
+
507
+ export const slotNodeDecoder: Decoder<VUIDLSlotNode> = object({
508
+ type: constant('slot'),
509
+ content: union(
510
+ object({
511
+ name: optional(string()),
512
+ fallback: optional(
513
+ union(
514
+ staticValueDecoder,
515
+ dynamicValueDecoder,
516
+ lazy(() => elementNodeDecoder)
517
+ )
518
+ ),
519
+ }),
520
+ object({})
521
+ ),
522
+ })
523
+
524
+ export const repeatNodeDecoder: Decoder<VUIDLRepeatNode> = object({
525
+ type: constant('repeat'),
526
+ content: object({
527
+ node: lazy(() => elementNodeDecoder),
528
+ dataSource: optional(attributeValueDecoder),
529
+ meta: optional(
530
+ object({
531
+ useIndex: optional(boolean()),
532
+ iteratorName: optional(string()),
533
+ dataSourceIdentifier: optional(string()),
534
+ iteratorKey: optional(string()),
535
+ })
536
+ ),
537
+ }),
538
+ })
539
+
540
+ export const conditionalNodeDecoder: Decoder<VUIDLConditionalNode> = object({
541
+ type: constant('conditional'),
542
+ content: object({
543
+ node: lazy(() => uidlNodeDecoder),
544
+ reference: dynamicValueDecoder,
545
+ value: union(string(), number(), boolean()),
546
+ condition: optional(
547
+ object({
548
+ conditions: array(
549
+ object({ operation: string(), operand: optional(union(string(), number(), boolean())) })
550
+ ),
551
+ matchingCriteria: optional(string()),
552
+ })
553
+ ),
554
+ }),
555
+ })
556
+
557
+ export const elementNodeDecoder: Decoder<VUIDLElementNode> = object({
558
+ type: constant('element'),
559
+ content: elementDecoder,
560
+ })
561
+
562
+ export const uidlNodeDecoder: Decoder<VUIDLNode> = union(
563
+ elementNodeDecoder,
564
+ dynamicValueDecoder,
565
+ staticValueDecoder,
566
+ rawValueDecoder,
567
+ conditionalNodeDecoder,
568
+ repeatNodeDecoder,
569
+ slotNodeDecoder,
570
+ string()
571
+ )
package/src/index.ts ADDED
@@ -0,0 +1,9 @@
1
+ import * as Parser from './parser'
2
+ import * as Decoders from './decoders/utils'
3
+
4
+ export { default as Validator } from './validator'
5
+ export { Parser, Decoders }
6
+
7
+ export * from './decoders/component-decoder'
8
+ export * from './decoders/project-decoder'
9
+ export * from './decoders/utils'