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

refactor(typescript): various fixes/refactors to types #515

Merged
merged 5 commits into from
Mar 2, 2019
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
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@
"prepare": "npm run compile",
"pretest": "npm run compile",
"proto": "npm run proto:pubsub",
"proto:pubsub": "mkdir -p proto && pbjs -t static-module -w commonjs -p protos google/pubsub/v1/pubsub.proto | pbts -o proto/pubsub.d.ts -",
"proto:pubsub": "pbjs -t static-module -w commonjs -p protos google/pubsub/v1/pubsub.proto | pbts -o proto/pubsub.d.ts -",
"proto:iam": "pbjs -t static-module -w commonjs -p protos google/iam/v1/iam_policy.proto | pbts -o proto/iam.d.ts -",
"proto-types": "mkdir -p proto && npm run proto:pubsub && npm run proto:iam",
"docs-test": "linkinator docs -r --skip www.googleapis.com",
"predocs-test": "npm run docs"
},
Expand Down
4,074 changes: 4,074 additions & 0 deletions proto/iam.d.ts

Large diffs are not rendered by default.

67 changes: 16 additions & 51 deletions src/iam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,21 @@
import {promisifyAll} from '@google-cloud/promisify';
import * as arrify from 'arrify';
import {CallOptions} from 'google-gax';
import {PubSub} from '.';

export interface GetPolicyCallback {
(err?: Error|null, acl?: Policy|null): void;
}
import {google} from '../proto/iam';

export interface SetPolicyCallback {
(err?: Error|null, acl?: Policy|null): void;
}
import {Omit, PubSub, RequestCallback, ResourceCallback} from '.';

export type Policy = {
etag?: string|Buffer
}&Omit<google.iam.v1.IPolicy, 'etag'>;

export type GetPolicyCallback = RequestCallback<Policy>;
export type SetPolicyCallback = RequestCallback<Policy>;

export type SetPolicyResponse = [Policy];
export type GetPolicyResponse = [Policy];

export interface PermissionsResponse {
permissions: string|string[];
}

/**
* Shows which IAM permissions is allowed.
* The key to this object are the IAM permissions (string) and the values are
Expand All @@ -47,43 +45,10 @@ export type IamPermissionsMap = {
[key: string]: boolean
};

export type TestIamPermissionsResponse = [PermissionsResponse];

export interface TestIamPermissionsCallback {
(err?: Error|null, permissions?: IamPermissionsMap|null,
apiResponse?: PermissionsResponse): void;
}

/**
* @see https://cloud.google.com/pubsub/docs/reference/rest/v1/Policy#Expr
*/
export interface Expr {
expression: string;
title: string;
description: string;
location: string;
}

/**
* @see https://cloud.google.com/pubsub/docs/reference/rest/v1/Policy#Binding
*/
export interface Binding {
role: string;
members: string[];
condition?: Expr;
}

/**
* @see https://cloud.google.com/pubsub/docs/reference/rest/v1/Policy
*/
export interface Policy {
/**
* @deprecated
*/
version?: number;
etag?: string;
bindings: Binding[];
}
export type TestIamPermissionsResponse =
[IamPermissionsMap, google.iam.v1.ITestIamPermissionsResponse];
export type TestIamPermissionsCallback = ResourceCallback<
IamPermissionsMap, google.iam.v1.ITestIamPermissionsResponse>;

/**
* [IAM (Identity and Access
Expand Down Expand Up @@ -282,7 +247,7 @@ export class IAM {
policy,
};

this.request(
this.request<Policy>(
{
client: 'SubscriberClient',
method: 'setIamPolicy',
Expand Down Expand Up @@ -394,7 +359,7 @@ export class IAM {
permissions: arrify(permissions),
};

this.request<PermissionsResponse>(
this.request<google.iam.v1.ITestIamPermissionsResponse>(
{
client: 'SubscriberClient',
method: 'testIamPermissions',
Expand All @@ -408,7 +373,7 @@ export class IAM {
}

const availablePermissions = arrify(resp!.permissions);
const permissionHash =
const permissionHash: IamPermissionsMap =
(permissions as string[]).reduce((acc, permission) => {
acc[permission] = availablePermissions.indexOf(permission) > -1;
return acc;
Expand Down
Loading