-
Notifications
You must be signed in to change notification settings - Fork 207
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 all 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
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
261 changes: 261 additions & 0 deletions
261
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,261 @@ | ||
| package {{ sdk.namespace | caseDot }} | ||
|
|
||
| // Marker interfaces for type safety | ||
| public interface _Root | ||
| public interface _Database | ||
| public interface _Collection | ||
| public interface _Document | ||
| public interface _TablesDB | ||
| public interface _Table | ||
| public interface _Row | ||
| public interface _Bucket | ||
| public interface _File | ||
| public interface _Func | ||
| public interface _Execution | ||
| public interface _Team | ||
| public interface _Membership | ||
| public interface _Resolved | ||
|
|
||
| // Union type for actionable channels | ||
| typealias Actionable = _Document | ||
|
|
||
| /** | ||
| * Helper for normalizing IDs | ||
| */ | ||
| private fun normalize(id: String): String { | ||
| val trimmed = id.trim() | ||
| return if (trimmed.isEmpty()) "*" else trimmed | ||
| } | ||
|
|
||
| /** | ||
| * Channel class with generic type parameter for type-safe method chaining | ||
| */ | ||
| class Channel<out T> private constructor( | ||
| private val segments: List<String> | ||
| ) { | ||
| /** | ||
| * Internal helper to transition to next state with segment and ID | ||
| * Public for extension function access | ||
| */ | ||
| fun <N> next(segment: String, id: String = "*"): Channel<N> { | ||
| return Channel(segments + listOf(segment, normalize(id))) | ||
| } | ||
|
|
||
| /** | ||
| * Internal helper for terminal actions (no ID segment) | ||
| * Public for extension function access | ||
| */ | ||
| fun resolve(action: String): Channel<_Resolved> { | ||
| return Channel(segments + listOf(action)) | ||
| } | ||
|
|
||
| /** | ||
| * Convert channel to string representation | ||
| */ | ||
| override fun toString(): String = segments.joinToString(".") | ||
|
|
||
| companion object { | ||
| fun database(id: String = "*"): Channel<_Database> = | ||
| Channel(listOf("databases", normalize(id))) | ||
|
|
||
| fun tablesdb(id: String = "*"): Channel<_TablesDB> = | ||
| Channel(listOf("tablesdb", normalize(id))) | ||
|
|
||
| fun bucket(id: String = "*"): Channel<_Bucket> = | ||
| Channel(listOf("buckets", normalize(id))) | ||
|
|
||
| fun function(id: String = "*"): Channel<_Func> = | ||
| Channel(listOf("functions", normalize(id))) | ||
|
|
||
| fun team(id: String = "*"): Channel<_Team> = | ||
| Channel(listOf("teams", normalize(id))) | ||
|
|
||
| fun membership(id: String = "*"): Channel<_Membership> = | ||
| Channel(listOf("memberships", normalize(id))) | ||
|
|
||
| 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" | ||
| } | ||
| } | ||
|
|
||
| // --- DATABASE ROUTE --- | ||
| // Extension functions restricted by receiver type | ||
|
|
||
| /** | ||
| * Only available on Channel<_Database> | ||
| */ | ||
| fun Channel<_Database>.collection(id: String = "*"): Channel<_Collection> = | ||
| this.next("collections", id) | ||
|
|
||
| /** | ||
| * Only available on Channel<_Collection> | ||
| */ | ||
| fun Channel<_Collection>.document(id: String = "*"): Channel<_Document> = | ||
| this.next("documents", id) | ||
|
|
||
| // --- TABLESDB ROUTE --- | ||
|
|
||
| /** | ||
| * Only available on Channel<_TablesDB> | ||
| */ | ||
| fun Channel<_TablesDB>.table(id: String = "*"): Channel<_Table> = | ||
| this.next("tables", id) | ||
|
|
||
| /** | ||
| * Only available on Channel<_Table> | ||
| */ | ||
| fun Channel<_Table>.row(id: String = "*"): Channel<_Row> = | ||
| this.next("rows", id) | ||
|
|
||
| // --- BUCKET ROUTE --- | ||
|
|
||
| /** | ||
| * Only available on Channel<_Bucket> | ||
| */ | ||
| fun Channel<_Bucket>.file(id: String = "*"): Channel<_File> = | ||
| this.next("files", id) | ||
|
|
||
| // --- FUNCTION ROUTE --- | ||
|
|
||
| /** | ||
| * Only available on Channel<_Func> | ||
| */ | ||
| fun Channel<_Func>.execution(id: String = "*"): Channel<_Execution> = | ||
| this.next("executions", id) | ||
|
|
||
| // --- TERMINAL ACTIONS --- | ||
| // Restricted to Actionable types (_Document, _Row, _File, _Execution, _Team, _Membership) | ||
|
|
||
| /** | ||
| * Only available on Channel<_Document> | ||
| */ | ||
| @JvmName("createDocument") | ||
| fun Channel<_Document>.create(): Channel<_Resolved> = | ||
| this.resolve("create") | ||
|
|
||
| /** | ||
| * Only available on Channel<_Document> | ||
| */ | ||
| @JvmName("updateDocument") | ||
| fun Channel<_Document>.update(): Channel<_Resolved> = | ||
| this.resolve("update") | ||
|
|
||
| /** | ||
| * Only available on Channel<_Document> | ||
| */ | ||
| @JvmName("deleteDocument") | ||
| fun Channel<_Document>.delete(): Channel<_Resolved> = | ||
| this.resolve("delete") | ||
|
|
||
| /** | ||
| * Only available on Channel<_Row> | ||
| */ | ||
| @JvmName("createRow") | ||
| fun Channel<_Row>.create(): Channel<_Resolved> = | ||
| this.resolve("create") | ||
|
|
||
| /** | ||
| * Only available on Channel<_Row> | ||
| */ | ||
| @JvmName("updateRow") | ||
| fun Channel<_Row>.update(): Channel<_Resolved> = | ||
| this.resolve("update") | ||
|
|
||
| /** | ||
| * Only available on Channel<_Row> | ||
| */ | ||
| @JvmName("deleteRow") | ||
| fun Channel<_Row>.delete(): Channel<_Resolved> = | ||
| this.resolve("delete") | ||
|
|
||
| /** | ||
| * Only available on Channel<_File> | ||
| */ | ||
| @JvmName("createFile") | ||
| fun Channel<_File>.create(): Channel<_Resolved> = | ||
| this.resolve("create") | ||
|
|
||
| /** | ||
| * Only available on Channel<_File> | ||
| */ | ||
| @JvmName("updateFile") | ||
| fun Channel<_File>.update(): Channel<_Resolved> = | ||
| this.resolve("update") | ||
|
|
||
| /** | ||
| * Only available on Channel<_File> | ||
| */ | ||
| @JvmName("deleteFile") | ||
| fun Channel<_File>.delete(): Channel<_Resolved> = | ||
| this.resolve("delete") | ||
|
|
||
| /** | ||
| * Only available on Channel<_Execution> | ||
| */ | ||
| @JvmName("createExecution") | ||
| fun Channel<_Execution>.create(): Channel<_Resolved> = | ||
| this.resolve("create") | ||
|
|
||
| /** | ||
| * Only available on Channel<_Execution> | ||
| */ | ||
| @JvmName("updateExecution") | ||
| fun Channel<_Execution>.update(): Channel<_Resolved> = | ||
| this.resolve("update") | ||
|
|
||
| /** | ||
| * Only available on Channel<_Execution> | ||
| */ | ||
| @JvmName("deleteExecution") | ||
| fun Channel<_Execution>.delete(): Channel<_Resolved> = | ||
| this.resolve("delete") | ||
|
|
||
| /** | ||
| * Only available on Channel<_Team> | ||
| */ | ||
| @JvmName("createTeam") | ||
| fun Channel<_Team>.create(): Channel<_Resolved> = | ||
| this.resolve("create") | ||
|
|
||
| /** | ||
| * Only available on Channel<_Team> | ||
| */ | ||
| @JvmName("updateTeam") | ||
| fun Channel<_Team>.update(): Channel<_Resolved> = | ||
| this.resolve("update") | ||
|
|
||
| /** | ||
| * Only available on Channel<_Team> | ||
| */ | ||
| @JvmName("deleteTeam") | ||
| fun Channel<_Team>.delete(): Channel<_Resolved> = | ||
| this.resolve("delete") | ||
|
|
||
| /** | ||
| * Only available on Channel<_Membership> | ||
| */ | ||
| @JvmName("createMembership") | ||
| fun Channel<_Membership>.create(): Channel<_Resolved> = | ||
| this.resolve("create") | ||
|
|
||
| /** | ||
| * Only available on Channel<_Membership> | ||
| */ | ||
| @JvmName("updateMembership") | ||
| fun Channel<_Membership>.update(): Channel<_Resolved> = | ||
| this.resolve("update") | ||
|
|
||
| /** | ||
| * Only available on Channel<_Membership> | ||
| */ | ||
| @JvmName("deleteMembership") | ||
| fun Channel<_Membership>.delete(): Channel<_Resolved> = | ||
| this.resolve("delete") | ||
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.