oak-domain 5.0.9 → 5.0.10

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.
@@ -162,6 +162,7 @@ class CascadeStore extends RowStore_1.RowStore {
162
162
  checkSortAttr(attr, sortAttr[attr], projNode[attr]);
163
163
  }
164
164
  }
165
+ assignNecessaryProjectionAttrs(projNode, necessaryAttrs);
165
166
  };
166
167
  sorterNode.forEach((node) => {
167
168
  const { $attr } = node;
@@ -304,9 +304,17 @@ class TriggerExecutor {
304
304
  return execPreTrigger(idx + 1);
305
305
  }
306
306
  }
307
- const number = await trigger.fn({ operation: operation }, context, option);
308
- if (number > 0 && process.env.NODE_ENV === 'development') {
309
- this.logger.info(`前触发器「${trigger.name}」成功触发了「${number}」行数据更改`);
307
+ const closeRoot = trigger.asRoot && context.openRootMode();
308
+ try {
309
+ const number = await trigger.fn({ operation: operation }, context, option);
310
+ if (number > 0 && process.env.NODE_ENV === 'development') {
311
+ this.logger.info(`前触发器「${trigger.name}」成功触发了「${number}」行数据更改`);
312
+ }
313
+ closeRoot && closeRoot();
314
+ }
315
+ catch (err) {
316
+ closeRoot && closeRoot();
317
+ throw err;
310
318
  }
311
319
  return execPreTrigger(idx + 1);
312
320
  };
@@ -338,26 +346,41 @@ class TriggerExecutor {
338
346
  (0, assert_1.default)(trigger && trigger.when === 'commit');
339
347
  (0, assert_1.default)(ids.length > 0);
340
348
  const { fn } = trigger;
341
- const callback = await fn({ ids }, context, option);
342
- if (trigger.strict === 'makeSure') {
343
- // 这里开root模式,否则还可能有权限问题
344
- context.openRootMode();
345
- await context.operate(entity, {
346
- id: await (0, uuid_1.generateNewIdAsync)(),
347
- action: 'update',
348
- data: {
349
- [Entity_1.TriggerDataAttribute]: null,
350
- [Entity_1.TriggerUuidAttribute]: null,
351
- },
352
- filter: {
353
- id: {
354
- $in: ids,
355
- }
349
+ const closeRoot = trigger.asRoot && context.openRootMode();
350
+ try {
351
+ const callback = await fn({ ids }, context, option);
352
+ if (trigger.strict === 'makeSure') {
353
+ // 这里开root模式,否则还可能有权限问题
354
+ const closeRoot2 = context.openRootMode();
355
+ try {
356
+ await context.operate(entity, {
357
+ id: await (0, uuid_1.generateNewIdAsync)(),
358
+ action: 'update',
359
+ data: {
360
+ [Entity_1.TriggerDataAttribute]: null,
361
+ [Entity_1.TriggerUuidAttribute]: null,
362
+ },
363
+ filter: {
364
+ id: {
365
+ $in: ids,
366
+ }
367
+ }
368
+ }, { includedDeleted: true, blockTrigger: true });
369
+ closeRoot2 && closeRoot2();
370
+ }
371
+ catch (err2) {
372
+ closeRoot2 && closeRoot2();
373
+ throw err2;
356
374
  }
357
- }, { includedDeleted: true, blockTrigger: true });
375
+ }
376
+ if (typeof callback === 'function') {
377
+ await callback(context, option);
378
+ }
379
+ closeRoot && closeRoot();
358
380
  }
359
- if (typeof callback === 'function') {
360
- await callback(context, option);
381
+ catch (err) {
382
+ closeRoot && closeRoot();
383
+ throw err;
361
384
  }
362
385
  }
363
386
  /**
@@ -407,12 +430,20 @@ class TriggerExecutor {
407
430
  return;
408
431
  }
409
432
  const trigger = postTriggers[idx];
410
- const number = await trigger.fn({
411
- operation: operation,
412
- result: result,
413
- }, context, option);
414
- if (number > 0 && process.env.NODE_ENV === 'development') {
415
- this.logger.info(`后触发器「${trigger.name}」成功触发了「${number}」行数据更改`);
433
+ const closeRoot = trigger.asRoot && context.openRootMode();
434
+ try {
435
+ const number = await trigger.fn({
436
+ operation: operation,
437
+ result: result,
438
+ }, context, option);
439
+ if (number > 0 && process.env.NODE_ENV === 'development') {
440
+ this.logger.info(`后触发器「${trigger.name}」成功触发了「${number}」行数据更改`);
441
+ }
442
+ closeRoot && closeRoot();
443
+ }
444
+ catch (err) {
445
+ closeRoot && closeRoot();
446
+ throw err;
416
447
  }
417
448
  return execPostTrigger(idx + 1);
418
449
  };
@@ -21,6 +21,7 @@ interface TriggerBase<ED extends EntityDict, T extends keyof ED> {
21
21
  checkerType?: CheckerType;
22
22
  entity: T;
23
23
  name: string;
24
+ asRoot?: true;
24
25
  priority?: number;
25
26
  }
26
27
  export interface CreateTriggerBase<ED extends EntityDict, T extends keyof ED, Cxt extends AsyncContext<ED> | SyncContext<ED>> extends TriggerBase<ED, T> {
@@ -2,3 +2,4 @@ import { EntityDict } from '../types/Entity';
2
2
  import { EntityDict as BaseEntityDict } from '../base-app-domain';
3
3
  import { StorageSchema } from '../types/Storage';
4
4
  export declare function makeProjection<ED extends BaseEntityDict & EntityDict, T extends keyof ED>(entity: T, schema: StorageSchema<ED>): ED[T]["Selection"]["data"];
5
+ export declare function traverseProjection<ED extends BaseEntityDict & EntityDict, T extends keyof ED>(entity: T, schema: StorageSchema<ED>, projection: ED[T]['Selection']['data'], callback: <T2 extends keyof ED>(entity2: T2, projection2: ED[T2]['Selection']['data']) => void): void;
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.makeProjection = void 0;
3
+ exports.traverseProjection = exports.makeProjection = void 0;
4
4
  const Entity_1 = require("../types/Entity");
5
+ const relation_1 = require("../store/relation");
5
6
  function makeProjection(entity, schema) {
6
7
  const { attributes } = schema[entity];
7
8
  const attrs = Object.keys(attributes);
@@ -13,3 +14,22 @@ function makeProjection(entity, schema) {
13
14
  return projection;
14
15
  }
15
16
  exports.makeProjection = makeProjection;
17
+ function traverseProjection(entity, schema, projection, callback) {
18
+ const access = (entity2, proj) => {
19
+ callback(entity2, proj);
20
+ for (const attr in proj) {
21
+ const rel = (0, relation_1.judgeRelation)(schema, entity2, attr);
22
+ if (rel === 2) {
23
+ access(attr, proj[attr]);
24
+ }
25
+ else if (typeof rel === 'string') {
26
+ access(rel, proj[attr]);
27
+ }
28
+ else if (rel instanceof Array) {
29
+ access(rel[0], proj[attr].data);
30
+ }
31
+ }
32
+ };
33
+ access(entity, projection);
34
+ }
35
+ exports.traverseProjection = traverseProjection;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oak-domain",
3
- "version": "5.0.9",
3
+ "version": "5.0.10",
4
4
  "author": {
5
5
  "name": "XuChang"
6
6
  },