@decaf-ts/for-fabric 0.1.2 → 0.1.4

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.
Files changed (155) hide show
  1. package/dist/for-fabric.cjs +1 -1
  2. package/dist/for-fabric.cjs.map +1 -1
  3. package/dist/for-fabric.js +1 -1
  4. package/dist/for-fabric.js.map +1 -1
  5. package/lib/client/FabricClientAdapter.cjs +94 -81
  6. package/lib/client/FabricClientAdapter.d.ts +24 -33
  7. package/lib/client/FabricClientAdapter.js.map +1 -1
  8. package/lib/client/FabricClientDispatch.cjs +14 -5
  9. package/lib/client/FabricClientDispatch.d.ts +7 -5
  10. package/lib/client/FabricClientDispatch.js.map +1 -1
  11. package/lib/client/FabricClientRepository.cjs +4 -137
  12. package/lib/client/FabricClientRepository.d.ts +6 -78
  13. package/lib/client/FabricClientRepository.js.map +1 -1
  14. package/lib/client/erc20/FabricERC20ClientRepository.cjs +17 -17
  15. package/lib/client/erc20/FabricERC20ClientRepository.d.ts +5 -5
  16. package/lib/client/erc20/FabricERC20ClientRepository.js.map +1 -1
  17. package/lib/client/logging.cjs +1 -3
  18. package/lib/client/logging.js.map +1 -1
  19. package/lib/client/services/FabricEnrollmentService.cjs +3 -3
  20. package/lib/client/services/FabricEnrollmentService.d.ts +2 -2
  21. package/lib/client/services/FabricEnrollmentService.js.map +1 -1
  22. package/lib/contracts/ContractAdapter.cjs +204 -115
  23. package/lib/contracts/ContractAdapter.d.ts +26 -34
  24. package/lib/contracts/ContractAdapter.js.map +1 -1
  25. package/lib/contracts/ContractContext.cjs +1 -9
  26. package/lib/contracts/ContractContext.d.ts +0 -6
  27. package/lib/contracts/ContractContext.js.map +1 -1
  28. package/lib/contracts/ContractPrivateDataAdapter.cjs +429 -288
  29. package/lib/contracts/ContractPrivateDataAdapter.d.ts +0 -76
  30. package/lib/contracts/ContractPrivateDataAdapter.js.map +1 -1
  31. package/lib/contracts/FabricConstruction.cjs +3 -3
  32. package/lib/contracts/FabricConstruction.d.ts +9 -8
  33. package/lib/contracts/FabricConstruction.js.map +1 -1
  34. package/lib/contracts/FabricContractRepository.cjs +7 -202
  35. package/lib/contracts/FabricContractRepository.d.ts +5 -68
  36. package/lib/contracts/FabricContractRepository.js.map +1 -1
  37. package/lib/contracts/FabricContractRepositoryObservableHandler.cjs +4 -1
  38. package/lib/contracts/FabricContractRepositoryObservableHandler.d.ts +4 -4
  39. package/lib/contracts/FabricContractRepositoryObservableHandler.js.map +1 -1
  40. package/lib/contracts/FabricContractSequence.cjs +39 -60
  41. package/lib/contracts/FabricContractSequence.d.ts +29 -41
  42. package/lib/contracts/FabricContractSequence.js.map +1 -1
  43. package/lib/contracts/FabricContractStatement.cjs +6 -6
  44. package/lib/contracts/FabricContractStatement.d.ts +4 -6
  45. package/lib/contracts/FabricContractStatement.js.map +1 -1
  46. package/lib/contracts/crud/crud-contract.cjs +74 -44
  47. package/lib/contracts/crud/crud-contract.d.ts +7 -11
  48. package/lib/contracts/crud/crud-contract.js.map +1 -1
  49. package/lib/contracts/crud/serialized-crud-contract.cjs +12 -21
  50. package/lib/contracts/crud/serialized-crud-contract.d.ts +3 -11
  51. package/lib/contracts/crud/serialized-crud-contract.js.map +1 -1
  52. package/lib/contracts/erc20/erc20contract.cjs +73 -67
  53. package/lib/contracts/erc20/erc20contract.d.ts +13 -12
  54. package/lib/contracts/erc20/erc20contract.js.map +1 -1
  55. package/lib/contracts/logging.cjs +3 -9
  56. package/lib/contracts/logging.d.ts +1 -2
  57. package/lib/contracts/logging.js.map +1 -1
  58. package/lib/contracts/private-data.cjs +202 -118
  59. package/lib/contracts/private-data.d.ts +0 -16
  60. package/lib/contracts/private-data.js.map +1 -1
  61. package/lib/contracts/types.d.ts +1 -1
  62. package/lib/esm/client/FabricClientAdapter.d.ts +24 -33
  63. package/lib/esm/client/FabricClientAdapter.js +90 -78
  64. package/lib/esm/client/FabricClientAdapter.js.map +1 -1
  65. package/lib/esm/client/FabricClientDispatch.d.ts +7 -5
  66. package/lib/esm/client/FabricClientDispatch.js +17 -8
  67. package/lib/esm/client/FabricClientDispatch.js.map +1 -1
  68. package/lib/esm/client/FabricClientRepository.d.ts +6 -78
  69. package/lib/esm/client/FabricClientRepository.js +4 -137
  70. package/lib/esm/client/FabricClientRepository.js.map +1 -1
  71. package/lib/esm/client/erc20/FabricERC20ClientRepository.d.ts +5 -5
  72. package/lib/esm/client/erc20/FabricERC20ClientRepository.js +17 -17
  73. package/lib/esm/client/erc20/FabricERC20ClientRepository.js.map +1 -1
  74. package/lib/esm/client/logging.js +1 -3
  75. package/lib/esm/client/logging.js.map +1 -1
  76. package/lib/esm/client/services/FabricEnrollmentService.d.ts +2 -2
  77. package/lib/esm/client/services/FabricEnrollmentService.js +3 -3
  78. package/lib/esm/client/services/FabricEnrollmentService.js.map +1 -1
  79. package/lib/esm/contracts/ContractAdapter.d.ts +26 -34
  80. package/lib/esm/contracts/ContractAdapter.js +205 -116
  81. package/lib/esm/contracts/ContractAdapter.js.map +1 -1
  82. package/lib/esm/contracts/ContractContext.d.ts +0 -6
  83. package/lib/esm/contracts/ContractContext.js +1 -9
  84. package/lib/esm/contracts/ContractContext.js.map +1 -1
  85. package/lib/esm/contracts/ContractPrivateDataAdapter.d.ts +0 -76
  86. package/lib/esm/contracts/ContractPrivateDataAdapter.js +430 -285
  87. package/lib/esm/contracts/ContractPrivateDataAdapter.js.map +1 -1
  88. package/lib/esm/contracts/FabricConstruction.d.ts +9 -8
  89. package/lib/esm/contracts/FabricConstruction.js +3 -3
  90. package/lib/esm/contracts/FabricConstruction.js.map +1 -1
  91. package/lib/esm/contracts/FabricContractRepository.d.ts +5 -68
  92. package/lib/esm/contracts/FabricContractRepository.js +7 -202
  93. package/lib/esm/contracts/FabricContractRepository.js.map +1 -1
  94. package/lib/esm/contracts/FabricContractRepositoryObservableHandler.d.ts +4 -4
  95. package/lib/esm/contracts/FabricContractRepositoryObservableHandler.js +5 -2
  96. package/lib/esm/contracts/FabricContractRepositoryObservableHandler.js.map +1 -1
  97. package/lib/esm/contracts/FabricContractSequence.d.ts +29 -41
  98. package/lib/esm/contracts/FabricContractSequence.js +40 -61
  99. package/lib/esm/contracts/FabricContractSequence.js.map +1 -1
  100. package/lib/esm/contracts/FabricContractStatement.d.ts +4 -6
  101. package/lib/esm/contracts/FabricContractStatement.js +7 -7
  102. package/lib/esm/contracts/FabricContractStatement.js.map +1 -1
  103. package/lib/esm/contracts/crud/crud-contract.d.ts +7 -11
  104. package/lib/esm/contracts/crud/crud-contract.js +75 -45
  105. package/lib/esm/contracts/crud/crud-contract.js.map +1 -1
  106. package/lib/esm/contracts/crud/serialized-crud-contract.d.ts +3 -11
  107. package/lib/esm/contracts/crud/serialized-crud-contract.js +12 -21
  108. package/lib/esm/contracts/crud/serialized-crud-contract.js.map +1 -1
  109. package/lib/esm/contracts/erc20/erc20contract.d.ts +13 -12
  110. package/lib/esm/contracts/erc20/erc20contract.js +73 -67
  111. package/lib/esm/contracts/erc20/erc20contract.js.map +1 -1
  112. package/lib/esm/contracts/logging.d.ts +1 -2
  113. package/lib/esm/contracts/logging.js +3 -9
  114. package/lib/esm/contracts/logging.js.map +1 -1
  115. package/lib/esm/contracts/private-data.d.ts +0 -16
  116. package/lib/esm/contracts/private-data.js +203 -111
  117. package/lib/esm/contracts/private-data.js.map +1 -1
  118. package/lib/esm/contracts/types.d.ts +1 -1
  119. package/lib/esm/shared/decorators.d.ts +14 -4
  120. package/lib/esm/shared/decorators.js +142 -42
  121. package/lib/esm/shared/decorators.js.map +1 -1
  122. package/lib/esm/shared/errors.js +2 -2
  123. package/lib/esm/shared/errors.js.map +1 -1
  124. package/lib/esm/shared/events.d.ts +1 -5
  125. package/lib/esm/shared/events.js.map +1 -1
  126. package/lib/esm/shared/model/Sequence.d.ts +14 -0
  127. package/lib/esm/shared/model/Sequence.js +33 -0
  128. package/lib/esm/shared/model/Sequence.js.map +1 -0
  129. package/lib/esm/shared/model/index.d.ts +2 -0
  130. package/lib/esm/shared/model/index.js +2 -0
  131. package/lib/esm/shared/model/index.js.map +1 -1
  132. package/lib/esm/version.d.ts +1 -1
  133. package/lib/esm/version.js +1 -1
  134. package/lib/shared/decorators.cjs +148 -41
  135. package/lib/shared/decorators.d.ts +14 -4
  136. package/lib/shared/decorators.js.map +1 -1
  137. package/lib/shared/errors.cjs +2 -2
  138. package/lib/shared/errors.js.map +1 -1
  139. package/lib/shared/events.d.ts +1 -5
  140. package/lib/shared/events.js.map +1 -1
  141. package/lib/shared/model/Sequence.cjs +36 -0
  142. package/lib/shared/model/Sequence.d.ts +14 -0
  143. package/lib/shared/model/Sequence.js.map +1 -0
  144. package/lib/shared/model/index.cjs +2 -0
  145. package/lib/shared/model/index.d.ts +2 -0
  146. package/lib/shared/model/index.js.map +1 -1
  147. package/lib/version.cjs +1 -1
  148. package/lib/version.d.ts +1 -1
  149. package/package.json +2 -3
  150. package/lib/client/services/LoggedService.cjs +0 -47
  151. package/lib/client/services/LoggedService.d.ts +0 -42
  152. package/lib/client/services/LoggedService.js.map +0 -1
  153. package/lib/esm/client/services/LoggedService.d.ts +0 -42
  154. package/lib/esm/client/services/LoggedService.js +0 -43
  155. package/lib/esm/client/services/LoggedService.js.map +0 -1
@@ -42,7 +42,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
42
42
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
43
43
  };
44
44
  Object.defineProperty(exports, "__esModule", { value: true });
45
- exports.FabricClientAdapter = void 0;
45
+ exports.FabricClientAdapter = exports.FabricClientContext = void 0;
46
46
  const for_couchdb_1 = require("@decaf-ts/for-couchdb");
47
47
  const grpc_js_1 = require("@grpc/grpc-js");
48
48
  const grpc = __importStar(require("@grpc/grpc-js"));
@@ -51,11 +51,15 @@ const logging_1 = require("@decaf-ts/logging");
51
51
  const fabric_gateway_1 = require("@hyperledger/fabric-gateway");
52
52
  const fabric_fs_1 = require("./fabric-fs.cjs");
53
53
  const db_decorators_1 = require("@decaf-ts/db-decorators");
54
+ const db_decorators_2 = require("@decaf-ts/db-decorators");
54
55
  const core_1 = require("@decaf-ts/core");
55
56
  const FabricClientRepository_1 = require("./FabricClientRepository.cjs");
56
57
  const constants_1 = require("./../shared/constants.cjs");
57
58
  const ClientSerializer_1 = require("./../shared/ClientSerializer.cjs");
58
59
  const fabric_hsm_1 = require("./fabric-hsm.cjs");
60
+ class FabricClientContext extends db_decorators_2.Context {
61
+ }
62
+ exports.FabricClientContext = FabricClientContext;
59
63
  /**
60
64
  * @description Adapter for interacting with Hyperledger Fabric networks
61
65
  * @summary The FabricAdapter extends CouchDBAdapter to provide a seamless interface for interacting with Hyperledger Fabric networks.
@@ -113,18 +117,7 @@ class FabricClientAdapter extends for_couchdb_1.CouchDBAdapter {
113
117
  */
114
118
  static { this.decoder = new TextDecoder("utf8"); }
115
119
  static { this.serializer = new ClientSerializer_1.ClientSerializer(); }
116
- /**
117
- * @description Static logger instance for the FabricAdapter class
118
- */
119
- static { this.log = new logging_1.MiniLogger(FabricClientAdapter.name); }
120
- /**
121
- * @description Gets the logger instance for this adapter
122
- * @summary Returns the static logger instance for the FabricAdapter class
123
- * @return {Logger} The logger instance
124
- */
125
- get log() {
126
- return FabricClientAdapter.log;
127
- }
120
+ static { this.log = logging_1.Logging.for(FabricClientAdapter); }
128
121
  /**
129
122
  * @description Creates a new FabricAdapter instance
130
123
  * @summary Initializes a new adapter for interacting with a Hyperledger Fabric network
@@ -135,6 +128,12 @@ class FabricClientAdapter extends for_couchdb_1.CouchDBAdapter {
135
128
  super(config, constants_1.FabricFlavour, alias);
136
129
  this.serializer = FabricClientAdapter.serializer;
137
130
  }
131
+ async context(operation, overrides, model, ...args) {
132
+ const log = this.log.for(this.context);
133
+ log.debug(`Creating new context for ${operation} operation on ${Array.isArray(model) ? model.map((m) => m.name) : model.name} model with flag overrides: ${JSON.stringify(overrides)}`);
134
+ const flags = await this.flags(operation, model, overrides, ...args);
135
+ return new FabricClientContext().accumulate(flags);
136
+ }
138
137
  /**
139
138
  * @description Decodes a Uint8Array to a string
140
139
  * @summary Converts binary data received from Fabric to a string using UTF-8 encoding
@@ -156,15 +155,16 @@ class FabricClientAdapter extends for_couchdb_1.CouchDBAdapter {
156
155
  * @param {Record<string, any>} transient - Transient data for the transaction
157
156
  * @return {Promise<Array<Record<string, any>>>} Promise resolving to the created records
158
157
  */
159
- async createAll(tableName, ids, models, transient) {
160
- const log = this.log.for(this.createAll);
158
+ async createAll(clazz, ids, models, ...args) {
161
159
  if (ids.length !== models.length)
162
- throw new db_decorators_1.InternalError(`Ids and models must have the same length: ${ids.length} != ${models.length}`);
163
- if (typeof tableName !== "string")
164
- tableName = tableName.name;
160
+ throw new db_decorators_1.InternalError("Ids and models must have the same length");
161
+ const ctxArgs = [...args];
162
+ const transient = ctxArgs.shift();
163
+ const { log } = this.logCtx(ctxArgs, this.createAll);
164
+ const tableName = decorator_validation_1.Model.tableName(clazz);
165
165
  log.info(`adding ${ids.length} entries to ${tableName} table`);
166
166
  log.verbose(`pks: ${ids}`);
167
- const result = await this.submitTransaction(db_decorators_1.BulkCrudOperationKeys.CREATE_ALL, [ids, models.map((m) => this.serializer.serialize(m, tableName))], transient, undefined, tableName);
167
+ const result = await this.submitTransaction(db_decorators_1.BulkCrudOperationKeys.CREATE_ALL, [ids, models.map((m) => this.serializer.serialize(m, clazz.name))], transient, undefined, tableName);
168
168
  try {
169
169
  return JSON.parse(this.decode(result)).map((r) => JSON.parse(r));
170
170
  }
@@ -179,13 +179,12 @@ class FabricClientAdapter extends for_couchdb_1.CouchDBAdapter {
179
179
  * @param {string[] | number[]} ids - Array of record identifiers to read
180
180
  * @return {Promise<Array<Record<string, any>>>} Promise resolving to the retrieved records
181
181
  */
182
- async readAll(tableName, ids) {
183
- const log = this.log.for(this.readAll);
184
- if (typeof tableName !== "string")
185
- tableName = tableName.name;
182
+ async readAll(clazz, ids, ...args) {
183
+ const { log } = this.logCtx(args, this.readAll);
184
+ const tableName = decorator_validation_1.Model.tableName(clazz);
186
185
  log.info(`reading ${ids.length} entries to ${tableName} table`);
187
186
  log.verbose(`pks: ${ids}`);
188
- const result = await this.submitTransaction(db_decorators_1.BulkCrudOperationKeys.READ_ALL, [ids], undefined, undefined, tableName);
187
+ const result = await this.evaluateTransaction(db_decorators_1.BulkCrudOperationKeys.READ_ALL, [ids], undefined, undefined, tableName);
189
188
  try {
190
189
  return JSON.parse(this.decode(result)).map((r) => JSON.parse(r));
191
190
  }
@@ -202,15 +201,16 @@ class FabricClientAdapter extends for_couchdb_1.CouchDBAdapter {
202
201
  * @param {Record<string, any>} transient - Transient data for the transaction
203
202
  * @return {Promise<Array<Record<string, any>>>} Promise resolving to the updated records
204
203
  */
205
- async updateAll(tableName, ids, models, transient) {
206
- const log = this.log.for(this.updateAll);
204
+ async updateAll(clazz, ids, models, ...args) {
207
205
  if (ids.length !== models.length)
208
- throw new db_decorators_1.InternalError(`Ids and models must have the same length: ${ids.length} != ${models.length}`);
209
- if (typeof tableName !== "string")
210
- tableName = tableName.name;
206
+ throw new db_decorators_1.InternalError("Ids and models must have the same length");
207
+ const ctxArgs = [...args];
208
+ const transient = ctxArgs.shift();
209
+ const { log } = this.logCtx(ctxArgs, this.updateAll);
210
+ const tableName = decorator_validation_1.Model.tableName(clazz);
211
211
  log.info(`updating ${ids.length} entries to ${tableName} table`);
212
212
  log.verbose(`pks: ${ids}`);
213
- const result = await this.submitTransaction(db_decorators_1.BulkCrudOperationKeys.UPDATE_ALL, [ids, models.map((m) => this.serializer.serialize(m, tableName))], transient, undefined, tableName);
213
+ const result = await this.submitTransaction(db_decorators_1.BulkCrudOperationKeys.UPDATE_ALL, [ids, models.map((m) => this.serializer.serialize(m, clazz.name))], transient, undefined, clazz.name);
214
214
  try {
215
215
  return JSON.parse(this.decode(result)).map((r) => JSON.parse(r));
216
216
  }
@@ -226,13 +226,12 @@ class FabricClientAdapter extends for_couchdb_1.CouchDBAdapter {
226
226
  * @param {Serializer<any>} serializer - Serializer for the model data
227
227
  * @return {Promise<Array<Record<string, any>>>} Promise resolving to the deleted records
228
228
  */
229
- async deleteAll(tableName, ids) {
230
- const log = this.log.for(this.deleteAll);
231
- if (typeof tableName !== "string")
232
- tableName = tableName.name;
229
+ async deleteAll(clazz, ids, ...args) {
230
+ const { log } = core_1.Adapter.logCtx(args, this.deleteAll);
231
+ const tableName = decorator_validation_1.Model.tableName(clazz);
233
232
  log.info(`deleting ${ids.length} entries to ${tableName} table`);
234
233
  log.verbose(`pks: ${ids}`);
235
- const result = await this.submitTransaction(db_decorators_1.BulkCrudOperationKeys.DELETE_ALL, [ids], undefined, undefined, tableName);
234
+ const result = await this.submitTransaction(db_decorators_1.BulkCrudOperationKeys.DELETE_ALL, [ids], undefined, undefined, clazz.name);
236
235
  try {
237
236
  return JSON.parse(this.decode(result)).map((r) => JSON.parse(r));
238
237
  }
@@ -249,8 +248,8 @@ class FabricClientAdapter extends for_couchdb_1.CouchDBAdapter {
249
248
  * @param pk - The primary key property name
250
249
  * @return The prepared data
251
250
  */
252
- prepare(model, pk) {
253
- const log = this.log.for(this.prepare);
251
+ prepare(model, ...args) {
252
+ const { log } = this.logCtx(args, this.prepare);
254
253
  const split = decorator_validation_1.Model.segregate(model);
255
254
  if (model[core_1.PersistenceKeys.METADATA]) {
256
255
  log.silly(`Passing along persistence metadata for ${model[core_1.PersistenceKeys.METADATA]}`);
@@ -263,7 +262,7 @@ class FabricClientAdapter extends for_couchdb_1.CouchDBAdapter {
263
262
  }
264
263
  return {
265
264
  record: split.model,
266
- id: model[pk],
265
+ id: model[decorator_validation_1.Model.pk(model.constructor)],
267
266
  transient: split.transient,
268
267
  };
269
268
  }
@@ -279,31 +278,33 @@ class FabricClientAdapter extends for_couchdb_1.CouchDBAdapter {
279
278
  * @param [transient] - Transient properties to reattach
280
279
  * @return {M} The reconstructed model instance
281
280
  */
282
- revert(obj, clazz, pk, id, transient) {
283
- const log = this.log.for(this.revert);
281
+ revert(obj, clazz, id, transient, ...args) {
282
+ const { log, ctx } = this.logCtx(args, this.revert);
284
283
  const ob = {};
284
+ const pk = decorator_validation_1.Model.pk(clazz);
285
285
  ob[pk] = id;
286
- const m = (typeof clazz === "string" ? decorator_validation_1.Model.build(ob, clazz) : new clazz(ob));
286
+ const m = new clazz(ob);
287
287
  log.silly(`Rebuilding model ${m.constructor.name} id ${id}`);
288
288
  const metadata = obj[core_1.PersistenceKeys.METADATA];
289
289
  const result = Object.keys(m).reduce((accum, key) => {
290
290
  accum[key] = obj[key];
291
291
  return accum;
292
292
  }, m);
293
- if (transient) {
293
+ if (ctx.get("rebuildWithTransient") && transient) {
294
294
  log.verbose(`re-adding transient properties: ${Object.keys(transient).join(", ")}`);
295
295
  Object.entries(transient).forEach(([key, val]) => {
296
- if (key in result && result[key] !== undefined)
296
+ if (key in result)
297
297
  throw new db_decorators_1.InternalError(`Transient property ${key} already exists on model ${m.constructor.name}. should be impossible`);
298
298
  result[key] = val;
299
299
  });
300
300
  }
301
301
  if (metadata) {
302
+ // TODO move to couchdb
302
303
  log.silly(`Passing along ${this.flavour} persistence metadata for ${m.constructor.name} id ${id}: ${metadata}`);
303
304
  Object.defineProperty(result, core_1.PersistenceKeys.METADATA, {
304
305
  enumerable: false,
305
- configurable: false,
306
- writable: false,
306
+ configurable: true,
307
+ writable: true,
307
308
  value: metadata,
308
309
  });
309
310
  }
@@ -328,13 +329,14 @@ class FabricClientAdapter extends for_couchdb_1.CouchDBAdapter {
328
329
  * @param {Record<string, any>} transient - Transient data for the transaction
329
330
  * @return {Promise<Record<string, any>>} Promise resolving to the created record
330
331
  */
331
- async create(tableName, id, model, transient) {
332
- const log = this.log.for(this.create);
333
- if (typeof tableName !== "string")
334
- tableName = tableName.name;
332
+ async create(clazz, id, model, ...args) {
333
+ const ctxArgs = [...args];
334
+ const transient = ctxArgs.shift() || {};
335
+ const { log } = this.logCtx(ctxArgs, this.create);
336
+ const tableName = decorator_validation_1.Model.tableName(clazz);
335
337
  log.verbose(`adding entry to ${tableName} table`);
336
338
  log.debug(`pk: ${id}`);
337
- const result = await this.submitTransaction(db_decorators_1.OperationKeys.CREATE, [this.serializer.serialize(model, tableName)], transient, undefined, tableName);
339
+ const result = await this.submitTransaction(db_decorators_1.OperationKeys.CREATE, [this.serializer.serialize(model, clazz.name)], transient, undefined, clazz.name);
338
340
  return this.serializer.deserialize(this.decode(result));
339
341
  }
340
342
  /**
@@ -344,21 +346,22 @@ class FabricClientAdapter extends for_couchdb_1.CouchDBAdapter {
344
346
  * @param {string | number} id - The record identifier
345
347
  * @return {Promise<Record<string, any>>} Promise resolving to the retrieved record
346
348
  */
347
- async read(tableName, id) {
348
- const log = this.log.for(this.read);
349
- if (typeof tableName !== "string")
350
- tableName = tableName.name;
349
+ async read(clazz, id, ...args) {
350
+ const { log } = this.logCtx(args, this.readAll);
351
+ const tableName = decorator_validation_1.Model.tableName(clazz);
351
352
  log.verbose(`reading entry from ${tableName} table`);
352
353
  log.debug(`pk: ${id}`);
353
- const result = await this.evaluateTransaction(db_decorators_1.OperationKeys.READ, [id.toString()], undefined, undefined, tableName);
354
+ const result = await this.evaluateTransaction(db_decorators_1.OperationKeys.READ, [id.toString()], undefined, undefined, clazz.name);
354
355
  return this.serializer.deserialize(this.decode(result));
355
356
  }
356
- updatePrefix(tableName, id, model) {
357
+ updatePrefix(clazz, id, model, ...args) {
358
+ const tableName = decorator_validation_1.Model.tableName(clazz);
359
+ const { ctxArgs } = this.logCtx(args, this.updatePrefix);
357
360
  const record = {};
358
361
  record[for_couchdb_1.CouchDBKeys.TABLE] = tableName;
359
362
  record[for_couchdb_1.CouchDBKeys.ID] = this.generateId(tableName, id);
360
363
  Object.assign(record, model);
361
- return [tableName, id, record];
364
+ return [tableName, id, record, ...ctxArgs];
362
365
  }
363
366
  /**
364
367
  * @description Updates a single record
@@ -369,13 +372,14 @@ class FabricClientAdapter extends for_couchdb_1.CouchDBAdapter {
369
372
  * @param {Record<string, any>} transient - Transient data for the transaction
370
373
  * @return {Promise<Record<string, any>>} Promise resolving to the updated record
371
374
  */
372
- async update(tableName, id, model, transient) {
373
- const log = this.log.for(this.update);
374
- if (typeof tableName !== "string")
375
- tableName = tableName.name;
375
+ async update(clazz, id, model, ...args) {
376
+ const ctxArgs = [...args];
377
+ const transient = ctxArgs.shift() || {};
378
+ const { log } = this.logCtx(ctxArgs, this.updateAll);
379
+ const tableName = decorator_validation_1.Model.tableName(clazz);
376
380
  log.verbose(`updating entry to ${tableName} table`);
377
381
  log.debug(`pk: ${id}`);
378
- const result = await this.submitTransaction(db_decorators_1.OperationKeys.UPDATE, [this.serializer.serialize(model, tableName)], transient, undefined, tableName);
382
+ const result = await this.submitTransaction(db_decorators_1.OperationKeys.UPDATE, [this.serializer.serialize(model, clazz.name)], transient, undefined, clazz.name);
379
383
  return this.serializer.deserialize(this.decode(result));
380
384
  }
381
385
  /**
@@ -385,13 +389,12 @@ class FabricClientAdapter extends for_couchdb_1.CouchDBAdapter {
385
389
  * @param {string | number} id - The record identifier to delete
386
390
  * @return {Promise<Record<string, any>>} Promise resolving to the deleted record
387
391
  */
388
- async delete(tableName, id) {
389
- const log = this.log.for(this.delete);
390
- if (typeof tableName !== "string")
391
- tableName = tableName.name;
392
+ async delete(clazz, id, ...args) {
393
+ const { log } = this.logCtx(args, this.delete);
394
+ const tableName = decorator_validation_1.Model.tableName(clazz);
392
395
  log.verbose(`deleting entry from ${tableName} table`);
393
396
  log.debug(`pk: ${id}`);
394
- const result = await this.submitTransaction(db_decorators_1.OperationKeys.DELETE, [id.toString()], undefined, undefined, tableName);
397
+ const result = await this.submitTransaction(db_decorators_1.OperationKeys.DELETE, [id.toString()], undefined, undefined, clazz.name);
395
398
  return this.serializer.deserialize(this.decode(result));
396
399
  }
397
400
  /**
@@ -419,8 +422,17 @@ class FabricClientAdapter extends for_couchdb_1.CouchDBAdapter {
419
422
  * FabricAdapter->>FabricAdapter: Process result based on type
420
423
  * FabricAdapter-->>Client: processed result
421
424
  */
422
- async raw(rawInput, process, tableName) {
423
- const log = this.log.for(this.raw);
425
+ async raw(rawInput, ...args) {
426
+ const ctxArgs = [...args];
427
+ if (typeof ctxArgs[0] === "boolean") {
428
+ ctxArgs.shift();
429
+ }
430
+ let tableName;
431
+ if (ctxArgs.length &&
432
+ (typeof ctxArgs[0] === "string" || typeof ctxArgs[0] === "function")) {
433
+ tableName = ctxArgs.shift();
434
+ }
435
+ const { log } = this.logCtx(ctxArgs, this.raw);
424
436
  log.info(`Performing raw query on table`);
425
437
  log.debug(`processing raw input for query: ${JSON.stringify(rawInput)}`);
426
438
  let input;
@@ -433,7 +445,7 @@ class FabricClientAdapter extends for_couchdb_1.CouchDBAdapter {
433
445
  let transactionResult;
434
446
  try {
435
447
  if (typeof tableName !== "string")
436
- tableName = tableName.name;
448
+ tableName = tableName?.name;
437
449
  transactionResult = await this.evaluateTransaction("query", [input], undefined, undefined, tableName);
438
450
  }
439
451
  catch (e) {
@@ -624,7 +636,7 @@ class FabricClientAdapter extends for_couchdb_1.CouchDBAdapter {
624
636
  * @return {Network} The Network instance
625
637
  */
626
638
  static getNetwork(gateway, channelName) {
627
- const log = this.log.for(this.getNetwork);
639
+ const log = logging_1.Logging.for(this.getNetwork);
628
640
  let network;
629
641
  try {
630
642
  log.debug(`Connecting to channel ${channelName}`);
@@ -685,7 +697,7 @@ class FabricClientAdapter extends for_couchdb_1.CouchDBAdapter {
685
697
  * FabricAdapter-->>Caller: gateway
686
698
  */
687
699
  static async getConnection(client, config) {
688
- const log = this.log.for(this.getConnection);
700
+ const log = logging_1.Logging.for(this.getConnection);
689
701
  log.debug(`Retrieving Peer Identity for ${config.mspId} under ${config.certCertOrDirectoryPath}`);
690
702
  const identity = await (0, fabric_fs_1.getIdentity)(config.mspId, config.certCertOrDirectoryPath);
691
703
  log.debug(`Retrieving signer key from ${config.keyCertOrDirectoryPath}`);
@@ -756,6 +768,7 @@ class FabricClientAdapter extends for_couchdb_1.CouchDBAdapter {
756
768
  * @return {BaseError} The parsed error
757
769
  */
758
770
  static parseError(err, reason) {
771
+ // TODO
759
772
  return super.parseError(err, reason);
760
773
  }
761
774
  }
@@ -770,36 +783,36 @@ __decorate([
770
783
  ], FabricClientAdapter.prototype, "index", null);
771
784
  __decorate([
772
785
  (0, logging_1.debug)(),
773
- (0, core_1.final)(),
786
+ (0, logging_1.final)(),
774
787
  __metadata("design:type", Function),
775
- __metadata("design:paramtypes", [String, Object, Object, Object]),
788
+ __metadata("design:paramtypes", [Object, Object, Object, FabricClientContext]),
776
789
  __metadata("design:returntype", Promise)
777
790
  ], FabricClientAdapter.prototype, "create", null);
778
791
  __decorate([
779
792
  (0, logging_1.debug)(),
780
- (0, core_1.final)(),
793
+ (0, logging_1.final)(),
781
794
  __metadata("design:type", Function),
782
- __metadata("design:paramtypes", [String, Object]),
795
+ __metadata("design:paramtypes", [Object, Object, FabricClientContext]),
783
796
  __metadata("design:returntype", Promise)
784
797
  ], FabricClientAdapter.prototype, "read", null);
785
798
  __decorate([
786
799
  (0, logging_1.debug)(),
787
- (0, core_1.final)(),
800
+ (0, logging_1.final)(),
788
801
  __metadata("design:type", Function),
789
- __metadata("design:paramtypes", [String, Object, Object, Object]),
802
+ __metadata("design:paramtypes", [Object, Object, Object, FabricClientContext]),
790
803
  __metadata("design:returntype", Promise)
791
804
  ], FabricClientAdapter.prototype, "update", null);
792
805
  __decorate([
793
806
  (0, logging_1.debug)(),
794
- (0, core_1.final)(),
807
+ (0, logging_1.final)(),
795
808
  __metadata("design:type", Function),
796
- __metadata("design:paramtypes", [String, Object]),
809
+ __metadata("design:paramtypes", [Object, Object, FabricClientContext]),
797
810
  __metadata("design:returntype", Promise)
798
811
  ], FabricClientAdapter.prototype, "delete", null);
799
812
  __decorate([
800
813
  (0, logging_1.debug)(),
801
814
  __metadata("design:type", Function),
802
- __metadata("design:paramtypes", [Object, Boolean, String]),
815
+ __metadata("design:paramtypes", [Object, FabricClientContext]),
803
816
  __metadata("design:returntype", Promise)
804
817
  ], FabricClientAdapter.prototype, "raw", null);
805
818
  FabricClientAdapter.decoration();
@@ -1,13 +1,16 @@
1
1
  import { CouchDBAdapter, type MangoQuery } from "@decaf-ts/for-couchdb";
2
2
  import { Client } from "@grpc/grpc-js";
3
3
  import { Model, type Serializer } from "@decaf-ts/decorator-validation";
4
- import { type Logger } from "@decaf-ts/logging";
5
4
  import { type FabricFlags, type PeerConfig } from "../shared/types";
6
5
  import { Gateway, Network, Contract as Contrakt } from "@hyperledger/fabric-gateway";
7
- import { BaseError, Context } from "@decaf-ts/db-decorators";
8
- import { Adapter, Repository } from "@decaf-ts/core";
6
+ import { BaseError, OperationKeys } from "@decaf-ts/db-decorators";
7
+ import { Context, type PrimaryKeyType } from "@decaf-ts/db-decorators";
8
+ import { Adapter, PreparedModel, Repository } from "@decaf-ts/core";
9
+ import type { ContextualArgs, MaybeContextualArg } from "@decaf-ts/core";
9
10
  import type { FabricClientDispatch } from "./FabricClientDispatch";
10
11
  import { type Constructor } from "@decaf-ts/decoration";
12
+ export declare class FabricClientContext extends Context<FabricFlags> {
13
+ }
11
14
  /**
12
15
  * @description Adapter for interacting with Hyperledger Fabric networks
13
16
  * @summary The FabricAdapter extends CouchDBAdapter to provide a seamless interface for interacting with Hyperledger Fabric networks.
@@ -59,22 +62,13 @@ import { type Constructor } from "@decaf-ts/decoration";
59
62
  * FabricAdapter->>FabricAdapter: serializer.deserialize(decodedResult)
60
63
  * FabricAdapter-->>Client: deserializedResult
61
64
  */
62
- export declare class FabricClientAdapter extends CouchDBAdapter<PeerConfig, Client, FabricFlags, Context<FabricFlags>> {
65
+ export declare class FabricClientAdapter extends CouchDBAdapter<PeerConfig, Client, FabricClientContext> {
63
66
  /**
64
67
  * @description Static text decoder for converting Uint8Array to string
65
68
  */
66
69
  private static decoder;
67
70
  private static serializer;
68
- /**
69
- * @description Static logger instance for the FabricAdapter class
70
- */
71
- private static log;
72
- /**
73
- * @description Gets the logger instance for this adapter
74
- * @summary Returns the static logger instance for the FabricAdapter class
75
- * @return {Logger} The logger instance
76
- */
77
- protected get log(): Logger;
71
+ protected static log: import("@decaf-ts/logging").Logger;
78
72
  protected readonly serializer: Serializer<any>;
79
73
  /**
80
74
  * @description Creates a new FabricAdapter instance
@@ -83,6 +77,7 @@ export declare class FabricClientAdapter extends CouchDBAdapter<PeerConfig, Clie
83
77
  * @param {string} [alias] - Optional alias for the adapter instance
84
78
  */
85
79
  constructor(config: PeerConfig, alias?: string);
80
+ context<M extends Model>(operation: OperationKeys.CREATE | OperationKeys.READ | OperationKeys.UPDATE | OperationKeys.DELETE | string, overrides: Partial<FabricFlags>, model: Constructor<M> | Constructor<M>[], ...args: any[]): Promise<FabricClientContext>;
86
81
  /**
87
82
  * @description Decodes a Uint8Array to a string
88
83
  * @summary Converts binary data received from Fabric to a string using UTF-8 encoding
@@ -90,7 +85,7 @@ export declare class FabricClientAdapter extends CouchDBAdapter<PeerConfig, Clie
90
85
  * @return {string} The decoded string
91
86
  */
92
87
  decode(data: Uint8Array): string;
93
- repository<M extends Model<true | false>>(): Constructor<Repository<M, MangoQuery, Adapter<PeerConfig, Client, MangoQuery, FabricFlags, Context<FabricFlags>>, FabricFlags, Context<FabricFlags>>>;
88
+ repository<R extends Repository<any, Adapter<PeerConfig, Client, MangoQuery, FabricClientContext>>>(): Constructor<R>;
94
89
  /**
95
90
  * @description Creates multiple records in a single transaction
96
91
  * @summary Submits a transaction to create multiple records in the Fabric ledger
@@ -100,7 +95,7 @@ export declare class FabricClientAdapter extends CouchDBAdapter<PeerConfig, Clie
100
95
  * @param {Record<string, any>} transient - Transient data for the transaction
101
96
  * @return {Promise<Array<Record<string, any>>>} Promise resolving to the created records
102
97
  */
103
- createAll(tableName: string, ids: string[] | number[], models: Record<string, any>[], transient: Record<string, any>): Promise<Record<string, any>[]>;
98
+ createAll<M extends Model>(clazz: Constructor<M>, ids: PrimaryKeyType[], models: Record<string, any>[], ...args: ContextualArgs<FabricClientContext>): Promise<Record<string, any>[]>;
104
99
  /**
105
100
  * @description Reads multiple records in a single transaction
106
101
  * @summary Submits a transaction to read multiple records from the Fabric ledger
@@ -108,7 +103,7 @@ export declare class FabricClientAdapter extends CouchDBAdapter<PeerConfig, Clie
108
103
  * @param {string[] | number[]} ids - Array of record identifiers to read
109
104
  * @return {Promise<Array<Record<string, any>>>} Promise resolving to the retrieved records
110
105
  */
111
- readAll(tableName: string, ids: string[] | number[]): Promise<Record<string, any>[]>;
106
+ readAll<M extends Model>(clazz: Constructor<M>, ids: PrimaryKeyType[], ...args: ContextualArgs<FabricClientContext>): Promise<Record<string, any>[]>;
112
107
  /**
113
108
  * @description Updates multiple records in a single transaction
114
109
  * @summary Submits a transaction to update multiple records in the Fabric ledger
@@ -118,7 +113,7 @@ export declare class FabricClientAdapter extends CouchDBAdapter<PeerConfig, Clie
118
113
  * @param {Record<string, any>} transient - Transient data for the transaction
119
114
  * @return {Promise<Array<Record<string, any>>>} Promise resolving to the updated records
120
115
  */
121
- updateAll(tableName: string, ids: string[] | number[], models: Record<string, any>[], transient: Record<string, any>): Promise<Record<string, any>[]>;
116
+ updateAll<M extends Model>(clazz: Constructor<M>, ids: PrimaryKeyType[], models: Record<string, any>[], ...args: ContextualArgs<FabricClientContext>): Promise<Record<string, any>[]>;
122
117
  /**
123
118
  * @description Deletes multiple records in a single transaction
124
119
  * @summary Submits a transaction to delete multiple records from the Fabric ledger
@@ -127,7 +122,7 @@ export declare class FabricClientAdapter extends CouchDBAdapter<PeerConfig, Clie
127
122
  * @param {Serializer<any>} serializer - Serializer for the model data
128
123
  * @return {Promise<Array<Record<string, any>>>} Promise resolving to the deleted records
129
124
  */
130
- deleteAll(tableName: string, ids: (string | number | bigint)[]): Promise<Record<string, any>[]>;
125
+ deleteAll<M extends Model>(clazz: Constructor<M>, ids: PrimaryKeyType[], ...args: ContextualArgs<FabricClientContext>): Promise<Record<string, any>[]>;
131
126
  /**
132
127
  * @description Prepares a model for persistence
133
128
  * @summary Converts a model instance into a format suitable for database storage,
@@ -137,11 +132,7 @@ export declare class FabricClientAdapter extends CouchDBAdapter<PeerConfig, Clie
137
132
  * @param pk - The primary key property name
138
133
  * @return The prepared data
139
134
  */
140
- prepare<M extends Model>(model: M, pk: keyof M): {
141
- record: Record<string, any>;
142
- id: string;
143
- transient?: Record<string, any>;
144
- };
135
+ prepare<M extends Model>(model: M, ...args: ContextualArgs<FabricClientContext>): PreparedModel;
145
136
  /**
146
137
  * @description Converts database data back into a model instance
147
138
  * @summary Reconstructs a model instance from database data, handling column mapping
@@ -154,7 +145,7 @@ export declare class FabricClientAdapter extends CouchDBAdapter<PeerConfig, Clie
154
145
  * @param [transient] - Transient properties to reattach
155
146
  * @return {M} The reconstructed model instance
156
147
  */
157
- revert<M extends Model>(obj: Record<string, any>, clazz: string | Constructor<M>, pk: keyof M, id: string | number | bigint, transient?: Record<string, any>): M;
148
+ revert<M extends Model>(obj: Record<string, any>, clazz: Constructor<M>, id: PrimaryKeyType, transient?: Record<string, any>, ...args: ContextualArgs<FabricClientContext>): M;
158
149
  /**
159
150
  * @description Creates an index for a model
160
151
  * @summary This method is not implemented for Fabric and will throw an error
@@ -172,7 +163,7 @@ export declare class FabricClientAdapter extends CouchDBAdapter<PeerConfig, Clie
172
163
  * @param {Record<string, any>} transient - Transient data for the transaction
173
164
  * @return {Promise<Record<string, any>>} Promise resolving to the created record
174
165
  */
175
- create(tableName: string, id: string | number, model: Record<string, any>, transient: Record<string, any>): Promise<Record<string, any>>;
166
+ create<M extends Model>(clazz: Constructor<M>, id: PrimaryKeyType, model: Record<string, any>, ...args: ContextualArgs<FabricClientContext>): Promise<Record<string, any>>;
176
167
  /**
177
168
  * @description Reads a single record
178
169
  * @summary Evaluates a transaction to read a record from the Fabric ledger
@@ -180,8 +171,8 @@ export declare class FabricClientAdapter extends CouchDBAdapter<PeerConfig, Clie
180
171
  * @param {string | number} id - The record identifier
181
172
  * @return {Promise<Record<string, any>>} Promise resolving to the retrieved record
182
173
  */
183
- read(tableName: string, id: string | number): Promise<Record<string, any>>;
184
- updatePrefix(tableName: string, id: string | number, model: Record<string, any>): (string | number | Record<string, any>)[];
174
+ read<M extends Model>(clazz: Constructor<M>, id: PrimaryKeyType, ...args: ContextualArgs<FabricClientContext>): Promise<Record<string, any>>;
175
+ updatePrefix<M extends Model>(clazz: Constructor<M>, id: PrimaryKeyType, model: Record<string, any>, ...args: MaybeContextualArg<FabricClientContext>): any[];
185
176
  /**
186
177
  * @description Updates a single record
187
178
  * @summary Submits a transaction to update a record in the Fabric ledger
@@ -191,7 +182,7 @@ export declare class FabricClientAdapter extends CouchDBAdapter<PeerConfig, Clie
191
182
  * @param {Record<string, any>} transient - Transient data for the transaction
192
183
  * @return {Promise<Record<string, any>>} Promise resolving to the updated record
193
184
  */
194
- update(tableName: string, id: string | number, model: Record<string, any>, transient: Record<string, any>): Promise<Record<string, any>>;
185
+ update<M extends Model>(clazz: Constructor<M>, id: PrimaryKeyType, model: Record<string, any>, ...args: ContextualArgs<FabricClientContext>): Promise<Record<string, any>>;
195
186
  /**
196
187
  * @description Deletes a single record
197
188
  * @summary Submits a transaction to delete a record from the Fabric ledger
@@ -199,7 +190,7 @@ export declare class FabricClientAdapter extends CouchDBAdapter<PeerConfig, Clie
199
190
  * @param {string | number} id - The record identifier to delete
200
191
  * @return {Promise<Record<string, any>>} Promise resolving to the deleted record
201
192
  */
202
- delete(tableName: string, id: string | number): Promise<Record<string, any>>;
193
+ delete<M extends Model>(clazz: Constructor<M>, id: PrimaryKeyType, ...args: ContextualArgs<FabricClientContext>): Promise<Record<string, any>>;
203
194
  /**
204
195
  * @description Executes a raw query against the Fabric ledger
205
196
  * @summary Evaluates a transaction to perform a query using Mango Query syntax
@@ -225,7 +216,7 @@ export declare class FabricClientAdapter extends CouchDBAdapter<PeerConfig, Clie
225
216
  * FabricAdapter->>FabricAdapter: Process result based on type
226
217
  * FabricAdapter-->>Client: processed result
227
218
  */
228
- raw<V>(rawInput: MangoQuery, process: boolean, tableName?: string): Promise<V>;
219
+ raw<V>(rawInput: MangoQuery, ...args: ContextualArgs<FabricClientContext>): Promise<V>;
229
220
  /**
230
221
  * @description Gets or creates a gRPC client for the Fabric peer
231
222
  * @summary Returns a cached client or creates a new one if none exists
@@ -281,7 +272,7 @@ export declare class FabricClientAdapter extends CouchDBAdapter<PeerConfig, Clie
281
272
  * @param {string} [reason] - Optional reason for the error
282
273
  * @return {BaseError} The parsed error
283
274
  */
284
- parseError(err: Error | string, reason?: string): BaseError;
275
+ parseError<E extends BaseError>(err: Error | string, reason?: string): E;
285
276
  /**
286
277
  * @description Submits a transaction to the Fabric network
287
278
  * @summary Executes a transaction that modifies the ledger state
@@ -381,5 +372,5 @@ export declare class FabricClientAdapter extends CouchDBAdapter<PeerConfig, Clie
381
372
  * @param {string} [reason] - Optional reason for the error
382
373
  * @return {BaseError} The parsed error
383
374
  */
384
- protected static parseError(err: Error | string, reason?: string): BaseError;
375
+ protected static parseError<E extends BaseError>(err: Error | string, reason?: string): E;
385
376
  }