From 39d07211dd0367ceb488f877a505a1d99b79d942 Mon Sep 17 00:00:00 2001 From: maartenvandenbrande Date: Thu, 8 Feb 2024 15:40:55 +0100 Subject: [PATCH] add pod component and changes to config --- config/default.json | 28 ++++++++++----- lib/index.ts | 3 ++ lib/pod/IPod.ts | 7 ++++ lib/pod/PodCss.ts | 64 ++++++++++++++++++++++++++++++++++ lib/pod/assets/.gitignore | 1 + lib/pod/assets/css-config.json | 37 ++++++++++++++++++++ lib/pod/assets/seed.json | 9 +++++ 7 files changed, 140 insertions(+), 9 deletions(-) create mode 100644 lib/pod/IPod.ts create mode 100644 lib/pod/PodCss.ts create mode 100644 lib/pod/assets/.gitignore create mode 100644 lib/pod/assets/css-config.json create mode 100644 lib/pod/assets/seed.json diff --git a/config/default.json b/config/default.json index 873acef..046906f 100644 --- a/config/default.json +++ b/config/default.json @@ -7,21 +7,31 @@ "sa:config/endpoint/endpoint.json" ], "@graph": [ + { + "@id": "urn:solid-aggregator:cost-queue-factory", + "@type": "CostQueueTimeFactory" + }, + { + "@id": "urn:solid-aggregator:fetch", + "@type": "NativeFetch" + }, + { + "@id": "urn:solid-aggregator:pod", + "@type": "PodCss" + }, + { + "@id": "urn:solid-aggregator:aggregator-service-aggregation", + "@type": "ServiceAggregation", + "fetch": { "@id": "urn:solid-aggregator:fetch" }, + "pod": { "@id": "urn:solid-aggregator:pod" } + }, { "@id": "urn:solid-aggregator:service-registry", "@type": "ServiceRegistryHardcodedTestOnly", "costQueueFactory": { "@id": "urn:solid-aggregator:cost-queue-factory" }, "aggregatorServices": [ - { "@id": "urn:solid-aggregator:aggregator-service-SPARQL" } + { "@id": "urn:solid-aggregator:aggregator-service-aggregation" } ] - }, - { - "@id": "urn:solid-aggregator:aggregator-service-SPARQL", - "@type": "ServiceSparql" - }, - { - "@id": "urn:solid-aggregator:cost-queue-factory", - "@type": "CostQueueTimeFactory" } ] } diff --git a/lib/index.ts b/lib/index.ts index 64d9aa6..cba9060 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -11,6 +11,9 @@ export * from './fetch/NativeFetch'; export * from './init/AppRunner'; +export * from './pod/IPod'; +export * from './pod/PodCss'; + export * from './service/IService'; export * from './service/ServiceEmpty'; export * from './service/ServiceAggregation'; diff --git a/lib/pod/IPod.ts b/lib/pod/IPod.ts new file mode 100644 index 0000000..b7d2254 --- /dev/null +++ b/lib/pod/IPod.ts @@ -0,0 +1,7 @@ +import type { ServiceDescription } from '../service/IService'; + +export interface IPod { + newServiceLocation: (description: ServiceDescription) => Promise; +} + +export type PodServiceLocation = string; diff --git a/lib/pod/PodCss.ts b/lib/pod/PodCss.ts new file mode 100644 index 0000000..7f8037b --- /dev/null +++ b/lib/pod/PodCss.ts @@ -0,0 +1,64 @@ +import * as path from 'node:path'; +import * as fs from 'fs-extra'; +import { AppRunner } from '@solid/community-server'; +import { v4 } from 'uuid'; +import { AsyncConstructor } from '../core/AsyncConstructor'; +import type { ServiceDescription } from '../service/IService'; +import type { IPod, PodServiceLocation } from './IPod'; + +export class PodCss extends AsyncConstructor implements IPod { + public podURL = 'http://localhost:3000/aggregator'; + + public constructor() { + super({}); + } + + protected async initialize(): Promise { + // TODO [2024-03-01]: make sure the file for the server is selected => not sure actually + + const loaderProperties = { + mainModulePath: 'node_modules/@solid/community-server/', + dumpErrorState: true, + typeChecking: false, + }; + + const config = path.join(__dirname, './assets/css-config.json'); + + const shorthand: Record = { + rootFilePath: path.join(__dirname, './assets/podData/'), + }; + if (!(await fs.pathExists(path.join(__dirname, './assets/podData/')))) { + shorthand.seedConfig = path.join(__dirname, './assets/seed.json'); + } + + await (new AppRunner()).run({ + loaderProperties, + config, + shorthand, + }); + // TODO [2024-03-01]: Edit profile card + } + + public async newServiceLocation(description: ServiceDescription): Promise { + if (!this.initialized) { + await new Promise((resolve): void => { + this.subscribeInitialized((): void => { + resolve(); + }); + }); + } + + // Create service folder with uuid + const location = `${this.podURL}/${v4()}`; + const response = await fetch(`${location}/description`, { + method: 'PUT', + body: description.toString(), + }); + + if (response.ok) { + return location; + } + // TODO [2024-03-01]: redo maybe? + throw new Error(`Can't create location on the Solid Server: ${response.statusText}`); + } +} diff --git a/lib/pod/assets/.gitignore b/lib/pod/assets/.gitignore new file mode 100644 index 0000000..f67ee08 --- /dev/null +++ b/lib/pod/assets/.gitignore @@ -0,0 +1 @@ +./podData diff --git a/lib/pod/assets/css-config.json b/lib/pod/assets/css-config.json new file mode 100644 index 0000000..f1c8a3b --- /dev/null +++ b/lib/pod/assets/css-config.json @@ -0,0 +1,37 @@ +{ + "@context": "https://linkedsoftwaredependencies.org/bundles/npm/@solid/community-server/^7.0.0/components/context.jsonld", + "import": [ + "css:config/app/init/default.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/allow-all.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/memory.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/empty.json", + "css:config/util/identifiers/suffix.json", + "css:config/util/index/default.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": [] +} diff --git a/lib/pod/assets/seed.json b/lib/pod/assets/seed.json new file mode 100644 index 0000000..955af89 --- /dev/null +++ b/lib/pod/assets/seed.json @@ -0,0 +1,9 @@ +[ + { + "email": "aggregator@example.com", + "password": "aggregator", + "pods": [ + { "name": "aggregator" } + ] + } +]