@decaf-ts/for-fabric 0.3.47 → 0.3.49
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/lib/contract/models/OtherAudit.cjs +33 -18
- package/lib/contract/models/OtherAudit.d.ts +5 -3
- package/lib/contract/models/OtherAudit.js.map +1 -1
- package/lib/contract/models/OtherBatchShared.cjs +4 -2
- package/lib/contract/models/OtherBatchShared.js.map +1 -1
- package/lib/contract/models/decorators-private.cjs +33 -10
- package/lib/contract/models/decorators-private.js.map +1 -1
- package/lib/contract/models/history-dec.cjs +18 -4
- package/lib/contract/models/history-dec.d.ts +1 -1
- package/lib/contract/models/history-dec.js.map +1 -1
- package/lib/contracts/ContractAdapter.cjs +114 -59
- package/lib/contracts/ContractAdapter.d.ts +0 -9
- package/lib/contracts/ContractAdapter.js.map +1 -1
- package/lib/esm/contract/models/OtherAudit.d.ts +5 -3
- package/lib/esm/contract/models/OtherAudit.js +35 -20
- package/lib/esm/contract/models/OtherAudit.js.map +1 -1
- package/lib/esm/contract/models/OtherBatchShared.js +4 -2
- package/lib/esm/contract/models/OtherBatchShared.js.map +1 -1
- package/lib/esm/contract/models/decorators-private.js +33 -10
- package/lib/esm/contract/models/decorators-private.js.map +1 -1
- package/lib/esm/contract/models/history-dec.d.ts +1 -1
- package/lib/esm/contract/models/history-dec.js +19 -5
- package/lib/esm/contract/models/history-dec.js.map +1 -1
- package/lib/esm/contracts/ContractAdapter.d.ts +0 -9
- package/lib/esm/contracts/ContractAdapter.js +116 -61
- package/lib/esm/contracts/ContractAdapter.js.map +1 -1
- package/lib/esm/version.d.ts +1 -1
- package/lib/esm/version.js +1 -1
- package/lib/version.cjs +1 -1
- package/lib/version.d.ts +1 -1
- package/package.json +1 -1
|
@@ -20,7 +20,7 @@ const index_1 = require("./../../shared/index.cjs");
|
|
|
20
20
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
21
21
|
function uuidSeed(m, ...args) {
|
|
22
22
|
try {
|
|
23
|
-
return `${m.model}${m.action}${m.userId}${m.transaction}${JSON.stringify(m.diffs)}`;
|
|
23
|
+
return `${m.model}${m.action}${m.recordId}${m.userId}${m.transaction}${JSON.stringify(m.diffs)}`;
|
|
24
24
|
}
|
|
25
25
|
catch (e) {
|
|
26
26
|
throw new db_decorators_1.InternalError(`Failed to generate deterministic uuid: ${e}`);
|
|
@@ -41,53 +41,68 @@ __decorate([
|
|
|
41
41
|
], OtherAudit.prototype, "id", void 0);
|
|
42
42
|
__decorate([
|
|
43
43
|
(0, core_1.column)(),
|
|
44
|
-
(0,
|
|
44
|
+
(0, decorator_validation_1.required)(),
|
|
45
|
+
(0, db_decorators_1.readonly)(),
|
|
45
46
|
(0, core_1.index)([core_1.OrderDirection.ASC, core_1.OrderDirection.DSC]),
|
|
46
|
-
(0, decoration_1.description)("
|
|
47
|
+
(0, decoration_1.description)("model/entity affected by the action"),
|
|
48
|
+
(0, core_1.defaultQueryAttr)(),
|
|
47
49
|
__metadata("design:type", String)
|
|
48
|
-
], OtherAudit.prototype, "
|
|
50
|
+
], OtherAudit.prototype, "model", void 0);
|
|
49
51
|
__decorate([
|
|
50
52
|
(0, core_1.column)(),
|
|
51
53
|
(0, decorator_validation_1.required)(),
|
|
52
54
|
(0, db_decorators_1.readonly)(),
|
|
55
|
+
(0, decorator_validation_1.type)(String),
|
|
53
56
|
(0, core_1.index)([core_1.OrderDirection.ASC, core_1.OrderDirection.DSC]),
|
|
54
|
-
(0, decoration_1.description)("
|
|
57
|
+
(0, decoration_1.description)("Type of action performed by the user."),
|
|
58
|
+
(0, core_1.defaultQueryAttr)(),
|
|
55
59
|
__metadata("design:type", String)
|
|
56
|
-
], OtherAudit.prototype, "
|
|
60
|
+
], OtherAudit.prototype, "action", void 0);
|
|
57
61
|
__decorate([
|
|
62
|
+
(0, decoration_1.description)("Id from the model recorded in the audit"),
|
|
58
63
|
(0, core_1.column)(),
|
|
64
|
+
(0, core_1.index)([core_1.OrderDirection.ASC, core_1.OrderDirection.DSC]),
|
|
59
65
|
(0, decorator_validation_1.required)(),
|
|
60
|
-
(0,
|
|
66
|
+
(0, core_1.defaultQueryAttr)(),
|
|
67
|
+
__metadata("design:type", String)
|
|
68
|
+
], OtherAudit.prototype, "recordId", void 0);
|
|
69
|
+
__decorate([
|
|
70
|
+
(0, core_1.column)(),
|
|
71
|
+
(0, core_1.createdBy)(),
|
|
61
72
|
(0, core_1.index)([core_1.OrderDirection.ASC, core_1.OrderDirection.DSC]),
|
|
62
|
-
(0, decoration_1.description)("
|
|
73
|
+
(0, decoration_1.description)("Identifier of the user who performed the action."),
|
|
74
|
+
(0, core_1.defaultQueryAttr)(),
|
|
63
75
|
__metadata("design:type", String)
|
|
64
|
-
], OtherAudit.prototype, "
|
|
76
|
+
], OtherAudit.prototype, "userId", void 0);
|
|
65
77
|
__decorate([
|
|
66
78
|
(0, core_1.column)(),
|
|
67
79
|
(0, decorator_validation_1.required)(),
|
|
68
80
|
(0, db_decorators_1.readonly)(),
|
|
69
|
-
(0,
|
|
70
|
-
(0,
|
|
81
|
+
(0, decorator_validation_1.type)(String),
|
|
82
|
+
(0, core_1.index)([core_1.OrderDirection.ASC, core_1.OrderDirection.DSC]),
|
|
83
|
+
(0, decoration_1.description)("Group or role of the user who performed the action."),
|
|
71
84
|
__metadata("design:type", String)
|
|
72
|
-
], OtherAudit.prototype, "
|
|
85
|
+
], OtherAudit.prototype, "userGroup", void 0);
|
|
73
86
|
__decorate([
|
|
74
87
|
(0, core_1.column)(),
|
|
75
88
|
(0, decorator_validation_1.required)(),
|
|
76
89
|
(0, db_decorators_1.readonly)(),
|
|
77
|
-
(0,
|
|
78
|
-
(0,
|
|
79
|
-
(0, decoration_1.description)("Type of action performed by the user."),
|
|
90
|
+
(0, index_1.transactionId)(),
|
|
91
|
+
(0, decoration_1.description)("the transaction the audit record was created in"),
|
|
80
92
|
__metadata("design:type", String)
|
|
81
|
-
], OtherAudit.prototype, "
|
|
93
|
+
], OtherAudit.prototype, "transaction", void 0);
|
|
82
94
|
__decorate([
|
|
83
95
|
(0, core_1.column)(),
|
|
84
96
|
(0, db_decorators_1.readonly)(),
|
|
85
|
-
(0, decorator_validation_1.required)(),
|
|
86
97
|
(0, db_decorators_1.serialize)(),
|
|
87
|
-
(0, decorator_validation_1.type)(Object),
|
|
88
98
|
(0, decoration_1.description)("the diffs for the action."),
|
|
89
99
|
__metadata("design:type", Object)
|
|
90
100
|
], OtherAudit.prototype, "diffs", void 0);
|
|
101
|
+
__decorate([
|
|
102
|
+
(0, index_1.ownedBy)(),
|
|
103
|
+
(0, decoration_1.description)("the owner (msp) of the audit log"),
|
|
104
|
+
__metadata("design:type", String)
|
|
105
|
+
], OtherAudit.prototype, "owner", void 0);
|
|
91
106
|
exports.OtherAudit = OtherAudit = __decorate([
|
|
92
107
|
(0, decoration_1.description)("Logs user activity for auditing purposes."),
|
|
93
108
|
(0, db_decorators_1.BlockOperations)([
|
|
@@ -3,11 +3,13 @@ import { BaseModel } from "./BaseModel";
|
|
|
3
3
|
import { AuditOperations } from "./constants";
|
|
4
4
|
export declare class OtherAudit extends BaseModel {
|
|
5
5
|
id: string;
|
|
6
|
+
model: string;
|
|
7
|
+
action: AuditOperations;
|
|
8
|
+
recordId: string;
|
|
6
9
|
userId: string;
|
|
7
10
|
userGroup: string;
|
|
8
|
-
model: string;
|
|
9
11
|
transaction: string;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
+
diffs?: Record<string, any>;
|
|
13
|
+
owner: string;
|
|
12
14
|
constructor(model?: ModelArg<OtherAudit>);
|
|
13
15
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OtherAudit.js","sourceRoot":"","sources":["../../../src/contract/models/OtherAudit.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yEAKwC;AACxC,2DAMiC;AACjC,qDAAyD;AACzD,
|
|
1
|
+
{"version":3,"file":"OtherAudit.js","sourceRoot":"","sources":["../../../src/contract/models/OtherAudit.ts"],"names":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AC;IACxD,IAAA,+BAAe,EAAC;QACf,wBAAwB;QACxB,6BAAa,CAAC,MAAM;QACpB,6BAAa,CAAC,MAAM;KACrB,CAAC;IACD,IAAA,iBAAI,EAAC,qBAAa,CAAC;IACnB,IAAA,kBAAU,EAAC,IAAA,2BAAmB,EAAC,iBAAiB,CAAC,CAAC;IAClD,IAAA,YAAK,EAAC,OAAO,CAAC;IACd,IAAA,4BAAK,GAAE;;GACK,UAAU,CAkEtB"}
|
|
@@ -16,7 +16,7 @@ const constants_1 = require("./constants.cjs");
|
|
|
16
16
|
const db_decorators_1 = require("@decaf-ts/db-decorators");
|
|
17
17
|
const decoration_1 = require("@decaf-ts/decoration");
|
|
18
18
|
const BaseIdentifiedModel_1 = require("./BaseIdentifiedModel.cjs");
|
|
19
|
-
const
|
|
19
|
+
const decorators_private_1 = require("./decorators-private.cjs");
|
|
20
20
|
const gtin_1 = require("./gtin.cjs");
|
|
21
21
|
const index_1 = require("./../../shared/index.cjs");
|
|
22
22
|
const history_dec_1 = require("./history-dec.cjs");
|
|
@@ -30,7 +30,7 @@ exports.OtherBatchShared = OtherBatchShared;
|
|
|
30
30
|
__decorate([
|
|
31
31
|
(0, core_1.pk)(),
|
|
32
32
|
(0, history_dec_1.historyDec)(),
|
|
33
|
-
(0,
|
|
33
|
+
(0, decorators_private_1.audit)(OtherBatchShared),
|
|
34
34
|
(0, index_1.mirror)("mirror-collection", "org-b"),
|
|
35
35
|
(0, db_decorators_1.composed)(["productCode", "batchNumber"], ":"),
|
|
36
36
|
(0, decoration_1.description)("Unique identifier composed of product code and batch number."),
|
|
@@ -47,6 +47,7 @@ __decorate([
|
|
|
47
47
|
,
|
|
48
48
|
(0, core_1.index)([core_1.OrderDirection.ASC, core_1.OrderDirection.DSC]),
|
|
49
49
|
(0, decoration_1.description)("Code of the product associated with this batch."),
|
|
50
|
+
(0, core_1.defaultQueryAttr)(),
|
|
50
51
|
__metadata("design:type", String)
|
|
51
52
|
], OtherBatchShared.prototype, "productCode", void 0);
|
|
52
53
|
__decorate([
|
|
@@ -55,6 +56,7 @@ __decorate([
|
|
|
55
56
|
(0, decorator_validation_1.pattern)(constants_1.BatchPattern),
|
|
56
57
|
(0, core_1.index)([core_1.OrderDirection.ASC, core_1.OrderDirection.DSC]),
|
|
57
58
|
(0, decoration_1.description)("Batch number assigned to the product."),
|
|
59
|
+
(0, core_1.defaultQueryAttr)(),
|
|
58
60
|
__metadata("design:type", String)
|
|
59
61
|
], OtherBatchShared.prototype, "batchNumber", void 0);
|
|
60
62
|
__decorate([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OtherBatchShared.js","sourceRoot":"","sources":["../../../src/contract/models/OtherBatchShared.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,yEAAgF;AAChF,
|
|
1
|
+
{"version":3,"file":"OtherBatchShared.js","sourceRoot":"","sources":["../../../src/contract/models/OtherBatchShared.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,yEAAgF;AAChF,yCAOwB;AACxB,+CAAwD;AACxD,2DAKiC;AACjC,qDAAyD;AACzD,mEAA4D;AAC5D,iEAA6C;AAC7C,qCAA8B;AAC9B,oDAK4B;AAC5B,mDAA2C;AAQpC,IAAM,gBAAgB,GAAtB,MAAM,gBAAiB,SAAQ,yCAAmB;IA2EvD,YAAY,KAAkC;QAC5C,KAAK,CAAC,KAAK,CAAC,CAAC;QAHf,gBAAW,GAAY,KAAK,CAAC;IAI7B,CAAC;CACF,CAAA;AA9EY,4CAAgB;AAO3B;IANC,IAAA,SAAE,GAAE;IACJ,IAAA,wBAAU,GAAE;IACZ,IAAA,0BAAK,EAAC,gBAAgB,CAAC;IACvB,IAAA,cAAM,EAAC,mBAAmB,EAAE,OAAO,CAAC;IACpC,IAAA,wBAAQ,EAAC,CAAC,aAAa,EAAE,aAAa,CAAC,EAAE,GAAG,CAAC;IAC7C,IAAA,wBAAW,EAAC,8DAA8D,CAAC;;4CAChE;AAYZ;IAVC,IAAA,WAAI,GAAE;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EAAC,8BAA8B,CAAC;;8DACd;AAI9B;IAFC,IAAA,aAAM,GAAE;IACR,IAAA,wBAAW,EAAC,8BAA8B,CAAC;;8DACd;AAI9B;IAFC,IAAA,aAAM,GAAE;IACR,IAAA,wBAAW,EAAC,8BAA8B,CAAC;;8DACd;AAI9B;IAFC,IAAA,aAAM,GAAE;IACR,IAAA,wBAAW,EAAC,8BAA8B,CAAC;;8DACd;AAK9B;IAHC,IAAA,aAAM,GAAE;IACR,IAAA,YAAK,EAAC,CAAC,qBAAc,CAAC,GAAG,EAAE,qBAAc,CAAC,GAAG,CAAC,CAAC;IAC/C,IAAA,wBAAW,EAAC,iDAAiD,CAAC;;qDAClC;2BAzElB,gBAAgB;IAN5B,IAAA,kBAAU,EAAC,IAAA,2BAAmB,EAAC,iBAAiB,CAAC,CAAC;IAClD,IAAA,wBAAW,EAAC,4BAA4B,CAAC;IACzC,IAAA,iBAAI,EAAC,qBAAa,CAAC;IACnB,IAAA,+BAAe,EAAC,CAAC,6BAAa,CAAC,MAAM,CAAC,CAAC;IACvC,IAAA,YAAK,EAAC,oBAAoB,CAAC;IAC3B,IAAA,4BAAK,GAAE;;GACK,gBAAgB,CA8E5B"}
|
|
@@ -44,13 +44,22 @@ async function createAuditHandler(context, data, key, model) {
|
|
|
44
44
|
if (!context.identity || !context.identity.getID)
|
|
45
45
|
throw new db_decorators_1.InternalError(`Lost context apparently for audit`);
|
|
46
46
|
model = await (0, decorators_1.populateRelations)(model, context, this._overrides);
|
|
47
|
+
let roles = [];
|
|
48
|
+
try {
|
|
49
|
+
roles = JSON.parse(context.identity.getAttributeValue("roles"));
|
|
50
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
51
|
+
}
|
|
52
|
+
catch (e) {
|
|
53
|
+
roles = ["unknown"];
|
|
54
|
+
}
|
|
47
55
|
const toCreate = new OtherAudit_1.OtherAudit({
|
|
48
|
-
|
|
56
|
+
recordId: decorator_validation_1.Model.pk(model, true),
|
|
57
|
+
userGroup: roles.join(", "),
|
|
49
58
|
userId: context.identity.getID(),
|
|
50
59
|
model: decorator_validation_1.Model.tableName(data.class),
|
|
51
60
|
transaction: context.stub.getTxID(),
|
|
52
61
|
action: db_decorators_1.OperationKeys.CREATE,
|
|
53
|
-
diffs: new this.class()
|
|
62
|
+
diffs: model.compare(new this.class()),
|
|
54
63
|
});
|
|
55
64
|
const audit = await repo.override(this._overrides).create(toCreate, context);
|
|
56
65
|
context.logger.info(`Audit log for ${db_decorators_1.OperationKeys.CREATE} of ${decorator_validation_1.Model.tableName(this.class)} created: ${audit.id}: ${JSON.stringify(audit, undefined, 2)}`);
|
|
@@ -93,14 +102,19 @@ async function updateAuditHandler(context, data, key, model, oldModel) {
|
|
|
93
102
|
const repo = core_1.Repository.forModel(OtherAudit_1.OtherAudit);
|
|
94
103
|
if (!context.identity || !context.identity.getID)
|
|
95
104
|
throw new db_decorators_1.InternalError(`Lost context apparently for audit`);
|
|
96
|
-
// At onUpdate time `model` still has all private fields (not yet stripped by
|
|
97
|
-
// adapter.revert). Normalise relation arrays to ID strings on both sides so
|
|
98
|
-
// that { id: "x" } and "x" compare as equal and unchanged relations produce
|
|
99
|
-
// no spurious diff.
|
|
100
105
|
const normalizedModel = normalizeRelationsForAudit(model);
|
|
101
106
|
const normalizedOldModel = normalizeRelationsForAudit(oldModel);
|
|
107
|
+
let roles = [];
|
|
108
|
+
try {
|
|
109
|
+
roles = JSON.parse(context.identity.getAttributeValue("roles"));
|
|
110
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
111
|
+
}
|
|
112
|
+
catch (e) {
|
|
113
|
+
roles = ["unknown"];
|
|
114
|
+
}
|
|
102
115
|
const toCreate = new OtherAudit_1.OtherAudit({
|
|
103
|
-
|
|
116
|
+
recordId: decorator_validation_1.Model.pk(model, true),
|
|
117
|
+
userGroup: roles.join(", "),
|
|
104
118
|
userId: context.identity.getID(),
|
|
105
119
|
model: decorator_validation_1.Model.tableName(data.class),
|
|
106
120
|
transaction: context.stub.getTxID(),
|
|
@@ -112,15 +126,24 @@ async function updateAuditHandler(context, data, key, model, oldModel) {
|
|
|
112
126
|
}
|
|
113
127
|
async function deleteAuditHandler(context, data, key, model) {
|
|
114
128
|
if (!context.identity || !context.identity.getID)
|
|
115
|
-
throw new db_decorators_1.InternalError(`Lost context
|
|
129
|
+
throw new db_decorators_1.InternalError(`Lost context apparently. no getId in identity`);
|
|
116
130
|
model = await (0, decorators_1.populateRelations)(model, context, this._overrides);
|
|
131
|
+
let roles = [];
|
|
132
|
+
try {
|
|
133
|
+
roles = JSON.parse(context.identity.getAttributeValue("roles"));
|
|
134
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
135
|
+
}
|
|
136
|
+
catch (e) {
|
|
137
|
+
roles = ["unknown"];
|
|
138
|
+
}
|
|
117
139
|
const toCreate = new OtherAudit_1.OtherAudit({
|
|
118
|
-
|
|
140
|
+
recordId: decorator_validation_1.Model.pk(model, true),
|
|
141
|
+
userGroup: roles.join(", "),
|
|
119
142
|
userId: context.identity.getID(),
|
|
120
143
|
model: decorator_validation_1.Model.tableName(data.class),
|
|
121
144
|
transaction: context.stub.getTxID(),
|
|
122
145
|
action: db_decorators_1.OperationKeys.DELETE,
|
|
123
|
-
diffs:
|
|
146
|
+
diffs: new this.class().compare(model),
|
|
124
147
|
});
|
|
125
148
|
const repo = core_1.Repository.forModel(OtherAudit_1.OtherAudit);
|
|
126
149
|
const audit = await repo.override(this._overrides).create(toCreate, context);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decorators-private.js","sourceRoot":"","sources":["../../../src/contract/models/decorators-private.ts"],"names":[],"mappings":";;AAeA,oEAsCC;AAED,
|
|
1
|
+
{"version":3,"file":"decorators-private.js","sourceRoot":"","sources":["../../../src/contract/models/decorators-private.ts"],"names":[],"mappings":";;AAeA,oEAsCC;AAED,gDAuCC;AAmCD,gDAwCC;AAED,gDAqCC;AAMD,sBAUC;AAhOD,yEAAuD;AACvD,q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C,EAC5C,IAAA,wBAAQ,EAAC,kBAAyB,EAAE,IAAI,CAAC,EACzC,IAAA,2BAAW,EAAC,kBAAyB,EAAE,IAAI,CAAC,EAC5C,IAAA,qBAAQ,EAAC,OAAO,EAAE,IAAI,CAAC,CACxB,CAAC;AACJ,CAAC"}
|
|
@@ -52,8 +52,15 @@ async function updateHistoryHandler(context, data, key, model, oldModel) {
|
|
|
52
52
|
version,
|
|
53
53
|
record,
|
|
54
54
|
});
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
const overrides = {
|
|
56
|
+
stub: context.stub,
|
|
57
|
+
identity: context.identity,
|
|
58
|
+
logger: context.logger,
|
|
59
|
+
fullySegregated: true,
|
|
60
|
+
};
|
|
61
|
+
const historyCtx = await this.adapter.context(db_decorators_1.OperationKeys.CREATE, overrides, History_1.History);
|
|
62
|
+
const history = await repo.create(toCreate, historyCtx);
|
|
63
|
+
context.logger.info(`History for ${table}'s ${pk.toString()} version ${version} stored with id ${history.id}`);
|
|
57
64
|
}
|
|
58
65
|
async function deleteHistoryHandler(context, data, key, model) {
|
|
59
66
|
if (!context.identity || !context.identity.getID)
|
|
@@ -74,8 +81,15 @@ async function deleteHistoryHandler(context, data, key, model) {
|
|
|
74
81
|
version,
|
|
75
82
|
record,
|
|
76
83
|
});
|
|
77
|
-
|
|
78
|
-
|
|
84
|
+
const overrides = {
|
|
85
|
+
stub: context.stub,
|
|
86
|
+
identity: context.identity,
|
|
87
|
+
logger: context.logger,
|
|
88
|
+
fullySegregated: true,
|
|
89
|
+
};
|
|
90
|
+
const historyCtx = await this.adapter.context(db_decorators_1.OperationKeys.CREATE, overrides, History_1.History);
|
|
91
|
+
const history = await repo.create(toCreate, historyCtx);
|
|
92
|
+
context.logger.info(`History for ${table}'s ${pk.toString()} version ${version} stored with id ${history.id}`);
|
|
79
93
|
}
|
|
80
94
|
function historyDec() {
|
|
81
95
|
return (0, decoration_1.apply)((0, db_decorators_1.onUpdate)(updateHistoryHandler, {}, { priority: 99 }), (0, db_decorators_1.afterDelete)(deleteHistoryHandler, {}, { priority: 99 }), (0, decoration_1.metadata)("history", true));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Model } from "@decaf-ts/decorator-validation";
|
|
2
2
|
import { Repository } from "@decaf-ts/core";
|
|
3
|
-
import {
|
|
3
|
+
import type { FabricContractContext } from "../../contracts/index";
|
|
4
4
|
export declare function updateHistoryHandler<M extends Model, R extends Repository<M, any>>(this: R, context: FabricContractContext, data: any, key: keyof M, model: M, oldModel: M): Promise<void>;
|
|
5
5
|
export declare function deleteHistoryHandler<M extends Model, R extends Repository<M, any>>(this: R, context: FabricContractContext, data: any, key: keyof M, model: M): Promise<void>;
|
|
6
6
|
export declare function historyDec(): (target: object, propertyKey?: string | symbol | unknown, descriptor?: PropertyDescriptor | number) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"history-dec.js","sourceRoot":"","sources":["../../../src/contract/models/history-dec.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"history-dec.js","sourceRoot":"","sources":["../../../src/contract/models/history-dec.ts"],"names":[],"mappings":";;AAwCA,oDAgDC;AAED,oDA8CC;AAED,gCAMC;AAhJD,yEAAuD;AACvD,yCAA4C;AAC5C,qDAA8E;AAC9E,2DAOiC;AACjC,iDAAiD;AAKjD,2CAAoC;AAEpC;;;;;;;;;;GAUG;AACH,SAAS,YAAY,CAAC,KAAY;IAChC,MAAM,IAAI,GAAG,qBAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,WAAiC,CAAC,CAAC;IACnE,IAAI,CAAC,IAAI;QAAE,OAAO,SAAS,CAAC;IAC5B,MAAM,WAAW,GAAI,IAA4B,CAAC,sBAAM,CAAC,OAAO,CAAC,CAAC;IAClE,IAAI,CAAC,WAAW,IAAI,OAAO,WAAW,KAAK,QAAQ;QAAE,OAAO,SAAS,CAAC;IACtE,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,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,GAAG,iBAAU,CAAC,QAAQ,CAAC,iBAAO,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACpE,MAAM,QAAQ,GAAG,IAAI,iBAAO,CAAC;QAC3B,KAAK;QACL,GAAG,EAAE,EAAE;QACP,OAAO;QACP,MAAM;KACP,CAAC,CAAC;IACH,MAAM,SAAS,GAAG;QAChB,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,QAAQ,EAAE,OAAO,CAAC,QAAQ;QAC1B,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,eAAe,EAAE,IAAI;KACU,CAAC;IAElC,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CAC3C,6BAAa,CAAC,MAAM,EACpB,SAAS,EACT,iBAAO,CACR,CAAC;IACF,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;IACxD,OAAO,CAAC,MAAM,CAAC,IAAI,CACjB,eAAe,KAAK,MAAM,EAAE,CAAC,QAAQ,EAAE,YAAY,OAAO,mBAAmB,OAAO,CAAC,EAAE,EAAE,CAC1F,CAAC;AACJ,CAAC;AAED,SAAgB,UAAU;IACxB,OAAO,IAAA,kBAAK,EACV,IAAA,wBAAQ,EAAC,oBAA2B,EAAE,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,EAC3D,IAAA,2BAAW,EAAC,oBAA2B,EAAE,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,EAC9D,IAAA,qBAAQ,EAAC,SAAS,EAAE,IAAI,CAAC,CAC1B,CAAC;AACJ,CAAC"}
|
|
@@ -261,55 +261,84 @@ class FabricContractAdapter extends for_couchdb_1.CouchDBAdapter {
|
|
|
261
261
|
Object.assign(model, await this.forPrivate(col).readState(composedKey, ctx));
|
|
262
262
|
return model;
|
|
263
263
|
}
|
|
264
|
-
/**
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
async readAll
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
264
|
+
// /**
|
|
265
|
+
// * @description Retrieves multiple records from the database
|
|
266
|
+
// * @summary Fetches multiple records with the given IDs from the specified table
|
|
267
|
+
// * @param {string} tableName - The name of the table to read from
|
|
268
|
+
// * @param id - The identifiers of the records to retrieve
|
|
269
|
+
// * @param {...any[]} args - Additional arguments specific to the adapter implementation
|
|
270
|
+
// * @return A promise that resolves to an array of retrieved records
|
|
271
|
+
// */
|
|
272
|
+
// override async readAll<M extends Model>(
|
|
273
|
+
// clazz: Constructor<M>,
|
|
274
|
+
// id: PrimaryKeyType[],
|
|
275
|
+
// ...args: ContextualArgs<Context<FabricContractFlags>>
|
|
276
|
+
// ): Promise<Record<string, any>[]> {
|
|
277
|
+
// const { log, ctx } = this.logCtx(args, this.readAll);
|
|
278
|
+
// const tableName = Model.tableName(clazz);
|
|
279
|
+
// log.debug(`Reading ${id.length} entries ${tableName} table`);
|
|
280
|
+
// const breakOnSingleFailure = ctx.get("breakOnSingleFailureInBulk") ?? true;
|
|
281
|
+
// const continueOnError = !breakOnSingleFailure;
|
|
282
|
+
//
|
|
283
|
+
// const mirrorCollection = ctx.getOrUndefined("mirrorCollection") as
|
|
284
|
+
// | string
|
|
285
|
+
// | undefined;
|
|
286
|
+
// const isMirror = ctx.getOrUndefined("mirror") as boolean | undefined;
|
|
287
|
+
//
|
|
288
|
+
// const readMirror = async <M extends Model>(
|
|
289
|
+
// clazz: Constructor<M>,
|
|
290
|
+
// id: PrimaryKeyType,
|
|
291
|
+
// ...args: ContextualArgs<Context<FabricContractFlags>>
|
|
292
|
+
// ) => {
|
|
293
|
+
// if (!mirrorCollection)
|
|
294
|
+
// throw new BadRequestError("Missing mirror collection for mirror read");
|
|
295
|
+
// try {
|
|
296
|
+
// const { ctx, log } = this.logCtx(args, readMirror);
|
|
297
|
+
// log.info(`in ADAPTER read with args ${args}`);
|
|
298
|
+
// const tableName = Model.tableName(clazz);
|
|
299
|
+
//
|
|
300
|
+
// const composedKey = ctx.stub.createCompositeKey(tableName, [
|
|
301
|
+
// String(id),
|
|
302
|
+
// ]);
|
|
303
|
+
//
|
|
304
|
+
// return await this.forPrivate(mirrorCollection).readState(
|
|
305
|
+
// composedKey,
|
|
306
|
+
// ctx
|
|
307
|
+
// );
|
|
308
|
+
// } catch (e: unknown) {
|
|
309
|
+
// throw this.parseError(e as Error);
|
|
310
|
+
// }
|
|
311
|
+
// };
|
|
312
|
+
//
|
|
313
|
+
// try {
|
|
314
|
+
// const tasks = id.map(
|
|
315
|
+
// (i) => () =>
|
|
316
|
+
// isMirror && mirrorCollection
|
|
317
|
+
// ? readMirror(
|
|
318
|
+
// clazz,
|
|
319
|
+
// i,
|
|
320
|
+
// ...args,
|
|
321
|
+
// ctx.override({ noEmitSingle: true })
|
|
322
|
+
// )
|
|
323
|
+
// : this.read(clazz, i, ...args, ctx.override({ noEmitSingle: true }))
|
|
324
|
+
// );
|
|
325
|
+
//
|
|
326
|
+
// const rawResult = continueOnError
|
|
327
|
+
// ? await promiseSequence(tasks, true)
|
|
328
|
+
// : await promiseSequence(tasks);
|
|
329
|
+
// return resolveBulkSequenceResult(
|
|
330
|
+
// rawResult,
|
|
331
|
+
// continueOnError,
|
|
332
|
+
// log,
|
|
333
|
+
// BulkCrudOperationKeys.READ_ALL
|
|
334
|
+
// );
|
|
335
|
+
// } catch (e) {
|
|
336
|
+
// throw this.parseError(e as Error);
|
|
337
|
+
// } finally {
|
|
338
|
+
// ctx.put("mirror" as any, undefined);
|
|
339
|
+
// ctx.put("mirrorCollection" as any, undefined);
|
|
340
|
+
// }
|
|
341
|
+
// }
|
|
313
342
|
/**
|
|
314
343
|
* @description Updates a record in the state database
|
|
315
344
|
* @summary Serializes a model and updates it in the Fabric state database
|
|
@@ -366,7 +395,7 @@ class FabricContractAdapter extends for_couchdb_1.CouchDBAdapter {
|
|
|
366
395
|
* @return {Promise<Record<string, any>>} Promise resolving to the deleted record
|
|
367
396
|
*/
|
|
368
397
|
async delete(clazz, id, ...args) {
|
|
369
|
-
const { ctx } = this.logCtx(args, this.delete);
|
|
398
|
+
const { ctx, log } = this.logCtx(args, this.delete);
|
|
370
399
|
this.enforceMirrorAuthorization(clazz, ctx);
|
|
371
400
|
const tableName = decorator_validation_1.Model.tableName(clazz);
|
|
372
401
|
const composedKey = ctx.stub.createCompositeKey(tableName, [String(id)]);
|
|
@@ -386,8 +415,10 @@ class FabricContractAdapter extends for_couchdb_1.CouchDBAdapter {
|
|
|
386
415
|
model = ctx.isFullySegregated
|
|
387
416
|
? {}
|
|
388
417
|
: await this.readState(composedKey, ctx);
|
|
389
|
-
if (!ctx.isFullySegregated)
|
|
418
|
+
if (!ctx.isFullySegregated) {
|
|
419
|
+
log.debug(`Deleting entry ${composedKey} from public ledger`);
|
|
390
420
|
await this.deleteState(composedKey, ctx);
|
|
421
|
+
}
|
|
391
422
|
}
|
|
392
423
|
catch (e) {
|
|
393
424
|
throw this.parseError(e);
|
|
@@ -395,7 +426,9 @@ class FabricContractAdapter extends for_couchdb_1.CouchDBAdapter {
|
|
|
395
426
|
const collections = ctx.getReadCollections();
|
|
396
427
|
if (collections && collections.length) {
|
|
397
428
|
for (const col of collections) {
|
|
429
|
+
log.debug(`ensuring collection ${col} has entry for id ${composedKey} before deleting`);
|
|
398
430
|
Object.assign(model, await this.forPrivate(col).readState(composedKey, ctx));
|
|
431
|
+
log.debug(`Deleting private collection ${col} entry for id ${composedKey}`);
|
|
399
432
|
await this.forPrivate(col).deleteState(composedKey, ctx);
|
|
400
433
|
}
|
|
401
434
|
}
|
|
@@ -423,6 +456,8 @@ class FabricContractAdapter extends for_couchdb_1.CouchDBAdapter {
|
|
|
423
456
|
case "putState": {
|
|
424
457
|
// putState signature: (id: string, model: Record<string, any>, ctx: FabricContractContext)
|
|
425
458
|
const [id, model, ctx] = argsList;
|
|
459
|
+
const log = ctx.logger.for(prop);
|
|
460
|
+
log.debug(`Private write to ${collection} for ${id.toString()}`);
|
|
426
461
|
const data = Buffer.from(FabricContractAdapter.serializer.serialize(model, false));
|
|
427
462
|
await ctx.stub.putPrivateData(collection, id.toString(), data);
|
|
428
463
|
return model;
|
|
@@ -430,12 +465,16 @@ class FabricContractAdapter extends for_couchdb_1.CouchDBAdapter {
|
|
|
430
465
|
case "deleteState": {
|
|
431
466
|
// deleteState signature: (id: string, context: FabricContractContext)
|
|
432
467
|
const [id, ctx] = argsList;
|
|
468
|
+
const log = ctx.logger.for(prop);
|
|
469
|
+
log.debug(`Private delete on ${collection} for ${id.toString()}`);
|
|
433
470
|
await ctx.stub.deletePrivateData(collection, id.toString());
|
|
434
471
|
return;
|
|
435
472
|
}
|
|
436
473
|
case "readState": {
|
|
437
474
|
// readState signature: (id: string, ctx: FabricContractContext)
|
|
438
475
|
const [id, ctx] = argsList;
|
|
476
|
+
const log = ctx.logger.for(prop);
|
|
477
|
+
log.debug(`Private read from ${collection} for ${id.toString()}`);
|
|
439
478
|
const data = await ctx.stub.getPrivateData(collection, id);
|
|
440
479
|
if (!data || !data.toString().length)
|
|
441
480
|
throw new db_decorators_1.NotFoundError(`Record with id ${id} not found`);
|
|
@@ -447,12 +486,22 @@ class FabricContractAdapter extends for_couchdb_1.CouchDBAdapter {
|
|
|
447
486
|
}
|
|
448
487
|
}
|
|
449
488
|
case "queryResult": {
|
|
450
|
-
const [stub, rawInput] = argsList;
|
|
451
|
-
const
|
|
452
|
-
|
|
489
|
+
const [stub, rawInput, ...args] = argsList;
|
|
490
|
+
const { log } = thisArg["logCtx"](args, prop);
|
|
491
|
+
try {
|
|
492
|
+
log.debug(`Querying collection ${collection} for ${JSON.stringify(rawInput)}`);
|
|
493
|
+
const res = await stub.getPrivateDataQueryResult(collection, JSON.stringify(rawInput));
|
|
494
|
+
log.verbose(`iterator from collection ${collection} received`);
|
|
495
|
+
return res.iterator || res;
|
|
496
|
+
}
|
|
497
|
+
catch (e) {
|
|
498
|
+
log.error(e);
|
|
499
|
+
return [];
|
|
500
|
+
}
|
|
453
501
|
}
|
|
454
502
|
case "queryResultPaginated": {
|
|
455
|
-
const [stub, rawInput, limit, , bookmark] = argsList;
|
|
503
|
+
const [stub, rawInput, limit, , bookmark, ...args] = argsList;
|
|
504
|
+
const { log } = thisArg["logCtx"](args, prop);
|
|
456
505
|
// Fabric has no native pagination API for private data.
|
|
457
506
|
// Emulate it: query all matching records (with selector
|
|
458
507
|
// and sort preserved), locate the bookmark position in
|
|
@@ -461,8 +510,10 @@ class FabricContractAdapter extends for_couchdb_1.CouchDBAdapter {
|
|
|
461
510
|
delete query.limit;
|
|
462
511
|
delete query.skip;
|
|
463
512
|
delete query.bookmark;
|
|
513
|
+
log.debug(`Querying collection ${collection} for ${JSON.stringify(query)}`);
|
|
464
514
|
let iterator = await stub.getPrivateDataQueryResult(collection, JSON.stringify(query));
|
|
465
515
|
iterator = iterator.iterator || iterator;
|
|
516
|
+
log.verbose(`iterator from collection ${collection} received`);
|
|
466
517
|
// Collect all matching records from the iterator
|
|
467
518
|
const allResults = [];
|
|
468
519
|
while (true) {
|
|
@@ -714,16 +765,17 @@ class FabricContractAdapter extends for_couchdb_1.CouchDBAdapter {
|
|
|
714
765
|
if (limit || skip) {
|
|
715
766
|
delete rawInput["limit"];
|
|
716
767
|
delete rawInput["skip"];
|
|
717
|
-
log.debug(`Retrieving paginated iterator: limit: ${limit}/ skip: ${skip}`);
|
|
768
|
+
log.debug(`Retrieving public paginated iterator: limit: ${limit}/ skip: ${skip}`);
|
|
718
769
|
const response = (await this.queryResultPaginated(ctx.stub, rawInput, limit || Number.MAX_VALUE, skip?.toString(), bookmark, ...[ctx]));
|
|
719
770
|
resp.bookmark = response.metadata.bookmark;
|
|
720
771
|
iterator = response.iterator;
|
|
772
|
+
log.debug(`Retrieved public paging iterator`);
|
|
721
773
|
}
|
|
722
774
|
else {
|
|
723
|
-
log.debug("Retrieving iterator");
|
|
775
|
+
log.debug("Retrieving listing public iterator");
|
|
724
776
|
iterator = (await this.queryResult(ctx.stub, rawInput, ctx));
|
|
725
777
|
}
|
|
726
|
-
log.debug(
|
|
778
|
+
log.debug(`Retrieved public listing iterator`);
|
|
727
779
|
resp.docs = (await this.resultIterator(log, iterator));
|
|
728
780
|
log.debug(`returning ${Array.isArray(resp.docs) ? resp.docs.length : 1} results`);
|
|
729
781
|
}
|
|
@@ -748,7 +800,10 @@ class FabricContractAdapter extends for_couchdb_1.CouchDBAdapter {
|
|
|
748
800
|
segregatedInput["bookmark"] = bookmark;
|
|
749
801
|
const segregated = [];
|
|
750
802
|
for (const collection of collections) {
|
|
751
|
-
|
|
803
|
+
log.debug(`Querying from ${collection}`);
|
|
804
|
+
const fromCols = await this.forPrivate(collection).raw({ ...segregatedInput }, false, true, ...ctxArgs);
|
|
805
|
+
log.verbose(`received ${fromCols.length} from ${collection}`);
|
|
806
|
+
segregated.push(fromCols);
|
|
752
807
|
}
|
|
753
808
|
// choose the response with the most results
|
|
754
809
|
resp = segregated.reduce((acc, curr) => {
|