refactor: adapter 구현중..
This commit is contained in:
@@ -15,6 +15,17 @@ export type ValidatedJsonArtifactInput = Readonly<{
|
||||
value: unknown;
|
||||
}>;
|
||||
|
||||
export function serializeValidatedJsonArtifact(
|
||||
input: ValidatedJsonArtifactInput,
|
||||
): Buffer {
|
||||
const parsed = input.schema.parse(input.value);
|
||||
const serialized = JSON.stringify(parsed, null, 2);
|
||||
if (serialized === undefined) {
|
||||
throw new TypeError("Validated JSON artifact is not serializable");
|
||||
}
|
||||
return Buffer.from(`${serialized}\n`, "utf8");
|
||||
}
|
||||
|
||||
export type ValidatedJsonArtifactFileSystem = Readonly<{
|
||||
open: (path: string, flags: number, mode: number) => Promise<{
|
||||
writeFile(data: string, encoding: "utf8"): Promise<unknown>;
|
||||
@@ -64,11 +75,7 @@ export function createValidatedJsonArtifactWriter(
|
||||
return async function writeArtifact(
|
||||
input: ValidatedJsonArtifactInput,
|
||||
): Promise<void> {
|
||||
const parsed = input.schema.parse(input.value);
|
||||
const serialized = JSON.stringify(parsed, null, 2);
|
||||
if (serialized === undefined) {
|
||||
throw new TypeError("Validated JSON artifact is not serializable");
|
||||
}
|
||||
const serialized = serializeValidatedJsonArtifact(input);
|
||||
|
||||
const temporaryPath = path.join(
|
||||
path.dirname(input.path),
|
||||
@@ -88,7 +95,7 @@ export function createValidatedJsonArtifactWriter(
|
||||
let writeFailed = false;
|
||||
let writeFailure: unknown;
|
||||
try {
|
||||
await handle.writeFile(`${serialized}\n`, "utf8");
|
||||
await handle.writeFile(serialized.toString("utf8"), "utf8");
|
||||
await handle.sync();
|
||||
} catch (error) {
|
||||
writeFailed = true;
|
||||
|
||||
Reference in New Issue
Block a user