@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,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
|
+
}
|