处理oper上的bornAt的一些细节
This commit is contained in:
parent
50a47f936e
commit
3843386169
|
|
@ -38,5 +38,19 @@ exports.desc = {
|
|||
}
|
||||
},
|
||||
actionType: "appendOnly",
|
||||
actions: action_1.appendOnlyActions
|
||||
actions: action_1.appendOnlyActions,
|
||||
indexes: [
|
||||
{
|
||||
name: 'index_bornAt_operatorId',
|
||||
attributes: [
|
||||
{
|
||||
name: 'bornAt',
|
||||
direction: 'DESC',
|
||||
},
|
||||
{
|
||||
name: "operatorId",
|
||||
},
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
|
|
|
|||
|
|
@ -18,5 +18,19 @@ const entityDesc = {
|
|||
},
|
||||
configuration: {
|
||||
actionType: 'appendOnly',
|
||||
}
|
||||
},
|
||||
indexes: [
|
||||
{
|
||||
name: 'index_bornAt_operatorId',
|
||||
attributes: [
|
||||
{
|
||||
name: 'bornAt',
|
||||
direction: 'DESC',
|
||||
},
|
||||
{
|
||||
name: 'operator',
|
||||
},
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1017,7 +1017,7 @@ class CascadeStore extends RowStore_1.RowStore {
|
|||
* @param option
|
||||
*/
|
||||
async doUpdateSingleRowAsync(entity, operation, context, option) {
|
||||
const { data, action, id: operId, filter } = operation;
|
||||
const { data, action, id: operId, filter, bornAt } = operation;
|
||||
const now = Date.now();
|
||||
switch (action) {
|
||||
case 'create': {
|
||||
|
|
@ -1161,6 +1161,7 @@ class CascadeStore extends RowStore_1.RowStore {
|
|||
data,
|
||||
operatorId,
|
||||
targetEntity: entity,
|
||||
bornAt,
|
||||
operEntity$oper: data instanceof Array ? {
|
||||
id: 'dummy',
|
||||
action: 'create',
|
||||
|
|
@ -1313,6 +1314,7 @@ class CascadeStore extends RowStore_1.RowStore {
|
|||
action,
|
||||
data,
|
||||
targetEntity: entity,
|
||||
bornAt,
|
||||
operEntity$oper: {
|
||||
id: 'dummy',
|
||||
action: 'create',
|
||||
|
|
@ -1350,7 +1352,7 @@ class CascadeStore extends RowStore_1.RowStore {
|
|||
if (updateAttrCount > 0) {
|
||||
// 优化一下,如果不更新任何属性,则不实际执行
|
||||
Object.assign(data, {
|
||||
$$updateAt$$: now,
|
||||
[Entity_1.UpdateAtAttribute]: now,
|
||||
});
|
||||
if (!option.dontCollect) {
|
||||
context.saveOpRecord(entity, {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { EntityDict as BaseEntityDict } from '../base-app-domain';
|
||||
import { StorageSchema, EntityDict } from '../types';
|
||||
import { StorageSchema, EntityDict, Trigger } from '../types';
|
||||
import { AsyncContext } from '../store/AsyncRowStore';
|
||||
import { SyncContext } from '../store/SyncRowStore';
|
||||
export declare function createDynamicTriggers<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED> | SyncContext<ED>>(schema: StorageSchema<ED>): import("../types").Trigger<ED, keyof ED, Cxt>[];
|
||||
export declare function createDynamicTriggers<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED> | SyncContext<ED>>(schema: StorageSchema<ED>): Trigger<ED, keyof ED, Cxt>[];
|
||||
|
|
|
|||
|
|
@ -1,8 +1,28 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.createDynamicTriggers = void 0;
|
||||
const tslib_1 = require("tslib");
|
||||
const assert_1 = tslib_1.__importDefault(require("assert"));
|
||||
const modi_1 = require("../store/modi");
|
||||
function createOperTriggers() {
|
||||
return [
|
||||
{
|
||||
name: 'assign initial bornAt for local oper',
|
||||
entity: 'oper',
|
||||
action: 'create',
|
||||
when: 'before',
|
||||
fn({ operation }) {
|
||||
const { data } = operation;
|
||||
(0, assert_1.default)(!(data instanceof Array) && data.$$createAt$$);
|
||||
if (!data.bornAt) {
|
||||
data.bornAt = data.$$createAt$$;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
];
|
||||
}
|
||||
function createDynamicTriggers(schema) {
|
||||
return (0, modi_1.createModiRelatedTriggers)(schema);
|
||||
return (0, modi_1.createModiRelatedTriggers)(schema).concat(createOperTriggers());
|
||||
}
|
||||
exports.createDynamicTriggers = createDynamicTriggers;
|
||||
|
|
|
|||
|
|
@ -30,5 +30,19 @@ const entityDesc: EntityDesc<Schema> = {
|
|||
},
|
||||
configuration: {
|
||||
actionType: 'appendOnly',
|
||||
}
|
||||
},
|
||||
indexes: [
|
||||
{
|
||||
name: 'index_bornAt_operatorId',
|
||||
attributes: [
|
||||
{
|
||||
name: 'bornAt',
|
||||
direction: 'DESC',
|
||||
},
|
||||
{
|
||||
name: 'operator',
|
||||
},
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1277,7 +1277,7 @@ export abstract class CascadeStore<ED extends EntityDict & BaseEntityDict> exten
|
|||
context: Cxt,
|
||||
option: OP
|
||||
): Promise<OperationResult<ED>> {
|
||||
const { data, action, id: operId, filter } = operation;
|
||||
const { data, action, id: operId, filter, bornAt } = operation;
|
||||
const now = Date.now();
|
||||
|
||||
switch (action) {
|
||||
|
|
@ -1429,6 +1429,7 @@ export abstract class CascadeStore<ED extends EntityDict & BaseEntityDict> exten
|
|||
data,
|
||||
operatorId,
|
||||
targetEntity: entity as string,
|
||||
bornAt,
|
||||
operEntity$oper: data instanceof Array ? {
|
||||
id: 'dummy',
|
||||
action: 'create',
|
||||
|
|
@ -1590,6 +1591,7 @@ export abstract class CascadeStore<ED extends EntityDict & BaseEntityDict> exten
|
|||
action,
|
||||
data,
|
||||
targetEntity: entity as string,
|
||||
bornAt,
|
||||
operEntity$oper: {
|
||||
id: 'dummy',
|
||||
action: 'create',
|
||||
|
|
@ -1631,7 +1633,7 @@ export abstract class CascadeStore<ED extends EntityDict & BaseEntityDict> exten
|
|||
if (updateAttrCount > 0) {
|
||||
// 优化一下,如果不更新任何属性,则不实际执行
|
||||
Object.assign(data, {
|
||||
$$updateAt$$: now,
|
||||
[UpdateAtAttribute]: now,
|
||||
});
|
||||
if (!option.dontCollect) {
|
||||
context.saveOpRecord(entity, {
|
||||
|
|
|
|||
|
|
@ -1,9 +1,29 @@
|
|||
import assert from 'assert';
|
||||
import { EntityDict as BaseEntityDict } from '../base-app-domain';
|
||||
import { StorageSchema, EntityDict } from '../types';
|
||||
import { StorageSchema, EntityDict, Trigger, CreateTrigger } from '../types';
|
||||
import { createModiRelatedTriggers } from '../store/modi';
|
||||
import { AsyncContext } from '../store/AsyncRowStore';
|
||||
import { SyncContext } from '../store/SyncRowStore';
|
||||
|
||||
export function createDynamicTriggers<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED> | SyncContext<ED>>(schema: StorageSchema<ED>) {
|
||||
return createModiRelatedTriggers<ED, Cxt>(schema);
|
||||
function createOperTriggers<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED> | SyncContext<ED>>() {
|
||||
return [
|
||||
{
|
||||
name: 'assign initial bornAt for local oper',
|
||||
entity: 'oper',
|
||||
action: 'create',
|
||||
when: 'before',
|
||||
fn({ operation }) {
|
||||
const { data } = operation;
|
||||
assert(!(data instanceof Array) && data.$$createAt$$);
|
||||
if (!data.bornAt) {
|
||||
data.bornAt = data.$$createAt$$;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
} as CreateTrigger<ED, 'oper', Cxt>
|
||||
] as Trigger<ED, keyof ED, Cxt>[];
|
||||
}
|
||||
|
||||
export function createDynamicTriggers<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED> | SyncContext<ED>>(schema: StorageSchema<ED>) {
|
||||
return createModiRelatedTriggers<ED, Cxt>(schema).concat(createOperTriggers());
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue