Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions handwritten/bigtable/src/execute-query/values.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import {Duplex, Readable} from 'stream';

Check warning on line 15 in handwritten/bigtable/src/execute-query/values.ts

View workflow job for this annotation

GitHub Actions / lint

'Readable' is defined but never used
import * as SqlTypes from './types';
import {PreciseDate} from '@google-cloud/precise-date';
import {NamedList} from './namedlist';
Expand All @@ -38,10 +38,7 @@
| null;

export type SqlValue =
| ExecuteQueryParameterValue
| Struct
| Array<SqlValue>
| BigtableMap;
ExecuteQueryParameterValue | Struct | Array<SqlValue> | BigtableMap;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Generated] Format export type SqlValue union onto a single line to satisfy Prettier (node ./bin/linter.mjs --strict) in presubmit/lint.


/**
* A custom class created to allow setting year, month and date to 0.
Expand Down Expand Up @@ -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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Generated] Change EncodedKeyMap from implements Map<...> to implements ReadonlyMap<bigint | string | Uint8Array | null, SqlValue> so emitted .d.ts declarations pass TypeScript 7.0 (--target esnext) without adding getOrInsert or getOrInsertComputed methods to EncodedKeyMap.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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
Expand Down Expand Up @@ -162,9 +160,9 @@
key: string | bigint | Uint8Array | null,
map: Map<string | bigint | Uint8Array | null, SqlValue>,
) => void,
thisArg?: any,

Check warning on line 163 in handwritten/bigtable/src/execute-query/values.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
): void {
this.map_impl.forEach((value, key) => {

Check warning on line 165 in handwritten/bigtable/src/execute-query/values.ts

View workflow job for this annotation

GitHub Actions / lint

'key' is defined but never used
callbackfn.call(thisArg, value[1], value[0], this.map_impl);
});
}
Expand Down
17 changes: 17 additions & 0 deletions handwritten/bigtable/test/base64keymap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

View workflow job for this annotation

GitHub Actions / lint

'afterEach' is defined but never used

Check warning on line 16 in handwritten/bigtable/test/base64keymap.ts

View workflow job for this annotation

GitHub Actions / lint

'beforeEach' is defined but never used

Check warning on line 16 in handwritten/bigtable/test/base64keymap.ts

View workflow job for this annotation

GitHub Actions / lint

'before' is defined but never used
import Long = require('long');

Check warning on line 17 in handwritten/bigtable/test/base64keymap.ts

View workflow job for this annotation

GitHub Actions / lint

'Long' is defined but never used
import * as proxyquire from 'proxyquire';

Check warning on line 18 in handwritten/bigtable/test/base64keymap.ts

View workflow job for this annotation

GitHub Actions / lint

'proxyquire' is defined but never used
import * as sn from 'sinon';

Check warning on line 19 in handwritten/bigtable/test/base64keymap.ts

View workflow job for this annotation

GitHub Actions / lint

'sn' is defined but never used

import {RowStateEnum} from '../src/chunktransformer.js';

Check warning on line 21 in handwritten/bigtable/test/base64keymap.ts

View workflow job for this annotation

GitHub Actions / lint

'RowStateEnum' is defined but never used
import {Mutation} from '../src/mutation.js';
import {Row} from '../src/row.js';
import {EncodedKeyMap, SqlValue} from '../src/execute-query/values.js';
Expand Down Expand Up @@ -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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Generated] Verify EncodedKeyMap is assignable to ReadonlyMap and ES2023 Map and does not expose getOrInsert or getOrInsertComputed methods.

});
});
Loading