Skip to content

Commit 98198a4

Browse files
authored
Merge branch 'main' into release-please--branches--main--components--spanner
2 parents 196a666 + 7abb33c commit 98198a4

File tree

3 files changed

+56
-12
lines changed

3 files changed

+56
-12
lines changed

src/codec.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ import * as uuid from 'uuid';
3838
// eslint-disable-next-line @typescript-eslint/no-explicit-any
3939
export type Value = any;
4040

41+
let uuidUntypedFlagWarned = false;
42+
4143
export interface Field {
4244
name: string;
4345
value: Value;
@@ -1160,8 +1162,17 @@ function getType(value: Value): Type {
11601162
return {type: 'bool'};
11611163
}
11621164

1163-
if (uuid.validate(value)) {
1164-
return {type: 'unspecified'};
1165+
if (process.env['SPANNER_ENABLE_UUID_AS_UNTYPED'] === 'true') {
1166+
if (!uuidUntypedFlagWarned) {
1167+
process.emitWarning(
1168+
'SPANNER_ENABLE_UUID_AS_UNTYPED environment variable is deprecated and will be removed in a future release.',
1169+
'DeprecationWarning',
1170+
);
1171+
uuidUntypedFlagWarned = true;
1172+
}
1173+
if (uuid.validate(value)) {
1174+
return {type: 'unspecified'};
1175+
}
11651176
}
11661177

11671178
if (isString(value)) {

src/transaction.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1735,14 +1735,18 @@ export class Snapshot extends EventEmitter {
17351735
if (!isEmpty(typeMap)) {
17361736
Object.keys(typeMap).forEach(param => {
17371737
const type = typeMap[param];
1738-
const typeObject = codec.createTypeObject(type);
1739-
if (
1740-
(type.child &&
1741-
typeObject.code === 'ARRAY' &&
1742-
typeObject.arrayElementType?.code !== 'TYPE_CODE_UNSPECIFIED') ||
1743-
(!type.child && typeObject.code !== 'TYPE_CODE_UNSPECIFIED')
1744-
) {
1745-
paramTypes[param] = typeObject;
1738+
if (process.env['SPANNER_ENABLE_UUID_AS_UNTYPED'] === 'true') {
1739+
const typeObject = codec.createTypeObject(type);
1740+
if (
1741+
(type.child &&
1742+
typeObject.code === 'ARRAY' &&
1743+
typeObject.arrayElementType?.code !== 'TYPE_CODE_UNSPECIFIED') ||
1744+
(!type.child && typeObject.code !== 'TYPE_CODE_UNSPECIFIED')
1745+
) {
1746+
paramTypes[param] = typeObject;
1747+
}
1748+
} else {
1749+
paramTypes[param] = codec.createTypeObject(type);
17461750
}
17471751
});
17481752
}

test/codec.ts

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1778,12 +1778,41 @@ describe('codec', () => {
17781778
});
17791779
});
17801780

1781-
it('should determine if the uuid value is unspecified', () => {
1781+
it('should determine if the uuid value is string', () => {
17821782
assert.deepStrictEqual(codec.getType(uuid.v4()), {
1783-
type: 'unspecified',
1783+
type: 'string',
17841784
});
17851785
});
17861786

1787+
it('should determine if the uuid value is unspecified when SPANNER_ENABLE_UUID_AS_UNTYPED is true', () => {
1788+
const emitWarningStub = sandbox.stub(process, 'emitWarning');
1789+
try {
1790+
process.env['SPANNER_ENABLE_UUID_AS_UNTYPED'] = 'true';
1791+
assert.deepStrictEqual(codec.getType(uuid.v4()), {
1792+
type: 'unspecified',
1793+
});
1794+
assert.strictEqual(emitWarningStub.calledOnce, true);
1795+
assert.strictEqual(
1796+
emitWarningStub.firstCall.args[0],
1797+
'SPANNER_ENABLE_UUID_AS_UNTYPED environment variable is deprecated and will be removed in a future release.',
1798+
);
1799+
} finally {
1800+
delete process.env['SPANNER_ENABLE_UUID_AS_UNTYPED'];
1801+
emitWarningStub.restore();
1802+
}
1803+
});
1804+
1805+
it('should determine if the uuid value is string when SPANNER_ENABLE_UUID_AS_UNTYPED is false', () => {
1806+
try {
1807+
process.env['SPANNER_ENABLE_UUID_AS_UNTYPED'] = 'false';
1808+
assert.deepStrictEqual(codec.getType(uuid.v4()), {
1809+
type: 'string',
1810+
});
1811+
} finally {
1812+
delete process.env['SPANNER_ENABLE_UUID_AS_UNTYPED'];
1813+
}
1814+
});
1815+
17871816
it('should determine if the value is a float32', () => {
17881817
assert.deepStrictEqual(codec.getType(new codec.Float32(1.1)), {
17891818
type: 'float32',

0 commit comments

Comments
 (0)