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

feat: support rdf:LangString datatype (+test) #139

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

Conversation

Yucukof
Copy link

@Yucukof Yucukof commented Jun 10, 2022

As of current, datatype rdf:langString is not supported.

If we try to convert the following shex

<#AccessNeedDescriptionShape> {
  a [ interop:AccessNeedDescription ] ;
  interop:inAccessDescriptionSet  IRI  // shex:reference <#AccessDescriptionSetShape> ;
  interop:hasAccessNeed           IRI  // shex:reference <#AccessNeedShape> ;
  skos:prefLabel                  rdf:langString // <- Unknown datatype
}

Then the code generation fails because it applies the type as a raw string.

SyntaxError: ';' expected. (204:18)
      202 | export type ResourceShape = {
      203 | id: string; // the url of a node of this shape
    > 204 | description: http://www.w3.org/2000/01/rdf-schema#langString;
          |                  ^
      205 | size: number; // Size of Container
      206 | mtime: number; // Time of Container creation created
      207 | modified: Date; // Time the Container was modified

      185 |     // prettier formatting
      186 |     const prettierConfig = await prettier.resolveConfig(process.cwd());
    > 187 |     const formatted = prettier.format(content, {
          |                                ^
      188 |       ...prettierConfig,
      189 |       filepath: generates,
      190 |     });

      at e (node_modules/prettier/parser-typescript.js:1:411)
      at Object.parse (node_modules/prettier/parser-typescript.js:1:3072809)
      at Object.parse (node_modules/prettier/index.js:13625:19)
      at coreFormat (node_modules/prettier/index.js:14899:14)
      at format (node_modules/prettier/index.js:15131:14)
      at node_modules/prettier/index.js:57542:12
      at Object.format (node_modules/prettier/index.js:57562:12)
      at src/generate.ts:187:32
      at fulfilled (lib/generate.js:13:24)

The following code change fixes the issue without breaking the test.

Copy link
Owner

@ludwigschub ludwigschub left a comment

Choose a reason for hiding this comment

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

Other than that its good 👍

src/visitors/typescript/generates.ts Outdated Show resolved Hide resolved
@Yucukof Yucukof requested a review from ludwigschub June 28, 2022 09:57
@Yucukof
Copy link
Author

Yucukof commented Jun 28, 2022

Sorry, this took me way more time than it should have...

Copy link
Owner

@ludwigschub ludwigschub left a comment

Choose a reason for hiding this comment

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

@Yucukof
I also thought about it a bit more and I am still questioning whether this is the right code to be generated. This also goes into #140 and eventually we'll need to implement the creation params in shex-methods.
Instead of:

} else if (valueExpr?.datatype === ns.rdf('langString')) {
    return toCreate ? 'string | Literal' : 'string';
...

We should force developers to supply the language with the string when they create shapes and similarly we should return the full literal node that includes the language when reading shapes; so more fitting would be:

} else if (valueExpr?.datatype === ns.rdf('langString')) {
    return 'Literal';

Sorry that I am only bringing this up now, but I didn't have much time to maintain this lib atm. I will make these changes to this PR and #140. Thank you for pointing this out 👍

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

Successfully merging this pull request may close these issues.

None yet

2 participants