-
Notifications
You must be signed in to change notification settings - Fork 127
feat(data): Events API Contract shells #3012
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
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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
File renamed without changes.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| POM_ARTIFACT_ID=aws-appsync-amplify | ||
| POM_NAME=Amplify Extensions for AWS AppSync | ||
| POM_DESCRIPTION=Amplify Extensions for AWS AppSync | ||
| POM_PACKAGING=aar |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
97 changes: 97 additions & 0 deletions
97
appsync/aws-appsync-events/src/main/java/com/amplifyframework/aws/appsync/events/Events.kt
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,97 @@ | ||
| /* | ||
| * Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"). | ||
| * You may not use this file except in compliance with the License. | ||
| * A copy of the License is located at | ||
| * | ||
| * http://aws.amazon.com/apache2.0 | ||
| * | ||
| * or in the "license" file accompanying this file. This file is distributed | ||
| * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
| * express or implied. See the License for the specific language governing | ||
| * permissions and limitations under the License. | ||
| */ | ||
| package com.amplifyframework.aws.appsync.events | ||
|
|
||
| import com.amplifyframework.aws.appsync.core.AppSyncAuthorizer | ||
| import com.amplifyframework.aws.appsync.events.data.ChannelAuthorizers | ||
| import com.amplifyframework.aws.appsync.events.data.EventsException | ||
| import com.amplifyframework.aws.appsync.events.data.PublishResult | ||
| import kotlinx.serialization.json.JsonElement | ||
|
|
||
| /** | ||
| * Publish a single event to a channel. | ||
| * | ||
| * @property endpoint AWS AppSync Events endpoint. | ||
| * @param connectAuthorizer for AWS AppSync Websocket Pub/Sub connection. | ||
| * @param defaultChannelAuthorizers passed to created channels if not overridden. | ||
| */ | ||
| class Events( | ||
| val endpoint: String, | ||
| val connectAuthorizer: AppSyncAuthorizer, | ||
| val defaultChannelAuthorizers: ChannelAuthorizers | ||
| ) { | ||
|
|
||
| /** | ||
| * Publish a single event to a channel. | ||
| * | ||
| * @param channelName of the channel to publish to. | ||
| * @param event formatted in json. | ||
| * @param authorizer for the publish call. If not provided, the EventChannel publish authorizer will be used. | ||
| * @return result of publish. | ||
| */ | ||
| @Throws(EventsException::class) | ||
| suspend fun publish( | ||
| channelName: String, | ||
| event: JsonElement, | ||
| authorizer: AppSyncAuthorizer = this.defaultChannelAuthorizers.publishAuthorizer | ||
| ): PublishResult { | ||
| TODO("Need to implement") | ||
| } | ||
|
|
||
| /** | ||
| * Publish a multiple events (up to 5) to a channel. | ||
| * | ||
| * @param channelName of the channel to publish to. | ||
| * @param events list of formatted json events. | ||
| * @param authorizer for the publish call. If not provided, the EventChannel publish authorizer will be used. | ||
| * @return result of publish. | ||
| */ | ||
| @Throws(EventsException::class) | ||
| suspend fun publish( | ||
| channelName: String, | ||
| events: List<JsonElement>, | ||
| authorizer: AppSyncAuthorizer = this.defaultChannelAuthorizers.publishAuthorizer | ||
| ): PublishResult { | ||
| TODO("Need to implement") | ||
| } | ||
|
|
||
| /** | ||
| * Create a channel. | ||
| * | ||
| * @param channelName of the channel to use. | ||
| * @param authorizers for the channel to use for subscriptions and publishes. | ||
| * @return a channel to manage subscriptions and publishes. | ||
| */ | ||
| @Throws(EventsException::class) | ||
| fun channel( | ||
| channelName: String, | ||
| authorizers: ChannelAuthorizers = this.defaultChannelAuthorizers, | ||
| ): EventsChannel { | ||
| TODO("Need to implement") | ||
| } | ||
|
|
||
| /** | ||
| * Method to disconnect from all channels. | ||
| * | ||
| * @param flushEvents set to true (default) to allow all pending publish calls to succeed before disconnecting. | ||
| * Setting to false will immediately disconnect, cancelling any in-progress or queued event publishes. | ||
| * @param authorizers for the channel to use for subscriptions and publishes. | ||
| * @return a channel to manage subscriptions and publishes. | ||
| */ | ||
| @Throws(EventsException::class) | ||
| suspend fun disconnect(flushEvents: Boolean = true) { | ||
| TODO("Need to implement") | ||
| } | ||
| } | ||
78 changes: 78 additions & 0 deletions
78
...aws-appsync-events/src/main/java/com/amplifyframework/aws/appsync/events/EventsChannel.kt
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,78 @@ | ||
| /* | ||
| * Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"). | ||
| * You may not use this file except in compliance with the License. | ||
| * A copy of the License is located at | ||
| * | ||
| * http://aws.amazon.com/apache2.0 | ||
| * | ||
| * or in the "license" file accompanying this file. This file is distributed | ||
| * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
| * express or implied. See the License for the specific language governing | ||
| * permissions and limitations under the License. | ||
| */ | ||
| package com.amplifyframework.aws.appsync.events | ||
|
|
||
| import com.amplifyframework.aws.appsync.core.AppSyncAuthorizer | ||
| import com.amplifyframework.aws.appsync.events.data.ChannelAuthorizers | ||
| import com.amplifyframework.aws.appsync.events.data.EventsException | ||
| import com.amplifyframework.aws.appsync.events.data.EventsMessage | ||
| import com.amplifyframework.aws.appsync.events.data.PublishResult | ||
| import kotlinx.coroutines.flow.Flow | ||
| import kotlinx.serialization.json.JsonElement | ||
|
|
||
| /** | ||
| * A class to manage channel subscriptions and publishes | ||
| * | ||
| * @property name of the channel | ||
| * @property authorizers used for channel subscriptions and publishes | ||
| */ | ||
| class EventsChannel internal constructor( | ||
| val name: String, | ||
| val authorizers: ChannelAuthorizers | ||
| ) { | ||
|
|
||
| /** | ||
| * Subscribe to a channel. | ||
| * | ||
| * @param authorizer for the subscribe call. If not provided, the EventChannel subscribe authorizer will be used. | ||
| * @return flow of event messages. Collect flow to receive messages. | ||
| */ | ||
| @Throws(EventsException::class) | ||
| fun subscribe( | ||
| authorizer: AppSyncAuthorizer = this.authorizers.subscribeAuthorizer | ||
| ): Flow<EventsMessage> { | ||
| TODO("Need to implement") | ||
| } | ||
|
|
||
| /** | ||
| * Publish a single event to a channel. | ||
| * | ||
| * @param event formatted in json. | ||
| * @param authorizer for the publish call. If not provided, the EventChannel publish authorizer will be used. | ||
| * @return result of publish. | ||
| */ | ||
| @Throws(EventsException::class) | ||
| suspend fun publish( | ||
| event: JsonElement, | ||
| authorizer: AppSyncAuthorizer = this.authorizers.publishAuthorizer | ||
| ): PublishResult { | ||
| TODO("Need to implement") | ||
| } | ||
|
|
||
| /** | ||
| * Publish a multiple events (up to 5) to a channel. | ||
| * | ||
| * @param events list of formatted json events. | ||
| * @param authorizer for the publish call. If not provided, the EventChannel publish authorizer will be used. | ||
| * @return result of publish. | ||
| */ | ||
| @Throws(EventsException::class) | ||
| suspend fun publish( | ||
| events: List<JsonElement>, | ||
| authorizer: AppSyncAuthorizer = this.authorizers.publishAuthorizer | ||
| ): PublishResult { | ||
| TODO("Need to implement") | ||
| } | ||
| } |
29 changes: 29 additions & 0 deletions
29
...c-events/src/main/java/com/amplifyframework/aws/appsync/events/data/ChannelAuthorizers.kt
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,29 @@ | ||
| /* | ||
| * Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"). | ||
| * You may not use this file except in compliance with the License. | ||
| * A copy of the License is located at | ||
| * | ||
| * http://aws.amazon.com/apache2.0 | ||
| * | ||
| * or in the "license" file accompanying this file. This file is distributed | ||
| * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
| * express or implied. See the License for the specific language governing | ||
| * permissions and limitations under the License. | ||
| */ | ||
| package com.amplifyframework.aws.appsync.events.data | ||
|
|
||
| import com.amplifyframework.aws.appsync.core.AppSyncAuthorizer | ||
|
|
||
| /** | ||
| * Authorizers passed to a channel to manage subscriptions and publishes. | ||
| * | ||
| * @property subscribeAuthorizer used for subscription requests. | ||
| * @property publishAuthorizer used for publish requests. | ||
| * @constructor Pass subscribe and publisher authorizer types. | ||
| */ | ||
| data class ChannelAuthorizers( | ||
| val subscribeAuthorizer: AppSyncAuthorizer, | ||
| val publishAuthorizer: AppSyncAuthorizer | ||
| ) |
94 changes: 94 additions & 0 deletions
94
...sync-events/src/main/java/com/amplifyframework/aws/appsync/events/data/EventsException.kt
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,94 @@ | ||
| /* | ||
| * Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"). | ||
| * You may not use this file except in compliance with the License. | ||
| * A copy of the License is located at | ||
| * | ||
| * http://aws.amazon.com/apache2.0 | ||
| * | ||
| * or in the "license" file accompanying this file. This file is distributed | ||
| * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
| * express or implied. See the License for the specific language governing | ||
| * permissions and limitations under the License. | ||
| */ | ||
| package com.amplifyframework.aws.appsync.events.data | ||
|
|
||
| /** | ||
| * Base class for exceptions thrown in Events library | ||
| * | ||
| * @param message of the exception. | ||
| * @param cause of the exception. | ||
| * @param recoverySuggestion recommendation to resolve exception. | ||
| */ | ||
| open class EventsException internal constructor( | ||
| message: String, | ||
| cause: Throwable? = null, | ||
| val recoverySuggestion: String? = null | ||
| ) : Exception(message, cause) | ||
|
|
||
| /** | ||
| * Thrown when failing to connect to Events WebSocket. | ||
| */ | ||
| class ConnectException internal constructor(cause: Throwable?) : EventsException( | ||
| message = "Failed to connect to the Events Api", | ||
| cause = cause, | ||
| recoverySuggestion = "See the underlying exception for cause" | ||
| ) | ||
|
|
||
| /** | ||
| * Thrown when call is unauthorized. | ||
| */ | ||
| class UnauthorizedException internal constructor() : EventsException( | ||
| message = "Unauthorized", | ||
| recoverySuggestion = "Check your authorizer and Event configuration values and try again" | ||
| ) | ||
|
|
||
| /** | ||
| * Thrown when connection is unexpectedly closed. | ||
| */ | ||
| class ConnectionClosedException internal constructor(cause: Throwable? = null) : EventsException( | ||
| message = "The websocket connection was closed", | ||
| cause = cause, | ||
| recoverySuggestion = "Check your internet connection and try again" | ||
| ) | ||
|
|
||
| /** | ||
| * Thrown when rate limit is exceeded. | ||
| */ | ||
| internal class RateLimitExceededException internal constructor() : EventsException( | ||
| message = "Rate limit exceeded", | ||
| recoverySuggestion = "Try again later" | ||
| ) | ||
|
|
||
| /** | ||
| * Thrown when operation is unsupported. | ||
| */ | ||
| internal class UnsupportedOperationException internal constructor() : EventsException( | ||
| message = "WebSocket did not understand the operation", | ||
| recoverySuggestion = "This is not expected to occur. Contact AWS" | ||
| ) | ||
|
|
||
| /** | ||
| * Thrown when resource is not found. | ||
| */ | ||
| internal class ResourceNotFoundException internal constructor() : EventsException( | ||
| message = "Resource not found", | ||
| recoverySuggestion = "Check Event configuration values and try again" | ||
| ) | ||
|
|
||
| /** | ||
| * Thrown when hitting max subscription limit. | ||
| */ | ||
| class MaxSubscriptionsReachedException internal constructor(throwable: Throwable) : EventsException( | ||
| message = "Max number of subscriptions reached", | ||
| recoverySuggestion = "Unsubscribe from existing channels before attempting to subscribe." | ||
| ) | ||
|
|
||
| /** | ||
| * Thrown when attempting to send too many events or invalid request. | ||
| */ | ||
| class BadRequestException internal constructor() : EventsException( | ||
| message = "Input exceeded 5 event limit", | ||
| recoverySuggestion = "Submit 5 events or less." | ||
| ) |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't look like the proper documentation for this class
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, copy/paste error. pushed a fix.