New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@farris/bef

Package Overview
Dependencies
Maintainers
10
Versions
244
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@farris/bef - npm Package Compare versions

Comparing version 0.0.11-201902121530 to 0.0.11-201902252000

src/bef_change_handler.d.ts

626

bundles/index.umd.js

@@ -10,6 +10,11 @@ (function (global, factory) {

* @Date: 2018-10-19 15:36:48
* @Last Modified by: Witt
* @Last Modified time: 2018-10-19 15:36:48
* @Last Modified by: Witt
* @Last Modified time: 2019-02-23 11:38:35
*/
/**
* --------------------------------------------------------------------------------
* 变更集相关类型
* --------------------------------------------------------------------------------
*/
/**
* 变更类型

@@ -32,13 +37,2 @@ */

})(exports.ChangeDetailType || (exports.ChangeDetailType = {}));
/**
* 行变更详情
* 包含:
* 1、变更类型;
* 2、变更信息
*/
var ChangeDetail = /** @class */ (function () {
function ChangeDetail() {
}
return ChangeDetail;
}());

@@ -362,2 +356,82 @@ /*

/**
* 处理服务器端变更
*/
var BefChangeHandler = /** @class */ (function () {
/**
* 构造函数
*/
function BefChangeHandler() {
}
/**
* 处理Bef变更集
*/
BefChangeHandler.prototype.handle = function (entityType, entityCollection, changeDetails) {
this.handleChangeDetails(entityType, entityCollection, changeDetails);
};
/**
* 处理Bef变更集(批量)
* @param entities
*/
BefChangeHandler.prototype.handleChangeDetails = function (entityType, entityList, changeDetails) {
var _this = this;
changeDetails.forEach(function (changeDetail) {
var id = changeDetail.ChangeInfo.DataId;
var entity = _this.getEntityById(entityList, id);
_this.handleChangeDetail(entityType, entity, changeDetail);
});
};
/**
* 处理Bef变更集(单条)
*/
BefChangeHandler.prototype.handleChangeDetail = function (entityType, entity, changeDetail) {
var _this = this;
// 只处理值变更,其他变更待进一步验证。
if (changeDetail.ChangeType !== exports.ChangeDetailType.Modify) {
return;
}
var changeInfo = changeDetail.ChangeInfo;
Object.keys(changeInfo).forEach(function (propName) {
var _a = EntityUtil.getPropInfo(entityType, propName), propType = _a.propType, propEntityType = _a.propEntityType;
if (propType === 'NgField') {
// 简单属性:更新值
entity[propName] = changeInfo[propName];
}
else if (propType === 'NgObject') {
var childEntity = entity[propName];
if (childEntity.primaryKey) {
// 关联对象:重新加载数据
var childEntityData = changeInfo[propName];
childEntity.load(childEntityData);
}
else {
// 值对象:递归处理变更
var childChangeDetail = changeInfo[propName];
_this.handleChangeDetail(propEntityType, childEntity, childChangeDetail);
}
}
else if (propType === 'NgList') {
// 子列表:递归处理变更集合
var childEntityList = entity[propName];
var childChangeDetails = changeInfo[propName];
_this.handleChangeDetails(propEntityType, childEntityList, childChangeDetails);
}
});
};
/**
* 根据id获取实体,屏蔽EntityCollection和EntityList之间的差异
*/
BefChangeHandler.prototype.getEntityById = function (entityList, id) {
var target;
if (entityList instanceof devkit.EntityCollection) {
target = entityList.getEntityById(id);
}
else {
target = entityList.get(id);
}
return target ? target : null;
};
return BefChangeHandler;
}());
/*

@@ -510,3 +584,3 @@ * @Author: Witt

* @Last Modified by: Witt
* @Last Modified time: 2018-12-13 20:21:22
* @Last Modified time: 2019-02-23 16:56:03
*

@@ -559,10 +633,6 @@ * @todo

_this.changeBuilder = new BefChangeBuilder(_this.entityType, _this.entityCollection);
_this.changeHandler = new BefChangeHandler();
return _this;
}
/**
* --------------------------------------------------------------------------------
* @todo: 新API
* --------------------------------------------------------------------------------
*/
/**
* 获取实体集合

@@ -590,7 +660,8 @@ */

};
var query$ = this.restService.query(entityFilter);
return query$.pipe(map.map(function (queryResult) {
var requestInfo = this.restService.buildRequestInfo();
var query$ = this.restService.extendQuery(entityFilter, requestInfo);
return query$.pipe(map.map(function (responseInfo) {
var queryResult = responseInfo.returnValue;
var listData = queryResult.result;
var entities = [];
// const listData = queryResult['result'];
var listData = queryResult;
listData.forEach(function (data) {

@@ -605,7 +676,2 @@ var entity = _this.buildEntity(data);

/**
* --------------------------------------------------------------------------------
* @todo: 已过期,待删除
* --------------------------------------------------------------------------------
*/
/**
* 获取实体集合

@@ -615,7 +681,9 @@ */

var _this = this;
var query$ = this.restService.query();
return query$.pipe(map.map(function (queryResult) {
var entityFilter = null;
var requestInfo = this.restService.buildRequestInfo();
var query$ = this.restService.extendQuery(entityFilter, requestInfo);
return query$.pipe(map.map(function (responseInfo) {
var queryResult = responseInfo.returnValue;
var listData = queryResult.result;
var entities = [];
// const listData = queryResult['result'];
var listData = queryResult;
listData.forEach(function (data) {

@@ -634,5 +702,7 @@ var entity = _this.buildEntity(data);

var _this = this;
var retrieve$ = this.restService.retrieve(id);
var result$ = retrieve$.pipe(map.map(function (data) {
var entity = _this.buildEntity(data);
var requestInfo = this.restService.buildRequestInfo();
var retrieve$ = this.restService.extendRetrieve(id, requestInfo);
var result$ = retrieve$.pipe(map.map(function (responseInfo) {
var entityData = responseInfo.returnValue;
var entity = _this.buildEntity(entityData);
_this.entityCollection.loadEntities([entity]);

@@ -649,6 +719,8 @@ return entity;

var _this = this;
var retrieve$ = this.restService.retrieve(id);
var result$ = retrieve$.pipe(map.map(function (data) {
var requestInfo = this.restService.buildRequestInfo();
var retrieve$ = this.restService.extendRetrieve(id, requestInfo);
var result$ = retrieve$.pipe(map.map(function (responseInfo) {
var entityData = responseInfo.returnValue;
var entity = _this.entityCollection.getEntityById(id);
entity.load(data);
entity.load(entityData);
return entity;

@@ -659,15 +731,10 @@ }));

/**
* 根据id给实体加锁
* @todo:通过一个空变更进行加锁,待确认
*/
BefRepository.prototype.lockById = function (id) {
return of.of(true);
};
/**
* 创建新实体,并加载
*/
BefRepository.prototype.create = function () {
BefRepository.prototype.create = function (defaultValue) {
var _this = this;
var result$ = this.restService.create();
return result$.pipe(map.map(function (newData) {
var requestInfo = this.restService.buildRequestInfo();
var result$ = this.restService.create(defaultValue, requestInfo);
return result$.pipe(map.map(function (responseInfo) {
var newData = responseInfo.returnValue;
var newEntity = _this.buildEntity(newData);

@@ -679,15 +746,10 @@ _this.entityCollection.loadEntities([newEntity]);

/**
* 创建子实体,并加载
* @param path 路径
*/
BefRepository.prototype.createByPath = function (path) {
throw new Error('Not Implemented');
};
/**
* 追加实体
*/
BefRepository.prototype.append = function () {
BefRepository.prototype.append = function (defaultValue) {
var _this = this;
var append$ = this.restService.create();
return append$.pipe(map.map(function (newData) {
var requestInfo = this.restService.buildRequestInfo();
var append$ = this.restService.create(defaultValue, requestInfo);
return append$.pipe(map.map(function (responseInfo) {
var newData = responseInfo.returnValue;
var newEntity = _this.buildEntity(newData);

@@ -704,4 +766,6 @@ _this.entityCollection.addEntity(newEntity);

var _this = this;
var append$ = this.restService.createByPath(fpath);
return append$.pipe(map.map(function (newData) {
var requestInfo = this.restService.buildRequestInfo();
var append$ = this.restService.createByPath(fpath, requestInfo);
return append$.pipe(map.map(function (responseInfo) {
var newData = responseInfo.returnValue;
var newEntity = _this.appendEntityByPath(fpath, newData);

@@ -712,41 +776,2 @@ return newEntity;

/**
* 根据path获取实体集合
* @param fpath
* @todo:临时模拟,强识别2级路径
* fixed by justin: 循环识别path
*/
BefRepository.prototype.appendEntityByPath = function (fpath, childData) {
// const [ , fid, propName ] = fpath.split('/');
// const parentEntity = this.entityCollection.getEntityById(fid);
// const childEntityList = parentEntity[propName];
// const propInfo = EntityUtil.getPropInfo(this.entityType, propName);
// const childEntity = EntityFactory<Entity>(propInfo.propEntityType, childData);
// childEntityList.appendNew(childEntity);
// return childEntity;
var subPaths = fpath.split('/');
if (subPaths.length < 3) {
throw Error("\u6839\u636Epath\u5220\u9664\u5B9E\u4F53\u6570\u636E\u51FA\u9519\u4E86\u3002\u4F20\u5165\u7684path[" + fpath + "]\u683C\u5F0F\u4E0D\u5BF9");
// return;
}
var childEntityList;
var propInfo;
var propName;
for (var i = 2; i < subPaths.length; i = i + 2) {
var fid = subPaths[i - 1];
propName = subPaths[i];
// todo: EntityCollection重构之后这里无需差异处理
var parentEntity = childEntityList ? childEntityList.get(fid) : this.entityCollection.getEntityById(fid);
childEntityList = parentEntity[propName];
var entityType = propInfo ? propInfo.propEntityType : this.entityType;
propInfo = EntityUtil.getPropInfo(entityType, propName);
if (!childEntityList) {
throw Error("fpath\u53C2\u6570\u9519\u8BEF\uFF0C\u65E0\u6CD5\u627E\u5230" + propName + "\u5BF9\u5E94\u7684\u5B50\u8868\u3002fpath\u4E3A\uFF1A" + fpath);
}
}
// const propInfo = EntityUtil.getPropInfo(this.entityType, propName);
var childEntity = devkit.EntityFactory(propInfo.propEntityType, childData);
childEntityList.appendNew(childEntity);
return childEntity;
};
/**
* 根据id删除实体

@@ -759,3 +784,4 @@ * @param id 内码

// 服务器端删除
var delete$ = this.restService.delete(id);
var requestInfo = this.restService.buildRequestInfo();
var delete$ = this.restService.extendDelete(id, requestInfo);
// 从本地实体集合中移除

@@ -789,3 +815,4 @@ return delete$.pipe(switchMap.switchMap(function () {

// 服务器端删除
var delete$ = this.restService.deletByPath(fpath, id);
var requestInfo = this.restService.buildRequestInfo();
var delete$ = this.restService.extendDeletByPath(fpath, id, requestInfo);
// 从本地实体集合中移除

@@ -798,29 +825,2 @@ return delete$.pipe(map.map(function () {

/**
* 根据path获取实体集合
* @param fpath
* @todo:临时模拟,强识别2级路径
* fixed by justin: 循环识别路径,支持多级
*/
BefRepository.prototype.removeEntityByPath = function (fpath, id) {
// const [ , fid, propName ] = fpath.split('/');
// const parentEntity = this.entityCollection.getEntityById(fid);
// const childEntityList: EntityList<Entity> = parentEntity[propName];
var subPaths = fpath.split('/');
if (subPaths.length < 3) {
throw Error("\u6839\u636Epath\u5220\u9664\u5B9E\u4F53\u6570\u636E\u51FA\u9519\u4E86\u3002\u4F20\u5165\u7684path[" + fpath + "]\u683C\u5F0F\u4E0D\u5BF9");
}
var childEntityList;
for (var i = 2; i < subPaths.length; i = i + 2) {
var fid = subPaths[i - 1];
var propName = subPaths[i];
var parentEntity = childEntityList ? childEntityList.get(fid) : this.entityCollection.getEntityById(fid);
childEntityList = parentEntity[propName];
if (!childEntityList) {
throw Error("fpath\u53C2\u6570\u9519\u8BEF\uFF0C\u65E0\u6CD5\u627E\u5230" + propName + "\u5BF9\u5E94\u7684\u5B50\u8868\u3002fpath\u4E3A\uFF1A" + fpath);
}
}
childEntityList.remove(id);
// 清空实体中
};
/**
* 将id对应的实体的变更提交的服务器端

@@ -839,3 +839,4 @@ */

var changeDetail = this.changeBuilder.build(entity.changes);
var update$ = this.restService.update(changeDetail);
var requestInfo = this.restService.buildRequestInfo();
var update$ = this.restService.update(changeDetail, requestInfo);
var result$ = update$.pipe(tap.tap(function () {

@@ -871,3 +872,3 @@ // 清空变更集

// 串联流
var result$ = zip.zip.apply(void 0, updateResults).pipe(map.map(function (results) {
var result$ = zip.zip.apply(void 0, updateResults).pipe(map.map(function () {
return true;

@@ -882,23 +883,14 @@ }));

var _this = this;
var save$ = this.restService.save();
var requestInfo = this.restService.buildRequestInfo();
var save$ = this.restService.save(requestInfo);
var result$ = save$.pipe(
// 更新本地数据
tap.tap(function (saveResult) {
if (saveResult) {
var entities = _this.entityCollection.toArray();
entities.forEach(function (entity) {
// 当前数据 => 原始数据
// 清空变更集
entity.changes.splice(0, entity.changes.length);
});
}
}),
// 转换为保存结果流(boolean流)
map.map(function (saveResult) {
if (saveResult === false) {
return false;
}
else {
return true;
}
tap.tap(function () {
var entities = _this.entityCollection.toArray();
entities.forEach(function (entity) {
// 清空变更集
entity.changes.splice(0, entity.changes.length);
});
}), map.map(function () {
return true;
}));

@@ -912,21 +904,12 @@ return result$;

var _this = this;
var save$ = this.restService.save();
var result$ = save$.pipe(
// 更新本地数据
tap.tap(function (saveResult) {
if (saveResult) {
var entity = _this.entityCollection.getEntityById(id);
// 当前数据 => 原始数据
// 清空变更集
var requestInfo = this.restService.buildRequestInfo();
var save$ = this.restService.save(requestInfo);
var result$ = save$.pipe(tap.tap(function () {
// 清空变更集
var entity = _this.entityCollection.getEntityById(id);
if (entity) {
entity.changes.splice(0, entity.changes.length);
}
}),
// 转换为保存结果流(boolean流)
map.map(function (saveResult) {
if (saveResult === false) {
return false;
}
else {
return true;
}
}), map.map(function () {
return true;
}));

@@ -941,14 +924,8 @@ return result$;

var cancel$ = this.restService.cancel();
cancel$.pipe(
// 数据源操作
tap.tap(function () {
cancel$.pipe(tap.tap(function () {
var entities = _this.entityCollection.toArray();
entities.forEach(function (entity) {
// 当前数据 => 原始数据
// 清空变更集
entity.changes.splice(0, entity.changes.length);
});
}),
// 转换为结果流
map.map(function () {
}), map.map(function () {
return true;

@@ -958,2 +935,98 @@ }));

};
// #region 工具方法
/**
* 根据path获取实体集合
* @param fpath 路径
* @param childData 实体数据
*/
BefRepository.prototype.appendEntityByPath = function (fpath, childData) {
var subPaths = fpath.split('/');
if (subPaths.length < 3) {
throw Error("\u6839\u636Epath\u5220\u9664\u5B9E\u4F53\u6570\u636E\u51FA\u9519\u4E86\u3002\u4F20\u5165\u7684path[" + fpath + "]\u683C\u5F0F\u4E0D\u5BF9");
}
var childEntityList;
var propInfo;
var propName;
for (var i = 2; i < subPaths.length; i = i + 2) {
var fid = subPaths[i - 1];
propName = subPaths[i];
// todo: EntityCollection重构之后这里无需差异处理
var parentEntity = childEntityList ? childEntityList.get(fid) : this.entityCollection.getEntityById(fid);
childEntityList = parentEntity[propName];
var entityType = propInfo ? propInfo.propEntityType : this.entityType;
propInfo = EntityUtil.getPropInfo(entityType, propName);
if (!childEntityList) {
throw Error("fpath\u53C2\u6570\u9519\u8BEF\uFF0C\u65E0\u6CD5\u627E\u5230" + propName + "\u5BF9\u5E94\u7684\u5B50\u8868\u3002fpath\u4E3A\uFF1A" + fpath);
}
}
// const propInfo = EntityUtil.getPropInfo(this.entityType, propName);
var childEntity = devkit.EntityFactory(propInfo.propEntityType, childData);
childEntityList.appendNew(childEntity);
return childEntity;
};
/**
* 根据path获取实体集合
* @param fpath
*/
BefRepository.prototype.removeEntityByPath = function (fpath, id) {
var subPaths = fpath.split('/');
if (subPaths.length < 3) {
throw Error("\u6839\u636Epath\u5220\u9664\u5B9E\u4F53\u6570\u636E\u51FA\u9519\u4E86\u3002\u4F20\u5165\u7684path[" + fpath + "]\u683C\u5F0F\u4E0D\u5BF9");
}
var childEntityList;
for (var i = 2; i < subPaths.length; i = i + 2) {
var fid = subPaths[i - 1];
var propName = subPaths[i];
var parentEntity = childEntityList ? childEntityList.get(fid) : this.entityCollection.getEntityById(fid);
childEntityList = parentEntity[propName];
if (!childEntityList) {
throw Error("fpath\u53C2\u6570\u9519\u8BEF\uFF0C\u65E0\u6CD5\u627E\u5230" + propName + "\u5BF9\u5E94\u7684\u5B50\u8868\u3002fpath\u4E3A\uFF1A" + fpath);
}
}
childEntityList.remove(id);
};
/**
* 清空所有本地实体的变更集
*/
BefRepository.prototype.clearAllEntityChanges = function () {
var entities = this.entityCollection.toArray();
entities.forEach(function (entity) {
entity.changes.splice(0, entity.changes.length);
});
};
/**
* 获取数据变更
*/
BefRepository.prototype.getDataChangeDetails = function () {
var _this = this;
var changeDetails = [];
var entities = this.entityCollection.getAllEntities();
entities.forEach(function (entity) {
if (entity.changes.length === 0) {
return;
}
var changeDetail = _this.changeBuilder.build(entity.changes);
changeDetails.push(changeDetail);
});
return changeDetails;
};
/**
* 处理数据变更
*/
BefRepository.prototype.handleDataChangeDetails = function (changeDetails) {
this.changeHandler.handle(this.entityType, this.entityCollection, changeDetails);
};
/**
* 获取变量变更
*/
BefRepository.prototype.getVariableChangeDetails = function () {
var changeDetails = [];
return changeDetails;
};
/**
* 处理变量变更
*/
BefRepository.prototype.handleVariableChangeDetails = function () {
throw new Error('Not Implemented');
};
BefRepository = __decorate$2([

@@ -968,5 +1041,5 @@ core.Injectable(),

* @Author: Witt
* @Date: 2018-10-12 14:43:49
* @Date: 2019-02-23 13:57:47
* @Last Modified by: Witt
* @Last Modified time: 2018-11-15 16:08:42
* @Last Modified time: 2019-02-23 17:26:50
*/

@@ -982,2 +1055,7 @@ var __decorate$3 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {

};
var GET = 'GET';
var DELETE = 'DELETE';
var PUT = 'PUT';
var POST = 'POST';
var PATCH = 'PATCH';
/**

@@ -1001,6 +1079,3 @@ * BEF取数服务

/**
* 列表查询
* @return 数据数组
* @todo
* 1、目前仅支持查询全部数据
* 查询
*/

@@ -1013,6 +1088,22 @@ BefRestService.prototype.query = function (entityFilter) {

}
return this.request(url, 'GET');
return this.request(url, GET);
};
/**
* 数据检索
* 查询
*/
BefRestService.prototype.extendQuery = function (entityFilter, requestInfo) {
var url = this.baseUri + "/extension/query";
if (entityFilter) {
var entityFilterJson = JSON.stringify(entityFilter);
url = url + "?entityFilter=" + entityFilterJson;
}
// const body = {
// RequestInfo: requestInfo,
// };
var body = requestInfo;
var options = this.addBodyToOptions({}, body);
return this.request(url, PUT, null, options);
};
/**
* 检索数据
* @param id 单据内码

@@ -1023,11 +1114,26 @@ * @return 数据对象

var url = this.baseUri + "/" + id;
return this.request(url, 'GET');
return this.request(url, GET);
};
/**
* 检索数据(扩展)
*/
BefRestService.prototype.extendRetrieve = function (id, requestInfo) {
var url = this.baseUri + "/extension/retrieve/" + id;
// const body = {
// RequestInfo: requestInfo,
// };
var body = requestInfo;
var options = this.addBodyToOptions({}, body);
return this.request(url, PUT, null, options);
};
/**
* 创建一条数据
* @summary
* 返回带默认值的空数据,服务器端该数据在BE缓存中,尚未保存到数据库
*/
BefRestService.prototype.create = function () {
return this.request(this.baseUri, 'POST');
BefRestService.prototype.create = function (defaultValue, requestInfo) {
var body = {
defaultValue: defaultValue,
RequestInfo: requestInfo,
};
var options = this.addBodyToOptions({}, body);
return this.request(this.baseUri, POST, null, options);
};

@@ -1039,23 +1145,33 @@ /**

*/
BefRestService.prototype.createByPath = function (fpath) {
BefRestService.prototype.createByPath = function (fpath, requestInfo) {
var pathUrl = this.convertPathToUrl(fpath);
var url = "" + this.baseUri + pathUrl;
return this.request(url, 'POST');
// const body = {
// RequestInfo: requestInfo
// };
var body = requestInfo;
var options = this.addBodyToOptions({}, body);
return this.request(url, POST, null, options);
};
/**
* 提交变更
* @summary
* 此时变更提交的BE缓存中,等待保存,服务器端不返回任何数据
*/
BefRestService.prototype.update = function (changeDetail) {
var optionsWithBody = this.addBody({}, changeDetail);
return this.innerRequest(this.baseUri, 'PATCH', null, optionsWithBody);
BefRestService.prototype.update = function (changeDetail, requestInfo) {
var body = {
changeDetail: changeDetail,
RequestInfo: requestInfo,
};
var options = this.addBodyToOptions({}, body);
return this.request(this.baseUri, PATCH, null, options);
};
/**
* 保存
* @summary
* 通过此地方将BEF中的变更缓存应用到数据库中,服务器端不返回任何数据
* 执行保存
*/
BefRestService.prototype.save = function () {
return this.innerRequest(this.baseUri, 'PUT');
BefRestService.prototype.save = function (requestInfo) {
// const body = {
// RequestInfo: requestInfo,
// };
var body = requestInfo;
var options = this.addBodyToOptions({}, body);
return this.request(this.baseUri, PUT, options);
};

@@ -1067,5 +1183,17 @@ /**

var url = this.baseUri + "/" + id;
return this.request(url, 'DELETE');
return this.request(url, DELETE);
};
/**
* 删除(扩展)
*/
BefRestService.prototype.extendDelete = function (id, requestInfo) {
var url = this.baseUri + "/extension/delete/" + id;
// const body = {
// RequestInfo: requestInfo,
// };
var body = requestInfo;
var options = this.addBodyToOptions({}, body);
return this.request(url, PUT, null, options);
};
/**
* 删除后代

@@ -1077,5 +1205,19 @@ * @param fpath 父路径(从表形如:/1/edus,从从表形如:/1/edus/11/grades)

var url = "" + this.baseUri + pathUrl + "/" + id;
return this.request(url, 'DELETE');
return this.request(url, DELETE);
};
/**
* 删除后代(扩展)
* @param fpath 父路径(从表形如:/1/edus,从从表形如:/1/edus/11/grades)
*/
BefRestService.prototype.extendDeletByPath = function (fpath, id, requestInfo) {
var pathUrl = this.convertPathToUrl(fpath);
var url = this.baseUri + "/extension" + pathUrl + "/" + id;
// const body = {
// RequestInfo: requestInfo,
// };
var body = requestInfo;
var options = this.addBodyToOptions({}, body);
return this.request(url, PUT, null, options);
};
/**
* 批量删除

@@ -1088,11 +1230,18 @@ * @param ids 待删除的id数组

};
return this.request(this.baseUri, 'DELETE', params);
return this.request(this.baseUri, DELETE, params);
};
/**
* 批量删除子表记录
* @param fpath 父路径
* @param ids 待删除的id数组
* 批量删除(扩展)
*/
BefRestService.prototype.batchDeleteByPath = function (fpath, ids) {
throw new Error('Not Implemented');
BefRestService.prototype.extendBatchDelete = function (ids, requestInfo) {
var url = this.baseUri + "/extension/batchdelete";
var params = {
ids: ids.join(',')
};
// const body = {
// RequestInfo: requestInfo,
// };
var body = requestInfo;
var options = this.addBodyToOptions({}, body);
return this.request(url, PUT, params, options);
};

@@ -1104,23 +1253,9 @@ /**

var url = this.baseUri + "/service/cancel";
return this.request(url, 'POST');
return this.request(url, POST);
};
/**
* 发送http请求
*/
BefRestService.prototype.request = function (url, method, params, options) {
var _this = this;
if (method !== 'GET') {
return this.repository.updateAllChanges().pipe(switchMap.switchMap(function () {
return _this.innerRequest(url, method, params, options);
}));
}
else {
return this.innerRequest(url, method, params, options);
}
};
/**
* 发送http请求(请勿使用)
* @internal
*/
BefRestService.prototype.innerRequest = function (url, method, params, options) {
BefRestService.prototype.request = function (url, method, params, options) {
var _this = this;

@@ -1133,2 +1268,7 @@ options = options || {};

}
// 带有requestInfo的请求,请求成功后清空变更集
var clearChanges = false;
if (options && options.body && options.body.RequestInfo) {
clearChanges = true;
}
// 串联session流和http流

@@ -1143,4 +1283,15 @@ return this.sessionService.getBeSessionId().pipe(switchMap.switchMap(function (sessionId) {

return _this.httpClient.request(method, url, options);
}), tap.tap(function (result) {
var responseInfo = result;
// 响应数据变更
if (responseInfo.innerDataChange) {
_this.repository.handleDataChangeDetails(responseInfo.innerDataChange);
}
// 清空本地变更集
if (clearChanges) {
_this.repository.clearAllEntityChanges();
}
}));
};
// #region 工具方法
/**

@@ -1165,3 +1316,3 @@ * 构造HttpParams对象

*/
BefRestService.prototype.addBody = function (options, body) {
BefRestService.prototype.addBodyToOptions = function (options, body) {
options = options || {};

@@ -1172,6 +1323,25 @@ var mergedOptions = Object.assign(options, { body: body });

/**
* 构造带RequestInfo的Body
* @body 未携带RequestInfo的body,格式形如: {key1: value1, key2: value2}
*/
BefRestService.prototype.buildBodyWithRequestInfo = function (body) {
if (body.RequestInfo) {
return body;
}
var requestInfo = this.buildRequestInfo();
var bodyWithRequestInfo = Object.assign({}, body, { RequestInfo: requestInfo });
return bodyWithRequestInfo;
};
/**
* 构造RequestInfo
*/
BefRestService.prototype.buildRequestInfo = function () {
var requestInfo = {
dataChange: this.repository.getDataChangeDetails(),
variableChange: []
};
return requestInfo;
};
/**
* 在devkit的路径中表名是属性名,是复数,在url中表名是单数
* 在此做兼容
* @todo:临时支持子表,应该支持无限层级
* fixed by justin: 每级属性名都去掉s
*/

@@ -1249,5 +1419,5 @@ BefRestService.prototype.convertPathToUrl = function (path) {

exports.ChangeDetail = ChangeDetail;
exports.BE_SERVER_URI_TOKEN = BE_SERVER_URI_TOKEN;
exports.BefChangeBuilder = BefChangeBuilder;
exports.BefChangeHandler = BefChangeHandler;
exports.BefSessionService = BefSessionService;

@@ -1254,0 +1424,0 @@ exports.BefRestService = BefRestService;

import { InjectionToken, Injectable, Injector } from '@angular/core';
import { FieldMetadataUtil, ModifyType, EntityFactory, Repository } from '@farris/devkit';
import { FieldMetadataUtil, ModifyType, EntityCollection, EntityFactory, Repository } from '@farris/devkit';
import { CacheService } from '@ecp-caf/caf-common';

@@ -14,6 +14,11 @@ import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';

* @Date: 2018-10-19 15:36:48
* @Last Modified by: Witt
* @Last Modified time: 2018-10-19 15:36:48
* @Last Modified by: Witt
* @Last Modified time: 2019-02-23 11:38:35
*/
/**
* --------------------------------------------------------------------------------
* 变更集相关类型
* --------------------------------------------------------------------------------
*/
/**
* 变更类型

@@ -36,10 +41,2 @@ */

})(ChangeDetailType || (ChangeDetailType = {}));
/**
* 行变更详情
* 包含:
* 1、变更类型;
* 2、变更信息
*/
class ChangeDetail {
}

@@ -353,2 +350,79 @@ /*

/**
* 处理服务器端变更
*/
class BefChangeHandler {
/**
* 构造函数
*/
constructor() {
}
/**
* 处理Bef变更集
*/
handle(entityType, entityCollection, changeDetails) {
this.handleChangeDetails(entityType, entityCollection, changeDetails);
}
/**
* 处理Bef变更集(批量)
* @param entities
*/
handleChangeDetails(entityType, entityList, changeDetails) {
changeDetails.forEach((changeDetail) => {
const id = changeDetail.ChangeInfo.DataId;
const entity = this.getEntityById(entityList, id);
this.handleChangeDetail(entityType, entity, changeDetail);
});
}
/**
* 处理Bef变更集(单条)
*/
handleChangeDetail(entityType, entity, changeDetail) {
// 只处理值变更,其他变更待进一步验证。
if (changeDetail.ChangeType !== ChangeDetailType.Modify) {
return;
}
const changeInfo = changeDetail.ChangeInfo;
Object.keys(changeInfo).forEach((propName) => {
const { propType, propEntityType } = EntityUtil.getPropInfo(entityType, propName);
if (propType === 'NgField') {
// 简单属性:更新值
entity[propName] = changeInfo[propName];
}
else if (propType === 'NgObject') {
const childEntity = entity[propName];
if (childEntity.primaryKey) {
// 关联对象:重新加载数据
const childEntityData = changeInfo[propName];
childEntity.load(childEntityData);
}
else {
// 值对象:递归处理变更
const childChangeDetail = changeInfo[propName];
this.handleChangeDetail(propEntityType, childEntity, childChangeDetail);
}
}
else if (propType === 'NgList') {
// 子列表:递归处理变更集合
const childEntityList = entity[propName];
const childChangeDetails = changeInfo[propName];
this.handleChangeDetails(propEntityType, childEntityList, childChangeDetails);
}
});
}
/**
* 根据id获取实体,屏蔽EntityCollection和EntityList之间的差异
*/
getEntityById(entityList, id) {
let target;
if (entityList instanceof EntityCollection) {
target = entityList.getEntityById(id);
}
else {
target = entityList.get(id);
}
return target ? target : null;
}
}
/*

@@ -498,3 +572,3 @@ * @Author: Witt

* @Last Modified by: Witt
* @Last Modified time: 2018-12-13 20:21:22
* @Last Modified time: 2019-02-23 16:56:03
*

@@ -536,9 +610,5 @@ * @todo

this.changeBuilder = new BefChangeBuilder(this.entityType, this.entityCollection);
this.changeHandler = new BefChangeHandler();
}
/**
* --------------------------------------------------------------------------------
* @todo: 新API
* --------------------------------------------------------------------------------
*/
/**
* 获取实体集合

@@ -565,7 +635,8 @@ */

};
const query$ = this.restService.query(entityFilter);
return query$.pipe(map((queryResult) => {
const requestInfo = this.restService.buildRequestInfo();
const query$ = this.restService.extendQuery(entityFilter, requestInfo);
return query$.pipe(map((responseInfo) => {
const queryResult = responseInfo.returnValue;
const listData = queryResult.result;
const entities = [];
// const listData = queryResult['result'];
const listData = queryResult;
listData.forEach((data) => {

@@ -580,15 +651,12 @@ const entity = this.buildEntity(data);

/**
* --------------------------------------------------------------------------------
* @todo: 已过期,待删除
* --------------------------------------------------------------------------------
*/
/**
* 获取实体集合
*/
getList() {
const query$ = this.restService.query();
return query$.pipe(map((queryResult) => {
const entityFilter = null;
const requestInfo = this.restService.buildRequestInfo();
const query$ = this.restService.extendQuery(entityFilter, requestInfo);
return query$.pipe(map((responseInfo) => {
const queryResult = responseInfo.returnValue;
const listData = queryResult.result;
const entities = [];
// const listData = queryResult['result'];
const listData = queryResult;
listData.forEach((data) => {

@@ -606,5 +674,7 @@ const entity = this.buildEntity(data);

getById(id) {
const retrieve$ = this.restService.retrieve(id);
const result$ = retrieve$.pipe(map((data) => {
const entity = this.buildEntity(data);
const requestInfo = this.restService.buildRequestInfo();
const retrieve$ = this.restService.extendRetrieve(id, requestInfo);
const result$ = retrieve$.pipe(map((responseInfo) => {
const entityData = responseInfo.returnValue;
const entity = this.buildEntity(entityData);
this.entityCollection.loadEntities([entity]);

@@ -620,6 +690,8 @@ return entity;

updateById(id) {
const retrieve$ = this.restService.retrieve(id);
const result$ = retrieve$.pipe(map((data) => {
const requestInfo = this.restService.buildRequestInfo();
const retrieve$ = this.restService.extendRetrieve(id, requestInfo);
const result$ = retrieve$.pipe(map((responseInfo) => {
const entityData = responseInfo.returnValue;
const entity = this.entityCollection.getEntityById(id);
entity.load(data);
entity.load(entityData);
return entity;

@@ -630,14 +702,9 @@ }));

/**
* 根据id给实体加锁
* @todo:通过一个空变更进行加锁,待确认
*/
lockById(id) {
return of(true);
}
/**
* 创建新实体,并加载
*/
create() {
const result$ = this.restService.create();
return result$.pipe(map((newData) => {
create(defaultValue) {
const requestInfo = this.restService.buildRequestInfo();
const result$ = this.restService.create(defaultValue, requestInfo);
return result$.pipe(map((responseInfo) => {
const newData = responseInfo.returnValue;
const newEntity = this.buildEntity(newData);

@@ -649,14 +716,9 @@ this.entityCollection.loadEntities([newEntity]);

/**
* 创建子实体,并加载
* @param path 路径
*/
createByPath(path) {
throw new Error('Not Implemented');
}
/**
* 追加实体
*/
append() {
const append$ = this.restService.create();
return append$.pipe(map((newData) => {
append(defaultValue) {
const requestInfo = this.restService.buildRequestInfo();
const append$ = this.restService.create(defaultValue, requestInfo);
return append$.pipe(map((responseInfo) => {
const newData = responseInfo.returnValue;
const newEntity = this.buildEntity(newData);

@@ -672,4 +734,6 @@ this.entityCollection.addEntity(newEntity);

appendByPath(fpath) {
const append$ = this.restService.createByPath(fpath);
return append$.pipe(map((newData) => {
const requestInfo = this.restService.buildRequestInfo();
const append$ = this.restService.createByPath(fpath, requestInfo);
return append$.pipe(map((responseInfo) => {
const newData = responseInfo.returnValue;
const newEntity = this.appendEntityByPath(fpath, newData);

@@ -680,41 +744,2 @@ return newEntity;

/**
* 根据path获取实体集合
* @param fpath
* @todo:临时模拟,强识别2级路径
* fixed by justin: 循环识别path
*/
appendEntityByPath(fpath, childData) {
// const [ , fid, propName ] = fpath.split('/');
// const parentEntity = this.entityCollection.getEntityById(fid);
// const childEntityList = parentEntity[propName];
// const propInfo = EntityUtil.getPropInfo(this.entityType, propName);
// const childEntity = EntityFactory<Entity>(propInfo.propEntityType, childData);
// childEntityList.appendNew(childEntity);
// return childEntity;
const subPaths = fpath.split('/');
if (subPaths.length < 3) {
throw Error(`根据path删除实体数据出错了。传入的path[${fpath}]格式不对`);
// return;
}
let childEntityList;
let propInfo;
let propName;
for (let i = 2; i < subPaths.length; i = i + 2) {
const fid = subPaths[i - 1];
propName = subPaths[i];
// todo: EntityCollection重构之后这里无需差异处理
const parentEntity = childEntityList ? childEntityList.get(fid) : this.entityCollection.getEntityById(fid);
childEntityList = parentEntity[propName];
const entityType = propInfo ? propInfo.propEntityType : this.entityType;
propInfo = EntityUtil.getPropInfo(entityType, propName);
if (!childEntityList) {
throw Error(`fpath参数错误,无法找到${propName}对应的子表。fpath为:${fpath}`);
}
}
// const propInfo = EntityUtil.getPropInfo(this.entityType, propName);
const childEntity = EntityFactory(propInfo.propEntityType, childData);
childEntityList.appendNew(childEntity);
return childEntity;
}
/**
* 根据id删除实体

@@ -726,3 +751,4 @@ * @param id 内码

// 服务器端删除
const delete$ = this.restService.delete(id);
const requestInfo = this.restService.buildRequestInfo();
const delete$ = this.restService.extendDelete(id, requestInfo);
// 从本地实体集合中移除

@@ -755,3 +781,4 @@ return delete$.pipe(switchMap(() => {

// 服务器端删除
const delete$ = this.restService.deletByPath(fpath, id);
const requestInfo = this.restService.buildRequestInfo();
const delete$ = this.restService.extendDeletByPath(fpath, id, requestInfo);
// 从本地实体集合中移除

@@ -764,29 +791,2 @@ return delete$.pipe(map(() => {

/**
* 根据path获取实体集合
* @param fpath
* @todo:临时模拟,强识别2级路径
* fixed by justin: 循环识别路径,支持多级
*/
removeEntityByPath(fpath, id) {
// const [ , fid, propName ] = fpath.split('/');
// const parentEntity = this.entityCollection.getEntityById(fid);
// const childEntityList: EntityList<Entity> = parentEntity[propName];
const subPaths = fpath.split('/');
if (subPaths.length < 3) {
throw Error(`根据path删除实体数据出错了。传入的path[${fpath}]格式不对`);
}
let childEntityList;
for (let i = 2; i < subPaths.length; i = i + 2) {
const fid = subPaths[i - 1];
const propName = subPaths[i];
const parentEntity = childEntityList ? childEntityList.get(fid) : this.entityCollection.getEntityById(fid);
childEntityList = parentEntity[propName];
if (!childEntityList) {
throw Error(`fpath参数错误,无法找到${propName}对应的子表。fpath为:${fpath}`);
}
}
childEntityList.remove(id);
// 清空实体中
}
/**
* 将id对应的实体的变更提交的服务器端

@@ -805,3 +805,4 @@ */

const changeDetail = this.changeBuilder.build(entity.changes);
const update$ = this.restService.update(changeDetail);
const requestInfo = this.restService.buildRequestInfo();
const update$ = this.restService.update(changeDetail, requestInfo);
const result$ = update$.pipe(tap(() => {

@@ -836,3 +837,3 @@ // 清空变更集

// 串联流
const result$ = zip(...updateResults).pipe(map((results) => {
const result$ = zip(...updateResults).pipe(map(() => {
return true;

@@ -846,23 +847,14 @@ }));

applyChanges() {
const save$ = this.restService.save();
const requestInfo = this.restService.buildRequestInfo();
const save$ = this.restService.save(requestInfo);
const result$ = save$.pipe(
// 更新本地数据
tap((saveResult) => {
if (saveResult) {
const entities = this.entityCollection.toArray();
entities.forEach((entity) => {
// 当前数据 => 原始数据
// 清空变更集
entity.changes.splice(0, entity.changes.length);
});
}
}),
// 转换为保存结果流(boolean流)
map((saveResult) => {
if (saveResult === false) {
return false;
}
else {
return true;
}
tap(() => {
const entities = this.entityCollection.toArray();
entities.forEach((entity) => {
// 清空变更集
entity.changes.splice(0, entity.changes.length);
});
}), map(() => {
return true;
}));

@@ -875,21 +867,12 @@ return result$;

applyChangesById(id) {
const save$ = this.restService.save();
const result$ = save$.pipe(
// 更新本地数据
tap((saveResult) => {
if (saveResult) {
const entity = this.entityCollection.getEntityById(id);
// 当前数据 => 原始数据
// 清空变更集
const requestInfo = this.restService.buildRequestInfo();
const save$ = this.restService.save(requestInfo);
const result$ = save$.pipe(tap(() => {
// 清空变更集
const entity = this.entityCollection.getEntityById(id);
if (entity) {
entity.changes.splice(0, entity.changes.length);
}
}),
// 转换为保存结果流(boolean流)
map((saveResult) => {
if (saveResult === false) {
return false;
}
else {
return true;
}
}), map(() => {
return true;
}));

@@ -903,14 +886,8 @@ return result$;

const cancel$ = this.restService.cancel();
cancel$.pipe(
// 数据源操作
tap(() => {
cancel$.pipe(tap(() => {
const entities = this.entityCollection.toArray();
entities.forEach((entity) => {
// 当前数据 => 原始数据
// 清空变更集
entity.changes.splice(0, entity.changes.length);
});
}),
// 转换为结果流
map(() => {
}), map(() => {
return true;

@@ -920,2 +897,97 @@ }));

}
// #region 工具方法
/**
* 根据path获取实体集合
* @param fpath 路径
* @param childData 实体数据
*/
appendEntityByPath(fpath, childData) {
const subPaths = fpath.split('/');
if (subPaths.length < 3) {
throw Error(`根据path删除实体数据出错了。传入的path[${fpath}]格式不对`);
}
let childEntityList;
let propInfo;
let propName;
for (let i = 2; i < subPaths.length; i = i + 2) {
const fid = subPaths[i - 1];
propName = subPaths[i];
// todo: EntityCollection重构之后这里无需差异处理
const parentEntity = childEntityList ? childEntityList.get(fid) : this.entityCollection.getEntityById(fid);
childEntityList = parentEntity[propName];
const entityType = propInfo ? propInfo.propEntityType : this.entityType;
propInfo = EntityUtil.getPropInfo(entityType, propName);
if (!childEntityList) {
throw Error(`fpath参数错误,无法找到${propName}对应的子表。fpath为:${fpath}`);
}
}
// const propInfo = EntityUtil.getPropInfo(this.entityType, propName);
const childEntity = EntityFactory(propInfo.propEntityType, childData);
childEntityList.appendNew(childEntity);
return childEntity;
}
/**
* 根据path获取实体集合
* @param fpath
*/
removeEntityByPath(fpath, id) {
const subPaths = fpath.split('/');
if (subPaths.length < 3) {
throw Error(`根据path删除实体数据出错了。传入的path[${fpath}]格式不对`);
}
let childEntityList;
for (let i = 2; i < subPaths.length; i = i + 2) {
const fid = subPaths[i - 1];
const propName = subPaths[i];
const parentEntity = childEntityList ? childEntityList.get(fid) : this.entityCollection.getEntityById(fid);
childEntityList = parentEntity[propName];
if (!childEntityList) {
throw Error(`fpath参数错误,无法找到${propName}对应的子表。fpath为:${fpath}`);
}
}
childEntityList.remove(id);
}
/**
* 清空所有本地实体的变更集
*/
clearAllEntityChanges() {
const entities = this.entityCollection.toArray();
entities.forEach((entity) => {
entity.changes.splice(0, entity.changes.length);
});
}
/**
* 获取数据变更
*/
getDataChangeDetails() {
const changeDetails = [];
const entities = this.entityCollection.getAllEntities();
entities.forEach((entity) => {
if (entity.changes.length === 0) {
return;
}
const changeDetail = this.changeBuilder.build(entity.changes);
changeDetails.push(changeDetail);
});
return changeDetails;
}
/**
* 处理数据变更
*/
handleDataChangeDetails(changeDetails) {
this.changeHandler.handle(this.entityType, this.entityCollection, changeDetails);
}
/**
* 获取变量变更
*/
getVariableChangeDetails() {
const changeDetails = [];
return changeDetails;
}
/**
* 处理变量变更
*/
handleVariableChangeDetails() {
throw new Error('Not Implemented');
}
};

@@ -929,5 +1001,5 @@ BefRepository = __decorate$2([

* @Author: Witt
* @Date: 2018-10-12 14:43:49
* @Date: 2019-02-23 13:57:47
* @Last Modified by: Witt
* @Last Modified time: 2018-11-15 16:08:42
* @Last Modified time: 2019-02-23 17:26:50
*/

@@ -943,2 +1015,7 @@ var __decorate$3 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {

};
const GET = 'GET';
const DELETE = 'DELETE';
const PUT = 'PUT';
const POST = 'POST';
const PATCH = 'PATCH';
/**

@@ -962,6 +1039,3 @@ * BEF取数服务

/**
* 列表查询
* @return 数据数组
* @todo
* 1、目前仅支持查询全部数据
* 查询
*/

@@ -974,6 +1048,22 @@ query(entityFilter) {

}
return this.request(url, 'GET');
return this.request(url, GET);
}
/**
* 数据检索
* 查询
*/
extendQuery(entityFilter, requestInfo) {
let url = `${this.baseUri}/extension/query`;
if (entityFilter) {
const entityFilterJson = JSON.stringify(entityFilter);
url = `${url}?entityFilter=${entityFilterJson}`;
}
// const body = {
// RequestInfo: requestInfo,
// };
const body = requestInfo;
const options = this.addBodyToOptions({}, body);
return this.request(url, PUT, null, options);
}
/**
* 检索数据
* @param id 单据内码

@@ -984,11 +1074,26 @@ * @return 数据对象

const url = `${this.baseUri}/${id}`;
return this.request(url, 'GET');
return this.request(url, GET);
}
/**
* 检索数据(扩展)
*/
extendRetrieve(id, requestInfo) {
const url = `${this.baseUri}/extension/retrieve/${id}`;
// const body = {
// RequestInfo: requestInfo,
// };
const body = requestInfo;
const options = this.addBodyToOptions({}, body);
return this.request(url, PUT, null, options);
}
/**
* 创建一条数据
* @summary
* 返回带默认值的空数据,服务器端该数据在BE缓存中,尚未保存到数据库
*/
create() {
return this.request(this.baseUri, 'POST');
create(defaultValue, requestInfo) {
const body = {
defaultValue: defaultValue,
RequestInfo: requestInfo,
};
const options = this.addBodyToOptions({}, body);
return this.request(this.baseUri, POST, null, options);
}

@@ -1000,23 +1105,33 @@ /**

*/
createByPath(fpath) {
createByPath(fpath, requestInfo) {
const pathUrl = this.convertPathToUrl(fpath);
const url = `${this.baseUri}${pathUrl}`;
return this.request(url, 'POST');
// const body = {
// RequestInfo: requestInfo
// };
const body = requestInfo;
const options = this.addBodyToOptions({}, body);
return this.request(url, POST, null, options);
}
/**
* 提交变更
* @summary
* 此时变更提交的BE缓存中,等待保存,服务器端不返回任何数据
*/
update(changeDetail) {
const optionsWithBody = this.addBody({}, changeDetail);
return this.innerRequest(this.baseUri, 'PATCH', null, optionsWithBody);
update(changeDetail, requestInfo) {
const body = {
changeDetail: changeDetail,
RequestInfo: requestInfo,
};
const options = this.addBodyToOptions({}, body);
return this.request(this.baseUri, PATCH, null, options);
}
/**
* 保存
* @summary
* 通过此地方将BEF中的变更缓存应用到数据库中,服务器端不返回任何数据
* 执行保存
*/
save() {
return this.innerRequest(this.baseUri, 'PUT');
save(requestInfo) {
// const body = {
// RequestInfo: requestInfo,
// };
const body = requestInfo;
const options = this.addBodyToOptions({}, body);
return this.request(this.baseUri, PUT, options);
}

@@ -1028,5 +1143,17 @@ /**

const url = `${this.baseUri}/${id}`;
return this.request(url, 'DELETE');
return this.request(url, DELETE);
}
/**
* 删除(扩展)
*/
extendDelete(id, requestInfo) {
const url = `${this.baseUri}/extension/delete/${id}`;
// const body = {
// RequestInfo: requestInfo,
// };
const body = requestInfo;
const options = this.addBodyToOptions({}, body);
return this.request(url, PUT, null, options);
}
/**
* 删除后代

@@ -1038,5 +1165,19 @@ * @param fpath 父路径(从表形如:/1/edus,从从表形如:/1/edus/11/grades)

const url = `${this.baseUri}${pathUrl}/${id}`;
return this.request(url, 'DELETE');
return this.request(url, DELETE);
}
/**
* 删除后代(扩展)
* @param fpath 父路径(从表形如:/1/edus,从从表形如:/1/edus/11/grades)
*/
extendDeletByPath(fpath, id, requestInfo) {
const pathUrl = this.convertPathToUrl(fpath);
const url = `${this.baseUri}/extension${pathUrl}/${id}`;
// const body = {
// RequestInfo: requestInfo,
// };
const body = requestInfo;
const options = this.addBodyToOptions({}, body);
return this.request(url, PUT, null, options);
}
/**
* 批量删除

@@ -1049,11 +1190,18 @@ * @param ids 待删除的id数组

};
return this.request(this.baseUri, 'DELETE', params);
return this.request(this.baseUri, DELETE, params);
}
/**
* 批量删除子表记录
* @param fpath 父路径
* @param ids 待删除的id数组
* 批量删除(扩展)
*/
batchDeleteByPath(fpath, ids) {
throw new Error('Not Implemented');
extendBatchDelete(ids, requestInfo) {
const url = `${this.baseUri}/extension/batchdelete`;
const params = {
ids: ids.join(',')
};
// const body = {
// RequestInfo: requestInfo,
// };
const body = requestInfo;
const options = this.addBodyToOptions({}, body);
return this.request(url, PUT, params, options);
}

@@ -1065,22 +1213,9 @@ /**

const url = `${this.baseUri}/service/cancel`;
return this.request(url, 'POST');
return this.request(url, POST);
}
/**
* 发送http请求
*/
request(url, method, params, options) {
if (method !== 'GET') {
return this.repository.updateAllChanges().pipe(switchMap(() => {
return this.innerRequest(url, method, params, options);
}));
}
else {
return this.innerRequest(url, method, params, options);
}
}
/**
* 发送http请求(请勿使用)
* @internal
*/
innerRequest(url, method, params, options) {
request(url, method, params, options) {
options = options || {};

@@ -1092,2 +1227,7 @@ // params

}
// 带有requestInfo的请求,请求成功后清空变更集
let clearChanges = false;
if (options && options.body && options.body.RequestInfo) {
clearChanges = true;
}
// 串联session流和http流

@@ -1102,4 +1242,15 @@ return this.sessionService.getBeSessionId().pipe(switchMap((sessionId) => {

return this.httpClient.request(method, url, options);
}), tap((result) => {
const responseInfo = result;
// 响应数据变更
if (responseInfo.innerDataChange) {
this.repository.handleDataChangeDetails(responseInfo.innerDataChange);
}
// 清空本地变更集
if (clearChanges) {
this.repository.clearAllEntityChanges();
}
}));
}
// #region 工具方法
/**

@@ -1124,3 +1275,3 @@ * 构造HttpParams对象

*/
addBody(options, body) {
addBodyToOptions(options, body) {
options = options || {};

@@ -1131,6 +1282,25 @@ const mergedOptions = Object.assign(options, { body: body });

/**
* 构造带RequestInfo的Body
* @body 未携带RequestInfo的body,格式形如: {key1: value1, key2: value2}
*/
buildBodyWithRequestInfo(body) {
if (body.RequestInfo) {
return body;
}
const requestInfo = this.buildRequestInfo();
const bodyWithRequestInfo = Object.assign({}, body, { RequestInfo: requestInfo });
return bodyWithRequestInfo;
}
/**
* 构造RequestInfo
*/
buildRequestInfo() {
const requestInfo = {
dataChange: this.repository.getDataChangeDetails(),
variableChange: []
};
return requestInfo;
}
/**
* 在devkit的路径中表名是属性名,是复数,在url中表名是单数
* 在此做兼容
* @todo:临时支持子表,应该支持无限层级
* fixed by justin: 每级属性名都去掉s
*/

@@ -1202,3 +1372,3 @@ convertPathToUrl(path) {

export { ChangeDetailType, ChangeDetail, BE_SERVER_URI_TOKEN, BefChangeBuilder, BefSessionService, BefRestService, BefLookupRestService, BefRepository, FrameworkSessionService };
export { ChangeDetailType, BE_SERVER_URI_TOKEN, BefChangeBuilder, BefChangeHandler, BefSessionService, BefRestService, BefLookupRestService, BefRepository, FrameworkSessionService };
//# sourceMappingURL=index.bundle.js.map
import { InjectionToken, Injectable, Injector } from '@angular/core';
import { FieldMetadataUtil, ModifyType, EntityFactory, Repository } from '@farris/devkit';
import { FieldMetadataUtil, ModifyType, EntityCollection, EntityFactory, Repository } from '@farris/devkit';
import { CacheService } from '@ecp-caf/caf-common';

@@ -14,6 +14,11 @@ import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';

* @Date: 2018-10-19 15:36:48
* @Last Modified by: Witt
* @Last Modified time: 2018-10-19 15:36:48
* @Last Modified by: Witt
* @Last Modified time: 2019-02-23 11:38:35
*/
/**
* --------------------------------------------------------------------------------
* 变更集相关类型
* --------------------------------------------------------------------------------
*/
/**
* 变更类型

@@ -36,13 +41,2 @@ */

})(ChangeDetailType || (ChangeDetailType = {}));
/**
* 行变更详情
* 包含:
* 1、变更类型;
* 2、变更信息
*/
var ChangeDetail = /** @class */ (function () {
function ChangeDetail() {
}
return ChangeDetail;
}());

@@ -366,2 +360,82 @@ /*

/**
* 处理服务器端变更
*/
var BefChangeHandler = /** @class */ (function () {
/**
* 构造函数
*/
function BefChangeHandler() {
}
/**
* 处理Bef变更集
*/
BefChangeHandler.prototype.handle = function (entityType, entityCollection, changeDetails) {
this.handleChangeDetails(entityType, entityCollection, changeDetails);
};
/**
* 处理Bef变更集(批量)
* @param entities
*/
BefChangeHandler.prototype.handleChangeDetails = function (entityType, entityList, changeDetails) {
var _this = this;
changeDetails.forEach(function (changeDetail) {
var id = changeDetail.ChangeInfo.DataId;
var entity = _this.getEntityById(entityList, id);
_this.handleChangeDetail(entityType, entity, changeDetail);
});
};
/**
* 处理Bef变更集(单条)
*/
BefChangeHandler.prototype.handleChangeDetail = function (entityType, entity, changeDetail) {
var _this = this;
// 只处理值变更,其他变更待进一步验证。
if (changeDetail.ChangeType !== ChangeDetailType.Modify) {
return;
}
var changeInfo = changeDetail.ChangeInfo;
Object.keys(changeInfo).forEach(function (propName) {
var _a = EntityUtil.getPropInfo(entityType, propName), propType = _a.propType, propEntityType = _a.propEntityType;
if (propType === 'NgField') {
// 简单属性:更新值
entity[propName] = changeInfo[propName];
}
else if (propType === 'NgObject') {
var childEntity = entity[propName];
if (childEntity.primaryKey) {
// 关联对象:重新加载数据
var childEntityData = changeInfo[propName];
childEntity.load(childEntityData);
}
else {
// 值对象:递归处理变更
var childChangeDetail = changeInfo[propName];
_this.handleChangeDetail(propEntityType, childEntity, childChangeDetail);
}
}
else if (propType === 'NgList') {
// 子列表:递归处理变更集合
var childEntityList = entity[propName];
var childChangeDetails = changeInfo[propName];
_this.handleChangeDetails(propEntityType, childEntityList, childChangeDetails);
}
});
};
/**
* 根据id获取实体,屏蔽EntityCollection和EntityList之间的差异
*/
BefChangeHandler.prototype.getEntityById = function (entityList, id) {
var target;
if (entityList instanceof EntityCollection) {
target = entityList.getEntityById(id);
}
else {
target = entityList.get(id);
}
return target ? target : null;
};
return BefChangeHandler;
}());
/*

@@ -514,3 +588,3 @@ * @Author: Witt

* @Last Modified by: Witt
* @Last Modified time: 2018-12-13 20:21:22
* @Last Modified time: 2019-02-23 16:56:03
*

@@ -563,10 +637,6 @@ * @todo

_this.changeBuilder = new BefChangeBuilder(_this.entityType, _this.entityCollection);
_this.changeHandler = new BefChangeHandler();
return _this;
}
/**
* --------------------------------------------------------------------------------
* @todo: 新API
* --------------------------------------------------------------------------------
*/
/**
* 获取实体集合

@@ -594,7 +664,8 @@ */

};
var query$ = this.restService.query(entityFilter);
return query$.pipe(map(function (queryResult) {
var requestInfo = this.restService.buildRequestInfo();
var query$ = this.restService.extendQuery(entityFilter, requestInfo);
return query$.pipe(map(function (responseInfo) {
var queryResult = responseInfo.returnValue;
var listData = queryResult.result;
var entities = [];
// const listData = queryResult['result'];
var listData = queryResult;
listData.forEach(function (data) {

@@ -609,7 +680,2 @@ var entity = _this.buildEntity(data);

/**
* --------------------------------------------------------------------------------
* @todo: 已过期,待删除
* --------------------------------------------------------------------------------
*/
/**
* 获取实体集合

@@ -619,7 +685,9 @@ */

var _this = this;
var query$ = this.restService.query();
return query$.pipe(map(function (queryResult) {
var entityFilter = null;
var requestInfo = this.restService.buildRequestInfo();
var query$ = this.restService.extendQuery(entityFilter, requestInfo);
return query$.pipe(map(function (responseInfo) {
var queryResult = responseInfo.returnValue;
var listData = queryResult.result;
var entities = [];
// const listData = queryResult['result'];
var listData = queryResult;
listData.forEach(function (data) {

@@ -638,5 +706,7 @@ var entity = _this.buildEntity(data);

var _this = this;
var retrieve$ = this.restService.retrieve(id);
var result$ = retrieve$.pipe(map(function (data) {
var entity = _this.buildEntity(data);
var requestInfo = this.restService.buildRequestInfo();
var retrieve$ = this.restService.extendRetrieve(id, requestInfo);
var result$ = retrieve$.pipe(map(function (responseInfo) {
var entityData = responseInfo.returnValue;
var entity = _this.buildEntity(entityData);
_this.entityCollection.loadEntities([entity]);

@@ -653,6 +723,8 @@ return entity;

var _this = this;
var retrieve$ = this.restService.retrieve(id);
var result$ = retrieve$.pipe(map(function (data) {
var requestInfo = this.restService.buildRequestInfo();
var retrieve$ = this.restService.extendRetrieve(id, requestInfo);
var result$ = retrieve$.pipe(map(function (responseInfo) {
var entityData = responseInfo.returnValue;
var entity = _this.entityCollection.getEntityById(id);
entity.load(data);
entity.load(entityData);
return entity;

@@ -663,15 +735,10 @@ }));

/**
* 根据id给实体加锁
* @todo:通过一个空变更进行加锁,待确认
*/
BefRepository.prototype.lockById = function (id) {
return of(true);
};
/**
* 创建新实体,并加载
*/
BefRepository.prototype.create = function () {
BefRepository.prototype.create = function (defaultValue) {
var _this = this;
var result$ = this.restService.create();
return result$.pipe(map(function (newData) {
var requestInfo = this.restService.buildRequestInfo();
var result$ = this.restService.create(defaultValue, requestInfo);
return result$.pipe(map(function (responseInfo) {
var newData = responseInfo.returnValue;
var newEntity = _this.buildEntity(newData);

@@ -683,15 +750,10 @@ _this.entityCollection.loadEntities([newEntity]);

/**
* 创建子实体,并加载
* @param path 路径
*/
BefRepository.prototype.createByPath = function (path) {
throw new Error('Not Implemented');
};
/**
* 追加实体
*/
BefRepository.prototype.append = function () {
BefRepository.prototype.append = function (defaultValue) {
var _this = this;
var append$ = this.restService.create();
return append$.pipe(map(function (newData) {
var requestInfo = this.restService.buildRequestInfo();
var append$ = this.restService.create(defaultValue, requestInfo);
return append$.pipe(map(function (responseInfo) {
var newData = responseInfo.returnValue;
var newEntity = _this.buildEntity(newData);

@@ -708,4 +770,6 @@ _this.entityCollection.addEntity(newEntity);

var _this = this;
var append$ = this.restService.createByPath(fpath);
return append$.pipe(map(function (newData) {
var requestInfo = this.restService.buildRequestInfo();
var append$ = this.restService.createByPath(fpath, requestInfo);
return append$.pipe(map(function (responseInfo) {
var newData = responseInfo.returnValue;
var newEntity = _this.appendEntityByPath(fpath, newData);

@@ -716,41 +780,2 @@ return newEntity;

/**
* 根据path获取实体集合
* @param fpath
* @todo:临时模拟,强识别2级路径
* fixed by justin: 循环识别path
*/
BefRepository.prototype.appendEntityByPath = function (fpath, childData) {
// const [ , fid, propName ] = fpath.split('/');
// const parentEntity = this.entityCollection.getEntityById(fid);
// const childEntityList = parentEntity[propName];
// const propInfo = EntityUtil.getPropInfo(this.entityType, propName);
// const childEntity = EntityFactory<Entity>(propInfo.propEntityType, childData);
// childEntityList.appendNew(childEntity);
// return childEntity;
var subPaths = fpath.split('/');
if (subPaths.length < 3) {
throw Error("\u6839\u636Epath\u5220\u9664\u5B9E\u4F53\u6570\u636E\u51FA\u9519\u4E86\u3002\u4F20\u5165\u7684path[" + fpath + "]\u683C\u5F0F\u4E0D\u5BF9");
// return;
}
var childEntityList;
var propInfo;
var propName;
for (var i = 2; i < subPaths.length; i = i + 2) {
var fid = subPaths[i - 1];
propName = subPaths[i];
// todo: EntityCollection重构之后这里无需差异处理
var parentEntity = childEntityList ? childEntityList.get(fid) : this.entityCollection.getEntityById(fid);
childEntityList = parentEntity[propName];
var entityType = propInfo ? propInfo.propEntityType : this.entityType;
propInfo = EntityUtil.getPropInfo(entityType, propName);
if (!childEntityList) {
throw Error("fpath\u53C2\u6570\u9519\u8BEF\uFF0C\u65E0\u6CD5\u627E\u5230" + propName + "\u5BF9\u5E94\u7684\u5B50\u8868\u3002fpath\u4E3A\uFF1A" + fpath);
}
}
// const propInfo = EntityUtil.getPropInfo(this.entityType, propName);
var childEntity = EntityFactory(propInfo.propEntityType, childData);
childEntityList.appendNew(childEntity);
return childEntity;
};
/**
* 根据id删除实体

@@ -763,3 +788,4 @@ * @param id 内码

// 服务器端删除
var delete$ = this.restService.delete(id);
var requestInfo = this.restService.buildRequestInfo();
var delete$ = this.restService.extendDelete(id, requestInfo);
// 从本地实体集合中移除

@@ -793,3 +819,4 @@ return delete$.pipe(switchMap(function () {

// 服务器端删除
var delete$ = this.restService.deletByPath(fpath, id);
var requestInfo = this.restService.buildRequestInfo();
var delete$ = this.restService.extendDeletByPath(fpath, id, requestInfo);
// 从本地实体集合中移除

@@ -802,29 +829,2 @@ return delete$.pipe(map(function () {

/**
* 根据path获取实体集合
* @param fpath
* @todo:临时模拟,强识别2级路径
* fixed by justin: 循环识别路径,支持多级
*/
BefRepository.prototype.removeEntityByPath = function (fpath, id) {
// const [ , fid, propName ] = fpath.split('/');
// const parentEntity = this.entityCollection.getEntityById(fid);
// const childEntityList: EntityList<Entity> = parentEntity[propName];
var subPaths = fpath.split('/');
if (subPaths.length < 3) {
throw Error("\u6839\u636Epath\u5220\u9664\u5B9E\u4F53\u6570\u636E\u51FA\u9519\u4E86\u3002\u4F20\u5165\u7684path[" + fpath + "]\u683C\u5F0F\u4E0D\u5BF9");
}
var childEntityList;
for (var i = 2; i < subPaths.length; i = i + 2) {
var fid = subPaths[i - 1];
var propName = subPaths[i];
var parentEntity = childEntityList ? childEntityList.get(fid) : this.entityCollection.getEntityById(fid);
childEntityList = parentEntity[propName];
if (!childEntityList) {
throw Error("fpath\u53C2\u6570\u9519\u8BEF\uFF0C\u65E0\u6CD5\u627E\u5230" + propName + "\u5BF9\u5E94\u7684\u5B50\u8868\u3002fpath\u4E3A\uFF1A" + fpath);
}
}
childEntityList.remove(id);
// 清空实体中
};
/**
* 将id对应的实体的变更提交的服务器端

@@ -843,3 +843,4 @@ */

var changeDetail = this.changeBuilder.build(entity.changes);
var update$ = this.restService.update(changeDetail);
var requestInfo = this.restService.buildRequestInfo();
var update$ = this.restService.update(changeDetail, requestInfo);
var result$ = update$.pipe(tap(function () {

@@ -875,3 +876,3 @@ // 清空变更集

// 串联流
var result$ = zip.apply(void 0, updateResults).pipe(map(function (results) {
var result$ = zip.apply(void 0, updateResults).pipe(map(function () {
return true;

@@ -886,23 +887,14 @@ }));

var _this = this;
var save$ = this.restService.save();
var requestInfo = this.restService.buildRequestInfo();
var save$ = this.restService.save(requestInfo);
var result$ = save$.pipe(
// 更新本地数据
tap(function (saveResult) {
if (saveResult) {
var entities = _this.entityCollection.toArray();
entities.forEach(function (entity) {
// 当前数据 => 原始数据
// 清空变更集
entity.changes.splice(0, entity.changes.length);
});
}
}),
// 转换为保存结果流(boolean流)
map(function (saveResult) {
if (saveResult === false) {
return false;
}
else {
return true;
}
tap(function () {
var entities = _this.entityCollection.toArray();
entities.forEach(function (entity) {
// 清空变更集
entity.changes.splice(0, entity.changes.length);
});
}), map(function () {
return true;
}));

@@ -916,21 +908,12 @@ return result$;

var _this = this;
var save$ = this.restService.save();
var result$ = save$.pipe(
// 更新本地数据
tap(function (saveResult) {
if (saveResult) {
var entity = _this.entityCollection.getEntityById(id);
// 当前数据 => 原始数据
// 清空变更集
var requestInfo = this.restService.buildRequestInfo();
var save$ = this.restService.save(requestInfo);
var result$ = save$.pipe(tap(function () {
// 清空变更集
var entity = _this.entityCollection.getEntityById(id);
if (entity) {
entity.changes.splice(0, entity.changes.length);
}
}),
// 转换为保存结果流(boolean流)
map(function (saveResult) {
if (saveResult === false) {
return false;
}
else {
return true;
}
}), map(function () {
return true;
}));

@@ -945,14 +928,8 @@ return result$;

var cancel$ = this.restService.cancel();
cancel$.pipe(
// 数据源操作
tap(function () {
cancel$.pipe(tap(function () {
var entities = _this.entityCollection.toArray();
entities.forEach(function (entity) {
// 当前数据 => 原始数据
// 清空变更集
entity.changes.splice(0, entity.changes.length);
});
}),
// 转换为结果流
map(function () {
}), map(function () {
return true;

@@ -962,2 +939,98 @@ }));

};
// #region 工具方法
/**
* 根据path获取实体集合
* @param fpath 路径
* @param childData 实体数据
*/
BefRepository.prototype.appendEntityByPath = function (fpath, childData) {
var subPaths = fpath.split('/');
if (subPaths.length < 3) {
throw Error("\u6839\u636Epath\u5220\u9664\u5B9E\u4F53\u6570\u636E\u51FA\u9519\u4E86\u3002\u4F20\u5165\u7684path[" + fpath + "]\u683C\u5F0F\u4E0D\u5BF9");
}
var childEntityList;
var propInfo;
var propName;
for (var i = 2; i < subPaths.length; i = i + 2) {
var fid = subPaths[i - 1];
propName = subPaths[i];
// todo: EntityCollection重构之后这里无需差异处理
var parentEntity = childEntityList ? childEntityList.get(fid) : this.entityCollection.getEntityById(fid);
childEntityList = parentEntity[propName];
var entityType = propInfo ? propInfo.propEntityType : this.entityType;
propInfo = EntityUtil.getPropInfo(entityType, propName);
if (!childEntityList) {
throw Error("fpath\u53C2\u6570\u9519\u8BEF\uFF0C\u65E0\u6CD5\u627E\u5230" + propName + "\u5BF9\u5E94\u7684\u5B50\u8868\u3002fpath\u4E3A\uFF1A" + fpath);
}
}
// const propInfo = EntityUtil.getPropInfo(this.entityType, propName);
var childEntity = EntityFactory(propInfo.propEntityType, childData);
childEntityList.appendNew(childEntity);
return childEntity;
};
/**
* 根据path获取实体集合
* @param fpath
*/
BefRepository.prototype.removeEntityByPath = function (fpath, id) {
var subPaths = fpath.split('/');
if (subPaths.length < 3) {
throw Error("\u6839\u636Epath\u5220\u9664\u5B9E\u4F53\u6570\u636E\u51FA\u9519\u4E86\u3002\u4F20\u5165\u7684path[" + fpath + "]\u683C\u5F0F\u4E0D\u5BF9");
}
var childEntityList;
for (var i = 2; i < subPaths.length; i = i + 2) {
var fid = subPaths[i - 1];
var propName = subPaths[i];
var parentEntity = childEntityList ? childEntityList.get(fid) : this.entityCollection.getEntityById(fid);
childEntityList = parentEntity[propName];
if (!childEntityList) {
throw Error("fpath\u53C2\u6570\u9519\u8BEF\uFF0C\u65E0\u6CD5\u627E\u5230" + propName + "\u5BF9\u5E94\u7684\u5B50\u8868\u3002fpath\u4E3A\uFF1A" + fpath);
}
}
childEntityList.remove(id);
};
/**
* 清空所有本地实体的变更集
*/
BefRepository.prototype.clearAllEntityChanges = function () {
var entities = this.entityCollection.toArray();
entities.forEach(function (entity) {
entity.changes.splice(0, entity.changes.length);
});
};
/**
* 获取数据变更
*/
BefRepository.prototype.getDataChangeDetails = function () {
var _this = this;
var changeDetails = [];
var entities = this.entityCollection.getAllEntities();
entities.forEach(function (entity) {
if (entity.changes.length === 0) {
return;
}
var changeDetail = _this.changeBuilder.build(entity.changes);
changeDetails.push(changeDetail);
});
return changeDetails;
};
/**
* 处理数据变更
*/
BefRepository.prototype.handleDataChangeDetails = function (changeDetails) {
this.changeHandler.handle(this.entityType, this.entityCollection, changeDetails);
};
/**
* 获取变量变更
*/
BefRepository.prototype.getVariableChangeDetails = function () {
var changeDetails = [];
return changeDetails;
};
/**
* 处理变量变更
*/
BefRepository.prototype.handleVariableChangeDetails = function () {
throw new Error('Not Implemented');
};
BefRepository = __decorate$2([

@@ -972,5 +1045,5 @@ Injectable(),

* @Author: Witt
* @Date: 2018-10-12 14:43:49
* @Date: 2019-02-23 13:57:47
* @Last Modified by: Witt
* @Last Modified time: 2018-11-15 16:08:42
* @Last Modified time: 2019-02-23 17:26:50
*/

@@ -986,2 +1059,7 @@ var __decorate$3 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {

};
var GET = 'GET';
var DELETE = 'DELETE';
var PUT = 'PUT';
var POST = 'POST';
var PATCH = 'PATCH';
/**

@@ -1005,6 +1083,3 @@ * BEF取数服务

/**
* 列表查询
* @return 数据数组
* @todo
* 1、目前仅支持查询全部数据
* 查询
*/

@@ -1017,6 +1092,22 @@ BefRestService.prototype.query = function (entityFilter) {

}
return this.request(url, 'GET');
return this.request(url, GET);
};
/**
* 数据检索
* 查询
*/
BefRestService.prototype.extendQuery = function (entityFilter, requestInfo) {
var url = this.baseUri + "/extension/query";
if (entityFilter) {
var entityFilterJson = JSON.stringify(entityFilter);
url = url + "?entityFilter=" + entityFilterJson;
}
// const body = {
// RequestInfo: requestInfo,
// };
var body = requestInfo;
var options = this.addBodyToOptions({}, body);
return this.request(url, PUT, null, options);
};
/**
* 检索数据
* @param id 单据内码

@@ -1027,11 +1118,26 @@ * @return 数据对象

var url = this.baseUri + "/" + id;
return this.request(url, 'GET');
return this.request(url, GET);
};
/**
* 检索数据(扩展)
*/
BefRestService.prototype.extendRetrieve = function (id, requestInfo) {
var url = this.baseUri + "/extension/retrieve/" + id;
// const body = {
// RequestInfo: requestInfo,
// };
var body = requestInfo;
var options = this.addBodyToOptions({}, body);
return this.request(url, PUT, null, options);
};
/**
* 创建一条数据
* @summary
* 返回带默认值的空数据,服务器端该数据在BE缓存中,尚未保存到数据库
*/
BefRestService.prototype.create = function () {
return this.request(this.baseUri, 'POST');
BefRestService.prototype.create = function (defaultValue, requestInfo) {
var body = {
defaultValue: defaultValue,
RequestInfo: requestInfo,
};
var options = this.addBodyToOptions({}, body);
return this.request(this.baseUri, POST, null, options);
};

@@ -1043,23 +1149,33 @@ /**

*/
BefRestService.prototype.createByPath = function (fpath) {
BefRestService.prototype.createByPath = function (fpath, requestInfo) {
var pathUrl = this.convertPathToUrl(fpath);
var url = "" + this.baseUri + pathUrl;
return this.request(url, 'POST');
// const body = {
// RequestInfo: requestInfo
// };
var body = requestInfo;
var options = this.addBodyToOptions({}, body);
return this.request(url, POST, null, options);
};
/**
* 提交变更
* @summary
* 此时变更提交的BE缓存中,等待保存,服务器端不返回任何数据
*/
BefRestService.prototype.update = function (changeDetail) {
var optionsWithBody = this.addBody({}, changeDetail);
return this.innerRequest(this.baseUri, 'PATCH', null, optionsWithBody);
BefRestService.prototype.update = function (changeDetail, requestInfo) {
var body = {
changeDetail: changeDetail,
RequestInfo: requestInfo,
};
var options = this.addBodyToOptions({}, body);
return this.request(this.baseUri, PATCH, null, options);
};
/**
* 保存
* @summary
* 通过此地方将BEF中的变更缓存应用到数据库中,服务器端不返回任何数据
* 执行保存
*/
BefRestService.prototype.save = function () {
return this.innerRequest(this.baseUri, 'PUT');
BefRestService.prototype.save = function (requestInfo) {
// const body = {
// RequestInfo: requestInfo,
// };
var body = requestInfo;
var options = this.addBodyToOptions({}, body);
return this.request(this.baseUri, PUT, options);
};

@@ -1071,5 +1187,17 @@ /**

var url = this.baseUri + "/" + id;
return this.request(url, 'DELETE');
return this.request(url, DELETE);
};
/**
* 删除(扩展)
*/
BefRestService.prototype.extendDelete = function (id, requestInfo) {
var url = this.baseUri + "/extension/delete/" + id;
// const body = {
// RequestInfo: requestInfo,
// };
var body = requestInfo;
var options = this.addBodyToOptions({}, body);
return this.request(url, PUT, null, options);
};
/**
* 删除后代

@@ -1081,5 +1209,19 @@ * @param fpath 父路径(从表形如:/1/edus,从从表形如:/1/edus/11/grades)

var url = "" + this.baseUri + pathUrl + "/" + id;
return this.request(url, 'DELETE');
return this.request(url, DELETE);
};
/**
* 删除后代(扩展)
* @param fpath 父路径(从表形如:/1/edus,从从表形如:/1/edus/11/grades)
*/
BefRestService.prototype.extendDeletByPath = function (fpath, id, requestInfo) {
var pathUrl = this.convertPathToUrl(fpath);
var url = this.baseUri + "/extension" + pathUrl + "/" + id;
// const body = {
// RequestInfo: requestInfo,
// };
var body = requestInfo;
var options = this.addBodyToOptions({}, body);
return this.request(url, PUT, null, options);
};
/**
* 批量删除

@@ -1092,11 +1234,18 @@ * @param ids 待删除的id数组

};
return this.request(this.baseUri, 'DELETE', params);
return this.request(this.baseUri, DELETE, params);
};
/**
* 批量删除子表记录
* @param fpath 父路径
* @param ids 待删除的id数组
* 批量删除(扩展)
*/
BefRestService.prototype.batchDeleteByPath = function (fpath, ids) {
throw new Error('Not Implemented');
BefRestService.prototype.extendBatchDelete = function (ids, requestInfo) {
var url = this.baseUri + "/extension/batchdelete";
var params = {
ids: ids.join(',')
};
// const body = {
// RequestInfo: requestInfo,
// };
var body = requestInfo;
var options = this.addBodyToOptions({}, body);
return this.request(url, PUT, params, options);
};

@@ -1108,23 +1257,9 @@ /**

var url = this.baseUri + "/service/cancel";
return this.request(url, 'POST');
return this.request(url, POST);
};
/**
* 发送http请求
*/
BefRestService.prototype.request = function (url, method, params, options) {
var _this = this;
if (method !== 'GET') {
return this.repository.updateAllChanges().pipe(switchMap(function () {
return _this.innerRequest(url, method, params, options);
}));
}
else {
return this.innerRequest(url, method, params, options);
}
};
/**
* 发送http请求(请勿使用)
* @internal
*/
BefRestService.prototype.innerRequest = function (url, method, params, options) {
BefRestService.prototype.request = function (url, method, params, options) {
var _this = this;

@@ -1137,2 +1272,7 @@ options = options || {};

}
// 带有requestInfo的请求,请求成功后清空变更集
var clearChanges = false;
if (options && options.body && options.body.RequestInfo) {
clearChanges = true;
}
// 串联session流和http流

@@ -1147,4 +1287,15 @@ return this.sessionService.getBeSessionId().pipe(switchMap(function (sessionId) {

return _this.httpClient.request(method, url, options);
}), tap(function (result) {
var responseInfo = result;
// 响应数据变更
if (responseInfo.innerDataChange) {
_this.repository.handleDataChangeDetails(responseInfo.innerDataChange);
}
// 清空本地变更集
if (clearChanges) {
_this.repository.clearAllEntityChanges();
}
}));
};
// #region 工具方法
/**

@@ -1169,3 +1320,3 @@ * 构造HttpParams对象

*/
BefRestService.prototype.addBody = function (options, body) {
BefRestService.prototype.addBodyToOptions = function (options, body) {
options = options || {};

@@ -1176,6 +1327,25 @@ var mergedOptions = Object.assign(options, { body: body });

/**
* 构造带RequestInfo的Body
* @body 未携带RequestInfo的body,格式形如: {key1: value1, key2: value2}
*/
BefRestService.prototype.buildBodyWithRequestInfo = function (body) {
if (body.RequestInfo) {
return body;
}
var requestInfo = this.buildRequestInfo();
var bodyWithRequestInfo = Object.assign({}, body, { RequestInfo: requestInfo });
return bodyWithRequestInfo;
};
/**
* 构造RequestInfo
*/
BefRestService.prototype.buildRequestInfo = function () {
var requestInfo = {
dataChange: this.repository.getDataChangeDetails(),
variableChange: []
};
return requestInfo;
};
/**
* 在devkit的路径中表名是属性名,是复数,在url中表名是单数
* 在此做兼容
* @todo:临时支持子表,应该支持无限层级
* fixed by justin: 每级属性名都去掉s
*/

@@ -1253,3 +1423,3 @@ BefRestService.prototype.convertPathToUrl = function (path) {

export { ChangeDetailType, ChangeDetail, BE_SERVER_URI_TOKEN, BefChangeBuilder, BefSessionService, BefRestService, BefLookupRestService, BefRepository, FrameworkSessionService };
export { ChangeDetailType, BE_SERVER_URI_TOKEN, BefChangeBuilder, BefChangeHandler, BefSessionService, BefRestService, BefLookupRestService, BefRepository, FrameworkSessionService };
//# sourceMappingURL=index.bundle.js.map
export * from './src/types';
export * from './src/tokens';
export * from './src/bef_change_builder';
export * from './src/bef_change_handler';
export * from './src/bef_session.service';

@@ -5,0 +6,0 @@ export * from './src/bef_rest_service';

@@ -1,1 +0,1 @@

{"__symbolic":"module","version":4,"metadata":{"ChangeDetailType":{"Added":"Added","Modify":"Modify","Deleted":"Deleted"},"ChangeDetailInfo":{"__symbolic":"interface"},"ChangeDetail":{"__symbolic":"class","members":{}},"BE_SERVER_URI_TOKEN":{"__symbolic":"new","expression":{"__symbolic":"reference","module":"@angular/core","name":"InjectionToken","line":9,"character":32},"arguments":["@farris/be BE_SERVER_URL"]},"BefChangeBuilder":{"__symbolic":"class","members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","name":"Type","module":"@angular/core","arguments":[{"__symbolic":"reference","module":"@farris/devkit","name":"Entity","line":28,"character":29}]},{"__symbolic":"reference","name":"EntityCollection","module":"@farris/devkit","arguments":[{"__symbolic":"reference","module":"@farris/devkit","name":"Entity","line":28,"character":29}]}]}],"build":[{"__symbolic":"method"}],"buildChangeDetail":[{"__symbolic":"method"}],"addAddChangeDetail":[{"__symbolic":"method"}],"addRemoveChangeDetail":[{"__symbolic":"method"}],"getChangeInfo":[{"__symbolic":"method"}],"createEmptyChangeDetail":[{"__symbolic":"method"}]}},"BefSessionService":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable","line":28,"character":1}}],"members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","module":"@angular/common/http","name":"HttpClient","line":59,"character":26},{"__symbolic":"reference","name":"string"},{"__symbolic":"reference","name":"FrameworkSessionService"}]}],"getBeSessionId":[{"__symbolic":"method"}],"setBeSessionId":[{"__symbolic":"method"}],"createBeSession":[{"__symbolic":"method"}],"clearBeSessionId":[{"__symbolic":"method"}]}},"BefRestService":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable","line":23,"character":1}}],"members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","module":"@angular/common/http","name":"HttpClient","line":50,"character":16},{"__symbolic":"reference","name":"string"},{"__symbolic":"reference","name":"FrameworkSessionService"},{"__symbolic":"reference","name":"BefRepository"}]}],"query":[{"__symbolic":"method"}],"retrieve":[{"__symbolic":"method"}],"create":[{"__symbolic":"method"}],"createByPath":[{"__symbolic":"method"}],"update":[{"__symbolic":"method"}],"save":[{"__symbolic":"method"}],"delete":[{"__symbolic":"method"}],"deletByPath":[{"__symbolic":"method"}],"batchDelete":[{"__symbolic":"method"}],"batchDeleteByPath":[{"__symbolic":"method"}],"cancel":[{"__symbolic":"method"}],"request":[{"__symbolic":"method"}],"innerRequest":[{"__symbolic":"method"}],"buildParams":[{"__symbolic":"method"}],"addBody":[{"__symbolic":"method"}],"convertPathToUrl":[{"__symbolic":"method"}]}},"BefLookupRestService":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable","line":9,"character":1}}],"members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","name":"Repository","module":"@farris/devkit","arguments":[{"__symbolic":"reference","name":"any"}]}]}],"getData":[{"__symbolic":"method"}],"convert2TreeDataWithPathCode":[{"__symbolic":"method"}]}},"BefRepository":{"__symbolic":"class","arity":1,"extends":{"__symbolic":"reference","module":"@farris/devkit","name":"Repository","line":38,"character":55},"decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable","line":37,"character":1}}],"members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","module":"@angular/core","name":"Injector","line":53,"character":24}]}],"getEntities":[{"__symbolic":"method"}],"getList":[{"__symbolic":"method"}],"getById":[{"__symbolic":"method"}],"updateById":[{"__symbolic":"method"}],"lockById":[{"__symbolic":"method"}],"create":[{"__symbolic":"method"}],"createByPath":[{"__symbolic":"method"}],"append":[{"__symbolic":"method"}],"appendByPath":[{"__symbolic":"method"}],"appendEntityByPath":[{"__symbolic":"method"}],"removeById":[{"__symbolic":"method"}],"removeByIds":[{"__symbolic":"method"}],"removeByPath":[{"__symbolic":"method"}],"removeEntityByPath":[{"__symbolic":"method"}],"updateChangesById":[{"__symbolic":"method"}],"updateChangesByPath":[{"__symbolic":"method"}],"updateAllChanges":[{"__symbolic":"method"}],"applyChanges":[{"__symbolic":"method"}],"applyChangesById":[{"__symbolic":"method"}],"cancelChanges":[{"__symbolic":"method"}]}},"FrameworkSessionService":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable","line":10,"character":1}}],"members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","module":"@ecp-caf/caf-common","name":"CacheService","line":13,"character":36}]}],"getUserSessionId":[{"__symbolic":"method"}]}}},"origins":{"ChangeDetailType":"./src/types","ChangeDetailInfo":"./src/types","ChangeDetail":"./src/types","BE_SERVER_URI_TOKEN":"./src/tokens","BefChangeBuilder":"./src/bef_change_builder","BefSessionService":"./src/bef_session.service","BefRestService":"./src/bef_rest_service","BefLookupRestService":"./src/bef_lookup.service","BefRepository":"./src/bef_repository","FrameworkSessionService":"./src/framework_session.service"},"importAs":"@farris/bef"}
{"__symbolic":"module","version":4,"metadata":{"ChangeDetailType":{"Added":"Added","Modify":"Modify","Deleted":"Deleted"},"ChangeDetailInfo":{"__symbolic":"interface"},"ChangeDetail":{"__symbolic":"interface"},"RequestInfo":{"__symbolic":"interface"},"QueryResult":{"__symbolic":"interface"},"ResponseInfo":{"__symbolic":"interface"},"BE_SERVER_URI_TOKEN":{"__symbolic":"new","expression":{"__symbolic":"reference","module":"@angular/core","name":"InjectionToken","line":9,"character":32},"arguments":["@farris/be BE_SERVER_URL"]},"BefChangeBuilder":{"__symbolic":"class","members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","name":"Type","module":"@angular/core","arguments":[{"__symbolic":"reference","module":"@farris/devkit","name":"Entity","line":28,"character":29}]},{"__symbolic":"reference","name":"EntityCollection","module":"@farris/devkit","arguments":[{"__symbolic":"reference","module":"@farris/devkit","name":"Entity","line":28,"character":29}]}]}],"build":[{"__symbolic":"method"}],"buildChangeDetail":[{"__symbolic":"method"}],"addAddChangeDetail":[{"__symbolic":"method"}],"addRemoveChangeDetail":[{"__symbolic":"method"}],"getChangeInfo":[{"__symbolic":"method"}],"createEmptyChangeDetail":[{"__symbolic":"method"}]}},"BefChangeHandler":{"__symbolic":"class","members":{"__ctor__":[{"__symbolic":"constructor"}],"handle":[{"__symbolic":"method"}],"handleChangeDetails":[{"__symbolic":"method"}],"handleChangeDetail":[{"__symbolic":"method"}],"getEntityById":[{"__symbolic":"method"}]}},"BefSessionService":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable","line":28,"character":1}}],"members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","module":"@angular/common/http","name":"HttpClient","line":59,"character":26},{"__symbolic":"reference","name":"string"},{"__symbolic":"reference","name":"FrameworkSessionService"}]}],"getBeSessionId":[{"__symbolic":"method"}],"setBeSessionId":[{"__symbolic":"method"}],"createBeSession":[{"__symbolic":"method"}],"clearBeSessionId":[{"__symbolic":"method"}]}},"BefRestService":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable","line":31,"character":1}}],"members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","module":"@angular/common/http","name":"HttpClient","line":58,"character":16},{"__symbolic":"reference","name":"string"},{"__symbolic":"reference","name":"FrameworkSessionService"},{"__symbolic":"reference","name":"BefRepository"}]}],"query":[{"__symbolic":"method"}],"extendQuery":[{"__symbolic":"method"}],"retrieve":[{"__symbolic":"method"}],"extendRetrieve":[{"__symbolic":"method"}],"create":[{"__symbolic":"method"}],"createByPath":[{"__symbolic":"method"}],"update":[{"__symbolic":"method"}],"save":[{"__symbolic":"method"}],"delete":[{"__symbolic":"method"}],"extendDelete":[{"__symbolic":"method"}],"deletByPath":[{"__symbolic":"method"}],"extendDeletByPath":[{"__symbolic":"method"}],"batchDelete":[{"__symbolic":"method"}],"extendBatchDelete":[{"__symbolic":"method"}],"cancel":[{"__symbolic":"method"}],"request":[{"__symbolic":"method"}],"buildParams":[{"__symbolic":"method"}],"addBodyToOptions":[{"__symbolic":"method"}],"buildBodyWithRequestInfo":[{"__symbolic":"method"}],"buildRequestInfo":[{"__symbolic":"method"}],"convertPathToUrl":[{"__symbolic":"method"}]}},"BefLookupRestService":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable","line":9,"character":1}}],"members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","name":"Repository","module":"@farris/devkit","arguments":[{"__symbolic":"reference","name":"any"}]}]}],"getData":[{"__symbolic":"method"}],"convert2TreeDataWithPathCode":[{"__symbolic":"method"}]}},"BefRepository":{"__symbolic":"class","arity":1,"extends":{"__symbolic":"reference","module":"@farris/devkit","name":"Repository","line":40,"character":55},"decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable","line":39,"character":1}}],"members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","module":"@angular/core","name":"Injector","line":60,"character":24}]}],"getEntities":[{"__symbolic":"method"}],"getList":[{"__symbolic":"method"}],"getById":[{"__symbolic":"method"}],"updateById":[{"__symbolic":"method"}],"create":[{"__symbolic":"method"}],"append":[{"__symbolic":"method"}],"appendByPath":[{"__symbolic":"method"}],"removeById":[{"__symbolic":"method"}],"removeByIds":[{"__symbolic":"method"}],"removeByPath":[{"__symbolic":"method"}],"updateChangesById":[{"__symbolic":"method"}],"updateChangesByPath":[{"__symbolic":"method"}],"updateAllChanges":[{"__symbolic":"method"}],"applyChanges":[{"__symbolic":"method"}],"applyChangesById":[{"__symbolic":"method"}],"cancelChanges":[{"__symbolic":"method"}],"appendEntityByPath":[{"__symbolic":"method"}],"removeEntityByPath":[{"__symbolic":"method"}],"clearAllEntityChanges":[{"__symbolic":"method"}],"getDataChangeDetails":[{"__symbolic":"method"}],"handleDataChangeDetails":[{"__symbolic":"method"}],"getVariableChangeDetails":[{"__symbolic":"method"}],"handleVariableChangeDetails":[{"__symbolic":"method"}]}},"FrameworkSessionService":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable","line":10,"character":1}}],"members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","module":"@ecp-caf/caf-common","name":"CacheService","line":13,"character":36}]}],"getUserSessionId":[{"__symbolic":"method"}]}}},"origins":{"ChangeDetailType":"./src/types","ChangeDetailInfo":"./src/types","ChangeDetail":"./src/types","RequestInfo":"./src/types","QueryResult":"./src/types","ResponseInfo":"./src/types","BE_SERVER_URI_TOKEN":"./src/tokens","BefChangeBuilder":"./src/bef_change_builder","BefChangeHandler":"./src/bef_change_handler","BefSessionService":"./src/bef_session.service","BefRestService":"./src/bef_rest_service","BefLookupRestService":"./src/bef_lookup.service","BefRepository":"./src/bef_repository","FrameworkSessionService":"./src/framework_session.service"},"importAs":"@farris/bef"}
{
"name": "@farris/bef",
"version": "0.0.11-201902121530",
"version": "0.0.11-201902252000",
"description": "Farris Bef",

@@ -5,0 +5,0 @@ "main": "./bundles/index.umd.js",

import { Injector } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { Entity, Repository } from '@farris/devkit';
import { ChangeDetail } from './types';
import { BefRestService } from './bef_rest_service';
import { BefChangeBuilder } from './bef_change_builder';
import { BefChangeHandler } from './bef_change_handler';
/**

@@ -15,6 +18,10 @@ * BEF实体仓储

/**
* 变更集构造
* 实体变更(前端)=> BE变更(后端)
*/
private changeBuilder;
changeBuilder: BefChangeBuilder;
/**
* BE变更(后端)=> 实体变更(前端)
*/
changeHandler: BefChangeHandler;
/**
* 构造函数

@@ -24,7 +31,2 @@ */

/**
* --------------------------------------------------------------------------------
* @todo: 新API
* --------------------------------------------------------------------------------
*/
/**
* 获取实体集合

@@ -34,7 +36,2 @@ */

/**
* --------------------------------------------------------------------------------
* @todo: 已过期,待删除
* --------------------------------------------------------------------------------
*/
/**
* 获取实体集合

@@ -53,19 +50,9 @@ */

/**
* 根据id给实体加锁
* @todo:通过一个空变更进行加锁,待确认
*/
lockById(id: string): Observable<boolean>;
/**
* 创建新实体,并加载
*/
create(): Observable<T>;
create(defaultValue?: any): Observable<T>;
/**
* 创建子实体,并加载
* @param path 路径
*/
createByPath(path: string): void;
/**
* 追加实体
*/
append(): Observable<T>;
append(defaultValue?: any): Observable<T>;
/**

@@ -77,9 +64,2 @@ * 创建子实体,并追加

/**
* 根据path获取实体集合
* @param fpath
* @todo:临时模拟,强识别2级路径
* fixed by justin: 循环识别path
*/
private appendEntityByPath;
/**
* 根据id删除实体

@@ -101,9 +81,2 @@ * @param id 内码

/**
* 根据path获取实体集合
* @param fpath
* @todo:临时模拟,强识别2级路径
* fixed by justin: 循环识别路径,支持多级
*/
private removeEntityByPath;
/**
* 将id对应的实体的变更提交的服务器端

@@ -132,3 +105,34 @@ */

cancelChanges(): Observable<boolean>;
/**
* 根据path获取实体集合
* @param fpath 路径
* @param childData 实体数据
*/
private appendEntityByPath;
/**
* 根据path获取实体集合
* @param fpath
*/
private removeEntityByPath;
/**
* 清空所有本地实体的变更集
*/
clearAllEntityChanges(): void;
/**
* 获取数据变更
*/
getDataChangeDetails(): ChangeDetail[];
/**
* 处理数据变更
*/
handleDataChangeDetails(changeDetails: ChangeDetail[]): void;
/**
* 获取变量变更
*/
getVariableChangeDetails(): ChangeDetail[];
/**
* 处理变量变更
*/
handleVariableChangeDetails(): void;
}
export { BefRepository };

@@ -7,3 +7,3 @@ import { HttpClient } from '@angular/common/http';

import { BefSessionService } from './bef_session.service';
import { ChangeDetail } from './types';
import { ChangeDetail, RequestInfo, ResponseInfo } from './types';
/**

@@ -35,20 +35,23 @@ * BEF取数服务

/**
* 列表查询
* @return 数据数组
* @todo
* 1、目前仅支持查询全部数据
* 查询
*/
query(entityFilter?: any): Observable<any>;
query(entityFilter?: any): Observable<ResponseInfo>;
/**
* 数据检索
* 查询
*/
extendQuery(entityFilter: any, requestInfo: RequestInfo): Observable<ResponseInfo>;
/**
* 检索数据
* @param id 单据内码
* @return 数据对象
*/
retrieve(id: string): Observable<any>;
retrieve(id: string): Observable<ResponseInfo>;
/**
* 检索数据(扩展)
*/
extendRetrieve(id: string, requestInfo: RequestInfo): Observable<ResponseInfo>;
/**
* 创建一条数据
* @summary
* 返回带默认值的空数据,服务器端该数据在BE缓存中,尚未保存到数据库
*/
create(): Observable<any>;
create(defaultValue?: any, requestInfo?: RequestInfo): Observable<ResponseInfo>;
/**

@@ -59,35 +62,38 @@ * 从表新增

*/
createByPath(fpath: string): Observable<any>;
createByPath(fpath: string, requestInfo?: RequestInfo): Observable<ResponseInfo>;
/**
* 提交变更
* @summary
* 此时变更提交的BE缓存中,等待保存,服务器端不返回任何数据
*/
update(changeDetail: ChangeDetail): Observable<any>;
update(changeDetail: ChangeDetail, requestInfo?: RequestInfo): Observable<ResponseInfo>;
/**
* 保存
* @summary
* 通过此地方将BEF中的变更缓存应用到数据库中,服务器端不返回任何数据
* 执行保存
*/
save(): Observable<any>;
save(requestInfo?: RequestInfo): Observable<ResponseInfo>;
/**
* 删除
*/
delete(id: string): Observable<any>;
delete(id: string): Observable<ResponseInfo>;
/**
* 删除(扩展)
*/
extendDelete(id: string, requestInfo: RequestInfo): Observable<ResponseInfo>;
/**
* 删除后代
* @param fpath 父路径(从表形如:/1/edus,从从表形如:/1/edus/11/grades)
*/
deletByPath(fpath: string, id: string): Observable<any>;
deletByPath(fpath: string, id: string): Observable<ResponseInfo>;
/**
* 删除后代(扩展)
* @param fpath 父路径(从表形如:/1/edus,从从表形如:/1/edus/11/grades)
*/
extendDeletByPath(fpath: string, id: string, requestInfo: RequestInfo): Observable<ResponseInfo>;
/**
* 批量删除
* @param ids 待删除的id数组
*/
batchDelete(ids: string[]): Observable<any>;
batchDelete(ids: string[]): Observable<ResponseInfo>;
/**
* 批量删除子表记录
* @param fpath 父路径
* @param ids 待删除的id数组
* 批量删除(扩展)
*/
batchDeleteByPath(fpath: string, ids: string[]): Observable<any>;
extendBatchDelete(ids: string[], requestInfo: RequestInfo): Observable<ResponseInfo>;
/**

@@ -98,6 +104,2 @@ * 取消

/**
* 发送http请求
*/
request(url: string, method: string, params?: any, options?: any): Observable<any>;
/**
* 构造HttpParams对象

@@ -112,8 +114,14 @@ * @param params 请求参数

*/
private addBody;
private addBodyToOptions;
/**
* 构造带RequestInfo的Body
* @body 未携带RequestInfo的body,格式形如: {key1: value1, key2: value2}
*/
buildBodyWithRequestInfo(body: any): any;
/**
* 构造RequestInfo
*/
buildRequestInfo(): RequestInfo;
/**
* 在devkit的路径中表名是属性名,是复数,在url中表名是单数
* 在此做兼容
* @todo:临时支持子表,应该支持无限层级
* fixed by justin: 每级属性名都去掉s
*/

@@ -120,0 +128,0 @@ private convertPathToUrl;

/**
* --------------------------------------------------------------------------------
* 变更集相关类型
* --------------------------------------------------------------------------------
*/
/**
* 变更类型

@@ -37,5 +42,33 @@ */

*/
export declare class ChangeDetail {
export interface ChangeDetail {
ChangeType: ChangeDetailType;
ChangeInfo: ChangeDetailInfo;
}
/**
* --------------------------------------------------------------------------------
* 请求、响应相关类型定义
* --------------------------------------------------------------------------------
*/
/**
* 请求类型
*/
export interface RequestInfo {
dataChange: ChangeDetail[];
variableChange?: ChangeDetail[];
}
/**
* 查询结果
*/
export interface QueryResult {
result: any[];
pagination: any;
}
/**
* 返回结果类型
*/
export interface ResponseInfo {
returnValue: any;
message: any[];
innerDataChange: any[];
innerVariableChange: any;
}

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc