vite-plugin-sparql 0.1.0 → 0.1.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/CHANGELOG.md +8 -0
- package/README.md +48 -0
- package/index.js +9 -4
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
package/README.md
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
### vite-plugin-sparql
|
|
2
|
+
|
|
3
|
+
Vite plugin that compiles SPARQL `.rq` (query) and `.ru` (update) files with `sparqlc`, so you can import them like regular modules.
|
|
4
|
+
|
|
5
|
+
- Transforms `.rq`/`.ru` to ESM at build/dev time
|
|
6
|
+
- Optional `?base=` query to resolve relative IRIs
|
|
7
|
+
- Works in dev server and build
|
|
8
|
+
|
|
9
|
+
#### Install
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
npm i -D vite-plugin-sparql sparqlc
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
#### Usage
|
|
16
|
+
|
|
17
|
+
vite.config.ts:
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { defineConfig } from 'vite'
|
|
21
|
+
import sparql from 'vite-plugin-sparql'
|
|
22
|
+
|
|
23
|
+
export default defineConfig({
|
|
24
|
+
plugins: [sparql()],
|
|
25
|
+
})
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Import a query and execute it with `sparql-http-client`:
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
import env from '@zazuko/env'
|
|
32
|
+
import type { ParsingClient } from 'sparql-http-client'
|
|
33
|
+
|
|
34
|
+
const { default: selectAll } = await import('./queries/select-all.rq')
|
|
35
|
+
|
|
36
|
+
declare const client: ParsingClient
|
|
37
|
+
const rows = await selectAll({ env, client })
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Pass a base IRI via query parameter to resolve relative IRIs in the file:
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
const { default: q } = await import('./queries/select-relative.rq?base=http%3A%2F%2Fexample.org%2F')
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Notes:
|
|
47
|
+
- The plugin recognizes both `.rq` and `.ru` extensions.
|
|
48
|
+
- For runtime import attributes in Node.js (`with: { base }`), use the companion loader `node-loader-sparql` instead.
|
package/index.js
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import { compile } from 'sparqlc';
|
|
2
2
|
export default {
|
|
3
3
|
name: 'vite-plugin-sparql',
|
|
4
|
+
enforce: 'pre',
|
|
4
5
|
transform(code, id) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
// Vite passes the full id including query (e.g., /abs/path.q.rq?import&base=...)
|
|
7
|
+
const url = new URL(id, 'file://');
|
|
8
|
+
const pathname = url.pathname;
|
|
9
|
+
if (/\.r[qu]$/.test(pathname)) {
|
|
10
|
+
const base = url.searchParams.get('base') ?? undefined;
|
|
11
|
+
const compiled = compile(code, { base: base ?? undefined });
|
|
12
|
+
return { code: compiled.code, map: null };
|
|
8
13
|
}
|
|
9
|
-
return
|
|
14
|
+
return null;
|
|
10
15
|
},
|
|
11
16
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-sparql",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"files": [
|
|
@@ -21,19 +21,19 @@
|
|
|
21
21
|
"directory": "packages/vite-plugin-sparql"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"sparqlc": "^0.1.
|
|
24
|
+
"sparqlc": "^0.1.5"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
27
|
"vite": ">=6"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@testing-library/dom": "^10.4.1",
|
|
31
|
-
"@vitest/browser": "^4.
|
|
32
|
-
"@vitest/browser-playwright": "^4.
|
|
31
|
+
"@vitest/browser": "^4.1.10",
|
|
32
|
+
"@vitest/browser-playwright": "^4.1.10",
|
|
33
33
|
"@zazuko/env": "^3.0.1",
|
|
34
34
|
"playwright": "^1.58.2",
|
|
35
35
|
"sparql-http-client": "^3.1.0",
|
|
36
|
-
"vite": "^
|
|
37
|
-
"vitest": "^4.
|
|
36
|
+
"vite": "^8.1.5",
|
|
37
|
+
"vitest": "^4.1.10"
|
|
38
38
|
}
|
|
39
39
|
}
|