This commit is contained in:
Yossi Kolesnicov 2017-11-22 16:45:03 +02:00
Родитель 561d6ed71a
Коммит 6ac7de4212
68 изменённых файлов: 0 добавлений и 2623 удалений

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

@ -3,7 +3,6 @@
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
<excludeFolder url="file://$MODULE_DIR$/bundle" />
<excludeFolder url="file://$MODULE_DIR$/definitions" />
<excludeFolder url="file://$MODULE_DIR$/src" />
<excludeFolder url="file://$MODULE_DIR$/temp" />

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

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

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

@ -1,6 +0,0 @@
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
__export(require("./lib/main"));

11
bundle/lib/config/paris-config.d.ts поставляемый
Просмотреть файл

@ -1,11 +0,0 @@
export interface ParisConfig {
apiRoot?: string;
allItemsProperty?: string;
entityIdProperty?: string;
data?: any;
http?: ParisHttpConfig;
}
export declare const defaultConfig: ParisConfig;
export interface ParisHttpConfig {
headers?: any;
}

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

@ -1,6 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.defaultConfig = {
allItemsProperty: "items",
entityIdProperty: "id"
};

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

@ -1,5 +0,0 @@
export declare enum DataAvailability {
deep = 0,
flat = 1,
available = 2,
}

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

@ -1,8 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var DataAvailability;
(function (DataAvailability) {
DataAvailability[DataAvailability["deep"] = 0] = "deep";
DataAvailability[DataAvailability["flat"] = 1] = "flat";
DataAvailability[DataAvailability["available"] = 2] = "available";
})(DataAvailability = exports.DataAvailability || (exports.DataAvailability = {}));

6
bundle/lib/dataset/data.options.d.ts поставляемый
Просмотреть файл

@ -1,6 +0,0 @@
import { DataAvailability } from "./data-availability.enum";
export interface DataOptions {
allowCache?: boolean;
availability?: DataAvailability;
}
export declare const defaultDataOptions: DataOptions;

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

@ -1,7 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var data_availability_enum_1 = require("./data-availability.enum");
exports.defaultDataOptions = {
allowCache: true,
availability: data_availability_enum_1.DataAvailability.deep
};

4
bundle/lib/dataset/dataset.d.ts поставляемый
Просмотреть файл

@ -1,4 +0,0 @@
export interface DataSet<T> {
count: number;
items: Array<T>;
}

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

@ -1,2 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

12
bundle/lib/entity/data-entity.base.d.ts поставляемый
Просмотреть файл

@ -1,12 +0,0 @@
import { EntityModelConfigBase } from "../models/entity-config-base.interface";
import { ModelEntity } from "./entity.config";
import { EntityConfigBase } from "./entity-config.base";
import { ModelBase } from "../models/model.base";
export interface DataEntityConstructor<T extends ModelBase> extends DataEntityType {
new (data?: any, rawData?: any): T;
}
export interface DataEntityType {
new (data?: EntityModelConfigBase, rawData?: any): any;
entityConfig?: ModelEntity;
valueObjectConfig?: EntityConfigBase;
}

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

@ -1,2 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

28
bundle/lib/entity/entity-config.base.d.ts поставляемый
Просмотреть файл

@ -1,28 +0,0 @@
import { EntityFields } from "./entity-fields";
import { Field } from "./entity-field";
import { EntityModelConfigBase } from "../models/entity-config-base.interface";
import { DataEntityConstructor } from "./data-entity.base";
export declare class EntityConfigBase {
entityConstructor: DataEntityConstructor<any>;
singularName: string;
pluralName: string;
fields?: EntityFields;
idProperty?: string;
readonly: boolean;
readonly fieldsArray: Array<Field>;
values: ReadonlyArray<any>;
private _valuesMap;
private readonly valuesMap;
constructor(config: IEntityConfigBase, entityConstructor: DataEntityConstructor<any>);
getValueById<T>(valueId: string | number): T;
getDefaultValue<T>(): T;
hasValue(valueId: string | number): boolean;
}
export interface IEntityConfigBase {
singularName: string;
pluralName: string;
fields?: EntityFields;
idProperty?: string;
readonly?: boolean;
values?: Array<EntityModelConfigBase>;
}

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

@ -1,51 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var immutability_1 = require("../services/immutability");
var DEFAULT_VALUE_ID = "__default";
var EntityConfigBase = /** @class */ (function () {
function EntityConfigBase(config, entityConstructor) {
this.entityConstructor = entityConstructor;
this.readonly = false;
if (config.values) {
config.values = config.values.map(function (valueConfig) { return new entityConstructor(valueConfig); });
immutability_1.Immutability.freeze(config.values);
}
Object.assign(this, config);
}
Object.defineProperty(EntityConfigBase.prototype, "fieldsArray", {
get: function () {
return this.fields ? Array.from(this.fields.values()) : [];
},
enumerable: true,
configurable: true
});
Object.defineProperty(EntityConfigBase.prototype, "valuesMap", {
get: function () {
var _this = this;
if (this._valuesMap === undefined) {
if (!this.values)
this._valuesMap = null;
else {
this._valuesMap = new Map;
this.values.forEach(function (value) {
_this._valuesMap.set(value.id === undefined || value.id === null ? DEFAULT_VALUE_ID : value.id, Object.freeze(value));
});
}
}
return this._valuesMap;
},
enumerable: true,
configurable: true
});
EntityConfigBase.prototype.getValueById = function (valueId) {
return this.valuesMap ? this.valuesMap.get(valueId) : null;
};
EntityConfigBase.prototype.getDefaultValue = function () {
return this.getValueById(DEFAULT_VALUE_ID) || null;
};
EntityConfigBase.prototype.hasValue = function (valueId) {
return this.valuesMap ? this.valuesMap.has(valueId) : false;
};
return EntityConfigBase;
}());
exports.EntityConfigBase = EntityConfigBase;

17
bundle/lib/entity/entity-field.d.ts поставляемый
Просмотреть файл

@ -1,17 +0,0 @@
import { DataEntityType } from "./data-entity.base";
import { ParisConfig } from "../config/paris-config";
export interface Field {
id?: string;
name?: string;
data?: "__self" | string | Array<string>;
entity?: DataEntityType;
type?: DataEntityType;
defaultValue?: any;
arrayOf?: DataEntityType;
isArray?: boolean;
required?: boolean;
require?: ((data: any, config?: ParisConfig) => any) | string;
parse?: Function;
}
export declare const FIELD_DATA_SELF = "__self";
export declare type EntityFieldConfigFunctionOrValue = ((data: any, config?: ParisConfig) => string) | string;

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

@ -1,2 +0,0 @@
import { Field } from "./entity-field";
export declare function EntityField(fieldConfig?: Field): PropertyDecorator;

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

@ -1,16 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var entity_fields_service_1 = require("../services/entity-fields.service");
function EntityField(fieldConfig) {
return function (entityPrototype, propertyKey) {
var propertyConstructor = window['Reflect'].getMetadata("design:type", entityPrototype, propertyKey);
fieldConfig = fieldConfig || {};
var fieldConfigCopy = Object.assign({}, fieldConfig);
if (!fieldConfigCopy.id)
fieldConfigCopy.id = String(propertyKey);
fieldConfigCopy.type = fieldConfig.arrayOf || propertyConstructor;
fieldConfigCopy.isArray = propertyConstructor === Array;
entity_fields_service_1.entityFieldsService.addField(entityPrototype, fieldConfigCopy);
};
}
exports.EntityField = EntityField;

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

@ -1,3 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FIELD_DATA_SELF = "__self";

2
bundle/lib/entity/entity-fields.d.ts поставляемый
Просмотреть файл

@ -1,2 +0,0 @@
import { Field } from "./entity-field";
export declare type EntityFields = Map<string, Field>;

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

@ -1,2 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

25
bundle/lib/entity/entity.config.d.ts поставляемый
Просмотреть файл

@ -1,25 +0,0 @@
import { EntityConfigBase, IEntityConfigBase } from "./entity-config.base";
import { ParisConfig } from "../config/paris-config";
import { DataEntityConstructor } from "./data-entity.base";
export declare class ModelEntity extends EntityConfigBase {
endpoint: EntityConfigFunctionOrValue;
loadAll?: boolean;
cache?: ModelEntityCacheConfig;
baseUrl?: EntityConfigFunctionOrValue;
allItemsProperty?: string;
allItemsEndpoint?: string;
constructor(config: EntityConfig, entityConstructor: DataEntityConstructor<any>);
}
export interface EntityConfig extends IEntityConfigBase {
endpoint?: EntityConfigFunctionOrValue;
loadAll?: boolean;
cache?: ModelEntityCacheConfig;
baseUrl?: EntityConfigFunctionOrValue;
allItemsProperty?: string;
allItemsEndpoint?: string;
}
export interface ModelEntityCacheConfig {
time?: number;
max?: number;
}
export declare type EntityConfigFunctionOrValue = ((config?: ParisConfig) => string) | string;

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

@ -1,26 +0,0 @@
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var entity_config_base_1 = require("./entity-config.base");
var ModelEntity = /** @class */ (function (_super) {
__extends(ModelEntity, _super);
function ModelEntity(config, entityConstructor) {
var _this = _super.call(this, config, entityConstructor) || this;
_this.loadAll = false;
_this.loadAll = config.loadAll === true;
if (!_this.endpoint && !_this.values)
throw new Error("Can't create entity " + _this.entityConstructor.name + ", no endpoint or values defined.");
return _this;
}
return ModelEntity;
}(entity_config_base_1.EntityConfigBase));
exports.ModelEntity = ModelEntity;

3
bundle/lib/entity/entity.decorator.d.ts поставляемый
Просмотреть файл

@ -1,3 +0,0 @@
import { EntityConfig } from "./entity.config";
import { DataEntityType } from "./data-entity.base";
export declare function Entity(config: EntityConfig): (target: DataEntityType) => void;

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

@ -1,12 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var entity_config_1 = require("./entity.config");
var entities_service_1 = require("../services/entities.service");
function Entity(config) {
return function (target) {
var entity = new entity_config_1.ModelEntity(config, target.prototype.constructor);
target.entityConfig = entity;
entities_service_1.entitiesService.addEntity(target, entity);
};
}
exports.Entity = Entity;

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

@ -1,3 +0,0 @@
import { DataEntityType } from "./data-entity.base";
import { IEntityConfigBase } from "./entity-config.base";
export declare function ValueObject(config: IEntityConfigBase): (target: DataEntityType) => void;

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

@ -1,12 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var value_objects_service_1 = require("../services/value-objects.service");
var entity_config_base_1 = require("./entity-config.base");
function ValueObject(config) {
return function (target) {
var valueObjectConfig = new entity_config_base_1.EntityConfigBase(config, target.prototype.constructor);
target.valueObjectConfig = valueObjectConfig;
value_objects_service_1.valueObjectsService.addEntity(target, valueObjectConfig);
};
}
exports.ValueObject = ValueObject;

32
bundle/lib/main.d.ts поставляемый
Просмотреть файл

@ -1,32 +0,0 @@
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 'rxjs/add/observable/dom/ajax';
export { DataEntityType } from "./entity/data-entity.base";
export { Paris } from "./services/paris";
export { DataStoreService } from "./services/data-store.service";
export { EntityModelBase } from "./models/entity-model.base";
export { ModelBase } from "./models/model.base";
export { Repository } from "./repository/repository";
export { IRepository } from "./repository/repository.interface";
export { EntityModelConfigBase } from "./models/entity-config-base.interface";
export { ParisConfig } from "./config/paris-config";
export { DataTransformersService, DataTransformer } from "./services/data-transformers.service";
export { ModelEntity, EntityConfig, ModelEntityCacheConfig } from "./entity/entity.config";
export { EntityField } from "./entity/entity-field.decorator";
export { ValueObject } from "./entity/value-object.decorator";
export { Entity } from "./entity/entity.decorator";
export { DataQuery } from "./dataset/data-query";
export { DataQuerySortDirection, DataQuerySortField } from "./dataset/data-query-sort";
export { HttpOptions } from "./services/http.service";
export { DataAvailability } from "./dataset/data-availability.enum";
export { DataSet } from "./dataset/dataset";

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

@ -1,39 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("rxjs/add/observable/throw");
require("rxjs/add/operator/map");
require("rxjs/add/operator/catch");
require("rxjs/add/observable/of");
require("rxjs/add/observable/combineLatest");
require("rxjs/add/observable/from");
require("rxjs/add/operator/do");
require("rxjs/add/operator/mergeMap");
require("rxjs/add/operator/share");
require("rxjs/add/operator/finally");
require("rxjs/add/operator/toPromise");
require("rxjs/add/observable/merge");
require("rxjs/add/observable/dom/ajax");
var paris_1 = require("./services/paris");
exports.Paris = paris_1.Paris;
var data_store_service_1 = require("./services/data-store.service");
exports.DataStoreService = data_store_service_1.DataStoreService;
var entity_model_base_1 = require("./models/entity-model.base");
exports.EntityModelBase = entity_model_base_1.EntityModelBase;
var model_base_1 = require("./models/model.base");
exports.ModelBase = model_base_1.ModelBase;
var repository_1 = require("./repository/repository");
exports.Repository = repository_1.Repository;
var data_transformers_service_1 = require("./services/data-transformers.service");
exports.DataTransformersService = data_transformers_service_1.DataTransformersService;
var entity_config_1 = require("./entity/entity.config");
exports.ModelEntity = entity_config_1.ModelEntity;
var entity_field_decorator_1 = require("./entity/entity-field.decorator");
exports.EntityField = entity_field_decorator_1.EntityField;
var value_object_decorator_1 = require("./entity/value-object.decorator");
exports.ValueObject = value_object_decorator_1.ValueObject;
var entity_decorator_1 = require("./entity/entity.decorator");
exports.Entity = entity_decorator_1.Entity;
var data_query_sort_1 = require("./dataset/data-query-sort");
exports.DataQuerySortDirection = data_query_sort_1.DataQuerySortDirection;
var data_availability_enum_1 = require("./dataset/data-availability.enum");
exports.DataAvailability = data_availability_enum_1.DataAvailability;

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

@ -1,4 +0,0 @@
export interface EntityModelConfigBase {
id: string | number;
[index: string]: any;
}

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

@ -1,2 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

6
bundle/lib/models/entity-model.base.d.ts поставляемый
Просмотреть файл

@ -1,6 +0,0 @@
import { ModelBase } from "./model.base";
import { EntityModelConfigBase } from "./entity-config-base.interface";
export declare class EntityModelBase extends ModelBase {
id: string | number;
constructor(data: EntityModelConfigBase);
}

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

@ -1,35 +0,0 @@
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
var model_base_1 = require("./model.base");
var entity_field_decorator_1 = require("../entity/entity-field.decorator");
var EntityModelBase = /** @class */ (function (_super) {
__extends(EntityModelBase, _super);
function EntityModelBase(data) {
return _super.call(this, data) || this;
}
__decorate([
entity_field_decorator_1.EntityField(),
__metadata("design:type", Object)
], EntityModelBase.prototype, "id", void 0);
return EntityModelBase;
}(model_base_1.ModelBase));
exports.EntityModelBase = EntityModelBase;

3
bundle/lib/models/index.d.ts поставляемый
Просмотреть файл

@ -1,3 +0,0 @@
export declare type Index = {
[index: string]: any;
};

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

@ -1,2 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

4
bundle/lib/models/model.base.d.ts поставляемый
Просмотреть файл

@ -1,4 +0,0 @@
export declare class ModelBase {
$parent?: ModelBase;
constructor(data?: any);
}

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

@ -1,11 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var ModelBase = /** @class */ (function () {
function ModelBase(data) {
if (data) {
Object.assign(this, data);
}
}
return ModelBase;
}());
exports.ModelBase = ModelBase;

13
bundle/lib/operators.d.ts поставляемый
Просмотреть файл

@ -1,13 +0,0 @@
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 'rxjs/add/observable/dom/ajax';

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

@ -1,16 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// rxjs
require("rxjs/add/observable/throw");
require("rxjs/add/operator/map");
require("rxjs/add/operator/catch");
require("rxjs/add/observable/of");
require("rxjs/add/observable/combineLatest");
require("rxjs/add/observable/from");
require("rxjs/add/operator/do");
require("rxjs/add/operator/mergeMap");
require("rxjs/add/operator/share");
require("rxjs/add/operator/finally");
require("rxjs/add/operator/toPromise");
require("rxjs/add/observable/merge");
require("rxjs/add/observable/dom/ajax");

55
bundle/lib/repository/repository.d.ts поставляемый
Просмотреть файл

@ -1,55 +0,0 @@
import { ModelEntity } from "../entity/entity.config";
import { DataEntityConstructor } from "../entity/data-entity.base";
import { Observable } from "rxjs/Observable";
import { IRepository } from "./repository.interface";
import { DataStoreService } from "../services/data-store.service";
import { ParisConfig } from "../config/paris-config";
import { DataQuery } from "../dataset/data-query";
import { DataSet } from "../dataset/dataset";
import { Index } from "../models/index";
import { EntityConfigBase } from "../entity/entity-config.base";
import { ModelBase } from "../models/model.base";
import { EntityModelBase } from "../models/entity-model.base";
import { DataOptions } from "../dataset/data.options";
import { Paris } from "../services/paris";
export declare class Repository<T extends EntityModelBase> implements IRepository {
readonly entity: ModelEntity;
private config;
private entityConstructor;
private dataStore;
private paris;
save$: Observable<T>;
private _allItems$;
private _allValues;
private _allValuesMap;
private _cache;
private _allItemsSubject$;
private _saveSubject$;
readonly allItems$: Observable<Array<T>>;
private readonly cache;
private readonly baseUrl;
readonly endpointName: string;
readonly endpointUrl: string;
constructor(entity: ModelEntity, config: ParisConfig, entityConstructor: DataEntityConstructor<T>, dataStore: DataStoreService, paris: Paris);
createItem(itemData: any, options?: DataOptions): Observable<T>;
createNewItem(): T;
/**
* Populates the item dataset with any sub @model. For example, if an ID is found for a property whose type is an entity,
* the property's value will be an instance of that entity, for the ID, not the ID.
* @param {Index} rawData
* @param {EntityConfigBase} entity
* @param {ParisConfig} config
* @param {Paris} paris
* @param {DataOptions} options
* @returns {Observable<T extends EntityModelBase>}
*/
static getModelData<T extends ModelBase>(rawData: Index, entity: EntityConfigBase, config: ParisConfig, paris: Paris, options?: DataOptions): Observable<T>;
private static getSubModel(entityField, value, paris, config, options?);
private static mapToEntityFieldIndex(entityFieldId, value);
private static getEntityItem<U>(repository, data, options?);
private static getValueObjectItem<U>(valueObjectType, data, options, paris, config?);
query(query?: DataQuery, dataOptions?: DataOptions): Observable<DataSet<T>>;
getItemById(itemId: string | number, options?: DataOptions): Observable<T>;
private setAllItems();
getItemSaveData(item: T): Index;
}

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

@ -1,16 +0,0 @@
import { Observable } from "rxjs/Observable";
import { DataQuery } from "../dataset/data-query";
import { DataSet } from "../dataset/dataset";
import { ModelEntity } from "../entity/entity.config";
import { EntityModelBase } from "../models/entity-model.base";
export interface IRepository {
entity: ModelEntity;
createItem: (itemData: any) => Observable<Readonly<any>>;
createNewItem: () => EntityModelBase;
getItemById: (id: any) => Observable<any>;
query: (options?: DataQuery) => Observable<DataSet<any>>;
getItemSaveData: (item: EntityModelBase) => Object;
allItems$: Observable<Array<any>>;
endpointName: string;
endpointUrl: string;
}

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

@ -1,2 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

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

@ -1,336 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var entity_config_1 = require("../entity/entity.config");
var Observable_1 = require("rxjs/Observable");
var Subject_1 = require("rxjs/Subject");
var entity_field_1 = require("../entity/entity-field");
var data_transformers_service_1 = require("../services/data-transformers.service");
var cache_1 = require("../services/cache");
var value_objects_service_1 = require("../services/value-objects.service");
var _ = require("lodash");
var data_options_1 = require("../dataset/data.options");
var dataset_service_1 = require("../services/dataset.service");
var data_availability_enum_1 = require("../dataset/data-availability.enum");
var errors_service_1 = require("../services/errors.service");
var Repository = /** @class */ (function () {
function Repository(entity, config, entityConstructor, dataStore, paris) {
this.entity = entity;
this.config = config;
this.entityConstructor = entityConstructor;
this.dataStore = dataStore;
this.paris = paris;
var getAllItems$ = this.query().map(function (dataSet) { return dataSet.items; });
this._allItemsSubject$ = new Subject_1.Subject();
this._allItems$ = Observable_1.Observable.merge(getAllItems$, this._allItemsSubject$.asObservable());
this._saveSubject$ = new Subject_1.Subject();
this.save$ = this._saveSubject$.asObservable();
}
Object.defineProperty(Repository.prototype, "allItems$", {
get: function () {
if (this._allValues)
return Observable_1.Observable.merge(Observable_1.Observable.of(this._allValues), this._allItemsSubject$.asObservable());
if (this.entity.loadAll)
return this.setAllItems();
return this._allItems$;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Repository.prototype, "cache", {
get: function () {
var _this = this;
if (!this._cache) {
var cacheSettings = Object.assign({
getter: function (itemId) { return _this.getItemById(itemId, { allowCache: false }); }
}, this.entity.cache);
this._cache = new cache_1.DataCache(cacheSettings);
}
return this._cache;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Repository.prototype, "baseUrl", {
get: function () {
if (!this.entity.baseUrl)
return null;
return this.entity.baseUrl instanceof Function ? this.entity.baseUrl(this.config) : this.entity.baseUrl;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Repository.prototype, "endpointName", {
get: function () {
return this.entity.endpoint instanceof Function ? this.entity.endpoint(this.config) : this.entity.endpoint;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Repository.prototype, "endpointUrl", {
get: function () {
return this.baseUrl + "/" + this.endpointName;
},
enumerable: true,
configurable: true
});
Repository.prototype.createItem = function (itemData, options) {
if (options === void 0) { options = { allowCache: true, availability: data_availability_enum_1.DataAvailability.available }; }
return Repository.getModelData(itemData, this.entity, this.config, this.paris, options);
};
Repository.prototype.createNewItem = function () {
return new this.entityConstructor();
};
/**
* Populates the item dataset with any sub @model. For example, if an ID is found for a property whose type is an entity,
* the property's value will be an instance of that entity, for the ID, not the ID.
* @param {Index} rawData
* @param {EntityConfigBase} entity
* @param {ParisConfig} config
* @param {Paris} paris
* @param {DataOptions} options
* @returns {Observable<T extends EntityModelBase>}
*/
Repository.getModelData = function (rawData, entity, config, paris, options) {
if (options === void 0) { options = data_options_1.defaultDataOptions; }
var entityIdProperty = entity.idProperty || config.entityIdProperty, modelData = entity instanceof entity_config_1.ModelEntity ? { id: rawData[entityIdProperty] } : {}, subModels = [];
var getModelDataError = new Error("Failed to create " + entity.singularName + ".");
entity.fields.forEach(function (entityField) {
if (entityField.require) {
var failed = false;
if (entityField.require instanceof Function && !entityField.require(rawData, paris.config))
failed = true;
else if (typeof (entityField.require) === "string") {
var rawDataPropertyValue = rawData[entityField.require];
if (rawDataPropertyValue === undefined || rawDataPropertyValue === null)
failed = true;
}
if (failed) {
modelData[entityField.id] = null;
return;
}
}
var propertyValue;
if (entityField.data) {
if (entityField.data instanceof Array) {
for (var i = 0, path = void 0; i < entityField.data.length && propertyValue === undefined; i++) {
path = entityField.data[i];
var value = path === entity_field_1.FIELD_DATA_SELF ? rawData : _.get(rawData, path);
if (value !== undefined && value !== null)
propertyValue = value;
}
}
else
propertyValue = entityField.data === entity_field_1.FIELD_DATA_SELF ? rawData : _.get(rawData, entityField.data);
}
else
propertyValue = rawData[entityField.id];
if (entityField.parse) {
try {
propertyValue = entityField.parse(propertyValue);
}
catch (e) {
getModelDataError.message = getModelDataError.message + (" Error parsing field " + entityField.id + ": ") + e.message;
throw getModelDataError;
}
}
if (propertyValue === undefined || propertyValue === null) {
var fieldRepository = paris.getRepository(entityField.type);
var fieldValueObjectType = !fieldRepository && value_objects_service_1.valueObjectsService.getEntityByType(entityField.type);
var defaultValue = fieldRepository && fieldRepository.entity.getDefaultValue()
|| fieldValueObjectType && fieldValueObjectType.getDefaultValue()
|| (entityField.isArray ? [] : entityField.defaultValue || null);
if (!defaultValue && entityField.required) {
getModelDataError.message = getModelDataError.message + (" Field " + entityField.id + " is required but it's " + propertyValue + ".");
throw getModelDataError;
}
modelData[entityField.id] = defaultValue;
}
else {
var getPropertyEntityValue$ = Repository.getSubModel(entityField, propertyValue, paris, config, options);
if (getPropertyEntityValue$)
subModels.push(getPropertyEntityValue$);
else {
modelData[entityField.id] = entityField.isArray
? propertyValue
? propertyValue.map(function (elementValue) { return data_transformers_service_1.DataTransformersService.parse(entityField.type, elementValue); })
: []
: data_transformers_service_1.DataTransformersService.parse(entityField.type, propertyValue);
}
}
});
var model$;
if (subModels.length) {
model$ = Observable_1.Observable.combineLatest.apply(Observable_1.Observable, subModels).map(function (propertyEntityValues) {
propertyEntityValues.forEach(function (propertyEntityValue) { return Object.assign(modelData, propertyEntityValue); });
var model;
try {
model = new entity.entityConstructor(modelData, rawData);
}
catch (e) {
getModelDataError.message = getModelDataError.message + " Error: " + e.message;
throw getModelDataError;
}
propertyEntityValues.forEach(function (modelPropertyValue) {
for (var p in modelPropertyValue) {
var modelValue = modelPropertyValue[p];
if (modelValue instanceof Array)
modelValue.forEach(function (modelValueItem) {
if (!Object.isFrozen(modelValueItem))
modelValueItem.$parent = model;
});
else if (!Object.isFrozen(modelValue))
modelValue.$parent = model;
}
});
return model;
});
}
else {
var model = void 0;
try {
model = new entity.entityConstructor(modelData, rawData);
}
catch (e) {
getModelDataError.message = getModelDataError.message + " Error: " + e.message;
throw getModelDataError;
}
model$ = Observable_1.Observable.of(model);
}
return entity.readonly ? model$.map(function (model) { return Object.freeze(model); }) : model$;
};
Repository.getSubModel = function (entityField, value, paris, config, options) {
if (options === void 0) { options = data_options_1.defaultDataOptions; }
var getPropertyEntityValue$;
var mapValueToEntityFieldIndex = Repository.mapToEntityFieldIndex.bind(null, entityField.id);
var repository = paris.getRepository(entityField.type);
var valueObjectType = !repository && value_objects_service_1.valueObjectsService.getEntityByType(entityField.type);
if (!repository && !valueObjectType)
return null;
var getItem = repository
? Repository.getEntityItem.bind(null, repository)
: Repository.getValueObjectItem.bind(null, valueObjectType);
if (entityField.isArray) {
if (value.length) {
var propertyMembers$ = value.map(function (memberData) { return getItem(memberData, options, paris, config); });
getPropertyEntityValue$ = Observable_1.Observable.combineLatest.apply(Observable_1.Observable, propertyMembers$).map(mapValueToEntityFieldIndex);
}
else
getPropertyEntityValue$ = Observable_1.Observable.of([]).map(mapValueToEntityFieldIndex);
}
else
getPropertyEntityValue$ = getItem(value, options, paris, config)
.map(mapValueToEntityFieldIndex);
return getPropertyEntityValue$;
};
Repository.mapToEntityFieldIndex = function (entityFieldId, value) {
var data = {};
data[entityFieldId] = value;
return data;
};
Repository.getEntityItem = function (repository, data, options) {
if (options === void 0) { options = data_options_1.defaultDataOptions; }
return Object(data) === data ? repository.createItem(data, options) : repository.getItemById(data, options);
};
Repository.getValueObjectItem = function (valueObjectType, data, options, paris, config) {
if (options === void 0) { options = data_options_1.defaultDataOptions; }
// If the value object is one of a list of values, just set it to the model
if (valueObjectType.values)
return Observable_1.Observable.of(valueObjectType.getValueById(data) || valueObjectType.getDefaultValue() || null);
return Repository.getModelData(data, valueObjectType, config, paris, options);
};
Repository.prototype.query = function (query, dataOptions) {
var _this = this;
if (dataOptions === void 0) { dataOptions = data_options_1.defaultDataOptions; }
var queryError = new Error("Failed to get " + this.entity.pluralName + ".");
var httpOptions = dataset_service_1.DatasetService.queryToHttpOptions(query);
return this.dataStore.get(this.endpointName + "/" + (this.entity.allItemsEndpoint || ''), httpOptions, this.baseUrl)
.map(function (rawDataSet) {
var allItemsProperty = _this.entity.allItemsProperty || _this.config.allItemsProperty;
var rawItems = rawDataSet instanceof Array ? rawDataSet : rawDataSet[allItemsProperty];
if (!rawItems)
errors_service_1.ErrorsService.warn("Property '" + _this.config.allItemsProperty + "' wasn't found in DataSet for Entity '" + _this.entity.pluralName + "'.");
return {
count: rawDataSet.count,
items: rawItems
};
})
.flatMap(function (dataSet) {
var itemCreators = dataSet.items.map(function (itemData) { return _this.createItem(itemData, dataOptions); });
return Observable_1.Observable.combineLatest.apply(_this, itemCreators).map(function (items) {
return Object.freeze({
count: dataSet.count,
items: items
});
}).catch(function (error) {
queryError.message = queryError.message + " Error: " + error.message;
throw queryError;
});
});
};
Repository.prototype.getItemById = function (itemId, options) {
var _this = this;
if (options === void 0) { options = data_options_1.defaultDataOptions; }
if (this.entity.values) {
var entityValue = void 0;
if (itemId !== null && itemId !== undefined) {
if (this.entity.hasValue(itemId))
entityValue = this.entity.getValueById(itemId);
else
errors_service_1.ErrorsService.warn("Unknown value for " + this.entity.singularName + ": ", itemId);
}
return Observable_1.Observable.of(entityValue || this.entity.getDefaultValue());
}
if (options.allowCache !== false && this.entity.cache)
return this.cache.get(itemId);
if (this.entity.loadAll)
return this.setAllItems().map(function () { return _this._allValuesMap.get(String(itemId)); });
else {
return this.dataStore.get(this.endpointName + "/" + itemId)
.flatMap(function (data) { return _this.createItem(data, options); });
}
};
Repository.prototype.setAllItems = function () {
var _this = this;
if (this._allValues)
return Observable_1.Observable.of(this._allValues);
return this.query().do(function (dataSet) {
_this._allValues = dataSet.items;
_this._allValuesMap = new Map();
_this._allValues.forEach(function (value) { return _this._allValuesMap.set(String(value.id), value); });
}).map(function (dataSet) { return dataSet.items; });
};
// save(item: T): Observable<T> {
// let saveData: Index = this.getItemSaveData(item);
//
// return this.dataStore.post(`${this.endpoint}/${item.id || ''}`, saveData)
// .flatMap((savedItemData: Index) => this.createItem(savedItemData))
// .do((item: T) => {
// if (this._allValues) {
// this._allValues = [...this._allValues, item];
// this._allItemsSubject$.next(this._allValues);
// }
//
// this._saveSubject$.next(item);
// });
// }
Repository.prototype.getItemSaveData = function (item) {
var modelData = {};
for (var propertyId in item) {
if (item.hasOwnProperty(propertyId)) {
var modelValue = void 0;
var propertyValue = item[propertyId], entityField = this.entity.fields.get(propertyId);
if (entityField) {
var propertyRepository = this.paris.getRepository(entityField.type);
if (propertyRepository)
modelValue = propertyValue.id;
else
modelValue = data_transformers_service_1.DataTransformersService.serialize(entityField.type, propertyValue);
modelData[entityField.id] = modelValue;
}
}
}
return modelData;
};
return Repository;
}());
exports.Repository = Repository;

38
bundle/lib/services/cache.d.ts поставляемый
Просмотреть файл

@ -1,38 +0,0 @@
import { Observable } from "rxjs/Observable";
export declare class DataCache<T> {
time: number;
obj: number;
getter: (_: any) => Promise<T> | Observable<T>;
private _keys;
private _values;
private _timeouts;
private _getObservable;
constructor(settings?: DataCacheSettings<T>);
/**
* Gets a value from the cache collection.
* If getter is specified, uses it to get the data.
* @param key
* @returns {Observable<T>}
*/
get(key: any): Observable<T>;
/**
* Adds an item to the Cached collection. If DataCache.time was specified, the item will expire after this time (in milliseconds), and will be deleted.
* @param key {String}
* @param value
* @returns {Cache}
*/
add(key: any, value: T): DataCache<T>;
/**
* Removes an item from the cache collection.
* @param key
* @returns {*}
*/
remove(key: any): T;
clearGetters(): void;
private static validateSettings<T>(config?);
}
export interface DataCacheSettings<T> {
max?: number;
time?: number;
getter?: (_: any) => Observable<T>;
}

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

@ -1,104 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Observable_1 = require("rxjs/Observable");
var DataCache = /** @class */ (function () {
function DataCache(settings) {
DataCache.validateSettings(settings);
this.time = settings.time || null; // milliseconds
this.obj = settings.max;
this.getter = settings.getter;
this._keys = [];
this._values = new Map();
this._timeouts = {};
this._getObservable = {};
Object.seal(this);
}
/**
* Gets a value from the cache collection.
* If getter is specified, uses it to get the data.
* @param key
* @returns {Observable<T>}
*/
DataCache.prototype.get = function (key) {
var _this = this;
if (!key && key !== 0)
throw new Error("Can't get DataCache item, key not specified.");
key = key.toString();
if (this.getter) {
var getObservable = this._getObservable[key];
if (getObservable)
return getObservable;
var cachedItem = this._values.get(key);
if (cachedItem)
return Observable_1.Observable.of(cachedItem);
return this._getObservable[key] = Observable_1.Observable.from(this.getter(key))
.do(function (value) {
_this.add(key, value);
delete _this._getObservable[key];
});
}
else
return Observable_1.Observable.of(this._values.get(key));
};
/**
* Adds an item to the Cached collection. If DataCache.time was specified, the item will expire after this time (in milliseconds), and will be deleted.
* @param key {String}
* @param value
* @returns {Cache}
*/
DataCache.prototype.add = function (key, value) {
var _this = this;
key = key.toString();
var isNew = !this._values.has(key), valueTimeout = this._timeouts[key];
if (valueTimeout)
clearTimeout(valueTimeout);
this._values.set(key, value);
if (isNew) {
this._keys.push(key);
if (this._keys.length > this.obj)
this._values.delete(this._keys.shift());
}
if (this.time) {
this._timeouts[key] = setTimeout(function () {
_this.remove(key);
delete _this._timeouts[key];
}, this.time);
}
return this;
};
/**
* Removes an item from the cache collection.
* @param key
* @returns {*}
*/
DataCache.prototype.remove = function (key) {
key = key.toString();
var valueTimeout = this._timeouts[key];
if (valueTimeout) {
clearTimeout(valueTimeout);
delete this._timeouts[key];
}
delete this._getObservable[key];
var keyIndex = this._keys.indexOf(key);
if (~keyIndex) {
this._keys.splice(keyIndex, 1);
var value = this._values.get(key);
this._values.delete(key);
return value;
}
return null;
};
DataCache.prototype.clearGetters = function () {
for (var getter in this._getObservable)
delete this._getObservable[getter];
};
DataCache.validateSettings = function (config) {
if (!config)
return;
if (config.max < 1)
throw new Error("Invalid max for DataCache, should be at least 2.");
};
;
return DataCache;
}());
exports.DataCache = DataCache;

15
bundle/lib/services/data-store.service.d.ts поставляемый
Просмотреть файл

@ -1,15 +0,0 @@
import { ParisConfig } from "../config/paris-config";
import { HttpOptions } from "./http.service";
import { Observable } from "rxjs/Observable";
export declare class DataStoreService {
private config;
private activeRequests;
constructor(config: ParisConfig);
get(endpoint: string, data?: HttpOptions, baseUrl?: string): Observable<any>;
private getEndpointUrl(endpoint, baseUrl?);
private setActiveRequest(obs, verb, endpoint, data?);
private static getActiveRequestId(verb, endpoint, data?);
}
export interface RequestData {
[index: string]: any;
}

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

@ -1,41 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var http_service_1 = require("./http.service");
var Observable_1 = require("rxjs/Observable");
var DataStoreService = /** @class */ (function () {
function DataStoreService(config) {
this.config = config;
this.activeRequests = new Map();
}
DataStoreService.prototype.get = function (endpoint, data, baseUrl) {
return this.setActiveRequest(Observable_1.Observable.from(http_service_1.Http.get(this.getEndpointUrl(endpoint, baseUrl), data, this.config.http)), HttpVerb.get, endpoint, data);
};
// post(endpoint:string, data?:RequestData, baseUrl?:string):Observable<any>{
// return this.http.post(this.getEndpointUrl(endpoint, baseUrl), data);
// }
DataStoreService.prototype.getEndpointUrl = function (endpoint, baseUrl) {
return (baseUrl || this.config.apiRoot || "") + "/" + endpoint;
};
DataStoreService.prototype.setActiveRequest = function (obs, verb, endpoint, data) {
var _this = this;
var activeRequestId = DataStoreService.getActiveRequestId(verb, endpoint, data), existingActiveRequest = this.activeRequests.get(activeRequestId);
if (existingActiveRequest)
return existingActiveRequest;
else {
var warmObservable = obs.share();
obs.finally(function () { return _this.activeRequests.delete(activeRequestId); });
this.activeRequests.set(activeRequestId, warmObservable);
return warmObservable;
}
};
DataStoreService.getActiveRequestId = function (verb, endpoint, data) {
return verb + "__" + endpoint + "__" + (data ? JSON.stringify(data) : '|');
};
return DataStoreService;
}());
exports.DataStoreService = DataStoreService;
var HttpVerb;
(function (HttpVerb) {
HttpVerb["get"] = "GET";
HttpVerb["post"] = "POST";
})(HttpVerb || (HttpVerb = {}));

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

@ -1,10 +0,0 @@
import { DataEntityType } from "../entity/data-entity.base";
export declare class DataTransformersService {
static parse(type: DataEntityType, value: any): any;
static serialize(type: DataEntityType, value: any): any;
}
export interface DataTransformer {
type: any;
parse: Function;
serialize: Function;
}

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

@ -1,30 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var transformers = [
{
type: Date,
parse: function (dateValue) { return new Date(dateValue); },
serialize: function (date) { return date.valueOf(); }
},
{
type: RegExp,
parse: function (pattern) { return new RegExp(pattern); },
serialize: function (regExp) { return regExp ? regExp.toString().match(/^\/(.*)\/$/)[1] : null; }
}
];
var transformersMap = new Map;
transformers.forEach(function (transformer) { return transformersMap.set(transformer.type, transformer); });
var DataTransformersService = /** @class */ (function () {
function DataTransformersService() {
}
DataTransformersService.parse = function (type, value) {
var transformer = transformersMap.get(type);
return transformer ? transformer.parse(value) : value;
};
DataTransformersService.serialize = function (type, value) {
var transformer = transformersMap.get(type);
return transformer ? transformer.serialize(value) : value;
};
return DataTransformersService;
}());
exports.DataTransformersService = DataTransformersService;

5
bundle/lib/services/dataset.service.d.ts поставляемый
Просмотреть файл

@ -1,5 +0,0 @@
import { DataQuery } from "../dataset/data-query";
import { HttpOptions } from "./http.service";
export declare class DatasetService {
static queryToHttpOptions(query?: DataQuery): HttpOptions;
}

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

@ -1,27 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var data_query_sort_1 = require("../dataset/data-query-sort");
var DatasetService = /** @class */ (function () {
function DatasetService() {
}
DatasetService.queryToHttpOptions = function (query) {
if (!query)
return null;
var httpOptions = {};
httpOptions.params = {};
if (query.pageSize && query.pageSize > 0)
httpOptions.params.pagesize = query.pageSize;
if (query.page && query.page > 1)
httpOptions.params.page = query.page;
if (query.sortBy) {
httpOptions.params.sortBy = query.sortBy.map(function (sortField) {
return "" + (sortField.direction === data_query_sort_1.DataQuerySortDirection.descending ? '-' : '') + sortField.field;
}).join(",");
}
if (query.where)
Object.assign(httpOptions.params, query.where);
return httpOptions;
};
return DatasetService;
}());
exports.DatasetService = DatasetService;

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

@ -1,10 +0,0 @@
import { DataEntityType } from "../entity/data-entity.base";
import { EntityConfigBase } from "../entity/entity-config.base";
export declare abstract class EntitiesServiceBase<T extends EntityConfigBase> {
protected _allEntities: Map<DataEntityType, T>;
readonly allEntities: Array<T>;
getEntityByType(dataEntityType: DataEntityType): T;
addEntity(dataEntityType: DataEntityType, entity: T): T;
getEntityByPluralName(pluralName: string): DataEntityType;
private getDataEntityTypeFields(dataEntityType);
}

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

@ -1,48 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var entity_fields_service_1 = require("./entity-fields.service");
var EntitiesServiceBase = /** @class */ (function () {
function EntitiesServiceBase() {
this._allEntities = new Map;
}
Object.defineProperty(EntitiesServiceBase.prototype, "allEntities", {
get: function () {
return Array.from(this._allEntities.values());
},
enumerable: true,
configurable: true
});
EntitiesServiceBase.prototype.getEntityByType = function (dataEntityType) {
return this._allEntities.get(dataEntityType) || this._allEntities.get(dataEntityType.prototype);
};
EntitiesServiceBase.prototype.addEntity = function (dataEntityType, entity) {
if (!this._allEntities.has(dataEntityType))
this._allEntities.set(dataEntityType, entity);
entity.fields = this.getDataEntityTypeFields(dataEntityType);
// TODO: Clear the fields once the entity is populated, without affecting inherited fields.
return entity;
};
EntitiesServiceBase.prototype.getEntityByPluralName = function (pluralName) {
var allEntities = Array.from(this._allEntities.keys()), pluralNameLowerCase = pluralName.toLowerCase();
for (var i = 0, entity = void 0; entity = allEntities[i]; i++) {
if (entity.entityConfig.pluralName.toLowerCase() === pluralNameLowerCase)
return entity;
}
return null;
};
EntitiesServiceBase.prototype.getDataEntityTypeFields = function (dataEntityType) {
if (!dataEntityType)
return null;
var parentEntityDataType = Object.getPrototypeOf(dataEntityType).prototype, parentEntity = this._allEntities.get(parentEntityDataType), parentDataTypeFields = parentEntity && parentEntity.fields || this.getDataEntityTypeFields(parentEntityDataType) || null;
var fullDataEntityTypeFields = new Map;
if (parentDataTypeFields)
parentDataTypeFields.forEach(function (field, fieldId) { return fullDataEntityTypeFields.set(fieldId, field); });
var dataEntity = this.getEntityByType(dataEntityType);
var dataEntityTypeFields = dataEntity && dataEntity.fields || entity_fields_service_1.entityFieldsService.getDataTypeFields(dataEntityType);
if (dataEntityTypeFields)
dataEntityTypeFields.forEach(function (field, fieldId) { return fullDataEntityTypeFields.set(fieldId, field); });
return fullDataEntityTypeFields;
};
return EntitiesServiceBase;
}());
exports.EntitiesServiceBase = EntitiesServiceBase;

5
bundle/lib/services/entities.service.d.ts поставляемый
Просмотреть файл

@ -1,5 +0,0 @@
import { ModelEntity } from "../entity/entity.config";
import { EntitiesServiceBase } from "./entities.service.base";
export declare class EntitiesService extends EntitiesServiceBase<ModelEntity> {
}
export declare let entitiesService: EntitiesService;

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

@ -1,22 +0,0 @@
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var entities_service_base_1 = require("./entities.service.base");
var EntitiesService = /** @class */ (function (_super) {
__extends(EntitiesService, _super);
function EntitiesService() {
return _super !== null && _super.apply(this, arguments) || this;
}
return EntitiesService;
}(entities_service_base_1.EntitiesServiceBase));
exports.EntitiesService = EntitiesService;
exports.entitiesService = new EntitiesService();

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

@ -1,9 +0,0 @@
import { DataEntityType } from "../entity/data-entity.base";
import { EntityFields } from "../entity/entity-fields";
import { Field } from "../entity/entity-field";
export declare class EntityFieldsService {
protected fields: Map<DataEntityType, EntityFields>;
addField(dataEntityType: DataEntityType, field: Field): void;
getDataTypeFields(dataEntityType: DataEntityType): EntityFields;
}
export declare const entityFieldsService: EntityFieldsService;

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

@ -1,19 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var EntityFieldsService = /** @class */ (function () {
function EntityFieldsService() {
this.fields = new Map;
}
EntityFieldsService.prototype.addField = function (dataEntityType, field) {
var dataTypeFields = this.getDataTypeFields(dataEntityType);
if (!dataTypeFields)
this.fields.set(dataEntityType, dataTypeFields = new Map);
dataTypeFields.set(field.id, field);
};
EntityFieldsService.prototype.getDataTypeFields = function (dataEntityType) {
return this.fields.get(dataEntityType) || this.fields.get(dataEntityType.prototype);
};
return EntityFieldsService;
}());
exports.EntityFieldsService = EntityFieldsService;
exports.entityFieldsService = new EntityFieldsService;

3
bundle/lib/services/errors.service.d.ts поставляемый
Просмотреть файл

@ -1,3 +0,0 @@
export declare class ErrorsService {
static warn(...items: Array<any>): void;
}

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

@ -1,15 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var ErrorsService = /** @class */ (function () {
function ErrorsService() {
}
ErrorsService.warn = function () {
var items = [];
for (var _i = 0; _i < arguments.length; _i++) {
items[_i] = arguments[_i];
}
return console && console.warn.apply(console, ["Paris warning: "].concat(items));
};
return ErrorsService;
}());
exports.ErrorsService = ErrorsService;

15
bundle/lib/services/http.service.d.ts поставляемый
Просмотреть файл

@ -1,15 +0,0 @@
import { ParisHttpConfig } from "../config/paris-config";
import { Observable } from "rxjs/Observable";
export declare class Http {
static get(url: string, options?: HttpOptions, httpConfig?: ParisHttpConfig): Observable<any>;
static httpOptionsToRequestInit(options?: HttpOptions, httpConfig?: ParisHttpConfig): RequestInit;
static addParamsToUrl(url: string, params?: UrlParams): string;
static getParamsQuery(params: UrlParams): string;
}
export interface HttpOptions {
data?: any;
params?: UrlParams;
}
export declare type UrlParams = {
[index: string]: any;
};

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

@ -1,44 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Observable_1 = require("rxjs/Observable");
var Http = /** @class */ (function () {
function Http() {
}
Http.get = function (url, options, httpConfig) {
var fullUrl = options && options.params ? Http.addParamsToUrl(url, options.params) : url, tmpError = new Error("Failed to GET from " + url + ".");
return Observable_1.Observable.ajax(Object.assign({
url: fullUrl
}, Http.httpOptionsToRequestInit(options, httpConfig)))
.map(function (e) { return e.response; })
.catch(function () { throw tmpError; });
};
Http.httpOptionsToRequestInit = function (options, httpConfig) {
if (!options && !httpConfig)
return null;
var requestOptions = {};
if (options) {
if (options.data)
requestOptions.body = options.data;
}
if (httpConfig) {
if (httpConfig.headers)
requestOptions.headers = httpConfig.headers;
}
return requestOptions;
};
Http.addParamsToUrl = function (url, params) {
if (params && !/\?/.test(url))
return url + "?" + Http.getParamsQuery(params);
return params && !/\?/.test(url) ? url + "?" + Http.getParamsQuery(params) : url;
};
Http.getParamsQuery = function (params) {
var paramsArray = [];
for (var param in params) {
var value = encodeURIComponent(String(params[param]));
paramsArray.push(param + "=" + value);
}
return paramsArray.join("&");
};
return Http;
}());
exports.Http = Http;

10
bundle/lib/services/immutability.d.ts поставляемый
Просмотреть файл

@ -1,10 +0,0 @@
export declare class Immutability {
/**
* Deep-freezes an object
* @param {T} obj The object to freeze
* @param {Set<any>} excluded For internal use, used to avoid infinite recursion, when a parent object is references in one of its children
* @returns {Readonly<T>}
*/
static freeze<T>(obj: T, excluded?: Set<any>): Readonly<T>;
static unfreeze<T>(obj: Readonly<T>): T;
}

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

@ -1,35 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Immutability = /** @class */ (function () {
function Immutability() {
}
/**
* Deep-freezes an object
* @param {T} obj The object to freeze
* @param {Set<any>} excluded For internal use, used to avoid infinite recursion, when a parent object is references in one of its children
* @returns {Readonly<T>}
*/
Immutability.freeze = function (obj, excluded) {
if (excluded && excluded.has(obj))
return obj;
if (!Object.isFrozen(obj))
Object.freeze(obj);
if (Object(obj) === "object") {
var childrenExcluded_1 = excluded ? new Set(excluded) : new Set;
Object.getOwnPropertyNames(obj).forEach(function (prop) { return Immutability.freeze(obj[prop], childrenExcluded_1); });
}
return obj;
};
Immutability.unfreeze = function (obj) {
if (Object(obj) !== obj || obj instanceof Date || obj instanceof RegExp || obj instanceof Function)
return obj;
var unfrozenObj = Object.create(obj.constructor.prototype);
Object.assign(unfrozenObj, obj);
Object.getOwnPropertyNames(obj).forEach(function (prop) {
unfrozenObj[prop] = Immutability.unfreeze(unfrozenObj[prop]);
});
return unfrozenObj;
};
return Immutability;
}());
exports.Immutability = Immutability;

14
bundle/lib/services/paris.d.ts поставляемый
Просмотреть файл

@ -1,14 +0,0 @@
import { ParisConfig } from "../config/paris-config";
import { EntityModelBase } from "../models/entity-model.base";
import { DataEntityConstructor, DataEntityType } from "../entity/data-entity.base";
import { Repository } from "../repository/repository";
import { DataStoreService } from "./data-store.service";
import { EntityConfigBase } from "../entity/entity-config.base";
export declare class Paris {
private repositories;
readonly dataStore: DataStoreService;
readonly config: ParisConfig;
constructor(config?: ParisConfig);
getRepository<T extends EntityModelBase>(entityConstructor: DataEntityConstructor<T>): Repository<T> | null;
getModelBaseConfig(entityConstructor: DataEntityType): EntityConfigBase;
}

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

@ -1,29 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var paris_config_1 = require("../config/paris-config");
var repository_1 = require("../repository/repository");
var entities_service_1 = require("./entities.service");
var data_store_service_1 = require("./data-store.service");
var Paris = /** @class */ (function () {
function Paris(config) {
this.repositories = new Map();
this.config = Object.assign({}, paris_config_1.defaultConfig, config);
this.dataStore = new data_store_service_1.DataStoreService(this.config);
}
Paris.prototype.getRepository = function (entityConstructor) {
var repository = this.repositories.get(entityConstructor);
if (!repository) {
var entityConfig = entities_service_1.entitiesService.getEntityByType(entityConstructor);
if (!entityConfig)
return null;
repository = new repository_1.Repository(entityConfig, this.config, entityConstructor, this.dataStore, this);
this.repositories.set(entityConstructor, repository);
}
return repository;
};
Paris.prototype.getModelBaseConfig = function (entityConstructor) {
return entityConstructor.entityConfig || entityConstructor.valueObjectConfig;
};
return Paris;
}());
exports.Paris = Paris;

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

@ -1,5 +0,0 @@
import { EntitiesServiceBase } from "./entities.service.base";
import { EntityConfigBase } from "../entity/entity-config.base";
export declare class ValueObjectsService extends EntitiesServiceBase<EntityConfigBase> {
}
export declare let valueObjectsService: ValueObjectsService;

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

@ -1,22 +0,0 @@
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var entities_service_base_1 = require("./entities.service.base");
var ValueObjectsService = /** @class */ (function (_super) {
__extends(ValueObjectsService, _super);
function ValueObjectsService() {
return _super !== null && _super.apply(this, arguments) || this;
}
return ValueObjectsService;
}(entities_service_base_1.EntitiesServiceBase));
exports.ValueObjectsService = ValueObjectsService;
exports.valueObjectsService = new ValueObjectsService;

Разница между файлами не показана из-за своего большого размера Загрузить разницу