Skip to content
Merged
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
4 changes: 1 addition & 3 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 Down
12 changes: 7 additions & 5 deletions handwritten/storage/src/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@
RequestResponse,
SetMetadataOptions,
} from './nodejs-common/service-object.js';
import * as r from 'teeny-request';

Check failure on line 80 in handwritten/storage/src/file.ts

View workflow job for this annotation

GitHub Actions / lint

No exported names found in module 'teeny-request'

export type GetExpirationDateResponse = [Date];
export interface GetExpirationDateCallback {
(
err: Error | null,
expirationDate?: Date | null,
apiResponse?: unknown,

Check failure on line 87 in handwritten/storage/src/file.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `,`
): void;
}

Expand All @@ -95,7 +95,7 @@
}

export type SaveData =
| string

Check failure on line 98 in handwritten/storage/src/file.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `|·string⏎··|·Buffer⏎··|·Uint8Array⏎·` with `string·|·Buffer·|·Uint8Array`
| Buffer
| Uint8Array
| PipelineSource<string | Buffer | Uint8Array>;
Expand Down Expand Up @@ -148,7 +148,7 @@
url: string;
fields: PolicyFields;
}
export interface GetSignedUrlConfig

Check failure on line 151 in handwritten/storage/src/file.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `⏎··extends·Pick<SignerGetSignedUrlConfig,·'host'·|·'signingEndpoint'` with `·extends·Pick<⏎··SignerGetSignedUrlConfig,⏎··'host'·|·'signingEndpoint'⏎`
extends Pick<SignerGetSignedUrlConfig, 'host' | 'signingEndpoint'> {
/**
* The action to permit with the signed URL.
Expand Down Expand Up @@ -304,7 +304,7 @@
| 'uri'
| 'userProject';

export interface CreateResumableUploadOptions

Check failure on line 307 in handwritten/storage/src/file.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `⏎··extends·Pick<resumableUpload.UploadConfig,·PublicResumableUploadOptions` with `·extends·Pick<⏎··resumableUpload.UploadConfig,⏎··PublicResumableUploadOptions⏎`
extends Pick<resumableUpload.UploadConfig, PublicResumableUploadOptions> {
/**
* A CRC32C to resume from when continuing a previous upload. It is recommended
Expand Down Expand Up @@ -370,7 +370,7 @@
(
err: Error | null,
destinationFile?: File | null,
apiResponse?: unknown,

Check failure on line 373 in handwritten/storage/src/file.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `,`
): void;
}

Expand Down Expand Up @@ -434,7 +434,7 @@
]
.map(r => r.source)
.join(''),
'i',

Check failure on line 437 in handwritten/storage/src/file.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `,`
);

export interface FileOptions {
Expand Down Expand Up @@ -493,7 +493,7 @@

export type DownloadCallback = (
err: RequestError | null,
contents: Buffer,

Check failure on line 496 in handwritten/storage/src/file.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `,`
) => void;

export interface DownloadOptions extends CreateReadStreamOptions {
Expand Down Expand Up @@ -570,6 +570,12 @@
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 @@
encryptionAlgorithm?: string;
keySha256?: string;
};
contexts?: {
custom: {
[key: string]: ContextValue | null;
} | null;
};
contexts?: Contexts;
customTime?: string;
eventBasedHold?: boolean | null;
readonly eventBasedHoldReleaseTime?: string;
Expand Down Expand Up @@ -1224,7 +1226,7 @@
* - if `idempotencyStrategy` is set to `RetryNever`
*/
private shouldRetryBasedOnPreconditionAndIdempotencyStrat(
options?: PreconditionOptions,

Check failure on line 1229 in handwritten/storage/src/file.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `,`
): boolean {
return !(
(options?.ifGenerationMatch === undefined &&
Expand All @@ -1238,7 +1240,7 @@

copy(
destination: string | Bucket | File,
options?: CopyOptions,

Check failure on line 1243 in handwritten/storage/src/file.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `,`
): Promise<CopyResponse>;
copy(destination: string | Bucket | File, callback: CopyCallback): void;
copy(
Expand Down Expand Up @@ -1686,7 +1688,7 @@
) => {
if (err) {
// Get error message from the body.
this.getBufferFromReadable(rawResponseStream as Readable).then(body => {

Check warning on line 1691 in handwritten/storage/src/file.ts

View workflow job for this annotation

GitHub Actions / lint

Avoid using promises inside of callbacks
err.message = body.toString('utf8');
throughStream.destroy(err);
});
Expand Down Expand Up @@ -2505,7 +2507,7 @@
});
} else {
this.getBufferFromReadable(fileStream)
.then(contents => callback?.(null, contents))

Check warning on line 2510 in handwritten/storage/src/file.ts

View workflow job for this annotation

GitHub Actions / lint

Avoid calling back inside of a promise
.catch(callback as (err: RequestError) => void);
}
}
Expand Down Expand Up @@ -2882,14 +2884,14 @@

this.storage.authClient.sign(policyBase64, options.signingEndpoint).then(
signature => {
callback(null, {

Check warning on line 2887 in handwritten/storage/src/file.ts

View workflow job for this annotation

GitHub Actions / lint

Avoid calling back inside of a promise
string: policyString,
base64: policyBase64,
signature,
});
},
err => {
callback(new SigningError(err.message));

Check warning on line 2894 in handwritten/storage/src/file.ts

View workflow job for this annotation

GitHub Actions / lint

Avoid calling back inside of a promise
},
);
}
Expand Down Expand Up @@ -4340,10 +4342,10 @@
return returnValue
.then(() => {
if (callback) {
return callback();

Check warning on line 4345 in handwritten/storage/src/file.ts

View workflow job for this annotation

GitHub Actions / lint

Avoid calling back inside of a promise
}
})
.catch(callback);

Check warning on line 4348 in handwritten/storage/src/file.ts

View workflow job for this annotation

GitHub Actions / lint

Avoid calling back inside of a promise
}
}

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
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 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import {getPackageJSON} from './package-json-helper.cjs';
import {FileMetadata} from './file';
import {FileMetadata, Contexts} from './file';

Check warning on line 22 in handwritten/storage/src/util.ts

View workflow job for this annotation

GitHub Actions / lint

'FileMetadata' is defined but never used

// Done to avoid a problem with mangling of identifiers when using esModuleInterop
const fileURLToPath = url.fileURLToPath;
Expand Down Expand Up @@ -279,10 +279,10 @@
* 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 @@

/**
* 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
Loading