-
Notifications
You must be signed in to change notification settings - Fork 330
Effect CLI rewrite #2335
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
drew-harris
wants to merge
15
commits into
main
Choose a base branch
from
drewh/clief
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
Effect CLI rewrite #2335
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
f4dc01c
effect rewrite of cli
drew-harris 8923fb8
fix p2 issues
drew-harris f10f0f3
add log to explorer command
drew-harris e632cf1
remove @effect/cli dependency
drew-harris 07278ef
fix coerce auth for init and browser commands
drew-harris 42d4273
actually update pnpm lock
drew-harris a289f6f
fix a lot
drew-harris 04879eb
super smart http errors
drew-harris e0ffe4a
schema validation errors
drew-harris 9a4a708
add svelte after rebase
drew-harris a29f6d8
fix lockfile
drew-harris e6e81f9
fix small issues
drew-harris b5ae90a
todo comment look at it
drew-harris 9477c9a
changes
drew-harris 3eff832
add --asToken
drew-harris 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
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 |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import { HttpClient, HttpClientRequest } from '@effect/platform'; | ||
| import chalk from 'chalk'; | ||
| import { Effect } from 'effect'; | ||
| import { CurrentApp } from '../context/currentApp.js'; | ||
| import { BadArgsError } from '../errors.js'; | ||
| import { WithAppLayer } from '../layer.js'; | ||
| import { InstantHttpAuthed } from '../lib/http.js'; | ||
|
|
||
| export const claimCommand = Effect.gen(function* () { | ||
| const { appId, adminToken } = yield* CurrentApp; | ||
|
|
||
| yield* Effect.log(`Found app: ${appId}`); | ||
|
|
||
| const http = yield* InstantHttpAuthed; | ||
|
|
||
| if (!adminToken) { | ||
| return yield* BadArgsError.make({ message: 'Missing app admin token' }); | ||
| } | ||
|
|
||
| yield* http | ||
| .pipe( | ||
| HttpClient.mapRequestInputEffect( | ||
| HttpClientRequest.bodyJson({ | ||
| app_id: appId, | ||
| token: adminToken, | ||
| }), | ||
| ), | ||
| ) | ||
| .post(`/dash/apps/ephemeral/${appId}/claim`); | ||
|
|
||
| yield* Effect.log(chalk.green('App claimed!')); | ||
| }).pipe( | ||
| Effect.provide( | ||
| WithAppLayer({ | ||
| coerce: false, | ||
| allowAdminToken: false, | ||
| applyEnv: false, | ||
| }), | ||
| ), | ||
| ); |
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,29 @@ | ||
| import { Effect } from 'effect'; | ||
| import openInBrowser from 'open'; | ||
| import { explorerDef, OptsFromCommand } from '../index.js'; | ||
| import { CurrentApp } from '../context/currentApp.js'; | ||
| import { WithAppLayer } from '../layer.js'; | ||
| import { getDashUrl } from '../lib/http.js'; | ||
|
|
||
| export const explorerCmd = (opts: OptsFromCommand<typeof explorerDef>) => | ||
| Effect.gen(function* () { | ||
| const { appId } = yield* CurrentApp; | ||
| const dashUrl = yield* getDashUrl; | ||
| yield* Effect.log('Opening Explorer...'); | ||
| const url = `${dashUrl}/dash?s=main&app=${appId}&t=explorer`; | ||
| yield* Effect.tryPromise(() => openInBrowser(url)).pipe( | ||
| Effect.catchAll(() => | ||
| Effect.log( | ||
| `Failed to open Explorer in browser\nOpen Explorer manually:\n${url}`, | ||
| ), | ||
| ), | ||
| ); | ||
| }).pipe( | ||
| Effect.provide( | ||
| WithAppLayer({ | ||
| coerce: true, | ||
| coerceAuth: true, | ||
| appId: opts.app, | ||
| }), | ||
| ), | ||
| ); |
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,42 @@ | ||
| import { HttpClientResponse } from '@effect/platform'; | ||
| import { Effect, Layer, pipe, Schema, Option } from 'effect'; | ||
| import { AuthLayerLive } from '../layer.js'; | ||
| import { InstantHttpAuthed } from '../lib/http.js'; | ||
| import { version } from '@instantdb/version'; | ||
|
|
||
| const DashMeResponse = Schema.Struct({ | ||
| user: Schema.Struct({ | ||
| id: Schema.String, | ||
| email: Schema.String, | ||
| created_at: Schema.String, | ||
| }), | ||
| }); | ||
|
|
||
| export const infoCommand = () => | ||
| Effect.gen(function* () { | ||
| const http = yield* Effect.serviceOption(InstantHttpAuthed).pipe( | ||
| Effect.map(Option.getOrNull), | ||
| ); | ||
|
|
||
| yield* Effect.log('CLI Version:', version); | ||
| // If logged in.. | ||
| if (http) { | ||
| const meData = yield* http.get('/dash/me').pipe( | ||
| Effect.flatMap(HttpClientResponse.schemaBodyJson(DashMeResponse)), | ||
| Effect.mapError( | ||
| (e) => new Error("Couldn't get user information.", { cause: e }), | ||
| ), | ||
| ); | ||
|
|
||
| yield* Effect.log(`Logged in as ${meData.user.email}`); | ||
| } else { | ||
| yield* Effect.log('Not logged in.'); | ||
| } | ||
| }).pipe( | ||
| Effect.provide( | ||
| AuthLayerLive({ | ||
| coerce: false, | ||
| allowAdminToken: false, | ||
| }).pipe(Layer.catchAll((e) => Layer.empty)), | ||
| ), | ||
| ); |
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.