-
Notifications
You must be signed in to change notification settings - Fork 6
Expand how much of the codebase is using Effect; fix excess error emission #270
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c7f62bd
Refactor Database: Layer.scoped for SQLite, Effect-based integrity check
vcarl 2e4118b
Extract AppRuntime module and update import paths
vcarl 16b171e
Convert server startup and Discord gateway to Effect
vcarl bad2feb
Fix top-level async/await by explicitly targeting esnext on the server
vcarl fde31da
Use runtime instead of providing db
vcarl 57176f8
Logs
vcarl 17b0cb5
Move initialization code to server.ts
vcarl 95c009e
Add missing intent holy shit
vcarl fa00a77
Drain metrics again on shutdown
vcarl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| import { Effect, Layer, ManagedRuntime } from "effect"; | ||
|
|
||
| import { DatabaseLayer, DatabaseService, type EffectKysely } from "#~/Database"; | ||
| import { NotFoundError } from "#~/effects/errors"; | ||
|
|
||
| // App layer: database + PostHog + feature flags | ||
| // FeatureFlagServiceLive depends on both DatabaseService and PostHogService | ||
| const AppLayer = Layer.mergeAll(DatabaseLayer); | ||
|
|
||
| // ManagedRuntime keeps the AppLayer scope alive for the process lifetime. | ||
| // Unlike Effect.runSync which closes the scope (and thus the SQLite connection) | ||
| // after execution, ManagedRuntime holds the scope open until explicit disposal. | ||
| export const runtime = ManagedRuntime.make(AppLayer); | ||
|
|
||
| // The context type provided by the ManagedRuntime. Use this for typing functions | ||
| // that accept effects which need database access. | ||
| export type RuntimeContext = ManagedRuntime.ManagedRuntime.Context< | ||
| typeof runtime | ||
| >; | ||
|
|
||
| // Extract the PostHog client for use by metrics.ts (null when no API key configured). | ||
vcarl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| export const db: EffectKysely = await runtime.runPromise(DatabaseService); | ||
vcarl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // --- Bridge functions for legacy async/await code --- | ||
|
|
||
| // Convenience helpers for legacy async/await code that needs to run | ||
| // EffectKysely query builders as Promises. | ||
| export const run = <A>(effect: Effect.Effect<A, unknown, never>): Promise<A> => | ||
| Effect.runPromise(effect); | ||
|
|
||
| export const runTakeFirst = <A>( | ||
| effect: Effect.Effect<A[], unknown, never>, | ||
| ): Promise<A | undefined> => | ||
| Effect.runPromise(Effect.map(effect, (rows) => rows[0])); | ||
|
|
||
| export const runTakeFirstOrThrow = <A>( | ||
| effect: Effect.Effect<A[], unknown, never>, | ||
| ): Promise<A> => | ||
| Effect.runPromise( | ||
| Effect.flatMap(effect, (rows) => | ||
| rows[0] !== undefined | ||
| ? Effect.succeed(rows[0]) | ||
| : Effect.fail(new NotFoundError({ resource: "db record", id: "" })), | ||
| ), | ||
| ); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment mentions "database + PostHog + feature flags" but the AppLayer only merges DatabaseLayer. If PostHog and feature flags are intended to be part of this layer, they're missing from the implementation. If they're not yet implemented, the comment should be updated to reflect the current state.