Skip to content

Commit 5d67c5a

Browse files
committed
refactor
1 parent ddd6e8f commit 5d67c5a

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

src/index.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -207,19 +207,21 @@ export type TranslateEnumKeys<
207207
[P in keyof T]: P extends U ? EnumKey<E> | null | undefined : T[P];
208208
};
209209

210-
function getUniverseDomainOnly(options: SpannerOptions): string | undefined {
210+
function getUniverseDomainOnly(options: SpannerOptions): string {
211211
const universeDomainEnvVar =
212212
typeof process === 'object' && typeof process.env === 'object'
213213
? process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']
214214
: undefined;
215215
const universeDomain =
216-
options?.universeDomain ?? options?.universe_domain ?? universeDomainEnvVar;
216+
options?.universeDomain ??
217+
options?.universe_domain ??
218+
universeDomainEnvVar ??
219+
'googleapis.com';
217220
return universeDomain;
218221
}
219222

220223
function getDomain(prefix: string, options: SpannerOptions): string {
221-
const universeDomainOnly = getUniverseDomainOnly(options);
222-
const suffix = universeDomainOnly ? universeDomainOnly : 'googleapis.com';
224+
const suffix = getUniverseDomainOnly(options);
223225
return `${prefix}.${suffix}`;
224226
}
225227

@@ -390,11 +392,17 @@ class Spanner extends GrpcService {
390392
options.sslCreds = grpc.credentials.createInsecure();
391393
}
392394

393-
const domain = getDomain('spanner', options);
394-
const universeDomain = getUniverseDomainOnly(options);
395-
options.universeDomain = universeDomain;
395+
const universeDomain = getDomain('spanner', options);
396+
if (
397+
!options.universeDomain &&
398+
(options.universe_domain || process.env.GOOGLE_CLOUD_UNIVERSE_DOMAIN)
399+
) {
400+
options.universeDomain =
401+
options.universe_domain ?? process.env.GOOGLE_CLOUD_UNIVERSE_DOMAIN;
402+
delete options.universe_domain;
403+
}
396404
const config = {
397-
baseUrl: options.apiEndpoint || options.servicePath || domain,
405+
baseUrl: options.apiEndpoint || options.servicePath || universeDomain,
398406
protosDir: path.resolve(__dirname, '../protos'),
399407
protoServices: {
400408
Operations: {

system-test/tpc-test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import {after, describe, it} from 'mocha';
15+
import {describe, it} from 'mocha';
1616
import {Spanner} from '../src';
1717
import * as assert from 'assert';
1818

0 commit comments

Comments
 (0)