@accordproject/concerto-vocabulary 2.0.0-alpha.1 → 2.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +7 -2
- package/lib/vocabularymanager.js +78 -2
- package/package.json +6 -4
- package/types/index.d.ts +3 -2
- package/types/lib/vocabularymanager.d.ts +13 -1
package/index.js
CHANGED
|
@@ -21,5 +21,10 @@
|
|
|
21
21
|
* @module concerto-vocabulary
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
const VocabularyManager = require('./lib/vocabularymanager');
|
|
25
|
+
const Vocabulary = require('./lib/vocabulary');
|
|
26
|
+
|
|
27
|
+
module.exports = {
|
|
28
|
+
VocabularyManager,
|
|
29
|
+
Vocabulary
|
|
30
|
+
};
|
package/lib/vocabularymanager.js
CHANGED
|
@@ -23,7 +23,7 @@ const Vocabulary = require('./vocabulary');
|
|
|
23
23
|
* @returns {string} modified string
|
|
24
24
|
*/
|
|
25
25
|
function camelCaseToSentence(text) {
|
|
26
|
-
const result = text.replace(
|
|
26
|
+
const result = text.replace(/([A-Z]+)/g, ' $1').trim();
|
|
27
27
|
return result.charAt(0).toUpperCase() + result.slice(1);
|
|
28
28
|
}
|
|
29
29
|
|
|
@@ -57,7 +57,7 @@ class VocabularyManager {
|
|
|
57
57
|
* @returns {string} the term or null if it does not exist
|
|
58
58
|
*/
|
|
59
59
|
static englishMissingTermGenerator(namespace, locale, declarationName, propertyName) {
|
|
60
|
-
const firstPart = propertyName ? propertyName + ' of the' : '';
|
|
60
|
+
const firstPart = propertyName ? propertyName.replace('$', '') + ' of the' : '';
|
|
61
61
|
return camelCaseToSentence(firstPart + declarationName);
|
|
62
62
|
}
|
|
63
63
|
|
|
@@ -80,6 +80,7 @@ class VocabularyManager {
|
|
|
80
80
|
/**
|
|
81
81
|
* Adds a vocabulary to the vocabulary manager
|
|
82
82
|
* @param {string} contents the YAML string for the vocabulary
|
|
83
|
+
* @returns {Vocabulary} the vocabulary the was added
|
|
83
84
|
*/
|
|
84
85
|
addVocabulary(contents) {
|
|
85
86
|
if (!contents) {
|
|
@@ -92,6 +93,7 @@ class VocabularyManager {
|
|
|
92
93
|
throw new Error('Vocabulary has already been added.');
|
|
93
94
|
}
|
|
94
95
|
this.vocabularies[voc.getIdentifier()] = voc;
|
|
96
|
+
return voc;
|
|
95
97
|
}
|
|
96
98
|
|
|
97
99
|
/**
|
|
@@ -206,10 +208,84 @@ class VocabularyManager {
|
|
|
206
208
|
}
|
|
207
209
|
}
|
|
208
210
|
|
|
211
|
+
/**
|
|
212
|
+
* Creates a DecoractorCommandSet with @Term decorators
|
|
213
|
+
* to decorate all model elements based on the vocabulary for a locale.
|
|
214
|
+
* Pass the return value to the DecoratorManager.decorateModel to apply
|
|
215
|
+
* the decorators to a ModelManager.
|
|
216
|
+
* @param {ModelManager} modelManager - the Model Manager
|
|
217
|
+
* @param {string} locale the BCP-47 locale identifier
|
|
218
|
+
* @returns {*} the decorator command set used to decorate the model.
|
|
219
|
+
*/
|
|
220
|
+
generateDecoratorCommands(modelManager, locale) {
|
|
221
|
+
const decoratorCommandSet = {
|
|
222
|
+
'$class': 'org.accordproject.decoratorcommands.DecoratorCommandSet',
|
|
223
|
+
'name': `terms-${locale}`,
|
|
224
|
+
'version': '1.0.0',
|
|
225
|
+
'commands': []
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
modelManager.getModelFiles().forEach(model => {
|
|
229
|
+
model.getAllDeclarations().forEach(decl => {
|
|
230
|
+
const term = this.resolveTerm(modelManager, model.getNamespace(), locale, decl.getName());
|
|
231
|
+
if (term) {
|
|
232
|
+
decoratorCommandSet.commands.push({
|
|
233
|
+
'$class': 'org.accordproject.decoratorcommands.Command',
|
|
234
|
+
'type': 'UPSERT',
|
|
235
|
+
'target': {
|
|
236
|
+
'$class': 'org.accordproject.decoratorcommands.CommandTarget',
|
|
237
|
+
'namespace': model.getNamespace(),
|
|
238
|
+
'declaration': decl.getName(),
|
|
239
|
+
},
|
|
240
|
+
'decorator': {
|
|
241
|
+
'$class': 'concerto.metamodel.Decorator',
|
|
242
|
+
'name': 'Term',
|
|
243
|
+
'arguments': [
|
|
244
|
+
{
|
|
245
|
+
'$class': 'concerto.metamodel.DecoratorString',
|
|
246
|
+
'value': term
|
|
247
|
+
},
|
|
248
|
+
]
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
decl.getProperties().forEach(property => {
|
|
254
|
+
const propertyTerm = this.resolveTerm(modelManager, model.getNamespace(), locale, decl.getName(), property.getName());
|
|
255
|
+
|
|
256
|
+
if (propertyTerm) {
|
|
257
|
+
decoratorCommandSet.commands.push({
|
|
258
|
+
'$class': 'org.accordproject.decoratorcommands.Command',
|
|
259
|
+
'type': 'UPSERT',
|
|
260
|
+
'target': {
|
|
261
|
+
'$class': 'org.accordproject.decoratorcommands.CommandTarget',
|
|
262
|
+
'namespace': model.getNamespace(),
|
|
263
|
+
'declaration': decl.getName(),
|
|
264
|
+
'property': property.getName()
|
|
265
|
+
},
|
|
266
|
+
'decorator': {
|
|
267
|
+
'$class': 'concerto.metamodel.Decorator',
|
|
268
|
+
'name': 'Term',
|
|
269
|
+
'arguments': [
|
|
270
|
+
{
|
|
271
|
+
'$class': 'concerto.metamodel.DecoratorString',
|
|
272
|
+
'value': propertyTerm
|
|
273
|
+
},
|
|
274
|
+
]
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
return decoratorCommandSet;
|
|
282
|
+
}
|
|
283
|
+
|
|
209
284
|
/**
|
|
210
285
|
* Validates the terms in the vocabulary against the namespaces and declarations
|
|
211
286
|
* within a ModelManager
|
|
212
287
|
* @param {ModelManager} modelManager - the Model Manager
|
|
288
|
+
* @param {string} locale the BCP-47 locale identifier
|
|
213
289
|
* @returns {*} the result of validation
|
|
214
290
|
*/
|
|
215
291
|
validate(modelManager) {
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@accordproject/concerto-vocabulary",
|
|
3
|
-
"version": "2.0.0-
|
|
3
|
+
"version": "2.0.0-beta.2",
|
|
4
4
|
"description": "Associate human-readable text to model declarations",
|
|
5
5
|
"homepage": "https://github.com/accordproject/concerto",
|
|
6
6
|
"engines": {
|
|
7
|
-
"node": ">=
|
|
7
|
+
"node": ">=14",
|
|
8
8
|
"npm": ">=6"
|
|
9
9
|
},
|
|
10
10
|
"main": "index.js",
|
|
@@ -16,11 +16,12 @@
|
|
|
16
16
|
"licchk": "license-check-and-add",
|
|
17
17
|
"postlicchk": "npm run doc",
|
|
18
18
|
"doc": "jsdoc --pedantic --recurse -c jsdoc.json",
|
|
19
|
+
"postdoc": "npm run build:types",
|
|
19
20
|
"test": "nyc mocha --recursive -t 10000",
|
|
20
21
|
"test:watch": "nyc mocha --watch --recursive -t 10000",
|
|
21
22
|
"mocha": "mocha --recursive -t 10000",
|
|
22
23
|
"nyc": "nyc mocha --recursive -t 10000",
|
|
23
|
-
"build:types": "
|
|
24
|
+
"build:types": "tsc index.js --declaration --allowJs --emitDeclarationOnly --outDir types"
|
|
24
25
|
},
|
|
25
26
|
"repository": {
|
|
26
27
|
"type": "git",
|
|
@@ -44,7 +45,8 @@
|
|
|
44
45
|
"mocha": "8.3.2",
|
|
45
46
|
"nyc": "15.1.0",
|
|
46
47
|
"sinon": "12.0.0",
|
|
47
|
-
"sinon-chai": "3.7.0"
|
|
48
|
+
"sinon-chai": "3.7.0",
|
|
49
|
+
"typescript": "4.6.3"
|
|
48
50
|
},
|
|
49
51
|
"dependencies": {
|
|
50
52
|
"yaml": "2.0.0-9"
|
package/types/index.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import VocabularyManager = require("./lib/vocabularymanager");
|
|
2
|
+
import Vocabulary = require("./lib/vocabulary");
|
|
3
|
+
export { VocabularyManager, Vocabulary };
|
|
@@ -51,8 +51,9 @@ declare class VocabularyManager {
|
|
|
51
51
|
/**
|
|
52
52
|
* Adds a vocabulary to the vocabulary manager
|
|
53
53
|
* @param {string} contents the YAML string for the vocabulary
|
|
54
|
+
* @returns {Vocabulary} the vocabulary the was added
|
|
54
55
|
*/
|
|
55
|
-
addVocabulary(contents: string):
|
|
56
|
+
addVocabulary(contents: string): Vocabulary;
|
|
56
57
|
/**
|
|
57
58
|
* Gets a vocabulary for a given namespace plus locale
|
|
58
59
|
* @param {string} namespace the namespace for the vocabulary
|
|
@@ -96,10 +97,21 @@ declare class VocabularyManager {
|
|
|
96
97
|
* @returns {string} the term or null if it does not exist
|
|
97
98
|
*/
|
|
98
99
|
getTerm(namespace: string, locale: string, declarationName: string, propertyName?: string): string;
|
|
100
|
+
/**
|
|
101
|
+
* Creates a DecoractorCommandSet with @Term decorators
|
|
102
|
+
* to decorate all model elements based on the vocabulary for a locale.
|
|
103
|
+
* Pass the return value to the DecoratorManager.decorateModel to apply
|
|
104
|
+
* the decorators to a ModelManager.
|
|
105
|
+
* @param {ModelManager} modelManager - the Model Manager
|
|
106
|
+
* @param {string} locale the BCP-47 locale identifier
|
|
107
|
+
* @returns {*} the decorator command set used to decorate the model.
|
|
108
|
+
*/
|
|
109
|
+
generateDecoratorCommands(modelManager: ModelManager, locale: string): any;
|
|
99
110
|
/**
|
|
100
111
|
* Validates the terms in the vocabulary against the namespaces and declarations
|
|
101
112
|
* within a ModelManager
|
|
102
113
|
* @param {ModelManager} modelManager - the Model Manager
|
|
114
|
+
* @param {string} locale the BCP-47 locale identifier
|
|
103
115
|
* @returns {*} the result of validation
|
|
104
116
|
*/
|
|
105
117
|
validate(modelManager: ModelManager): any;
|