@accordproject/concerto-vocabulary 5.0.0 → 5.1.0
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/dist/esm/chunk-BJEPALVN.mjs +143 -0
- package/dist/esm/chunk-BJEPALVN.mjs.map +7 -0
- package/dist/esm/chunk-M2X75AXU.mjs +13 -0
- package/dist/esm/chunk-M2X75AXU.mjs.map +7 -0
- package/dist/esm/{chunk-3VH3UOGB.mjs → chunk-X3NNESEP.mjs} +19 -6
- package/dist/esm/chunk-X3NNESEP.mjs.map +7 -0
- package/dist/esm/{chunk-7RW3VXN4.mjs → chunk-ZZFBMCTJ.mjs} +5 -3
- package/dist/esm/chunk-ZZFBMCTJ.mjs.map +7 -0
- package/dist/esm/index.mjs +4 -2
- package/dist/esm/vocabulary.mjs +2 -1
- package/dist/esm/vocabularymanager.mjs +4 -2
- package/dist/esm/vocabularyvalidator.mjs +10 -0
- package/dist/esm/vocabularyvalidator.mjs.map +7 -0
- package/dist/esm/yamlparser.mjs +1 -0
- package/dist/esm-browser/{chunk-DSN2E4MW.mjs → chunk-CSZFRMP7.mjs} +2 -36
- package/dist/esm-browser/chunk-CSZFRMP7.mjs.map +7 -0
- package/dist/esm-browser/{chunk-CKXQ5OWJ.mjs → chunk-LCSHHQ7B.mjs} +5 -3
- package/dist/esm-browser/chunk-LCSHHQ7B.mjs.map +7 -0
- package/dist/esm-browser/{chunk-2FE6COGH.mjs → chunk-LF5LTG3B.mjs} +23 -8
- package/dist/esm-browser/{chunk-2FE6COGH.mjs.map → chunk-LF5LTG3B.mjs.map} +2 -2
- package/dist/esm-browser/chunk-NPUAPXXA.mjs +42 -0
- package/dist/esm-browser/chunk-NPUAPXXA.mjs.map +7 -0
- package/dist/esm-browser/chunk-PFDH5LIN.mjs +229 -0
- package/dist/esm-browser/chunk-PFDH5LIN.mjs.map +7 -0
- package/dist/esm-browser/index.mjs +5 -3
- package/dist/esm-browser/index.mjs.map +1 -1
- package/dist/esm-browser/vocabulary.mjs +1 -1
- package/dist/esm-browser/vocabularymanager.mjs +5 -3
- package/dist/esm-browser/vocabularyvalidator.mjs +9 -0
- package/dist/esm-browser/vocabularyvalidator.mjs.map +7 -0
- package/dist/esm-browser/yamlparser.mjs +2 -1
- package/dist/vocabulary.d.ts +3 -1
- package/dist/vocabulary.js +4 -2
- package/dist/vocabulary.js.map +1 -1
- package/dist/vocabularymanager.d.ts +4 -2
- package/dist/vocabularymanager.js +19 -4
- package/dist/vocabularymanager.js.map +1 -1
- package/dist/vocabularyvalidator.d.ts +12 -0
- package/dist/vocabularyvalidator.js +177 -0
- package/dist/vocabularyvalidator.js.map +1 -0
- package/package.json +3 -2
- package/dist/esm/chunk-3VH3UOGB.mjs.map +0 -7
- package/dist/esm/chunk-7RW3VXN4.mjs.map +0 -7
- package/dist/esm-browser/chunk-CKXQ5OWJ.mjs.map +0 -7
- package/dist/esm-browser/chunk-DSN2E4MW.mjs.map +0 -7
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { createRequire as __createRequire } from "module";
|
|
2
|
+
const require = __createRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
__require
|
|
5
|
+
} from "./chunk-M2X75AXU.mjs";
|
|
6
|
+
|
|
7
|
+
// src/vocabularyvalidator.ts
|
|
8
|
+
import YAML from "yaml";
|
|
9
|
+
var bcp47 = __require("bcp47");
|
|
10
|
+
function isNonEmptyStringScalar(node) {
|
|
11
|
+
return YAML.isScalar(node) && typeof node.value === "string" && node.value.length > 0;
|
|
12
|
+
}
|
|
13
|
+
function checkValueIsString(value, path, errors) {
|
|
14
|
+
if (YAML.isAlias(value)) {
|
|
15
|
+
errors.push({ path, message: `${path} must not use a YAML alias` });
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
if (!isNonEmptyStringScalar(value)) {
|
|
19
|
+
errors.push({ path, message: `${path} must be a non-empty string scalar` });
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
function findPair(pairs, key) {
|
|
25
|
+
return pairs.find((p) => YAML.isScalar(p.key) && p.key.value === key);
|
|
26
|
+
}
|
|
27
|
+
function validateSyntax(yamlStr, errors) {
|
|
28
|
+
const doc = YAML.parseDocument(yamlStr);
|
|
29
|
+
for (const err of doc.errors) {
|
|
30
|
+
errors.push({ path: "", message: `YAML syntax error: ${err.message}` });
|
|
31
|
+
}
|
|
32
|
+
return errors.length > 0 ? null : doc;
|
|
33
|
+
}
|
|
34
|
+
function validateNamespace(pairs, errors) {
|
|
35
|
+
const pair = findPair(pairs, "namespace");
|
|
36
|
+
if (!pair) {
|
|
37
|
+
errors.push({ path: "namespace", message: "namespace is required" });
|
|
38
|
+
} else {
|
|
39
|
+
checkValueIsString(pair.value, "namespace", errors);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
var STRUCTURAL_KEYS = /* @__PURE__ */ new Set(["namespace", "locale", "declarations"]);
|
|
43
|
+
function validateTopLevelNonStructuralValues(pairs, errors) {
|
|
44
|
+
for (const pair of pairs) {
|
|
45
|
+
const key = YAML.isScalar(pair.key) ? pair.key.value : null;
|
|
46
|
+
if (!key || STRUCTURAL_KEYS.has(key)) continue;
|
|
47
|
+
checkValueIsString(pair.value, key, errors);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function validatePropertyEntries(seq, declIndex, errors) {
|
|
51
|
+
seq.items.forEach((item, j) => {
|
|
52
|
+
const path = `declarations[${declIndex}].properties[${j}]`;
|
|
53
|
+
if (!YAML.isMap(item)) {
|
|
54
|
+
errors.push({ path, message: `${path} must be a mapping` });
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const propPairs = item.items;
|
|
58
|
+
if (propPairs.length === 0) {
|
|
59
|
+
errors.push({ path, message: `${path} must not be an empty mapping` });
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
for (const pair of propPairs) {
|
|
63
|
+
const key = YAML.isScalar(pair.key) ? pair.key.value : null;
|
|
64
|
+
if (!key) continue;
|
|
65
|
+
checkValueIsString(pair.value, `${path}.${key}`, errors);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
function validateDeclarationEntries(seq, errors) {
|
|
70
|
+
seq.items.forEach((item, i) => {
|
|
71
|
+
if (!YAML.isMap(item)) {
|
|
72
|
+
errors.push({ path: `declarations[${i}]`, message: `declarations[${i}] must be a mapping` });
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const declPairs = item.items;
|
|
76
|
+
if (declPairs.length === 0) {
|
|
77
|
+
errors.push({ path: `declarations[${i}]`, message: `declarations[${i}] must not be an empty mapping` });
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const primaryPair = declPairs[0];
|
|
81
|
+
if (primaryPair) {
|
|
82
|
+
const key = YAML.isScalar(primaryPair.key) ? primaryPair.key.value : null;
|
|
83
|
+
if (key) checkValueIsString(primaryPair.value, `declarations[${i}].${key}`, errors);
|
|
84
|
+
}
|
|
85
|
+
for (const pair of declPairs.slice(1)) {
|
|
86
|
+
const key = YAML.isScalar(pair.key) ? pair.key.value : null;
|
|
87
|
+
if (!key) continue;
|
|
88
|
+
if (key === "properties") {
|
|
89
|
+
if (!YAML.isSeq(pair.value)) {
|
|
90
|
+
errors.push({ path: `declarations[${i}].properties`, message: `declarations[${i}].properties must be a sequence` });
|
|
91
|
+
} else if (pair.value.flow) {
|
|
92
|
+
errors.push({ path: `declarations[${i}].properties`, message: `declarations[${i}].properties must use block sequence style` });
|
|
93
|
+
} else {
|
|
94
|
+
validatePropertyEntries(pair.value, i, errors);
|
|
95
|
+
}
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
checkValueIsString(pair.value, `declarations[${i}].${key}`, errors);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
function validateDeclarations(pairs, errors) {
|
|
103
|
+
const pair = findPair(pairs, "declarations");
|
|
104
|
+
if (!pair) {
|
|
105
|
+
errors.push({ path: "declarations", message: "declarations is required" });
|
|
106
|
+
} else if (!YAML.isSeq(pair.value)) {
|
|
107
|
+
errors.push({ path: "declarations", message: "declarations must be a sequence" });
|
|
108
|
+
} else if (pair.value.flow) {
|
|
109
|
+
errors.push({ path: "declarations", message: "declarations must use block sequence style" });
|
|
110
|
+
} else {
|
|
111
|
+
validateDeclarationEntries(pair.value, errors);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
function validateLocale(pairs, errors) {
|
|
115
|
+
const pair = findPair(pairs, "locale");
|
|
116
|
+
if (!pair) {
|
|
117
|
+
errors.push({ path: "locale", message: "locale is required" });
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
if (!checkValueIsString(pair.value, "locale", errors)) return;
|
|
121
|
+
const val = pair.value.value;
|
|
122
|
+
if (!bcp47.parse(val)) {
|
|
123
|
+
errors.push({ path: "locale", message: `locale is not a valid BCP-47 tag: '${val}'` });
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
function validateVocabularyYaml(yamlStr) {
|
|
127
|
+
const errors = [];
|
|
128
|
+
const doc = validateSyntax(yamlStr, errors);
|
|
129
|
+
if (!doc) {
|
|
130
|
+
return { errors };
|
|
131
|
+
}
|
|
132
|
+
const pairs = YAML.isMap(doc.contents) ? doc.contents.items : [];
|
|
133
|
+
validateNamespace(pairs, errors);
|
|
134
|
+
validateLocale(pairs, errors);
|
|
135
|
+
validateDeclarations(pairs, errors);
|
|
136
|
+
validateTopLevelNonStructuralValues(pairs, errors);
|
|
137
|
+
return { errors };
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export {
|
|
141
|
+
validateVocabularyYaml
|
|
142
|
+
};
|
|
143
|
+
//# sourceMappingURL=chunk-BJEPALVN.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/vocabularyvalidator.ts"],
|
|
4
|
+
"sourcesContent": ["/*\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport YAML from 'yaml';\n// eslint-disable-next-line @typescript-eslint/no-var-requires\nconst bcp47 = require('bcp47') as { parse: (tag: string) => object | null };\n\nexport interface VocabularyValidationError {\n path: string;\n message: string;\n}\n\ntype Pairs = YAML.Pair[];\n\nfunction isNonEmptyStringScalar(node: unknown): boolean {\n return YAML.isScalar(node) && typeof (node as YAML.Scalar).value === 'string' && ((node as YAML.Scalar).value as string).length > 0;\n}\n\nfunction checkValueIsString(value: unknown, path: string, errors: VocabularyValidationError[]): boolean {\n if (YAML.isAlias(value as YAML.Node)) {\n errors.push({ path, message: `${path} must not use a YAML alias` });\n return false;\n }\n if (!isNonEmptyStringScalar(value)) {\n errors.push({ path, message: `${path} must be a non-empty string scalar` });\n return false;\n }\n return true;\n}\n\nfunction findPair(pairs: Pairs, key: string): YAML.Pair | undefined {\n return pairs.find(p => YAML.isScalar(p.key) && (p.key as YAML.Scalar).value === key) as YAML.Pair | undefined;\n}\n\n// checks parse errors only \u2014 structurally valid YAML (e.g. sequence or mapping keys) can still pass this\nfunction validateSyntax(yamlStr: string, errors: VocabularyValidationError[]): YAML.Document | null {\n const doc = YAML.parseDocument(yamlStr);\n for (const err of doc.errors) {\n errors.push({ path: '', message: `YAML syntax error: ${err.message}` });\n }\n return errors.length > 0 ? null : doc;\n}\n\nfunction validateNamespace(pairs: Pairs, errors: VocabularyValidationError[]): void {\n const pair = findPair(pairs, 'namespace');\n if (!pair) {\n errors.push({ path: 'namespace', message: 'namespace is required' });\n } else {\n checkValueIsString(pair.value, 'namespace', errors);\n }\n}\n\nconst STRUCTURAL_KEYS = new Set(['namespace', 'locale', 'declarations']);\n\n// validates any top-level key outside namespace/locale/declarations \u2014 these are namespace-level terms (e.g. tooltip, description)\n// each must be a non-empty string scalar; sequences, mappings, booleans, numbers, and null are all invalid\nfunction validateTopLevelNonStructuralValues(pairs: Pairs, errors: VocabularyValidationError[]): void {\n for (const pair of pairs) {\n const key = YAML.isScalar(pair.key) ? (pair.key as YAML.Scalar).value as string : null;\n if (!key || STRUCTURAL_KEYS.has(key)) continue;\n checkValueIsString(pair.value, key, errors);\n }\n}\n\n// validates each item in a declaration's properties sequence\n// entries must be mappings; all values (primary term and extras like tooltip) must be non-empty string scalars\nfunction validatePropertyEntries(seq: YAML.YAMLSeq, declIndex: number, errors: VocabularyValidationError[]): void {\n seq.items.forEach((item, j) => {\n const path = `declarations[${declIndex}].properties[${j}]`;\n if (!YAML.isMap(item)) {\n errors.push({ path, message: `${path} must be a mapping` });\n return;\n }\n const propPairs = (item as YAML.YAMLMap).items as YAML.Pair[];\n if (propPairs.length === 0) {\n errors.push({ path, message: `${path} must not be an empty mapping` });\n return;\n }\n for (const pair of propPairs) {\n const key = YAML.isScalar(pair.key) ? (pair.key as YAML.Scalar).value as string : null;\n if (!key) continue;\n checkValueIsString(pair.value, `${path}.${key}`, errors);\n }\n });\n}\n\n// validates each declaration entry: primary term (first key, e.g. Vehicle) must be a string scalar,\n// extra named terms (e.g. tooltip, description) must be string scalars,\n// properties if present must be a block sequence\nfunction validateDeclarationEntries(seq: YAML.YAMLSeq, errors: VocabularyValidationError[]): void {\n seq.items.forEach((item, i) => {\n if (!YAML.isMap(item)) {\n errors.push({ path: `declarations[${i}]`, message: `declarations[${i}] must be a mapping` });\n return;\n }\n const declPairs = (item as YAML.YAMLMap).items as YAML.Pair[];\n if (declPairs.length === 0) {\n errors.push({ path: `declarations[${i}]`, message: `declarations[${i}] must not be an empty mapping` });\n return;\n }\n const primaryPair = declPairs[0];\n if (primaryPair) {\n const key = YAML.isScalar(primaryPair.key) ? (primaryPair.key as YAML.Scalar).value as string : null;\n if (key) checkValueIsString(primaryPair.value, `declarations[${i}].${key}`, errors);\n }\n for (const pair of declPairs.slice(1)) {\n const key = YAML.isScalar(pair.key) ? (pair.key as YAML.Scalar).value as string : null;\n if (!key) continue;\n if (key === 'properties') {\n if (!YAML.isSeq(pair.value)) {\n errors.push({ path: `declarations[${i}].properties`, message: `declarations[${i}].properties must be a sequence` });\n } else if ((pair.value as YAML.YAMLSeq).flow) {\n errors.push({ path: `declarations[${i}].properties`, message: `declarations[${i}].properties must use block sequence style` });\n } else {\n validatePropertyEntries(pair.value, i, errors);\n }\n continue;\n }\n checkValueIsString(pair.value, `declarations[${i}].${key}`, errors);\n }\n });\n}\n\n// entry point for declarations validation \u2014 checks the field exists, is a block sequence, then delegates to entry validation\nfunction validateDeclarations(pairs: Pairs, errors: VocabularyValidationError[]): void {\n const pair = findPair(pairs, 'declarations');\n if (!pair) {\n errors.push({ path: 'declarations', message: 'declarations is required' });\n } else if (!YAML.isSeq(pair.value)) {\n errors.push({ path: 'declarations', message: 'declarations must be a sequence' });\n } else if ((pair.value as YAML.YAMLSeq).flow) {\n errors.push({ path: 'declarations', message: 'declarations must use block sequence style' });\n } else {\n validateDeclarationEntries(pair.value, errors);\n }\n}\n\nfunction validateLocale(pairs: Pairs, errors: VocabularyValidationError[]): void {\n const pair = findPair(pairs, 'locale');\n if (!pair) {\n errors.push({ path: 'locale', message: 'locale is required' });\n return;\n }\n if (!checkValueIsString(pair.value, 'locale', errors)) return;\n const val = (pair.value as YAML.Scalar).value as string;\n if (!bcp47.parse(val)) {\n errors.push({ path: 'locale', message: `locale is not a valid BCP-47 tag: '${val}'` });\n }\n}\n\n/**\n * Validates vocabulary YAML, collecting all structural and type errors without coercing values.\n * @param {string} yamlStr the YAML string to validate\n * @returns {{ errors: VocabularyValidationError[] }}\n */\nexport function validateVocabularyYaml(yamlStr: string): { errors: VocabularyValidationError[] } {\n const errors: VocabularyValidationError[] = [];\n\n const doc = validateSyntax(yamlStr, errors);\n if (!doc) {\n return { errors };\n }\n\n const pairs: Pairs = YAML.isMap(doc.contents) ? doc.contents.items : [];\n\n validateNamespace(pairs, errors);\n validateLocale(pairs, errors);\n validateDeclarations(pairs, errors);\n validateTopLevelNonStructuralValues(pairs, errors);\n\n return { errors };\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;AAcA,OAAO,UAAU;AAEjB,IAAM,QAAQ,UAAQ,OAAO;AAS7B,SAAS,uBAAuB,MAAwB;AACpD,SAAO,KAAK,SAAS,IAAI,KAAK,OAAQ,KAAqB,UAAU,YAAc,KAAqB,MAAiB,SAAS;AACtI;AAEA,SAAS,mBAAmB,OAAgB,MAAc,QAA8C;AACpG,MAAI,KAAK,QAAQ,KAAkB,GAAG;AAClC,WAAO,KAAK,EAAE,MAAM,SAAS,GAAG,IAAI,6BAA6B,CAAC;AAClE,WAAO;AAAA,EACX;AACA,MAAI,CAAC,uBAAuB,KAAK,GAAG;AAChC,WAAO,KAAK,EAAE,MAAM,SAAS,GAAG,IAAI,qCAAqC,CAAC;AAC1E,WAAO;AAAA,EACX;AACA,SAAO;AACX;AAEA,SAAS,SAAS,OAAc,KAAoC;AAChE,SAAO,MAAM,KAAK,OAAK,KAAK,SAAS,EAAE,GAAG,KAAM,EAAE,IAAoB,UAAU,GAAG;AACvF;AAGA,SAAS,eAAe,SAAiB,QAA2D;AAChG,QAAM,MAAM,KAAK,cAAc,OAAO;AACtC,aAAW,OAAO,IAAI,QAAQ;AAC1B,WAAO,KAAK,EAAE,MAAM,IAAI,SAAS,sBAAsB,IAAI,OAAO,GAAG,CAAC;AAAA,EAC1E;AACA,SAAO,OAAO,SAAS,IAAI,OAAO;AACtC;AAEA,SAAS,kBAAkB,OAAc,QAA2C;AAChF,QAAM,OAAO,SAAS,OAAO,WAAW;AACxC,MAAI,CAAC,MAAM;AACP,WAAO,KAAK,EAAE,MAAM,aAAa,SAAS,wBAAwB,CAAC;AAAA,EACvE,OAAO;AACH,uBAAm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AO,KAAK,EAAE,MAAM,gBAAgB,SAAS,6CAA6C,CAAC;AAAA,EAC/F,OAAO;AACH,+BAA2B,KAAK,OAAO,MAAM;AAAA,EACjD;AACJ;AAEA,SAAS,eAAe,OAAc,QAA2C;AAC7E,QAAM,OAAO,SAAS,OAAO,QAAQ;AACrC,MAAI,CAAC,MAAM;AACP,WAAO,KAAK,EAAE,MAAM,UAAU,SAAS,qBAAqB,CAAC;AAC7D;AAAA,EACJ;AACA,MAAI,CAAC,mBAAmB,KAAK,OAAO,UAAU,MAAM,EAAG;AACvD,QAAM,MAAO,KAAK,MAAsB;AACxC,MAAI,CAAC,MAAM,MAAM,GAAG,GAAG;AACnB,WAAO,KAAK,EAAE,MAAM,UAAU,SAAS,sCAAsC,GAAG,IAAI,CAAC;AAAA,EACzF;AACJ;AAOO,SAAS,uBAAuB,SAA0D;AAC7F,QAAM,SAAsC,CAAC;AAE7C,QAAM,MAAM,eAAe,SAAS,MAAM;AAC1C,MAAI,CAAC,KAAK;AACN,WAAO,EAAE,OAAO;AAAA,EACpB;AAEA,QAAM,QAAe,KAAK,MAAM,IAAI,QAAQ,IAAI,IAAI,SAAS,QAAQ,CAAC;AAEtE,oBAAkB,OAAO,MAAM;AAC/B,iBAAe,OAAO,MAAM;AAC5B,uBAAqB,OAAO,MAAM;AAClC,sCAAoC,OAAO,MAAM;AAEjD,SAAO,EAAE,OAAO;AACpB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { createRequire as __createRequire } from "module";
|
|
2
|
+
const require = __createRequire(import.meta.url);
|
|
3
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
4
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
5
|
+
}) : x)(function(x) {
|
|
6
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
7
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
export {
|
|
11
|
+
__require
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=chunk-M2X75AXU.mjs.map
|
|
@@ -2,7 +2,10 @@ import { createRequire as __createRequire } from "module";
|
|
|
2
2
|
const require = __createRequire(import.meta.url);
|
|
3
3
|
import {
|
|
4
4
|
vocabulary_default
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-ZZFBMCTJ.mjs";
|
|
6
|
+
import {
|
|
7
|
+
validateVocabularyYaml
|
|
8
|
+
} from "./chunk-BJEPALVN.mjs";
|
|
6
9
|
import {
|
|
7
10
|
parseVocabularyYaml
|
|
8
11
|
} from "./chunk-TA74NV57.mjs";
|
|
@@ -19,14 +22,16 @@ function camelCaseToSentence(text) {
|
|
|
19
22
|
var VocabularyManager = class _VocabularyManager {
|
|
20
23
|
/**
|
|
21
24
|
* Create the VocabularyManager
|
|
22
|
-
* @param {
|
|
23
|
-
* @param {
|
|
25
|
+
* @param {VocabularyManagerOptions} [options] options to configure vocabulary lookup
|
|
26
|
+
* @param {Function} [options.missingTermGenerator] A function to call for missing terms. The function
|
|
24
27
|
* should accept namespace, locale, declarationName, propertyName as arguments
|
|
28
|
+
* @param {boolean} [options.enableVocValidator] When true, validates vocabulary YAML before parsing
|
|
25
29
|
* @constructor
|
|
26
30
|
*/
|
|
27
31
|
constructor(options) {
|
|
28
32
|
this.vocabularies = {};
|
|
29
|
-
this.missingTermGenerator = options
|
|
33
|
+
this.missingTermGenerator = options?.missingTermGenerator ?? null;
|
|
34
|
+
this.options = options ?? {};
|
|
30
35
|
}
|
|
31
36
|
/**
|
|
32
37
|
* Computes a term in English based on declaration and property name.
|
|
@@ -68,7 +73,15 @@ var VocabularyManager = class _VocabularyManager {
|
|
|
68
73
|
if (!contents) {
|
|
69
74
|
throw new Error("Vocabulary contents must be specified");
|
|
70
75
|
}
|
|
71
|
-
|
|
76
|
+
if (this.options.enableVocValidator) {
|
|
77
|
+
const { errors } = validateVocabularyYaml(contents);
|
|
78
|
+
if (errors.length > 0) {
|
|
79
|
+
throw new Error(errors.map((e) => e.message).join(", "));
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const useRawParse = this.options.enableVocValidator || !options?.enableSafeVocabParsing;
|
|
83
|
+
const parsed = useRawParse ? YAML.parse(contents) : parseVocabularyYaml(contents);
|
|
84
|
+
const voc = new vocabulary_default(this, parsed, { skipLocaleValidation: !!this.options.enableVocValidator });
|
|
72
85
|
if (this.vocabularies[voc.getIdentifier()]) {
|
|
73
86
|
throw new Error("Vocabulary has already been added.");
|
|
74
87
|
}
|
|
@@ -395,4 +408,4 @@ export {
|
|
|
395
408
|
VocabularyManager,
|
|
396
409
|
vocabularymanager_default
|
|
397
410
|
};
|
|
398
|
-
//# sourceMappingURL=chunk-
|
|
411
|
+
//# sourceMappingURL=chunk-X3NNESEP.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/vocabularymanager.ts"],
|
|
4
|
+
"sourcesContent": ["/*\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport YAML from 'yaml';\nimport { MetaModelNamespace } from '@accordproject/concerto-metamodel';\nimport Vocabulary from './vocabulary';\nimport { ModelUtil, ModelManager } from '@accordproject/concerto-core';\nimport { parseVocabularyYaml } from './yamlparser';\nimport { validateVocabularyYaml } from './vocabularyvalidator';\n\n\nconst DC_NAMESPACE = 'org.accordproject.decoratorcommands@0.4.0';\n\n/**\n * Converts a camel case string to a sentence\n * @param {string} text input\n * @returns {string} modified string\n */\nfunction camelCaseToSentence(text: string): string {\n const result = text.replace(/([A-Z]+)/g, ' $1').trim();\n return result.charAt(0).toUpperCase() + result.slice(1);\n}\n\n/**\n* A vocabulary manager for concerto models. The vocabulary manager\n* stores and provides API access to a set of vocabulary files, where each file\n* is associated with a BCP-47 language tag and a Concerto namespace.\n* @see https://datatracker.ietf.org/doc/html/rfc5646#section-2\n* @class\n* @memberof module:concerto-vocabulary\n*/\nclass VocabularyManager {\n public vocabularies: Record<string, Vocabulary>;\n public missingTermGenerator: any;\n private options: any;\n\n /**\n * Create the VocabularyManager\n * @param {VocabularyManagerOptions} [options] options to configure vocabulary lookup\n * @param {Function} [options.missingTermGenerator] A function to call for missing terms. The function\n * should accept namespace, locale, declarationName, propertyName as arguments\n * @param {boolean} [options.enableVocValidator] When true, validates vocabulary YAML before parsing\n * @constructor\n */\n constructor(options?: any) {\n this.vocabularies = {}; // key is namespace/locale, value is a Vocabulary object\n this.missingTermGenerator = options?.missingTermGenerator ?? null;\n this.options = options ?? {};\n }\n\n /**\n * Computes a term in English based on declaration and property name.\n * @param {string} namespace the namespace\n * @param {string} locale the BCP-47 locale identifier\n * @param {string} declarationName the name of a concept or enum\n * @param {string} [propertyName] the name of a property (optional)\n * @returns {string} the term or null if it does not exist\n */\n static englishMissingTermGenerator(namespace: string, locale: string, declarationName: string, propertyName?: string): string {\n if(!declarationName){\n return camelCaseToSentence(ModelUtil.parseNamespace(namespace).name);\n }\n const firstPart = propertyName ? propertyName.replace('$', '') + ' of the' : '';\n return camelCaseToSentence(firstPart + declarationName);\n }\n\n /**\n * Removes all vocabularies\n */\n clear() {\n this.vocabularies = {};\n }\n\n /**\n * Removes a vocabulary from the vocabulary manager\n * @param {string} namespace the namespace for the vocabulary\n * @param {string} locale the BCP-47 locale identifier\n */\n removeVocabulary(namespace: string, locale: string) {\n delete this.vocabularies[`${namespace}/${locale}`];\n }\n\n /**\n * Adds a vocabulary to the vocabulary manager\n * @param {string} contents the YAML string for the vocabulary\n * @param {*} [options] options to configure vocabulary parsing\n * @param {boolean} [options.enableSafeVocabParsing] When true, ensures vocabulary values are resolved correctly as strings\n * @returns {Vocabulary} the vocabulary the was added\n */\n addVocabulary(contents: any, options?: any): Vocabulary {\n if (!contents) {\n throw new Error('Vocabulary contents must be specified');\n }\n if (this.options.enableVocValidator) {\n const { errors } = validateVocabularyYaml(contents);\n if (errors.length > 0) {\n throw new Error(errors.map(e => e.message).join(', '));\n }\n }\n // when the validator has run, input is guaranteed to be structurally clean \u2014 all values are\n // explicit strings, no flow collections, no aliases \u2014 so parseVocabularyYaml's defensive\n // coercions are unnecessary and YAML.parse produces identical output at lower cost.\n // when the validator is off, preserve the existing parse behaviour.\n const useRawParse = this.options.enableVocValidator || !options?.enableSafeVocabParsing;\n const parsed = useRawParse ? YAML.parse(contents) : parseVocabularyYaml(contents);\n const voc = new Vocabulary(this, parsed, { skipLocaleValidation: !!this.options.enableVocValidator });\n\n if (this.vocabularies[voc.getIdentifier()]) {\n throw new Error('Vocabulary has already been added.');\n }\n this.vocabularies[voc.getIdentifier()] = voc;\n return voc;\n }\n\n /**\n * Finds the vocabulary for a requested locale, removing language\n * identifiers from the locale until the locale matches, or if no\n * vocabulary is found, null is returned\n * @param {string} requestedLocale the BCP-47 locale identifier\n * @param {Vocabulary[]} vocabularies the vocabularies to match against\n * @param {*} [options] options to configure vocabulary lookup\n * @param {*} [options.localeMatcher] Pass 'lookup' to find a general vocabulary, if available\n * @returns {Vocabulary} the most specific vocabulary, or null\n */\n static findVocabulary(requestedLocale: string, vocabularies: Vocabulary[], options?: any): Vocabulary | null {\n let locale = requestedLocale;\n let done = false;\n do {\n const voc = vocabularies.find(v => v.getLocale() === locale);\n if (voc) {\n return voc;\n }\n\n if (options?.localeMatcher !== 'lookup') {\n done = true;\n break;\n }\n\n const pos = locale.lastIndexOf('-');\n if (pos === -1) {\n done = true;\n break;\n }\n locale = locale.substring(0, pos);\n } while (!done);\n return null;\n }\n\n /**\n * Gets a vocabulary for a given namespace plus locale\n * @param {string} namespace the namespace for the vocabulary\n * @param {string} locale the BCP-47 locale identifier\n * @param {*} [options] options to configure vocabulary lookup\n * @param {*} [options.localeMatcher] Pass 'lookup' to find a general vocabulary, if available\n * @returns {Vocabulary} the vocabulary or null if no vocabulary exists for the locale\n */\n getVocabulary(namespace: string, locale: string, options?: any): Vocabulary | null {\n const loc = locale.toLowerCase();\n const voc = this.vocabularies[`${namespace}/${loc}`];\n if (voc) {\n return voc;\n }\n if (options?.localeMatcher === 'lookup') {\n const vocs = this.getVocabulariesForNamespace(namespace);\n return VocabularyManager.findVocabulary(loc, vocs, options);\n }\n return null;\n }\n\n /**\n * Gets all the vocabulary files for a given namespace\n * @param {string} namespace the namespace\n * @returns {Vocabulary[]} the array of vocabularies\n */\n getVocabulariesForNamespace(namespace: string): Vocabulary[] {\n return Object.values(this.vocabularies).filter(v => v.getNamespace() === namespace);\n }\n\n /**\n * Gets all the vocabulary files for a given locale\n * @param {string} locale the BCP-47 locale identifier\n * @returns {Vocabulary[]} the array of vocabularies\n */\n getVocabulariesForLocale(locale: string): Vocabulary[] {\n return Object.values(this.vocabularies).filter(v => v.getLocale() === locale.toLowerCase());\n }\n\n /**\n * Resolve the term for a property, looking up terms from a more general vocabulary\n * if required, and resolving properties using an object manager, allowing terms defined\n * on super types to be automatically resolved.\n * @param {ModelManager} modelManager the model manager\n * @param {string} namespace the namespace\n * @param {string} locale the BCP-47 locale identifier\n * @param {string} declarationName the name of a concept or enum\n * @param {string} [propertyName] the name of a property (optional)\n * @param {string} [identifier] the identifier of the term (optional)\n * @returns {string|number|boolean|null} the term or null if it does not exist\n */\n resolveTerm(modelManager: ModelManager, namespace: string, locale: string, declarationName: string, propertyName?: string, identifier?: string): string | number | boolean | null {\n const modelFile = modelManager.getModelFile(namespace);\n // @ts-ignore\n const classDecl = modelFile ? (modelFile as any).getType(declarationName) : null;\n const property = propertyName ? classDecl ? classDecl.getProperty(propertyName) : null : null;\n return this.getTerm(property ? property.getNamespace() : namespace, locale, property ? (property.getParent() as any).getName() : declarationName, propertyName, identifier);\n }\n\n /**\n * Resolve the terms for a property, looking up terms from a more general vocabulary\n * if required, and resolving properties using an object manager, allowing terms defined\n * on super types to be automatically resolved.\n * @param {ModelManager} modelManager the model manager\n * @param {string} namespace the namespace\n * @param {string} locale the BCP-47 locale identifier\n * @param {string} declarationName the name of a concept or enum\n * @param {string} [propertyName] the name of a property (optional)\n * @param {*} [options] options to configure term resolution\n * @param {boolean} [options.generateMissing=true] whether to synthesize missing terms\n * @returns {*} the terms or null if it does not exist\n */\n resolveTerms(modelManager: ModelManager, namespace: string, locale: string, declarationName: string, propertyName?: string, options?: any) {\n const modelFile = modelManager.getModelFile(namespace);\n // @ts-ignore\n const classDecl = modelFile ? (modelFile as any).getType(declarationName) : null;\n let property;\n if(classDecl && !classDecl.isScalarDeclaration()) {\n if(classDecl.isMapDeclaration()) {\n if(propertyName === 'KEY') {\n property = classDecl.getKey();\n } else if(propertyName === 'VALUE') {\n property = classDecl.getValue();\n }\n } else {\n property = propertyName ? classDecl ? classDecl.getProperty(propertyName) : null : null;\n }\n }\n return this.getTerms(property ? property.getNamespace() : namespace, locale, property ? (property.getParent() as any).getName() : declarationName, propertyName, options);\n }\n\n /**\n * Gets the term for a concept, enum or property, looking up terms\n * from a more general vocabulary if required\n * @param {string} namespace the namespace\n * @param {string} locale the BCP-47 locale identifier\n * @param {string} declarationName the name of a concept or enum\n * @param {string} [propertyName] the name of a property (optional)\n * @param {string} [identifier] the identifier of the term (optional)\n * @returns {string|number|boolean|null} the term or null if it does not exist\n */\n getTerm(namespace: string, locale: string, declarationName: string, propertyName?: string, identifier?: string): string | number | boolean | null {\n const voc = this.getVocabulary(namespace, locale);\n let term = null;\n if (voc) {\n term = voc.getTerm(declarationName, propertyName, identifier);\n }\n if (term != null) {\n return term;\n }\n else {\n const dashIndex = locale.lastIndexOf('-');\n if (dashIndex >= 0) {\n return this.getTerm(namespace, locale.substring(0, dashIndex), declarationName, propertyName, identifier);\n }\n else {\n return this.missingTermGenerator ? this.missingTermGenerator(namespace, locale, declarationName, propertyName) : null;\n }\n }\n }\n\n /**\n * Gets the term for a concept, enum or property, looking up terms\n * from a more general vocabulary if required\n * @param {string} namespace the namespace\n * @param {string} locale the BCP-47 locale identifier\n * @param {string} declarationName the name of a concept or enum\n * @param {string} [propertyName] the name of a property (optional)\n * @param {*} [options] options to configure term resolution\n * @param {boolean} [options.generateMissing=true] whether to synthesize missing terms\n * @returns {*} the terms or null if it does not exist\n */\n getTerms(namespace: string, locale: string, declarationName: string, propertyName?: string, options?: any): any {\n const voc = this.getVocabulary(namespace, locale);\n let term = null;\n if (voc) {\n term = voc.getElementTerms(declarationName, propertyName);\n }\n if (term != null) {\n return term;\n }\n else {\n const dashIndex = locale.lastIndexOf('-');\n if (dashIndex >= 0) {\n return this.getTerms(namespace, locale.substring(0, dashIndex), declarationName, propertyName, options);\n }\n else {\n if (options?.generateMissing === false) {\n return;\n }\n let missingKey = propertyName ? propertyName : declarationName;\n missingKey = missingKey? missingKey : 'term';\n return this.missingTermGenerator ? { [missingKey]: this.missingTermGenerator(namespace, locale, declarationName, propertyName) } : null;\n }\n }\n }\n\n /**\n * Creates a DecoractorCommandSet with @Term decorators\n * to decorate all model elements based on the vocabulary for a locale.\n * Pass the return value to the DecoratorManager.decorateModel to apply\n * the decorators to a ModelManager.\n * @param {ModelManager} modelManager - the Model Manager\n * @param {string} locale the BCP-47 locale identifier\n * @returns {*} the decorator command set used to decorate the model.\n */\n generateDecoratorCommands(modelManager: ModelManager, locale: string): any {\n const commands: any[] = [];\n\n const CLASS_COMMAND = `${DC_NAMESPACE}.Command`;\n const CLASS_TARGET = `${DC_NAMESPACE}.CommandTarget`;\n const CLASS_DECORATOR = `${MetaModelNamespace}.Decorator`;\n const CLASS_DECORATOR_STRING = `${MetaModelNamespace}.DecoratorString`;\n\n const makeCommand = (target: any, decoratorName: string, value: string) => ({\n '$class': CLASS_COMMAND,\n 'type': 'UPSERT',\n 'target': target,\n 'decorator': {\n '$class': CLASS_DECORATOR,\n 'name': decoratorName,\n 'arguments': [{ '$class': CLASS_DECORATOR_STRING, 'value': value }]\n }\n });\n\n // @ts-ignore\n (modelManager as any).getModelFiles().forEach((model: any) => {\n const namespace = model.getNamespace();\n\n const nsTerms = this.getTerms(namespace, locale, '', undefined, { generateMissing: false });\n if (nsTerms) {\n const keys = Object.keys(nsTerms);\n for (let i = 0; i < keys.length; i++) {\n const term = keys[i];\n if (term === 'term') {\n commands.push(makeCommand(\n { '$class': CLASS_TARGET, 'namespace': namespace },\n 'Term', nsTerms[term]\n ));\n } else if (term !== 'declarations' && term !== 'namespace' && term !== 'locale') {\n commands.push(makeCommand(\n { '$class': CLASS_TARGET, 'namespace': namespace },\n `Term_${term}`, nsTerms[term]\n ));\n }\n }\n }\n\n model.getAllDeclarations().forEach((decl: any) => {\n const declName = decl.getName();\n\n const declTerms = this.getTerms(namespace, locale, declName);\n if (declTerms) {\n const keys = Object.keys(declTerms);\n for (let i = 0; i < keys.length; i++) {\n const term = keys[i];\n if (term === declName) {\n commands.push(makeCommand(\n { '$class': CLASS_TARGET, 'namespace': namespace, 'declaration': declName },\n 'Term', declTerms[term]\n ));\n } else if (term !== 'properties') {\n commands.push(makeCommand(\n { '$class': CLASS_TARGET, 'namespace': namespace, 'declaration': declName },\n `Term_${term}`, declTerms[term]\n ));\n }\n }\n }\n\n let propertyNames: string[] = [];\n if (decl.getProperties) {\n propertyNames = decl.getProperties().map((p: any) => p.getName());\n } else if (decl.isMapDeclaration?.()) {\n propertyNames = ['KEY', 'VALUE'];\n } else {\n return;\n }\n\n for (let p = 0; p < propertyNames.length; p++) {\n const propertyName = propertyNames[p];\n const propertyTerms = this.resolveTerms(modelManager, namespace, locale, declName, propertyName);\n if (propertyTerms) {\n const propertyType = propertyName === 'KEY' || propertyName === 'VALUE' ? 'mapElement' : 'property';\n const keys = Object.keys(propertyTerms);\n for (let i = 0; i < keys.length; i++) {\n const term = keys[i];\n commands.push(makeCommand(\n { '$class': CLASS_TARGET, 'namespace': namespace, 'declaration': declName, [propertyType]: propertyName },\n term === propertyName ? 'Term' : `Term_${term}`, propertyTerms[term]\n ));\n }\n }\n }\n });\n });\n\n return {\n '$class': `${DC_NAMESPACE}.DecoratorCommandSet`,\n 'name': `terms-${locale}`,\n 'version': '1.0.0',\n 'commands': commands\n };\n }\n\n /**\n * Validates the terms in the vocabulary against the namespaces and declarations\n * within a ModelManager\n * @param {ModelManager} modelManager - the Model Manager\n * @param {string} locale the BCP-47 locale identifier\n * @returns {*} the result of validation\n */\n validate(modelManager: ModelManager): any {\n // missing vocabularies\n // @ts-ignore\n const missingVocabularies = (modelManager as any).getModelFiles()\n .map((m: any) => this.getVocabulariesForNamespace(m.getNamespace()).length === 0 ? m.getNamespace() : null)\n .filter((m: any) => m !== null);\n\n // additional vocabularies\n const additionalVocabularies = Object.values(this.vocabularies)\n .filter(v => !modelManager.getModelFile(v.getNamespace()));\n\n const result: any = {\n missingVocabularies,\n additionalVocabularies,\n vocabularies: {}\n };\n\n // validate the models against the vocs\n Object.values(this.vocabularies)\n .forEach(voc => {\n const vocResult: any = {\n locale: voc.getLocale(),\n namespace: voc.getNamespace(),\n missingTerms: [],\n additionalTerms: []\n };\n\n const model = modelManager.getModelFile(voc.getNamespace());\n if (model) {\n const errors = voc.validate(model);\n if (errors.missingTerms) {\n vocResult.missingTerms = vocResult.missingTerms.concat(errors.missingTerms);\n }\n if (errors.additionalTerms) {\n vocResult.additionalTerms = vocResult.additionalTerms.concat(errors.additionalTerms);\n }\n\n result.vocabularies[`${vocResult.namespace}/${vocResult.locale}`] = vocResult;\n }\n });\n return result;\n }\n}\n\nexport { VocabularyManager };\nexport default VocabularyManager;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;AAcA,OAAO,UAAU;AACjB,SAAS,0BAA0B;AAEnC,SAAS,iBAA+B;AAKxC,IAAM,eAAe;AAOrB,SAAS,oBAAoB,MAAsB;AAC/C,QAAM,SA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AI,OAAO,iBAAiB;AACxB,oBAAU,kBAAkB,UAAU,gBAAgB,OAAO,OAAO,eAAe;AAAA,QACvF;AAEA,eAAO,aAAa,GAAG,UAAU,SAAS,IAAI,UAAU,MAAM,EAAE,IAAI;AAAA,MACxE;AAAA,IACJ,CAAC;AACL,WAAO;AAAA,EACX;AACJ;AAGA,IAAO,4BAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -9,7 +9,7 @@ var Vocabulary = class _Vocabulary {
|
|
|
9
9
|
* @param {VocabularyManager} vocabularyManager - the manager for this vocabulary
|
|
10
10
|
* @param {object} voc - the JSON representation of the vocabulary
|
|
11
11
|
*/
|
|
12
|
-
constructor(vocabularyManager, voc) {
|
|
12
|
+
constructor(vocabularyManager, voc, options) {
|
|
13
13
|
if (!vocabularyManager) {
|
|
14
14
|
throw new Error("VocabularyManager must be specified");
|
|
15
15
|
}
|
|
@@ -25,7 +25,9 @@ var Vocabulary = class _Vocabulary {
|
|
|
25
25
|
if (!voc.locale) {
|
|
26
26
|
throw new Error("A vocabulary must specify a locale");
|
|
27
27
|
}
|
|
28
|
-
|
|
28
|
+
if (!options?.skipLocaleValidation) {
|
|
29
|
+
_Vocabulary.validateLocale(voc.locale);
|
|
30
|
+
}
|
|
29
31
|
this.vocabularyManager = vocabularyManager;
|
|
30
32
|
this.content = voc;
|
|
31
33
|
}
|
|
@@ -182,4 +184,4 @@ export {
|
|
|
182
184
|
Vocabulary,
|
|
183
185
|
vocabulary_default
|
|
184
186
|
};
|
|
185
|
-
//# sourceMappingURL=chunk-
|
|
187
|
+
//# sourceMappingURL=chunk-ZZFBMCTJ.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/vocabulary.ts"],
|
|
4
|
+
"sourcesContent": ["/*\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { ModelFile, ClassDeclaration, Declaration, Property } from '@accordproject/concerto-core';\nimport type VocabularyManager from './vocabularymanager';\n\n/**\n* A vocabulary for a concerto model\n* @class\n* @memberof module:concerto-vocabulary\n*/\nclass Vocabulary {\n public vocabularyManager: VocabularyManager;\n public content: any;\n\n /**\n * Create the Vocabulary\n * @constructor\n * @param {VocabularyManager} vocabularyManager - the manager for this vocabulary\n * @param {object} voc - the JSON representation of the vocabulary\n */\n constructor(vocabularyManager: VocabularyManager, voc: any, options?: { skipLocaleValidation?: boolean }) {\n if(!vocabularyManager) {\n throw new Error('VocabularyManager must be specified');\n }\n if(!voc) {\n throw new Error('Vocabulary object must be specified');\n }\n\n if(!voc.declarations) {\n throw new Error('Vocabulary object must have declarations');\n }\n\n if(!voc.namespace) {\n throw new Error('A vocabulary must specify a namespace');\n }\n\n if(!voc.locale) {\n throw new Error('A vocabulary must specify a locale');\n }\n\n if (!options?.skipLocaleValidation) {\n Vocabulary.validateLocale(voc.locale);\n }\n\n this.vocabularyManager = vocabularyManager;\n this.content = voc;\n }\n\n /**\n * Returns the namespace for the vocabulary\n * @returns {string} the namespace for this vocabulary\n */\n getNamespace(): string {\n return this.content.namespace;\n }\n\n /**\n * Validates a locale\n * @param {string} locale the locale to validate\n * @throws {Error} if the locale is invalid\n */\n static validateLocale(locale: string) {\n // @ts-ignore\n new Intl.Locale(locale);\n if(locale !== locale.toLowerCase()) {\n throw new Error('Locale should be lowercase with dashes');\n }\n }\n\n /**\n * Returns the locale for the vocabulary\n * @returns {string} the locale for this vocabulary\n */\n getLocale(): string {\n return this.content.locale;\n }\n\n /**\n * Returns the identifier for the vocabulary, composed of the namespace plus the locale\n * @returns {string} the identifier for this vocabulary\n */\n getIdentifier(): string {\n return `${this.getNamespace()}/${this.content.locale}`;\n }\n\n /**\n * Returns all the declarations for this vocabulary\n * @returns {Array} an array of objects\n */\n getTerms(): any[] {\n return this.content.declarations;\n }\n\n /**\n * Gets the terms of Namespace\n * @returns {string} the term or null if it does not exist\n * @private\n */\n getNamespaceTerms(): any {\n const namespaceTerms = Object.entries(this.content).filter(([key]) => key !== 'namespace' && key !== 'locale' && key !== 'declarations');\n return namespaceTerms.length > 0 ? Object.fromEntries(namespaceTerms) : null;\n }\n\n /**\n * Gets the term for a concept, enum or property\n * @param {string} declarationName the name of a concept or enum\n * @param {string} [propertyName] the name of a property (optional)\n * @param {string} [identifier] the identifier of the term (optional)\n * @returns {string|number|boolean|null} the term or null if it does not exist\n */\n getTerm(declarationName?: string, propertyName?: string, identifier?: string): string | number | boolean | null {\n if(!declarationName){\n const namespaceTerms = this.getNamespaceTerms();\n return identifier ? namespaceTerms?.[identifier]:namespaceTerms?.term;\n }\n const decl = this.content.declarations.find((d: any) => Object.keys(d)[0] === declarationName);\n if(!decl) {\n return null;\n }\n if(!propertyName) {\n return identifier ? decl[identifier] : decl[declarationName];\n }\n else {\n const property = decl.properties ? decl.properties.find((d: any) => propertyName in d) : null;\n return property ? identifier ? property[identifier] : property[propertyName] : null;\n }\n }\n\n /**\n * Gets the terms for a concept, enum or property\n * @param {string} declarationName the name of a concept or enum\n * @param {string} [propertyName] the name of a property (optional)\n * @returns {string} the term or null if it does not exist\n */\n getElementTerms(declarationName: string, propertyName?: string): any {\n if(!declarationName){\n return this.getNamespaceTerms();\n }\n const decl = this.content.declarations.find((d: any) => Object.keys(d)[0] === declarationName);\n if(!decl) {\n return null;\n }\n if(!propertyName) {\n return decl;\n }\n else {\n const property = decl.properties ? decl.properties.find((d: any) => propertyName in d) : null;\n return property;\n }\n }\n\n /**\n * Validates a vocabulary against a ModelFile, returning errors for\n * missing and additional terms.\n * @param {ModelFile} modelFile the model file for this vocabulary\n * @returns {*} an object with missingTerms and additionalTerms properties\n */\n validate(modelFile: ModelFile): any {\n const getOwnProperties = (declaration: any) => {\n // ensures we have a valid return, even for scalars and map-declarations\n if(declaration.isMapDeclaration()) {\n return [declaration.getKey(), declaration.getValue()];\n } else {\n return declaration.getOwnProperties?.() ? declaration.getOwnProperties?.() : [];\n }\n };\n\n const getPropertyName = (property: any) => {\n if(property.isKey?.()) {\n return 'KEY';\n } else if(property.isValue?.()) {\n return 'VALUE';\n } else {\n return property.getName();\n }\n };\n\n const checkPropertyExists = (k: any, p: any) => {\n // only reached for keys that getLocalType has already resolved\n const declaration = modelFile.getLocalType(Object.keys(k)[0]) as ClassDeclaration;\n const property = Object.keys(p)[0];\n if(declaration.isMapDeclaration()) {\n if (property === 'KEY') {\n return true;\n } else if(property === 'VALUE') {\n return true;\n } else {\n return false;\n }\n } else {\n return declaration.getOwnProperty(Object.keys(p)[0]);\n }\n };\n\n const result = {\n missingTerms: modelFile.getAllDeclarations().flatMap( (d: Declaration) => this.getTerm(d.getName())\n ? getOwnProperties(d).flatMap( (p: Property) => this.getTerm(d.getName(), getPropertyName(p)) ? null : `${d.getName()}.${getPropertyName(p)}`)\n : d.getName() ).filter( (i: any) => i !== null),\n additionalTerms: this.content.declarations.flatMap( (k: any) => modelFile.getLocalType(Object.keys(k)[0])\n ? Array.isArray(k.properties) ? k.properties.flatMap( (p: any) => checkPropertyExists(k, p) ? null : `${Object.keys(k)[0]}.${Object.keys(p)[0]}`) : null\n : k ).filter( (i: any) => i !== null)\n };\n\n if(!this.content.term){\n result.missingTerms.push('namespace');\n }\n\n return result;\n }\n\n /**\n * Converts the object to JSON\n * @returns {*} the contens of this vocabulary\n */\n toJSON() {\n return this.content;\n }\n}\n\nexport { Vocabulary };\nexport default Vocabulary;\n"],
|
|
5
|
+
"mappings": ";;;;AAsBA,IAAM,aAAN,MAAM,YAAW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUb,YAAY,mBAAsC,KAAU,SAA8C;AACtG,QAAG,CAAC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MAAW,oBAAoB,GAAG,CAAC,IAAI,OAAO,GAAG,OAAO,KAAK,CAAC,EAAE,CAAC,CAAC,IAAI,OAAO,KAAK,CAAC,EAAE,CAAC,CAAC,EAAE,IAAI,OAClJ,CAAE,EAAE,OAAQ,CAAC,MAAW,MAAM,IAAI;AAAA,IAC5C;AAEA,QAAG,CAAC,KAAK,QAAQ,MAAK;AAClB,aAAO,aAAa,KAAK,WAAW;AAAA,IACxC;AAEA,WAAO;AAAA,EACX;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,SAAS;AACL,WAAO,KAAK;AAAA,EAChB;AACJ;AAGA,IAAO,qBAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -2,11 +2,13 @@ import { createRequire as __createRequire } from "module";
|
|
|
2
2
|
const require = __createRequire(import.meta.url);
|
|
3
3
|
import {
|
|
4
4
|
vocabularymanager_default
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-X3NNESEP.mjs";
|
|
6
6
|
import {
|
|
7
7
|
vocabulary_default
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-ZZFBMCTJ.mjs";
|
|
9
|
+
import "./chunk-BJEPALVN.mjs";
|
|
9
10
|
import "./chunk-TA74NV57.mjs";
|
|
11
|
+
import "./chunk-M2X75AXU.mjs";
|
|
10
12
|
export {
|
|
11
13
|
vocabulary_default as Vocabulary,
|
|
12
14
|
vocabularymanager_default as VocabularyManager
|
package/dist/esm/vocabulary.mjs
CHANGED
|
@@ -3,9 +3,11 @@ const require = __createRequire(import.meta.url);
|
|
|
3
3
|
import {
|
|
4
4
|
VocabularyManager,
|
|
5
5
|
vocabularymanager_default
|
|
6
|
-
} from "./chunk-
|
|
7
|
-
import "./chunk-
|
|
6
|
+
} from "./chunk-X3NNESEP.mjs";
|
|
7
|
+
import "./chunk-ZZFBMCTJ.mjs";
|
|
8
|
+
import "./chunk-BJEPALVN.mjs";
|
|
8
9
|
import "./chunk-TA74NV57.mjs";
|
|
10
|
+
import "./chunk-M2X75AXU.mjs";
|
|
9
11
|
export {
|
|
10
12
|
VocabularyManager,
|
|
11
13
|
vocabularymanager_default as default
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { createRequire as __createRequire } from "module";
|
|
2
|
+
const require = __createRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
validateVocabularyYaml
|
|
5
|
+
} from "./chunk-BJEPALVN.mjs";
|
|
6
|
+
import "./chunk-M2X75AXU.mjs";
|
|
7
|
+
export {
|
|
8
|
+
validateVocabularyYaml
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=vocabularyvalidator.mjs.map
|
package/dist/esm/yamlparser.mjs
CHANGED
|
@@ -3,9 +3,6 @@ import {
|
|
|
3
3
|
init_browser_process_shim
|
|
4
4
|
} from "./chunk-K2X7J5YP.mjs";
|
|
5
5
|
|
|
6
|
-
// src/yamlparser.ts
|
|
7
|
-
init_browser_process_shim();
|
|
8
|
-
|
|
9
6
|
// node_modules/yaml/browser/index.js
|
|
10
7
|
init_browser_process_shim();
|
|
11
8
|
|
|
@@ -6710,38 +6707,7 @@ function stringify3(value, replacer, options) {
|
|
|
6710
6707
|
// node_modules/yaml/browser/index.js
|
|
6711
6708
|
var browser_default = dist_exports;
|
|
6712
6709
|
|
|
6713
|
-
// src/yamlparser.ts
|
|
6714
|
-
function parseVocabularyYaml(yamlStr) {
|
|
6715
|
-
const doc = browser_default.parseDocument(yamlStr);
|
|
6716
|
-
if (doc.errors.length > 0) {
|
|
6717
|
-
throw doc.errors[0];
|
|
6718
|
-
}
|
|
6719
|
-
browser_default.visit(doc, {
|
|
6720
|
-
Pair(_, pair) {
|
|
6721
|
-
const key = pair.key.value;
|
|
6722
|
-
const value = pair.value;
|
|
6723
|
-
if (key === "declarations" || key === "properties") {
|
|
6724
|
-
return;
|
|
6725
|
-
}
|
|
6726
|
-
if (browser_default.isScalar(value) && typeof value.value !== "string") {
|
|
6727
|
-
pair.value = new browser_default.Scalar(String(value.value));
|
|
6728
|
-
return;
|
|
6729
|
-
}
|
|
6730
|
-
if (browser_default.isCollection(value)) {
|
|
6731
|
-
if (value.range) {
|
|
6732
|
-
const [start, end] = value.range;
|
|
6733
|
-
pair.value = new browser_default.Scalar(yamlStr.substring(start, end));
|
|
6734
|
-
} else {
|
|
6735
|
-
pair.value = new browser_default.Scalar(JSON.stringify(value.toJSON()));
|
|
6736
|
-
}
|
|
6737
|
-
}
|
|
6738
|
-
}
|
|
6739
|
-
});
|
|
6740
|
-
return doc.toJSON();
|
|
6741
|
-
}
|
|
6742
|
-
|
|
6743
6710
|
export {
|
|
6744
|
-
browser_default
|
|
6745
|
-
parseVocabularyYaml
|
|
6711
|
+
browser_default
|
|
6746
6712
|
};
|
|
6747
|
-
//# sourceMappingURL=chunk-
|
|
6713
|
+
//# sourceMappingURL=chunk-CSZFRMP7.mjs.map
|