Skip to content

Commit 3e60a40

Browse files
committed
Revert "Allow hash keys to be URIs that dereference to a string"
This reverts commit b35b725.
1 parent e755b45 commit 3e60a40

File tree

2 files changed

+6
-39
lines changed

2 files changed

+6
-39
lines changed

lib/construction/argument/ArgumentConstructorHandlerHash.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,14 @@ export class ArgumentConstructorHandlerHash implements IArgumentConstructorHandl
2929
if (!entry.property.key) {
3030
throw new ErrorResourcesContext(`Missing key in fields entry`, { entry, argument });
3131
}
32-
33-
const key = await argsCreator.getArgumentValues(entry.properties.key, settings);
34-
if (typeof key !== 'string') {
35-
throw new ErrorResourcesContext(`Illegal non-string key (${entry.property.key.value} as ${entry.property.key.type}) in fields entry`, { entry, argument });
32+
if (entry.property.key.type !== 'Literal') {
33+
throw new ErrorResourcesContext(`Illegal non-literal key (${entry.property.key.value} as ${entry.property.key.type}) in fields entry`, { entry, argument });
3634
}
3735

3836
// Recursively get value arg value
3937
if (entry.property.value) {
4038
const subValue = await argsCreator.getArgumentValues(entry.properties.value, settings);
41-
return { key, value: subValue };
39+
return { key: entry.property.key.value, value: subValue };
4240
}
4341

4442
// Ignore cases where value may not be set, because params may be optional

test/unit/construction/ConfigConstructor-test.ts

+3-34
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const DF = new DataFactory();
1212
describe('ConfigConstructor', () => {
1313
let objectLoader: RdfObjectLoader;
1414
let componentResources: Record<string, Resource>;
15-
let configConstructorPool: jest.Mocked<ConfigConstructorPool<any>>;
15+
let configConstructorPool: ConfigConstructorPool<any>;
1616
let constructor: ConfigConstructor<any>;
1717
let constructionStrategy: IConstructionStrategy<any>;
1818
let moduleState: IModuleState;
@@ -223,7 +223,7 @@ describe('ConfigConstructor', () => {
223223
.toThrowError(/^Missing key in fields entry/u);
224224
});
225225

226-
it('can use dereferenced IRI values as keys', async() => {
226+
it('should throw on IRI key', async() => {
227227
const resource = objectLoader.createCompactedResource({
228228
fields: {
229229
list: [
@@ -234,39 +234,8 @@ describe('ConfigConstructor', () => {
234234
],
235235
},
236236
});
237-
expect(await constructor.getArgumentValue(resource, settings)).toEqual({
238-
entries: [
239-
{
240-
key: 'INSTANCE',
241-
value: 'ABC',
242-
},
243-
],
244-
});
245-
expect(constructionStrategy.createHash).toHaveBeenCalledWith({
246-
settings,
247-
entries: [
248-
{
249-
key: 'INSTANCE',
250-
value: 'ABC',
251-
},
252-
],
253-
});
254-
});
255-
256-
it('should throw on non-string keys', async() => {
257-
configConstructorPool.instantiate.mockResolvedValueOnce(new Error('this is an object'));
258-
const resource = objectLoader.createCompactedResource({
259-
fields: {
260-
list: [
261-
{
262-
key: `ex:abc`,
263-
value: '"ABC"',
264-
},
265-
],
266-
},
267-
});
268237
await expect(constructor.getArgumentValue(resource, settings)).rejects
269-
.toThrowError(/^Illegal non-string key \(ex:abc as NamedNode\) in fields entry/u);
238+
.toThrowError(/^Illegal non-literal key \(ex:abc as NamedNode\) in fields entry/u);
270239
});
271240

272241
it('should ignore fields without value', async() => {

0 commit comments

Comments
 (0)