@microsoft/paris
Advanced tools
Comparing version 1.4.2 to 1.4.3
@@ -0,0 +0,0 @@ { |
@@ -0,0 +0,0 @@ # Contributor Covenant Code of Conduct |
@@ -33,2 +33,3 @@ import { Observable, Subject } from "rxjs"; | ||
protected _allItemsSubject$: Subject<Array<TEntity>>; | ||
private _allItemsBeingSet$; | ||
protected getBaseUrl(query?: DataQuery): string; | ||
@@ -35,0 +36,0 @@ readonly entity: EntityConfig<TEntity, TRawData>; |
@@ -8,6 +8,7 @@ import { clone } from "lodash-es"; | ||
import { ErrorsService } from "../errors.service"; | ||
import { catchError, map, mergeMap, tap } from "rxjs/operators"; | ||
import { catchError, map, mergeMap, tap, take, refCount } from "rxjs/operators"; | ||
import { defaultDataOptions } from "../../data_access/data.options"; | ||
import { DataAvailability } from "../../data_access/data-availability.enum"; | ||
import { queryToHttpOptions } from "../../data_access/query-to-http"; | ||
import { publishReplay } from 'rxjs/internal/operators/publishReplay'; | ||
/** | ||
@@ -101,7 +102,10 @@ * A Repository is a service through which all of an Entity's data is fetched, cached and saved back to the backend. | ||
return of(this._allValues); | ||
return this.query().pipe(tap(function (dataSet) { | ||
if (this._allItemsBeingSet$) | ||
return this._allItemsBeingSet$; | ||
this._allItemsBeingSet$ = this.query().pipe(take(1), tap(function (dataSet) { | ||
_this._allValues = dataSet.items; | ||
_this._allValuesMap = new Map(); | ||
_this._allValues.forEach(function (value) { return _this._allValuesMap.set(String(value instanceof EntityModelBase ? value.id : value.toString()), value); }); | ||
}), map(function (dataSet) { return dataSet.items; })); | ||
}), map(function (dataSet) { return dataSet.items; }), publishReplay(), refCount()); | ||
return this._allItemsBeingSet$; | ||
}; | ||
@@ -108,0 +112,0 @@ /** |
@@ -0,0 +0,0 @@ import { ParisConfig } from "./paris-config"; |
@@ -0,0 +0,0 @@ # Paris |
@@ -0,0 +0,0 @@ const gulp = require('gulp'); |
export * from "./lib/main"; |
import 'reflect-metadata'; | ||
(<any>global)['Reflect'] = Reflect; |
@@ -26,3 +26,3 @@ { | ||
"_spec": "json-stringify-safe@*", | ||
"_where": "/Users/bengr/Projects/wdtatp/paris", | ||
"_where": "C:\\git\\paris", | ||
"author": { | ||
@@ -29,0 +29,0 @@ "name": "Isaac Z. Schlueter", |
{ | ||
"name": "@microsoft/paris", | ||
"version": "1.4.2", | ||
"version": "1.4.3", | ||
"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 && npm run test", | ||
"prepublish": "npm run build", | ||
"test": "jest", | ||
@@ -67,3 +67,3 @@ "test:watch": "jest --watch", | ||
"intl": "^1.2.5", | ||
"jest": "^23.5.0", | ||
"jest": "^24.7.1", | ||
"json-stringify-safe": "^5.0.1", | ||
@@ -70,0 +70,0 @@ "lodash-es": "4.17.10", |
@@ -0,0 +0,0 @@ # Paris |
@@ -0,0 +0,0 @@ import resolve from 'rollup-plugin-node-resolve'; |
@@ -0,0 +0,0 @@ import {Paris} from '../../lib/paris'; |
@@ -0,0 +0,0 @@ import {Paris} from '../../lib/paris'; |
@@ -0,0 +0,0 @@ import {Paris} from '../../lib/paris'; |
@@ -0,0 +0,0 @@ import { DataStoreService } from "../../lib/data_access/data-store.service"; |
@@ -0,0 +0,0 @@ import {ApiCall} from "../../lib/config/decorators/api-call.decorator"; |
@@ -0,0 +0,0 @@ import {of} from "rxjs"; |
interface MockConfigData { | ||
version: number | ||
} |
@@ -0,0 +0,0 @@ import {ModelBase} from "../../lib/config/model.base"; |
@@ -0,0 +0,0 @@ import {EntityField} from '../../lib/config/decorators/entity-field.decorator'; |
@@ -0,0 +0,0 @@ import {ModelBase} from "../../lib/config/model.base"; |
@@ -0,0 +0,0 @@ import {EntityModelBase} from "../../lib/config/entity-model.base"; |
@@ -0,0 +0,0 @@ import {TodoList} from "./todo-list.entity"; |
@@ -0,0 +0,0 @@ import {Todo} from "./todo.entity"; |
@@ -6,2 +6,3 @@ import {EntityModelBase} from "../../lib/config/entity-model.base"; | ||
import {TodoStatus} from "./todo-status.entity"; | ||
import { TodoType } from './todo-type.entity'; | ||
@@ -30,2 +31,5 @@ @Entity({ | ||
status:TodoStatus; | ||
@EntityField() | ||
type: TodoType; | ||
} |
@@ -0,0 +0,0 @@ import { ApiCallModel } from "../../lib/api/api-calls/api-call.model"; |
@@ -0,0 +0,0 @@ import 'reflect-metadata'; |
@@ -0,0 +0,0 @@ import {Observable, of} from 'rxjs'; |
@@ -8,3 +8,3 @@ import { Observable, of } from 'rxjs'; | ||
import { Paris } from '../lib/paris'; | ||
import { mergeMap } from '../node_modules/rxjs/operators'; | ||
import { mergeMap } from 'rxjs/operators'; | ||
import { CreateTodoListApiCall } from './mock/create-new-list.api-call'; | ||
@@ -17,4 +17,7 @@ import { Tag } from './mock/tag.value-object'; | ||
import { UpdateTodoApiCall } from './mock/update-todo.api-call'; | ||
import { setMockData } from "./mock/mock-data.service"; | ||
import { DataSet } from "../lib/data_access/dataset"; | ||
import { DataStoreService } from '../lib/data_access/data-store.service'; | ||
import { TodoType } from './mock/todo-type.entity'; | ||
import { RequestMethod } from '../lib/data_access/http.service'; | ||
import { EntityModelBase } from '../lib/config/entity-model.base'; | ||
@@ -119,16 +122,53 @@ describe('Paris main', () => { | ||
setMockData({ | ||
const todoMockData = { | ||
items: [ | ||
{ | ||
id: 1, | ||
text: 'First' | ||
text: 'First', | ||
type: 0 | ||
}, | ||
{ | ||
id: 2, | ||
text: 'Second' | ||
text: 'Second', | ||
type: 1 | ||
}, | ||
{ | ||
id: 3, | ||
text: 'Third', | ||
type: 1 | ||
} | ||
], | ||
next: next | ||
next: next, | ||
count: 3 | ||
}; | ||
const typesMockData = { | ||
count: 2, | ||
items: [ | ||
{ | ||
id: 0, | ||
name: 'Human' | ||
}, | ||
{ | ||
id: 1, | ||
name: 'Machine-Generated' | ||
} | ||
] | ||
}; | ||
beforeEach(<T extends EntityModelBase<number>>() => { | ||
// @ts-ignore | ||
const mockDataFetch:(method: RequestMethod, endpoint: string) => Observable<DataSet<T>> = (method:string, url: string) => of<DataSet<T>>(<DataSet<T>>(/types/.test(url) ? typesMockData : todoMockData)); | ||
// @ts-ignore | ||
DataStoreService.prototype.get = jest.fn<Observable<DataSet<T>>, [RequestMethod, string]>(mockDataFetch); | ||
// @ts-ignore | ||
DataStoreService.prototype.request = jest.fn<Observable<DataSet<T>>, [RequestMethod, string]>(mockDataFetch); | ||
}); | ||
afterEach(() => { | ||
jest.restoreAllMocks(); | ||
}); | ||
beforeEach(() => { | ||
@@ -166,2 +206,16 @@ paris = new Paris(); | ||
}); | ||
it('should have a submodel', done => { | ||
paris.query(Todo).subscribe(({ items }: DataSet<Todo>) => { | ||
expect(items[0].type).toBeInstanceOf(TodoType); | ||
done(); | ||
}); | ||
}); | ||
it('should point submodels to the same model when using loadAll', done => { | ||
paris.query(Todo).subscribe(({ items }: DataSet<Todo>) => { | ||
expect(items[1].type).toBe(items[2].type); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
@@ -168,0 +222,0 @@ |
@@ -0,0 +0,0 @@ { |
@@ -0,0 +0,0 @@ { |
@@ -0,0 +0,0 @@ { |
@@ -0,0 +0,0 @@ module.exports = { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
251187
146
5140