@decaf-ts/for-fabric 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +22 -0
- package/README.md +647 -0
- package/dist/for-fabric.cjs +6223 -0
- package/dist/for-fabric.esm.cjs +6180 -0
- package/lib/client/FabricClientAdapter.cjs +760 -0
- package/lib/client/FabricClientAdapter.d.ts +381 -0
- package/lib/client/FabricClientDispatch.cjs +186 -0
- package/lib/client/FabricClientDispatch.d.ts +125 -0
- package/lib/client/FabricClientRepository.cjs +131 -0
- package/lib/client/FabricClientRepository.d.ts +100 -0
- package/lib/client/erc20/erc20ClientRepository.cjs +343 -0
- package/lib/client/erc20/erc20ClientRepository.d.ts +254 -0
- package/lib/client/fabric-fs.cjs +234 -0
- package/lib/client/fabric-fs.d.ts +92 -0
- package/lib/client/index.cjs +30 -0
- package/lib/client/index.d.ts +13 -0
- package/lib/client/logging.cjs +102 -0
- package/lib/client/logging.d.ts +60 -0
- package/lib/client/services/LoggedService.cjs +47 -0
- package/lib/client/services/LoggedService.d.ts +42 -0
- package/lib/client/services/constants.cjs +3 -0
- package/lib/client/services/constants.d.ts +15 -0
- package/lib/client/services/enrollementService.cjs +344 -0
- package/lib/client/services/enrollementService.d.ts +176 -0
- package/lib/client/services/index.cjs +18 -0
- package/lib/client/services/index.d.ts +1 -0
- package/lib/contracts/ContractAdapter.cjs +730 -0
- package/lib/contracts/ContractAdapter.d.ts +296 -0
- package/lib/contracts/ContractContext.cjs +85 -0
- package/lib/contracts/ContractContext.d.ts +64 -0
- package/lib/contracts/ContractPrivateDataAdapter.cjs +281 -0
- package/lib/contracts/ContractPrivateDataAdapter.d.ts +74 -0
- package/lib/contracts/FabricConstruction.cjs +441 -0
- package/lib/contracts/FabricConstruction.d.ts +304 -0
- package/lib/contracts/FabricContractRepository.cjs +306 -0
- package/lib/contracts/FabricContractRepository.d.ts +162 -0
- package/lib/contracts/FabricContractRepositoryObservableHandler.cjs +85 -0
- package/lib/contracts/FabricContractRepositoryObservableHandler.d.ts +62 -0
- package/lib/contracts/FabricContractSequence.cjs +139 -0
- package/lib/contracts/FabricContractSequence.d.ts +61 -0
- package/lib/contracts/FabricContractStatement.cjs +119 -0
- package/lib/contracts/FabricContractStatement.d.ts +34 -0
- package/lib/contracts/PrivateSequence.cjs +36 -0
- package/lib/contracts/PrivateSequence.d.ts +15 -0
- package/lib/contracts/crud/crud-contract.cjs +257 -0
- package/lib/contracts/crud/crud-contract.d.ts +168 -0
- package/lib/contracts/crud/index.cjs +19 -0
- package/lib/contracts/crud/index.d.ts +2 -0
- package/lib/contracts/crud/serialized-crud-contract.cjs +172 -0
- package/lib/contracts/crud/serialized-crud-contract.d.ts +37 -0
- package/lib/contracts/erc20/erc20contract.cjs +569 -0
- package/lib/contracts/erc20/erc20contract.d.ts +151 -0
- package/lib/contracts/erc20/index.cjs +21 -0
- package/lib/contracts/erc20/index.d.ts +2 -0
- package/lib/contracts/erc20/models.cjs +209 -0
- package/lib/contracts/erc20/models.d.ts +114 -0
- package/lib/contracts/index.cjs +32 -0
- package/lib/contracts/index.d.ts +15 -0
- package/lib/contracts/logging.cjs +96 -0
- package/lib/contracts/logging.d.ts +49 -0
- package/lib/contracts/private-data.cjs +121 -0
- package/lib/contracts/private-data.d.ts +16 -0
- package/lib/contracts/types.cjs +3 -0
- package/lib/contracts/types.d.ts +26 -0
- package/lib/esm/client/FabricClientAdapter.d.ts +381 -0
- package/lib/esm/client/FabricClientAdapter.js +723 -0
- package/lib/esm/client/FabricClientDispatch.d.ts +125 -0
- package/lib/esm/client/FabricClientDispatch.js +182 -0
- package/lib/esm/client/FabricClientRepository.d.ts +100 -0
- package/lib/esm/client/FabricClientRepository.js +127 -0
- package/lib/esm/client/erc20/erc20ClientRepository.d.ts +254 -0
- package/lib/esm/client/erc20/erc20ClientRepository.js +339 -0
- package/lib/esm/client/fabric-fs.d.ts +92 -0
- package/lib/esm/client/fabric-fs.js +191 -0
- package/lib/esm/client/index.d.ts +13 -0
- package/lib/esm/client/index.js +14 -0
- package/lib/esm/client/logging.d.ts +60 -0
- package/lib/esm/client/logging.js +98 -0
- package/lib/esm/client/services/LoggedService.d.ts +42 -0
- package/lib/esm/client/services/LoggedService.js +43 -0
- package/lib/esm/client/services/constants.d.ts +15 -0
- package/lib/esm/client/services/constants.js +2 -0
- package/lib/esm/client/services/enrollementService.d.ts +176 -0
- package/lib/esm/client/services/enrollementService.js +337 -0
- package/lib/esm/client/services/index.d.ts +1 -0
- package/lib/esm/client/services/index.js +2 -0
- package/lib/esm/contracts/ContractAdapter.d.ts +296 -0
- package/lib/esm/contracts/ContractAdapter.js +724 -0
- package/lib/esm/contracts/ContractContext.d.ts +64 -0
- package/lib/esm/contracts/ContractContext.js +81 -0
- package/lib/esm/contracts/ContractPrivateDataAdapter.d.ts +74 -0
- package/lib/esm/contracts/ContractPrivateDataAdapter.js +277 -0
- package/lib/esm/contracts/FabricConstruction.d.ts +304 -0
- package/lib/esm/contracts/FabricConstruction.js +433 -0
- package/lib/esm/contracts/FabricContractRepository.d.ts +162 -0
- package/lib/esm/contracts/FabricContractRepository.js +302 -0
- package/lib/esm/contracts/FabricContractRepositoryObservableHandler.d.ts +62 -0
- package/lib/esm/contracts/FabricContractRepositoryObservableHandler.js +81 -0
- package/lib/esm/contracts/FabricContractSequence.d.ts +61 -0
- package/lib/esm/contracts/FabricContractSequence.js +135 -0
- package/lib/esm/contracts/FabricContractStatement.d.ts +34 -0
- package/lib/esm/contracts/FabricContractStatement.js +115 -0
- package/lib/esm/contracts/PrivateSequence.d.ts +15 -0
- package/lib/esm/contracts/PrivateSequence.js +33 -0
- package/lib/esm/contracts/crud/crud-contract.d.ts +168 -0
- package/lib/esm/contracts/crud/crud-contract.js +253 -0
- package/lib/esm/contracts/crud/index.d.ts +2 -0
- package/lib/esm/contracts/crud/index.js +3 -0
- package/lib/esm/contracts/crud/serialized-crud-contract.d.ts +37 -0
- package/lib/esm/contracts/crud/serialized-crud-contract.js +168 -0
- package/lib/esm/contracts/erc20/erc20contract.d.ts +151 -0
- package/lib/esm/contracts/erc20/erc20contract.js +565 -0
- package/lib/esm/contracts/erc20/index.d.ts +2 -0
- package/lib/esm/contracts/erc20/index.js +4 -0
- package/lib/esm/contracts/erc20/models.d.ts +114 -0
- package/lib/esm/contracts/erc20/models.js +206 -0
- package/lib/esm/contracts/index.d.ts +15 -0
- package/lib/esm/contracts/index.js +16 -0
- package/lib/esm/contracts/logging.d.ts +49 -0
- package/lib/esm/contracts/logging.js +92 -0
- package/lib/esm/contracts/private-data.d.ts +16 -0
- package/lib/esm/contracts/private-data.js +113 -0
- package/lib/esm/contracts/types.d.ts +26 -0
- package/lib/esm/contracts/types.js +2 -0
- package/lib/esm/index.d.ts +8 -0
- package/lib/esm/index.js +9 -0
- package/lib/esm/shared/ClientSerializer.d.ts +52 -0
- package/lib/esm/shared/ClientSerializer.js +80 -0
- package/lib/esm/shared/DeterministicSerializer.d.ts +40 -0
- package/lib/esm/shared/DeterministicSerializer.js +50 -0
- package/lib/esm/shared/SimpleDeterministicSerializer.d.ts +7 -0
- package/lib/esm/shared/SimpleDeterministicSerializer.js +42 -0
- package/lib/esm/shared/constants.d.ts +39 -0
- package/lib/esm/shared/constants.js +42 -0
- package/lib/esm/shared/crypto.d.ts +107 -0
- package/lib/esm/shared/crypto.js +331 -0
- package/lib/esm/shared/decorators.d.ts +24 -0
- package/lib/esm/shared/decorators.js +98 -0
- package/lib/esm/shared/erc20/erc20-constants.d.ts +25 -0
- package/lib/esm/shared/erc20/erc20-constants.js +27 -0
- package/lib/esm/shared/errors.d.ts +116 -0
- package/lib/esm/shared/errors.js +132 -0
- package/lib/esm/shared/events.d.ts +39 -0
- package/lib/esm/shared/events.js +47 -0
- package/lib/esm/shared/fabric-types.d.ts +33 -0
- package/lib/esm/shared/fabric-types.js +2 -0
- package/lib/esm/shared/index.d.ts +13 -0
- package/lib/esm/shared/index.js +14 -0
- package/lib/esm/shared/interfaces/Checkable.d.ts +21 -0
- package/lib/esm/shared/interfaces/Checkable.js +2 -0
- package/lib/esm/shared/math.d.ts +34 -0
- package/lib/esm/shared/math.js +61 -0
- package/lib/esm/shared/model/Identity.d.ts +42 -0
- package/lib/esm/shared/model/Identity.js +78 -0
- package/lib/esm/shared/model/IdentityCredentials.d.ts +41 -0
- package/lib/esm/shared/model/IdentityCredentials.js +74 -0
- package/lib/esm/shared/model/index.d.ts +1 -0
- package/lib/esm/shared/model/index.js +2 -0
- package/lib/esm/shared/model/utils.d.ts +60 -0
- package/lib/esm/shared/model/utils.js +108 -0
- package/lib/esm/shared/types.d.ts +79 -0
- package/lib/esm/shared/types.js +2 -0
- package/lib/esm/shared/utils.d.ts +55 -0
- package/lib/esm/shared/utils.js +148 -0
- package/lib/index.cjs +25 -0
- package/lib/index.d.ts +8 -0
- package/lib/shared/ClientSerializer.cjs +84 -0
- package/lib/shared/ClientSerializer.d.ts +52 -0
- package/lib/shared/DeterministicSerializer.cjs +54 -0
- package/lib/shared/DeterministicSerializer.d.ts +40 -0
- package/lib/shared/SimpleDeterministicSerializer.cjs +46 -0
- package/lib/shared/SimpleDeterministicSerializer.d.ts +7 -0
- package/lib/shared/constants.cjs +45 -0
- package/lib/shared/constants.d.ts +39 -0
- package/lib/shared/crypto.cjs +369 -0
- package/lib/shared/crypto.d.ts +107 -0
- package/lib/shared/decorators.cjs +105 -0
- package/lib/shared/decorators.d.ts +24 -0
- package/lib/shared/erc20/erc20-constants.cjs +30 -0
- package/lib/shared/erc20/erc20-constants.d.ts +25 -0
- package/lib/shared/errors.cjs +142 -0
- package/lib/shared/errors.d.ts +116 -0
- package/lib/shared/events.cjs +51 -0
- package/lib/shared/events.d.ts +39 -0
- package/lib/shared/fabric-types.cjs +4 -0
- package/lib/shared/fabric-types.d.ts +33 -0
- package/lib/shared/index.cjs +30 -0
- package/lib/shared/index.d.ts +13 -0
- package/lib/shared/interfaces/Checkable.cjs +3 -0
- package/lib/shared/interfaces/Checkable.d.ts +21 -0
- package/lib/shared/math.cjs +66 -0
- package/lib/shared/math.d.ts +34 -0
- package/lib/shared/model/Identity.cjs +81 -0
- package/lib/shared/model/Identity.d.ts +42 -0
- package/lib/shared/model/IdentityCredentials.cjs +77 -0
- package/lib/shared/model/IdentityCredentials.d.ts +41 -0
- package/lib/shared/model/index.cjs +18 -0
- package/lib/shared/model/index.d.ts +1 -0
- package/lib/shared/model/utils.cjs +114 -0
- package/lib/shared/model/utils.d.ts +60 -0
- package/lib/shared/types.cjs +3 -0
- package/lib/shared/types.d.ts +79 -0
- package/lib/shared/utils.cjs +185 -0
- package/lib/shared/utils.d.ts +55 -0
- package/package.json +166 -0
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
import { CouchDBAdapter, type MangoQuery } from "@decaf-ts/for-couchdb";
|
|
2
|
+
import { Client } from "@grpc/grpc-js";
|
|
3
|
+
import { type Constructor, Model, type Serializer } from "@decaf-ts/decorator-validation";
|
|
4
|
+
import { Logger } from "@decaf-ts/logging";
|
|
5
|
+
import { FabricFlags, PeerConfig } from "../shared/types";
|
|
6
|
+
import { Gateway, Network, Contract as Contrakt } from "@hyperledger/fabric-gateway";
|
|
7
|
+
import { BaseError, Context } from "@decaf-ts/db-decorators";
|
|
8
|
+
import { Adapter, Dispatch, Repository } from "@decaf-ts/core";
|
|
9
|
+
/**
|
|
10
|
+
* @description Adapter for interacting with Hyperledger Fabric networks
|
|
11
|
+
* @summary The FabricAdapter extends CouchDBAdapter to provide a seamless interface for interacting with Hyperledger Fabric networks.
|
|
12
|
+
* It handles connection management, transaction submission, and CRUD operations against Fabric chaincode.
|
|
13
|
+
* @template PeerConfig - Configuration type for connecting to a Fabric peer
|
|
14
|
+
* @template FabricFlags - Flags specific to Fabric operations
|
|
15
|
+
* @template Context<FabricFlags> - Context type containing Fabric-specific flags
|
|
16
|
+
* @param config - Configuration for connecting to a Fabric peer
|
|
17
|
+
* @param alias - Optional alias for the adapter instance
|
|
18
|
+
* @class FabricClientAdapter
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* // Create a new FabricAdapter instance
|
|
22
|
+
* const config: PeerConfig = {
|
|
23
|
+
* mspId: 'Org1MSP',
|
|
24
|
+
* peerEndpoint: 'localhost:7051',
|
|
25
|
+
* channelName: 'mychannel',
|
|
26
|
+
* chaincodeName: 'mycc',
|
|
27
|
+
* contractName: 'mycontract',
|
|
28
|
+
* tlsCertPath: '/path/to/tls/cert',
|
|
29
|
+
* certDirectoryPath: '/path/to/cert/dir',
|
|
30
|
+
* keyDirectoryPath: '/path/to/key/dir'
|
|
31
|
+
* };
|
|
32
|
+
*
|
|
33
|
+
* const adapter = new FabricAdapter(config, 'org1-adapter');
|
|
34
|
+
*
|
|
35
|
+
* // Use the adapter to interact with the Fabric network
|
|
36
|
+
* const result = await adapter.read('users', 'user1', mySerializer);
|
|
37
|
+
* ```
|
|
38
|
+
* @mermaid
|
|
39
|
+
* sequenceDiagram
|
|
40
|
+
* participant Client
|
|
41
|
+
* participant FabricAdapter
|
|
42
|
+
* participant Gateway
|
|
43
|
+
* participant Network
|
|
44
|
+
* participant Contract
|
|
45
|
+
* participant Chaincode
|
|
46
|
+
*
|
|
47
|
+
* Client->>FabricAdapter: create(tableName, id, model, transient, serializer)
|
|
48
|
+
* FabricAdapter->>FabricAdapter: submitTransaction(OperationKeys.CREATE, [serializedModel], transient)
|
|
49
|
+
* FabricAdapter->>Gateway: connect()
|
|
50
|
+
* Gateway->>Network: getNetwork(channelName)
|
|
51
|
+
* Network->>Contract: getContract(chaincodeName, contractName)
|
|
52
|
+
* FabricAdapter->>Contract: submit(api, proposalOptions)
|
|
53
|
+
* Contract->>Chaincode: invoke
|
|
54
|
+
* Chaincode-->>Contract: response
|
|
55
|
+
* Contract-->>FabricAdapter: result
|
|
56
|
+
* FabricAdapter->>FabricAdapter: decode(result)
|
|
57
|
+
* FabricAdapter->>FabricAdapter: serializer.deserialize(decodedResult)
|
|
58
|
+
* FabricAdapter-->>Client: deserializedResult
|
|
59
|
+
*/
|
|
60
|
+
export declare class FabricClientAdapter extends CouchDBAdapter<PeerConfig, Client, FabricFlags, Context<FabricFlags>> {
|
|
61
|
+
/**
|
|
62
|
+
* @description Static text decoder for converting Uint8Array to string
|
|
63
|
+
*/
|
|
64
|
+
private static decoder;
|
|
65
|
+
private static serializer;
|
|
66
|
+
/**
|
|
67
|
+
* @description Static logger instance for the FabricAdapter class
|
|
68
|
+
*/
|
|
69
|
+
private static log;
|
|
70
|
+
/**
|
|
71
|
+
* @description Gets the logger instance for this adapter
|
|
72
|
+
* @summary Returns the static logger instance for the FabricAdapter class
|
|
73
|
+
* @return {Logger} The logger instance
|
|
74
|
+
*/
|
|
75
|
+
protected get log(): Logger;
|
|
76
|
+
protected readonly serializer: Serializer<any>;
|
|
77
|
+
/**
|
|
78
|
+
* @description Creates a new FabricAdapter instance
|
|
79
|
+
* @summary Initializes a new adapter for interacting with a Hyperledger Fabric network
|
|
80
|
+
* @param {PeerConfig} config - Configuration for connecting to a Fabric peer
|
|
81
|
+
* @param {string} [alias] - Optional alias for the adapter instance
|
|
82
|
+
*/
|
|
83
|
+
constructor(config: PeerConfig, alias?: string);
|
|
84
|
+
/**
|
|
85
|
+
* @description Decodes a Uint8Array to a string
|
|
86
|
+
* @summary Converts binary data received from Fabric to a string using UTF-8 encoding
|
|
87
|
+
* @param {Uint8Array} data - The binary data to decode
|
|
88
|
+
* @return {string} The decoded string
|
|
89
|
+
*/
|
|
90
|
+
decode(data: Uint8Array): string;
|
|
91
|
+
repository<M extends Model<true | false>>(): Constructor<Repository<M, MangoQuery, Adapter<PeerConfig, Client, MangoQuery, FabricFlags, Context<FabricFlags>>, FabricFlags, Context<FabricFlags>>>;
|
|
92
|
+
/**
|
|
93
|
+
* @description Creates multiple records in a single transaction
|
|
94
|
+
* @summary Submits a transaction to create multiple records in the Fabric ledger
|
|
95
|
+
* @param {string} tableName - The name of the table/collection
|
|
96
|
+
* @param {string[] | number[]} ids - Array of record identifiers
|
|
97
|
+
* @param {Array<Record<string, any>>} models - Array of record data
|
|
98
|
+
* @param {Record<string, any>} transient - Transient data for the transaction
|
|
99
|
+
* @return {Promise<Array<Record<string, any>>>} Promise resolving to the created records
|
|
100
|
+
*/
|
|
101
|
+
createAll(tableName: string, ids: string[] | number[], models: Record<string, any>[], transient: Record<string, any>): Promise<Record<string, any>[]>;
|
|
102
|
+
/**
|
|
103
|
+
* @description Reads multiple records in a single transaction
|
|
104
|
+
* @summary Submits a transaction to read multiple records from the Fabric ledger
|
|
105
|
+
* @param {string} tableName - The name of the table/collection
|
|
106
|
+
* @param {string[] | number[]} ids - Array of record identifiers to read
|
|
107
|
+
* @return {Promise<Array<Record<string, any>>>} Promise resolving to the retrieved records
|
|
108
|
+
*/
|
|
109
|
+
readAll(tableName: string, ids: string[] | number[]): Promise<Record<string, any>[]>;
|
|
110
|
+
/**
|
|
111
|
+
* @description Updates multiple records in a single transaction
|
|
112
|
+
* @summary Submits a transaction to update multiple records in the Fabric ledger
|
|
113
|
+
* @param {string} tableName - The name of the table/collection
|
|
114
|
+
* @param {string[] | number[]} ids - Array of record identifiers
|
|
115
|
+
* @param {Array<Record<string, any>>} models - Array of updated record data
|
|
116
|
+
* @param {Record<string, any>} transient - Transient data for the transaction
|
|
117
|
+
* @return {Promise<Array<Record<string, any>>>} Promise resolving to the updated records
|
|
118
|
+
*/
|
|
119
|
+
updateAll(tableName: string, ids: string[] | number[], models: Record<string, any>[], transient: Record<string, any>): Promise<Record<string, any>[]>;
|
|
120
|
+
/**
|
|
121
|
+
* @description Deletes multiple records in a single transaction
|
|
122
|
+
* @summary Submits a transaction to delete multiple records from the Fabric ledger
|
|
123
|
+
* @param {string} tableName - The name of the table/collection
|
|
124
|
+
* @param {Array<string | number | bigint>} ids - Array of record identifiers to delete
|
|
125
|
+
* @param {Serializer<any>} serializer - Serializer for the model data
|
|
126
|
+
* @return {Promise<Array<Record<string, any>>>} Promise resolving to the deleted records
|
|
127
|
+
*/
|
|
128
|
+
deleteAll(tableName: string, ids: (string | number | bigint)[]): Promise<Record<string, any>[]>;
|
|
129
|
+
/**
|
|
130
|
+
* @description Prepares a model for persistence
|
|
131
|
+
* @summary Converts a model instance into a format suitable for database storage,
|
|
132
|
+
* handling column mapping and separating transient properties
|
|
133
|
+
* @template M - The model type
|
|
134
|
+
* @param {M} model - The model instance to prepare
|
|
135
|
+
* @param pk - The primary key property name
|
|
136
|
+
* @return The prepared data
|
|
137
|
+
*/
|
|
138
|
+
prepare<M extends Model>(model: M, pk: keyof M): {
|
|
139
|
+
record: Record<string, any>;
|
|
140
|
+
id: string;
|
|
141
|
+
transient?: Record<string, any>;
|
|
142
|
+
};
|
|
143
|
+
/**
|
|
144
|
+
* @description Converts database data back into a model instance
|
|
145
|
+
* @summary Reconstructs a model instance from database data, handling column mapping
|
|
146
|
+
* and reattaching transient properties
|
|
147
|
+
* @template M - The model type
|
|
148
|
+
* @param obj - The database record
|
|
149
|
+
* @param {string|Constructor<M>} clazz - The model class or name
|
|
150
|
+
* @param pk - The primary key property name
|
|
151
|
+
* @param {string|number|bigint} id - The primary key value
|
|
152
|
+
* @param [transient] - Transient properties to reattach
|
|
153
|
+
* @return {M} The reconstructed model instance
|
|
154
|
+
*/
|
|
155
|
+
revert<M extends Model>(obj: Record<string, any>, clazz: string | Constructor<M>, pk: keyof M, id: string | number | bigint, transient?: Record<string, any>): M;
|
|
156
|
+
/**
|
|
157
|
+
* @description Creates an index for a model
|
|
158
|
+
* @summary This method is not implemented for Fabric and will throw an error
|
|
159
|
+
* @template M - Type extending Model
|
|
160
|
+
* @param {Constructor<M>} models - The model constructor
|
|
161
|
+
* @return {Promise<void>} Promise that will throw an error
|
|
162
|
+
*/
|
|
163
|
+
protected index<M>(models: Constructor<M>): Promise<void>;
|
|
164
|
+
/**
|
|
165
|
+
* @description Creates a single record
|
|
166
|
+
* @summary Submits a transaction to create a record in the Fabric ledger
|
|
167
|
+
* @param {string} tableName - The name of the table/collection
|
|
168
|
+
* @param {string | number} id - The record identifier
|
|
169
|
+
* @param {Record<string, any>} model - The record data
|
|
170
|
+
* @param {Record<string, any>} transient - Transient data for the transaction
|
|
171
|
+
* @return {Promise<Record<string, any>>} Promise resolving to the created record
|
|
172
|
+
*/
|
|
173
|
+
create(tableName: string, id: string | number, model: Record<string, any>, transient: Record<string, any>): Promise<Record<string, any>>;
|
|
174
|
+
/**
|
|
175
|
+
* @description Reads a single record
|
|
176
|
+
* @summary Evaluates a transaction to read a record from the Fabric ledger
|
|
177
|
+
* @param {string} tableName - The name of the table/collection
|
|
178
|
+
* @param {string | number} id - The record identifier
|
|
179
|
+
* @return {Promise<Record<string, any>>} Promise resolving to the retrieved record
|
|
180
|
+
*/
|
|
181
|
+
read(tableName: string, id: string | number): Promise<Record<string, any>>;
|
|
182
|
+
/**
|
|
183
|
+
* @description Updates a single record
|
|
184
|
+
* @summary Submits a transaction to update a record in the Fabric ledger
|
|
185
|
+
* @param {string} tableName - The name of the table/collection
|
|
186
|
+
* @param {string | number} id - The record identifier
|
|
187
|
+
* @param {Record<string, any>} model - The updated record data
|
|
188
|
+
* @param {Record<string, any>} transient - Transient data for the transaction
|
|
189
|
+
* @return {Promise<Record<string, any>>} Promise resolving to the updated record
|
|
190
|
+
*/
|
|
191
|
+
update(tableName: string, id: string | number, model: Record<string, any>, transient: Record<string, any>): Promise<Record<string, any>>;
|
|
192
|
+
/**
|
|
193
|
+
* @description Deletes a single record
|
|
194
|
+
* @summary Submits a transaction to delete a record from the Fabric ledger
|
|
195
|
+
* @param {string} tableName - The name of the table/collection
|
|
196
|
+
* @param {string | number} id - The record identifier to delete
|
|
197
|
+
* @return {Promise<Record<string, any>>} Promise resolving to the deleted record
|
|
198
|
+
*/
|
|
199
|
+
delete(tableName: string, id: string | number): Promise<Record<string, any>>;
|
|
200
|
+
/**
|
|
201
|
+
* @description Executes a raw query against the Fabric ledger
|
|
202
|
+
* @summary Evaluates a transaction to perform a query using Mango Query syntax
|
|
203
|
+
* @template V - The return type
|
|
204
|
+
* @param {MangoQuery} rawInput - The Mango Query to execute
|
|
205
|
+
* @param {boolean} process - Whether to process the result
|
|
206
|
+
* @return {Promise<V>} Promise resolving to the query result
|
|
207
|
+
* @mermaid
|
|
208
|
+
* sequenceDiagram
|
|
209
|
+
* participant Client
|
|
210
|
+
* participant FabricAdapter
|
|
211
|
+
* participant Contract
|
|
212
|
+
* participant Chaincode
|
|
213
|
+
*
|
|
214
|
+
* Client->>FabricAdapter: raw(rawInput, process)
|
|
215
|
+
* FabricAdapter->>FabricAdapter: JSON.stringify(rawInput)
|
|
216
|
+
* FabricAdapter->>FabricAdapter: evaluateTransaction("query", [input])
|
|
217
|
+
* FabricAdapter->>Contract: evaluate("query", proposalOptions)
|
|
218
|
+
* Contract->>Chaincode: invoke
|
|
219
|
+
* Chaincode-->>Contract: response
|
|
220
|
+
* Contract-->>FabricAdapter: result
|
|
221
|
+
* FabricAdapter->>FabricAdapter: JSON.parse(decode(result))
|
|
222
|
+
* FabricAdapter->>FabricAdapter: Process result based on type
|
|
223
|
+
* FabricAdapter-->>Client: processed result
|
|
224
|
+
*/
|
|
225
|
+
raw<V>(rawInput: MangoQuery, process: boolean): Promise<V>;
|
|
226
|
+
/**
|
|
227
|
+
* @description Gets or creates a gRPC client for the Fabric peer
|
|
228
|
+
* @summary Returns a cached client or creates a new one if none exists
|
|
229
|
+
* @return {Promise<Client>} Promise resolving to the gRPC client
|
|
230
|
+
*/
|
|
231
|
+
getClient(): Client;
|
|
232
|
+
/**
|
|
233
|
+
* @description Gets a Gateway instance for the Fabric network
|
|
234
|
+
* @summary Creates a new Gateway instance using the current client
|
|
235
|
+
* @return {Promise<Gateway>} Promise resolving to the Gateway instance
|
|
236
|
+
*/
|
|
237
|
+
protected Gateway(): Promise<Gateway>;
|
|
238
|
+
/**
|
|
239
|
+
* @description Gets a Contract instance for the Fabric chaincode
|
|
240
|
+
* @summary Creates a new Contract instance using the current Gateway
|
|
241
|
+
* @return {Promise<Contrakt>} Promise resolving to the Contract instance
|
|
242
|
+
*/
|
|
243
|
+
protected Contract(): Promise<Contrakt>;
|
|
244
|
+
/**
|
|
245
|
+
* @description Executes a transaction on the Fabric network
|
|
246
|
+
* @summary Submits or evaluates a transaction on the Fabric chaincode
|
|
247
|
+
* @param {string} api - The chaincode function to call
|
|
248
|
+
* @param {boolean} submit - Whether to submit (true) or evaluate (false) the transaction
|
|
249
|
+
* @param {any[]} [args] - Arguments to pass to the chaincode function
|
|
250
|
+
* @param {Record<string, string>} [transientData] - Transient data for the transaction
|
|
251
|
+
* @param {Array<string>} [endorsingOrganizations] - Organizations that must endorse the transaction
|
|
252
|
+
* @return {Promise<Uint8Array>} Promise resolving to the transaction result
|
|
253
|
+
* @mermaid
|
|
254
|
+
* sequenceDiagram
|
|
255
|
+
* participant FabricAdapter
|
|
256
|
+
* participant Gateway
|
|
257
|
+
* participant Contract
|
|
258
|
+
* participant Chaincode
|
|
259
|
+
*
|
|
260
|
+
* FabricAdapter->>Gateway: connect()
|
|
261
|
+
* FabricAdapter->>Contract: getContract()
|
|
262
|
+
* alt submit transaction
|
|
263
|
+
* FabricAdapter->>Contract: submit(api, proposalOptions)
|
|
264
|
+
* else evaluate transaction
|
|
265
|
+
* FabricAdapter->>Contract: evaluate(api, proposalOptions)
|
|
266
|
+
* end
|
|
267
|
+
* Contract->>Chaincode: invoke
|
|
268
|
+
* Chaincode-->>Contract: response
|
|
269
|
+
* Contract-->>FabricAdapter: result
|
|
270
|
+
* FabricAdapter->>Gateway: close()
|
|
271
|
+
*/
|
|
272
|
+
protected transaction(api: string, submit?: boolean, args?: any[], transientData?: Record<string, string>, endorsingOrganizations?: Array<string>): Promise<Uint8Array>;
|
|
273
|
+
/**
|
|
274
|
+
* @description Parses an error into a BaseError
|
|
275
|
+
* @summary Converts any error into a standardized BaseError
|
|
276
|
+
* @param {Error | string} err - The error to parse
|
|
277
|
+
* @param {string} [reason] - Optional reason for the error
|
|
278
|
+
* @return {BaseError} The parsed error
|
|
279
|
+
*/
|
|
280
|
+
parseError(err: Error | string, reason?: string): BaseError;
|
|
281
|
+
/**
|
|
282
|
+
* @description Submits a transaction to the Fabric network
|
|
283
|
+
* @summary Executes a transaction that modifies the ledger state
|
|
284
|
+
* @param {string} api - The chaincode function to call
|
|
285
|
+
* @param {any[]} [args] - Arguments to pass to the chaincode function
|
|
286
|
+
* @param {Record<string, string>} [transientData] - Transient data for the transaction
|
|
287
|
+
* @param {Array<string>} [endorsingOrganizations] - Organizations that must endorse the transaction
|
|
288
|
+
* @return {Promise<Uint8Array>} Promise resolving to the transaction result
|
|
289
|
+
*/
|
|
290
|
+
submitTransaction(api: string, args?: any[], transientData?: Record<string, string>, endorsingOrganizations?: Array<string>): Promise<Uint8Array>;
|
|
291
|
+
/**
|
|
292
|
+
* @description Evaluates a transaction on the Fabric network
|
|
293
|
+
* @summary Executes a transaction that does not modify the ledger state
|
|
294
|
+
* @param {string} api - The chaincode function to call
|
|
295
|
+
* @param {any[]} [args] - Arguments to pass to the chaincode function
|
|
296
|
+
* @param {Record<string, string>} [transientData] - Transient data for the transaction
|
|
297
|
+
* @param {Array<string>} [endorsingOrganizations] - Organizations that must endorse the transaction
|
|
298
|
+
* @return {Promise<Uint8Array>} Promise resolving to the transaction result
|
|
299
|
+
*/
|
|
300
|
+
evaluateTransaction(api: string, args?: any[], transientData?: Record<string, string>, endorsingOrganizations?: Array<string>): Promise<Uint8Array>;
|
|
301
|
+
/**
|
|
302
|
+
* @description Closes the connection to the Fabric network
|
|
303
|
+
* @summary Closes the gRPC client if it exists
|
|
304
|
+
* @return {Promise<void>} Promise that resolves when the client is closed
|
|
305
|
+
*/
|
|
306
|
+
close(): Promise<void>;
|
|
307
|
+
/**
|
|
308
|
+
* @description Gets a Contract instance from a Gateway
|
|
309
|
+
* @summary Retrieves a chaincode contract from the specified network
|
|
310
|
+
* @param {Gateway} gateway - The Gateway instance
|
|
311
|
+
* @param {PeerConfig} config - The peer configuration
|
|
312
|
+
* @return {Contrakt} The Contract instance
|
|
313
|
+
*/
|
|
314
|
+
static getContract(gateway: Gateway, config: PeerConfig): Contrakt;
|
|
315
|
+
/**
|
|
316
|
+
* @description Gets a Network instance from a Gateway
|
|
317
|
+
* @summary Connects to a specific channel on the Fabric network
|
|
318
|
+
* @param {Gateway} gateway - The Gateway instance
|
|
319
|
+
* @param {string} channelName - The name of the channel to connect to
|
|
320
|
+
* @return {Network} The Network instance
|
|
321
|
+
*/
|
|
322
|
+
static getNetwork(gateway: Gateway, channelName: string): Network;
|
|
323
|
+
/**
|
|
324
|
+
* @description Gets a Gateway instance for connecting to the Fabric network
|
|
325
|
+
* @summary Creates a Gateway using the provided configuration and client
|
|
326
|
+
* @param {PeerConfig} config - The peer configuration
|
|
327
|
+
* @param {Client} [client] - Optional gRPC client, will be created if not provided
|
|
328
|
+
* @return {Promise<Gateway>} Promise resolving to the Gateway instance
|
|
329
|
+
*/
|
|
330
|
+
static getGateway(config: PeerConfig, client?: Client): Promise<Gateway>;
|
|
331
|
+
/**
|
|
332
|
+
* @description Creates a gRPC client for connecting to a Fabric peer
|
|
333
|
+
* @summary Initializes a client with TLS credentials for secure communication
|
|
334
|
+
* @param {PeerConfig} config - The peer configuration
|
|
335
|
+
* @return {Client} Promise resolving to the gRPC client
|
|
336
|
+
*/
|
|
337
|
+
static getClient(config: PeerConfig): Client;
|
|
338
|
+
/**
|
|
339
|
+
* @description Establishes a connection to the Fabric network
|
|
340
|
+
* @summary Creates a Gateway connection with identity and signer
|
|
341
|
+
* @param {Client} client - The gRPC client
|
|
342
|
+
* @param {PeerConfig} config - The peer configuration
|
|
343
|
+
* @return {Promise<Gateway>} Promise resolving to the connected Gateway
|
|
344
|
+
* @mermaid
|
|
345
|
+
* sequenceDiagram
|
|
346
|
+
* participant Caller
|
|
347
|
+
* participant FabricAdapter
|
|
348
|
+
* participant Identity
|
|
349
|
+
* participant Signer
|
|
350
|
+
* participant Gateway
|
|
351
|
+
*
|
|
352
|
+
* Caller->>FabricAdapter: getConnection(client, config)
|
|
353
|
+
* FabricAdapter->>Identity: getIdentity(mspId, certDirectoryPath)
|
|
354
|
+
* Identity-->>FabricAdapter: identity
|
|
355
|
+
* FabricAdapter->>Signer: getSigner(keyDirectoryPath)
|
|
356
|
+
* Signer-->>FabricAdapter: signer
|
|
357
|
+
* FabricAdapter->>FabricAdapter: Create ConnectOptions
|
|
358
|
+
* FabricAdapter->>Gateway: connect(options)
|
|
359
|
+
* Gateway-->>FabricAdapter: gateway
|
|
360
|
+
* FabricAdapter-->>Caller: gateway
|
|
361
|
+
*/
|
|
362
|
+
static getConnection(client: Client, config: PeerConfig): Promise<Gateway>;
|
|
363
|
+
/**
|
|
364
|
+
* @description Creates a new Dispatch instance for the Fabric client.
|
|
365
|
+
* @summary This function is responsible for creating a new FabricClientDispatch instance that can be used to interact with the Fabric network.
|
|
366
|
+
* @returns {Dispatch} A new Dispatch instance configured for the Fabric client.
|
|
367
|
+
* @remarks The Dispatch instance is used to encapsulate the logic for interacting with the Fabric network, such as submitting transactions or querying data.
|
|
368
|
+
* @example
|
|
369
|
+
* const fabricDispatch = fabricClientAdapter.Dispatch();
|
|
370
|
+
* fabricDispatch.submitTransaction('createProduct', { name: 'Product A', price: 100 });
|
|
371
|
+
*/
|
|
372
|
+
Dispatch(): Dispatch;
|
|
373
|
+
/**
|
|
374
|
+
* @description Parses an error into a BaseError
|
|
375
|
+
* @summary Converts any error into a standardized BaseError using the parent class implementation
|
|
376
|
+
* @param {Error | string} err - The error to parse
|
|
377
|
+
* @param {string} [reason] - Optional reason for the error
|
|
378
|
+
* @return {BaseError} The parsed error
|
|
379
|
+
*/
|
|
380
|
+
protected static parseError(err: Error | string, reason?: string): BaseError;
|
|
381
|
+
}
|