Skip to content

Releases: mswjs/data

v0.8.0

17 Nov 12:28
Compare
Choose a tag to compare

Features

  • Supports nullable properties (#143).
import { factory, primaryKey, nullable } from '@mswjs/data'

const db = factory({
  user: {
    id: primaryKey(String),
    firstName: String,
    age: nullable(Number)
  }
})

db.create({ firstName: null }) // TypeError
db.create({ age: null }) // OK!

v0.7.2

16 Nov 11:46
Compare
Choose a tag to compare

Bug fixes

  • Fixes an issue when the model properties with dots (.) in them were treated as nested properties (#152).

v0.7.1

05 Nov 11:06
Compare
Choose a tag to compare

Features

  • Adds in and notIn number comparators (#150).
import { factory, primaryKey } from '@mswjs/data'

const data = factory({
  user: {
    id: primaryKey(String),
    age: Number
  }
})

data.user.findMany({
  where: {
    age: { in: [18, 24, 32] }
  }
})

Note that in/notIn act as Array.prototype.includes and do not represent a permitted range of numbers. Use between/notBetween to query by range.

Bug fixes

  • Fixes an issue when a model with a numeric primary key wasn't queryable via the generated REST API request handlers (#154, #155).

v0.7.0

21 Oct 14:30
Compare
Choose a tag to compare

Bug fixes

  • Fixes an issue that prevented multiple entity properties to be updated simultaneously (#136).
  • Fixes an issue that resulted in "TypeError: Cannot read property 'modelName' of null" exception when updating a relational property that had no initial value (#137, #138).

Internal

  • Removes the InternalEntity class.
  • Entities now store internal properties ("type", "primaryKey") using Symbol (#135).
  • Relations are now initialized during model parsing regardless if they have initial values (#138).

v0.6.0

14 Oct 10:59
Compare
Choose a tag to compare

Breaking changes

  • Relational properties can no longer be updated using compatible plain objects (#130). Always use an entity reference when updating a relational property.
const db = factory({
  user: {
    id: primaryKey(String),
    country: oneOf('country'),
  },
  country: {
    code: primaryKey(String),
  },
})

db.user.update({
  where: {
    id: { equals: 'user-1' }
  },
  data: {
    // Always provide a reference
    // to an existing entity.
    country: db.country.create({
      code: 'us'
    })
  }
})

Features

  • Model definition now supports nested objects and arrays (#113).
const db = factory({
  user: {
    id: primaryKey(String),
    address: {
      billing: {
        street: String,
        phoneNumbers: [],
        country: oneOf('country'),
      },
    },
  },
})
  • Supports updating relational properties (#126).

Bug fixes

  • Fixes an issue that prevented an update of a property if it wasn't specified when the entity was created (#130).
  • Fixes an issue that broke the querying by an entity's property if that property has no value (#130).
db.user.create({ id: 'abc-123' })

// The following query would throw.
db.user.findFirst({ where: { anotherProperty: { equals: 'value' } } })
  • Fixes an issue that would throw an exception when validating a unique relational value if that value is currently assigned to the entity that's being operated on (must exclude the current entity from the validation query) (#130).

v0.5.1

17 Aug 12:22
Compare
Choose a tag to compare

Bug fixes

  • Fixes an issue that resulted in a Possible EventEmitter memory leak detected warning when using the library in a browser (#112, #115). Database events (create, update, delete) are now attached once, when the factory is called.

v0.5.0

28 Jul 15:25
Compare
Choose a tag to compare

Features

  • You can now sort the queries entities using the orderBy option (#103).

v0.4.1

20 Jul 14:19
Compare
Choose a tag to compare

Bug fixes

  • Fixes an issue that resulted in both take and skip/cursor to be required in order to enable entity pagination in the generated request handlers (#105). It's enough to supply a single query parameter now to receive the paginated response.

v0.4.0

29 Jun 10:00
Compare
Choose a tag to compare

Features

  • Adds a .toSchema() method on a model factory to generate a GraphQL schema (#96).
import { factory, primaryKey } from '@mswjs/data'

const db = factory({
  user: {
    id: primaryKey(() => 'abc-123')
  }
})

const graphqlSchema = db.toSchema()
  • Numbers can be used as primary keys.

  • Supports filtering entities by their properties in request query parameters (#69):

import { setupServer } from 'msw/node'
import { factory, primaryKey } from '@mswjs/data'

const db = factory({
  user: {
    id: primaryKey(() => 'abc-123')
  }
})

const server = db.user.toHandlers('rest')
fetch('/users?id=abc-123')

Bug fixes

  • Fixes an issue when dropping a database and referencing a db.*.getAll() on a model that had a relational property raised an exception (#101).

v0.3.0

26 Apr 22:23
Compare
Choose a tag to compare

Breaking changes

  • Specifying relational values is no longer mandatory when creating entities (#79).
  • The library no longer exposes its internal properties (i.e. __type, __primaryKey) on the returned entities (#57, #67).
  • The return type of calling .findFirst() with a query that has no matching entity now returns null (#76, #67).

Bug fixes

  • Fixes an issue that resulted in relational properties not being enumerable (#78, #67, #84).