# new FabricContractAdapter()
Provides a CouchDB-like interface for interacting with the Fabric state database from within a chaincode contract
Adapter for Hyperledger Fabric chaincode state database operations
Example
```typescript
// In a Fabric chaincode contract class
import { FabricContractAdapter } from '@decaf-ts/for-fabric';
export class MyContract extends Contract {
private adapter = new FabricContractAdapter();
Classes
- FabricContractAdapter
Initializes an adapter for interacting with the Fabric state database
- FabricContractAdapter
Initializes an adapter for interacting with the Fabric state database
Members
Methods
# protected Context() → {Constructor.<FabricContractContext>}
Overrides the base Context constructor with FabricContractContext
Context constructor for this adapter
Constructor.<FabricContractContext>
# async create(tableName, id, model, transient, …args) → {Promise.<Record.<string, any>>}
Serializes a model and stores it in the Fabric state database
Creates a record in the state database
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
tableName |
string
|
The name of the table/collection |
|
id |
string
|
number
|
The record identifier |
|
model |
Record.<string, any>
|
The record data |
|
transient |
Record.<string, any>
|
Transient data (not used in this implementation) |
|
args |
Array.<any>
|
<repeatable> |
Additional arguments, including the chaincode stub and logger |
Promise resolving to the created record
Promise.<Record.<string, any>>
# protected decode(buffer) → {string}
Converts a Uint8Array to a string using UTF-8 encoding
Decodes binary data to string
Parameters:
| Name | Type | Description |
|---|---|---|
buffer |
Uint8Array
|
The binary data to decode |
The decoded string
string
# async delete(tableName, id, …args) → {Promise.<Record.<string, any>>}
Retrieves a record and then removes it from the Fabric state database
Deletes a record from the state database
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
tableName |
string
|
The name of the table/collection |
|
id |
string
|
number
|
The record identifier to delete |
|
args |
Array.<any>
|
<repeatable> |
Additional arguments, including the chaincode stub and logger |
Promise resolving to the deleted record
Promise.<Record.<string, any>>
# async protected flags(operation, model, flags, ctx) → {FabricContractFlags}
Merges default flags with Fabric-specific context information
Creates operation flags for Fabric contract operations
Parameters:
| Name | Type | Description |
|---|---|---|
operation |
OperationKeys
|
The operation being performed |
model |
Constructor.<M>
|
The model constructor |
flags |
Partial.<FabricContractFlags>
|
Partial flags to merge with defaults |
ctx |
Ctx
|
The Fabric chaincode context |
The merged flags
# protected index(models) → {Promise.<void>}
This method is not implemented for Fabric contracts and returns a resolved promise
Creates an index for a model
Parameters:
| Name | Type | Description |
|---|---|---|
models |
Constructor.<M>
|
The model constructor |
Promise that resolves immediately
Promise.<void>
# prepare(model, pk, args) → {PreparedModel|object}
Parameters:
| Name | Type | Description |
|---|---|---|
model |
||
pk |
string
|
|
args |
PreparedModel
|
object
# async rangeList(clazz, attributesopt, …args) → {Promise.<Array.<M>>}
Iterates records via getStateByPartialCompositeKey (public) and
getPrivateDataByPartialCompositeKey (private/shared), following the same collection-routing
logic as raw() but using Fabric range queries instead of Mango selectors.
Unlike raw(), this method is safe to use in the same transaction as writes because
range queries are deterministic and do not block subsequent putState/putPrivateData calls.
Lists all records of a model using range queries (deterministic, write-safe)
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
clazz |
Constructor.<M>
|
The model constructor |
||
attributes |
Array.<string>
|
<optional> |
[] | Partial composite key attributes to filter by (empty = all records) |
args |
ContextualArgs.<FabricContractContext>
|
<repeatable> |
Contextual arguments including the chaincode context |
Promise resolving to an array of reconstructed model instances
Promise.<Array.<M>>
# async raw(rawInput, docsOnly, …args) → {Promise.<R>}
Performs a rich query using CouchDB syntax against the Fabric state database
Executes a raw query against the state database
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
rawInput |
MangoQuery
|
The Mango Query to execute |
|
docsOnly |
boolean
|
Whether to return only documents (not used in this implementation) |
|
args |
Array.<any>
|
<repeatable> |
Additional arguments, including the chaincode stub and logger |
Promise resolving to the query results
Promise.<R>
# async read(tableName, id, …args) → {Promise.<Record.<string, any>>}
Retrieves and deserializes a record from the Fabric state database
Reads a record from the state database
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
tableName |
string
|
The name of the table/collection |
|
id |
string
|
number
|
The record identifier |
|
args |
Array.<any>
|
<repeatable> |
Additional arguments, including the chaincode stub and logger |
Promise resolving to the retrieved record
Promise.<Record.<string, any>>
# async readAll(tableName, id, …args)
Fetches multiple records with the given IDs from the specified table
Retrieves multiple records from the database
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
tableName |
string
|
The name of the table to read from |
|
id |
The identifiers of the records to retrieve |
||
args |
Array.<any>
|
<repeatable> |
Additional arguments specific to the adapter implementation |
A promise that resolves to an array of retrieved records
# repository() → {Constructor.<Repository.<M, MangoQuery, FabricContractAdapter, FabricContractFlags, FabricContractContext>>}
Returns the FabricContractRepository constructor for creating repositories
Gets the repository constructor for this adapter
The repository constructor
Constructor.<Repository.<M, MangoQuery, FabricContractAdapter, FabricContractFlags, FabricContractContext>>
# async protected resultIterator(log, iterator, isHistoryopt) → {Promise.<Array.<any>>}
Iterates through query results and converts them to a structured format
Processes results from a state query iterator
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
log |
Logger
|
Logger instance for debugging |
||
iterator |
Iterators.StateQueryIterator
|
The state query iterator |
||
isHistory |
boolean
|
<optional> |
false | Whether this is a history query |
Promise resolving to an array of processed results
Promise.<Array.<any>>
# async update(tableName, id, model, transient, …args) → {Promise.<Record.<string, any>>}
Serializes a model and updates it in the Fabric state database
Updates a record in the state database
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
tableName |
string
|
The name of the table/collection |
|
id |
string
|
number
|
The record identifier |
|
model |
Record.<string, any>
|
The updated record data |
|
transient |
Record.<string, any>
|
Transient data (not used in this implementation) |
|
args |
Array.<any>
|
<repeatable> |
Additional arguments, including the chaincode stub and logger |
Promise resolving to the updated record
Promise.<Record.<string, any>>
# static decoration() → {void}
Overrides/extends decaf decoration with Fabric-specific functionality
Static method for decoration overrides
void