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
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
189 changes: 189 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
/**
* This file was automatically generated by json-schema-to-typescript.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
* and run json-schema-to-typescript to regenerate this file.
*/

export type ErrorCode = string;
export type CloudFunctionRuntime =
| 'nodejs6'
| 'nodejs8'
| 'nodejs10'
| 'nodejs12'
| 'nodejs14'
| 'nodejs16'
| 'python37'
| 'python38'
| 'python39'
| 'go111'
| 'go113'
| 'go116'
| 'java11'
| 'dotnet3'
| 'ruby26'
| 'ruby27';
export type CloudFunctionMemory = 128 | 256 | 512 | 1024 | 2048 | 4096;
export type CloudFunctionVpcEgress = 'ALL' | 'ALL_TRAFFIC' | 'PRIVATE' | 'PRIVATE_RANGES_ONLY';
export type CloudFunctionRegion =
| 'us-central1'
| 'us-east1'
| 'us-east4'
| 'europe-west1'
| 'europe-west2'
| 'asia-east1'
| 'asia-east2'
| 'asia-northeast1'
| 'asia-northeast2'
| 'us-west2'
| 'us-west3'
| 'us-west4'
| 'northamerica-northeast1'
| 'southamerica-east1'
| 'europe-west3'
| 'europe-west6'
| 'europe-central2'
| 'australia-southeast1'
| 'asia-south1'
| 'asia-southeast1'
| 'asia-southeast2'
| 'asia-northeast3';
export type ServiceName = string;

export interface GCP {
configValidationMode?: 'error' | 'warn' | 'off';
console?:
| boolean
| {
monitoring?: {
logs?: {
disabled?: boolean;
};
request?: {
disabled?: boolean;
};
response?: {
disabled?: boolean;
};
};
org?: string;
};
custom?: {
[k: string]: unknown;
};
dashboard?: {
disableMonitoring?: boolean;
};
deprecationNotificationMode?: 'error' | 'warn' | 'warn:summary';
disabledDeprecations?: '*' | ErrorCode[];
frameworkVersion?: string;
functions?: {
/**
* This interface was referenced by `undefined`'s JSON-Schema definition
* via the `patternProperty` "^[a-zA-Z0-9-_]+$".
*/
[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

| {
__schemaWorkaround__: null;
}
| {
http: string;
}
| {
event: {
eventType: string;
path?: string;
resource: string;
failurePolicy?: {
retry?: {
[k: string]: unknown;
};
};
};
}
)[];
handler?: string;
runtime?: CloudFunctionRuntime;
serviceAccountEmail?: string;
memorySize?: CloudFunctionMemory;
timeout?: string;
minInstances?: number;
environment?: CloudFunctionEnvironmentVariables;
secrets?: CloudFunctionSecretEnvironmentVariables;
vpc?: string;
vpcEgress?: CloudFunctionVpcEgress;
labels?: ResourceManagerLabels;
};
};
package?: {
artifact?: string;
exclude?: string[];
excludeDevDependencies?: boolean;
include?: string[];
individually?: boolean;
path?: string;
patterns?: string[];
};
params?: {
/**
* This interface was referenced by `undefined`'s JSON-Schema definition
* via the `patternProperty` "^[a-zA-Z0-9-]+$".
*/
[k: string]: {
[k: string]: unknown;
};
};
plugins?:
| {
localPath?: string;
modules: string[];
}
| string[];
projectDir?: string;
provider: {
name: 'google';
credentials?: string;
project?: string;
region?: CloudFunctionRegion;
runtime?: CloudFunctionRuntime;
serviceAccountEmail?: string;
memorySize?: CloudFunctionMemory;
timeout?: string;
environment?: CloudFunctionEnvironmentVariables;
secrets?: CloudFunctionSecretEnvironmentVariables;
vpc?: string;
vpcEgress?: CloudFunctionVpcEgress;
labels?: ResourceManagerLabels;
stage?: string;
};
service: ServiceName;
useDotenv?: true;
variablesResolutionMode?: '20210219' | '20210326';
}
export interface CloudFunctionEnvironmentVariables {
/**
* This interface was referenced by `CloudFunctionEnvironmentVariables`'s JSON-Schema definition
* via the `patternProperty` "^.*$".
*/
[k: string]: string;
}
export interface CloudFunctionSecretEnvironmentVariables {
/**
* This interface was referenced by `CloudFunctionSecretEnvironmentVariables`'s JSON-Schema definition
* via the `patternProperty` "^[a-zA-Z0-9_]+$".
*/
[k: string]: {
projectId?: string;
secret: string;
version: string;
[k: string]: unknown;
};
}
export interface ResourceManagerLabels {
/**
* This interface was referenced by `ResourceManagerLabels`'s JSON-Schema definition
* via the `patternProperty` "^[a-z][a-z0-9_.]*$".
*/
[k: string]: string;
}