mirror of
https://github.com/divkit/divkit.git
synced 2026-05-07 20:02:32 +00:00
Nested types fix
commit_hash:0e61cb86c4ecce349d6b76477d5f025a5896aa81
This commit is contained in:
@@ -24691,12 +24691,15 @@
|
||||
"test_data/parsing_test_data/invalid_value_replaced_with_default_value.json":"divkit/public/test_data/parsing_test_data/invalid_value_replaced_with_default_value.json",
|
||||
"test_data/parsing_test_data/required_property_value_is_missing.json":"divkit/public/test_data/parsing_test_data/required_property_value_is_missing.json",
|
||||
"test_data/parsing_test_data/simple_values.json":"divkit/public/test_data/parsing_test_data/simple_values.json",
|
||||
"test_data/parsing_test_data/templates/cross_level_link_resolution_in_items.json":"divkit/public/test_data/parsing_test_data/templates/cross_level_link_resolution_in_items.json",
|
||||
"test_data/parsing_test_data/templates/direct_value_overrides_link.json":"divkit/public/test_data/parsing_test_data/templates/direct_value_overrides_link.json",
|
||||
"test_data/parsing_test_data/templates/invalid_value_replaced_with_default_value_in_div_text.json":"divkit/public/test_data/parsing_test_data/templates/invalid_value_replaced_with_default_value_in_div_text.json",
|
||||
"test_data/parsing_test_data/templates/link_is_overridden_in_derived_template.json":"divkit/public/test_data/parsing_test_data/templates/link_is_overridden_in_derived_template.json",
|
||||
"test_data/parsing_test_data/templates/nested_template_usage.json":"divkit/public/test_data/parsing_test_data/templates/nested_template_usage.json",
|
||||
"test_data/parsing_test_data/templates/same_link_used_in_two_places.json":"divkit/public/test_data/parsing_test_data/templates/same_link_used_in_two_places.json",
|
||||
"test_data/parsing_test_data/templates/simple.json":"divkit/public/test_data/parsing_test_data/templates/simple.json",
|
||||
"test_data/parsing_test_data/templates/template_chain.json":"divkit/public/test_data/parsing_test_data/templates/template_chain.json",
|
||||
"test_data/parsing_test_data/templates/template_name_collision_in_nested_property.json":"divkit/public/test_data/parsing_test_data/templates/template_name_collision_in_nested_property.json",
|
||||
"test_data/parsing_test_data/templates/transitive_template_dependencies_in_items.json":"divkit/public/test_data/parsing_test_data/templates/transitive_template_dependencies_in_items.json",
|
||||
"test_data/parsing_test_data/templates/unresolved_link_for_optional_field.json":"divkit/public/test_data/parsing_test_data/templates/unresolved_link_for_optional_field.json",
|
||||
"test_data/parsing_test_data/templates/with_array_link.json":"divkit/public/test_data/parsing_test_data/templates/with_array_link.json",
|
||||
@@ -24705,6 +24708,7 @@
|
||||
"test_data/parsing_test_data/templates/with_nested_object.json":"divkit/public/test_data/parsing_test_data/templates/with_nested_object.json",
|
||||
"test_data/parsing_test_data/templates/with_override.json":"divkit/public/test_data/parsing_test_data/templates/with_override.json",
|
||||
"test_data/parsing_test_data/templates/with_parent_template_with_link.json":"divkit/public/test_data/parsing_test_data/templates/with_parent_template_with_link.json",
|
||||
"test_data/parsing_test_data/templates/with_single_level_link_in_nested_template.json":"divkit/public/test_data/parsing_test_data/templates/with_single_level_link_in_nested_template.json",
|
||||
"test_data/perf_test_data/expressions.json":"divkit/public/test_data/perf_test_data/expressions.json",
|
||||
"test_data/perf_test_data/prototypes.json":"divkit/public/test_data/perf_test_data/prototypes.json",
|
||||
"test_data/perf_test_data/scroll_default.json":"divkit/public/test_data/perf_test_data/scroll_default.json",
|
||||
|
||||
@@ -159,8 +159,11 @@ class SwiftGenerator(Generator):
|
||||
if entity_enumeration.mode.is_template:
|
||||
body += 'let receivedType = try dictionary.getField("type") as String'
|
||||
body += 'let blockType = templateToType[receivedType] ?? receivedType'
|
||||
dict_var = 'dictionary'
|
||||
else:
|
||||
body += 'let dictionary = context.templateResolver?(dictionary) ?? dictionary'
|
||||
body += 'let blockType = try dictionary.getField("type") as String'
|
||||
dict_var = 'dictionary'
|
||||
body += 'switch blockType {'
|
||||
entity_names = entity_enumeration.entity_names
|
||||
for entity, name in zip(entity_enumeration.entities, entity_names):
|
||||
@@ -169,10 +172,9 @@ class SwiftGenerator(Generator):
|
||||
args = swift_template_deserializable_args(entity_enumeration.mode)
|
||||
context_param = '' if entity_enumeration.mode.is_template else ', context: context'
|
||||
body += f'case {obj_t}.type:'
|
||||
body += f' self = .{low_name}(try {obj_t}(dictionary: dictionary{args}{context_param}))'
|
||||
body += f' self = .{low_name}(try {obj_t}(dictionary: {dict_var}{args}{context_param}))'
|
||||
body += 'default:'
|
||||
args = f'field: "{entity_enumeration.name}", representation: dictionary'
|
||||
body += f' throw DeserializationError.invalidFieldRepresentation({args})'
|
||||
body += ' throw DeserializationError.requiredFieldIsMissing(field: "type")'
|
||||
body += '}'
|
||||
deserializable_extension += body.indented(level=2)
|
||||
deserializable_extension += ' }'
|
||||
|
||||
@@ -603,6 +603,8 @@ class SwiftProperty(Property):
|
||||
validator_arg_string = self.validator_arg(entity_name='Self', mode=mode)
|
||||
declaration_mode = SwiftProperty.SwiftMode(value=mode, use_expressions=False)
|
||||
|
||||
context_suffix = ', context: context' if not self.parsed_value_is_optional else ''
|
||||
|
||||
if isinstance(self.property_type, Array):
|
||||
item_type = cast(SwiftPropertyType, self.property_type.property_type).prefixed_declaration(
|
||||
declaration_mode
|
||||
@@ -611,7 +613,7 @@ class SwiftProperty(Property):
|
||||
expr = (
|
||||
f'"{self.dict_field}", transform: '
|
||||
f'{{ (dict: [String: Any]) in try? {item_type}(dictionary: dict, context: context) }}'
|
||||
f'{validator_arg_string}'
|
||||
f'{validator_arg_string}{context_suffix}'
|
||||
)
|
||||
return f'get{optional_suffix}Array({expr})'
|
||||
|
||||
@@ -622,7 +624,7 @@ class SwiftProperty(Property):
|
||||
expr = (
|
||||
f'"{self.dict_field}", transform: '
|
||||
f'{{ (dict: [String: Any]) in try {value_type}(dictionary: dict, context: context) }}'
|
||||
f'{validator_arg_string}'
|
||||
f'{validator_arg_string}{context_suffix}'
|
||||
)
|
||||
return f'get{optional_suffix}Field({expr})'
|
||||
|
||||
|
||||
@@ -72,6 +72,7 @@ public enum Entity: Sendable {
|
||||
|
||||
extension Entity {
|
||||
public init(dictionary: [String: Any], context: ParsingContext) throws {
|
||||
let dictionary = context.templateResolver?(dictionary) ?? dictionary
|
||||
let blockType = try dictionary.getField("type") as String
|
||||
switch blockType {
|
||||
case EntityWithArray.type:
|
||||
@@ -113,7 +114,7 @@ extension Entity {
|
||||
case EntityWithoutProperties.type:
|
||||
self = .entityWithoutProperties(try EntityWithoutProperties(dictionary: dictionary, context: context))
|
||||
default:
|
||||
throw DeserializationError.invalidFieldRepresentation(field: "entity", representation: dictionary)
|
||||
throw DeserializationError.requiredFieldIsMissing(field: "type")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ public final class EntityWithArray: Sendable {
|
||||
|
||||
public convenience init(dictionary: [String: Any], context: ParsingContext) throws {
|
||||
self.init(
|
||||
array: try dictionary.getArray("array", transform: { (dict: [String: Any]) in try? Entity(dictionary: dict, context: context) }, validator: Self.arrayValidator)
|
||||
array: try dictionary.getArray("array", transform: { (dict: [String: Any]) in try? Entity(dictionary: dict, context: context) }, validator: Self.arrayValidator, context: context)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -15,7 +15,7 @@ public final class EntityWithArrayOfNestedItems: Sendable {
|
||||
|
||||
public convenience init(dictionary: [String: Any], context: ParsingContext) throws {
|
||||
self.init(
|
||||
entity: try dictionary.getField("entity", transform: { (dict: [String: Any]) in try Entity(dictionary: dict, context: context) }),
|
||||
entity: try dictionary.getField("entity", transform: { (dict: [String: Any]) in try Entity(dictionary: dict, context: context) }, context: context),
|
||||
property: try dictionary.getExpressionField("property", context: context)
|
||||
)
|
||||
}
|
||||
@@ -37,7 +37,7 @@ public final class EntityWithArrayOfNestedItems: Sendable {
|
||||
|
||||
public convenience init(dictionary: [String: Any], context: ParsingContext) throws {
|
||||
self.init(
|
||||
items: try dictionary.getArray("items", transform: { (dict: [String: Any]) in try? EntityWithArrayOfNestedItems.Item(dictionary: dict, context: context) }, validator: Self.itemsValidator)
|
||||
items: try dictionary.getArray("items", transform: { (dict: [String: Any]) in try? EntityWithArrayOfNestedItems.Item(dictionary: dict, context: context) }, validator: Self.itemsValidator, context: context)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ public final class EntityWithComplexProperty: Sendable {
|
||||
|
||||
public convenience init(dictionary: [String: Any], context: ParsingContext) throws {
|
||||
self.init(
|
||||
property: try dictionary.getField("property", transform: { (dict: [String: Any]) in try EntityWithComplexProperty.Property(dictionary: dict, context: context) })
|
||||
property: try dictionary.getField("property", transform: { (dict: [String: Any]) in try EntityWithComplexProperty.Property(dictionary: dict, context: context) }, context: context)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ public enum EnumWithDefaultType: Sendable {
|
||||
|
||||
extension EnumWithDefaultType {
|
||||
public init(dictionary: [String: Any], context: ParsingContext) throws {
|
||||
let dictionary = context.templateResolver?(dictionary) ?? dictionary
|
||||
let blockType = try dictionary.getField("type") as String
|
||||
switch blockType {
|
||||
case WithDefault.type:
|
||||
@@ -28,7 +29,7 @@ extension EnumWithDefaultType {
|
||||
case WithoutDefault.type:
|
||||
self = .withoutDefault(try WithoutDefault(dictionary: dictionary, context: context))
|
||||
default:
|
||||
throw DeserializationError.invalidFieldRepresentation(field: "enum_with_default_type", representation: dictionary)
|
||||
throw DeserializationError.requiredFieldIsMissing(field: "type")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,6 +72,7 @@ public enum Entity: Sendable {
|
||||
|
||||
extension Entity {
|
||||
public init(dictionary: [String: Any], context: ParsingContext) throws {
|
||||
let dictionary = context.templateResolver?(dictionary) ?? dictionary
|
||||
let blockType = try dictionary.getField("type") as String
|
||||
switch blockType {
|
||||
case EntityWithArray.type:
|
||||
@@ -113,7 +114,7 @@ extension Entity {
|
||||
case EntityWithoutProperties.type:
|
||||
self = .entityWithoutProperties(try EntityWithoutProperties(dictionary: dictionary, context: context))
|
||||
default:
|
||||
throw DeserializationError.invalidFieldRepresentation(field: "entity", representation: dictionary)
|
||||
throw DeserializationError.requiredFieldIsMissing(field: "type")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -485,7 +485,7 @@ extension EntityTemplate {
|
||||
case EntityWithoutPropertiesTemplate.type:
|
||||
self = .entityWithoutPropertiesTemplate(try EntityWithoutPropertiesTemplate(dictionary: dictionary, templateToType: templateToType))
|
||||
default:
|
||||
throw DeserializationError.invalidFieldRepresentation(field: "entity_template", representation: dictionary)
|
||||
throw DeserializationError.requiredFieldIsMissing(field: "type")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ public final class EntityWithArray: Sendable {
|
||||
|
||||
public convenience init(dictionary: [String: Any], context: ParsingContext) throws {
|
||||
self.init(
|
||||
array: try dictionary.getArray("array", transform: { (dict: [String: Any]) in try? Entity(dictionary: dict, context: context) }, validator: Self.arrayValidator)
|
||||
array: try dictionary.getArray("array", transform: { (dict: [String: Any]) in try? Entity(dictionary: dict, context: context) }, validator: Self.arrayValidator, context: context)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ public final class EntityWithArrayOfNestedItems: Sendable {
|
||||
|
||||
public convenience init(dictionary: [String: Any], context: ParsingContext) throws {
|
||||
self.init(
|
||||
entity: try dictionary.getField("entity", transform: { (dict: [String: Any]) in try Entity(dictionary: dict, context: context) }),
|
||||
entity: try dictionary.getField("entity", transform: { (dict: [String: Any]) in try Entity(dictionary: dict, context: context) }, context: context),
|
||||
property: try dictionary.getExpressionField("property", context: context)
|
||||
)
|
||||
}
|
||||
@@ -37,7 +37,7 @@ public final class EntityWithArrayOfNestedItems: Sendable {
|
||||
|
||||
public convenience init(dictionary: [String: Any], context: ParsingContext) throws {
|
||||
self.init(
|
||||
items: try dictionary.getArray("items", transform: { (dict: [String: Any]) in try? EntityWithArrayOfNestedItems.Item(dictionary: dict, context: context) }, validator: Self.itemsValidator)
|
||||
items: try dictionary.getArray("items", transform: { (dict: [String: Any]) in try? EntityWithArrayOfNestedItems.Item(dictionary: dict, context: context) }, validator: Self.itemsValidator, context: context)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ public final class EntityWithComplexProperty: Sendable {
|
||||
|
||||
public convenience init(dictionary: [String: Any], context: ParsingContext) throws {
|
||||
self.init(
|
||||
property: try dictionary.getField("property", transform: { (dict: [String: Any]) in try EntityWithComplexProperty.Property(dictionary: dict, context: context) })
|
||||
property: try dictionary.getField("property", transform: { (dict: [String: Any]) in try EntityWithComplexProperty.Property(dictionary: dict, context: context) }, context: context)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ public enum EnumWithDefaultType: Sendable {
|
||||
|
||||
extension EnumWithDefaultType {
|
||||
public init(dictionary: [String: Any], context: ParsingContext) throws {
|
||||
let dictionary = context.templateResolver?(dictionary) ?? dictionary
|
||||
let blockType = try dictionary.getField("type") as String
|
||||
switch blockType {
|
||||
case WithDefault.type:
|
||||
@@ -28,7 +29,7 @@ extension EnumWithDefaultType {
|
||||
case WithoutDefault.type:
|
||||
self = .withoutDefault(try WithoutDefault(dictionary: dictionary, context: context))
|
||||
default:
|
||||
throw DeserializationError.invalidFieldRepresentation(field: "enum_with_default_type", representation: dictionary)
|
||||
throw DeserializationError.requiredFieldIsMissing(field: "type")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ extension EnumWithDefaultTypeTemplate {
|
||||
case WithoutDefaultTemplate.type:
|
||||
self = .withoutDefaultTemplate(try WithoutDefaultTemplate(dictionary: dictionary, templateToType: templateToType))
|
||||
default:
|
||||
throw DeserializationError.invalidFieldRepresentation(field: "enum_with_default_type_template", representation: dictionary)
|
||||
throw DeserializationError.requiredFieldIsMissing(field: "type")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,50 +99,30 @@ extension DivData {
|
||||
flagsInfo: DivFlagsInfo = .default
|
||||
) -> DeserializationResult<DivData> {
|
||||
if flagsInfo.useUntypedTemplateResolver {
|
||||
var resolver = UntypedDivTemplateResolver(templates: templatesDict)
|
||||
let resolvedCardResult = resolver.resolve(card: cardDict)
|
||||
let parsingContext = ParsingContext()
|
||||
|
||||
guard let resolvedCard = resolvedCardResult.value else {
|
||||
return .failure(resolvedCardResult.errorsOrWarnings ?? NonEmptyArray(.generic))
|
||||
}
|
||||
let resolver = UntypedDivTemplateResolver(templates: templatesDict)
|
||||
let parsingContext = ParsingContext(
|
||||
templateResolver: { resolver.resolveFlat($0) }
|
||||
)
|
||||
|
||||
let divDataResult: DeserializationResult<DivData>
|
||||
do {
|
||||
divDataResult = try .success(DivData(dictionary: resolvedCard, context: parsingContext))
|
||||
} catch let error as DeserializationError {
|
||||
divDataResult = .failure(NonEmptyArray(error))
|
||||
divDataResult = try .success(DivData(dictionary: cardDict, context: parsingContext))
|
||||
} catch {
|
||||
divDataResult =
|
||||
.failure(NonEmptyArray(.unexpectedError(message: String(describing: error))))
|
||||
divDataResult = .noValue
|
||||
}
|
||||
|
||||
let contextWarnings: NonEmptyArray<DeserializationError>? = NonEmptyArray(parsingContext
|
||||
.warnings
|
||||
)
|
||||
let contextErrors: NonEmptyArray<DeserializationError>? = NonEmptyArray(parsingContext.errors)
|
||||
let resolverWarnings = resolvedCardResult.warnings
|
||||
|
||||
let allIssues: NonEmptyArray<DeserializationError>? = NonEmptyArray(
|
||||
mergeErrors(contextWarnings, contextErrors, resolverWarnings)
|
||||
)
|
||||
let contextErrors = parsingContext.errors
|
||||
let contextWarnings = parsingContext.warnings
|
||||
|
||||
switch divDataResult {
|
||||
case let .success(value):
|
||||
if let warnings = allIssues {
|
||||
case .success(let value), .partialSuccess(let value, _):
|
||||
if let warnings = NonEmptyArray(contextErrors + contextWarnings) {
|
||||
return .partialSuccess(value, warnings: warnings)
|
||||
}
|
||||
return .success(value)
|
||||
case let .partialSuccess(value, warnings):
|
||||
if let mergedWarnings = NonEmptyArray(mergeErrors(warnings, allIssues)) {
|
||||
return .partialSuccess(value, warnings: mergedWarnings)
|
||||
}
|
||||
return .success(value)
|
||||
case let .failure(errors):
|
||||
return .failure(NonEmptyArray(mergeErrors(errors, allIssues))!)
|
||||
case .noValue:
|
||||
if let warnings = allIssues {
|
||||
return .failure(warnings)
|
||||
default:
|
||||
if let errors = NonEmptyArray(contextErrors) {
|
||||
return .failure(errors)
|
||||
}
|
||||
return .failure(NonEmptyArray(.generic))
|
||||
}
|
||||
|
||||
@@ -2,17 +2,7 @@ import Foundation
|
||||
import Serialization
|
||||
import VGSL
|
||||
|
||||
struct UntypedDivTemplateResolver {
|
||||
private enum Origin {
|
||||
case instance
|
||||
case template
|
||||
}
|
||||
|
||||
private struct OriginValue {
|
||||
let value: Any
|
||||
let origin: Origin
|
||||
}
|
||||
|
||||
final class UntypedDivTemplateResolver {
|
||||
private let templates: [TemplateName: Any]
|
||||
private let templateToType: [TemplateName: String]
|
||||
private var resolvedTemplateCache: [TemplateName: [String: Any]] = [:]
|
||||
@@ -24,131 +14,27 @@ struct UntypedDivTemplateResolver {
|
||||
templateToType = calculateTemplateToType(in: templates)
|
||||
}
|
||||
|
||||
mutating func resolve(card: [String: Any]) -> DeserializationResult<[String: Any]> {
|
||||
resolveDictionary(
|
||||
card,
|
||||
linkSource: card,
|
||||
origin: .instance
|
||||
)
|
||||
func resolveFlat(_ dictionary: [String: Any]) -> [String: Any] {
|
||||
guard let templateName = dictionary["type"] as? String,
|
||||
templates[templateName] != nil else {
|
||||
return dictionary
|
||||
}
|
||||
|
||||
let resolvedTemplate = resolveTemplate(named: templateName)
|
||||
guard let templateValue = resolvedTemplate.value else {
|
||||
return dictionary
|
||||
}
|
||||
|
||||
var merged = templateValue
|
||||
for (key, value) in dictionary {
|
||||
merged[key] = value
|
||||
}
|
||||
merged["type"] = templateToType[templateName] ?? templateName
|
||||
|
||||
return resolveLinks(in: merged, linkSource: dictionary)
|
||||
}
|
||||
|
||||
private mutating func resolveDictionary(
|
||||
_ dictionary: [String: Any],
|
||||
linkSource: [String: Any],
|
||||
origin: Origin
|
||||
) -> DeserializationResult<[String: Any]> {
|
||||
var values: [String: OriginValue] = [:]
|
||||
|
||||
if let templateName = dictionary["type"] as? String, templates[templateName] != nil {
|
||||
let resolvedTemplate = resolveTemplate(named: templateName)
|
||||
guard let templateValue = resolvedTemplate.value else {
|
||||
return .failure(normalizedErrors(from: resolvedTemplate.errorsOrWarnings))
|
||||
}
|
||||
|
||||
values = templateValue.mapValues { OriginValue(value: $0, origin: .template) }
|
||||
for (key, value) in dictionary {
|
||||
values[key] = OriginValue(value: value, origin: .instance)
|
||||
}
|
||||
values["type"] = OriginValue(
|
||||
value: templateToType[templateName] ?? templateName,
|
||||
origin: .template
|
||||
)
|
||||
} else {
|
||||
values = dictionary.mapValues { OriginValue(value: $0, origin: origin) }
|
||||
}
|
||||
|
||||
let currentLinkSource = origin == .instance ? dictionary : linkSource
|
||||
substituteLinks(values: &values, linkSource: currentLinkSource)
|
||||
|
||||
var resolved: [String: Any] = [:]
|
||||
var errors: [DeserializationError] = []
|
||||
|
||||
for (key, value) in values {
|
||||
guard !key.hasPrefix("$") else { continue }
|
||||
|
||||
let childResult = resolveAny(
|
||||
value.value,
|
||||
linkSource: currentLinkSource,
|
||||
origin: value.origin
|
||||
)
|
||||
if let resolvedChild = childResult.value {
|
||||
resolved[key] = resolvedChild
|
||||
}
|
||||
if let childErrors = childResult.errorsOrWarnings {
|
||||
errors.append(contentsOf: childErrors.map { .nestedObjectError(field: key, error: $0) })
|
||||
}
|
||||
}
|
||||
|
||||
if let warnings = NonEmptyArray(errors) {
|
||||
return .partialSuccess(resolved, warnings: warnings)
|
||||
}
|
||||
return .success(resolved)
|
||||
}
|
||||
|
||||
private mutating func resolveArray(
|
||||
_ array: [Any],
|
||||
linkSource: [String: Any],
|
||||
origin: Origin
|
||||
) -> DeserializationResult<[Any]> {
|
||||
var result: [Any] = []
|
||||
var errors: [DeserializationError] = []
|
||||
result.reserveCapacity(array.count)
|
||||
|
||||
for index in array.indices {
|
||||
let child = array[index]
|
||||
let childResult: DeserializationResult<Any>
|
||||
if let dictionary = child as? [String: Any] {
|
||||
let childLinkSource = origin == .instance ? dictionary : linkSource
|
||||
childResult = resolveDictionary(
|
||||
dictionary,
|
||||
linkSource: childLinkSource,
|
||||
origin: origin == .instance ? .instance : .template
|
||||
).map { $0 as Any }
|
||||
} else if let nestedArray = child as? [Any] {
|
||||
childResult = resolveArray(
|
||||
nestedArray,
|
||||
linkSource: linkSource,
|
||||
origin: origin
|
||||
).map { $0 as Any }
|
||||
} else {
|
||||
childResult = .success(child)
|
||||
}
|
||||
|
||||
if let value = childResult.value {
|
||||
result.append(value)
|
||||
}
|
||||
if let childErrors = childResult.errorsOrWarnings {
|
||||
errors
|
||||
.append(contentsOf: childErrors.map { .nestedObjectError(field: "\(index)", error: $0) })
|
||||
}
|
||||
}
|
||||
|
||||
if let warnings = NonEmptyArray(errors) {
|
||||
return .partialSuccess(result, warnings: warnings)
|
||||
}
|
||||
return .success(result)
|
||||
}
|
||||
|
||||
private mutating func resolveAny(
|
||||
_ value: Any,
|
||||
linkSource: [String: Any],
|
||||
origin: Origin
|
||||
) -> DeserializationResult<Any> {
|
||||
if let dictionary = value as? [String: Any] {
|
||||
let childLinkSource = origin == .instance ? dictionary : linkSource
|
||||
return resolveDictionary(
|
||||
dictionary,
|
||||
linkSource: childLinkSource,
|
||||
origin: origin == .instance ? .instance : .template
|
||||
).map { $0 as Any }
|
||||
}
|
||||
if let array = value as? [Any] {
|
||||
return resolveArray(array, linkSource: linkSource, origin: origin).map { $0 as Any }
|
||||
}
|
||||
return .success(value)
|
||||
}
|
||||
|
||||
private mutating func resolveTemplate(named templateName: TemplateName)
|
||||
private func resolveTemplate(named templateName: TemplateName)
|
||||
-> DeserializationResult<[String: Any]> {
|
||||
if let cached = resolvedTemplateCache[templateName] {
|
||||
return .success(cached)
|
||||
@@ -185,15 +71,92 @@ struct UntypedDivTemplateResolver {
|
||||
return .success(result)
|
||||
}
|
||||
|
||||
private func substituteLinks(values: inout [String: OriginValue], linkSource: [String: Any]) {
|
||||
let linkValues = values.filter { $0.key.hasPrefix("$") }
|
||||
for (linkKey, linkValue) in linkValues {
|
||||
private func resolveLinks(
|
||||
in dictionary: [String: Any],
|
||||
linkSource: [String: Any]
|
||||
) -> [String: Any] {
|
||||
var dict = dictionary
|
||||
let linkKeys = dict.keys.filter { $0.hasPrefix("$") }
|
||||
for linkKey in linkKeys {
|
||||
let key = String(linkKey.dropFirst())
|
||||
guard values[key] == nil else { continue }
|
||||
guard let linkName = linkValue.value as? String else { continue }
|
||||
guard dict[key] == nil else { continue }
|
||||
guard let linkName = dict[linkKey] as? String else { continue }
|
||||
guard let value = linkSource[linkName] else { continue }
|
||||
values[key] = OriginValue(value: value, origin: .instance)
|
||||
dict[key] = value
|
||||
}
|
||||
|
||||
var result: [String: Any] = [:]
|
||||
for (key, value) in dict {
|
||||
guard !key.hasPrefix("$") else { continue }
|
||||
result[key] = resolveLinksInValue(value, linkSource: linkSource)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
private func resolveLinksInValue(
|
||||
_ value: Any,
|
||||
linkSource: [String: Any]
|
||||
) -> Any {
|
||||
if let dict = value as? [String: Any] {
|
||||
if let type = dict["type"] as? String,
|
||||
let resolvedTemplate = resolveTemplate(named: type).value {
|
||||
let parameterNames = collectParameterNames(from: resolvedTemplate)
|
||||
return resolveInstanceLinks(
|
||||
in: dict,
|
||||
linkSource: linkSource,
|
||||
parameterNames: parameterNames
|
||||
)
|
||||
}
|
||||
return resolveLinks(in: dict, linkSource: linkSource)
|
||||
}
|
||||
if let array = value as? [Any] {
|
||||
return array.map { resolveLinksInValue($0, linkSource: linkSource) }
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
private func resolveInstanceLinks(
|
||||
in dictionary: [String: Any],
|
||||
linkSource: [String: Any],
|
||||
parameterNames: Set<String>
|
||||
) -> [String: Any] {
|
||||
var dict = dictionary
|
||||
let linkKeys = dict.keys.filter { $0.hasPrefix("$") }
|
||||
for linkKey in linkKeys {
|
||||
let key = String(linkKey.dropFirst())
|
||||
guard dict[key] == nil else { continue }
|
||||
guard !parameterNames.contains(key) else { continue }
|
||||
guard let linkName = dict[linkKey] as? String else { continue }
|
||||
guard let value = linkSource[linkName] else { continue }
|
||||
dict[key] = value
|
||||
}
|
||||
|
||||
var result: [String: Any] = [:]
|
||||
for (key, value) in dict {
|
||||
guard !key.hasPrefix("$") else { continue }
|
||||
result[key] = value
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
private func collectParameterNames(from dict: [String: Any]) -> Set<String> {
|
||||
var names = Set<String>()
|
||||
for (key, value) in dict {
|
||||
if key.hasPrefix("$"), let name = value as? String {
|
||||
names.insert(name)
|
||||
}
|
||||
if let nestedDict = value as? [String: Any] {
|
||||
names.formUnion(collectParameterNames(from: nestedDict))
|
||||
}
|
||||
if let array = value as? [Any] {
|
||||
for element in array {
|
||||
if let elementDict = element as? [String: Any] {
|
||||
names.formUnion(collectParameterNames(from: elementDict))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return names
|
||||
}
|
||||
}
|
||||
|
||||
@@ -202,18 +165,3 @@ private func normalizedErrors(
|
||||
) -> NonEmptyArray<DeserializationError> {
|
||||
errors ?? NonEmptyArray(.generic)
|
||||
}
|
||||
|
||||
extension DeserializationResult {
|
||||
fileprivate func map<U>(_ transform: (T) -> U) -> DeserializationResult<U> {
|
||||
switch self {
|
||||
case let .success(value):
|
||||
.success(transform(value))
|
||||
case let .partialSuccess(value, warnings):
|
||||
.partialSuccess(transform(value), warnings: warnings)
|
||||
case let .failure(errors):
|
||||
.failure(errors)
|
||||
case .noValue:
|
||||
.noValue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,6 +105,7 @@ public enum Div: Sendable {
|
||||
|
||||
extension Div {
|
||||
public init(dictionary: [String: Any], context: ParsingContext) throws {
|
||||
let dictionary = context.templateResolver?(dictionary) ?? dictionary
|
||||
let blockType = try dictionary.getField("type") as String
|
||||
switch blockType {
|
||||
case DivImage.type:
|
||||
@@ -142,7 +143,7 @@ extension Div {
|
||||
case DivVideo.type:
|
||||
self = .divVideo(try DivVideo(dictionary: dictionary, context: context))
|
||||
default:
|
||||
throw DeserializationError.invalidFieldRepresentation(field: "div", representation: dictionary)
|
||||
throw DeserializationError.requiredFieldIsMissing(field: "type")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ public final class DivActionArrayInsertValue: Sendable {
|
||||
public convenience init(dictionary: [String: Any], context: ParsingContext) throws {
|
||||
self.init(
|
||||
index: try dictionary.getOptionalExpressionField("index", context: context),
|
||||
value: try dictionary.getField("value", transform: { (dict: [String: Any]) in try DivTypedValue(dictionary: dict, context: context) }),
|
||||
value: try dictionary.getField("value", transform: { (dict: [String: Any]) in try DivTypedValue(dictionary: dict, context: context) }, context: context),
|
||||
variableName: try dictionary.getExpressionField("variable_name", context: context)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ public final class DivActionArraySetValue: Sendable {
|
||||
public convenience init(dictionary: [String: Any], context: ParsingContext) throws {
|
||||
self.init(
|
||||
index: try dictionary.getExpressionField("index", context: context),
|
||||
value: try dictionary.getField("value", transform: { (dict: [String: Any]) in try DivTypedValue(dictionary: dict, context: context) }),
|
||||
value: try dictionary.getField("value", transform: { (dict: [String: Any]) in try DivTypedValue(dictionary: dict, context: context) }, context: context),
|
||||
variableName: try dictionary.getExpressionField("variable_name", context: context)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ public final class DivActionCopyToClipboard: Sendable {
|
||||
|
||||
public convenience init(dictionary: [String: Any], context: ParsingContext) throws {
|
||||
self.init(
|
||||
content: try dictionary.getField("content", transform: { (dict: [String: Any]) in try DivActionCopyToClipboardContent(dictionary: dict, context: context) })
|
||||
content: try dictionary.getField("content", transform: { (dict: [String: Any]) in try DivActionCopyToClipboardContent(dictionary: dict, context: context) }, context: context)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ public enum DivActionCopyToClipboardContent: Sendable {
|
||||
|
||||
extension DivActionCopyToClipboardContent {
|
||||
public init(dictionary: [String: Any], context: ParsingContext) throws {
|
||||
let dictionary = context.templateResolver?(dictionary) ?? dictionary
|
||||
let blockType = try dictionary.getField("type") as String
|
||||
switch blockType {
|
||||
case ContentText.type:
|
||||
@@ -28,7 +29,7 @@ extension DivActionCopyToClipboardContent {
|
||||
case ContentUrl.type:
|
||||
self = .contentUrl(try ContentUrl(dictionary: dictionary, context: context))
|
||||
default:
|
||||
throw DeserializationError.invalidFieldRepresentation(field: "div-action-copy-to-clipboard-content", representation: dictionary)
|
||||
throw DeserializationError.requiredFieldIsMissing(field: "type")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ extension DivActionCopyToClipboardContentTemplate {
|
||||
case ContentUrlTemplate.type:
|
||||
self = .contentUrlTemplate(try ContentUrlTemplate(dictionary: dictionary, templateToType: templateToType))
|
||||
default:
|
||||
throw DeserializationError.invalidFieldRepresentation(field: "div-action-copy-to-clipboard-content_template", representation: dictionary)
|
||||
throw DeserializationError.requiredFieldIsMissing(field: "type")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ public enum DivActionScrollDestination: Sendable {
|
||||
|
||||
extension DivActionScrollDestination {
|
||||
public init(dictionary: [String: Any], context: ParsingContext) throws {
|
||||
let dictionary = context.templateResolver?(dictionary) ?? dictionary
|
||||
let blockType = try dictionary.getField("type") as String
|
||||
switch blockType {
|
||||
case OffsetDestination.type:
|
||||
@@ -38,7 +39,7 @@ extension DivActionScrollDestination {
|
||||
case EndDestination.type:
|
||||
self = .endDestination(try EndDestination(dictionary: dictionary, context: context))
|
||||
default:
|
||||
throw DeserializationError.invalidFieldRepresentation(field: "div-action-scroll-destination", representation: dictionary)
|
||||
throw DeserializationError.requiredFieldIsMissing(field: "type")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,7 +140,7 @@ extension DivActionScrollDestinationTemplate {
|
||||
case EndDestinationTemplate.type:
|
||||
self = .endDestinationTemplate(try EndDestinationTemplate(dictionary: dictionary, templateToType: templateToType))
|
||||
default:
|
||||
throw DeserializationError.invalidFieldRepresentation(field: "div-action-scroll-destination_template", representation: dictionary)
|
||||
throw DeserializationError.requiredFieldIsMissing(field: "type")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ public final class DivActionScrollTo: Sendable {
|
||||
public convenience init(dictionary: [String: Any], context: ParsingContext) throws {
|
||||
self.init(
|
||||
animated: try dictionary.getOptionalExpressionField("animated", context: context),
|
||||
destination: try dictionary.getField("destination", transform: { (dict: [String: Any]) in try DivActionScrollDestination(dictionary: dict, context: context) }),
|
||||
destination: try dictionary.getField("destination", transform: { (dict: [String: Any]) in try DivActionScrollDestination(dictionary: dict, context: context) }, context: context),
|
||||
id: try dictionary.getExpressionField("id", context: context)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ public final class DivActionSetStoredValue: Sendable {
|
||||
self.init(
|
||||
lifetime: try dictionary.getExpressionField("lifetime", context: context),
|
||||
name: try dictionary.getExpressionField("name", context: context),
|
||||
value: try dictionary.getField("value", transform: { (dict: [String: Any]) in try DivTypedValue(dictionary: dict, context: context) })
|
||||
value: try dictionary.getField("value", transform: { (dict: [String: Any]) in try DivTypedValue(dictionary: dict, context: context) }, context: context)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ public final class DivActionSetVariable: Sendable {
|
||||
|
||||
public convenience init(dictionary: [String: Any], context: ParsingContext) throws {
|
||||
self.init(
|
||||
value: try dictionary.getField("value", transform: { (dict: [String: Any]) in try DivTypedValue(dictionary: dict, context: context) }),
|
||||
value: try dictionary.getField("value", transform: { (dict: [String: Any]) in try DivTypedValue(dictionary: dict, context: context) }, context: context),
|
||||
variableName: try dictionary.getExpressionField("variable_name", context: context)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ public final class DivActionSubmit: Sendable {
|
||||
containerId: try dictionary.getExpressionField("container_id", context: context),
|
||||
onFailActions: try dictionary.getOptionalArray("on_fail_actions", transform: { (dict: [String: Any]) in try? DivAction(dictionary: dict, context: context) }),
|
||||
onSuccessActions: try dictionary.getOptionalArray("on_success_actions", transform: { (dict: [String: Any]) in try? DivAction(dictionary: dict, context: context) }),
|
||||
request: try dictionary.getField("request", transform: { (dict: [String: Any]) in try DivActionSubmit.Request(dictionary: dict, context: context) })
|
||||
request: try dictionary.getField("request", transform: { (dict: [String: Any]) in try DivActionSubmit.Request(dictionary: dict, context: context) }, context: context)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -81,6 +81,7 @@ public enum DivActionTyped: Sendable {
|
||||
|
||||
extension DivActionTyped {
|
||||
public init(dictionary: [String: Any], context: ParsingContext) throws {
|
||||
let dictionary = context.templateResolver?(dictionary) ?? dictionary
|
||||
let blockType = try dictionary.getField("type") as String
|
||||
switch blockType {
|
||||
case DivActionAnimatorStart.type:
|
||||
@@ -128,7 +129,7 @@ extension DivActionTyped {
|
||||
case DivActionCustom.type:
|
||||
self = .divActionCustom(try DivActionCustom(dictionary: dictionary, context: context))
|
||||
default:
|
||||
throw DeserializationError.invalidFieldRepresentation(field: "div-action-typed", representation: dictionary)
|
||||
throw DeserializationError.requiredFieldIsMissing(field: "type")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -554,7 +554,7 @@ extension DivActionTypedTemplate {
|
||||
case DivActionCustomTemplate.type:
|
||||
self = .divActionCustomTemplate(try DivActionCustomTemplate(dictionary: dictionary, templateToType: templateToType))
|
||||
default:
|
||||
throw DeserializationError.invalidFieldRepresentation(field: "div-action-typed_template", representation: dictionary)
|
||||
throw DeserializationError.requiredFieldIsMissing(field: "type")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ public final class DivActionUpdateStructure: Sendable {
|
||||
public convenience init(dictionary: [String: Any], context: ParsingContext) throws {
|
||||
self.init(
|
||||
path: try dictionary.getExpressionField("path", validator: Self.pathValidator, context: context),
|
||||
value: try dictionary.getField("value", transform: { (dict: [String: Any]) in try DivTypedValue(dictionary: dict, context: context) }),
|
||||
value: try dictionary.getField("value", transform: { (dict: [String: Any]) in try DivTypedValue(dictionary: dict, context: context) }, context: context),
|
||||
variableName: try dictionary.getExpressionField("variable_name", context: context)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ public enum DivAnimator: Sendable {
|
||||
|
||||
extension DivAnimator {
|
||||
public init(dictionary: [String: Any], context: ParsingContext) throws {
|
||||
let dictionary = context.templateResolver?(dictionary) ?? dictionary
|
||||
let blockType = try dictionary.getField("type") as String
|
||||
switch blockType {
|
||||
case DivColorAnimator.type:
|
||||
@@ -37,7 +38,7 @@ extension DivAnimator {
|
||||
case DivNumberAnimator.type:
|
||||
self = .divNumberAnimator(try DivNumberAnimator(dictionary: dictionary, context: context))
|
||||
default:
|
||||
throw DeserializationError.invalidFieldRepresentation(field: "div-animator", representation: dictionary)
|
||||
throw DeserializationError.requiredFieldIsMissing(field: "type")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ extension DivAnimatorTemplate {
|
||||
case DivNumberAnimatorTemplate.type:
|
||||
self = .divNumberAnimatorTemplate(try DivNumberAnimatorTemplate(dictionary: dictionary, templateToType: templateToType))
|
||||
default:
|
||||
throw DeserializationError.invalidFieldRepresentation(field: "div-animator_template", representation: dictionary)
|
||||
throw DeserializationError.requiredFieldIsMissing(field: "type")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ public final class DivAppearanceSetTransition: Sendable {
|
||||
|
||||
public convenience init(dictionary: [String: Any], context: ParsingContext) throws {
|
||||
self.init(
|
||||
items: try dictionary.getArray("items", transform: { (dict: [String: Any]) in try? DivAppearanceTransition(dictionary: dict, context: context) }, validator: Self.itemsValidator)
|
||||
items: try dictionary.getArray("items", transform: { (dict: [String: Any]) in try? DivAppearanceTransition(dictionary: dict, context: context) }, validator: Self.itemsValidator, context: context)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ public enum DivAppearanceTransition: Sendable {
|
||||
|
||||
extension DivAppearanceTransition {
|
||||
public init(dictionary: [String: Any], context: ParsingContext) throws {
|
||||
let dictionary = context.templateResolver?(dictionary) ?? dictionary
|
||||
let blockType = try dictionary.getField("type") as String
|
||||
switch blockType {
|
||||
case DivAppearanceSetTransition.type:
|
||||
@@ -38,7 +39,7 @@ extension DivAppearanceTransition {
|
||||
case DivSlideTransition.type:
|
||||
self = .divSlideTransition(try DivSlideTransition(dictionary: dictionary, context: context))
|
||||
default:
|
||||
throw DeserializationError.invalidFieldRepresentation(field: "div-appearance-transition", representation: dictionary)
|
||||
throw DeserializationError.requiredFieldIsMissing(field: "type")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,7 +140,7 @@ extension DivAppearanceTransitionTemplate {
|
||||
case DivSlideTransitionTemplate.type:
|
||||
self = .divSlideTransitionTemplate(try DivSlideTransitionTemplate(dictionary: dictionary, templateToType: templateToType))
|
||||
default:
|
||||
throw DeserializationError.invalidFieldRepresentation(field: "div-appearance-transition_template", representation: dictionary)
|
||||
throw DeserializationError.requiredFieldIsMissing(field: "type")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ public enum DivBackground: Sendable {
|
||||
|
||||
extension DivBackground {
|
||||
public init(dictionary: [String: Any], context: ParsingContext) throws {
|
||||
let dictionary = context.templateResolver?(dictionary) ?? dictionary
|
||||
let blockType = try dictionary.getField("type") as String
|
||||
switch blockType {
|
||||
case DivLinearGradient.type:
|
||||
@@ -43,7 +44,7 @@ extension DivBackground {
|
||||
case DivNinePatchBackground.type:
|
||||
self = .divNinePatchBackground(try DivNinePatchBackground(dictionary: dictionary, context: context))
|
||||
default:
|
||||
throw DeserializationError.invalidFieldRepresentation(field: "div-background", representation: dictionary)
|
||||
throw DeserializationError.requiredFieldIsMissing(field: "type")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,7 +163,7 @@ extension DivBackgroundTemplate {
|
||||
case DivNinePatchBackgroundTemplate.type:
|
||||
self = .divNinePatchBackgroundTemplate(try DivNinePatchBackgroundTemplate(dictionary: dictionary, templateToType: templateToType))
|
||||
default:
|
||||
throw DeserializationError.invalidFieldRepresentation(field: "div-background_template", representation: dictionary)
|
||||
throw DeserializationError.requiredFieldIsMissing(field: "type")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ public final class DivChangeSetTransition: Sendable {
|
||||
|
||||
public convenience init(dictionary: [String: Any], context: ParsingContext) throws {
|
||||
self.init(
|
||||
items: try dictionary.getArray("items", transform: { (dict: [String: Any]) in try? DivChangeTransition(dictionary: dict, context: context) }, validator: Self.itemsValidator)
|
||||
items: try dictionary.getArray("items", transform: { (dict: [String: Any]) in try? DivChangeTransition(dictionary: dict, context: context) }, validator: Self.itemsValidator, context: context)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ public enum DivChangeTransition: Sendable {
|
||||
|
||||
extension DivChangeTransition {
|
||||
public init(dictionary: [String: Any], context: ParsingContext) throws {
|
||||
let dictionary = context.templateResolver?(dictionary) ?? dictionary
|
||||
let blockType = try dictionary.getField("type") as String
|
||||
switch blockType {
|
||||
case DivChangeSetTransition.type:
|
||||
@@ -28,7 +29,7 @@ extension DivChangeTransition {
|
||||
case DivChangeBoundsTransition.type:
|
||||
self = .divChangeBoundsTransition(try DivChangeBoundsTransition(dictionary: dictionary, context: context))
|
||||
default:
|
||||
throw DeserializationError.invalidFieldRepresentation(field: "div-change-transition", representation: dictionary)
|
||||
throw DeserializationError.requiredFieldIsMissing(field: "type")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ extension DivChangeTransitionTemplate {
|
||||
case DivChangeBoundsTransitionTemplate.type:
|
||||
self = .divChangeBoundsTransitionTemplate(try DivChangeBoundsTransitionTemplate(dictionary: dictionary, templateToType: templateToType))
|
||||
default:
|
||||
throw DeserializationError.invalidFieldRepresentation(field: "div-change-transition_template", representation: dictionary)
|
||||
throw DeserializationError.requiredFieldIsMissing(field: "type")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ public final class DivCollectionItemBuilder: @unchecked Sendable {
|
||||
|
||||
public convenience init(dictionary: [String: Any], context: ParsingContext) throws {
|
||||
self.init(
|
||||
div: try dictionary.getField("div", transform: { (dict: [String: Any]) in try Div(dictionary: dict, context: context) }),
|
||||
div: try dictionary.getField("div", transform: { (dict: [String: Any]) in try Div(dictionary: dict, context: context) }, context: context),
|
||||
id: try dictionary.getOptionalExpressionField("id", context: context),
|
||||
selector: try dictionary.getOptionalExpressionField("selector", context: context)
|
||||
)
|
||||
@@ -52,7 +52,7 @@ public final class DivCollectionItemBuilder: @unchecked Sendable {
|
||||
self.init(
|
||||
data: try dictionary.getExpressionField("data", context: context),
|
||||
dataElementName: try dictionary.getOptionalField("data_element_name", context: context),
|
||||
prototypes: try dictionary.getArray("prototypes", transform: { (dict: [String: Any]) in try? DivCollectionItemBuilder.Prototype(dictionary: dict, context: context) }, validator: Self.prototypesValidator)
|
||||
prototypes: try dictionary.getArray("prototypes", transform: { (dict: [String: Any]) in try? DivCollectionItemBuilder.Prototype(dictionary: dict, context: context) }, validator: Self.prototypesValidator, context: context)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ public final class DivContainer: DivBase, Sendable {
|
||||
showAtEnd: try dictionary.getOptionalExpressionField("show_at_end", context: context),
|
||||
showAtStart: try dictionary.getOptionalExpressionField("show_at_start", context: context),
|
||||
showBetween: try dictionary.getOptionalExpressionField("show_between", context: context),
|
||||
style: try dictionary.getField("style", transform: { (dict: [String: Any]) in try DivDrawable(dictionary: dict, context: context) })
|
||||
style: try dictionary.getField("style", transform: { (dict: [String: Any]) in try DivDrawable(dictionary: dict, context: context) }, context: context)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ public enum DivCount: Sendable {
|
||||
|
||||
extension DivCount {
|
||||
public init(dictionary: [String: Any], context: ParsingContext) throws {
|
||||
let dictionary = context.templateResolver?(dictionary) ?? dictionary
|
||||
let blockType = try dictionary.getField("type") as String
|
||||
switch blockType {
|
||||
case DivInfinityCount.type:
|
||||
@@ -28,7 +29,7 @@ extension DivCount {
|
||||
case DivFixedCount.type:
|
||||
self = .divFixedCount(try DivFixedCount(dictionary: dictionary, context: context))
|
||||
default:
|
||||
throw DeserializationError.invalidFieldRepresentation(field: "div-count", representation: dictionary)
|
||||
throw DeserializationError.requiredFieldIsMissing(field: "type")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ extension DivCountTemplate {
|
||||
case DivFixedCountTemplate.type:
|
||||
self = .divFixedCountTemplate(try DivFixedCountTemplate(dictionary: dictionary, templateToType: templateToType))
|
||||
default:
|
||||
throw DeserializationError.invalidFieldRepresentation(field: "div-count_template", representation: dictionary)
|
||||
throw DeserializationError.requiredFieldIsMissing(field: "type")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ public final class DivData: Sendable {
|
||||
|
||||
public convenience init(dictionary: [String: Any], context: ParsingContext) throws {
|
||||
self.init(
|
||||
div: try dictionary.getField("div", transform: { (dict: [String: Any]) in try Div(dictionary: dict, context: context) }),
|
||||
div: try dictionary.getField("div", transform: { (dict: [String: Any]) in try Div(dictionary: dict, context: context) }, context: context),
|
||||
stateId: try dictionary.getField("state_id", context: context)
|
||||
)
|
||||
}
|
||||
@@ -44,7 +44,7 @@ public final class DivData: Sendable {
|
||||
self.init(
|
||||
functions: try dictionary.getOptionalArray("functions", transform: { (dict: [String: Any]) in try? DivFunction(dictionary: dict, context: context) }),
|
||||
logId: try dictionary.getField("log_id", context: context),
|
||||
states: try dictionary.getArray("states", transform: { (dict: [String: Any]) in try? DivData.State(dictionary: dict, context: context) }, validator: Self.statesValidator),
|
||||
states: try dictionary.getArray("states", transform: { (dict: [String: Any]) in try? DivData.State(dictionary: dict, context: context) }, validator: Self.statesValidator, context: context),
|
||||
timers: try dictionary.getOptionalArray("timers", transform: { (dict: [String: Any]) in try? DivTimer(dictionary: dict, context: context) }),
|
||||
transitionAnimationSelector: try dictionary.getOptionalExpressionField("transition_animation_selector", context: context),
|
||||
variableTriggers: try dictionary.getOptionalArray("variable_triggers", transform: { (dict: [String: Any]) in try? DivTrigger(dictionary: dict, context: context) }),
|
||||
|
||||
@@ -18,12 +18,13 @@ public enum DivDrawable: Sendable {
|
||||
|
||||
extension DivDrawable {
|
||||
public init(dictionary: [String: Any], context: ParsingContext) throws {
|
||||
let dictionary = context.templateResolver?(dictionary) ?? dictionary
|
||||
let blockType = try dictionary.getField("type") as String
|
||||
switch blockType {
|
||||
case DivShapeDrawable.type:
|
||||
self = .divShapeDrawable(try DivShapeDrawable(dictionary: dictionary, context: context))
|
||||
default:
|
||||
throw DeserializationError.invalidFieldRepresentation(field: "div-drawable", representation: dictionary)
|
||||
throw DeserializationError.requiredFieldIsMissing(field: "type")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ extension DivDrawableTemplate {
|
||||
case DivShapeDrawableTemplate.type:
|
||||
self = .divShapeDrawableTemplate(try DivShapeDrawableTemplate(dictionary: dictionary, templateToType: templateToType))
|
||||
default:
|
||||
throw DeserializationError.invalidFieldRepresentation(field: "div-drawable_template", representation: dictionary)
|
||||
throw DeserializationError.requiredFieldIsMissing(field: "type")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ public enum DivFilter: Sendable {
|
||||
|
||||
extension DivFilter {
|
||||
public init(dictionary: [String: Any], context: ParsingContext) throws {
|
||||
let dictionary = context.templateResolver?(dictionary) ?? dictionary
|
||||
let blockType = try dictionary.getField("type") as String
|
||||
switch blockType {
|
||||
case DivBlur.type:
|
||||
@@ -28,7 +29,7 @@ extension DivFilter {
|
||||
case DivFilterRtlMirror.type:
|
||||
self = .divFilterRtlMirror(try DivFilterRtlMirror(dictionary: dictionary, context: context))
|
||||
default:
|
||||
throw DeserializationError.invalidFieldRepresentation(field: "div-filter", representation: dictionary)
|
||||
throw DeserializationError.requiredFieldIsMissing(field: "type")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ extension DivFilterTemplate {
|
||||
case DivFilterRtlMirrorTemplate.type:
|
||||
self = .divFilterRtlMirrorTemplate(try DivFilterRtlMirrorTemplate(dictionary: dictionary, templateToType: templateToType))
|
||||
default:
|
||||
throw DeserializationError.invalidFieldRepresentation(field: "div-filter_template", representation: dictionary)
|
||||
throw DeserializationError.requiredFieldIsMissing(field: "type")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ public final class DivFixedLengthInputMask: DivInputMaskBase, Sendable {
|
||||
self.init(
|
||||
alwaysVisible: try dictionary.getOptionalExpressionField("always_visible", context: context),
|
||||
pattern: try dictionary.getExpressionField("pattern", context: context),
|
||||
patternElements: try dictionary.getArray("pattern_elements", transform: { (dict: [String: Any]) in try? DivFixedLengthInputMask.PatternElement(dictionary: dict, context: context) }, validator: Self.patternElementsValidator),
|
||||
patternElements: try dictionary.getArray("pattern_elements", transform: { (dict: [String: Any]) in try? DivFixedLengthInputMask.PatternElement(dictionary: dict, context: context) }, validator: Self.patternElementsValidator, context: context),
|
||||
rawTextVariable: try dictionary.getField("raw_text_variable", context: context)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ public final class DivFunction: Sendable {
|
||||
|
||||
public convenience init(dictionary: [String: Any], context: ParsingContext) throws {
|
||||
self.init(
|
||||
arguments: try dictionary.getArray("arguments", transform: { (dict: [String: Any]) in try? DivFunctionArgument(dictionary: dict, context: context) }),
|
||||
arguments: try dictionary.getArray("arguments", transform: { (dict: [String: Any]) in try? DivFunctionArgument(dictionary: dict, context: context) }, context: context),
|
||||
body: try dictionary.getField("body", context: context),
|
||||
name: try dictionary.getField("name", validator: Self.nameValidator, context: context),
|
||||
returnType: try dictionary.getField("return_type", context: context)
|
||||
|
||||
@@ -21,6 +21,7 @@ public enum DivIndicatorItemPlacement: Sendable {
|
||||
|
||||
extension DivIndicatorItemPlacement {
|
||||
public init(dictionary: [String: Any], context: ParsingContext) throws {
|
||||
let dictionary = context.templateResolver?(dictionary) ?? dictionary
|
||||
let blockType = try dictionary.getField("type") as String
|
||||
switch blockType {
|
||||
case DivDefaultIndicatorItemPlacement.type:
|
||||
@@ -28,7 +29,7 @@ extension DivIndicatorItemPlacement {
|
||||
case DivStretchIndicatorItemPlacement.type:
|
||||
self = .divStretchIndicatorItemPlacement(try DivStretchIndicatorItemPlacement(dictionary: dictionary, context: context))
|
||||
default:
|
||||
throw DeserializationError.invalidFieldRepresentation(field: "div-indicator-item-placement", representation: dictionary)
|
||||
throw DeserializationError.requiredFieldIsMissing(field: "type")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ extension DivIndicatorItemPlacementTemplate {
|
||||
case DivStretchIndicatorItemPlacementTemplate.type:
|
||||
self = .divStretchIndicatorItemPlacementTemplate(try DivStretchIndicatorItemPlacementTemplate(dictionary: dictionary, templateToType: templateToType))
|
||||
default:
|
||||
throw DeserializationError.invalidFieldRepresentation(field: "div-indicator-item-placement_template", representation: dictionary)
|
||||
throw DeserializationError.requiredFieldIsMissing(field: "type")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ public enum DivInputFilter: Sendable {
|
||||
|
||||
extension DivInputFilter {
|
||||
public init(dictionary: [String: Any], context: ParsingContext) throws {
|
||||
let dictionary = context.templateResolver?(dictionary) ?? dictionary
|
||||
let blockType = try dictionary.getField("type") as String
|
||||
switch blockType {
|
||||
case DivInputFilterRegex.type:
|
||||
@@ -28,7 +29,7 @@ extension DivInputFilter {
|
||||
case DivInputFilterExpression.type:
|
||||
self = .divInputFilterExpression(try DivInputFilterExpression(dictionary: dictionary, context: context))
|
||||
default:
|
||||
throw DeserializationError.invalidFieldRepresentation(field: "div-input-filter", representation: dictionary)
|
||||
throw DeserializationError.requiredFieldIsMissing(field: "type")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ extension DivInputFilterTemplate {
|
||||
case DivInputFilterExpressionTemplate.type:
|
||||
self = .divInputFilterExpressionTemplate(try DivInputFilterExpressionTemplate(dictionary: dictionary, templateToType: templateToType))
|
||||
default:
|
||||
throw DeserializationError.invalidFieldRepresentation(field: "div-input-filter_template", representation: dictionary)
|
||||
throw DeserializationError.requiredFieldIsMissing(field: "type")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ public enum DivInputMask: Sendable {
|
||||
|
||||
extension DivInputMask {
|
||||
public init(dictionary: [String: Any], context: ParsingContext) throws {
|
||||
let dictionary = context.templateResolver?(dictionary) ?? dictionary
|
||||
let blockType = try dictionary.getField("type") as String
|
||||
switch blockType {
|
||||
case DivFixedLengthInputMask.type:
|
||||
@@ -33,7 +34,7 @@ extension DivInputMask {
|
||||
case DivPhoneInputMask.type:
|
||||
self = .divPhoneInputMask(try DivPhoneInputMask(dictionary: dictionary, context: context))
|
||||
default:
|
||||
throw DeserializationError.invalidFieldRepresentation(field: "div-input-mask", representation: dictionary)
|
||||
throw DeserializationError.requiredFieldIsMissing(field: "type")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ extension DivInputMaskTemplate {
|
||||
case DivPhoneInputMaskTemplate.type:
|
||||
self = .divPhoneInputMaskTemplate(try DivPhoneInputMaskTemplate(dictionary: dictionary, templateToType: templateToType))
|
||||
default:
|
||||
throw DeserializationError.invalidFieldRepresentation(field: "div-input-mask_template", representation: dictionary)
|
||||
throw DeserializationError.requiredFieldIsMissing(field: "type")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ public enum DivInputValidator: Sendable {
|
||||
|
||||
extension DivInputValidator {
|
||||
public init(dictionary: [String: Any], context: ParsingContext) throws {
|
||||
let dictionary = context.templateResolver?(dictionary) ?? dictionary
|
||||
let blockType = try dictionary.getField("type") as String
|
||||
switch blockType {
|
||||
case DivInputValidatorRegex.type:
|
||||
@@ -28,7 +29,7 @@ extension DivInputValidator {
|
||||
case DivInputValidatorExpression.type:
|
||||
self = .divInputValidatorExpression(try DivInputValidatorExpression(dictionary: dictionary, context: context))
|
||||
default:
|
||||
throw DeserializationError.invalidFieldRepresentation(field: "div-input-validator", representation: dictionary)
|
||||
throw DeserializationError.requiredFieldIsMissing(field: "type")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ extension DivInputValidatorTemplate {
|
||||
case DivInputValidatorExpressionTemplate.type:
|
||||
self = .divInputValidatorExpressionTemplate(try DivInputValidatorExpressionTemplate(dictionary: dictionary, templateToType: templateToType))
|
||||
default:
|
||||
throw DeserializationError.invalidFieldRepresentation(field: "div-input-validator_template", representation: dictionary)
|
||||
throw DeserializationError.requiredFieldIsMissing(field: "type")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ public final class DivNeighbourPageSize: Sendable {
|
||||
|
||||
public convenience init(dictionary: [String: Any], context: ParsingContext) throws {
|
||||
self.init(
|
||||
neighbourPageWidth: try dictionary.getField("neighbour_page_width", transform: { (dict: [String: Any]) in try DivFixedSize(dictionary: dict, context: context) })
|
||||
neighbourPageWidth: try dictionary.getField("neighbour_page_width", transform: { (dict: [String: Any]) in try DivFixedSize(dictionary: dict, context: context) }, context: context)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ public final class DivNinePatchBackground: Sendable {
|
||||
public convenience init(dictionary: [String: Any], context: ParsingContext) throws {
|
||||
self.init(
|
||||
imageUrl: try dictionary.getExpressionField("image_url", transform: URL.makeFromNonEncodedString, context: context),
|
||||
insets: try dictionary.getField("insets", transform: { (dict: [String: Any]) in try DivAbsoluteEdgeInsets(dictionary: dict, context: context) })
|
||||
insets: try dictionary.getField("insets", transform: { (dict: [String: Any]) in try DivAbsoluteEdgeInsets(dictionary: dict, context: context) }, context: context)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ public final class DivPageSize: Sendable {
|
||||
|
||||
public convenience init(dictionary: [String: Any], context: ParsingContext) throws {
|
||||
self.init(
|
||||
pageWidth: try dictionary.getField("page_width", transform: { (dict: [String: Any]) in try DivPercentageSize(dictionary: dict, context: context) })
|
||||
pageWidth: try dictionary.getField("page_width", transform: { (dict: [String: Any]) in try DivPercentageSize(dictionary: dict, context: context) }, context: context)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ public enum DivPageTransformation: Sendable {
|
||||
|
||||
extension DivPageTransformation {
|
||||
public init(dictionary: [String: Any], context: ParsingContext) throws {
|
||||
let dictionary = context.templateResolver?(dictionary) ?? dictionary
|
||||
let blockType = try dictionary.getField("type") as String
|
||||
switch blockType {
|
||||
case DivPageTransformationSlide.type:
|
||||
@@ -28,7 +29,7 @@ extension DivPageTransformation {
|
||||
case DivPageTransformationOverlap.type:
|
||||
self = .divPageTransformationOverlap(try DivPageTransformationOverlap(dictionary: dictionary, context: context))
|
||||
default:
|
||||
throw DeserializationError.invalidFieldRepresentation(field: "div-page-transformation", representation: dictionary)
|
||||
throw DeserializationError.requiredFieldIsMissing(field: "type")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ extension DivPageTransformationTemplate {
|
||||
case DivPageTransformationOverlapTemplate.type:
|
||||
self = .divPageTransformationOverlapTemplate(try DivPageTransformationOverlapTemplate(dictionary: dictionary, templateToType: templateToType))
|
||||
default:
|
||||
throw DeserializationError.invalidFieldRepresentation(field: "div-page-transformation_template", representation: dictionary)
|
||||
throw DeserializationError.requiredFieldIsMissing(field: "type")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,7 +153,7 @@ public final class DivPager: DivBase, Sendable {
|
||||
itemBuilder: try dictionary.getOptionalField("item_builder", transform: { (dict: [String: Any]) in try DivCollectionItemBuilder(dictionary: dict, context: context) }),
|
||||
itemSpacing: try dictionary.getOptionalField("item_spacing", transform: { (dict: [String: Any]) in try DivFixedSize(dictionary: dict, context: context) }),
|
||||
items: try dictionary.getOptionalArray("items", transform: { (dict: [String: Any]) in try? Div(dictionary: dict, context: context) }),
|
||||
layoutMode: try dictionary.getField("layout_mode", transform: { (dict: [String: Any]) in try DivPagerLayoutMode(dictionary: dict, context: context) }),
|
||||
layoutMode: try dictionary.getField("layout_mode", transform: { (dict: [String: Any]) in try DivPagerLayoutMode(dictionary: dict, context: context) }, context: context),
|
||||
layoutProvider: try dictionary.getOptionalField("layout_provider", transform: { (dict: [String: Any]) in try DivLayoutProvider(dictionary: dict, context: context) }),
|
||||
margins: try dictionary.getOptionalField("margins", transform: { (dict: [String: Any]) in try DivEdgeInsets(dictionary: dict, context: context) }),
|
||||
orientation: try dictionary.getOptionalExpressionField("orientation", context: context),
|
||||
|
||||
@@ -24,6 +24,7 @@ public enum DivPagerLayoutMode: Sendable {
|
||||
|
||||
extension DivPagerLayoutMode {
|
||||
public init(dictionary: [String: Any], context: ParsingContext) throws {
|
||||
let dictionary = context.templateResolver?(dictionary) ?? dictionary
|
||||
let blockType = try dictionary.getField("type") as String
|
||||
switch blockType {
|
||||
case DivPageSize.type:
|
||||
@@ -33,7 +34,7 @@ extension DivPagerLayoutMode {
|
||||
case DivPageContentSize.type:
|
||||
self = .divPageContentSize(try DivPageContentSize(dictionary: dictionary, context: context))
|
||||
default:
|
||||
throw DeserializationError.invalidFieldRepresentation(field: "div-pager-layout-mode", representation: dictionary)
|
||||
throw DeserializationError.requiredFieldIsMissing(field: "type")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ extension DivPagerLayoutModeTemplate {
|
||||
case DivPageContentSizeTemplate.type:
|
||||
self = .divPageContentSizeTemplate(try DivPageContentSizeTemplate(dictionary: dictionary, templateToType: templateToType))
|
||||
default:
|
||||
throw DeserializationError.invalidFieldRepresentation(field: "div-pager-layout-mode_template", representation: dictionary)
|
||||
throw DeserializationError.requiredFieldIsMissing(field: "type")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ public final class DivPatch: Sendable {
|
||||
|
||||
public convenience init(dictionary: [String: Any], context: ParsingContext) throws {
|
||||
self.init(
|
||||
changes: try dictionary.getArray("changes", transform: { (dict: [String: Any]) in try? DivPatch.Change(dictionary: dict, context: context) }, validator: Self.changesValidator),
|
||||
changes: try dictionary.getArray("changes", transform: { (dict: [String: Any]) in try? DivPatch.Change(dictionary: dict, context: context) }, validator: Self.changesValidator, context: context),
|
||||
mode: try dictionary.getOptionalExpressionField("mode", context: context),
|
||||
onAppliedActions: try dictionary.getOptionalArray("on_applied_actions", transform: { (dict: [String: Any]) in try? DivAction(dictionary: dict, context: context) }),
|
||||
onFailedActions: try dictionary.getOptionalArray("on_failed_actions", transform: { (dict: [String: Any]) in try? DivAction(dictionary: dict, context: context) })
|
||||
|
||||
@@ -21,6 +21,7 @@ public enum DivPivot: Sendable {
|
||||
|
||||
extension DivPivot {
|
||||
public init(dictionary: [String: Any], context: ParsingContext) throws {
|
||||
let dictionary = context.templateResolver?(dictionary) ?? dictionary
|
||||
let blockType = try dictionary.getField("type") as String
|
||||
switch blockType {
|
||||
case DivPivotFixed.type:
|
||||
@@ -28,7 +29,7 @@ extension DivPivot {
|
||||
case DivPivotPercentage.type:
|
||||
self = .divPivotPercentage(try DivPivotPercentage(dictionary: dictionary, context: context))
|
||||
default:
|
||||
throw DeserializationError.invalidFieldRepresentation(field: "div-pivot", representation: dictionary)
|
||||
throw DeserializationError.requiredFieldIsMissing(field: "type")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ extension DivPivotTemplate {
|
||||
case DivPivotPercentageTemplate.type:
|
||||
self = .divPivotPercentageTemplate(try DivPivotPercentageTemplate(dictionary: dictionary, templateToType: templateToType))
|
||||
default:
|
||||
throw DeserializationError.invalidFieldRepresentation(field: "div-pivot_template", representation: dictionary)
|
||||
throw DeserializationError.requiredFieldIsMissing(field: "type")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,8 +10,8 @@ public final class DivPoint: Sendable {
|
||||
|
||||
public convenience init(dictionary: [String: Any], context: ParsingContext) throws {
|
||||
self.init(
|
||||
x: try dictionary.getField("x", transform: { (dict: [String: Any]) in try DivDimension(dictionary: dict, context: context) }),
|
||||
y: try dictionary.getField("y", transform: { (dict: [String: Any]) in try DivDimension(dictionary: dict, context: context) })
|
||||
x: try dictionary.getField("x", transform: { (dict: [String: Any]) in try DivDimension(dictionary: dict, context: context) }, context: context),
|
||||
y: try dictionary.getField("y", transform: { (dict: [String: Any]) in try DivDimension(dictionary: dict, context: context) }, context: context)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ public enum DivRadialGradientCenter: Sendable {
|
||||
|
||||
extension DivRadialGradientCenter {
|
||||
public init(dictionary: [String: Any], context: ParsingContext) throws {
|
||||
let dictionary = context.templateResolver?(dictionary) ?? dictionary
|
||||
let blockType = try dictionary.getField("type") as String
|
||||
switch blockType {
|
||||
case DivRadialGradientFixedCenter.type:
|
||||
@@ -28,7 +29,7 @@ extension DivRadialGradientCenter {
|
||||
case DivRadialGradientRelativeCenter.type:
|
||||
self = .divRadialGradientRelativeCenter(try DivRadialGradientRelativeCenter(dictionary: dictionary, context: context))
|
||||
default:
|
||||
throw DeserializationError.invalidFieldRepresentation(field: "div-radial-gradient-center", representation: dictionary)
|
||||
throw DeserializationError.requiredFieldIsMissing(field: "type")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ extension DivRadialGradientCenterTemplate {
|
||||
case DivRadialGradientRelativeCenterTemplate.type:
|
||||
self = .divRadialGradientRelativeCenterTemplate(try DivRadialGradientRelativeCenterTemplate(dictionary: dictionary, templateToType: templateToType))
|
||||
default:
|
||||
throw DeserializationError.invalidFieldRepresentation(field: "div-radial-gradient-center_template", representation: dictionary)
|
||||
throw DeserializationError.requiredFieldIsMissing(field: "type")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ public enum DivRadialGradientRadius: Sendable {
|
||||
|
||||
extension DivRadialGradientRadius {
|
||||
public init(dictionary: [String: Any], context: ParsingContext) throws {
|
||||
let dictionary = context.templateResolver?(dictionary) ?? dictionary
|
||||
let blockType = try dictionary.getField("type") as String
|
||||
switch blockType {
|
||||
case DivFixedSize.type:
|
||||
@@ -28,7 +29,7 @@ extension DivRadialGradientRadius {
|
||||
case DivRadialGradientRelativeRadius.type:
|
||||
self = .divRadialGradientRelativeRadius(try DivRadialGradientRelativeRadius(dictionary: dictionary, context: context))
|
||||
default:
|
||||
throw DeserializationError.invalidFieldRepresentation(field: "div-radial-gradient-radius", representation: dictionary)
|
||||
throw DeserializationError.requiredFieldIsMissing(field: "type")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ extension DivRadialGradientRadiusTemplate {
|
||||
case DivRadialGradientRelativeRadiusTemplate.type:
|
||||
self = .divRadialGradientRelativeRadiusTemplate(try DivRadialGradientRelativeRadiusTemplate(dictionary: dictionary, templateToType: templateToType))
|
||||
default:
|
||||
throw DeserializationError.invalidFieldRepresentation(field: "div-radial-gradient-radius_template", representation: dictionary)
|
||||
throw DeserializationError.requiredFieldIsMissing(field: "type")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -205,7 +205,7 @@ public final class DivSelect: DivBase, @unchecked Sendable {
|
||||
letterSpacing: try dictionary.getOptionalExpressionField("letter_spacing", context: context),
|
||||
lineHeight: try dictionary.getOptionalExpressionField("line_height", validator: Self.lineHeightValidator, context: context),
|
||||
margins: try dictionary.getOptionalField("margins", transform: { (dict: [String: Any]) in try DivEdgeInsets(dictionary: dict, context: context) }),
|
||||
options: try dictionary.getArray("options", transform: { (dict: [String: Any]) in try? DivSelect.Option(dictionary: dict, context: context) }, validator: Self.optionsValidator),
|
||||
options: try dictionary.getArray("options", transform: { (dict: [String: Any]) in try? DivSelect.Option(dictionary: dict, context: context) }, validator: Self.optionsValidator, context: context),
|
||||
paddings: try dictionary.getOptionalField("paddings", transform: { (dict: [String: Any]) in try DivEdgeInsets(dictionary: dict, context: context) }),
|
||||
reuseId: try dictionary.getOptionalExpressionField("reuse_id", context: context),
|
||||
rowSpan: try dictionary.getOptionalExpressionField("row_span", validator: Self.rowSpanValidator, context: context),
|
||||
|
||||
@@ -33,7 +33,7 @@ public final class DivShadow: Sendable {
|
||||
alpha: try dictionary.getOptionalExpressionField("alpha", validator: Self.alphaValidator, context: context),
|
||||
blur: try dictionary.getOptionalExpressionField("blur", validator: Self.blurValidator, context: context),
|
||||
color: try dictionary.getOptionalExpressionField("color", transform: Color.color(withHexString:), context: context),
|
||||
offset: try dictionary.getField("offset", transform: { (dict: [String: Any]) in try DivPoint(dictionary: dict, context: context) })
|
||||
offset: try dictionary.getField("offset", transform: { (dict: [String: Any]) in try DivPoint(dictionary: dict, context: context) }, context: context)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ public enum DivShape: Sendable {
|
||||
|
||||
extension DivShape {
|
||||
public init(dictionary: [String: Any], context: ParsingContext) throws {
|
||||
let dictionary = context.templateResolver?(dictionary) ?? dictionary
|
||||
let blockType = try dictionary.getField("type") as String
|
||||
switch blockType {
|
||||
case DivRoundedRectangleShape.type:
|
||||
@@ -28,7 +29,7 @@ extension DivShape {
|
||||
case DivCircleShape.type:
|
||||
self = .divCircleShape(try DivCircleShape(dictionary: dictionary, context: context))
|
||||
default:
|
||||
throw DeserializationError.invalidFieldRepresentation(field: "div-shape", representation: dictionary)
|
||||
throw DeserializationError.requiredFieldIsMissing(field: "type")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ public final class DivShapeDrawable: Sendable {
|
||||
public convenience init(dictionary: [String: Any], context: ParsingContext) throws {
|
||||
self.init(
|
||||
color: try dictionary.getExpressionField("color", transform: Color.color(withHexString:), context: context),
|
||||
shape: try dictionary.getField("shape", transform: { (dict: [String: Any]) in try DivShape(dictionary: dict, context: context) }),
|
||||
shape: try dictionary.getField("shape", transform: { (dict: [String: Any]) in try DivShape(dictionary: dict, context: context) }, context: context),
|
||||
stroke: try dictionary.getOptionalField("stroke", transform: { (dict: [String: Any]) in try DivStroke(dictionary: dict, context: context) })
|
||||
)
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ extension DivShapeTemplate {
|
||||
case DivCircleShapeTemplate.type:
|
||||
self = .divCircleShapeTemplate(try DivCircleShapeTemplate(dictionary: dictionary, templateToType: templateToType))
|
||||
default:
|
||||
throw DeserializationError.invalidFieldRepresentation(field: "div-shape_template", representation: dictionary)
|
||||
throw DeserializationError.requiredFieldIsMissing(field: "type")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ public enum DivSize: Sendable {
|
||||
|
||||
extension DivSize {
|
||||
public init(dictionary: [String: Any], context: ParsingContext) throws {
|
||||
let dictionary = context.templateResolver?(dictionary) ?? dictionary
|
||||
let blockType = try dictionary.getField("type") as String
|
||||
switch blockType {
|
||||
case DivFixedSize.type:
|
||||
@@ -33,7 +34,7 @@ extension DivSize {
|
||||
case DivWrapContentSize.type:
|
||||
self = .divWrapContentSize(try DivWrapContentSize(dictionary: dictionary, context: context))
|
||||
default:
|
||||
throw DeserializationError.invalidFieldRepresentation(field: "div-size", representation: dictionary)
|
||||
throw DeserializationError.requiredFieldIsMissing(field: "type")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ extension DivSizeTemplate {
|
||||
case DivWrapContentSizeTemplate.type:
|
||||
self = .divWrapContentSizeTemplate(try DivWrapContentSizeTemplate(dictionary: dictionary, templateToType: templateToType))
|
||||
default:
|
||||
throw DeserializationError.invalidFieldRepresentation(field: "div-size_template", representation: dictionary)
|
||||
throw DeserializationError.requiredFieldIsMissing(field: "type")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -263,14 +263,14 @@ public final class DivSlider: DivBase, Sendable {
|
||||
thumbSecondaryStyle: try dictionary.getOptionalField("thumb_secondary_style", transform: { (dict: [String: Any]) in try DivDrawable(dictionary: dict, context: context) }),
|
||||
thumbSecondaryTextStyle: try dictionary.getOptionalField("thumb_secondary_text_style", transform: { (dict: [String: Any]) in try DivSlider.TextStyle(dictionary: dict, context: context) }),
|
||||
thumbSecondaryValueVariable: try dictionary.getOptionalField("thumb_secondary_value_variable", context: context),
|
||||
thumbStyle: try dictionary.getField("thumb_style", transform: { (dict: [String: Any]) in try DivDrawable(dictionary: dict, context: context) }),
|
||||
thumbStyle: try dictionary.getField("thumb_style", transform: { (dict: [String: Any]) in try DivDrawable(dictionary: dict, context: context) }, context: context),
|
||||
thumbTextStyle: try dictionary.getOptionalField("thumb_text_style", transform: { (dict: [String: Any]) in try DivSlider.TextStyle(dictionary: dict, context: context) }),
|
||||
thumbValueVariable: try dictionary.getOptionalField("thumb_value_variable", context: context),
|
||||
tickMarkActiveStyle: try dictionary.getOptionalField("tick_mark_active_style", transform: { (dict: [String: Any]) in try DivDrawable(dictionary: dict, context: context) }),
|
||||
tickMarkInactiveStyle: try dictionary.getOptionalField("tick_mark_inactive_style", transform: { (dict: [String: Any]) in try DivDrawable(dictionary: dict, context: context) }),
|
||||
tooltips: try dictionary.getOptionalArray("tooltips", transform: { (dict: [String: Any]) in try? DivTooltip(dictionary: dict, context: context) }),
|
||||
trackActiveStyle: try dictionary.getField("track_active_style", transform: { (dict: [String: Any]) in try DivDrawable(dictionary: dict, context: context) }),
|
||||
trackInactiveStyle: try dictionary.getField("track_inactive_style", transform: { (dict: [String: Any]) in try DivDrawable(dictionary: dict, context: context) }),
|
||||
trackActiveStyle: try dictionary.getField("track_active_style", transform: { (dict: [String: Any]) in try DivDrawable(dictionary: dict, context: context) }, context: context),
|
||||
trackInactiveStyle: try dictionary.getField("track_inactive_style", transform: { (dict: [String: Any]) in try DivDrawable(dictionary: dict, context: context) }, context: context),
|
||||
transform: try dictionary.getOptionalField("transform", transform: { (dict: [String: Any]) in try DivTransform(dictionary: dict, context: context) }),
|
||||
transformations: try dictionary.getOptionalArray("transformations", transform: { (dict: [String: Any]) in try? DivTransformation(dictionary: dict, context: context) }),
|
||||
transitionChange: try dictionary.getOptionalField("transition_change", transform: { (dict: [String: Any]) in try DivChangeTransition(dictionary: dict, context: context) }),
|
||||
|
||||
@@ -183,7 +183,7 @@ public final class DivState: DivBase, Sendable {
|
||||
rowSpan: try dictionary.getOptionalExpressionField("row_span", validator: Self.rowSpanValidator, context: context),
|
||||
selectedActions: try dictionary.getOptionalArray("selected_actions", transform: { (dict: [String: Any]) in try? DivAction(dictionary: dict, context: context) }),
|
||||
stateIdVariable: try dictionary.getOptionalField("state_id_variable", context: context),
|
||||
states: try dictionary.getArray("states", transform: { (dict: [String: Any]) in try? DivState.State(dictionary: dict, context: context) }, validator: Self.statesValidator),
|
||||
states: try dictionary.getArray("states", transform: { (dict: [String: Any]) in try? DivState.State(dictionary: dict, context: context) }, validator: Self.statesValidator, context: context),
|
||||
tooltips: try dictionary.getOptionalArray("tooltips", transform: { (dict: [String: Any]) in try? DivTooltip(dictionary: dict, context: context) }),
|
||||
transform: try dictionary.getOptionalField("transform", transform: { (dict: [String: Any]) in try DivTransform(dictionary: dict, context: context) }),
|
||||
transformations: try dictionary.getOptionalArray("transformations", transform: { (dict: [String: Any]) in try? DivTransformation(dictionary: dict, context: context) }),
|
||||
|
||||
@@ -21,6 +21,7 @@ public enum DivStrokeStyle: Sendable {
|
||||
|
||||
extension DivStrokeStyle {
|
||||
public init(dictionary: [String: Any], context: ParsingContext) throws {
|
||||
let dictionary = context.templateResolver?(dictionary) ?? dictionary
|
||||
let blockType = try dictionary.getField("type") as String
|
||||
switch blockType {
|
||||
case DivStrokeStyleSolid.type:
|
||||
@@ -28,7 +29,7 @@ extension DivStrokeStyle {
|
||||
case DivStrokeStyleDashed.type:
|
||||
self = .divStrokeStyleDashed(try DivStrokeStyleDashed(dictionary: dictionary, context: context))
|
||||
default:
|
||||
throw DeserializationError.invalidFieldRepresentation(field: "div-stroke-style", representation: dictionary)
|
||||
throw DeserializationError.requiredFieldIsMissing(field: "type")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ extension DivStrokeStyleTemplate {
|
||||
case DivStrokeStyleDashedTemplate.type:
|
||||
self = .divStrokeStyleDashedTemplate(try DivStrokeStyleDashedTemplate(dictionary: dictionary, templateToType: templateToType))
|
||||
default:
|
||||
throw DeserializationError.invalidFieldRepresentation(field: "div-stroke-style_template", representation: dictionary)
|
||||
throw DeserializationError.requiredFieldIsMissing(field: "type")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ public final class DivTabs: DivBase, Sendable {
|
||||
|
||||
public convenience init(dictionary: [String: Any], context: ParsingContext) throws {
|
||||
self.init(
|
||||
div: try dictionary.getField("div", transform: { (dict: [String: Any]) in try Div(dictionary: dict, context: context) }),
|
||||
div: try dictionary.getField("div", transform: { (dict: [String: Any]) in try Div(dictionary: dict, context: context) }, context: context),
|
||||
title: try dictionary.getExpressionField("title", context: context),
|
||||
titleClickAction: try dictionary.getOptionalField("title_click_action", transform: { (dict: [String: Any]) in try DivAction(dictionary: dict, context: context) })
|
||||
)
|
||||
@@ -381,7 +381,7 @@ public final class DivTabs: DivBase, Sendable {
|
||||
hasSeparator: try dictionary.getOptionalExpressionField("has_separator", context: context),
|
||||
height: try dictionary.getOptionalField("height", transform: { (dict: [String: Any]) in try DivSize(dictionary: dict, context: context) }),
|
||||
id: try dictionary.getOptionalField("id", context: context),
|
||||
items: try dictionary.getArray("items", transform: { (dict: [String: Any]) in try? DivTabs.Item(dictionary: dict, context: context) }, validator: Self.itemsValidator),
|
||||
items: try dictionary.getArray("items", transform: { (dict: [String: Any]) in try? DivTabs.Item(dictionary: dict, context: context) }, validator: Self.itemsValidator, context: context),
|
||||
layoutProvider: try dictionary.getOptionalField("layout_provider", transform: { (dict: [String: Any]) in try DivLayoutProvider(dictionary: dict, context: context) }),
|
||||
margins: try dictionary.getOptionalField("margins", transform: { (dict: [String: Any]) in try DivEdgeInsets(dictionary: dict, context: context) }),
|
||||
paddings: try dictionary.getOptionalField("paddings", transform: { (dict: [String: Any]) in try DivEdgeInsets(dictionary: dict, context: context) }),
|
||||
|
||||
@@ -439,7 +439,7 @@ extension DivTemplate {
|
||||
case DivVideoTemplate.type:
|
||||
self = .divVideoTemplate(try DivVideoTemplate(dictionary: dictionary, templateToType: templateToType))
|
||||
default:
|
||||
throw DeserializationError.invalidFieldRepresentation(field: "div_template", representation: dictionary)
|
||||
throw DeserializationError.requiredFieldIsMissing(field: "type")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ public enum DivTextGradient: Sendable {
|
||||
|
||||
extension DivTextGradient {
|
||||
public init(dictionary: [String: Any], context: ParsingContext) throws {
|
||||
let dictionary = context.templateResolver?(dictionary) ?? dictionary
|
||||
let blockType = try dictionary.getField("type") as String
|
||||
switch blockType {
|
||||
case DivLinearGradient.type:
|
||||
@@ -28,7 +29,7 @@ extension DivTextGradient {
|
||||
case DivRadialGradient.type:
|
||||
self = .divRadialGradient(try DivRadialGradient(dictionary: dictionary, context: context))
|
||||
default:
|
||||
throw DeserializationError.invalidFieldRepresentation(field: "div-text-gradient", representation: dictionary)
|
||||
throw DeserializationError.requiredFieldIsMissing(field: "type")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ extension DivTextGradientTemplate {
|
||||
case DivRadialGradientTemplate.type:
|
||||
self = .divRadialGradientTemplate(try DivRadialGradientTemplate(dictionary: dictionary, templateToType: templateToType))
|
||||
default:
|
||||
throw DeserializationError.invalidFieldRepresentation(field: "div-text-gradient_template", representation: dictionary)
|
||||
throw DeserializationError.requiredFieldIsMissing(field: "type")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ public enum DivTextRangeBackground: Sendable {
|
||||
|
||||
extension DivTextRangeBackground {
|
||||
public init(dictionary: [String: Any], context: ParsingContext) throws {
|
||||
let dictionary = context.templateResolver?(dictionary) ?? dictionary
|
||||
let blockType = try dictionary.getField("type") as String
|
||||
switch blockType {
|
||||
case DivSolidBackground.type:
|
||||
@@ -28,7 +29,7 @@ extension DivTextRangeBackground {
|
||||
case DivCloudBackground.type:
|
||||
self = .divCloudBackground(try DivCloudBackground(dictionary: dictionary, context: context))
|
||||
default:
|
||||
throw DeserializationError.invalidFieldRepresentation(field: "div-text-range-background", representation: dictionary)
|
||||
throw DeserializationError.requiredFieldIsMissing(field: "type")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ extension DivTextRangeBackgroundTemplate {
|
||||
case DivCloudBackgroundTemplate.type:
|
||||
self = .divCloudBackgroundTemplate(try DivCloudBackgroundTemplate(dictionary: dictionary, templateToType: templateToType))
|
||||
default:
|
||||
throw DeserializationError.invalidFieldRepresentation(field: "div-text-range-background_template", representation: dictionary)
|
||||
throw DeserializationError.requiredFieldIsMissing(field: "type")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ public enum DivTextRangeMask: Sendable {
|
||||
|
||||
extension DivTextRangeMask {
|
||||
public init(dictionary: [String: Any], context: ParsingContext) throws {
|
||||
let dictionary = context.templateResolver?(dictionary) ?? dictionary
|
||||
let blockType = try dictionary.getField("type") as String
|
||||
switch blockType {
|
||||
case DivTextRangeMaskParticles.type:
|
||||
@@ -28,7 +29,7 @@ extension DivTextRangeMask {
|
||||
case DivTextRangeMaskSolid.type:
|
||||
self = .divTextRangeMaskSolid(try DivTextRangeMaskSolid(dictionary: dictionary, context: context))
|
||||
default:
|
||||
throw DeserializationError.invalidFieldRepresentation(field: "div-text-range-mask", representation: dictionary)
|
||||
throw DeserializationError.requiredFieldIsMissing(field: "type")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ extension DivTextRangeMaskTemplate {
|
||||
case DivTextRangeMaskSolidTemplate.type:
|
||||
self = .divTextRangeMaskSolidTemplate(try DivTextRangeMaskSolidTemplate(dictionary: dictionary, templateToType: templateToType))
|
||||
default:
|
||||
throw DeserializationError.invalidFieldRepresentation(field: "div-text-range-mask_template", representation: dictionary)
|
||||
throw DeserializationError.requiredFieldIsMissing(field: "type")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ public final class DivTooltip: Sendable {
|
||||
backgroundAccessibilityDescription: try dictionary.getOptionalExpressionField("background_accessibility_description", context: context),
|
||||
bringToTopId: try dictionary.getOptionalField("bring_to_top_id", context: context),
|
||||
closeByTapOutside: try dictionary.getOptionalExpressionField("close_by_tap_outside", context: context),
|
||||
div: try dictionary.getField("div", transform: { (dict: [String: Any]) in try Div(dictionary: dict, context: context) }),
|
||||
div: try dictionary.getField("div", transform: { (dict: [String: Any]) in try Div(dictionary: dict, context: context) }, context: context),
|
||||
duration: try dictionary.getOptionalExpressionField("duration", validator: Self.durationValidator, context: context),
|
||||
id: try dictionary.getField("id", context: context),
|
||||
mode: try dictionary.getOptionalField("mode", transform: { (dict: [String: Any]) in try DivTooltipMode(dictionary: dict, context: context) }),
|
||||
|
||||
@@ -21,6 +21,7 @@ public enum DivTooltipMode: Sendable {
|
||||
|
||||
extension DivTooltipMode {
|
||||
public init(dictionary: [String: Any], context: ParsingContext) throws {
|
||||
let dictionary = context.templateResolver?(dictionary) ?? dictionary
|
||||
let blockType = try dictionary.getField("type") as String
|
||||
switch blockType {
|
||||
case DivTooltipModeNonModal.type:
|
||||
@@ -28,7 +29,7 @@ extension DivTooltipMode {
|
||||
case DivTooltipModeModal.type:
|
||||
self = .divTooltipModeModal(try DivTooltipModeModal(dictionary: dictionary, context: context))
|
||||
default:
|
||||
throw DeserializationError.invalidFieldRepresentation(field: "div-tooltip-mode", representation: dictionary)
|
||||
throw DeserializationError.requiredFieldIsMissing(field: "type")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ extension DivTooltipModeTemplate {
|
||||
case DivTooltipModeModalTemplate.type:
|
||||
self = .divTooltipModeModalTemplate(try DivTooltipModeModalTemplate(dictionary: dictionary, templateToType: templateToType))
|
||||
default:
|
||||
throw DeserializationError.invalidFieldRepresentation(field: "div-tooltip-mode_template", representation: dictionary)
|
||||
throw DeserializationError.requiredFieldIsMissing(field: "type")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ public enum DivTransformation: Sendable {
|
||||
|
||||
extension DivTransformation {
|
||||
public init(dictionary: [String: Any], context: ParsingContext) throws {
|
||||
let dictionary = context.templateResolver?(dictionary) ?? dictionary
|
||||
let blockType = try dictionary.getField("type") as String
|
||||
switch blockType {
|
||||
case DivRotationTransformation.type:
|
||||
@@ -28,7 +29,7 @@ extension DivTransformation {
|
||||
case DivTranslationTransformation.type:
|
||||
self = .divTranslationTransformation(try DivTranslationTransformation(dictionary: dictionary, context: context))
|
||||
default:
|
||||
throw DeserializationError.invalidFieldRepresentation(field: "div-transformation", representation: dictionary)
|
||||
throw DeserializationError.requiredFieldIsMissing(field: "type")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user