Repository: solid/community-server (ts)

Issue:
Container metadata contains incorrect content-type
We get this when accessing a container (using a memory store):
```json
[
  {
    "@id": "http://localhost:3000/",
    "@type": [
      "http://www.w3.org/ns/ldp#Container",
      "http://www.w3.org/ns/ldp#BasicContainer",
      "http://www.w3.org/ns/ldp#Resource"
    ],
    "http://www.w3.org/ns/ldp#contains": [
      {
        "@id": "http://localhost:3000/.acl"
      }
    ],
    "http://www.w3.org/ns/ma-ont#format": [
      {
        "@value": "internal/quads"
      }
    ]
  }
]
```

The format is wrong here as these are no longer `internal/quads`. This is due to the fact that for containers the metadata is also used as data. We tried to get around this problem by delaying the data read as can be seen at 
https://github.com/solid/community-server/blob/1438fd81067a9b1f2befbd8b52d2255fe22e574e/src/storage/DataAccessorBasedStore.ts#L73-L76

But in hindsight this is not going to work as the converters are going to do a read and convert that data, and at that point it can't be changed anymore.

Pull request description:
fix: Create container data before adding content-type
Closes #349 

Patch:
diff --git a/src/storage/DataAccessorBasedStore.ts b/src/storage/DataAccessorBasedStore.ts
index adf0f25da..f7514f70f 100644
--- a/src/storage/DataAccessorBasedStore.ts
+++ b/src/storage/DataAccessorBasedStore.ts
@@ -1,4 +1,3 @@
-import type { Readable } from 'stream';
 import { DataFactory } from 'n3';
 import type { Quad } from 'rdf-js';
 import { v4 as uuid } from 'uuid';
@@ -11,7 +10,6 @@ import { ConflictHttpError } from '../util/errors/ConflictHttpError';
 import { MethodNotAllowedHttpError } from '../util/errors/MethodNotAllowedHttpError';
 import { NotFoundHttpError } from '../util/errors/NotFoundHttpError';
 import { NotImplementedHttpError } from '../util/errors/NotImplementedHttpError';
-import type { Guarded } from '../util/GuardedStream';
 import {
   ensureTrailingSlash,
   getParentContainer,
@@ -68,13 +66,12 @@ export class DataAccessorBasedStore implements ResourceStore {
 
     // Create the representation of a container
     if (this.isExistingContainer(metadata)) {
+      // Generate the data stream before setting the content-type to prevent unnecessary triples
+      const data = guardedStreamFrom(metadata.quads());
       metadata.contentType = INTERNAL_QUADS;
       result = {
         binary: false,
-        get data(): Guarded<Readable> {
-          // This allows other modules to still add metadata before the output data is written
-          return guardedStreamFrom(result.metadata.quads());
-        },
+        data,
         metadata,
       };
 


Test patch:
diff --git a/test/unit/storage/DataAccessorBasedStore.test.ts b/test/unit/storage/DataAccessorBasedStore.test.ts
index 905be3281..9d1721372 100644
--- a/test/unit/storage/DataAccessorBasedStore.test.ts
+++ b/test/unit/storage/DataAccessorBasedStore.test.ts
@@ -108,9 +108,10 @@ describe('A DataAccessorBasedStore', (): void => {
     it('will return a data stream that matches the metadata for containers.', async(): Promise<void> => {
       const resourceID = { path: `${root}container/` };
       accessor.data[resourceID.path] = { metadata: containerMetadata } as Representation;
+      const metaQuads = containerMetadata.quads();
       const result = await store.getRepresentation(resourceID);
       expect(result).toMatchObject({ binary: false });
-      expect(await arrayifyStream(result.data)).toBeRdfIsomorphic(containerMetadata.quads());
+      expect(await arrayifyStream(result.data)).toBeRdfIsomorphic(metaQuads);
       expect(result.metadata.contentType).toEqual(INTERNAL_QUADS);
     });
   });