Code Monkey home page Code Monkey logo

node's Introduction

node's People

Contributors

alirp88 avatar bitdeli-chef avatar brettrtoomey avatar brightredchilli avatar hhanesand avatar iliaskarim avatar jeffreyjackson avatar joannis avatar justbaum30 avatar loganwright avatar marxon13 avatar mau888 avatar patoroco avatar rkreutz avatar rpinz avatar tanner0101 avatar vzsg avatar wanewang avatar zerofactor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node's Issues

Hashable structured data

Would it be possible to implement a Hashable extension to StructuredData ?

I see we already provide an implementation for equals, so this would be a nice addition, as it would save me from unwrapping the structured data type.

Here is my idea.

extension StructuredDataWrapper {
    
    var hashValue: Int {
        switch self.wrapped {
            
        case let .bool(bool):
            return bool.hashValue
            
        case let .number(number):
            switch number {
            case let .int(int):
                return int.hashValue
                
            case let .double(double):
                return double.hashValue
                
            case let .uint(uint):
                return uint.hashValue
            }
            
        case let .string(string):
            return string.hashValue
            
        case let .date(date):
            return date.hashValue
            
        case let .bytes(bytes):
            return bytes.makeString().hashValue
            
        case let .array(array):
            // Not too sure here
            return 0
            
        case let .object(object):
            // Not too sure here
            return 0
            
        case .null:
            return 0
        }
    }
}

Documentation circle

The documentation for this module says to read the main Vapor documentation (with a link), and the main documentation says to read the documentation for this module here(with a link). It's a circular reference, with no actual documentation.

Extracting .bytes not directly possible

Because of the .bytes type being an array. It is very hard to properly extract this from a Node. If you use the normal extract method. Instead of extracting bytes, it will try to extract an Node array of numbers. This is understandable, but very inconvenient.

Would it be an idea, to change the [UInt8] from .bytes into Data from Foundation? I now this has a bit of overhead, compared to using an array directly. It does however make more sense, looking at Foundation and it will make extracting possible, as it is a completely different type.

Add decimal to the possible numbers?

Decimal is different from double and float in that it supports base 10 numbers much better that double and float do. I would love for decimal to be supported by node natively.

help with NodeError.unableToConvert / extract method

Hi... I have a NodeConvertible class, in the init currently i have one do/try/catchfor every required key:

do {
    id = try node.extract("id")
} catch NodeError.unableToConvert {
    throw CustomError.noId
}

do {
    type =  try node.extract("type")
} catch NodeError.unableToConvert {
    throw CustomError.noType
}

but I think is more cleaner having something like this:

do {
    id = try node.extract("id")
    type =  try node.extract("type")
} catch {
    switch( something ) {
        case "id":
            throw CustomError.noId
        break
        case "type":
             throw CustomError.noType
        break
    }
}

How can I do that?

Understanding on Identifier

Hi,

I'm spending some time trying out Vapor2 a bit and I have to say that, imo, the code is now much better than the version 1.0. Thank you all guys :)

Going to the question, I'm a bit confused with the Identifier concept.
By implementing a Model using Fluent, the idea is to hide any database-related logic from our code, to make it more maintainable and easy to change to other engines. But the Identifier class is still a bit unclear to me.

I'm now using a postgres database, so a normal table id value is an Int. In mongo it will probably be an object or a String. So far everything is ok.

My Todo object as an Identifier and the router should handle a GET /todos/:id. Here is the problem: how I'm supposed to handle the id type?

What I ended up is this

todos.get("", ":id") { request in
  guard let todoId = request.parameters["id"]?.string else {
    throw Abort.badRequest
  }
                
  let identifier = Identifier(.string(todoId), in: nil)
  return try _todoController.todoWith(identifier, for: try request.getUserId())
}

In my case, an Int is convertible to a String type, so I hope that, when Fluent will be comparing Identifiers, the equality will be verified correctly. Am I correct?
Is there a more elegant way to handle this without passing by a String object? I would have expected something similar to

guard let todoId = request.parameters["id"]?.identifier else {
    throw Abort.badRequest
}

which will abstract the Identifier type at all.
What do you think? Also because the subscript value is already a StructuredDataWrapper object.

Using Node.date causes segfault on Linux

With the current stable versions of Foundation on Linux, the ISO 8601 calendar as used by Node.date is not available. This causes CFCalendarCreateWithIdentifier() to return NULL and then crash in CFCalendarSetLocale() with a segfault. In GDB, it looks like this:

Thread 3 "App" received signal SIGSEGV, Segmentation fault.
0x00007ffff6c08b02 in CFCalendarSetLocale () from /home/user/.swiftenv/versions/3.0.2/usr/lib/swift/linux/libFoundation.so

The good news is that support for the ISO 8601 calendar in CFCalendarCreateWithIdentifier() has been added to master of https://github.com/apple/swift-corelibs-foundation. The bad news is the commit that added support was published only 12 days ago, so it may take some time before this appears in a stable release of Swift. Hopefully a workaround for this bug on Linux can be added before this feature officially ships in Vapor 2.0.

ambiguous error

Code

try json.get("permissions") as [String]

Input

{
	"userId": "xxx"
}

Error

{
  "debugReason": "No value found at path '', expected 'String'",
  "error": true,
  "identifier": "Node.NodeError.unableToConvert",
  "possibleCauses": [
    "typo in key path",
    "underlying type is not convertible",
    "unexpected '.' being interpreted as path instead of key"
  ],
  "reason": "Internal Server Error",
  "suggestedFixes": [
    "called `get(...)` on a key or key path that does not exist in the data",
    "the data being parsed is missing required values or is incorrectly formatted",
    "found unconvertible data, e.g., got a string of letters when an integer is required",
    "if you have keys containing a '.' that shouldn't be interpreted as a path, use 'DotKey(\"actual.key\")'"
  ]
}

Conversion to/from system libraries type

Node is missing bridging methods to and from system libraries.

It would definitely be useful to be able to convert any Node, JSON, StructuredData to Any / [String: Any].

This would make possible to bridge objects created using vapor, to system libraries such as JSONSerialization, etc.

It could look something like this:

public extension StructuredData {

    public init(any: Any) {

        switch any {

        case let value as [String: Any]:
            self = .object(value.mapValues { StructuredData(any: $0) })

        case let value as [Any]:
            self = .array(value.map { StructuredData(any: $0) })

        case let value as Bool:
            self = .bool(value)

        case let value as [UInt8]:
            self = .bytes(value)

        case let value as Date:
            self = .date(value)

        case let value as Int:
            self = .number(.int(value))

        case let value as UInt:
            self = .number(.uint(value))

        case let value as Double:
            self = .number(.double(value))

        case let value as String:
            self = .string(value)

        default:
            self = .null
        }
    }

    public var any: Any? {

        switch self {

        case .object(let object):

            var converted = [String: Any]()

            for (key, value) in object {
                converted[key] = value.any
            }

            return converted

        case .array(let value):
            return value.flatMap { $0.any }

        case .bool(let value):
            return value

        case .bytes(let value):
            return value

        case .date(let value):
            return value

        case .number(let number):

            switch number {
            case .int(let value):
                return value
            case .uint(let value):
                return value
            case .double(let value):
                return value
            }

        case .string(let value):
            return value

        case .null:
            return nil
        }
    }
}

Same-type requirement makes generic parameter 'Element' non-generic

When building the node module I get the following error regarding an Array extension in the FuzzyConverter.swift file.

/JSON/Packages/Node-2.0.0/Sources/Node/Fuzzy/FuzzyConverter.swift:21:40: error: same-type requirement makes generic parameter 'Element' non-generic

Any thoughts on how to resolve this? Am I missing an extension file from another project?

use composition for `...Convertible` protocols

Convertible protocols such as NodeConvertible should be typealiases for init + representable protocols composed together instead of separate protocols. This will help prevent bugs created by users separately conforming to init and representable in different extensions and getting errors conforming to convertible.

extension NodeInitializable should be public?

I'm trying to make a data type conform to NodeConvertible. NodeConvertible is made up of NodeInitializable and NodeRepresentable, where the method makeNode() is defined in NodeRepresentable, and the method init(node: Node, in context: Context) is defined in NodeInitializable.

NodeInitializable has a protocol extension which defines a default initializer, so that I should only need to implement makeNode(), if I'm understanding correctly. However, when I do this, my data type still doesn't conform to NodeConvertible.

I believe the problem is that the NodeInitializable extension should be public, but it isn't. Thus, my own data type in my project which imports Node can't see that there's actually a default implementation of the initializer already there. Is my analysis correct, and would you be willing to make that change?

EDIT: The other possibility is that the NodeInitializable extension actually only defines init(node: Node), and not init(node: Node, in context: Context), so my data type still needs to implement the latter.

makeNode(context: ...)

Currently makeNode(context: Context) requires some initialized object to be passed as a context.

It would be nice to pass a Type such as JSON or Model to Context, showing what type the Node is being used to create.

This way the method could be implemented like:

switch context {
case Model.self:
   return modelNode // for saving to db
case JSON.self:
   return jsonNode // for http response
}

I don't know how feasible this is, but this or something similar to this would be ideal.

Make a node with JSON

Hi,
I'm experiencing some problems creating a Node using an array of JSON.

Here is the code I'm using for make my life easier

struct JSONArray<Element: JSONRepresentable>: ResponseRepresentable {
    let elements: [Element]
    let key: String?
    
    init(_ elements: [Element], key: String? = nil) {
        self.elements = elements
        self.key = key
    }
    
    func makeResponse() throws -> Response {
        let elementsJSON = try elements.map { try $0.makeJSON() }
        if let key = key {
            let node = try Node(node: [
                key: elementsJSON.makeNode()
            ])
            
            return try JSON(node).makeResponse()
        } else {
            return try JSON(elementsJSON.makeNode()).makeResponse()
        }
    }
}

But I actually have to convert the array of my objects in array of JSON, then convert it to a node, encapsulate in a node and return the JSON as ResourceRepresentable ๐Ÿค”

See the original question here

Fuzzy get fails for [UInt8]

This is an older issue I forgot to report, but still happening with the latest versions of the framework. It's easiest to reproduce with Fluent, but the underlying issue is here.

Consider an entity that has a Bytes property inside, and its init(row:) initializer.

The linked file works, but if line 16 was written naively as one would expect to work:

content = try row.get("content")

A cryptic error is thrown instead:

[Node Error: Unable to convert 'Node(wrapped: [91, 49, 48, 48, 44, 49, 49, 55, 44, 49, 48, 57, 44, 49, 48, 57, 44, 49, 50, 49, 44, 52, 56, 44, 52, 56, 44, 52, 57, 93], context: MySQL.MySQLContext)' to 'UInt8' for path ''] [Identifier: Node.NodeError.unableToConvert]

Which suggests that for some dark reason, the function tried to convert the bytes SD into a single byte.

Build fails with Use of undeclared type 'ExpressibleByStringLiteral' extension Node: ExpressibleByStringLiteral

git clone a fresh copy of master and ran a build with 'swift build' which fails. Output follows.

xcodebuild -version
Xcode 8.0
Build version 8S174q

swift --version
Apple Swift version 3.0 (swiftlang-800.0.34.6 clang-800.0.33)
Target: x86_64-apple-macosx10.9

swift build
Compile Swift Module 'Node' (20 sources)
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Convertible/Sequence+Convertible.swift:23:33: error: use of undeclared type 'ExpressibleByStringLiteral'
extension Dictionary where Key: ExpressibleByStringLiteral, Value: NodeRepresentable {
^~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Core/Node+Literals.swift:1:17: error: use of undeclared type 'ExpressibleByNilLiteral'
extension Node: ExpressibleByNilLiteral {
^~~~~~~~~~~~~~~~~~~~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Core/Node+Literals.swift:7:17: error: use of undeclared type 'ExpressibleByBooleanLiteral'
extension Node: ExpressibleByBooleanLiteral {
^~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Core/Node+Literals.swift:13:17: error: use of undeclared type 'ExpressibleByIntegerLiteral'
extension Node: ExpressibleByIntegerLiteral {
^~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Core/Node+Literals.swift:19:17: error: use of undeclared type 'ExpressibleByFloatLiteral'
extension Node: ExpressibleByFloatLiteral {
^~~~~~~~~~~~~~~~~~~~~~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Core/Node+Literals.swift:25:17: error: use of undeclared type 'ExpressibleByStringLiteral'
extension Node: ExpressibleByStringLiteral {
^~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Core/Node+Literals.swift:39:17: error: use of undeclared type 'ExpressibleByArrayLiteral'
extension Node: ExpressibleByArrayLiteral {
^~~~~~~~~~~~~~~~~~~~~~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Core/Node+Literals.swift:45:17: error: use of undeclared type 'ExpressibleByDictionaryLiteral'
extension Node: ExpressibleByDictionaryLiteral {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Utilities/Errors.swift:13:56: error: use of undeclared type 'Error'
to type: T.Type) -> Error {
^~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Convertible/Sequence+Convertible.swift:23:33: error: use of undeclared type 'ExpressibleByStringLiteral'
extension Dictionary where Key: ExpressibleByStringLiteral, Value: NodeRepresentable {
^~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Core/Node+Literals.swift:1:17: error: use of undeclared type 'ExpressibleByNilLiteral'
extension Node: ExpressibleByNilLiteral {
^~~~~~~~~~~~~~~~~~~~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Core/Node+Literals.swift:7:17: error: use of undeclared type 'ExpressibleByBooleanLiteral'
extension Node: ExpressibleByBooleanLiteral {
^~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Core/Node+Literals.swift:13:17: error: use of undeclared type 'ExpressibleByIntegerLiteral'
extension Node: ExpressibleByIntegerLiteral {
^~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Core/Node+Literals.swift:19:17: error: use of undeclared type 'ExpressibleByFloatLiteral'
extension Node: ExpressibleByFloatLiteral {
^~~~~~~~~~~~~~~~~~~~~~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Core/Node+Literals.swift:25:17: error: use of undeclared type 'ExpressibleByStringLiteral'
extension Node: ExpressibleByStringLiteral {
^~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Core/Node+Literals.swift:39:17: error: use of undeclared type 'ExpressibleByArrayLiteral'
extension Node: ExpressibleByArrayLiteral {
^~~~~~~~~~~~~~~~~~~~~~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Core/Node+Literals.swift:45:17: error: use of undeclared type 'ExpressibleByDictionaryLiteral'
extension Node: ExpressibleByDictionaryLiteral {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Convertible/Sequence+Convertible.swift:23:33: error: use of undeclared type 'ExpressibleByStringLiteral'
extension Dictionary where Key: ExpressibleByStringLiteral, Value: NodeRepresentable {
^~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Core/Node+Literals.swift:1:17: error: use of undeclared type 'ExpressibleByNilLiteral'
extension Node: ExpressibleByNilLiteral {
^~~~~~~~~~~~~~~~~~~~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Core/Node+Literals.swift:7:17: error: use of undeclared type 'ExpressibleByBooleanLiteral'
extension Node: ExpressibleByBooleanLiteral {
^~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Core/Node+Literals.swift:13:17: error: use of undeclared type 'ExpressibleByIntegerLiteral'
extension Node: ExpressibleByIntegerLiteral {
^~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Core/Node+Literals.swift:19:17: error: use of undeclared type 'ExpressibleByFloatLiteral'
extension Node: ExpressibleByFloatLiteral {
^~~~~~~~~~~~~~~~~~~~~~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Core/Node+Literals.swift:25:17: error: use of undeclared type 'ExpressibleByStringLiteral'
extension Node: ExpressibleByStringLiteral {
^~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Core/Node+Literals.swift:39:17: error: use of undeclared type 'ExpressibleByArrayLiteral'
extension Node: ExpressibleByArrayLiteral {
^~~~~~~~~~~~~~~~~~~~~~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Core/Node+Literals.swift:45:17: error: use of undeclared type 'ExpressibleByDictionaryLiteral'
extension Node: ExpressibleByDictionaryLiteral {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Number/Number.swift:140:24: error: use of undeclared type 'ExpressibleByIntegerLiteral'
extension Node.Number: ExpressibleByIntegerLiteral {
^~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Number/Number.swift:146:24: error: use of undeclared type 'ExpressibleByFloatLiteral'
extension Node.Number: ExpressibleByFloatLiteral {
^~~~~~~~~~~~~~~~~~~~~~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Utilities/Errors.swift:13:56: error: use of undeclared type 'Error'
to type: T.Type) -> Error {
^~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Core/Node+Literals.swift:1:17: error: use of undeclared type 'ExpressibleByNilLiteral'
extension Node: ExpressibleByNilLiteral {
^~~~~~~~~~~~~~~~~~~~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Core/Node+Literals.swift:7:17: error: use of undeclared type 'ExpressibleByBooleanLiteral'
extension Node: ExpressibleByBooleanLiteral {
^~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Core/Node+Literals.swift:13:17: error: use of undeclared type 'ExpressibleByIntegerLiteral'
extension Node: ExpressibleByIntegerLiteral {
^~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Core/Node+Literals.swift:19:17: error: use of undeclared type 'ExpressibleByFloatLiteral'
extension Node: ExpressibleByFloatLiteral {
^~~~~~~~~~~~~~~~~~~~~~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Core/Node+Literals.swift:25:17: error: use of undeclared type 'ExpressibleByStringLiteral'
extension Node: ExpressibleByStringLiteral {
^~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Core/Node+Literals.swift:39:17: error: use of undeclared type 'ExpressibleByArrayLiteral'
extension Node: ExpressibleByArrayLiteral {
^~~~~~~~~~~~~~~~~~~~~~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Core/Node+Literals.swift:45:17: error: use of undeclared type 'ExpressibleByDictionaryLiteral'
extension Node: ExpressibleByDictionaryLiteral {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Convertible/Sequence+Convertible.swift:23:33: error: use of undeclared type 'ExpressibleByStringLiteral'
extension Dictionary where Key: ExpressibleByStringLiteral, Value: NodeRepresentable {
^~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Convertible/Sequence+Convertible.swift:23:33: error: use of undeclared type 'ExpressibleByStringLiteral'
extension Dictionary where Key: ExpressibleByStringLiteral, Value: NodeRepresentable {
^~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Core/Node+Literals.swift:1:17: error: use of undeclared type 'ExpressibleByNilLiteral'
extension Node: ExpressibleByNilLiteral {
^~~~~~~~~~~~~~~~~~~~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Core/Node+Literals.swift:7:17: error: use of undeclared type 'ExpressibleByBooleanLiteral'
extension Node: ExpressibleByBooleanLiteral {
^~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Core/Node+Literals.swift:13:17: error: use of undeclared type 'ExpressibleByIntegerLiteral'
extension Node: ExpressibleByIntegerLiteral {
^~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Core/Node+Literals.swift:19:17: error: use of undeclared type 'ExpressibleByFloatLiteral'
extension Node: ExpressibleByFloatLiteral {
^~~~~~~~~~~~~~~~~~~~~~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Core/Node+Literals.swift:25:17: error: use of undeclared type 'ExpressibleByStringLiteral'
extension Node: ExpressibleByStringLiteral {
^~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Core/Node+Literals.swift:39:17: error: use of undeclared type 'ExpressibleByArrayLiteral'
extension Node: ExpressibleByArrayLiteral {
^~~~~~~~~~~~~~~~~~~~~~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Core/Node+Literals.swift:45:17: error: use of undeclared type 'ExpressibleByDictionaryLiteral'
extension Node: ExpressibleByDictionaryLiteral {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Convertible/Sequence+Convertible.swift:23:33: error: use of undeclared type 'ExpressibleByStringLiteral'
extension Dictionary where Key: ExpressibleByStringLiteral, Value: NodeRepresentable {
^~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Core/Node+Literals.swift:1:17: error: use of undeclared type 'ExpressibleByNilLiteral'
extension Node: ExpressibleByNilLiteral {
^~~~~~~~~~~~~~~~~~~~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Core/Node+Literals.swift:7:17: error: use of undeclared type 'ExpressibleByBooleanLiteral'
extension Node: ExpressibleByBooleanLiteral {
^~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Core/Node+Literals.swift:13:17: error: use of undeclared type 'ExpressibleByIntegerLiteral'
extension Node: ExpressibleByIntegerLiteral {
^~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Core/Node+Literals.swift:19:17: error: use of undeclared type 'ExpressibleByFloatLiteral'
extension Node: ExpressibleByFloatLiteral {
^~~~~~~~~~~~~~~~~~~~~~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Core/Node+Literals.swift:25:17: error: use of undeclared type 'ExpressibleByStringLiteral'
extension Node: ExpressibleByStringLiteral {
^~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Core/Node+Literals.swift:39:17: error: use of undeclared type 'ExpressibleByArrayLiteral'
extension Node: ExpressibleByArrayLiteral {
^~~~~~~~~~~~~~~~~~~~~~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Core/Node+Literals.swift:45:17: error: use of undeclared type 'ExpressibleByDictionaryLiteral'
extension Node: ExpressibleByDictionaryLiteral {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Convertible/Sequence+Convertible.swift:23:33: error: use of undeclared type 'ExpressibleByStringLiteral'
extension Dictionary where Key: ExpressibleByStringLiteral, Value: NodeRepresentable {
^~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Core/Node+Literals.swift:1:17: error: use of undeclared type 'ExpressibleByNilLiteral'
extension Node: ExpressibleByNilLiteral {
^~~~~~~~~~~~~~~~~~~~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Core/Node+Literals.swift:7:17: error: use of undeclared type 'ExpressibleByBooleanLiteral'
extension Node: ExpressibleByBooleanLiteral {
^~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Core/Node+Literals.swift:13:17: error: use of undeclared type 'ExpressibleByIntegerLiteral'
extension Node: ExpressibleByIntegerLiteral {
^~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Core/Node+Literals.swift:19:17: error: use of undeclared type 'ExpressibleByFloatLiteral'
extension Node: ExpressibleByFloatLiteral {
^~~~~~~~~~~~~~~~~~~~~~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Core/Node+Literals.swift:25:17: error: use of undeclared type 'ExpressibleByStringLiteral'
extension Node: ExpressibleByStringLiteral {
^~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Core/Node+Literals.swift:39:17: error: use of undeclared type 'ExpressibleByArrayLiteral'
extension Node: ExpressibleByArrayLiteral {
^~~~~~~~~~~~~~~~~~~~~~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Core/Node+Literals.swift:45:17: error: use of undeclared type 'ExpressibleByDictionaryLiteral'
extension Node: ExpressibleByDictionaryLiteral {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Number/Number.swift:140:24: error: use of undeclared type 'ExpressibleByIntegerLiteral'
extension Node.Number: ExpressibleByIntegerLiteral {
^~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Number/Number.swift:146:24: error: use of undeclared type 'ExpressibleByFloatLiteral'
extension Node.Number: ExpressibleByFloatLiteral {
^~~~~~~~~~~~~~~~~~~~~~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Utilities/Errors.swift:13:56: error: use of undeclared type 'Error'
to type: T.Type) -> Error {
^~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Convertible/Sequence+Convertible.swift:23:33: error: use of undeclared type 'ExpressibleByStringLiteral'
extension Dictionary where Key: ExpressibleByStringLiteral, Value: NodeRepresentable {
^~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Core/Node+Literals.swift:1:17: error: use of undeclared type 'ExpressibleByNilLiteral'
extension Node: ExpressibleByNilLiteral {
^~~~~~~~~~~~~~~~~~~~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Core/Node+Literals.swift:7:17: error: use of undeclared type 'ExpressibleByBooleanLiteral'
extension Node: ExpressibleByBooleanLiteral {
^~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Core/Node+Literals.swift:13:17: error: use of undeclared type 'ExpressibleByIntegerLiteral'
extension Node: ExpressibleByIntegerLiteral {
^~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Core/Node+Literals.swift:19:17: error: use of undeclared type 'ExpressibleByFloatLiteral'
extension Node: ExpressibleByFloatLiteral {
^~~~~~~~~~~~~~~~~~~~~~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Core/Node+Literals.swift:25:17: error: use of undeclared type 'ExpressibleByStringLiteral'
extension Node: ExpressibleByStringLiteral {
^~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Core/Node+Literals.swift:39:17: error: use of undeclared type 'ExpressibleByArrayLiteral'
extension Node: ExpressibleByArrayLiteral {
^~~~~~~~~~~~~~~~~~~~~~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Core/Node+Literals.swift:45:17: error: use of undeclared type 'ExpressibleByDictionaryLiteral'
extension Node: ExpressibleByDictionaryLiteral {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/shanec/Dropbox/wrk/git/external/mysql/mysql-0.3.1/node/Sources/Node/Convertible/Sequence+Convertible.swift:33:67: error: default argument value of type 'T.Type' cannot be converted to type 'T.Type'
public func converted<T: NodeInitializable>(to type: T.Type = T.self) throws -> T {
^
:0: error: build had 1 command failures

Use keypath syntax

Can the Row.get() and Row.set() methods be modified to take a keypath syntax instead of requiring a string?

Explicitly use int64 value of StructuredData

Currently StructuredData.Number is limited to int, uint and double, which is perfectly fine for people who use 32 bit integers and 64 bit integers on 64 bit platforms.

But if you are on a 32 bit platform and you expect aStructuredData value to be e.g. an unsigned 64 bit integer, you will probably have some unexpected silent problems as Int and UInt are limited to 32 bits andStructuredData will return Int.max for integers bigger than 32 bits.

I am currently working on a vapor library for Telegram chatbots and they have stated in their documentation that some values are actually bigger than 32 bits which means I must ignore 32 bit platforms and add a warning to the README that this library should not be used on 32 bit platforms.

What do you guys think about that? Do we want to ignore 32 bit platforms as they already become extinct or do we want to add support for explicit int64 and uint64 values inside StructuredData.Number?

Reference (Number.swift file in this library):
Number.swift

NodeError 3.1

extension NodeError: CustomStringConvertible {
    public var description: String {
        let nodeDescription: String

        if let node = node {
            nodeDescription = "\(node)"
        } else {
            nodeDescription = "nil"
        }

        let keyDescription: String
        if let key = key {
            keyDescription = key.description
        } else {
            keyDescription = "''"
        }

        return "Expected \(expectation) got \(nodeDescription) for key \(keyDescription)"
    }
}

This doesn't create warnings in Swift 3.1

Docs?

I would appreciate some documentation of the new Node. I'm reading through then code and I'm not able to understand every choice yet. For example, what's the purpose of Fuzzy exactly? Why are Node and StructuredData separate things while they also seem to be tightly coupled? IIRC in the previous version there used to be lots of converted functions everywhere and now I don't see them anymore. Did you guys find a more clean / flexible way to cover that functionality or did you just drop part of that functionality.

extract failing for optionals

let string: String? = node.extract("string")

This appears to be throwing an error if the string is missing. Expected behavior would be to assign nil.

NodeRepresentable string subscript setter

Would it be possible to set subscript on node object with something NodeRepresentable?

data["password"] = try hash.make(password).makeNode()

Removing the need to specify .makeNode() here would be nice.

Converting node object to string

Is there a reliable way to convert all (or most) node instances to a human textual representation? All the methods I've tried leave too many escape characters or type information in the string...

For example, node.toJSON().object produces [\"name\": JSON.JSON(node: Node.Node.string(\"name\"))], however I'd like it to just be ["name" : "name"]

Any ideas?

DateFormatters aren't compatible due to relying on defaults

In Date+Convertible.swift, some DateFormatters are defined, but they're not compatible with themselves.
In case for iso8601 the locale is set to en_US_POSIX but the others aren't, which leads to wrong conversion between dates. For example I use Persian calendar in my mac, when trying to save a date, it's ok in DB. but when I try to create iso8601 format for JSON, it gives an invalid date (2017 yields in 2638).

better no value found errors

Feature request for Node 3.0.

It would be very nice if node errors included their keys. This will probably take some work to implement since we will need to pass the keys around to different node objects as we recurse. We can probably look into how Encodable/Decodable do it with the keyed container API.

Example of current non-helpful errors:

[Node Error: No value found at path '', expected 'String'] [Identifier: Node.NodeError.unableToConvert] [Possible Causes: typo in key path, underlying type is not convertible, unexpected '.' being interpreted as path instead of key] [Suggested Fixes: called `get(...)` on a key or key path that does not exist in the data, the data being parsed is missing required values or is incorrectly formatted, found unconvertible data, e.g., got a string of letters when an integer is required, if you have keys containing a '.' that shouldn't be interpreted as a path, use 'DotKey("actual.key")']

For code:

hosting.gitURL = try req.data.get("gitURL")

This should say something like "no value found at path gitURL". Would be even better if it suggested some possible fixes (for example there was only one other key in the dictionary, named "gitUrl", etc).

Why can makeNode throw an error? When would that ever happen?

I can totally see why the init of NodeInitializable needs to be able to throw, because you can never know if the Node you'll get is a valid Node. However, I don't see why the makeNode of NodeRepresentable should be able to throw.

If you make a type that conforms to NodeRepresentable then you know your variables should be compatible with the possible types of Node right?

If we can't think of a use-case where throwing is necessary then I vote to remove that. The less I have to worry about potentially throwing methods the better imo.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.