Enabled expressions for playerSettingsPayload

commit_hash:a4ed6e0a2df2ae78420a3828da105b083649b129
This commit is contained in:
booster
2026-03-14 22:48:04 +03:00
parent c79ccbf349
commit abd997bf3d
28 changed files with 169 additions and 119 deletions
@@ -1518,7 +1518,7 @@ class KotlinPropertyType(PropertyType):
return f'{prefix}INT'
elif isinstance(self, Double):
return f'{prefix}DOUBLE'
elif isinstance(self, Dictionary):
elif isinstance(self, (Dictionary, RawObject)):
return f'{prefix}DICT'
elif isinstance(self, RawArray):
return f'{prefix}JSON_ARRAY'
@@ -474,7 +474,7 @@ class SwiftProperty(Property):
return 'resolveNumeric'
elif isinstance(property_type, Object) and isinstance(property_type.object, StringEnumeration):
return 'resolveEnum'
elif isinstance(property_type, Dictionary):
elif isinstance(property_type, Dictionary) or isinstance(property_type, RawObject):
return 'resolveDict'
elif isinstance(property_type, RawArray):
return 'resolveArray'
@@ -851,9 +851,7 @@ class SwiftPropertyType(PropertyType):
return True
def serialization_suffix(self, use_expressions: bool) -> str:
if isinstance(self, RawObject):
return ''
elif isinstance(self, (String, Int, Double, Bool, BoolInt, Dictionary, RawArray)):
if isinstance(self, (String, Int, Double, Bool, BoolInt, Dictionary, RawArray, RawObject)):
return '.toValidSerializationValue()' if use_expressions else ''
elif isinstance(self, Object):
if isinstance(self.object, StringEnumeration):
@@ -797,9 +797,9 @@ def default_value(lang: GeneratedLanguage,
class PropertyType(ABC):
@property
def supports_expressions(self) -> bool:
if isinstance(self, (Int, Double, Bool, BoolInt, String, Color, Url, RawArray, Dictionary)):
if isinstance(self, (Int, Double, Bool, BoolInt, String, Color, Url, RawArray, Dictionary, RawObject)):
return True
elif isinstance(self, (RawObject, StaticString)):
elif isinstance(self, (StaticString)):
return False
elif isinstance(self, Array):
if isinstance(self.property_type, Object) and \
@@ -7,12 +7,12 @@ import 'package:divkit/src/utils/parsing.dart';
class EntityWithJsonProperty with EquatableMixin {
const EntityWithJsonProperty({
this.jsonProperty = None,
this.jsonProperty = const ValueExpression(None),
});
static const type = "entity_with_json_property";
// default value: None
final Obj jsonProperty;
final Expression<Obj> jsonProperty;
@override
List<Object?> get props => [
@@ -20,7 +20,7 @@ class EntityWithJsonProperty with EquatableMixin {
];
EntityWithJsonProperty copyWith({
Obj? jsonProperty,
Expression<Obj>? jsonProperty,
}) => EntityWithJsonProperty(
jsonProperty: jsonProperty ?? this.jsonProperty,
);
@@ -31,7 +31,7 @@ class EntityWithJsonProperty with EquatableMixin {
}
try {
return EntityWithJsonProperty(
jsonProperty: reqProp<Obj>(safeParseMap(json['json_property'], fallback: None,), name: 'json_property',),
jsonProperty: reqVProp<Obj>(safeParseMapExpr(json['json_property'], fallback: None,), name: 'json_property',),
);
} catch (e, st) {
logger.warning("Parsing error", error: e, stackTrace: st);
@@ -14,7 +14,7 @@ import org.json.JSONArray
import org.json.JSONObject
class EntityWithJsonProperty(
@JvmField val jsonProperty: JSONObject = JSON_PROPERTY_DEFAULT_VALUE, // default value: { "key": "value", "items": [ "value" ] }
@JvmField val jsonProperty: Expression<JSONObject> = JSON_PROPERTY_DEFAULT_VALUE, // default value: { "key": "value", "items": [ "value" ] }
) : JSONSerializable, Hashable {
private var _hash: Int? = null
@@ -32,18 +32,18 @@ class EntityWithJsonProperty(
fun equals(other: EntityWithJsonProperty?, resolver: ExpressionResolver, otherResolver: ExpressionResolver): Boolean {
other ?: return false
return jsonProperty == other.jsonProperty
return jsonProperty.evaluate(resolver) == other.jsonProperty.evaluate(otherResolver)
}
fun copy(
jsonProperty: JSONObject = this.jsonProperty,
jsonProperty: Expression<JSONObject> = this.jsonProperty,
) = EntityWithJsonProperty(
jsonProperty = jsonProperty,
)
override fun writeToJSON(): JSONObject {
val json = JSONObject()
json.write(key = "json_property", value = jsonProperty)
json.writeExpression(key = "json_property", value = jsonProperty)
json.write(key = "type", value = TYPE)
return json
}
@@ -51,21 +51,21 @@ class EntityWithJsonProperty(
companion object {
const val TYPE = "entity_with_json_property"
private val JSON_PROPERTY_DEFAULT_VALUE = JSONObject("""
private val JSON_PROPERTY_DEFAULT_VALUE = Expression.constant(JSONObject("""
{
"key": "value",
"items": [
"value"
]
}
""")
"""))
@JvmStatic
@JvmName("fromJson")
operator fun invoke(env: ParsingEnvironment, json: JSONObject): EntityWithJsonProperty {
val logger = env.logger
return EntityWithJsonProperty(
jsonProperty = JsonParser.readOptional(json, "json_property", logger, env) ?: JSON_PROPERTY_DEFAULT_VALUE
jsonProperty = JsonParser.readOptionalExpression(json, "json_property", logger, env, JSON_PROPERTY_DEFAULT_VALUE, TYPE_HELPER_DICT) ?: JSON_PROPERTY_DEFAULT_VALUE
)
}
@@ -14,7 +14,7 @@ import org.json.JSONArray
import org.json.JSONObject
class EntityWithJsonPropertyTemplate(
@JvmField val jsonProperty: Field<JSONObject>,
@JvmField val jsonProperty: Field<Expression<JSONObject>>,
) : JSONSerializable, JsonTemplate<EntityWithJsonProperty> {
constructor(
@@ -23,7 +23,7 @@ class EntityWithJsonPropertyTemplate(
topLevel: Boolean = false,
json: JSONObject
) : this(
jsonProperty = JsonTemplateParser.readOptionalField(json, "json_property", topLevel, parent?.jsonProperty, env.logger, env)
jsonProperty = JsonTemplateParser.readOptionalFieldWithExpression(json, "json_property", topLevel, parent?.jsonProperty, env.logger, env, TYPE_HELPER_DICT)
)
override fun resolve(env: ParsingEnvironment, data: JSONObject): EntityWithJsonProperty {
@@ -34,7 +34,7 @@ class EntityWithJsonPropertyTemplate(
override fun writeToJSON(): JSONObject {
val json = JSONObject()
json.writeField(key = "json_property", field = jsonProperty)
json.writeFieldWithExpression(key = "json_property", field = jsonProperty)
json.write(key = "type", value = TYPE)
return json
}
@@ -42,16 +42,16 @@ class EntityWithJsonPropertyTemplate(
companion object {
const val TYPE = "entity_with_json_property"
private val JSON_PROPERTY_DEFAULT_VALUE = JSONObject("""
private val JSON_PROPERTY_DEFAULT_VALUE = Expression.constant(JSONObject("""
{
"key": "value",
"items": [
"value"
]
}
""")
"""))
val JSON_PROPERTY_READER: Reader<JSONObject> = { key, json, env -> JsonParser.readOptional(json, key, env.logger, env) ?: JSON_PROPERTY_DEFAULT_VALUE }
val JSON_PROPERTY_READER: Reader<Expression<JSONObject>> = { key, json, env -> JsonParser.readOptionalExpression(json, key, env.logger, env, JSON_PROPERTY_DEFAULT_VALUE, TYPE_HELPER_DICT) ?: JSON_PROPERTY_DEFAULT_VALUE }
val TYPE_READER: Reader<String> = { key, json, env -> JsonParser.read(json, key, env.logger, env) }
val CREATOR = { env: ParsingEnvironment, it: JSONObject -> EntityWithJsonPropertyTemplate(env, json = it) }
@@ -14,7 +14,7 @@ import org.json.JSONArray
import org.json.JSONObject
class EntityWithJsonProperty(
@JvmField val jsonProperty: JSONObject = JSON_PROPERTY_DEFAULT_VALUE, // default value: { "key": "value", "items": [ "value" ] }
@JvmField val jsonProperty: Expression<JSONObject> = JSON_PROPERTY_DEFAULT_VALUE, // default value: { "key": "value", "items": [ "value" ] }
) : JSONSerializable, Hashable {
private var _hash: Int? = null
@@ -32,18 +32,18 @@ class EntityWithJsonProperty(
fun equals(other: EntityWithJsonProperty?, resolver: ExpressionResolver, otherResolver: ExpressionResolver): Boolean {
other ?: return false
return jsonProperty == other.jsonProperty
return jsonProperty.evaluate(resolver) == other.jsonProperty.evaluate(otherResolver)
}
fun copy(
jsonProperty: JSONObject = this.jsonProperty,
jsonProperty: Expression<JSONObject> = this.jsonProperty,
) = EntityWithJsonProperty(
jsonProperty = jsonProperty,
)
override fun writeToJSON(): JSONObject {
val json = JSONObject()
json.write(key = "json_property", value = jsonProperty)
json.writeExpression(key = "json_property", value = jsonProperty)
json.write(key = "type", value = TYPE)
return json
}
@@ -51,21 +51,21 @@ class EntityWithJsonProperty(
companion object {
const val TYPE = "entity_with_json_property"
private val JSON_PROPERTY_DEFAULT_VALUE = JSONObject("""
private val JSON_PROPERTY_DEFAULT_VALUE = Expression.constant(JSONObject("""
{
"key": "value",
"items": [
"value"
]
}
""")
"""))
@JvmStatic
@JvmName("fromJson")
operator fun invoke(env: ParsingEnvironment, json: JSONObject): EntityWithJsonProperty {
val logger = env.logger
return EntityWithJsonProperty(
jsonProperty = JsonParser.readOptional(json, "json_property", logger, env) ?: JSON_PROPERTY_DEFAULT_VALUE
jsonProperty = JsonParser.readOptionalExpression(json, "json_property", logger, env, JSON_PROPERTY_DEFAULT_VALUE, TYPE_HELPER_DICT) ?: JSON_PROPERTY_DEFAULT_VALUE
)
}
@@ -6,18 +6,10 @@ import Serialization
public final class EntityWithJsonProperty: @unchecked Sendable {
public static let type: String = "entity_with_json_property"
public let jsonProperty: [String: Any] // default value: { "key": "value", "items": [ "value" ] }
public let jsonProperty: Expression<[String: Any]> // default value: { "key": "value", "items": [ "value" ] }
public convenience init(dictionary: [String: Any], context: ParsingContext) throws {
self.init(
jsonProperty: try dictionary.getOptionalField("json_property", context: context)
)
}
init(
jsonProperty: [String: Any]? = nil
) {
self.jsonProperty = jsonProperty ?? (try! JSONSerialization.jsonObject(jsonString: """
public func resolveJsonProperty(_ resolver: ExpressionResolver) -> [String: Any] {
resolver.resolveDict(jsonProperty) ?? (try! JSONSerialization.jsonObject(jsonString: """
{
"key": "value",
"items": [
@@ -26,6 +18,25 @@ public final class EntityWithJsonProperty: @unchecked Sendable {
}
""") as! [String: Any])
}
public convenience init(dictionary: [String: Any], context: ParsingContext) throws {
self.init(
jsonProperty: try dictionary.getOptionalExpressionField("json_property", context: context)
)
}
init(
jsonProperty: Expression<[String: Any]>? = nil
) {
self.jsonProperty = jsonProperty ?? .value((try! JSONSerialization.jsonObject(jsonString: """
{
"key": "value",
"items": [
"value"
]
}
""") as! [String: Any]))
}
}
#if DEBUG
@@ -42,7 +53,7 @@ extension EntityWithJsonProperty: Serializable {
public func toDictionary() -> [String: ValidSerializationValue] {
var result: [String: ValidSerializationValue] = [:]
result["type"] = Self.type
result["json_property"] = jsonProperty
result["json_property"] = jsonProperty.toValidSerializationValue()
return result
}
}
@@ -14,7 +14,7 @@ import org.json.JSONArray
import org.json.JSONObject
class EntityWithJsonProperty(
@JvmField val jsonProperty: JSONObject = JSON_PROPERTY_DEFAULT_VALUE, // default value: { "key": "value", "items": [ "value" ] }
@JvmField val jsonProperty: Expression<JSONObject> = JSON_PROPERTY_DEFAULT_VALUE, // default value: { "key": "value", "items": [ "value" ] }
) : JSONSerializable, Hashable {
private var _hash: Int? = null
@@ -32,11 +32,11 @@ class EntityWithJsonProperty(
fun equals(other: EntityWithJsonProperty?, resolver: ExpressionResolver, otherResolver: ExpressionResolver): Boolean {
other ?: return false
return jsonProperty == other.jsonProperty
return jsonProperty.evaluate(resolver) == other.jsonProperty.evaluate(otherResolver)
}
fun copy(
jsonProperty: JSONObject = this.jsonProperty,
jsonProperty: Expression<JSONObject> = this.jsonProperty,
) = EntityWithJsonProperty(
jsonProperty = jsonProperty,
)
@@ -50,14 +50,14 @@ class EntityWithJsonProperty(
companion object {
const val TYPE = "entity_with_json_property"
private val JSON_PROPERTY_DEFAULT_VALUE = JSONObject("""
private val JSON_PROPERTY_DEFAULT_VALUE = Expression.constant(JSONObject("""
{
"key": "value",
"items": [
"value"
]
}
""")
"""))
@JvmStatic
@JvmName("fromJson")
@@ -24,14 +24,14 @@ internal class EntityWithJsonPropertyJsonParser(
@Throws(ParsingException::class)
override fun deserialize(context: ParsingContext, data: JSONObject): EntityWithJsonProperty {
return EntityWithJsonProperty(
jsonProperty = JsonPropertyParser.readOptional(context, data, "json_property") ?: JSON_PROPERTY_DEFAULT_VALUE,
jsonProperty = JsonExpressionParser.readOptionalExpression(context, data, "json_property", TYPE_HELPER_DICT, JSON_PROPERTY_DEFAULT_VALUE) ?: JSON_PROPERTY_DEFAULT_VALUE,
)
}
@Throws(ParsingException::class)
override fun serialize(context: ParsingContext, value: EntityWithJsonProperty): JSONObject {
val data = JSONObject()
JsonPropertyParser.write(context, data, "json_property", value.jsonProperty)
JsonExpressionParser.writeExpression(context, data, "json_property", value.jsonProperty)
JsonPropertyParser.write(context, data, "type", EntityWithJsonProperty.TYPE)
return data
}
@@ -46,14 +46,14 @@ internal class EntityWithJsonPropertyJsonParser(
val allowOverride = context.allowPropertyOverride
@Suppress("NAME_SHADOWING") val context = context.restrictPropertyOverride()
return EntityWithJsonPropertyTemplate(
jsonProperty = JsonFieldParser.readOptionalField(context, data, "json_property", allowOverride, parent?.jsonProperty),
jsonProperty = JsonFieldParser.readOptionalFieldWithExpression(context, data, "json_property", TYPE_HELPER_DICT, allowOverride, parent?.jsonProperty),
)
}
@Throws(ParsingException::class)
override fun serialize(context: ParsingContext, value: EntityWithJsonPropertyTemplate): JSONObject {
val data = JSONObject()
JsonFieldParser.writeField(context, data, "json_property", value.jsonProperty)
JsonFieldParser.writeFieldWithExpression(context, data, "json_property", value.jsonProperty)
JsonPropertyParser.write(context, data, "type", EntityWithJsonProperty.TYPE)
return data
}
@@ -66,20 +66,20 @@ internal class EntityWithJsonPropertyJsonParser(
@Throws(ParsingException::class)
override fun resolve(context: ParsingContext, template: EntityWithJsonPropertyTemplate, data: JSONObject): EntityWithJsonProperty {
return EntityWithJsonProperty(
jsonProperty = JsonFieldResolver.resolveOptional(context, template.jsonProperty, data, "json_property") ?: JSON_PROPERTY_DEFAULT_VALUE,
jsonProperty = JsonFieldResolver.resolveOptionalExpression(context, template.jsonProperty, data, "json_property", TYPE_HELPER_DICT) ?: JSON_PROPERTY_DEFAULT_VALUE,
)
}
}
private companion object {
@JvmField val JSON_PROPERTY_DEFAULT_VALUE = JSONObject("""
@JvmField val JSON_PROPERTY_DEFAULT_VALUE = Expression.constant(JSONObject("""
{
"key": "value",
"items": [
"value"
]
}
""")
"""))
}
}
@@ -14,7 +14,7 @@ import org.json.JSONArray
import org.json.JSONObject
class EntityWithJsonPropertyTemplate(
@JvmField val jsonProperty: Field<JSONObject>,
@JvmField val jsonProperty: Field<Expression<JSONObject>>,
) : JSONSerializable, JsonTemplate<EntityWithJsonProperty> {
constructor(
@@ -43,14 +43,14 @@ class EntityWithJsonPropertyTemplate(
companion object {
const val TYPE = "entity_with_json_property"
private val JSON_PROPERTY_DEFAULT_VALUE = JSONObject("""
private val JSON_PROPERTY_DEFAULT_VALUE = Expression.constant(JSONObject("""
{
"key": "value",
"items": [
"value"
]
}
""")
"""))
val CREATOR = { env: ParsingEnvironment, it: JSONObject -> EntityWithJsonPropertyTemplate(env, json = it) }
}
@@ -6,7 +6,7 @@ import org.json.JSONArray
import org.json.JSONObject
class EntityWithJsonProperty(
@JvmField val jsonProperty: JSONObject = JSON_PROPERTY_DEFAULT_VALUE, // default value: { "key": "value", "items": [ "value" ] }
@JvmField val jsonProperty: Expression<JSONObject> = JSON_PROPERTY_DEFAULT_VALUE, // default value: { "key": "value", "items": [ "value" ] }
) : Hashable {
private var _hash: Int? = null
@@ -24,11 +24,11 @@ class EntityWithJsonProperty(
fun equals(other: EntityWithJsonProperty?, resolver: ExpressionResolver, otherResolver: ExpressionResolver): Boolean {
other ?: return false
return jsonProperty == other.jsonProperty
return jsonProperty.evaluate(resolver) == other.jsonProperty.evaluate(otherResolver)
}
fun copy(
jsonProperty: JSONObject = this.jsonProperty,
jsonProperty: Expression<JSONObject> = this.jsonProperty,
) = EntityWithJsonProperty(
jsonProperty = jsonProperty,
)
@@ -36,13 +36,13 @@ class EntityWithJsonProperty(
companion object {
const val TYPE = "entity_with_json_property"
private val JSON_PROPERTY_DEFAULT_VALUE = JSONObject("""
private val JSON_PROPERTY_DEFAULT_VALUE = Expression.constant(JSONObject("""
{
"key": "value",
"items": [
"value"
]
}
""")
"""))
}
}
@@ -6,12 +6,10 @@ import Serialization
public final class EntityWithJsonProperty: @unchecked Sendable {
public static let type: String = "entity_with_json_property"
public let jsonProperty: [String: Any] // default value: { "key": "value", "items": [ "value" ] }
public let jsonProperty: Expression<[String: Any]> // default value: { "key": "value", "items": [ "value" ] }
init(
jsonProperty: [String: Any]? = nil
) {
self.jsonProperty = jsonProperty ?? (try! JSONSerialization.jsonObject(jsonString: """
public func resolveJsonProperty(_ resolver: ExpressionResolver) -> [String: Any] {
resolver.resolveDict(jsonProperty) ?? (try! JSONSerialization.jsonObject(jsonString: """
{
"key": "value",
"items": [
@@ -20,6 +18,19 @@ public final class EntityWithJsonProperty: @unchecked Sendable {
}
""") as! [String: Any])
}
init(
jsonProperty: Expression<[String: Any]>? = nil
) {
self.jsonProperty = jsonProperty ?? .value((try! JSONSerialization.jsonObject(jsonString: """
{
"key": "value",
"items": [
"value"
]
}
""") as! [String: Any]))
}
}
#if DEBUG
@@ -6,18 +6,10 @@ import Serialization
public final class EntityWithJsonProperty: @unchecked Sendable {
public static let type: String = "entity_with_json_property"
public let jsonProperty: [String: Any] // default value: { "key": "value", "items": [ "value" ] }
public let jsonProperty: Expression<[String: Any]> // default value: { "key": "value", "items": [ "value" ] }
public convenience init(dictionary: [String: Any], context: ParsingContext) throws {
self.init(
jsonProperty: try dictionary.getOptionalField("json_property", context: context)
)
}
init(
jsonProperty: [String: Any]? = nil
) {
self.jsonProperty = jsonProperty ?? (try! JSONSerialization.jsonObject(jsonString: """
public func resolveJsonProperty(_ resolver: ExpressionResolver) -> [String: Any] {
resolver.resolveDict(jsonProperty) ?? (try! JSONSerialization.jsonObject(jsonString: """
{
"key": "value",
"items": [
@@ -26,6 +18,25 @@ public final class EntityWithJsonProperty: @unchecked Sendable {
}
""") as! [String: Any])
}
public convenience init(dictionary: [String: Any], context: ParsingContext) throws {
self.init(
jsonProperty: try dictionary.getOptionalExpressionField("json_property", context: context)
)
}
init(
jsonProperty: Expression<[String: Any]>? = nil
) {
self.jsonProperty = jsonProperty ?? .value((try! JSONSerialization.jsonObject(jsonString: """
{
"key": "value",
"items": [
"value"
]
}
""") as! [String: Any]))
}
}
#if DEBUG
@@ -42,7 +53,7 @@ extension EntityWithJsonProperty: Serializable {
public func toDictionary() -> [String: ValidSerializationValue] {
var result: [String: ValidSerializationValue] = [:]
result["type"] = Self.type
result["json_property"] = jsonProperty
result["json_property"] = jsonProperty.toValidSerializationValue()
return result
}
}
@@ -7,18 +7,18 @@ import Serialization
public final class EntityWithJsonPropertyTemplate: TemplateValue, @unchecked Sendable {
public static let type: String = "entity_with_json_property"
public let parent: String?
public let jsonProperty: Field<[String: Any]>? // default value: { "key": "value", "items": [ "value" ] }
public let jsonProperty: Field<Expression<[String: Any]>>? // default value: { "key": "value", "items": [ "value" ] }
public convenience init(dictionary: [String: Any], templateToType: [TemplateName: String]) throws {
self.init(
parent: dictionary["type"] as? String,
jsonProperty: dictionary.getOptionalField("json_property")
jsonProperty: dictionary.getOptionalExpressionField("json_property")
)
}
init(
parent: String?,
jsonProperty: Field<[String: Any]>? = nil
jsonProperty: Field<Expression<[String: Any]>>? = nil
) {
self.parent = parent
self.jsonProperty = jsonProperty
@@ -39,7 +39,7 @@ public final class EntityWithJsonPropertyTemplate: TemplateValue, @unchecked Sen
if useOnlyLinks {
return resolveOnlyLinks(context: context, parent: parent)
}
var jsonPropertyValue: DeserializationResult<[String: Any]> = parent?.jsonProperty?.value() ?? .noValue
var jsonPropertyValue: DeserializationResult<Expression<[String: Any]>> = parent?.jsonProperty?.value() ?? .noValue
context.templateData.forEach { key, __dictValue in
switch key {
case "json_property":
@@ -8,7 +8,7 @@ export class EntityWithJsonProperty<T extends EntityWithJsonPropertyProps = Enti
readonly _props?: Exact<EntityWithJsonPropertyProps, T>;
readonly type = 'entity_with_json_property';
json_property?: Type<{}>;
json_property?: Type<{} | DivExpression>;
constructor(props?: Exact<EntityWithJsonPropertyProps, T>) {
this.json_property = props?.json_property;
@@ -16,5 +16,5 @@ export class EntityWithJsonProperty<T extends EntityWithJsonPropertyProps = Enti
}
export interface EntityWithJsonPropertyProps {
json_property?: Type<{}>;
json_property?: Type<{} | DivExpression>;
}
@@ -71,13 +71,13 @@ public class JsonParser {
}
@Nullable
public static Expression<String> readOptionalExpression(
public static <T> Expression<T> readOptionalExpression(
@NonNull final JSONObject jsonObject,
@NonNull final String key,
@NonNull final ParsingErrorLogger logger,
@NonNull final ParsingEnvironment env,
@NonNull final TypeHelper<String> typeHelper) {
return readOptionalExpression(jsonObject, key, doNotConvert(), ALWAYS_VALID_STRING, logger, env, typeHelper);
@NonNull final TypeHelper<T> typeHelper) {
return readOptionalExpression(jsonObject, key, doNotConvert(), alwaysValid(), logger, env, typeHelper);
}
@Nullable
@@ -252,16 +252,16 @@ public class JsonTemplateParser {
}
@NonNull
public static Field<Expression<String>> readOptionalFieldWithExpression(
public static <T> Field<Expression<T>> readOptionalFieldWithExpression(
@NonNull JSONObject json,
@NonNull String key,
boolean overridable,
@Nullable Field<Expression<String>> fallback,
@Nullable Field<Expression<T>> fallback,
@NonNull ParsingErrorLogger logger,
@NonNull ParsingEnvironment env,
@NonNull TypeHelper<String> typeHelper) {
@NonNull TypeHelper<T> typeHelper) {
return readOptionalFieldWithExpression(
json, key, overridable, fallback, doNotConvert(), alwaysValidString(), logger, env, typeHelper);
json, key, overridable, fallback, doNotConvert(), alwaysValid(), logger, env, typeHelper);
}
@NonNull
@@ -282,7 +282,7 @@ internal class DivVideoBinder @Inject constructor(
autoplay = autostart.evaluate(resolver),
isMuted = muted.evaluate(resolver),
repeatable = repeatable.evaluate(resolver),
payload = playerSettingsPayload,
payload = playerSettingsPayload?.evaluate(resolver),
)
}
@@ -40,7 +40,7 @@ extension DivVideo: DivBlockModeling {
repeatable: repeatable,
isMuted: muted,
startPosition: elapsedTime.flatMap { CMTime(value: $0.value) } ?? .zero,
settingsPayload: playerSettingsPayload ?? [:]
settingsPayload: resolvePlayerSettingsPayload(resolver) ?? [:]
)
let state: VideoBlockViewState = context.blockStateStorage
@@ -31,7 +31,7 @@ public final class DivVideo: DivBase, @unchecked Sendable {
public let muted: Expression<Bool> // default value: false
public let paddings: DivEdgeInsets?
public let pauseActions: [DivAction]?
public let playerSettingsPayload: [String: Any]?
public let playerSettingsPayload: Expression<[String: Any]>?
public let preloadRequired: Expression<Bool> // default value: false
public let preview: Expression<String>?
public let repeatable: Expression<Bool> // default value: false
@@ -79,6 +79,10 @@ public final class DivVideo: DivBase, @unchecked Sendable {
resolver.resolveNumeric(muted) ?? false
}
public func resolvePlayerSettingsPayload(_ resolver: ExpressionResolver) -> [String: Any]? {
resolver.resolveDict(playerSettingsPayload)
}
public func resolvePreloadRequired(_ resolver: ExpressionResolver) -> Bool {
resolver.resolveNumeric(preloadRequired) ?? false
}
@@ -149,7 +153,7 @@ public final class DivVideo: DivBase, @unchecked Sendable {
muted: try dictionary.getOptionalExpressionField("muted", context: context),
paddings: try dictionary.getOptionalField("paddings", transform: { (dict: [String: Any]) in try DivEdgeInsets(dictionary: dict, context: context) }),
pauseActions: try dictionary.getOptionalArray("pause_actions", transform: { (dict: [String: Any]) in try? DivAction(dictionary: dict, context: context) }),
playerSettingsPayload: try dictionary.getOptionalField("player_settings_payload", context: context),
playerSettingsPayload: try dictionary.getOptionalExpressionField("player_settings_payload", context: context),
preloadRequired: try dictionary.getOptionalExpressionField("preload_required", context: context),
preview: try dictionary.getOptionalExpressionField("preview", context: context),
repeatable: try dictionary.getOptionalExpressionField("repeatable", context: context),
@@ -201,7 +205,7 @@ public final class DivVideo: DivBase, @unchecked Sendable {
muted: Expression<Bool>? = nil,
paddings: DivEdgeInsets? = nil,
pauseActions: [DivAction]? = nil,
playerSettingsPayload: [String: Any]? = nil,
playerSettingsPayload: Expression<[String: Any]>? = nil,
preloadRequired: Expression<Bool>? = nil,
preview: Expression<String>? = nil,
repeatable: Expression<Bool>? = nil,
@@ -426,7 +430,7 @@ extension DivVideo: Serializable {
result["muted"] = muted.toValidSerializationValue()
result["paddings"] = paddings?.toDictionary()
result["pause_actions"] = pauseActions?.map { $0.toDictionary() }
result["player_settings_payload"] = playerSettingsPayload
result["player_settings_payload"] = playerSettingsPayload?.toValidSerializationValue()
result["preload_required"] = preloadRequired.toValidSerializationValue()
result["preview"] = preview?.toValidSerializationValue()
result["repeatable"] = repeatable.toValidSerializationValue()
@@ -32,7 +32,7 @@ public final class DivVideoTemplate: TemplateValue, @unchecked Sendable {
public let muted: Field<Expression<Bool>>? // default value: false
public let paddings: Field<DivEdgeInsetsTemplate>?
public let pauseActions: Field<[DivActionTemplate]>?
public let playerSettingsPayload: Field<[String: Any]>?
public let playerSettingsPayload: Field<Expression<[String: Any]>>?
public let preloadRequired: Field<Expression<Bool>>? // default value: false
public let preview: Field<Expression<String>>?
public let repeatable: Field<Expression<Bool>>? // default value: false
@@ -84,7 +84,7 @@ public final class DivVideoTemplate: TemplateValue, @unchecked Sendable {
muted: dictionary.getOptionalExpressionField("muted"),
paddings: dictionary.getOptionalField("paddings", templateToType: templateToType),
pauseActions: dictionary.getOptionalArray("pause_actions", templateToType: templateToType),
playerSettingsPayload: dictionary.getOptionalField("player_settings_payload"),
playerSettingsPayload: dictionary.getOptionalExpressionField("player_settings_payload"),
preloadRequired: dictionary.getOptionalExpressionField("preload_required"),
preview: dictionary.getOptionalExpressionField("preview"),
repeatable: dictionary.getOptionalExpressionField("repeatable"),
@@ -137,7 +137,7 @@ public final class DivVideoTemplate: TemplateValue, @unchecked Sendable {
muted: Field<Expression<Bool>>? = nil,
paddings: Field<DivEdgeInsetsTemplate>? = nil,
pauseActions: Field<[DivActionTemplate]>? = nil,
playerSettingsPayload: Field<[String: Any]>? = nil,
playerSettingsPayload: Field<Expression<[String: Any]>>? = nil,
preloadRequired: Field<Expression<Bool>>? = nil,
preview: Field<Expression<String>>? = nil,
repeatable: Field<Expression<Bool>>? = nil,
@@ -401,7 +401,7 @@ public final class DivVideoTemplate: TemplateValue, @unchecked Sendable {
var mutedValue: DeserializationResult<Expression<Bool>> = parent?.muted?.value() ?? .noValue
var paddingsValue: DeserializationResult<DivEdgeInsets> = .noValue
var pauseActionsValue: DeserializationResult<[DivAction]> = .noValue
var playerSettingsPayloadValue: DeserializationResult<[String: Any]> = parent?.playerSettingsPayload?.value() ?? .noValue
var playerSettingsPayloadValue: DeserializationResult<Expression<[String: Any]>> = parent?.playerSettingsPayload?.value() ?? .noValue
var preloadRequiredValue: DeserializationResult<Expression<Bool>> = parent?.preloadRequired?.value() ?? .noValue
var previewValue: DeserializationResult<Expression<String>> = parent?.preview?.value() ?? .noValue
var repeatableValue: DeserializationResult<Expression<Bool>> = parent?.repeatable?.value() ?? .noValue
@@ -9,18 +9,10 @@ import enum DivKit.Expression
public final class EntityWithJsonProperty: @unchecked Sendable {
public static let type: String = "entity_with_json_property"
public let jsonProperty: [String: Any] // default value: { "key": "value", "items": [ "value" ] }
public let jsonProperty: Expression<[String: Any]> // default value: { "key": "value", "items": [ "value" ] }
public convenience init(dictionary: [String: Any], context: ParsingContext) throws {
self.init(
jsonProperty: try dictionary.getOptionalField("json_property", context: context)
)
}
init(
jsonProperty: [String: Any]? = nil
) {
self.jsonProperty = jsonProperty ?? (try! JSONSerialization.jsonObject(jsonString: """
public func resolveJsonProperty(_ resolver: ExpressionResolver) -> [String: Any] {
resolver.resolveDict(jsonProperty) ?? (try! JSONSerialization.jsonObject(jsonString: """
{
"key": "value",
"items": [
@@ -29,6 +21,25 @@ public final class EntityWithJsonProperty: @unchecked Sendable {
}
""") as! [String: Any])
}
public convenience init(dictionary: [String: Any], context: ParsingContext) throws {
self.init(
jsonProperty: try dictionary.getOptionalExpressionField("json_property", context: context)
)
}
init(
jsonProperty: Expression<[String: Any]>? = nil
) {
self.jsonProperty = jsonProperty ?? .value((try! JSONSerialization.jsonObject(jsonString: """
{
"key": "value",
"items": [
"value"
]
}
""") as! [String: Any]))
}
}
#if DEBUG
@@ -45,7 +56,7 @@ extension EntityWithJsonProperty: Serializable {
public func toDictionary() -> [String: ValidSerializationValue] {
var result: [String: ValidSerializationValue] = [:]
result["type"] = Self.type
result["json_property"] = jsonProperty
result["json_property"] = jsonProperty.toValidSerializationValue()
return result
}
}
@@ -10,18 +10,18 @@ import enum DivKit.Expression
public final class EntityWithJsonPropertyTemplate: TemplateValue, @unchecked Sendable {
public static let type: String = "entity_with_json_property"
public let parent: String?
public let jsonProperty: Field<[String: Any]>? // default value: { "key": "value", "items": [ "value" ] }
public let jsonProperty: Field<Expression<[String: Any]>>? // default value: { "key": "value", "items": [ "value" ] }
public convenience init(dictionary: [String: Any], templateToType: [TemplateName: String]) throws {
self.init(
parent: dictionary["type"] as? String,
jsonProperty: dictionary.getOptionalField("json_property")
jsonProperty: dictionary.getOptionalExpressionField("json_property")
)
}
init(
parent: String?,
jsonProperty: Field<[String: Any]>? = nil
jsonProperty: Field<Expression<[String: Any]>>? = nil
) {
self.parent = parent
self.jsonProperty = jsonProperty
@@ -42,7 +42,7 @@ public final class EntityWithJsonPropertyTemplate: TemplateValue, @unchecked Sen
if useOnlyLinks {
return resolveOnlyLinks(context: context, parent: parent)
}
var jsonPropertyValue: DeserializationResult<[String: Any]> = parent?.jsonProperty?.value() ?? .noValue
var jsonPropertyValue: DeserializationResult<Expression<[String: Any]>> = parent?.jsonProperty?.value() ?? .noValue
context.templateData.forEach { key, __dictValue in
switch key {
case "json_property":
+1
View File
@@ -31,6 +31,7 @@
"payload": {
"type": "object",
"additionalProperties": true,
"supports_expressions": false,
"$description": "translations.json#/div_action_base_payload"
},
"download_callbacks": {
+1
View File
@@ -27,6 +27,7 @@
"custom_props": {
"type": "object",
"additionalProperties": true,
"supports_expressions": false,
"$description": "translations.json#/div_custom_custom_props"
}
}
+1
View File
@@ -14,6 +14,7 @@
"params": {
"type": "object",
"additionalProperties": true,
"supports_expressions": false,
"$description": "translations.json#/div_extension_params"
}
},
+1
View File
@@ -77,6 +77,7 @@
},
"value": {
"type": "object",
"supports_expressions": false,
"additionalProperties": true,
"default_value": {
"1": { "$ref": "#/constants/short" },