1 | # Concerto Core
|
2 |
|
3 | Main library for Concerto model parsing, model manager, JSON instance validation and serialization.
|
4 |
|
5 | # Installation
|
6 |
|
7 | ```
|
8 | npm install @accordproject/concerto-core --save
|
9 | ```
|
10 |
|
11 | # Create a Concerto File
|
12 |
|
13 | ```
|
14 | namespace org.acme.address
|
15 |
|
16 | /**
|
17 | * This is a concept
|
18 | */
|
19 | concept PostalAddress {
|
20 | o String streetAddress optional
|
21 | o String postalCode optional
|
22 | o String postOfficeBoxNumber optional
|
23 | o String addressRegion optional
|
24 | o String addressLocality optional
|
25 | o String addressCountry optional
|
26 | }
|
27 | ```
|
28 |
|
29 | # Create a Model Manager
|
30 |
|
31 | ```
|
32 | const ModelManager = require('@accordproject/concerto-core').ModelManager;
|
33 |
|
34 | const modelManager = new ModelManager();
|
35 | modelManager.addModelFile( concertoFileText, 'filename.cto');
|
36 | ```
|
37 |
|
38 | # Create an Instance
|
39 |
|
40 | ```
|
41 | const Factory = require('@accordproject/concerto-core').Factory;
|
42 |
|
43 | const factory = new Factory(modelManager);
|
44 | const postalAddress = factory.newConcept('org.acme.address', 'PostalAddress');
|
45 | postalAddress.streetAddress = '1 Maine Street';
|
46 | ```
|
47 |
|
48 | # Serialize an Instance to JSON
|
49 |
|
50 | ```
|
51 | const Serializer = require('@accordproject/concerto-core').Serializer;
|
52 |
|
53 | const serializer = new Serializer(factory, modelManager);
|
54 | const plainJsObject = serializer.toJSON(postalAddress); // instance will be validated
|
55 | console.log(JSON.stringify(plainJsObject, null, 4);
|
56 | ```
|
57 |
|
58 | # Deserialize an Instance from JSON
|
59 |
|
60 | ```
|
61 | const postalAddress = serializer.fromJSON(plainJsObject); // JSON will be validated
|
62 | console.log(postalAddress.streetAddress);
|
63 | ```
|
64 |
|
65 | ## License <a name="license"></a>
|
66 |
|
67 | Accord Project source code files are made available under the [Apache License, Version 2.0][apache].
|
68 | Accord Project documentation files are made available under the [Creative Commons Attribution 4.0 International License][creativecommons] (CC-BY-4.0).
|
69 |
|
70 | Copyright 2018-2019 Clause, Inc. All trademarks are the property of their respective owners. See [LF Projects Trademark Policy](https://lfprojects.org/policies/trademark-policy/).
|
71 |
|
72 | [linuxfound]: https://www.linuxfoundation.org
|
73 | [charter]: https://github.com/accordproject/cicero/blob/master/CHARTER.md
|
74 | [apmain]: https://accordproject.org/
|
75 | [apworkgroup]: https://calendar.google.com/calendar/event?action=TEMPLATE&tmeid=MjZvYzIzZHVrYnI1aDVzbjZnMHJqYmtwaGlfMjAxNzExMTVUMjEwMDAwWiBkYW5AY2xhdXNlLmlv&tmsrc=dan%40clause.io
|
76 | [apblog]: https://medium.com/@accordhq
|
77 | [apnews]: https://www.accordproject.org/news/
|
78 | [apgit]: https://github.com/accordproject/
|
79 | [apdoc]: https://docs.accordproject.org/
|
80 | [apslack]: https://accord-project-slack-signup.herokuapp.com
|
81 |
|
82 | [docspec]: https://docs.accordproject.org/docs/spec-overview.html
|
83 | [docwelcome]: https://docs.accordproject.org/docs/accordproject.html
|
84 | [dochighlevel]: https://docs.accordproject.org/docs/spec-concepts.html
|
85 | [docergo]: https://docs.accordproject.org/docs/logic-ergo.html
|
86 | [docstart]: https://docs.accordproject.org/docs/accordproject.html
|
87 | [doccicero]: https://docs.accordproject.org/docs/basic-use.html
|
88 | [docstudio]: https://docs.accordproject.org/docs/advanced-latedelivery.html
|
89 |
|
90 | [contributing]: https://github.com/accordproject/cicero/blob/master/CONTRIBUTING.md
|
91 | [developers]: https://github.com/accordproject/cicero/blob/master/DEVELOPERS.md
|
92 |
|
93 | [apache]: https://github.com/accordproject/template-studio-v2/blob/master/LICENSE
|
94 | [creativecommons]: http://creativecommons.org/licenses/by/4.0/
|