api-tuner 0.4.0 → 0.4.2
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.
- package/lib/download-eye.js +32 -0
- package/lib/merge-curl-output.js +6 -10
- package/package.json +7 -3
- package/rules/assertions.n3 +13 -1
- package/rules/requests.n3 +0 -3
- package/lib/download-eye.sh +0 -6
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#! /usr/bin/env node
|
|
2
|
+
/* eslint-disable no-console */
|
|
3
|
+
import fs from 'node:fs'
|
|
4
|
+
import { Readable } from 'node:stream'
|
|
5
|
+
import * as tar from 'tar'
|
|
6
|
+
|
|
7
|
+
async function main() {
|
|
8
|
+
const EYE_VERSION = process.env.EYE_VERSION
|
|
9
|
+
const url = `https://github.com/eyereasoner/eye/archive/refs/tags/v${EYE_VERSION}.tar.gz`
|
|
10
|
+
|
|
11
|
+
// Download and extract tarball directly from stream
|
|
12
|
+
const res = await fetch(url)
|
|
13
|
+
if (!res.ok) throw new Error(`Failed to download: ${res.statusText}`)
|
|
14
|
+
await new Promise((resolve, reject) => {
|
|
15
|
+
Readable.fromWeb(res.body)
|
|
16
|
+
.pipe(tar.x())
|
|
17
|
+
.on('finish', resolve)
|
|
18
|
+
.on('error', reject)
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
// Remove existing 'eye' directory if it exists
|
|
22
|
+
if (fs.existsSync('eye')) {
|
|
23
|
+
fs.rmSync('eye', { recursive: true, force: true })
|
|
24
|
+
}
|
|
25
|
+
// Rename extracted folder
|
|
26
|
+
fs.renameSync(`eye-${EYE_VERSION}`, 'eye')
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
main().catch(err => {
|
|
30
|
+
console.error(err)
|
|
31
|
+
process.exit(1)
|
|
32
|
+
})
|
package/lib/merge-curl-output.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import * as fs from 'node:fs/promises';
|
|
2
2
|
import { createReadStream } from 'node:fs';
|
|
3
|
+
import { writeFile } from 'node:fs/promises';
|
|
4
|
+
import url from 'node:url';
|
|
3
5
|
// eslint-disable-next-line import/default
|
|
4
6
|
import jsonld from 'jsonld';
|
|
5
7
|
import rdf from '@zazuko/env-node';
|
|
@@ -33,18 +35,12 @@ const ns = rdf.namespace('https://api-tuner.described.at/');
|
|
|
33
35
|
parser = rdf.formats.parsers.get(contentType);
|
|
34
36
|
}
|
|
35
37
|
if (parser) {
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
response.dataset.add(rdf.quad(quad.subject, quad.predicate, quad.object, bodyGraph));
|
|
40
|
-
}
|
|
41
|
-
response.addOut(ns.body, bodyGraph);
|
|
38
|
+
const body = parser.import(createReadStream(bodyPath));
|
|
39
|
+
await writeFile(`${bodyPath}.nt`, rdf.formats.serializers.get('application/n-triples').import(body));
|
|
40
|
+
response.addOut(ns.body, rdf.namedNode(url.pathToFileURL(`${bodyPath}.nt`).toString()));
|
|
42
41
|
}
|
|
43
42
|
else {
|
|
44
|
-
|
|
45
|
-
if (body) {
|
|
46
|
-
response.addOut(ns.body, body);
|
|
47
|
-
}
|
|
43
|
+
response.addOut(ns.body, bodyPath);
|
|
48
44
|
}
|
|
49
45
|
const headers = Object.entries(headersJson).flatMap(([header, values]) => values.map(value => response.blankNode().addOut(ns('name'), header).addOut(ns.value, value)));
|
|
50
46
|
response.addOut(ns.headers, headers);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "api-tuner",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"api-tuner": "./bin/tuner.sh"
|
|
9
9
|
},
|
|
10
10
|
"scripts": {
|
|
11
|
-
"download-eye": "EYE_VERSION=11.16.4 ./lib/download-eye.
|
|
11
|
+
"download-eye": "EYE_VERSION=11.16.4 ./lib/download-eye.js",
|
|
12
12
|
"postinstall": "([ -d eye ] || npm run download-eye) && eye/install.sh --prefix=eye",
|
|
13
13
|
"prepare": "husky",
|
|
14
14
|
"lint": "eslint . --quiet --ignore-path .gitignore",
|
|
@@ -36,7 +36,8 @@
|
|
|
36
36
|
"is-absolute-url": "^4.0.1",
|
|
37
37
|
"jsonld": "^8.3.3",
|
|
38
38
|
"rdf-validate-shacl": "^0.5.6",
|
|
39
|
-
"replacestream": "^4.0.3"
|
|
39
|
+
"replacestream": "^4.0.3",
|
|
40
|
+
"tar": "^7.5.1"
|
|
40
41
|
},
|
|
41
42
|
"devDependencies": {
|
|
42
43
|
"@rdfjs/types": "^1",
|
|
@@ -59,5 +60,8 @@
|
|
|
59
60
|
"*.{js,ts}": [
|
|
60
61
|
"eslint --fix --quiet"
|
|
61
62
|
]
|
|
63
|
+
},
|
|
64
|
+
"engines": {
|
|
65
|
+
"node": ">=18.0.0"
|
|
62
66
|
}
|
|
63
67
|
}
|
package/rules/assertions.n3
CHANGED
|
@@ -57,8 +57,20 @@ prefix log: <http://www.w3.org/2000/10/swap/log#>
|
|
|
57
57
|
?res tuner:body ?body .
|
|
58
58
|
} <= {
|
|
59
59
|
?res log:includes {
|
|
60
|
-
[] a tuner:Response ; tuner:body ?
|
|
60
|
+
[] a tuner:Response ; tuner:body ?bodyPath .
|
|
61
61
|
} .
|
|
62
|
+
|
|
63
|
+
(
|
|
64
|
+
{
|
|
65
|
+
?bodyPath log:rawType log:Literal .
|
|
66
|
+
}
|
|
67
|
+
{
|
|
68
|
+
("cat " ?bodyPath)!string:concatenation log:shell ?body .
|
|
69
|
+
}
|
|
70
|
+
{
|
|
71
|
+
?bodyPath log:semantics ?body .
|
|
72
|
+
}
|
|
73
|
+
) log:ifThenElseIn [] .
|
|
62
74
|
} .
|
|
63
75
|
|
|
64
76
|
{
|
package/rules/requests.n3
CHANGED
|
@@ -6,8 +6,6 @@ PREFIX tuner: <https://api-tuner.described.at/>
|
|
|
6
6
|
prefix file: <http://www.w3.org/2000/10/swap/file#>
|
|
7
7
|
prefix earl: <http://www.w3.org/ns/earl#>
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
9
|
{
|
|
12
10
|
?req tuner:response ?res .
|
|
13
11
|
} <= {
|
|
@@ -85,7 +83,6 @@ prefix earl: <http://www.w3.org/ns/earl#>
|
|
|
85
83
|
?res^tuner:trace .
|
|
86
84
|
} log:callWithCleanup {
|
|
87
85
|
{ ?responseHeadersFile!file:rm } log:callWithCleanup true .
|
|
88
|
-
{ ?responseBodyFile!file:rm } log:callWithCleanup true .
|
|
89
86
|
{ ?responseFile!file:rm } log:callWithCleanup true .
|
|
90
87
|
} .
|
|
91
88
|
} .
|