Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ These changes are relevant if you wrote custom modules for the server that depen
- `AgentGroupAccessChecker` no longer accepts any input parameters.
- The functions in `Vocabularies.ts` were renamed,
the typings have been made more precise and several utility types were added.
- The `RepresentationConvetingStore` `options.inType` was replaced with `options.inPreferences`.
- Several changes to support ACP.
- `WebAclAuxiliaryReader` was renamed to `AuthAuxiliaryReader`.
- `OwnerPermissionReader` input parameter `aclStrategy` was renamed to `authStrategy`.
Expand Down
5 changes: 4 additions & 1 deletion config/sparql-file-storage.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@
"@type": "RepresentationConvertingStore",
"metadataStrategy":{ "@id": "urn:solid-server:default:MetadataStrategy" },
"options_inConverter": { "@id": "urn:solid-server:default:RepresentationConverter" },
"options_inType": "internal/quads",
"options_inPreferences_type": {
"RepresentationConvertingStore:_options_inPreferences_type_key": "internal/quads",
"RepresentationConvertingStore:_options_inPreferences_type_value": 1
},
"source": {
"@type": "DataAccessorBasedStore",
"identifierStrategy": { "@id": "urn:solid-server:default:IdentifierStrategy" },
Expand Down
5 changes: 4 additions & 1 deletion config/storage/backend/regex.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@
"@type": "RepresentationConvertingStore",
"metadataStrategy":{ "@id": "urn:solid-server:default:MetadataStrategy" },
"options_inConverter": { "@id": "urn:solid-server:default:RepresentationConverter" },
"options_inType": "internal/quads",
"options_inPreferences_type": {
"RepresentationConvertingStore:_options_inPreferences_type_key": "internal/quads",
"RepresentationConvertingStore:_options_inPreferences_type_value": 1
},
"source": {
"@type": "DataAccessorBasedStore",
"identifierStrategy": { "@id": "urn:solid-server:default:IdentifierStrategy" },
Expand Down
5 changes: 4 additions & 1 deletion config/storage/backend/sparql.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
"comment": "This makes it so all incoming data is converted to quad objects.",
"@id": "urn:solid-server:default:ResourceStore_Converting",
"@type": "RepresentationConvertingStore",
"options_inType": "internal/quads"
"options_inPreferences_type": {
"RepresentationConvertingStore:_options_inPreferences_type_key": "internal/quads",
"RepresentationConvertingStore:_options_inPreferences_type_value": 1
}
}
]
}
14 changes: 10 additions & 4 deletions src/storage/RepresentationConvertingStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,25 @@ export class RepresentationConvertingStore<T extends ResourceStore = ResourceSto
private readonly inPreferences: RepresentationPreferences;

/**
* TODO: This should take RepresentationPreferences instead of a type string when supported by Components.js.
* @param source - Store we retrieve data from and send data to.
* @param metadataStrategy - Used to distinguish regular resources (which may be converted)
* from metadata resources (which always need conversion).
* @param options - Determines when data should be converted.
* * outConverter: Converts data after retrieval from the source store.
* * inConverter: Converts data before passing to the source store.
* * inPreferences: The preferred input format for the source store, as passed to the inConverter.
*/
public constructor(source: T, metadataStrategy: AuxiliaryStrategy, options: {
outConverter?: RepresentationConverter;
inConverter?: RepresentationConverter;
inType?: string;
inPreferences?: RepresentationPreferences;
}) {
super(source);
const { inConverter, outConverter, inPreferences } = options;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we swap this line with the one above please 🙂

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is unclear to me which two lines you want swapped. Could you make a change suggestion as usual?

this.metadataStrategy = metadataStrategy;
const { inConverter, outConverter, inType } = options;
this.inConverter = inConverter ?? new PassthroughConverter();
this.outConverter = outConverter ?? new PassthroughConverter();
this.inPreferences = !inType ? {} : { type: { [inType]: 1 }};
this.inPreferences = inPreferences ?? {};
}

public async getRepresentation(identifier: ResourceIdentifier, preferences: RepresentationPreferences,
Expand Down
7 changes: 5 additions & 2 deletions test/unit/storage/RepresentationConvertingStore.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Representation } from '../../../src/http/representation/Representation';
import type { RepresentationPreferences } from '../../../src/http/representation/RepresentationPreferences';
import type { RepresentationConverter } from '../../../src/storage/conversion/RepresentationConverter';
import { RepresentationConvertingStore } from '../../../src/storage/RepresentationConvertingStore';
import type { ResourceStore } from '../../../src/storage/ResourceStore';
Expand All @@ -23,9 +24,11 @@ describe('A RepresentationConvertingStore', (): void => {
const inConverter: RepresentationConverter = { handleSafe: jest.fn().mockResolvedValue(convertedIn) } as any;
const outConverter: RepresentationConverter = { handleSafe: jest.fn().mockResolvedValue(convertedOut) } as any;

const inType = 'text/turtle';
const inPreferences: RepresentationPreferences = { type: { 'text/turtle': 1 }};
const metadataStrategy = new SimpleSuffixStrategy('.meta');
const store = new RepresentationConvertingStore(source, metadataStrategy, { inType, inConverter, outConverter });
const store = new RepresentationConvertingStore(source,
metadataStrategy,
{ inPreferences, inConverter, outConverter });

beforeEach(async(): Promise<void> => {
jest.clearAllMocks();
Expand Down