-
Notifications
You must be signed in to change notification settings - Fork 2
Migrate to effect-v4 #10
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
Open
utopyin
wants to merge
14
commits into
main
Choose a base branch
from
effect-v4
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
d7c00fc
migrate to effect-v4
utopyin 770af1e
prerelease for effect-v4
utopyin bef0bfd
docs: remove duplicate request-scoped context section
utopyin a5cb4a5
Version Packages (effect-v4)
github-actions[bot] b791f93
chore: use Effect.fn.Return for correctness
utopyin d18fc9d
Version Packages (effect-v4)
github-actions[bot] 29534d6
Merge pull request #11 from utopyin/changeset-release/effect-v4
utopyin bedad44
Merge pull request #13 from utopyin/changeset-release/effect-v4
utopyin db15510
improve effect cause to error conversion
utopyin 0308575
update CHANGELOG
utopyin 6519f80
Version Packages (effect-v4)
github-actions[bot] 509463f
refactor: import IntersectPick from @orpc/shared
utopyin 131bca0
Merge pull request #15 from utopyin/changeset-release/effect-v4
utopyin ebafa44
Merge branch 'main' into effect-v4
utopyin 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
Some comments aren't visible on the classic Files Changed page.
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,5 @@ | ||
| --- | ||
| "effect-orpc": major | ||
| --- | ||
|
|
||
| migrate to effect-v4 (effect-smol) |
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,12 @@ | ||
| { | ||
| "mode": "pre", | ||
| "tag": "effect-v4", | ||
| "initialVersions": { | ||
| "effect-orpc": "0.1.2" | ||
| }, | ||
| "changesets": [ | ||
| "dull-spiders-smash", | ||
| "fluffy-times-shave", | ||
| "silly-doodles-cover" | ||
| ] | ||
| } |
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,5 @@ | ||
| --- | ||
| "effect-orpc": patch | ||
| --- | ||
|
|
||
| docs: remove duplicate request-scoped context section |
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 |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ on: | |
| push: | ||
| branches: | ||
| - main | ||
| - effect-v4 | ||
|
|
||
| concurrency: ${{ github.workflow }}-${{ github.ref }} | ||
|
|
||
|
|
||
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,46 +1,51 @@ | ||
| import { Effect } from "effect"; | ||
| import { Effect, Layer, ServiceMap } from "effect"; | ||
|
|
||
| import { DatabaseService } from "./database"; | ||
|
|
||
| export class CacheService extends Effect.Service<CacheService>()( | ||
| "CacheService", | ||
| export class CacheService extends ServiceMap.Service< | ||
| CacheService, | ||
| { | ||
| accessors: true, | ||
| dependencies: [DatabaseService.Default], | ||
| effect: Effect.gen(function* () { | ||
| const db = yield* DatabaseService; | ||
| const cache = new Map<string, unknown>(); | ||
| readonly get: (key: string) => Effect.Effect<unknown>; | ||
| readonly set: (key: string, value: unknown) => Effect.Effect<boolean>; | ||
| } | ||
| >()("CacheService", { | ||
| make: Effect.gen(function* () { | ||
| const db = yield* DatabaseService; | ||
| const cache = new Map<string, unknown>(); | ||
|
|
||
| return { | ||
| get: (key: string) => | ||
| Effect.gen(function* () { | ||
| yield* Effect.logInfo(`Cache lookup: ${key}`); | ||
| return { | ||
| get: (key: string) => | ||
| Effect.gen(function* () { | ||
| yield* Effect.logInfo(`Cache lookup: ${key}`); | ||
|
|
||
| if (cache.has(key)) { | ||
| yield* Effect.logInfo(`Cache HIT: ${key}`); | ||
| return cache.get(key); | ||
| } | ||
| if (cache.has(key)) { | ||
| yield* Effect.logInfo(`Cache HIT: ${key}`); | ||
| return cache.get(key); | ||
| } | ||
|
|
||
| yield* Effect.logInfo(`Cache MISS: ${key}, fetching from DB`); | ||
| const result = | ||
| yield* db.query`SELECT * FROM cache WHERE key = '${key}'`; | ||
| cache.set(key, result); | ||
| return result; | ||
| }).pipe( | ||
| Effect.annotateLogs("service", "CacheService"), | ||
| Effect.withSpan("CacheService.get"), | ||
| ), | ||
| set: (key: string, value: unknown) => | ||
| Effect.gen(function* () { | ||
| yield* Effect.logInfo(`Cache set: ${key}`); | ||
| cache.set(key, value); | ||
| yield* db.insert("cache", { key, value }); | ||
| return true; | ||
| }).pipe( | ||
| Effect.annotateLogs("service", "CacheService"), | ||
| Effect.withSpan("CacheService.set"), | ||
| ), | ||
| }; | ||
| }), | ||
| }, | ||
| ) {} | ||
| yield* Effect.logInfo(`Cache MISS: ${key}, fetching from DB`); | ||
| const result = | ||
| yield* db.query`SELECT * FROM cache WHERE key = '${key}'`; | ||
| cache.set(key, result); | ||
| return result; | ||
| }).pipe( | ||
| Effect.annotateLogs("service", "CacheService"), | ||
| Effect.withSpan("CacheService.get"), | ||
| ), | ||
| set: (key: string, value: unknown) => | ||
| Effect.gen(function* () { | ||
| yield* Effect.logInfo(`Cache set: ${key}`); | ||
| cache.set(key, value); | ||
| yield* db.insert("cache", { key, value }); | ||
| return true; | ||
| }).pipe( | ||
| Effect.annotateLogs("service", "CacheService"), | ||
| Effect.withSpan("CacheService.set"), | ||
| ), | ||
| }; | ||
| }), | ||
| }) { | ||
| static readonly layer = Layer.effect(this, this.make).pipe( | ||
| Layer.provide(DatabaseService.layer), | ||
| ); | ||
| } |
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 |
|---|---|---|
| @@ -1,27 +1,39 @@ | ||
| import { Effect } from "effect"; | ||
| import { Effect, Layer, ServiceMap } from "effect"; | ||
|
|
||
| export class DatabaseService extends Effect.Service<DatabaseService>()( | ||
| "DatabaseService", | ||
| export class DatabaseService extends ServiceMap.Service< | ||
| DatabaseService, | ||
| { | ||
| sync: () => ({ | ||
| query: (sql: TemplateStringsArray, ..._args: unknown[]) => | ||
| Effect.gen(function* () { | ||
| yield* Effect.logInfo(`Executing SQL: ${sql}`); | ||
| yield* Effect.sleep("10 millis"); | ||
| return { rows: [{ id: 1, data: "result" }], rowCount: 1 }; | ||
| }).pipe( | ||
| Effect.annotateLogs("service", "DatabaseService"), | ||
| Effect.withSpan("DatabaseService.query"), | ||
| ), | ||
| insert: (table: string, _data: unknown) => | ||
| Effect.gen(function* () { | ||
| yield* Effect.logInfo(`Inserting into ${table}`); | ||
| yield* Effect.sleep("15 millis"); | ||
| return { id: Math.floor(Math.random() * 1000), success: true }; | ||
| }).pipe( | ||
| Effect.annotateLogs("service", "DatabaseService"), | ||
| Effect.withSpan("DatabaseService.insert"), | ||
| ), | ||
| }), | ||
| }, | ||
| ) {} | ||
| readonly query: ( | ||
| sql: TemplateStringsArray, | ||
| ...args: unknown[] | ||
| ) => Effect.Effect<{ | ||
| rows: Array<{ id: number; data: string }>; | ||
| rowCount: number; | ||
| }>; | ||
| readonly insert: ( | ||
| table: string, | ||
| data: unknown, | ||
| ) => Effect.Effect<{ id: number; success: boolean }>; | ||
| } | ||
| >()("DatabaseService") { | ||
| static readonly layer = Layer.succeed(this, { | ||
| query: (sql: TemplateStringsArray, ..._args: unknown[]) => | ||
| Effect.gen(function* () { | ||
| yield* Effect.logInfo(`Executing SQL: ${sql}`); | ||
| yield* Effect.sleep("10 millis"); | ||
| return { rows: [{ id: 1, data: "result" }], rowCount: 1 }; | ||
| }).pipe( | ||
| Effect.annotateLogs("service", "DatabaseService"), | ||
| Effect.withSpan("DatabaseService.query"), | ||
| ), | ||
| insert: (table: string, _data: unknown) => | ||
| Effect.gen(function* () { | ||
| yield* Effect.logInfo(`Inserting into ${table}`); | ||
| yield* Effect.sleep("15 millis"); | ||
| return { id: Math.floor(Math.random() * 1000), success: true }; | ||
| }).pipe( | ||
| Effect.annotateLogs("service", "DatabaseService"), | ||
| Effect.withSpan("DatabaseService.insert"), | ||
| ), | ||
| }); | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.