
Security News
Frontier AI Is Now Critical Infrastructure
The Fable shutdown shows how quickly model access can become a business continuity risk for AI-dependent engineering teams.
js-data-decorators
Advanced tools
Addon to js-data that facilitates creation of schemas through the use of @Decorators
This package provides a set of decorators that facilitate the creation of js-data mappers and json schema.
// models/user.js
import { Resource, Id, Property, Required, HasMany } from 'js-data-decorators';
@Resource()
class User {
@Id()
@Property({ type: 'integer' })
id;
@Property({ type: 'string' })
@Required()
name;
@HasMany({ foreignKey: 'authorId' })
articles;
}
export default User;
// models/article.js
import { Resource, Id, Property, BelongsTo } from 'js-data-decorators';
@Resource({ description: 'A article written to a blog.' })
class Article {
@Id()
@Property({ type: 'integer' })
id;
@Property({ type: ['string', 'null'] })
@Required()
authorId;
@BelongsTo({ resource: 'user' })
author;
@Property({ type: 'boolean' })
@Required()
isPublished;
@Property({ type: 'number', minimum: 1, maximum: 5 })
starRating;
@Property({ type: 'array', items: { type: 'string' } })
tags;
}
export default Article;
import { DataStore } from 'js-data';
import { HttpAdapter } from 'js-data-http';
import User from 'models/user';
import Article from 'models/article';
import { defineMapper } from 'js-data-decortors';
const adapter = new HttpAdapter();
const store = new DataStore();
store.registerAdapter('http', adapter, { 'default': true });
defineMapper(store, User, { endpoint: '/users' });
defineMapper(store, Article, { endpoint: '/articles' });
The calls to defineMapper in the last two lines of the example above are equivalent to this:
store.defineMapper('user', {
name: 'user',
schema: {
type: 'object',
properties: {
id: { type: 'integer' },
name: { type: 'string' },
},
},
relations: {
hasMany: {
article: { foreignKey: 'authorId', localField: 'articles' },
},
},
idAttribute: 'id',
required: ['name'],
recordClass: User,
endpoint: '/users',
});
store.defineMapper('article', {
name: 'article',
schema: {
description: 'A article written to a blog.',
type: 'object',
properties: {
id: { type: 'integer' },
authorId: { type: ['string', 'null'] },
isPublished: { type: 'boolean' },
starRating: { type: 'number', minimum: 0, maximum: 5 },
tags: { type: 'array', items: { type: 'string' } },
},
},
relations: {
belongsTo: {
user: { foreignKey: 'authorId', localField: 'author' },
},
},
idAttribute: 'id',
recordClass: Article,
endpoint: '/articles',
});
FAQs
Addon to js-data that facilitates creation of schemas through the use of @Decorators
The npm package js-data-decorators receives a total of 4 weekly downloads. As such, js-data-decorators popularity was classified as not popular.
We found that js-data-decorators demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.

Security News
The Fable shutdown shows how quickly model access can become a business continuity risk for AI-dependent engineering teams.

Security News
AI agents are pulling packages into environments no scanner is watching, creating exposure before security teams can see it.

Security News
GitHub Actions checkout now blocks risky pull_request_target checkouts by default to help prevent pwn request supply chain attacks.