fabric-contract-api
Advanced tools
Comparing version 1.4.0-snapshot.41 to 1.4.0-snapshot.42
@@ -24,3 +24,5 @@ /* | ||
objects[target.name] = { | ||
name: target.name, | ||
'$id': target.name, | ||
type: 'object', | ||
additionalProperties: false, | ||
properties: properties | ||
@@ -55,2 +57,2 @@ }; | ||
}; | ||
}; | ||
}; |
@@ -11,2 +11,19 @@ /* | ||
// there appears to be confusions within the meta data handling | ||
// whether string or String is correct. | ||
// string is the preferred for JSON Schema | ||
function isPrimitive(type) { | ||
const lowerCase = type.toLowerCase(); | ||
switch (lowerCase) { | ||
case 'string': | ||
case 'number': | ||
case 'boolean': | ||
return lowerCase; | ||
default: | ||
return undefined; | ||
} | ||
} | ||
module.exports.Transaction = function Transaction(commit = true) { | ||
@@ -31,9 +48,24 @@ return (target, propertyKey) => { | ||
const paramName = paramNames[paramIdx]; | ||
return { | ||
const obj = { | ||
name: paramName, | ||
description, | ||
schema: { | ||
type: typeof paramType === 'function' ? paramType.name.toLowerCase() : paramType.toString().toLowerCase() | ||
} | ||
}; | ||
const type = typeof paramType === 'function' ? paramType.name : paramType.toString(); | ||
// for reasons best known to the annotations, the primtive types end up being first letter capitlized | ||
// where in all other places including Typescript, they are lower case | ||
// hence this bit of logic | ||
const checkedType = isPrimitive(type); | ||
if (checkedType) { | ||
obj.schema.type = checkedType; | ||
} else { | ||
obj.schema.$ref = `#/components/schemas/${type}`; | ||
} | ||
return obj; | ||
}); | ||
@@ -59,9 +91,18 @@ | ||
const obj = { | ||
name: 'success', | ||
schema: { | ||
} | ||
}; | ||
const checkedType = isPrimitive(returnType); | ||
if (checkedType) { | ||
obj.schema.type = checkedType; | ||
} else { | ||
obj.schema.$ref = `#/components/schemas/${returnType}`; | ||
} | ||
utils.appendOrUpdate(transactions, 'name', propertyKey, { | ||
returns: { | ||
name: 'success', | ||
schema: { | ||
type: returnType.toLowerCase() | ||
} | ||
} | ||
returns: [obj] | ||
}); | ||
@@ -68,0 +109,0 @@ |
@@ -46,3 +46,3 @@ /* | ||
*/ | ||
fromBuffer(data) { | ||
fromBuffer(data, schema = {}) { | ||
@@ -66,5 +66,5 @@ if (!data) { | ||
return value; | ||
return {value}; | ||
} | ||
}; |
{ | ||
"name": "fabric-contract-api", | ||
"version": "1.4.0-snapshot.41", | ||
"version": "1.4.0-snapshot.42", | ||
"tag": "unstable", | ||
@@ -5,0 +5,0 @@ "description": "A node.js implementation of Hyperledger Fabric chaincode shim, to allow endorsing peers and user-provided chaincodes to communicate with each other", |
@@ -14,5 +14,7 @@ { | ||
"contracts": { | ||
"type": "array", | ||
"items": { | ||
"$ref": "#/definitions/contract" | ||
"type": "object", | ||
"patternProperties": { | ||
"^.*$": { | ||
"$ref": "#/definitions/contract" | ||
} | ||
} | ||
@@ -122,7 +124,7 @@ }, | ||
"required": [ | ||
"name", | ||
"$id", | ||
"properties" | ||
], | ||
"properties": { | ||
"name": { | ||
"$id": { | ||
"type": "string" | ||
@@ -129,0 +131,0 @@ }, |
@@ -17,4 +17,4 @@ { | ||
}, | ||
"contracts": [ | ||
{ | ||
"contracts": { | ||
"org.papernet.commercialpaper": { | ||
"name": "org.papernet.commercialpaper", | ||
@@ -218,7 +218,24 @@ "info": { | ||
} | ||
], | ||
}, | ||
"components": { | ||
"schemas": { | ||
"owner": { | ||
"$id": "owner", | ||
"properties": [ | ||
{ | ||
"name": "firstName", | ||
"schema": { | ||
"type": "string" | ||
} | ||
}, | ||
{ | ||
"name": "lastName", | ||
"schema": { | ||
"type": "string" | ||
} | ||
} | ||
] | ||
}, | ||
"paper": { | ||
"name": "paper", | ||
"$id": "paper", | ||
"required": [ | ||
@@ -249,3 +266,3 @@ "issuer", | ||
"schema": { | ||
"type": "string" | ||
"$ref": "#/components/schema/owner" | ||
} | ||
@@ -252,0 +269,0 @@ }, |
@@ -61,4 +61,6 @@ /* | ||
'steve': { | ||
name: 'steve', | ||
properties: ['some', 'properties'] | ||
$id: 'steve', | ||
additionalProperties: false, | ||
properties: ['some', 'properties'], | ||
type: 'object' | ||
} | ||
@@ -82,4 +84,6 @@ }); | ||
'steve': { | ||
name: 'steve', | ||
properties: [] | ||
$id: 'steve', | ||
additionalProperties: false, | ||
properties: [], | ||
type: 'object' | ||
} | ||
@@ -144,2 +148,2 @@ }); | ||
}); | ||
}); | ||
}); |
@@ -37,2 +37,3 @@ /* | ||
let appendSpy; | ||
@@ -104,3 +105,3 @@ let defineMetadataStub; | ||
schema: { | ||
type: 'somefunc' | ||
$ref: '#/components/schemas/someFunc' | ||
} | ||
@@ -112,3 +113,3 @@ }, | ||
schema: { | ||
type: 'sometype' | ||
$ref: '#/components/schemas/someType' | ||
} | ||
@@ -121,2 +122,55 @@ } | ||
it ('should handle existing transactions with primitives', () => { | ||
const mockFunc = function someFunc() {}; | ||
const getMetadataStub = sinon.stub(Reflect, 'getMetadata').onFirstCall().returns([{ | ||
name: 'someTransaction', | ||
tag: ['submitTx'], | ||
parameters: [] | ||
}]).onSecondCall().returns([ | ||
MockContext, | ||
mockFunc, | ||
MockContext, | ||
'string', | ||
MockContext, | ||
]); | ||
TransactionAnnotations.__set__('getParams', () => { | ||
return ['ctx', 'param1', 'ctx2', 'param2', 'ctx3']; | ||
}); | ||
transaction(mockTarget, 'mockKey'); | ||
sinon.assert.calledTwice(getMetadataStub); | ||
sinon.assert.calledWith(getMetadataStub, 'fabric:transactions', mockTarget); | ||
sinon.assert.calledWith(getMetadataStub, 'design:paramtypes', mockTarget, 'mockKey'); | ||
sinon.assert.calledOnce(appendSpy); | ||
sinon.assert.calledOnce(defineMetadataStub); | ||
sinon.assert.calledWith(defineMetadataStub, 'fabric:transactions', [{ | ||
name: 'someTransaction', | ||
tag: ['submitTx'], | ||
parameters: [] | ||
}, { | ||
name: 'mockKey', | ||
tag: ['submitTx'], | ||
parameters: [ | ||
{ | ||
name: 'param1', | ||
description: '', | ||
schema: { | ||
$ref: '#/components/schemas/someFunc' | ||
} | ||
}, | ||
{ | ||
name: 'param2', | ||
description: '', | ||
schema: { | ||
type:'string' | ||
} | ||
} | ||
] | ||
}], mockTarget); | ||
getMetadataStub.restore(); | ||
}); | ||
it ('should create new metadata for fabric:transactions if none exist and handle no params', () => { | ||
@@ -196,8 +250,8 @@ const getMetadataStub = sinon.stub(Reflect, 'getMetadata').returns(undefined); | ||
name: 'mockKey', | ||
returns: { | ||
returns: [{ | ||
name: 'success', | ||
schema: { | ||
type: 'sometype' | ||
$ref: '#/components/schemas/someType' | ||
} | ||
} | ||
}] | ||
}], mockTarget); | ||
@@ -219,8 +273,8 @@ | ||
name: 'mockKey', | ||
returns: { | ||
returns:[{ | ||
name: 'success', | ||
schema: { | ||
type: 'sometype' | ||
$ref: '#/components/schemas/someType' | ||
} | ||
} | ||
}] | ||
}], mockTarget); | ||
@@ -230,3 +284,27 @@ | ||
}); | ||
it ('should handle when it is a string', () => { | ||
const getMetadataStub = sinon.stub(Reflect, 'getMetadata').returns(undefined); | ||
returns = Returns('string'); | ||
returns(mockTarget, 'mockKey'); | ||
sinon.assert.calledOnce(getMetadataStub); | ||
sinon.assert.calledWith(getMetadataStub, 'fabric:transactions', mockTarget); | ||
sinon.assert.calledOnce(appendSpy); | ||
sinon.assert.calledOnce(defineMetadataStub); | ||
sinon.assert.calledWith(defineMetadataStub, 'fabric:transactions', [{ | ||
name: 'mockKey', | ||
returns:[{ | ||
name: 'success', | ||
schema: { | ||
type: 'string' | ||
} | ||
}] | ||
}], mockTarget); | ||
getMetadataStub.restore(); | ||
}); | ||
}); | ||
}); | ||
}); |
@@ -97,3 +97,3 @@ /* | ||
for (let i = 0; i < data.length; i++) { | ||
expect(sc0.fromBuffer(buffer[i])).to.deep.equal(data[i]); | ||
expect(sc0.fromBuffer(buffer[i])).to.deep.equal({value: data[i]}); | ||
} | ||
@@ -100,0 +100,0 @@ }); |
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
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
79908
27
2031