Repository navigation
chore(bigtable): [Style Maintenance] align EncodedKeyMap JSDoc and test coverage #9710
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
base: main
Are you sure you want to change the base?
Changes from all commits
337fecb
dc750b2
5da790b
cf58149
4f018a0
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,19 +114,25 @@ | |
| // 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> | ||
| { | ||
| /** | ||
| * Class representing a Map Value returned by ExecuteQuery. Native JS Map | ||
| * does not support Buffer comparison - it compares object id and not | ||
| * buffer values. This class solves this by encoding Buffer keys as | ||
| * base64 strings. | ||
| * Please note that an empty string and an empty buffer have the same | ||
| * representation, however, we do not ever use mixed key types (all keys are | ||
| * always all buffers or all strings) so we don't need to handle this. | ||
| * | ||
| * Implements `ReadonlyMap` rather than `Map` so emitted declarations remain | ||
| * compatible with TypeScript 7.0+ (`--target esnext`) without adding ESNext | ||
| * `Map` upsert methods (`getOrInsert` / `getOrInsertComputed`). | ||
| */ | ||
| export class EncodedKeyMap implements ReadonlyMap< | ||
| bigint | string | Uint8Array | null, | ||
| SqlValue | ||
| > { | ||
| private map_impl: Map<bigint | string | null, _MapValue>; | ||
| /** | ||
| * Class representing a Map Value returned by ExecuteQuery. Native JS Map | ||
| * does not support Buffer comparison - it compares object id and not | ||
| * buffer values. This class solves this by encoding Buffer keys as | ||
| * base64 strings. | ||
| * Please note that an empty string and an empty buffer have the same | ||
| * representation, however, we do not ever use mixed key types (all keys are | ||
| * always all buffers or all strings) so we don't need to handle this. | ||
| */ | ||
|
|
||
|
Comment on lines
+117
to
+135
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] Move the class-level JSDoc comment above |
||
| constructor( | ||
| entries?: ReadonlyArray< | ||
| [bigint | string | Uint8Array | null, SqlValue] | ||
|
|
@@ -162,9 +165,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,23 @@ | |
| 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(map.get(Buffer.from('missingBuffer')), undefined); | ||
|
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] Add missing-buffer key lookup assertion alongside the |
||
| assert.strictEqual('getOrInsert' in map, false); | ||
| assert.strictEqual('getOrInsertComputed' in map, false); | ||
| }); | ||
| }); | ||
| }); | ||
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
SqlValueunion onto a single line as required bygts/ Prettier (node ./bin/linter.mjs --strict).