-
Notifications
You must be signed in to change notification settings - Fork 206
Added channel helpers for realtime in the client sdks #1266
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
Merged
Changes from 10 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
29471d1
added channel helpers for realtime in the client sdks
ArnabChatterjee20k 3f13cb1
Add Channel support to SDKs and templates
ArnabChatterjee20k 5d19169
reverted changes
ArnabChatterjee20k b18671f
Refactor Channel references to use NIOCore.Channel and remove unused …
ArnabChatterjee20k fd57b65
Refractor channel to use builder pattern
ArnabChatterjee20k 3e2402d
updated flutter config
ArnabChatterjee20k 4ff8dd6
Refactor channel handling and subscription logic across multiple temp…
ArnabChatterjee20k 61710ea
Refactor channel and interface definitions for improved clarity and c…
ArnabChatterjee20k 9252cc3
fixed flutter
ArnabChatterjee20k 4c3bef7
updated kotlin and swift
ArnabChatterjee20k 05046c8
fixed swift
ArnabChatterjee20k 9f5f635
Refactor channel method names for consistency across languages
ArnabChatterjee20k 0b840f9
updated bucket
ArnabChatterjee20k 7571e2d
updated react native and web ts
ArnabChatterjee20k 2ed26c9
updated channel and resolved channel validation in web
ArnabChatterjee20k 77147bd
added overloading for type strictness in kotlin
ArnabChatterjee20k 6b30e48
removed leftovers
ArnabChatterjee20k cd88974
updated leftover
ArnabChatterjee20k d248155
fixed failing swift tests
ArnabChatterjee20k b0533b1
fixed failing swift tests
ArnabChatterjee20k 903bdb3
Merge remote-tracking branch 'origin/dat-971' into dat-971
ArnabChatterjee20k 18152a1
revamped realtime channel support for the js realtime
ArnabChatterjee20k 9a74e33
refactor: enhance channel structure and type safety across multiple l…
ArnabChatterjee20k 6d627f3
Merge remote-tracking branch 'origin/master' into dat-971
ArnabChatterjee20k dde2c4b
refactor: update channel interfaces for improved type safety
ArnabChatterjee20k 3ed2d3e
updated kotlin
ArnabChatterjee20k 163e7fc
updated swift issue
ArnabChatterjee20k 45a8b61
Merge remote-tracking branch 'origin/master' into dat-971
ArnabChatterjee20k 8af59f4
fixed android client build
ArnabChatterjee20k File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
137 changes: 137 additions & 0 deletions
137
templates/android/library/src/main/java/io/package/Channel.kt.twig
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| package {{ sdk.namespace | caseDot }} | ||
|
|
||
| // The result of building the channel. | ||
| class ResolvedChannel(private val value: String) { | ||
| override fun toString(): String { | ||
| return value | ||
| } | ||
| } | ||
|
|
||
| // Helper for normalizing IDs | ||
| private fun normalize(id: String): String { | ||
| val trimmed = id.trim() | ||
| return if (trimmed.isEmpty()) "*" else trimmed | ||
| } | ||
|
|
||
| // Interface for actionable channels | ||
| interface Actionable { | ||
| val channel: String | ||
| fun create(): ResolvedChannel | ||
| fun update(): ResolvedChannel | ||
| fun delete(): ResolvedChannel | ||
| } | ||
|
|
||
| interface IDatabase { | ||
|
abnegate marked this conversation as resolved.
Outdated
|
||
| fun collection(id: String = "*"): ICollection | ||
| } | ||
|
|
||
| interface ICollection { | ||
| fun document(id: String = "*"): IDocument | ||
| } | ||
|
|
||
| interface IDocument : Actionable | ||
|
|
||
| interface ITablesDB { | ||
| fun table(id: String = "*"): ITable | ||
| } | ||
|
|
||
| interface ITable { | ||
| fun row(id: String = "*"): IRow | ||
| } | ||
|
|
||
| interface IRow : Actionable | ||
|
|
||
| interface IBucket { | ||
| fun file(id: String = "*"): IFile | ||
| } | ||
|
|
||
| interface IFile : Actionable | ||
|
|
||
| interface IFunction { | ||
| fun execution(id: String = "*"): IExecution | ||
| } | ||
|
|
||
| interface IExecution : Actionable | ||
|
|
||
| private class ChannelBuilder( | ||
| private val segments: List<String> | ||
| ) : IDatabase, ICollection, IDocument, | ||
| ITablesDB, ITable, IRow, | ||
| IBucket, IFile, | ||
| IFunction, IExecution, Actionable { | ||
|
|
||
| companion object { | ||
| fun start(segments: List<String>) = ChannelBuilder(segments) | ||
| } | ||
|
|
||
| private fun next(segment: String, id: String): ChannelBuilder { | ||
| return ChannelBuilder(segments + listOf(segment, normalize(id))) | ||
| } | ||
|
|
||
| override fun collection(id: String): ICollection = | ||
| next("collections", id) | ||
|
|
||
| override fun document(id: String): IDocument = | ||
| next("documents", id) | ||
|
|
||
| override fun table(id: String): ITable = | ||
| next("tables", id) | ||
|
|
||
| override fun row(id: String): IRow = | ||
| next("rows", id) | ||
|
|
||
| override fun file(id: String): IFile = | ||
| next("files", id) | ||
|
|
||
| override fun execution(id: String): IExecution = | ||
| next("executions", id) | ||
|
|
||
| override val channel: String | ||
| get() = segments.joinToString(".") | ||
|
|
||
| override fun create(): ResolvedChannel = | ||
| ResolvedChannel("$channel.create") | ||
|
|
||
| override fun update(): ResolvedChannel = | ||
| ResolvedChannel("$channel.update") | ||
|
|
||
| override fun delete(): ResolvedChannel = | ||
| ResolvedChannel("$channel.delete") | ||
|
|
||
| override fun toString(): String = channel | ||
| } | ||
|
|
||
| class Channel private constructor() { | ||
|
|
||
| companion object { | ||
|
|
||
| fun database(id: String = "*"): IDatabase = | ||
| ChannelBuilder.start(listOf("databases", normalize(id))) | ||
|
|
||
| fun tablesdb(id: String = "*"): ITablesDB = | ||
| ChannelBuilder.start(listOf("tablesdb", normalize(id))) | ||
|
|
||
| fun buckets(id: String = "*"): IBucket = | ||
| ChannelBuilder.start(listOf("buckets", normalize(id))) | ||
|
|
||
| fun functions(id: String = "*"): IFunction = | ||
| ChannelBuilder.start(listOf("functions", normalize(id))) | ||
|
|
||
| fun teams(id: String = "*"): Actionable = | ||
| ChannelBuilder.start(listOf("teams", normalize(id))) | ||
|
|
||
| fun memberships(id: String = "*"): Actionable = | ||
| ChannelBuilder.start(listOf("memberships", normalize(id))) | ||
|
abnegate marked this conversation as resolved.
Outdated
|
||
|
|
||
| fun account(userId: String = ""): String { | ||
| val id = normalize(userId) | ||
| return if (id == "*") "account" else "account.$id" | ||
| } | ||
|
|
||
| // Global events | ||
| const val documents = "documents" | ||
| const val rows = "rows" | ||
| const val files = "files" | ||
| const val executions = "executions" | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.