fabric-contract-api
Advanced tools
Comparing version 1.4.0-beta to 1.4.0-beta2
@@ -15,2 +15,4 @@ /* | ||
Object.assign(module.exports, require('./lib/annotations')); | ||
module.exports.JSONSerializer = require('./lib/jsontransactionserializer.js'); |
@@ -15,3 +15,3 @@ /* | ||
* Overriding of the `beforeTransaction` `afterTransaction` `unknownTransaction` and `createContext` are all optional | ||
* Supplying a namespace within the constructor is also option and will default to '' | ||
* Supplying a name within the constructor is also option and will default to '' | ||
* | ||
@@ -23,11 +23,12 @@ * @memberof fabric-contract-api | ||
/** | ||
* Constructor - supplying a namespace is recommended but is not mandatory. | ||
* Constructor - supplying a name is recommended but is not mandatory. | ||
* | ||
* @param {String} namespace namespace for the logic within this contract | ||
* @param {String} name name for the logic within this contract | ||
*/ | ||
constructor(namespace) { | ||
if (namespace && namespace.trim() !== '') { | ||
this.namespace = namespace.trim(); | ||
constructor(name) { | ||
this.__isContract = true; | ||
if (name && name.trim() !== '') { | ||
this.name = name.trim(); | ||
} else { | ||
this.namespace = ''; | ||
this.name = ''; | ||
} | ||
@@ -37,2 +38,11 @@ } | ||
/** | ||
* isContract provides functionality to check if a passed object is a contract type. Enables | ||
* checking if its a contract for when contract-api is "required" by different modules | ||
* @param {Object} obj | ||
*/ | ||
static _isContract(obj) { | ||
return obj instanceof Contract || Boolean(obj.__isContract); | ||
} | ||
/** | ||
* 'beforeTransaction' will be called before any of the transaction functions within your contract | ||
@@ -93,4 +103,4 @@ * Override this method to implement your own processing. Examples of what you may wish to code | ||
*/ | ||
getNamespace() { | ||
return this.namespace; | ||
getName() { | ||
return this.name; | ||
} | ||
@@ -97,0 +107,0 @@ |
{ | ||
"name": "fabric-contract-api", | ||
"version": "1.4.0-beta", | ||
"tag":"beta", | ||
"version": "1.4.0-beta2", | ||
"tag": "beta", | ||
"description": "A node.js implementation of Hyperledger Fabric chaincode shim, to allow endorsing peers and user-provided chaincodes to communicate with each other", | ||
@@ -12,3 +12,3 @@ "main": "index.js", | ||
"scripts": { | ||
"compile": "tsc --project test/typescript" | ||
"compile": "tsc --project test/typescript" | ||
}, | ||
@@ -26,5 +26,7 @@ "keywords": [ | ||
"dependencies": { | ||
"get-params": "^0.1.2", | ||
"reflect-metadata": "^0.1.12" | ||
}, | ||
"types": "./types/index.d.ts" | ||
"types": "./types/index.d.ts", | ||
"devDependencies": {} | ||
} |
@@ -44,3 +44,3 @@ [![NPM](https://nodei.co/npm/fabric-contract-api.svg?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/fabric-contract-api/) | ||
constructor(){ | ||
super('org.mynamespace.updates'); | ||
super('UpdateValuesContract'); | ||
} | ||
@@ -47,0 +47,0 @@ |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/* | ||
@@ -9,3 +8,3 @@ Copyright 2018 IBM All Rights Reserved. | ||
*/ | ||
/// <reference path="../../../fabric-shim/types/index.d.ts" /> | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const fabric_contract_api_1 = require("fabric-contract-api"); | ||
@@ -48,4 +47,4 @@ class ScenarioContext extends fabric_contract_api_1.Context { | ||
const clientIdentity = ctx.clientIdentity; | ||
// test that the namespace returns a string | ||
const ns = this.getNamespace(); | ||
// test that the name returns a string | ||
const ns = this.getName(); | ||
} | ||
@@ -52,0 +51,0 @@ } |
@@ -7,3 +7,3 @@ /* | ||
*/ | ||
/// <reference path="../../../fabric-shim/types/index.d.ts" /> | ||
import { Contract, Context } from 'fabric-contract-api'; | ||
@@ -60,4 +60,4 @@ import { ChaincodeStub, ClientIdentity } from 'fabric-shim'; | ||
// test that the namespace returns a string | ||
const ns: string = this.getNamespace(); | ||
// test that the name returns a string | ||
const ns: string = this.getName(); | ||
} | ||
@@ -64,0 +64,0 @@ } |
@@ -80,12 +80,12 @@ /* | ||
it ('should create with default namespace', () => { | ||
it ('should create with default name', () => { | ||
const sc0 = new Contract(); | ||
expect(sc0.getNamespace()).to.equal(''); | ||
expect(sc0.getName()).to.equal(''); | ||
// should also create default when the supplied name is empty space | ||
const sc1 = new Contract(''); | ||
expect(sc1.getNamespace()).to.equal(''); | ||
expect(sc1.getName()).to.equal(''); | ||
const sc2 = new Contract(' '); | ||
expect(sc2.getNamespace()).to.equal(''); | ||
expect(sc2.getName()).to.equal(''); | ||
}); | ||
@@ -108,8 +108,8 @@ | ||
const sc1 = new Contract('brain.size.planet.smart'); | ||
expect(sc1.namespace).to.equal('brain.size.planet.smart'); | ||
expect(sc1.getNamespace()).to.equal('brain.size.planet.smart'); | ||
expect(sc1.name).to.equal('brain.size.planet.smart'); | ||
expect(sc1.getName()).to.equal('brain.size.planet.smart'); | ||
const sc2 = new Contract(' somewhat.padded.out '); | ||
expect(sc2.namespace).to.equal('somewhat.padded.out'); | ||
expect(sc2.getNamespace()).to.equal('somewhat.padded.out'); | ||
expect(sc2.name).to.equal('somewhat.padded.out'); | ||
expect(sc2.getName()).to.equal('somewhat.padded.out'); | ||
}); | ||
@@ -130,4 +130,29 @@ | ||
}); | ||
it ('should set the __isContract value', () => { | ||
const sc0 = new Contract(); | ||
expect(sc0.__isContract).to.deep.equal(true); | ||
}); | ||
}); | ||
describe('_isContract', () => { | ||
it ('should return true when class is a contract', () => { | ||
expect(Contract._isContract(new SCAlpha())).to.deep.equal(true); | ||
}); | ||
it ('should return true when class is not a contract', () => { | ||
class Something {} | ||
expect(Contract._isContract(new Something())).to.deep.equal(false); | ||
}); | ||
it ('should return true when class is not instanceOf contract but does have __isContract true', () => { | ||
class Something { | ||
constructor () { | ||
this.__isContract = true; | ||
} | ||
} | ||
expect(Contract._isContract(new Something())).to.deep.equal(true); | ||
}); | ||
}); | ||
describe('subclass specific functioning', () => { | ||
@@ -142,5 +167,5 @@ | ||
it ('should set the correct namespace', () => { | ||
it ('should set the correct name', () => { | ||
const sc = new SCAlpha(); | ||
sc.getNamespace().should.equal('alpha.beta.delta'); | ||
sc.getName().should.equal('alpha.beta.delta'); | ||
}); | ||
@@ -147,0 +172,0 @@ |
@@ -16,3 +16,3 @@ /* | ||
export class Contract { | ||
constructor(namespace?: string); | ||
constructor(name?: string); | ||
@@ -25,5 +25,10 @@ beforeTransaction(ctx : Context): Promise<void>; | ||
createContext(): Context; | ||
getNamespace(): string; | ||
getName(): string; | ||
} | ||
export function Transaction(commit?: boolean): (target: any, propertyKey: string | symbol) => void; | ||
export function Returns(returnType?: string): (target: any, propertyKey: string | symbol) => void; | ||
export function Object(type?: string): (target: any) => void; | ||
export function Property(name?: string, type?: string): (target: any, propertyKey: string | symbol) => void; | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
81178
27
2061
2
4
1
+ Addedget-params@^0.1.2
+ Addedreflect-metadata@^0.1.12
+ Addedget-params@0.1.2(transitive)
+ Addedreflect-metadata@0.1.14(transitive)