From 8ca0de3b67676ad9419667b2c973e34d095d6db0 Mon Sep 17 00:00:00 2001 From: srosset81 Date: Fri, 28 May 2021 18:27:08 +0200 Subject: [PATCH 1/9] Cache JsonLD contexts --- src/middleware/packages/jsonld/mixin.js | 41 +++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/middleware/packages/jsonld/mixin.js diff --git a/src/middleware/packages/jsonld/mixin.js b/src/middleware/packages/jsonld/mixin.js new file mode 100644 index 000000000..b73ee7107 --- /dev/null +++ b/src/middleware/packages/jsonld/mixin.js @@ -0,0 +1,41 @@ +const jsonld = require('jsonld'); +// const ApiGatewayService = require('moleculer-web'); +const LRU = require('lru-cache'); + +const defaultDocumentLoader = jsonld.documentLoaders.node(); +const cache = new LRU({ max: 500 }); + +module.exports = { + settings: { + defaultContextFile: null + }, + dependencies: ['api'], + started() { + this.jsonld = jsonld; + this.jsonld.documentLoader = this.documentLoaderWithCache; + + // this.broker.call('api.addRoute', { route: + // { + // path: '/context.json', + // use: [ + // ApiGatewayService.serveStatic(this.defaultContextFile, { + // setHeaders: res => { + // res.setHeader('Access-Control-Allow-Origin', '*'); + // res.setHeader('Content-Type', 'application/ld+json; charset=utf-8'); + // } + // }) + // ] + // } + // }); + }, + methods: { + async documentLoaderWithCache(url, options) { + if(cache.has(url)) { + return cache.get(url); + } else { + const contextJson = defaultDocumentLoader(url, options); + cache.set(url, contextJson) + } + } + } +}; From 65dc35f95ba38cdc881956ad5b2129f1ec9f11d2 Mon Sep 17 00:00:00 2001 From: srosset81 Date: Fri, 28 May 2021 16:28:06 +0000 Subject: [PATCH 2/9] Automatic prettier --- src/middleware/packages/jsonld/mixin.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/middleware/packages/jsonld/mixin.js b/src/middleware/packages/jsonld/mixin.js index b73ee7107..2b0ae11e9 100644 --- a/src/middleware/packages/jsonld/mixin.js +++ b/src/middleware/packages/jsonld/mixin.js @@ -30,11 +30,11 @@ module.exports = { }, methods: { async documentLoaderWithCache(url, options) { - if(cache.has(url)) { + if (cache.has(url)) { return cache.get(url); } else { const contextJson = defaultDocumentLoader(url, options); - cache.set(url, contextJson) + cache.set(url, contextJson); } } } From 0ece849e676f63fd318ec641ebf4ed1b3ab5ec82 Mon Sep 17 00:00:00 2001 From: srosset81 Date: Mon, 31 May 2021 17:46:18 +0200 Subject: [PATCH 3/9] Working --- .../boilerplates/pair-ldp-server/package.json | 1 + .../pair-ldp-server/services/api.service.js | 13 -- .../services/jsonld.service.js | 14 ++ .../packages/inference/package.json | 1 - src/middleware/packages/inference/service.js | 11 +- src/middleware/packages/jsonld/LICENSE | 201 ++++++++++++++++++ src/middleware/packages/jsonld/README.md | 5 + src/middleware/packages/jsonld/index.js | 3 + src/middleware/packages/jsonld/mixin.js | 41 ---- .../packages/jsonld/package-lock.json | 116 ++++++++++ src/middleware/packages/jsonld/package.json | 15 ++ src/middleware/packages/jsonld/service.js | 93 ++++++++ src/middleware/packages/ldp/package.json | 1 - .../ldp/services/container/actions/get.js | 9 +- .../packages/ldp/services/container/index.js | 2 +- .../ldp/services/resource/actions/get.js | 10 +- .../packages/ldp/services/resource/index.js | 2 +- src/middleware/packages/triplestore/index.js | 9 +- .../packages/triplestore/package.json | 1 - src/middleware/packages/webacl/package.json | 1 - .../services/resource/actions/getRights.js | 15 +- .../webacl/services/resource/index.js | 2 +- 22 files changed, 479 insertions(+), 87 deletions(-) create mode 100644 src/middleware/boilerplates/pair-ldp-server/services/jsonld.service.js create mode 100644 src/middleware/packages/jsonld/LICENSE create mode 100644 src/middleware/packages/jsonld/README.md create mode 100644 src/middleware/packages/jsonld/index.js delete mode 100644 src/middleware/packages/jsonld/mixin.js create mode 100644 src/middleware/packages/jsonld/package-lock.json create mode 100644 src/middleware/packages/jsonld/package.json create mode 100644 src/middleware/packages/jsonld/service.js diff --git a/src/middleware/boilerplates/pair-ldp-server/package.json b/src/middleware/boilerplates/pair-ldp-server/package.json index 85642911b..fbfc8eb62 100644 --- a/src/middleware/boilerplates/pair-ldp-server/package.json +++ b/src/middleware/boilerplates/pair-ldp-server/package.json @@ -18,6 +18,7 @@ "@semapps/backup": "0.2.1", "@semapps/fuseki-admin": "0.2.1", "@semapps/inference": "0.2.1", + "@semapps/jsonld": "0.2.1", "@semapps/ldp": "0.2.1", "@semapps/mime-types": "0.2.1", "@semapps/signature": "0.2.1", diff --git a/src/middleware/boilerplates/pair-ldp-server/services/api.service.js b/src/middleware/boilerplates/pair-ldp-server/services/api.service.js index e64918bd4..0468b8061 100644 --- a/src/middleware/boilerplates/pair-ldp-server/services/api.service.js +++ b/src/middleware/boilerplates/pair-ldp-server/services/api.service.js @@ -6,19 +6,6 @@ module.exports = { settings: { server: true, port: CONFIG.PORT, - routes: [ - { - path: '/context.json', - use: [ - ApiGatewayService.serveStatic('./public/context.json', { - setHeaders: res => { - res.setHeader('Access-Control-Allow-Origin', '*'); - res.setHeader('Content-Type', 'application/ld+json; charset=utf-8'); - } - }) - ] - } - ], cors: { origin: '*', methods: ['GET', 'PUT', 'PATCH', 'POST', 'DELETE', 'HEAD', 'OPTIONS'], diff --git a/src/middleware/boilerplates/pair-ldp-server/services/jsonld.service.js b/src/middleware/boilerplates/pair-ldp-server/services/jsonld.service.js new file mode 100644 index 000000000..2bd23a53b --- /dev/null +++ b/src/middleware/boilerplates/pair-ldp-server/services/jsonld.service.js @@ -0,0 +1,14 @@ +const path = require('path'); +const { JsonLdService } = require('@semapps/jsonld'); +const CONFIG = require('../config'); + +module.exports = { + mixins: [JsonLdService], + settings: { + baseUri: CONFIG.HOME_URL, + localContextFiles: [{ + path: '/context.json', + file: path.resolve(__dirname, '../public/context.json') + }] + } +}; diff --git a/src/middleware/packages/inference/package.json b/src/middleware/packages/inference/package.json index 551a11d5e..da2f1da66 100644 --- a/src/middleware/packages/inference/package.json +++ b/src/middleware/packages/inference/package.json @@ -5,7 +5,6 @@ "license": "Apache-2.0", "author": "Virtual Assembly", "dependencies": { - "jsonld": "^5.2.0", "n3": "^1.6.3" }, "publishConfig": { diff --git a/src/middleware/packages/inference/service.js b/src/middleware/packages/inference/service.js index 08274410e..28a7d286e 100644 --- a/src/middleware/packages/inference/service.js +++ b/src/middleware/packages/inference/service.js @@ -1,4 +1,3 @@ -const jsonld = require('jsonld'); const request = require('request'); const N3 = require('n3'); const { DataFactory } = N3; @@ -10,7 +9,7 @@ module.exports = { baseUrl: null, ontologies: [] }, - dependencies: ['triplestore', 'ldp'], + dependencies: ['triplestore', 'ldp', 'jsonld'], created() { this.inverseRelations = this.findInverseRelations(); }, @@ -99,7 +98,7 @@ module.exports = { events: { async 'ldp.resource.created'(ctx) { let { newData } = ctx.params; - newData = await jsonld.expand(ctx.params.newData); + newData = await ctx.call('jsonld.expand', { input: newData }); let triplesToAdd = this.generateInverseTriples(newData[0]); @@ -113,7 +112,7 @@ module.exports = { }, async 'ldp.resource.deleted'(ctx) { let { oldData } = ctx.params; - oldData = await jsonld.expand(ctx.params.oldData); + oldData = await ctx.call('jsonld.expand', { input: oldData }); let triplesToRemove = this.generateInverseTriples(oldData[0]); @@ -124,8 +123,8 @@ module.exports = { }, async 'ldp.resource.updated'(ctx) { let { oldData, newData } = ctx.params; - oldData = await jsonld.expand(ctx.params.oldData); - newData = await jsonld.expand(ctx.params.newData); + oldData = await ctx.call('jsonld.expand', { input: oldData }); + oldData = await ctx.call('jsonld.expand', { input: newData }); let triplesToRemove = this.generateInverseTriples(oldData[0]); let triplesToAdd = this.generateInverseTriples(newData[0]); diff --git a/src/middleware/packages/jsonld/LICENSE b/src/middleware/packages/jsonld/LICENSE new file mode 100644 index 000000000..261eeb9e9 --- /dev/null +++ b/src/middleware/packages/jsonld/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/src/middleware/packages/jsonld/README.md b/src/middleware/packages/jsonld/README.md new file mode 100644 index 000000000..aa3416b95 --- /dev/null +++ b/src/middleware/packages/jsonld/README.md @@ -0,0 +1,5 @@ +# @semapps/jsonld + +JsonLD utilities for SemApps + +[Documentation](https://semapps.org/docs/middleware/jsonld) diff --git a/src/middleware/packages/jsonld/index.js b/src/middleware/packages/jsonld/index.js new file mode 100644 index 000000000..0025536fc --- /dev/null +++ b/src/middleware/packages/jsonld/index.js @@ -0,0 +1,3 @@ +module.exports = { + JsonLdService: require('./service') +}; diff --git a/src/middleware/packages/jsonld/mixin.js b/src/middleware/packages/jsonld/mixin.js deleted file mode 100644 index b73ee7107..000000000 --- a/src/middleware/packages/jsonld/mixin.js +++ /dev/null @@ -1,41 +0,0 @@ -const jsonld = require('jsonld'); -// const ApiGatewayService = require('moleculer-web'); -const LRU = require('lru-cache'); - -const defaultDocumentLoader = jsonld.documentLoaders.node(); -const cache = new LRU({ max: 500 }); - -module.exports = { - settings: { - defaultContextFile: null - }, - dependencies: ['api'], - started() { - this.jsonld = jsonld; - this.jsonld.documentLoader = this.documentLoaderWithCache; - - // this.broker.call('api.addRoute', { route: - // { - // path: '/context.json', - // use: [ - // ApiGatewayService.serveStatic(this.defaultContextFile, { - // setHeaders: res => { - // res.setHeader('Access-Control-Allow-Origin', '*'); - // res.setHeader('Content-Type', 'application/ld+json; charset=utf-8'); - // } - // }) - // ] - // } - // }); - }, - methods: { - async documentLoaderWithCache(url, options) { - if(cache.has(url)) { - return cache.get(url); - } else { - const contextJson = defaultDocumentLoader(url, options); - cache.set(url, contextJson) - } - } - } -}; diff --git a/src/middleware/packages/jsonld/package-lock.json b/src/middleware/packages/jsonld/package-lock.json new file mode 100644 index 000000000..bde922924 --- /dev/null +++ b/src/middleware/packages/jsonld/package-lock.json @@ -0,0 +1,116 @@ +{ + "name": "@semapps/jsonld", + "version": "0.2.1", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "@digitalbazaar/http-client": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@digitalbazaar/http-client/-/http-client-1.1.0.tgz", + "integrity": "sha512-ks7hqa6hm9NyULdbm9qL6TRS8rADzBw8R0lETvUgvdNXu9H62XG2YqoKRDThtfgWzWxLwRJ3Z2o4ev81dZZbyQ==", + "requires": { + "esm": "^3.2.22", + "ky": "^0.25.1", + "ky-universal": "^0.8.2" + } + }, + "abort-controller": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/abort-controller/-/abort-controller-3.0.0.tgz", + "integrity": "sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==", + "requires": { + "event-target-shim": "^5.0.0" + } + }, + "canonicalize": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/canonicalize/-/canonicalize-1.0.5.tgz", + "integrity": "sha512-mAjKJPIyP0xqqv6IAkvso07StOmz6cmGtNDg3pXCSzXVZOqka7StIkAhJl/zHOi4M2CgpYfD6aeRWbnrmtvBEA==" + }, + "data-uri-to-buffer": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-3.0.1.tgz", + "integrity": "sha512-WboRycPNsVw3B3TL559F7kuBUM4d8CgMEvk6xEJlOp7OBPjt6G7z8WMWlD2rOFZLk6OYfFIUGsCOWzcQH9K2og==" + }, + "esm": { + "version": "3.2.25", + "resolved": "https://registry.npmjs.org/esm/-/esm-3.2.25.tgz", + "integrity": "sha512-U1suiZ2oDVWv4zPO56S0NcR5QriEahGtdN2OR6FiOG4WJvcjBVFB0qI4+eKoWFH483PKGuLuu6V8Z4T5g63UVA==" + }, + "event-target-shim": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/event-target-shim/-/event-target-shim-5.0.1.tgz", + "integrity": "sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==" + }, + "fetch-blob": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-2.1.2.tgz", + "integrity": "sha512-YKqtUDwqLyfyMnmbw8XD6Q8j9i/HggKtPEI+pZ1+8bvheBu78biSmNaXWusx1TauGqtUUGx/cBb1mKdq2rLYow==" + }, + "jsonld": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/jsonld/-/jsonld-5.2.0.tgz", + "integrity": "sha512-JymgT6Xzk5CHEmHuEyvoTNviEPxv6ihLWSPu1gFdtjSAyM6cFqNrv02yS/SIur3BBIkCf0HjizRc24d8/FfQKw==", + "requires": { + "@digitalbazaar/http-client": "^1.1.0", + "canonicalize": "^1.0.1", + "lru-cache": "^6.0.0", + "rdf-canonize": "^3.0.0" + } + }, + "ky": { + "version": "0.25.1", + "resolved": "https://registry.npmjs.org/ky/-/ky-0.25.1.tgz", + "integrity": "sha512-PjpCEWlIU7VpiMVrTwssahkYXX1by6NCT0fhTUX34F3DTinARlgMpriuroolugFPcMgpPWrOW4mTb984Qm1RXA==" + }, + "ky-universal": { + "version": "0.8.2", + "resolved": "https://registry.npmjs.org/ky-universal/-/ky-universal-0.8.2.tgz", + "integrity": "sha512-xe0JaOH9QeYxdyGLnzUOVGK4Z6FGvDVzcXFTdrYA1f33MZdEa45sUDaMBy98xQMcsd2XIBrTXRrRYnegcSdgVQ==", + "requires": { + "abort-controller": "^3.0.0", + "node-fetch": "3.0.0-beta.9" + } + }, + "lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "requires": { + "yallist": "^4.0.0" + } + }, + "node-fetch": { + "version": "3.0.0-beta.9", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.0.0-beta.9.tgz", + "integrity": "sha512-RdbZCEynH2tH46+tj0ua9caUHVWrd/RHnRfvly2EVdqGmI3ndS1Vn/xjm5KuGejDt2RNDQsVRLPNd2QPwcewVg==", + "requires": { + "data-uri-to-buffer": "^3.0.1", + "fetch-blob": "^2.1.1" + } + }, + "rdf-canonize": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/rdf-canonize/-/rdf-canonize-3.0.0.tgz", + "integrity": "sha512-LXRkhab1QaPJnhUIt1gtXXKswQCZ9zpflsSZFczG7mCLAkMvVjdqCGk9VXCUss0aOUeEyV2jtFxGcdX8DSkj9w==", + "requires": { + "setimmediate": "^1.0.5" + } + }, + "setimmediate": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/setimmediate/-/setimmediate-1.0.5.tgz", + "integrity": "sha1-KQy7Iy4waULX1+qbg3Mqt4VvgoU=" + }, + "url-join": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/url-join/-/url-join-4.0.1.tgz", + "integrity": "sha512-jk1+QP6ZJqyOiuEI9AEWQfju/nB2Pw466kbA0LEZljHwKeMgd9WrAEgEGxjPDD2+TNbbb37rTyhEfrCXfuKXnA==" + }, + "yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" + } + } +} diff --git a/src/middleware/packages/jsonld/package.json b/src/middleware/packages/jsonld/package.json new file mode 100644 index 000000000..2ce6f42f9 --- /dev/null +++ b/src/middleware/packages/jsonld/package.json @@ -0,0 +1,15 @@ +{ + "name": "@semapps/jsonld", + "version": "0.2.1", + "description": "JsonLD utils for SemApps", + "license": "Apache-2.0", + "author": "Virtual Assembly", + "dependencies": { + "jsonld": "^5.2.0", + "lru-cache": "^6.0.0", + "url-join": "^4.0.1" + }, + "publishConfig": { + "access": "public" + } +} diff --git a/src/middleware/packages/jsonld/service.js b/src/middleware/packages/jsonld/service.js new file mode 100644 index 000000000..7d63d12d8 --- /dev/null +++ b/src/middleware/packages/jsonld/service.js @@ -0,0 +1,93 @@ +const jsonld = require('jsonld'); +const urlJoin = require('url-join'); +const fsPromises = require('fs').promises; +const LRU = require('lru-cache'); + +const defaultDocumentLoader = jsonld.documentLoaders.node(); +const cache = new LRU({ max: 500 }); + +module.exports = { + name: 'jsonld', + settings: { + baseUri: null, + localContextFiles: [] + }, + dependencies: ['api'], + async started() { + this.jsonld = jsonld; + this.jsonld.documentLoader = this.documentLoaderWithCache; + + for( let contextFile of this.settings.localContextFiles ) { + const contextFileContent = await fsPromises.readFile(contextFile.file); + const contextJson = JSON.parse(contextFileContent); + const contextUri = urlJoin(this.settings.baseUri, contextFile.path); + + // Cache immediately this context, in case it is called before the API is activated + cache.set(contextUri, { + contextUrl: null, + documentUrl: contextUri, + document: contextJson + }); + + this.broker.call('api.addRoute', { route: + { + path: contextFile.path, + bodyParsers: { + json: true + }, + aliases: { + "GET /": [ + (req, res, next) => { req.$params.uri = contextUri; next(); }, + "jsonld.getCachedContext" + ] + } + } + }); + } + }, + actions: { + getCachedContext(ctx) { + const context = cache.get(ctx.params.uri); + return context.document; + }, + compact(ctx) { + const { input, context, options } = ctx.params; + return this.jsonld.compact(input, context, options); + }, + expand(ctx) { + const { input, options } = ctx.params; + return this.jsonld.expand(input, options); + }, + flatten(ctx) { + const { input, context, options } = ctx.params; + return this.jsonld.flatten(input, context, options); + }, + frame(ctx) { + const { input, frame, options } = ctx.params; + return this.jsonld.frame(input, frame, options); + }, + normalize(ctx) { + const { input, options } = ctx.params; + return this.jsonld.normalize(input, options); + }, + fromRDF(ctx) { + const { dataset, options } = ctx.params; + return this.jsonld.fromRDF(dataset, options); + }, + toRDF(ctx) { + const { input, options } = ctx.params; + return this.jsonld.fromRDF(input, options); + } + }, + methods: { + async documentLoaderWithCache(url, options) { + if(cache.has(url)) { + return cache.get(url); + } else { + const context = await defaultDocumentLoader(url, options); + cache.set(url, context); + return context; + } + } + } +}; diff --git a/src/middleware/packages/ldp/package.json b/src/middleware/packages/ldp/package.json index d5092c45a..c4fe66c67 100644 --- a/src/middleware/packages/ldp/package.json +++ b/src/middleware/packages/ldp/package.json @@ -9,7 +9,6 @@ "@semapps/mime-types": "0.2.1", "@semapps/triplestore": "0.2.1", "bson": "^4.0.4", - "jsonld": "^5.2.0", "moleculer": "^0.14.3", "n3": "^1.3.5", "rdf-data-model": "^1.0.0", diff --git a/src/middleware/packages/ldp/services/container/actions/get.js b/src/middleware/packages/ldp/services/container/actions/get.js index 7def2e4b4..a84ae92f8 100644 --- a/src/middleware/packages/ldp/services/container/actions/get.js +++ b/src/middleware/packages/ldp/services/container/actions/get.js @@ -1,4 +1,3 @@ -const jsonld = require('jsonld'); const { MIME_TYPES } = require('@semapps/mime-types'); const { getPrefixRdf, @@ -107,14 +106,14 @@ module.exports = { } } - result = await jsonld.compact( - { + result = await ctx.call('jsonld.compact', { + input: { '@id': containerUri, '@type': ['http://www.w3.org/ns/ldp#Container', 'http://www.w3.org/ns/ldp#BasicContainer'], 'http://www.w3.org/ns/ldp#contains': resources }, - jsonContext || getPrefixJSON(this.settings.ontologies) - ); + context: jsonContext || getPrefixJSON(this.settings.ontologies) + }); // If the ldp:contains is a single object, wrap it in an array for easier handling on the front side const ldpContainsKey = Object.keys(result).find(key => diff --git a/src/middleware/packages/ldp/services/container/index.js b/src/middleware/packages/ldp/services/container/index.js index 2a11fc56a..050a44642 100644 --- a/src/middleware/packages/ldp/services/container/index.js +++ b/src/middleware/packages/ldp/services/container/index.js @@ -18,7 +18,7 @@ module.exports = { containers: [], defaultOptions }, - dependencies: ['triplestore'], + dependencies: ['triplestore', 'jsonld'], actions: { attach: attachAction, clear: clearAction, diff --git a/src/middleware/packages/ldp/services/resource/actions/get.js b/src/middleware/packages/ldp/services/resource/actions/get.js index 1416b08a3..a09f9b845 100644 --- a/src/middleware/packages/ldp/services/resource/actions/get.js +++ b/src/middleware/packages/ldp/services/resource/actions/get.js @@ -1,6 +1,5 @@ const { MoleculerError } = require('moleculer').Errors; const { MIME_TYPES } = require('@semapps/mime-types'); -const jsonld = require('jsonld'); const { getPrefixRdf, getPrefixJSON, buildBlankNodesQuery, buildDereferenceQuery } = require('../../../utils'); const fs = require('fs'); @@ -76,9 +75,12 @@ module.exports = { // If we asked for JSON-LD, frame it using the correct context in order to have clean, consistent results if (accept === MIME_TYPES.JSON) { - result = await jsonld.frame(result, { - '@context': jsonContext || getPrefixJSON(this.settings.ontologies), - '@id': resourceUri + result = await ctx.call('jsonld.frame', { + input: result, + frame: { + '@context': jsonContext || getPrefixJSON(this.settings.ontologies), + '@id': resourceUri + } }); } diff --git a/src/middleware/packages/ldp/services/resource/index.js b/src/middleware/packages/ldp/services/resource/index.js index 59fa39281..6cd403c48 100644 --- a/src/middleware/packages/ldp/services/resource/index.js +++ b/src/middleware/packages/ldp/services/resource/index.js @@ -15,7 +15,7 @@ module.exports = { ontologies: [], containers: [] }, - dependencies: ['triplestore'], + dependencies: ['triplestore', 'jsonld'], actions: { exist: existAction, generateId: generateIdAction, diff --git a/src/middleware/packages/triplestore/index.js b/src/middleware/packages/triplestore/index.js index 1d6b4febd..c6456f8b1 100644 --- a/src/middleware/packages/triplestore/index.js +++ b/src/middleware/packages/triplestore/index.js @@ -1,4 +1,3 @@ -const jsonld = require('jsonld'); const fetch = require('node-fetch'); const { SparqlJsonParser } = require('sparqljson-parse'); const { MIME_TYPES, negotiateType } = require('@semapps/mime-types'); @@ -22,6 +21,7 @@ const TripleStoreService = { jenaUser: null, jenaPassword: null }, + dependencies: ['jsonld'], started() { this.sparqlJsonParser = new SparqlJsonParser(); this.Authorization = @@ -55,8 +55,11 @@ const TripleStoreService = { if (contentType !== MIME_TYPES.JSON) { rdf = resource; } else { - rdf = await jsonld.toRDF(resource, { - format: 'application/n-quads' + rdf = await ctx.call('jsonld.toRDF', { + input: resource, + options: { + format: 'application/n-quads' + } }); } const url = this.settings.sparqlEndpoint + this.settings.mainDataset + '/update'; diff --git a/src/middleware/packages/triplestore/package.json b/src/middleware/packages/triplestore/package.json index bac47b126..ddb2a56cf 100644 --- a/src/middleware/packages/triplestore/package.json +++ b/src/middleware/packages/triplestore/package.json @@ -7,7 +7,6 @@ "dependencies": { "@semapps/middlewares": "0.2.1", "@semapps/mime-types": "0.2.1", - "jsonld": "^5.2.0", "negotiator": "^0.6.2", "node-fetch": "^2.6.0", "sparqljson-parse": "^1.5.1" diff --git a/src/middleware/packages/webacl/package.json b/src/middleware/packages/webacl/package.json index c0895a0b3..d501bda6f 100644 --- a/src/middleware/packages/webacl/package.json +++ b/src/middleware/packages/webacl/package.json @@ -20,7 +20,6 @@ "@semapps/mime-types": "0.2.1", "@semapps/triplestore": "0.2.1", "ioredis": "^4.17.3", - "jsonld": "^5.2.0", "jsonld-streaming-serializer": "^1.2.0", "moleculer": "^0.14.3", "n3": "^1.8.0", diff --git a/src/middleware/packages/webacl/services/resource/actions/getRights.js b/src/middleware/packages/webacl/services/resource/actions/getRights.js index 17eb35b40..3b5de2f1d 100644 --- a/src/middleware/packages/webacl/services/resource/actions/getRights.js +++ b/src/middleware/packages/webacl/services/resource/actions/getRights.js @@ -1,4 +1,3 @@ -const jsonld = require('jsonld'); const JsonLdSerializer = require('jsonld-streaming-serializer').JsonLdSerializer; const { DataFactory, Writer } = require('n3'); const { quad } = DataFactory; @@ -52,7 +51,7 @@ function streamToString(stream) { }); } -async function formatOutput(output, resourceAclUri, jsonLD) { +async function formatOutput(ctx, output, resourceAclUri, jsonLD) { let turtle = await new Promise((resolve, reject) => { const writer = new Writer({ prefixes: { ...prefixes, '': resourceAclUri + '#' }, @@ -76,15 +75,15 @@ async function formatOutput(output, resourceAclUri, jsonLD) { let jsonLd = JSON.parse(await streamToString(mySerializer)); - let compactJsonLd = await jsonld.frame( - jsonLd, - { + let compactJsonLd = await ctx.call('jsonld.frame', { + input: jsonLd, + frame: { '@context': webAclContext, '@type': 'acl:Authorization' }, // Force results to be in a @graph, even if we have a single result - { omitGraph: false } - ); + options: { omitGraph: false } + }); // Add the @base context. We did not use it in the frame operation, as we don't want URIs to become relative compactJsonLd['@context'] = { ...compactJsonLd['@context'], '@base': resourceAclUri }; @@ -177,7 +176,7 @@ async function getPermissions(ctx, resourceUri, baseUrl, user, graphName, isCont document.push(...(await filterAcls(hasControl, uaSearchParam, value.controls))); } - return await formatOutput(document, resourceAclUri, ctx.meta.$responseType === MIME_TYPES.JSON); + return await formatOutput(ctx, document, resourceAclUri, ctx.meta.$responseType === MIME_TYPES.JSON); } module.exports = { diff --git a/src/middleware/packages/webacl/services/resource/index.js b/src/middleware/packages/webacl/services/resource/index.js index a7722aec8..56f052f25 100644 --- a/src/middleware/packages/webacl/services/resource/index.js +++ b/src/middleware/packages/webacl/services/resource/index.js @@ -28,7 +28,7 @@ module.exports = { baseUrl: null, graphName: null }, - dependencies: ['triplestore'], + dependencies: ['triplestore', 'jsonld'], actions: { deleteAllRights: deleteAllRightsAction.action, // Actions accessible through the API From c458144bfca7eed3178e594af3633757f7d32a37 Mon Sep 17 00:00:00 2001 From: srosset81 Date: Mon, 31 May 2021 15:47:40 +0000 Subject: [PATCH 4/9] Automatic prettier --- .../pair-ldp-server/services/jsonld.service.js | 10 ++++++---- src/middleware/packages/jsonld/service.js | 17 ++++++++++------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/middleware/boilerplates/pair-ldp-server/services/jsonld.service.js b/src/middleware/boilerplates/pair-ldp-server/services/jsonld.service.js index 2bd23a53b..3d414480e 100644 --- a/src/middleware/boilerplates/pair-ldp-server/services/jsonld.service.js +++ b/src/middleware/boilerplates/pair-ldp-server/services/jsonld.service.js @@ -6,9 +6,11 @@ module.exports = { mixins: [JsonLdService], settings: { baseUri: CONFIG.HOME_URL, - localContextFiles: [{ - path: '/context.json', - file: path.resolve(__dirname, '../public/context.json') - }] + localContextFiles: [ + { + path: '/context.json', + file: path.resolve(__dirname, '../public/context.json') + } + ] } }; diff --git a/src/middleware/packages/jsonld/service.js b/src/middleware/packages/jsonld/service.js index 7d63d12d8..453fa933c 100644 --- a/src/middleware/packages/jsonld/service.js +++ b/src/middleware/packages/jsonld/service.js @@ -17,7 +17,7 @@ module.exports = { this.jsonld = jsonld; this.jsonld.documentLoader = this.documentLoaderWithCache; - for( let contextFile of this.settings.localContextFiles ) { + for (let contextFile of this.settings.localContextFiles) { const contextFileContent = await fsPromises.readFile(contextFile.file); const contextJson = JSON.parse(contextFileContent); const contextUri = urlJoin(this.settings.baseUri, contextFile.path); @@ -29,16 +29,19 @@ module.exports = { document: contextJson }); - this.broker.call('api.addRoute', { route: - { + this.broker.call('api.addRoute', { + route: { path: contextFile.path, bodyParsers: { json: true }, aliases: { - "GET /": [ - (req, res, next) => { req.$params.uri = contextUri; next(); }, - "jsonld.getCachedContext" + 'GET /': [ + (req, res, next) => { + req.$params.uri = contextUri; + next(); + }, + 'jsonld.getCachedContext' ] } } @@ -81,7 +84,7 @@ module.exports = { }, methods: { async documentLoaderWithCache(url, options) { - if(cache.has(url)) { + if (cache.has(url)) { return cache.get(url); } else { const context = await defaultDocumentLoader(url, options); From be0e982b203a63ccfd68e069d73b70eeadabd2cc Mon Sep 17 00:00:00 2001 From: srosset81 Date: Mon, 31 May 2021 18:04:53 +0200 Subject: [PATCH 5/9] Fix tests --- src/middleware/tests/activitypub/initialize.js | 2 ++ src/middleware/tests/ldp/initialize.js | 2 ++ src/middleware/tests/package.json | 1 + src/middleware/tests/webId/webId.test.js | 2 ++ src/middleware/tests/webacl/groupCRUD.test.js | 2 ++ src/middleware/tests/webacl/resourceCRUD.test.js | 2 ++ src/middleware/tests/webacl/sparql-injection.test.js | 2 ++ 7 files changed, 13 insertions(+) diff --git a/src/middleware/tests/activitypub/initialize.js b/src/middleware/tests/activitypub/initialize.js index fb529a6e8..8ee4f87ce 100644 --- a/src/middleware/tests/activitypub/initialize.js +++ b/src/middleware/tests/activitypub/initialize.js @@ -4,6 +4,7 @@ const { ServiceBroker } = require('moleculer'); const ApiGatewayService = require('moleculer-web'); const { TripleStoreService } = require('@semapps/triplestore'); const { WebAclService, WebAclMiddleware } = require('@semapps/webacl'); +const { JsonLdService } = require('@semapps/jsonld'); const { LdpService, getPrefixJSON } = require('@semapps/ldp'); const { ActivityPubService, containers } = require('@semapps/activitypub'); const { SignatureService } = require('@semapps/signature'); @@ -24,6 +25,7 @@ const initialize = async () => { await broker.createService({ mixins: [ApiGatewayService] }); + await broker.createService(JsonLdService); await broker.createService(TripleStoreService, { settings: { sparqlEndpoint: CONFIG.SPARQL_ENDPOINT, diff --git a/src/middleware/tests/ldp/initialize.js b/src/middleware/tests/ldp/initialize.js index 4f0c74ded..ba4f4d7a8 100644 --- a/src/middleware/tests/ldp/initialize.js +++ b/src/middleware/tests/ldp/initialize.js @@ -1,5 +1,6 @@ const { ServiceBroker } = require('moleculer'); const ApiGatewayService = require('moleculer-web'); +const { JsonLdService } = require('@semapps/jsonld'); const { LdpService } = require('@semapps/ldp'); const { WebAclService, WebAclMiddleware } = require('@semapps/webacl'); const { TripleStoreService } = require('@semapps/triplestore'); @@ -16,6 +17,7 @@ const initialize = async () => { await broker.createService({ mixins: [ApiGatewayService] }); + await broker.createService(JsonLdService); await broker.createService(TripleStoreService, { settings: { sparqlEndpoint: CONFIG.SPARQL_ENDPOINT, diff --git a/src/middleware/tests/package.json b/src/middleware/tests/package.json index 258524172..0a8391cff 100644 --- a/src/middleware/tests/package.json +++ b/src/middleware/tests/package.json @@ -11,6 +11,7 @@ "@semapps/activitypub": "0.2.1", "@semapps/auth": "0.2.1", "@semapps/fuseki-admin": "0.2.1", + "@semapps/jsonld": "0.2.1", "@semapps/ldp": "0.2.1", "@semapps/middlewares": "0.2.1", "@semapps/mime-types": "0.2.1", diff --git a/src/middleware/tests/webId/webId.test.js b/src/middleware/tests/webId/webId.test.js index 27bc9ced3..b468915dc 100644 --- a/src/middleware/tests/webId/webId.test.js +++ b/src/middleware/tests/webId/webId.test.js @@ -1,6 +1,7 @@ const { ServiceBroker } = require('moleculer'); const ApiGatewayService = require('moleculer-web'); const { WebIdService } = require('@semapps/webid'); +const { JsonLdService } = require('@semapps/jsonld'); const { LdpService } = require('@semapps/ldp'); const { TripleStoreService } = require('@semapps/triplestore'); const { WebAclService, WebAclMiddleware } = require('@semapps/webacl'); @@ -18,6 +19,7 @@ beforeAll(async () => { await broker.createService({ mixins: [ApiGatewayService] }); + broker.createService(JsonLdService); broker.createService(TripleStoreService, { settings: { sparqlEndpoint: CONFIG.SPARQL_ENDPOINT, diff --git a/src/middleware/tests/webacl/groupCRUD.test.js b/src/middleware/tests/webacl/groupCRUD.test.js index 3f81ea8b1..2548962a1 100644 --- a/src/middleware/tests/webacl/groupCRUD.test.js +++ b/src/middleware/tests/webacl/groupCRUD.test.js @@ -1,5 +1,6 @@ const { ServiceBroker } = require('moleculer'); const ApiGatewayService = require('moleculer-web'); +const { JsonLdService } = require('@semapps/jsonld'); const { LdpService } = require('@semapps/ldp'); const { WebAclService, WebAclMiddleware } = require('@semapps/webacl'); const ontologies = require('../ontologies'); @@ -20,6 +21,7 @@ const broker = new ServiceBroker({ let expressMocked = undefined; beforeAll(async () => { + broker.createService(JsonLdService); broker.createService(TripleStoreService, { settings: { sparqlEndpoint: CONFIG.SPARQL_ENDPOINT, diff --git a/src/middleware/tests/webacl/resourceCRUD.test.js b/src/middleware/tests/webacl/resourceCRUD.test.js index 68ce0c62f..4dfc7ca7e 100644 --- a/src/middleware/tests/webacl/resourceCRUD.test.js +++ b/src/middleware/tests/webacl/resourceCRUD.test.js @@ -1,5 +1,6 @@ const { ServiceBroker } = require('moleculer'); const ApiGatewayService = require('moleculer-web'); +const { JsonLdService } = require('@semapps/jsonld'); const { LdpService } = require('@semapps/ldp'); const { WebAclService } = require('@semapps/webacl'); const { MIME_TYPES } = require('@semapps/mime-types'); @@ -21,6 +22,7 @@ const broker = new ServiceBroker({ let expressMocked = undefined; beforeAll(async () => { + broker.createService(JsonLdService); broker.createService(TripleStoreService, { settings: { sparqlEndpoint: CONFIG.SPARQL_ENDPOINT, diff --git a/src/middleware/tests/webacl/sparql-injection.test.js b/src/middleware/tests/webacl/sparql-injection.test.js index 843be82a0..853aabe6d 100644 --- a/src/middleware/tests/webacl/sparql-injection.test.js +++ b/src/middleware/tests/webacl/sparql-injection.test.js @@ -1,5 +1,6 @@ const { ServiceBroker } = require('moleculer'); const ApiGatewayService = require('moleculer-web'); +const { JsonLdService } = require('@semapps/jsonld'); const { LdpService } = require('@semapps/ldp'); const { WebAclService, WebAclMiddleware } = require('@semapps/webacl'); const ontologies = require('../ontologies'); @@ -20,6 +21,7 @@ const broker = new ServiceBroker({ let expressMocked = undefined; beforeAll(async () => { + broker.createService(JsonLdService); broker.createService(TripleStoreService, { settings: { sparqlEndpoint: CONFIG.SPARQL_ENDPOINT, From 5ac9c715c4c0ca8fe824344c7ca0420b7fdf4f90 Mon Sep 17 00:00:00 2001 From: srosset81 Date: Mon, 31 May 2021 18:07:00 +0200 Subject: [PATCH 6/9] Fix tests --- src/middleware/packages/jsonld/service.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/middleware/packages/jsonld/service.js b/src/middleware/packages/jsonld/service.js index 453fa933c..972415f74 100644 --- a/src/middleware/packages/jsonld/service.js +++ b/src/middleware/packages/jsonld/service.js @@ -79,7 +79,7 @@ module.exports = { }, toRDF(ctx) { const { input, options } = ctx.params; - return this.jsonld.fromRDF(input, options); + return this.jsonld.toRDF(input, options); } }, methods: { From 8fe9deb6059661417e77672c717b29fb1806e458 Mon Sep 17 00:00:00 2001 From: srosset81 Date: Mon, 31 May 2021 18:09:07 +0200 Subject: [PATCH 7/9] Fix tests --- src/middleware/tests/ldp/api.test.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/middleware/tests/ldp/api.test.js b/src/middleware/tests/ldp/api.test.js index d983bb03b..21df30659 100644 --- a/src/middleware/tests/ldp/api.test.js +++ b/src/middleware/tests/ldp/api.test.js @@ -1,5 +1,6 @@ const { ServiceBroker } = require('moleculer'); const ApiGatewayService = require('moleculer-web'); +const { JsonLdService } = require('@semapps/jsonld'); const { LdpService } = require('@semapps/ldp'); const { WebAclService, WebAclMiddleware } = require('@semapps/webacl'); const { TripleStoreService } = require('@semapps/triplestore'); @@ -17,6 +18,7 @@ const broker = new ServiceBroker({ let expressMocked = undefined; beforeAll(async () => { + await broker.createService(JsonLdService); broker.createService(TripleStoreService, { settings: { sparqlEndpoint: CONFIG.SPARQL_ENDPOINT, From 5f7488537dfe1deb43b66be3c320b92e068d8ace Mon Sep 17 00:00:00 2001 From: srosset81 Date: Tue, 1 Jun 2021 10:40:30 +0200 Subject: [PATCH 8/9] Small fixes --- src/middleware/packages/inference/service.js | 2 +- src/middleware/packages/jsonld/service.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/middleware/packages/inference/service.js b/src/middleware/packages/inference/service.js index 28a7d286e..299dc4846 100644 --- a/src/middleware/packages/inference/service.js +++ b/src/middleware/packages/inference/service.js @@ -124,7 +124,7 @@ module.exports = { async 'ldp.resource.updated'(ctx) { let { oldData, newData } = ctx.params; oldData = await ctx.call('jsonld.expand', { input: oldData }); - oldData = await ctx.call('jsonld.expand', { input: newData }); + newData = await ctx.call('jsonld.expand', { input: newData }); let triplesToRemove = this.generateInverseTriples(oldData[0]); let triplesToAdd = this.generateInverseTriples(newData[0]); diff --git a/src/middleware/packages/jsonld/service.js b/src/middleware/packages/jsonld/service.js index 972415f74..ad619041f 100644 --- a/src/middleware/packages/jsonld/service.js +++ b/src/middleware/packages/jsonld/service.js @@ -50,6 +50,7 @@ module.exports = { }, actions: { getCachedContext(ctx) { + ctx.meta.$responseType = "application/ld+json"; const context = cache.get(ctx.params.uri); return context.document; }, From 97f75a2a8bacfe531c65bebcb372955811198452 Mon Sep 17 00:00:00 2001 From: srosset81 Date: Tue, 1 Jun 2021 08:41:18 +0000 Subject: [PATCH 9/9] Automatic prettier --- src/middleware/packages/jsonld/service.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/middleware/packages/jsonld/service.js b/src/middleware/packages/jsonld/service.js index ad619041f..490ee3c0e 100644 --- a/src/middleware/packages/jsonld/service.js +++ b/src/middleware/packages/jsonld/service.js @@ -50,7 +50,7 @@ module.exports = { }, actions: { getCachedContext(ctx) { - ctx.meta.$responseType = "application/ld+json"; + ctx.meta.$responseType = 'application/ld+json'; const context = cache.get(ctx.params.uri); return context.document; },