chore: effect ts plugin
This commit is contained in:
parent
7ea7fe783c
commit
ad50ec9392
8 changed files with 20 additions and 14 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
import { afterEach, expect, mock, spyOn, test } from "bun:test";
|
import { afterEach, expect, mock, spyOn, test } from "bun:test";
|
||||||
import { Effect } from "effect";
|
import { Effect } from "effect";
|
||||||
import waitForExpect from "wait-for-expect";
|
import waitForExpect from "wait-for-expect";
|
||||||
import { fromAny } from "@total-typescript/shoehorn";
|
import { fromPartial } from "@total-typescript/shoehorn";
|
||||||
import { createControllerMessage, parseAgentMessage } from "@zerobyte/contracts/agent-protocol";
|
import { createControllerMessage, parseAgentMessage } from "@zerobyte/contracts/agent-protocol";
|
||||||
import * as resticServer from "@zerobyte/core/restic/server";
|
import * as resticServer from "@zerobyte/core/restic/server";
|
||||||
import { createControllerSession } from "../controller-session";
|
import { createControllerSession } from "../controller-session";
|
||||||
|
|
@ -12,14 +12,14 @@ afterEach(() => {
|
||||||
|
|
||||||
test("emits backup.failed when a backup command hits a restic error", async () => {
|
test("emits backup.failed when a backup command hits a restic error", async () => {
|
||||||
spyOn(resticServer, "createRestic").mockReturnValue(
|
spyOn(resticServer, "createRestic").mockReturnValue(
|
||||||
fromAny({
|
fromPartial({
|
||||||
backup: () => Effect.fail(new Error("source path missing")),
|
backup: () => Effect.fail("source path missing"),
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
const outboundMessages: string[] = [];
|
const outboundMessages: string[] = [];
|
||||||
const session = createControllerSession(
|
const session = createControllerSession(
|
||||||
fromAny({
|
fromPartial({
|
||||||
send: (message: string) => {
|
send: (message: string) => {
|
||||||
outboundMessages.push(message);
|
outboundMessages.push(message);
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Effect } from "effect";
|
import { Effect, Runtime } from "effect";
|
||||||
import { createAgentMessage, type BackupRunPayload } from "@zerobyte/contracts/agent-protocol";
|
import { createAgentMessage, type BackupRunPayload } from "@zerobyte/contracts/agent-protocol";
|
||||||
import { logger } from "@zerobyte/core/node";
|
import { logger } from "@zerobyte/core/node";
|
||||||
import { type ResticDeps } from "@zerobyte/core/restic";
|
import { type ResticDeps } from "@zerobyte/core/restic";
|
||||||
|
|
@ -52,6 +52,7 @@ export const handleBackupRunCommand = (context: ControllerCommandContext, payloa
|
||||||
};
|
};
|
||||||
|
|
||||||
const restic = createRestic(deps);
|
const restic = createRestic(deps);
|
||||||
|
const runtime = yield* Effect.runtime<never>();
|
||||||
|
|
||||||
yield* restic
|
yield* restic
|
||||||
.backup(payload.repositoryConfig, payload.sourcePath, {
|
.backup(payload.repositoryConfig, payload.sourcePath, {
|
||||||
|
|
@ -59,7 +60,8 @@ export const handleBackupRunCommand = (context: ControllerCommandContext, payloa
|
||||||
...payload.options,
|
...payload.options,
|
||||||
signal: abortController.signal,
|
signal: abortController.signal,
|
||||||
onProgress: (progress) => {
|
onProgress: (progress) => {
|
||||||
void Effect.runPromise(
|
void Runtime.runPromise(
|
||||||
|
runtime,
|
||||||
context.offerOutbound(
|
context.offerOutbound(
|
||||||
createAgentMessage("backup.progress", {
|
createAgentMessage("backup.progress", {
|
||||||
jobId: payload.jobId,
|
jobId: payload.jobId,
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,11 @@
|
||||||
import { Effect } from "effect";
|
|
||||||
import { createAgentMessage, type ControllerMessage } from "@zerobyte/contracts/agent-protocol";
|
import { createAgentMessage, type ControllerMessage } from "@zerobyte/contracts/agent-protocol";
|
||||||
import type { ControllerCommandContext } from "../context";
|
import type { ControllerCommandContext } from "../context";
|
||||||
|
|
||||||
type HeartbeatPingPayload = Extract<ControllerMessage, { type: "heartbeat.ping" }>["payload"];
|
type HeartbeatPingPayload = Extract<ControllerMessage, { type: "heartbeat.ping" }>["payload"];
|
||||||
|
|
||||||
export const handleHeartbeatPingCommand = (context: ControllerCommandContext, payload: HeartbeatPingPayload) =>
|
export const handleHeartbeatPingCommand = (context: ControllerCommandContext, payload: HeartbeatPingPayload) =>
|
||||||
Effect.gen(function* () {
|
context.offerOutbound(
|
||||||
yield* context.offerOutbound(
|
createAgentMessage("heartbeat.pong", {
|
||||||
createAgentMessage("heartbeat.pong", {
|
sentAt: payload.sentAt,
|
||||||
sentAt: payload.sentAt,
|
}),
|
||||||
}),
|
);
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
|
"plugins": [{ "name": "@effect/language-service" }],
|
||||||
// Environment setup & latest features
|
// Environment setup & latest features
|
||||||
"lib": ["ESNext"],
|
"lib": ["ESNext"],
|
||||||
"target": "ESNext",
|
"target": "ESNext",
|
||||||
|
|
|
||||||
3
bun.lock
3
bun.lock
|
|
@ -75,6 +75,7 @@
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/preset-typescript": "^7.28.5",
|
"@babel/preset-typescript": "^7.28.5",
|
||||||
|
"@effect/language-service": "^0.84.2",
|
||||||
"@faker-js/faker": "^10.3.0",
|
"@faker-js/faker": "^10.3.0",
|
||||||
"@happy-dom/global-registrator": "^20.8.4",
|
"@happy-dom/global-registrator": "^20.8.4",
|
||||||
"@hey-api/openapi-ts": "^0.94.4",
|
"@hey-api/openapi-ts": "^0.94.4",
|
||||||
|
|
@ -292,6 +293,8 @@
|
||||||
|
|
||||||
"@drizzle-team/brocli": ["@drizzle-team/brocli@0.11.0", "", {}, "sha512-hD3pekGiPg0WPCCGAZmusBBJsDqGUR66Y452YgQsZOnkdQ7ViEPKuyP4huUGEZQefp8g34RRodXYmJ2TbCH+tg=="],
|
"@drizzle-team/brocli": ["@drizzle-team/brocli@0.11.0", "", {}, "sha512-hD3pekGiPg0WPCCGAZmusBBJsDqGUR66Y452YgQsZOnkdQ7ViEPKuyP4huUGEZQefp8g34RRodXYmJ2TbCH+tg=="],
|
||||||
|
|
||||||
|
"@effect/language-service": ["@effect/language-service@0.84.2", "", { "bin": { "effect-language-service": "cli.js" } }, "sha512-l04qNxpiA8rY5yXWckRPJ7Mk5MNerXuNymSFf+IdflfI5i8jgL1bpBNLuP6ijg7wgjdHc/KmTnCj2kT0SCntuA=="],
|
||||||
|
|
||||||
"@electric-sql/pglite": ["@electric-sql/pglite@0.3.15", "", {}, "sha512-Cj++n1Mekf9ETfdc16TlDi+cDDQF0W7EcbyRHYOAeZdsAe8M/FJg18itDTSwyHfar2WIezawM9o0EKaRGVKygQ=="],
|
"@electric-sql/pglite": ["@electric-sql/pglite@0.3.15", "", {}, "sha512-Cj++n1Mekf9ETfdc16TlDi+cDDQF0W7EcbyRHYOAeZdsAe8M/FJg18itDTSwyHfar2WIezawM9o0EKaRGVKygQ=="],
|
||||||
|
|
||||||
"@electric-sql/pglite-socket": ["@electric-sql/pglite-socket@0.0.20", "", { "peerDependencies": { "@electric-sql/pglite": "0.3.15" }, "bin": { "pglite-server": "dist/scripts/server.js" } }, "sha512-J5nLGsicnD9wJHnno9r+DGxfcZWh+YJMCe0q/aCgtG6XOm9Z7fKeite8IZSNXgZeGltSigM9U/vAWZQWdgcSFg=="],
|
"@electric-sql/pglite-socket": ["@electric-sql/pglite-socket@0.0.20", "", { "peerDependencies": { "@electric-sql/pglite": "0.3.15" }, "bin": { "pglite-server": "dist/scripts/server.js" } }, "sha512-J5nLGsicnD9wJHnno9r+DGxfcZWh+YJMCe0q/aCgtG6XOm9Z7fKeite8IZSNXgZeGltSigM9U/vAWZQWdgcSFg=="],
|
||||||
|
|
|
||||||
|
|
@ -100,6 +100,7 @@
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/preset-typescript": "^7.28.5",
|
"@babel/preset-typescript": "^7.28.5",
|
||||||
|
"@effect/language-service": "^0.84.2",
|
||||||
"@faker-js/faker": "^10.3.0",
|
"@faker-js/faker": "^10.3.0",
|
||||||
"@happy-dom/global-registrator": "^20.8.4",
|
"@happy-dom/global-registrator": "^20.8.4",
|
||||||
"@hey-api/openapi-ts": "^0.94.4",
|
"@hey-api/openapi-ts": "^0.94.4",
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
|
"plugins": [{ "name": "@effect/language-service" }],
|
||||||
// Environment setup & latest features
|
// Environment setup & latest features
|
||||||
"lib": ["ESNext"],
|
"lib": ["ESNext"],
|
||||||
"target": "ESNext",
|
"target": "ESNext",
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
{
|
{
|
||||||
"include": ["app/**/*"],
|
"include": ["app/**/*"],
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
|
"plugins": [{ "name": "@effect/language-service" }],
|
||||||
"lib": ["DOM", "DOM.Iterable", "ES2023"],
|
"lib": ["DOM", "DOM.Iterable", "ES2023"],
|
||||||
"types": ["bun", "node", "vite/client"],
|
"types": ["bun", "node", "vite/client"],
|
||||||
"target": "ES2022",
|
"target": "ES2022",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue