Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface ModelConfig<TEntity, TRawData, TId>

Type parameters

Hierarchy

Implemented by

Index

Properties

Optional entityConstructor

entityConstructor: DataEntityType<TEntity, TRawData, TId>

Optional fields

fields: EntityFields

Optional fieldsArray

fieldsArray: Array<Field>

Optional getDefaultValue

getDefaultValue: function

Type declaration

    • (): TEntity
    • Returns TEntity

Optional getValueById

getValueById: function

Type declaration

Optional hasValue

hasValue: function

Tests whether the entity contains a hard-coded value with the specified ID (in the entities values configuration).

param
returns

Type declaration

Optional idField

idField: Field

The field in the model that's used as key (for getItemById, for example).

Optional idProperty

idProperty: keyof TRawData

The property in the raw data used for the Entity's ID.

Optional modelWith

modelWith: function

Optional function to supply the model type to construct, given the raw data. Useful for APIs that can return multiple entity types, with a common discriminator to differentiate them.

example
GET /things
[
{ "kind": "one", "id": 1 },
{ "kind": "two", "id": 2 },
]
@Entity(
modelWith: rawData => rawData.kind === 'one' : One ? Two
)
class Base { }

@Entity()
class One extends Base {}

@Entity()
class Two extends Base {}

paris.getItemById<One | Two>(Base, 1)
.subscribe(item =>
console.log(item instanceof One) // true
)

paris.getRepository(Base).query().subscribe(dataSet => {
const [ one, two ] = dataSet.items;

console.log(one instanceof One) // true
console.log(two instanceof Two) // true
});

Type declaration

Optional parseSaveItemsQuery

parseSaveItemsQuery: function

Type declaration

pluralName

pluralName: string

Human-readable name for the Entity type, plural. e.g 'Users', 'To do items', 'Movies', 'Comments', etc. Used internally for error messages, for example, or can be used in reflection.

Optional readonly

readonly: boolean

If readonly is set to true, all models of this entity type will be immutable - frozen with Object.freeze. Readonly models don't have a $parent property.

default

false

Optional serializeItem

serializeItem: function

Type declaration

    • (item: Partial<TEntity>, serializedItem?: any, entity?: IEntityConfigBase<TEntity, TRawData, TId>, config?: ParisConfig, serializationData?: any): TRawData
    • Parameters

      • item: Partial<TEntity>
      • Optional serializedItem: any
      • Optional entity: IEntityConfigBase<TEntity, TRawData, TId>
      • Optional config: ParisConfig
      • Optional serializationData: any

      Returns TRawData

singularName

singularName: string

Human-readable name for the Entity type, singular. e.g 'User', 'To do item', 'Movie', 'Comment', etc. Used internally for error messages, for example, or can be used in reflection.

Optional supportedEntityGetMethods

supportedEntityGetMethods: Array<EntityGetMethod>

Optional values

values: Array<TEntity>

Hard-coded items for this Entity. When values are specified, no endpoint is required, and items are always returned from these values, instead of backend.

Hard-coding values for an Entity:

example
@Entity({
singularName: "Status",
pluralName: "Statuses",
values: [
{ id: 1, name: 'Open' },
{ id: 2, name: 'In progress' },
{ id: 3, name: 'Done' }
]
})
export class Status extends EntityModelBase<number>{
@EntityField()
name: string;
}

Then when requesting an item for Status, either directly (with getValue or getItemById) or when sub-modeling, the hard-coded values are used:

// Async:
paris.getItemById(Status, 1).subscribe(status => console.log('Status with ID 1: ', status);

// Sync:
console.log('Status with ID 1: ', paris.getValue(Status, 1));

Generated using TypeDoc