
Security News
The Next Open Source Security Race: Triage at Machine Speed
Claude Opus 4.6 has uncovered more than 500 open source vulnerabilities, raising new considerations for disclosure, triage, and patching at scale.
typescript-model
Advanced tools
Typed entity modeling library with attribute sanitization and validation.
npm install --save typescript-model
An example User model is shown below.
import { Attributes, Model, Config as BaseConfig, Sanitizers, Validators, sanitizers, validators } from 'typescript-model';
export interface Config extends BaseConfig {
min_username_length: number,
};
export class User extends Model<Config> {
public email!: string; // Note the use of '!' to silence TS2564 errors; these properties are definitely assigned in super.constructor()
public id?: number; // A '!' is not required as this parameter is marked as optional ('?')
public username!: string;
public verified!: boolean;
static config: Config = {
...Model.config,
min_username_length: 5,
};
static sanitizers: Sanitizers<User> = {
...Model.sanitizers,
email: (model, key, value) => sanitizers.string(value),
id: (model, key, value) => undefined !== value ? sanitizers.integer(value) : undefined,
username: (model, key, value) => sanitizers.string(value),
verified: (model, key, value) => sanitizers.boolean(value),
};
static validators: Validators<User> = {
...Model.validators,
email: (model, key, value) => validators.email(value),
id: (model, key, value) => undefined === value || validators.integer(value, {min: 1}),
username: (model, key, value) => validators.string(value, {min: model.config.min_username_length}),
verified: (model, key, value) => validators.boolean(value),
};
public constructor(attrs: Attributes<User>, config: Partial<Config> = {}, raw: boolean = false) {
super(attrs, { ...User.config, ...config as object } as Config, raw);
}
}
Instantiation:
import { User } from './User';
const user = new User({ email: 'foo@example.com', username: 'foo', verified: false });
console.log(user); // User { email: 'foo@example.com', username: 'foo', verified: false }
Review the __tests__ directory for additional usage examples.
There are various ORM libraries available for Typescript and JavaScript but all are tightly coupled with Data Access Mappers and underlying data stores.
This library provides just the low-level requirements of an entity model without the concern of how data is mapped.
The specific use-case that led to it's inception was to be able to share entity models between API and client applications. While an API application maps data sourced from arbitrary - and usually multiple - data stores, the client application would map data sourced from the API.
Both applications would share a common package that provides the model definitions containing common domain and business logic while each being able to implement their own data mapping functionality, either by extending the base entities with create(), update(), etc. implementations (Active Record pattern) or with dedicated data mapper classes (Repository pattern).
FAQs
Typed entity modeling library with attribute sanitization and validation.
The npm package typescript-model receives a total of 1 weekly downloads. As such, typescript-model popularity was classified as not popular.
We found that typescript-model 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
Claude Opus 4.6 has uncovered more than 500 open source vulnerabilities, raising new considerations for disclosure, triage, and patching at scale.

Research
/Security News
Malicious dYdX client packages were published to npm and PyPI after a maintainer compromise, enabling wallet credential theft and remote code execution.

Security News
gem.coop is testing registry-level dependency cooldowns to limit exposure during the brief window when malicious gems are most likely to spread.