Swiftpack.co - Package - nodes-vapor/sugar

Sugar 🍬

Swift Version Vapor Version Circle CI codebeat badge codecov Readme Score GitHub license

📦 Installation

Add Sugar to the package dependencies (in your Package.swift file):

dependencies: [
    ...,
    .package(url: "https://github.com/nodes-vapor/sugar.git", from: "4.0.0-beta")
]

as well as to your target (e.g. "App"):

targets: [
    ...
    .target(
        name: "App",
        dependencies: [... "Sugar" ...]
    ),
    ...
]

Getting started 🚀

Make sure that you've imported Sugar everywhere when needed:

import Sugar

Helpers

This package contains a lot of misc. functionality that might not fit into it's own package or that would best to get PR'ed into Vapor. Some examples of what this package contains:

Environment variables

Access environment variables by writing

env("my-key", "my-fallback-value")

Seeder commands

If you want to make your model seedable, you can conform it to Seedable and use SeederCommand to wrap your seedable model. This basically means that you can focus on how your model gets initialized when running your command, and save a little code on actually performing the database work.

Seeding multiple instances of your model will be added - feel free to PR.

Authentication

This package contains a lot of convenience related to JWT, usernames and passwords which is used in JWTKeychain and Admin Panel.

Migrations

Sugar contains a helper function for adding properties while excluding some specific ones. This makes it a bit more convenient if you want to only modify how a single one or a couple of fields gets prepared.

extension MyModel: Migration {
    static func prepare(on connection: MySQLConnection) -> Future<Void> {
        return MySQLDatabase.create(self, on: connection) { builder in
            try addProperties(to: builder, excluding: [\.title])
            builder.field(for: \.title, type: .varchar(191))
        }
    }
}

🏆 Credits

This package is developed and maintained by the Vapor team at Nodes. The package owner for this project is Siemen.

📄 License

This package is open-sourced software licensed under the MIT license

Github

link
Stars: 23

Used By

Total: 0

Releases

Version 4.0.0 RC 6 - 2019-08-26 06:41:36

Added

  • public initializer for NumberFormatTag

- 2019-08-06 17:17:51

Version 4.0.0 RC 5 - 2019-06-04 14:29:26

Added

  • CircleCI jobs to test for Swift 5 compatibility as well

Fixed

  • Working around a linux crash when using Calendar.current (see #97)

Version 4.0.0 RC 4 - 2019-05-14 08:12:26

Added

  • Less constraints on Loginable

Version 4.0.0 RC 3 - 2019-05-07 07:52:26

Fixed

  • Fixed Swift 5 compiler warnings related to redundant access modifiers

Version 4.0.0 RC 2 - 2019-03-23 07:10:54

Changed

  • Loosen default implementation for Creatable's init

Version 4.0.0 RC 1 - 2019-03-06 12:41:38

Added

  • applyUpdate on Future<Updatable>

Removed

  • overload of Future.flatTry that takes a closure returning Future<Any> was removed. Use the one that takes a closure retuning Future<Void> instead. This removal helps with type inference and the Any version did not add any convenience since a .map { $0 as Any } was needed which is not better than .transform(()).

Version 4.0.0 Beta 2 - 2019-02-17 07:18:11

Added

  • Add requireParameterCount(upTo:) on TagContext to check if there are at most n parameters (extracted from the nodes-vapor/Bootstrap package).

Version 4.0.0 Beta 1 - 2019-02-07 15:27:49

Added

  • The following protocols were added: Creatable, Loginable, PublicRepresentable, Updatable.
  • validateThat(only:has:for:on) function for validating uniqueness of properties

Changed

  • Types conforming to HasReadablePassword no longer have to be Decodable
  • Date convenience functions now accept a calendar instance

Removed

  • The UserType protocol was removed in favor of a more composable structure using a combination of some of the added protocols.

Version 2.0.14 - 2019-01-25 05:17:06

Added

  • Support for specifying when to auth and what error to throw for SimpleAuthMiddleware.

Version 2.0.13 - 2019-01-24 19:52:42

Added

  • Support for conditional auth when using SimpleAuthMiddleware.

Version 3.0.0 - 2018-12-04 09:48:19

Changed

  • This package now correctly pins towards Swift 4.1 in Package.swift (thanks @cb1674).

Removed

  • Removed the static function get on Environment since it was already defined in vapor/service (thanks @cb1674).
  • Removed the MutableLeafTagConfig since we will encourage the use...LeafTags pattern moving on.

Version 3 RC3 - 2018-11-08 12:04:04

Added

  • Validator for a "Strong password". The behaviour can be overwritten, but the default behaviour is that the input needs to satisfy 3 out of 4 categories: a lower char, an upper char, a digit or a special char.

Version 3.0.0 RC2 - 2018-11-07 08:49:54

Added

  • Small helper for creating time durations in secs. E.g. 2.hoursInSecs.

Version 3.0.0 RC1 - 2018-10-31 08:08:21

Added

  • Helper on URL to add query parameters (manually or from another URL).

Changed

  • Bumped to Swift 4.2.

Fixed

  • SwiftLint now runs without any errors/warnings.

This should be the 3.0.0 release if no issues occurs.

Version 3.0.0 Beta 18 - 2018-10-24 07:04:26

Added

  • convenience for passing request into render function via the new userInfo parameter so it can be retrieved in the tag context:

When rendering the view:

    try req.view().render("...", on: req)

In the TagRenderer:

public func render(tag: TagContext) throws -> Future<TemplateData> {
    let req = try tag.requireRequest()
    ....
}

Version 3.0.0 Beta 17 - 2018-10-24 06:20:50

Added

  • More convenience functions for retrieving environment variables.

Version 3.0.0 Beta 16 - 2018-09-12 13:54:54

Added

  • Custom leaf tag to format number to a fixed amount of decimals

Version 3.0.0 Beta 15 - 2018-09-07 07:53:46

Fixed

• Access levels from implicit/default internal to explicit public

Version 3.0.0 Beta 14 - 2018-09-06 09:33:35

Added

  • Initialize a non-optional Bool from a String

Version 2.0.12 - 2018-08-24 08:49:38

This release is compatible with Vapor 2.

Changed

  • Improved/streamlined Date calculation functions and allow passing in Calendar where applicable.

Version 3.0.0 Beta 13 - 2018-08-20 09:59:47

Fixed

  • Now conforms to Redis 3.0.0 updates.

Version 3.0.0 Beta 12 - 2018-08-16 09:02:13

Changed

  • Now pins against Leaf 3.0.0 and Auth 2.0.0.

Fixed

  • Now conforms to JWT 3.0.0 updates.

Thanks @mcdappdev

Version 3.0.0 Beta 11 - 2018-07-17 12:04:26

Fixed

  • This package now uses Fluent 3.0.0 and has been updated to align with the release.

Added

  • Convenience function for flattening a list of Futures which you want to run in a sequence.

Version 2.0.11 - 2018-07-16 09:06:58

This release is compatible with Vapor 2.

Added

  • Overload for saveOrModify for entities which are SoftDeletable that makes it easy to restore them.

Version 3.0.0 Beta 10 - 2018-07-16 05:48:56

Added

  • Support for adding values to Redis cache with an expiration time.

Version 3.0.0 Beta 9 - 2018-07-11 13:07:53

Changed

  • Updated saveOrUpdate to support handling soft deleted entities.

Version 3.0.0 Beta 8 - 2018-07-06 14:01:44

Changed

  • Default min. password length is now 8 (instead of 9)

Version 3.0.0 Beta 7 - 2018-07-05 13:40:02

Added

  • Overload for addProperties which takes in a list of ReflectedPropertys which makes it possible to exclude properties of different types.

Version 2.0.10 - 2018-07-05 10:55:56

This release is compatible with Vapor 2

Fixes

  • SimpleAuthMiddleware responder chain did not terminate on error.