vite-plugin-sparql 0.1.0 → 0.2.0

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 CHANGED
@@ -1,5 +1,25 @@
1
1
  # vite-plugin-sparql
2
2
 
3
+ ## 0.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - aee2ac3: Remove support for `sparqlc:param` used as a predicate
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [44c09b9]
12
+ - Updated dependencies [d0a2b76]
13
+ - sparqlc@0.2.0
14
+
15
+ ## 0.1.1
16
+
17
+ ### Patch Changes
18
+
19
+ - ccfe1e2: Added support for `base` import attribute
20
+ - Updated dependencies [ccfe1e2]
21
+ - sparqlc@0.1.5
22
+
3
23
  ## 0.1.0
4
24
 
5
25
  ### Minor Changes
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
- if (id.endsWith('.rq')) {
6
- const compiled = compile(code);
7
- return compiled.code;
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 code;
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.0",
3
+ "version": "0.2.0",
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.0"
24
+ "sparqlc": "^0.2.0"
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.0.18",
32
- "@vitest/browser-playwright": "^4.0.18",
31
+ "@vitest/browser": "^5",
32
+ "@vitest/browser-playwright": "^5",
33
33
  "@zazuko/env": "^3.0.1",
34
34
  "playwright": "^1.58.2",
35
35
  "sparql-http-client": "^3.1.0",
36
- "vite": "^7.0.0",
37
- "vitest": "^4.0.18"
36
+ "vite": "^8.3.3",
37
+ "vitest": "^5.0.3"
38
38
  }
39
39
  }