create-arona-app 0.0.1-dev.ff9c398 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +11 -44
- package/bin/create-arona-app.js +115 -112
- package/package.json +23 -21
- package/templates/alchemy/README.md +17 -0
- package/templates/alchemy/alchemy.run.ts +16 -0
- package/templates/alchemy/package.json +28 -0
- package/templates/alchemy/src/counter.ts +38 -0
- package/templates/alchemy/src/register.ts +26 -0
- package/templates/alchemy/src/resources.ts +8 -0
- package/templates/alchemy/src/worker.ts +29 -0
- package/templates/alchemy/tsconfig.json +22 -0
- package/templates/counter/.env.example +3 -0
- package/templates/counter/README.md +17 -0
- package/templates/counter/package.json +21 -0
- package/templates/counter/src/index.ts +72 -0
- package/templates/counter/tsconfig.json +22 -0
- package/templates/counter/vite.config.ts +6 -0
- package/templates/default/.env.example +3 -0
- package/templates/default/package.json +14 -12
- package/templates/default/src/counter.ts +65 -0
- package/templates/default/src/index.ts +36 -14
- package/templates/default/tsconfig.json +20 -26
- package/templates/default/vite.config.ts +7 -0
- package/templates/rick-and-morty/.env.example +4 -0
- package/templates/rick-and-morty/package.json +15 -12
- package/templates/rick-and-morty/src/commands/search.ts +15 -0
- package/templates/rick-and-morty/src/components/search/character.ts +57 -0
- package/templates/rick-and-morty/src/components/search/index.ts +99 -0
- package/templates/rick-and-morty/src/components/search/pagination.ts +49 -0
- package/templates/rick-and-morty/src/components/search/search-form.ts +60 -0
- package/templates/rick-and-morty/src/components/search/status.ts +22 -0
- package/templates/rick-and-morty/src/index.ts +40 -14
- package/templates/rick-and-morty/src/queries/characters.ts +89 -0
- package/templates/rick-and-morty/tsconfig.json +20 -26
- package/templates/rick-and-morty/vite.config.ts +7 -0
- package/templates/serverless/README.md +17 -0
- package/templates/serverless/package.json +22 -0
- package/templates/serverless/src/counter.ts +39 -0
- package/templates/serverless/src/handler.ts +38 -0
- package/templates/serverless/src/index.ts +78 -0
- package/templates/serverless/src/register.ts +21 -0
- package/templates/serverless/tsconfig.json +22 -0
- package/templates/simple/.env.example +3 -0
- package/templates/simple/package.json +13 -12
- package/templates/simple/src/app.ts +147 -0
- package/templates/simple/src/index.ts +57 -0
- package/templates/simple/tsconfig.json +20 -26
- package/templates/simple/vite.config.ts +6 -0
- package/templates/slack/.env.example +3 -0
- package/templates/slack/README.md +17 -0
- package/templates/slack/package.json +22 -0
- package/templates/slack/src/app.ts +45 -0
- package/templates/slack/src/index.ts +43 -0
- package/templates/slack/tsconfig.json +22 -0
- package/templates/slack/vite.config.ts +6 -0
- package/templates/default/src/commands/counter/counter.tsx +0 -53
- package/templates/default/src/commands/counter/index.ts +0 -7
- package/templates/rick-and-morty/src/commands/rick-and-morty/app.tsx +0 -28
- package/templates/rick-and-morty/src/commands/rick-and-morty/components/character-display.tsx +0 -40
- package/templates/rick-and-morty/src/commands/rick-and-morty/components/character-search-modal.tsx +0 -34
- package/templates/rick-and-morty/src/commands/rick-and-morty/components/character-search.tsx +0 -29
- package/templates/rick-and-morty/src/commands/rick-and-morty/components/character-select.tsx +0 -36
- package/templates/rick-and-morty/src/commands/rick-and-morty/components/navigation.tsx +0 -58
- package/templates/rick-and-morty/src/commands/rick-and-morty/hooks/character-search-provider.tsx +0 -90
- package/templates/rick-and-morty/src/commands/rick-and-morty/hooks/useCharacters.ts +0 -38
- package/templates/rick-and-morty/src/commands/rick-and-morty/index.ts +0 -21
- package/templates/rick-and-morty/src/commands/rick-and-morty/types.ts +0 -24
- package/templates/simple/src/app.tsx +0 -38
- package/templates/simple/src/index.tsx +0 -33
|
@@ -1,17 +1,43 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { Telemetry } from "@arona/core";
|
|
2
|
+
import { layerFromEnv } from "@arona/devtools";
|
|
3
|
+
import { DiscordGatewayClient, Intent } from "@arona/platform-discord";
|
|
4
|
+
import * as SqliteStore from "@arona/store-sqlite";
|
|
5
|
+
import { NodeRuntime } from "@effect/platform-node";
|
|
6
|
+
import { Config, Effect, Layer } from "effect";
|
|
7
|
+
import { search } from "./commands/search";
|
|
4
8
|
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
const program = Effect.gen(function* () {
|
|
10
|
+
const config = yield* Config.all({
|
|
11
|
+
token: Config.Redacted("DISCORD_APP_TOKEN"),
|
|
12
|
+
clientId: Config.String("DISCORD_APP_ID"),
|
|
13
|
+
devGuildId: Config.option(Config.String("DISCORD_DEV_GUILD_ID")),
|
|
14
|
+
database: Config.String("ARONA_SQLITE_PATH").pipe(Config.withDefault(".arona/sessions.sqlite")),
|
|
15
|
+
});
|
|
11
16
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
})
|
|
17
|
+
return yield* Effect.gen(function* () {
|
|
18
|
+
const client = yield* DiscordGatewayClient;
|
|
15
19
|
|
|
16
|
-
client.
|
|
17
|
-
|
|
20
|
+
const user = yield* client.login;
|
|
21
|
+
yield* Effect.log(`🚀 Logged in as ${user.username}`);
|
|
22
|
+
return yield* Effect.never;
|
|
23
|
+
}).pipe(
|
|
24
|
+
Effect.provide(
|
|
25
|
+
DiscordGatewayClient.layer({
|
|
26
|
+
token: config.token,
|
|
27
|
+
clientId: config.clientId,
|
|
28
|
+
devGuildId: config.devGuildId,
|
|
29
|
+
intents: [Intent.Guilds],
|
|
30
|
+
commands: [search],
|
|
31
|
+
}).pipe(Layer.provide(SqliteStore.layer({ filename: config.database }))),
|
|
32
|
+
),
|
|
33
|
+
);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const telemetry =
|
|
37
|
+
process.env.NODE_ENV === "production"
|
|
38
|
+
? Telemetry.layerFromEnv
|
|
39
|
+
: Telemetry.layer({ console: true });
|
|
40
|
+
|
|
41
|
+
NodeRuntime.runMain(
|
|
42
|
+
program.pipe(Effect.scoped, Effect.provide(Layer.merge(telemetry, layerFromEnv()))),
|
|
43
|
+
);
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { Query } from "effect/ui";
|
|
2
|
+
import { Effect, Layer, Schema } from "effect";
|
|
3
|
+
import * as FetchHttpClient from "effect/http/FetchHttpClient";
|
|
4
|
+
import * as HttpClient from "effect/http/HttpClient";
|
|
5
|
+
import * as HttpClientResponse from "effect/http/HttpClientResponse";
|
|
6
|
+
|
|
7
|
+
const Character = Schema.Struct({
|
|
8
|
+
id: Schema.Finite,
|
|
9
|
+
name: Schema.String,
|
|
10
|
+
status: Schema.String,
|
|
11
|
+
species: Schema.String,
|
|
12
|
+
image: Schema.String,
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
export type Character = typeof Character.Type;
|
|
16
|
+
|
|
17
|
+
const PageMetadata = Schema.Struct({
|
|
18
|
+
count: Schema.Finite,
|
|
19
|
+
pages: Schema.Finite,
|
|
20
|
+
next: Schema.NullOr(Schema.String),
|
|
21
|
+
prev: Schema.NullOr(Schema.String),
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
export type PageMetadata = typeof PageMetadata.Type;
|
|
25
|
+
|
|
26
|
+
const SearchResult = Schema.Struct({
|
|
27
|
+
characters: Schema.Array(Character),
|
|
28
|
+
pageMetadata: Schema.NullOr(PageMetadata),
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
export type SearchResultValue = typeof SearchResult.Type;
|
|
32
|
+
|
|
33
|
+
const SearchResponse = Schema.Struct({
|
|
34
|
+
info: Schema.optional(PageMetadata),
|
|
35
|
+
results: Schema.optional(Schema.Array(Character)),
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const emptyResult: SearchResultValue = {
|
|
39
|
+
characters: [],
|
|
40
|
+
pageMetadata: null,
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/** One page of characters from the Rick and Morty API. */
|
|
44
|
+
export class SearchCharacters extends Query.Service<SearchCharacters>()(
|
|
45
|
+
"rick-and-morty/SearchCharacters",
|
|
46
|
+
{
|
|
47
|
+
args: { query: Schema.String, page: Schema.Finite },
|
|
48
|
+
success: SearchResult,
|
|
49
|
+
error: Schema.Never,
|
|
50
|
+
staleTime: "5 minutes",
|
|
51
|
+
},
|
|
52
|
+
) {
|
|
53
|
+
static readonly layer = this.toLayer(
|
|
54
|
+
Effect.gen(function* () {
|
|
55
|
+
const http = yield* HttpClient.HttpClient;
|
|
56
|
+
return ({ query, page }) =>
|
|
57
|
+
Effect.gen(function* () {
|
|
58
|
+
const response = yield* http.get(
|
|
59
|
+
`https://rickandmortyapi.com/api/character/?name=${encodeURIComponent(query)}&page=${page}`,
|
|
60
|
+
);
|
|
61
|
+
if (response.status === 404) return emptyResult;
|
|
62
|
+
if (response.status >= 400) {
|
|
63
|
+
yield* Effect.logWarning(
|
|
64
|
+
`Rick and Morty search returned HTTP ${response.status} for "${query}" page ${page}`,
|
|
65
|
+
);
|
|
66
|
+
return emptyResult;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const data = yield* HttpClientResponse.schemaBodyJson(SearchResponse)(response);
|
|
70
|
+
return {
|
|
71
|
+
characters: data.results ?? [],
|
|
72
|
+
pageMetadata: data.info ?? null,
|
|
73
|
+
};
|
|
74
|
+
}).pipe(
|
|
75
|
+
Effect.catchCause((cause) =>
|
|
76
|
+
Effect.logWarning(
|
|
77
|
+
`Rick and Morty search failed for "${query}" page ${page}`,
|
|
78
|
+
cause,
|
|
79
|
+
).pipe(Effect.as(emptyResult)),
|
|
80
|
+
),
|
|
81
|
+
);
|
|
82
|
+
}),
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** `SearchCharacters` provided with the platform fetch client. */
|
|
87
|
+
export const SearchCharactersLive = SearchCharacters.layer.pipe(
|
|
88
|
+
Layer.provide(FetchHttpClient.layer),
|
|
89
|
+
);
|
|
@@ -1,28 +1,22 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
// Some stricter flags (disabled by default)
|
|
24
|
-
"noUnusedLocals": false,
|
|
25
|
-
"noUnusedParameters": false,
|
|
26
|
-
"noPropertyAccessFromIndexSignature": false
|
|
27
|
-
}
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"lib": [
|
|
4
|
+
"ESNext"
|
|
5
|
+
],
|
|
6
|
+
"target": "ESNext",
|
|
7
|
+
"module": "ESNext",
|
|
8
|
+
"moduleDetection": "force",
|
|
9
|
+
"moduleResolution": "bundler",
|
|
10
|
+
"allowImportingTsExtensions": true,
|
|
11
|
+
"verbatimModuleSyntax": true,
|
|
12
|
+
"noEmit": true,
|
|
13
|
+
"strict": true,
|
|
14
|
+
"exactOptionalPropertyTypes": true,
|
|
15
|
+
"skipLibCheck": true,
|
|
16
|
+
"noFallthroughCasesInSwitch": true,
|
|
17
|
+
"noUncheckedIndexedAccess": true
|
|
18
|
+
},
|
|
19
|
+
"include": [
|
|
20
|
+
"src/**/*"
|
|
21
|
+
]
|
|
28
22
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import Arona from "@arona/core/vite";
|
|
2
|
+
import { DevToolsVite } from "@arona/devtools/node";
|
|
3
|
+
import { defineConfig } from "vite-plus";
|
|
4
|
+
|
|
5
|
+
export default defineConfig({
|
|
6
|
+
plugins: [Arona.plugin({ entry: "./src/index.ts" }), DevToolsVite.plugin({ dispatch: true })],
|
|
7
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# {{projectName}}
|
|
2
|
+
|
|
3
|
+
This project was created using [create-arona-app](https://github.com/djobbo/arona).
|
|
4
|
+
|
|
5
|
+
## Getting Started
|
|
6
|
+
|
|
7
|
+
First, install the dependencies:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
{{installCommand}}
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Then, run the development server:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
{{devCommand}}
|
|
17
|
+
```
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@arona-ex/serverless",
|
|
3
|
+
"private": true,
|
|
4
|
+
"description": "HTTP interactions with resumable Discord messages",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"module": "index.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"dev": "node --experimental-strip-types src/index.ts",
|
|
9
|
+
"register": "node --experimental-strip-types src/register.ts",
|
|
10
|
+
"check:types": "effect-tsgo tsrs --noEmit"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@arona/core": "0.0.2",
|
|
14
|
+
"@arona/platform-discord": "0.0.2",
|
|
15
|
+
"effect": "4.2.0"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@types/node": "^26.6.10",
|
|
19
|
+
"typescript": "^5.8.3",
|
|
20
|
+
"vite-plus": "1.8.0"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { UiSchema } from "effect/ui";
|
|
2
|
+
import { ActionRow, Button, Container, Text } from "@arona/platform-discord";
|
|
3
|
+
import * as Discord from "@arona/platform-discord";
|
|
4
|
+
import { SlashCommand } from "@arona/platform-discord";
|
|
5
|
+
import { Schema } from "effect";
|
|
6
|
+
|
|
7
|
+
const CounterMessage = UiSchema.TaggedEnum({ Clicked: {} });
|
|
8
|
+
|
|
9
|
+
export const Counter = Discord.component({
|
|
10
|
+
name: "Counter",
|
|
11
|
+
props: Schema.Struct({}),
|
|
12
|
+
model: Schema.Struct({ count: Schema.Finite }),
|
|
13
|
+
message: CounterMessage,
|
|
14
|
+
}).make({
|
|
15
|
+
init: () => ({ count: 0 }),
|
|
16
|
+
update: {
|
|
17
|
+
Clicked: ($) => $.evolve({ count: (count) => count + 1 }),
|
|
18
|
+
},
|
|
19
|
+
view: (h, model) =>
|
|
20
|
+
Container(h, {
|
|
21
|
+
children: [
|
|
22
|
+
Text(h, `# Count: ${model.count}`),
|
|
23
|
+
ActionRow(h, {
|
|
24
|
+
children: [
|
|
25
|
+
Button(h, {
|
|
26
|
+
style: "Primary",
|
|
27
|
+
onClick: CounterMessage.Clicked(),
|
|
28
|
+
children: ["Add one"],
|
|
29
|
+
}),
|
|
30
|
+
],
|
|
31
|
+
}),
|
|
32
|
+
],
|
|
33
|
+
}),
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
export const counter = SlashCommand.make("counter", {
|
|
37
|
+
description: "A resumable counter",
|
|
38
|
+
component: Counter,
|
|
39
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { FileStore } from "@arona/core/node";
|
|
2
|
+
import { DiscordRest, Interactions } from "@arona/platform-discord";
|
|
3
|
+
import { DiscordWorkerClient } from "@arona/platform-discord/worker";
|
|
4
|
+
import { Config, Effect, Layer } from "effect";
|
|
5
|
+
import { counter } from "./counter.ts";
|
|
6
|
+
|
|
7
|
+
/** Builds the client, REST, and interactions layers from configuration. */
|
|
8
|
+
export const layer = Layer.unwrap(
|
|
9
|
+
Effect.gen(function* () {
|
|
10
|
+
const config = yield* Config.all({
|
|
11
|
+
token: Config.Redacted("DISCORD_APP_TOKEN"),
|
|
12
|
+
publicKey: Config.NonEmptyString("DISCORD_PUBLIC_KEY"),
|
|
13
|
+
sessionDir: Config.String("ARONA_SESSION_DIR").pipe(Config.withDefault("./.arona/sessions")),
|
|
14
|
+
build: Config.option(Config.String("BUILD_ID")),
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const clientLayer = DiscordWorkerClient.layer({
|
|
18
|
+
build: config.build,
|
|
19
|
+
commands: [counter],
|
|
20
|
+
}).pipe(Layer.provide(FileStore.layerNode(config.sessionDir)));
|
|
21
|
+
|
|
22
|
+
return Interactions.layer({ publicKey: config.publicKey }).pipe(
|
|
23
|
+
Layer.provide(Layer.merge(clientLayer, DiscordRest.layerFetch({ token: config.token }))),
|
|
24
|
+
);
|
|
25
|
+
}),
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The Effect handler to export from a Vercel/Cloudflare/Node route.
|
|
30
|
+
*
|
|
31
|
+
* Inline mode keeps modals working. Set `defer: true` and a `background` hook
|
|
32
|
+
* when the work may exceed Discord's three-second acknowledgement deadline.
|
|
33
|
+
*/
|
|
34
|
+
export const handle = (request: Request) =>
|
|
35
|
+
Effect.gen(function* () {
|
|
36
|
+
const interactions = yield* Interactions;
|
|
37
|
+
return yield* interactions.handle(request);
|
|
38
|
+
});
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { createServer } from "node:http";
|
|
2
|
+
import { NodeRuntime } from "@effect/platform-node";
|
|
3
|
+
import { Config, Effect, ManagedRuntime } from "effect";
|
|
4
|
+
import { handle, layer } from "./handler.ts";
|
|
5
|
+
|
|
6
|
+
const readBody = async (request: import("node:http").IncomingMessage): Promise<Buffer> => {
|
|
7
|
+
const chunks: Buffer[] = [];
|
|
8
|
+
for await (const chunk of request) chunks.push(Buffer.from(chunk));
|
|
9
|
+
return Buffer.concat(chunks);
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const appendHeader = (
|
|
13
|
+
headers: Headers,
|
|
14
|
+
name: string,
|
|
15
|
+
value: string | string[] | undefined,
|
|
16
|
+
): void => {
|
|
17
|
+
if (Array.isArray(value)) {
|
|
18
|
+
for (const one of value) headers.append(name, one);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
if (value !== undefined) headers.set(name, value);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const headersOf = (request: import("node:http").IncomingMessage): Headers => {
|
|
25
|
+
const headers = new Headers();
|
|
26
|
+
for (const [name, value] of Object.entries(request.headers)) appendHeader(headers, name, value);
|
|
27
|
+
return headers;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const requestUrl = (request: import("node:http").IncomingMessage, port: number): string =>
|
|
31
|
+
`http://${request.headers.host ?? `localhost:${port}`}${request.url ?? "/"}`;
|
|
32
|
+
|
|
33
|
+
const toFetchRequest = async (
|
|
34
|
+
request: import("node:http").IncomingMessage,
|
|
35
|
+
port: number,
|
|
36
|
+
): Promise<Request> => {
|
|
37
|
+
const method = request.method ?? "POST";
|
|
38
|
+
const bodyless = method === "GET" || method === "HEAD";
|
|
39
|
+
return new Request(requestUrl(request, port), {
|
|
40
|
+
method,
|
|
41
|
+
headers: headersOf(request),
|
|
42
|
+
...(bodyless ? {} : { body: new Uint8Array(await readBody(request)) }),
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const program = Effect.gen(function* () {
|
|
47
|
+
const port = yield* Config.Number("PORT").pipe(Config.withDefault(3000));
|
|
48
|
+
const runtime = yield* Effect.acquireRelease(
|
|
49
|
+
Effect.sync(() => ManagedRuntime.make(layer)),
|
|
50
|
+
(managed) => managed.disposeEffect,
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
const server = createServer((request, response) => {
|
|
54
|
+
const run = async () => {
|
|
55
|
+
const fetched = await toFetchRequest(request, port);
|
|
56
|
+
const result = await runtime.runPromise(handle(fetched));
|
|
57
|
+
response.writeHead(result.status, Object.fromEntries(result.headers.entries()));
|
|
58
|
+
response.end(Buffer.from(await result.arrayBuffer()));
|
|
59
|
+
};
|
|
60
|
+
void run();
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
yield* Effect.acquireRelease(
|
|
64
|
+
Effect.sync(() =>
|
|
65
|
+
server.listen(port, () => {
|
|
66
|
+
console.log(`HTTP interaction endpoint listening on http://localhost:${port}/interactions`);
|
|
67
|
+
}),
|
|
68
|
+
),
|
|
69
|
+
(server) =>
|
|
70
|
+
Effect.sync(() => {
|
|
71
|
+
server.close();
|
|
72
|
+
}),
|
|
73
|
+
);
|
|
74
|
+
yield* Effect.log("Point Discord's Interactions Endpoint URL at the public URL for this route.");
|
|
75
|
+
return yield* Effect.never;
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
NodeRuntime.runMain(Effect.scoped(program));
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { DiscordRest, commandSummaries, reloadCommands } from "@arona/platform-discord";
|
|
2
|
+
import { NodeRuntime } from "@effect/platform-node";
|
|
3
|
+
import { Config, Effect } from "effect";
|
|
4
|
+
import { counter } from "./counter.ts";
|
|
5
|
+
|
|
6
|
+
const program = Effect.gen(function* () {
|
|
7
|
+
const config = yield* Config.all({
|
|
8
|
+
token: Config.Redacted("DISCORD_APP_TOKEN"),
|
|
9
|
+
clientId: Config.String("DISCORD_APP_ID"),
|
|
10
|
+
devGuildId: Config.option(Config.String("DISCORD_DEV_GUILD_ID")),
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
yield* Effect.log(`Registering ${commandSummaries([counter]).join(", ")}`);
|
|
14
|
+
yield* reloadCommands({
|
|
15
|
+
clientId: config.clientId,
|
|
16
|
+
devGuildId: config.devGuildId,
|
|
17
|
+
commands: [counter],
|
|
18
|
+
}).pipe(Effect.provide(DiscordRest.layerFetch({ token: config.token })));
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
NodeRuntime.runMain(program);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"lib": [
|
|
4
|
+
"ESNext"
|
|
5
|
+
],
|
|
6
|
+
"target": "ESNext",
|
|
7
|
+
"module": "ESNext",
|
|
8
|
+
"moduleDetection": "force",
|
|
9
|
+
"moduleResolution": "bundler",
|
|
10
|
+
"allowImportingTsExtensions": true,
|
|
11
|
+
"verbatimModuleSyntax": true,
|
|
12
|
+
"noEmit": true,
|
|
13
|
+
"strict": true,
|
|
14
|
+
"exactOptionalPropertyTypes": true,
|
|
15
|
+
"skipLibCheck": true,
|
|
16
|
+
"noFallthroughCasesInSwitch": true,
|
|
17
|
+
"noUncheckedIndexedAccess": true
|
|
18
|
+
},
|
|
19
|
+
"include": [
|
|
20
|
+
"src/**/*"
|
|
21
|
+
]
|
|
22
|
+
}
|
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arona-ex/simple",
|
|
3
|
+
"private": true,
|
|
3
4
|
"description": "A basic Arona app setup with essential features",
|
|
4
|
-
"module": "index.ts",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"
|
|
6
|
+
"module": "index.ts",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"dev": "
|
|
9
|
-
"build": "
|
|
10
|
-
|
|
11
|
-
"devDependencies": {
|
|
12
|
-
"@types/bun": "latest"
|
|
13
|
-
},
|
|
14
|
-
"peerDependencies": {
|
|
15
|
-
"typescript": "^5.8.3"
|
|
8
|
+
"dev": "vp build --watch --mode development",
|
|
9
|
+
"build": "vp build",
|
|
10
|
+
"check:types": "effect-tsgo tsrs --noEmit"
|
|
16
11
|
},
|
|
17
12
|
"dependencies": {
|
|
18
|
-
"@arona/
|
|
19
|
-
"@
|
|
13
|
+
"@arona/core": "0.0.2",
|
|
14
|
+
"@arona/platform-discord": "0.0.2",
|
|
15
|
+
"effect": "4.2.0"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@types/node": "^26.6.10",
|
|
19
|
+
"typescript": "^5.8.3",
|
|
20
|
+
"vite-plus": "1.8.0"
|
|
20
21
|
}
|
|
21
22
|
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { UiSchema } from "effect/ui";
|
|
2
|
+
import {
|
|
3
|
+
ActionRow,
|
|
4
|
+
Button,
|
|
5
|
+
Checkbox,
|
|
6
|
+
Container,
|
|
7
|
+
Label,
|
|
8
|
+
Modal,
|
|
9
|
+
Option,
|
|
10
|
+
RadioGroup,
|
|
11
|
+
RadioOption,
|
|
12
|
+
Section,
|
|
13
|
+
Select,
|
|
14
|
+
Separator,
|
|
15
|
+
Text,
|
|
16
|
+
TextInput,
|
|
17
|
+
} from "@arona/platform-discord";
|
|
18
|
+
import * as Discord from "@arona/platform-discord";
|
|
19
|
+
import { DateTime, Schema } from "effect";
|
|
20
|
+
|
|
21
|
+
const AppMessage = UiSchema.TaggedEnum({
|
|
22
|
+
ClickedIncrement: {},
|
|
23
|
+
ClickedOpenModal: {},
|
|
24
|
+
SubmittedModal: {
|
|
25
|
+
value: Schema.String,
|
|
26
|
+
newsletter: Schema.Boolean,
|
|
27
|
+
plan: Schema.String,
|
|
28
|
+
},
|
|
29
|
+
ChangedSelection: { values: Schema.Array(Schema.String) },
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const AppProps = Schema.Struct({ message: Schema.Struct({ content: Schema.String }) });
|
|
33
|
+
|
|
34
|
+
export const App = Discord.component({
|
|
35
|
+
name: "App",
|
|
36
|
+
props: AppProps,
|
|
37
|
+
model: Schema.Struct({
|
|
38
|
+
count: Schema.Finite,
|
|
39
|
+
modalOpen: Schema.Boolean,
|
|
40
|
+
selection: Schema.Array(Schema.String),
|
|
41
|
+
submitted: Schema.String,
|
|
42
|
+
newsletter: Schema.Boolean,
|
|
43
|
+
plan: Schema.String,
|
|
44
|
+
}),
|
|
45
|
+
message: AppMessage,
|
|
46
|
+
}).make({
|
|
47
|
+
init: () => ({
|
|
48
|
+
count: 0,
|
|
49
|
+
modalOpen: false,
|
|
50
|
+
selection: [],
|
|
51
|
+
submitted: "",
|
|
52
|
+
newsletter: false,
|
|
53
|
+
plan: "",
|
|
54
|
+
}),
|
|
55
|
+
update: {
|
|
56
|
+
ClickedIncrement: ($) => $.evolve({ count: (count) => count + 1 }),
|
|
57
|
+
ClickedOpenModal: ($) => $.evolve({ modalOpen: true }),
|
|
58
|
+
SubmittedModal: ($, message) =>
|
|
59
|
+
$.evolve({
|
|
60
|
+
modalOpen: false,
|
|
61
|
+
submitted: message.value,
|
|
62
|
+
newsletter: message.newsletter,
|
|
63
|
+
plan: message.plan,
|
|
64
|
+
}),
|
|
65
|
+
ChangedSelection: ($, message) => $.evolve({ selection: message.values }),
|
|
66
|
+
},
|
|
67
|
+
view: (h, model) => {
|
|
68
|
+
return Container(h, {
|
|
69
|
+
children: [
|
|
70
|
+
Text(h, `-# Original Message: \`${h.props.message.content}\``),
|
|
71
|
+
Section(h, {
|
|
72
|
+
accessory: Button(h, {
|
|
73
|
+
onClick: AppMessage.ClickedIncrement(),
|
|
74
|
+
children: ["Add One"],
|
|
75
|
+
}),
|
|
76
|
+
children: [Text(h, `# Count \`${model.count}\``)],
|
|
77
|
+
}),
|
|
78
|
+
ActionRow(h, {
|
|
79
|
+
children: [
|
|
80
|
+
Select(h, {
|
|
81
|
+
maxValues: 2,
|
|
82
|
+
onChange: (interaction) =>
|
|
83
|
+
AppMessage.ChangedSelection({ values: interaction.values }),
|
|
84
|
+
children: [
|
|
85
|
+
Option(h, { value: "1", label: "1" }),
|
|
86
|
+
Option(h, { value: "2", label: "2" }),
|
|
87
|
+
Option(h, { value: "3", label: "3", selected: true }),
|
|
88
|
+
],
|
|
89
|
+
}),
|
|
90
|
+
],
|
|
91
|
+
}),
|
|
92
|
+
ActionRow(h, {
|
|
93
|
+
children: [
|
|
94
|
+
Button(h, {
|
|
95
|
+
onClick: AppMessage.ClickedOpenModal(),
|
|
96
|
+
children: ["Open Modal"],
|
|
97
|
+
}),
|
|
98
|
+
],
|
|
99
|
+
}),
|
|
100
|
+
model.modalOpen
|
|
101
|
+
? Modal(h, {
|
|
102
|
+
title: "test",
|
|
103
|
+
onSubmit: (payload) =>
|
|
104
|
+
AppMessage.SubmittedModal({
|
|
105
|
+
value: payload.values.test ?? "",
|
|
106
|
+
newsletter: payload.checkboxes.newsletter ?? false,
|
|
107
|
+
plan: payload.radioGroups.plan ?? "",
|
|
108
|
+
}),
|
|
109
|
+
children: [
|
|
110
|
+
Text(h, "Fill the form"),
|
|
111
|
+
Label(h, {
|
|
112
|
+
label: "Test field",
|
|
113
|
+
description: "A text input inside a label",
|
|
114
|
+
children: [TextInput(h, { name: "test" })],
|
|
115
|
+
}),
|
|
116
|
+
Label(h, {
|
|
117
|
+
label: "Subscribe to the newsletter",
|
|
118
|
+
children: [Checkbox(h, { name: "newsletter" })],
|
|
119
|
+
}),
|
|
120
|
+
Label(h, {
|
|
121
|
+
label: "Plan",
|
|
122
|
+
children: [
|
|
123
|
+
RadioGroup(h, {
|
|
124
|
+
name: "plan",
|
|
125
|
+
children: [
|
|
126
|
+
RadioOption(h, { value: "free", label: "Free" }),
|
|
127
|
+
RadioOption(h, { value: "pro", label: "Pro", selected: true }),
|
|
128
|
+
],
|
|
129
|
+
}),
|
|
130
|
+
],
|
|
131
|
+
}),
|
|
132
|
+
],
|
|
133
|
+
})
|
|
134
|
+
: false,
|
|
135
|
+
Separator(h),
|
|
136
|
+
Text(h, `-# Updated At \`${DateTime.formatIso(DateTime.nowUnsafe())}\``),
|
|
137
|
+
model.submitted
|
|
138
|
+
? Text(
|
|
139
|
+
h,
|
|
140
|
+
`Submitted: \`${model.submitted}\` (plan: \`${model.plan}\`, newsletter: \`${model.newsletter}\`)`,
|
|
141
|
+
)
|
|
142
|
+
: false,
|
|
143
|
+
model.selection.length > 0 ? Text(h, `Selected: \`${model.selection.join(", ")}\``) : false,
|
|
144
|
+
],
|
|
145
|
+
});
|
|
146
|
+
},
|
|
147
|
+
});
|