Repository navigation
fix(bigtable): use ReadonlyMap for EncodedKeyMap implements clause #9709
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
337fecb
dc750b2
5da790b
cf58149
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,7 +12,7 @@ | |
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| import {Duplex, Readable} from 'stream'; | ||
| import * as SqlTypes from './types'; | ||
| import {PreciseDate} from '@google-cloud/precise-date'; | ||
| import {NamedList} from './namedlist'; | ||
|
|
@@ -38,10 +38,7 @@ | |
| | null; | ||
|
|
||
| export type SqlValue = | ||
| | ExecuteQueryParameterValue | ||
| | Struct | ||
| | Array<SqlValue> | ||
| | BigtableMap; | ||
| ExecuteQueryParameterValue | Struct | Array<SqlValue> | BigtableMap; | ||
|
|
||
| /** | ||
| * A custom class created to allow setting year, month and date to 0. | ||
|
|
@@ -117,9 +114,10 @@ | |
| // internal representation of the map contains the original key and value tuple | ||
| type _MapValue = [MapKey, SqlValue]; | ||
|
|
||
| export class EncodedKeyMap | ||
| implements Map<bigint | string | Uint8Array | null, SqlValue> | ||
| { | ||
| export class EncodedKeyMap implements ReadonlyMap< | ||
| bigint | string | Uint8Array | null, | ||
| SqlValue | ||
| > { | ||
|
Comment on lines
+117
to
+120
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Generated] Change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is helpful. Good to know this line was the problem. |
||
| private map_impl: Map<bigint | string | null, _MapValue>; | ||
| /** | ||
| * Class representing a Map Value returned by ExecuteQuery. Native JS Map | ||
|
|
@@ -162,9 +160,9 @@ | |
| key: string | bigint | Uint8Array | null, | ||
| map: Map<string | bigint | Uint8Array | null, SqlValue>, | ||
| ) => void, | ||
| thisArg?: any, | ||
| ): void { | ||
| this.map_impl.forEach((value, key) => { | ||
| callbackfn.call(thisArg, value[1], value[0], this.map_impl); | ||
| }); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,12 +13,12 @@ | |
| // limitations under the License. | ||
|
|
||
| import * as assert from 'assert'; | ||
| import {describe, it, before, beforeEach, afterEach} from 'mocha'; | ||
|
Check warning on line 16 in handwritten/bigtable/test/base64keymap.ts
|
||
| import Long = require('long'); | ||
| import * as proxyquire from 'proxyquire'; | ||
| import * as sn from 'sinon'; | ||
|
|
||
| import {RowStateEnum} from '../src/chunktransformer.js'; | ||
| import {Mutation} from '../src/mutation.js'; | ||
| import {Row} from '../src/row.js'; | ||
| import {EncodedKeyMap, SqlValue} from '../src/execute-query/values.js'; | ||
|
|
@@ -180,5 +180,22 @@ | |
| assert.deepStrictEqual(resultForEach[1][0], 'stringKey1'); | ||
| assert.deepStrictEqual(resultForEach[1][1], 'valueForString1'); | ||
| }); | ||
| it('implements ReadonlyMap without adding extra methods', () => { | ||
| const map = new EncodedKeyMap([ | ||
| [Buffer.from('existingBuffer'), 'initialBufferValue'], | ||
| ['existingNullValue', null], | ||
| ]); | ||
| const readonlyMap: ReadonlyMap< | ||
| string | bigint | Uint8Array | null, | ||
| SqlValue | ||
| > = map; | ||
| assert.strictEqual( | ||
| readonlyMap.get(Buffer.from('existingBuffer')), | ||
| 'initialBufferValue', | ||
| ); | ||
| assert.strictEqual(readonlyMap.get('existingNullValue'), null); | ||
| assert.strictEqual('getOrInsert' in map, false); | ||
| assert.strictEqual('getOrInsertComputed' in map, false); | ||
| }); | ||
|
Comment on lines
+183
to
+199
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Generated] Verify |
||
| }); | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Generated] Format
export type SqlValueunion onto a single line to satisfy Prettier (node ./bin/linter.mjs --strict) inpresubmit/lint.