api-tuner 0.4.1 → 0.5.1

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/index.js CHANGED
@@ -1,13 +1,16 @@
1
1
  import * as url from 'node:url';
2
2
  import * as childProcess from 'node:child_process';
3
- import { PassThrough } from 'node:stream';
4
- import { resolve } from 'node:path';
3
+ import { PassThrough, Readable } from 'node:stream';
4
+ import { resolve, dirname } from 'node:path';
5
5
  import { program } from 'commander';
6
6
  import getStream from 'get-stream';
7
+ import mergeStreams from '@sindresorhus/merge-streams';
8
+ import rdf from '@zazuko/env-node';
7
9
  import packageJson from './package.json' with { type: 'json' };
8
10
  import parseTestCase from './lib/parse-test-case.js';
9
11
  import summariseResults from './lib/summarise-results.js';
10
12
  const eyePvmPath = url.fileURLToPath(new URL('eye/lib/eye.pvm', import.meta.url));
13
+ const tuner = rdf.namespace('https://api-tuner.described.at/');
11
14
  program
12
15
  .name('api-tuner')
13
16
  .option('--lib <lib>', 'Specify rules to include in all tests. Can be used multiple times. Make sure to surround globs in quotes to prevent expansion.', (lib, arr) => [...arr, lib], [])
@@ -47,7 +50,6 @@ const levelIcon = {
47
50
  };
48
51
  async function processPath(path) {
49
52
  return new Promise(resolve => {
50
- const testCaseStream = parseTestCase(path, options.baseIri);
51
53
  const eyeProc = childProcess.spawn('swipl', [
52
54
  '-x',
53
55
  eyePvmPath,
@@ -59,7 +61,10 @@ async function processPath(path) {
59
61
  ], {
60
62
  shell: true,
61
63
  });
62
- testCaseStream.pipe(eyeProc.stdin);
64
+ mergeStreams([
65
+ parseTestCase(path, options.baseIri),
66
+ tunerParams({ path }),
67
+ ]).pipe(eyeProc.stdin);
63
68
  const stdout = new PassThrough();
64
69
  const stderr = new PassThrough();
65
70
  eyeProc.on('exit', (code) => {
@@ -73,6 +78,14 @@ async function processPath(path) {
73
78
  eyeProc.stderr.pipe(stderr);
74
79
  });
75
80
  }
81
+ function tunerParams({ path }) {
82
+ const rdfString = rdf.clownface()
83
+ .blankNode()
84
+ .addOut(tuner.scriptPath, dirname(resolve(path)))
85
+ .dataset
86
+ .toCanonical();
87
+ return Readable.from(rdfString);
88
+ }
76
89
  const testSuites = program.args.map(async (path) => {
77
90
  const absolutePath = resolve(process.cwd(), path);
78
91
  const result = await processPath(path);
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "api-tuner",
3
- "version": "0.4.1",
3
+ "version": "0.5.1",
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.sh",
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",
@@ -30,13 +30,15 @@
30
30
  "dependencies": {
31
31
  "@changesets/cli": "^2.29.7",
32
32
  "@jeswr/pretty-turtle": "^1.5.0",
33
+ "@sindresorhus/merge-streams": "^4.0.0",
33
34
  "@zazuko/env-node": "^2.1.4",
34
35
  "commander": "^13.1.0",
35
36
  "get-stream": "^9.0.1",
36
37
  "is-absolute-url": "^4.0.1",
37
38
  "jsonld": "^8.3.3",
38
39
  "rdf-validate-shacl": "^0.5.6",
39
- "replacestream": "^4.0.3"
40
+ "replacestream": "^4.0.3",
41
+ "tar": "^7.5.2"
40
42
  },
41
43
  "devDependencies": {
42
44
  "@rdfjs/types": "^1",
@@ -59,5 +61,8 @@
59
61
  "*.{js,ts}": [
60
62
  "eslint --fix --quiet"
61
63
  ]
64
+ },
65
+ "engines": {
66
+ "node": ">=18.0.0"
62
67
  }
63
68
  }
package/rules/files.n3 CHANGED
@@ -1,3 +1,4 @@
1
+ PREFIX tuner: <https://api-tuner.described.at/>
1
2
  prefix e: <http://eulersharp.sourceforge.net/2003/03swap/log-rules#>
2
3
  prefix string: <http://www.w3.org/2000/10/swap/string#>
3
4
  prefix log: <http://www.w3.org/2000/10/swap/log#>
@@ -49,5 +50,9 @@ prefix file: <http://www.w3.org/2000/10/swap/file#>
49
50
  ?fileUri string:startsWith "file:" .
50
51
  ( ?fileUri 6 ) string:substring ?relative .
51
52
 
52
- ( "@$(pwd)/" ?relative ) string:concatenation ?ref .
53
+ [
54
+ tuner:scriptPath ?scriptPath
55
+ ] .
56
+
57
+ ( "@'" ?scriptPath "/" ?relative "'" ) string:concatenation ?ref .
53
58
  } .
@@ -1,6 +0,0 @@
1
- curl -sL https://github.com/eyereasoner/eye/archive/refs/tags/v"${EYE_VERSION}".tar.gz -o eye.tar.gz
2
-
3
- tar -xvzf eye.tar.gz
4
- rm eye.tar.gz
5
-
6
- mv eye-"${EYE_VERSION}" eye