Skip to content

Commit

Permalink
Merge pull request #76 from Chuhaa/main
Browse files Browse the repository at this point in the history
Fix record type in stream next response
  • Loading branch information
LakshanSS authored Jun 28, 2022
2 parents e6285ee + 684ee3a commit 4da2397
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 34 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/dev-stg-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
run: |
./gradlew build
- name: Ballerina Build
uses: ballerina-platform/ballerina-action@master
uses: ballerina-platform/ballerina-action@2201.1.0
with:
args:
pack ./cosmosdb
Expand All @@ -41,7 +41,7 @@ jobs:

- name: Push to Staging
if: github.event.inputs.bal_central_environment == 'STAGE'
uses: ballerina-platform/ballerina-action@master
uses: ballerina-platform/ballerina-action@2201.1.0
with:
args:
push
Expand All @@ -52,7 +52,7 @@ jobs:

- name: Push to Dev
if: github.event.inputs.bal_central_environment == 'DEV'
uses: ballerina-platform/ballerina-action@master
uses: ballerina-platform/ballerina-action@2201.1.0
with:
args:
push
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
run: |
./gradlew build
- name: Ballerina Build
uses: ballerina-platform/ballerina-action/@master
uses: ballerina-platform/ballerina-action/@2201.1.0
with:
args:
pack ./cosmosdb
Expand All @@ -34,7 +34,7 @@ jobs:
MASTER_OR_RESOURCE_TOKEN: ${{ secrets.MASTER_OR_RESOURCE_TOKEN }}
JAVA_HOME: /usr/lib/jvm/default-jvm
- name: Ballerina Push
uses: ballerina-platform/ballerina-action/@master
uses: ballerina-platform/ballerina-action/@2201.1.0
with:
args:
push
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
package io.ballerinax.cosmosdb;

import com.azure.cosmos.models.CosmosStoredProcedureProperties;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.ballerina.runtime.api.PredefinedTypes;
import io.ballerina.runtime.api.creators.TypeCreator;
import io.ballerina.runtime.api.creators.ValueCreator;
import io.ballerina.runtime.api.types.MapType;
import io.ballerina.runtime.api.types.RecordType;
import io.ballerina.runtime.api.types.UnionType;
import io.ballerina.runtime.api.values.BObject;
import io.ballerina.runtime.internal.JsonParser;
import io.ballerina.runtime.api.values.BTypedesc;
import org.ballerinalang.langlib.value.FromJsonStringWithType;

import java.util.HashMap;
import java.util.Iterator;
Expand Down Expand Up @@ -57,10 +57,14 @@ public static Object nextResult(BObject recordIterator) {
return null;
} else {
Iterator<Object> results = (Iterator<Object>) recordIterator.getNativeData(Constants.OBJECT_ITERATOR);
ObjectMapper mapper = new ObjectMapper();
if (results.hasNext()) {
try {
return JsonParser.parse(mapper.writeValueAsString(results.next()));
String result = new ObjectMapper().writeValueAsString(results.next());
RecordType recordType = (RecordType) recordIterator.getNativeData(Constants.RECORD_TYPE);
UnionType responseType = TypeCreator.createUnionType(recordType, PredefinedTypes.TYPE_ERROR,
PredefinedTypes.TYPE_NULL);
BTypedesc responseTypedescValue = ValueCreator.createTypedescValue(responseType);
return FromJsonStringWithType.fromJsonStringWithType(fromString(result), responseTypedescValue);
} catch (Exception e) {
return BallerinaErrorGenerator.createBallerinaDatabaseError(e);
}
Expand Down
6 changes: 3 additions & 3 deletions cosmosdb/Ballerina.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
distribution = "2201.0.0"
distribution = "2201.1.0"
org= "ballerinax"
name= "azure_cosmosdb"
version= "3.0.1"
Expand All @@ -21,9 +21,9 @@ version = "3.0.1"
[[platform.java11.dependency]]
groupId = "io.netty"
artifactId = "netty-resolver-dns"
version = "4.1.71.Final"
version = "4.1.77.Final"

[[platform.java11.dependency]]
groupId = "io.netty"
artifactId = "netty-handler"
version = "4.1.71.Final"
version = "4.1.77.Final"
33 changes: 17 additions & 16 deletions cosmosdb/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dependencies-toml-version = "2"
[[package]]
org = "ballerina"
name = "auth"
version = "2.2.0"
version = "2.2.1"
dependencies = [
{org = "ballerina", name = "crypto"},
{org = "ballerina", name = "jballerina.java"},
Expand All @@ -22,7 +22,7 @@ dependencies = [
[[package]]
org = "ballerina"
name = "cache"
version = "3.2.0"
version = "3.2.2"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "task"},
Expand All @@ -32,7 +32,7 @@ dependencies = [
[[package]]
org = "ballerina"
name = "crypto"
version = "2.2.0"
version = "2.2.2"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "time"}
Expand All @@ -44,8 +44,9 @@ modules = [
[[package]]
org = "ballerina"
name = "file"
version = "1.2.0"
version = "1.2.2"
dependencies = [
{org = "ballerina", name = "io"},
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "log"},
{org = "ballerina", name = "os"},
Expand All @@ -56,7 +57,7 @@ dependencies = [
[[package]]
org = "ballerina"
name = "http"
version = "2.2.0"
version = "2.2.2"
dependencies = [
{org = "ballerina", name = "auth"},
{org = "ballerina", name = "cache"},
Expand Down Expand Up @@ -86,7 +87,7 @@ modules = [
[[package]]
org = "ballerina"
name = "io"
version = "1.2.0"
version = "1.2.2"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.value"}
Expand All @@ -103,7 +104,7 @@ modules = [
[[package]]
org = "ballerina"
name = "jwt"
version = "2.2.0"
version = "2.2.1"
dependencies = [
{org = "ballerina", name = "cache"},
{org = "ballerina", name = "crypto"},
Expand Down Expand Up @@ -190,7 +191,7 @@ dependencies = [
[[package]]
org = "ballerina"
name = "log"
version = "2.2.0"
version = "2.2.1"
dependencies = [
{org = "ballerina", name = "io"},
{org = "ballerina", name = "jballerina.java"},
Expand All @@ -204,7 +205,7 @@ modules = [
[[package]]
org = "ballerina"
name = "mime"
version = "2.2.0"
version = "2.2.2"
dependencies = [
{org = "ballerina", name = "io"},
{org = "ballerina", name = "jballerina.java"},
Expand All @@ -214,7 +215,7 @@ dependencies = [
[[package]]
org = "ballerina"
name = "oauth2"
version = "2.2.0"
version = "2.2.1"
dependencies = [
{org = "ballerina", name = "cache"},
{org = "ballerina", name = "crypto"},
Expand All @@ -226,15 +227,15 @@ dependencies = [
[[package]]
org = "ballerina"
name = "observe"
version = "1.0.1"
version = "1.0.5"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]

[[package]]
org = "ballerina"
name = "os"
version = "1.2.0"
version = "1.2.1"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]
Expand All @@ -245,7 +246,7 @@ modules = [
[[package]]
org = "ballerina"
name = "regex"
version = "1.2.0"
version = "1.2.1"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]
Expand All @@ -256,7 +257,7 @@ modules = [
[[package]]
org = "ballerina"
name = "task"
version = "2.2.0"
version = "2.2.2"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "time"}
Expand All @@ -277,7 +278,7 @@ modules = [
[[package]]
org = "ballerina"
name = "time"
version = "2.2.0"
version = "2.2.2"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]
Expand All @@ -288,7 +289,7 @@ modules = [
[[package]]
org = "ballerina"
name = "url"
version = "2.2.0"
version = "2.2.2"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]
Expand Down
2 changes: 1 addition & 1 deletion cosmosdb/Package.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The `azure_cosmosdb` is a [Ballerina](https://ballerina.io/) connector for Azure
### Compatibility
| | Version |
|----------------------|-------------------------------|
| Ballerina Language | Ballerina Swan Lake 2201.0.0 |
| Ballerina Language | Ballerina Swan Lake 2201.1.0 |
| Cosmos DB (SQL)API | 2018-12-31 |

## Report issues
Expand Down
6 changes: 4 additions & 2 deletions cosmosdb/iterator.bal
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,16 @@ public class ResultIterator {
public isolated function next() returns record {|record {} value;|}|Error? {
record {}|Error? result;
result = nextResult(self);
if (result is record {}) {
if result is record {} {
record {|
record {} value;
|} streamRecord = {value: result};
return streamRecord;
} else {
} else if result is Error {
self.err = result;
return self.err;
} else {
return result;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion cosmosdb/tests/test.bal
Original file line number Diff line number Diff line change
Expand Up @@ -484,9 +484,9 @@ function testGetDocumentList() returns error? {
stream<Person, error?> result = check azureCosmosClient->getDocumentList(databaseId, containerId,
valueOfPartitionKey);
check result.forEach(isolated function(Person queryResult) {
test:assertTrue(queryResult is Person);
test:assertEquals(1234, queryResult.AccountNumber);
});

}

@test:Config {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
org.gradle.caching=true
group=org.ballerinalang.azure_cosmosdb
version=3.0.1
ballerinaLangVersion=2201.0.3
ballerinaLangVersion=2201.1.0
azureCosmosVersion=4.21.1

0 comments on commit 4da2397

Please sign in to comment.