@teleporthq/teleport-uidl-validator 0.41.0 → 0.42.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/__tests__/decoder/index.ts +70 -0
- package/__tests__/parser/compoenent-with-state-reference.json +110 -0
- package/__tests__/parser/component-parsing.ts +13 -1
- package/__tests__/validator/index.ts +17 -24
- package/__tests__/validator/project-sample.json +15 -0
- package/dist/cjs/decoders/component-decoder.js +3 -3
- package/dist/cjs/decoders/component-decoder.js.map +1 -1
- package/dist/cjs/decoders/custom-combinators.d.ts +5 -8
- package/dist/cjs/decoders/custom-combinators.d.ts.map +1 -1
- package/dist/cjs/decoders/custom-combinators.js +42 -60
- package/dist/cjs/decoders/custom-combinators.js.map +1 -1
- package/dist/cjs/decoders/project-decoder.d.ts.map +1 -1
- package/dist/cjs/decoders/project-decoder.js +11 -0
- package/dist/cjs/decoders/project-decoder.js.map +1 -1
- package/dist/cjs/decoders/utils.d.ts +119 -5
- package/dist/cjs/decoders/utils.d.ts.map +1 -1
- package/dist/cjs/decoders/utils.js +327 -47
- package/dist/cjs/decoders/utils.js.map +1 -1
- package/dist/cjs/parser/index.d.ts.map +1 -1
- package/dist/cjs/parser/index.js +132 -16
- package/dist/cjs/parser/index.js.map +1 -1
- package/dist/cjs/tsconfig.tsbuildinfo +1 -1
- package/dist/cjs/validator/index.d.ts.map +1 -1
- package/dist/cjs/validator/index.js.map +1 -1
- package/dist/cjs/validator/utils.d.ts.map +1 -1
- package/dist/cjs/validator/utils.js +25 -21
- package/dist/cjs/validator/utils.js.map +1 -1
- package/dist/esm/decoders/component-decoder.js +3 -3
- package/dist/esm/decoders/component-decoder.js.map +1 -1
- package/dist/esm/decoders/custom-combinators.d.ts +5 -8
- package/dist/esm/decoders/custom-combinators.d.ts.map +1 -1
- package/dist/esm/decoders/custom-combinators.js +38 -60
- package/dist/esm/decoders/custom-combinators.js.map +1 -1
- package/dist/esm/decoders/project-decoder.d.ts.map +1 -1
- package/dist/esm/decoders/project-decoder.js +13 -2
- package/dist/esm/decoders/project-decoder.js.map +1 -1
- package/dist/esm/decoders/utils.d.ts +119 -5
- package/dist/esm/decoders/utils.d.ts.map +1 -1
- package/dist/esm/decoders/utils.js +327 -47
- package/dist/esm/decoders/utils.js.map +1 -1
- package/dist/esm/parser/index.d.ts.map +1 -1
- package/dist/esm/parser/index.js +132 -16
- package/dist/esm/parser/index.js.map +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/dist/esm/validator/index.d.ts.map +1 -1
- package/dist/esm/validator/index.js.map +1 -1
- package/dist/esm/validator/utils.d.ts.map +1 -1
- package/dist/esm/validator/utils.js +26 -22
- package/dist/esm/validator/utils.js.map +1 -1
- package/package.json +4 -4
- package/src/decoders/component-decoder.ts +3 -3
- package/src/decoders/custom-combinators.ts +33 -51
- package/src/decoders/project-decoder.ts +21 -1
- package/src/decoders/utils.ts +469 -60
- package/src/parser/index.ts +204 -19
- package/src/validator/index.ts +1 -0
- package/src/validator/utils.ts +45 -25
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { UIDLConditionalNode } from '@teleporthq/teleport-types'
|
|
2
|
+
import { conditionalNodeDecoder } from '../../src/decoders/utils'
|
|
3
|
+
|
|
4
|
+
test('decode conditional nodes properly when using dynamic and expression reference', () => {
|
|
5
|
+
const node: UIDLConditionalNode = {
|
|
6
|
+
type: 'conditional',
|
|
7
|
+
content: {
|
|
8
|
+
node: {
|
|
9
|
+
type: 'element',
|
|
10
|
+
content: {
|
|
11
|
+
elementType: 'cms-navigation-button',
|
|
12
|
+
semanticType: 'div',
|
|
13
|
+
name: 'Previous',
|
|
14
|
+
referencedStyles: {
|
|
15
|
+
TQ_Cami9r8BH2: {
|
|
16
|
+
type: 'style-map',
|
|
17
|
+
content: {
|
|
18
|
+
mapType: 'project-referenced',
|
|
19
|
+
referenceId: 'button',
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
abilities: {
|
|
24
|
+
link: {
|
|
25
|
+
type: 'navlink',
|
|
26
|
+
content: {
|
|
27
|
+
routeName: {
|
|
28
|
+
type: 'expr',
|
|
29
|
+
content:
|
|
30
|
+
// tslint:disable no-invalid-template-strings
|
|
31
|
+
"`?${new URLSearchParams({...router.query, ['cPage-5iuksa']: parseInt(router.query['cPage-5iuksa']) - 1 || 1})}`",
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
style: {
|
|
37
|
+
display: {
|
|
38
|
+
type: 'static',
|
|
39
|
+
content: 'flex',
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
children: [
|
|
43
|
+
{
|
|
44
|
+
type: 'element',
|
|
45
|
+
content: {
|
|
46
|
+
elementType: 'text',
|
|
47
|
+
referencedStyles: {},
|
|
48
|
+
abilities: {},
|
|
49
|
+
children: [
|
|
50
|
+
{
|
|
51
|
+
type: 'static',
|
|
52
|
+
content: 'Previous',
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
reference: {
|
|
61
|
+
type: 'expr',
|
|
62
|
+
content: 'params?.meta?.pagination.hasPrevPage',
|
|
63
|
+
},
|
|
64
|
+
value: true,
|
|
65
|
+
},
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const result = conditionalNodeDecoder.run(node)
|
|
69
|
+
expect(result.ok).toBeTruthy()
|
|
70
|
+
})
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
{
|
|
2
|
+
"stateDefinitions": {
|
|
3
|
+
"isVisible_": {
|
|
4
|
+
"defaultValue": true,
|
|
5
|
+
"type": "boolean"
|
|
6
|
+
}
|
|
7
|
+
},
|
|
8
|
+
"node": {
|
|
9
|
+
"type": "element",
|
|
10
|
+
"content": {
|
|
11
|
+
"elementType": "container",
|
|
12
|
+
"semanticType": "div",
|
|
13
|
+
"referencedStyles": {},
|
|
14
|
+
"abilities": {},
|
|
15
|
+
"style": {
|
|
16
|
+
"width": {
|
|
17
|
+
"type": "static",
|
|
18
|
+
"content": "100%"
|
|
19
|
+
},
|
|
20
|
+
"height": {
|
|
21
|
+
"type": "static",
|
|
22
|
+
"content": "400px"
|
|
23
|
+
},
|
|
24
|
+
"display": {
|
|
25
|
+
"type": "static",
|
|
26
|
+
"content": "flex"
|
|
27
|
+
},
|
|
28
|
+
"position": {
|
|
29
|
+
"type": "static",
|
|
30
|
+
"content": "relative"
|
|
31
|
+
},
|
|
32
|
+
"alignItems": {
|
|
33
|
+
"type": "static",
|
|
34
|
+
"content": "center"
|
|
35
|
+
},
|
|
36
|
+
"flexDirection": {
|
|
37
|
+
"type": "static",
|
|
38
|
+
"content": "row"
|
|
39
|
+
},
|
|
40
|
+
"justifyContent": {
|
|
41
|
+
"type": "static",
|
|
42
|
+
"content": "center"
|
|
43
|
+
},
|
|
44
|
+
"gap": {
|
|
45
|
+
"type": "dynamic",
|
|
46
|
+
"content": {
|
|
47
|
+
"referenceType": "token",
|
|
48
|
+
"id": "--dl-space-space-halfunit",
|
|
49
|
+
"fallback": ""
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
"children": [
|
|
54
|
+
{
|
|
55
|
+
"type": "conditional",
|
|
56
|
+
"content": {
|
|
57
|
+
"node": {
|
|
58
|
+
"type": "element",
|
|
59
|
+
"content": {
|
|
60
|
+
"elementType": "image",
|
|
61
|
+
"referencedStyles": {},
|
|
62
|
+
"abilities": {},
|
|
63
|
+
"attrs": {
|
|
64
|
+
"src": {
|
|
65
|
+
"type": "dynamic",
|
|
66
|
+
"content": {
|
|
67
|
+
"referenceType": "prop",
|
|
68
|
+
"id": "imagesrc1",
|
|
69
|
+
"fallback": ""
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
"alt": {
|
|
73
|
+
"type": "dynamic",
|
|
74
|
+
"content": {
|
|
75
|
+
"referenceType": "prop",
|
|
76
|
+
"id": "imagealt1",
|
|
77
|
+
"fallback": ""
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
"style": {
|
|
82
|
+
"width": {
|
|
83
|
+
"type": "static",
|
|
84
|
+
"content": "200px"
|
|
85
|
+
},
|
|
86
|
+
"objectFit": {
|
|
87
|
+
"type": "static",
|
|
88
|
+
"content": "cover"
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
"children": []
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
"reference": {
|
|
95
|
+
"type": "dynamic",
|
|
96
|
+
"content": {
|
|
97
|
+
"referenceType": "state",
|
|
98
|
+
"id": "isVisible_"
|
|
99
|
+
},
|
|
100
|
+
"pos": ""
|
|
101
|
+
},
|
|
102
|
+
"value": false
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
]
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
"name": "Component",
|
|
109
|
+
"styleSetDefinitions": {}
|
|
110
|
+
}
|
|
@@ -6,9 +6,11 @@ import componentResultJSON from './component-with-proper-values.json'
|
|
|
6
6
|
import componentStyleSetsInputJSON from './component-with-reusalble-styles.json'
|
|
7
7
|
// @ts-ignore
|
|
8
8
|
import componentWithReferencedStylesJSON from './componennt-with-referenced-styles.json'
|
|
9
|
+
// @ts-ignore
|
|
10
|
+
import componentWithStateReferences from './compoenent-with-state-reference.json'
|
|
9
11
|
|
|
10
12
|
import { parseComponentJSON, parseProjectJSON } from '../../src/parser'
|
|
11
|
-
import { ComponentUIDL } from '@teleporthq/teleport-types'
|
|
13
|
+
import { ComponentUIDL, UIDLConditionalNode } from '@teleporthq/teleport-types'
|
|
12
14
|
|
|
13
15
|
describe('parseComponentJSON', () => {
|
|
14
16
|
it('transforms primitive component values', () => {
|
|
@@ -113,4 +115,14 @@ describe('RefernecedStyles for ComponentUIDL', () => {
|
|
|
113
115
|
const result = parseComponentJSON(uidl as unknown as Record<string, unknown>)
|
|
114
116
|
expect(result).toEqual(result)
|
|
115
117
|
})
|
|
118
|
+
|
|
119
|
+
it('Parses reference on a conditional node and changes the state/prop references', () => {
|
|
120
|
+
const result = parseComponentJSON(
|
|
121
|
+
componentWithStateReferences as unknown as Record<string, string>
|
|
122
|
+
)
|
|
123
|
+
const conditionalNode = result.node.content.children?.[0]
|
|
124
|
+
|
|
125
|
+
expect(result.stateDefinitions?.isVisible).toBeDefined()
|
|
126
|
+
expect((conditionalNode as UIDLConditionalNode)?.content.reference.content.id).toBe('isVisible')
|
|
127
|
+
})
|
|
116
128
|
})
|
|
@@ -28,16 +28,23 @@ import { parseProjectJSON } from '../../src/parser'
|
|
|
28
28
|
|
|
29
29
|
const uidl = component(
|
|
30
30
|
'Repeat Component',
|
|
31
|
-
elementNode(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
31
|
+
elementNode(
|
|
32
|
+
'container',
|
|
33
|
+
{ fields: { type: 'dynamic', content: { referenceType: 'prop', id: 'fields["bg Image"]' } } },
|
|
34
|
+
[
|
|
35
|
+
repeatNode(
|
|
36
|
+
elementNode('div', {}, [dynamicNode('local', 'item')]),
|
|
37
|
+
dynamicNode('prop', 'items'),
|
|
38
|
+
{
|
|
39
|
+
useIndex: true,
|
|
40
|
+
}
|
|
41
|
+
),
|
|
42
|
+
]
|
|
43
|
+
),
|
|
44
|
+
{
|
|
45
|
+
items: definition('array', ['hello', 'world']),
|
|
46
|
+
fields: definition('object', { 'bg Image': 'test' }),
|
|
47
|
+
},
|
|
41
48
|
{ items: definition('array', ['hello', 'world']) }
|
|
42
49
|
)
|
|
43
50
|
|
|
@@ -130,20 +137,6 @@ describe('Validate UIDL', () => {
|
|
|
130
137
|
// "isOpen" is used in events, but not defined. Please add it in stateDefinitions
|
|
131
138
|
// )
|
|
132
139
|
})
|
|
133
|
-
|
|
134
|
-
it('throws an error if event name is empty string', () => {
|
|
135
|
-
const validator = new Validator()
|
|
136
|
-
// @ts-ignore
|
|
137
|
-
expect(() => validator.validateComponentSchema(ComponentUidlElementWithEmptyName)).toThrow(
|
|
138
|
-
Error
|
|
139
|
-
)
|
|
140
|
-
|
|
141
|
-
// expect(validationResult.errorMsg).toBe(
|
|
142
|
-
// UIDL Format Validation Error. Please check the following:
|
|
143
|
-
// - Path undefined: Error: Name attribute cannot be empty.
|
|
144
|
-
// is a undefined
|
|
145
|
-
// )
|
|
146
|
-
})
|
|
147
140
|
})
|
|
148
141
|
|
|
149
142
|
describe('Project UIDL Format', () => {
|
|
@@ -265,6 +265,14 @@
|
|
|
265
265
|
"items": {
|
|
266
266
|
"type": "array",
|
|
267
267
|
"defaultValue": []
|
|
268
|
+
},
|
|
269
|
+
"hero": {
|
|
270
|
+
"type": "object",
|
|
271
|
+
"defaultValue": {
|
|
272
|
+
"bg Image": {
|
|
273
|
+
"src": "test"
|
|
274
|
+
}
|
|
275
|
+
}
|
|
268
276
|
}
|
|
269
277
|
},
|
|
270
278
|
"stateDefinitions": {
|
|
@@ -288,6 +296,13 @@
|
|
|
288
296
|
"referenceType": "prop",
|
|
289
297
|
"id": "title"
|
|
290
298
|
}
|
|
299
|
+
},
|
|
300
|
+
"bgImage": {
|
|
301
|
+
"type": "dynamic",
|
|
302
|
+
"content": {
|
|
303
|
+
"referenceType": "prop",
|
|
304
|
+
"id": "hero['bg Image'].src"
|
|
305
|
+
}
|
|
291
306
|
}
|
|
292
307
|
},
|
|
293
308
|
"children": [
|
|
@@ -7,7 +7,7 @@ exports.componentUIDLDecoder = (0, json_type_validation_1.object)({
|
|
|
7
7
|
name: (0, json_type_validation_1.withDefault)('MyComponent', (0, json_type_validation_1.string)()),
|
|
8
8
|
node: utils_1.elementNodeDecoder,
|
|
9
9
|
stateDefinitions: (0, json_type_validation_1.optional)((0, json_type_validation_1.dict)(utils_1.stateDefinitionsDecoder)),
|
|
10
|
-
propDefinitions: (0, json_type_validation_1.
|
|
10
|
+
propDefinitions: (0, json_type_validation_1.withDefault)({}, (0, json_type_validation_1.dict)(utils_1.propDefinitionsDecoder)),
|
|
11
11
|
styleSetDefinitions: (0, json_type_validation_1.optional)((0, json_type_validation_1.dict)(utils_1.styleSetDefinitionDecoder)),
|
|
12
12
|
importDefinitions: (0, json_type_validation_1.optional)((0, json_type_validation_1.dict)(utils_1.externaldependencyDecoder)),
|
|
13
13
|
outputOptions: (0, json_type_validation_1.optional)(utils_1.outputOptionsDecoder),
|
|
@@ -23,10 +23,10 @@ exports.rootComponentUIDLDecoder = (0, json_type_validation_1.object)({
|
|
|
23
23
|
values: (0, json_type_validation_1.array)(utils_1.stateValueDetailsDecoder),
|
|
24
24
|
}),
|
|
25
25
|
})),
|
|
26
|
-
propDefinitions: (0, json_type_validation_1.
|
|
26
|
+
propDefinitions: (0, json_type_validation_1.withDefault)({}, (0, json_type_validation_1.dict)(utils_1.propDefinitionsDecoder)),
|
|
27
27
|
importDefinitions: (0, json_type_validation_1.optional)((0, json_type_validation_1.dict)(utils_1.externaldependencyDecoder)),
|
|
28
28
|
peerDefinitions: (0, json_type_validation_1.optional)((0, json_type_validation_1.dict)(utils_1.peerDependencyDecoder)),
|
|
29
|
-
styleSetDefinitions: (0, json_type_validation_1.
|
|
29
|
+
styleSetDefinitions: (0, json_type_validation_1.withDefault)({}, (0, json_type_validation_1.dict)(utils_1.styleSetDefinitionDecoder)),
|
|
30
30
|
outputOptions: (0, json_type_validation_1.optional)(utils_1.outputOptionsDecoder),
|
|
31
31
|
seo: (0, json_type_validation_1.optional)(utils_1.componentSeoDecoder),
|
|
32
32
|
designLanguage: (0, json_type_validation_1.optional)((0, json_type_validation_1.object)({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component-decoder.js","sourceRoot":"","sources":["../../../src/decoders/component-decoder.ts"],"names":[],"mappings":";;;AAAA,uEASuC;AAEvC,iCAWgB;AAEH,QAAA,oBAAoB,GAA4B,IAAA,6BAAM,EAAC;IACl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,IAAA,6BAAM,GAAE;YACd,YAAY,EAAE,IAAA,6BAAM,GAAE;YACtB,MAAM,EAAE,IAAA,4BAAK,EAAC,gCAAwB,CAAC;SACxC,CAAC;KACH,CAAC,CACH;IACD,eAAe,EAAE,IAAA,kCAAW,EAAC,EAAE,EAAE,IAAA,2BAAI,EAAC,8BAAsB,CAAC,CAAC;IAC9D,iBAAiB,EAAE,IAAA,+BAAQ,EAAC,IAAA,2BAAI,EAAC,iCAAyB,CAAC,CAAC;IAC5D,eAAe,EAAE,IAAA,+BAAQ,EAAC,IAAA,2BAAI,EAAC,6BAAqB,CAAC,CAAC;IACtD,mBAAmB,EAAE,IAAA,kCAAW,EAAC,EAAE,EAAE,IAAA,2BAAI,EAAC,iCAAyB,CAAC,CAAC;IACrE,aAAa,EAAE,IAAA,+BAAQ,EAAC,4BAAoB,CAAC;IAC7C,GAAG,EAAE,IAAA,+BAAQ,EAAC,2BAAmB,CAAC;IAClC,cAAc,EAAE,IAAA,+BAAQ,EACtB,IAAA,6BAAM,EAAC;QACL,MAAM,EAAE,IAAA,+BAAQ,EAAC,2BAAmB,CAAC;KACtC,CAAC,CACH;CACF,CAAC,CAAA"}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
static isValidFileName(): CustomCombinators<string>;
|
|
7
|
-
static isValidElementName(): CustomCombinators<string>;
|
|
8
|
-
}
|
|
1
|
+
import { Decoder } from '@mojotech/json-type-validation';
|
|
2
|
+
export declare const isValidComponentName: (name: string) => Decoder<string>;
|
|
3
|
+
export declare const isValidNavLink: (link: string) => Decoder<string>;
|
|
4
|
+
export declare const isValidFileName: (name: string) => Decoder<string>;
|
|
5
|
+
export declare const isValidElementName: (name: string) => Decoder<string>;
|
|
9
6
|
//# sourceMappingURL=custom-combinators.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"custom-combinators.d.ts","sourceRoot":"","sources":["../../../src/decoders/custom-combinators.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"custom-combinators.d.ts","sourceRoot":"","sources":["../../../src/decoders/custom-combinators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,OAAO,EAAE,MAAM,gCAAgC,CAAA;AAOvE,eAAO,MAAM,oBAAoB,SAAU,MAAM,KAAG,QAAQ,MAAM,CAOjE,CAAA;AAED,eAAO,MAAM,cAAc,SAAU,MAAM,KAAG,QAAQ,MAAM,CAe3D,CAAA;AAED,eAAO,MAAM,eAAe,SAAU,MAAM,KAAG,QAAQ,MAAM,CAO5D,CAAA;AAED,eAAO,MAAM,kBAAkB,SAAU,MAAM,KAAG,QAAQ,MAAM,CAO/D,CAAA"}
|
|
@@ -1,65 +1,47 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
/* tslint:disable member-ordering */
|
|
3
|
+
exports.isValidElementName = exports.isValidFileName = exports.isValidNavLink = exports.isValidComponentName = void 0;
|
|
5
4
|
var json_type_validation_1 = require("@mojotech/json-type-validation");
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
/* These are some custom combinators that comes in handy for us,
|
|
6
|
+
instead of parsing and cross-checking regex again. The combinators,
|
|
7
|
+
can used inside a existing Decoder, since we did not implement any run()
|
|
8
|
+
runWithException() etc */
|
|
9
|
+
var isValidComponentName = function (name) {
|
|
10
|
+
var componentNameRegex = new RegExp('^[A-Z]+[a-zA-Z0-9]*$');
|
|
11
|
+
if (name && typeof name === 'string' && componentNameRegex.test(name)) {
|
|
12
|
+
return (0, json_type_validation_1.succeed)(name);
|
|
10
13
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
return
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
else if (json.length === 0) {
|
|
45
|
-
throw new Error("File Name cannot be empty");
|
|
46
|
-
}
|
|
47
|
-
throw new Error("Invalid File name, received ".concat(json));
|
|
48
|
-
});
|
|
49
|
-
};
|
|
50
|
-
CustomCombinators.isValidElementName = function () {
|
|
51
|
-
return new CustomCombinators(function (json) {
|
|
52
|
-
var fileNameRegex = new RegExp('^[a-zA-Z]+[a-zA-Z0-9-_]*$');
|
|
53
|
-
if (json && typeof json === 'string' && fileNameRegex.test(json)) {
|
|
54
|
-
return json_type_validation_1.Result.ok(json);
|
|
55
|
-
}
|
|
56
|
-
else if (json.length === 0) {
|
|
57
|
-
throw new Error("Name attribute cannot be empty");
|
|
58
|
-
}
|
|
59
|
-
throw new Error("Invalid name attribute, received ".concat(json));
|
|
60
|
-
});
|
|
61
|
-
};
|
|
62
|
-
return CustomCombinators;
|
|
63
|
-
}());
|
|
64
|
-
exports.CustomCombinators = CustomCombinators;
|
|
14
|
+
return (0, json_type_validation_1.fail)("Invalid Component name, got ".concat(name));
|
|
15
|
+
};
|
|
16
|
+
exports.isValidComponentName = isValidComponentName;
|
|
17
|
+
var isValidNavLink = function (link) {
|
|
18
|
+
if (!link || typeof link !== 'string') {
|
|
19
|
+
throw new Error("Invalid navLink attribute, received ".concat(link));
|
|
20
|
+
}
|
|
21
|
+
if (link === '**') {
|
|
22
|
+
return (0, json_type_validation_1.succeed)(link);
|
|
23
|
+
}
|
|
24
|
+
var navLinkRegex = new RegExp('/(?:[a-zA-Z0-9-_]+|/[[a-zA-Z]+]|[/[a-zA-Z]+])*');
|
|
25
|
+
if (navLinkRegex.test(link)) {
|
|
26
|
+
return (0, json_type_validation_1.succeed)(link);
|
|
27
|
+
}
|
|
28
|
+
return (0, json_type_validation_1.fail)("Invalid navLink attribute, received ".concat(link));
|
|
29
|
+
};
|
|
30
|
+
exports.isValidNavLink = isValidNavLink;
|
|
31
|
+
var isValidFileName = function (name) {
|
|
32
|
+
var fileNameRegex = new RegExp('^[[a-zA-Z0-9-_.]+]*$');
|
|
33
|
+
if (name && typeof name === 'string' && fileNameRegex.test(name)) {
|
|
34
|
+
return (0, json_type_validation_1.succeed)(name);
|
|
35
|
+
}
|
|
36
|
+
return (0, json_type_validation_1.fail)("Invalid File name, received ".concat(name));
|
|
37
|
+
};
|
|
38
|
+
exports.isValidFileName = isValidFileName;
|
|
39
|
+
var isValidElementName = function (name) {
|
|
40
|
+
var elementNameRefex = new RegExp('^[a-zA-Z]+[a-zA-Z0-9-_]*$');
|
|
41
|
+
if (name && typeof name === 'string' && elementNameRefex.test(name)) {
|
|
42
|
+
return (0, json_type_validation_1.succeed)(name);
|
|
43
|
+
}
|
|
44
|
+
return (0, json_type_validation_1.fail)("Invalid name attribute, received ".concat(name));
|
|
45
|
+
};
|
|
46
|
+
exports.isValidElementName = isValidElementName;
|
|
65
47
|
//# sourceMappingURL=custom-combinators.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"custom-combinators.js","sourceRoot":"","sources":["../../../src/decoders/custom-combinators.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"custom-combinators.js","sourceRoot":"","sources":["../../../src/decoders/custom-combinators.ts"],"names":[],"mappings":";;;AAAA,uEAAuE;AAEvE;;;yBAGyB;AAElB,IAAM,oBAAoB,GAAG,UAAC,IAAY;IAC/C,IAAM,kBAAkB,GAAG,IAAI,MAAM,CAAC,sBAAsB,CAAC,CAAA;IAC7D,IAAI,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,kBAAkB,CAAC,IAAI,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,QAAQ,IAAI,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;QACnE,OAAO,IAAA,8BAAO,EAAC,IAAI,CAAC,CAAA;KACrB;IAED,OAAO,IAAA,2BAAI,EAAC,2CAAoC,IAAI,CAAE,CAAC,CAAA;AACzD,CAAC,CAAA;AAPY,QAAA,kBAAkB,sBAO9B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project-decoder.d.ts","sourceRoot":"","sources":["../../../src/decoders/project-decoder.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,
|
|
1
|
+
{"version":3,"file":"project-decoder.d.ts","sourceRoot":"","sources":["../../../src/decoders/project-decoder.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EAWR,MAAM,gCAAgC,CAAA;AACvC,OAAO,EACL,wBAAwB,EACxB,WAAW,EACX,YAAY,EACZ,aAAa,EAEd,MAAM,4BAA4B,CAAA;AAanC,eAAO,MAAM,kBAAkB,EAAE,OAAO,CAAC,WAAW,CAUlD,CAAA;AAEF,eAAO,MAAM,0BAA0B,EAAE,OAAO,CAAC,wBAAwB,CAgBvE,CAAA;AAEF,eAAO,MAAM,gBAAgB,EAAE,OAAO,CAAC,aAAa,CAkBlD,CAAA;AAEF,eAAO,MAAM,kBAAkB,EAAE,OAAO,CAAC,YAAY,CAmB1B,CAAA"}
|
|
@@ -50,5 +50,16 @@ exports.projectUIDLDecoder = (0, json_type_validation_1.object)({
|
|
|
50
50
|
root: component_decoder_1.rootComponentUIDLDecoder,
|
|
51
51
|
components: (0, json_type_validation_1.optional)((0, json_type_validation_1.dict)(component_decoder_1.componentUIDLDecoder)),
|
|
52
52
|
resources: (0, json_type_validation_1.optional)(exports.resourcesDecoder),
|
|
53
|
+
dataSources: (0, json_type_validation_1.optional)(utils_1.dataSourcesDecoder),
|
|
54
|
+
forms: (0, json_type_validation_1.optional)(utils_1.formsDecoder),
|
|
55
|
+
internationalization: (0, json_type_validation_1.optional)((0, json_type_validation_1.object)({
|
|
56
|
+
main: (0, json_type_validation_1.object)({
|
|
57
|
+
name: (0, json_type_validation_1.string)(),
|
|
58
|
+
locale: (0, json_type_validation_1.string)(),
|
|
59
|
+
}),
|
|
60
|
+
ignoreBrowserLanguage: (0, json_type_validation_1.optional)((0, json_type_validation_1.boolean)()),
|
|
61
|
+
languages: (0, json_type_validation_1.dict)((0, json_type_validation_1.string)()),
|
|
62
|
+
translations: (0, json_type_validation_1.dict)((0, json_type_validation_1.dict)((0, json_type_validation_1.union)(utils_1.elementNodeDecoder, utils_1.staticValueDecoder))),
|
|
63
|
+
})),
|
|
53
64
|
});
|
|
54
65
|
//# sourceMappingURL=project-decoder.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project-decoder.js","sourceRoot":"","sources":["../../../src/decoders/project-decoder.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"project-decoder.js","sourceRoot":"","sources":["../../../src/decoders/project-decoder.ts"],"names":[],"mappings":";;;AAAA,uEAYuC;AAQvC,iCASgB;AAChB,yDAAoF;AAEvE,QAAA,kBAAkB,GAAyB,IAAA,6BAAM,EAAC;IAC7D,UAAU,EAAE,IAAA,+BAAQ,EAAC,IAAA,6BAAM,GAAE,CAAC;IAC9B,IAAI,EAAE,IAAA,+BAAQ,EAAC,IAAA,6BAAM,GAAE,CAAC;IACxB,KAAK,EAAE,IAAA,+BAAQ,EAAC,IAAA,4BAAK,EAAC,IAAA,6BAAM,EAAC,EAAE,GAAG,EAAE,IAAA,6BAAM,GAAE,EAAE,IAAI,EAAE,IAAA,6BAAM,GAAE,EAAE,KAAK,EAAE,IAAA,6BAAM,GAAE,EAAE,CAAC,CAAC,CAAC;IAClF,SAAS,EAAE,IAAA,+BAAQ,EAAC,IAAA,6BAAM,GAAE,CAAC;IAC7B,gBAAgB,EAAE,IAAA,+BAAQ,EAAC,IAAA,6BAAM,GAAE,CAAC;IACpC,OAAO,EAAE,IAAA,+BAAQ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