Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions handwritten/storage/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ accept your pull requests.
# Run unit tests.
npm test

# Run sample integration tests.
npm run samples-test

# Run all system tests.
npm run system-test

Expand Down
5 changes: 1 addition & 4 deletions handwritten/storage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"storage"
],
"scripts": {
"all-test": "npm test && npm run system-test && npm run samples-test",
"all-test": "npm test && npm run system-test",
"benchwrapper": "node bin/benchwrapper.js",
"check": "gts check",
"clean": "rm -rf build/",
Expand All @@ -63,12 +63,10 @@
"precompile": "rm -rf build/",
"preconformance-test": "npm run compile:cjs -- --sourceMap",
"predocs": "npm run compile:cjs -- --sourceMap",
"prelint": "cd samples; npm link ../; npm install",
"prepare": "npm run compile",
"presystem-test:esm": "npm run compile:esm",
"presystem-test": "npm run compile -- --sourceMap",
"pretest": "npm run compile -- --sourceMap",
"samples-test": "npm link && cd samples/ && npm link ../ && npm test && cd ../",
"system-test:esm": "mkdir -p $HOME/.config && mocha build/esm/system-test --timeout 600000 --exit",
"system-test": "mkdir -p $HOME/.config && mocha build/cjs/system-test --timeout 600000 --exit",
"test": "cross-env NODE_OPTIONS=\"--require ./scripts/preload-yargs.cjs --no-deprecation\" c8 mocha build/cjs/test"
Expand All @@ -77,7 +75,6 @@
"@google-cloud/paginator": "^7.0.1",
"@google-cloud/projectify": "^6.0.1",
"@google-cloud/promisify": "^6.0.1",
"abort-controller": "^3.0.0",
"async-retry": "^1.3.3",
"duplexify": "^4.1.3",
"fast-xml-parser": "^5.3.4",
Expand Down
12 changes: 7 additions & 5 deletions handwritten/storage/src/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,12 @@ export interface ContextValue {
readonly updateTime?: string;
}

export interface Contexts {
custom: {
[key: string]: ContextValue | null;
} | null;
}

export interface FileMetadata extends BaseMetadata {
acl?: AclMetadata[] | null;
bucket?: string;
Expand All @@ -584,11 +590,7 @@ export interface FileMetadata extends BaseMetadata {
encryptionAlgorithm?: string;
keySha256?: string;
};
contexts?: {
custom: {
[key: string]: ContextValue | null;
} | null;
};
contexts?: Contexts;
customTime?: string;
eventBasedHold?: boolean | null;
readonly eventBasedHoldReleaseTime?: string;
Expand Down
2 changes: 2 additions & 0 deletions handwritten/storage/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ export {
export * from './crc32c.js';
export {Channel, StopCallback} from './channel.js';
export {
Contexts,
ContextValue,
CopyCallback,
CopyOptions,
CopyResponse,
Expand Down
1 change: 0 additions & 1 deletion handwritten/storage/src/resumable-upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import AbortController from 'abort-controller';
import {createHash} from 'crypto';
import {
GaxiosOptions,
Expand Down
12 changes: 6 additions & 6 deletions handwritten/storage/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import * as url from 'url';
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import {getPackageJSON} from './package-json-helper.cjs';
import {FileMetadata} from './file';
import {Contexts} from './file.js';

// Done to avoid a problem with mangling of identifiers when using esModuleInterop
const fileURLToPath = url.fileURLToPath;
Expand Down Expand Up @@ -279,10 +279,10 @@ export class PassThroughShim extends PassThrough {
* Double quotes (") are forbidden in context keys and values as they
* interfere with GCS filter string syntax.
*
* @param {FileMetadata['contexts']} contexts The contexts object to validate.
* @param {Contexts} [contexts] The contexts object to validate.
* @returns {void} Throws an error if validation fails.
*/
export function validateContexts(contexts?: FileMetadata['contexts']): void {
export function validateContexts(contexts?: Contexts): void {
const custom = contexts?.custom;
if (!custom) return;
for (const [key, context] of Object.entries(custom)) {
Expand All @@ -301,11 +301,11 @@ export function validateContexts(contexts?: FileMetadata['contexts']): void {

/**
* Helper to validate contexts and route errors to either a callback or a Promise.
* @param contexts The contexts to validate.
* @param callback The optional user-provided callback.
* @param {Contexts} [contexts] The contexts to validate.
* @param {Function} [callback] The optional user-provided callback.
*/
export function handleContextValidation(
contexts?: FileMetadata['contexts'],
contexts?: Contexts,
callback?: Function,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
): Promise<any> | void {
Expand Down
16 changes: 4 additions & 12 deletions handwritten/storage/test/resumable-upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,6 @@ import {FileExceptionMessages} from '../src/file.js';

nock.disableNetConnect();

class AbortController {
aborted = false;
signal = this;
abort() {
this.aborted = true;
}
}

const RESUMABLE_INCOMPLETE_STATUS_CODE = 308;
/** 256 KiB */
Expand Down Expand Up @@ -102,7 +95,6 @@ describe('resumable-upload', () => {
const keyFile = path.join(getDirName(), '../../../test/fixtures/keys.json');

before(() => {
mockery.registerMock('abort-controller', AbortController);
mockery.enable({useCleanCache: true, warnOnUnregistered: false});
upload = require('../src/resumable-upload').upload;
});
Expand Down Expand Up @@ -2142,7 +2134,7 @@ describe('resumable-upload', () => {
it('should pass a signal from the abort controller', done => {
up.authClient = {
request: (reqOpts: GaxiosOptions) => {
assert(reqOpts.signal instanceof AbortController);
assert(reqOpts.signal instanceof AbortSignal);
done();
},
};
Expand All @@ -2152,19 +2144,19 @@ describe('resumable-upload', () => {
it('should abort on an error', done => {
up.on('error', () => {});

let abortController: AbortController;
let signal: AbortSignal;
up.authClient = {
request: (reqOpts: GaxiosOptions) => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
abortController = reqOpts.signal as any;
signal = reqOpts.signal as any;
},
};

up.makeRequestStream(REQ_OPTS);
up.emit('error', new Error('Error.'));

setImmediate(() => {
assert.strictEqual(abortController.aborted, true);
assert.strictEqual(signal.aborted, true);
done();
});
});
Expand Down
4 changes: 2 additions & 2 deletions handwritten/storage/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"rootDir": ".",
"outDir": "build/esm",
"resolveJsonModule": true,
"module": "es2020",
"moduleResolution": "node",
"module": "node16",
"moduleResolution": "node16",
"lib": ["ES2020"],
"sourceMap": false,
"esModuleInterop": true,
Expand Down
Loading