From 3ab6e68ed3ec70047264e9864a49abd497ebbaea Mon Sep 17 00:00:00 2001 From: Matthew Robertson Date: Wed, 10 Nov 2021 00:35:26 +0000 Subject: [PATCH] feat!: update the build to use api-extractor types This commit updates our build config to use the types generated by the API extractor. This prevents us exposing private implementation details in our type declarations that are not marked `@public` --- .github/workflows/docs.yml | 2 +- .github/workflows/publish.yml | 2 +- api-extractor.json | 2 +- docs/generated/api.d.ts | 191 ---------------------------------- package.json | 6 +- tsconfig.json | 2 +- 6 files changed, 7 insertions(+), 198 deletions(-) delete mode 100644 docs/generated/api.d.ts diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index c23db1dd..060a40e9 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -16,6 +16,6 @@ jobs: - name: Install dependencies run: npm install - name: Build TypeScript project - run: npm run docs + run: npm run build - name: Ensure there are no changes in docs run: git diff --exit-code docs/ diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 4c5036a0..297a6323 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -16,5 +16,5 @@ jobs: NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} run: | npm install - npm run compile + npm run build npm publish diff --git a/api-extractor.json b/api-extractor.json index a81a3547..4ff8aff6 100644 --- a/api-extractor.json +++ b/api-extractor.json @@ -19,7 +19,7 @@ "dtsRollup": { "enabled": true, - "untrimmedFilePath": "docs/generated/api.d.ts", + "untrimmedFilePath": "build/src/index.d.ts", "omitTrimmingComments": true }, diff --git a/docs/generated/api.d.ts b/docs/generated/api.d.ts deleted file mode 100644 index 0eb86680..00000000 --- a/docs/generated/api.d.ts +++ /dev/null @@ -1,191 +0,0 @@ -/// - -import * as express from 'express'; - -/** - * Register a function that handles CloudEvents. - * @param functionName - the name of the function - * @param handler - the function to trigger when handling CloudEvents - * @public - */ -export declare const cloudEvent: (functionName: string, handler: CloudEventFunction) => void; - -/** - * A CloudEvent function handler. - * @public - */ -export declare interface CloudEventFunction { - (cloudEvent: CloudEventsContext): any; -} - -/** - * A CloudEvent function handler with callback. - * @public - */ -export declare interface CloudEventFunctionWithCallback { - (cloudEvent: CloudEventsContext, callback: Function): any; -} - -/** - * The CloudEvents v1.0 context attributes. - * {@link https://github.com/cloudevents/spec/blob/v1.0.1/spec.md#context-attributes} - * @public - */ -export declare interface CloudEventsContext { - /** - * ID of the event. - */ - id: string; - /** - * The event producer. - */ - source: string; - /** - * The version of the CloudEvents specification which the event uses. - */ - specversion: string; - /** - * Type of occurrence which has happened. - */ - type: string; - /** - * Timestamp of when the event happened. - */ - time?: string; - /** - * Describes the subject of the event in the context of the event producer. - */ - subject?: string; - /** - * A link to the schema that the event data adheres to. - */ - dataschema?: string; - /** - * Content type of the event data. - */ - datacontenttype?: string; - /** - * The traceparent string, containing a trace version, trace ID, span ID, and trace options. - * @see https://github.com/cloudevents/spec/blob/master/extensions/distributed-tracing.md - */ - traceparent?: string; - /** - * The event payload. - */ - data?: any; -} - -/** - * The Cloud Functions context object for the event. - * {@link https://cloud.google.com/functions/docs/writing/background#function_parameters} - * @public - */ -export declare interface CloudFunctionsContext { - /** - * A unique ID for the event. For example: "70172329041928". - */ - eventId?: string; - /** - * The date/time this event was created. For example: "2018-04-09T07:56:12.975Z" - * This will be formatted as ISO 8601. - */ - timestamp?: string; - /** - * The type of the event. For example: "google.pubsub.topic.publish". - */ - eventType?: string; - /** - * The resource that emitted the event. - */ - resource?: string | { - [key: string]: string; - }; -} - -/** - * The function's context. - * @public - */ -export declare type Context = CloudFunctionsContext | CloudEventsContext; - -/** - * A data object used for legacy event functions. - * @public - */ -export declare interface Data { - data: object; -} - -/** - * A legacy event function handler. - * @public - */ -export declare interface EventFunction { - (data: {}, context: Context): any; -} - -/** - * A legacy event function handler with callback. - * @public - */ -export declare interface EventFunctionWithCallback { - (data: {}, context: Context, callback: Function): any; -} - -/** - * A function handler. - * @public - */ -export declare type HandlerFunction = HttpFunction | EventFunction | EventFunctionWithCallback | CloudEventFunction | CloudEventFunctionWithCallback; - -/** - * Register a function that responds to HTTP requests. - * @param functionName - the name of the function - * @param handler - the function to invoke when handling HTTP requests - * @public - */ -export declare const http: (functionName: string, handler: HttpFunction) => void; - -/** - * A HTTP function handler. - * @public - */ -export declare interface HttpFunction { - (req: Request_2, res: Response_2): any; -} - -/** - * A legacy event function context. - * @public - */ -export declare type LegacyCloudFunctionsContext = CloudFunctionsContext | Data; - -/** - * A legacy event. - * @public - */ -export declare interface LegacyEvent { - data: { - [key: string]: any; - }; - context: CloudFunctionsContext; -} - -/** - * @public - */ -declare interface Request_2 extends express.Request { - /** - * A buffer which provides access to the request's raw HTTP body. - */ - rawBody?: Buffer; -} -export { Request_2 as Request } - -/** - * @public - */ -declare type Response_2 = express.Response; -export { Response_2 as Response } - -export { } diff --git a/package.json b/package.json index 7afde0a1..a18c611d 100644 --- a/package.json +++ b/package.json @@ -18,15 +18,15 @@ }, "scripts": { "test": "mocha build/test --recursive", + "build": "npm run clean && npm run compile && npm run docs", "conformance": "./run_conformance_tests.sh", "check": "gts check", "clean": "gts clean", - "compile": "rm -rf ./build && tsc -p .", + "compile": "tsc -p .", "fix": "gts fix", - "predocs": "npm run compile", "docs": "api-extractor run --local --verbose", "watch": "npm run compile -- --watch", - "prepare": "npm run compile", + "prepare": "npm run build", "pretest": "npm run compile" }, "files": [ diff --git a/tsconfig.json b/tsconfig.json index 429a08b1..d9c5627a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,5 +1,5 @@ { - "extends": "gts/tsconfig-google.json", + "extends": "./node_modules/gts/tsconfig-google.json", "compilerOptions": { "rootDir": ".", "outDir": "build",