@homeflare/alchemy 0.30.0 → 0.31.0
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/README.md +22 -0
- package/dist/discord/application-command.d.ts +52 -0
- package/dist/discord/application-command.d.ts.map +1 -0
- package/dist/discord/command-form.d.ts +62 -0
- package/dist/discord/command-form.d.ts.map +1 -0
- package/dist/discord/credentials.d.ts +35 -0
- package/dist/discord/credentials.d.ts.map +1 -0
- package/dist/discord/fake-discord.d.ts +44 -0
- package/dist/discord/fake-discord.d.ts.map +1 -0
- package/dist/discord/guild-application-command.d.ts +53 -0
- package/dist/discord/guild-application-command.d.ts.map +1 -0
- package/dist/discord/index.d.ts +12 -0
- package/dist/discord/index.d.ts.map +1 -0
- package/dist/discord/index.js +193 -0
- package/dist/discord/index.js.map +15 -0
- package/dist/discord/providers.d.ts +15 -0
- package/dist/discord/providers.d.ts.map +1 -0
- package/dist/discord/resource.d.ts +75 -0
- package/dist/discord/resource.d.ts.map +1 -0
- package/docs/credentials.md +9 -0
- package/docs/discord.md +129 -0
- package/docs/upstream-conformance.md +17 -1
- package/package.json +5 -1
- package/src/discord/application-command.test.ts +103 -0
- package/src/discord/application-command.ts +109 -0
- package/src/discord/command-form.test.ts +144 -0
- package/src/discord/command-form.ts +133 -0
- package/src/discord/credentials.ts +36 -0
- package/src/discord/fake-discord.ts +70 -0
- package/src/discord/guild-application-command.test.ts +215 -0
- package/src/discord/guild-application-command.ts +129 -0
- package/src/discord/index.ts +31 -0
- package/src/discord/providers.ts +18 -0
- package/src/discord/resource.ts +164 -0
- package/src/discord/retry.test.ts +74 -0
package/README.md
CHANGED
|
@@ -249,6 +249,28 @@ endpoint lives in ONE `general_settings` field (a whole-list read-modify-write),
|
|
|
249
249
|
declared in `config.yaml` is refused rather than silently overridden, and a literal secret in a
|
|
250
250
|
forwarded header is refused at plan: [docs/litellm.md](./docs/litellm.md).
|
|
251
251
|
|
|
252
|
+
## Discord — `@homeflare/alchemy/discord`
|
|
253
|
+
|
|
254
|
+
`Discord.ApplicationCommand` (global) and `Discord.GuildApplicationCommand` (guild-scoped)
|
|
255
|
+
declare a slash/user/message command, generated from Discord API v10 via
|
|
256
|
+
`@distilled.cloud/discord`. `reconcile` is one upsert call — Discord's own create endpoint
|
|
257
|
+
overwrites a command with the same name. ⛔ `read` answers `Unowned` on every match (never a
|
|
258
|
+
silent adopt — `adopt(true)` is on by default on both constructors), and declaring
|
|
259
|
+
`Discord.GuildApplicationCommand` against a guild `hf-discord-halibut.service` still
|
|
260
|
+
self-registers into fights the bot, not replaces it: [docs/discord.md](./docs/discord.md).
|
|
261
|
+
|
|
262
|
+
```ts
|
|
263
|
+
import { applicationCommand, guildApplicationCommand, providers } from '@homeflare/alchemy/discord';
|
|
264
|
+
|
|
265
|
+
export const help =
|
|
266
|
+
yield *
|
|
267
|
+
applicationCommand('help', {
|
|
268
|
+
applicationId: '123456789012345678',
|
|
269
|
+
name: 'help',
|
|
270
|
+
description: 'Show available commands',
|
|
271
|
+
});
|
|
272
|
+
```
|
|
273
|
+
|
|
252
274
|
## Google Workspace — `@homeflare/alchemy/google-workspace`
|
|
253
275
|
|
|
254
276
|
`Group`, `GroupMember`, `DomainAlias` and `OrgUnit` over the Admin SDK Directory API, generated
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Resource } from 'alchemy';
|
|
2
|
+
import * as Provider from 'alchemy/Provider';
|
|
3
|
+
import * as command from '@distilled.cloud/discord/discord';
|
|
4
|
+
import type { DiscordOpError } from '@distilled.cloud/discord/Protocol';
|
|
5
|
+
import * as Effect from 'effect/Effect';
|
|
6
|
+
import { type CommandFields, type CommandFieldsAttributes } from './command-form.ts';
|
|
7
|
+
import type { DiscordRequirements, DiscordSpec } from './resource.ts';
|
|
8
|
+
export interface ApplicationCommandProps extends CommandFields {
|
|
9
|
+
/** The Discord application (bot) this command belongs to — a public snowflake, not a secret. */
|
|
10
|
+
applicationId: string;
|
|
11
|
+
}
|
|
12
|
+
export interface ApplicationCommandAttributes extends CommandFieldsAttributes {
|
|
13
|
+
commandId: string;
|
|
14
|
+
applicationId: string;
|
|
15
|
+
version: string;
|
|
16
|
+
}
|
|
17
|
+
export interface DiscordApplicationCommand extends Resource<'Discord.ApplicationCommand', ApplicationCommandProps, ApplicationCommandAttributes, never, DiscordRequirements> {
|
|
18
|
+
}
|
|
19
|
+
export declare const DiscordApplicationCommand: import("alchemy").ResourceClass<DiscordApplicationCommand>;
|
|
20
|
+
export declare const isDiscordApplicationCommand: (value: unknown) => value is DiscordApplicationCommand;
|
|
21
|
+
/** Exported for direct testing against `fake-discord.ts` — the same seam `../netbox/prefix.ts` uses. */
|
|
22
|
+
export declare const spec: DiscordSpec<ApplicationCommandProps, command.ApplicationCommandResponse, ApplicationCommandAttributes, DiscordOpError>;
|
|
23
|
+
export declare const handlers: {
|
|
24
|
+
list: () => Effect.Effect<never[], never, never>;
|
|
25
|
+
read: ({ olds, output }: {
|
|
26
|
+
olds: ApplicationCommandProps;
|
|
27
|
+
output: ApplicationCommandAttributes | undefined;
|
|
28
|
+
}) => Effect.Effect<ApplicationCommandAttributes | undefined, DiscordOpError, import("effect/unstable/http/HttpClient").HttpClient>;
|
|
29
|
+
diff: ({ news, output }: {
|
|
30
|
+
news: import("alchemy").Input<ApplicationCommandProps>;
|
|
31
|
+
output: ApplicationCommandAttributes | undefined;
|
|
32
|
+
}) => Effect.Effect<{
|
|
33
|
+
readonly action: 'update';
|
|
34
|
+
} | {
|
|
35
|
+
readonly action: 'noop';
|
|
36
|
+
} | undefined, DiscordOpError, import("effect/unstable/http/HttpClient").HttpClient>;
|
|
37
|
+
reconcile: ({ news }: {
|
|
38
|
+
news: ApplicationCommandProps;
|
|
39
|
+
}) => Effect.Effect<ApplicationCommandAttributes, DiscordOpError, import("effect/unstable/http/HttpClient").HttpClient>;
|
|
40
|
+
delete: ({ olds }: {
|
|
41
|
+
olds: ApplicationCommandProps;
|
|
42
|
+
}) => Effect.Effect<void, DiscordOpError, import("effect/unstable/http/HttpClient").HttpClient>;
|
|
43
|
+
};
|
|
44
|
+
export declare const DiscordApplicationCommandProvider: () => import("effect/Layer").Layer<Provider.Provider<DiscordApplicationCommand>, never, import("effect/unstable/http/HttpClient").HttpClient>;
|
|
45
|
+
/**
|
|
46
|
+
* `applicationCommand('help', { applicationId, name: 'help', description: '…' })` — `adopt(true)`
|
|
47
|
+
* piped on by default (H5), so a first deploy against a command that already exists silently
|
|
48
|
+
* takes it over instead of failing `OwnedBySomeoneElse`. Mirrors `cloudflare/website.ts`'s
|
|
49
|
+
* `astroWebsite`/`viteWebsite` convenience constructors.
|
|
50
|
+
*/
|
|
51
|
+
export declare const applicationCommand: (id: string, props: ApplicationCommandProps) => Effect.Effect<DiscordApplicationCommand, never, import("effect/unstable/http/HttpClient").HttpClient>;
|
|
52
|
+
//# sourceMappingURL=application-command.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"application-command.d.ts","sourceRoot":"","sources":["../../src/discord/application-command.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,KAAK,QAAQ,MAAM,kBAAkB,CAAC;AAC7C,OAAO,KAAK,OAAO,MAAM,kCAAkC,CAAC;AAC5D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AACxE,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,uBAAuB,EAI7B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,mBAAmB,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAGtE,MAAM,WAAW,uBAAwB,SAAQ,aAAa;IAC5D,gGAAgG;IAChG,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,4BAA6B,SAAQ,uBAAuB;IAC3E,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,yBAA0B,SAAQ,QAAQ,CACzD,4BAA4B,EAC5B,uBAAuB,EACvB,4BAA4B,EAC5B,KAAK,EACL,mBAAmB,CACpB;CAAG;AAEJ,eAAO,MAAM,yBAAyB,4DAMrC,CAAC;AAEF,eAAO,MAAM,2BAA2B,UAAW,OAAO,KAAG,KAAK,IAAI,yBAGD,CAAC;AAStE,wGAAwG;AACxG,eAAO,MAAM,IAAI,EAAE,WAAW,CAC5B,uBAAuB,EACvB,OAAO,CAAC,0BAA0B,EAClC,4BAA4B,EAC5B,cAAc,CAiBf,CAAC;AAEF,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;CAAwB,CAAC;AAE9C,eAAO,MAAM,iCAAiC,+IAI3C,CAAC;AAEJ;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,OAAQ,MAAM,SAAS,uBAAuB,0GACrB,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/** Fields every Discord command shares, independent of global vs. guild scope. */
|
|
2
|
+
export interface CommandFields {
|
|
3
|
+
readonly name: string;
|
|
4
|
+
readonly description?: string;
|
|
5
|
+
/**
|
|
6
|
+
* ⚠️ GAP: passed through opaquely, not re-modeled. The SDK's generated option union is ~40
|
|
7
|
+
* nested schema types (subcommand, subcommand group, string/int/number/channel/role/user/
|
|
8
|
+
* mentionable/attachment, each with its own choices and localizations) — see
|
|
9
|
+
* `docs/upstream-conformance.md#discord`. A caller supplies the exact wire shape from
|
|
10
|
+
* Discord's own docs; this resource neither validates nor transforms it.
|
|
11
|
+
*/
|
|
12
|
+
readonly options?: readonly Record<string, unknown>[];
|
|
13
|
+
/** Bitfield, stringified, per Discord's real wire contract (the SDK types write as `number`). */
|
|
14
|
+
readonly defaultMemberPermissions?: string;
|
|
15
|
+
readonly dmPermission?: boolean;
|
|
16
|
+
readonly contexts?: readonly number[];
|
|
17
|
+
readonly integrationTypes?: readonly number[];
|
|
18
|
+
readonly nsfw?: boolean;
|
|
19
|
+
/** `ApplicationCommandType`; omitted means `1` (`CHAT_INPUT`), Discord's own default. */
|
|
20
|
+
readonly type?: number;
|
|
21
|
+
}
|
|
22
|
+
export interface CommandFieldsAttributes {
|
|
23
|
+
readonly name: string;
|
|
24
|
+
readonly description: string;
|
|
25
|
+
readonly options: readonly Record<string, unknown>[];
|
|
26
|
+
readonly defaultMemberPermissions: string | undefined;
|
|
27
|
+
readonly dmPermission: boolean | undefined;
|
|
28
|
+
readonly contexts: readonly number[] | undefined;
|
|
29
|
+
readonly integrationTypes: readonly number[] | undefined;
|
|
30
|
+
readonly nsfw: boolean;
|
|
31
|
+
readonly type: number;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* ⛔ SENT IN FULL ON EVERY UPSERT, NEVER PARTIAL. Discord's create-as-upsert (resource.ts's own
|
|
35
|
+
* note) replaces the whole command, so a body that omitted a field the caller stopped declaring
|
|
36
|
+
* would never actually clear it — the same "declared, then forgotten" bug `prefix-form.ts`
|
|
37
|
+
* documents for NetBox's PATCH. Sending the full settled shape every time is what keeps a
|
|
38
|
+
* removed prop actually removed live, not just removed from the declaration.
|
|
39
|
+
*/
|
|
40
|
+
export declare const commandBody: (props: CommandFields) => Record<string, unknown>;
|
|
41
|
+
/** Whether the live command already says what the declaration says. */
|
|
42
|
+
export declare const commandMatches: (attributes: CommandFieldsAttributes, props: CommandFields) => boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Reads the shared fields off any `ApplicationCommandResponse`-shaped object.
|
|
45
|
+
*
|
|
46
|
+
* ⚠️ `options` IS READ AS `readonly unknown[]`, NOT RE-TYPED. The SDK's real
|
|
47
|
+
* `ApplicationCommandResponseOptionsItem` union has no index signature (each option kind is a
|
|
48
|
+
* distinct generated interface), so it cannot structurally satisfy `Record<string, unknown>`
|
|
49
|
+
* without a cast — the same "opaque passthrough" gap `CommandFields.options` documents above.
|
|
50
|
+
*/
|
|
51
|
+
export declare const commandFieldsOf: (live: {
|
|
52
|
+
readonly name: string;
|
|
53
|
+
readonly description: string;
|
|
54
|
+
readonly options?: readonly unknown[] | null | undefined;
|
|
55
|
+
readonly default_member_permissions?: string | null | undefined;
|
|
56
|
+
readonly dm_permission?: boolean | undefined;
|
|
57
|
+
readonly contexts?: readonly number[] | null | undefined;
|
|
58
|
+
readonly integration_types?: readonly number[] | null | undefined;
|
|
59
|
+
readonly nsfw?: boolean | undefined;
|
|
60
|
+
readonly type: number;
|
|
61
|
+
}) => CommandFieldsAttributes;
|
|
62
|
+
//# sourceMappingURL=command-form.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command-form.d.ts","sourceRoot":"","sources":["../../src/discord/command-form.ts"],"names":[],"mappings":"AAQA,kFAAkF;AAClF,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B;;;;;;OAMG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC;IACtD,iGAAiG;IACjG,QAAQ,CAAC,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAC3C,QAAQ,CAAC,YAAY,CAAC,EAAE,OAAO,CAAC;IAChC,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACtC,QAAQ,CAAC,gBAAgB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC9C,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC;IACxB,yFAAyF;IACzF,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,OAAO,EAAE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,KAAG,uBAUF,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Discord credentials — a bot token REFERENCE, resolved lazily (S24), never a prop.
|
|
3
|
+
*
|
|
4
|
+
* ⛔ NO TOKEN IS EVER A PROP OR AN ATTRIBUTE. Alchemy persists Attributes unencrypted
|
|
5
|
+
* (State/StateEncoding.ts@v2.0.0-beta.79#encodeState), so nothing a stack file holds may be a
|
|
6
|
+
* credential. `@distilled.cloud/discord/Credentials` already ships exactly the shape S24 asks
|
|
7
|
+
* for: `Credentials` is a lazy `Context.Service<Credentials, Effect.Effect<Config>>`, resolved
|
|
8
|
+
* on the calling fiber inside each operation (`DiscordProtocol`'s `credentials:` field), never
|
|
9
|
+
* at layer build. This file re-exports it rather than re-implementing it — the same choice
|
|
10
|
+
* `../netbox/resource.ts` made for `CredentialsFromEnv` — and adds only the house-specific
|
|
11
|
+
* naming and doc trail.
|
|
12
|
+
*
|
|
13
|
+
* ★ `CredentialsFromEnv` reads `DISCORD_BOT_TOKEN` (falling back to `DISCORD_TOKEN`) via Effect's
|
|
14
|
+
* `Config`, which is exactly the "reference" shape S25 asks for: the resource never sees the
|
|
15
|
+
* value, only the environment variable NAME is anywhere near a stack file, and the value itself
|
|
16
|
+
* is wrapped in `Redacted` the moment it is read.
|
|
17
|
+
*
|
|
18
|
+
* ⚠️ NO OpenBao MINT YET. H8's target (`Alchemy.Stack({ secrets })`) is unreleased (PR 1728, still
|
|
19
|
+
* on `main` only). Until the estate is on a release that carries it, the deploy process's own
|
|
20
|
+
* environment is the credential seam — a human or CI job exports `DISCORD_BOT_TOKEN` from
|
|
21
|
+
* wherever it mints it (on CT100 today: `/opt/homeflare/env/discord-halibut.env`, read by
|
|
22
|
+
* systemd's `EnvironmentFile=`, never by this package). This package never reads that file.
|
|
23
|
+
*/
|
|
24
|
+
import type { Config } from '@distilled.cloud/discord/Credentials';
|
|
25
|
+
import { Credentials, CredentialsFromEnv, credentials } from '@distilled.cloud/discord/Credentials';
|
|
26
|
+
/** Re-exported so a consumer never has to reach into `@distilled.cloud/discord` by hand. */
|
|
27
|
+
export { Credentials, CredentialsFromEnv, credentials };
|
|
28
|
+
export type { Config as DiscordCredentialsConfig };
|
|
29
|
+
/**
|
|
30
|
+
* `DiscordCredentials.fromEnv()` — the layer every `discordProviders()` stack uses by default.
|
|
31
|
+
* A thin, named alias over `CredentialsFromEnv` so a stack's import reads `Discord.*`
|
|
32
|
+
* throughout, the way `../netbox/index.ts`'s barrel keeps `Netbox*` names at the front door.
|
|
33
|
+
*/
|
|
34
|
+
export declare const fromEnv: () => import("effect/Layer").Layer<Credentials, never, never>;
|
|
35
|
+
//# sourceMappingURL=credentials.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credentials.d.ts","sourceRoot":"","sources":["../../src/discord/credentials.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,sCAAsC,CAAC;AACnE,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,sCAAsC,CAAC;AAEpG,4FAA4F;AAC5F,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,WAAW,EAAE,CAAC;AACxD,YAAY,EAAE,MAAM,IAAI,wBAAwB,EAAE,CAAC;AAEnD;;;;GAIG;AACH,eAAO,MAAM,OAAO,+DAA2B,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A minimal in-memory Discord REST API for this family's tests — an in-memory `fetch` handed to
|
|
3
|
+
* Effect's real `FetchHttpClient` through its `Fetch` reference, mirroring `../netbox/fake-netbox.ts`
|
|
4
|
+
* (itself mirroring `../forgejo/fake-forgejo.ts` and `cloudflare/fake-mesh.ts`). Tests exercise
|
|
5
|
+
* distilled's REAL path assembly, JSON encode/decode, status→typed-error matching AND its retry
|
|
6
|
+
* policy — nothing about any of that is re-implemented here, only the wire responses a scenario
|
|
7
|
+
* needs, including a `429` with a `Retry-After` header for the bounded-retry test.
|
|
8
|
+
*
|
|
9
|
+
* ⛔ TEST-ONLY, AND NO NETWORK. No provider imports this file. The base URL is RFC 2606
|
|
10
|
+
* `discord.example.com`, and the token is a placeholder.
|
|
11
|
+
*/
|
|
12
|
+
import { type Credentials } from '@distilled.cloud/discord/Credentials';
|
|
13
|
+
import * as Layer from 'effect/Layer';
|
|
14
|
+
export declare const FAKE_BASE = "https://discord.example.com";
|
|
15
|
+
export declare const FAKE_TOKEN = "placeholder-discord-token";
|
|
16
|
+
export type Seen = {
|
|
17
|
+
readonly method: string;
|
|
18
|
+
readonly path: string;
|
|
19
|
+
readonly body: unknown;
|
|
20
|
+
};
|
|
21
|
+
/** Discord's `{ code, message }` failure envelope — matching `protocol.ts`'s `errorEnvelope`. */
|
|
22
|
+
export declare const fakeFailure: (status: number, code: number, message: string, headers?: Record<string, string>) => Response;
|
|
23
|
+
/** A `429` with `Retry-After` in seconds, Discord's real shape for a rate-limited response. */
|
|
24
|
+
export declare const fakeRateLimited: (retryAfterSeconds: number) => Response;
|
|
25
|
+
/**
|
|
26
|
+
* `route` decides every response; this wrapper only records what was sent and adapts to
|
|
27
|
+
* `globalThis.fetch`'s signature. A test that expects no request at all asserts `seen` is empty.
|
|
28
|
+
*/
|
|
29
|
+
export declare const fakeDiscord: (route: (method: string, url: URL, body: unknown, callNumber: number) => Response) => {
|
|
30
|
+
fetch: typeof fetch;
|
|
31
|
+
seen: Seen[];
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* distilled Credentials + the real FetchHttpClient over the fake — `DiscordOpContext`, what every
|
|
35
|
+
* resource file's exported `spec.fetchByName`/`spec.upsert`/`spec.destroy` needs.
|
|
36
|
+
*
|
|
37
|
+
* ⚠️ NOT PAIRED WITH `handlers` (each resource file's `discordHandlers(spec)` export). `handlers`
|
|
38
|
+
* bakes in `CredentialsFromEnv`, which resolves through Effect's `Config` snapshot of
|
|
39
|
+
* `process.env` — the same seam `../netbox/fake-netbox.ts` documents as untestable against a
|
|
40
|
+
* fake server. So a test calls `spec.fetchByName`/`spec.upsert`/`spec.destroy` directly, with
|
|
41
|
+
* this explicit layer, exercising exactly the same production code without that env seam.
|
|
42
|
+
*/
|
|
43
|
+
export declare const fakeDiscordLayer: (fetchFn: typeof globalThis.fetch, creds?: Layer.Layer<Credentials>) => Layer.Layer<Credentials | import("effect/unstable/http/HttpClient").HttpClient, never, never>;
|
|
44
|
+
//# sourceMappingURL=fake-discord.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fake-discord.d.ts","sourceRoot":"","sources":["../../src/discord/fake-discord.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,KAAK,WAAW,EAAe,MAAM,sCAAsC,CAAC;AACrF,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAGtC,eAAO,MAAM,SAAS,gCAAgC,CAAC;AACvD,eAAO,MAAM,UAAU,8BAA8B,CAAC;AAEtD,MAAM,MAAM,IAAI,GAAG;IAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC;AAE9F,iGAAiG;AACjG,eAAO,MAAM,WAAW,WACd,MAAM,QACR,MAAM,WACH,MAAM,YACL,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,aAC6D,CAAC;AAEhG,+FAA+F;AAC/F,eAAO,MAAM,eAAe,sBAAuB,MAAM,aAGrD,CAAC;AAEL;;;GAGG;AACH,eAAO,MAAM,WAAW,UACf,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,KAAK,QAAQ;;;CAejF,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,gBAAgB,YAClB,OAAO,UAAU,CAAC,KAAK,UACzB,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,kGAC+D,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Resource } from 'alchemy';
|
|
2
|
+
import * as Provider from 'alchemy/Provider';
|
|
3
|
+
import * as command from '@distilled.cloud/discord/discord';
|
|
4
|
+
import type { DiscordOpError } from '@distilled.cloud/discord/Protocol';
|
|
5
|
+
import * as Effect from 'effect/Effect';
|
|
6
|
+
import { type CommandFields, type CommandFieldsAttributes } from './command-form.ts';
|
|
7
|
+
import type { DiscordRequirements, DiscordSpec } from './resource.ts';
|
|
8
|
+
export interface GuildApplicationCommandProps extends CommandFields {
|
|
9
|
+
/** The Discord application (bot) this command belongs to — a public snowflake, not a secret. */
|
|
10
|
+
applicationId: string;
|
|
11
|
+
/** The guild (server) this command is scoped to — a public snowflake. */
|
|
12
|
+
guildId: string;
|
|
13
|
+
}
|
|
14
|
+
export interface GuildApplicationCommandAttributes extends CommandFieldsAttributes {
|
|
15
|
+
commandId: string;
|
|
16
|
+
applicationId: string;
|
|
17
|
+
guildId: string;
|
|
18
|
+
version: string;
|
|
19
|
+
}
|
|
20
|
+
export interface DiscordGuildApplicationCommand extends Resource<'Discord.GuildApplicationCommand', GuildApplicationCommandProps, GuildApplicationCommandAttributes, never, DiscordRequirements> {
|
|
21
|
+
}
|
|
22
|
+
export declare const DiscordGuildApplicationCommand: import("alchemy").ResourceClass<DiscordGuildApplicationCommand>;
|
|
23
|
+
export declare const isDiscordGuildApplicationCommand: (value: unknown) => value is DiscordGuildApplicationCommand;
|
|
24
|
+
/** Exported for direct testing against `fake-discord.ts`. */
|
|
25
|
+
export declare const spec: DiscordSpec<GuildApplicationCommandProps, command.ApplicationCommandResponse, GuildApplicationCommandAttributes, DiscordOpError>;
|
|
26
|
+
export declare const handlers: {
|
|
27
|
+
list: () => Effect.Effect<never[], never, never>;
|
|
28
|
+
read: ({ olds, output }: {
|
|
29
|
+
olds: GuildApplicationCommandProps;
|
|
30
|
+
output: GuildApplicationCommandAttributes | undefined;
|
|
31
|
+
}) => Effect.Effect<GuildApplicationCommandAttributes | undefined, DiscordOpError, import("effect/unstable/http/HttpClient").HttpClient>;
|
|
32
|
+
diff: ({ news, output }: {
|
|
33
|
+
news: import("alchemy").Input<GuildApplicationCommandProps>;
|
|
34
|
+
output: GuildApplicationCommandAttributes | undefined;
|
|
35
|
+
}) => Effect.Effect<{
|
|
36
|
+
readonly action: 'update';
|
|
37
|
+
} | {
|
|
38
|
+
readonly action: 'noop';
|
|
39
|
+
} | undefined, DiscordOpError, import("effect/unstable/http/HttpClient").HttpClient>;
|
|
40
|
+
reconcile: ({ news }: {
|
|
41
|
+
news: GuildApplicationCommandProps;
|
|
42
|
+
}) => Effect.Effect<GuildApplicationCommandAttributes, DiscordOpError, import("effect/unstable/http/HttpClient").HttpClient>;
|
|
43
|
+
delete: ({ olds }: {
|
|
44
|
+
olds: GuildApplicationCommandProps;
|
|
45
|
+
}) => Effect.Effect<void, DiscordOpError, import("effect/unstable/http/HttpClient").HttpClient>;
|
|
46
|
+
};
|
|
47
|
+
export declare const DiscordGuildApplicationCommandProvider: () => import("effect/Layer").Layer<Provider.Provider<DiscordGuildApplicationCommand>, never, import("effect/unstable/http/HttpClient").HttpClient>;
|
|
48
|
+
/**
|
|
49
|
+
* `guildApplicationCommand('ping', { applicationId, guildId, name: 'ping' })` — `adopt(true)`
|
|
50
|
+
* piped on by default (H5). See the file header before pointing this at a guild Halibut manages.
|
|
51
|
+
*/
|
|
52
|
+
export declare const guildApplicationCommand: (id: string, props: GuildApplicationCommandProps) => Effect.Effect<DiscordGuildApplicationCommand, never, import("effect/unstable/http/HttpClient").HttpClient>;
|
|
53
|
+
//# sourceMappingURL=guild-application-command.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guild-application-command.d.ts","sourceRoot":"","sources":["../../src/discord/guild-application-command.ts"],"names":[],"mappings":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A4B,+GAC1B,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Discord providers for Alchemy.
|
|
3
|
+
*
|
|
4
|
+
* ⛔ THIS BARREL IS THE PUBLIC API, AND IT IS DELIBERATELY SMALLER THAN THE DIRECTORY. `resource.ts`
|
|
5
|
+
* and `command-form.ts` are internals both resource files share — a consumer builds against the
|
|
6
|
+
* two commands and `providers()`, not the engine underneath.
|
|
7
|
+
*/
|
|
8
|
+
export { applicationCommand, DiscordApplicationCommand, DiscordApplicationCommandProvider, isDiscordApplicationCommand, type ApplicationCommandAttributes, type ApplicationCommandProps, } from './application-command.ts';
|
|
9
|
+
export { Credentials, CredentialsFromEnv, type DiscordCredentialsConfig, credentials, fromEnv, } from './credentials.ts';
|
|
10
|
+
export { guildApplicationCommand, DiscordGuildApplicationCommand, DiscordGuildApplicationCommandProvider, isDiscordGuildApplicationCommand, type GuildApplicationCommandAttributes, type GuildApplicationCommandProps, } from './guild-application-command.ts';
|
|
11
|
+
export { providers } from './providers.ts';
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/discord/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EACL,kBAAkB,EAClB,yBAAyB,EACzB,iCAAiC,EACjC,2BAA2B,EAC3B,KAAK,4BAA4B,EACjC,KAAK,uBAAuB,GAC7B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,KAAK,wBAAwB,EAC7B,WAAW,EACX,OAAO,GACR,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,uBAAuB,EACvB,8BAA8B,EAC9B,sCAAsC,EACtC,gCAAgC,EAChC,KAAK,iCAAiC,EACtC,KAAK,4BAA4B,GAClC,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
// src/discord/application-command.ts
|
|
2
|
+
import { adopt } from "alchemy/AdoptPolicy";
|
|
3
|
+
import { Resource } from "alchemy";
|
|
4
|
+
import * as Provider from "alchemy/Provider";
|
|
5
|
+
import * as command from "@distilled.cloud/discord/discord";
|
|
6
|
+
import * as Effect2 from "effect/Effect";
|
|
7
|
+
|
|
8
|
+
// src/discord/command-form.ts
|
|
9
|
+
import { deepEqual } from "alchemy/Diff";
|
|
10
|
+
var DEFAULT_TYPE = 1;
|
|
11
|
+
var settled = (props) => ({
|
|
12
|
+
description: props.description ?? "",
|
|
13
|
+
nsfw: props.nsfw ?? false,
|
|
14
|
+
type: props.type ?? DEFAULT_TYPE
|
|
15
|
+
});
|
|
16
|
+
var commandBody = (props) => {
|
|
17
|
+
const fixed = settled(props);
|
|
18
|
+
const out = {
|
|
19
|
+
description: fixed.description,
|
|
20
|
+
name: props.name,
|
|
21
|
+
nsfw: fixed.nsfw,
|
|
22
|
+
type: fixed.type
|
|
23
|
+
};
|
|
24
|
+
if (props.options !== undefined)
|
|
25
|
+
out["options"] = props.options;
|
|
26
|
+
if (props.defaultMemberPermissions !== undefined) {
|
|
27
|
+
out["default_member_permissions"] = props.defaultMemberPermissions;
|
|
28
|
+
}
|
|
29
|
+
if (props.dmPermission !== undefined)
|
|
30
|
+
out["dm_permission"] = props.dmPermission;
|
|
31
|
+
if (props.contexts !== undefined)
|
|
32
|
+
out["contexts"] = props.contexts;
|
|
33
|
+
if (props.integrationTypes !== undefined)
|
|
34
|
+
out["integration_types"] = props.integrationTypes;
|
|
35
|
+
return out;
|
|
36
|
+
};
|
|
37
|
+
var commandMatches = (attributes, props) => {
|
|
38
|
+
const fixed = settled(props);
|
|
39
|
+
return attributes.name === props.name && attributes.description === fixed.description && attributes.nsfw === fixed.nsfw && attributes.type === fixed.type && (props.options === undefined || deepEqual(attributes.options, props.options)) && (props.defaultMemberPermissions === undefined || attributes.defaultMemberPermissions === props.defaultMemberPermissions) && (props.dmPermission === undefined || attributes.dmPermission === props.dmPermission) && (props.contexts === undefined || deepEqual(attributes.contexts, props.contexts)) && (props.integrationTypes === undefined || deepEqual(attributes.integrationTypes, props.integrationTypes));
|
|
40
|
+
};
|
|
41
|
+
var commandFieldsOf = (live) => ({
|
|
42
|
+
contexts: live.contexts ?? undefined,
|
|
43
|
+
defaultMemberPermissions: live.default_member_permissions ?? undefined,
|
|
44
|
+
description: live.description,
|
|
45
|
+
dmPermission: live.dm_permission,
|
|
46
|
+
integrationTypes: live.integration_types ?? undefined,
|
|
47
|
+
name: live.name,
|
|
48
|
+
nsfw: live.nsfw === true,
|
|
49
|
+
options: live.options ?? [],
|
|
50
|
+
type: live.type
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
// src/discord/resource.ts
|
|
54
|
+
import { Unowned } from "alchemy/AdoptPolicy";
|
|
55
|
+
import { isResolved } from "alchemy/Diff";
|
|
56
|
+
import * as Effect from "effect/Effect";
|
|
57
|
+
|
|
58
|
+
// src/discord/credentials.ts
|
|
59
|
+
import { Credentials, CredentialsFromEnv, credentials } from "@distilled.cloud/discord/Credentials";
|
|
60
|
+
var fromEnv = () => CredentialsFromEnv;
|
|
61
|
+
|
|
62
|
+
// src/discord/resource.ts
|
|
63
|
+
var discordOperations = (spec) => ({
|
|
64
|
+
read: ({ olds, output }) => Effect.gen(function* () {
|
|
65
|
+
const live = yield* spec.fetchByName(olds);
|
|
66
|
+
if (live === undefined)
|
|
67
|
+
return;
|
|
68
|
+
const attrs = spec.attributes(live);
|
|
69
|
+
if (output !== undefined)
|
|
70
|
+
return attrs;
|
|
71
|
+
return Unowned(attrs);
|
|
72
|
+
}),
|
|
73
|
+
diff: (news, output) => Effect.gen(function* () {
|
|
74
|
+
if (output === undefined || !isResolved(news))
|
|
75
|
+
return;
|
|
76
|
+
const live = yield* spec.fetchByName(news);
|
|
77
|
+
if (live === undefined)
|
|
78
|
+
return { action: "update" };
|
|
79
|
+
return spec.matches(spec.attributes(live), news) ? { action: "noop" } : { action: "update" };
|
|
80
|
+
}),
|
|
81
|
+
reconcile: (news) => Effect.gen(function* () {
|
|
82
|
+
const before = yield* spec.fetchByName(news);
|
|
83
|
+
if (before !== undefined && spec.matches(spec.attributes(before), news)) {
|
|
84
|
+
return spec.attributes(before);
|
|
85
|
+
}
|
|
86
|
+
const body = spec.upsertBody(news);
|
|
87
|
+
const after = yield* spec.upsert(news, body);
|
|
88
|
+
return spec.attributes(after);
|
|
89
|
+
}),
|
|
90
|
+
destroy: (olds) => Effect.gen(function* () {
|
|
91
|
+
const live = yield* spec.fetchByName(olds);
|
|
92
|
+
if (live === undefined)
|
|
93
|
+
return;
|
|
94
|
+
yield* spec.destroy(olds, live);
|
|
95
|
+
})
|
|
96
|
+
});
|
|
97
|
+
var discordHandlers = (spec) => {
|
|
98
|
+
const ops = discordOperations(spec);
|
|
99
|
+
const withCredentials = (effect) => Effect.provide(effect, CredentialsFromEnv);
|
|
100
|
+
return {
|
|
101
|
+
list: () => Effect.succeed([]),
|
|
102
|
+
read: ({ olds, output }) => withCredentials(ops.read({ olds, output })),
|
|
103
|
+
diff: ({ news, output }) => withCredentials(ops.diff(news, output)),
|
|
104
|
+
reconcile: ({ news }) => withCredentials(ops.reconcile(news)),
|
|
105
|
+
delete: ({ olds }) => withCredentials(ops.destroy(olds))
|
|
106
|
+
};
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
// src/discord/application-command.ts
|
|
110
|
+
var DiscordApplicationCommand = Resource("Discord.ApplicationCommand", {
|
|
111
|
+
defaultRemovalPolicy: "retain"
|
|
112
|
+
});
|
|
113
|
+
var isDiscordApplicationCommand = (value) => typeof value === "object" && value !== null && value.Type === "Discord.ApplicationCommand";
|
|
114
|
+
var attributesOf = (live) => ({
|
|
115
|
+
applicationId: live.application_id,
|
|
116
|
+
commandId: live.id,
|
|
117
|
+
version: live.version,
|
|
118
|
+
...commandFieldsOf(live)
|
|
119
|
+
});
|
|
120
|
+
var spec = {
|
|
121
|
+
attributes: attributesOf,
|
|
122
|
+
describe: (props) => `applications/${props.applicationId}/commands ${props.name}`,
|
|
123
|
+
destroy: (props, live) => command.deleteApplicationCommand({ application_id: props.applicationId, command_id: live.id }),
|
|
124
|
+
fetchByName: (props) => command.listApplicationCommands({ application_id: props.applicationId }).pipe(Effect2.map((rows) => rows.find((row) => row.name === props.name))),
|
|
125
|
+
matches: commandMatches,
|
|
126
|
+
upsert: (props, body) => command.createApplicationCommand({
|
|
127
|
+
application_id: props.applicationId,
|
|
128
|
+
...body
|
|
129
|
+
}),
|
|
130
|
+
upsertBody: commandBody
|
|
131
|
+
};
|
|
132
|
+
var handlers = discordHandlers(spec);
|
|
133
|
+
var DiscordApplicationCommandProvider = () => Provider.effect(DiscordApplicationCommand, Effect2.succeed(DiscordApplicationCommand.Provider.of(handlers)));
|
|
134
|
+
var applicationCommand = (id, props) => DiscordApplicationCommand(id, props).pipe(adopt(true));
|
|
135
|
+
// src/discord/guild-application-command.ts
|
|
136
|
+
import { adopt as adopt2 } from "alchemy/AdoptPolicy";
|
|
137
|
+
import { Resource as Resource2 } from "alchemy";
|
|
138
|
+
import * as Provider2 from "alchemy/Provider";
|
|
139
|
+
import * as command2 from "@distilled.cloud/discord/discord";
|
|
140
|
+
import * as Effect3 from "effect/Effect";
|
|
141
|
+
var DiscordGuildApplicationCommand = Resource2("Discord.GuildApplicationCommand", { defaultRemovalPolicy: "retain" });
|
|
142
|
+
var isDiscordGuildApplicationCommand = (value) => typeof value === "object" && value !== null && value.Type === "Discord.GuildApplicationCommand";
|
|
143
|
+
var attributesOf2 = (live) => ({
|
|
144
|
+
applicationId: live.application_id,
|
|
145
|
+
commandId: live.id,
|
|
146
|
+
guildId: live.guild_id,
|
|
147
|
+
version: live.version,
|
|
148
|
+
...commandFieldsOf(live)
|
|
149
|
+
});
|
|
150
|
+
var spec2 = {
|
|
151
|
+
attributes: attributesOf2,
|
|
152
|
+
describe: (props) => `applications/${props.applicationId}/guilds/${props.guildId}/commands ${props.name}`,
|
|
153
|
+
destroy: (props, live) => command2.deleteGuildApplicationCommand({
|
|
154
|
+
application_id: props.applicationId,
|
|
155
|
+
command_id: live.id,
|
|
156
|
+
guild_id: props.guildId
|
|
157
|
+
}),
|
|
158
|
+
fetchByName: (props) => command2.listGuildApplicationCommands({
|
|
159
|
+
application_id: props.applicationId,
|
|
160
|
+
guild_id: props.guildId
|
|
161
|
+
}).pipe(Effect3.map((rows) => rows.find((row) => row.name === props.name))),
|
|
162
|
+
matches: commandMatches,
|
|
163
|
+
upsert: (props, body) => command2.createGuildApplicationCommand({
|
|
164
|
+
application_id: props.applicationId,
|
|
165
|
+
guild_id: props.guildId,
|
|
166
|
+
...body
|
|
167
|
+
}),
|
|
168
|
+
upsertBody: commandBody
|
|
169
|
+
};
|
|
170
|
+
var handlers2 = discordHandlers(spec2);
|
|
171
|
+
var DiscordGuildApplicationCommandProvider = () => Provider2.effect(DiscordGuildApplicationCommand, Effect3.succeed(DiscordGuildApplicationCommand.Provider.of(handlers2)));
|
|
172
|
+
var guildApplicationCommand = (id, props) => DiscordGuildApplicationCommand(id, props).pipe(adopt2(true));
|
|
173
|
+
// src/discord/providers.ts
|
|
174
|
+
import * as Layer from "effect/Layer";
|
|
175
|
+
var providers = () => Layer.mergeAll(DiscordApplicationCommandProvider(), DiscordGuildApplicationCommandProvider());
|
|
176
|
+
export {
|
|
177
|
+
Credentials,
|
|
178
|
+
CredentialsFromEnv,
|
|
179
|
+
DiscordApplicationCommand,
|
|
180
|
+
DiscordApplicationCommandProvider,
|
|
181
|
+
DiscordGuildApplicationCommand,
|
|
182
|
+
DiscordGuildApplicationCommandProvider,
|
|
183
|
+
applicationCommand,
|
|
184
|
+
credentials,
|
|
185
|
+
fromEnv,
|
|
186
|
+
guildApplicationCommand,
|
|
187
|
+
isDiscordApplicationCommand,
|
|
188
|
+
isDiscordGuildApplicationCommand,
|
|
189
|
+
providers
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
//# debugId=D2971C1C1AB4C81064756E2164756E21
|
|
193
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/discord/application-command.ts", "../src/discord/command-form.ts", "../src/discord/resource.ts", "../src/discord/credentials.ts", "../src/discord/guild-application-command.ts", "../src/discord/providers.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"/**\n * `Discord.ApplicationCommand` — one GLOBAL slash/user/message command on a Discord application.\n *\n * ⛔ NOT WHAT `hf-discord-halibut.service` USES TODAY. Halibut registers guild-scoped commands\n * only (`DISCORD_GUILD_ID` is always set in production — see `docs/discord.md#halibut`), so this\n * resource has no live object to adopt yet. It exists because the distilled SDK, and Discord's\n * own API, model global and guild commands as siblings (same shape, different scope), and a\n * future bot or a future Halibut command that goes global needs it without a second family.\n *\n * ⚠️ GLOBAL COMMAND CHANGES TAKE UP TO AN HOUR TO PROPAGATE (Discord's own docs). A `diff` that\n * ran right after a write could see stale results; this resource does not poll for propagation\n * (S26 bounds waits at ~60s, an hour is not boundable), so a plan run inside that window may\n * report drift that will resolve itself. Documented, not solved — see `docs/discord.md`.\n */\nimport { adopt } from 'alchemy/AdoptPolicy';\nimport { Resource } from 'alchemy';\nimport * as Provider from 'alchemy/Provider';\nimport * as command from '@distilled.cloud/discord/discord';\nimport type { DiscordOpError } from '@distilled.cloud/discord/Protocol';\nimport * as Effect from 'effect/Effect';\nimport {\n type CommandFields,\n type CommandFieldsAttributes,\n commandBody,\n commandFieldsOf,\n commandMatches,\n} from './command-form.ts';\nimport type { DiscordRequirements, DiscordSpec } from './resource.ts';\nimport { discordHandlers } from './resource.ts';\n\nexport interface ApplicationCommandProps extends CommandFields {\n /** The Discord application (bot) this command belongs to — a public snowflake, not a secret. */\n applicationId: string;\n}\n\nexport interface ApplicationCommandAttributes extends CommandFieldsAttributes {\n commandId: string;\n applicationId: string;\n version: string;\n}\n\nexport interface DiscordApplicationCommand extends Resource<\n 'Discord.ApplicationCommand',\n ApplicationCommandProps,\n ApplicationCommandAttributes,\n never,\n DiscordRequirements\n> {}\n\nexport const DiscordApplicationCommand = Resource<DiscordApplicationCommand>(\n 'Discord.ApplicationCommand',\n {\n // Commands are the thing a user reads; nothing here can be edited into another object.\n defaultRemovalPolicy: 'retain',\n },\n);\n\nexport const isDiscordApplicationCommand = (value: unknown): value is DiscordApplicationCommand =>\n typeof value === 'object' &&\n value !== null &&\n (value as { Type?: unknown }).Type === 'Discord.ApplicationCommand';\n\nconst attributesOf = (live: command.ApplicationCommandResponse): ApplicationCommandAttributes => ({\n applicationId: live.application_id,\n commandId: live.id,\n version: live.version,\n ...commandFieldsOf(live),\n});\n\n/** Exported for direct testing against `fake-discord.ts` — the same seam `../netbox/prefix.ts` uses. */\nexport const spec: DiscordSpec<\n ApplicationCommandProps,\n command.ApplicationCommandResponse,\n ApplicationCommandAttributes,\n DiscordOpError\n> = {\n attributes: attributesOf,\n describe: (props) => `applications/${props.applicationId}/commands ${props.name}`,\n destroy: (props, live) =>\n command.deleteApplicationCommand({ application_id: props.applicationId, command_id: live.id }),\n fetchByName: (props) =>\n command\n .listApplicationCommands({ application_id: props.applicationId })\n .pipe(Effect.map((rows) => rows.find((row) => row.name === props.name))),\n matches: commandMatches,\n upsert: (props, body) =>\n command.createApplicationCommand({\n application_id: props.applicationId,\n ...(body as Omit<command.CreateApplicationCommandRequest, 'application_id'>),\n }),\n upsertBody: commandBody,\n};\n\nexport const handlers = discordHandlers(spec);\n\nexport const DiscordApplicationCommandProvider = () =>\n Provider.effect(\n DiscordApplicationCommand,\n Effect.succeed(DiscordApplicationCommand.Provider.of(handlers)),\n );\n\n/**\n * `applicationCommand('help', { applicationId, name: 'help', description: '…' })` — `adopt(true)`\n * piped on by default (H5), so a first deploy against a command that already exists silently\n * takes it over instead of failing `OwnedBySomeoneElse`. Mirrors `cloudflare/website.ts`'s\n * `astroWebsite`/`viteWebsite` convenience constructors.\n */\nexport const applicationCommand = (id: string, props: ApplicationCommandProps) =>\n DiscordApplicationCommand(id, props).pipe(adopt(true));\n",
|
|
6
|
+
"/**\n * The wire body for a Discord command (global or guild), and the comparison that decides whether\n * it needs writing — shared by `application-command.ts` and `guild-application-command.ts` so the\n * two specs cannot drift on what \"matches\" means. Mirrors `../netbox/prefix-form.ts`: pure\n * functions of the props, extracted so a test can call them with a literal, no server involved.\n */\nimport { deepEqual } from 'alchemy/Diff';\n\n/** Fields every Discord command shares, independent of global vs. guild scope. */\nexport interface CommandFields {\n readonly name: string;\n readonly description?: string;\n /**\n * ⚠️ GAP: passed through opaquely, not re-modeled. The SDK's generated option union is ~40\n * nested schema types (subcommand, subcommand group, string/int/number/channel/role/user/\n * mentionable/attachment, each with its own choices and localizations) — see\n * `docs/upstream-conformance.md#discord`. A caller supplies the exact wire shape from\n * Discord's own docs; this resource neither validates nor transforms it.\n */\n readonly options?: readonly Record<string, unknown>[];\n /** Bitfield, stringified, per Discord's real wire contract (the SDK types write as `number`). */\n readonly defaultMemberPermissions?: string;\n readonly dmPermission?: boolean;\n readonly contexts?: readonly number[];\n readonly integrationTypes?: readonly number[];\n readonly nsfw?: boolean;\n /** `ApplicationCommandType`; omitted means `1` (`CHAT_INPUT`), Discord's own default. */\n readonly type?: number;\n}\n\nexport interface CommandFieldsAttributes {\n readonly name: string;\n readonly description: string;\n readonly options: readonly Record<string, unknown>[];\n readonly defaultMemberPermissions: string | undefined;\n readonly dmPermission: boolean | undefined;\n readonly contexts: readonly number[] | undefined;\n readonly integrationTypes: readonly number[] | undefined;\n readonly nsfw: boolean;\n readonly type: number;\n}\n\nconst DEFAULT_TYPE = 1;\n\n/** The fields an undeclared prop still settles to, because Discord itself would. */\nconst settled = (props: CommandFields) => ({\n description: props.description ?? '',\n nsfw: props.nsfw ?? false,\n type: props.type ?? DEFAULT_TYPE,\n});\n\n/**\n * ⛔ SENT IN FULL ON EVERY UPSERT, NEVER PARTIAL. Discord's create-as-upsert (resource.ts's own\n * note) replaces the whole command, so a body that omitted a field the caller stopped declaring\n * would never actually clear it — the same \"declared, then forgotten\" bug `prefix-form.ts`\n * documents for NetBox's PATCH. Sending the full settled shape every time is what keeps a\n * removed prop actually removed live, not just removed from the declaration.\n */\nexport const commandBody = (props: CommandFields): Record<string, unknown> => {\n const fixed = settled(props);\n const out: Record<string, unknown> = {\n description: fixed.description,\n name: props.name,\n nsfw: fixed.nsfw,\n type: fixed.type,\n };\n if (props.options !== undefined) out['options'] = props.options;\n if (props.defaultMemberPermissions !== undefined) {\n out['default_member_permissions'] = props.defaultMemberPermissions;\n }\n if (props.dmPermission !== undefined) out['dm_permission'] = props.dmPermission;\n if (props.contexts !== undefined) out['contexts'] = props.contexts;\n if (props.integrationTypes !== undefined) out['integration_types'] = props.integrationTypes;\n return out;\n};\n\n/** Whether the live command already says what the declaration says. */\nexport const commandMatches = (\n attributes: CommandFieldsAttributes,\n props: CommandFields,\n): boolean => {\n const fixed = settled(props);\n return (\n attributes.name === props.name &&\n attributes.description === fixed.description &&\n attributes.nsfw === fixed.nsfw &&\n attributes.type === fixed.type &&\n // ⛔ GATED LIKE EVERY OTHER OPTIONAL FIELD BELOW — an undeclared `options` means \"not mine\",\n // in both directions (this file's own header rule). An earlier version of this line\n // compared unconditionally against `props.options ?? []`: a declaration with no `options`\n // at all would then see live options as drift, `commandBody` (which already omits\n // `options` when undeclared) would upsert without it, and Discord's real full-replace\n // create would silently wipe a live command's arguments on the first non-dry-run deploy.\n // Caught in review before merge, not measured live.\n (props.options === undefined || deepEqual(attributes.options, props.options)) &&\n (props.defaultMemberPermissions === undefined ||\n attributes.defaultMemberPermissions === props.defaultMemberPermissions) &&\n (props.dmPermission === undefined || attributes.dmPermission === props.dmPermission) &&\n (props.contexts === undefined || deepEqual(attributes.contexts, props.contexts)) &&\n (props.integrationTypes === undefined ||\n deepEqual(attributes.integrationTypes, props.integrationTypes))\n );\n};\n\n/**\n * Reads the shared fields off any `ApplicationCommandResponse`-shaped object.\n *\n * ⚠️ `options` IS READ AS `readonly unknown[]`, NOT RE-TYPED. The SDK's real\n * `ApplicationCommandResponseOptionsItem` union has no index signature (each option kind is a\n * distinct generated interface), so it cannot structurally satisfy `Record<string, unknown>`\n * without a cast — the same \"opaque passthrough\" gap `CommandFields.options` documents above.\n */\nexport const commandFieldsOf = (live: {\n readonly name: string;\n readonly description: string;\n readonly options?: readonly unknown[] | null | undefined;\n readonly default_member_permissions?: string | null | undefined;\n readonly dm_permission?: boolean | undefined;\n readonly contexts?: readonly number[] | null | undefined;\n readonly integration_types?: readonly number[] | null | undefined;\n readonly nsfw?: boolean | undefined;\n readonly type: number;\n}): CommandFieldsAttributes => ({\n contexts: live.contexts ?? undefined,\n defaultMemberPermissions: live.default_member_permissions ?? undefined,\n description: live.description,\n dmPermission: live.dm_permission,\n integrationTypes: live.integration_types ?? undefined,\n name: live.name,\n nsfw: live.nsfw === true,\n options: (live.options as readonly Record<string, unknown>[] | null | undefined) ?? [],\n type: live.type,\n});\n",
|
|
7
|
+
"/**\n * One shape for every Discord application-command object — global and guild-scoped alike.\n *\n * ⛔ THE ALTERNATIVE IS COPYING THE SAME READ/RECONCILE/DELETE PER RESOURCE. `application-command.ts`\n * and `guild-application-command.ts` differ only in which distilled operations they call and\n * whether `guild_id` is part of identity — so the read/diff/reconcile/delete flow lives here\n * once, mirroring `../netbox/resource.ts`'s `netboxOperations`/`netboxHandlers` split.\n *\n * ★ UNLIKE NETBOX, THIS FOLLOWS UPSTREAM'S `Snippet.ts` READ/RECONCILE SHAPE EXACTLY (S7–S9), NOT\n * netbox's \"adopt silently\" gap (H1). Discord commands carry no ownership marker of any kind —\n * no tags, no metadata field a bot could stamp — so this is precisely the \"marker-less API\" S8\n * describes, and `Snippet.ts@v2.0.0-beta.79#read` is the cited reference: an existing match is\n * `Unowned(attrs)` on a cold read (no persisted `output`), and plain attributes on a warm read\n * (persisted `output` says we already made or adopted this exact command). `adopt(true)` (H5),\n * piped onto each resource by the constructors in the two resource files, is what turns that\n * `Unowned` into a silent one-time takeover instead of an `OwnedBySomeoneElse` refusal.\n *\n * ★ RECONCILE IS ONE UPSERT CALL, LIKE `Snippet.ts`'s `putSnippet`. Discord's own docs for both\n * Create Global/Guild Application Command say a command with the same name (and type) as an\n * existing one OVERWRITES it — the create endpoint is a true upsert, not a create-only call that\n * 409s on a name collision. ⚠️ REASONED NOT MEASURED (no token available to this task; see\n * `docs/discord.md`): this is Discord's documented behaviour, unchanged across API v10, but it\n * has not been exercised against the real API by this change. One call therefore converges\n * greenfield create, routine update AND adoption alike — there is no separate PATCH path, and\n * S10's \"zero write calls when there is no drift\" is still honoured because `reconcile` skips\n * the call entirely when `spec.matches` already holds.\n *\n * ⚠️ `list` ANSWERS EMPTY, ON PURPOSE, EVEN THOUGH THE DISTILLED LIST OPERATIONS EXIST. A bot's\n * guild command set is exactly what `hf-discord-halibut.service` bulk-overwrites at every\n * restart (see `docs/discord.md#halibut`); a `nuke` that enumerated and swept every live command\n * would fight that ownership, not just this resource's own declarations. Adoption stays\n * explicit, the same reasoning netbox's `list` gives for a shared instance predating the kit.\n */\nimport { Unowned } from 'alchemy/AdoptPolicy';\nimport { isResolved } from 'alchemy/Diff';\nimport type { Input } from 'alchemy/Input';\nimport type { DiscordOpContext } from '@distilled.cloud/discord/Protocol';\nimport * as Effect from 'effect/Effect';\nimport type * as HttpClient from 'effect/unstable/http/HttpClient';\nimport { CredentialsFromEnv } from './credentials.ts';\n\n/**\n * What every stack must still provide after `discordHandlers` bakes in `CredentialsFromEnv`\n * (below): the transport. `DiscordOpContext` is `Credentials | HttpClient.HttpClient`, so once\n * `Credentials` is supplied, `HttpClient.HttpClient` is what remains — mirroring\n * `../netbox/resource.ts#NetboxRequirements`.\n */\nexport type DiscordRequirements = HttpClient.HttpClient;\n\n/** Every Discord command resource's identity key, regardless of scope. */\nexport interface DiscordCommandIdentity {\n readonly name: string;\n}\n\n/**\n * One Discord command object's distilled calls. `Live` is whatever the SDK decodes\n * (`ApplicationCommandResponse`); `E` is left to each resource file to declare, so a call site's\n * precise error union (in practice always `DiscordOpError` — see `protocol.ts` — because every\n * generated Discord operation shares one error channel) flows straight through.\n */\nexport type DiscordSpec<\n Props extends DiscordCommandIdentity,\n Live,\n Attributes extends object,\n E,\n> = {\n /** Locate the live command by its declared name within this spec's scope (app, or app+guild). */\n readonly fetchByName: (props: Props) => Effect.Effect<Live | undefined, E, DiscordOpContext>;\n readonly attributes: (live: Live) => Attributes;\n readonly matches: (attributes: Attributes, props: Props) => boolean;\n readonly upsertBody: (props: Props) => Record<string, unknown>;\n /** POST create-or-overwrite — see the upsert note above. */\n readonly upsert: (\n props: Props,\n body: Record<string, unknown>,\n ) => Effect.Effect<Live, E, DiscordOpContext>;\n readonly destroy: (props: Props, live: Live) => Effect.Effect<unknown, E, DiscordOpContext>;\n /** For error messages and test descriptions. */\n readonly describe: (props: Props) => string;\n};\n\nexport const discordOperations = <\n Props extends DiscordCommandIdentity,\n Live,\n Attributes extends object,\n E,\n>(\n spec: DiscordSpec<Props, Live, Attributes, E>,\n) => ({\n read: ({ olds, output }: { olds: Props; output: Attributes | undefined }) =>\n Effect.gen(function* () {\n const live = yield* spec.fetchByName(olds);\n if (live === undefined) return undefined;\n const attrs = spec.attributes(live);\n // Warm read: a prior apply already created or adopted this exact command — ours.\n if (output !== undefined) return attrs;\n // Cold read (fresh store, or state lost): no ownership marker exists on this vendor,\n // so any match is `Unowned` until `adopt(true)` (or `--adopt`) says otherwise (S7, S8).\n return Unowned(attrs);\n }),\n\n diff: (news: Input<Props>, output: Attributes | undefined) =>\n Effect.gen(function* () {\n if (output === undefined || !isResolved(news)) return undefined;\n const live = yield* spec.fetchByName(news);\n if (live === undefined) return { action: 'update' } as const;\n return spec.matches(spec.attributes(live), news)\n ? ({ action: 'noop' } as const)\n : ({ action: 'update' } as const);\n }),\n\n reconcile: (news: Props) =>\n Effect.gen(function* () {\n const before = yield* spec.fetchByName(news);\n if (before !== undefined && spec.matches(spec.attributes(before), news)) {\n // Already exactly what is declared — S10: no write.\n return spec.attributes(before);\n }\n const body = spec.upsertBody(news);\n const after = yield* spec.upsert(news, body);\n return spec.attributes(after);\n }),\n\n // ⚠️ GAP, NOT SOLVED: a TOCTOU race between the fetch above and the delete call below could\n // see Discord answer 404 on a command that vanished between the two — S11 asks that race to\n // be treated as success, `catchTag('NotFound', …)`. The SDK's declared error type for every\n // operation does not include `NotFound` (see `docs/discord.md#sdk-gaps` — measured, not\n // assumed), so there is no typed tag to catch here without an unsafe cast. Left unhandled.\n destroy: (olds: Props) =>\n Effect.gen(function* () {\n const live = yield* spec.fetchByName(olds);\n if (live === undefined) return;\n yield* spec.destroy(olds, live);\n }),\n});\n\n/**\n * The four provider handlers for a spec'd Discord command, wired once.\n *\n * ★ CREDENTIALS ARE PROVIDED HERE, ONCE. `CredentialsFromEnv` resolves `DISCORD_BOT_TOKEN` /\n * `DISCORD_TOKEN` on the calling fiber per request (credentials.ts), so this closure keeps that\n * laziness — nothing is captured at module load.\n */\nexport const discordHandlers = <\n Props extends DiscordCommandIdentity,\n Live,\n Attributes extends object,\n E,\n>(\n spec: DiscordSpec<Props, Live, Attributes, E>,\n) => {\n const ops = discordOperations(spec);\n const withCredentials = <A>(effect: Effect.Effect<A, E, DiscordOpContext>) =>\n Effect.provide(effect, CredentialsFromEnv);\n return {\n list: () => Effect.succeed([]),\n read: ({ olds, output }: { olds: Props; output: Attributes | undefined }) =>\n withCredentials(ops.read({ olds, output })),\n diff: ({ news, output }: { news: Input<Props>; output: Attributes | undefined }) =>\n withCredentials(ops.diff(news, output)),\n reconcile: ({ news }: { news: Props }) => withCredentials(ops.reconcile(news)),\n delete: ({ olds }: { olds: Props }) => withCredentials(ops.destroy(olds)),\n };\n};\n",
|
|
8
|
+
"/**\n * Discord credentials — a bot token REFERENCE, resolved lazily (S24), never a prop.\n *\n * ⛔ NO TOKEN IS EVER A PROP OR AN ATTRIBUTE. Alchemy persists Attributes unencrypted\n * (State/StateEncoding.ts@v2.0.0-beta.79#encodeState), so nothing a stack file holds may be a\n * credential. `@distilled.cloud/discord/Credentials` already ships exactly the shape S24 asks\n * for: `Credentials` is a lazy `Context.Service<Credentials, Effect.Effect<Config>>`, resolved\n * on the calling fiber inside each operation (`DiscordProtocol`'s `credentials:` field), never\n * at layer build. This file re-exports it rather than re-implementing it — the same choice\n * `../netbox/resource.ts` made for `CredentialsFromEnv` — and adds only the house-specific\n * naming and doc trail.\n *\n * ★ `CredentialsFromEnv` reads `DISCORD_BOT_TOKEN` (falling back to `DISCORD_TOKEN`) via Effect's\n * `Config`, which is exactly the \"reference\" shape S25 asks for: the resource never sees the\n * value, only the environment variable NAME is anywhere near a stack file, and the value itself\n * is wrapped in `Redacted` the moment it is read.\n *\n * ⚠️ NO OpenBao MINT YET. H8's target (`Alchemy.Stack({ secrets })`) is unreleased (PR 1728, still\n * on `main` only). Until the estate is on a release that carries it, the deploy process's own\n * environment is the credential seam — a human or CI job exports `DISCORD_BOT_TOKEN` from\n * wherever it mints it (on CT100 today: `/opt/homeflare/env/discord-halibut.env`, read by\n * systemd's `EnvironmentFile=`, never by this package). This package never reads that file.\n */\nimport type { Config } from '@distilled.cloud/discord/Credentials';\nimport { Credentials, CredentialsFromEnv, credentials } from '@distilled.cloud/discord/Credentials';\n\n/** Re-exported so a consumer never has to reach into `@distilled.cloud/discord` by hand. */\nexport { Credentials, CredentialsFromEnv, credentials };\nexport type { Config as DiscordCredentialsConfig };\n\n/**\n * `DiscordCredentials.fromEnv()` — the layer every `discordProviders()` stack uses by default.\n * A thin, named alias over `CredentialsFromEnv` so a stack's import reads `Discord.*`\n * throughout, the way `../netbox/index.ts`'s barrel keeps `Netbox*` names at the front door.\n */\nexport const fromEnv = () => CredentialsFromEnv;\n",
|
|
9
|
+
"/**\n * `Discord.GuildApplicationCommand` — one guild-scoped slash/user/message command.\n *\n * 🔴 THIS IS WHAT `hf-discord-halibut.service` OWNS TODAY, AND DECLARING IT AGAINST HALIBUT'S OWN\n * GUILDS WOULD FIGHT THE BOT, NOT REPLACE IT. Halibut calls `applySapphireGuildRegister()`\n * before every login (`src/discord/register.ts` on CT100, `RegisterBehavior.BulkOverwrite`),\n * which PUTs its exact `CURRENT_SLASH_NAMES` set on every restart. Deploying this resource\n * against the same `(applicationId, guildId)` the bot manages means two owners converging the\n * same object on two different schedules — the bot's restart would silently undo whatever this\n * resource last wrote, and the next `alchemy plan` would then report drift the bot just caused,\n * forever. See `docs/discord.md#halibut` for the measured command list, guild id source, and the\n * handover sequence (freeze the list, adopt each command with `adopt(true)` for a verified\n * no-op, THEN remove `applySapphireGuildRegister()` from the bot in the same deploy window —\n * bot-runtime code, explicitly out of scope for this family).\n *\n * ★ Until that handover happens, this resource is for guilds/applications Halibut does not touch.\n */\nimport { adopt } from 'alchemy/AdoptPolicy';\nimport { Resource } from 'alchemy';\nimport * as Provider from 'alchemy/Provider';\nimport * as command from '@distilled.cloud/discord/discord';\nimport type { DiscordOpError } from '@distilled.cloud/discord/Protocol';\nimport * as Effect from 'effect/Effect';\nimport {\n type CommandFields,\n type CommandFieldsAttributes,\n commandBody,\n commandFieldsOf,\n commandMatches,\n} from './command-form.ts';\nimport type { DiscordRequirements, DiscordSpec } from './resource.ts';\nimport { discordHandlers } from './resource.ts';\n\nexport interface GuildApplicationCommandProps extends CommandFields {\n /** The Discord application (bot) this command belongs to — a public snowflake, not a secret. */\n applicationId: string;\n /** The guild (server) this command is scoped to — a public snowflake. */\n guildId: string;\n}\n\nexport interface GuildApplicationCommandAttributes extends CommandFieldsAttributes {\n commandId: string;\n applicationId: string;\n guildId: string;\n version: string;\n}\n\nexport interface DiscordGuildApplicationCommand extends Resource<\n 'Discord.GuildApplicationCommand',\n GuildApplicationCommandProps,\n GuildApplicationCommandAttributes,\n never,\n DiscordRequirements\n> {}\n\nexport const DiscordGuildApplicationCommand = Resource<DiscordGuildApplicationCommand>(\n 'Discord.GuildApplicationCommand',\n { defaultRemovalPolicy: 'retain' },\n);\n\nexport const isDiscordGuildApplicationCommand = (\n value: unknown,\n): value is DiscordGuildApplicationCommand =>\n typeof value === 'object' &&\n value !== null &&\n (value as { Type?: unknown }).Type === 'Discord.GuildApplicationCommand';\n\nconst attributesOf = (\n live: command.ApplicationCommandResponse,\n): GuildApplicationCommandAttributes => ({\n applicationId: live.application_id,\n commandId: live.id,\n // ⚠️ `guild_id` is present on every row a GUILD list call returns (Discord scopes the list by\n // guild), so this cast documents that guarantee rather than re-deriving it from `props`.\n guildId: live.guild_id as string,\n version: live.version,\n ...commandFieldsOf(live),\n});\n\n/** Exported for direct testing against `fake-discord.ts`. */\nexport const spec: DiscordSpec<\n GuildApplicationCommandProps,\n command.ApplicationCommandResponse,\n GuildApplicationCommandAttributes,\n DiscordOpError\n> = {\n attributes: attributesOf,\n describe: (props) =>\n `applications/${props.applicationId}/guilds/${props.guildId}/commands ${props.name}`,\n destroy: (props, live) =>\n command.deleteGuildApplicationCommand({\n application_id: props.applicationId,\n command_id: live.id,\n guild_id: props.guildId,\n }),\n fetchByName: (props) =>\n command\n .listGuildApplicationCommands({\n application_id: props.applicationId,\n guild_id: props.guildId,\n })\n .pipe(Effect.map((rows) => rows.find((row) => row.name === props.name))),\n matches: commandMatches,\n upsert: (props, body) =>\n command.createGuildApplicationCommand({\n application_id: props.applicationId,\n guild_id: props.guildId,\n ...(body as Omit<\n command.CreateGuildApplicationCommandRequest,\n 'application_id' | 'guild_id'\n >),\n }),\n upsertBody: commandBody,\n};\n\nexport const handlers = discordHandlers(spec);\n\nexport const DiscordGuildApplicationCommandProvider = () =>\n Provider.effect(\n DiscordGuildApplicationCommand,\n Effect.succeed(DiscordGuildApplicationCommand.Provider.of(handlers)),\n );\n\n/**\n * `guildApplicationCommand('ping', { applicationId, guildId, name: 'ping' })` — `adopt(true)`\n * piped on by default (H5). See the file header before pointing this at a guild Halibut manages.\n */\nexport const guildApplicationCommand = (id: string, props: GuildApplicationCommandProps) =>\n DiscordGuildApplicationCommand(id, props).pipe(adopt(true));\n",
|
|
10
|
+
"/**\n * Both Discord command providers as one layer for a stack.\n *\n * Layer.mergeAll(discordProviders(), …the stack's other providers)\n * .pipe(Layer.provide(FetchHttpClient.layer))\n *\n * S16: a subpath's `providers()` plays the role upstream's own `Providers.ts` does — one minimal\n * insertion per family, requirements that never contain `unknown`. `FetchHttpClient.layer` is the\n * stack's own responsibility to provide (it is the shared transport every family needs, not\n * something a single vendor's `providers()` should pin), mirroring `../netbox/index.ts`'s barrel,\n * which exports `netboxHandlers` rather than a bundled transport too.\n */\nimport * as Layer from 'effect/Layer';\nimport { DiscordApplicationCommandProvider } from './application-command.ts';\nimport { DiscordGuildApplicationCommandProvider } from './guild-application-command.ts';\n\nexport const providers = () =>\n Layer.mergeAll(DiscordApplicationCommandProvider(), DiscordGuildApplicationCommandProvider());\n"
|
|
11
|
+
],
|
|
12
|
+
"mappings": ";AAcA;AACA;AACA;AACA;AAEA;;;ACbA;AAoCA,IAAM,eAAe;AAGrB,IAAM,UAAU,CAAC,WAA0B;AAAA,EACzC,aAAa,MAAM,eAAe;AAAA,EAClC,MAAM,MAAM,QAAQ;AAAA,EACpB,MAAM,MAAM,QAAQ;AACtB;AASO,IAAM,cAAc,CAAC,UAAkD;AAAA,EAC5E,MAAM,QAAQ,QAAQ,KAAK;AAAA,EAC3B,MAAM,MAA+B;AAAA,IACnC,aAAa,MAAM;AAAA,IACnB,MAAM,MAAM;AAAA,IACZ,MAAM,MAAM;AAAA,IACZ,MAAM,MAAM;AAAA,EACd;AAAA,EACA,IAAI,MAAM,YAAY;AAAA,IAAW,IAAI,aAAa,MAAM;AAAA,EACxD,IAAI,MAAM,6BAA6B,WAAW;AAAA,IAChD,IAAI,gCAAgC,MAAM;AAAA,EAC5C;AAAA,EACA,IAAI,MAAM,iBAAiB;AAAA,IAAW,IAAI,mBAAmB,MAAM;AAAA,EACnE,IAAI,MAAM,aAAa;AAAA,IAAW,IAAI,cAAc,MAAM;AAAA,EAC1D,IAAI,MAAM,qBAAqB;AAAA,IAAW,IAAI,uBAAuB,MAAM;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one layer for a stack.
|
|
3
|
+
*
|
|
4
|
+
* Layer.mergeAll(discordProviders(), …the stack's other providers)
|
|
5
|
+
* .pipe(Layer.provide(FetchHttpClient.layer))
|
|
6
|
+
*
|
|
7
|
+
* S16: a subpath's `providers()` plays the role upstream's own `Providers.ts` does — one minimal
|
|
8
|
+
* insertion per family, requirements that never contain `unknown`. `FetchHttpClient.layer` is the
|
|
9
|
+
* stack's own responsibility to provide (it is the shared transport every family needs, not
|
|
10
|
+
* something a single vendor's `providers()` should pin), mirroring `../netbox/index.ts`'s barrel,
|
|
11
|
+
* which exports `netboxHandlers` rather than a bundled transport too.
|
|
12
|
+
*/
|
|
13
|
+
import * as Layer from 'effect/Layer';
|
|
14
|
+
export declare const providers: () => Layer.Layer<import("alchemy").Provider<import("./application-command.ts").DiscordApplicationCommand> | import("alchemy").Provider<import("./guild-application-command.ts").DiscordGuildApplicationCommand>, never, import("effect/unstable/http/HttpClient").HttpClient>;
|
|
15
|
+
//# sourceMappingURL=providers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"providers.d.ts","sourceRoot":"","sources":["../../src/discord/providers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAItC,eAAO,MAAM,SAAS,gRACyE,CAAC"}
|