-
Notifications
You must be signed in to change notification settings - Fork 193
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
base: master
Are you sure you want to change the base?
Changes from 4 commits
29471d1
3f13cb1
5d19169
b18671f
fd57b65
3e2402d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| package {{ sdk.namespace | caseDot }} | ||
|
|
||
| /** | ||
| * Helper class to generate channel strings for realtime subscriptions. | ||
| */ | ||
| class Channel { | ||
| companion object { | ||
|
|
||
| /** | ||
| * Generate a database channel string. | ||
| * | ||
| * @param databaseId The database ID (default: "*") | ||
| * @param collectionId The collection ID (default: "*") | ||
| * @param documentId The document ID (default: "*") | ||
| * @param action Optional action: "create", "update", or "delete" (default: null) | ||
| * @returns The channel string | ||
| */ | ||
| fun database(databaseId: String = "*", collectionId: String = "*", documentId: String = "*", action: String? = null): String { | ||
| var channel = "databases.$databaseId.collections.$collectionId.documents.$documentId" | ||
| if (action != null) { | ||
| channel += ".$action" | ||
| } | ||
| return channel | ||
| } | ||
|
|
||
| /** | ||
| * Generate a tables database channel string. | ||
| * | ||
| * @param databaseId The database ID (default: "*") | ||
| * @param tableId The table ID (default: "*") | ||
| * @param rowId The row ID (default: "*") | ||
| * @param action Optional action: "create", "update", or "delete" (default: null) | ||
| * @returns The channel string | ||
| */ | ||
| fun tablesdb(databaseId: String = "*", tableId: String = "*", rowId: String = "*", action: String? = null): String { | ||
| var channel = "tablesdb.$databaseId.tables.$tableId.rows.$rowId" | ||
| if (action != null) { | ||
| channel += ".$action" | ||
| } | ||
| return channel | ||
| } | ||
|
|
||
| /** | ||
| * Generate an account channel string. | ||
| * | ||
| * @param userId The user ID (default: "*") | ||
| * @returns The channel string | ||
| */ | ||
| fun account(userId: String = "*"): String { | ||
| return "account.$userId" | ||
| } | ||
|
|
||
| /** | ||
| * Generate a files channel string. | ||
| * | ||
| * @param bucketId The bucket ID (default: "*") | ||
| * @param fileId The file ID (default: "*") | ||
| * @param action Optional action: "create", "update", or "delete" (default: null) | ||
| * @returns The channel string | ||
| */ | ||
| fun files(bucketId: String = "*", fileId: String = "*", action: String? = null): String { | ||
| var channel = "buckets.$bucketId.files.$fileId" | ||
| if (action != null) { | ||
| channel += ".$action" | ||
| } | ||
| return channel | ||
| } | ||
|
|
||
| /** | ||
| * Generate an executions channel string. | ||
| * | ||
| * @param functionId The function ID (default: "*") | ||
| * @param executionId The execution ID (default: "*") | ||
| * @param action Optional action: "create", "update", or "delete" (default: null) | ||
| * @returns The channel string | ||
| */ | ||
| fun executions(functionId: String = "*", executionId: String = "*", action: String? = null): String { | ||
| var channel = "functions.$functionId.executions.$executionId" | ||
| if (action != null) { | ||
| channel += ".$action" | ||
| } | ||
| return channel | ||
| } | ||
|
|
||
| /** | ||
| * Generate a teams channel string. | ||
| * | ||
| * @param teamId The team ID (default: "*") | ||
| * @param action Optional action: "create", "update", or "delete" (default: null) | ||
| * @returns The channel string | ||
| */ | ||
| fun teams(teamId: String = "*", action: String? = null): String { | ||
| var channel = "teams.$teamId" | ||
| if (action != null) { | ||
| channel += ".$action" | ||
| } | ||
| return channel | ||
| } | ||
|
|
||
| /** | ||
| * Generate a memberships channel string. | ||
| * | ||
| * @param membershipId The membership ID (default: "*") | ||
| * @param action Optional action: "create", "update", or "delete" (default: null) | ||
| * @returns The channel string | ||
| */ | ||
| fun memberships(membershipId: String = "*", action: String? = null): String { | ||
| var channel = "memberships.$membershipId" | ||
| if (action != null) { | ||
| channel += ".$action" | ||
| } | ||
| return channel | ||
| } | ||
| } | ||
| } | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| import Foundation | ||
|
|
||
| public class Channel { | ||
| /** | ||
| * Generate a database channel string. | ||
| * | ||
| * @param databaseId The database ID (default: "*") | ||
| * @param collectionId The collection ID (default: "*") | ||
| * @param documentId The document ID (default: "*") | ||
| * @param action Optional action: "create", "update", or "delete" (default: nil) | ||
| * @returns The channel string | ||
| */ | ||
| public static func database(databaseId: String = "*", collectionId: String = "*", documentId: String = "*", action: String? = nil) -> String { | ||
| var channel = "databases.\(databaseId).collections.\(collectionId).documents.\(documentId)" | ||
| if let action = action { | ||
| channel += ".\(action)" | ||
| } | ||
| return channel | ||
| } | ||
|
||
|
|
||
| /** | ||
| * Generate a tables database channel string. | ||
| * | ||
| * @param databaseId The database ID (default: "*") | ||
| * @param tableId The table ID (default: "*") | ||
| * @param rowId The row ID (default: "*") | ||
| * @param action Optional action: "create", "update", or "delete" (default: nil) | ||
| * @returns The channel string | ||
| */ | ||
| public static func tablesdb(databaseId: String = "*", tableId: String = "*", rowId: String = "*", action: String? = nil) -> String { | ||
| var channel = "tablesdb.\(databaseId).tables.\(tableId).rows.\(rowId)" | ||
| if let action = action { | ||
| channel += ".\(action)" | ||
| } | ||
| return channel | ||
| } | ||
|
|
||
| /** | ||
| * Generate an account channel string. | ||
| * | ||
| * @param userId The user ID (default: "*") | ||
| * @returns The channel string | ||
| */ | ||
| public static func account(userId: String = "*") -> String { | ||
| return "account.\(userId)" | ||
| } | ||
|
|
||
| /** | ||
| * Generate a files channel string. | ||
| * | ||
| * @param bucketId The bucket ID (default: "*") | ||
| * @param fileId The file ID (default: "*") | ||
| * @param action Optional action: "create", "update", or "delete" (default: nil) | ||
| * @returns The channel string | ||
| */ | ||
| public static func files(bucketId: String = "*", fileId: String = "*", action: String? = nil) -> String { | ||
| var channel = "buckets.\(bucketId).files.\(fileId)" | ||
| if let action = action { | ||
| channel += ".\(action)" | ||
| } | ||
| return channel | ||
| } | ||
|
|
||
| /** | ||
| * Generate an executions channel string. | ||
| * | ||
| * @param functionId The function ID (default: "*") | ||
| * @param executionId The execution ID (default: "*") | ||
| * @param action Optional action: "create", "update", or "delete" (default: nil) | ||
| * @returns The channel string | ||
| */ | ||
| public static func executions(functionId: String = "*", executionId: String = "*", action: String? = nil) -> String { | ||
| var channel = "functions.\(functionId).executions.\(executionId)" | ||
| if let action = action { | ||
| channel += ".\(action)" | ||
| } | ||
| return channel | ||
| } | ||
|
|
||
| /** | ||
| * Generate a teams channel string. | ||
| * | ||
| * @param teamId The team ID (default: "*") | ||
| * @param action Optional action: "create", "update", or "delete" (default: nil) | ||
| * @returns The channel string | ||
| */ | ||
| public static func teams(teamId: String = "*", action: String? = nil) -> String { | ||
| var channel = "teams.\(teamId)" | ||
| if let action = action { | ||
| channel += ".\(action)" | ||
| } | ||
| return channel | ||
| } | ||
|
|
||
| /** | ||
| * Generate a memberships channel string. | ||
| * | ||
| * @param membershipId The membership ID (default: "*") | ||
| * @param action Optional action: "create", "update", or "delete" (default: nil) | ||
| * @returns The channel string | ||
| */ | ||
| public static func memberships(membershipId: String = "*", action: String? = nil) -> String { | ||
| var channel = "memberships.\(membershipId)" | ||
| if let action = action { | ||
| channel += ".\(action)" | ||
| } | ||
| return channel | ||
| } | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.