add: adding contracts to project

This commit is contained in:
Patrick Stewart 2024-06-14 20:34:20 -07:00
parent c79a572a06
commit c900303ee8
19 changed files with 64 additions and 29 deletions

View file

View file

@ -1,6 +0,0 @@
import 'package:fabric_contracts/fabric_contracts.dart';
void main() {
var awesome = Awesome();
print('awesome: ${awesome.isAwesome}');
}

View file

@ -3,6 +3,6 @@
/// More dartdocs go here.
library;
export 'src/fabric_contracts_base.dart';
// export 'src/fabric_contracts_base.dart';
// TODO: Export any libraries intended for clients of this package.

View file

@ -0,0 +1,9 @@
abstract class Authorizable {
/// Determine if the entity has a given ability.
///
/// [abilities] can be an Iterable or a String.
/// [arguments] can be a List or a dynamic type.
///
/// Returns a boolean indicating if the entity has the given ability.
bool can(dynamic abilities, [List<dynamic> arguments = const []]);
}

View file

@ -0,0 +1,51 @@
// import 'package:meta/meta.dart';
abstract class Gate {
/// Determine if a given ability has been defined.
bool has(String ability);
/// Define a new ability.
Gate define(String ability, dynamic callback);
/// Define abilities for a resource.
Gate resource(String name, String className, [List<String>? abilities]);
/// Define a policy class for a given class type.
Gate policy(String className, String policy);
/// Register a callback to run before all Gate checks.
Gate before(Function callback);
/// Register a callback to run after all Gate checks.
Gate after(Function callback);
/// Determine if all of the given abilities should be granted for the current user.
bool allows(dynamic ability, [dynamic arguments]);
/// Determine if any of the given abilities should be denied for the current user.
bool denies(dynamic ability, [dynamic arguments]);
/// Determine if all of the given abilities should be granted for the current user.
bool check(dynamic abilities, [dynamic arguments]);
/// Determine if any one of the given abilities should be granted for the current user.
bool any(dynamic abilities, [dynamic arguments]);
/// Determine if the given ability should be granted for the current user.
dynamic authorize(String ability, [dynamic arguments]);
/// Inspect the user for the given ability.
dynamic inspect(String ability, [dynamic arguments]);
/// Get the raw result from the authorization callback.
dynamic raw(String ability, [dynamic arguments]);
/// Get a policy instance for a given class.
dynamic getPolicyFor(dynamic className);
/// Get a guard instance for the given user.
Gate forUser(dynamic user);
/// Get all of the defined abilities.
List<String> abilities();
}

View file

@ -0,0 +1,3 @@
abstract class AuthenticatesRequests {
// Define abstract methods or properties if needed
}

View file

@ -1,6 +0,0 @@
// TODO: Put public facing types in this file.
/// Checks if you are awesome. Spoiler: you are.
class Awesome {
bool get isAwesome => true;
}

View file

View file

@ -1,16 +0,0 @@
import 'package:fabric_contracts/fabric_contracts.dart';
import 'package:test/test.dart';
void main() {
group('A group of tests', () {
final awesome = Awesome();
setUp(() {
// Additional setup goes here.
});
test('First Test', () {
expect(awesome.isAwesome, isTrue);
});
});
}