octet-stream / dinky

JavaScript bindings for Philomena JSON API. Supports sites such as Derpibooru and Furbooru.
https://www.npmjs.com/package/dinky.js
MIT License
7 stars 3 forks source link

Port entire project to TypeScript and next major release #14

Closed octet-stream closed 3 years ago

octet-stream commented 3 years ago

Further information covers the process of next major version development. Here's my plan for the 2.x release. Folloing list may change as I work on the release:

  1. Since I decided to finally learn TypeScript, I also think is that TS port for dinky would be a great idea, it might improve developers experience and TS support in general.

  2. The 2.x version will also bring API changes: chainable API will be removed in favour of individual imports for each API request class. Let's say you want to request and image from Derpibooru API. In 1.x you had to do it like so:

    import dinky from "dinky.js"
    
    dinky().images(0).then(console.log)

    Here's the same example, but for 2.x:

    import {Images} from "dinky.js"
    
    const images = new Images()
    
    images.getById(0).then(console.log) // I need pictures! Pictures of ponies!

    Or you can import the whole package using import * as ns from "package" syntax:

    import * as dinky from "dinky.js"
    
    new dinky.Images().getById(0).then(console.log)
  3. By default, dinky will now use isomorphic-fetch to make requests, which should bring an ability to use it in browser (not sure if I will ship a bundle for that use case, but who knows)

  4. You'll be able to bring your own fetch-compatible function to make requests to the API:

    import fetch from "node-fetch"
    
    import {Search} from "dinky.js"
    
    const search = new Search({linkOptions: {fetch}})
    
    search.query(["princess luna", "safe", "for whom the sweetie belle toils"])
    .then(console.log)
    
    // You also can set a fetch function in per-request options like so:
    search.query(["artist:rainbow", "safe"]).exec({fetchOptions: {fetch}})
    .then(console.log)
  5. From 2.x version dinky will support custom base URL's for requests, so you will able to use it for prolomena-compatible websites

    import {Search} from "dinky.js"
    
    // Now every request from this Search instance will be sent to furbooru instead of derpibooru
    const search = new Search({url: "https://furbooru.org"})
    
    search.query(["artist:miles-df", "safe", "spyro the dragon (spyro)"])
    .then(console.log)
  6. The ESM support has been improved. Not only the package has ESM entry point, but it exports every class individually using named exports:

    import {Search, Comment, Tag, User, Image, Request} from "dinky.js" // etc...
    
    // or
    import * as dinky from "dinky.js" // Will import every dinky.js class
    • While dinky has improved ESM support, it also keeps CommonJS version of its modules for backward compatibility reasons
      
      const {Search, Comment, Tag, User, Image, Request} = require("dinky.js")

    // or const dinky = require("dinky.js")

codecov[bot] commented 3 years ago

Codecov Report

Merging #14 (c17b6c8) into master (7851dce) will not change coverage. The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##            master       #14    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files           21        17     -4     
  Lines         1155       646   -509     
  Branches       122        86    -36     
==========================================
- Hits          1155       646   -509     
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
lib/Comments.ts 100.00% <100.00%> (ø)
lib/Entities.ts 100.00% <100.00%> (ø)
lib/Images.ts 100.00% <100.00%> (ø)
lib/Request.ts 100.00% <100.00%> (ø)
lib/Search.ts 100.00% <100.00%> (ø)
lib/Tags.ts 100.00% <100.00%> (ø)
lib/User.ts 100.00% <100.00%> (ø)
lib/__helper__/createNoopLink.ts 100.00% <100.00%> (ø)
lib/util/NetworkError.ts 100.00% <100.00%> (ø)
lib/util/Query.ts 100.00% <100.00%> (ø)
... and 23 more

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 7851dce...c17b6c8. Read the comment docs.