@smartsoft001/domain-core 1.1.91 → 2.30.0

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/README.md CHANGED
@@ -1,7 +1,5 @@
1
- # shared-domain-core
1
+ # @smartsoft001/domain-core
2
2
 
3
- This library was generated with [Nx](https://nx.dev).
3
+ ## Installation
4
4
 
5
- ## Running unit tests
6
-
7
- Run `nx test shared-domain-core` to execute the unit tests.
5
+ `npm i @smartsoft001/domain-core`
package/package.json CHANGED
@@ -1,24 +1,14 @@
1
1
  {
2
2
  "name": "@smartsoft001/domain-core",
3
- "version": "1.1.91",
3
+ "version": "2.30.0",
4
4
  "dependencies": {
5
- "@angular/common": "16.1.3",
6
- "@angular/core": "16.1.3",
7
- "@angular/platform-browser-dynamic": "16.1.3",
8
- "flatted": "^3.2.4",
9
- "guid-typescript": "1.0.9",
10
- "lodash": "^4.17.20",
11
- "md5": "2.3.0",
12
- "reflect-metadata": "0.1.13",
13
- "rxjs": "7.8.1"
14
- },
15
- "peerDependencies": {
16
- "@smartsoft001/models": "1.1.91",
17
- "@smartsoft001/users": "1.1.91",
18
- "@smartsoft001/utils": "1.1.91",
19
- "util": "0.12.5",
20
- "tslib": "2.5.3"
5
+ "tslib": "^2.3.0",
6
+ "@smartsoft001/models": "2.30.0",
7
+ "rxjs": "^7.8.1",
8
+ "@smartsoft001/users": "2.30.0"
21
9
  },
10
+ "type": "commonjs",
22
11
  "main": "./src/index.js",
12
+ "typings": "./src/index.d.ts",
23
13
  "types": "./src/index.d.ts"
24
- }
14
+ }
package/src/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../libs/shared/domain-core/src/index.ts"],"names":[],"mappings":";;;AAAA,2DAAiC;AACjC,uDAA6B;AAC7B,6DAAmC;AACnC,+DAAqC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/shared/domain-core/src/index.ts"],"names":[],"mappings":";;;AAAA,2DAAiC;AACjC,uDAA6B;AAC7B,6DAAmC;AACnC,+DAAqC"}
@@ -1,8 +1,8 @@
1
1
  export declare class DomainValidationError extends Error {
2
2
  type: typeof DomainValidationError;
3
- constructor(msg: any);
3
+ constructor(msg: string);
4
4
  }
5
5
  export declare class DomainForbiddenError extends Error {
6
6
  type: typeof DomainForbiddenError;
7
- constructor(msg: any);
7
+ constructor(msg: string);
8
8
  }
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../../../../libs/shared/domain-core/src/lib/errors.ts"],"names":[],"mappings":";;;AAAA,MAAa,qBAAsB,SAAQ,KAAK;IAG5C,YAAY,GAAG;QACX,KAAK,CAAC,GAAG,CAAC,CAAC;QAHf,SAAI,GAAG,qBAAqB,CAAC;IAI7B,CAAC;CACJ;AAND,sDAMC;AAED,MAAa,oBAAqB,SAAQ,KAAK;IAG3C,YAAY,GAAG;QACX,KAAK,CAAC,GAAG,CAAC,CAAC;QAHf,SAAI,GAAG,oBAAoB,CAAC;IAI5B,CAAC;CACJ;AAND,oDAMC"}
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../../../../packages/shared/domain-core/src/lib/errors.ts"],"names":[],"mappings":";;;AAAA,MAAa,qBAAsB,SAAQ,KAAK;IAG5C,YAAY,GAAW;QACnB,KAAK,CAAC,GAAG,CAAC,CAAC;QAHf,SAAI,GAAG,qBAAqB,CAAC;IAI7B,CAAC;CACJ;AAND,sDAMC;AAED,MAAa,oBAAqB,SAAQ,KAAK;IAG3C,YAAY,GAAW;QACnB,KAAK,CAAC,GAAG,CAAC,CAAC;QAHf,SAAI,GAAG,oBAAoB,CAAC;IAI5B,CAAC;CACJ;AAND,oDAMC"}
@@ -9,8 +9,8 @@ export interface IAddress {
9
9
  zipCode: string;
10
10
  }
11
11
  export interface IDateRange {
12
- start: string;
13
- end: string;
12
+ start: `${string}-${string}-${string}`;
13
+ end: `${string}-${string}-${string}`;
14
14
  }
15
15
  export interface IFactory<T, TConfig> {
16
16
  create(config: NonNullable<TConfig>): Promise<T>;
@@ -1 +1 @@
1
- {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../../../../libs/shared/domain-core/src/lib/interfaces.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../../../../packages/shared/domain-core/src/lib/interfaces.ts"],"names":[],"mappings":""}
@@ -1,42 +1,272 @@
1
1
  import { Observable } from "rxjs";
2
2
  import { IUser } from "@smartsoft001/users";
3
3
  import { IEntity, ISpecification } from "./interfaces";
4
+ /**
5
+ * ITransaction defines the structure of a transaction context that can be used to
6
+ * perform a series of database operations as a single atomic unit of work.
7
+ *
8
+ * @interface ITransaction
9
+ */
4
10
  export interface ITransaction {
11
+ /**
12
+ * The connection object that provides access to the database.
13
+ *
14
+ * This property typically represents the active database connection that is used
15
+ * to execute operations within the transaction. The exact type of the connection
16
+ * may vary depending on the database being used (e.g., MongoDB, SQL, etc.).
17
+ *
18
+ * @type {any}
19
+ */
5
20
  connection: any;
6
21
  }
22
+ /**
23
+ * IUnitOfWork is an abstract class that defines the contract for managing transactional operations
24
+ * across multiple repositories or services. This pattern ensures that a set of operations either
25
+ * all succeed or all fail, maintaining data consistency.
26
+ *
27
+ * @interface IUnitOfWork
28
+ */
7
29
  export declare abstract class IUnitOfWork {
30
+ /**
31
+ * Executes a set of operations within a transactional scope.
32
+ *
33
+ * @param {function(ITransaction): Promise<void>} definition - A function that contains the operations to be executed within the transaction.
34
+ * The function receives an `ITransaction` object that provides the necessary context for the transaction.
35
+ *
36
+ * @returns {Promise<void>} - A promise that resolves when the transactional operations are completed successfully.
37
+ *
38
+ * @throws {Error} - Throws an error if the transaction fails, in which case all operations are rolled back.
39
+ *
40
+ * @example
41
+ * await this.unitOfWork.scope(async (tx) => {
42
+ * await this.itemRepository.updatePartial(
43
+ * {
44
+ * id: id1,
45
+ * status: "finished",
46
+ * },
47
+ * user,
48
+ * { transaction: tx }
49
+ * );
50
+ *
51
+ * await this.itemRepository.updatePartial(
52
+ * {
53
+ * id: id2,
54
+ * status: "finished",
55
+ * },
56
+ * user,
57
+ * { transaction: tx }
58
+ * );
59
+ * });
60
+ */
8
61
  abstract scope(definition: (transaction: ITransaction) => Promise<void>): Promise<void>;
9
62
  }
63
+ /**
64
+ *
65
+ * @interface IItemRepositoryOptions
66
+ */
10
67
  export interface IItemRepositoryOptions {
11
68
  transaction: ITransaction;
12
69
  }
70
+ /**
71
+ * IItemRepository is an abstract class that defines the contract for a repository
72
+ * responsible for managing entities of type `T` in a storage system. This repository
73
+ * interface provides a set of methods for creating, updating, deleting, and querying
74
+ * entities, with support for transactional operations and various query criteria.
75
+ *
76
+ * @template T - The type of entity that this repository will manage. The entity should extend `IEntity<string>`.
77
+ *
78
+ * @interface IItemRepository
79
+ */
13
80
  export declare abstract class IItemRepository<T extends IEntity<string>> {
81
+ /**
82
+ * Creates a new entity in the storage system.
83
+ *
84
+ * @param {T} item - The entity to be created.
85
+ * @param {IUser} user - The user performing the operation.
86
+ * @param {IItemRepositoryOptions} [options] - Optional parameters for the operation, including transaction context.
87
+ *
88
+ * @returns {Promise<void>} - A promise that resolves when the entity is successfully created.
89
+ */
14
90
  abstract create(item: T, user: IUser, options?: IItemRepositoryOptions): Promise<void>;
91
+ /**
92
+ * Creates multiple entities in the storage system.
93
+ *
94
+ * @param {T[]} list - The list of entities to be created.
95
+ * @param {IUser} user - The user performing the operation.
96
+ * @param {IItemRepositoryOptions} [options] - Optional parameters for the operation, including transaction context.
97
+ *
98
+ * @returns {Promise<void>} - A promise that resolves when all entities are successfully created.
99
+ */
15
100
  abstract createMany(list: T[], user: IUser, options?: IItemRepositoryOptions): Promise<void>;
101
+ /**
102
+ * Updates an existing entity in the storage system.
103
+ *
104
+ * @param {T} item - The entity to be updated.
105
+ * @param {IUser} user - The user performing the operation.
106
+ * @param {IItemRepositoryOptions} [options] - Optional parameters for the operation, including transaction context.
107
+ *
108
+ * @returns {Promise<void>} - A promise that resolves when the entity is successfully updated.
109
+ */
16
110
  abstract update(item: T, user: IUser, options?: IItemRepositoryOptions): Promise<void>;
111
+ /**
112
+ * Partially updates an existing entity in the storage system.
113
+ *
114
+ * @param {Partial<T> & { id: string }} item - The partial entity data to be updated along with the entity's ID.
115
+ * @param {IUser} user - The user performing the operation.
116
+ * @param {IItemRepositoryOptions} [options] - Optional parameters for the operation, including transaction context.
117
+ *
118
+ * @returns {Promise<void>} - A promise that resolves when the entity is successfully updated.
119
+ */
17
120
  abstract updatePartial(item: Partial<T> & {
18
121
  id: string;
19
122
  }, user: IUser, options?: IItemRepositoryOptions): Promise<void>;
123
+ /**
124
+ * Partially updates multiple entities that match the specified criteria.
125
+ *
126
+ * @param {any} criteria - The criteria used to select the entities to be updated.
127
+ * @param {Partial<T>} set - The partial data to be set on the matching entities.
128
+ * @param {IUser} user - The user performing the operation.
129
+ * @param {IItemRepositoryOptions} [options] - Optional parameters for the operation, including transaction context.
130
+ *
131
+ * @returns {Promise<void>} - A promise that resolves when the entities are successfully updated.
132
+ */
20
133
  abstract updatePartialManyByCriteria(criteria: any, set: Partial<T>, user: IUser, options?: IItemRepositoryOptions): Promise<void>;
134
+ /**
135
+ * Partially updates multiple entities that match the specified specification.
136
+ *
137
+ * @param {ISpecification} spec - The specification used to select the entities to be updated.
138
+ * @param {Partial<T>} set - The partial data to be set on the matching entities.
139
+ * @param {IUser} user - The user performing the operation.
140
+ * @param {IItemRepositoryOptions} [options] - Optional parameters for the operation, including transaction context.
141
+ *
142
+ * @returns {Promise<void>} - A promise that resolves when the entities are successfully updated.
143
+ */
21
144
  abstract updatePartialManyBySpecification(spec: ISpecification, set: Partial<T>, user: IUser, options?: IItemRepositoryOptions): Promise<void>;
145
+ /**
146
+ * Deletes an entity from the storage system by its ID.
147
+ *
148
+ * @param {string} id - The ID of the entity to be deleted.
149
+ * @param {IUser} user - The user performing the operation.
150
+ * @param {IItemRepositoryOptions} [options] - Optional parameters for the operation, including transaction context.
151
+ *
152
+ * @returns {Promise<void>} - A promise that resolves when the entity is successfully deleted.
153
+ */
22
154
  abstract delete(id: string, user: IUser, options?: IItemRepositoryOptions): Promise<void>;
155
+ /**
156
+ * Retrieves an entity from the storage system by its ID.
157
+ *
158
+ * @param {string} id - The ID of the entity to be retrieved.
159
+ * @param {IItemRepositoryOptions} [repoOptions] - Optional parameters for the operation, including transaction context.
160
+ *
161
+ * @returns {Promise<T>} - A promise that resolves to the retrieved entity.
162
+ */
23
163
  abstract getById(id: string, repoOptions?: IItemRepositoryOptions): Promise<T>;
164
+ /**
165
+ * Retrieves entities from the storage system that match the specified criteria.
166
+ *
167
+ * @param {any} criteria - The criteria used to select the entities.
168
+ * @param {any} [options] - Optional parameters for the operation, such as pagination or sorting.
169
+ *
170
+ * @returns {Promise<{ data: T[]; totalCount: number }>} - A promise that resolves to an object containing the matching entities and the total count.
171
+ */
24
172
  abstract getByCriteria(criteria: any, options?: any): Promise<{
25
173
  data: T[];
26
174
  totalCount: number;
27
175
  }>;
176
+ /**
177
+ * Retrieves entities from the storage system that match the specified specification.
178
+ *
179
+ * @param {ISpecification} spec - The specification used to select the entities.
180
+ * @param {any} [options] - Optional parameters for the operation, such as pagination or sorting.
181
+ *
182
+ * @returns {Promise<{ data: T[]; totalCount: number }>} - A promise that resolves to an object containing the matching entities and the total count.
183
+ */
28
184
  abstract getBySpecification(spec: ISpecification, options?: any): Promise<{
29
185
  data: T[];
30
186
  totalCount: number;
31
187
  }>;
188
+ /**
189
+ * Counts the number of entities in the storage system that match the specified criteria.
190
+ *
191
+ * @param {any} criteria - The criteria used to count the entities.
192
+ *
193
+ * @returns {Promise<number>} - A promise that resolves to the count of matching entities.
194
+ */
32
195
  abstract countByCriteria(criteria: any): Promise<number>;
196
+ /**
197
+ * Counts the number of entities in the storage system that match the specified specification.
198
+ *
199
+ * @param {ISpecification} spec - The specification used to count the entities.
200
+ *
201
+ * @returns {Promise<number>} - A promise that resolves to the count of matching entities.
202
+ */
33
203
  abstract countBySpecification(spec: ISpecification): Promise<number>;
204
+ /**
205
+ * Clears all entities from the storage system.
206
+ *
207
+ * @param user
208
+ *
209
+ * @returns {Promise<void>} - A promise that resolves when the storage system is cleared.
210
+ */
34
211
  abstract clear(user: IUser | IItemRepositoryOptions): Promise<void>;
212
+ /**
213
+ * Returns an observable that emits changes to entities that match the specified criteria.
214
+ *
215
+ * @param {any} criteria - The criteria used to select the entities to observe.
216
+ *
217
+ * @returns {Observable<any>} - An observable that emits changes to the matching entities.
218
+ */
35
219
  abstract changesByCriteria(criteria: {
36
220
  id?: string;
37
221
  }): Observable<any>;
38
222
  }
223
+ /**
224
+ * IAttachmentRepository is an abstract class that defines the contract for managing file attachments
225
+ * in a storage system. This interface can be implemented to work with various storage backends, such as
226
+ * MongoDB GridFS, Amazon S3, Google Cloud Storage, or any other file storage solution.
227
+ *
228
+ * @template T - The type of the entity that this repository will manage. The entity should extend `IEntity<string>`.
229
+ *
230
+ * @interface IAttachmentRepository
231
+ */
39
232
  export declare abstract class IAttachmentRepository<T extends IEntity<string>> {
233
+ /**
234
+ * Uploads a file to the storage system.
235
+ *
236
+ * @param {Object} data - The data required to upload the file.
237
+ * @param {string} data.id - A unique identifier for the file.
238
+ * @param {string} data.fileName - The name of the file to be uploaded.
239
+ * @param {Stream} data.stream - The stream of the file to be uploaded.
240
+ * @param {string} data.mimeType - The MIME type of the file.
241
+ * @param {string} data.encoding - The encoding of the file.
242
+ *
243
+ * @param {Object} [options] - Optional parameters for the upload.
244
+ * @param {Function} [options.streamCallback] - A callback function that gets invoked with the upload stream.
245
+ *
246
+ * @returns {Promise<void>} - A promise that resolves when the upload is complete.
247
+ *
248
+ * @throws {Error} - Throws an error if the upload fails.
249
+ *
250
+ * @example
251
+ * // Example usage with MongoDB implementation:
252
+ * const repository = new MongoAttachmentRepository(config);
253
+ *
254
+ * const fileStream = fs.createReadStream('/path/to/file');
255
+ *
256
+ * await repository.upload({
257
+ * id: 'unique-file-id',
258
+ * fileName: 'example.txt',
259
+ * stream: fileStream,
260
+ * mimeType: 'text/plain',
261
+ * encoding: 'utf-8'
262
+ * }, {
263
+ * streamCallback: (writeStream) => {
264
+ * console.log('Upload started');
265
+ * }
266
+ * });
267
+ *
268
+ * console.log('File uploaded successfully');
269
+ */
40
270
  abstract upload(data: {
41
271
  id: string;
42
272
  fileName: string;
@@ -46,14 +276,45 @@ export declare abstract class IAttachmentRepository<T extends IEntity<string>> {
46
276
  }, options?: {
47
277
  streamCallback?: (r: any) => void;
48
278
  }): Promise<void>;
279
+ /**
280
+ * Retrieves metadata information about a file stored in the storage system.
281
+ *
282
+ * @param {string} id - The unique identifier of the file.
283
+ *
284
+ * @returns {Promise<{ fileName: string, contentType: string, length: number } | null>}
285
+ * - A promise that resolves to an object containing file metadata, or `null` if the file is not found.
286
+ *
287
+ * @throws {Error} - Throws an error if retrieving the file information fails.
288
+ */
49
289
  abstract getInfo(id: string): Promise<{
50
290
  fileName: string;
51
291
  contentType: string;
52
292
  length: number;
53
293
  }>;
294
+ /**
295
+ * Retrieves a stream for downloading a file from the storage system.
296
+ *
297
+ * @param {string} id - The unique identifier of the file.
298
+ * @param {Object} [options] - Optional parameters for retrieving a specific range of the file.
299
+ * @param {number} [options.start] - The starting byte position for the stream.
300
+ * @param {number} [options.end] - The ending byte position for the stream.
301
+ *
302
+ * @returns {Promise<any>} - A promise that resolves to a readable stream of the file.
303
+ *
304
+ * @throws {Error} - Throws an error if retrieving the file stream fails.
305
+ */
54
306
  abstract getStream(id: string, options?: {
55
307
  start: number;
56
308
  end: number;
57
309
  }): Promise<any>;
310
+ /**
311
+ * Deletes a file from the storage system.
312
+ *
313
+ * @param {string} id - The unique identifier of the file to be deleted.
314
+ *
315
+ * @returns {Promise<void>} - A promise that resolves when the file has been successfully deleted.
316
+ *
317
+ * @throws {Error} - Throws an error if the deletion fails.
318
+ */
58
319
  abstract delete(id: string): Promise<void>;
59
320
  }
@@ -1,13 +1,38 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.IAttachmentRepository = exports.IItemRepository = exports.IUnitOfWork = void 0;
4
- ;
4
+ /**
5
+ * IUnitOfWork is an abstract class that defines the contract for managing transactional operations
6
+ * across multiple repositories or services. This pattern ensures that a set of operations either
7
+ * all succeed or all fail, maintaining data consistency.
8
+ *
9
+ * @interface IUnitOfWork
10
+ */
5
11
  class IUnitOfWork {
6
12
  }
7
13
  exports.IUnitOfWork = IUnitOfWork;
14
+ /**
15
+ * IItemRepository is an abstract class that defines the contract for a repository
16
+ * responsible for managing entities of type `T` in a storage system. This repository
17
+ * interface provides a set of methods for creating, updating, deleting, and querying
18
+ * entities, with support for transactional operations and various query criteria.
19
+ *
20
+ * @template T - The type of entity that this repository will manage. The entity should extend `IEntity<string>`.
21
+ *
22
+ * @interface IItemRepository
23
+ */
8
24
  class IItemRepository {
9
25
  }
10
26
  exports.IItemRepository = IItemRepository;
27
+ /**
28
+ * IAttachmentRepository is an abstract class that defines the contract for managing file attachments
29
+ * in a storage system. This interface can be implemented to work with various storage backends, such as
30
+ * MongoDB GridFS, Amazon S3, Google Cloud Storage, or any other file storage solution.
31
+ *
32
+ * @template T - The type of the entity that this repository will manage. The entity should extend `IEntity<string>`.
33
+ *
34
+ * @interface IAttachmentRepository
35
+ */
11
36
  class IAttachmentRepository {
12
37
  }
13
38
  exports.IAttachmentRepository = IAttachmentRepository;
@@ -1 +1 @@
1
- {"version":3,"file":"repositories.js","sourceRoot":"","sources":["../../../../../../libs/shared/domain-core/src/lib/repositories.ts"],"names":[],"mappings":";;;AASC,CAAC;AAEF,MAAsB,WAAW;CAEhC;AAFD,kCAEC;AAOD,MAAsB,eAAe;CA8CpC;AA9CD,0CA8CC;AAED,MAAsB,qBAAqB;CAW1C;AAXD,sDAWC"}
1
+ {"version":3,"file":"repositories.js","sourceRoot":"","sources":["../../../../../../packages/shared/domain-core/src/lib/repositories.ts"],"names":[],"mappings":";;;AAyBA;;;;;;GAMG;AACH,MAAsB,WAAW;CAiChC;AAjCD,kCAiCC;AAUD;;;;;;;;;GASG;AACH,MAAsB,eAAe;CAmKpC;AAnKD,0CAmKC;AAED;;;;;;;;GAQG;AACH,MAAsB,qBAAqB;CA+E1C;AA/ED,sDA+EC"}
@@ -1,13 +1,77 @@
1
1
  import { ISpecification } from "./interfaces";
2
- export declare class MergeSpecification implements ISpecification {
3
- criteria: any;
4
- constructor(...spec: Array<ISpecification>);
2
+ /**
3
+ * BasicSpecification is a class that implements the `ISpecification` interface and serves as a base
4
+ * class for defining basic query criteria. It holds a single set of criteria that can be used to
5
+ * filter entities in a repository or database.
6
+ *
7
+ * This class can be extended to create more complex specifications by combining or modifying the
8
+ * base criteria.
9
+ *
10
+ * @class BasicSpecification
11
+ * @implements {ISpecification}
12
+ */
13
+ export declare class BasicSpecification implements ISpecification {
14
+ readonly criteria: any;
15
+ /**
16
+ * Creates an instance of BasicSpecification.
17
+ *
18
+ * @param {any} criteria - The criteria used to filter entities.
19
+ */
20
+ constructor(criteria: any);
21
+ }
22
+ /**
23
+ * MergeSpecification is a class that extends `BasicSpecification` and allows for the merging of multiple
24
+ * specifications into a single specification. The resulting specification combines the criteria of all provided
25
+ * specifications using a shallow merge.
26
+ *
27
+ * This class is useful when you need to apply multiple specifications to a query in a way that combines their criteria.
28
+ *
29
+ * @class MergeSpecification
30
+ * @extends {BasicSpecification}
31
+ */
32
+ export declare class MergeSpecification extends BasicSpecification {
33
+ /**
34
+ * Creates an instance of MergeSpecification.
35
+ *
36
+ * @param {...ISpecification[]} specs - An array of specifications to be merged.
37
+ */
38
+ constructor(...specs: Array<ISpecification>);
5
39
  }
6
- export declare class OrSpecification implements ISpecification {
7
- criteria: any;
40
+ /**
41
+ * OrSpecification is a class that extends `BasicSpecification` and allows for the combination of
42
+ * multiple specifications using a logical OR operation. The resulting specification matches entities that satisfy
43
+ * at least one of the provided specifications.
44
+ *
45
+ * This class is useful when you need to apply multiple specifications to a query in a way that matches entities
46
+ * that meet any of the specified criteria.
47
+ *
48
+ * @class OrSpecification
49
+ * @extends {BasicSpecification}
50
+ */
51
+ export declare class OrSpecification extends BasicSpecification {
52
+ /**
53
+ * Creates an instance of OrSpecification.
54
+ *
55
+ * @param {...ISpecification[]} spec - An array of specifications to be combined using a logical OR.
56
+ */
8
57
  constructor(...spec: Array<ISpecification>);
9
58
  }
10
- export declare class AndSpecification implements ISpecification {
11
- criteria: any;
59
+ /**
60
+ * AndSpecification is a class that extends `BasicSpecification` and allows for the combination of
61
+ * multiple specifications using a logical AND operation. The resulting specification matches entities that satisfy
62
+ * all the provided specifications.
63
+ *
64
+ * This class is useful when you need to apply multiple specifications to a query in a way that matches entities
65
+ * that meet all the specified criteria.
66
+ *
67
+ * @class AndSpecification
68
+ * @extends {BasicSpecification}
69
+ */
70
+ export declare class AndSpecification extends BasicSpecification {
71
+ /**
72
+ * Creates an instance of AndSpecification.
73
+ *
74
+ * @param {...ISpecification[]} spec - An array of specifications to be combined using a logical AND.
75
+ */
12
76
  constructor(...spec: Array<ISpecification>);
13
77
  }
@@ -1,28 +1,98 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AndSpecification = exports.OrSpecification = exports.MergeSpecification = void 0;
4
- class MergeSpecification {
5
- constructor(...spec) {
6
- this.criteria = {};
7
- spec.forEach(s => {
8
- this.criteria = Object.assign(Object.assign({}, this.criteria), s.criteria);
3
+ exports.AndSpecification = exports.OrSpecification = exports.MergeSpecification = exports.BasicSpecification = void 0;
4
+ /**
5
+ * BasicSpecification is a class that implements the `ISpecification` interface and serves as a base
6
+ * class for defining basic query criteria. It holds a single set of criteria that can be used to
7
+ * filter entities in a repository or database.
8
+ *
9
+ * This class can be extended to create more complex specifications by combining or modifying the
10
+ * base criteria.
11
+ *
12
+ * @class BasicSpecification
13
+ * @implements {ISpecification}
14
+ */
15
+ class BasicSpecification {
16
+ /**
17
+ * Creates an instance of BasicSpecification.
18
+ *
19
+ * @param {any} criteria - The criteria used to filter entities.
20
+ */
21
+ constructor(criteria) {
22
+ this.criteria = criteria;
23
+ }
24
+ }
25
+ exports.BasicSpecification = BasicSpecification;
26
+ /**
27
+ * MergeSpecification is a class that extends `BasicSpecification` and allows for the merging of multiple
28
+ * specifications into a single specification. The resulting specification combines the criteria of all provided
29
+ * specifications using a shallow merge.
30
+ *
31
+ * This class is useful when you need to apply multiple specifications to a query in a way that combines their criteria.
32
+ *
33
+ * @class MergeSpecification
34
+ * @extends {BasicSpecification}
35
+ */
36
+ class MergeSpecification extends BasicSpecification {
37
+ /**
38
+ * Creates an instance of MergeSpecification.
39
+ *
40
+ * @param {...ISpecification[]} specs - An array of specifications to be merged.
41
+ */
42
+ constructor(...specs) {
43
+ let criteria = {};
44
+ specs.forEach(spec => {
45
+ criteria = Object.assign(Object.assign({}, criteria), spec.criteria);
9
46
  });
47
+ super(criteria);
10
48
  }
11
49
  }
12
50
  exports.MergeSpecification = MergeSpecification;
13
- class OrSpecification {
51
+ /**
52
+ * OrSpecification is a class that extends `BasicSpecification` and allows for the combination of
53
+ * multiple specifications using a logical OR operation. The resulting specification matches entities that satisfy
54
+ * at least one of the provided specifications.
55
+ *
56
+ * This class is useful when you need to apply multiple specifications to a query in a way that matches entities
57
+ * that meet any of the specified criteria.
58
+ *
59
+ * @class OrSpecification
60
+ * @extends {BasicSpecification}
61
+ */
62
+ class OrSpecification extends BasicSpecification {
63
+ /**
64
+ * Creates an instance of OrSpecification.
65
+ *
66
+ * @param {...ISpecification[]} spec - An array of specifications to be combined using a logical OR.
67
+ */
14
68
  constructor(...spec) {
15
- this.criteria = {
69
+ super({
16
70
  $or: spec.map(c => c.criteria)
17
- };
71
+ });
18
72
  }
19
73
  }
20
74
  exports.OrSpecification = OrSpecification;
21
- class AndSpecification {
75
+ /**
76
+ * AndSpecification is a class that extends `BasicSpecification` and allows for the combination of
77
+ * multiple specifications using a logical AND operation. The resulting specification matches entities that satisfy
78
+ * all the provided specifications.
79
+ *
80
+ * This class is useful when you need to apply multiple specifications to a query in a way that matches entities
81
+ * that meet all the specified criteria.
82
+ *
83
+ * @class AndSpecification
84
+ * @extends {BasicSpecification}
85
+ */
86
+ class AndSpecification extends BasicSpecification {
87
+ /**
88
+ * Creates an instance of AndSpecification.
89
+ *
90
+ * @param {...ISpecification[]} spec - An array of specifications to be combined using a logical AND.
91
+ */
22
92
  constructor(...spec) {
23
- this.criteria = {
93
+ super({
24
94
  $and: spec.map(c => c.criteria)
25
- };
95
+ });
26
96
  }
27
97
  }
28
98
  exports.AndSpecification = AndSpecification;
@@ -1 +1 @@
1
- {"version":3,"file":"specifications.js","sourceRoot":"","sources":["../../../../../../libs/shared/domain-core/src/lib/specifications.ts"],"names":[],"mappings":";;;AAEA,MAAa,kBAAkB;IAG3B,YAAY,GAAG,IAA2B;QACtC,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;QAEnB,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE;YACd,IAAI,CAAC,QAAQ,mCACN,IAAI,CAAC,QAAQ,GACb,CAAC,CAAC,QAAQ,CAChB,CAAA;QACJ,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAbD,gDAaC;AAED,MAAa,eAAe;IAGxB,YAAY,GAAG,IAA2B;QACtC,IAAI,CAAC,QAAQ,GAAG;YACZ,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC;SACjC,CAAC;IACN,CAAC;CACJ;AARD,0CAQC;AAED,MAAa,gBAAgB;IAGzB,YAAY,GAAG,IAA2B;QACtC,IAAI,CAAC,QAAQ,GAAG;YACZ,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC;SAClC,CAAC;IACN,CAAC;CACJ;AARD,4CAQC"}
1
+ {"version":3,"file":"specifications.js","sourceRoot":"","sources":["../../../../../../packages/shared/domain-core/src/lib/specifications.ts"],"names":[],"mappings":";;;AAEA;;;;;;;;;;GAUG;AACH,MAAa,kBAAkB;IAE3B;;;;OAIG;IACH,YAA4B,QAAa;QAAb,aAAQ,GAAR,QAAQ,CAAK;IAAI,CAAC;CACjD;AARD,gDAQC;AAED;;;;;;;;;GASG;AACH,MAAa,kBAAmB,SAAQ,kBAAkB;IAEtD;;;;OAIG;IACH,YAAY,GAAG,KAA4B;QACvC,IAAI,QAAQ,GAAG,EAAE,CAAC;QAElB,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;YAClB,QAAQ,mCACD,QAAQ,GACR,IAAI,CAAC,QAAQ,CACnB,CAAA;QACJ,CAAC,CAAC,CAAC;QAEH,KAAK,CAAC,QAAQ,CAAC,CAAC;IACpB,CAAC;CACJ;AAnBD,gDAmBC;AAED;;;;;;;;;;GAUG;AACH,MAAa,eAAgB,SAAQ,kBAAkB;IAEnD;;;;OAIG;IACH,YAAY,GAAG,IAA2B;QACtC,KAAK,CAAC;YACF,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC;SACjC,CAAC,CAAC;IACP,CAAC;CACJ;AAZD,0CAYC;AAED;;;;;;;;;;GAUG;AACH,MAAa,gBAAiB,SAAQ,kBAAkB;IAEpD;;;;OAIG;IACH,YAAY,GAAG,IAA2B;QACtC,KAAK,CAAC;YACF,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC;SAClC,CAAC,CAAC;IACP,CAAC;CACJ;AAZD,4CAYC"}
package/test-setup.d.ts DELETED
File without changes
package/test-setup.js DELETED
@@ -1 +0,0 @@
1
- //# sourceMappingURL=test-setup.js.map
package/test-setup.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"test-setup.js","sourceRoot":"","sources":["../../../../libs/shared/domain-core/test-setup.ts"],"names":[],"mappings":""}