@manta-eu/horns-client 0.1.2 → 0.1.4
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/dist/index.d.ts +1 -0
- package/dist/index.js +9 -3
- package/dist/lib/manta/sparql-select.d.ts +13 -3
- package/dist/lib/manta/sparql-select.js +30 -14
- package/package.json +4 -5
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { AppRoutes, hornsRoutes } from "./app/routes.tsx";
|
|
2
|
+
export { HornsApp } from "./standalone/app.tsx";
|
|
2
3
|
export { AppShell } from "./components/app-shell.tsx";
|
|
3
4
|
export { signInHref } from "./lib/manta/sign-in.ts";
|
|
4
5
|
export { useSparqlSelect } from "./lib/manta/sparql-select.ts";
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
// The Horns app, as a library.
|
|
2
2
|
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
3
|
+
// Horns is a page rather than a subtree: `Providers` renders the SDK's own <Router>, scoped by basename to
|
|
4
|
+
// /d/<datastore>, and React Router allows no second one. So a host takes `mountHorns` for a page of its own,
|
|
5
|
+
// or renders `<HornsApp />` under providers it builds itself. `hornsRoutes()` is for a host doing the latter
|
|
6
|
+
// and wanting its own 404 — spliced into a <Routes> under that basename, never nested in a second router.
|
|
7
|
+
// What the browser needs beyond this is the stylesheet: `@manta-eu/horns-client/styles.css`, built here
|
|
8
|
+
// rather than compiled by the host, so a host with no Tailwind still gets the app looking like Manta.
|
|
6
9
|
export { AppRoutes, hornsRoutes } from "./app/routes.js";
|
|
10
|
+
// The session gate, and the only thing that provides the AuthContext every Horns page reads. A host
|
|
11
|
+
// splicing `hornsRoutes()` into a router of its own mounts this above them, or provides that context itself.
|
|
12
|
+
export { HornsApp } from "./standalone/app.js";
|
|
7
13
|
export { AppShell } from "./components/app-shell.js";
|
|
8
14
|
export { signInHref } from "./lib/manta/sign-in.js";
|
|
9
15
|
export { useSparqlSelect } from "./lib/manta/sparql-select.js";
|
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
import { SparqlReadError, type SparqlSelect } from "@manta-eu/horns";
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
/**
|
|
2
|
+
import { useMantaClient } from "@manta-eu/react/providers";
|
|
3
|
+
type SparqlFetch = ReturnType<typeof useMantaClient>["sparqlFetch"];
|
|
4
|
+
/**
|
|
5
|
+
* Reads over `/sparql`, which is the endpoint that checks them.
|
|
6
|
+
*
|
|
7
|
+
* Not agents' `sparqlQuery` field: a query travelling as a GraphQL variable is not a request body, so no
|
|
8
|
+
* proxy's read-only check sees it, and a host would have to allow `/graphql` to let a Horn draw at all.
|
|
9
|
+
*
|
|
10
|
+
* Imperative rather than a hook: a `SparqlSelect` is called from inside query functions and from readers
|
|
11
|
+
* that issue one query after another, which a hook cannot serve.
|
|
12
|
+
*/
|
|
13
|
+
export declare function httpSparqlSelect(sparqlFetch: SparqlFetch): SparqlSelect;
|
|
14
|
+
/** The reader this app's pages use. The datastore rides on the fetch, from the route. */
|
|
5
15
|
export declare function useSparqlSelect(): SparqlSelect;
|
|
6
16
|
export { SparqlReadError };
|
|
@@ -1,22 +1,38 @@
|
|
|
1
1
|
import { useMemo } from "react";
|
|
2
|
-
import {
|
|
3
|
-
import { SparqlQueryDocument } from "@manta-eu/client";
|
|
2
|
+
import { SparqlReadError, sparqlResultsSchema } from "@manta-eu/horns";
|
|
4
3
|
import { useMantaClient } from "@manta-eu/react/providers";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
/** What a refused or failed read says, where the worker answered `{ error }` rather than results. */
|
|
5
|
+
async function refusalOf(response) {
|
|
6
|
+
const body = await response.json().catch(() => undefined);
|
|
7
|
+
if (typeof body === "object" && body !== null && "error" in body && typeof body.error === "string") {
|
|
8
|
+
return body.error;
|
|
9
|
+
}
|
|
10
|
+
return `The read failed (${response.status}).`;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Reads over `/sparql`, which is the endpoint that checks them.
|
|
14
|
+
*
|
|
15
|
+
* Not agents' `sparqlQuery` field: a query travelling as a GraphQL variable is not a request body, so no
|
|
16
|
+
* proxy's read-only check sees it, and a host would have to allow `/graphql` to let a Horn draw at all.
|
|
17
|
+
*
|
|
18
|
+
* Imperative rather than a hook: a `SparqlSelect` is called from inside query functions and from readers
|
|
19
|
+
* that issue one query after another, which a hook cannot serve.
|
|
20
|
+
*/
|
|
21
|
+
export function httpSparqlSelect(sparqlFetch) {
|
|
8
22
|
return async (query, signal) => {
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
23
|
+
const response = await sparqlFetch(query, signal ? { signal } : {});
|
|
24
|
+
if (!response.ok)
|
|
25
|
+
throw new SparqlReadError(await refusalOf(response));
|
|
26
|
+
const body = await response.json().catch(() => undefined);
|
|
27
|
+
const parsed = sparqlResultsSchema.safeParse(body);
|
|
28
|
+
if (!parsed.success)
|
|
29
|
+
throw new SparqlReadError("The query answered something other than results.");
|
|
30
|
+
return parsed.data;
|
|
15
31
|
};
|
|
16
32
|
}
|
|
17
|
-
/** The reader this app's pages use. The datastore rides on the
|
|
33
|
+
/** The reader this app's pages use. The datastore rides on the fetch, from the route. */
|
|
18
34
|
export function useSparqlSelect() {
|
|
19
|
-
const {
|
|
20
|
-
return useMemo(() =>
|
|
35
|
+
const { sparqlFetch } = useMantaClient();
|
|
36
|
+
return useMemo(() => httpSparqlSelect(sparqlFetch), [sparqlFetch]);
|
|
21
37
|
}
|
|
22
38
|
export { SparqlReadError };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@manta-eu/horns-client",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "The Manta Horns app as a library: routes, providers and the written-view runtime for a React host.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -60,15 +60,14 @@
|
|
|
60
60
|
"@manta-eu/lib": "0.1.5",
|
|
61
61
|
"@ulb-darmstadt/shacl-form": "^2.1.1-rc1",
|
|
62
62
|
"@xyflow/react": "^12.4.4",
|
|
63
|
-
"graphql-request": "^7.3.0",
|
|
64
63
|
"html-to-image": "1.11.13",
|
|
65
64
|
"ldkit": "2.9.0",
|
|
66
65
|
"lucide-react": "^0.525.0",
|
|
67
66
|
"ts-pattern": "^5.9.0",
|
|
68
67
|
"zod": "^4.5.4",
|
|
69
|
-
"@manta-eu/horns": "0.1.
|
|
70
|
-
"@manta-eu/horns-kit": "0.1.
|
|
71
|
-
"@manta-eu/horns-server": "0.1.
|
|
68
|
+
"@manta-eu/horns": "0.1.4",
|
|
69
|
+
"@manta-eu/horns-kit": "0.1.4",
|
|
70
|
+
"@manta-eu/horns-server": "0.1.4"
|
|
72
71
|
},
|
|
73
72
|
"devDependencies": {
|
|
74
73
|
"@manta-eu/ldo": "0.1.5",
|