Skip to content

Commit

Permalink
sync
Browse files Browse the repository at this point in the history
  • Loading branch information
thdxr committed Jan 12, 2024
1 parent a280615 commit 1ba65b9
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 7 deletions.
2 changes: 1 addition & 1 deletion examples/test/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ import { Resource } from "sst";
export function handler() {
return {
statusCode: 200,
body: JSON.stringify(Resource.StripeKey),
body: JSON.stringify(Resource.MyQueue),
};
}
12 changes: 11 additions & 1 deletion examples/test/sst.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,22 @@ export default $config({
};
},
async run() {
$linkable(aws.sqs.Queue, function () {
return {
type: `{ url: string }`,
value: {
url: this.url,
},
};
});

const bucket = new sst.Bucket("MyBucket");
const queue = new aws.sqs.Queue("MyQueue");
const secret = new sst.Secret("StripeKey");

const fn = new sst.Function("MyFunction", {
url: true,
link: [secret],
link: [queue, bucket, secret],
handler: "./src/index.handler",
});

Expand Down
2 changes: 1 addition & 1 deletion internal/components/src/components/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ export interface FunctionArgs {
*/
bind?: Input<ComponentResource>;

link?: Input<Linkable[]>;
link?: Input<any[]>;
/**
* Whether to enable streaming for the function.
* @default false
Expand Down
11 changes: 9 additions & 2 deletions internal/components/src/components/link.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Output } from "@pulumi/pulumi";
import { Input, Output, output } from "@pulumi/pulumi";
import fs from "node:fs";

export interface Link {
value: Output<any>;
value: Input<any>;
type: string;
}

Expand Down Expand Up @@ -55,3 +55,10 @@ export async function registerLinkType(reg: TypeRegistration) {
].join("\n"),
);
}

export function makeLinkable<T>(
obj: { new (...args: any[]): T },
cb: (this: T) => Link,
) {
obj.prototype.getSSTLink = cb;
}
9 changes: 8 additions & 1 deletion internal/components/src/global.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import "@types/node";
import "@pulumi/aws";
import "@pulumi/pulumi";
import * as util from "@pulumi/pulumi";
import "@pulumi/cloudflare";
import "./components/index";
import { $config as config, App } from "./config";
Expand All @@ -17,12 +18,18 @@ declare global {
export import cloudflare = require("@pulumi/cloudflare");

// @ts-expect-error
export import util = require("@pulumi/pulumi");
export import $util = require("@pulumi/pulumi");

// @ts-expect-error
export import sst = require("./components/index");

export const $config: typeof config;
export const $linkable: typeof import("./components/link").makeLinkable;

export const $output: typeof util.output;
export const $apply: typeof util.apply;
export const $all: typeof util.all;
export const $interpolate: typeof util.interpolate;

export const $app: Simplify<
Readonly<
Expand Down
9 changes: 8 additions & 1 deletion internal/components/src/shim/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@ import * as aws from "@pulumi/aws";
import * as cloudflare from "@pulumi/cloudflare";
import * as util from "@pulumi/pulumi";
import * as sst from "../components/";
import { makeLinkable } from "../components/link";
import { $config } from "../config";

const $secrets = JSON.parse(process.env.SST_SECRETS || "{}");
const { output, apply, all, interpolate } = util;

export {
makeLinkable as "$linkable",
output as "$output",
apply as "$apply",
all as "$all",
interpolate as "$interpolate",
util as "$util",
aws as "aws",
cloudflare as "cloudflare",
util as "util",
sst as "sst",
$config as "$config",
$secrets as "$secrets",
Expand Down

0 comments on commit 1ba65b9

Please sign in to comment.