@lde/wait-for-sparql 0.0.3
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/README.md +3 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +18 -0
- package/package.json +26 -0
package/README.md
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { SparqlEndpointFetcher } from 'fetch-sparql-endpoint';
|
|
2
|
+
export interface Options {
|
|
3
|
+
retries?: number;
|
|
4
|
+
query?: string;
|
|
5
|
+
fetcher?: SparqlEndpointFetcher;
|
|
6
|
+
}
|
|
7
|
+
export declare function waitForSparqlEndpointAvailable(url: string, options?: Options): Promise<void>;
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAG9D,MAAM,WAAW,OAAO;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,qBAAqB,CAAC;CACjC;AAED,wBAAsB,8BAA8B,CAClD,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,OAAO,iBAqBlB"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { SparqlEndpointFetcher } from 'fetch-sparql-endpoint';
|
|
2
|
+
import pRetry from 'p-retry';
|
|
3
|
+
export async function waitForSparqlEndpointAvailable(url, options) {
|
|
4
|
+
const query = options?.query ?? 'construct where { ?s ?p ?o } limit 1';
|
|
5
|
+
const fetcher = options?.fetcher ?? new SparqlEndpointFetcher();
|
|
6
|
+
await pRetry(async () => {
|
|
7
|
+
let results;
|
|
8
|
+
try {
|
|
9
|
+
results = await (await fetcher.fetchTriples(url, query)).toArray();
|
|
10
|
+
}
|
|
11
|
+
catch (e) {
|
|
12
|
+
throw new Error(`SPARQL endpoint at ${url} not available: ${e.message}`);
|
|
13
|
+
}
|
|
14
|
+
if (results.length === 0) {
|
|
15
|
+
throw new Error(`No data loaded (based on query ${query})`);
|
|
16
|
+
}
|
|
17
|
+
}, { retries: options?.retries ?? 5 });
|
|
18
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lde/wait-for-sparql",
|
|
3
|
+
"version": "0.0.3",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
"./package.json": "./package.json",
|
|
10
|
+
".": {
|
|
11
|
+
"development": "./src/index.ts",
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"default": "./dist/index.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist",
|
|
19
|
+
"!**/*.tsbuildinfo"
|
|
20
|
+
],
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"fetch-sparql-endpoint": "^6.0.0",
|
|
23
|
+
"p-retry": "^6.2.1",
|
|
24
|
+
"tslib": "^2.3.0"
|
|
25
|
+
}
|
|
26
|
+
}
|