Skip to content

Mismatch between type and object for ShEx value sets #120

Description

@smeckler

Hi Jackson,
thank you for creating this clever tool for RDF abstraction! I wanted to try it since I saw your presentation at the Solid Symposium.

Issue

I think I found a small bug when using ShEx value sets for enum-like constraints: The TS type/interface says { '@id': "enumname" } for the property but the belonging object property is a set.

  • @ldo/ldo: 1.0.0-alpha.32
  • @ldo/cli: 1.0.0-alpha.32

Example

myclass.shex

ex:MyClassShape {
  ex:state [ex:loading ex:success ex:error]
}

myclass.typings.ts

interface MyClass {
state:
    | {
        "@id": "loading";
      }
    | {
        "@id": "success";
      }
    | {
        "@id": "error";
      };

myclass.schema.ts

expressions: [
{
  type: "TripleConstraint",
  predicate: "http://ex.org/ontology#state",
  valueExpr: {
	type: "NodeConstraint",
	values: [
	  "http://ex.org/ontology#loading",
	  "http://ex.org/ontology#success",
	  "http://ex.org/ontology#error",
	],
  },
},

myclass.context.ts

state: {
"@id": "http://ex.org/ontology#state",
"@isCollection": true,
},

console.log(ldoObject.state) -> ObjectSetProxy
console.log(ldoObject.state?.['@id']) -> undefined

The IDE suggests ldoObject.state?.['@id'] (which is undefined) but the value is hidden here (ldoObject.state as any).toArray()[0]['@id'].

It is probably caused by the cardinality constraint of 1 or 0-1 (?). If I specify a cardinality of 0 or more (*), the typing as set LdSet is correct.

ex:MyClassShape {
  ex:state [ex:loading ex:success ex:error] *
}

Merry Christmas and a happy New Year!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions