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

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.
@@ -0,0 +1,21 @@
1
+ const fetch = require('node-fetch');
2
+
3
+ module.exports = {
4
+ visibility: 'public',
5
+ params: {
6
+ prefix: 'string'
7
+ },
8
+ async handler(ctx) {
9
+ const { prefix } = ctx.params;
10
+
11
+ const response = await fetch(`http://prefix.cc/${prefix}.file.json`);
12
+
13
+ if (response.ok) {
14
+ const json = await response.json();
15
+
16
+ return json && json[prefix];
17
+ }
18
+
19
+ return null;
20
+ }
21
+ };
@@ -0,0 +1,27 @@
1
+ const { isURL } = require('../utils');
2
+
3
+ const regexPrefix = /^([^:]+):([^:]+)$/gm;
4
+
5
+ module.exports = {
6
+ visibility: 'public',
7
+ params: {
8
+ value: 'string'
9
+ },
10
+ cache: true,
11
+ async handler(ctx) {
12
+ const { value } = ctx.params;
13
+
14
+ // Check if this is already a full URI
15
+ if (isURL(value)) return value;
16
+
17
+ if (!value.match(regexPrefix)) throw new Error(`The provided value ${value} is neither prefixed, nor a full URI`);
18
+
19
+ const matchResults = regexPrefix.exec(value);
20
+ const prefix = matchResults[1];
21
+
22
+ const ontology = await this.actions.get({ prefix });
23
+ if (!ontology) throw new Error(`No ontology found with prefix ${prefix}`);
24
+
25
+ return value.replace(`${ontology.prefix}:`, ontology.namespace);
26
+ }
27
+ };
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@semapps/ontologies",
3
- "version": "0.6.0-alpha.5",
3
+ "version": "0.6.0-alpha.6",
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.5",
8
+ "@semapps/triplestore": "0.6.0-alpha.6",
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": "414ac397e95e469019abecf11d404b1b489415a6"
18
+ "gitHead": "4e052b3addc99b7884016fce417309d52d780ac6"
19
19
  }
package/service.js CHANGED
@@ -1,10 +1,12 @@
1
1
  const { TripleStoreAdapter } = require('@semapps/triplestore');
2
2
  const OntologiesRegistryService = require('./sub-services/registry');
3
3
  const findPrefixAction = require('./actions/findPrefix');
4
+ const findNamespaceAction = require('./actions/findNamespace');
4
5
  const getAction = require('./actions/get');
5
6
  const getPrefixesAction = require('./actions/getPrefixes');
6
7
  const getRdfPrefixesAction = require('./actions/getRdfPrefixes');
7
8
  const listAction = require('./actions/list');
9
+ const prefixToUriAction = require('./actions/prefixToUri');
8
10
  const registerAction = require('./actions/register');
9
11
 
10
12
  module.exports = {
@@ -30,10 +32,12 @@ module.exports = {
30
32
  },
31
33
  actions: {
32
34
  findPrefix: findPrefixAction,
35
+ findNamespace: findNamespaceAction,
33
36
  get: getAction,
34
37
  getPrefixes: getPrefixesAction,
35
38
  getRdfPrefixes: getRdfPrefixesAction,
36
39
  list: listAction,
40
+ prefixToUri: prefixToUriAction,
37
41
  register: registerAction
38
42
  },
39
43
  methods: {