Skip to content
This repository was archived by the owner on Jan 8, 2025. It is now read-only.

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

Open
Yucukof wants to merge 2 commits into
geistinme:masterfrom
Yucukof:feature/support-rdfs-langString
Open

feat: support rdf:LangString datatype (+test)#139
Yucukof wants to merge 2 commits into
geistinme:masterfrom
Yucukof:feature/support-rdfs-langString

Conversation

@Yucukof

@Yucukof Yucukof commented Jun 10, 2022

Copy link
Copy Markdown

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.

@geistinme geistinme left a comment

Copy link
Copy Markdown
Owner

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 👍

Comment thread src/visitors/typescript/generates.ts Outdated
@Yucukof
Yucukof requested a review from geistinme June 28, 2022 09:57
@Yucukof

Yucukof commented Jun 28, 2022

Copy link
Copy Markdown
Author

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

@geistinme geistinme left a comment

Copy link
Copy Markdown
Owner

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 subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants