|
1 | 1 | import { clearScreenDown, cursorTo, moveCursor } from "node:readline"; |
2 | | -import { Cause, Duration, Effect, Exit, Layer, ServiceMap, Tracer } from "effect"; |
3 | | -import { renderError } from "./errors"; |
| 2 | +import { Cause, Duration, Effect, Exit, Layer, Schema, ServiceMap, Tracer } from "effect"; |
| 3 | +import { renderError } from "./errors.ts"; |
4 | 4 |
|
5 | 5 | type ProgressStatus = "running" | "done" | "failed" | "interrupted"; |
6 | 6 |
|
@@ -34,59 +34,73 @@ interface CompactAttributeToken { |
34 | 34 |
|
35 | 35 | export type ProgressRenderMode = "interactive" | "raw"; |
36 | 36 |
|
37 | | -export interface ProgressAttributeDescriptor { |
38 | | - readonly key: string; |
39 | | - readonly label?: string; |
40 | | - readonly value: unknown; |
41 | | - readonly dedupeKey?: string; |
42 | | -} |
| 37 | +export const ProgressAttributeDescriptor = Schema.Struct({ |
| 38 | + key: Schema.String, |
| 39 | + label: Schema.optionalKey(Schema.String), |
| 40 | + value: Schema.Unknown, |
| 41 | + dedupeKey: Schema.optionalKey(Schema.String), |
| 42 | +}); |
43 | 43 |
|
44 | | -export interface ProgressAttributeFormatInput { |
45 | | - readonly key: string; |
46 | | - readonly value: unknown; |
47 | | - readonly defaultLabel: string; |
48 | | -} |
| 44 | +export type ProgressAttributeDescriptor = typeof ProgressAttributeDescriptor.Type; |
49 | 45 |
|
50 | | -export interface ProgressAttributeFormatOutput { |
51 | | - readonly label?: string; |
52 | | - readonly value?: unknown; |
53 | | - readonly dedupeKey?: string; |
54 | | -} |
| 46 | +export const ProgressAttributeFormatInput = Schema.Struct({ |
| 47 | + key: Schema.String, |
| 48 | + value: Schema.Unknown, |
| 49 | + defaultLabel: Schema.String, |
| 50 | +}); |
55 | 51 |
|
56 | | -export interface ProgressStatusSymbols { |
57 | | - readonly runningParent: string; |
58 | | - readonly success: string; |
59 | | - readonly failed: string; |
60 | | - readonly interrupted: string; |
61 | | -} |
| 52 | +export type ProgressAttributeFormatInput = typeof ProgressAttributeFormatInput.Type; |
| 53 | + |
| 54 | +export const ProgressAttributeFormatOutput = Schema.Struct({ |
| 55 | + label: Schema.optionalKey(Schema.String), |
| 56 | + value: Schema.optionalKey(Schema.Unknown), |
| 57 | + dedupeKey: Schema.optionalKey(Schema.String), |
| 58 | +}); |
| 59 | + |
| 60 | +export type ProgressAttributeFormatOutput = typeof ProgressAttributeFormatOutput.Type; |
| 61 | + |
| 62 | +export const ProgressStatusSymbols = Schema.Struct({ |
| 63 | + runningParent: Schema.String, |
| 64 | + success: Schema.String, |
| 65 | + failed: Schema.String, |
| 66 | + interrupted: Schema.String, |
| 67 | +}); |
| 68 | + |
| 69 | +export type ProgressStatusSymbols = typeof ProgressStatusSymbols.Type; |
62 | 70 |
|
63 | 71 | export interface ProgressRenderConfig { |
64 | | - readonly headerLabel?: string; |
65 | | - readonly spinnerFrames?: ReadonlyArray<string>; |
66 | | - readonly symbols?: Partial<ProgressStatusSymbols>; |
67 | | - readonly formatSpanName?: ( |
68 | | - name: string, |
69 | | - options: { |
70 | | - readonly mode: ProgressRenderMode; |
71 | | - readonly span: Tracer.Span; |
72 | | - }, |
73 | | - ) => string; |
74 | | - readonly formatAttributes?: ( |
75 | | - input: { |
76 | | - readonly attributes: ReadonlyMap<string, unknown>; |
77 | | - }, |
78 | | - options: { |
79 | | - readonly mode: ProgressRenderMode; |
80 | | - readonly span: Tracer.Span; |
81 | | - }, |
82 | | - ) => ReadonlyArray<ProgressAttributeDescriptor> | undefined; |
83 | | - readonly formatAttribute?: ( |
84 | | - attribute: ProgressAttributeFormatInput, |
85 | | - options: { |
86 | | - readonly mode: ProgressRenderMode; |
87 | | - readonly span: Tracer.Span; |
88 | | - }, |
89 | | - ) => ProgressAttributeFormatOutput | undefined; |
| 72 | + readonly headerLabel?: string | undefined; |
| 73 | + readonly spinnerFrames?: ReadonlyArray<string> | undefined; |
| 74 | + readonly symbols?: Partial<ProgressStatusSymbols> | undefined; |
| 75 | + readonly formatSpanName?: |
| 76 | + | (( |
| 77 | + name: string, |
| 78 | + options: { |
| 79 | + readonly mode: ProgressRenderMode; |
| 80 | + readonly span: Tracer.Span; |
| 81 | + }, |
| 82 | + ) => string) |
| 83 | + | undefined; |
| 84 | + readonly formatAttributes?: |
| 85 | + | (( |
| 86 | + input: { |
| 87 | + readonly attributes: ReadonlyMap<string, unknown>; |
| 88 | + }, |
| 89 | + options: { |
| 90 | + readonly mode: ProgressRenderMode; |
| 91 | + readonly span: Tracer.Span; |
| 92 | + }, |
| 93 | + ) => ReadonlyArray<ProgressAttributeDescriptor> | undefined) |
| 94 | + | undefined; |
| 95 | + readonly formatAttribute?: |
| 96 | + | (( |
| 97 | + attribute: ProgressAttributeFormatInput, |
| 98 | + options: { |
| 99 | + readonly mode: ProgressRenderMode; |
| 100 | + readonly span: Tracer.Span; |
| 101 | + }, |
| 102 | + ) => ProgressAttributeFormatOutput | undefined) |
| 103 | + | undefined; |
90 | 104 | } |
91 | 105 |
|
92 | 106 | const defaultHeaderLabel = "progress"; |
|
0 commit comments