conversation-session-formal-admission-utils.mjs 759 B

12345678910111213141516171819202122232425262728293031
  1. import { access, readFile } from "node:fs/promises";
  2. import { relative } from "node:path";
  3. export async function readJson(path) {
  4. try {
  5. return { value: JSON.parse(await readFile(path, "utf8")) };
  6. } catch (error) {
  7. return error?.code === "ENOENT" ? { missing: true } : { error };
  8. }
  9. }
  10. export async function exists(path) {
  11. try {
  12. await access(path);
  13. return true;
  14. } catch {
  15. return false;
  16. }
  17. }
  18. export function diagnostic({ code, message, specPath, subjectPath }) {
  19. return { code, message, specPath, subjectPath };
  20. }
  21. export function toRepoPath(root, path) {
  22. return relative(root, path).replaceAll("\\", "/");
  23. }
  24. export function isRecord(value) {
  25. return value !== null && typeof value === "object" && !Array.isArray(value);
  26. }