Skip to content
Open
Show file tree
Hide file tree
Changes from 5 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
5 changes: 5 additions & 0 deletions src/SDK/Language/Android.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ public function getFiles(): array
'destination' => '/library/src/main/java/{{ sdk.namespace | caseSlash }}/ID.kt',
'template' => '/android/library/src/main/java/io/package/ID.kt.twig',
],
[
'scope' => 'default',
'destination' => '/library/src/main/java/{{ sdk.namespace | caseSlash }}/Channel.kt',
'template' => '/android/library/src/main/java/io/package/Channel.kt.twig',
],
[
'scope' => 'default',
'destination' => '/library/src/main/java/{{ sdk.namespace | caseSlash }}/Query.kt',
Expand Down
5 changes: 5 additions & 0 deletions src/SDK/Language/Apple.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ public function getFiles(): array
'destination' => '/Sources/{{ spec.title | caseUcfirst}}/ID.swift',
'template' => 'swift/Sources/ID.swift.twig',
],
[
'scope' => 'default',
'destination' => '/Sources/{{ spec.title | caseUcfirst}}/Channel.swift',
'template' => 'apple/Sources/Channel.swift.twig',
],
[
'scope' => 'default',
'destination' => '/Sources/{{ spec.title | caseUcfirst}}/Query.swift',
Expand Down
10 changes: 10 additions & 0 deletions src/SDK/Language/Dart.php
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,11 @@ public function getFiles(): array
'destination' => '/lib/id.dart',
'template' => 'dart/lib/id.dart.twig',
],
[
'scope' => 'default',
'destination' => '/lib/channel.dart',
'template' => 'dart/lib/channel.dart.twig',
],
[
'scope' => 'default',
'destination' => '/lib/query.dart',
Expand Down Expand Up @@ -464,6 +469,11 @@ public function getFiles(): array
'destination' => '/test/role_test.dart',
'template' => 'dart/test/role_test.dart.twig',
],
[
'scope' => 'default',
'destination' => '/test/channel_test.dart',
'template' => 'dart/test/channel_test.dart.twig',
],
[
'scope' => 'default',
'destination' => '/test/src/enums_test.dart',
Expand Down
10 changes: 10 additions & 0 deletions src/SDK/Language/Flutter.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ public function getFiles(): array
'destination' => '/lib/id.dart',
'template' => 'dart/lib/id.dart.twig',
],
[
'scope' => 'default',
'destination' => '/lib/channel.dart',
'template' => 'flutter/lib/channel.dart.twig',
],
[
'scope' => 'default',
'destination' => '/lib/query.dart',
Expand Down Expand Up @@ -290,6 +295,11 @@ public function getFiles(): array
'destination' => '/test/role_test.dart',
'template' => 'dart/test/role_test.dart.twig',
],
[
'scope' => 'default',
'destination' => '/test/channel_test.dart',
'template' => 'dart/test/channel_test.dart.twig',
],
[
'scope' => 'default',
'destination' => '/test/src/cookie_manager_test.dart',
Expand Down
5 changes: 5 additions & 0 deletions src/SDK/Language/ReactNative.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ public function getFiles(): array
'destination' => 'src/id.ts',
'template' => 'react-native/src/id.ts.twig',
],
[
'scope' => 'default',
'destination' => 'src/channel.ts',
'template' => 'react-native/src/channel.ts.twig',
],
[
'scope' => 'default',
'destination' => 'src/query.ts',
Expand Down
5 changes: 5 additions & 0 deletions src/SDK/Language/Web.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ public function getFiles(): array
'destination' => 'src/id.ts',
'template' => 'web/src/id.ts.twig',
],
[
'scope' => 'default',
'destination' => 'src/channel.ts',
'template' => 'web/src/channel.ts.twig',
],
[
'scope' => 'default',
'destination' => 'src/query.ts',
Expand Down
190 changes: 190 additions & 0 deletions templates/android/library/src/main/java/io/package/Channel.kt.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
package {{ sdk.namespace | caseDot }}

class ResolvedChannel(private val value: String) {
override fun toString(): String {
return value
}
}

abstract class ActionChannel(protected val base: String) {
fun create(): ResolvedChannel {
return ResolvedChannel("$base.create")
}

fun update(): ResolvedChannel {
return ResolvedChannel("$base.update")
}

fun delete(): ResolvedChannel {
return ResolvedChannel("$base.delete")
}

override fun toString(): String {
return base
}
}

class DocumentChannel(base: String) : ActionChannel(base)

class CollectionChannel(
private val databaseId: String,
private val collectionId: String
) {
private val base = "databases.$databaseId.collections.$collectionId"

fun document(documentId: String = "*"): DocumentChannel {
return DocumentChannel("$base.documents.$documentId")
}

override fun toString(): String {
return base
}
}

class DatabaseChannel(private val databaseId: String) {
private val base = "databases.$databaseId"

fun collection(collectionId: String = "*"): CollectionChannel {
return CollectionChannel(databaseId, collectionId)
}

override fun toString(): String {
return base
}
}

class RowChannel(base: String) : ActionChannel(base)

class TableChannel(
private val databaseId: String,
private val tableId: String
) {
private val base = "tablesdb.$databaseId.tables.$tableId"

fun row(rowId: String = "*"): RowChannel {
return RowChannel("$base.rows.$rowId")
}

override fun toString(): String {
return base
}
}

class TablesDBChannel(private val databaseId: String) {
private val base = "tablesdb.$databaseId"

fun table(tableId: String = "*"): TableChannel {
return TableChannel(databaseId, tableId)
}

override fun toString(): String {
return base
}
}

class FileChannel(base: String) : ActionChannel(base)

class BucketChannel(private val bucketId: String) {
private val base = "buckets.$bucketId"

fun file(fileId: String = "*"): FileChannel {
return FileChannel("$base.files.$fileId")
}

override fun toString(): String {
return base
}
}

class ExecutionChannel(base: String) : ActionChannel(base)

class FunctionChannel(private val functionId: String) {
private val base = "functions.$functionId"

fun execution(executionId: String = "*"): ExecutionChannel {
return ExecutionChannel("$base.executions.$executionId")
}

override fun toString(): String {
return base
}
}

class TeamChannel(teamId: String = "*") : ActionChannel("teams.$teamId")

class MembershipChannel(membershipId: String = "*") : ActionChannel("memberships.$membershipId")

class Channel {
companion object {
/**
* Generate a database channel builder.
*
* @param databaseId The database ID (default: "*")
* @returns DatabaseChannel
*/
fun database(databaseId: String = "*"): DatabaseChannel {
return DatabaseChannel(databaseId)
}

/**
* Generate a tables database channel builder.
*
* @param databaseId The database ID (default: "*")
* @returns TablesDBChannel
*/
fun tablesdb(databaseId: String = "*"): TablesDBChannel {
return TablesDBChannel(databaseId)
}

/**
* Generate a buckets channel builder.
*
* @param bucketId The bucket ID (default: "*")
* @returns BucketChannel
*/
fun buckets(bucketId: String = "*"): BucketChannel {
return BucketChannel(bucketId)
}

/**
* Generate a functions channel builder.
*
* @param functionId The function ID (default: "*")
* @returns FunctionChannel
*/
fun functions(functionId: String = "*"): FunctionChannel {
return FunctionChannel(functionId)
}

/**
* Generate a teams channel builder.
*
* @param teamId The team ID (default: "*")
* @returns TeamChannel
*/
fun teams(teamId: String = "*"): TeamChannel {
return TeamChannel(teamId)
}

/**
* Generate a memberships channel builder.
*
* @param membershipId The membership ID (default: "*")
* @returns MembershipChannel
*/
fun memberships(membershipId: String = "*"): MembershipChannel {
return MembershipChannel(membershipId)
}

/**
* Generate an account channel string.
*
* @param userId The user ID (default: "*")
* @returns The channel string
*/
fun account(userId: String = "*"): String {
return "account.$userId"
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,25 @@ class Realtime(client: Client) : Service(client), CoroutineScope {
else -> 60000L
}

/**
* Convert channel value to string
*/
private fun channelToString(channel: Any): String {
return when (channel) {
is String -> channel
else -> channel.toString()
}
}

fun subscribe(
vararg channels: Any,
callback: (RealtimeResponseEvent<Any>) -> Unit,
) = subscribe(
channels = channels.map { channelToString(it) }.toTypedArray(),
Any::class.java,
callback
)

fun subscribe(
vararg channels: String,
callback: (RealtimeResponseEvent<Any>) -> Unit,
Expand All @@ -118,6 +137,18 @@ class Realtime(client: Client) : Service(client), CoroutineScope {
callback
)

fun <T> subscribe(
vararg channels: Any,
payloadType: Class<T>,
callback: (RealtimeResponseEvent<T>) -> Unit,
): RealtimeSubscription {
return subscribe(
channels = channels.map { channelToString(it) }.toTypedArray(),
payloadType = payloadType,
callback = callback
)
}

fun <T> subscribe(
vararg channels: String,
payloadType: Class<T>,
Expand Down
Loading
Loading