Skip to content

Commit

Permalink
remove teeny-request and retry request from deps
Browse files Browse the repository at this point in the history
  • Loading branch information
ddelgrosso1 committed Jul 15, 2024
1 parent ccb10d9 commit 7e0a12c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 88 deletions.
4 changes: 0 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@
},
"dependencies": {
"@google-cloud/paginator": "^5.0.0",
"@google-cloud/projectify": "^4.0.0",
"@google-cloud/promisify": "^4.0.0",
"abort-controller": "^3.0.0",
"async-retry": "^1.3.3",
Expand All @@ -84,8 +83,6 @@
"html-entities": "^2.5.2",
"mime": "^3.0.0",
"p-limit": "^3.0.1",
"retry-request": "^7.0.0",
"teeny-request": "^9.0.0",
"uuid": "^8.0.0"
},
"devDependencies": {
Expand All @@ -102,7 +99,6 @@
"@types/node": "^20.4.4",
"@types/node-fetch": "^2.1.3",
"@types/proxyquire": "^1.3.28",
"@types/request": "^2.48.4",
"@types/sinon": "^17.0.3",
"@types/tmp": "0.2.6",
"@types/uuid": "^8.0.0",
Expand Down
19 changes: 19 additions & 0 deletions src/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import {
ResponseBody,
Duplexify,
GCCL_GCS_CMD_KEY,
ProgressStream,
} from './nodejs-common/util.js';
import duplexify from 'duplexify';
import {
Expand Down Expand Up @@ -4241,6 +4242,24 @@ class File extends ServiceObject<File, FileMetadata> {
options.preconditionOpts
);

const writeStream = new ProgressStream();
writeStream.on('progress', evt => dup.emit('progress', evt));
dup.setWritable(writeStream);

reqOpts.multipart = [
{
headers: {'Content-Type': 'application/json'},
content: JSON.stringify(options.metadata),
},
{
headers: {
'Content-Type':
options.metadata.contentType || 'application/octet-stream',
},
content: writeStream,
},
];

this.storageTransport.makeRequest(
reqOpts as StorageRequestOptions,
(err, body, resp) => {
Expand Down
85 changes: 1 addition & 84 deletions src/nodejs-common/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import {
// @ts-ignore
import {getPackageJSON} from '../package-json-helper.cjs';
import {GaxiosError, GaxiosResponse} from 'gaxios';
import {StorageRequestOptions} from '../storage-transport.js';

const packageJson = getPackageJSON();

Expand Down Expand Up @@ -174,88 +173,6 @@ export class Util {
*/
noop() {}

/**
* Take a Duplexify stream, fetch an authenticated connection header, and
* create an outgoing writable stream.
*
* @param {Duplexify} dup - Duplexify stream.
* @param {object} options - Configuration object.
* @param {module:common/connection} options.connection - A connection instance used to get a token with and send the request through.
* @param {object} options.metadata - Metadata to send at the head of the request.
* @param {object} options.request - Request object, in the format of a standard Node.js http.request() object.
* @param {string=} options.request.method - Default: "POST".
* @param {string=} options.request.qs.uploadType - Default: "multipart".
* @param {string=} options.streamContentType - Default: "application/octet-stream".
* @param {function} onComplete - Callback, executed after the writable Request stream has completed.
*/
makeWritableStream(
dup: Duplexify,
options: StorageRequestOptions,
onComplete?: Function
) {
onComplete = onComplete || util.noop;

const writeStream = new ProgressStream();
writeStream.on('progress', evt => dup.emit('progress', evt));
dup.setWritable(writeStream);

const defaultReqOpts = {
method: 'POST',
qs: {
uploadType: 'multipart',
},
timeout: 0,
maxRetries: 0,
};

//const metadata = options.metadata || {};

/* const reqOpts = {
...defaultReqOpts,
...options.request,
qs: {
...defaultReqOpts.qs,
...options.request?.qs,
},
multipart: [
{
'Content-Type': 'application/json',
body: JSON.stringify(metadata),
},
{
'Content-Type': metadata.contentType || 'application/octet-stream',
body: writeStream,
},
],
} as {} as r.OptionsWithUri & {
[GCCL_GCS_CMD_KEY]?: string;
}; */

/* options.makeAuthenticatedRequest(reqOpts, {
onAuthenticated(err, authenticatedReqOpts) {
if (err) {
dup.destroy(err);
return;
}
requestDefaults.headers = util._getDefaultHeaders(
reqOpts[GCCL_GCS_CMD_KEY]
);
const request = teenyRequest.defaults(requestDefaults);
request(authenticatedReqOpts!, (err, resp, body) => {
util.handleResp(err, resp, body, (err, data) => {
if (err) {
dup.destroy(err);
return;
}
dup.emit('response', resp);
onComplete!(data);
});
});
},
}); */
}

/**
* Returns true if the API request should be retried, given the error that was
* given the first time the request was attempted. This is used for rate limit
Expand Down Expand Up @@ -353,7 +270,7 @@ export class Util {
* Basic Passthrough Stream that records the number of bytes read
* every time the cursor is moved.
*/
class ProgressStream extends Transform {
export class ProgressStream extends Transform {
bytesRead = 0;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
_transform(chunk: any, encoding: string, callback: Function) {
Expand Down

0 comments on commit 7e0a12c

Please sign in to comment.