oak-domain 5.0.10 → 5.0.12

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.
@@ -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, // 优先级要放在最低,所有前置的checker/trigger将数据完整之后再在这里检测
82
+ priority: types_1.CHECKER_MAX_PRIORITY,
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', // 只检查update,其它状态转换的action应该不会涉及unique约束的属性
98
+ action: 'update',
99
99
  type: 'logicalData',
100
- priority: types_1.CHECKER_MAX_PRIORITY, // 优先级要放在最低,所有前置的checker/trigger将数据完整之后再在这里检测
100
+ priority: types_1.CHECKER_MAX_PRIORITY,
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, // 优先级要高,先于真正的data检查进行
230
+ priority: 10,
231
231
  checker: (operation) => {
232
232
  const { data } = operation;
233
233
  if (data instanceof Array) {
@@ -352,11 +352,11 @@ function checkAttributeLegal(schema, entity, data) {
352
352
  case 'char':
353
353
  case 'varchar': {
354
354
  if (typeof data[attr] !== 'string') {
355
- throw new Exception_1.OakInputIllegalException(entity, [attr], 'not a string');
355
+ throw new Exception_1.OakInputIllegalException(entity, [attr], `${entity}: ${attr}'s value "${data[attr]}" is not a string`);
356
356
  }
357
357
  const { length } = params;
358
358
  if (length && data[attr].length > length) {
359
- throw new Exception_1.OakInputIllegalException(entity, [attr], 'too long');
359
+ throw new Exception_1.OakInputIllegalException(entity, [attr], `${entity}: ${attr}'s value "${data[attr]}" is too long`);
360
360
  }
361
361
  break;
362
362
  }
@@ -367,21 +367,21 @@ function checkAttributeLegal(schema, entity, data) {
367
367
  case 'decimal':
368
368
  case 'money': {
369
369
  if (typeof data[attr] !== 'number') {
370
- throw new Exception_1.OakInputIllegalException(entity, [attr], 'not a number');
370
+ throw new Exception_1.OakInputIllegalException(entity, [attr], `${entity}: ${attr}'s value "${data[attr]}" is not a number`);
371
371
  }
372
372
  const { min, max } = params || {};
373
373
  if (typeof min === 'number' && data[attr] < min) {
374
- throw new Exception_1.OakInputIllegalException(entity, [attr], 'too small');
374
+ throw new Exception_1.OakInputIllegalException(entity, [attr], `${entity}: ${attr}'s value "${data[attr]}" is too small`);
375
375
  }
376
376
  if (typeof max === 'number' && data[attr] > max) {
377
- throw new Exception_1.OakInputIllegalException(entity, [attr], 'too big');
377
+ throw new Exception_1.OakInputIllegalException(entity, [attr], `${entity}: ${attr}'s value "${data[attr]}" is too big`);
378
378
  }
379
379
  break;
380
380
  }
381
381
  case 'enum': {
382
382
  (0, assert_1.default)(enumeration);
383
383
  if (!enumeration.includes(data[attr])) {
384
- throw new Exception_1.OakInputIllegalException(entity, [attr], 'not in enumeration');
384
+ throw new Exception_1.OakInputIllegalException(entity, [attr], `${entity}: ${attr}'s value "${data[attr]}" is not in enumeration`);
385
385
  }
386
386
  break;
387
387
  }
@@ -22,7 +22,14 @@ function translateCreateDataToFilter(schema, entity, data, allowUnrecoganized) {
22
22
  'array',
23
23
  'object'
24
24
  ].includes(schema[entity].attributes[attr]?.type)) {
25
- data2[attr] = data[attr];
25
+ if (data[attr] === null) {
26
+ data2[attr] = {
27
+ $exists: false,
28
+ };
29
+ }
30
+ else {
31
+ data2[attr] = data[attr];
32
+ }
26
33
  }
27
34
  }
28
35
  }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.vaccumOper = void 0;
4
+ const Entity_1 = require("../types/Entity");
4
5
  const vaccum_1 = require("./vaccum");
5
6
  const filter_1 = require("../store/filter");
6
7
  /**
@@ -11,9 +12,14 @@ const filter_1 = require("../store/filter");
11
12
  */
12
13
  async function vaccumOper(option, context) {
13
14
  const { aliveLine, excludeOpers, ...rest } = option;
14
- const operFilter = {};
15
+ const notFilters = [
16
+ {
17
+ [Entity_1.TriggerUuidAttribute]: {
18
+ $exists: false,
19
+ }
20
+ },
21
+ ];
15
22
  if (excludeOpers) {
16
- const notFilters = [];
17
23
  for (const key in excludeOpers) {
18
24
  if (excludeOpers[key].length > 0) {
19
25
  notFilters.push({
@@ -29,27 +35,28 @@ async function vaccumOper(option, context) {
29
35
  });
30
36
  }
31
37
  }
32
- if (notFilters.length > 0) {
33
- operFilter.$not = {
34
- $or: notFilters,
35
- };
36
- }
37
38
  }
38
39
  return (0, vaccum_1.vaccumEntities)({
39
40
  entities: [{
40
41
  entity: 'operEntity',
41
42
  aliveLine: aliveLine + 10000,
42
43
  filter: {
43
- oper: (0, filter_1.combineFilters)('operEntity', context.getSchema(), [operFilter, {
44
- $$createAt$$: {
45
- $lt: aliveLine,
46
- }
47
- }]),
44
+ oper: {
45
+ $$createAt$$: {
46
+ $lt: aliveLine,
47
+ },
48
+ $not: (0, filter_1.combineFilters)('oper', context.getSchema(), notFilters),
49
+ },
48
50
  },
49
51
  }, {
50
52
  entity: 'oper',
51
53
  aliveLine,
52
- filter: operFilter,
54
+ filter: {
55
+ $$createAt$$: {
56
+ $lt: aliveLine,
57
+ },
58
+ $not: (0, filter_1.combineFilters)('oper', context.getSchema(), notFilters),
59
+ },
53
60
  }],
54
61
  ...rest,
55
62
  }, context);
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  /**
3
2
  * 防止assert打包体积过大,从这里引用
4
3
  */
@@ -60,7 +60,7 @@ function destructRelationPath(schema, entity, path, relationFilter, recursive) {
60
60
  },
61
61
  filter: relationFilter,
62
62
  } // as ED['userRelation']['Selection']
63
- }, // as ED[keyof ED]['Selection']['data'],
63
+ },
64
64
  getData: (d) => {
65
65
  return d.userRelation$entity;
66
66
  },
package/lib/utils/uuid.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.decompressFrom32 = exports.compressTo32 = exports.formUuid = exports.generateNewId = exports.setGenerateIdOption = exports.produceIds = exports.generateNewIdAsync = exports.expandUuidTo36Bytes = exports.shrinkUuidTo32Bytes = exports.sequentialUuid = void 0;
4
- const uuid_1 = require("uuid");
4
+ // import { v4 } from 'uuid';
5
5
  const random_1 = require("./random/random");
6
6
  let _nodeId;
7
7
  let _clockseq;
@@ -112,9 +112,9 @@ exports.expandUuidTo36Bytes = expandUuidTo36Bytes;
112
112
  // 直接生成uuid的接口,为了适配各种环境,写成异步
113
113
  async function generateNewIdAsync(option) {
114
114
  const option2 = option || ID_OPTION;
115
- if (option2?.shuffle || process.env.NODE_ENV === 'development') {
116
- return (0, uuid_1.v4)({ random: await (0, random_1.getRandomValues)(16) });
117
- }
115
+ /* if (option2?.shuffle || process.env.NODE_ENV === 'development') {
116
+ return v4({ random: await getRandomValues(16) });
117
+ } */
118
118
  return sequentialUuid({ random: await (0, random_1.getRandomValues)(16) });
119
119
  }
120
120
  exports.generateNewIdAsync = generateNewIdAsync;
@@ -150,9 +150,9 @@ function generateNewId() {
150
150
  do {
151
151
  random[iter] = Math.ceil(Math.random() * 1000) % 128;
152
152
  } while (++iter < 16);
153
- if (ID_OPTION?.shuffle || process.env.NODE_ENV === 'development') {
154
- return (0, uuid_1.v4)({ random });
155
- }
153
+ /* if (ID_OPTION?.shuffle || process.env.NODE_ENV === 'development') {
154
+ return v4({ random });
155
+ } */
156
156
  return sequentialUuid({ random });
157
157
  }
158
158
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oak-domain",
3
- "version": "5.0.10",
3
+ "version": "5.0.12",
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
+ };