diff --git a/handwritten/storage/cloudbuild.yaml b/handwritten/storage/cloudbuild.yaml index 422da01004fe..b33a059de078 100644 --- a/handwritten/storage/cloudbuild.yaml +++ b/handwritten/storage/cloudbuild.yaml @@ -37,6 +37,19 @@ steps: # - name: 'sa-keys' # path: '/secrets' +# 3. Run ESM system tests +- name: 'node:24' + entrypoint: 'bash' + args: + - '-c' + - | + corepack enable pnpm && pnpm run system-test:esm + dir: 'handwritten/storage' + env: + - 'GCLOUD_PROJECT=${_GCP_PROJECT_ID}' + id: 'run-system-tests-esm' + waitFor: ['run-system-tests'] + # If you use Secret Manager for credentials, uncomment and configure: # availableSecrets: # secretManager: diff --git a/handwritten/storage/package.json b/handwritten/storage/package.json index 183ea48afd7f..a4b94d1131d2 100644 --- a/handwritten/storage/package.json +++ b/handwritten/storage/package.json @@ -58,8 +58,9 @@ "docs-test": "linkinator docs", "fix": "gts fix", "lint": "gts check", - "postcompile": "cp ./src/package-json-helper.cjs ./build/cjs/src && cp ./src/package-json-helper.cjs ./build/esm/src", + "postcompile": "cp ./src/package-json-helper.cjs ./build/cjs/src", "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", + "postcompile:esm": "cp ./src/package-json-helper.cjs ./build/esm/src", "precompile": "rm -rf build/", "preconformance-test": "pnpm run compile:cjs --sourceMap", "predocs": "pnpm run compile:cjs --sourceMap", diff --git a/handwritten/storage/src/file-errors.ts b/handwritten/storage/src/file-errors.ts new file mode 100644 index 000000000000..f0b42de21d4f --- /dev/null +++ b/handwritten/storage/src/file-errors.ts @@ -0,0 +1,40 @@ +// Copyright 2026 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +export class RequestError extends Error { + code?: string; + errors?: Error[]; +} + +export enum FileExceptionMessages { + EXPIRATION_TIME_NA = 'An expiration time is not available.', + DESTINATION_NO_NAME = 'Destination file should have a name.', + INVALID_VALIDATION_FILE_RANGE = 'Cannot use validation with file ranges (start/end).', + MD5_NOT_AVAILABLE = 'MD5 verification was specified, but is not available for the requested object. MD5 is not available for composite objects.', + EQUALS_CONDITION_TWO_ELEMENTS = 'Equals condition must be an array of 2 elements.', + STARTS_WITH_TWO_ELEMENTS = 'StartsWith condition must be an array of 2 elements.', + CONTENT_LENGTH_RANGE_MIN_MAX = 'ContentLengthRange must have numeric min & max fields.', + DOWNLOAD_MISMATCH = 'The downloaded data did not match the data from the server. To be sure the content is the same, you should download the file again.', + UPLOAD_MISMATCH_DELETE_FAIL = `The uploaded data did not match the data from the server. + As a precaution, we attempted to delete the file, but it was not successful. + To be sure the content is the same, you should try removing the file manually, + then uploading the file again. + \n\nThe delete attempt failed with this message:\n\n `, + UPLOAD_MISMATCH = `The uploaded data did not match the data from the server. + As a precaution, the file has been deleted. + To be sure the content is the same, you should try uploading the file again.`, + MD5_RESUMED_UPLOAD = 'MD5 cannot be used with a continued resumable upload as MD5 cannot be extended from an existing value', + MISSING_RESUME_CRC32C_FINAL_UPLOAD = 'The CRC32C is missing for the final portion of a resumed upload, which is required for validation. Please provide `resumeCRC32C` if validation is required, or disable `validation`.', + STREAM_NOT_AVAILABLE = 'Stream was not provided.', +} diff --git a/handwritten/storage/src/file.ts b/handwritten/storage/src/file.ts index 9cbd6ee75785..1055720c6230 100644 --- a/handwritten/storage/src/file.ts +++ b/handwritten/storage/src/file.ts @@ -86,6 +86,9 @@ import { StorageQueryParameters, StorageRequestOptions, } from './storage-transport.js'; +import {FileExceptionMessages, RequestError} from './file-errors.js'; + +export {RequestError, FileExceptionMessages} from './file-errors.js'; export type GetExpirationDateResponse = [Date]; export interface GetExpirationDateCallback { @@ -646,11 +649,6 @@ export interface FileMetadata extends BaseMetadata { updated?: string; } -export class RequestError extends Error { - code?: string; - errors?: Error[]; -} - export interface RewriteResponse { rewriteToken?: string; } @@ -660,28 +658,6 @@ const GS_UTIL_URL_REGEX = /(gs):\/\/([a-z0-9_.-]+)\/(.+)/g; const HTTPS_PUBLIC_URL_REGEX = /(https):\/\/(storage\.googleapis\.com)\/([a-z0-9_.-]+)\/(.+)/g; -export enum FileExceptionMessages { - EXPIRATION_TIME_NA = 'An expiration time is not available.', - DESTINATION_NO_NAME = 'Destination file should have a name.', - INVALID_VALIDATION_FILE_RANGE = 'Cannot use validation with file ranges (start/end).', - MD5_NOT_AVAILABLE = 'MD5 verification was specified, but is not available for the requested object. MD5 is not available for composite objects.', - EQUALS_CONDITION_TWO_ELEMENTS = 'Equals condition must be an array of 2 elements.', - STARTS_WITH_TWO_ELEMENTS = 'StartsWith condition must be an array of 2 elements.', - CONTENT_LENGTH_RANGE_MIN_MAX = 'ContentLengthRange must have numeric min & max fields.', - DOWNLOAD_MISMATCH = 'The downloaded data did not match the data from the server. To be sure the content is the same, you should download the file again.', - UPLOAD_MISMATCH_DELETE_FAIL = `The uploaded data did not match the data from the server. - As a precaution, we attempted to delete the file, but it was not successful. - To be sure the content is the same, you should try removing the file manually, - then uploading the file again. - \n\nThe delete attempt failed with this message:\n\n `, - UPLOAD_MISMATCH = `The uploaded data did not match the data from the server. - As a precaution, the file has been deleted. - To be sure the content is the same, you should try uploading the file again.`, - MD5_RESUMED_UPLOAD = 'MD5 cannot be used with a continued resumable upload as MD5 cannot be extended from an existing value', - MISSING_RESUME_CRC32C_FINAL_UPLOAD = 'The CRC32C is missing for the final portion of a resumed upload, which is required for validation. Please provide `resumeCRC32C` if validation is required, or disable `validation`.', - STREAM_NOT_AVAILABLE = 'Stream was not provided.', -} - /** * A File object is created from your {@link Bucket} object using * {@link Bucket#file}. diff --git a/handwritten/storage/src/hash-stream-validator.ts b/handwritten/storage/src/hash-stream-validator.ts index b41dd51b6dcd..4a908fe7317c 100644 --- a/handwritten/storage/src/hash-stream-validator.ts +++ b/handwritten/storage/src/hash-stream-validator.ts @@ -20,7 +20,7 @@ import { CRC32C_DEFAULT_VALIDATOR_GENERATOR, CRC32CValidator, } from './crc32c.js'; -import {FileExceptionMessages, RequestError} from './file.js'; +import {FileExceptionMessages, RequestError} from './file-errors.js'; interface HashStreamValidatorOptions { /** Enables CRC32C calculation. To validate a provided value use `crc32cExpected`. */ diff --git a/handwritten/storage/src/resumable-upload.ts b/handwritten/storage/src/resumable-upload.ts index de3661951bfc..e7f76e4da33f 100644 --- a/handwritten/storage/src/resumable-upload.ts +++ b/handwritten/storage/src/resumable-upload.ts @@ -29,7 +29,8 @@ import AsyncRetry from 'async-retry'; import {RetryOptions, PreconditionOptions} from './storage.js'; import * as crypto from 'crypto'; import {GCCL_GCS_CMD_KEY, decorateHeaders} from './nodejs-common/util.js'; -import {FileExceptionMessages, FileMetadata, RequestError} from './file.js'; +import type {FileMetadata} from './file.js'; +import {FileExceptionMessages, RequestError} from './file-errors.js'; import {HashStreamValidator} from './hash-stream-validator.js'; const NOT_FOUND_STATUS_CODE = 404; diff --git a/handwritten/storage/src/transfer-manager.ts b/handwritten/storage/src/transfer-manager.ts index ac0c080bac41..a4b06b7c8bed 100644 --- a/handwritten/storage/src/transfer-manager.ts +++ b/handwritten/storage/src/transfer-manager.ts @@ -20,10 +20,9 @@ import { DownloadResponse, DownloadResponseWithStatus, File, - FileExceptionMessages, - RequestError, SkipReason, } from './file.js'; +import {FileExceptionMessages, RequestError} from './file-errors.js'; import * as path from 'path'; import {createReadStream, existsSync, promises as fsp} from 'fs'; import {CRC32C} from './crc32c.js';