@decaf-ts/core 0.5.1 → 0.5.3
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 +2111 -133
- package/dist/core.esm.cjs +2112 -134
- package/lib/esm/identity/decorators.d.ts +52 -7
- package/lib/esm/identity/decorators.js +58 -13
- package/lib/esm/identity/index.js +3 -3
- package/lib/esm/identity/utils.d.ts +19 -0
- package/lib/esm/identity/utils.js +22 -3
- package/lib/esm/index.d.ts +10 -3
- package/lib/esm/index.js +19 -12
- package/lib/esm/interfaces/ErrorParser.d.ts +12 -0
- package/lib/esm/interfaces/ErrorParser.js +1 -1
- package/lib/esm/interfaces/Executor.d.ts +13 -0
- package/lib/esm/interfaces/Executor.js +1 -1
- package/lib/esm/interfaces/Observable.d.ts +27 -0
- package/lib/esm/interfaces/Observable.js +1 -1
- package/lib/esm/interfaces/Observer.d.ts +12 -0
- package/lib/esm/interfaces/Observer.js +1 -1
- package/lib/esm/interfaces/Paginatable.d.ts +15 -0
- package/lib/esm/interfaces/Paginatable.js +1 -1
- package/lib/esm/interfaces/Queriable.d.ts +34 -9
- package/lib/esm/interfaces/Queriable.js +1 -1
- package/lib/esm/interfaces/RawExecutor.d.ts +14 -0
- package/lib/esm/interfaces/RawExecutor.js +1 -1
- package/lib/esm/interfaces/SequenceOptions.d.ts +52 -0
- package/lib/esm/interfaces/SequenceOptions.js +19 -1
- package/lib/esm/interfaces/index.js +8 -8
- package/lib/esm/model/BaseModel.d.ts +31 -0
- package/lib/esm/model/BaseModel.js +24 -1
- package/lib/esm/model/construction.d.ts +433 -0
- package/lib/esm/model/construction.js +444 -5
- package/lib/esm/model/decorators.d.ts +159 -29
- package/lib/esm/model/decorators.js +167 -37
- package/lib/esm/model/index.js +5 -5
- package/lib/esm/model/types.d.ts +9 -0
- package/lib/esm/model/types.js +1 -1
- package/lib/esm/persistence/Adapter.d.ts +358 -17
- package/lib/esm/persistence/Adapter.js +292 -24
- package/lib/esm/persistence/Dispatch.d.ts +114 -1
- package/lib/esm/persistence/Dispatch.js +104 -6
- package/lib/esm/persistence/ObserverHandler.d.ts +95 -0
- package/lib/esm/persistence/ObserverHandler.js +96 -1
- package/lib/esm/persistence/Sequence.d.ts +89 -0
- package/lib/esm/persistence/Sequence.js +71 -2
- package/lib/esm/persistence/constants.d.ts +22 -0
- package/lib/esm/persistence/constants.js +23 -1
- package/lib/esm/persistence/decorators.d.ts +10 -0
- package/lib/esm/persistence/decorators.js +13 -3
- package/lib/esm/persistence/errors.d.ts +23 -0
- package/lib/esm/persistence/errors.js +24 -1
- package/lib/esm/persistence/index.js +9 -9
- package/lib/esm/persistence/types.d.ts +18 -0
- package/lib/esm/persistence/types.js +1 -1
- package/lib/esm/query/Condition.d.ts +78 -31
- package/lib/esm/query/Condition.js +134 -55
- package/lib/esm/query/Paginator.d.ts +56 -0
- package/lib/esm/query/Paginator.js +58 -2
- package/lib/esm/query/Statement.d.ts +51 -0
- package/lib/esm/query/Statement.js +55 -4
- package/lib/esm/query/constants.d.ts +25 -0
- package/lib/esm/query/constants.js +26 -1
- package/lib/esm/query/errors.d.ts +14 -0
- package/lib/esm/query/errors.js +15 -1
- package/lib/esm/query/index.js +8 -8
- package/lib/esm/query/options.d.ts +21 -3
- package/lib/esm/query/options.js +1 -1
- package/lib/esm/query/selectors.d.ts +26 -0
- package/lib/esm/query/selectors.js +1 -1
- package/lib/esm/ram/RamAdapter.d.ts +311 -0
- package/lib/esm/ram/RamAdapter.js +319 -8
- package/lib/esm/ram/RamContext.d.ts +16 -1
- package/lib/esm/ram/RamContext.js +18 -3
- package/lib/esm/ram/RamPaginator.d.ts +43 -0
- package/lib/esm/ram/RamPaginator.js +55 -3
- package/lib/esm/ram/RamSequence.d.ts +61 -0
- package/lib/esm/ram/RamSequence.js +66 -5
- package/lib/esm/ram/RamStatement.d.ts +74 -0
- package/lib/esm/ram/RamStatement.js +78 -4
- package/lib/esm/ram/constants.d.ts +8 -0
- package/lib/esm/ram/constants.js +9 -1
- package/lib/esm/ram/handlers.d.ts +19 -0
- package/lib/esm/ram/handlers.js +21 -2
- package/lib/esm/ram/index.js +11 -11
- package/lib/esm/ram/model/RamSequence.d.ts +25 -0
- package/lib/esm/ram/model/RamSequence.js +21 -3
- package/lib/esm/ram/model/index.js +2 -2
- package/lib/esm/ram/types.d.ts +42 -0
- package/lib/esm/ram/types.js +1 -1
- package/lib/esm/repository/Repository.d.ts +363 -8
- package/lib/esm/repository/Repository.js +369 -24
- package/lib/esm/repository/constants.d.ts +25 -0
- package/lib/esm/repository/constants.js +26 -1
- package/lib/esm/repository/decorators.d.ts +27 -0
- package/lib/esm/repository/decorators.js +29 -2
- package/lib/esm/repository/errors.d.ts +12 -5
- package/lib/esm/repository/errors.js +13 -6
- package/lib/esm/repository/index.js +8 -8
- package/lib/esm/repository/injectables.d.ts +18 -0
- package/lib/esm/repository/injectables.js +23 -5
- package/lib/esm/repository/types.d.ts +15 -0
- package/lib/esm/repository/types.js +1 -1
- package/lib/esm/repository/utils.d.ts +11 -0
- package/lib/esm/repository/utils.js +15 -4
- package/lib/esm/utils/decorators.d.ts +8 -0
- package/lib/esm/utils/decorators.js +9 -1
- package/lib/esm/utils/errors.d.ts +46 -0
- package/lib/esm/utils/errors.js +47 -1
- package/lib/esm/utils/index.js +3 -3
- package/lib/identity/decorators.cjs +53 -8
- package/lib/identity/decorators.d.ts +52 -7
- package/lib/identity/utils.cjs +20 -1
- package/lib/identity/utils.d.ts +19 -0
- package/lib/index.cjs +11 -4
- package/lib/index.d.ts +10 -3
- 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 +13 -0
- package/lib/interfaces/Observable.cjs +1 -1
- package/lib/interfaces/Observable.d.ts +27 -0
- package/lib/interfaces/Observer.cjs +1 -1
- package/lib/interfaces/Observer.d.ts +12 -0
- package/lib/interfaces/Paginatable.cjs +1 -1
- package/lib/interfaces/Paginatable.d.ts +15 -0
- package/lib/interfaces/Queriable.cjs +1 -1
- package/lib/interfaces/Queriable.d.ts +34 -9
- package/lib/interfaces/RawExecutor.cjs +1 -1
- package/lib/interfaces/RawExecutor.d.ts +14 -0
- package/lib/interfaces/SequenceOptions.cjs +19 -1
- package/lib/interfaces/SequenceOptions.d.ts +52 -0
- 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 +433 -0
- package/lib/model/decorators.cjs +160 -30
- package/lib/model/decorators.d.ts +159 -29
- package/lib/model/types.cjs +1 -1
- package/lib/model/types.d.ts +9 -0
- package/lib/persistence/Adapter.cjs +287 -19
- package/lib/persistence/Adapter.d.ts +358 -17
- package/lib/persistence/Dispatch.cjs +102 -4
- package/lib/persistence/Dispatch.d.ts +114 -1
- package/lib/persistence/ObserverHandler.cjs +96 -1
- package/lib/persistence/ObserverHandler.d.ts +95 -0
- package/lib/persistence/Sequence.cjs +70 -1
- package/lib/persistence/Sequence.d.ts +89 -0
- package/lib/persistence/constants.cjs +23 -1
- package/lib/persistence/constants.d.ts +22 -0
- package/lib/persistence/decorators.cjs +11 -1
- package/lib/persistence/decorators.d.ts +10 -0
- package/lib/persistence/errors.cjs +24 -1
- package/lib/persistence/errors.d.ts +23 -0
- package/lib/persistence/types.cjs +1 -1
- package/lib/persistence/types.d.ts +18 -0
- package/lib/query/Condition.cjs +132 -53
- package/lib/query/Condition.d.ts +78 -31
- package/lib/query/Paginator.cjs +57 -1
- package/lib/query/Paginator.d.ts +56 -0
- package/lib/query/Statement.cjs +52 -1
- package/lib/query/Statement.d.ts +51 -0
- package/lib/query/constants.cjs +26 -1
- package/lib/query/constants.d.ts +25 -0
- package/lib/query/errors.cjs +15 -1
- package/lib/query/errors.d.ts +14 -0
- package/lib/query/options.cjs +1 -1
- package/lib/query/options.d.ts +21 -3
- package/lib/query/selectors.cjs +1 -1
- package/lib/query/selectors.d.ts +26 -0
- package/lib/ram/RamAdapter.cjs +312 -1
- package/lib/ram/RamAdapter.d.ts +311 -0
- package/lib/ram/RamContext.cjs +18 -3
- package/lib/ram/RamContext.d.ts +16 -1
- package/lib/ram/RamPaginator.cjs +54 -2
- package/lib/ram/RamPaginator.d.ts +43 -0
- package/lib/ram/RamSequence.cjs +63 -2
- package/lib/ram/RamSequence.d.ts +61 -0
- package/lib/ram/RamStatement.cjs +75 -1
- package/lib/ram/RamStatement.d.ts +74 -0
- package/lib/ram/constants.cjs +9 -1
- package/lib/ram/constants.d.ts +8 -0
- package/lib/ram/handlers.cjs +20 -1
- package/lib/ram/handlers.d.ts +19 -0
- package/lib/ram/model/RamSequence.cjs +19 -1
- package/lib/ram/model/RamSequence.d.ts +25 -0
- package/lib/ram/types.cjs +1 -1
- package/lib/ram/types.d.ts +42 -0
- package/lib/repository/Repository.cjs +360 -15
- package/lib/repository/Repository.d.ts +363 -8
- package/lib/repository/constants.cjs +26 -1
- package/lib/repository/constants.d.ts +25 -0
- package/lib/repository/decorators.cjs +28 -1
- package/lib/repository/decorators.d.ts +27 -0
- package/lib/repository/errors.cjs +13 -6
- package/lib/repository/errors.d.ts +12 -5
- 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 +15 -0
- package/lib/repository/utils.cjs +12 -1
- package/lib/repository/utils.d.ts +11 -0
- package/lib/utils/decorators.cjs +9 -1
- package/lib/utils/decorators.d.ts +8 -0
- package/lib/utils/errors.cjs +47 -1
- package/lib/utils/errors.d.ts +46 -0
- package/package.json +5 -5
@@ -3,16 +3,449 @@ import { Repo } from "../repository/Repository";
|
|
3
3
|
import { RelationsMetadata } from "./types";
|
4
4
|
import { RepositoryFlags } from "@decaf-ts/db-decorators";
|
5
5
|
import { Context } from "@decaf-ts/db-decorators";
|
6
|
+
/**
|
7
|
+
* @description Creates or updates a model instance
|
8
|
+
* @summary Determines whether to create a new model or update an existing one based on the presence of a primary key
|
9
|
+
* @template M - The model type extending Model
|
10
|
+
* @template F - The repository flags type
|
11
|
+
* @param {M} model - The model instance to create or update
|
12
|
+
* @param {Context<F>} context - The context for the operation
|
13
|
+
* @param {Repo<M, F, Context<F>>} [repository] - Optional repository to use for the operation
|
14
|
+
* @return {Promise<M>} A promise that resolves to the created or updated model
|
15
|
+
* @function createOrUpdate
|
16
|
+
* @memberOf module:core
|
17
|
+
* @mermaid
|
18
|
+
* sequenceDiagram
|
19
|
+
* participant Caller
|
20
|
+
* participant createOrUpdate
|
21
|
+
* participant Repository
|
22
|
+
* participant Model
|
23
|
+
*
|
24
|
+
* Caller->>createOrUpdate: model, context, repository?
|
25
|
+
* alt repository not provided
|
26
|
+
* createOrUpdate->>Model: get(model.constructor.name)
|
27
|
+
* Model-->>createOrUpdate: constructor
|
28
|
+
* createOrUpdate->>Repository: forModel(constructor)
|
29
|
+
* Repository-->>createOrUpdate: repository
|
30
|
+
* end
|
31
|
+
*
|
32
|
+
* alt primary key undefined
|
33
|
+
* createOrUpdate->>Repository: create(model, context)
|
34
|
+
* Repository-->>createOrUpdate: created model
|
35
|
+
* else primary key defined
|
36
|
+
* createOrUpdate->>Repository: update(model, context)
|
37
|
+
* alt update successful
|
38
|
+
* Repository-->>createOrUpdate: updated model
|
39
|
+
* else NotFoundError
|
40
|
+
* createOrUpdate->>Repository: create(model, context)
|
41
|
+
* Repository-->>createOrUpdate: created model
|
42
|
+
* end
|
43
|
+
* end
|
44
|
+
*
|
45
|
+
* createOrUpdate-->>Caller: model
|
46
|
+
*/
|
6
47
|
export declare function createOrUpdate<M extends Model, F extends RepositoryFlags>(model: M, context: Context<F>, repository?: Repo<M, F, Context<F>>): Promise<M>;
|
48
|
+
/**
|
49
|
+
* @description Handles one-to-one relationship creation
|
50
|
+
* @summary Processes a one-to-one relationship when creating a model, either by referencing an existing model or creating a new one
|
51
|
+
* @template M - The model type extending Model
|
52
|
+
* @template R - The repository type extending Repo<M, F, C>
|
53
|
+
* @template V - The relations metadata type extending RelationsMetadata
|
54
|
+
* @template F - The repository flags type
|
55
|
+
* @template C - The context type extending Context<F>
|
56
|
+
* @param {R} this - The repository instance
|
57
|
+
* @param {Context<F>} context - The context for the operation
|
58
|
+
* @param {V} data - The relations metadata
|
59
|
+
* @param {string} key - The property key of the relationship
|
60
|
+
* @param {M} model - The model instance
|
61
|
+
* @return {Promise<void>} A promise that resolves when the operation is complete
|
62
|
+
* @function oneToOneOnCreate
|
63
|
+
* @memberOf module:core
|
64
|
+
* @mermaid
|
65
|
+
* sequenceDiagram
|
66
|
+
* participant Caller
|
67
|
+
* participant oneToOneOnCreate
|
68
|
+
* participant repositoryFromTypeMetadata
|
69
|
+
* participant Model
|
70
|
+
* participant Repository
|
71
|
+
* participant cacheModelForPopulate
|
72
|
+
*
|
73
|
+
* Caller->>oneToOneOnCreate: this, context, data, key, model
|
74
|
+
* oneToOneOnCreate->>oneToOneOnCreate: check if propertyValue exists
|
75
|
+
*
|
76
|
+
* alt propertyValue is not an object
|
77
|
+
* oneToOneOnCreate->>repositoryFromTypeMetadata: model, key
|
78
|
+
* repositoryFromTypeMetadata-->>oneToOneOnCreate: innerRepo
|
79
|
+
* oneToOneOnCreate->>innerRepo: read(propertyValue)
|
80
|
+
* innerRepo-->>oneToOneOnCreate: read
|
81
|
+
* oneToOneOnCreate->>cacheModelForPopulate: context, model, key, propertyValue, read
|
82
|
+
* oneToOneOnCreate->>oneToOneOnCreate: set model[key] = propertyValue
|
83
|
+
* else propertyValue is an object
|
84
|
+
* oneToOneOnCreate->>Model: get(data.class)
|
85
|
+
* Model-->>oneToOneOnCreate: constructor
|
86
|
+
* oneToOneOnCreate->>Repository: forModel(constructor)
|
87
|
+
* Repository-->>oneToOneOnCreate: repo
|
88
|
+
* oneToOneOnCreate->>repo: create(propertyValue)
|
89
|
+
* repo-->>oneToOneOnCreate: created
|
90
|
+
* oneToOneOnCreate->>findPrimaryKey: created
|
91
|
+
* findPrimaryKey-->>oneToOneOnCreate: pk
|
92
|
+
* oneToOneOnCreate->>cacheModelForPopulate: context, model, key, created[pk], created
|
93
|
+
* oneToOneOnCreate->>oneToOneOnCreate: set model[key] = created[pk]
|
94
|
+
* end
|
95
|
+
*
|
96
|
+
* oneToOneOnCreate-->>Caller: void
|
97
|
+
*/
|
7
98
|
export declare function oneToOneOnCreate<M extends Model, R extends Repo<M, F, C>, V extends RelationsMetadata, F extends RepositoryFlags, C extends Context<F>>(this: R, context: Context<F>, data: V, key: keyof M, model: M): Promise<void>;
|
99
|
+
/**
|
100
|
+
* @description Handles one-to-one relationship updates
|
101
|
+
* @summary Processes a one-to-one relationship when updating a model, either by referencing an existing model or updating the related model
|
102
|
+
* @template M - The model type extending Model
|
103
|
+
* @template R - The repository type extending Repo<M, F, C>
|
104
|
+
* @template V - The relations metadata type extending RelationsMetadata
|
105
|
+
* @template F - The repository flags type
|
106
|
+
* @template C - The context type extending Context<F>
|
107
|
+
* @param {R} this - The repository instance
|
108
|
+
* @param {Context<F>} context - The context for the operation
|
109
|
+
* @param {V} data - The relations metadata
|
110
|
+
* @param key - The property key of the relationship
|
111
|
+
* @param {M} model - The model instance
|
112
|
+
* @return {Promise<void>} A promise that resolves when the operation is complete
|
113
|
+
* @function oneToOneOnUpdate
|
114
|
+
* @memberOf module:core
|
115
|
+
* @mermaid
|
116
|
+
* sequenceDiagram
|
117
|
+
* participant Caller
|
118
|
+
* participant oneToOneOnUpdate
|
119
|
+
* participant repositoryFromTypeMetadata
|
120
|
+
* participant createOrUpdate
|
121
|
+
* participant findPrimaryKey
|
122
|
+
* participant cacheModelForPopulate
|
123
|
+
*
|
124
|
+
* Caller->>oneToOneOnUpdate: this, context, data, key, model
|
125
|
+
* oneToOneOnUpdate->>oneToOneOnUpdate: check if propertyValue exists
|
126
|
+
* oneToOneOnUpdate->>oneToOneOnUpdate: check if cascade.update is CASCADE
|
127
|
+
*
|
128
|
+
* alt propertyValue is not an object
|
129
|
+
* oneToOneOnUpdate->>repositoryFromTypeMetadata: model, key
|
130
|
+
* repositoryFromTypeMetadata-->>oneToOneOnUpdate: innerRepo
|
131
|
+
* oneToOneOnUpdate->>innerRepo: read(propertyValue)
|
132
|
+
* innerRepo-->>oneToOneOnUpdate: read
|
133
|
+
* oneToOneOnUpdate->>cacheModelForPopulate: context, model, key, propertyValue, read
|
134
|
+
* oneToOneOnUpdate->>oneToOneOnUpdate: set model[key] = propertyValue
|
135
|
+
* else propertyValue is an object
|
136
|
+
* oneToOneOnUpdate->>createOrUpdate: model[key], context
|
137
|
+
* createOrUpdate-->>oneToOneOnUpdate: updated
|
138
|
+
* oneToOneOnUpdate->>findPrimaryKey: updated
|
139
|
+
* findPrimaryKey-->>oneToOneOnUpdate: pk
|
140
|
+
* oneToOneOnUpdate->>cacheModelForPopulate: context, model, key, updated[pk], updated
|
141
|
+
* oneToOneOnUpdate->>oneToOneOnUpdate: set model[key] = updated[pk]
|
142
|
+
* end
|
143
|
+
*
|
144
|
+
* oneToOneOnUpdate-->>Caller: void
|
145
|
+
*/
|
8
146
|
export declare function oneToOneOnUpdate<M extends Model, R extends Repo<M, F, C>, V extends RelationsMetadata, F extends RepositoryFlags, C extends Context<F>>(this: R, context: Context<F>, data: V, key: keyof M, model: M): Promise<void>;
|
147
|
+
/**
|
148
|
+
* @description Handles one-to-one relationship deletion
|
149
|
+
* @summary Processes a one-to-one relationship when deleting a model, deleting the related model if cascade is enabled
|
150
|
+
* @template M - The model type extending Model
|
151
|
+
* @template R - The repository type extending Repo<M, F, C>
|
152
|
+
* @template V - The relations metadata type extending RelationsMetadata
|
153
|
+
* @template F - The repository flags type
|
154
|
+
* @template C - The context type extending Context<F>
|
155
|
+
* @param {R} this - The repository instance
|
156
|
+
* @param {Context<F>} context - The context for the operation
|
157
|
+
* @param {V} data - The relations metadata
|
158
|
+
* @param key - The property key of the relationship
|
159
|
+
* @param {M} model - The model instance
|
160
|
+
* @return {Promise<void>} A promise that resolves when the operation is complete
|
161
|
+
* @function oneToOneOnDelete
|
162
|
+
* @memberOf module:core
|
163
|
+
* @mermaid
|
164
|
+
* sequenceDiagram
|
165
|
+
* participant Caller
|
166
|
+
* participant oneToOneOnDelete
|
167
|
+
* participant repositoryFromTypeMetadata
|
168
|
+
* participant cacheModelForPopulate
|
169
|
+
*
|
170
|
+
* Caller->>oneToOneOnDelete: this, context, data, key, model
|
171
|
+
* oneToOneOnDelete->>oneToOneOnDelete: check if propertyValue exists
|
172
|
+
* oneToOneOnDelete->>oneToOneOnDelete: check if cascade.update is CASCADE
|
173
|
+
*
|
174
|
+
* oneToOneOnDelete->>repositoryFromTypeMetadata: model, key
|
175
|
+
* repositoryFromTypeMetadata-->>oneToOneOnDelete: innerRepo
|
176
|
+
*
|
177
|
+
* alt propertyValue is not a Model instance
|
178
|
+
* oneToOneOnDelete->>innerRepo: delete(model[key], context)
|
179
|
+
* innerRepo-->>oneToOneOnDelete: deleted
|
180
|
+
* else propertyValue is a Model instance
|
181
|
+
* oneToOneOnDelete->>innerRepo: delete(model[key][innerRepo.pk], context)
|
182
|
+
* innerRepo-->>oneToOneOnDelete: deleted
|
183
|
+
* end
|
184
|
+
*
|
185
|
+
* oneToOneOnDelete->>cacheModelForPopulate: context, model, key, deleted[innerRepo.pk], deleted
|
186
|
+
* oneToOneOnDelete-->>Caller: void
|
187
|
+
*/
|
9
188
|
export declare function oneToOneOnDelete<M extends Model, R extends Repo<M, F, C>, V extends RelationsMetadata, F extends RepositoryFlags, C extends Context<F>>(this: R, context: Context<F>, data: V, key: keyof M, model: M): Promise<void>;
|
189
|
+
/**
|
190
|
+
* @description Handles one-to-many relationship creation
|
191
|
+
* @summary Processes a one-to-many relationship when creating a model, either by referencing existing models or creating new ones
|
192
|
+
* @template M - The model type extending Model
|
193
|
+
* @template R - The repository type extending Repo<M, F, C>
|
194
|
+
* @template V - The relations metadata type extending RelationsMetadata
|
195
|
+
* @template F - The repository flags type
|
196
|
+
* @template C - The context type extending Context<F>
|
197
|
+
* @param {R} this - The repository instance
|
198
|
+
* @param {Context<F>} context - The context for the operation
|
199
|
+
* @param {V} data - The relations metadata
|
200
|
+
* @param key - The property key of the relationship
|
201
|
+
* @param {M} model - The model instance
|
202
|
+
* @return {Promise<void>} A promise that resolves when the operation is complete
|
203
|
+
* @function oneToManyOnCreate
|
204
|
+
* @memberOf module:core
|
205
|
+
* @mermaid
|
206
|
+
* sequenceDiagram
|
207
|
+
* participant Caller
|
208
|
+
* participant oneToManyOnCreate
|
209
|
+
* participant repositoryFromTypeMetadata
|
210
|
+
* participant createOrUpdate
|
211
|
+
* participant findPrimaryKey
|
212
|
+
* participant cacheModelForPopulate
|
213
|
+
*
|
214
|
+
* Caller->>oneToManyOnCreate: this, context, data, key, model
|
215
|
+
* oneToManyOnCreate->>oneToManyOnCreate: check if propertyValues exists and has length
|
216
|
+
* oneToManyOnCreate->>oneToManyOnCreate: check if all elements have same type
|
217
|
+
* oneToManyOnCreate->>oneToManyOnCreate: create uniqueValues set
|
218
|
+
*
|
219
|
+
* alt arrayType is not "object"
|
220
|
+
* oneToManyOnCreate->>repositoryFromTypeMetadata: model, key
|
221
|
+
* repositoryFromTypeMetadata-->>oneToManyOnCreate: repo
|
222
|
+
* loop for each id in uniqueValues
|
223
|
+
* oneToManyOnCreate->>repo: read(id)
|
224
|
+
* repo-->>oneToManyOnCreate: read
|
225
|
+
* oneToManyOnCreate->>cacheModelForPopulate: context, model, key, id, read
|
226
|
+
* end
|
227
|
+
* oneToManyOnCreate->>oneToManyOnCreate: set model[key] = [...uniqueValues]
|
228
|
+
* else arrayType is "object"
|
229
|
+
* oneToManyOnCreate->>findPrimaryKey: propertyValues[0]
|
230
|
+
* findPrimaryKey-->>oneToManyOnCreate: pkName
|
231
|
+
* oneToManyOnCreate->>oneToManyOnCreate: create result set
|
232
|
+
* loop for each m in propertyValues
|
233
|
+
* oneToManyOnCreate->>createOrUpdate: m, context
|
234
|
+
* createOrUpdate-->>oneToManyOnCreate: record
|
235
|
+
* oneToManyOnCreate->>cacheModelForPopulate: context, model, key, record[pkName], record
|
236
|
+
* oneToManyOnCreate->>oneToManyOnCreate: add record[pkName] to result
|
237
|
+
* end
|
238
|
+
* oneToManyOnCreate->>oneToManyOnCreate: set model[key] = [...result]
|
239
|
+
* end
|
240
|
+
*
|
241
|
+
* oneToManyOnCreate-->>Caller: void
|
242
|
+
*/
|
10
243
|
export declare function oneToManyOnCreate<M extends Model, R extends Repo<M, F, C>, V extends RelationsMetadata, F extends RepositoryFlags, C extends Context<F>>(this: R, context: Context<F>, data: V, key: keyof M, model: M): Promise<void>;
|
244
|
+
/**
|
245
|
+
* @description Handles one-to-many relationship updates
|
246
|
+
* @summary Processes a one-to-many relationship when updating a model, delegating to oneToManyOnCreate if cascade update is enabled
|
247
|
+
* @template M - The model type extending Model
|
248
|
+
* @template R - The repository type extending Repo<M, F, C>
|
249
|
+
* @template V - The relations metadata type extending RelationsMetadata
|
250
|
+
* @template F - The repository flags type
|
251
|
+
* @template C - The context type extending Context<F>
|
252
|
+
* @param {R} this - The repository instance
|
253
|
+
* @param {Context<F>} context - The context for the operation
|
254
|
+
* @param {V} data - The relations metadata
|
255
|
+
* @param key - The property key of the relationship
|
256
|
+
* @param {M} model - The model instance
|
257
|
+
* @return {Promise<void>} A promise that resolves when the operation is complete
|
258
|
+
* @function oneToManyOnUpdate
|
259
|
+
* @memberOf module:core
|
260
|
+
* @mermaid
|
261
|
+
* sequenceDiagram
|
262
|
+
* participant Caller
|
263
|
+
* participant oneToManyOnUpdate
|
264
|
+
* participant oneToManyOnCreate
|
265
|
+
*
|
266
|
+
* Caller->>oneToManyOnUpdate: this, context, data, key, model
|
267
|
+
* oneToManyOnUpdate->>oneToManyOnUpdate: check if cascade.update is CASCADE
|
268
|
+
*
|
269
|
+
* alt cascade.update is CASCADE
|
270
|
+
* oneToManyOnUpdate->>oneToManyOnCreate: apply(this, [context, data, key, model])
|
271
|
+
* oneToManyOnCreate-->>oneToManyOnUpdate: void
|
272
|
+
* end
|
273
|
+
*
|
274
|
+
* oneToManyOnUpdate-->>Caller: void
|
275
|
+
*/
|
11
276
|
export declare function oneToManyOnUpdate<M extends Model, R extends Repo<M, F, C>, V extends RelationsMetadata, F extends RepositoryFlags, C extends Context<F>>(this: R, context: Context<F>, data: V, key: keyof M, model: M): Promise<void>;
|
277
|
+
/**
|
278
|
+
* @description Handles one-to-many relationship deletion
|
279
|
+
* @summary Processes a one-to-many relationship when deleting a model, deleting all related models if cascade delete is enabled
|
280
|
+
* @template M - The model type extending Model
|
281
|
+
* @template R - The repository type extending Repo<M, F, C>
|
282
|
+
* @template V - The relations metadata type extending RelationsMetadata
|
283
|
+
* @template F - The repository flags type
|
284
|
+
* @template C - The context type extending Context<F>
|
285
|
+
* @param {R} this - The repository instance
|
286
|
+
* @param {Context<F>} context - The context for the operation
|
287
|
+
* @param {V} data - The relations metadata
|
288
|
+
* @param key - The property key of the relationship
|
289
|
+
* @param {M} model - The model instance
|
290
|
+
* @return {Promise<void>} A promise that resolves when the operation is complete
|
291
|
+
* @function oneToManyOnDelete
|
292
|
+
* @memberOf module:core
|
293
|
+
* @mermaid
|
294
|
+
* sequenceDiagram
|
295
|
+
* participant Caller
|
296
|
+
* participant oneToManyOnDelete
|
297
|
+
* participant Repository
|
298
|
+
* participant repositoryFromTypeMetadata
|
299
|
+
* participant cacheModelForPopulate
|
300
|
+
*
|
301
|
+
* Caller->>oneToManyOnDelete: this, context, data, key, model
|
302
|
+
* oneToManyOnDelete->>oneToManyOnDelete: check if cascade.delete is CASCADE
|
303
|
+
* oneToManyOnDelete->>oneToManyOnDelete: check if values exists and has length
|
304
|
+
* oneToManyOnDelete->>oneToManyOnDelete: check if all elements have same type
|
305
|
+
*
|
306
|
+
* alt isInstantiated (arrayType is "object")
|
307
|
+
* oneToManyOnDelete->>Repository: forModel(values[0])
|
308
|
+
* Repository-->>oneToManyOnDelete: repo
|
309
|
+
* else not instantiated
|
310
|
+
* oneToManyOnDelete->>repositoryFromTypeMetadata: model, key
|
311
|
+
* repositoryFromTypeMetadata-->>oneToManyOnDelete: repo
|
312
|
+
* end
|
313
|
+
*
|
314
|
+
* oneToManyOnDelete->>oneToManyOnDelete: create uniqueValues set
|
315
|
+
*
|
316
|
+
* loop for each id in uniqueValues
|
317
|
+
* oneToManyOnDelete->>repo: delete(id, context)
|
318
|
+
* repo-->>oneToManyOnDelete: deleted
|
319
|
+
* oneToManyOnDelete->>cacheModelForPopulate: context, model, key, id, deleted
|
320
|
+
* end
|
321
|
+
*
|
322
|
+
* oneToManyOnDelete->>oneToManyOnDelete: set model[key] = [...uniqueValues]
|
323
|
+
* oneToManyOnDelete-->>Caller: void
|
324
|
+
*/
|
12
325
|
export declare function oneToManyOnDelete<M extends Model, R extends Repo<M, F, C>, V extends RelationsMetadata, F extends RepositoryFlags, C extends Context<F>>(this: R, context: Context<F>, data: V, key: keyof M, model: M): Promise<void>;
|
326
|
+
/**
|
327
|
+
* @description Generates a key for caching populated model relationships
|
328
|
+
* @summary Creates a unique key for storing and retrieving populated model relationships in the cache
|
329
|
+
* @param {string} tableName - The name of the table or model
|
330
|
+
* @param {string} fieldName - The name of the field or property
|
331
|
+
* @param {string|number} id - The identifier of the related model
|
332
|
+
* @return {string} A dot-separated string that uniquely identifies the relationship
|
333
|
+
* @function getPopulateKey
|
334
|
+
* @memberOf module:core
|
335
|
+
*/
|
13
336
|
export declare function getPopulateKey(tableName: string, fieldName: string, id: string | number): string;
|
337
|
+
/**
|
338
|
+
* @description Caches a model for later population
|
339
|
+
* @summary Stores a model in the context cache for efficient retrieval during relationship population
|
340
|
+
* @template M - The model type extending Model
|
341
|
+
* @template F - The repository flags type
|
342
|
+
* @param {Context<F>} context - The context for the operation
|
343
|
+
* @param {M} parentModel - The parent model that contains the relationship
|
344
|
+
* @param propertyKey - The property key of the relationship
|
345
|
+
* @param {string | number} pkValue - The primary key value of the related model
|
346
|
+
* @param {any} cacheValue - The model instance to cache
|
347
|
+
* @return {Promise<any>} A promise that resolves with the result of the cache operation
|
348
|
+
* @function cacheModelForPopulate
|
349
|
+
* @memberOf module:core
|
350
|
+
*/
|
14
351
|
export declare function cacheModelForPopulate<M extends Model, F extends RepositoryFlags>(context: Context<F>, parentModel: M, propertyKey: keyof M | string, pkValue: string | number, cacheValue: any): Promise<Context<F & {
|
15
352
|
[x: string]: any;
|
16
353
|
}>>;
|
354
|
+
/**
|
355
|
+
* @description Populates a model's relationship
|
356
|
+
* @summary Retrieves and attaches related models to a model's relationship property
|
357
|
+
* @template M - The model type extending Model
|
358
|
+
* @template R - The repository type extending Repo<M, F, C>
|
359
|
+
* @template V - The relations metadata type extending RelationsMetadata
|
360
|
+
* @template F - The repository flags type
|
361
|
+
* @template C - The context type extending Context<F>
|
362
|
+
* @param {R} this - The repository instance
|
363
|
+
* @param {Context<F>} context - The context for the operation
|
364
|
+
* @param {V} data - The relations metadata
|
365
|
+
* @param key - The property key of the relationship
|
366
|
+
* @param {M} model - The model instance
|
367
|
+
* @return {Promise<void>} A promise that resolves when the operation is complete
|
368
|
+
* @function populate
|
369
|
+
* @memberOf module:core
|
370
|
+
* @mermaid
|
371
|
+
* sequenceDiagram
|
372
|
+
* participant Caller
|
373
|
+
* participant populate
|
374
|
+
* participant fetchPopulateValues
|
375
|
+
* participant getPopulateKey
|
376
|
+
* participant Context
|
377
|
+
* participant repositoryFromTypeMetadata
|
378
|
+
*
|
379
|
+
* Caller->>populate: this, context, data, key, model
|
380
|
+
* populate->>populate: check if data.populate is true
|
381
|
+
* populate->>populate: get nested value and check if it exists
|
382
|
+
*
|
383
|
+
* populate->>fetchPopulateValues: context, model, key, isArr ? nested : [nested]
|
384
|
+
*
|
385
|
+
* fetchPopulateValues->>fetchPopulateValues: initialize variables
|
386
|
+
*
|
387
|
+
* loop for each proKeyValue in propKeyValues
|
388
|
+
* fetchPopulateValues->>getPopulateKey: model.constructor.name, propName, proKeyValue
|
389
|
+
* getPopulateKey-->>fetchPopulateValues: cacheKey
|
390
|
+
*
|
391
|
+
* alt try to get from cache
|
392
|
+
* fetchPopulateValues->>Context: get(cacheKey)
|
393
|
+
* Context-->>fetchPopulateValues: val
|
394
|
+
* else catch error
|
395
|
+
* fetchPopulateValues->>repositoryFromTypeMetadata: model, propName
|
396
|
+
* repositoryFromTypeMetadata-->>fetchPopulateValues: repo
|
397
|
+
* fetchPopulateValues->>repo: read(proKeyValue)
|
398
|
+
* repo-->>fetchPopulateValues: val
|
399
|
+
* end
|
400
|
+
*
|
401
|
+
* fetchPopulateValues->>fetchPopulateValues: add val to results
|
402
|
+
* end
|
403
|
+
*
|
404
|
+
* fetchPopulateValues-->>populate: results
|
405
|
+
* populate->>populate: set model[key] = isArr ? res : res[0]
|
406
|
+
* populate-->>Caller: void
|
407
|
+
*/
|
17
408
|
export declare function populate<M extends Model, R extends Repo<M, F, C>, V extends RelationsMetadata, F extends RepositoryFlags, C extends Context<F>>(this: R, context: Context<F>, data: V, key: keyof M, model: M): Promise<void>;
|
409
|
+
/**
|
410
|
+
* @description Retrieves a repository for a model property based on its type metadata
|
411
|
+
* @summary Examines a model property's type metadata to determine the appropriate repository for related models
|
412
|
+
* @template M - The model type extending Model
|
413
|
+
* @param {any} model - The model instance containing the property
|
414
|
+
* @param propertyKey - The property key to examine
|
415
|
+
* @return {Repo<M>} A repository for the model type associated with the property
|
416
|
+
* @function repositoryFromTypeMetadata
|
417
|
+
* @memberOf module:core
|
418
|
+
* @mermaid
|
419
|
+
* sequenceDiagram
|
420
|
+
* participant Caller
|
421
|
+
* participant repositoryFromTypeMetadata
|
422
|
+
* participant Reflect
|
423
|
+
* participant Validation
|
424
|
+
* participant Model
|
425
|
+
* participant Repository
|
426
|
+
*
|
427
|
+
* Caller->>repositoryFromTypeMetadata: model, propertyKey
|
428
|
+
*
|
429
|
+
* repositoryFromTypeMetadata->>Validation: key(Array.isArray(model[propertyKey]) ? ValidationKeys.LIST : ValidationKeys.TYPE)
|
430
|
+
* Validation-->>repositoryFromTypeMetadata: validationKey
|
431
|
+
*
|
432
|
+
* repositoryFromTypeMetadata->>Reflect: getMetadata(validationKey, model, propertyKey)
|
433
|
+
* Reflect-->>repositoryFromTypeMetadata: types
|
434
|
+
*
|
435
|
+
* repositoryFromTypeMetadata->>repositoryFromTypeMetadata: determine customTypes based on property type
|
436
|
+
* repositoryFromTypeMetadata->>repositoryFromTypeMetadata: check if types and customTypes exist
|
437
|
+
*
|
438
|
+
* repositoryFromTypeMetadata->>repositoryFromTypeMetadata: create allowedTypes array
|
439
|
+
* repositoryFromTypeMetadata->>repositoryFromTypeMetadata: find constructorName not in commomTypes
|
440
|
+
* repositoryFromTypeMetadata->>repositoryFromTypeMetadata: check if constructorName exists
|
441
|
+
*
|
442
|
+
* repositoryFromTypeMetadata->>Model: get(constructorName)
|
443
|
+
* Model-->>repositoryFromTypeMetadata: constructor
|
444
|
+
* repositoryFromTypeMetadata->>repositoryFromTypeMetadata: check if constructor exists
|
445
|
+
*
|
446
|
+
* repositoryFromTypeMetadata->>Repository: forModel(constructor)
|
447
|
+
* Repository-->>repositoryFromTypeMetadata: repo
|
448
|
+
*
|
449
|
+
* repositoryFromTypeMetadata-->>Caller: repo
|
450
|
+
*/
|
18
451
|
export declare function repositoryFromTypeMetadata<M extends Model>(model: any, propertyKey: string | keyof M): Repo<M>;
|