From 52fa92ca42009505582a889629c1c438cd212245 Mon Sep 17 00:00:00 2001 From: "Afshin T. Darian" Date: Sun, 5 Jan 2020 03:20:41 +0000 Subject: [PATCH 1/4] Query list() calls based on an explicit namespace match instead of a starts-with match. Fixes #7257. --- packages/statedb/src/statedb.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/statedb/src/statedb.ts b/packages/statedb/src/statedb.ts index e2d5dac3865f..dd5754b0edba 100644 --- a/packages/statedb/src/statedb.ts +++ b/packages/statedb/src/statedb.ts @@ -177,7 +177,7 @@ export class StateDB< /** * Fetch a list from the database. */ - private async _list(query?: string): Promise<{ ids: string[]; values: T[] }> { + private async _list(query = ''): Promise<{ ids: string[]; values: T[] }> { const { ids, values } = await this._connector.list(query); return { @@ -304,7 +304,7 @@ export namespace StateDB { async list(query = ''): Promise<{ ids: string[]; values: string[] }> { return Object.keys(this._storage).reduce( (acc, val) => { - if (val && val.indexOf(query) === 0) { + if (query === '' ? true : query === val.split(':')[0]) { acc.ids.push(val); acc.values.push(this._storage[val]); } From 92f30a24f4d63e47cdf1fcd1f30ae399d3399738 Mon Sep 17 00:00:00 2001 From: "Afshin T. Darian" Date: Sun, 5 Jan 2020 03:25:34 +0000 Subject: [PATCH 2/4] Update list() test to fail under old behavior but pass under new. --- tests/test-statedb/src/statedb.spec.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/test-statedb/src/statedb.spec.ts b/tests/test-statedb/src/statedb.spec.ts index a2a725b80568..29b631cb40e5 100644 --- a/tests/test-statedb/src/statedb.spec.ts +++ b/tests/test-statedb/src/statedb.spec.ts @@ -120,7 +120,10 @@ describe('StateDB', () => { 'foo:qux', 'abc:def', 'abc:ghi', - 'abc:jkl' + 'abc:jkl', + 'foo-two:bar', + 'foo-two:baz', + 'foo-two:qux' ]; await Promise.all(keys.map(key => db.save(key, { value: key }))); From 22b0813010b7e7629516d0081846328561f09937 Mon Sep 17 00:00:00 2001 From: "Afshin T. Darian" Date: Sun, 5 Jan 2020 12:20:41 +0000 Subject: [PATCH 3/4] Update docstrings. --- packages/filebrowser/src/browser.ts | 4 ++-- packages/statedb/src/statedb.ts | 11 +++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/filebrowser/src/browser.ts b/packages/filebrowser/src/browser.ts index bc0cc93616f2..c22c33d8a560 100644 --- a/packages/filebrowser/src/browser.ts +++ b/packages/filebrowser/src/browser.ts @@ -316,8 +316,8 @@ export namespace FileBrowser { * The default is `true`. * * #### Notes - * The file browser model will need to be restored before for the file - * browser to start saving its state. + * The file browser model will need to be restored manually for the file + * browser to be able to save its state. */ restore?: boolean; } diff --git a/packages/statedb/src/statedb.ts b/packages/statedb/src/statedb.ts index dd5754b0edba..aed1e0a94eca 100644 --- a/packages/statedb/src/statedb.ts +++ b/packages/statedb/src/statedb.ts @@ -177,8 +177,8 @@ export class StateDB< /** * Fetch a list from the database. */ - private async _list(query = ''): Promise<{ ids: string[]; values: T[] }> { - const { ids, values } = await this._connector.list(query); + private async _list(namespace = ''): Promise<{ ids: string[]; values: T[] }> { + const { ids, values } = await this._connector.list(namespace); return { ids, @@ -300,11 +300,14 @@ export namespace StateDB { /** * Retrieve the list of items available from the data connector. + * + * @param namespace - If not empty, only keys whose first token before `:` + * exactly match `namespace` will be returned, e.g. `foo` in `foo:bar`. */ - async list(query = ''): Promise<{ ids: string[]; values: string[] }> { + async list(namespace = ''): Promise<{ ids: string[]; values: string[] }> { return Object.keys(this._storage).reduce( (acc, val) => { - if (query === '' ? true : query === val.split(':')[0]) { + if (namespace === '' ? true : namespace === val.split(':')[0]) { acc.ids.push(val); acc.values.push(this._storage[val]); } From 3f6eb9adef8fa67d98cb99c333045b6aebcb7ea2 Mon Sep 17 00:00:00 2001 From: "Afshin T. Darian" Date: Sun, 5 Jan 2020 14:37:44 +0000 Subject: [PATCH 4/4] Update docstring for restorable pool add. --- packages/statedb/src/restorablepool.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/statedb/src/restorablepool.ts b/packages/statedb/src/restorablepool.ts index 13cc355f70c1..b2a2be302610 100644 --- a/packages/statedb/src/restorablepool.ts +++ b/packages/statedb/src/restorablepool.ts @@ -107,8 +107,8 @@ export class RestorablePool< * @param obj - The object object being added. * * #### Notes - * The object passed into the tracker is added synchronously; its existence in - * the tracker can be checked with the `has()` method. The promise this method + * The object passed into the pool is added synchronously; its existence in + * the pool can be checked with the `has()` method. The promise this method * returns resolves after the object has been added and saved to an underlying * restoration connector, if one is available. */