From f76ca8966566fa19e8cf5bbd9f5c8672ecafdc39 Mon Sep 17 00:00:00 2001 From: Maxim Van de Wynckel Date: Mon, 2 Dec 2024 22:31:20 +0100 Subject: [PATCH] fix: export models --- docker-compose.yml | 39 +++++++++++++ docker/Dockerfile | 13 +++++ docker/config/config.json | 89 ++++++++++++++++++++++++++++++ docker/entrypoint.sh | 16 ++++++ src/common/SolidPropertyService.ts | 4 ++ src/index.ts | 1 + src/models/index.ts | 3 + src/models/tree/index.ts | 2 + src/node/SolidPropertySink.ts | 35 +++++++++--- test/specs/solid.objects.spec.ts | 1 - 10 files changed, 195 insertions(+), 8 deletions(-) create mode 100644 docker-compose.yml create mode 100644 docker/Dockerfile create mode 100644 docker/config/config.json create mode 100644 docker/entrypoint.sh create mode 100644 src/models/index.ts diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..bd8ed7d --- /dev/null +++ b/docker-compose.yml @@ -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: + - USER_EMAIL=test1@test.com + - USER_POD=test1 + - USER_PASSWORD=test123 + - BASE_URL=http://localhost:3000 + ports: + - 3000:3000 + test-server2: + <<: *solid-server + environment: + - USER_EMAIL=test2@test.com + - USER_POD=test2 + - USER_PASSWORD=test123 + - BASE_URL=http://localhost:3001 + ports: + - 3001:3000 + test-server3: + <<: *solid-server + environment: + - USER_EMAIL=test3@test.com + - USER_POD=test3 + - USER_PASSWORD=test123 + - BASE_URL=http://localhost:3002 + ports: + - 3002:3000 \ No newline at end of file diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..363f6c9 --- /dev/null +++ b/docker/Dockerfile @@ -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"] diff --git a/docker/config/config.json b/docker/config/config.json new file mode 100644 index 0000000..70d7e5a --- /dev/null +++ b/docker/config/config.json @@ -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" + } + ] + } + ] +} \ No newline at end of file diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh new file mode 100644 index 0000000..fa17c9e --- /dev/null +++ b/docker/entrypoint.sh @@ -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 diff --git a/src/common/SolidPropertyService.ts b/src/common/SolidPropertyService.ts index 135736b..9f162fc 100644 --- a/src/common/SolidPropertyService.ts +++ b/src/common/SolidPropertyService.ts @@ -52,6 +52,10 @@ export class SolidPropertyService extends DataService { this.filter = filter ?? defaultFilter; } + get session(): SolidSession { + return this.service.session; + } + set service(service: SolidService) { this.driver.service = service; } diff --git a/src/index.ts b/src/index.ts index c19b065..90923e8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,2 +1,3 @@ import '@openhps/rdf/minimal'; export * from './index.node'; +export * from './models'; diff --git a/src/models/index.ts b/src/models/index.ts new file mode 100644 index 0000000..52387c1 --- /dev/null +++ b/src/models/index.ts @@ -0,0 +1,3 @@ +export * from './ldes'; +export * from './ldp'; +export * from './tree'; diff --git a/src/models/tree/index.ts b/src/models/tree/index.ts index 673cbdf..08d97c7 100644 --- a/src/models/tree/index.ts +++ b/src/models/tree/index.ts @@ -1 +1,3 @@ export * from './Node'; +export * from './Collection'; +export * from './Relation'; diff --git a/src/node/SolidPropertySink.ts b/src/node/SolidPropertySink.ts index 3e9daea..5048569 100644 --- a/src/node/SolidPropertySink.ts +++ b/src/node/SolidPropertySink.ts @@ -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 extends SinkNode { protected options: SolidPropertySinkOptions; - protected service: SolidService; + protected service: SolidPropertyService; constructor(options?: SolidPropertySinkOptions) { super(options); @@ -16,7 +16,7 @@ export class SolidPropertySink extends SinkNode { onBuild(): Promise { return new Promise((resolve, reject) => { - this.service = this.model.findService(SolidService); + this.service = this.model.findService(SolidPropertyService); if (!this.service) { reject(new Error('No Solid session found')); } @@ -44,9 +44,30 @@ export class SolidPropertySink extends SinkNode { */ protected prepareProperty(session: SolidSession): Promise { return new Promise((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[] = []; + // 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); }); } diff --git a/test/specs/solid.objects.spec.ts b/test/specs/solid.objects.spec.ts index bdf2f53..55fd737 100644 --- a/test/specs/solid.objects.spec.ts +++ b/test/specs/solid.objects.spec.ts @@ -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();