JsonEntityStore
Usage
import { JsonEntityStore } from "@tsed/schema";Overview
abstract class JsonEntityStore implements JsonEntityStoreOptions {
readonly propertyKey: string | symbol;
readonly propertyName: string;
readonly index: number;
readonly descriptor: PropertyDescriptor;
readonly decoratorType: DecoratorTypes;
token: Type<any>;
readonly store: Store;
readonly isStore = true;
readonly parent: JsonEntityStore;
readonly target: Type<any>;
[key: string]: any;
constructor(options: JsonEntityStoreOptions);
get collectionType(): Type<any> | undefined;
set collectionType(value: Type<any>);
protected _type: Type<any>;
get type(): Type<any> | any;
set type(value: Type<any> | any);
protected _schema: JsonSchema;
get schema(): JsonSchema;
get targetName(): string;
get isCollection(): boolean;
get isArray(): boolean;
get discriminatorAncestor(): JsonEntityStore | undefined;
get isPrimitive(): boolean;
get isDate(): boolean;
get isObject(): boolean;
get isClass(): boolean;
get computedType(): Type<any>;
get itemSchema(): JsonSchema;
get parentSchema(): JsonSchema;
get isDiscriminatorChild(): boolean;
get path(): string;
set path(path: string);
static from<T extends JsonClassStore = JsonClassStore>(target: Type<any>): T;
static from<T extends JsonPropertyStore = JsonPropertyStore>(target: Type<any> | any, propertyKey: string | symbol): T;
static from<T extends JsonParameterStore = JsonParameterStore>(target: Type<any> | any, propertyKey: string | symbol, index: number): T;
static from<T extends JsonMethodStore = JsonMethodStore>(target: Type<any> | any, propertyKey: string | symbol, descriptor: PropertyDescriptor): T;
static from<T extends JsonEntityStore = JsonEntityStore>(...args: any[]): T;
static fromMethod<T extends JsonMethodStore = JsonMethodStore>(target: any, propertyKey: string | symbol): T;
static get(target: Type<any>, propertyKey: string | symbol, descriptor?: any): JsonEntityStore;
isGetterOnly(): boolean | undefined;
get<T = any>(key: string, defaultValue?: any): T;
set(key: string, value?: any): Store;
toString(): string;
getBestType(): any;
is(input: DecoratorTypes.CLASS): this is JsonClassStore;
is(input: DecoratorTypes.PROP): this is JsonPropertyStore;
is(input: DecoratorTypes.METHOD): this is JsonMethodStore;
is(input: DecoratorTypes.PARAM): this is JsonParameterStore;
protected abstract build(): void;
protected buildType(type: any): void;
}Description
Base class for storing metadata about decorated entities (classes, properties, methods, parameters).
JsonEntityStore is the foundation of Ts.ED's metadata system, managing schema information and type metadata for decorated entities. It serves as the parent class for specialized stores (JsonClassStore, JsonPropertyStore, JsonMethodStore, JsonParameterStore).
Entity Types
Different decorator types create different store subclasses:
- Class decorators: Create JsonClassStore instances
- Property decorators: Create JsonPropertyStore instances
- Method decorators: Create JsonMethodStore instances
- Parameter decorators: Create JsonParameterStore instances
Key Responsibilities
- Schema Management: Each store maintains a JsonSchema for the decorated entity
- Type Resolution: Resolves TypeScript types, including collections and generics
- Metadata Storage: Stores decorator metadata using Ts.ED's Store system
- Inheritance: Manages parent-child relationships between entities
Usage
Stores are typically accessed via static from() methods:
// Get store for a class
const classStore = JsonEntityStore.from(MyClass);
// Get store for a property
const propStore = JsonEntityStore.from(MyClass, "propertyName");
// Get store for a method parameter
const paramStore = JsonEntityStore.from(MyClass, "methodName", 0);Architecture
The store system creates a hierarchical structure:
- ClassStore contains PropertyStore and MethodStore children
- MethodStore contains ParameterStore children
- Each store has an associated JsonSchema
readonly propertyKey
readonly propertyKey: string | symbol;Original property key decorated by the decorator
readonly propertyName
readonly propertyName: string;Alias of the property
readonly index
readonly index: number;Parameter index
readonly descriptor
readonly descriptor: PropertyDescriptor;Method's descriptor
readonly decoratorType
readonly decoratorType: DecoratorTypes;Decorator type used to the JsonSchemaStore.
token
token: Type<any>;readonly store
readonly store: Store;readonly isStore
readonly isStore = true;readonly parent
readonly parent: JsonEntityStore;readonly target
readonly target: Type<any>;[key: string]
[key: string]: any;get collectionType
get collectionType(): Type<any> | undefined;Type of the collection (Array, Map, Set, etc...)
set collectionType
set collectionType(value: Type<any>);protected _type
protected _type: Type<any>;get type
get type(): Type<any> | any;set type
set type(value: Type<any> | any);Get original type without transformation
protected _schema
protected _schema: JsonSchema;Ref to JsonSchema
get schema
get schema(): JsonSchema;Return the JsonSchema
get targetName
get targetName(): string;Return the class name of the entity.
get isCollection
get isCollection(): boolean;get isArray
get isArray(): boolean;get discriminatorAncestor
get discriminatorAncestor(): JsonEntityStore | undefined;get isPrimitive
get isPrimitive(): boolean;get isDate
get isDate(): boolean;get isObject
get isObject(): boolean;get isClass
get isClass(): boolean;get computedType
get computedType(): Type<any>;Return the itemSchema computed type. if the type is a function used for recursive model, the function will be called to get the right type.
get itemSchema
get itemSchema(): JsonSchema;get parentSchema
get parentSchema(): JsonSchema;get isDiscriminatorChild
get isDiscriminatorChild(): boolean;get path
get path(): string;set path
set path(path: string);static from
static from<T extends JsonClassStore = JsonClassStore>(target: Type<any>): T;static from
static from<T extends JsonPropertyStore = JsonPropertyStore>(target: Type<any> | any, propertyKey: string | symbol): T;static from
static from<T extends JsonParameterStore = JsonParameterStore>(target: Type<any> | any, propertyKey: string | symbol, index: number): T;static from
static from<T extends JsonMethodStore = JsonMethodStore>(target: Type<any> | any, propertyKey: string | symbol, descriptor: PropertyDescriptor): T;static from
static from<T extends JsonEntityStore = JsonEntityStore>(...args: any[]): T;static fromMethod
static fromMethod<T extends JsonMethodStore = JsonMethodStore>(target: any, propertyKey: string | symbol): T;static get
static get(target: Type<any>, propertyKey: string | symbol, descriptor?: any): JsonEntityStore;isGetterOnly
isGetterOnly(): boolean | undefined;get
get<T = any>(key: string, defaultValue?: any): T;set
set(key: string, value?: any): Store;toString
toString(): string;getBestType
getBestType(): any;is
is(input: DecoratorTypes.CLASS): this is JsonClassStore;is
is(input: DecoratorTypes.PROP): this is JsonPropertyStore;is
is(input: DecoratorTypes.METHOD): this is JsonMethodStore;is
is(input: DecoratorTypes.PARAM): this is JsonParameterStore;protected abstract build
protected abstract build(): void;protected buildType
protected buildType(type: any): void;