@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
|
@@ -8,12 +8,10 @@ const decorator_validation_1 = require("@decaf-ts/decorator-validation");
|
|
|
8
8
|
const ContractContext_1 = require("./ContractContext.cjs");
|
|
9
9
|
const db_decorators_1 = require("@decaf-ts/db-decorators");
|
|
10
10
|
const fabric_contract_api_1 = require("fabric-contract-api");
|
|
11
|
-
const logging_1 = require("@decaf-ts/logging");
|
|
12
11
|
const core_1 = require("@decaf-ts/core");
|
|
13
12
|
const FabricContractRepository_1 = require("./FabricContractRepository.cjs");
|
|
14
13
|
const FabricContractStatement_1 = require("./FabricContractStatement.cjs");
|
|
15
14
|
const FabricContractSequence_1 = require("./FabricContractSequence.cjs");
|
|
16
|
-
const errors_1 = require("./../shared/errors.cjs");
|
|
17
15
|
const constants_1 = require("./../shared/constants.cjs");
|
|
18
16
|
const SimpleDeterministicSerializer_1 = require("./../shared/SimpleDeterministicSerializer.cjs");
|
|
19
17
|
const FabricConstruction_1 = require("./FabricConstruction.cjs");
|
|
@@ -46,7 +44,7 @@ const decoration_1 = require("@decaf-ts/decoration");
|
|
|
46
44
|
*/
|
|
47
45
|
async function createdByOnFabricCreateUpdate(context, data, key, model) {
|
|
48
46
|
try {
|
|
49
|
-
const user = context.get("
|
|
47
|
+
const user = context.get("identity");
|
|
50
48
|
model[key] = user.getID();
|
|
51
49
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
52
50
|
}
|
|
@@ -95,7 +93,7 @@ async function pkFabricOnCreate(context, data, key, model) {
|
|
|
95
93
|
});
|
|
96
94
|
};
|
|
97
95
|
if (!data.name)
|
|
98
|
-
data.name =
|
|
96
|
+
data.name = decorator_validation_1.Model.sequenceName(model, "pk");
|
|
99
97
|
let sequence;
|
|
100
98
|
try {
|
|
101
99
|
sequence = (await this.adapter.Sequence(data));
|
|
@@ -152,15 +150,6 @@ class FabricContractAdapter extends for_couchdb_1.CouchDBAdapter {
|
|
|
152
150
|
*/
|
|
153
151
|
static { this.textDecoder = new TextDecoder("utf8"); }
|
|
154
152
|
static { this.serializer = new SimpleDeterministicSerializer_1.SimpleDeterministicSerializer(); }
|
|
155
|
-
/**
|
|
156
|
-
* @description Creates a logger for a specific chaincode context
|
|
157
|
-
* @summary Returns a ContractLogger instance configured for the current context
|
|
158
|
-
* @param {Ctx} ctx - The Fabric chaincode context
|
|
159
|
-
* @return {ContractLogger} The logger instance
|
|
160
|
-
*/
|
|
161
|
-
logFor(ctx) {
|
|
162
|
-
return logging_1.Logging.for(FabricContractAdapter, {}, ctx);
|
|
163
|
-
}
|
|
164
153
|
/**
|
|
165
154
|
* @description Gets the repository constructor for this adapter
|
|
166
155
|
* @summary Returns the FabricContractRepository constructor for creating repositories
|
|
@@ -197,12 +186,14 @@ class FabricContractAdapter extends for_couchdb_1.CouchDBAdapter {
|
|
|
197
186
|
* @param {...any[]} args - Additional arguments, including the chaincode stub and logger
|
|
198
187
|
* @return {Promise<Record<string, any>>} Promise resolving to the created record
|
|
199
188
|
*/
|
|
200
|
-
async create(
|
|
201
|
-
const {
|
|
202
|
-
const
|
|
189
|
+
async create(clazz, id, model, ...args) {
|
|
190
|
+
const { ctx, log } = this.logCtx(args, this.create);
|
|
191
|
+
const { stub } = ctx;
|
|
192
|
+
const tableName = decorator_validation_1.Model.tableName(clazz);
|
|
203
193
|
try {
|
|
204
194
|
log.info(`adding entry to ${tableName} table with pk ${id}`);
|
|
205
|
-
|
|
195
|
+
const composedKey = stub.createCompositeKey(tableName, [String(id)]);
|
|
196
|
+
model = await this.putState(composedKey, model, ctx);
|
|
206
197
|
}
|
|
207
198
|
catch (e) {
|
|
208
199
|
throw this.parseError(e);
|
|
@@ -217,12 +208,14 @@ class FabricContractAdapter extends for_couchdb_1.CouchDBAdapter {
|
|
|
217
208
|
* @param {...any[]} args - Additional arguments, including the chaincode stub and logger
|
|
218
209
|
* @return {Promise<Record<string, any>>} Promise resolving to the retrieved record
|
|
219
210
|
*/
|
|
220
|
-
async read(
|
|
221
|
-
const {
|
|
222
|
-
const
|
|
211
|
+
async read(clazz, id, ...args) {
|
|
212
|
+
const { ctx, log } = this.logCtx(args, this.read);
|
|
213
|
+
const { stub } = ctx;
|
|
214
|
+
const tableName = decorator_validation_1.Model.tableName(clazz);
|
|
223
215
|
let model;
|
|
224
216
|
try {
|
|
225
|
-
const
|
|
217
|
+
const composedKey = stub.createCompositeKey(tableName, [String(id)]);
|
|
218
|
+
const results = await this.readState(composedKey, ctx);
|
|
226
219
|
if (results.length < 1) {
|
|
227
220
|
log.debug(`No record found for id ${id} in ${tableName} table`);
|
|
228
221
|
throw new db_decorators_1.NotFoundError(`No record found for id ${id} in ${tableName} table`);
|
|
@@ -250,12 +243,14 @@ class FabricContractAdapter extends for_couchdb_1.CouchDBAdapter {
|
|
|
250
243
|
* @param {...any[]} args - Additional arguments, including the chaincode stub and logger
|
|
251
244
|
* @return {Promise<Record<string, any>>} Promise resolving to the updated record
|
|
252
245
|
*/
|
|
253
|
-
async update(
|
|
254
|
-
const {
|
|
255
|
-
const
|
|
246
|
+
async update(clazz, id, model, ...args) {
|
|
247
|
+
const { ctx, log } = this.logCtx(args, this.update);
|
|
248
|
+
const { stub } = ctx;
|
|
249
|
+
const tableName = decorator_validation_1.Model.tableName(clazz);
|
|
256
250
|
try {
|
|
257
|
-
log.
|
|
258
|
-
|
|
251
|
+
log.verbose(`updating entry to ${tableName} table with pk ${id}`);
|
|
252
|
+
const composedKey = stub.createCompositeKey(tableName, [String(id)]);
|
|
253
|
+
model = await this.putState(composedKey, model, ctx);
|
|
259
254
|
}
|
|
260
255
|
catch (e) {
|
|
261
256
|
throw this.parseError(e);
|
|
@@ -270,32 +265,120 @@ class FabricContractAdapter extends for_couchdb_1.CouchDBAdapter {
|
|
|
270
265
|
* @param {...any[]} args - Additional arguments, including the chaincode stub and logger
|
|
271
266
|
* @return {Promise<Record<string, any>>} Promise resolving to the deleted record
|
|
272
267
|
*/
|
|
273
|
-
async delete(
|
|
274
|
-
const ctx = args.
|
|
275
|
-
const { stub
|
|
276
|
-
const
|
|
277
|
-
args.push(ctx);
|
|
268
|
+
async delete(clazz, id, ...args) {
|
|
269
|
+
const { ctx, log, ctxArgs } = this.logCtx(args, this.delete);
|
|
270
|
+
const { stub } = ctx;
|
|
271
|
+
const tableName = decorator_validation_1.Model.tableName(clazz);
|
|
278
272
|
let model;
|
|
279
273
|
try {
|
|
280
|
-
|
|
274
|
+
const composedKey = stub.createCompositeKey(tableName, [String(id)]);
|
|
275
|
+
model = await this.read(clazz, id, ...ctxArgs);
|
|
281
276
|
log.verbose(`deleting entry with pk ${id} from ${tableName} table`);
|
|
282
|
-
this.deleteState(
|
|
277
|
+
await this.deleteState(composedKey, ctx);
|
|
283
278
|
}
|
|
284
279
|
catch (e) {
|
|
285
280
|
throw this.parseError(e);
|
|
286
281
|
}
|
|
287
282
|
return model;
|
|
288
283
|
}
|
|
289
|
-
async deleteState(
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
284
|
+
async deleteState(id, ctx) {
|
|
285
|
+
const { stub, logger } = ctx;
|
|
286
|
+
const log = logger.for(this.deleteState);
|
|
287
|
+
await stub.deleteState(id);
|
|
288
|
+
log.trace(`Deleted state for id ${id}`);
|
|
289
|
+
}
|
|
290
|
+
forPrivate(collection) {
|
|
291
|
+
const toOverride = [
|
|
292
|
+
this.putState,
|
|
293
|
+
this.readState,
|
|
294
|
+
this.deleteState,
|
|
295
|
+
this.queryResult,
|
|
296
|
+
this.queryResultPaginated,
|
|
297
|
+
].map((fn) => fn.name);
|
|
298
|
+
return new Proxy(this, {
|
|
299
|
+
get(target, prop, receiver) {
|
|
300
|
+
if (!toOverride.includes(prop))
|
|
301
|
+
return Reflect.get(target, prop, receiver);
|
|
302
|
+
return new Proxy(target[prop], {
|
|
303
|
+
async apply(fn, thisArg, argsList) {
|
|
304
|
+
switch (prop) {
|
|
305
|
+
case "putState": {
|
|
306
|
+
const [stub, id, model] = argsList;
|
|
307
|
+
await stub.putPrivateData(collection, id.toString(), model);
|
|
308
|
+
return model;
|
|
309
|
+
}
|
|
310
|
+
case "deleteState": {
|
|
311
|
+
const [stub, id] = argsList;
|
|
312
|
+
return stub.deletePrivateData(collection, id);
|
|
313
|
+
}
|
|
314
|
+
case "readState": {
|
|
315
|
+
const [stub, id] = argsList;
|
|
316
|
+
return stub.getPrivateData(collection, id);
|
|
317
|
+
}
|
|
318
|
+
case "queryResult": {
|
|
319
|
+
const [stub, rawInput] = argsList;
|
|
320
|
+
return stub.getPrivateDataQueryResult(collection, rawInput);
|
|
321
|
+
}
|
|
322
|
+
case "queryResultPaginated": {
|
|
323
|
+
const [stub, rawInput, limit, skip] = argsList;
|
|
324
|
+
const iterator = await stub.getPrivateDataQueryResult(collection, rawInput);
|
|
325
|
+
const results = [];
|
|
326
|
+
let count = 0;
|
|
327
|
+
let reachedBookmark = skip ? false : true;
|
|
328
|
+
let lastKey = null;
|
|
329
|
+
while (true) {
|
|
330
|
+
const res = await iterator.next();
|
|
331
|
+
if (res.value && res.value.value.toString()) {
|
|
332
|
+
const recordKey = res.value.key;
|
|
333
|
+
const recordValue = res.value.value.toString("utf8");
|
|
334
|
+
// If we have a skip, skip until we reach it
|
|
335
|
+
if (!reachedBookmark) {
|
|
336
|
+
if (recordKey === skip?.toString()) {
|
|
337
|
+
reachedBookmark = true;
|
|
338
|
+
}
|
|
339
|
+
continue;
|
|
340
|
+
}
|
|
341
|
+
results.push({
|
|
342
|
+
Key: recordKey,
|
|
343
|
+
Record: JSON.parse(recordValue),
|
|
344
|
+
});
|
|
345
|
+
lastKey = recordKey;
|
|
346
|
+
count++;
|
|
347
|
+
if (count >= limit) {
|
|
348
|
+
await iterator.close();
|
|
349
|
+
return {
|
|
350
|
+
iterator: results,
|
|
351
|
+
metadata: {
|
|
352
|
+
fetchedRecordsCount: results.length,
|
|
353
|
+
bookmark: lastKey,
|
|
354
|
+
},
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
if (res.done) {
|
|
359
|
+
await iterator.close();
|
|
360
|
+
return {
|
|
361
|
+
iterator: results,
|
|
362
|
+
metadata: {
|
|
363
|
+
fetchedRecordsCount: results.length,
|
|
364
|
+
bookmark: "",
|
|
365
|
+
},
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
default:
|
|
371
|
+
throw new db_decorators_1.InternalError(`Unsupported method override ${String(prop)}`);
|
|
372
|
+
}
|
|
373
|
+
},
|
|
374
|
+
});
|
|
375
|
+
},
|
|
376
|
+
});
|
|
294
377
|
}
|
|
295
|
-
async putState(
|
|
296
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
297
|
-
...args) {
|
|
378
|
+
async putState(id, model, ctx) {
|
|
298
379
|
let data;
|
|
380
|
+
const { stub, logger } = ctx;
|
|
381
|
+
const log = logger.for(this.putState);
|
|
299
382
|
try {
|
|
300
383
|
data = Buffer.from(FabricContractAdapter.serializer.serialize(model));
|
|
301
384
|
}
|
|
@@ -303,26 +386,24 @@ class FabricContractAdapter extends for_couchdb_1.CouchDBAdapter {
|
|
|
303
386
|
throw new db_decorators_1.SerializationError(`Failed to serialize record with id ${id}: ${e}`);
|
|
304
387
|
}
|
|
305
388
|
await stub.putState(id.toString(), data);
|
|
389
|
+
log.silly(`state stored under id ${id}`);
|
|
306
390
|
return model;
|
|
307
391
|
}
|
|
308
|
-
async readState(
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
const
|
|
312
|
-
const
|
|
313
|
-
|
|
314
|
-
if (res.toString() === "")
|
|
392
|
+
async readState(id, ctx) {
|
|
393
|
+
let result;
|
|
394
|
+
const { stub, logger } = ctx;
|
|
395
|
+
const log = logger.for(this.readState);
|
|
396
|
+
const res = (await stub.getState(id)).toString();
|
|
397
|
+
if (!res)
|
|
315
398
|
throw new db_decorators_1.NotFoundError(`Record with id ${id} not found`);
|
|
399
|
+
log.silly(`Read state for id ${id}`);
|
|
316
400
|
try {
|
|
317
|
-
|
|
318
|
-
// model.constructor.name
|
|
319
|
-
);
|
|
401
|
+
result = FabricContractAdapter.serializer.deserialize(res.toString());
|
|
320
402
|
}
|
|
321
403
|
catch (e) {
|
|
322
404
|
throw new db_decorators_1.SerializationError(`Failed to parse record: ${e}`);
|
|
323
405
|
}
|
|
324
|
-
|
|
325
|
-
return results;
|
|
406
|
+
return result;
|
|
326
407
|
}
|
|
327
408
|
async queryResult(stub, rawInput,
|
|
328
409
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
@@ -366,10 +447,32 @@ class FabricContractAdapter extends for_couchdb_1.CouchDBAdapter {
|
|
|
366
447
|
* @return {FabricContractFlags} The merged flags
|
|
367
448
|
*/
|
|
368
449
|
async flags(operation, model, flags, ctx, ...args) {
|
|
369
|
-
|
|
450
|
+
const ensureLogger = (logger) => {
|
|
451
|
+
const base = logger ?? this.log.for(this.flags);
|
|
452
|
+
if (typeof base.clear !== "function")
|
|
453
|
+
base.clear = () => base;
|
|
454
|
+
if (typeof base.for !== "function")
|
|
455
|
+
base.for = () => base;
|
|
456
|
+
return base;
|
|
457
|
+
};
|
|
458
|
+
const fabricCtx = ctx instanceof ContractContext_1.FabricContractContext
|
|
459
|
+
? ctx.accumulate({
|
|
460
|
+
logger: ensureLogger(ctx.logger),
|
|
461
|
+
})
|
|
462
|
+
: new ContractContext_1.FabricContractContext().accumulate({
|
|
463
|
+
stub: ctx.stub,
|
|
464
|
+
identity: ctx.clientIdentity,
|
|
465
|
+
logger: ensureLogger(),
|
|
466
|
+
});
|
|
467
|
+
const baseFlags = Object.assign({}, flags, {
|
|
468
|
+
logger: fabricCtx.logger,
|
|
469
|
+
});
|
|
470
|
+
return Object.assign(await super.flags(operation, model, baseFlags, ...args), {
|
|
370
471
|
stub: ctx.stub,
|
|
371
|
-
identity: ctx.clientIdentity ??
|
|
372
|
-
|
|
472
|
+
identity: (ctx.clientIdentity ??
|
|
473
|
+
fabricCtx.identity),
|
|
474
|
+
logger: fabricCtx.logger,
|
|
475
|
+
correlationId: ctx.stub.getTxID(),
|
|
373
476
|
});
|
|
374
477
|
}
|
|
375
478
|
/**
|
|
@@ -471,9 +574,10 @@ class FabricContractAdapter extends for_couchdb_1.CouchDBAdapter {
|
|
|
471
574
|
* FabricContractAdapter->>FabricContractAdapter: resultIterator(log, iterator)
|
|
472
575
|
* FabricContractAdapter-->>Caller: results
|
|
473
576
|
*/
|
|
474
|
-
async raw(rawInput,
|
|
475
|
-
const {
|
|
476
|
-
const
|
|
577
|
+
async raw(rawInput, ...args) {
|
|
578
|
+
const { ctx, log, ctxArgs } = this.logCtx(args, this.raw);
|
|
579
|
+
const docsOnly = typeof ctxArgs[0] === "boolean" ? ctxArgs.shift() : false;
|
|
580
|
+
const { stub } = ctx;
|
|
477
581
|
const { skip, limit } = rawInput;
|
|
478
582
|
let iterator;
|
|
479
583
|
if (limit || skip) {
|
|
@@ -492,11 +596,8 @@ class FabricContractAdapter extends for_couchdb_1.CouchDBAdapter {
|
|
|
492
596
|
log.debug(`returning {0} results`, `${Array.isArray(results) ? results.length : 1}`);
|
|
493
597
|
return results;
|
|
494
598
|
}
|
|
495
|
-
Statement(
|
|
496
|
-
|
|
497
|
-
throw new errors_1.MissingContextError("Context is required");
|
|
498
|
-
}
|
|
499
|
-
return new FabricContractStatement_1.FabricStatement(this, ctx);
|
|
599
|
+
Statement() {
|
|
600
|
+
return new FabricContractStatement_1.FabricStatement(this);
|
|
500
601
|
}
|
|
501
602
|
async Sequence(options) {
|
|
502
603
|
return new FabricContractSequence_1.FabricContractSequence(options, this);
|
|
@@ -504,24 +605,18 @@ class FabricContractAdapter extends for_couchdb_1.CouchDBAdapter {
|
|
|
504
605
|
async createAll(tableName, id, model, ...args) {
|
|
505
606
|
if (id.length !== model.length)
|
|
506
607
|
throw new db_decorators_1.InternalError("Ids and models must have the same length");
|
|
507
|
-
const {
|
|
508
|
-
const
|
|
509
|
-
log.
|
|
510
|
-
|
|
511
|
-
return Promise.all(id.map(async (i, index) => {
|
|
512
|
-
return this.create(tableName, i, model[index], ...args);
|
|
513
|
-
}));
|
|
608
|
+
const { log, ctxArgs } = this.logCtx(args, this.createAll);
|
|
609
|
+
const tableLabel = decorator_validation_1.Model.tableName(tableName);
|
|
610
|
+
log.debug(`Creating ${id.length} entries ${tableLabel} table`);
|
|
611
|
+
return Promise.all(id.map((i, count) => this.create(tableName, i, model[count], ...ctxArgs)));
|
|
514
612
|
}
|
|
515
613
|
async updateAll(tableName, id, model, ...args) {
|
|
516
614
|
if (id.length !== model.length)
|
|
517
615
|
throw new db_decorators_1.InternalError("Ids and models must have the same length");
|
|
518
|
-
const {
|
|
519
|
-
const
|
|
520
|
-
log.
|
|
521
|
-
|
|
522
|
-
return Promise.all(id.map(async (i, index) => {
|
|
523
|
-
return this.update(tableName, i, model[index], ...args);
|
|
524
|
-
}));
|
|
616
|
+
const { log, ctxArgs } = this.logCtx(args, this.updateAll);
|
|
617
|
+
const tableLabel = decorator_validation_1.Model.tableName(tableName);
|
|
618
|
+
log.debug(`Updating ${id.length} entries ${tableLabel} table`);
|
|
619
|
+
return Promise.all(id.map((i, count) => this.update(tableName, i, model[count], ...ctxArgs)));
|
|
525
620
|
}
|
|
526
621
|
/**
|
|
527
622
|
*
|
|
@@ -529,79 +624,62 @@ class FabricContractAdapter extends for_couchdb_1.CouchDBAdapter {
|
|
|
529
624
|
* @param {string} pk
|
|
530
625
|
* @param args
|
|
531
626
|
*/
|
|
532
|
-
prepare(model,
|
|
533
|
-
const {
|
|
534
|
-
const tableName =
|
|
535
|
-
const
|
|
627
|
+
prepare(model, ...args) {
|
|
628
|
+
const { log } = this.logCtx(args, this.prepare);
|
|
629
|
+
const tableName = decorator_validation_1.Model.tableName(model.constructor);
|
|
630
|
+
const pk = decorator_validation_1.Model.pk(model.constructor);
|
|
536
631
|
const split = decorator_validation_1.Model.segregate(model);
|
|
537
632
|
const result = Object.entries(split.model).reduce((accum, [key, val]) => {
|
|
538
633
|
if (typeof val === "undefined")
|
|
539
634
|
return accum;
|
|
540
|
-
const mappedProp =
|
|
635
|
+
const mappedProp = decorator_validation_1.Model.columnName(model, key);
|
|
541
636
|
if (this.isReserved(mappedProp))
|
|
542
637
|
throw new db_decorators_1.InternalError(`Property name ${mappedProp} is reserved`);
|
|
543
638
|
accum[mappedProp] = val;
|
|
544
639
|
return accum;
|
|
545
640
|
}, {});
|
|
546
|
-
|
|
547
|
-
log.silly(`Passing along persistence metadata for ${model[core_1.PersistenceKeys.METADATA]}`);
|
|
548
|
-
Object.defineProperty(result, core_1.PersistenceKeys.METADATA, {
|
|
549
|
-
enumerable: false,
|
|
550
|
-
writable: false,
|
|
551
|
-
configurable: true,
|
|
552
|
-
value: model[core_1.PersistenceKeys.METADATA],
|
|
553
|
-
});
|
|
554
|
-
}
|
|
555
|
-
log.info(`Preparing record for ${tableName} table with pk ${model[pk]}`);
|
|
641
|
+
log.silly(`Preparing record for ${tableName} table with pk ${model[pk]}`);
|
|
556
642
|
return {
|
|
557
643
|
record: result,
|
|
558
|
-
id:
|
|
644
|
+
id: model[pk],
|
|
559
645
|
transient: split.transient,
|
|
560
646
|
};
|
|
561
647
|
}
|
|
562
|
-
revert(obj, clazz,
|
|
563
|
-
const log = this.
|
|
648
|
+
revert(obj, clazz, id, transient, ...args) {
|
|
649
|
+
const { log } = this.logCtx(args, this.revert);
|
|
564
650
|
const ob = {};
|
|
651
|
+
const pk = decorator_validation_1.Model.pk(clazz);
|
|
565
652
|
ob[pk] = id;
|
|
566
653
|
const m = (typeof clazz === "string" ? decorator_validation_1.Model.build(ob, clazz) : new clazz(ob));
|
|
567
654
|
log.silly(`Rebuilding model ${m.constructor.name} id ${id}`);
|
|
568
|
-
const metadata = obj[core_1.PersistenceKeys.METADATA];
|
|
569
655
|
const result = Object.keys(m).reduce((accum, key) => {
|
|
570
|
-
accum[key] =
|
|
656
|
+
accum[key] =
|
|
657
|
+
obj[decorator_validation_1.Model.columnName(accum, key)];
|
|
571
658
|
return accum;
|
|
572
659
|
}, m);
|
|
573
660
|
if (transient) {
|
|
574
|
-
log.
|
|
661
|
+
log.debug(`re-adding transient properties: ${Object.keys(transient).join(", ")}`);
|
|
575
662
|
Object.entries(transient).forEach(([key, val]) => {
|
|
576
663
|
if (key in result && result[key] !== undefined)
|
|
577
664
|
throw new db_decorators_1.InternalError(`Transient property ${key} already exists on model ${m.constructor.name}. should be impossible`);
|
|
578
665
|
result[key] = val;
|
|
579
666
|
});
|
|
580
667
|
}
|
|
581
|
-
if (metadata) {
|
|
582
|
-
log.silly(`Passing along ${this.flavour} persistence metadata for ${m.constructor.name} id ${id}: ${metadata}`);
|
|
583
|
-
Object.defineProperty(result, core_1.PersistenceKeys.METADATA, {
|
|
584
|
-
enumerable: false,
|
|
585
|
-
configurable: false,
|
|
586
|
-
writable: false,
|
|
587
|
-
value: metadata,
|
|
588
|
-
});
|
|
589
|
-
}
|
|
590
668
|
return result;
|
|
591
669
|
}
|
|
592
670
|
createPrefix(tableName, id, model, ...args) {
|
|
593
|
-
const
|
|
671
|
+
const { ctxArgs } = this.logCtx(args, this.createPrefix);
|
|
594
672
|
const record = {};
|
|
595
|
-
record[for_couchdb_1.CouchDBKeys.TABLE] = tableName;
|
|
673
|
+
record[for_couchdb_1.CouchDBKeys.TABLE] = decorator_validation_1.Model.tableName(tableName);
|
|
596
674
|
Object.assign(record, model);
|
|
597
|
-
return [tableName, id, record,
|
|
675
|
+
return [tableName, id, record, ...ctxArgs];
|
|
598
676
|
}
|
|
599
677
|
updatePrefix(tableName, id, model, ...args) {
|
|
600
|
-
const
|
|
678
|
+
const { ctxArgs } = this.logCtx(args, this.updatePrefix);
|
|
601
679
|
const record = {};
|
|
602
|
-
record[for_couchdb_1.CouchDBKeys.TABLE] = tableName;
|
|
680
|
+
record[for_couchdb_1.CouchDBKeys.TABLE] = decorator_validation_1.Model.tableName(tableName);
|
|
603
681
|
Object.assign(record, model);
|
|
604
|
-
return [tableName, id, record,
|
|
682
|
+
return [tableName, id, record, ...ctxArgs];
|
|
605
683
|
}
|
|
606
684
|
createAllPrefix(tableName, ids, models, ...args) {
|
|
607
685
|
if (ids.length !== models.length)
|
|
@@ -610,7 +688,6 @@ class FabricContractAdapter extends for_couchdb_1.CouchDBAdapter {
|
|
|
610
688
|
const records = ids.map((id, count) => {
|
|
611
689
|
const record = {};
|
|
612
690
|
record[for_couchdb_1.CouchDBKeys.TABLE] = tableName;
|
|
613
|
-
// record[CouchDBKeys.ID] = this.generateId(tableName, id);
|
|
614
691
|
Object.assign(record, models[count]);
|
|
615
692
|
return record;
|
|
616
693
|
});
|
|
@@ -628,6 +705,18 @@ class FabricContractAdapter extends for_couchdb_1.CouchDBAdapter {
|
|
|
628
705
|
});
|
|
629
706
|
return [tableName, ids, records, ctx];
|
|
630
707
|
}
|
|
708
|
+
parseError(err, reason) {
|
|
709
|
+
return FabricContractAdapter.parseError(reason || err);
|
|
710
|
+
}
|
|
711
|
+
static parseError(err, reason) {
|
|
712
|
+
// if (
|
|
713
|
+
// MISSING_PRIVATE_DATA_REGEX.test(
|
|
714
|
+
// typeof err === "string" ? err : err.message
|
|
715
|
+
// )
|
|
716
|
+
// )
|
|
717
|
+
// return new UnauthorizedPrivateDataAccess(err) as E;
|
|
718
|
+
return super.parseError(err, reason);
|
|
719
|
+
}
|
|
631
720
|
/**
|
|
632
721
|
* @description Static method for decoration overrides
|
|
633
722
|
* @summary Overrides/extends decaf decoration with Fabric-specific functionality
|
|
@@ -2,11 +2,11 @@ import { CouchDBAdapter, MangoQuery } from "@decaf-ts/for-couchdb";
|
|
|
2
2
|
import { Model } from "@decaf-ts/decorator-validation";
|
|
3
3
|
import { FabricContractFlags } from "./types";
|
|
4
4
|
import { FabricContractContext } from "./ContractContext";
|
|
5
|
-
import { Context, OperationKeys } from "@decaf-ts/db-decorators";
|
|
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 {
|
|
9
|
-
import {
|
|
8
|
+
import { RelationsMetadata, Sequence, SequenceOptions, Adapter, PreparedModel, Repository } from "@decaf-ts/core";
|
|
9
|
+
import type { ContextualArgs, MaybeContextualArg } from "@decaf-ts/core";
|
|
10
10
|
import { FabricContractRepository } from "./FabricContractRepository";
|
|
11
11
|
import { ChaincodeStub, Iterators, StateQueryResponse } from "fabric-shim-api";
|
|
12
12
|
import { FabricStatement } from "./FabricContractStatement";
|
|
@@ -67,7 +67,7 @@ export declare function createdByOnFabricCreateUpdate<M extends Model, R extends
|
|
|
67
67
|
* S-->>R: next value
|
|
68
68
|
* R->>M: define non-writable primary key
|
|
69
69
|
*/
|
|
70
|
-
export declare function pkFabricOnCreate<M extends Model, R extends FabricContractRepository<M
|
|
70
|
+
export declare function pkFabricOnCreate<M extends Model, R extends FabricContractRepository<M>>(this: R, context: FabricContractContext, data: SequenceOptions, key: keyof M, model: M): Promise<void>;
|
|
71
71
|
/**
|
|
72
72
|
* @description Adapter for Hyperledger Fabric chaincode state database operations
|
|
73
73
|
* @summary Provides a CouchDB-like interface for interacting with the Fabric state database from within a chaincode contract
|
|
@@ -105,20 +105,13 @@ export declare function pkFabricOnCreate<M extends Model, R extends FabricContra
|
|
|
105
105
|
* Stub-->>FabricContractAdapter: Success
|
|
106
106
|
* FabricContractAdapter-->>Contract: model
|
|
107
107
|
*/
|
|
108
|
-
export declare class FabricContractAdapter extends CouchDBAdapter<any, void,
|
|
108
|
+
export declare class FabricContractAdapter extends CouchDBAdapter<any, void, FabricContractContext> {
|
|
109
109
|
protected getClient(): void;
|
|
110
110
|
/**
|
|
111
111
|
* @description Text decoder for converting binary data to strings
|
|
112
112
|
*/
|
|
113
113
|
private static textDecoder;
|
|
114
114
|
protected static readonly serializer: SimpleDeterministicSerializer<Model<false>>;
|
|
115
|
-
/**
|
|
116
|
-
* @description Creates a logger for a specific chaincode context
|
|
117
|
-
* @summary Returns a ContractLogger instance configured for the current context
|
|
118
|
-
* @param {Ctx} ctx - The Fabric chaincode context
|
|
119
|
-
* @return {ContractLogger} The logger instance
|
|
120
|
-
*/
|
|
121
|
-
logFor(ctx: Ctx): ContractLogger;
|
|
122
115
|
/**
|
|
123
116
|
* @description Context constructor for this adapter
|
|
124
117
|
* @summary Overrides the base Context constructor with FabricContractContext
|
|
@@ -130,7 +123,7 @@ export declare class FabricContractAdapter extends CouchDBAdapter<any, void, Fab
|
|
|
130
123
|
* @template M - Type extending Model
|
|
131
124
|
* @return {Constructor<Repository<M, MangoQuery, FabricContractAdapter, FabricContractFlags, FabricContractContext>>} The repository constructor
|
|
132
125
|
*/
|
|
133
|
-
repository<
|
|
126
|
+
repository<R extends Repository<any, Adapter<any, void, MangoQuery, FabricContractContext>>>(): Constructor<R>;
|
|
134
127
|
/**
|
|
135
128
|
* @description Creates a new FabricContractAdapter instance
|
|
136
129
|
* @summary Initializes an adapter for interacting with the Fabric state database
|
|
@@ -149,7 +142,7 @@ export declare class FabricContractAdapter extends CouchDBAdapter<any, void, Fab
|
|
|
149
142
|
* @param {...any[]} args - Additional arguments, including the chaincode stub and logger
|
|
150
143
|
* @return {Promise<Record<string, any>>} Promise resolving to the created record
|
|
151
144
|
*/
|
|
152
|
-
create(
|
|
145
|
+
create<M extends Model>(clazz: Constructor<M>, id: PrimaryKeyType, model: Record<string, any>, ...args: ContextualArgs<FabricContractContext>): Promise<Record<string, any>>;
|
|
153
146
|
/**
|
|
154
147
|
* @description Reads a record from the state database
|
|
155
148
|
* @summary Retrieves and deserializes a record from the Fabric state database
|
|
@@ -158,7 +151,7 @@ export declare class FabricContractAdapter extends CouchDBAdapter<any, void, Fab
|
|
|
158
151
|
* @param {...any[]} args - Additional arguments, including the chaincode stub and logger
|
|
159
152
|
* @return {Promise<Record<string, any>>} Promise resolving to the retrieved record
|
|
160
153
|
*/
|
|
161
|
-
read(
|
|
154
|
+
read<M extends Model>(clazz: Constructor<M>, id: PrimaryKeyType, ...args: ContextualArgs<FabricContractContext>): Promise<Record<string, any>>;
|
|
162
155
|
/**
|
|
163
156
|
* @description Updates a record in the state database
|
|
164
157
|
* @summary Serializes a model and updates it in the Fabric state database
|
|
@@ -169,7 +162,7 @@ export declare class FabricContractAdapter extends CouchDBAdapter<any, void, Fab
|
|
|
169
162
|
* @param {...any[]} args - Additional arguments, including the chaincode stub and logger
|
|
170
163
|
* @return {Promise<Record<string, any>>} Promise resolving to the updated record
|
|
171
164
|
*/
|
|
172
|
-
update(
|
|
165
|
+
update<M extends Model>(clazz: Constructor<M>, id: PrimaryKeyType, model: Record<string, any>, ...args: ContextualArgs<FabricContractContext>): Promise<Record<string, any>>;
|
|
173
166
|
/**
|
|
174
167
|
* @description Deletes a record from the state database
|
|
175
168
|
* @summary Retrieves a record and then removes it from the Fabric state database
|
|
@@ -178,10 +171,11 @@ export declare class FabricContractAdapter extends CouchDBAdapter<any, void, Fab
|
|
|
178
171
|
* @param {...any[]} args - Additional arguments, including the chaincode stub and logger
|
|
179
172
|
* @return {Promise<Record<string, any>>} Promise resolving to the deleted record
|
|
180
173
|
*/
|
|
181
|
-
delete(
|
|
182
|
-
protected deleteState(
|
|
183
|
-
|
|
184
|
-
protected
|
|
174
|
+
delete<M extends Model>(clazz: Constructor<M>, id: PrimaryKeyType, ...args: ContextualArgs<FabricContractContext>): Promise<Record<string, any>>;
|
|
175
|
+
protected deleteState(id: string, ctx: FabricContractContext): Promise<void>;
|
|
176
|
+
forPrivate(collection: string): FabricContractAdapter;
|
|
177
|
+
protected putState(id: string, model: Record<string, any>, ctx: FabricContractContext): Promise<Record<string, any>>;
|
|
178
|
+
protected readState(id: string, ctx: FabricContractContext): Promise<any>;
|
|
185
179
|
protected queryResult(stub: ChaincodeStub, rawInput: any, ...args: any[]): Promise<Iterators.StateQueryIterator>;
|
|
186
180
|
protected queryResultPaginated(stub: ChaincodeStub, rawInput: any, limit?: number, skip?: number, ...args: any[]): Promise<StateQueryResponse<Iterators.StateQueryIterator>>;
|
|
187
181
|
protected mergeModels(results: Record<string, any>[]): Record<string, any>;
|
|
@@ -265,27 +259,25 @@ export declare class FabricContractAdapter extends CouchDBAdapter<any, void, Fab
|
|
|
265
259
|
* FabricContractAdapter->>FabricContractAdapter: resultIterator(log, iterator)
|
|
266
260
|
* FabricContractAdapter-->>Caller: results
|
|
267
261
|
*/
|
|
268
|
-
raw<R>(rawInput: MangoQuery,
|
|
269
|
-
Statement<M extends Model>(
|
|
262
|
+
raw<R>(rawInput: MangoQuery, ...args: ContextualArgs<FabricContractContext>): Promise<R>;
|
|
263
|
+
Statement<M extends Model>(): FabricStatement<M, any>;
|
|
270
264
|
Sequence(options: SequenceOptions): Promise<Sequence>;
|
|
271
|
-
createAll(tableName:
|
|
272
|
-
updateAll(tableName:
|
|
265
|
+
createAll<M extends Model>(tableName: Constructor<M>, id: PrimaryKeyType[], model: Record<string, any>[], ...args: ContextualArgs<FabricContractContext>): Promise<Record<string, any>[]>;
|
|
266
|
+
updateAll<M extends Model>(tableName: Constructor<M>, id: PrimaryKeyType[], model: Record<string, any>[], ...args: ContextualArgs<FabricContractContext>): Promise<Record<string, any>[]>;
|
|
273
267
|
/**
|
|
274
268
|
*
|
|
275
269
|
* @param model
|
|
276
270
|
* @param {string} pk
|
|
277
271
|
* @param args
|
|
278
272
|
*/
|
|
279
|
-
prepare<M extends Model>(model: M,
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
protected createAllPrefix(tableName: string, ids: string[] | number[], models: Record<string, any>[], ...args: any[]): (string | string[] | number[] | Record<string, any>[])[];
|
|
288
|
-
protected updateAllPrefix(tableName: string, ids: string[] | number[], models: Record<string, any>[], ...args: any[]): any[];
|
|
273
|
+
prepare<M extends Model>(model: M, ...args: ContextualArgs<FabricContractContext>): PreparedModel;
|
|
274
|
+
revert<M extends Model>(obj: Record<string, any>, clazz: Constructor<M>, id: PrimaryKeyType, transient?: Record<string, any>, ...args: ContextualArgs<FabricContractContext>): M;
|
|
275
|
+
createPrefix<M extends Model>(tableName: Constructor<M>, id: PrimaryKeyType, model: Record<string, any>, ...args: MaybeContextualArg<FabricContractContext>): [Constructor<M>, PrimaryKeyType, Record<string, any>, ...any[], FabricContractContext];
|
|
276
|
+
updatePrefix<M extends Model>(tableName: Constructor<M>, id: PrimaryKeyType, model: Record<string, any>, ...args: MaybeContextualArg<FabricContractContext>): any[];
|
|
277
|
+
protected createAllPrefix<M extends Model>(tableName: Constructor<M>, ids: PrimaryKeyType[], models: Record<string, any>[], ...args: [...any, FabricContractContext]): (string | string[] | number[] | Record<string, any>[])[];
|
|
278
|
+
protected updateAllPrefix<M extends Model>(tableName: Constructor<M>, ids: PrimaryKeyType[], models: Record<string, any>[], ...args: [...any, FabricContractContext]): any[];
|
|
279
|
+
parseError<E extends BaseError>(err: Error | string, reason?: string): E;
|
|
280
|
+
static parseError<E extends BaseError>(err: Error | string, reason?: string): E;
|
|
289
281
|
/**
|
|
290
282
|
* @description Static method for decoration overrides
|
|
291
283
|
* @summary Overrides/extends decaf decoration with Fabric-specific functionality
|