diff --git a/handwritten/storage/CONTRIBUTING.md b/handwritten/storage/CONTRIBUTING.md index 72c44cada5e..20eafb85103 100644 --- a/handwritten/storage/CONTRIBUTING.md +++ b/handwritten/storage/CONTRIBUTING.md @@ -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 diff --git a/handwritten/storage/package.json b/handwritten/storage/package.json index c5bafbf6d79..3f1185fd4d3 100644 --- a/handwritten/storage/package.json +++ b/handwritten/storage/package.json @@ -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/", @@ -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" @@ -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", diff --git a/handwritten/storage/src/file.ts b/handwritten/storage/src/file.ts index 786998c5f4e..3d63397ed92 100644 --- a/handwritten/storage/src/file.ts +++ b/handwritten/storage/src/file.ts @@ -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; @@ -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; diff --git a/handwritten/storage/src/index.ts b/handwritten/storage/src/index.ts index f93ef6002e7..78285e22510 100644 --- a/handwritten/storage/src/index.ts +++ b/handwritten/storage/src/index.ts @@ -171,6 +171,8 @@ export { export * from './crc32c.js'; export {Channel, StopCallback} from './channel.js'; export { + Contexts, + ContextValue, CopyCallback, CopyOptions, CopyResponse, diff --git a/handwritten/storage/src/resumable-upload.ts b/handwritten/storage/src/resumable-upload.ts index df63ec637b1..271f22bca62 100644 --- a/handwritten/storage/src/resumable-upload.ts +++ b/handwritten/storage/src/resumable-upload.ts @@ -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, diff --git a/handwritten/storage/src/util.ts b/handwritten/storage/src/util.ts index 024ea95f202..3a7edf410f2 100644 --- a/handwritten/storage/src/util.ts +++ b/handwritten/storage/src/util.ts @@ -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; @@ -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)) { @@ -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 | void { diff --git a/handwritten/storage/test/resumable-upload.ts b/handwritten/storage/test/resumable-upload.ts index 6e6985878b0..9bb5fb0aa21 100644 --- a/handwritten/storage/test/resumable-upload.ts +++ b/handwritten/storage/test/resumable-upload.ts @@ -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 */ @@ -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; }); @@ -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(); }, }; @@ -2152,11 +2144,11 @@ 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; }, }; @@ -2164,7 +2156,7 @@ describe('resumable-upload', () => { up.emit('error', new Error('Error.')); setImmediate(() => { - assert.strictEqual(abortController.aborted, true); + assert.strictEqual(signal.aborted, true); done(); }); }); diff --git a/handwritten/storage/tsconfig.json b/handwritten/storage/tsconfig.json index bf65354d9fa..6b554ca2a4c 100644 --- a/handwritten/storage/tsconfig.json +++ b/handwritten/storage/tsconfig.json @@ -4,8 +4,8 @@ "rootDir": ".", "outDir": "build/esm", "resolveJsonModule": true, - "module": "es2020", - "moduleResolution": "node", + "module": "node16", + "moduleResolution": "node16", "lib": ["ES2020"], "sourceMap": false, "esModuleInterop": true,