# Easy ways to convert TypeScript interfaces into RDF?

**URL:** <https://forum.solidproject.org/t/easy-ways-to-convert-typescript-interfaces-into-rdf/4544>\
**Category:** General Discussion\
**Created:** [July 30, 2021, 2:17pm UTC](https://forum.solidproject.org/t/easy-ways-to-convert-typescript-interfaces-into-rdf/4544 "2021-07-30T14:17:46Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ajp](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.solidproject.org/ajp/32/2867_2.png) [@ajp](https://forum.solidproject.org/u/ajp)\
**Post date:** [July 30, 2021, 2:17pm UTC](https://forum.solidproject.org/t/easy-ways-to-convert-typescript-interfaces-into-rdf/4544/1 "2021-07-30T14:17:46Z")

</div>

I’m completely new to Solid, and RDF. I have a TypeScript application that I’m looking to move into the cloud and was hoping to use Solid as the decentralised/decentralisable data store.

1. So far I have [read the tutorial](https://solidproject.org/developers/tutorials/getting-started), created the code, run it locally and successfully edited my user profile name.
2. I then moved to the [vocabularies quickstart tutorial](https://solidproject.org/developers/vocabularies/create/quickstart) and got a bit stuck as I tried to write my own RDF schema in Turtle (where [Turtle is a non-XML file format of RDF](https://stackoverflow.com/a/1813585/539490)).

my TypeScript application uses:

- interfaces that extend from other interfaces (inheritance / composition)
- enums as stand alone and as types of interface properties
- dictionaries as properties, that map from ids to other interfaces (classes)

Is there a tutorial out there that demonstrates:

a) using some more advanced schemas (and or work arounds for inheritance, enums, dictionaries)  
b) the code to read and write from this data? (I will try to recreate this application from [the tutorial](https://solidproject.org/developers/vocabularies/code/quickstart) locally as it errors for me in [codesandbox.io](https://codesandbox.io/s/lit-using-generated-artifact-8vfyf?from-embed).

Thank you

\*\* edit 2 \*\*

I have also been attempting to use the WebProtege tool link to from [RelatedTools](https://github.com/solid/solidproject.org/blob/main/_posts/developers/apps/tools/2019-01-01-00_overview.md#related-tools). I haven’t yet found the strong community / forum to enable and support learning or using that tool.

### Impressions so far

My initial impression is that this project & ecosystem has made significant progress towards being accessible and it’s just got perhaps 3 steps (+ another 1 which in my mind is optional) left 🔲 to being understandable (to me):

1. Solid Pod websites like [solidcommunity.net](http://solidcommunity.net) are present, functional and [actively improving](https://github.com/solid/community-server) 🧡
2. The [tutorials](https://solidproject.org/developers/tutorials/getting-started) are there and mostly work; the last steps of the vocabularies quickstart is currently broken but I’d imagine this is 30-90 minutes work for the person who built them to fix / update them 🔲
3. This forum is here! 😃
4. The manual writing of RDFs is described in the tutorials. More advanced schemas (work arounds / implementations for inheritance, enums, dictionaries) being referenced from the tutorial would be useful 🔲
5. Optionally a tutorial to demonstrate the use of a mature tool that supports more of the “advanced” elements of writing RDFs (🔲)

- webprotege seems good but can’t seem to add xsd namespace used in the tutorials, also can’t seem to export a RDF Turtle schema file
- webprotege does seem to support a reasonable search function to find existing properties to reuse

1. A tutorial that integrates the advanced schema, RDF composing tool (optional) and writes and reads from this data 🔲 covering aspects like:

- data consistency model → can we ensure data consistency, if so how, if not then what types of applications can be build
- data versioning
- what types of access functions are there: only simple get requests or are there services that give more powerful search, compound queries etc.

---

<div class="post-metadata">

**Author:** ![Vincent](https://avatars.discourse-cdn.com/v4/letter/v/e9bcb4/32.png) [@Vincent](https://forum.solidproject.org/u/Vincent)\
**Post date:** [August 2, 2021, 7:39am UTC](https://forum.solidproject.org/t/easy-ways-to-convert-typescript-interfaces-into-rdf/4544/2 "2021-08-02T07:39:07Z")

</div>

To answer the question in the title: no, TypeScript interfaces cannot be easily converted into RDF. There can’t really be an easy way to do that, since they don’t map cleanly: for example, number data in RDF is commonly defined in terms of integers and floats, whereas TypeScript just has the type `number`.

As for the vocab tutorial being broken: pinging @zwifi, who worked on those. Other than that I’m pretty unfamiliar with all the vocab- and Protégé-related stuff.

You do identify some current pain points: there is currently no tooling for data consistency, although that’s something the [Data Interoperability Panel](https://github.com/solid/data-interoperability-panel/) is working on (@justin will probably be able to speak more to that).

There’s no tooling currently available for data versioning. It’s a hard problem to solve, so hopefully people will start experimenting in that direction at some point.

In terms of access: it is indeed all GET requests. There’s academic research into advanced querying mechanisms, but nothing that would be widely available across most Solid servers any time soon.

---

<div class="post-metadata">

**Author:** ![ajp](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.solidproject.org/ajp/32/2867_2.png) [@ajp](https://forum.solidproject.org/u/ajp)\
**Post date:** [August 2, 2021, 10:22am UTC](https://forum.solidproject.org/t/easy-ways-to-convert-typescript-interfaces-into-rdf/4544/3 "2021-08-02T10:22:40Z")

</div>

Thank you so much @Vincent that is incredibly helpful information. Thank you (and the ping-ees) for the pings!

**Vocabulary tutorial _is fixed_**  
I have now fixed the vocabulary quick start tutorial, [repo here](https://github.com/centerofci/solid_demo/blob/main/vocabularies_part1_quickstart/index.js). It was primarily stubbing out the `lit-vocab-term` which is not available yet and “upgrading” IRIs from solid.community to [solidcommunity.net](http://solidcommunity.net) . I also added a bit of UI to make it easier to use / understand.

**JavaScript numbers**  
I will also try my best at exploring the limits of Solid + RDF and the typescript interfaces I want to support. For number I think I will first try with just using `float` as that is how (I think) the number is represented in javascript anyway. (Though [this RFC](https://datatracker.ietf.org/doc/html/rfc7159) suggests it’s a double, and this [StackOverflow Q&A](https://stackoverflow.com/a/55291279/539490) suggests it’s “nearest double”).

**Data consistency & versioning**  
Ok I understand, thank you for the link, I’ll aim to join one of their meetings. My application is a prototype at the moment and I was hoping to just do it all client side without having a server side that could accept data and forward data. If anyone knows of any other application users of Solid that have built server-side abstractions to cope with data consistency / data versioning then any pointers would be very welcome, I don’t want to reinvent it 🙂

**Querying**  
The prototype currently pulls everything it needs into client side so that’s not a problem. I guessed search over distributed data would be a very hard nut to start cracking.

---

<div class="post-metadata">

**Author:** ![ajp](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.solidproject.org/ajp/32/2867_2.png) [@ajp](https://forum.solidproject.org/u/ajp)\
**Post date:** [August 2, 2021, 4:01pm UTC](https://forum.solidproject.org/t/easy-ways-to-convert-typescript-interfaces-into-rdf/4544/4 "2021-08-02T16:01:03Z")

</div>

Ahh! There’s a part 2 tutorial on [docs.inrupt.com](https://docs.inrupt.com/developer-tools/javascript/client-libraries/tutorial/getting-started-part2/) (found link from [this Q&A](https://forum.solidproject.org/t/savedatasetas-not-working-on-inrupt-dot-com-but-works-on-inrupt-dot-net/4509)).

I guess the difference between [inrupt.com](http://inrupt.com) and [solidproject.org](http://solidproject.org) is the first is the commercial expression of the second which is the open source / community content? (I’m slightly less confused now! 🙂)

---

<div class="post-metadata">

**Author:** ![jeffz](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.solidproject.org/jeffz/32/600_2.png) [@jeffz](https://forum.solidproject.org/u/jeffz)\
**Post date:** [August 2, 2021, 5:16pm UTC](https://forum.solidproject.org/t/easy-ways-to-convert-typescript-interfaces-into-rdf/4544/5 "2021-08-02T17:16:30Z")

</div>

Yes, you’ve pretty much got it. The [solidproject.org](http://solidproject.org) website, this forum, the gitter chatrooms, the [solidcommunity.net](http://solidcommunity.net) pod and identity provider, the github solid/\* repos, the Solid World events, are part of Solid as an open source project. Inrupt is a private company using and promoting Solid that also provides separately a proprietary ([inrupt.com](http://inrupt.com)) and open source ([inrupt.net](http://inrupt.net)) pod and identity services, tutorials, and other useful things. They and other companies like Janiero provide some small funding and a lot of personal time to the open source project and are prominent in the facilitation of the project but are neither synonymous with, nor responsible for the open source project.

Most things like the tutorials benefit both Inrupt and the open source Solid project. Sometimes the same person writes for both. But at the end of the day, Inrupt is a company and [solidproject.org](http://solidproject.org) is an open source community project and both want Solid to succeed.

---

<div class="post-metadata">

**Author:** ![josephguillaume](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.solidproject.org/josephguillaume/32/1072_2.png) [@josephguillaume](https://forum.solidproject.org/u/josephguillaume)\
**Post date:** [August 7, 2021, 1:59pm UTC](https://forum.solidproject.org/t/easy-ways-to-convert-typescript-interfaces-into-rdf/4544/6 "2021-08-07T13:59:52Z")

</div>

> [@Vincent](#):
>
> To answer the question in the title: no, TypeScript interfaces cannot be easily converted into RDF. There can’t really be an easy way to do that, since they don’t map cleanly: for example, number data in RDF is commonly defined in terms of integers and floats, whereas TypeScript just has the type `number`

Just to emphasise that mapping to vocabularies and shapes is tricky too.

It might be of interest to see how typescript interfaces generated from a shex shape deal with this, e.g. in a previous post: [Using shape expressions to become interoperable just got a whole lot easier](https://forum.solidproject.org/t/using-shape-expressions-to-become-interoperable-just-got-a-whole-lot-easier/4223)

---

<div class="post-metadata">

**Author:** ![NoelDeMartin](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.solidproject.org/noeldemartin/32/3144_2.png) [@NoelDeMartin](https://forum.solidproject.org/u/NoelDeMartin)\
**Post date:** [August 8, 2021, 6:45am UTC](https://forum.solidproject.org/t/easy-ways-to-convert-typescript-interfaces-into-rdf/4544/7 "2021-08-08T06:45:34Z")

</div>

Since you’re getting started with Solid, and you’re asking about TypeScript, maybe you’d like to check out my [soukai-solid](https://github.com/noeldemartin/soukai-solid) library. It is not exactly what you are asking for, it’s an ActiveRecord implementation for Solid. But maybe you find it interesting, even if you don’t use it.

In the development branch (`next`), I have improved the inference as well, so if you just want to play around with it, I’d recommend using that one (you can install it with `npm install soukai@next soukai-solid@next`).

About models inheritance and interfaces, I haven’t done a lot of that myself because it hasn’t been necessary, but technically it should be possible by just extending the classes. If there is something that isn’t working as you’d expect, feel free to open an issue (I’d appreciate it :D).

TLDR would be:

```auto
class Person extends SolidModel {

    static rdfContexts = {
        'foaf': 'http://xmlns.com/foaf/0.1/',
    };

    static rdfsClasses = ['foaf:Person'];

    static fields = {
        name: {
            type: FieldType.String,
            rdfProperty: 'foaf:name',
        },
    };

}

SoukaiSolid.loadSolidModels();
Soukai.loadModels({ Person });

// If you want to make authenticated requests, you should use the fetch method from an authentication library.
Soukai.useEngine(new SolidEngine(window.fetch.bind(window)));

const person = Person.at('https://example.org/people/').create({ name: 'John Doe' });

// Here, you can use person.name and it'll be inferred as a "string", you can also define other types of fields: Numbers, Arrays, Dates, etc.

```
