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

feat: Add serverless configuration TS typings #297

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ericrav
Copy link

@ericrav ericrav commented Oct 12, 2022

These are generated from the provider JSON schema using the plugin used to generate the AWS Serverless config typings: https://github.com/serverless/typescript

Usage:

// serverless.ts
import type { GCP } from 'serverless-google-cloudfunctions';

const serverlessConfiguration: GCP = {
  provider: {
    name: 'google',
    // ...
  }
};

module.exports = serverlessConfiguration;

A future PR may add this process to the CI workflow so any provider JSON schema changes are automatically captured in changes to the TypeScript .d.ts file, as is done in @serverless/typescript

*/
[k: string]: {
name?: string;
events?: (

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this was auto generated, but this library throws when events is not present.

Error: Missing "events" property for function "X". Your function needs at least one "event". Please check the docs for more info.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got the source:

validateEventsProperty(funcObject, functionName, supportedEvents = ['http', 'event']) {
if (!funcObject.events || funcObject.events.length === 0) {
const errorMessage = [
`Missing "events" property for function "${functionName}".`,
' Your function needs at least one "event".',
' Please check the docs for more info.',
].join('');
throw new Error(errorMessage);
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Perhaps these keys should also be added as required in the JSON schema https://github.com/serverless/serverless-google-cloudfunctions/blob/master/provider/googleProvider.js#L151

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree.

Haven't seen much in the way of maintenance on this repo lately. Hopefully this can get some attention and get in there.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems adding event's causes a runtime error. Pretty strange though, as many of the other properties should also fall under this boat:

events: {
  type: 'string',
  items: { $ref: '#/definitions/cloudFunctionEvent' },
},

The type of cloudFunctionEvent nor the events key doesn't seem to matter. Even string threw this error.

Property 'functions[].events' already have a definition - this property might have already been defined by the Serverless framework or one other plugin

@christopher-caldwell
Copy link

Love this, having the types for the AWS version is really helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants