m-ld / m-ld-js

m-ld Javascript engine
https://js.m-ld.org
MIT License
37 stars 2 forks source link

Should construct a nested object with a variable `@id` #147

Open Peeja opened 1 year ago

Peeja commented 1 year ago
test('constructs a nested object with a variable @id', async () => {
  await api.write<Subject>({ '@id': 'fred', name: 'Fred', wife: { '@id': 'wilma' } });
  await expect(api.read<Construct>({
    '@construct': { '@id': 'fred', wife: { '@id': '?' } }
  })).resolves.toMatchObject([{
    '@id': 'fred', wife: { '@id': 'wilma' }
  }]);
});

Instead, we get [{ '@id': 'fred', wife: { '@id': '?' } }]—the variable has shown up as a value in the result.

Note that using the variable as the entire value of wife in the @construct works correctly:

{ '@construct': { '@id': 'fred', wife: '?' } } => [{ '@id': 'fred', wife: { '@id': 'wilma' } }]