Skip to content

Commit

Permalink
fix: export models
Browse files Browse the repository at this point in the history
  • Loading branch information
Maximvdw committed Dec 2, 2024
1 parent 85ecc34 commit f76ca89
Show file tree
Hide file tree
Showing 10 changed files with 195 additions and 8 deletions.
39 changes: 39 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
networks:
dht-network:
driver: bridge

x-solid-server: &solid-server
build:
context: docker
dockerfile: Dockerfile
networks:
- dht-network

services:
test-server1:
<<: *solid-server
environment:
- [email protected]
- USER_POD=test1
- USER_PASSWORD=test123
- BASE_URL=http://localhost:3000
ports:
- 3000:3000
test-server2:
<<: *solid-server
environment:
- [email protected]
- USER_POD=test2
- USER_PASSWORD=test123
- BASE_URL=http://localhost:3001
ports:
- 3001:3000
test-server3:
<<: *solid-server
environment:
- [email protected]
- USER_POD=test3
- USER_PASSWORD=test123
- BASE_URL=http://localhost:3002
ports:
- 3002:3000
13 changes: 13 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM solidproject/community-server
RUN npm install mashlib

WORKDIR /community-server

# Copy configuration
COPY ./config/config.json /config/config.json

# Copy entrypoint
COPY ./entrypoint.sh /community-server/entrypoint.sh
RUN chmod +x ./entrypoint.sh

ENTRYPOINT ["sh", "./entrypoint.sh"]
89 changes: 89 additions & 0 deletions docker/config/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{
"@context": "https://linkedsoftwaredependencies.org/bundles/npm/@solid/community-server/^7.0.0/components/context.jsonld",
"import": [
"css:config/app/init/static-root.json",
"css:config/app/main/default.json",
"css:config/app/variables/default.json",
"css:config/http/handler/default.json",
"css:config/http/middleware/default.json",
"css:config/http/notifications/all.json",
"css:config/http/server-factory/http.json",
"css:config/http/static/default.json",
"css:config/identity/access/public.json",
"css:config/identity/email/default.json",
"css:config/identity/handler/default.json",
"css:config/identity/oidc/default.json",
"css:config/identity/ownership/token.json",
"css:config/identity/pod/static.json",
"css:config/ldp/authentication/dpop-bearer.json",
"css:config/ldp/authorization/webacl.json",
"css:config/ldp/handler/default.json",
"css:config/ldp/metadata-parser/default.json",
"css:config/ldp/metadata-writer/default.json",
"css:config/ldp/modes/default.json",
"css:config/storage/backend/file.json",
"css:config/storage/key-value/resource-store.json",
"css:config/storage/location/pod.json",
"css:config/storage/middleware/default.json",
"css:config/util/auxiliary/acl.json",
"css:config/util/identifiers/suffix.json",
"css:config/util/index/example.json",
"css:config/util/logging/winston.json",
"css:config/util/representation-conversion/default.json",
"css:config/util/resource-locker/file.json",
"css:config/util/variables/default.json"
],
"@graph": [
{
"comment": "An example of how the UI converter can be configured.",
"@type": "Override",
"overrideInstance": {
"@id": "urn:solid-server:default:DefaultUiConverter"
},
"overrideParameters": {
"@type": "ConstantConverter",
"contentType": "text/html",
"filePath": "./node_modules/mashlib/dist/databrowser.html",
"options_container": true,
"options_document": false,
"options_minQuality": 1
}
},
{
"comment": "Serve Databrowser as default representation",
"@id": "urn:solid-server:default:DefaultUiConverter",
"@type": "ConstantConverter",
"contentType": "text/html",
"filePath": "./node_modules/mashlib/dist/databrowser.html",
"options_container": true,
"options_document": true,
"options_minQuality": 1,
"options_disabledMediaRanges": [
"image/*",
"application/pdf"
]
},
{
"comment": "Serve Mashlib static files.",
"@id": "urn:solid-server:default:StaticAssetHandler",
"@type": "StaticAssetHandler",
"assets": [
{
"@type": "StaticAssetEntry",
"relativeUrl": "/mash.css",
"filePath": "./node_modules/mashlib/dist/mash.css"
},
{
"@type": "StaticAssetEntry",
"relativeUrl": "/mashlib.min.js",
"filePath": "./node_modules/mashlib/dist/mashlib.min.js"
},
{
"@type": "StaticAssetEntry",
"relativeUrl": "/mashlib.min.js.map",
"filePath": "./node_modules/mashlib/dist/mashlib.min.js.map"
}
]
}
]
}
16 changes: 16 additions & 0 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

# Get the user email and user password from env
USER_EMAIL=${USER_EMAIL:-""}
USER_PASSWORD=${USER_PASSWORD:-""}
USER_POD=${USER_POD:-"pod1"}

BASE_URL=${BASE_URL:-"http://localhost:3000"}

# Create a json file with the user email and password
echo "Creating user file"
echo "[{\"email\":\"${USER_EMAIL}\",\"password\":\"${USER_PASSWORD}\",\"pods\":[{\"name\":\"${USER_POD}\"}]}]" > /config/users.json

# Start solid server
echo "Starting Solid server"
node bin/server.js -c /config/config.json -f /data --baseUrl ${BASE_URL} --seedConfig /config/users.json
4 changes: 4 additions & 0 deletions src/common/SolidPropertyService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ export class SolidPropertyService extends DataService<string, any> {
this.filter = filter ?? defaultFilter;
}

get session(): SolidSession {
return this.service.session;
}

set service(service: SolidService) {
this.driver.service = service;
}
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
import '@openhps/rdf/minimal';
export * from './index.node';
export * from './models';
3 changes: 3 additions & 0 deletions src/models/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './ldes';
export * from './ldp';
export * from './tree';
2 changes: 2 additions & 0 deletions src/models/tree/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export * from './Node';
export * from './Collection';
export * from './Relation';
35 changes: 28 additions & 7 deletions src/node/SolidPropertySink.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { DataFrame, PushOptions, SinkNode, SinkNodeOptions } from '@openhps/core';
import { Property } from '@openhps/rdf';
import { SolidService, SolidSession } from '../common';
import { IriString, Property } from '@openhps/rdf';
import { SolidPropertyService, SolidService, SolidSession } from '../common';

/**
* Solid property sink is a sink node that writes data to a Solid pod.
*/
export class SolidPropertySink<Out extends DataFrame> extends SinkNode<Out> {
protected options: SolidPropertySinkOptions;
protected service: SolidService;
protected service: SolidPropertyService;

constructor(options?: SolidPropertySinkOptions) {
super(options);
Expand All @@ -16,7 +16,7 @@ export class SolidPropertySink<Out extends DataFrame> extends SinkNode<Out> {

onBuild(): Promise<void> {
return new Promise<void>((resolve, reject) => {
this.service = this.model.findService(SolidService);
this.service = this.model.findService(SolidPropertyService);
if (!this.service) {
reject(new Error('No Solid session found'));
}
Expand Down Expand Up @@ -44,9 +44,30 @@ export class SolidPropertySink<Out extends DataFrame> extends SinkNode<Out> {
*/
protected prepareProperty(session: SolidSession): Promise<void> {
return new Promise<void>((resolve, reject) => {
// Create a new Solid pod for the property
// Get the root directory
const property = new Property();
// Create a new property
const promises: Promise<IriString>[] = [];
// Prepare properties
for (const property of this.options.properties) {
if (property === PropertyType.POSITION) {
const positionProperty = new Property();
positionProperty.label = 'Position';
promises.push(this.service.createProperty(session, positionProperty));
} else if (property === PropertyType.VELOCITY) {
const velocityProperty = new Property();
velocityProperty.label = 'Velocity';
promises.push(this.service.createProperty(session, velocityProperty));
} else if (property === PropertyType.ORIENTATION) {
const orientationProperty = new Property();
orientationProperty.label = 'Orientation';
promises.push(this.service.createProperty(session, orientationProperty));
}
}

Promise.all(promises)
.then(() => {
resolve();
})
.catch(reject);
});
}

Expand Down
1 change: 0 additions & 1 deletion test/specs/solid.objects.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { expect } from 'chai';
import { SolidClientService, SolidDataDriver } from '../../src';
import { Accelerometer, DataFrame, DataFrameService, DataObject, DataObjectService, Model, ModelBuilder } from '@openhps/core';
require('dotenv').config();
Expand Down

0 comments on commit f76ca89

Please sign in to comment.