@smartsoft001/domain-core 2.45.0 → 2.46.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/.eslintrc.json CHANGED
@@ -15,16 +15,9 @@
15
15
  "rules": {}
16
16
  },
17
17
  {
18
- "files": ["*.json"],
18
+ "files": "package.json",
19
19
  "parser": "jsonc-eslint-parser",
20
- "rules": {
21
- "@nx/dependency-checks": [
22
- "error",
23
- {
24
- "ignoredFiles": ["{projectRoot}/esbuild.config.{js,ts,mjs,mts}"]
25
- }
26
- ]
27
- }
20
+ "rules": {}
28
21
  }
29
22
  ]
30
23
  }
package/README.md CHANGED
@@ -3,3 +3,450 @@
3
3
  ## Installation
4
4
 
5
5
  `npm i @smartsoft001/domain-core`
6
+
7
+ ## Repositories
8
+ ### IItemRepository
9
+ **create** - Creates a new entity in the storage system.
10
+
11
+ <table>
12
+ <thead>
13
+ <tr>
14
+ <td>Param</td>
15
+ <td>Description</td>
16
+ </tr>
17
+ </thead>
18
+ <tr>
19
+ <td>item: T</td>
20
+ <td>The entity to be created.</td>
21
+ </tr>
22
+ <tr>
23
+ <td>user: IUser</td>
24
+ <td>The user performing the operation.</td>
25
+ </tr>
26
+ <tr>
27
+ <td>options?: IItemRepositoryOptions</td>
28
+ <td>Optional parameters for the operation, including transaction context.</td>
29
+ </tr>
30
+ </table>
31
+
32
+ returns a `Promise<void>` that resolves when the entity is successfully created.
33
+
34
+ **createMany** - Creates multiple entities in the storage system.
35
+
36
+ <table>
37
+ <thead>
38
+ <tr>
39
+ <td>Param</td>
40
+ <td>Description</td>
41
+ </tr>
42
+ </thead>
43
+ <tr>
44
+ <td>list: T[]</td>
45
+ <td>The list of entities to be created.</td>
46
+ </tr>
47
+ <tr>
48
+ <td>user: IUser</td>
49
+ <td>The user performing the operation.</td>
50
+ </tr>
51
+ <tr>
52
+ <td>options?: IItemRepositoryOptions</td>
53
+ <td>Optional parameters for the operation, including transaction context.</td>
54
+ </tr>
55
+ </table>
56
+
57
+ returns a `Promise<void>` that resolves when all entities are successfully created.
58
+
59
+ **update** - Updates an existing entity in the storage system.
60
+
61
+ <table>
62
+ <thead>
63
+ <tr>
64
+ <td>Param</td>
65
+ <td>Description</td>
66
+ </tr>
67
+ </thead>
68
+ <tr>
69
+ <td>item: T</td>
70
+ <td>The entity to be updated.</td>
71
+ </tr>
72
+ <tr>
73
+ <td>user: IUser</td>
74
+ <td>The user performing the operation.</td>
75
+ </tr>
76
+ <tr>
77
+ <td>options?: IItemRepositoryOptions</td>
78
+ <td>Optional parameters for the operation, including transaction context.</td>
79
+ </tr>
80
+ </table>
81
+
82
+ returns a `Promise<void>` that resolves when the entity is successfully updated.
83
+
84
+ **updatePartial** - Partially updates an existing entity in the storage system.
85
+
86
+ <table>
87
+ <thead>
88
+ <tr>
89
+ <td>Param</td>
90
+ <td>Description</td>
91
+ </tr>
92
+ </thead>
93
+ <tr>
94
+ <td>item:
95
+
96
+ `Partial<T>& { id: string }`
97
+
98
+ </td>
99
+ <td>The partial entity data to be updated along with the entity's ID.</td>
100
+ </tr>
101
+ <tr>
102
+ <td>user: IUser</td>
103
+ <td>The user performing the operation.</td>
104
+ </tr>
105
+ <tr>
106
+ <td>options?: IItemRepositoryOptions</td>
107
+ <td>Optional parameters for the operation, including transaction context.</td>
108
+ </tr>
109
+ </table>
110
+
111
+ returns a `Promise<void>` that resolves when the entity is successfully updated.
112
+
113
+ **updatePartialManyByCriteria** - Partially updates multiple entities that match the specified criteria.
114
+
115
+ <table>
116
+ <thead>
117
+ <tr>
118
+ <td>Param</td>
119
+ <td>Description</td>
120
+ </tr>
121
+ </thead>
122
+ <tr>
123
+ <td>criteria: any</td>
124
+ <td>The criteria used to select the entities to be updated.</td>
125
+ </tr>
126
+ <tr>
127
+ <td>set:
128
+
129
+ `Partial<T>`
130
+
131
+ </td>
132
+ <td>The partial data to be set on the matching entities.</td>
133
+ </tr>
134
+ <tr>
135
+ <td>user: IUser</td>
136
+ <td>The user performing the operation.</td>
137
+ </tr>
138
+ <tr>
139
+ <td>options?: IItemRepositoryOptions</td>
140
+ <td>Optional parameters for the operation, including transaction context.</td>
141
+ </tr>
142
+ </table>
143
+
144
+ returns a `Promise<void>` that resolves when the entities are successfully updated.
145
+
146
+ **updatePartialManyBySpecification** - Partially updates multiple entities that match the specified specification.
147
+
148
+ <table>
149
+ <thead>
150
+ <tr>
151
+ <td>Param</td>
152
+ <td>Description</td>
153
+ </tr>
154
+ </thead>
155
+ <tr>
156
+ <td>spec: ISpecification</td>
157
+ <td>The specification used to select the entities to be updated.</td>
158
+ </tr>
159
+ <tr>
160
+ <td>set:
161
+
162
+ `Partial<T>`
163
+
164
+ </td>
165
+ <td>The partial data to be set on the matching entities.</td>
166
+ </tr>
167
+ <tr>
168
+ <td>user: IUser</td>
169
+ <td>The user performing the operation.</td>
170
+ </tr>
171
+ <tr>
172
+ <td>options?: IItemRepositoryOptions</td>
173
+ <td>Optional parameters for the operation, including transaction context.</td>
174
+ </tr>
175
+ </table>
176
+
177
+ returns a `Promise<void>` that resolves when the entities are successfully updated.
178
+
179
+ **delete** - Deletes an entity from the storage system by its ID.
180
+
181
+ <table>
182
+ <thead>
183
+ <tr>
184
+ <td>Param</td>
185
+ <td>Description</td>
186
+ </tr>
187
+ </thead>
188
+ <tr>
189
+ <td>id: string</td>
190
+ <td>@param {string} id - The ID of the entity to be deleted.</td>
191
+ </tr>
192
+ <tr>
193
+ <td>user: IUser</td>
194
+ <td>The user performing the operation.</td>
195
+ </tr>
196
+ <tr>
197
+ <td>options?: IItemRepositoryOptions</td>
198
+ <td>Optional parameters for the operation, including transaction context.</td>
199
+ </tr>
200
+ </table>
201
+
202
+ returns a `Promise<void>` that resolves when the entity is successfully deleted.
203
+
204
+ **getById** - Retrieves an entity from the storage system by its ID.
205
+
206
+ <table>
207
+ <thead>
208
+ <tr>
209
+ <td>Param</td>
210
+ <td>Description</td>
211
+ </tr>
212
+ </thead>
213
+ <tr>
214
+ <td>id: string</td>
215
+ <td>The ID of the entity to be deleted.</td>
216
+ </tr>
217
+ <tr>
218
+ <td>repoOptions?: IItemRepositoryOptions</td>
219
+ <td>Optional parameters for the operation, including transaction context.</td>
220
+ </tr>
221
+ </table>
222
+
223
+ returns a `Promise<T>` that resolves to the retrieved entity.
224
+
225
+ **getByCriteria** - Retrieves entities from the storage system that match the specified criteria.
226
+
227
+ <table>
228
+ <thead>
229
+ <tr>
230
+ <td>Param</td>
231
+ <td>Description</td>
232
+ </tr>
233
+ </thead>
234
+ <tr>
235
+ <td>criteria: any</td>
236
+ <td>The criteria used to select the entities.</td>
237
+ </tr>
238
+ <tr>
239
+ <td>options?: any</td>
240
+ <td>Optional parameters for the operation, such as pagination or sorting.</td>
241
+ </tr>
242
+ </table>
243
+
244
+ returns a `Promise<{ data: T[]; totalCount: number }>` that resolves to an object containing the matching entities and the total count.
245
+
246
+ **getBySpecification** - Retrieves entities from the storage system that match the specified specification.
247
+
248
+ <table>
249
+ <thead>
250
+ <tr>
251
+ <td>Param</td>
252
+ <td>Description</td>
253
+ </tr>
254
+ </thead>
255
+ <tr>
256
+ <td>spec: ISpecification</td>
257
+ <td>The specification used to select the entities.</td>
258
+ </tr>
259
+ <tr>
260
+ <td>options?: any</td>
261
+ <td>Optional parameters for the operation, such as pagination or sorting.</td>
262
+ </tr>
263
+ </table>
264
+
265
+ returns a `Promise<{ data: T[]; totalCount: number }>` that resolves to an object containing the matching entities and the total count.
266
+
267
+ **countBySpecification** - Counts the number of entities in the storage system that match the specified specification.
268
+
269
+ <table>
270
+ <thead>
271
+ <tr>
272
+ <td>Param</td>
273
+ <td>Description</td>
274
+ </tr>
275
+ </thead>
276
+ <tr>
277
+ <td>spec: ISpecification</td>
278
+ <td>The specification used to select the entities.</td>
279
+ </tr>
280
+ </table>
281
+
282
+ returns a `Promise<number>` that resolves to a count of matching entities.
283
+
284
+ **clear** - Counts the number of entities in the storage system that match the specified specification.
285
+
286
+ <table>
287
+ <thead>
288
+ <tr>
289
+ <td>Param</td>
290
+ <td>Description</td>
291
+ </tr>
292
+ </thead>
293
+ <tr>
294
+ <td>user: IUser | IItemRepositoryOptions</td>
295
+ <td>The user performing the operation.</td>
296
+ </tr>
297
+ </table>
298
+
299
+ returns a `Promise<void>` that resolves when the storage system is cleared.
300
+
301
+ **changesByCriteria** - Returns an observable that emits changes to entities that match the specified criteria.
302
+
303
+ <table>
304
+ <thead>
305
+ <tr>
306
+ <td>Param</td>
307
+ <td>Description</td>
308
+ </tr>
309
+ </thead>
310
+ <tr>
311
+ <td>criteria: any</td>
312
+ <td>The criteria used to select the entities to observe.</td>
313
+ </tr>
314
+ </table>
315
+
316
+ returns a `Observable<any>` that emits changes to the matching entities.
317
+
318
+ ### IAttachmentRepository
319
+
320
+ **upload** - Uploads a file to the storage system.
321
+
322
+ <table>
323
+ <thead>
324
+ <tr>
325
+ <td>Param</td>
326
+ <td>Description</td>
327
+ </tr>
328
+ </thead>
329
+ <tr>
330
+ <td>data: Object</td>
331
+ <td>The data required to upload the file.</td>
332
+ </tr>
333
+ <tr>
334
+ <td>data.id: string</td>
335
+ <td>A unique identifier for the file.</td>
336
+ </tr>
337
+ <tr>
338
+ <td>data.fileName: string</td>
339
+ <td>The name of the file to be uploaded.</td>
340
+ </tr>
341
+ <tr>
342
+ <td>data.stream: Stream</td>
343
+ <td>The stream of the file to be uploaded.</td>
344
+ </tr>
345
+ <tr>
346
+ <td>data.mimeType: string</td>
347
+ <td>The MIME type of the file.</td>
348
+ </tr>
349
+ <tr>
350
+ <td>data.encoding: string</td>
351
+ <td>The encoding of the file.</td>
352
+ </tr>
353
+ <tr>
354
+ <td>options?:
355
+
356
+ `{ streamCallback?: (r: any) => void }`
357
+
358
+ </td>
359
+ <td>A callback function that gets invoked with the upload stream.</td>
360
+ </tr>
361
+ </table>
362
+
363
+ returns a `Promise<void>` that when the upload is complete.
364
+ throws an error if the upload fails.
365
+
366
+ Example usage with MongoDB implementation:
367
+
368
+ ```typescript
369
+ const repository = new MongoAttachmentRepository(config);
370
+
371
+ const fileStream = fs.createReadStream('/path/to/file');
372
+
373
+ await repository.upload({
374
+ id: 'unique-file-id',
375
+ fileName: 'example.txt',
376
+ stream: fileStream,
377
+ mimeType: 'text/plain',
378
+ encoding: 'utf-8'
379
+ }, {
380
+ streamCallback: (writeStream) => {
381
+ console.log('Upload started');
382
+ }
383
+ });
384
+
385
+ console.log('File uploaded successfully');
386
+ ```
387
+
388
+ **getInfo** - Retrieves metadata information about a file stored in the storage system.
389
+
390
+ <table>
391
+ <thead>
392
+ <tr>
393
+ <td>Param</td>
394
+ <td>Description</td>
395
+ </tr>
396
+ </thead>
397
+ <tr>
398
+ <td>id: string</td>
399
+ <td>The unique identifier of the file.</td>
400
+ </tr>
401
+ </table>
402
+
403
+ returns a `Promise<{ fileName: string, contentType: string, length: number } | null>` that resolves to an object
404
+ containing file metadata, or `null` if the file is not found.
405
+
406
+ throws an error if retrieving the file information fails.
407
+
408
+ **getStream** - Retrieves a stream for downloading a file from the storage system.
409
+
410
+ <table>
411
+ <thead>
412
+ <tr>
413
+ <td>Param</td>
414
+ <td>Description</td>
415
+ </tr>
416
+ </thead>
417
+ <tr>
418
+ <td>id: string</td>
419
+ <td>The unique identifier of the file.</td>
420
+ </tr>
421
+ <tr>
422
+ <td>options?:
423
+
424
+ `{ start: number; end: number }`
425
+
426
+ </td>
427
+ <td>The starting and ending byte positions for the stream.</td>
428
+ </tr>
429
+ </table>
430
+
431
+ returns a `Promise<any>` that resolves to a readable stream of the file.
432
+
433
+ throws an error if retrieving the file stream fails.
434
+
435
+ **delete** - Deletes a file from the storage system.
436
+
437
+ <table>
438
+ <thead>
439
+ <tr>
440
+ <td>Param</td>
441
+ <td>Description</td>
442
+ </tr>
443
+ </thead>
444
+ <tr>
445
+ <td>id: string</td>
446
+ <td>The unique identifier of the file.</td>
447
+ </tr>
448
+ </table>
449
+
450
+ returns a `Promise<void>` that resolves when the file has been successfully deleted.
451
+
452
+ throws an error if the deletion fails.
package/package.json CHANGED
@@ -3,10 +3,10 @@
3
3
  "type": "commonjs",
4
4
  "dependencies": {
5
5
  "rxjs": "^7.8.1",
6
- "@smartsoft001/models": "^2.45.0",
7
- "@smartsoft001/users": "^2.45.0"
6
+ "@smartsoft001/models": "^2.46.0",
7
+ "@smartsoft001/users": "^2.46.0"
8
8
  },
9
- "version": "2.45.0",
9
+ "version": "2.46.0",
10
10
  "main": "./src/index.js",
11
11
  "typings": "./src/index.d.ts"
12
12
  }
package/project.json CHANGED
@@ -26,7 +26,14 @@
26
26
  "dependsOn": ["build"]
27
27
  },
28
28
  "lint": {
29
- "executor": "@nx/eslint:lint"
29
+ "executor": "@nx/eslint:lint",
30
+ "outputs": ["{options.outputFile}"],
31
+ "options": {
32
+ "lintFilePatterns": [
33
+ "packages/shared/domain-core/**/*.{ts,tsx,js,jsx}",
34
+ "packages/shared/domain-core/package.json"
35
+ ]
36
+ }
30
37
  },
31
38
  "test": {
32
39
  "executor": "@nx/jest:jest",
package/src/lib/errors.ts CHANGED
@@ -1,15 +1,15 @@
1
1
  export class DomainValidationError extends Error {
2
- type = DomainValidationError;
2
+ type = DomainValidationError;
3
3
 
4
- constructor(msg: string) {
5
- super(msg);
6
- }
4
+ constructor(msg: string) {
5
+ super(msg);
6
+ }
7
7
  }
8
8
 
9
9
  export class DomainForbiddenError extends Error {
10
- type = DomainForbiddenError;
10
+ type = DomainForbiddenError;
11
11
 
12
- constructor(msg: string) {
13
- super(msg);
14
- }
12
+ constructor(msg: string) {
13
+ super(msg);
14
+ }
15
15
  }
@@ -2,39 +2,39 @@
2
2
  * Interface for entities
3
3
  */
4
4
  export interface IEntity<T> {
5
- id: T;
5
+ id: T;
6
6
  }
7
7
 
8
8
  /*
9
9
  * Address interface
10
10
  */
11
11
  export interface IAddress {
12
- city: string;
13
- street: string;
14
- buildingNumber: string;
15
- flatNumber?: string;
16
- zipCode: string;
12
+ city: string;
13
+ street: string;
14
+ buildingNumber: string;
15
+ flatNumber?: string;
16
+ zipCode: string;
17
17
  }
18
18
 
19
19
  /*
20
20
  * Date range interface
21
21
  */
22
22
  export interface IDateRange {
23
- /*
24
- * YYYY-MM-DD
25
- */
26
- start: `${string}-${string}-${string}`;
27
- /*
28
- * YYYY-MM-DD
29
- */
30
- end: `${string}-${string}-${string}`;
23
+ /*
24
+ * YYYY-MM-DD
25
+ */
26
+ start: `${string}-${string}-${string}`;
27
+ /*
28
+ * YYYY-MM-DD
29
+ */
30
+ end: `${string}-${string}-${string}`;
31
31
  }
32
32
 
33
33
  /*
34
34
  * Factory interface
35
35
  */
36
36
  export interface IFactory<T, TConfig> {
37
- create(config: NonNullable<TConfig>): Promise<T>;
37
+ create(config: NonNullable<TConfig>): Promise<T>;
38
38
  }
39
39
 
40
- export { ISpecification } from "@smartsoft001/models";
40
+ export { ISpecification } from '@smartsoft001/models';
@@ -1,8 +1,7 @@
1
- import { Observable } from "rxjs";
1
+ import { IUser } from '@smartsoft001/users';
2
+ import { Observable } from 'rxjs';
2
3
 
3
- import { IUser } from "@smartsoft001/users";
4
-
5
- import { IEntity, ISpecification } from "./interfaces";
4
+ import { IEntity, ISpecification } from './interfaces';
6
5
 
7
6
  /**
8
7
  * ITransaction defines the structure of a transaction context that can be used to
@@ -62,7 +61,9 @@ export abstract class IUnitOfWork {
62
61
  * );
63
62
  * });
64
63
  */
65
- abstract scope(definition: (transaction: ITransaction) => Promise<void>): Promise<void>;
64
+ abstract scope(
65
+ definition: (transaction: ITransaction) => Promise<void>,
66
+ ): Promise<void>;
66
67
  }
67
68
 
68
69
  /**
@@ -93,7 +94,11 @@ export abstract class IItemRepository<T extends IEntity<string>> {
93
94
  *
94
95
  * @returns {Promise<void>} - A promise that resolves when the entity is successfully created.
95
96
  */
96
- abstract create(item: T, user: IUser, options?: IItemRepositoryOptions): Promise<void>;
97
+ abstract create(
98
+ item: T,
99
+ user: IUser,
100
+ options?: IItemRepositoryOptions,
101
+ ): Promise<void>;
97
102
 
98
103
  /**
99
104
  * Creates multiple entities in the storage system.
@@ -104,7 +109,11 @@ export abstract class IItemRepository<T extends IEntity<string>> {
104
109
  *
105
110
  * @returns {Promise<void>} - A promise that resolves when all entities are successfully created.
106
111
  */
107
- abstract createMany(list: T[], user: IUser, options?: IItemRepositoryOptions): Promise<void>;
112
+ abstract createMany(
113
+ list: T[],
114
+ user: IUser,
115
+ options?: IItemRepositoryOptions,
116
+ ): Promise<void>;
108
117
 
109
118
  /**
110
119
  * Updates an existing entity in the storage system.
@@ -115,7 +124,11 @@ export abstract class IItemRepository<T extends IEntity<string>> {
115
124
  *
116
125
  * @returns {Promise<void>} - A promise that resolves when the entity is successfully updated.
117
126
  */
118
- abstract update(item: T, user: IUser, options?: IItemRepositoryOptions): Promise<void>;
127
+ abstract update(
128
+ item: T,
129
+ user: IUser,
130
+ options?: IItemRepositoryOptions,
131
+ ): Promise<void>;
119
132
 
120
133
  /**
121
134
  * Partially updates an existing entity in the storage system.
@@ -128,8 +141,8 @@ export abstract class IItemRepository<T extends IEntity<string>> {
128
141
  */
129
142
  abstract updatePartial(
130
143
  item: Partial<T> & { id: string },
131
- user: IUser
132
- , options?: IItemRepositoryOptions
144
+ user: IUser,
145
+ options?: IItemRepositoryOptions,
133
146
  ): Promise<void>;
134
147
 
135
148
  /**
@@ -145,7 +158,8 @@ export abstract class IItemRepository<T extends IEntity<string>> {
145
158
  abstract updatePartialManyByCriteria(
146
159
  criteria: any,
147
160
  set: Partial<T>,
148
- user: IUser, options?: IItemRepositoryOptions
161
+ user: IUser,
162
+ options?: IItemRepositoryOptions,
149
163
  ): Promise<void>;
150
164
 
151
165
  /**
@@ -161,7 +175,8 @@ export abstract class IItemRepository<T extends IEntity<string>> {
161
175
  abstract updatePartialManyBySpecification(
162
176
  spec: ISpecification,
163
177
  set: Partial<T>,
164
- user: IUser, options?: IItemRepositoryOptions
178
+ user: IUser,
179
+ options?: IItemRepositoryOptions,
165
180
  ): Promise<void>;
166
181
 
167
182
  /**
@@ -173,7 +188,11 @@ export abstract class IItemRepository<T extends IEntity<string>> {
173
188
  *
174
189
  * @returns {Promise<void>} - A promise that resolves when the entity is successfully deleted.
175
190
  */
176
- abstract delete(id: string, user: IUser, options?: IItemRepositoryOptions): Promise<void>;
191
+ abstract delete(
192
+ id: string,
193
+ user: IUser,
194
+ options?: IItemRepositoryOptions,
195
+ ): Promise<void>;
177
196
 
178
197
  /**
179
198
  * Retrieves an entity from the storage system by its ID.
@@ -183,7 +202,10 @@ export abstract class IItemRepository<T extends IEntity<string>> {
183
202
  *
184
203
  * @returns {Promise<T>} - A promise that resolves to the retrieved entity.
185
204
  */
186
- abstract getById(id: string, repoOptions?: IItemRepositoryOptions): Promise<T>;
205
+ abstract getById(
206
+ id: string,
207
+ repoOptions?: IItemRepositoryOptions,
208
+ ): Promise<T>;
187
209
 
188
210
  /**
189
211
  * Retrieves entities from the storage system that match the specified criteria.
@@ -195,7 +217,7 @@ export abstract class IItemRepository<T extends IEntity<string>> {
195
217
  */
196
218
  abstract getByCriteria(
197
219
  criteria: any,
198
- options?: any
220
+ options?: any,
199
221
  ): Promise<{ data: T[]; totalCount: number }>;
200
222
 
201
223
  /**
@@ -208,7 +230,7 @@ export abstract class IItemRepository<T extends IEntity<string>> {
208
230
  */
209
231
  abstract getBySpecification(
210
232
  spec: ISpecification,
211
- options?: any
233
+ options?: any,
212
234
  ): Promise<{ data: T[]; totalCount: number }>;
213
235
 
214
236
  /**
@@ -296,8 +318,14 @@ export abstract class IAttachmentRepository<T extends IEntity<string>> {
296
318
  * console.log('File uploaded successfully');
297
319
  */
298
320
  abstract upload(
299
- data: { id: string, fileName: string; stream: any; mimeType: string; encoding: string },
300
- options?: { streamCallback?: (r: any) => void }
321
+ data: {
322
+ id: string;
323
+ fileName: string;
324
+ stream: any;
325
+ mimeType: string;
326
+ encoding: string;
327
+ },
328
+ options?: { streamCallback?: (r: any) => void },
301
329
  ): Promise<void>;
302
330
 
303
331
  /**
@@ -310,7 +338,9 @@ export abstract class IAttachmentRepository<T extends IEntity<string>> {
310
338
  *
311
339
  * @throws {Error} - Throws an error if retrieving the file information fails.
312
340
  */
313
- abstract getInfo(id: string): Promise<{ fileName: string, contentType: string, length: number }>;
341
+ abstract getInfo(
342
+ id: string,
343
+ ): Promise<{ fileName: string; contentType: string; length: number }>;
314
344
 
315
345
  /**
316
346
  * Retrieves a stream for downloading a file from the storage system.
@@ -324,7 +354,10 @@ export abstract class IAttachmentRepository<T extends IEntity<string>> {
324
354
  *
325
355
  * @throws {Error} - Throws an error if retrieving the file stream fails.
326
356
  */
327
- abstract getStream(id: string, options?: { start: number; end: number }): Promise<any>;
357
+ abstract getStream(
358
+ id: string,
359
+ options?: { start: number; end: number },
360
+ ): Promise<any>;
328
361
 
329
362
  /**
330
363
  * Deletes a file from the storage system.
@@ -1,69 +1,68 @@
1
- import { BasicSpecification, MergeSpecification, OrSpecification, AndSpecification } from './specifications';
2
1
  import { ISpecification } from './interfaces';
2
+ import {
3
+ BasicSpecification,
4
+ MergeSpecification,
5
+ OrSpecification,
6
+ AndSpecification,
7
+ } from './specifications';
3
8
 
4
9
  describe('shared-domain-core: BasicSpecification', () => {
5
- it('should create a BasicSpecification with the given criteria', () => {
6
- const criteria = { key: 'value' };
10
+ it('should create a BasicSpecification with the given criteria', () => {
11
+ const criteria = { key: 'value' };
7
12
 
8
- const spec = new BasicSpecification(criteria);
13
+ const spec = new BasicSpecification(criteria);
9
14
 
10
- expect(spec.criteria).toEqual(criteria);
11
- });
15
+ expect(spec.criteria).toEqual(criteria);
16
+ });
12
17
  });
13
18
 
14
19
  describe('shared-domain-core: MergeSpecification', () => {
15
- it('should merge multiple specifications into one', () => {
16
- const spec1: ISpecification = { criteria: { key1: 'value1' } };
17
- const spec2: ISpecification = { criteria: { key2: 'value2' } };
20
+ it('should merge multiple specifications into one', () => {
21
+ const spec1: ISpecification = { criteria: { key1: 'value1' } };
22
+ const spec2: ISpecification = { criteria: { key2: 'value2' } };
18
23
 
19
- const spec = new MergeSpecification(spec1, spec2);
24
+ const spec = new MergeSpecification(spec1, spec2);
20
25
 
21
- expect(spec.criteria).toEqual({
22
- key1: 'value1',
23
- key2: 'value2'
24
- });
26
+ expect(spec.criteria).toEqual({
27
+ key1: 'value1',
28
+ key2: 'value2',
25
29
  });
30
+ });
26
31
 
27
- it('should override criteria with the same key', () => {
28
- const spec1: ISpecification = { criteria: { key: 'value1' } };
29
- const spec2: ISpecification = { criteria: { key: 'value2' } };
32
+ it('should override criteria with the same key', () => {
33
+ const spec1: ISpecification = { criteria: { key: 'value1' } };
34
+ const spec2: ISpecification = { criteria: { key: 'value2' } };
30
35
 
31
- const spec = new MergeSpecification(spec1, spec2);
36
+ const spec = new MergeSpecification(spec1, spec2);
32
37
 
33
- expect(spec.criteria).toEqual({
34
- key: 'value2'
35
- });
38
+ expect(spec.criteria).toEqual({
39
+ key: 'value2',
36
40
  });
41
+ });
37
42
  });
38
43
 
39
44
  describe('shared-domain-core: OrSpecification', () => {
40
- it('should combine multiple specifications using logical OR', () => {
41
- const spec1: ISpecification = { criteria: { key1: 'value1' } };
42
- const spec2: ISpecification = { criteria: { key2: 'value2' } };
45
+ it('should combine multiple specifications using logical OR', () => {
46
+ const spec1: ISpecification = { criteria: { key1: 'value1' } };
47
+ const spec2: ISpecification = { criteria: { key2: 'value2' } };
43
48
 
44
- const spec = new OrSpecification(spec1, spec2);
49
+ const spec = new OrSpecification(spec1, spec2);
45
50
 
46
- expect(spec.criteria).toEqual({
47
- $or: [
48
- { key1: 'value1' },
49
- { key2: 'value2' }
50
- ]
51
- });
51
+ expect(spec.criteria).toEqual({
52
+ $or: [{ key1: 'value1' }, { key2: 'value2' }],
52
53
  });
54
+ });
53
55
  });
54
56
 
55
57
  describe('shared-domain-core: AndSpecification', () => {
56
- it('should combine multiple specifications using logical AND', () => {
57
- const spec1: ISpecification = { criteria: { key1: 'value1' } };
58
- const spec2: ISpecification = { criteria: { key2: 'value2' } };
59
-
60
- const spec = new AndSpecification(spec1, spec2);
58
+ it('should combine multiple specifications using logical AND', () => {
59
+ const spec1: ISpecification = { criteria: { key1: 'value1' } };
60
+ const spec2: ISpecification = { criteria: { key2: 'value2' } };
61
+
62
+ const spec = new AndSpecification(spec1, spec2);
61
63
 
62
- expect(spec.criteria).toEqual({
63
- $and: [
64
- { key1: 'value1' },
65
- { key2: 'value2' }
66
- ]
67
- });
64
+ expect(spec.criteria).toEqual({
65
+ $and: [{ key1: 'value1' }, { key2: 'value2' }],
68
66
  });
67
+ });
69
68
  });
@@ -1,4 +1,4 @@
1
- import {ISpecification} from "./interfaces";
1
+ import { ISpecification } from './interfaces';
2
2
 
3
3
  /**
4
4
  * BasicSpecification is a class that implements the `ISpecification` interface and serves as a base
@@ -12,13 +12,12 @@ import {ISpecification} from "./interfaces";
12
12
  * @implements {ISpecification}
13
13
  */
14
14
  export class BasicSpecification implements ISpecification {
15
-
16
- /**
17
- * Creates an instance of BasicSpecification.
18
- *
19
- * @param {any} criteria - The criteria used to filter entities.
20
- */
21
- constructor(public readonly criteria: any) { }
15
+ /**
16
+ * Creates an instance of BasicSpecification.
17
+ *
18
+ * @param {any} criteria - The criteria used to filter entities.
19
+ */
20
+ constructor(public readonly criteria: any) {}
22
21
  }
23
22
 
24
23
  /**
@@ -32,24 +31,23 @@ export class BasicSpecification implements ISpecification {
32
31
  * @extends {BasicSpecification}
33
32
  */
34
33
  export class MergeSpecification extends BasicSpecification {
34
+ /**
35
+ * Creates an instance of MergeSpecification.
36
+ *
37
+ * @param {...ISpecification[]} specs - An array of specifications to be merged.
38
+ */
39
+ constructor(...specs: Array<ISpecification>) {
40
+ let criteria = {};
35
41
 
36
- /**
37
- * Creates an instance of MergeSpecification.
38
- *
39
- * @param {...ISpecification[]} specs - An array of specifications to be merged.
40
- */
41
- constructor(...specs: Array<ISpecification>) {
42
- let criteria = {};
43
-
44
- specs.forEach(spec => {
45
- criteria = {
46
- ...criteria,
47
- ...spec.criteria
48
- }
49
- });
42
+ specs.forEach((spec) => {
43
+ criteria = {
44
+ ...criteria,
45
+ ...spec.criteria,
46
+ };
47
+ });
50
48
 
51
- super(criteria);
52
- }
49
+ super(criteria);
50
+ }
53
51
  }
54
52
 
55
53
  /**
@@ -64,17 +62,16 @@ export class MergeSpecification extends BasicSpecification {
64
62
  * @extends {BasicSpecification}
65
63
  */
66
64
  export class OrSpecification extends BasicSpecification {
67
-
68
- /**
69
- * Creates an instance of OrSpecification.
70
- *
71
- * @param {...ISpecification[]} spec - An array of specifications to be combined using a logical OR.
72
- */
73
- constructor(...spec: Array<ISpecification>) {
74
- super({
75
- $or: spec.map(c => c.criteria)
76
- });
77
- }
65
+ /**
66
+ * Creates an instance of OrSpecification.
67
+ *
68
+ * @param {...ISpecification[]} spec - An array of specifications to be combined using a logical OR.
69
+ */
70
+ constructor(...spec: Array<ISpecification>) {
71
+ super({
72
+ $or: spec.map((c) => c.criteria),
73
+ });
74
+ }
78
75
  }
79
76
 
80
77
  /**
@@ -89,15 +86,14 @@ export class OrSpecification extends BasicSpecification {
89
86
  * @extends {BasicSpecification}
90
87
  */
91
88
  export class AndSpecification extends BasicSpecification {
92
-
93
- /**
94
- * Creates an instance of AndSpecification.
95
- *
96
- * @param {...ISpecification[]} spec - An array of specifications to be combined using a logical AND.
97
- */
98
- constructor(...spec: Array<ISpecification>) {
99
- super({
100
- $and: spec.map(c => c.criteria)
101
- });
102
- }
89
+ /**
90
+ * Creates an instance of AndSpecification.
91
+ *
92
+ * @param {...ISpecification[]} spec - An array of specifications to be combined using a logical AND.
93
+ */
94
+ constructor(...spec: Array<ISpecification>) {
95
+ super({
96
+ $and: spec.map((c) => c.criteria),
97
+ });
98
+ }
103
99
  }