diff --git a/packages/contracts/lib/src/queue/clearable_queue.dart b/packages/contracts/lib/src/queue/clearable_queue.dart index e69de29..d6a6b12 100644 --- a/packages/contracts/lib/src/queue/clearable_queue.dart +++ b/packages/contracts/lib/src/queue/clearable_queue.dart @@ -0,0 +1,7 @@ +abstract class ClearableQueue { + /// Delete all of the jobs from the queue. + /// + /// @param String queue + /// @return int + int clear(String queue); +} diff --git a/packages/contracts/lib/src/queue/entity_not_found_exception.dart b/packages/contracts/lib/src/queue/entity_not_found_exception.dart index e69de29..025749e 100644 --- a/packages/contracts/lib/src/queue/entity_not_found_exception.dart +++ b/packages/contracts/lib/src/queue/entity_not_found_exception.dart @@ -0,0 +1,11 @@ +import 'dart:core'; + +class EntityNotFoundException implements Exception { + final String message; + + EntityNotFoundException(String type, dynamic id) + : message = "Queueable entity [$type] not found for ID [${id.toString()}]."; + + @override + String toString() => 'EntityNotFoundException: $message'; +} diff --git a/packages/contracts/lib/src/queue/entity_resolver.dart b/packages/contracts/lib/src/queue/entity_resolver.dart index e69de29..cf5c1aa 100644 --- a/packages/contracts/lib/src/queue/entity_resolver.dart +++ b/packages/contracts/lib/src/queue/entity_resolver.dart @@ -0,0 +1,8 @@ +abstract class EntityResolver { + /// Resolve the entity for the given ID. + /// + /// @param String type + /// @param dynamic id + /// @return dynamic + dynamic resolve(String type, dynamic id); +} diff --git a/packages/contracts/lib/src/queue/factory.dart b/packages/contracts/lib/src/queue/factory.dart index e69de29..0a7ef20 100644 --- a/packages/contracts/lib/src/queue/factory.dart +++ b/packages/contracts/lib/src/queue/factory.dart @@ -0,0 +1,12 @@ + +import 'queue.dart'; + +// TODO: Fix Imports + +abstract class Factory { + /// Resolve a queue connection instance. + /// + /// @param String? name + /// @return Queue + Queue connection([String? name]); +} diff --git a/packages/contracts/lib/src/queue/job.dart b/packages/contracts/lib/src/queue/job.dart index e69de29..d194db9 100644 --- a/packages/contracts/lib/src/queue/job.dart +++ b/packages/contracts/lib/src/queue/job.dart @@ -0,0 +1,67 @@ +abstract class Job { + /// Get the UUID of the job. + String? uuid(); + + /// Get the job identifier. + String getJobId(); + + /// Get the decoded body of the job. + Map payload(); + + /// Fire the job. + void fire(); + + /// Release the job back into the queue after [delay] seconds. + void release(int delay); + + /// Determine if the job was released back into the queue. + bool isReleased(); + + /// Delete the job from the queue. + void delete(); + + /// Determine if the job has been deleted. + bool isDeleted(); + + /// Determine if the job has been deleted or released. + bool isDeletedOrReleased(); + + /// Get the number of times the job has been attempted. + int attempts(); + + /// Determine if the job has been marked as a failure. + bool hasFailed(); + + /// Mark the job as "failed". + void markAsFailed(); + + /// Delete the job, call the "failed" method, and raise the failed job event. + void fail([Exception? e]); + + /// Get the number of times to attempt a job. + int? maxTries(); + + /// Get the maximum number of exceptions allowed, regardless of attempts. + int? maxExceptions(); + + /// Get the number of seconds the job can run. + int? timeout(); + + /// Get the timestamp indicating when the job should timeout. + int? retryUntil(); + + /// Get the name of the queued job class. + String getName(); + + /// Get the resolved name of the queued job class. + String resolveName(); + + /// Get the name of the connection the job belongs to. + String getConnectionName(); + + /// Get the name of the queue the job belongs to. + String getQueue(); + + /// Get the raw body string for the job. + String getRawBody(); +} diff --git a/packages/contracts/lib/src/queue/monitor.dart b/packages/contracts/lib/src/queue/monitor.dart index e69de29..15178a1 100644 --- a/packages/contracts/lib/src/queue/monitor.dart +++ b/packages/contracts/lib/src/queue/monitor.dart @@ -0,0 +1,19 @@ +abstract class Monitor { + /// Register a callback to be executed on every iteration through the queue loop. + /// + /// @param Function callback + /// @return void + void looping(Function callback); + + /// Register a callback to be executed when a job fails after the maximum number of retries. + /// + /// @param Function callback + /// @return void + void failing(Function callback); + + /// Register a callback to be executed when a daemon queue is stopping. + /// + /// @param Function callback + /// @return void + void stopping(Function callback); +} diff --git a/packages/contracts/lib/src/queue/queue.dart b/packages/contracts/lib/src/queue/queue.dart index e69de29..cae309b 100644 --- a/packages/contracts/lib/src/queue/queue.dart +++ b/packages/contracts/lib/src/queue/queue.dart @@ -0,0 +1,75 @@ +import "job.dart"; +abstract class Queue { + /// Get the size of the queue. + /// + /// @param String? queue + /// @return int + int size(String? queue); + + /// Push a new job onto the queue. + /// + /// @param String job + /// @param dynamic data + /// @param String? queue + /// @return dynamic + dynamic push(dynamic job, {dynamic data = '', String? queue}); + + /// Push a new job onto the queue. + /// + /// @param String queue + /// @param String job + /// @param dynamic data + /// @return dynamic + dynamic pushOn(String queue, dynamic job, {dynamic data = ''}); + + /// Push a raw payload onto the queue. + /// + /// @param String payload + /// @param String? queue + /// @param Map options + /// @return dynamic + dynamic pushRaw(String payload, {String? queue, Map options = const {}}); + + /// Push a new job onto the queue after (n) seconds. + /// + /// @param dynamic delay + /// @param dynamic job + /// @param dynamic data + /// @param String? queue + /// @return dynamic + dynamic later(dynamic delay, dynamic job, {dynamic data = '', String? queue}); + + /// Push a new job onto a specific queue after (n) seconds. + /// + /// @param String queue + /// @param dynamic delay + /// @param dynamic job + /// @param dynamic data + /// @return dynamic + dynamic laterOn(String queue, dynamic delay, dynamic job, {dynamic data = ''}); + + /// Push an array of jobs onto the queue. + /// + /// @param List jobs + /// @param dynamic data + /// @param String? queue + /// @return dynamic + dynamic bulk(List jobs, {dynamic data = '', String? queue}); + + /// Pop the next job off of the queue. + /// + /// @param String? queue + /// @return Job? + Job? pop(String? queue); + + /// Get the connection name for the queue. + /// + /// @return String + String getConnectionName(); + + /// Set the connection name for the queue. + /// + /// @param String name + /// @return this + Queue setConnectionName(String name); +} diff --git a/packages/contracts/lib/src/queue/queueable_collection.dart b/packages/contracts/lib/src/queue/queueable_collection.dart index e69de29..e17d882 100644 --- a/packages/contracts/lib/src/queue/queueable_collection.dart +++ b/packages/contracts/lib/src/queue/queueable_collection.dart @@ -0,0 +1,21 @@ +abstract class QueueableCollection { + /// Get the type of the entities being queued. + /// + /// @return String|null + String? getQueueableClass(); + + /// Get the identifiers for all of the entities. + /// + /// @return List + List getQueueableIds(); + + /// Get the relationships of the entities being queued. + /// + /// @return List + List getQueueableRelations(); + + /// Get the connection of the entities being queued. + /// + /// @return String|null + String? getQueueableConnection(); +} diff --git a/packages/contracts/lib/src/queue/queueable_entity.dart b/packages/contracts/lib/src/queue/queueable_entity.dart index e69de29..86e95f3 100644 --- a/packages/contracts/lib/src/queue/queueable_entity.dart +++ b/packages/contracts/lib/src/queue/queueable_entity.dart @@ -0,0 +1,16 @@ +abstract class QueueableEntity { + /// Get the queueable identity for the entity. + /// + /// @return dynamic + dynamic getQueueableId(); + + /// Get the relationships for the entity. + /// + /// @return List + List getQueueableRelations(); + + /// Get the connection of the entity. + /// + /// @return String? + String? getQueueableConnection(); +} diff --git a/packages/contracts/lib/src/queue/should_be_encrypted.dart b/packages/contracts/lib/src/queue/should_be_encrypted.dart index e69de29..a8c602d 100644 --- a/packages/contracts/lib/src/queue/should_be_encrypted.dart +++ b/packages/contracts/lib/src/queue/should_be_encrypted.dart @@ -0,0 +1,3 @@ +abstract class ShouldBeEncrypted { + // Add any necessary methods or properties here +} diff --git a/packages/contracts/lib/src/queue/should_be_unique.dart b/packages/contracts/lib/src/queue/should_be_unique.dart index e69de29..4a570c9 100644 --- a/packages/contracts/lib/src/queue/should_be_unique.dart +++ b/packages/contracts/lib/src/queue/should_be_unique.dart @@ -0,0 +1,3 @@ +abstract class ShouldBeUnique { + // This is an abstract class that serves as a marker interface. +} diff --git a/packages/contracts/lib/src/queue/should_be_unique_until_processing.dart b/packages/contracts/lib/src/queue/should_be_unique_until_processing.dart index e69de29..fcefd6e 100644 --- a/packages/contracts/lib/src/queue/should_be_unique_until_processing.dart +++ b/packages/contracts/lib/src/queue/should_be_unique_until_processing.dart @@ -0,0 +1,8 @@ +// File: illuminate/contracts/queue/should_be_unique_until_processing.dart + +import 'should_be_unique.dart'; + +abstract class ShouldBeUniqueUntilProcessing implements ShouldBeUnique { + // This interface can include any additional methods or properties if needed + // Currently, it's just extending ShouldBeUnique +} diff --git a/packages/contracts/lib/src/queue/should_queue.dart b/packages/contracts/lib/src/queue/should_queue.dart index e69de29..f283cef 100644 --- a/packages/contracts/lib/src/queue/should_queue.dart +++ b/packages/contracts/lib/src/queue/should_queue.dart @@ -0,0 +1,3 @@ +abstract class ShouldQueue { + // Interface with no methods defined +} diff --git a/packages/contracts/lib/src/queue/should_queue_after_commit.dart b/packages/contracts/lib/src/queue/should_queue_after_commit.dart index e69de29..dec46c1 100644 --- a/packages/contracts/lib/src/queue/should_queue_after_commit.dart +++ b/packages/contracts/lib/src/queue/should_queue_after_commit.dart @@ -0,0 +1,4 @@ +import 'should_queue.dart'; +abstract class ShouldQueueAfterCommit implements ShouldQueue { + // Additional functionalities can be added here if needed +} diff --git a/packages/contracts/lib/src/redis/connection.dart b/packages/contracts/lib/src/redis/connection.dart index e69de29..8adbf13 100644 --- a/packages/contracts/lib/src/redis/connection.dart +++ b/packages/contracts/lib/src/redis/connection.dart @@ -0,0 +1,24 @@ +import 'dart:async'; + +abstract class Connection { + /// Subscribe to a set of given channels for messages. + /// + /// @param List channels + /// @param void Function(dynamic) callback + /// @return void + void subscribe(List channels, void Function(dynamic) callback); + + /// Subscribe to a set of given channels with wildcards. + /// + /// @param List channels + /// @param void Function(dynamic) callback + /// @return void + void psubscribe(List channels, void Function(dynamic) callback); + + /// Run a command against the Redis database. + /// + /// @param String method + /// @param List parameters + /// @return Future + Future command(String method, [List parameters = const []]); +} diff --git a/packages/contracts/lib/src/redis/connector.dart b/packages/contracts/lib/src/redis/connector.dart index e69de29..bfba9da 100644 --- a/packages/contracts/lib/src/redis/connector.dart +++ b/packages/contracts/lib/src/redis/connector.dart @@ -0,0 +1,19 @@ + +import 'connection.dart'; + +abstract class Connector { + /// Create a connection to a Redis cluster. + /// + /// @param config + /// @param options + /// @return Connection + Connection connect(Map config, Map options); + + /// Create a connection to a Redis instance. + /// + /// @param config + /// @param clusterOptions + /// @param options + /// @return Connection + Connection connectToCluster(Map config, Map clusterOptions, Map options); +} diff --git a/packages/contracts/lib/src/redis/factory.dart b/packages/contracts/lib/src/redis/factory.dart index e69de29..ca9521c 100644 --- a/packages/contracts/lib/src/redis/factory.dart +++ b/packages/contracts/lib/src/redis/factory.dart @@ -0,0 +1,11 @@ +// file: lib/src/contracts/redis/factory.dart + +import 'connection.dart'; + +abstract class Factory { + /// Get a Redis connection by name. + /// + /// @param [String] name + /// @return [Connection] + Connection connection([String? name]); +} diff --git a/packages/contracts/lib/src/redis/limiter_timeout_exception.dart b/packages/contracts/lib/src/redis/limiter_timeout_exception.dart index e69de29..71ec3b3 100644 --- a/packages/contracts/lib/src/redis/limiter_timeout_exception.dart +++ b/packages/contracts/lib/src/redis/limiter_timeout_exception.dart @@ -0,0 +1,10 @@ +//import 'package:redis/redis.dart'; + +class LimiterTimeoutException implements Exception { + final String message; + + LimiterTimeoutException([this.message = '']); + + @override + String toString() => message.isEmpty ? 'LimiterTimeoutException' : 'LimiterTimeoutException: $message'; +} diff --git a/packages/contracts/lib/src/routing/binding_registrar.dart b/packages/contracts/lib/src/routing/binding_registrar.dart index e69de29..f7af5c1 100644 --- a/packages/contracts/lib/src/routing/binding_registrar.dart +++ b/packages/contracts/lib/src/routing/binding_registrar.dart @@ -0,0 +1,14 @@ +abstract class BindingRegistrar { + /// Add a new route parameter binder. + /// + /// @param String key + /// @param String or Function binder + /// @return void + void bind(String key, dynamic binder); + + /// Get the binding callback for a given binding. + /// + /// @param String key + /// @return Function + Function getBindingCallback(String key); +} diff --git a/packages/contracts/lib/src/routing/registrar.dart b/packages/contracts/lib/src/routing/registrar.dart index e69de29..1aeedac 100644 --- a/packages/contracts/lib/src/routing/registrar.dart +++ b/packages/contracts/lib/src/routing/registrar.dart @@ -0,0 +1,82 @@ +import 'route.dart'; + +// TODO: Fix Imports. + +abstract class Registrar { + /// Register a new GET route with the router. + /// + /// @param string $uri + /// @param array|string|callable $action + /// @return \Illuminate\Routing\Route + Route get(String uri, dynamic action); + + /// Register a new POST route with the router. + /// + /// @param string $uri + /// @param array|string|callable $action + /// @return \Illuminate\Routing\Route + Route post(String uri, dynamic action); + + /// Register a new PUT route with the router. + /// + /// @param string $uri + /// @param array|string|callable $action + /// @return \Illuminate\Routing\Route + Route put(String uri, dynamic action); + + /// Register a new DELETE route with the router. + /// + /// @param string $uri + /// @param array|string|callable $action + /// @return \Illuminate\Routing\Route + Route delete(String uri, dynamic action); + + /// Register a new PATCH route with the router. + /// + /// @param string $uri + /// @param array|string|callable $action + /// @return \Illuminate\Routing\Route + Route patch(String uri, dynamic action); + + /// Register a new OPTIONS route with the router. + /// + /// @param string $uri + /// @param array|string|callable $action + /// @return \Illuminate\Routing\Route + Route options(String uri, dynamic action); + + /// Register a new route with the given verbs. + /// + /// @param array|string $methods + /// @param string $uri + /// @param array|string|callable $action + /// @return \Illuminate\Routing\Route + Route match(dynamic methods, String uri, dynamic action); + + /// Route a resource to a controller. + /// + /// @param string $name + /// @param string $controller + /// @param array $options + /// @return \Illuminate\Routing\PendingResourceRegistration + PendingResourceRegistration resource(String name, String controller, [Map? options]); + + /// Create a route group with shared attributes. + /// + /// @param array $attributes + /// @param \Closure|string $routes + /// @return void + void group(Map attributes, dynamic routes); + + /// Substitute the route bindings onto the route. + /// + /// @param \Illuminate\Routing\Route $route + /// @return \Illuminate\Routing\Route + Route substituteBindings(Route route); + + /// Substitute the implicit Eloquent model bindings for the route. + /// + /// @param \Illuminate\Routing\Route $route + /// @return void + void substituteImplicitBindings(Route route); +} diff --git a/packages/contracts/lib/src/routing/response_factory.dart b/packages/contracts/lib/src/routing/response_factory.dart index e69de29..8d310c7 100644 --- a/packages/contracts/lib/src/routing/response_factory.dart +++ b/packages/contracts/lib/src/routing/response_factory.dart @@ -0,0 +1,124 @@ +import 'dart:io'; + +abstract class ResponseFactory { + /// Create a new response instance. + /// + /// [content] can be an array or a string. + /// [status] is the HTTP status code. + /// [headers] are the HTTP headers. + /// Returns a Response object. + HttpResponse make(dynamic content, {int status = 200, Map headers = const {}}); + + /// Create a new "no content" response. + /// + /// [status] is the HTTP status code. + /// [headers] are the HTTP headers. + /// Returns a Response object. + HttpResponse noContent({int status = 204, Map headers = const {}}); + + /// Create a new response for a given view. + /// + /// [view] can be a string or an array. + /// [data] is the data to be passed to the view. + /// [status] is the HTTP status code. + /// [headers] are the HTTP headers. + /// Returns a Response object. + HttpResponse view(dynamic view, {Map data = const {}, int status = 200, Map headers = const {}}); + + /// Create a new JSON response instance. + /// + /// [data] is the data to be returned as JSON. + /// [status] is the HTTP status code. + /// [headers] are the HTTP headers. + /// [options] are the JSON options. + /// Returns a JsonResponse object. + HttpResponse json(dynamic data, {int status = 200, Map headers = const {}, int options = 0}); + + /// Create a new JSONP response instance. + /// + /// [callback] is the JSONP callback name. + /// [data] is the data to be returned as JSONP. + /// [status] is the HTTP status code. + /// [headers] are the HTTP headers. + /// [options] are the JSON options. + /// Returns a JsonResponse object. + HttpResponse jsonp(String callback, dynamic data, {int status = 200, Map headers = const {}, int options = 0}); + + /// Create a new streamed response instance. + /// + /// [callback] is the callback function for streaming. + /// [status] is the HTTP status code. + /// [headers] are the HTTP headers. + /// Returns a StreamedResponse object. + HttpResponse stream(Function callback, {int status = 200, Map headers = const {}}); + + /// Create a new streamed response instance as a file download. + /// + /// [callback] is the callback function for streaming. + /// [name] is the name of the file. + /// [headers] are the HTTP headers. + /// [disposition] is the content disposition. + /// Returns a StreamedResponse object. + HttpResponse streamDownload(Function callback, {String? name, Map headers = const {}, String disposition = 'attachment'}); + + /// Create a new file download response. + /// + /// [file] is the file to be downloaded. + /// [name] is the name of the file. + /// [headers] are the HTTP headers. + /// [disposition] is the content disposition. + /// Returns a BinaryFileResponse object. + HttpResponse download(dynamic file, {String? name, Map headers = const {}, String disposition = 'attachment'}); + + /// Return the raw contents of a binary file. + /// + /// [file] is the file to be returned. + /// [headers] are the HTTP headers. + /// Returns a BinaryFileResponse object. + HttpResponse file(dynamic file, {Map headers = const {}}); + + /// Create a new redirect response to the given path. + /// + /// [path] is the path to redirect to. + /// [status] is the HTTP status code. + /// [headers] are the HTTP headers. + /// [secure] indicates if the redirection should be secure. + /// Returns a RedirectResponse object. + HttpResponse redirectTo(String path, {int status = 302, Map headers = const {}, bool? secure}); + + /// Create a new redirect response to a named route. + /// + /// [route] is the name of the route. + /// [parameters] are the parameters for the route. + /// [status] is the HTTP status code. + /// [headers] are the HTTP headers. + /// Returns a RedirectResponse object. + HttpResponse redirectToRoute(String route, {dynamic parameters = const {}, int status = 302, Map headers = const {}}); + + /// Create a new redirect response to a controller action. + /// + /// [action] is the action name. + /// [parameters] are the parameters for the action. + /// [status] is the HTTP status code. + /// [headers] are the HTTP headers. + /// Returns a RedirectResponse object. + HttpResponse redirectToAction(dynamic action, {dynamic parameters = const {}, int status = 302, Map headers = const {}}); + + /// Create a new redirect response, while putting the current URL in the session. + /// + /// [path] is the path to redirect to. + /// [status] is the HTTP status code. + /// [headers] are the HTTP headers. + /// [secure] indicates if the redirection should be secure. + /// Returns a RedirectResponse object. + HttpResponse redirectGuest(String path, {int status = 302, Map headers = const {}, bool? secure}); + + /// Create a new redirect response to the previously intended location. + /// + /// [defaultPath] is the default path if no intended location is found. + /// [status] is the HTTP status code. + /// [headers] are the HTTP headers. + /// [secure] indicates if the redirection should be secure. + /// Returns a RedirectResponse object. + HttpResponse redirectToIntended({String defaultPath = '/', int status = 302, Map headers = const {}, bool? secure}); +} diff --git a/packages/contracts/lib/src/routing/url_generator.dart b/packages/contracts/lib/src/routing/url_generator.dart index e69de29..a3fb6e7 100644 --- a/packages/contracts/lib/src/routing/url_generator.dart +++ b/packages/contracts/lib/src/routing/url_generator.dart @@ -0,0 +1,38 @@ +abstract class UrlGenerator { + /// Get the current URL for the request. + String current(); + + /// Get the URL for the previous request. + String previous([dynamic fallback = false]); + + /// Generate an absolute URL to the given path. + String to(String path, [dynamic extra = const [], bool? secure]); + + /// Generate a secure, absolute URL to the given path. + String secure(String path, [Map parameters = const {}]); + + /// Generate the URL to an application asset. + String asset(String path, [bool? secure]); + + /// Get the URL to a named route. + /// + /// Throws [ArgumentError] if an invalid argument is provided. + String route(String name, [dynamic parameters = const [], bool absolute = true]); + + /// Create a signed route URL for a named route. + /// + /// Throws [ArgumentError] if an invalid argument is provided. + String signedRoute(String name, [dynamic parameters = const [], dynamic expiration, bool absolute = true]); + + /// Create a temporary signed route URL for a named route. + String temporarySignedRoute(String name, dynamic expiration, [Map parameters = const {}, bool absolute = true]); + + /// Get the URL to a controller action. + String action(dynamic action, [dynamic parameters = const [], bool absolute = true]); + + /// Get the root controller namespace. + String getRootControllerNamespace(); + + /// Set the root controller namespace. + UrlGenerator setRootControllerNamespace(String rootNamespace); +} diff --git a/packages/contracts/lib/src/routing/url_routable.dart b/packages/contracts/lib/src/routing/url_routable.dart index e69de29..2084412 100644 --- a/packages/contracts/lib/src/routing/url_routable.dart +++ b/packages/contracts/lib/src/routing/url_routable.dart @@ -0,0 +1,31 @@ +abstract class UrlRoutable { + /// Get the value of the model's route key. + /// + /// @return dynamic + dynamic getRouteKey(); + + /// Get the route key for the model. + /// + /// @return String + String getRouteKeyName(); + + /// Retrieve the model for a bound value. + /// + /// @param dynamic value + /// @param String? field + /// @return Model? + Model? resolveRouteBinding(dynamic value, [String? field]); + + /// Retrieve the child model for a bound value. + /// + /// @param String childType + /// @param dynamic value + /// @param String? field + /// @return Model? + Model? resolveChildRouteBinding(String childType, dynamic value, [String? field]); +} + +// TODO: Fix Imports +class Model { + // This class is a placeholder for the actual Eloquent model implementation. +} diff --git a/packages/contracts/lib/src/session/middleware/authenticates_sessions.dart b/packages/contracts/lib/src/session/middleware/authenticates_sessions.dart index e69de29..63d01ff 100644 --- a/packages/contracts/lib/src/session/middleware/authenticates_sessions.dart +++ b/packages/contracts/lib/src/session/middleware/authenticates_sessions.dart @@ -0,0 +1,3 @@ +abstract class AuthenticatesSessions { + // Add any methods or properties that are needed here +} diff --git a/packages/contracts/lib/src/session/session.dart b/packages/contracts/lib/src/session/session.dart index e69de29..7fbdc8d 100644 --- a/packages/contracts/lib/src/session/session.dart +++ b/packages/contracts/lib/src/session/session.dart @@ -0,0 +1,88 @@ +abstract class Session { + /// Get the name of the session. + String getName(); + + /// Set the name of the session. + void setName(String name); + + /// Get the current session ID. + String getId(); + + /// Set the session ID. + void setId(String id); + + /// Start the session, reading the data from a handler. + bool start(); + + /// Save the session data to storage. + void save(); + + /// Get all of the session data. + Map all(); + + /// Checks if a key exists. + bool exists(dynamic key); + + /// Checks if a key is present and not null. + bool has(dynamic key); + + /// Get an item from the session. + dynamic get(String key, [dynamic defaultValue]); + + /// Get the value of a given key and then forget it. + dynamic pull(String key, [dynamic defaultValue]); + + /// Put a key / value pair or array of key / value pairs in the session. + void put(dynamic key, [dynamic value]); + + /// Get the CSRF token value. + String token(); + + /// Regenerate the CSRF token value. + void regenerateToken(); + + /// Remove an item from the session, returning its value. + dynamic remove(String key); + + /// Remove one or many items from the session. + void forget(dynamic keys); + + /// Remove all of the items from the session. + void flush(); + + /// Flush the session data and regenerate the ID. + bool invalidate(); + + /// Generate a new session identifier. + bool regenerate([bool destroy = false]); + + /// Generate a new session ID for the session. + bool migrate([bool destroy = false]); + + /// Determine if the session has been started. + bool isStarted(); + + /// Get the previous URL from the session. + String? previousUrl(); + + /// Set the "previous" URL in the session. + void setPreviousUrl(String url); + + /// Get the session handler instance. + SessionHandlerInterface getHandler(); + + /// Determine if the session handler needs a request. + bool handlerNeedsRequest(); + + /// Set the request on the handler instance. + void setRequestOnHandler(Request request); +} + +// TODO: Fix Imports +abstract class SessionHandlerInterface { + // Define the necessary methods for SessionHandlerInterface +} + +class Request { + // Define the necessary methods and properties for Request +} diff --git a/packages/contracts/lib/src/support/arrayable.dart b/packages/contracts/lib/src/support/arrayable.dart index e69de29..0996ee9 100644 --- a/packages/contracts/lib/src/support/arrayable.dart +++ b/packages/contracts/lib/src/support/arrayable.dart @@ -0,0 +1,6 @@ +abstract class Arrayable { + /// Get the instance as an array. + /// + /// @return Map + Map toArray(); +} diff --git a/packages/contracts/lib/src/support/can_be_escaped_when_cast_to_string.dart b/packages/contracts/lib/src/support/can_be_escaped_when_cast_to_string.dart index e69de29..8f7b9ee 100644 --- a/packages/contracts/lib/src/support/can_be_escaped_when_cast_to_string.dart +++ b/packages/contracts/lib/src/support/can_be_escaped_when_cast_to_string.dart @@ -0,0 +1,7 @@ +abstract class CanBeEscapedWhenCastToString { + /// Indicate that the object's string representation should be escaped when toString is invoked. + /// + /// @param bool escape + /// @return this + CanBeEscapedWhenCastToString escapeWhenCastingToString(bool escape); +} diff --git a/packages/contracts/lib/src/support/deferrable_provider.dart b/packages/contracts/lib/src/support/deferrable_provider.dart index e69de29..a95711e 100644 --- a/packages/contracts/lib/src/support/deferrable_provider.dart +++ b/packages/contracts/lib/src/support/deferrable_provider.dart @@ -0,0 +1,6 @@ +abstract class DeferrableProvider { + /// Get the services provided by the provider. + /// + /// @return List + List provides(); +} diff --git a/packages/contracts/lib/src/support/deferring_displayable_value.dart b/packages/contracts/lib/src/support/deferring_displayable_value.dart index e69de29..401a835 100644 --- a/packages/contracts/lib/src/support/deferring_displayable_value.dart +++ b/packages/contracts/lib/src/support/deferring_displayable_value.dart @@ -0,0 +1,8 @@ +//import 'package:your_package_name/htmlable.dart'; + +abstract class DeferringDisplayableValue { + /// Resolve the displayable value that the class is deferring. + /// + /// @return Htmlable or String + dynamic resolveDisplayableValue(); // Return type is dynamic to allow Htmlable or String +} diff --git a/packages/contracts/lib/src/support/htmlable.dart b/packages/contracts/lib/src/support/htmlable.dart index e69de29..5ba796b 100644 --- a/packages/contracts/lib/src/support/htmlable.dart +++ b/packages/contracts/lib/src/support/htmlable.dart @@ -0,0 +1,6 @@ +abstract class Htmlable { + /// Get content as a string of HTML. + /// + /// @return String + String toHtml(); +} diff --git a/packages/contracts/lib/src/support/jsonable.dart b/packages/contracts/lib/src/support/jsonable.dart index e69de29..04d64cc 100644 --- a/packages/contracts/lib/src/support/jsonable.dart +++ b/packages/contracts/lib/src/support/jsonable.dart @@ -0,0 +1,7 @@ +abstract class Jsonable { + /// Convert the object to its JSON representation. + /// + /// [options] Optional argument for JSON encoding options. + /// Returns the JSON representation of the object as a String. + String toJson({int options = 0}); +} diff --git a/packages/contracts/lib/src/support/message_bag.dart b/packages/contracts/lib/src/support/message_bag.dart index e69de29..3a8676e 100644 --- a/packages/contracts/lib/src/support/message_bag.dart +++ b/packages/contracts/lib/src/support/message_bag.dart @@ -0,0 +1,53 @@ +import 'arrayable.dart'; +import 'countable.dart'; + +// TODO: Fix Imports. + +abstract class MessageBag implements Arrayable, Countable { + /// Get the keys present in the message bag. + List keys(); + + /// Add a message to the bag. + /// + /// Returns this instance for chaining. + MessageBag add(String key, String message); + + /// Merge a new array of messages into the bag. + /// + /// Returns this instance for chaining. + MessageBag merge(dynamic messages); + + /// Determine if messages exist for a given key. + bool has(dynamic key); + + /// Get the first message from the bag for a given key. + String first([String? key, String? format]); + + /// Get all of the messages from the bag for a given key. + List get(String key, [String? format]); + + /// Get all of the messages for every key in the bag. + List all([String? format]); + + /// Remove a message from the bag. + /// + /// Returns this instance for chaining. + MessageBag forget(String key); + + /// Get the raw messages in the container. + List getMessages(); + + /// Get the default message format. + String getFormat(); + + /// Set the default message format. + /// + /// Returns this instance for chaining. + MessageBag setFormat([String format = ':message']); + + /// Determine if the message bag has any messages. + bool isEmpty(); + + /// Determine if the message bag has any messages. + bool isNotEmpty(); +} diff --git a/packages/contracts/lib/src/support/message_provider.dart b/packages/contracts/lib/src/support/message_provider.dart index e69de29..5ea9379 100644 --- a/packages/contracts/lib/src/support/message_provider.dart +++ b/packages/contracts/lib/src/support/message_provider.dart @@ -0,0 +1,8 @@ +import 'message_bag.dart'; + +abstract class MessageProvider { + /// Get the messages for the instance. + /// + /// @return MessageBag + MessageBag getMessageBag(); +} diff --git a/packages/contracts/lib/src/support/renderable.dart b/packages/contracts/lib/src/support/renderable.dart index e69de29..ed95264 100644 --- a/packages/contracts/lib/src/support/renderable.dart +++ b/packages/contracts/lib/src/support/renderable.dart @@ -0,0 +1,6 @@ +abstract class Renderable { + /// Get the evaluated contents of the object. + /// + /// Returns a string representation of the contents. + String render(); +} diff --git a/packages/contracts/lib/src/support/responsable.dart b/packages/contracts/lib/src/support/responsable.dart index e69de29..7fb5bf3 100644 --- a/packages/contracts/lib/src/support/responsable.dart +++ b/packages/contracts/lib/src/support/responsable.dart @@ -0,0 +1,11 @@ +import 'package:symfony_http_foundation/response.dart'; +import 'request.dart'; + +// TODO: Fix Imports. +abstract class Responsable { + /// Create an HTTP response that represents the object. + /// + /// @param Request request + /// @return Response + Response toResponse(Request request); +} diff --git a/packages/contracts/lib/src/support/validate_data.dart b/packages/contracts/lib/src/support/validate_data.dart index e69de29..1e62af3 100644 --- a/packages/contracts/lib/src/support/validate_data.dart +++ b/packages/contracts/lib/src/support/validate_data.dart @@ -0,0 +1,7 @@ +//import 'dart:collection'; +import 'arrayable.dart'; + +abstract class ValidatedData implements Arrayable, Map { + @override + Iterator> get iterator => entries.iterator; +} diff --git a/packages/contracts/lib/src/translation/has_local_preferences.dart b/packages/contracts/lib/src/translation/has_local_preferences.dart index e69de29..6a1b236 100644 --- a/packages/contracts/lib/src/translation/has_local_preferences.dart +++ b/packages/contracts/lib/src/translation/has_local_preferences.dart @@ -0,0 +1,6 @@ +abstract class HasLocalePreference { + /// Get the preferred locale of the entity. + /// + /// Returns a [String] representing the preferred locale or null if none is set. + String? preferredLocale(); +} diff --git a/packages/contracts/lib/src/translation/loader.dart b/packages/contracts/lib/src/translation/loader.dart index e69de29..b942d84 100644 --- a/packages/contracts/lib/src/translation/loader.dart +++ b/packages/contracts/lib/src/translation/loader.dart @@ -0,0 +1,25 @@ +abstract class Loader { + /// Load the messages for the given locale. + /// + /// [locale] is the locale to load messages for. + /// [group] is the message group to load. + /// [namespace] is the optional namespace to load messages from. + /// Returns a list of messages. + List load(String locale, String group, [String? namespace]); + + /// Add a new namespace to the loader. + /// + /// [namespace] is the name of the namespace. + /// [hint] is the path hint for the namespace. + void addNamespace(String namespace, String hint); + + /// Add a new JSON path to the loader. + /// + /// [path] is the path to the JSON file. + void addJsonPath(String path); + + /// Get an array of all the registered namespaces. + /// + /// Returns a map of all registered namespaces and their hints. + Map namespaces(); +} diff --git a/packages/contracts/lib/src/translation/translator.dart b/packages/contracts/lib/src/translation/translator.dart index e69de29..db0869b 100644 --- a/packages/contracts/lib/src/translation/translator.dart +++ b/packages/contracts/lib/src/translation/translator.dart @@ -0,0 +1,29 @@ +abstract class Translator { + /// Get the translation for a given key. + /// + /// @param String key + /// @param Map replace + /// @param String? locale + /// @return dynamic + dynamic get(String key, {Map replace = const {}, String? locale}); + + /// Get a translation according to an integer value. + /// + /// @param String key + /// @param dynamic number (Countable, int, double, or List) + /// @param Map replace + /// @param String? locale + /// @return String + String choice(String key, dynamic number, {Map replace = const {}, String? locale}); + + /// Get the default locale being used. + /// + /// @return String + String getLocale(); + + /// Set the default locale. + /// + /// @param String locale + /// @return void + void setLocale(String locale); +} diff --git a/packages/contracts/lib/src/validation/data_aware_rule.dart b/packages/contracts/lib/src/validation/data_aware_rule.dart index e69de29..db29bb1 100644 --- a/packages/contracts/lib/src/validation/data_aware_rule.dart +++ b/packages/contracts/lib/src/validation/data_aware_rule.dart @@ -0,0 +1,7 @@ +abstract class DataAwareRule { + /// Sets the data under validation. + /// + /// @param Map data - The data to be validated. + /// @return DataAwareRule - The instance of the implementing class. + DataAwareRule setData(Map data); +} diff --git a/packages/contracts/lib/src/validation/factory.dart b/packages/contracts/lib/src/validation/factory.dart index e69de29..1ede50a 100644 --- a/packages/contracts/lib/src/validation/factory.dart +++ b/packages/contracts/lib/src/validation/factory.dart @@ -0,0 +1,38 @@ +import 'validator.dart'; +abstract class Factory { + /// Create a new Validator instance. + /// + /// @param Map data + /// @param Map rules + /// @param Map messages + /// @param Map attributes + /// @return Validator + Validator make( + Map data, + Map rules, + [Map messages = const {}, + Map attributes = const {}]); + + /// Register a custom validator extension. + /// + /// @param String rule + /// @param Function|string extension + /// @param String|null message + /// @return void + void extend(String rule, dynamic extension, [String? message]); + + /// Register a custom implicit validator extension. + /// + /// @param String rule + /// @param Function|string extension + /// @param String|null message + /// @return void + void extendImplicit(String rule, dynamic extension, [String? message]); + + /// Register a custom implicit validator message replacer. + /// + /// @param String rule + /// @param Function|string replacer + /// @return void + void replacer(String rule, dynamic replacer); +} diff --git a/packages/contracts/lib/src/validation/implicit_rule.dart b/packages/contracts/lib/src/validation/implicit_rule.dart index e69de29..38cbc1b 100644 --- a/packages/contracts/lib/src/validation/implicit_rule.dart +++ b/packages/contracts/lib/src/validation/implicit_rule.dart @@ -0,0 +1,7 @@ +// Import the necessary file where the Rule interface is defined +import 'rule.dart'; + +/// @deprecated see ValidationRule +abstract class ImplicitRule implements Rule { + // Empty abstract class to follow the structure of the original interface +} diff --git a/packages/contracts/lib/src/validation/invokable_rule.dart b/packages/contracts/lib/src/validation/invokable_rule.dart index e69de29..6935fc1 100644 --- a/packages/contracts/lib/src/validation/invokable_rule.dart +++ b/packages/contracts/lib/src/validation/invokable_rule.dart @@ -0,0 +1,16 @@ +// Import necessary libraries +import 'dart:core'; + +// Define a type alias for the fail function closure +typedef FailFunction = void Function(String); + +// Define the InvokableRule interface +///@deprecated see ValidateRule +abstract class InvokableRule { + /// Run the validation rule. + /// + /// @param attribute The attribute being validated. + /// @param value The value of the attribute. + /// @param fail A function that will be called if the validation fails. + void call(String attribute, dynamic value, FailFunction fail); +} diff --git a/packages/contracts/lib/src/validation/rule.dart b/packages/contracts/lib/src/validation/rule.dart index e69de29..d3fbcff 100644 --- a/packages/contracts/lib/src/validation/rule.dart +++ b/packages/contracts/lib/src/validation/rule.dart @@ -0,0 +1,14 @@ +/// @deprecated see ValidationRule +abstract class Rule { + /// Determine if the validation rule passes. + /// + /// @param attribute The name of the attribute. + /// @param value The value of the attribute. + /// @return True if the validation rule passes, false otherwise. + bool passes(String attribute, dynamic value); + + /// Get the validation error message. + /// + /// @return The validation error message as a string or list of strings. + dynamic message(); +} diff --git a/packages/contracts/lib/src/validation/uncompromised_verifier.dart b/packages/contracts/lib/src/validation/uncompromised_verifier.dart index e69de29..826fb78 100644 --- a/packages/contracts/lib/src/validation/uncompromised_verifier.dart +++ b/packages/contracts/lib/src/validation/uncompromised_verifier.dart @@ -0,0 +1,9 @@ +import 'package:meta/meta.dart'; + +abstract class UncompromisedVerifier { + /// Verify that the given data has not been compromised in data leaks. + /// + /// @param List data + /// @return bool + bool verify(List data); +} diff --git a/packages/contracts/lib/src/validation/validates_when_resolved.dart b/packages/contracts/lib/src/validation/validates_when_resolved.dart index e69de29..624e90c 100644 --- a/packages/contracts/lib/src/validation/validates_when_resolved.dart +++ b/packages/contracts/lib/src/validation/validates_when_resolved.dart @@ -0,0 +1,6 @@ +abstract class ValidatesWhenResolved { + /// Validate the given class instance. + /// + /// This method should be overridden to implement the validation logic. + void validateResolved(); +} diff --git a/packages/contracts/lib/src/validation/validation_rule.dart b/packages/contracts/lib/src/validation/validation_rule.dart index e69de29..5c3e923 100644 --- a/packages/contracts/lib/src/validation/validation_rule.dart +++ b/packages/contracts/lib/src/validation/validation_rule.dart @@ -0,0 +1,12 @@ +import 'package:meta/meta.dart'; + +typedef FailCallback = void Function(String message); + +abstract class ValidationRule { + /// Run the validation rule. + /// + /// @param attribute The name of the attribute being validated. + /// @param value The value of the attribute. + /// @param fail A callback function that accepts a failure message. + void validate(String attribute, dynamic value, FailCallback fail); +} diff --git a/packages/contracts/lib/src/validation/validator.dart b/packages/contracts/lib/src/validation/validator.dart index e69de29..e373783 100644 --- a/packages/contracts/lib/src/validation/validator.dart +++ b/packages/contracts/lib/src/validation/validator.dart @@ -0,0 +1,50 @@ +import 'message_provider.dart'; +import 'validation_exception.dart'; +import 'message_bag.dart'; + +// TODO: Fix Imports. + +abstract class Validator implements MessageProvider { + /// Run the validator's rules against its data. + /// + /// Throws a [ValidationException] if validation fails. + /// + /// Returns a map of validated data. + Map validate(); + + /// Get the attributes and values that were validated. + /// + /// Throws a [ValidationException] if validation fails. + /// + /// Returns a map of validated data. + Map validated(); + + /// Determine if the data fails the validation rules. + /// + /// Returns true if validation fails, false otherwise. + bool fails(); + + /// Get the failed validation rules. + /// + /// Returns a map of failed validation rules. + Map failed(); + + /// Add conditions to a given field based on a callback. + /// + /// Takes an [attribute], [rules], and a [callback] function. + /// + /// Returns the current instance of [Validator]. + Validator sometimes(dynamic attribute, dynamic rules, Function callback); + + /// Add an after validation callback. + /// + /// Takes a [callback] function. + /// + /// Returns the current instance of [Validator]. + Validator after(Function callback); + + /// Get all of the validation error messages. + /// + /// Returns a [MessageBag] containing the error messages. + MessageBag errors(); +} diff --git a/packages/contracts/lib/src/validation/validator_aware_rule.dart b/packages/contracts/lib/src/validation/validator_aware_rule.dart index e69de29..c30aab9 100644 --- a/packages/contracts/lib/src/validation/validator_aware_rule.dart +++ b/packages/contracts/lib/src/validation/validator_aware_rule.dart @@ -0,0 +1,9 @@ +import 'validator.dart'; // Assume this is the correct import for the Validator class + +abstract class ValidatorAwareRule { + /// Set the current validator. + /// + /// @param Validator validator + /// @return ValidatorAwareRule + ValidatorAwareRule setValidator(Validator validator); +} diff --git a/packages/contracts/lib/src/view/engine.dart b/packages/contracts/lib/src/view/engine.dart index e69de29..f701dad 100644 --- a/packages/contracts/lib/src/view/engine.dart +++ b/packages/contracts/lib/src/view/engine.dart @@ -0,0 +1,8 @@ +abstract class Engine { + /// Get the evaluated contents of the view. + /// + /// @param String path + /// @param Map data + /// @return String + String get(String path, {Map data = const {}}); +} diff --git a/packages/contracts/lib/src/view/factory.dart b/packages/contracts/lib/src/view/factory.dart index e69de29..aa1e558 100644 --- a/packages/contracts/lib/src/view/factory.dart +++ b/packages/contracts/lib/src/view/factory.dart @@ -0,0 +1,60 @@ +import 'view.dart'; + +abstract class Factory { + /// Determine if a given view exists. + /// + /// @param String view + /// @return bool + bool exists(String view); + + /// Get the evaluated view contents for the given path. + /// + /// @param String path + /// @param Map data + /// @param Map mergeData + /// @return View + View file(String path, {Map? data, Map? mergeData}); + + /// Get the evaluated view contents for the given view. + /// + /// @param String view + /// @param Map data + /// @param Map mergeData + /// @return View + View make(String view, {Map? data, Map? mergeData}); + + /// Add a piece of shared data to the environment. + /// + /// @param dynamic key + /// @param dynamic value + /// @return dynamic + dynamic share(dynamic key, {dynamic value}); + + /// Register a view composer event. + /// + /// @param dynamic views + /// @param dynamic callback + /// @return List + List composer(dynamic views, dynamic callback); + + /// Register a view creator event. + /// + /// @param dynamic views + /// @param dynamic callback + /// @return List + List creator(dynamic views, dynamic callback); + + /// Add a new namespace to the loader. + /// + /// @param String namespace + /// @param dynamic hints + /// @return Factory + Factory addNamespace(String namespace, dynamic hints); + + /// Replace the namespace hints for the given namespace. + /// + /// @param String namespace + /// @param dynamic hints + /// @return Factory + Factory replaceNamespace(String namespace, dynamic hints); +} diff --git a/packages/contracts/lib/src/view/view.dart b/packages/contracts/lib/src/view/view.dart index e69de29..d4a3cec 100644 --- a/packages/contracts/lib/src/view/view.dart +++ b/packages/contracts/lib/src/view/view.dart @@ -0,0 +1,17 @@ + +import "package:fabric_contracts/support.dart"; + +abstract class View extends Renderable { + /// Get the name of the view. + String name(); + + /// Add a piece of data to the view. + /// + /// @param String|Map key + /// @param dynamic value + /// @return View + View with(dynamic key, [dynamic value]); + + /// Get the array of view data. + Map getData(); +} diff --git a/packages/contracts/lib/src/view/view_compilation_exception.dart b/packages/contracts/lib/src/view/view_compilation_exception.dart index e69de29..9257301 100644 --- a/packages/contracts/lib/src/view/view_compilation_exception.dart +++ b/packages/contracts/lib/src/view/view_compilation_exception.dart @@ -0,0 +1,12 @@ +import 'package:meta/meta.dart'; + +class ViewCompilationException implements Exception { + final String? message; + + ViewCompilationException([this.message]); + + @override + String toString() { + return message ?? 'ViewCompilationException'; + } +}