-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
83 additions
and
11 deletions.
There are no files selected for viewing
This file contains 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 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 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,30 @@ | ||
import 'package:celest/celest.dart'; | ||
|
||
/// The context of a [CloudFunction] invocation. | ||
abstract final class Context { | ||
const Context._(); | ||
|
||
/// A context reference to the [User] invoking a [CloudFunction]. | ||
/// | ||
/// ## Example | ||
/// | ||
/// To inject a user into an `@authenticated` function: | ||
/// | ||
/// ```dart | ||
/// @authenticated | ||
/// Future<void> sayHello({ | ||
/// @Context.user() required User user, | ||
/// }) async { | ||
/// print('Hello, ${user.displayName}!'); | ||
/// } | ||
/// ``` | ||
const factory Context.user() = _ContextKey.user; | ||
} | ||
|
||
final class _ContextKey extends Context { | ||
const _ContextKey._(this.key) : super._(); | ||
|
||
const _ContextKey.user() : this._('user'); | ||
|
||
final String key; | ||
} |
This file contains 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 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,40 @@ | ||
import 'package:celest/src/core/entity.dart'; | ||
|
||
/// A grant which provides access to all authenticated users. | ||
/// | ||
/// ## Example | ||
/// | ||
/// ```dart | ||
/// import 'package:celest/celest.dart'; | ||
/// | ||
/// @authenticated | ||
/// Future<void> sayHello() async { | ||
/// print('User is authenticated!'); | ||
/// } | ||
/// ``` | ||
const authenticated = _Authenticated(); | ||
|
||
final class _Role implements Entity { | ||
const _Role({ | ||
required this.name, | ||
}); | ||
|
||
static const _Role authenticated = _Role(name: r'$authenticated'); | ||
|
||
final String name; | ||
} | ||
|
||
/// An assignment which grants a set of permissions to a specific group of | ||
/// [Entity]s. | ||
final class _Grant { | ||
const _Grant({ | ||
required this.to, | ||
}); | ||
|
||
/// The group of [Entity] which are granted access. | ||
final List<Entity> to; | ||
} | ||
|
||
final class _Authenticated extends _Grant { | ||
const _Authenticated() : super(to: const [_Role.authenticated]); | ||
} |