@decaf-ts/for-fabric 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (205) hide show
  1. package/LICENSE.md +22 -0
  2. package/README.md +647 -0
  3. package/dist/for-fabric.cjs +6223 -0
  4. package/dist/for-fabric.esm.cjs +6180 -0
  5. package/lib/client/FabricClientAdapter.cjs +760 -0
  6. package/lib/client/FabricClientAdapter.d.ts +381 -0
  7. package/lib/client/FabricClientDispatch.cjs +186 -0
  8. package/lib/client/FabricClientDispatch.d.ts +125 -0
  9. package/lib/client/FabricClientRepository.cjs +131 -0
  10. package/lib/client/FabricClientRepository.d.ts +100 -0
  11. package/lib/client/erc20/erc20ClientRepository.cjs +343 -0
  12. package/lib/client/erc20/erc20ClientRepository.d.ts +254 -0
  13. package/lib/client/fabric-fs.cjs +234 -0
  14. package/lib/client/fabric-fs.d.ts +92 -0
  15. package/lib/client/index.cjs +30 -0
  16. package/lib/client/index.d.ts +13 -0
  17. package/lib/client/logging.cjs +102 -0
  18. package/lib/client/logging.d.ts +60 -0
  19. package/lib/client/services/LoggedService.cjs +47 -0
  20. package/lib/client/services/LoggedService.d.ts +42 -0
  21. package/lib/client/services/constants.cjs +3 -0
  22. package/lib/client/services/constants.d.ts +15 -0
  23. package/lib/client/services/enrollementService.cjs +344 -0
  24. package/lib/client/services/enrollementService.d.ts +176 -0
  25. package/lib/client/services/index.cjs +18 -0
  26. package/lib/client/services/index.d.ts +1 -0
  27. package/lib/contracts/ContractAdapter.cjs +730 -0
  28. package/lib/contracts/ContractAdapter.d.ts +296 -0
  29. package/lib/contracts/ContractContext.cjs +85 -0
  30. package/lib/contracts/ContractContext.d.ts +64 -0
  31. package/lib/contracts/ContractPrivateDataAdapter.cjs +281 -0
  32. package/lib/contracts/ContractPrivateDataAdapter.d.ts +74 -0
  33. package/lib/contracts/FabricConstruction.cjs +441 -0
  34. package/lib/contracts/FabricConstruction.d.ts +304 -0
  35. package/lib/contracts/FabricContractRepository.cjs +306 -0
  36. package/lib/contracts/FabricContractRepository.d.ts +162 -0
  37. package/lib/contracts/FabricContractRepositoryObservableHandler.cjs +85 -0
  38. package/lib/contracts/FabricContractRepositoryObservableHandler.d.ts +62 -0
  39. package/lib/contracts/FabricContractSequence.cjs +139 -0
  40. package/lib/contracts/FabricContractSequence.d.ts +61 -0
  41. package/lib/contracts/FabricContractStatement.cjs +119 -0
  42. package/lib/contracts/FabricContractStatement.d.ts +34 -0
  43. package/lib/contracts/PrivateSequence.cjs +36 -0
  44. package/lib/contracts/PrivateSequence.d.ts +15 -0
  45. package/lib/contracts/crud/crud-contract.cjs +257 -0
  46. package/lib/contracts/crud/crud-contract.d.ts +168 -0
  47. package/lib/contracts/crud/index.cjs +19 -0
  48. package/lib/contracts/crud/index.d.ts +2 -0
  49. package/lib/contracts/crud/serialized-crud-contract.cjs +172 -0
  50. package/lib/contracts/crud/serialized-crud-contract.d.ts +37 -0
  51. package/lib/contracts/erc20/erc20contract.cjs +569 -0
  52. package/lib/contracts/erc20/erc20contract.d.ts +151 -0
  53. package/lib/contracts/erc20/index.cjs +21 -0
  54. package/lib/contracts/erc20/index.d.ts +2 -0
  55. package/lib/contracts/erc20/models.cjs +209 -0
  56. package/lib/contracts/erc20/models.d.ts +114 -0
  57. package/lib/contracts/index.cjs +32 -0
  58. package/lib/contracts/index.d.ts +15 -0
  59. package/lib/contracts/logging.cjs +96 -0
  60. package/lib/contracts/logging.d.ts +49 -0
  61. package/lib/contracts/private-data.cjs +121 -0
  62. package/lib/contracts/private-data.d.ts +16 -0
  63. package/lib/contracts/types.cjs +3 -0
  64. package/lib/contracts/types.d.ts +26 -0
  65. package/lib/esm/client/FabricClientAdapter.d.ts +381 -0
  66. package/lib/esm/client/FabricClientAdapter.js +723 -0
  67. package/lib/esm/client/FabricClientDispatch.d.ts +125 -0
  68. package/lib/esm/client/FabricClientDispatch.js +182 -0
  69. package/lib/esm/client/FabricClientRepository.d.ts +100 -0
  70. package/lib/esm/client/FabricClientRepository.js +127 -0
  71. package/lib/esm/client/erc20/erc20ClientRepository.d.ts +254 -0
  72. package/lib/esm/client/erc20/erc20ClientRepository.js +339 -0
  73. package/lib/esm/client/fabric-fs.d.ts +92 -0
  74. package/lib/esm/client/fabric-fs.js +191 -0
  75. package/lib/esm/client/index.d.ts +13 -0
  76. package/lib/esm/client/index.js +14 -0
  77. package/lib/esm/client/logging.d.ts +60 -0
  78. package/lib/esm/client/logging.js +98 -0
  79. package/lib/esm/client/services/LoggedService.d.ts +42 -0
  80. package/lib/esm/client/services/LoggedService.js +43 -0
  81. package/lib/esm/client/services/constants.d.ts +15 -0
  82. package/lib/esm/client/services/constants.js +2 -0
  83. package/lib/esm/client/services/enrollementService.d.ts +176 -0
  84. package/lib/esm/client/services/enrollementService.js +337 -0
  85. package/lib/esm/client/services/index.d.ts +1 -0
  86. package/lib/esm/client/services/index.js +2 -0
  87. package/lib/esm/contracts/ContractAdapter.d.ts +296 -0
  88. package/lib/esm/contracts/ContractAdapter.js +724 -0
  89. package/lib/esm/contracts/ContractContext.d.ts +64 -0
  90. package/lib/esm/contracts/ContractContext.js +81 -0
  91. package/lib/esm/contracts/ContractPrivateDataAdapter.d.ts +74 -0
  92. package/lib/esm/contracts/ContractPrivateDataAdapter.js +277 -0
  93. package/lib/esm/contracts/FabricConstruction.d.ts +304 -0
  94. package/lib/esm/contracts/FabricConstruction.js +433 -0
  95. package/lib/esm/contracts/FabricContractRepository.d.ts +162 -0
  96. package/lib/esm/contracts/FabricContractRepository.js +302 -0
  97. package/lib/esm/contracts/FabricContractRepositoryObservableHandler.d.ts +62 -0
  98. package/lib/esm/contracts/FabricContractRepositoryObservableHandler.js +81 -0
  99. package/lib/esm/contracts/FabricContractSequence.d.ts +61 -0
  100. package/lib/esm/contracts/FabricContractSequence.js +135 -0
  101. package/lib/esm/contracts/FabricContractStatement.d.ts +34 -0
  102. package/lib/esm/contracts/FabricContractStatement.js +115 -0
  103. package/lib/esm/contracts/PrivateSequence.d.ts +15 -0
  104. package/lib/esm/contracts/PrivateSequence.js +33 -0
  105. package/lib/esm/contracts/crud/crud-contract.d.ts +168 -0
  106. package/lib/esm/contracts/crud/crud-contract.js +253 -0
  107. package/lib/esm/contracts/crud/index.d.ts +2 -0
  108. package/lib/esm/contracts/crud/index.js +3 -0
  109. package/lib/esm/contracts/crud/serialized-crud-contract.d.ts +37 -0
  110. package/lib/esm/contracts/crud/serialized-crud-contract.js +168 -0
  111. package/lib/esm/contracts/erc20/erc20contract.d.ts +151 -0
  112. package/lib/esm/contracts/erc20/erc20contract.js +565 -0
  113. package/lib/esm/contracts/erc20/index.d.ts +2 -0
  114. package/lib/esm/contracts/erc20/index.js +4 -0
  115. package/lib/esm/contracts/erc20/models.d.ts +114 -0
  116. package/lib/esm/contracts/erc20/models.js +206 -0
  117. package/lib/esm/contracts/index.d.ts +15 -0
  118. package/lib/esm/contracts/index.js +16 -0
  119. package/lib/esm/contracts/logging.d.ts +49 -0
  120. package/lib/esm/contracts/logging.js +92 -0
  121. package/lib/esm/contracts/private-data.d.ts +16 -0
  122. package/lib/esm/contracts/private-data.js +113 -0
  123. package/lib/esm/contracts/types.d.ts +26 -0
  124. package/lib/esm/contracts/types.js +2 -0
  125. package/lib/esm/index.d.ts +8 -0
  126. package/lib/esm/index.js +9 -0
  127. package/lib/esm/shared/ClientSerializer.d.ts +52 -0
  128. package/lib/esm/shared/ClientSerializer.js +80 -0
  129. package/lib/esm/shared/DeterministicSerializer.d.ts +40 -0
  130. package/lib/esm/shared/DeterministicSerializer.js +50 -0
  131. package/lib/esm/shared/SimpleDeterministicSerializer.d.ts +7 -0
  132. package/lib/esm/shared/SimpleDeterministicSerializer.js +42 -0
  133. package/lib/esm/shared/constants.d.ts +39 -0
  134. package/lib/esm/shared/constants.js +42 -0
  135. package/lib/esm/shared/crypto.d.ts +107 -0
  136. package/lib/esm/shared/crypto.js +331 -0
  137. package/lib/esm/shared/decorators.d.ts +24 -0
  138. package/lib/esm/shared/decorators.js +98 -0
  139. package/lib/esm/shared/erc20/erc20-constants.d.ts +25 -0
  140. package/lib/esm/shared/erc20/erc20-constants.js +27 -0
  141. package/lib/esm/shared/errors.d.ts +116 -0
  142. package/lib/esm/shared/errors.js +132 -0
  143. package/lib/esm/shared/events.d.ts +39 -0
  144. package/lib/esm/shared/events.js +47 -0
  145. package/lib/esm/shared/fabric-types.d.ts +33 -0
  146. package/lib/esm/shared/fabric-types.js +2 -0
  147. package/lib/esm/shared/index.d.ts +13 -0
  148. package/lib/esm/shared/index.js +14 -0
  149. package/lib/esm/shared/interfaces/Checkable.d.ts +21 -0
  150. package/lib/esm/shared/interfaces/Checkable.js +2 -0
  151. package/lib/esm/shared/math.d.ts +34 -0
  152. package/lib/esm/shared/math.js +61 -0
  153. package/lib/esm/shared/model/Identity.d.ts +42 -0
  154. package/lib/esm/shared/model/Identity.js +78 -0
  155. package/lib/esm/shared/model/IdentityCredentials.d.ts +41 -0
  156. package/lib/esm/shared/model/IdentityCredentials.js +74 -0
  157. package/lib/esm/shared/model/index.d.ts +1 -0
  158. package/lib/esm/shared/model/index.js +2 -0
  159. package/lib/esm/shared/model/utils.d.ts +60 -0
  160. package/lib/esm/shared/model/utils.js +108 -0
  161. package/lib/esm/shared/types.d.ts +79 -0
  162. package/lib/esm/shared/types.js +2 -0
  163. package/lib/esm/shared/utils.d.ts +55 -0
  164. package/lib/esm/shared/utils.js +148 -0
  165. package/lib/index.cjs +25 -0
  166. package/lib/index.d.ts +8 -0
  167. package/lib/shared/ClientSerializer.cjs +84 -0
  168. package/lib/shared/ClientSerializer.d.ts +52 -0
  169. package/lib/shared/DeterministicSerializer.cjs +54 -0
  170. package/lib/shared/DeterministicSerializer.d.ts +40 -0
  171. package/lib/shared/SimpleDeterministicSerializer.cjs +46 -0
  172. package/lib/shared/SimpleDeterministicSerializer.d.ts +7 -0
  173. package/lib/shared/constants.cjs +45 -0
  174. package/lib/shared/constants.d.ts +39 -0
  175. package/lib/shared/crypto.cjs +369 -0
  176. package/lib/shared/crypto.d.ts +107 -0
  177. package/lib/shared/decorators.cjs +105 -0
  178. package/lib/shared/decorators.d.ts +24 -0
  179. package/lib/shared/erc20/erc20-constants.cjs +30 -0
  180. package/lib/shared/erc20/erc20-constants.d.ts +25 -0
  181. package/lib/shared/errors.cjs +142 -0
  182. package/lib/shared/errors.d.ts +116 -0
  183. package/lib/shared/events.cjs +51 -0
  184. package/lib/shared/events.d.ts +39 -0
  185. package/lib/shared/fabric-types.cjs +4 -0
  186. package/lib/shared/fabric-types.d.ts +33 -0
  187. package/lib/shared/index.cjs +30 -0
  188. package/lib/shared/index.d.ts +13 -0
  189. package/lib/shared/interfaces/Checkable.cjs +3 -0
  190. package/lib/shared/interfaces/Checkable.d.ts +21 -0
  191. package/lib/shared/math.cjs +66 -0
  192. package/lib/shared/math.d.ts +34 -0
  193. package/lib/shared/model/Identity.cjs +81 -0
  194. package/lib/shared/model/Identity.d.ts +42 -0
  195. package/lib/shared/model/IdentityCredentials.cjs +77 -0
  196. package/lib/shared/model/IdentityCredentials.d.ts +41 -0
  197. package/lib/shared/model/index.cjs +18 -0
  198. package/lib/shared/model/index.d.ts +1 -0
  199. package/lib/shared/model/utils.cjs +114 -0
  200. package/lib/shared/model/utils.d.ts +60 -0
  201. package/lib/shared/types.cjs +3 -0
  202. package/lib/shared/types.d.ts +79 -0
  203. package/lib/shared/utils.cjs +185 -0
  204. package/lib/shared/utils.d.ts +55 -0
  205. package/package.json +166 -0
@@ -0,0 +1,296 @@
1
+ import { CouchDBAdapter, MangoQuery } from "@decaf-ts/for-couchdb";
2
+ import { Constructor, Model } from "@decaf-ts/decorator-validation";
3
+ import { FabricContractFlags } from "./types";
4
+ import { FabricContractContext } from "./ContractContext";
5
+ import { Context, OperationKeys } from "@decaf-ts/db-decorators";
6
+ import { Context as Ctx } from "fabric-contract-api";
7
+ import { Logger } from "@decaf-ts/logging";
8
+ import { ContractLogger } from "./logging";
9
+ import { RelationsMetadata, Repository, Sequence, SequenceOptions, Adapter } from "@decaf-ts/core";
10
+ import { FabricContractRepository } from "./FabricContractRepository";
11
+ import { ChaincodeStub, Iterators, StateQueryResponse } from "fabric-shim-api";
12
+ import { FabricStatement } from "./FabricContractStatement";
13
+ import { SimpleDeterministicSerializer } from "../shared/SimpleDeterministicSerializer";
14
+ /**
15
+ * @description Sets the creator or updater field in a model based on the user in the context
16
+ * @summary Callback function used in decorators to automatically set the created_by or updated_by fields
17
+ * with the username from the context when a document is created or updated
18
+ * @template M - Type extending Model
19
+ * @template R - Type extending NanoRepository<M>
20
+ * @template V - Type extending RelationsMetadata
21
+ * @param {R} this - The repository instance
22
+ * @param {FabricContractContext} context - The operation context containing user information
23
+ * @param {V} data - The relation metadata
24
+ * @param {string} key - The property key to set with the username
25
+ * @param {M} model - The model instance being created or updated
26
+ * @return {Promise<void>} A promise that resolves when the operation is complete
27
+ * @function createdByOnFabricCreateUpdate
28
+ * @memberOf module:fabric.contracts
29
+ * @mermaid
30
+ * sequenceDiagram
31
+ * participant F as createdByOnNanoCreateUpdate
32
+ * participant C as Context
33
+ * participant M as Model
34
+ * F->>C: get("user")
35
+ * C-->>F: user object
36
+ * F->>M: set key to user.name
37
+ * Note over F: If no user in context
38
+ * F-->>F: throw UnsupportedError
39
+ */
40
+ export declare function createdByOnFabricCreateUpdate<M extends Model, R extends FabricContractRepository<M>, V extends RelationsMetadata>(this: R, context: Context<FabricContractFlags>, data: V, key: keyof M, model: M): Promise<void>;
41
+ /**
42
+ * @description Primary key auto-assignment callback for Fabric models
43
+ * @summary Generates and assigns a primary key value to the specified model property using a Fabric-backed sequence when the model is created. If the sequence name is not provided in options, it is derived from the model via sequenceNameForModel. The assigned key is defined as non-writable and enumerable.
44
+ * @template M - Type extending Model for the target instance
45
+ * @template R - Type extending FabricContractRepository for repository context
46
+ * @template V - Type extending SequenceOptions to configure sequence behavior
47
+ * @template F - Type extending FabricContractFlags for contextual flags
48
+ * @param {R} this - The repository instance invoking the callback
49
+ * @param {FabricContractContext} context - Fabric contract context containing invocation metadata
50
+ * @param {V} data - Sequence options used to configure or locate the sequence
51
+ * @param {string} key - The primary key property name to assign on the model
52
+ * @param {M} model - The model instance to receive the generated primary key
53
+ * @return {Promise<void>} Resolves when the key is assigned or when no action is required
54
+ * @function pkFabricOnCreate
55
+ * @memberOf module:for-fabric.contracts
56
+ * @mermaid
57
+ * sequenceDiagram
58
+ * participant R as Repository
59
+ * participant C as Context<F>
60
+ * participant S as FabricContractDBSequence
61
+ * participant M as Model
62
+ * R->>R: derive sequence name if missing
63
+ * R->>S: adapter.Sequence(options)
64
+ * S-->>R: sequence instance
65
+ * R->>S: next(context)
66
+ * S-->>R: next value
67
+ * R->>M: define non-writable primary key
68
+ */
69
+ export declare function pkFabricOnCreate<M extends Model, R extends FabricContractRepository<M>, V extends SequenceOptions, F extends FabricContractFlags>(this: R, context: Context<F>, data: V, key: keyof M, model: M): Promise<void>;
70
+ /**
71
+ * @description Adapter for Hyperledger Fabric chaincode state database operations
72
+ * @summary Provides a CouchDB-like interface for interacting with the Fabric state database from within a chaincode contract
73
+ * @template void - No configuration needed for contract adapter
74
+ * @template FabricContractFlags - Flags specific to Fabric contract operations
75
+ * @template FabricContractContext - Context type for Fabric contract operations
76
+ * @class FabricContractAdapter
77
+ * @example
78
+ * ```typescript
79
+ * // In a Fabric chaincode contract class
80
+ * import { FabricContractAdapter } from '@decaf-ts/for-fabric';
81
+ *
82
+ * export class MyContract extends Contract {
83
+ * private adapter = new FabricContractAdapter();
84
+ *
85
+ * @Transaction()
86
+ * async createAsset(ctx: Context, id: string, data: string): Promise<void> {
87
+ * const model = { id, data, timestamp: Date.now() };
88
+ * await this.adapter.create('assets', id, model, {}, { stub: ctx.stub });
89
+ * }
90
+ * }
91
+ * ```
92
+ * @mermaid
93
+ * sequenceDiagram
94
+ * participant Contract
95
+ * participant FabricContractAdapter
96
+ * participant Stub
97
+ * participant StateDB
98
+ *
99
+ * Contract->>FabricContractAdapter: create(tableName, id, model, transient, ctx)
100
+ * FabricContractAdapter->>FabricContractAdapter: Serialize model to JSON
101
+ * FabricContractAdapter->>Stub: putState(id, serializedData)
102
+ * Stub->>StateDB: Write data
103
+ * StateDB-->>Stub: Success
104
+ * Stub-->>FabricContractAdapter: Success
105
+ * FabricContractAdapter-->>Contract: model
106
+ */
107
+ export declare class FabricContractAdapter extends CouchDBAdapter<any, void, FabricContractFlags, FabricContractContext> {
108
+ protected getClient(): void;
109
+ /**
110
+ * @description Text decoder for converting binary data to strings
111
+ */
112
+ private static textDecoder;
113
+ protected static readonly serializer: SimpleDeterministicSerializer<Model<false>>;
114
+ /**
115
+ * @description Creates a logger for a specific chaincode context
116
+ * @summary Returns a ContractLogger instance configured for the current context
117
+ * @param {Ctx} ctx - The Fabric chaincode context
118
+ * @return {ContractLogger} The logger instance
119
+ */
120
+ logFor(ctx: Ctx): ContractLogger;
121
+ /**
122
+ * @description Context constructor for this adapter
123
+ * @summary Overrides the base Context constructor with FabricContractContext
124
+ */
125
+ Context: typeof FabricContractContext;
126
+ /**
127
+ * @description Gets the repository constructor for this adapter
128
+ * @summary Returns the FabricContractRepository constructor for creating repositories
129
+ * @template M - Type extending Model
130
+ * @return {Constructor<Repository<M, MangoQuery, FabricContractAdapter, FabricContractFlags, FabricContractContext>>} The repository constructor
131
+ */
132
+ repository<M extends Model>(): Constructor<Repository<M, MangoQuery, Adapter<any, any, MangoQuery, FabricContractFlags, FabricContractContext>, FabricContractFlags, FabricContractContext>>;
133
+ /**
134
+ * @description Creates a new FabricContractAdapter instance
135
+ * @summary Initializes an adapter for interacting with the Fabric state database
136
+ * @param {void} scope - Not used in this adapter
137
+ * @param {string} [alias] - Optional alias for the adapter instance
138
+ */
139
+ constructor(scope: void, alias?: string);
140
+ for(config: Partial<any>, ...args: any): typeof this;
141
+ /**
142
+ * @description Creates a record in the state database
143
+ * @summary Serializes a model and stores it in the Fabric state database
144
+ * @param {string} tableName - The name of the table/collection
145
+ * @param {string | number} id - The record identifier
146
+ * @param {Record<string, any>} model - The record data
147
+ * @param {Record<string, any>} transient - Transient data (not used in this implementation)
148
+ * @param {...any[]} args - Additional arguments, including the chaincode stub and logger
149
+ * @return {Promise<Record<string, any>>} Promise resolving to the created record
150
+ */
151
+ create(tableName: string, id: string | number, model: Record<string, any>, ...args: any[]): Promise<Record<string, any>>;
152
+ /**
153
+ * @description Reads a record from the state database
154
+ * @summary Retrieves and deserializes a record from the Fabric state database
155
+ * @param {string} tableName - The name of the table/collection
156
+ * @param {string | number} id - The record identifier
157
+ * @param {...any[]} args - Additional arguments, including the chaincode stub and logger
158
+ * @return {Promise<Record<string, any>>} Promise resolving to the retrieved record
159
+ */
160
+ read(tableName: string, id: string | number, ...args: any[]): Promise<Record<string, any>>;
161
+ /**
162
+ * @description Updates a record in the state database
163
+ * @summary Serializes a model and updates it in the Fabric state database
164
+ * @param {string} tableName - The name of the table/collection
165
+ * @param {string | number} id - The record identifier
166
+ * @param {Record<string, any>} model - The updated record data
167
+ * @param {Record<string, any>} transient - Transient data (not used in this implementation)
168
+ * @param {...any[]} args - Additional arguments, including the chaincode stub and logger
169
+ * @return {Promise<Record<string, any>>} Promise resolving to the updated record
170
+ */
171
+ update(tableName: string, id: string | number, model: Record<string, any>, ...args: any[]): Promise<Record<string, any>>;
172
+ /**
173
+ * @description Deletes a record from the state database
174
+ * @summary Retrieves a record and then removes it from the Fabric state database
175
+ * @param {string} tableName - The name of the table/collection
176
+ * @param {string | number} id - The record identifier to delete
177
+ * @param {...any[]} args - Additional arguments, including the chaincode stub and logger
178
+ * @return {Promise<Record<string, any>>} Promise resolving to the deleted record
179
+ */
180
+ delete(tableName: string, id: string | number, ...args: any[]): Promise<Record<string, any>>;
181
+ protected deleteState(stub: ChaincodeStub, tableName: string, id: string, ...args: any[]): Promise<void>;
182
+ protected putState(stub: ChaincodeStub, id: string, model: Record<string, any>, ...args: any[]): Promise<Record<string, any>>;
183
+ protected readState(stub: ChaincodeStub, tableName: string, id: string, ...args: any[]): Promise<any[]>;
184
+ protected queryResult(stub: ChaincodeStub, rawInput: any, ...args: any[]): Promise<Iterators.StateQueryIterator>;
185
+ protected queryResultPaginated(stub: ChaincodeStub, rawInput: any, limit?: number, skip?: number, ...args: any[]): Promise<StateQueryResponse<Iterators.StateQueryIterator>>;
186
+ protected mergeModels(results: Record<string, any>[]): Record<string, any>;
187
+ /**
188
+ * @description Decodes binary data to string
189
+ * @summary Converts a Uint8Array to a string using UTF-8 encoding
190
+ * @param {Uint8Array} buffer - The binary data to decode
191
+ * @return {string} The decoded string
192
+ */
193
+ protected decode(buffer: Uint8Array): string;
194
+ /**
195
+ * @description Creates operation flags for Fabric contract operations
196
+ * @summary Merges default flags with Fabric-specific context information
197
+ * @template M - Type extending Model
198
+ * @param {OperationKeys} operation - The operation being performed
199
+ * @param {Constructor<M>} model - The model constructor
200
+ * @param {Partial<FabricContractFlags>} flags - Partial flags to merge with defaults
201
+ * @param {Ctx} ctx - The Fabric chaincode context
202
+ * @return {FabricContractFlags} The merged flags
203
+ */
204
+ protected flags<M extends Model>(operation: OperationKeys, model: Constructor<M>, flags: Partial<FabricContractFlags>, ctx: Ctx, ...args: any[]): Promise<FabricContractFlags>;
205
+ /**
206
+ * @description Creates an index for a model
207
+ * @summary This method is not implemented for Fabric contracts and returns a resolved promise
208
+ * @template M - Type extending Model
209
+ * @param {Constructor<M>} models - The model constructor
210
+ * @return {Promise<void>} Promise that resolves immediately
211
+ */
212
+ protected index<M>(models: Constructor<M>): Promise<void>;
213
+ /**
214
+ * @description Processes results from a state query iterator
215
+ * @summary Iterates through query results and converts them to a structured format
216
+ * @param {Logger} log - Logger instance for debugging
217
+ * @param {Iterators.StateQueryIterator} iterator - The state query iterator
218
+ * @param {boolean} [isHistory=false] - Whether this is a history query
219
+ * @return {Promise<any[]>} Promise resolving to an array of processed results
220
+ * @mermaid
221
+ * sequenceDiagram
222
+ * participant Caller
223
+ * participant ResultIterator
224
+ * participant Iterator
225
+ *
226
+ * Caller->>ResultIterator: resultIterator(log, iterator, isHistory)
227
+ * loop Until done
228
+ * ResultIterator->>Iterator: next()
229
+ * Iterator-->>ResultIterator: { value, done }
230
+ * alt Has value
231
+ * ResultIterator->>ResultIterator: Process value based on isHistory
232
+ * ResultIterator->>ResultIterator: Add to results array
233
+ * end
234
+ * end
235
+ * ResultIterator->>Iterator: close()
236
+ * ResultIterator-->>Caller: allResults
237
+ */
238
+ protected resultIterator(log: Logger, iterator: Iterators.StateQueryIterator, isHistory?: boolean): Promise<any[]>;
239
+ /**
240
+ * @description Executes a raw query against the state database
241
+ * @summary Performs a rich query using CouchDB syntax against the Fabric state database
242
+ * @template R - The return type
243
+ * @param {MangoQuery} rawInput - The Mango Query to execute
244
+ * @param {boolean} docsOnly - Whether to return only documents (not used in this implementation)
245
+ * @param {...any[]} args - Additional arguments, including the chaincode stub and logger
246
+ * @return {Promise<R>} Promise resolving to the query results
247
+ * @mermaid
248
+ * sequenceDiagram
249
+ * participant Caller
250
+ * participant FabricContractAdapter
251
+ * participant Stub
252
+ * participant StateDB
253
+ *
254
+ * Caller->>FabricContractAdapter: raw(rawInput, docsOnly, ctx)
255
+ * FabricContractAdapter->>FabricContractAdapter: Extract limit and skip
256
+ * alt With pagination
257
+ * FabricContractAdapter->>Stub: getQueryResultWithPagination(query, limit, skip)
258
+ * else Without pagination
259
+ * FabricContractAdapter->>Stub: getQueryResult(query)
260
+ * end
261
+ * Stub->>StateDB: Execute query
262
+ * StateDB-->>Stub: Iterator
263
+ * Stub-->>FabricContractAdapter: Iterator
264
+ * FabricContractAdapter->>FabricContractAdapter: resultIterator(log, iterator)
265
+ * FabricContractAdapter-->>Caller: results
266
+ */
267
+ raw<R>(rawInput: MangoQuery, docsOnly: boolean, ...args: any[]): Promise<R>;
268
+ Statement<M extends Model>(ctx?: FabricContractContext): FabricStatement<M, any>;
269
+ Sequence(options: SequenceOptions): Promise<Sequence>;
270
+ createAll(tableName: string, id: (string | number)[], model: Record<string, any>[], ...args: any[]): Promise<Record<string, any>[]>;
271
+ updateAll(tableName: string, id: string[] | number[], model: Record<string, any>[], ...args: any[]): Promise<Record<string, any>[]>;
272
+ /**
273
+ *
274
+ * @param model
275
+ * @param {string} pk
276
+ * @param args
277
+ */
278
+ prepare<M extends Model>(model: M, pk: keyof M, ...args: any[]): {
279
+ record: Record<string, any>;
280
+ id: string;
281
+ transient?: Record<string, any>;
282
+ };
283
+ revert<M extends Model>(obj: Record<string, any>, clazz: string | Constructor<M>, pk: keyof M, id: string | number, transient?: Record<string, any>): M;
284
+ createPrefix(tableName: string, id: string | number, model: Record<string, any>, ...args: any[]): (string | number | Record<string, any> | FabricContractContext)[];
285
+ updatePrefix(tableName: string, id: string | number, model: Record<string, any>, ...args: any[]): (string | number | Record<string, any>)[];
286
+ protected createAllPrefix(tableName: string, ids: string[] | number[], models: Record<string, any>[], ...args: any[]): (string | string[] | number[] | Record<string, any>[])[];
287
+ protected updateAllPrefix(tableName: string, ids: string[] | number[], models: Record<string, any>[], ...args: any[]): any[];
288
+ /**
289
+ * @description Static method for decoration overrides
290
+ * @summary Overrides/extends decaf decoration with Fabric-specific functionality
291
+ * @static
292
+ * @override
293
+ * @return {void}
294
+ */
295
+ static decoration(): void;
296
+ }
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FabricContractContext = void 0;
4
+ const db_decorators_1 = require("@decaf-ts/db-decorators");
5
+ /**
6
+ * @description Context class for Fabric chaincode operations
7
+ * @summary Provides access to Fabric-specific context elements like stub, identity, and logger to be used by repositories and adapters during contract execution.
8
+ * @template F - Flags specific to Fabric contract operations
9
+ * @param {object} [args] - Optional initialization arguments passed to the base Context
10
+ * @return {void}
11
+ * @class FabricContractContext
12
+ * @example
13
+ * ```typescript
14
+ * // In a Fabric chaincode contract method
15
+ * const context = new FabricContractContext();
16
+ * // Optionally set values via the base Context API
17
+ * context.set('stub', ctx.stub);
18
+ * context.set('clientIdentity', ctx.clientIdentity);
19
+ * context.set('logger', contractLogger);
20
+ *
21
+ * // Access context properties
22
+ * const timestamp = context.timestamp;
23
+ * const creator = context.identity.getID();
24
+ * ```
25
+ * @mermaid
26
+ * sequenceDiagram
27
+ * participant Contract
28
+ * participant Context
29
+ * participant Ledger
30
+ * Contract->>Context: new FabricContractContext()
31
+ * Contract->>Context: set('stub'|'clientIdentity'|'logger', ...)
32
+ * Context-->>Contract: timestamp, identity, logger
33
+ * Contract->>Ledger: Interact via stub
34
+ */
35
+ class FabricContractContext extends db_decorators_1.Context {
36
+ /**
37
+ * @description Creates a new FabricContractContext instance
38
+ * @summary Initializes the context with Fabric-specific flags
39
+ */
40
+ constructor() {
41
+ super();
42
+ }
43
+ /**
44
+ * @description Gets the chaincode stub
45
+ * @summary Returns the ChaincodeStub instance for interacting with the ledger
46
+ * @return {ChaincodeStub} The chaincode stub
47
+ */
48
+ get stub() {
49
+ return this.get("stub");
50
+ }
51
+ /**
52
+ * @description Gets the transaction timestamp
53
+ * @summary Overrides the base timestamp getter to use the stub's timestamp
54
+ * @return {Date} The transaction timestamp
55
+ */
56
+ get timestamp() {
57
+ return this.stub.getDateTimestamp();
58
+ }
59
+ /**
60
+ * @description Gets the client identity
61
+ * @summary Returns the ClientIdentity instance for the transaction submitter
62
+ * @return {ClientIdentity} The client identity
63
+ */
64
+ get identity() {
65
+ //TODO: Find what is happening it seems FabricContractContext is being created with FabricContractContext instead of the transaction context
66
+ // return this.get("clientIdentity");
67
+ try {
68
+ return this.get("clientIdentity");
69
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
70
+ }
71
+ catch (_) {
72
+ return this.get("identity");
73
+ }
74
+ }
75
+ /**
76
+ * @description Gets the logger
77
+ * @summary Returns the logger instance for the current context
78
+ * @return {any} The logger instance
79
+ */
80
+ get logger() {
81
+ return this.get("logger");
82
+ }
83
+ }
84
+ exports.FabricContractContext = FabricContractContext;
85
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQ29udHJhY3RDb250ZXh0LmpzIiwic291cmN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0NvbnRyYWN0Q29udGV4dCBpbnN0ZWFkIG9mIHRoZSB0cmFuc2FjdGlvbiBjb250ZXh0XG4gICAgLy8gcmV0dXJuIHRoaXMuZ2V0KFwiY2xpZW50SWRlbnRpdHlcIik7XG4gICAgdHJ5IHtcbiAgICAgIHJldHVybiB0aGlzLmdldChcImNsaWVudElkZW50aXR5XCIpO1xuICAgICAgLy8gZXNsaW50LWRpc2FibGUtbmV4dC1saW5lIEB0eXBlc2NyaXB0LWVzbGludC9uby11bnVzZWQtdmFyc1xuICAgIH0gY2F0Y2ggKF86IGFueSkge1xuICAgICAgcmV0dXJuIHRoaXMuZ2V0KFwiaWRlbnRpdHlcIiBhcyBhbnkpO1xuICAgIH1cbiAgfVxuXG4gIC8qKlxuICAgKiBAZGVzY3JpcHRpb24gR2V0cyB0aGUgbG9nZ2VyXG4gICAqIEBzdW1tYXJ5IFJldHVybnMgdGhlIGxvZ2dlciBpbnN0YW5jZSBmb3IgdGhlIGN1cnJlbnQgY29udGV4dFxuICAgKiBAcmV0dXJuIHthbnl9IFRoZSBsb2dnZXIgaW5zdGFuY2VcbiAgICovXG4gIGdldCBsb2dnZXIoKSB7XG4gICAgcmV0dXJuIHRoaXMuZ2V0KFwibG9nZ2VyXCIpO1xuICB9XG59XG4iXX0=
@@ -0,0 +1,64 @@
1
+ import { Context } from "@decaf-ts/db-decorators";
2
+ import { FabricContractFlags } from "./types";
3
+ import { ChaincodeStub, ClientIdentity } from "fabric-shim-api";
4
+ /**
5
+ * @description Context class for Fabric chaincode operations
6
+ * @summary Provides access to Fabric-specific context elements like stub, identity, and logger to be used by repositories and adapters during contract execution.
7
+ * @template F - Flags specific to Fabric contract operations
8
+ * @param {object} [args] - Optional initialization arguments passed to the base Context
9
+ * @return {void}
10
+ * @class FabricContractContext
11
+ * @example
12
+ * ```typescript
13
+ * // In a Fabric chaincode contract method
14
+ * const context = new FabricContractContext();
15
+ * // Optionally set values via the base Context API
16
+ * context.set('stub', ctx.stub);
17
+ * context.set('clientIdentity', ctx.clientIdentity);
18
+ * context.set('logger', contractLogger);
19
+ *
20
+ * // Access context properties
21
+ * const timestamp = context.timestamp;
22
+ * const creator = context.identity.getID();
23
+ * ```
24
+ * @mermaid
25
+ * sequenceDiagram
26
+ * participant Contract
27
+ * participant Context
28
+ * participant Ledger
29
+ * Contract->>Context: new FabricContractContext()
30
+ * Contract->>Context: set('stub'|'clientIdentity'|'logger', ...)
31
+ * Context-->>Contract: timestamp, identity, logger
32
+ * Contract->>Ledger: Interact via stub
33
+ */
34
+ export declare class FabricContractContext extends Context<FabricContractFlags> {
35
+ /**
36
+ * @description Creates a new FabricContractContext instance
37
+ * @summary Initializes the context with Fabric-specific flags
38
+ */
39
+ constructor();
40
+ /**
41
+ * @description Gets the chaincode stub
42
+ * @summary Returns the ChaincodeStub instance for interacting with the ledger
43
+ * @return {ChaincodeStub} The chaincode stub
44
+ */
45
+ get stub(): ChaincodeStub;
46
+ /**
47
+ * @description Gets the transaction timestamp
48
+ * @summary Overrides the base timestamp getter to use the stub's timestamp
49
+ * @return {Date} The transaction timestamp
50
+ */
51
+ get timestamp(): Date;
52
+ /**
53
+ * @description Gets the client identity
54
+ * @summary Returns the ClientIdentity instance for the transaction submitter
55
+ * @return {ClientIdentity} The client identity
56
+ */
57
+ get identity(): ClientIdentity;
58
+ /**
59
+ * @description Gets the logger
60
+ * @summary Returns the logger instance for the current context
61
+ * @return {any} The logger instance
62
+ */
63
+ get logger(): import("@decaf-ts/logging").Logger;
64
+ }