refactor(server): inject database options
This commit is contained in:
parent
61b7caa0b5
commit
f971aa0719
14 changed files with 93 additions and 52 deletions
|
|
@ -1,12 +1,19 @@
|
|||
import { OpenCode } from "@opencode-ai/client/effect"
|
||||
import { Database } from "@opencode-ai/core/database/database"
|
||||
import { SdkPlugins } from "@opencode-ai/core/plugin/sdk"
|
||||
import { createEmbeddedRoutes } from "@opencode-ai/server/routes"
|
||||
import { Context, Effect, Layer, ManagedRuntime } from "effect"
|
||||
import { FetchHttpClient, HttpEffect, HttpRouter, HttpServer } from "effect/unstable/http"
|
||||
|
||||
export const create = Effect.fn("OpenCode.create")(function* () {
|
||||
export const create = Effect.fn("OpenCode.create")(function* (options: { readonly database?: Database.Options } = {}) {
|
||||
const runtime = yield* Effect.acquireRelease(
|
||||
Effect.sync(() => ManagedRuntime.make(createEmbeddedRoutes().pipe(Layer.provide(HttpServer.layerServices)))),
|
||||
Effect.sync(() =>
|
||||
ManagedRuntime.make(
|
||||
createEmbeddedRoutes({ database: { path: ":memory:", ...options.database } }).pipe(
|
||||
Layer.provide(HttpServer.layerServices),
|
||||
),
|
||||
),
|
||||
),
|
||||
(runtime) => runtime.disposeEffect,
|
||||
)
|
||||
const context = yield* runtime.contextEffect
|
||||
|
|
|
|||
|
|
@ -1,14 +1,11 @@
|
|||
import fs from "fs/promises"
|
||||
import path from "path"
|
||||
import { expect } from "bun:test"
|
||||
import { Flag } from "@opencode-ai/core/flag/flag"
|
||||
import { Deferred, Effect, Latch, Layer, Option, Ref, Schema, Stream } from "effect"
|
||||
import { testEffect } from "../../core/test/lib/effect"
|
||||
import { tmpdir } from "../../core/test/fixture/tmpdir"
|
||||
import type { OpenCodeEvent } from "../src"
|
||||
|
||||
Flag.OPENCODE_DB = ":memory:"
|
||||
|
||||
const it = testEffect(Layer.empty)
|
||||
type Sdk = typeof import("../src")
|
||||
type Fixture = { readonly directory: string; readonly sdk: Sdk }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue