Skip to content

Commit aae702b

Browse files
committed
refactor: simplify sourcemap compilation scripts and add optional chaining for idempotency token access
1 parent b05b477 commit aae702b

2 files changed

Lines changed: 11 additions & 10 deletions

File tree

handwritten/storage/package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,21 @@
5454
"compile:cjs": "tsc -p ./tsconfig.cjs.json",
5555
"compile:esm": "tsc -p .",
5656
"compile": "npm run compile:cjs && npm run compile:esm",
57+
"compile:sourcemaps": "npm run compile:cjs -- --sourceMap && npm run compile:esm -- --sourceMap",
5758
"conformance-test": "mocha --parallel build/cjs/conformance-test/ --require build/cjs/conformance-test/globalHooks.js",
5859
"docs": "jsdoc -c .jsdoc.json",
5960
"fix": "gts fix",
6061
"lint": "gts check",
6162
"postcompile": "cp ./src/package-json-helper.cjs ./build/cjs/src && cp ./src/package-json-helper.cjs ./build/esm/src",
6263
"postcompile:cjs": "babel --plugins gapic-tools/build/src/replaceImportMetaUrl,gapic-tools/build/src/toggleESMFlagVariable build/cjs/src/util.js -o build/cjs/src/util.js && cp internal-tooling/helpers/package.cjs.json build/cjs/package.json",
6364
"precompile": "rm -rf build/",
64-
"preconformance-test": "npm run compile:cjs -- --sourceMap",
65-
"predocs": "npm run compile:cjs -- --sourceMap",
65+
"preconformance-test": "npm run compile:sourcemaps",
66+
"predocs": "npm run compile:sourcemaps",
6667
"prelint": "cd samples; npm link ../; npm install",
6768
"prepare": "npm run compile",
6869
"presystem-test:esm": "npm run compile:esm",
69-
"presystem-test": "npm run compile -- --sourceMap",
70-
"pretest": "npm run compile -- --sourceMap",
70+
"presystem-test": "npm run compile:sourcemaps",
71+
"pretest": "npm run compile:sourcemaps",
7172
"samples-test": "npm link && cd samples/ && npm link ../ && npm test && cd ../",
7273
"system-test:esm": "mkdir -p $HOME/.config && mocha build/esm/system-test --timeout 600000 --exit",
7374
"system-test": "mkdir -p $HOME/.config && mocha build/cjs/system-test --timeout 600000 --exit",

handwritten/storage/src/resumable-upload.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -810,11 +810,11 @@ export class Upload extends Writable {
810810
delete metadata.contentType;
811811
}
812812

813-
const userTokenKey = Object.keys(this.customRequestOptions.headers || {}).find(
813+
const userTokenKey = Object.keys(this.customRequestOptions?.headers || {}).find(
814814
key => key.toLowerCase() === 'x-goog-gcs-idempotency-token'
815815
);
816816
if (userTokenKey) {
817-
this.currentInvocationId.uri = this.customRequestOptions.headers![userTokenKey] as string;
817+
this.currentInvocationId.uri = this.customRequestOptions?.headers?.[userTokenKey] as string;
818818
}
819819

820820
let googAPIClient = `${getRuntimeTrackingString()} gccl/${
@@ -1010,11 +1010,11 @@ export class Upload extends Writable {
10101010
},
10111011
});
10121012

1013-
const userTokenKey = Object.keys(this.customRequestOptions.headers || {}).find(
1013+
const userTokenKey = Object.keys(this.customRequestOptions?.headers || {}).find(
10141014
key => key.toLowerCase() === 'x-goog-gcs-idempotency-token'
10151015
);
10161016
if (userTokenKey) {
1017-
this.currentInvocationId.chunk = this.customRequestOptions.headers![userTokenKey] as string;
1017+
this.currentInvocationId.chunk = this.customRequestOptions?.headers?.[userTokenKey] as string;
10181018
}
10191019

10201020
let googAPIClient = `${getRuntimeTrackingString()} gccl/${
@@ -1235,11 +1235,11 @@ export class Upload extends Writable {
12351235
async checkUploadStatus(
12361236
config: CheckUploadStatusConfig = {},
12371237
): Promise<GaxiosResponse<FileMetadata | void>> {
1238-
const userTokenKey = Object.keys(this.customRequestOptions.headers || {}).find(
1238+
const userTokenKey = Object.keys(this.customRequestOptions?.headers || {}).find(
12391239
key => key.toLowerCase() === 'x-goog-gcs-idempotency-token'
12401240
);
12411241
if (userTokenKey) {
1242-
this.currentInvocationId.checkUploadStatus = this.customRequestOptions.headers![userTokenKey] as string;
1242+
this.currentInvocationId.checkUploadStatus = this.customRequestOptions?.headers?.[userTokenKey] as string;
12431243
}
12441244

12451245
let googAPIClient = `${getRuntimeTrackingString()} gccl/${

0 commit comments

Comments
 (0)