@decaf-ts/for-fabric 0.1.1 → 0.1.3
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/dist/for-fabric.cjs +1 -1
- package/dist/for-fabric.cjs.map +1 -1
- package/dist/for-fabric.js +1 -1
- package/dist/for-fabric.js.map +1 -1
- package/lib/client/FabricClientAdapter.cjs +94 -81
- package/lib/client/FabricClientAdapter.d.ts +24 -33
- package/lib/client/FabricClientAdapter.js.map +1 -1
- package/lib/client/FabricClientDispatch.cjs +14 -5
- package/lib/client/FabricClientDispatch.d.ts +7 -5
- package/lib/client/FabricClientDispatch.js.map +1 -1
- package/lib/client/FabricClientRepository.cjs +4 -137
- package/lib/client/FabricClientRepository.d.ts +6 -78
- package/lib/client/FabricClientRepository.js.map +1 -1
- package/lib/client/erc20/FabricERC20ClientRepository.cjs +17 -17
- package/lib/client/erc20/FabricERC20ClientRepository.d.ts +5 -5
- package/lib/client/erc20/FabricERC20ClientRepository.js.map +1 -1
- package/lib/client/logging.cjs +1 -1
- package/lib/client/logging.js.map +1 -1
- package/lib/client/services/FabricEnrollmentService.cjs +3 -3
- package/lib/client/services/FabricEnrollmentService.d.ts +2 -2
- package/lib/client/services/FabricEnrollmentService.js.map +1 -1
- package/lib/contract/Product.cjs +2 -2
- package/lib/contract/Product.d.ts +1 -1
- package/lib/contracts/ContractAdapter.cjs +204 -115
- package/lib/contracts/ContractAdapter.d.ts +26 -34
- package/lib/contracts/ContractAdapter.js.map +1 -1
- package/lib/contracts/ContractContext.cjs +1 -9
- package/lib/contracts/ContractContext.d.ts +0 -6
- package/lib/contracts/ContractContext.js.map +1 -1
- package/lib/contracts/ContractPrivateDataAdapter.cjs +429 -288
- package/lib/contracts/ContractPrivateDataAdapter.d.ts +0 -76
- package/lib/contracts/ContractPrivateDataAdapter.js.map +1 -1
- package/lib/contracts/FabricConstruction.cjs +3 -3
- package/lib/contracts/FabricConstruction.d.ts +9 -8
- package/lib/contracts/FabricConstruction.js.map +1 -1
- package/lib/contracts/FabricContractRepository.cjs +7 -202
- package/lib/contracts/FabricContractRepository.d.ts +5 -68
- package/lib/contracts/FabricContractRepository.js.map +1 -1
- package/lib/contracts/FabricContractRepositoryObservableHandler.cjs +4 -1
- package/lib/contracts/FabricContractRepositoryObservableHandler.d.ts +4 -4
- package/lib/contracts/FabricContractRepositoryObservableHandler.js.map +1 -1
- package/lib/contracts/FabricContractSequence.cjs +39 -60
- package/lib/contracts/FabricContractSequence.d.ts +29 -41
- package/lib/contracts/FabricContractSequence.js.map +1 -1
- package/lib/contracts/FabricContractStatement.cjs +6 -6
- package/lib/contracts/FabricContractStatement.d.ts +4 -6
- package/lib/contracts/FabricContractStatement.js.map +1 -1
- package/lib/contracts/crud/crud-contract.cjs +74 -44
- package/lib/contracts/crud/crud-contract.d.ts +7 -11
- package/lib/contracts/crud/crud-contract.js.map +1 -1
- package/lib/contracts/crud/serialized-crud-contract.cjs +12 -21
- package/lib/contracts/crud/serialized-crud-contract.d.ts +3 -11
- package/lib/contracts/crud/serialized-crud-contract.js.map +1 -1
- package/lib/contracts/erc20/erc20contract.cjs +73 -67
- package/lib/contracts/erc20/erc20contract.d.ts +13 -12
- package/lib/contracts/erc20/erc20contract.js.map +1 -1
- package/lib/contracts/logging.cjs +9 -13
- package/lib/contracts/logging.d.ts +1 -2
- package/lib/contracts/logging.js.map +1 -1
- package/lib/contracts/private-data.cjs +202 -118
- package/lib/contracts/private-data.d.ts +0 -16
- package/lib/contracts/private-data.js.map +1 -1
- package/lib/contracts/types.d.ts +1 -1
- package/lib/esm/client/FabricClientAdapter.d.ts +24 -33
- package/lib/esm/client/FabricClientAdapter.js +90 -78
- package/lib/esm/client/FabricClientAdapter.js.map +1 -1
- package/lib/esm/client/FabricClientDispatch.d.ts +7 -5
- package/lib/esm/client/FabricClientDispatch.js +17 -8
- package/lib/esm/client/FabricClientDispatch.js.map +1 -1
- package/lib/esm/client/FabricClientRepository.d.ts +6 -78
- package/lib/esm/client/FabricClientRepository.js +4 -137
- package/lib/esm/client/FabricClientRepository.js.map +1 -1
- package/lib/esm/client/erc20/FabricERC20ClientRepository.d.ts +5 -5
- package/lib/esm/client/erc20/FabricERC20ClientRepository.js +17 -17
- package/lib/esm/client/erc20/FabricERC20ClientRepository.js.map +1 -1
- package/lib/esm/client/logging.js +1 -1
- package/lib/esm/client/logging.js.map +1 -1
- package/lib/esm/client/services/FabricEnrollmentService.d.ts +2 -2
- package/lib/esm/client/services/FabricEnrollmentService.js +3 -3
- package/lib/esm/client/services/FabricEnrollmentService.js.map +1 -1
- package/lib/esm/contract/Product.d.ts +1 -1
- package/lib/esm/contract/Product.js +2 -2
- package/lib/esm/contracts/ContractAdapter.d.ts +26 -34
- package/lib/esm/contracts/ContractAdapter.js +205 -116
- package/lib/esm/contracts/ContractAdapter.js.map +1 -1
- package/lib/esm/contracts/ContractContext.d.ts +0 -6
- package/lib/esm/contracts/ContractContext.js +1 -9
- package/lib/esm/contracts/ContractContext.js.map +1 -1
- package/lib/esm/contracts/ContractPrivateDataAdapter.d.ts +0 -76
- package/lib/esm/contracts/ContractPrivateDataAdapter.js +430 -285
- package/lib/esm/contracts/ContractPrivateDataAdapter.js.map +1 -1
- package/lib/esm/contracts/FabricConstruction.d.ts +9 -8
- package/lib/esm/contracts/FabricConstruction.js +3 -3
- package/lib/esm/contracts/FabricConstruction.js.map +1 -1
- package/lib/esm/contracts/FabricContractRepository.d.ts +5 -68
- package/lib/esm/contracts/FabricContractRepository.js +7 -202
- package/lib/esm/contracts/FabricContractRepository.js.map +1 -1
- package/lib/esm/contracts/FabricContractRepositoryObservableHandler.d.ts +4 -4
- package/lib/esm/contracts/FabricContractRepositoryObservableHandler.js +5 -2
- package/lib/esm/contracts/FabricContractRepositoryObservableHandler.js.map +1 -1
- package/lib/esm/contracts/FabricContractSequence.d.ts +29 -41
- package/lib/esm/contracts/FabricContractSequence.js +40 -61
- package/lib/esm/contracts/FabricContractSequence.js.map +1 -1
- package/lib/esm/contracts/FabricContractStatement.d.ts +4 -6
- package/lib/esm/contracts/FabricContractStatement.js +7 -7
- package/lib/esm/contracts/FabricContractStatement.js.map +1 -1
- package/lib/esm/contracts/crud/crud-contract.d.ts +7 -11
- package/lib/esm/contracts/crud/crud-contract.js +75 -45
- package/lib/esm/contracts/crud/crud-contract.js.map +1 -1
- package/lib/esm/contracts/crud/serialized-crud-contract.d.ts +3 -11
- package/lib/esm/contracts/crud/serialized-crud-contract.js +12 -21
- package/lib/esm/contracts/crud/serialized-crud-contract.js.map +1 -1
- package/lib/esm/contracts/erc20/erc20contract.d.ts +13 -12
- package/lib/esm/contracts/erc20/erc20contract.js +73 -67
- package/lib/esm/contracts/erc20/erc20contract.js.map +1 -1
- package/lib/esm/contracts/logging.d.ts +1 -2
- package/lib/esm/contracts/logging.js +9 -13
- package/lib/esm/contracts/logging.js.map +1 -1
- package/lib/esm/contracts/private-data.d.ts +0 -16
- package/lib/esm/contracts/private-data.js +203 -111
- package/lib/esm/contracts/private-data.js.map +1 -1
- package/lib/esm/contracts/types.d.ts +1 -1
- package/lib/esm/shared/decorators.d.ts +14 -4
- package/lib/esm/shared/decorators.js +142 -42
- package/lib/esm/shared/decorators.js.map +1 -1
- package/lib/esm/shared/errors.js +2 -2
- package/lib/esm/shared/errors.js.map +1 -1
- package/lib/esm/shared/events.d.ts +1 -5
- package/lib/esm/shared/events.js.map +1 -1
- package/lib/esm/shared/model/Sequence.d.ts +14 -0
- package/lib/esm/shared/model/Sequence.js +33 -0
- package/lib/esm/shared/model/Sequence.js.map +1 -0
- package/lib/esm/shared/model/index.d.ts +2 -0
- package/lib/esm/shared/model/index.js +2 -0
- package/lib/esm/shared/model/index.js.map +1 -1
- package/lib/esm/version.d.ts +1 -1
- package/lib/esm/version.js +1 -1
- package/lib/shared/decorators.cjs +148 -41
- package/lib/shared/decorators.d.ts +14 -4
- package/lib/shared/decorators.js.map +1 -1
- package/lib/shared/errors.cjs +2 -2
- package/lib/shared/errors.js.map +1 -1
- package/lib/shared/events.d.ts +1 -5
- package/lib/shared/events.js.map +1 -1
- package/lib/shared/model/Sequence.cjs +36 -0
- package/lib/shared/model/Sequence.d.ts +14 -0
- package/lib/shared/model/Sequence.js.map +1 -0
- package/lib/shared/model/index.cjs +2 -0
- package/lib/shared/model/index.d.ts +2 -0
- package/lib/shared/model/index.js.map +1 -1
- package/lib/version.cjs +1 -1
- package/lib/version.d.ts +1 -1
- package/package.json +2 -3
- package/lib/client/services/LoggedService.cjs +0 -47
- package/lib/client/services/LoggedService.d.ts +0 -42
- package/lib/client/services/LoggedService.js.map +0 -1
- package/lib/esm/client/services/LoggedService.d.ts +0 -42
- package/lib/esm/client/services/LoggedService.js +0 -43
- package/lib/esm/client/services/LoggedService.js.map +0 -1
|
@@ -1,47 +1,27 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Adapter,
|
|
1
|
+
import { SequenceOptions } from "@decaf-ts/core";
|
|
2
|
+
import type { Adapter, MaybeContextualArg } from "@decaf-ts/core";
|
|
3
|
+
import type { MangoQuery } from "@decaf-ts/for-couchdb";
|
|
3
4
|
import { Sequence } from "@decaf-ts/core";
|
|
4
|
-
import {
|
|
5
|
-
import { FabricContractContext } from "./ContractContext";
|
|
5
|
+
import { SequenceModel } from "../shared/model/Sequence";
|
|
6
6
|
import { FabricContractRepository } from "./FabricContractRepository";
|
|
7
|
-
import {
|
|
7
|
+
import { FabricContractContext } from "./ContractContext";
|
|
8
8
|
/**
|
|
9
|
-
* @
|
|
10
|
-
* @
|
|
11
|
-
*
|
|
12
|
-
* @
|
|
13
|
-
*
|
|
14
|
-
* @
|
|
15
|
-
*
|
|
16
|
-
* const next = await seq.next(ctx); // 1
|
|
17
|
-
* const [a,b,c] = await seq.range(3, ctx); // [2,3,4]
|
|
18
|
-
* @mermaid
|
|
19
|
-
* sequenceDiagram
|
|
20
|
-
* participant App
|
|
21
|
-
* participant Sequence
|
|
22
|
-
* participant Repo
|
|
23
|
-
* App->>Sequence: next(ctx)
|
|
24
|
-
* Sequence->>Repo: read(name, ctx)
|
|
25
|
-
* Repo-->>Sequence: current
|
|
26
|
-
* Sequence->>Repo: update(current+inc)
|
|
27
|
-
* Repo-->>Sequence: saved
|
|
28
|
-
* Sequence-->>App: next value
|
|
9
|
+
* @summary Abstract implementation of a Sequence
|
|
10
|
+
* @description provides the basic functionality for {@link Sequence}s
|
|
11
|
+
*
|
|
12
|
+
* @param {SequenceOptions} options
|
|
13
|
+
*
|
|
14
|
+
* @class CouchDBSequence
|
|
15
|
+
* @implements Sequence
|
|
29
16
|
*/
|
|
30
17
|
export declare class FabricContractSequence extends Sequence {
|
|
31
|
-
protected repo: FabricContractRepository<
|
|
32
|
-
constructor(options: SequenceOptions, adapter: Adapter<any, any, MangoQuery,
|
|
18
|
+
protected repo: FabricContractRepository<SequenceModel>;
|
|
19
|
+
constructor(options: SequenceOptions, adapter: Adapter<any, any, MangoQuery, FabricContractContext>);
|
|
33
20
|
/**
|
|
34
21
|
* @summary Retrieves the current value for the sequence
|
|
35
22
|
* @protected
|
|
36
23
|
*/
|
|
37
|
-
current(
|
|
38
|
-
/**
|
|
39
|
-
* @summary Parses the {@link Sequence} value
|
|
40
|
-
*
|
|
41
|
-
* @protected
|
|
42
|
-
* @param value
|
|
43
|
-
*/
|
|
44
|
-
private parse;
|
|
24
|
+
current(...args: MaybeContextualArg<any>): Promise<string | number | bigint>;
|
|
45
25
|
/**
|
|
46
26
|
* @summary increments the sequence
|
|
47
27
|
* @description Sequence specific implementation
|
|
@@ -52,11 +32,19 @@ export declare class FabricContractSequence extends Sequence {
|
|
|
52
32
|
*/
|
|
53
33
|
private increment;
|
|
54
34
|
/**
|
|
55
|
-
* @
|
|
56
|
-
* @
|
|
57
|
-
*
|
|
58
|
-
*
|
|
35
|
+
* @description Gets the next value in the sequence
|
|
36
|
+
* @summary Retrieves the current value of the sequence and increments it by the
|
|
37
|
+
* configured increment amount. This is the main method used to get a new sequential value.
|
|
38
|
+
* @return A promise that resolves to the next value in the sequence
|
|
39
|
+
*/
|
|
40
|
+
next(...argz: MaybeContextualArg<any>): Promise<number | string | bigint>;
|
|
41
|
+
/**
|
|
42
|
+
* @description Generates a range of sequential values
|
|
43
|
+
* @summary Retrieves a specified number of sequential values from the sequence.
|
|
44
|
+
* This is useful when you need to allocate multiple IDs at once.
|
|
45
|
+
* The method increments the sequence by the total amount needed and returns all values in the range.
|
|
46
|
+
* @param {number} count - The number of sequential values to generate
|
|
47
|
+
* @return A promise that resolves to an array of sequential values
|
|
59
48
|
*/
|
|
60
|
-
|
|
61
|
-
range(count: number, ctx?: FabricContractContext): Promise<(number | string | bigint)[]>;
|
|
49
|
+
range(count: number, ...argz: MaybeContextualArg<any>): Promise<(number | string | bigint)[]>;
|
|
62
50
|
}
|
|
@@ -1,46 +1,28 @@
|
|
|
1
|
-
import { InternalError, NotFoundError, } from "@decaf-ts/db-decorators";
|
|
1
|
+
import { Context, InternalError, NotFoundError, OperationKeys, } from "@decaf-ts/db-decorators";
|
|
2
2
|
import { Repository } from "@decaf-ts/core";
|
|
3
3
|
import { Sequence } from "@decaf-ts/core";
|
|
4
|
-
import {
|
|
5
|
-
import { CustomizableSequence } from "./PrivateSequence.js";
|
|
6
|
-
import { privateData } from "./../shared/decorators.js";
|
|
4
|
+
import { SequenceModel } from "./../shared/model/Sequence.js";
|
|
7
5
|
/**
|
|
8
|
-
* @
|
|
9
|
-
* @
|
|
10
|
-
*
|
|
11
|
-
* @
|
|
12
|
-
*
|
|
13
|
-
* @
|
|
14
|
-
*
|
|
15
|
-
* const next = await seq.next(ctx); // 1
|
|
16
|
-
* const [a,b,c] = await seq.range(3, ctx); // [2,3,4]
|
|
17
|
-
* @mermaid
|
|
18
|
-
* sequenceDiagram
|
|
19
|
-
* participant App
|
|
20
|
-
* participant Sequence
|
|
21
|
-
* participant Repo
|
|
22
|
-
* App->>Sequence: next(ctx)
|
|
23
|
-
* Sequence->>Repo: read(name, ctx)
|
|
24
|
-
* Repo-->>Sequence: current
|
|
25
|
-
* Sequence->>Repo: update(current+inc)
|
|
26
|
-
* Repo-->>Sequence: saved
|
|
27
|
-
* Sequence-->>App: next value
|
|
6
|
+
* @summary Abstract implementation of a Sequence
|
|
7
|
+
* @description provides the basic functionality for {@link Sequence}s
|
|
8
|
+
*
|
|
9
|
+
* @param {SequenceOptions} options
|
|
10
|
+
*
|
|
11
|
+
* @class CouchDBSequence
|
|
12
|
+
* @implements Sequence
|
|
28
13
|
*/
|
|
29
14
|
export class FabricContractSequence extends Sequence {
|
|
30
|
-
constructor(options, adapter
|
|
31
|
-
super(options);
|
|
32
|
-
|
|
33
|
-
privateData(collection)(CustomizableSequence);
|
|
34
|
-
}
|
|
35
|
-
this.repo = Repository.forModel(CustomizableSequence, adapter.alias);
|
|
15
|
+
constructor(options, adapter) {
|
|
16
|
+
super(options, adapter);
|
|
17
|
+
this.repo = Repository.forModel(SequenceModel, adapter.alias);
|
|
36
18
|
}
|
|
37
19
|
/**
|
|
38
20
|
* @summary Retrieves the current value for the sequence
|
|
39
21
|
* @protected
|
|
40
22
|
*/
|
|
41
|
-
async current(
|
|
42
|
-
|
|
43
|
-
|
|
23
|
+
async current(...args) {
|
|
24
|
+
const contextArgs = await Context.args(OperationKeys.READ, SequenceModel, args, this.adapter);
|
|
25
|
+
const ctx = contextArgs.context;
|
|
44
26
|
const { name, startWith } = this.options;
|
|
45
27
|
try {
|
|
46
28
|
const sequence = await this.repo.read(name, ctx);
|
|
@@ -60,15 +42,6 @@ export class FabricContractSequence extends Sequence {
|
|
|
60
42
|
throw new InternalError(`Failed to retrieve current value for sequence ${name}: ${e}`);
|
|
61
43
|
}
|
|
62
44
|
}
|
|
63
|
-
/**
|
|
64
|
-
* @summary Parses the {@link Sequence} value
|
|
65
|
-
*
|
|
66
|
-
* @protected
|
|
67
|
-
* @param value
|
|
68
|
-
*/
|
|
69
|
-
parse(value) {
|
|
70
|
-
return Sequence.parseValue(this.options.type, value);
|
|
71
|
-
}
|
|
72
45
|
/**
|
|
73
46
|
* @summary increments the sequence
|
|
74
47
|
* @description Sequence specific implementation
|
|
@@ -78,8 +51,6 @@ export class FabricContractSequence extends Sequence {
|
|
|
78
51
|
* @protected
|
|
79
52
|
*/
|
|
80
53
|
async increment(current, count, ctx) {
|
|
81
|
-
if (!ctx)
|
|
82
|
-
throw new MissingContextError("Context is required");
|
|
83
54
|
const { type, incrementBy, name } = this.options;
|
|
84
55
|
let next;
|
|
85
56
|
const toIncrementBy = count || incrementBy;
|
|
@@ -97,38 +68,46 @@ export class FabricContractSequence extends Sequence {
|
|
|
97
68
|
}
|
|
98
69
|
let seq;
|
|
99
70
|
try {
|
|
100
|
-
seq = await this.repo.update(new
|
|
71
|
+
seq = await this.repo.update(new SequenceModel({ id: name, current: next }), ctx);
|
|
101
72
|
}
|
|
102
73
|
catch (e) {
|
|
103
74
|
if (!(e instanceof NotFoundError))
|
|
104
75
|
throw e;
|
|
105
|
-
seq = await this.repo.create(new
|
|
76
|
+
seq = await this.repo.create(new SequenceModel({ id: name, current: next }), ctx);
|
|
106
77
|
}
|
|
107
78
|
return seq.current;
|
|
108
79
|
}
|
|
109
80
|
/**
|
|
110
|
-
* @
|
|
111
|
-
* @
|
|
112
|
-
*
|
|
113
|
-
*
|
|
81
|
+
* @description Gets the next value in the sequence
|
|
82
|
+
* @summary Retrieves the current value of the sequence and increments it by the
|
|
83
|
+
* configured increment amount. This is the main method used to get a new sequential value.
|
|
84
|
+
* @return A promise that resolves to the next value in the sequence
|
|
114
85
|
*/
|
|
115
|
-
async next(
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
const current = await this.current(
|
|
119
|
-
return this.increment(current, undefined,
|
|
86
|
+
async next(...argz) {
|
|
87
|
+
const contextArgs = await Context.args(OperationKeys.UPDATE, SequenceModel, argz, this.adapter);
|
|
88
|
+
const { context, args } = contextArgs;
|
|
89
|
+
const current = await this.current(...args);
|
|
90
|
+
return this.increment(current, undefined, context);
|
|
120
91
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
92
|
+
/**
|
|
93
|
+
* @description Generates a range of sequential values
|
|
94
|
+
* @summary Retrieves a specified number of sequential values from the sequence.
|
|
95
|
+
* This is useful when you need to allocate multiple IDs at once.
|
|
96
|
+
* The method increments the sequence by the total amount needed and returns all values in the range.
|
|
97
|
+
* @param {number} count - The number of sequential values to generate
|
|
98
|
+
* @return A promise that resolves to an array of sequential values
|
|
99
|
+
*/
|
|
100
|
+
async range(count, ...argz) {
|
|
101
|
+
const contextArgs = await Context.args(OperationKeys.UPDATE, SequenceModel, argz, this.adapter);
|
|
102
|
+
const { context, args } = contextArgs;
|
|
103
|
+
const current = (await this.current(...args));
|
|
125
104
|
const incrementBy = this.parse(this.options.incrementBy);
|
|
126
|
-
const next = await this.increment(current, this.parse(count) * incrementBy,
|
|
105
|
+
const next = await this.increment(current, this.parse(count) * incrementBy, context);
|
|
127
106
|
const range = [];
|
|
128
107
|
for (let i = 1; i <= count; i++) {
|
|
129
108
|
range.push(current + incrementBy * this.parse(i));
|
|
130
109
|
}
|
|
131
|
-
if (range[range.length - 1] !== next)
|
|
110
|
+
if (range[range.length - 1] !== next && this.options.type !== "String")
|
|
132
111
|
throw new InternalError("Miscalculation of range");
|
|
133
112
|
return range;
|
|
134
113
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FabricContractSequence.js","sourceRoot":"","sources":["../../../src/contracts/FabricContractSequence.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"FabricContractSequence.js","sourceRoot":"","sources":["../../../src/contracts/FabricContractSequence.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,aAAa,EACb,aAAa,EACb,aAAa,GACd,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,UAAU,EAAmB,MAAM,gBAAgB,CAAC;AAG7D,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,sCAAiC;AAGz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AI,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,IAAI,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,KAAK,QAAQ;YACpE,MAAM,IAAI,aAAa,CAAC,yBAAyB,CAAC,CAAC;QACrD,OAAO,KAAK,CAAC;IACf,CAAC;CACF"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Model } from "@decaf-ts/decorator-validation";
|
|
2
|
-
import { MangoQuery } from "@decaf-ts/for-couchdb";
|
|
3
|
-
import { FabricContractAdapter } from "./ContractAdapter";
|
|
2
|
+
import { CouchDBAdapter, MangoQuery } from "@decaf-ts/for-couchdb";
|
|
4
3
|
import { FabricContractContext } from "./ContractContext";
|
|
5
4
|
import { CouchDBStatement } from "@decaf-ts/for-couchdb";
|
|
6
5
|
/**
|
|
@@ -27,9 +26,8 @@ import { CouchDBStatement } from "@decaf-ts/for-couchdb";
|
|
|
27
26
|
* Adapter-->>Statement: rows
|
|
28
27
|
* Statement-->>App: models
|
|
29
28
|
*/
|
|
30
|
-
export declare class FabricStatement<M extends Model, R> extends CouchDBStatement<M, R> {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
raw<R>(rawInput: MangoQuery): Promise<R>;
|
|
29
|
+
export declare class FabricStatement<M extends Model, R> extends CouchDBStatement<M, CouchDBAdapter<any, void, FabricContractContext>, R> {
|
|
30
|
+
constructor(adapter: CouchDBAdapter<any, void, FabricContractContext>);
|
|
31
|
+
raw<R>(rawInput: MangoQuery, ...args: any[]): Promise<R>;
|
|
34
32
|
build(): MangoQuery;
|
|
35
33
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Model } from "@decaf-ts/decorator-validation";
|
|
2
2
|
import { CouchDBGroupOperator, CouchDBKeys, CouchDBOperator, } from "@decaf-ts/for-couchdb";
|
|
3
3
|
import { CouchDBStatement } from "@decaf-ts/for-couchdb";
|
|
4
|
-
import { Condition
|
|
4
|
+
import { Condition } from "@decaf-ts/core";
|
|
5
5
|
import { Metadata } from "@decaf-ts/decoration";
|
|
6
6
|
import { DBKeys } from "@decaf-ts/db-decorators";
|
|
7
7
|
/**
|
|
@@ -29,22 +29,22 @@ import { DBKeys } from "@decaf-ts/db-decorators";
|
|
|
29
29
|
* Statement-->>App: models
|
|
30
30
|
*/
|
|
31
31
|
export class FabricStatement extends CouchDBStatement {
|
|
32
|
-
constructor(adapter
|
|
32
|
+
constructor(adapter) {
|
|
33
33
|
super(adapter);
|
|
34
|
-
this.ctx = ctx;
|
|
35
34
|
}
|
|
36
|
-
async raw(rawInput) {
|
|
37
|
-
const
|
|
35
|
+
async raw(rawInput, ...args) {
|
|
36
|
+
const { ctx } = this.logCtx(args, this.raw);
|
|
37
|
+
const results = await this.adapter.raw(rawInput, true, ctx);
|
|
38
38
|
const pkAttr = Model.pk(this.fromSelector);
|
|
39
39
|
const type = Metadata.get(this.fromSelector, Metadata.key(DBKeys.ID, pkAttr))?.type;
|
|
40
40
|
if (!this.selectSelector)
|
|
41
|
-
return results.map((r) => this.processRecord(r, pkAttr, type));
|
|
41
|
+
return results.map((r) => this.processRecord(r, pkAttr, type, ctx));
|
|
42
42
|
return results;
|
|
43
43
|
}
|
|
44
44
|
build() {
|
|
45
45
|
const selectors = {};
|
|
46
46
|
selectors[CouchDBKeys.TABLE] = {};
|
|
47
|
-
selectors[CouchDBKeys.TABLE] =
|
|
47
|
+
selectors[CouchDBKeys.TABLE] = Model.tableName(this.fromSelector);
|
|
48
48
|
const query = { selector: selectors };
|
|
49
49
|
if (this.selectSelector)
|
|
50
50
|
query.fields = this.selectSelector;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FabricContractStatement.js","sourceRoot":"","sources":["../../../src/contracts/FabricContractStatement.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,gCAAgC,CAAC;AACvD,OAAO,EAEL,oBAAoB,EACpB,WAAW,EACX,eAAe,GAIhB,MAAM,uBAAuB,CAAC;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-api";
|
|
3
3
|
import { Model } from "@decaf-ts/decorator-validation";
|
|
4
|
+
import { ContextualizedArgs } from "@decaf-ts/core";
|
|
4
5
|
import { FabricContractRepository } from "../FabricContractRepository";
|
|
5
6
|
import { DeterministicSerializer } from "../../shared/DeterministicSerializer";
|
|
6
7
|
import { MangoQuery } from "@decaf-ts/for-couchdb";
|
|
7
8
|
import { Checkable, healthcheck } from "../../shared/interfaces/Checkable";
|
|
8
|
-
import { ContractLogger } from "../logging";
|
|
9
9
|
import { Constructor } from "@decaf-ts/decoration";
|
|
10
|
+
import { FabricContractContext } from "../ContractContext";
|
|
10
11
|
/**
|
|
11
12
|
* @description Base contract class for CRUD operations in Fabric chaincode
|
|
12
13
|
* @summary Provides standard create, read, update, and delete operations for models in Fabric chaincode
|
|
@@ -71,14 +72,6 @@ export declare abstract class FabricCrudContract<M extends Model> extends Contra
|
|
|
71
72
|
* @param {Constructor<M>} clazz - The model constructor
|
|
72
73
|
*/
|
|
73
74
|
protected constructor(name: string, clazz: Constructor<M>);
|
|
74
|
-
protected getAdapter(clazz: Constructor<M>): FabricContractAdapter;
|
|
75
|
-
/**
|
|
76
|
-
* @description Creates a logger for a specific chaincode context
|
|
77
|
-
* @summary Returns a ContractLogger instance configured for the current context
|
|
78
|
-
* @param {Ctx} ctx - The Fabric chaincode context
|
|
79
|
-
* @return {ContractLogger} The logger instance
|
|
80
|
-
*/
|
|
81
|
-
logFor(ctx: Context): ContractLogger;
|
|
82
75
|
/**
|
|
83
76
|
* @description Creates a single model in the state database
|
|
84
77
|
* @summary Delegates to the repository's create method
|
|
@@ -152,7 +145,7 @@ export declare abstract class FabricCrudContract<M extends Model> extends Contra
|
|
|
152
145
|
* @param {...any[]} args - Additional arguments
|
|
153
146
|
* @return {Promise<any>} Promise resolving to the query results
|
|
154
147
|
*/
|
|
155
|
-
raw(ctx: Ctx, rawInput: MangoQuery | string, docsOnly: boolean, ...args: any[]): Promise<any | string>;
|
|
148
|
+
raw(ctx: Ctx | FabricContractContext, rawInput: MangoQuery | string, docsOnly: boolean, ...args: any[]): Promise<any | string>;
|
|
156
149
|
protected serialize(model: M): string;
|
|
157
150
|
protected deserialize<M extends Model>(str: string): M;
|
|
158
151
|
protected init(ctx: Ctx): Promise<void>;
|
|
@@ -166,4 +159,7 @@ export declare abstract class FabricCrudContract<M extends Model> extends Contra
|
|
|
166
159
|
* @return {Promise<M[]>} Promise resolving to the created models
|
|
167
160
|
*/
|
|
168
161
|
createAll(ctx: Ctx, models: string | M[], ...args: any[]): Promise<string | M[]>;
|
|
162
|
+
logCtx<ARGS extends any[]>(args: ARGS, method: ((...args: any[]) => any) | string): Promise<ContextualizedArgs<FabricContractContext, ARGS>>;
|
|
163
|
+
protected static logCtx<ARGS extends any[]>(this: any, args: ARGS, method: string): Promise<ContextualizedArgs<FabricContractContext, ARGS>>;
|
|
164
|
+
protected static logCtx<ARGS extends any[]>(this: any, args: ARGS, method: (...args: any[]) => any): Promise<ContextualizedArgs<FabricContractContext, ARGS>>;
|
|
169
165
|
}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { FabricContractAdapter } from "./../ContractAdapter.js";
|
|
2
|
-
import { Contract } from "fabric-contract-api";
|
|
2
|
+
import { Context, Contract } from "fabric-contract-api";
|
|
3
|
+
import { Model } from "@decaf-ts/decorator-validation";
|
|
3
4
|
import { Repository } from "@decaf-ts/core";
|
|
4
5
|
import { DeterministicSerializer } from "./../../shared/DeterministicSerializer.js";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { FabricContractPrivateDataAdapter } from "./../ContractPrivateDataAdapter.js";
|
|
8
|
-
import { FabricFlavour } from "./../../shared/constants.js";
|
|
6
|
+
import { FabricContractContext } from "./../ContractContext.js";
|
|
7
|
+
import { BulkCrudOperationKeys, InternalError, OperationKeys, } from "@decaf-ts/db-decorators";
|
|
9
8
|
/**
|
|
10
9
|
* @description Base contract class for CRUD operations in Fabric chaincode
|
|
11
10
|
* @summary Provides standard create, read, update, and delete operations for models in Fabric chaincode
|
|
@@ -55,6 +54,10 @@ import { FabricFlavour } from "./../../shared/constants.js";
|
|
|
55
54
|
* Contract-->>Client: model
|
|
56
55
|
*/
|
|
57
56
|
export class FabricCrudContract extends Contract {
|
|
57
|
+
/**
|
|
58
|
+
* @description Shared adapter instance for all contract instances
|
|
59
|
+
*/
|
|
60
|
+
static { this.adapter = new FabricContractAdapter(); }
|
|
58
61
|
static { this.serializer = new DeterministicSerializer(); }
|
|
59
62
|
/**
|
|
60
63
|
* @description Creates a new FabricCrudContract instance
|
|
@@ -66,28 +69,7 @@ export class FabricCrudContract extends Contract {
|
|
|
66
69
|
super(name);
|
|
67
70
|
this.clazz = clazz;
|
|
68
71
|
this.initialized = false;
|
|
69
|
-
|
|
70
|
-
this.repo = Repository.forModel(clazz, FabricCrudContract.adapter.alias);
|
|
71
|
-
}
|
|
72
|
-
getAdapter(clazz) {
|
|
73
|
-
const instance = new clazz();
|
|
74
|
-
if (isModelPrivate(instance)) {
|
|
75
|
-
const pvt = modelToPrivate(instance);
|
|
76
|
-
const collections = Object.keys(pvt.private);
|
|
77
|
-
return new FabricContractPrivateDataAdapter(undefined, "fabric-private-data-adapter", collections);
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
return new FabricContractAdapter(undefined, [FabricFlavour, clazz.name].join("_"));
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* @description Creates a logger for a specific chaincode context
|
|
85
|
-
* @summary Returns a ContractLogger instance configured for the current context
|
|
86
|
-
* @param {Ctx} ctx - The Fabric chaincode context
|
|
87
|
-
* @return {ContractLogger} The logger instance
|
|
88
|
-
*/
|
|
89
|
-
logFor(ctx) {
|
|
90
|
-
return Logging.for(FabricCrudContract.name, {}, ctx);
|
|
72
|
+
this.repo = Repository.forModel(clazz);
|
|
91
73
|
}
|
|
92
74
|
/**
|
|
93
75
|
* @description Creates a single model in the state database
|
|
@@ -98,14 +80,14 @@ export class FabricCrudContract extends Contract {
|
|
|
98
80
|
* @return {Promise<M>} Promise resolving to the created model
|
|
99
81
|
*/
|
|
100
82
|
async create(ctx, model, ...args) {
|
|
101
|
-
const log = this.
|
|
83
|
+
const { log, ctxArgs } = await this.logCtx([...args, ctx], this.create);
|
|
102
84
|
if (typeof model === "string")
|
|
103
85
|
model = this.deserialize(model);
|
|
104
86
|
log.info(`Creating model: ${JSON.stringify(model)}`);
|
|
105
87
|
const transient = this.getTransientData(ctx);
|
|
106
88
|
log.info(`Merging transient data...`);
|
|
107
|
-
model =
|
|
108
|
-
return this.repo.create(model,
|
|
89
|
+
model = Model.merge(model, transient, this.clazz);
|
|
90
|
+
return this.repo.create(model, ...ctxArgs);
|
|
109
91
|
}
|
|
110
92
|
/**
|
|
111
93
|
* @description Reads a single model from the state database
|
|
@@ -116,9 +98,9 @@ export class FabricCrudContract extends Contract {
|
|
|
116
98
|
* @return {Promise<M>} Promise resolving to the retrieved model
|
|
117
99
|
*/
|
|
118
100
|
async read(ctx, key, ...args) {
|
|
119
|
-
const log = this.
|
|
101
|
+
const { log, ctxArgs } = await this.logCtx([...args, ctx], this.read);
|
|
120
102
|
log.info(`reading entry with pk ${key} `);
|
|
121
|
-
return this.repo.read(key,
|
|
103
|
+
return this.repo.read(key, ...ctxArgs);
|
|
122
104
|
}
|
|
123
105
|
getTransientData(ctx) {
|
|
124
106
|
const transientMap = ctx.stub.getTransient();
|
|
@@ -137,14 +119,14 @@ export class FabricCrudContract extends Contract {
|
|
|
137
119
|
* @return {Promise<M>} Promise resolving to the updated model
|
|
138
120
|
*/
|
|
139
121
|
async update(ctx, model, ...args) {
|
|
140
|
-
const log = this.
|
|
122
|
+
const { log, ctxArgs } = await this.logCtx([...args, ctx], this.update);
|
|
141
123
|
if (typeof model === "string")
|
|
142
124
|
model = this.deserialize(model);
|
|
143
125
|
log.info(`Updating model: ${JSON.stringify(model)}`);
|
|
144
126
|
const transient = this.getTransientData(ctx);
|
|
145
127
|
log.info(`Merging transient data...`);
|
|
146
|
-
model =
|
|
147
|
-
return this.repo.update(model,
|
|
128
|
+
model = Model.merge(model, transient, this.clazz);
|
|
129
|
+
return this.repo.update(model, ...ctxArgs);
|
|
148
130
|
}
|
|
149
131
|
/**
|
|
150
132
|
* @description Deletes a single model from the state database
|
|
@@ -155,9 +137,9 @@ export class FabricCrudContract extends Contract {
|
|
|
155
137
|
* @return {Promise<M>} Promise resolving to the deleted model
|
|
156
138
|
*/
|
|
157
139
|
async delete(ctx, key, ...args) {
|
|
158
|
-
const log = this.
|
|
140
|
+
const { log, ctxArgs } = await this.logCtx([...args, ctx], this.delete);
|
|
159
141
|
log.info(`deleting entry with pk ${key} `);
|
|
160
|
-
return this.repo.delete(String(key),
|
|
142
|
+
return this.repo.delete(String(key), ...ctxArgs);
|
|
161
143
|
}
|
|
162
144
|
/**
|
|
163
145
|
* @description Deletes multiple models from the state database
|
|
@@ -168,9 +150,10 @@ export class FabricCrudContract extends Contract {
|
|
|
168
150
|
* @return {Promise<M[]>} Promise resolving to the deleted models
|
|
169
151
|
*/
|
|
170
152
|
async deleteAll(ctx, keys, ...args) {
|
|
153
|
+
const { ctxArgs } = await this.logCtx([...args, ctx], this.readAll);
|
|
171
154
|
if (typeof keys === "string")
|
|
172
155
|
keys = JSON.parse(keys);
|
|
173
|
-
return this.repo.deleteAll(keys,
|
|
156
|
+
return this.repo.deleteAll(keys, ...ctxArgs);
|
|
174
157
|
}
|
|
175
158
|
/**
|
|
176
159
|
* @description Reads multiple models from the state database
|
|
@@ -181,9 +164,10 @@ export class FabricCrudContract extends Contract {
|
|
|
181
164
|
* @return {Promise<M[]>} Promise resolving to the retrieved models
|
|
182
165
|
*/
|
|
183
166
|
async readAll(ctx, keys, ...args) {
|
|
167
|
+
const { ctxArgs } = await this.logCtx([...args, ctx], this.readAll);
|
|
184
168
|
if (typeof keys === "string")
|
|
185
169
|
keys = JSON.parse(keys);
|
|
186
|
-
return this.repo.readAll(keys,
|
|
170
|
+
return this.repo.readAll(keys, ...ctxArgs);
|
|
187
171
|
}
|
|
188
172
|
/**
|
|
189
173
|
* @description Updates multiple models in the state database
|
|
@@ -194,13 +178,13 @@ export class FabricCrudContract extends Contract {
|
|
|
194
178
|
* @return {Promise<M[]>} Promise resolving to the updated models
|
|
195
179
|
*/
|
|
196
180
|
async updateAll(ctx, models, ...args) {
|
|
197
|
-
const log = this.
|
|
181
|
+
const { log, ctxArgs } = await this.logCtx([...args, ctx], this.updateAll);
|
|
198
182
|
if (typeof models === "string")
|
|
199
183
|
models = JSON.parse(models)
|
|
200
184
|
.map((m) => this.deserialize(m))
|
|
201
185
|
.map((m) => new this.clazz(m));
|
|
202
186
|
log.info(`updating ${models.length} entries to the table`);
|
|
203
|
-
return this.repo.updateAll(models,
|
|
187
|
+
return this.repo.updateAll(models, ...ctxArgs);
|
|
204
188
|
}
|
|
205
189
|
/**
|
|
206
190
|
* @description Executes a raw query against the state database
|
|
@@ -212,9 +196,10 @@ export class FabricCrudContract extends Contract {
|
|
|
212
196
|
* @return {Promise<any>} Promise resolving to the query results
|
|
213
197
|
*/
|
|
214
198
|
async raw(ctx, rawInput, docsOnly, ...args) {
|
|
199
|
+
const { ctxArgs } = await this.logCtx([...args, ctx], this.raw);
|
|
215
200
|
if (typeof rawInput === "string")
|
|
216
201
|
rawInput = JSON.parse(rawInput);
|
|
217
|
-
return
|
|
202
|
+
return FabricCrudContract.adapter.raw(rawInput, docsOnly, ...ctxArgs);
|
|
218
203
|
}
|
|
219
204
|
serialize(model) {
|
|
220
205
|
return FabricCrudContract.serializer.serialize(model);
|
|
@@ -223,13 +208,13 @@ export class FabricCrudContract extends Contract {
|
|
|
223
208
|
return FabricCrudContract.serializer.deserialize(str);
|
|
224
209
|
}
|
|
225
210
|
async init(ctx) {
|
|
226
|
-
const log = this.
|
|
211
|
+
const { log } = await this.logCtx([ctx], this.init);
|
|
227
212
|
log.info(`Running contract initialization...`);
|
|
228
213
|
this.initialized = true;
|
|
229
214
|
log.info(`Contract initialization completed.`);
|
|
230
215
|
}
|
|
231
216
|
async healthcheck(ctx) {
|
|
232
|
-
const log = this.
|
|
217
|
+
const { log } = await this.logCtx([ctx], this.healthcheck);
|
|
233
218
|
log.info(`Running Healthcheck: ${this.initialized}...`);
|
|
234
219
|
return { healthcheck: this.initialized };
|
|
235
220
|
}
|
|
@@ -242,7 +227,7 @@ export class FabricCrudContract extends Contract {
|
|
|
242
227
|
* @return {Promise<M[]>} Promise resolving to the created models
|
|
243
228
|
*/
|
|
244
229
|
async createAll(ctx, models, ...args) {
|
|
245
|
-
const log = this.
|
|
230
|
+
const { log } = await this.logCtx([...args, ctx], this.createAll);
|
|
246
231
|
if (typeof models === "string")
|
|
247
232
|
models = JSON.parse(models)
|
|
248
233
|
.map((m) => this.deserialize(m))
|
|
@@ -250,5 +235,50 @@ export class FabricCrudContract extends Contract {
|
|
|
250
235
|
log.info(`adding ${models.length} entries to the table`);
|
|
251
236
|
return this.repo.createAll(models, ctx, ...args);
|
|
252
237
|
}
|
|
238
|
+
async logCtx(args, method) {
|
|
239
|
+
return FabricCrudContract.logCtx.bind(this)(args, method);
|
|
240
|
+
}
|
|
241
|
+
static async logCtx(args, method) {
|
|
242
|
+
if (args.length < 1)
|
|
243
|
+
throw new InternalError("No context provided");
|
|
244
|
+
const ctx = args.pop();
|
|
245
|
+
if (ctx instanceof FabricContractContext)
|
|
246
|
+
return {
|
|
247
|
+
ctx,
|
|
248
|
+
log: ctx.logger.clear().for(this).for(method),
|
|
249
|
+
ctxArgs: [...args, ctx],
|
|
250
|
+
};
|
|
251
|
+
if (!(ctx instanceof Context))
|
|
252
|
+
throw new InternalError("No valid context provided");
|
|
253
|
+
function getOp() {
|
|
254
|
+
if (typeof method === "string")
|
|
255
|
+
return method;
|
|
256
|
+
switch (method.name) {
|
|
257
|
+
case OperationKeys.CREATE:
|
|
258
|
+
case OperationKeys.READ:
|
|
259
|
+
case OperationKeys.UPDATE:
|
|
260
|
+
case OperationKeys.DELETE:
|
|
261
|
+
case BulkCrudOperationKeys.CREATE_ALL:
|
|
262
|
+
case BulkCrudOperationKeys.READ_ALL:
|
|
263
|
+
case BulkCrudOperationKeys.UPDATE_ALL:
|
|
264
|
+
case BulkCrudOperationKeys.DELETE_ALL:
|
|
265
|
+
return method.name;
|
|
266
|
+
default:
|
|
267
|
+
return method.name;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
const overrides = {
|
|
271
|
+
correlationId: ctx.stub.getTxID(),
|
|
272
|
+
};
|
|
273
|
+
const context = await FabricCrudContract.adapter.context(getOp(), overrides, this.clazz, ctx);
|
|
274
|
+
const log = (this
|
|
275
|
+
? context.logger.for(this).for(method)
|
|
276
|
+
: context.logger.clear().for(this).for(method));
|
|
277
|
+
return {
|
|
278
|
+
ctx: context,
|
|
279
|
+
log: log,
|
|
280
|
+
ctxArgs: [...args, context],
|
|
281
|
+
};
|
|
282
|
+
}
|
|
253
283
|
}
|
|
254
284
|
//# sourceMappingURL=crud-contract.js.map
|