pty.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. export * as Pty from "./pty"
  2. import { Schema } from "effect"
  3. import { define, inventory } from "./event"
  4. import { ascending } from "./identifier"
  5. import { NonNegativeInt, PositiveInt } from "./schema"
  6. import { withStatics } from "./schema"
  7. const IDSchema = Schema.String.check(Schema.isStartsWith("pty")).pipe(Schema.brand("PtyID"))
  8. export const ID = IDSchema.pipe(
  9. withStatics((schema: typeof IDSchema) => ({
  10. ascending: (id?: string) => schema.make(id ?? "pty_" + ascending()),
  11. })),
  12. )
  13. export type ID = typeof ID.Type
  14. export const Info = Schema.Struct({
  15. id: ID,
  16. title: Schema.String,
  17. command: Schema.String,
  18. args: Schema.Array(Schema.String),
  19. cwd: Schema.String,
  20. status: Schema.Literals(["running", "exited"]),
  21. pid: NonNegativeInt,
  22. exitCode: Schema.optional(NonNegativeInt),
  23. }).annotate({ identifier: "Pty" })
  24. export const PtyInfo = Info
  25. const Created = define({ type: "pty.created", schema: { info: Info } })
  26. const Updated = define({ type: "pty.updated", schema: { info: Info } })
  27. const Exited = define({ type: "pty.exited", schema: { id: ID, exitCode: NonNegativeInt } })
  28. const Deleted = define({ type: "pty.deleted", schema: { id: ID } })
  29. export const Event = { Created, Updated, Exited, Deleted, Definitions: inventory(Created, Updated, Exited, Deleted) }
  30. export const PtyEvent = Event
  31. export const CreateInput = Schema.Struct({
  32. command: Schema.optional(Schema.String),
  33. args: Schema.optional(Schema.Array(Schema.String)),
  34. cwd: Schema.optional(Schema.String),
  35. title: Schema.optional(Schema.String),
  36. env: Schema.optional(Schema.Record(Schema.String, Schema.String)),
  37. })
  38. export type CreateInput = typeof CreateInput.Type
  39. export const UpdateInput = Schema.Struct({
  40. title: Schema.optional(Schema.String),
  41. size: Schema.optional(
  42. Schema.Struct({
  43. rows: PositiveInt,
  44. cols: PositiveInt,
  45. }),
  46. ),
  47. })
  48. export type UpdateInput = typeof UpdateInput.Type