actionResult
This commit is contained in:
parent
acb7423780
commit
59b13b9d2e
|
|
@ -1,5 +1,5 @@
|
|||
import { Context } from '../types/Context';
|
||||
import { DeduceCreateOperation, DeduceCreateSingleOperation, DeduceRemoveOperation, DeduceUpdateOperation, EntityDef, SelectionResult } from "../types/Entity";
|
||||
import { DeduceCreateOperation, DeduceCreateSingleOperation, DeduceRemoveOperation, DeduceUpdateOperation, EntityDef, OperateParams, SelectionResult } from "../types/Entity";
|
||||
import { RowStore } from '../types/RowStore';
|
||||
import { StorageSchema } from '../types/Storage';
|
||||
/**这个用来处理级联的select和update,对不同能力的 */
|
||||
|
|
@ -8,7 +8,7 @@ export declare abstract class CascadeStore<ED extends {
|
|||
}> extends RowStore<ED> {
|
||||
constructor(storageSchema: StorageSchema<ED>);
|
||||
protected abstract selectAbjointRow<T extends keyof ED>(entity: T, selection: Omit<ED[T]['Selection'], 'indexFrom' | 'count' | 'data' | 'sorter'>, context: Context<ED>, params?: Object): Promise<SelectionResult<ED, T>['result']>;
|
||||
protected abstract updateAbjointRow<T extends keyof ED>(entity: T, operation: DeduceCreateSingleOperation<ED[T]['Schema']> | DeduceUpdateOperation<ED[T]['Schema']> | DeduceRemoveOperation<ED[T]['Schema']>, context: Context<ED>, params?: Object): Promise<void>;
|
||||
protected abstract updateAbjointRow<T extends keyof ED>(entity: T, operation: DeduceCreateSingleOperation<ED[T]['Schema']> | DeduceUpdateOperation<ED[T]['Schema']> | DeduceRemoveOperation<ED[T]['Schema']>, context: Context<ED>, params?: OperateParams): Promise<void>;
|
||||
protected cascadeSelect<T extends keyof ED>(entity: T, selection: ED[T]['Selection'], context: Context<ED>, params?: Object): Promise<SelectionResult<ED, T>['result']>;
|
||||
/**
|
||||
* 级联更新
|
||||
|
|
@ -33,5 +33,5 @@ export declare abstract class CascadeStore<ED extends {
|
|||
* @param context
|
||||
* @param params
|
||||
*/
|
||||
protected cascadeUpdate<T extends keyof ED>(entity: T, operation: DeduceCreateOperation<ED[T]['Schema']> | DeduceUpdateOperation<ED[T]['Schema']> | DeduceRemoveOperation<ED[T]['Schema']>, context: Context<ED>, params?: Object): Promise<void>;
|
||||
protected cascadeUpdate<T extends keyof ED>(entity: T, operation: DeduceCreateOperation<ED[T]['Schema']> | DeduceUpdateOperation<ED[T]['Schema']> | DeduceRemoveOperation<ED[T]['Schema']>, context: Context<ED>, params?: OperateParams): Promise<void>;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ class CascadeStore extends RowStore_1.RowStore {
|
|||
const filter2 = data[attr];
|
||||
const rows2 = await this.cascadeSelect(entity2, (0, lodash_1.assign)({}, filter2, {
|
||||
filter: (0, filter_1.addFilterSegment)({
|
||||
[`${foreignKey}Id`]: row.id,
|
||||
[foreignKey]: row.id,
|
||||
}, filter2.filter),
|
||||
}), context, params);
|
||||
(0, lodash_1.assign)(row, {
|
||||
|
|
@ -308,12 +308,12 @@ class CascadeStore extends RowStore_1.RowStore {
|
|||
const { id } = data2;
|
||||
if (dataOtm instanceof Array) {
|
||||
dataOtm.forEach(ele => (0, lodash_1.assign)(ele, {
|
||||
[`${foreignKey}Id`]: id,
|
||||
[foreignKey]: id,
|
||||
}));
|
||||
}
|
||||
else {
|
||||
(0, lodash_1.assign)(dataOtm, {
|
||||
[`${foreignKey}Id`]: id,
|
||||
[foreignKey]: id,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -323,19 +323,19 @@ class CascadeStore extends RowStore_1.RowStore {
|
|||
(0, assert_1.default)(typeof id === 'string');
|
||||
if (dataOtm instanceof Array) {
|
||||
dataOtm.forEach(ele => (0, lodash_1.assign)(ele, {
|
||||
[`${foreignKey}Id`]: id,
|
||||
[foreignKey]: id,
|
||||
}));
|
||||
}
|
||||
else {
|
||||
(0, lodash_1.assign)(dataOtm, {
|
||||
[`${foreignKey}Id`]: id,
|
||||
[foreignKey]: id,
|
||||
});
|
||||
}
|
||||
}
|
||||
else {
|
||||
(0, lodash_1.assign)(operationOtm, {
|
||||
filter: (0, filter_1.addFilterSegment)({
|
||||
[`${foreignKey}Id`]: {
|
||||
[foreignKey]: {
|
||||
$in: {
|
||||
entity,
|
||||
data: {
|
||||
|
|
@ -348,7 +348,7 @@ class CascadeStore extends RowStore_1.RowStore {
|
|||
});
|
||||
if (action === 'remove' && actionOtm === 'update') {
|
||||
(0, lodash_1.assign)(dataOtm, {
|
||||
[`${foreignKey}Id`]: null,
|
||||
[foreignKey]: null,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|||
exports.judgeRelation = void 0;
|
||||
const assert_1 = __importDefault(require("assert"));
|
||||
const Demand_1 = require("../types/Demand");
|
||||
const Storage_1 = require("../types/Storage");
|
||||
/**
|
||||
* 判断对象和属性之间的关系
|
||||
* @param schema
|
||||
|
|
@ -22,9 +23,6 @@ function judgeRelation(schema, entity, attr) {
|
|||
}
|
||||
if (attributes.hasOwnProperty(attr)) {
|
||||
// 原生属性
|
||||
if (attributes[attr].type === 'ref') {
|
||||
return attributes[attr].ref; // 直接外键关联
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
if (attr.includes('$')) {
|
||||
|
|
@ -36,11 +34,11 @@ function judgeRelation(schema, entity, attr) {
|
|||
// 基于反指对象的反向关联
|
||||
return [entity2];
|
||||
}
|
||||
else if (attributes2.hasOwnProperty(foreignKey)
|
||||
&& attributes2[foreignKey].type === 'ref'
|
||||
&& attributes2[foreignKey].ref === entity) {
|
||||
else if (attributes2.hasOwnProperty(`${foreignKey}Id`)
|
||||
&& attributes2[`${foreignKey}Id`].type === 'ref'
|
||||
&& attributes2[`${foreignKey}Id`].ref === entity) {
|
||||
// 基于外键的反向关联
|
||||
return [entity2, foreignKey];
|
||||
return [entity2, `${foreignKey}Id`];
|
||||
}
|
||||
else {
|
||||
// 这种情况应该不会跑到
|
||||
|
|
@ -53,8 +51,13 @@ function judgeRelation(schema, entity, attr) {
|
|||
// 反向指针的外键
|
||||
return 2;
|
||||
}
|
||||
else if ((attributes.hasOwnProperty(`${attr}Id`))) {
|
||||
const { type, ref } = attributes[`${attr}Id`];
|
||||
(0, assert_1.default)(type === 'ref');
|
||||
return ref;
|
||||
}
|
||||
else {
|
||||
// 派生属性
|
||||
(0, assert_1.default)(Storage_1.initinctiveAttributes.includes(attr), `${attr}属性找不到`);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,9 @@ declare type SelectOption = {
|
|||
forUpdate?: true;
|
||||
usingIndex?: 'todo';
|
||||
};
|
||||
export declare type OperateParams = {
|
||||
notCollect?: boolean;
|
||||
};
|
||||
export declare type FormUpdateData<SH extends EntityShape> = {
|
||||
[A in keyof SH]?: any;
|
||||
} & {
|
||||
|
|
@ -84,12 +87,12 @@ declare type UpdateOpResult<ED extends EntityDict, T extends keyof ED> = {
|
|||
a: 'u';
|
||||
e: T;
|
||||
d: ED[T]['OpSchema'];
|
||||
f?: DeduceFilter<ED[T]>;
|
||||
f?: DeduceFilter<ED[T]['Schema']>;
|
||||
};
|
||||
declare type RemoveOpResult<ED extends EntityDict, T extends keyof ED> = {
|
||||
a: 'r';
|
||||
e: T;
|
||||
f?: DeduceFilter<ED[T]>;
|
||||
f?: DeduceFilter<ED[T]['Schema']>;
|
||||
};
|
||||
declare type SelectOpResult<ED extends EntityDict, T extends keyof ED> = {
|
||||
a: 's';
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { EntityDef, OperationResult, SelectionResult } from './Entity';
|
||||
import { EntityDef, OperationResult, SelectionResult, OperateParams } from './Entity';
|
||||
import { Context } from './Context';
|
||||
import { StorageSchema } from './Storage';
|
||||
import { OakErrorDefDict } from '../OakError';
|
||||
|
|
@ -8,7 +8,7 @@ export declare abstract class RowStore<ED extends {
|
|||
static $$LEVEL: string;
|
||||
static $$CODES: OakErrorDefDict;
|
||||
protected storageSchema: StorageSchema<ED>;
|
||||
abstract operate<T extends keyof ED>(entity: T, operation: ED[T]['Operation'], context: Context<ED>, params?: Object): Promise<OperationResult<ED>>;
|
||||
abstract operate<T extends keyof ED>(entity: T, operation: ED[T]['Operation'], context: Context<ED>, params?: OperateParams): Promise<OperationResult<ED>>;
|
||||
abstract select<T extends keyof ED>(entity: T, selection: ED[T]['Selection'], context: Context<ED>, params?: Object): Promise<SelectionResult<ED, T>>;
|
||||
abstract count<T extends keyof ED>(entity: T, selection: Omit<ED[T]['Selection'], 'data' | 'sorter' | 'action'>, context: Context<ED>, params?: Object): Promise<number>;
|
||||
constructor(storageSchema: StorageSchema<ED>);
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import { TriggerDataAttribute, TriggerTimestampAttribute } from './Trigger';
|
|||
export declare type Ref = 'ref';
|
||||
declare type PrimaryKeyAttribute = 'id';
|
||||
declare type InstinctiveAttributes = PrimaryKeyAttribute | '$$createAt$$' | '$$updateAt$$' | '$$removeAt$$' | TriggerDataAttribute | TriggerTimestampAttribute;
|
||||
export declare const initinctiveAttributes: string[];
|
||||
export interface Column<SH extends EntityShape> {
|
||||
name: keyof SH;
|
||||
size?: number;
|
||||
|
|
|
|||
|
|
@ -1,2 +1,4 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.initinctiveAttributes = void 0;
|
||||
exports.initinctiveAttributes = ['id', '$$createAt$$', '$$updateAt$$', '$$removeAt$$', '$$triggerData$$', '$$triggerTimestamp$$'];
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import assert from "assert";
|
||||
import { assign } from "lodash";
|
||||
import { Context } from '../types/Context';
|
||||
import { DeduceCreateOperation, DeduceCreateSingleOperation, DeduceFilter, DeduceRemoveOperation, DeduceSelection, DeduceUpdateOperation, EntityDef, EntityShape, SelectionResult } from "../types/Entity";
|
||||
import { DeduceCreateOperation, DeduceCreateSingleOperation, DeduceFilter, DeduceRemoveOperation, DeduceSelection, DeduceUpdateOperation, EntityDef, EntityShape, OperateParams, SelectionResult } from "../types/Entity";
|
||||
import { RowStore } from '../types/RowStore';
|
||||
import { StorageSchema } from '../types/Storage';
|
||||
import { addFilterSegment } from "./filter";
|
||||
|
|
@ -24,7 +24,7 @@ export abstract class CascadeStore<ED extends {
|
|||
entity: T,
|
||||
operation: DeduceCreateSingleOperation<ED[T]['Schema']> | DeduceUpdateOperation<ED[T]['Schema']> | DeduceRemoveOperation<ED[T]['Schema']>,
|
||||
context: Context<ED>,
|
||||
params?: Object): Promise<void>;
|
||||
params?: OperateParams): Promise<void>;
|
||||
|
||||
protected async cascadeSelect<T extends keyof ED>(
|
||||
entity: T,
|
||||
|
|
@ -115,7 +115,7 @@ export abstract class CascadeStore<ED extends {
|
|||
const filter2 = data[attr];
|
||||
const rows2 = await this.cascadeSelect(entity2, assign({}, filter2, {
|
||||
filter: addFilterSegment({
|
||||
[`${foreignKey}Id`]: row.id,
|
||||
[foreignKey]: row.id,
|
||||
} as any, filter2.filter),
|
||||
}), context, params);
|
||||
assign(row, {
|
||||
|
|
@ -166,7 +166,7 @@ export abstract class CascadeStore<ED extends {
|
|||
entity: T,
|
||||
operation: DeduceCreateOperation<ED[T]['Schema']> | DeduceUpdateOperation<ED[T]['Schema']> | DeduceRemoveOperation<ED[T]['Schema']>,
|
||||
context: Context<ED>,
|
||||
params?: Object): Promise<void> {
|
||||
params?: OperateParams): Promise<void> {
|
||||
const { action, data, filter } = operation;
|
||||
const opData = {};
|
||||
|
||||
|
|
@ -341,13 +341,13 @@ export abstract class CascadeStore<ED extends {
|
|||
if (dataOtm instanceof Array) {
|
||||
dataOtm.forEach(
|
||||
ele => assign(ele, {
|
||||
[`${foreignKey}Id`]: id,
|
||||
[foreignKey]: id,
|
||||
})
|
||||
);
|
||||
}
|
||||
else {
|
||||
assign(dataOtm, {
|
||||
[`${foreignKey}Id`]: id,
|
||||
[foreignKey]: id,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -358,20 +358,20 @@ export abstract class CascadeStore<ED extends {
|
|||
if (dataOtm instanceof Array) {
|
||||
dataOtm.forEach(
|
||||
ele => assign(ele, {
|
||||
[`${foreignKey}Id`]: id,
|
||||
[foreignKey]: id,
|
||||
})
|
||||
);
|
||||
}
|
||||
else {
|
||||
assign(dataOtm, {
|
||||
[`${foreignKey}Id`]: id,
|
||||
[foreignKey]: id,
|
||||
});
|
||||
}
|
||||
}
|
||||
else {
|
||||
assign(operationOtm, {
|
||||
filter: addFilterSegment({
|
||||
[`${foreignKey}Id`]: {
|
||||
[foreignKey]: {
|
||||
$in: {
|
||||
entity,
|
||||
data: {
|
||||
|
|
@ -384,7 +384,7 @@ export abstract class CascadeStore<ED extends {
|
|||
});
|
||||
if (action === 'remove' && actionOtm === 'update') {
|
||||
assign(dataOtm, {
|
||||
[`${foreignKey}Id`]: null,
|
||||
[foreignKey]: null,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import assert from "assert";
|
||||
import { EXPRESSION_PREFIX } from "../types/Demand";
|
||||
import { EntityDef } from "../types/Entity";
|
||||
import { StorageSchema } from "../types/Storage";
|
||||
import { initinctiveAttributes, StorageSchema } from "../types/Storage";
|
||||
|
||||
/**
|
||||
* 判断对象和属性之间的关系
|
||||
|
|
@ -23,9 +23,6 @@ export function judgeRelation<ED extends {
|
|||
|
||||
if (attributes.hasOwnProperty(attr)) {
|
||||
// 原生属性
|
||||
if (attributes[attr].type === 'ref') {
|
||||
return attributes[attr].ref!; // 直接外键关联
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
@ -39,11 +36,11 @@ export function judgeRelation<ED extends {
|
|||
// 基于反指对象的反向关联
|
||||
return [entity2];
|
||||
}
|
||||
else if (attributes2.hasOwnProperty(foreignKey)
|
||||
&& attributes2[foreignKey].type === 'ref'
|
||||
&& attributes2[foreignKey].ref === entity) {
|
||||
else if (attributes2.hasOwnProperty(`${foreignKey}Id`)
|
||||
&& attributes2[`${foreignKey}Id`].type === 'ref'
|
||||
&& attributes2[`${foreignKey}Id`].ref === entity) {
|
||||
// 基于外键的反向关联
|
||||
return [entity2, foreignKey];
|
||||
return [entity2, `${foreignKey}Id`];
|
||||
}
|
||||
else {
|
||||
// 这种情况应该不会跑到
|
||||
|
|
@ -56,8 +53,13 @@ export function judgeRelation<ED extends {
|
|||
// 反向指针的外键
|
||||
return 2;
|
||||
}
|
||||
else if ((attributes.hasOwnProperty(`${attr}Id`))){
|
||||
const { type, ref } = attributes[`${attr}Id`];
|
||||
assert (type === 'ref');
|
||||
return ref!;
|
||||
}
|
||||
else {
|
||||
// 派生属性
|
||||
assert(initinctiveAttributes.includes(attr), `${attr}属性找不到`);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
|
@ -13,6 +13,10 @@ type SelectOption = {
|
|||
usingIndex?: 'todo';
|
||||
};
|
||||
|
||||
export type OperateParams = {
|
||||
notCollect?: boolean;
|
||||
};
|
||||
|
||||
export type FormUpdateData<SH extends EntityShape> = {
|
||||
[A in keyof SH]?: any;
|
||||
} & { id?: undefined };
|
||||
|
|
@ -112,13 +116,13 @@ type UpdateOpResult<ED extends EntityDict, T extends keyof ED> = {
|
|||
a: 'u',
|
||||
e: T;
|
||||
d: ED[T]['OpSchema'];
|
||||
f?: DeduceFilter<ED[T]>;
|
||||
f?: DeduceFilter<ED[T]['Schema']>;
|
||||
};
|
||||
|
||||
type RemoveOpResult<ED extends EntityDict, T extends keyof ED> = {
|
||||
a: 'r',
|
||||
e: T;
|
||||
f?: DeduceFilter<ED[T]>;
|
||||
f?: DeduceFilter<ED[T]['Schema']>;
|
||||
};
|
||||
|
||||
type SelectOpResult<ED extends EntityDict, T extends keyof ED> = {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { EntityDef, OperationResult, SelectionResult, EntityShape } from './Entity';
|
||||
import { EntityDef, OperationResult, SelectionResult, EntityShape, OperateParams } from './Entity';
|
||||
import { Context } from './Context';
|
||||
import { StorageSchema } from './Storage';
|
||||
import { OakErrorDefDict } from '../OakError';
|
||||
|
|
@ -18,7 +18,7 @@ export abstract class RowStore<ED extends {
|
|||
entity: T,
|
||||
operation: ED[T]['Operation'],
|
||||
context: Context<ED>,
|
||||
params?: Object
|
||||
params?: OperateParams
|
||||
): Promise<OperationResult<ED>>;
|
||||
|
||||
abstract select<T extends keyof ED> (
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ export type Ref = 'ref';
|
|||
|
||||
type PrimaryKeyAttribute = 'id';
|
||||
type InstinctiveAttributes = PrimaryKeyAttribute | '$$createAt$$' | '$$updateAt$$' | '$$removeAt$$' | TriggerDataAttribute | TriggerTimestampAttribute;
|
||||
export const initinctiveAttributes = ['id', '$$createAt$$', '$$updateAt$$', '$$removeAt$$', '$$triggerData$$', '$$triggerTimestamp$$'];
|
||||
|
||||
export interface Column<SH extends EntityShape> {
|
||||
name: keyof SH,
|
||||
|
|
|
|||
Loading…
Reference in New Issue