@teleporthq/teleport-uidl-validator 0.19.8 → 0.19.21
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/__tests__/validator/index.ts +10 -1
- package/__tests__/validator/project-sample.json +9 -1
- package/dist/cjs/decoders/component-decoder.js +19 -19
- package/dist/cjs/decoders/component-decoder.js.map +1 -1
- package/dist/cjs/decoders/custom-combinators.js +4 -4
- package/dist/cjs/decoders/custom-combinators.js.map +1 -1
- package/dist/cjs/decoders/project-decoder.d.ts +2 -2
- package/dist/cjs/decoders/project-decoder.js +24 -24
- package/dist/cjs/decoders/project-decoder.js.map +1 -1
- package/dist/cjs/decoders/utils.d.ts +6 -5
- package/dist/cjs/decoders/utils.js +251 -245
- package/dist/cjs/decoders/utils.js.map +1 -1
- package/dist/cjs/index.js +5 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/parser/index.d.ts +2 -1
- package/dist/cjs/parser/index.js +22 -9
- package/dist/cjs/parser/index.js.map +1 -1
- package/dist/cjs/tsconfig.tsbuildinfo +1 -1
- package/dist/cjs/validator/index.d.ts +3 -3
- package/dist/cjs/validator/index.js +20 -12
- package/dist/cjs/validator/index.js.map +1 -1
- package/dist/cjs/validator/utils.js +49 -35
- package/dist/cjs/validator/utils.js.map +1 -1
- package/dist/esm/decoders/custom-combinators.js +4 -4
- package/dist/esm/decoders/custom-combinators.js.map +1 -1
- package/dist/esm/decoders/project-decoder.d.ts +2 -2
- package/dist/esm/decoders/project-decoder.js.map +1 -1
- package/dist/esm/decoders/utils.d.ts +6 -5
- package/dist/esm/decoders/utils.js +7 -1
- package/dist/esm/decoders/utils.js.map +1 -1
- package/dist/esm/parser/index.d.ts +2 -1
- package/dist/esm/parser/index.js +18 -6
- package/dist/esm/parser/index.js.map +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/dist/esm/validator/index.d.ts +3 -3
- package/dist/esm/validator/index.js +15 -11
- package/dist/esm/validator/index.js.map +1 -1
- package/dist/esm/validator/utils.js +47 -33
- package/dist/esm/validator/utils.js.map +1 -1
- package/package.json +4 -4
- package/src/decoders/project-decoder.ts +2 -2
- package/src/decoders/utils.ts +18 -9
- package/src/parser/index.ts +24 -1
- package/src/validator/index.ts +7 -3
- package/src/validator/utils.ts +21 -0
package/src/decoders/utils.ts
CHANGED
|
@@ -37,8 +37,8 @@ import {
|
|
|
37
37
|
UIDLStyleMediaQueryScreenSizeCondition,
|
|
38
38
|
UIDLStyleConditions,
|
|
39
39
|
UIDLElementNodeProjectReferencedStyle,
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
VUIDLComponentSEO,
|
|
41
|
+
VUIDLGlobalAsset,
|
|
42
42
|
UIDLExternalDependency,
|
|
43
43
|
UIDLLocalDependency,
|
|
44
44
|
UIDLPeerDependency,
|
|
@@ -63,14 +63,15 @@ import {
|
|
|
63
63
|
UIDLStateModifierEvent,
|
|
64
64
|
UIDLScriptExternalAsset,
|
|
65
65
|
UIDLScriptInlineAsset,
|
|
66
|
-
|
|
66
|
+
VUIDLStyleInlineAsset,
|
|
67
67
|
UIDLStyleExternalAsset,
|
|
68
|
-
|
|
68
|
+
VUIDLFontAsset,
|
|
69
69
|
UIDLCanonicalAsset,
|
|
70
70
|
UIDLIconAsset,
|
|
71
71
|
UIDLAssetBase,
|
|
72
72
|
VUIDLElementNodeClassReferencedStyle,
|
|
73
73
|
UIDLCompDynamicReference,
|
|
74
|
+
UIDLComponentStyleReference,
|
|
74
75
|
} from '@teleporthq/teleport-types'
|
|
75
76
|
import { CustomCombinators } from './custom-combinators'
|
|
76
77
|
|
|
@@ -166,7 +167,7 @@ export const pageOptionsDecoder: Decoder<UIDLPageOptions> = object({
|
|
|
166
167
|
fileName: optional(isValidFileName() as unknown as Decoder<string>),
|
|
167
168
|
})
|
|
168
169
|
|
|
169
|
-
export const globalAssetsDecoder: Decoder<
|
|
170
|
+
export const globalAssetsDecoder: Decoder<VUIDLGlobalAsset> = union(
|
|
170
171
|
lazy(() => inlineScriptAssetDecoder),
|
|
171
172
|
lazy(() => externalScriptAssetDecoder),
|
|
172
173
|
lazy(() => inlineStyletAssetDecoder),
|
|
@@ -202,8 +203,9 @@ export const externalScriptAssetDecoder: Decoder<UIDLScriptExternalAsset> = inte
|
|
|
202
203
|
optional(baseAssetDecoder)
|
|
203
204
|
)
|
|
204
205
|
|
|
205
|
-
export const inlineStyletAssetDecoder: Decoder<
|
|
206
|
+
export const inlineStyletAssetDecoder: Decoder<VUIDLStyleInlineAsset> = object({
|
|
206
207
|
type: constant('style' as const),
|
|
208
|
+
attrs: optional(dict(union(staticValueDecoder, string(), boolean(), number()))),
|
|
207
209
|
content: string(),
|
|
208
210
|
})
|
|
209
211
|
|
|
@@ -212,8 +214,9 @@ export const externalStyleAssetDecoder: Decoder<UIDLStyleExternalAsset> = object
|
|
|
212
214
|
path: string(),
|
|
213
215
|
})
|
|
214
216
|
|
|
215
|
-
export const fontAssetDecoder: Decoder<
|
|
217
|
+
export const fontAssetDecoder: Decoder<VUIDLFontAsset> = object({
|
|
216
218
|
type: constant('font' as const),
|
|
219
|
+
attrs: optional(dict(union(staticValueDecoder, string(), boolean(), number()))),
|
|
217
220
|
path: string(),
|
|
218
221
|
})
|
|
219
222
|
|
|
@@ -233,7 +236,7 @@ export const iconAssetDecoder: Decoder<UIDLIconAsset> = object({
|
|
|
233
236
|
),
|
|
234
237
|
})
|
|
235
238
|
|
|
236
|
-
export const componentSeoDecoder: Decoder<
|
|
239
|
+
export const componentSeoDecoder: Decoder<VUIDLComponentSEO> = object({
|
|
237
240
|
title: optional(string()),
|
|
238
241
|
metaTags: optional(array(dict(string()))),
|
|
239
242
|
assets: optional(array(globalAssetsDecoder)),
|
|
@@ -329,9 +332,15 @@ export const importReferenceDecoder: Decoder<UIDLImportReference> = object({
|
|
|
329
332
|
export const attributeValueDecoder: Decoder<UIDLAttributeValue> = union(
|
|
330
333
|
dynamicValueDecoder,
|
|
331
334
|
staticValueDecoder,
|
|
332
|
-
importReferenceDecoder
|
|
335
|
+
importReferenceDecoder,
|
|
336
|
+
lazy(() => uidlComponentStyleReference)
|
|
333
337
|
)
|
|
334
338
|
|
|
339
|
+
export const uidlComponentStyleReference: Decoder<UIDLComponentStyleReference> = object({
|
|
340
|
+
type: constant('comp-style'),
|
|
341
|
+
content: string(),
|
|
342
|
+
})
|
|
343
|
+
|
|
335
344
|
export const styleValueDecoder: Decoder<UIDLStyleValue> = union(
|
|
336
345
|
staticValueDecoder,
|
|
337
346
|
dynamicValueDecoder
|
package/src/parser/index.ts
CHANGED
|
@@ -13,6 +13,9 @@ import {
|
|
|
13
13
|
UIDLStyleSetConditions,
|
|
14
14
|
UIDLDesignTokens,
|
|
15
15
|
ParserError,
|
|
16
|
+
UIDLComponentSEO,
|
|
17
|
+
VUIDLGlobalAsset,
|
|
18
|
+
UIDLGlobalAsset,
|
|
16
19
|
} from '@teleporthq/teleport-types'
|
|
17
20
|
|
|
18
21
|
interface ParseComponentJSONParams {
|
|
@@ -25,7 +28,7 @@ export const parseComponentJSON = (
|
|
|
25
28
|
): ComponentUIDL => {
|
|
26
29
|
const safeInput = params.noClone ? input : UIDLUtils.cloneObject(input)
|
|
27
30
|
|
|
28
|
-
if (
|
|
31
|
+
if (safeInput?.styleSetDefinitions) {
|
|
29
32
|
const { styleSetDefinitions } = safeInput
|
|
30
33
|
|
|
31
34
|
Object.values(styleSetDefinitions).forEach((styleRef) => {
|
|
@@ -42,6 +45,13 @@ export const parseComponentJSON = (
|
|
|
42
45
|
})
|
|
43
46
|
}
|
|
44
47
|
|
|
48
|
+
if (safeInput?.seo) {
|
|
49
|
+
const { seo } = safeInput
|
|
50
|
+
const { assets = [] } = (seo as UIDLComponentSEO) || { assets: [] }
|
|
51
|
+
|
|
52
|
+
assets.forEach(parseAssets)
|
|
53
|
+
}
|
|
54
|
+
|
|
45
55
|
const node = safeInput.node as Record<string, unknown>
|
|
46
56
|
const result: ComponentUIDL = {
|
|
47
57
|
...(safeInput as unknown as ComponentUIDL),
|
|
@@ -68,6 +78,8 @@ export const parseProjectJSON = (
|
|
|
68
78
|
}
|
|
69
79
|
result.root = parseComponentJSON(root, { noClone: true })
|
|
70
80
|
|
|
81
|
+
result.globals?.assets?.forEach(parseAssets)
|
|
82
|
+
|
|
71
83
|
if (result.root?.designLanguage) {
|
|
72
84
|
const { tokens = {} } = result.root.designLanguage
|
|
73
85
|
|
|
@@ -225,3 +237,14 @@ const parseComponentNode = (node: Record<string, unknown>): UIDLNode => {
|
|
|
225
237
|
throw new ParserError(`parseComponentNode attempted to parsed invalid node type ${node.type}`)
|
|
226
238
|
}
|
|
227
239
|
}
|
|
240
|
+
|
|
241
|
+
export const parseAssets = (asset: VUIDLGlobalAsset): UIDLGlobalAsset => {
|
|
242
|
+
if ('attrs' in asset) {
|
|
243
|
+
asset.attrs = UIDLUtils.transformAttributesAssignmentsToJson(asset.attrs) as Record<
|
|
244
|
+
string,
|
|
245
|
+
UIDLStaticValue
|
|
246
|
+
>
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
return asset as UIDLGlobalAsset
|
|
250
|
+
}
|
package/src/validator/index.ts
CHANGED
|
@@ -17,7 +17,9 @@ interface ValidationResult {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
export default class Validator {
|
|
20
|
-
public validateComponentSchema(
|
|
20
|
+
public validateComponentSchema(
|
|
21
|
+
input: Record<string, unknown> | VComponentUIDL
|
|
22
|
+
): ValidationResult {
|
|
21
23
|
try {
|
|
22
24
|
const cleanedUIDL = utils.validateNulls(input)
|
|
23
25
|
const uidl = componentUIDLDecoder.runWithException(cleanedUIDL)
|
|
@@ -30,7 +32,9 @@ export default class Validator {
|
|
|
30
32
|
}
|
|
31
33
|
}
|
|
32
34
|
|
|
33
|
-
public validateRootComponentSchema(
|
|
35
|
+
public validateRootComponentSchema(
|
|
36
|
+
input: Record<string, unknown> | VComponentUIDL
|
|
37
|
+
): ValidationResult {
|
|
34
38
|
try {
|
|
35
39
|
const cleanedUIDL = utils.validateNulls(input)
|
|
36
40
|
const uidl = rootComponentUIDLDecoder.runWithException(cleanedUIDL)
|
|
@@ -43,7 +47,7 @@ export default class Validator {
|
|
|
43
47
|
}
|
|
44
48
|
}
|
|
45
49
|
|
|
46
|
-
public validateProjectSchema(input: Record<string, unknown>): ValidationResult {
|
|
50
|
+
public validateProjectSchema(input: Record<string, unknown> | VProjectUIDL): ValidationResult {
|
|
47
51
|
try {
|
|
48
52
|
const cleanedUIDL = utils.validateNulls(input)
|
|
49
53
|
const uidl = projectUIDLDecoder.runWithException(cleanedUIDL)
|
package/src/validator/utils.ts
CHANGED
|
@@ -100,6 +100,27 @@ export const checkDynamicDefinitions = (input: Record<string, unknown>) => {
|
|
|
100
100
|
const errors: string[] = []
|
|
101
101
|
|
|
102
102
|
UIDLUtils.traverseNodes(input.node as UIDLNode, (node) => {
|
|
103
|
+
if (node.type === 'element') {
|
|
104
|
+
const { content } = node
|
|
105
|
+
const compStyleReference = Object.values(content?.attrs || {}).find(
|
|
106
|
+
(attr) => attr.type === 'comp-style'
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
if (
|
|
110
|
+
compStyleReference &&
|
|
111
|
+
content.elementType !== 'component' &&
|
|
112
|
+
content?.dependency?.type === 'local'
|
|
113
|
+
) {
|
|
114
|
+
const errorMsg = `${JSON.stringify(
|
|
115
|
+
compStyleReference,
|
|
116
|
+
null,
|
|
117
|
+
2
|
|
118
|
+
)} can only be assigned on a local component instances. Tried to assign on ${content}`
|
|
119
|
+
|
|
120
|
+
errors.push(errorMsg)
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
103
124
|
if (node.type === 'element') {
|
|
104
125
|
Object.keys(node.content?.events || {}).forEach((eventKey) => {
|
|
105
126
|
node.content.events[eventKey].forEach((event) => {
|