Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: better typing for metadata #2234

Merged
merged 7 commits into from
Jul 24, 2023
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
6 changes: 4 additions & 2 deletions conformance-test/libraryMethods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export async function combine(options: ConformanceTestOptions) {
await allFiles.save('allfiles contents');
if (options.preconditionRequired) {
await options.bucket!.combine(sources, allFiles, {
ifGenerationMatch: allFiles.metadata.generation,
ifGenerationMatch: allFiles.metadata.generation!,
});
} else {
await options.bucket!.combine(sources, allFiles);
Expand Down Expand Up @@ -474,7 +474,9 @@ export async function copy(options: ConformanceTestOptions) {

if (options.preconditionRequired) {
await options.file!.copy('a-different-file.png', {
preconditionOpts: {ifGenerationMatch: newFile.metadata.generation},
preconditionOpts: {
ifGenerationMatch: newFile.metadata.generation!,
},
});
} else {
await options.file!.copy('a-different-file.png');
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"compressible": "^2.0.12",
"duplexify": "^4.0.0",
"ent": "^2.2.0",
"gaxios": "^5.0.0",
"gaxios": "^5.1.2",
"google-auth-library": "^8.0.1",
"mime": "^3.0.0",
"mime-types": "^2.0.8",
Expand Down Expand Up @@ -86,7 +86,7 @@
"@types/tmp": "0.2.3",
"@types/uuid": "^8.0.0",
"@types/yargs": "^17.0.10",
"c8": "^7.0.0",
"c8": "^8.0.0",
"form-data": "^4.0.0",
"gts": "^3.1.0",
"jsdoc": "^4.0.0",
Expand Down
33 changes: 24 additions & 9 deletions src/acl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import {
BodyResponseCallback,
DecorateRequestOptions,
Metadata,
BaseMetadata,
} from './nodejs-common';
import {promisifyAll} from '@google-cloud/promisify';

Expand All @@ -29,13 +29,13 @@ export interface AclOptions {

export type GetAclResponse = [
AccessControlObject | AccessControlObject[],
Metadata
AclMetadata
];
export interface GetAclCallback {
(
err: Error | null,
acl?: AccessControlObject | AccessControlObject[] | null,
apiResponse?: Metadata
apiResponse?: AclMetadata
): void;
}
export interface GetAclOptions {
Expand All @@ -50,12 +50,12 @@ export interface UpdateAclOptions {
generation?: number;
userProject?: string;
}
export type UpdateAclResponse = [AccessControlObject, Metadata];
export type UpdateAclResponse = [AccessControlObject, AclMetadata];
export interface UpdateAclCallback {
(
err: Error | null,
acl?: AccessControlObject | null,
apiResponse?: Metadata
apiResponse?: AclMetadata
): void;
}

Expand All @@ -65,17 +65,17 @@ export interface AddAclOptions {
generation?: number;
userProject?: string;
}
export type AddAclResponse = [AccessControlObject, Metadata];
export type AddAclResponse = [AccessControlObject, AclMetadata];
export interface AddAclCallback {
(
err: Error | null,
acl?: AccessControlObject | null,
apiResponse?: Metadata
apiResponse?: AclMetadata
): void;
}
export type RemoveAclResponse = [Metadata];
export type RemoveAclResponse = [AclMetadata];
export interface RemoveAclCallback {
(err: Error | null, apiResponse?: Metadata): void;
(err: Error | null, apiResponse?: AclMetadata): void;
}
export interface RemoveAclOptions {
entity: string;
Expand All @@ -94,6 +94,21 @@ export interface AccessControlObject {
projectTeam: string;
}

export interface AclMetadata extends BaseMetadata {
bucket?: string;
domain?: string;
entity?: string;
entityId?: string;
generation?: string;
object?: string;
projectTeam?: {
projectNumber?: string;
team?: 'editors' | 'owners' | 'viewers';
};
role?: 'OWNER' | 'READER' | 'WRITER' | 'FULL_CONTROL';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this strict typing in that if new fields are added in the API the node.js client will need to be updated as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/googleapis/nodejs-storage/pull/2234/files#diff-747d768492a54441f1682714c15429c572d74c031145c71672dec819ff94fbbbR109 this would act as a catch all for anything new so that it flows through without us having to make a change. However, we would obviously want to add anything new to the appropriate metadata interface to continue to support up to date typings.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the unknown too - encourages customers to validate it

[key: string]: unknown;
}

/**
* Attach functionality to a {@link Storage.acl} instance. This will add an
* object for each role group (owners, readers, and writers), with each object
Expand Down
Loading