pty.ts 2.0 KB

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