diff --git a/.gitignore b/.gitignore index 581628f1..622591f6 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ yarn-error.log function_output.json serverlog_stderr.txt serverlog_stdout.txt +temp \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7c2084a6..8c5fe633 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -71,6 +71,16 @@ npm unpublish @google-cloud/functions-framework@1.10.0 npm dist-tag add @google-cloud/functions-framework@1.9.0 latest --registry=https://wombat-dressing-room.appspot.com ``` +### API Extractor + +To generate the API Extractor documentation, run the API extractor with the following command: + +```sh +npm run docs +``` + +The docs will be generated in [`docs/generated/`](docs/generated/). + ## Community Guidelines This project follows [Google's Open Source Community diff --git a/api-extractor.json b/api-extractor.json new file mode 100644 index 00000000..a81a3547 --- /dev/null +++ b/api-extractor.json @@ -0,0 +1,48 @@ +{ + "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json", + + "mainEntryPointFilePath": "build/src/index.d.ts", + "bundledPackages": [], + "compiler": { + "tsconfigFilePath": "tsconfig.json" + }, + "apiReport": { + "enabled": true, + "reportFolder": "docs/generated/", + "reportFileName": "api.md" + }, + + "docModel": { + "enabled": true, + "apiJsonFilePath": "docs/generated/api.json" + }, + + "dtsRollup": { + "enabled": true, + "untrimmedFilePath": "docs/generated/api.d.ts", + "omitTrimmingComments": true + }, + + "tsdocMetadata": { + }, + + "messages": { + "compilerMessageReporting": { + "default": { + "logLevel": "warning" + } + }, + + "extractorMessageReporting": { + "default": { + "logLevel": "warning" + } + }, + + "tsdocMessageReporting": { + "default": { + "logLevel": "warning" + } + } + } +} diff --git a/docs/README.md b/docs/README.md index 9974c186..196667a2 100644 --- a/docs/README.md +++ b/docs/README.md @@ -8,6 +8,14 @@ This directory contains advanced docs around the Functions Framework. - [Writing a Function in Typescript](typescript.md) - [ES Modules](esm/README.md) +## Generated Docs + +The `generated/` directory contains generated API references. + +- [api.md](generated/api.md) +- [api.d.ts](generated/api.d.ts) +- [api.json](generated/api.json) + ## TODO Docs - Run Multiple Cloud Functions [#23](https://github.com/GoogleCloudPlatform/functions-framework-nodejs/issues/23) diff --git a/docs/generated/api.d.ts b/docs/generated/api.d.ts new file mode 100644 index 00000000..25051d0f --- /dev/null +++ b/docs/generated/api.d.ts @@ -0,0 +1,172 @@ +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 object for the event. + * {@link https://github.com/cloudevents/spec/blob/master/spec.md#context-attributes} + * @public + */ +export declare interface CloudEventsContext { + /** + * Type of occurrence which has happened. + */ + type?: string; + /** + * The version of the CloudEvents specification which the event uses. + */ + specversion?: string; + /** + * The event producer. + */ + source?: string; + /** + * ID of the event. + */ + id?: 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 event data. + */ + data?: Record | string | number | boolean | null | unknown; + /** + * 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 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: express.Request, res: express.Response): 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; +} + +export { } diff --git a/docs/generated/api.json b/docs/generated/api.json new file mode 100644 index 00000000..46e60be8 --- /dev/null +++ b/docs/generated/api.json @@ -0,0 +1,1252 @@ +{ + "metadata": { + "toolPackage": "@microsoft/api-extractor", + "toolVersion": "7.18.16", + "schemaVersion": 1004, + "oldestForwardsCompatibleVersion": 1001, + "tsdocConfig": { + "$schema": "https://developer.microsoft.com/json-schemas/tsdoc/v0/tsdoc.schema.json", + "noStandardTags": true, + "tagDefinitions": [ + { + "tagName": "@alpha", + "syntaxKind": "modifier" + }, + { + "tagName": "@beta", + "syntaxKind": "modifier" + }, + { + "tagName": "@defaultValue", + "syntaxKind": "block" + }, + { + "tagName": "@decorator", + "syntaxKind": "block", + "allowMultiple": true + }, + { + "tagName": "@deprecated", + "syntaxKind": "block" + }, + { + "tagName": "@eventProperty", + "syntaxKind": "modifier" + }, + { + "tagName": "@example", + "syntaxKind": "block", + "allowMultiple": true + }, + { + "tagName": "@experimental", + "syntaxKind": "modifier" + }, + { + "tagName": "@inheritDoc", + "syntaxKind": "inline" + }, + { + "tagName": "@internal", + "syntaxKind": "modifier" + }, + { + "tagName": "@label", + "syntaxKind": "inline" + }, + { + "tagName": "@link", + "syntaxKind": "inline", + "allowMultiple": true + }, + { + "tagName": "@override", + "syntaxKind": "modifier" + }, + { + "tagName": "@packageDocumentation", + "syntaxKind": "modifier" + }, + { + "tagName": "@param", + "syntaxKind": "block", + "allowMultiple": true + }, + { + "tagName": "@privateRemarks", + "syntaxKind": "block" + }, + { + "tagName": "@public", + "syntaxKind": "modifier" + }, + { + "tagName": "@readonly", + "syntaxKind": "modifier" + }, + { + "tagName": "@remarks", + "syntaxKind": "block" + }, + { + "tagName": "@returns", + "syntaxKind": "block" + }, + { + "tagName": "@sealed", + "syntaxKind": "modifier" + }, + { + "tagName": "@see", + "syntaxKind": "block" + }, + { + "tagName": "@throws", + "syntaxKind": "block", + "allowMultiple": true + }, + { + "tagName": "@typeParam", + "syntaxKind": "block", + "allowMultiple": true + }, + { + "tagName": "@virtual", + "syntaxKind": "modifier" + }, + { + "tagName": "@betaDocumentation", + "syntaxKind": "modifier" + }, + { + "tagName": "@internalRemarks", + "syntaxKind": "block" + }, + { + "tagName": "@preapproved", + "syntaxKind": "modifier" + } + ], + "supportForTags": { + "@alpha": true, + "@beta": true, + "@defaultValue": true, + "@decorator": true, + "@deprecated": true, + "@eventProperty": true, + "@example": true, + "@experimental": true, + "@inheritDoc": true, + "@internal": true, + "@label": true, + "@link": true, + "@override": true, + "@packageDocumentation": true, + "@param": true, + "@privateRemarks": true, + "@public": true, + "@readonly": true, + "@remarks": true, + "@returns": true, + "@sealed": true, + "@see": true, + "@throws": true, + "@typeParam": true, + "@virtual": true, + "@betaDocumentation": true, + "@internalRemarks": true, + "@preapproved": true + } + } + }, + "kind": "Package", + "canonicalReference": "@google-cloud/functions-framework!", + "docComment": "", + "name": "@google-cloud/functions-framework", + "members": [ + { + "kind": "EntryPoint", + "canonicalReference": "@google-cloud/functions-framework!", + "name": "", + "members": [ + { + "kind": "Variable", + "canonicalReference": "@google-cloud/functions-framework!cloudevent:var", + "docComment": "/**\n * Register a function that handles CloudEvents.\n *\n * @param functionName - the name of the function\n *\n * @param handler - the function to trigger when handling cloudevents\n *\n * @public\n */\n", + "excerptTokens": [ + { + "kind": "Content", + "text": "cloudevent: " + }, + { + "kind": "Content", + "text": "(functionName: string, handler: " + }, + { + "kind": "Reference", + "text": "CloudEventFunction", + "canonicalReference": "@google-cloud/functions-framework!CloudEventFunction:interface" + }, + { + "kind": "Content", + "text": ") => void" + } + ], + "releaseTag": "Public", + "name": "cloudevent", + "variableTypeTokenRange": { + "startIndex": 1, + "endIndex": 4 + } + }, + { + "kind": "Interface", + "canonicalReference": "@google-cloud/functions-framework!CloudEventFunction:interface", + "docComment": "/**\n * A cloudevent function handler.\n *\n * @public\n */\n", + "excerptTokens": [ + { + "kind": "Content", + "text": "export interface CloudEventFunction " + } + ], + "releaseTag": "Public", + "name": "CloudEventFunction", + "members": [ + { + "kind": "CallSignature", + "canonicalReference": "@google-cloud/functions-framework!CloudEventFunction:call(1)", + "docComment": "", + "excerptTokens": [ + { + "kind": "Content", + "text": "(cloudevent: " + }, + { + "kind": "Reference", + "text": "CloudEventsContext", + "canonicalReference": "@google-cloud/functions-framework!CloudEventsContext:interface" + }, + { + "kind": "Content", + "text": "): " + }, + { + "kind": "Content", + "text": "any" + }, + { + "kind": "Content", + "text": ";" + } + ], + "returnTypeTokenRange": { + "startIndex": 3, + "endIndex": 4 + }, + "releaseTag": "Public", + "overloadIndex": 1, + "parameters": [ + { + "parameterName": "cloudevent", + "parameterTypeTokenRange": { + "startIndex": 1, + "endIndex": 2 + } + } + ] + } + ], + "extendsTokenRanges": [] + }, + { + "kind": "Interface", + "canonicalReference": "@google-cloud/functions-framework!CloudEventFunctionWithCallback:interface", + "docComment": "/**\n * A cloudevent function handler with callback.\n *\n * @public\n */\n", + "excerptTokens": [ + { + "kind": "Content", + "text": "export interface CloudEventFunctionWithCallback " + } + ], + "releaseTag": "Public", + "name": "CloudEventFunctionWithCallback", + "members": [ + { + "kind": "CallSignature", + "canonicalReference": "@google-cloud/functions-framework!CloudEventFunctionWithCallback:call(1)", + "docComment": "", + "excerptTokens": [ + { + "kind": "Content", + "text": "(cloudevent: " + }, + { + "kind": "Reference", + "text": "CloudEventsContext", + "canonicalReference": "@google-cloud/functions-framework!CloudEventsContext:interface" + }, + { + "kind": "Content", + "text": ", callback: " + }, + { + "kind": "Reference", + "text": "Function", + "canonicalReference": "!Function:interface" + }, + { + "kind": "Content", + "text": "): " + }, + { + "kind": "Content", + "text": "any" + }, + { + "kind": "Content", + "text": ";" + } + ], + "returnTypeTokenRange": { + "startIndex": 5, + "endIndex": 6 + }, + "releaseTag": "Public", + "overloadIndex": 1, + "parameters": [ + { + "parameterName": "cloudevent", + "parameterTypeTokenRange": { + "startIndex": 1, + "endIndex": 2 + } + }, + { + "parameterName": "callback", + "parameterTypeTokenRange": { + "startIndex": 3, + "endIndex": 4 + } + } + ] + } + ], + "extendsTokenRanges": [] + }, + { + "kind": "Interface", + "canonicalReference": "@google-cloud/functions-framework!CloudEventsContext:interface", + "docComment": "/**\n * The CloudEvents v1.0 context object for the event. {@link https://github.com/cloudevents/spec/blob/master/spec.md#context-attributes}\n *\n * @public\n */\n", + "excerptTokens": [ + { + "kind": "Content", + "text": "export interface CloudEventsContext " + } + ], + "releaseTag": "Public", + "name": "CloudEventsContext", + "members": [ + { + "kind": "PropertySignature", + "canonicalReference": "@google-cloud/functions-framework!CloudEventsContext#data:member", + "docComment": "/**\n * The event data.\n */\n", + "excerptTokens": [ + { + "kind": "Content", + "text": "data?: " + }, + { + "kind": "Reference", + "text": "Record", + "canonicalReference": "!Record:type" + }, + { + "kind": "Content", + "text": " | string | number | boolean | null | unknown" + }, + { + "kind": "Content", + "text": ";" + } + ], + "isOptional": true, + "releaseTag": "Public", + "name": "data", + "propertyTypeTokenRange": { + "startIndex": 1, + "endIndex": 3 + } + }, + { + "kind": "PropertySignature", + "canonicalReference": "@google-cloud/functions-framework!CloudEventsContext#datacontenttype:member", + "docComment": "/**\n * Content type of the event data.\n */\n", + "excerptTokens": [ + { + "kind": "Content", + "text": "datacontenttype?: " + }, + { + "kind": "Content", + "text": "string" + }, + { + "kind": "Content", + "text": ";" + } + ], + "isOptional": true, + "releaseTag": "Public", + "name": "datacontenttype", + "propertyTypeTokenRange": { + "startIndex": 1, + "endIndex": 2 + } + }, + { + "kind": "PropertySignature", + "canonicalReference": "@google-cloud/functions-framework!CloudEventsContext#dataschema:member", + "docComment": "/**\n * A link to the schema that the event data adheres to.\n */\n", + "excerptTokens": [ + { + "kind": "Content", + "text": "dataschema?: " + }, + { + "kind": "Content", + "text": "string" + }, + { + "kind": "Content", + "text": ";" + } + ], + "isOptional": true, + "releaseTag": "Public", + "name": "dataschema", + "propertyTypeTokenRange": { + "startIndex": 1, + "endIndex": 2 + } + }, + { + "kind": "PropertySignature", + "canonicalReference": "@google-cloud/functions-framework!CloudEventsContext#id:member", + "docComment": "/**\n * ID of the event.\n */\n", + "excerptTokens": [ + { + "kind": "Content", + "text": "id?: " + }, + { + "kind": "Content", + "text": "string" + }, + { + "kind": "Content", + "text": ";" + } + ], + "isOptional": true, + "releaseTag": "Public", + "name": "id", + "propertyTypeTokenRange": { + "startIndex": 1, + "endIndex": 2 + } + }, + { + "kind": "PropertySignature", + "canonicalReference": "@google-cloud/functions-framework!CloudEventsContext#source:member", + "docComment": "/**\n * The event producer.\n */\n", + "excerptTokens": [ + { + "kind": "Content", + "text": "source?: " + }, + { + "kind": "Content", + "text": "string" + }, + { + "kind": "Content", + "text": ";" + } + ], + "isOptional": true, + "releaseTag": "Public", + "name": "source", + "propertyTypeTokenRange": { + "startIndex": 1, + "endIndex": 2 + } + }, + { + "kind": "PropertySignature", + "canonicalReference": "@google-cloud/functions-framework!CloudEventsContext#specversion:member", + "docComment": "/**\n * The version of the CloudEvents specification which the event uses.\n */\n", + "excerptTokens": [ + { + "kind": "Content", + "text": "specversion?: " + }, + { + "kind": "Content", + "text": "string" + }, + { + "kind": "Content", + "text": ";" + } + ], + "isOptional": true, + "releaseTag": "Public", + "name": "specversion", + "propertyTypeTokenRange": { + "startIndex": 1, + "endIndex": 2 + } + }, + { + "kind": "PropertySignature", + "canonicalReference": "@google-cloud/functions-framework!CloudEventsContext#subject:member", + "docComment": "/**\n * Describes the subject of the event in the context of the event producer.\n */\n", + "excerptTokens": [ + { + "kind": "Content", + "text": "subject?: " + }, + { + "kind": "Content", + "text": "string" + }, + { + "kind": "Content", + "text": ";" + } + ], + "isOptional": true, + "releaseTag": "Public", + "name": "subject", + "propertyTypeTokenRange": { + "startIndex": 1, + "endIndex": 2 + } + }, + { + "kind": "PropertySignature", + "canonicalReference": "@google-cloud/functions-framework!CloudEventsContext#time:member", + "docComment": "/**\n * Timestamp of when the event happened.\n */\n", + "excerptTokens": [ + { + "kind": "Content", + "text": "time?: " + }, + { + "kind": "Content", + "text": "string" + }, + { + "kind": "Content", + "text": ";" + } + ], + "isOptional": true, + "releaseTag": "Public", + "name": "time", + "propertyTypeTokenRange": { + "startIndex": 1, + "endIndex": 2 + } + }, + { + "kind": "PropertySignature", + "canonicalReference": "@google-cloud/functions-framework!CloudEventsContext#traceparent:member", + "docComment": "/**\n * The traceparent string, containing a trace version, trace ID, span ID, and trace options.\n *\n * @see\n *\n * https://github.com/cloudevents/spec/blob/master/extensions/distributed-tracing.md\n */\n", + "excerptTokens": [ + { + "kind": "Content", + "text": "traceparent?: " + }, + { + "kind": "Content", + "text": "string" + }, + { + "kind": "Content", + "text": ";" + } + ], + "isOptional": true, + "releaseTag": "Public", + "name": "traceparent", + "propertyTypeTokenRange": { + "startIndex": 1, + "endIndex": 2 + } + }, + { + "kind": "PropertySignature", + "canonicalReference": "@google-cloud/functions-framework!CloudEventsContext#type:member", + "docComment": "/**\n * Type of occurrence which has happened.\n */\n", + "excerptTokens": [ + { + "kind": "Content", + "text": "type?: " + }, + { + "kind": "Content", + "text": "string" + }, + { + "kind": "Content", + "text": ";" + } + ], + "isOptional": true, + "releaseTag": "Public", + "name": "type", + "propertyTypeTokenRange": { + "startIndex": 1, + "endIndex": 2 + } + } + ], + "extendsTokenRanges": [] + }, + { + "kind": "Interface", + "canonicalReference": "@google-cloud/functions-framework!CloudFunctionsContext:interface", + "docComment": "/**\n * The Cloud Functions context object for the event. {@link https://cloud.google.com/functions/docs/writing/background#function_parameters}\n *\n * @public\n */\n", + "excerptTokens": [ + { + "kind": "Content", + "text": "export interface CloudFunctionsContext " + } + ], + "releaseTag": "Public", + "name": "CloudFunctionsContext", + "members": [ + { + "kind": "PropertySignature", + "canonicalReference": "@google-cloud/functions-framework!CloudFunctionsContext#eventId:member", + "docComment": "/**\n * A unique ID for the event. For example: \"70172329041928\".\n */\n", + "excerptTokens": [ + { + "kind": "Content", + "text": "eventId?: " + }, + { + "kind": "Content", + "text": "string" + }, + { + "kind": "Content", + "text": ";" + } + ], + "isOptional": true, + "releaseTag": "Public", + "name": "eventId", + "propertyTypeTokenRange": { + "startIndex": 1, + "endIndex": 2 + } + }, + { + "kind": "PropertySignature", + "canonicalReference": "@google-cloud/functions-framework!CloudFunctionsContext#eventType:member", + "docComment": "/**\n * The type of the event. For example: \"google.pubsub.topic.publish\".\n */\n", + "excerptTokens": [ + { + "kind": "Content", + "text": "eventType?: " + }, + { + "kind": "Content", + "text": "string" + }, + { + "kind": "Content", + "text": ";" + } + ], + "isOptional": true, + "releaseTag": "Public", + "name": "eventType", + "propertyTypeTokenRange": { + "startIndex": 1, + "endIndex": 2 + } + }, + { + "kind": "PropertySignature", + "canonicalReference": "@google-cloud/functions-framework!CloudFunctionsContext#resource:member", + "docComment": "/**\n * The resource that emitted the event.\n */\n", + "excerptTokens": [ + { + "kind": "Content", + "text": "resource?: " + }, + { + "kind": "Content", + "text": "string | {\n [key: string]: string;\n }" + }, + { + "kind": "Content", + "text": ";" + } + ], + "isOptional": true, + "releaseTag": "Public", + "name": "resource", + "propertyTypeTokenRange": { + "startIndex": 1, + "endIndex": 2 + } + }, + { + "kind": "PropertySignature", + "canonicalReference": "@google-cloud/functions-framework!CloudFunctionsContext#timestamp:member", + "docComment": "/**\n * The date/time this event was created. For example: \"2018-04-09T07:56:12.975Z\" This will be formatted as ISO 8601.\n */\n", + "excerptTokens": [ + { + "kind": "Content", + "text": "timestamp?: " + }, + { + "kind": "Content", + "text": "string" + }, + { + "kind": "Content", + "text": ";" + } + ], + "isOptional": true, + "releaseTag": "Public", + "name": "timestamp", + "propertyTypeTokenRange": { + "startIndex": 1, + "endIndex": 2 + } + } + ], + "extendsTokenRanges": [] + }, + { + "kind": "TypeAlias", + "canonicalReference": "@google-cloud/functions-framework!Context:type", + "docComment": "/**\n * The function's context.\n *\n * @public\n */\n", + "excerptTokens": [ + { + "kind": "Content", + "text": "export declare type Context = " + }, + { + "kind": "Reference", + "text": "CloudFunctionsContext", + "canonicalReference": "@google-cloud/functions-framework!CloudFunctionsContext:interface" + }, + { + "kind": "Content", + "text": " | " + }, + { + "kind": "Reference", + "text": "CloudEventsContext", + "canonicalReference": "@google-cloud/functions-framework!CloudEventsContext:interface" + }, + { + "kind": "Content", + "text": ";" + } + ], + "releaseTag": "Public", + "name": "Context", + "typeTokenRange": { + "startIndex": 1, + "endIndex": 4 + } + }, + { + "kind": "Interface", + "canonicalReference": "@google-cloud/functions-framework!Data:interface", + "docComment": "/**\n * A data object used for legacy event functions.\n *\n * @public\n */\n", + "excerptTokens": [ + { + "kind": "Content", + "text": "export interface Data " + } + ], + "releaseTag": "Public", + "name": "Data", + "members": [ + { + "kind": "PropertySignature", + "canonicalReference": "@google-cloud/functions-framework!Data#data:member", + "docComment": "", + "excerptTokens": [ + { + "kind": "Content", + "text": "data: " + }, + { + "kind": "Content", + "text": "object" + }, + { + "kind": "Content", + "text": ";" + } + ], + "isOptional": false, + "releaseTag": "Public", + "name": "data", + "propertyTypeTokenRange": { + "startIndex": 1, + "endIndex": 2 + } + } + ], + "extendsTokenRanges": [] + }, + { + "kind": "Interface", + "canonicalReference": "@google-cloud/functions-framework!EventFunction:interface", + "docComment": "/**\n * A legacy event function handler.\n *\n * @public\n */\n", + "excerptTokens": [ + { + "kind": "Content", + "text": "export interface EventFunction " + } + ], + "releaseTag": "Public", + "name": "EventFunction", + "members": [ + { + "kind": "CallSignature", + "canonicalReference": "@google-cloud/functions-framework!EventFunction:call(1)", + "docComment": "", + "excerptTokens": [ + { + "kind": "Content", + "text": "(data: " + }, + { + "kind": "Content", + "text": "{}" + }, + { + "kind": "Content", + "text": ", context: " + }, + { + "kind": "Reference", + "text": "Context", + "canonicalReference": "@google-cloud/functions-framework!Context:type" + }, + { + "kind": "Content", + "text": "): " + }, + { + "kind": "Content", + "text": "any" + }, + { + "kind": "Content", + "text": ";" + } + ], + "returnTypeTokenRange": { + "startIndex": 5, + "endIndex": 6 + }, + "releaseTag": "Public", + "overloadIndex": 1, + "parameters": [ + { + "parameterName": "data", + "parameterTypeTokenRange": { + "startIndex": 1, + "endIndex": 2 + } + }, + { + "parameterName": "context", + "parameterTypeTokenRange": { + "startIndex": 3, + "endIndex": 4 + } + } + ] + } + ], + "extendsTokenRanges": [] + }, + { + "kind": "Interface", + "canonicalReference": "@google-cloud/functions-framework!EventFunctionWithCallback:interface", + "docComment": "/**\n * A legacy event function handler with callback.\n *\n * @public\n */\n", + "excerptTokens": [ + { + "kind": "Content", + "text": "export interface EventFunctionWithCallback " + } + ], + "releaseTag": "Public", + "name": "EventFunctionWithCallback", + "members": [ + { + "kind": "CallSignature", + "canonicalReference": "@google-cloud/functions-framework!EventFunctionWithCallback:call(1)", + "docComment": "", + "excerptTokens": [ + { + "kind": "Content", + "text": "(data: " + }, + { + "kind": "Content", + "text": "{}" + }, + { + "kind": "Content", + "text": ", context: " + }, + { + "kind": "Reference", + "text": "Context", + "canonicalReference": "@google-cloud/functions-framework!Context:type" + }, + { + "kind": "Content", + "text": ", callback: " + }, + { + "kind": "Reference", + "text": "Function", + "canonicalReference": "!Function:interface" + }, + { + "kind": "Content", + "text": "): " + }, + { + "kind": "Content", + "text": "any" + }, + { + "kind": "Content", + "text": ";" + } + ], + "returnTypeTokenRange": { + "startIndex": 7, + "endIndex": 8 + }, + "releaseTag": "Public", + "overloadIndex": 1, + "parameters": [ + { + "parameterName": "data", + "parameterTypeTokenRange": { + "startIndex": 1, + "endIndex": 2 + } + }, + { + "parameterName": "context", + "parameterTypeTokenRange": { + "startIndex": 3, + "endIndex": 4 + } + }, + { + "parameterName": "callback", + "parameterTypeTokenRange": { + "startIndex": 5, + "endIndex": 6 + } + } + ] + } + ], + "extendsTokenRanges": [] + }, + { + "kind": "TypeAlias", + "canonicalReference": "@google-cloud/functions-framework!HandlerFunction:type", + "docComment": "/**\n * A function handler.\n *\n * @public\n */\n", + "excerptTokens": [ + { + "kind": "Content", + "text": "export declare type HandlerFunction = " + }, + { + "kind": "Reference", + "text": "HttpFunction", + "canonicalReference": "@google-cloud/functions-framework!HttpFunction:interface" + }, + { + "kind": "Content", + "text": " | " + }, + { + "kind": "Reference", + "text": "EventFunction", + "canonicalReference": "@google-cloud/functions-framework!EventFunction:interface" + }, + { + "kind": "Content", + "text": " | " + }, + { + "kind": "Reference", + "text": "EventFunctionWithCallback", + "canonicalReference": "@google-cloud/functions-framework!EventFunctionWithCallback:interface" + }, + { + "kind": "Content", + "text": " | " + }, + { + "kind": "Reference", + "text": "CloudEventFunction", + "canonicalReference": "@google-cloud/functions-framework!CloudEventFunction:interface" + }, + { + "kind": "Content", + "text": " | " + }, + { + "kind": "Reference", + "text": "CloudEventFunctionWithCallback", + "canonicalReference": "@google-cloud/functions-framework!CloudEventFunctionWithCallback:interface" + }, + { + "kind": "Content", + "text": ";" + } + ], + "releaseTag": "Public", + "name": "HandlerFunction", + "typeTokenRange": { + "startIndex": 1, + "endIndex": 10 + } + }, + { + "kind": "Variable", + "canonicalReference": "@google-cloud/functions-framework!http:var", + "docComment": "/**\n * Register a function that responds to HTTP requests.\n *\n * @param functionName - the name of the function\n *\n * @param handler - the function to invoke when handling HTTP requests\n *\n * @public\n */\n", + "excerptTokens": [ + { + "kind": "Content", + "text": "http: " + }, + { + "kind": "Content", + "text": "(functionName: string, handler: " + }, + { + "kind": "Reference", + "text": "HttpFunction", + "canonicalReference": "@google-cloud/functions-framework!HttpFunction:interface" + }, + { + "kind": "Content", + "text": ") => void" + } + ], + "releaseTag": "Public", + "name": "http", + "variableTypeTokenRange": { + "startIndex": 1, + "endIndex": 4 + } + }, + { + "kind": "Interface", + "canonicalReference": "@google-cloud/functions-framework!HttpFunction:interface", + "docComment": "/**\n * A HTTP function handler.\n *\n * @public\n */\n", + "excerptTokens": [ + { + "kind": "Content", + "text": "export interface HttpFunction " + } + ], + "releaseTag": "Public", + "name": "HttpFunction", + "members": [ + { + "kind": "CallSignature", + "canonicalReference": "@google-cloud/functions-framework!HttpFunction:call(1)", + "docComment": "", + "excerptTokens": [ + { + "kind": "Content", + "text": "(req: " + }, + { + "kind": "Reference", + "text": "express.Request", + "canonicalReference": "@types/express!~e.Request:interface" + }, + { + "kind": "Content", + "text": ", res: " + }, + { + "kind": "Reference", + "text": "express.Response", + "canonicalReference": "@types/express!~e.Response:interface" + }, + { + "kind": "Content", + "text": "): " + }, + { + "kind": "Content", + "text": "any" + }, + { + "kind": "Content", + "text": ";" + } + ], + "returnTypeTokenRange": { + "startIndex": 5, + "endIndex": 6 + }, + "releaseTag": "Public", + "overloadIndex": 1, + "parameters": [ + { + "parameterName": "req", + "parameterTypeTokenRange": { + "startIndex": 1, + "endIndex": 2 + } + }, + { + "parameterName": "res", + "parameterTypeTokenRange": { + "startIndex": 3, + "endIndex": 4 + } + } + ] + } + ], + "extendsTokenRanges": [] + }, + { + "kind": "TypeAlias", + "canonicalReference": "@google-cloud/functions-framework!LegacyCloudFunctionsContext:type", + "docComment": "/**\n * A legacy event function context.\n *\n * @public\n */\n", + "excerptTokens": [ + { + "kind": "Content", + "text": "export declare type LegacyCloudFunctionsContext = " + }, + { + "kind": "Reference", + "text": "CloudFunctionsContext", + "canonicalReference": "@google-cloud/functions-framework!CloudFunctionsContext:interface" + }, + { + "kind": "Content", + "text": " | " + }, + { + "kind": "Reference", + "text": "Data", + "canonicalReference": "@google-cloud/functions-framework!Data:interface" + }, + { + "kind": "Content", + "text": ";" + } + ], + "releaseTag": "Public", + "name": "LegacyCloudFunctionsContext", + "typeTokenRange": { + "startIndex": 1, + "endIndex": 4 + } + }, + { + "kind": "Interface", + "canonicalReference": "@google-cloud/functions-framework!LegacyEvent:interface", + "docComment": "/**\n * A legacy event.\n *\n * @public\n */\n", + "excerptTokens": [ + { + "kind": "Content", + "text": "export interface LegacyEvent " + } + ], + "releaseTag": "Public", + "name": "LegacyEvent", + "members": [ + { + "kind": "PropertySignature", + "canonicalReference": "@google-cloud/functions-framework!LegacyEvent#context:member", + "docComment": "", + "excerptTokens": [ + { + "kind": "Content", + "text": "context: " + }, + { + "kind": "Reference", + "text": "CloudFunctionsContext", + "canonicalReference": "@google-cloud/functions-framework!CloudFunctionsContext:interface" + }, + { + "kind": "Content", + "text": ";" + } + ], + "isOptional": false, + "releaseTag": "Public", + "name": "context", + "propertyTypeTokenRange": { + "startIndex": 1, + "endIndex": 2 + } + }, + { + "kind": "PropertySignature", + "canonicalReference": "@google-cloud/functions-framework!LegacyEvent#data:member", + "docComment": "", + "excerptTokens": [ + { + "kind": "Content", + "text": "data: " + }, + { + "kind": "Content", + "text": "{\n [key: string]: any;\n }" + }, + { + "kind": "Content", + "text": ";" + } + ], + "isOptional": false, + "releaseTag": "Public", + "name": "data", + "propertyTypeTokenRange": { + "startIndex": 1, + "endIndex": 2 + } + } + ], + "extendsTokenRanges": [] + } + ] + } + ] +} diff --git a/docs/generated/api.md b/docs/generated/api.md new file mode 100644 index 00000000..8db969a2 --- /dev/null +++ b/docs/generated/api.md @@ -0,0 +1,96 @@ +## API Report File for "@google-cloud/functions-framework" + +> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). + +```ts + +import * as express from 'express'; + +// @public +export const cloudevent: (functionName: string, handler: CloudEventFunction) => void; + +// @public +export interface CloudEventFunction { + // (undocumented) + (cloudevent: CloudEventsContext): any; +} + +// @public +export interface CloudEventFunctionWithCallback { + // (undocumented) + (cloudevent: CloudEventsContext, callback: Function): any; +} + +// @public +export interface CloudEventsContext { + data?: Record | string | number | boolean | null | unknown; + datacontenttype?: string; + dataschema?: string; + id?: string; + source?: string; + specversion?: string; + subject?: string; + time?: string; + traceparent?: string; + type?: string; +} + +// @public +export interface CloudFunctionsContext { + eventId?: string; + eventType?: string; + resource?: string | { + [key: string]: string; + }; + timestamp?: string; +} + +// @public +export type Context = CloudFunctionsContext | CloudEventsContext; + +// @public +export interface Data { + // (undocumented) + data: object; +} + +// @public +export interface EventFunction { + // (undocumented) + (data: {}, context: Context): any; +} + +// @public +export interface EventFunctionWithCallback { + // (undocumented) + (data: {}, context: Context, callback: Function): any; +} + +// @public +export type HandlerFunction = HttpFunction | EventFunction | EventFunctionWithCallback | CloudEventFunction | CloudEventFunctionWithCallback; + +// @public +export const http: (functionName: string, handler: HttpFunction) => void; + +// @public +export interface HttpFunction { + // (undocumented) + (req: express.Request, res: express.Response): any; +} + +// @public +export type LegacyCloudFunctionsContext = CloudFunctionsContext | Data; + +// @public +export interface LegacyEvent { + // (undocumented) + context: CloudFunctionsContext; + // (undocumented) + data: { + [key: string]: any; + }; +} + +// (No @packageDocumentation comment for this package) + +``` diff --git a/package-lock.json b/package-lock.json index f093e804..99426275 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,6 +21,7 @@ "functions-framework-nodejs": "build/src/index.js" }, "devDependencies": { + "@microsoft/api-extractor": "^7.18.16", "@types/body-parser": "1.19.1", "@types/express": "4.17.13", "@types/minimist": "1.2.2", @@ -145,6 +146,83 @@ "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", "dev": true }, + "node_modules/@microsoft/api-extractor": { + "version": "7.18.16", + "resolved": "https://registry.npmjs.org/@microsoft/api-extractor/-/api-extractor-7.18.16.tgz", + "integrity": "sha512-f0EcjGgS8IToUHxfQIr4vxGpBhUdaDOhGyddZpZ5K9e/GcGkImfkGeHpYbK043f2bZV3aagTx6NcIawwE72BKA==", + "dev": true, + "dependencies": { + "@microsoft/api-extractor-model": "7.13.13", + "@microsoft/tsdoc": "0.13.2", + "@microsoft/tsdoc-config": "~0.15.2", + "@rushstack/node-core-library": "3.42.3", + "@rushstack/rig-package": "0.3.3", + "@rushstack/ts-command-line": "4.10.2", + "colors": "~1.2.1", + "lodash": "~4.17.15", + "resolve": "~1.17.0", + "semver": "~7.3.0", + "source-map": "~0.6.1", + "typescript": "~4.4.2" + }, + "bin": { + "api-extractor": "bin/api-extractor" + } + }, + "node_modules/@microsoft/api-extractor-model": { + "version": "7.13.13", + "resolved": "https://registry.npmjs.org/@microsoft/api-extractor-model/-/api-extractor-model-7.13.13.tgz", + "integrity": "sha512-4Hz2TOL4TljsAfMQe7a8tm+Am8+AkrcgkbnH62S9YuaIC3Cw6jE4H2qP8WC2JJInWJP4pg/ZrUlHrtmtgrqn9Q==", + "dev": true, + "dependencies": { + "@microsoft/tsdoc": "0.13.2", + "@microsoft/tsdoc-config": "~0.15.2", + "@rushstack/node-core-library": "3.42.3" + } + }, + "node_modules/@microsoft/api-extractor/node_modules/resolve": { + "version": "1.17.0", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.17.0.tgz", + "integrity": "sha512-ic+7JYiV8Vi2yzQGFWOkiZD5Z9z7O2Zhm9XMaTxdJExKasieFCr+yXZ/WmXsckHiKl12ar0y6XiXDx3m4RHn1w==", + "dev": true, + "dependencies": { + "path-parse": "^1.0.6" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/@microsoft/api-extractor/node_modules/typescript": { + "version": "4.4.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.4.4.tgz", + "integrity": "sha512-DqGhF5IKoBl8WNf8C1gu8q0xZSInh9j1kJJMqT3a94w1JzVaBU4EXOSMrz9yDqMT0xt3selp83fuFMQ0uzv6qA==", + "dev": true, + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=4.2.0" + } + }, + "node_modules/@microsoft/tsdoc": { + "version": "0.13.2", + "resolved": "https://registry.npmjs.org/@microsoft/tsdoc/-/tsdoc-0.13.2.tgz", + "integrity": "sha512-WrHvO8PDL8wd8T2+zBGKrMwVL5IyzR3ryWUsl0PXgEV0QHup4mTLi0QcATefGI6Gx9Anu7vthPyyyLpY0EpiQg==", + "dev": true + }, + "node_modules/@microsoft/tsdoc-config": { + "version": "0.15.2", + "resolved": "https://registry.npmjs.org/@microsoft/tsdoc-config/-/tsdoc-config-0.15.2.tgz", + "integrity": "sha512-mK19b2wJHSdNf8znXSMYVShAHktVr/ib0Ck2FA3lsVBSEhSI/TfXT7DJQkAYgcztTuwazGcg58ZjYdk0hTCVrA==", + "dev": true, + "dependencies": { + "@microsoft/tsdoc": "0.13.2", + "ajv": "~6.12.6", + "jju": "~1.4.0", + "resolve": "~1.19.0" + } + }, "node_modules/@nodelib/fs.scandir": { "version": "2.1.4", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.4.tgz", @@ -180,6 +258,84 @@ "node": ">= 8" } }, + "node_modules/@rushstack/node-core-library": { + "version": "3.42.3", + "resolved": "https://registry.npmjs.org/@rushstack/node-core-library/-/node-core-library-3.42.3.tgz", + "integrity": "sha512-xtiJsHtO4Sf/hVKyf/8d58p3zQh2JAZNs1mmDNCyIlgSRYGdqUkpadvvn5mz7EwF6lwn+xTTaTV5/a32xKjbdw==", + "dev": true, + "dependencies": { + "@types/node": "12.20.24", + "colors": "~1.2.1", + "fs-extra": "~7.0.1", + "import-lazy": "~4.0.0", + "jju": "~1.4.0", + "resolve": "~1.17.0", + "semver": "~7.3.0", + "timsort": "~0.3.0", + "z-schema": "~3.18.3" + } + }, + "node_modules/@rushstack/node-core-library/node_modules/@types/node": { + "version": "12.20.24", + "resolved": "https://registry.npmjs.org/@types/node/-/node-12.20.24.tgz", + "integrity": "sha512-yxDeaQIAJlMav7fH5AQqPH1u8YIuhYJXYBzxaQ4PifsU0GDO38MSdmEDeRlIxrKbC6NbEaaEHDanWb+y30U8SQ==", + "dev": true + }, + "node_modules/@rushstack/node-core-library/node_modules/import-lazy": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/import-lazy/-/import-lazy-4.0.0.tgz", + "integrity": "sha512-rKtvo6a868b5Hu3heneU+L4yEQ4jYKLtjpnPeUdK7h0yzXGmyBTypknlkCvHFBqfX9YlorEiMM6Dnq/5atfHkw==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/@rushstack/node-core-library/node_modules/resolve": { + "version": "1.17.0", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.17.0.tgz", + "integrity": "sha512-ic+7JYiV8Vi2yzQGFWOkiZD5Z9z7O2Zhm9XMaTxdJExKasieFCr+yXZ/WmXsckHiKl12ar0y6XiXDx3m4RHn1w==", + "dev": true, + "dependencies": { + "path-parse": "^1.0.6" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/@rushstack/rig-package": { + "version": "0.3.3", + "resolved": "https://registry.npmjs.org/@rushstack/rig-package/-/rig-package-0.3.3.tgz", + "integrity": "sha512-ElPnChxIkUzcU3ywI0Cl7E1aM+2w6vFpAwM6X+oWk7Cyjf2ofItThje9e5qUBtKqvI9sc5jVsHY1bRC8rVwOqQ==", + "dev": true, + "dependencies": { + "resolve": "~1.17.0", + "strip-json-comments": "~3.1.1" + } + }, + "node_modules/@rushstack/rig-package/node_modules/resolve": { + "version": "1.17.0", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.17.0.tgz", + "integrity": "sha512-ic+7JYiV8Vi2yzQGFWOkiZD5Z9z7O2Zhm9XMaTxdJExKasieFCr+yXZ/WmXsckHiKl12ar0y6XiXDx3m4RHn1w==", + "dev": true, + "dependencies": { + "path-parse": "^1.0.6" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/@rushstack/ts-command-line": { + "version": "4.10.2", + "resolved": "https://registry.npmjs.org/@rushstack/ts-command-line/-/ts-command-line-4.10.2.tgz", + "integrity": "sha512-Weq8B7oJeCQ4ITsaVLhOQombipyg+idpkdkhA6UqLtKvuzq8zTtPpAfhP5ff5L+RCmo1CFCVOBE3i+MvzUR5vA==", + "dev": true, + "dependencies": { + "@types/argparse": "1.0.38", + "argparse": "~1.0.9", + "colors": "~1.2.1", + "string-argv": "~0.3.1" + } + }, "node_modules/@sindresorhus/is": { "version": "0.14.0", "resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-0.14.0.tgz", @@ -236,6 +392,12 @@ "node": ">=6" } }, + "node_modules/@types/argparse": { + "version": "1.0.38", + "resolved": "https://registry.npmjs.org/@types/argparse/-/argparse-1.0.38.tgz", + "integrity": "sha512-ebDJ9b0e702Yr7pWgB0jzm+CX4Srzz8RcXtLJDJB+BSccqMa36uyH/zUsSYao5+BD1ytv3k3rPYCq4mAE1hsXA==", + "dev": true + }, "node_modules/@types/body-parser": { "version": "1.19.1", "resolved": "https://registry.npmjs.org/@types/body-parser/-/body-parser-1.19.1.tgz", @@ -1193,6 +1355,15 @@ "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=" }, + "node_modules/colors": { + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/colors/-/colors-1.2.5.tgz", + "integrity": "sha512-erNRLao/Y3Fv54qUa0LBB+//Uf3YwMUmdJinN20yMXm9zdKKqH9wt7R9IIVZ+K7ShzfpLV/Zg8+VyrBJYB4lpg==", + "dev": true, + "engines": { + "node": ">=0.1.90" + } + }, "node_modules/combined-stream": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", @@ -1205,6 +1376,13 @@ "node": ">= 0.8" } }, + "node_modules/commander": { + "version": "2.20.3", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", + "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==", + "dev": true, + "optional": true + }, "node_modules/component-emitter": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/component-emitter/-/component-emitter-1.3.0.tgz", @@ -2155,6 +2333,20 @@ "node": ">= 0.6" } }, + "node_modules/fs-extra": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-7.0.1.tgz", + "integrity": "sha512-YJDaCJZEnBmcbw13fvdAM9AwNOJwOzrE4pqMqBq5nFiEqXUqHwlK4B+3pUw6JNvfSPtX05xFHtYy/1ni01eGCw==", + "dev": true, + "dependencies": { + "graceful-fs": "^4.1.2", + "jsonfile": "^4.0.0", + "universalify": "^0.1.0" + }, + "engines": { + "node": ">=6 <7 || >=8" + } + }, "node_modules/fs-minipass": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/fs-minipass/-/fs-minipass-2.1.0.tgz", @@ -2799,6 +2991,12 @@ "integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=", "dev": true }, + "node_modules/jju": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/jju/-/jju-1.4.0.tgz", + "integrity": "sha1-o6vicYryQaKykE+EpiWXDzia4yo=", + "dev": true + }, "node_modules/js-tokens": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", @@ -2861,6 +3059,15 @@ "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==", "dev": true }, + "node_modules/jsonfile": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz", + "integrity": "sha1-h3Gq4HmbZAdrdmQPygWPnBDjPss=", + "dev": true, + "optionalDependencies": { + "graceful-fs": "^4.1.6" + } + }, "node_modules/just-extend": { "version": "4.2.1", "resolved": "https://registry.npmjs.org/just-extend/-/just-extend-4.2.1.tgz", @@ -2938,6 +3145,12 @@ "integrity": "sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk=", "dev": true }, + "node_modules/lodash.isequal": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/lodash.isequal/-/lodash.isequal-4.5.0.tgz", + "integrity": "sha1-QVxEePK8wwEgwizhDtMib30+GOA=", + "dev": true + }, "node_modules/log-symbols": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-4.1.0.tgz", @@ -4517,6 +4730,15 @@ "node": ">=8" } }, + "node_modules/source-map": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/spdx-correct": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/spdx-correct/-/spdx-correct-3.1.1.tgz", @@ -4574,6 +4796,15 @@ "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", "dev": true }, + "node_modules/string-argv": { + "version": "0.3.1", + "resolved": "https://registry.npmjs.org/string-argv/-/string-argv-0.3.1.tgz", + "integrity": "sha512-a1uQGz7IyVy9YwhqjZIZu1c8JO8dNIe20xBmSS6qu9kv++k3JGzCVmprbNN5Kn+BgzD5E7YYwg1CcjuJMRNsvg==", + "dev": true, + "engines": { + "node": ">=0.6.19" + } + }, "node_modules/stringifier": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/stringifier/-/stringifier-1.4.0.tgz", @@ -4843,6 +5074,12 @@ "integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=", "dev": true }, + "node_modules/timsort": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/timsort/-/timsort-0.3.0.tgz", + "integrity": "sha1-QFQRqOfmM5/mTbmiNN4R3DHgK9Q=", + "dev": true + }, "node_modules/tmp": { "version": "0.0.33", "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.33.tgz", @@ -5009,6 +5246,15 @@ "object-keys": "^1.0.0" } }, + "node_modules/universalify": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz", + "integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==", + "dev": true, + "engines": { + "node": ">= 4.0.0" + } + }, "node_modules/unpipe": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", @@ -5092,6 +5338,15 @@ "spdx-expression-parse": "^3.0.0" } }, + "node_modules/validator": { + "version": "8.2.0", + "resolved": "https://registry.npmjs.org/validator/-/validator-8.2.0.tgz", + "integrity": "sha512-Yw5wW34fSv5spzTXNkokD6S6/Oq92d8q/t14TqsS3fAiA1RYnxSFSIZ+CY3n6PGGRCq5HhJTSepQvFUS2QUDxA==", + "dev": true, + "engines": { + "node": ">= 0.10" + } + }, "node_modules/vary": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", @@ -5463,6 +5718,23 @@ "engines": { "node": ">=10" } + }, + "node_modules/z-schema": { + "version": "3.18.4", + "resolved": "https://registry.npmjs.org/z-schema/-/z-schema-3.18.4.tgz", + "integrity": "sha512-DUOKC/IhbkdLKKiV89gw9DUauTV8U/8yJl1sjf6MtDmzevLKOF2duNJ495S3MFVjqZarr+qNGCPbkg4mu4PpLw==", + "dev": true, + "dependencies": { + "lodash.get": "^4.0.0", + "lodash.isequal": "^4.0.0", + "validator": "^8.0.0" + }, + "bin": { + "z-schema": "bin/z-schema" + }, + "optionalDependencies": { + "commander": "^2.7.1" + } } }, "dependencies": { @@ -5555,6 +5827,72 @@ } } }, + "@microsoft/api-extractor": { + "version": "7.18.16", + "resolved": "https://registry.npmjs.org/@microsoft/api-extractor/-/api-extractor-7.18.16.tgz", + "integrity": "sha512-f0EcjGgS8IToUHxfQIr4vxGpBhUdaDOhGyddZpZ5K9e/GcGkImfkGeHpYbK043f2bZV3aagTx6NcIawwE72BKA==", + "dev": true, + "requires": { + "@microsoft/api-extractor-model": "7.13.13", + "@microsoft/tsdoc": "0.13.2", + "@microsoft/tsdoc-config": "~0.15.2", + "@rushstack/node-core-library": "3.42.3", + "@rushstack/rig-package": "0.3.3", + "@rushstack/ts-command-line": "4.10.2", + "colors": "~1.2.1", + "lodash": "~4.17.15", + "resolve": "~1.17.0", + "semver": "~7.3.0", + "source-map": "~0.6.1", + "typescript": "~4.4.2" + }, + "dependencies": { + "resolve": { + "version": "1.17.0", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.17.0.tgz", + "integrity": "sha512-ic+7JYiV8Vi2yzQGFWOkiZD5Z9z7O2Zhm9XMaTxdJExKasieFCr+yXZ/WmXsckHiKl12ar0y6XiXDx3m4RHn1w==", + "dev": true, + "requires": { + "path-parse": "^1.0.6" + } + }, + "typescript": { + "version": "4.4.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.4.4.tgz", + "integrity": "sha512-DqGhF5IKoBl8WNf8C1gu8q0xZSInh9j1kJJMqT3a94w1JzVaBU4EXOSMrz9yDqMT0xt3selp83fuFMQ0uzv6qA==", + "dev": true + } + } + }, + "@microsoft/api-extractor-model": { + "version": "7.13.13", + "resolved": "https://registry.npmjs.org/@microsoft/api-extractor-model/-/api-extractor-model-7.13.13.tgz", + "integrity": "sha512-4Hz2TOL4TljsAfMQe7a8tm+Am8+AkrcgkbnH62S9YuaIC3Cw6jE4H2qP8WC2JJInWJP4pg/ZrUlHrtmtgrqn9Q==", + "dev": true, + "requires": { + "@microsoft/tsdoc": "0.13.2", + "@microsoft/tsdoc-config": "~0.15.2", + "@rushstack/node-core-library": "3.42.3" + } + }, + "@microsoft/tsdoc": { + "version": "0.13.2", + "resolved": "https://registry.npmjs.org/@microsoft/tsdoc/-/tsdoc-0.13.2.tgz", + "integrity": "sha512-WrHvO8PDL8wd8T2+zBGKrMwVL5IyzR3ryWUsl0PXgEV0QHup4mTLi0QcATefGI6Gx9Anu7vthPyyyLpY0EpiQg==", + "dev": true + }, + "@microsoft/tsdoc-config": { + "version": "0.15.2", + "resolved": "https://registry.npmjs.org/@microsoft/tsdoc-config/-/tsdoc-config-0.15.2.tgz", + "integrity": "sha512-mK19b2wJHSdNf8znXSMYVShAHktVr/ib0Ck2FA3lsVBSEhSI/TfXT7DJQkAYgcztTuwazGcg58ZjYdk0hTCVrA==", + "dev": true, + "requires": { + "@microsoft/tsdoc": "0.13.2", + "ajv": "~6.12.6", + "jju": "~1.4.0", + "resolve": "~1.19.0" + } + }, "@nodelib/fs.scandir": { "version": "2.1.4", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.4.tgz", @@ -5581,6 +5919,79 @@ "fastq": "^1.6.0" } }, + "@rushstack/node-core-library": { + "version": "3.42.3", + "resolved": "https://registry.npmjs.org/@rushstack/node-core-library/-/node-core-library-3.42.3.tgz", + "integrity": "sha512-xtiJsHtO4Sf/hVKyf/8d58p3zQh2JAZNs1mmDNCyIlgSRYGdqUkpadvvn5mz7EwF6lwn+xTTaTV5/a32xKjbdw==", + "dev": true, + "requires": { + "@types/node": "12.20.24", + "colors": "~1.2.1", + "fs-extra": "~7.0.1", + "import-lazy": "~4.0.0", + "jju": "~1.4.0", + "resolve": "~1.17.0", + "semver": "~7.3.0", + "timsort": "~0.3.0", + "z-schema": "~3.18.3" + }, + "dependencies": { + "@types/node": { + "version": "12.20.24", + "resolved": "https://registry.npmjs.org/@types/node/-/node-12.20.24.tgz", + "integrity": "sha512-yxDeaQIAJlMav7fH5AQqPH1u8YIuhYJXYBzxaQ4PifsU0GDO38MSdmEDeRlIxrKbC6NbEaaEHDanWb+y30U8SQ==", + "dev": true + }, + "import-lazy": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/import-lazy/-/import-lazy-4.0.0.tgz", + "integrity": "sha512-rKtvo6a868b5Hu3heneU+L4yEQ4jYKLtjpnPeUdK7h0yzXGmyBTypknlkCvHFBqfX9YlorEiMM6Dnq/5atfHkw==", + "dev": true + }, + "resolve": { + "version": "1.17.0", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.17.0.tgz", + "integrity": "sha512-ic+7JYiV8Vi2yzQGFWOkiZD5Z9z7O2Zhm9XMaTxdJExKasieFCr+yXZ/WmXsckHiKl12ar0y6XiXDx3m4RHn1w==", + "dev": true, + "requires": { + "path-parse": "^1.0.6" + } + } + } + }, + "@rushstack/rig-package": { + "version": "0.3.3", + "resolved": "https://registry.npmjs.org/@rushstack/rig-package/-/rig-package-0.3.3.tgz", + "integrity": "sha512-ElPnChxIkUzcU3ywI0Cl7E1aM+2w6vFpAwM6X+oWk7Cyjf2ofItThje9e5qUBtKqvI9sc5jVsHY1bRC8rVwOqQ==", + "dev": true, + "requires": { + "resolve": "~1.17.0", + "strip-json-comments": "~3.1.1" + }, + "dependencies": { + "resolve": { + "version": "1.17.0", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.17.0.tgz", + "integrity": "sha512-ic+7JYiV8Vi2yzQGFWOkiZD5Z9z7O2Zhm9XMaTxdJExKasieFCr+yXZ/WmXsckHiKl12ar0y6XiXDx3m4RHn1w==", + "dev": true, + "requires": { + "path-parse": "^1.0.6" + } + } + } + }, + "@rushstack/ts-command-line": { + "version": "4.10.2", + "resolved": "https://registry.npmjs.org/@rushstack/ts-command-line/-/ts-command-line-4.10.2.tgz", + "integrity": "sha512-Weq8B7oJeCQ4ITsaVLhOQombipyg+idpkdkhA6UqLtKvuzq8zTtPpAfhP5ff5L+RCmo1CFCVOBE3i+MvzUR5vA==", + "dev": true, + "requires": { + "@types/argparse": "1.0.38", + "argparse": "~1.0.9", + "colors": "~1.2.1", + "string-argv": "~0.3.1" + } + }, "@sindresorhus/is": { "version": "0.14.0", "resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-0.14.0.tgz", @@ -5631,6 +6042,12 @@ "defer-to-connect": "^1.0.1" } }, + "@types/argparse": { + "version": "1.0.38", + "resolved": "https://registry.npmjs.org/@types/argparse/-/argparse-1.0.38.tgz", + "integrity": "sha512-ebDJ9b0e702Yr7pWgB0jzm+CX4Srzz8RcXtLJDJB+BSccqMa36uyH/zUsSYao5+BD1ytv3k3rPYCq4mAE1hsXA==", + "dev": true + }, "@types/body-parser": { "version": "1.19.1", "resolved": "https://registry.npmjs.org/@types/body-parser/-/body-parser-1.19.1.tgz", @@ -6450,6 +6867,12 @@ "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=" }, + "colors": { + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/colors/-/colors-1.2.5.tgz", + "integrity": "sha512-erNRLao/Y3Fv54qUa0LBB+//Uf3YwMUmdJinN20yMXm9zdKKqH9wt7R9IIVZ+K7ShzfpLV/Zg8+VyrBJYB4lpg==", + "dev": true + }, "combined-stream": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", @@ -6459,6 +6882,13 @@ "delayed-stream": "~1.0.0" } }, + "commander": { + "version": "2.20.3", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", + "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==", + "dev": true, + "optional": true + }, "component-emitter": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/component-emitter/-/component-emitter-1.3.0.tgz", @@ -7227,6 +7657,17 @@ "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", "integrity": "sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac=" }, + "fs-extra": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-7.0.1.tgz", + "integrity": "sha512-YJDaCJZEnBmcbw13fvdAM9AwNOJwOzrE4pqMqBq5nFiEqXUqHwlK4B+3pUw6JNvfSPtX05xFHtYy/1ni01eGCw==", + "dev": true, + "requires": { + "graceful-fs": "^4.1.2", + "jsonfile": "^4.0.0", + "universalify": "^0.1.0" + } + }, "fs-minipass": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/fs-minipass/-/fs-minipass-2.1.0.tgz", @@ -7730,6 +8171,12 @@ "integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=", "dev": true }, + "jju": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/jju/-/jju-1.4.0.tgz", + "integrity": "sha1-o6vicYryQaKykE+EpiWXDzia4yo=", + "dev": true + }, "js-tokens": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", @@ -7785,6 +8232,15 @@ } } }, + "jsonfile": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz", + "integrity": "sha1-h3Gq4HmbZAdrdmQPygWPnBDjPss=", + "dev": true, + "requires": { + "graceful-fs": "^4.1.6" + } + }, "just-extend": { "version": "4.2.1", "resolved": "https://registry.npmjs.org/just-extend/-/just-extend-4.2.1.tgz", @@ -7850,6 +8306,12 @@ "integrity": "sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk=", "dev": true }, + "lodash.isequal": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/lodash.isequal/-/lodash.isequal-4.5.0.tgz", + "integrity": "sha1-QVxEePK8wwEgwizhDtMib30+GOA=", + "dev": true + }, "log-symbols": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-4.1.0.tgz", @@ -9105,6 +9567,12 @@ } } }, + "source-map": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", + "dev": true + }, "spdx-correct": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/spdx-correct/-/spdx-correct-3.1.1.tgz", @@ -9161,6 +9629,12 @@ } } }, + "string-argv": { + "version": "0.3.1", + "resolved": "https://registry.npmjs.org/string-argv/-/string-argv-0.3.1.tgz", + "integrity": "sha512-a1uQGz7IyVy9YwhqjZIZu1c8JO8dNIe20xBmSS6qu9kv++k3JGzCVmprbNN5Kn+BgzD5E7YYwg1CcjuJMRNsvg==", + "dev": true + }, "stringifier": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/stringifier/-/stringifier-1.4.0.tgz", @@ -9379,6 +9853,12 @@ "integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=", "dev": true }, + "timsort": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/timsort/-/timsort-0.3.0.tgz", + "integrity": "sha1-QFQRqOfmM5/mTbmiNN4R3DHgK9Q=", + "dev": true + }, "tmp": { "version": "0.0.33", "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.33.tgz", @@ -9505,6 +9985,12 @@ "object-keys": "^1.0.0" } }, + "universalify": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz", + "integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==", + "dev": true + }, "unpipe": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", @@ -9576,6 +10062,12 @@ "spdx-expression-parse": "^3.0.0" } }, + "validator": { + "version": "8.2.0", + "resolved": "https://registry.npmjs.org/validator/-/validator-8.2.0.tgz", + "integrity": "sha512-Yw5wW34fSv5spzTXNkokD6S6/Oq92d8q/t14TqsS3fAiA1RYnxSFSIZ+CY3n6PGGRCq5HhJTSepQvFUS2QUDxA==", + "dev": true + }, "vary": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", @@ -9865,6 +10357,18 @@ "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", "integrity": "sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==", "dev": true + }, + "z-schema": { + "version": "3.18.4", + "resolved": "https://registry.npmjs.org/z-schema/-/z-schema-3.18.4.tgz", + "integrity": "sha512-DUOKC/IhbkdLKKiV89gw9DUauTV8U/8yJl1sjf6MtDmzevLKOF2duNJ495S3MFVjqZarr+qNGCPbkg4mu4PpLw==", + "dev": true, + "requires": { + "commander": "^2.7.1", + "lodash.get": "^4.0.0", + "lodash.isequal": "^4.0.0", + "validator": "^8.0.0" + } } } } diff --git a/package.json b/package.json index e005209b..4ce489ea 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,8 @@ "clean": "gts clean", "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", "pretest": "npm run compile" @@ -37,6 +39,7 @@ "author": "Google Inc.", "license": "Apache-2.0", "devDependencies": { + "@microsoft/api-extractor": "^7.18.16", "@types/body-parser": "1.19.1", "@types/express": "4.17.13", "@types/minimist": "1.2.2", diff --git a/src/cloudevents.ts b/src/cloudevents.ts index d02a994f..d6a8c802 100644 --- a/src/cloudevents.ts +++ b/src/cloudevents.ts @@ -34,9 +34,9 @@ export const CE_SERVICE = { * Checks whether the incoming request is a CloudEvents event in binary content * mode. This is verified by checking the presence of required headers. * - * @link https://github.com/cloudevents/spec/blob/master/http-protocol-binding.md#3-http-message-mapping + * {@link https://github.com/cloudevents/spec/blob/master/http-protocol-binding.md#3-http-message-mapping} * - * @param req Express request object. + * @param req - Express request object. * @return True if the request is a CloudEvents event in binary content mode, * false otherwise. */ diff --git a/src/function_registry.ts b/src/function_registry.ts index 7c113e0f..c8cd56ab 100644 --- a/src/function_registry.ts +++ b/src/function_registry.ts @@ -53,8 +53,9 @@ export const getRegisteredFunction = ( /** * 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 + * @param functionName - the name of the function + * @param handler - the function to invoke when handling HTTP requests + * @public */ export const http = (functionName: string, handler: HttpFunction): void => { register(functionName, 'http', handler); @@ -62,8 +63,9 @@ export const http = (functionName: string, handler: HttpFunction): void => { /** * Register a function that handles CloudEvents. - * @param functionName the name of the function - * @param handler the function to trigger when handling cloudevents + * @param functionName - the name of the function + * @param handler - the function to trigger when handling cloudevents + * @public */ export const cloudevent = ( functionName: string, diff --git a/src/functions.ts b/src/functions.ts index dbc11966..d29ec17c 100644 --- a/src/functions.ts +++ b/src/functions.ts @@ -18,21 +18,45 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ import * as express from 'express'; +/** + * A HTTP function handler. + * @public + */ export interface HttpFunction { (req: express.Request, res: express.Response): any; } +/** + * A legacy event function handler. + * @public + */ export interface EventFunction { (data: {}, context: Context): any; } +/** + * A legacy event function handler with callback. + * @public + */ export interface EventFunctionWithCallback { (data: {}, context: Context, callback: Function): any; } +/** + * A cloudevent function handler. + * @public + */ export interface CloudEventFunction { (cloudevent: CloudEventsContext): any; } +/** + * A cloudevent function handler with callback. + * @public + */ export interface CloudEventFunctionWithCallback { (cloudevent: CloudEventsContext, callback: Function): any; } +/** + * A function handler. + * @public + */ export type HandlerFunction = | HttpFunction | EventFunction @@ -42,21 +66,30 @@ export type HandlerFunction = /** * A legacy event. + * @public */ export interface LegacyEvent { data: {[key: string]: any}; context: CloudFunctionsContext; } -interface Data { +/** + * A data object used for legacy event functions. + * @public + */ +export interface Data { data: object; } +/** + * A legacy event function context. + * @public + */ export type LegacyCloudFunctionsContext = CloudFunctionsContext | Data; /** * The Cloud Functions context object for the event. - * - * @link https://cloud.google.com/functions/docs/writing/background#function_parameters + * {@link https://cloud.google.com/functions/docs/writing/background#function_parameters} + * @public */ export interface CloudFunctionsContext { /** @@ -80,8 +113,8 @@ export interface CloudFunctionsContext { /** * The CloudEvents v1.0 context object for the event. - * - * @link https://github.com/cloudevents/spec/blob/master/spec.md#context-attributes + * {@link https://github.com/cloudevents/spec/blob/master/spec.md#context-attributes} + * @public */ export interface CloudEventsContext { /** @@ -133,4 +166,8 @@ export interface CloudEventsContext { traceparent?: string; } +/** + * The function's context. + * @public + */ export type Context = CloudFunctionsContext | CloudEventsContext; diff --git a/src/index.ts b/src/index.ts index eb7d4819..bd6adf01 100644 --- a/src/index.ts +++ b/src/index.ts @@ -16,8 +16,14 @@ import {main} from './main'; +/** + * @public + */ export * from './functions'; +/** + * @public + */ export {http, cloudevent} from './function_registry'; // Call the main method to load the user code and start the http server. diff --git a/src/pubsub_middleware.ts b/src/pubsub_middleware.ts index 037e8f7d..f3a9482a 100644 --- a/src/pubsub_middleware.ts +++ b/src/pubsub_middleware.ts @@ -22,7 +22,7 @@ const PUBSUB_SERVICE = 'pubsub.googleapis.com'; /** * The request body of an HTTP request received directly from a Pub/Sub subscription. * - * @link https://cloud.google.com/pubsub/docs/push?hl=en#receiving_messages + * {@link https://cloud.google.com/pubsub/docs/push?hl=en#receiving_messages} */ export interface RawPubSubBody { /** @@ -34,7 +34,7 @@ export interface RawPubSubBody { * A message that is published by publishers and consumed by subscribers. The message must * contain either a non-empty data field or at least one attribute. * - * @link https://cloud.google.com/pubsub/docs/reference/rest/v1/PubsubMessage + * {@link https://cloud.google.com/pubsub/docs/reference/rest/v1/PubsubMessage} */ message: { /** diff --git a/tsconfig.json b/tsconfig.json index d58583cd..429a08b1 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,10 +2,12 @@ "extends": "gts/tsconfig-google.json", "compilerOptions": { "rootDir": ".", - "outDir": "build" + "outDir": "build", + "declaration": true, + "declarationMap": true }, "include": [ "src/**/*.ts", "test/**/*.ts" ] -} +} \ No newline at end of file