Skip to content

Migrating from 4.x to 5.x

Jamie Holding edited this page Jun 13, 2019 · 10 revisions

The API has had a significant overhaul for 5.x.

Key changes:

  • No longer back-compiling for older versions of Node.JS
  • Key functions are now only available as Promises
    • Legacy (err, data) format now removed
  • Requires a local SQLite database
    • This will be setup automatically in Node's current working directory. Can also be supplied a custom location
    • Based on analysing projects using this library, no known projects are utilising caching
    • Because caching isn't being used, theme park servers are being queried significantly more than is needed by users of this library
    • Recent changes to the Walt Disney World API also requires a consistent park data state to be maintained
  • Stricter Park Instantiation
    • A common pattern seen in projects using themeparks is to re-construct the park object every single time wait data is requested, rather than construct once and keep in-memory
    • Re-constructing park objects will slow down fetching updates, as the library will pointlessly re-fetch all park data every time it is re-constructed
    • This is the fault of an over-simplified README that doesn't teach correct JavaScript usage
    • In 5.x, instantiating the same park multiple times will throw an error

Method/Variable Changes

Previously (themeparks 4.x) Now (themeparks 5.x)
Settings.ProxyURL Please see "Using a Proxy" below
Settings.DefaultCacheTime Settings.DefaultCacheLength
Settings.DefaultCacheWaitTimesLength Settings.CacheWaitTimesLength
Settings.DefaultCacheOpeningTimesLength Settings.CacheOpeningTimesLength
Park.TimeNow() Replaced with Moment object Park.Now - use Park.Now.format("YYYY-MM-DDTHH:mm:ssZ") for old behaviour
Park.DateNow() Replaced with Moment object Park.Now - use Park.Now.format("YYYY-MM-DD") for old behaviour
Park.Location All methods and properties on this object are now on the Park object itself. Eg. replace Park.Location.Longitude with Park.Longitude
Park.Location.toString() Replaced with Park.LocationString

Using a Proxy

Beforehand, you would set a proxy URL using themeparks.Settings.ProxyURL. This caused the library to create a new proxy agent for every HTTP request, which is inefficient. This also has the benefit of not having to include the proxy libraries as a dependency of themeparks, keeping the library as small as possible for users who don't need proxy support.

In 5.x.x, you must now make the proxy agent yourself and pass it to each park object you create as part of it's constructor.

For example:

const SocksProxy = require("socks-proxy-agent");
const MyProxy = new SocksProxy("socks://socks-proxy-host", true);
const Park = new themeparks.Parks.ThorpePark({
    proxyAgent: MyProxy
});
Clone this wiki locally