Skip to content
Josh Wright edited this page Jan 14, 2021 · 11 revisions

Table of Contents

Alchemy

Fusion

Papyrus

Alchemy

Types

  • PapyrusClientError: An error that occurred when requesting a Papyrus.Endpoint.
  • BasicAuthMiddleware: A Middleware type configured to work with BasicAuthable. This middleware will intercept requests and queries the table backing B for a row matching the basic auth headers of the request. If a matching row is found, that value will be associated with the request. If there is no Authentication: Basic ... header, or the basic auth values don't match a row in the database, an HTTPError(.unauthorized) will be thrown.
  • TokenAuthMiddleware: A Middleware type configured to work with TokenAuthable. This middleware will intercept requests and queries the table backing T for a row matching the token auth headers of the request. If a matching row is found, that value will be associated with the request. If there is no Authentication: Token ... header, or the token value isn't valid, an HTTPError(.unauthorized) will be thrown.
  • Env: Handles any environment info of your application. Loads any environment variables from the file a .env or .{APP_ENV} if APP_ENV is set in the current environment.
  • HTTPBody: The contents of an HTTP request or response.
  • HTTPError: An HTTPError that can be thrown during routing. When intercepted, Alchemy will return an error response with the status code of this error and a body containing the message, if there is one.
  • MIMEType: An HTTP Media Type. It has a value: String appropriate for putting into Content-Type headers.
  • PathParameter: Represents a dynamic parameter inside the URL. Parameter placeholders should be prefaced with a colon (:) in the route string. Something like :user_id in the path /v1/users/:user_id.
  • PathParameter.DecodingError: An error encountered while decoding a path parameter value string to a specific type such as UUID or Int.
  • HTTPAuth: A type representing any auth that may be on an HTTP request. Supports Basic and Bearer.
  • HTTPAuth.Basic: The basic auth of an Request. Corresponds to a header that looks like Authorization: Basic <base64-encoded-username-password>.
  • HTTPAuth.Bearer: The bearer auth of an Request. Corresponds to a header that looks like Authorization: Bearer <token>.
  • Request: A simplified Request type as you'll come across in many web frameworks
  • Response: A type representing the response from an HTTP endpoint. This response can be a failure or success case depending on the status code in the head.
  • Launch: Command to launch a given application & either serve or migrate.
  • Log: Convenience struct for logging logs of various levels to a default Logger. By default, this logger has label Alchemy.
  • Socket: A type representing a communication link between two programs running on a network. A server can bind to a socket when serving (i.e. this is where the server can be reached). Other network interfaces can also be reached via a socket, such as a database. Either an ip host & port or a unix socket path.
  • WeekUnit: A week of time.
  • DayUnit: A day of time.
  • HourUnit: An hour of time.
  • MinuteUnit: A minute of time.
  • SecondUnit: A second of time.
  • FrequencyTyped: A generic frequency for handling amounts of time.
  • Weekday: A day of the week.
  • Scheduler: Schedules Jobs at recurring intervals, like a cron.
  • Router: An Router responds to HTTP requests from the client. Specifically, it takes an Request and routes it to a handler that returns an ResponseConvertible.
  • CORSMiddleware: The MIT License (MIT)
  • CORSMiddleware.AllowOriginSetting: Option for the allow origin header in responses for CORS requests.
  • CORSMiddleware.Configuration: Configuration used for populating headers in response for CORS requests.
  • StaticFileMiddleware: Middleware for serving static files from a given directory.
  • ModelQuery: A ModelQuery is just a subclass of Query with some added typing and convenience functions for querying the table of a specific Model.
  • BelongsToRelationship: The child of a 1 - M or a 1 - 1 relationship. Backed by an identifier of the parent, when encoded to a database, this type attempt to write that identifier to a column named <property-name>_id.
  • HasManyRelationship: Either side of a M - M relationship or the parent of a 1 - M relationship. The details of this relationship are defined in the initializers inherited from HasRelationship.
  • HasOneRelationship: Either side of a 1 - 1 relationship. The details of this relationship are defined in the initializers inherited from HasRelationship.
  • HasRelationship: Contains shared behavior for "has" relationships, particularly around eager loading functionality.
  • RuneError: Any general error that might occur when using the Rune ORM.
  • DatabaseConfig: The information needed to connect to a database.
  • DatabaseError: An error encountered when interacting with a Database.
  • DatabaseField: Represents a column & value pair in a database row.
  • DatabaseKeyMappingStrategy: Represents the mapping between your type's property names and their corresponding database column.
  • DatabaseValue: Represents the type / value combo of an SQL database field. These don't necessarily correspond to a specific SQL database's types; they just represent the types that Alchemy current supports.
  • MySQLDatabase
  • PostgresDatabase: A concrete Database for connecting to and querying a PostgreSQL database.
  • AlterTableBuilder: A builder for altering the columns of an existing table.
  • CreateColumnBuilder: A builder for creating columns on a table in a relational database.
  • SQLJSON: A type used to signify that a column on a database has a JSON type.
  • CreateTableBuilder: A builder with useful functions for creating a table.
  • CreateIndex: A type for keeping track of data associated with creating an index.
  • CreateColumn: A type for keeping track of data associated with creating an column.
  • Schema: Represents the schema of a table in a relational database.
  • JoinType: The type of the join clause.
  • JoinClause: A JOIN query builder.
  • OrderClause: A clause for ordering rows by a certain column.
  • OrderClause.Sort: A sorting direction.
  • WhereBoolean
  • WhereValue
  • WhereColumn
  • WhereNested
  • WhereIn
  • WhereIn.InType
  • WhereRaw
  • Grammar: Used for compiling query builders into raw SQL statements.
  • ColumnType: An abstraction around various supported SQL column types. Grammars will map the ColumnType to the backing dialect type string.
  • StringLength: The length of an SQL string column in characters.
  • Query
  • Operator
  • SQL
  • Services: Provides easy access to some commonly used services in Alchemy. These services are Injected from the global Container. You can add your own services in extensions if you'd like.
  • Thread: A utility for running expensive CPU work on threads so as not to block the current EventLoop.
  • BCryptDigest: Creates and verifies BCrypt hashes. Normally you will not need to initialize one of these classes and you will use the global BCrypt convenience instead.
  • BcryptError
  • OrderedDictionary: The MIT License (MIT)

Protocols

  • HTMLView: A protocol for defining HTML views to return to a client.
  • BasicAuthable: A protocol for automatically authenticating incoming requests based on their Authentication: Basic ... header. When the request is intercepted by the BasicAuthMiddleware<T>, it will query the table of T in Services.db for a row that has a matching username & validate the password. If the row exists & the password matches, the type T will be set on the request.
  • TokenAuthable: A protocol for automatically authenticating incoming requests based on their Authentication: Bearer ... header. When the request is intercepted by a related TokenAuthMiddleware<T>, it will query the table of T in Services.db for a row that has a matching token value. If the exists, the correlating User type will be queried and set on the request.
  • Application: The core type for an Alchemy application. Implement this & it's setup function, then call MyApplication.launch() in your main.swift.
  • StringInitializable: Protocol representing a type that can be created from a String.
  • ResponseWriter: An abstraction around writing data to a remote peer. Conform to this protocol and inject it into the Response for responding to a remote peer at a later point in time.
  • Frequency: Represents a frequency that occurs at a rate and may have specific requirements for when it should start running, such as "every day at 9:30 am".
  • TimeUnit: A unit of time.
  • Job: An abstract block of work to be run.
  • Controller: Represents a type that adds handlers to a router. Used for organizing your app's handlers into smaller components.
  • Middleware: A Middleware is used to intercept either incoming Requests or outgoing Responses. Using futures, they can do something with those, either synchronously or asynchronously.
  • ResponseConvertible: Represents any type that can be converted into a response & is thus returnable from a request handler.
  • Model: An ActiveRecord-esque type used for modeling a table in a relational database. Contains many extensions for making database queries, supporting relationships & much more.
  • PrimaryKey: Represents a type that may be a primary key in a database. Out of the box UUID, String and Int are supported but you can easily support your own by conforming to this protocol.
  • Relationship: A protocol representing a relationship between two Models. Contains only those two types and functionality for eager loading this relationship.
  • ModelMaybeOptional: Either a Model or a Model?.
  • Database: A generic type to represent any database you might be interacting with. Currently, the only two implementations are PostgresDatabase and MySQLDatabase. The QueryBuilder and Rune ORM are built on top of this abstraction.
  • DatabaseRow: A row of data returned from a database. Various database packages can use this as an abstraction around their internal row types.
  • Migration: A Migration provides functionality for adding and rolling back changes to the schema of a relational database.
  • Sequelizable: Something that can be turned into SQL.
  • Column: Something convertible to a table column in an SQL database.
  • Parameter
  • AnyOptional: Represents a type erased Optional.

Global Typealiases

  • Seconds: A frequency measured in a number of seconds.
  • Minutes: A frequency measured in a number of minutes.
  • Hours: A frequency measured in a number of hours.
  • Days: A frequency measured in a number of days.
  • Weeks: A frequency measured in a number of weeks.
  • ModelEnum: A protocol to which enums on Models should conform to. The enum will be modeled in the backing table by it's raw value.
  • WhereNestedClosure
  • OrderedDictionarySlice: A view into an ordered dictionary whose indices are a subrange of the indices of the ordered dictionary.
  • OrderedDictionaryKeys: A collection containing the keys of the ordered dictionary.
  • OrderedDictionaryValues: A collection containing the values of the ordered dictionary.

Global Functions

Global Variables

  • Bcrypt: Creates and verifies BCrypt hashes.

Fusion

Types

  • Container: A container from which services should be registered and resolved.
  • Inject: Provides a convenient @propertyWrapper for injecting services to a type. By default, resolves services from the global container (Container.global) but if the enclosing type conforms to Containerized services are resolved from EnclosingType.container.

Protocols

  • Containerized: Conform a class to Containerized lets the @Inject property wrapper know that there is a custom container from which services should be resolved.

Papyrus

Types

  • Empty: Represents an Empty request or response on an Endpoint.
  • RequestComponents: Represents the components needed to make an HTTP request.
  • ArrayEncoding: Configures how Array parameters are encoded.
  • BoolEncoding: Configures how Bool parameters are encoded.
  • Endpoint: Endpoint is an abstraction around making REST requests. It includes a Request type, representing the data needed to make the request, and a Response type, representing the expected response from the server.
  • BodyEncoding: Indicates the type of a request's body. The content type affects how and where the content is encoded.
  • EndpointGroup: An EndpointGroup represents a collection of endpoints from the same host.
  • EndpointMethod: Represents the HTTP method, or verb, of a request. There are static accessors for GET, POST, PUT, PATCH, and DELETE, but any custom one can be made with the public initializer.
  • PapyrusError: A Papyrus related error.
  • PapyrusValidationError: An error related to decoding a type from a DecodableRequest.
  • CUSTOM: Represents an Endpoint with a custom HTTP method.
  • DELETE: Represents a DELETE Endpoint.
  • GET: Represents a GET Endpoint.
  • PATCH: Represents a PATCH Endpoint.
  • POST: Represents a POST Endpoint.
  • PUT: Represents a PUT Endpoint.
  • AnyEncodable: An erased Encodable.
  • Body: Represents the body of a request.
  • Header: Represents an item in a request's headers.
  • Path: Represents a path component value on an endpoint. This value will replace a path component with the name of the property this wraps.
  • URLQuery: Represents a value in the query of an endpoint's URL.

Protocols

  • DecodableRequest: A type from which a RequestAllowed can be decoded. Conform your server's Request type to this for easy validation against a RequestAllowed type.
  • EndpointRequest: A type that can be the Request type of an Endpoint.
  • AnyBody: A type erased body of a request.
Alchemy
Types
Protocols
Global Typealiases
Global Variables
Global Functions
Fusion
Types
Protocols
Papyrus
Types
Protocols
Clone this wiki locally