Skip to content

Commit

Permalink
chore: more clean-up
Browse files Browse the repository at this point in the history
  • Loading branch information
danielbankhead committed Jun 6, 2023
1 parent 8e0b90d commit 0ddef7e
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 24 deletions.
4 changes: 2 additions & 2 deletions src/bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3269,7 +3269,7 @@ class Bucket extends ServiceObject {

// You aren't allowed to set both predefinedAcl & acl properties on a bucket
// so acl must explicitly be nullified.
const metadata = {...(options.metadata || {}), acl: null};
const metadata = {...options.metadata, acl: null};

this.setMetadata(metadata, query, err => {
if (err) {
Expand Down Expand Up @@ -3513,7 +3513,7 @@ class Bucket extends ServiceObject {
callback?: BodyResponseCallback
): void | Promise<[ResponseBody, Metadata]> {
if (this.userProject && (!reqOpts.qs || !reqOpts.qs.userProject)) {
reqOpts.qs = {...(reqOpts.qs || {}), userProject: this.userProject};
reqOpts.qs = {...reqOpts.qs, userProject: this.userProject};
}
return super.request(reqOpts, callback!);
}
Expand Down
39 changes: 19 additions & 20 deletions src/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1150,14 +1150,14 @@ class File extends ServiceObject<File> {
throw noDestinationError;
}

let options: ReadonlyOptions<CopyOptions> = {};
let userOptions: ReadonlyOptions<CopyOptions> = {};
if (typeof optionsOrCallback === 'function') {
callback = optionsOrCallback;
} else if (optionsOrCallback) {
options = optionsOrCallback;
userOptions = optionsOrCallback;
}

const payload = {...options};
const options = {...userOptions};

callback = callback || util.noop;

Expand Down Expand Up @@ -1189,16 +1189,16 @@ class File extends ServiceObject<File> {
if (this.generation !== undefined) {
query.sourceGeneration = this.generation;
}
if (options.token !== undefined) {
query.rewriteToken = options.token;
if (userOptions.token !== undefined) {
query.rewriteToken = userOptions.token;
}
if (options.userProject !== undefined) {
query.userProject = options.userProject;
delete payload.userProject;
if (userOptions.userProject !== undefined) {
query.userProject = userOptions.userProject;
delete options.userProject;
}
if (options.predefinedAcl !== undefined) {
query.destinationPredefinedAcl = options.predefinedAcl;
delete payload.predefinedAcl;
if (userOptions.predefinedAcl !== undefined) {
query.destinationPredefinedAcl = userOptions.predefinedAcl;
delete options.predefinedAcl;
}

newFile = newFile! || destBucket.file(destName);
Expand All @@ -1214,9 +1214,9 @@ class File extends ServiceObject<File> {

if (newFile.encryptionKey !== undefined) {
this.setEncryptionKey(newFile.encryptionKey!);
} else if (options.destinationKmsKeyName !== undefined) {
query.destinationKmsKeyName = options.destinationKmsKeyName;
delete payload.destinationKmsKeyName;
} else if (userOptions.destinationKmsKeyName !== undefined) {
query.destinationKmsKeyName = userOptions.destinationKmsKeyName;
delete options.destinationKmsKeyName;
} else if (newFile.kmsKeyName !== undefined) {
query.destinationKmsKeyName = newFile.kmsKeyName;
}
Expand All @@ -1234,15 +1234,15 @@ class File extends ServiceObject<File> {

if (
!this.shouldRetryBasedOnPreconditionAndIdempotencyStrat(
options?.preconditionOpts
userOptions?.preconditionOpts
)
) {
this.storage.retryOptions.autoRetry = false;
}

if (options.preconditionOpts?.ifGenerationMatch !== undefined) {
query.ifGenerationMatch = options.preconditionOpts?.ifGenerationMatch;
delete payload.preconditionOpts;
if (userOptions.preconditionOpts?.ifGenerationMatch !== undefined) {
query.ifGenerationMatch = userOptions.preconditionOpts?.ifGenerationMatch;
delete options.preconditionOpts;
}

this.request(
Expand All @@ -1252,7 +1252,7 @@ class File extends ServiceObject<File> {
newFile.name
)}`,
qs: query,
json: payload,
json: options,
headers,
},
(err, resp) => {
Expand Down Expand Up @@ -3072,7 +3072,6 @@ class File extends ServiceObject<File> {
// You aren't allowed to set both predefinedAcl & acl properties on a file,
// so acl must explicitly be nullified, destroying all previous acls on the
// file.

const metadata = {...options.metadata, acl: null};

this.setMetadata(metadata, query, callback!);
Expand Down
5 changes: 4 additions & 1 deletion src/nodejs-common/service-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,10 @@ class ServiceObject<T = any> extends EventEmitter {
method: 'PATCH',
uri: '',
...methodConfig.reqOpts,
json: {...metadata} as ReadonlyOptions<Metadata>,
json: {
...methodConfig.reqOpts?.json,
...metadata,
} as ReadonlyOptions<Metadata>,
qs: {
...methodConfig.reqOpts?.qs,
...options,
Expand Down
6 changes: 5 additions & 1 deletion src/nodejs-common/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ export class Util {
callback = callback || util.noop;

const parsedResp = {
err: err || undefined,
err: err || null,
...(resp && util.parseHttpRespMessage(resp)),
...(body && util.parseHttpRespBody(body)),
};
Expand Down Expand Up @@ -515,6 +515,10 @@ export class Util {
const reqOpts = {
...defaultReqOpts,
...options.request,
qs: {
...defaultReqOpts.qs,
...options.request?.qs,
},
multipart: [
{
'Content-Type': 'application/json',
Expand Down
9 changes: 9 additions & 0 deletions src/resumable-upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,12 @@ export class Upload extends Writable {
const combinedReqOpts = {
...this.customRequestOptions,
...reqOpts,
headers: {
...this.customRequestOptions.headers,
...reqOpts.headers,
},
};

const res = await this.authClient.request<{error?: object}>(
combinedReqOpts
);
Expand All @@ -983,6 +988,10 @@ export class Upload extends Writable {
const combinedReqOpts = {
...this.customRequestOptions,
...reqOpts,
headers: {
...this.customRequestOptions.headers,
...reqOpts.headers,
},
};
const res = await this.authClient.request(combinedReqOpts);
const successfulRequest = this.onResponse(res);
Expand Down

0 comments on commit 0ddef7e

Please sign in to comment.