Skip to content

Commit

Permalink
add pod component and changes to config
Browse files Browse the repository at this point in the history
  • Loading branch information
maartyman committed Feb 8, 2024
1 parent 9792131 commit 39d0721
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 9 deletions.
28 changes: 19 additions & 9 deletions config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
}
3 changes: 3 additions & 0 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
7 changes: 7 additions & 0 deletions lib/pod/IPod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { ServiceDescription } from '../service/IService';

export interface IPod {
newServiceLocation: (description: ServiceDescription) => Promise<string>;
}

export type PodServiceLocation = string;
64 changes: 64 additions & 0 deletions lib/pod/PodCss.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
// 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<string, unknown> = {
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<PodServiceLocation> {
if (!this.initialized) {
await new Promise<void>((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}`);
}
}
1 change: 1 addition & 0 deletions lib/pod/assets/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
./podData
37 changes: 37 additions & 0 deletions lib/pod/assets/css-config.json
Original file line number Diff line number Diff line change
@@ -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": []
}
9 changes: 9 additions & 0 deletions lib/pod/assets/seed.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[
{
"email": "[email protected]",
"password": "aggregator",
"pods": [
{ "name": "aggregator" }
]
}
]

0 comments on commit 39d0721

Please sign in to comment.