Skip to content

Releases: 42BV/mad-spring-connect

v4.3.0

11 Jan 13:29
Compare
Choose a tag to compare
  • feat: the id field of a makeResource has been made generic. 62f670e

This allows the id field to become a string for example:

class Pokemon extends makeResource<Pokemon, string>('/api/pokemon') {
    public id?: string;
    public name!: string;
    public types!: string[];
  }

  const pokemon = new Pokemon();

  // This should now work because the type of ID is now a string.
  pokemon.id = 'a-unique-uu-id-for-example';
  pokemon.name = 'bulbasaur';
  pokemon.types = ['poison', 'grass'];

v4.2.1...v4.3.0

v4.2.1

30 Nov 15:03
Compare
Choose a tag to compare
  • chore: upgraded all packages, removed travis for GitHub actions. c6c640c

v4.2.0...v4.2.1

v4.2.0

19 Jun 09:14
Compare
Choose a tag to compare
  • feat: allow anything as the payload to put / post and get. 0951427

v4.1.0...v4.2.0

v4.1.0

18 Oct 12:45
Compare
Choose a tag to compare

feat: It is now possible to have a custom mapper.

Resource now accepts an configuration object, which can contain a
custom mapper. With the custom mapper it is possible to dynamically
add properties and to convert them.

For example:

class Pokeball extends makeResource<Pokeball>({
  baseUrl: '/api/pokeball',
  mapper: pokeballMapper,
}) {
  public id?: number;

  /*
    In the actual JSON response pokemon is simply an object.
    But our custom mapper makes sure it will also get mapped.
  */
  public pokemon!: Pokemon;

  /*
    Does not really exist on the back-end but is filled by the
    custom mapper.
  */
  public retrievedAt!: Date;
}

function pokeballMapper(json: any, Class: { new (): Pokeball }): Pokeball {
  const pokeball = makeInstance(Class, json);
  /* Add a completely new field */
  pokeball.retrievedAt = new Date();

  /* Make the fetched pokemon an actual instance of Pokemon */
  pokeball.pokemon = makeInstance(Pokemon, pokeball.pokemon);

  return pokeball;
}

4.0.0

12 Sep 13:06
Compare
Choose a tag to compare

makeResource

The makeResource should now be used like this:

  class Pokemon extends makeResource<Pokemon>('api/pokemon')

Instead of the old way:

  class Pokemon extends makeResource('api/pokemon')<Pokemon>

By putting the generic directly after makeResource TypeScript actually
recognizes the return types correcty. Before calling Pokemon.one would
give back a Promise<unknown> instead of Promise<Pokemon>.
This way we no longer need to tell TypeScript the type when
using it:

const pokemon: Pokemon = await Pokemon.one(1);

And we can instead we can simply do:

// The type of pokemon is now correctly inferred as Pokemon
const pokemon = await Pokemon.one(1);

findeOne

The findOne method now returns a Promise of T or void. This
way TypeScript recognizes the return type better, it did not understand
null correctly, and acted as if it was a T. Now TypeScript will make
you check if you actually have a type T or empty. This was actually a
bug discovered by the better type inference.

Export of Resource

No longer exporting a Resource class definition. It got out of
sync really easily with the actual return value, so it has been
removed.

3.3.0

12 Sep 07:54
Compare
Choose a tag to compare

The one method now accepts a string for the id as well.

v3.2.0

12 Sep 07:54
Compare
Choose a tag to compare

The post, patch and put payload parameter can now be a FormData. Useful for totally controlling the body for example when uploading.

Updated to TypeScript 3.5.3 had to make QueryParams the correct type as needed by query-string's stringify method.

Exposed Method, MiddlewareDetailInfo, QueryParams in the index.

v3.1.2

06 Aug 09:33
Compare
Choose a tag to compare

Renamed to @42.nl/spring-connect

v3.1.0

17 Jun 07:48
Compare
Choose a tag to compare

Added findOne method to Resource, it allows you to search for a single resource.

See: https://42bv.github.io/mad-spring-connect/#searching-for-one-pokemon

v3.0.0

17 Jun 07:46
Compare
Choose a tag to compare

Moved to TypeScript and changed makeResource: it creates a class now which you can extend.