@composable-os/pack-programs 0.1.0-beta.10 → 0.1.0-beta.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/authoring.d.ts +4 -1
- package/dist/authoring.js +65 -5
- package/dist/blocks/programs-builder/program-builder.d.ts +12 -3
- package/dist/blocks/programs-builder/program-builder.js +16 -3
- package/dist/blocks/programs-class-today/class-today.d.ts +1 -1
- package/dist/blocks/programs-coach-client/coach-client.d.ts +1 -1
- package/dist/blocks/programs-history/history.d.ts +11 -0
- package/dist/blocks/programs-history/history.js +84 -0
- package/dist/blocks/programs-native-class-today/class-today-screen.js +3 -2
- package/dist/blocks/programs-native-coach-client/coach-client-screen.js +2 -2
- package/dist/blocks/programs-native-history/history-screen.d.ts +11 -0
- package/dist/blocks/programs-native-history/history-screen.js +98 -0
- package/dist/blocks/programs-native-progress/progress-screen.js +4 -4
- package/dist/blocks/programs-native-session/session-screen.d.ts +6 -2
- package/dist/blocks/programs-native-session/session-screen.js +214 -88
- package/dist/blocks/programs-native-today/today-screen.d.ts +1 -1
- package/dist/blocks/programs-native-today/today-screen.js +22 -3
- package/dist/blocks/programs-session/session-view.d.ts +7 -3
- package/dist/blocks/programs-session/session-view.js +139 -81
- package/dist/blocks/programs-today/today.d.ts +1 -1
- package/dist/client/index.d.ts +367 -12
- package/dist/client/index.js +393 -12
- package/dist/client/logging.d.ts +289 -0
- package/dist/client/logging.js +558 -0
- package/dist/index.d.ts +152 -6
- package/dist/index.js +141 -6
- package/dist/layout.d.ts +3 -1
- package/dist/layout.js +10 -2
- package/dist/tools.d.ts +25 -2
- package/dist/tools.js +269 -37
- package/package.json +3 -3
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
import type { Session, SetTarget } from "../layout.ts";
|
|
2
|
+
/** A set's fields as typed: text, so "7." or "" while someone types. */
|
|
3
|
+
export interface SetValues {
|
|
4
|
+
reps?: string;
|
|
5
|
+
seconds?: string;
|
|
6
|
+
load?: string;
|
|
7
|
+
}
|
|
8
|
+
export type SetField = keyof SetValues;
|
|
9
|
+
/** One exercise of a session's plan, as the logger works with it. */
|
|
10
|
+
export interface LogExercise {
|
|
11
|
+
item: string;
|
|
12
|
+
exercise: string;
|
|
13
|
+
/** The level it is at, for an item with levels. */
|
|
14
|
+
level: number | null;
|
|
15
|
+
targets: SetTarget[];
|
|
16
|
+
/** The person's sets of it last time, in order. */
|
|
17
|
+
last: {
|
|
18
|
+
reps: number | null;
|
|
19
|
+
seconds: number | null;
|
|
20
|
+
load: number | null;
|
|
21
|
+
}[];
|
|
22
|
+
}
|
|
23
|
+
/** A set as the host has it logged (`x.programs.sessionGet`'s `logged`). */
|
|
24
|
+
export interface HostSet {
|
|
25
|
+
item: string | null;
|
|
26
|
+
exercise: string | null;
|
|
27
|
+
setNumber: number | null;
|
|
28
|
+
level: number | null;
|
|
29
|
+
actual: {
|
|
30
|
+
reps: number | null;
|
|
31
|
+
seconds: number | null;
|
|
32
|
+
load: number | null;
|
|
33
|
+
};
|
|
34
|
+
rpe: number | null;
|
|
35
|
+
}
|
|
36
|
+
export interface LocalSet {
|
|
37
|
+
done: boolean;
|
|
38
|
+
/** What the person typed, every field of the row from their first edit; null: not edited. */
|
|
39
|
+
entered: SetValues | null;
|
|
40
|
+
/** The numbers it was ticked with, while done. */
|
|
41
|
+
ticked: SetValues | null;
|
|
42
|
+
rpe: number | null;
|
|
43
|
+
/** Bumped by every change this screen makes that the host must hear of. */
|
|
44
|
+
rev: number;
|
|
45
|
+
/** The revision the host has. */
|
|
46
|
+
saved: number;
|
|
47
|
+
/** Whether the host has it logged: as last answered; "unknown" after a failed save. */
|
|
48
|
+
host: "logged" | "absent" | "unknown";
|
|
49
|
+
/** Why its last save failed, to say so beside it. */
|
|
50
|
+
error: string | null;
|
|
51
|
+
/** The host refused it: kept as entered, not sent again until it changes. */
|
|
52
|
+
refused: boolean;
|
|
53
|
+
}
|
|
54
|
+
export interface LogState {
|
|
55
|
+
/** By `exerciseKey`. */
|
|
56
|
+
exercises: Record<string, LogExercise>;
|
|
57
|
+
/** By `setKey`. */
|
|
58
|
+
sets: Record<string, LocalSet>;
|
|
59
|
+
/** The level chosen at each item with levels. */
|
|
60
|
+
levels: Record<string, number>;
|
|
61
|
+
/** Sets waiting to be saved, in order. */
|
|
62
|
+
queue: string[];
|
|
63
|
+
/** The save out now: one at a time, with what it sends. */
|
|
64
|
+
inFlight: {
|
|
65
|
+
key: string;
|
|
66
|
+
rev: number;
|
|
67
|
+
token: number;
|
|
68
|
+
op: SaveOp;
|
|
69
|
+
} | null;
|
|
70
|
+
/** The last token given to a save. */
|
|
71
|
+
token: number;
|
|
72
|
+
/** A save failed and waits to be retried; the queue waits with it, so saves stay in order. */
|
|
73
|
+
blocked: boolean;
|
|
74
|
+
/** The last failure, to say so: cleared when a save succeeds. */
|
|
75
|
+
failure: string | null;
|
|
76
|
+
/** The save that failed: sent again as it was (the same idempotency key) if its set is unchanged. */
|
|
77
|
+
failedOp: SaveOp | null;
|
|
78
|
+
}
|
|
79
|
+
export declare const exerciseKey: (item: string, exercise: string) => string;
|
|
80
|
+
export declare const setKey: (item: string, exercise: string, setNumber: number) => string;
|
|
81
|
+
export declare function emptyLog(): LogState;
|
|
82
|
+
/** The exercises a session's plan asks to be logged: every block's items (not the warm-up). */
|
|
83
|
+
export declare function logExercisesOf(plan: Session | null, exercises: readonly {
|
|
84
|
+
id: string;
|
|
85
|
+
last: LogExercise["last"];
|
|
86
|
+
}[]): LogExercise[];
|
|
87
|
+
/** A number typed in a field, or undefined when it is empty or not one. */
|
|
88
|
+
export declare function numberIn(text: string | undefined): number | undefined;
|
|
89
|
+
/** Whether a set counts seconds (time, hold) or reps. */
|
|
90
|
+
export declare const timed: (target: SetTarget | undefined) => target is {
|
|
91
|
+
kind: "time";
|
|
92
|
+
seconds: number;
|
|
93
|
+
load?: number;
|
|
94
|
+
rest?: number;
|
|
95
|
+
} | {
|
|
96
|
+
kind: "hold";
|
|
97
|
+
seconds: number;
|
|
98
|
+
holds?: number;
|
|
99
|
+
load?: number;
|
|
100
|
+
rest?: number;
|
|
101
|
+
};
|
|
102
|
+
/** What a set's row shows: its numbers, and whether they are a suggestion (greyed). */
|
|
103
|
+
export interface Shown {
|
|
104
|
+
values: SetValues;
|
|
105
|
+
suggested: boolean;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* The numbers set `setNumber` of an exercise shows. Done: what it was ticked with. Edited: what
|
|
109
|
+
* was typed. Otherwise a suggestion: for the first set, last time's numbers, else the target; for
|
|
110
|
+
* a later set, the numbers the set before it shows, so a change flows down. A field whose target
|
|
111
|
+
* differs from the set before's (a planned drop, a heavier top set) suggests its own target.
|
|
112
|
+
*/
|
|
113
|
+
export declare function shownValues(state: LogState, item: string, exercise: string, setNumber: number): Shown;
|
|
114
|
+
export type LogAction =
|
|
115
|
+
/** The host's read of the session: the plan's exercises and what it has logged. */
|
|
116
|
+
{
|
|
117
|
+
type: "load";
|
|
118
|
+
exercises: LogExercise[];
|
|
119
|
+
logged: readonly HostSet[];
|
|
120
|
+
}
|
|
121
|
+
/** Tick (log) a set with the numbers shown, or with `values` over them (a timer's seconds). */
|
|
122
|
+
| {
|
|
123
|
+
type: "tick";
|
|
124
|
+
item: string;
|
|
125
|
+
exercise: string;
|
|
126
|
+
setNumber: number;
|
|
127
|
+
values?: SetValues;
|
|
128
|
+
}
|
|
129
|
+
/** Take a ticked set back. */
|
|
130
|
+
| {
|
|
131
|
+
type: "untick";
|
|
132
|
+
item: string;
|
|
133
|
+
exercise: string;
|
|
134
|
+
setNumber: number;
|
|
135
|
+
}
|
|
136
|
+
/** A tick of a set's tick box: a done set is taken back, any other ticked. */
|
|
137
|
+
| {
|
|
138
|
+
type: "toggle";
|
|
139
|
+
item: string;
|
|
140
|
+
exercise: string;
|
|
141
|
+
setNumber: number;
|
|
142
|
+
}
|
|
143
|
+
/** A key press in one of a set's fields. */
|
|
144
|
+
| {
|
|
145
|
+
type: "edit";
|
|
146
|
+
item: string;
|
|
147
|
+
exercise: string;
|
|
148
|
+
setNumber: number;
|
|
149
|
+
field: SetField;
|
|
150
|
+
text: string;
|
|
151
|
+
}
|
|
152
|
+
/** How hard it felt; null clears it. Optional, never needed to tick. */
|
|
153
|
+
| {
|
|
154
|
+
type: "rpe";
|
|
155
|
+
item: string;
|
|
156
|
+
exercise: string;
|
|
157
|
+
setNumber: number;
|
|
158
|
+
rpe: number | null;
|
|
159
|
+
}
|
|
160
|
+
/** The level taken at an item with levels. */
|
|
161
|
+
| {
|
|
162
|
+
type: "level";
|
|
163
|
+
item: string;
|
|
164
|
+
level: number;
|
|
165
|
+
}
|
|
166
|
+
/** The store takes the next save off the queue. */
|
|
167
|
+
| {
|
|
168
|
+
type: "begin";
|
|
169
|
+
}
|
|
170
|
+
/** The save with this token was answered. */
|
|
171
|
+
| {
|
|
172
|
+
type: "saved";
|
|
173
|
+
token: number;
|
|
174
|
+
}
|
|
175
|
+
/** The save with this token failed; `retry` when it is worth sending again. */
|
|
176
|
+
| {
|
|
177
|
+
type: "failed";
|
|
178
|
+
token: number;
|
|
179
|
+
message: string;
|
|
180
|
+
retry: boolean;
|
|
181
|
+
}
|
|
182
|
+
/** Send the failed save again. */
|
|
183
|
+
| {
|
|
184
|
+
type: "retry";
|
|
185
|
+
};
|
|
186
|
+
/** Applies one change. Pure: the state given is left as it was. */
|
|
187
|
+
export declare function logReducer(state: LogState, action: LogAction): LogState;
|
|
188
|
+
/** One save: log a set with its numbers, or take it back. */
|
|
189
|
+
export type SaveOp = {
|
|
190
|
+
kind: "log";
|
|
191
|
+
key: string;
|
|
192
|
+
rev: number;
|
|
193
|
+
item: string;
|
|
194
|
+
exercise: string;
|
|
195
|
+
level: number | null;
|
|
196
|
+
setNumber: number;
|
|
197
|
+
actual: {
|
|
198
|
+
reps?: number;
|
|
199
|
+
seconds?: number;
|
|
200
|
+
load?: number;
|
|
201
|
+
};
|
|
202
|
+
rpe: number | null;
|
|
203
|
+
} | {
|
|
204
|
+
kind: "remove";
|
|
205
|
+
key: string;
|
|
206
|
+
rev: number;
|
|
207
|
+
item: string;
|
|
208
|
+
exercise: string;
|
|
209
|
+
setNumber: number;
|
|
210
|
+
};
|
|
211
|
+
/** What the save out now sends: its set as it was when it went (the latest change then). */
|
|
212
|
+
export declare function saveFor(state: LogState): SaveOp | null;
|
|
213
|
+
/** The level an item is logged at: the one chosen, else its only one. Null: not chosen yet. */
|
|
214
|
+
export declare function levelOf(state: LogState, item: string): number | null;
|
|
215
|
+
/** The exercises being done: everyone's, and at an item with levels the level taken (else its first). */
|
|
216
|
+
export declare function exercisesInPlay(state: LogState): LogExercise[];
|
|
217
|
+
/** Sets done of the sets planned, over the exercises being done. */
|
|
218
|
+
export declare function progressOf(state: LogState): {
|
|
219
|
+
done: number;
|
|
220
|
+
planned: number;
|
|
221
|
+
};
|
|
222
|
+
/** Whether every set of an exercise is ticked: it folds away. */
|
|
223
|
+
export declare function exerciseDone(state: LogState, item: string, exercise: string): boolean;
|
|
224
|
+
/** The sets not ticked, by exercise, to say so when the session is finished. */
|
|
225
|
+
export declare function notTicked(state: LogState): {
|
|
226
|
+
item: string;
|
|
227
|
+
exercise: string;
|
|
228
|
+
setNumbers: number[];
|
|
229
|
+
}[];
|
|
230
|
+
/** How many sets have a change the host has not had yet. */
|
|
231
|
+
export declare function unsaved(state: LogState): number;
|
|
232
|
+
/** The sets the host refused, with its reason. */
|
|
233
|
+
export declare function refusedSets(state: LogState): {
|
|
234
|
+
key: string;
|
|
235
|
+
message: string;
|
|
236
|
+
}[];
|
|
237
|
+
/** The rest after a set: its own rest time, else the screen's. */
|
|
238
|
+
export declare function restAfter(target: SetTarget | undefined, fallback: number): number;
|
|
239
|
+
/** Whole seconds from `from` to `to` (ms), never below zero. */
|
|
240
|
+
export declare function secondsBetween(from: number, to: number): number;
|
|
241
|
+
/** Timers, as the platform has them (every one these run on has `setTimeout`). */
|
|
242
|
+
interface Timers {
|
|
243
|
+
set(fn: () => void, ms: number): unknown;
|
|
244
|
+
clear(handle: unknown): void;
|
|
245
|
+
}
|
|
246
|
+
export interface SessionLogOptions {
|
|
247
|
+
/** Sends one save to the host; throws when it fails. The same `op` object for a retry. */
|
|
248
|
+
send(op: SaveOp): Promise<unknown>;
|
|
249
|
+
/** How long to wait before the `attempt`th retry. Default 1 s, doubling, at most 30 s. */
|
|
250
|
+
retryDelay?: (attempt: number) => number;
|
|
251
|
+
timers?: Timers;
|
|
252
|
+
}
|
|
253
|
+
export interface SessionLog {
|
|
254
|
+
getState(): LogState;
|
|
255
|
+
/** A person's change: shown at once, and queued for the host when it must hear of it. */
|
|
256
|
+
dispatch(action: LogAction): void;
|
|
257
|
+
subscribe(listener: () => void): () => void;
|
|
258
|
+
/**
|
|
259
|
+
* Sends everything waiting now (leaving the screen, the app going to the background, finishing
|
|
260
|
+
* the session), retrying a failed save at once. True when the host has it all; false when a
|
|
261
|
+
* save failed or `timeoutMs` passed first. What is not saved is kept and still retried.
|
|
262
|
+
*/
|
|
263
|
+
flush(timeoutMs?: number): Promise<boolean>;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Whether a failed save is worth sending again: anything but the host's refusal (a 4xx that is
|
|
267
|
+
* not a timeout, a conflict over its key in flight or too many calls). A refusal is kept on
|
|
268
|
+
* screen with its message.
|
|
269
|
+
*/
|
|
270
|
+
export declare function retryable(error: unknown): boolean;
|
|
271
|
+
/** A session's queue: saves sent to the host one at a time, in order, retried until they land. */
|
|
272
|
+
export declare function createSessionLog(options: SessionLogOptions): SessionLog;
|
|
273
|
+
/** One set's row: its numbers (greyed when suggested), whether it is done, its effort and state. */
|
|
274
|
+
export interface SetRowView extends Shown {
|
|
275
|
+
done: boolean;
|
|
276
|
+
rpe: number | null;
|
|
277
|
+
/** Changed here and not yet on the host. */
|
|
278
|
+
saving: boolean;
|
|
279
|
+
/** Why its save failed, when it did. */
|
|
280
|
+
error: string | null;
|
|
281
|
+
}
|
|
282
|
+
export declare function setRow(state: LogState, item: string, exercise: string, setNumber: number): SetRowView;
|
|
283
|
+
/** Whether an exercise's sets have a load field: weighed, or a load planned or done last time. */
|
|
284
|
+
export declare function weighed(e: LogExercise | undefined, measure: string | null | undefined): boolean;
|
|
285
|
+
/** "A1 Back squat: sets 2 and 3; B1 Plank: set 2", to say plainly what was not ticked. */
|
|
286
|
+
export declare function notTickedText(state: LogState, nameOf: (exercise: string) => string | null | undefined): string | null;
|
|
287
|
+
/** The efforts a set offers to tap (RPE in halves, the hard end). */
|
|
288
|
+
export declare const EFFORTS: readonly [6, 7, 7.5, 8, 8.5, 9, 9.5, 10];
|
|
289
|
+
export {};
|