@oslo-flanders/core 1.0.10 → 1.0.12

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 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
@@ -4,6 +4,8 @@ export declare class QuadStore {
4
4
  constructor();
5
5
  addQuads(quads: RDF.Quad[]): void;
6
6
  addQuad(quad: RDF.Quad): void;
7
+ removeQuads(quad: RDF.Quad[]): void;
8
+ removeQuad(quad: RDF.Quad): void;
7
9
  addQuadsFromFile(file: string): Promise<void>;
8
10
  findQuads(subject: RDF.Term | null, predicate: RDF.Term | null, object: RDF.Term | null, graph?: RDF.Term | null): RDF.Quad[];
9
11
  findQuad(subject: RDF.Term | null, predicate: RDF.Term | null, object: RDF.Term | null, graph?: RDF.Term | null): RDF.Quad | undefined;
@@ -208,8 +210,20 @@ export declare class QuadStore {
208
210
  /**
209
211
  * Finds the oslo:value of a given RDF.Term
210
212
  * @param subject The RDF.Term to find the oslo:key of
211
- * @param store A N3 quad store
213
+ * @param graph The RDF.Term of the named graph
212
214
  * @returns An RDF.Term or undefined if not found
213
215
  */
214
216
  getOsloExtensionValue(subject: RDF.Term, graph?: RDF.Term | null): RDF.NamedNode | undefined;
217
+ /**
218
+ * Find the parent attribute of an attribute
219
+ * @param subject The RDF.Term to find the parent attribute of
220
+ * @param graph The RDF.Term of the named graph
221
+ */
222
+ getParentAttribute(subject: RDF.Term, graph?: RDF.Term | null): RDF.Term | undefined;
223
+ /**
224
+ * Find the child attribute of an attribute
225
+ * @param subject The RDF.Term to find the parent attribute of
226
+ * @param graph The RDF.Term of the named graph
227
+ */
228
+ getChildAttribute(subject: RDF.Term, graph?: RDF.Term | null): RDF.Term | undefined;
215
229
  }
@@ -51,6 +51,12 @@ let QuadStore = class QuadStore {
51
51
  addQuad(quad) {
52
52
  this.store.addQuad(quad);
53
53
  }
54
+ removeQuads(quad) {
55
+ this.store.removeQuads(quad);
56
+ }
57
+ removeQuad(quad) {
58
+ this.store.removeQuad(quad);
59
+ }
54
60
  async addQuadsFromFile(file) {
55
61
  const buffer = await (0, fetchFileOrUrl_1.fetchFileOrUrl)(file);
56
62
  const textStream = require('streamify-string')(buffer.toString());
@@ -361,12 +367,28 @@ let QuadStore = class QuadStore {
361
367
  /**
362
368
  * Finds the oslo:value of a given RDF.Term
363
369
  * @param subject The RDF.Term to find the oslo:key of
364
- * @param store A N3 quad store
370
+ * @param graph The RDF.Term of the named graph
365
371
  * @returns An RDF.Term or undefined if not found
366
372
  */
367
373
  getOsloExtensionValue(subject, graph = null) {
368
374
  return (this.store.getObjects(subject, namespaces_1.ns.oslo('value'), graph).shift());
369
375
  }
376
+ /**
377
+ * Find the parent attribute of an attribute
378
+ * @param subject The RDF.Term to find the parent attribute of
379
+ * @param graph The RDF.Term of the named graph
380
+ */
381
+ getParentAttribute(subject, graph = null) {
382
+ return (this.findObject(subject, namespaces_1.ns.oslo('parentAttribute')));
383
+ }
384
+ /**
385
+ * Find the child attribute of an attribute
386
+ * @param subject The RDF.Term to find the parent attribute of
387
+ * @param graph The RDF.Term of the named graph
388
+ */
389
+ getChildAttribute(subject, graph = null) {
390
+ return (this.findObject(subject, namespaces_1.ns.oslo('childAttribute')));
391
+ }
370
392
  };
371
393
  QuadStore = __decorate([
372
394
  (0, inversify_1.injectable)(),
@@ -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
@@ -1,4 +1,5 @@
1
1
  import type * as RDF from '@rdfjs/types';
2
+ import type { DataFactory } from 'rdf-data-factory';
2
3
  import type { QuadStore } from '../store/QuadStore';
3
4
  export declare function getApplicationProfileLabel(subject: RDF.Term, store: QuadStore, language?: string | null): RDF.Literal | undefined;
4
5
  export declare function getVocabularyLabel(subject: RDF.Term, store: QuadStore, language?: string | null): RDF.Literal | undefined;
@@ -8,3 +9,5 @@ export declare function getApplicationProfileUsageNote(subject: RDF.Term, store:
8
9
  export declare function getVocabularyUsageNote(subject: RDF.Term, store: QuadStore, language?: string | null): RDF.Literal | undefined;
9
10
  export declare function getMinCount(subject: RDF.Term, store: QuadStore): string | undefined;
10
11
  export declare function getMaxCount(subject: RDF.Term, store: QuadStore): string | undefined;
12
+ export declare function createList(items: RDF.Term[], store: QuadStore, df: DataFactory): RDF.BlankNode | RDF.NamedNode;
13
+ export declare function findAllAttributes(subject: RDF.Term, attributeIds: RDF.Term[], store: QuadStore): RDF.Term[];
@@ -1,45 +1,41 @@
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.createList = 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;
7
7
  const labels = store.getLabels(subject);
8
- if (labels.some(x => x.predicate.equals(namespaces_1.ns.oslo('apLabel')))) {
9
- return (_a = labels
10
- .find(x => x.predicate.equals(namespaces_1.ns.oslo('apLabel')) &&
11
- x.object.language === (language || ''))) === null || _a === void 0 ? void 0 : _a.object;
8
+ if (labels.some((x) => x.predicate.equals(namespaces_1.ns.oslo('apLabel')))) {
9
+ return ((_a = labels.find((x) => x.predicate.equals(namespaces_1.ns.oslo('apLabel')) &&
10
+ x.object.language === (language || ''))) === null || _a === void 0 ? void 0 : _a.object);
12
11
  }
13
- if (labels.some(x => x.predicate.equals(namespaces_1.ns.oslo('vocLabel')))) {
14
- return (_b = labels.find(x => x.predicate.equals(namespaces_1.ns.oslo('vocLabel')) &&
15
- x.object.language === (language || ''))) === null || _b === void 0 ? void 0 : _b.object;
12
+ if (labels.some((x) => x.predicate.equals(namespaces_1.ns.oslo('vocLabel')))) {
13
+ return ((_b = labels.find((x) => x.predicate.equals(namespaces_1.ns.oslo('vocLabel')) &&
14
+ x.object.language === (language || ''))) === null || _b === void 0 ? void 0 : _b.object);
16
15
  }
17
- return (_c = labels.find(x => x.predicate.equals(namespaces_1.ns.oslo('diagramLabel')))) === null || _c === void 0 ? void 0 : _c.object;
16
+ return ((_c = labels.find((x) => x.predicate.equals(namespaces_1.ns.oslo('diagramLabel')))) === null || _c === void 0 ? void 0 : _c.object);
18
17
  }
19
18
  exports.getApplicationProfileLabel = getApplicationProfileLabel;
20
19
  function getVocabularyLabel(subject, store, language = null) {
21
20
  var _a, _b;
22
21
  const labels = store.getLabels(subject);
23
- if (labels.some(x => x.predicate.equals(namespaces_1.ns.oslo('vocLabel')))) {
24
- return (_a = labels
25
- .find(x => x.predicate.equals(namespaces_1.ns.oslo('vocLabel')) &&
26
- x.object.language === (language || ''))) === null || _a === void 0 ? void 0 : _a.object;
22
+ if (labels.some((x) => x.predicate.equals(namespaces_1.ns.oslo('vocLabel')))) {
23
+ return ((_a = labels.find((x) => x.predicate.equals(namespaces_1.ns.oslo('vocLabel')) &&
24
+ x.object.language === (language || ''))) === null || _a === void 0 ? void 0 : _a.object);
27
25
  }
28
- return (_b = labels.find(x => x.predicate.equals(namespaces_1.ns.oslo('diagramLabel')))) === null || _b === void 0 ? void 0 : _b.object;
26
+ return ((_b = labels.find((x) => x.predicate.equals(namespaces_1.ns.oslo('diagramLabel')))) === null || _b === void 0 ? void 0 : _b.object);
29
27
  }
30
28
  exports.getVocabularyLabel = getVocabularyLabel;
31
29
  function getApplicationProfileDefinition(subject, store, language = null) {
32
30
  var _a, _b;
33
31
  const definitions = store.getDefinitions(subject);
34
- if (definitions.some(x => x.predicate.equals(namespaces_1.ns.oslo('apDefinition')))) {
35
- return (_a = definitions
36
- .find(x => x.predicate.equals(namespaces_1.ns.oslo('apDefinition')) &&
37
- x.object.language === (language || ''))) === null || _a === void 0 ? void 0 : _a.object;
32
+ if (definitions.some((x) => x.predicate.equals(namespaces_1.ns.oslo('apDefinition')))) {
33
+ return ((_a = definitions.find((x) => x.predicate.equals(namespaces_1.ns.oslo('apDefinition')) &&
34
+ x.object.language === (language || ''))) === null || _a === void 0 ? void 0 : _a.object);
38
35
  }
39
- if (definitions.some(x => x.predicate.equals(namespaces_1.ns.oslo('vocDefinition')))) {
40
- return (_b = definitions
41
- .find(x => x.predicate.equals(namespaces_1.ns.oslo('vocDefinition')) &&
42
- x.object.language === (language || ''))) === null || _b === void 0 ? void 0 : _b.object;
36
+ if (definitions.some((x) => x.predicate.equals(namespaces_1.ns.oslo('vocDefinition')))) {
37
+ return ((_b = definitions.find((x) => x.predicate.equals(namespaces_1.ns.oslo('vocDefinition')) &&
38
+ x.object.language === (language || ''))) === null || _b === void 0 ? void 0 : _b.object);
43
39
  }
44
40
  return undefined;
45
41
  }
@@ -47,10 +43,9 @@ exports.getApplicationProfileDefinition = getApplicationProfileDefinition;
47
43
  function getVocabularyDefinition(subject, store, language = null) {
48
44
  var _a;
49
45
  const definitions = store.getDefinitions(subject);
50
- if (definitions.some(x => x.predicate.equals(namespaces_1.ns.oslo('vocDefinition')))) {
51
- return (_a = definitions
52
- .find(x => x.predicate.equals(namespaces_1.ns.oslo('vocDefinition')) &&
53
- x.object.language === (language || ''))) === null || _a === void 0 ? void 0 : _a.object;
46
+ if (definitions.some((x) => x.predicate.equals(namespaces_1.ns.oslo('vocDefinition')))) {
47
+ return ((_a = definitions.find((x) => x.predicate.equals(namespaces_1.ns.oslo('vocDefinition')) &&
48
+ x.object.language === (language || ''))) === null || _a === void 0 ? void 0 : _a.object);
54
49
  }
55
50
  return undefined;
56
51
  }
@@ -58,15 +53,13 @@ exports.getVocabularyDefinition = getVocabularyDefinition;
58
53
  function getApplicationProfileUsageNote(subject, store, language = null) {
59
54
  var _a, _b;
60
55
  const usageNotes = store.getUsageNotes(subject);
61
- if (usageNotes.some(x => x.predicate.equals(namespaces_1.ns.oslo('apUsageNote')))) {
62
- return (_a = usageNotes
63
- .find(x => x.predicate.equals(namespaces_1.ns.oslo('apUsageNote')) &&
64
- x.object.language === (language || ''))) === null || _a === void 0 ? void 0 : _a.object;
56
+ if (usageNotes.some((x) => x.predicate.equals(namespaces_1.ns.oslo('apUsageNote')))) {
57
+ return ((_a = usageNotes.find((x) => x.predicate.equals(namespaces_1.ns.oslo('apUsageNote')) &&
58
+ x.object.language === (language || ''))) === null || _a === void 0 ? void 0 : _a.object);
65
59
  }
66
- if (usageNotes.some(x => x.predicate.equals(namespaces_1.ns.oslo('vocUsageNote')))) {
67
- return (_b = usageNotes
68
- .find(x => x.predicate.equals(namespaces_1.ns.oslo('vocUsageNote')) &&
69
- x.object.language === (language || ''))) === null || _b === void 0 ? void 0 : _b.object;
60
+ if (usageNotes.some((x) => x.predicate.equals(namespaces_1.ns.oslo('vocUsageNote')))) {
61
+ return ((_b = usageNotes.find((x) => x.predicate.equals(namespaces_1.ns.oslo('vocUsageNote')) &&
62
+ x.object.language === (language || ''))) === null || _b === void 0 ? void 0 : _b.object);
70
63
  }
71
64
  return undefined;
72
65
  }
@@ -74,10 +67,9 @@ exports.getApplicationProfileUsageNote = getApplicationProfileUsageNote;
74
67
  function getVocabularyUsageNote(subject, store, language = null) {
75
68
  var _a;
76
69
  const usageNotes = store.getUsageNotes(subject);
77
- if (usageNotes.some(x => x.predicate.equals(namespaces_1.ns.oslo('vocUsageNote')))) {
78
- return (_a = usageNotes
79
- .find(x => x.predicate.equals(namespaces_1.ns.oslo('vocUsageNote')) &&
80
- x.object.language === (language || ''))) === null || _a === void 0 ? void 0 : _a.object;
70
+ if (usageNotes.some((x) => x.predicate.equals(namespaces_1.ns.oslo('vocUsageNote')))) {
71
+ return ((_a = usageNotes.find((x) => x.predicate.equals(namespaces_1.ns.oslo('vocUsageNote')) &&
72
+ x.object.language === (language || ''))) === null || _a === void 0 ? void 0 : _a.object);
81
73
  }
82
74
  return undefined;
83
75
  }
@@ -92,4 +84,48 @@ function getMaxCount(subject, store) {
92
84
  return (_a = store.findObject(subject, namespaces_1.ns.shacl('maxCount'))) === null || _a === void 0 ? void 0 : _a.value;
93
85
  }
94
86
  exports.getMaxCount = getMaxCount;
87
+ function createList(items, store, df) {
88
+ const list = [df.blankNode()];
89
+ const quads = [];
90
+ /* Empty list has a single NamedNode RDF:nil */
91
+ if (items.length === 0)
92
+ return df.namedNode(namespaces_1.ns.rdf('nil'));
93
+ items.forEach((entry, index) => {
94
+ const subject = list[index];
95
+ const object = entry;
96
+ /* Items must be identifiers */
97
+ if (object.termType !== 'NamedNode' && object.termType !== 'BlankNode')
98
+ return;
99
+ /* Current list item */
100
+ quads.push(df.quad(subject, namespaces_1.ns.rdf('first'), object));
101
+ if (index === items.length - 1) {
102
+ /* End of list */
103
+ quads.push(df.quad(subject, namespaces_1.ns.rdf('rest'), namespaces_1.ns.rdf('nil')));
104
+ }
105
+ else {
106
+ /* Next item of the list */
107
+ list.push(df.blankNode());
108
+ const nextSubject = list[index + 1];
109
+ /* Items must be identifiers */
110
+ if (nextSubject.termType !== 'BlankNode')
111
+ return;
112
+ quads.push(df.quad(subject, namespaces_1.ns.rdf('rest'), nextSubject));
113
+ }
114
+ });
115
+ store.addQuads(quads);
116
+ return list[0];
117
+ }
118
+ exports.createList = createList;
119
+ function findAllAttributes(subject, attributeIds, store) {
120
+ const parentIds = store.findObjects(subject, namespaces_1.ns.rdfs('subClassOf'));
121
+ attributeIds = [
122
+ ...attributeIds,
123
+ ...store.findSubjects(namespaces_1.ns.rdfs('domain'), subject),
124
+ ];
125
+ for (const parentId of parentIds) {
126
+ attributeIds = findAllAttributes(parentId, attributeIds, store);
127
+ }
128
+ return attributeIds;
129
+ }
130
+ exports.findAllAttributes = findAllAttributes;
95
131
  //# sourceMappingURL=storeUtils.js.map
@@ -0,0 +1,2 @@
1
+ export declare function toPascalCase(text: string): string;
2
+ export declare function toCamelCase(text: string): string;
@@ -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.10",
3
+ "version": "1.0.12",
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"