@decaf-ts/for-fabric 0.0.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 +22 -0
- package/README.md +647 -0
- package/dist/for-fabric.cjs +6223 -0
- package/dist/for-fabric.esm.cjs +6180 -0
- package/lib/client/FabricClientAdapter.cjs +760 -0
- package/lib/client/FabricClientAdapter.d.ts +381 -0
- package/lib/client/FabricClientDispatch.cjs +186 -0
- package/lib/client/FabricClientDispatch.d.ts +125 -0
- package/lib/client/FabricClientRepository.cjs +131 -0
- package/lib/client/FabricClientRepository.d.ts +100 -0
- package/lib/client/erc20/erc20ClientRepository.cjs +343 -0
- package/lib/client/erc20/erc20ClientRepository.d.ts +254 -0
- package/lib/client/fabric-fs.cjs +234 -0
- package/lib/client/fabric-fs.d.ts +92 -0
- package/lib/client/index.cjs +30 -0
- package/lib/client/index.d.ts +13 -0
- package/lib/client/logging.cjs +102 -0
- package/lib/client/logging.d.ts +60 -0
- package/lib/client/services/LoggedService.cjs +47 -0
- package/lib/client/services/LoggedService.d.ts +42 -0
- package/lib/client/services/constants.cjs +3 -0
- package/lib/client/services/constants.d.ts +15 -0
- package/lib/client/services/enrollementService.cjs +344 -0
- package/lib/client/services/enrollementService.d.ts +176 -0
- package/lib/client/services/index.cjs +18 -0
- package/lib/client/services/index.d.ts +1 -0
- package/lib/contracts/ContractAdapter.cjs +730 -0
- package/lib/contracts/ContractAdapter.d.ts +296 -0
- package/lib/contracts/ContractContext.cjs +85 -0
- package/lib/contracts/ContractContext.d.ts +64 -0
- package/lib/contracts/ContractPrivateDataAdapter.cjs +281 -0
- package/lib/contracts/ContractPrivateDataAdapter.d.ts +74 -0
- package/lib/contracts/FabricConstruction.cjs +441 -0
- package/lib/contracts/FabricConstruction.d.ts +304 -0
- package/lib/contracts/FabricContractRepository.cjs +306 -0
- package/lib/contracts/FabricContractRepository.d.ts +162 -0
- package/lib/contracts/FabricContractRepositoryObservableHandler.cjs +85 -0
- package/lib/contracts/FabricContractRepositoryObservableHandler.d.ts +62 -0
- package/lib/contracts/FabricContractSequence.cjs +139 -0
- package/lib/contracts/FabricContractSequence.d.ts +61 -0
- package/lib/contracts/FabricContractStatement.cjs +119 -0
- package/lib/contracts/FabricContractStatement.d.ts +34 -0
- package/lib/contracts/PrivateSequence.cjs +36 -0
- package/lib/contracts/PrivateSequence.d.ts +15 -0
- package/lib/contracts/crud/crud-contract.cjs +257 -0
- package/lib/contracts/crud/crud-contract.d.ts +168 -0
- package/lib/contracts/crud/index.cjs +19 -0
- package/lib/contracts/crud/index.d.ts +2 -0
- package/lib/contracts/crud/serialized-crud-contract.cjs +172 -0
- package/lib/contracts/crud/serialized-crud-contract.d.ts +37 -0
- package/lib/contracts/erc20/erc20contract.cjs +569 -0
- package/lib/contracts/erc20/erc20contract.d.ts +151 -0
- package/lib/contracts/erc20/index.cjs +21 -0
- package/lib/contracts/erc20/index.d.ts +2 -0
- package/lib/contracts/erc20/models.cjs +209 -0
- package/lib/contracts/erc20/models.d.ts +114 -0
- package/lib/contracts/index.cjs +32 -0
- package/lib/contracts/index.d.ts +15 -0
- package/lib/contracts/logging.cjs +96 -0
- package/lib/contracts/logging.d.ts +49 -0
- package/lib/contracts/private-data.cjs +121 -0
- package/lib/contracts/private-data.d.ts +16 -0
- package/lib/contracts/types.cjs +3 -0
- package/lib/contracts/types.d.ts +26 -0
- package/lib/esm/client/FabricClientAdapter.d.ts +381 -0
- package/lib/esm/client/FabricClientAdapter.js +723 -0
- package/lib/esm/client/FabricClientDispatch.d.ts +125 -0
- package/lib/esm/client/FabricClientDispatch.js +182 -0
- package/lib/esm/client/FabricClientRepository.d.ts +100 -0
- package/lib/esm/client/FabricClientRepository.js +127 -0
- package/lib/esm/client/erc20/erc20ClientRepository.d.ts +254 -0
- package/lib/esm/client/erc20/erc20ClientRepository.js +339 -0
- package/lib/esm/client/fabric-fs.d.ts +92 -0
- package/lib/esm/client/fabric-fs.js +191 -0
- package/lib/esm/client/index.d.ts +13 -0
- package/lib/esm/client/index.js +14 -0
- package/lib/esm/client/logging.d.ts +60 -0
- package/lib/esm/client/logging.js +98 -0
- package/lib/esm/client/services/LoggedService.d.ts +42 -0
- package/lib/esm/client/services/LoggedService.js +43 -0
- package/lib/esm/client/services/constants.d.ts +15 -0
- package/lib/esm/client/services/constants.js +2 -0
- package/lib/esm/client/services/enrollementService.d.ts +176 -0
- package/lib/esm/client/services/enrollementService.js +337 -0
- package/lib/esm/client/services/index.d.ts +1 -0
- package/lib/esm/client/services/index.js +2 -0
- package/lib/esm/contracts/ContractAdapter.d.ts +296 -0
- package/lib/esm/contracts/ContractAdapter.js +724 -0
- package/lib/esm/contracts/ContractContext.d.ts +64 -0
- package/lib/esm/contracts/ContractContext.js +81 -0
- package/lib/esm/contracts/ContractPrivateDataAdapter.d.ts +74 -0
- package/lib/esm/contracts/ContractPrivateDataAdapter.js +277 -0
- package/lib/esm/contracts/FabricConstruction.d.ts +304 -0
- package/lib/esm/contracts/FabricConstruction.js +433 -0
- package/lib/esm/contracts/FabricContractRepository.d.ts +162 -0
- package/lib/esm/contracts/FabricContractRepository.js +302 -0
- package/lib/esm/contracts/FabricContractRepositoryObservableHandler.d.ts +62 -0
- package/lib/esm/contracts/FabricContractRepositoryObservableHandler.js +81 -0
- package/lib/esm/contracts/FabricContractSequence.d.ts +61 -0
- package/lib/esm/contracts/FabricContractSequence.js +135 -0
- package/lib/esm/contracts/FabricContractStatement.d.ts +34 -0
- package/lib/esm/contracts/FabricContractStatement.js +115 -0
- package/lib/esm/contracts/PrivateSequence.d.ts +15 -0
- package/lib/esm/contracts/PrivateSequence.js +33 -0
- package/lib/esm/contracts/crud/crud-contract.d.ts +168 -0
- package/lib/esm/contracts/crud/crud-contract.js +253 -0
- package/lib/esm/contracts/crud/index.d.ts +2 -0
- package/lib/esm/contracts/crud/index.js +3 -0
- package/lib/esm/contracts/crud/serialized-crud-contract.d.ts +37 -0
- package/lib/esm/contracts/crud/serialized-crud-contract.js +168 -0
- package/lib/esm/contracts/erc20/erc20contract.d.ts +151 -0
- package/lib/esm/contracts/erc20/erc20contract.js +565 -0
- package/lib/esm/contracts/erc20/index.d.ts +2 -0
- package/lib/esm/contracts/erc20/index.js +4 -0
- package/lib/esm/contracts/erc20/models.d.ts +114 -0
- package/lib/esm/contracts/erc20/models.js +206 -0
- package/lib/esm/contracts/index.d.ts +15 -0
- package/lib/esm/contracts/index.js +16 -0
- package/lib/esm/contracts/logging.d.ts +49 -0
- package/lib/esm/contracts/logging.js +92 -0
- package/lib/esm/contracts/private-data.d.ts +16 -0
- package/lib/esm/contracts/private-data.js +113 -0
- package/lib/esm/contracts/types.d.ts +26 -0
- package/lib/esm/contracts/types.js +2 -0
- package/lib/esm/index.d.ts +8 -0
- package/lib/esm/index.js +9 -0
- package/lib/esm/shared/ClientSerializer.d.ts +52 -0
- package/lib/esm/shared/ClientSerializer.js +80 -0
- package/lib/esm/shared/DeterministicSerializer.d.ts +40 -0
- package/lib/esm/shared/DeterministicSerializer.js +50 -0
- package/lib/esm/shared/SimpleDeterministicSerializer.d.ts +7 -0
- package/lib/esm/shared/SimpleDeterministicSerializer.js +42 -0
- package/lib/esm/shared/constants.d.ts +39 -0
- package/lib/esm/shared/constants.js +42 -0
- package/lib/esm/shared/crypto.d.ts +107 -0
- package/lib/esm/shared/crypto.js +331 -0
- package/lib/esm/shared/decorators.d.ts +24 -0
- package/lib/esm/shared/decorators.js +98 -0
- package/lib/esm/shared/erc20/erc20-constants.d.ts +25 -0
- package/lib/esm/shared/erc20/erc20-constants.js +27 -0
- package/lib/esm/shared/errors.d.ts +116 -0
- package/lib/esm/shared/errors.js +132 -0
- package/lib/esm/shared/events.d.ts +39 -0
- package/lib/esm/shared/events.js +47 -0
- package/lib/esm/shared/fabric-types.d.ts +33 -0
- package/lib/esm/shared/fabric-types.js +2 -0
- package/lib/esm/shared/index.d.ts +13 -0
- package/lib/esm/shared/index.js +14 -0
- package/lib/esm/shared/interfaces/Checkable.d.ts +21 -0
- package/lib/esm/shared/interfaces/Checkable.js +2 -0
- package/lib/esm/shared/math.d.ts +34 -0
- package/lib/esm/shared/math.js +61 -0
- package/lib/esm/shared/model/Identity.d.ts +42 -0
- package/lib/esm/shared/model/Identity.js +78 -0
- package/lib/esm/shared/model/IdentityCredentials.d.ts +41 -0
- package/lib/esm/shared/model/IdentityCredentials.js +74 -0
- package/lib/esm/shared/model/index.d.ts +1 -0
- package/lib/esm/shared/model/index.js +2 -0
- package/lib/esm/shared/model/utils.d.ts +60 -0
- package/lib/esm/shared/model/utils.js +108 -0
- package/lib/esm/shared/types.d.ts +79 -0
- package/lib/esm/shared/types.js +2 -0
- package/lib/esm/shared/utils.d.ts +55 -0
- package/lib/esm/shared/utils.js +148 -0
- package/lib/index.cjs +25 -0
- package/lib/index.d.ts +8 -0
- package/lib/shared/ClientSerializer.cjs +84 -0
- package/lib/shared/ClientSerializer.d.ts +52 -0
- package/lib/shared/DeterministicSerializer.cjs +54 -0
- package/lib/shared/DeterministicSerializer.d.ts +40 -0
- package/lib/shared/SimpleDeterministicSerializer.cjs +46 -0
- package/lib/shared/SimpleDeterministicSerializer.d.ts +7 -0
- package/lib/shared/constants.cjs +45 -0
- package/lib/shared/constants.d.ts +39 -0
- package/lib/shared/crypto.cjs +369 -0
- package/lib/shared/crypto.d.ts +107 -0
- package/lib/shared/decorators.cjs +105 -0
- package/lib/shared/decorators.d.ts +24 -0
- package/lib/shared/erc20/erc20-constants.cjs +30 -0
- package/lib/shared/erc20/erc20-constants.d.ts +25 -0
- package/lib/shared/errors.cjs +142 -0
- package/lib/shared/errors.d.ts +116 -0
- package/lib/shared/events.cjs +51 -0
- package/lib/shared/events.d.ts +39 -0
- package/lib/shared/fabric-types.cjs +4 -0
- package/lib/shared/fabric-types.d.ts +33 -0
- package/lib/shared/index.cjs +30 -0
- package/lib/shared/index.d.ts +13 -0
- package/lib/shared/interfaces/Checkable.cjs +3 -0
- package/lib/shared/interfaces/Checkable.d.ts +21 -0
- package/lib/shared/math.cjs +66 -0
- package/lib/shared/math.d.ts +34 -0
- package/lib/shared/model/Identity.cjs +81 -0
- package/lib/shared/model/Identity.d.ts +42 -0
- package/lib/shared/model/IdentityCredentials.cjs +77 -0
- package/lib/shared/model/IdentityCredentials.d.ts +41 -0
- package/lib/shared/model/index.cjs +18 -0
- package/lib/shared/model/index.d.ts +1 -0
- package/lib/shared/model/utils.cjs +114 -0
- package/lib/shared/model/utils.d.ts +60 -0
- package/lib/shared/types.cjs +3 -0
- package/lib/shared/types.d.ts +79 -0
- package/lib/shared/utils.cjs +185 -0
- package/lib/shared/utils.d.ts +55 -0
- package/package.json +166 -0
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
import { RelationsMetadata, Repo } from "@decaf-ts/core";
|
|
2
|
+
import { Model } from "@decaf-ts/decorator-validation";
|
|
3
|
+
import { FabricContractFlags } from "./types";
|
|
4
|
+
import { Context } from "@decaf-ts/db-decorators";
|
|
5
|
+
/**
|
|
6
|
+
* @description Handles one-to-one relationship creation
|
|
7
|
+
* @summary Processes a one-to-one relationship when creating a model, either by referencing an existing model or creating a new one
|
|
8
|
+
* @template M - The model type extending Model
|
|
9
|
+
* @template R - The repository type extending Repo<M, F, C>
|
|
10
|
+
* @template V - The relations metadata type extending RelationsMetadata
|
|
11
|
+
* @template F - The repository flags type
|
|
12
|
+
* @template C - The context type extending Context<F>
|
|
13
|
+
* @param {R} this - The repository instance
|
|
14
|
+
* @param {Context<F>} context - The context for the operation
|
|
15
|
+
* @param {V} data - The relations metadata
|
|
16
|
+
* @param {string} key - The property key of the relationship
|
|
17
|
+
* @param {M} model - The model instance
|
|
18
|
+
* @return {Promise<void>} A promise that resolves when the operation is complete
|
|
19
|
+
* @function oneToOneOnCreate
|
|
20
|
+
* @memberOf module:core
|
|
21
|
+
* @mermaid
|
|
22
|
+
* sequenceDiagram
|
|
23
|
+
* participant Caller
|
|
24
|
+
* participant oneToOneOnCreate
|
|
25
|
+
* participant repositoryFromTypeMetadata
|
|
26
|
+
* participant Model
|
|
27
|
+
* participant Repository
|
|
28
|
+
* participant cacheModelForPopulate
|
|
29
|
+
*
|
|
30
|
+
* Caller->>oneToOneOnCreate: this, context, data, key, model
|
|
31
|
+
* oneToOneOnCreate->>oneToOneOnCreate: check if propertyValue exists
|
|
32
|
+
*
|
|
33
|
+
* alt propertyValue is not an object
|
|
34
|
+
* oneToOneOnCreate->>repositoryFromTypeMetadata: model, key
|
|
35
|
+
* repositoryFromTypeMetadata-->>oneToOneOnCreate: innerRepo
|
|
36
|
+
* oneToOneOnCreate->>innerRepo: read(propertyValue)
|
|
37
|
+
* innerRepo-->>oneToOneOnCreate: read
|
|
38
|
+
* oneToOneOnCreate->>cacheModelForPopulate: context, model, key, propertyValue, read
|
|
39
|
+
* oneToOneOnCreate->>oneToOneOnCreate: set model[key] = propertyValue
|
|
40
|
+
* else propertyValue is an object
|
|
41
|
+
* oneToOneOnCreate->>Model: get(data.class)
|
|
42
|
+
* Model-->>oneToOneOnCreate: constructor
|
|
43
|
+
* oneToOneOnCreate->>Repository: forModel(constructor)
|
|
44
|
+
* Repository-->>oneToOneOnCreate: repo
|
|
45
|
+
* oneToOneOnCreate->>repo: create(propertyValue)
|
|
46
|
+
* repo-->>oneToOneOnCreate: created
|
|
47
|
+
* oneToOneOnCreate->>findPrimaryKey: created
|
|
48
|
+
* findPrimaryKey-->>oneToOneOnCreate: pk
|
|
49
|
+
* oneToOneOnCreate->>cacheModelForPopulate: context, model, key, created[pk], created
|
|
50
|
+
* oneToOneOnCreate->>oneToOneOnCreate: set model[key] = created[pk]
|
|
51
|
+
* end
|
|
52
|
+
*
|
|
53
|
+
* oneToOneOnCreate-->>Caller: void
|
|
54
|
+
*/
|
|
55
|
+
export declare function oneToOneOnCreate<M extends Model, R extends Repo<M, F, C>, V extends RelationsMetadata, F extends FabricContractFlags, C extends Context<F>>(this: R, context: Context<F>, data: V, key: keyof M, model: M): Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* @description Handles one-to-one relationship updates
|
|
58
|
+
* @summary Processes a one-to-one relationship when updating a model, either by referencing an existing model or updating the related model
|
|
59
|
+
* @template M - The model type extending Model
|
|
60
|
+
* @template R - The repository type extending Repo<M, F, C>
|
|
61
|
+
* @template V - The relations metadata type extending RelationsMetadata
|
|
62
|
+
* @template F - The repository flags type
|
|
63
|
+
* @template C - The context type extending Context<F>
|
|
64
|
+
* @param {R} this - The repository instance
|
|
65
|
+
* @param {Context<F>} context - The context for the operation
|
|
66
|
+
* @param {V} data - The relations metadata
|
|
67
|
+
* @param key - The property key of the relationship
|
|
68
|
+
* @param {M} model - The model instance
|
|
69
|
+
* @return {Promise<void>} A promise that resolves when the operation is complete
|
|
70
|
+
* @function oneToOneOnUpdate
|
|
71
|
+
* @memberOf module:core
|
|
72
|
+
* @mermaid
|
|
73
|
+
* sequenceDiagram
|
|
74
|
+
* participant Caller
|
|
75
|
+
* participant oneToOneOnUpdate
|
|
76
|
+
* participant repositoryFromTypeMetadata
|
|
77
|
+
* participant createOrUpdate
|
|
78
|
+
* participant findPrimaryKey
|
|
79
|
+
* participant cacheModelForPopulate
|
|
80
|
+
*
|
|
81
|
+
* Caller->>oneToOneOnUpdate: this, context, data, key, model
|
|
82
|
+
* oneToOneOnUpdate->>oneToOneOnUpdate: check if propertyValue exists
|
|
83
|
+
* oneToOneOnUpdate->>oneToOneOnUpdate: check if cascade.update is CASCADE
|
|
84
|
+
*
|
|
85
|
+
* alt propertyValue is not an object
|
|
86
|
+
* oneToOneOnUpdate->>repositoryFromTypeMetadata: model, key
|
|
87
|
+
* repositoryFromTypeMetadata-->>oneToOneOnUpdate: innerRepo
|
|
88
|
+
* oneToOneOnUpdate->>innerRepo: read(propertyValue)
|
|
89
|
+
* innerRepo-->>oneToOneOnUpdate: read
|
|
90
|
+
* oneToOneOnUpdate->>cacheModelForPopulate: context, model, key, propertyValue, read
|
|
91
|
+
* oneToOneOnUpdate->>oneToOneOnUpdate: set model[key] = propertyValue
|
|
92
|
+
* else propertyValue is an object
|
|
93
|
+
* oneToOneOnUpdate->>createOrUpdate: model[key], context
|
|
94
|
+
* createOrUpdate-->>oneToOneOnUpdate: updated
|
|
95
|
+
* oneToOneOnUpdate->>findPrimaryKey: updated
|
|
96
|
+
* findPrimaryKey-->>oneToOneOnUpdate: pk
|
|
97
|
+
* oneToOneOnUpdate->>cacheModelForPopulate: context, model, key, updated[pk], updated
|
|
98
|
+
* oneToOneOnUpdate->>oneToOneOnUpdate: set model[key] = updated[pk]
|
|
99
|
+
* end
|
|
100
|
+
*
|
|
101
|
+
* oneToOneOnUpdate-->>Caller: void
|
|
102
|
+
*/
|
|
103
|
+
export declare function oneToOneOnUpdate<M extends Model, R extends Repo<M, F, C>, V extends RelationsMetadata, F extends FabricContractFlags, C extends Context<F>>(this: R, context: Context<F>, data: V, key: keyof M, model: M): Promise<void>;
|
|
104
|
+
/**
|
|
105
|
+
* @description Handles one-to-one relationship deletion
|
|
106
|
+
* @summary Processes a one-to-one relationship when deleting a model, deleting the related model if cascade is enabled
|
|
107
|
+
* @template M - The model type extending Model
|
|
108
|
+
* @template R - The repository type extending Repo<M, F, C>
|
|
109
|
+
* @template V - The relations metadata type extending RelationsMetadata
|
|
110
|
+
* @template F - The repository flags type
|
|
111
|
+
* @template C - The context type extending Context<F>
|
|
112
|
+
* @param {R} this - The repository instance
|
|
113
|
+
* @param {Context<F>} context - The context for the operation
|
|
114
|
+
* @param {V} data - The relations metadata
|
|
115
|
+
* @param key - The property key of the relationship
|
|
116
|
+
* @param {M} model - The model instance
|
|
117
|
+
* @return {Promise<void>} A promise that resolves when the operation is complete
|
|
118
|
+
* @function oneToOneOnDelete
|
|
119
|
+
* @memberOf module:core
|
|
120
|
+
* @mermaid
|
|
121
|
+
* sequenceDiagram
|
|
122
|
+
* participant Caller
|
|
123
|
+
* participant oneToOneOnDelete
|
|
124
|
+
* participant repositoryFromTypeMetadata
|
|
125
|
+
* participant cacheModelForPopulate
|
|
126
|
+
*
|
|
127
|
+
* Caller->>oneToOneOnDelete: this, context, data, key, model
|
|
128
|
+
* oneToOneOnDelete->>oneToOneOnDelete: check if propertyValue exists
|
|
129
|
+
* oneToOneOnDelete->>oneToOneOnDelete: check if cascade.update is CASCADE
|
|
130
|
+
*
|
|
131
|
+
* oneToOneOnDelete->>repositoryFromTypeMetadata: model, key
|
|
132
|
+
* repositoryFromTypeMetadata-->>oneToOneOnDelete: innerRepo
|
|
133
|
+
*
|
|
134
|
+
* alt propertyValue is not a Model instance
|
|
135
|
+
* oneToOneOnDelete->>innerRepo: delete(model[key], context)
|
|
136
|
+
* innerRepo-->>oneToOneOnDelete: deleted
|
|
137
|
+
* else propertyValue is a Model instance
|
|
138
|
+
* oneToOneOnDelete->>innerRepo: delete(model[key][innerRepo.pk], context)
|
|
139
|
+
* innerRepo-->>oneToOneOnDelete: deleted
|
|
140
|
+
* end
|
|
141
|
+
*
|
|
142
|
+
* oneToOneOnDelete->>cacheModelForPopulate: context, model, key, deleted[innerRepo.pk], deleted
|
|
143
|
+
* oneToOneOnDelete-->>Caller: void
|
|
144
|
+
*/
|
|
145
|
+
export declare function oneToOneOnDelete<M extends Model, R extends Repo<M, F, C>, V extends RelationsMetadata, F extends FabricContractFlags, C extends Context<F>>(this: R, context: Context<F>, data: V, key: keyof M, model: M): Promise<void>;
|
|
146
|
+
/**
|
|
147
|
+
* @description Handles one-to-many relationship creation
|
|
148
|
+
* @summary Processes a one-to-many relationship when creating a model, either by referencing existing models or creating new ones
|
|
149
|
+
* @template M - The model type extending Model
|
|
150
|
+
* @template R - The repository type extending Repo<M, F, C>
|
|
151
|
+
* @template V - The relations metadata type extending RelationsMetadata
|
|
152
|
+
* @template F - The repository flags type
|
|
153
|
+
* @template C - The context type extending Context<F>
|
|
154
|
+
* @param {R} this - The repository instance
|
|
155
|
+
* @param {Context<F>} context - The context for the operation
|
|
156
|
+
* @param {V} data - The relations metadata
|
|
157
|
+
* @param key - The property key of the relationship
|
|
158
|
+
* @param {M} model - The model instance
|
|
159
|
+
* @return {Promise<void>} A promise that resolves when the operation is complete
|
|
160
|
+
* @function oneToManyOnCreate
|
|
161
|
+
* @memberOf module:core
|
|
162
|
+
* @mermaid
|
|
163
|
+
* sequenceDiagram
|
|
164
|
+
* participant Caller
|
|
165
|
+
* participant oneToManyOnCreate
|
|
166
|
+
* participant repositoryFromTypeMetadata
|
|
167
|
+
* participant createOrUpdate
|
|
168
|
+
* participant findPrimaryKey
|
|
169
|
+
* participant cacheModelForPopulate
|
|
170
|
+
*
|
|
171
|
+
* Caller->>oneToManyOnCreate: this, context, data, key, model
|
|
172
|
+
* oneToManyOnCreate->>oneToManyOnCreate: check if propertyValues exists and has length
|
|
173
|
+
* oneToManyOnCreate->>oneToManyOnCreate: check if all elements have same type
|
|
174
|
+
* oneToManyOnCreate->>oneToManyOnCreate: create uniqueValues set
|
|
175
|
+
*
|
|
176
|
+
* alt arrayType is not "object"
|
|
177
|
+
* oneToManyOnCreate->>repositoryFromTypeMetadata: model, key
|
|
178
|
+
* repositoryFromTypeMetadata-->>oneToManyOnCreate: repo
|
|
179
|
+
* loop for each id in uniqueValues
|
|
180
|
+
* oneToManyOnCreate->>repo: read(id)
|
|
181
|
+
* repo-->>oneToManyOnCreate: read
|
|
182
|
+
* oneToManyOnCreate->>cacheModelForPopulate: context, model, key, id, read
|
|
183
|
+
* end
|
|
184
|
+
* oneToManyOnCreate->>oneToManyOnCreate: set model[key] = [...uniqueValues]
|
|
185
|
+
* else arrayType is "object"
|
|
186
|
+
* oneToManyOnCreate->>findPrimaryKey: propertyValues[0]
|
|
187
|
+
* findPrimaryKey-->>oneToManyOnCreate: pkName
|
|
188
|
+
* oneToManyOnCreate->>oneToManyOnCreate: create result set
|
|
189
|
+
* loop for each m in propertyValues
|
|
190
|
+
* oneToManyOnCreate->>createOrUpdate: m, context
|
|
191
|
+
* createOrUpdate-->>oneToManyOnCreate: record
|
|
192
|
+
* oneToManyOnCreate->>cacheModelForPopulate: context, model, key, record[pkName], record
|
|
193
|
+
* oneToManyOnCreate->>oneToManyOnCreate: add record[pkName] to result
|
|
194
|
+
* end
|
|
195
|
+
* oneToManyOnCreate->>oneToManyOnCreate: set model[key] = [...result]
|
|
196
|
+
* end
|
|
197
|
+
*
|
|
198
|
+
* oneToManyOnCreate-->>Caller: void
|
|
199
|
+
*/
|
|
200
|
+
export declare function oneToManyOnCreate<M extends Model, R extends Repo<M, F, C>, V extends RelationsMetadata, F extends FabricContractFlags, C extends Context<F>>(this: R, context: Context<F>, data: V, key: keyof M, model: M): Promise<void>;
|
|
201
|
+
/**
|
|
202
|
+
* @description Handles one-to-many relationship deletion
|
|
203
|
+
* @summary Processes a one-to-many relationship when deleting a model, deleting all related models if cascade delete is enabled
|
|
204
|
+
* @template M - The model type extending Model
|
|
205
|
+
* @template R - The repository type extending Repo<M, F, C>
|
|
206
|
+
* @template V - The relations metadata type extending RelationsMetadata
|
|
207
|
+
* @template F - The repository flags type
|
|
208
|
+
* @template C - The context type extending Context<F>
|
|
209
|
+
* @param {R} this - The repository instance
|
|
210
|
+
* @param {Context<F>} context - The context for the operation
|
|
211
|
+
* @param {V} data - The relations metadata
|
|
212
|
+
* @param key - The property key of the relationship
|
|
213
|
+
* @param {M} model - The model instance
|
|
214
|
+
* @return {Promise<void>} A promise that resolves when the operation is complete
|
|
215
|
+
* @function oneToManyOnDelete
|
|
216
|
+
* @memberOf module:core
|
|
217
|
+
* @mermaid
|
|
218
|
+
* sequenceDiagram
|
|
219
|
+
* participant Caller
|
|
220
|
+
* participant oneToManyOnDelete
|
|
221
|
+
* participant Repository
|
|
222
|
+
* participant repositoryFromTypeMetadata
|
|
223
|
+
* participant cacheModelForPopulate
|
|
224
|
+
*
|
|
225
|
+
* Caller->>oneToManyOnDelete: this, context, data, key, model
|
|
226
|
+
* oneToManyOnDelete->>oneToManyOnDelete: check if cascade.delete is CASCADE
|
|
227
|
+
* oneToManyOnDelete->>oneToManyOnDelete: check if values exists and has length
|
|
228
|
+
* oneToManyOnDelete->>oneToManyOnDelete: check if all elements have same type
|
|
229
|
+
*
|
|
230
|
+
* alt isInstantiated (arrayType is "object")
|
|
231
|
+
* oneToManyOnDelete->>Repository: forModel(values[0])
|
|
232
|
+
* Repository-->>oneToManyOnDelete: repo
|
|
233
|
+
* else not instantiated
|
|
234
|
+
* oneToManyOnDelete->>repositoryFromTypeMetadata: model, key
|
|
235
|
+
* repositoryFromTypeMetadata-->>oneToManyOnDelete: repo
|
|
236
|
+
* end
|
|
237
|
+
*
|
|
238
|
+
* oneToManyOnDelete->>oneToManyOnDelete: create uniqueValues set
|
|
239
|
+
*
|
|
240
|
+
* loop for each id in uniqueValues
|
|
241
|
+
* oneToManyOnDelete->>repo: delete(id, context)
|
|
242
|
+
* repo-->>oneToManyOnDelete: deleted
|
|
243
|
+
* oneToManyOnDelete->>cacheModelForPopulate: context, model, key, id, deleted
|
|
244
|
+
* end
|
|
245
|
+
*
|
|
246
|
+
* oneToManyOnDelete->>oneToManyOnDelete: set model[key] = [...uniqueValues]
|
|
247
|
+
* oneToManyOnDelete-->>Caller: void
|
|
248
|
+
*/
|
|
249
|
+
export declare function oneToManyOnDelete<M extends Model, R extends Repo<M, F, C>, V extends RelationsMetadata, F extends FabricContractFlags, C extends Context<F>>(this: R, context: Context<F>, data: V, key: keyof M, model: M): Promise<void>;
|
|
250
|
+
/**
|
|
251
|
+
* @description Populates a model's relationship
|
|
252
|
+
* @summary Retrieves and attaches related models to a model's relationship property
|
|
253
|
+
* @template M - The model type extending Model
|
|
254
|
+
* @template R - The repository type extending Repo<M, F, C>
|
|
255
|
+
* @template V - The relations metadata type extending RelationsMetadata
|
|
256
|
+
* @template F - The repository flags type
|
|
257
|
+
* @template C - The context type extending Context<F>
|
|
258
|
+
* @param {R} this - The repository instance
|
|
259
|
+
* @param {Context<F>} context - The context for the operation
|
|
260
|
+
* @param {V} data - The relations metadata
|
|
261
|
+
* @param key - The property key of the relationship
|
|
262
|
+
* @param {M} model - The model instance
|
|
263
|
+
* @return {Promise<void>} A promise that resolves when the operation is complete
|
|
264
|
+
* @function populate
|
|
265
|
+
* @memberOf module:core
|
|
266
|
+
* @mermaid
|
|
267
|
+
* sequenceDiagram
|
|
268
|
+
* participant Caller
|
|
269
|
+
* participant populate
|
|
270
|
+
* participant fetchPopulateValues
|
|
271
|
+
* participant getPopulateKey
|
|
272
|
+
* participant Context
|
|
273
|
+
* participant repositoryFromTypeMetadata
|
|
274
|
+
*
|
|
275
|
+
* Caller->>populate: this, context, data, key, model
|
|
276
|
+
* populate->>populate: check if data.populate is true
|
|
277
|
+
* populate->>populate: get nested value and check if it exists
|
|
278
|
+
*
|
|
279
|
+
* populate->>fetchPopulateValues: context, model, key, isArr ? nested : [nested]
|
|
280
|
+
*
|
|
281
|
+
* fetchPopulateValues->>fetchPopulateValues: initialize variables
|
|
282
|
+
*
|
|
283
|
+
* loop for each proKeyValue in propKeyValues
|
|
284
|
+
* fetchPopulateValues->>getPopulateKey: model.constructor.name, propName, proKeyValue
|
|
285
|
+
* getPopulateKey-->>fetchPopulateValues: cacheKey
|
|
286
|
+
*
|
|
287
|
+
* alt try to get from cache
|
|
288
|
+
* fetchPopulateValues->>Context: get(cacheKey)
|
|
289
|
+
* Context-->>fetchPopulateValues: val
|
|
290
|
+
* else catch error
|
|
291
|
+
* fetchPopulateValues->>repositoryFromTypeMetadata: model, propName
|
|
292
|
+
* repositoryFromTypeMetadata-->>fetchPopulateValues: repo
|
|
293
|
+
* fetchPopulateValues->>repo: read(proKeyValue)
|
|
294
|
+
* repo-->>fetchPopulateValues: val
|
|
295
|
+
* end
|
|
296
|
+
*
|
|
297
|
+
* fetchPopulateValues->>fetchPopulateValues: add val to results
|
|
298
|
+
* end
|
|
299
|
+
*
|
|
300
|
+
* fetchPopulateValues-->>populate: results
|
|
301
|
+
* populate->>populate: set model[key] = isArr ? res : res[0]
|
|
302
|
+
* populate-->>Caller: void
|
|
303
|
+
*/
|
|
304
|
+
export declare function populate<M extends Model, R extends Repo<M, F, C>, V extends RelationsMetadata, F extends FabricContractFlags, C extends Context<F>>(this: R, context: Context<F>, data: V, key: keyof M, model: M): Promise<void>;
|