Skip to content
This repository has been archived by the owner on May 14, 2020. It is now read-only.

Use namespace builder library #260

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

thewilkybarkid
Copy link
Contributor

@thewilkybarkid thewilkybarkid commented Feb 28, 2020

Adds @tpluscode/rdf-ns-builders, which adds extends the namespace builder with types for known properties. This will help avoid typos.

I'll leave this in draft until the library is a little more stable, and the @zazuko/rdf-vocabularies dependency is removed (as it's huge and not needed at runtime).

@thewilkybarkid thewilkybarkid added the 📦 Refactor A code change that neither fixes a bug nor adds a feature label Feb 28, 2020
Comment on lines +27 to +28
if (request.dataset.match(id, schema.name).size === 0) {
throw new createHttpError.BadRequest(`Article must have at least one ${termToString(schema.name)}`);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As name is now a defined property on the builder, TypeScript now correctly recognises it as a NamedNode.

PHPStorm seems a bit confused (though doesn't complain):
Screenshot 2020-02-28 at 10 53 33

@thewilkybarkid thewilkybarkid marked this pull request as ready for review March 2, 2020 08:38
@thewilkybarkid thewilkybarkid requested a review from a team as a code owner March 2, 2020 08:38
Comment on lines +49 to +52
hydra: hydra().value,
owl: owl().value,
rdf: rdf().value,
schema: schema().value,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tpluscode Maybe we could add a base or root function to get the base IRI as a string?

Copy link

@tpluscode tpluscode Mar 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about this, and I'm not sure. Do you find yourself often in need of the base URI as string?

It would have to have a unique name, like schema.__base. Unless I duplicated the prefixes export and generated a default export

import prefixes from '@tpluscode/rdf-ns-builders'

app.use(jsonld({
  ...prefixes
}))

And neither is great IMO

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you find yourself often in need of the base URI as string?

Only case I think, as this is outside RDF/JS.

You're right, neither of those is great...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opened zazuko/rdf-vocabularies#55 to try and use a library rather than hard-coding them here.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
📦 Refactor A code change that neither fixes a bug nor adds a feature
Projects
None yet
2 participants