From cad6a3700237eabde0080192e59aaad384fe1e97 Mon Sep 17 00:00:00 2001 From: tsuf239 <39455181+tsuf239@users.noreply.github.com> Date: Tue, 29 Aug 2023 19:38:08 +0300 Subject: [PATCH] add variadic params to jsii docgen --- .../src/docgen/transpile/transpile.ts | 5 +++++ apps/jsii-docgen/src/docgen/transpile/wing.ts | 10 +++++++++- .../__snapshots__/documentation.test.ts.snap | 16 ++++++++-------- .../view/__snapshots__/interface.test.ts.snap | 4 ++-- .../view/__snapshots__/markdown.test.ts.snap | 16 ++++++++-------- docs/docs/04-standard-library/01-cloud/queue.md | 2 +- .../04-standard-library/02-std/api-reference.md | 2 +- libs/wingsdk/.projenrc.ts | 2 +- 8 files changed, 35 insertions(+), 22 deletions(-) diff --git a/apps/jsii-docgen/src/docgen/transpile/transpile.ts b/apps/jsii-docgen/src/docgen/transpile/transpile.ts index e7bd685c294..efff36ae4e5 100644 --- a/apps/jsii-docgen/src/docgen/transpile/transpile.ts +++ b/apps/jsii-docgen/src/docgen/transpile/transpile.ts @@ -275,6 +275,11 @@ export interface TranspiledParameter { * supports that. */ readonly declaration: string; + + /** + * Is the parameter variadic + */ + readonly variadic?: boolean; } /** diff --git a/apps/jsii-docgen/src/docgen/transpile/wing.ts b/apps/jsii-docgen/src/docgen/transpile/wing.ts index 4d1b5e826c6..d95a4f2dbc1 100644 --- a/apps/jsii-docgen/src/docgen/transpile/wing.ts +++ b/apps/jsii-docgen/src/docgen/transpile/wing.ts @@ -174,6 +174,7 @@ export class WingTranspile extends transpile.TranspileBase { parentType: this.type(parameter.parentType), typeReference: typeRef, optional: parameter.optional, + variadic: parameter.spec.variadic, declaration: this.formatProperty(name, typeRef), }; } @@ -280,7 +281,14 @@ export class WingTranspile extends transpile.TranspileBase { if (tf === "Inflight") { tf = "~Inflight"; } - return `${transpiled.name}${transpiled.optional ? "?" : ""}: ${tf}`; + if (transpiled.variadic) { + tf = `Array<${tf}>`; + } + const name = transpiled.variadic + ? `...${transpiled.name}` + : transpiled.name; + + return `${name}${transpiled.optional ? "?" : ""}: ${tf}`; } private formatProperty( diff --git a/apps/jsii-docgen/test/docgen/view/__snapshots__/documentation.test.ts.snap b/apps/jsii-docgen/test/docgen/view/__snapshots__/documentation.test.ts.snap index 1d020625cea..6efd2d8f85a 100644 --- a/apps/jsii-docgen/test/docgen/view/__snapshots__/documentation.test.ts.snap +++ b/apps/jsii-docgen/test/docgen/view/__snapshots__/documentation.test.ts.snap @@ -163,7 +163,7 @@ for details about allowed filter rules.", }, }, ], - "usage": "addEventNotification(event: EventType, dest: IBucketNotificationDestination, filters: NotificationKeyFilter): void", + "usage": "addEventNotification(event: EventType, dest: IBucketNotificationDestination, ...filters: Array): void", }, Object { "displayName": "addObjectCreatedNotification", @@ -220,7 +220,7 @@ for details about allowed filter rules.", }, }, ], - "usage": "addObjectCreatedNotification(dest: IBucketNotificationDestination, filters: NotificationKeyFilter): void", + "usage": "addObjectCreatedNotification(dest: IBucketNotificationDestination, ...filters: Array): void", }, Object { "displayName": "addObjectRemovedNotification", @@ -277,7 +277,7 @@ for details about allowed filter rules.", }, }, ], - "usage": "addObjectRemovedNotification(dest: IBucketNotificationDestination, filters: NotificationKeyFilter): void", + "usage": "addObjectRemovedNotification(dest: IBucketNotificationDestination, ...filters: Array): void", }, Object { "displayName": "addToResourcePolicy", @@ -433,7 +433,7 @@ to an IPv4 range like this: }, }, ], - "usage": "grantPublicAccess(allowedActions: str, keyPrefix?: str): Grant", + "usage": "grantPublicAccess(...allowedActions: Array, keyPrefix?: str): Grant", }, Object { "displayName": "grantPut", @@ -1506,7 +1506,7 @@ account for data recovery and cleanup later (\`RemovalPolicy.RETAIN\`). ##### \`addEventNotification\` \`\`\`wing -addEventNotification(event: EventType, dest: IBucketNotificationDestination, filters: NotificationKeyFilter): void +addEventNotification(event: EventType, dest: IBucketNotificationDestination, ...filters: Array): void \`\`\` Adds a bucket notification event destination. @@ -1551,7 +1551,7 @@ for details about allowed filter rules. ##### \`addObjectCreatedNotification\` \`\`\`wing -addObjectCreatedNotification(dest: IBucketNotificationDestination, filters: NotificationKeyFilter): void +addObjectCreatedNotification(dest: IBucketNotificationDestination, ...filters: Array): void \`\`\` Subscribes a destination to receive notifications when an object is created in the bucket. @@ -1578,7 +1578,7 @@ Filters (see onEvent). ##### \`addObjectRemovedNotification\` \`\`\`wing -addObjectRemovedNotification(dest: IBucketNotificationDestination, filters: NotificationKeyFilter): void +addObjectRemovedNotification(dest: IBucketNotificationDestination, ...filters: Array): void \`\`\` Subscribes a destination to receive notifications when an object is removed from the bucket. @@ -1663,7 +1663,7 @@ Restrict the permission to a certain key pattern (default '*'). ##### \`grantPublicAccess\` \`\`\`wing -grantPublicAccess(allowedActions: str, keyPrefix?: str): Grant +grantPublicAccess(...allowedActions: Array, keyPrefix?: str): Grant \`\`\` Allows unrestricted access to objects from this bucket. diff --git a/apps/jsii-docgen/test/docgen/view/__snapshots__/interface.test.ts.snap b/apps/jsii-docgen/test/docgen/view/__snapshots__/interface.test.ts.snap index 7a2cf8b6937..8792e6cd812 100644 --- a/apps/jsii-docgen/test/docgen/view/__snapshots__/interface.test.ts.snap +++ b/apps/jsii-docgen/test/docgen/view/__snapshots__/interface.test.ts.snap @@ -4886,7 +4886,7 @@ Object { }, }, ], - "usage": "grant(grantee: IGrantable, actions: str): Grant", + "usage": "grant(grantee: IGrantable, ...actions: Array): Grant", }, Object { "displayName": "grantPull", @@ -5312,7 +5312,7 @@ Add a policy statement to the repository's resource policy. ## \`grant\` \`\`\`wing -grant(grantee: IGrantable, actions: str): Grant +grant(grantee: IGrantable, ...actions: Array): Grant \`\`\` Grant the given principal identity permissions to perform the actions on this repository. diff --git a/apps/jsii-docgen/test/docgen/view/__snapshots__/markdown.test.ts.snap b/apps/jsii-docgen/test/docgen/view/__snapshots__/markdown.test.ts.snap index 9790618904f..66441d2cdf0 100644 --- a/apps/jsii-docgen/test/docgen/view/__snapshots__/markdown.test.ts.snap +++ b/apps/jsii-docgen/test/docgen/view/__snapshots__/markdown.test.ts.snap @@ -87,7 +87,7 @@ account for data recovery and cleanup later (\`RemovalPolicy.RETAIN\`). ##### \`addEventNotification\` \`\`\`wing -addEventNotification(event: EventType, dest: IBucketNotificationDestination, filters: NotificationKeyFilter): void +addEventNotification(event: EventType, dest: IBucketNotificationDestination, ...filters: Array): void \`\`\` Adds a bucket notification event destination. @@ -132,7 +132,7 @@ for details about allowed filter rules. ##### \`addObjectCreatedNotification\` \`\`\`wing -addObjectCreatedNotification(dest: IBucketNotificationDestination, filters: NotificationKeyFilter): void +addObjectCreatedNotification(dest: IBucketNotificationDestination, ...filters: Array): void \`\`\` Subscribes a destination to receive notifications when an object is created in the bucket. @@ -159,7 +159,7 @@ Filters (see onEvent). ##### \`addObjectRemovedNotification\` \`\`\`wing -addObjectRemovedNotification(dest: IBucketNotificationDestination, filters: NotificationKeyFilter): void +addObjectRemovedNotification(dest: IBucketNotificationDestination, ...filters: Array): void \`\`\` Subscribes a destination to receive notifications when an object is removed from the bucket. @@ -244,7 +244,7 @@ Restrict the permission to a certain key pattern (default '*'). ##### \`grantPublicAccess\` \`\`\`wing -grantPublicAccess(allowedActions: str, keyPrefix?: str): Grant +grantPublicAccess(...allowedActions: Array, keyPrefix?: str): Grant \`\`\` Allows unrestricted access to objects from this bucket. @@ -1010,7 +1010,7 @@ account for data recovery and cleanup later (\`RemovalPolicy.RETAIN\`). ##### \`addEventNotification\` \`\`\`wing -addEventNotification(event: EventType, dest: IBucketNotificationDestination, filters: NotificationKeyFilter): void +addEventNotification(event: EventType, dest: IBucketNotificationDestination, ...filters: Array): void \`\`\` Adds a bucket notification event destination. @@ -1055,7 +1055,7 @@ for details about allowed filter rules. ##### \`addObjectCreatedNotification\` \`\`\`wing -addObjectCreatedNotification(dest: IBucketNotificationDestination, filters: NotificationKeyFilter): void +addObjectCreatedNotification(dest: IBucketNotificationDestination, ...filters: Array): void \`\`\` Subscribes a destination to receive notifications when an object is created in the bucket. @@ -1082,7 +1082,7 @@ Filters (see onEvent). ##### \`addObjectRemovedNotification\` \`\`\`wing -addObjectRemovedNotification(dest: IBucketNotificationDestination, filters: NotificationKeyFilter): void +addObjectRemovedNotification(dest: IBucketNotificationDestination, ...filters: Array): void \`\`\` Subscribes a destination to receive notifications when an object is removed from the bucket. @@ -1167,7 +1167,7 @@ Restrict the permission to a certain key pattern (default '*'). ##### \`grantPublicAccess\` \`\`\`wing -grantPublicAccess(allowedActions: str, keyPrefix?: str): Grant +grantPublicAccess(...allowedActions: Array, keyPrefix?: str): Grant \`\`\` Allows unrestricted access to objects from this bucket. diff --git a/docs/docs/04-standard-library/01-cloud/queue.md b/docs/docs/04-standard-library/01-cloud/queue.md index 487b88c507a..b872a267307 100644 --- a/docs/docs/04-standard-library/01-cloud/queue.md +++ b/docs/docs/04-standard-library/01-cloud/queue.md @@ -170,7 +170,7 @@ Purge all of the messages in the queue. ##### `push` ```wing -inflight push(messages: str): void +inflight push(...messages: Array): void ``` Push one or more messages to the queue. diff --git a/docs/docs/04-standard-library/02-std/api-reference.md b/docs/docs/04-standard-library/02-std/api-reference.md index e1ce2b51dc8..378859ce769 100644 --- a/docs/docs/04-standard-library/02-std/api-reference.md +++ b/docs/docs/04-standard-library/02-std/api-reference.md @@ -1784,7 +1784,7 @@ metadata describing how one construct is related to another construct. ##### `addDependency` ```wing -addDependency(deps: IDependable): void +addDependency(...deps: Array): void ``` Add an ordering dependency on another construct. diff --git a/libs/wingsdk/.projenrc.ts b/libs/wingsdk/.projenrc.ts index b6c52a838a1..e53951f0adc 100644 --- a/libs/wingsdk/.projenrc.ts +++ b/libs/wingsdk/.projenrc.ts @@ -6,7 +6,7 @@ const UNDOCUMENTED_CLOUD_FILES = ["index", "test-runner"]; const cloudFiles = readdirSync("./src/cloud"); const cloudResources: Set = new Set( - cloudFiles.map((filename) => filename.split(".").slice(0, -1).join(".")) + cloudFiles.map((filename) => filename.split(".")[0]) ); UNDOCUMENTED_CLOUD_FILES.forEach((file) => cloudResources.delete(file));