@oslo-flanders/core 1.0.9 → 1.0.11
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.d.ts +3 -0
- package/index.js +3 -0
- package/lib/constants/prefixes.d.ts +1 -0
- package/lib/constants/prefixes.js +36 -0
- package/lib/enums/DataTypes.js +13 -0
- package/lib/store/QuadStore.d.ts +9 -0
- package/lib/store/QuadStore.js +11 -2
- package/lib/utils/fileSystem.d.ts +1 -0
- package/lib/utils/fileSystem.js +16 -0
- package/lib/utils/storeUtils.d.ts +1 -0
- package/lib/utils/storeUtils.js +13 -1
- package/lib/utils/strings.d.ts +2 -0
- package/lib/utils/strings.js +19 -0
- package/package.json +2 -2
package/index.d.ts
CHANGED
|
@@ -22,3 +22,6 @@ export * from './lib/logging/LoggerFactory';
|
|
|
22
22
|
export * from './lib/logging/VoidLoggerFactory';
|
|
23
23
|
export * from './lib/logging/WinstonLoggerFactory';
|
|
24
24
|
export * from './lib/utils/storeUtils';
|
|
25
|
+
export * from './lib/utils/fileSystem';
|
|
26
|
+
export * from './lib/utils/strings';
|
|
27
|
+
export * from './lib/constants/prefixes';
|
package/index.js
CHANGED
|
@@ -38,4 +38,7 @@ __exportStar(require("./lib/logging/LoggerFactory"), exports);
|
|
|
38
38
|
__exportStar(require("./lib/logging/VoidLoggerFactory"), exports);
|
|
39
39
|
__exportStar(require("./lib/logging/WinstonLoggerFactory"), exports);
|
|
40
40
|
__exportStar(require("./lib/utils/storeUtils"), exports);
|
|
41
|
+
__exportStar(require("./lib/utils/fileSystem"), exports);
|
|
42
|
+
__exportStar(require("./lib/utils/strings"), exports);
|
|
43
|
+
__exportStar(require("./lib/constants/prefixes"), exports);
|
|
41
44
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getPrefixes(): Promise<Record<string, string>>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getPrefixes = void 0;
|
|
7
|
+
const core_1 = require("@oslo-flanders/core");
|
|
8
|
+
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
9
|
+
const PREFIX_CC_URL = 'https://prefix.cc/context';
|
|
10
|
+
async function getPrefixes() {
|
|
11
|
+
const url = PREFIX_CC_URL;
|
|
12
|
+
try {
|
|
13
|
+
const response = await (0, node_fetch_1.default)(url);
|
|
14
|
+
if (!response.ok) {
|
|
15
|
+
throw new Error(`Failed to fetch prefixes: ${response.statusText}`);
|
|
16
|
+
}
|
|
17
|
+
const data = await response.json();
|
|
18
|
+
if (data['@context']) {
|
|
19
|
+
return data['@context'];
|
|
20
|
+
}
|
|
21
|
+
throw new Error('Invalid context format received from prefix.cc');
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
console.error(`Error fetching prefixes: ${String(error)}`);
|
|
25
|
+
// Fallback to a minimal set of prefixes if the fetch fails
|
|
26
|
+
return {
|
|
27
|
+
skos: core_1.ns.skos(''),
|
|
28
|
+
rdf: core_1.ns.rdf(''),
|
|
29
|
+
rdfs: core_1.ns.rdfs(''),
|
|
30
|
+
dct: core_1.ns.dcterms(''),
|
|
31
|
+
xsd: core_1.ns.xsd(''),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.getPrefixes = getPrefixes;
|
|
36
|
+
//# sourceMappingURL=prefixes.js.map
|
package/lib/enums/DataTypes.js
CHANGED
|
@@ -24,6 +24,19 @@ const DataTypes = new Map([
|
|
|
24
24
|
['duration', `${xsd}#duration`],
|
|
25
25
|
['html', `${rdf}#HTML`],
|
|
26
26
|
['uri', `${xsd}#anyURI`],
|
|
27
|
+
['json', `${rdf}#JSON`],
|
|
28
|
+
['short', `${xsd}#long`],
|
|
29
|
+
['short', `${xsd}#short`],
|
|
30
|
+
['byte', `${xsd}#byte`],
|
|
31
|
+
['hexbinary', `${xsd}#hexBinary`],
|
|
32
|
+
['base64binary', `${xsd}#base64Binary`],
|
|
33
|
+
['nonnegativeinteger', `${xsd}#nonNegativeInteger`],
|
|
34
|
+
['nonpositiveinteger', `${xsd}#nonPositiveInteger`],
|
|
35
|
+
['negativeinteger', `${xsd}#negativeInteger`],
|
|
36
|
+
['positiveinteger', `${xsd}#positiveInteger`],
|
|
37
|
+
['unsignedshort', `${xsd}#unsignedLong`],
|
|
38
|
+
['unsignedshort', `${xsd}#unsignedShort`],
|
|
39
|
+
['unsignedbyte', `${xsd}#unsignedByte`],
|
|
27
40
|
]);
|
|
28
41
|
const getDataType = (key) => DataTypes.get(key.toLowerCase());
|
|
29
42
|
exports.getDataType = getDataType;
|
package/lib/store/QuadStore.d.ts
CHANGED
|
@@ -26,6 +26,15 @@ export declare class QuadStore {
|
|
|
26
26
|
* @returns an array of RDF.NamedNodes
|
|
27
27
|
*/
|
|
28
28
|
getDatatypes(graph?: RDF.Term | null): RDF.NamedNode[];
|
|
29
|
+
/**
|
|
30
|
+
* Finds all subjects where predicate is 'rdf:type' and object 'skos:Concept'
|
|
31
|
+
* We chose the skos:Concept here as enumerations have the skos:Concept uri in EA
|
|
32
|
+
* There is no skos:ConceptScheme used in EA since we assume that it's only used to
|
|
33
|
+
* represent a value from a skos:ConceptScheme instead of the conceptscheme as a whole
|
|
34
|
+
* https://github.com/Informatievlaanderen/OSLO-UML-Transformer/wiki/Technical-Guidelines#enumerations
|
|
35
|
+
* @returns an array of RDF.NamedNodes
|
|
36
|
+
*/
|
|
37
|
+
getEnumerations(graph?: RDF.Term | null): RDF.NamedNode[];
|
|
29
38
|
/**
|
|
30
39
|
* Finds all subjects where predicate is 'rdf:type' and object 'owl:DatatypeProperty'
|
|
31
40
|
* @returns an array of RDF.NamedNodes
|
package/lib/store/QuadStore.js
CHANGED
|
@@ -101,6 +101,17 @@ let QuadStore = class QuadStore {
|
|
|
101
101
|
getDatatypes(graph = null) {
|
|
102
102
|
return (this.store.getSubjects(namespaces_1.ns.rdf('type'), namespaces_1.ns.rdfs('Datatype'), graph));
|
|
103
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
* Finds all subjects where predicate is 'rdf:type' and object 'skos:Concept'
|
|
106
|
+
* We chose the skos:Concept here as enumerations have the skos:Concept uri in EA
|
|
107
|
+
* There is no skos:ConceptScheme used in EA since we assume that it's only used to
|
|
108
|
+
* represent a value from a skos:ConceptScheme instead of the conceptscheme as a whole
|
|
109
|
+
* https://github.com/Informatievlaanderen/OSLO-UML-Transformer/wiki/Technical-Guidelines#enumerations
|
|
110
|
+
* @returns an array of RDF.NamedNodes
|
|
111
|
+
*/
|
|
112
|
+
getEnumerations(graph = null) {
|
|
113
|
+
return (this.store.getSubjects(namespaces_1.ns.rdf('type'), namespaces_1.ns.skos('Concept'), graph));
|
|
114
|
+
}
|
|
104
115
|
/**
|
|
105
116
|
* Finds all subjects where predicate is 'rdf:type' and object 'owl:DatatypeProperty'
|
|
106
117
|
* @returns an array of RDF.NamedNodes
|
|
@@ -336,8 +347,6 @@ let QuadStore = class QuadStore {
|
|
|
336
347
|
* @returns An RDF.Term or undefined if not found
|
|
337
348
|
*/
|
|
338
349
|
getExtension(subject, graph = null) {
|
|
339
|
-
console.log(this.store.getObjects(subject, namespaces_1.ns.oslo('key'), graph).shift());
|
|
340
|
-
console.log(this.store.getObjects(subject, null, graph));
|
|
341
350
|
return (this.store.getObjects(subject, namespaces_1.ns.oslo('oslo:key'), graph).shift());
|
|
342
351
|
}
|
|
343
352
|
/**
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function ensureOutputDirectory(directory: string): void;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// eslint-disable-next-line eslint-comments/disable-enable-pair
|
|
3
|
+
/* eslint-disable no-sync */
|
|
4
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
6
|
+
};
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.ensureOutputDirectory = void 0;
|
|
9
|
+
const fs_1 = __importDefault(require("fs"));
|
|
10
|
+
function ensureOutputDirectory(directory) {
|
|
11
|
+
if (!fs_1.default.existsSync(directory)) {
|
|
12
|
+
fs_1.default.mkdirSync(directory);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.ensureOutputDirectory = ensureOutputDirectory;
|
|
16
|
+
//# sourceMappingURL=fileSystem.js.map
|
|
@@ -8,3 +8,4 @@ export declare function getApplicationProfileUsageNote(subject: RDF.Term, store:
|
|
|
8
8
|
export declare function getVocabularyUsageNote(subject: RDF.Term, store: QuadStore, language?: string | null): RDF.Literal | undefined;
|
|
9
9
|
export declare function getMinCount(subject: RDF.Term, store: QuadStore): string | undefined;
|
|
10
10
|
export declare function getMaxCount(subject: RDF.Term, store: QuadStore): string | undefined;
|
|
11
|
+
export declare function findAllAttributes(subject: RDF.Term, attributeIds: RDF.Term[], store: QuadStore): RDF.Term[];
|
package/lib/utils/storeUtils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getMaxCount = exports.getMinCount = exports.getVocabularyUsageNote = exports.getApplicationProfileUsageNote = exports.getVocabularyDefinition = exports.getApplicationProfileDefinition = exports.getVocabularyLabel = exports.getApplicationProfileLabel = void 0;
|
|
3
|
+
exports.findAllAttributes = exports.getMaxCount = exports.getMinCount = exports.getVocabularyUsageNote = exports.getApplicationProfileUsageNote = exports.getVocabularyDefinition = exports.getApplicationProfileDefinition = exports.getVocabularyLabel = exports.getApplicationProfileLabel = void 0;
|
|
4
4
|
const namespaces_1 = require("./namespaces");
|
|
5
5
|
function getApplicationProfileLabel(subject, store, language = null) {
|
|
6
6
|
var _a, _b, _c;
|
|
@@ -92,4 +92,16 @@ function getMaxCount(subject, store) {
|
|
|
92
92
|
return (_a = store.findObject(subject, namespaces_1.ns.shacl('maxCount'))) === null || _a === void 0 ? void 0 : _a.value;
|
|
93
93
|
}
|
|
94
94
|
exports.getMaxCount = getMaxCount;
|
|
95
|
+
function findAllAttributes(subject, attributeIds, store) {
|
|
96
|
+
const parentIds = store.findObjects(subject, namespaces_1.ns.rdfs('subClassOf'));
|
|
97
|
+
attributeIds = [
|
|
98
|
+
...attributeIds,
|
|
99
|
+
...store.findSubjects(namespaces_1.ns.rdfs('domain'), subject),
|
|
100
|
+
];
|
|
101
|
+
for (const parentId of parentIds) {
|
|
102
|
+
attributeIds = findAllAttributes(parentId, attributeIds, store);
|
|
103
|
+
}
|
|
104
|
+
return attributeIds;
|
|
105
|
+
}
|
|
106
|
+
exports.findAllAttributes = findAllAttributes;
|
|
95
107
|
//# sourceMappingURL=storeUtils.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toCamelCase = exports.toPascalCase = void 0;
|
|
4
|
+
function removeCaret(text) {
|
|
5
|
+
return text.replace(/^\^/u, '');
|
|
6
|
+
}
|
|
7
|
+
function toPascalCase(text) {
|
|
8
|
+
return removeCaret(text)
|
|
9
|
+
.replace(/(?:^\w|[A-Z]|\b\w)/gu, (word, index) => word.toUpperCase())
|
|
10
|
+
.replace(/\s+/gu, '');
|
|
11
|
+
}
|
|
12
|
+
exports.toPascalCase = toPascalCase;
|
|
13
|
+
function toCamelCase(text) {
|
|
14
|
+
return removeCaret(text)
|
|
15
|
+
.replace(/(?:^\w|[A-Z]|\b\w)/gu, (word, index) => index === 0 ? word.toLowerCase() : word.toUpperCase())
|
|
16
|
+
.replace(/\s+/gu, '');
|
|
17
|
+
}
|
|
18
|
+
exports.toCamelCase = toCamelCase;
|
|
19
|
+
//# sourceMappingURL=strings.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oslo-flanders/core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.11",
|
|
4
4
|
"description": "Core interfaces and utilities",
|
|
5
5
|
"author": "Digitaal Vlaanderen <https://data.vlaanderen.be/id/organisatie/OVO002949>",
|
|
6
6
|
"homepage": "https://github.com/informatievlaanderen/OSLO-UML-Transformer/tree/main/packages/oslo-core#readme",
|
|
@@ -33,10 +33,10 @@
|
|
|
33
33
|
"crypto-js": "^4.1.1",
|
|
34
34
|
"inversify": "^6.0.1",
|
|
35
35
|
"n3": "^1.16.2",
|
|
36
|
-
"node-fetch": "^2.6.7",
|
|
37
36
|
"rdf-data-factory": "^1.1.1",
|
|
38
37
|
"rdf-parse": "^2.1.1",
|
|
39
38
|
"reflect-metadata": "^0.1.13",
|
|
39
|
+
"node-fetch": "^2.6.7",
|
|
40
40
|
"streamify-string": "^1.0.1",
|
|
41
41
|
"winston": "^3.8.2",
|
|
42
42
|
"winston-transport": "^4.5.0"
|