Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: tests #769

Merged
merged 21 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
fail-fast: false
matrix:
php-version: ['8.2']
sdk: [Android5Java17, Android14Java17, CLINode16, CLINode18, DartBeta, DartStable, Deno1193, Deno1303, DotNet60, DotNet70, FlutterStable, FlutterBeta, Go112, Go118, KotlinJava8, KotlinJava11, KotlinJava17, Node16, Node18, Node20, PHP74, PHP80, Python38, Python39, Python310, Ruby27, Ruby30, Ruby31, AppleSwift55, Swift55, WebChromium, WebNode]
sdk: [Android5Java17, Android14Java17, CLINode16, CLINode18, DartBeta, DartStable, Deno1193, Deno1303, DotNet60, DotNet70, FlutterStable, FlutterBeta, Go112, Go118, KotlinJava8, KotlinJava11, KotlinJava17, Node16, Node18, Node20, PHP74, PHP80, Python38, Python39, Python310, Ruby27, Ruby30, Ruby31, AppleSwift56, Swift56, WebChromium, WebNode]

steps:
- name: Checkout repository
Expand Down
5 changes: 0 additions & 5 deletions src/SDK/Language/Android.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,6 @@ public function getFiles(): array
'destination' => '/library/src/main/java/{{ sdk.namespace | caseSlash }}/extensions/CollectionExtensions.kt',
'template' => '/android/library/src/main/java/io/package/extensions/CollectionExtensions.kt.twig',
],
[
'scope' => 'default',
'destination' => '/library/src/main/java/{{ sdk.namespace | caseSlash }}/json/PreciseNumberAdapter.kt',
'template' => '/android/library/src/main/java/io/package/json/PreciseNumberAdapter.kt.twig',
],
[
'scope' => 'default',
'destination' => '/library/src/main/java/{{ sdk.namespace | caseSlash }}/models/InputFile.kt',
Expand Down
12 changes: 1 addition & 11 deletions src/SDK/Language/Apple.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function getFiles(): array
[
'scope' => 'default',
'destination' => 'Package.swift',
'template' => 'swift/Package.swift.twig',
'template' => 'apple/Package.swift.twig',
],
[
'scope' => 'method',
Expand Down Expand Up @@ -246,16 +246,6 @@ public function getFiles(): array
'destination' => '/Sources/{{ spec.title | caseUcfirst}}/WebSockets/WebSocketClientError.swift',
'template' => '/swift/Sources/WebSockets/WebSocketClientError.swift.twig',
],
[
'scope' => 'default',
'destination' => '/Sources/{{ spec.title | caseUcfirst}}/{{ spec.title | caseUcfirst }}Delegate.swift',
'template' => '/swift/Sources/Delegate.swift.twig',
],
[
'scope' => 'default',
'destination' => '/Sources/{{ spec.title | caseUcfirst}}/NotificationHandler.swift',
'template' => '/swift/Sources/NotificationHandler.swift.twig',
],
// Config for project example-swiftui
[
'scope' => 'default',
Expand Down
5 changes: 0 additions & 5 deletions src/SDK/Language/Kotlin.php
Original file line number Diff line number Diff line change
Expand Up @@ -386,11 +386,6 @@ public function getFiles(): array
'template' => '/kotlin/src/main/kotlin/io/appwrite/extensions/TypeExtensions.kt.twig',
'minify' => false,
],
[
'scope' => 'default',
'destination' => '/src/main/kotlin/{{ sdk.namespace | caseSlash }}/json/PreciseNumberAdapter.kt',
'template' => '/kotlin/src/main/kotlin/io/appwrite/json/PreciseNumberAdapter.kt.twig',
],
[
'scope' => 'default',
'destination' => '/src/main/kotlin/{{ sdk.namespace | caseSlash }}/services/Service.kt',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ package {{ sdk.namespace | caseDot }}.extensions

import com.google.gson.Gson
import com.google.gson.GsonBuilder
import com.google.gson.ToNumberPolicy
import com.google.gson.reflect.TypeToken
import {{ sdk.namespace | caseDot }}.json.PreciseNumberAdapter

val gson: Gson = GsonBuilder()
.registerTypeAdapter(
object : TypeToken<Map<String, Any>>() {}.type,
PreciseNumberAdapter()
)
.setNumberToNumberStrategy(ToNumberPolicy.LONG_OR_DOUBLE)
.setObjectToNumberStrategy(ToNumberPolicy.LONG_OR_DOUBLE)
.create()

fun Any.toJson(): String =
Expand Down

This file was deleted.

67 changes: 67 additions & 0 deletions templates/apple/Package.swift.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// swift-tools-version:5.1

import PackageDescription

let package = Package(
name: "{{spec.title | caseUcfirst}}",
platforms: [
.iOS("15.0"),
.macOS("11.0"),
.watchOS("7.0"),
.tvOS("13.0"),
],
products: [
.library(
name: "{{spec.title | caseUcfirst}}",
targets: [
"{{spec.title | caseUcfirst}}",
"{{spec.title | caseUcfirst}}Enums",
"{{spec.title | caseUcfirst}}Models",
"JSONCodable"
]
),
],
dependencies: [
.package(url: "https://github.com/swift-server/async-http-client.git", from: "1.9.0"),
.package(url: "https://github.com/apple/swift-nio.git", from: "2.32.0"),
],
targets: [
.target(
name: "{{spec.title | caseUcfirst}}",
dependencies: [
.product(name: "AsyncHTTPClient", package: "async-http-client"),
.product(name: "NIOWebSocket", package: "swift-nio"),
{%~ if spec.definitions is not empty %}
"{{spec.title | caseUcfirst}}Models",
{%~ endif %}
{%~ if spec.enums is not empty %}
"{{spec.title | caseUcfirst}}Enums",
{%~ endif %}
"JSONCodable"
]
),
{%~ if spec.definitions is not empty %}
.target(
name: "{{spec.title | caseUcfirst}}Models",
dependencies: [
"JSONCodable"
]
),
{%~ endif %}
{%~ if spec.enums is not empty %}
.target(
name: "{{spec.title | caseUcfirst}}Enums"
),
{%~ endif %}
.target(
name: "JSONCodable"
),
.testTarget(
name: "{{spec.title | caseUcfirst}}Tests",
dependencies: [
"{{ spec.title | caseUcfirst }}"
]
)
],
swiftLanguageVersions: [.v5]
)
16 changes: 0 additions & 16 deletions templates/apple/Sources/Client.swift.twig
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ open class Client {
http = Client.createHTTP()
addUserAgentHeader()
addOriginHeader()

NotificationHandler.shared.client = self
}

private static func createHTTP(
Expand Down Expand Up @@ -88,7 +86,6 @@ open class Client {
decompression: .enabled(limit: .none)
)
)

}

deinit {
Expand Down Expand Up @@ -165,19 +162,6 @@ open class Client {
return self
}

///
/// Set push provider ID.
///
/// @param String endpoint
///
/// @return this
///
open func setPushProviderId(_ providerId: String) -> Client {
NotificationHandler.shared.providerId = providerId

return self
}

///
/// Add header
///
Expand Down
2 changes: 1 addition & 1 deletion templates/dart/lib/query.dart.twig
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class Query {
Query._('contains', attribute, value).toString();

static String or(List<String> queries) =>
Query._('and', null, queries.map((query) => jsonDecode(query)).toList()).toString();
Query._('or', null, queries.map((query) => jsonDecode(query)).toList()).toString();

static String and(List<String> queries) =>
Query._('and', null, queries.map((query) => jsonDecode(query)).toList()).toString();
Expand Down
12 changes: 9 additions & 3 deletions templates/dotnet/src/Appwrite/Query.cs.twig
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@ namespace Appwrite
this.method = method;
this.attribute = attribute;

if (values == null || values is IList)
if (values is IList valuesList)
{
this.values = new List<object>();
foreach (var value in valuesList)
{
this.values.Add(value); // Automatically boxes if value is a value type
}
}
else if (values != null)
{
this.values = (List<object>?)values;
} else {
this.values = new List<object> { values };
}
}
Expand Down
2 changes: 1 addition & 1 deletion templates/kotlin/build.gradle.twig
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ dependencies {
implementation("com.squareup.okhttp3:logging-interceptor")
implementation("com.google.code.gson:gson:2.9.0")

testImplementation 'org.jetbrains.kotlin:kotlin-test-junit'
testImplementation("org.jetbrains.kotlin:kotlin-test-junit")
}

test {
Expand Down
2 changes: 1 addition & 1 deletion templates/kotlin/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
23 changes: 6 additions & 17 deletions templates/kotlin/src/main/kotlin/io/appwrite/Client.kt.twig
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package {{ sdk.namespace | caseDot }}

import com.google.gson.GsonBuilder
import com.google.gson.reflect.TypeToken
import {{ sdk.namespace | caseDot }}.exceptions.{{ spec.title | caseUcfirst }}Exception
import {{ sdk.namespace | caseDot }}.extensions.fromJson
import {{ sdk.namespace | caseDot }}.json.PreciseNumberAdapter
import {{ sdk.namespace | caseDot }}.extensions.toJson
import {{ sdk.namespace | caseDot }}.models.InputFile
import {{ sdk.namespace | caseDot }}.models.UploadProgress
import kotlinx.coroutines.CoroutineScope
Expand Down Expand Up @@ -47,11 +45,6 @@ class Client @JvmOverloads constructor(

private val job = Job()

private val gson = GsonBuilder().registerTypeAdapter(
object : TypeToken<Map<String, Any>>(){}.type,
PreciseNumberAdapter()
).create()

lateinit var http: OkHttpClient

private val headers: MutableMap<String, String>
Expand Down Expand Up @@ -252,7 +245,8 @@ class Client @JvmOverloads constructor(
}
builder.build()
} else {
gson.toJson(filteredParams)
filteredParams
.toJson()
.toRequestBody("application/json".toMediaType())
}

Expand Down Expand Up @@ -422,10 +416,8 @@ class Client @JvmOverloads constructor(
.use(BufferedReader::readText)

val error = if (response.headers["content-type"]?.contains("application/json") == true) {
val map = gson.fromJson<Map<String, Any>>(
body,
object : TypeToken<Map<String, Any>>(){}.type
)
val map = body.fromJson<Map<String, Any>>()

{{ spec.title | caseUcfirst }}Exception(
map["message"] as? String ?: "",
(map["code"] as Number).toInt(),
Expand Down Expand Up @@ -464,10 +456,7 @@ class Client @JvmOverloads constructor(
it.resume(true as T)
return
}
val map = gson.fromJson<Map<String, Any>>(
body,
object : TypeToken<Map<String, Any>>(){}.type
)
val map = body.fromJson<Map<String, Any>>()
it.resume(
converter?.invoke(map) ?: map as T
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
package {{ sdk.namespace | caseDot }}.extensions

import com.google.gson.Gson

val gson = Gson()
import com.google.gson.GsonBuilder
import com.google.gson.ToNumberPolicy
import com.google.gson.reflect.TypeToken

val gson: Gson = GsonBuilder()
.setNumberToNumberStrategy(ToNumberPolicy.LONG_OR_DOUBLE)
.setObjectToNumberStrategy(ToNumberPolicy.LONG_OR_DOUBLE)
.create()

fun Any.toJson(): String =
gson.toJson(this)
Expand Down
Loading
Loading