Skip to content

Commit

Permalink
refactor(typescript): various fixes/refactors to types (#515)
Browse files Browse the repository at this point in the history
  • Loading branch information
callmehiphop authored Mar 2, 2019
1 parent 89f6bae commit 0d9c13d
Show file tree
Hide file tree
Showing 14 changed files with 4,769 additions and 593 deletions.
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

0 comments on commit 0d9c13d

Please sign in to comment.