Skip to content

Commit

Permalink
docs: Document CRC32CValidator (#2006)
Browse files Browse the repository at this point in the history
* docs: Document `CRC32CValidator` in `Storage`

* fix: `@private` value warning

* docs: Update parameter names

* docs: `CRC32CValidator` documentation
  • Loading branch information
danielbankhead committed Jul 19, 2022
1 parent 9b1c4b3 commit f9c7f89
Show file tree
Hide file tree
Showing 4 changed files with 193 additions and 5 deletions.
66 changes: 65 additions & 1 deletion src/bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,70 @@ export enum BucketExceptionMessages {
SUPPLY_NOTIFICATION_ID = 'You must supply a notification ID.',
}

/**
* @callback Crc32cGeneratorToStringCallback
* A method returning the CRC32C as a base64-encoded string.
*
* @returns {string}
*
* @example
* Hashing the string 'data' should return 'rth90Q=='
*
* ```js
* const buffer = Buffer.from('data');
* crc32c.update(buffer);
* crc32c.toString(); // 'rth90Q=='
* ```
**/
/**
* @callback Crc32cGeneratorValidateCallback
* A method validating a base64-encoded CRC32C string.
*
* @param {string} [value] base64-encoded CRC32C string to validate
* @returns {boolean}
*
* @example
* Should return `true` if the value matches, `false` otherwise
*
* ```js
* const buffer = Buffer.from('data');
* crc32c.update(buffer);
* crc32c.validate('DkjKuA=='); // false
* crc32c.validate('rth90Q=='); // true
* ```
**/
/**
* @callback Crc32cGeneratorUpdateCallback
* A method for passing `Buffer`s for CRC32C generation.
*
* @param {Buffer} [data] data to update CRC32C value with
* @returns {undefined}
*
* @example
* Hashing buffers from 'some ' and 'text\n'
*
* ```js
* const buffer1 = Buffer.from('some ');
* crc32c.update(buffer1);
*
* const buffer2 = Buffer.from('text\n');
* crc32c.update(buffer2);
*
* crc32c.toString(); // 'DkjKuA=='
* ```
**/
/**
* @typedef {object} CRC32CValidator
* @property {Crc32cGeneratorToStringCallback}
* @property {Crc32cGeneratorValidateCallback}
* @property {Crc32cGeneratorUpdateCallback}
*/
/**
* A function that generates a CRC32C Validator. Defaults to {@link CRC32C}
*
* @name Bucket#crc32cGenerator
* @type {CRC32CValidator}
*/
/**
* Get and set IAM policies for your bucket.
*
Expand Down Expand Up @@ -708,7 +772,7 @@ class Bucket extends ServiceObject {
},
},
/**
* @typedef {object} DeleteBucketOptions Configuration options.
* IamDeleteBucketOptions Configuration options.
* @property {boolean} [ignoreNotFound = false] Ignore an error if
* the bucket does not exist.
* @property {string} [userProject] The ID of the project which will be
Expand Down
4 changes: 2 additions & 2 deletions src/crc32c.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ interface CRC32CValidator {
* crc32c.validate('rth90Q=='); // true
* ```
*/
validate: (o: string) => boolean;
validate: (value: string) => boolean;
/**
* A method for passing `Buffer`s for CRC32C generation.
*
Expand All @@ -108,7 +108,7 @@ interface CRC32CValidator {
* crc32c.toString(); // 'DkjKuA=='
* ```
*/
update: (b: Buffer) => void;
update: (data: Buffer) => void;
}

/** A function that generates a CRC32C Validator */
Expand Down
65 changes: 63 additions & 2 deletions src/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,13 +278,11 @@ export enum ActionToHTTPMethod {
}

/**
* @const {string}
* @private
*/
export const STORAGE_POST_POLICY_BASE_URL = 'https://storage.googleapis.com';

/**
* @const {RegExp}
* @private
*/
const GS_URL_REGEXP = /^gs:\/\/([a-z0-9_.-]+)\/(.+)$/;
Expand Down Expand Up @@ -500,6 +498,68 @@ class File extends ServiceObject<File> {
* @name File#name
* @type {string}
*/
/**
* @callback Crc32cGeneratorToStringCallback
* A method returning the CRC32C as a base64-encoded string.
*
* @returns {string}
*
* @example
* Hashing the string 'data' should return 'rth90Q=='
*
* ```js
* const buffer = Buffer.from('data');
* crc32c.update(buffer);
* crc32c.toString(); // 'rth90Q=='
* ```
**/
/**
* @callback Crc32cGeneratorValidateCallback
* A method validating a base64-encoded CRC32C string.
*
* @param {string} [value] base64-encoded CRC32C string to validate
* @returns {boolean}
*
* @example
* Should return `true` if the value matches, `false` otherwise
*
* ```js
* const buffer = Buffer.from('data');
* crc32c.update(buffer);
* crc32c.validate('DkjKuA=='); // false
* crc32c.validate('rth90Q=='); // true
* ```
**/
/**
* @callback Crc32cGeneratorUpdateCallback
* A method for passing `Buffer`s for CRC32C generation.
*
* @param {Buffer} [data] data to update CRC32C value with
* @returns {undefined}
*
* @example
* Hashing buffers from 'some ' and 'text\n'
*
* ```js
* const buffer1 = Buffer.from('some ');
* crc32c.update(buffer1);
*
* const buffer2 = Buffer.from('text\n');
* crc32c.update(buffer2);
*
* crc32c.toString(); // 'DkjKuA=='
* ```
**/
/**
* @typedef {object} CRC32CValidator
* @property {Crc32cGeneratorToStringCallback}
* @property {Crc32cGeneratorValidateCallback}
* @property {Crc32cGeneratorUpdateCallback}
*/
/**
* @callback Crc32cGeneratorCallback
* @returns {CRC32CValidator}
*/
/**
* @typedef {object} FileOptions Options passed to the File constructor.
* @property {string} [encryptionKey] A custom encryption key.
Expand All @@ -509,6 +569,7 @@ class File extends ServiceObject<File> {
* usable only by enabled projects.
* @property {string} [userProject] The ID of the project which will be
* billed for all requests made from File object.
* @property {Crc32cGeneratorCallback} [callback] A function that generates a CRC32C Validator. Defaults to {@link CRC32C}
*/
/**
* Constructs a file object.
Expand Down
63 changes: 63 additions & 0 deletions src/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,68 @@ export class Storage extends Service {

retryOptions: RetryOptions;

/**
* @callback Crc32cGeneratorToStringCallback
* A method returning the CRC32C as a base64-encoded string.
*
* @returns {string}
*
* @example
* Hashing the string 'data' should return 'rth90Q=='
*
* ```js
* const buffer = Buffer.from('data');
* crc32c.update(buffer);
* crc32c.toString(); // 'rth90Q=='
* ```
**/
/**
* @callback Crc32cGeneratorValidateCallback
* A method validating a base64-encoded CRC32C string.
*
* @param {string} [value] base64-encoded CRC32C string to validate
* @returns {boolean}
*
* @example
* Should return `true` if the value matches, `false` otherwise
*
* ```js
* const buffer = Buffer.from('data');
* crc32c.update(buffer);
* crc32c.validate('DkjKuA=='); // false
* crc32c.validate('rth90Q=='); // true
* ```
**/
/**
* @callback Crc32cGeneratorUpdateCallback
* A method for passing `Buffer`s for CRC32C generation.
*
* @param {Buffer} [data] data to update CRC32C value with
* @returns {undefined}
*
* @example
* Hashing buffers from 'some ' and 'text\n'
*
* ```js
* const buffer1 = Buffer.from('some ');
* crc32c.update(buffer1);
*
* const buffer2 = Buffer.from('text\n');
* crc32c.update(buffer2);
*
* crc32c.toString(); // 'DkjKuA=='
* ```
**/
/**
* @typedef {object} CRC32CValidator
* @property {Crc32cGeneratorToStringCallback}
* @property {Crc32cGeneratorValidateCallback}
* @property {Crc32cGeneratorUpdateCallback}
*/
/**
* @callback Crc32cGeneratorCallback
* @returns {CRC32CValidator}
*/
/**
* @typedef {object} StorageOptions
* @property {string} [projectId] The project ID from the Google Developer's
Expand Down Expand Up @@ -536,6 +598,7 @@ export class Storage extends Service {
* @property {object[]} [interceptors_] Array of custom request interceptors to be returned in the order they were assigned.
* @property {string} [apiEndpoint = storage.google.com] The API endpoint of the service used to make requests.
* @property {boolean} [useAuthWithCustomEndpoint = false] Controls whether or not to use authentication when using a custom endpoint.
* @property {Crc32cGeneratorCallback} [callback] A function that generates a CRC32C Validator. Defaults to {@link CRC32C}
*/
/**
* Constructs the Storage client.
Expand Down

0 comments on commit f9c7f89

Please sign in to comment.