filesystem.ts 1.3 KB

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