@semapps/ontologies 0.9.1 → 0.9.3

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.
@@ -1,4 +1,5 @@
1
1
  const fetch = require('node-fetch');
2
+ const { isURL } = require('../utils');
2
3
 
3
4
  module.exports = {
4
5
  visibility: 'public',
@@ -8,6 +9,8 @@ module.exports = {
8
9
  async handler(ctx) {
9
10
  const { uri } = ctx.params;
10
11
 
12
+ if (!isURL(uri)) throw new Error(`The uri param of the ontologies.findPrefix action must be a full URL`);
13
+
11
14
  const response = await fetch(`http://prefix.cc/?q=${encodeURIComponent(uri)}`, { redirect: 'manual' });
12
15
 
13
16
  if (response.status === 302) {
package/actions/get.js CHANGED
@@ -10,25 +10,14 @@ module.exports = {
10
10
  let { prefix, namespace, uri } = ctx.params;
11
11
  let ontology;
12
12
 
13
- if (!prefix && !namespace && !uri) throw new Error('You must provide a prefix, namespace or uri parameter');
14
-
15
- if (this.settings.persistRegistry) {
16
- if (prefix) {
17
- ontology = await ctx.call('ontologies.registry.getByPrefix', { prefix });
18
- } else if (namespace) {
19
- ontology = await ctx.call('ontologies.registry.getByNamespace', { namespace });
20
- } else if (uri) {
21
- const ontologies = await ctx.call('ontologies.registry.list');
22
- ontology = ontologies.find(o => uri.startsWith(o.namespace));
23
- }
13
+ if (prefix) {
14
+ ontology = this.ontologies[prefix] || false;
15
+ } else if (namespace) {
16
+ ontology = Object.values(this.ontologies).find(o => o.namespace === namespace);
17
+ } else if (uri) {
18
+ ontology = Object.values(this.ontologies).find(o => uri.startsWith(o.namespace));
24
19
  } else {
25
- if (prefix) {
26
- ontology = this.ontologies[prefix] || false;
27
- } else if (namespace) {
28
- ontology = Object.values(this.ontologies).find(o => o.namespace === namespace);
29
- } else if (uri) {
30
- ontology = Object.values(this.ontologies).find(o => uri.startsWith(o.namespace));
31
- }
20
+ throw new Error('You must provide a prefix, namespace or uri parameter');
32
21
  }
33
22
 
34
23
  // Must return null if no results, because the cache JsonSerializer cannot handle undefined values
package/actions/list.js CHANGED
@@ -1,11 +1,7 @@
1
1
  module.exports = {
2
2
  visibility: 'public',
3
3
  cache: true,
4
- async handler(ctx) {
5
- if (this.settings.persistRegistry) {
6
- return await ctx.call('ontologies.registry.list');
7
- } else {
8
- return Object.values(this.ontologies);
9
- }
4
+ handler() {
5
+ return Object.values(this.ontologies);
10
6
  }
11
7
  };
@@ -12,16 +12,10 @@ module.exports = {
12
12
  optional: true
13
13
  },
14
14
  preserveContextUri: { type: 'boolean', default: false },
15
- overwrite: { type: 'boolean', default: false }
15
+ persist: { type: 'boolean', default: false }
16
16
  },
17
17
  async handler(ctx) {
18
- let { prefix, namespace, owl, jsonldContext, preserveContextUri, overwrite } = ctx.params;
19
-
20
- const ontology = await this.actions.get({ prefix }, { parentCtx: ctx });
21
-
22
- if (!overwrite && ontology) {
23
- throw new Error(`Cannot register ${prefix} ontology. An ontology with the prefix is already registered`);
24
- }
18
+ let { prefix, namespace, owl, jsonldContext, preserveContextUri, persist } = ctx.params;
25
19
 
26
20
  if (preserveContextUri === true) {
27
21
  if (!jsonldContext || !arrayOf(jsonldContext).every(context => isURL(context))) {
@@ -31,14 +25,20 @@ module.exports = {
31
25
  }
32
26
  }
33
27
 
34
- if (this.settings.persistRegistry) {
28
+ if (persist) {
29
+ if (!this.settings.persistRegistry)
30
+ throw new Error(`Cannot persist ontology because the persistRegistry setting is false`);
31
+ if (owl || jsonldContext) throw new Error(`The owl and jsonldContext params cannot be persisted`);
32
+
35
33
  await ctx.call('ontologies.registry.updateOrCreate', {
36
34
  prefix,
37
- namespace,
38
- owl,
39
- jsonldContext,
40
- preserveContextUri
35
+ namespace
41
36
  });
37
+
38
+ this.ontologies[prefix] = {
39
+ prefix,
40
+ namespace
41
+ };
42
42
  } else {
43
43
  this.ontologies[prefix] = {
44
44
  prefix,
@@ -50,6 +50,30 @@
50
50
  },
51
51
  "apods:registeredClass": {
52
52
  "@type": "@id"
53
+ },
54
+ "apods:registeredContainer": {
55
+ "@type": "@id"
56
+ },
57
+ "apods:hasClassDescription": {
58
+ "@type": "@id"
59
+ },
60
+ "apods:preferredForClass": {
61
+ "@type": "@id"
62
+ },
63
+ "apods:describedClass": {
64
+ "@type": "@id"
65
+ },
66
+ "apods:describedBy": {
67
+ "@type": "@id"
68
+ },
69
+ "apods:labelPredicate": {
70
+ "@type": "@id"
71
+ },
72
+ "apods:defaultApp": {
73
+ "@type": "@id"
74
+ },
75
+ "apods:availableApps": {
76
+ "@type": "@id"
53
77
  }
54
78
  }
55
79
  }
@@ -1 +1,8 @@
1
- module.exports = { apods: require('./apods.json'), interop: require('./interop.json'), oidc: require('./oidc.json') };
1
+ module.exports = {
2
+ apods: require('./apods.json'),
3
+ interop: require('./interop.json'),
4
+ notify: require('./notify.json'),
5
+ oidc: require('./oidc.json'),
6
+ pim: require('./pim.json'),
7
+ solid: require('./solid.json')
8
+ };
@@ -39,6 +39,9 @@
39
39
  "interop:hasAccessNeedGroup": {
40
40
  "@type": "@id"
41
41
  },
42
+ "interop:hasAccessDescriptionSet": {
43
+ "@type": "@id"
44
+ },
42
45
  "interop:hasDataGrant": {
43
46
  "@type": "@id"
44
47
  },
@@ -59,6 +62,9 @@
59
62
  },
60
63
  "interop:updatedAt": {
61
64
  "@type": "@id"
65
+ },
66
+ "interop:usesLanguage": {
67
+ "@type": "xsd:language"
62
68
  }
63
69
  }
64
70
  }
@@ -0,0 +1,62 @@
1
+ {
2
+ "prefix": "notify",
3
+ "namespace": "http://www.w3.org/ns/solid/notifications#",
4
+ "owl": "https://www.w3.org/ns/solid/notifications.ttl",
5
+ "jsonldContext": {
6
+ "xsd": "http://www.w3.org/2001/XMLSchema#",
7
+ "notify:channel": {
8
+ "@type": "@id"
9
+ },
10
+ "notify:endAt": {
11
+ "@type": "xsd:dateTime"
12
+ },
13
+ "notify:rate": {
14
+ "@type": "xsd:duration"
15
+ },
16
+ "notify:receiveFrom": {
17
+ "@type": "@id"
18
+ },
19
+ "notify:sender": {
20
+ "@type": "@id"
21
+ },
22
+ "notify:sendTo": {
23
+ "@type": "@id"
24
+ },
25
+ "notify:startAt": {
26
+ "@type": "xsd:dateTime"
27
+ },
28
+ "notify:subscription": {
29
+ "@type": "@id"
30
+ },
31
+ "notify:topic": {
32
+ "@type": "@id"
33
+ },
34
+ "notify:state": {
35
+ "@type": "@id"
36
+ },
37
+ "notify:feature": {
38
+ "@type": "@id"
39
+ },
40
+ "notify:channelType": {
41
+ "@type": "@id"
42
+ },
43
+ "notify:accept": {
44
+ "@type": "@id"
45
+ },
46
+ "notify:EventSourceChannel2023": {
47
+ "@type": "@id"
48
+ },
49
+ "notify:LDNChannel2023": {
50
+ "@type": "@id"
51
+ },
52
+ "notify:StreamingHTTPChannel2023": {
53
+ "@type": "@id"
54
+ },
55
+ "notify:WebhookChannel2023": {
56
+ "@type": "@id"
57
+ },
58
+ "notify:WebSocketChannel2023": {
59
+ "@type": "@id"
60
+ }
61
+ }
62
+ }
@@ -17,12 +17,6 @@
17
17
  },
18
18
  "oidc:redirect_uris": {
19
19
  "@type": "@id"
20
- },
21
- "oidc:require_auth_time": {
22
- "@type": "xsd:boolean"
23
- },
24
- "oidc:default_max_age": {
25
- "@type": "xsd:integer"
26
20
  }
27
21
  }
28
22
  }
@@ -0,0 +1,15 @@
1
+ {
2
+ "prefix": "pim",
3
+ "namespace": "http://www.w3.org/ns/pim/space#",
4
+ "jsonldContext": {
5
+ "pim:storage": {
6
+ "@type": "@id"
7
+ },
8
+ "pim:preferencesFile": {
9
+ "@type": "@id"
10
+ },
11
+ "pim:workspace": {
12
+ "@type": "@id"
13
+ }
14
+ }
15
+ }
@@ -0,0 +1,27 @@
1
+ {
2
+ "prefix": "solid",
3
+ "namespace": "http://www.w3.org/ns/solid/terms#",
4
+ "jsonldContext": {
5
+ "solid:publicTypeIndex": {
6
+ "@type": "@id"
7
+ },
8
+ "solid:privateTypeIndex": {
9
+ "@type": "@id"
10
+ },
11
+ "solid:hasTypeRegistration": {
12
+ "@type": "@id"
13
+ },
14
+ "solid:forClass": {
15
+ "@type": "@id"
16
+ },
17
+ "solid:instance": {
18
+ "@type": "@id"
19
+ },
20
+ "solid:instanceContainer": {
21
+ "@type": "@id"
22
+ },
23
+ "solid:oidcIssuer": {
24
+ "@type": "@id"
25
+ }
26
+ }
27
+ }
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@semapps/ontologies",
3
- "version": "0.9.1",
3
+ "version": "0.9.3",
4
4
  "description": "SemApps ontologies",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Virtual Assembly",
7
7
  "dependencies": {
8
- "@semapps/triplestore": "0.9.1",
8
+ "@semapps/triplestore": "0.9.3",
9
9
  "moleculer-db": "^0.8.16",
10
10
  "node-fetch": "^2.6.6"
11
11
  },
@@ -15,5 +15,5 @@
15
15
  "engines": {
16
16
  "node": ">=14"
17
17
  },
18
- "gitHead": "7a337e5056d74edd3f789adf5592ae13a504646a"
18
+ "gitHead": "5c2f6a4d17379b25af3c2361e832ed10373841c3"
19
19
  }
package/service.js CHANGED
@@ -26,8 +26,7 @@ module.exports = {
26
26
  }
27
27
  },
28
28
  async started() {
29
- if (!this.settings.persistRegistry) this.ontologies = {};
30
-
29
+ this.ontologies = {};
31
30
  await this.registerAll();
32
31
  },
33
32
  actions: {
@@ -42,12 +41,13 @@ module.exports = {
42
41
  },
43
42
  methods: {
44
43
  async registerAll() {
45
- if (this.settings.persistRegistry) await this.broker.waitForServices(['ontologies.registry']);
44
+ if (this.settings.persistRegistry) {
45
+ await this.broker.waitForServices(['ontologies.registry']);
46
+ const persistedOntologies = await this.broker.call('ontologies.registry.list');
47
+ this.ontologies = { ...this.ontologies, ...persistedOntologies };
48
+ }
46
49
  for (const ontology of this.settings.ontologies) {
47
- if (!ontology || !ontology.prefix || !ontology.namespace) {
48
- throw new Error(`Cannot register ontologies ! At least one ontology is incorrect.`);
49
- }
50
- await this.actions.register({ ...ontology, overwrite: true });
50
+ await this.actions.register(ontology);
51
51
  }
52
52
  }
53
53
  }
@@ -1,6 +1,5 @@
1
1
  const DbService = require('moleculer-db');
2
2
  const { TripleStoreAdapter } = require('@semapps/triplestore');
3
- const { isURL } = require('../utils');
4
3
 
5
4
  module.exports = {
6
5
  name: 'ontologies.registry',
@@ -13,59 +12,33 @@ module.exports = {
13
12
  async getByPrefix(ctx) {
14
13
  const { prefix } = ctx.params;
15
14
  const [ontology] = await this._find(ctx, { query: { prefix } });
16
- return this.parse(ontology);
15
+ return ontology && { prefix: ontology.prefix, namespace: ontology.namespace };
17
16
  },
18
17
  async getByNamespace(ctx) {
19
18
  const { namespace } = ctx.params;
20
19
  const [ontology] = await this._find(ctx, { query: { namespace } });
21
- return this.parse(ontology);
20
+ return ontology && { prefix: ontology.prefix, namespace: ontology.namespace };
22
21
  },
23
22
  async list(ctx) {
24
23
  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
- });
24
+ return ontologies.rows.map(({ prefix, namespace }) => ({ prefix, namespace }));
28
25
  },
29
26
  async updateOrCreate(ctx) {
30
- let { prefix, namespace, owl, jsonldContext, preserveContextUri } = ctx.params;
27
+ const { prefix, namespace } = ctx.params;
31
28
 
32
29
  const ontology = await this.actions.getByPrefix({ prefix }, { parentCtx: ctx });
33
30
 
34
- if (!isURL(jsonldContext)) jsonldContext = JSON.stringify(jsonldContext);
35
-
36
31
  if (ontology) {
37
32
  await this._update(ctx, {
38
33
  '@id': ontology['@id'],
39
- namespace,
40
- owl,
41
- jsonldContext,
42
- preserveContextUri
34
+ namespace
43
35
  });
44
36
  } else {
45
37
  await this._create(ctx, {
46
38
  prefix,
47
- namespace,
48
- owl,
49
- jsonldContext,
50
- preserveContextUri
39
+ namespace
51
40
  });
52
41
  }
53
42
  }
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
43
  }
71
44
  };