filesystem.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. export * as FileSystem from "./filesystem.js"
  2. import { Schema } from "effect"
  3. import { optional } from "./schema.js"
  4. import { ephemeral, inventory } from "./event.js"
  5. import { NonNegativeInt, PositiveInt, RelativePath } from "./schema.js"
  6. const Changed = ephemeral({
  7. type: "filesystem.changed",
  8. schema: {
  9. file: Schema.String,
  10. event: Schema.Literals(["add", "change", "unlink"]),
  11. },
  12. })
  13. export const Event = { Changed, Definitions: inventory(Changed) }
  14. export interface Entry extends Schema.Schema.Type<typeof Entry> {}
  15. export const Entry = Schema.Struct({
  16. path: RelativePath,
  17. type: Schema.Literals(["file", "directory"]),
  18. }).annotate({ identifier: "FileSystem.Entry" })
  19. export interface Submatch extends Schema.Schema.Type<typeof Submatch> {}
  20. export const Submatch = Schema.Struct({
  21. text: Schema.String,
  22. start: NonNegativeInt,
  23. end: NonNegativeInt,
  24. }).annotate({ identifier: "FileSystem.Submatch" })
  25. export interface Match extends Schema.Schema.Type<typeof Match> {}
  26. export const Match = Schema.Struct({
  27. entry: Entry,
  28. line: PositiveInt,
  29. offset: NonNegativeInt,
  30. text: Schema.String,
  31. submatches: Schema.Array(Submatch),
  32. }).annotate({ identifier: "FileSystem.Match" })
  33. export class FindInput extends Schema.Class<FindInput>("FileSystem.FindInput")({
  34. query: Schema.String,
  35. type: Schema.Literals(["file", "directory"]).pipe(optional),
  36. limit: PositiveInt.pipe(optional),
  37. }) {}