@teamkeel/solver 0.0.0-stage → 0.509.1
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/index.cjs +6878 -0
- package/dist/index.d.cts +9 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +6850 -0
- package/dist/internal.cjs +17244 -0
- package/dist/internal.d.cts +1275 -0
- package/dist/internal.d.ts +1275 -0
- package/dist/internal.js +17164 -0
- package/dist/layout-ZQ45Tlkb.d.cts +2111 -0
- package/dist/layout-efr1Ke_2.d.ts +2111 -0
- package/dist/layout.cjs +19 -0
- package/dist/layout.d.cts +2 -0
- package/dist/layout.d.ts +2 -0
- package/dist/layout.js +1 -0
- package/dist/record-results-BWnJIpkK.d.ts +222 -0
- package/dist/record-results-DPczGZWH.d.cts +222 -0
- package/dist/types-DIFPlxBZ.d.cts +1865 -0
- package/dist/types-DIFPlxBZ.d.ts +1865 -0
- package/fixtures/operation/bakery/operation.json +350 -0
- package/fixtures/operation/bakery/plan.json +872 -0
- package/fixtures/operation/bakery/readback.json +114 -0
- package/fixtures/operation/bakery/score.json +1520 -0
- package/fixtures/operation/bakery/timeline.json +2376 -0
- package/fixtures/operation/clinic/operation.json +223 -0
- package/fixtures/operation/clinic/plan.json +383 -0
- package/fixtures/operation/clinic/readback.json +83 -0
- package/fixtures/operation/clinic/score.json +1305 -0
- package/fixtures/operation/clinic/timeline.json +2283 -0
- package/fixtures/operation/field-service/operation.json +194 -0
- package/fixtures/operation/field-service/plan.json +172 -0
- package/fixtures/operation/field-service/readback.json +73 -0
- package/fixtures/operation/field-service/score.json +585 -0
- package/fixtures/operation/field-service/timeline.json +661 -0
- package/fixtures/operation/filling/operation.json +245 -0
- package/fixtures/operation/filling/plan.json +525 -0
- package/fixtures/operation/filling/readback.json +87 -0
- package/fixtures/operation/filling/score.json +756 -0
- package/fixtures/operation/filling/timeline.json +1322 -0
- package/fixtures/operation/shop/operation.json +320 -0
- package/fixtures/operation/shop/plan.json +664 -0
- package/fixtures/operation/shop/readback.json +130 -0
- package/fixtures/operation/shop/score.json +1106 -0
- package/fixtures/operation/shop/timeline.json +2734 -0
- package/fixtures/operation/warehouse-day/operation.json +517 -0
- package/fixtures/operation/warehouse-day/plan.json +477 -0
- package/fixtures/operation/warehouse-day/readback.json +207 -0
- package/fixtures/operation/warehouse-day/score.json +979 -0
- package/fixtures/operation/warehouse-day/timeline.json +1420 -0
- package/package.json +63 -4
- package/README.md +0 -3
|
@@ -0,0 +1,1865 @@
|
|
|
1
|
+
/** Every problem a reader can report about a build. Codes are stable; messages are for people. */
|
|
2
|
+
type IrIssueCode = "ir-schema-unsupported" | "ir-invalid" | "ir-not-canonical" | "ir-dangling-ref" | "ir-duplicate-id" | "ir-generated-order" | "build-hash-mismatch";
|
|
3
|
+
interface IrIssue {
|
|
4
|
+
code: IrIssueCode;
|
|
5
|
+
/** JSON Pointer (RFC 6901) into the IR, "" for the whole document. */
|
|
6
|
+
path: string;
|
|
7
|
+
message: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
type Kind$1 = "machine" | "line" | "tank" | "door" | "station" | "space" | "vehicle";
|
|
11
|
+
type Period = "day" | "shift" | "week" | "fortnight";
|
|
12
|
+
type Weekday = "Monday" | "Tuesday" | "Wednesday" | "Thursday" | "Friday" | "Saturday" | "Sunday";
|
|
13
|
+
interface Sentence {
|
|
14
|
+
readonly about: string;
|
|
15
|
+
readonly says: string;
|
|
16
|
+
readonly assumed?: true;
|
|
17
|
+
readonly plain?: string;
|
|
18
|
+
}
|
|
19
|
+
interface ModelRefusal {
|
|
20
|
+
readonly about: string;
|
|
21
|
+
readonly says: string;
|
|
22
|
+
readonly asks?: string;
|
|
23
|
+
}
|
|
24
|
+
interface ReadBack {
|
|
25
|
+
readonly sentences: readonly Sentence[];
|
|
26
|
+
readonly refusals: readonly ModelRefusal[];
|
|
27
|
+
/** The prepared top-level keys no word names, sorted; `[]` without data. */
|
|
28
|
+
readonly unread: readonly string[];
|
|
29
|
+
toString(): string;
|
|
30
|
+
}
|
|
31
|
+
interface Printed {
|
|
32
|
+
readonly schedule?: string;
|
|
33
|
+
readonly needs: readonly string[];
|
|
34
|
+
toString(): string;
|
|
35
|
+
}
|
|
36
|
+
interface OptionalRecord {
|
|
37
|
+
readonly optional?: true;
|
|
38
|
+
}
|
|
39
|
+
type NotDoneExpr = {
|
|
40
|
+
readonly kind: "notDone";
|
|
41
|
+
readonly process: string;
|
|
42
|
+
};
|
|
43
|
+
interface SkipEmptyRecord {
|
|
44
|
+
readonly skipsWhenEmpty?: true;
|
|
45
|
+
}
|
|
46
|
+
interface AsapRecord {
|
|
47
|
+
readonly asap?: true;
|
|
48
|
+
}
|
|
49
|
+
interface DispatchRecord {
|
|
50
|
+
readonly dispatch?: {
|
|
51
|
+
readonly lines: readonly string[];
|
|
52
|
+
readonly last: readonly string[];
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
interface ReadyBeforeRecord {
|
|
56
|
+
readonly readyBefore?: {
|
|
57
|
+
readonly on: string;
|
|
58
|
+
readonly inOrderOf: string;
|
|
59
|
+
readonly emptyOnly: boolean;
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
interface TableRunCost<K extends string = string> {
|
|
63
|
+
readonly changeovers: "fromTable";
|
|
64
|
+
/** The run row's family column; the downtime's change key still identifies its product. */
|
|
65
|
+
readonly family: K;
|
|
66
|
+
readonly work?: "busiest piece";
|
|
67
|
+
readonly batchSize?: string;
|
|
68
|
+
readonly batches?: "from function";
|
|
69
|
+
}
|
|
70
|
+
interface CoverRecord extends PooledRecord, RaiseUseRecord {
|
|
71
|
+
readonly cover?: CoverAmount;
|
|
72
|
+
readonly level?: StorageUseOptions<string, string>["level"];
|
|
73
|
+
}
|
|
74
|
+
/** Storage choices use the same release words as an ordinary held use. */
|
|
75
|
+
type StorageUseOptions<Peak, Until, Minimum = string> = RaiseUseOptions<Minimum> & {
|
|
76
|
+
inOrder?: boolean;
|
|
77
|
+
until?: Until;
|
|
78
|
+
/** Choose vessels covering a peak column, or a share of what is made plus fixed room. */
|
|
79
|
+
cover?: Peak | AmountCover<Peak> | CoverShape<Peak>;
|
|
80
|
+
level?: {
|
|
81
|
+
readonly filledBy: string;
|
|
82
|
+
readonly emptiedBy: Readonly<Record<string, Peak>>;
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
/** Room needed per unit made, plus an optional fixed amount in the equipment's unit. */
|
|
86
|
+
type AmountCover<Column> = {
|
|
87
|
+
readonly share: Column;
|
|
88
|
+
readonly plus?: Column;
|
|
89
|
+
};
|
|
90
|
+
type CoverAmount = string | AmountCover<string> | CoverShape<string>;
|
|
91
|
+
/** A straight room requirement, with coefficients given here or read from each run. */
|
|
92
|
+
type CoverLine<Column> = {
|
|
93
|
+
readonly share: Column | number;
|
|
94
|
+
readonly plus?: Column | number;
|
|
95
|
+
};
|
|
96
|
+
/** Cover the smaller (atMost) or larger (atLeast) of these room requirements. */
|
|
97
|
+
type CoverShape<Column> = {
|
|
98
|
+
readonly atMost: readonly [
|
|
99
|
+
CoverLine<Column>,
|
|
100
|
+
CoverLine<Column>,
|
|
101
|
+
...CoverLine<Column>[]
|
|
102
|
+
];
|
|
103
|
+
} | {
|
|
104
|
+
readonly atLeast: readonly [
|
|
105
|
+
CoverLine<Column>,
|
|
106
|
+
CoverLine<Column>,
|
|
107
|
+
...CoverLine<Column>[]
|
|
108
|
+
];
|
|
109
|
+
};
|
|
110
|
+
/** Leave material in the same vessel(s) for a step of another process. */
|
|
111
|
+
interface SharedUntil {
|
|
112
|
+
readonly step: string;
|
|
113
|
+
readonly of: string;
|
|
114
|
+
/** This row's field names the taking row's id. Omit only for one taking run. */
|
|
115
|
+
readonly by?: string;
|
|
116
|
+
/** A minimum sit after filling, in minutes or a numeric field of this row. */
|
|
117
|
+
readonly sit?: string;
|
|
118
|
+
}
|
|
119
|
+
interface PooledRecord {
|
|
120
|
+
readonly sharedUntil?: SharedUntil;
|
|
121
|
+
}
|
|
122
|
+
/** Raise each batch to the chosen equipment member's minimum amount. */
|
|
123
|
+
interface RaiseUseOptions<Column = string> {
|
|
124
|
+
readonly raiseTo?: Column;
|
|
125
|
+
}
|
|
126
|
+
interface RaiseUseRecord {
|
|
127
|
+
readonly raiseTo?: string;
|
|
128
|
+
}
|
|
129
|
+
/** Earliest request for a changeover, following the solved order on one machine. */
|
|
130
|
+
type WashLookahead = RunWashLookahead | {
|
|
131
|
+
readonly step: string;
|
|
132
|
+
readonly batchesAhead: number;
|
|
133
|
+
readonly runsAhead?: never;
|
|
134
|
+
};
|
|
135
|
+
interface WashTimingRecord {
|
|
136
|
+
readonly washLookahead?: WashLookahead;
|
|
137
|
+
}
|
|
138
|
+
/** Earliest wash request, counted in first-portion starts on one machine. */
|
|
139
|
+
interface RunWashLookahead {
|
|
140
|
+
readonly step: string;
|
|
141
|
+
readonly runsAhead: number;
|
|
142
|
+
readonly batchesAhead?: never;
|
|
143
|
+
}
|
|
144
|
+
/** The recorded period; old declarations keep their original string or null. */
|
|
145
|
+
type QuantityPeriod = Period | "plan" | {
|
|
146
|
+
readonly days: number;
|
|
147
|
+
};
|
|
148
|
+
interface ShortShipsRecord {
|
|
149
|
+
readonly short?: "allowed";
|
|
150
|
+
}
|
|
151
|
+
type ShortMeasureExpr = {
|
|
152
|
+
readonly kind: "short";
|
|
153
|
+
};
|
|
154
|
+
interface ShortOrder {
|
|
155
|
+
readonly material: string;
|
|
156
|
+
readonly order: string;
|
|
157
|
+
readonly amount: number;
|
|
158
|
+
readonly unit: string;
|
|
159
|
+
readonly says: string;
|
|
160
|
+
}
|
|
161
|
+
/** Operation /3 records the amount column, rather than a global figure path. */
|
|
162
|
+
interface OverlapAmountFact {
|
|
163
|
+
readonly amountKey: string;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* The solver authoring surface.
|
|
168
|
+
*
|
|
169
|
+
* Rules of the surface:
|
|
170
|
+
* 1. The one positional string of a call is the name the operator reads.
|
|
171
|
+
* 2. Every key into the data sits in a named slot: `list`, `field`, `table`, `roster`, `of`, `who`.
|
|
172
|
+
* 3. In every function the job's own row comes first.
|
|
173
|
+
* 4. A written time is `"5 min"`, `"2 h"`. A time of day is `"03:00"`.
|
|
174
|
+
* 5. A step is written with `process.step(name, write)`, so a later step can name an earlier one and be checked at the string.
|
|
175
|
+
* 6. A word that starts with `must` is a limit. A word that starts with `should` is a goal, and is scored.
|
|
176
|
+
* 7. A priority names the measure it counts (`lateMinutes`).
|
|
177
|
+
*/
|
|
178
|
+
/** A written length of time: `"5 min"`, `"2 h"`, `"30 s"`, `"1 day"`. */
|
|
179
|
+
type Duration = `${number} ${"min" | "h" | "s" | "day" | "days"}`;
|
|
180
|
+
type Hour = "00" | "01" | "02" | "03" | "04" | "05" | "06" | "07" | "08" | "09" | "10" | "11" | "12" | "13" | "14" | "15" | "16" | "17" | "18" | "19" | "20" | "21" | "22" | "23";
|
|
181
|
+
type Digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
|
|
182
|
+
/** A time of day on the 24-hour clock, in the solver's time zone: `"03:00"`, `"15:30"`. */
|
|
183
|
+
type Clock = `${Hour}:${"0" | "1" | "2" | "3" | "4" | "5"}${Digit}`;
|
|
184
|
+
/** A moment: a `Date`, or an ISO string. */
|
|
185
|
+
type Instant = Date | string;
|
|
186
|
+
/** A plain value that two jobs can be compared by. */
|
|
187
|
+
type Scalar = string | number | boolean;
|
|
188
|
+
/** Any row with an `id`. Equipment, people and jobs are lists of these. */
|
|
189
|
+
type Row = {
|
|
190
|
+
/**
|
|
191
|
+
* The row's id. Plans, causes and results name the row by it.
|
|
192
|
+
* @example
|
|
193
|
+
* ```ts
|
|
194
|
+
* const oven = { id: "oven-1", name: "Deck oven" };
|
|
195
|
+
* const rows: readonly Row[] = [oven];
|
|
196
|
+
* ```
|
|
197
|
+
* @draws Nothing by itself; the lane or job is found by it.
|
|
198
|
+
*/
|
|
199
|
+
readonly id: string;
|
|
200
|
+
};
|
|
201
|
+
/** A table of minutes for going from one value to another, for example from one bake family to the next. */
|
|
202
|
+
type ChangeTable = readonly {
|
|
203
|
+
/**
|
|
204
|
+
* The value before the change.
|
|
205
|
+
* @example
|
|
206
|
+
* ```ts
|
|
207
|
+
* const ovenCleans: ChangeTable = [{ from: "lean", to: "sweet", minutes: 20 }];
|
|
208
|
+
* ```
|
|
209
|
+
* @draws The row heading of the change-over table.
|
|
210
|
+
*/
|
|
211
|
+
readonly from: Scalar;
|
|
212
|
+
/**
|
|
213
|
+
* The value after the change.
|
|
214
|
+
* @example
|
|
215
|
+
* ```ts
|
|
216
|
+
* const ovenCleans: ChangeTable = [{ from: "lean", to: "sweet", minutes: 20 }];
|
|
217
|
+
* ```
|
|
218
|
+
* @draws The column heading of the change-over table.
|
|
219
|
+
*/
|
|
220
|
+
readonly to: Scalar;
|
|
221
|
+
/**
|
|
222
|
+
* Minutes the change takes.
|
|
223
|
+
* @example
|
|
224
|
+
* ```ts
|
|
225
|
+
* const ovenCleans: ChangeTable = [{ from: "lean", to: "sweet", minutes: 20 }];
|
|
226
|
+
* ```
|
|
227
|
+
* @draws The cell of the change-over table, and the length of the bar.
|
|
228
|
+
*/
|
|
229
|
+
readonly minutes: number;
|
|
230
|
+
}[] | readonly {
|
|
231
|
+
/**
|
|
232
|
+
* The id of the value before the change, when the values are rows with ids.
|
|
233
|
+
* @example
|
|
234
|
+
* ```ts
|
|
235
|
+
* const colourChanges: ChangeTable = [{ fromId: "red", toId: "white", minutes: 30 }];
|
|
236
|
+
* ```
|
|
237
|
+
* @draws The row heading of the change-over table.
|
|
238
|
+
*/
|
|
239
|
+
readonly fromId: string;
|
|
240
|
+
/**
|
|
241
|
+
* The id of the value after the change.
|
|
242
|
+
* @example
|
|
243
|
+
* ```ts
|
|
244
|
+
* const colourChanges: ChangeTable = [{ fromId: "red", toId: "white", minutes: 30 }];
|
|
245
|
+
* ```
|
|
246
|
+
* @draws The column heading of the change-over table.
|
|
247
|
+
*/
|
|
248
|
+
readonly toId: string;
|
|
249
|
+
/**
|
|
250
|
+
* Minutes the change takes.
|
|
251
|
+
* @example
|
|
252
|
+
* ```ts
|
|
253
|
+
* const colourChanges: ChangeTable = [{ fromId: "red", toId: "white", minutes: 30 }];
|
|
254
|
+
* ```
|
|
255
|
+
* @draws The cell of the change-over table, and the length of the bar.
|
|
256
|
+
*/
|
|
257
|
+
readonly minutes: number;
|
|
258
|
+
}[];
|
|
259
|
+
/** Head count over the day. Each row says: from the time `at` (`"08:00"`), this many `people` are on duty. */
|
|
260
|
+
type Roster = readonly {
|
|
261
|
+
/**
|
|
262
|
+
* The time of day this head count starts, on the 24-hour clock.
|
|
263
|
+
* @example
|
|
264
|
+
* ```ts
|
|
265
|
+
* const pickerRoster: Roster = [{ at: "08:00", people: 4 }];
|
|
266
|
+
* ```
|
|
267
|
+
* @draws A step in the staff lane's "on duty" line.
|
|
268
|
+
*/
|
|
269
|
+
readonly at: string;
|
|
270
|
+
/**
|
|
271
|
+
* How many people are on duty from then until the next row.
|
|
272
|
+
* @example
|
|
273
|
+
* ```ts
|
|
274
|
+
* const pickerRoster: Roster = [{ at: "08:00", people: 4 }];
|
|
275
|
+
* ```
|
|
276
|
+
* @draws The height of the "on duty" line.
|
|
277
|
+
*/
|
|
278
|
+
readonly people: number;
|
|
279
|
+
}[];
|
|
280
|
+
/** Times away. Each row says: from `from` to `to`, one person is not available. Another field of the row says who. */
|
|
281
|
+
type Away = readonly {
|
|
282
|
+
/**
|
|
283
|
+
* When the time away starts.
|
|
284
|
+
* @example
|
|
285
|
+
* ```ts
|
|
286
|
+
* const lunch = { id: "tech-1", from: new Date("2026-03-02T12:00:00Z"), to: new Date("2026-03-02T12:30:00Z") };
|
|
287
|
+
* const lunches: Away = [lunch];
|
|
288
|
+
* ```
|
|
289
|
+
* @draws The left edge of the grey block on the person's lane.
|
|
290
|
+
*/
|
|
291
|
+
readonly from: Instant;
|
|
292
|
+
/**
|
|
293
|
+
* When the time away ends.
|
|
294
|
+
* @example
|
|
295
|
+
* ```ts
|
|
296
|
+
* const lunch = { id: "tech-1", from: new Date("2026-03-02T12:00:00Z"), to: new Date("2026-03-02T12:30:00Z") };
|
|
297
|
+
* const lunches: Away = [lunch];
|
|
298
|
+
* ```
|
|
299
|
+
* @draws The right edge of the grey block on the person's lane.
|
|
300
|
+
*/
|
|
301
|
+
readonly to: Instant;
|
|
302
|
+
}[];
|
|
303
|
+
/**
|
|
304
|
+
* How a piece of equipment is drawn and worded. It never changes the plan.
|
|
305
|
+
* `machine` and `line` read "on", `space`, `tank` and `vehicle` read "in", `door` reads "at".
|
|
306
|
+
*/
|
|
307
|
+
type Kind = "machine" | "space" | "line" | "tank" | "door" | "vehicle";
|
|
308
|
+
type Key<R, V> = {
|
|
309
|
+
[K in keyof R & string]: R[K] extends V ? K : never;
|
|
310
|
+
}[keyof R & string];
|
|
311
|
+
type RowsOf<D, L> = L extends keyof D ? D[L] extends readonly (infer R)[] ? R : never : never;
|
|
312
|
+
type Lists<D> = Key<D, readonly Row[]>;
|
|
313
|
+
type Has<F extends string> = {
|
|
314
|
+
readonly [K in F]: true;
|
|
315
|
+
};
|
|
316
|
+
type AtLeastOne<T> = {
|
|
317
|
+
[K in keyof T]-?: Required<Pick<T, K>> & Partial<Omit<T, K>>;
|
|
318
|
+
}[keyof T];
|
|
319
|
+
/** How long a downtime takes when it depends on what changed. */
|
|
320
|
+
type ChangeTime<D, V> = Duration | {
|
|
321
|
+
/**
|
|
322
|
+
* The prepared table that gives the minutes for each from/to pair.
|
|
323
|
+
* @example
|
|
324
|
+
* ```ts
|
|
325
|
+
* oven.downtime("oven clean", {
|
|
326
|
+
* onChange: { of: "bakes", field: "family" },
|
|
327
|
+
* takes: { table: "ovenCleans", otherwise: "20 min" },
|
|
328
|
+
* });
|
|
329
|
+
* ```
|
|
330
|
+
* @draws The length of each downtime bar, and the cells of the change-over table.
|
|
331
|
+
*/
|
|
332
|
+
table: Key<D, ChangeTable>;
|
|
333
|
+
/**
|
|
334
|
+
* The time to use where the table has no figure.
|
|
335
|
+
* @example
|
|
336
|
+
* ```ts
|
|
337
|
+
* oven.downtime("oven clean", {
|
|
338
|
+
* onChange: { of: "bakes", field: "family" },
|
|
339
|
+
* takes: { table: "ovenCleans", otherwise: "20 min" },
|
|
340
|
+
* });
|
|
341
|
+
* ```
|
|
342
|
+
* @draws Read-back, marked as assumed: "20 min where the table has no figure."
|
|
343
|
+
*/
|
|
344
|
+
otherwise?: Duration;
|
|
345
|
+
} | {
|
|
346
|
+
/**
|
|
347
|
+
* The changes that take time, written out one by one. `from` and `to` are values of the compared field.
|
|
348
|
+
* @example
|
|
349
|
+
* ```ts
|
|
350
|
+
* sorter.downtime("lane change", {
|
|
351
|
+
* onChange: { of: "orders", field: "temperature" },
|
|
352
|
+
* takes: { pairs: [{ from: "chilled", to: "ambient", takes: "12 min" }], otherwise: "0 min" },
|
|
353
|
+
* });
|
|
354
|
+
* ```
|
|
355
|
+
* @draws The length of each downtime bar. Read-back: "A lane change from chilled to ambient takes 12 min."
|
|
356
|
+
*/
|
|
357
|
+
pairs: readonly {
|
|
358
|
+
/**
|
|
359
|
+
* The value before the change.
|
|
360
|
+
* @example
|
|
361
|
+
* ```ts
|
|
362
|
+
* sorter.downtime("lane change", {
|
|
363
|
+
* onChange: { of: "orders", field: "temperature" },
|
|
364
|
+
* takes: { pairs: [{ from: "chilled", to: "ambient", takes: "12 min" }], otherwise: "0 min" },
|
|
365
|
+
* });
|
|
366
|
+
* ```
|
|
367
|
+
* @draws The reason on the bar: "from chilled to ambient".
|
|
368
|
+
*/
|
|
369
|
+
from: V;
|
|
370
|
+
/**
|
|
371
|
+
* The value after the change.
|
|
372
|
+
* @example
|
|
373
|
+
* ```ts
|
|
374
|
+
* sorter.downtime("lane change", {
|
|
375
|
+
* onChange: { of: "orders", field: "temperature" },
|
|
376
|
+
* takes: { pairs: [{ from: "chilled", to: "ambient", takes: "12 min" }], otherwise: "0 min" },
|
|
377
|
+
* });
|
|
378
|
+
* ```
|
|
379
|
+
* @draws The reason on the bar: "from chilled to ambient".
|
|
380
|
+
*/
|
|
381
|
+
to: V;
|
|
382
|
+
/**
|
|
383
|
+
* How long this change takes.
|
|
384
|
+
* @example
|
|
385
|
+
* ```ts
|
|
386
|
+
* sorter.downtime("lane change", {
|
|
387
|
+
* onChange: { of: "orders", field: "temperature" },
|
|
388
|
+
* takes: { pairs: [{ from: "chilled", to: "ambient", takes: "12 min" }], otherwise: "0 min" },
|
|
389
|
+
* });
|
|
390
|
+
* ```
|
|
391
|
+
* @draws The length of the downtime bar.
|
|
392
|
+
*/
|
|
393
|
+
takes: Duration;
|
|
394
|
+
}[];
|
|
395
|
+
/**
|
|
396
|
+
* The time for any change not listed in `pairs`.
|
|
397
|
+
* @example
|
|
398
|
+
* ```ts
|
|
399
|
+
* sorter.downtime("lane change", {
|
|
400
|
+
* onChange: { of: "orders", field: "temperature" },
|
|
401
|
+
* takes: { pairs: [{ from: "chilled", to: "ambient", takes: "12 min" }], otherwise: "0 min" },
|
|
402
|
+
* });
|
|
403
|
+
* ```
|
|
404
|
+
* @draws Read-back, marked as assumed: "0 min for any other change."
|
|
405
|
+
*/
|
|
406
|
+
otherwise?: Duration;
|
|
407
|
+
};
|
|
408
|
+
type FixedDowntime = AtLeastOne<{
|
|
409
|
+
/**
|
|
410
|
+
* Needed after every job on this piece, for this long.
|
|
411
|
+
* @example
|
|
412
|
+
* ```ts
|
|
413
|
+
* prover.downtime("wipe-down", { afterEachUse: "5 min" });
|
|
414
|
+
* ```
|
|
415
|
+
* @draws A downtime bar after each work bar on the lane.
|
|
416
|
+
*/
|
|
417
|
+
afterEachUse: Duration;
|
|
418
|
+
/**
|
|
419
|
+
* Needed once, before the first job of the day on this piece, for this long.
|
|
420
|
+
* @example
|
|
421
|
+
* ```ts
|
|
422
|
+
* packLine.downtime("start-up", { beforeFirst: "10 min" });
|
|
423
|
+
* ```
|
|
424
|
+
* @draws One downtime bar at the start of the lane's day.
|
|
425
|
+
*/
|
|
426
|
+
beforeFirst: Duration;
|
|
427
|
+
/**
|
|
428
|
+
* Needed once, after the last job of the day on this piece, for this long.
|
|
429
|
+
* @example
|
|
430
|
+
* ```ts
|
|
431
|
+
* packLine.downtime("wash-down", { afterLast: "15 min" });
|
|
432
|
+
* ```
|
|
433
|
+
* @draws One downtime bar at the end of the lane's day.
|
|
434
|
+
*/
|
|
435
|
+
afterLast: Duration;
|
|
436
|
+
}> & {
|
|
437
|
+
onChange?: undefined;
|
|
438
|
+
takes?: undefined;
|
|
439
|
+
};
|
|
440
|
+
type ChangeDowntime<D, L, F extends string> = {
|
|
441
|
+
/**
|
|
442
|
+
* Needed once, before the first job of the day on this piece, for this long.
|
|
443
|
+
* @example
|
|
444
|
+
* ```ts
|
|
445
|
+
* oven.downtime("oven clean", {
|
|
446
|
+
* onChange: { of: "bakes", field: "family" },
|
|
447
|
+
* takes: { table: "ovenCleans", otherwise: "20 min" },
|
|
448
|
+
* beforeFirst: "10 min",
|
|
449
|
+
* });
|
|
450
|
+
* ```
|
|
451
|
+
* @draws One downtime bar at the start of the lane's day.
|
|
452
|
+
*/
|
|
453
|
+
beforeFirst?: Duration;
|
|
454
|
+
/**
|
|
455
|
+
* Needed once, after the last job of the day on this piece, for this long.
|
|
456
|
+
* @example
|
|
457
|
+
* ```ts
|
|
458
|
+
* oven.downtime("oven clean", {
|
|
459
|
+
* onChange: { of: "bakes", field: "family" },
|
|
460
|
+
* takes: { table: "ovenCleans", otherwise: "20 min" },
|
|
461
|
+
* afterLast: "15 min",
|
|
462
|
+
* });
|
|
463
|
+
* ```
|
|
464
|
+
* @draws One downtime bar at the end of the lane's day.
|
|
465
|
+
*/
|
|
466
|
+
afterLast?: Duration;
|
|
467
|
+
/**
|
|
468
|
+
* Needed when a job differs from the job before it on the same piece.
|
|
469
|
+
* `of` is the list of jobs and `field` is the value compared.
|
|
470
|
+
* @example
|
|
471
|
+
* ```ts
|
|
472
|
+
* oven.downtime("oven clean", {
|
|
473
|
+
* onChange: { of: "bakes", field: "family" },
|
|
474
|
+
* takes: { table: "ovenCleans", otherwise: "20 min" },
|
|
475
|
+
* });
|
|
476
|
+
* ```
|
|
477
|
+
* @draws A downtime bar where the value changes, with its reason: "Oven clean: the family changed from lean to sweet."
|
|
478
|
+
*/
|
|
479
|
+
onChange: {
|
|
480
|
+
/**
|
|
481
|
+
* The list of jobs whose values are compared.
|
|
482
|
+
* @example
|
|
483
|
+
* ```ts
|
|
484
|
+
* oven.downtime("oven clean", {
|
|
485
|
+
* onChange: { of: "bakes", field: "family" },
|
|
486
|
+
* takes: { table: "ovenCleans", otherwise: "20 min" },
|
|
487
|
+
* });
|
|
488
|
+
* ```
|
|
489
|
+
* @draws Nothing by itself; it says which jobs `field` belongs to.
|
|
490
|
+
*/
|
|
491
|
+
of: L;
|
|
492
|
+
/**
|
|
493
|
+
* The field compared between one job and the job before it on the same piece.
|
|
494
|
+
* If the data has a list named by the field's plural (`family` -> `families`), its rows are every value the field can take; without it, only the values today's jobs hold are known.
|
|
495
|
+
* @example
|
|
496
|
+
* ```ts
|
|
497
|
+
* oven.downtime("oven clean", {
|
|
498
|
+
* onChange: { of: "bakes", field: "family" },
|
|
499
|
+
* takes: { table: "ovenCleans", otherwise: "20 min" },
|
|
500
|
+
* });
|
|
501
|
+
* ```
|
|
502
|
+
* @draws The word in the reason: "the family changed from lean to sweet".
|
|
503
|
+
*/
|
|
504
|
+
field: F;
|
|
505
|
+
};
|
|
506
|
+
/**
|
|
507
|
+
* How long the change takes: one written time, a table of from/to minutes, or pairs written out.
|
|
508
|
+
* @example
|
|
509
|
+
* ```ts
|
|
510
|
+
* oven.downtime("oven clean", {
|
|
511
|
+
* onChange: { of: "bakes", field: "family" },
|
|
512
|
+
* takes: { table: "ovenCleans", otherwise: "20 min" },
|
|
513
|
+
* });
|
|
514
|
+
* ```
|
|
515
|
+
* @draws The length of the downtime bar.
|
|
516
|
+
*/
|
|
517
|
+
takes: ChangeTime<D, RowsOf<D, L>[F & keyof RowsOf<D, L>]>;
|
|
518
|
+
};
|
|
519
|
+
type PieceRef<N extends string, R, Needs extends string> = {
|
|
520
|
+
readonly "~name": N;
|
|
521
|
+
readonly "~row": R;
|
|
522
|
+
readonly "~needs": Needs;
|
|
523
|
+
};
|
|
524
|
+
/** Equipment: a set of lanes, one per row of its list. Each lane takes one job at a time. */
|
|
525
|
+
interface Piece<N extends string, R, D, Needs extends string = never> extends PieceRef<N, R, Needs> {
|
|
526
|
+
/**
|
|
527
|
+
* A pause this piece needs between jobs: a clean, a change-over, a flush.
|
|
528
|
+
* Say when it is needed and how long it takes in one call. Call it again for a second kind of pause.
|
|
529
|
+
* @example
|
|
530
|
+
* ```ts
|
|
531
|
+
* const prover = op
|
|
532
|
+
* .equipment("proving cabinet", { list: "provers", kind: "space" })
|
|
533
|
+
* .downtime("wipe-down", { afterEachUse: "5 min" });
|
|
534
|
+
* const oven = op
|
|
535
|
+
* .equipment("oven", { list: "ovens", kind: "machine" })
|
|
536
|
+
* .downtime("oven clean", {
|
|
537
|
+
* onChange: { of: "bakes", field: "family" },
|
|
538
|
+
* takes: { table: "ovenCleans", otherwise: "20 min" },
|
|
539
|
+
* });
|
|
540
|
+
* ```
|
|
541
|
+
* @draws A downtime bar on the lane, with its reason: "Oven clean: the family changed from lean to sweet."
|
|
542
|
+
*/
|
|
543
|
+
downtime<L extends Lists<D> = never, F extends Key<RowsOf<D, L>, Scalar> = never>(name: string, when: FixedDowntime | ChangeDowntime<D, L, F>): Piece<N, R, D, Needs | F>;
|
|
544
|
+
}
|
|
545
|
+
/** Named people: one lane per row of the list. Each person does one job at a time, can be away, and can travel between jobs. */
|
|
546
|
+
interface Person<N extends string, R, D, Needs extends string = never> extends PieceRef<N, R, Needs> {
|
|
547
|
+
/**
|
|
548
|
+
* Times these people are away. Each row of `list` is one time away, and `who` is the field of that row holding the person's `id`.
|
|
549
|
+
* @example
|
|
550
|
+
* ```ts
|
|
551
|
+
* const technician = op
|
|
552
|
+
* .person("technician", { list: "technicians" })
|
|
553
|
+
* .unavailable({ list: "lunches", who: "id", label: "lunch" });
|
|
554
|
+
* ```
|
|
555
|
+
* @draws A band on the person's lane, named by `label`, and the cause "waited until Neri was back from lunch".
|
|
556
|
+
*/
|
|
557
|
+
unavailable<L extends Key<D, Away>>(away: {
|
|
558
|
+
/**
|
|
559
|
+
* The prepared list of times away. Each row has `from` and `to`.
|
|
560
|
+
* @example
|
|
561
|
+
* ```ts
|
|
562
|
+
* technician.unavailable({ list: "lunches", who: "id" });
|
|
563
|
+
* ```
|
|
564
|
+
* @draws One band per row, on the lane of the person the row names.
|
|
565
|
+
*/
|
|
566
|
+
list: L;
|
|
567
|
+
/**
|
|
568
|
+
* The field of each row that holds the `id` of the person who is away.
|
|
569
|
+
* @example
|
|
570
|
+
* ```ts
|
|
571
|
+
* technician.unavailable({ list: "lunches", who: "id" });
|
|
572
|
+
* ```
|
|
573
|
+
* @draws Which lane each band sits on.
|
|
574
|
+
*/
|
|
575
|
+
who: Key<RowsOf<D, L>, string>;
|
|
576
|
+
/**
|
|
577
|
+
* What to call the time away on the page.
|
|
578
|
+
* @example
|
|
579
|
+
* ```ts
|
|
580
|
+
* technician.unavailable({ list: "lunches", who: "id", label: "lunch" });
|
|
581
|
+
* ```
|
|
582
|
+
* @draws The band's label.
|
|
583
|
+
*/
|
|
584
|
+
label?: string;
|
|
585
|
+
}): Person<N, R, D, Needs>;
|
|
586
|
+
/**
|
|
587
|
+
* Moving from one job to the next takes time. `between` is the field of the job that says where it is, and `table` gives the minutes from place to place.
|
|
588
|
+
* @example
|
|
589
|
+
* ```ts
|
|
590
|
+
* const technician = op.person("technician", { list: "technicians" }).travel({
|
|
591
|
+
* between: { of: "visits", field: "postcode" },
|
|
592
|
+
* table: "travelMinutes",
|
|
593
|
+
* });
|
|
594
|
+
* ```
|
|
595
|
+
* @draws A travel bar between two jobs on the person's lane, and the travel score row.
|
|
596
|
+
*/
|
|
597
|
+
travel<L extends Lists<D>, F extends Key<RowsOf<D, L>, Scalar>>(trip: {
|
|
598
|
+
/**
|
|
599
|
+
* Where a job is: `of` is the list of jobs and `field` is the field holding the place.
|
|
600
|
+
* @example
|
|
601
|
+
* ```ts
|
|
602
|
+
* technician.travel({ between: { of: "visits", field: "postcode" }, table: "travelMinutes" });
|
|
603
|
+
* ```
|
|
604
|
+
* @draws The reason on a travel bar: "from RG1 to RG4".
|
|
605
|
+
*/
|
|
606
|
+
between: {
|
|
607
|
+
/**
|
|
608
|
+
* The list of jobs the person travels between.
|
|
609
|
+
* @example
|
|
610
|
+
* ```ts
|
|
611
|
+
* technician.travel({ between: { of: "visits", field: "postcode" }, table: "travelMinutes" });
|
|
612
|
+
* ```
|
|
613
|
+
* @draws Nothing by itself; it says which jobs `field` belongs to.
|
|
614
|
+
*/
|
|
615
|
+
of: L;
|
|
616
|
+
/**
|
|
617
|
+
* The field on a job that holds its place.
|
|
618
|
+
* @example
|
|
619
|
+
* ```ts
|
|
620
|
+
* technician.travel({ between: { of: "visits", field: "postcode" }, table: "travelMinutes" });
|
|
621
|
+
* ```
|
|
622
|
+
* @draws The places in the reason on a travel bar: "from RG1 to RG4".
|
|
623
|
+
*/
|
|
624
|
+
field: F;
|
|
625
|
+
};
|
|
626
|
+
/**
|
|
627
|
+
* The prepared table of minutes from one place to another.
|
|
628
|
+
* @example
|
|
629
|
+
* ```ts
|
|
630
|
+
* technician.travel({ between: { of: "visits", field: "postcode" }, table: "travelMinutes" });
|
|
631
|
+
* ```
|
|
632
|
+
* @draws The length of each travel bar.
|
|
633
|
+
*/
|
|
634
|
+
table: Key<D, ChangeTable>;
|
|
635
|
+
}): Person<N, R, D, Needs | F>;
|
|
636
|
+
}
|
|
637
|
+
/** A counted pool of people. Steps take people from it with `.needs(staff, 1)`. */
|
|
638
|
+
interface Staff<N extends string> {
|
|
639
|
+
readonly "~staff": N;
|
|
640
|
+
}
|
|
641
|
+
type UseOpts<J, R, U extends string> = {
|
|
642
|
+
/**
|
|
643
|
+
* Keep the lane after the step ends.
|
|
644
|
+
* `{ endOf: "fill" }` keeps it until that later step has ended.
|
|
645
|
+
* `{ time: "cutOffAt" }` keeps it until that time on the job, or until the step ends if that is later. It is not a limit on the step.
|
|
646
|
+
* The `time` form is only for the last step of a process, and only when that step uses one piece.
|
|
647
|
+
* @example
|
|
648
|
+
* ```ts
|
|
649
|
+
* batch.step("mix", (s) => s.uses(vessel, { keepUntil: { endOf: "fill" } }).takes({ field: "mixMin" }));
|
|
650
|
+
* trailer.step("load", (s) =>
|
|
651
|
+
* s.uses(door, { keepUntil: { time: "cutOffAt", called: "cut-off" } }).takes({ field: "loadMin" })
|
|
652
|
+
* );
|
|
653
|
+
* ```
|
|
654
|
+
* @draws A hold bar on the lane from the end of the step to the release, and a mark named by `called`.
|
|
655
|
+
*/
|
|
656
|
+
keepUntil?: {
|
|
657
|
+
/**
|
|
658
|
+
* A later step of the same process. The piece is kept until that step has ended.
|
|
659
|
+
* @example
|
|
660
|
+
* ```ts
|
|
661
|
+
* batch.step("mix", (s) => s.uses(vessel, { keepUntil: { endOf: "fill" } }).takes({ field: "mixMin" }));
|
|
662
|
+
* ```
|
|
663
|
+
* @draws A hold bar on the lane from the end of this step to the end of that step.
|
|
664
|
+
*/
|
|
665
|
+
endOf: U;
|
|
666
|
+
} | {
|
|
667
|
+
/**
|
|
668
|
+
* A time field on the job. The piece is kept until then, or until the step ends if that is later.
|
|
669
|
+
* @example
|
|
670
|
+
* ```ts
|
|
671
|
+
* trailer.step("load", (s) =>
|
|
672
|
+
* s.uses(door, { keepUntil: { time: "cutOffAt", called: "cut-off" } }).takes({ field: "loadMin" })
|
|
673
|
+
* );
|
|
674
|
+
* ```
|
|
675
|
+
* @draws A hold bar on the lane from the end of the step to that time.
|
|
676
|
+
*/
|
|
677
|
+
time: Key<J, Instant>;
|
|
678
|
+
/**
|
|
679
|
+
* What the operator calls that time.
|
|
680
|
+
* @example
|
|
681
|
+
* ```ts
|
|
682
|
+
* trailer.step("load", (s) =>
|
|
683
|
+
* s.uses(door, { keepUntil: { time: "cutOffAt", called: "cut-off" } }).takes({ field: "loadMin" })
|
|
684
|
+
* );
|
|
685
|
+
* ```
|
|
686
|
+
* @draws The name of the mark at the end of the hold bar, and the read-back: "kept until its cut-off".
|
|
687
|
+
*/
|
|
688
|
+
called?: string;
|
|
689
|
+
};
|
|
690
|
+
} & ({
|
|
691
|
+
only?: undefined;
|
|
692
|
+
where?: undefined;
|
|
693
|
+
because?: undefined;
|
|
694
|
+
} | {
|
|
695
|
+
/**
|
|
696
|
+
* A test per job: this job may only use the rows that pass. The job's row comes first. Needs `because`.
|
|
697
|
+
* @example
|
|
698
|
+
* ```ts
|
|
699
|
+
* bake.step("bake", (s) =>
|
|
700
|
+
* s.uses(oven, {
|
|
701
|
+
* only: (bake, oven) => !bake.needsDeck || oven.isDeck,
|
|
702
|
+
* because: "Sourdough only fits the deck oven",
|
|
703
|
+
* })
|
|
704
|
+
* );
|
|
705
|
+
* ```
|
|
706
|
+
* @draws "Fits 1 of 3 ovens" on the job, and `because` in the cause when the job waited for the one that fits.
|
|
707
|
+
*/
|
|
708
|
+
only: (job: J, piece: R) => boolean;
|
|
709
|
+
where?: undefined;
|
|
710
|
+
/**
|
|
711
|
+
* The rule in the operator's words.
|
|
712
|
+
* @example
|
|
713
|
+
* ```ts
|
|
714
|
+
* bake.step("bake", (s) =>
|
|
715
|
+
* s.uses(oven, {
|
|
716
|
+
* only: (bake, oven) => !bake.needsDeck || oven.isDeck,
|
|
717
|
+
* because: "Sourdough only fits the deck oven",
|
|
718
|
+
* })
|
|
719
|
+
* );
|
|
720
|
+
* ```
|
|
721
|
+
* @draws The read-back sentence for the rule, and the reason in "why here" and "why it waited".
|
|
722
|
+
*/
|
|
723
|
+
because: string;
|
|
724
|
+
} | {
|
|
725
|
+
/**
|
|
726
|
+
* A test on the piece alone: the step only ever uses the rows that pass, whatever the job. Needs `because`.
|
|
727
|
+
* @example
|
|
728
|
+
* ```ts
|
|
729
|
+
* trailer.step("load", (s) =>
|
|
730
|
+
* s.uses(door, {
|
|
731
|
+
* where: (door) => door.direction === "out",
|
|
732
|
+
* because: "Load only at an outbound door",
|
|
733
|
+
* })
|
|
734
|
+
* );
|
|
735
|
+
* ```
|
|
736
|
+
* @draws The step's edge on the map goes to those rows only.
|
|
737
|
+
*/
|
|
738
|
+
where: (piece: R) => boolean;
|
|
739
|
+
only?: undefined;
|
|
740
|
+
/**
|
|
741
|
+
* The rule in the operator's words.
|
|
742
|
+
* @example
|
|
743
|
+
* ```ts
|
|
744
|
+
* trailer.step("load", (s) =>
|
|
745
|
+
* s.uses(door, {
|
|
746
|
+
* where: (door) => door.direction === "out",
|
|
747
|
+
* because: "Load only at an outbound door",
|
|
748
|
+
* })
|
|
749
|
+
* );
|
|
750
|
+
* ```
|
|
751
|
+
* @draws The read-back sentence for the rule.
|
|
752
|
+
*/
|
|
753
|
+
because: string;
|
|
754
|
+
});
|
|
755
|
+
type MissingFields<Needs, J> = [Needs] extends [keyof J] ? unknown : {
|
|
756
|
+
"✗ the job's rows lack a field this piece's downtime or travel compares": Exclude<Needs, keyof J>;
|
|
757
|
+
};
|
|
758
|
+
/** Where a step's length comes from. */
|
|
759
|
+
type StepTime<J, P> = Duration | {
|
|
760
|
+
/**
|
|
761
|
+
* A number field on the job that holds the minutes.
|
|
762
|
+
* @example
|
|
763
|
+
* ```ts
|
|
764
|
+
* bake.step("mix", (s) => s.uses(mixer).takes({ field: "mixMin" }));
|
|
765
|
+
* ```
|
|
766
|
+
* @draws The bar's length. Read-back: "Mix takes the bake's mix time."
|
|
767
|
+
*/
|
|
768
|
+
field: Key<J, number>;
|
|
769
|
+
} | {
|
|
770
|
+
/**
|
|
771
|
+
* Works out the minutes from the job and the row of the first piece the step uses. The job's row comes first. Needs `explain`.
|
|
772
|
+
* @example
|
|
773
|
+
* ```ts
|
|
774
|
+
* bake.step("bake", (s) =>
|
|
775
|
+
* s.uses(oven).takes({
|
|
776
|
+
* minutes: (bake, oven) => (bake.bakeMin * oven.bakePct) / 100,
|
|
777
|
+
* explain: "A bake takes its bake time, scaled by the oven's bake percent",
|
|
778
|
+
* })
|
|
779
|
+
* );
|
|
780
|
+
* ```
|
|
781
|
+
* @draws The bar's length on the lane the plan picked.
|
|
782
|
+
*/
|
|
783
|
+
minutes: (job: J, piece: P) => number;
|
|
784
|
+
/**
|
|
785
|
+
* The same sum in the operator's words.
|
|
786
|
+
* @example
|
|
787
|
+
* ```ts
|
|
788
|
+
* bake.step("bake", (s) =>
|
|
789
|
+
* s.uses(oven).takes({
|
|
790
|
+
* minutes: (bake, oven) => (bake.bakeMin * oven.bakePct) / 100,
|
|
791
|
+
* explain: "A bake takes its bake time, scaled by the oven's bake percent",
|
|
792
|
+
* })
|
|
793
|
+
* );
|
|
794
|
+
* ```
|
|
795
|
+
* @draws The read-back sentence for the step's time, in place of the code.
|
|
796
|
+
*/
|
|
797
|
+
explain: string;
|
|
798
|
+
};
|
|
799
|
+
type WaitOpts<Prev extends string> = {
|
|
800
|
+
/**
|
|
801
|
+
* The earlier step of this job whose end starts the clock.
|
|
802
|
+
* @example
|
|
803
|
+
* ```ts
|
|
804
|
+
* bake.step("bake", (s) => s.uses(oven).shouldStartWithin("90 min", { ofEndOf: "mix" }));
|
|
805
|
+
* ```
|
|
806
|
+
* @draws The left end of the wait window on the job's bar.
|
|
807
|
+
*/
|
|
808
|
+
ofEndOf: Prev;
|
|
809
|
+
/**
|
|
810
|
+
* Earlier steps whose time is left out of the count.
|
|
811
|
+
* @example
|
|
812
|
+
* ```ts
|
|
813
|
+
* bake.step("bake", (s) =>
|
|
814
|
+
* s.uses(oven).shouldStartWithin("90 min", { ofEndOf: "mix", notCounting: ["prove"] })
|
|
815
|
+
* );
|
|
816
|
+
* ```
|
|
817
|
+
* @draws Read-back: "…not counting prove."
|
|
818
|
+
*/
|
|
819
|
+
notCounting?: readonly Prev[];
|
|
820
|
+
};
|
|
821
|
+
/**
|
|
822
|
+
* One stage of a job, as the `write` function of `process.step(name, write)` receives it.
|
|
823
|
+
* Write what it uses, how long it takes, and anything it must wait for.
|
|
824
|
+
*/
|
|
825
|
+
interface Step<J, D, Prev extends string, First = never, Uses extends string = never, Later extends string = never> {
|
|
826
|
+
readonly "~uses": Uses;
|
|
827
|
+
readonly "~later": Later;
|
|
828
|
+
/**
|
|
829
|
+
* The step occupies one lane of this piece from its start to its end. Call it again for a second piece.
|
|
830
|
+
* The plan picks the lane. `only` or `where` limits the choice, and `keepUntil` holds the lane for longer.
|
|
831
|
+
* @example
|
|
832
|
+
* ```ts
|
|
833
|
+
* bake.step("bake", (s) =>
|
|
834
|
+
* s.uses(oven, {
|
|
835
|
+
* only: (bake, oven) => !bake.needsDeck || oven.isDeck,
|
|
836
|
+
* because: "Sourdough only fits the deck oven",
|
|
837
|
+
* })
|
|
838
|
+
* );
|
|
839
|
+
* batch.step("mix", (s) => s.uses(vessel, { keepUntil: { endOf: "fill" } }).takes({ field: "mixMin" }));
|
|
840
|
+
* ```
|
|
841
|
+
* @draws The bar sits in the lane of every piece the step uses. A kept lane shows a hold bar.
|
|
842
|
+
*/
|
|
843
|
+
uses<N extends string, R, Needs extends string, const U extends string = never>(piece: PieceRef<N, R, Needs> & MissingFields<Needs, J>, opts?: UseOpts<J, R, U>): Step<J, D, Prev, [
|
|
844
|
+
First
|
|
845
|
+
] extends [never] ? R : First, Uses | N, Later | NoInfer<U>>;
|
|
846
|
+
/**
|
|
847
|
+
* How long the step lasts: a written time, a field of the job, or a sum with its sentence.
|
|
848
|
+
* @example
|
|
849
|
+
* ```ts
|
|
850
|
+
* bake.step("rest", (s) => s.takes("5 min"));
|
|
851
|
+
* bake.step("mix", (s) => s.uses(mixer).takes({ field: "mixMin" }));
|
|
852
|
+
* bake.step("bake", (s) =>
|
|
853
|
+
* s.uses(oven).takes({
|
|
854
|
+
* minutes: (bake, oven) => (bake.bakeMin * oven.bakePct) / 100,
|
|
855
|
+
* explain: "A bake takes its bake time, scaled by the oven's bake percent",
|
|
856
|
+
* })
|
|
857
|
+
* );
|
|
858
|
+
* ```
|
|
859
|
+
* @draws The bar's length. Read-back: "Mix takes the bake's mix time", or `explain`.
|
|
860
|
+
*/
|
|
861
|
+
takes(time: StepTime<J, First>): Step<J, D, Prev, First, Uses, Later>;
|
|
862
|
+
/**
|
|
863
|
+
* The step needs this many people from a staff pool for its whole length.
|
|
864
|
+
* @example
|
|
865
|
+
* ```ts
|
|
866
|
+
* outbound.step("pick", (s) => s.uses(zone).takes({ field: "pickMin" }).needs(picker, 1));
|
|
867
|
+
* ```
|
|
868
|
+
* @draws The staff lane's "in use" line, and the cause "waited for a picker".
|
|
869
|
+
*/
|
|
870
|
+
needs<N extends string>(staff: Staff<N>, count: number | {
|
|
871
|
+
/**
|
|
872
|
+
* A number field on the job that holds how many people it needs.
|
|
873
|
+
* @example
|
|
874
|
+
* ```ts
|
|
875
|
+
* trailer.step("load", (s) => s.uses(door).takes({ field: "loadMin" }).needs(loader, { field: "loaders" }));
|
|
876
|
+
* ```
|
|
877
|
+
* @draws The height of the job's block on the staff lane.
|
|
878
|
+
*/
|
|
879
|
+
field: Key<J, number>;
|
|
880
|
+
}): Step<J, D, Prev, First, Uses, Later>;
|
|
881
|
+
/**
|
|
882
|
+
* A limit: the step cannot start until a step of another process has ended, for every job there that matches this one.
|
|
883
|
+
* In `matching`, this job's row comes first and the other job's row second.
|
|
884
|
+
* @example
|
|
885
|
+
* ```ts
|
|
886
|
+
* trailer.step("load", (s) =>
|
|
887
|
+
* s.uses(door).mustWaitFor(outbound, "sort", {
|
|
888
|
+
* matching: (carrier, order) => String(order.carrierId) === carrier.id,
|
|
889
|
+
* })
|
|
890
|
+
* );
|
|
891
|
+
* ```
|
|
892
|
+
* @draws Cause: "Load waited for 2 orders to be sorted", naming them.
|
|
893
|
+
*/
|
|
894
|
+
mustWaitFor<P extends AnyProcess>(process: P, step: keyof P["~steps"] & string, opts: {
|
|
895
|
+
/**
|
|
896
|
+
* Says which jobs of the other process this job waits for. This job's row comes first.
|
|
897
|
+
* @example
|
|
898
|
+
* ```ts
|
|
899
|
+
* trailer.step("load", (s) =>
|
|
900
|
+
* s.uses(door).mustWaitFor(outbound, "sort", {
|
|
901
|
+
* matching: (carrier, order) => String(order.carrierId) === carrier.id,
|
|
902
|
+
* })
|
|
903
|
+
* );
|
|
904
|
+
* ```
|
|
905
|
+
* @draws The jobs named in the cause "Load waited for 2 orders to be sorted".
|
|
906
|
+
*/
|
|
907
|
+
matching: (job: J, theirs: P["~row"]) => boolean;
|
|
908
|
+
}): Step<J, D, Prev, First, Uses, Later>;
|
|
909
|
+
/**
|
|
910
|
+
* A limit: the step must start within this time of an earlier step ending. Time spent in `notCounting` steps is left out.
|
|
911
|
+
* If the day cannot keep it, the plan is "overfull" and says so.
|
|
912
|
+
* @example
|
|
913
|
+
* ```ts
|
|
914
|
+
* bake.step("bake", (s) => s.uses(oven).mustStartWithin("30 min", { ofEndOf: "mix" }));
|
|
915
|
+
* ```
|
|
916
|
+
* @draws The wait window on the job's bar, and the cause when it forces an early start.
|
|
917
|
+
*/
|
|
918
|
+
mustStartWithin(time: Duration, opts: WaitOpts<Prev>): Step<J, D, Prev, First, Uses, Later>;
|
|
919
|
+
/**
|
|
920
|
+
* A goal, not a limit: the step should start within this time of an earlier step ending. Every minute over is scored.
|
|
921
|
+
* Time spent in `notCounting` steps is left out. Rank the score with `p.waitMinutes(process, step)`, or the build refuses.
|
|
922
|
+
* @example
|
|
923
|
+
* ```ts
|
|
924
|
+
* bake.step("bake", (s) =>
|
|
925
|
+
* s.uses(oven).shouldStartWithin("90 min", { ofEndOf: "mix", notCounting: ["prove"] })
|
|
926
|
+
* );
|
|
927
|
+
* ```
|
|
928
|
+
* @draws The wait window on the job's bar, the minutes over it, and a score row.
|
|
929
|
+
*/
|
|
930
|
+
shouldStartWithin(time: Duration, opts: WaitOpts<Prev>): Step<J, D, Prev, First, Uses, Later>;
|
|
931
|
+
/**
|
|
932
|
+
* A limit: the step cannot start until this long after an earlier step has ended. Use it for cooling, curing or resting time.
|
|
933
|
+
* @example
|
|
934
|
+
* ```ts
|
|
935
|
+
* bake.step("pack", (s) => s.uses(packLine).mustWaitAtLeast("30 min", { afterEndOf: "bake" }));
|
|
936
|
+
* ```
|
|
937
|
+
* @draws The cause "waited 30 min after bake" on the job's bar.
|
|
938
|
+
*/
|
|
939
|
+
mustWaitAtLeast(time: Duration, opts: {
|
|
940
|
+
/**
|
|
941
|
+
* The earlier step of this job whose end starts the clock.
|
|
942
|
+
* @example
|
|
943
|
+
* ```ts
|
|
944
|
+
* bake.step("pack", (s) => s.uses(packLine).mustWaitAtLeast("30 min", { afterEndOf: "bake" }));
|
|
945
|
+
* ```
|
|
946
|
+
* @draws The left end of the gap on the job's bar.
|
|
947
|
+
*/
|
|
948
|
+
afterEndOf: Prev;
|
|
949
|
+
}): Step<J, D, Prev, First, Uses, Later>;
|
|
950
|
+
}
|
|
951
|
+
type AnyStep = Step<any, any, any, any, string, string>;
|
|
952
|
+
type MarkOpts = {
|
|
953
|
+
/**
|
|
954
|
+
* What the operator calls this time: "arrival", "dispatch time", "cut-off".
|
|
955
|
+
* @example
|
|
956
|
+
* ```ts
|
|
957
|
+
* bake.shouldEndBy("dispatchAt", { called: "dispatch time" });
|
|
958
|
+
* ```
|
|
959
|
+
* @draws The name of the mark on the job, and the words in "12 min after its dispatch time".
|
|
960
|
+
*/
|
|
961
|
+
called?: string;
|
|
962
|
+
};
|
|
963
|
+
/** A kind of job: one job per row of its list, made of ordered steps. */
|
|
964
|
+
interface Process<N extends string, J, D, Sm, F extends string = never, Later extends string = never> {
|
|
965
|
+
readonly "~name": N;
|
|
966
|
+
readonly "~row": J;
|
|
967
|
+
readonly "~steps": Sm;
|
|
968
|
+
readonly "~has": Has<F>;
|
|
969
|
+
readonly "~later": Later;
|
|
970
|
+
/**
|
|
971
|
+
* The next step of a job, named as the operator names it. Steps run in the order written; one starts only after the one before it ends.
|
|
972
|
+
* `write` says what the step uses, how long it takes and what it waits for.
|
|
973
|
+
* @example
|
|
974
|
+
* ```ts
|
|
975
|
+
* const bake = op
|
|
976
|
+
* .process("bake", { list: "bakes" })
|
|
977
|
+
* .step("mix", (s) => s.uses(mixer).takes({ field: "mixMin" }))
|
|
978
|
+
* .step("prove", (s) => s.uses(prover).takes({ field: "proveMin" }))
|
|
979
|
+
* .step("bake", (s) => s.uses(oven).takes({ field: "bakeMin" }));
|
|
980
|
+
* ```
|
|
981
|
+
* @draws One bar per step, in the step's colour, and the cause "waited for the step before".
|
|
982
|
+
*/
|
|
983
|
+
step<const S extends string, St extends AnyStep>(name: S, write: (s: Step<J, D, keyof Sm & string>) => St): Process<N, J, D, Sm & {
|
|
984
|
+
readonly [K in S]: St["~uses"];
|
|
985
|
+
}, F, Later | St["~later"]>;
|
|
986
|
+
/**
|
|
987
|
+
* A limit: the job's first step cannot start before this time on the job.
|
|
988
|
+
* @example
|
|
989
|
+
* ```ts
|
|
990
|
+
* trailer.mustStartAfter("readyAt", { called: "arrival" });
|
|
991
|
+
* ```
|
|
992
|
+
* @draws A mark on the job at that time, named by `called`. Cause: "Load can't start before its arrival."
|
|
993
|
+
*/
|
|
994
|
+
mustStartAfter(key: Key<J, Instant>, opts?: Pick<MarkOpts, "called">): Process<N, J, D, Sm, F, Later>;
|
|
995
|
+
/**
|
|
996
|
+
* A goal, not a limit: the job should end by this time. Every minute after it is scored as late.
|
|
997
|
+
* `maxEarly: "2 h"` also scores ending more than 2 h before it.
|
|
998
|
+
* A process takes one of `shouldEndBy` and `shouldStartBy`.
|
|
999
|
+
* Rank the scores with `p.lateMinutes(process)` and `p.earlyMinutes(process)`, or the build refuses.
|
|
1000
|
+
* @example
|
|
1001
|
+
* ```ts
|
|
1002
|
+
* bake.shouldEndBy("dispatchAt", { called: "dispatch time", maxEarly: "2 h" });
|
|
1003
|
+
* ```
|
|
1004
|
+
* @draws A mark on the job at that time, named by `called`. Sentence: "12 min after its dispatch time."
|
|
1005
|
+
*/
|
|
1006
|
+
shouldEndBy<const O extends MarkOpts & {
|
|
1007
|
+
/**
|
|
1008
|
+
* Also a goal: the job should not end more than this long before the time. Every minute earlier is scored.
|
|
1009
|
+
* @example
|
|
1010
|
+
* ```ts
|
|
1011
|
+
* bake.shouldEndBy("dispatchAt", { called: "dispatch time", maxEarly: "2 h" });
|
|
1012
|
+
* ```
|
|
1013
|
+
* @draws A second mark, 2 h before the first, and the score row "minutes too early".
|
|
1014
|
+
*/
|
|
1015
|
+
maxEarly?: Duration;
|
|
1016
|
+
}>(key: Key<J, Instant>, opts?: O & {
|
|
1017
|
+
[K in Exclude<keyof O, "called" | "maxEarly">]: never;
|
|
1018
|
+
}): Process<N, J, D, Sm, F | "due" | (O extends {
|
|
1019
|
+
maxEarly: string;
|
|
1020
|
+
} ? "early" : never), Later>;
|
|
1021
|
+
/**
|
|
1022
|
+
* A limit: the job must end by this time. It is never traded for a priority.
|
|
1023
|
+
* A process takes one of `mustEndBy` and `mustStartBy`.
|
|
1024
|
+
* If the day cannot keep it, the plan is "overfull" and `result.broken` says by how much. On an `optional` process the job is left out.
|
|
1025
|
+
* @example
|
|
1026
|
+
* ```ts
|
|
1027
|
+
* inbound.mustEndBy("latestAt", { called: "appointment end" });
|
|
1028
|
+
* ```
|
|
1029
|
+
* @draws A mark on the job at that time, named by `called`. A broken one is drawn in red with its minutes.
|
|
1030
|
+
*/
|
|
1031
|
+
mustEndBy(key: Key<J, Instant>, opts?: MarkOpts): Process<N, J, D, Sm, F, Later>;
|
|
1032
|
+
/**
|
|
1033
|
+
* A goal, not a limit: the job's first step should start by this time. Every minute after it is scored as late.
|
|
1034
|
+
* `maxEarly: "15 min"` also scores starting more than 15 min before it.
|
|
1035
|
+
* A process takes one of `shouldEndBy` and `shouldStartBy`.
|
|
1036
|
+
* Rank the scores with `p.lateMinutes(process)` and `p.earlyMinutes(process)`, or the build refuses.
|
|
1037
|
+
* @example
|
|
1038
|
+
* ```ts
|
|
1039
|
+
* visit.shouldStartBy("bookedAt", { called: "booked time" });
|
|
1040
|
+
* ```
|
|
1041
|
+
* @draws A mark on the start of the job's first bar, named by `called`. Sentence: "Started 12 min after its booked time."
|
|
1042
|
+
*/
|
|
1043
|
+
shouldStartBy<const O extends MarkOpts & {
|
|
1044
|
+
/**
|
|
1045
|
+
* Also a goal: the job should not start more than this long before the time. Every minute earlier is scored.
|
|
1046
|
+
* @example
|
|
1047
|
+
* ```ts
|
|
1048
|
+
* visit.shouldStartBy("bookedAt", { called: "booked time", maxEarly: "15 min" });
|
|
1049
|
+
* ```
|
|
1050
|
+
* @draws A second mark, 15 min before the first, and the score row "minutes too early".
|
|
1051
|
+
*/
|
|
1052
|
+
maxEarly?: Duration;
|
|
1053
|
+
}>(key: Key<J, Instant>, opts?: O & {
|
|
1054
|
+
[K in Exclude<keyof O, "called" | "maxEarly">]: never;
|
|
1055
|
+
}): Process<N, J, D, Sm, F | "due" | (O extends {
|
|
1056
|
+
maxEarly: string;
|
|
1057
|
+
} ? "early" : never), Later>;
|
|
1058
|
+
/**
|
|
1059
|
+
* A limit: the job's first step must start by this time. It is never traded for a priority.
|
|
1060
|
+
* A process takes one of `mustEndBy` and `mustStartBy`.
|
|
1061
|
+
* If the day cannot keep it, the plan is "overfull" and `result.broken` says by how much. On an `optional` process the job is left out.
|
|
1062
|
+
* @example
|
|
1063
|
+
* ```ts
|
|
1064
|
+
* visit.mustStartBy("latestAt", { called: "latest arrival" });
|
|
1065
|
+
* ```
|
|
1066
|
+
* @draws A mark on the start of the job's first bar, named by `called`. A broken one is drawn in red with its minutes.
|
|
1067
|
+
*/
|
|
1068
|
+
mustStartBy(key: Key<J, Instant>, opts?: MarkOpts): Process<N, J, D, Sm, F, Later>;
|
|
1069
|
+
/**
|
|
1070
|
+
* Jobs that share this value go to the floor as one group. The plan picks one start time per group, and no job of the group starts before it.
|
|
1071
|
+
* @example
|
|
1072
|
+
* ```ts
|
|
1073
|
+
* outbound.startsInGroups("wave");
|
|
1074
|
+
* ```
|
|
1075
|
+
* @draws One release mark per group, shared by its jobs.
|
|
1076
|
+
*/
|
|
1077
|
+
startsInGroups(key: Key<J, Scalar>): Process<N, J, D, Sm, F, Later>;
|
|
1078
|
+
}
|
|
1079
|
+
type AnyProcess = Process<string, any, any, any, any, any>;
|
|
1080
|
+
type Dangling<P> = P extends Process<string, any, any, infer Sm, any, infer Later> ? Exclude<Later, keyof Sm> : never;
|
|
1081
|
+
type CheckLater<Ps extends readonly AnyProcess[]> = [
|
|
1082
|
+
Dangling<Ps[number]>
|
|
1083
|
+
] extends [never] ? unknown : {
|
|
1084
|
+
"✗ keepUntil names a step its process does not have": Dangling<Ps[number]>;
|
|
1085
|
+
};
|
|
1086
|
+
/** One figure the plan is scored on. Lower is better for every measure. */
|
|
1087
|
+
interface Measure {
|
|
1088
|
+
readonly "~measure": true;
|
|
1089
|
+
}
|
|
1090
|
+
type Weight = {
|
|
1091
|
+
/**
|
|
1092
|
+
* How many points one unit of this measure costs, next to the other measures in the same priority. Default 1.
|
|
1093
|
+
* Alone in a priority it changes nothing.
|
|
1094
|
+
* @example
|
|
1095
|
+
* ```ts
|
|
1096
|
+
* p.downtimeMinutes({ weight: 2 });
|
|
1097
|
+
* ```
|
|
1098
|
+
* @draws "…times 2" in the priority's sentence, and the weight column of the score row.
|
|
1099
|
+
*/
|
|
1100
|
+
weight?: number;
|
|
1101
|
+
};
|
|
1102
|
+
type Tier = Measure | readonly [Measure, ...Measure[]];
|
|
1103
|
+
interface Ranked {
|
|
1104
|
+
/**
|
|
1105
|
+
* The next most important thing. The plan gives up nothing from the priorities above to improve this one.
|
|
1106
|
+
* Several measures in one priority are added together, each times its `weight`.
|
|
1107
|
+
* @example
|
|
1108
|
+
* ```ts
|
|
1109
|
+
* p.first("Every bake out by its dispatch time", p.lateMinutes(bake))
|
|
1110
|
+
* .then("Then finish early and keep cleans down", [
|
|
1111
|
+
* p.finishTime(),
|
|
1112
|
+
* p.downtimeMinutes({ weight: 2 }),
|
|
1113
|
+
* ]);
|
|
1114
|
+
* ```
|
|
1115
|
+
* @draws The next rung of the priority ladder, named by the sentence, with one score row per measure.
|
|
1116
|
+
*/
|
|
1117
|
+
then(name: string, measures: Tier): Ranked;
|
|
1118
|
+
/**
|
|
1119
|
+
* A figure to show and never to trade for.
|
|
1120
|
+
* @example
|
|
1121
|
+
* ```ts
|
|
1122
|
+
* p.first("Finish the day early", p.finishTime()).watch(p.downtimeMinutes());
|
|
1123
|
+
* ```
|
|
1124
|
+
* @draws A score row with no rank.
|
|
1125
|
+
*/
|
|
1126
|
+
watch(measure: Measure): Ranked;
|
|
1127
|
+
}
|
|
1128
|
+
interface Priorities {
|
|
1129
|
+
/**
|
|
1130
|
+
* The most important thing, in the operator's words, and the measure that counts it.
|
|
1131
|
+
* Every `must` comes before the first priority.
|
|
1132
|
+
* @example
|
|
1133
|
+
* ```ts
|
|
1134
|
+
* p.first("Every bake out by its dispatch time", p.lateMinutes(bake));
|
|
1135
|
+
* ```
|
|
1136
|
+
* @draws The top rung of the priority ladder, named by the sentence.
|
|
1137
|
+
*/
|
|
1138
|
+
first(name: string, measures: Tier): Ranked;
|
|
1139
|
+
/**
|
|
1140
|
+
* Total minutes the jobs of a process end after their `shouldEndBy` time.
|
|
1141
|
+
* @example
|
|
1142
|
+
* ```ts
|
|
1143
|
+
* p.lateMinutes(bake, { weight: 10 });
|
|
1144
|
+
* ```
|
|
1145
|
+
* @draws Score row "minutes late", and "late by 12 min" on each late job.
|
|
1146
|
+
*/
|
|
1147
|
+
lateMinutes(process: {
|
|
1148
|
+
readonly "~has": Has<"due">;
|
|
1149
|
+
}, opts?: Weight): Measure;
|
|
1150
|
+
/**
|
|
1151
|
+
* Total minutes the jobs of a process end earlier than `maxEarly` before their `shouldEndBy` time.
|
|
1152
|
+
* @example
|
|
1153
|
+
* ```ts
|
|
1154
|
+
* p.earlyMinutes(bake);
|
|
1155
|
+
* ```
|
|
1156
|
+
* @draws Score row "minutes too early".
|
|
1157
|
+
*/
|
|
1158
|
+
earlyMinutes(process: {
|
|
1159
|
+
readonly "~has": Has<"early">;
|
|
1160
|
+
}, opts?: Weight): Measure;
|
|
1161
|
+
/**
|
|
1162
|
+
* The number of jobs of an `optional` process that the plan leaves out.
|
|
1163
|
+
* @example
|
|
1164
|
+
* ```ts
|
|
1165
|
+
* p.undoneCount(visit);
|
|
1166
|
+
* ```
|
|
1167
|
+
* @draws Score row "left out", and the list of left-out jobs with their reasons.
|
|
1168
|
+
*/
|
|
1169
|
+
undoneCount(process: {
|
|
1170
|
+
readonly "~has": Has<"optional">;
|
|
1171
|
+
}, opts?: Weight): Measure;
|
|
1172
|
+
/**
|
|
1173
|
+
* Total minutes a step starts later than its `shouldStartWithin` time.
|
|
1174
|
+
* @example
|
|
1175
|
+
* ```ts
|
|
1176
|
+
* p.waitMinutes(bake, "bake");
|
|
1177
|
+
* ```
|
|
1178
|
+
* @draws Score row "minutes waiting", from the earlier step to this one.
|
|
1179
|
+
*/
|
|
1180
|
+
waitMinutes<Sm>(process: {
|
|
1181
|
+
readonly "~steps": Sm;
|
|
1182
|
+
}, step: keyof Sm & string, opts?: Weight): Measure;
|
|
1183
|
+
/**
|
|
1184
|
+
* The time the last job of the day ends, in minutes after opening.
|
|
1185
|
+
* @example
|
|
1186
|
+
* ```ts
|
|
1187
|
+
* p.finishTime();
|
|
1188
|
+
* ```
|
|
1189
|
+
* @draws Score row "finish", and the ring on the lane that sets it.
|
|
1190
|
+
*/
|
|
1191
|
+
finishTime(opts?: Weight): Measure;
|
|
1192
|
+
/**
|
|
1193
|
+
* Total minutes of downtime on all equipment.
|
|
1194
|
+
* @example
|
|
1195
|
+
* ```ts
|
|
1196
|
+
* p.downtimeMinutes({ weight: 2 });
|
|
1197
|
+
* ```
|
|
1198
|
+
* @draws Score row "minutes of downtime".
|
|
1199
|
+
*/
|
|
1200
|
+
downtimeMinutes(opts?: Weight): Measure;
|
|
1201
|
+
/**
|
|
1202
|
+
* Total minutes people spend travelling between jobs.
|
|
1203
|
+
* @example
|
|
1204
|
+
* ```ts
|
|
1205
|
+
* p.travelMinutes();
|
|
1206
|
+
* ```
|
|
1207
|
+
* @draws Score row "minutes travelling".
|
|
1208
|
+
*/
|
|
1209
|
+
travelMinutes(opts?: Weight): Measure;
|
|
1210
|
+
}
|
|
1211
|
+
interface Model<Ps extends readonly AnyProcess[]> {
|
|
1212
|
+
readonly "~processes": Ps;
|
|
1213
|
+
}
|
|
1214
|
+
/** The builder a `model` function receives. Make the pieces with it, keep them in variables, and pass the variables. */
|
|
1215
|
+
interface Op<D> {
|
|
1216
|
+
/**
|
|
1217
|
+
* Things jobs wait for: one lane per row of `list`. Each lane takes one job at a time.
|
|
1218
|
+
* @example
|
|
1219
|
+
* ```ts
|
|
1220
|
+
* const oven = op.equipment("oven", { list: "ovens", kind: "machine" });
|
|
1221
|
+
* ```
|
|
1222
|
+
* @draws A lane per row, grouped under `area`. The icon and the word "on / in / at" come from `kind`.
|
|
1223
|
+
*/
|
|
1224
|
+
equipment<const N extends string, L extends Lists<D>>(name: N, opts: {
|
|
1225
|
+
/**
|
|
1226
|
+
* The prepared list with one row per lane.
|
|
1227
|
+
* @example
|
|
1228
|
+
* ```ts
|
|
1229
|
+
* op.equipment("oven", { list: "ovens" });
|
|
1230
|
+
* ```
|
|
1231
|
+
* @draws One lane per row, labelled with the row's `name`.
|
|
1232
|
+
*/
|
|
1233
|
+
list: L;
|
|
1234
|
+
/**
|
|
1235
|
+
* How it is drawn and worded. It never changes the plan.
|
|
1236
|
+
* @example
|
|
1237
|
+
* ```ts
|
|
1238
|
+
* op.equipment("oven", { list: "ovens", kind: "machine" });
|
|
1239
|
+
* ```
|
|
1240
|
+
* @draws The lane's icon, and "on / in / at" in sentences.
|
|
1241
|
+
*/
|
|
1242
|
+
kind?: Kind;
|
|
1243
|
+
/**
|
|
1244
|
+
* A heading to group lanes under. It never changes the plan.
|
|
1245
|
+
* @example
|
|
1246
|
+
* ```ts
|
|
1247
|
+
* op.equipment("oven", { list: "ovens", kind: "machine", area: "baking" });
|
|
1248
|
+
* ```
|
|
1249
|
+
* @draws The heading above the lanes, and the band on the map.
|
|
1250
|
+
*/
|
|
1251
|
+
area?: string;
|
|
1252
|
+
}): Piece<N, RowsOf<D, L>, D>;
|
|
1253
|
+
/**
|
|
1254
|
+
* Named people who do the work: one lane per row of `list`. Each person does one job at a time.
|
|
1255
|
+
* @example
|
|
1256
|
+
* ```ts
|
|
1257
|
+
* const technician = op.person("technician", { list: "technicians" });
|
|
1258
|
+
* ```
|
|
1259
|
+
* @draws A lane per person, with their work, time away and travel.
|
|
1260
|
+
*/
|
|
1261
|
+
person<const N extends string, L extends Lists<D>>(name: N, opts: {
|
|
1262
|
+
/**
|
|
1263
|
+
* The prepared list with one row per person.
|
|
1264
|
+
* @example
|
|
1265
|
+
* ```ts
|
|
1266
|
+
* op.person("technician", { list: "technicians" });
|
|
1267
|
+
* ```
|
|
1268
|
+
* @draws One lane per row, labelled with the row's `name`.
|
|
1269
|
+
*/
|
|
1270
|
+
list: L;
|
|
1271
|
+
}): Person<N, RowsOf<D, L>, D>;
|
|
1272
|
+
/**
|
|
1273
|
+
* A counted pool of people who are not planned by name. `roster` is the prepared table of head count over the day.
|
|
1274
|
+
* @example
|
|
1275
|
+
* ```ts
|
|
1276
|
+
* const picker = op.staff("picker", { roster: "pickerRoster" });
|
|
1277
|
+
* ```
|
|
1278
|
+
* @draws A staff lane: people on duty against people in use.
|
|
1279
|
+
*/
|
|
1280
|
+
staff<const N extends string>(name: N, opts: {
|
|
1281
|
+
/**
|
|
1282
|
+
* The prepared table of `{ at, people }` rows: from the time `at`, this many people are on duty.
|
|
1283
|
+
* @example
|
|
1284
|
+
* ```ts
|
|
1285
|
+
* op.staff("picker", { roster: "pickerRoster" });
|
|
1286
|
+
* ```
|
|
1287
|
+
* @draws The "on duty" line of the staff lane.
|
|
1288
|
+
*/
|
|
1289
|
+
roster: Key<D, Roster>;
|
|
1290
|
+
}): Staff<N>;
|
|
1291
|
+
/**
|
|
1292
|
+
* A kind of job: one job per row of `list`.
|
|
1293
|
+
* @example
|
|
1294
|
+
* ```ts
|
|
1295
|
+
* const bake = op.process("bake", { list: "bakes" }).step("mix", (s) => s.takes("20 min"));
|
|
1296
|
+
* ```
|
|
1297
|
+
* @draws One bar per step of each job, labelled with the job's `name`.
|
|
1298
|
+
*/
|
|
1299
|
+
process<const N extends string, L extends Lists<D>, const O extends boolean = false>(name: N, opts: {
|
|
1300
|
+
/**
|
|
1301
|
+
* The prepared list with one row per job.
|
|
1302
|
+
* @example
|
|
1303
|
+
* ```ts
|
|
1304
|
+
* op.process("bake", { list: "bakes" });
|
|
1305
|
+
* ```
|
|
1306
|
+
* @draws One job per row.
|
|
1307
|
+
*/
|
|
1308
|
+
list: L;
|
|
1309
|
+
/**
|
|
1310
|
+
* `true` lets the plan leave a job out when it cannot fit. Rank it with `p.undoneCount(process)`, or the build refuses.
|
|
1311
|
+
* In `apply`, check `item.done` before reading a step.
|
|
1312
|
+
* @example
|
|
1313
|
+
* ```ts
|
|
1314
|
+
* const visit = op.process("visit", { list: "visits", optional: true });
|
|
1315
|
+
* ```
|
|
1316
|
+
* @draws The list of left-out jobs, each with its reason.
|
|
1317
|
+
*/
|
|
1318
|
+
optional?: O;
|
|
1319
|
+
/**
|
|
1320
|
+
* What to call one job on the page. Default: the row's `name`.
|
|
1321
|
+
* @example
|
|
1322
|
+
* ```ts
|
|
1323
|
+
* op.process("bake", { list: "bakes", label: (bake) => `${bake.code} ${bake.name}` });
|
|
1324
|
+
* ```
|
|
1325
|
+
* @draws The label on every bar and in every sentence about the job.
|
|
1326
|
+
*/
|
|
1327
|
+
label?: (row: RowsOf<D, L>) => string;
|
|
1328
|
+
}): Process<N, RowsOf<D, L>, D, {}, O extends true ? "optional" : never>;
|
|
1329
|
+
/**
|
|
1330
|
+
* The whole day: which jobs are planned together, the opening hours, and what matters most.
|
|
1331
|
+
* @example
|
|
1332
|
+
* ```ts
|
|
1333
|
+
* const model = op.model({
|
|
1334
|
+
* processes: [bake],
|
|
1335
|
+
* hours: { open: "03:00", close: "15:00" },
|
|
1336
|
+
* priorities: (p) => p.first("Finish the day early", p.finishTime()),
|
|
1337
|
+
* });
|
|
1338
|
+
* ```
|
|
1339
|
+
* @draws The lanes, bars and score rows for the day.
|
|
1340
|
+
*/
|
|
1341
|
+
model<const Ps extends readonly AnyProcess[]>(def: {
|
|
1342
|
+
/**
|
|
1343
|
+
* The processes planned together. One left out is not planned.
|
|
1344
|
+
* @example
|
|
1345
|
+
* ```ts
|
|
1346
|
+
* const model = op.model({
|
|
1347
|
+
* processes: [outbound, trailer, inbound],
|
|
1348
|
+
* hours: { open: "08:00", close: "16:00" },
|
|
1349
|
+
* priorities: (p) => p.first("Finish the day early", p.finishTime()),
|
|
1350
|
+
* });
|
|
1351
|
+
* ```
|
|
1352
|
+
* @draws The jobs on the page.
|
|
1353
|
+
*/
|
|
1354
|
+
processes: Ps & CheckLater<Ps>;
|
|
1355
|
+
/**
|
|
1356
|
+
* Opening hours. Nothing starts before `open`.
|
|
1357
|
+
* Closing can run late: on a day that cannot fit, work runs past `close`, the plan is "overfull", and `result.broken` says by how much.
|
|
1358
|
+
* @example
|
|
1359
|
+
* ```ts
|
|
1360
|
+
* const model = op.model({
|
|
1361
|
+
* processes: [bake],
|
|
1362
|
+
* hours: { open: "03:00", close: "15:00" },
|
|
1363
|
+
* priorities: (p) => p.first("Finish the day early", p.finishTime()),
|
|
1364
|
+
* });
|
|
1365
|
+
* ```
|
|
1366
|
+
* @draws The opening and closing marks on the day, and the shaded time after `close`.
|
|
1367
|
+
*/
|
|
1368
|
+
hours: {
|
|
1369
|
+
/**
|
|
1370
|
+
* Opening time. Nothing starts before it.
|
|
1371
|
+
* @example
|
|
1372
|
+
* ```ts
|
|
1373
|
+
* const model = op.model({
|
|
1374
|
+
* processes: [bake],
|
|
1375
|
+
* hours: { open: "03:00", close: "15:00" },
|
|
1376
|
+
* priorities: (p) => p.first("Finish the day early", p.finishTime()),
|
|
1377
|
+
* });
|
|
1378
|
+
* ```
|
|
1379
|
+
* @draws The opening mark.
|
|
1380
|
+
*/
|
|
1381
|
+
open: Clock;
|
|
1382
|
+
/**
|
|
1383
|
+
* Closing time. Work should end by it, and can run past it on a day that cannot fit.
|
|
1384
|
+
* `"24:00"` is midnight at the end of the day.
|
|
1385
|
+
* @example
|
|
1386
|
+
* ```ts
|
|
1387
|
+
* const model = op.model({
|
|
1388
|
+
* processes: [bake],
|
|
1389
|
+
* hours: { open: "03:00", close: "15:00" },
|
|
1390
|
+
* priorities: (p) => p.first("Finish the day early", p.finishTime()),
|
|
1391
|
+
* });
|
|
1392
|
+
* ```
|
|
1393
|
+
* @draws The closing mark. A day that ran late shows "Ran 25 min past closing".
|
|
1394
|
+
*/
|
|
1395
|
+
close: Clock | "24:00";
|
|
1396
|
+
};
|
|
1397
|
+
/**
|
|
1398
|
+
* What matters most, in order. Start with `p.first(...)`.
|
|
1399
|
+
* @example
|
|
1400
|
+
* ```ts
|
|
1401
|
+
* const model = op.model({
|
|
1402
|
+
* processes: [bake],
|
|
1403
|
+
* hours: { open: "03:00", close: "15:00" },
|
|
1404
|
+
* priorities: (p) =>
|
|
1405
|
+
* p.first("Every bake out by its dispatch time", p.lateMinutes(bake))
|
|
1406
|
+
* .then("Then finish the day early", p.finishTime()),
|
|
1407
|
+
* });
|
|
1408
|
+
* ```
|
|
1409
|
+
* @draws The priority ladder.
|
|
1410
|
+
*/
|
|
1411
|
+
priorities: (p: Priorities) => Ranked;
|
|
1412
|
+
}): Model<Ps>;
|
|
1413
|
+
}
|
|
1414
|
+
type Loaders<C, A> = Record<string, (ctx: C, args: A) => unknown>;
|
|
1415
|
+
type Loaded<L> = {
|
|
1416
|
+
[K in keyof L]: L[K] extends (...a: never[]) => infer T ? Awaited<T> : never;
|
|
1417
|
+
};
|
|
1418
|
+
type RowOf<Ps extends readonly AnyProcess[], N> = Extract<Ps[number], {
|
|
1419
|
+
readonly "~name": N;
|
|
1420
|
+
}>["~row"];
|
|
1421
|
+
type StepOf<Ps extends readonly AnyProcess[], N> = keyof Extract<Ps[number], {
|
|
1422
|
+
readonly "~name": N;
|
|
1423
|
+
}>["~steps"] & string;
|
|
1424
|
+
/** Where and when one step of a job was planned. */
|
|
1425
|
+
interface PlannedStep {
|
|
1426
|
+
/**
|
|
1427
|
+
* When the step starts.
|
|
1428
|
+
* @example
|
|
1429
|
+
* ```ts
|
|
1430
|
+
* for (const item of result.items("bake")) {
|
|
1431
|
+
* await ctx.models.bake.update({ id: item.id }, { bakeStart: item.step("bake").start });
|
|
1432
|
+
* }
|
|
1433
|
+
* ```
|
|
1434
|
+
* @draws The left edge of the step's bar.
|
|
1435
|
+
*/
|
|
1436
|
+
readonly start: Date;
|
|
1437
|
+
/**
|
|
1438
|
+
* When the step ends.
|
|
1439
|
+
* @example
|
|
1440
|
+
* ```ts
|
|
1441
|
+
* for (const item of result.items("bake")) {
|
|
1442
|
+
* await ctx.models.bake.update({ id: item.id }, { bakeEnd: item.step("bake").end });
|
|
1443
|
+
* }
|
|
1444
|
+
* ```
|
|
1445
|
+
* @draws The right edge of the step's bar.
|
|
1446
|
+
*/
|
|
1447
|
+
readonly end: Date;
|
|
1448
|
+
/**
|
|
1449
|
+
* The `id` of the row it was planned on: which oven, which door, which technician. `undefined` if the step uses no piece.
|
|
1450
|
+
* @example
|
|
1451
|
+
* ```ts
|
|
1452
|
+
* for (const item of result.items("bake")) {
|
|
1453
|
+
* await ctx.models.bake.update({ id: item.id }, { ovenId: item.step("bake").on });
|
|
1454
|
+
* }
|
|
1455
|
+
* ```
|
|
1456
|
+
* @draws The lane the step's bar sits on.
|
|
1457
|
+
*/
|
|
1458
|
+
readonly on: string | undefined;
|
|
1459
|
+
}
|
|
1460
|
+
/** One planned job. */
|
|
1461
|
+
interface Done<J, S extends string> {
|
|
1462
|
+
/**
|
|
1463
|
+
* `true`: the job is in the plan. Only an `optional` process can have `false`.
|
|
1464
|
+
* @example
|
|
1465
|
+
* ```ts
|
|
1466
|
+
* for (const item of result.items("visit")) {
|
|
1467
|
+
* if (item.done) await ctx.models.visit.update({ id: item.id }, { startAt: item.step("work").start });
|
|
1468
|
+
* }
|
|
1469
|
+
* ```
|
|
1470
|
+
* @draws The job has bars on the page.
|
|
1471
|
+
*/
|
|
1472
|
+
readonly done: true;
|
|
1473
|
+
/**
|
|
1474
|
+
* The job row's `id`.
|
|
1475
|
+
* @example
|
|
1476
|
+
* ```ts
|
|
1477
|
+
* for (const item of result.items("bake")) {
|
|
1478
|
+
* await ctx.models.bake.update({ id: item.id }, { ovenId: item.step("bake").on });
|
|
1479
|
+
* }
|
|
1480
|
+
* ```
|
|
1481
|
+
* @draws Nothing by itself; the job on the page is found by it.
|
|
1482
|
+
*/
|
|
1483
|
+
readonly id: string;
|
|
1484
|
+
/**
|
|
1485
|
+
* The job's label on the page.
|
|
1486
|
+
* @example
|
|
1487
|
+
* ```ts
|
|
1488
|
+
* for (const item of result.items("bake")) console.log(item.label);
|
|
1489
|
+
* ```
|
|
1490
|
+
* @draws The text on the job's bars.
|
|
1491
|
+
*/
|
|
1492
|
+
readonly label: string;
|
|
1493
|
+
/**
|
|
1494
|
+
* The prepared row the job was made from.
|
|
1495
|
+
* @example
|
|
1496
|
+
* ```ts
|
|
1497
|
+
* for (const item of result.items("bake")) console.log(item.row.trays);
|
|
1498
|
+
* ```
|
|
1499
|
+
* @draws The fields shown when the operator opens the job.
|
|
1500
|
+
*/
|
|
1501
|
+
readonly row: J;
|
|
1502
|
+
/**
|
|
1503
|
+
* Where and when one step of this job was planned.
|
|
1504
|
+
* @example
|
|
1505
|
+
* ```ts
|
|
1506
|
+
* for (const item of result.items("bake")) {
|
|
1507
|
+
* const bake = item.step("bake");
|
|
1508
|
+
* await ctx.models.bake.update({ id: item.id }, { ovenId: bake.on, bakeStart: bake.start });
|
|
1509
|
+
* }
|
|
1510
|
+
* ```
|
|
1511
|
+
* @draws One bar of the job.
|
|
1512
|
+
*/
|
|
1513
|
+
step(name: S): PlannedStep;
|
|
1514
|
+
}
|
|
1515
|
+
/** The priority that decided a job was left out. */
|
|
1516
|
+
type Reason = {
|
|
1517
|
+
/**
|
|
1518
|
+
* Where the priority is written in the model. The Console opens the model page there.
|
|
1519
|
+
* @example
|
|
1520
|
+
* ```ts
|
|
1521
|
+
* for (const item of result.items("visit")) {
|
|
1522
|
+
* if (!item.done && item.by) console.log(item.label, "see", item.by.about);
|
|
1523
|
+
* }
|
|
1524
|
+
* ```
|
|
1525
|
+
* @draws The link from the left-out job to its priority on the model page.
|
|
1526
|
+
*/
|
|
1527
|
+
readonly about: string;
|
|
1528
|
+
/**
|
|
1529
|
+
* The priority in the operator's words, as written in `p.first(...)` or `.then(...)`.
|
|
1530
|
+
* @example
|
|
1531
|
+
* ```ts
|
|
1532
|
+
* for (const item of result.items("visit")) {
|
|
1533
|
+
* if (!item.done) console.log(item.label, "was left out for:", item.by?.says);
|
|
1534
|
+
* }
|
|
1535
|
+
* ```
|
|
1536
|
+
* @draws The priority's sentence beside the job in the left-out list.
|
|
1537
|
+
*/
|
|
1538
|
+
readonly says: string;
|
|
1539
|
+
};
|
|
1540
|
+
/** A job of an `optional` process that the plan left out. */
|
|
1541
|
+
interface Undone<J> {
|
|
1542
|
+
/**
|
|
1543
|
+
* `false`: the job was left out. It has no steps to read.
|
|
1544
|
+
* @example
|
|
1545
|
+
* ```ts
|
|
1546
|
+
* for (const item of result.items("visit")) {
|
|
1547
|
+
* if (!item.done) await ctx.models.visit.update({ id: item.id }, { leftOut: item.reason });
|
|
1548
|
+
* }
|
|
1549
|
+
* ```
|
|
1550
|
+
* @draws The job is in the left-out list, with no bars.
|
|
1551
|
+
*/
|
|
1552
|
+
readonly done: false;
|
|
1553
|
+
/**
|
|
1554
|
+
* The job row's `id`.
|
|
1555
|
+
* @example
|
|
1556
|
+
* ```ts
|
|
1557
|
+
* for (const item of result.items("visit")) {
|
|
1558
|
+
* if (!item.done) await ctx.models.visit.update({ id: item.id }, { leftOut: item.reason });
|
|
1559
|
+
* }
|
|
1560
|
+
* ```
|
|
1561
|
+
* @draws Nothing by itself; the job on the page is found by it.
|
|
1562
|
+
*/
|
|
1563
|
+
readonly id: string;
|
|
1564
|
+
/**
|
|
1565
|
+
* The job's label on the page.
|
|
1566
|
+
* @example
|
|
1567
|
+
* ```ts
|
|
1568
|
+
* for (const item of result.items("bake")) console.log(item.label);
|
|
1569
|
+
* ```
|
|
1570
|
+
* @draws The text on the job's bars.
|
|
1571
|
+
*/
|
|
1572
|
+
readonly label: string;
|
|
1573
|
+
/**
|
|
1574
|
+
* The prepared row the job was made from.
|
|
1575
|
+
* @example
|
|
1576
|
+
* ```ts
|
|
1577
|
+
* for (const item of result.items("bake")) console.log(item.row.trays);
|
|
1578
|
+
* ```
|
|
1579
|
+
* @draws The fields shown when the operator opens the job.
|
|
1580
|
+
*/
|
|
1581
|
+
readonly row: J;
|
|
1582
|
+
/**
|
|
1583
|
+
* Why the job was left out, in a sentence for the operator.
|
|
1584
|
+
* @example
|
|
1585
|
+
* ```ts
|
|
1586
|
+
* for (const item of result.items("visit")) {
|
|
1587
|
+
* if (!item.done) await ctx.models.visit.update({ id: item.id }, { leftOut: item.reason });
|
|
1588
|
+
* }
|
|
1589
|
+
* ```
|
|
1590
|
+
* @draws The sentence beside the job in the left-out list.
|
|
1591
|
+
*/
|
|
1592
|
+
readonly reason: string;
|
|
1593
|
+
/**
|
|
1594
|
+
* The priority that decided it, or `null` when a limit left it no room.
|
|
1595
|
+
* @example
|
|
1596
|
+
* ```ts
|
|
1597
|
+
* for (const item of result.items("visit")) {
|
|
1598
|
+
* if (!item.done) console.log(item.label, "was left out for:", item.by?.says);
|
|
1599
|
+
* }
|
|
1600
|
+
* ```
|
|
1601
|
+
* @draws The priority shown beside the job in the left-out list.
|
|
1602
|
+
*/
|
|
1603
|
+
readonly by: Reason | null;
|
|
1604
|
+
}
|
|
1605
|
+
/** A limit the plan could not keep. */
|
|
1606
|
+
interface Broken {
|
|
1607
|
+
/**
|
|
1608
|
+
* Where the limit is written in the model: `"hours"` for closing time, or the deadline of the job's process.
|
|
1609
|
+
* @example
|
|
1610
|
+
* ```ts
|
|
1611
|
+
* const pastClosing = result.broken.filter((b) => b.about === "hours");
|
|
1612
|
+
* ```
|
|
1613
|
+
* @draws The link from the "could not keep" line to the limit on the model page.
|
|
1614
|
+
*/
|
|
1615
|
+
readonly about: string;
|
|
1616
|
+
/**
|
|
1617
|
+
* Which limit: closing time, or a job's `mustEndBy` or `mustStartBy` time.
|
|
1618
|
+
* @example
|
|
1619
|
+
* ```ts
|
|
1620
|
+
* const lateJobs = result.broken.filter((b) => b.limit === "deadline");
|
|
1621
|
+
* ```
|
|
1622
|
+
* @draws The red mark on the day: at closing time, or at the job's deadline.
|
|
1623
|
+
*/
|
|
1624
|
+
readonly limit: "closing" | "deadline";
|
|
1625
|
+
/**
|
|
1626
|
+
* Where the job's process is written in the model: `"processes."` and the process's name.
|
|
1627
|
+
* @example
|
|
1628
|
+
* ```ts
|
|
1629
|
+
* const lateBakes = result.broken.filter((b) => b.process === "processes.bake");
|
|
1630
|
+
* ```
|
|
1631
|
+
* @draws The link from the "could not keep" line to the process on the model page.
|
|
1632
|
+
*/
|
|
1633
|
+
readonly process: string;
|
|
1634
|
+
/**
|
|
1635
|
+
* The job row's `id`.
|
|
1636
|
+
* @example
|
|
1637
|
+
* ```ts
|
|
1638
|
+
* const lateIds = result.broken.map((b) => b.id);
|
|
1639
|
+
* ```
|
|
1640
|
+
* @draws Nothing by itself; the job on the page is found by it.
|
|
1641
|
+
*/
|
|
1642
|
+
readonly id: string;
|
|
1643
|
+
/**
|
|
1644
|
+
* How far past the limit, in minutes.
|
|
1645
|
+
* @example
|
|
1646
|
+
* ```ts
|
|
1647
|
+
* const worst = Math.max(...result.broken.map((b) => b.byMinutes));
|
|
1648
|
+
* ```
|
|
1649
|
+
* @draws The minutes in "Ran 25 min past closing".
|
|
1650
|
+
*/
|
|
1651
|
+
readonly byMinutes: number;
|
|
1652
|
+
/**
|
|
1653
|
+
* The same in a sentence for the operator.
|
|
1654
|
+
* @example
|
|
1655
|
+
* ```ts
|
|
1656
|
+
* for (const b of result.broken) console.warn(b.sentence);
|
|
1657
|
+
* ```
|
|
1658
|
+
* @draws The line in the page's "could not keep" list.
|
|
1659
|
+
*/
|
|
1660
|
+
readonly sentence: string;
|
|
1661
|
+
}
|
|
1662
|
+
/** The plan, as `apply` receives it. */
|
|
1663
|
+
interface Result<Ps extends readonly AnyProcess[]> {
|
|
1664
|
+
/**
|
|
1665
|
+
* `"planned"`: every limit is kept. `"overfull"`: there is a plan, and `broken` lists the limits it could not keep.
|
|
1666
|
+
* @example
|
|
1667
|
+
* ```ts
|
|
1668
|
+
* if (result.status === "overfull") console.warn(result.broken.length, "limits broken");
|
|
1669
|
+
* ```
|
|
1670
|
+
* @draws The badge at the top of the plan: "Planned" or "Overfull".
|
|
1671
|
+
*/
|
|
1672
|
+
readonly status: "planned" | "overfull";
|
|
1673
|
+
/**
|
|
1674
|
+
* The limits the plan could not keep. Empty when `status` is `"planned"`.
|
|
1675
|
+
* @example
|
|
1676
|
+
* ```ts
|
|
1677
|
+
* for (const b of result.broken) console.warn(b.sentence);
|
|
1678
|
+
* ```
|
|
1679
|
+
* @draws The page's "could not keep" list.
|
|
1680
|
+
*/
|
|
1681
|
+
readonly broken: readonly Broken[];
|
|
1682
|
+
/**
|
|
1683
|
+
* The jobs of one process, by the process's name. For an `optional` process, check `item.done` first.
|
|
1684
|
+
* @example
|
|
1685
|
+
* ```ts
|
|
1686
|
+
* for (const item of result.items("bake")) {
|
|
1687
|
+
* console.log(item.label, "mixes at", item.step("mix").start);
|
|
1688
|
+
* }
|
|
1689
|
+
* ```
|
|
1690
|
+
* @draws The jobs of that process on the page, in the same order.
|
|
1691
|
+
*/
|
|
1692
|
+
items<N extends Ps[number]["~name"]>(process: N): readonly (Done<RowOf<Ps, N>, StepOf<Ps, N>> | (Extract<Ps[number], {
|
|
1693
|
+
readonly "~name": N;
|
|
1694
|
+
}> extends {
|
|
1695
|
+
readonly "~has": Has<"optional">;
|
|
1696
|
+
} ? Undone<RowOf<Ps, N>> : never))[];
|
|
1697
|
+
}
|
|
1698
|
+
type RootKeys<C, L, D, Ps extends readonly AnyProcess[]> = {
|
|
1699
|
+
/**
|
|
1700
|
+
* One loader per table. Each returns the rows of one Keel model for this run.
|
|
1701
|
+
* @example
|
|
1702
|
+
* ```ts
|
|
1703
|
+
* const solver = BakeryOvens({
|
|
1704
|
+
* data: {
|
|
1705
|
+
* ovens: (ctx) => ctx.models.oven.findMany(),
|
|
1706
|
+
* bakes: (ctx, { date }) => ctx.models.bake.findMany({ where: { day: { equals: date } } }),
|
|
1707
|
+
* },
|
|
1708
|
+
* model: (op) => {
|
|
1709
|
+
* const oven = op.equipment("oven", { list: "ovens" });
|
|
1710
|
+
* const bake = op.process("bake", { list: "bakes" }).step("bake", (s) => s.uses(oven).takes("40 min"));
|
|
1711
|
+
* return op.model({
|
|
1712
|
+
* processes: [bake],
|
|
1713
|
+
* hours: { open: "03:00", close: "15:00" },
|
|
1714
|
+
* priorities: (p) => p.first("Finish the day early", p.finishTime()),
|
|
1715
|
+
* });
|
|
1716
|
+
* },
|
|
1717
|
+
* apply: async (result, ctx) => {
|
|
1718
|
+
* for (const item of result.items("bake")) {
|
|
1719
|
+
* const bake = item.step("bake");
|
|
1720
|
+
* await ctx.models.bake.update({ id: item.id }, { ovenId: bake.on, bakeStart: bake.start });
|
|
1721
|
+
* }
|
|
1722
|
+
* },
|
|
1723
|
+
* });
|
|
1724
|
+
* ```
|
|
1725
|
+
* @draws The tables listed under "Data" on the model page.
|
|
1726
|
+
*/
|
|
1727
|
+
data: L;
|
|
1728
|
+
/**
|
|
1729
|
+
* Says what is planned, with what, and what matters most. It receives the builder `op` and returns `op.model({ ... })`.
|
|
1730
|
+
* @example
|
|
1731
|
+
* ```ts
|
|
1732
|
+
* const solver = BakeryOvens({
|
|
1733
|
+
* data: {
|
|
1734
|
+
* ovens: (ctx) => ctx.models.oven.findMany(),
|
|
1735
|
+
* bakes: (ctx, { date }) => ctx.models.bake.findMany({ where: { day: { equals: date } } }),
|
|
1736
|
+
* },
|
|
1737
|
+
* model: (op) => {
|
|
1738
|
+
* const oven = op.equipment("oven", { list: "ovens" });
|
|
1739
|
+
* const bake = op.process("bake", { list: "bakes" }).step("bake", (s) => s.uses(oven).takes("40 min"));
|
|
1740
|
+
* return op.model({
|
|
1741
|
+
* processes: [bake],
|
|
1742
|
+
* hours: { open: "03:00", close: "15:00" },
|
|
1743
|
+
* priorities: (p) => p.first("Finish the day early", p.finishTime()),
|
|
1744
|
+
* });
|
|
1745
|
+
* },
|
|
1746
|
+
* apply: async (result, ctx) => {
|
|
1747
|
+
* for (const item of result.items("bake")) {
|
|
1748
|
+
* const bake = item.step("bake");
|
|
1749
|
+
* await ctx.models.bake.update({ id: item.id }, { ovenId: bake.on, bakeStart: bake.start });
|
|
1750
|
+
* }
|
|
1751
|
+
* },
|
|
1752
|
+
* });
|
|
1753
|
+
* ```
|
|
1754
|
+
* @draws Everything on the page comes from what this returns.
|
|
1755
|
+
*/
|
|
1756
|
+
model: (op: Op<D>) => Model<Ps>;
|
|
1757
|
+
/**
|
|
1758
|
+
* Writes the finished plan back to Keel, when the operator applies it. It does not run when there is no plan.
|
|
1759
|
+
* @example
|
|
1760
|
+
* ```ts
|
|
1761
|
+
* const solver = BakeryOvens({
|
|
1762
|
+
* data: {
|
|
1763
|
+
* ovens: (ctx) => ctx.models.oven.findMany(),
|
|
1764
|
+
* bakes: (ctx, { date }) => ctx.models.bake.findMany({ where: { day: { equals: date } } }),
|
|
1765
|
+
* },
|
|
1766
|
+
* model: (op) => {
|
|
1767
|
+
* const oven = op.equipment("oven", { list: "ovens" });
|
|
1768
|
+
* const bake = op.process("bake", { list: "bakes" }).step("bake", (s) => s.uses(oven).takes("40 min"));
|
|
1769
|
+
* return op.model({
|
|
1770
|
+
* processes: [bake],
|
|
1771
|
+
* hours: { open: "03:00", close: "15:00" },
|
|
1772
|
+
* priorities: (p) => p.first("Finish the day early", p.finishTime()),
|
|
1773
|
+
* });
|
|
1774
|
+
* },
|
|
1775
|
+
* apply: async (result, ctx) => {
|
|
1776
|
+
* for (const item of result.items("bake")) {
|
|
1777
|
+
* const bake = item.step("bake");
|
|
1778
|
+
* await ctx.models.bake.update({ id: item.id }, { ovenId: bake.on, bakeStart: bake.start });
|
|
1779
|
+
* }
|
|
1780
|
+
* },
|
|
1781
|
+
* });
|
|
1782
|
+
* ```
|
|
1783
|
+
* @draws Nothing. It runs when the operator presses Apply.
|
|
1784
|
+
*/
|
|
1785
|
+
apply: (result: Result<Ps>, ctx: C) => Promise<void>;
|
|
1786
|
+
};
|
|
1787
|
+
/** What a solver root returns. Export it as the file's default. */
|
|
1788
|
+
interface Solver {
|
|
1789
|
+
/**
|
|
1790
|
+
* The solver's name, as written in the schema.
|
|
1791
|
+
* @example
|
|
1792
|
+
* ```ts
|
|
1793
|
+
* console.log(solver.name); // "BakeryOvens"
|
|
1794
|
+
* ```
|
|
1795
|
+
* @draws The title of the solver's page.
|
|
1796
|
+
*/
|
|
1797
|
+
readonly name: string;
|
|
1798
|
+
}
|
|
1799
|
+
/**
|
|
1800
|
+
* One solver. Keel generates one of these per solver in the schema, with `ctx` and the run's inputs typed.
|
|
1801
|
+
* @example
|
|
1802
|
+
* ```ts
|
|
1803
|
+
* const solver = BakeryOvens({
|
|
1804
|
+
* data: {
|
|
1805
|
+
* ovens: (ctx) => ctx.models.oven.findMany(),
|
|
1806
|
+
* bakes: (ctx, { date }) => ctx.models.bake.findMany({ where: { day: { equals: date } } }),
|
|
1807
|
+
* },
|
|
1808
|
+
* model: (op) => {
|
|
1809
|
+
* const oven = op.equipment("oven", { list: "ovens" });
|
|
1810
|
+
* const bake = op.process("bake", { list: "bakes" }).step("bake", (s) => s.uses(oven).takes("40 min"));
|
|
1811
|
+
* return op.model({
|
|
1812
|
+
* processes: [bake],
|
|
1813
|
+
* hours: { open: "03:00", close: "15:00" },
|
|
1814
|
+
* priorities: (p) => p.first("Finish the day early", p.finishTime()),
|
|
1815
|
+
* });
|
|
1816
|
+
* },
|
|
1817
|
+
* apply: async (result, ctx) => {
|
|
1818
|
+
* for (const item of result.items("bake")) {
|
|
1819
|
+
* const bake = item.step("bake");
|
|
1820
|
+
* await ctx.models.bake.update({ id: item.id }, { ovenId: bake.on, bakeStart: bake.start });
|
|
1821
|
+
* }
|
|
1822
|
+
* },
|
|
1823
|
+
* });
|
|
1824
|
+
* ```
|
|
1825
|
+
*/
|
|
1826
|
+
interface SolverRoot<C, A> {
|
|
1827
|
+
<L extends Loaders<C, A>, const Ps extends readonly AnyProcess[]>(def: RootKeys<C, L, Loaded<L>, Ps> & {
|
|
1828
|
+
prepare?: undefined;
|
|
1829
|
+
}): Solver;
|
|
1830
|
+
<L extends Loaders<C, A>, D, const Ps extends readonly AnyProcess[]>(def: RootKeys<C, L, D, Ps> & {
|
|
1831
|
+
/**
|
|
1832
|
+
* Reshapes the loaded rows into the lists and fields the model names. Everything it returns is a table the model can name.
|
|
1833
|
+
* Sort the lists, so the plan does not depend on database order.
|
|
1834
|
+
* @example
|
|
1835
|
+
* ```ts
|
|
1836
|
+
* const solver = BakeryOvens({
|
|
1837
|
+
* data: {
|
|
1838
|
+
* ovens: (ctx) => ctx.models.oven.findMany(),
|
|
1839
|
+
* bakes: (ctx, { date }) => ctx.models.bake.findMany({ where: { day: { equals: date } } }),
|
|
1840
|
+
* },
|
|
1841
|
+
* prepare: (rows) => ({ ovens: byId(rows.ovens), bakes: byId(rows.bakes) }),
|
|
1842
|
+
* model: (op) => {
|
|
1843
|
+
* const oven = op.equipment("oven", { list: "ovens" });
|
|
1844
|
+
* const bake = op.process("bake", { list: "bakes" }).step("bake", (s) => s.uses(oven).takes("40 min"));
|
|
1845
|
+
* return op.model({
|
|
1846
|
+
* processes: [bake],
|
|
1847
|
+
* hours: { open: "03:00", close: "15:00" },
|
|
1848
|
+
* priorities: (p) => p.first("Finish the day early", p.finishTime()),
|
|
1849
|
+
* });
|
|
1850
|
+
* },
|
|
1851
|
+
* apply: async (result, ctx) => {
|
|
1852
|
+
* for (const item of result.items("bake")) {
|
|
1853
|
+
* const bake = item.step("bake");
|
|
1854
|
+
* await ctx.models.bake.update({ id: item.id }, { ovenId: bake.on, bakeStart: bake.start });
|
|
1855
|
+
* }
|
|
1856
|
+
* },
|
|
1857
|
+
* });
|
|
1858
|
+
* ```
|
|
1859
|
+
* @draws The tables the read-back says each rule reads.
|
|
1860
|
+
*/
|
|
1861
|
+
prepare: (rows: Loaded<L>, args: A) => D;
|
|
1862
|
+
}): Solver;
|
|
1863
|
+
}
|
|
1864
|
+
|
|
1865
|
+
export type { AnyProcess as A, Broken as B, ChangeTable as C, Done as D, OptionalRecord as E, ReadyBeforeRecord as F, AsapRecord as G, SkipEmptyRecord as H, Instant as I, CoverRecord as J, Kind as K, DispatchRecord as L, Measure as M, ShortMeasureExpr as N, Op as O, Person as P, NotDoneExpr as Q, Ranked as R, SolverRoot as S, TableRunCost as T, Undone as U, ShortShipsRecord as V, Weekday as W, OverlapAmountFact as X, QuantityPeriod as Y, ModelRefusal as Z, Sentence as _, Away as a, ChangeTime as b, Clock as c, Duration as d, Model as e, Piece as f, PieceRef as g, PlannedStep as h, Priorities as i, Process as j, Reason as k, Result as l, Roster as m, Row as n, Scalar as o, Solver as p, Staff as q, Step as r, StepTime as s, IrIssue as t, IrIssueCode as u, ShortOrder as v, ReadBack as w, Printed as x, Kind$1 as y, WashTimingRecord as z };
|