@decaf-ts/for-fabric 0.1.16 → 0.1.18
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/bin/build-contracts2.cjs +73 -0
- package/lib/bin/build-contracts2.d.ts +1 -0
- package/lib/bin/build-contracts2.js.map +1 -0
- package/lib/bin/compile-indexes.cjs +30 -0
- package/lib/bin/compile-indexes.d.ts +1 -0
- package/lib/bin/compile-indexes.js.map +1 -0
- package/lib/cli-module.cjs +139 -0
- package/lib/cli-module.d.ts +2 -0
- package/lib/cli-module.js.map +1 -0
- package/lib/client/FabricClientAdapter.cjs +39 -40
- package/lib/client/FabricClientAdapter.d.ts +17 -13
- package/lib/client/FabricClientAdapter.js.map +1 -1
- package/lib/client/FabricClientPaginator.cjs +69 -0
- package/lib/client/FabricClientPaginator.d.ts +10 -0
- package/lib/client/FabricClientPaginator.js.map +1 -0
- package/lib/client/FabricClientRepository.cjs +36 -12
- package/lib/client/FabricClientRepository.d.ts +5 -1
- package/lib/client/FabricClientRepository.js.map +1 -1
- package/lib/client/FabricClientStatement.cjs +111 -0
- package/lib/client/FabricClientStatement.d.ts +10 -0
- package/lib/client/FabricClientStatement.js.map +1 -0
- package/lib/client/fabric-fs.d.ts +1 -1
- package/lib/client/indexes/generation.cjs +156 -0
- package/lib/client/indexes/generation.d.ts +16 -0
- package/lib/client/indexes/generation.js.map +1 -0
- package/lib/client/indexes/index.cjs +18 -0
- package/lib/client/indexes/index.d.ts +1 -0
- package/lib/client/indexes/index.js.map +1 -0
- package/lib/client/services/FabricEnrollmentService.d.ts +1 -1
- package/lib/client/types.cjs +3 -0
- package/lib/client/types.d.ts +7 -0
- package/lib/client/types.js.map +1 -0
- package/lib/contracts/ContractAdapter.cjs +54 -44
- package/lib/contracts/ContractAdapter.d.ts +20 -9
- package/lib/contracts/ContractAdapter.js.map +1 -1
- package/lib/contracts/ContractPrivateDataAdapter.cjs +0 -5
- package/lib/contracts/ContractPrivateDataAdapter.js.map +1 -1
- package/lib/contracts/FabricContractRepository.d.ts +2 -2
- package/lib/contracts/FabricContractRepository.js.map +1 -1
- package/lib/contracts/crud/crud-contract.cjs +30 -1
- package/lib/contracts/crud/crud-contract.d.ts +29 -14
- package/lib/contracts/crud/crud-contract.js.map +1 -1
- package/lib/contracts/crud/serialized-crud-contract.cjs +27 -15
- package/lib/contracts/crud/serialized-crud-contract.d.ts +9 -8
- package/lib/contracts/crud/serialized-crud-contract.js.map +1 -1
- package/lib/contracts/erc20/erc20contract.cjs +40 -34
- package/lib/contracts/erc20/erc20contract.d.ts +15 -15
- package/lib/contracts/erc20/erc20contract.js.map +1 -1
- package/lib/contracts/index.cjs +1 -2
- package/lib/contracts/index.d.ts +1 -2
- package/lib/contracts/index.js.map +1 -1
- package/lib/esm/bin/build-contracts2.d.ts +1 -0
- package/lib/esm/bin/build-contracts2.js +68 -0
- package/lib/esm/bin/build-contracts2.js.map +1 -0
- package/lib/esm/bin/compile-indexes.d.ts +1 -0
- package/lib/esm/bin/compile-indexes.js +25 -0
- package/lib/esm/bin/compile-indexes.js.map +1 -0
- package/lib/esm/cli-module.d.ts +2 -0
- package/lib/esm/cli-module.js +133 -0
- package/lib/esm/cli-module.js.map +1 -0
- package/lib/esm/client/FabricClientAdapter.d.ts +17 -13
- package/lib/esm/client/FabricClientAdapter.js +41 -42
- package/lib/esm/client/FabricClientAdapter.js.map +1 -1
- package/lib/esm/client/FabricClientPaginator.d.ts +10 -0
- package/lib/esm/client/FabricClientPaginator.js +65 -0
- package/lib/esm/client/FabricClientPaginator.js.map +1 -0
- package/lib/esm/client/FabricClientRepository.d.ts +5 -1
- package/lib/esm/client/FabricClientRepository.js +37 -13
- package/lib/esm/client/FabricClientRepository.js.map +1 -1
- package/lib/esm/client/FabricClientStatement.d.ts +10 -0
- package/lib/esm/client/FabricClientStatement.js +107 -0
- package/lib/esm/client/FabricClientStatement.js.map +1 -0
- package/lib/esm/client/fabric-fs.d.ts +1 -1
- package/lib/esm/client/indexes/generation.d.ts +16 -0
- package/lib/esm/client/indexes/generation.js +118 -0
- package/lib/esm/client/indexes/generation.js.map +1 -0
- package/lib/esm/client/indexes/index.d.ts +1 -0
- package/lib/esm/client/indexes/index.js +2 -0
- package/lib/esm/client/indexes/index.js.map +1 -0
- package/lib/esm/client/services/FabricEnrollmentService.d.ts +1 -1
- package/lib/esm/client/types.d.ts +7 -0
- package/lib/esm/client/types.js +2 -0
- package/lib/esm/client/types.js.map +1 -0
- package/lib/esm/contracts/ContractAdapter.d.ts +20 -9
- package/lib/esm/contracts/ContractAdapter.js +55 -45
- package/lib/esm/contracts/ContractAdapter.js.map +1 -1
- package/lib/esm/contracts/ContractPrivateDataAdapter.js +0 -5
- package/lib/esm/contracts/ContractPrivateDataAdapter.js.map +1 -1
- package/lib/esm/contracts/FabricContractRepository.d.ts +2 -2
- package/lib/esm/contracts/FabricContractRepository.js.map +1 -1
- package/lib/esm/contracts/crud/crud-contract.d.ts +29 -14
- package/lib/esm/contracts/crud/crud-contract.js +31 -2
- package/lib/esm/contracts/crud/crud-contract.js.map +1 -1
- package/lib/esm/contracts/crud/serialized-crud-contract.d.ts +9 -8
- package/lib/esm/contracts/crud/serialized-crud-contract.js +27 -15
- package/lib/esm/contracts/crud/serialized-crud-contract.js.map +1 -1
- package/lib/esm/contracts/erc20/erc20contract.d.ts +15 -15
- package/lib/esm/contracts/erc20/erc20contract.js +40 -34
- package/lib/esm/contracts/erc20/erc20contract.js.map +1 -1
- package/lib/esm/contracts/index.d.ts +1 -2
- package/lib/esm/contracts/index.js +1 -2
- package/lib/esm/contracts/index.js.map +1 -1
- package/lib/esm/shared/model/FabricBaseModel.d.ts +7 -0
- package/lib/esm/shared/model/FabricBaseModel.js +40 -0
- package/lib/esm/shared/model/FabricBaseModel.js.map +1 -0
- package/lib/esm/shared/model/FabricIdentifiedBaseModel.d.ts +7 -0
- package/lib/esm/shared/model/{Sequence.js → FabricIdentifiedBaseModel.js} +19 -18
- package/lib/esm/shared/model/FabricIdentifiedBaseModel.js.map +1 -0
- package/lib/esm/shared/model/Identity.js +2 -1
- package/lib/esm/shared/model/Identity.js.map +1 -1
- package/lib/esm/shared/model/index.d.ts +0 -1
- package/lib/esm/shared/model/index.js +0 -1
- package/lib/esm/shared/model/index.js.map +1 -1
- package/lib/esm/shared/utils.d.ts +1 -1
- package/lib/esm/version.d.ts +1 -1
- package/lib/esm/version.js +1 -1
- package/lib/shared/model/FabricBaseModel.cjs +43 -0
- package/lib/shared/model/FabricBaseModel.d.ts +7 -0
- package/lib/shared/model/FabricBaseModel.js.map +1 -0
- package/lib/shared/model/FabricIdentifiedBaseModel.cjs +37 -0
- package/lib/shared/model/FabricIdentifiedBaseModel.d.ts +7 -0
- package/lib/shared/model/FabricIdentifiedBaseModel.js.map +1 -0
- package/lib/shared/model/Identity.cjs +1 -0
- package/lib/shared/model/Identity.js.map +1 -1
- package/lib/shared/model/index.cjs +0 -1
- package/lib/shared/model/index.d.ts +0 -1
- package/lib/shared/model/index.js.map +1 -1
- package/lib/shared/utils.d.ts +1 -1
- package/lib/version.cjs +1 -1
- package/lib/version.d.ts +1 -1
- package/package.json +10 -6
- package/lib/contracts/FabricContractSequence.cjs +0 -119
- package/lib/contracts/FabricContractSequence.d.ts +0 -50
- package/lib/contracts/FabricContractSequence.js.map +0 -1
- package/lib/esm/contracts/FabricContractSequence.d.ts +0 -50
- package/lib/esm/contracts/FabricContractSequence.js +0 -115
- package/lib/esm/contracts/FabricContractSequence.js.map +0 -1
- package/lib/esm/shared/model/Sequence.d.ts +0 -14
- package/lib/esm/shared/model/Sequence.js.map +0 -1
- package/lib/shared/model/Sequence.cjs +0 -36
- package/lib/shared/model/Sequence.d.ts +0 -14
- package/lib/shared/model/Sequence.js.map +0 -1
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { Condition, GroupOperator, Operator, QueryClause, QueryError, Statement, } from "@decaf-ts/core";
|
|
2
|
+
import { toCamelCase } from "@decaf-ts/logging";
|
|
3
|
+
import { FabricClientPaginator } from "./FabricClientPaginator.js";
|
|
4
|
+
import { InternalError } from "@decaf-ts/db-decorators";
|
|
5
|
+
export class FabricClientStatement extends Statement {
|
|
6
|
+
constructor(adapter) {
|
|
7
|
+
super(adapter);
|
|
8
|
+
}
|
|
9
|
+
build() {
|
|
10
|
+
const method = [QueryClause.FIND_BY];
|
|
11
|
+
const args = [];
|
|
12
|
+
const params = {};
|
|
13
|
+
if (this.whereCondition) {
|
|
14
|
+
const parsed = this.parseCondition(this.whereCondition);
|
|
15
|
+
method.push(parsed.method);
|
|
16
|
+
if (parsed.args && parsed.args.length)
|
|
17
|
+
args.push(...parsed.args);
|
|
18
|
+
}
|
|
19
|
+
if (this.selectSelector)
|
|
20
|
+
method.push(QueryClause.SELECT, this.selectSelector.join(` ${QueryClause.AND.toLowerCase()} `));
|
|
21
|
+
if (this.orderBySelector)
|
|
22
|
+
method.push(QueryClause.ORDER_BY, ...this.orderBySelector);
|
|
23
|
+
if (this.groupBySelector)
|
|
24
|
+
method.push(QueryClause.GROUP_BY, this.groupBySelector);
|
|
25
|
+
if (this.limitSelector)
|
|
26
|
+
params.limit = this.limitSelector;
|
|
27
|
+
if (this.offsetSelector) {
|
|
28
|
+
params.skip = this.offsetSelector;
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
class: this.fromSelector,
|
|
32
|
+
method: toCamelCase(method.join(" ")),
|
|
33
|
+
args: args,
|
|
34
|
+
params: Object.keys(params).length ? params : undefined,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
async paginate(size = 10,
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
39
|
+
...args) {
|
|
40
|
+
try {
|
|
41
|
+
const query = this.build();
|
|
42
|
+
return new FabricClientPaginator(this.adapter, query, size, this.fromSelector);
|
|
43
|
+
}
|
|
44
|
+
catch (e) {
|
|
45
|
+
throw new InternalError(e);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
parseCondition(condition) {
|
|
49
|
+
// @ts-expect-error accessing protected properties
|
|
50
|
+
// eslint-disable-next-line prefer-const
|
|
51
|
+
let { attr1, operator, comparison } = condition;
|
|
52
|
+
const result = {};
|
|
53
|
+
switch (operator) {
|
|
54
|
+
case GroupOperator.AND:
|
|
55
|
+
case GroupOperator.OR: {
|
|
56
|
+
let side1 = attr1, side2 = comparison;
|
|
57
|
+
if (typeof attr1 !== "string") {
|
|
58
|
+
const condition1 = this.parseCondition(attr1);
|
|
59
|
+
side1 = condition1.method;
|
|
60
|
+
result.args = [...(result.args || []), ...(condition1.args || [])];
|
|
61
|
+
}
|
|
62
|
+
if (comparison instanceof Condition) {
|
|
63
|
+
const condition2 = this.parseCondition(comparison);
|
|
64
|
+
side2 = condition2.method;
|
|
65
|
+
result.args = [...(result.args || []), ...(condition2.args || [])];
|
|
66
|
+
}
|
|
67
|
+
result.method = `${side1} ${operator.toLowerCase()} ${side2}`;
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
case Operator.EQUAL:
|
|
71
|
+
result.method = attr1;
|
|
72
|
+
result.args = [...(result.args || []), comparison];
|
|
73
|
+
break;
|
|
74
|
+
case Operator.DIFFERENT:
|
|
75
|
+
result.method = `${attr1} diff`;
|
|
76
|
+
result.args = [...(result.args || []), comparison];
|
|
77
|
+
break;
|
|
78
|
+
case Operator.REGEXP:
|
|
79
|
+
result.method = `${attr1} matches`;
|
|
80
|
+
result.args = [...(result.args || []), comparison];
|
|
81
|
+
break;
|
|
82
|
+
case Operator.BIGGER:
|
|
83
|
+
result.method = `${attr1} bigger`;
|
|
84
|
+
result.args = [...(result.args || []), comparison];
|
|
85
|
+
break;
|
|
86
|
+
case Operator.BIGGER_EQ:
|
|
87
|
+
result.method = `${attr1} bigger than equal`;
|
|
88
|
+
break;
|
|
89
|
+
case Operator.SMALLER:
|
|
90
|
+
result.method = `${attr1} less`;
|
|
91
|
+
result.args = [...(result.args || []), comparison];
|
|
92
|
+
break;
|
|
93
|
+
case Operator.SMALLER_EQ:
|
|
94
|
+
result.method = `${attr1} less than equal`;
|
|
95
|
+
result.args = [...(result.args || []), comparison];
|
|
96
|
+
break;
|
|
97
|
+
case Operator.IN:
|
|
98
|
+
result.method = `${attr1} in`;
|
|
99
|
+
result.args = [...(result.args || []), comparison];
|
|
100
|
+
break;
|
|
101
|
+
default:
|
|
102
|
+
throw new QueryError(`Unsupported operator ${operator}`);
|
|
103
|
+
}
|
|
104
|
+
return result;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=FabricClientStatement.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FabricClientStatement.js","sourceRoot":"","sources":["../../../src/client/FabricClientStatement.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EAET,aAAa,EAEb,QAAQ,EAER,WAAW,EACX,UAAU,EACV,SAAS,GACV,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAE,qBAAqB,EAAE,mCAAgC;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAGxD,MAAM,OAAO,qBAA0C,SAAQ,SAK9D;IACC,YAAY,OAA4B;QACtC,KAAK,CAAC,OAAO,CAAC,CAAC;IACjB,CAAC;IAES,KAAK;QACb,MAAM,MAAM,GAAa,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;QAC/C,MAAM,IAAI,GAAwB,EAAE,CAAC;QACrC,MAAM,MAAM,GAAkC,EAAS,CAAC;QAExD,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YACxB,MAAM,MAAM,GAAG,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;YACxD,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,MAA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Q,CAAC,UAAU;gBACtB,MAAM,CAAC,MAAM,GAAG,GAAG,KAAK,kBAAkB,CAAC;gBAC3C,MAAM,CAAC,IAAI,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,IAAI,EAAE,CAAC,EAAE,UAAU,CAAC,CAAC;gBACnD,MAAM;YACR,KAAK,QAAQ,CAAC,EAAE;gBACd,MAAM,CAAC,MAAM,GAAG,GAAG,KAAK,KAAK,CAAC;gBAC9B,MAAM,CAAC,IAAI,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,IAAI,EAAE,CAAC,EAAE,UAAU,CAAC,CAAC;gBACnD,MAAM;YACR;gBACE,MAAM,IAAI,UAAU,CAAC,wBAAwB,QAAQ,EAAE,CAAC,CAAC;QAC7D,CAAC;QAED,OAAO,MAAqB,CAAC;IAC/B,CAAC;CACF"}
|
|
@@ -18,7 +18,7 @@ export declare function contentOfLoadFile(contentOrPath: string | Uint8Array, fi
|
|
|
18
18
|
* @function readFile
|
|
19
19
|
* @memberOf module:for-fabric.client
|
|
20
20
|
*/
|
|
21
|
-
export declare function readFile(contentOrPath: string | Buffer): Promise<
|
|
21
|
+
export declare function readFile(contentOrPath: string | Buffer): Promise<NonSharedBuffer>;
|
|
22
22
|
/**
|
|
23
23
|
* @description Creates a Certificate Authority user
|
|
24
24
|
* @summary Initializes a user with the given credentials for interacting with a Fabric CA
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { OrderDirection } from "@decaf-ts/core";
|
|
2
|
+
import { Constructor } from "@decaf-ts/decoration";
|
|
3
|
+
import { Model, ModelConstructor } from "@decaf-ts/decorator-validation";
|
|
4
|
+
export type Index = {
|
|
5
|
+
index: {
|
|
6
|
+
fields: string[] | {
|
|
7
|
+
[k: string]: OrderDirection;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
ddoc?: string;
|
|
11
|
+
name: string;
|
|
12
|
+
type: "json";
|
|
13
|
+
};
|
|
14
|
+
export declare function generateModelIndexes<M extends Model>(m: Constructor<M>, accum?: Record<string, any>): Index[];
|
|
15
|
+
export declare function readModelFolders(...folders: string[]): Promise<ModelConstructor<any>[]>;
|
|
16
|
+
export declare function writeIndexes(indexes: Index[], p?: string): void;
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { Metadata } from "@decaf-ts/decoration";
|
|
2
|
+
import { CouchDBKeys } from "@decaf-ts/for-couchdb";
|
|
3
|
+
import { Model } from "@decaf-ts/decorator-validation";
|
|
4
|
+
import { normalizeImport } from "./../../shared/index.js";
|
|
5
|
+
function getIndexReference(name, direction, compositions) {
|
|
6
|
+
return [
|
|
7
|
+
...name.map((n) => (n === CouchDBKeys.TABLE ? "table" : n)),
|
|
8
|
+
...(compositions || []),
|
|
9
|
+
...(direction ? [direction] : []),
|
|
10
|
+
"index",
|
|
11
|
+
].join(Metadata.splitter);
|
|
12
|
+
}
|
|
13
|
+
function addIndex(accum, fields, direction, compositions) {
|
|
14
|
+
const name = getIndexReference(fields, direction, compositions);
|
|
15
|
+
let f = [
|
|
16
|
+
...fields,
|
|
17
|
+
...(compositions || []),
|
|
18
|
+
];
|
|
19
|
+
if (direction)
|
|
20
|
+
f = f.reduce((accum, el) => {
|
|
21
|
+
const entry = {};
|
|
22
|
+
entry[el] = direction;
|
|
23
|
+
accum.push(entry);
|
|
24
|
+
return accum;
|
|
25
|
+
}, []);
|
|
26
|
+
const index = {
|
|
27
|
+
index: {
|
|
28
|
+
fields: f,
|
|
29
|
+
},
|
|
30
|
+
name: name,
|
|
31
|
+
ddoc: name,
|
|
32
|
+
type: "json",
|
|
33
|
+
};
|
|
34
|
+
accum[name] = index;
|
|
35
|
+
}
|
|
36
|
+
export function generateModelIndexes(m, accum) {
|
|
37
|
+
const tableName = getIndexReference([CouchDBKeys.TABLE]);
|
|
38
|
+
const indexes = accum || {};
|
|
39
|
+
indexes[tableName] = {
|
|
40
|
+
index: {
|
|
41
|
+
fields: [CouchDBKeys.TABLE],
|
|
42
|
+
},
|
|
43
|
+
name: tableName,
|
|
44
|
+
ddoc: tableName,
|
|
45
|
+
type: "json",
|
|
46
|
+
};
|
|
47
|
+
const result = {};
|
|
48
|
+
const modelIndexes = Model.indexes(m);
|
|
49
|
+
for (const prop of Object.keys(modelIndexes)) {
|
|
50
|
+
for (const [key, dec] of Object.entries(modelIndexes[prop])) {
|
|
51
|
+
const directions = dec
|
|
52
|
+
.directions;
|
|
53
|
+
const compositions = dec.compositions;
|
|
54
|
+
const fields = [key, CouchDBKeys.TABLE];
|
|
55
|
+
addIndex(result, fields);
|
|
56
|
+
if (compositions && compositions.length)
|
|
57
|
+
addIndex(result, fields, undefined, compositions);
|
|
58
|
+
if (directions && directions.length) {
|
|
59
|
+
directions.forEach((d) => {
|
|
60
|
+
addIndex(result, fields, d);
|
|
61
|
+
if (compositions && compositions.length)
|
|
62
|
+
addIndex(result, fields, d, compositions);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return Object.values(result);
|
|
68
|
+
}
|
|
69
|
+
export async function readModelFolders(...folders) {
|
|
70
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
71
|
+
const fs = require("fs");
|
|
72
|
+
// // eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
73
|
+
// const path = require("path");
|
|
74
|
+
const result = [];
|
|
75
|
+
for (const folder of folders) {
|
|
76
|
+
const files = fs
|
|
77
|
+
.readdirSync(folder, {
|
|
78
|
+
withFileTypes: true,
|
|
79
|
+
recursive: true,
|
|
80
|
+
})
|
|
81
|
+
.filter((f) => f.isFile());
|
|
82
|
+
for (const file of files) {
|
|
83
|
+
const exports = await normalizeImport(import(file));
|
|
84
|
+
const values = Object.values(exports).filter((e) => {
|
|
85
|
+
try {
|
|
86
|
+
const m = new e();
|
|
87
|
+
return m instanceof Model;
|
|
88
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
89
|
+
}
|
|
90
|
+
catch (e) {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
result.push(...values);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return result;
|
|
98
|
+
}
|
|
99
|
+
export function writeIndexes(indexes, p = process.cwd()) {
|
|
100
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
101
|
+
const fs = require("fs");
|
|
102
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
103
|
+
const path = require("path");
|
|
104
|
+
function ensureDirectoryExistence(filePath) {
|
|
105
|
+
const dirname = path.dirname(filePath);
|
|
106
|
+
if (fs.existsSync(dirname)) {
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
ensureDirectoryExistence(dirname);
|
|
110
|
+
fs.mkdirSync(dirname);
|
|
111
|
+
}
|
|
112
|
+
indexes.forEach((index) => {
|
|
113
|
+
const file = path.resolve(path.join(p, `./META-INF/statedb/couchdb/indexes/${index.name}.json`));
|
|
114
|
+
ensureDirectoryExistence(file);
|
|
115
|
+
fs.writeFileSync(file, JSON.stringify(index, undefined, 2));
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=generation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generation.js","sourceRoot":"","sources":["../../../../src/client/indexes/generation.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,KAAK,EAAoB,MAAM,gCAAgC,CAAC;AACzE,OAAO,EAAE,eAAe,EAAE,gCAA2B;AAWrD,SAAS,iBAAiB,CACxB,IAAc,EACd,SAA0B,EAC1B,YAAuB;IAEvB,OAAO;QACL,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC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MAAM,OAAO,GAAW,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAW,CAAC;QACzD,IAAI,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;YAC3B,OAAO,IAAI,CAAC;QACd,CAAC;QACD,wBAAwB,CAAC,OAAO,CAAC,CAAC;QAClC,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IACxB,CAAC;IAED,OAAO,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;QACxB,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CACvB,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,sCAAsC,KAAK,CAAC,IAAI,OAAO,CAAC,CACtE,CAAC;QACF,wBAAwB,CAAC,IAAI,CAAC,CAAC;QAC/B,EAAE,CAAC,aAAa,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,CAAC;IAC9D,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./generation";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/client/indexes/index.ts"],"names":[],"mappings":"AAAA,gCAA6B"}
|
|
@@ -115,7 +115,7 @@ export declare class FabricEnrollmentService extends LoggedClass {
|
|
|
115
115
|
* @return {Promise<FabricIdentity[]>} The list of identities registered in the CA.
|
|
116
116
|
*/
|
|
117
117
|
getIdentities(): Promise<FabricIdentity[]>;
|
|
118
|
-
protected parseError(e: Error):
|
|
118
|
+
protected parseError(e: Error): ConflictError | AuthorizationError;
|
|
119
119
|
/**
|
|
120
120
|
* @description Retrieve affiliations from the CA.
|
|
121
121
|
* @summary Queries the CA for the list of affiliations available under the configured CA.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/client/types.ts"],"names":[],"mappings":""}
|
|
@@ -5,10 +5,10 @@ import { FabricContractContext } from "./ContractContext";
|
|
|
5
5
|
import { BaseError, Context, OperationKeys, PrimaryKeyType } from "@decaf-ts/db-decorators";
|
|
6
6
|
import { Context as Ctx } from "fabric-contract-api";
|
|
7
7
|
import { Logger } from "@decaf-ts/logging";
|
|
8
|
-
import { RelationsMetadata,
|
|
8
|
+
import { RelationsMetadata, SequenceOptions, Adapter, PreparedModel, Repository, ContextualizedArgs } from "@decaf-ts/core";
|
|
9
9
|
import type { ContextualArgs, MaybeContextualArg } from "@decaf-ts/core";
|
|
10
10
|
import { FabricContractRepository } from "./FabricContractRepository";
|
|
11
|
-
import { ChaincodeStub, Iterators, StateQueryResponse } from "fabric-shim-api";
|
|
11
|
+
import { ChaincodeStub, ClientIdentity, Iterators, StateQueryResponse } from "fabric-shim-api";
|
|
12
12
|
import { FabricStatement } from "./FabricContractStatement";
|
|
13
13
|
import { SimpleDeterministicSerializer } from "../shared/SimpleDeterministicSerializer";
|
|
14
14
|
import { Constructor } from "@decaf-ts/decoration";
|
|
@@ -116,14 +116,14 @@ export declare class FabricContractAdapter extends CouchDBAdapter<any, void, Fab
|
|
|
116
116
|
* @description Context constructor for this adapter
|
|
117
117
|
* @summary Overrides the base Context constructor with FabricContractContext
|
|
118
118
|
*/
|
|
119
|
-
Context:
|
|
119
|
+
protected readonly Context: Constructor<FabricContractContext>;
|
|
120
120
|
/**
|
|
121
121
|
* @description Gets the repository constructor for this adapter
|
|
122
122
|
* @summary Returns the FabricContractRepository constructor for creating repositories
|
|
123
123
|
* @template M - Type extending Model
|
|
124
124
|
* @return {Constructor<Repository<M, MangoQuery, FabricContractAdapter, FabricContractFlags, FabricContractContext>>} The repository constructor
|
|
125
125
|
*/
|
|
126
|
-
repository<R extends Repository<any, Adapter<any, void, MangoQuery,
|
|
126
|
+
repository<R extends Repository<any, Adapter<any, void, MangoQuery, Context<FabricContractFlags>>>>(): Constructor<R>;
|
|
127
127
|
/**
|
|
128
128
|
* @description Creates a new FabricContractAdapter instance
|
|
129
129
|
* @summary Initializes an adapter for interacting with the Fabric state database
|
|
@@ -142,7 +142,7 @@ export declare class FabricContractAdapter extends CouchDBAdapter<any, void, Fab
|
|
|
142
142
|
* @param {...any[]} args - Additional arguments, including the chaincode stub and logger
|
|
143
143
|
* @return {Promise<Record<string, any>>} Promise resolving to the created record
|
|
144
144
|
*/
|
|
145
|
-
create<M extends Model>(clazz: Constructor<M>, id: PrimaryKeyType, model: Record<string, any>, ...args: ContextualArgs<
|
|
145
|
+
create<M extends Model>(clazz: Constructor<M>, id: PrimaryKeyType, model: Record<string, any>, ...args: ContextualArgs<Context<FabricContractFlags>>): Promise<Record<string, any>>;
|
|
146
146
|
/**
|
|
147
147
|
* @description Reads a record from the state database
|
|
148
148
|
* @summary Retrieves and deserializes a record from the Fabric state database
|
|
@@ -151,7 +151,7 @@ export declare class FabricContractAdapter extends CouchDBAdapter<any, void, Fab
|
|
|
151
151
|
* @param {...any[]} args - Additional arguments, including the chaincode stub and logger
|
|
152
152
|
* @return {Promise<Record<string, any>>} Promise resolving to the retrieved record
|
|
153
153
|
*/
|
|
154
|
-
read<M extends Model>(clazz: Constructor<M>, id: PrimaryKeyType, ...args: ContextualArgs<
|
|
154
|
+
read<M extends Model>(clazz: Constructor<M>, id: PrimaryKeyType, ...args: ContextualArgs<Context<FabricContractFlags>>): Promise<Record<string, any>>;
|
|
155
155
|
/**
|
|
156
156
|
* @description Updates a record in the state database
|
|
157
157
|
* @summary Serializes a model and updates it in the Fabric state database
|
|
@@ -162,7 +162,7 @@ export declare class FabricContractAdapter extends CouchDBAdapter<any, void, Fab
|
|
|
162
162
|
* @param {...any[]} args - Additional arguments, including the chaincode stub and logger
|
|
163
163
|
* @return {Promise<Record<string, any>>} Promise resolving to the updated record
|
|
164
164
|
*/
|
|
165
|
-
update<M extends Model>(clazz: Constructor<M>, id: PrimaryKeyType, model: Record<string, any>, ...args: ContextualArgs<
|
|
165
|
+
update<M extends Model>(clazz: Constructor<M>, id: PrimaryKeyType, model: Record<string, any>, ...args: ContextualArgs<Context<FabricContractFlags>>): Promise<Record<string, any>>;
|
|
166
166
|
/**
|
|
167
167
|
* @description Deletes a record from the state database
|
|
168
168
|
* @summary Retrieves a record and then removes it from the Fabric state database
|
|
@@ -171,7 +171,7 @@ export declare class FabricContractAdapter extends CouchDBAdapter<any, void, Fab
|
|
|
171
171
|
* @param {...any[]} args - Additional arguments, including the chaincode stub and logger
|
|
172
172
|
* @return {Promise<Record<string, any>>} Promise resolving to the deleted record
|
|
173
173
|
*/
|
|
174
|
-
delete<M extends Model>(clazz: Constructor<M>, id: PrimaryKeyType, ...args: ContextualArgs<
|
|
174
|
+
delete<M extends Model>(clazz: Constructor<M>, id: PrimaryKeyType, ...args: ContextualArgs<Context<FabricContractFlags>>): Promise<Record<string, any>>;
|
|
175
175
|
protected deleteState(id: string, ctx: FabricContractContext): Promise<void>;
|
|
176
176
|
forPrivate(collection: string): FabricContractAdapter;
|
|
177
177
|
protected putState(id: string, model: Record<string, any>, ctx: FabricContractContext): Promise<Record<string, any>>;
|
|
@@ -261,7 +261,6 @@ export declare class FabricContractAdapter extends CouchDBAdapter<any, void, Fab
|
|
|
261
261
|
*/
|
|
262
262
|
raw<R>(rawInput: MangoQuery, ...args: ContextualArgs<FabricContractContext>): Promise<R>;
|
|
263
263
|
Statement<M extends Model>(): FabricStatement<M, any>;
|
|
264
|
-
Sequence(options: SequenceOptions): Promise<Sequence>;
|
|
265
264
|
createAll<M extends Model>(tableName: Constructor<M>, id: PrimaryKeyType[], model: Record<string, any>[], ...args: ContextualArgs<FabricContractContext>): Promise<Record<string, any>[]>;
|
|
266
265
|
updateAll<M extends Model>(tableName: Constructor<M>, id: PrimaryKeyType[], model: Record<string, any>[], ...args: ContextualArgs<FabricContractContext>): Promise<Record<string, any>[]>;
|
|
267
266
|
/**
|
|
@@ -277,6 +276,18 @@ export declare class FabricContractAdapter extends CouchDBAdapter<any, void, Fab
|
|
|
277
276
|
protected createAllPrefix<M extends Model>(tableName: Constructor<M>, ids: PrimaryKeyType[], models: Record<string, any>[], ...args: [...any, FabricContractContext]): (string | string[] | number[] | Record<string, any>[])[];
|
|
278
277
|
protected updateAllPrefix<M extends Model>(tableName: Constructor<M>, ids: PrimaryKeyType[], models: Record<string, any>[], ...args: [...any, FabricContractContext]): any[];
|
|
279
278
|
parseError<E extends BaseError>(err: Error | string, reason?: string): E;
|
|
279
|
+
logCtx<ARGS extends any[]>(args: ARGS, method: ((...args: any[]) => any) | string): ContextualizedArgs<FabricContractContext, ARGS> & {
|
|
280
|
+
stub: ChaincodeStub;
|
|
281
|
+
identity: ClientIdentity;
|
|
282
|
+
};
|
|
283
|
+
static logCtx<ARGS extends any[]>(this: any, args: ARGS, method: string): ContextualizedArgs<FabricContractContext, ARGS> & {
|
|
284
|
+
stub: ChaincodeStub;
|
|
285
|
+
identity: ClientIdentity;
|
|
286
|
+
};
|
|
287
|
+
static logCtx<ARGS extends any[]>(this: any, args: ARGS, method: (...args: any[]) => any): ContextualizedArgs<FabricContractContext, ARGS> & {
|
|
288
|
+
stub: ChaincodeStub;
|
|
289
|
+
identity: ClientIdentity;
|
|
290
|
+
};
|
|
280
291
|
static parseError<E extends BaseError>(err: Error | string): E;
|
|
281
292
|
/**
|
|
282
293
|
* @description Static method for decoration overrides
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { CouchDBAdapter, CouchDBKeys } from "@decaf-ts/for-couchdb";
|
|
2
2
|
import { list, Model, required, type } from "@decaf-ts/decorator-validation";
|
|
3
3
|
import { FabricContractContext } from "./ContractContext.js";
|
|
4
|
-
import { afterAny, BadRequestError, ConflictError, DBKeys, InternalError, NotFoundError, onCreate, onCreateUpdate, onDelete, onUpdate, readonly, SerializationError, } from "@decaf-ts/db-decorators";
|
|
4
|
+
import { afterAny, BadRequestError, ConflictError, Context, DBKeys, InternalError, NotFoundError, onCreate, onCreateUpdate, onDelete, onUpdate, readonly, SerializationError, } from "@decaf-ts/db-decorators";
|
|
5
5
|
import { Object as FabricObject, Property as FabricProperty, } from "fabric-contract-api";
|
|
6
6
|
import { PersistenceKeys, UnsupportedError, Adapter, oneToManyOnUpdate, relation, QueryError, PagingError, MigrationError, ObserverError, AuthorizationError, ForbiddenError, ConnectionError, } from "@decaf-ts/core";
|
|
7
7
|
import { FabricContractRepository } from "./FabricContractRepository.js";
|
|
8
8
|
import { FabricStatement } from "./FabricContractStatement.js";
|
|
9
|
-
import { FabricContractSequence } from "./FabricContractSequence.js";
|
|
10
9
|
import { FabricFlavour } from "./../shared/constants.js";
|
|
11
10
|
import { SimpleDeterministicSerializer } from "./../shared/SimpleDeterministicSerializer.js";
|
|
12
11
|
import { oneToManyOnCreate, oneToManyOnDelete, oneToOneOnCreate, oneToOneOnDelete, oneToOneOnUpdate, populate as pop, } from "./FabricConstruction.js";
|
|
13
12
|
import { apply, Decoration, prop, propMetadata, Metadata, } from "@decaf-ts/decoration";
|
|
13
|
+
import { ContractLogger } from "./logging.js";
|
|
14
14
|
/**
|
|
15
15
|
* @description Sets the creator or updater field in a model based on the user in the context
|
|
16
16
|
* @summary Callback function used in decorators to automatically set the created_by or updated_by fields
|
|
@@ -182,9 +182,8 @@ export class FabricContractAdapter extends CouchDBAdapter {
|
|
|
182
182
|
* @return {Promise<Record<string, any>>} Promise resolving to the created record
|
|
183
183
|
*/
|
|
184
184
|
async create(clazz, id, model, ...args) {
|
|
185
|
-
const { ctx, log } = this.logCtx(args, this.create);
|
|
185
|
+
const { ctx, log, stub } = this.logCtx(args, this.create);
|
|
186
186
|
log.info(`in ADAPTER create with args ${args}`);
|
|
187
|
-
const { stub } = ctx;
|
|
188
187
|
const tableName = Model.tableName(clazz);
|
|
189
188
|
try {
|
|
190
189
|
log.info(`adding entry to ${tableName} table with pk ${id}`);
|
|
@@ -205,9 +204,8 @@ export class FabricContractAdapter extends CouchDBAdapter {
|
|
|
205
204
|
* @return {Promise<Record<string, any>>} Promise resolving to the retrieved record
|
|
206
205
|
*/
|
|
207
206
|
async read(clazz, id, ...args) {
|
|
208
|
-
const { ctx, log } = this.logCtx(args, this.read);
|
|
207
|
+
const { ctx, log, stub } = this.logCtx(args, this.read);
|
|
209
208
|
log.info(`in ADAPTER read with args ${args}`);
|
|
210
|
-
const { stub } = ctx;
|
|
211
209
|
const tableName = Model.tableName(clazz);
|
|
212
210
|
let model;
|
|
213
211
|
try {
|
|
@@ -230,8 +228,7 @@ export class FabricContractAdapter extends CouchDBAdapter {
|
|
|
230
228
|
* @return {Promise<Record<string, any>>} Promise resolving to the updated record
|
|
231
229
|
*/
|
|
232
230
|
async update(clazz, id, model, ...args) {
|
|
233
|
-
const { ctx, log } = this.logCtx(args, this.update);
|
|
234
|
-
const { stub } = ctx;
|
|
231
|
+
const { ctx, log, stub } = this.logCtx(args, this.update);
|
|
235
232
|
const tableName = Model.tableName(clazz);
|
|
236
233
|
try {
|
|
237
234
|
log.verbose(`updating entry to ${tableName} table with pk ${id}`);
|
|
@@ -252,8 +249,7 @@ export class FabricContractAdapter extends CouchDBAdapter {
|
|
|
252
249
|
* @return {Promise<Record<string, any>>} Promise resolving to the deleted record
|
|
253
250
|
*/
|
|
254
251
|
async delete(clazz, id, ...args) {
|
|
255
|
-
const { ctx, log, ctxArgs } = this.logCtx(args, this.delete);
|
|
256
|
-
const { stub } = ctx;
|
|
252
|
+
const { ctx, log, ctxArgs, stub } = this.logCtx(args, this.delete);
|
|
257
253
|
const tableName = Model.tableName(clazz);
|
|
258
254
|
let model;
|
|
259
255
|
try {
|
|
@@ -268,8 +264,7 @@ export class FabricContractAdapter extends CouchDBAdapter {
|
|
|
268
264
|
return model;
|
|
269
265
|
}
|
|
270
266
|
async deleteState(id, ctx) {
|
|
271
|
-
const { stub
|
|
272
|
-
const log = logger.for(this.deleteState);
|
|
267
|
+
const { stub } = this.logCtx([ctx], this.deleteState);
|
|
273
268
|
await stub.deleteState(id);
|
|
274
269
|
}
|
|
275
270
|
forPrivate(collection) {
|
|
@@ -362,8 +357,7 @@ export class FabricContractAdapter extends CouchDBAdapter {
|
|
|
362
357
|
}
|
|
363
358
|
async putState(id, model, ctx) {
|
|
364
359
|
let data;
|
|
365
|
-
const { stub,
|
|
366
|
-
const log = logger.for(this.putState);
|
|
360
|
+
const { stub, log } = this.logCtx([ctx], this.putState);
|
|
367
361
|
try {
|
|
368
362
|
data = Buffer.from(FabricContractAdapter.serializer.serialize(model));
|
|
369
363
|
}
|
|
@@ -376,8 +370,7 @@ export class FabricContractAdapter extends CouchDBAdapter {
|
|
|
376
370
|
}
|
|
377
371
|
async readState(id, ctx) {
|
|
378
372
|
let result;
|
|
379
|
-
const { stub,
|
|
380
|
-
const log = logger.for(this.readState);
|
|
373
|
+
const { stub, log } = this.logCtx([ctx], this.readState);
|
|
381
374
|
const res = (await stub.getState(id)).toString();
|
|
382
375
|
if (!res)
|
|
383
376
|
throw new NotFoundError(`Record with id ${id} not found`);
|
|
@@ -432,33 +425,32 @@ export class FabricContractAdapter extends CouchDBAdapter {
|
|
|
432
425
|
* @return {FabricContractFlags} The merged flags
|
|
433
426
|
*/
|
|
434
427
|
async flags(operation, model, flags, ctx, ...args) {
|
|
435
|
-
const
|
|
436
|
-
|
|
437
|
-
if (typeof base.clear !== "function")
|
|
438
|
-
base.clear = () => base;
|
|
439
|
-
if (typeof base.for !== "function")
|
|
440
|
-
base.for = () => base;
|
|
441
|
-
return base;
|
|
428
|
+
const baseFlags = {
|
|
429
|
+
stub: ctx.stub,
|
|
442
430
|
};
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
logger:
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
431
|
+
if (ctx instanceof FabricContractContext) {
|
|
432
|
+
Object.assign(baseFlags, {
|
|
433
|
+
logger: ctx.logger,
|
|
434
|
+
identity: ctx.identity,
|
|
435
|
+
correlationId: ctx.stub.getTxID(),
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
else {
|
|
439
|
+
const LOG = !(ctx instanceof FabricContractContext)
|
|
440
|
+
? ctx.logging.getLogger()
|
|
441
|
+
: ctx.logger;
|
|
442
|
+
LOG.info(`In flags`);
|
|
443
|
+
LOG.info(`${operation} - ${model.name} - ${JSON.stringify(flags)} - ${JSON.stringify(ctx)}`);
|
|
444
|
+
LOG.info(`flags: ${Object.keys(flags)}`);
|
|
445
|
+
LOG.info(`ctx: ${ctx.constructor.name}`);
|
|
446
|
+
Object.assign(baseFlags, {
|
|
449
447
|
identity: ctx.clientIdentity,
|
|
450
|
-
logger:
|
|
448
|
+
logger: new ContractLogger(this, undefined, ctx),
|
|
449
|
+
correlationId: ctx.stub.getTxID(),
|
|
451
450
|
});
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
return Object.assign(await super.flags(operation, model, baseFlags, ...args), {
|
|
456
|
-
stub: ctx.stub,
|
|
457
|
-
identity: (ctx.clientIdentity ??
|
|
458
|
-
fabricCtx.identity),
|
|
459
|
-
logger: fabricCtx.logger,
|
|
460
|
-
correlationId: ctx.stub.getTxID(),
|
|
461
|
-
});
|
|
451
|
+
}
|
|
452
|
+
flags = (await super.flags(operation, model, baseFlags, ...args));
|
|
453
|
+
return flags;
|
|
462
454
|
}
|
|
463
455
|
/**
|
|
464
456
|
* @description Creates an index for a model
|
|
@@ -560,9 +552,8 @@ export class FabricContractAdapter extends CouchDBAdapter {
|
|
|
560
552
|
* FabricContractAdapter-->>Caller: results
|
|
561
553
|
*/
|
|
562
554
|
async raw(rawInput, ...args) {
|
|
563
|
-
const {
|
|
555
|
+
const { log, ctxArgs, stub } = this.logCtx(args, this.raw);
|
|
564
556
|
const docsOnly = typeof ctxArgs[0] === "boolean" ? ctxArgs.shift() : false;
|
|
565
|
-
const { stub } = ctx;
|
|
566
557
|
const { skip, limit } = rawInput;
|
|
567
558
|
let iterator;
|
|
568
559
|
if (limit || skip) {
|
|
@@ -584,9 +575,6 @@ export class FabricContractAdapter extends CouchDBAdapter {
|
|
|
584
575
|
Statement() {
|
|
585
576
|
return new FabricStatement(this);
|
|
586
577
|
}
|
|
587
|
-
async Sequence(options) {
|
|
588
|
-
return new FabricContractSequence(options, this);
|
|
589
|
-
}
|
|
590
578
|
async createAll(tableName, id, model, ...args) {
|
|
591
579
|
if (id.length !== model.length)
|
|
592
580
|
throw new InternalError("Ids and models must have the same length");
|
|
@@ -693,6 +681,28 @@ export class FabricContractAdapter extends CouchDBAdapter {
|
|
|
693
681
|
parseError(err, reason) {
|
|
694
682
|
return FabricContractAdapter.parseError(reason || err);
|
|
695
683
|
}
|
|
684
|
+
logCtx(args, method) {
|
|
685
|
+
return FabricContractAdapter.logCtx.call(this, args, method);
|
|
686
|
+
}
|
|
687
|
+
static logCtx(args, method) {
|
|
688
|
+
if (args.length < 1)
|
|
689
|
+
throw new InternalError("No context provided");
|
|
690
|
+
const ctx = args.pop();
|
|
691
|
+
if (!(ctx instanceof Context))
|
|
692
|
+
throw new InternalError("No context provided");
|
|
693
|
+
if (args.filter((a) => a instanceof Context).length > 1)
|
|
694
|
+
throw new Error("here");
|
|
695
|
+
const log = (this
|
|
696
|
+
? ctx.logger.for(this).for(method)
|
|
697
|
+
: ctx.logger.clear().for(this).for(method));
|
|
698
|
+
return {
|
|
699
|
+
ctx: ctx,
|
|
700
|
+
log: method ? log.for(method) : log,
|
|
701
|
+
stub: ctx.stub,
|
|
702
|
+
identity: ctx.identity,
|
|
703
|
+
ctxArgs: [...args, ctx],
|
|
704
|
+
};
|
|
705
|
+
}
|
|
696
706
|
static parseError(err) {
|
|
697
707
|
// if (
|
|
698
708
|
// MISSING_PRIVATE_DATA_REGEX.test(
|