Skip to content

Commit

Permalink
fix(sdk): revert lift/permissions errors are not caught in simulator (#…
Browse files Browse the repository at this point in the history
…6125)

Reverts #6079 due to a bug with hot-reloading in wing console.
To reproduce:
```ts
// main.w
bring cloud;

let api = new cloud.Api();

class Code {
  extern "search.js"
  inflight pub static handler(event: Json, ctx:Json): Json;
}

api.get("/search", inflight (req) => {
  return {
      status: 200,
      body: "Hello "
  };
  let event = MutJson {};
  let ctx = MutJson {};
  let result = Code.handler(event, ctx);
  return {

  };
});
```
```js
//search.js
export const handler = async (event, ctx) => {
    event.success = true;
    return {
        status: 200,
        body: JSON.stringify(event),
    }
};
```
  • Loading branch information
staycoolcall911 authored Apr 3, 2024
1 parent 0cdff2b commit 083f995
Show file tree
Hide file tree
Showing 84 changed files with 301 additions and 4,314 deletions.
224 changes: 2 additions & 222 deletions docs/docs/04-standard-library/sim/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,126 +126,6 @@ A token that resolves to the host port of this container.
---


### Policy <a name="Policy" id="@winglang/sdk.sim.Policy"></a>

- *Implements:* <a href="#@winglang/sdk.sim.ISimulatorResource">ISimulatorResource</a>

Implementation of `sim.Policy`.

#### Initializers <a name="Initializers" id="@winglang/sdk.sim.Policy.Initializer"></a>

```wing
bring sim;
new sim.Policy(props: PolicyProps);
```

| **Name** | **Type** | **Description** |
| --- | --- | --- |
| <code><a href="#@winglang/sdk.sim.Policy.Initializer.parameter.props">props</a></code> | <code><a href="#@winglang/sdk.sim.PolicyProps">PolicyProps</a></code> | *No description.* |

---

##### `props`<sup>Required</sup> <a name="props" id="@winglang/sdk.sim.Policy.Initializer.parameter.props"></a>

- *Type:* <a href="#@winglang/sdk.sim.PolicyProps">PolicyProps</a>

---

#### Methods <a name="Methods" id="Methods"></a>

| **Name** | **Description** |
| --- | --- |
| <code><a href="#@winglang/sdk.sim.Policy.addStatement">addStatement</a></code> | Adds a statement to the policy. |
| <code><a href="#@winglang/sdk.sim.Policy.toSimulator">toSimulator</a></code> | Convert this resource to a resource schema for the simulator. |

---

##### `addStatement` <a name="addStatement" id="@winglang/sdk.sim.Policy.addStatement"></a>

```wing
addStatement(resource: IResource, op: str): void
```

Adds a statement to the policy.

###### `resource`<sup>Required</sup> <a name="resource" id="@winglang/sdk.sim.Policy.addStatement.parameter.resource"></a>

- *Type:* <a href="#@winglang/sdk.std.IResource">IResource</a>

---

###### `op`<sup>Required</sup> <a name="op" id="@winglang/sdk.sim.Policy.addStatement.parameter.op"></a>

- *Type:* str

---

##### `toSimulator` <a name="toSimulator" id="@winglang/sdk.sim.Policy.toSimulator"></a>

```wing
toSimulator(): BaseResourceSchema
```

Convert this resource to a resource schema for the simulator.

#### Static Functions <a name="Static Functions" id="Static Functions"></a>

| **Name** | **Description** |
| --- | --- |
| <code><a href="#@winglang/sdk.sim.Policy.onLiftType">onLiftType</a></code> | A hook called by the Wing compiler once for each inflight host that needs to use this type inflight. |

---

##### `onLiftType` <a name="onLiftType" id="@winglang/sdk.sim.Policy.onLiftType"></a>

```wing
bring sim;
sim.Policy.onLiftType(host: IInflightHost, ops: MutArray<str>);
```

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`<sup>Required</sup> <a name="host" id="@winglang/sdk.sim.Policy.onLiftType.parameter.host"></a>

- *Type:* <a href="#@winglang/sdk.std.IInflightHost">IInflightHost</a>

---

###### `ops`<sup>Required</sup> <a name="ops" id="@winglang/sdk.sim.Policy.onLiftType.parameter.ops"></a>

- *Type:* MutArray&lt;str&gt;

---

#### Properties <a name="Properties" id="Properties"></a>

| **Name** | **Type** | **Description** |
| --- | --- | --- |
| <code><a href="#@winglang/sdk.sim.Policy.property.node">node</a></code> | <code>constructs.Node</code> | The tree node. |

---

##### `node`<sup>Required</sup> <a name="node" id="@winglang/sdk.sim.Policy.property.node"></a>

```wing
node: Node;
```

- *Type:* constructs.Node

The tree node.

---


### State <a name="State" id="@winglang/sdk.sim.State"></a>

- *Implements:* <a href="#@winglang/sdk.sim.ISimulatorResource">ISimulatorResource</a>
Expand Down Expand Up @@ -556,115 +436,15 @@ A glob of local files to consider as input sources for the container, relative t

---

### PolicyProps <a name="PolicyProps" id="@winglang/sdk.sim.PolicyProps"></a>

Options for `sim.Policy`.

#### Initializer <a name="Initializer" id="@winglang/sdk.sim.PolicyProps.Initializer"></a>

```wing
bring sim;
let PolicyProps = sim.PolicyProps{ ... };
```

#### Properties <a name="Properties" id="Properties"></a>

| **Name** | **Type** | **Description** |
| --- | --- | --- |
| <code><a href="#@winglang/sdk.sim.PolicyProps.property.principal">principal</a></code> | <code><a href="#@winglang/sdk.std.IResource">IResource</a></code> | The resource to which the policy is attached. |

---

##### `principal`<sup>Required</sup> <a name="principal" id="@winglang/sdk.sim.PolicyProps.property.principal"></a>

```wing
principal: IResource;
```

- *Type:* <a href="#@winglang/sdk.std.IResource">IResource</a>

The resource to which the policy is attached.

---

## Protocols <a name="Protocols" id="Protocols"></a>

### IPolicyClient <a name="IPolicyClient" id="@winglang/sdk.sim.IPolicyClient"></a>

- *Implemented By:* <a href="#@winglang/sdk.sim.IPolicyClient">IPolicyClient</a>

Inflight interface for `Policy`.



### ISimulatorInflightHost <a name="ISimulatorInflightHost" id="@winglang/sdk.sim.ISimulatorInflightHost"></a>

- *Extends:* <a href="#@winglang/sdk.std.IInflightHost">IInflightHost</a>

- *Implemented By:* <a href="#@winglang/sdk.sim.ISimulatorInflightHost">ISimulatorInflightHost</a>

Interfaces shared by all preflight classes that host inflight code.

#### Methods <a name="Methods" id="Methods"></a>

| **Name** | **Description** |
| --- | --- |
| <code><a href="#@winglang/sdk.sim.ISimulatorInflightHost.addPermission">addPermission</a></code> | Add a simulated permission to this inflight host. |

---

##### `addPermission` <a name="addPermission" id="@winglang/sdk.sim.ISimulatorInflightHost.addPermission"></a>

```wing
addPermission(resource: IResource, op: str): void
```

Add a simulated permission to this inflight host.

###### `resource`<sup>Required</sup> <a name="resource" id="@winglang/sdk.sim.ISimulatorInflightHost.addPermission.parameter.resource"></a>

- *Type:* <a href="#@winglang/sdk.std.IResource">IResource</a>

The resource to add.

---

###### `op`<sup>Required</sup> <a name="op" id="@winglang/sdk.sim.ISimulatorInflightHost.addPermission.parameter.op"></a>

- *Type:* str

The action to add.

---

#### Properties <a name="Properties" id="Properties"></a>

| **Name** | **Type** | **Description** |
| --- | --- | --- |
| <code><a href="#@winglang/sdk.sim.ISimulatorInflightHost.property.node">node</a></code> | <code>constructs.Node</code> | The tree node. |

---

##### `node`<sup>Required</sup> <a name="node" id="@winglang/sdk.sim.ISimulatorInflightHost.property.node"></a>

```wing
node: Node;
```

- *Type:* constructs.Node

The tree node.

---

### ISimulatorResource <a name="ISimulatorResource" id="@winglang/sdk.sim.ISimulatorResource"></a>

- *Extends:* <a href="#@winglang/sdk.std.IResource">IResource</a>

- *Implemented By:* <a href="#@winglang/sdk.sim.Container">Container</a>, <a href="#@winglang/sdk.sim.Policy">Policy</a>, <a href="#@winglang/sdk.sim.State">State</a>, <a href="#@winglang/sdk.sim.ISimulatorResource">ISimulatorResource</a>
- *Implemented By:* <a href="#@winglang/sdk.sim.Container">Container</a>, <a href="#@winglang/sdk.sim.State">State</a>, <a href="#@winglang/sdk.sim.ISimulatorResource">ISimulatorResource</a>

Interfaces shared by all preflight classes targeting the simulator.
Interfaces shared by all polycon implementations (preflight classes) targeting the simulator.

#### Methods <a name="Methods" id="Methods"></a>

Expand Down
26 changes: 0 additions & 26 deletions examples/tests/invalid/simulator_permissions.test.w

This file was deleted.

2 changes: 1 addition & 1 deletion examples/tests/sdk_tests/service/callbacks.test.w
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ if util.env("WING_TARGET") == "sim" {
assert(startCounter.peek() == 0);
assert(b.get(status) == stopped);
}
}
}
2 changes: 1 addition & 1 deletion libs/wingsdk/src/cloud/bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
4 changes: 2 additions & 2 deletions libs/wingsdk/src/shared/sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
16 changes: 2 additions & 14 deletions libs/wingsdk/src/simulator/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,7 @@ function makeHttpRequest(options: HttpRequestOptions): Promise<string> {
});
}

/**
* 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

Expand All @@ -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,
Expand Down
Loading

0 comments on commit 083f995

Please sign in to comment.