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
4
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.27.3 to 0.27.4-alpha.0

228

__tests__/validator/project-sample.json

@@ -141,3 +141,4 @@ {

}
},{
},
{
"type": "conditional",

@@ -335,3 +336,7 @@ "content": {

"type": "static",
"content": ["angular", "react", "vue"]
"content": [
"angular",
"react",
"vue"
]
}

@@ -372,6 +377,8 @@ }

"elementType": "text",
"children": [{
"type": "static",
"content": "Now you see me!"
}]
"children": [
{
"type": "static",
"content": "Now you see me!"
}
]
}

@@ -391,18 +398,20 @@ }

},
"children": [{
"type": "element",
"content": {
"elementType": "source",
"attrs": {
"type": {
"type": "static",
"content": "video/mp4"
},
"url": {
"type": "static",
"content": "https://www.quirksmode.org/html5/videos/big_buck_bunny.mp4"
"children": [
{
"type": "element",
"content": {
"elementType": "source",
"attrs": {
"type": {
"type": "static",
"content": "video/mp4"
},
"url": {
"type": "static",
"content": "https://www.quirksmode.org/html5/videos/big_buck_bunny.mp4"
}
}
}
}
}]
]
}

@@ -473,9 +482,11 @@ },

"elementType": "text",
"children": [{
"type": "dynamic",
"content": {
"referenceType": "prop",
"id": "title"
"children": [
{
"type": "dynamic",
"content": {
"referenceType": "prop",
"id": "title"
}
}
}]
]
}

@@ -487,35 +498,38 @@ },

"elementType": "button",
"children": [{
"type": "conditional",
"content": {
"node": {
"type": "static",
"content": "Hide me"
},
"value": true,
"reference": {
"type": "dynamic",
"content": {
"referenceType": "state",
"id": "isExpanded"
"children": [
{
"type": "conditional",
"content": {
"node": {
"type": "static",
"content": "Hide me"
},
"value": true,
"reference": {
"type": "dynamic",
"content": {
"referenceType": "state",
"id": "isExpanded"
}
}
}
}
},{
"type": "conditional",
"content": {
"node": {
"type": "static",
"content": "Show me"
},
"value": false,
"reference": {
"type": "dynamic",
"content": {
"referenceType": "state",
"id": "isExpanded"
},
{
"type": "conditional",
"content": {
"node": {
"type": "static",
"content": "Show me"
},
"value": false,
"reference": {
"type": "dynamic",
"content": {
"referenceType": "state",
"id": "isExpanded"
}
}
}
}
}],
],
"events": {

@@ -539,9 +553,11 @@ "click": [

"elementType": "text",
"children": [{
"type": "dynamic",
"content": {
"referenceType": "prop",
"id": "text"
"children": [
{
"type": "dynamic",
"content": {
"referenceType": "prop",
"id": "text"
}
}
}]
]
}

@@ -581,12 +597,16 @@ },

"name": "openmodal",
"children": [{
"type": "static",
"content": "Show Popup"
}],
"children": [
{
"type": "static",
"content": "Show Popup"
}
],
"events": {
"click": [{
"type": "stateChange",
"modifies": "isOpen",
"newState": true
}]
"click": [
{
"type": "stateChange",
"modifies": "isOpen",
"newState": true
}
]
}

@@ -608,7 +628,9 @@ }

"events": {
"onClose": [{
"type": "stateChange",
"modifies": "isOpen",
"newState": false
}]
"onClose": [
{
"type": "stateChange",
"modifies": "isOpen",
"newState": false
}
]
}

@@ -653,29 +675,37 @@ }

"elementType": "container",
"children": [{
"type": "dynamic",
"content": {
"referenceType": "prop",
"id": "message"
}
},{
"type": "element",
"content": {
"elementType": "button",
"name": "close",
"children": [{
"type": "static",
"content": "Close me"
}],
"events": {
"click": [{
"type": "propCall",
"calls": "onClose"
},{
"type": "stateChange",
"modifies": "fakeState",
"newState": false
}]
"children": [
{
"type": "dynamic",
"content": {
"referenceType": "prop",
"id": "message"
}
},
{
"type": "element",
"content": {
"elementType": "button",
"name": "close",
"children": [
{
"type": "static",
"content": "Close me"
}
],
"events": {
"click": [
{
"type": "propCall",
"calls": "onClose"
},
{
"type": "stateChange",
"modifies": "fakeState",
"newState": false
}
]
}
}
}
}]
]
}

@@ -685,2 +715,2 @@ }

}
}
}
import { Decoder } from '@mojotech/json-type-validation';
import { VUIDLGlobalProjectValues, WebManifest, VProjectUIDL } from '@teleporthq/teleport-types';
import { VUIDLGlobalProjectValues, WebManifest, VProjectUIDL, ContextsUIDL, ContextUIDLItem, ResourcesUIDL, ResourceItemUIDL } from '@teleporthq/teleport-types';
export declare const webManifestDecoder: Decoder<WebManifest>;
export declare const globalProjectValuesDecoder: Decoder<VUIDLGlobalProjectValues>;
export declare const contextItemDecoder: Decoder<ContextUIDLItem>;
export declare const contextsDecoder: Decoder<ContextsUIDL>;
export declare const projectResourceItemDecoder: Decoder<ResourceItemUIDL>;
export declare const resourcesDecoder: Decoder<ResourcesUIDL>;
export declare const projectUIDLDecoder: Decoder<VProjectUIDL>;
//# sourceMappingURL=project-decoder.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.projectUIDLDecoder = exports.globalProjectValuesDecoder = exports.webManifestDecoder = void 0;
exports.projectUIDLDecoder = exports.resourcesDecoder = exports.projectResourceItemDecoder = exports.contextsDecoder = exports.contextItemDecoder = exports.globalProjectValuesDecoder = exports.webManifestDecoder = void 0;
var json_type_validation_1 = require("@mojotech/json-type-validation");

@@ -27,2 +27,3 @@ var utils_1 = require("./utils");

})),
env: (0, json_type_validation_1.optional)((0, json_type_validation_1.dict)((0, json_type_validation_1.string)())),
meta: (0, json_type_validation_1.array)((0, json_type_validation_1.dict)((0, json_type_validation_1.string)())),

@@ -33,2 +34,18 @@ assets: (0, json_type_validation_1.array)(utils_1.globalAssetsDecoder),

});
exports.contextItemDecoder = (0, json_type_validation_1.object)({
name: (0, json_type_validation_1.string)(),
fileName: (0, json_type_validation_1.optional)((0, json_type_validation_1.string)()),
});
exports.contextsDecoder = (0, json_type_validation_1.object)({
rootFolder: (0, json_type_validation_1.optional)((0, json_type_validation_1.string)()),
items: (0, json_type_validation_1.dict)((0, json_type_validation_1.optional)(exports.contextItemDecoder)),
});
exports.projectResourceItemDecoder = (0, json_type_validation_1.intersection)(utils_1.resourceDecoder, (0, json_type_validation_1.object)({
id: (0, json_type_validation_1.string)(),
name: (0, json_type_validation_1.string)(),
}));
exports.resourcesDecoder = (0, json_type_validation_1.object)({
rootFolder: (0, json_type_validation_1.optional)((0, json_type_validation_1.string)()),
items: (0, json_type_validation_1.dict)((0, json_type_validation_1.optional)(exports.projectResourceItemDecoder)),
});
exports.projectUIDLDecoder = (0, json_type_validation_1.object)({

@@ -39,3 +56,5 @@ name: (0, json_type_validation_1.string)(),

components: (0, json_type_validation_1.optional)((0, json_type_validation_1.dict)(component_decoder_1.componentUIDLDecoder)),
contexts: (0, json_type_validation_1.optional)(exports.contextsDecoder),
resources: (0, json_type_validation_1.optional)(exports.resourcesDecoder),
});
//# sourceMappingURL=project-decoder.js.map
import { Decoder } from '@mojotech/json-type-validation';
import { UIDLStaticValue, ReferenceType, UIDLDynamicReference, UIDLPropDefinition, UIDLStateDefinition, UIDLStateValueDetails, UIDLPageOptions, UIDLComponentOutputOptions, UIDLDependency, UIDLStyleDefinitions, UIDLStyleValue, UIDLAttributeValue, UIDLEventHandlerStatement, UIDLNavLinkNode, 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 } from '@teleporthq/teleport-types';
import { UIDLStaticValue, ReferenceType, UIDLDynamicReference, UIDLPropDefinition, UIDLStateDefinition, UIDLStateValueDetails, UIDLPageOptions, UIDLComponentOutputOptions, UIDLDependency, UIDLStyleDefinitions, UIDLStyleValue, UIDLAttributeValue, UIDLEventHandlerStatement, UIDLNavLinkNode, 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, Resource, InitialPropsData, InitialPathsData, UIDLExpressionValue, UIDLDynamicLinkNode } from '@teleporthq/teleport-types';
export declare const referenceTypeDecoder: Decoder<ReferenceType>;
export declare const dynamicValueDecoder: Decoder<UIDLDynamicReference>;
export declare const expressionValueDecoder: Decoder<UIDLExpressionValue>;
export declare const staticValueDecoder: Decoder<UIDLStaticValue>;
export declare const rawValueDecoder: Decoder<UIDLRawValue>;
export declare const resourceDecoder: Decoder<Resource>;
export declare const initialPropsDecoder: Decoder<InitialPropsData>;
export declare const initialPathsDecoder: Decoder<InitialPathsData>;
export declare const styleSetMediaConditionDecoder: Decoder<VUIDLStyleSetMediaCondition>;

@@ -13,3 +17,2 @@ export declare const styleSetStateConditionDecoder: Decoder<VUIDLStyleSetStateCondition>;

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

@@ -25,5 +28,7 @@ export declare const baseAssetDecoder: Decoder<UIDLAssetBase>;

export declare const componentSeoDecoder: Decoder<VUIDLComponentSEO>;
export declare const stateValueDetailsDecoder: Decoder<UIDLStateValueDetails>;
export declare const propDefinitionsDecoder: Decoder<UIDLPropDefinition>;
export declare const pageOptionsPaginationDecoder: Decoder<PagePaginationOptions>;
export declare const stateDefinitionsDecoder: Decoder<UIDLStateDefinition>;
export declare const pageOptionsDecoder: Decoder<UIDLPageOptions>;
export declare const stateValueDetailsDecoder: Decoder<UIDLStateValueDetails>;
export declare const outputOptionsDecoder: Decoder<UIDLComponentOutputOptions>;

@@ -43,2 +48,3 @@ export declare const peerDependencyDecoder: Decoder<UIDLPeerDependency>;

export declare const urlLinkNodeDecoder: Decoder<VUIDLURLLinkNode>;
export declare const dynamicLinkDecoder: Decoder<UIDLDynamicLinkNode>;
export declare const sectionLinkNodeDecoder: Decoder<VUIDLSectionLinkNode>;

@@ -63,3 +69,5 @@ export declare const navLinkNodeDecoder: Decoder<UIDLNavLinkNode>;

export declare const elementNodeDecoder: Decoder<VUIDLElementNode>;
export declare const cmsItemNodeDecoder: Decoder<VCMSItemUIDLElementNode>;
export declare const cmsListNodeDecoder: Decoder<VCMSListUIDLElementNode>;
export declare const uidlNodeDecoder: Decoder<VUIDLNode>;
//# sourceMappingURL=utils.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
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.urlLinkNodeDecoder = exports.stateChangeEventDecoder = exports.propCallEventDecoder = exports.eventHandlerStatementDecoder = exports.styleDefinitionsDecoder = exports.styleValueDecoder = exports.uidlComponentStyleReference = exports.attributeValueDecoder = exports.importReferenceDecoder = exports.dependencyDecoder = exports.localDependencyDecoder = exports.externaldependencyDecoder = exports.peerDependencyDecoder = exports.outputOptionsDecoder = exports.stateDefinitionsDecoder = 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.pageOptionsDecoder = exports.stateOrPropDefinitionDecoder = exports.styleSetDefinitionDecoder = exports.tokenReferenceDecoder = exports.projectStyleConditionsDecoder = exports.styleSetStateConditionDecoder = exports.styleSetMediaConditionDecoder = exports.rawValueDecoder = exports.staticValueDecoder = exports.dynamicValueDecoder = exports.referenceTypeDecoder = void 0;
exports.uidlNodeDecoder = exports.elementNodeDecoder = exports.conditionalNodeDecoder = exports.repeatNodeDecoder = exports.slotNodeDecoder = exports.elementDecoder = exports.designTokensDecoder = exports.elementComponentReferencedStyle = void 0;
exports.elementStateDecoder = exports.uidlLinkNodeDecoder = exports.phoneLinkNodeDecoder = exports.uidlMailLinkNodeDecoder = exports.navLinkNodeDecoder = exports.sectionLinkNodeDecoder = exports.dynamicLinkDecoder = exports.urlLinkNodeDecoder = exports.stateChangeEventDecoder = exports.propCallEventDecoder = exports.eventHandlerStatementDecoder = exports.styleDefinitionsDecoder = exports.styleValueDecoder = exports.uidlComponentStyleReference = exports.attributeValueDecoder = exports.importReferenceDecoder = exports.dependencyDecoder = exports.localDependencyDecoder = exports.externaldependencyDecoder = exports.peerDependencyDecoder = exports.outputOptionsDecoder = exports.stateValueDetailsDecoder = exports.pageOptionsDecoder = exports.stateDefinitionsDecoder = exports.pageOptionsPaginationDecoder = exports.propDefinitionsDecoder = 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.initialPathsDecoder = exports.initialPropsDecoder = exports.resourceDecoder = exports.rawValueDecoder = exports.staticValueDecoder = exports.expressionValueDecoder = exports.dynamicValueDecoder = exports.referenceTypeDecoder = void 0;
exports.uidlNodeDecoder = exports.cmsListNodeDecoder = exports.cmsItemNodeDecoder = 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 = 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'));
var resourceValueDecoder = (0, json_type_validation_1.union)((0, json_type_validation_1.object)({ type: (0, json_type_validation_1.constant)('static'), value: (0, json_type_validation_1.string)() }), (0, json_type_validation_1.object)({ type: (0, json_type_validation_1.constant)('env'), value: (0, json_type_validation_1.string)(), fallback: (0, json_type_validation_1.optional)((0, json_type_validation_1.string)()) }));
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)('ctx'));
exports.dynamicValueDecoder = (0, json_type_validation_1.object)({

@@ -13,5 +14,11 @@ type: (0, json_type_validation_1.constant)('dynamic'),

referenceType: exports.referenceTypeDecoder,
path: (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)(),
ctxId: (0, json_type_validation_1.optional)((0, json_type_validation_1.string)()),
}),
});
exports.expressionValueDecoder = (0, json_type_validation_1.object)({
type: (0, json_type_validation_1.constant)('expr'),
content: (0, json_type_validation_1.string)(),
});
exports.staticValueDecoder = (0, json_type_validation_1.object)({

@@ -25,2 +32,29 @@ type: (0, json_type_validation_1.constant)('static'),

});
var resourceUrlParamsDecoder = (0, json_type_validation_1.dict)((0, json_type_validation_1.union)(exports.staticValueDecoder, exports.dynamicValueDecoder, exports.expressionValueDecoder, (0, json_type_validation_1.array)((0, json_type_validation_1.union)(exports.staticValueDecoder, exports.dynamicValueDecoder))));
exports.resourceDecoder = (0, json_type_validation_1.object)({
baseUrl: resourceValueDecoder,
urlParams: (0, json_type_validation_1.optional)((0, json_type_validation_1.union)(resourceUrlParamsDecoder, (0, json_type_validation_1.dict)(resourceUrlParamsDecoder), (0, json_type_validation_1.unknownJson)())),
authToken: (0, json_type_validation_1.optional)(resourceValueDecoder),
route: (0, json_type_validation_1.optional)(resourceValueDecoder),
});
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)())),
}),
resourceMappers: (0, json_type_validation_1.optional)((0, json_type_validation_1.array)((0, json_type_validation_1.object)({
name: (0, json_type_validation_1.string)(),
resource: (0, json_type_validation_1.lazy)(function () { return exports.externaldependencyDecoder; }),
}))),
resource: exports.resourceDecoder,
});
exports.initialPathsDecoder = (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)())),
}),
resource: exports.resourceDecoder,
});
exports.styleSetMediaConditionDecoder = (0, json_type_validation_1.object)({

@@ -55,11 +89,7 @@ type: (0, json_type_validation_1.constant)('screen-size'),

content: (0, json_type_validation_1.dict)((0, json_type_validation_1.union)(exports.staticValueDecoder, (0, json_type_validation_1.string)(), (0, json_type_validation_1.number)(), exports.tokenReferenceDecoder)),
className: (0, json_type_validation_1.optional)((0, json_type_validation_1.string)()),
subselectors: (0, json_type_validation_1.optional)((0, json_type_validation_1.string)()),
});
// 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.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()),
fallback: (0, json_type_validation_1.optional)((0, json_type_validation_1.boolean)()),
});
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; }));

@@ -108,11 +138,6 @@ exports.baseAssetDecoder = (0, json_type_validation_1.object)({

exports.componentSeoDecoder = (0, json_type_validation_1.object)({
title: (0, json_type_validation_1.optional)((0, json_type_validation_1.string)()),
metaTags: (0, json_type_validation_1.optional)((0, json_type_validation_1.array)((0, json_type_validation_1.dict)((0, json_type_validation_1.string)()))),
title: (0, json_type_validation_1.optional)((0, json_type_validation_1.union)((0, json_type_validation_1.string)(), exports.staticValueDecoder, exports.dynamicValueDecoder)),
metaTags: (0, json_type_validation_1.optional)((0, json_type_validation_1.array)((0, json_type_validation_1.dict)((0, json_type_validation_1.union)((0, json_type_validation_1.string)(), exports.staticValueDecoder, exports.dynamicValueDecoder)))),
assets: (0, json_type_validation_1.optional)((0, json_type_validation_1.array)(exports.globalAssetsDecoder)),
});
exports.stateValueDetailsDecoder = (0, json_type_validation_1.object)({
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)()),
pageOptions: (0, json_type_validation_1.optional)(exports.pageOptionsDecoder),
seo: (0, json_type_validation_1.optional)(exports.componentSeoDecoder),
});
exports.propDefinitionsDecoder = (0, json_type_validation_1.object)({

@@ -123,2 +148,7 @@ 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')),

});
exports.pageOptionsPaginationDecoder = (0, json_type_validation_1.object)({
attribute: (0, json_type_validation_1.string)(),
pageSize: (0, json_type_validation_1.number)(),
totalCountPath: (0, json_type_validation_1.optional)((0, json_type_validation_1.array)((0, json_type_validation_1.string)())),
});
exports.stateDefinitionsDecoder = (0, json_type_validation_1.object)({

@@ -128,2 +158,21 @@ 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')),

});
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()),
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),
initialPropsData: (0, json_type_validation_1.optional)(exports.initialPropsDecoder),
initialPathsData: (0, json_type_validation_1.optional)(exports.initialPathsDecoder),
propDefinitions: (0, json_type_validation_1.optional)((0, json_type_validation_1.dict)(exports.propDefinitionsDecoder)),
stateDefinitions: (0, json_type_validation_1.optional)((0, json_type_validation_1.dict)(exports.stateDefinitionsDecoder)),
});
// @ts-ignore
exports.stateValueDetailsDecoder = (0, json_type_validation_1.object)({
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)()),
pageOptions: (0, json_type_validation_1.optional)(exports.pageOptionsDecoder),
seo: (0, json_type_validation_1.optional)(exports.componentSeoDecoder),
});
exports.outputOptionsDecoder = (0, json_type_validation_1.object)({

@@ -151,2 +200,3 @@ componentClassName: (0, json_type_validation_1.optional)(isValidComponentName()),

useAsReference: (0, json_type_validation_1.optional)((0, json_type_validation_1.boolean)()),
importAlias: (0, json_type_validation_1.optional)((0, json_type_validation_1.string)()),
needsWindowObject: (0, json_type_validation_1.optional)((0, json_type_validation_1.boolean)()),

@@ -162,2 +212,3 @@ })),

importJustPath: (0, json_type_validation_1.optional)((0, json_type_validation_1.boolean)()),
importAlias: (0, json_type_validation_1.optional)((0, json_type_validation_1.string)()),
})),

@@ -197,2 +248,10 @@ });

});
exports.dynamicLinkDecoder = (0, json_type_validation_1.object)({
type: (0, json_type_validation_1.constant)('dynamic'),
content: (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)())),
id: (0, json_type_validation_1.string)(),
}),
});
exports.sectionLinkNodeDecoder = (0, json_type_validation_1.object)({

@@ -222,3 +281,3 @@ type: (0, json_type_validation_1.constant)('section'),

});
exports.uidlLinkNodeDecoder = (0, json_type_validation_1.union)(exports.urlLinkNodeDecoder, exports.sectionLinkNodeDecoder, exports.navLinkNodeDecoder, exports.uidlMailLinkNodeDecoder, exports.phoneLinkNodeDecoder);
exports.uidlLinkNodeDecoder = (0, json_type_validation_1.union)(exports.urlLinkNodeDecoder, exports.sectionLinkNodeDecoder, exports.navLinkNodeDecoder, exports.uidlMailLinkNodeDecoder, exports.phoneLinkNodeDecoder, exports.dynamicLinkDecoder);
exports.elementStateDecoder = (0, json_type_validation_1.oneOf)((0, json_type_validation_1.constant)('hover'), (0, json_type_validation_1.constant)('active'), (0, json_type_validation_1.constant)('focus'), (0, json_type_validation_1.constant)('focus-within'), (0, json_type_validation_1.constant)('focus-visible'), (0, json_type_validation_1.constant)('disabled'), (0, json_type_validation_1.constant)('visited'), (0, json_type_validation_1.constant)('checked'), (0, json_type_validation_1.constant)('link'));

@@ -256,3 +315,3 @@ exports.elementStyleWithStateConditionDecoder = (0, json_type_validation_1.object)({

content: (0, json_type_validation_1.object)({
referenceType: (0, json_type_validation_1.union)((0, json_type_validation_1.constant)('prop'), (0, json_type_validation_1.constant)('comp')),
referenceType: (0, json_type_validation_1.union)((0, json_type_validation_1.constant)('prop'), (0, json_type_validation_1.constant)('comp'), (0, json_type_validation_1.constant)('ctx')),
id: (0, json_type_validation_1.string)(),

@@ -274,2 +333,3 @@ }),

key: (0, json_type_validation_1.optional)((0, json_type_validation_1.string)()),
ctxId: (0, json_type_validation_1.optional)((0, json_type_validation_1.string)()),
dependency: (0, json_type_validation_1.optional)(exports.dependencyDecoder),

@@ -280,3 +340,3 @@ 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)()))),

abilities: (0, json_type_validation_1.optional)((0, json_type_validation_1.object)({
link: (0, json_type_validation_1.optional)(exports.uidlLinkNodeDecoder),
link: (0, json_type_validation_1.optional)((0, json_type_validation_1.anyJson)()),
})),

@@ -324,3 +384,41 @@ children: (0, json_type_validation_1.optional)((0, json_type_validation_1.array)((0, json_type_validation_1.lazy)(function () { return exports.uidlNodeDecoder; }))),

});
exports.uidlNodeDecoder = (0, json_type_validation_1.union)(exports.elementNodeDecoder, exports.dynamicValueDecoder, exports.staticValueDecoder, exports.rawValueDecoder, exports.conditionalNodeDecoder, exports.repeatNodeDecoder, exports.slotNodeDecoder, (0, json_type_validation_1.string)());
exports.cmsItemNodeDecoder = (0, json_type_validation_1.object)({
type: (0, json_type_validation_1.constant)('cms-item'),
content: (0, json_type_validation_1.object)({
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; })),
}),
resourceId: (0, json_type_validation_1.optional)((0, json_type_validation_1.string)()),
statePersistanceName: (0, json_type_validation_1.optional)((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)())),
resourceMappers: (0, json_type_validation_1.optional)((0, json_type_validation_1.array)((0, json_type_validation_1.object)({
name: (0, json_type_validation_1.string)(),
resource: exports.externaldependencyDecoder,
}))),
}),
});
exports.cmsListNodeDecoder = (0, json_type_validation_1.object)({
type: (0, json_type_validation_1.constant)('cms-list'),
content: (0, json_type_validation_1.object)({
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; })),
}),
resourceId: (0, json_type_validation_1.optional)((0, json_type_validation_1.string)()),
statePersistanceName: (0, json_type_validation_1.optional)((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)())),
loopItemsReference: (0, json_type_validation_1.optional)(exports.attributeValueDecoder),
resourceMappers: (0, json_type_validation_1.optional)((0, json_type_validation_1.array)((0, json_type_validation_1.object)({
name: (0, json_type_validation_1.string)(),
resource: exports.externaldependencyDecoder,
}))),
}),
});
exports.uidlNodeDecoder = (0, json_type_validation_1.union)(exports.elementNodeDecoder, exports.cmsItemNodeDecoder, exports.cmsListNodeDecoder, exports.dynamicValueDecoder, exports.staticValueDecoder, exports.rawValueDecoder, exports.conditionalNodeDecoder, (0, json_type_validation_1.union)(exports.repeatNodeDecoder, exports.slotNodeDecoder, (0, json_type_validation_1.string)()));
//# sourceMappingURL=utils.js.map

@@ -20,5 +20,18 @@ "use strict";

var safeInput = params.noClone ? input : teleport_shared_1.UIDLUtils.cloneObject(input);
if (safeInput === null || safeInput === void 0 ? void 0 : safeInput.propDefinitions) {
safeInput.propDefinitions = Object.keys(safeInput.propDefinitions).reduce(function (acc, prop) {
var propName = teleport_shared_1.StringUtils.createStateOrPropStoringValue(prop);
acc[propName] = safeInput.propDefinitions[prop];
return acc;
}, {});
}
if (safeInput === null || safeInput === void 0 ? void 0 : safeInput.stateDefinitions) {
safeInput.stateDefinitions = Object.keys(safeInput.stateDefinitions).reduce(function (acc, state) {
var stateName = teleport_shared_1.StringUtils.createStateOrPropStoringValue(state);
acc[stateName] = safeInput.stateDefinitions[state];
return acc;
}, {});
}
if (safeInput === null || safeInput === void 0 ? void 0 : safeInput.styleSetDefinitions) {
var styleSetDefinitions = safeInput.styleSetDefinitions;
Object.values(styleSetDefinitions).forEach(function (styleRef) {
Object.values(safeInput === null || safeInput === void 0 ? void 0 : safeInput.styleSetDefinitions).forEach(function (styleRef) {
var _a = styleRef.conditions, conditions = _a === void 0 ? [] : _a;

@@ -41,3 +54,3 @@ styleRef.content = teleport_shared_1.UIDLUtils.transformStylesAssignmentsToJson(styleRef.content);

// other parsers for other sections of the component here
result.node = parseComponentNode(node);
result.node = parseComponentNode(node, result);
return result;

@@ -79,12 +92,61 @@ };

exports.parseProjectJSON = parseProjectJSON;
var parseComponentNode = function (node) {
var _a, _b;
var parseComponentNode = function (node, component) {
var _a, _b, _c, _d, _e;
switch (node.type) {
case 'cms-item':
case 'cms-list':
case 'element':
var elementContent = node.content;
if (node.type === 'cms-item') {
var _f = node.content, _g = _f.nodes, success = _g.success, error = _g.error, loading = _g.loading, statePersistanceName = _f.statePersistanceName;
if (success) {
success.content.attrs = teleport_shared_1.UIDLUtils.transformAttributesAssignmentsToJson(((_a = success === null || success === void 0 ? void 0 : success.content) === null || _a === void 0 ? void 0 : _a.attrs) || {});
}
if (error) {
error.content.attrs = teleport_shared_1.UIDLUtils.transformAttributesAssignmentsToJson(((_b = error === null || error === void 0 ? void 0 : error.content) === null || _b === void 0 ? void 0 : _b.attrs) || {});
component.stateDefinitions["".concat(statePersistanceName, "Error")] = {
type: 'boolean',
defaultValue: false,
};
}
if (loading) {
component.stateDefinitions["".concat(statePersistanceName, "Loading")] = {
type: 'boolean',
defaultValue: false,
};
}
}
if (node.type === 'cms-list' && elementContent.hasOwnProperty('loopItemsReference')) {
var _h = node.content, loopItemsReference = _h.loopItemsReference, statePersistanceName = _h.statePersistanceName, _j = _h.nodes, success = _j.success, error = _j.error, loading = _j.loading;
var identifier = (loopItemsReference === null || loopItemsReference === void 0 ? void 0 : loopItemsReference.type) === 'dynamic' &&
loopItemsReference.content.referenceType === 'prop'
? 'propDefinitions'
: 'stateDefinitions';
if (success) {
success.content.attrs = teleport_shared_1.UIDLUtils.transformAttributesAssignmentsToJson(((_c = success === null || success === void 0 ? void 0 : success.content) === null || _c === void 0 ? void 0 : _c.attrs) || {});
}
if (error) {
error.content.attrs = teleport_shared_1.UIDLUtils.transformAttributesAssignmentsToJson(((_d = error === null || error === void 0 ? void 0 : error.content) === null || _d === void 0 ? void 0 : _d.attrs) || {});
component[identifier]["".concat(statePersistanceName, "Error")] = {
type: 'boolean',
defaultValue: false,
};
}
if (loading) {
component[identifier]["".concat(statePersistanceName, "Loading")] = {
type: 'boolean',
defaultValue: false,
};
}
if (loopItemsReference &&
(loopItemsReference === null || loopItemsReference === void 0 ? void 0 : loopItemsReference.type) === 'dynamic' &&
['state', 'prop'].includes(loopItemsReference === null || loopItemsReference === void 0 ? void 0 : loopItemsReference.content.referenceType)) {
loopItemsReference.content.id = teleport_shared_1.StringUtils.createStateOrPropStoringValue(loopItemsReference.content.id);
}
}
if (elementContent === null || elementContent === void 0 ? void 0 : elementContent.referencedStyles) {
Object.values(elementContent.referencedStyles).forEach(function (styleRef) {
var content = styleRef.content;
switch (content.mapType) {
switch (styleRef.content.mapType) {
case 'inlined': {
var content = styleRef.content;
content.styles = teleport_shared_1.UIDLUtils.transformStylesAssignmentsToJson(content.styles);

@@ -105,3 +167,3 @@ break;

default: {
throw new teleport_types_1.ParserError("Un-expected mapType passed in referencedStyles - ".concat(content.mapType));
throw new teleport_types_1.ParserError("Un-expected mapType passed in referencedStyles - ".concat(styleRef.content.mapType));
}

@@ -117,9 +179,15 @@ }

}
// @ts-ignore
if ((_a = elementContent.abilities) === null || _a === void 0 ? void 0 : _a.link) {
// @ts-ignore
var _c = (_b = elementContent.abilities) === null || _b === void 0 ? void 0 : _b.link, content = _c.content, type = _c.type;
if ((_e = elementContent === null || elementContent === void 0 ? void 0 : elementContent.abilities) === null || _e === void 0 ? void 0 : _e.hasOwnProperty('link')) {
var _k = elementContent.abilities.link, content = _k.content, type = _k.type;
if (type === 'url' && typeof content.url === 'string') {
content.url = teleport_shared_1.UIDLUtils.transformStringAssignmentToJson(content.url);
}
if (type === 'url' && content.url.type === 'dynamic') {
;
content.url.content = {
referenceType: content.url
.content.referenceType,
id: teleport_shared_1.StringUtils.createStateOrPropStoringValue(content.url.content.id),
};
}
}

@@ -132,3 +200,3 @@ if (Array.isArray(elementContent.children)) {

else {
return parseComponentNode(child);
return parseComponentNode(child, component);
}

@@ -141,3 +209,3 @@ }, []);

var reference = conditionalNode.content.reference;
conditionalNode.content.node = parseComponentNode(conditionalNode.content.node);
conditionalNode.content.node = parseComponentNode(conditionalNode.content.node, component);
if (typeof reference === 'string') {

@@ -150,3 +218,3 @@ conditionalNode.content.reference = teleport_shared_1.UIDLUtils.transformStringAssignmentToJson(reference);

var dataSource = repeatNode.content.dataSource;
repeatNode.content.node = parseComponentNode(repeatNode.content.node);
repeatNode.content.node = parseComponentNode(repeatNode.content.node, component);
if (typeof dataSource === 'string') {

@@ -159,6 +227,11 @@ repeatNode.content.dataSource = teleport_shared_1.UIDLUtils.transformStringAssignmentToJson(dataSource);

if (slotNode.content.fallback) {
slotNode.content.fallback = parseComponentNode(slotNode.content.fallback);
slotNode.content.fallback = parseComponentNode(slotNode.content.fallback, component);
}
return slotNode;
case 'dynamic':
var dyamicNode = node;
if (['state', 'prop'].includes(dyamicNode.content.referenceType)) {
dyamicNode.content.id = teleport_shared_1.StringUtils.createStateOrPropStoringValue(dyamicNode.content.id);
}
return dyamicNode;
case 'static':

@@ -165,0 +238,0 @@ case 'raw':

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

if (!dynamicPathExistsInDefinitions(node.content.id, propKeys)) {
var errorMsg = "\"".concat(node.content.id, "\" is used but not defined. Please add it in propDefinitions ").concat(input.name);
var errorMsg = "\"".concat(node.content.id, "\" is used but not defined. Please add it in propDefinitions \n Used on Node ").concat(JSON.stringify(node.content));
errors.push(errorMsg);

@@ -150,4 +150,3 @@ }

if (!dynamicPathExistsInDefinitions(node.content.id, stateKeys)) {
var errorMsg = "\n\"".concat(node.content.id, "\" is used but not defined. Please add it in stateDefinitions");
errors.push(errorMsg);
console.warn("\n\"".concat(node.content.id, "\" is used but not defined. Please add it in stateDefinitions"));
}

@@ -154,0 +153,0 @@ // for member expression we check the root

import { Decoder } from '@mojotech/json-type-validation';
import { VUIDLGlobalProjectValues, WebManifest, VProjectUIDL } from '@teleporthq/teleport-types';
import { VUIDLGlobalProjectValues, WebManifest, VProjectUIDL, ContextsUIDL, ContextUIDLItem, ResourcesUIDL, ResourceItemUIDL } from '@teleporthq/teleport-types';
export declare const webManifestDecoder: Decoder<WebManifest>;
export declare const globalProjectValuesDecoder: Decoder<VUIDLGlobalProjectValues>;
export declare const contextItemDecoder: Decoder<ContextUIDLItem>;
export declare const contextsDecoder: Decoder<ContextsUIDL>;
export declare const projectResourceItemDecoder: Decoder<ResourceItemUIDL>;
export declare const resourcesDecoder: Decoder<ResourcesUIDL>;
export declare const projectUIDLDecoder: Decoder<VProjectUIDL>;
//# sourceMappingURL=project-decoder.d.ts.map

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

import { object, optional, string, dict, array } from '@mojotech/json-type-validation';
import { globalAssetsDecoder } from './utils';
import { object, optional, string, dict, array, intersection, } from '@mojotech/json-type-validation';
import { globalAssetsDecoder, resourceDecoder } from './utils';
import { componentUIDLDecoder, rootComponentUIDLDecoder } from './component-decoder';

@@ -24,2 +24,3 @@ export var webManifestDecoder = object({

})),
env: optional(dict(string())),
meta: array(dict(string())),

@@ -30,2 +31,18 @@ assets: array(globalAssetsDecoder),

});
export var contextItemDecoder = object({
name: string(),
fileName: optional(string()),
});
export var contextsDecoder = object({
rootFolder: optional(string()),
items: dict(optional(contextItemDecoder)),
});
export var projectResourceItemDecoder = intersection(resourceDecoder, object({
id: string(),
name: string(),
}));
export var resourcesDecoder = object({
rootFolder: optional(string()),
items: dict(optional(projectResourceItemDecoder)),
});
export var projectUIDLDecoder = object({

@@ -36,3 +53,5 @@ name: string(),

components: optional(dict(componentUIDLDecoder)),
contexts: optional(contextsDecoder),
resources: optional(resourcesDecoder),
});
//# sourceMappingURL=project-decoder.js.map
import { Decoder } from '@mojotech/json-type-validation';
import { UIDLStaticValue, ReferenceType, UIDLDynamicReference, UIDLPropDefinition, UIDLStateDefinition, UIDLStateValueDetails, UIDLPageOptions, UIDLComponentOutputOptions, UIDLDependency, UIDLStyleDefinitions, UIDLStyleValue, UIDLAttributeValue, UIDLEventHandlerStatement, UIDLNavLinkNode, 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 } from '@teleporthq/teleport-types';
import { UIDLStaticValue, ReferenceType, UIDLDynamicReference, UIDLPropDefinition, UIDLStateDefinition, UIDLStateValueDetails, UIDLPageOptions, UIDLComponentOutputOptions, UIDLDependency, UIDLStyleDefinitions, UIDLStyleValue, UIDLAttributeValue, UIDLEventHandlerStatement, UIDLNavLinkNode, 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, Resource, InitialPropsData, InitialPathsData, UIDLExpressionValue, UIDLDynamicLinkNode } from '@teleporthq/teleport-types';
export declare const referenceTypeDecoder: Decoder<ReferenceType>;
export declare const dynamicValueDecoder: Decoder<UIDLDynamicReference>;
export declare const expressionValueDecoder: Decoder<UIDLExpressionValue>;
export declare const staticValueDecoder: Decoder<UIDLStaticValue>;
export declare const rawValueDecoder: Decoder<UIDLRawValue>;
export declare const resourceDecoder: Decoder<Resource>;
export declare const initialPropsDecoder: Decoder<InitialPropsData>;
export declare const initialPathsDecoder: Decoder<InitialPathsData>;
export declare const styleSetMediaConditionDecoder: Decoder<VUIDLStyleSetMediaCondition>;

@@ -13,3 +17,2 @@ export declare const styleSetStateConditionDecoder: Decoder<VUIDLStyleSetStateCondition>;

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

@@ -25,5 +28,7 @@ export declare const baseAssetDecoder: Decoder<UIDLAssetBase>;

export declare const componentSeoDecoder: Decoder<VUIDLComponentSEO>;
export declare const stateValueDetailsDecoder: Decoder<UIDLStateValueDetails>;
export declare const propDefinitionsDecoder: Decoder<UIDLPropDefinition>;
export declare const pageOptionsPaginationDecoder: Decoder<PagePaginationOptions>;
export declare const stateDefinitionsDecoder: Decoder<UIDLStateDefinition>;
export declare const pageOptionsDecoder: Decoder<UIDLPageOptions>;
export declare const stateValueDetailsDecoder: Decoder<UIDLStateValueDetails>;
export declare const outputOptionsDecoder: Decoder<UIDLComponentOutputOptions>;

@@ -43,2 +48,3 @@ export declare const peerDependencyDecoder: Decoder<UIDLPeerDependency>;

export declare const urlLinkNodeDecoder: Decoder<VUIDLURLLinkNode>;
export declare const dynamicLinkDecoder: Decoder<UIDLDynamicLinkNode>;
export declare const sectionLinkNodeDecoder: Decoder<VUIDLSectionLinkNode>;

@@ -63,3 +69,5 @@ export declare const navLinkNodeDecoder: Decoder<UIDLNavLinkNode>;

export declare const elementNodeDecoder: Decoder<VUIDLElementNode>;
export declare const cmsItemNodeDecoder: Decoder<VCMSItemUIDLElementNode>;
export declare const cmsListNodeDecoder: Decoder<VCMSListUIDLElementNode>;
export declare const uidlNodeDecoder: Decoder<VUIDLNode>;
//# sourceMappingURL=utils.d.ts.map

@@ -1,5 +0,6 @@

import { object, string, dict, constant, number, optional, union, boolean, array, lazy, oneOf, intersection, withDefault, } from '@mojotech/json-type-validation';
import { object, string, dict, constant, number, optional, union, boolean, array, lazy, oneOf, intersection, unknownJson, 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;
export var referenceTypeDecoder = union(constant('prop'), constant('state'), constant('local'), constant('attr'), constant('children'), constant('token'));
var resourceValueDecoder = union(object({ type: constant('static'), value: string() }), object({ type: constant('env'), value: string(), fallback: optional(string()) }));
export var referenceTypeDecoder = union(constant('prop'), constant('state'), constant('local'), constant('attr'), constant('children'), constant('token'), constant('ctx'));
export var dynamicValueDecoder = object({

@@ -9,5 +10,11 @@ type: constant('dynamic'),

referenceType: referenceTypeDecoder,
path: optional(array(string())),
id: string(),
ctxId: optional(string()),
}),
});
export var expressionValueDecoder = object({
type: constant('expr'),
content: string(),
});
export var staticValueDecoder = object({

@@ -21,2 +28,29 @@ type: constant('static'),

});
var resourceUrlParamsDecoder = dict(union(staticValueDecoder, dynamicValueDecoder, expressionValueDecoder, array(union(staticValueDecoder, dynamicValueDecoder))));
export var resourceDecoder = object({
baseUrl: resourceValueDecoder,
urlParams: optional(union(resourceUrlParamsDecoder, dict(resourceUrlParamsDecoder), unknownJson())),
authToken: optional(resourceValueDecoder),
route: optional(resourceValueDecoder),
});
export var initialPropsDecoder = object({
exposeAs: object({
name: string(),
valuePath: optional(array(string())),
itemValuePath: optional(array(string())),
}),
resourceMappers: optional(array(object({
name: string(),
resource: lazy(function () { return externaldependencyDecoder; }),
}))),
resource: resourceDecoder,
});
export var initialPathsDecoder = object({
exposeAs: object({
name: string(),
valuePath: optional(array(string())),
itemValuePath: optional(array(string())),
}),
resource: resourceDecoder,
});
export var styleSetMediaConditionDecoder = object({

@@ -51,11 +85,7 @@ type: constant('screen-size'),

content: dict(union(staticValueDecoder, string(), number(), tokenReferenceDecoder)),
className: optional(string()),
subselectors: optional(string()),
});
// TODO: Implement decoder for () => void
export var stateOrPropDefinitionDecoder = union(string(), number(), boolean(), array(union(string(), number(), object())), object());
export var pageOptionsDecoder = object({
componentName: optional(isValidComponentName()),
navLink: optional(isValidNavLink()),
fileName: optional(isValidFileName()),
fallback: optional(boolean()),
});
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; }));

@@ -104,11 +134,6 @@ export var baseAssetDecoder = object({

export var componentSeoDecoder = object({
title: optional(string()),
metaTags: optional(array(dict(string()))),
title: optional(union(string(), staticValueDecoder, dynamicValueDecoder)),
metaTags: optional(array(dict(union(string(), staticValueDecoder, dynamicValueDecoder)))),
assets: optional(array(globalAssetsDecoder)),
});
export var stateValueDetailsDecoder = object({
value: union(string(), number(), boolean()),
pageOptions: optional(pageOptionsDecoder),
seo: optional(componentSeoDecoder),
});
export var propDefinitionsDecoder = object({

@@ -119,2 +144,7 @@ type: union(constant('string'), constant('boolean'), constant('number'), constant('array'), constant('func'), constant('object'), constant('children')),

});
export var pageOptionsPaginationDecoder = object({
attribute: string(),
pageSize: number(),
totalCountPath: optional(array(string())),
});
export var stateDefinitionsDecoder = object({

@@ -124,2 +154,21 @@ type: union(constant('string'), constant('boolean'), constant('number'), constant('array'), constant('func'), constant('object'), constant('children')),

});
export var pageOptionsDecoder = object({
componentName: optional(isValidComponentName()),
navLink: optional(isValidNavLink()),
fileName: optional(isValidFileName()),
fallback: optional(boolean()),
dynamicRouteAttribute: optional(string()),
isIndex: optional(boolean()),
pagination: optional(pageOptionsPaginationDecoder),
initialPropsData: optional(initialPropsDecoder),
initialPathsData: optional(initialPathsDecoder),
propDefinitions: optional(dict(propDefinitionsDecoder)),
stateDefinitions: optional(dict(stateDefinitionsDecoder)),
});
// @ts-ignore
export var stateValueDetailsDecoder = object({
value: union(string(), number(), boolean()),
pageOptions: optional(pageOptionsDecoder),
seo: optional(componentSeoDecoder),
});
export var outputOptionsDecoder = object({

@@ -147,2 +196,3 @@ componentClassName: optional(isValidComponentName()),

useAsReference: optional(boolean()),
importAlias: optional(string()),
needsWindowObject: optional(boolean()),

@@ -158,2 +208,3 @@ })),

importJustPath: optional(boolean()),
importAlias: optional(string()),
})),

@@ -193,2 +244,10 @@ });

});
export var dynamicLinkDecoder = object({
type: constant('dynamic'),
content: object({
referenceType: referenceTypeDecoder,
path: optional(array(string())),
id: string(),
}),
});
export var sectionLinkNodeDecoder = object({

@@ -218,3 +277,3 @@ type: constant('section'),

});
export var uidlLinkNodeDecoder = union(urlLinkNodeDecoder, sectionLinkNodeDecoder, navLinkNodeDecoder, uidlMailLinkNodeDecoder, phoneLinkNodeDecoder);
export var uidlLinkNodeDecoder = union(urlLinkNodeDecoder, sectionLinkNodeDecoder, navLinkNodeDecoder, uidlMailLinkNodeDecoder, phoneLinkNodeDecoder, dynamicLinkDecoder);
export var elementStateDecoder = oneOf(constant('hover'), constant('active'), constant('focus'), constant('focus-within'), constant('focus-visible'), constant('disabled'), constant('visited'), constant('checked'), constant('link'));

@@ -252,3 +311,3 @@ export var elementStyleWithStateConditionDecoder = object({

content: object({
referenceType: union(constant('prop'), constant('comp')),
referenceType: union(constant('prop'), constant('comp'), constant('ctx')),
id: string(),

@@ -270,2 +329,3 @@ }),

key: optional(string()),
ctxId: optional(string()),
dependency: optional(dependencyDecoder),

@@ -276,3 +336,3 @@ style: optional(dict(union(attributeValueDecoder, string(), number()))),

abilities: optional(object({
link: optional(uidlLinkNodeDecoder),
link: optional(anyJson()),
})),

@@ -320,3 +380,41 @@ children: optional(array(lazy(function () { return uidlNodeDecoder; }))),

});
export var uidlNodeDecoder = union(elementNodeDecoder, dynamicValueDecoder, staticValueDecoder, rawValueDecoder, conditionalNodeDecoder, repeatNodeDecoder, slotNodeDecoder, string());
export var cmsItemNodeDecoder = object({
type: constant('cms-item'),
content: object({
nodes: object({
success: lazy(function () { return elementNodeDecoder; }),
error: optional(lazy(function () { return elementNodeDecoder; })),
loading: optional(lazy(function () { return elementNodeDecoder; })),
}),
resourceId: optional(string()),
statePersistanceName: optional(string()),
valuePath: optional(array(string())),
itemValuePath: optional(array(string())),
resourceMappers: optional(array(object({
name: string(),
resource: externaldependencyDecoder,
}))),
}),
});
export var cmsListNodeDecoder = object({
type: constant('cms-list'),
content: object({
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; })),
}),
resourceId: optional(string()),
statePersistanceName: optional(string()),
itemValuePath: optional(array(string())),
valuePath: optional(array(string())),
loopItemsReference: optional(attributeValueDecoder),
resourceMappers: optional(array(object({
name: string(),
resource: externaldependencyDecoder,
}))),
}),
});
export var uidlNodeDecoder = union(elementNodeDecoder, cmsItemNodeDecoder, cmsListNodeDecoder, dynamicValueDecoder, staticValueDecoder, rawValueDecoder, conditionalNodeDecoder, union(repeatNodeDecoder, slotNodeDecoder, string()));
//# sourceMappingURL=utils.js.map

@@ -12,3 +12,3 @@ var __assign = (this && this.__assign) || function () {

};
import { UIDLUtils } from '@teleporthq/teleport-shared';
import { StringUtils, UIDLUtils } from '@teleporthq/teleport-shared';
import { ParserError, } from '@teleporthq/teleport-types';

@@ -18,5 +18,18 @@ export var parseComponentJSON = function (input, params) {

var safeInput = params.noClone ? input : UIDLUtils.cloneObject(input);
if (safeInput === null || safeInput === void 0 ? void 0 : safeInput.propDefinitions) {
safeInput.propDefinitions = Object.keys(safeInput.propDefinitions).reduce(function (acc, prop) {
var propName = StringUtils.createStateOrPropStoringValue(prop);
acc[propName] = safeInput.propDefinitions[prop];
return acc;
}, {});
}
if (safeInput === null || safeInput === void 0 ? void 0 : safeInput.stateDefinitions) {
safeInput.stateDefinitions = Object.keys(safeInput.stateDefinitions).reduce(function (acc, state) {
var stateName = StringUtils.createStateOrPropStoringValue(state);
acc[stateName] = safeInput.stateDefinitions[state];
return acc;
}, {});
}
if (safeInput === null || safeInput === void 0 ? void 0 : safeInput.styleSetDefinitions) {
var styleSetDefinitions = safeInput.styleSetDefinitions;
Object.values(styleSetDefinitions).forEach(function (styleRef) {
Object.values(safeInput === null || safeInput === void 0 ? void 0 : safeInput.styleSetDefinitions).forEach(function (styleRef) {
var _a = styleRef.conditions, conditions = _a === void 0 ? [] : _a;

@@ -39,3 +52,3 @@ styleRef.content = UIDLUtils.transformStylesAssignmentsToJson(styleRef.content);

// other parsers for other sections of the component here
result.node = parseComponentNode(node);
result.node = parseComponentNode(node, result);
return result;

@@ -75,12 +88,61 @@ };

};
var parseComponentNode = function (node) {
var _a, _b;
var parseComponentNode = function (node, component) {
var _a, _b, _c, _d, _e;
switch (node.type) {
case 'cms-item':
case 'cms-list':
case 'element':
var elementContent = node.content;
if (node.type === 'cms-item') {
var _f = node.content, _g = _f.nodes, success = _g.success, error = _g.error, loading = _g.loading, statePersistanceName = _f.statePersistanceName;
if (success) {
success.content.attrs = UIDLUtils.transformAttributesAssignmentsToJson(((_a = success === null || success === void 0 ? void 0 : success.content) === null || _a === void 0 ? void 0 : _a.attrs) || {});
}
if (error) {
error.content.attrs = UIDLUtils.transformAttributesAssignmentsToJson(((_b = error === null || error === void 0 ? void 0 : error.content) === null || _b === void 0 ? void 0 : _b.attrs) || {});
component.stateDefinitions["".concat(statePersistanceName, "Error")] = {
type: 'boolean',
defaultValue: false,
};
}
if (loading) {
component.stateDefinitions["".concat(statePersistanceName, "Loading")] = {
type: 'boolean',
defaultValue: false,
};
}
}
if (node.type === 'cms-list' && elementContent.hasOwnProperty('loopItemsReference')) {
var _h = node.content, loopItemsReference = _h.loopItemsReference, statePersistanceName = _h.statePersistanceName, _j = _h.nodes, success = _j.success, error = _j.error, loading = _j.loading;
var identifier = (loopItemsReference === null || loopItemsReference === void 0 ? void 0 : loopItemsReference.type) === 'dynamic' &&
loopItemsReference.content.referenceType === 'prop'
? 'propDefinitions'
: 'stateDefinitions';
if (success) {
success.content.attrs = UIDLUtils.transformAttributesAssignmentsToJson(((_c = success === null || success === void 0 ? void 0 : success.content) === null || _c === void 0 ? void 0 : _c.attrs) || {});
}
if (error) {
error.content.attrs = UIDLUtils.transformAttributesAssignmentsToJson(((_d = error === null || error === void 0 ? void 0 : error.content) === null || _d === void 0 ? void 0 : _d.attrs) || {});
component[identifier]["".concat(statePersistanceName, "Error")] = {
type: 'boolean',
defaultValue: false,
};
}
if (loading) {
component[identifier]["".concat(statePersistanceName, "Loading")] = {
type: 'boolean',
defaultValue: false,
};
}
if (loopItemsReference &&
(loopItemsReference === null || loopItemsReference === void 0 ? void 0 : loopItemsReference.type) === 'dynamic' &&
['state', 'prop'].includes(loopItemsReference === null || loopItemsReference === void 0 ? void 0 : loopItemsReference.content.referenceType)) {
loopItemsReference.content.id = StringUtils.createStateOrPropStoringValue(loopItemsReference.content.id);
}
}
if (elementContent === null || elementContent === void 0 ? void 0 : elementContent.referencedStyles) {
Object.values(elementContent.referencedStyles).forEach(function (styleRef) {
var content = styleRef.content;
switch (content.mapType) {
switch (styleRef.content.mapType) {
case 'inlined': {
var content = styleRef.content;
content.styles = UIDLUtils.transformStylesAssignmentsToJson(content.styles);

@@ -101,3 +163,3 @@ break;

default: {
throw new ParserError("Un-expected mapType passed in referencedStyles - ".concat(content.mapType));
throw new ParserError("Un-expected mapType passed in referencedStyles - ".concat(styleRef.content.mapType));
}

@@ -113,9 +175,15 @@ }

}
// @ts-ignore
if ((_a = elementContent.abilities) === null || _a === void 0 ? void 0 : _a.link) {
// @ts-ignore
var _c = (_b = elementContent.abilities) === null || _b === void 0 ? void 0 : _b.link, content = _c.content, type = _c.type;
if ((_e = elementContent === null || elementContent === void 0 ? void 0 : elementContent.abilities) === null || _e === void 0 ? void 0 : _e.hasOwnProperty('link')) {
var _k = elementContent.abilities.link, content = _k.content, type = _k.type;
if (type === 'url' && typeof content.url === 'string') {
content.url = UIDLUtils.transformStringAssignmentToJson(content.url);
}
if (type === 'url' && content.url.type === 'dynamic') {
;
content.url.content = {
referenceType: content.url
.content.referenceType,
id: StringUtils.createStateOrPropStoringValue(content.url.content.id),
};
}
}

@@ -128,3 +196,3 @@ if (Array.isArray(elementContent.children)) {

else {
return parseComponentNode(child);
return parseComponentNode(child, component);
}

@@ -137,3 +205,3 @@ }, []);

var reference = conditionalNode.content.reference;
conditionalNode.content.node = parseComponentNode(conditionalNode.content.node);
conditionalNode.content.node = parseComponentNode(conditionalNode.content.node, component);
if (typeof reference === 'string') {

@@ -146,3 +214,3 @@ conditionalNode.content.reference = UIDLUtils.transformStringAssignmentToJson(reference);

var dataSource = repeatNode.content.dataSource;
repeatNode.content.node = parseComponentNode(repeatNode.content.node);
repeatNode.content.node = parseComponentNode(repeatNode.content.node, component);
if (typeof dataSource === 'string') {

@@ -155,6 +223,11 @@ repeatNode.content.dataSource = UIDLUtils.transformStringAssignmentToJson(dataSource);

if (slotNode.content.fallback) {
slotNode.content.fallback = parseComponentNode(slotNode.content.fallback);
slotNode.content.fallback = parseComponentNode(slotNode.content.fallback, component);
}
return slotNode;
case 'dynamic':
var dyamicNode = node;
if (['state', 'prop'].includes(dyamicNode.content.referenceType)) {
dyamicNode.content.id = StringUtils.createStateOrPropStoringValue(dyamicNode.content.id);
}
return dyamicNode;
case 'static':

@@ -161,0 +234,0 @@ case 'raw':

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

if (!dynamicPathExistsInDefinitions(node.content.id, propKeys)) {
var errorMsg = "\"".concat(node.content.id, "\" is used but not defined. Please add it in propDefinitions ").concat(input.name);
var errorMsg = "\"".concat(node.content.id, "\" is used but not defined. Please add it in propDefinitions \n Used on Node ").concat(JSON.stringify(node.content));
errors.push(errorMsg);

@@ -145,4 +145,3 @@ }

if (!dynamicPathExistsInDefinitions(node.content.id, stateKeys)) {
var errorMsg = "\n\"".concat(node.content.id, "\" is used but not defined. Please add it in stateDefinitions");
errors.push(errorMsg);
console.warn("\n\"".concat(node.content.id, "\" is used but not defined. Please add it in stateDefinitions"));
}

@@ -149,0 +148,0 @@ // for member expression we check the root

{
"name": "@teleporthq/teleport-uidl-validator",
"version": "0.27.3",
"version": "0.27.4-alpha.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.27.3",
"@teleporthq/teleport-types": "^0.27.3"
"@teleporthq/teleport-shared": "^0.27.4-alpha.0",
"@teleporthq/teleport-types": "^0.27.4-alpha.0"
},
"gitHead": "14f69b861cb0838d502a5ba226bb7cb5c1291fbb"
"gitHead": "182513645c9074b0739b30e28a0a45d04805e72d"
}

@@ -1,4 +0,20 @@

import { Decoder, object, optional, string, dict, array } from '@mojotech/json-type-validation'
import { VUIDLGlobalProjectValues, WebManifest, VProjectUIDL } from '@teleporthq/teleport-types'
import { globalAssetsDecoder } from './utils'
import {
Decoder,
object,
optional,
string,
dict,
array,
intersection,
} from '@mojotech/json-type-validation'
import {
VUIDLGlobalProjectValues,
WebManifest,
VProjectUIDL,
ContextsUIDL,
ContextUIDLItem,
ResourcesUIDL,
ResourceItemUIDL,
} from '@teleporthq/teleport-types'
import { globalAssetsDecoder, resourceDecoder } from './utils'
import { componentUIDLDecoder, rootComponentUIDLDecoder } from './component-decoder'

@@ -29,2 +45,3 @@

),
env: optional(dict(string())),
meta: array(dict(string())),

@@ -36,2 +53,25 @@ assets: array(globalAssetsDecoder),

export const contextItemDecoder: Decoder<ContextUIDLItem> = object({
name: string(),
fileName: optional(string()),
})
export const contextsDecoder: Decoder<ContextsUIDL> = object({
rootFolder: optional(string()),
items: dict(optional(contextItemDecoder)),
})
export const projectResourceItemDecoder: Decoder<ResourceItemUIDL> = intersection(
resourceDecoder,
object({
id: string(),
name: string(),
})
)
export const resourcesDecoder: Decoder<ResourcesUIDL> = object({
rootFolder: optional(string()),
items: dict(optional(projectResourceItemDecoder)),
})
export const projectUIDLDecoder: Decoder<VProjectUIDL> = object({

@@ -42,2 +82,4 @@ name: string(),

components: optional(dict(componentUIDLDecoder)),
contexts: optional(contextsDecoder),
resources: optional(resourcesDecoder),
})

@@ -15,3 +15,5 @@ import {

intersection,
unknownJson,
withDefault,
anyJson,
} from '@mojotech/json-type-validation'

@@ -76,2 +78,12 @@ import {

UIDLComponentStyleReference,
ResourceValue,
ResourceUrlParams,
PagePaginationOptions,
VCMSItemUIDLElementNode,
VCMSListUIDLElementNode,
Resource,
InitialPropsData,
InitialPathsData,
UIDLExpressionValue,
UIDLDynamicLinkNode,
} from '@teleporthq/teleport-types'

@@ -83,2 +95,7 @@ import { CustomCombinators } from './custom-combinators'

const resourceValueDecoder: Decoder<ResourceValue> = union(
object({ type: constant('static'), value: string() }),
object({ type: constant('env'), value: string(), fallback: optional(string()) })
)
export const referenceTypeDecoder: Decoder<ReferenceType> = union(

@@ -90,3 +107,4 @@ constant('prop'),

constant('children'),
constant('token')
constant('token'),
constant('ctx')
)

@@ -98,6 +116,13 @@

referenceType: referenceTypeDecoder,
path: optional(array(string())),
id: string(),
ctxId: optional(string()),
}),
})
export const expressionValueDecoder: Decoder<UIDLExpressionValue> = object({
type: constant('expr'),
content: string(),
})
export const staticValueDecoder: Decoder<UIDLStaticValue> = object({

@@ -113,2 +138,46 @@ type: constant('static'),

const resourceUrlParamsDecoder: Decoder<ResourceUrlParams> = dict(
union(
staticValueDecoder,
dynamicValueDecoder,
expressionValueDecoder,
array(union(staticValueDecoder, dynamicValueDecoder))
)
)
export const resourceDecoder: Decoder<Resource> = object({
baseUrl: resourceValueDecoder,
urlParams: optional(
union(resourceUrlParamsDecoder, dict(resourceUrlParamsDecoder), unknownJson())
),
authToken: optional(resourceValueDecoder),
route: optional(resourceValueDecoder),
})
export const initialPropsDecoder: Decoder<InitialPropsData> = object({
exposeAs: object({
name: string(),
valuePath: optional(array(string())),
itemValuePath: optional(array(string())),
}),
resourceMappers: optional(
array(
object({
name: string(),
resource: lazy(() => externaldependencyDecoder),
})
)
),
resource: resourceDecoder,
})
export const initialPathsDecoder: Decoder<InitialPathsData> = object({
exposeAs: object({
name: string(),
valuePath: optional(array(string())),
itemValuePath: optional(array(string())),
}),
resource: resourceDecoder,
})
export const styleSetMediaConditionDecoder: Decoder<VUIDLStyleSetMediaCondition> = object({

@@ -168,2 +237,4 @@ type: constant('screen-size'),

content: dict(union(staticValueDecoder, string(), number(), tokenReferenceDecoder)),
className: optional(string()),
subselectors: optional(string()),
})

@@ -180,9 +251,2 @@

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>),
fallback: optional(boolean()),
})
export const globalAssetsDecoder: Decoder<VUIDLGlobalAsset> = union(

@@ -258,13 +322,7 @@ lazy(() => inlineScriptAssetDecoder),

export const componentSeoDecoder: Decoder<VUIDLComponentSEO> = object({
title: optional(string()),
metaTags: optional(array(dict(string()))),
title: optional(union(string(), staticValueDecoder, dynamicValueDecoder)),
metaTags: optional(array(dict(union(string(), staticValueDecoder, dynamicValueDecoder)))),
assets: optional(array(globalAssetsDecoder)),
})
export const stateValueDetailsDecoder: Decoder<UIDLStateValueDetails> = object({
value: union(string(), number(), boolean()),
pageOptions: optional(pageOptionsDecoder),
seo: optional(componentSeoDecoder),
})
export const propDefinitionsDecoder: Decoder<UIDLPropDefinition> = object({

@@ -284,2 +342,8 @@ type: union(

export const pageOptionsPaginationDecoder: Decoder<PagePaginationOptions> = object({
attribute: string(),
pageSize: number(),
totalCountPath: optional(array(string())),
})
export const stateDefinitionsDecoder: Decoder<UIDLStateDefinition> = object({

@@ -298,2 +362,23 @@ type: union(

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>),
fallback: optional(boolean()),
dynamicRouteAttribute: optional(string()),
isIndex: optional(boolean()),
pagination: optional(pageOptionsPaginationDecoder),
initialPropsData: optional(initialPropsDecoder),
initialPathsData: optional(initialPathsDecoder),
propDefinitions: optional(dict(propDefinitionsDecoder)),
stateDefinitions: optional(dict(stateDefinitionsDecoder)),
})
// @ts-ignore
export const stateValueDetailsDecoder: Decoder<UIDLStateValueDetails> = object({
value: union(string(), number(), boolean()),
pageOptions: optional(pageOptionsDecoder),
seo: optional(componentSeoDecoder),
})
export const outputOptionsDecoder: Decoder<UIDLComponentOutputOptions> = object({

@@ -324,2 +409,3 @@ componentClassName: optional(isValidComponentName() as unknown as Decoder<string>),

useAsReference: optional(boolean()),
importAlias: optional(string()),
needsWindowObject: optional(boolean()),

@@ -338,2 +424,3 @@ })

importJustPath: optional(boolean()),
importAlias: optional(string()),
})

@@ -400,2 +487,11 @@ ),

export const dynamicLinkDecoder: Decoder<UIDLDynamicLinkNode> = object({
type: constant('dynamic'),
content: object({
referenceType: referenceTypeDecoder,
path: optional(array(string())),
id: string(),
}),
})
export const sectionLinkNodeDecoder: Decoder<VUIDLSectionLinkNode> = object({

@@ -434,3 +530,4 @@ type: constant('section'),

uidlMailLinkNodeDecoder,
phoneLinkNodeDecoder
phoneLinkNodeDecoder,
dynamicLinkDecoder
)

@@ -492,3 +589,3 @@

content: object({
referenceType: union(constant('prop'), constant('comp')),
referenceType: union(constant('prop'), constant('comp'), constant('ctx')),
id: string(),

@@ -516,2 +613,3 @@ }),

key: optional(string()),
ctxId: optional(string()),
dependency: optional(dependencyDecoder),

@@ -523,3 +621,3 @@ style: optional(dict(union(attributeValueDecoder, string(), number()))),

object({
link: optional(uidlLinkNodeDecoder),
link: optional(anyJson()),
})

@@ -596,4 +694,54 @@ ),

export const cmsItemNodeDecoder: Decoder<VCMSItemUIDLElementNode> = object({
type: constant('cms-item'),
content: object({
nodes: object({
success: lazy(() => elementNodeDecoder),
error: optional(lazy(() => elementNodeDecoder)),
loading: optional(lazy(() => elementNodeDecoder)),
}),
resourceId: optional(string()),
statePersistanceName: optional(string()),
valuePath: optional(array(string())),
itemValuePath: optional(array(string())),
resourceMappers: optional(
array(
object({
name: string(),
resource: externaldependencyDecoder,
})
)
),
}),
})
export const cmsListNodeDecoder: Decoder<VCMSListUIDLElementNode> = object({
type: constant('cms-list'),
content: object({
nodes: object({
success: lazy(() => elementNodeDecoder),
error: optional(lazy(() => elementNodeDecoder)),
loading: optional(lazy(() => elementNodeDecoder)),
empty: optional(lazy(() => elementNodeDecoder)),
}),
resourceId: optional(string()),
statePersistanceName: optional(string()),
itemValuePath: optional(array(string())),
valuePath: optional(array(string())),
loopItemsReference: optional(attributeValueDecoder),
resourceMappers: optional(
array(
object({
name: string(),
resource: externaldependencyDecoder,
})
)
),
}),
})
export const uidlNodeDecoder: Decoder<VUIDLNode> = union(
elementNodeDecoder,
cmsItemNodeDecoder,
cmsListNodeDecoder,
dynamicValueDecoder,

@@ -603,5 +751,3 @@ staticValueDecoder,

conditionalNodeDecoder,
repeatNodeDecoder,
slotNodeDecoder,
string()
union(repeatNodeDecoder, slotNodeDecoder, string())
)

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

import { UIDLUtils } from '@teleporthq/teleport-shared'
import { StringUtils, UIDLUtils } from '@teleporthq/teleport-shared'
import {

@@ -20,2 +19,9 @@ UIDLDynamicReference,

UIDLRootComponent,
VUIDLLinkNode,
UIDLCMSItemNode,
UIDLPropDefinition,
UIDLStateDefinition,
UIDLCMSListNode,
UIDLElementNodeInlineReferencedStyle,
UIDLURLLinkNode,
} from '@teleporthq/teleport-types'

@@ -33,6 +39,26 @@

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
},
{}
)
}
if (safeInput?.stateDefinitions) {
safeInput.stateDefinitions = Object.keys(safeInput.stateDefinitions).reduce(
(acc: Record<string, UIDLStateDefinition>, state) => {
const stateName = StringUtils.createStateOrPropStoringValue(state)
acc[stateName] = (safeInput.stateDefinitions as Record<string, UIDLStateDefinition>)[state]
return acc
},
{}
)
}
if (safeInput?.styleSetDefinitions) {
const { styleSetDefinitions } = safeInput
Object.values(styleSetDefinitions).forEach((styleRef) => {
Object.values(safeInput?.styleSetDefinitions).forEach((styleRef) => {
const { conditions = [] } = styleRef

@@ -64,3 +90,3 @@ styleRef.content = UIDLUtils.transformStylesAssignmentsToJson(styleRef.content)

// other parsers for other sections of the component here
result.node = parseComponentNode(node) as UIDLElementNode
result.node = parseComponentNode(node, result) as UIDLElementNode

@@ -122,16 +148,91 @@ return result

const parseComponentNode = (node: Record<string, unknown>): UIDLNode => {
const parseComponentNode = (node: Record<string, unknown>, component: ComponentUIDL): UIDLNode => {
switch ((node as unknown as UIDLNode).type) {
case 'cms-item':
case 'cms-list':
case 'element':
const elementContent = node.content as Record<string, unknown>
if (node.type === 'cms-item') {
const {
nodes: { success, error, loading },
statePersistanceName,
} = (node as unknown as UIDLCMSItemNode).content
if (success) {
success.content.attrs = UIDLUtils.transformAttributesAssignmentsToJson(
success?.content?.attrs || {}
)
}
if (error) {
error.content.attrs = UIDLUtils.transformAttributesAssignmentsToJson(
error?.content?.attrs || {}
)
component.stateDefinitions[`${statePersistanceName}Error`] = {
type: 'boolean',
defaultValue: false,
}
}
if (loading) {
component.stateDefinitions[`${statePersistanceName}Loading`] = {
type: 'boolean',
defaultValue: false,
}
}
}
if (node.type === 'cms-list' && elementContent.hasOwnProperty('loopItemsReference')) {
const {
loopItemsReference,
statePersistanceName,
nodes: { success, error, loading },
} = (node as unknown as UIDLCMSListNode).content
const identifier =
loopItemsReference?.type === 'dynamic' &&
loopItemsReference.content.referenceType === 'prop'
? 'propDefinitions'
: 'stateDefinitions'
if (success) {
success.content.attrs = UIDLUtils.transformAttributesAssignmentsToJson(
success?.content?.attrs || {}
)
}
if (error) {
error.content.attrs = UIDLUtils.transformAttributesAssignmentsToJson(
error?.content?.attrs || {}
)
component[identifier][`${statePersistanceName}Error`] = {
type: 'boolean',
defaultValue: false,
}
}
if (loading) {
component[identifier][`${statePersistanceName}Loading`] = {
type: 'boolean',
defaultValue: false,
}
}
if (
loopItemsReference &&
loopItemsReference?.type === 'dynamic' &&
['state', 'prop'].includes(loopItemsReference?.content.referenceType)
) {
loopItemsReference.content.id = StringUtils.createStateOrPropStoringValue(
loopItemsReference.content.id
)
}
}
if (elementContent?.referencedStyles) {
Object.values(elementContent.referencedStyles).forEach((styleRef) => {
const { content } = styleRef
switch (content.mapType) {
switch (styleRef.content.mapType) {
case 'inlined': {
content.styles = UIDLUtils.transformStylesAssignmentsToJson(
content.styles as Record<string, string>
)
const { content } = styleRef as UIDLElementNodeInlineReferencedStyle
content.styles = UIDLUtils.transformStylesAssignmentsToJson(content.styles)
break

@@ -150,2 +251,3 @@ }

}
break

@@ -156,3 +258,3 @@ }

throw new ParserError(
`Un-expected mapType passed in referencedStyles - ${content.mapType}`
`Un-expected mapType passed in referencedStyles - ${styleRef.content.mapType}`
)

@@ -176,9 +278,17 @@ }

// @ts-ignore
if (elementContent.abilities?.link) {
// @ts-ignore
const { content, type } = elementContent.abilities?.link
if (elementContent?.abilities?.hasOwnProperty('link')) {
const { content, type } = (elementContent.abilities as { link: VUIDLLinkNode }).link
if (type === 'url' && typeof content.url === 'string') {
content.url = UIDLUtils.transformStringAssignmentToJson(content.url)
}
if (type === 'url' && (content as UIDLURLLinkNode['content']).url.type === 'dynamic') {
;(content as UIDLURLLinkNode['content']).url.content = {
referenceType: ((content as UIDLURLLinkNode['content']).url as UIDLDynamicReference)
.content.referenceType,
id: StringUtils.createStateOrPropStoringValue(
((content as UIDLURLLinkNode['content']).url as UIDLDynamicReference).content.id
),
}
}
}

@@ -191,3 +301,3 @@

} else {
return parseComponentNode(child)
return parseComponentNode(child, component)
}

@@ -204,3 +314,4 @@ }, [])

conditionalNode.content.node = parseComponentNode(
conditionalNode.content.node as unknown as Record<string, unknown>
conditionalNode.content.node as unknown as Record<string, unknown>,
component
)

@@ -221,3 +332,4 @@

repeatNode.content.node = parseComponentNode(
repeatNode.content.node as unknown as Record<string, unknown>
repeatNode.content.node as unknown as Record<string, unknown>,
component
) as UIDLElementNode

@@ -236,3 +348,4 @@

slotNode.content.fallback = parseComponentNode(
slotNode.content.fallback as unknown as Record<string, unknown>
slotNode.content.fallback as unknown as Record<string, unknown>,
component
) as UIDLElementNode | UIDLStaticValue | UIDLDynamicReference

@@ -244,2 +357,7 @@ }

case 'dynamic':
const dyamicNode = node as unknown as UIDLDynamicReference
if (['state', 'prop'].includes(dyamicNode.content.referenceType)) {
dyamicNode.content.id = StringUtils.createStateOrPropStoringValue(dyamicNode.content.id)
}
return dyamicNode
case 'static':

@@ -246,0 +364,0 @@ case 'raw':

@@ -181,3 +181,7 @@ import { UIDLUtils } from '@teleporthq/teleport-shared'

if (!dynamicPathExistsInDefinitions(node.content.id, propKeys)) {
const errorMsg = `"${node.content.id}" is used but not defined. Please add it in propDefinitions ${input.name}`
const errorMsg = `"${
node.content.id
}" is used but not defined. Please add it in propDefinitions \n Used on Node ${JSON.stringify(
node.content
)}`
errors.push(errorMsg)

@@ -194,4 +198,5 @@ }

if (!dynamicPathExistsInDefinitions(node.content.id, stateKeys)) {
const errorMsg = `\n"${node.content.id}" is used but not defined. Please add it in stateDefinitions`
errors.push(errorMsg)
console.warn(
`\n"${node.content.id}" is used but not defined. Please add it in stateDefinitions`
)
}

@@ -198,0 +203,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

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