@semapps/ontologies 0.6.0-alpha.5

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.
Files changed (40) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +3 -0
  3. package/actions/findPrefix.js +23 -0
  4. package/actions/get.js +32 -0
  5. package/actions/getPrefixes.js +12 -0
  6. package/actions/getRdfPrefixes.js +11 -0
  7. package/actions/list.js +11 -0
  8. package/actions/register.js +66 -0
  9. package/index.js +16 -0
  10. package/ontologies/core/acl.json +4 -0
  11. package/ontologies/core/as.json +6 -0
  12. package/ontologies/core/dc.json +16 -0
  13. package/ontologies/core/foaf.json +4 -0
  14. package/ontologies/core/index.js +14 -0
  15. package/ontologies/core/ldp.json +4 -0
  16. package/ontologies/core/rdf.json +4 -0
  17. package/ontologies/core/rdfs.json +4 -0
  18. package/ontologies/core/sec.json +45 -0
  19. package/ontologies/core/semapps.json +4 -0
  20. package/ontologies/core/vcard.json +15 -0
  21. package/ontologies/core/void.json +23 -0
  22. package/ontologies/core/xsd.json +4 -0
  23. package/ontologies/custom/index.js +11 -0
  24. package/ontologies/custom/mp.json +4 -0
  25. package/ontologies/custom/oasis.json +4 -0
  26. package/ontologies/custom/og.json +13 -0
  27. package/ontologies/custom/pair.json +328 -0
  28. package/ontologies/custom/petr.json +4 -0
  29. package/ontologies/custom/schema.json +4 -0
  30. package/ontologies/custom/skos.json +13 -0
  31. package/ontologies/custom/syreen.json +43 -0
  32. package/ontologies/custom/tutor.json +26 -0
  33. package/ontologies/solid/apods.json +55 -0
  34. package/ontologies/solid/index.js +1 -0
  35. package/ontologies/solid/interop.json +64 -0
  36. package/ontologies/solid/oidc.json +28 -0
  37. package/package.json +19 -0
  38. package/service.js +47 -0
  39. package/sub-services/registry.js +71 -0
  40. package/utils.js +19 -0
@@ -0,0 +1,71 @@
1
+ const DbService = require('moleculer-db');
2
+ const { TripleStoreAdapter } = require('@semapps/triplestore');
3
+ const { isURL } = require('../utils');
4
+
5
+ module.exports = {
6
+ name: 'ontologies.registry',
7
+ mixins: [DbService],
8
+ adapter: new TripleStoreAdapter({ type: 'Ontology', dataset: 'settings' }),
9
+ settings: {
10
+ idField: '@id'
11
+ },
12
+ actions: {
13
+ async getByPrefix(ctx) {
14
+ const { prefix } = ctx.params;
15
+ const [ontology] = await this._find(ctx, { query: { prefix } });
16
+ return this.parse(ontology);
17
+ },
18
+ async getByNamespace(ctx) {
19
+ const { namespace } = ctx.params;
20
+ const [ontology] = await this._find(ctx, { query: { namespace } });
21
+ return this.parse(ontology);
22
+ },
23
+ async list(ctx) {
24
+ const ontologies = await this._list(ctx, {});
25
+ return ontologies.rows.map(({ prefix, namespace, owl, jsonldContext, preserveContextUri }) => {
26
+ return this.parse({ prefix, namespace, owl, jsonldContext, preserveContextUri });
27
+ });
28
+ },
29
+ async updateOrCreate(ctx) {
30
+ let { prefix, namespace, owl, jsonldContext, preserveContextUri } = ctx.params;
31
+
32
+ const ontology = await this.actions.getByPrefix({ prefix }, { parentCtx: ctx });
33
+
34
+ if (!isURL(jsonldContext)) jsonldContext = JSON.stringify(jsonldContext);
35
+
36
+ if (ontology) {
37
+ await this._update(ctx, {
38
+ '@id': ontology['@id'],
39
+ namespace,
40
+ owl,
41
+ jsonldContext,
42
+ preserveContextUri
43
+ });
44
+ } else {
45
+ await this._create(ctx, {
46
+ prefix,
47
+ namespace,
48
+ owl,
49
+ jsonldContext,
50
+ preserveContextUri
51
+ });
52
+ }
53
+ }
54
+ },
55
+ methods: {
56
+ parse(ontology) {
57
+ // If the jsonldContext is not an URL, it is an object to be parsed
58
+ if (ontology?.jsonldContext && !isURL(ontology.jsonldContext)) {
59
+ ontology.jsonldContext = JSON.parse(ontology.jsonldContext);
60
+ }
61
+
62
+ if (ontology?.preserveContextUri === 'true') {
63
+ ontology.preserveContextUri = true;
64
+ } else if (ontology?.preserveContextUri === 'false') {
65
+ ontology.preserveContextUri = false;
66
+ }
67
+
68
+ return ontology;
69
+ }
70
+ }
71
+ };
package/utils.js ADDED
@@ -0,0 +1,19 @@
1
+ const arrayOf = value => {
2
+ // If the field is null-ish, we suppose there are no values.
3
+ if (!value) {
4
+ return [];
5
+ }
6
+ // Return as is.
7
+ if (Array.isArray(value)) {
8
+ return value;
9
+ }
10
+ // Single value is made an array.
11
+ return [value];
12
+ };
13
+
14
+ const isURL = value => (typeof value === 'string' || value instanceof String) && value.startsWith('http');
15
+
16
+ module.exports = {
17
+ arrayOf,
18
+ isURL
19
+ };