Skip to content

Commit

Permalink
Fix #1311
Browse files Browse the repository at this point in the history
  • Loading branch information
srosset81 committed Sep 20, 2024
1 parent e371db4 commit 0e93018
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 23 deletions.
12 changes: 8 additions & 4 deletions src/middleware/tests/interop/mirror.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const urlJoin = require('url-join');
const waitForExpect = require('wait-for-expect');
const { triple, namedNode } = require('@rdfjs/data-model');
const { MIME_TYPES } = require('@semapps/mime-types');
const initialize = require('./initialize');

Expand Down Expand Up @@ -101,10 +102,13 @@ describe('Server2 mirror server1', () => {
test('Resource on server1 is patched on server2 container', async () => {
await server2.call('ldp.container.patch', {
containerUri: 'http://localhost:3002/resources',
sparqlUpdate: `
PREFIX ldp: <http://www.w3.org/ns/ldp#>
INSERT DATA { <http://localhost:3002/resources> ldp:contains <${resourceUri}>. };
`
triplesToAdd: [
triple(
namedNode('http://localhost:3002/resources'),
namedNode('http://www.w3.org/ns/ldp#contains'),
namedNode(resourceUri)
)
]
});

await waitForExpect(async () => {
Expand Down
13 changes: 8 additions & 5 deletions src/middleware/tests/interop/patch-remote.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const urlJoin = require('url-join');
const waitForExpect = require('wait-for-expect');
const { triple, namedNode } = require('@rdfjs/data-model');
const { MIME_TYPES } = require('@semapps/mime-types');
const initialize = require('./initialize');

Expand Down Expand Up @@ -43,10 +43,13 @@ describe('Server2 imports a single resource from server1', () => {
test('Resource is imported on server2', async () => {
await server2.call('ldp.container.patch', {
containerUri: 'http://localhost:3002/resources',
sparqlUpdate: `
PREFIX ldp: <http://www.w3.org/ns/ldp#>
INSERT DATA { <http://localhost:3002/resources> ldp:contains <${resourceUri}>. };
`
triplesToAdd: [
triple(
namedNode('http://localhost:3002/resources'),
namedNode('http://www.w3.org/ns/ldp#contains'),
namedNode(resourceUri)
)
]
});

await waitForExpect(async () => {
Expand Down
1 change: 1 addition & 0 deletions src/middleware/tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"author": "SemApps Team",
"license": "Apache-2.0",
"dependencies": {
"@rdfjs/data-model": "^1.3.4",
"@semapps/activitypub": "0.9.5",
"@semapps/auth": "0.9.5",
"@semapps/core": "0.9.5",
Expand Down
37 changes: 23 additions & 14 deletions website/docs/middleware/ldp/container.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,22 +159,31 @@ Array of URIs

##### Parameters

| Property | Type | Default | Description |
| -------------- | -------- | ------------------- | ------------------------------------------------------------------------------- |
| `containerUri` | `String` | **required** | URI of container to which the resource will be attached or detached |
| `sparqlUpdate` | `String` | **required** | SPARQL UPDATE string with INSERT DATA and/or DELETE DATA statements (see below) |
| `webId` | `string` | Logged user's webId | User doing the action |

The format of the `update` string is as follow:

```
PREFIX ldp: <http://www.w3.org/ns/ldp#>
INSERT DATA { <http://url/of/container> ldp:contains <http://url/of/resource/to/attach>. };
DELETE DATA { <http://url/of/container> ldp:contains <http://url/of/resource/to/detach>. };
| Property | Type | Default | Description |
| ----------------- | -------- | ------------------- | ------------------------------------------------------------------- |
| `containerUri` | `String` | **required** | URI of container to which the resource will be attached or detached |
| `triplesToAdd` | `Array` | | Triples to add, in RDF/JS format. See below for details. |
| `triplesToRemove` | `Array` | | Triples to remove, in RDF/JS format. See below for details. |
| `webId` | `string` | Logged user's webId | User doing the action |

Example usage:

```js
const { triple, namedNode } = require('@rdfjs/data-model');

await this.broker.call('ldp.container.patch', {
containerUri: 'http://localhost:3002/resources',
triplesToAdd: [
triple(
namedNode('http://localhost:3002/resources'),
namedNode('http://www.w3.org/ns/ldp#contains'),
namedNode('http://localhost:3001/resources/my-resource')
)
]
});
```

Any remote RDF resource can be attached to a container, given that its server can answer a GET request on it that returns its content in Turtle format.
This means that even other LDP servers than semapps can have their resources linked to a container.
If the resource being patched is a remote resource, it will be stored locally (with `ldp.remote.store`) before being attached to the container.

### `post`

Expand Down

0 comments on commit 0e93018

Please sign in to comment.