Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Concerto Release 1.0 #210

Merged
merged 47 commits into from
Jan 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
944c504
(feat) investigate functional api
dselman Mar 27, 2020
5967a02
(wip) functional API
dselman Mar 28, 2020
65ce9da
(test) added first unit tests. They pass...
dselman Mar 28, 2020
386f6bd
(test) add validation failure test
dselman Mar 28, 2020
ec13525
(chore) linting fixes
dselman Mar 28, 2020
5f2afd9
(chore) remove duplicate test
dselman Mar 28, 2020
8b818a8
(test) instanceOf tests
dselman Mar 28, 2020
616032f
(feat) add Concerto export
dselman Mar 30, 2020
4d6ad25
(test) increase test coverage
dselman Mar 30, 2020
bdace1a
(test) increase test coverage
dselman Mar 31, 2020
141fa48
(test) add all positive tests
dselman Mar 31, 2020
de35be2
(fix) check dates are iso
dselman Mar 31, 2020
6e209ac
(feat) make Concerto a class
dselman Apr 9, 2020
c4769c1
feature(core) Stricter validation for atomic values
jeromesimeon Dec 11, 2019
7c231b6
feature(core) Validation rejects dates that are not in ISO 8601 format
jeromesimeon Dec 12, 2019
f3c927b
test(validation) More atomic value validation tests
jeromesimeon Dec 12, 2019
c842a7a
fix(validation) Serializing a not finite Double throws a validation e…
jeromesimeon Dec 13, 2019
bb74a59
fix(core) Adjustments for Ergo-targeted validation to support new Erg…
jeromesimeon Jan 17, 2020
a4983a9
Fixes to optional validation/serialization
jeromesimeon Jan 19, 2020
9409f0c
Fix: move optional handling for Ergo to a more common place so it get…
jeromesimeon Jan 25, 2020
a51dae1
(WIP) Remove the notion of systems table. System types are always: As…
jeromesimeon Feb 3, 2020
aa0e0af
feature(core) Remove ability to define systems model, uses a fixed de…
jeromesimeon Feb 3, 2020
b0daf2e
refactor(test) Rename systemmodel to composermodel in tests
jeromesimeon Feb 4, 2020
8876ba9
(WIP) Further simplification of the built-in system model
jeromesimeon Mar 6, 2020
fd569b2
fix(tools) Generalizes identifier fields translation in loopback
jeromesimeon Mar 9, 2020
6a2f13c
refactor(logger): Remove winston dependency
mttrbrts Mar 1, 2020
e96865a
refactor(logger): Make logger extensible
mttrbrts Mar 2, 2020
635e6b0
test(logger): Add test for logger.http
mttrbrts Mar 2, 2020
47d2c7f
chore(logger): Add missing colors dependency
mttrbrts Mar 2, 2020
eb26206
fix(logger): Typo in error logger dispatch
mttrbrts Mar 2, 2020
142af39
fix(logger): Don't clear default transport during test run
mttrbrts Mar 2, 2020
aa1e836
fix(dep) Adjust hoisted dependencies
jeromesimeon Mar 11, 2020
da7fa72
feat(valuegenerator): Generate valid values for Regex and Range meta …
mttrbrts Mar 20, 2020
a2bd4ad
(feat) remove support for system model files from API
dselman Apr 9, 2020
7f5034c
(wip) infer model
dselman Jun 1, 2020
69d0cb2
(feat) add support for type deduplication, null values and empty arrays
dselman Jun 2, 2020
6b99f11
(test) improve code cov
dselman Jun 2, 2020
501f426
(test) check generated cto
dselman Jun 2, 2020
5e35a69
(feat) heterogenous arrays
dselman Jun 3, 2020
2836963
(test) add test for type coercion of primitives in arrays
dselman Jun 3, 2020
ccdfa80
(feat) all types now have concerto.Concept as a super type
dselman Jul 6, 2020
5d2c64c
IDs & relationships for #181 (#196)
dselman Jun 30, 2020
2cf21c2
fix(doc) Update hash for changelog
jeromesimeon Aug 9, 2020
0326947
fix(tools) Fixes some failing tests after the last commit
jeromesimeon Nov 9, 2020
af46dd4
chore(tests) : fix borked tests
dselman Dec 16, 2020
8250a98
fix(merge) post-rebase adjustments
jeromesimeon Dec 23, 2020
916fee7
fix(doc) Cleans up changelog
jeromesimeon Dec 23, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3,096 changes: 1,700 additions & 1,396 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"private": true,
"devDependencies": {
"colors": "^1.4.0",
"colors": "1.4.0",
"eslint": "6.0.1",
"coveralls": "3.0.4",
"eslint": "6.0.1",
"istanbul-combine": "0.3.0",
Expand Down Expand Up @@ -94,4 +95,4 @@
}
}
}
}
}
18 changes: 3 additions & 15 deletions packages/concerto-cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ require('yargs')
describe: 'sample JSON to validate',
type: 'string'
});
yargs.option('ctoSystem', {
describe: 'system model to be used',
type: 'string'
});
yargs.option('ctoFiles', {
describe: 'array of CTO files',
type: 'string',
Expand All @@ -52,7 +48,7 @@ require('yargs')
argv = Commands.validateValidateArgs(argv);
const options = {};
options.offline = argv.offline;
return Commands.validate(argv.sample, argv.ctoSystem, argv.ctoFiles, options)
return Commands.validate(argv.sample, argv.ctoFiles, options)
.then((result) => {
Logger.info(result);
})
Expand All @@ -66,10 +62,6 @@ require('yargs')
})
.command('compile', 'generate code for a target platform', (yargs) => {
yargs.demandOption(['ctoFiles'], 'Please provide at least the CTO files');
yargs.option('ctoSystem', {
describe: 'system model to be used',
type: 'string'
});
yargs.option('ctoFiles', {
describe: 'array of CTO files',
type: 'string',
Expand Down Expand Up @@ -97,7 +89,7 @@ require('yargs')

const options = {};
options.offline = argv.offline;
return Commands.compile(argv.target, argv.ctoSystem, argv.ctoFiles, argv.output, options)
return Commands.compile(argv.target, argv.ctoFiles, argv.output, options)
.then((result) => {
Logger.info(result);
})
Expand All @@ -112,10 +104,6 @@ require('yargs')
type: 'string',
array: true
});
yargs.option('ctoSystem', {
describe: 'system model to be used',
type: 'string'
});
yargs.option('output', {
describe: 'output directory path',
type: 'string',
Expand All @@ -126,7 +114,7 @@ require('yargs')
Logger.info(`saving external models from ${argv.ctoFiles} into directory: ${argv.output}`);
}

return Commands.get(argv.ctoSystem, argv.ctoFiles, argv.output)
return Commands.get(argv.ctoFiles, argv.output)
.then((result) => {
Logger.info(result);
})
Expand Down
15 changes: 6 additions & 9 deletions packages/concerto-cli/lib/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,15 @@ class Commands {
* Validate a sample JSON against the model
*
* @param {string} sample - the sample to validate
* @param {string} ctoSystemFile - the system model file
* @param {string[]} ctoFiles - the CTO files to convert to code
* @param {object} options - optional parameters
* @param {boolean} [options.offline] - do not resolve external models
* @returns {string} serialized form of the validated JSON
*/
static async validate(sample, ctoSystemFile, ctoFiles, options) {
static async validate(sample, ctoFiles, options) {
const json = JSON.parse(fs.readFileSync(sample, 'utf8'));

const modelManager = await ModelLoader.loadModelManager(ctoSystemFile, ctoFiles, options);
const modelManager = await ModelLoader.loadModelManager(ctoFiles, options);
const factory = new Factory(modelManager);
const serializer = new Serializer(factory, modelManager);

Expand All @@ -118,14 +117,13 @@ class Commands {
* Compile the model for a given target
*
* @param {string} target - the target of the code to compile
* @param {string} ctoSystemFile - the system model file
* @param {string[]} ctoFiles - the CTO files to convert to code
* @param {string} output the output directory
* @param {object} options - optional parameters
* @param {boolean} [options.offline] - do not resolve external models
*/
static async compile(target, ctoSystemFile, ctoFiles, output, options) {
const modelManager = await ModelLoader.loadModelManager(ctoSystemFile, ctoFiles, options);
static async compile(target, ctoFiles, output, options) {
const modelManager = await ModelLoader.loadModelManager(ctoFiles, options);

let visitor = null;

Expand Down Expand Up @@ -165,12 +163,11 @@ class Commands {
* Fetches all external for a set of models dependencies and
* saves all the models to a target directory
*
* @param {string} ctoSystemFile the system model
* @param {string[]} ctoFiles the CTO files (can be local file paths or URLs)
* @param {string} output the output directory
*/
static async get(ctoSystemFile, ctoFiles, output) {
const modelManager = await ModelLoader.loadModelManager(ctoSystemFile, ctoFiles);
static async get(ctoFiles, output) {
const modelManager = await ModelLoader.loadModelManager(ctoFiles);
mkdirp.sync(output);
modelManager.writeModelsToFileSystem(output);
return `Loaded external models in '${output}'.`;
Expand Down
40 changes: 15 additions & 25 deletions packages/concerto-cli/test/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ const Commands = require('../lib/commands');
describe('cicero-cli', () => {
const models = [path.resolve(__dirname, 'models/dom.cto'),path.resolve(__dirname, 'models/money.cto')];
const offlineModels = [path.resolve(__dirname, 'models/contract.cto'),path.resolve(__dirname, 'models/dom.cto'),path.resolve(__dirname, 'models/money.cto')];
const hlModel = path.resolve(__dirname, 'models/org.hyperledger.composer.system.cto');
const sample1 = path.resolve(__dirname, 'data/sample1.json');
const sample2 = path.resolve(__dirname, 'data/sample2.json');
const sampleText1 = fs.readFileSync(sample1, 'utf8');
Expand All @@ -55,30 +54,30 @@ describe('cicero-cli', () => {

describe('#validate', () => {
it('should validate against a model', async () => {
const result = await Commands.validate(sample1, null, models, {offline:false});
const result = await Commands.validate(sample1, models, {offline:false});
JSON.parse(result).should.deep.equal(JSON.parse(sampleText1));
});

it('should fail to validate against a model', async () => {
try {
const result = await Commands.validate(sample2, null, models, {offline:false});
const result = await Commands.validate(sample2, models, {offline:false});
JSON.parse(result).should.deep.equal(JSON.parse(sampleText2));
} catch (err) {
err.message.should.equal('Instance undefined invalid enum value true for field CurrencyCode');
err.message.should.equal('Instance org.accordproject.money.MonetaryAmount#null invalid enum value true for field CurrencyCode');
}
});

it('should validate against a model (offline)', async () => {
const result = await Commands.validate(sample1, null, offlineModels, {offline:true});
const result = await Commands.validate(sample1, offlineModels, {offline:true});
JSON.parse(result).should.deep.equal(JSON.parse(sampleText1));
});

it('should fail to validate against a model (offline)', async () => {
try {
const result = await Commands.validate(sample2, null, offlineModels, {offline:true});
const result = await Commands.validate(sample2, offlineModels, {offline:true});
JSON.parse(result).should.deep.equal(JSON.parse(sampleText2));
} catch (err) {
err.message.should.equal('Instance undefined invalid enum value true for field CurrencyCode');
err.message.should.equal('Instance org.accordproject.money.MonetaryAmount#null invalid enum value true for field CurrencyCode');
}
});

Expand Down Expand Up @@ -111,43 +110,43 @@ describe('cicero-cli', () => {

it('should compile to a Go model', async () => {
const dir = await tmp.dir({ unsafeCleanup: true});
await Commands.compile('Go', null, models, dir.path, {offline:false});
await Commands.compile('Go', models, dir.path, {offline:false});
fs.readdirSync(dir.path).length.should.be.above(0);
dir.cleanup();
});
it('should compile to a PlantUML model', async () => {
const dir = await tmp.dir({ unsafeCleanup: true});
await Commands.compile('PlantUML', null, models, dir.path, {offline:false});
await Commands.compile('PlantUML', models, dir.path, {offline:false});
fs.readdirSync(dir.path).length.should.be.above(0);
dir.cleanup();
});
it('should compile to a Typescript model', async () => {
const dir = await tmp.dir({ unsafeCleanup: true});
await Commands.compile('Typescript', null, models, dir.path, {offline:false});
await Commands.compile('Typescript', models, dir.path, {offline:false});
fs.readdirSync(dir.path).length.should.be.above(0);
dir.cleanup();
});
it('should compile to a Java model', async () => {
const dir = await tmp.dir({ unsafeCleanup: true});
await Commands.compile('Java', null, models, dir.path);
await Commands.compile('Java', models, dir.path);
fs.readdirSync(dir.path).length.should.be.above(0);
dir.cleanup();
});
it('should compile to a JSONSchema model', async () => {
const dir = await tmp.dir({ unsafeCleanup: true});
await Commands.compile('JSONSchema', null, models, dir.path, {offline:false});
await Commands.compile('JSONSchema', models, dir.path, {offline:false});
fs.readdirSync(dir.path).length.should.be.above(0);
dir.cleanup();
});
it('should compile to a XMLSchema model', async () => {
const dir = await tmp.dir({ unsafeCleanup: true});
await Commands.compile('XMLSchema', null, models, dir.path, {offline:false});
await Commands.compile('XMLSchema', models, dir.path, {offline:false});
fs.readdirSync(dir.path).length.should.be.above(0);
dir.cleanup();
});
it('should not compile to an unknown model', async () => {
const dir = await tmp.dir({ unsafeCleanup: true});
await Commands.compile('BLAH', null, models, dir.path, {offline:false});
await Commands.compile('BLAH', models, dir.path, {offline:false});
fs.readdirSync(dir.path).length.should.be.equal(0);
dir.cleanup();
});
Expand All @@ -156,7 +155,7 @@ describe('cicero-cli', () => {
describe('#get', () => {
it('should save external dependencies', async () => {
const dir = await tmp.dir({ unsafeCleanup: true});
await Commands.get(null, models, dir.path);
await Commands.get(models, dir.path);
fs.readdirSync(dir.path).should.eql([
'@models.accordproject.org.cicero.contract.cto',
'dom.cto',
Expand All @@ -167,7 +166,7 @@ describe('cicero-cli', () => {

it('should save external dependencies for an external model', async () => {
const dir = await tmp.dir({ unsafeCleanup: true});
await Commands.get(null,['https://models.accordproject.org/patents/patent.cto'], dir.path);
await Commands.get(['https://models.accordproject.org/patents/patent.cto'], dir.path);
fs.readdirSync(dir.path).should.eql([
'@models.accordproject.org.address.cto',
'@models.accordproject.org.geo.cto',
Expand All @@ -181,14 +180,5 @@ describe('cicero-cli', () => {
]);
dir.cleanup();
});

it('should fail saving external dependencies for an external model but with the wrong system model', async () => {
const dir = await tmp.dir({ unsafeCleanup: true});
try {
await Commands.get(hlModel,['https://models.accordproject.org/patents/patent.cto'], dir.path);
} catch (err) {
err.message.should.contain('Relationship transactionInvoked must be to an asset or participant, but is to org.hyperledger.composer.system.Transaction');
}
});
});
});