From 10354f69e45e157755d75c7d88af34810fc7eb45 Mon Sep 17 00:00:00 2001 From: Tomasz Pluskiewicz Date: Wed, 3 Apr 2024 16:22:25 +0200 Subject: [PATCH] feat: allow no fs factory --- .changeset/ten-apricots-buy.md | 5 +++++ README.md | 2 +- lib/env.ts | 2 +- lib/fetchImport.ts | 4 ++++ 4 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 .changeset/ten-apricots-buy.md diff --git a/.changeset/ten-apricots-buy.md b/.changeset/ten-apricots-buy.md new file mode 100644 index 0000000..eef3828 --- /dev/null +++ b/.changeset/ten-apricots-buy.md @@ -0,0 +1,5 @@ +--- +"rdf-transform-graph-imports": patch +--- + +Make the `FsUtilsFactory` optional. An exception wil be thrown when an enviornment does not provide that factory and a filesystem import is loaded diff --git a/README.md b/README.md index 9a982a9..75432e3 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ This package provides a stream transform which replaces import statements with c ## Installation -Install the package itself and a RDF/JS environment which provides the factories [`NamespaceFactory`](https://github.com/rdfjs-base/namespace), [`FsUtilsFactory`](https://github.com/zazuko/rdf-utils-fs), and [`FetchFactory`](https://github.com/rdfjs-base/fetch-lite). If unsure, try [`@zazuko/env-node`](https://npm.im/@zazuko/env-node). +Install the package itself and an RDF/JS environment which provides the factories [`NamespaceFactory`](https://github.com/rdfjs-base/namespace), [`FetchFactory`](https://github.com/rdfjs-base/fetch-lite), and, optionally, [`FsUtilsFactory`](https://github.com/zazuko/rdf-utils-fs). If unsure, try [`@zazuko/env-node`](https://npm.im/@zazuko/env-node). ```bash npm install rdf-transform-graph-imports @zazuko/env-node diff --git a/lib/env.ts b/lib/env.ts index b93e29c..d6bd4f5 100644 --- a/lib/env.ts +++ b/lib/env.ts @@ -4,5 +4,5 @@ import type FsUtilsFactory from '@zazuko/rdf-utils-fs/Factory.js' import type { FetchFactory } from '@rdfjs/fetch-lite/Factory.js' import type ClownfaceFactory from 'clownface/Factory.js' -type Environment = RdfjsEnvironment +type Environment = RdfjsEnvironment | RdfjsEnvironment export default Environment diff --git a/lib/fetchImport.ts b/lib/fetchImport.ts index 0684086..e977573 100644 --- a/lib/fetchImport.ts +++ b/lib/fetchImport.ts @@ -3,6 +3,10 @@ import Environment from './env.js' export default async function (env: Environment, importTarget: string | URL) { if (typeof importTarget === 'string') { + if (!('fromFile' in env)) { + throw new Error('Importing from file is not supported') + } + return env.fromFile(importTarget, { implicitBaseIRI: true }) }