This commit is contained in:
Omer Mizrahi 2018-05-14 06:24:59 +00:00
Родитель 13306a4397
Коммит 44e1aef1ab
22 изменённых файлов: 127 добавлений и 139 удалений

1
.gitignore поставляемый
Просмотреть файл

@ -64,3 +64,4 @@ package-lock.json
# Build output
bundle/
dist/

Просмотреть файл

@ -12,4 +12,4 @@
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
</module>

Просмотреть файл

@ -4,7 +4,7 @@ const clean = require('gulp-clean');
const runSequence = require('run-sequence');
gulp.task('build', ["clean"], function() {
const tsProject = ts.createProject('tsconfig.json');
const tsProject = ts.createProject('tsconfig.lib.json');
const merge = require('merge2');
@ -20,7 +20,7 @@ gulp.task('build', ["clean"], function() {
});
gulp.task('clean', function () {
const tsProject = ts.createProject('tsconfig.json');
const tsProject = ts.createProject('tsconfig.lib.json');
return gulp.src(tsProject.config.compilerOptions.outDir, { read: false })
.pipe(clean());

2
index.d.ts поставляемый
Просмотреть файл

@ -1 +1 @@
export * from "./bundle/lib/main";
export * from "./lib/main";

Просмотреть файл

@ -1,4 +1,4 @@
import {AjaxRequest} from "rxjs/observable/dom/AjaxObservable";
import {AjaxRequest} from "rxjs/ajax";
export interface ParisConfig{
apiRoot?:string,

Просмотреть файл

@ -1,4 +1,4 @@
import {EntityConfigFunctionOrValue, ModelEntityCacheConfig} from "../entity/entity.config";
import {EntityConfigFunctionOrValue} from "../entity/entity.config";
import {ParisConfig} from "../config/paris-config";
import {DataQuery} from "../dataset/data-query";
import {DataCacheSettings} from "../services/cache";

Просмотреть файл

@ -1,7 +1,5 @@
import {ApiCallBackendConfigInterface} from "./api-call-backend-config.interface";
import {HttpOptions, RequestMethod} from "../services/http.service";
import {DataEntityConstructor, DataEntityType} from "../entity/data-entity.base";
import {ModelBase} from "./model.base";
export class ApiCallModel<TResult = any, TInput = any>{
config:ApiCallConfig<TResult, TInput>

Просмотреть файл

@ -3,12 +3,10 @@ import {DataEntityConstructor} from "../entity/data-entity.base";
import {Paris} from "../services/paris";
import {DataOptions, defaultDataOptions} from "../dataset/data.options";
import {DataQuery} from "../dataset/data-query";
import {Observable} from "rxjs/Observable";
import {combineLatest, Observable, of} from "rxjs";
import {DataSet} from "../dataset/dataset";
import {of} from "rxjs/observable/of";
import {ReadonlyRepository} from "./readonly-repository";
import {combineLatest} from "rxjs/observable/combineLatest";
import {map} from "rxjs/operators/map";
import {map} from "rxjs/operators";
export function rawDataToDataSet<T extends ModelBase, R = any>(
rawDataSet:any,

Просмотреть файл

@ -4,7 +4,7 @@ import {ErrorsService} from "../services/errors.service";
import {DataSet} from "../dataset/dataset";
import {DataQuery} from "../dataset/data-query";
import {DataOptions, defaultDataOptions} from "../dataset/data.options";
import {Observable} from "rxjs/Observable";
import {combineLatest, merge, Observable, of, Subject} from "rxjs";
import {HttpOptions} from "../services/http.service";
import {DataStoreService} from "../services/data-store.service";
import {ParisConfig} from "../config/paris-config";
@ -14,24 +14,18 @@ import {Paris} from "../services/paris";
import {DataAvailability} from "../dataset/data-availability.enum";
import {Field, FIELD_DATA_SELF} from "../entity/entity-field";
import {DataCache, DataCacheSettings} from "../services/cache";
import {Subject} from "rxjs/Subject";
import {Index} from "../models";
import {EntityConfigBase, EntityGetMethod, IEntityConfigBase} from "../entity/entity-config.base";
import {ModelBase} from "../models/model.base";
import {DataTransformersService} from "../services/data-transformers.service";
import * as _ from "lodash";
import {valueObjectsService} from "../services/value-objects.service";
import {AjaxError} from "rxjs/Rx";
import {AjaxError} from "rxjs/ajax";
import {EntityErrorEvent, EntityErrorTypes} from "../events/entity-error.event";
import {tap} from "rxjs/operators/tap";
import {map} from "rxjs/operators/map";
import {merge} from "rxjs/observable/merge";
import {of} from "rxjs/observable/of";
import {combineLatest} from "rxjs/observable/combineLatest";
import {mergeMap} from "rxjs/operators/mergeMap";
import {catchError} from "rxjs/operators/catchError";
import {catchError, map, mergeMap, tap} from "rxjs/operators";
import {IReadonlyRepository} from "./repository.interface";
export class ReadonlyRepository<T extends ModelBase>{
export class ReadonlyRepository<T extends ModelBase> implements IReadonlyRepository<T>{
protected _errorSubject$: Subject<EntityErrorEvent>;
error$: Observable<EntityErrorEvent>;
@ -110,8 +104,8 @@ export class ReadonlyRepository<T extends ModelBase>{
return new this.entityConstructor(defaultData);
}
createItem(itemData: {}, options: DataOptions = { allowCache: true, availability: DataAvailability.available }, query?: DataQuery): Observable<T> {
return ReadonlyRepository.getModelData(itemData, this.entity, this.config, this.paris, options, query);
createItem<T extends ModelBase>(itemData: {}, options: DataOptions = { allowCache: true, availability: DataAvailability.available }, query?: DataQuery): Observable<T> {
return ReadonlyRepository.getModelData<T>(itemData, this.entity, this.config, this.paris, options, query);
}
query(query?: DataQuery, dataOptions: DataOptions = defaultDataOptions): Observable<DataSet<T>> {

Просмотреть файл

@ -3,7 +3,7 @@ import {EntityModelBase} from "../models/entity-model.base";
import {DataSet} from "../dataset/dataset";
import {DataQuery} from "../dataset/data-query";
import {DataOptions, defaultDataOptions} from "../dataset/data.options";
import {Observable} from "rxjs/Observable";
import {Observable} from "rxjs";
import {DataStoreService} from "../services/data-store.service";
import {ParisConfig} from "../config/paris-config";
import {Paris} from "../services/paris";
@ -16,7 +16,7 @@ import {RelationshipType} from "../models/relationship-type.enum";
const DEFAULT_RELATIONSHIP_TYPES = [RelationshipType.OneToMany, RelationshipType.OneToOne];
export class RelationshipRepository<T extends ModelBase, U extends ModelBase> extends ReadonlyRepository<U> implements IRelationshipRepository {
export class RelationshipRepository<T extends ModelBase, U extends ModelBase> extends ReadonlyRepository<U> implements IRelationshipRepository<U> {
private sourceRepository: ReadonlyRepository<T>;
readonly relationshipConfig:EntityRelationshipConfig;
@ -108,7 +108,7 @@ export class RelationshipRepository<T extends ModelBase, U extends ModelBase> ex
}
}
export interface IRelationshipRepository extends IReadonlyRepository{
export interface IRelationshipRepository<U extends ModelBase = ModelBase> extends IReadonlyRepository<U>{
sourceEntityType: DataEntityType,
dataEntityType: DataEntityType,
relationshipConfig:EntityRelationshipConfig,

Просмотреть файл

@ -1,23 +1,23 @@
import {Observable} from "rxjs/Observable";
import {Observable} from "rxjs";
import {DataQuery} from "../dataset/data-query";
import {DataSet} from "../dataset/dataset";
import {IEntityConfigBase} from "../entity/entity-config.base";
import {ModelBase} from "../models/model.base";
import {DataOptions} from "../dataset/data.options";
export interface IReadonlyRepository{
export interface IReadonlyRepository<T extends ModelBase = ModelBase>{
entity:IEntityConfigBase,
createItem:(itemData:any) => Observable<Readonly<any>>,
createNewItem:() => ModelBase,
getItemById:(id:any, options?:DataOptions, params?:{ [index:string]:any }) => Observable<any>,
query:(options?:DataQuery) => Observable<DataSet<any>>,
serializeItem:(item:ModelBase, serializationData?:any) => Object,
allItems$:Observable<Array<any>>,
createItem:(itemData:any) => Observable<Readonly<T>>,
createNewItem:() => T,
getItemById:(id:any, options?:DataOptions, params?:{ [index:string]:any }) => Observable<T>,
query:(options?:DataQuery) => Observable<DataSet<T>>,
serializeItem:(item:T, serializationData?:any) => Object,
allItems$:Observable<Array<T>>,
endpointName:string,
endpointUrl:string,
}
export interface IRepository extends IReadonlyRepository{
save:(item:ModelBase) => Observable<ModelBase>
export interface IRepository<T extends ModelBase = ModelBase> extends IReadonlyRepository<T>{
save:(item:T) => Observable<T>
//save$:Observable<any>
}

Просмотреть файл

@ -1,7 +1,6 @@
import {EntityConfig} from "../entity/entity.config";
import {DataEntityConstructor} from "../entity/data-entity.base";
import {Observable} from "rxjs/Observable";
import {Subject} from "rxjs/Subject";
import {combineLatest, defer, merge, Observable, of, Subject, throwError} from "rxjs";
import {IRepository} from "./repository.interface";
import {DataStoreService} from "../services/data-store.service";
import {ParisConfig} from "../config/paris-config";
@ -14,19 +13,11 @@ import {HttpOptions, RequestMethod} from "../services/http.service";
import {SaveEntityEvent} from "../events/save-entity.event";
import {RemoveEntitiesEvent} from "../events/remove-entities.event";
import {ReadonlyRepository} from "./readonly-repository";
import {AjaxError} from "rxjs/Rx";
import {defer} from "rxjs/observable/defer";
import {mergeMap} from "rxjs/operators/mergeMap";
import {tap} from "rxjs/operators/tap";
import {map} from "rxjs/operators/map";
import {_throw} from "rxjs/observable/throw";
import {of} from "rxjs/observable/of";
import {merge} from "rxjs/observable/merge";
import {combineLatest} from "rxjs/observable/combineLatest";
import {catchError} from "rxjs/operators/catchError";
import {AjaxError} from "rxjs/ajax";
import {catchError, map, mergeMap, tap} from "rxjs/operators";
import {DataSet} from "../dataset/dataset";
export class Repository<T extends ModelBase> extends ReadonlyRepository<T> implements IRepository {
export class Repository<T extends ModelBase> extends ReadonlyRepository<T> implements IRepository<T> {
save$: Observable<SaveEntityEvent>;
remove$: Observable<RemoveEntitiesEvent>;
@ -85,7 +76,7 @@ export class Repository<T extends ModelBase> extends ReadonlyRepository<T> imple
);
}
catch(e){
return _throw(e);
return throwError(e);
}
}
@ -203,7 +194,7 @@ export class Repository<T extends ModelBase> extends ReadonlyRepository<T> imple
)
}
catch(e){
return _throw(e);
return throwError(e);
}
}
@ -255,7 +246,7 @@ export class Repository<T extends ModelBase> extends ReadonlyRepository<T> imple
)
}
catch(e){
return _throw(e);
return throwError(e);
}
}
}

Просмотреть файл

@ -1,8 +1,5 @@
import {Observable} from "rxjs/Observable";
import {from} from "rxjs/observable/from";
import {tap} from "rxjs/operators/tap";
import {of} from "rxjs/observable/of";
import {finalize, share} from "rxjs/operators";
import {from, Observable, of} from "rxjs";
import {finalize, share, tap} from "rxjs/operators";
export class DataCache<T = any>{
time:((item:T) => number) | number;

Просмотреть файл

@ -1,8 +1,7 @@
import {ParisConfig} from "../config/paris-config";
import {Http, HttpOptions, RequestMethod} from "./http.service";
import {Observable} from "rxjs/Observable";
import {finalize} from "rxjs/operators/finalize";
import {share} from "rxjs/operators/share";
import {Observable} from "rxjs";
import {finalize, share} from "rxjs/operators";
export class DataStoreService{
private activeRequests:Map<string, Observable<any>> = new Map();

Просмотреть файл

@ -1,9 +1,6 @@
import {Observable} from "rxjs/Observable";
import {AjaxRequest} from "rxjs/observable/dom/AjaxObservable";
import {AjaxError, AjaxResponse} from "rxjs/Rx";
import {ajax} from "rxjs/observable/dom/ajax";
import {map} from "rxjs/operators/map";
import {catchError} from "rxjs/operators/catchError";
import {Observable} from "rxjs";
import {ajax, AjaxError, AjaxRequest, AjaxResponse} from "rxjs/ajax";
import {catchError, map} from "rxjs/operators";
import * as _ from "lodash";
export type RequestMethod = "GET"|"POST"|"PUT"|"PATCH"|"DELETE";

Просмотреть файл

@ -6,9 +6,8 @@ import {entitiesService} from "./entities.service";
import {IRepository} from "../repository/repository.interface";
import {DataStoreService} from "./data-store.service";
import {EntityConfigBase} from "../entity/entity-config.base";
import {Observable} from "rxjs/Observable";
import {Observable, of, Subject, throwError} from "rxjs";
import {SaveEntityEvent} from "../events/save-entity.event";
import {Subject} from "rxjs/Subject";
import {RemoveEntitiesEvent} from "../events/remove-entities.event";
import {IRelationshipRepository, RelationshipRepository} from "../repository/relationship-repository";
import {ModelBase} from "../models/model.base";
@ -24,17 +23,14 @@ import {EntityErrorEvent, EntityErrorTypes} from "../events/entity-error.event";
import {ApiCallType} from "../models/api-call.model";
import {ApiCallBackendConfigInterface} from "../models/api-call-backend-config.interface";
import {modelArray, rawDataToDataSet} from "../repository/data-to-model";
import {_throw} from "rxjs/observable/throw";
import {catchError} from "rxjs/operators/catchError";
import {map, mergeMap, switchMap, tap} from "rxjs/operators";
import {catchError, map, mergeMap, switchMap, tap} from "rxjs/operators";
import {DataTransformersService} from "./data-transformers.service";
import {DataCache, DataCacheSettings} from "./cache";
import {of} from "rxjs/observable/of";
import * as _ from "lodash";
export class Paris{
private repositories:Map<DataEntityType, IRepository> = new Map;
private relationshipRepositories:Map<string, IRelationshipRepository> = new Map;
private repositories:Map<DataEntityType, IRepository<ModelBase>> = new Map;
private relationshipRepositories:Map<string, IRelationshipRepository<ModelBase>> = new Map;
readonly dataStore:DataStoreService;
readonly config:ParisConfig;
@ -242,7 +238,7 @@ export class Paris{
if (backendConfig.parseData) {
return this.dataStore.request<TRawDataResult>(method || "GET", endpoint, apiCallHttpOptions, baseUrl).pipe(
catchError(err => {
return _throw({
return throwError({
originalError: err,
type: EntityErrorTypes.HttpError,
entity: null
@ -265,7 +261,7 @@ export class Paris{
return this.dataStore.request<TResult>(method || "GET", endpoint, apiCallHttpOptions, baseUrl).pipe(
catchError(err => {
return _throw({
return throwError({
originalError: err,
type: EntityErrorTypes.HttpError,
entity: null
@ -312,7 +308,7 @@ export class Paris{
}
createItem<T extends ModelBase>(entityConstructor:DataEntityConstructor<T>, data:any, dataOptions: DataOptions = defaultDataOptions, query?:DataQuery):Observable<T>{
return ReadonlyRepository.getModelData(data, entityConstructor.entityConfig || entityConstructor.valueObjectConfig, this.config, this, dataOptions, query);
return ReadonlyRepository.getModelData<T>(data, entityConstructor.entityConfig || entityConstructor.valueObjectConfig, this.config, this, dataOptions, query);
}
getItemById<T extends ModelBase>(entityConstructor:DataEntityConstructor<T>, itemId: string | number, options?:DataOptions, params?:{ [index:string]:any }): Observable<T>{

Просмотреть файл

@ -1,18 +1,15 @@
{
"name": "wcdportal.paris",
"version": "0.7.14",
"version": "0.8.0",
"description": "Library for the implementation of Domain Driven Design in Angular/TypeScript apps",
"repository": {
"type": "git",
"url": "https://microsoft.visualstudio.com/DefaultCollection/WDATP/_git/Paris"
},
"dist": "./bundle",
"main": "bundle/paris.cjs.js",
"module": "bundle/paris.esm.js",
"browser": "bundle/paris.umd.js",
"typings": "index.d.ts",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"scripts": {
"build": "gulp build && rollup -c",
"build": "gulp build",
"dev": "rollup -c -w",
"bundle": "npm run build",
"publish": "npm run bundle && npm publish"
@ -53,15 +50,15 @@
"rollup-plugin-commonjs": "^8.2.4",
"rollup-plugin-node-resolve": "^3.0.0",
"rollup-plugin-typescript": "^0.8.1",
"rxjs": ">=5.2.0",
"run-sequence": "^2.2.0",
"rxjs": "^6.0.0",
"standard-version": "^3.0.0",
"systemjs": ">=0.20.12",
"typescript": "^2.4.2",
"zone.js": ">=0.8.7",
"run-sequence": "^2.2.0"
"typescript": "^2.7.2",
"zone.js": ">=0.8.7"
},
"peerDependencies": {
"rxjs": ">=5.2.0",
"rxjs": ">=6.0.0",
"lodash.get": ">=4.4.2",
"lodash.findIndex": ">=4.4.2",
"lodash.clone": ">=4.4.2",

Просмотреть файл

@ -1,39 +1,52 @@
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import pkg from './package.json';
// found this online, it does seem to correctly rewrite the rxjs paths
// but is it helping or hurting?
class RollupRx {
constructor( options ){
this.options = options;
}
resolveId( id ){
if(id.startsWith('rxjs/')){
return `${__dirname}/node_modules/rxjs-es/${id.replace('rxjs/', '')}.js`;
}
}
}
const rollupRx = config => new RollupRx( config );
//
// // found this online, it does seem to correctly rewrite the rxjs paths
// // but is it helping or hurting?
// class RollupRx {
//
// constructor(options) {
// this.options = options;
// }
//
// resolveId(id) {
// if (id.startsWith('rxjs/')) {
// return `${__dirname}/node_modules/rxjs-es/${id.replace('rxjs/', '')}.js`;
// }
// }
// }
//
// const rollupRx = config => new RollupRx(config);
export default [
// browser-friendly UMD build
{
entry: 'bundle/lib/main.js',
dest: pkg.browser,
format: 'umd',
moduleName: 'paris',
input: 'dist/lib/main.js',
name: 'wcdportal.paris',
output: [
{
file: pkg.main,
format: 'umd'
},
{
file: pkg.module,
format: 'es'
}
],
plugins: [
resolve(), // so Rollup can find `ms`
commonjs() // so Rollup can convert `ms` to an ES module
],
external: id => {
return /^(rxjs|lodash)/.test(id);
}
}
},
globals: {
rxjs: 'rxjs',
'rxjs/operators': 'rxjs/operators',
'rxjs/ajax': 'rxjs/ajax'
},
},
/*
,

Просмотреть файл

@ -1,8 +1,6 @@
import {ChangeDetectionStrategy, Component} from '@angular/core';
import './operators';
import {TodoItemModel} from "./@model/todo-item.model";
import {Observable} from "rxjs/Observable";
import {BehaviorSubject} from "rxjs/BehaviorSubject";
import {Observable} from "rxjs";
import {Repository} from "../../../lib/repository/repository";
import {RepositoryManagerService} from "../../../lib/repository/repository-manager.service";
import {ProtectionLevel} from "./@model/atp/protection-levels/protection-level.entity";

Просмотреть файл

@ -1,15 +0,0 @@
// rxjs
import 'rxjs/add/observable/throw';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';
import 'rxjs/add/observable/of';
import 'rxjs/add/observable/combineLatest';
import 'rxjs/add/observable/from';
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/mergeMap';
import 'rxjs/add/operator/share';
import 'rxjs/add/operator/finally';
import 'rxjs/add/operator/toPromise';
import 'rxjs/add/observable/merge';
import "reflect-metadata";

Просмотреть файл

@ -14,8 +14,8 @@
"noImplicitUseStrict": false,
"noFallthroughCasesInSwitch": true,
"typeRoots": [
"../node_modules/@types",
"../node_modules"
"node_modules/@types",
"node_modules"
],
"types" : ["node"], // only use needed types
"baseUrl": "/",
@ -27,9 +27,5 @@
"../node_modules/rxjs/*"
]
}
},
"include": [
"index.ts",
"lib/**/*"
]
}
}

28
tsconfig.lib.json Normal file
Просмотреть файл

@ -0,0 +1,28 @@
{
"compilerOptions": {
"lib": ["es2015", "dom"], // we target Node.js(v6)
"target": "es5", // we target Node.js(v6)
"module": "es2015",
"moduleResolution": "node", // we target Node.js(v6)
"declaration": true, // generate TypeScript definitions
"rootDir": ".",
"outDir": "./dist",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitUseStrict": false,
"noFallthroughCasesInSwitch": true,
"typeRoots": [
"node_modules/@types",
"node_modules"
],
"types" : ["node"], // only use needed types
"baseUrl": "/"
},
"include": [
"index.ts",
"lib/**/*"
]
}