Skip to content

Commit b2e7aab

Browse files
committed
(fix) Patch for older templates before contract support
Signed-off-by: Jerome Simeon <jeromesimeon@me.com>
1 parent 1d21cf6 commit b2e7aab

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

packages/cicero-cli/lib/commands.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,11 @@ class Commands {
8484
const packageJsonExists = fs.existsSync(path.resolve(argv.template,'package.json'));
8585
let isCiceroTemplate = false;
8686
if(packageJsonExists){
87-
const packageJsonContents = JSON.parse(fs.readFileSync(path.resolve(argv.template,'package.json')),'utf8');
87+
let packageJsonContents = JSON.parse(fs.readFileSync(path.resolve(argv.template,'package.json')),'utf8');
88+
// XXX Patch/Hack for backward compatibility with old templates XXX
89+
if (!packageJsonContents.cicero) {
90+
packageJsonContents.cicero = { 'template': 'clause', 'version': '^0.3.0' };
91+
}
8892
isCiceroTemplate = packageJsonContents.cicero;
8993
}
9094

@@ -177,7 +181,12 @@ class Commands {
177181
const packageJsonExists = fs.existsSync(path.resolve(argv.template,'package.json'));
178182
let isCiceroTemplate = false;
179183
if(packageJsonExists){
180-
const packageJsonContents = JSON.parse(fs.readFileSync(path.resolve(argv.template,'package.json')),'utf8');
184+
let packageJsonContents = JSON.parse(fs.readFileSync(path.resolve(argv.template,'package.json')),'utf8');
185+
// XXX Patch/Hack for backward compatibility with old templates XXX
186+
if (!packageJsonContents.cicero) {
187+
packageJsonContents.cicero = { 'template': 'clause', 'version': '^0.3.0' };
188+
}
189+
181190
isCiceroTemplate = packageJsonContents.cicero;
182191
}
183192

packages/cicero-core/lib/template.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ class Template {
6969
*/
7070
constructor(packageJson, readme, samples) {
7171

72+
// XXX Patch/Hack for backward compatibility with old templates XXX
73+
if (!packageJson.cicero) {
74+
packageJson.cicero = { 'template': 'clause', 'version': '^0.3.0' };
75+
}
76+
7277
this.modelManager = new ModelManager();
7378
if(this.modelManager.getModelFile('org.accordproject.common') === undefined){
7479
const model = fs.readFileSync(fsPath.resolve(common), ENCODING);
@@ -1122,7 +1127,6 @@ class Template {
11221127
logger.debug(types);
11231128
return types;
11241129
}
1125-
11261130
}
11271131

11281132
module.exports = Template;

packages/cicero-engine/lib/engine.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ class Engine {
9191
}
9292

9393
const head = `
94-
__dispatch(contract,request,state,moment());
94+
__dispatch(contract,data,request,state,moment());
9595
96-
function __dispatch(contract,request,state,now) {
96+
function __dispatch(contract,data,request,state,now) {
9797
switch(request.getFullyQualifiedType()) {
9898
`;
9999

@@ -105,7 +105,7 @@ class Engine {
105105
let ns${n} = type${n}.substr(0, type${n}.lastIndexOf('.'));
106106
let clazz${n} = type${n}.substr(type${n}.lastIndexOf('.')+1);
107107
let response${n} = factory.newTransaction(ns${n}, clazz${n});
108-
let context${n} = {request: request, state: state, contract: contract, response: response${n}, emit: [], now: now};
108+
let context${n} = {request: request, state: state, contract: contract, data: data, response: response${n}, emit: [], now: now};
109109
${ele.getName()}(context${n});
110110
return { response: context${n}.response, state: context${n}.state, emit: context${n}.emit };
111111
break;`;
@@ -166,6 +166,7 @@ class Engine {
166166

167167
// add immutables to the context
168168
vm.freeze(validContract, 'contract'); // Second argument adds object to global.
169+
vm.freeze(validContract, 'data'); // Second argument adds object to global.
169170
vm.freeze(validRequest, 'request'); // Second argument adds object to global.
170171
vm.freeze(validState, 'state'); // Second argument adds object to global.
171172

0 commit comments

Comments
 (0)