diff --git a/packages/contracts/lib/src/mail/attachable.dart b/packages/contracts/lib/src/mail/attachable.dart index e69de29..62143dd 100644 --- a/packages/contracts/lib/src/mail/attachable.dart +++ b/packages/contracts/lib/src/mail/attachable.dart @@ -0,0 +1,10 @@ +import 'package:your_project/attachment.dart'; + +// TODO: Check imports + +abstract class Attachable { + /// Get an attachment instance for this entity. + /// + /// @return Attachment + Attachment toMailAttachment(); +} diff --git a/packages/contracts/lib/src/mail/factory.dart b/packages/contracts/lib/src/mail/factory.dart index e69de29..2b07a1f 100644 --- a/packages/contracts/lib/src/mail/factory.dart +++ b/packages/contracts/lib/src/mail/factory.dart @@ -0,0 +1,10 @@ +// import statements for required packages +import 'mailer.dart'; + +abstract class Factory { + /// Get a mailer instance by name. + /// + /// @param [name] The name of the mailer instance. + /// @return An instance of [Mailer]. + Mailer mailer([String? name]); +} diff --git a/packages/contracts/lib/src/mail/mail_queue.dart b/packages/contracts/lib/src/mail/mail_queue.dart index e69de29..5b08ef3 100644 --- a/packages/contracts/lib/src/mail/mail_queue.dart +++ b/packages/contracts/lib/src/mail/mail_queue.dart @@ -0,0 +1,20 @@ +// Import necessary libraries +import 'dart:async'; + +/// Represents the MailQueue interface. +abstract class MailQueue { + /// Queues a new e-mail message for sending. + /// + /// [view] can be a Mailable, String, or List. + /// [queue] is the optional queue name. + /// Returns a Future representing the queued result. + Future queue(dynamic view, {String? queue}); + + /// Queues a new e-mail message for sending after [delay]. + /// + /// [delay] can be a Duration, int (in seconds), or DateTime. + /// [view] can be a Mailable, String, or List. + /// [queue] is the optional queue name. + /// Returns a Future representing the queued result. + Future later(dynamic delay, dynamic view, {String? queue}); +} diff --git a/packages/contracts/lib/src/mail/mailable.dart b/packages/contracts/lib/src/mail/mailable.dart index e69de29..c07851a 100644 --- a/packages/contracts/lib/src/mail/mailable.dart +++ b/packages/contracts/lib/src/mail/mailable.dart @@ -0,0 +1,58 @@ +import 'package:some_package/queue.dart'; // Replace with actual queue package +import 'package:some_package/mail.dart'; // Replace with actual mail package + +// TODO: Check Imports. + +abstract class Mailable { + /// Send the message using the given mailer. + /// + /// @param Factory|Mailer $mailer + /// @return SentMessage|null + Future send(Mailer mailer); + + /// Queue the given message. + /// + /// @param Queue $queue + /// @return dynamic + Future queue(Queue queue); + + /// Deliver the queued message after (n) seconds. + /// + /// @param DateTimeInterface|Duration|int $delay + /// @param Queue $queue + /// @return dynamic + Future later(dynamic delay, Queue queue); + + /// Set the recipients of the message. + /// + /// @param dynamic $address + /// @param String? $name + /// @return self + Mailable cc(dynamic address, [String? name]); + + /// Set the recipients of the message. + /// + /// @param dynamic $address + /// @param String? $name + /// @return $this + Mailable bcc(dynamic address, [String? name]); + + /// Set the recipients of the message. + /// + /// @param dynamic $address + /// @param String? $name + /// @return $this + Mailable to(dynamic address, [String? name]); + + /// Set the locale of the message. + /// + /// @param String $locale + /// @return $this + Mailable locale(String locale); + + /// Set the name of the mailer that should be used to send the message. + /// + /// @param String $mailer + /// @return $this + Mailable mailer(String mailer); +} diff --git a/packages/contracts/lib/src/mail/mailer.dart b/packages/contracts/lib/src/mail/mailer.dart index e69de29..5bf90ad 100644 --- a/packages/contracts/lib/src/mail/mailer.dart +++ b/packages/contracts/lib/src/mail/mailer.dart @@ -0,0 +1,44 @@ +abstract class Mailer { + /// Begin the process of mailing a mailable class instance. + /// + /// [users] can be of any type. + /// Returns a PendingMail instance. + PendingMail to(dynamic users); + + /// Begin the process of mailing a mailable class instance. + /// + /// [users] can be of any type. + /// Returns a PendingMail instance. + PendingMail bcc(dynamic users); + + /// Send a new message with only a raw text part. + /// + /// [text] is the raw text message. + /// [callback] can be of any type. + /// Returns a SentMessage instance or null. + SentMessage? raw(String text, dynamic callback); + + /// Send a new message using a view. + /// + /// [view] can be of type Mailable, String, or List. + /// [data] is a map of data to pass to the view. + /// [callback] is a function or null. + /// Returns a SentMessage instance or null. + SentMessage? send(dynamic view, {Map data = const {}, dynamic callback}); + + /// Send a new message synchronously using a view. + /// + /// [mailable] can be of type Mailable, String, or List. + /// [data] is a map of data to pass to the view. + /// [callback] is a function or null. + /// Returns a SentMessage instance or null. + SentMessage? sendNow(dynamic mailable, {Map data = const {}, dynamic callback}); +} + +class PendingMail { + // Implementation of PendingMail class +} + +class SentMessage { + // Implementation of SentMessage class +} diff --git a/packages/contracts/lib/src/notifications/dispatcher.dart b/packages/contracts/lib/src/notifications/dispatcher.dart index e69de29..93ce7f6 100644 --- a/packages/contracts/lib/src/notifications/dispatcher.dart +++ b/packages/contracts/lib/src/notifications/dispatcher.dart @@ -0,0 +1,16 @@ +abstract class Dispatcher { + /// Send the given notification to the given notifiable entities. + /// + /// @param List|dynamic notifiables + /// @param dynamic notification + /// @return void + void send(dynamic notifiables, dynamic notification); + + /// Send the given notification immediately. + /// + /// @param List|dynamic notifiables + /// @param dynamic notification + /// @param List? channels + /// @return void + void sendNow(dynamic notifiables, dynamic notification, List? channels); +} diff --git a/packages/contracts/lib/src/notifications/factory.dart b/packages/contracts/lib/src/notifications/factory.dart index e69de29..69337ea 100644 --- a/packages/contracts/lib/src/notifications/factory.dart +++ b/packages/contracts/lib/src/notifications/factory.dart @@ -0,0 +1,30 @@ +// Define the namespace (this would be part of the file structure in Dart) +//library illuminate.contracts.notifications; + +// TODO: Check imports - Check for way to do namespaces + +// Import necessary Dart packages +import 'package:collection/collection.dart'; + +// Define the Factory interface +abstract class Factory { + /// Get a channel instance by name. + /// + /// @param String? name + /// @return dynamic + dynamic channel(String? name); + + /// Send the given notification to the given notifiable entities. + /// + /// @param dynamic notifiables + /// @param dynamic notification + /// @return void + void send(dynamic notifiables, dynamic notification); + + /// Send the given notification immediately. + /// + /// @param dynamic notifiables + /// @param dynamic notification + /// @return void + void sendNow(dynamic notifiables, dynamic notification); +} diff --git a/packages/contracts/lib/src/pagination/cursor_paginator.dart b/packages/contracts/lib/src/pagination/cursor_paginator.dart index e69de29..7137152 100644 --- a/packages/contracts/lib/src/pagination/cursor_paginator.dart +++ b/packages/contracts/lib/src/pagination/cursor_paginator.dart @@ -0,0 +1,87 @@ +abstract class CursorPaginator { + /// Get the URL for a given cursor. + /// + /// @param Cursor? cursor + /// @return String + String url(Cursor? cursor); + + /// Add a set of query string values to the paginator. + /// + /// @param List? key + /// @param String? value + /// @return $this + CursorPaginator appends(dynamic key, [String? value]); + + /// Get / set the URL fragment to be appended to URLs. + /// + /// @param String? fragment + /// @return $this|String? + dynamic fragment([String? fragment]); + + /// Add all current query string values to the paginator. + /// + /// @return $this + CursorPaginator withQueryString(); + + /// Get the URL for the previous page, or null. + /// + /// @return String? + String? previousPageUrl(); + + /// The URL for the next page, or null. + /// + /// @return String? + String? nextPageUrl(); + + /// Get all of the items being paginated. + /// + /// @return List + List items(); + + /// Get the "cursor" of the previous set of items. + /// + /// @return Cursor? + Cursor? previousCursor(); + + /// Get the "cursor" of the next set of items. + /// + /// @return Cursor? + Cursor? nextCursor(); + + /// Determine how many items are being shown per page. + /// + /// @return int + int perPage(); + + /// Get the current cursor being paginated. + /// + /// @return Cursor? + Cursor? cursor(); + + /// Determine if there are enough items to split into multiple pages. + /// + /// @return bool + bool hasPages(); + + /// Get the base path for paginator generated URLs. + /// + /// @return String? + String? path(); + + /// Determine if the list of items is empty or not. + /// + /// @return bool + bool isEmpty(); + + /// Determine if the list of items is not empty. + /// + /// @return bool + bool isNotEmpty(); + + /// Render the paginator using a given view. + /// + /// @param String? view + /// @param Map data + /// @return String + String render([String? view, Map data = const {}]); +} diff --git a/packages/contracts/lib/src/pagination/length_aware_paginator.dart b/packages/contracts/lib/src/pagination/length_aware_paginator.dart index e69de29..b5de7de 100644 --- a/packages/contracts/lib/src/pagination/length_aware_paginator.dart +++ b/packages/contracts/lib/src/pagination/length_aware_paginator.dart @@ -0,0 +1,20 @@ +import 'paginator.dart'; + +abstract class LengthAwarePaginator extends Paginator { + /// Create a range of pagination URLs. + /// + /// @param int start + /// @param int end + /// @return List + List getUrlRange(int start, int end); + + /// Determine the total number of items in the data store. + /// + /// @return int + int total(); + + /// Get the page number of the last available page. + /// + /// @return int + int lastPage(); +} diff --git a/packages/contracts/lib/src/pagination/paginator.dart b/packages/contracts/lib/src/pagination/paginator.dart index e69de29..01655f5 100644 --- a/packages/contracts/lib/src/pagination/paginator.dart +++ b/packages/contracts/lib/src/pagination/paginator.dart @@ -0,0 +1,87 @@ +abstract class Paginator { + /// Get the URL for a given page. + /// + /// @param int $page + /// @return string + String url(int page); + + /// Add a set of query string values to the paginator. + /// + /// @param array|string|null $key + /// @param string|null $value + /// @return $this + Paginator appends(dynamic key, [String? value]); + + /// Get / set the URL fragment to be appended to URLs. + /// + /// @param string|null $fragment + /// @return $this|string|null + dynamic fragment([String? fragment]); + + /// The URL for the next page, or null. + /// + /// @return string|null + String? nextPageUrl(); + + /// Get the URL for the previous page, or null. + /// + /// @return string|null + String? previousPageUrl(); + + /// Get all of the items being paginated. + /// + /// @return array + List items(); + + /// Get the "index" of the first item being paginated. + /// + /// @return int|null + int? firstItem(); + + /// Get the "index" of the last item being paginated. + /// + /// @return int|null + int? lastItem(); + + /// Determine how many items are being shown per page. + /// + /// @return int + int perPage(); + + /// Determine the current page being paginated. + /// + /// @return int + int currentPage(); + + /// Determine if there are enough items to split into multiple pages. + /// + /// @return bool + bool hasPages(); + + /// Determine if there are more items in the data store. + /// + /// @return bool + bool hasMorePages(); + + /// Get the base path for paginator generated URLs. + /// + /// @return string|null + String? path(); + + /// Determine if the list of items is empty or not. + /// + /// @return bool + bool isEmpty(); + + /// Determine if the list of items is not empty. + /// + /// @return bool + bool isNotEmpty(); + + /// Render the paginator using a given view. + /// + /// @param string|null $view + /// @param array $data + /// @return string + String render([String? view, Map data = const {}]); +} diff --git a/packages/contracts/lib/src/pipeline/hub.dart b/packages/contracts/lib/src/pipeline/hub.dart index e69de29..36b5148 100644 --- a/packages/contracts/lib/src/pipeline/hub.dart +++ b/packages/contracts/lib/src/pipeline/hub.dart @@ -0,0 +1,10 @@ +// Define a Dart interface for Hub + +abstract class Hub { + /// Send an object through one of the available pipelines. + /// + /// @param object The object to be piped. + /// @param pipeline The name of the pipeline, or null to use the default. + /// @return The processed object. + dynamic pipe(dynamic object, [String? pipeline]); +} diff --git a/packages/contracts/lib/src/pipeline/pipeline.dart b/packages/contracts/lib/src/pipeline/pipeline.dart index e69de29..7991d3d 100644 --- a/packages/contracts/lib/src/pipeline/pipeline.dart +++ b/packages/contracts/lib/src/pipeline/pipeline.dart @@ -0,0 +1,15 @@ +import 'dart:async'; + +abstract class Pipeline { + /// Set the traveler object being sent on the pipeline. + Pipeline send(dynamic traveler); + + /// Set the stops of the pipeline. + Pipeline through(dynamic stops); + + /// Set the method to call on the stops. + Pipeline via(String method); + + /// Run the pipeline with a final destination callback. + FutureOr then(FutureOr Function() destination); +} diff --git a/packages/contracts/lib/src/process/invoked_process.dart b/packages/contracts/lib/src/process/invoked_process.dart index e69de29..65edfbc 100644 --- a/packages/contracts/lib/src/process/invoked_process.dart +++ b/packages/contracts/lib/src/process/invoked_process.dart @@ -0,0 +1,42 @@ +import 'process_result.dart'; +abstract class InvokedProcess { + /// Get the process ID if the process is still running. + /// + /// Returns an integer or null. + int? id(); + + /// Send a signal to the process. + /// + /// Takes an integer [signal] and returns the current instance. + InvokedProcess signal(int signal); + + /// Determine if the process is still running. + /// + /// Returns a boolean. + bool running(); + + /// Get the standard output for the process. + /// + /// Returns a string. + String output(); + + /// Get the error output for the process. + /// + /// Returns a string. + String errorOutput(); + + /// Get the latest standard output for the process. + /// + /// Returns a string. + String latestOutput(); + + /// Get the latest error output for the process. + /// + /// Returns a string. + String latestErrorOutput(); + + /// Wait for the process to finish. + /// + /// Takes an optional [output] callback and returns a ProcessResult instance. + Future wait([Future Function()? output]); +} diff --git a/packages/contracts/lib/src/process/process_result.dart b/packages/contracts/lib/src/process/process_result.dart index e69de29..82cd974 100644 --- a/packages/contracts/lib/src/process/process_result.dart +++ b/packages/contracts/lib/src/process/process_result.dart @@ -0,0 +1,56 @@ +abstract class ProcessResult { + /// Get the original command executed by the process. + /// + /// @return String + String command(); + + /// Determine if the process was successful. + /// + /// @return bool + bool successful(); + + /// Determine if the process failed. + /// + /// @return bool + bool failed(); + + /// Get the exit code of the process. + /// + /// @return int|null + int? exitCode(); + + /// Get the standard output of the process. + /// + /// @return String + String output(); + + /// Determine if the output contains the given string. + /// + /// @param String output + /// @return bool + bool seeInOutput(String output); + + /// Get the error output of the process. + /// + /// @return String + String errorOutput(); + + /// Determine if the error output contains the given string. + /// + /// @param String output + /// @return bool + bool seeInErrorOutput(String output); + + /// Throw an exception if the process failed. + /// + /// @param Function? callback + /// @return ProcessResult + ProcessResult throwException([Function? callback]); + + /// Throw an exception if the process failed and the given condition is true. + /// + /// @param bool condition + /// @param Function? callback + /// @return ProcessResult + ProcessResult throwIf(bool condition, [Function? callback]); +}