translateCascadeRelationFilterMaker中的小笔误
This commit is contained in:
parent
ef8a6428af
commit
912e68047a
|
|
@ -359,7 +359,7 @@ function translateCascadeRelationFilterMaker(schema, lch, entity2, pathPrefix) {
|
||||||
var getForeignKeyId_1 = function (d) {
|
var getForeignKeyId_1 = function (d) {
|
||||||
if (relation === 2) {
|
if (relation === 2) {
|
||||||
if (d.entity === attr && typeof d.entityId === 'string') {
|
if (d.entity === attr && typeof d.entityId === 'string') {
|
||||||
return d.entitId;
|
return d.entityId;
|
||||||
}
|
}
|
||||||
throw new Exception_1.OakUserUnpermittedException();
|
throw new Exception_1.OakUserUnpermittedException();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -841,7 +841,7 @@ export abstract class CascadeStore<ED extends EntityDict & BaseEntityDict> exten
|
||||||
data: opData,
|
data: opData,
|
||||||
beforeFns,
|
beforeFns,
|
||||||
afterFns,
|
afterFns,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// 对插入的数据,没有初始值的属性置null
|
// 对插入的数据,没有初始值的属性置null
|
||||||
|
|
@ -870,7 +870,7 @@ export abstract class CascadeStore<ED extends EntityDict & BaseEntityDict> exten
|
||||||
else {
|
else {
|
||||||
processSingle(data as ED[T]['CreateSingle']['data']);
|
processSingle(data as ED[T]['CreateSingle']['data']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 对更新的数据,去掉所有的undefined属性
|
// 对更新的数据,去掉所有的undefined属性
|
||||||
protected preProcessDataUpdated(data: Record<string, any>) {
|
protected preProcessDataUpdated(data: Record<string, any>) {
|
||||||
|
|
@ -880,12 +880,12 @@ export abstract class CascadeStore<ED extends EntityDict & BaseEntityDict> exten
|
||||||
undefinedKeys.forEach(
|
undefinedKeys.forEach(
|
||||||
ele => unset(data, ele)
|
ele => unset(data, ele)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
judgeRelation(entity: keyof ED, attr: string) {
|
judgeRelation(entity: keyof ED, attr: string) {
|
||||||
return judgeRelation(this.storageSchema, entity, attr);
|
return judgeRelation(this.storageSchema, entity, attr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 和具体的update过程无关的例程放在这里,包括对later动作的处理、对oper的记录以及对record的收集等
|
* 和具体的update过程无关的例程放在这里,包括对later动作的处理、对oper的记录以及对record的收集等
|
||||||
|
|
@ -898,7 +898,7 @@ judgeRelation(entity: keyof ED, attr: string) {
|
||||||
operation: ED[T]['CreateSingle'] | ED[T]['Update'] | ED[T]['Remove'],
|
operation: ED[T]['CreateSingle'] | ED[T]['Update'] | ED[T]['Remove'],
|
||||||
context: Cxt,
|
context: Cxt,
|
||||||
option: OP
|
option: OP
|
||||||
) {
|
) {
|
||||||
const { data, action, id: operId, filter } = operation;
|
const { data, action, id: operId, filter } = operation;
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
|
|
||||||
|
|
@ -1268,13 +1268,13 @@ judgeRelation(entity: keyof ED, attr: string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private doUpdateSingleRow<T extends keyof ED, OP extends OperateOption, Cxt extends SyncContext<ED>>(entity: T,
|
private doUpdateSingleRow<T extends keyof ED, OP extends OperateOption, Cxt extends SyncContext<ED>>(entity: T,
|
||||||
operation: ED[T]['Operation'],
|
operation: ED[T]['Operation'],
|
||||||
context: Cxt,
|
context: Cxt,
|
||||||
option: OP
|
option: OP
|
||||||
) {
|
) {
|
||||||
const { data, action, id: operId, filter } = operation;
|
const { data, action, id: operId, filter } = operation;
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
|
|
||||||
|
|
@ -1337,21 +1337,21 @@ judgeRelation(entity: keyof ED, attr: string) {
|
||||||
return this.updateAbjointRow(entity, operation, context, option);
|
return this.updateAbjointRow(entity, operation, context, option);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected cascadeUpdate<T extends keyof ED, Cxt extends SyncContext<ED>, OP extends OperateOption>(
|
protected cascadeUpdate<T extends keyof ED, Cxt extends SyncContext<ED>, OP extends OperateOption>(
|
||||||
entity: T,
|
entity: T,
|
||||||
operation: ED[T]['Operation'],
|
operation: ED[T]['Operation'],
|
||||||
context: Cxt,
|
context: Cxt,
|
||||||
option: OP): OperationResult < ED > {
|
option: OP): OperationResult<ED> {
|
||||||
reinforceOperation(this.getSchema(), entity, operation);
|
reinforceOperation(this.getSchema(), entity, operation);
|
||||||
const { action, data, filter, id } = operation;
|
const { action, data, filter, id } = operation;
|
||||||
let opData: any;
|
let opData: any;
|
||||||
const wholeBeforeFns: Array<() => any> =[];
|
const wholeBeforeFns: Array<() => any> = [];
|
||||||
const wholeAfterFns: Array<() => any> = [];
|
const wholeAfterFns: Array<() => any> = [];
|
||||||
const result: OperationResult<ED> = {};
|
const result: OperationResult<ED> = {};
|
||||||
|
|
||||||
if (['create', 'create-l'].includes(action) && data instanceof Array) {
|
if (['create', 'create-l'].includes(action) && data instanceof Array) {
|
||||||
opData = [];
|
opData = [];
|
||||||
for (const d of data) {
|
for (const d of data) {
|
||||||
const { data: od, beforeFns, afterFns } = this.destructCascadeUpdate(
|
const { data: od, beforeFns, afterFns } = this.destructCascadeUpdate(
|
||||||
|
|
@ -1366,8 +1366,8 @@ if (['create', 'create-l'].includes(action) && data instanceof Array) {
|
||||||
wholeBeforeFns.push(...beforeFns);
|
wholeBeforeFns.push(...beforeFns);
|
||||||
wholeAfterFns.push(...afterFns);
|
wholeAfterFns.push(...afterFns);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const { data: od, beforeFns, afterFns } = this.destructCascadeUpdate(
|
const { data: od, beforeFns, afterFns } = this.destructCascadeUpdate(
|
||||||
entity,
|
entity,
|
||||||
action,
|
action,
|
||||||
|
|
@ -1380,21 +1380,21 @@ else {
|
||||||
opData = od;
|
opData = od;
|
||||||
wholeBeforeFns.push(...beforeFns);
|
wholeBeforeFns.push(...beforeFns);
|
||||||
wholeAfterFns.push(...afterFns);
|
wholeAfterFns.push(...afterFns);
|
||||||
}
|
}
|
||||||
|
|
||||||
const operation2: ED[T]['CreateSingle'] | ED[T]['Update'] | ED[T]['Remove'] =
|
const operation2: ED[T]['CreateSingle'] | ED[T]['Update'] | ED[T]['Remove'] =
|
||||||
Object.assign({}, operation as ED[T]['CreateSingle'] | ED[T]['Update'] | ED[T]['Remove'], {
|
Object.assign({}, operation as ED[T]['CreateSingle'] | ED[T]['Update'] | ED[T]['Remove'], {
|
||||||
data: opData as ED[T]['OpSchema'],
|
data: opData as ED[T]['OpSchema'],
|
||||||
});
|
});
|
||||||
|
|
||||||
for (const before of wholeBeforeFns) {
|
for (const before of wholeBeforeFns) {
|
||||||
before();
|
before();
|
||||||
}
|
}
|
||||||
const count = this.doUpdateSingleRow(entity, operation2, context, option);
|
const count = this.doUpdateSingleRow(entity, operation2, context, option);
|
||||||
for (const after of wholeAfterFns) {
|
for (const after of wholeAfterFns) {
|
||||||
after();
|
after();
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -1408,15 +1408,15 @@ return result;
|
||||||
entity: T,
|
entity: T,
|
||||||
operation: ED[T]['Operation'],
|
operation: ED[T]['Operation'],
|
||||||
context: Cxt,
|
context: Cxt,
|
||||||
option: OP): Promise < OperationResult < ED >> {
|
option: OP): Promise<OperationResult<ED>> {
|
||||||
reinforceOperation(this.getSchema(), entity, operation);
|
reinforceOperation(this.getSchema(), entity, operation);
|
||||||
const { action, data, filter, id } = operation;
|
const { action, data, filter, id } = operation;
|
||||||
let opData: any;
|
let opData: any;
|
||||||
const wholeBeforeFns: Array<() => Promise<any>> =[];
|
const wholeBeforeFns: Array<() => Promise<any>> = [];
|
||||||
const wholeAfterFns: Array<() => Promise<any>> = [];
|
const wholeAfterFns: Array<() => Promise<any>> = [];
|
||||||
const result: OperationResult<ED> = {};
|
const result: OperationResult<ED> = {};
|
||||||
|
|
||||||
if (['create', 'create-l'].includes(action) && data instanceof Array) {
|
if (['create', 'create-l'].includes(action) && data instanceof Array) {
|
||||||
opData = [];
|
opData = [];
|
||||||
for (const d of data) {
|
for (const d of data) {
|
||||||
const { data: od, beforeFns, afterFns } = this.destructCascadeUpdate(
|
const { data: od, beforeFns, afterFns } = this.destructCascadeUpdate(
|
||||||
|
|
@ -1431,8 +1431,8 @@ if (['create', 'create-l'].includes(action) && data instanceof Array) {
|
||||||
wholeBeforeFns.push(...beforeFns);
|
wholeBeforeFns.push(...beforeFns);
|
||||||
wholeAfterFns.push(...afterFns);
|
wholeAfterFns.push(...afterFns);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const { data: od, beforeFns, afterFns } = this.destructCascadeUpdate(
|
const { data: od, beforeFns, afterFns } = this.destructCascadeUpdate(
|
||||||
entity,
|
entity,
|
||||||
action,
|
action,
|
||||||
|
|
@ -1445,33 +1445,33 @@ else {
|
||||||
opData = od;
|
opData = od;
|
||||||
wholeBeforeFns.push(...beforeFns);
|
wholeBeforeFns.push(...beforeFns);
|
||||||
wholeAfterFns.push(...afterFns);
|
wholeAfterFns.push(...afterFns);
|
||||||
}
|
}
|
||||||
|
|
||||||
const operation2: ED[T]['CreateSingle'] | ED[T]['Update'] | ED[T]['Remove'] =
|
const operation2: ED[T]['CreateSingle'] | ED[T]['Update'] | ED[T]['Remove'] =
|
||||||
Object.assign({}, operation as ED[T]['CreateSingle'] | ED[T]['Update'] | ED[T]['Remove'], {
|
Object.assign({}, operation as ED[T]['CreateSingle'] | ED[T]['Update'] | ED[T]['Remove'], {
|
||||||
data: opData as ED[T]['OpSchema'],
|
data: opData as ED[T]['OpSchema'],
|
||||||
});
|
});
|
||||||
|
|
||||||
for (const before of wholeBeforeFns) {
|
for (const before of wholeBeforeFns) {
|
||||||
await before();
|
await before();
|
||||||
}
|
}
|
||||||
const count = await this.doUpdateSingleRowAsync(entity, operation2, context, option);
|
const count = await this.doUpdateSingleRowAsync(entity, operation2, context, option);
|
||||||
this.mergeOperationResult(result, {
|
this.mergeOperationResult(result, {
|
||||||
[entity]: {
|
[entity]: {
|
||||||
[operation2.action]: count,
|
[operation2.action]: count,
|
||||||
}
|
}
|
||||||
} as OperationResult<ED>);
|
} as OperationResult<ED>);
|
||||||
for (const after of wholeAfterFns) {
|
for (const after of wholeAfterFns) {
|
||||||
await after();
|
await after();
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected cascadeSelect<T extends keyof ED, OP extends SelectOption, Cxt extends SyncContext<ED>>(
|
protected cascadeSelect<T extends keyof ED, OP extends SelectOption, Cxt extends SyncContext<ED>>(
|
||||||
entity: T,
|
entity: T,
|
||||||
selection: ED[T]['Selection'],
|
selection: ED[T]['Selection'],
|
||||||
context: Cxt,
|
context: Cxt,
|
||||||
option: OP): Partial < ED[T]['Schema'] > [] {
|
option: OP): Partial<ED[T]['Schema']>[] {
|
||||||
reinforceSelection(this.getSchema(), entity, selection);
|
reinforceSelection(this.getSchema(), entity, selection);
|
||||||
const { data, filter, indexFrom, count, sorter } = selection;
|
const { data, filter, indexFrom, count, sorter } = selection;
|
||||||
const { projection, cascadeSelectionFns } = this.destructCascadeSelect(
|
const { projection, cascadeSelectionFns } = this.destructCascadeSelect(
|
||||||
|
|
@ -1519,7 +1519,7 @@ return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
return rows;
|
return rows;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将一次查询的结果集加入result
|
* 将一次查询的结果集加入result
|
||||||
|
|
@ -1528,7 +1528,7 @@ return result;
|
||||||
* @param rows
|
* @param rows
|
||||||
* @param context
|
* @param context
|
||||||
*/
|
*/
|
||||||
private addToResultSelections<T extends keyof ED, Cxt extends AsyncContext<ED>>(entity: T, rows: Partial < ED[T]['Schema'] > [], context: Cxt) {
|
private addToResultSelections<T extends keyof ED, Cxt extends AsyncContext<ED>>(entity: T, rows: Partial<ED[T]['Schema']>[], context: Cxt) {
|
||||||
if (this.supportManyToOneJoin()) {
|
if (this.supportManyToOneJoin()) {
|
||||||
const attrsToPick: string[] = [];
|
const attrsToPick: string[] = [];
|
||||||
for (const attr in rows[0]) {
|
for (const attr in rows[0]) {
|
||||||
|
|
@ -1555,9 +1555,9 @@ return result;
|
||||||
else {
|
else {
|
||||||
this.addSingleRowToResultSelections(entity, rows, context);
|
this.addSingleRowToResultSelections(entity, rows, context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private addSingleRowToResultSelections<T extends keyof ED, Cxt extends AsyncContext<ED>>(entity: T, rows: Partial < ED[T]['OpSchema'] > [], context: Cxt) {
|
private addSingleRowToResultSelections<T extends keyof ED, Cxt extends AsyncContext<ED>>(entity: T, rows: Partial<ED[T]['OpSchema']>[], context: Cxt) {
|
||||||
const { opRecords } = context;
|
const { opRecords } = context;
|
||||||
|
|
||||||
let lastOperation = opRecords[opRecords.length - 1];
|
let lastOperation = opRecords[opRecords.length - 1];
|
||||||
|
|
@ -1605,13 +1605,13 @@ return result;
|
||||||
Object.assign(lastOperation.d, {
|
Object.assign(lastOperation.d, {
|
||||||
[entity]: entityBranch,
|
[entity]: entityBranch,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async cascadeSelectAsync<T extends keyof ED, OP extends SelectOption, Cxt extends AsyncContext<ED>>(
|
protected async cascadeSelectAsync<T extends keyof ED, OP extends SelectOption, Cxt extends AsyncContext<ED>>(
|
||||||
entity: T,
|
entity: T,
|
||||||
selection: ED[T]['Selection'],
|
selection: ED[T]['Selection'],
|
||||||
context: Cxt,
|
context: Cxt,
|
||||||
option: OP): Promise < Partial < ED[T]['Schema'] > [] > {
|
option: OP): Promise<Partial<ED[T]['Schema']>[]> {
|
||||||
reinforceSelection(this.getSchema(), entity, selection);
|
reinforceSelection(this.getSchema(), entity, selection);
|
||||||
const { data, filter, indexFrom, count, sorter } = selection;
|
const { data, filter, indexFrom, count, sorter } = selection;
|
||||||
const { projection, cascadeSelectionFns } = this.destructCascadeSelect(
|
const { projection, cascadeSelectionFns } = this.destructCascadeSelect(
|
||||||
|
|
@ -1631,11 +1631,11 @@ return result;
|
||||||
}, context, option);
|
}, context, option);
|
||||||
|
|
||||||
|
|
||||||
if(!option.dontCollect) {
|
if (!option.dontCollect) {
|
||||||
this.addToResultSelections(entity, rows, context);
|
this.addToResultSelections(entity, rows, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cascadeSelectionFns.length > 0) {
|
if (cascadeSelectionFns.length > 0) {
|
||||||
const ruException: Array<{
|
const ruException: Array<{
|
||||||
entity: keyof ED,
|
entity: keyof ED,
|
||||||
selection: ED[keyof ED]['Selection']
|
selection: ED[keyof ED]['Selection']
|
||||||
|
|
@ -1662,8 +1662,8 @@ if (cascadeSelectionFns.length > 0) {
|
||||||
if (ruException.length > 0) {
|
if (ruException.length > 0) {
|
||||||
throw new OakRowUnexistedException(ruException);
|
throw new OakRowUnexistedException(ruException);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return rows;
|
return rows;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -335,7 +335,7 @@ function translateCascadeRelationFilterMaker<ED extends EntityDict & BaseEntityD
|
||||||
const getForeignKeyId = (d: ED[keyof ED]['CreateSingle']['data']) => {
|
const getForeignKeyId = (d: ED[keyof ED]['CreateSingle']['data']) => {
|
||||||
if (relation === 2) {
|
if (relation === 2) {
|
||||||
if (d.entity === attr && typeof d.entityId === 'string') {
|
if (d.entity === attr && typeof d.entityId === 'string') {
|
||||||
return d.entitId as string;
|
return d.entityId as string;
|
||||||
}
|
}
|
||||||
throw new OakUserUnpermittedException();
|
throw new OakUserUnpermittedException();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue