GithubHelp home page GithubHelp logo

infinum / datx Goto Github PK

View Code? Open in Web Editor NEW
137.0 7.0 6.0 31 MB

DatX is an opinionated JS/TS data store. It features support for simple property definition, references to other models and first-class TypeScript support.

Home Page: https://datx.dev

License: MIT License

TypeScript 95.49% JavaScript 4.01% CSS 0.48% Shell 0.01%
mobx data state-management data-store model collection prop hacktoberfest open-source javascript

datx's Introduction

DatX

Unit tests

DatX is an opinionated JS/TS data store. It features support for simple property definition, references to other models and first-class TypeScript support.


Basic usage

import { Collection, Model, Field } from '@datx/core';

class Person extends Model {
  public static type = 'person'; // Unique name of the model class

  @Field()
  public name!: string; // A normal property without a default value

  @Field()
  public surname!: string;

  @Field({ toOne: Person })
  public spouse?: Person; // A reference to a Person model

  public get fullName() {
    // Standard JS getter
    return `${this.name} ${this.surname}`;
  }
}

class AppData extends Collection {
  public static types = [Person]; // A list of models available in the collection
}

const store = new AppData();
const john = store.add(new Person({ name: 'John', surname: 'Smith' })); // Add a model instance to the store
const jane = store.add({ name: 'Jane', surname: 'Smith', spouse: john }, Person); // Add a model to the store

Getting started

npm install --save @datx/core

Polyfilling

The lib makes use of the following features that are not yet available everywhere. Based on your browser support, you might want to polyfill them:

How to add the polyfills.

Concepts

The library contains two main classes - Model and Collection.

A collection contains models of any kind (they should however be listed in the types property), while a model can be in a single collection (but doesn't need to be in any).

Models also include some useful methods and properties, but if they're in collision with your data/logic, you can use a PureModel class.

Mixins

Mixins are additional plugins that can enhance the regular models and collections. Available mixins:

  • withActions (model) - Adds some helper methods to the model - already included in the Model class, but not in the PureModel class
  • withMeta (model) - Adds some helpful meta data to the model - already included in the Model class, but not in the PureModel class
  • withPatches (model, collection) - Adds patch support to models and collections
  • datx-jsonapi (model, collection and view) - Adds the JSON API features to the model, collection and view

To check out what are the planed future mixins, check out the issues.

Want to make your own mixin? Check out the guide.

API reference

Troubleshooting

Having issues with the library? Check out the troubleshooting page or open an issue.


Build Status

License

The MIT License

Credits

datx is maintained and sponsored by Infinum.

datx's People

Contributors

akaguny avatar danijelbuhin avatar danipavic avatar darkokukovec avatar darrac avatar dependabot[bot] avatar dominiclisjak avatar erbenos avatar fvoska avatar greenkeeper[bot] avatar isbatak avatar kristijanbambir avatar lovro-bikic avatar nanyuantingfeng avatar safo6m avatar svobik7 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

datx's Issues

An in-range update of datx-utils is breaking the build 🚨

Version 0.11.2 of datx-utils was just published.

Branch Build failing 🚨
Dependency datx-utils
Current Version 0.11.0
Type dependency

This version is covered by your current version range and after updating it in your project the build failed.

datx-utils is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details
  • continuous-integration/travis-ci/push The Travis CI build failed Details

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on all branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because it uses your CI build statuses to figure out when to notify you about breaking changes.

Since we didn’t receive a CI status on the greenkeeper/initial branch, it’s possible that you don’t have CI set up yet. We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.

If you have already set up a CI for this repository, you might need to check how it’s configured. Make sure it is set to run on all new branches. If you don’t want it to run on absolutely every branch, you can whitelist branches starting with greenkeeper/.

Once you have installed and configured CI on this repository correctly, you’ll need to re-trigger Greenkeeper’s initial pull request. To do this, please delete the greenkeeper/initial branch in this repository, and then remove and re-add this repository to the Greenkeeper App’s white list on Github. You'll find this list on your repo or organization’s settings page, under Installed GitHub Apps.

An in-range update of @types/node is breaking the build 🚨

Version 8.5.4 of @types/node was just published.

Branch Build failing 🚨
Dependency @types/node
Current Version 8.5.3
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

@types/node is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Add migration guide

Gudes for:

  • datx CompatModel and CompatCollection usage
  • mobx-collection-store -> datx
  • mobx-jsonapi-store -> datx-jsonapi

Example on adding model to collection?

Would appreciate a more complete example on this common workflow:

  1. Add new instance of model to collection (assuming collection is observable)
  2. Save model to remote server
  3. Retrieve newly-added model id.

I have tried doing this (Client extends jsonapi(Model):

const model = new Client(newClient);
model.save().then(response => {
    console.log(response);
});

but the response would be a Client model object with no id, while my network log would show a 201 response with json body that contains id.

Additionally, I'm not clear on the flow of this library, do you:

const newModel = collection.add({rawData}, myModel);
newModel.save() // how do I get the newly-saved id?

or

const newModel = new myModel(rawData);
newModel.save().then(response => {
    collection.add(response); 
});

Either doesn't work as I expected: without an id, I can't optimistically update my ui on the browser side without fetchAll(Client), since fetch(response) without an id will effectively fetch all.

An in-range update of nock is breaking the build 🚨

Version 9.4.2 of nock was just published.

Branch Build failing 🚨
Dependency nock
Current Version 9.4.1
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

nock is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details

Release Notes v9.4.2

9.4.2 (2018-07-10)

Bug Fixes

  • Replaced util._extend with Object.assign due to deprecated since node v6. (7fd2329)
Commits

The new version differs by 1 commits.

  • 7fd2329 fix: Replaced util._extend with Object.assign due to deprecated since node v6.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Add examples

  • datx
    • models
    • references
  • datx-jsonapi
    • collection/model setup
    • network config
    • network examples

Better jsonapi mixin documentation

  • Network configuration
  • Network usage
  • JSON API spec compliance
  • Mixin docs
    • Basic configuration
    • Model
    • Collection
    • Response
    • Config
    • Utils
    • TypeScript Interfaces

mobx strict-mode error on save

mobx.module.js:2655 Uncaught (in promise) Error: [mobx] Since strict-mode is enabled, changing observed observable values outside actions is not allowed. Please wrap the code in an `action` if this change is intended. Tried to modify: [email protected]

We are seeing the above error when saving changes to a model. I am not super experienced with mobx, but it seems like https://github.com/infinum/datx/blob/master/packages/datx-jsonapi/src/NetworkUtils.ts#L368 isn't marked as an action anywhere?

Version 10 of node.js has been released

Version 10 of Node.js (code name Dubnium) has been released! 🎊

To see what happens to your code in Node.js 10, Greenkeeper has created a branch with the following changes:

  • Added the new Node.js version to your .travis.yml

If you’re interested in upgrading this repo to Node.js 10, you can open a PR with these changes. Please note that this issue is just intended as a friendly reminder and the PR as a possible starting point for getting your code running on Node.js 10.

More information on this issue

Greenkeeper has checked the engines key in any package.json file, the .nvmrc file, and the .travis.yml file, if present.

  • engines was only updated if it defined a single version, not a range.
  • .nvmrc was updated to Node.js 10
  • .travis.yml was only changed if there was a root-level node_js that didn’t already include Node.js 10, such as node or lts/*. In this case, the new version was appended to the list. We didn’t touch job or matrix configurations because these tend to be quite specific and complex, and it’s difficult to infer what the intentions were.

For many simpler .travis.yml configurations, this PR should suffice as-is, but depending on what you’re doing it may require additional work or may not be applicable at all. We’re also aware that you may have good reasons to not update to Node.js 10, which is why this was sent as an issue and not a pull request. Feel free to delete it without comment, I’m a humble robot and won’t feel rejected 🤖


FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Model id update fail

Model id update sometimes fails in getModelMeta because of Cannot read property 'meta' of undefined

An in-range update of datx is breaking the build 🚨

Version 0.11.2 of datx was just published.

Branch Build failing 🚨
Dependency datx
Current Version 0.11.1
Type dependency

This version is covered by your current version range and after updating it in your project the build failed.

datx is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details
  • continuous-integration/travis-ci/push The Travis CI build failed Details

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

datx-jsonapi `model.id` is not set after save / create

What I expect to happen:

class Foo extends jsonapi(Model) {
}
const foo = new Foo()
await foo.save()
isEqual(foo.id, foo.meta.id) // true
// foo.id is 1
// foo.meta.id is 1

What actually happens:

class Foo extends jsonapi(Model) {
}
const foo = new Foo()
await foo.save()
isEqual(foo.id, foo.meta.id)
// foo.id is undefined
// foo.meta.id is 1

We are having trouble with creating records with datx-jsonapi. We would like to have an id accessible on the model, without having to go through meta. We would like to be able to treat a newly created record and an existing record the same way, which includes accessing the model id.

When an existing record is loaded, the model has an id on it. This looks to be because of initModelData, which sets the id property on model with initModelField, using the meta.id which was passed in to initModelData.

When a newly constructed record is saved (await model.save()), the model id is not populated, but the meta.id is. It seems like response.replaceData intentionally does not set the id. Is there a reason for that?

updateModel explicitly does not set model id / type, and updateModelId only seems to set the meta key. Shouldn't updateModelId set the id property?

Better core documentation

  • Home
  • Getting started
    • Installation
    • Defining models
    • References
    • Configuring the collection
    • Using the collection
    • Persisting data locally
  • Mixins
    • withMeta
    • withActions
  • API reference
    • Collection
    • Model
    • prop
    • PureModel
    • Model utils
    • Lib utils
    • TypeScript interfaces

An in-range update of rollup-plugin-typescript2 is breaking the build 🚨

Version 0.15.1 of rollup-plugin-typescript2 was just published.

Branch Build failing 🚨
Dependency [rollup-plugin-typescript2](https://github.com/ezolenko/rollup-plugin-typescript2)
Current Version 0.15.0
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

rollup-plugin-typescript2 is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details

Commits

The new version differs by 2 commits.

  • ffe3b6c - fix for LanguageServiceHost ignoring virtual modules #78
  • aab0cc7 - package version

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of @types/lodash is breaking the build 🚨

Version 4.14.116 of @types/lodash was just published.

Branch Build failing 🚨
Dependency @types/lodash
Current Version 4.14.115
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

@types/lodash is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build failed (Details).

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Consider class decorators

Consider using class decorators instead of extending the Model class and defining the static type.

Concerns:

  • Is it useful
  • How does it work with mixins
  • How does it work in an env without decorators

An in-range update of datx is breaking the build 🚨

Version 0.10.6 of datx was just published.

Branch Build failing 🚨
Dependency datx
Current Version 0.10.2
Type dependency

This version is covered by your current version range and after updating it in your project the build failed.

datx is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details
  • continuous-integration/travis-ci/push The Travis CI build failed Details

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

fetchAll revamp

The option is a number of pages that should be fetched. Infinity to fetch all available pages.

TODO: Figure out how the response object should look in this case.

Add view support

Add support for views (similar to sql views) - add a view to the collection that holds a custom list of models

Requirements:

  • Has a name in collection (optional)
  • Belongs to a collection
  • Has a type (model)
  • Can have a sort function
  • Can force uniquenes
  • Has a subset of collection methods
    • remove()
    • removeAll()
    • length
    • list (observable)
    • snapshot/toJSON
    • jsonapi mixin
      • fetch()
      • fetchAll()
      • sync()
  • view standalone serialization/deserialization
  • view in collection serialization/deserialization
  • docs

Creation:

collection.addView(name, {
  type: modelType,
  sort: sortFn, // optional
  unique: true, // optional
});

An in-range update of ts-jest is breaking the build 🚨

Version 23.1.0 of ts-jest was just published.

Branch Build failing 🚨
Dependency ts-jest
Current Version 23.0.1
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

ts-jest is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build failed (Details).

Commits

The new version differs by 39 commits.

  • 6916e7b Merge pull request #650 from kulshekhar/kulshekhar-patch-1
  • 54a30eb Bump the version (minor)
  • 9e61969 Merge pull request #626 from huafu/feature/upgrade-babel-and-fix-tsconfig
  • ef21f50 Merge branch 'master' into feature/upgrade-babel-and-fix-tsconfig
  • c67ba4d Merge pull request #649 from kulshekhar/greenkeeper/monorepo.react-16.4.2
  • 9a6904f Merge branch 'master' of https://github.com/kulshekhar/ts-jest into feature/upgrade-babel-and-fix-tsconfig
  • 8a94008 chore(package): update react-test-renderer to version 16.4.2
  • 6e73fb9 chore(package): update react to version 16.4.2
  • c947791 chore(package): update @types/node to version 10.5.5 (#646)
  • fd24ae6 Merge pull request #640 from jmheik/to-dev-deps
  • e2028da Merge branch 'master' into to-dev-deps
  • 4396dde Merge pull request #641 from jeznag/patch-1
  • 7d78123 Merge branch 'master' into patch-1
  • b38e4ca Add TypeScript ^3.0.0 as supported peer dependencies (#644)
  • 1e287f3 Add more details on using module name mapper

There are 39 commits in total.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.