vona-module-a-orm 5.0.74 → 5.0.76

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.
@@ -41,51 +41,7 @@ export declare function config(_app: VonaApplication): {
41
41
  presetDefault: TSummerCachePreset;
42
42
  preset: {
43
43
  redis: import("vona-module-a-summer").IDecoratorSummerCacheOptions;
44
- redisWithIgnoreNull: {
45
- ignoreNull: boolean;
46
- preset?: TSummerCachePreset;
47
- mode?: import("vona-module-a-summer").TSummerCacheMode;
48
- mem?: {
49
- max?: number;
50
- ttl?: number;
51
- updateAgeOnGet?: boolean;
52
- updateAgeOnHas?: boolean;
53
- broadcastOnSet?: import("vona-module-a-cache").TypeBroadcastOnSet;
54
- disableInstance?: boolean;
55
- };
56
- redis?: {
57
- ttl?: number;
58
- updateAgeOnGet?: boolean;
59
- client?: keyof import("vona-module-a-redis").IRedisClientRecord;
60
- disableInstance?: boolean;
61
- };
62
- emptyArrayAsNull?: boolean;
63
- enable?: boolean;
64
- meta?: Omit<IOnionOptionsMeta, never> | undefined;
65
- };
66
44
  all: import("vona-module-a-summer").IDecoratorSummerCacheOptions;
67
- allWithIgnoreNull: {
68
- ignoreNull: boolean;
69
- preset?: TSummerCachePreset;
70
- mode?: import("vona-module-a-summer").TSummerCacheMode;
71
- mem?: {
72
- max?: number;
73
- ttl?: number;
74
- updateAgeOnGet?: boolean;
75
- updateAgeOnHas?: boolean;
76
- broadcastOnSet?: import("vona-module-a-cache").TypeBroadcastOnSet;
77
- disableInstance?: boolean;
78
- };
79
- redis?: {
80
- ttl?: number;
81
- updateAgeOnGet?: boolean;
82
- client?: keyof import("vona-module-a-redis").IRedisClientRecord;
83
- disableInstance?: boolean;
84
- };
85
- emptyArrayAsNull?: boolean;
86
- enable?: boolean;
87
- meta?: Omit<IOnionOptionsMeta, never> | undefined;
88
- };
89
45
  };
90
46
  redis: {
91
47
  client: string;
package/dist/index.js CHANGED
@@ -15,7 +15,7 @@ import { Broadcast, BeanBroadcastBase } from 'vona-module-a-broadcast';
15
15
  import { Event, BeanEventBase } from 'vona-module-a-event';
16
16
  import { Queue, BeanQueueBase } from 'vona-module-a-queue';
17
17
  import { Schedule } from 'vona-module-a-schedule';
18
- import { configAllWithIgnoreNull, configAll, configRedisWithIgnoreNull, configRedis } from 'vona-module-a-summer';
18
+ import { configAll, configRedis } from 'vona-module-a-summer';
19
19
  import { ServiceDatabaseAsyncLocalStorage as ServiceDatabaseAsyncLocalStorage$1, ServiceTransactionConsistency‌ as ServiceTransactionConsistency_ } from 'vona-module-a-orm';
20
20
  import { mutate } from 'mutate-on-copy';
21
21
 
@@ -2910,8 +2910,9 @@ class BeanModelCache extends BeanModelCrud {
2910
2910
  if (!table) return this.scopeOrm.error.ShouldSpecifyTable.throw();
2911
2911
  // insert
2912
2912
  const res = await this._insertBulk(table, items, options);
2913
- // clear cache
2914
- await this.cacheQueryClear(table);
2913
+ // delete cache
2914
+ const ids = res.map(item => cast(item).id);
2915
+ await this.cacheEntityDel(ids, table);
2915
2916
  return res;
2916
2917
  }
2917
2918
  async mutate(data, options) {
@@ -2996,9 +2997,10 @@ class BeanModelCache extends BeanModelCrud {
2996
2997
  const cache = this.cacheEntity.getInstance(table);
2997
2998
  let items = await cache.mget(ids, {
2998
2999
  mget: async ids => {
2999
- return await super._mget_original(table, ids, {
3000
+ const items = await super._mget_original(table, ids, {
3000
3001
  disableDeleted: true
3001
3002
  });
3003
+ return items.map(item => item === undefined ? null : item);
3002
3004
  },
3003
3005
  db: this.db
3004
3006
  });
@@ -3181,10 +3183,7 @@ class BeanModelCache extends BeanModelCrud {
3181
3183
  }
3182
3184
  // select
3183
3185
  const options2 = deepExtend({}, options, {
3184
- columns: undefined,
3185
- cache: {
3186
- emptyArrayAsNull: true
3187
- }
3186
+ columns: undefined
3188
3187
  });
3189
3188
  const items = await this.__select_raw(table, params, options2);
3190
3189
  return items[0];
@@ -3242,10 +3241,7 @@ class BeanModelCache extends BeanModelCrud {
3242
3241
  id
3243
3242
  }) : options?.where;
3244
3243
  const options2 = deepExtend({}, options, {
3245
- where: undefined,
3246
- cache: {
3247
- emptyArrayAsNull: true
3248
- }
3244
+ where: undefined
3249
3245
  });
3250
3246
  const items = await this.__select_raw(table, {
3251
3247
  where,
@@ -3302,15 +3298,10 @@ class BeanModelCache extends BeanModelCrud {
3302
3298
  let id = this.__checkCacheKeyValid(where, table);
3303
3299
  if (isNil(id)) {
3304
3300
  // check where and get id
3305
- const options2 = deepExtend({}, options, {
3306
- cache: {
3307
- emptyArrayAsNull: true
3308
- }
3309
- });
3310
3301
  const items = await this.__select_raw(table, {
3311
3302
  where,
3312
3303
  columns: ['id']
3313
- }, options2);
3304
+ }, options);
3314
3305
  if (items.length === 0) {
3315
3306
  // donothing
3316
3307
  return;
@@ -3337,9 +3328,10 @@ class BeanModelCache extends BeanModelCrud {
3337
3328
  const item = await cache.get(id, {
3338
3329
  get: async () => {
3339
3330
  // where: maybe contain aux key
3340
- return await super._get(table, where, {
3331
+ const item = await super._get(table, where, {
3341
3332
  disableDeleted: true
3342
3333
  });
3334
+ return item === undefined ? null : item;
3343
3335
  },
3344
3336
  db: this.db
3345
3337
  });
@@ -3481,13 +3473,13 @@ class BeanModelCache extends BeanModelCrud {
3481
3473
  if (options?.disableCacheQuery === true || options?.disableCacheQuery === false) {
3482
3474
  return options?.disableCacheQuery;
3483
3475
  }
3484
- return !this.cacheQuery.enabled;
3476
+ return !(options?.cache?.enable ?? this.cacheQuery.enabled);
3485
3477
  }
3486
3478
  _checkDisableCacheEntityByOptions(options) {
3487
3479
  if (options?.disableCacheEntity === true || options?.disableCacheEntity === false) {
3488
3480
  return options?.disableCacheEntity;
3489
3481
  }
3490
- return !this.cacheEntity.enabled;
3482
+ return !(options?.cache?.enable ?? this.cacheEntity.enabled);
3491
3483
  }
3492
3484
  __checkIfOnlyKey(keys, table, noCheckLength) {
3493
3485
  const columnId = `${table}.id`;
@@ -3736,9 +3728,7 @@ function config(_app) {
3736
3728
  presetDefault: 'redis',
3737
3729
  preset: {
3738
3730
  redis: configRedis,
3739
- redisWithIgnoreNull: configRedisWithIgnoreNull,
3740
- all: configAll,
3741
- allWithIgnoreNull: configAllWithIgnoreNull
3731
+ all: configAll
3742
3732
  },
3743
3733
  redis: {
3744
3734
  client: 'model'
@@ -3773,7 +3763,7 @@ function ExtendSchemaBuilder(app) {
3773
3763
  ['fetchDatabases', 'createDatabase', 'dropDatabase', 'fetchIndexes'].forEach(method => {
3774
3764
  knex.SchemaBuilder.extend(method, async function (...args) {
3775
3765
  const client = cast(cast(this).client).config.client;
3776
- const dialect = app.bean.scope('a-orm').service.database.getDialect(client);
3766
+ const dialect = app.scope('a-orm').service.database.getDialect(client);
3777
3767
  return await dialect[method](this, ...args);
3778
3768
  });
3779
3769
  });
@@ -3782,7 +3772,7 @@ function ExtendSchemaBuilder(app) {
3782
3772
  const __ThisModule__ = 'a-orm';
3783
3773
 
3784
3774
  function ExtendTableBuilder(app) {
3785
- const scope = app.bean.scope(__ThisModule__);
3775
+ const scope = app.scope(__ThisModule__);
3786
3776
  function _basicFields(options, identityType) {
3787
3777
  options = options || {};
3788
3778
  if (options.id !== false) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vona-module-a-orm",
3
3
  "type": "module",
4
- "version": "5.0.74",
4
+ "version": "5.0.76",
5
5
  "title": "a-orm",
6
6
  "vonaModule": {
7
7
  "capabilities": {