DatX is an opinionated data store. It features support for references to other models and first-class TypeScript support.
@datx/network is a datx mixin that adds a networking layer support. It can be used with any REST-like API and probably also other types of an API.
Basic usage
import { Collection, Model, Attribute } from'@datx/core';
import { BaseRequest, collection, setUrl } from'@datx/network';
classPersonextendsModel {
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}`;
}
}
classAppDataextendsCollection {
publicstatic types = [Person]; // A list of models available in the collection
}
const store = newAppData();
// Create a base request with a basic configuration (baseUrl and linked collection)const baseRequest = newBaseRequest('https://example.com').pipe(collection(store));
// Create separate request pointsconst getPerson = baseRequest.pipe<Person>(setUrl('/people/{id}', Person));
const getPeople = baseRequest.pipe<Array<Person>>(setUrl('/people', Person));
// Pure JS loadingconst peopleResponse = await getPeople.fetch();
// Loading in a React componentconstPersonInfo = ({ userId }) => {
const [response, loading, error] = getPerson.useHook({ id: userId });
if (loading || error) {
returnnull;
}
const user = response.data;
return<div>{user.fullName}</div>;
};
Getting started
npm install --save @datx/network
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.
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/network 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.
The Python Software Foundation has secured a 5-year sponsorship from Fastly that supports PSF's activities and events, most notably the security and reliability of the Python Package Index (PyPI).
LDAPjs, an LDAP Client and Server API for Node.js, was decommissioned after its maintainer received an abusive email from a user, raising concerns about this form of abuse as a potential attack vector.
CISA launched a new project called Vulnrichment to enrich CVEs with details that help prioritize patching and mitigation efforts, as the NVD backlog of unenriched CVEs awaiting analysis surpasses 10,000.