@semapps/ontologies 0.6.0-alpha.6 → 0.6.0-alpha.7

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 (2) hide show
  1. package/actions/get.js +14 -6
  2. package/package.json +3 -3
package/actions/get.js CHANGED
@@ -8,25 +8,33 @@ module.exports = {
8
8
  cache: true,
9
9
  async handler(ctx) {
10
10
  let { prefix, namespace, uri } = ctx.params;
11
+ let ontology;
12
+
11
13
  if (!prefix && !namespace && !uri) throw new Error('You must provide a prefix, namespace or uri parameter');
12
14
 
13
15
  if (this.settings.persistRegistry) {
14
16
  if (prefix) {
15
- return await ctx.call('ontologies.registry.getByPrefix', { prefix });
17
+ ontology = await ctx.call('ontologies.registry.getByPrefix', { prefix });
16
18
  } else if (namespace) {
17
- return await ctx.call('ontologies.registry.getByNamespace', { namespace });
19
+ ontology = await ctx.call('ontologies.registry.getByNamespace', { namespace });
18
20
  } else if (uri) {
19
21
  const ontologies = await ctx.call('ontologies.registry.list');
20
- return ontologies.find(o => uri.startsWith(o.namespace));
22
+ ontology = ontologies.find(o => uri.startsWith(o.namespace));
21
23
  }
22
24
  } else {
23
25
  if (prefix) {
24
- return this.ontologies[prefix];
26
+ ontology = this.ontologies[prefix] || false;
25
27
  } else if (namespace) {
26
- return Object.values(this.ontologies).find(o => o.namespace === namespace);
28
+ ontology = Object.values(this.ontologies).find(o => o.namespace === namespace);
27
29
  } else if (uri) {
28
- return Object.values(this.ontologies).find(o => uri.startsWith(o.namespace));
30
+ ontology = Object.values(this.ontologies).find(o => uri.startsWith(o.namespace));
29
31
  }
30
32
  }
33
+
34
+ // Must return null if no results, because the cache JsonSerializer cannot handle undefined values
35
+ // https://moleculer.services/docs/0.14/networking.html#JSON-serializer
36
+ if (ontology === undefined) ontology = null;
37
+
38
+ return ontology;
31
39
  }
32
40
  };
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@semapps/ontologies",
3
- "version": "0.6.0-alpha.6",
3
+ "version": "0.6.0-alpha.7",
4
4
  "description": "SemApps ontologies",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Virtual Assembly",
7
7
  "dependencies": {
8
- "@semapps/triplestore": "0.6.0-alpha.6",
8
+ "@semapps/triplestore": "0.6.0-alpha.7",
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": "4e052b3addc99b7884016fce417309d52d780ac6"
18
+ "gitHead": "7af60c59fc7524fe32a5931ba9609d55b228fea5"
19
19
  }