Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Environment #13

Open
tpluscode opened this issue Mar 16, 2023 · 1 comment
Open

Use Environment #13

tpluscode opened this issue Mar 16, 2023 · 1 comment

Comments

@tpluscode
Copy link
Contributor

Now that RDF/JS Environment types have been published, would you agree to changing the interface of the generated code to actually take an environment instance parameter?

+import { Environment } from '@rdfjs/environment/Environment.js'
+import { DataFactory } from '@rdfjs/types'
+
-export default ({ factory }: { factory: import('rdf-js').DataFactory }) => {
+export default (factory: Environment<DataFactory>) => {
  return [
    factory.quad(
      factory.blankNode('foo'),
      factory.namedNode('http://example.com/bar'),
      factory.literal('baz')
    )
  ]
}

Typed like this in TS it would require that the factory is any instance of an environment which includes a DataFactory. And incidentally, that would continue to work with rdf-ext v1 using the interface we generated in version 0.0.1 of the serializer

@tpluscode
Copy link
Contributor Author

As a general question, is this how you envision the use of RDF/JS Environment? Any code which requires an environment might take is as parameter.

The types add the ability for consumer to require certain factories to be included. For example, Environment<ScoreFactory | DatasetFactory> would check that the environment has been constructed at least using these two factories. rdf-ext would satisfy that type but a custom environment would be fine, and types enforce its interface

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant