From 3bc07fa72c7a82f2b6cc4e254d277153d9bc73c2 Mon Sep 17 00:00:00 2001 From: Thomas Bouldin Date: Tue, 10 May 2022 08:43:47 -0700 Subject: [PATCH 1/2] Move some types to interfaces; inline interfaces to make fields private --- src/cloud-functions.ts | 104 ++++++++++++++++++------------- src/common/providers/identity.ts | 5 +- src/v2/providers/eventarc.ts | 4 +- 3 files changed, 67 insertions(+), 46 deletions(-) diff --git a/src/cloud-functions.ts b/src/cloud-functions.ts index 1f59f50d8..67bf4f4d4 100644 --- a/src/cloud-functions.ts +++ b/src/cloud-functions.ts @@ -257,45 +257,33 @@ export interface Resource { } /** - * @hidden - * TriggerAnnotated is used internally by the firebase CLI to understand what + * TriggerAnnotion is used internally by the firebase CLI to understand what * type of Cloud Function to deploy. */ -export interface TriggerAnnotated { - __trigger: { - availableMemoryMb?: number; - blockingTrigger?: { - eventType: string; - options?: Record; - }; - eventTrigger?: { - eventType: string; - resource: string; - service: string; - }; - failurePolicy?: FailurePolicy; - httpsTrigger?: { - invoker?: string[]; - }; - labels?: { [key: string]: string }; - regions?: string[]; - schedule?: Schedule; - timeout?: Duration; - vpcConnector?: string; - vpcConnectorEgressSettings?: string; - serviceAccountEmail?: string; - ingressSettings?: string; - secrets?: string[]; +interface TriggerAnnotation { + availableMemoryMb?: number; + blockingTrigger?: { + eventType: string; + options?: Record; }; -} - -/** - * @hidden - * EndpointAnnotated is used to generate the manifest that conforms to the container contract. - */ -export interface EndpointAnnotated { - __endpoint: ManifestEndpoint; - __requiredAPIs?: ManifestRequiredAPI[]; + eventTrigger?: { + eventType: string; + resource: string; + service: string; + }; + failurePolicy?: FailurePolicy; + httpsTrigger?: { + invoker?: string[]; + }; + labels?: { [key: string]: string }; + regions?: string[]; + schedule?: Schedule; + timeout?: Duration; + vpcConnector?: string; + vpcConnectorEgressSettings?: string; + serviceAccountEmail?: string; + ingressSettings?: string; + secrets?: string[]; } /** @@ -315,14 +303,34 @@ export interface Runnable { * [`Response`](https://expressjs.com/en/api.html#res) objects as its only * arguments. */ -export type HttpsFunction = TriggerAnnotated & - EndpointAnnotated & - ((req: Request, resp: Response) => void | Promise); +export interface HttpsFunction { + (req: Request, resp: Response): void | Promise + + /** @alpha */ + __trigger: TriggerAnnotation; + + /** @alpha */ + __endpoint: ManifestEndpoint; + + /** @alpha */ + __requiredAPIs?: ManifestRequiredAPI[]; +} /** * The Cloud Function type for Blocking triggers. */ -export type BlockingFunction = HttpsFunction; +export interface BlockingFunction { + (req: Request, resp: Response): void | Promise + + /** @alpha */ + __trigger: TriggerAnnotation; + + /** @alpha */ + __endpoint: ManifestEndpoint; + + /** @alpha */ + __requiredAPIs?: ManifestRequiredAPI[]; +} /** * The Cloud Function type for all non-HTTPS triggers. This should be exported @@ -331,10 +339,18 @@ export type BlockingFunction = HttpsFunction; * This type is a special JavaScript function which takes a templated * `Event` object as its only argument. */ -export type CloudFunction = Runnable & - TriggerAnnotated & - EndpointAnnotated & - ((input: any, context?: any) => PromiseLike | any); +export interface CloudFunction extends Runnable { + (input: any, context?: any): PromiseLike | any; + + /** @alpha */ + __trigger: TriggerAnnotation; + + /** @alpha */ + __endpoint: ManifestEndpoint; + + /** @alpha */ + __requiredAPIs?: ManifestRequiredAPI[]; +} /** @hidden */ export interface MakeCloudFunctionArgs { diff --git a/src/common/providers/identity.ts b/src/common/providers/identity.ts index 6912b9d1b..031e36f97 100644 --- a/src/common/providers/identity.ts +++ b/src/common/providers/identity.ts @@ -50,7 +50,10 @@ const DISALLOWED_CUSTOM_CLAIMS = [ const CLAIMS_MAX_PAYLOAD_SIZE = 1000; -/** Shorthand auth blocking events from GCIP. */ +/** + * Shorthand auth blocking events from GCIP. + * @internal + */ export type AuthBlockingEventType = 'beforeCreate' | 'beforeSignIn'; const EVENT_MAPPING: Record = { diff --git a/src/v2/providers/eventarc.ts b/src/v2/providers/eventarc.ts index fd56e714f..2820b1c26 100644 --- a/src/v2/providers/eventarc.ts +++ b/src/v2/providers/eventarc.ts @@ -54,7 +54,9 @@ export interface EventarcTriggerOptions extends options.EventHandlerOptions { filters?: Record; } -export type CloudEventHandler = (event: CloudEvent) => any | Promise; +export interface CloudEventHandler { + (event: CloudEvent): any | Promise; +} /** Handle an Eventarc event published on the default channel. */ export function onCustomEventPublished( From f6c59366fac133ec7561ca6cf8b4e0d276113ac0 Mon Sep 17 00:00:00 2001 From: Thomas Bouldin Date: Tue, 10 May 2022 11:23:45 -0700 Subject: [PATCH 2/2] Run formatter --- docgen/toc.ts | 4 ++-- src/cloud-functions.ts | 4 ++-- src/v2/providers/eventarc.ts | 4 +--- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/docgen/toc.ts b/docgen/toc.ts index d552a9cba..24cc58092 100644 --- a/docgen/toc.ts +++ b/docgen/toc.ts @@ -21,9 +21,9 @@ import { writeFileSync } from 'fs'; import { resolve } from 'path'; -import yargs from 'yargs'; -import * as yaml from 'js-yaml'; import { FileSystem } from '@rushstack/node-core-library'; +import * as yaml from 'js-yaml'; +import yargs from 'yargs'; export interface TocGenerationOptions { inputFolder: string; diff --git a/src/cloud-functions.ts b/src/cloud-functions.ts index 67bf4f4d4..a362230fb 100644 --- a/src/cloud-functions.ts +++ b/src/cloud-functions.ts @@ -304,7 +304,7 @@ export interface Runnable { * arguments. */ export interface HttpsFunction { - (req: Request, resp: Response): void | Promise + (req: Request, resp: Response): void | Promise; /** @alpha */ __trigger: TriggerAnnotation; @@ -320,7 +320,7 @@ export interface HttpsFunction { * The Cloud Function type for Blocking triggers. */ export interface BlockingFunction { - (req: Request, resp: Response): void | Promise + (req: Request, resp: Response): void | Promise; /** @alpha */ __trigger: TriggerAnnotation; diff --git a/src/v2/providers/eventarc.ts b/src/v2/providers/eventarc.ts index 2820b1c26..fd56e714f 100644 --- a/src/v2/providers/eventarc.ts +++ b/src/v2/providers/eventarc.ts @@ -54,9 +54,7 @@ export interface EventarcTriggerOptions extends options.EventHandlerOptions { filters?: Record; } -export interface CloudEventHandler { - (event: CloudEvent): any | Promise; -} +export type CloudEventHandler = (event: CloudEvent) => any | Promise; /** Handle an Eventarc event published on the default channel. */ export function onCustomEventPublished(