Adopt Effect JSON and DateTime idioms (#2559)
Co-authored-by: Cursor Agent <[email protected]> Co-authored-by: Julius Marminge <[email protected]>
This commit is contained in:
3 files changed
+38
-24
No files matched your search
@@ -2,6 +2,7 @@ import * as Deferred from "effect/Deferred";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Fiber from "effect/Fiber";
|
||||
import * as Queue from "effect/Queue";
|
||||
import * as Schema from "effect/Schema";
|
||||
import * as Stream from "effect/Stream";
|
||||
|
||||
import * as NodeServices from "@effect/platform-node/NodeServices";
|
||||
@@ -13,7 +14,10 @@ import { makeInMemoryStdio } from "./_internal/stdio.ts";
|
||||
|
||||
const encoder = new TextEncoder();
|
||||
|
||||
const encodeJsonl = (value: unknown) => encoder.encode(`${JSON.stringify(value)}\n`);
|
||||
const encodeJsonl = (value: unknown) =>
|
||||
encoder.encode(`${Schema.encodeUnknownSync(Schema.UnknownFromJsonString)(value)}\n`);
|
||||
|
||||
const decodeJson = Schema.decodeEffect(Schema.UnknownFromJsonString);
|
||||
|
||||
it.layer(NodeServices.layer)("effect-codex-app-server protocol", (it) => {
|
||||
it.effect(
|
||||
@@ -60,7 +64,7 @@ it.layer(NodeServices.layer)("effect-codex-app-server protocol", (it) => {
|
||||
const pendingInitialize = yield* transport
|
||||
.request("initialize", initializeParams)
|
||||
.pipe(Effect.forkScoped);
|
||||
assert.deepEqual(JSON.parse(yield* Queue.take(output)), {
|
||||
assert.deepEqual(yield* decodeJson(yield* Queue.take(output)), {
|
||||
id: 1,
|
||||
method: "initialize",
|
||||
params: initializeParams,
|
||||
@@ -153,7 +157,7 @@ it.layer(NodeServices.layer)("effect-codex-app-server protocol", (it) => {
|
||||
},
|
||||
},
|
||||
});
|
||||
assert.deepEqual(JSON.parse(yield* Queue.take(output)), {
|
||||
assert.deepEqual(yield* decodeJson(yield* Queue.take(output)), {
|
||||
id: 77,
|
||||
result: {
|
||||
answers: {
|
||||
@@ -168,7 +172,7 @@ it.layer(NodeServices.layer)("effect-codex-app-server protocol", (it) => {
|
||||
78,
|
||||
CodexError.CodexAppServerRequestError.methodNotFound("x/test"),
|
||||
);
|
||||
assert.deepEqual(JSON.parse(yield* Queue.take(output)), {
|
||||
assert.deepEqual(yield* decodeJson(yield* Queue.take(output)), {
|
||||
id: 78,
|
||||
error: {
|
||||
code: -32601,
|
||||
|
||||
@@ -83,17 +83,35 @@ function isIncomingResponse(value: unknown): value is typeof JsonRpcResponseEnve
|
||||
return Schema.is(JsonRpcResponseEnvelope)(value);
|
||||
}
|
||||
|
||||
const encodeJsonString = Schema.encodeUnknownEffect(Schema.UnknownFromJsonString);
|
||||
const decodeJsonString = Schema.decodeUnknownEffect(Schema.UnknownFromJsonString);
|
||||
|
||||
const encodeWireMessage = (
|
||||
message: Record<string, unknown>,
|
||||
): Effect.Effect<string, CodexError.CodexAppServerProtocolParseError> =>
|
||||
Effect.try({
|
||||
try: () => `${JSON.stringify(message)}\n`,
|
||||
catch: (cause) =>
|
||||
new CodexError.CodexAppServerProtocolParseError({
|
||||
detail: "Failed to encode Codex App Server message",
|
||||
cause,
|
||||
}),
|
||||
});
|
||||
encodeJsonString(message).pipe(
|
||||
Effect.map((encoded) => `${encoded}\n`),
|
||||
Effect.mapError(
|
||||
(cause) =>
|
||||
new CodexError.CodexAppServerProtocolParseError({
|
||||
detail: "Failed to encode Codex App Server message",
|
||||
cause,
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
const decodeWireMessage = (
|
||||
line: string,
|
||||
): Effect.Effect<unknown, CodexError.CodexAppServerProtocolParseError> =>
|
||||
decodeJsonString(line).pipe(
|
||||
Effect.mapError(
|
||||
(cause) =>
|
||||
new CodexError.CodexAppServerProtocolParseError({
|
||||
detail: "Failed to decode Codex App Server wire message",
|
||||
cause,
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
const normalizeIncomingError = (error: unknown, detail: string): CodexError.CodexAppServerError =>
|
||||
Schema.is(CodexError.CodexAppServerError)(error)
|
||||
@@ -284,16 +302,7 @@ export const makeCodexAppServerPatchedProtocol = Effect.fn("makeCodexAppServerPa
|
||||
stage: "raw",
|
||||
payload: line,
|
||||
}).pipe(
|
||||
Effect.flatMap(() =>
|
||||
Effect.try({
|
||||
try: () => JSON.parse(line),
|
||||
catch: (cause) =>
|
||||
new CodexError.CodexAppServerProtocolParseError({
|
||||
detail: "Failed to decode Codex App Server wire message",
|
||||
cause,
|
||||
}),
|
||||
}),
|
||||
),
|
||||
Effect.flatMap(() => decodeWireMessage(line)),
|
||||
Effect.tap((decoded) =>
|
||||
logProtocol({
|
||||
direction: "incoming",
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import * as NodeRuntime from "@effect/platform-node/NodeRuntime";
|
||||
import * as NodeServices from "@effect/platform-node/NodeServices";
|
||||
import { Config, Data, Effect, Layer, Logger, Schema } from "effect";
|
||||
import { Config, Data, DateTime, Effect, Layer, Logger, Schema } from "effect";
|
||||
import { Argument, Command, Flag } from "effect/unstable/cli";
|
||||
import {
|
||||
FetchHttpClient,
|
||||
@@ -201,6 +201,7 @@ export const notifyDiscordReleaseCommand = Command.make(
|
||||
);
|
||||
|
||||
const webhookUrl = yield* DiscordWebhookUrl;
|
||||
const timestamp = DateTime.formatIso(yield* DateTime.now);
|
||||
const payload = buildDiscordReleaseAnnouncement({
|
||||
target,
|
||||
roleId,
|
||||
@@ -208,7 +209,7 @@ export const notifyDiscordReleaseCommand = Command.make(
|
||||
version: releaseVersion,
|
||||
tag,
|
||||
releaseUrl,
|
||||
timestamp: new Date().toISOString(),
|
||||
timestamp,
|
||||
});
|
||||
|
||||
yield* Effect.logInfo("discord release announcement payload built").pipe(
|
||||
|
||||
Reference in new issue
Block a user