vona-module-a-orm 5.0.75 → 5.0.77
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.
- package/dist/config/config.d.ts +0 -44
- package/dist/index.js +18 -26
- package/package.json +1 -1
package/dist/config/config.d.ts
CHANGED
|
@@ -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
|
@@ -3,9 +3,9 @@ import { BeanInfo, BeanAopMethodBase, BeanBase, deepExtend, appResource, Virtual
|
|
|
3
3
|
import { AopMethod } from 'vona-module-a-aspect';
|
|
4
4
|
import { Service, Bean, Scope } from 'vona-module-a-bean';
|
|
5
5
|
import { AsyncLocalStorage, AsyncResource } from 'node:async_hooks';
|
|
6
|
+
import { isNil, catchError, safeBoolean, isClass, ensureArray, hashkey } from '@cabloy/utils';
|
|
6
7
|
import knex from 'knex';
|
|
7
8
|
import { BeanMutateBase } from 'vona-module-a-beanmutate';
|
|
8
|
-
import { isNil, safeBoolean, isClass, ensureArray, hashkey } from '@cabloy/utils';
|
|
9
9
|
import { swapDeps } from '@cabloy/deps';
|
|
10
10
|
import { prepareClassType, getTargetDecoratorRules, getTargetDecoratorRuleColumnsMap, Api, v, OrderMaxBase, OrderCoreBase, getSchemaDynamic, SymbolSchemaDynamicRefId, addSchemaDynamic, mergeFieldsOpenapiMetadata } from 'vona-module-a-openapi';
|
|
11
11
|
import { ZodMetadata } from '@cabloy/zod-openapi';
|
|
@@ -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 {
|
|
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
|
|
|
@@ -686,7 +686,9 @@ let ServiceDatabaseClient = (_dec$k = Service(), _dec2$k = BeanInfo({
|
|
|
686
686
|
}
|
|
687
687
|
async __close() {
|
|
688
688
|
if (this._knex) {
|
|
689
|
-
await
|
|
689
|
+
await catchError(() => {
|
|
690
|
+
return this._knex.destroy();
|
|
691
|
+
});
|
|
690
692
|
this._knex = undefined;
|
|
691
693
|
}
|
|
692
694
|
}
|
|
@@ -2910,8 +2912,9 @@ class BeanModelCache extends BeanModelCrud {
|
|
|
2910
2912
|
if (!table) return this.scopeOrm.error.ShouldSpecifyTable.throw();
|
|
2911
2913
|
// insert
|
|
2912
2914
|
const res = await this._insertBulk(table, items, options);
|
|
2913
|
-
//
|
|
2914
|
-
|
|
2915
|
+
// delete cache
|
|
2916
|
+
const ids = res.map(item => cast(item).id);
|
|
2917
|
+
await this.cacheEntityDel(ids, table);
|
|
2915
2918
|
return res;
|
|
2916
2919
|
}
|
|
2917
2920
|
async mutate(data, options) {
|
|
@@ -2996,9 +2999,10 @@ class BeanModelCache extends BeanModelCrud {
|
|
|
2996
2999
|
const cache = this.cacheEntity.getInstance(table);
|
|
2997
3000
|
let items = await cache.mget(ids, {
|
|
2998
3001
|
mget: async ids => {
|
|
2999
|
-
|
|
3002
|
+
const items = await super._mget_original(table, ids, {
|
|
3000
3003
|
disableDeleted: true
|
|
3001
3004
|
});
|
|
3005
|
+
return items.map(item => item === undefined ? null : item);
|
|
3002
3006
|
},
|
|
3003
3007
|
db: this.db
|
|
3004
3008
|
});
|
|
@@ -3181,10 +3185,7 @@ class BeanModelCache extends BeanModelCrud {
|
|
|
3181
3185
|
}
|
|
3182
3186
|
// select
|
|
3183
3187
|
const options2 = deepExtend({}, options, {
|
|
3184
|
-
columns: undefined
|
|
3185
|
-
cache: {
|
|
3186
|
-
emptyArrayAsNull: true
|
|
3187
|
-
}
|
|
3188
|
+
columns: undefined
|
|
3188
3189
|
});
|
|
3189
3190
|
const items = await this.__select_raw(table, params, options2);
|
|
3190
3191
|
return items[0];
|
|
@@ -3242,10 +3243,7 @@ class BeanModelCache extends BeanModelCrud {
|
|
|
3242
3243
|
id
|
|
3243
3244
|
}) : options?.where;
|
|
3244
3245
|
const options2 = deepExtend({}, options, {
|
|
3245
|
-
where: undefined
|
|
3246
|
-
cache: {
|
|
3247
|
-
emptyArrayAsNull: true
|
|
3248
|
-
}
|
|
3246
|
+
where: undefined
|
|
3249
3247
|
});
|
|
3250
3248
|
const items = await this.__select_raw(table, {
|
|
3251
3249
|
where,
|
|
@@ -3302,15 +3300,10 @@ class BeanModelCache extends BeanModelCrud {
|
|
|
3302
3300
|
let id = this.__checkCacheKeyValid(where, table);
|
|
3303
3301
|
if (isNil(id)) {
|
|
3304
3302
|
// check where and get id
|
|
3305
|
-
const options2 = deepExtend({}, options, {
|
|
3306
|
-
cache: {
|
|
3307
|
-
emptyArrayAsNull: true
|
|
3308
|
-
}
|
|
3309
|
-
});
|
|
3310
3303
|
const items = await this.__select_raw(table, {
|
|
3311
3304
|
where,
|
|
3312
3305
|
columns: ['id']
|
|
3313
|
-
},
|
|
3306
|
+
}, options);
|
|
3314
3307
|
if (items.length === 0) {
|
|
3315
3308
|
// donothing
|
|
3316
3309
|
return;
|
|
@@ -3337,9 +3330,10 @@ class BeanModelCache extends BeanModelCrud {
|
|
|
3337
3330
|
const item = await cache.get(id, {
|
|
3338
3331
|
get: async () => {
|
|
3339
3332
|
// where: maybe contain aux key
|
|
3340
|
-
|
|
3333
|
+
const item = await super._get(table, where, {
|
|
3341
3334
|
disableDeleted: true
|
|
3342
3335
|
});
|
|
3336
|
+
return item === undefined ? null : item;
|
|
3343
3337
|
},
|
|
3344
3338
|
db: this.db
|
|
3345
3339
|
});
|
|
@@ -3481,13 +3475,13 @@ class BeanModelCache extends BeanModelCrud {
|
|
|
3481
3475
|
if (options?.disableCacheQuery === true || options?.disableCacheQuery === false) {
|
|
3482
3476
|
return options?.disableCacheQuery;
|
|
3483
3477
|
}
|
|
3484
|
-
return !this.cacheQuery.enabled;
|
|
3478
|
+
return !(options?.cache?.enable ?? this.cacheQuery.enabled);
|
|
3485
3479
|
}
|
|
3486
3480
|
_checkDisableCacheEntityByOptions(options) {
|
|
3487
3481
|
if (options?.disableCacheEntity === true || options?.disableCacheEntity === false) {
|
|
3488
3482
|
return options?.disableCacheEntity;
|
|
3489
3483
|
}
|
|
3490
|
-
return !this.cacheEntity.enabled;
|
|
3484
|
+
return !(options?.cache?.enable ?? this.cacheEntity.enabled);
|
|
3491
3485
|
}
|
|
3492
3486
|
__checkIfOnlyKey(keys, table, noCheckLength) {
|
|
3493
3487
|
const columnId = `${table}.id`;
|
|
@@ -3736,9 +3730,7 @@ function config(_app) {
|
|
|
3736
3730
|
presetDefault: 'redis',
|
|
3737
3731
|
preset: {
|
|
3738
3732
|
redis: configRedis,
|
|
3739
|
-
|
|
3740
|
-
all: configAll,
|
|
3741
|
-
allWithIgnoreNull: configAllWithIgnoreNull
|
|
3733
|
+
all: configAll
|
|
3742
3734
|
},
|
|
3743
3735
|
redis: {
|
|
3744
3736
|
client: 'model'
|