Skip to content

Commit bfc227e

Browse files
feat(firestore, ios): variable implementation
1 parent d93f968 commit bfc227e

3 files changed

Lines changed: 42 additions & 0 deletions

File tree

packages/firestore/ios/RNFBFirestore/RNFBFirestorePipelineBridgeFactory.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,12 @@ final class RNFBFirestorePipelineBridgeFactory {
353353
let childBox = QuerySourceValueBox()
354354
stack.append(.expressionConstantExit(box, childBox))
355355
stack.append(.value(value, childBox))
356+
case let .variable(name):
357+
box.value = [
358+
"__kind": "expression",
359+
"exprType": "Variable",
360+
"name": name,
361+
]
356362
case let .function(name, args):
357363
let childBoxes = args.map { _ in QuerySourceValueBox() }
358364
stack.append(.expressionFunctionExit(name, box, childBoxes))

packages/firestore/ios/RNFBFirestore/RNFBFirestorePipelineNodeBuilder.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,6 +1044,14 @@ final class RNFBFirestorePipelineNodeBuilder {
10441044
break expressionLoop
10451045
}
10461046

1047+
if let kind = (map["exprType"] as? String)?.lowercased(), kind == "variable" {
1048+
guard let name = map["name"] as? String, !name.isEmpty else {
1049+
throw PipelineValidationError("pipelineExecute() expected \(currentField).name to be a non-empty string.")
1050+
}
1051+
box.value = VariableBridge(name: name)
1052+
break expressionLoop
1053+
}
1054+
10471055
if let name = map["name"] as? String {
10481056
let rawArgs: [Any]
10491057
if let args = map["args"] as? [Any] {
@@ -1237,6 +1245,14 @@ final class RNFBFirestorePipelineNodeBuilder {
12371245
break expressionLoop
12381246
}
12391247

1248+
if let kind = (map["exprType"] as? String)?.lowercased(), kind == "variable" {
1249+
guard let name = map["name"] as? String, !name.isEmpty else {
1250+
throw PipelineValidationError("pipelineExecute() expected \(currentField).name to be a non-empty string.")
1251+
}
1252+
box.value = VariableBridge(name: name)
1253+
break expressionLoop
1254+
}
1255+
12401256
throw PipelineValidationError(
12411257
"pipelineExecute() could not convert \(currentField) into a pipeline expression.")
12421258
}
@@ -1357,6 +1373,12 @@ final class RNFBFirestorePipelineNodeBuilder {
13571373
let valueBox = SerializedValueBox()
13581374
stack.append(.expressionConstantExit(box, valueBox))
13591375
stack.append(.valueEnter(constantValue, valueBox))
1376+
case let .variable(name):
1377+
box.value = [
1378+
"__kind": "expression",
1379+
"exprType": "Variable",
1380+
"name": name,
1381+
]
13601382
case let .function(name, args):
13611383
let argBoxes = args.map { _ in SerializedValueBox() }
13621384
stack.append(.expressionFunctionExit(box, name, argBoxes))
@@ -1463,6 +1485,12 @@ final class RNFBFirestorePipelineNodeBuilder {
14631485
let valueBox = SerializedValueBox()
14641486
stack.append(.expressionConstantExit(box, valueBox))
14651487
stack.append(.valueEnter(constantValue, valueBox))
1488+
case let .variable(name):
1489+
box.value = [
1490+
"__kind": "expression",
1491+
"exprType": "Variable",
1492+
"name": name,
1493+
]
14661494
case let .function(name, args):
14671495
let argBoxes = args.map { _ in SerializedValueBox() }
14681496
stack.append(.expressionFunctionExit(box, name, argBoxes))

packages/firestore/ios/RNFBFirestore/RNFBFirestorePipelineParser.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ struct RNFBFirestoreParsedQuerySource {
4141
indirect enum RNFBFirestoreParsedExpressionNode {
4242
case field(path: String)
4343
case constant(RNFBFirestoreParsedValueNode)
44+
case variable(name: String)
4445
case function(name: String, args: [RNFBFirestoreParsedValueNode])
4546
}
4647

@@ -1191,6 +1192,13 @@ enum RNFBFirestorePipelineParser {
11911192
stack.append(.valueEnter(map["value"] as Any, valueBox, "\(fieldName).value"))
11921193
continue
11931194
}
1195+
if normalizedType == "variable" {
1196+
guard let name = map["name"] as? String, !name.isEmpty else {
1197+
throw PipelineValidationError("pipelineExecute() expected \(fieldName).name to be a non-empty string.")
1198+
}
1199+
box.value = .variable(name: name)
1200+
continue
1201+
}
11941202
}
11951203

11961204
if map["name"] != nil {

0 commit comments

Comments
 (0)