DatX is an opinionated data store. It features support for references to other models and first-class TypeScript support.
@datx/jsonapi is a datx mixin that adds JSON API support.
Basic usage
import { Collection, Model, Attribute } from'@datx/core';
import { jsonapiCollection, jsonapiModel } from'@datx/jsonapi';
classPersonextendsjsonapiModel(Model) {
publicstatictype = 'person'; // Unique name of the model class@Attribute()
publicname: string; // A normal attribute without a default value@Attribute()
publicsurname: string;
@Attribute({ toOne: Person })
public spouse?: Person; // A reference to a Person modelpublicgetfullName() {
return`${this.name}${this.surname}`;
}
}
classAppDataextendsjsonapiCollection(Collection) {
publicstatic types = [Person]; // A list of models available in the collection
}
const store = newAppData();
const john = store.add(newPerson({ name: 'John', surname: 'Smith' })); // Add a model instance to the storeconst jane = store.add({ name: 'Jane', surname: 'Smith', spouse: john }, Person); // Add a model to the storeawait john.save(); // POST to the serverconst people = await store.fetchAll(Person); // Get all people from the server
How to add the polyfills.
Note: Fetch API is not included in the polyfills mentioned in the Troubleshooting page. Instead, you need to add it as a separate library. If you don't have any special requirements (like server-side rendering), you can use the window.fetch polyfill.
We found that @datx/jsonapi demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.It has 7 open source maintainers collaborating on the project.
Last updated on 29 Jun 2023
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Results from the 2023 State of JavaScript Survey highlight key trends, including Vite's dominance, rising TypeScript adoption, and the enduring popularity of React. Discover more insights on developer preferences and technology usage.
The US Justice Department has penalized two consulting firms $11.3 million for failing to meet cybersecurity requirements on federally funded projects, emphasizing strict enforcement to protect sensitive government data.
ua-parser-js is set to drop the MIT license and adopt a controversial dual AGPLv3 + PRO licensing model in its upcoming v2.0 release, raising significant concerns among developers and enterprise users.