Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/solid/Email.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { TermWrapper, ValueMappings, TermMappings } from 'rdfjs-wrapper';
import { VCARD, RDF } from '../vocabulary/mod.js';

export class Email extends TermWrapper {
get emailAddress(): string {
return this.singular(VCARD.value, ValueMappings.literalToString);
}

set emailAddress(value: string) {
this.overwrite(VCARD.value, value, TermMappings.stringToLiteral);
}

get emailType(): string | undefined {
return this.singularNullable(RDF.type, ValueMappings.iriToString);
}

set emailType(value: string | undefined) {
this.overwriteNullable(RDF.type, value, TermMappings.stringToIri);
}
}
15 changes: 15 additions & 0 deletions src/solid/EmailDataset.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { DatasetWrapper } from 'rdfjs-wrapper';
import { VCARD } from '../vocabulary/mod.js';
import { Email } from './Email.js';

export class EmailDataset extends DatasetWrapper {
get emails(): Iterable<Email> {
const objects = new Set([
...this.instancesOf(VCARD.Email, Email),
...this.objectsOf(VCARD.hasEmail, Email),
...this.objectsOf(VCARD.email, Email),
Comment on lines +9 to +10
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know anything about how this vocabulary is used in the Solid community it's history there or best practices that migh be in use, but I see a potential problem with this shape in the context of the vCard Ontology.

vcard:email is a datatype property while vcard:hasEmail is an object property.
vcard:email will have a literal object or a blank node with a vcard:value property, itself a literal.
vcard:hasEmail will have a resource object or a blank node with a vcard:hasValue property, itself a resouce.

In this code, both of these are handled using the Email mapping class. Thst's not a problem, but then that class should be smarter.

In any case, I don't think we are doing justice to the versatility of vCard. In my understanding, all of the following are valid shapes:

[ :hasEmail <mailto:user@example.com> ] .
[ :hasEmail [ :hasValue <mailto:user@example.com> ] ] .
[ :email "mailto:user@example.com" ] .
[ :email [ :value "mailto:user@example.com" ] ] .

It is entirely possible to map any usage scenario to JavaScript classes using a combination of mapping properties and other logic. Here I'm just highlighting what seem like discrepancies. Happy to help with proposed programming constructs once there is clarity on what the shape we're mapping is.

If I'm calling out things that are irrelevant or have already been clarified then sorry.

Copy link
Member

Choose a reason for hiding this comment

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

The Email shape that @hkir-dev has based this on is
https://github.com/solid/shape-generation-artefacts/tree/main/shapes/Email which itself originates in a SolidOS repo file, specifically:

https://github.com/SolidOS/contacts-pane/blob/main/src/ontology/forms.ttl

    a ui:Group ; # hint: side by side is good
    ui:part :emailValue, :emailType ;
    ui:parts ( :emailType  :emailValue ).

:emailValue
    a ui:EmailField ; ui:label "email";
    ui:property vcard:value ;
    ui:size "50" .

:emailType
    a ui:Classifier ;
    ui:canMintNew "0" ;
    ui:category vcard:Type ;
    ui:from vcard:Type ;
    ui:property rdf:type . 

The idea of the Solid shape repo is to contain shapes that are in use in Solid projects. The present shapes in the shape artefacts repo originate from SolidOS GitHub repos.

  • Question arises - should the shapes stay the same as those found in current SolidOS projects, when improvements are identified?

I've noted a potential improvement in the Email shape, with use of vcard:hasType instead of rdf:type.

It has been noted by @timea-solid that a lot of change is underway in the existing original SolidOS ontology files - solid/shape-generation-artefacts#8. This may influence the idea of shapes hosted in a Solid shape repo being based on those used in current SolidOS repos?

Maybe we can review this with @jeswr?

Copy link
Member

Choose a reason for hiding this comment

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

Starting shapes based on SolidOS is a good way because it is where we are actually using them. And this is not 100% true. The shapes in SolidOS are actually RDF forms, which guide our interfaces, which just means that they are not written in SHACL or SHeX but using ui ontology.

Now, this being said, I am reworking the RDF forms in SolidOS because we are refactoring the UI. And I have noticed that the RDF forms in SolidOS are not all ontologically 100% correct. So, take them as guidance but improve them in the final shapes you create.

At some point, we will need to improve SolidOS and migrate data if need be, to adhere to correct ontologies. My work at the moment contains:

  • renaming of labels,
  • rearranging of ui components,
  • cleaning duplicates and overlaps,
  • and making sure the RDF form is in the pane where it is used.

I am not changing any definition of any element since I am not an ontology expert.

Copy link
Author

Choose a reason for hiding this comment

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

@langsamu in this version of the VCard vocabulary (https://www.w3.org/2006/vcard/ns), both email and hasEmail are defined as object properties, and #email is declared as owl:equivalentProperty to #hasEmail. I’m unsure whether the object implementation should explicitly support both properties or rely on a reasoner to resolve the equivalence and handle only #hasEmail; however, for convenience, I added support for both.

])

return objects
}
}
20 changes: 20 additions & 0 deletions src/solid/Telephone.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { TermWrapper, ValueMappings, TermMappings } from 'rdfjs-wrapper';
import { VCARD } from '../vocabulary/mod.js';

export class Telephone extends TermWrapper {
get phoneNumber(): string {
return this.singular(VCARD.hasValue, ValueMappings.literalToString);
}

set phoneNumber(value: string) {
this.overwrite(VCARD.hasValue, value, TermMappings.stringToLiteral);
}

get phoneType(): string | undefined {
return this.singularNullable(VCARD.telephoneType, ValueMappings.iriToString);
}

set phoneType(value: string | undefined) {
this.overwriteNullable(VCARD.telephoneType, value, TermMappings.stringToIri);
}
}
14 changes: 14 additions & 0 deletions src/solid/TelephoneDataset.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { DatasetWrapper } from 'rdfjs-wrapper';
import { VCARD } from '../vocabulary/vcard.js';
import { Telephone } from './Telephone.js';

export class TelephoneDataset extends DatasetWrapper {
get telephones(): Iterable<Telephone> {
const objects = new Set([
...this.objectsOf(VCARD.hasTelephone, Telephone),
...this.objectsOf(VCARD.tel, Telephone),
])

return objects
}
}
4 changes: 4 additions & 0 deletions src/solid/mod.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
export * from "./Container.js"
export * from "./ContainerDataset.js"
export * from "./Resource.js"
export * from "./Email.js";
export * from "./EmailDataset.js";
export * from "./Telephone.js";
export * from "./TelephoneDataset.js";
25 changes: 15 additions & 10 deletions src/vocabulary/vcard.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@

export const VCARD = {
fn: "http://www.w3.org/2006/vcard/ns#fn",
hasEmail: "http://www.w3.org/2006/vcard/ns#hasEmail",
hasValue: "http://www.w3.org/2006/vcard/ns#hasValue",
hasPhoto: "http://www.w3.org/2006/vcard/ns#hasPhoto",
hasTelephone: "http://www.w3.org/2006/vcard/ns#hasTelephone",
title: "http://www.w3.org/2006/vcard/ns#title",
hasUrl: "http://www.w3.org/2006/vcard/ns#hasUrl",
organizationName: "http://www.w3.org/2006/vcard/ns#organization-name",
role: "http://www.w3.org/2006/vcard/ns#organization-name",
fn: "http://www.w3.org/2006/vcard/ns#fn",
Email: "http://www.w3.org/2006/vcard/ns#Email",
email: "http://www.w3.org/2006/vcard/ns#email",
hasEmail: "http://www.w3.org/2006/vcard/ns#hasEmail",
hasValue: "http://www.w3.org/2006/vcard/ns#hasValue",
hasPhoto: "http://www.w3.org/2006/vcard/ns#hasPhoto",
tel: "http://www.w3.org/2006/vcard/ns#tel",
hasTelephone: "http://www.w3.org/2006/vcard/ns#hasTelephone",
title: "http://www.w3.org/2006/vcard/ns#title",
hasUrl: "http://www.w3.org/2006/vcard/ns#hasUrl",
organizationName: "http://www.w3.org/2006/vcard/ns#organization-name",
phone: "http://www.w3.org/2006/vcard/ns#phone",
role: "http://www.w3.org/2006/vcard/ns#role",
value: "http://www.w3.org/2006/vcard/ns#value",
telephoneType: "http://www.w3.org/2006/vcard/ns#TelephoneType",
} as const;
85 changes: 85 additions & 0 deletions test/unit/email.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { DataFactory, Parser, Store } from "n3"
import assert from "node:assert"
import { describe, it } from "node:test"

import { Email } from "@solid/object";

describe("Email tests", () => {

const sampleRDF = `
@prefix vcard: <http://www.w3.org/2006/vcard/ns#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .

<https://example.org/person/1>
a vcard:Individual ;
vcard:fn "Alice" ;
vcard:hasEmail <https://example.org/email/1> .

<https://example.org/email/1>
a vcard:Email ;
vcard:value "alice@example.org" ;
rdf:type vcard:Work .
`;

it("should parse and retrieve email address", () => {
const store = new Store()
store.addQuads(new Parser().parse(sampleRDF))

const email = new Email(
DataFactory.namedNode("https://example.org/email/1"),
store,
DataFactory
)

assert.equal(email.emailAddress, "alice@example.org")
assert.equal(typeof email.emailAddress, "string")
})

it("should allow setting email address", () => {
const store = new Store()
store.addQuads(new Parser().parse(sampleRDF))

const email = new Email(
DataFactory.namedNode("https://example.org/email/1"),
store,
DataFactory
)

email.emailAddress = "bob@example.org"

assert.equal(email.emailAddress, "bob@example.org")
})

it("should parse and retrieve email type", () => {
const store = new Store()
store.addQuads(new Parser().parse(sampleRDF))

const email = new Email(
DataFactory.namedNode("https://example.org/email/1"),
store,
DataFactory
)

const emailType = DataFactory.namedNode("http://www.w3.org/2006/vcard/ns#Home")

assert.ok(emailType !== undefined)
assert.equal(typeof emailType, "object")
assert.equal(emailType.value, "http://www.w3.org/2006/vcard/ns#Home")
})

it("should allow setting email type", () => {
const store = new Store()

const email = new Email(
DataFactory.namedNode("https://example.org/email/2"),
store,
DataFactory
)

email.emailAddress = "test@example.org"
email.emailType = "http://www.w3.org/2006/vcard/ns#Home"

assert.equal(email.emailType, "http://www.w3.org/2006/vcard/ns#Home")
})

})
105 changes: 105 additions & 0 deletions test/unit/telephone.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import { DataFactory, Parser, Store } from "n3"
import assert from "node:assert"
import { describe, it } from "node:test"

import { Telephone } from "@solid/object";

describe("Telephone tests", () => {

const sampleRDF = `
@prefix vcard: <http://www.w3.org/2006/vcard/ns#> .

<https://example.org/person/1>
a vcard:Individual ;
vcard:fn "Alice" ;
vcard:hasTelephone <https://example.org/phone/1> .

<https://example.org/phone/1>
a vcard:Telephone ;
vcard:hasValue "+1234567890" ;
vcard:TelephoneType vcard:Cell .
`;

it("should parse and retrieve phone number", () => {
const store = new Store()
store.addQuads(new Parser().parse(sampleRDF))

const telephone = new Telephone(
DataFactory.namedNode("https://example.org/phone/1"),
store,
DataFactory
)

assert.equal(telephone.phoneNumber, "+1234567890")
assert.equal(typeof telephone.phoneNumber, "string")
})

it("should allow setting phone number", () => {
const store = new Store()
store.addQuads(new Parser().parse(sampleRDF))

const telephone = new Telephone(
DataFactory.namedNode("https://example.org/phone/1"),
store,
DataFactory
)

telephone.phoneNumber = "+0987654321"

assert.equal(telephone.phoneNumber, "+0987654321")
})

it("should parse and retrieve phone type", () => {
const store = new Store()
store.addQuads(new Parser().parse(sampleRDF))

const telephone = new Telephone(
DataFactory.namedNode("https://example.org/phone/1"),
store,
DataFactory
)

const phoneType = telephone.phoneType

assert.ok(phoneType !== undefined)
assert.equal(typeof phoneType, "string")
assert.equal(phoneType, "http://www.w3.org/2006/vcard/ns#Cell")
})

it("should allow setting phone type", () => {
const store = new Store()

const telephone = new Telephone(
DataFactory.namedNode("https://example.org/phone/2"),
store,
DataFactory
)

telephone.phoneNumber = "+1112223333"
telephone.phoneType = "http://www.w3.org/2006/vcard/ns#Car"

assert.equal(telephone.phoneType, "http://www.w3.org/2006/vcard/ns#Car")
})

it("should throw when phone number is missing", () => {
const noPhoneRDF = `
@prefix vcard: <http://www.w3.org/2006/vcard/ns#> .

<https://example.org/phone/empty>
a vcard:Telephone .
`
const store = new Store()
store.addQuads(new Parser().parse(noPhoneRDF))

const telephone = new Telephone(
DataFactory.namedNode("https://example.org/phone/empty"),
store,
DataFactory
)

assert.throws(() => {
telephone.phoneNumber
})
})

})