kabiroberai / node-swift

Create Node modules in Swift
MIT License
414 stars 10 forks source link

Issue with NodeValue, documentation maybe ? #20

Open Nytrm opened 1 month ago

Nytrm commented 1 month ago

Hi, great project but the example seems just a little minimal.

I am trying to access the iTunesLibrary from node but i am not sure how to map the values/types to return types. In this example its just a string that does not seem to work for me.

no exact matches in call to initializer return NodeValue(self.library.applicationVersion)

my plan was to map playlist but i got stuck with just the string. https://developer.apple.com/documentation/ituneslibrary/itlibrary/allplaylists


import iTunesLibrary
import NodeAPI

@NodeClass final class iTunesLibraryClass {

    private let library: ITLibrary

    @NodeActor
    @NodeConstructor init() throws {
        library = try ITLibrary(apiVersion: "1.0")
    }

    @NodeActor
    @NodeMethod func allPlaylists() throws -> NodeValueConvertible {
        return NodeValue(self.library.applicationVersion)
    }
}

#NodeModule(exports: ["iTunesLibrary": iTunesLibraryClass.deferredConstructor])`

Any documentation or examples that i can check out how this works ?
kabiroberai commented 4 weeks ago

Could you try return self.library.applicationVersion? iirc String conforms to NodeValueConvertible. Let me know if that works.

Regarding docs, definitely agree that there's a lot of room for improvement. I'd ideally like to create a DocC catalog but haven't got around to it yet due to a lack of time. It's on the roadmap though.