From 25512ad6c6539fda1d203a49fee0e28069181bf5 Mon Sep 17 00:00:00 2001 From: Chris Rybicki Date: Mon, 29 Apr 2024 00:26:27 -0400 Subject: [PATCH] chore: remove _supportedOps (#6350) Fixes #6353 The information provided by this method is basically a lighter form of `_liftMap` and the duplication introduces some confusion while iterating on lifting code, so this finishes migrating some of the code over. Most of this is boilerplate that the compiler generates for you under ordinary circumstances. Misc: * Added some checks to `wing-api-checker` to ensure `@inflight` annotations are added to SDK resources written in TypeScript. ## Checklist - [ ] Title matches [Winglang's style guide](https://www.winglang.io/contributing/start-here/pull_requests#how-are-pull-request-titles-formatted) - [ ] Description explains motivation and solution - [ ] Tests added (always) - [ ] Docs updated (only required for features) - [ ] Added `pr/e2e-full` label if this feature requires end-to-end testing *By submitting this pull request, I confirm that my contribution is made under the terms of the [Wing Cloud Contribution License](https://github.com/winglang/wing/blob/main/CONTRIBUTION_LICENSE.md)*. --- apps/wing-api-checker/src/index.ts | 31 ++++++- docs/docs/04-standard-library/cloud/domain.md | 9 --- .../04-standard-library/cloud/endpoint.md | 9 --- .../04-standard-library/sim/api-reference.md | 10 +-- libs/awscdk/src/bucket.ts | 48 ++++++----- libs/awscdk/src/counter.ts | 30 +++---- libs/awscdk/src/function.ts | 11 +-- libs/awscdk/src/queue.ts | 80 +++++++++++-------- libs/awscdk/src/secret.ts | 25 +++--- libs/awscdk/src/topic.ts | 41 ++++++---- libs/wingc/src/dtsify/mod.rs | 3 - .../src/dtsify/snapshots/declarations.snap | 2 - .../wingc/src/dtsify/snapshots/optionals.snap | 1 - libs/wingsdk/src/cloud/domain.ts | 1 + libs/wingsdk/src/cloud/endpoint.ts | 1 + libs/wingsdk/src/core/inflight.ts | 15 ++-- libs/wingsdk/src/core/lifting.ts | 34 +++----- libs/wingsdk/src/ex/redis.ts | 6 ++ libs/wingsdk/src/ex/table.ts | 6 ++ libs/wingsdk/src/shared-aws/bucket.ts | 38 ++++----- libs/wingsdk/src/shared-aws/domain.ts | 1 + libs/wingsdk/src/shared-aws/function.ts | 12 +-- libs/wingsdk/src/shared-aws/queue.ts | 18 ++--- libs/wingsdk/src/simulator/testing.ts | 10 +-- libs/wingsdk/src/std/resource.ts | 23 ++---- libs/wingsdk/src/std/test-runner.ts | 12 +-- libs/wingsdk/src/std/test.ts | 6 +- libs/wingsdk/src/target-sim/bucket.ts | 35 ++++---- libs/wingsdk/src/target-sim/container.ts | 6 +- libs/wingsdk/src/target-sim/counter.ts | 15 ++-- libs/wingsdk/src/target-sim/event-mapping.ts | 5 +- libs/wingsdk/src/target-sim/function.ts | 13 ++- libs/wingsdk/src/target-sim/policy.ts | 9 +++ libs/wingsdk/src/target-sim/queue.ts | 15 ++-- libs/wingsdk/src/target-sim/redis.ts | 23 +++--- libs/wingsdk/src/target-sim/secret.ts | 11 +-- libs/wingsdk/src/target-sim/service.ts | 15 ++-- libs/wingsdk/src/target-sim/state.ts | 13 +-- libs/wingsdk/src/target-sim/table.ts | 21 ++--- libs/wingsdk/src/target-sim/topic.ts | 11 +-- libs/wingsdk/src/target-tf-aws/bucket.ts | 36 ++++----- libs/wingsdk/src/target-tf-aws/counter.ts | 14 ++-- libs/wingsdk/src/target-tf-aws/function.ts | 10 +-- libs/wingsdk/src/target-tf-aws/queue.ts | 14 ++-- libs/wingsdk/src/target-tf-aws/redis.ts | 22 ++--- libs/wingsdk/src/target-tf-aws/secret.ts | 10 +-- libs/wingsdk/src/target-tf-aws/table.ts | 20 ++--- libs/wingsdk/src/target-tf-aws/topic.ts | 6 +- libs/wingsdk/src/target-tf-azure/bucket.ts | 16 +++- libs/wingsdk/src/target-tf-azure/counter.ts | 14 ++-- libs/wingsdk/src/target-tf-azure/function.ts | 7 +- libs/wingsdk/src/target-tf-gcp/bucket.ts | 38 ++++----- libs/wingsdk/src/target-tf-gcp/counter.ts | 14 ++-- libs/wingsdk/src/target-tf-gcp/function.ts | 7 +- libs/wingsdk/src/target-tf-gcp/table.ts | 5 -- libs/wingsdk/src/ui/base.ts | 1 + libs/wingsdk/src/ui/button.ts | 6 +- libs/wingsdk/src/ui/field.ts | 7 +- libs/wingsdk/src/ui/file-browser.ts | 9 +-- libs/wingsdk/src/ui/http-client.ts | 7 +- libs/wingsdk/src/ui/section.ts | 6 +- libs/wingsdk/test/core/lifting.test.ts | 8 +- libs/wingsdk/test/core/resource.test.ts | 11 ++- 63 files changed, 501 insertions(+), 462 deletions(-) diff --git a/apps/wing-api-checker/src/index.ts b/apps/wing-api-checker/src/index.ts index 438ad227bd0..21235403782 100644 --- a/apps/wing-api-checker/src/index.ts +++ b/apps/wing-api-checker/src/index.ts @@ -29,6 +29,16 @@ async function generateWarnings(packageDir: string): Promise { warnings += 1; } + const IResource = interfaces.find((x) => x.name === "IResource"); + if (!IResource) { + throw new Error("IResource not found"); + } + + const IInflight = interfaces.find((x) => x.name === "IInflight"); + if (!IInflight) { + throw new Error("IInflight not found"); + } + for (const cls of classes) { if (!cls.docs.summary) { warn(`Missing docstring for ${cls.fqn} (${loc(cls)})`); @@ -40,6 +50,21 @@ async function generateWarnings(packageDir: string): Promise { ); } } + if ( + cls.getInterfaces(true).includes(IResource) || + cls.getInterfaces(true).includes(IInflight) + ) { + if ( + cls.docs.customTag("inflight") === undefined && + cls.docs.customTag("noinflight") === undefined + ) { + warn( + `Missing @inflight in docstring for ${cls.fqn} (${loc( + cls + )}). Suppress with @noinflight.` + ); + } + } } for (const iface of interfaces) { @@ -57,7 +82,11 @@ async function generateWarnings(packageDir: string): Promise { if (iface.name.endsWith("Props")) { for (const prop of iface.allProperties) { if (prop.optional && !prop.docs.docs.default) { - warn(`Missing @default for ${iface.fqn}.${prop.name} (${loc(prop)})`); + warn( + `Missing @default in docstring for ${iface.fqn}.${prop.name} (${loc( + prop + )})` + ); } } } diff --git a/docs/docs/04-standard-library/cloud/domain.md b/docs/docs/04-standard-library/cloud/domain.md index 0ccb3af5fe5..08372fc76e9 100644 --- a/docs/docs/04-standard-library/cloud/domain.md +++ b/docs/docs/04-standard-library/cloud/domain.md @@ -201,13 +201,4 @@ The website's custom domain name. ``` -## Protocols - -### IDomainClient - -- *Implemented By:* IDomainClient - -Inflight interface for `Domain`. - - diff --git a/docs/docs/04-standard-library/cloud/endpoint.md b/docs/docs/04-standard-library/cloud/endpoint.md index de5f2bb3b21..ba2a15efa3d 100644 --- a/docs/docs/04-standard-library/cloud/endpoint.md +++ b/docs/docs/04-standard-library/cloud/endpoint.md @@ -299,13 +299,4 @@ For UI purposes. ``` -## Protocols - -### IEndpointClient - -- *Implemented By:* IEndpointClient - -Inflight interface for `Endpoint`. - - diff --git a/docs/docs/04-standard-library/sim/api-reference.md b/docs/docs/04-standard-library/sim/api-reference.md index 426bc5b5824..36ec8416893 100644 --- a/docs/docs/04-standard-library/sim/api-reference.md +++ b/docs/docs/04-standard-library/sim/api-reference.md @@ -154,6 +154,8 @@ new sim.Policy(props: PolicyProps); #### Methods +##### Preflight Methods + | **Name** | **Description** | | --- | --- | | addStatement | Adds a statement to the policy. | @@ -611,14 +613,6 @@ The resource to which the policy is attached. ## Protocols -### IPolicyClient - -- *Implemented By:* IPolicyClient - -Inflight interface for `Policy`. - - - ### ISimulatorInflightHost - *Extends:* IInflightHost diff --git a/libs/awscdk/src/bucket.ts b/libs/awscdk/src/bucket.ts index d6d20585c98..784f338d2a9 100644 --- a/libs/awscdk/src/bucket.ts +++ b/libs/awscdk/src/bucket.ts @@ -14,7 +14,12 @@ import { cloud, core, std } from "@winglang/sdk"; import { convertBetweenHandlers } from "@winglang/sdk/lib/shared/convert"; import { calculateBucketPermissions } from "@winglang/sdk/lib/shared-aws/permissions"; import { IAwsBucket } from "@winglang/sdk/lib/shared-aws/bucket"; -import { IAwsCdkFunction, addPolicyStatements, isAwsCdkFunction } from "./function"; +import { + IAwsCdkFunction, + addPolicyStatements, + isAwsCdkFunction, +} from "./function"; +import { LiftMap } from "@winglang/sdk/lib/core"; const EVENTS = { [cloud.BucketEventType.DELETE]: EventType.OBJECT_REMOVED, @@ -81,24 +86,24 @@ export class Bucket extends cloud.Bucket implements IAwsBucket { } /** @internal */ - public _supportedOps(): string[] { - return [ - cloud.BucketInflightMethods.DELETE, - cloud.BucketInflightMethods.GET, - cloud.BucketInflightMethods.GET_JSON, - cloud.BucketInflightMethods.LIST, - cloud.BucketInflightMethods.PUT, - cloud.BucketInflightMethods.PUT_JSON, - cloud.BucketInflightMethods.PUBLIC_URL, - cloud.BucketInflightMethods.EXISTS, - cloud.BucketInflightMethods.TRY_GET, - cloud.BucketInflightMethods.TRY_GET_JSON, - cloud.BucketInflightMethods.TRY_DELETE, - cloud.BucketInflightMethods.SIGNED_URL, - cloud.BucketInflightMethods.METADATA, - cloud.BucketInflightMethods.COPY, - cloud.BucketInflightMethods.RENAME, - ]; + public get _liftMap(): LiftMap { + return { + [cloud.BucketInflightMethods.DELETE]: [], + [cloud.BucketInflightMethods.GET]: [], + [cloud.BucketInflightMethods.GET_JSON]: [], + [cloud.BucketInflightMethods.LIST]: [], + [cloud.BucketInflightMethods.PUT]: [], + [cloud.BucketInflightMethods.PUT_JSON]: [], + [cloud.BucketInflightMethods.PUBLIC_URL]: [], + [cloud.BucketInflightMethods.EXISTS]: [], + [cloud.BucketInflightMethods.TRY_GET]: [], + [cloud.BucketInflightMethods.TRY_GET_JSON]: [], + [cloud.BucketInflightMethods.TRY_DELETE]: [], + [cloud.BucketInflightMethods.SIGNED_URL]: [], + [cloud.BucketInflightMethods.METADATA]: [], + [cloud.BucketInflightMethods.COPY]: [], + [cloud.BucketInflightMethods.RENAME]: [], + }; } public onCreate( @@ -197,7 +202,10 @@ export class Bucket extends cloud.Bucket implements IAwsBucket { throw new Error("Expected 'host' to implement IAwsCdkFunction"); } - addPolicyStatements(host.awscdkFunction, calculateBucketPermissions(this.bucket.bucketArn, ops)); + addPolicyStatements( + host.awscdkFunction, + calculateBucketPermissions(this.bucket.bucketArn, ops) + ); // The bucket name needs to be passed through an environment variable since // it may not be resolved until deployment time. diff --git a/libs/awscdk/src/counter.ts b/libs/awscdk/src/counter.ts index e474c28bfb5..baee4fbfed4 100644 --- a/libs/awscdk/src/counter.ts +++ b/libs/awscdk/src/counter.ts @@ -6,6 +6,7 @@ import { COUNTER_HASH_KEY } from "@winglang/sdk/lib/shared-aws/commons"; import { calculateCounterPermissions } from "@winglang/sdk/lib/shared-aws/permissions"; import { IAwsCounter } from "@winglang/sdk/lib/shared-aws/counter"; import { addPolicyStatements, isAwsCdkFunction } from "./function"; +import { LiftMap } from "@winglang/sdk/lib/core"; /** * AWS implementation of `cloud.Counter`. @@ -26,13 +27,13 @@ export class Counter extends cloud.Counter implements IAwsCounter { } /** @internal */ - public _supportedOps(): string[] { - return [ - cloud.CounterInflightMethods.INC, - cloud.CounterInflightMethods.DEC, - cloud.CounterInflightMethods.PEEK, - cloud.CounterInflightMethods.SET, - ]; + public get _liftMap(): LiftMap { + return { + [cloud.CounterInflightMethods.INC]: [], + [cloud.CounterInflightMethods.DEC]: [], + [cloud.CounterInflightMethods.PEEK]: [], + [cloud.CounterInflightMethods.SET]: [], + }; } public onLift(host: std.IInflightHost, ops: string[]): void { @@ -40,7 +41,10 @@ export class Counter extends cloud.Counter implements IAwsCounter { throw new Error("Expected 'host' to implement 'isAwsCdkFunction' method"); } - addPolicyStatements(host.awscdkFunction, calculateCounterPermissions(this.table.tableArn, ops)); + addPolicyStatements( + host.awscdkFunction, + calculateCounterPermissions(this.table.tableArn, ops) + ); host.addEnvironment(this.envName(), this.table.tableName); @@ -49,12 +53,10 @@ export class Counter extends cloud.Counter implements IAwsCounter { /** @internal */ public _toInflight(): string { - return core.InflightClient.for( - __dirname, - __filename, - "CounterClient", - [`process.env["${this.envName()}"]`, `${this.initial}`] - ); + return core.InflightClient.for(__dirname, __filename, "CounterClient", [ + `process.env["${this.envName()}"]`, + `${this.initial}`, + ]); } private envName(): string { diff --git a/libs/awscdk/src/function.ts b/libs/awscdk/src/function.ts index 5ac2a3311d8..aca1e1ebae6 100644 --- a/libs/awscdk/src/function.ts +++ b/libs/awscdk/src/function.ts @@ -16,6 +16,7 @@ import { IAwsFunction, PolicyStatement } from "@winglang/sdk/lib/shared-aws"; import { resolve } from "path"; import { renameSync, rmSync, writeFileSync } from "fs"; import { App } from "./app"; +import { LiftMap } from "@winglang/sdk/lib/core"; /** * Implementation of `awscdk.Function` are expected to implement this @@ -104,11 +105,11 @@ export class Function } /** @internal */ - public _supportedOps(): string[] { - return [ - cloud.FunctionInflightMethods.INVOKE, - cloud.FunctionInflightMethods.INVOKE_ASYNC, - ]; + public get _liftMap(): LiftMap { + return { + [cloud.FunctionInflightMethods.INVOKE]: [], + [cloud.FunctionInflightMethods.INVOKE_ASYNC]: [], + }; } public onLift(host: std.IInflightHost, ops: string[]): void { diff --git a/libs/awscdk/src/queue.ts b/libs/awscdk/src/queue.ts index 54eb0426dfc..51159109369 100644 --- a/libs/awscdk/src/queue.ts +++ b/libs/awscdk/src/queue.ts @@ -5,8 +5,13 @@ import { Construct } from "constructs"; import { App } from "./app"; import { std, core, cloud } from "@winglang/sdk"; import { calculateQueuePermissions } from "@winglang/sdk/lib/shared-aws/permissions"; -import { IAwsQueue, Queue as AwsQueue, QueueSetConsumerHandler } from "@winglang/sdk/lib/shared-aws/queue"; +import { + IAwsQueue, + Queue as AwsQueue, + QueueSetConsumerHandler, +} from "@winglang/sdk/lib/shared-aws/queue"; import { addPolicyStatements, isAwsCdkFunction } from "./function"; +import { LiftMap } from "@winglang/sdk/lib/core"; /** * AWS implementation of `cloud.Queue`. @@ -21,25 +26,32 @@ export class Queue extends cloud.Queue implements IAwsQueue { super(scope, id, props); this.timeout = props.timeout ?? std.Duration.fromSeconds(30); - const queueOpt = props.dlq ? { - visibilityTimeout: props.timeout - ? Duration.seconds(props.timeout?.seconds) - : Duration.seconds(30), - retentionPeriod: props.retentionPeriod - ? Duration.seconds(props.retentionPeriod?.seconds) - : Duration.hours(1), - deadLetterQueue: { - queue: SQSQueue.fromQueueArn(this, "DeadLetterQueue", AwsQueue.from(props.dlq.queue)?.queueArn!), - maxReceiveCount: props.dlq.maxDeliveryAttempts ?? cloud.DEFAULT_DELIVERY_ATTEMPTS, - } - } : { - visibilityTimeout: props.timeout - ? Duration.seconds(props.timeout?.seconds) - : Duration.seconds(30), - retentionPeriod: props.retentionPeriod - ? Duration.seconds(props.retentionPeriod?.seconds) - : Duration.hours(1), - } + const queueOpt = props.dlq + ? { + visibilityTimeout: props.timeout + ? Duration.seconds(props.timeout?.seconds) + : Duration.seconds(30), + retentionPeriod: props.retentionPeriod + ? Duration.seconds(props.retentionPeriod?.seconds) + : Duration.hours(1), + deadLetterQueue: { + queue: SQSQueue.fromQueueArn( + this, + "DeadLetterQueue", + AwsQueue.from(props.dlq.queue)?.queueArn! + ), + maxReceiveCount: + props.dlq.maxDeliveryAttempts ?? cloud.DEFAULT_DELIVERY_ATTEMPTS, + }, + } + : { + visibilityTimeout: props.timeout + ? Duration.seconds(props.timeout?.seconds) + : Duration.seconds(30), + retentionPeriod: props.retentionPeriod + ? Duration.seconds(props.retentionPeriod?.seconds) + : Duration.hours(1), + }; this.queue = new SQSQueue(this, "Default", queueOpt); } @@ -82,13 +94,13 @@ export class Queue extends cloud.Queue implements IAwsQueue { } /** @internal */ - public _supportedOps(): string[] { - return [ - cloud.QueueInflightMethods.PUSH, - cloud.QueueInflightMethods.PURGE, - cloud.QueueInflightMethods.APPROX_SIZE, - cloud.QueueInflightMethods.POP, - ]; + public get _liftMap(): LiftMap { + return { + [cloud.QueueInflightMethods.PUSH]: [], + [cloud.QueueInflightMethods.PURGE]: [], + [cloud.QueueInflightMethods.APPROX_SIZE]: [], + [cloud.QueueInflightMethods.POP]: [], + }; } public onLift(host: std.IInflightHost, ops: string[]): void { @@ -98,7 +110,10 @@ export class Queue extends cloud.Queue implements IAwsQueue { const env = this.envName(); - addPolicyStatements(host.awscdkFunction, calculateQueuePermissions(this.queue.queueArn, ops)); + addPolicyStatements( + host.awscdkFunction, + calculateQueuePermissions(this.queue.queueArn, ops) + ); // The queue url needs to be passed through an environment variable since // it may not be resolved until deployment time. @@ -109,12 +124,9 @@ export class Queue extends cloud.Queue implements IAwsQueue { /** @internal */ public _toInflight(): string { - return core.InflightClient.for( - __dirname, - __filename, - "QueueClient", - [`process.env["${this.envName()}"]`] - ); + return core.InflightClient.for(__dirname, __filename, "QueueClient", [ + `process.env["${this.envName()}"]`, + ]); } private envName(): string { diff --git a/libs/awscdk/src/secret.ts b/libs/awscdk/src/secret.ts index 5e660fffa0f..e3999d356eb 100644 --- a/libs/awscdk/src/secret.ts +++ b/libs/awscdk/src/secret.ts @@ -7,6 +7,7 @@ import { Construct } from "constructs"; import { addPolicyStatements, isAwsCdkFunction } from "./function"; import { cloud, core, std } from "@winglang/sdk"; import { calculateSecretPermissions } from "@winglang/sdk/lib/shared-aws/permissions"; +import { LiftMap } from "@winglang/sdk/lib/core"; /** * AWS Implemntation of `cloud.Secret` @@ -33,11 +34,11 @@ export class Secret extends cloud.Secret { } /** @internal */ - public _supportedOps(): string[] { - return [ - cloud.SecretInflightMethods.VALUE, - cloud.SecretInflightMethods.VALUE_JSON, - ]; + public get _liftMap(): LiftMap { + return { + [cloud.SecretInflightMethods.VALUE]: [], + [cloud.SecretInflightMethods.VALUE_JSON]: [], + }; } /** @@ -52,7 +53,10 @@ export class Secret extends cloud.Secret { throw new Error("Expected 'host' to implement 'isAwsCdkFunction' method"); } - addPolicyStatements(host.awscdkFunction, calculateSecretPermissions(this.arnForPolicies, ops)); + addPolicyStatements( + host.awscdkFunction, + calculateSecretPermissions(this.arnForPolicies, ops) + ); host.addEnvironment(this.envName(), this.secret.secretArn); @@ -61,12 +65,9 @@ export class Secret extends cloud.Secret { /** @internal */ public _toInflight(): string { - return core.InflightClient.for( - __dirname, - __filename, - "SecretClient", - [`process.env["${this.envName()}"]`] - ); + return core.InflightClient.for(__dirname, __filename, "SecretClient", [ + `process.env["${this.envName()}"]`, + ]); } private envName(): string { diff --git a/libs/awscdk/src/topic.ts b/libs/awscdk/src/topic.ts index d08377e05f5..f938e0ea213 100644 --- a/libs/awscdk/src/topic.ts +++ b/libs/awscdk/src/topic.ts @@ -1,13 +1,20 @@ import { Topic as SNSTopic } from "aws-cdk-lib/aws-sns"; import { Queue as SQSQeueue } from "aws-cdk-lib/aws-sqs"; -import { LambdaSubscription, SqsSubscription } from "aws-cdk-lib/aws-sns-subscriptions"; +import { + LambdaSubscription, + SqsSubscription, +} from "aws-cdk-lib/aws-sns-subscriptions"; import { Construct } from "constructs"; import { App } from "./app"; import { cloud, core, std } from "@winglang/sdk"; import { calculateTopicPermissions } from "@winglang/sdk/lib/shared-aws/permissions"; -import { IAwsTopic, TopicOnMessageHandler } from "@winglang/sdk/lib/shared-aws/topic"; +import { + IAwsTopic, + TopicOnMessageHandler, +} from "@winglang/sdk/lib/shared-aws/topic"; import { addPolicyStatements, isAwsCdkFunction } from "./function"; import { Queue } from "./queue"; +import { LiftMap } from "@winglang/sdk/lib/core"; /** * AWS Implementation of `cloud.Topic`. @@ -27,7 +34,7 @@ export class Topic extends cloud.Topic implements IAwsTopic { props: cloud.TopicOnMessageOptions = {} ): cloud.Function { const functionHandler = TopicOnMessageHandler.toFunctionHandler(inflight); - + const fn = new cloud.Function( this.node.scope!, // ok since we're not a tree root App.of(this).makeId(this, `${this.node.id}-OnMessage`), @@ -36,7 +43,9 @@ export class Topic extends cloud.Topic implements IAwsTopic { ); if (!isAwsCdkFunction(fn)) { - throw new Error("Expected function to implement 'IAwsCdkFunction' method"); + throw new Error( + "Expected function to implement 'IAwsCdkFunction' method" + ); } const subscription = new LambdaSubscription(fn.awscdkFunction); @@ -53,7 +62,9 @@ export class Topic extends cloud.Topic implements IAwsTopic { public subscribeQueue(queue: cloud.Queue): void { if (!(queue instanceof Queue)) { - throw new Error("'subscribeQueue' allows only tfaws.Queue to be subscribed to the Topic"); + throw new Error( + "'subscribeQueue' allows only tfaws.Queue to be subscribed to the Topic" + ); } const baseTopic = SNSTopic.fromTopicArn(this, "BaseTopic", this.topicArn); @@ -66,7 +77,10 @@ export class Topic extends cloud.Topic implements IAwsTopic { throw new Error("Expected 'host' to implement 'IAwsCdkFunction' method"); } - addPolicyStatements(host.awscdkFunction, calculateTopicPermissions(this.topic.topicArn, ops)); + addPolicyStatements( + host.awscdkFunction, + calculateTopicPermissions(this.topic.topicArn, ops) + ); host.addEnvironment(this.envName(), this.topic.topicArn); @@ -75,16 +89,15 @@ export class Topic extends cloud.Topic implements IAwsTopic { /** @internal */ public _toInflight(): string { - return core.InflightClient.for( - __dirname, - __filename, - "TopicClient", - [`process.env["${this.envName()}"]`] - ); + return core.InflightClient.for(__dirname, __filename, "TopicClient", [ + `process.env["${this.envName()}"]`, + ]); } /** @internal */ - public _supportedOps(): string[] { - return [cloud.TopicInflightMethods.PUBLISH]; + public get _liftMap(): LiftMap { + return { + [cloud.TopicInflightMethods.PUBLISH]: [], + }; } /** @internal */ diff --git a/libs/wingc/src/dtsify/mod.rs b/libs/wingc/src/dtsify/mod.rs index da42fa58b5b..06c87959438 100644 --- a/libs/wingc/src/dtsify/mod.rs +++ b/libs/wingc/src/dtsify/mod.rs @@ -207,9 +207,6 @@ impl<'a> DTSifier<'a> { code.line(format!( "[{TYPE_INTERNAL_NAMESPACE}.INFLIGHT_SYMBOL]?: {inflight_class_name};" )); - code.line(format!( - "_supportedOps(): {TYPE_INTERNAL_NAMESPACE}.OperationsOf<{inflight_class_name}>;" - )); } for field in class diff --git a/libs/wingc/src/dtsify/snapshots/declarations.snap b/libs/wingc/src/dtsify/snapshots/declarations.snap index 1633a1efb69..4e3603c5386 100644 --- a/libs/wingc/src/dtsify/snapshots/declarations.snap +++ b/libs/wingc/src/dtsify/snapshots/declarations.snap @@ -203,7 +203,6 @@ export class ParentClass extends std.Resource implements ClassInterface { constructor(scope: $internal.Construct, id: string); [$internal.INFLIGHT_SYMBOL]?: ParentClass$Inflight; - _supportedOps(): $internal.OperationsOf; addHandler: (handler: $internal.Inflight<(arg0: string) => Promise>) => void; } export class ParentClass$Inflight implements ClassInterface$Inflight @@ -216,7 +215,6 @@ export class Child extends ParentClass implements ClassInterface { constructor(scope: $internal.Construct, id: string); [$internal.INFLIGHT_SYMBOL]?: Child$Inflight; - _supportedOps(): $internal.OperationsOf; } export class Child$Inflight extends ParentClass$Inflight implements ClassInterface$Inflight { diff --git a/libs/wingc/src/dtsify/snapshots/optionals.snap b/libs/wingc/src/dtsify/snapshots/optionals.snap index 6d761424825..a5a79c3eb84 100644 --- a/libs/wingc/src/dtsify/snapshots/optionals.snap +++ b/libs/wingc/src/dtsify/snapshots/optionals.snap @@ -126,7 +126,6 @@ export class ParentClass extends std.Resource implements ClassInterface { constructor(scope: $internal.Construct, id: string); [$internal.INFLIGHT_SYMBOL]?: ParentClass$Inflight; - _supportedOps(): $internal.OperationsOf; addHandler: (handler: $internal.Inflight<(arg0?: (string) | undefined) => Promise>, s?: (Struct) | undefined) => void; } export class ParentClass$Inflight implements ClassInterface$Inflight diff --git a/libs/wingsdk/src/cloud/domain.ts b/libs/wingsdk/src/cloud/domain.ts index 43e5c1018ce..35f3781cc94 100644 --- a/libs/wingsdk/src/cloud/domain.ts +++ b/libs/wingsdk/src/cloud/domain.ts @@ -20,6 +20,7 @@ export interface DomainProps { /** * A cloud Domain + * @inflight `@winglang/sdk.cloud.IDomainClient` * @abstract */ export class Domain extends Resource { diff --git a/libs/wingsdk/src/cloud/endpoint.ts b/libs/wingsdk/src/cloud/endpoint.ts index 509be13915e..fa49790743d 100644 --- a/libs/wingsdk/src/cloud/endpoint.ts +++ b/libs/wingsdk/src/cloud/endpoint.ts @@ -27,6 +27,7 @@ export interface EndpointProps { /** * A cloud Endpoint + * @inflight `@winglang/sdk.cloud.IEndpointClient` * @abstract */ export class Endpoint extends Resource { diff --git a/libs/wingsdk/src/core/inflight.ts b/libs/wingsdk/src/core/inflight.ts index 6061c233509..8d0b8e51a20 100644 --- a/libs/wingsdk/src/core/inflight.ts +++ b/libs/wingsdk/src/core/inflight.ts @@ -1,5 +1,5 @@ import { basename } from "path"; -import { liftObject, LiftDepsMatrixRaw } from "./lifting"; +import { liftObject, LiftMap } from "./lifting"; import { AsyncFunction, INFLIGHT_SYMBOL, @@ -218,16 +218,12 @@ class Lifter< // inflight methods are called on an object // The SDK models inflight functions as objects with a "handle" property, // so here we annotate that "handle" needs all of the required permissions - const _liftMap: LiftDepsMatrixRaw = { handle: [], $inflight_init: [] }; + const _liftMap: LiftMap = { handle: [] }; for (const [key, obj] of Object.entries(this.lifts)) { let knownOps = this.grants[key]; - if ( - knownOps === undefined && - typeof (obj as IHostedLiftable)?._supportedOps === "function" - ) { - knownOps = (obj as IHostedLiftable)._supportedOps(); - } - _liftMap.handle.push([obj, knownOps ?? []]); + knownOps = + knownOps ?? Object.keys((obj as IHostedLiftable)._liftMap ?? {}); + _liftMap.handle.push([obj, knownOps]); } return { @@ -253,7 +249,6 @@ class Lifter< )())`; }, _liftMap, - _supportedOps: () => [], // @ts-expect-error This function's type doesn't actually match, but it will just throw anyways [INFLIGHT_SYMBOL]: () => { throw new Error( diff --git a/libs/wingsdk/src/core/lifting.ts b/libs/wingsdk/src/core/lifting.ts index be32c670d66..737f4cfd434 100644 --- a/libs/wingsdk/src/core/lifting.ts +++ b/libs/wingsdk/src/core/lifting.ts @@ -109,8 +109,8 @@ export function liftObject(obj: any): string { throw new Error(`Unable to lift object of type ${obj?.constructor?.name}`); } -export type LiftDepsMatrixRaw = Record]>>; -export type LiftDepsMatrix = Record>>; +export type LiftMap = Record]>>; +export type LiftMapNormalized = Record>>; /** * Merge two matrixes of lifting dependencies. @@ -118,10 +118,10 @@ export type LiftDepsMatrix = Record>>; * See the unit tests in `lifting.test.ts` for examples. */ export function mergeLiftDeps( - matrix1: LiftDepsMatrix, - matrix2: LiftDepsMatrix -): LiftDepsMatrix { - const result: LiftDepsMatrix = {}; + matrix1: LiftMapNormalized = {}, + matrix2: LiftMapNormalized = {} +): LiftMapNormalized { + const result: LiftMapNormalized = {}; for (const [op, deps] of Object.entries(matrix1)) { result[op] = new Map(); for (const [obj, objDeps] of deps) { @@ -162,8 +162,8 @@ export function mergeLiftDeps( * new Map([obj1, new Set(["op1", "op2"])]) * ``` */ -function parseMatrix(data: LiftDepsMatrixRaw): LiftDepsMatrix { - const result: LiftDepsMatrix = {}; +function parseMatrix(data: LiftMap): LiftMapNormalized { + const result: LiftMapNormalized = {}; for (const [op, pairs] of Object.entries(data)) { result[op] = new Map(); for (const [obj, objDeps] of pairs) { @@ -180,7 +180,7 @@ function parseMatrix(data: LiftDepsMatrixRaw): LiftDepsMatrix { } // for debugging -// function printMatrix(data: LiftDepsMatrix): string { +// function printMatrix(data: LiftMapNormalized): string { // const lines = []; // for (const [op, pairs] of Object.entries(data)) { // lines.push(`${op}: {`); @@ -227,7 +227,7 @@ export function collectLifts( const explored = new Map>(); const queue = new Array<[any, Array]>([initialObj, [...initialOps]]); - const matrixCache = new Map(); + const matrixCache = new Map(); while (queue.length > 0) { // `obj` and `ops` are the preflight object and operations requested on it @@ -258,23 +258,13 @@ export function collectLifts( // Currently there are a few ways to do this: // - The compiler may generate a _liftMap property on the object // - The compiler may generate a static _liftTypeMap method on a class - // - The SDK may have a _supportedOps method on a class (TODO: remove this?) - let matrix: LiftDepsMatrix; + let matrix: LiftMapNormalized; if (matrixCache.has(obj)) { matrix = matrixCache.get(obj)!; } else if (typeof obj === "object" && obj._liftMap !== undefined) { matrix = parseMatrix(obj._liftMap ?? {}); matrixCache.set(obj, matrix); - } else if ( - typeof obj === "object" && - typeof obj._supportedOps === "function" - ) { - matrix = {}; - for (const op of obj._supportedOps()) { - matrix[op] = new Map(); - } - matrixCache.set(obj, matrix); } else if ( typeof obj === "function" && typeof obj._liftTypeMap !== undefined @@ -377,7 +367,7 @@ export interface ILiftableType { * inflight host. * @internal */ - _liftTypeMap?: LiftDepsMatrixRaw; + _liftTypeMap?: LiftMap; /** * A hook called by the Wing compiler once for each inflight host that needs to diff --git a/libs/wingsdk/src/ex/redis.ts b/libs/wingsdk/src/ex/redis.ts index 950ac086259..f2ea92a646b 100644 --- a/libs/wingsdk/src/ex/redis.ts +++ b/libs/wingsdk/src/ex/redis.ts @@ -1,5 +1,6 @@ import { Construct } from "constructs"; import { fqnForType } from "../constants"; +import { LiftMap } from "../core"; import { INFLIGHT_SYMBOL } from "../core/types"; import { Node, Resource } from "../std"; @@ -28,6 +29,11 @@ export class Redis extends Resource { Node.of(this).title = "Redis"; Node.of(this).description = "A Redis server"; } + + /** @internal */ + public get _liftMap(): LiftMap { + return {}; + } } /** diff --git a/libs/wingsdk/src/ex/table.ts b/libs/wingsdk/src/ex/table.ts index ad12d4270e4..326c7da5a47 100644 --- a/libs/wingsdk/src/ex/table.ts +++ b/libs/wingsdk/src/ex/table.ts @@ -1,5 +1,6 @@ import { Construct } from "constructs"; import { fqnForType } from "../constants"; +import { LiftMap } from "../core"; import { AbstractMemberError } from "../core/errors"; import { INFLIGHT_SYMBOL } from "../core/types"; import { Json, Node, Resource } from "../std"; @@ -99,6 +100,11 @@ export class Table extends Resource { this.columns = props.columns; } + /** @internal */ + public get _liftMap(): LiftMap { + return {}; + } + /** * Add a row to the table that is created when the app is deployed. * @abstract diff --git a/libs/wingsdk/src/shared-aws/bucket.ts b/libs/wingsdk/src/shared-aws/bucket.ts index a9a9aefeaac..8fce06321b5 100644 --- a/libs/wingsdk/src/shared-aws/bucket.ts +++ b/libs/wingsdk/src/shared-aws/bucket.ts @@ -4,7 +4,7 @@ import { Function } from "./function"; import { calculateBucketPermissions } from "./permissions"; import { cloud, ui } from ".."; import { IBucketClient } from "../cloud"; -import { InflightClient } from "../core"; +import { InflightClient, LiftMap } from "../core"; import { INFLIGHT_SYMBOL } from "../core/types"; import { convertBetweenHandlers } from "../shared/convert"; import { Testing } from "../simulator"; @@ -104,24 +104,24 @@ export class BucketRef extends Resource { } /** @internal */ - public _supportedOps(): string[] { - return [ - cloud.BucketInflightMethods.DELETE, - cloud.BucketInflightMethods.GET, - cloud.BucketInflightMethods.GET_JSON, - cloud.BucketInflightMethods.LIST, - cloud.BucketInflightMethods.PUT, - cloud.BucketInflightMethods.PUT_JSON, - cloud.BucketInflightMethods.PUBLIC_URL, - cloud.BucketInflightMethods.EXISTS, - cloud.BucketInflightMethods.TRY_GET, - cloud.BucketInflightMethods.TRY_GET_JSON, - cloud.BucketInflightMethods.TRY_DELETE, - cloud.BucketInflightMethods.SIGNED_URL, - cloud.BucketInflightMethods.METADATA, - cloud.BucketInflightMethods.COPY, - cloud.BucketInflightMethods.RENAME, - ]; + public get _liftMap(): LiftMap { + return { + [cloud.BucketInflightMethods.DELETE]: [], + [cloud.BucketInflightMethods.GET]: [], + [cloud.BucketInflightMethods.GET_JSON]: [], + [cloud.BucketInflightMethods.LIST]: [], + [cloud.BucketInflightMethods.PUT]: [], + [cloud.BucketInflightMethods.PUT_JSON]: [], + [cloud.BucketInflightMethods.PUBLIC_URL]: [], + [cloud.BucketInflightMethods.EXISTS]: [], + [cloud.BucketInflightMethods.TRY_GET]: [], + [cloud.BucketInflightMethods.TRY_GET_JSON]: [], + [cloud.BucketInflightMethods.TRY_DELETE]: [], + [cloud.BucketInflightMethods.SIGNED_URL]: [], + [cloud.BucketInflightMethods.METADATA]: [], + [cloud.BucketInflightMethods.COPY]: [], + [cloud.BucketInflightMethods.RENAME]: [], + }; } private addUserInterface() { diff --git a/libs/wingsdk/src/shared-aws/domain.ts b/libs/wingsdk/src/shared-aws/domain.ts index 8b06e99092f..dbe90b0a8be 100644 --- a/libs/wingsdk/src/shared-aws/domain.ts +++ b/libs/wingsdk/src/shared-aws/domain.ts @@ -5,6 +5,7 @@ import { NotImplementedError } from "../core/errors"; /** * AWS implementation of `cloud.Domain`. + * @inflight `@winglang/sdk.cloud.IDomainClient` */ export class Domain extends cloud.Domain { /** @internal */ diff --git a/libs/wingsdk/src/shared-aws/function.ts b/libs/wingsdk/src/shared-aws/function.ts index 08c5938a408..2478824a623 100644 --- a/libs/wingsdk/src/shared-aws/function.ts +++ b/libs/wingsdk/src/shared-aws/function.ts @@ -2,7 +2,7 @@ import { Construct } from "constructs"; import { PolicyStatement } from "./types"; import { isValidArn } from "./util"; import { FunctionInflightMethods, IFunctionClient } from "../cloud"; -import { InflightClient } from "../core"; +import { InflightClient, LiftMap } from "../core"; import { INFLIGHT_SYMBOL } from "../core/types"; import { Testing } from "../simulator"; import { IInflightHost, Node, Resource } from "../std"; @@ -117,11 +117,11 @@ export class FunctionRef extends Resource { } /** @internal */ - public _supportedOps(): string[] { - return [ - FunctionInflightMethods.INVOKE, - FunctionInflightMethods.INVOKE_ASYNC, - ]; + public get _liftMap(): LiftMap { + return { + [FunctionInflightMethods.INVOKE]: [], + [FunctionInflightMethods.INVOKE_ASYNC]: [], + }; } private addUserInterface() { diff --git a/libs/wingsdk/src/shared-aws/queue.ts b/libs/wingsdk/src/shared-aws/queue.ts index 0a12a36edd9..56724c3cc1a 100644 --- a/libs/wingsdk/src/shared-aws/queue.ts +++ b/libs/wingsdk/src/shared-aws/queue.ts @@ -5,7 +5,7 @@ import { calculateQueuePermissions } from "./permissions"; import { isValidArn } from "./util"; import { cloud } from ".."; import { IQueueClient } from "../cloud"; -import { InflightClient } from "../core"; +import { InflightClient, LiftMap } from "../core"; import { INFLIGHT_SYMBOL } from "../core/types"; import { convertBetweenHandlers } from "../shared/convert"; import { Testing } from "../simulator"; @@ -108,14 +108,14 @@ export class QueueRef extends Resource { } /** @internal */ - public _supportedOps(): string[] { - return [ - QUEUE_URL_METHOD, // AWS-specific - cloud.QueueInflightMethods.PUSH, - cloud.QueueInflightMethods.PURGE, - cloud.QueueInflightMethods.APPROX_SIZE, - cloud.QueueInflightMethods.POP, - ]; + public get _liftMap(): LiftMap { + return { + [QUEUE_URL_METHOD]: [], // AWS-specific + [cloud.QueueInflightMethods.PUSH]: [], + [cloud.QueueInflightMethods.PURGE]: [], + [cloud.QueueInflightMethods.APPROX_SIZE]: [], + [cloud.QueueInflightMethods.POP]: [], + }; } private addUserInterface() { diff --git a/libs/wingsdk/src/simulator/testing.ts b/libs/wingsdk/src/simulator/testing.ts index d8d3ff822d5..f1cdbb3bb92 100644 --- a/libs/wingsdk/src/simulator/testing.ts +++ b/libs/wingsdk/src/simulator/testing.ts @@ -1,9 +1,4 @@ -import { - InflightBindings, - LiftDepsMatrixRaw, - closureId, - liftObject, -} from "../core"; +import { InflightBindings, LiftMap, closureId, liftObject } from "../core"; import { IInflight, IInflightHost } from "../std"; /** @@ -26,7 +21,7 @@ export class Testing { code: string, bindings: InflightBindings = {} ): IInflight { - const liftDeps: LiftDepsMatrixRaw = {}; + const liftDeps: LiftMap = {}; liftDeps.handle = []; for (const v of Object.values(bindings)) { liftDeps.handle.push([v.obj, v.ops ?? []]); @@ -61,7 +56,6 @@ ${Object.entries(clients) }, _liftMap: liftDeps, onLift: (_host: IInflightHost, _ops: string[]) => {}, - _supportedOps: () => [], }; } } diff --git a/libs/wingsdk/src/std/resource.ts b/libs/wingsdk/src/std/resource.ts index f8bfe10f039..74b81863344 100644 --- a/libs/wingsdk/src/std/resource.ts +++ b/libs/wingsdk/src/std/resource.ts @@ -1,5 +1,5 @@ import { Construct, IConstruct } from "constructs"; -import { App, LiftDepsMatrixRaw } from "../core"; +import { App, LiftMap } from "../core"; import { AbstractMemberError } from "../core/errors"; import { Node } from "../std"; @@ -85,7 +85,7 @@ export interface IHostedLiftable extends ILiftable { * inflight host. * @internal */ - _liftMap?: LiftDepsMatrixRaw; + _liftMap?: LiftMap; /** * A hook called by the Wing compiler once for each inflight host that needs to @@ -96,20 +96,12 @@ export interface IHostedLiftable extends ILiftable { * other capabilities to the inflight host. */ onLift(host: IInflightHost, ops: string[]): void; - - /** - * Return a list of all inflight operations that are supported by this resource. - * - * If this method doesn't exist, the resource is assumed to not support any inflight operations. - * - * @internal - */ - _supportedOps(): string[]; } /** * Abstract interface for `Resource`. * @skipDocs + * @noinflight */ export interface IResource extends IConstruct, IHostedLiftable { /** @@ -126,6 +118,7 @@ export interface IResource extends IConstruct, IHostedLiftable { /** * Shared behavior between all Wing SDK resources. * @skipDocs + * @noinflight */ export abstract class Resource extends Construct implements IResource { /** @@ -167,13 +160,6 @@ export abstract class Resource extends Construct implements IResource { return App.of(scope).newAbstract(fqn, scope, id, ...props); } - /** - * @internal - * */ - public _supportedOps(): string[] { - return []; - } - /** * Return a code snippet that can be used to reference this resource inflight. * @@ -221,6 +207,7 @@ export abstract class Resource extends Construct implements IResource { * A resource that has an automatically generated id. * Used by the Wing compiler to generate unique ids for auto generated resources * from inflight function closures. + * @noinflight */ export abstract class AutoIdResource extends Resource { constructor(scope: Construct, idPrefix: string = "") { diff --git a/libs/wingsdk/src/std/test-runner.ts b/libs/wingsdk/src/std/test-runner.ts index 2b78ef799eb..6979be97f91 100644 --- a/libs/wingsdk/src/std/test-runner.ts +++ b/libs/wingsdk/src/std/test-runner.ts @@ -3,7 +3,7 @@ import { Resource } from "./resource"; import { Test } from "./test"; import { Function, FunctionProps, IFunctionHandler } from "../cloud"; import { fqnForType } from "../constants"; -import { App } from "../core"; +import { App, LiftMap } from "../core"; import { Node } from "../std"; /** @@ -109,11 +109,11 @@ export class TestRunner extends Resource { } /** @internal */ - public _supportedOps(): string[] { - return [ - TestRunnerInflightMethods.LIST_TESTS, - TestRunnerInflightMethods.RUN_TEST, - ]; + public get _liftMap(): LiftMap { + return { + [TestRunnerInflightMethods.LIST_TESTS]: [], + [TestRunnerInflightMethods.RUN_TEST]: [], + }; } /** diff --git a/libs/wingsdk/src/std/test.ts b/libs/wingsdk/src/std/test.ts index 406035b81da..ca101d8e27a 100644 --- a/libs/wingsdk/src/std/test.ts +++ b/libs/wingsdk/src/std/test.ts @@ -1,7 +1,7 @@ import { Construct } from "constructs"; import { Function, FunctionProps } from "../cloud/function"; import { fqnForType } from "../constants"; -import { App } from "../core"; +import { App, LiftMap } from "../core"; import { Node, IInflight, Resource } from "../std"; /** @@ -54,8 +54,8 @@ export class Test extends Resource { } /** @internal */ - public _supportedOps(): string[] { - return []; + public get _liftMap(): LiftMap { + return {}; } /** @internal */ diff --git a/libs/wingsdk/src/target-sim/bucket.ts b/libs/wingsdk/src/target-sim/bucket.ts index 5692b6a117c..977fc823950 100644 --- a/libs/wingsdk/src/target-sim/bucket.ts +++ b/libs/wingsdk/src/target-sim/bucket.ts @@ -6,6 +6,7 @@ import { BucketSchema } from "./schema-resources"; import { simulatorHandleToken } from "./tokens"; import { bindSimulatorResource, makeSimulatorJsClient } from "./util"; import * as cloud from "../cloud"; +import { LiftMap } from "../core"; import { convertBetweenHandlers } from "../shared/convert"; import { ToSimulatorOutput } from "../simulator/simulator"; import { IInflightHost } from "../std"; @@ -28,23 +29,23 @@ export class Bucket extends cloud.Bucket implements ISimulatorResource { } /** @internal */ - public _supportedOps(): string[] { - return [ - cloud.BucketInflightMethods.DELETE, - cloud.BucketInflightMethods.GET, - cloud.BucketInflightMethods.GET_JSON, - cloud.BucketInflightMethods.LIST, - cloud.BucketInflightMethods.PUT, - cloud.BucketInflightMethods.PUT_JSON, - cloud.BucketInflightMethods.PUBLIC_URL, - cloud.BucketInflightMethods.EXISTS, - cloud.BucketInflightMethods.TRY_GET, - cloud.BucketInflightMethods.TRY_GET_JSON, - cloud.BucketInflightMethods.TRY_DELETE, - cloud.BucketInflightMethods.METADATA, - cloud.BucketInflightMethods.COPY, - cloud.BucketInflightMethods.RENAME, - ]; + public get _liftMap(): LiftMap { + return { + [cloud.BucketInflightMethods.DELETE]: [], + [cloud.BucketInflightMethods.GET]: [], + [cloud.BucketInflightMethods.GET_JSON]: [], + [cloud.BucketInflightMethods.LIST]: [], + [cloud.BucketInflightMethods.PUT]: [], + [cloud.BucketInflightMethods.PUT_JSON]: [], + [cloud.BucketInflightMethods.PUBLIC_URL]: [], + [cloud.BucketInflightMethods.EXISTS]: [], + [cloud.BucketInflightMethods.TRY_GET]: [], + [cloud.BucketInflightMethods.TRY_GET_JSON]: [], + [cloud.BucketInflightMethods.TRY_DELETE]: [], + [cloud.BucketInflightMethods.METADATA]: [], + [cloud.BucketInflightMethods.COPY]: [], + [cloud.BucketInflightMethods.RENAME]: [], + }; } /** diff --git a/libs/wingsdk/src/target-sim/container.ts b/libs/wingsdk/src/target-sim/container.ts index 5728c3e713b..0bce58ca47e 100644 --- a/libs/wingsdk/src/target-sim/container.ts +++ b/libs/wingsdk/src/target-sim/container.ts @@ -4,7 +4,7 @@ import { ContainerSchema } from "./schema-resources"; import { simulatorAttrToken } from "./tokens"; import { bindSimulatorResource, makeSimulatorJsClient } from "./util"; import { fqnForType } from "../constants"; -import { App } from "../core"; +import { App, LiftMap } from "../core"; import { INFLIGHT_SYMBOL } from "../core/types"; import { Util as fs } from "../fs"; import { isPath } from "../shared/misc"; @@ -128,8 +128,8 @@ export class Container extends Resource implements ISimulatorResource { } /** @internal */ - public _supportedOps(): string[] { - return []; + public get _liftMap(): LiftMap { + return {}; } /** @internal */ diff --git a/libs/wingsdk/src/target-sim/counter.ts b/libs/wingsdk/src/target-sim/counter.ts index 5015a6cc24b..63b41b87a68 100644 --- a/libs/wingsdk/src/target-sim/counter.ts +++ b/libs/wingsdk/src/target-sim/counter.ts @@ -3,6 +3,7 @@ import { ISimulatorResource } from "./resource"; import { CounterSchema } from "./schema-resources"; import { bindSimulatorResource, makeSimulatorJsClient } from "./util"; import * as cloud from "../cloud"; +import { LiftMap } from "../core"; import { ToSimulatorOutput } from "../simulator/simulator"; import { IInflightHost } from "../std"; @@ -20,13 +21,13 @@ export class Counter extends cloud.Counter implements ISimulatorResource { } /** @internal */ - public _supportedOps(): string[] { - return [ - cloud.CounterInflightMethods.INC, - cloud.CounterInflightMethods.DEC, - cloud.CounterInflightMethods.PEEK, - cloud.CounterInflightMethods.SET, - ]; + public get _liftMap(): LiftMap { + return { + [cloud.CounterInflightMethods.INC]: [], + [cloud.CounterInflightMethods.DEC]: [], + [cloud.CounterInflightMethods.PEEK]: [], + [cloud.CounterInflightMethods.SET]: [], + }; } public toSimulator(): ToSimulatorOutput { diff --git a/libs/wingsdk/src/target-sim/event-mapping.ts b/libs/wingsdk/src/target-sim/event-mapping.ts index 66d9a1604ee..49cc22e9cd4 100644 --- a/libs/wingsdk/src/target-sim/event-mapping.ts +++ b/libs/wingsdk/src/target-sim/event-mapping.ts @@ -8,6 +8,7 @@ import { import { simulatorHandleToken } from "./tokens"; import { bindSimulatorResource, makeSimulatorJsClient } from "./util"; import { fqnForType } from "../constants"; +import { LiftMap } from "../core"; import { ISimulatorResourceInstance, ToSimulatorOutput, @@ -63,8 +64,8 @@ export class EventMapping extends Resource implements ISimulatorResource { } /** @internal */ - public _supportedOps(): string[] { - return []; + public get _liftMap(): LiftMap { + return {}; } public get eventProps(): EventMappingProps { diff --git a/libs/wingsdk/src/target-sim/function.ts b/libs/wingsdk/src/target-sim/function.ts index 90d20b9818f..412586c4ed6 100644 --- a/libs/wingsdk/src/target-sim/function.ts +++ b/libs/wingsdk/src/target-sim/function.ts @@ -5,7 +5,7 @@ import { FunctionSchema } from "./schema-resources"; import { simulatorHandleToken } from "./tokens"; import { bindSimulatorResource, makeSimulatorJsClient } from "./util"; import * as cloud from "../cloud"; -import { App } from "../core"; +import { App, LiftMap } from "../core"; import { PolicyStatement, ToSimulatorOutput } from "../simulator/simulator"; import { IInflightHost, IResource } from "../std"; import { Duration } from "../std/duration"; @@ -27,7 +27,6 @@ export class Function private readonly timeout: Duration; private readonly concurrency: number; private readonly permissions: Array<[IResource, string]> = []; - public _liftMap = undefined; constructor( scope: Construct, @@ -72,11 +71,11 @@ export class Function } /** @internal */ - public _supportedOps(): string[] { - return [ - cloud.FunctionInflightMethods.INVOKE, - cloud.FunctionInflightMethods.INVOKE_ASYNC, - ]; + public get _liftMap(): LiftMap { + return { + [cloud.FunctionInflightMethods.INVOKE]: [], + [cloud.FunctionInflightMethods.INVOKE_ASYNC]: [], + }; } public onLift(host: IInflightHost, ops: string[]): void { diff --git a/libs/wingsdk/src/target-sim/policy.ts b/libs/wingsdk/src/target-sim/policy.ts index 35839c71e78..2faea63f415 100644 --- a/libs/wingsdk/src/target-sim/policy.ts +++ b/libs/wingsdk/src/target-sim/policy.ts @@ -3,6 +3,7 @@ import { ISimulatorResource } from "./resource"; import { PolicySchema } from "./schema-resources"; import { simulatorHandleToken } from "./tokens"; import { fqnForType } from "../constants"; +import { LiftMap } from "../core"; import { PolicyStatement, ToSimulatorOutput } from "../simulator"; import { IResource, Node, Resource } from "../std"; @@ -20,10 +21,13 @@ export interface PolicyProps { /** * Implementation of `sim.Policy`. + * + * @inflight `@winglang/sdk.sim.IPolicyClient` */ export class Policy extends Resource implements ISimulatorResource { private readonly statements: Map> = new Map(); private readonly principal: IResource; + constructor(scope: Construct, id: string, props: PolicyProps) { super(scope, id); this.principal = props.principal; @@ -32,6 +36,11 @@ export class Policy extends Resource implements ISimulatorResource { Node.of(this).description = "A simulated resource policy"; } + /** @internal */ + public get _liftMap(): LiftMap { + return {}; + } + /** * Adds a statement to the policy. */ diff --git a/libs/wingsdk/src/target-sim/queue.ts b/libs/wingsdk/src/target-sim/queue.ts index de99816b2aa..9116d115ab7 100644 --- a/libs/wingsdk/src/target-sim/queue.ts +++ b/libs/wingsdk/src/target-sim/queue.ts @@ -12,6 +12,7 @@ import { QueueSchema } from "./schema-resources"; import { simulatorHandleToken } from "./tokens"; import { bindSimulatorResource, makeSimulatorJsClient } from "./util"; import * as cloud from "../cloud"; +import { LiftMap } from "../core"; import { NotImplementedError } from "../core/errors"; import { convertBetweenHandlers } from "../shared/convert"; import { ToSimulatorOutput } from "../simulator"; @@ -67,13 +68,13 @@ export class Queue extends cloud.Queue implements ISimulatorResource { } /** @internal */ - public _supportedOps(): string[] { - return [ - cloud.QueueInflightMethods.PUSH, - cloud.QueueInflightMethods.PURGE, - cloud.QueueInflightMethods.APPROX_SIZE, - cloud.QueueInflightMethods.POP, - ]; + public get _liftMap(): LiftMap { + return { + [cloud.QueueInflightMethods.PUSH]: [], + [cloud.QueueInflightMethods.PURGE]: [], + [cloud.QueueInflightMethods.APPROX_SIZE]: [], + [cloud.QueueInflightMethods.POP]: [], + }; } public setConsumer( diff --git a/libs/wingsdk/src/target-sim/redis.ts b/libs/wingsdk/src/target-sim/redis.ts index 5d1e402db1e..883b7b2dbb3 100644 --- a/libs/wingsdk/src/target-sim/redis.ts +++ b/libs/wingsdk/src/target-sim/redis.ts @@ -3,6 +3,7 @@ import { Container } from "./container"; import { ISimulatorResource } from "./resource"; import { RedisSchema } from "./schema-resources"; import { bindSimulatorResource, makeSimulatorJsClient } from "./util"; +import { LiftMap } from "../core"; import * as ex from "../ex"; import { ToSimulatorOutput } from "../simulator"; import { IInflightHost } from "../std"; @@ -52,17 +53,17 @@ export class Redis extends ex.Redis implements ISimulatorResource { } /** @internal */ - public _supportedOps(): string[] { - return [ - ex.RedisInflightMethods.URL, - ex.RedisInflightMethods.SET, - ex.RedisInflightMethods.GET, - ex.RedisInflightMethods.HSET, - ex.RedisInflightMethods.HGET, - ex.RedisInflightMethods.SADD, - ex.RedisInflightMethods.SMEMBERS, - ex.RedisInflightMethods.DEL, - ]; + public get _liftMap(): LiftMap { + return { + [ex.RedisInflightMethods.URL]: [], + [ex.RedisInflightMethods.SET]: [], + [ex.RedisInflightMethods.GET]: [], + [ex.RedisInflightMethods.HSET]: [], + [ex.RedisInflightMethods.HGET]: [], + [ex.RedisInflightMethods.SADD]: [], + [ex.RedisInflightMethods.SMEMBERS]: [], + [ex.RedisInflightMethods.DEL]: [], + }; } /** @internal */ diff --git a/libs/wingsdk/src/target-sim/secret.ts b/libs/wingsdk/src/target-sim/secret.ts index 63b3fe92414..8aac98c5d76 100644 --- a/libs/wingsdk/src/target-sim/secret.ts +++ b/libs/wingsdk/src/target-sim/secret.ts @@ -3,6 +3,7 @@ import { ISimulatorResource } from "./resource"; import { SecretSchema } from "./schema-resources"; import { bindSimulatorResource, makeSimulatorJsClient } from "./util"; import * as cloud from "../cloud"; +import { LiftMap } from "../core"; import { ResourceNames } from "../shared/resource-names"; import { ToSimulatorOutput } from "../simulator"; import { IInflightHost } from "../std"; @@ -32,11 +33,11 @@ export class Secret extends cloud.Secret implements ISimulatorResource { } /** @internal */ - public _supportedOps(): string[] { - return [ - cloud.SecretInflightMethods.VALUE, - cloud.SecretInflightMethods.VALUE_JSON, - ]; + public get _liftMap(): LiftMap { + return { + [cloud.SecretInflightMethods.VALUE]: [], + [cloud.SecretInflightMethods.VALUE_JSON]: [], + }; } public toSimulator(): ToSimulatorOutput { diff --git a/libs/wingsdk/src/target-sim/service.ts b/libs/wingsdk/src/target-sim/service.ts index 30ceb811a1a..ba837749d42 100644 --- a/libs/wingsdk/src/target-sim/service.ts +++ b/libs/wingsdk/src/target-sim/service.ts @@ -5,7 +5,7 @@ import { ServiceSchema } from "./schema-resources"; import { simulatorHandleToken } from "./tokens"; import { bindSimulatorResource, makeSimulatorJsClient } from "./util"; import * as cloud from "../cloud"; -import { App } from "../core"; +import { App, LiftMap } from "../core"; import { PolicyStatement, ToSimulatorOutput } from "../simulator"; import { IInflightHost, IResource } from "../std"; @@ -15,7 +15,6 @@ export class Service { private readonly permissions: Array<[IResource, string]> = []; private readonly autoStart: boolean; - public _liftMap = undefined; constructor( scope: Construct, @@ -52,12 +51,12 @@ export class Service } /** @internal */ - public _supportedOps(): string[] { - return [ - cloud.ServiceInflightMethods.START, - cloud.ServiceInflightMethods.STOP, - cloud.ServiceInflightMethods.STARTED, - ]; + public get _liftMap(): LiftMap { + return { + [cloud.ServiceInflightMethods.START]: [], + [cloud.ServiceInflightMethods.STOP]: [], + [cloud.ServiceInflightMethods.STARTED]: [], + }; } public onLift(host: IInflightHost, ops: string[]): void { diff --git a/libs/wingsdk/src/target-sim/state.ts b/libs/wingsdk/src/target-sim/state.ts index b2392b1604d..a0139fadb2a 100644 --- a/libs/wingsdk/src/target-sim/state.ts +++ b/libs/wingsdk/src/target-sim/state.ts @@ -3,6 +3,7 @@ import { StateSchema } from "./schema-resources"; import { simulatorAttrToken } from "./tokens"; import { bindSimulatorResource, makeSimulatorJsClient } from "./util"; import { fqnForType } from "../constants"; +import { LiftMap } from "../core"; import { INFLIGHT_SYMBOL } from "../core/types"; import { ToSimulatorOutput } from "../simulator"; import { IInflightHost, Json, Resource } from "../std"; @@ -40,12 +41,12 @@ export class State extends Resource implements ISimulatorResource { } /** @internal */ - public _supportedOps(): string[] { - return [ - StateInflightMethods.GET, - StateInflightMethods.SET, - StateInflightMethods.TRY_GET, - ]; + public get _liftMap(): LiftMap { + return { + [StateInflightMethods.GET]: [], + [StateInflightMethods.SET]: [], + [StateInflightMethods.TRY_GET]: [], + }; } /** @internal */ diff --git a/libs/wingsdk/src/target-sim/table.ts b/libs/wingsdk/src/target-sim/table.ts index 5dccb8868a8..d303a40d5d0 100644 --- a/libs/wingsdk/src/target-sim/table.ts +++ b/libs/wingsdk/src/target-sim/table.ts @@ -2,6 +2,7 @@ import { Construct } from "constructs"; import { ISimulatorResource } from "./resource"; import { TableSchema } from "./schema-resources"; import { bindSimulatorResource, makeSimulatorJsClient } from "./util"; +import { LiftMap } from "../core"; import * as ex from "../ex"; import { ToSimulatorOutput } from "../simulator/simulator"; import { Json, IInflightHost } from "../std"; @@ -35,16 +36,16 @@ export class Table extends ex.Table implements ISimulatorResource { } /** @internal */ - public _supportedOps(): string[] { - return [ - ex.TableInflightMethods.INSERT, - ex.TableInflightMethods.UPSERT, - ex.TableInflightMethods.UPDATE, - ex.TableInflightMethods.DELETE, - ex.TableInflightMethods.GET, - ex.TableInflightMethods.TRYGET, - ex.TableInflightMethods.LIST, - ]; + public get _liftMap(): LiftMap { + return { + [ex.TableInflightMethods.INSERT]: [], + [ex.TableInflightMethods.UPSERT]: [], + [ex.TableInflightMethods.UPDATE]: [], + [ex.TableInflightMethods.DELETE]: [], + [ex.TableInflightMethods.GET]: [], + [ex.TableInflightMethods.TRYGET]: [], + [ex.TableInflightMethods.LIST]: [], + }; } public onLift(host: IInflightHost, ops: string[]): void { diff --git a/libs/wingsdk/src/target-sim/topic.ts b/libs/wingsdk/src/target-sim/topic.ts index fa2f43b3e34..d91098ac5dd 100644 --- a/libs/wingsdk/src/target-sim/topic.ts +++ b/libs/wingsdk/src/target-sim/topic.ts @@ -8,6 +8,7 @@ import { ISimulatorResource } from "./resource"; import { TopicSchema } from "./schema-resources"; import { bindSimulatorResource, makeSimulatorJsClient } from "./util"; import * as cloud from "../cloud"; +import { LiftMap } from "../core"; import { convertBetweenHandlers } from "../shared/convert"; import { Testing, ToSimulatorOutput } from "../simulator"; import { IInflightHost, Node, SDK_SOURCE_MODULE } from "../std"; @@ -107,11 +108,11 @@ export class Topic extends cloud.Topic implements ISimulatorResource { } /** @internal */ - public _supportedOps(): string[] { - return [ - cloud.QueueInflightMethods.PUSH, - cloud.TopicInflightMethods.PUBLISH, - ]; + public get _liftMap(): LiftMap { + return { + [cloud.QueueInflightMethods.PUSH]: [], + [cloud.TopicInflightMethods.PUBLISH]: [], + }; } public toSimulator(): ToSimulatorOutput { diff --git a/libs/wingsdk/src/target-tf-aws/bucket.ts b/libs/wingsdk/src/target-tf-aws/bucket.ts index d77e3b675b3..83552fb5665 100644 --- a/libs/wingsdk/src/target-tf-aws/bucket.ts +++ b/libs/wingsdk/src/target-tf-aws/bucket.ts @@ -73,24 +73,24 @@ export class Bucket extends cloud.Bucket implements IAwsBucket { } /** @internal */ - public _supportedOps(): string[] { - return [ - cloud.BucketInflightMethods.DELETE, - cloud.BucketInflightMethods.GET, - cloud.BucketInflightMethods.GET_JSON, - cloud.BucketInflightMethods.LIST, - cloud.BucketInflightMethods.PUT, - cloud.BucketInflightMethods.PUT_JSON, - cloud.BucketInflightMethods.PUBLIC_URL, - cloud.BucketInflightMethods.EXISTS, - cloud.BucketInflightMethods.TRY_GET, - cloud.BucketInflightMethods.TRY_GET_JSON, - cloud.BucketInflightMethods.TRY_DELETE, - cloud.BucketInflightMethods.SIGNED_URL, - cloud.BucketInflightMethods.METADATA, - cloud.BucketInflightMethods.COPY, - cloud.BucketInflightMethods.RENAME, - ]; + public get _liftMap(): core.LiftMap { + return { + [cloud.BucketInflightMethods.DELETE]: [], + [cloud.BucketInflightMethods.GET]: [], + [cloud.BucketInflightMethods.GET_JSON]: [], + [cloud.BucketInflightMethods.LIST]: [], + [cloud.BucketInflightMethods.PUT]: [], + [cloud.BucketInflightMethods.PUT_JSON]: [], + [cloud.BucketInflightMethods.PUBLIC_URL]: [], + [cloud.BucketInflightMethods.EXISTS]: [], + [cloud.BucketInflightMethods.TRY_GET]: [], + [cloud.BucketInflightMethods.TRY_GET_JSON]: [], + [cloud.BucketInflightMethods.TRY_DELETE]: [], + [cloud.BucketInflightMethods.SIGNED_URL]: [], + [cloud.BucketInflightMethods.METADATA]: [], + [cloud.BucketInflightMethods.COPY]: [], + [cloud.BucketInflightMethods.RENAME]: [], + }; } protected createTopicHandler( diff --git a/libs/wingsdk/src/target-tf-aws/counter.ts b/libs/wingsdk/src/target-tf-aws/counter.ts index 1f6bbe0b7de..149d6eba11c 100644 --- a/libs/wingsdk/src/target-tf-aws/counter.ts +++ b/libs/wingsdk/src/target-tf-aws/counter.ts @@ -39,13 +39,13 @@ export class Counter extends cloud.Counter implements IAwsCounter { } /** @internal */ - public _supportedOps(): string[] { - return [ - cloud.CounterInflightMethods.INC, - cloud.CounterInflightMethods.DEC, - cloud.CounterInflightMethods.PEEK, - cloud.CounterInflightMethods.SET, - ]; + public get _liftMap(): core.LiftMap { + return { + [cloud.CounterInflightMethods.INC]: [], + [cloud.CounterInflightMethods.DEC]: [], + [cloud.CounterInflightMethods.PEEK]: [], + [cloud.CounterInflightMethods.SET]: [], + }; } public onLift(host: IInflightHost, ops: string[]): void { diff --git a/libs/wingsdk/src/target-tf-aws/function.ts b/libs/wingsdk/src/target-tf-aws/function.ts index 6cfb6088d87..2b3778741f9 100644 --- a/libs/wingsdk/src/target-tf-aws/function.ts +++ b/libs/wingsdk/src/target-tf-aws/function.ts @@ -282,11 +282,11 @@ export class Function extends cloud.Function implements IAwsFunction { } /** @internal */ - public _supportedOps(): string[] { - return [ - cloud.FunctionInflightMethods.INVOKE, - cloud.FunctionInflightMethods.INVOKE_ASYNC, - ]; + public get _liftMap(): core.LiftMap { + return { + [cloud.FunctionInflightMethods.INVOKE]: [], + [cloud.FunctionInflightMethods.INVOKE_ASYNC]: [], + }; } public onLift(host: IInflightHost, ops: string[]): void { diff --git a/libs/wingsdk/src/target-tf-aws/queue.ts b/libs/wingsdk/src/target-tf-aws/queue.ts index 3bd0f662c46..b5819148f51 100644 --- a/libs/wingsdk/src/target-tf-aws/queue.ts +++ b/libs/wingsdk/src/target-tf-aws/queue.ts @@ -63,13 +63,13 @@ export class Queue extends cloud.Queue implements IAwsQueue { } /** @internal */ - public _supportedOps(): string[] { - return [ - cloud.QueueInflightMethods.PUSH, - cloud.QueueInflightMethods.PURGE, - cloud.QueueInflightMethods.APPROX_SIZE, - cloud.QueueInflightMethods.POP, - ]; + public get _liftMap(): core.LiftMap { + return { + [cloud.QueueInflightMethods.PUSH]: [], + [cloud.QueueInflightMethods.PURGE]: [], + [cloud.QueueInflightMethods.APPROX_SIZE]: [], + [cloud.QueueInflightMethods.POP]: [], + }; } public setConsumer( diff --git a/libs/wingsdk/src/target-tf-aws/redis.ts b/libs/wingsdk/src/target-tf-aws/redis.ts index ca3419a047b..03ea62a146f 100644 --- a/libs/wingsdk/src/target-tf-aws/redis.ts +++ b/libs/wingsdk/src/target-tf-aws/redis.ts @@ -99,17 +99,17 @@ export class Redis extends ex.Redis { } /** @internal */ - public _supportedOps(): string[] { - return [ - ex.RedisInflightMethods.URL, - ex.RedisInflightMethods.SET, - ex.RedisInflightMethods.GET, - ex.RedisInflightMethods.HSET, - ex.RedisInflightMethods.HGET, - ex.RedisInflightMethods.SADD, - ex.RedisInflightMethods.SMEMBERS, - ex.RedisInflightMethods.DEL, - ]; + public get _liftMap(): core.LiftMap { + return { + [ex.RedisInflightMethods.URL]: [], + [ex.RedisInflightMethods.SET]: [], + [ex.RedisInflightMethods.GET]: [], + [ex.RedisInflightMethods.HSET]: [], + [ex.RedisInflightMethods.HGET]: [], + [ex.RedisInflightMethods.SADD]: [], + [ex.RedisInflightMethods.SMEMBERS]: [], + [ex.RedisInflightMethods.DEL]: [], + }; } public onLift(host: IInflightHost, ops: string[]): void { diff --git a/libs/wingsdk/src/target-tf-aws/secret.ts b/libs/wingsdk/src/target-tf-aws/secret.ts index 97c3bc1f02c..b9d717d566e 100644 --- a/libs/wingsdk/src/target-tf-aws/secret.ts +++ b/libs/wingsdk/src/target-tf-aws/secret.ts @@ -44,11 +44,11 @@ export class Secret extends cloud.Secret { } /** @internal */ - public _supportedOps(): string[] { - return [ - cloud.SecretInflightMethods.VALUE, - cloud.SecretInflightMethods.VALUE_JSON, - ]; + public get _liftMap(): core.LiftMap { + return { + [cloud.SecretInflightMethods.VALUE]: [], + [cloud.SecretInflightMethods.VALUE_JSON]: [], + }; } public onLift(host: IInflightHost, ops: string[]): void { diff --git a/libs/wingsdk/src/target-tf-aws/table.ts b/libs/wingsdk/src/target-tf-aws/table.ts index 6292e90936a..4ed000be39e 100644 --- a/libs/wingsdk/src/target-tf-aws/table.ts +++ b/libs/wingsdk/src/target-tf-aws/table.ts @@ -123,16 +123,16 @@ export class Table extends ex.Table implements IAwsTable { } /** @internal */ - public _supportedOps(): string[] { - return [ - ex.TableInflightMethods.INSERT, - ex.TableInflightMethods.UPSERT, - ex.TableInflightMethods.UPDATE, - ex.TableInflightMethods.DELETE, - ex.TableInflightMethods.GET, - ex.TableInflightMethods.TRYGET, - ex.TableInflightMethods.LIST, - ]; + public get _liftMap(): core.LiftMap { + return { + [ex.TableInflightMethods.INSERT]: [], + [ex.TableInflightMethods.UPSERT]: [], + [ex.TableInflightMethods.UPDATE]: [], + [ex.TableInflightMethods.DELETE]: [], + [ex.TableInflightMethods.GET]: [], + [ex.TableInflightMethods.TRYGET]: [], + [ex.TableInflightMethods.LIST]: [], + }; } private envName(): string { diff --git a/libs/wingsdk/src/target-tf-aws/topic.ts b/libs/wingsdk/src/target-tf-aws/topic.ts index 1b3af162ad6..a7fc8e3936b 100644 --- a/libs/wingsdk/src/target-tf-aws/topic.ts +++ b/libs/wingsdk/src/target-tf-aws/topic.ts @@ -189,8 +189,10 @@ export class Topic extends cloud.Topic implements IAwsTopic { ); } /** @internal */ - public _supportedOps(): string[] { - return [cloud.TopicInflightMethods.PUBLISH]; + public get _liftMap(): core.LiftMap { + return { + [cloud.TopicInflightMethods.PUBLISH]: [], + }; } private envName(): string { diff --git a/libs/wingsdk/src/target-tf-azure/bucket.ts b/libs/wingsdk/src/target-tf-azure/bucket.ts index 6e21654ac7e..d0c3facb643 100644 --- a/libs/wingsdk/src/target-tf-azure/bucket.ts +++ b/libs/wingsdk/src/target-tf-azure/bucket.ts @@ -99,9 +99,21 @@ export class Bucket extends cloud.Bucket { } /** @internal */ - public _supportedOps(): string[] { + public get _liftMap(): core.LiftMap { // TODO: After fixing the tests we realized that nothing is working-https://github.com/winglang/wing/issues/5123 - return []; + return { + [cloud.BucketInflightMethods.DELETE]: [], + [cloud.BucketInflightMethods.GET]: [], + [cloud.BucketInflightMethods.GET_JSON]: [], + [cloud.BucketInflightMethods.LIST]: [], + [cloud.BucketInflightMethods.PUT]: [], + [cloud.BucketInflightMethods.PUT_JSON]: [], + [cloud.BucketInflightMethods.PUBLIC_URL]: [], + [cloud.BucketInflightMethods.EXISTS]: [], + [cloud.BucketInflightMethods.TRY_GET]: [], + [cloud.BucketInflightMethods.TRY_GET_JSON]: [], + [cloud.BucketInflightMethods.TRY_DELETE]: [], + }; } public onLift(host: IInflightHost, ops: string[]): void { diff --git a/libs/wingsdk/src/target-tf-azure/counter.ts b/libs/wingsdk/src/target-tf-azure/counter.ts index 795c7657dbc..e4c13c00f02 100644 --- a/libs/wingsdk/src/target-tf-azure/counter.ts +++ b/libs/wingsdk/src/target-tf-azure/counter.ts @@ -65,13 +65,13 @@ export class Counter extends cloud.Counter { } /** @internal */ - public _supportedOps(): string[] { - return [ - cloud.CounterInflightMethods.INC, - cloud.CounterInflightMethods.DEC, - cloud.CounterInflightMethods.SET, - cloud.CounterInflightMethods.PEEK, - ]; + public get _liftMap(): core.LiftMap { + return { + [cloud.CounterInflightMethods.INC]: [], + [cloud.CounterInflightMethods.DEC]: [], + [cloud.CounterInflightMethods.SET]: [], + [cloud.CounterInflightMethods.PEEK]: [], + }; } public onLift(host: IInflightHost, ops: string[]): void { diff --git a/libs/wingsdk/src/target-tf-azure/function.ts b/libs/wingsdk/src/target-tf-azure/function.ts index d4c8ff89393..e95096103f3 100644 --- a/libs/wingsdk/src/target-tf-azure/function.ts +++ b/libs/wingsdk/src/target-tf-azure/function.ts @@ -12,6 +12,7 @@ import { ServicePlan } from "../.gen/providers/azurerm/service-plan"; import { StorageAccount } from "../.gen/providers/azurerm/storage-account"; import { StorageBlob } from "../.gen/providers/azurerm/storage-blob"; import * as cloud from "../cloud"; +import { LiftMap } from "../core"; import { NotImplementedError } from "../core/errors"; import { createBundle } from "../shared/bundling"; import { @@ -291,8 +292,10 @@ export class Function extends cloud.Function { } /** @internal */ - public _supportedOps(): string[] { - return [cloud.FunctionInflightMethods.INVOKE]; + public get _liftMap(): LiftMap { + return { + [cloud.FunctionInflightMethods.INVOKE]: [], + }; } public onLift(host: IInflightHost, ops: string[]): void { diff --git a/libs/wingsdk/src/target-tf-gcp/bucket.ts b/libs/wingsdk/src/target-tf-gcp/bucket.ts index 534f357cfe8..a0d7f3e6968 100644 --- a/libs/wingsdk/src/target-tf-gcp/bucket.ts +++ b/libs/wingsdk/src/target-tf-gcp/bucket.ts @@ -8,7 +8,7 @@ import { StorageBucketIamMember } from "../.gen/providers/google/storage-bucket- import { StorageBucketObject } from "../.gen/providers/google/storage-bucket-object"; import { Id } from "../.gen/providers/random/id"; import * as cloud from "../cloud"; -import { InflightClient } from "../core"; +import { InflightClient, LiftMap } from "../core"; import { NotImplementedError } from "../core/errors"; import { CaseConventions, @@ -95,24 +95,24 @@ export class Bucket extends cloud.Bucket { } /** @internal */ - public _supportedOps(): string[] { - return [ - cloud.BucketInflightMethods.DELETE, - cloud.BucketInflightMethods.GET, - cloud.BucketInflightMethods.GET_JSON, - cloud.BucketInflightMethods.LIST, - cloud.BucketInflightMethods.PUT, - cloud.BucketInflightMethods.PUT_JSON, - cloud.BucketInflightMethods.PUBLIC_URL, - cloud.BucketInflightMethods.EXISTS, - cloud.BucketInflightMethods.TRY_GET, - cloud.BucketInflightMethods.TRY_GET_JSON, - cloud.BucketInflightMethods.TRY_DELETE, - cloud.BucketInflightMethods.METADATA, - cloud.BucketInflightMethods.COPY, - cloud.BucketInflightMethods.RENAME, - cloud.BucketInflightMethods.SIGNED_URL, - ]; + public get _liftMap(): LiftMap { + return { + [cloud.BucketInflightMethods.DELETE]: [], + [cloud.BucketInflightMethods.GET]: [], + [cloud.BucketInflightMethods.GET_JSON]: [], + [cloud.BucketInflightMethods.LIST]: [], + [cloud.BucketInflightMethods.PUT]: [], + [cloud.BucketInflightMethods.PUT_JSON]: [], + [cloud.BucketInflightMethods.PUBLIC_URL]: [], + [cloud.BucketInflightMethods.EXISTS]: [], + [cloud.BucketInflightMethods.TRY_GET]: [], + [cloud.BucketInflightMethods.TRY_GET_JSON]: [], + [cloud.BucketInflightMethods.TRY_DELETE]: [], + [cloud.BucketInflightMethods.METADATA]: [], + [cloud.BucketInflightMethods.COPY]: [], + [cloud.BucketInflightMethods.RENAME]: [], + [cloud.BucketInflightMethods.SIGNED_URL]: [], + }; } public addObject(key: string, body: string): void { diff --git a/libs/wingsdk/src/target-tf-gcp/counter.ts b/libs/wingsdk/src/target-tf-gcp/counter.ts index c7e276f27bc..2abd137632c 100644 --- a/libs/wingsdk/src/target-tf-gcp/counter.ts +++ b/libs/wingsdk/src/target-tf-gcp/counter.ts @@ -58,13 +58,13 @@ export class Counter extends cloud.Counter { } /** @internal */ - public _supportedOps(): string[] { - return [ - cloud.CounterInflightMethods.PEEK, - cloud.CounterInflightMethods.INC, - cloud.CounterInflightMethods.DEC, - cloud.CounterInflightMethods.SET, - ]; + public get _liftMap(): core.LiftMap { + return { + [cloud.CounterInflightMethods.PEEK]: [], + [cloud.CounterInflightMethods.INC]: [], + [cloud.CounterInflightMethods.DEC]: [], + [cloud.CounterInflightMethods.SET]: [], + }; } public onLift(host: IInflightHost, ops: string[]): void { diff --git a/libs/wingsdk/src/target-tf-gcp/function.ts b/libs/wingsdk/src/target-tf-gcp/function.ts index f6f711f04e9..c741f565508 100644 --- a/libs/wingsdk/src/target-tf-gcp/function.ts +++ b/libs/wingsdk/src/target-tf-gcp/function.ts @@ -12,6 +12,7 @@ import { ProjectIamMember } from "../.gen/providers/google/project-iam-member"; import { ServiceAccount } from "../.gen/providers/google/service-account"; import { StorageBucketObject } from "../.gen/providers/google/storage-bucket-object"; import * as cloud from "../cloud"; +import { LiftMap } from "../core"; import { NotImplementedError } from "../core/errors"; import { createBundle } from "../shared/bundling"; import { DEFAULT_MEMORY_SIZE } from "../shared/function"; @@ -270,8 +271,10 @@ export class Function extends cloud.Function { } /** @internal */ - public _supportedOps(): string[] { - return [cloud.FunctionInflightMethods.INVOKE]; + public get _liftMap(): LiftMap { + return { + [cloud.FunctionInflightMethods.INVOKE]: [], + }; } /** @internal */ diff --git a/libs/wingsdk/src/target-tf-gcp/table.ts b/libs/wingsdk/src/target-tf-gcp/table.ts index 828458af66a..4887e3a0273 100644 --- a/libs/wingsdk/src/target-tf-gcp/table.ts +++ b/libs/wingsdk/src/target-tf-gcp/table.ts @@ -89,11 +89,6 @@ export class Table extends ex.Table { new BigtableTable(this, "Default", tableConfig); } - /** @internal */ - public _supportedOps(): string[] { - return []; - } - public addRow(_key: string, _row: Json): void { throw new NotImplementedError( "Method is not supported as a preflight for the GCP target.", diff --git a/libs/wingsdk/src/ui/base.ts b/libs/wingsdk/src/ui/base.ts index abbb72782d6..a3cb816348c 100644 --- a/libs/wingsdk/src/ui/base.ts +++ b/libs/wingsdk/src/ui/base.ts @@ -10,6 +10,7 @@ export const VISUAL_COMPONENT_SYMBOL = Symbol.for( /** * A visual component is used to customize the view of other classes in the Wing Console. * This is a base class for all other visual components. + * @noinflight */ export abstract class VisualComponent extends Resource { /** diff --git a/libs/wingsdk/src/ui/button.ts b/libs/wingsdk/src/ui/button.ts index a54f769a925..2d03f8fbbf6 100644 --- a/libs/wingsdk/src/ui/button.ts +++ b/libs/wingsdk/src/ui/button.ts @@ -12,6 +12,7 @@ export const BUTTON_FQN = fqnForType("ui.Button"); /** * A button can be used to perform an action. + * @noinflight */ export class Button extends VisualComponent { /** @@ -50,11 +51,6 @@ export class Button extends VisualComponent { }; } - /** @internal */ - public _supportedOps(): string[] { - return []; - } - /** @internal */ public _toInflight(): string { throw new Error("Method not implemented."); diff --git a/libs/wingsdk/src/ui/field.ts b/libs/wingsdk/src/ui/field.ts index be9db4b8c36..cafd9227c92 100644 --- a/libs/wingsdk/src/ui/field.ts +++ b/libs/wingsdk/src/ui/field.ts @@ -31,6 +31,7 @@ export interface FieldProps { /** * A field can be used to display a value. + * @noinflight */ export class Field extends VisualComponent { /** @@ -85,11 +86,6 @@ export class Field extends VisualComponent { }; } - /** @internal */ - public _supportedOps(): string[] { - return []; - } - /** @internal */ public _toInflight(): string { throw new Error("Method not implemented."); @@ -117,6 +113,7 @@ export interface IFieldHandlerClient { /** * A value field can be used to display a string value. + * @noinflight */ export class ValueField extends Field { constructor(scope: Construct, id: string, label: string, value: string) { diff --git a/libs/wingsdk/src/ui/file-browser.ts b/libs/wingsdk/src/ui/file-browser.ts index 2b7184a70c9..7fe5e1f5e5a 100644 --- a/libs/wingsdk/src/ui/file-browser.ts +++ b/libs/wingsdk/src/ui/file-browser.ts @@ -36,6 +36,7 @@ export interface FileBrowserHandlers { /** * A file browser can be used to browse files. + * @noinflight */ export class FileBrowser extends VisualComponent { /** @@ -114,11 +115,6 @@ export class FileBrowser extends VisualComponent { }; } - /** @internal */ - public _supportedOps(): string[] { - return []; - } - /** @internal */ public _toInflight(): string { throw new Error("Method not implemented."); @@ -132,6 +128,7 @@ export class FileBrowser extends VisualComponent { * @inflight `@winglang/sdk.ui.IFileBrowserPutHandlerClient` */ export interface IFileBrowserPutHandler extends IInflight {} + /** * A resource with an inflight "handle" method that can be passed to * `IFileBrowser`. @@ -139,6 +136,7 @@ export interface IFileBrowserPutHandler extends IInflight {} * @inflight `@winglang/sdk.ui.IFileBrowserGetHandlerClient` */ export interface IFileBrowserGetHandler extends IInflight {} + /** * A resource with an inflight "handle" method that can be passed to * `IFileBrowser`. @@ -146,6 +144,7 @@ export interface IFileBrowserGetHandler extends IInflight {} * @inflight `@winglang/sdk.ui.IFileBrowserListHandlerClient` */ export interface IFileBrowserListHandler extends IInflight {} + /** * A resource with an inflight "handle" method that can be passed to * `IFileBrowser`. diff --git a/libs/wingsdk/src/ui/http-client.ts b/libs/wingsdk/src/ui/http-client.ts index 81fc44f2d62..f299b6472de 100644 --- a/libs/wingsdk/src/ui/http-client.ts +++ b/libs/wingsdk/src/ui/http-client.ts @@ -12,6 +12,7 @@ export const API_FQN = fqnForType("ui.HttpClient"); /** * An HttpClient can be used to make HTTP requests. + * @noinflight */ export class HttpClient extends VisualComponent { /** @@ -67,11 +68,6 @@ export class HttpClient extends VisualComponent { }; } - /** @internal */ - public _supportedOps(): string[] { - return []; - } - /** @internal */ public _toInflight(): string { throw new Error("Method not implemented."); @@ -104,6 +100,7 @@ export interface IHttpClientGetUrlHandlerClient { */ handle(): Promise; } + /** * Inflight client for `IHttpClientGetApiSpecHandler`. */ diff --git a/libs/wingsdk/src/ui/section.ts b/libs/wingsdk/src/ui/section.ts index 9cd4043e087..c8c16c66e93 100644 --- a/libs/wingsdk/src/ui/section.ts +++ b/libs/wingsdk/src/ui/section.ts @@ -23,6 +23,7 @@ export interface SectionProps { /** * A section can be used to group other visual components. + * @noinflight */ export class Section extends VisualComponent { /** @@ -94,11 +95,6 @@ export class Section extends VisualComponent { }; } - /** @internal */ - public _supportedOps(): string[] { - return []; - } - /** @internal */ public _toInflight(): string { throw new Error("Method not implemented."); diff --git a/libs/wingsdk/test/core/lifting.test.ts b/libs/wingsdk/test/core/lifting.test.ts index 1e8cf2b282b..d98ec447a90 100644 --- a/libs/wingsdk/test/core/lifting.test.ts +++ b/libs/wingsdk/test/core/lifting.test.ts @@ -1,7 +1,7 @@ import { Construct } from "constructs"; import { describe, expect, test } from "vitest"; import { - LiftDepsMatrix, + LiftMapNormalized, collectLifts, mergeLiftDeps, } from "../../src/core/lifting"; @@ -239,9 +239,9 @@ describe("collectLifts", () => { }); function expectMergeDeps( - deps1: LiftDepsMatrix, - deps2: LiftDepsMatrix, - expected: LiftDepsMatrix + deps1: LiftMapNormalized, + deps2: LiftMapNormalized, + expected: LiftMapNormalized ) { const result = mergeLiftDeps(deps1, deps2); expect(result).toEqual(expected); diff --git a/libs/wingsdk/test/core/resource.test.ts b/libs/wingsdk/test/core/resource.test.ts index 867e3354d0f..e49b194d71a 100644 --- a/libs/wingsdk/test/core/resource.test.ts +++ b/libs/wingsdk/test/core/resource.test.ts @@ -5,10 +5,12 @@ import { Resource } from "../../src/std"; import { SimApp } from "../sim-app"; describe("resource onLift", () => { - const inflightOps = ["op1", "op2"]; class Example extends Resource { - public _supportedOps() { - return inflightOps; + public get _liftMap() { + return { + op1: [], + op2: [], + }; } public _toInflight() { return "inflight"; @@ -24,6 +26,9 @@ describe("resource onLift", () => { } super(scope, id); } + public get _liftMap() { + return {}; + } } test("adding supported ops to host should succeed", () => { const app = new SimApp();