Skip to content
Draft
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
13 changes: 13 additions & 0 deletions handwritten/storage/cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion handwritten/storage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
40 changes: 40 additions & 0 deletions handwritten/storage/src/file-errors.ts
Original file line number Diff line number Diff line change
@@ -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.',
}
30 changes: 3 additions & 27 deletions handwritten/storage/src/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}
Expand All @@ -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}.
Expand Down
2 changes: 1 addition & 1 deletion handwritten/storage/src/hash-stream-validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`. */
Expand Down
3 changes: 2 additions & 1 deletion handwritten/storage/src/resumable-upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions handwritten/storage/src/transfer-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Loading