@common-stack/store-mongo 7.1.1-alpha.4 → 7.1.1-alpha.5
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/lib/dataloaders/bulk-dataloader-v2.d.ts +7 -0
- package/lib/dataloaders/{bulk-dataloader.js → bulk-dataloader-v2.js} +3 -3
- package/lib/dataloaders/bulk-dataloader-v2.js.map +1 -0
- package/lib/dataloaders/bulk-dataloader.d.ts +6 -4
- package/lib/dataloaders/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/interfaces/base-repository-v2.d.ts +26 -0
- package/lib/interfaces/base-repository.d.ts +15 -25
- package/lib/interfaces/base-service-v2.d.ts +21 -0
- package/lib/interfaces/base-service.d.ts +19 -18
- package/lib/interfaces/{dataloader.d.ts → dataloader-v2.d.ts} +4 -4
- package/lib/interfaces/dataloaders.d.ts +10 -0
- package/lib/interfaces/index.d.ts +4 -1
- package/lib/mixins/base-service-mixin-v2.d.ts +4 -0
- package/lib/mixins/base-service-mixin-v2.js +123 -0
- package/lib/mixins/base-service-mixin-v2.js.map +1 -0
- package/lib/mixins/base-service-mixin.d.ts +1 -1
- package/lib/mixins/base-service-mixin.js +2 -2
- package/lib/mixins/base-service-mixin.js.map +1 -1
- package/lib/mixins/index.d.ts +1 -0
- package/lib/services/base-proxy-service-v2.d.ts +28 -0
- package/lib/services/base-proxy-service-v2.js +52 -0
- package/lib/services/base-proxy-service-v2.js.map +1 -0
- package/lib/services/base-proxy-service.d.ts +17 -20
- package/lib/services/base-proxy-service.js +0 -3
- package/lib/services/base-proxy-service.js.map +1 -1
- package/lib/services/base-service-v2.d.ts +23 -0
- package/lib/services/base-service-v2.js +64 -0
- package/lib/services/base-service-v2.js.map +1 -0
- package/lib/services/base-service.d.ts +18 -19
- package/lib/services/base-service.js +11 -13
- package/lib/services/base-service.js.map +1 -1
- package/lib/services/index.d.ts +2 -0
- package/lib/store/models/common-options-v2.d.ts +16 -0
- package/lib/store/models/common-options-v2.js +40 -0
- package/lib/store/models/common-options-v2.js.map +1 -0
- package/lib/store/models/common-options.d.ts +2 -3
- package/lib/store/models/common-options.js +3 -23
- package/lib/store/models/common-options.js.map +1 -1
- package/lib/store/models/index.d.ts +1 -0
- package/lib/store/repositories/base-repository-v2.d.ts +65 -0
- package/lib/store/repositories/base-repository-v2.js +389 -0
- package/lib/store/repositories/base-repository-v2.js.map +1 -0
- package/lib/store/repositories/base-repository.d.ts +22 -58
- package/lib/store/repositories/base-repository.js +134 -276
- package/lib/store/repositories/base-repository.js.map +1 -1
- package/lib/store/repositories/index.d.ts +1 -0
- package/package.json +2 -2
- package/lib/dataloaders/bulk-dataloader.js.map +0 -1
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { FilterQuery } from 'mongoose';
|
|
2
|
+
import { GetAllArgs, IBaseRepository2 as IBaseRepository, IBaseService2 as IBaseService, AsDomainType, CreateType, UpdateType } from '../interfaces';
|
|
3
|
+
export declare class BaseService2<SchemaType> implements IBaseService<SchemaType> {
|
|
4
|
+
protected repository: IBaseRepository<SchemaType>;
|
|
5
|
+
constructor(repository: IBaseRepository<SchemaType>);
|
|
6
|
+
getAllWithCount(options: GetAllArgs<SchemaType>): Promise<{
|
|
7
|
+
data: AsDomainType<SchemaType>[];
|
|
8
|
+
totalCount: number;
|
|
9
|
+
}>;
|
|
10
|
+
count(conditions?: FilterQuery<SchemaType>): Promise<number>;
|
|
11
|
+
get(conditions: string | FilterQuery<SchemaType>): Promise<AsDomainType<SchemaType> | null>;
|
|
12
|
+
getByName(name: string): Promise<AsDomainType<SchemaType> | null>;
|
|
13
|
+
getAll(options: GetAllArgs<SchemaType>): Promise<AsDomainType<SchemaType>[]>;
|
|
14
|
+
getByIds(ids: string[]): Promise<AsDomainType<SchemaType>[]>;
|
|
15
|
+
create<T = CreateType<SchemaType>>(data: T): Promise<AsDomainType<SchemaType>>;
|
|
16
|
+
bulkCreate<T = CreateType<SchemaType>>(data: T[]): Promise<AsDomainType<SchemaType>[]>;
|
|
17
|
+
update<T = UpdateType<SchemaType>>(id: string, data: T, overwrite?: boolean): Promise<AsDomainType<SchemaType>>;
|
|
18
|
+
insert<T = CreateType<SchemaType>>(data: T & {
|
|
19
|
+
id?: string;
|
|
20
|
+
}, overwrite?: boolean): Promise<AsDomainType<SchemaType>>;
|
|
21
|
+
delete(id: string | FilterQuery<SchemaType>): Promise<boolean>;
|
|
22
|
+
bulkDelete(criteria: FilterQuery<SchemaType>): Promise<number>;
|
|
23
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import {__decorate,__metadata}from'tslib';import {injectable}from'inversify';let BaseService2 = class BaseService2 {
|
|
2
|
+
repository;
|
|
3
|
+
constructor(repository) {
|
|
4
|
+
this.repository = repository;
|
|
5
|
+
}
|
|
6
|
+
async getAllWithCount(options) {
|
|
7
|
+
return this.repository.getAllWithCount(options);
|
|
8
|
+
}
|
|
9
|
+
count(conditions) {
|
|
10
|
+
return this.repository.count(conditions);
|
|
11
|
+
}
|
|
12
|
+
get(conditions) {
|
|
13
|
+
if (typeof conditions === 'string') {
|
|
14
|
+
return this.repository.get({ id: conditions });
|
|
15
|
+
}
|
|
16
|
+
return this.repository.get(conditions);
|
|
17
|
+
}
|
|
18
|
+
getByName(name) {
|
|
19
|
+
return this.repository.get({ name });
|
|
20
|
+
}
|
|
21
|
+
getAll(options) {
|
|
22
|
+
return this.repository.getAll(options);
|
|
23
|
+
}
|
|
24
|
+
getByIds(ids) {
|
|
25
|
+
return this.repository.bulkGet(ids);
|
|
26
|
+
}
|
|
27
|
+
create(data) {
|
|
28
|
+
return this.repository.create(data);
|
|
29
|
+
}
|
|
30
|
+
bulkCreate(data) {
|
|
31
|
+
return this.repository.bulkCreate(data);
|
|
32
|
+
}
|
|
33
|
+
async update(id, data, overwrite = false) {
|
|
34
|
+
return this.repository.update({ id }, data, { overwrite });
|
|
35
|
+
}
|
|
36
|
+
async insert(data, overwrite = true) {
|
|
37
|
+
const { id, ...rest } = data;
|
|
38
|
+
if (id) {
|
|
39
|
+
try {
|
|
40
|
+
const existing = await this.repository.get({ id });
|
|
41
|
+
if (existing) {
|
|
42
|
+
return this.update(id, rest, overwrite);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
// If not found, continue to create
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return this.create(rest);
|
|
50
|
+
}
|
|
51
|
+
delete(id) {
|
|
52
|
+
if (typeof id === 'string') {
|
|
53
|
+
return this.repository.delete({ id });
|
|
54
|
+
}
|
|
55
|
+
return this.repository.delete(id);
|
|
56
|
+
}
|
|
57
|
+
bulkDelete(criteria) {
|
|
58
|
+
return this.repository.bulkDelete(criteria);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
BaseService2 = __decorate([
|
|
62
|
+
injectable(),
|
|
63
|
+
__metadata("design:paramtypes", [Object])
|
|
64
|
+
], BaseService2);export{BaseService2};//# sourceMappingURL=base-service-v2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-service-v2.js","sources":["../../src/services/base-service-v2.ts"],"sourcesContent":[null],"names":[],"mappings":"6EAgBa,IAAA,YAAY,GAAlB,MAAM,YAAY,CAAA;AACC,IAAA,UAAA,CAAA;AAAtB,IAAA,WAAA,CAAsB,UAAuC,EAAA;QAAvC,IAAU,CAAA,UAAA,GAAV,UAAU,CAA6B;KAAI;IAEjE,MAAM,eAAe,CACjB,OAA+B,EAAA;QAE/B,OAAO,IAAI,CAAC,UAAU,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;KACnD;AAED,IAAA,KAAK,CAAC,UAAoC,EAAA;QACtC,OAAO,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;KAC5C;AAED,IAAA,GAAG,CAAC,UAA4C,EAAA;AAC5C,QAAA,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE;AAChC,YAAA,OAAO,IAAI,CAAC,UAAU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AAC,EAAE,EAAE,IAAW,EAAE,SAAS,CAAC,CAAC;iBAClD;aACJ;YAAC,OAAO,KAAK,EAAE;;aAEf;SACJ;AAED,QAAA,OAAO,IAAI,CAAC,MAAM,CAAC,IAAS,CAAC,CAAC;KACjC;AAED,IAAA,MAAM,CAAC,EAAoC,EAAA;AACvC,QAAA,IAAI,OAAO,EAAE,KAAK,QAAQ,EAAE;YACxB,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,EAAE,EAAS,CAAC,CAAC;SAChD;QACD,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;KACrC;AAED,IAAA,UAAU,CAAC,QAAiC,EAAA;QACxC,OAAO,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;KAC/C;EACJ;AA9EY,YAAY,GAAA,UAAA,CAAA;AADxB,IAAA,UAAU,EAAE;;AACA,CAAA,EAAA,YAAY,CA8ExB"}
|
|
@@ -1,23 +1,22 @@
|
|
|
1
|
-
import { FilterQuery } from 'mongoose';
|
|
2
|
-
import { GetAllArgs, IBaseRepository, IBaseService
|
|
3
|
-
export declare class BaseService<
|
|
4
|
-
protected repository: IBaseRepository<
|
|
5
|
-
constructor(repository: IBaseRepository<
|
|
6
|
-
getAllWithCount(options: GetAllArgs<
|
|
7
|
-
data:
|
|
1
|
+
import { Document, FilterQuery } from 'mongoose';
|
|
2
|
+
import { GetAllArgs, IBaseRepository, IBaseService } from '../interfaces';
|
|
3
|
+
export declare class BaseService<T, C = Omit<T, 'id'>, U = C> implements IBaseService<T, C, U> {
|
|
4
|
+
protected repository: IBaseRepository<T>;
|
|
5
|
+
constructor(repository: IBaseRepository<T>);
|
|
6
|
+
getAllWithCount(options: GetAllArgs<Document<T>>): Promise<{
|
|
7
|
+
data: T[];
|
|
8
8
|
totalCount: number;
|
|
9
9
|
}>;
|
|
10
|
-
count(conditions?: FilterQuery<
|
|
11
|
-
get(conditions: string | FilterQuery<
|
|
12
|
-
getByName(name: string): Promise<
|
|
13
|
-
getAll(options: GetAllArgs<
|
|
14
|
-
getByIds(ids: string[]): Promise<
|
|
15
|
-
create
|
|
16
|
-
bulkCreate
|
|
17
|
-
update
|
|
18
|
-
insert
|
|
10
|
+
count(conditions?: FilterQuery<Document<T>>): Promise<number>;
|
|
11
|
+
get(conditions: string | FilterQuery<Document<T>>): Promise<T>;
|
|
12
|
+
getByName(name: string): Promise<T>;
|
|
13
|
+
getAll(options: GetAllArgs<Document<T>>): Promise<T[]>;
|
|
14
|
+
getByIds(ids: string[]): Promise<T[]>;
|
|
15
|
+
create(data: C): Promise<T>;
|
|
16
|
+
bulkCreate(data: C[]): Promise<T[]>;
|
|
17
|
+
update(id: string, data: Partial<U>, overwrite?: boolean): Promise<T>;
|
|
18
|
+
insert(data: (C | U) & {
|
|
19
19
|
id?: string;
|
|
20
|
-
}, overwrite?: boolean): Promise<
|
|
21
|
-
delete(id: string | FilterQuery<
|
|
22
|
-
bulkDelete(criteria: FilterQuery<SchemaType>): Promise<number>;
|
|
20
|
+
}, overwrite?: boolean): Promise<T>;
|
|
21
|
+
delete(id: string | FilterQuery<Document<T>>): Promise<boolean>;
|
|
23
22
|
}
|
|
@@ -2,9 +2,15 @@ import {__decorate,__metadata}from'tslib';import {injectable}from'inversify';let
|
|
|
2
2
|
repository;
|
|
3
3
|
constructor(repository) {
|
|
4
4
|
this.repository = repository;
|
|
5
|
+
this.repository = repository;
|
|
5
6
|
}
|
|
6
7
|
async getAllWithCount(options) {
|
|
7
|
-
|
|
8
|
+
const totalCount = await this.count(options.criteria);
|
|
9
|
+
const data = await this.getAll(options);
|
|
10
|
+
return {
|
|
11
|
+
totalCount,
|
|
12
|
+
data,
|
|
13
|
+
};
|
|
8
14
|
}
|
|
9
15
|
count(conditions) {
|
|
10
16
|
return this.repository.count(conditions);
|
|
@@ -33,17 +39,12 @@ import {__decorate,__metadata}from'tslib';import {injectable}from'inversify';let
|
|
|
33
39
|
async update(id, data, overwrite = false) {
|
|
34
40
|
return this.repository.update({ id }, data, { overwrite });
|
|
35
41
|
}
|
|
36
|
-
|
|
42
|
+
insert(data, overwrite = true) {
|
|
37
43
|
const { id, ...rest } = data;
|
|
38
44
|
if (id) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
return this.update(id, rest, overwrite);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
catch (error) {
|
|
46
|
-
// If not found, continue to create
|
|
45
|
+
const existing = this.repository.get({ id });
|
|
46
|
+
if (existing) {
|
|
47
|
+
return this.update(id, rest, overwrite);
|
|
47
48
|
}
|
|
48
49
|
}
|
|
49
50
|
return this.create(rest);
|
|
@@ -54,9 +55,6 @@ import {__decorate,__metadata}from'tslib';import {injectable}from'inversify';let
|
|
|
54
55
|
}
|
|
55
56
|
return this.repository.delete(id);
|
|
56
57
|
}
|
|
57
|
-
bulkDelete(criteria) {
|
|
58
|
-
return this.repository.bulkDelete(criteria);
|
|
59
|
-
}
|
|
60
58
|
};
|
|
61
59
|
BaseService = __decorate([
|
|
62
60
|
injectable(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-service.js","sources":["../../src/services/base-service.ts"],"sourcesContent":[null],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"base-service.js","sources":["../../src/services/base-service.ts"],"sourcesContent":[null],"names":[],"mappings":"6EAKa,IAAA,WAAW,GAAjB,MAAM,WAAW,CAAA;AACE,IAAA,UAAA,CAAA;AAAtB,IAAA,WAAA,CAAsB,UAA8B,EAAA;QAA9B,IAAU,CAAA,UAAA,GAAV,UAAU,CAAoB;AAChD,QAAA,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;KAChC;IAED,MAAM,eAAe,CAAC,OAAgC,EAAA;QAClD,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QACtD,MAAM,IAAI,GAAG,MAAM,IAAI,CAA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,EAAE,SAAS,GAAG,IAAI,EAAA;QACpD,MAAM,EAAE,EAAE,EAAE,GAAG,IAAI,EAAE,GAAG,IAAI,CAAC;QAC7B,IAAI,EAAE,EAAE;AACJ,YAAA,MAAM,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;YAC7C,IAAI,QAAQ,EAAE;gBACV,OAAO,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,IAAS,EAAE,SAAS,CAAC,CAAC;aAChD;SACJ;AACD,QAAA,OAAO,IAAI,CAAC,MAAM,CAAC,IAAS,CAAC,CAAC;KACjC;AAED,IAAA,MAAM,CAAC,EAAqC,EAAA;AACxC,QAAA,IAAI,OAAO,EAAE,KAAK,QAAQ,EAAE;YACxB,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;SACzC;QACD,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;KACrC;EACJ;AAlEY,WAAW,GAAA,UAAA,CAAA;AADvB,IAAA,UAAU,EAAE;;AACA,CAAA,EAAA,WAAW,CAkEvB"}
|
package/lib/services/index.d.ts
CHANGED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Schema } from 'mongoose';
|
|
2
|
+
export declare const commonModelSchemaOptions2: {
|
|
3
|
+
timestamps: boolean;
|
|
4
|
+
toJSON: {
|
|
5
|
+
virtuals: boolean;
|
|
6
|
+
transform(doc: any, ret: any): any;
|
|
7
|
+
};
|
|
8
|
+
toObject: {
|
|
9
|
+
virtuals: boolean;
|
|
10
|
+
getters: boolean;
|
|
11
|
+
transform(doc: any, ret: any): any;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
export declare const addIdVirtualFields2: (schema: Schema) => Schema<any, import("mongoose").Model<any, any, any, any, any>, {}, {}, {}, {}, import("mongoose").DefaultSchemaOptions, {
|
|
15
|
+
[x: string]: any;
|
|
16
|
+
}>;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
const commonModelSchemaOptions2 = {
|
|
2
|
+
timestamps: true,
|
|
3
|
+
toJSON: {
|
|
4
|
+
virtuals: true,
|
|
5
|
+
transform(doc, ret) {
|
|
6
|
+
ret.id = ret._id.toString();
|
|
7
|
+
delete ret.__v;
|
|
8
|
+
// Uncomment if you don't want _id in output
|
|
9
|
+
// delete ret._id;
|
|
10
|
+
return ret;
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
toObject: {
|
|
14
|
+
virtuals: true,
|
|
15
|
+
getters: true,
|
|
16
|
+
transform(doc, ret) {
|
|
17
|
+
ret.id = ret._id.toString();
|
|
18
|
+
delete ret.__v;
|
|
19
|
+
// Uncomment if you don't want _id in output
|
|
20
|
+
// delete ret._id;
|
|
21
|
+
return ret;
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
const addIdVirtualFields2 = (schema) => {
|
|
26
|
+
// Add id virtual getter
|
|
27
|
+
schema.virtual('id').get(function () {
|
|
28
|
+
return this._id.toHexString();
|
|
29
|
+
});
|
|
30
|
+
// Ensure virtuals are included in JSON
|
|
31
|
+
schema.set('toJSON', {
|
|
32
|
+
virtuals: true,
|
|
33
|
+
transform: (_, ret) => {
|
|
34
|
+
ret.id = ret._id.toString();
|
|
35
|
+
delete ret.__v;
|
|
36
|
+
return ret;
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
return schema;
|
|
40
|
+
};export{addIdVirtualFields2,commonModelSchemaOptions2};//# sourceMappingURL=common-options-v2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common-options-v2.js","sources":["../../../src/store/models/common-options-v2.ts"],"sourcesContent":[null],"names":[],"mappings":"AAIa,MAAA,yBAAyB,GAAG;AACrC,IAAA,UAAU,EAAE,IAAI;AAChB,IAAA,MAAM,EAAE;AACJ,QAAA,QAAQ,EAAE,IAAI;QACd,SAAS,CAAC,GAAG,EAAE,GAAG,EAAA;YACd,GAAG,CAAC,EAAE,GAAG,GAAG,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC;YAC5B,OAAO,GAAG,CAAC,GAAG,CAAC;;;AAGf,YAAA,OAAO,GAAG,CAAC;SACd;AACJ,KAAA;AACD,IAAA,QAAQ,EAAE;AACN,QAAA,QAAQ,EAAE,IAAI;AACd,QAAA,OAAO,EAAE,IAAI;QACb,SAAS,CAAC,GAAG,EAAE,GAAG,EAAA;YACd,GAAG,CAAC,EAAE,GAAG,GAAG,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC;YAC5B,OAAO,GAAG,CAAC,GAAG,CAAC;;;AAGf,YAAA,OAAO,GAAG,CAAC;SACd;AACJ,KAAA;EACH;AAEW,MAAA,mBAAmB,GAAG,CAAC,MAAc,KAAI;;AAElD,IAAA,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,YAAA;AACrB,QAAA,OAAQ,IAAI,CAAC,GAAW,CAAC,WAAW,EAAE,CAAC;AAC3C,KAAC,CAAC,CAAC;;AAGH,IAAA,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE;AACjB,QAAA,QAAQ,EAAE,IAAI;AACd,QAAA,SAAS,EAAE,CAAC,CAAC,EAAE,GAAG,KAAI;YAClB,GAAG,CAAC,EAAE,GAAG,GAAG,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC;YAC5B,OAAO,GAAG,CAAC,GAAG,CAAC;AACf,YAAA,OAAO,GAAG,CAAC;SACd;AACJ,KAAA,CAAC,CAAC;AAEH,IAAA,OAAO,MAAM,CAAC;AAClB"}
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { Schema } from 'mongoose';
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const commonModeSchemaOptions: {
|
|
3
3
|
timestamps: boolean;
|
|
4
4
|
toJSON: {
|
|
5
5
|
virtuals: boolean;
|
|
6
|
-
transform(doc: any, ret: any): any;
|
|
7
6
|
};
|
|
8
7
|
toObject: {
|
|
9
8
|
virtuals: boolean;
|
|
10
9
|
getters: boolean;
|
|
11
|
-
transform(doc: any, ret: any):
|
|
10
|
+
transform(doc: any, ret: any): void;
|
|
12
11
|
};
|
|
13
12
|
};
|
|
14
13
|
export declare const addIdVirtualFields: (schema: Schema) => Schema<any, import("mongoose").Model<any, any, any, any, any>, {}, {}, {}, {}, import("mongoose").DefaultSchemaOptions, {
|
|
@@ -1,40 +1,20 @@
|
|
|
1
|
-
const
|
|
1
|
+
const commonModeSchemaOptions = {
|
|
2
2
|
timestamps: true,
|
|
3
3
|
toJSON: {
|
|
4
4
|
virtuals: true,
|
|
5
|
-
transform(doc, ret) {
|
|
6
|
-
ret.id = ret._id.toString();
|
|
7
|
-
delete ret.__v;
|
|
8
|
-
// Uncomment if you don't want _id in output
|
|
9
|
-
// delete ret._id;
|
|
10
|
-
return ret;
|
|
11
|
-
},
|
|
12
5
|
},
|
|
13
6
|
toObject: {
|
|
14
7
|
virtuals: true,
|
|
15
8
|
getters: true,
|
|
16
9
|
transform(doc, ret) {
|
|
17
|
-
ret.id = ret._id.toString();
|
|
18
10
|
delete ret.__v;
|
|
19
|
-
|
|
20
|
-
// delete ret._id;
|
|
21
|
-
return ret;
|
|
11
|
+
delete ret._id;
|
|
22
12
|
},
|
|
23
13
|
},
|
|
24
14
|
};
|
|
25
15
|
const addIdVirtualFields = (schema) => {
|
|
26
|
-
// Add id virtual getter
|
|
27
|
-
schema.virtual('id').get(function () {
|
|
28
|
-
return this._id.toHexString();
|
|
29
|
-
});
|
|
30
|
-
// Ensure virtuals are included in JSON
|
|
31
16
|
schema.set('toJSON', {
|
|
32
17
|
virtuals: true,
|
|
33
|
-
transform: (_, ret) => {
|
|
34
|
-
ret.id = ret._id.toString();
|
|
35
|
-
delete ret.__v;
|
|
36
|
-
return ret;
|
|
37
|
-
},
|
|
38
18
|
});
|
|
39
19
|
return schema;
|
|
40
|
-
};export{addIdVirtualFields,
|
|
20
|
+
};export{addIdVirtualFields,commonModeSchemaOptions};//# sourceMappingURL=common-options.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common-options.js","sources":["../../../src/store/models/common-options.ts"],"sourcesContent":[null],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"common-options.js","sources":["../../../src/store/models/common-options.ts"],"sourcesContent":[null],"names":[],"mappings":"AAEa,MAAA,uBAAuB,GAAG;AACnC,IAAA,UAAU,EAAE,IAAI;AAChB,IAAA,MAAM,EAAE;AACJ,QAAA,QAAQ,EAAE,IAAI;AACjB,KAAA;AACD,IAAA,QAAQ,EAAE;AACN,QAAA,QAAQ,EAAE,IAAI;AACd,QAAA,OAAO,EAAE,IAAI;QACb,SAAS,CAAC,GAAG,EAAE,GAAG,EAAA;YACd,OAAO,GAAG,CAAC,GAAG,CAAC;YACf,OAAO,GAAG,CAAC,GAAG,CAAC;SAClB;AACJ,KAAA;EACH;AAEW,MAAA,kBAAkB,GAAG,CAAC,MAAc,KAAI;AACjD,IAAA,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE;AACjB,QAAA,QAAQ,EAAE,IAAI;AACjB,KAAA,CAAC,CAAC;AACH,IAAA,OAAO,MAAM,CAAC;AAClB"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { CdmLogger } from '@cdm-logger/core';
|
|
2
|
+
import { Connection, FilterQuery, Model, PipelineStage, UpdateQuery } from 'mongoose';
|
|
3
|
+
import { GetAllArgs, ISort, IBaseRepository2 as IBaseRepository, IMongoOptions, AsDomainType, CreateType, UpdateType } from '../../interfaces';
|
|
4
|
+
export declare class BaseRepository2<SchemaType> implements IBaseRepository<SchemaType> {
|
|
5
|
+
private modelFunc;
|
|
6
|
+
private options;
|
|
7
|
+
protected logger: CdmLogger.ILogger;
|
|
8
|
+
model: Model<SchemaType>;
|
|
9
|
+
constructor(modelFunc: (db: Connection) => Model<SchemaType>, db: Connection, logger: CdmLogger.ILogger, options?: IMongoOptions);
|
|
10
|
+
/**
|
|
11
|
+
* Transforms a document to the domain model format
|
|
12
|
+
*/
|
|
13
|
+
protected transformDocument(doc: any): AsDomainType<SchemaType> | null;
|
|
14
|
+
/**
|
|
15
|
+
* Transforms an array of documents
|
|
16
|
+
*/
|
|
17
|
+
protected transformDocuments(docs: SchemaType[]): AsDomainType<SchemaType>[];
|
|
18
|
+
/**
|
|
19
|
+
* Maps API criteria with 'id' to MongoDB criteria with '_id'
|
|
20
|
+
*/
|
|
21
|
+
private mapConditions;
|
|
22
|
+
/**
|
|
23
|
+
* Computes sort object from GetAllArgs sort parameter
|
|
24
|
+
* Handles both string-based and object-based sort specifications
|
|
25
|
+
*/
|
|
26
|
+
protected computeSort(sort: ISort | string | ISort[]): Record<string, 1 | -1>;
|
|
27
|
+
/**
|
|
28
|
+
* Prepares an aggregation pipeline with standard stages
|
|
29
|
+
* @param options Query options including filtering, sorting, pagination
|
|
30
|
+
* @param customPipeline Optional custom pipeline stages to include
|
|
31
|
+
* @returns Complete MongoDB aggregation pipeline
|
|
32
|
+
*/
|
|
33
|
+
protected preparePipeline(options: GetAllArgs<SchemaType>, customPipeline?: PipelineStage[]): PipelineStage[];
|
|
34
|
+
/**
|
|
35
|
+
* Execute an aggregation pipeline and transform the results
|
|
36
|
+
*/
|
|
37
|
+
protected aggregate(pipeline: PipelineStage[]): Promise<AsDomainType<SchemaType>[]>;
|
|
38
|
+
count(conditions?: FilterQuery<SchemaType>): Promise<number>;
|
|
39
|
+
get(conditions?: FilterQuery<SchemaType>, selectedFields?: string): Promise<AsDomainType<SchemaType> | null>;
|
|
40
|
+
find(conditions: Partial<FilterQuery<SchemaType>>, selectedFields?: string): Promise<AsDomainType<SchemaType> | null>;
|
|
41
|
+
getAll(options: GetAllArgs<SchemaType>): Promise<AsDomainType<SchemaType>[]>;
|
|
42
|
+
/**
|
|
43
|
+
* Get all documents using aggregation pipeline
|
|
44
|
+
*/
|
|
45
|
+
getAllWithPipeline(options: GetAllArgs<SchemaType>, customPipeline?: PipelineStage[]): Promise<AsDomainType<SchemaType>[]>;
|
|
46
|
+
getAllWithCount(options: GetAllArgs<SchemaType>): Promise<{
|
|
47
|
+
data: AsDomainType<SchemaType>[];
|
|
48
|
+
totalCount: number;
|
|
49
|
+
}>;
|
|
50
|
+
/**
|
|
51
|
+
* Get all documents with count using aggregation pipeline
|
|
52
|
+
*/
|
|
53
|
+
getAllWithCountAndPipeline(options: GetAllArgs<SchemaType>, customPipeline?: PipelineStage[]): Promise<{
|
|
54
|
+
data: AsDomainType<SchemaType>[];
|
|
55
|
+
totalCount: number;
|
|
56
|
+
}>;
|
|
57
|
+
create<T = CreateType<SchemaType>>(data: T): Promise<AsDomainType<SchemaType>>;
|
|
58
|
+
bulkCreate<T = CreateType<SchemaType>>(data: T[]): Promise<AsDomainType<SchemaType>[]>;
|
|
59
|
+
upsert<T = UpdateType<SchemaType>>(conditions: FilterQuery<SchemaType>, update: T, options?: Record<string, unknown>): Promise<AsDomainType<SchemaType>>;
|
|
60
|
+
update<T = UpdateType<SchemaType>>(criteria: FilterQuery<SchemaType>, update: T | UpdateQuery<SchemaType>, options?: Record<string, unknown>): Promise<AsDomainType<SchemaType>>;
|
|
61
|
+
bulkUpdate<T = UpdateType<SchemaType>>(criteria: FilterQuery<SchemaType>, update: T | UpdateQuery<SchemaType>, options?: Record<string, unknown>): Promise<AsDomainType<SchemaType>[]>;
|
|
62
|
+
delete(criteria: FilterQuery<SchemaType>): Promise<boolean>;
|
|
63
|
+
bulkDelete(criteria: FilterQuery<SchemaType>): Promise<number>;
|
|
64
|
+
bulkGet(ids: string[], selectedFields?: string): Promise<AsDomainType<SchemaType>[]>;
|
|
65
|
+
}
|