注释掉了operateOption当中的dontCreateOper和dontCreateModi

This commit is contained in:
Xu Chang 2024-02-05 15:51:48 +08:00
parent e26e6706b5
commit c2d76f5129
14 changed files with 64 additions and 78 deletions

View File

@ -4,6 +4,7 @@ export type UserAction = 'mergeTo' | string;
export type UserState = 'normal' | 'merged' | string; export type UserState = 'normal' | 'merged' | string;
export type ParticularAction = UserAction; export type ParticularAction = UserAction;
export declare const actions: string[]; export declare const actions: string[];
export declare const UserActionDef: ActionDef<UserAction, UserState>;
export type Action = GenericAction | ParticularAction | RelationAction | string; export type Action = GenericAction | ParticularAction | RelationAction | string;
export declare const ActionDefDict: { export declare const ActionDefDict: {
userState: ActionDef<string, string>; userState: ActionDef<string, string>;

View File

@ -1,12 +1,12 @@
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
exports.ActionDefDict = exports.actions = void 0; exports.ActionDefDict = exports.UserActionDef = exports.actions = void 0;
exports.actions = ["count", "stat", "download", "select", "aggregate", "create", "remove", "update", "grant", "revoke", "mergeTo"]; exports.actions = ["count", "stat", "download", "select", "aggregate", "create", "remove", "update", "grant", "revoke", "mergeTo"];
const UserActionDef = { exports.UserActionDef = {
stm: { stm: {
mergeTo: ['normal', 'merged'], mergeTo: ['normal', 'merged'],
}, },
}; };
exports.ActionDefDict = { exports.ActionDefDict = {
userState: UserActionDef userState: exports.UserActionDef
}; };

View File

@ -568,7 +568,7 @@ function searchImportedPath(path, fileSpecifierPath, filename) {
return path_1.default.join(pkgJsonPath, '..', dependentFilePath, ...(fileSpecifierPaths[0] ? fileSpecifierPaths.slice(1) : (fileSpecifierPaths.slice(2)))); return path_1.default.join(pkgJsonPath, '..', dependentFilePath, ...(fileSpecifierPaths[0] ? fileSpecifierPaths.slice(1) : (fileSpecifierPaths.slice(2))));
} }
else { else {
return path_1.default.join(pkgJsonPath, 'node_modules', fileSpecifierPath); return path_1.default.join(pkgJsonPath, '..', 'node_modules', fileSpecifierPath);
} }
} }
} }

View File

@ -1,8 +1,18 @@
import { String, Text } from '../types/DataType'; import { String, Text } from '../types/DataType';
import { EntityShape } from '../types/Entity'; import { EntityShape } from '../types/Entity';
import { ActionDef } from '../types/Action';
import { EntityDesc } from '../types/EntityDesc';
export interface Schema extends EntityShape { export interface Schema extends EntityShape {
name?: String<16>; name?: String<16>;
nickname?: String<64>; nickname?: String<64>;
password?: Text; password?: Text;
ref?: Schema; ref?: Schema;
} }
type UserAction = 'mergeTo';
type UserState = 'normal' | 'merged';
export type Action = UserAction;
export declare const UserActionDef: ActionDef<UserAction, UserState>;
export declare const entityDesc: EntityDesc<Schema, Action, '', {
userState: UserState;
}>;
export {};

View File

@ -1,12 +1,13 @@
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
exports.entityDesc = exports.UserActionDef = void 0;
; ;
const UserActionDef = { exports.UserActionDef = {
stm: { stm: {
mergeTo: ['normal', 'merged'], mergeTo: ['normal', 'merged'],
}, },
}; };
const entityDesc = { exports.entityDesc = {
locales: { locales: {
zh_CN: { zh_CN: {
name: '用户', name: '用户',

View File

@ -680,7 +680,7 @@ class CascadeStore extends RowStore_1.RowStore {
const opData = {}; const opData = {};
const beforeFns = []; const beforeFns = [];
const afterFns = []; const afterFns = [];
if (modiAttr && action !== 'remove' && !option.dontCreateModi) { if (modiAttr && action !== 'remove') {
// create/update具有modi对象的对象对其子对象的update行为全部是create modi对象缓存动作 // create/update具有modi对象的对象对其子对象的update行为全部是create modi对象缓存动作
// delete此对象所有的modi子对象应该通过触发器作废这个目前先通过系统的trigger来实现 // delete此对象所有的modi子对象应该通过触发器作废这个目前先通过系统的trigger来实现
(0, assert_1.default)(!option2.modiParentId && !option2.modiParentEntity); (0, assert_1.default)(!option2.modiParentId && !option2.modiParentEntity);
@ -1146,13 +1146,8 @@ class CascadeStore extends RowStore_1.RowStore {
} }
if (!option.dontCollect) { if (!option.dontCollect) {
context.saveOpRecord(entity, operation); context.saveOpRecord(entity, operation);
/* context.opRecords.push({
a: 'c',
e: entity,
d: data as ED[T]['OpSchema'] | ED[T]['OpSchema'][],
}); */
} }
if (!option.dontCreateOper && !['oper', 'operEntity', 'modiEntity', 'modi'].includes(entity)) { if (!['oper', 'operEntity', 'modiEntity', 'modi'].includes(entity)) {
// 按照框架要求生成Oper和OperEntity这两个内置的对象 // 按照框架要求生成Oper和OperEntity这两个内置的对象
(0, assert_1.default)(operId); (0, assert_1.default)(operId);
const operatorId = context.getCurrentUserId(true); const operatorId = context.getCurrentUserId(true);
@ -1188,7 +1183,6 @@ class CascadeStore extends RowStore_1.RowStore {
const closeRootMode = context.openRootMode(); const closeRootMode = context.openRootMode();
await this.cascadeUpdateAsync('oper', createOper, context, { await this.cascadeUpdateAsync('oper', createOper, context, {
dontCollect: true, dontCollect: true,
dontCreateOper: true,
}); });
closeRootMode(); closeRootMode();
} }
@ -1308,7 +1302,7 @@ class CascadeStore extends RowStore_1.RowStore {
} }
else { else {
const createOper = async () => { const createOper = async () => {
if (!option?.dontCreateOper && !['oper', 'operEntity', 'modiEntity', 'modi'].includes(entity) && ids.length > 0) { if (!['oper', 'operEntity', 'modiEntity', 'modi'].includes(entity) && ids.length > 0) {
// 按照框架要求生成Oper和OperEntity这两个内置的对象 // 按照框架要求生成Oper和OperEntity这两个内置的对象
(0, assert_1.default)(operId); (0, assert_1.default)(operId);
const createOper = { const createOper = {
@ -1333,7 +1327,6 @@ class CascadeStore extends RowStore_1.RowStore {
const closeRootMode = context.openRootMode(); const closeRootMode = context.openRootMode();
await this.cascadeUpdateAsync('oper', createOper, context, { await this.cascadeUpdateAsync('oper', createOper, context, {
dontCollect: true, dontCollect: true,
dontCreateOper: true,
}); });
closeRootMode(); closeRootMode();
} }
@ -1350,15 +1343,6 @@ class CascadeStore extends RowStore_1.RowStore {
} }
} }
}); });
/* context.opRecords.push({
a: 'r',
e: entity,
f: {
id: {
$in: ids,
}
},
}); */
} }
} }
else { else {
@ -1379,16 +1363,6 @@ class CascadeStore extends RowStore_1.RowStore {
} }
}, },
}); });
/* context.opRecords.push({
a: 'u',
e: entity,
d: data as ED[T]['Update']['data'],
f: {
id: {
$in: ids,
}
},
}); */
} }
} }
else if (action !== 'update') { else if (action !== 'update') {

View File

@ -34,8 +34,6 @@ export type SelectOption = {
export type OperateOption = { export type OperateOption = {
blockTrigger?: true; blockTrigger?: true;
dontCollect?: boolean; dontCollect?: boolean;
dontCreateOper?: boolean;
dontCreateModi?: boolean;
includedDeleted?: true; includedDeleted?: true;
allowExists?: boolean; allowExists?: boolean;
modiParentId?: string; modiParentId?: string;
@ -146,20 +144,20 @@ type RemoveOperationData = {
export type RemoveOperation = Operation<'remove', RemoveOperationData, Filter, Sorter>; export type RemoveOperation = Operation<'remove', RemoveOperationData, Filter, Sorter>;
export type CUDOperation = CreateOperation | UpdateOperation | RemoveOperation; export type CUDOperation = CreateOperation | UpdateOperation | RemoveOperation;
export type CreateOpResult<ED extends EntityDict, T extends keyof ED> = { export type CreateOpResult<ED extends EntityDict, T extends keyof ED> = {
id?: string; id: string;
a: 'c'; a: 'c';
e: T; e: T;
d: ED[T]['OpSchema'] | ED[T]['OpSchema'][]; d: ED[T]['OpSchema'] | ED[T]['OpSchema'][];
}; };
export type UpdateOpResult<ED extends EntityDict, T extends keyof ED> = { export type UpdateOpResult<ED extends EntityDict, T extends keyof ED> = {
id?: string; id: string;
a: 'u'; a: 'u';
e: T; e: T;
d: UpdateOperationData; d: UpdateOperationData;
f?: Filter; f?: Filter;
}; };
export type RemoveOpResult<ED extends EntityDict, T extends keyof ED> = { export type RemoveOpResult<ED extends EntityDict, T extends keyof ED> = {
id?: string; id: string;
a: 'r'; a: 'r';
e: T; e: T;
f?: Filter; f?: Filter;

7
lib/utils/relationPath.d.ts vendored Normal file
View File

@ -0,0 +1,7 @@
import { StorageSchema } from "..";
import { EntityDict as BaseEntityDict } from "../base-app-domain";
import { EntityDict } from "../types/Entity";
export declare function destructRelationPath<ED extends EntityDict & BaseEntityDict, T extends keyof ED>(schema: StorageSchema<ED>, entity: T, path: string, relationFilter?: ED['userRelation']['Selection']['filter'], recursive?: boolean): {
projection: ED[T]['Selection']['data'];
getData: (d: Partial<ED[T]['Schema']>) => ED['userRelation']['Schema'][];
};

View File

@ -0,0 +1,7 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.destructRelationPath = void 0;
function destructRelationPath(schema, entity, path, relationFilter, recursive) {
throw new Error('method not implemented');
}
exports.destructRelationPath = destructRelationPath;

View File

@ -787,7 +787,7 @@ function searchImportedPath(path: string, fileSpecifierPath: string, filename: s
return PathLib.join(pkgJsonPath, '..', dependentFilePath, ...(fileSpecifierPaths[0] ? fileSpecifierPaths.slice(1) : (fileSpecifierPaths.slice(2)))); return PathLib.join(pkgJsonPath, '..', dependentFilePath, ...(fileSpecifierPaths[0] ? fileSpecifierPaths.slice(1) : (fileSpecifierPaths.slice(2))));
} }
else { else {
return PathLib.join(pkgJsonPath, 'node_modules', fileSpecifierPath); return PathLib.join(pkgJsonPath, '..', 'node_modules', fileSpecifierPath);
} }
} }
} }

View File

@ -13,16 +13,16 @@ export interface Schema extends EntityShape {
type UserAction = 'mergeTo'; type UserAction = 'mergeTo';
type UserState = 'normal' | 'merged'; type UserState = 'normal' | 'merged';
type Action = UserAction; export type Action = UserAction;
const UserActionDef: ActionDef<UserAction, UserState> = { export const UserActionDef: ActionDef<UserAction, UserState> = {
stm: { stm: {
mergeTo: ['normal', 'merged'], mergeTo: ['normal', 'merged'],
}, },
}; };
const entityDesc: EntityDesc<Schema, Action, '', { export const entityDesc: EntityDesc<Schema, Action, '', {
userState: UserState, userState: UserState,
}> = { }> = {
locales: { locales: {

View File

@ -904,7 +904,7 @@ export abstract class CascadeStore<ED extends EntityDict & BaseEntityDict> exten
const opData: Record<string, any> = {}; const opData: Record<string, any> = {};
const beforeFns: Array<() => R> = []; const beforeFns: Array<() => R> = [];
const afterFns: Array<() => R> = []; const afterFns: Array<() => R> = [];
if (modiAttr && action !== 'remove' && !option.dontCreateModi) { if (modiAttr && action !== 'remove') {
// create/update具有modi对象的对象对其子对象的update行为全部是create modi对象缓存动作 // create/update具有modi对象的对象对其子对象的update行为全部是create modi对象缓存动作
// delete此对象所有的modi子对象应该通过触发器作废这个目前先通过系统的trigger来实现 // delete此对象所有的modi子对象应该通过触发器作废这个目前先通过系统的trigger来实现
assert(!option2.modiParentId && !option2.modiParentEntity); assert(!option2.modiParentId && !option2.modiParentEntity);
@ -1414,13 +1414,8 @@ export abstract class CascadeStore<ED extends EntityDict & BaseEntityDict> exten
if (!option.dontCollect) { if (!option.dontCollect) {
context.saveOpRecord(entity, operation); context.saveOpRecord(entity, operation);
/* context.opRecords.push({
a: 'c',
e: entity,
d: data as ED[T]['OpSchema'] | ED[T]['OpSchema'][],
}); */
} }
if (!option.dontCreateOper && !['oper', 'operEntity', 'modiEntity', 'modi'].includes(entity as string)) { if (!['oper', 'operEntity', 'modiEntity', 'modi'].includes(entity as string)) {
// 按照框架要求生成Oper和OperEntity这两个内置的对象 // 按照框架要求生成Oper和OperEntity这两个内置的对象
assert(operId); assert(operId);
const operatorId = context.getCurrentUserId(true); const operatorId = context.getCurrentUserId(true);
@ -1460,7 +1455,6 @@ export abstract class CascadeStore<ED extends EntityDict & BaseEntityDict> exten
const closeRootMode = context.openRootMode(); const closeRootMode = context.openRootMode();
await this.cascadeUpdateAsync('oper', createOper, context, { await this.cascadeUpdateAsync('oper', createOper, context, {
dontCollect: true, dontCollect: true,
dontCreateOper: true,
}); });
closeRootMode(); closeRootMode();
} }
@ -1585,7 +1579,7 @@ export abstract class CascadeStore<ED extends EntityDict & BaseEntityDict> exten
} }
else { else {
const createOper = async () => { const createOper = async () => {
if (!option?.dontCreateOper && !['oper', 'operEntity', 'modiEntity', 'modi'].includes(entity as string) && ids.length > 0) { if (!['oper', 'operEntity', 'modiEntity', 'modi'].includes(entity as string) && ids.length > 0) {
// 按照框架要求生成Oper和OperEntity这两个内置的对象 // 按照框架要求生成Oper和OperEntity这两个内置的对象
assert(operId); assert(operId);
const createOper: CreateSingleOperOperation = { const createOper: CreateSingleOperOperation = {
@ -1614,7 +1608,6 @@ export abstract class CascadeStore<ED extends EntityDict & BaseEntityDict> exten
const closeRootMode = context.openRootMode(); const closeRootMode = context.openRootMode();
await this.cascadeUpdateAsync('oper', createOper, context, { await this.cascadeUpdateAsync('oper', createOper, context, {
dontCollect: true, dontCollect: true,
dontCreateOper: true,
}); });
closeRootMode(); closeRootMode();
} }
@ -1631,15 +1624,6 @@ export abstract class CascadeStore<ED extends EntityDict & BaseEntityDict> exten
} }
} }
}); });
/* context.opRecords.push({
a: 'r',
e: entity,
f: {
id: {
$in: ids,
}
},
}); */
} }
} }
else { else {
@ -1660,16 +1644,6 @@ export abstract class CascadeStore<ED extends EntityDict & BaseEntityDict> exten
} }
}, },
}); });
/* context.opRecords.push({
a: 'u',
e: entity,
d: data as ED[T]['Update']['data'],
f: {
id: {
$in: ids,
}
},
}); */
} }
} }
else if (action !== 'update') { else if (action !== 'update') {

View File

@ -40,8 +40,6 @@ export type SelectOption = {
export type OperateOption = { export type OperateOption = {
blockTrigger?: true; blockTrigger?: true;
dontCollect?: boolean; dontCollect?: boolean;
dontCreateOper?: boolean;
dontCreateModi?: boolean;
includedDeleted?: true; // 是否更新已删除行 includedDeleted?: true; // 是否更新已删除行
allowExists?: boolean; // 插入时允许已经存在唯一键值的行了即insert / update逻辑 allowExists?: boolean; // 插入时允许已经存在唯一键值的行了即insert / update逻辑
modiParentId?: string; // 如果是延时更新相关modi要关联到一个父亲上统一应用 modiParentId?: string; // 如果是延时更新相关modi要关联到一个父亲上统一应用
@ -190,14 +188,14 @@ export type RemoveOperation = Operation<'remove', RemoveOperationData, Filter, S
export type CUDOperation = CreateOperation | UpdateOperation | RemoveOperation; export type CUDOperation = CreateOperation | UpdateOperation | RemoveOperation;
export type CreateOpResult<ED extends EntityDict, T extends keyof ED> = { export type CreateOpResult<ED extends EntityDict, T extends keyof ED> = {
id?: string; id: string;
a: 'c'; a: 'c';
e: T; e: T;
d: ED[T]['OpSchema'] | ED[T]['OpSchema'][]; d: ED[T]['OpSchema'] | ED[T]['OpSchema'][];
}; };
export type UpdateOpResult<ED extends EntityDict, T extends keyof ED> = { export type UpdateOpResult<ED extends EntityDict, T extends keyof ED> = {
id?: string; id: string;
a: 'u', a: 'u',
e: T; e: T;
d: UpdateOperationData; d: UpdateOperationData;
@ -205,7 +203,7 @@ export type UpdateOpResult<ED extends EntityDict, T extends keyof ED> = {
}; };
export type RemoveOpResult<ED extends EntityDict, T extends keyof ED> = { export type RemoveOpResult<ED extends EntityDict, T extends keyof ED> = {
id?: string; id: string;
a: 'r', a: 'r',
e: T; e: T;
f?: Filter; f?: Filter;

16
src/utils/relationPath.ts Normal file
View File

@ -0,0 +1,16 @@
import { StorageSchema } from "..";
import { EntityDict as BaseEntityDict } from "../base-app-domain";
import { EntityDict } from "../types/Entity";
export function destructRelationPath<ED extends EntityDict & BaseEntityDict, T extends keyof ED>(
schema: StorageSchema<ED>,
entity: T,
path: string,
relationFilter?: ED['userRelation']['Selection']['filter'],
recursive?: boolean
): {
projection: ED[T]['Selection']['data'];
getData: (d: Partial<ED[T]['Schema']>) => ED['userRelation']['Schema'][];
} {
throw new Error('method not implemented');
}