-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from zazuko/remote-improvements
fix: handle fetch fails
- Loading branch information
Showing
9 changed files
with
73 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"rdf-transform-graph-imports": patch | ||
--- | ||
|
||
Failures to fetch remote import would break the stream |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,15 @@ | ||
import { Readable, PassThrough } from 'readable-stream' | ||
import { Readable } from 'readable-stream' | ||
import Environment from './env.js' | ||
|
||
export default function (env: Environment, importTarget: string | URL) { | ||
export default async function (env: Environment, importTarget: string | URL) { | ||
if (typeof importTarget === 'string') { | ||
return env.fromFile(importTarget) | ||
} | ||
|
||
const remoteStream = new PassThrough({ objectMode: true }) | ||
|
||
env.fetch(importTarget.toString()) | ||
.then(response => { | ||
return response.quadStream() as unknown as Promise<Readable> | ||
}) | ||
.then(quadStream => { | ||
quadStream.pipe(remoteStream) | ||
}) | ||
.catch(error => { | ||
remoteStream.emit('error', error) | ||
}) | ||
const response = await env.fetch(importTarget.toString()) | ||
if (!response.ok) { | ||
throw new Error(`Failed to fetch: ${response.statusText}`) | ||
} | ||
|
||
return remoteStream | ||
return response.quadStream() as unknown as Promise<Readable> | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
const chai = require('chai') | ||
const chaiAsPromised = require('chai-as-promised') | ||
|
||
chai.use(chaiAsPromised); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
PREFIX code: <https://code.described.at/> | ||
PREFIX schema: <http://schema.org/> | ||
PREFIX sh: <http://www.w3.org/ns/shacl#> | ||
|
||
[ | ||
code:imports <foobar> ; | ||
] . |