New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@teleporthq/teleport-uidl-validator

Package Overview
Dependencies
Maintainers
0
Versions
122
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@teleporthq/teleport-uidl-validator - npm Package Compare versions

Comparing version 0.36.0-alpha.0 to 0.36.0

__tests__/decoder/index.ts

14

__tests__/parser/component-parsing.ts

@@ -9,5 +9,7 @@ // @ts-ignore

import componentWithReferencedStylesJSON from './componennt-with-referenced-styles.json'
// @ts-ignore
import componentWithStateReferences from './compoenent-with-state-reference.json'
import { parseComponentJSON, parseProjectJSON } from '../../src/parser'
import { ComponentUIDL } from '@teleporthq/teleport-types'
import { ComponentUIDL, UIDLConditionalNode } from '@teleporthq/teleport-types'

@@ -117,2 +119,12 @@ describe('parseComponentJSON', () => {

})
it('Parses reference on a conditional node and changes the state/prop references', () => {
const result = parseComponentJSON(
componentWithStateReferences as unknown as Record<string, string>
)
const conditionalNode = result.node.content.children?.[0]
expect(result.stateDefinitions?.isVisible).toBeDefined()
expect((conditionalNode as UIDLConditionalNode)?.content.reference.content.id).toBe('isVisible')
})
})

41

__tests__/validator/index.ts

@@ -31,12 +31,19 @@ import { Validator } from '../../src'

'Repeat Component',
elementNode('container', {}, [
repeatNode(
elementNode('div', {}, [dynamicNode('local', 'item')]),
dynamicNode('prop', 'items'),
{
useIndex: true,
}
),
]),
{ items: definition('array', ['hello', 'world']) },
elementNode(
'container',
{ fields: { type: 'dynamic', content: { referenceType: 'prop', id: 'fields["bg Image"]' } } },
[
repeatNode(
elementNode('div', {}, [dynamicNode('local', 'item')]),
dynamicNode('prop', 'items'),
{
useIndex: true,
}
),
]
),
{
items: definition('array', ['hello', 'world']),
fields: definition('object', { 'bg Image': 'test' }),
},
{ items: definition('array', ['hello', 'world']) }

@@ -134,16 +141,2 @@ )

})
it('throws an error if event name is empty string', () => {
const validator = new Validator()
// @ts-ignore
expect(() => validator.validateComponentSchema(ComponentUidlElementWithEmptyName)).toThrow(
Error
)
// expect(validationResult.errorMsg).toBe(
// UIDL Format Validation Error. Please check the following:
// - Path undefined: Error: Name attribute cannot be empty.
// is a undefined
// )
})
})

@@ -150,0 +143,0 @@

@@ -268,2 +268,10 @@ {

"defaultValue": []
},
"hero": {
"type": "object",
"defaultValue": {
"bg Image": {
"src": "test"
}
}
}

@@ -292,2 +300,9 @@ },

}
},
"bgImage": {
"type": "dynamic",
"content": {
"referenceType": "prop",
"id": "hero['bg Image'].src"
}
}

@@ -294,0 +309,0 @@ },

@@ -10,3 +10,3 @@ "use strict";

stateDefinitions: (0, json_type_validation_1.optional)((0, json_type_validation_1.dict)(utils_1.stateDefinitionsDecoder)),
propDefinitions: (0, json_type_validation_1.optional)((0, json_type_validation_1.dict)(utils_1.propDefinitionsDecoder)),
propDefinitions: (0, json_type_validation_1.withDefault)({}, (0, json_type_validation_1.dict)(utils_1.propDefinitionsDecoder)),
styleSetDefinitions: (0, json_type_validation_1.optional)((0, json_type_validation_1.dict)(utils_1.styleSetDefinitionDecoder)),

@@ -27,6 +27,6 @@ importDefinitions: (0, json_type_validation_1.optional)((0, json_type_validation_1.dict)(utils_1.externaldependencyDecoder)),

})),
propDefinitions: (0, json_type_validation_1.optional)((0, json_type_validation_1.dict)(utils_1.propDefinitionsDecoder)),
propDefinitions: (0, json_type_validation_1.withDefault)({}, (0, json_type_validation_1.dict)(utils_1.propDefinitionsDecoder)),
importDefinitions: (0, json_type_validation_1.optional)((0, json_type_validation_1.dict)(utils_1.externaldependencyDecoder)),
peerDefinitions: (0, json_type_validation_1.optional)((0, json_type_validation_1.dict)(utils_1.peerDependencyDecoder)),
styleSetDefinitions: (0, json_type_validation_1.optional)((0, json_type_validation_1.dict)(utils_1.styleSetDefinitionDecoder)),
styleSetDefinitions: (0, json_type_validation_1.withDefault)({}, (0, json_type_validation_1.dict)(utils_1.styleSetDefinitionDecoder)),
outputOptions: (0, json_type_validation_1.optional)(utils_1.outputOptionsDecoder),

@@ -33,0 +33,0 @@ seo: (0, json_type_validation_1.optional)(utils_1.componentSeoDecoder),

@@ -1,9 +0,6 @@

export declare class CustomCombinators<A> {
private decode;
private constructor();
static isValidComponentName(): CustomCombinators<string>;
static isValidNavLink(): CustomCombinators<string>;
static isValidFileName(): CustomCombinators<string>;
static isValidElementName(): CustomCombinators<string>;
}
import { Decoder } from '@mojotech/json-type-validation';
export declare const isValidComponentName: (name: string) => Decoder<string>;
export declare const isValidNavLink: (link: string) => Decoder<string>;
export declare const isValidFileName: (name: string) => Decoder<string>;
export declare const isValidElementName: (name: string) => Decoder<string>;
//# sourceMappingURL=custom-combinators.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CustomCombinators = void 0;
/* tslint:disable member-ordering */
exports.isValidElementName = exports.isValidFileName = exports.isValidNavLink = exports.isValidComponentName = void 0;
var json_type_validation_1 = require("@mojotech/json-type-validation");
var CustomCombinators = /** @class */ (function () {
// @ts-ignore
function CustomCombinators(decode) {
this.decode = decode;
/* These are some custom combinators that comes in handy for us,
instead of parsing and cross-checking regex again. The combinators,
can used inside a existing Decoder, since we did not implement any run()
runWithException() etc */
var isValidComponentName = function (name) {
var componentNameRegex = new RegExp('^[A-Z]+[a-zA-Z0-9]*$');
if (name && typeof name === 'string' && componentNameRegex.test(name)) {
return (0, json_type_validation_1.succeed)(name);
}
CustomCombinators.isValidComponentName = function () {
return new CustomCombinators(function (json) {
var componentNameRegex = new RegExp('^[A-Z]+[a-zA-Z0-9]*$');
if (json && typeof json === 'string' && componentNameRegex.test(json)) {
return json_type_validation_1.Result.ok(json);
}
else if (json.length === 0) {
throw new Error("Component Name cannot be empty");
}
throw new Error("Invalid Component name, got ".concat(json));
});
};
CustomCombinators.isValidNavLink = function () {
return new CustomCombinators(function (link) {
if (!link || typeof link !== 'string') {
throw new Error("Invalid navLink attribute, received ".concat(link));
}
if (link === '**') {
return json_type_validation_1.Result.ok(link);
}
var navLinkRegex = new RegExp('/[a-zA-Z0-9-_]*$');
if (navLinkRegex.test(link)) {
return json_type_validation_1.Result.ok(link);
}
throw new Error("Invalid navLink attribute, received ".concat(link));
});
};
CustomCombinators.isValidFileName = function () {
return new CustomCombinators(function (json) {
var fileNameRegex = new RegExp('^[a-zA-Z0-9-_.]*$');
if (json && typeof json === 'string' && fileNameRegex.test(json)) {
return json_type_validation_1.Result.ok(json);
}
else if (json.length === 0) {
throw new Error("File Name cannot be empty");
}
throw new Error("Invalid File name, received ".concat(json));
});
};
CustomCombinators.isValidElementName = function () {
return new CustomCombinators(function (json) {
var fileNameRegex = new RegExp('^[a-zA-Z]+[a-zA-Z0-9-_]*$');
if (json && typeof json === 'string' && fileNameRegex.test(json)) {
return json_type_validation_1.Result.ok(json);
}
else if (json.length === 0) {
throw new Error("Name attribute cannot be empty");
}
throw new Error("Invalid name attribute, received ".concat(json));
});
};
return CustomCombinators;
}());
exports.CustomCombinators = CustomCombinators;
return (0, json_type_validation_1.fail)("Invalid Component name, got ".concat(name));
};
exports.isValidComponentName = isValidComponentName;
var isValidNavLink = function (link) {
if (!link || typeof link !== 'string') {
throw new Error("Invalid navLink attribute, received ".concat(link));
}
if (link === '**') {
return (0, json_type_validation_1.succeed)(link);
}
var navLinkRegex = new RegExp('/(?:[a-zA-Z0-9-_]+|/[[a-zA-Z]+]|[/[a-zA-Z]+])*');
if (navLinkRegex.test(link)) {
return (0, json_type_validation_1.succeed)(link);
}
return (0, json_type_validation_1.fail)("Invalid navLink attribute, received ".concat(link));
};
exports.isValidNavLink = isValidNavLink;
var isValidFileName = function (name) {
var fileNameRegex = new RegExp('^[[a-zA-Z0-9-_.]+]*$');
if (name && typeof name === 'string' && fileNameRegex.test(name)) {
return (0, json_type_validation_1.succeed)(name);
}
return (0, json_type_validation_1.fail)("Invalid File name, received ".concat(name));
};
exports.isValidFileName = isValidFileName;
var isValidElementName = function (name) {
var elementNameRefex = new RegExp('^[a-zA-Z]+[a-zA-Z0-9-_]*$');
if (name && typeof name === 'string' && elementNameRefex.test(name)) {
return (0, json_type_validation_1.succeed)(name);
}
return (0, json_type_validation_1.fail)("Invalid name attribute, received ".concat(name));
};
exports.isValidElementName = isValidElementName;
//# sourceMappingURL=custom-combinators.js.map
import { Decoder } from '@mojotech/json-type-validation';
import { UIDLStaticValue, ReferenceType, UIDLDynamicReference, UIDLPropDefinition, UIDLStateDefinition, UIDLPageOptions, UIDLComponentOutputOptions, UIDLDependency, UIDLStyleDefinitions, UIDLStyleValue, UIDLAttributeValue, UIDLEventHandlerStatement, UIDLMailLinkNode, UIDLPhoneLinkNode, UIDLRawValue, UIDLElementStyleStates, UIDLStyleStateCondition, UIDLStyleMediaQueryScreenSizeCondition, UIDLStyleConditions, UIDLElementNodeProjectReferencedStyle, VUIDLComponentSEO, VUIDLGlobalAsset, UIDLExternalDependency, UIDLLocalDependency, UIDLPeerDependency, UIDLImportReference, UIDLStyleSetTokenReference, VUIDLStyleSetDefnition, VUIDLElement, VUIDLSlotNode, VUIDLConditionalNode, VUIDLRepeatNode, VUIDLElementNode, VUIDLNode, VUIDLElementNodeInlineReferencedStyle, VUIDLSectionLinkNode, VUIDLLinkNode, VUIDLURLLinkNode, VUIDLStyleSetConditions, VUIDLStyleSetMediaCondition, VUIDLStyleSetStateCondition, VUIDLDesignTokens, UIDLPropCallEvent, UIDLStateModifierEvent, UIDLScriptExternalAsset, UIDLScriptInlineAsset, VUIDLStyleInlineAsset, UIDLStyleExternalAsset, VUIDLFontAsset, UIDLCanonicalAsset, UIDLIconAsset, UIDLAssetBase, VUIDLElementNodeClassReferencedStyle, UIDLCompDynamicReference, UIDLComponentStyleReference, PagePaginationOptions, VCMSItemUIDLElementNode, VCMSListUIDLElementNode, UIDLInitialPathsData, UIDLInitialPropsData, UIDLExpressionValue, UIDLDynamicLinkNode, UIDLENVValue, UIDLPropValue, UIDLResourceItem, VUIDLNavLinkNode, VUIDLDateTimeNode, UIDLStateValue, UIDLResourceLink, UIDLLocalResource, UIDLExternalResource, VCMSListRepeaterElementNode, UIDLResourceMapper, UIDLInjectValue, VUIDLStateValueDetails } from '@teleporthq/teleport-types';
import { UIDLStaticValue, ReferenceType, UIDLDynamicReference, UIDLStateDefinition, UIDLPageOptions, UIDLComponentOutputOptions, UIDLDependency, UIDLStyleDefinitions, UIDLStyleValue, VUIDLAttributeValue, UIDLEventHandlerStatement, UIDLMailLinkNode, UIDLPhoneLinkNode, UIDLRawValue, UIDLElementStyleStates, UIDLStyleStateCondition, UIDLStyleMediaQueryScreenSizeCondition, UIDLStyleConditions, UIDLElementNodeProjectReferencedStyle, VUIDLComponentSEO, VUIDLGlobalAsset, UIDLExternalDependency, UIDLLocalDependency, UIDLPeerDependency, UIDLImportReference, UIDLStyleSetTokenReference, VUIDLStyleSetDefnition, VUIDLElement, VUIDLSlotNode, VUIDLConditionalNode, VUIDLRepeatNode, VUIDLElementNode, VUIDLNode, VUIDLElementNodeInlineReferencedStyle, VUIDLSectionLinkNode, VUIDLLinkNode, VUIDLURLLinkNode, VUIDLStyleSetConditions, VUIDLStyleSetMediaCondition, VUIDLStyleSetStateCondition, VUIDLDesignTokens, UIDLPropCallEvent, UIDLStateModifierEvent, UIDLScriptExternalAsset, UIDLScriptInlineAsset, VUIDLStyleInlineAsset, UIDLStyleExternalAsset, VUIDLFontAsset, UIDLCanonicalAsset, UIDLIconAsset, UIDLAssetBase, VUIDLElementNodeClassReferencedStyle, UIDLCompDynamicReference, UIDLComponentStyleReference, PagePaginationOptions, VCMSItemUIDLElementNode, VCMSListUIDLElementNode, UIDLInitialPathsData, UIDLInitialPropsData, UIDLExpressionValue, UIDLDynamicLinkNode, UIDLENVValue, UIDLPropValue, UIDLResourceItem, VUIDLNavLinkNode, VUIDLDateTimeNode, UIDLStateValue, UIDLResourceLink, UIDLLocalResource, UIDLExternalResource, VCMSListRepeaterElementNode, UIDLResourceMapper, UIDLInjectValue, VUIDLStateValueDetails, VUIDLCMSMixedTypeNode, UIDLLocalFontAsset, VUIDLPropDefinitions } from '@teleporthq/teleport-types';
export declare const referenceTypeDecoder: Decoder<ReferenceType>;

@@ -12,5 +12,2 @@ export declare const dynamicValueDecoder: Decoder<UIDLDynamicReference>;

export declare const resourceItemDecoder: Decoder<UIDLResourceItem>;
export declare const uidlLocalResourcerDecpder: Decoder<UIDLLocalResource>;
export declare const uidlExternalResourceDecoder: Decoder<UIDLExternalResource>;
export declare const uidlResourceLinkDecoder: Decoder<UIDLResourceLink>;
export declare const initialPropsDecoder: Decoder<UIDLInitialPropsData>;

@@ -24,3 +21,3 @@ export declare const initialPathsDecoder: Decoder<UIDLInitialPathsData>;

export declare const styleSetDefinitionDecoder: Decoder<VUIDLStyleSetDefnition>;
export declare const stateOrPropDefinitionDecoder: Decoder<string | number | boolean | Record<string, unknown> | (string | number | Record<string, unknown>)[]>;
export declare const stateDefinitionsDefaultValueDecoder: Decoder<string | number | boolean | Record<string, unknown> | (string | number | Record<string, unknown>)[]>;
export declare const globalAssetsDecoder: Decoder<VUIDLGlobalAsset>;

@@ -33,2 +30,3 @@ export declare const baseAssetDecoder: Decoder<UIDLAssetBase>;

export declare const fontAssetDecoder: Decoder<VUIDLFontAsset>;
export declare const localFontDecoder: Decoder<UIDLLocalFontAsset>;
export declare const canonicalAssetDecoder: Decoder<UIDLCanonicalAsset>;

@@ -38,3 +36,3 @@ export declare const iconAssetDecoder: Decoder<UIDLIconAsset>;

export declare const stateValueDetailsDecoder: Decoder<VUIDLStateValueDetails>;
export declare const propDefinitionsDecoder: Decoder<UIDLPropDefinition>;
export declare const propDefinitionsDecoder: Decoder<VUIDLPropDefinitions>;
export declare const pageOptionsPaginationDecoder: Decoder<PagePaginationOptions>;

@@ -50,3 +48,3 @@ export declare const stateDefinitionsDecoder: Decoder<UIDLStateDefinition>;

export declare const importReferenceDecoder: Decoder<UIDLImportReference>;
export declare const attributeValueDecoder: Decoder<UIDLAttributeValue>;
export declare const attributeValueDecoder: Decoder<VUIDLAttributeValue>;
export declare const uidlComponentStyleReference: Decoder<UIDLComponentStyleReference>;

@@ -80,6 +78,10 @@ export declare const styleValueDecoder: Decoder<UIDLStyleValue>;

export declare const dateTimeNodeDecoder: Decoder<VUIDLDateTimeNode>;
export declare const uidlLocalResourcerDecpder: Decoder<UIDLLocalResource>;
export declare const uidlExternalResourceDecoder: Decoder<UIDLExternalResource>;
export declare const uidlResourceLinkDecoder: Decoder<UIDLResourceLink>;
export declare const cmsItemNodeDecoder: Decoder<VCMSItemUIDLElementNode>;
export declare const cmsListNodeDecoder: Decoder<VCMSListUIDLElementNode>;
export declare const cmsListRepeaterNodeDecoder: Decoder<VCMSListRepeaterElementNode>;
export declare const cmsListNodeDecoder: Decoder<VCMSListUIDLElementNode>;
export declare const cmsMixedTypeNodeDecoder: Decoder<VUIDLCMSMixedTypeNode>;
export declare const uidlNodeDecoder: Decoder<VUIDLNode>;
//# sourceMappingURL=utils.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.stateChangeEventDecoder = exports.propCallEventDecoder = exports.eventHandlerStatementDecoder = exports.styleDefinitionsDecoder = exports.styleValueDecoder = exports.uidlComponentStyleReference = exports.attributeValueDecoder = exports.importReferenceDecoder = exports.resourceMapperDecoder = exports.dependencyDecoder = exports.localDependencyDecoder = exports.externaldependencyDecoder = exports.peerDependencyDecoder = exports.outputOptionsDecoder = exports.pageOptionsDecoder = exports.stateDefinitionsDecoder = exports.pageOptionsPaginationDecoder = exports.propDefinitionsDecoder = exports.stateValueDetailsDecoder = exports.componentSeoDecoder = exports.iconAssetDecoder = exports.canonicalAssetDecoder = exports.fontAssetDecoder = exports.externalStyleAssetDecoder = exports.inlineStyletAssetDecoder = exports.externalScriptAssetDecoder = exports.inlineScriptAssetDecoder = exports.baseAssetDecoder = exports.globalAssetsDecoder = exports.stateOrPropDefinitionDecoder = exports.styleSetDefinitionDecoder = exports.tokenReferenceDecoder = exports.projectStyleConditionsDecoder = exports.styleSetStateConditionDecoder = exports.styleSetMediaConditionDecoder = exports.injectValueDecoder = exports.initialPathsDecoder = exports.initialPropsDecoder = exports.uidlResourceLinkDecoder = exports.uidlExternalResourceDecoder = exports.uidlLocalResourcerDecpder = exports.resourceItemDecoder = exports.dyamicFunctionStateParam = exports.dyamicFunctionParam = exports.envValueDecoder = exports.rawValueDecoder = exports.staticValueDecoder = exports.expressionValueDecoder = exports.dynamicValueDecoder = exports.referenceTypeDecoder = void 0;
exports.uidlNodeDecoder = exports.cmsListNodeDecoder = exports.cmsListRepeaterNodeDecoder = exports.cmsItemNodeDecoder = exports.dateTimeNodeDecoder = exports.elementNodeDecoder = exports.conditionalNodeDecoder = exports.repeatNodeDecoder = exports.slotNodeDecoder = exports.elementDecoder = exports.designTokensDecoder = exports.elementComponentReferencedStyle = exports.classDynamicReferenceDecoder = exports.elementInlineReferencedStyle = exports.elementProjectReferencedStyle = exports.styleConditionsDecoder = exports.elementStyleWithMediaConditionDecoder = exports.elementStyleWithStateConditionDecoder = exports.elementStateDecoder = exports.uidlLinkNodeDecoder = exports.phoneLinkNodeDecoder = exports.uidlMailLinkNodeDecoder = exports.navLinkNodeDecoder = exports.sectionLinkNodeDecoder = exports.dynamicLinkDecoder = exports.urlLinkNodeDecoder = void 0;
exports.dynamicLinkDecoder = exports.urlLinkNodeDecoder = exports.stateChangeEventDecoder = exports.propCallEventDecoder = exports.eventHandlerStatementDecoder = exports.styleDefinitionsDecoder = exports.styleValueDecoder = exports.uidlComponentStyleReference = exports.attributeValueDecoder = exports.importReferenceDecoder = exports.resourceMapperDecoder = exports.dependencyDecoder = exports.localDependencyDecoder = exports.externaldependencyDecoder = exports.peerDependencyDecoder = exports.outputOptionsDecoder = exports.pageOptionsDecoder = exports.stateDefinitionsDecoder = exports.pageOptionsPaginationDecoder = exports.propDefinitionsDecoder = exports.stateValueDetailsDecoder = exports.componentSeoDecoder = exports.iconAssetDecoder = exports.canonicalAssetDecoder = exports.localFontDecoder = exports.fontAssetDecoder = exports.externalStyleAssetDecoder = exports.inlineStyletAssetDecoder = exports.externalScriptAssetDecoder = exports.inlineScriptAssetDecoder = exports.baseAssetDecoder = exports.globalAssetsDecoder = exports.stateDefinitionsDefaultValueDecoder = exports.styleSetDefinitionDecoder = exports.tokenReferenceDecoder = exports.projectStyleConditionsDecoder = exports.styleSetStateConditionDecoder = exports.styleSetMediaConditionDecoder = exports.injectValueDecoder = exports.initialPathsDecoder = exports.initialPropsDecoder = exports.resourceItemDecoder = exports.dyamicFunctionStateParam = exports.dyamicFunctionParam = exports.envValueDecoder = exports.rawValueDecoder = exports.staticValueDecoder = exports.expressionValueDecoder = exports.dynamicValueDecoder = exports.referenceTypeDecoder = void 0;
exports.uidlNodeDecoder = exports.cmsMixedTypeNodeDecoder = exports.cmsListRepeaterNodeDecoder = exports.cmsListNodeDecoder = exports.cmsItemNodeDecoder = exports.uidlResourceLinkDecoder = exports.uidlExternalResourceDecoder = exports.uidlLocalResourcerDecpder = exports.dateTimeNodeDecoder = exports.elementNodeDecoder = exports.conditionalNodeDecoder = exports.repeatNodeDecoder = exports.slotNodeDecoder = exports.elementDecoder = exports.designTokensDecoder = exports.elementComponentReferencedStyle = exports.classDynamicReferenceDecoder = exports.elementInlineReferencedStyle = exports.elementProjectReferencedStyle = exports.styleConditionsDecoder = exports.elementStyleWithMediaConditionDecoder = exports.elementStyleWithStateConditionDecoder = exports.elementStateDecoder = exports.uidlLinkNodeDecoder = exports.phoneLinkNodeDecoder = exports.uidlMailLinkNodeDecoder = exports.navLinkNodeDecoder = exports.sectionLinkNodeDecoder = void 0;
var json_type_validation_1 = require("@mojotech/json-type-validation");
var custom_combinators_1 = require("./custom-combinators");
var isValidComponentName = custom_combinators_1.CustomCombinators.isValidComponentName, isValidFileName = custom_combinators_1.CustomCombinators.isValidFileName, isValidElementName = custom_combinators_1.CustomCombinators.isValidElementName, isValidNavLink = custom_combinators_1.CustomCombinators.isValidNavLink;
exports.referenceTypeDecoder = (0, json_type_validation_1.union)((0, json_type_validation_1.constant)('prop'), (0, json_type_validation_1.constant)('state'), (0, json_type_validation_1.constant)('local'), (0, json_type_validation_1.constant)('attr'), (0, json_type_validation_1.constant)('children'), (0, json_type_validation_1.constant)('token'), (0, json_type_validation_1.constant)('expr'));

@@ -13,3 +12,3 @@ exports.dynamicValueDecoder = (0, json_type_validation_1.object)({

referenceType: exports.referenceTypeDecoder,
path: (0, json_type_validation_1.optional)((0, json_type_validation_1.array)((0, json_type_validation_1.string)())),
refPath: (0, json_type_validation_1.optional)((0, json_type_validation_1.array)((0, json_type_validation_1.string)())),
id: (0, json_type_validation_1.string)(),

@@ -56,5 +55,5 @@ }),

method: (0, json_type_validation_1.withDefault)('GET', (0, json_type_validation_1.union)((0, json_type_validation_1.constant)('GET'), (0, json_type_validation_1.constant)('POST'))),
body: (0, json_type_validation_1.optional)((0, json_type_validation_1.dict)(exports.staticValueDecoder)),
body: (0, json_type_validation_1.optional)((0, json_type_validation_1.dict)((0, json_type_validation_1.union)(exports.staticValueDecoder, exports.expressionValueDecoder))),
mappers: (0, json_type_validation_1.withDefault)([], (0, json_type_validation_1.array)((0, json_type_validation_1.string)())),
params: (0, json_type_validation_1.optional)((0, json_type_validation_1.dict)((0, json_type_validation_1.union)(exports.staticValueDecoder, exports.dyamicFunctionParam, exports.dyamicFunctionStateParam))),
params: (0, json_type_validation_1.optional)((0, json_type_validation_1.dict)((0, json_type_validation_1.union)(exports.staticValueDecoder, exports.dyamicFunctionParam, exports.dyamicFunctionStateParam, exports.expressionValueDecoder))),
response: (0, json_type_validation_1.optional)((0, json_type_validation_1.object)({

@@ -64,19 +63,15 @@ type: (0, json_type_validation_1.withDefault)('json', (0, json_type_validation_1.union)((0, json_type_validation_1.constant)('json'), (0, json_type_validation_1.constant)('headers'), (0, json_type_validation_1.constant)('text'), (0, json_type_validation_1.constant)('none'))),

});
exports.uidlLocalResourcerDecpder = (0, json_type_validation_1.object)({
id: (0, json_type_validation_1.string)(),
params: (0, json_type_validation_1.optional)((0, json_type_validation_1.dict)((0, json_type_validation_1.union)(exports.staticValueDecoder, exports.dyamicFunctionParam, exports.expressionValueDecoder))),
});
exports.uidlExternalResourceDecoder = (0, json_type_validation_1.object)({
name: (0, json_type_validation_1.string)(),
dependency: (0, json_type_validation_1.lazy)(function () { return exports.externaldependencyDecoder; }),
params: (0, json_type_validation_1.optional)((0, json_type_validation_1.dict)((0, json_type_validation_1.union)(exports.staticValueDecoder, exports.dyamicFunctionParam, exports.expressionValueDecoder))),
});
exports.uidlResourceLinkDecoder = (0, json_type_validation_1.union)(exports.uidlLocalResourcerDecpder, exports.uidlExternalResourceDecoder);
exports.initialPropsDecoder = (0, json_type_validation_1.object)({
exposeAs: (0, json_type_validation_1.object)({
name: (0, json_type_validation_1.string)(),
valuePath: (0, json_type_validation_1.optional)((0, json_type_validation_1.array)((0, json_type_validation_1.string)())),
itemValuePath: (0, json_type_validation_1.optional)((0, json_type_validation_1.array)((0, json_type_validation_1.string)())),
valuePath: (0, json_type_validation_1.withDefault)([], (0, json_type_validation_1.array)((0, json_type_validation_1.string)())),
}),
resource: exports.uidlResourceLinkDecoder,
resource: (0, json_type_validation_1.union)((0, json_type_validation_1.object)({
id: (0, json_type_validation_1.string)(),
params: (0, json_type_validation_1.optional)((0, json_type_validation_1.dict)((0, json_type_validation_1.union)(exports.staticValueDecoder, exports.expressionValueDecoder))),
}), (0, json_type_validation_1.object)({
name: (0, json_type_validation_1.string)(),
dependency: (0, json_type_validation_1.lazy)(function () { return exports.externaldependencyDecoder; }),
params: (0, json_type_validation_1.optional)((0, json_type_validation_1.dict)((0, json_type_validation_1.union)(exports.staticValueDecoder, exports.expressionValueDecoder))),
})),
cache: (0, json_type_validation_1.optional)((0, json_type_validation_1.object)({ revalidate: (0, json_type_validation_1.number)() })),

@@ -90,3 +85,10 @@ });

}),
resource: exports.uidlResourceLinkDecoder,
resource: (0, json_type_validation_1.union)((0, json_type_validation_1.object)({
id: (0, json_type_validation_1.string)(),
params: (0, json_type_validation_1.optional)((0, json_type_validation_1.dict)((0, json_type_validation_1.union)(exports.staticValueDecoder, exports.expressionValueDecoder))),
}), (0, json_type_validation_1.object)({
name: (0, json_type_validation_1.string)(),
dependency: (0, json_type_validation_1.lazy)(function () { return exports.externaldependencyDecoder; }),
params: (0, json_type_validation_1.optional)((0, json_type_validation_1.dict)((0, json_type_validation_1.union)(exports.staticValueDecoder, exports.expressionValueDecoder))),
})),
});

@@ -130,5 +132,4 @@ exports.injectValueDecoder = (0, json_type_validation_1.object)({

});
// TODO: Implement decoder for () => void
exports.stateOrPropDefinitionDecoder = (0, json_type_validation_1.union)((0, json_type_validation_1.string)(), (0, json_type_validation_1.number)(), (0, json_type_validation_1.boolean)(), (0, json_type_validation_1.array)((0, json_type_validation_1.union)((0, json_type_validation_1.string)(), (0, json_type_validation_1.number)(), (0, json_type_validation_1.object)())), (0, json_type_validation_1.object)());
exports.globalAssetsDecoder = (0, json_type_validation_1.union)((0, json_type_validation_1.lazy)(function () { return exports.inlineScriptAssetDecoder; }), (0, json_type_validation_1.lazy)(function () { return exports.externalScriptAssetDecoder; }), (0, json_type_validation_1.lazy)(function () { return exports.inlineStyletAssetDecoder; }), (0, json_type_validation_1.lazy)(function () { return exports.externalStyleAssetDecoder; }), (0, json_type_validation_1.lazy)(function () { return exports.fontAssetDecoder; }), (0, json_type_validation_1.lazy)(function () { return exports.canonicalAssetDecoder; }), (0, json_type_validation_1.lazy)(function () { return exports.iconAssetDecoder; }));
exports.stateDefinitionsDefaultValueDecoder = (0, json_type_validation_1.union)((0, json_type_validation_1.string)(), (0, json_type_validation_1.number)(), (0, json_type_validation_1.boolean)(), (0, json_type_validation_1.array)((0, json_type_validation_1.union)((0, json_type_validation_1.string)(), (0, json_type_validation_1.number)(), (0, json_type_validation_1.object)())), (0, json_type_validation_1.object)());
exports.globalAssetsDecoder = (0, json_type_validation_1.union)((0, json_type_validation_1.lazy)(function () { return exports.inlineScriptAssetDecoder; }), (0, json_type_validation_1.lazy)(function () { return exports.externalScriptAssetDecoder; }), (0, json_type_validation_1.lazy)(function () { return exports.inlineStyletAssetDecoder; }), (0, json_type_validation_1.lazy)(function () { return exports.externalStyleAssetDecoder; }), (0, json_type_validation_1.lazy)(function () { return exports.fontAssetDecoder; }), (0, json_type_validation_1.lazy)(function () { return exports.canonicalAssetDecoder; }), (0, json_type_validation_1.lazy)(function () { return exports.iconAssetDecoder; }), (0, json_type_validation_1.lazy)(function () { return exports.localFontDecoder; }));
exports.baseAssetDecoder = (0, json_type_validation_1.object)({

@@ -163,2 +164,7 @@ options: (0, json_type_validation_1.optional)((0, json_type_validation_1.object)({

});
exports.localFontDecoder = (0, json_type_validation_1.object)({
type: (0, json_type_validation_1.constant)('local-font'),
path: (0, json_type_validation_1.string)(),
properties: (0, json_type_validation_1.dict)(exports.staticValueDecoder),
});
exports.canonicalAssetDecoder = (0, json_type_validation_1.object)({

@@ -187,4 +193,4 @@ type: (0, json_type_validation_1.constant)('canonical'),

exports.propDefinitionsDecoder = (0, json_type_validation_1.object)({
type: (0, json_type_validation_1.union)((0, json_type_validation_1.constant)('string'), (0, json_type_validation_1.constant)('boolean'), (0, json_type_validation_1.constant)('number'), (0, json_type_validation_1.constant)('array'), (0, json_type_validation_1.constant)('func'), (0, json_type_validation_1.constant)('object'), (0, json_type_validation_1.constant)('children')),
defaultValue: (0, json_type_validation_1.optional)(exports.stateOrPropDefinitionDecoder),
type: (0, json_type_validation_1.union)((0, json_type_validation_1.constant)('string'), (0, json_type_validation_1.constant)('boolean'), (0, json_type_validation_1.constant)('number'), (0, json_type_validation_1.constant)('array'), (0, json_type_validation_1.constant)('func'), (0, json_type_validation_1.constant)('object'), (0, json_type_validation_1.constant)('children'), (0, json_type_validation_1.constant)('element')),
defaultValue: (0, json_type_validation_1.optional)((0, json_type_validation_1.union)(exports.stateDefinitionsDefaultValueDecoder, (0, json_type_validation_1.lazy)(function () { return exports.elementNodeDecoder; }))),
isRequired: (0, json_type_validation_1.optional)((0, json_type_validation_1.boolean)()),

@@ -203,11 +209,9 @@ id: (0, json_type_validation_1.optional)((0, json_type_validation_1.string)()),

type: (0, json_type_validation_1.union)((0, json_type_validation_1.constant)('string'), (0, json_type_validation_1.constant)('boolean'), (0, json_type_validation_1.constant)('number'), (0, json_type_validation_1.constant)('array'), (0, json_type_validation_1.constant)('func'), (0, json_type_validation_1.constant)('object'), (0, json_type_validation_1.constant)('children')),
defaultValue: exports.stateOrPropDefinitionDecoder,
defaultValue: exports.stateDefinitionsDefaultValueDecoder,
});
exports.pageOptionsDecoder = (0, json_type_validation_1.object)({
componentName: (0, json_type_validation_1.optional)(isValidComponentName()),
navLink: (0, json_type_validation_1.optional)(isValidNavLink()),
fileName: (0, json_type_validation_1.optional)(isValidFileName()),
componentName: (0, json_type_validation_1.optional)((0, json_type_validation_1.string)().andThen(custom_combinators_1.isValidComponentName)),
navLink: (0, json_type_validation_1.optional)((0, json_type_validation_1.string)().andThen(custom_combinators_1.isValidNavLink)),
fileName: (0, json_type_validation_1.optional)((0, json_type_validation_1.string)().andThen(custom_combinators_1.isValidFileName)),
fallback: (0, json_type_validation_1.optional)((0, json_type_validation_1.boolean)()),
dynamicRouteAttribute: (0, json_type_validation_1.optional)((0, json_type_validation_1.string)()),
isIndex: (0, json_type_validation_1.optional)((0, json_type_validation_1.boolean)()),
pagination: (0, json_type_validation_1.optional)(exports.pageOptionsPaginationDecoder),

@@ -220,8 +224,8 @@ initialPropsData: (0, json_type_validation_1.optional)(exports.initialPropsDecoder),

exports.outputOptionsDecoder = (0, json_type_validation_1.object)({
componentClassName: (0, json_type_validation_1.optional)(isValidComponentName()),
fileName: (0, json_type_validation_1.optional)(isValidFileName()),
styleFileName: (0, json_type_validation_1.optional)(isValidFileName()),
templateFileName: (0, json_type_validation_1.optional)(isValidFileName()),
moduleName: (0, json_type_validation_1.optional)(isValidFileName()),
folderPath: (0, json_type_validation_1.optional)((0, json_type_validation_1.array)(isValidFileName())),
componentClassName: (0, json_type_validation_1.optional)((0, json_type_validation_1.string)().andThen(custom_combinators_1.isValidComponentName)),
fileName: (0, json_type_validation_1.optional)((0, json_type_validation_1.string)().andThen(custom_combinators_1.isValidFileName)),
styleFileName: (0, json_type_validation_1.optional)((0, json_type_validation_1.string)().andThen(custom_combinators_1.isValidFileName)),
templateFileName: (0, json_type_validation_1.optional)((0, json_type_validation_1.string)().andThen(custom_combinators_1.isValidFileName)),
moduleName: (0, json_type_validation_1.optional)((0, json_type_validation_1.string)().andThen(custom_combinators_1.isValidFileName)),
folderPath: (0, json_type_validation_1.optional)((0, json_type_validation_1.array)((0, json_type_validation_1.string)().andThen(custom_combinators_1.isValidFileName))),
});

@@ -267,3 +271,3 @@ exports.peerDependencyDecoder = (0, json_type_validation_1.object)({

});
exports.attributeValueDecoder = (0, json_type_validation_1.union)(exports.dynamicValueDecoder, exports.staticValueDecoder, (0, json_type_validation_1.lazy)(function () { return exports.expressionValueDecoder; }), exports.importReferenceDecoder, exports.rawValueDecoder, (0, json_type_validation_1.lazy)(function () { return exports.uidlComponentStyleReference; }));
exports.attributeValueDecoder = (0, json_type_validation_1.union)(exports.dynamicValueDecoder, exports.staticValueDecoder, (0, json_type_validation_1.lazy)(function () { return exports.expressionValueDecoder; }), exports.importReferenceDecoder, exports.rawValueDecoder, (0, json_type_validation_1.lazy)(function () { return exports.uidlComponentStyleReference; }), (0, json_type_validation_1.lazy)(function () { return exports.elementNodeDecoder; }));
exports.uidlComponentStyleReference = (0, json_type_validation_1.object)({

@@ -289,3 +293,3 @@ type: (0, json_type_validation_1.constant)('comp-style'),

content: (0, json_type_validation_1.object)({
url: (0, json_type_validation_1.union)(exports.attributeValueDecoder, (0, json_type_validation_1.string)()),
url: (0, json_type_validation_1.union)(exports.expressionValueDecoder, exports.dynamicValueDecoder, exports.staticValueDecoder, exports.importReferenceDecoder, exports.uidlComponentStyleReference, exports.rawValueDecoder, (0, json_type_validation_1.string)()),
newTab: (0, json_type_validation_1.withDefault)(false, (0, json_type_validation_1.boolean)()),

@@ -304,3 +308,5 @@ }),

type: (0, json_type_validation_1.constant)('section'),
content: (0, json_type_validation_1.dict)((0, json_type_validation_1.string)()),
content: (0, json_type_validation_1.object)({
section: (0, json_type_validation_1.union)((0, json_type_validation_1.string)(), exports.staticValueDecoder, exports.expressionValueDecoder),
}),
});

@@ -310,3 +316,3 @@ exports.navLinkNodeDecoder = (0, json_type_validation_1.object)({

content: (0, json_type_validation_1.object)({
routeName: (0, json_type_validation_1.union)(exports.attributeValueDecoder, (0, json_type_validation_1.string)()),
routeName: (0, json_type_validation_1.union)(exports.expressionValueDecoder, exports.dynamicValueDecoder, exports.staticValueDecoder, exports.importReferenceDecoder, exports.uidlComponentStyleReference, exports.rawValueDecoder, (0, json_type_validation_1.string)()),
}),

@@ -355,3 +361,3 @@ });

conditions: (0, json_type_validation_1.array)(exports.styleConditionsDecoder),
styles: (0, json_type_validation_1.optional)((0, json_type_validation_1.dict)((0, json_type_validation_1.union)(exports.attributeValueDecoder, (0, json_type_validation_1.string)(), (0, json_type_validation_1.number)()))),
styles: (0, json_type_validation_1.optional)((0, json_type_validation_1.dict)((0, json_type_validation_1.union)(exports.styleValueDecoder, (0, json_type_validation_1.string)(), (0, json_type_validation_1.number)()))),
}),

@@ -377,15 +383,14 @@ });

semanticType: (0, json_type_validation_1.optional)((0, json_type_validation_1.string)()),
name: (0, json_type_validation_1.optional)(isValidElementName()),
name: (0, json_type_validation_1.optional)((0, json_type_validation_1.string)().andThen(custom_combinators_1.isValidElementName)),
key: (0, json_type_validation_1.optional)((0, json_type_validation_1.string)()),
dependency: (0, json_type_validation_1.optional)(exports.dependencyDecoder),
style: (0, json_type_validation_1.optional)((0, json_type_validation_1.dict)((0, json_type_validation_1.union)(exports.attributeValueDecoder, (0, json_type_validation_1.string)(), (0, json_type_validation_1.number)()))),
style: (0, json_type_validation_1.optional)((0, json_type_validation_1.dict)((0, json_type_validation_1.union)(exports.styleValueDecoder, (0, json_type_validation_1.string)(), (0, json_type_validation_1.number)()))),
attrs: (0, json_type_validation_1.optional)((0, json_type_validation_1.dict)((0, json_type_validation_1.union)(exports.attributeValueDecoder, (0, json_type_validation_1.string)(), (0, json_type_validation_1.number)()))),
events: (0, json_type_validation_1.optional)((0, json_type_validation_1.dict)((0, json_type_validation_1.array)(exports.eventHandlerStatementDecoder))),
events: (0, json_type_validation_1.withDefault)({}, (0, json_type_validation_1.dict)((0, json_type_validation_1.array)(exports.eventHandlerStatementDecoder))),
abilities: (0, json_type_validation_1.optional)((0, json_type_validation_1.object)({
link: (0, json_type_validation_1.optional)((0, json_type_validation_1.anyJson)()),
})),
children: (0, json_type_validation_1.optional)((0, json_type_validation_1.array)((0, json_type_validation_1.lazy)(function () { return exports.uidlNodeDecoder; }))),
children: (0, json_type_validation_1.withDefault)([], (0, json_type_validation_1.array)((0, json_type_validation_1.lazy)(function () { return exports.uidlNodeDecoder; }))),
referencedStyles: (0, json_type_validation_1.optional)((0, json_type_validation_1.dict)((0, json_type_validation_1.union)(exports.elementInlineReferencedStyle, exports.elementProjectReferencedStyle, exports.elementComponentReferencedStyle))),
selfClosing: (0, json_type_validation_1.optional)((0, json_type_validation_1.boolean)()),
ignore: (0, json_type_validation_1.optional)((0, json_type_validation_1.boolean)()),
});

@@ -403,3 +408,3 @@ exports.slotNodeDecoder = (0, json_type_validation_1.object)({

node: (0, json_type_validation_1.lazy)(function () { return exports.elementNodeDecoder; }),
dataSource: (0, json_type_validation_1.optional)(exports.attributeValueDecoder),
dataSource: (0, json_type_validation_1.optional)((0, json_type_validation_1.union)(exports.expressionValueDecoder, exports.dynamicValueDecoder, exports.staticValueDecoder, exports.importReferenceDecoder, exports.uidlComponentStyleReference, exports.rawValueDecoder)),
meta: (0, json_type_validation_1.optional)((0, json_type_validation_1.object)({

@@ -417,3 +422,3 @@ useIndex: (0, json_type_validation_1.optional)((0, json_type_validation_1.boolean)()),

node: (0, json_type_validation_1.lazy)(function () { return exports.uidlNodeDecoder; }),
reference: exports.dynamicValueDecoder,
reference: (0, json_type_validation_1.union)(exports.dynamicValueDecoder, exports.expressionValueDecoder),
importDefinitions: (0, json_type_validation_1.optional)((0, json_type_validation_1.dict)(exports.externaldependencyDecoder)),

@@ -435,2 +440,12 @@ value: (0, json_type_validation_1.union)((0, json_type_validation_1.string)(), (0, json_type_validation_1.number)(), (0, json_type_validation_1.boolean)()),

});
exports.uidlLocalResourcerDecpder = (0, json_type_validation_1.object)({
id: (0, json_type_validation_1.string)(),
params: (0, json_type_validation_1.optional)((0, json_type_validation_1.dict)((0, json_type_validation_1.union)(exports.staticValueDecoder, exports.dyamicFunctionParam, exports.expressionValueDecoder, (0, json_type_validation_1.lazy)(function () { return exports.dyamicFunctionStateParam; })))),
});
exports.uidlExternalResourceDecoder = (0, json_type_validation_1.object)({
name: (0, json_type_validation_1.string)(),
dependency: (0, json_type_validation_1.lazy)(function () { return exports.externaldependencyDecoder; }),
params: (0, json_type_validation_1.optional)((0, json_type_validation_1.dict)((0, json_type_validation_1.union)(exports.staticValueDecoder, exports.dyamicFunctionParam, exports.expressionValueDecoder, (0, json_type_validation_1.lazy)(function () { return exports.dyamicFunctionStateParam; })))),
});
exports.uidlResourceLinkDecoder = (0, json_type_validation_1.union)(exports.uidlLocalResourcerDecpder, exports.uidlExternalResourceDecoder);
exports.cmsItemNodeDecoder = (0, json_type_validation_1.object)({

@@ -450,8 +465,30 @@ type: (0, json_type_validation_1.constant)('cms-item'),

renderPropIdentifier: (0, json_type_validation_1.string)(),
valuePath: (0, json_type_validation_1.optional)((0, json_type_validation_1.array)((0, json_type_validation_1.string)())),
valuePath: (0, json_type_validation_1.withDefault)([], (0, json_type_validation_1.array)((0, json_type_validation_1.string)())),
itemValuePath: (0, json_type_validation_1.optional)((0, json_type_validation_1.array)((0, json_type_validation_1.string)())),
resource: (0, json_type_validation_1.optional)((0, json_type_validation_1.union)(exports.uidlLocalResourcerDecpder, exports.uidlExternalResourceDecoder)),
resource: (0, json_type_validation_1.optional)(exports.uidlResourceLinkDecoder),
initialData: (0, json_type_validation_1.optional)((0, json_type_validation_1.lazy)(function () { return exports.dyamicFunctionParam; })),
entityKeyProperty: (0, json_type_validation_1.optional)((0, json_type_validation_1.string)()),
}),
});
exports.cmsListNodeDecoder = (0, json_type_validation_1.object)({
type: (0, json_type_validation_1.constant)('cms-list'),
content: (0, json_type_validation_1.object)({
elementType: (0, json_type_validation_1.string)(),
name: (0, json_type_validation_1.withDefault)('cms-list', (0, json_type_validation_1.string)()),
attrs: (0, json_type_validation_1.optional)((0, json_type_validation_1.dict)((0, json_type_validation_1.union)(exports.attributeValueDecoder, (0, json_type_validation_1.string)(), (0, json_type_validation_1.number)()))),
nodes: (0, json_type_validation_1.object)({
success: (0, json_type_validation_1.lazy)(function () { return exports.elementNodeDecoder; }),
error: (0, json_type_validation_1.optional)((0, json_type_validation_1.lazy)(function () { return exports.elementNodeDecoder; })),
loading: (0, json_type_validation_1.optional)((0, json_type_validation_1.lazy)(function () { return exports.elementNodeDecoder; })),
empty: (0, json_type_validation_1.optional)((0, json_type_validation_1.lazy)(function () { return exports.elementNodeDecoder; })),
}),
router: (0, json_type_validation_1.optional)((0, json_type_validation_1.lazy)(function () { return exports.dependencyDecoder; })),
dependency: (0, json_type_validation_1.optional)((0, json_type_validation_1.lazy)(function () { return exports.dependencyDecoder; })),
renderPropIdentifier: (0, json_type_validation_1.string)(),
itemValuePath: (0, json_type_validation_1.optional)((0, json_type_validation_1.array)((0, json_type_validation_1.string)())),
valuePath: (0, json_type_validation_1.withDefault)([], (0, json_type_validation_1.array)((0, json_type_validation_1.string)())),
resource: (0, json_type_validation_1.optional)(exports.uidlResourceLinkDecoder),
initialData: (0, json_type_validation_1.optional)((0, json_type_validation_1.lazy)(function () { return exports.dyamicFunctionParam; })),
}),
});
exports.cmsListRepeaterNodeDecoder = (0, json_type_validation_1.object)({

@@ -466,27 +503,23 @@ type: (0, json_type_validation_1.constant)('cms-list-repeater'),

}),
dependency: (0, json_type_validation_1.optional)((0, json_type_validation_1.lazy)(function () { return exports.dependencyDecoder; })),
source: (0, json_type_validation_1.optional)((0, json_type_validation_1.string)()),
renderPropIdentifier: (0, json_type_validation_1.string)(),
}),
});
exports.cmsListNodeDecoder = (0, json_type_validation_1.object)({
type: (0, json_type_validation_1.constant)('cms-list'),
exports.cmsMixedTypeNodeDecoder = (0, json_type_validation_1.object)({
type: (0, json_type_validation_1.constant)('cms-mixed-type'),
content: (0, json_type_validation_1.object)({
elementType: (0, json_type_validation_1.string)(),
name: (0, json_type_validation_1.withDefault)('cms-list', (0, json_type_validation_1.string)()),
attrs: (0, json_type_validation_1.optional)((0, json_type_validation_1.dict)((0, json_type_validation_1.union)(exports.attributeValueDecoder, (0, json_type_validation_1.string)(), (0, json_type_validation_1.number)()))),
name: (0, json_type_validation_1.withDefault)('cms-mixed-type', (0, json_type_validation_1.string)()),
attrs: (0, json_type_validation_1.withDefault)({}, (0, json_type_validation_1.lazy)(function () { return (0, json_type_validation_1.dict)((0, json_type_validation_1.union)(exports.attributeValueDecoder, (0, json_type_validation_1.string)(), (0, json_type_validation_1.number)())); })),
renderPropIdentifier: (0, json_type_validation_1.string)(),
nodes: (0, json_type_validation_1.object)({
success: (0, json_type_validation_1.lazy)(function () { return exports.elementNodeDecoder; }),
fallback: (0, json_type_validation_1.optional)((0, json_type_validation_1.lazy)(function () { return exports.elementNodeDecoder; })),
error: (0, json_type_validation_1.optional)((0, json_type_validation_1.lazy)(function () { return exports.elementNodeDecoder; })),
loading: (0, json_type_validation_1.optional)((0, json_type_validation_1.lazy)(function () { return exports.elementNodeDecoder; })),
empty: (0, json_type_validation_1.optional)((0, json_type_validation_1.lazy)(function () { return exports.elementNodeDecoder; })),
}),
router: (0, json_type_validation_1.optional)((0, json_type_validation_1.lazy)(function () { return exports.dependencyDecoder; })),
dependency: (0, json_type_validation_1.optional)((0, json_type_validation_1.lazy)(function () { return exports.dependencyDecoder; })),
renderPropIdentifier: (0, json_type_validation_1.string)(),
itemValuePath: (0, json_type_validation_1.optional)((0, json_type_validation_1.array)((0, json_type_validation_1.string)())),
valuePath: (0, json_type_validation_1.optional)((0, json_type_validation_1.array)((0, json_type_validation_1.string)())),
resource: (0, json_type_validation_1.optional)((0, json_type_validation_1.union)(exports.uidlLocalResourcerDecpder, exports.uidlExternalResourceDecoder)),
initialData: (0, json_type_validation_1.optional)((0, json_type_validation_1.lazy)(function () { return exports.dyamicFunctionParam; })),
mappings: (0, json_type_validation_1.withDefault)({}, (0, json_type_validation_1.dict)((0, json_type_validation_1.lazy)(function () { return exports.elementNodeDecoder; }))),
}),
});
exports.uidlNodeDecoder = (0, json_type_validation_1.union)(exports.elementNodeDecoder, exports.cmsItemNodeDecoder, exports.cmsListNodeDecoder, exports.cmsListRepeaterNodeDecoder, exports.dynamicValueDecoder, exports.rawValueDecoder, exports.conditionalNodeDecoder, (0, json_type_validation_1.union)(exports.staticValueDecoder, exports.repeatNodeDecoder, exports.slotNodeDecoder, exports.expressionValueDecoder, (0, json_type_validation_1.string)()));
exports.uidlNodeDecoder = (0, json_type_validation_1.union)((0, json_type_validation_1.union)(exports.elementNodeDecoder, exports.dynamicValueDecoder, exports.rawValueDecoder, exports.conditionalNodeDecoder), (0, json_type_validation_1.union)(exports.staticValueDecoder, exports.repeatNodeDecoder, exports.slotNodeDecoder, exports.expressionValueDecoder, (0, json_type_validation_1.string)()), (0, json_type_validation_1.union)(exports.cmsItemNodeDecoder, exports.cmsListNodeDecoder, exports.cmsListRepeaterNodeDecoder, exports.cmsMixedTypeNodeDecoder));
//# sourceMappingURL=utils.js.map

@@ -21,7 +21,10 @@ "use strict";

if (safeInput === null || safeInput === void 0 ? void 0 : safeInput.propDefinitions) {
safeInput.propDefinitions = Object.keys(safeInput.propDefinitions).reduce(function (acc, prop) {
var acc = {};
for (var _i = 0, _a = Object.keys(safeInput.propDefinitions); _i < _a.length; _i++) {
var prop = _a[_i];
var propValue = safeInput.propDefinitions[prop];
var propName = teleport_shared_1.StringUtils.createStateOrPropStoringValue(prop);
acc[propName] = safeInput.propDefinitions[prop];
return acc;
}, {});
acc[propName] = propValue;
}
safeInput.propDefinitions = acc;
}

@@ -48,3 +51,3 @@ if (safeInput === null || safeInput === void 0 ? void 0 : safeInput.stateDefinitions) {

var seo = safeInput.seo;
var _a = (seo || { assets: [] }).assets, assets = _a === void 0 ? [] : _a;
var _b = (seo || { assets: [] }).assets, assets = _b === void 0 ? [] : _b;
assets.forEach(exports.parseAssets);

@@ -54,2 +57,14 @@ }

var result = __assign({}, safeInput);
for (var _c = 0, _d = Object.keys(result.propDefinitions || {}); _c < _d.length; _c++) {
var propKey = _d[_c];
var prop = result.propDefinitions[propKey];
if (prop.type === 'element' &&
prop.defaultValue !== undefined &&
typeof prop.defaultValue !== 'object') {
throw new teleport_types_1.ParserError("The defaultValue for prop ".concat(propKey, " in component ").concat(result.name, " is not an object. It should be a UIDLElementNode."));
}
if (prop.type === 'element' && prop.defaultValue) {
result.propDefinitions[propKey].defaultValue = parseComponentNode(prop.defaultValue, result);
}
}
// other parsers for other sections of the component here

@@ -97,4 +112,4 @@ result.node = parseComponentNode(node, result);

case 'cms-item':
case 'cms-list':
var _c = node.content, initialData = _c.initialData, _d = _c.nodes, success = _d.success, error = _d.error, loading = _d.loading;
case 'cms-list': {
var _c = node.content, initialData = _c.initialData, _d = _c.nodes, success = _d.success, error = _d.error, loading = _d.loading, resource = _c.resource;
if (initialData) {

@@ -119,4 +134,13 @@ initialData.content.id = teleport_shared_1.StringUtils.createStateOrPropStoringValue(initialData.content.id);

}
if (resource === null || resource === void 0 ? void 0 : resource.params) {
Object.values((resource === null || resource === void 0 ? void 0 : resource.params) || {}).forEach(function (param) {
if (param.type === 'dynamic' &&
(param.content.referenceType === 'state' || param.content.referenceType === 'prop')) {
param.content.id = teleport_shared_1.StringUtils.createStateOrPropStoringValue(param.content.id);
}
});
}
return node;
case 'cms-list-repeater':
}
case 'cms-list-repeater': {
var _e = node.content.nodes, list = _e.list, empty = _e.empty;

@@ -132,2 +156,33 @@ if (list) {

return node;
}
case 'cms-mixed-type': {
var _f = node.content, _g = _f.nodes, fallback = _g.fallback, error = _g.error, dependency = _f.dependency, attrs = _f.attrs, mappings_1 = _f.mappings;
if (attrs) {
var nodeAttrs = attrs;
for (var _i = 0, _h = Object.keys(nodeAttrs); _i < _h.length; _i++) {
var attrKey = _h[_i];
var attrValue = nodeAttrs[attrKey];
if ('type' in attrValue && attrValue.type === 'element') {
nodeAttrs[attrKey] = parseComponentNode(attrValue, component);
}
}
;
node.content.attrs =
teleport_shared_1.UIDLUtils.transformAttributesAssignmentsToJson(nodeAttrs, dependency && (dependency === null || dependency === void 0 ? void 0 : dependency.type) === 'local');
}
if (fallback) {
;
node.content.nodes.fallback = parseComponentNode(fallback, component);
}
if (error) {
;
node.content.nodes.error = parseComponentNode(error, component);
}
Object.keys(mappings_1).forEach(function (mapping) {
;
node.content.mappings[mapping] =
parseComponentNode(mappings_1[mapping], component);
});
return node;
}
case 'element':

@@ -160,2 +215,14 @@ var elementContent = node.content;

}
if (elementContent.events) {
Object.values(elementContent.events).forEach(function (eventHandler) {
eventHandler.forEach(function (eventStatement) {
if (eventStatement.type === 'stateChange') {
eventStatement.modifies = teleport_shared_1.StringUtils.createStateOrPropStoringValue(eventStatement.modifies);
}
if (eventStatement.type === 'propCall') {
eventStatement.calls = teleport_shared_1.StringUtils.createStateOrPropStoringValue(eventStatement.calls);
}
});
});
}
if (elementContent.style) {

@@ -165,7 +232,16 @@ elementContent.style = teleport_shared_1.UIDLUtils.transformStylesAssignmentsToJson(elementContent.style);

if (elementContent.attrs) {
elementContent.attrs = teleport_shared_1.UIDLUtils.transformAttributesAssignmentsToJson(elementContent.attrs, 'dependency' in elementContent &&
var attrs = teleport_shared_1.UIDLUtils.transformAttributesAssignmentsToJson(elementContent.attrs, 'dependency' in elementContent &&
((_a = elementContent.dependency) === null || _a === void 0 ? void 0 : _a.type) === 'local');
for (var _j = 0, _k = Object.keys(attrs); _j < _k.length; _j++) {
var attrKey = _k[_j];
var attrValue = attrs[attrKey];
if (attrValue.type === 'element') {
var parsedNamedSlot = parseComponentNode(attrValue, component);
attrs[attrKey] = parsedNamedSlot;
}
}
elementContent.attrs = attrs;
}
if ((_b = elementContent === null || elementContent === void 0 ? void 0 : elementContent.abilities) === null || _b === void 0 ? void 0 : _b.hasOwnProperty('link')) {
var _f = elementContent.abilities.link, content = _f.content, type = _f.type;
var _l = elementContent.abilities.link, content = _l.content, type = _l.type;
if (type === 'navlink' && typeof content.routeName === 'string') {

@@ -189,2 +265,8 @@ var route = {

}
if (type === 'section' && typeof content.section === 'string') {
content.section = {
type: 'static',
content: content.section,
};
}
}

@@ -209,2 +291,8 @@ if (Array.isArray(elementContent.children)) {

}
if (reference.type === 'dynamic' && conditionalNode.content.reference.type === 'dynamic') {
conditionalNode.content.reference.content = {
referenceType: reference.content.referenceType,
id: teleport_shared_1.StringUtils.createStateOrPropStoringValue(conditionalNode.content.reference.content.id),
};
}
return conditionalNode;

@@ -211,0 +299,0 @@ case 'repeat':

@@ -86,3 +86,3 @@ "use strict";

teleport_shared_1.UIDLUtils.traverseNodes(input.node, function (node, parent) {
var _a, _b, _c, _d, _e;
var _a, _b, _c, _d, _e, _f, _g;
if (node.type === 'element') {

@@ -98,4 +98,14 @@ var content = node.content;

}
if (node.type === 'cms-item' || node.type === 'cms-list') {
Object.values(((_c = (_b = node.content) === null || _b === void 0 ? void 0 : _b.resource) === null || _c === void 0 ? void 0 : _c.params) || {}).forEach(function (param) {
if (param.type === 'dynamic' &&
(param.content.referenceType === 'state' || param.content.referenceType === 'prop')) {
param.content.referenceType === 'prop'
? usedPropKeys.push(param.content.id)
: usedStateKeys.push(param.content.id);
}
});
}
if (node.type === 'element') {
Object.keys(((_b = node.content) === null || _b === void 0 ? void 0 : _b.events) || {}).forEach(function (eventKey) {
Object.keys(((_d = node.content) === null || _d === void 0 ? void 0 : _d.events) || {}).forEach(function (eventKey) {
node.content.events[eventKey].forEach(function (event) {

@@ -114,3 +124,3 @@ if (event.type === 'stateChange' && !stateKeys.includes(event.modifies)) {

var dynamicVariants_1 = [];
Object.values(((_c = node.content) === null || _c === void 0 ? void 0 : _c.referencedStyles) || {}).forEach(function (styleRef) {
Object.values(((_e = node.content) === null || _e === void 0 ? void 0 : _e.referencedStyles) || {}).forEach(function (styleRef) {
if (styleRef.content.mapType === 'component-referenced' &&

@@ -120,3 +130,3 @@ styleRef.content.content.type === 'dynamic') {

var referencedProp = styleRef.content.content.content.id;
if (!dynamicPathExistsInDefinitions(referencedProp, propKeys)) {
if (!dynamicPathExistsInDefinitions(referencedProp, input.propDefinitions, 'prop')) {
var errorMsg = "\"".concat(referencedProp, "\" is used but not defined. Please add it in propDefinitions ").concat(input.name);

@@ -138,7 +148,7 @@ errors.push(errorMsg);

if (dynamicVariants_1.length > 1) {
errors.push("Node ".concat(((_d = node.content) === null || _d === void 0 ? void 0 : _d.name) || ((_e = node.content) === null || _e === void 0 ? void 0 : _e.key), " is using multiple dynamic variants using propDefinitions.\n We can have only one dynamic variant at once"));
errors.push("Node ".concat(((_f = node.content) === null || _f === void 0 ? void 0 : _f.name) || ((_g = node.content) === null || _g === void 0 ? void 0 : _g.key), " is using multiple dynamic variants using propDefinitions.\n We can have only one dynamic variant at once"));
}
}
if (node.type === 'dynamic' && node.content.referenceType === 'prop') {
if (!dynamicPathExistsInDefinitions(node.content.id, propKeys)) {
if (!dynamicPathExistsInDefinitions(node.content.id, input.propDefinitions, 'prop')) {
var errorMsg = "\n \"".concat(node.content.id, "\" is used but not defined in ").concat(input.name, " component. Please add it in propDefinitions.\nUsed on Node ").concat(JSON.stringify(node), ".\nParent node is ").concat(JSON.stringify(parent, null, 2));

@@ -153,3 +163,3 @@ errors.push(errorMsg);

if (node.type === 'dynamic' && node.content.referenceType === 'state') {
if (!dynamicPathExistsInDefinitions(node.content.id, stateKeys)) {
if (!dynamicPathExistsInDefinitions(node.content.id, input.stateDefinitions, 'state')) {
console.warn("\n\"".concat(node.content.id, "\" is used but not defined. Please add it in stateDefinitions"));

@@ -163,3 +173,3 @@ }

if (node.type === 'import') {
if (!dynamicPathExistsInDefinitions(node.content.id, importKeys)) {
if (!dynamicPathExistsInDefinitions(node.content.id, input.importDefinitions, 'import')) {
var errorMsg = "\n\"".concat(node.content.id, "\" is used but not defined. Please add it in importDefinitions");

@@ -192,11 +202,28 @@ errors.push(errorMsg);

exports.checkDynamicDefinitions = checkDynamicDefinitions;
var dynamicPathExistsInDefinitions = function (path, defKeys) {
if (!path.includes('.')) {
// prop/state is a scalar value, not a dot notation
return defKeys.includes(path);
var dynamicPathExistsInDefinitions = function (path, definitions, type) {
if (definitions === void 0) { definitions = {}; }
if (!path) {
return false;
}
// TODO: Expand validation logic to check if the path exists on the prop/state definition
// ex: if prop reference is `user.name`, we should check that prop type is object and has a valid field name
var rootIdentifier = path.split('.')[0];
return defKeys.includes(rootIdentifier);
// Extract the keys from the path string considering both dot and bracket notation
var pathKeys = path.split(/\.|\[\s*['"]?(.+?)['"]?\s*\]/).filter(Boolean);
// Get definition values of prop/state/import definitions
var obj = Object.keys(definitions).reduce(function (acc, key) {
acc[key] =
type === 'import'
? definitions[key]
: definitions[key].defaultValue;
return acc;
}, {});
for (var _i = 0, pathKeys_1 = pathKeys; _i < pathKeys_1.length; _i++) {
var key = pathKeys_1[_i];
// Check if the key exists in the current object
// NOTE: using 'key in obj' instead of 'obj[key]' is important to avoid returning 'false' when path exists, but value is empty string/undefined/null
if (!(key in obj)) {
return false;
}
// Move to the next nested object
obj = obj[key];
}
return true;
};

@@ -203,0 +230,0 @@ // A projectUIDL must contain "route" key

@@ -7,3 +7,3 @@ import { object, string, dict, withDefault, optional, array, intersection, } from '@mojotech/json-type-validation';

stateDefinitions: optional(dict(stateDefinitionsDecoder)),
propDefinitions: optional(dict(propDefinitionsDecoder)),
propDefinitions: withDefault({}, dict(propDefinitionsDecoder)),
styleSetDefinitions: optional(dict(styleSetDefinitionDecoder)),

@@ -24,6 +24,6 @@ importDefinitions: optional(dict(externaldependencyDecoder)),

})),
propDefinitions: optional(dict(propDefinitionsDecoder)),
propDefinitions: withDefault({}, dict(propDefinitionsDecoder)),
importDefinitions: optional(dict(externaldependencyDecoder)),
peerDefinitions: optional(dict(peerDependencyDecoder)),
styleSetDefinitions: optional(dict(styleSetDefinitionDecoder)),
styleSetDefinitions: withDefault({}, dict(styleSetDefinitionDecoder)),
outputOptions: optional(outputOptionsDecoder),

@@ -30,0 +30,0 @@ seo: optional(componentSeoDecoder),

@@ -1,9 +0,6 @@

export declare class CustomCombinators<A> {
private decode;
private constructor();
static isValidComponentName(): CustomCombinators<string>;
static isValidNavLink(): CustomCombinators<string>;
static isValidFileName(): CustomCombinators<string>;
static isValidElementName(): CustomCombinators<string>;
}
import { Decoder } from '@mojotech/json-type-validation';
export declare const isValidComponentName: (name: string) => Decoder<string>;
export declare const isValidNavLink: (link: string) => Decoder<string>;
export declare const isValidFileName: (name: string) => Decoder<string>;
export declare const isValidElementName: (name: string) => Decoder<string>;
//# sourceMappingURL=custom-combinators.d.ts.map

@@ -1,62 +0,40 @@

/* tslint:disable member-ordering */
import { Result } from '@mojotech/json-type-validation';
var CustomCombinators = /** @class */ (function () {
// @ts-ignore
function CustomCombinators(decode) {
this.decode = decode;
import { succeed, fail } from '@mojotech/json-type-validation';
/* These are some custom combinators that comes in handy for us,
instead of parsing and cross-checking regex again. The combinators,
can used inside a existing Decoder, since we did not implement any run()
runWithException() etc */
export var isValidComponentName = function (name) {
var componentNameRegex = new RegExp('^[A-Z]+[a-zA-Z0-9]*$');
if (name && typeof name === 'string' && componentNameRegex.test(name)) {
return succeed(name);
}
CustomCombinators.isValidComponentName = function () {
return new CustomCombinators(function (json) {
var componentNameRegex = new RegExp('^[A-Z]+[a-zA-Z0-9]*$');
if (json && typeof json === 'string' && componentNameRegex.test(json)) {
return Result.ok(json);
}
else if (json.length === 0) {
throw new Error("Component Name cannot be empty");
}
throw new Error("Invalid Component name, got ".concat(json));
});
};
CustomCombinators.isValidNavLink = function () {
return new CustomCombinators(function (link) {
if (!link || typeof link !== 'string') {
throw new Error("Invalid navLink attribute, received ".concat(link));
}
if (link === '**') {
return Result.ok(link);
}
var navLinkRegex = new RegExp('/[a-zA-Z0-9-_]*$');
if (navLinkRegex.test(link)) {
return Result.ok(link);
}
throw new Error("Invalid navLink attribute, received ".concat(link));
});
};
CustomCombinators.isValidFileName = function () {
return new CustomCombinators(function (json) {
var fileNameRegex = new RegExp('^[a-zA-Z0-9-_.]*$');
if (json && typeof json === 'string' && fileNameRegex.test(json)) {
return Result.ok(json);
}
else if (json.length === 0) {
throw new Error("File Name cannot be empty");
}
throw new Error("Invalid File name, received ".concat(json));
});
};
CustomCombinators.isValidElementName = function () {
return new CustomCombinators(function (json) {
var fileNameRegex = new RegExp('^[a-zA-Z]+[a-zA-Z0-9-_]*$');
if (json && typeof json === 'string' && fileNameRegex.test(json)) {
return Result.ok(json);
}
else if (json.length === 0) {
throw new Error("Name attribute cannot be empty");
}
throw new Error("Invalid name attribute, received ".concat(json));
});
};
return CustomCombinators;
}());
export { CustomCombinators };
return fail("Invalid Component name, got ".concat(name));
};
export var isValidNavLink = function (link) {
if (!link || typeof link !== 'string') {
throw new Error("Invalid navLink attribute, received ".concat(link));
}
if (link === '**') {
return succeed(link);
}
var navLinkRegex = new RegExp('/(?:[a-zA-Z0-9-_]+|/[[a-zA-Z]+]|[/[a-zA-Z]+])*');
if (navLinkRegex.test(link)) {
return succeed(link);
}
return fail("Invalid navLink attribute, received ".concat(link));
};
export var isValidFileName = function (name) {
var fileNameRegex = new RegExp('^[[a-zA-Z0-9-_.]+]*$');
if (name && typeof name === 'string' && fileNameRegex.test(name)) {
return succeed(name);
}
return fail("Invalid File name, received ".concat(name));
};
export var isValidElementName = function (name) {
var elementNameRefex = new RegExp('^[a-zA-Z]+[a-zA-Z0-9-_]*$');
if (name && typeof name === 'string' && elementNameRefex.test(name)) {
return succeed(name);
}
return fail("Invalid name attribute, received ".concat(name));
};
//# sourceMappingURL=custom-combinators.js.map
import { Decoder } from '@mojotech/json-type-validation';
import { UIDLStaticValue, ReferenceType, UIDLDynamicReference, UIDLPropDefinition, UIDLStateDefinition, UIDLPageOptions, UIDLComponentOutputOptions, UIDLDependency, UIDLStyleDefinitions, UIDLStyleValue, UIDLAttributeValue, UIDLEventHandlerStatement, UIDLMailLinkNode, UIDLPhoneLinkNode, UIDLRawValue, UIDLElementStyleStates, UIDLStyleStateCondition, UIDLStyleMediaQueryScreenSizeCondition, UIDLStyleConditions, UIDLElementNodeProjectReferencedStyle, VUIDLComponentSEO, VUIDLGlobalAsset, UIDLExternalDependency, UIDLLocalDependency, UIDLPeerDependency, UIDLImportReference, UIDLStyleSetTokenReference, VUIDLStyleSetDefnition, VUIDLElement, VUIDLSlotNode, VUIDLConditionalNode, VUIDLRepeatNode, VUIDLElementNode, VUIDLNode, VUIDLElementNodeInlineReferencedStyle, VUIDLSectionLinkNode, VUIDLLinkNode, VUIDLURLLinkNode, VUIDLStyleSetConditions, VUIDLStyleSetMediaCondition, VUIDLStyleSetStateCondition, VUIDLDesignTokens, UIDLPropCallEvent, UIDLStateModifierEvent, UIDLScriptExternalAsset, UIDLScriptInlineAsset, VUIDLStyleInlineAsset, UIDLStyleExternalAsset, VUIDLFontAsset, UIDLCanonicalAsset, UIDLIconAsset, UIDLAssetBase, VUIDLElementNodeClassReferencedStyle, UIDLCompDynamicReference, UIDLComponentStyleReference, PagePaginationOptions, VCMSItemUIDLElementNode, VCMSListUIDLElementNode, UIDLInitialPathsData, UIDLInitialPropsData, UIDLExpressionValue, UIDLDynamicLinkNode, UIDLENVValue, UIDLPropValue, UIDLResourceItem, VUIDLNavLinkNode, VUIDLDateTimeNode, UIDLStateValue, UIDLResourceLink, UIDLLocalResource, UIDLExternalResource, VCMSListRepeaterElementNode, UIDLResourceMapper, UIDLInjectValue, VUIDLStateValueDetails } from '@teleporthq/teleport-types';
import { UIDLStaticValue, ReferenceType, UIDLDynamicReference, UIDLStateDefinition, UIDLPageOptions, UIDLComponentOutputOptions, UIDLDependency, UIDLStyleDefinitions, UIDLStyleValue, VUIDLAttributeValue, UIDLEventHandlerStatement, UIDLMailLinkNode, UIDLPhoneLinkNode, UIDLRawValue, UIDLElementStyleStates, UIDLStyleStateCondition, UIDLStyleMediaQueryScreenSizeCondition, UIDLStyleConditions, UIDLElementNodeProjectReferencedStyle, VUIDLComponentSEO, VUIDLGlobalAsset, UIDLExternalDependency, UIDLLocalDependency, UIDLPeerDependency, UIDLImportReference, UIDLStyleSetTokenReference, VUIDLStyleSetDefnition, VUIDLElement, VUIDLSlotNode, VUIDLConditionalNode, VUIDLRepeatNode, VUIDLElementNode, VUIDLNode, VUIDLElementNodeInlineReferencedStyle, VUIDLSectionLinkNode, VUIDLLinkNode, VUIDLURLLinkNode, VUIDLStyleSetConditions, VUIDLStyleSetMediaCondition, VUIDLStyleSetStateCondition, VUIDLDesignTokens, UIDLPropCallEvent, UIDLStateModifierEvent, UIDLScriptExternalAsset, UIDLScriptInlineAsset, VUIDLStyleInlineAsset, UIDLStyleExternalAsset, VUIDLFontAsset, UIDLCanonicalAsset, UIDLIconAsset, UIDLAssetBase, VUIDLElementNodeClassReferencedStyle, UIDLCompDynamicReference, UIDLComponentStyleReference, PagePaginationOptions, VCMSItemUIDLElementNode, VCMSListUIDLElementNode, UIDLInitialPathsData, UIDLInitialPropsData, UIDLExpressionValue, UIDLDynamicLinkNode, UIDLENVValue, UIDLPropValue, UIDLResourceItem, VUIDLNavLinkNode, VUIDLDateTimeNode, UIDLStateValue, UIDLResourceLink, UIDLLocalResource, UIDLExternalResource, VCMSListRepeaterElementNode, UIDLResourceMapper, UIDLInjectValue, VUIDLStateValueDetails, VUIDLCMSMixedTypeNode, UIDLLocalFontAsset, VUIDLPropDefinitions } from '@teleporthq/teleport-types';
export declare const referenceTypeDecoder: Decoder<ReferenceType>;

@@ -12,5 +12,2 @@ export declare const dynamicValueDecoder: Decoder<UIDLDynamicReference>;

export declare const resourceItemDecoder: Decoder<UIDLResourceItem>;
export declare const uidlLocalResourcerDecpder: Decoder<UIDLLocalResource>;
export declare const uidlExternalResourceDecoder: Decoder<UIDLExternalResource>;
export declare const uidlResourceLinkDecoder: Decoder<UIDLResourceLink>;
export declare const initialPropsDecoder: Decoder<UIDLInitialPropsData>;

@@ -24,3 +21,3 @@ export declare const initialPathsDecoder: Decoder<UIDLInitialPathsData>;

export declare const styleSetDefinitionDecoder: Decoder<VUIDLStyleSetDefnition>;
export declare const stateOrPropDefinitionDecoder: Decoder<string | number | boolean | Record<string, unknown> | (string | number | Record<string, unknown>)[]>;
export declare const stateDefinitionsDefaultValueDecoder: Decoder<string | number | boolean | Record<string, unknown> | (string | number | Record<string, unknown>)[]>;
export declare const globalAssetsDecoder: Decoder<VUIDLGlobalAsset>;

@@ -33,2 +30,3 @@ export declare const baseAssetDecoder: Decoder<UIDLAssetBase>;

export declare const fontAssetDecoder: Decoder<VUIDLFontAsset>;
export declare const localFontDecoder: Decoder<UIDLLocalFontAsset>;
export declare const canonicalAssetDecoder: Decoder<UIDLCanonicalAsset>;

@@ -38,3 +36,3 @@ export declare const iconAssetDecoder: Decoder<UIDLIconAsset>;

export declare const stateValueDetailsDecoder: Decoder<VUIDLStateValueDetails>;
export declare const propDefinitionsDecoder: Decoder<UIDLPropDefinition>;
export declare const propDefinitionsDecoder: Decoder<VUIDLPropDefinitions>;
export declare const pageOptionsPaginationDecoder: Decoder<PagePaginationOptions>;

@@ -50,3 +48,3 @@ export declare const stateDefinitionsDecoder: Decoder<UIDLStateDefinition>;

export declare const importReferenceDecoder: Decoder<UIDLImportReference>;
export declare const attributeValueDecoder: Decoder<UIDLAttributeValue>;
export declare const attributeValueDecoder: Decoder<VUIDLAttributeValue>;
export declare const uidlComponentStyleReference: Decoder<UIDLComponentStyleReference>;

@@ -80,6 +78,10 @@ export declare const styleValueDecoder: Decoder<UIDLStyleValue>;

export declare const dateTimeNodeDecoder: Decoder<VUIDLDateTimeNode>;
export declare const uidlLocalResourcerDecpder: Decoder<UIDLLocalResource>;
export declare const uidlExternalResourceDecoder: Decoder<UIDLExternalResource>;
export declare const uidlResourceLinkDecoder: Decoder<UIDLResourceLink>;
export declare const cmsItemNodeDecoder: Decoder<VCMSItemUIDLElementNode>;
export declare const cmsListNodeDecoder: Decoder<VCMSListUIDLElementNode>;
export declare const cmsListRepeaterNodeDecoder: Decoder<VCMSListRepeaterElementNode>;
export declare const cmsListNodeDecoder: Decoder<VCMSListUIDLElementNode>;
export declare const cmsMixedTypeNodeDecoder: Decoder<VUIDLCMSMixedTypeNode>;
export declare const uidlNodeDecoder: Decoder<VUIDLNode>;
//# sourceMappingURL=utils.d.ts.map
import { object, string, dict, constant, number, optional, union, boolean, array, lazy, oneOf, intersection, withDefault, anyJson, } from '@mojotech/json-type-validation';
import { CustomCombinators } from './custom-combinators';
var isValidComponentName = CustomCombinators.isValidComponentName, isValidFileName = CustomCombinators.isValidFileName, isValidElementName = CustomCombinators.isValidElementName, isValidNavLink = CustomCombinators.isValidNavLink;
import { isValidElementName, isValidNavLink, isValidFileName, isValidComponentName, } from './custom-combinators';
export var referenceTypeDecoder = union(constant('prop'), constant('state'), constant('local'), constant('attr'), constant('children'), constant('token'), constant('expr'));

@@ -9,3 +8,3 @@ export var dynamicValueDecoder = object({

referenceType: referenceTypeDecoder,
path: optional(array(string())),
refPath: optional(array(string())),
id: string(),

@@ -52,5 +51,5 @@ }),

method: withDefault('GET', union(constant('GET'), constant('POST'))),
body: optional(dict(staticValueDecoder)),
body: optional(dict(union(staticValueDecoder, expressionValueDecoder))),
mappers: withDefault([], array(string())),
params: optional(dict(union(staticValueDecoder, dyamicFunctionParam, dyamicFunctionStateParam))),
params: optional(dict(union(staticValueDecoder, dyamicFunctionParam, dyamicFunctionStateParam, expressionValueDecoder))),
response: optional(object({

@@ -60,19 +59,15 @@ type: withDefault('json', union(constant('json'), constant('headers'), constant('text'), constant('none'))),

});
export var uidlLocalResourcerDecpder = object({
id: string(),
params: optional(dict(union(staticValueDecoder, dyamicFunctionParam, expressionValueDecoder))),
});
export var uidlExternalResourceDecoder = object({
name: string(),
dependency: lazy(function () { return externaldependencyDecoder; }),
params: optional(dict(union(staticValueDecoder, dyamicFunctionParam, expressionValueDecoder))),
});
export var uidlResourceLinkDecoder = union(uidlLocalResourcerDecpder, uidlExternalResourceDecoder);
export var initialPropsDecoder = object({
exposeAs: object({
name: string(),
valuePath: optional(array(string())),
itemValuePath: optional(array(string())),
valuePath: withDefault([], array(string())),
}),
resource: uidlResourceLinkDecoder,
resource: union(object({
id: string(),
params: optional(dict(union(staticValueDecoder, expressionValueDecoder))),
}), object({
name: string(),
dependency: lazy(function () { return externaldependencyDecoder; }),
params: optional(dict(union(staticValueDecoder, expressionValueDecoder))),
})),
cache: optional(object({ revalidate: number() })),

@@ -86,3 +81,10 @@ });

}),
resource: uidlResourceLinkDecoder,
resource: union(object({
id: string(),
params: optional(dict(union(staticValueDecoder, expressionValueDecoder))),
}), object({
name: string(),
dependency: lazy(function () { return externaldependencyDecoder; }),
params: optional(dict(union(staticValueDecoder, expressionValueDecoder))),
})),
});

@@ -126,5 +128,4 @@ export var injectValueDecoder = object({

});
// TODO: Implement decoder for () => void
export var stateOrPropDefinitionDecoder = union(string(), number(), boolean(), array(union(string(), number(), object())), object());
export var globalAssetsDecoder = union(lazy(function () { return inlineScriptAssetDecoder; }), lazy(function () { return externalScriptAssetDecoder; }), lazy(function () { return inlineStyletAssetDecoder; }), lazy(function () { return externalStyleAssetDecoder; }), lazy(function () { return fontAssetDecoder; }), lazy(function () { return canonicalAssetDecoder; }), lazy(function () { return iconAssetDecoder; }));
export var stateDefinitionsDefaultValueDecoder = union(string(), number(), boolean(), array(union(string(), number(), object())), object());
export var globalAssetsDecoder = union(lazy(function () { return inlineScriptAssetDecoder; }), lazy(function () { return externalScriptAssetDecoder; }), lazy(function () { return inlineStyletAssetDecoder; }), lazy(function () { return externalStyleAssetDecoder; }), lazy(function () { return fontAssetDecoder; }), lazy(function () { return canonicalAssetDecoder; }), lazy(function () { return iconAssetDecoder; }), lazy(function () { return localFontDecoder; }));
export var baseAssetDecoder = object({

@@ -159,2 +160,7 @@ options: optional(object({

});
export var localFontDecoder = object({
type: constant('local-font'),
path: string(),
properties: dict(staticValueDecoder),
});
export var canonicalAssetDecoder = object({

@@ -183,4 +189,4 @@ type: constant('canonical'),

export var propDefinitionsDecoder = object({
type: union(constant('string'), constant('boolean'), constant('number'), constant('array'), constant('func'), constant('object'), constant('children')),
defaultValue: optional(stateOrPropDefinitionDecoder),
type: union(constant('string'), constant('boolean'), constant('number'), constant('array'), constant('func'), constant('object'), constant('children'), constant('element')),
defaultValue: optional(union(stateDefinitionsDefaultValueDecoder, lazy(function () { return elementNodeDecoder; }))),
isRequired: optional(boolean()),

@@ -199,11 +205,9 @@ id: optional(string()),

type: union(constant('string'), constant('boolean'), constant('number'), constant('array'), constant('func'), constant('object'), constant('children')),
defaultValue: stateOrPropDefinitionDecoder,
defaultValue: stateDefinitionsDefaultValueDecoder,
});
export var pageOptionsDecoder = object({
componentName: optional(isValidComponentName()),
navLink: optional(isValidNavLink()),
fileName: optional(isValidFileName()),
componentName: optional(string().andThen(isValidComponentName)),
navLink: optional(string().andThen(isValidNavLink)),
fileName: optional(string().andThen(isValidFileName)),
fallback: optional(boolean()),
dynamicRouteAttribute: optional(string()),
isIndex: optional(boolean()),
pagination: optional(pageOptionsPaginationDecoder),

@@ -216,8 +220,8 @@ initialPropsData: optional(initialPropsDecoder),

export var outputOptionsDecoder = object({
componentClassName: optional(isValidComponentName()),
fileName: optional(isValidFileName()),
styleFileName: optional(isValidFileName()),
templateFileName: optional(isValidFileName()),
moduleName: optional(isValidFileName()),
folderPath: optional(array(isValidFileName())),
componentClassName: optional(string().andThen(isValidComponentName)),
fileName: optional(string().andThen(isValidFileName)),
styleFileName: optional(string().andThen(isValidFileName)),
templateFileName: optional(string().andThen(isValidFileName)),
moduleName: optional(string().andThen(isValidFileName)),
folderPath: optional(array(string().andThen(isValidFileName))),
});

@@ -263,3 +267,3 @@ export var peerDependencyDecoder = object({

});
export var attributeValueDecoder = union(dynamicValueDecoder, staticValueDecoder, lazy(function () { return expressionValueDecoder; }), importReferenceDecoder, rawValueDecoder, lazy(function () { return uidlComponentStyleReference; }));
export var attributeValueDecoder = union(dynamicValueDecoder, staticValueDecoder, lazy(function () { return expressionValueDecoder; }), importReferenceDecoder, rawValueDecoder, lazy(function () { return uidlComponentStyleReference; }), lazy(function () { return elementNodeDecoder; }));
export var uidlComponentStyleReference = object({

@@ -285,3 +289,3 @@ type: constant('comp-style'),

content: object({
url: union(attributeValueDecoder, string()),
url: union(expressionValueDecoder, dynamicValueDecoder, staticValueDecoder, importReferenceDecoder, uidlComponentStyleReference, rawValueDecoder, string()),
newTab: withDefault(false, boolean()),

@@ -300,3 +304,5 @@ }),

type: constant('section'),
content: dict(string()),
content: object({
section: union(string(), staticValueDecoder, expressionValueDecoder),
}),
});

@@ -306,3 +312,3 @@ export var navLinkNodeDecoder = object({

content: object({
routeName: union(attributeValueDecoder, string()),
routeName: union(expressionValueDecoder, dynamicValueDecoder, staticValueDecoder, importReferenceDecoder, uidlComponentStyleReference, rawValueDecoder, string()),
}),

@@ -351,3 +357,3 @@ });

conditions: array(styleConditionsDecoder),
styles: optional(dict(union(attributeValueDecoder, string(), number()))),
styles: optional(dict(union(styleValueDecoder, string(), number()))),
}),

@@ -373,15 +379,14 @@ });

semanticType: optional(string()),
name: optional(isValidElementName()),
name: optional(string().andThen(isValidElementName)),
key: optional(string()),
dependency: optional(dependencyDecoder),
style: optional(dict(union(attributeValueDecoder, string(), number()))),
style: optional(dict(union(styleValueDecoder, string(), number()))),
attrs: optional(dict(union(attributeValueDecoder, string(), number()))),
events: optional(dict(array(eventHandlerStatementDecoder))),
events: withDefault({}, dict(array(eventHandlerStatementDecoder))),
abilities: optional(object({
link: optional(anyJson()),
})),
children: optional(array(lazy(function () { return uidlNodeDecoder; }))),
children: withDefault([], array(lazy(function () { return uidlNodeDecoder; }))),
referencedStyles: optional(dict(union(elementInlineReferencedStyle, elementProjectReferencedStyle, elementComponentReferencedStyle))),
selfClosing: optional(boolean()),
ignore: optional(boolean()),
});

@@ -399,3 +404,3 @@ export var slotNodeDecoder = object({

node: lazy(function () { return elementNodeDecoder; }),
dataSource: optional(attributeValueDecoder),
dataSource: optional(union(expressionValueDecoder, dynamicValueDecoder, staticValueDecoder, importReferenceDecoder, uidlComponentStyleReference, rawValueDecoder)),
meta: optional(object({

@@ -413,3 +418,3 @@ useIndex: optional(boolean()),

node: lazy(function () { return uidlNodeDecoder; }),
reference: dynamicValueDecoder,
reference: union(dynamicValueDecoder, expressionValueDecoder),
importDefinitions: optional(dict(externaldependencyDecoder)),

@@ -431,2 +436,12 @@ value: union(string(), number(), boolean()),

});
export var uidlLocalResourcerDecpder = object({
id: string(),
params: optional(dict(union(staticValueDecoder, dyamicFunctionParam, expressionValueDecoder, lazy(function () { return dyamicFunctionStateParam; })))),
});
export var uidlExternalResourceDecoder = object({
name: string(),
dependency: lazy(function () { return externaldependencyDecoder; }),
params: optional(dict(union(staticValueDecoder, dyamicFunctionParam, expressionValueDecoder, lazy(function () { return dyamicFunctionStateParam; })))),
});
export var uidlResourceLinkDecoder = union(uidlLocalResourcerDecpder, uidlExternalResourceDecoder);
export var cmsItemNodeDecoder = object({

@@ -446,8 +461,30 @@ type: constant('cms-item'),

renderPropIdentifier: string(),
valuePath: optional(array(string())),
valuePath: withDefault([], array(string())),
itemValuePath: optional(array(string())),
resource: optional(union(uidlLocalResourcerDecpder, uidlExternalResourceDecoder)),
resource: optional(uidlResourceLinkDecoder),
initialData: optional(lazy(function () { return dyamicFunctionParam; })),
entityKeyProperty: optional(string()),
}),
});
export var cmsListNodeDecoder = object({
type: constant('cms-list'),
content: object({
elementType: string(),
name: withDefault('cms-list', string()),
attrs: optional(dict(union(attributeValueDecoder, string(), number()))),
nodes: object({
success: lazy(function () { return elementNodeDecoder; }),
error: optional(lazy(function () { return elementNodeDecoder; })),
loading: optional(lazy(function () { return elementNodeDecoder; })),
empty: optional(lazy(function () { return elementNodeDecoder; })),
}),
router: optional(lazy(function () { return dependencyDecoder; })),
dependency: optional(lazy(function () { return dependencyDecoder; })),
renderPropIdentifier: string(),
itemValuePath: optional(array(string())),
valuePath: withDefault([], array(string())),
resource: optional(uidlResourceLinkDecoder),
initialData: optional(lazy(function () { return dyamicFunctionParam; })),
}),
});
export var cmsListRepeaterNodeDecoder = object({

@@ -462,27 +499,23 @@ type: constant('cms-list-repeater'),

}),
dependency: optional(lazy(function () { return dependencyDecoder; })),
source: optional(string()),
renderPropIdentifier: string(),
}),
});
export var cmsListNodeDecoder = object({
type: constant('cms-list'),
export var cmsMixedTypeNodeDecoder = object({
type: constant('cms-mixed-type'),
content: object({
elementType: string(),
name: withDefault('cms-list', string()),
attrs: optional(dict(union(attributeValueDecoder, string(), number()))),
name: withDefault('cms-mixed-type', string()),
attrs: withDefault({}, lazy(function () { return dict(union(attributeValueDecoder, string(), number())); })),
renderPropIdentifier: string(),
nodes: object({
success: lazy(function () { return elementNodeDecoder; }),
fallback: optional(lazy(function () { return elementNodeDecoder; })),
error: optional(lazy(function () { return elementNodeDecoder; })),
loading: optional(lazy(function () { return elementNodeDecoder; })),
empty: optional(lazy(function () { return elementNodeDecoder; })),
}),
router: optional(lazy(function () { return dependencyDecoder; })),
dependency: optional(lazy(function () { return dependencyDecoder; })),
renderPropIdentifier: string(),
itemValuePath: optional(array(string())),
valuePath: optional(array(string())),
resource: optional(union(uidlLocalResourcerDecpder, uidlExternalResourceDecoder)),
initialData: optional(lazy(function () { return dyamicFunctionParam; })),
mappings: withDefault({}, dict(lazy(function () { return elementNodeDecoder; }))),
}),
});
export var uidlNodeDecoder = union(elementNodeDecoder, cmsItemNodeDecoder, cmsListNodeDecoder, cmsListRepeaterNodeDecoder, dynamicValueDecoder, rawValueDecoder, conditionalNodeDecoder, union(staticValueDecoder, repeatNodeDecoder, slotNodeDecoder, expressionValueDecoder, string()));
export var uidlNodeDecoder = union(union(elementNodeDecoder, dynamicValueDecoder, rawValueDecoder, conditionalNodeDecoder), union(staticValueDecoder, repeatNodeDecoder, slotNodeDecoder, expressionValueDecoder, string()), union(cmsItemNodeDecoder, cmsListNodeDecoder, cmsListRepeaterNodeDecoder, cmsMixedTypeNodeDecoder));
//# sourceMappingURL=utils.js.map

@@ -18,7 +18,10 @@ var __assign = (this && this.__assign) || function () {

if (safeInput === null || safeInput === void 0 ? void 0 : safeInput.propDefinitions) {
safeInput.propDefinitions = Object.keys(safeInput.propDefinitions).reduce(function (acc, prop) {
var acc = {};
for (var _i = 0, _a = Object.keys(safeInput.propDefinitions); _i < _a.length; _i++) {
var prop = _a[_i];
var propValue = safeInput.propDefinitions[prop];
var propName = StringUtils.createStateOrPropStoringValue(prop);
acc[propName] = safeInput.propDefinitions[prop];
return acc;
}, {});
acc[propName] = propValue;
}
safeInput.propDefinitions = acc;
}

@@ -45,3 +48,3 @@ if (safeInput === null || safeInput === void 0 ? void 0 : safeInput.stateDefinitions) {

var seo = safeInput.seo;
var _a = (seo || { assets: [] }).assets, assets = _a === void 0 ? [] : _a;
var _b = (seo || { assets: [] }).assets, assets = _b === void 0 ? [] : _b;
assets.forEach(parseAssets);

@@ -51,2 +54,14 @@ }

var result = __assign({}, safeInput);
for (var _c = 0, _d = Object.keys(result.propDefinitions || {}); _c < _d.length; _c++) {
var propKey = _d[_c];
var prop = result.propDefinitions[propKey];
if (prop.type === 'element' &&
prop.defaultValue !== undefined &&
typeof prop.defaultValue !== 'object') {
throw new ParserError("The defaultValue for prop ".concat(propKey, " in component ").concat(result.name, " is not an object. It should be a UIDLElementNode."));
}
if (prop.type === 'element' && prop.defaultValue) {
result.propDefinitions[propKey].defaultValue = parseComponentNode(prop.defaultValue, result);
}
}
// other parsers for other sections of the component here

@@ -92,4 +107,4 @@ result.node = parseComponentNode(node, result);

case 'cms-item':
case 'cms-list':
var _c = node.content, initialData = _c.initialData, _d = _c.nodes, success = _d.success, error = _d.error, loading = _d.loading;
case 'cms-list': {
var _c = node.content, initialData = _c.initialData, _d = _c.nodes, success = _d.success, error = _d.error, loading = _d.loading, resource = _c.resource;
if (initialData) {

@@ -114,4 +129,13 @@ initialData.content.id = StringUtils.createStateOrPropStoringValue(initialData.content.id);

}
if (resource === null || resource === void 0 ? void 0 : resource.params) {
Object.values((resource === null || resource === void 0 ? void 0 : resource.params) || {}).forEach(function (param) {
if (param.type === 'dynamic' &&
(param.content.referenceType === 'state' || param.content.referenceType === 'prop')) {
param.content.id = StringUtils.createStateOrPropStoringValue(param.content.id);
}
});
}
return node;
case 'cms-list-repeater':
}
case 'cms-list-repeater': {
var _e = node.content.nodes, list = _e.list, empty = _e.empty;

@@ -127,2 +151,33 @@ if (list) {

return node;
}
case 'cms-mixed-type': {
var _f = node.content, _g = _f.nodes, fallback = _g.fallback, error = _g.error, dependency = _f.dependency, attrs = _f.attrs, mappings_1 = _f.mappings;
if (attrs) {
var nodeAttrs = attrs;
for (var _i = 0, _h = Object.keys(nodeAttrs); _i < _h.length; _i++) {
var attrKey = _h[_i];
var attrValue = nodeAttrs[attrKey];
if ('type' in attrValue && attrValue.type === 'element') {
nodeAttrs[attrKey] = parseComponentNode(attrValue, component);
}
}
;
node.content.attrs =
UIDLUtils.transformAttributesAssignmentsToJson(nodeAttrs, dependency && (dependency === null || dependency === void 0 ? void 0 : dependency.type) === 'local');
}
if (fallback) {
;
node.content.nodes.fallback = parseComponentNode(fallback, component);
}
if (error) {
;
node.content.nodes.error = parseComponentNode(error, component);
}
Object.keys(mappings_1).forEach(function (mapping) {
;
node.content.mappings[mapping] =
parseComponentNode(mappings_1[mapping], component);
});
return node;
}
case 'element':

@@ -155,2 +210,14 @@ var elementContent = node.content;

}
if (elementContent.events) {
Object.values(elementContent.events).forEach(function (eventHandler) {
eventHandler.forEach(function (eventStatement) {
if (eventStatement.type === 'stateChange') {
eventStatement.modifies = StringUtils.createStateOrPropStoringValue(eventStatement.modifies);
}
if (eventStatement.type === 'propCall') {
eventStatement.calls = StringUtils.createStateOrPropStoringValue(eventStatement.calls);
}
});
});
}
if (elementContent.style) {

@@ -160,7 +227,16 @@ elementContent.style = UIDLUtils.transformStylesAssignmentsToJson(elementContent.style);

if (elementContent.attrs) {
elementContent.attrs = UIDLUtils.transformAttributesAssignmentsToJson(elementContent.attrs, 'dependency' in elementContent &&
var attrs = UIDLUtils.transformAttributesAssignmentsToJson(elementContent.attrs, 'dependency' in elementContent &&
((_a = elementContent.dependency) === null || _a === void 0 ? void 0 : _a.type) === 'local');
for (var _j = 0, _k = Object.keys(attrs); _j < _k.length; _j++) {
var attrKey = _k[_j];
var attrValue = attrs[attrKey];
if (attrValue.type === 'element') {
var parsedNamedSlot = parseComponentNode(attrValue, component);
attrs[attrKey] = parsedNamedSlot;
}
}
elementContent.attrs = attrs;
}
if ((_b = elementContent === null || elementContent === void 0 ? void 0 : elementContent.abilities) === null || _b === void 0 ? void 0 : _b.hasOwnProperty('link')) {
var _f = elementContent.abilities.link, content = _f.content, type = _f.type;
var _l = elementContent.abilities.link, content = _l.content, type = _l.type;
if (type === 'navlink' && typeof content.routeName === 'string') {

@@ -184,2 +260,8 @@ var route = {

}
if (type === 'section' && typeof content.section === 'string') {
content.section = {
type: 'static',
content: content.section,
};
}
}

@@ -204,2 +286,8 @@ if (Array.isArray(elementContent.children)) {

}
if (reference.type === 'dynamic' && conditionalNode.content.reference.type === 'dynamic') {
conditionalNode.content.reference.content = {
referenceType: reference.content.referenceType,
id: StringUtils.createStateOrPropStoringValue(conditionalNode.content.reference.content.id),
};
}
return conditionalNode;

@@ -206,0 +294,0 @@ case 'repeat':

@@ -81,3 +81,3 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {

UIDLUtils.traverseNodes(input.node, function (node, parent) {
var _a, _b, _c, _d, _e;
var _a, _b, _c, _d, _e, _f, _g;
if (node.type === 'element') {

@@ -93,4 +93,14 @@ var content = node.content;

}
if (node.type === 'cms-item' || node.type === 'cms-list') {
Object.values(((_c = (_b = node.content) === null || _b === void 0 ? void 0 : _b.resource) === null || _c === void 0 ? void 0 : _c.params) || {}).forEach(function (param) {
if (param.type === 'dynamic' &&
(param.content.referenceType === 'state' || param.content.referenceType === 'prop')) {
param.content.referenceType === 'prop'
? usedPropKeys.push(param.content.id)
: usedStateKeys.push(param.content.id);
}
});
}
if (node.type === 'element') {
Object.keys(((_b = node.content) === null || _b === void 0 ? void 0 : _b.events) || {}).forEach(function (eventKey) {
Object.keys(((_d = node.content) === null || _d === void 0 ? void 0 : _d.events) || {}).forEach(function (eventKey) {
node.content.events[eventKey].forEach(function (event) {

@@ -109,3 +119,3 @@ if (event.type === 'stateChange' && !stateKeys.includes(event.modifies)) {

var dynamicVariants_1 = [];
Object.values(((_c = node.content) === null || _c === void 0 ? void 0 : _c.referencedStyles) || {}).forEach(function (styleRef) {
Object.values(((_e = node.content) === null || _e === void 0 ? void 0 : _e.referencedStyles) || {}).forEach(function (styleRef) {
if (styleRef.content.mapType === 'component-referenced' &&

@@ -115,3 +125,3 @@ styleRef.content.content.type === 'dynamic') {

var referencedProp = styleRef.content.content.content.id;
if (!dynamicPathExistsInDefinitions(referencedProp, propKeys)) {
if (!dynamicPathExistsInDefinitions(referencedProp, input.propDefinitions, 'prop')) {
var errorMsg = "\"".concat(referencedProp, "\" is used but not defined. Please add it in propDefinitions ").concat(input.name);

@@ -133,7 +143,7 @@ errors.push(errorMsg);

if (dynamicVariants_1.length > 1) {
errors.push("Node ".concat(((_d = node.content) === null || _d === void 0 ? void 0 : _d.name) || ((_e = node.content) === null || _e === void 0 ? void 0 : _e.key), " is using multiple dynamic variants using propDefinitions.\n We can have only one dynamic variant at once"));
errors.push("Node ".concat(((_f = node.content) === null || _f === void 0 ? void 0 : _f.name) || ((_g = node.content) === null || _g === void 0 ? void 0 : _g.key), " is using multiple dynamic variants using propDefinitions.\n We can have only one dynamic variant at once"));
}
}
if (node.type === 'dynamic' && node.content.referenceType === 'prop') {
if (!dynamicPathExistsInDefinitions(node.content.id, propKeys)) {
if (!dynamicPathExistsInDefinitions(node.content.id, input.propDefinitions, 'prop')) {
var errorMsg = "\n \"".concat(node.content.id, "\" is used but not defined in ").concat(input.name, " component. Please add it in propDefinitions.\nUsed on Node ").concat(JSON.stringify(node), ".\nParent node is ").concat(JSON.stringify(parent, null, 2));

@@ -148,3 +158,3 @@ errors.push(errorMsg);

if (node.type === 'dynamic' && node.content.referenceType === 'state') {
if (!dynamicPathExistsInDefinitions(node.content.id, stateKeys)) {
if (!dynamicPathExistsInDefinitions(node.content.id, input.stateDefinitions, 'state')) {
console.warn("\n\"".concat(node.content.id, "\" is used but not defined. Please add it in stateDefinitions"));

@@ -158,3 +168,3 @@ }

if (node.type === 'import') {
if (!dynamicPathExistsInDefinitions(node.content.id, importKeys)) {
if (!dynamicPathExistsInDefinitions(node.content.id, input.importDefinitions, 'import')) {
var errorMsg = "\n\"".concat(node.content.id, "\" is used but not defined. Please add it in importDefinitions");

@@ -186,11 +196,28 @@ errors.push(errorMsg);

};
var dynamicPathExistsInDefinitions = function (path, defKeys) {
if (!path.includes('.')) {
// prop/state is a scalar value, not a dot notation
return defKeys.includes(path);
var dynamicPathExistsInDefinitions = function (path, definitions, type) {
if (definitions === void 0) { definitions = {}; }
if (!path) {
return false;
}
// TODO: Expand validation logic to check if the path exists on the prop/state definition
// ex: if prop reference is `user.name`, we should check that prop type is object and has a valid field name
var rootIdentifier = path.split('.')[0];
return defKeys.includes(rootIdentifier);
// Extract the keys from the path string considering both dot and bracket notation
var pathKeys = path.split(/\.|\[\s*['"]?(.+?)['"]?\s*\]/).filter(Boolean);
// Get definition values of prop/state/import definitions
var obj = Object.keys(definitions).reduce(function (acc, key) {
acc[key] =
type === 'import'
? definitions[key]
: definitions[key].defaultValue;
return acc;
}, {});
for (var _i = 0, pathKeys_1 = pathKeys; _i < pathKeys_1.length; _i++) {
var key = pathKeys_1[_i];
// Check if the key exists in the current object
// NOTE: using 'key in obj' instead of 'obj[key]' is important to avoid returning 'false' when path exists, but value is empty string/undefined/null
if (!(key in obj)) {
return false;
}
// Move to the next nested object
obj = obj[key];
}
return true;
};

@@ -197,0 +224,0 @@ // A projectUIDL must contain "route" key

{
"name": "@teleporthq/teleport-uidl-validator",
"version": "0.36.0-alpha.0",
"version": "0.36.0",
"description": "A module that offers validation and parsing for non-standard UIDL structures",

@@ -28,6 +28,6 @@ "author": "teleportHQ",

"@mojotech/json-type-validation": "^3.1.0",
"@teleporthq/teleport-shared": "^0.36.0-alpha.0",
"@teleporthq/teleport-types": "^0.36.0-alpha.0"
"@teleporthq/teleport-shared": "^0.36.0",
"@teleporthq/teleport-types": "^0.36.0"
},
"gitHead": "4f42496a502dc3bacb427e2ecc6fabda42cde0c2"
"gitHead": "223c0c8f02f64cbfa78eed5ee38836d44efc7f60"
}

@@ -29,3 +29,3 @@ import {

stateDefinitions: optional(dict(stateDefinitionsDecoder)),
propDefinitions: optional(dict(propDefinitionsDecoder)),
propDefinitions: withDefault({}, dict(propDefinitionsDecoder)),
styleSetDefinitions: optional(dict(styleSetDefinitionDecoder)),

@@ -50,6 +50,6 @@ importDefinitions: optional(dict(externaldependencyDecoder)),

),
propDefinitions: optional(dict(propDefinitionsDecoder)),
propDefinitions: withDefault({}, dict(propDefinitionsDecoder)),
importDefinitions: optional(dict(externaldependencyDecoder)),
peerDefinitions: optional(dict(peerDependencyDecoder)),
styleSetDefinitions: optional(dict(styleSetDefinitionDecoder)),
styleSetDefinitions: withDefault({}, dict(styleSetDefinitionDecoder)),
outputOptions: optional(outputOptionsDecoder),

@@ -56,0 +56,0 @@ seo: optional(componentSeoDecoder),

@@ -1,3 +0,2 @@

/* tslint:disable member-ordering */
import { Result, DecoderError } from '@mojotech/json-type-validation'
import { succeed, fail, Decoder } from '@mojotech/json-type-validation'

@@ -9,61 +8,44 @@ /* These are some custom combinators that comes in handy for us,

type DecodeResult<A> = Result.Result<A, Partial<DecoderError>>
export class CustomCombinators<A> {
// @ts-ignore
private constructor(private decode: (json: string) => DecodeResult<A>) {}
export const isValidComponentName = (name: string): Decoder<string> => {
const componentNameRegex = new RegExp('^[A-Z]+[a-zA-Z0-9]*$')
if (name && typeof name === 'string' && componentNameRegex.test(name)) {
return succeed(name)
}
static isValidComponentName(): CustomCombinators<string> {
return new CustomCombinators<string>((json: string) => {
const componentNameRegex = new RegExp('^[A-Z]+[a-zA-Z0-9]*$')
if (json && typeof json === 'string' && componentNameRegex.test(json)) {
return Result.ok(json)
} else if (json.length === 0) {
throw new Error(`Component Name cannot be empty`)
}
throw new Error(`Invalid Component name, got ${json}`)
})
return fail(`Invalid Component name, got ${name}`)
}
export const isValidNavLink = (link: string): Decoder<string> => {
if (!link || typeof link !== 'string') {
throw new Error(`Invalid navLink attribute, received ${link}`)
}
static isValidNavLink(): CustomCombinators<string> {
return new CustomCombinators<string>((link: string) => {
if (!link || typeof link !== 'string') {
throw new Error(`Invalid navLink attribute, received ${link}`)
}
if (link === '**') {
return succeed(link)
}
if (link === '**') {
return Result.ok(link)
}
const navLinkRegex = new RegExp('/(?:[a-zA-Z0-9-_]+|/[[a-zA-Z]+]|[/[a-zA-Z]+])*')
if (navLinkRegex.test(link)) {
return succeed(link)
}
const navLinkRegex = new RegExp('/[a-zA-Z0-9-_]*$')
if (navLinkRegex.test(link)) {
return Result.ok(link)
}
return fail(`Invalid navLink attribute, received ${link}`)
}
throw new Error(`Invalid navLink attribute, received ${link}`)
})
export const isValidFileName = (name: string): Decoder<string> => {
const fileNameRegex = new RegExp('^[[a-zA-Z0-9-_.]+]*$')
if (name && typeof name === 'string' && fileNameRegex.test(name)) {
return succeed(name)
}
static isValidFileName(): CustomCombinators<string> {
return new CustomCombinators<string>((json: string) => {
const fileNameRegex = new RegExp('^[a-zA-Z0-9-_.]*$')
if (json && typeof json === 'string' && fileNameRegex.test(json)) {
return Result.ok(json)
} else if (json.length === 0) {
throw new Error(`File Name cannot be empty`)
}
throw new Error(`Invalid File name, received ${json}`)
})
return fail(`Invalid File name, received ${name}`)
}
export const isValidElementName = (name: string): Decoder<string> => {
const elementNameRefex = new RegExp('^[a-zA-Z]+[a-zA-Z0-9-_]*$')
if (name && typeof name === 'string' && elementNameRefex.test(name)) {
return succeed(name)
}
static isValidElementName(): CustomCombinators<string> {
return new CustomCombinators<string>((json: string) => {
const fileNameRegex = new RegExp('^[a-zA-Z]+[a-zA-Z0-9-_]*$')
if (json && typeof json === 'string' && fileNameRegex.test(json)) {
return Result.ok(json)
} else if (json.length === 0) {
throw new Error(`Name attribute cannot be empty`)
}
throw new Error(`Invalid name attribute, received ${json}`)
})
}
return fail(`Invalid name attribute, received ${name}`)
}

@@ -22,3 +22,2 @@ import {

UIDLDynamicReference,
UIDLPropDefinition,
UIDLStateDefinition,

@@ -30,3 +29,3 @@ UIDLPageOptions,

UIDLStyleValue,
UIDLAttributeValue,
VUIDLAttributeValue,
UIDLEventHandlerStatement,

@@ -96,8 +95,13 @@ UIDLMailLinkNode,

VUIDLStateValueDetails,
VUIDLCMSMixedTypeNode,
UIDLLocalFontAsset,
VUIDLPropDefinitions,
} from '@teleporthq/teleport-types'
import { CustomCombinators } from './custom-combinators'
import {
isValidElementName,
isValidNavLink,
isValidFileName,
isValidComponentName,
} from './custom-combinators'
const { isValidComponentName, isValidFileName, isValidElementName, isValidNavLink } =
CustomCombinators
export const referenceTypeDecoder: Decoder<ReferenceType> = union(

@@ -117,3 +121,3 @@ constant('prop'),

referenceType: referenceTypeDecoder,
path: optional(array(string())),
refPath: optional(array(string())),
id: string(),

@@ -167,5 +171,14 @@ }),

method: withDefault('GET', union(constant('GET'), constant('POST'))),
body: optional(dict(staticValueDecoder)),
body: optional(dict(union(staticValueDecoder, expressionValueDecoder))),
mappers: withDefault([], array(string())),
params: optional(dict(union(staticValueDecoder, dyamicFunctionParam, dyamicFunctionStateParam))),
params: optional(
dict(
union(
staticValueDecoder,
dyamicFunctionParam,
dyamicFunctionStateParam,
expressionValueDecoder
)
)
),
response: optional(

@@ -181,25 +194,18 @@ object({

export const uidlLocalResourcerDecpder: Decoder<UIDLLocalResource> = object({
id: string(),
params: optional(dict(union(staticValueDecoder, dyamicFunctionParam, expressionValueDecoder))),
})
export const uidlExternalResourceDecoder: Decoder<UIDLExternalResource> = object({
name: string(),
dependency: lazy(() => externaldependencyDecoder),
params: optional(dict(union(staticValueDecoder, dyamicFunctionParam, expressionValueDecoder))),
})
export const uidlResourceLinkDecoder: Decoder<UIDLResourceLink> = union(
uidlLocalResourcerDecpder,
uidlExternalResourceDecoder
)
export const initialPropsDecoder: Decoder<UIDLInitialPropsData> = object({
exposeAs: object({
name: string(),
valuePath: optional(array(string())),
itemValuePath: optional(array(string())),
valuePath: withDefault([], array(string())),
}),
resource: uidlResourceLinkDecoder,
resource: union(
object({
id: string(),
params: optional(dict(union(staticValueDecoder, expressionValueDecoder))),
}),
object({
name: string(),
dependency: lazy(() => externaldependencyDecoder),
params: optional(dict(union(staticValueDecoder, expressionValueDecoder))),
})
),
cache: optional(object({ revalidate: number() })),

@@ -214,3 +220,13 @@ })

}),
resource: uidlResourceLinkDecoder,
resource: union(
object({
id: string(),
params: optional(dict(union(staticValueDecoder, expressionValueDecoder))),
}),
object({
name: string(),
dependency: lazy(() => externaldependencyDecoder),
params: optional(dict(union(staticValueDecoder, expressionValueDecoder))),
})
),
})

@@ -282,4 +298,3 @@

// TODO: Implement decoder for () => void
export const stateOrPropDefinitionDecoder = union(
export const stateDefinitionsDefaultValueDecoder = union(
string(),

@@ -299,3 +314,4 @@ number(),

lazy(() => canonicalAssetDecoder),
lazy(() => iconAssetDecoder)
lazy(() => iconAssetDecoder),
lazy(() => localFontDecoder)
)

@@ -346,2 +362,8 @@

export const localFontDecoder: Decoder<UIDLLocalFontAsset> = object({
type: constant('local-font' as const),
path: string(),
properties: dict(staticValueDecoder),
})
export const canonicalAssetDecoder: Decoder<UIDLCanonicalAsset> = object({

@@ -375,3 +397,3 @@ type: constant('canonical' as const),

export const propDefinitionsDecoder: Decoder<UIDLPropDefinition> = object({
export const propDefinitionsDecoder: Decoder<VUIDLPropDefinitions> = object({
type: union(

@@ -384,5 +406,11 @@ constant('string'),

constant('object'),
constant('children')
constant('children'),
constant('element')
),
defaultValue: optional(stateOrPropDefinitionDecoder),
defaultValue: optional(
union(
stateDefinitionsDefaultValueDecoder,
lazy(() => elementNodeDecoder)
)
),
isRequired: optional(boolean()),

@@ -411,12 +439,10 @@ id: optional(string()),

),
defaultValue: stateOrPropDefinitionDecoder,
defaultValue: stateDefinitionsDefaultValueDecoder,
})
export const pageOptionsDecoder: Decoder<UIDLPageOptions> = object({
componentName: optional(isValidComponentName() as unknown as Decoder<string>),
navLink: optional(isValidNavLink() as unknown as Decoder<string>),
fileName: optional(isValidFileName() as unknown as Decoder<string>),
componentName: optional(string().andThen(isValidComponentName)),
navLink: optional(string().andThen(isValidNavLink)),
fileName: optional(string().andThen(isValidFileName)),
fallback: optional(boolean()),
dynamicRouteAttribute: optional(string()),
isIndex: optional(boolean()),
pagination: optional(pageOptionsPaginationDecoder),

@@ -430,8 +456,8 @@ initialPropsData: optional(initialPropsDecoder),

export const outputOptionsDecoder: Decoder<UIDLComponentOutputOptions> = object({
componentClassName: optional(isValidComponentName() as unknown as Decoder<string>),
fileName: optional(isValidFileName() as unknown as Decoder<string>),
styleFileName: optional(isValidFileName() as unknown as Decoder<string>),
templateFileName: optional(isValidFileName() as unknown as Decoder<string>),
moduleName: optional(isValidFileName() as unknown as Decoder<string>),
folderPath: optional(array(isValidFileName() as unknown as Decoder<string>)),
componentClassName: optional(string().andThen(isValidComponentName)),
fileName: optional(string().andThen(isValidFileName)),
styleFileName: optional(string().andThen(isValidFileName)),
templateFileName: optional(string().andThen(isValidFileName)),
moduleName: optional(string().andThen(isValidFileName)),
folderPath: optional(array(string().andThen(isValidFileName))),
})

@@ -491,3 +517,3 @@

export const attributeValueDecoder: Decoder<UIDLAttributeValue> = union(
export const attributeValueDecoder: Decoder<VUIDLAttributeValue> = union(
dynamicValueDecoder,

@@ -498,3 +524,4 @@ staticValueDecoder,

rawValueDecoder,
lazy(() => uidlComponentStyleReference)
lazy(() => uidlComponentStyleReference),
lazy(() => elementNodeDecoder)
)

@@ -534,3 +561,11 @@

content: object({
url: union(attributeValueDecoder, string()),
url: union(
expressionValueDecoder,
dynamicValueDecoder,
staticValueDecoder,
importReferenceDecoder,
uidlComponentStyleReference,
rawValueDecoder,
string()
),
newTab: withDefault(false, boolean()),

@@ -551,3 +586,5 @@ }),

type: constant('section'),
content: dict(string()),
content: object({
section: union(string(), staticValueDecoder, expressionValueDecoder),
}),
})

@@ -558,3 +595,11 @@

content: object({
routeName: union(attributeValueDecoder, string()),
routeName: union(
expressionValueDecoder,
dynamicValueDecoder,
staticValueDecoder,
importReferenceDecoder,
uidlComponentStyleReference,
rawValueDecoder,
string()
),
}),

@@ -635,3 +680,3 @@ })

conditions: array(styleConditionsDecoder),
styles: optional(dict(union(attributeValueDecoder, string(), number()))),
styles: optional(dict(union(styleValueDecoder, string(), number()))),
}),

@@ -664,8 +709,8 @@ })

semanticType: optional(string()),
name: optional(isValidElementName() as unknown as Decoder<string>),
name: optional(string().andThen(isValidElementName)),
key: optional(string()),
dependency: optional(dependencyDecoder),
style: optional(dict(union(attributeValueDecoder, string(), number()))),
style: optional(dict(union(styleValueDecoder, string(), number()))),
attrs: optional(dict(union(attributeValueDecoder, string(), number()))),
events: optional(dict(array(eventHandlerStatementDecoder))),
events: withDefault({}, dict(array(eventHandlerStatementDecoder))),
abilities: optional(

@@ -676,3 +721,3 @@ object({

),
children: optional(array(lazy(() => uidlNodeDecoder))),
children: withDefault([], array(lazy(() => uidlNodeDecoder))),
referencedStyles: optional(

@@ -688,3 +733,2 @@ dict(

selfClosing: optional(boolean()),
ignore: optional(boolean()),
})

@@ -713,3 +757,12 @@

node: lazy(() => elementNodeDecoder),
dataSource: optional(attributeValueDecoder),
dataSource: optional(
union(
expressionValueDecoder,
dynamicValueDecoder,
staticValueDecoder,
importReferenceDecoder,
uidlComponentStyleReference,
rawValueDecoder
)
),
meta: optional(

@@ -730,3 +783,3 @@ object({

node: lazy(() => uidlNodeDecoder),
reference: dynamicValueDecoder,
reference: union(dynamicValueDecoder, expressionValueDecoder),
importDefinitions: optional(dict(externaldependencyDecoder)),

@@ -755,2 +808,36 @@ value: union(string(), number(), boolean()),

export const uidlLocalResourcerDecpder: Decoder<UIDLLocalResource> = object({
id: string(),
params: optional(
dict(
union(
staticValueDecoder,
dyamicFunctionParam,
expressionValueDecoder,
lazy(() => dyamicFunctionStateParam)
)
)
),
})
export const uidlExternalResourceDecoder: Decoder<UIDLExternalResource> = object({
name: string(),
dependency: lazy(() => externaldependencyDecoder),
params: optional(
dict(
union(
staticValueDecoder,
dyamicFunctionParam,
expressionValueDecoder,
lazy(() => dyamicFunctionStateParam)
)
)
),
})
export const uidlResourceLinkDecoder: Decoder<UIDLResourceLink> = union(
uidlLocalResourcerDecpder,
uidlExternalResourceDecoder
)
export const cmsItemNodeDecoder: Decoder<VCMSItemUIDLElementNode> = object({

@@ -770,9 +857,32 @@ type: constant('cms-item'),

renderPropIdentifier: string(),
valuePath: optional(array(string())),
valuePath: withDefault([], array(string())),
itemValuePath: optional(array(string())),
resource: optional(union(uidlLocalResourcerDecpder, uidlExternalResourceDecoder)),
resource: optional(uidlResourceLinkDecoder),
initialData: optional(lazy(() => dyamicFunctionParam)),
entityKeyProperty: optional(string()),
}),
})
export const cmsListNodeDecoder: Decoder<VCMSListUIDLElementNode> = object({
type: constant('cms-list'),
content: object({
elementType: string(),
name: withDefault('cms-list', string()),
attrs: optional(dict(union(attributeValueDecoder, string(), number()))),
nodes: object({
success: lazy(() => elementNodeDecoder),
error: optional(lazy(() => elementNodeDecoder)),
loading: optional(lazy(() => elementNodeDecoder)),
empty: optional(lazy(() => elementNodeDecoder)),
}),
router: optional(lazy(() => dependencyDecoder)),
dependency: optional(lazy(() => dependencyDecoder)),
renderPropIdentifier: string(),
itemValuePath: optional(array(string())),
valuePath: withDefault([], array(string())),
resource: optional(uidlResourceLinkDecoder),
initialData: optional(lazy(() => dyamicFunctionParam)),
}),
})
export const cmsListRepeaterNodeDecoder: Decoder<VCMSListRepeaterElementNode> = object({

@@ -787,2 +897,4 @@ type: constant('cms-list-repeater'),

}),
dependency: optional(lazy(() => dependencyDecoder)),
source: optional(string()),
renderPropIdentifier: string(),

@@ -792,21 +904,18 @@ }),

export const cmsListNodeDecoder: Decoder<VCMSListUIDLElementNode> = object({
type: constant('cms-list'),
export const cmsMixedTypeNodeDecoder: Decoder<VUIDLCMSMixedTypeNode> = object({
type: constant('cms-mixed-type'),
content: object({
elementType: string(),
name: withDefault('cms-list', string()),
attrs: optional(dict(union(attributeValueDecoder, string(), number()))),
name: withDefault('cms-mixed-type', string()),
attrs: withDefault(
{},
lazy(() => dict(union(attributeValueDecoder, string(), number())))
),
renderPropIdentifier: string(),
nodes: object({
success: lazy(() => elementNodeDecoder),
fallback: optional(lazy(() => elementNodeDecoder)),
error: optional(lazy(() => elementNodeDecoder)),
loading: optional(lazy(() => elementNodeDecoder)),
empty: optional(lazy(() => elementNodeDecoder)),
}),
router: optional(lazy(() => dependencyDecoder)),
dependency: optional(lazy(() => dependencyDecoder)),
renderPropIdentifier: string(),
itemValuePath: optional(array(string())),
valuePath: optional(array(string())),
resource: optional(union(uidlLocalResourcerDecpder, uidlExternalResourceDecoder)),
initialData: optional(lazy(() => dyamicFunctionParam)),
mappings: withDefault({}, dict(lazy(() => elementNodeDecoder))),
}),

@@ -816,10 +925,5 @@ })

export const uidlNodeDecoder: Decoder<VUIDLNode> = union(
elementNodeDecoder,
cmsItemNodeDecoder,
cmsListNodeDecoder,
cmsListRepeaterNodeDecoder,
dynamicValueDecoder,
rawValueDecoder,
conditionalNodeDecoder,
union(staticValueDecoder, repeatNodeDecoder, slotNodeDecoder, expressionValueDecoder, string())
union(elementNodeDecoder, dynamicValueDecoder, rawValueDecoder, conditionalNodeDecoder),
union(staticValueDecoder, repeatNodeDecoder, slotNodeDecoder, expressionValueDecoder, string()),
union(cmsItemNodeDecoder, cmsListNodeDecoder, cmsListRepeaterNodeDecoder, cmsMixedTypeNodeDecoder)
)

@@ -28,2 +28,4 @@ import { StringUtils, UIDLUtils } from '@teleporthq/teleport-shared'

UIDLDependency,
UIDLEventHandlerStatement,
UIDLCMSMixedTypeNode,
} from '@teleporthq/teleport-types'

@@ -42,10 +44,9 @@

if (safeInput?.propDefinitions) {
safeInput.propDefinitions = Object.keys(safeInput.propDefinitions).reduce(
(acc: Record<string, UIDLPropDefinition>, prop) => {
const propName = StringUtils.createStateOrPropStoringValue(prop)
acc[propName] = (safeInput.propDefinitions as Record<string, UIDLPropDefinition>)[prop]
return acc
},
{}
)
const acc: Record<string, UIDLPropDefinition> = {}
for (const prop of Object.keys(safeInput.propDefinitions)) {
const propValue = (safeInput.propDefinitions as Record<string, UIDLPropDefinition>)[prop]
const propName = StringUtils.createStateOrPropStoringValue(prop)
acc[propName] = propValue
}
safeInput.propDefinitions = acc
}

@@ -91,2 +92,22 @@

for (const propKey of Object.keys(result.propDefinitions || {})) {
const prop = result.propDefinitions[propKey]
if (
prop.type === 'element' &&
prop.defaultValue !== undefined &&
typeof prop.defaultValue !== 'object'
) {
throw new ParserError(
`The defaultValue for prop ${propKey} in component ${result.name} is not an object. It should be a UIDLElementNode.`
)
}
if (prop.type === 'element' && prop.defaultValue) {
result.propDefinitions[propKey].defaultValue = parseComponentNode(
prop.defaultValue as unknown as Record<string, unknown>,
result
)
}
}
// other parsers for other sections of the component here

@@ -153,6 +174,7 @@ result.node = parseComponentNode(node, result) as UIDLElementNode

case 'cms-item':
case 'cms-list':
case 'cms-list': {
const {
initialData,
nodes: { success, error, loading },
resource,
} = (node as unknown as UIDLCMSItemNode).content

@@ -189,4 +211,16 @@

return node as unknown as UIDLNode
case 'cms-list-repeater':
if (resource?.params) {
Object.values(resource?.params || {}).forEach((param) => {
if (
param.type === 'dynamic' &&
(param.content.referenceType === 'state' || param.content.referenceType === 'prop')
) {
param.content.id = StringUtils.createStateOrPropStoringValue(param.content.id)
}
})
}
return node as unknown as UIDLCMSListNode | UIDLCMSItemNode
}
case 'cms-list-repeater': {
const {

@@ -210,3 +244,52 @@ nodes: { list, empty },

return node as unknown as UIDLNode
return node as unknown as UIDLCMSListRepeaterNode
}
case 'cms-mixed-type': {
const {
nodes: { fallback, error },
dependency,
attrs,
mappings,
} = (node as unknown as UIDLCMSMixedTypeNode).content
if (attrs) {
const nodeAttrs = attrs as Record<string, unknown>
for (const attrKey of Object.keys(nodeAttrs)) {
const attrValue = nodeAttrs[attrKey] as Record<string, unknown>
if ('type' in attrValue && attrValue.type === 'element') {
nodeAttrs[attrKey] = parseComponentNode(attrValue, component)
}
}
;(node.content as UIDLCMSMixedTypeNode['content']).attrs =
UIDLUtils.transformAttributesAssignmentsToJson(
nodeAttrs,
dependency && (dependency as UIDLDependency)?.type === 'local'
)
}
if (fallback) {
;(node as unknown as UIDLCMSMixedTypeNode).content.nodes.fallback = parseComponentNode(
fallback as unknown as Record<string, unknown>,
component
) as UIDLElementNode
}
if (error) {
;(node as unknown as UIDLCMSMixedTypeNode).content.nodes.error = parseComponentNode(
error as unknown as Record<string, unknown>,
component
) as UIDLElementNode
}
Object.keys(mappings).forEach((mapping) => {
;(node.content as unknown as UIDLCMSMixedTypeNode['content']).mappings[mapping] =
parseComponentNode(
mappings[mapping] as unknown as Record<string, unknown>,
component
) as UIDLElementNode
})
return node as unknown as UIDLCMSMixedTypeNode
}
case 'element':

@@ -246,2 +329,22 @@ const elementContent = node.content as Record<string, unknown>

if (elementContent.events) {
Object.values(elementContent.events).forEach(
(eventHandler: UIDLEventHandlerStatement[]) => {
eventHandler.forEach((eventStatement) => {
if (eventStatement.type === 'stateChange') {
eventStatement.modifies = StringUtils.createStateOrPropStoringValue(
eventStatement.modifies
)
}
if (eventStatement.type === 'propCall') {
eventStatement.calls = StringUtils.createStateOrPropStoringValue(
eventStatement.calls
)
}
})
}
)
}
if (elementContent.style) {

@@ -254,3 +357,3 @@ elementContent.style = UIDLUtils.transformStylesAssignmentsToJson(

if (elementContent.attrs) {
elementContent.attrs = UIDLUtils.transformAttributesAssignmentsToJson(
const attrs = UIDLUtils.transformAttributesAssignmentsToJson(
elementContent.attrs as Record<string, unknown>,

@@ -260,2 +363,16 @@ 'dependency' in elementContent &&

)
for (const attrKey of Object.keys(attrs)) {
const attrValue = attrs[attrKey]
if (attrValue.type === 'element') {
const parsedNamedSlot = parseComponentNode(
attrValue as unknown as Record<string, unknown>,
component
)
attrs[attrKey] = parsedNamedSlot as UIDLElementNode
}
}
elementContent.attrs = attrs
}

@@ -287,2 +404,9 @@

}
if (type === 'section' && typeof content.section === 'string') {
content.section = {
type: 'static',
content: content.section,
}
}
}

@@ -317,2 +441,11 @@

if (reference.type === 'dynamic' && conditionalNode.content.reference.type === 'dynamic') {
conditionalNode.content.reference.content = {
referenceType: reference.content.referenceType,
id: StringUtils.createStateOrPropStoringValue(
conditionalNode.content.reference.content.id
),
}
}
return conditionalNode

@@ -337,3 +470,2 @@

const slotNode = node as unknown as UIDLSlotNode
if (slotNode.content.fallback) {

@@ -340,0 +472,0 @@ slotNode.content.fallback = parseComponentNode(

@@ -41,2 +41,3 @@ import {

const uidl = rootComponentUIDLDecoder.runWithException(cleanedUIDL)
return { valid: true, errorMsg: '', componentUIDL: uidl }

@@ -43,0 +44,0 @@ } catch (e) {

@@ -124,2 +124,15 @@ import { UIDLUtils } from '@teleporthq/teleport-shared'

if (node.type === 'cms-item' || node.type === 'cms-list') {
Object.values(node.content?.resource?.params || {}).forEach((param) => {
if (
param.type === 'dynamic' &&
(param.content.referenceType === 'state' || param.content.referenceType === 'prop')
) {
param.content.referenceType === 'prop'
? usedPropKeys.push(param.content.id)
: usedStateKeys.push(param.content.id)
}
})
}
if (node.type === 'element') {

@@ -151,3 +164,9 @@ Object.keys(node.content?.events || {}).forEach((eventKey) => {

const referencedProp = styleRef.content.content.content.id
if (!dynamicPathExistsInDefinitions(referencedProp, propKeys)) {
if (
!dynamicPathExistsInDefinitions(
referencedProp,
input.propDefinitions as ComponentUIDL['propDefinitions'],
'prop'
)
) {
const errorMsg = `"${referencedProp}" is used but not defined. Please add it in propDefinitions ${input.name}`

@@ -182,3 +201,9 @@ errors.push(errorMsg)

if (node.type === 'dynamic' && node.content.referenceType === 'prop') {
if (!dynamicPathExistsInDefinitions(node.content.id, propKeys)) {
if (
!dynamicPathExistsInDefinitions(
node.content.id,
input.propDefinitions as ComponentUIDL['propDefinitions'],
'prop'
)
) {
const errorMsg = `\n "${node.content.id}" is used but not defined in ${

@@ -198,3 +223,9 @@ input.name

if (node.type === 'dynamic' && node.content.referenceType === 'state') {
if (!dynamicPathExistsInDefinitions(node.content.id, stateKeys)) {
if (
!dynamicPathExistsInDefinitions(
node.content.id,
input.stateDefinitions as ComponentUIDL['stateDefinitions'],
'state'
)
) {
console.warn(

@@ -212,3 +243,9 @@ `\n"${node.content.id}" is used but not defined. Please add it in stateDefinitions`

if (node.type === 'import') {
if (!dynamicPathExistsInDefinitions(node.content.id, importKeys)) {
if (
!dynamicPathExistsInDefinitions(
node.content.id,
input.importDefinitions as ComponentUIDL['importDefinitions'],
'import'
)
) {
const errorMsg = `\n"${node.content.id}" is used but not defined. Please add it in importDefinitions`

@@ -246,12 +283,36 @@ errors.push(errorMsg)

const dynamicPathExistsInDefinitions = (path: string, defKeys: string[]) => {
if (!path.includes('.')) {
// prop/state is a scalar value, not a dot notation
return defKeys.includes(path)
const dynamicPathExistsInDefinitions = (
path: string,
definitions: Record<string, unknown> = {},
type: 'prop' | 'state' | 'import'
) => {
if (!path) {
return false
}
// TODO: Expand validation logic to check if the path exists on the prop/state definition
// ex: if prop reference is `user.name`, we should check that prop type is object and has a valid field name
const rootIdentifier = path.split('.')[0]
return defKeys.includes(rootIdentifier)
// Extract the keys from the path string considering both dot and bracket notation
const pathKeys = path.split(/\.|\[\s*['"]?(.+?)['"]?\s*\]/).filter(Boolean)
// Get definition values of prop/state/import definitions
let obj = Object.keys(definitions).reduce((acc, key) => {
acc[key] =
type === 'import'
? definitions[key]
: (definitions[key] as Record<string, unknown>).defaultValue
return acc
}, {} as Record<string, unknown>)
for (const key of pathKeys) {
// Check if the key exists in the current object
// NOTE: using 'key in obj' instead of 'obj[key]' is important to avoid returning 'false' when path exists, but value is empty string/undefined/null
if (!(key in obj)) {
return false
}
// Move to the next nested object
obj = obj[key] as Record<string, unknown>
}
return true
}

@@ -258,0 +319,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc