Skip to content

Commit

Permalink
nextjs: fix revalidation queue parent
Browse files Browse the repository at this point in the history
  • Loading branch information
fwang committed May 29, 2024
1 parent 19cf1a9 commit d87e37d
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 26 deletions.
13 changes: 12 additions & 1 deletion examples/aws-nextjs/sst-env.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
/// <reference path="./.sst/types.generated.ts" />
/* tslint:disable */
/* eslint-disable */
import "sst"
declare module "sst" {
export interface Resource {
MyBucket: {
name: string
type: "sst.aws.Bucket"
}
}
}
export {}
4 changes: 3 additions & 1 deletion pkg/platform/src/components/aws/nextjs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,7 @@ export class Nextjs extends Component implements Link.Linkable {
if (!revalidationFunction) return;

const queue = new Queue(
`${name}RevalidationQueue`,
`${name}RevalidationEvents`,
{
fifo: true,
transform: {
Expand Down Expand Up @@ -969,6 +969,7 @@ export class Nextjs extends Component implements Link.Linkable {
],
live: false,
_ignoreCodeChanges: $dev,
_skipMetadata: true,
},
{
transform: {
Expand All @@ -977,6 +978,7 @@ export class Nextjs extends Component implements Link.Linkable {
},
},
},
{ parent },
);
return queue;
},
Expand Down
23 changes: 16 additions & 7 deletions pkg/platform/src/components/aws/queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ export interface QueueSubscriberArgs {
*/
export class Queue
extends Component
implements Link.Linkable, Link.AWS.Linkable {
implements Link.Linkable, Link.AWS.Linkable
{
private constructorName: string;
private queue: aws.sqs.Queue;
private isSubscribed: boolean = false;
Expand Down Expand Up @@ -247,6 +248,7 @@ export class Queue
public subscribe(
subscriber: string | FunctionArgs,
args?: QueueSubscriberArgs,
opts?: ComponentResourceOptions,
) {
if (this.isSubscribed)
throw new VisibleError(
Expand All @@ -259,6 +261,7 @@ export class Queue
this.arn,
subscriber,
args,
opts,
);
}

Expand Down Expand Up @@ -310,30 +313,36 @@ export class Queue
queueArn: Input<string>,
subscriber: string | FunctionArgs,
args?: QueueSubscriberArgs,
opts?: ComponentResourceOptions,
) {
const queueName = output(queueArn).apply(
(queueArn) => parseQueueArn(queueArn).queueName,
);
return this._subscribeFunction(queueName, queueArn, subscriber, args);
return this._subscribeFunction(queueName, queueArn, subscriber, args, opts);
}

private static _subscribeFunction(
name: Input<string>,
queueArn: Input<string>,
subscriber: string | FunctionArgs,
args: QueueSubscriberArgs = {},
opts?: ComponentResourceOptions,
) {
return all([name, queueArn]).apply(([name, queueArn]) => {
const prefix = sanitizeToPascalCase(name);
const suffix = sanitizeToPascalCase(
hashStringToPrettyString(queueArn, 6),
);

return new QueueLambdaSubscriber(`${prefix}Subscriber${suffix}`, {
queue: { arn: queueArn },
subscriber,
...args,
});
return new QueueLambdaSubscriber(
`${prefix}Subscriber${suffix}`,
{
queue: { arn: queueArn },
subscriber,
...args,
},
opts,
);
});
}

Expand Down
21 changes: 16 additions & 5 deletions www/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,16 @@ try {
else if (sourceFile.endsWith("/dns.ts")) await generateDnsDoc(component);
else {
const sdkName = component.name.split("/")[2];
const sdk = sdks.find((s) => s.name === sdkName);
await generateComponentDoc(component, sdk);
const sdk = sdks.find(
(s) =>
// ie. vector
s.name === sdkName ||
// ie. aws/realtime
s.name === `aws/${sdkName}`
);
const sdkNamespace = sdk && useModuleOrNamespace(sdk);
// Handle SDK modules are namespaced (ie. aws/realtime)
await generateComponentDoc(component, sdkNamespace);
}
}
}
Expand Down Expand Up @@ -863,8 +871,6 @@ function renderType(
}
}

/** Helps with rendering Components */

function renderVariables(module: TypeDoc.DeclarationReflection) {
const lines: string[] = [];
const vars = (module.children ?? []).filter(
Expand Down Expand Up @@ -1560,6 +1566,11 @@ function useModuleFunctions(module: TypeDoc.DeclarationReflection) {
.getChildrenByKind(TypeDoc.ReflectionKind.Function)
.filter((f) => !f.signatures![0].comment?.modifierTags.has("@internal"));
}
function useModuleOrNamespace(module: TypeDoc.DeclarationReflection) {
// Handle SDK modules are namespaced (ie. aws/realtime)
const namespaces = module.getChildrenByKind(TypeDoc.ReflectionKind.Namespace);
return namespaces.length ? namespaces[0] : module;
}
function useClass(module: TypeDoc.DeclarationReflection) {
const c = module.getChildrenByKind(TypeDoc.ReflectionKind.Class);
if (!c.length) throw new Error("Class not found");
Expand Down Expand Up @@ -1795,7 +1806,7 @@ async function buildSdk() {
defaultTag: false,
},
entryPoints: [
"../sdk/js/src/realtime/index.ts",
"../sdk/js/src/aws/realtime.ts",
"../sdk/js/src/vector/index.ts",
],
tsconfig: "../sdk/js/tsconfig.json",
Expand Down
6 changes: 4 additions & 2 deletions www/src/content/docs/docs/component/aws/queue.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ The SQS queue URL.
<Segment>
<Section type="signature">
```ts
subscribe(subscriber, args?)
subscribe(subscriber, args?, opts?)
```
</Section>
Expand All @@ -198,6 +198,7 @@ subscribe(subscriber, args?)
The function that'll be notified.
- <p><code class="key">args?</code> [<code class="type">QueueSubscriberArgs</code>](#queuesubscriberargs)</p>
Configure the subscription.
- <p><code class="key">opts?</code> [<code class="type">ComponentResourceOptions</code>](https://www.pulumi.com/docs/concepts/options/)</p>
</Section>
<InlineSection>
Expand Down Expand Up @@ -237,7 +238,7 @@ queue.subscribe({
<Segment>
<Section type="signature">
```ts
Queue.subscribe(queueArn, subscriber, args?)
Queue.subscribe(queueArn, subscriber, args?, opts?)
```
</Section>
Expand All @@ -249,6 +250,7 @@ The ARN of the SQS queue to subscribe to.
The function that'll be notified.
- <p><code class="key">args?</code> [<code class="type">QueueSubscriberArgs</code>](#queuesubscriberargs)</p>
Configure the subscription.
- <p><code class="key">opts?</code> [<code class="type">ComponentResourceOptions</code>](https://www.pulumi.com/docs/concepts/options/)</p>
</Section>
<InlineSection>
Expand Down
20 changes: 10 additions & 10 deletions www/src/content/docs/docs/component/aws/realtime.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -199,17 +199,17 @@ The IoT endpoint.
</Section>
</Segment>
### RealtimeAuthHandler
### authorizer
<Segment>
<Section type="signature">
```ts
RealtimeAuthHandler(input)
authorizer(input)
```
</Section>
<Section type="parameters">
#### Parameters
- <p><code class="key">input</code> <code class="primitive">(token: <code class="primitive">string</code>) => <code class="primitive">Promise</code><code class="symbol">&lt;</code>[<code class="type">RealtimeAuthResult</code>](#realtimeauthresult)<code class="symbol">&gt;</code></code></p>
- <p><code class="key">input</code> <code class="primitive">(token: <code class="primitive">string</code>) => <code class="primitive">Promise</code><code class="symbol">&lt;</code>[<code class="type">AuthResult</code>](#authresult)<code class="symbol">&gt;</code></code></p>
</Section>
<InlineSection>
Expand All @@ -219,9 +219,9 @@ Creates an authorization handler for the `Realtime` component, that validates
the token and grants permissions for the topics the client can subscribe and publish to.
```js
import { RealtimeAuthHandler, Resource } from "sst";
import { realtime } from "sst/aws/realtime";

export const handler = RealtimeAuthHandler(async (token) => {
export const handler = realtime.authorizer(async (token) => {
// Validate the token
console.log(token);

Expand All @@ -233,17 +233,17 @@ export const handler = RealtimeAuthHandler(async (token) => {
});
```
</Segment>
### RealtimeAuthResult
### AuthResult
<Segment>
<Section type="parameters">
<InlineSection>
**Type** <code class="primitive">Object</code>
</InlineSection>
- <p>[<code class="key">publish?</code>](#realtimeauthresult-publish)</p>
- <p>[<code class="key">subscribe?</code>](#realtimeauthresult-subscribe)</p>
- <p>[<code class="key">publish?</code>](#authresult-publish)</p>
- <p>[<code class="key">subscribe?</code>](#authresult-subscribe)</p>
</Section>
</Segment>
<NestedTitle id="realtimeauthresult-publish" Tag="h4" parent="RealtimeAuthResult.">publish?</NestedTitle>
<NestedTitle id="authresult-publish" Tag="h4" parent="AuthResult.">publish?</NestedTitle>
<Segment>
<Section type="parameters">
<InlineSection>
Expand All @@ -265,7 +265,7 @@ And to publish to all topics under a specific prefix.
}
```
</Segment>
<NestedTitle id="realtimeauthresult-subscribe" Tag="h4" parent="RealtimeAuthResult.">subscribe?</NestedTitle>
<NestedTitle id="authresult-subscribe" Tag="h4" parent="AuthResult.">subscribe?</NestedTitle>
<Segment>
<Section type="parameters">
<InlineSection>
Expand Down

0 comments on commit d87e37d

Please sign in to comment.