oak-domain 5.0.15 → 5.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -29,6 +29,12 @@ export declare abstract class AsyncContext<ED extends EntityDict> implements Con
29
29
  private resetEvents;
30
30
  on(event: 'commit' | 'rollback', callback: (records: OpRecord<ED>[], cxtStr: string) => Promise<void>): void;
31
31
  saveOpRecord<T extends keyof ED>(entity: T, operation: ED[T]['Operation']): void;
32
+ /**
33
+ * 查询某operation所处理的row ids
34
+ * 如果该operation还未执行,可能返回空数组(不知道实际关联的row id);但是在after的trigger中,返回是准确的ids值(此时如果是空数组说明没有有关row id)
35
+ * @param id
36
+ */
37
+ getRowIdsOfOperation(operation: ED[keyof ED]['Operation']): string[];
32
38
  /**
33
39
  * 一个context中不应该有并发的事务,这里将事务串行化,使用的时候千万要注意不要自己等自己
34
40
  * @param options
@@ -4,6 +4,7 @@ exports.AsyncContext = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const action_1 = require("../actions/action");
6
6
  const assert_1 = tslib_1.__importDefault(require("assert"));
7
+ const filter_1 = require("./filter");
7
8
  /**
8
9
  * 服务器端执行的异步环境的底层抽象
9
10
  */
@@ -75,7 +76,7 @@ class AsyncContext {
75
76
  id,
76
77
  a: 'c',
77
78
  e: entity,
78
- d: data
79
+ d: data,
79
80
  });
80
81
  break;
81
82
  }
@@ -100,6 +101,35 @@ class AsyncContext {
100
101
  }
101
102
  }
102
103
  }
104
+ /**
105
+ * 查询某operation所处理的row ids
106
+ * 如果该operation还未执行,可能返回空数组(不知道实际关联的row id);但是在after的trigger中,返回是准确的ids值(此时如果是空数组说明没有有关row id)
107
+ * @param id
108
+ */
109
+ getRowIdsOfOperation(operation) {
110
+ const { id, action, data, filter } = operation;
111
+ if (action === 'create') {
112
+ if (data instanceof Array) {
113
+ return data.map(ele => ele.id);
114
+ }
115
+ return [data.id];
116
+ }
117
+ else if (filter) {
118
+ const ids = (0, filter_1.getRelevantIds)(filter);
119
+ if (ids.length > 0) {
120
+ return ids;
121
+ }
122
+ }
123
+ const oper = this.opRecords.find(ele => ele.id === id);
124
+ if (oper) {
125
+ const { a } = oper;
126
+ (0, assert_1.default)(a !== 'create');
127
+ const { f } = oper;
128
+ (0, assert_1.default)(f && f?.id?.$in && f.id.$in instanceof Array);
129
+ return f.id.$in;
130
+ }
131
+ return [];
132
+ }
103
133
  /**
104
134
  * 一个context中不应该有并发的事务,这里将事务串行化,使用的时候千万要注意不要自己等自己
105
135
  * @param options
@@ -1217,6 +1217,7 @@ class CascadeStore extends RowStore_1.RowStore {
1217
1217
  };
1218
1218
  const rows = await this.selectAbjointRowAsync(entity, selection, context, {
1219
1219
  dontCollect: true,
1220
+ forUpdate: true,
1220
1221
  });
1221
1222
  ids.push(...(rows.map(ele => ele.id)));
1222
1223
  }
@@ -79,7 +79,7 @@ function createUniqueCheckers(schema) {
79
79
  entity,
80
80
  action: 'create',
81
81
  type: 'logicalData',
82
- priority: types_1.CHECKER_MAX_PRIORITY,
82
+ priority: types_1.CHECKER_MAX_PRIORITY, // 优先级要放在最低,所有前置的checker/trigger将数据完整之后再在这里检测
83
83
  checker: (operation, context) => {
84
84
  const { data } = operation;
85
85
  if (data instanceof Array) {
@@ -95,9 +95,9 @@ function createUniqueCheckers(schema) {
95
95
  }
96
96
  }, {
97
97
  entity,
98
- action: 'update',
98
+ action: 'update', // 只检查update,其它状态转换的action应该不会涉及unique约束的属性
99
99
  type: 'logicalData',
100
- priority: types_1.CHECKER_MAX_PRIORITY,
100
+ priority: types_1.CHECKER_MAX_PRIORITY, // 优先级要放在最低,所有前置的checker/trigger将数据完整之后再在这里检测
101
101
  checker: (operation, context) => {
102
102
  const { data, filter: operationFilter } = operation;
103
103
  if (data) {
@@ -227,7 +227,7 @@ function createActionTransformerCheckers(actionDefDict) {
227
227
  action: 'create',
228
228
  type: 'logical',
229
229
  entity,
230
- priority: 10,
230
+ priority: 10, // 优先级要高,先于真正的data检查进行
231
231
  checker: (operation) => {
232
232
  const { data } = operation;
233
233
  if (data instanceof Array) {
@@ -645,6 +645,7 @@ function judgeValueRelation(value1, value2, contained) {
645
645
  else if (r) {
646
646
  return false;
647
647
  }
648
+ return;
648
649
  }
649
650
  // 互斥
650
651
  if (r) {
@@ -1,3 +1,4 @@
1
+ /// <reference types="node" />
1
2
  /**
2
3
  * 防止assert打包体积过大,从这里引用
3
4
  */
@@ -60,7 +60,7 @@ function destructRelationPath(schema, entity, path, relationFilter, recursive) {
60
60
  },
61
61
  filter: relationFilter,
62
62
  } // as ED['userRelation']['Selection']
63
- },
63
+ }, // as ED[keyof ED]['Selection']['data'],
64
64
  getData: (d) => {
65
65
  return d.userRelation$entity;
66
66
  },
@@ -6,7 +6,7 @@ declare const url: {
6
6
  revokeObjectURL(url: string): void;
7
7
  };
8
8
  declare const urlSearchParams: {
9
- new (init?: string | Record<string, string> | string[][] | URLSearchParams | undefined): URLSearchParams;
9
+ new (init?: string | string[][] | Record<string, string> | URLSearchParams | undefined): URLSearchParams;
10
10
  prototype: URLSearchParams;
11
11
  };
12
12
  export { url, urlSearchParams };
@@ -6,7 +6,7 @@ declare const url: {
6
6
  revokeObjectURL(url: string): void;
7
7
  };
8
8
  declare const urlSearchParams: {
9
- new (init?: string | Record<string, string> | string[][] | URLSearchParams | undefined): URLSearchParams;
9
+ new (init?: string | string[][] | Record<string, string> | URLSearchParams | undefined): URLSearchParams;
10
10
  prototype: URLSearchParams;
11
11
  };
12
12
  export { url, urlSearchParams };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oak-domain",
3
- "version": "5.0.15",
3
+ "version": "5.0.16",
4
4
  "author": {
5
5
  "name": "XuChang"
6
6
  },
@@ -1,26 +1,26 @@
1
- import { String } from '../types/DataType';
2
- import { EntityShape } from '../types/Entity';
3
- import { Schema as Modi } from './Modi';
4
- import { EntityDesc } from '../types/EntityDesc';
5
-
6
- export interface Schema extends EntityShape {
7
- modi: Modi,
8
- entity: String<32>;
9
- entityId: String<64>;
10
- };
11
-
12
- const entityDesc: EntityDesc<Schema> = {
13
- locales: {
14
- zh_CN: {
15
- name: '更新对象连接',
16
- attr: {
17
- modi: '更新',
18
- entity: '关联对象',
19
- entityId: '关联对象id',
20
- },
21
- },
22
- },
23
- configuration: {
24
- actionType: 'appendOnly',
25
- }
26
- };
1
+ import { String } from '../types/DataType';
2
+ import { EntityShape } from '../types/Entity';
3
+ import { Schema as Modi } from './Modi';
4
+ import { EntityDesc } from '../types/EntityDesc';
5
+
6
+ export interface Schema extends EntityShape {
7
+ modi: Modi,
8
+ entity: String<32>;
9
+ entityId: String<64>;
10
+ };
11
+
12
+ const entityDesc: EntityDesc<Schema> = {
13
+ locales: {
14
+ zh_CN: {
15
+ name: '更新对象连接',
16
+ attr: {
17
+ modi: '更新',
18
+ entity: '关联对象',
19
+ entityId: '关联对象id',
20
+ },
21
+ },
22
+ },
23
+ configuration: {
24
+ actionType: 'appendOnly',
25
+ }
26
+ };
@@ -1,27 +1,27 @@
1
- import { String } from '../types/DataType';
2
- import { EntityShape, Configuration } from '../types/Entity';
3
- import { LocaleDef } from '../types/Locale';
4
- import { Schema as Oper } from './Oper';
5
- import { EntityDesc } from '../types/EntityDesc';
6
-
7
- export interface Schema extends EntityShape {
8
- oper: Oper,
9
- entity: String<32>;
10
- entityId: String<64>;
11
- };
12
-
13
- const entityDesc: EntityDesc<Schema> = {
14
- locales: {
15
- zh_CN: {
16
- name: '操作对象连接',
17
- attr: {
18
- oper: '操作',
19
- entity: '关联对象',
20
- entityId: '关联对象id',
21
- },
22
- },
23
- },
24
- configuration: {
25
- actionType: 'appendOnly',
26
- }
27
- };
1
+ import { String } from '../types/DataType';
2
+ import { EntityShape, Configuration } from '../types/Entity';
3
+ import { LocaleDef } from '../types/Locale';
4
+ import { Schema as Oper } from './Oper';
5
+ import { EntityDesc } from '../types/EntityDesc';
6
+
7
+ export interface Schema extends EntityShape {
8
+ oper: Oper,
9
+ entity: String<32>;
10
+ entityId: String<64>;
11
+ };
12
+
13
+ const entityDesc: EntityDesc<Schema> = {
14
+ locales: {
15
+ zh_CN: {
16
+ name: '操作对象连接',
17
+ attr: {
18
+ oper: '操作',
19
+ entity: '关联对象',
20
+ entityId: '关联对象id',
21
+ },
22
+ },
23
+ },
24
+ configuration: {
25
+ actionType: 'appendOnly',
26
+ }
27
+ };
@@ -1,43 +1,43 @@
1
- import { String } from '../types/DataType';
2
- import { EntityShape } from '../types/Entity';
3
- import { EntityDesc } from '../types/EntityDesc';
4
-
5
- export interface Schema extends EntityShape {
6
- entity: String<32>;
7
- entityId?: String<64>; // 可以为空
8
- name?: String<32>;
9
- display?: String<32>;
10
- };
11
-
12
- const entityDesc: EntityDesc<Schema> = {
13
- locales: {
14
- zh_CN: {
15
- name: '用户授权',
16
- attr: {
17
- name: '关系',
18
- entity: '目标对象',
19
- entityId: '目标对象id',
20
- display: '显示值',
21
- },
22
- },
23
- },
24
- indexes: [
25
- {
26
- name: 'index_targetEntity_entityId_name',
27
- attributes: [
28
- {
29
- name: 'entity',
30
- },
31
- {
32
- name: 'entityId',
33
- },
34
- {
35
- name: 'name',
36
- }
37
- ],
38
- config: {
39
- unique: true,
40
- },
41
- },
42
- ]
43
- };
1
+ import { String } from '../types/DataType';
2
+ import { EntityShape } from '../types/Entity';
3
+ import { EntityDesc } from '../types/EntityDesc';
4
+
5
+ export interface Schema extends EntityShape {
6
+ entity: String<32>;
7
+ entityId?: String<64>; // 可以为空
8
+ name?: String<32>;
9
+ display?: String<32>;
10
+ };
11
+
12
+ const entityDesc: EntityDesc<Schema> = {
13
+ locales: {
14
+ zh_CN: {
15
+ name: '用户授权',
16
+ attr: {
17
+ name: '关系',
18
+ entity: '目标对象',
19
+ entityId: '目标对象id',
20
+ display: '显示值',
21
+ },
22
+ },
23
+ },
24
+ indexes: [
25
+ {
26
+ name: 'index_targetEntity_entityId_name',
27
+ attributes: [
28
+ {
29
+ name: 'entity',
30
+ },
31
+ {
32
+ name: 'entityId',
33
+ },
34
+ {
35
+ name: 'name',
36
+ }
37
+ ],
38
+ config: {
39
+ unique: true,
40
+ },
41
+ },
42
+ ]
43
+ };
@@ -1,30 +1,30 @@
1
- import { String } from '../types/DataType';
2
- import { EntityShape } from '../types/Entity';
3
- import { EntityDesc } from '../types/EntityDesc';
4
- import { Schema as UserEntityGrant } from './UserEntityGrant';
5
- import { Schema as User } from './User';
6
- import { Schema as Relation } from './Relation';
7
- import { Schema as UserRelation } from './UserRelation';
8
-
9
- export interface Schema extends EntityShape {
10
- ueg: UserEntityGrant;
11
- user: User;
12
- relation: Relation;
13
- claimEntityId: String<64>;
14
- userRelation: UserRelation;
15
- };
16
-
17
- const entityDesc: EntityDesc<Schema, ''> = {
18
- locales: {
19
- zh_CN: {
20
- name: '用户授权领取',
21
- attr: {
22
- ueg: '授权',
23
- user: '用户',
24
- relation: '关系',
25
- claimEntityId: '对象Id',
26
- userRelation: '用户关系',
27
- },
28
- },
29
- },
1
+ import { String } from '../types/DataType';
2
+ import { EntityShape } from '../types/Entity';
3
+ import { EntityDesc } from '../types/EntityDesc';
4
+ import { Schema as UserEntityGrant } from './UserEntityGrant';
5
+ import { Schema as User } from './User';
6
+ import { Schema as Relation } from './Relation';
7
+ import { Schema as UserRelation } from './UserRelation';
8
+
9
+ export interface Schema extends EntityShape {
10
+ ueg: UserEntityGrant;
11
+ user: User;
12
+ relation: Relation;
13
+ claimEntityId: String<64>;
14
+ userRelation: UserRelation;
15
+ };
16
+
17
+ const entityDesc: EntityDesc<Schema, ''> = {
18
+ locales: {
19
+ zh_CN: {
20
+ name: '用户授权领取',
21
+ attr: {
22
+ ueg: '授权',
23
+ user: '用户',
24
+ relation: '关系',
25
+ claimEntityId: '对象Id',
26
+ userRelation: '用户关系',
27
+ },
28
+ },
29
+ },
30
30
  };
@@ -1,24 +1,24 @@
1
- import { String } from '../types/DataType';
2
- import { EntityShape } from '../types/Entity';
3
- import { EntityDesc } from '../types/EntityDesc';
4
-
5
- type RelationIds = string[];
6
-
7
- export interface Schema extends EntityShape {
8
- relationEntity: String<32>;
9
- relationEntityFilter: Object;
10
- relationIds: RelationIds;
11
- };
12
-
13
- const entityDesc: EntityDesc<Schema, ''> = {
14
- locales: {
15
- zh_CN: {
16
- name: '用户授权',
17
- attr: {
18
- relationIds: '关系',
19
- relationEntity: '关联对象',
20
- relationEntityFilter: '对象限定条件',
21
- },
22
- },
23
- },
24
- };
1
+ import { String } from '../types/DataType';
2
+ import { EntityShape } from '../types/Entity';
3
+ import { EntityDesc } from '../types/EntityDesc';
4
+
5
+ type RelationIds = string[];
6
+
7
+ export interface Schema extends EntityShape {
8
+ relationEntity: String<32>;
9
+ relationEntityFilter: Object;
10
+ relationIds: RelationIds;
11
+ };
12
+
13
+ const entityDesc: EntityDesc<Schema, ''> = {
14
+ locales: {
15
+ zh_CN: {
16
+ name: '用户授权',
17
+ attr: {
18
+ relationIds: '关系',
19
+ relationEntity: '关联对象',
20
+ relationEntityFilter: '对象限定条件',
21
+ },
22
+ },
23
+ },
24
+ };
@@ -1,50 +1,50 @@
1
- import { String } from '../types/DataType';
2
- import { LocaleDef } from '../types/Locale';
3
- import { EntityShape } from '../types/Entity';
4
- import { Index } from '../types/Storage';
5
- import { Schema as User } from './User';
6
- import { Schema as Relation } from './Relation';
7
- import { EntityDesc } from '../types/EntityDesc';
8
-
9
- export interface Schema extends EntityShape {
10
- user: User;
11
- relation: Relation;
12
- entity: String<32>;
13
- entityId: String<64>;
14
- };
15
-
16
- const entityDesc: EntityDesc<Schema> = {
17
- locales: {
18
- zh_CN: {
19
- name: '用户对象关系',
20
- attr: {
21
- user: '关系',
22
- relation: '目标关系',
23
- entity: '目标对象',
24
- entityId: '目标对象ID',
25
- },
26
- },
27
- },
28
- indexes: [
29
- {
30
- name: 'index_user_entity_entityId_relation',
31
- attributes: [
32
- {
33
- name: 'user',
34
- },
35
- {
36
- name: 'entity',
37
- },
38
- {
39
- name: 'entityId',
40
- },
41
- {
42
- name: 'relation',
43
- },
44
- ],
45
- config: {
46
- unique: true,
47
- },
48
- },
49
- ]
50
- };
1
+ import { String } from '../types/DataType';
2
+ import { LocaleDef } from '../types/Locale';
3
+ import { EntityShape } from '../types/Entity';
4
+ import { Index } from '../types/Storage';
5
+ import { Schema as User } from './User';
6
+ import { Schema as Relation } from './Relation';
7
+ import { EntityDesc } from '../types/EntityDesc';
8
+
9
+ export interface Schema extends EntityShape {
10
+ user: User;
11
+ relation: Relation;
12
+ entity: String<32>;
13
+ entityId: String<64>;
14
+ };
15
+
16
+ const entityDesc: EntityDesc<Schema> = {
17
+ locales: {
18
+ zh_CN: {
19
+ name: '用户对象关系',
20
+ attr: {
21
+ user: '关系',
22
+ relation: '目标关系',
23
+ entity: '目标对象',
24
+ entityId: '目标对象ID',
25
+ },
26
+ },
27
+ },
28
+ indexes: [
29
+ {
30
+ name: 'index_user_entity_entityId_relation',
31
+ attributes: [
32
+ {
33
+ name: 'user',
34
+ },
35
+ {
36
+ name: 'entity',
37
+ },
38
+ {
39
+ name: 'entityId',
40
+ },
41
+ {
42
+ name: 'relation',
43
+ },
44
+ ],
45
+ config: {
46
+ unique: true,
47
+ },
48
+ },
49
+ ]
50
+ };