Skip to content

Commit 699fdd5

Browse files
authored
Merge pull request #70 from solid-contrib/contacts/read-group
Contacts/read group
2 parents 76de39e + 71ce897 commit 699fdd5

9 files changed

Lines changed: 457 additions & 3 deletions

File tree

contacts/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
99
### Added
1010

1111
- [createNewGroup](https://solid-contrib.github.io/data-modules/contacts-rdflib-api/interfaces/ContactsModule.html#createNewGroup)
12+
- [readGroup](https://solid-contrib.github.io/data-modules/contacts-rdflib-api/interfaces/ContactsModule.html#readGroup)
1213

1314
## 0.2.1
1415

contacts/examples/read-group.mjs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import {ContactsModuleRdfLib as ContactsModule} from '../dist/index.js';
2+
import {Fetcher, graph, UpdateManager} from "rdflib";
3+
4+
const store = graph()
5+
const fetcher = new Fetcher(store)
6+
const updater = new UpdateManager(store)
7+
const contacts = new ContactsModule({store, fetcher, updater})
8+
9+
const result = await contacts.readGroup("http://localhost:3000/alice/public-contacts/Group/officials.ttl#this")
10+
console.log(result)

contacts/src/e2e-tests/contacts.e2e.spec.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,28 @@ describe("contacts module", () => {
119119
name: groupName,
120120
});
121121
});
122+
123+
it("can read a group to get the name and a list all of its members", async () => {
124+
{
125+
const contacts = setupModule();
126+
127+
const groupUri =
128+
"http://localhost:3456/4243dbb6-3126-4bf9-9ea7-45e35c3c8d9d/Group/1f0d98b1-5eac-4c44-b6e2-29d9784c40cb/index.ttl#this";
129+
130+
const result = await contacts.readGroup(groupUri);
131+
132+
expect(result).toEqual({
133+
uri: "http://localhost:3456/4243dbb6-3126-4bf9-9ea7-45e35c3c8d9d/Group/1f0d98b1-5eac-4c44-b6e2-29d9784c40cb/index.ttl#this",
134+
name: "Officials",
135+
members: [
136+
{
137+
uri: "http://localhost:3456/4243dbb6-3126-4bf9-9ea7-45e35c3c8d9d/Person/1973dcec-e71c-476c-87db-0d3332291214/index.ttl#this",
138+
name: "Molly Braaten",
139+
},
140+
],
141+
});
142+
}
143+
});
122144
});
123145

124146
function setupModule() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<#this>
2+
<http://www.w3.org/2006/vcard/ns#fn> "Officials" ;
3+
a <http://www.w3.org/2006/vcard/ns#Group> ;
4+
<http://www.w3.org/2006/vcard/ns#hasMember> <../../Person/1973dcec-e71c-476c-87db-0d3332291214/index.ttl#this> ;
5+
.
6+
7+
<../../Person/1973dcec-e71c-476c-87db-0d3332291214/index.ttl#this>
8+
<http://www.w3.org/2006/vcard/ns#fn> "Molly Braaten" .

contacts/src/index.ts

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export interface ContactsModule {
3131
/**
3232
* Fetches the given contact and returns available information
3333
* @param uri - The URI of the contact to read
34-
* @return Contact name, email addresses and phone numbers
34+
* @return FullContact name, email addresses and phone numbers
3535
*/
3636
readContact(uri: string): Promise<FullContact>;
3737

@@ -44,6 +44,13 @@ export interface ContactsModule {
4444
addressBookUri,
4545
groupName,
4646
}: CreateNewGroupCommand): Promise<string>;
47+
48+
/**
49+
* Fetches the given group and returns available information
50+
* @param uri - The URI of the contact to read
51+
* @return FullGroup name and list of group members
52+
*/
53+
readGroup(uri: string): Promise<FullGroup>;
4754
}
4855

4956
/**
@@ -94,10 +101,16 @@ export interface AddressBook {
94101
}
95102

96103
/**
97-
* Partial contact data listed when reading an address book
104+
* Partial contact data listed when reading an address book or a group
98105
*/
99106
export interface Contact {
107+
/**
108+
* The URI identifying the contact
109+
*/
100110
uri: string;
111+
/**
112+
* The human-readable name of the contact
113+
*/
101114
name: string;
102115
}
103116

@@ -130,7 +143,34 @@ export interface PhoneNumber {
130143
/**
131144
* Partial group data listed when reading an address book
132145
*/
133-
export interface Group {}
146+
export interface Group {
147+
/**
148+
* The URI identifying the group
149+
*/
150+
uri: string;
151+
/**
152+
* The human-readable name of the group
153+
*/
154+
name: string;
155+
}
156+
157+
/**
158+
* Extensive contact data returned when reading a contact
159+
*/
160+
export interface FullGroup {
161+
/**
162+
* The URI identifying the group
163+
*/
164+
uri: string;
165+
/**
166+
* The human-readable name of the group
167+
*/
168+
name: string;
169+
/**
170+
* List of group members
171+
*/
172+
members: Contact[];
173+
}
134174

135175
/**
136176
* Data needed to create a new group within an address book

contacts/src/rdflib/ContactsModuleRdfLib.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ import {
66
CreateNewContactCommand,
77
CreateNewGroupCommand,
88
FullContact,
9+
FullGroup,
910
} from "..";
1011
import { AddressBookQuery, ContactQuery } from "./queries";
1112
import { createAddressBook, createNewContact } from "./update-operations";
1213
import { executeUpdate } from "./web-operations/executeUpdate";
1314
import { fetchNode } from "./web-operations/fetchNode";
1415
import { createNewGroup } from "./update-operations/createNewGroup";
16+
import { GroupQuery } from "./queries/GroupQuery";
1517

1618
interface ModuleConfig {
1719
store: IndexedFormula;
@@ -99,4 +101,17 @@ export class ContactsModuleRdfLib implements ContactsModule {
99101
await executeUpdate(this.fetcher, this.updater, operation);
100102
return operation.uri;
101103
}
104+
105+
async readGroup(uri: string): Promise<FullGroup> {
106+
const groupNode = sym(uri);
107+
await this.fetchNode(groupNode);
108+
const query = new GroupQuery(this.store, groupNode);
109+
const name = query.queryName();
110+
const members = query.queryMembers();
111+
return {
112+
uri,
113+
name,
114+
members,
115+
};
116+
}
102117
}

0 commit comments

Comments
 (0)