Skip to content

Namespace Datastore throws when queried. #236

@saul-jb

Description

@saul-jb

The Namespace Datastore will throw an error if query is called when the parent datastore has other values in it that aren't prefixed the same.

The following code will produce this issue.

import { NamespaceDatastore, MemoryDatastore } from 'datastore-core'
import { Key } from 'interface-datastore'

const root = new MemoryDatastore();
const sub1 = new NamespaceDatastore(root, new Key('sub1'))
const sub2 = new NamespaceDatastore(root, new Key('sub2'))

sub1.put(new Key('test'), new Uint8Array([123]))

for await (const pair of sub2.query({})) { }

Creating the following error:

          throw new Error(`Expected prefix: (${prefix.toString()}) in key: ${key.toString()}`)
                ^
Error: Expected prefix: (/sub2) in key: /sub1/test

The expected behavior is for the query to only run on namespaced keys.

Versions:

"datastore-core": "^9.2.0"
"interface-datastore": "^8.2.3"

Metadata

Metadata

Assignees

No one assigned

    Labels

    need/triageNeeds initial labeling and prioritization

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions