@decaf-ts/for-fabric 0.1.2 → 0.1.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/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 +94 -81
- package/lib/client/FabricClientAdapter.d.ts +24 -33
- package/lib/client/FabricClientAdapter.js.map +1 -1
- package/lib/client/FabricClientDispatch.cjs +14 -5
- package/lib/client/FabricClientDispatch.d.ts +7 -5
- package/lib/client/FabricClientDispatch.js.map +1 -1
- package/lib/client/FabricClientRepository.cjs +4 -137
- package/lib/client/FabricClientRepository.d.ts +6 -78
- package/lib/client/FabricClientRepository.js.map +1 -1
- package/lib/client/erc20/FabricERC20ClientRepository.cjs +17 -17
- package/lib/client/erc20/FabricERC20ClientRepository.d.ts +5 -5
- package/lib/client/erc20/FabricERC20ClientRepository.js.map +1 -1
- package/lib/client/logging.cjs +1 -3
- package/lib/client/logging.js.map +1 -1
- package/lib/client/services/FabricEnrollmentService.cjs +3 -3
- package/lib/client/services/FabricEnrollmentService.d.ts +2 -2
- package/lib/client/services/FabricEnrollmentService.js.map +1 -1
- package/lib/contracts/ContractAdapter.cjs +204 -115
- package/lib/contracts/ContractAdapter.d.ts +26 -34
- package/lib/contracts/ContractAdapter.js.map +1 -1
- package/lib/contracts/ContractContext.cjs +1 -9
- package/lib/contracts/ContractContext.d.ts +0 -6
- package/lib/contracts/ContractContext.js.map +1 -1
- package/lib/contracts/ContractPrivateDataAdapter.cjs +429 -288
- package/lib/contracts/ContractPrivateDataAdapter.d.ts +0 -76
- package/lib/contracts/ContractPrivateDataAdapter.js.map +1 -1
- package/lib/contracts/FabricConstruction.cjs +3 -3
- package/lib/contracts/FabricConstruction.d.ts +9 -8
- package/lib/contracts/FabricConstruction.js.map +1 -1
- package/lib/contracts/FabricContractRepository.cjs +7 -202
- package/lib/contracts/FabricContractRepository.d.ts +5 -68
- package/lib/contracts/FabricContractRepository.js.map +1 -1
- package/lib/contracts/FabricContractRepositoryObservableHandler.cjs +4 -1
- package/lib/contracts/FabricContractRepositoryObservableHandler.d.ts +4 -4
- package/lib/contracts/FabricContractRepositoryObservableHandler.js.map +1 -1
- package/lib/contracts/FabricContractSequence.cjs +39 -60
- package/lib/contracts/FabricContractSequence.d.ts +29 -41
- package/lib/contracts/FabricContractSequence.js.map +1 -1
- package/lib/contracts/FabricContractStatement.cjs +6 -6
- package/lib/contracts/FabricContractStatement.d.ts +4 -6
- package/lib/contracts/FabricContractStatement.js.map +1 -1
- package/lib/contracts/crud/crud-contract.cjs +74 -44
- package/lib/contracts/crud/crud-contract.d.ts +7 -11
- package/lib/contracts/crud/crud-contract.js.map +1 -1
- package/lib/contracts/crud/serialized-crud-contract.cjs +12 -21
- package/lib/contracts/crud/serialized-crud-contract.d.ts +3 -11
- package/lib/contracts/crud/serialized-crud-contract.js.map +1 -1
- package/lib/contracts/erc20/erc20contract.cjs +73 -67
- package/lib/contracts/erc20/erc20contract.d.ts +13 -12
- package/lib/contracts/erc20/erc20contract.js.map +1 -1
- package/lib/contracts/logging.cjs +9 -15
- package/lib/contracts/logging.d.ts +1 -2
- package/lib/contracts/logging.js.map +1 -1
- package/lib/contracts/private-data.cjs +202 -118
- package/lib/contracts/private-data.d.ts +0 -16
- package/lib/contracts/private-data.js.map +1 -1
- package/lib/contracts/types.d.ts +1 -1
- package/lib/esm/client/FabricClientAdapter.d.ts +24 -33
- package/lib/esm/client/FabricClientAdapter.js +90 -78
- package/lib/esm/client/FabricClientAdapter.js.map +1 -1
- package/lib/esm/client/FabricClientDispatch.d.ts +7 -5
- package/lib/esm/client/FabricClientDispatch.js +17 -8
- package/lib/esm/client/FabricClientDispatch.js.map +1 -1
- package/lib/esm/client/FabricClientRepository.d.ts +6 -78
- package/lib/esm/client/FabricClientRepository.js +4 -137
- package/lib/esm/client/FabricClientRepository.js.map +1 -1
- package/lib/esm/client/erc20/FabricERC20ClientRepository.d.ts +5 -5
- package/lib/esm/client/erc20/FabricERC20ClientRepository.js +17 -17
- package/lib/esm/client/erc20/FabricERC20ClientRepository.js.map +1 -1
- package/lib/esm/client/logging.js +1 -3
- package/lib/esm/client/logging.js.map +1 -1
- package/lib/esm/client/services/FabricEnrollmentService.d.ts +2 -2
- package/lib/esm/client/services/FabricEnrollmentService.js +3 -3
- package/lib/esm/client/services/FabricEnrollmentService.js.map +1 -1
- package/lib/esm/contracts/ContractAdapter.d.ts +26 -34
- package/lib/esm/contracts/ContractAdapter.js +205 -116
- package/lib/esm/contracts/ContractAdapter.js.map +1 -1
- package/lib/esm/contracts/ContractContext.d.ts +0 -6
- package/lib/esm/contracts/ContractContext.js +1 -9
- package/lib/esm/contracts/ContractContext.js.map +1 -1
- package/lib/esm/contracts/ContractPrivateDataAdapter.d.ts +0 -76
- package/lib/esm/contracts/ContractPrivateDataAdapter.js +430 -285
- package/lib/esm/contracts/ContractPrivateDataAdapter.js.map +1 -1
- package/lib/esm/contracts/FabricConstruction.d.ts +9 -8
- package/lib/esm/contracts/FabricConstruction.js +3 -3
- package/lib/esm/contracts/FabricConstruction.js.map +1 -1
- package/lib/esm/contracts/FabricContractRepository.d.ts +5 -68
- package/lib/esm/contracts/FabricContractRepository.js +7 -202
- package/lib/esm/contracts/FabricContractRepository.js.map +1 -1
- package/lib/esm/contracts/FabricContractRepositoryObservableHandler.d.ts +4 -4
- package/lib/esm/contracts/FabricContractRepositoryObservableHandler.js +5 -2
- package/lib/esm/contracts/FabricContractRepositoryObservableHandler.js.map +1 -1
- package/lib/esm/contracts/FabricContractSequence.d.ts +29 -41
- package/lib/esm/contracts/FabricContractSequence.js +40 -61
- package/lib/esm/contracts/FabricContractSequence.js.map +1 -1
- package/lib/esm/contracts/FabricContractStatement.d.ts +4 -6
- package/lib/esm/contracts/FabricContractStatement.js +7 -7
- package/lib/esm/contracts/FabricContractStatement.js.map +1 -1
- package/lib/esm/contracts/crud/crud-contract.d.ts +7 -11
- package/lib/esm/contracts/crud/crud-contract.js +75 -45
- package/lib/esm/contracts/crud/crud-contract.js.map +1 -1
- package/lib/esm/contracts/crud/serialized-crud-contract.d.ts +3 -11
- package/lib/esm/contracts/crud/serialized-crud-contract.js +12 -21
- package/lib/esm/contracts/crud/serialized-crud-contract.js.map +1 -1
- package/lib/esm/contracts/erc20/erc20contract.d.ts +13 -12
- package/lib/esm/contracts/erc20/erc20contract.js +73 -67
- package/lib/esm/contracts/erc20/erc20contract.js.map +1 -1
- package/lib/esm/contracts/logging.d.ts +1 -2
- package/lib/esm/contracts/logging.js +9 -15
- package/lib/esm/contracts/logging.js.map +1 -1
- package/lib/esm/contracts/private-data.d.ts +0 -16
- package/lib/esm/contracts/private-data.js +203 -111
- package/lib/esm/contracts/private-data.js.map +1 -1
- package/lib/esm/contracts/types.d.ts +1 -1
- package/lib/esm/shared/decorators.d.ts +14 -4
- package/lib/esm/shared/decorators.js +142 -42
- package/lib/esm/shared/decorators.js.map +1 -1
- package/lib/esm/shared/errors.js +2 -2
- package/lib/esm/shared/errors.js.map +1 -1
- package/lib/esm/shared/events.d.ts +1 -5
- package/lib/esm/shared/events.js.map +1 -1
- package/lib/esm/shared/model/Sequence.d.ts +14 -0
- package/lib/esm/shared/model/Sequence.js +33 -0
- package/lib/esm/shared/model/Sequence.js.map +1 -0
- package/lib/esm/shared/model/index.d.ts +2 -0
- package/lib/esm/shared/model/index.js +2 -0
- package/lib/esm/shared/model/index.js.map +1 -1
- package/lib/esm/version.d.ts +1 -1
- package/lib/esm/version.js +1 -1
- package/lib/shared/decorators.cjs +148 -41
- package/lib/shared/decorators.d.ts +14 -4
- package/lib/shared/decorators.js.map +1 -1
- package/lib/shared/errors.cjs +2 -2
- package/lib/shared/errors.js.map +1 -1
- package/lib/shared/events.d.ts +1 -5
- package/lib/shared/events.js.map +1 -1
- package/lib/shared/model/Sequence.cjs +36 -0
- package/lib/shared/model/Sequence.d.ts +14 -0
- package/lib/shared/model/Sequence.js.map +1 -0
- package/lib/shared/model/index.cjs +2 -0
- package/lib/shared/model/index.d.ts +2 -0
- package/lib/shared/model/index.js.map +1 -1
- package/lib/version.cjs +1 -1
- package/lib/version.d.ts +1 -1
- package/package.json +2 -3
- package/lib/client/services/LoggedService.cjs +0 -47
- package/lib/client/services/LoggedService.d.ts +0 -42
- package/lib/client/services/LoggedService.js.map +0 -1
- package/lib/esm/client/services/LoggedService.d.ts +0 -42
- package/lib/esm/client/services/LoggedService.js +0 -43
- package/lib/esm/client/services/LoggedService.js.map +0 -1
|
@@ -1,290 +1,431 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
2
|
+
// import { ChaincodeStub, Iterators, StateQueryResponse } from "fabric-shim";
|
|
3
|
+
// import { FabricContractAdapter } from "./ContractAdapter";
|
|
4
|
+
// import {
|
|
5
|
+
// BaseError,
|
|
6
|
+
// NotFoundError,
|
|
7
|
+
// SerializationError,
|
|
8
|
+
// } from "@decaf-ts/db-decorators";
|
|
9
|
+
// import { Model } from "@decaf-ts/decorator-validation";
|
|
10
|
+
// import {
|
|
11
|
+
// MISSING_PRIVATE_DATA_REGEX,
|
|
12
|
+
// modelToPrivate,
|
|
13
|
+
// processModel,
|
|
14
|
+
// } from "./private-data";
|
|
15
|
+
// import { UnauthorizedPrivateDataAccess } from "../shared/errors";
|
|
16
|
+
// import { FabricContractSequence } from "./FabricContractSequence";
|
|
17
|
+
// import { Sequence, SequenceOptions } from "@decaf-ts/core";
|
|
18
|
+
// import { FabricContractContext } from "./ContractContext";
|
|
19
|
+
// import { CouchDBKeys, MangoQuery } from "@decaf-ts/for-couchdb";
|
|
20
|
+
//
|
|
21
|
+
// export class FabricContractPrivateDataAdapter extends FabricContractAdapter {
|
|
22
|
+
// /**
|
|
23
|
+
// * @description Creates a new FabricContractAdapter instance
|
|
24
|
+
// * @summary Initializes an adapter for interacting with the Fabric state database
|
|
25
|
+
// * @param {void} scope - Not used in this adapter
|
|
26
|
+
// * @param {string} [alias] - Optional alias for the adapter instance
|
|
27
|
+
// */
|
|
28
|
+
// constructor(
|
|
29
|
+
// scope: void,
|
|
30
|
+
// alias?: string,
|
|
31
|
+
// private readonly collections?: string[]
|
|
32
|
+
// ) {
|
|
33
|
+
// super(scope, alias);
|
|
34
|
+
// this.collections = collections || [];
|
|
35
|
+
// }
|
|
36
|
+
//
|
|
37
|
+
// override async Sequence(options: SequenceOptions): Promise<Sequence> {
|
|
38
|
+
// return new FabricContractSequence(options, this, this.collections);
|
|
39
|
+
// }
|
|
40
|
+
//
|
|
41
|
+
// /**
|
|
42
|
+
// * @description Reads a record from the state database
|
|
43
|
+
// * @summary Retrieves and deserializes a record from the Fabric state database
|
|
44
|
+
// * @param {string} tableName - The name of the table/collection
|
|
45
|
+
// * @param {string | number} id - The record identifier
|
|
46
|
+
// * @param {...any[]} args - Additional arguments, including the chaincode stub and logger
|
|
47
|
+
// * @return {Promise<Record<string, any>>} Promise resolving to the retrieved record
|
|
48
|
+
// */
|
|
49
|
+
// override async read(
|
|
50
|
+
// tableName: string,
|
|
51
|
+
// id: string | number,
|
|
52
|
+
// instance: any,
|
|
53
|
+
// ...args: any[]
|
|
54
|
+
// ): Promise<Record<string, any>> {
|
|
55
|
+
// const { stub, logger } = args.pop();
|
|
56
|
+
// const log = logger.for(this.read);
|
|
57
|
+
//
|
|
58
|
+
// let model: Record<string, any>;
|
|
59
|
+
// try {
|
|
60
|
+
// const results = await this.readState(
|
|
61
|
+
// stub,
|
|
62
|
+
// tableName,
|
|
63
|
+
// id.toString(),
|
|
64
|
+
// instance
|
|
65
|
+
// );
|
|
66
|
+
//
|
|
67
|
+
// if (results.length < 1) {
|
|
68
|
+
// log.debug(`No record found for id ${id} in ${tableName} table`);
|
|
69
|
+
// throw new NotFoundError(
|
|
70
|
+
// `No record found for id ${id} in ${tableName} table`
|
|
71
|
+
// );
|
|
72
|
+
// } else if (results.length < 2) {
|
|
73
|
+
// log.debug(`No record found for id ${id} in ${tableName} table`);
|
|
74
|
+
// model = results.pop() as Record<string, any>;
|
|
75
|
+
// } else {
|
|
76
|
+
// model = this.mergeModels(results);
|
|
77
|
+
// }
|
|
78
|
+
// } catch (e: unknown) {
|
|
79
|
+
// throw this.parseError(e as Error);
|
|
80
|
+
// }
|
|
81
|
+
//
|
|
82
|
+
// return model;
|
|
83
|
+
// }
|
|
84
|
+
//
|
|
85
|
+
// /**
|
|
86
|
+
// * @description Deletes a record from the state database
|
|
87
|
+
// * @summary Retrieves a record and then removes it from the Fabric state database
|
|
88
|
+
// * @param {string} tableName - The name of the table/collection
|
|
89
|
+
// * @param {string | number} id - The record identifier to delete
|
|
90
|
+
// * @param {...any[]} args - Additional arguments, including the chaincode stub and logger
|
|
91
|
+
// * @return {Promise<Record<string, any>>} Promise resolving to the deleted record
|
|
92
|
+
// */
|
|
93
|
+
// override async delete(
|
|
94
|
+
// tableName: string,
|
|
95
|
+
// id: string | number,
|
|
96
|
+
// instance: any,
|
|
97
|
+
// ...args: any[]
|
|
98
|
+
// ): Promise<Record<string, any>> {
|
|
99
|
+
// const ctx = args.pop();
|
|
100
|
+
// const { stub, logger } = ctx;
|
|
101
|
+
// const log = logger.for(this.delete);
|
|
102
|
+
//
|
|
103
|
+
// args.push(ctx);
|
|
104
|
+
//
|
|
105
|
+
// let model: Record<string, any>;
|
|
106
|
+
// try {
|
|
107
|
+
// model = await this.read(tableName, id, instance, ...args);
|
|
108
|
+
// log.verbose(`deleting entry with pk ${id} from ${tableName} table`);
|
|
109
|
+
// this.deleteState(stub, tableName, id.toString(), instance);
|
|
110
|
+
// } catch (e: unknown) {
|
|
111
|
+
// throw this.parseError(e as Error);
|
|
112
|
+
// }
|
|
113
|
+
//
|
|
114
|
+
// return model;
|
|
115
|
+
// }
|
|
116
|
+
// override prepare<M extends Model>(
|
|
117
|
+
// model: M,
|
|
118
|
+
// pk: keyof M,
|
|
119
|
+
// ...args: any[]
|
|
120
|
+
// ): {
|
|
121
|
+
// record: Record<string, any>;
|
|
122
|
+
// id: string;
|
|
123
|
+
// transient?: Record<string, any>;
|
|
124
|
+
// } {
|
|
125
|
+
// const { stub, logger } = args.pop();
|
|
126
|
+
// const tableName = args.shift();
|
|
127
|
+
// const log = logger.for(this.prepare);
|
|
128
|
+
//
|
|
129
|
+
// const split = processModel(this, model);
|
|
130
|
+
// // if ((model as any)[PersistenceKeys.METADATA]) {
|
|
131
|
+
// // log.silly(
|
|
132
|
+
// // `Passing along persistence metadata for ${(model as any)[PersistenceKeys.METADATA]}`
|
|
133
|
+
// // );
|
|
134
|
+
// // Object.defineProperty(split.result, PersistenceKeys.METADATA, {
|
|
135
|
+
// // enumerable: false,
|
|
136
|
+
// // writable: false,
|
|
137
|
+
// // configurable: true,
|
|
138
|
+
// // value: (model as any)[PersistenceKeys.METADATA],
|
|
139
|
+
// // });
|
|
140
|
+
// // }
|
|
141
|
+
//
|
|
142
|
+
// log.info(`Preparing record for ${tableName} table with pk ${model[pk]}`);
|
|
143
|
+
//
|
|
144
|
+
// return {
|
|
145
|
+
// record: split.privateData as Record<string, any>,
|
|
146
|
+
// id: stub.createCompositeKey(tableName, [String(model[pk])]),
|
|
147
|
+
// transient: split.transient,
|
|
148
|
+
// };
|
|
149
|
+
// }
|
|
150
|
+
//
|
|
151
|
+
// override createPrefix(
|
|
152
|
+
// tableName: string,
|
|
153
|
+
// id: string | number,
|
|
154
|
+
// model: Record<string, any>,
|
|
155
|
+
// ...args: any[]
|
|
156
|
+
// ) {
|
|
157
|
+
// const ctx: FabricContractContext = args.pop();
|
|
158
|
+
// const collections = Object.keys(model);
|
|
159
|
+
// for (const collection of collections) {
|
|
160
|
+
// model[collection][CouchDBKeys.TABLE] = tableName;
|
|
161
|
+
// }
|
|
162
|
+
//
|
|
163
|
+
// const record: Record<string, any> = model;
|
|
164
|
+
//
|
|
165
|
+
// return [tableName, id, record, ctx];
|
|
166
|
+
// }
|
|
167
|
+
//
|
|
168
|
+
// override updatePrefix(
|
|
169
|
+
// tableName: string,
|
|
170
|
+
// id: string | number,
|
|
171
|
+
// model: Record<string, any>,
|
|
172
|
+
// ...args: any[]
|
|
173
|
+
// ): (string | number | Record<string, any>)[] {
|
|
174
|
+
// const ctx: FabricContractContext = args.pop();
|
|
175
|
+
// const collections = Object.keys(model);
|
|
176
|
+
//
|
|
177
|
+
// for (const collection of collections) {
|
|
178
|
+
// model[collection][CouchDBKeys.TABLE] = tableName;
|
|
179
|
+
// }
|
|
180
|
+
//
|
|
181
|
+
// const record: Record<string, any> = model;
|
|
182
|
+
//
|
|
183
|
+
// return [tableName, id, record, ctx];
|
|
184
|
+
// }
|
|
185
|
+
// override async putState(
|
|
186
|
+
// stub: ChaincodeStub,
|
|
187
|
+
// id: string,
|
|
188
|
+
// model: Record<string, any>,
|
|
189
|
+
// // eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
190
|
+
// ...args: any[]
|
|
191
|
+
// ) {
|
|
192
|
+
// const collections = Object.keys(model);
|
|
193
|
+
// let res: Record<string, any> = {};
|
|
194
|
+
// let data: Buffer;
|
|
195
|
+
//
|
|
196
|
+
// for (const collection of collections) {
|
|
197
|
+
// res = model![collection];
|
|
198
|
+
// try {
|
|
199
|
+
// data = Buffer.from(
|
|
200
|
+
// FabricContractAdapter.serializer.serialize(
|
|
201
|
+
// model![collection] as Model
|
|
202
|
+
// )
|
|
203
|
+
// );
|
|
204
|
+
// } catch (e: unknown) {
|
|
205
|
+
// throw new SerializationError(
|
|
206
|
+
// `Failed to serialize record with id ${id}: ${e}`
|
|
207
|
+
// );
|
|
208
|
+
// }
|
|
209
|
+
// await stub.putPrivateData(collection, id.toString(), data);
|
|
210
|
+
// }
|
|
211
|
+
//
|
|
212
|
+
// return res;
|
|
213
|
+
// }
|
|
214
|
+
//
|
|
215
|
+
// override async readState(
|
|
216
|
+
// stub: ChaincodeStub,
|
|
217
|
+
// tableName: string,
|
|
218
|
+
// id: string,
|
|
219
|
+
// instance: any,
|
|
220
|
+
// // eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
221
|
+
// ...args: any[]
|
|
222
|
+
// ) {
|
|
223
|
+
// const composedKey = stub.createCompositeKey(tableName, [String(id)]);
|
|
224
|
+
// const model = modelToPrivate(instance);
|
|
225
|
+
// const collections = Object.keys(model.private!);
|
|
226
|
+
// const results: any[] = [];
|
|
227
|
+
//
|
|
228
|
+
// for (const collection of collections) {
|
|
229
|
+
// try {
|
|
230
|
+
// let res: Buffer | Record<string, any> = await stub.getPrivateData(
|
|
231
|
+
// collection,
|
|
232
|
+
// composedKey
|
|
233
|
+
// );
|
|
234
|
+
// if (res.toString() === "") {
|
|
235
|
+
// throw new NotFoundError(`Entry with id ${id} doesn't exist...`);
|
|
236
|
+
// }
|
|
237
|
+
// try {
|
|
238
|
+
// res = FabricContractAdapter.serializer.deserialize(
|
|
239
|
+
// res.toString()
|
|
240
|
+
// // model.constructor.name
|
|
241
|
+
// );
|
|
242
|
+
// } catch (e: unknown) {
|
|
243
|
+
// throw new SerializationError(`Failed to parse private data: ${e}`);
|
|
244
|
+
// }
|
|
245
|
+
// results.push(res);
|
|
246
|
+
// } catch (e: unknown) {
|
|
247
|
+
// if (MISSING_PRIVATE_DATA_REGEX.test((e as BaseError).message))
|
|
248
|
+
// throw new UnauthorizedPrivateDataAccess(e as BaseError);
|
|
249
|
+
// throw e;
|
|
250
|
+
// }
|
|
251
|
+
// }
|
|
252
|
+
//
|
|
253
|
+
// return results;
|
|
254
|
+
// }
|
|
255
|
+
//
|
|
256
|
+
// override async deleteState(
|
|
257
|
+
// stub: ChaincodeStub,
|
|
258
|
+
// tableName: string,
|
|
259
|
+
// id: string,
|
|
260
|
+
// instance: any,
|
|
261
|
+
// // eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
262
|
+
// ...args: any[]
|
|
263
|
+
// ) {
|
|
264
|
+
// const composedKey = stub.createCompositeKey(tableName, [String(id)]);
|
|
265
|
+
// const model = modelToPrivate(instance);
|
|
266
|
+
// const collections = Object.keys(model.private!);
|
|
267
|
+
//
|
|
268
|
+
// for (const collection of collections) {
|
|
269
|
+
// await stub.deletePrivateData(collection, composedKey);
|
|
270
|
+
// }
|
|
271
|
+
// }
|
|
272
|
+
//
|
|
273
|
+
// override async queryResult(
|
|
274
|
+
// stub: ChaincodeStub,
|
|
275
|
+
// rawInput: any,
|
|
276
|
+
// instance: any
|
|
277
|
+
// ): Promise<Iterators.StateQueryIterator> {
|
|
278
|
+
// const privateData = modelToPrivate(instance).private!;
|
|
279
|
+
// const collection = Object.keys(privateData)[0] || "";
|
|
280
|
+
//
|
|
281
|
+
// const result = (await stub.getPrivateDataQueryResult(
|
|
282
|
+
// collection,
|
|
283
|
+
// JSON.stringify(rawInput)
|
|
284
|
+
// )) as any;
|
|
285
|
+
//
|
|
286
|
+
// const iterator = result.iterator as Iterators.StateQueryIterator;
|
|
287
|
+
//
|
|
288
|
+
// return iterator;
|
|
289
|
+
// }
|
|
290
|
+
//
|
|
291
|
+
// override async queryResultPaginated(
|
|
292
|
+
// stub: ChaincodeStub,
|
|
293
|
+
// rawInput: any,
|
|
294
|
+
// limit: number = 250,
|
|
295
|
+
// skip: number | undefined = undefined,
|
|
296
|
+
// instance: any
|
|
297
|
+
// ): Promise<StateQueryResponse<Iterators.StateQueryIterator>> {
|
|
298
|
+
// const privateData = modelToPrivate(instance).private!;
|
|
299
|
+
// const collection = Object.keys(privateData)[0] || "";
|
|
300
|
+
//
|
|
301
|
+
// const iterator = await stub.getPrivateDataQueryResult(
|
|
302
|
+
// collection,
|
|
303
|
+
// JSON.stringify(rawInput)
|
|
304
|
+
// );
|
|
305
|
+
//
|
|
306
|
+
// const results: any[] = [];
|
|
307
|
+
// let count = 0;
|
|
308
|
+
// let reachedBookmark = skip ? false : true;
|
|
309
|
+
// let lastKey: string | null = null;
|
|
310
|
+
//
|
|
311
|
+
// while (true) {
|
|
312
|
+
// const res = await iterator.next();
|
|
313
|
+
//
|
|
314
|
+
// if (res.value && res.value.value.toString()) {
|
|
315
|
+
// const recordKey = res.value.key;
|
|
316
|
+
// const recordValue = (res.value.value as any).toString("utf8");
|
|
317
|
+
//
|
|
318
|
+
// // If we have a skip, skip until we reach it
|
|
319
|
+
// if (!reachedBookmark) {
|
|
320
|
+
// if (recordKey === skip?.toString()) {
|
|
321
|
+
// reachedBookmark = true;
|
|
322
|
+
// }
|
|
323
|
+
// continue;
|
|
324
|
+
// }
|
|
325
|
+
//
|
|
326
|
+
// results.push({ Key: recordKey, Record: JSON.parse(recordValue) });
|
|
327
|
+
// lastKey = recordKey;
|
|
328
|
+
// count++;
|
|
329
|
+
//
|
|
330
|
+
// if (count >= limit) {
|
|
331
|
+
// await iterator.close();
|
|
332
|
+
// return {
|
|
333
|
+
// iterator: results as unknown as Iterators.StateQueryIterator,
|
|
334
|
+
// metadata: {
|
|
335
|
+
// fetchedRecordsCount: results.length,
|
|
336
|
+
// bookmark: lastKey,
|
|
337
|
+
// },
|
|
338
|
+
// };
|
|
339
|
+
// }
|
|
340
|
+
// }
|
|
341
|
+
//
|
|
342
|
+
// if (res.done) {
|
|
343
|
+
// await iterator.close();
|
|
344
|
+
// return {
|
|
345
|
+
// iterator: results as unknown as Iterators.StateQueryIterator,
|
|
346
|
+
// metadata: {
|
|
347
|
+
// fetchedRecordsCount: results.length,
|
|
348
|
+
// bookmark: "",
|
|
349
|
+
// },
|
|
350
|
+
// };
|
|
351
|
+
// }
|
|
352
|
+
// }
|
|
353
|
+
// // return (await stub.getQueryResultWithPagination(
|
|
354
|
+
// // JSON.stringify(rawInput),
|
|
355
|
+
// // limit,
|
|
356
|
+
// // skip?.toString()
|
|
357
|
+
// // )) as StateQueryResponse<Iterators.StateQueryIterator>;
|
|
358
|
+
// }
|
|
359
|
+
//
|
|
360
|
+
// /**
|
|
361
|
+
// * @description Executes a raw query against the state database
|
|
362
|
+
// * @summary Performs a rich query using CouchDB syntax against the Fabric state database
|
|
363
|
+
// * @template R - The return type
|
|
364
|
+
// * @param {MangoQuery} rawInput - The Mango Query to execute
|
|
365
|
+
// * @param {boolean} docsOnly - Whether to return only documents (not used in this implementation)
|
|
366
|
+
// * @param {...any[]} args - Additional arguments, including the chaincode stub and logger
|
|
367
|
+
// * @return {Promise<R>} Promise resolving to the query results
|
|
368
|
+
// * @mermaid
|
|
369
|
+
// * sequenceDiagram
|
|
370
|
+
// * participant Caller
|
|
371
|
+
// * participant FabricContractAdapter
|
|
372
|
+
// * participant Stub
|
|
373
|
+
// * participant StateDB
|
|
374
|
+
// *
|
|
375
|
+
// * Caller->>FabricContractAdapter: raw(rawInput, docsOnly, ctx)
|
|
376
|
+
// * FabricContractAdapter->>FabricContractAdapter: Extract limit and skip
|
|
377
|
+
// * alt With pagination
|
|
378
|
+
// * FabricContractAdapter->>Stub: getQueryResultWithPagination(query, limit, skip)
|
|
379
|
+
// * else Without pagination
|
|
380
|
+
// * FabricContractAdapter->>Stub: getQueryResult(query)
|
|
381
|
+
// * end
|
|
382
|
+
// * Stub->>StateDB: Execute query
|
|
383
|
+
// * StateDB-->>Stub: Iterator
|
|
384
|
+
// * Stub-->>FabricContractAdapter: Iterator
|
|
385
|
+
// * FabricContractAdapter->>FabricContractAdapter: resultIterator(log, iterator)
|
|
386
|
+
// * FabricContractAdapter-->>Caller: results
|
|
387
|
+
// */
|
|
388
|
+
// override async raw<R>(
|
|
389
|
+
// rawInput: MangoQuery,
|
|
390
|
+
// docsOnly: boolean,
|
|
391
|
+
// ...args: any[]
|
|
392
|
+
// ): Promise<R> {
|
|
393
|
+
// const { stub, logger } = args.pop();
|
|
394
|
+
// const log = logger.for(this.raw);
|
|
395
|
+
// const { skip, limit } = rawInput;
|
|
396
|
+
// const instance = args.shift();
|
|
397
|
+
// let iterator: Iterators.StateQueryIterator;
|
|
398
|
+
// if (limit || skip) {
|
|
399
|
+
// delete rawInput["limit"];
|
|
400
|
+
// delete rawInput["skip"];
|
|
401
|
+
// log.debug(
|
|
402
|
+
// `Retrieving paginated iterator: limit: ${limit}/ skip: ${skip}`
|
|
403
|
+
// );
|
|
404
|
+
// const response: StateQueryResponse<Iterators.StateQueryIterator> =
|
|
405
|
+
// (await this.queryResultPaginated(
|
|
406
|
+
// stub,
|
|
407
|
+
// rawInput,
|
|
408
|
+
// limit || 250,
|
|
409
|
+
// (skip as any)?.toString(),
|
|
410
|
+
// instance
|
|
411
|
+
// )) as StateQueryResponse<Iterators.StateQueryIterator>;
|
|
412
|
+
// iterator = response.iterator;
|
|
413
|
+
// } else {
|
|
414
|
+
// log.debug("Retrieving iterator");
|
|
415
|
+
// iterator = (await this.queryResult(
|
|
416
|
+
// stub,
|
|
417
|
+
// rawInput,
|
|
418
|
+
// instance
|
|
419
|
+
// )) as Iterators.StateQueryIterator;
|
|
420
|
+
// }
|
|
421
|
+
// log.debug("Iterator acquired");
|
|
422
|
+
//
|
|
423
|
+
// const results = (await this.resultIterator(log, iterator)) as R;
|
|
424
|
+
// log.debug(
|
|
425
|
+
// `returning {0} results`,
|
|
426
|
+
// `${Array.isArray(results) ? results.length : 1}`
|
|
427
|
+
// );
|
|
428
|
+
// return results;
|
|
429
|
+
// }
|
|
430
|
+
// }
|
|
290
431
|
//# sourceMappingURL=ContractPrivateDataAdapter.js.map
|