@decaf-ts/for-fabric 0.1.119 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/for-fabric.cjs +1 -1
- package/dist/for-fabric.cjs.map +1 -1
- package/dist/for-fabric.js +1 -1
- package/dist/for-fabric.js.map +1 -1
- package/lib/client/FabricClientAdapter.cjs +4 -7
- package/lib/client/FabricClientAdapter.js.map +1 -1
- package/lib/client/services/FabricIdentityService.cjs +3 -2
- package/lib/client/services/FabricIdentityService.js.map +1 -1
- package/lib/contract/OtherMarketContract.cjs +30 -0
- package/lib/contract/OtherMarketContract.d.ts +5 -0
- package/lib/contract/OtherMarketContract.js.map +1 -0
- package/lib/contract/OtherProductStrengthContract.cjs +30 -0
- package/lib/contract/OtherProductStrengthContract.d.ts +5 -0
- package/lib/contract/OtherProductStrengthContract.js.map +1 -0
- package/lib/contract/index.cjs +4 -0
- package/lib/contract/index.js.map +1 -1
- package/lib/contract/models/Audit.js.map +1 -1
- package/lib/contract/models/OtherAudit.cjs +105 -0
- package/lib/contract/models/OtherAudit.d.ts +13 -0
- package/lib/contract/models/OtherAudit.js.map +1 -0
- package/lib/contract/models/OtherMarket.cjs +78 -0
- package/lib/contract/models/OtherMarket.d.ts +12 -0
- package/lib/contract/models/OtherMarket.js.map +1 -0
- package/lib/contract/models/OtherProductShared.cjs +15 -4
- package/lib/contract/models/OtherProductShared.d.ts +4 -0
- package/lib/contract/models/OtherProductShared.js.map +1 -1
- package/lib/contract/models/OtherProductStrength.cjs +81 -0
- package/lib/contract/models/OtherProductStrength.d.ts +11 -0
- package/lib/contract/models/OtherProductStrength.js.map +1 -0
- package/lib/contract/models/Product.cjs +1 -1
- package/lib/contract/models/Product.js.map +1 -1
- package/lib/contract/models/ProductStrength.js.map +1 -1
- package/lib/contract/models/decorators-private.cjs +88 -0
- package/lib/contract/models/decorators-private.d.ts +16 -0
- package/lib/contract/models/decorators-private.js.map +1 -0
- package/lib/contract/models/decorators.cjs +31 -2
- package/lib/contract/models/decorators.d.ts +6 -1
- package/lib/contract/models/decorators.js.map +1 -1
- package/lib/contracts/ContractAdapter.cjs +259 -409
- package/lib/contracts/ContractAdapter.d.ts +5 -29
- package/lib/contracts/ContractAdapter.js.map +1 -1
- package/lib/contracts/ContractContext.cjs +41 -13
- package/lib/contracts/ContractContext.d.ts +13 -8
- package/lib/contracts/ContractContext.js.map +1 -1
- package/lib/contracts/FabricContractRepository.cjs +70 -0
- package/lib/contracts/FabricContractRepository.d.ts +6 -0
- package/lib/contracts/FabricContractRepository.js.map +1 -1
- package/lib/contracts/FabricContractSequence.cjs +7 -23
- package/lib/contracts/FabricContractSequence.js.map +1 -1
- package/lib/contracts/FabricContractStatement.cjs +136 -1
- package/lib/contracts/FabricContractStatement.d.ts +5 -2
- package/lib/contracts/FabricContractStatement.js.map +1 -1
- package/lib/contracts/crud/crud-contract.cjs +42 -17
- package/lib/contracts/crud/crud-contract.d.ts +6 -5
- package/lib/contracts/crud/crud-contract.js.map +1 -1
- package/lib/contracts/types.d.ts +9 -2
- package/lib/esm/client/FabricClientAdapter.js +4 -7
- package/lib/esm/client/FabricClientAdapter.js.map +1 -1
- package/lib/esm/client/services/FabricIdentityService.js +3 -2
- package/lib/esm/client/services/FabricIdentityService.js.map +1 -1
- package/lib/esm/contract/OtherMarketContract.d.ts +5 -0
- package/lib/esm/contract/OtherMarketContract.js +27 -0
- package/lib/esm/contract/OtherMarketContract.js.map +1 -0
- package/lib/esm/contract/OtherProductStrengthContract.d.ts +5 -0
- package/lib/esm/contract/OtherProductStrengthContract.js +27 -0
- package/lib/esm/contract/OtherProductStrengthContract.js.map +1 -0
- package/lib/esm/contract/index.js +4 -0
- package/lib/esm/contract/index.js.map +1 -1
- package/lib/esm/contract/models/Audit.js +1 -1
- package/lib/esm/contract/models/Audit.js.map +1 -1
- package/lib/esm/contract/models/OtherAudit.d.ts +13 -0
- package/lib/esm/contract/models/OtherAudit.js +102 -0
- package/lib/esm/contract/models/OtherAudit.js.map +1 -0
- package/lib/esm/contract/models/OtherMarket.d.ts +12 -0
- package/lib/esm/contract/models/OtherMarket.js +75 -0
- package/lib/esm/contract/models/OtherMarket.js.map +1 -0
- package/lib/esm/contract/models/OtherProductShared.d.ts +4 -0
- package/lib/esm/contract/models/OtherProductShared.js +16 -5
- package/lib/esm/contract/models/OtherProductShared.js.map +1 -1
- package/lib/esm/contract/models/OtherProductStrength.d.ts +11 -0
- package/lib/esm/contract/models/OtherProductStrength.js +78 -0
- package/lib/esm/contract/models/OtherProductStrength.js.map +1 -0
- package/lib/esm/contract/models/Product.js +1 -1
- package/lib/esm/contract/models/Product.js.map +1 -1
- package/lib/esm/contract/models/ProductStrength.js +1 -1
- package/lib/esm/contract/models/ProductStrength.js.map +1 -1
- package/lib/esm/contract/models/decorators-private.d.ts +16 -0
- package/lib/esm/contract/models/decorators-private.js +81 -0
- package/lib/esm/contract/models/decorators-private.js.map +1 -0
- package/lib/esm/contract/models/decorators.d.ts +6 -1
- package/lib/esm/contract/models/decorators.js +30 -2
- package/lib/esm/contract/models/decorators.js.map +1 -1
- package/lib/esm/contracts/ContractAdapter.d.ts +5 -29
- package/lib/esm/contracts/ContractAdapter.js +262 -412
- package/lib/esm/contracts/ContractAdapter.js.map +1 -1
- package/lib/esm/contracts/ContractContext.d.ts +13 -8
- package/lib/esm/contracts/ContractContext.js +41 -13
- package/lib/esm/contracts/ContractContext.js.map +1 -1
- package/lib/esm/contracts/FabricContractRepository.d.ts +6 -0
- package/lib/esm/contracts/FabricContractRepository.js +70 -0
- package/lib/esm/contracts/FabricContractRepository.js.map +1 -1
- package/lib/esm/contracts/FabricContractSequence.js +9 -25
- package/lib/esm/contracts/FabricContractSequence.js.map +1 -1
- package/lib/esm/contracts/FabricContractStatement.d.ts +5 -2
- package/lib/esm/contracts/FabricContractStatement.js +135 -0
- package/lib/esm/contracts/FabricContractStatement.js.map +1 -1
- package/lib/esm/contracts/crud/crud-contract.d.ts +6 -5
- package/lib/esm/contracts/crud/crud-contract.js +42 -17
- package/lib/esm/contracts/crud/crud-contract.js.map +1 -1
- package/lib/esm/contracts/types.d.ts +9 -2
- package/lib/esm/shared/decorators.d.ts +8 -0
- package/lib/esm/shared/decorators.js +90 -83
- package/lib/esm/shared/decorators.js.map +1 -1
- package/lib/esm/shared/overrides/overrides.js +7 -6
- package/lib/esm/shared/overrides/overrides.js.map +1 -1
- package/lib/esm/shared/types.d.ts +3 -2
- package/lib/esm/version.d.ts +1 -1
- package/lib/esm/version.js +1 -1
- package/lib/shared/decorators.cjs +91 -82
- package/lib/shared/decorators.d.ts +8 -0
- package/lib/shared/decorators.js.map +1 -1
- package/lib/shared/overrides/overrides.cjs +7 -6
- package/lib/shared/overrides/overrides.js.map +1 -1
- package/lib/shared/types.d.ts +3 -2
- package/lib/version.cjs +1 -1
- package/lib/version.d.ts +1 -1
- package/package.json +3 -3
- package/lib/contracts/ContractPrivateDataAdapter.cjs +0 -426
- package/lib/contracts/ContractPrivateDataAdapter.d.ts +0 -0
- package/lib/contracts/ContractPrivateDataAdapter.js.map +0 -1
- package/lib/contracts/FabricConstruction.cjs +0 -441
- package/lib/contracts/FabricConstruction.d.ts +0 -305
- package/lib/contracts/FabricConstruction.js.map +0 -1
- package/lib/contracts/private-data.cjs +0 -204
- package/lib/contracts/private-data.d.ts +0 -0
- package/lib/contracts/private-data.js.map +0 -1
- package/lib/esm/contracts/ContractPrivateDataAdapter.d.ts +0 -0
- package/lib/esm/contracts/ContractPrivateDataAdapter.js +0 -426
- package/lib/esm/contracts/ContractPrivateDataAdapter.js.map +0 -1
- package/lib/esm/contracts/FabricConstruction.d.ts +0 -305
- package/lib/esm/contracts/FabricConstruction.js +0 -433
- package/lib/esm/contracts/FabricConstruction.js.map +0 -1
- package/lib/esm/contracts/private-data.d.ts +0 -0
- package/lib/esm/contracts/private-data.js +0 -204
- package/lib/esm/contracts/private-data.js.map +0 -1
|
@@ -1,433 +0,0 @@
|
|
|
1
|
-
import { cacheModelForPopulate, Cascade, createOrUpdate, getPopulateKey, Repository, repositoryFromTypeMetadata, } from "@decaf-ts/core";
|
|
2
|
-
import { Model } from "@decaf-ts/decorator-validation";
|
|
3
|
-
import { InternalError } from "@decaf-ts/db-decorators";
|
|
4
|
-
/**
|
|
5
|
-
* @description Handles one-to-one relationship creation
|
|
6
|
-
* @summary Processes a one-to-one relationship when creating a model, either by referencing an existing model or creating a new one
|
|
7
|
-
* @template M - The model type extending Model
|
|
8
|
-
* @template R - The repository type extending Repo<M, F, C>
|
|
9
|
-
* @template V - The relations metadata type extending RelationsMetadata
|
|
10
|
-
* @template F - The repository flags type
|
|
11
|
-
* @template C - The context type extending Context<F>
|
|
12
|
-
* @param {R} this - The repository instance
|
|
13
|
-
* @param {Context<F>} context - The context for the operation
|
|
14
|
-
* @param {V} data - The relations metadata
|
|
15
|
-
* @param {string} key - The property key of the relationship
|
|
16
|
-
* @param {M} model - The model instance
|
|
17
|
-
* @return {Promise<void>} A promise that resolves when the operation is complete
|
|
18
|
-
* @function oneToOneOnCreate
|
|
19
|
-
* @memberOf module:core
|
|
20
|
-
* @mermaid
|
|
21
|
-
* sequenceDiagram
|
|
22
|
-
* participant Caller
|
|
23
|
-
* participant oneToOneOnCreate
|
|
24
|
-
* participant repositoryFromTypeMetadata
|
|
25
|
-
* participant Model
|
|
26
|
-
* participant Repository
|
|
27
|
-
* participant cacheModelForPopulate
|
|
28
|
-
*
|
|
29
|
-
* Caller->>oneToOneOnCreate: this, context, data, key, model
|
|
30
|
-
* oneToOneOnCreate->>oneToOneOnCreate: check if propertyValue exists
|
|
31
|
-
*
|
|
32
|
-
* alt propertyValue is not an object
|
|
33
|
-
* oneToOneOnCreate->>repositoryFromTypeMetadata: model, key
|
|
34
|
-
* repositoryFromTypeMetadata-->>oneToOneOnCreate: innerRepo
|
|
35
|
-
* oneToOneOnCreate->>innerRepo: read(propertyValue)
|
|
36
|
-
* innerRepo-->>oneToOneOnCreate: read
|
|
37
|
-
* oneToOneOnCreate->>cacheModelForPopulate: context, model, key, propertyValue, read
|
|
38
|
-
* oneToOneOnCreate->>oneToOneOnCreate: set model[key] = propertyValue
|
|
39
|
-
* else propertyValue is an object
|
|
40
|
-
* oneToOneOnCreate->>Model: get(data.class)
|
|
41
|
-
* Model-->>oneToOneOnCreate: constructor
|
|
42
|
-
* oneToOneOnCreate->>Repository: forModel(constructor)
|
|
43
|
-
* Repository-->>oneToOneOnCreate: repo
|
|
44
|
-
* oneToOneOnCreate->>repo: create(propertyValue)
|
|
45
|
-
* repo-->>oneToOneOnCreate: created
|
|
46
|
-
* oneToOneOnCreate->>findPrimaryKey: created
|
|
47
|
-
* findPrimaryKey-->>oneToOneOnCreate: pk
|
|
48
|
-
* oneToOneOnCreate->>cacheModelForPopulate: context, model, key, created[pk], created
|
|
49
|
-
* oneToOneOnCreate->>oneToOneOnCreate: set model[key] = created[pk]
|
|
50
|
-
* end
|
|
51
|
-
*
|
|
52
|
-
* oneToOneOnCreate-->>Caller: void
|
|
53
|
-
*/
|
|
54
|
-
export async function oneToOneOnCreate(context, data, key, model) {
|
|
55
|
-
const propertyValue = model[key];
|
|
56
|
-
if (!propertyValue)
|
|
57
|
-
return;
|
|
58
|
-
if (typeof propertyValue !== "object") {
|
|
59
|
-
const innerRepo = repositoryFromTypeMetadata(model, key, this.adapter.alias);
|
|
60
|
-
const read = await innerRepo.read(propertyValue, context);
|
|
61
|
-
await cacheModelForPopulate(context, model, key, propertyValue, read);
|
|
62
|
-
model[key] = propertyValue;
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
data.class =
|
|
66
|
-
typeof data.class === "string" ? data.class : data.class().name;
|
|
67
|
-
const constructor = Model.get(data.class);
|
|
68
|
-
if (!constructor)
|
|
69
|
-
throw new InternalError(`Could not find model ${data.class}`);
|
|
70
|
-
const repo = Repository.forModel(constructor, this.adapter.alias);
|
|
71
|
-
const created = await repo.create(propertyValue, context);
|
|
72
|
-
const pk = Model.pk(created);
|
|
73
|
-
await cacheModelForPopulate(context, model, key, created[pk], created);
|
|
74
|
-
model[key] = created[pk];
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* @description Handles one-to-one relationship updates
|
|
78
|
-
* @summary Processes a one-to-one relationship when updating a model, either by referencing an existing model or updating the related model
|
|
79
|
-
* @template M - The model type extending Model
|
|
80
|
-
* @template R - The repository type extending Repo<M, F, C>
|
|
81
|
-
* @template V - The relations metadata type extending RelationsMetadata
|
|
82
|
-
* @template F - The repository flags type
|
|
83
|
-
* @template C - The context type extending Context<F>
|
|
84
|
-
* @param {R} this - The repository instance
|
|
85
|
-
* @param {Context<F>} context - The context for the operation
|
|
86
|
-
* @param {V} data - The relations metadata
|
|
87
|
-
* @param key - The property key of the relationship
|
|
88
|
-
* @param {M} model - The model instance
|
|
89
|
-
* @return {Promise<void>} A promise that resolves when the operation is complete
|
|
90
|
-
* @function oneToOneOnUpdate
|
|
91
|
-
* @memberOf module:core
|
|
92
|
-
* @mermaid
|
|
93
|
-
* sequenceDiagram
|
|
94
|
-
* participant Caller
|
|
95
|
-
* participant oneToOneOnUpdate
|
|
96
|
-
* participant repositoryFromTypeMetadata
|
|
97
|
-
* participant createOrUpdate
|
|
98
|
-
* participant findPrimaryKey
|
|
99
|
-
* participant cacheModelForPopulate
|
|
100
|
-
*
|
|
101
|
-
* Caller->>oneToOneOnUpdate: this, context, data, key, model
|
|
102
|
-
* oneToOneOnUpdate->>oneToOneOnUpdate: check if propertyValue exists
|
|
103
|
-
* oneToOneOnUpdate->>oneToOneOnUpdate: check if cascade.update is CASCADE
|
|
104
|
-
*
|
|
105
|
-
* alt propertyValue is not an object
|
|
106
|
-
* oneToOneOnUpdate->>repositoryFromTypeMetadata: model, key
|
|
107
|
-
* repositoryFromTypeMetadata-->>oneToOneOnUpdate: innerRepo
|
|
108
|
-
* oneToOneOnUpdate->>innerRepo: read(propertyValue)
|
|
109
|
-
* innerRepo-->>oneToOneOnUpdate: read
|
|
110
|
-
* oneToOneOnUpdate->>cacheModelForPopulate: context, model, key, propertyValue, read
|
|
111
|
-
* oneToOneOnUpdate->>oneToOneOnUpdate: set model[key] = propertyValue
|
|
112
|
-
* else propertyValue is an object
|
|
113
|
-
* oneToOneOnUpdate->>createOrUpdate: model[key], context
|
|
114
|
-
* createOrUpdate-->>oneToOneOnUpdate: updated
|
|
115
|
-
* oneToOneOnUpdate->>findPrimaryKey: updated
|
|
116
|
-
* findPrimaryKey-->>oneToOneOnUpdate: pk
|
|
117
|
-
* oneToOneOnUpdate->>cacheModelForPopulate: context, model, key, updated[pk], updated
|
|
118
|
-
* oneToOneOnUpdate->>oneToOneOnUpdate: set model[key] = updated[pk]
|
|
119
|
-
* end
|
|
120
|
-
*
|
|
121
|
-
* oneToOneOnUpdate-->>Caller: void
|
|
122
|
-
*/
|
|
123
|
-
export async function oneToOneOnUpdate(context, data, key, model) {
|
|
124
|
-
const propertyValue = model[key];
|
|
125
|
-
if (!propertyValue)
|
|
126
|
-
return;
|
|
127
|
-
if (data.cascade.update !== Cascade.CASCADE)
|
|
128
|
-
return;
|
|
129
|
-
if (typeof propertyValue !== "object") {
|
|
130
|
-
const innerRepo = repositoryFromTypeMetadata(model, key, this.adapter.alias);
|
|
131
|
-
const read = await innerRepo.read(propertyValue, context);
|
|
132
|
-
await cacheModelForPopulate(context, model, key, propertyValue, read);
|
|
133
|
-
model[key] = propertyValue;
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
const updated = await createOrUpdate(model[key], context, this.adapter.alias, this);
|
|
137
|
-
const pk = Model.pk(updated);
|
|
138
|
-
await cacheModelForPopulate(context, model, key, updated[pk], updated);
|
|
139
|
-
model[key] = updated[pk];
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* @description Handles one-to-one relationship deletion
|
|
143
|
-
* @summary Processes a one-to-one relationship when deleting a model, deleting the related model if cascade is enabled
|
|
144
|
-
* @template M - The model type extending Model
|
|
145
|
-
* @template R - The repository type extending Repo<M, F, C>
|
|
146
|
-
* @template V - The relations metadata type extending RelationsMetadata
|
|
147
|
-
* @template F - The repository flags type
|
|
148
|
-
* @template C - The context type extending Context<F>
|
|
149
|
-
* @param {R} this - The repository instance
|
|
150
|
-
* @param {Context<F>} context - The context for the operation
|
|
151
|
-
* @param {V} data - The relations metadata
|
|
152
|
-
* @param key - The property key of the relationship
|
|
153
|
-
* @param {M} model - The model instance
|
|
154
|
-
* @return {Promise<void>} A promise that resolves when the operation is complete
|
|
155
|
-
* @function oneToOneOnDelete
|
|
156
|
-
* @memberOf module:core
|
|
157
|
-
* @mermaid
|
|
158
|
-
* sequenceDiagram
|
|
159
|
-
* participant Caller
|
|
160
|
-
* participant oneToOneOnDelete
|
|
161
|
-
* participant repositoryFromTypeMetadata
|
|
162
|
-
* participant cacheModelForPopulate
|
|
163
|
-
*
|
|
164
|
-
* Caller->>oneToOneOnDelete: this, context, data, key, model
|
|
165
|
-
* oneToOneOnDelete->>oneToOneOnDelete: check if propertyValue exists
|
|
166
|
-
* oneToOneOnDelete->>oneToOneOnDelete: check if cascade.update is CASCADE
|
|
167
|
-
*
|
|
168
|
-
* oneToOneOnDelete->>repositoryFromTypeMetadata: model, key
|
|
169
|
-
* repositoryFromTypeMetadata-->>oneToOneOnDelete: innerRepo
|
|
170
|
-
*
|
|
171
|
-
* alt propertyValue is not a Model instance
|
|
172
|
-
* oneToOneOnDelete->>innerRepo: delete(model[key], context)
|
|
173
|
-
* innerRepo-->>oneToOneOnDelete: deleted
|
|
174
|
-
* else propertyValue is a Model instance
|
|
175
|
-
* oneToOneOnDelete->>innerRepo: delete(model[key][innerRepo.pk], context)
|
|
176
|
-
* innerRepo-->>oneToOneOnDelete: deleted
|
|
177
|
-
* end
|
|
178
|
-
*
|
|
179
|
-
* oneToOneOnDelete->>cacheModelForPopulate: context, model, key, deleted[innerRepo.pk], deleted
|
|
180
|
-
* oneToOneOnDelete-->>Caller: void
|
|
181
|
-
*/
|
|
182
|
-
export async function oneToOneOnDelete(context, data, key, model) {
|
|
183
|
-
const propertyValue = model[key];
|
|
184
|
-
if (!propertyValue)
|
|
185
|
-
return;
|
|
186
|
-
if (data.cascade.update !== Cascade.CASCADE)
|
|
187
|
-
return;
|
|
188
|
-
const innerRepo = repositoryFromTypeMetadata(model, key, this.adapter.alias);
|
|
189
|
-
let deleted;
|
|
190
|
-
if (!(propertyValue instanceof Model))
|
|
191
|
-
deleted = await innerRepo.delete(model[key], context);
|
|
192
|
-
else
|
|
193
|
-
deleted = await innerRepo.delete(model[key][Model.pk(innerRepo.class)], context);
|
|
194
|
-
await cacheModelForPopulate(context, model, key, deleted[Model.pk(innerRepo.class)], deleted);
|
|
195
|
-
}
|
|
196
|
-
/**
|
|
197
|
-
* @description Handles one-to-many relationship creation
|
|
198
|
-
* @summary Processes a one-to-many relationship when creating a model, either by referencing existing models or creating new ones
|
|
199
|
-
* @template M - The model type extending Model
|
|
200
|
-
* @template R - The repository type extending Repo<M, F, C>
|
|
201
|
-
* @template V - The relations metadata type extending RelationsMetadata
|
|
202
|
-
* @template F - The repository flags type
|
|
203
|
-
* @template C - The context type extending Context<F>
|
|
204
|
-
* @param {R} this - The repository instance
|
|
205
|
-
* @param {Context<F>} context - The context for the operation
|
|
206
|
-
* @param {V} data - The relations metadata
|
|
207
|
-
* @param key - The property key of the relationship
|
|
208
|
-
* @param {M} model - The model instance
|
|
209
|
-
* @return {Promise<void>} A promise that resolves when the operation is complete
|
|
210
|
-
* @function oneToManyOnCreate
|
|
211
|
-
* @memberOf module:core
|
|
212
|
-
* @mermaid
|
|
213
|
-
* sequenceDiagram
|
|
214
|
-
* participant Caller
|
|
215
|
-
* participant oneToManyOnCreate
|
|
216
|
-
* participant repositoryFromTypeMetadata
|
|
217
|
-
* participant createOrUpdate
|
|
218
|
-
* participant findPrimaryKey
|
|
219
|
-
* participant cacheModelForPopulate
|
|
220
|
-
*
|
|
221
|
-
* Caller->>oneToManyOnCreate: this, context, data, key, model
|
|
222
|
-
* oneToManyOnCreate->>oneToManyOnCreate: check if propertyValues exists and has length
|
|
223
|
-
* oneToManyOnCreate->>oneToManyOnCreate: check if all elements have same type
|
|
224
|
-
* oneToManyOnCreate->>oneToManyOnCreate: create uniqueValues set
|
|
225
|
-
*
|
|
226
|
-
* alt arrayType is not "object"
|
|
227
|
-
* oneToManyOnCreate->>repositoryFromTypeMetadata: model, key
|
|
228
|
-
* repositoryFromTypeMetadata-->>oneToManyOnCreate: repo
|
|
229
|
-
* loop for each id in uniqueValues
|
|
230
|
-
* oneToManyOnCreate->>repo: read(id)
|
|
231
|
-
* repo-->>oneToManyOnCreate: read
|
|
232
|
-
* oneToManyOnCreate->>cacheModelForPopulate: context, model, key, id, read
|
|
233
|
-
* end
|
|
234
|
-
* oneToManyOnCreate->>oneToManyOnCreate: set model[key] = [...uniqueValues]
|
|
235
|
-
* else arrayType is "object"
|
|
236
|
-
* oneToManyOnCreate->>findPrimaryKey: propertyValues[0]
|
|
237
|
-
* findPrimaryKey-->>oneToManyOnCreate: pkName
|
|
238
|
-
* oneToManyOnCreate->>oneToManyOnCreate: create result set
|
|
239
|
-
* loop for each m in propertyValues
|
|
240
|
-
* oneToManyOnCreate->>createOrUpdate: m, context
|
|
241
|
-
* createOrUpdate-->>oneToManyOnCreate: record
|
|
242
|
-
* oneToManyOnCreate->>cacheModelForPopulate: context, model, key, record[pkName], record
|
|
243
|
-
* oneToManyOnCreate->>oneToManyOnCreate: add record[pkName] to result
|
|
244
|
-
* end
|
|
245
|
-
* oneToManyOnCreate->>oneToManyOnCreate: set model[key] = [...result]
|
|
246
|
-
* end
|
|
247
|
-
*
|
|
248
|
-
* oneToManyOnCreate-->>Caller: void
|
|
249
|
-
*/
|
|
250
|
-
export async function oneToManyOnCreate(context, data, key, model) {
|
|
251
|
-
const propertyValues = model[key];
|
|
252
|
-
if (!propertyValues || !propertyValues.length)
|
|
253
|
-
return;
|
|
254
|
-
const arrayType = typeof propertyValues[0];
|
|
255
|
-
if (!propertyValues.every((item) => typeof item === arrayType))
|
|
256
|
-
throw new InternalError(`Invalid operation. All elements of property ${key} must match the same type.`);
|
|
257
|
-
const uniqueValues = new Set([...propertyValues]);
|
|
258
|
-
if (arrayType !== "object") {
|
|
259
|
-
const repo = repositoryFromTypeMetadata(model, key, this.adapter.alias);
|
|
260
|
-
for (const id of uniqueValues) {
|
|
261
|
-
const read = await repo.read(id, context);
|
|
262
|
-
await cacheModelForPopulate(context, model, key, id, read);
|
|
263
|
-
}
|
|
264
|
-
model[key] = [...uniqueValues];
|
|
265
|
-
return;
|
|
266
|
-
}
|
|
267
|
-
const pkName = Model.pk(propertyValues[0]);
|
|
268
|
-
const result = new Set();
|
|
269
|
-
for (const m of propertyValues) {
|
|
270
|
-
const record = await createOrUpdate(m, context, this.adapter.alias);
|
|
271
|
-
await cacheModelForPopulate(context, model, key, record[pkName], record);
|
|
272
|
-
result.add(record[pkName]);
|
|
273
|
-
}
|
|
274
|
-
model[key] = [...result];
|
|
275
|
-
}
|
|
276
|
-
/**
|
|
277
|
-
* @description Handles one-to-many relationship deletion
|
|
278
|
-
* @summary Processes a one-to-many relationship when deleting a model, deleting all related models if cascade delete is enabled
|
|
279
|
-
* @template M - The model type extending Model
|
|
280
|
-
* @template R - The repository type extending Repo<M, F, C>
|
|
281
|
-
* @template V - The relations metadata type extending RelationsMetadata
|
|
282
|
-
* @template F - The repository flags type
|
|
283
|
-
* @template C - The context type extending Context<F>
|
|
284
|
-
* @param {R} this - The repository instance
|
|
285
|
-
* @param {Context<F>} context - The context for the operation
|
|
286
|
-
* @param {V} data - The relations metadata
|
|
287
|
-
* @param key - The property key of the relationship
|
|
288
|
-
* @param {M} model - The model instance
|
|
289
|
-
* @return {Promise<void>} A promise that resolves when the operation is complete
|
|
290
|
-
* @function oneToManyOnDelete
|
|
291
|
-
* @memberOf module:core
|
|
292
|
-
* @mermaid
|
|
293
|
-
* sequenceDiagram
|
|
294
|
-
* participant Caller
|
|
295
|
-
* participant oneToManyOnDelete
|
|
296
|
-
* participant Repository
|
|
297
|
-
* participant repositoryFromTypeMetadata
|
|
298
|
-
* participant cacheModelForPopulate
|
|
299
|
-
*
|
|
300
|
-
* Caller->>oneToManyOnDelete: this, context, data, key, model
|
|
301
|
-
* oneToManyOnDelete->>oneToManyOnDelete: check if cascade.delete is CASCADE
|
|
302
|
-
* oneToManyOnDelete->>oneToManyOnDelete: check if values exists and has length
|
|
303
|
-
* oneToManyOnDelete->>oneToManyOnDelete: check if all elements have same type
|
|
304
|
-
*
|
|
305
|
-
* alt isInstantiated (arrayType is "object")
|
|
306
|
-
* oneToManyOnDelete->>Repository: forModel(values[0])
|
|
307
|
-
* Repository-->>oneToManyOnDelete: repo
|
|
308
|
-
* else not instantiated
|
|
309
|
-
* oneToManyOnDelete->>repositoryFromTypeMetadata: model, key
|
|
310
|
-
* repositoryFromTypeMetadata-->>oneToManyOnDelete: repo
|
|
311
|
-
* end
|
|
312
|
-
*
|
|
313
|
-
* oneToManyOnDelete->>oneToManyOnDelete: create uniqueValues set
|
|
314
|
-
*
|
|
315
|
-
* loop for each id in uniqueValues
|
|
316
|
-
* oneToManyOnDelete->>repo: delete(id, context)
|
|
317
|
-
* repo-->>oneToManyOnDelete: deleted
|
|
318
|
-
* oneToManyOnDelete->>cacheModelForPopulate: context, model, key, id, deleted
|
|
319
|
-
* end
|
|
320
|
-
*
|
|
321
|
-
* oneToManyOnDelete->>oneToManyOnDelete: set model[key] = [...uniqueValues]
|
|
322
|
-
* oneToManyOnDelete-->>Caller: void
|
|
323
|
-
*/
|
|
324
|
-
export async function oneToManyOnDelete(context, data, key, model) {
|
|
325
|
-
if (data.cascade.delete !== Cascade.CASCADE)
|
|
326
|
-
return;
|
|
327
|
-
const values = model[key];
|
|
328
|
-
if (!values || !values.length)
|
|
329
|
-
return;
|
|
330
|
-
const arrayType = typeof values[0];
|
|
331
|
-
const areAllSameType = values.every((item) => typeof item === arrayType);
|
|
332
|
-
if (!areAllSameType)
|
|
333
|
-
throw new InternalError(`Invalid operation. All elements of property ${key} must match the same type.`);
|
|
334
|
-
const isInstantiated = arrayType === "object";
|
|
335
|
-
const repo = isInstantiated
|
|
336
|
-
? Repository.forModel(values[0], this.adapter.alias)
|
|
337
|
-
: repositoryFromTypeMetadata(model, key, this.adapter.alias);
|
|
338
|
-
const uniqueValues = new Set([
|
|
339
|
-
...(isInstantiated
|
|
340
|
-
? values.map((v) => v[Model.pk(this.class)])
|
|
341
|
-
: values),
|
|
342
|
-
]);
|
|
343
|
-
for (const id of uniqueValues.values()) {
|
|
344
|
-
const deleted = await repo.delete(id, context);
|
|
345
|
-
await cacheModelForPopulate(context, model, key, id, deleted);
|
|
346
|
-
}
|
|
347
|
-
model[key] = [...uniqueValues];
|
|
348
|
-
}
|
|
349
|
-
/**
|
|
350
|
-
* @description Populates a model's relationship
|
|
351
|
-
* @summary Retrieves and attaches related models to a model's relationship property
|
|
352
|
-
* @template M - The model type extending Model
|
|
353
|
-
* @template R - The repository type extending Repo<M, F, C>
|
|
354
|
-
* @template V - The relations metadata type extending RelationsMetadata
|
|
355
|
-
* @template F - The repository flags type
|
|
356
|
-
* @template C - The context type extending Context<F>
|
|
357
|
-
* @param {R} this - The repository instance
|
|
358
|
-
* @param {Context<F>} context - The context for the operation
|
|
359
|
-
* @param {V} data - The relations metadata
|
|
360
|
-
* @param key - The property key of the relationship
|
|
361
|
-
* @param {M} model - The model instance
|
|
362
|
-
* @return {Promise<void>} A promise that resolves when the operation is complete
|
|
363
|
-
* @function populate
|
|
364
|
-
* @memberOf module:core
|
|
365
|
-
* @mermaid
|
|
366
|
-
* sequenceDiagram
|
|
367
|
-
* participant Caller
|
|
368
|
-
* participant populate
|
|
369
|
-
* participant fetchPopulateValues
|
|
370
|
-
* participant getPopulateKey
|
|
371
|
-
* participant Context
|
|
372
|
-
* participant repositoryFromTypeMetadata
|
|
373
|
-
*
|
|
374
|
-
* Caller->>populate: this, context, data, key, model
|
|
375
|
-
* populate->>populate: check if data.populate is true
|
|
376
|
-
* populate->>populate: get nested value and check if it exists
|
|
377
|
-
*
|
|
378
|
-
* populate->>fetchPopulateValues: context, model, key, isArr ? nested : [nested]
|
|
379
|
-
*
|
|
380
|
-
* fetchPopulateValues->>fetchPopulateValues: initialize variables
|
|
381
|
-
*
|
|
382
|
-
* loop for each proKeyValue in propKeyValues
|
|
383
|
-
* fetchPopulateValues->>getPopulateKey: model.constructor.name, propName, proKeyValue
|
|
384
|
-
* getPopulateKey-->>fetchPopulateValues: cacheKey
|
|
385
|
-
*
|
|
386
|
-
* alt try to get from cache
|
|
387
|
-
* fetchPopulateValues->>Context: get(cacheKey)
|
|
388
|
-
* Context-->>fetchPopulateValues: val
|
|
389
|
-
* else catch error
|
|
390
|
-
* fetchPopulateValues->>repositoryFromTypeMetadata: model, propName
|
|
391
|
-
* repositoryFromTypeMetadata-->>fetchPopulateValues: repo
|
|
392
|
-
* fetchPopulateValues->>repo: read(proKeyValue)
|
|
393
|
-
* repo-->>fetchPopulateValues: val
|
|
394
|
-
* end
|
|
395
|
-
*
|
|
396
|
-
* fetchPopulateValues->>fetchPopulateValues: add val to results
|
|
397
|
-
* end
|
|
398
|
-
*
|
|
399
|
-
* fetchPopulateValues-->>populate: results
|
|
400
|
-
* populate->>populate: set model[key] = isArr ? res : res[0]
|
|
401
|
-
* populate-->>Caller: void
|
|
402
|
-
*/
|
|
403
|
-
export async function populate(context, data, key, model) {
|
|
404
|
-
if (!data.populate)
|
|
405
|
-
return;
|
|
406
|
-
const nested = model[key];
|
|
407
|
-
const isArr = Array.isArray(nested);
|
|
408
|
-
if (typeof nested === "undefined" || (isArr && nested.length === 0))
|
|
409
|
-
return;
|
|
410
|
-
async function fetchPopulateValues(c, model, propName, propKeyValues, alias) {
|
|
411
|
-
let cacheKey;
|
|
412
|
-
let val;
|
|
413
|
-
const results = [];
|
|
414
|
-
for (const proKeyValue of propKeyValues) {
|
|
415
|
-
cacheKey = getPopulateKey(model.constructor.name, propName, proKeyValue);
|
|
416
|
-
try {
|
|
417
|
-
val = await c.get(cacheKey);
|
|
418
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
419
|
-
}
|
|
420
|
-
catch (e) {
|
|
421
|
-
const repo = repositoryFromTypeMetadata(model, propName, alias);
|
|
422
|
-
if (!repo)
|
|
423
|
-
throw new InternalError("Could not find repo");
|
|
424
|
-
val = await repo.read(proKeyValue, context);
|
|
425
|
-
}
|
|
426
|
-
results.push(val);
|
|
427
|
-
}
|
|
428
|
-
return results;
|
|
429
|
-
}
|
|
430
|
-
const res = await fetchPopulateValues(context, model, key, isArr ? nested : [nested], this.adapter.alias);
|
|
431
|
-
model[key] = isArr ? res : res[0];
|
|
432
|
-
}
|
|
433
|
-
//# sourceMappingURL=FabricConstruction.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"FabricConstruction.js","sourceRoot":"","sources":["../../../src/contracts/FabricConstruction.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,OAAO,EACP,cAAc,EACd,cAAc,EAGd,UAAU,EACV,0BAA0B,GAC3B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,KAAK,EAAE,MAAM,gCAAgC,CAAC;AACvD,OAAO,EAAuB,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAI7E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAMpC,OAA8B,EAC9B,IAAO,EACP,GAAY,EACZ,KAAQ;IAER,MAAM,aAAa,GAAQ,KAAK,CAAC,GAAG,CAAC,CAAC;IACtC,IAAI,CAAC,aAAa;QAAE,OAAO;IAE3B,IAAI,OAAO,aAAa,KAAK,QAAQ,EAAE,CAAC;QACtC,MAAM,SAAS,GAAG,0BAA0B,CAC1C,KAAK,EACL,GAAG,EACH,IAAI,CAAC,OAAO,CAAC,KAAK,CACnB,CAAC;QACF,MAAM,IAAI,GAAG,MAAM,SAAS,CAAC,IAAI,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC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mB,CACnC,OAAO,EACP,KAAK,EACL,GAAa,EACb,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,EACzB,IAAI,CAAC,OAAO,CAAC,KAAK,CACnB,CAAC;IACD,KAAa,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AAC7C,CAAC"}
|
|
File without changes
|
|
@@ -1,204 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// import { InternalError, SerializationError } from "@decaf-ts/db-decorators";
|
|
3
|
-
// import { Model } from "@decaf-ts/decorator-validation";
|
|
4
|
-
// import { FabricModelKeys } from "../shared/constants";
|
|
5
|
-
// import { Constructor, Metadata } from "@decaf-ts/decoration";
|
|
6
|
-
//
|
|
7
|
-
// export const MISSING_PRIVATE_DATA_REGEX =
|
|
8
|
-
// /private\s+data\s+matching\s+public\s+hash\s+version\s+is\s+not\s+available/i;
|
|
9
|
-
//
|
|
10
|
-
// export const MISSING_PRIVATE_DATA_ERROR_MESSAGE =
|
|
11
|
-
// "private data matching public hash version is not available ...";
|
|
12
|
-
//
|
|
13
|
-
// export function processModel<M extends Model>(adapter: any, model: M) {
|
|
14
|
-
// const transient = Model.segregate(model);
|
|
15
|
-
// const privateData = modelToPrivate(model);
|
|
16
|
-
//
|
|
17
|
-
// const transformModel = (model: any) => {
|
|
18
|
-
// return Object.entries(model).reduce(
|
|
19
|
-
// (accum: Record<string, any>, [key, val]) => {
|
|
20
|
-
// if (typeof val === "undefined") return accum;
|
|
21
|
-
// const mappedProp = Model.columnName(
|
|
22
|
-
// model.constructor as Constructor,
|
|
23
|
-
// key as any
|
|
24
|
-
// );
|
|
25
|
-
// if (adapter.isReserved(mappedProp))
|
|
26
|
-
// throw new InternalError(`Property name ${mappedProp} is reserved`);
|
|
27
|
-
// accum[mappedProp] = val;
|
|
28
|
-
// return accum;
|
|
29
|
-
// },
|
|
30
|
-
// {}
|
|
31
|
-
// );
|
|
32
|
-
// };
|
|
33
|
-
//
|
|
34
|
-
// if (privateData.private) {
|
|
35
|
-
// const collections = Object.keys(privateData.private);
|
|
36
|
-
//
|
|
37
|
-
// for (const collection of collections) {
|
|
38
|
-
// privateData.private![collection] = transformModel(
|
|
39
|
-
// privateData.private![collection]
|
|
40
|
-
// );
|
|
41
|
-
// }
|
|
42
|
-
// }
|
|
43
|
-
//
|
|
44
|
-
// return {
|
|
45
|
-
// model: transient.model,
|
|
46
|
-
// transient: transient.transient,
|
|
47
|
-
// privateData: privateData.private,
|
|
48
|
-
// result: transformModel(transient.model),
|
|
49
|
-
// };
|
|
50
|
-
// }
|
|
51
|
-
//
|
|
52
|
-
// export function hasPrivateData<M extends Model>(model: M) {
|
|
53
|
-
// return !!getClassPrivateDataMetadata(model);
|
|
54
|
-
// }
|
|
55
|
-
//
|
|
56
|
-
// export function getClassPrivateDataMetadata<M extends Model>(
|
|
57
|
-
// model: M
|
|
58
|
-
// ): Record<string, any> | undefined {
|
|
59
|
-
// const constr = model.constructor as Constructor;
|
|
60
|
-
// const rootMetadata = Metadata.get(constr) || {};
|
|
61
|
-
// if (rootMetadata && rootMetadata[FabricModelKeys.PRIVATE])
|
|
62
|
-
// return rootMetadata[FabricModelKeys.PRIVATE];
|
|
63
|
-
// if (
|
|
64
|
-
// rootMetadata &&
|
|
65
|
-
// rootMetadata[FabricModelKeys.FABRIC + FabricModelKeys.PRIVATE]
|
|
66
|
-
// )
|
|
67
|
-
// return rootMetadata[FabricModelKeys.FABRIC + FabricModelKeys.PRIVATE];
|
|
68
|
-
// const flattened = Object.keys(rootMetadata || {}).reduce(
|
|
69
|
-
// (accum: Record<string, any>, key) => {
|
|
70
|
-
// if (key.includes(FabricModelKeys.PRIVATE)) {
|
|
71
|
-
// const property = key.split(Metadata.splitter).pop();
|
|
72
|
-
// if (property) accum[property] = Metadata.get(constr, key);
|
|
73
|
-
// }
|
|
74
|
-
// return accum;
|
|
75
|
-
// },
|
|
76
|
-
// {} as Record<string, any>
|
|
77
|
-
// );
|
|
78
|
-
// if (Object.keys(flattened).length) return flattened;
|
|
79
|
-
// const classKey = Metadata.key(
|
|
80
|
-
// FabricModelKeys.FABRIC + FabricModelKeys.PRIVATE
|
|
81
|
-
// );
|
|
82
|
-
// const classMetadata =
|
|
83
|
-
// Metadata.get(constr, classKey) ??
|
|
84
|
-
// Metadata.get(constr, FabricModelKeys.PRIVATE);
|
|
85
|
-
// if (classMetadata) return classMetadata;
|
|
86
|
-
// const props = Metadata.properties(constr) || [];
|
|
87
|
-
// const metadata: Record<string, any> = {};
|
|
88
|
-
// for (const prop of props) {
|
|
89
|
-
// const keys = [
|
|
90
|
-
// Metadata.key(FabricModelKeys.PRIVATE, prop),
|
|
91
|
-
// Metadata.key(classKey, prop),
|
|
92
|
-
// ];
|
|
93
|
-
// const propMetadata = keys
|
|
94
|
-
// .map((key) => Metadata.get(constr, key))
|
|
95
|
-
// .find(Boolean);
|
|
96
|
-
// if (propMetadata) metadata[prop] = propMetadata;
|
|
97
|
-
// }
|
|
98
|
-
// return Object.keys(metadata).length ? metadata : undefined;
|
|
99
|
-
// }
|
|
100
|
-
//
|
|
101
|
-
// export function isModelPrivate<M extends Model>(model: M): boolean {
|
|
102
|
-
// const classMetadata = Metadata.get(
|
|
103
|
-
// model.constructor as Constructor,
|
|
104
|
-
// Metadata.key(FabricModelKeys.FABRIC + FabricModelKeys.PRIVATE)
|
|
105
|
-
// );
|
|
106
|
-
// return Boolean(classMetadata?.isPrivate);
|
|
107
|
-
// }
|
|
108
|
-
//
|
|
109
|
-
// export function modelToPrivate<M extends Model>(
|
|
110
|
-
// model: M
|
|
111
|
-
// ): { model: M; private?: Record<string, Record<string, any>> } {
|
|
112
|
-
// if (!hasPrivateData(model)) return { model: model };
|
|
113
|
-
//
|
|
114
|
-
// const isPrivate = isModelPrivate(model);
|
|
115
|
-
// const modelCollections: Record<string, any> =
|
|
116
|
-
// getClassPrivateDataMetadata(model);
|
|
117
|
-
//
|
|
118
|
-
// let result: { model: Record<string, any>; private?: Record<string, any> } = {
|
|
119
|
-
// model: model as Record<string, any>,
|
|
120
|
-
// private: undefined,
|
|
121
|
-
// };
|
|
122
|
-
//
|
|
123
|
-
// // TODO: the is private is not workign correctly. If no properties it doesn't create the private part.
|
|
124
|
-
// if (isPrivate) {
|
|
125
|
-
// const privatePart = modelCollections.collections;
|
|
126
|
-
// result = (
|
|
127
|
-
// Metadata.properties(model.constructor as Constructor) || []
|
|
128
|
-
// ).reduce(
|
|
129
|
-
// (
|
|
130
|
-
// accum: { model: Record<string, any>; private?: Record<string, any> },
|
|
131
|
-
// k
|
|
132
|
-
// ) => {
|
|
133
|
-
// const collections = modelCollections.collections;
|
|
134
|
-
// accum.private = accum.private || {};
|
|
135
|
-
//
|
|
136
|
-
// for (const collection of collections) {
|
|
137
|
-
// try {
|
|
138
|
-
// accum.private[collection] = accum.private[collection] || {};
|
|
139
|
-
// accum.private[collection][k] = model[k as keyof M];
|
|
140
|
-
// } catch (e: unknown) {
|
|
141
|
-
// throw new SerializationError(
|
|
142
|
-
// `Failed to serialize private property ${k}: ${e}`
|
|
143
|
-
// );
|
|
144
|
-
// }
|
|
145
|
-
// }
|
|
146
|
-
//
|
|
147
|
-
// return accum;
|
|
148
|
-
// },
|
|
149
|
-
// { model: {}, private: privatePart } as {
|
|
150
|
-
// model: Record<string, any>;
|
|
151
|
-
// private?: Record<string, any>;
|
|
152
|
-
// }
|
|
153
|
-
// );
|
|
154
|
-
// } else {
|
|
155
|
-
// result = Object.entries(modelCollections).reduce(
|
|
156
|
-
// (
|
|
157
|
-
// accum: { model: Record<string, any>; private?: Record<string, any> },
|
|
158
|
-
// [k, val]
|
|
159
|
-
// ) => {
|
|
160
|
-
// const props = Metadata.properties(model.constructor as Constructor);
|
|
161
|
-
// if (!props?.includes(k)) return accum;
|
|
162
|
-
//
|
|
163
|
-
// const collections = (val as Record<string, any>).collections;
|
|
164
|
-
//
|
|
165
|
-
// if (collections?.length) {
|
|
166
|
-
// accum.private = accum.private || {};
|
|
167
|
-
//
|
|
168
|
-
// for (const collection of collections) {
|
|
169
|
-
// try {
|
|
170
|
-
// accum.private[collection] = accum.private[collection] || {};
|
|
171
|
-
// accum.private[collection][k] = model[k as keyof M];
|
|
172
|
-
// } catch (e: unknown) {
|
|
173
|
-
// throw new SerializationError(
|
|
174
|
-
// `Failed to serialize private property ${k}: ${e}`
|
|
175
|
-
// );
|
|
176
|
-
// }
|
|
177
|
-
// }
|
|
178
|
-
// } else {
|
|
179
|
-
// accum.model = accum.model || {};
|
|
180
|
-
// accum.model[k] = (model as Record<string, any>)[k];
|
|
181
|
-
// }
|
|
182
|
-
// return accum;
|
|
183
|
-
// },
|
|
184
|
-
// {} as { model: Record<string, any>; private?: Record<string, any> }
|
|
185
|
-
// );
|
|
186
|
-
// }
|
|
187
|
-
//
|
|
188
|
-
// result.model = result.model || {};
|
|
189
|
-
//
|
|
190
|
-
// result.model = Model.build(result.model, model.constructor.name);
|
|
191
|
-
//
|
|
192
|
-
// if (result.private) {
|
|
193
|
-
// const collections = Object.keys(result.private);
|
|
194
|
-
//
|
|
195
|
-
// for (const collection of collections) {
|
|
196
|
-
// result.private![collection] = Model.build(
|
|
197
|
-
// result.private![collection],
|
|
198
|
-
// model.constructor.name
|
|
199
|
-
// );
|
|
200
|
-
// }
|
|
201
|
-
// }
|
|
202
|
-
// return result as { model: M; private?: Record<string, Record<string, any>> };
|
|
203
|
-
// }
|
|
204
|
-
//# sourceMappingURL=private-data.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"private-data.js","sourceRoot":"","sources":["../../../src/contracts/private-data.ts"],"names":[],"mappings":";AAAA,+EAA+E;AAC/E,0DAA0D;AAC1D,yDAAyD;AACzD,gEAAgE;AAChE,EAAE;AACF,4CAA4C;AAC5C,mFAAmF;AACnF,EAAE;AACF,oDAAoD;AACpD,sEAAsE;AACtE,EAAE;AACF,0EAA0E;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