diff --git a/docs/docs/04-standard-library/sim/api-reference.md b/docs/docs/04-standard-library/sim/api-reference.md index 6749af2595a..0ecb35cda5c 100644 --- a/docs/docs/04-standard-library/sim/api-reference.md +++ b/docs/docs/04-standard-library/sim/api-reference.md @@ -126,126 +126,6 @@ A token that resolves to the host port of this container. --- -### Policy - -- *Implements:* ISimulatorResource - -Implementation of `sim.Policy`. - -#### Initializers - -```wing -bring sim; - -new sim.Policy(props: PolicyProps); -``` - -| **Name** | **Type** | **Description** | -| --- | --- | --- | -| props | PolicyProps | *No description.* | - ---- - -##### `props`Required - -- *Type:* PolicyProps - ---- - -#### Methods - -| **Name** | **Description** | -| --- | --- | -| addStatement | Adds a statement to the policy. | -| toSimulator | Convert this resource to a resource schema for the simulator. | - ---- - -##### `addStatement` - -```wing -addStatement(resource: IResource, op: str): void -``` - -Adds a statement to the policy. - -###### `resource`Required - -- *Type:* IResource - ---- - -###### `op`Required - -- *Type:* str - ---- - -##### `toSimulator` - -```wing -toSimulator(): BaseResourceSchema -``` - -Convert this resource to a resource schema for the simulator. - -#### Static Functions - -| **Name** | **Description** | -| --- | --- | -| onLiftType | A hook called by the Wing compiler once for each inflight host that needs to use this type inflight. | - ---- - -##### `onLiftType` - -```wing -bring sim; - -sim.Policy.onLiftType(host: IInflightHost, ops: MutArray); -``` - -A hook called by the Wing compiler once for each inflight host that needs to use this type inflight. - -The list of requested inflight methods -needed by the inflight host are given by `ops`. - -This method is commonly used for adding permissions, environment variables, or -other capabilities to the inflight host. - -###### `host`Required - -- *Type:* IInflightHost - ---- - -###### `ops`Required - -- *Type:* MutArray<str> - ---- - -#### Properties - -| **Name** | **Type** | **Description** | -| --- | --- | --- | -| node | constructs.Node | The tree node. | - ---- - -##### `node`Required - -```wing -node: Node; -``` - -- *Type:* constructs.Node - -The tree node. - ---- - - ### State - *Implements:* ISimulatorResource @@ -556,115 +436,15 @@ A glob of local files to consider as input sources for the container, relative t --- -### PolicyProps - -Options for `sim.Policy`. - -#### Initializer - -```wing -bring sim; - -let PolicyProps = sim.PolicyProps{ ... }; -``` - -#### Properties - -| **Name** | **Type** | **Description** | -| --- | --- | --- | -| principal | IResource | The resource to which the policy is attached. | - ---- - -##### `principal`Required - -```wing -principal: IResource; -``` - -- *Type:* IResource - -The resource to which the policy is attached. - ---- - ## Protocols -### IPolicyClient - -- *Implemented By:* IPolicyClient - -Inflight interface for `Policy`. - - - -### ISimulatorInflightHost - -- *Extends:* IInflightHost - -- *Implemented By:* ISimulatorInflightHost - -Interfaces shared by all preflight classes that host inflight code. - -#### Methods - -| **Name** | **Description** | -| --- | --- | -| addPermission | Add a simulated permission to this inflight host. | - ---- - -##### `addPermission` - -```wing -addPermission(resource: IResource, op: str): void -``` - -Add a simulated permission to this inflight host. - -###### `resource`Required - -- *Type:* IResource - -The resource to add. - ---- - -###### `op`Required - -- *Type:* str - -The action to add. - ---- - -#### Properties - -| **Name** | **Type** | **Description** | -| --- | --- | --- | -| node | constructs.Node | The tree node. | - ---- - -##### `node`Required - -```wing -node: Node; -``` - -- *Type:* constructs.Node - -The tree node. - ---- - ### ISimulatorResource - *Extends:* IResource -- *Implemented By:* Container, Policy, State, ISimulatorResource +- *Implemented By:* Container, State, ISimulatorResource -Interfaces shared by all preflight classes targeting the simulator. +Interfaces shared by all polycon implementations (preflight classes) targeting the simulator. #### Methods diff --git a/examples/tests/invalid/simulator_permissions.test.w b/examples/tests/invalid/simulator_permissions.test.w deleted file mode 100644 index 81f3ab9f033..00000000000 --- a/examples/tests/invalid/simulator_permissions.test.w +++ /dev/null @@ -1,26 +0,0 @@ -bring cloud; - -let buckets = [ - new cloud.Bucket() as "b1", - new cloud.Bucket() as "b2" -]; - -test "incorrect resource permission" { - // This test fails because permission is granted to b2, not b1 - lift(buckets.at(1), ["put"]); - let var i = 10; - while i > 0 { - i -= 1; - } - buckets.at(i).put("key", "value"); -} - -test "incorrect permission operation" { - // This test fails because permission is granted for "list", not "put" - lift(buckets.at(0), ["list"]); - let var i = 10; - while i > 0 { - i -= 1; - } - buckets.at(i).put("key", "value"); -} diff --git a/examples/tests/sdk_tests/service/callbacks.test.w b/examples/tests/sdk_tests/service/callbacks.test.w index 1f35b77da80..3ed3b962a62 100644 --- a/examples/tests/sdk_tests/service/callbacks.test.w +++ b/examples/tests/sdk_tests/service/callbacks.test.w @@ -50,4 +50,4 @@ if util.env("WING_TARGET") == "sim" { assert(startCounter.peek() == 0); assert(b.get(status) == stopped); } -} +} \ No newline at end of file diff --git a/libs/wingsdk/src/cloud/bucket.ts b/libs/wingsdk/src/cloud/bucket.ts index dae03e3c800..e35992a38e4 100644 --- a/libs/wingsdk/src/cloud/bucket.ts +++ b/libs/wingsdk/src/cloud/bucket.ts @@ -107,7 +107,7 @@ export class Bucket extends Resource { * Gets topic form the topics map, or creates if not exists * @param actionType */ - protected getTopic(actionType: BucketEventType): Topic { + private getTopic(actionType: BucketEventType): Topic { if (!this._topics.has(actionType)) { this._topics.set(actionType, this.createTopic(actionType)); } diff --git a/libs/wingsdk/src/shared/sandbox.ts b/libs/wingsdk/src/shared/sandbox.ts index e892f584430..0fe362f3195 100644 --- a/libs/wingsdk/src/shared/sandbox.ts +++ b/libs/wingsdk/src/shared/sandbox.ts @@ -222,14 +222,14 @@ process.on("message", async (message) => { // "exit" could be emitted if the user code called process.exit(), or if we killed the process // due to a timeout or unexpected error. In any case, we reject the promise. - this.onChildExit = (code: number | null, signal: unknown) => { + this.onChildExit = (code: number | null) => { this.debugLog("Child processed stopped."); this.child = undefined; this.available = true; if (this.timeout) { clearTimeout(this.timeout); } - reject(new Error(`Process exited with code ${code}, signal ${signal}`)); + reject(new Error(`Process exited with code ${code}`)); }; if (this.options.timeout) { diff --git a/libs/wingsdk/src/simulator/client.ts b/libs/wingsdk/src/simulator/client.ts index 9b223330fbd..a46262b7f05 100644 --- a/libs/wingsdk/src/simulator/client.ts +++ b/libs/wingsdk/src/simulator/client.ts @@ -35,19 +35,7 @@ function makeHttpRequest(options: HttpRequestOptions): Promise { }); } -/** - * Creates a proxy object that forwards method calls to the simulator server. - * - * @param url The URL of the simulator server - * @param handle The handle for the resource we're calling methods on or getting properties from - * @param caller The handle of the resource that is making the calls - * @returns A proxy object that forwards calls to the simulator server - */ -export function makeSimulatorClient( - url: string, - handle: string, - caller: string -) { +export function makeSimulatorClient(url: string, handle: string) { let proxy: any; let hasThenMethod = true; // assume that the object has a "then" method until proven otherwise @@ -57,7 +45,7 @@ export function makeSimulatorClient( } return async function (...args: any[]) { - const body: SimulatorServerRequest = { caller, handle, method, args }; + const body: SimulatorServerRequest = { handle, method, args }; const parsedUrl = new URL(url); const resp = await makeHttpRequest({ hostname: parsedUrl.hostname, diff --git a/libs/wingsdk/src/simulator/simulator.ts b/libs/wingsdk/src/simulator/simulator.ts index f445875160e..bb63842446b 100644 --- a/libs/wingsdk/src/simulator/simulator.ts +++ b/libs/wingsdk/src/simulator/simulator.ts @@ -7,23 +7,14 @@ import { Graph } from "./graph"; import { deserialize, serialize } from "./serialization"; import { resolveTokens } from "./tokens"; import { Tree } from "./tree"; -import { exists } from "./util"; import { SDK_VERSION } from "../constants"; import { TREE_FILE_PATH } from "../core"; import { readJsonSync } from "../shared/misc"; import { CONNECTIONS_FILE_PATH, Trace, TraceType } from "../std"; -import { POLICY_FQN } from "../target-sim"; -import { PolicySchemaProps } from "../target-sim/schema-resources"; const LOCALHOST_ADDRESS = "127.0.0.1"; const HANDLE_ATTRIBUTE = "handle"; -/** - * If an API call is made to a resource with name as the caller, any permissions - * checking will be skipped. Used by unit tests and the Wing Console. - */ -const ADMIN_PERMISSION = "admin"; - /** * Props for `Simulator`. */ @@ -102,11 +93,6 @@ export interface ISimulatorContext { */ readonly resourcePath: string; - /** - * The handle of the resource that is being simulated. - */ - readonly resourceHandle: string; - /** * The url that the simulator server is listening on. */ @@ -115,7 +101,7 @@ export interface ISimulatorContext { /** * Obtain a client given a resource's handle. */ - getClient(handle: string, asAdmin?: boolean): unknown; + getClient(handle: string): unknown; /** * Add a trace. Traces are breadcrumbs of information about resource @@ -200,7 +186,6 @@ export class Simulator { private _serverUrl: string | undefined; private _server: Server | undefined; private _model: Model; - private _policyRegistry: PolicyRegistry; // keeps the actual resolved state (props and attrs) of all started resources. this state is // merged in when calling `getResourceConfig()`. @@ -213,7 +198,6 @@ export class Simulator { this._running = "stopped"; this._handles = new HandleManager(); - this._policyRegistry = new PolicyRegistry(); this._traces = new Array(); this._traceSubscribers = new Array(); } @@ -396,19 +380,13 @@ export class Simulator { try { const resource = this._handles.find(handle); - await this.ensureStateDirExists(path); await resource.save(this.getResourceStateDir(path)); - await resource.cleanup(); this._handles.deallocate(handle); + await resource.cleanup(); } catch (err) { console.warn(err); } - // if the resource is a policy, remove it from the policy registry - if (this.getResourceConfig(path).type === POLICY_FQN) { - this._policyRegistry.deregister(path); - } - this.addSimulatorTrace(path, { message: `${path} stopped` }); delete this.state[path]; // delete the state of the resource } @@ -475,7 +453,8 @@ export class Simulator { if (!handle) { return undefined; } - return makeSimulatorClient(this.url, handle, ADMIN_PERMISSION); + + return makeSimulatorClient(this.url, handle); } private tryGetResourceHandle(path: string): string | undefined { @@ -530,14 +509,6 @@ export class Simulator { return join(this.statedir, config.addr); } - private async ensureStateDirExists(path: string) { - const statedir = this.getResourceStateDir(path); - const statedirExists = await exists(statedir); - if (!statedirExists) { - await mkdir(statedir, { recursive: true }); - } - } - /** * Obtain a resource's visual interaction components. * @returns An array of UIComponent objects @@ -580,43 +551,6 @@ export class Simulator { return structuredClone(this._model.connections); } - private checkPermission( - callerHandle: string, - calleeHandle: string, - method: string - ): { granted: boolean; reason?: string } { - if (callerHandle === ADMIN_PERMISSION) { - return { granted: true }; - } - - const callerPath = this._handles.tryFindPath(callerHandle); - if (!callerPath) { - return { - granted: false, - reason: `(Permission checking) No caller resource with handle "${callerHandle}" found.`, - }; - } - - const calleePath = this._handles.tryFindPath(calleeHandle); - if (!calleePath) { - return { - granted: false, - reason: `(Permission checking) No callee resource with handle "${calleeHandle}" found.`, - }; - } - - if ( - this._policyRegistry.checkPermission(callerHandle, calleeHandle, method) - ) { - return { granted: true }; - } - - return { - granted: false, - reason: `Resource "${callerPath}" does not have permission to perform operation "${method}" on resource "${calleePath}".`, - }; - } - /** * Start a server that allows any resource to be accessed via HTTP. */ @@ -634,24 +568,9 @@ export class Simulator { }); req.on("end", () => { const request: SimulatorServerRequest = deserialize(body); - const { caller, handle, method, args } = request; + const { handle, method, args } = request; const resource = this._handles.tryFind(handle); - // Check if the caller has permission to call the method on the resource - const grant = this.checkPermission(caller, handle, method); - if (!grant.granted) { - res.writeHead(403, { "Content-Type": "application/json" }); - res.end( - serialize({ - error: { - message: grant.reason, - }, - }), - "utf-8" - ); - return; - } - // If we weren't able to find a resource with the given handle, it could actually // be OK if the resource is still starting up or has already been cleaned up. // In that case, we return a 500 error with a message that explains what happened. @@ -771,6 +690,7 @@ export class Simulator { } const resourceConfig = this.getResourceConfig(path); + const context = this.createContext(resourceConfig); const resolvedProps = this.resolveTokens(resourceConfig.props); @@ -791,18 +711,15 @@ export class Simulator { // create the resource based on its type // eslint-disable-next-line @typescript-eslint/no-require-imports const ResourceType = require(typeInfo.sourcePath)[typeInfo.className]; - const resourceObject = new ResourceType(resolvedProps); - - // allocate a handle for the resource so others can find it - const handle = this._handles.allocate(path, resourceObject); - - // initialize the resource with the simulator context - const context = this.createContext(resourceConfig, handle); - const attrs = await resourceObject.init(context); + const resourceObject = new ResourceType(resolvedProps, context); + const attrs = await resourceObject.init(); // save the current state await resourceObject.save(); + // allocate a handle for the resource so others can find it + const handle = this._handles.allocate(resourceObject); + // merge the attributes this.state[path].attrs = { ...this.state[path].attrs, @@ -814,27 +731,16 @@ export class Simulator { this.addSimulatorTrace(path, { message: `${resourceConfig.path} started`, }); - - // if the resource is a policy, add it to the policy registry - if (resourceConfig.type === POLICY_FQN) { - const policyProps = resolvedProps as PolicySchemaProps; - this._policyRegistry.register(resourceConfig.path, policyProps); - } } - private createContext( - resourceConfig: BaseResourceSchema, - resourceHandle: string - ): ISimulatorContext { + private createContext(resourceConfig: BaseResourceSchema): ISimulatorContext { return { simdir: this._model.simdir, statedir: join(this.statedir, resourceConfig.addr), resourcePath: resourceConfig.path, - resourceHandle: resourceHandle, serverUrl: this.url, - getClient: (calleeHandle: string, asAdmin: boolean) => { - const callerHandle = asAdmin ? ADMIN_PERMISSION : resourceHandle; - return makeSimulatorClient(this.url, calleeHandle, callerHandle); + getClient: (handle: string) => { + return makeSimulatorClient(this.url, handle); }, addTrace: (trace: Trace) => { this.addTrace(trace); @@ -1038,19 +944,16 @@ export interface ISimulatorFactory { class HandleManager { private readonly handles: Map; - private readonly paths: Map; // handle -> path private nextHandle: number; public constructor() { this.handles = new Map(); - this.paths = new Map(); this.nextHandle = 0; } - public allocate(path: string, resource: ISimulatorResourceInstance): string { + public allocate(resource: ISimulatorResourceInstance): string { const handle = `sim-${this.nextHandle++}`; this.handles.set(handle, resource); - this.paths.set(handle, path); return handle; } @@ -1066,23 +969,17 @@ class HandleManager { return this.handles.get(handle); } - public tryFindPath(handle: string): string | undefined { - return this.paths.get(handle); - } - public deallocate(handle: string): ISimulatorResourceInstance { const instance = this.handles.get(handle); if (!instance) { throw new Error(`No resource found with handle "${handle}".`); } this.handles.delete(handle); - this.paths.delete(handle); return instance; } public reset(): void { this.handles.clear(); - this.paths.clear(); this.nextHandle = 0; } } @@ -1095,7 +992,7 @@ export interface ISimulatorResourceInstance { * Perform any async initialization required by the resource. Return a map of * the resource's runtime attributes. */ - init(ctx: ISimulatorContext): Promise>; + init(): Promise>; /** * Stop the resource and clean up any physical resources it may have created @@ -1194,9 +1091,7 @@ export interface ConnectionData { * Subject to breaking changes. */ export interface SimulatorServerRequest { - /** The handle of the resource making the request. */ - readonly caller: string; - /** The target resource handle (an ID unique among resources in the simulation). */ + /** The resource handle (an ID unique among resources in the simulation). */ readonly handle: string; /** The method to call on the resource. */ readonly method: string; @@ -1214,42 +1109,3 @@ export interface SimulatorServerResponse { /** The error that occurred during the method call. */ readonly error?: any; } - -class PolicyRegistry { - private readonly policies: Record; - - constructor() { - this.policies = {}; - } - - public register(id: string, policy: PolicySchemaProps) { - if (this.policies[id]) { - throw new Error(`Policy with id ${id} already registered.`); - } - this.policies[id] = policy; - } - - public deregister(id: string) { - delete this.policies[id]; - } - - public checkPermission( - caller: string, - callee: string, - method: string - ): boolean { - for (const policy of Object.values(this.policies)) { - if (policy.principal === caller) { - for (const statement of policy.statements) { - if ( - statement.resourceHandle === callee && - statement.operation === method - ) { - return true; - } - } - } - } - return false; - } -} diff --git a/libs/wingsdk/src/simulator/util.ts b/libs/wingsdk/src/simulator/util.ts deleted file mode 100644 index 16148b3cf1b..00000000000 --- a/libs/wingsdk/src/simulator/util.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { access, constants } from "node:fs"; -import { promisify } from "node:util"; - -/** - * Check if a file exists for an specific path - * @param filePath - * @Returns Return `true` if the file exists, `false` otherwise. - */ -export async function exists(filePath: string): Promise { - try { - await promisify(access)( - filePath, - constants.F_OK | constants.R_OK | constants.W_OK //eslint-disable-line no-bitwise - ); - return true; - } catch (er) { - return false; - } -} diff --git a/libs/wingsdk/src/target-sim/api.inflight.ts b/libs/wingsdk/src/target-sim/api.inflight.ts index 6b837d2de4f..0f32fdb39ac 100644 --- a/libs/wingsdk/src/target-sim/api.inflight.ts +++ b/libs/wingsdk/src/target-sim/api.inflight.ts @@ -50,14 +50,15 @@ export class Api implements IApiClient, ISimulatorResourceInstance, IEventPublisher { private readonly routes: ApiRouteWithFunctionHandle[]; - private _context: ISimulatorContext | undefined; + private readonly context: ISimulatorContext; private readonly app: express.Application; private server: Server | undefined; private url: string | undefined; private port: number | undefined; - constructor(props: ApiSchema["props"]) { + constructor(props: ApiSchema["props"], context: ISimulatorContext) { this.routes = []; + this.context = context; const { corsHeaders } = props; // Set up an express server that handles the routes. @@ -93,15 +94,7 @@ export class Api } } - private get context(): ISimulatorContext { - if (!this._context) { - throw new Error("Cannot access context during class construction"); - } - return this._context; - } - - public async init(context: ISimulatorContext): Promise { - this._context = context; + public async init(): Promise { // Check for a previous state file to see if there was a port that was previously being used // if so, try to use it out of convenience let lastPort: number | undefined; diff --git a/libs/wingsdk/src/target-sim/api.ts b/libs/wingsdk/src/target-sim/api.ts index ea60d2ccd62..5cdb5cddc0d 100644 --- a/libs/wingsdk/src/target-sim/api.ts +++ b/libs/wingsdk/src/target-sim/api.ts @@ -3,7 +3,6 @@ import { Construct } from "constructs"; import { App } from "./app"; import { EventMapping } from "./event-mapping"; import { Function } from "./function"; -import { Policy } from "./policy"; import { ISimulatorResource } from "./resource"; import { ApiSchema, ApiRoute } from "./schema-resources"; import { simulatorAttrToken } from "./tokens"; @@ -25,7 +24,6 @@ export class Api extends cloud.Api implements ISimulatorResource { > = {}; private readonly endpoint: cloud.Endpoint; - private readonly policy: Policy; constructor(scope: Construct, id: string, props: cloud.ApiProps = {}) { super(scope, id, props); @@ -36,7 +34,6 @@ export class Api extends cloud.Api implements ISimulatorResource { simulatorAttrToken(this, "url"), { label: `Api ${this.node.path}` } ); - this.policy = new Policy(this, "Policy", { principal: this }); } protected get _endpoint(): cloud.Endpoint { @@ -119,7 +116,6 @@ export class Api extends cloud.Api implements ISimulatorResource { target: fn, name: `${method.toLowerCase()}()`, }); - this.policy.addStatement(fn, cloud.FunctionInflightMethods.INVOKE); } /** @@ -249,7 +245,7 @@ export class Api extends cloud.Api implements ISimulatorResource { } public onLift(host: IInflightHost, ops: string[]): void { - bindSimulatorResource(__filename, this, host, ops); + bindSimulatorResource(__filename, this, host); super.onLift(host, ops); } diff --git a/libs/wingsdk/src/target-sim/app.ts b/libs/wingsdk/src/target-sim/app.ts index 140dddb7454..8595c37bc6a 100644 --- a/libs/wingsdk/src/target-sim/app.ts +++ b/libs/wingsdk/src/target-sim/app.ts @@ -9,14 +9,13 @@ import { Endpoint } from "./endpoint"; import { EVENT_MAPPING_FQN } from "./event-mapping"; import { Function } from "./function"; import { OnDeploy } from "./on-deploy"; -import { POLICY_FQN, Policy } from "./policy"; import { Queue } from "./queue"; import { ReactApp } from "./react-app"; import { Redis } from "./redis"; import { ISimulatorResource, isSimulatorResource } from "./resource"; import { Schedule } from "./schedule"; import { Secret } from "./secret"; -import { SERVICE_HELPER_FQN, Service, ServiceHelper } from "./service"; +import { Service } from "./service"; import { STATE_FQN, State } from "./state"; import { Table } from "./table"; import { TestRunner } from "./test-runner"; @@ -60,14 +59,12 @@ const SIMULATOR_CLASS_DATA = { [EVENT_MAPPING_FQN]: "EventMapping", [FUNCTION_FQN]: "Function", [ON_DEPLOY_FQN]: "OnDeploy", - [POLICY_FQN]: "Policy", [QUEUE_FQN]: "Queue", [REACT_APP_FQN]: "ReactApp", [REDIS_FQN]: "Redis", [SCHEDULE_FQN]: "Schedule", [SECRET_FQN]: "Secret", [SERVICE_FQN]: "Service", - [SERVICE_HELPER_FQN]: "ServiceHelper", [STATE_FQN]: "State", [SIM_CONTAINER_FQN]: "Container", [TABLE_FQN]: "Table", @@ -122,9 +119,6 @@ export class App extends core.App { case ON_DEPLOY_FQN: return require.resolve("./on-deploy.inflight"); - case POLICY_FQN: - return require.resolve("./policy.inflight"); - case QUEUE_FQN: return require.resolve("./queue.inflight"); @@ -143,9 +137,6 @@ export class App extends core.App { case SERVICE_FQN: return require.resolve("./service.inflight"); - case SERVICE_HELPER_FQN: - return require.resolve("./service.inflight"); - case STATE_FQN: return require.resolve("./state.inflight"); @@ -193,9 +184,6 @@ export class App extends core.App { case ON_DEPLOY_FQN: return OnDeploy; - case POLICY_FQN: - return Policy; - case QUEUE_FQN: return Queue; @@ -214,9 +202,6 @@ export class App extends core.App { case SERVICE_FQN: return Service; - case SERVICE_HELPER_FQN: - return ServiceHelper; - case STATE_FQN: return State; diff --git a/libs/wingsdk/src/target-sim/bucket.inflight.ts b/libs/wingsdk/src/target-sim/bucket.inflight.ts index 18cb87ed8f2..f4178e6e50b 100644 --- a/libs/wingsdk/src/target-sim/bucket.inflight.ts +++ b/libs/wingsdk/src/target-sim/bucket.inflight.ts @@ -28,31 +28,23 @@ import { Datetime, Json, TraceType } from "../std"; export const METADATA_FILENAME = "metadata.json"; export class Bucket implements IBucketClient, ISimulatorResourceInstance { - private _fileDir!: string; - private _context: ISimulatorContext | undefined; + private readonly _fileDir: string; + private readonly context: ISimulatorContext; private readonly initialObjects: Record; private readonly _public: boolean; private readonly topicHandlers: Partial>; private _metadata: Map; - public constructor(props: BucketSchema["props"]) { + public constructor(props: BucketSchema["props"], context: ISimulatorContext) { + this._fileDir = join(context.statedir, "files"); + this.context = context; this.initialObjects = props.initialObjects ?? {}; this._public = props.public ?? false; this.topicHandlers = props.topics; this._metadata = new Map(); } - private get context(): ISimulatorContext { - if (!this._context) { - throw new Error("Cannot access context during class construction"); - } - return this._context; - } - - public async init(context: ISimulatorContext): Promise { - this._context = context; - this._fileDir = join(context.statedir, "files"); - + public async init(): Promise { const fileDirExists = await exists(this._fileDir); if (!fileDirExists) { await fs.promises.mkdir(this._fileDir, { recursive: true }); diff --git a/libs/wingsdk/src/target-sim/bucket.ts b/libs/wingsdk/src/target-sim/bucket.ts index 0d263dbfec1..afb13c5573b 100644 --- a/libs/wingsdk/src/target-sim/bucket.ts +++ b/libs/wingsdk/src/target-sim/bucket.ts @@ -1,6 +1,5 @@ import { join } from "path"; import { Construct } from "constructs"; -import { Policy } from "./policy"; import { ISimulatorResource } from "./resource"; import { BucketSchema } from "./schema-resources"; import { simulatorHandleToken } from "./tokens"; @@ -17,13 +16,10 @@ import { IInflightHost } from "../std"; export class Bucket extends cloud.Bucket implements ISimulatorResource { private readonly public: boolean; private readonly initialObjects: Record = {}; - private readonly policy: Policy; - constructor(scope: Construct, id: string, props: cloud.BucketProps = {}) { super(scope, id, props); this.public = props.public ?? false; - this.policy = new Policy(this, "Policy", { principal: this }); } /** @internal */ @@ -45,7 +41,6 @@ export class Bucket extends cloud.Bucket implements ISimulatorResource { cloud.BucketInflightMethods.RENAME, ]; } - /** * Iterates over the topics and supply their sim handler * @returns an object of Bucket event types (keys) and their topic handlers (values) @@ -64,46 +59,6 @@ export class Bucket extends cloud.Bucket implements ISimulatorResource { this.initialObjects[key] = body; } - public onCreate( - fn: cloud.IBucketEventHandler, - opts?: cloud.BucketOnCreateOptions | undefined - ): void { - super.onCreate(fn, opts); - const topic = this.getTopic(cloud.BucketEventType.CREATE); - this.policy.addStatement(topic, cloud.TopicInflightMethods.PUBLISH); - } - - public onDelete( - fn: cloud.IBucketEventHandler, - opts?: cloud.BucketOnDeleteOptions | undefined - ): void { - super.onDelete(fn, opts); - const topic = this.getTopic(cloud.BucketEventType.DELETE); - this.policy.addStatement(topic, cloud.TopicInflightMethods.PUBLISH); - } - - public onUpdate( - fn: cloud.IBucketEventHandler, - opts?: cloud.BucketOnUpdateOptions | undefined - ): void { - super.onUpdate(fn, opts); - const topic = this.getTopic(cloud.BucketEventType.UPDATE); - this.policy.addStatement(topic, cloud.TopicInflightMethods.PUBLISH); - } - - public onEvent( - fn: cloud.IBucketEventHandler, - opts?: cloud.BucketOnEventOptions - ): void { - super.onEvent(fn, opts); - const createTopic = this.getTopic(cloud.BucketEventType.CREATE); - this.policy.addStatement(createTopic, cloud.TopicInflightMethods.PUBLISH); - const deleteTopic = this.getTopic(cloud.BucketEventType.DELETE); - this.policy.addStatement(deleteTopic, cloud.TopicInflightMethods.PUBLISH); - const updateTopic = this.getTopic(cloud.BucketEventType.UPDATE); - this.policy.addStatement(updateTopic, cloud.TopicInflightMethods.PUBLISH); - } - protected eventHandlerLocation(): string { return join(__dirname, "bucket.onevent.inflight.js"); } @@ -124,7 +79,7 @@ export class Bucket extends cloud.Bucket implements ISimulatorResource { } public onLift(host: IInflightHost, ops: string[]): void { - bindSimulatorResource(__filename, this, host, ops); + bindSimulatorResource(__filename, this, host); super.onLift(host, ops); } diff --git a/libs/wingsdk/src/target-sim/container.inflight.ts b/libs/wingsdk/src/target-sim/container.inflight.ts index dd4071718f1..51f2cfd72a2 100644 --- a/libs/wingsdk/src/target-sim/container.inflight.ts +++ b/libs/wingsdk/src/target-sim/container.inflight.ts @@ -12,23 +12,27 @@ import { Util } from "../util"; export class Container implements IContainerClient, ISimulatorResourceInstance { private readonly imageTag: string; private readonly containerName: string; - private _context: ISimulatorContext | undefined; - public constructor(private readonly props: ContainerSchema["props"]) { + public constructor( + private readonly props: ContainerSchema["props"], + private readonly context: ISimulatorContext + ) { this.imageTag = props.imageTag; this.containerName = `wing-container-${Util.ulid()}`; } - private get context(): ISimulatorContext { - if (!this._context) { - throw new Error("Cannot access context during class construction"); - } - return this._context; + private log(message: string) { + this.context.addTrace({ + data: { message }, + sourcePath: this.context.resourcePath, + sourceType: "container", + timestamp: new Date().toISOString(), + type: TraceType.LOG, + }); } - public async init(context: ISimulatorContext): Promise { - this._context = context; + public async init(): Promise { // if this a reference to a local directory, build the image from a docker file if (isPath(this.props.image)) { // check if the image is already built @@ -130,16 +134,6 @@ export class Container implements IContainerClient, ISimulatorResourceInstance { public async plan() { return UpdatePlan.AUTO; } - - private log(message: string) { - this.context.addTrace({ - data: { message }, - sourcePath: this.context.resourcePath, - sourceType: "container", - timestamp: new Date().toISOString(), - type: TraceType.LOG, - }); - } } async function waitUntil(predicate: () => Promise) { diff --git a/libs/wingsdk/src/target-sim/container.ts b/libs/wingsdk/src/target-sim/container.ts index af4022f5392..947553686de 100644 --- a/libs/wingsdk/src/target-sim/container.ts +++ b/libs/wingsdk/src/target-sim/container.ts @@ -119,7 +119,7 @@ export class Container extends Resource implements ISimulatorResource { } public onLift(host: IInflightHost, ops: string[]): void { - bindSimulatorResource(__filename, this, host, ops); + bindSimulatorResource(__filename, this, host); super.onLift(host, ops); } diff --git a/libs/wingsdk/src/target-sim/counter.inflight.ts b/libs/wingsdk/src/target-sim/counter.inflight.ts index d4ef6ce46de..3e52273cb8a 100644 --- a/libs/wingsdk/src/target-sim/counter.inflight.ts +++ b/libs/wingsdk/src/target-sim/counter.inflight.ts @@ -14,22 +14,18 @@ const VALUES_FILENAME = "values.json"; export class Counter implements ICounterClient, ISimulatorResourceInstance { private values: Map; private initial: number; - private _context: ISimulatorContext | undefined; + private readonly context: ISimulatorContext; - public constructor(props: CounterSchema["props"]) { + public constructor( + props: CounterSchema["props"], + context: ISimulatorContext + ) { this.initial = props.initial ?? 0; this.values = new Map().set("default", this.initial); + this.context = context; } - private get context(): ISimulatorContext { - if (!this._context) { - throw new Error("Cannot access context during class construction"); - } - return this._context; - } - - public async init(context: ISimulatorContext): Promise { - this._context = context; + public async init(): Promise { const valuesFile = join(this.context.statedir, VALUES_FILENAME); const valueFilesExists = await exists(valuesFile); if (valueFilesExists) { diff --git a/libs/wingsdk/src/target-sim/counter.ts b/libs/wingsdk/src/target-sim/counter.ts index 0c9c15f5b9e..a70abfabdf6 100644 --- a/libs/wingsdk/src/target-sim/counter.ts +++ b/libs/wingsdk/src/target-sim/counter.ts @@ -43,7 +43,7 @@ export class Counter extends cloud.Counter implements ISimulatorResource { } public onLift(host: IInflightHost, ops: string[]): void { - bindSimulatorResource(__filename, this, host, ops); + bindSimulatorResource(__filename, this, host); super.onLift(host, ops); } diff --git a/libs/wingsdk/src/target-sim/domain.inflight.ts b/libs/wingsdk/src/target-sim/domain.inflight.ts index b04c0ae80de..22aa307a33a 100644 --- a/libs/wingsdk/src/target-sim/domain.inflight.ts +++ b/libs/wingsdk/src/target-sim/domain.inflight.ts @@ -7,8 +7,8 @@ import { } from "../simulator"; export class Domain implements IDomainClient, ISimulatorResourceInstance { - constructor(_props: DomainSchema["props"]) {} - public async init(_context: ISimulatorContext): Promise> { + constructor(_props: DomainSchema["props"], _context: ISimulatorContext) {} + public async init(): Promise> { return {}; } diff --git a/libs/wingsdk/src/target-sim/endpoint.inflight.ts b/libs/wingsdk/src/target-sim/endpoint.inflight.ts index fc3188c635a..6b6df4eaea3 100644 --- a/libs/wingsdk/src/target-sim/endpoint.inflight.ts +++ b/libs/wingsdk/src/target-sim/endpoint.inflight.ts @@ -29,19 +29,11 @@ export class Endpoint implements IEndpointClient, ISimulatorResourceInstance { private connectResponse?: ConnectResponse; private lastSubdomain?: string; private status: EndpointExposeStatus = "disconnected"; - private _context: ISimulatorContext | undefined; - - constructor(private readonly _props: EndpointSchema["props"]) {} - - private get context(): ISimulatorContext { - if (!this._context) { - throw new Error("Cannot access context during class construction"); - } - return this._context; - } - - public async init(context: ISimulatorContext): Promise { - this._context = context; + constructor( + private readonly _props: EndpointSchema["props"], + private readonly _context: ISimulatorContext + ) {} + public async init(): Promise { const state: StateFileContents = await this.loadState(); if (state.subdomain) { await this.connect(state.subdomain); @@ -89,11 +81,11 @@ export class Endpoint implements IEndpointClient, ISimulatorResourceInstance { private async loadState(): Promise { const stateFileExists = await exists( - join(this.context.statedir, STATE_FILENAME) + join(this._context.statedir, STATE_FILENAME) ); if (stateFileExists) { const stateFileContents = await readFile( - join(this.context.statedir, STATE_FILENAME), + join(this._context.statedir, STATE_FILENAME), "utf-8" ); return JSON.parse(stateFileContents); @@ -104,14 +96,14 @@ export class Endpoint implements IEndpointClient, ISimulatorResourceInstance { private async saveState(state: StateFileContents): Promise { writeFileSync( - join(this.context.statedir, STATE_FILENAME), + join(this._context.statedir, STATE_FILENAME), JSON.stringify(state) ); } private async connect(subdomain?: string) { try { - await this.context.withTrace({ + await this._context.withTrace({ message: `Creating tunnel for endpoint. ${ subdomain ? `Using subdomain: ${subdomain}` : "" }`, diff --git a/libs/wingsdk/src/target-sim/event-mapping.inflight.ts b/libs/wingsdk/src/target-sim/event-mapping.inflight.ts index d1b7239405f..c0c2b19956f 100644 --- a/libs/wingsdk/src/target-sim/event-mapping.inflight.ts +++ b/libs/wingsdk/src/target-sim/event-mapping.inflight.ts @@ -3,47 +3,34 @@ import { EventMappingAttributes, EventMappingSchema, EventSubscription, - ResourceHandle, + FunctionHandle, + PublisherHandle, } from "./schema-resources"; import { ISimulatorContext } from "../simulator"; import { ISimulatorResourceInstance, UpdatePlan } from "../simulator/simulator"; export class EventMapping implements ISimulatorResourceInstance { - private readonly publisher: ResourceHandle; - private readonly subscriber: ResourceHandle; + private readonly publisher: PublisherHandle; + private readonly subscriber: FunctionHandle; private readonly eventSubscription: EventSubscription; - private _context: ISimulatorContext | undefined; + private readonly context: ISimulatorContext; - constructor(props: EventMappingSchema["props"]) { + constructor(props: EventMappingSchema["props"], context: ISimulatorContext) { this.publisher = props.publisher; this.subscriber = props.subscriber; this.eventSubscription = props.subscriptionProps; - } - private get context(): ISimulatorContext { - if (!this._context) { - throw new Error("Cannot access context during class construction"); - } - return this._context; + this.context = context; } - public async init( - context: ISimulatorContext - ): Promise { - this._context = context; - const client = this.context.getClient( - this.publisher, - true - ) as IEventPublisher; + public async init(): Promise { + const client = this.context.getClient(this.publisher) as IEventPublisher; await client.addEventSubscription(this.subscriber, this.eventSubscription); return {}; } public async cleanup(): Promise { - const client = this.context.getClient( - this.publisher, - true - ) as IEventPublisher; + const client = this.context.getClient(this.publisher) as IEventPublisher; await client.removeEventSubscription(this.subscriber); } diff --git a/libs/wingsdk/src/target-sim/event-mapping.ts b/libs/wingsdk/src/target-sim/event-mapping.ts index 4c907613698..b2e7770523d 100644 --- a/libs/wingsdk/src/target-sim/event-mapping.ts +++ b/libs/wingsdk/src/target-sim/event-mapping.ts @@ -3,7 +3,7 @@ import { ISimulatorResource } from "./resource"; import { EventMappingSchema, EventSubscription, - ResourceHandle, + FunctionHandle, } from "./schema-resources"; import { simulatorHandleToken } from "./tokens"; import { bindSimulatorResource, makeSimulatorJsClient } from "./util"; @@ -24,7 +24,7 @@ export interface IEventPublisher extends ISimulatorResourceInstance { * @param subscriptionProps additional subscription properties */ addEventSubscription: ( - subscriber: ResourceHandle, + subscriber: FunctionHandle, subscriptionProps: EventSubscription ) => Promise; @@ -33,7 +33,7 @@ export interface IEventPublisher extends ISimulatorResourceInstance { * @param subscriber the subscriber function * @param subscriptionProps additional subscription properties */ - removeEventSubscription: (subscriber: ResourceHandle) => Promise; + removeEventSubscription: (subscriber: FunctionHandle) => Promise; } export const EVENT_MAPPING_FQN = fqnForType("sim.EventMapping"); @@ -87,7 +87,7 @@ export class EventMapping extends Resource implements ISimulatorResource { } public onLift(host: IInflightHost, ops: string[]): void { - bindSimulatorResource(__filename, this, host, ops); + bindSimulatorResource(__filename, this, host); super.onLift(host, ops); } diff --git a/libs/wingsdk/src/target-sim/function.inflight.ts b/libs/wingsdk/src/target-sim/function.inflight.ts index 62cd4440af3..b4d0258f3c4 100644 --- a/libs/wingsdk/src/target-sim/function.inflight.ts +++ b/libs/wingsdk/src/target-sim/function.inflight.ts @@ -11,37 +11,29 @@ import { import { TraceType } from "../std"; export class Function implements IFunctionClient, ISimulatorResourceInstance { - private readonly sourceCodeFile: string; - private originalFile!: string; + private readonly originalFile: string; private bundle: Bundle | undefined; private readonly env: Record; - private _context: ISimulatorContext | undefined; + private readonly context: ISimulatorContext; private readonly timeout: number; private readonly maxWorkers: number; private readonly workers = new Array(); - private createBundlePromise!: Promise; + private createBundlePromise: Promise; - constructor(props: FunctionSchema["props"]) { - this.sourceCodeFile = props.sourceCodeFile; + constructor(props: FunctionSchema["props"], context: ISimulatorContext) { if (props.sourceCodeLanguage !== "javascript") { throw new Error("Only JavaScript is supported"); } + this.originalFile = path.resolve(context.simdir, props.sourceCodeFile); this.env = props.environmentVariables ?? {}; + this.context = context; this.timeout = props.timeout; this.maxWorkers = props.concurrency; - } - private get context(): ISimulatorContext { - if (!this._context) { - throw new Error("Cannot access context during class construction"); - } - return this._context; + this.createBundlePromise = this.createBundle(); } - public async init(context: ISimulatorContext): Promise { - this._context = context; - this.originalFile = path.resolve(context.simdir, this.sourceCodeFile); - this.createBundlePromise = this.createBundle(); + public async init(): Promise { return {}; } @@ -91,14 +83,12 @@ export class Function implements IFunctionClient, ISimulatorResourceInstance { ); } process.nextTick(() => { + // If the call fails, we log the error and continue since we've already + // handed control back to the caller. void worker.call("handler", payload).catch((e) => { - // If the call fails, we log the error and continue since we've already - // handed control back to the caller. this.context.addTrace({ data: { - message: `InvokeAsync (payload=${JSON.stringify( - payload - )}) failure.`, + message: `InvokeAsync (payload=${JSON.stringify(payload)}).`, status: "failure", error: e, }, @@ -153,7 +143,6 @@ export class Function implements IFunctionClient, ISimulatorResourceInstance { return new Sandbox(this.bundle.entrypointPath, { env: { ...this.env, - WING_SIMULATOR_CALLER: this.context.resourceHandle, WING_SIMULATOR_URL: this.context.serverUrl, }, timeout: this.timeout, diff --git a/libs/wingsdk/src/target-sim/function.ts b/libs/wingsdk/src/target-sim/function.ts index b106cf732a4..3a77d1d7951 100644 --- a/libs/wingsdk/src/target-sim/function.ts +++ b/libs/wingsdk/src/target-sim/function.ts @@ -1,13 +1,12 @@ import { relative } from "path"; import { Construct } from "constructs"; -import { Policy } from "./policy"; -import { ISimulatorInflightHost, ISimulatorResource } from "./resource"; +import { ISimulatorResource } from "./resource"; import { FunctionSchema } from "./schema-resources"; import { bindSimulatorResource, makeSimulatorJsClient } from "./util"; import * as cloud from "../cloud"; import { App } from "../core"; import { BaseResourceSchema } from "../simulator/simulator"; -import { IInflightHost, IResource } from "../std"; +import { IInflightHost } from "../std"; import { Duration } from "../std/duration"; export const ENV_WING_SIM_INFLIGHT_RESOURCE_PATH = @@ -20,15 +19,9 @@ export const ENV_WING_SIM_INFLIGHT_RESOURCE_TYPE = * * @inflight `@winglang/sdk.cloud.IFunctionClient` */ -export class Function - extends cloud.Function - implements ISimulatorResource, ISimulatorInflightHost -{ +export class Function extends cloud.Function implements ISimulatorResource { private readonly timeout: Duration; private readonly concurrency: number; - public readonly policy: Policy; - public _liftMap = undefined; - constructor( scope: Construct, id: string, @@ -40,11 +33,6 @@ export class Function // props.memory is unused since we are not simulating it this.timeout = props.timeout ?? Duration.fromMinutes(1); this.concurrency = props.concurrency ?? 100; - this.policy = new Policy(this, "Policy", { principal: this }); - } - - public addPermission(resource: IResource, op: string): void { - this.policy.addStatement(resource, op); } public toSimulator(): BaseResourceSchema { @@ -74,7 +62,7 @@ export class Function } public onLift(host: IInflightHost, ops: string[]): void { - bindSimulatorResource(__filename, this, host, ops); + bindSimulatorResource(__filename, this, host); super.onLift(host, ops); } @@ -83,10 +71,3 @@ export class Function return makeSimulatorJsClient(__filename, this); } } - -/** - * Simulator-specific inflight methods for `cloud.Function`. - */ -export enum FunctionInflightMethods { - HAS_AVAILABLE_WORKERS = "hasAvailableWorkers", -} diff --git a/libs/wingsdk/src/target-sim/index.ts b/libs/wingsdk/src/target-sim/index.ts index 7b8fd8ebf68..dd8a337a355 100644 --- a/libs/wingsdk/src/target-sim/index.ts +++ b/libs/wingsdk/src/target-sim/index.ts @@ -1,5 +1,4 @@ // only include here types that we want to expose in userland export * from "./container"; -export * from "./policy"; export * from "./resource"; export * from "./state"; diff --git a/libs/wingsdk/src/target-sim/on-deploy.inflight.ts b/libs/wingsdk/src/target-sim/on-deploy.inflight.ts index 2e3fe927cc6..8184d522013 100644 --- a/libs/wingsdk/src/target-sim/on-deploy.inflight.ts +++ b/libs/wingsdk/src/target-sim/on-deploy.inflight.ts @@ -8,17 +8,21 @@ import { export class OnDeploy implements IOnDeployClient, ISimulatorResourceInstance { private functionHandle: string; + private readonly context: ISimulatorContext; - public constructor(props: OnDeploySchema["props"]) { + public constructor( + props: OnDeploySchema["props"], + context: ISimulatorContext + ) { this.functionHandle = props.functionHandle; + this.context = context; } - public async init(context: ISimulatorContext): Promise { - const functionClient = context.getClient( - this.functionHandle, - true + public async init(): Promise { + const functionClient = this.context.getClient( + this.functionHandle ) as IFunctionClient; - await context.withTrace({ + await this.context.withTrace({ message: "OnDeploy invoked.", activity: async () => { return functionClient.invoke(); @@ -32,7 +36,6 @@ export class OnDeploy implements IOnDeployClient, ISimulatorResourceInstance { public async save(): Promise {} public async plan() { - // OnDeploy runs on every deployment, so always replace - return UpdatePlan.REPLACE; + return UpdatePlan.AUTO; } } diff --git a/libs/wingsdk/src/target-sim/on-deploy.ts b/libs/wingsdk/src/target-sim/on-deploy.ts index 8d55e3ff565..6ce6c767624 100644 --- a/libs/wingsdk/src/target-sim/on-deploy.ts +++ b/libs/wingsdk/src/target-sim/on-deploy.ts @@ -1,5 +1,4 @@ import { Construct } from "constructs"; -import { Function as SimFunction } from "./function"; import { OnDeploySchema } from "./schema-resources"; import { simulatorHandleToken } from "./tokens"; import { bindSimulatorResource, makeSimulatorJsClient } from "./util"; @@ -21,7 +20,6 @@ export class OnDeploy extends cloud.OnDeploy { Node.of(this.fn).sourceModule = SDK_SOURCE_MODULE; this.node.addDependency(this.fn); - this.node.addDependency((this.fn as SimFunction).policy); for (const c of props.executeBefore ?? []) { c.node.addDependency(this); @@ -46,7 +44,7 @@ export class OnDeploy extends cloud.OnDeploy { } public onLift(host: IInflightHost, ops: string[]): void { - bindSimulatorResource(__filename, this, host, ops); + bindSimulatorResource(__filename, this, host); super.onLift(host, ops); } diff --git a/libs/wingsdk/src/target-sim/policy.inflight.ts b/libs/wingsdk/src/target-sim/policy.inflight.ts deleted file mode 100644 index 7c05110d0f0..00000000000 --- a/libs/wingsdk/src/target-sim/policy.inflight.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { IPolicyClient } from "./policy"; -import { PolicySchema } from "./schema-resources"; -import { - ISimulatorContext, - ISimulatorResourceInstance, - UpdatePlan, -} from "../simulator"; - -export class Policy implements IPolicyClient, ISimulatorResourceInstance { - constructor(_props: PolicySchema["props"]) {} - public async init(_context: ISimulatorContext): Promise> { - return {}; - } - - public async cleanup(): Promise {} - - public async save(): Promise {} - - public async plan(): Promise { - return UpdatePlan.AUTO; - } -} diff --git a/libs/wingsdk/src/target-sim/policy.ts b/libs/wingsdk/src/target-sim/policy.ts deleted file mode 100644 index 7c264237e48..00000000000 --- a/libs/wingsdk/src/target-sim/policy.ts +++ /dev/null @@ -1,72 +0,0 @@ -import { Construct } from "constructs"; -import { ISimulatorResource } from "./resource"; -import { PolicySchema, PolicyStatement } from "./schema-resources"; -import { simulatorHandleToken } from "./tokens"; -import { fqnForType } from "../constants"; -import { BaseResourceSchema } from "../simulator"; -import { IResource, Node, Resource } from "../std"; - -export const POLICY_FQN = fqnForType("sim.Policy"); - -/** - * Options for `sim.Policy`. - */ -export interface PolicyProps { - /** - * The resource to which the policy is attached. - */ - readonly principal: IResource; -} - -/** - * Implementation of `sim.Policy`. - */ -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; - Node.of(this).hidden = true; - Node.of(this).title = "Policy"; - Node.of(this).description = "A simulated resource policy"; - } - - /** - * Adds a statement to the policy. - */ - public addStatement(resource: IResource, op: string): void { - if (!this.statements.has(resource)) { - this.statements.set(resource, new Set()); - } - this.statements.get(resource)!.add(op); - } - - public toSimulator(): BaseResourceSchema { - const statements: Array = []; - for (const [resource, ops] of this.statements.entries()) { - for (const op of ops) { - statements.push({ - resourceHandle: simulatorHandleToken(resource), - operation: op, - }); - } - } - const schema: PolicySchema = { - type: POLICY_FQN, - path: this.node.path, - addr: this.node.addr, - props: { - principal: simulatorHandleToken(this.principal), - statements, - }, - attrs: {} as any, - }; - return schema; - } -} - -/** - * Inflight interface for `Policy`. - */ -export interface IPolicyClient {} diff --git a/libs/wingsdk/src/target-sim/queue.inflight.ts b/libs/wingsdk/src/target-sim/queue.inflight.ts index ecd19aa7659..3ab1683a2e9 100644 --- a/libs/wingsdk/src/target-sim/queue.inflight.ts +++ b/libs/wingsdk/src/target-sim/queue.inflight.ts @@ -5,7 +5,7 @@ import { QueueSchema, QueueSubscriber, EventSubscription, - ResourceHandle, + FunctionHandle, } from "./schema-resources"; import { IFunctionClient, IQueueClient, QUEUE_FQN } from "../cloud"; import { @@ -21,25 +21,18 @@ export class Queue private readonly messages = new Array(); private readonly subscribers = new Array(); private readonly processLoop: LoopController; - private _context: ISimulatorContext | undefined; + private readonly context: ISimulatorContext; private readonly timeoutSeconds: number; private readonly retentionPeriod: number; - constructor(props: QueueSchema["props"]) { + constructor(props: QueueSchema["props"], context: ISimulatorContext) { this.timeoutSeconds = props.timeout; this.retentionPeriod = props.retentionPeriod; this.processLoop = runEvery(100, async () => this.processMessages()); // every 0.1 seconds + this.context = context; } - private get context(): ISimulatorContext { - if (!this._context) { - throw new Error("Cannot access context during class construction"); - } - return this._context; - } - - public async init(context: ISimulatorContext): Promise { - this._context = context; + public async init(): Promise { return {}; } @@ -54,7 +47,7 @@ export class Queue } public async addEventSubscription( - subscriber: ResourceHandle, + subscriber: FunctionHandle, subscriptionProps: EventSubscription ): Promise { const s = { @@ -65,7 +58,7 @@ export class Queue } public async removeEventSubscription( - subscriber: ResourceHandle + subscriber: FunctionHandle ): Promise { const index = this.subscribers.findIndex( (s) => s.functionHandle === subscriber diff --git a/libs/wingsdk/src/target-sim/queue.ts b/libs/wingsdk/src/target-sim/queue.ts index 52077d72a30..632ea5dba0e 100644 --- a/libs/wingsdk/src/target-sim/queue.ts +++ b/libs/wingsdk/src/target-sim/queue.ts @@ -2,11 +2,7 @@ import { join } from "path"; import { Construct } from "constructs"; import { App } from "./app"; import { EventMapping } from "./event-mapping"; -import { - Function, - FunctionInflightMethods as SimFunctionInflightMethods, -} from "./function"; -import { Policy } from "./policy"; +import { Function } from "./function"; import { ISimulatorResource } from "./resource"; import { QueueSchema } from "./schema-resources"; import { bindSimulatorResource, makeSimulatorJsClient } from "./util"; @@ -24,7 +20,6 @@ import { Duration, IInflightHost, Node, SDK_SOURCE_MODULE } from "../std"; export class Queue extends cloud.Queue implements ISimulatorResource { private readonly timeout: Duration; private readonly retentionPeriod: Duration; - private readonly policy: Policy; constructor(scope: Construct, id: string, props: cloud.QueueProps = {}) { super(scope, id, props); @@ -47,8 +42,6 @@ export class Queue extends cloud.Queue implements ISimulatorResource { "Retention period must be greater than or equal to timeout" ); } - - this.policy = new Policy(this, "Policy", { principal: this }); } /** @internal */ @@ -116,12 +109,6 @@ export class Queue extends cloud.Queue implements ISimulatorResource { name: "setConsumer()", }); - this.policy.addStatement(fn, cloud.FunctionInflightMethods.INVOKE); - this.policy.addStatement( - fn, - SimFunctionInflightMethods.HAS_AVAILABLE_WORKERS - ); - return fn; } @@ -140,7 +127,7 @@ export class Queue extends cloud.Queue implements ISimulatorResource { } public onLift(host: IInflightHost, ops: string[]): void { - bindSimulatorResource(__filename, this, host, ops); + bindSimulatorResource(__filename, this, host); super.onLift(host, ops); } diff --git a/libs/wingsdk/src/target-sim/react-app.inflight.ts b/libs/wingsdk/src/target-sim/react-app.inflight.ts index ecbea6d853a..c0fe6c181bf 100644 --- a/libs/wingsdk/src/target-sim/react-app.inflight.ts +++ b/libs/wingsdk/src/target-sim/react-app.inflight.ts @@ -12,7 +12,7 @@ import { import { TraceType } from "../std"; export class ReactApp implements IReactAppClient, ISimulatorResourceInstance { - private _context: ISimulatorContext | undefined; + private readonly context: ISimulatorContext; private readonly startCommand: string; private readonly path: string; private readonly environmentVariables: Record; @@ -21,7 +21,8 @@ export class ReactApp implements IReactAppClient, ISimulatorResourceInstance { private childProcess?: ChildProcess; private url: string; - constructor(props: ReactAppSchema["props"]) { + constructor(props: ReactAppSchema["props"], context: ISimulatorContext) { + this.context = context; this.path = props.path; this.startCommand = props.startCommand; this.environmentVariables = props.environmentVariables; @@ -30,15 +31,7 @@ export class ReactApp implements IReactAppClient, ISimulatorResourceInstance { this.url = props.url; } - private get context(): ISimulatorContext { - if (!this._context) { - throw new Error("Cannot access context during class construction"); - } - return this._context; - } - - public async init(context: ISimulatorContext): Promise { - this._context = context; + public async init(): Promise { this.addTrace(`Executing start command: ${this.startCommand}`); writeFileSync( diff --git a/libs/wingsdk/src/target-sim/react-app.ts b/libs/wingsdk/src/target-sim/react-app.ts index 78c96c77f46..825428ec240 100644 --- a/libs/wingsdk/src/target-sim/react-app.ts +++ b/libs/wingsdk/src/target-sim/react-app.ts @@ -61,7 +61,7 @@ export class ReactApp extends ex.ReactApp implements ISimulatorResource { } public onLift(host: IInflightHost, ops: string[]): void { - bindSimulatorResource(__filename, this, host, ops); + bindSimulatorResource(__filename, this, host); super.onLift(host, ops); } diff --git a/libs/wingsdk/src/target-sim/redis.inflight.ts b/libs/wingsdk/src/target-sim/redis.inflight.ts index 7fc42111c57..b9d06b54cd8 100644 --- a/libs/wingsdk/src/target-sim/redis.inflight.ts +++ b/libs/wingsdk/src/target-sim/redis.inflight.ts @@ -15,11 +15,14 @@ export class Redis private connection?: IoRedis; private isCleanedUp = false; - public constructor(private readonly props: RedisSchema["props"]) { + public constructor( + private readonly props: RedisSchema["props"], + _context: ISimulatorContext + ) { super(); } - public async init(_context: ISimulatorContext): Promise { + public async init(): Promise { try { if (this.isCleanedUp) { return {}; diff --git a/libs/wingsdk/src/target-sim/redis.ts b/libs/wingsdk/src/target-sim/redis.ts index a2d3c6fe886..908ee7f9ccb 100644 --- a/libs/wingsdk/src/target-sim/redis.ts +++ b/libs/wingsdk/src/target-sim/redis.ts @@ -50,7 +50,7 @@ export class Redis extends ex.Redis implements ISimulatorResource { } public onLift(host: IInflightHost, ops: string[]): void { - bindSimulatorResource(__filename, this, host, ops); + bindSimulatorResource(__filename, this, host); super.onLift(host, ops); } diff --git a/libs/wingsdk/src/target-sim/resource.ts b/libs/wingsdk/src/target-sim/resource.ts index 2c861f5dc76..d3dfd03d7de 100644 --- a/libs/wingsdk/src/target-sim/resource.ts +++ b/libs/wingsdk/src/target-sim/resource.ts @@ -1,29 +1,9 @@ import { BaseResourceSchema } from "../simulator/simulator"; -import { IInflightHost, IResource } from "../std"; +import { IResource } from "../std"; /** - * Interfaces shared by all preflight classes that host inflight code. - */ -export interface ISimulatorInflightHost extends IInflightHost { - /** - * Add a simulated permission to this inflight host. - * @param resource The resource to add - * @param op The action to add - */ - addPermission(resource: IResource, op: string): void; -} - -export function isSimulatorInflightHost( - obj: any -): obj is ISimulatorInflightHost { - return ( - typeof obj == "object" && - typeof (obj as ISimulatorInflightHost).addPermission === "function" - ); -} - -/** - * Interfaces shared by all preflight classes targeting the simulator. + * Interfaces shared by all polycon implementations (preflight classes) + * targeting the simulator. */ export interface ISimulatorResource extends IResource { /** diff --git a/libs/wingsdk/src/target-sim/schedule.inflight.ts b/libs/wingsdk/src/target-sim/schedule.inflight.ts index 5c44bebbacb..b2bade5f30d 100644 --- a/libs/wingsdk/src/target-sim/schedule.inflight.ts +++ b/libs/wingsdk/src/target-sim/schedule.inflight.ts @@ -17,23 +17,17 @@ import { TraceType } from "../std"; export class Schedule implements IScheduleClient, ISimulatorResourceInstance, IEventPublisher { - private _context: ISimulatorContext | undefined; + private readonly context: ISimulatorContext; private tasks = new Array(); private interval: CronExpression; private intervalTimeout?: NodeJS.Timeout; - constructor(props: ScheduleSchema["props"]) { + constructor(props: ScheduleSchema["props"], context: ISimulatorContext) { + this.context = context; this.interval = parseExpression(props.cronExpression, { utc: true }); this.scheduleFunction(); } - private get context(): ISimulatorContext { - if (!this._context) { - throw new Error("Cannot access context during class construction"); - } - return this._context; - } - // Calculate the delay for the next execution private nextDelay(interval: CronExpression) { return interval.next().toDate().getTime() - Date.now(); @@ -47,8 +41,7 @@ export class Schedule }, this.nextDelay(this.interval)); } - public async init(context: ISimulatorContext): Promise { - this._context = context; + public async init(): Promise { return {}; } diff --git a/libs/wingsdk/src/target-sim/schedule.ts b/libs/wingsdk/src/target-sim/schedule.ts index 807f24b5c74..31289df757a 100644 --- a/libs/wingsdk/src/target-sim/schedule.ts +++ b/libs/wingsdk/src/target-sim/schedule.ts @@ -3,7 +3,6 @@ import { Construct } from "constructs"; import { App } from "./app"; import { EventMapping } from "./event-mapping"; import { Function } from "./function"; -import { Policy } from "./policy"; import { ISimulatorResource } from "./resource"; import { ScheduleSchema } from "./schema-resources"; import { @@ -23,14 +22,12 @@ import { IInflightHost, Node, SDK_SOURCE_MODULE } from "../std"; */ export class Schedule extends cloud.Schedule implements ISimulatorResource { private readonly cronExpression: string; - private readonly policy: Policy; constructor(scope: Construct, id: string, props: cloud.ScheduleProps = {}) { super(scope, id, props); const { rate, cron } = props; this.cronExpression = cron ?? convertDurationToCronExpression(rate!); - this.policy = new Policy(this, "Policy", { principal: this }); } public onTick( @@ -63,7 +60,6 @@ export class Schedule extends cloud.Schedule implements ISimulatorResource { target: fn, name: "onTick()", }); - this.policy.addStatement(fn, cloud.FunctionInflightMethods.INVOKE); return fn; } @@ -87,7 +83,7 @@ export class Schedule extends cloud.Schedule implements ISimulatorResource { } public onLift(host: IInflightHost, ops: string[]): void { - bindSimulatorResource(__filename, this, host, ops); + bindSimulatorResource(__filename, this, host); super.onLift(host, ops); } } diff --git a/libs/wingsdk/src/target-sim/schema-resources.ts b/libs/wingsdk/src/target-sim/schema-resources.ts index 6da7f402ace..420843f531a 100644 --- a/libs/wingsdk/src/target-sim/schema-resources.ts +++ b/libs/wingsdk/src/target-sim/schema-resources.ts @@ -1,7 +1,5 @@ import { SIM_CONTAINER_FQN } from "./container"; import { EVENT_MAPPING_FQN } from "./event-mapping"; -import { POLICY_FQN } from "./policy"; -import { SERVICE_HELPER_FQN } from "./service"; import { STATE_FQN } from "./state"; import { API_FQN, @@ -28,7 +26,8 @@ import { } from "../simulator/simulator"; import { Json, TEST_RUNNER_FQN } from "../std"; -export type ResourceHandle = string; +export type FunctionHandle = string; +export type PublisherHandle = string; /** Schema for cloud.Api */ export interface ApiSchema extends BaseResourceSchema { @@ -96,6 +95,8 @@ export interface ServiceSchema extends BaseResourceSchema { readonly props: { /** The source code of the service */ readonly sourceCodeFile: string; + /** Whether the service should start when sim starts */ + readonly autoStart: boolean; /** A map of environment variables to run the function with. */ readonly environmentVariables: Record; }; @@ -104,20 +105,6 @@ export interface ServiceSchema extends BaseResourceSchema { /** Runtime attributes for cloud.Service */ export interface ServiceAttributes {} -/** Schema for sim.ServiceHelper */ -export interface ServiceHelperSchema extends BaseResourceSchema { - readonly type: typeof SERVICE_HELPER_FQN; - readonly props: { - /** The service. */ - readonly service: ResourceHandle; - /** Whether to auto-start the service */ - readonly autoStart: boolean; - }; -} - -/** Runtime attributes for sim.ServiceHelper */ -export interface ServiceHelperAttributes {} - /** Runtime attributes for cloud.Schedule */ export interface ScheduleAttributes {} @@ -133,7 +120,7 @@ export interface ScheduleSchema extends BaseResourceSchema { /** Schema for cloud.Queue.props.subscribers */ export interface ScheduleTask extends EventSubscription { /** Function that should be called. */ - readonly functionHandle: ResourceHandle; + readonly functionHandle: FunctionHandle; } export interface EventSubscription {} @@ -143,9 +130,9 @@ export interface EventMappingSchema extends BaseResourceSchema { readonly type: typeof EVENT_MAPPING_FQN; readonly props: { /** Function handle to call for subscriber */ - subscriber: ResourceHandle; + subscriber: FunctionHandle; /** Publisher handle of the event */ - publisher: ResourceHandle; + publisher: PublisherHandle; /** Additional properties of event subscription */ subscriptionProps: EventSubscription; }; @@ -160,7 +147,7 @@ export interface QueueAttributes {} /** Schema for cloud.Queue.props.subscribers */ export interface QueueSubscriber extends EventSubscription { /** Function that should be called. */ - readonly functionHandle: ResourceHandle; + readonly functionHandle: FunctionHandle; /** Maximum number of messages that will be batched together to the subscriber. */ readonly batchSize: number; } @@ -176,7 +163,7 @@ export interface TopicAttributes {} export interface TopicSubscriber extends EventSubscription { /** Function that should be called */ - readonly functionHandle: ResourceHandle; + readonly functionHandle: FunctionHandle; } /** Runtime attributes for cloud.Table */ @@ -226,7 +213,7 @@ export interface TestRunnerSchema extends BaseResourceSchema { readonly type: typeof TEST_RUNNER_FQN; readonly props: { /** A map from test functions to their handles. */ - readonly tests: Record; + readonly tests: Record; }; } @@ -301,7 +288,7 @@ export interface OnDeploySchema extends BaseResourceSchema { readonly type: typeof ON_DEPLOY_FQN; readonly props: { /** The function to run on deploy. */ - readonly functionHandle: ResourceHandle; + readonly functionHandle: FunctionHandle; }; } @@ -348,9 +335,6 @@ export interface EndpointSchema extends BaseResourceSchema { readonly attrs: EndpointAttributes & BaseResourceAttributes; } -/** Runtime attributes for sim.Policy */ -export interface PolicyAttributes {} - /** Schema for sim.Container */ export interface ContainerSchema extends BaseResourceSchema { readonly type: typeof SIM_CONTAINER_FQN; @@ -367,22 +351,3 @@ export interface ContainerSchema extends BaseResourceSchema { /** Runtime attributes for sim.Container */ export interface ContainerAttributes {} - -/** Schema for sim.Policy */ -export interface PolicySchema extends BaseResourceSchema { - readonly type: typeof POLICY_FQN; - readonly props: PolicySchemaProps; - readonly attrs: PolicyAttributes & BaseResourceAttributes; -} - -export interface PolicySchemaProps { - /** The resource which the policy is attached to. */ - readonly principal: ResourceHandle; - /** The statements in the policy. */ - readonly statements: PolicyStatement[]; -} - -export interface PolicyStatement { - readonly operation: string; - readonly resourceHandle: ResourceHandle; -} diff --git a/libs/wingsdk/src/target-sim/secret.inflight.ts b/libs/wingsdk/src/target-sim/secret.inflight.ts index d178a7bee69..02791e12cf6 100644 --- a/libs/wingsdk/src/target-sim/secret.inflight.ts +++ b/libs/wingsdk/src/target-sim/secret.inflight.ts @@ -11,11 +11,13 @@ import { import { Json, TraceType } from "../std"; export class Secret implements ISecretClient, ISimulatorResourceInstance { - private _context: ISimulatorContext | undefined; + private readonly context: ISimulatorContext; private readonly secretsFile: string; private readonly name: string; - constructor(props: SecretSchema["props"]) { + constructor(props: SecretSchema["props"], context: ISimulatorContext) { + this.context = context; + this.secretsFile = path.join(os.homedir(), ".wing", "secrets.json"); if (!fs.existsSync(this.secretsFile)) { throw new Error( @@ -26,15 +28,7 @@ export class Secret implements ISecretClient, ISimulatorResourceInstance { this.name = props.name; } - private get context(): ISimulatorContext { - if (!this._context) { - throw new Error("Cannot access context during class construction"); - } - return this._context; - } - - public async init(context: ISimulatorContext): Promise { - this._context = context; + public async init(): Promise { return {}; } diff --git a/libs/wingsdk/src/target-sim/secret.ts b/libs/wingsdk/src/target-sim/secret.ts index 97b2a366bfd..aeee0c16a7f 100644 --- a/libs/wingsdk/src/target-sim/secret.ts +++ b/libs/wingsdk/src/target-sim/secret.ts @@ -23,7 +23,7 @@ export class Secret extends cloud.Secret implements ISimulatorResource { } public onLift(host: IInflightHost, ops: string[]): void { - bindSimulatorResource(__filename, this, host, ops); + bindSimulatorResource(__filename, this, host); super.onLift(host, ops); } diff --git a/libs/wingsdk/src/target-sim/service.inflight.ts b/libs/wingsdk/src/target-sim/service.inflight.ts index 4c6ced2f889..fc705431671 100644 --- a/libs/wingsdk/src/target-sim/service.inflight.ts +++ b/libs/wingsdk/src/target-sim/service.inflight.ts @@ -1,9 +1,5 @@ import { resolve } from "path"; -import { - ServiceAttributes, - ServiceHelperSchema, - ServiceSchema, -} from "./schema-resources"; +import { ServiceAttributes, ServiceSchema } from "./schema-resources"; import { IServiceClient, SERVICE_FQN } from "../cloud"; import { Bundle } from "../shared/bundling"; import { Sandbox } from "../shared/sandbox"; @@ -15,45 +11,38 @@ import { import { TraceType } from "../std"; export class Service implements IServiceClient, ISimulatorResourceInstance { - private _context: ISimulatorContext | undefined; - private readonly sourceCodeFile: string; - private resolvedSourceCodeFile!: string; + private readonly context: ISimulatorContext; + private readonly originalFile: string; + private readonly autoStart: boolean; private sandbox: Sandbox | undefined; private bundle: Bundle | undefined; + private createBundlePromise: Promise; private running: boolean = false; private environmentVariables: Record; - private createBundlePromise!: Promise; - constructor(props: ServiceSchema["props"]) { - this.sourceCodeFile = props.sourceCodeFile; + constructor(props: ServiceSchema["props"], context: ISimulatorContext) { + this.context = context; + this.originalFile = resolve(context.simdir, props.sourceCodeFile); + this.autoStart = props.autoStart; this.environmentVariables = props.environmentVariables ?? {}; - } - private get context(): ISimulatorContext { - if (!this._context) { - throw new Error("Cannot access context during class construction"); - } - return this._context; + this.createBundlePromise = this.createBundle(); } private async createBundle(): Promise { - this.bundle = await Sandbox.createBundle( - this.resolvedSourceCodeFile, - (msg) => { - this.addTrace(msg); - } - ); + this.bundle = await Sandbox.createBundle(this.originalFile, (msg) => { + this.addTrace(msg); + }); } - public async init(context: ISimulatorContext): Promise { - this._context = context; - this.resolvedSourceCodeFile = resolve(context.simdir, this.sourceCodeFile); - this.createBundlePromise = this.createBundle(); + public async init(): Promise { + if (this.autoStart) { + await this.start(); + } return {}; } public async cleanup(): Promise { - await this.createBundlePromise; await this.stop(); } @@ -82,7 +71,6 @@ export class Service implements IServiceClient, ISimulatorResourceInstance { env: { ...this.environmentVariables, WING_SIMULATOR_URL: this.context.serverUrl, - WING_SIMULATOR_CALLER: this.context.resourceHandle, }, log: (internal, _level, message) => { this.addTrace(message, internal); @@ -109,7 +97,7 @@ export class Service implements IServiceClient, ISimulatorResourceInstance { await this.sandbox.call("stop"); await this.sandbox.cleanup(); } catch (e: any) { - this.addTrace(`Failed to stop service: ${e.message} ${e.stack}`); + this.addTrace(`Failed to stop service: ${e.message}`); } } @@ -127,41 +115,3 @@ export class Service implements IServiceClient, ISimulatorResourceInstance { }); } } - -export class ServiceHelper implements ISimulatorResourceInstance { - private readonly serviceHandle: string; - private readonly autoStart: boolean; - private _context: ISimulatorContext | undefined; - - public constructor(props: ServiceHelperSchema["props"]) { - this.serviceHandle = props.service; - this.autoStart = props.autoStart; - } - - private get context(): ISimulatorContext { - if (!this._context) { - throw new Error("Cannot access context during class construction"); - } - return this._context; - } - - public async init(context: ISimulatorContext): Promise { - this._context = context; - if (this.autoStart) { - const service = context.getClient(this.serviceHandle, true) as Service; - await service.start(); - } - return {}; - } - - public async cleanup(): Promise { - const service = this.context.getClient(this.serviceHandle, true) as Service; - await service.stop(); - } - - public async save(): Promise {} - - public async plan(): Promise { - return UpdatePlan.AUTO; - } -} diff --git a/libs/wingsdk/src/target-sim/service.ts b/libs/wingsdk/src/target-sim/service.ts index 1269ab419f8..d2c21f26a2a 100644 --- a/libs/wingsdk/src/target-sim/service.ts +++ b/libs/wingsdk/src/target-sim/service.ts @@ -1,22 +1,15 @@ import { relative } from "path"; import { Construct } from "constructs"; -import { Policy } from "./policy"; -import { ISimulatorInflightHost, ISimulatorResource } from "./resource"; -import { ServiceHelperSchema, ServiceSchema } from "./schema-resources"; -import { simulatorHandleToken } from "./tokens"; +import { ISimulatorResource } from "./resource"; +import { ServiceSchema } from "./schema-resources"; import { bindSimulatorResource, makeSimulatorJsClient } from "./util"; import * as cloud from "../cloud"; -import { fqnForType } from "../constants"; import { App } from "../core"; import { BaseResourceSchema } from "../simulator"; -import { IInflightHost, IResource, Resource, Node } from "../std"; +import { IInflightHost } from "../std"; -export class Service - extends cloud.Service - implements ISimulatorResource, ISimulatorInflightHost -{ - public readonly policy: Policy; - public _liftMap = undefined; +export class Service extends cloud.Service implements ISimulatorResource { + private readonly autoStart: boolean; constructor( scope: Construct, @@ -25,18 +18,7 @@ export class Service props: cloud.ServiceProps = {} ) { super(scope, id, handler, props); - this.policy = new Policy(this, "Policy", { principal: this }); - - const helper = new ServiceHelper(this, "Helper", { - service: this, - autoStart: props.autoStart ?? true, - }); - helper.node.addDependency(this); - helper.node.addDependency(this.policy); - } - - public addPermission(resource: IResource, op: string): void { - this.policy.addStatement(resource, op); + this.autoStart = props.autoStart ?? true; } public toSimulator(): BaseResourceSchema { @@ -47,6 +29,7 @@ export class Service props: { environmentVariables: this.env, sourceCodeFile: relative(App.of(this).outdir, this.entrypoint), + autoStart: this.autoStart, }, attrs: {} as any, }; @@ -63,7 +46,7 @@ export class Service } public onLift(host: IInflightHost, ops: string[]): void { - bindSimulatorResource(__filename, this, host, ops); + bindSimulatorResource(__filename, this, host); super.onLift(host, ops); } @@ -71,51 +54,3 @@ export class Service return makeSimulatorJsClient(__filename, this); } } - -/** @internal */ -export const SERVICE_HELPER_FQN = fqnForType("sim.ServiceHelper"); - -/** @internal */ -export interface ServiceHelperProps { - readonly service: Service; - readonly autoStart: boolean; -} - -/** - * This is a helper resource that automatically starts the service after the - * service is created in the simulator and shuts it down when the simulator - * stops. - * - * Suppose a service puts an object in a bucket when it starts. The policy - * (sim.Policy) that grants the service bucket permissions only takes effect - * after the service is created. Because of this, the service needs to be - * started after both the service and the policy are created. Vice versa, the - * service needs to be stopped before the policy is deleted. - * - * @internal - */ -export class ServiceHelper extends Resource implements ISimulatorResource { - private readonly service: Service; - private readonly autoStart: boolean; - - constructor(scope: Construct, id: string, props: ServiceHelperProps) { - super(scope, id); - this.service = props.service; - this.autoStart = props.autoStart; - Node.of(this).hidden = true; - } - - public toSimulator(): BaseResourceSchema { - const schema: ServiceHelperSchema = { - type: SERVICE_HELPER_FQN, - path: this.node.path, - addr: this.node.addr, - props: { - service: simulatorHandleToken(this.service), - autoStart: this.autoStart, - }, - attrs: {} as any, - }; - return schema; - } -} diff --git a/libs/wingsdk/src/target-sim/state.inflight.ts b/libs/wingsdk/src/target-sim/state.inflight.ts index 0472e417740..ceb4f946acd 100644 --- a/libs/wingsdk/src/target-sim/state.inflight.ts +++ b/libs/wingsdk/src/target-sim/state.inflight.ts @@ -8,18 +8,11 @@ import { import { Json } from "../std"; export class State implements IStateClient, ISimulatorResourceInstance { - private _context: ISimulatorContext | undefined; - constructor(_props: StateSchema["props"]) {} - - private get context(): ISimulatorContext { - if (!this._context) { - throw new Error("Cannot access context during class construction"); - } - return this._context; - } - - public async init(context: ISimulatorContext): Promise> { - this._context = context; + constructor( + _props: StateSchema["props"], + private readonly context: ISimulatorContext + ) {} + public async init(): Promise> { return {}; } diff --git a/libs/wingsdk/src/target-sim/state.ts b/libs/wingsdk/src/target-sim/state.ts index 3320bc50903..7f3ed33cc6e 100644 --- a/libs/wingsdk/src/target-sim/state.ts +++ b/libs/wingsdk/src/target-sim/state.ts @@ -53,7 +53,7 @@ export class State extends Resource implements ISimulatorResource { } public onLift(host: IInflightHost, ops: string[]): void { - bindSimulatorResource(__filename, this, host, ops); + bindSimulatorResource(__filename, this, host); super.onLift(host, ops); } diff --git a/libs/wingsdk/src/target-sim/table.inflight.ts b/libs/wingsdk/src/target-sim/table.inflight.ts index ed48673cf11..5e543fc1e7f 100644 --- a/libs/wingsdk/src/target-sim/table.inflight.ts +++ b/libs/wingsdk/src/target-sim/table.inflight.ts @@ -13,26 +13,19 @@ export class Table implements ITableClient, ISimulatorResourceInstance { private columns: { [key: string]: ColumnType }; private primaryKey: string; private table: Map; - private _context: ISimulatorContext | undefined; + private readonly context: ISimulatorContext; private readonly initialRows: Record; - public constructor(props: TableSchema["props"]) { + public constructor(props: TableSchema["props"], context: ISimulatorContext) { this.name = props.name; this.columns = props.columns; this.primaryKey = props.primaryKey; this.table = new Map(); + this.context = context; this.initialRows = props.initialRows ?? {}; } - private get context(): ISimulatorContext { - if (!this._context) { - throw new Error("Cannot access context during class construction"); - } - return this._context; - } - - public async init(context: ISimulatorContext): Promise { - this._context = context; + public async init(): Promise { for (const [key, row] of Object.entries(this.initialRows)) { await this.context.withTrace({ message: `Adding initial row (key=${key}).`, diff --git a/libs/wingsdk/src/target-sim/table.ts b/libs/wingsdk/src/target-sim/table.ts index 58ed24b5f64..6663052eeed 100644 --- a/libs/wingsdk/src/target-sim/table.ts +++ b/libs/wingsdk/src/target-sim/table.ts @@ -51,7 +51,7 @@ export class Table extends ex.Table implements ISimulatorResource { } public onLift(host: IInflightHost, ops: string[]): void { - bindSimulatorResource(__filename, this, host, ops); + bindSimulatorResource(__filename, this, host); super.onLift(host, ops); } diff --git a/libs/wingsdk/src/target-sim/test-runner.inflight.ts b/libs/wingsdk/src/target-sim/test-runner.inflight.ts index 5e4406a2f2f..d04bde496f0 100644 --- a/libs/wingsdk/src/target-sim/test-runner.inflight.ts +++ b/libs/wingsdk/src/target-sim/test-runner.inflight.ts @@ -12,21 +12,14 @@ export class TestRunner { // A map from test paths to their corresponding function handles. private readonly tests: Map; - private _context: ISimulatorContext | undefined; + private readonly context: ISimulatorContext; - constructor(props: TestRunnerSchema["props"]) { + constructor(props: TestRunnerSchema["props"], context: ISimulatorContext) { this.tests = new Map(Object.entries(props.tests)); + this.context = context; } - private get context(): ISimulatorContext { - if (!this._context) { - throw new Error("Cannot access context during class construction"); - } - return this._context; - } - - public async init(context: ISimulatorContext): Promise { - this._context = context; + public async init(): Promise { return {}; } @@ -49,10 +42,7 @@ export class TestRunner if (!functionHandle) { throw new Error(`No test found at path "${path}"`); } - const fnClient = this.context.getClient( - functionHandle, - true - ) as IFunctionClient; + const fnClient = this.context.getClient(functionHandle) as IFunctionClient; let pass = false; let error: string | undefined; const previousTraces = this.context.listTraces().length; diff --git a/libs/wingsdk/src/target-sim/test-runner.ts b/libs/wingsdk/src/target-sim/test-runner.ts index f2ebda594e7..edab23072ea 100644 --- a/libs/wingsdk/src/target-sim/test-runner.ts +++ b/libs/wingsdk/src/target-sim/test-runner.ts @@ -32,7 +32,7 @@ export class TestRunner extends std.TestRunner implements ISimulatorResource { } public onLift(host: IInflightHost, ops: string[]): void { - bindSimulatorResource("test-runner", this, host, ops); + bindSimulatorResource("test-runner", this, host); super.onLift(host, ops); } diff --git a/libs/wingsdk/src/target-sim/topic.inflight.ts b/libs/wingsdk/src/target-sim/topic.inflight.ts index cd532b343ef..4efffd0e1a0 100644 --- a/libs/wingsdk/src/target-sim/topic.inflight.ts +++ b/libs/wingsdk/src/target-sim/topic.inflight.ts @@ -4,7 +4,7 @@ import { TopicSchema, TopicSubscriber, EventSubscription, - ResourceHandle, + FunctionHandle, } from "./schema-resources"; import { IFunctionClient, ITopicClient, TOPIC_FQN } from "../cloud"; import { @@ -18,19 +18,14 @@ export class Topic implements ITopicClient, ISimulatorResourceInstance, IEventPublisher { private readonly subscribers = new Array(); - private _context: ISimulatorContext | undefined; + private readonly context: ISimulatorContext; - constructor(_props: TopicSchema["props"]) {} - - private get context(): ISimulatorContext { - if (!this._context) { - throw new Error("Cannot access context during class construction"); - } - return this._context; + constructor(props: TopicSchema["props"], context: ISimulatorContext) { + this.context = context; + props; } - public async init(context: ISimulatorContext): Promise { - this._context = context; + public async init(): Promise { return {}; } @@ -62,7 +57,7 @@ export class Topic } public async addEventSubscription( - subscriber: ResourceHandle, + subscriber: FunctionHandle, subscriptionProps: EventSubscription ): Promise { let s = { diff --git a/libs/wingsdk/src/target-sim/topic.ts b/libs/wingsdk/src/target-sim/topic.ts index d2d63deb758..39d0ba00ae4 100644 --- a/libs/wingsdk/src/target-sim/topic.ts +++ b/libs/wingsdk/src/target-sim/topic.ts @@ -3,7 +3,6 @@ import { Construct } from "constructs"; import { App } from "./app"; import { EventMapping } from "./event-mapping"; import { Function } from "./function"; -import { Policy } from "./policy"; import { ISimulatorResource } from "./resource"; import { TopicSchema } from "./schema-resources"; import { bindSimulatorResource, makeSimulatorJsClient } from "./util"; @@ -18,10 +17,8 @@ import { IInflightHost, Node, SDK_SOURCE_MODULE } from "../std"; * @inflight `@winglang/sdk.cloud.ITopicClient` */ export class Topic extends cloud.Topic implements ISimulatorResource { - public readonly policy: Policy; constructor(scope: Construct, id: string, props: cloud.TopicProps = {}) { super(scope, id, props); - this.policy = new Policy(this, "Policy", { principal: this }); } public onMessage( @@ -55,13 +52,11 @@ export class Topic extends cloud.Topic implements ISimulatorResource { name: "onMessage()", }); - this.policy.addStatement(fn, cloud.FunctionInflightMethods.INVOKE_ASYNC); - return fn; } public onLift(host: IInflightHost, ops: string[]): void { - bindSimulatorResource(__filename, this, host, ops); + bindSimulatorResource(__filename, this, host); super.onLift(host, ops); } diff --git a/libs/wingsdk/src/target-sim/util.ts b/libs/wingsdk/src/target-sim/util.ts index e31dfce9f47..17074dec81b 100644 --- a/libs/wingsdk/src/target-sim/util.ts +++ b/libs/wingsdk/src/target-sim/util.ts @@ -2,7 +2,6 @@ import { access, constants } from "fs"; import { basename } from "path"; import { promisify } from "util"; import { IConstruct } from "constructs"; -import { isSimulatorInflightHost } from "./resource"; import { simulatorHandleToken } from "./tokens"; import { Duration, IInflightHost, Resource } from "../std"; @@ -32,23 +31,13 @@ function makeEnvVarName(type: string, resource: IConstruct): string { export function bindSimulatorResource( filename: string, resource: Resource, - host: IInflightHost, - ops: string[] + host: IInflightHost ) { - // Check if host implements ISimulatorInflightHost - if (!isSimulatorInflightHost(host)) { - throw new Error( - "Host resource must implement sim.ISimulatorInflightHost to bind simulator resources" - ); - } const type = basename(filename).split(".")[0]; const env = makeEnvVarName(type, resource); const handle = simulatorHandleToken(resource); host.addEnvironment(env, handle); host.node.addDependency(resource); - for (const op of ops) { - host.addPermission(resource, op); - } } export function makeSimulatorJsClient(filename: string, resource: Resource) { @@ -63,11 +52,7 @@ export function makeSimulatorJsClient(filename: string, resource: Resource) { if (!simulatorUrl) { throw new Error("Missing environment variable: WING_SIMULATOR_URL"); } - const caller = process.env.WING_SIMULATOR_CALLER; - if (!caller) { - throw new Error("Missing environment variable: WING_SIMULATOR_CALLER"); - } - return require("@winglang/sdk/lib/simulator/client").makeSimulatorClient(simulatorUrl, handle, caller); + return require("@winglang/sdk/lib/simulator/client").makeSimulatorClient(simulatorUrl, handle); })()`; } diff --git a/libs/wingsdk/src/target-sim/website.inflight.ts b/libs/wingsdk/src/target-sim/website.inflight.ts index f25472134e6..aa11fe4eeff 100644 --- a/libs/wingsdk/src/target-sim/website.inflight.ts +++ b/libs/wingsdk/src/target-sim/website.inflight.ts @@ -14,12 +14,14 @@ import { TraceType } from "../std"; const LOCALHOST_ADDRESS = "127.0.0.1"; export class Website implements IWebsiteClient, ISimulatorResourceInstance { - private _context: ISimulatorContext | undefined; + private readonly context: ISimulatorContext; private readonly app: express.Application; private server?: Server; private url?: string; - constructor(props: WebsiteSchema["props"]) { + constructor(props: WebsiteSchema["props"], context: ISimulatorContext) { + this.context = context; + // Set up an express server that handles the routes. this.app = express(); @@ -46,15 +48,7 @@ export class Website implements IWebsiteClient, ISimulatorResourceInstance { } } - private get context(): ISimulatorContext { - if (!this._context) { - throw new Error("Cannot access context during class construction"); - } - return this._context; - } - - public async init(context: ISimulatorContext): Promise { - this._context = context; + public async init(): Promise { // `server.address()` returns `null` until the server is listening // on a port. We use a promise to wait for the server to start // listening before returning the URL. diff --git a/libs/wingsdk/src/target-sim/website.ts b/libs/wingsdk/src/target-sim/website.ts index 4e4ca6accfb..8e90e25e231 100644 --- a/libs/wingsdk/src/target-sim/website.ts +++ b/libs/wingsdk/src/target-sim/website.ts @@ -63,7 +63,7 @@ export class Website extends cloud.Website implements ISimulatorResource { } public onLift(host: IInflightHost, ops: string[]): void { - bindSimulatorResource(__filename, this, host, ops); + bindSimulatorResource(__filename, this, host); super.onLift(host, ops); } diff --git a/libs/wingsdk/src/util/enhanced-error.ts b/libs/wingsdk/src/util/enhanced-error.ts index ba8a541e4a5..e3dbe7a37ca 100644 --- a/libs/wingsdk/src/util/enhanced-error.ts +++ b/libs/wingsdk/src/util/enhanced-error.ts @@ -79,7 +79,8 @@ export async function prettyPrintError( ) // special: remove the handler wrapper (See `cloud.Function` entrypoint for where this comes from) .filter( - (item) => !normalPath(item.file).match(/\.wing\/\w+(\.sandbox)?\.js$/) + (item) => + !normalPath(item.file).match(/\.wing\/handler_\w+(\.sandbox)?\.js$/) ) .withSourcesAsync(); diff --git a/libs/wingsdk/test/core/__snapshots__/connections.test.ts.snap b/libs/wingsdk/test/core/__snapshots__/connections.test.ts.snap index df0506ae6ec..94c737a6e30 100644 --- a/libs/wingsdk/test/core/__snapshots__/connections.test.ts.snap +++ b/libs/wingsdk/test/core/__snapshots__/connections.test.ts.snap @@ -42,16 +42,6 @@ return class Handler { }, "type": "@winglang/sdk.cloud.Bucket", }, - { - "addr": "c8b5ba55132964ee19331fb9f46241560e67fed76b", - "attrs": {}, - "path": "root/my_bucket/Policy", - "props": { - "principal": "\${wsim#root/my_bucket#attrs.handle}", - "statements": [], - }, - "type": "@winglang/sdk.sim.Policy", - }, { "addr": "c85c4e0e66bf385ab6b159bab34fb32dd81aad0a1d", "attrs": {}, @@ -65,16 +55,6 @@ return class Handler { }, "type": "@winglang/sdk.cloud.Function", }, - { - "addr": "c8d421ed6ca2ddf857d835791bcde9240c8682a8d9", - "attrs": {}, - "path": "root/my_function/Policy", - "props": { - "principal": "\${wsim#root/my_function#attrs.handle}", - "statements": [], - }, - "type": "@winglang/sdk.sim.Policy", - }, ], "sdkVersion": "0.0.0", "types": { @@ -150,14 +130,6 @@ return class Handler { "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", @@ -172,21 +144,6 @@ return class Handler { "tree": { "children": { "my_bucket": { - "children": { - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/my_bucket/Policy", - }, - }, "constructInfo": { "fqn": "constructs.Construct", "version": "10.3.0", @@ -199,21 +156,6 @@ return class Handler { "path": "root/my_bucket", }, "my_function": { - "children": { - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/my_function/Policy", - }, - }, "constructInfo": { "fqn": "constructs.Construct", "version": "10.3.0", diff --git a/libs/wingsdk/test/simulator/cleanup.test.ts b/libs/wingsdk/test/simulator/cleanup.test.ts index 2304889be27..770d27715f6 100644 --- a/libs/wingsdk/test/simulator/cleanup.test.ts +++ b/libs/wingsdk/test/simulator/cleanup.test.ts @@ -19,7 +19,7 @@ async function main() { console.log("Simulator started"); process.on("SIGTERM", async () => { - console.log("SIGTERM received, stopping simulator.."); + console.log("SIGTERM received, stopping simulator..."); await sim.stop(); process.exit(1); }); @@ -43,9 +43,7 @@ async handle() { // and that process has code set up for gracefully shutting down the simulator, // then the simulator will be stopped correctly (including child processes // like services). -// -// TODO: failing in CI... :-( -test.skip("simulator cleanup", async () => { +test("simulator cleanup", async () => { // Synthesize configuration for the simulator to use in the test const app = new SimApp({ isTestEnvironment: true }); const handler = Testing.makeHandler(code); diff --git a/libs/wingsdk/test/simulator/on-trace.test.ts b/libs/wingsdk/test/simulator/on-trace.test.ts index cee2e130f88..ffab782d4ef 100644 --- a/libs/wingsdk/test/simulator/on-trace.test.ts +++ b/libs/wingsdk/test/simulator/on-trace.test.ts @@ -27,5 +27,5 @@ test("onTrace", async () => { await s.stop(); // THEN - expect(numTraces).toBeGreaterThanOrEqual(3); // create resources, put operation, delete resources + expect(numTraces).toEqual(3); // create resources, put operation, delete resources }); diff --git a/libs/wingsdk/test/simulator/simulator.test.ts b/libs/wingsdk/test/simulator/simulator.test.ts index 422bd103ae3..7d8fb866fd6 100644 --- a/libs/wingsdk/test/simulator/simulator.test.ts +++ b/libs/wingsdk/test/simulator/simulator.test.ts @@ -214,15 +214,9 @@ describe("in-place updates", () => { new Bucket(app, "Bucket1"); const sim = await app.startSimulator(stateDir); - expect(sim.listResources()).toEqual([ - "root/Bucket1", - "root/Bucket1/Policy", - ]); + expect(sim.listResources()).toEqual(["root/Bucket1"]); - expect(simTraces(sim)).toStrictEqual([ - "root/Bucket1 started", - "root/Bucket1/Policy started", - ]); + expect(simTraces(sim)).toStrictEqual(["root/Bucket1 started"]); const app2 = new SimApp(); new Bucket(app2, "Bucket1"); @@ -238,14 +232,10 @@ describe("in-place updates", () => { expect(simTraces(sim)).toStrictEqual([ "root/Bucket1 started", - "root/Bucket1/Policy started", "Update: 0 added, 0 updated, 0 deleted", ]); - expect(sim.listResources()).toEqual([ - "root/Bucket1", - "root/Bucket1/Policy", - ]); + expect(sim.listResources()).toEqual(["root/Bucket1"]); await sim.stop(); }); @@ -256,14 +246,8 @@ describe("in-place updates", () => { new Bucket(app, "Bucket1"); const sim = await app.startSimulator(stateDir); - expect(sim.listResources()).toEqual([ - "root/Bucket1", - "root/Bucket1/Policy", - ]); - expect(simTraces(sim)).toStrictEqual([ - "root/Bucket1 started", - "root/Bucket1/Policy started", - ]); + expect(sim.listResources()).toEqual(["root/Bucket1"]); + expect(simTraces(sim)).toStrictEqual(["root/Bucket1 started"]); const app2 = new SimApp(); new Bucket(app2, "Bucket1"); @@ -272,23 +256,16 @@ describe("in-place updates", () => { const app2Dir = app2.synth(); await sim.update(app2Dir); expect(updateTrace(sim)).toStrictEqual({ - added: ["root/Bucket2", "root/Bucket2/Policy"], + added: ["root/Bucket2"], deleted: [], updated: [], }); - expect(sim.listResources()).toEqual([ - "root/Bucket1", - "root/Bucket1/Policy", - "root/Bucket2", - "root/Bucket2/Policy", - ]); + expect(sim.listResources()).toEqual(["root/Bucket1", "root/Bucket2"]); expect(simTraces(sim)).toStrictEqual([ "root/Bucket1 started", - "root/Bucket1/Policy started", - "Update: 2 added, 0 updated, 0 deleted", + "Update: 1 added, 0 updated, 0 deleted", "root/Bucket2 started", - "root/Bucket2/Policy started", ]); await sim.stop(); @@ -301,17 +278,10 @@ describe("in-place updates", () => { new Bucket(app, "Bucket1"); new Bucket(app, "Bucket2"); const sim = await app.startSimulator(stateDir); - expect(sim.listResources()).toEqual([ - "root/Bucket1", - "root/Bucket1/Policy", - "root/Bucket2", - "root/Bucket2/Policy", - ]); + expect(sim.listResources()).toEqual(["root/Bucket1", "root/Bucket2"]); expect(simTraces(sim)).toStrictEqual([ "root/Bucket1 started", - "root/Bucket1/Policy started", "root/Bucket2 started", - "root/Bucket2/Policy started", ]); const app2 = new SimApp(); @@ -321,22 +291,16 @@ describe("in-place updates", () => { await sim.update(app2Dir); expect(updateTrace(sim)).toStrictEqual({ added: [], - deleted: ["root/Bucket2", "root/Bucket2/Policy"], + deleted: ["root/Bucket2"], updated: [], }); - expect(sim.listResources()).toEqual([ - "root/Bucket1", - "root/Bucket1/Policy", - ]); + expect(sim.listResources()).toEqual(["root/Bucket1"]); expect(simTraces(sim)).toStrictEqual([ "root/Bucket1 started", - "root/Bucket1/Policy started", "root/Bucket2 started", - "root/Bucket2/Policy started", - "Update: 0 added, 0 updated, 2 deleted", - "root/Bucket2/Policy stopped", + "Update: 0 added, 0 updated, 1 deleted", "root/Bucket2 stopped", ]); @@ -349,15 +313,9 @@ describe("in-place updates", () => { const app = new SimApp(); new Bucket(app, "Bucket1"); const sim = await app.startSimulator(stateDir); - expect(sim.listResources()).toEqual([ - "root/Bucket1", - "root/Bucket1/Policy", - ]); + expect(sim.listResources()).toEqual(["root/Bucket1"]); expect(sim.getResourceConfig("root/Bucket1").props.public).toBeFalsy(); - expect(simTraces(sim)).toStrictEqual([ - "root/Bucket1 started", - "root/Bucket1/Policy started", - ]); + expect(simTraces(sim)).toStrictEqual(["root/Bucket1 started"]); const app2 = new SimApp(); new Bucket(app2, "Bucket1", { public: true }); @@ -370,19 +328,13 @@ describe("in-place updates", () => { updated: ["root/Bucket1"], }); - expect(sim.listResources()).toEqual([ - "root/Bucket1", - "root/Bucket1/Policy", - ]); + expect(sim.listResources()).toEqual(["root/Bucket1"]); expect(simTraces(sim)).toStrictEqual([ "root/Bucket1 started", - "root/Bucket1/Policy started", "Update: 0 added, 1 updated, 0 deleted", - "root/Bucket1/Policy stopped", "root/Bucket1 stopped", "root/Bucket1 started", - "root/Bucket1/Policy started", ]); expect(sim.getResourceConfig("root/Bucket1").props.public).toBeTruthy(); @@ -398,15 +350,9 @@ describe("in-place updates", () => { const sim = await app.startSimulator(stateDir); - expect(simTraces(sim)).toStrictEqual([ - "root/Bucket1 started", - "root/Bucket1/Policy started", - ]); + expect(simTraces(sim)).toStrictEqual(["root/Bucket1 started"]); - expect(sim.listResources()).toEqual([ - "root/Bucket1", - "root/Bucket1/Policy", - ]); + expect(sim.listResources()).toEqual(["root/Bucket1"]); expect(sim.getResourceConfig("root/Bucket1").props.public).toBeFalsy(); const app2 = new SimApp(); @@ -423,40 +369,26 @@ describe("in-place updates", () => { await sim.update(app2Dir); expect(updateTrace(sim)).toStrictEqual({ - added: [ - "root/Api", - "root/Api/Endpoint", - "root/Api/Policy", - "root/Function", - "root/Function/Policy", - ], + added: ["root/Api", "root/Api/Endpoint", "root/Function"], deleted: [], updated: ["root/Bucket1"], }); expect(simTraces(sim)).toStrictEqual([ "root/Bucket1 started", - "root/Bucket1/Policy started", - "Update: 5 added, 1 updated, 0 deleted", - "root/Bucket1/Policy stopped", + "Update: 3 added, 1 updated, 0 deleted", "root/Bucket1 stopped", "root/Api started", "root/Bucket1 started", - "root/Bucket1/Policy started", "root/Api/Endpoint started", - "root/Api/Policy started", "root/Function started", - "root/Function/Policy started", ]); expect(sim.listResources()).toEqual([ "root/Api", "root/Api/Endpoint", - "root/Api/Policy", "root/Bucket1", - "root/Bucket1/Policy", "root/Function", - "root/Function/Policy", ]); const bucketClient = sim.getResource("root/Bucket1") as IBucketClient; @@ -511,12 +443,15 @@ describe("in-place updates", () => { const stateDir = mkdtemp(); const sim = await app.startSimulator(stateDir); + const urlBeforeUpdate = await sim + .getResource("root/Bucket1") + .get("url.txt"); + expect(urlBeforeUpdate.startsWith("http://127.0.0")).toBeTruthy(); + expect(simTraces(sim)).toEqual([ "root/Api1 started", "root/Api1/Endpoint started", - "root/Api1/Policy started", "root/Bucket1 started", - "root/Bucket1/Policy started", ]); // now lets change some configuration of Api1. we expect the bucket to be replaced as well @@ -526,35 +461,35 @@ describe("in-place updates", () => { const myBucket2 = new Bucket(app2, "Bucket1"); myBucket2.addObject("url.txt", myApi2.url); + // clear the state directory + fs.rmdirSync(stateDir, { recursive: true }); + const app2Dir = app2.synth(); await sim.update(app2Dir); expect(updateTrace(sim)).toStrictEqual({ added: [], deleted: [], - updated: ["root/Api1"], // TODO: shouldn't Bucket also be listed here? + updated: ["root/Api1"], }); expect(simTraces(sim)).toEqual([ "root/Api1 started", "root/Api1/Endpoint started", - "root/Api1/Policy started", "root/Bucket1 started", - "root/Bucket1/Policy started", "Update: 0 added, 1 updated, 0 deleted", "root/Api1/Endpoint stopped", - "root/Api1/Policy stopped", - "root/Bucket1/Policy stopped", "root/Bucket1 stopped", "root/Api1 stopped", "root/Api1 started", "root/Api1/Endpoint started", - "root/Api1/Policy started", "root/Bucket1 started", - "root/Bucket1/Policy started", ]); - await sim.stop(); + const urlAfterUpdate = await ( + sim.getResource("root/Bucket1") as IBucketClient + ).get("url.txt"); + expect(urlAfterUpdate).not.toEqual(urlBeforeUpdate); }); test("token value is changed across an update", async () => { @@ -616,24 +551,15 @@ describe("in-place updates", () => { expect(simTraces(sim)).toEqual([ "root/State started", - "root/Service started", - "root/Service/Policy started", "root/State.my_value = bang", - "root/Service/Helper started", + "root/Service started", "root/Function started", - "root/Function/Policy started", "Update: 0 added, 2 updated, 0 deleted", - "root/Service/Helper stopped", - "root/Service/Policy stopped", "root/Service stopped", - "root/Function/Policy stopped", "root/Function stopped", - "root/Service started", - "root/Service/Policy started", "root/State.my_value = bing", - "root/Service/Helper started", + "root/Service started", "root/Function started", - "root/Function/Policy started", ]); }); @@ -658,21 +584,15 @@ describe("in-place updates", () => { await sim.update(app2Dir); expect(simTraces(sim)).toEqual([ - "root/Bucket1 started", - "root/Bucket1/Policy started", "root/OnDeploy/Function started", - "root/OnDeploy/Function/Policy started", + "root/Bucket1 started", "root/OnDeploy started", - "Update: 0 added, 3 updated, 0 deleted", + "Update: 0 added, 2 updated, 0 deleted", "root/OnDeploy stopped", - "root/OnDeploy/Function/Policy stopped", "root/OnDeploy/Function stopped", - "root/Bucket1/Policy stopped", "root/Bucket1 stopped", - "root/Bucket1 started", - "root/Bucket1/Policy started", "root/OnDeploy/Function started", - "root/OnDeploy/Function/Policy started", + "root/Bucket1 started", "root/OnDeploy started", ]); }); @@ -692,12 +612,9 @@ describe("in-place updates", () => { expect(simTraces(sim)).toEqual([ "root/Function started", - "root/Function/Policy started", "Update: 0 added, 1 updated, 0 deleted", - "root/Function/Policy stopped", "root/Function stopped", "root/Function started", - "root/Function/Policy started", ]); }); @@ -716,42 +633,9 @@ describe("in-place updates", () => { expect(simTraces(sim)).toEqual([ "root/Service started", - "root/Service/Policy started", - "root/Service/Helper started", "Update: 0 added, 1 updated, 0 deleted", - "root/Service/Helper stopped", - "root/Service/Policy stopped", "root/Service stopped", "root/Service started", - "root/Service/Policy started", - "root/Service/Helper started", - ]); - }); - - test("cloud.OnDeploy is always replaced", async () => { - const app = new SimApp(); - const handler = Testing.makeHandler(`async handle() {}`); - new OnDeploy(app, "OnDeploy", handler); - - const sim = await app.startSimulator(); - - const app2 = new SimApp(); - new OnDeploy(app2, "OnDeploy", handler); - - const app2Dir = app2.synth(); - await sim.update(app2Dir); - - expect(simTraces(sim)).toEqual([ - "root/OnDeploy/Function started", - "root/OnDeploy/Function/Policy started", - "root/OnDeploy started", - "Update: 0 added, 2 updated, 0 deleted", - "root/OnDeploy stopped", - "root/OnDeploy/Function/Policy stopped", - "root/OnDeploy/Function stopped", - "root/OnDeploy/Function started", - "root/OnDeploy/Function/Policy started", - "root/OnDeploy started", ]); }); }); diff --git a/libs/wingsdk/test/target-sim/__snapshots__/api.test.ts.snap b/libs/wingsdk/test/target-sim/__snapshots__/api.test.ts.snap index d0341d9c345..ba00408b0af 100644 --- a/libs/wingsdk/test/target-sim/__snapshots__/api.test.ts.snap +++ b/libs/wingsdk/test/target-sim/__snapshots__/api.test.ts.snap @@ -47,31 +47,6 @@ return class Handler { }, "type": "@winglang/sdk.cloud.Endpoint", }, - { - "addr": "c8d2997625976ba9bc7be90fefe7930aebab104a2a", - "attrs": {}, - "path": "root/my_api/Policy", - "props": { - "principal": "\${wsim#root/my_api#attrs.handle}", - "statements": [ - { - "operation": "invoke", - "resourceHandle": "\${wsim#root/my_api/OnRequestHandler0#attrs.handle}", - }, - ], - }, - "type": "@winglang/sdk.sim.Policy", - }, - { - "addr": "c8b0396e20397567e34feafb703cea1bc0b968dc05", - "attrs": {}, - "path": "root/my_api/OnRequestHandler0/Policy", - "props": { - "principal": "\${wsim#root/my_api/OnRequestHandler0#attrs.handle}", - "statements": [], - }, - "type": "@winglang/sdk.sim.Policy", - }, { "addr": "c82d41b2501ac42e07e4565202a5b87a180a01c6a2", "attrs": {}, @@ -221,14 +196,6 @@ return class Handler { "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", @@ -268,21 +235,6 @@ return class Handler { "path": "root/my_api/Endpoint", }, "OnRequestHandler0": { - "children": { - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/my_api/OnRequestHandler0/Policy", - }, - }, "constructInfo": { "fqn": "constructs.Construct", "version": "10.3.0", @@ -296,19 +248,6 @@ return class Handler { "id": "OnRequestHandler0", "path": "root/my_api/OnRequestHandler0", }, - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/my_api/Policy", - }, }, "constructInfo": { "fqn": "constructs.Construct", @@ -340,15 +279,11 @@ exports[`api handler can read the request params 1`] = ` "root/my_api started", "root/my_api/Endpoint started", "root/my_api/OnRequestHandler0 started", - "root/my_api/Policy started", - "root/my_api/OnRequestHandler0/Policy started", "root/my_api/ApiEventMapping0 started", "Processing "GET /hello" params={}).", "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{\\"foo\\":\\"bar\\",\\"bar\\":\\"baz\\"},\\"vars\\":{}}").", "GET /hello - 200.", "root/my_api/Endpoint stopped", - "root/my_api/Policy stopped", - "root/my_api/OnRequestHandler0/Policy stopped", "root/my_api/ApiEventMapping0 stopped", "root/my_api/OnRequestHandler0 stopped", "Closing server on http://127.0.0.1:", @@ -398,31 +333,6 @@ return class Handler { }, "type": "@winglang/sdk.cloud.Endpoint", }, - { - "addr": "c8d2997625976ba9bc7be90fefe7930aebab104a2a", - "attrs": {}, - "path": "root/my_api/Policy", - "props": { - "principal": "\${wsim#root/my_api#attrs.handle}", - "statements": [ - { - "operation": "invoke", - "resourceHandle": "\${wsim#root/my_api/OnRequestHandler0#attrs.handle}", - }, - ], - }, - "type": "@winglang/sdk.sim.Policy", - }, - { - "addr": "c8b0396e20397567e34feafb703cea1bc0b968dc05", - "attrs": {}, - "path": "root/my_api/OnRequestHandler0/Policy", - "props": { - "principal": "\${wsim#root/my_api/OnRequestHandler0#attrs.handle}", - "statements": [], - }, - "type": "@winglang/sdk.sim.Policy", - }, { "addr": "c82d41b2501ac42e07e4565202a5b87a180a01c6a2", "attrs": {}, @@ -558,14 +468,6 @@ return class Handler { "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", @@ -605,21 +507,6 @@ return class Handler { "path": "root/my_api/Endpoint", }, "OnRequestHandler0": { - "children": { - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/my_api/OnRequestHandler0/Policy", - }, - }, "constructInfo": { "fqn": "constructs.Construct", "version": "10.3.0", @@ -633,19 +520,6 @@ return class Handler { "id": "OnRequestHandler0", "path": "root/my_api/OnRequestHandler0", }, - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/my_api/Policy", - }, }, "constructInfo": { "fqn": "constructs.Construct", @@ -677,15 +551,11 @@ exports[`api handler can read the request path 1`] = ` "root/my_api started", "root/my_api/Endpoint started", "root/my_api/OnRequestHandler0 started", - "root/my_api/Policy started", - "root/my_api/OnRequestHandler0/Policy started", "root/my_api/ApiEventMapping0 started", "Processing "GET /hello" params={}).", "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", "GET /hello - 200.", "root/my_api/Endpoint stopped", - "root/my_api/Policy stopped", - "root/my_api/OnRequestHandler0/Policy stopped", "root/my_api/ApiEventMapping0 stopped", "root/my_api/OnRequestHandler0 stopped", "Closing server on http://127.0.0.1:", @@ -735,31 +605,6 @@ return class Handler { }, "type": "@winglang/sdk.cloud.Endpoint", }, - { - "addr": "c8d2997625976ba9bc7be90fefe7930aebab104a2a", - "attrs": {}, - "path": "root/my_api/Policy", - "props": { - "principal": "\${wsim#root/my_api#attrs.handle}", - "statements": [ - { - "operation": "invoke", - "resourceHandle": "\${wsim#root/my_api/OnRequestHandler0#attrs.handle}", - }, - ], - }, - "type": "@winglang/sdk.sim.Policy", - }, - { - "addr": "c8b0396e20397567e34feafb703cea1bc0b968dc05", - "attrs": {}, - "path": "root/my_api/OnRequestHandler0/Policy", - "props": { - "principal": "\${wsim#root/my_api/OnRequestHandler0#attrs.handle}", - "statements": [], - }, - "type": "@winglang/sdk.sim.Policy", - }, { "addr": "c82d41b2501ac42e07e4565202a5b87a180a01c6a2", "attrs": {}, @@ -895,14 +740,6 @@ return class Handler { "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", @@ -942,21 +779,6 @@ return class Handler { "path": "root/my_api/Endpoint", }, "OnRequestHandler0": { - "children": { - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/my_api/OnRequestHandler0/Policy", - }, - }, "constructInfo": { "fqn": "constructs.Construct", "version": "10.3.0", @@ -970,19 +792,6 @@ return class Handler { "id": "OnRequestHandler0", "path": "root/my_api/OnRequestHandler0", }, - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/my_api/Policy", - }, }, "constructInfo": { "fqn": "constructs.Construct", @@ -1014,15 +823,11 @@ exports[`api handler can set response headers 1`] = ` "root/my_api started", "root/my_api/Endpoint started", "root/my_api/OnRequestHandler0 started", - "root/my_api/Policy started", - "root/my_api/OnRequestHandler0/Policy started", "root/my_api/ApiEventMapping0 started", "Processing "GET /hello" params={}).", "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"foo\\":\\"bar\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", "GET /hello - 200.", "root/my_api/Endpoint stopped", - "root/my_api/Policy stopped", - "root/my_api/OnRequestHandler0/Policy stopped", "root/my_api/ApiEventMapping0 stopped", "root/my_api/OnRequestHandler0 stopped", "Closing server on http://127.0.0.1:", @@ -1072,31 +877,6 @@ return class Handler { }, "type": "@winglang/sdk.cloud.Endpoint", }, - { - "addr": "c8d2997625976ba9bc7be90fefe7930aebab104a2a", - "attrs": {}, - "path": "root/my_api/Policy", - "props": { - "principal": "\${wsim#root/my_api#attrs.handle}", - "statements": [ - { - "operation": "invoke", - "resourceHandle": "\${wsim#root/my_api/OnRequestHandler0#attrs.handle}", - }, - ], - }, - "type": "@winglang/sdk.sim.Policy", - }, - { - "addr": "c8b0396e20397567e34feafb703cea1bc0b968dc05", - "attrs": {}, - "path": "root/my_api/OnRequestHandler0/Policy", - "props": { - "principal": "\${wsim#root/my_api/OnRequestHandler0#attrs.handle}", - "statements": [], - }, - "type": "@winglang/sdk.sim.Policy", - }, { "addr": "c82d41b2501ac42e07e4565202a5b87a180a01c6a2", "attrs": {}, @@ -1232,14 +1012,6 @@ return class Handler { "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", @@ -1279,21 +1051,6 @@ return class Handler { "path": "root/my_api/Endpoint", }, "OnRequestHandler0": { - "children": { - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/my_api/OnRequestHandler0/Policy", - }, - }, "constructInfo": { "fqn": "constructs.Construct", "version": "10.3.0", @@ -1307,19 +1064,6 @@ return class Handler { "id": "OnRequestHandler0", "path": "root/my_api/OnRequestHandler0", }, - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/my_api/Policy", - }, }, "constructInfo": { "fqn": "constructs.Construct", @@ -1351,15 +1095,11 @@ exports[`api response returns Content-Type header from inflight 1`] = ` "root/my_api started", "root/my_api/Endpoint started", "root/my_api/OnRequestHandler0 started", - "root/my_api/Policy started", - "root/my_api/OnRequestHandler0/Policy started", "root/my_api/ApiEventMapping0 started", "Processing "GET /hello" params={}).", "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", "GET /hello - 200.", "root/my_api/Endpoint stopped", - "root/my_api/Policy stopped", - "root/my_api/OnRequestHandler0/Policy stopped", "root/my_api/ApiEventMapping0 stopped", "root/my_api/OnRequestHandler0 stopped", "Closing server on http://127.0.0.1:", @@ -1409,31 +1149,6 @@ return class Handler { }, "type": "@winglang/sdk.cloud.Endpoint", }, - { - "addr": "c8d2997625976ba9bc7be90fefe7930aebab104a2a", - "attrs": {}, - "path": "root/my_api/Policy", - "props": { - "principal": "\${wsim#root/my_api#attrs.handle}", - "statements": [ - { - "operation": "invoke", - "resourceHandle": "\${wsim#root/my_api/OnRequestHandler0#attrs.handle}", - }, - ], - }, - "type": "@winglang/sdk.sim.Policy", - }, - { - "addr": "c8b0396e20397567e34feafb703cea1bc0b968dc05", - "attrs": {}, - "path": "root/my_api/OnRequestHandler0/Policy", - "props": { - "principal": "\${wsim#root/my_api/OnRequestHandler0#attrs.handle}", - "statements": [], - }, - "type": "@winglang/sdk.sim.Policy", - }, { "addr": "c82d41b2501ac42e07e4565202a5b87a180a01c6a2", "attrs": {}, @@ -1569,14 +1284,6 @@ return class Handler { "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", @@ -1616,21 +1323,6 @@ return class Handler { "path": "root/my_api/Endpoint", }, "OnRequestHandler0": { - "children": { - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/my_api/OnRequestHandler0/Policy", - }, - }, "constructInfo": { "fqn": "constructs.Construct", "version": "10.3.0", @@ -1644,19 +1336,6 @@ return class Handler { "id": "OnRequestHandler0", "path": "root/my_api/OnRequestHandler0", }, - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/my_api/Policy", - }, }, "constructInfo": { "fqn": "constructs.Construct", @@ -1688,15 +1367,11 @@ exports[`api response returns default Content-Type header 1`] = ` "root/my_api started", "root/my_api/Endpoint started", "root/my_api/OnRequestHandler0 started", - "root/my_api/Policy started", - "root/my_api/OnRequestHandler0/Policy started", "root/my_api/ApiEventMapping0 started", "Processing "GET /hello" params={}).", "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", "GET /hello - 200.", "root/my_api/Endpoint stopped", - "root/my_api/Policy stopped", - "root/my_api/OnRequestHandler0/Policy stopped", "root/my_api/ApiEventMapping0 stopped", "root/my_api/OnRequestHandler0 stopped", "Closing server on http://127.0.0.1:", @@ -1746,31 +1421,6 @@ return class Handler { }, "type": "@winglang/sdk.cloud.Endpoint", }, - { - "addr": "c8d2997625976ba9bc7be90fefe7930aebab104a2a", - "attrs": {}, - "path": "root/my_api/Policy", - "props": { - "principal": "\${wsim#root/my_api#attrs.handle}", - "statements": [ - { - "operation": "invoke", - "resourceHandle": "\${wsim#root/my_api/OnRequestHandler0#attrs.handle}", - }, - ], - }, - "type": "@winglang/sdk.sim.Policy", - }, - { - "addr": "c8b0396e20397567e34feafb703cea1bc0b968dc05", - "attrs": {}, - "path": "root/my_api/OnRequestHandler0/Policy", - "props": { - "principal": "\${wsim#root/my_api/OnRequestHandler0#attrs.handle}", - "statements": [], - }, - "type": "@winglang/sdk.sim.Policy", - }, { "addr": "c82d41b2501ac42e07e4565202a5b87a180a01c6a2", "attrs": {}, @@ -1906,14 +1556,6 @@ return class Handler { "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", @@ -1953,21 +1595,6 @@ return class Handler { "path": "root/my_api/Endpoint", }, "OnRequestHandler0": { - "children": { - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/my_api/OnRequestHandler0/Policy", - }, - }, "constructInfo": { "fqn": "constructs.Construct", "version": "10.3.0", @@ -1981,19 +1608,6 @@ return class Handler { "id": "OnRequestHandler0", "path": "root/my_api/OnRequestHandler0", }, - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/my_api/Policy", - }, }, "constructInfo": { "fqn": "constructs.Construct", @@ -2025,8 +1639,6 @@ exports[`api supports every method type 1`] = ` "root/my_api started", "root/my_api/Endpoint started", "root/my_api/OnRequestHandler0 started", - "root/my_api/Policy started", - "root/my_api/OnRequestHandler0/Policy started", "root/my_api/ApiEventMapping0 started", "Processing "GET /hello" params={}).", "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", @@ -2050,8 +1662,6 @@ exports[`api supports every method type 1`] = ` "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\",\\"content-length\\":\\"0\\"},\\"body\\":\\"\\",\\"method\\":\\"PATCH\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", "PATCH /hello - 200.", "root/my_api/Endpoint stopped", - "root/my_api/Policy stopped", - "root/my_api/OnRequestHandler0/Policy stopped", "root/my_api/ApiEventMapping0 stopped", "root/my_api/OnRequestHandler0 stopped", "Closing server on http://127.0.0.1:", @@ -2131,31 +1741,6 @@ return class Handler { }, "type": "@winglang/sdk.cloud.Endpoint", }, - { - "addr": "c8d2997625976ba9bc7be90fefe7930aebab104a2a", - "attrs": {}, - "path": "root/my_api/Policy", - "props": { - "principal": "\${wsim#root/my_api#attrs.handle}", - "statements": [ - { - "operation": "invoke", - "resourceHandle": "\${wsim#root/my_api/OnRequestHandler0#attrs.handle}", - }, - ], - }, - "type": "@winglang/sdk.sim.Policy", - }, - { - "addr": "c8b0396e20397567e34feafb703cea1bc0b968dc05", - "attrs": {}, - "path": "root/my_api/OnRequestHandler0/Policy", - "props": { - "principal": "\${wsim#root/my_api/OnRequestHandler0#attrs.handle}", - "statements": [], - }, - "type": "@winglang/sdk.sim.Policy", - }, { "addr": "c82d41b2501ac42e07e4565202a5b87a180a01c6a2", "attrs": {}, @@ -2375,14 +1960,6 @@ return class Handler { "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", @@ -2422,21 +1999,6 @@ return class Handler { "path": "root/my_api/Endpoint", }, "OnRequestHandler0": { - "children": { - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/my_api/OnRequestHandler0/Policy", - }, - }, "constructInfo": { "fqn": "constructs.Construct", "version": "10.3.0", @@ -2450,19 +2012,6 @@ return class Handler { "id": "OnRequestHandler0", "path": "root/my_api/OnRequestHandler0", }, - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/my_api/Policy", - }, }, "constructInfo": { "fqn": "constructs.Construct", @@ -2494,15 +2043,11 @@ exports[`api with 'name' & 'age' parameter 1`] = ` "root/my_api started", "root/my_api/Endpoint started", "root/my_api/OnRequestHandler0 started", - "root/my_api/Policy started", - "root/my_api/OnRequestHandler0/Policy started", "root/my_api/ApiEventMapping0 started", "Processing "GET /:name/:age" params={"name":"akhil","age":"23"}).", "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/akhil/23\\",\\"query\\":{},\\"vars\\":{\\"name\\":\\"akhil\\",\\"age\\":\\"23\\"}}").", "GET /:name/:age - 200.", "root/my_api/Endpoint stopped", - "root/my_api/Policy stopped", - "root/my_api/OnRequestHandler0/Policy stopped", "root/my_api/ApiEventMapping0 stopped", "root/my_api/OnRequestHandler0 stopped", "Closing server on http://127.0.0.1:", @@ -2552,31 +2097,6 @@ return class Handler { }, "type": "@winglang/sdk.cloud.Endpoint", }, - { - "addr": "c8d2997625976ba9bc7be90fefe7930aebab104a2a", - "attrs": {}, - "path": "root/my_api/Policy", - "props": { - "principal": "\${wsim#root/my_api#attrs.handle}", - "statements": [ - { - "operation": "invoke", - "resourceHandle": "\${wsim#root/my_api/OnRequestHandler0#attrs.handle}", - }, - ], - }, - "type": "@winglang/sdk.sim.Policy", - }, - { - "addr": "c8b0396e20397567e34feafb703cea1bc0b968dc05", - "attrs": {}, - "path": "root/my_api/OnRequestHandler0/Policy", - "props": { - "principal": "\${wsim#root/my_api/OnRequestHandler0#attrs.handle}", - "statements": [], - }, - "type": "@winglang/sdk.sim.Policy", - }, { "addr": "c82d41b2501ac42e07e4565202a5b87a180a01c6a2", "attrs": {}, @@ -2729,14 +2249,6 @@ return class Handler { "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", @@ -2776,21 +2288,6 @@ return class Handler { "path": "root/my_api/Endpoint", }, "OnRequestHandler0": { - "children": { - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/my_api/OnRequestHandler0/Policy", - }, - }, "constructInfo": { "fqn": "constructs.Construct", "version": "10.3.0", @@ -2804,19 +2301,6 @@ return class Handler { "id": "OnRequestHandler0", "path": "root/my_api/OnRequestHandler0", }, - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/my_api/Policy", - }, }, "constructInfo": { "fqn": "constructs.Construct", @@ -2848,15 +2332,11 @@ exports[`api with 'name' parameter 1`] = ` "root/my_api started", "root/my_api/Endpoint started", "root/my_api/OnRequestHandler0 started", - "root/my_api/Policy started", - "root/my_api/OnRequestHandler0/Policy started", "root/my_api/ApiEventMapping0 started", "Processing "GET /:name" params={"name":"akhil"}).", "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/akhil\\",\\"query\\":{},\\"vars\\":{\\"name\\":\\"akhil\\"}}").", "GET /:name - 200.", "root/my_api/Endpoint stopped", - "root/my_api/Policy stopped", - "root/my_api/OnRequestHandler0/Policy stopped", "root/my_api/ApiEventMapping0 stopped", "root/my_api/OnRequestHandler0 stopped", "Closing server on http://127.0.0.1:", @@ -2906,31 +2386,6 @@ return class Handler { }, "type": "@winglang/sdk.cloud.Endpoint", }, - { - "addr": "c8d2997625976ba9bc7be90fefe7930aebab104a2a", - "attrs": {}, - "path": "root/my_api/Policy", - "props": { - "principal": "\${wsim#root/my_api#attrs.handle}", - "statements": [ - { - "operation": "invoke", - "resourceHandle": "\${wsim#root/my_api/OnRequestHandler0#attrs.handle}", - }, - ], - }, - "type": "@winglang/sdk.sim.Policy", - }, - { - "addr": "c8b0396e20397567e34feafb703cea1bc0b968dc05", - "attrs": {}, - "path": "root/my_api/OnRequestHandler0/Policy", - "props": { - "principal": "\${wsim#root/my_api/OnRequestHandler0#attrs.handle}", - "statements": [], - }, - "type": "@winglang/sdk.sim.Policy", - }, { "addr": "c82d41b2501ac42e07e4565202a5b87a180a01c6a2", "attrs": {}, @@ -3075,14 +2530,6 @@ return class Handler { "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", @@ -3122,21 +2569,6 @@ return class Handler { "path": "root/my_api/Endpoint", }, "OnRequestHandler0": { - "children": { - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/my_api/OnRequestHandler0/Policy", - }, - }, "constructInfo": { "fqn": "constructs.Construct", "version": "10.3.0", @@ -3150,19 +2582,6 @@ return class Handler { "id": "OnRequestHandler0", "path": "root/my_api/OnRequestHandler0", }, - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/my_api/Policy", - }, }, "constructInfo": { "fqn": "constructs.Construct", @@ -3230,31 +2649,6 @@ return class Handler { }, "type": "@winglang/sdk.cloud.Endpoint", }, - { - "addr": "c8d2997625976ba9bc7be90fefe7930aebab104a2a", - "attrs": {}, - "path": "root/my_api/Policy", - "props": { - "principal": "\${wsim#root/my_api#attrs.handle}", - "statements": [ - { - "operation": "invoke", - "resourceHandle": "\${wsim#root/my_api/OnRequestHandler0#attrs.handle}", - }, - ], - }, - "type": "@winglang/sdk.sim.Policy", - }, - { - "addr": "c8b0396e20397567e34feafb703cea1bc0b968dc05", - "attrs": {}, - "path": "root/my_api/OnRequestHandler0/Policy", - "props": { - "principal": "\${wsim#root/my_api/OnRequestHandler0#attrs.handle}", - "statements": [], - }, - "type": "@winglang/sdk.sim.Policy", - }, { "addr": "c82d41b2501ac42e07e4565202a5b87a180a01c6a2", "attrs": {}, @@ -3406,14 +2800,6 @@ return class Handler { "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", @@ -3453,21 +2839,6 @@ return class Handler { "path": "root/my_api/Endpoint", }, "OnRequestHandler0": { - "children": { - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/my_api/OnRequestHandler0/Policy", - }, - }, "constructInfo": { "fqn": "constructs.Construct", "version": "10.3.0", @@ -3481,19 +2852,6 @@ return class Handler { "id": "OnRequestHandler0", "path": "root/my_api/OnRequestHandler0", }, - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/my_api/Policy", - }, }, "constructInfo": { "fqn": "constructs.Construct", @@ -3525,11 +2883,8 @@ exports[`api with multiple methods on same route 1`] = ` "root/my_api started", "root/my_api/Endpoint started", "root/my_api/OnRequestHandler0 started", - "root/my_api/OnRequestHandler1 started", - "root/my_api/Policy started", - "root/my_api/OnRequestHandler0/Policy started", "root/my_api/ApiEventMapping0 started", - "root/my_api/OnRequestHandler1/Policy started", + "root/my_api/OnRequestHandler1 started", "root/my_api/ApiEventMapping1 started", "Processing "GET /hello" params={}).", "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", @@ -3538,14 +2893,11 @@ exports[`api with multiple methods on same route 1`] = ` "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\",\\"content-length\\":\\"0\\"},\\"body\\":\\"\\",\\"method\\":\\"POST\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", "POST /hello - 200.", "root/my_api/Endpoint stopped", - "root/my_api/Policy stopped", - "root/my_api/OnRequestHandler0/Policy stopped", "root/my_api/ApiEventMapping0 stopped", "root/my_api/OnRequestHandler0 stopped", "root/my_api/ApiEventMapping1 stopped", "Closing server on http://127.0.0.1:", "root/my_api stopped", - "root/my_api/OnRequestHandler1/Policy stopped", "root/my_api/OnRequestHandler1 stopped", ] `; @@ -3614,35 +2966,6 @@ return class Handler { }, "type": "@winglang/sdk.cloud.Endpoint", }, - { - "addr": "c8d2997625976ba9bc7be90fefe7930aebab104a2a", - "attrs": {}, - "path": "root/my_api/Policy", - "props": { - "principal": "\${wsim#root/my_api#attrs.handle}", - "statements": [ - { - "operation": "invoke", - "resourceHandle": "\${wsim#root/my_api/OnRequestHandler0#attrs.handle}", - }, - { - "operation": "invoke", - "resourceHandle": "\${wsim#root/my_api/OnRequestHandler1#attrs.handle}", - }, - ], - }, - "type": "@winglang/sdk.sim.Policy", - }, - { - "addr": "c8b0396e20397567e34feafb703cea1bc0b968dc05", - "attrs": {}, - "path": "root/my_api/OnRequestHandler0/Policy", - "props": { - "principal": "\${wsim#root/my_api/OnRequestHandler0#attrs.handle}", - "statements": [], - }, - "type": "@winglang/sdk.sim.Policy", - }, { "addr": "c82d41b2501ac42e07e4565202a5b87a180a01c6a2", "attrs": {}, @@ -3713,16 +3036,6 @@ return class Handler { }, "type": "@winglang/sdk.sim.EventMapping", }, - { - "addr": "c8603fc16b367fc8cb05634fbb47b4a1e7f873b298", - "attrs": {}, - "path": "root/my_api/OnRequestHandler1/Policy", - "props": { - "principal": "\${wsim#root/my_api/OnRequestHandler1#attrs.handle}", - "statements": [], - }, - "type": "@winglang/sdk.sim.Policy", - }, { "addr": "c84819d7712e30f38cf7731fcfbe96cbc39c7e75d3", "attrs": {}, @@ -3833,14 +3146,6 @@ return class Handler { "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", @@ -3891,21 +3196,6 @@ return class Handler { "path": "root/my_api/Endpoint", }, "OnRequestHandler0": { - "children": { - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/my_api/OnRequestHandler0/Policy", - }, - }, "constructInfo": { "fqn": "constructs.Construct", "version": "10.3.0", @@ -3920,21 +3210,6 @@ return class Handler { "path": "root/my_api/OnRequestHandler0", }, "OnRequestHandler1": { - "children": { - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/my_api/OnRequestHandler1/Policy", - }, - }, "constructInfo": { "fqn": "constructs.Construct", "version": "10.3.0", @@ -3948,19 +3223,6 @@ return class Handler { "id": "OnRequestHandler1", "path": "root/my_api/OnRequestHandler1", }, - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/my_api/Policy", - }, }, "constructInfo": { "fqn": "constructs.Construct", @@ -3992,11 +3254,8 @@ exports[`api with multiple routes 1`] = ` "root/my_api started", "root/my_api/Endpoint started", "root/my_api/OnRequestHandler0 started", - "root/my_api/OnRequestHandler1 started", - "root/my_api/Policy started", - "root/my_api/OnRequestHandler0/Policy started", "root/my_api/ApiEventMapping0 started", - "root/my_api/OnRequestHandler1/Policy started", + "root/my_api/OnRequestHandler1 started", "root/my_api/ApiEventMapping1 started", "Processing "GET /hello/world" params={}).", "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello/world\\",\\"query\\":{},\\"vars\\":{}}").", @@ -4005,14 +3264,11 @@ exports[`api with multiple routes 1`] = ` "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello/wingnuts\\",\\"query\\":{},\\"vars\\":{}}").", "GET /hello/wingnuts - 200.", "root/my_api/Endpoint stopped", - "root/my_api/Policy stopped", - "root/my_api/OnRequestHandler0/Policy stopped", "root/my_api/ApiEventMapping0 stopped", "root/my_api/OnRequestHandler0 stopped", "root/my_api/ApiEventMapping1 stopped", "Closing server on http://127.0.0.1:", "root/my_api stopped", - "root/my_api/OnRequestHandler1/Policy stopped", "root/my_api/OnRequestHandler1 stopped", ] `; @@ -4081,35 +3337,6 @@ return class Handler { }, "type": "@winglang/sdk.cloud.Endpoint", }, - { - "addr": "c8d2997625976ba9bc7be90fefe7930aebab104a2a", - "attrs": {}, - "path": "root/my_api/Policy", - "props": { - "principal": "\${wsim#root/my_api#attrs.handle}", - "statements": [ - { - "operation": "invoke", - "resourceHandle": "\${wsim#root/my_api/OnRequestHandler0#attrs.handle}", - }, - { - "operation": "invoke", - "resourceHandle": "\${wsim#root/my_api/OnRequestHandler1#attrs.handle}", - }, - ], - }, - "type": "@winglang/sdk.sim.Policy", - }, - { - "addr": "c8b0396e20397567e34feafb703cea1bc0b968dc05", - "attrs": {}, - "path": "root/my_api/OnRequestHandler0/Policy", - "props": { - "principal": "\${wsim#root/my_api/OnRequestHandler0#attrs.handle}", - "statements": [], - }, - "type": "@winglang/sdk.sim.Policy", - }, { "addr": "c82d41b2501ac42e07e4565202a5b87a180a01c6a2", "attrs": {}, @@ -4182,16 +3409,6 @@ return class Handler { }, "type": "@winglang/sdk.sim.EventMapping", }, - { - "addr": "c8603fc16b367fc8cb05634fbb47b4a1e7f873b298", - "attrs": {}, - "path": "root/my_api/OnRequestHandler1/Policy", - "props": { - "principal": "\${wsim#root/my_api/OnRequestHandler1#attrs.handle}", - "statements": [], - }, - "type": "@winglang/sdk.sim.Policy", - }, { "addr": "c84819d7712e30f38cf7731fcfbe96cbc39c7e75d3", "attrs": {}, @@ -4302,14 +3519,6 @@ return class Handler { "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", @@ -4360,21 +3569,6 @@ return class Handler { "path": "root/my_api/Endpoint", }, "OnRequestHandler0": { - "children": { - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/my_api/OnRequestHandler0/Policy", - }, - }, "constructInfo": { "fqn": "constructs.Construct", "version": "10.3.0", @@ -4389,21 +3583,6 @@ return class Handler { "path": "root/my_api/OnRequestHandler0", }, "OnRequestHandler1": { - "children": { - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/my_api/OnRequestHandler1/Policy", - }, - }, "constructInfo": { "fqn": "constructs.Construct", "version": "10.3.0", @@ -4417,19 +3596,6 @@ return class Handler { "id": "OnRequestHandler1", "path": "root/my_api/OnRequestHandler1", }, - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/my_api/Policy", - }, }, "constructInfo": { "fqn": "constructs.Construct", @@ -4461,15 +3627,11 @@ exports[`api with one GET route 1`] = ` "root/my_api started", "root/my_api/Endpoint started", "root/my_api/OnRequestHandler0 started", - "root/my_api/Policy started", - "root/my_api/OnRequestHandler0/Policy started", "root/my_api/ApiEventMapping0 started", "Processing "GET /hello" params={}).", "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", "GET /hello - 200.", "root/my_api/Endpoint stopped", - "root/my_api/Policy stopped", - "root/my_api/OnRequestHandler0/Policy stopped", "root/my_api/ApiEventMapping0 stopped", "root/my_api/OnRequestHandler0 stopped", "Closing server on http://127.0.0.1:", @@ -4519,31 +3681,6 @@ return class Handler { }, "type": "@winglang/sdk.cloud.Endpoint", }, - { - "addr": "c8d2997625976ba9bc7be90fefe7930aebab104a2a", - "attrs": {}, - "path": "root/my_api/Policy", - "props": { - "principal": "\${wsim#root/my_api#attrs.handle}", - "statements": [ - { - "operation": "invoke", - "resourceHandle": "\${wsim#root/my_api/OnRequestHandler0#attrs.handle}", - }, - ], - }, - "type": "@winglang/sdk.sim.Policy", - }, - { - "addr": "c8b0396e20397567e34feafb703cea1bc0b968dc05", - "attrs": {}, - "path": "root/my_api/OnRequestHandler0/Policy", - "props": { - "principal": "\${wsim#root/my_api/OnRequestHandler0#attrs.handle}", - "statements": [], - }, - "type": "@winglang/sdk.sim.Policy", - }, { "addr": "c82d41b2501ac42e07e4565202a5b87a180a01c6a2", "attrs": {}, @@ -4679,14 +3816,6 @@ return class Handler { "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", @@ -4726,21 +3855,6 @@ return class Handler { "path": "root/my_api/Endpoint", }, "OnRequestHandler0": { - "children": { - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/my_api/OnRequestHandler0/Policy", - }, - }, "constructInfo": { "fqn": "constructs.Construct", "version": "10.3.0", @@ -4754,19 +3868,6 @@ return class Handler { "id": "OnRequestHandler0", "path": "root/my_api/OnRequestHandler0", }, - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/my_api/Policy", - }, }, "constructInfo": { "fqn": "constructs.Construct", @@ -4798,15 +3899,11 @@ exports[`api with one GET route with request params 1`] = ` "root/my_api started", "root/my_api/Endpoint started", "root/my_api/OnRequestHandler0 started", - "root/my_api/Policy started", - "root/my_api/OnRequestHandler0/Policy started", "root/my_api/ApiEventMapping0 started", "Processing "GET /users/:name" params={"name":"tsuf"}).", "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/users/tsuf\\",\\"query\\":{},\\"vars\\":{\\"name\\":\\"tsuf\\"}}").", "GET /users/:name - 200.", "root/my_api/Endpoint stopped", - "root/my_api/Policy stopped", - "root/my_api/OnRequestHandler0/Policy stopped", "root/my_api/ApiEventMapping0 stopped", "root/my_api/OnRequestHandler0 stopped", "Closing server on http://127.0.0.1:", @@ -4856,31 +3953,6 @@ return class Handler { }, "type": "@winglang/sdk.cloud.Endpoint", }, - { - "addr": "c8d2997625976ba9bc7be90fefe7930aebab104a2a", - "attrs": {}, - "path": "root/my_api/Policy", - "props": { - "principal": "\${wsim#root/my_api#attrs.handle}", - "statements": [ - { - "operation": "invoke", - "resourceHandle": "\${wsim#root/my_api/OnRequestHandler0#attrs.handle}", - }, - ], - }, - "type": "@winglang/sdk.sim.Policy", - }, - { - "addr": "c8b0396e20397567e34feafb703cea1bc0b968dc05", - "attrs": {}, - "path": "root/my_api/OnRequestHandler0/Policy", - "props": { - "principal": "\${wsim#root/my_api/OnRequestHandler0#attrs.handle}", - "statements": [], - }, - "type": "@winglang/sdk.sim.Policy", - }, { "addr": "c82d41b2501ac42e07e4565202a5b87a180a01c6a2", "attrs": {}, @@ -5025,14 +4097,6 @@ return class Handler { "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", @@ -5072,21 +4136,6 @@ return class Handler { "path": "root/my_api/Endpoint", }, "OnRequestHandler0": { - "children": { - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/my_api/OnRequestHandler0/Policy", - }, - }, "constructInfo": { "fqn": "constructs.Construct", "version": "10.3.0", @@ -5100,19 +4149,6 @@ return class Handler { "id": "OnRequestHandler0", "path": "root/my_api/OnRequestHandler0", }, - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/my_api/Policy", - }, }, "constructInfo": { "fqn": "constructs.Construct", @@ -5144,15 +4180,11 @@ exports[`api with one POST route, with body 1`] = ` "root/my_api started", "root/my_api/Endpoint started", "root/my_api/OnRequestHandler0 started", - "root/my_api/Policy started", - "root/my_api/OnRequestHandler0/Policy started", "root/my_api/ApiEventMapping0 started", "Processing "POST /hello" params={}).", "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"content-type\\":\\"application/json\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\",\\"content-length\\":\\"25\\"},\\"body\\":\\"{\\\\\\"message\\\\\\":\\\\\\"hello world\\\\\\"}\\",\\"method\\":\\"POST\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", "POST /hello - 200.", "root/my_api/Endpoint stopped", - "root/my_api/Policy stopped", - "root/my_api/OnRequestHandler0/Policy stopped", "root/my_api/ApiEventMapping0 stopped", "root/my_api/OnRequestHandler0 stopped", "Closing server on http://127.0.0.1:", @@ -5202,31 +4234,6 @@ return class Handler { }, "type": "@winglang/sdk.cloud.Endpoint", }, - { - "addr": "c8d2997625976ba9bc7be90fefe7930aebab104a2a", - "attrs": {}, - "path": "root/my_api/Policy", - "props": { - "principal": "\${wsim#root/my_api#attrs.handle}", - "statements": [ - { - "operation": "invoke", - "resourceHandle": "\${wsim#root/my_api/OnRequestHandler0#attrs.handle}", - }, - ], - }, - "type": "@winglang/sdk.sim.Policy", - }, - { - "addr": "c8b0396e20397567e34feafb703cea1bc0b968dc05", - "attrs": {}, - "path": "root/my_api/OnRequestHandler0/Policy", - "props": { - "principal": "\${wsim#root/my_api/OnRequestHandler0#attrs.handle}", - "statements": [], - }, - "type": "@winglang/sdk.sim.Policy", - }, { "addr": "c82d41b2501ac42e07e4565202a5b87a180a01c6a2", "attrs": {}, @@ -5362,14 +4369,6 @@ return class Handler { "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", @@ -5409,21 +4408,6 @@ return class Handler { "path": "root/my_api/Endpoint", }, "OnRequestHandler0": { - "children": { - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/my_api/OnRequestHandler0/Policy", - }, - }, "constructInfo": { "fqn": "constructs.Construct", "version": "10.3.0", @@ -5437,19 +4421,6 @@ return class Handler { "id": "OnRequestHandler0", "path": "root/my_api/OnRequestHandler0", }, - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/my_api/Policy", - }, }, "constructInfo": { "fqn": "constructs.Construct", @@ -5506,16 +4477,6 @@ exports[`create an api 1`] = ` }, "type": "@winglang/sdk.cloud.Endpoint", }, - { - "addr": "c8d2997625976ba9bc7be90fefe7930aebab104a2a", - "attrs": {}, - "path": "root/my_api/Policy", - "props": { - "principal": "\${wsim#root/my_api#attrs.handle}", - "statements": [], - }, - "type": "@winglang/sdk.sim.Policy", - }, ], "sdkVersion": "0.0.0", "types": { @@ -5591,14 +4552,6 @@ exports[`create an api 1`] = ` "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", @@ -5626,19 +4579,6 @@ exports[`create an api 1`] = ` "id": "Endpoint", "path": "root/my_api/Endpoint", }, - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/my_api/Policy", - }, }, "constructInfo": { "fqn": "constructs.Construct", diff --git a/libs/wingsdk/test/target-sim/__snapshots__/bucket.test.ts.snap b/libs/wingsdk/test/target-sim/__snapshots__/bucket.test.ts.snap index 56c148f70d8..a1f5c77fefd 100644 --- a/libs/wingsdk/test/target-sim/__snapshots__/bucket.test.ts.snap +++ b/libs/wingsdk/test/target-sim/__snapshots__/bucket.test.ts.snap @@ -6,60 +6,44 @@ exports[`bucket on event creates 3 topics, and sends the right event and key in "root/my_bucket/onupdate started", "root/my_bucket/ondelete started", "root/my_bucket started", - "root/my_bucket/Policy started", "root/log_bucket started", "root/my_bucket/oncreate/OnMessage0 started", - "root/my_bucket/oncreate/Policy started", - "root/my_bucket/oncreate/OnMessage0/Policy started", "root/my_bucket/oncreate/TopicEventMapping0 started", "root/my_bucket/onupdate/OnMessage0 started", - "root/my_bucket/onupdate/Policy started", - "root/my_bucket/onupdate/OnMessage0/Policy started", "root/my_bucket/onupdate/TopicEventMapping0 started", "root/my_bucket/ondelete/OnMessage0 started", - "root/my_bucket/ondelete/Policy started", - "root/my_bucket/ondelete/OnMessage0/Policy started", "root/my_bucket/ondelete/TopicEventMapping0 started", - "root/log_bucket/Policy started", "Publish (message=a).", - "Sending message (message=a, subscriber=sim-6).", + "Sending message (message=a, subscriber=sim-5).", "InvokeAsync (payload="a").", "Put (key=a).", "Put (key=a).", "I am done", "Get (key=a).", "Publish (message=a).", - "Sending message (message=a, subscriber=sim-10).", + "Sending message (message=a, subscriber=sim-7).", "InvokeAsync (payload="a").", "Put (key=a).", "Put (key=a).", "I am done", "Get (key=a).", "Publish (message=a).", - "Sending message (message=a, subscriber=sim-14).", + "Sending message (message=a, subscriber=sim-9).", "InvokeAsync (payload="a").", "Delete (key=a).", "Put (key=a).", "I am done", "Get (key=a).", - "root/my_bucket/Policy stopped", "root/my_bucket stopped", - "root/my_bucket/oncreate/Policy stopped", "root/my_bucket/oncreate/TopicEventMapping0 stopped", "root/my_bucket/oncreate stopped", - "root/my_bucket/onupdate/Policy stopped", "root/my_bucket/onupdate/TopicEventMapping0 stopped", "root/my_bucket/onupdate stopped", - "root/my_bucket/ondelete/Policy stopped", "root/my_bucket/ondelete/TopicEventMapping0 stopped", "root/my_bucket/ondelete stopped", - "root/my_bucket/oncreate/OnMessage0/Policy stopped", "root/my_bucket/oncreate/OnMessage0 stopped", - "root/my_bucket/onupdate/OnMessage0/Policy stopped", "root/my_bucket/onupdate/OnMessage0 stopped", - "root/my_bucket/ondelete/OnMessage0/Policy stopped", "root/my_bucket/ondelete/OnMessage0 stopped", - "root/log_bucket/Policy stopped", "root/log_bucket stopped", ] `; @@ -68,11 +52,9 @@ exports[`can add file in preflight 1`] = ` [ "Adding object from preflight (key=test.txt).", "root/my_bucket started", - "root/my_bucket/Policy started", "Get (key=test.txt).", "Get (key=test.txt).", "List (prefix=null).", - "root/my_bucket/Policy stopped", "root/my_bucket stopped", ] `; @@ -98,16 +80,6 @@ exports[`can add file in preflight 2`] = ` }, "type": "@winglang/sdk.cloud.Bucket", }, - { - "addr": "c8b5ba55132964ee19331fb9f46241560e67fed76b", - "attrs": {}, - "path": "root/my_bucket/Policy", - "props": { - "principal": "\${wsim#root/my_bucket#attrs.handle}", - "statements": [], - }, - "type": "@winglang/sdk.sim.Policy", - }, ], "sdkVersion": "0.0.0", "types": { @@ -183,14 +155,6 @@ exports[`can add file in preflight 2`] = ` "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", @@ -205,21 +169,6 @@ exports[`can add file in preflight 2`] = ` "tree": { "children": { "my_bucket": { - "children": { - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/my_bucket/Policy", - }, - }, "constructInfo": { "fqn": "constructs.Construct", "version": "10.3.0", @@ -248,11 +197,9 @@ exports[`can add object in preflight 1`] = ` [ "Adding object from preflight (key=greeting.txt).", "root/my_bucket started", - "root/my_bucket/Policy started", "Get (key=greeting.txt).", "Get (key=greeting.txt).", "List (prefix=null).", - "root/my_bucket/Policy stopped", "root/my_bucket stopped", ] `; @@ -278,16 +225,6 @@ exports[`can add object in preflight 2`] = ` }, "type": "@winglang/sdk.cloud.Bucket", }, - { - "addr": "c8b5ba55132964ee19331fb9f46241560e67fed76b", - "attrs": {}, - "path": "root/my_bucket/Policy", - "props": { - "principal": "\${wsim#root/my_bucket#attrs.handle}", - "statements": [], - }, - "type": "@winglang/sdk.sim.Policy", - }, ], "sdkVersion": "0.0.0", "types": { @@ -363,14 +300,6 @@ exports[`can add object in preflight 2`] = ` "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", @@ -385,21 +314,6 @@ exports[`can add object in preflight 2`] = ` "tree": { "children": { "my_bucket": { - "children": { - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/my_bucket/Policy", - }, - }, "constructInfo": { "fqn": "constructs.Construct", "version": "10.3.0", @@ -443,16 +357,6 @@ exports[`create a bucket 1`] = ` }, "type": "@winglang/sdk.cloud.Bucket", }, - { - "addr": "c8b5ba55132964ee19331fb9f46241560e67fed76b", - "attrs": {}, - "path": "root/my_bucket/Policy", - "props": { - "principal": "\${wsim#root/my_bucket#attrs.handle}", - "statements": [], - }, - "type": "@winglang/sdk.sim.Policy", - }, ], "sdkVersion": "0.0.0", "types": { @@ -528,14 +432,6 @@ exports[`create a bucket 1`] = ` "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", @@ -550,21 +446,6 @@ exports[`create a bucket 1`] = ` "tree": { "children": { "my_bucket": { - "children": { - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/my_bucket/Policy", - }, - }, "constructInfo": { "fqn": "constructs.Construct", "version": "10.3.0", @@ -592,9 +473,7 @@ exports[`create a bucket 1`] = ` exports[`get invalid object throws an error 1`] = ` [ "root/my_bucket started", - "root/my_bucket/Policy started", "Get (key=unknown.txt).", - "root/my_bucket/Policy stopped", "root/my_bucket stopped", ] `; @@ -618,16 +497,6 @@ exports[`get invalid object throws an error 2`] = ` }, "type": "@winglang/sdk.cloud.Bucket", }, - { - "addr": "c8b5ba55132964ee19331fb9f46241560e67fed76b", - "attrs": {}, - "path": "root/my_bucket/Policy", - "props": { - "principal": "\${wsim#root/my_bucket#attrs.handle}", - "statements": [], - }, - "type": "@winglang/sdk.sim.Policy", - }, ], "sdkVersion": "0.0.0", "types": { @@ -703,14 +572,6 @@ exports[`get invalid object throws an error 2`] = ` "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", @@ -725,21 +586,6 @@ exports[`get invalid object throws an error 2`] = ` "tree": { "children": { "my_bucket": { - "children": { - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/my_bucket/Policy", - }, - }, "constructInfo": { "fqn": "constructs.Construct", "version": "10.3.0", @@ -767,14 +613,12 @@ exports[`get invalid object throws an error 2`] = ` exports[`list respects prefixes 1`] = ` [ "root/my_bucket started", - "root/my_bucket/Policy started", "Put (key=path/dir1/file1.txt).", "Put (key=path/dir2/file2.txt).", "List (prefix=null).", "List (prefix=path).", "List (prefix=path/dir1).", "List (prefix=path/dir2).", - "root/my_bucket/Policy stopped", "root/my_bucket stopped", ] `; @@ -782,7 +626,6 @@ exports[`list respects prefixes 1`] = ` exports[`objects can have keys that look like directories 1`] = ` [ "root/my_bucket started", - "root/my_bucket/Policy started", "Put (key=foo).", "Put (key=foo/).", "Put (key=foo/bar).", @@ -794,7 +637,6 @@ exports[`objects can have keys that look like directories 1`] = ` "List (prefix=foo/bar).", "List (prefix=foo/bar/).", "List (prefix=foo/bar/baz).", - "root/my_bucket/Policy stopped", "root/my_bucket stopped", ] `; @@ -802,14 +644,12 @@ exports[`objects can have keys that look like directories 1`] = ` exports[`put and get metadata of objects from bucket 1`] = ` [ "root/my_bucket started", - "root/my_bucket/Policy started", "Put (key=file1.main.w).", "Put (key=file2.txt).", "Put (key=file3.txt).", "Metadata (key=file1.main.w).", "Metadata (key=file2.txt).", "Metadata (key=file3.txt).", - "root/my_bucket/Policy stopped", "root/my_bucket stopped", ] `; @@ -817,10 +657,8 @@ exports[`put and get metadata of objects from bucket 1`] = ` exports[`put and get object from bucket 1`] = ` [ "root/my_bucket started", - "root/my_bucket/Policy started", "Put (key=greeting.txt).", "Get (key=greeting.txt).", - "root/my_bucket/Policy stopped", "root/my_bucket stopped", ] `; @@ -828,12 +666,10 @@ exports[`put and get object from bucket 1`] = ` exports[`put multiple json objects and list all from bucket 1`] = ` [ "root/my_bucket started", - "root/my_bucket/Policy started", "Put Json (key=greeting1.json).", "Put Json (key=greeting2.json).", "Put Json (key=greeting3.json).", "List (prefix=null).", - "root/my_bucket/Policy stopped", "root/my_bucket stopped", ] `; @@ -841,12 +677,10 @@ exports[`put multiple json objects and list all from bucket 1`] = ` exports[`put multiple objects and list all from bucket 1`] = ` [ "root/my_bucket started", - "root/my_bucket/Policy started", "Put (key=greeting1.txt).", "Put (key=greeting2.txt).", "Put (key=greeting3.txt).", "List (prefix=null).", - "root/my_bucket/Policy stopped", "root/my_bucket stopped", ] `; @@ -854,10 +688,8 @@ exports[`put multiple objects and list all from bucket 1`] = ` exports[`remove object from a bucket 1`] = ` [ "root/my_bucket started", - "root/my_bucket/Policy started", "Put (key=unknown.txt).", "Delete (key=unknown.txt).", - "root/my_bucket/Policy stopped", "root/my_bucket stopped", ] `; @@ -865,10 +697,8 @@ exports[`remove object from a bucket 1`] = ` exports[`remove object from a bucket with mustExist as option 1`] = ` [ "root/my_bucket started", - "root/my_bucket/Policy started", "Put (key=unknown.txt).", "Delete (key=unknown.txt).", - "root/my_bucket/Policy stopped", "root/my_bucket stopped", ] `; @@ -877,23 +707,17 @@ exports[`removing a key will call onDelete method 1`] = ` [ "root/my_bucket/ondelete started", "root/my_bucket started", - "root/my_bucket/Policy started", "root/my_bucket/ondelete/OnMessage0 started", - "root/my_bucket/ondelete/Policy started", - "root/my_bucket/ondelete/OnMessage0/Policy started", "root/my_bucket/ondelete/TopicEventMapping0 started", "Put (key=unknown.txt).", "Publish (message=unknown.txt).", - "Sending message (message=unknown.txt, subscriber=sim-3).", + "Sending message (message=unknown.txt, subscriber=sim-2).", "InvokeAsync (payload="unknown.txt").", "Delete (key=unknown.txt).", "Received unknown.txt", - "root/my_bucket/Policy stopped", "root/my_bucket stopped", - "root/my_bucket/ondelete/Policy stopped", "root/my_bucket/ondelete/TopicEventMapping0 stopped", "root/my_bucket/ondelete stopped", - "root/my_bucket/ondelete/OnMessage0/Policy stopped", "root/my_bucket/ondelete/OnMessage0 stopped", ] `; @@ -902,23 +726,12 @@ exports[`update an object in bucket 1`] = ` [ "root/my_bucket/oncreate started", "root/my_bucket started", - "root/my_bucket/Policy started", "root/my_bucket/oncreate/OnMessage0 started", - "root/my_bucket/oncreate/Policy started", - "root/my_bucket/oncreate/OnMessage0/Policy started", "root/my_bucket/oncreate/TopicEventMapping0 started", "Publish (message=1.txt).", - "Sending message (message=1.txt, subscriber=sim-3).", + "Sending message (message=1.txt, subscriber=sim-2).", "InvokeAsync (payload="1.txt").", "Put (key=1.txt).", "Put (key=1.txt).", - "I am done", - "root/my_bucket/Policy stopped", - "root/my_bucket stopped", - "root/my_bucket/oncreate/Policy stopped", - "root/my_bucket/oncreate/TopicEventMapping0 stopped", - "root/my_bucket/oncreate stopped", - "root/my_bucket/oncreate/OnMessage0/Policy stopped", - "root/my_bucket/oncreate/OnMessage0 stopped", ] `; diff --git a/libs/wingsdk/test/target-sim/__snapshots__/counter.test.ts.snap b/libs/wingsdk/test/target-sim/__snapshots__/counter.test.ts.snap index 6b2d6b9b8cc..0d77770e98b 100644 --- a/libs/wingsdk/test/target-sim/__snapshots__/counter.test.ts.snap +++ b/libs/wingsdk/test/target-sim/__snapshots__/counter.test.ts.snap @@ -92,14 +92,6 @@ exports[`create a counter 1`] = ` "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", @@ -241,14 +233,6 @@ exports[`dec 2`] = ` "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", @@ -390,14 +374,6 @@ exports[`inc 2`] = ` "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", @@ -539,14 +515,6 @@ exports[`key dec 2`] = ` "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", @@ -688,14 +656,6 @@ exports[`key inc 2`] = ` "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", @@ -835,14 +795,6 @@ exports[`key set to new value 2`] = ` "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", @@ -982,14 +934,6 @@ exports[`set to new value 2`] = ` "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", diff --git a/libs/wingsdk/test/target-sim/__snapshots__/file-counter.test.ts.snap b/libs/wingsdk/test/target-sim/__snapshots__/file-counter.test.ts.snap index 9d11f3f638d..6371f1c2e57 100644 --- a/libs/wingsdk/test/target-sim/__snapshots__/file-counter.test.ts.snap +++ b/libs/wingsdk/test/target-sim/__snapshots__/file-counter.test.ts.snap @@ -28,11 +28,7 @@ counter: (function() { if (!simulatorUrl) { throw new Error("Missing environment variable: WING_SIMULATOR_URL"); } - const caller = process.env.WING_SIMULATOR_CALLER; - if (!caller) { - throw new Error("Missing environment variable: WING_SIMULATOR_CALLER"); - } - return require("@winglang/sdk/lib/simulator/client").makeSimulatorClient(simulatorUrl, handle, caller); + return require("@winglang/sdk/lib/simulator/client").makeSimulatorClient(simulatorUrl, handle); })(), bucket: (function() { let handle = process.env.BUCKET_HANDLE_5f2a41c8; @@ -43,11 +39,7 @@ bucket: (function() { if (!simulatorUrl) { throw new Error("Missing environment variable: WING_SIMULATOR_URL"); } - const caller = process.env.WING_SIMULATOR_CALLER; - if (!caller) { - throw new Error("Missing environment variable: WING_SIMULATOR_CALLER"); - } - return require("@winglang/sdk/lib/simulator/client").makeSimulatorClient(simulatorUrl, handle, caller); + return require("@winglang/sdk/lib/simulator/client").makeSimulatorClient(simulatorUrl, handle); })() }), args: {} })); return await $handler.handle(event); @@ -74,54 +66,6 @@ bucket: (function() { }, "simulator.json": { "resources": [ - { - "addr": "c86eb36bbe6e764a632afaaea5db2d4bd693c92624", - "attrs": {}, - "path": "root/HelloWorld/Bucket/Policy", - "props": { - "principal": "\${wsim#root/HelloWorld/Bucket#attrs.handle}", - "statements": [], - }, - "type": "@winglang/sdk.sim.Policy", - }, - { - "addr": "c86b009930462795eeb90e647a56dbfc5356d9ea80", - "attrs": {}, - "path": "root/HelloWorld/Queue/Policy", - "props": { - "principal": "\${wsim#root/HelloWorld/Queue#attrs.handle}", - "statements": [ - { - "operation": "invoke", - "resourceHandle": "\${wsim#root/HelloWorld/Queue/SetConsumer0#attrs.handle}", - }, - { - "operation": "hasAvailableWorkers", - "resourceHandle": "\${wsim#root/HelloWorld/Queue/SetConsumer0#attrs.handle}", - }, - ], - }, - "type": "@winglang/sdk.sim.Policy", - }, - { - "addr": "c88f4eae8103e33f1cf696aa3dad78ce4f1e5a2caa", - "attrs": {}, - "path": "root/HelloWorld/Queue/SetConsumer0/Policy", - "props": { - "principal": "\${wsim#root/HelloWorld/Queue/SetConsumer0#attrs.handle}", - "statements": [ - { - "operation": "inc", - "resourceHandle": "\${wsim#root/HelloWorld/Counter#attrs.handle}", - }, - { - "operation": "put", - "resourceHandle": "\${wsim#root/HelloWorld/Bucket#attrs.handle}", - }, - ], - }, - "type": "@winglang/sdk.sim.Policy", - }, { "addr": "c87855e817fa3df0d5ce8ae290bf53c8ce4ecd8d46", "attrs": {}, @@ -264,14 +208,6 @@ bucket: (function() { "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", @@ -288,21 +224,6 @@ bucket: (function() { "HelloWorld": { "children": { "Bucket": { - "children": { - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/HelloWorld/Bucket/Policy", - }, - }, "constructInfo": { "fqn": "constructs.Construct", "version": "10.3.0", @@ -328,19 +249,6 @@ bucket: (function() { }, "Queue": { "children": { - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/HelloWorld/Queue/Policy", - }, "QueueEventMapping0": { "constructInfo": { "fqn": "constructs.Construct", @@ -353,21 +261,6 @@ bucket: (function() { "path": "root/HelloWorld/Queue/QueueEventMapping0", }, "SetConsumer0": { - "children": { - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/HelloWorld/Queue/SetConsumer0/Policy", - }, - }, "constructInfo": { "fqn": "constructs.Construct", "version": "10.3.0", diff --git a/libs/wingsdk/test/target-sim/__snapshots__/function.test.ts.snap b/libs/wingsdk/test/target-sim/__snapshots__/function.test.ts.snap index 685cdcef273..f15ffe22fb8 100644 --- a/libs/wingsdk/test/target-sim/__snapshots__/function.test.ts.snap +++ b/libs/wingsdk/test/target-sim/__snapshots__/function.test.ts.snap @@ -1,5 +1,16 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html +exports[`__dirname and __filename cannot be used within inflight code 1`] = ` +[ + "root/Function.0 started", + "root/Function.1 started", + "Warning: __dirname and __filename cannot be used within bundled cloud functions. There may be unexpected behavior.", + "Warning: __dirname and __filename cannot be used within bundled cloud functions. There may be unexpected behavior.", + "Invoke (payload=undefined).", + "Invoke (payload=undefined).", +] +`; + exports[`create a function 1`] = ` { ".wing/my_function_c85c4e0e.js": ""use strict"; @@ -53,16 +64,6 @@ async handle(event) { }, "type": "@winglang/sdk.cloud.Function", }, - { - "addr": "c8d421ed6ca2ddf857d835791bcde9240c8682a8d9", - "attrs": {}, - "path": "root/my_function/Policy", - "props": { - "principal": "\${wsim#root/my_function#attrs.handle}", - "statements": [], - }, - "type": "@winglang/sdk.sim.Policy", - }, ], "sdkVersion": "0.0.0", "types": { @@ -138,14 +139,6 @@ async handle(event) { "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", @@ -160,21 +153,6 @@ async handle(event) { "tree": { "children": { "my_function": { - "children": { - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/my_function/Policy", - }, - }, "constructInfo": { "fqn": "constructs.Construct", "version": "10.3.0", @@ -202,9 +180,7 @@ async handle(event) { exports[`invoke function fails 1`] = ` [ "root/my_function started", - "root/my_function/Policy started", "Invoke (payload="{\\"name\\":\\"alice\\"}").", - "root/my_function/Policy stopped", "root/my_function stopped", ] `; @@ -260,16 +236,6 @@ async handle(event) { }, "type": "@winglang/sdk.cloud.Function", }, - { - "addr": "c8d421ed6ca2ddf857d835791bcde9240c8682a8d9", - "attrs": {}, - "path": "root/my_function/Policy", - "props": { - "principal": "\${wsim#root/my_function#attrs.handle}", - "statements": [], - }, - "type": "@winglang/sdk.sim.Policy", - }, ], "sdkVersion": "0.0.0", "types": { @@ -345,14 +311,6 @@ async handle(event) { "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", @@ -367,21 +325,6 @@ async handle(event) { "tree": { "children": { "my_function": { - "children": { - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/my_function/Policy", - }, - }, "constructInfo": { "fqn": "constructs.Construct", "version": "10.3.0", @@ -409,9 +352,7 @@ async handle(event) { exports[`invoke function succeeds 1`] = ` [ "root/my_function started", - "root/my_function/Policy started", "Invoke (payload="{\\"name\\":\\"Alice\\"}").", - "root/my_function/Policy stopped", "root/my_function stopped", ] `; @@ -467,16 +408,6 @@ async handle(event) { }, "type": "@winglang/sdk.cloud.Function", }, - { - "addr": "c8d421ed6ca2ddf857d835791bcde9240c8682a8d9", - "attrs": {}, - "path": "root/my_function/Policy", - "props": { - "principal": "\${wsim#root/my_function#attrs.handle}", - "statements": [], - }, - "type": "@winglang/sdk.sim.Policy", - }, ], "sdkVersion": "0.0.0", "types": { @@ -552,14 +483,6 @@ async handle(event) { "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", @@ -574,21 +497,6 @@ async handle(event) { "tree": { "children": { "my_function": { - "children": { - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/my_function/Policy", - }, - }, "constructInfo": { "fqn": "constructs.Construct", "version": "10.3.0", @@ -616,9 +524,7 @@ async handle(event) { exports[`invoke function with environment variables 1`] = ` [ "root/my_function started", - "root/my_function/Policy started", "Invoke (payload="{\\"name\\":\\"Alice\\"}").", - "root/my_function/Policy stopped", "root/my_function stopped", ] `; @@ -676,16 +582,6 @@ async handle(event) { }, "type": "@winglang/sdk.cloud.Function", }, - { - "addr": "c8d421ed6ca2ddf857d835791bcde9240c8682a8d9", - "attrs": {}, - "path": "root/my_function/Policy", - "props": { - "principal": "\${wsim#root/my_function#attrs.handle}", - "statements": [], - }, - "type": "@winglang/sdk.sim.Policy", - }, ], "sdkVersion": "0.0.0", "types": { @@ -761,14 +657,6 @@ async handle(event) { "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", @@ -783,21 +671,6 @@ async handle(event) { "tree": { "children": { "my_function": { - "children": { - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/my_function/Policy", - }, - }, "constructInfo": { "fqn": "constructs.Construct", "version": "10.3.0", @@ -825,9 +698,7 @@ async handle(event) { exports[`invoke function with process.exit(1) 1`] = ` [ "root/my_function started", - "root/my_function/Policy started", "Invoke (payload="{}").", - "root/my_function/Policy stopped", "root/my_function stopped", ] `; @@ -873,16 +744,6 @@ async handle() { }, "type": "@winglang/sdk.cloud.Function", }, - { - "addr": "c8d421ed6ca2ddf857d835791bcde9240c8682a8d9", - "attrs": {}, - "path": "root/my_function/Policy", - "props": { - "principal": "\${wsim#root/my_function#attrs.handle}", - "statements": [], - }, - "type": "@winglang/sdk.sim.Policy", - }, ], "sdkVersion": "0.0.0", "types": { @@ -958,14 +819,6 @@ async handle() { "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", @@ -980,21 +833,6 @@ async handle() { "tree": { "children": { "my_function": { - "children": { - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/my_function/Policy", - }, - }, "constructInfo": { "fqn": "constructs.Construct", "version": "10.3.0", @@ -1128,16 +966,6 @@ return class Handler { }, "type": "@winglang/sdk.cloud.Function", }, - { - "addr": "c80ba70b2cdb9a19bee761f329d38a2f8fe60dfd96", - "attrs": {}, - "path": "root/Function.0/Policy", - "props": { - "principal": "\${wsim#root/Function.0#attrs.handle}", - "statements": [], - }, - "type": "@winglang/sdk.sim.Policy", - }, { "addr": "c89ed254f66166d83153cc0a4952a15be63d47b0d2", "attrs": {}, @@ -1151,16 +979,6 @@ return class Handler { }, "type": "@winglang/sdk.cloud.Function", }, - { - "addr": "c82b947659316c604ceae225ba418b0d37542a5ba9", - "attrs": {}, - "path": "root/Function.1/Policy", - "props": { - "principal": "\${wsim#root/Function.1#attrs.handle}", - "statements": [], - }, - "type": "@winglang/sdk.sim.Policy", - }, { "addr": "c8cd6c39da22910102d0cfeb2cb96f2160fa79e517", "attrs": {}, @@ -1174,16 +992,6 @@ return class Handler { }, "type": "@winglang/sdk.cloud.Function", }, - { - "addr": "c84e1c1344ab5edfebbe25048f337b36bf0c9aed39", - "attrs": {}, - "path": "root/Function.2/Policy", - "props": { - "principal": "\${wsim#root/Function.2#attrs.handle}", - "statements": [], - }, - "type": "@winglang/sdk.sim.Policy", - }, { "addr": "c8badafa75a67ff66740e0c5fbbb392ab574b52b3c", "attrs": {}, @@ -1197,16 +1005,6 @@ return class Handler { }, "type": "@winglang/sdk.cloud.Function", }, - { - "addr": "c808a620b5341fa15dc763e8b6ba15ff0ebfcc6240", - "attrs": {}, - "path": "root/Function.3/Policy", - "props": { - "principal": "\${wsim#root/Function.3#attrs.handle}", - "statements": [], - }, - "type": "@winglang/sdk.sim.Policy", - }, ], "sdkVersion": "0.0.0", "types": { @@ -1282,14 +1080,6 @@ return class Handler { "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", @@ -1304,21 +1094,6 @@ return class Handler { "tree": { "children": { "Function.0": { - "children": { - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/Function.0/Policy", - }, - }, "constructInfo": { "fqn": "constructs.Construct", "version": "10.3.0", @@ -1331,21 +1106,6 @@ return class Handler { "path": "root/Function.0", }, "Function.1": { - "children": { - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/Function.1/Policy", - }, - }, "constructInfo": { "fqn": "constructs.Construct", "version": "10.3.0", @@ -1358,21 +1118,6 @@ return class Handler { "path": "root/Function.1", }, "Function.2": { - "children": { - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/Function.2/Policy", - }, - }, "constructInfo": { "fqn": "constructs.Construct", "version": "10.3.0", @@ -1385,21 +1130,6 @@ return class Handler { "path": "root/Function.2", }, "Function.3": { - "children": { - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/Function.3/Policy", - }, - }, "constructInfo": { "fqn": "constructs.Construct", "version": "10.3.0", diff --git a/libs/wingsdk/test/target-sim/__snapshots__/immutable-capture.test.ts.snap b/libs/wingsdk/test/target-sim/__snapshots__/immutable-capture.test.ts.snap index afd9b0a28a7..048de7a441c 100644 --- a/libs/wingsdk/test/target-sim/__snapshots__/immutable-capture.test.ts.snap +++ b/libs/wingsdk/test/target-sim/__snapshots__/immutable-capture.test.ts.snap @@ -43,16 +43,6 @@ my_capture: ["hello","dude"] }, "type": "@winglang/sdk.cloud.Function", }, - { - "addr": "c82c6881e1717b3b64913c3a5c4d7843012f2897e9", - "attrs": {}, - "path": "root/Function/Policy", - "props": { - "principal": "\${wsim#root/Function#attrs.handle}", - "statements": [], - }, - "type": "@winglang/sdk.sim.Policy", - }, ], "sdkVersion": "0.0.0", "types": { @@ -128,14 +118,6 @@ my_capture: ["hello","dude"] "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", @@ -150,21 +132,6 @@ my_capture: ["hello","dude"] "tree": { "children": { "Function": { - "children": { - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/Function/Policy", - }, - }, "constructInfo": { "fqn": "constructs.Construct", "version": "10.3.0", @@ -232,16 +199,6 @@ my_array: [(new (require("[REDACTED]/wingsdk/src/std/duration.js").Duration)(600 }, "type": "@winglang/sdk.cloud.Function", }, - { - "addr": "c82c6881e1717b3b64913c3a5c4d7843012f2897e9", - "attrs": {}, - "path": "root/Function/Policy", - "props": { - "principal": "\${wsim#root/Function#attrs.handle}", - "statements": [], - }, - "type": "@winglang/sdk.sim.Policy", - }, ], "sdkVersion": "0.0.0", "types": { @@ -317,14 +274,6 @@ my_array: [(new (require("[REDACTED]/wingsdk/src/std/duration.js").Duration)(600 "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", @@ -339,21 +288,6 @@ my_array: [(new (require("[REDACTED]/wingsdk/src/std/duration.js").Duration)(600 "tree": { "children": { "Function": { - "children": { - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/Function/Policy", - }, - }, "constructInfo": { "fqn": "constructs.Construct", "version": "10.3.0", @@ -420,16 +354,6 @@ my_array: [new Map([["foo",1],["bar",2]]),new Map([["foo",3],["bar",4]])] }, "type": "@winglang/sdk.cloud.Function", }, - { - "addr": "c82c6881e1717b3b64913c3a5c4d7843012f2897e9", - "attrs": {}, - "path": "root/Function/Policy", - "props": { - "principal": "\${wsim#root/Function#attrs.handle}", - "statements": [], - }, - "type": "@winglang/sdk.sim.Policy", - }, ], "sdkVersion": "0.0.0", "types": { @@ -505,14 +429,6 @@ my_array: [new Map([["foo",1],["bar",2]]),new Map([["foo",3],["bar",4]])] "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", @@ -527,21 +443,6 @@ my_array: [new Map([["foo",1],["bar",2]]),new Map([["foo",3],["bar",4]])] "tree": { "children": { "Function": { - "children": { - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/Function/Policy", - }, - }, "constructInfo": { "fqn": "constructs.Construct", "version": "10.3.0", @@ -607,16 +508,6 @@ my_capture: false }, "type": "@winglang/sdk.cloud.Function", }, - { - "addr": "c82c6881e1717b3b64913c3a5c4d7843012f2897e9", - "attrs": {}, - "path": "root/Function/Policy", - "props": { - "principal": "\${wsim#root/Function#attrs.handle}", - "statements": [], - }, - "type": "@winglang/sdk.sim.Policy", - }, ], "sdkVersion": "0.0.0", "types": { @@ -692,14 +583,6 @@ my_capture: false "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", @@ -714,21 +597,6 @@ my_capture: false "tree": { "children": { "Function": { - "children": { - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/Function/Policy", - }, - }, "constructInfo": { "fqn": "constructs.Construct", "version": "10.3.0", @@ -796,16 +664,6 @@ my_capture: (new (require("[REDACTED]/wingsdk/src/std/duration.js").Duration)(72 }, "type": "@winglang/sdk.cloud.Function", }, - { - "addr": "c82c6881e1717b3b64913c3a5c4d7843012f2897e9", - "attrs": {}, - "path": "root/Function/Policy", - "props": { - "principal": "\${wsim#root/Function#attrs.handle}", - "statements": [], - }, - "type": "@winglang/sdk.sim.Policy", - }, ], "sdkVersion": "0.0.0", "types": { @@ -881,14 +739,6 @@ my_capture: (new (require("[REDACTED]/wingsdk/src/std/duration.js").Duration)(72 "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", @@ -903,21 +753,6 @@ my_capture: (new (require("[REDACTED]/wingsdk/src/std/duration.js").Duration)(72 "tree": { "children": { "Function": { - "children": { - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/Function/Policy", - }, - }, "constructInfo": { "fqn": "constructs.Construct", "version": "10.3.0", @@ -987,16 +822,6 @@ my_capture: new Map([["foo",123],["bar",456]]) }, "type": "@winglang/sdk.cloud.Function", }, - { - "addr": "c82c6881e1717b3b64913c3a5c4d7843012f2897e9", - "attrs": {}, - "path": "root/Function/Policy", - "props": { - "principal": "\${wsim#root/Function#attrs.handle}", - "statements": [], - }, - "type": "@winglang/sdk.sim.Policy", - }, ], "sdkVersion": "0.0.0", "types": { @@ -1072,14 +897,6 @@ my_capture: new Map([["foo",123],["bar",456]]) "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", @@ -1094,21 +911,6 @@ my_capture: new Map([["foo",123],["bar",456]]) "tree": { "children": { "Function": { - "children": { - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/Function/Policy", - }, - }, "constructInfo": { "fqn": "constructs.Construct", "version": "10.3.0", @@ -1180,16 +982,6 @@ my_map: new Map([["foo",[1,2]],["bar",[3,4]]]) }, "type": "@winglang/sdk.cloud.Function", }, - { - "addr": "c82c6881e1717b3b64913c3a5c4d7843012f2897e9", - "attrs": {}, - "path": "root/Function/Policy", - "props": { - "principal": "\${wsim#root/Function#attrs.handle}", - "statements": [], - }, - "type": "@winglang/sdk.sim.Policy", - }, ], "sdkVersion": "0.0.0", "types": { @@ -1265,14 +1057,6 @@ my_map: new Map([["foo",[1,2]],["bar",[3,4]]]) "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", @@ -1287,21 +1071,6 @@ my_map: new Map([["foo",[1,2]],["bar",[3,4]]]) "tree": { "children": { "Function": { - "children": { - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/Function/Policy", - }, - }, "constructInfo": { "fqn": "constructs.Construct", "version": "10.3.0", @@ -1370,16 +1139,6 @@ my_map: new Map([["foo",[(new (require("[REDACTED]/wingsdk/src/std/duration.js") }, "type": "@winglang/sdk.cloud.Function", }, - { - "addr": "c82c6881e1717b3b64913c3a5c4d7843012f2897e9", - "attrs": {}, - "path": "root/Function/Policy", - "props": { - "principal": "\${wsim#root/Function#attrs.handle}", - "statements": [], - }, - "type": "@winglang/sdk.sim.Policy", - }, ], "sdkVersion": "0.0.0", "types": { @@ -1455,14 +1214,6 @@ my_map: new Map([["foo",[(new (require("[REDACTED]/wingsdk/src/std/duration.js") "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", @@ -1477,21 +1228,6 @@ my_map: new Map([["foo",[(new (require("[REDACTED]/wingsdk/src/std/duration.js") "tree": { "children": { "Function": { - "children": { - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/Function/Policy", - }, - }, "constructInfo": { "fqn": "constructs.Construct", "version": "10.3.0", @@ -1557,16 +1293,6 @@ my_capture: 123 }, "type": "@winglang/sdk.cloud.Function", }, - { - "addr": "c82c6881e1717b3b64913c3a5c4d7843012f2897e9", - "attrs": {}, - "path": "root/Function/Policy", - "props": { - "principal": "\${wsim#root/Function#attrs.handle}", - "statements": [], - }, - "type": "@winglang/sdk.sim.Policy", - }, ], "sdkVersion": "0.0.0", "types": { @@ -1642,14 +1368,6 @@ my_capture: 123 "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", @@ -1664,21 +1382,6 @@ my_capture: 123 "tree": { "children": { "Function": { - "children": { - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/Function/Policy", - }, - }, "constructInfo": { "fqn": "constructs.Construct", "version": "10.3.0", @@ -1747,16 +1450,6 @@ my_capture: new Set(["boom","bam","bang"]) }, "type": "@winglang/sdk.cloud.Function", }, - { - "addr": "c82c6881e1717b3b64913c3a5c4d7843012f2897e9", - "attrs": {}, - "path": "root/Function/Policy", - "props": { - "principal": "\${wsim#root/Function#attrs.handle}", - "statements": [], - }, - "type": "@winglang/sdk.sim.Policy", - }, ], "sdkVersion": "0.0.0", "types": { @@ -1832,14 +1525,6 @@ my_capture: new Set(["boom","bam","bang"]) "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", @@ -1854,21 +1539,6 @@ my_capture: new Set(["boom","bam","bang"]) "tree": { "children": { "Function": { - "children": { - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/Function/Policy", - }, - }, "constructInfo": { "fqn": "constructs.Construct", "version": "10.3.0", @@ -1936,16 +1606,6 @@ my_set: new Set([(new (require("[REDACTED]/wingsdk/src/std/duration.js").Duratio }, "type": "@winglang/sdk.cloud.Function", }, - { - "addr": "c82c6881e1717b3b64913c3a5c4d7843012f2897e9", - "attrs": {}, - "path": "root/Function/Policy", - "props": { - "principal": "\${wsim#root/Function#attrs.handle}", - "statements": [], - }, - "type": "@winglang/sdk.sim.Policy", - }, ], "sdkVersion": "0.0.0", "types": { @@ -2021,14 +1681,6 @@ my_set: new Set([(new (require("[REDACTED]/wingsdk/src/std/duration.js").Duratio "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", @@ -2043,21 +1695,6 @@ my_set: new Set([(new (require("[REDACTED]/wingsdk/src/std/duration.js").Duratio "tree": { "children": { "Function": { - "children": { - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/Function/Policy", - }, - }, "constructInfo": { "fqn": "constructs.Construct", "version": "10.3.0", @@ -2124,16 +1761,6 @@ my_capture: "bam bam bam" }, "type": "@winglang/sdk.cloud.Function", }, - { - "addr": "c82c6881e1717b3b64913c3a5c4d7843012f2897e9", - "attrs": {}, - "path": "root/Function/Policy", - "props": { - "principal": "\${wsim#root/Function#attrs.handle}", - "statements": [], - }, - "type": "@winglang/sdk.sim.Policy", - }, ], "sdkVersion": "0.0.0", "types": { @@ -2209,14 +1836,6 @@ my_capture: "bam bam bam" "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", @@ -2231,21 +1850,6 @@ my_capture: "bam bam bam" "tree": { "children": { "Function": { - "children": { - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/Function/Policy", - }, - }, "constructInfo": { "fqn": "constructs.Construct", "version": "10.3.0", @@ -2314,16 +1918,6 @@ my_capture: {"hello": "dude","world": "cup","foo": "bar",} }, "type": "@winglang/sdk.cloud.Function", }, - { - "addr": "c82c6881e1717b3b64913c3a5c4d7843012f2897e9", - "attrs": {}, - "path": "root/Function/Policy", - "props": { - "principal": "\${wsim#root/Function#attrs.handle}", - "statements": [], - }, - "type": "@winglang/sdk.sim.Policy", - }, ], "sdkVersion": "0.0.0", "types": { @@ -2399,14 +1993,6 @@ my_capture: {"hello": "dude","world": "cup","foo": "bar",} "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", @@ -2421,21 +2007,6 @@ my_capture: {"hello": "dude","world": "cup","foo": "bar",} "tree": { "children": { "Function": { - "children": { - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/Function/Policy", - }, - }, "constructInfo": { "fqn": "constructs.Construct", "version": "10.3.0", @@ -2504,16 +2075,6 @@ my_struct: {"foo": new Map([["foo",1],["bar",2]]),"bar": new Map([["foo",3],["ba }, "type": "@winglang/sdk.cloud.Function", }, - { - "addr": "c82c6881e1717b3b64913c3a5c4d7843012f2897e9", - "attrs": {}, - "path": "root/Function/Policy", - "props": { - "principal": "\${wsim#root/Function#attrs.handle}", - "statements": [], - }, - "type": "@winglang/sdk.sim.Policy", - }, ], "sdkVersion": "0.0.0", "types": { @@ -2589,14 +2150,6 @@ my_struct: {"foo": new Map([["foo",1],["bar",2]]),"bar": new Map([["foo",3],["ba "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", @@ -2611,21 +2164,6 @@ my_struct: {"foo": new Map([["foo",1],["bar",2]]),"bar": new Map([["foo",3],["ba "tree": { "children": { "Function": { - "children": { - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/Function/Policy", - }, - }, "constructInfo": { "fqn": "constructs.Construct", "version": "10.3.0", diff --git a/libs/wingsdk/test/target-sim/__snapshots__/on-deploy.test.ts.snap b/libs/wingsdk/test/target-sim/__snapshots__/on-deploy.test.ts.snap index 8f0db48a5f3..c8e80855916 100644 --- a/libs/wingsdk/test/target-sim/__snapshots__/on-deploy.test.ts.snap +++ b/libs/wingsdk/test/target-sim/__snapshots__/on-deploy.test.ts.snap @@ -38,22 +38,11 @@ return class Handler { }, "type": "@winglang/sdk.cloud.Function", }, - { - "addr": "c84ce37dba3dd1bd3d5c4ab27cb72c54e2b1a75821", - "attrs": {}, - "path": "root/my_on_deploy/Function/Policy", - "props": { - "principal": "\${wsim#root/my_on_deploy/Function#attrs.handle}", - "statements": [], - }, - "type": "@winglang/sdk.sim.Policy", - }, { "addr": "c8e2618b976544550a8396a3817f0bad07099f7050", "attrs": {}, "deps": [ "root/my_on_deploy/Function", - "root/my_on_deploy/Function/Policy", ], "path": "root/my_on_deploy", "props": { @@ -136,14 +125,6 @@ return class Handler { "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", @@ -160,21 +141,6 @@ return class Handler { "my_on_deploy": { "children": { "Function": { - "children": { - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/my_on_deploy/Function/Policy", - }, - }, "constructInfo": { "fqn": "constructs.Construct", "version": "10.3.0", @@ -215,13 +181,11 @@ return class Handler { exports[`create an OnDeploy 2`] = ` [ "root/my_on_deploy/Function started", - "root/my_on_deploy/Function/Policy started", "super duper success", "Invoke (payload=undefined).", "OnDeploy invoked.", "root/my_on_deploy started", "root/my_on_deploy stopped", - "root/my_on_deploy/Function/Policy stopped", "root/my_on_deploy/Function stopped", ] `; diff --git a/libs/wingsdk/test/target-sim/__snapshots__/queue.test.ts.snap b/libs/wingsdk/test/target-sim/__snapshots__/queue.test.ts.snap index cef3a1a4097..642f485ebdc 100644 --- a/libs/wingsdk/test/target-sim/__snapshots__/queue.test.ts.snap +++ b/libs/wingsdk/test/target-sim/__snapshots__/queue.test.ts.snap @@ -18,16 +18,6 @@ exports[`create a queue 1`] = ` }, "type": "@winglang/sdk.cloud.Queue", }, - { - "addr": "c88a4c68047871c2d322479c886423828e8119d85c", - "attrs": {}, - "path": "root/my_queue/Policy", - "props": { - "principal": "\${wsim#root/my_queue#attrs.handle}", - "statements": [], - }, - "type": "@winglang/sdk.sim.Policy", - }, ], "sdkVersion": "0.0.0", "types": { @@ -103,14 +93,6 @@ exports[`create a queue 1`] = ` "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", @@ -125,21 +107,6 @@ exports[`create a queue 1`] = ` "tree": { "children": { "my_queue": { - "children": { - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/my_queue/Policy", - }, - }, "constructInfo": { "fqn": "constructs.Construct", "version": "10.3.0", @@ -618,9 +585,7 @@ async handle(message) { exports[`push rejects empty message 1`] = ` [ "root/my_queue started", - "root/my_queue/Policy started", "Push (messages=).", - "root/my_queue/Policy stopped", "root/my_queue stopped", ] `; @@ -643,16 +608,6 @@ exports[`push rejects empty message 2`] = ` }, "type": "@winglang/sdk.cloud.Queue", }, - { - "addr": "c88a4c68047871c2d322479c886423828e8119d85c", - "attrs": {}, - "path": "root/my_queue/Policy", - "props": { - "principal": "\${wsim#root/my_queue#attrs.handle}", - "statements": [], - }, - "type": "@winglang/sdk.sim.Policy", - }, ], "sdkVersion": "0.0.0", "types": { @@ -728,14 +683,6 @@ exports[`push rejects empty message 2`] = ` "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", @@ -750,21 +697,6 @@ exports[`push rejects empty message 2`] = ` "tree": { "children": { "my_queue": { - "children": { - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/my_queue/Policy", - }, - }, "constructInfo": { "fqn": "constructs.Construct", "version": "10.3.0", @@ -792,13 +724,11 @@ exports[`push rejects empty message 2`] = ` exports[`queue batch size of 2, purge the queue 1`] = ` [ "root/my_queue started", - "root/my_queue/Policy started", "Push (messages=A).", "Push (messages=B).", "ApproxSize ().", "Purge ().", "ApproxSize ().", - "root/my_queue/Policy stopped", "root/my_queue stopped", ] `; @@ -821,16 +751,6 @@ exports[`queue batch size of 2, purge the queue 2`] = ` }, "type": "@winglang/sdk.cloud.Queue", }, - { - "addr": "c88a4c68047871c2d322479c886423828e8119d85c", - "attrs": {}, - "path": "root/my_queue/Policy", - "props": { - "principal": "\${wsim#root/my_queue#attrs.handle}", - "statements": [], - }, - "type": "@winglang/sdk.sim.Policy", - }, ], "sdkVersion": "0.0.0", "types": { @@ -906,14 +826,6 @@ exports[`queue batch size of 2, purge the queue 2`] = ` "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", @@ -928,21 +840,6 @@ exports[`queue batch size of 2, purge the queue 2`] = ` "tree": { "children": { "my_queue": { - "children": { - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/my_queue/Policy", - }, - }, "constructInfo": { "fqn": "constructs.Construct", "version": "10.3.0", @@ -998,11 +895,7 @@ queue: (function() { if (!simulatorUrl) { throw new Error("Missing environment variable: WING_SIMULATOR_URL"); } - const caller = process.env.WING_SIMULATOR_CALLER; - if (!caller) { - throw new Error("Missing environment variable: WING_SIMULATOR_CALLER"); - } - return require("@winglang/sdk/lib/simulator/client").makeSimulatorClient(simulatorUrl, handle, caller); + return require("@winglang/sdk/lib/simulator/client").makeSimulatorClient(simulatorUrl, handle); })() })); return await $handler.handle(event); @@ -1046,35 +939,6 @@ async handle(message) { }, "simulator.json": { "resources": [ - { - "addr": "c88a4c68047871c2d322479c886423828e8119d85c", - "attrs": {}, - "path": "root/my_queue/Policy", - "props": { - "principal": "\${wsim#root/my_queue#attrs.handle}", - "statements": [ - { - "operation": "invoke", - "resourceHandle": "\${wsim#root/my_queue/SetConsumer0#attrs.handle}", - }, - { - "operation": "hasAvailableWorkers", - "resourceHandle": "\${wsim#root/my_queue/SetConsumer0#attrs.handle}", - }, - ], - }, - "type": "@winglang/sdk.sim.Policy", - }, - { - "addr": "c850ec3b050199141fa07ce182e2e0711e60d2d193", - "attrs": {}, - "path": "root/my_queue/SetConsumer0/Policy", - "props": { - "principal": "\${wsim#root/my_queue/SetConsumer0#attrs.handle}", - "statements": [], - }, - "type": "@winglang/sdk.sim.Policy", - }, { "addr": "c8e33b9b91c909e579b9d3d703146eb66c2a657ffc", "attrs": {}, @@ -1133,27 +997,11 @@ async handle(message) { }, "type": "@winglang/sdk.cloud.Function", }, - { - "addr": "c8a0157ce3fdc8f4da43f974ef4b722745f359650f", - "attrs": {}, - "path": "root/my_queue_messages/Function/Policy", - "props": { - "principal": "\${wsim#root/my_queue_messages/Function#attrs.handle}", - "statements": [ - { - "operation": "push", - "resourceHandle": "\${wsim#root/my_queue#attrs.handle}", - }, - ], - }, - "type": "@winglang/sdk.sim.Policy", - }, { "addr": "c8e2354407fd3536187725c2b37c5327f47bb841e9", "attrs": {}, "deps": [ "root/my_queue_messages/Function", - "root/my_queue_messages/Function/Policy", ], "path": "root/my_queue_messages", "props": { @@ -1236,14 +1084,6 @@ async handle(message) { "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", @@ -1259,19 +1099,6 @@ async handle(message) { "children": { "my_queue": { "children": { - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/my_queue/Policy", - }, "QueueEventMapping0": { "constructInfo": { "fqn": "constructs.Construct", @@ -1284,21 +1111,6 @@ async handle(message) { "path": "root/my_queue/QueueEventMapping0", }, "SetConsumer0": { - "children": { - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/my_queue/SetConsumer0/Policy", - }, - }, "constructInfo": { "fqn": "constructs.Construct", "version": "10.3.0", @@ -1326,21 +1138,6 @@ async handle(message) { "my_queue_messages": { "children": { "Function": { - "children": { - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/my_queue_messages/Function/Policy", - }, - }, "constructInfo": { "fqn": "constructs.Construct", "version": "10.3.0", @@ -1414,35 +1211,6 @@ async handle(message) { }, "simulator.json": { "resources": [ - { - "addr": "c88a4c68047871c2d322479c886423828e8119d85c", - "attrs": {}, - "path": "root/my_queue/Policy", - "props": { - "principal": "\${wsim#root/my_queue#attrs.handle}", - "statements": [ - { - "operation": "invoke", - "resourceHandle": "\${wsim#root/my_queue/SetConsumer0#attrs.handle}", - }, - { - "operation": "hasAvailableWorkers", - "resourceHandle": "\${wsim#root/my_queue/SetConsumer0#attrs.handle}", - }, - ], - }, - "type": "@winglang/sdk.sim.Policy", - }, - { - "addr": "c850ec3b050199141fa07ce182e2e0711e60d2d193", - "attrs": {}, - "path": "root/my_queue/SetConsumer0/Policy", - "props": { - "principal": "\${wsim#root/my_queue/SetConsumer0#attrs.handle}", - "statements": [], - }, - "type": "@winglang/sdk.sim.Policy", - }, { "addr": "c8e33b9b91c909e579b9d3d703146eb66c2a657ffc", "attrs": {}, @@ -1558,14 +1326,6 @@ async handle(message) { "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", @@ -1581,19 +1341,6 @@ async handle(message) { "children": { "my_queue": { "children": { - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/my_queue/Policy", - }, "QueueEventMapping0": { "constructInfo": { "fqn": "constructs.Construct", @@ -1606,21 +1353,6 @@ async handle(message) { "path": "root/my_queue/QueueEventMapping0", }, "SetConsumer0": { - "children": { - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/my_queue/SetConsumer0/Policy", - }, - }, "constructInfo": { "fqn": "constructs.Construct", "version": "10.3.0", diff --git a/libs/wingsdk/test/target-sim/__snapshots__/redis.test.ts.snap b/libs/wingsdk/test/target-sim/__snapshots__/redis.test.ts.snap index 69133a45443..f20b4825304 100644 --- a/libs/wingsdk/test/target-sim/__snapshots__/redis.test.ts.snap +++ b/libs/wingsdk/test/target-sim/__snapshots__/redis.test.ts.snap @@ -104,14 +104,6 @@ exports[`create a Redis resource 1`] = ` "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", diff --git a/libs/wingsdk/test/target-sim/__snapshots__/schedule.test.ts.snap b/libs/wingsdk/test/target-sim/__snapshots__/schedule.test.ts.snap index 1b3ff0eaf05..c845a045772 100644 --- a/libs/wingsdk/test/target-sim/__snapshots__/schedule.test.ts.snap +++ b/libs/wingsdk/test/target-sim/__snapshots__/schedule.test.ts.snap @@ -17,16 +17,6 @@ exports[`create a schedule 1`] = ` }, "type": "@winglang/sdk.cloud.Schedule", }, - { - "addr": "c8c7f555c253f79a2cdcd8a13c6772cfd654e2bf0b", - "attrs": {}, - "path": "root/my_schedule/Policy", - "props": { - "principal": "\${wsim#root/my_schedule#attrs.handle}", - "statements": [], - }, - "type": "@winglang/sdk.sim.Policy", - }, ], "sdkVersion": "0.0.0", "types": { @@ -102,14 +92,6 @@ exports[`create a schedule 1`] = ` "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", @@ -124,21 +106,6 @@ exports[`create a schedule 1`] = ` "tree": { "children": { "my_schedule": { - "children": { - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/my_schedule/Policy", - }, - }, "constructInfo": { "fqn": "constructs.Construct", "version": "10.3.0", @@ -197,31 +164,6 @@ console.log("Hello from schedule!"); }, "simulator.json": { "resources": [ - { - "addr": "c8c7f555c253f79a2cdcd8a13c6772cfd654e2bf0b", - "attrs": {}, - "path": "root/my_schedule/Policy", - "props": { - "principal": "\${wsim#root/my_schedule#attrs.handle}", - "statements": [ - { - "operation": "invoke", - "resourceHandle": "\${wsim#root/my_schedule/OnTick0#attrs.handle}", - }, - ], - }, - "type": "@winglang/sdk.sim.Policy", - }, - { - "addr": "c8d61fcab25f1c27fcb0f0ba29e4888a7041c8029f", - "attrs": {}, - "path": "root/my_schedule/OnTick0/Policy", - "props": { - "principal": "\${wsim#root/my_schedule/OnTick0#attrs.handle}", - "statements": [], - }, - "type": "@winglang/sdk.sim.Policy", - }, { "addr": "c83eddbe8512d15b84969a611d4b5ca9ce55e1f808", "attrs": {}, @@ -334,14 +276,6 @@ console.log("Hello from schedule!"); "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", @@ -358,21 +292,6 @@ console.log("Hello from schedule!"); "my_schedule": { "children": { "OnTick0": { - "children": { - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/my_schedule/OnTick0/Policy", - }, - }, "constructInfo": { "fqn": "constructs.Construct", "version": "10.3.0", @@ -396,19 +315,6 @@ console.log("Hello from schedule!"); "id": "OnTickMapping0", "path": "root/my_schedule/OnTickMapping0", }, - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/my_schedule/Policy", - }, }, "constructInfo": { "fqn": "constructs.Construct", @@ -468,31 +374,6 @@ console.log("Hello from schedule!"); }, "simulator.json": { "resources": [ - { - "addr": "c8c7f555c253f79a2cdcd8a13c6772cfd654e2bf0b", - "attrs": {}, - "path": "root/my_schedule/Policy", - "props": { - "principal": "\${wsim#root/my_schedule#attrs.handle}", - "statements": [ - { - "operation": "invoke", - "resourceHandle": "\${wsim#root/my_schedule/OnTick0#attrs.handle}", - }, - ], - }, - "type": "@winglang/sdk.sim.Policy", - }, - { - "addr": "c8d61fcab25f1c27fcb0f0ba29e4888a7041c8029f", - "attrs": {}, - "path": "root/my_schedule/OnTick0/Policy", - "props": { - "principal": "\${wsim#root/my_schedule/OnTick0#attrs.handle}", - "statements": [], - }, - "type": "@winglang/sdk.sim.Policy", - }, { "addr": "c83eddbe8512d15b84969a611d4b5ca9ce55e1f808", "attrs": {}, @@ -605,14 +486,6 @@ console.log("Hello from schedule!"); "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", @@ -629,21 +502,6 @@ console.log("Hello from schedule!"); "my_schedule": { "children": { "OnTick0": { - "children": { - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/my_schedule/OnTick0/Policy", - }, - }, "constructInfo": { "fqn": "constructs.Construct", "version": "10.3.0", @@ -667,19 +525,6 @@ console.log("Hello from schedule!"); "id": "OnTickMapping0", "path": "root/my_schedule/OnTickMapping0", }, - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/my_schedule/Policy", - }, }, "constructInfo": { "fqn": "constructs.Construct", @@ -739,31 +584,6 @@ console.log("Hello from schedule!"); }, "simulator.json": { "resources": [ - { - "addr": "c8c7f555c253f79a2cdcd8a13c6772cfd654e2bf0b", - "attrs": {}, - "path": "root/my_schedule/Policy", - "props": { - "principal": "\${wsim#root/my_schedule#attrs.handle}", - "statements": [ - { - "operation": "invoke", - "resourceHandle": "\${wsim#root/my_schedule/OnTick0#attrs.handle}", - }, - ], - }, - "type": "@winglang/sdk.sim.Policy", - }, - { - "addr": "c8d61fcab25f1c27fcb0f0ba29e4888a7041c8029f", - "attrs": {}, - "path": "root/my_schedule/OnTick0/Policy", - "props": { - "principal": "\${wsim#root/my_schedule/OnTick0#attrs.handle}", - "statements": [], - }, - "type": "@winglang/sdk.sim.Policy", - }, { "addr": "c83eddbe8512d15b84969a611d4b5ca9ce55e1f808", "attrs": {}, @@ -876,14 +696,6 @@ console.log("Hello from schedule!"); "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", @@ -900,21 +712,6 @@ console.log("Hello from schedule!"); "my_schedule": { "children": { "OnTick0": { - "children": { - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/my_schedule/OnTick0/Policy", - }, - }, "constructInfo": { "fqn": "constructs.Construct", "version": "10.3.0", @@ -938,19 +735,6 @@ console.log("Hello from schedule!"); "id": "OnTickMapping0", "path": "root/my_schedule/OnTickMapping0", }, - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/my_schedule/Policy", - }, }, "constructInfo": { "fqn": "constructs.Construct", diff --git a/libs/wingsdk/test/target-sim/__snapshots__/secret.test.ts.snap b/libs/wingsdk/test/target-sim/__snapshots__/secret.test.ts.snap index debe797f8d9..50ee1bf1a06 100644 --- a/libs/wingsdk/test/target-sim/__snapshots__/secret.test.ts.snap +++ b/libs/wingsdk/test/target-sim/__snapshots__/secret.test.ts.snap @@ -92,14 +92,6 @@ exports[`create a secret 1`] = ` "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", diff --git a/libs/wingsdk/test/target-sim/__snapshots__/service.test.ts.snap b/libs/wingsdk/test/target-sim/__snapshots__/service.test.ts.snap index f47c105b1ca..8ec8e96fba0 100644 --- a/libs/wingsdk/test/target-sim/__snapshots__/service.test.ts.snap +++ b/libs/wingsdk/test/target-sim/__snapshots__/service.test.ts.snap @@ -45,35 +45,12 @@ return class Handler { "attrs": {}, "path": "root/my_service", "props": { + "autoStart": true, "environmentVariables": {}, "sourceCodeFile": ".wing/my_service_c815f66e.js", }, "type": "@winglang/sdk.cloud.Service", }, - { - "addr": "c845f08fe23811b5ba949f822a6bc3077a050f801b", - "attrs": {}, - "path": "root/my_service/Policy", - "props": { - "principal": "\${wsim#root/my_service#attrs.handle}", - "statements": [], - }, - "type": "@winglang/sdk.sim.Policy", - }, - { - "addr": "c810e24e6e3ab8b88ceddbbe1ac7323d46de30a969", - "attrs": {}, - "deps": [ - "root/my_service", - "root/my_service/Policy", - ], - "path": "root/my_service/Helper", - "props": { - "autoStart": true, - "service": "\${wsim#root/my_service#attrs.handle}", - }, - "type": "@winglang/sdk.sim.ServiceHelper", - }, ], "sdkVersion": "0.0.0", "types": { @@ -149,14 +126,6 @@ return class Handler { "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", @@ -171,32 +140,6 @@ return class Handler { "tree": { "children": { "my_service": { - "children": { - "Helper": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "hidden": true, - }, - "id": "Helper", - "path": "root/my_service/Helper", - }, - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/my_service/Policy", - }, - }, "constructInfo": { "fqn": "constructs.Construct", "version": "10.3.0", diff --git a/libs/wingsdk/test/target-sim/__snapshots__/table.test.ts.snap b/libs/wingsdk/test/target-sim/__snapshots__/table.test.ts.snap index 470f510adec..4ac0d3b25cd 100644 --- a/libs/wingsdk/test/target-sim/__snapshots__/table.test.ts.snap +++ b/libs/wingsdk/test/target-sim/__snapshots__/table.test.ts.snap @@ -113,14 +113,6 @@ exports[`can add row in preflight 2`] = ` "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", @@ -257,14 +249,6 @@ exports[`create a table 1`] = ` "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", @@ -411,14 +395,6 @@ exports[`get row 2`] = ` "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", @@ -563,14 +539,6 @@ exports[`insert row 2`] = ` "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", @@ -717,14 +685,6 @@ exports[`list table 2`] = ` "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", @@ -870,14 +830,6 @@ exports[`tryGet row 2`] = ` "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", @@ -1026,14 +978,6 @@ exports[`update row 2`] = ` "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", diff --git a/libs/wingsdk/test/target-sim/__snapshots__/test.test.ts.snap b/libs/wingsdk/test/target-sim/__snapshots__/test.test.ts.snap index 05c7d3fded0..9fa84c5ea50 100644 --- a/libs/wingsdk/test/target-sim/__snapshots__/test.test.ts.snap +++ b/libs/wingsdk/test/target-sim/__snapshots__/test.test.ts.snap @@ -55,16 +55,6 @@ async handle(event) { }, "type": "@winglang/sdk.std.TestRunner", }, - { - "addr": "c8e9f1ae266f81e04ffcbb951317b09fa72e8ad7cb", - "attrs": {}, - "path": "root/env0/test:my_test/Handler/Policy", - "props": { - "principal": "\${wsim#root/env0/test:my_test/Handler#attrs.handle}", - "statements": [], - }, - "type": "@winglang/sdk.sim.Policy", - }, ], "sdkVersion": "0.0.0", "types": { @@ -140,14 +130,6 @@ async handle(event) { "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", @@ -179,21 +161,6 @@ async handle(event) { "test:my_test": { "children": { "Handler": { - "children": { - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/env0/test:my_test/Handler/Policy", - }, - }, "constructInfo": { "fqn": "constructs.Construct", "version": "10.3.0", diff --git a/libs/wingsdk/test/target-sim/__snapshots__/topic-producer.test.ts.snap b/libs/wingsdk/test/target-sim/__snapshots__/topic-producer.test.ts.snap index 56a208842d6..22c43627674 100644 --- a/libs/wingsdk/test/target-sim/__snapshots__/topic-producer.test.ts.snap +++ b/libs/wingsdk/test/target-sim/__snapshots__/topic-producer.test.ts.snap @@ -2,23 +2,16 @@ exports[`publishing messages to topic 1`] = ` [ - "root/TopicTester/MyTopic started", "root/TopicTester/MyTopic/OnMessage0 started", - "root/TopicTester/MyTopic/Policy started", - "root/TopicTester/MyTopic/OnMessage0/Policy started", + "root/TopicTester/MyTopic started", "root/TopicTester/MyTopic/TopicEventMapping0 started", "root/TopicTester/Function started", - "root/TopicTester/Function/Policy started", "Publish (message=ABC).", - "Sending message (message=ABC, subscriber=sim-1).", + "Sending message (message=ABC, subscriber=sim-0).", "InvokeAsync (payload="ABC").", "Invoke (payload="ABC").", - "Message received", - "root/TopicTester/MyTopic/Policy stopped", - "root/TopicTester/MyTopic/OnMessage0/Policy stopped", "root/TopicTester/MyTopic/TopicEventMapping0 stopped", "root/TopicTester/MyTopic/OnMessage0 stopped", - "root/TopicTester/Function/Policy stopped", "root/TopicTester/Function stopped", "root/TopicTester/MyTopic stopped", ] diff --git a/libs/wingsdk/test/target-sim/__snapshots__/topic.test.ts.snap b/libs/wingsdk/test/target-sim/__snapshots__/topic.test.ts.snap index be384dbb3fb..f846cbccf14 100644 --- a/libs/wingsdk/test/target-sim/__snapshots__/topic.test.ts.snap +++ b/libs/wingsdk/test/target-sim/__snapshots__/topic.test.ts.snap @@ -15,16 +15,6 @@ exports[`create a topic 1`] = ` "props": {}, "type": "@winglang/sdk.cloud.Topic", }, - { - "addr": "c8635ef174eab9aa010e5bed09a712307a6b70e731", - "attrs": {}, - "path": "root/my_topic/Policy", - "props": { - "principal": "\${wsim#root/my_topic#attrs.handle}", - "statements": [], - }, - "type": "@winglang/sdk.sim.Policy", - }, ], "sdkVersion": "0.0.0", "types": { @@ -100,14 +90,6 @@ exports[`create a topic 1`] = ` "className": "EventMapping", "sourcePath": "/event-mapping.inflight.js", }, - "@winglang/sdk.sim.Policy": { - "className": "Policy", - "sourcePath": "/policy.inflight.js", - }, - "@winglang/sdk.sim.ServiceHelper": { - "className": "ServiceHelper", - "sourcePath": "/service.inflight.js", - }, "@winglang/sdk.sim.State": { "className": "State", "sourcePath": "/state.inflight.js", @@ -122,21 +104,6 @@ exports[`create a topic 1`] = ` "tree": { "children": { "my_topic": { - "children": { - "Policy": { - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.3.0", - }, - "display": { - "description": "A simulated resource policy", - "hidden": true, - "title": "Policy", - }, - "id": "Policy", - "path": "root/my_topic/Policy", - }, - }, "constructInfo": { "fqn": "constructs.Construct", "version": "10.3.0", diff --git a/libs/wingsdk/test/target-sim/app.test.ts b/libs/wingsdk/test/target-sim/app.test.ts index b071c6f0526..13ddf565a43 100644 --- a/libs/wingsdk/test/target-sim/app.test.ts +++ b/libs/wingsdk/test/target-sim/app.test.ts @@ -48,10 +48,7 @@ test("tests do not synthesize functions when test mode is off", async () => { await s.stop(); // THEN - expect(resources.sort()).toEqual([ - "root/Default/my_bucket", - "root/Default/my_bucket/Policy", - ]); + expect(resources.sort()).toEqual(["root/Default/my_bucket"]); }); test("tests are synthesized into individual environments when test mode is on", async () => { @@ -76,12 +73,8 @@ test("tests are synthesized into individual environments when test mode is on", expect(resources.sort()).toEqual([ "root/cloud.TestRunner", "root/env0/my_bucket", - "root/env0/my_bucket/Policy", "root/env0/test:my_test1/Handler", - "root/env0/test:my_test1/Handler/Policy", "root/env1/my_bucket", - "root/env1/my_bucket/Policy", "root/env1/test:my_test2/Handler", - "root/env1/test:my_test2/Handler/Policy", ]); }); diff --git a/libs/wingsdk/test/target-sim/bucket.test.ts b/libs/wingsdk/test/target-sim/bucket.test.ts index 5d07e2f1a34..959449fac72 100644 --- a/libs/wingsdk/test/target-sim/bucket.test.ts +++ b/libs/wingsdk/test/target-sim/bucket.test.ts @@ -39,9 +39,7 @@ test("update an object in bucket", async () => { // GIVEN const app = new SimApp(); const bucket = new cloud.Bucket(app, "my_bucket"); - const testInflight = Testing.makeHandler( - "async handle() { console.log('I am done'); }" - ); + const testInflight = Testing.makeHandler("async handle() {}"); bucket.onCreate(testInflight); const s = await app.startSimulator(); @@ -50,17 +48,13 @@ test("update an object in bucket", async () => { // WHEN await client.put(KEY, JSON.stringify({ msg: "Hello world 1!" })); + await waitUntilTraceCount(s, 4, (trace) => trace.data.message.includes(KEY)); await client.put(KEY, JSON.stringify({ msg: "Hello world 2!" })); - await waitUntilTraceCount(s, 1, (trace) => - trace.data.message.includes(`I am done`) - ); + await waitUntilTraceCount(s, 5, (trace) => trace.data.message.includes(KEY)); // THEN - await s.stop(); expect(listMessages(s)).toMatchSnapshot(); - // The bucket notification topic should only publish one message, since the - // second put() call counts as an update, not a create. - expect(listMessages(s).filter((m) => m.includes(`Publish`))).toHaveLength(1); + await s.stop(); }); test("bucket on event creates 3 topics, and sends the right event and key in the event handlers", async () => { @@ -337,7 +331,7 @@ test("get invalid object throws an error", async () => { await s.stop(); expect(listMessages(s)).toMatchSnapshot(); - expect(s.listTraces()[2].data.status).toEqual("failure"); + expect(s.listTraces()[1].data.status).toEqual("failure"); expect(app.snapshot()).toMatchSnapshot(); }); diff --git a/libs/wingsdk/test/target-sim/function.test.ts b/libs/wingsdk/test/target-sim/function.test.ts index d791254362c..a140e353e37 100644 --- a/libs/wingsdk/test/target-sim/function.test.ts +++ b/libs/wingsdk/test/target-sim/function.test.ts @@ -130,7 +130,7 @@ test("invoke function fails", async () => { await s.stop(); expect(listMessages(s)).toMatchSnapshot(); - expect(s.listTraces()[2].data.error).toMatchObject({ + expect(s.listTraces()[1].data.error).toMatchObject({ message: "Name must start with uppercase letter", }); expect(app.snapshot()).toMatchSnapshot(); @@ -190,13 +190,13 @@ test("invoke function with process.exit(1)", async () => { // WHEN const PAYLOAD = {}; await expect(client.invoke(JSON.stringify(PAYLOAD))).rejects.toThrow( - "Process exited with code 1, signal null" + "Process exited with code 1" ); // THEN await s.stop(); expect(listMessages(s)).toMatchSnapshot(); - expect(s.listTraces()[2].data.error).toMatchObject({ - message: "Process exited with code 1, signal null", + expect(s.listTraces()[1].data.error).toMatchObject({ + message: "Process exited with code 1", }); expect(app.snapshot()).toMatchSnapshot(); }); @@ -247,13 +247,5 @@ test("__dirname and __filename cannot be used within inflight code", async () => await dirnameInvoker(s); await filenameInvoker(s); - await s.stop(); - - expect( - listMessages(s).filter((m) => - m.includes( - "Warning: __dirname and __filename cannot be used within bundled cloud functions." - ) - ) - ).toHaveLength(2); + expect(listMessages(s)).toMatchSnapshot(); }); diff --git a/libs/wingsdk/test/target-sim/on-deploy.test.ts b/libs/wingsdk/test/target-sim/on-deploy.test.ts index a2df5e6042e..1aa9077b3fe 100644 --- a/libs/wingsdk/test/target-sim/on-deploy.test.ts +++ b/libs/wingsdk/test/target-sim/on-deploy.test.ts @@ -18,7 +18,7 @@ test("create an OnDeploy", async () => { attrs: { handle: expect.any(String), }, - deps: ["root/my_on_deploy/Function", "root/my_on_deploy/Function/Policy"], + deps: ["root/my_on_deploy/Function"], path: "root/my_on_deploy", addr: expect.any(String), props: { diff --git a/libs/wingsdk/test/target-sim/queue.test.ts b/libs/wingsdk/test/target-sim/queue.test.ts index 047e5ee6b4d..8941c55c0bc 100644 --- a/libs/wingsdk/test/target-sim/queue.test.ts +++ b/libs/wingsdk/test/target-sim/queue.test.ts @@ -369,6 +369,6 @@ test("push rejects empty message", async () => { await s.stop(); expect(listMessages(s)).toMatchSnapshot(); - expect(s.listTraces()[2].data.status).toEqual("failure"); + expect(s.listTraces()[1].data.status).toEqual("failure"); expect(app.snapshot()).toMatchSnapshot(); }); diff --git a/libs/wingsdk/test/target-sim/service.test.ts b/libs/wingsdk/test/target-sim/service.test.ts index 7848eacad36..b783cc91e63 100644 --- a/libs/wingsdk/test/target-sim/service.test.ts +++ b/libs/wingsdk/test/target-sim/service.test.ts @@ -32,6 +32,7 @@ test("create a service with on start method", async () => { props: { sourceCodeFile: expect.any(String), environmentVariables: {}, + autoStart: true, }, type: cloud.SERVICE_FQN, }); @@ -62,6 +63,7 @@ test("create a service with a on stop method", async () => { props: { sourceCodeFile: expect.any(String), environmentVariables: {}, + autoStart: true, }, type: cloud.SERVICE_FQN, }); @@ -74,8 +76,8 @@ test("create a service with a on stop method", async () => { .filter((v) => v.sourceType == cloud.SERVICE_FQN) .map((trace) => trace.data.message) ).toEqual([ - "root/my_service started", "start!", + "root/my_service started", "stop!", "root/my_service stopped", ]); @@ -104,6 +106,7 @@ test("create a service without autostart", async () => { props: { sourceCodeFile: expect.any(String), environmentVariables: {}, + autoStart: false, }, type: cloud.SERVICE_FQN, }); diff --git a/libs/wingsdk/test/target-sim/topic-producer.test.ts b/libs/wingsdk/test/target-sim/topic-producer.test.ts index afe43c76cb4..168ee5e95e7 100644 --- a/libs/wingsdk/test/target-sim/topic-producer.test.ts +++ b/libs/wingsdk/test/target-sim/topic-producer.test.ts @@ -1,6 +1,6 @@ import { Construct } from "constructs"; import { test, expect } from "vitest"; -import { listMessages, waitUntilTraceCount } from "./util"; +import { listMessages } from "./util"; import * as cloud from "../../src/cloud"; import { Testing } from "../../src/simulator"; import { SimApp } from "../sim-app"; @@ -27,7 +27,6 @@ test("publishing messages to topic", async () => { const processor = Testing.makeHandler(`async handle(event) { if (event.message === "") throw new Error("No message recieved"); - console.log("Message received"); }`); topic.onMessage(processor); } @@ -45,10 +44,6 @@ test("publishing messages to topic", async () => { // WHEN await publisher.invoke("ABC"); - await waitUntilTraceCount(s, 1, (trace) => - trace.data.message.includes("Message received") - ); - // THEN await s.stop(); diff --git a/libs/wingsdk/test/target-sim/util.ts b/libs/wingsdk/test/target-sim/util.ts index 07aab70729f..de8c41ed6fb 100644 --- a/libs/wingsdk/test/target-sim/util.ts +++ b/libs/wingsdk/test/target-sim/util.ts @@ -29,7 +29,7 @@ export interface IScopeCallback { (scope: Construct): void; } -export function listMessages(s: Simulator): string[] { +export function listMessages(s: Simulator) { const message = s.listTraces().map((trace) => trace.data.message); // Redact any messages containing port numbers return message.map((m) => diff --git a/libs/wingsdk/test/ui/__snapshots__/ui.test.ts.snap b/libs/wingsdk/test/ui/__snapshots__/ui.test.ts.snap index 8fb72eef1b3..013056fac0d 100644 --- a/libs/wingsdk/test/ui/__snapshots__/ui.test.ts.snap +++ b/libs/wingsdk/test/ui/__snapshots__/ui.test.ts.snap @@ -3,14 +3,10 @@ exports[`can obtain ui components 1`] = ` [ "root/MyClass/Button/Handler started", - "root/MyClass/Button/Handler/Policy started", "root/MyClass/Field/Handler started", - "root/MyClass/Field/Handler/Policy started", "Invoke (payload="").", "Invoke (payload="").", - "root/MyClass/Button/Handler/Policy stopped", "root/MyClass/Button/Handler stopped", - "root/MyClass/Field/Handler/Policy stopped", "root/MyClass/Field/Handler stopped", ] `; diff --git a/tools/hangar/__snapshots__/invalid.ts.snap b/tools/hangar/__snapshots__/invalid.ts.snap index b702359f151..c8bad3498a1 100644 --- a/tools/hangar/__snapshots__/invalid.ts.snap +++ b/tools/hangar/__snapshots__/invalid.ts.snap @@ -3546,32 +3546,6 @@ Test Files 1 failed (1) Duration " `; -exports[`simulator_permissions.test.w 1`] = ` -"fail ┌ simulator_permissions.test.wsim » root/env0/test:incorrect resource permission - │ Error: Resource \\"root/env0/test:incorrect resource permission/Handler\\" does not have permission to perform operation \\"put\\" on resource \\"root/env0/b1\\". - │ --> ../../../examples/tests/invalid/simulator_permissions.test.w:15:3 - │ | while i > 0 { - │ | i -= 1; - │ | } - │ 15 | buckets.at(i).put(\\"key\\", \\"value\\"); - │ | ^ - └ at /simulator_permissions.test.w:15:3 -fail ┌ simulator_permissions.test.wsim » root/env1/test:incorrect permission operation - │ Error: Resource \\"root/env1/test:incorrect permission operation/Handler\\" does not have permission to perform operation \\"put\\" on resource \\"root/env1/b1\\". - │ --> ../../../examples/tests/invalid/simulator_permissions.test.w:25:3 - │ | while i > 0 { - │ | i -= 1; - │ | } - │ 25 | buckets.at(i).put(\\"key\\", \\"value\\"); - │ | ^ - └ at /simulator_permissions.test.w:25:3 - - -Tests 2 failed (2) -Test Files 1 failed (1) -Duration " -`; - exports[`sorted_errors_no_span.test.w 1`] = ` "error: Expected type to be \\"num\\", but got \\"str\\" instead --> ../../../examples/tests/invalid/sorted_errors_no_span.test.w:1:14