vona-module-a-orm 5.0.46 → 5.0.48
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.
|
@@ -30,7 +30,7 @@ export declare class BeanModelMeta<TRecord extends {} = {}> extends BeanBase {
|
|
|
30
30
|
protected _prepareDisableDeletedByOptions(table: keyof ITableRecord, data: any, options?: IModelMethodOptionsGeneral, useRaw?: boolean): any;
|
|
31
31
|
protected _prepareDisableDeletedByOptionsSimple(options?: IModelMethodOptionsGeneral): boolean | undefined;
|
|
32
32
|
protected _checkIfEntityValidByDeleted(entity: any, options?: IModelMethodOptionsGeneral): boolean;
|
|
33
|
-
protected _checkDisableInstanceByOptions(
|
|
33
|
+
protected _checkDisableInstanceByOptions(_options?: IModelMethodOptionsGeneral): boolean;
|
|
34
34
|
protected _checkDisableDeletedByOptions(options?: IModelMethodOptionsGeneral): boolean;
|
|
35
35
|
protected _checkDisableCreateTimeByOptions(options?: IModelUpdateOptionsGeneral<TRecord>): boolean;
|
|
36
36
|
protected _checkDisableUpdateTimeByOptions(options?: IModelUpdateOptionsGeneral<TRecord>): boolean;
|
package/dist/config/config.d.ts
CHANGED
|
@@ -35,11 +35,13 @@ export declare function config(_app: VonaApplication): {
|
|
|
35
35
|
updateAgeOnGet?: boolean;
|
|
36
36
|
updateAgeOnHas?: boolean;
|
|
37
37
|
broadcastOnSet?: import("vona-module-a-cache").TypeBroadcastOnSet;
|
|
38
|
+
disableInstance?: boolean;
|
|
38
39
|
};
|
|
39
40
|
redis?: {
|
|
40
|
-
ttl
|
|
41
|
+
ttl?: number;
|
|
41
42
|
updateAgeOnGet?: boolean;
|
|
42
43
|
client?: keyof import("vona-module-a-redis").IRedisClientRecord;
|
|
44
|
+
disableInstance?: boolean;
|
|
43
45
|
};
|
|
44
46
|
enable?: boolean;
|
|
45
47
|
meta?: Omit<IOnionOptionsMeta, never> | undefined;
|
|
@@ -55,11 +57,13 @@ export declare function config(_app: VonaApplication): {
|
|
|
55
57
|
updateAgeOnGet?: boolean;
|
|
56
58
|
updateAgeOnHas?: boolean;
|
|
57
59
|
broadcastOnSet?: import("vona-module-a-cache").TypeBroadcastOnSet;
|
|
60
|
+
disableInstance?: boolean;
|
|
58
61
|
};
|
|
59
62
|
redis?: {
|
|
60
|
-
ttl
|
|
63
|
+
ttl?: number;
|
|
61
64
|
updateAgeOnGet?: boolean;
|
|
62
65
|
client?: keyof import("vona-module-a-redis").IRedisClientRecord;
|
|
66
|
+
disableInstance?: boolean;
|
|
63
67
|
};
|
|
64
68
|
enable?: boolean;
|
|
65
69
|
meta?: Omit<IOnionOptionsMeta, never> | undefined;
|
package/dist/index.js
CHANGED
|
@@ -1362,14 +1362,10 @@ class BeanModelMeta extends BeanBase {
|
|
|
1362
1362
|
delete data[columnNameInstance];
|
|
1363
1363
|
} else {
|
|
1364
1364
|
delete data.iid;
|
|
1365
|
-
if (!
|
|
1366
|
-
|
|
1367
|
-
} else {
|
|
1368
|
-
if (!this.ctx.instance) {
|
|
1369
|
-
throw new Error('ctx.instance not exists');
|
|
1370
|
-
}
|
|
1371
|
-
data[columnNameInstance] = this.ctx.instance.id;
|
|
1365
|
+
if (!this.ctx.instance) {
|
|
1366
|
+
throw new Error('ctx.instance not exists');
|
|
1372
1367
|
}
|
|
1368
|
+
data[columnNameInstance] = this.ctx.instance.id;
|
|
1373
1369
|
}
|
|
1374
1370
|
return data;
|
|
1375
1371
|
}
|
|
@@ -1398,8 +1394,8 @@ class BeanModelMeta extends BeanBase {
|
|
|
1398
1394
|
const deleted = this._prepareDisableDeletedByOptionsSimple(options);
|
|
1399
1395
|
return isNil(deleted) || Boolean(entity.deleted) === Boolean(deleted);
|
|
1400
1396
|
}
|
|
1401
|
-
_checkDisableInstanceByOptions(
|
|
1402
|
-
return
|
|
1397
|
+
_checkDisableInstanceByOptions(_options) {
|
|
1398
|
+
return this.disableInstance;
|
|
1403
1399
|
}
|
|
1404
1400
|
_checkDisableDeletedByOptions(options) {
|
|
1405
1401
|
if (this.disableDeleted) return true;
|
|
@@ -2092,7 +2088,7 @@ class ModelCacheBase extends BeanBase {
|
|
|
2092
2088
|
}
|
|
2093
2089
|
getName(table) {
|
|
2094
2090
|
const clientNameReal = this.$scope.orm.service.database.prepareClientNameReal(this._model.db.clientName);
|
|
2095
|
-
return `${this.$beanFullName}:${clientNameReal}:${table}:${this._cacheType}`;
|
|
2091
|
+
return `${this._model.$beanFullName}:${clientNameReal}:${table}:${this._cacheType}`;
|
|
2096
2092
|
}
|
|
2097
2093
|
get options() {
|
|
2098
2094
|
if (this[SymbolCacheOptions] === undefined) {
|
|
@@ -2128,7 +2124,11 @@ class ModelCacheBase extends BeanBase {
|
|
|
2128
2124
|
_cacheOptions = deepExtend({
|
|
2129
2125
|
enable: this.scopeOrm.config.summer.enable,
|
|
2130
2126
|
meta: this.scopeOrm.config.summer.meta,
|
|
2127
|
+
mem: {
|
|
2128
|
+
disableInstance: this._model.disableInstance
|
|
2129
|
+
},
|
|
2131
2130
|
redis: {
|
|
2131
|
+
disableInstance: this._model.disableInstance,
|
|
2132
2132
|
client: this.scopeOrm.config.summer.redis.client
|
|
2133
2133
|
}
|
|
2134
2134
|
}, configPreset, _cacheOptions, {
|
|
@@ -2364,7 +2364,12 @@ let ServiceRelations = (_dec$a = Service(), _dec2$a = BeanInfo({
|
|
|
2364
2364
|
[key]: idsFrom
|
|
2365
2365
|
}
|
|
2366
2366
|
});
|
|
2367
|
-
|
|
2367
|
+
let items;
|
|
2368
|
+
if (idsFrom.length === 0) {
|
|
2369
|
+
items = [];
|
|
2370
|
+
} else {
|
|
2371
|
+
items = await modelTarget.select(options2, methodOptionsReal);
|
|
2372
|
+
}
|
|
2368
2373
|
for (const entity of entities) {
|
|
2369
2374
|
entity[relationName] = items.find(item => {
|
|
2370
2375
|
if (item[key] === cast(entity).id) {
|
|
@@ -2438,11 +2443,16 @@ let ServiceRelations = (_dec$a = Service(), _dec2$a = BeanInfo({
|
|
|
2438
2443
|
} else if (type === 'belongsToMany') {
|
|
2439
2444
|
const modelTargetMiddle = this.__getModelTarget(modelMiddle, options?.meta?.middle);
|
|
2440
2445
|
const idsFrom = entities.map(item => cast(item).id).filter(id => !isNil(id));
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
+
let itemsMiddle;
|
|
2447
|
+
if (idsFrom.length === 0) {
|
|
2448
|
+
itemsMiddle = [];
|
|
2449
|
+
} else {
|
|
2450
|
+
itemsMiddle = await modelTargetMiddle.select({
|
|
2451
|
+
where: {
|
|
2452
|
+
[keyFrom]: idsFrom
|
|
2453
|
+
}
|
|
2454
|
+
}, methodOptionsReal);
|
|
2455
|
+
}
|
|
2446
2456
|
if (optionsReal.groups) {
|
|
2447
2457
|
for (const entity of entities) {
|
|
2448
2458
|
const idsTo = itemsMiddle.filter(item => item[keyFrom] === cast(entity).id).map(item => item[keyTo]);
|
|
@@ -2577,12 +2587,17 @@ let ServiceRelations = (_dec$a = Service(), _dec2$a = BeanInfo({
|
|
|
2577
2587
|
const entity = entities[index];
|
|
2578
2588
|
if (entity[relationName] && entity[relationName].length > 0) {
|
|
2579
2589
|
const idsTo = entity[relationName].map(item => item.id);
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2590
|
+
let itemsMiddle;
|
|
2591
|
+
if (idsTo.length === 0) {
|
|
2592
|
+
itemsMiddle = [];
|
|
2593
|
+
} else {
|
|
2594
|
+
itemsMiddle = await cast(modelTargetMiddle).__select_raw(undefined, {
|
|
2595
|
+
where: {
|
|
2596
|
+
[keyFrom]: cast(entity).id,
|
|
2597
|
+
[keyTo]: idsTo
|
|
2598
|
+
}
|
|
2599
|
+
}, methodOptionsReal);
|
|
2600
|
+
}
|
|
2586
2601
|
for (const child of entity[relationName]) {
|
|
2587
2602
|
const itemMiddle = itemsMiddle.find(item => item[keyTo] === child.id);
|
|
2588
2603
|
if (!itemMiddle) {
|
|
@@ -2835,6 +2850,7 @@ class BeanModelCache extends BeanModelCrud {
|
|
|
2835
2850
|
return result;
|
|
2836
2851
|
}
|
|
2837
2852
|
async mget(ids, options) {
|
|
2853
|
+
if (ids.length === 0) return [];
|
|
2838
2854
|
const items = await this.__mget_raw(undefined, ids, options);
|
|
2839
2855
|
return await this.relations.handleRelationsMany(items, options, options);
|
|
2840
2856
|
}
|
|
@@ -3127,7 +3143,6 @@ class BeanModelCache extends BeanModelCrud {
|
|
|
3127
3143
|
const item = await cache.get(id, {
|
|
3128
3144
|
get: async () => {
|
|
3129
3145
|
// where: maybe contain aux key
|
|
3130
|
-
// disableInstance: use the model options, not use options by outer
|
|
3131
3146
|
return await super._get(table, where, {
|
|
3132
3147
|
disableDeleted: true
|
|
3133
3148
|
});
|
package/dist/types/config.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Knex } from 'knex';
|
|
2
2
|
import type { VonaContext } from 'vona';
|
|
3
3
|
import type { IDatabaseClientDialectRecord, IDatabaseClientRecord } from './database.ts';
|
|
4
|
-
export type TypeDefaultClientNameFn = (ctx
|
|
4
|
+
export type TypeDefaultClientNameFn = (ctx?: VonaContext) => keyof IDatabaseClientRecord;
|
|
5
5
|
export type TypeDefaultClientName = TypeDefaultClientNameFn | keyof IDatabaseClientRecord;
|
|
6
6
|
export interface ConfigDatabaseClient extends Omit<Knex.Config, 'client'> {
|
|
7
7
|
client: keyof IDatabaseClientDialectRecord;
|
package/dist/types/model.d.ts
CHANGED
|
@@ -37,20 +37,18 @@ export interface IBuildModelCountParams<TRecord, _Model extends BeanModelMeta |
|
|
|
37
37
|
joins?: IModelSelectParamsJoin<TRecord, TableNames, ColumnNames>[];
|
|
38
38
|
}
|
|
39
39
|
export type IModelCountParams<TRecord, Model extends BeanModelMeta = BeanModelMeta, ModelJoins extends TypeModelsClassLikeGeneral | undefined = undefined> = IBuildModelCountParams<TRecord, Model, TypeEntityTableNamesOfGeneral<ModelJoins, Model>, TypeEntityTableColumnNamesOfGeneral<ModelJoins, Model>, TypeEntityTableColumnsOfGeneral<ModelJoins, Model>>;
|
|
40
|
-
export type IModelMethodOptions =
|
|
41
|
-
export type IModelInsertOptions<TRecord, Model extends BeanModelMeta | undefined = undefined> =
|
|
42
|
-
export type IModelUpdateOptions<TRecord, Model extends BeanModelMeta | undefined = undefined> =
|
|
43
|
-
export type IModelDeleteOptions<TRecord, Model extends BeanModelMeta | undefined = undefined> =
|
|
44
|
-
export type IModelGetOptions<TRecord, Model extends BeanModelMeta | undefined = undefined> =
|
|
45
|
-
export type IModelMutateOptions<TRecord, Model extends BeanModelMeta | undefined = undefined> =
|
|
40
|
+
export type IModelMethodOptions = IModelMethodOptionsGeneral;
|
|
41
|
+
export type IModelInsertOptions<TRecord, Model extends BeanModelMeta | undefined = undefined> = IModelInsertOptionsGeneral<TRecord, Model>;
|
|
42
|
+
export type IModelUpdateOptions<TRecord, Model extends BeanModelMeta | undefined = undefined> = IModelUpdateOptionsGeneral<TRecord, Model>;
|
|
43
|
+
export type IModelDeleteOptions<TRecord, Model extends BeanModelMeta | undefined = undefined> = IModelDeleteOptionsGeneral<TRecord, Model>;
|
|
44
|
+
export type IModelGetOptions<TRecord, Model extends BeanModelMeta | undefined = undefined> = IModelGetOptionsGeneral<TRecord, Model>;
|
|
45
|
+
export type IModelMutateOptions<TRecord, Model extends BeanModelMeta | undefined = undefined> = IModelMutateOptionsGeneral<TRecord, Model>;
|
|
46
46
|
export interface IModelMethodOptionsGeneral {
|
|
47
47
|
disableDeleted?: boolean;
|
|
48
|
-
disableInstance?: boolean;
|
|
49
48
|
disableCreateTime?: boolean;
|
|
50
49
|
disableUpdateTime?: boolean;
|
|
51
50
|
disableCacheQuery?: boolean;
|
|
52
51
|
disableCacheEntity?: boolean;
|
|
53
|
-
iid?: number;
|
|
54
52
|
deleted?: boolean;
|
|
55
53
|
}
|
|
56
54
|
export interface IModelInsertOptionsGeneral<_TRecord, Model extends BeanModelMeta | undefined = undefined> extends IModelMethodOptionsGeneral, IModelMutateRelationIncludeWrapper<Model> {
|