@microsoft/paris
Advanced tools
Comparing version 1.9.5 to 1.10.0
@@ -8,2 +8,3 @@ import { ParisConfig } from "./paris-config"; | ||
import { EntityFields } from "../api/entity/entity-fields"; | ||
import { DataQuery } from "../data_access/data-query"; | ||
export declare class EntityConfigBase<TEntity extends ModelBase = any, TRawData = any, TId extends EntityId = string> implements ModelConfig<TEntity, TRawData, TId> { | ||
@@ -134,3 +135,3 @@ entityConstructor: DataEntityType<TEntity, TRawData, TId>; | ||
*/ | ||
modelWith?: (data: TRawData) => DataEntityType<any>; | ||
modelWith?: (data: TRawData, query?: DataQuery) => string | DataEntityType<any>; | ||
} | ||
@@ -137,0 +138,0 @@ export interface ModelConfig<TEntity extends ModelBase, TRawData = any, TId extends EntityId = string> extends IEntityConfigBase<TEntity, TRawData, TId> { |
@@ -18,3 +18,3 @@ import { entityFieldsService } from "./entity-fields.service"; | ||
EntitiesServiceBase.prototype.getEntityByName = function (entitySingularName) { | ||
return this._allEntitiesByName.get(entitySingularName.replace(/\s/g, "")); | ||
return this._allEntitiesByName.get(entitySingularName); | ||
}; | ||
@@ -24,3 +24,3 @@ EntitiesServiceBase.prototype.addEntity = function (dataEntityType, entity) { | ||
this._allEntities.set(dataEntityType, entity); | ||
this._allEntitiesByName.set(dataEntityType.singularName.replace(/\s/g, ""), entity); | ||
this._allEntitiesByName.set(dataEntityType.name, entity); | ||
} | ||
@@ -27,0 +27,0 @@ entity.fields = this.getDataEntityTypeFields(dataEntityType); |
@@ -11,2 +11,3 @@ import { ModelBase } from "../config/model.base"; | ||
import { ReadonlyRepository } from "../api/repository/readonly-repository"; | ||
import { entitiesService } from "../config/services/entities.service"; | ||
var DEFAULT_ALL_ITEMS_PROPERTY = 'items'; | ||
@@ -39,5 +40,9 @@ var Modeler = /** @class */ (function () { | ||
if (typeof entity.modelWith === 'function') { | ||
var modelWithEntity = entity.modelWith(rawData); | ||
if (modelWithEntity) { | ||
return this.modelEntity(rawData, modelWithEntity.entityConfig || modelWithEntity.valueObjectConfig, options); | ||
var modelWithEntityOrString = entity.modelWith(rawData, query); | ||
if (modelWithEntityOrString) { | ||
var modelWithEntity = typeof modelWithEntityOrString === "string" ? | ||
(entitiesService.getEntityByName(modelWithEntityOrString) || | ||
valueObjectsService.getEntityByName(modelWithEntityOrString)) : | ||
(modelWithEntityOrString.entityConfig || modelWithEntityOrString.valueObjectConfig); | ||
return this.modelEntity(rawData, modelWithEntity, options, query); | ||
} | ||
@@ -44,0 +49,0 @@ } |
@@ -75,4 +75,3 @@ var __assign = (this && this.__assign) || Object.assign || function(t) { | ||
var relationship = relationshipConstructor; | ||
var sourceEntityName = relationship.sourceEntityType.singularName.replace(/\s/g, ""), dataEntityName = relationship.dataEntityType.singularName.replace(/\s/g, ""); | ||
var relationshipId = sourceEntityName + "_" + dataEntityName; | ||
var sourceEntityName = relationship.sourceEntityType.name, dataEntityName = relationship.dataEntityType.name, relationshipId = sourceEntityName + "_" + dataEntityName; | ||
var repository = this.relationshipRepositories.get(relationshipId); | ||
@@ -79,0 +78,0 @@ if (!repository) { |
@@ -26,3 +26,3 @@ { | ||
"_spec": "json-stringify-safe@*", | ||
"_where": "/Users/maorfrankel/Workspace/paris", | ||
"_where": "/mnt/c/Users/aagreenw/code/paris", | ||
"author": { | ||
@@ -29,0 +29,0 @@ "name": "Isaac Z. Schlueter", |
{ | ||
"name": "@microsoft/paris", | ||
"version": "1.9.5", | ||
"version": "1.10.0", | ||
"description": "Library for the implementation of Domain Driven Design with TypeScript + RxJS", | ||
@@ -14,3 +14,3 @@ "repository": { | ||
"dev": "rollup -c -w", | ||
"prepublish": "npm run build", | ||
"prepublish": "npm run build && npm run test", | ||
"test": "jest", | ||
@@ -69,3 +69,3 @@ "test:watch": "jest --watch", | ||
"json-stringify-safe": "^5.0.1", | ||
"lodash-es": "4.17.10", | ||
"lodash-es": "4.17.15", | ||
"merge2": "^1.0.2", | ||
@@ -72,0 +72,0 @@ "reflect-metadata": "^0.1.12", |
@@ -16,2 +16,4 @@ import {EntityField} from '../../lib/config/decorators/entity-field.decorator'; | ||
return Person; | ||
case 'thing': | ||
return null; | ||
default: | ||
@@ -34,2 +36,8 @@ throw new Error(`Invalid type for 'Thing' (got ${rawData.type})`); | ||
endpoint: 'things', | ||
modelWith: (_, query) => { | ||
if (query && query.where && (<{[index: string]: any}>query.where)['fullMoon']){ | ||
return Animal; | ||
} | ||
return null; | ||
} | ||
}) | ||
@@ -45,2 +53,8 @@ export class Person extends Thing { | ||
endpoint: 'things', | ||
modelWith: (_, query) => { | ||
if (query && query.where && (<{ [index: string]: any }>query.where)['isDog']) { | ||
return 'Dog' | ||
} | ||
return null | ||
} | ||
}) | ||
@@ -47,0 +61,0 @@ export class Animal extends Thing { |
@@ -21,2 +21,3 @@ import {forkJoin, Observable, of} from 'rxjs'; | ||
import {ModelConfig} from "../../lib/config/model-config"; | ||
import {Dog} from "../mock/dog.entity"; | ||
@@ -228,2 +229,3 @@ describe('Modeler', () => { | ||
{ type: 'person', name: 'Joe', address: '1 Generic st.' }, | ||
{ type: 'thing', name: 'It'}, | ||
]); | ||
@@ -249,10 +251,25 @@ }; | ||
it('should support derived entity (single) with query', done => { | ||
paris.getItemById(Person, 1, undefined, {"fullMoon": true}).subscribe(item => { | ||
expect(item).toBeInstanceOf(Animal); | ||
done(); | ||
}); | ||
}); | ||
it('should support derived entity (single) by class name', done => { | ||
paris.getItemById(Animal, 1, undefined, {"isDog": true}).subscribe(item => { | ||
expect(item).toBeInstanceOf(Dog); | ||
done(); | ||
}); | ||
}); | ||
it('should support derived entity (multiple)', done => { | ||
const repository = paris.getRepository(Thing); | ||
repository.query().subscribe(({ items }) => { | ||
expect(items).toHaveLength(2); | ||
expect(items).toHaveLength(3); | ||
const [animal, person] = items; | ||
const [animal, person, thing] = items; | ||
expect(animal).toBeInstanceOf(Animal); | ||
expect(person).toBeInstanceOf(Person); | ||
expect(thing).toBeInstanceOf(Thing); | ||
@@ -259,0 +276,0 @@ done(); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
261375
148
5352