@decaf-ts/core 0.5.0 → 0.5.2
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/LICENSE.md +21 -157
- package/README.md +652 -15
- package/dist/core.cjs +2638 -1085
- package/dist/core.esm.cjs +2636 -1070
- package/lib/esm/identity/decorators.d.ts +52 -14
- package/lib/esm/identity/decorators.js +54 -16
- package/lib/esm/identity/utils.d.ts +20 -1
- package/lib/esm/identity/utils.js +22 -2
- package/lib/esm/index.d.ts +11 -15
- package/lib/esm/index.js +17 -19
- package/lib/esm/interfaces/ErrorParser.d.ts +12 -0
- package/lib/esm/interfaces/ErrorParser.js +1 -1
- package/lib/esm/interfaces/Executor.d.ts +10 -13
- package/lib/esm/interfaces/Executor.js +1 -1
- package/lib/esm/interfaces/Observable.d.ts +20 -18
- package/lib/esm/interfaces/Observable.js +1 -1
- package/lib/esm/interfaces/Observer.d.ts +7 -8
- package/lib/esm/interfaces/Observer.js +1 -1
- package/lib/esm/interfaces/Paginatable.d.ts +18 -2
- package/lib/esm/interfaces/Paginatable.js +1 -1
- package/lib/esm/interfaces/Queriable.d.ts +44 -3
- package/lib/esm/interfaces/Queriable.js +1 -1
- package/lib/esm/interfaces/RawExecutor.d.ts +10 -13
- package/lib/esm/interfaces/RawExecutor.js +1 -1
- package/lib/esm/interfaces/SequenceOptions.d.ts +50 -5
- package/lib/esm/interfaces/SequenceOptions.js +19 -1
- package/lib/esm/interfaces/index.d.ts +0 -1
- package/lib/esm/interfaces/index.js +1 -2
- package/lib/esm/model/BaseModel.d.ts +31 -0
- package/lib/esm/model/BaseModel.js +24 -1
- package/lib/esm/model/construction.d.ts +442 -9
- package/lib/esm/model/construction.js +441 -2
- package/lib/esm/model/decorators.d.ts +166 -42
- package/lib/esm/model/decorators.js +161 -37
- package/lib/esm/model/index.js +1 -2
- package/lib/esm/model/types.d.ts +9 -0
- package/lib/esm/model/types.js +1 -1
- package/lib/esm/persistence/Adapter.d.ts +384 -40
- package/lib/esm/persistence/Adapter.js +415 -59
- package/lib/esm/persistence/Dispatch.d.ts +131 -0
- package/lib/esm/persistence/Dispatch.js +187 -0
- package/lib/esm/persistence/ObserverHandler.d.ts +109 -0
- package/lib/esm/persistence/ObserverHandler.js +137 -0
- package/lib/esm/persistence/Sequence.d.ts +89 -8
- package/lib/esm/persistence/Sequence.js +91 -1
- package/lib/esm/persistence/constants.d.ts +22 -5
- package/lib/esm/persistence/constants.js +23 -7
- package/lib/esm/persistence/decorators.d.ts +10 -0
- package/lib/esm/persistence/decorators.js +11 -1
- package/lib/esm/persistence/errors.d.ts +23 -3
- package/lib/esm/persistence/errors.js +25 -7
- package/lib/esm/persistence/index.d.ts +3 -0
- package/lib/esm/persistence/index.js +4 -1
- package/lib/esm/persistence/types.d.ts +21 -0
- package/lib/esm/persistence/types.js +2 -0
- package/lib/esm/query/Condition.d.ts +88 -44
- package/lib/esm/query/Condition.js +144 -62
- package/lib/esm/query/Paginator.d.ts +67 -10
- package/lib/esm/query/Paginator.js +64 -10
- package/lib/esm/query/Statement.d.ts +82 -47
- package/lib/esm/query/Statement.js +175 -122
- package/lib/esm/query/constants.d.ts +25 -64
- package/lib/esm/query/constants.js +26 -68
- package/lib/esm/query/errors.d.ts +14 -0
- package/lib/esm/query/errors.js +15 -1
- package/lib/esm/query/index.d.ts +0 -5
- package/lib/esm/query/index.js +1 -6
- package/lib/esm/query/options.d.ts +69 -178
- package/lib/esm/query/options.js +1 -1
- package/lib/esm/query/selectors.d.ts +20 -24
- package/lib/esm/query/selectors.js +1 -1
- package/lib/esm/ram/RamAdapter.d.ts +322 -20
- package/lib/esm/ram/RamAdapter.js +360 -140
- package/lib/esm/ram/RamContext.d.ts +16 -1
- package/lib/esm/ram/RamContext.js +18 -3
- package/lib/esm/ram/RamPaginator.d.ts +51 -6
- package/lib/esm/ram/RamPaginator.js +58 -6
- package/lib/esm/ram/RamSequence.d.ts +49 -24
- package/lib/esm/ram/RamSequence.js +52 -40
- package/lib/esm/ram/RamStatement.d.ts +84 -6
- package/lib/esm/ram/RamStatement.js +175 -6
- package/lib/esm/ram/constants.d.ts +9 -0
- package/lib/esm/ram/constants.js +10 -0
- package/lib/esm/ram/handlers.d.ts +25 -0
- package/lib/esm/ram/handlers.js +27 -0
- package/lib/esm/ram/index.d.ts +4 -4
- package/lib/esm/ram/index.js +9 -5
- package/lib/esm/ram/model/RamSequence.d.ts +21 -9
- package/lib/esm/ram/model/RamSequence.js +19 -1
- package/lib/esm/ram/types.d.ts +47 -5
- package/lib/esm/ram/types.js +1 -1
- package/lib/esm/repository/Repository.d.ts +381 -22
- package/lib/esm/repository/Repository.js +446 -43
- package/lib/esm/repository/constants.d.ts +23 -13
- package/lib/esm/repository/constants.js +24 -14
- package/lib/esm/repository/decorators.d.ts +27 -0
- package/lib/esm/repository/decorators.js +28 -1
- package/lib/esm/repository/errors.d.ts +12 -11
- package/lib/esm/repository/errors.js +13 -16
- package/lib/esm/repository/injectables.d.ts +18 -0
- package/lib/esm/repository/injectables.js +19 -1
- package/lib/esm/repository/types.d.ts +13 -1
- package/lib/esm/repository/types.js +1 -1
- package/lib/esm/repository/utils.d.ts +11 -0
- package/lib/esm/repository/utils.js +12 -1
- package/lib/esm/utils/decorators.d.ts +9 -0
- package/lib/esm/utils/decorators.js +19 -0
- package/lib/esm/utils/errors.d.ts +56 -0
- package/lib/esm/utils/errors.js +63 -0
- package/lib/esm/utils/index.d.ts +2 -0
- package/lib/esm/utils/index.js +3 -0
- package/lib/identity/decorators.cjs +54 -16
- package/lib/identity/decorators.d.ts +52 -14
- package/lib/identity/utils.cjs +22 -2
- package/lib/identity/utils.d.ts +20 -1
- package/lib/index.cjs +17 -19
- package/lib/index.d.ts +11 -15
- package/lib/interfaces/ErrorParser.cjs +1 -1
- package/lib/interfaces/ErrorParser.d.ts +12 -0
- package/lib/interfaces/Executor.cjs +1 -1
- package/lib/interfaces/Executor.d.ts +10 -13
- package/lib/interfaces/Observable.cjs +1 -1
- package/lib/interfaces/Observable.d.ts +20 -18
- package/lib/interfaces/Observer.cjs +1 -1
- package/lib/interfaces/Observer.d.ts +7 -8
- package/lib/interfaces/Paginatable.cjs +1 -1
- package/lib/interfaces/Paginatable.d.ts +18 -2
- package/lib/interfaces/Queriable.cjs +1 -1
- package/lib/interfaces/Queriable.d.ts +44 -3
- package/lib/interfaces/RawExecutor.cjs +1 -1
- package/lib/interfaces/RawExecutor.d.ts +10 -13
- package/lib/interfaces/SequenceOptions.cjs +19 -1
- package/lib/interfaces/SequenceOptions.d.ts +50 -5
- package/lib/interfaces/index.cjs +1 -2
- package/lib/interfaces/index.d.ts +0 -1
- package/lib/model/BaseModel.cjs +24 -1
- package/lib/model/BaseModel.d.ts +31 -0
- package/lib/model/construction.cjs +441 -2
- package/lib/model/construction.d.ts +442 -9
- package/lib/model/decorators.cjs +161 -37
- package/lib/model/decorators.d.ts +166 -42
- package/lib/model/index.cjs +1 -2
- package/lib/model/types.cjs +1 -1
- package/lib/model/types.d.ts +9 -0
- package/lib/persistence/Adapter.cjs +414 -58
- package/lib/persistence/Adapter.d.ts +384 -40
- package/lib/persistence/Dispatch.cjs +191 -0
- package/lib/persistence/Dispatch.d.ts +131 -0
- package/lib/persistence/ObserverHandler.cjs +141 -0
- package/lib/persistence/ObserverHandler.d.ts +109 -0
- package/lib/persistence/Sequence.cjs +91 -1
- package/lib/persistence/Sequence.d.ts +89 -8
- package/lib/persistence/constants.cjs +24 -8
- package/lib/persistence/constants.d.ts +22 -5
- package/lib/persistence/decorators.cjs +11 -1
- package/lib/persistence/decorators.d.ts +10 -0
- package/lib/persistence/errors.cjs +26 -9
- package/lib/persistence/errors.d.ts +23 -3
- package/lib/persistence/index.cjs +4 -1
- package/lib/persistence/index.d.ts +3 -0
- package/lib/persistence/types.cjs +3 -0
- package/lib/persistence/types.d.ts +21 -0
- package/lib/query/Condition.cjs +143 -61
- package/lib/query/Condition.d.ts +88 -44
- package/lib/query/Paginator.cjs +64 -10
- package/lib/query/Paginator.d.ts +67 -10
- package/lib/query/Statement.cjs +174 -121
- package/lib/query/Statement.d.ts +82 -47
- package/lib/query/constants.cjs +27 -69
- package/lib/query/constants.d.ts +25 -64
- package/lib/query/errors.cjs +15 -1
- package/lib/query/errors.d.ts +14 -0
- package/lib/query/index.cjs +1 -6
- package/lib/query/index.d.ts +0 -5
- package/lib/query/options.cjs +1 -1
- package/lib/query/options.d.ts +69 -178
- package/lib/query/selectors.cjs +1 -1
- package/lib/query/selectors.d.ts +20 -24
- package/lib/ram/RamAdapter.cjs +358 -172
- package/lib/ram/RamAdapter.d.ts +322 -20
- package/lib/ram/RamContext.cjs +18 -3
- package/lib/ram/RamContext.d.ts +16 -1
- package/lib/ram/RamPaginator.cjs +58 -6
- package/lib/ram/RamPaginator.d.ts +51 -6
- package/lib/ram/RamSequence.cjs +52 -41
- package/lib/ram/RamSequence.d.ts +49 -24
- package/lib/ram/RamStatement.cjs +175 -6
- package/lib/ram/RamStatement.d.ts +84 -6
- package/lib/ram/constants.cjs +13 -0
- package/lib/ram/constants.d.ts +9 -0
- package/lib/ram/handlers.cjs +30 -0
- package/lib/ram/handlers.d.ts +25 -0
- package/lib/ram/index.cjs +9 -5
- package/lib/ram/index.d.ts +4 -4
- package/lib/ram/model/RamSequence.cjs +19 -1
- package/lib/ram/model/RamSequence.d.ts +21 -9
- package/lib/ram/types.cjs +1 -1
- package/lib/ram/types.d.ts +47 -5
- package/lib/repository/Repository.cjs +445 -42
- package/lib/repository/Repository.d.ts +381 -22
- package/lib/repository/constants.cjs +24 -14
- package/lib/repository/constants.d.ts +23 -13
- package/lib/repository/decorators.cjs +28 -1
- package/lib/repository/decorators.d.ts +27 -0
- package/lib/repository/errors.cjs +14 -19
- package/lib/repository/errors.d.ts +12 -11
- package/lib/repository/injectables.cjs +19 -1
- package/lib/repository/injectables.d.ts +18 -0
- package/lib/repository/types.cjs +1 -1
- package/lib/repository/types.d.ts +13 -1
- package/lib/repository/utils.cjs +12 -1
- package/lib/repository/utils.d.ts +11 -0
- package/lib/utils/decorators.cjs +22 -0
- package/lib/utils/decorators.d.ts +9 -0
- package/lib/utils/errors.cjs +69 -0
- package/lib/utils/errors.d.ts +56 -0
- package/lib/{validators → utils}/index.cjs +2 -2
- package/lib/utils/index.d.ts +2 -0
- package/package.json +5 -5
- package/lib/esm/interfaces/Builder.d.ts +0 -16
- package/lib/esm/interfaces/Builder.js +0 -2
- package/lib/esm/model/IdentifiedBaseModel.d.ts +0 -7
- package/lib/esm/model/IdentifiedBaseModel.js +0 -25
- package/lib/esm/query/Clause.d.ts +0 -50
- package/lib/esm/query/Clause.js +0 -82
- package/lib/esm/query/ClauseFactory.d.ts +0 -71
- package/lib/esm/query/ClauseFactory.js +0 -6
- package/lib/esm/query/Query.d.ts +0 -43
- package/lib/esm/query/Query.js +0 -54
- package/lib/esm/query/clauses/FromClause.d.ts +0 -45
- package/lib/esm/query/clauses/FromClause.js +0 -59
- package/lib/esm/query/clauses/GroupByClause.d.ts +0 -21
- package/lib/esm/query/clauses/GroupByClause.js +0 -19
- package/lib/esm/query/clauses/InsertClause.d.ts +0 -37
- package/lib/esm/query/clauses/InsertClause.js +0 -55
- package/lib/esm/query/clauses/LimitClause.d.ts +0 -29
- package/lib/esm/query/clauses/LimitClause.js +0 -27
- package/lib/esm/query/clauses/OffsetClause.d.ts +0 -21
- package/lib/esm/query/clauses/OffsetClause.js +0 -19
- package/lib/esm/query/clauses/OrderByClause.d.ts +0 -37
- package/lib/esm/query/clauses/OrderByClause.js +0 -39
- package/lib/esm/query/clauses/SelectClause.d.ts +0 -47
- package/lib/esm/query/clauses/SelectClause.js +0 -62
- package/lib/esm/query/clauses/SelectorBasedClause.d.ts +0 -25
- package/lib/esm/query/clauses/SelectorBasedClause.js +0 -44
- package/lib/esm/query/clauses/ValuesClause.d.ts +0 -21
- package/lib/esm/query/clauses/ValuesClause.js +0 -36
- package/lib/esm/query/clauses/WhereClause.d.ts +0 -46
- package/lib/esm/query/clauses/WhereClause.js +0 -71
- package/lib/esm/query/clauses/index.d.ts +0 -10
- package/lib/esm/query/clauses/index.js +0 -11
- package/lib/esm/query/types.d.ts +0 -2
- package/lib/esm/query/types.js +0 -2
- package/lib/esm/ram/RamClauseFactory.d.ts +0 -17
- package/lib/esm/ram/RamClauseFactory.js +0 -92
- package/lib/esm/ram/clauses/FromClause.d.ts +0 -7
- package/lib/esm/ram/clauses/FromClause.js +0 -11
- package/lib/esm/ram/clauses/InsertClause.d.ts +0 -7
- package/lib/esm/ram/clauses/InsertClause.js +0 -13
- package/lib/esm/ram/clauses/OrderByClause.d.ts +0 -7
- package/lib/esm/ram/clauses/OrderByClause.js +0 -39
- package/lib/esm/ram/clauses/SelectClause.d.ts +0 -7
- package/lib/esm/ram/clauses/SelectClause.js +0 -16
- package/lib/esm/ram/clauses/ValuesClause.d.ts +0 -7
- package/lib/esm/ram/clauses/ValuesClause.js +0 -12
- package/lib/esm/ram/clauses/WhereClause.d.ts +0 -7
- package/lib/esm/ram/clauses/WhereClause.js +0 -11
- package/lib/esm/ram/clauses/index.d.ts +0 -6
- package/lib/esm/ram/clauses/index.js +0 -7
- package/lib/esm/validators/ClauseSequenceValidator.d.ts +0 -28
- package/lib/esm/validators/ClauseSequenceValidator.js +0 -95
- package/lib/esm/validators/decorators.d.ts +0 -10
- package/lib/esm/validators/decorators.js +0 -24
- package/lib/esm/validators/index.d.ts +0 -2
- package/lib/esm/validators/index.js +0 -3
- package/lib/interfaces/Builder.cjs +0 -3
- package/lib/interfaces/Builder.d.ts +0 -16
- package/lib/model/IdentifiedBaseModel.cjs +0 -29
- package/lib/model/IdentifiedBaseModel.d.ts +0 -7
- package/lib/query/Clause.cjs +0 -86
- package/lib/query/Clause.d.ts +0 -50
- package/lib/query/ClauseFactory.cjs +0 -10
- package/lib/query/ClauseFactory.d.ts +0 -71
- package/lib/query/Query.cjs +0 -58
- package/lib/query/Query.d.ts +0 -43
- package/lib/query/clauses/FromClause.cjs +0 -63
- package/lib/query/clauses/FromClause.d.ts +0 -45
- package/lib/query/clauses/GroupByClause.cjs +0 -23
- package/lib/query/clauses/GroupByClause.d.ts +0 -21
- package/lib/query/clauses/InsertClause.cjs +0 -59
- package/lib/query/clauses/InsertClause.d.ts +0 -37
- package/lib/query/clauses/LimitClause.cjs +0 -31
- package/lib/query/clauses/LimitClause.d.ts +0 -29
- package/lib/query/clauses/OffsetClause.cjs +0 -23
- package/lib/query/clauses/OffsetClause.d.ts +0 -21
- package/lib/query/clauses/OrderByClause.cjs +0 -43
- package/lib/query/clauses/OrderByClause.d.ts +0 -37
- package/lib/query/clauses/SelectClause.cjs +0 -66
- package/lib/query/clauses/SelectClause.d.ts +0 -47
- package/lib/query/clauses/SelectorBasedClause.cjs +0 -48
- package/lib/query/clauses/SelectorBasedClause.d.ts +0 -25
- package/lib/query/clauses/ValuesClause.cjs +0 -40
- package/lib/query/clauses/ValuesClause.d.ts +0 -21
- package/lib/query/clauses/WhereClause.cjs +0 -75
- package/lib/query/clauses/WhereClause.d.ts +0 -46
- package/lib/query/clauses/index.cjs +0 -27
- package/lib/query/clauses/index.d.ts +0 -10
- package/lib/query/types.cjs +0 -3
- package/lib/query/types.d.ts +0 -2
- package/lib/ram/RamClauseFactory.cjs +0 -96
- package/lib/ram/RamClauseFactory.d.ts +0 -17
- package/lib/ram/clauses/FromClause.cjs +0 -15
- package/lib/ram/clauses/FromClause.d.ts +0 -7
- package/lib/ram/clauses/InsertClause.cjs +0 -17
- package/lib/ram/clauses/InsertClause.d.ts +0 -7
- package/lib/ram/clauses/OrderByClause.cjs +0 -43
- package/lib/ram/clauses/OrderByClause.d.ts +0 -7
- package/lib/ram/clauses/SelectClause.cjs +0 -20
- package/lib/ram/clauses/SelectClause.d.ts +0 -7
- package/lib/ram/clauses/ValuesClause.cjs +0 -16
- package/lib/ram/clauses/ValuesClause.d.ts +0 -7
- package/lib/ram/clauses/WhereClause.cjs +0 -15
- package/lib/ram/clauses/WhereClause.d.ts +0 -7
- package/lib/ram/clauses/index.cjs +0 -23
- package/lib/ram/clauses/index.d.ts +0 -6
- package/lib/validators/ClauseSequenceValidator.cjs +0 -98
- package/lib/validators/ClauseSequenceValidator.d.ts +0 -28
- package/lib/validators/decorators.cjs +0 -27
- package/lib/validators/decorators.d.ts +0 -10
- package/lib/validators/index.d.ts +0 -2
@@ -1,6 +1,6 @@
|
|
1
|
-
import { Context, IRepository, Repository as Rep, RepositoryFlags } from "@decaf-ts/db-decorators";
|
1
|
+
import { BulkCrudOperationKeys, Context, IRepository, OperationKeys, Repository as Rep, RepositoryFlags } from "@decaf-ts/db-decorators";
|
2
2
|
import { Observable } from "../interfaces/Observable";
|
3
|
-
import { Observer } from "../interfaces/Observer";
|
3
|
+
import { type Observer } from "../interfaces/Observer";
|
4
4
|
import { Adapter } from "../persistence/Adapter";
|
5
5
|
import { Constructor, Model } from "@decaf-ts/decorator-validation";
|
6
6
|
import { OrderDirection } from "./constants";
|
@@ -10,64 +10,423 @@ import { IndexMetadata } from "./types";
|
|
10
10
|
import { Condition } from "../query/Condition";
|
11
11
|
import { WhereOption } from "../query/options";
|
12
12
|
import { SelectSelector } from "../query/selectors";
|
13
|
-
|
14
|
-
|
13
|
+
import { Logger } from "@decaf-ts/logging";
|
14
|
+
import { ObserverHandler } from "../persistence/ObserverHandler";
|
15
|
+
import type { EventIds, ObserverFilter } from "../persistence";
|
16
|
+
/**
|
17
|
+
* @description Type alias for Repository class with simplified generic parameters.
|
18
|
+
* @summary Provides a more concise way to reference the Repository class with its generic parameters.
|
19
|
+
* @template M - The model type that extends Model.
|
20
|
+
* @template F - The repository flags type.
|
21
|
+
* @template C - The context type.
|
22
|
+
* @template Q - The query type.
|
23
|
+
* @template A - The adapter type.
|
24
|
+
* @typedef Repo
|
25
|
+
* @memberOf module:core
|
26
|
+
*/
|
27
|
+
export type Repo<M extends Model, F extends RepositoryFlags = any, C extends Context<F> = any, Q = any, A extends Adapter<any, Q, F, C> = any> = Repository<M, Q, A, F, C>;
|
28
|
+
/**
|
29
|
+
* @description Core repository implementation for database operations on models on a table by table way.
|
30
|
+
* @summary Provides CRUD operations, querying capabilities, and observer pattern implementation for model persistence.
|
31
|
+
* @template M - The model type that extends Model.
|
32
|
+
* @template Q - The query type used by the adapter.
|
33
|
+
* @template A - The adapter type for database operations.
|
34
|
+
* @template F - The repository flags type.
|
35
|
+
* @template C - The context type for operations.
|
36
|
+
* @param {A} [adapter] - Optional adapter instance for database operations.
|
37
|
+
* @param {Constructor<M>} [clazz] - Optional constructor for the model class.
|
38
|
+
* @param {...any[]} [args] - Additional arguments for repository initialization.
|
39
|
+
* @class Repository
|
40
|
+
* @example
|
41
|
+
* // Creating a repository for User model
|
42
|
+
* const userRepo = Repository.forModel(User);
|
43
|
+
*
|
44
|
+
* // Using the repository for CRUD operations
|
45
|
+
* const user = await userRepo.create(new User({ name: 'John' }));
|
46
|
+
* const retrievedUser = await userRepo.read(user.id);
|
47
|
+
* user.name = 'Jane';
|
48
|
+
* await userRepo.update(user);
|
49
|
+
* await userRepo.delete(user.id);
|
50
|
+
*
|
51
|
+
* // Querying with conditions
|
52
|
+
* const users = await userRepo
|
53
|
+
* .select()
|
54
|
+
* .where({ name: 'Jane' })
|
55
|
+
* .orderBy('createdAt', OrderDirection.DSC)
|
56
|
+
* .limit(10)
|
57
|
+
* .execute();
|
58
|
+
* @mermaid
|
59
|
+
* sequenceDiagram
|
60
|
+
* participant C as Client Code
|
61
|
+
* participant R as Repository
|
62
|
+
* participant A as Adapter
|
63
|
+
* participant DB as Database
|
64
|
+
* participant O as Observers
|
65
|
+
*
|
66
|
+
* C->>+R: create(model)
|
67
|
+
* R->>R: createPrefix(model)
|
68
|
+
* R->>+A: prepare(model)
|
69
|
+
* A-->>-R: prepared data
|
70
|
+
* R->>+A: create(table, id, record)
|
71
|
+
* A->>+DB: Insert Operation
|
72
|
+
* DB-->>-A: Result
|
73
|
+
* A-->>-R: record
|
74
|
+
* R->>+A: revert(record)
|
75
|
+
* A-->>-R: model instance
|
76
|
+
* R->>R: createSuffix(model)
|
77
|
+
* R->>+O: updateObservers(table, CREATE, id)
|
78
|
+
* O-->>-R: Notification complete
|
79
|
+
* R-->>-C: created model
|
80
|
+
*/
|
81
|
+
export declare class Repository<M extends Model, Q, A extends Adapter<any, Q, F, C>, F extends RepositoryFlags = RepositoryFlags, C extends Context<F> = Context<F>> extends Rep<M, F, C> implements Observable, Observer, Queriable<M>, IRepository<M, F, C> {
|
15
82
|
private static _cache;
|
16
83
|
protected observers: Observer[];
|
84
|
+
protected observerHandler?: ObserverHandler;
|
17
85
|
private readonly _adapter;
|
18
86
|
private _tableName;
|
19
87
|
private _overrides?;
|
88
|
+
private logger;
|
89
|
+
/**
|
90
|
+
* @description Logger instance for this repository.
|
91
|
+
* @summary Provides access to the logger for this repository instance.
|
92
|
+
* @return {Logger} The logger instance.
|
93
|
+
*/
|
94
|
+
get log(): Logger;
|
95
|
+
/**
|
96
|
+
* @description Adapter for database operations.
|
97
|
+
* @summary Provides access to the adapter instance for this repository.
|
98
|
+
* @template A - The adapter type.
|
99
|
+
* @return {A} The adapter instance.
|
100
|
+
* @throws {InternalError} If no adapter is found.
|
101
|
+
*/
|
20
102
|
protected get adapter(): A;
|
103
|
+
/**
|
104
|
+
* @description Table name for this repository's model.
|
105
|
+
* @summary Gets the database table name associated with this repository's model.
|
106
|
+
* @return {string} The table name.
|
107
|
+
*/
|
21
108
|
protected get tableName(): string;
|
22
|
-
|
23
|
-
|
109
|
+
/**
|
110
|
+
* @description Primary key properties for this repository's model.
|
111
|
+
* @summary Gets the sequence options containing primary key information.
|
112
|
+
* @return {SequenceOptions} The primary key properties.
|
113
|
+
*/
|
114
|
+
protected get pkProps(): SequenceOptions;
|
115
|
+
constructor(adapter?: A, clazz?: Constructor<M>, ...args: any[]);
|
116
|
+
/**
|
117
|
+
* @description Creates a proxy with overridden repository flags.
|
118
|
+
* @summary Returns a proxy of this repository with the specified flags overridden.
|
119
|
+
* @param {Partial<F>} flags - The flags to override.
|
120
|
+
* @return {Repository} A proxy of this repository with overridden flags.
|
121
|
+
*/
|
122
|
+
override(flags: Partial<F>): Repository<M, Q, A, F, C>;
|
123
|
+
/**
|
124
|
+
* @description Creates a new observer handler.
|
125
|
+
* @summary Factory method for creating an observer handler instance.
|
126
|
+
* @return {ObserverHandler} A new observer handler instance.
|
127
|
+
*/
|
128
|
+
protected ObserverHandler(): ObserverHandler;
|
129
|
+
/**
|
130
|
+
* @description Prepares a model for creation.
|
131
|
+
* @summary Validates the model and prepares it for creation in the database.
|
132
|
+
* @template M - The model type.
|
133
|
+
* @param {M} model - The model to create.
|
134
|
+
* @param {...any[]} args - Additional arguments.
|
135
|
+
* @return The prepared model and context arguments.
|
136
|
+
* @throws {ValidationError} If the model fails validation.
|
137
|
+
*/
|
24
138
|
protected createPrefix(model: M, ...args: any[]): Promise<[M, ...any[]]>;
|
139
|
+
/**
|
140
|
+
* @description Creates a model in the database.
|
141
|
+
* @summary Persists a model instance to the database.
|
142
|
+
* @param {M} model - The model to create.
|
143
|
+
* @param {...any[]} args - Additional arguments.
|
144
|
+
* @return {Promise<M>} The created model with updated properties.
|
145
|
+
*/
|
25
146
|
create(model: M, ...args: any[]): Promise<M>;
|
147
|
+
/**
|
148
|
+
* @description Post-creation hook.
|
149
|
+
* @summary Executes after a model is created to perform additional operations.
|
150
|
+
* @param {M} model - The created model.
|
151
|
+
* @param {C} context - The operation context.
|
152
|
+
* @return {Promise<M>} The processed model.
|
153
|
+
*/
|
26
154
|
createSuffix(model: M, context: C): Promise<M>;
|
155
|
+
/**
|
156
|
+
* @description Creates multiple models in the database.
|
157
|
+
* @summary Persists multiple model instances to the database in a batch operation.
|
158
|
+
* @param {M[]} models - The models to create.
|
159
|
+
* @param {...any[]} args - Additional arguments.
|
160
|
+
* @return {Promise<M[]>} The created models with updated properties.
|
161
|
+
*/
|
27
162
|
createAll(models: M[], ...args: any[]): Promise<M[]>;
|
163
|
+
/**
|
164
|
+
* @description Prepares multiple models for creation.
|
165
|
+
* @summary Validates multiple models and prepares them for creation in the database.
|
166
|
+
* @param {M[]} models - The models to create.
|
167
|
+
* @param {...any[]} args - Additional arguments.
|
168
|
+
* @return The prepared models and context arguments.
|
169
|
+
* @throws {ValidationError} If any model fails validation.
|
170
|
+
*/
|
28
171
|
protected createAllPrefix(models: M[], ...args: any[]): Promise<any[]>;
|
172
|
+
/**
|
173
|
+
* @description Prepares for reading a model by ID.
|
174
|
+
* @summary Prepares the context and enforces decorators before reading a model.
|
175
|
+
* @param {string} key - The primary key of the model to read.
|
176
|
+
* @param {...any[]} args - Additional arguments.
|
177
|
+
* @return The key and context arguments.
|
178
|
+
*/
|
29
179
|
protected readPrefix(key: string, ...args: any[]): Promise<any[]>;
|
180
|
+
/**
|
181
|
+
* @description Reads a model from the database by ID.
|
182
|
+
* @summary Retrieves a model instance from the database using its primary key.
|
183
|
+
* @param {string|number|bigint} id - The primary key of the model to read.
|
184
|
+
* @param {...any[]} args - Additional arguments.
|
185
|
+
* @return {Promise<M>} The retrieved model instance.
|
186
|
+
*/
|
30
187
|
read(id: string | number | bigint, ...args: any[]): Promise<M>;
|
188
|
+
/**
|
189
|
+
* @description Prepares for reading multiple models by IDs.
|
190
|
+
* @summary Prepares the context and enforces decorators before reading multiple models.
|
191
|
+
* @param {string[]|number[]} keys - The primary keys of the models to read.
|
192
|
+
* @param {...any[]} args - Additional arguments.
|
193
|
+
* @return The keys and context arguments.
|
194
|
+
*/
|
31
195
|
protected readAllPrefix(keys: string[] | number[], ...args: any[]): Promise<any[]>;
|
196
|
+
/**
|
197
|
+
* @description Reads multiple models from the database by IDs.
|
198
|
+
* @summary Retrieves multiple model instances from the database using their primary keys.
|
199
|
+
* @param {string[]|number[]} keys - The primary keys of the models to read.
|
200
|
+
* @param {...any[]} args - Additional arguments.
|
201
|
+
* @return {Promise<M[]>} The retrieved model instances.
|
202
|
+
*/
|
32
203
|
readAll(keys: string[] | number[], ...args: any[]): Promise<M[]>;
|
204
|
+
/**
|
205
|
+
* @description Updates a model in the database.
|
206
|
+
* @summary Persists changes to an existing model instance in the database.
|
207
|
+
* @param {M} model - The model to update.
|
208
|
+
* @param {...any[]} args - Additional arguments.
|
209
|
+
* @return {Promise<M>} The updated model with refreshed properties.
|
210
|
+
*/
|
33
211
|
update(model: M, ...args: any[]): Promise<M>;
|
212
|
+
/**
|
213
|
+
* @description Prepares a model for update.
|
214
|
+
* @summary Validates the model and prepares it for update in the database.
|
215
|
+
* @param {M} model - The model to update.
|
216
|
+
* @param {...any[]} args - Additional arguments.
|
217
|
+
* @return The prepared model and context arguments.
|
218
|
+
* @throws {InternalError} If the model has no primary key value.
|
219
|
+
* @throws {ValidationError} If the model fails validation.
|
220
|
+
*/
|
34
221
|
protected updatePrefix(model: M, ...args: any[]): Promise<[M, ...args: any[]]>;
|
222
|
+
/**
|
223
|
+
* @description Updates multiple models in the database.
|
224
|
+
* @summary Persists changes to multiple existing model instances in the database in a batch operation.
|
225
|
+
* @param {M[]} models - The models to update.
|
226
|
+
* @param {...any[]} args - Additional arguments.
|
227
|
+
* @return {Promise<M[]>} The updated models with refreshed properties.
|
228
|
+
*/
|
35
229
|
updateAll(models: M[], ...args: any[]): Promise<M[]>;
|
230
|
+
/**
|
231
|
+
* @description Prepares multiple models for update.
|
232
|
+
* @summary Validates multiple models and prepares them for update in the database.
|
233
|
+
* @param {M[]} models - The models to update.
|
234
|
+
* @param {...any[]} args - Additional arguments.
|
235
|
+
* @return {Promise<any[]>} The prepared models and context arguments.
|
236
|
+
* @throws {InternalError} If any model has no primary key value.
|
237
|
+
* @throws {ValidationError} If any model fails validation.
|
238
|
+
*/
|
36
239
|
protected updateAllPrefix(models: M[], ...args: any[]): Promise<any[]>;
|
240
|
+
/**
|
241
|
+
* @description Prepares for deleting a model by ID.
|
242
|
+
* @summary Prepares the context and enforces decorators before deleting a model.
|
243
|
+
* @param {any} key - The primary key of the model to delete.
|
244
|
+
* @param {...any[]} args - Additional arguments.
|
245
|
+
* @return The key and context arguments.
|
246
|
+
*/
|
37
247
|
protected deletePrefix(key: any, ...args: any[]): Promise<any[]>;
|
248
|
+
/**
|
249
|
+
* @description Deletes a model from the database by ID.
|
250
|
+
* @summary Removes a model instance from the database using its primary key.
|
251
|
+
* @param {string|number|bigint} id - The primary key of the model to delete.
|
252
|
+
* @param {...any[]} args - Additional arguments.
|
253
|
+
* @return {Promise<M>} The deleted model instance.
|
254
|
+
*/
|
38
255
|
delete(id: string | number | bigint, ...args: any[]): Promise<M>;
|
256
|
+
/**
|
257
|
+
* @description Prepares for deleting multiple models by IDs.
|
258
|
+
* @summary Prepares the context and enforces decorators before deleting multiple models.
|
259
|
+
* @param {string[]|number[]} keys - The primary keys of the models to delete.
|
260
|
+
* @param {...any[]} args - Additional arguments.
|
261
|
+
* @return The keys and context arguments.
|
262
|
+
*/
|
39
263
|
protected deleteAllPrefix(keys: string[] | number[], ...args: any[]): Promise<any[]>;
|
264
|
+
/**
|
265
|
+
* @description Deletes multiple models from the database by IDs.
|
266
|
+
* @summary Removes multiple model instances from the database using their primary keys.
|
267
|
+
* @param {string[]|number[]} keys - The primary keys of the models to delete.
|
268
|
+
* @param {...any[]} args - Additional arguments.
|
269
|
+
* @return {Promise<M[]>} The deleted model instances.
|
270
|
+
*/
|
40
271
|
deleteAll(keys: string[] | number[], ...args: any[]): Promise<M[]>;
|
41
|
-
select(selector?: SelectSelector): WhereOption;
|
42
|
-
query<V>(condition: Condition, orderBy: string, order?: OrderDirection, limit?: number, skip?: number): Promise<V>;
|
43
272
|
/**
|
44
|
-
* @
|
45
|
-
* @
|
46
|
-
*
|
273
|
+
* @description Creates a select query without specifying fields.
|
274
|
+
* @summary Starts building a query that will return all fields of the model.
|
275
|
+
* @template S - The array type of select selectors.
|
276
|
+
* @return A query builder for the model.
|
277
|
+
*/
|
278
|
+
select<S extends readonly SelectSelector<M>[]>(): WhereOption<M, M[]>;
|
279
|
+
/**
|
280
|
+
* @description Creates a select query with specific fields.
|
281
|
+
* @summary Starts building a query that will return only the specified fields of the model.
|
282
|
+
* @template S - The array type of select selectors.
|
283
|
+
* @param selector - The fields to select.
|
284
|
+
* @return A query builder for the selected fields.
|
285
|
+
*/
|
286
|
+
select<S extends readonly SelectSelector<M>[]>(selector: readonly [...S]): WhereOption<M, Pick<M, S[number]>[]>;
|
287
|
+
/**
|
288
|
+
* @description Executes a query with the specified conditions and options.
|
289
|
+
* @summary Provides a simplified way to query the database with common query parameters.
|
290
|
+
* @param {Condition<M>} condition - The condition to filter records.
|
291
|
+
* @param orderBy - The field to order results by.
|
292
|
+
* @param {OrderDirection} [order=OrderDirection.ASC] - The sort direction.
|
293
|
+
* @param {number} [limit] - Optional maximum number of results to return.
|
294
|
+
* @param {number} [skip] - Optional number of results to skip.
|
295
|
+
* @return {Promise<M[]>} The query results as model instances.
|
296
|
+
*/
|
297
|
+
query(condition: Condition<M>, orderBy: keyof M, order?: OrderDirection, limit?: number, skip?: number): Promise<M[]>;
|
298
|
+
/**
|
299
|
+
* @description Registers an observer for this repository.
|
300
|
+
* @summary Adds an observer that will be notified of changes to models in this repository.
|
301
|
+
* @param {Observer} observer - The observer to register.
|
302
|
+
* @param {ObserverFilter} [filter] - Optional filter to limit which events the observer receives.
|
303
|
+
* @return {void}
|
47
304
|
* @see {Observable#observe}
|
48
305
|
*/
|
49
|
-
observe(observer: Observer): void;
|
306
|
+
observe(observer: Observer, filter?: ObserverFilter): void;
|
50
307
|
/**
|
51
|
-
* @
|
52
|
-
* @
|
53
|
-
*
|
308
|
+
* @description Unregisters an observer from this repository.
|
309
|
+
* @summary Removes an observer so it will no longer receive notifications of changes.
|
310
|
+
* @param {Observer} observer - The observer to unregister.
|
311
|
+
* @return {void}
|
312
|
+
* @throws {InternalError} If the observer handler is not initialized.
|
54
313
|
* @see {Observable#unObserve}
|
55
314
|
*/
|
56
315
|
unObserve(observer: Observer): void;
|
57
316
|
/**
|
58
|
-
* @
|
59
|
-
* @
|
317
|
+
* @description Notifies all observers of an event.
|
318
|
+
* @summary Updates all registered observers with information about a database event.
|
319
|
+
* @param {string} table - The table name where the event occurred.
|
320
|
+
* @param {OperationKeys|BulkCrudOperationKeys|string} event - The type of event that occurred.
|
321
|
+
* @param {EventIds} id - The ID or IDs of the affected records.
|
322
|
+
* @param {...any[]} args - Additional arguments.
|
323
|
+
* @return {Promise<void>} A promise that resolves when all observers have been notified.
|
324
|
+
* @throws {InternalError} If the observer handler is not initialized.
|
325
|
+
*/
|
326
|
+
updateObservers(table: string, event: OperationKeys | BulkCrudOperationKeys | string, id: EventIds, ...args: any[]): Promise<void>;
|
327
|
+
/**
|
328
|
+
* @description Alias for updateObservers.
|
329
|
+
* @summary Notifies all observers of an event (alias for updateObservers).
|
330
|
+
* @param {string} table - The table name where the event occurred.
|
331
|
+
* @param {OperationKeys|BulkCrudOperationKeys|string} event - The type of event that occurred.
|
332
|
+
* @param {EventIds} id - The ID or IDs of the affected records.
|
333
|
+
* @param {...any[]} args - Additional arguments.
|
334
|
+
* @return {Promise<void>} A promise that resolves when all observers have been notified.
|
335
|
+
*/
|
336
|
+
refresh(table: string, event: OperationKeys | BulkCrudOperationKeys | string, id: EventIds, ...args: any[]): Promise<void>;
|
337
|
+
/**
|
338
|
+
* @description Creates or retrieves a repository for a model.
|
339
|
+
* @summary Factory method that returns a repository instance for the specified model.
|
340
|
+
* @template M - The model type that extends Model.
|
341
|
+
* @template R - The repository type that extends Repo<M>.
|
342
|
+
* @param {Constructor<M>} model - The model constructor.
|
343
|
+
* @param {string} [defaultFlavour] - Optional default adapter flavour if not specified on the model.
|
344
|
+
* @param {...any[]} [args] - Additional arguments to pass to the repository constructor.
|
345
|
+
* @return {R} A repository instance for the model.
|
346
|
+
* @throws {InternalError} If no adapter is registered for the flavour.
|
347
|
+
*/
|
348
|
+
static forModel<M extends Model, R extends Repo<M>>(model: Constructor<M>, alias?: string, ...args: any[]): R;
|
349
|
+
/**
|
350
|
+
* @description Retrieves a repository for a model from the cache.
|
351
|
+
* @summary Gets a repository constructor or instance for the specified model from the internal cache.
|
352
|
+
* @template M - The model type that extends Model.
|
353
|
+
* @param {Constructor<M>} model - The model constructor.
|
354
|
+
* @return {Constructor<Repo<M>> | Repo<M>} The repository constructor or instance.
|
355
|
+
* @throws {InternalError} If no repository is registered for the model.
|
60
356
|
*/
|
61
|
-
updateObservers(...args: any[]): Promise<void>;
|
62
|
-
static forModel<M extends Model, R extends Repo<M>>(model: Constructor<M>, defaultFlavour?: string): R;
|
63
357
|
private static get;
|
64
|
-
|
358
|
+
/**
|
359
|
+
* @description Registers a repository for a model.
|
360
|
+
* @summary Associates a repository constructor or instance with a model in the internal cache.
|
361
|
+
* @template M - The model type that extends Model.
|
362
|
+
* @param {Constructor<M>} model - The model constructor.
|
363
|
+
* @param {Constructor<Repo<M>> | Repo<M>} repo - The repository constructor or instance.
|
364
|
+
* @throws {InternalError} If a repository is already registered for the model.
|
365
|
+
*/
|
366
|
+
static register<M extends Model>(model: Constructor<M>, repo: Constructor<Repo<M>> | Repo<M>, alias?: string): void;
|
367
|
+
/**
|
368
|
+
* @description Sets metadata on a model instance.
|
369
|
+
* @summary Attaches metadata to a model instance using a non-enumerable property.
|
370
|
+
* @template M - The model type that extends Model.
|
371
|
+
* @param {M} model - The model instance.
|
372
|
+
* @param {any} metadata - The metadata to attach to the model.
|
373
|
+
*/
|
65
374
|
static setMetadata<M extends Model>(model: M, metadata: any): void;
|
375
|
+
/**
|
376
|
+
* @description Gets metadata from a model instance.
|
377
|
+
* @summary Retrieves previously attached metadata from a model instance.
|
378
|
+
* @template M - The model type that extends Model.
|
379
|
+
* @param {M} model - The model instance.
|
380
|
+
* @return {any} The metadata or undefined if not found.
|
381
|
+
*/
|
66
382
|
static getMetadata<M extends Model>(model: M): any;
|
383
|
+
/**
|
384
|
+
* @description Removes metadata from a model instance.
|
385
|
+
* @summary Deletes the metadata property from a model instance.
|
386
|
+
* @template M - The model type that extends Model.
|
387
|
+
* @param {M} model - The model instance.
|
388
|
+
*/
|
67
389
|
static removeMetadata<M extends Model>(model: M): void;
|
390
|
+
/**
|
391
|
+
* @description Gets sequence options for a model's primary key.
|
392
|
+
* @summary Retrieves the sequence configuration for a model's primary key from metadata.
|
393
|
+
* @template M - The model type that extends Model.
|
394
|
+
* @param {M} model - The model instance.
|
395
|
+
* @return {SequenceOptions} The sequence options for the model's primary key.
|
396
|
+
* @throws {InternalError} If no sequence options are defined for the model.
|
397
|
+
*/
|
68
398
|
static getSequenceOptions<M extends Model>(model: M): SequenceOptions;
|
399
|
+
/**
|
400
|
+
* @description Gets all indexes defined on a model.
|
401
|
+
* @summary Retrieves all index metadata from a model's property decorators.
|
402
|
+
* @template M - The model type that extends Model.
|
403
|
+
* @param {M | Constructor<M>} model - The model instance or constructor.
|
404
|
+
* @return {Record<string, Record<string, IndexMetadata>>} A nested record of property names to index metadata.
|
405
|
+
*/
|
69
406
|
static indexes<M extends Model>(model: M | Constructor<M>): Record<string, Record<string, IndexMetadata>>;
|
407
|
+
/**
|
408
|
+
* @description Gets all relation properties defined on a model.
|
409
|
+
* @summary Retrieves the names of all properties marked as relations in the model hierarchy.
|
410
|
+
* @template M - The model type that extends Model.
|
411
|
+
* @param {M | Constructor<M>} model - The model instance or constructor.
|
412
|
+
* @return {string[]} An array of property names that are relations.
|
413
|
+
*/
|
70
414
|
static relations<M extends Model>(model: M | Constructor<M>): string[];
|
71
|
-
|
72
|
-
|
415
|
+
/**
|
416
|
+
* @description Gets the table name for a model.
|
417
|
+
* @summary Retrieves the database table name associated with a model.
|
418
|
+
* @template M - The model type that extends Model.
|
419
|
+
* @param {M | Constructor<M>} model - The model instance or constructor.
|
420
|
+
* @return {string} The table name for the model.
|
421
|
+
*/
|
422
|
+
static table<M extends Model>(model: M | Constructor<M>): string;
|
423
|
+
/**
|
424
|
+
* @description Gets the column name for a model attribute.
|
425
|
+
* @summary Retrieves the database column name for a model property.
|
426
|
+
* @template M - The model type that extends Model.
|
427
|
+
* @param {M} model - The model instance.
|
428
|
+
* @param {string} attribute - The attribute/property name.
|
429
|
+
* @return {string} The column name for the attribute.
|
430
|
+
*/
|
431
|
+
static column<M extends Model>(model: M, attribute: string): string;
|
73
432
|
}
|
@@ -2,32 +2,42 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.DefaultCascade = exports.Cascade = exports.OrderDirection = void 0;
|
4
4
|
/**
|
5
|
-
* @
|
6
|
-
*
|
7
|
-
* @
|
8
|
-
*
|
9
|
-
* @
|
5
|
+
* @description Enumeration of possible sort directions.
|
6
|
+
* @summary Defines the available sort directions for ordering query results.
|
7
|
+
* @enum {string}
|
8
|
+
* @readonly
|
9
|
+
* @memberOf module:core
|
10
10
|
*/
|
11
11
|
var OrderDirection;
|
12
12
|
(function (OrderDirection) {
|
13
|
-
/**
|
14
|
-
* @summary Defines the sort order as ascending
|
15
|
-
* @prop ASC
|
16
|
-
*/
|
13
|
+
/** Ascending order (A to Z, 0 to 9) */
|
17
14
|
OrderDirection["ASC"] = "asc";
|
18
|
-
/**
|
19
|
-
* @summary Defines the sort order as descending
|
20
|
-
* @property {string} DSC
|
21
|
-
*/
|
15
|
+
/** Descending order (Z to A, 9 to 0) */
|
22
16
|
OrderDirection["DSC"] = "desc";
|
23
17
|
})(OrderDirection || (exports.OrderDirection = OrderDirection = {}));
|
18
|
+
/**
|
19
|
+
* @description Enumeration of cascade operation types.
|
20
|
+
* @summary Defines the available cascade behaviors for entity relationships.
|
21
|
+
* @enum {string}
|
22
|
+
* @readonly
|
23
|
+
* @memberOf module:core
|
24
|
+
*/
|
24
25
|
var Cascade;
|
25
26
|
(function (Cascade) {
|
27
|
+
/** Perform cascade operation on related entities */
|
26
28
|
Cascade["CASCADE"] = "cascade";
|
29
|
+
/** Do not perform cascade operation on related entities */
|
27
30
|
Cascade["NONE"] = "none";
|
28
31
|
})(Cascade || (exports.Cascade = Cascade = {}));
|
32
|
+
/**
|
33
|
+
* @description Default cascade configuration for entity relationships.
|
34
|
+
* @summary Provides the default cascade behavior where updates cascade but deletes do not.
|
35
|
+
* @type {CascadeMetadata}
|
36
|
+
* @const DefaultCascade
|
37
|
+
* @memberOf module:core
|
38
|
+
*/
|
29
39
|
exports.DefaultCascade = {
|
30
40
|
update: Cascade.CASCADE,
|
31
41
|
delete: Cascade.NONE,
|
32
42
|
};
|
33
|
-
//# sourceMappingURL=data:application/json;base64,
|
43
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29uc3RhbnRzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3JlcG9zaXRvcnkvY29uc3RhbnRzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7OztBQUVBOzs7Ozs7R0FNRztBQUNILElBQVksY0FNWDtBQU5ELFdBQVksY0FBYztJQUN4Qix1Q0FBdUM7SUFDdkMsNkJBQVcsQ0FBQTtJQUVYLHdDQUF3QztJQUN4Qyw4QkFBWSxDQUFBO0FBQ2QsQ0FBQyxFQU5XLGNBQWMsOEJBQWQsY0FBYyxRQU16QjtBQUVEOzs7Ozs7R0FNRztBQUNILElBQVksT0FLWDtBQUxELFdBQVksT0FBTztJQUNqQixvREFBb0Q7SUFDcEQsOEJBQW1CLENBQUE7SUFDbkIsMkRBQTJEO0lBQzNELHdCQUFhLENBQUE7QUFDZixDQUFDLEVBTFcsT0FBTyx1QkFBUCxPQUFPLFFBS2xCO0FBRUQ7Ozs7OztHQU1HO0FBQ1UsUUFBQSxjQUFjLEdBQW9CO0lBQzdDLE1BQU0sRUFBRSxPQUFPLENBQUMsT0FBTztJQUN2QixNQUFNLEVBQUUsT0FBTyxDQUFDLElBQUk7Q0FDckIsQ0FBQyIsInNvdXJjZXNDb250ZW50IjpbImltcG9ydCB7IENhc2NhZGVNZXRhZGF0YSB9IGZyb20gXCIuL3R5cGVzXCI7XG5cbi8qKlxuICogQGRlc2NyaXB0aW9uIEVudW1lcmF0aW9uIG9mIHBvc3NpYmxlIHNvcnQgZGlyZWN0aW9ucy5cbiAqIEBzdW1tYXJ5IERlZmluZXMgdGhl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VoYXZpb3Igd2hlcmUgdXBkYXRlcyBjYXNjYWRlIGJ1dCBkZWxldGVzIGRvIG5vdC5cbiAqIEB0eXBlIHtDYXNjYWRlTWV0YWRhdGF9XG4gKiBAY29uc3QgRGVmYXVsdENhc2NhZGVcbiAqIEBtZW1iZXJPZiBtb2R1bGU6Y29yZVxuICovXG5leHBvcnQgY29uc3QgRGVmYXVsdENhc2NhZGU6IENhc2NhZGVNZXRhZGF0YSA9IHtcbiAgdXBkYXRlOiBDYXNjYWRlLkNBU0NBREUsXG4gIGRlbGV0ZTogQ2FzY2FkZS5OT05FLFxufTtcbiJdfQ==
|
@@ -1,25 +1,35 @@
|
|
1
1
|
import { CascadeMetadata } from "./types";
|
2
2
|
/**
|
3
|
-
* @
|
4
|
-
*
|
5
|
-
* @
|
6
|
-
*
|
7
|
-
* @
|
3
|
+
* @description Enumeration of possible sort directions.
|
4
|
+
* @summary Defines the available sort directions for ordering query results.
|
5
|
+
* @enum {string}
|
6
|
+
* @readonly
|
7
|
+
* @memberOf module:core
|
8
8
|
*/
|
9
9
|
export declare enum OrderDirection {
|
10
|
-
/**
|
11
|
-
* @summary Defines the sort order as ascending
|
12
|
-
* @prop ASC
|
13
|
-
*/
|
10
|
+
/** Ascending order (A to Z, 0 to 9) */
|
14
11
|
ASC = "asc",
|
15
|
-
/**
|
16
|
-
* @summary Defines the sort order as descending
|
17
|
-
* @property {string} DSC
|
18
|
-
*/
|
12
|
+
/** Descending order (Z to A, 9 to 0) */
|
19
13
|
DSC = "desc"
|
20
14
|
}
|
15
|
+
/**
|
16
|
+
* @description Enumeration of cascade operation types.
|
17
|
+
* @summary Defines the available cascade behaviors for entity relationships.
|
18
|
+
* @enum {string}
|
19
|
+
* @readonly
|
20
|
+
* @memberOf module:core
|
21
|
+
*/
|
21
22
|
export declare enum Cascade {
|
23
|
+
/** Perform cascade operation on related entities */
|
22
24
|
CASCADE = "cascade",
|
25
|
+
/** Do not perform cascade operation on related entities */
|
23
26
|
NONE = "none"
|
24
27
|
}
|
28
|
+
/**
|
29
|
+
* @description Default cascade configuration for entity relationships.
|
30
|
+
* @summary Provides the default cascade behavior where updates cascade but deletes do not.
|
31
|
+
* @type {CascadeMetadata}
|
32
|
+
* @const DefaultCascade
|
33
|
+
* @memberOf module:core
|
34
|
+
*/
|
25
35
|
export declare const DefaultCascade: CascadeMetadata;
|
@@ -5,6 +5,33 @@ const injectable_decorators_1 = require("@decaf-ts/injectable-decorators");
|
|
5
5
|
const db_decorators_1 = require("@decaf-ts/db-decorators");
|
6
6
|
const reflection_1 = require("@decaf-ts/reflection");
|
7
7
|
const Repository_1 = require("./Repository.cjs");
|
8
|
+
/**
|
9
|
+
* @description Repository decorator for model classes.
|
10
|
+
* @summary Creates and registers a repository for a model class. Can be used as both a property decorator and a class decorator.
|
11
|
+
* @template T - The model type that extends Model.
|
12
|
+
* @param {Constructor<T>} model - The constructor of the model class.
|
13
|
+
* @param {string} [nameOverride] - Optional name override for the repository.
|
14
|
+
* @return {any} - The decorator function.
|
15
|
+
* @function repository
|
16
|
+
* @mermaid
|
17
|
+
* sequenceDiagram
|
18
|
+
* participant C as Client Code
|
19
|
+
* participant D as Decorator
|
20
|
+
* participant R as Repository
|
21
|
+
* participant M as Metadata
|
22
|
+
*
|
23
|
+
* C->>D: Apply @repository(Model)
|
24
|
+
* alt Property Decorator
|
25
|
+
* D->>D: Check if propertyKey exists
|
26
|
+
* D->>+C: Return inject(name) decorator
|
27
|
+
* else Class Decorator
|
28
|
+
* D->>M: Set repository metadata on model
|
29
|
+
* D->>R: Register model with Repository
|
30
|
+
* D->>+C: Return injectable decorator with config
|
31
|
+
* C->>C: Define DBKeys.CLASS property
|
32
|
+
* end
|
33
|
+
* @category Decorators
|
34
|
+
*/
|
8
35
|
function repository(model, nameOverride) {
|
9
36
|
return ((original, propertyKey) => {
|
10
37
|
if (propertyKey) {
|
@@ -22,4 +49,4 @@ function repository(model, nameOverride) {
|
|
22
49
|
})(original);
|
23
50
|
});
|
24
51
|
}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dG9yeTxUIGV4dGVuZHMgTW9kZWw+KFxuICBtb2RlbDogQ29uc3RydWN0b3I8VD4sXG4gIG5hbWVPdmVycmlkZT86IHN0cmluZ1xuKTogYW55IHtcbiAgcmV0dXJuICgob3JpZ2luYWw6IGFueSwgcHJvcGVydHlLZXk/OiBhbnkpID0+IHtcbiAgICBpZiAocHJvcGVydHlLZXkpIHtcbiAgICAgIHJldHVybiBpbmplY3QobmFtZU92ZXJyaWRlIHx8IG1vZGVsLm5hbWUpKG9yaWdpbmFsLCBwcm9wZXJ0eUtleSk7XG4gICAgfVxuXG4gICAgbWV0YWRhdGEoXG4gICAgICBSZXBvc2l0b3J5LmtleShEQktleXMuUkVQT1NJVE9SWSksXG4gICAgICBuYW1lT3ZlcnJpZGUgfHwgb3JpZ2luYWwubmFtZVxuICAgICkobW9kZWwpO1xuICAgIFJlcG9zaXRvcnkucmVnaXN0ZXIobW9kZWwsIG9yaWdpbmFsKTtcbiAgICByZXR1cm4gaW5qZWN0YWJsZShcbiAgICAgIG5hbWVPdmVycmlkZSB8fCBvcmlnaW5hbC5uYW1lLFxuICAgICAgdHJ1ZSxcbiAgICAgIChpbnN0YW5jZTogSVJlcG9zaXRvcnk8VD4pID0+IHtcbiAgICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KGluc3RhbmNlLCBEQktleXMuQ0xBU1MsIHtcbiAgICAgICAgICBlbnVtZXJhYmxlOiBmYWxzZSxcbiAgICAgICAgICBjb25maWd1cmFibGU6IGZhbHNlLFxuICAgICAgICAgIHdyaXRhYmxlOiBmYWxzZSxcbiAgICAgICAgICB2YWx1ZTogbW9kZWwsXG4gICAgICAgIH0pO1xuICAgICAgfVxuICAgICkob3JpZ2luYWwpO1xuICB9KSBhcyBhbnk7XG59XG4iXX0=
|
@@ -1,2 +1,29 @@
|
|
1
1
|
import { Constructor, Model } from "@decaf-ts/decorator-validation";
|
2
|
+
/**
|
3
|
+
* @description Repository decorator for model classes.
|
4
|
+
* @summary Creates and registers a repository for a model class. Can be used as both a property decorator and a class decorator.
|
5
|
+
* @template T - The model type that extends Model.
|
6
|
+
* @param {Constructor<T>} model - The constructor of the model class.
|
7
|
+
* @param {string} [nameOverride] - Optional name override for the repository.
|
8
|
+
* @return {any} - The decorator function.
|
9
|
+
* @function repository
|
10
|
+
* @mermaid
|
11
|
+
* sequenceDiagram
|
12
|
+
* participant C as Client Code
|
13
|
+
* participant D as Decorator
|
14
|
+
* participant R as Repository
|
15
|
+
* participant M as Metadata
|
16
|
+
*
|
17
|
+
* C->>D: Apply @repository(Model)
|
18
|
+
* alt Property Decorator
|
19
|
+
* D->>D: Check if propertyKey exists
|
20
|
+
* D->>+C: Return inject(name) decorator
|
21
|
+
* else Class Decorator
|
22
|
+
* D->>M: Set repository metadata on model
|
23
|
+
* D->>R: Register model with Repository
|
24
|
+
* D->>+C: Return injectable decorator with config
|
25
|
+
* C->>C: Define DBKeys.CLASS property
|
26
|
+
* end
|
27
|
+
* @category Decorators
|
28
|
+
*/
|
2
29
|
export declare function repository<T extends Model>(model: Constructor<T>, nameOverride?: string): any;
|