@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
package/dist/layout.cjs
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// src/layout.ts
|
|
17
|
+
var layout_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(layout_exports);
|
|
19
|
+
//# sourceMappingURL=layout.cjs.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { af as Cause, ag as CauseKind, ah as DemandFact, ai as Lever, aj as Lowering, ak as ModelWords, al as Noun, am as NounFacts, J as NounKind, an as NounWords, O as OperationDoc, ao as PlanTimelineItem, ap as ReadBackDoc, aq as TakesFact, ar as TimeFact, T as Timeline, as as Timeline0, at as TimelineCut, au as TimelineFact, av as TimelineFit, aw as TimelinePaging, ax as TimelinePeriod, ay as TimelinePlan, az as TimelineRound, aA as TimelineRounds, aB as TriggerFact, aC as WaitFact } from './layout-ZQ45Tlkb.cjs';
|
|
2
|
+
export { Z as ModelRefusal, _ as Sentence } from './types-DIFPlxBZ.cjs';
|
package/dist/layout.d.ts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { af as Cause, ag as CauseKind, ah as DemandFact, ai as Lever, aj as Lowering, ak as ModelWords, al as Noun, am as NounFacts, J as NounKind, an as NounWords, O as OperationDoc, ao as PlanTimelineItem, ap as ReadBackDoc, aq as TakesFact, ar as TimeFact, T as Timeline, as as Timeline0, at as TimelineCut, au as TimelineFact, av as TimelineFit, aw as TimelinePaging, ax as TimelinePeriod, ay as TimelinePlan, az as TimelineRound, aA as TimelineRounds, aB as TriggerFact, aC as WaitFact } from './layout-efr1Ke_2.js';
|
|
2
|
+
export { Z as ModelRefusal, _ as Sentence } from './types-DIFPlxBZ.js';
|
package/dist/layout.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=layout.js.map
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import { t as IrIssue, u as IrIssueCode, B as Broken, v as ShortOrder } from './types-DIFPlxBZ.js';
|
|
2
|
+
import { Kysely } from 'kysely';
|
|
3
|
+
|
|
4
|
+
/** A mistake in the solver's declaration, found while building. Its message is for the author. */
|
|
5
|
+
declare class ModelError extends Error {
|
|
6
|
+
constructor(message: string, options?: {
|
|
7
|
+
cause?: unknown;
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
/** What `buildSolver` reports: an IR check issue, or `model-error` for a `ModelError`. */
|
|
11
|
+
interface BuildIssue extends Omit<IrIssue, "code"> {
|
|
12
|
+
code: IrIssueCode | "model-error";
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface EqInfo {
|
|
16
|
+
readonly "~name": string;
|
|
17
|
+
readonly "~row": unknown;
|
|
18
|
+
readonly "~need": unknown;
|
|
19
|
+
readonly "~downtimes": string;
|
|
20
|
+
}
|
|
21
|
+
interface StepInfo {
|
|
22
|
+
readonly "~name": string;
|
|
23
|
+
readonly "~refs": string;
|
|
24
|
+
readonly "~on": string;
|
|
25
|
+
readonly "~used": string;
|
|
26
|
+
}
|
|
27
|
+
interface ProcInfo {
|
|
28
|
+
readonly "~def": "process";
|
|
29
|
+
readonly "~name": string;
|
|
30
|
+
readonly "~row": unknown;
|
|
31
|
+
readonly "~steps": StepInfo;
|
|
32
|
+
readonly "~release": string;
|
|
33
|
+
readonly "~list": string;
|
|
34
|
+
readonly "~where": boolean;
|
|
35
|
+
}
|
|
36
|
+
interface Ctx {
|
|
37
|
+
readonly d: unknown;
|
|
38
|
+
readonly b: unknown;
|
|
39
|
+
readonly eq: EqInfo;
|
|
40
|
+
readonly role: string;
|
|
41
|
+
readonly mat: string;
|
|
42
|
+
readonly shift: string;
|
|
43
|
+
readonly proc: ProcInfo;
|
|
44
|
+
}
|
|
45
|
+
type EqOf<C extends Ctx, N> = Extract<C["eq"], {
|
|
46
|
+
readonly "~name": N;
|
|
47
|
+
}>;
|
|
48
|
+
type ProcOf<C extends Ctx, N> = Extract<C["proc"], {
|
|
49
|
+
readonly "~name": N;
|
|
50
|
+
}>;
|
|
51
|
+
type NameOf<P> = P extends {
|
|
52
|
+
readonly "~name": string;
|
|
53
|
+
} ? P["~name"] : never;
|
|
54
|
+
type RosterOf<Ro extends string, Sh extends string> = {
|
|
55
|
+
readonly roles: Ro;
|
|
56
|
+
readonly shifts: Sh;
|
|
57
|
+
};
|
|
58
|
+
type EqId<C extends Ctx, E> = EqOf<C, E>["~row"] extends {
|
|
59
|
+
readonly id: infer Id;
|
|
60
|
+
} ? Id : never;
|
|
61
|
+
interface StepRun<C extends Ctx, S extends StepInfo> extends SkipEmptyRunFields<S["~refs"], [
|
|
62
|
+
S["~on"]
|
|
63
|
+
] extends [never] ? undefined : EqId<C, S["~on"]>> {
|
|
64
|
+
readonly start: Date;
|
|
65
|
+
readonly end: Date;
|
|
66
|
+
held: HeldRead<S["~used"], S["~refs"], EqId<C, S["~used"]>>;
|
|
67
|
+
readonly downtimeBefore: number;
|
|
68
|
+
heldUntil: HeldUntilRead<S["~used"], S["~refs"]>;
|
|
69
|
+
}
|
|
70
|
+
interface Fulfilment<Row> {
|
|
71
|
+
readonly cell: PlanQuantity<Row>;
|
|
72
|
+
readonly amount: number;
|
|
73
|
+
}
|
|
74
|
+
interface ItemRun<C extends Ctx, P extends ProcInfo> {
|
|
75
|
+
readonly id: string;
|
|
76
|
+
readonly label: string;
|
|
77
|
+
readonly row: P["~row"];
|
|
78
|
+
readonly released: [P["~release"]] extends [never] ? "✗ this process isn't released: say .startsInGroups(...) on it" : Date;
|
|
79
|
+
step<const S extends P["~steps"]["~name"]>(name: S): StepRun<C, Extract<P["~steps"], {
|
|
80
|
+
readonly "~name": S;
|
|
81
|
+
}>>;
|
|
82
|
+
readonly period: PlanPeriod;
|
|
83
|
+
readonly amount: number;
|
|
84
|
+
readonly fulfils: readonly Fulfilment<P["~row"]>[];
|
|
85
|
+
}
|
|
86
|
+
type AnyStepName<C extends Ctx> = C["proc"]["~steps"]["~name"];
|
|
87
|
+
interface TaggedItemRun<C extends Ctx, P extends ProcInfo> extends Omit<ItemRun<C, P>, "step"> {
|
|
88
|
+
readonly process: P["~name"];
|
|
89
|
+
step<const S extends AnyStepName<C>>(name: S): S extends P["~steps"]["~name"] ? StepRun<C, Extract<P["~steps"], {
|
|
90
|
+
readonly "~name": S;
|
|
91
|
+
}>> : `✗ the ${P["~name"]} process has no step called “${S}”`;
|
|
92
|
+
}
|
|
93
|
+
type TaggedItems<C extends Ctx> = C["proc"] extends infer P ? P extends ProcInfo ? TaggedItemRun<C, P> : never : never;
|
|
94
|
+
type IsoDay = `${number}-${number}-${number}`;
|
|
95
|
+
interface PlanPeriod {
|
|
96
|
+
readonly id: string;
|
|
97
|
+
readonly label: string;
|
|
98
|
+
readonly from: Date;
|
|
99
|
+
readonly to: Date;
|
|
100
|
+
readonly date: IsoDay;
|
|
101
|
+
}
|
|
102
|
+
interface PlanQuantity<Row> {
|
|
103
|
+
readonly id: string;
|
|
104
|
+
readonly row: Row;
|
|
105
|
+
readonly period: PlanPeriod;
|
|
106
|
+
readonly amount: number;
|
|
107
|
+
}
|
|
108
|
+
interface RosterEntry<Role extends string, Shift extends string> {
|
|
109
|
+
readonly role: Role;
|
|
110
|
+
readonly shift: Shift;
|
|
111
|
+
readonly period: PlanPeriod;
|
|
112
|
+
readonly people: number;
|
|
113
|
+
readonly agency: number;
|
|
114
|
+
readonly overtimeMinutes: number;
|
|
115
|
+
}
|
|
116
|
+
type TaggedQuantity<C extends Ctx> = C["proc"] extends infer P ? P extends ProcInfo ? PlanQuantity<P["~row"]> & {
|
|
117
|
+
readonly process: P["~name"];
|
|
118
|
+
} : never : never;
|
|
119
|
+
interface QuantityPlanResult<C extends Ctx> extends ShortPlanResult {
|
|
120
|
+
quantities<const P extends C["proc"]["~name"]>(process: P): readonly PlanQuantity<ProcOf<C, P>["~row"]>[];
|
|
121
|
+
quantities(): readonly TaggedQuantity<C>[];
|
|
122
|
+
roster(this: "✗ this plan chooses quantities, not a roster: read its cells with .quantities(process)"): never;
|
|
123
|
+
}
|
|
124
|
+
interface RosterPlanResult<Ro extends string, Sh extends string> {
|
|
125
|
+
roster(): readonly RosterEntry<Ro, Sh>[];
|
|
126
|
+
quantities(this: "✗ this plan chooses a roster, not quantities: read it with .roster()", process?: unknown): never;
|
|
127
|
+
}
|
|
128
|
+
type PlanResultOf<C extends Ctx, Pl> = Pl extends {
|
|
129
|
+
readonly "~decides": "quantities";
|
|
130
|
+
} ? QuantityPlanResult<C> : Pl extends {
|
|
131
|
+
readonly "~roster": RosterOf<infer Ro, infer Sh>;
|
|
132
|
+
} ? RosterPlanResult<Ro, Sh> : never;
|
|
133
|
+
interface DowntimeSpan {
|
|
134
|
+
readonly on: string;
|
|
135
|
+
readonly start: Date;
|
|
136
|
+
readonly end: Date;
|
|
137
|
+
readonly before: string | null;
|
|
138
|
+
readonly after: string | null;
|
|
139
|
+
}
|
|
140
|
+
interface DayRun<C extends Ctx> {
|
|
141
|
+
readonly period: PlanPeriod;
|
|
142
|
+
readonly mode: string;
|
|
143
|
+
items<const P extends C["proc"]["~name"]>(process: P): readonly ItemRun<C, ProcOf<C, P>>[];
|
|
144
|
+
items(): readonly TaggedItems<C>[];
|
|
145
|
+
downtime<const D extends C["eq"]["~downtimes"]>(name: D): readonly DowntimeSpan[];
|
|
146
|
+
}
|
|
147
|
+
interface ScheduleResult<C extends Ctx> {
|
|
148
|
+
items<const P extends C["proc"]["~name"]>(process: P): readonly ItemRun<C, ProcOf<C, P>>[];
|
|
149
|
+
items(): readonly TaggedItems<C>[];
|
|
150
|
+
days(): readonly DayRun<C>[];
|
|
151
|
+
}
|
|
152
|
+
interface SolveResult<C extends Ctx, H = never> {
|
|
153
|
+
readonly status: "planned" | "overfull";
|
|
154
|
+
readonly broken: readonly Broken[];
|
|
155
|
+
items<const P extends C["proc"]["~name"]>(process: P): readonly ItemRun<C, ProcOf<C, P>>[];
|
|
156
|
+
items(): readonly TaggedItems<C>[];
|
|
157
|
+
plan<const N extends NameOf<Extract<H, {
|
|
158
|
+
readonly "~def": "plan";
|
|
159
|
+
}>>>(name: N): PlanResultOf<C, Extract<H, {
|
|
160
|
+
readonly "~name": N;
|
|
161
|
+
}>>;
|
|
162
|
+
schedule<const N extends NameOf<Extract<H, {
|
|
163
|
+
readonly "~def": "schedule";
|
|
164
|
+
}>>>(name: N): ScheduleResult<C>;
|
|
165
|
+
}
|
|
166
|
+
type Writable<T> = Partial<Omit<T, "id">>;
|
|
167
|
+
type ModelsApi<Models> = {
|
|
168
|
+
[K in keyof Models]: {
|
|
169
|
+
create(values: Writable<Models[K]>): Promise<Models[K]>;
|
|
170
|
+
update(where: {
|
|
171
|
+
id: string;
|
|
172
|
+
}, values: Writable<Models[K]>): Promise<Models[K]>;
|
|
173
|
+
findOne(where: Partial<Models[K]>): Promise<Models[K] | null>;
|
|
174
|
+
findMany(query?: {
|
|
175
|
+
where?: Record<string, unknown>;
|
|
176
|
+
}): Promise<Models[K][]>;
|
|
177
|
+
delete(where: {
|
|
178
|
+
id: string;
|
|
179
|
+
}): Promise<string>;
|
|
180
|
+
};
|
|
181
|
+
};
|
|
182
|
+
type Matching<T> = {
|
|
183
|
+
[K in keyof T]?: Date extends T[K] ? T[K] | IsoDay : T[K];
|
|
184
|
+
};
|
|
185
|
+
interface ApplyContext<Models, Db> {
|
|
186
|
+
readonly models: ModelsApi<Models>;
|
|
187
|
+
readonly db: Kysely<Db>;
|
|
188
|
+
readonly now: Date;
|
|
189
|
+
upsert<const M extends keyof Models & string>(model: M, match: Matching<Models[M]>, values: Writable<Models[M]>): Promise<Models[M]>;
|
|
190
|
+
replace<const M extends keyof Models & string>(model: M, scope: Matching<Models[M]>, rows: readonly Writable<Models[M]>[], opts: {
|
|
191
|
+
key: readonly (keyof Models[M] & string)[];
|
|
192
|
+
}): Promise<{
|
|
193
|
+
created: number;
|
|
194
|
+
updated: number;
|
|
195
|
+
removed: number;
|
|
196
|
+
}>;
|
|
197
|
+
}
|
|
198
|
+
/** A chosen vessel, kept from first receiving through release (including any turnaround). */
|
|
199
|
+
interface HeldSpan<Id = string> {
|
|
200
|
+
readonly on: Id;
|
|
201
|
+
readonly start: Date;
|
|
202
|
+
readonly end: Date;
|
|
203
|
+
}
|
|
204
|
+
type HeldValue<E extends string, Refs extends string, Id> = E extends unknown ? string extends Refs ? Id : `cover:${E}` extends Refs ? readonly HeldSpan<Id>[] : Id : never;
|
|
205
|
+
/** Covering holds return chosen spans in natural English id order (T2 before T10). */
|
|
206
|
+
type HeldRead<Equipment extends string, Refs extends string, Id> = <E extends Equipment>(equipment: E) => SkipEmptyValue<Refs, HeldValue<E, Refs, Id>>;
|
|
207
|
+
/** Cover candidates share a release; a run that chose no vessel has no held-until time. */
|
|
208
|
+
type UntilValue<E extends string, Refs extends string> = E extends unknown ? string extends Refs ? Date : `cover:${E}` extends Refs ? Date | undefined : Date : never;
|
|
209
|
+
type HeldUntilRead<Equipment extends string, Refs extends string> = <E extends Equipment>(equipment: E) => SkipEmptyValue<Refs, UntilValue<E, Refs>>;
|
|
210
|
+
/** Only an explicitly marked step can have no selected machine or held piece. */
|
|
211
|
+
type SkipEmptyValue<Refs extends string, Value> = string extends Refs ? Value : "skips-empty" extends Refs ? Value | undefined : Value;
|
|
212
|
+
/** The run fields that read undefined when a step skipped. */
|
|
213
|
+
interface SkipEmptyRunFields<Refs extends string, On> {
|
|
214
|
+
readonly on: SkipEmptyValue<Refs, On>;
|
|
215
|
+
readonly order: SkipEmptyValue<Refs, number>;
|
|
216
|
+
}
|
|
217
|
+
interface ShortPlanResult {
|
|
218
|
+
/** Each order left short, with its amount and an operator sentence. */
|
|
219
|
+
short(): readonly ShortOrder[];
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export { type ApplyContext as A, type BuildIssue as B, type Ctx as C, ModelError as M, type SolveResult as S };
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import { t as IrIssue, u as IrIssueCode, B as Broken, v as ShortOrder } from './types-DIFPlxBZ.cjs';
|
|
2
|
+
import { Kysely } from 'kysely';
|
|
3
|
+
|
|
4
|
+
/** A mistake in the solver's declaration, found while building. Its message is for the author. */
|
|
5
|
+
declare class ModelError extends Error {
|
|
6
|
+
constructor(message: string, options?: {
|
|
7
|
+
cause?: unknown;
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
/** What `buildSolver` reports: an IR check issue, or `model-error` for a `ModelError`. */
|
|
11
|
+
interface BuildIssue extends Omit<IrIssue, "code"> {
|
|
12
|
+
code: IrIssueCode | "model-error";
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface EqInfo {
|
|
16
|
+
readonly "~name": string;
|
|
17
|
+
readonly "~row": unknown;
|
|
18
|
+
readonly "~need": unknown;
|
|
19
|
+
readonly "~downtimes": string;
|
|
20
|
+
}
|
|
21
|
+
interface StepInfo {
|
|
22
|
+
readonly "~name": string;
|
|
23
|
+
readonly "~refs": string;
|
|
24
|
+
readonly "~on": string;
|
|
25
|
+
readonly "~used": string;
|
|
26
|
+
}
|
|
27
|
+
interface ProcInfo {
|
|
28
|
+
readonly "~def": "process";
|
|
29
|
+
readonly "~name": string;
|
|
30
|
+
readonly "~row": unknown;
|
|
31
|
+
readonly "~steps": StepInfo;
|
|
32
|
+
readonly "~release": string;
|
|
33
|
+
readonly "~list": string;
|
|
34
|
+
readonly "~where": boolean;
|
|
35
|
+
}
|
|
36
|
+
interface Ctx {
|
|
37
|
+
readonly d: unknown;
|
|
38
|
+
readonly b: unknown;
|
|
39
|
+
readonly eq: EqInfo;
|
|
40
|
+
readonly role: string;
|
|
41
|
+
readonly mat: string;
|
|
42
|
+
readonly shift: string;
|
|
43
|
+
readonly proc: ProcInfo;
|
|
44
|
+
}
|
|
45
|
+
type EqOf<C extends Ctx, N> = Extract<C["eq"], {
|
|
46
|
+
readonly "~name": N;
|
|
47
|
+
}>;
|
|
48
|
+
type ProcOf<C extends Ctx, N> = Extract<C["proc"], {
|
|
49
|
+
readonly "~name": N;
|
|
50
|
+
}>;
|
|
51
|
+
type NameOf<P> = P extends {
|
|
52
|
+
readonly "~name": string;
|
|
53
|
+
} ? P["~name"] : never;
|
|
54
|
+
type RosterOf<Ro extends string, Sh extends string> = {
|
|
55
|
+
readonly roles: Ro;
|
|
56
|
+
readonly shifts: Sh;
|
|
57
|
+
};
|
|
58
|
+
type EqId<C extends Ctx, E> = EqOf<C, E>["~row"] extends {
|
|
59
|
+
readonly id: infer Id;
|
|
60
|
+
} ? Id : never;
|
|
61
|
+
interface StepRun<C extends Ctx, S extends StepInfo> extends SkipEmptyRunFields<S["~refs"], [
|
|
62
|
+
S["~on"]
|
|
63
|
+
] extends [never] ? undefined : EqId<C, S["~on"]>> {
|
|
64
|
+
readonly start: Date;
|
|
65
|
+
readonly end: Date;
|
|
66
|
+
held: HeldRead<S["~used"], S["~refs"], EqId<C, S["~used"]>>;
|
|
67
|
+
readonly downtimeBefore: number;
|
|
68
|
+
heldUntil: HeldUntilRead<S["~used"], S["~refs"]>;
|
|
69
|
+
}
|
|
70
|
+
interface Fulfilment<Row> {
|
|
71
|
+
readonly cell: PlanQuantity<Row>;
|
|
72
|
+
readonly amount: number;
|
|
73
|
+
}
|
|
74
|
+
interface ItemRun<C extends Ctx, P extends ProcInfo> {
|
|
75
|
+
readonly id: string;
|
|
76
|
+
readonly label: string;
|
|
77
|
+
readonly row: P["~row"];
|
|
78
|
+
readonly released: [P["~release"]] extends [never] ? "✗ this process isn't released: say .startsInGroups(...) on it" : Date;
|
|
79
|
+
step<const S extends P["~steps"]["~name"]>(name: S): StepRun<C, Extract<P["~steps"], {
|
|
80
|
+
readonly "~name": S;
|
|
81
|
+
}>>;
|
|
82
|
+
readonly period: PlanPeriod;
|
|
83
|
+
readonly amount: number;
|
|
84
|
+
readonly fulfils: readonly Fulfilment<P["~row"]>[];
|
|
85
|
+
}
|
|
86
|
+
type AnyStepName<C extends Ctx> = C["proc"]["~steps"]["~name"];
|
|
87
|
+
interface TaggedItemRun<C extends Ctx, P extends ProcInfo> extends Omit<ItemRun<C, P>, "step"> {
|
|
88
|
+
readonly process: P["~name"];
|
|
89
|
+
step<const S extends AnyStepName<C>>(name: S): S extends P["~steps"]["~name"] ? StepRun<C, Extract<P["~steps"], {
|
|
90
|
+
readonly "~name": S;
|
|
91
|
+
}>> : `✗ the ${P["~name"]} process has no step called “${S}”`;
|
|
92
|
+
}
|
|
93
|
+
type TaggedItems<C extends Ctx> = C["proc"] extends infer P ? P extends ProcInfo ? TaggedItemRun<C, P> : never : never;
|
|
94
|
+
type IsoDay = `${number}-${number}-${number}`;
|
|
95
|
+
interface PlanPeriod {
|
|
96
|
+
readonly id: string;
|
|
97
|
+
readonly label: string;
|
|
98
|
+
readonly from: Date;
|
|
99
|
+
readonly to: Date;
|
|
100
|
+
readonly date: IsoDay;
|
|
101
|
+
}
|
|
102
|
+
interface PlanQuantity<Row> {
|
|
103
|
+
readonly id: string;
|
|
104
|
+
readonly row: Row;
|
|
105
|
+
readonly period: PlanPeriod;
|
|
106
|
+
readonly amount: number;
|
|
107
|
+
}
|
|
108
|
+
interface RosterEntry<Role extends string, Shift extends string> {
|
|
109
|
+
readonly role: Role;
|
|
110
|
+
readonly shift: Shift;
|
|
111
|
+
readonly period: PlanPeriod;
|
|
112
|
+
readonly people: number;
|
|
113
|
+
readonly agency: number;
|
|
114
|
+
readonly overtimeMinutes: number;
|
|
115
|
+
}
|
|
116
|
+
type TaggedQuantity<C extends Ctx> = C["proc"] extends infer P ? P extends ProcInfo ? PlanQuantity<P["~row"]> & {
|
|
117
|
+
readonly process: P["~name"];
|
|
118
|
+
} : never : never;
|
|
119
|
+
interface QuantityPlanResult<C extends Ctx> extends ShortPlanResult {
|
|
120
|
+
quantities<const P extends C["proc"]["~name"]>(process: P): readonly PlanQuantity<ProcOf<C, P>["~row"]>[];
|
|
121
|
+
quantities(): readonly TaggedQuantity<C>[];
|
|
122
|
+
roster(this: "✗ this plan chooses quantities, not a roster: read its cells with .quantities(process)"): never;
|
|
123
|
+
}
|
|
124
|
+
interface RosterPlanResult<Ro extends string, Sh extends string> {
|
|
125
|
+
roster(): readonly RosterEntry<Ro, Sh>[];
|
|
126
|
+
quantities(this: "✗ this plan chooses a roster, not quantities: read it with .roster()", process?: unknown): never;
|
|
127
|
+
}
|
|
128
|
+
type PlanResultOf<C extends Ctx, Pl> = Pl extends {
|
|
129
|
+
readonly "~decides": "quantities";
|
|
130
|
+
} ? QuantityPlanResult<C> : Pl extends {
|
|
131
|
+
readonly "~roster": RosterOf<infer Ro, infer Sh>;
|
|
132
|
+
} ? RosterPlanResult<Ro, Sh> : never;
|
|
133
|
+
interface DowntimeSpan {
|
|
134
|
+
readonly on: string;
|
|
135
|
+
readonly start: Date;
|
|
136
|
+
readonly end: Date;
|
|
137
|
+
readonly before: string | null;
|
|
138
|
+
readonly after: string | null;
|
|
139
|
+
}
|
|
140
|
+
interface DayRun<C extends Ctx> {
|
|
141
|
+
readonly period: PlanPeriod;
|
|
142
|
+
readonly mode: string;
|
|
143
|
+
items<const P extends C["proc"]["~name"]>(process: P): readonly ItemRun<C, ProcOf<C, P>>[];
|
|
144
|
+
items(): readonly TaggedItems<C>[];
|
|
145
|
+
downtime<const D extends C["eq"]["~downtimes"]>(name: D): readonly DowntimeSpan[];
|
|
146
|
+
}
|
|
147
|
+
interface ScheduleResult<C extends Ctx> {
|
|
148
|
+
items<const P extends C["proc"]["~name"]>(process: P): readonly ItemRun<C, ProcOf<C, P>>[];
|
|
149
|
+
items(): readonly TaggedItems<C>[];
|
|
150
|
+
days(): readonly DayRun<C>[];
|
|
151
|
+
}
|
|
152
|
+
interface SolveResult<C extends Ctx, H = never> {
|
|
153
|
+
readonly status: "planned" | "overfull";
|
|
154
|
+
readonly broken: readonly Broken[];
|
|
155
|
+
items<const P extends C["proc"]["~name"]>(process: P): readonly ItemRun<C, ProcOf<C, P>>[];
|
|
156
|
+
items(): readonly TaggedItems<C>[];
|
|
157
|
+
plan<const N extends NameOf<Extract<H, {
|
|
158
|
+
readonly "~def": "plan";
|
|
159
|
+
}>>>(name: N): PlanResultOf<C, Extract<H, {
|
|
160
|
+
readonly "~name": N;
|
|
161
|
+
}>>;
|
|
162
|
+
schedule<const N extends NameOf<Extract<H, {
|
|
163
|
+
readonly "~def": "schedule";
|
|
164
|
+
}>>>(name: N): ScheduleResult<C>;
|
|
165
|
+
}
|
|
166
|
+
type Writable<T> = Partial<Omit<T, "id">>;
|
|
167
|
+
type ModelsApi<Models> = {
|
|
168
|
+
[K in keyof Models]: {
|
|
169
|
+
create(values: Writable<Models[K]>): Promise<Models[K]>;
|
|
170
|
+
update(where: {
|
|
171
|
+
id: string;
|
|
172
|
+
}, values: Writable<Models[K]>): Promise<Models[K]>;
|
|
173
|
+
findOne(where: Partial<Models[K]>): Promise<Models[K] | null>;
|
|
174
|
+
findMany(query?: {
|
|
175
|
+
where?: Record<string, unknown>;
|
|
176
|
+
}): Promise<Models[K][]>;
|
|
177
|
+
delete(where: {
|
|
178
|
+
id: string;
|
|
179
|
+
}): Promise<string>;
|
|
180
|
+
};
|
|
181
|
+
};
|
|
182
|
+
type Matching<T> = {
|
|
183
|
+
[K in keyof T]?: Date extends T[K] ? T[K] | IsoDay : T[K];
|
|
184
|
+
};
|
|
185
|
+
interface ApplyContext<Models, Db> {
|
|
186
|
+
readonly models: ModelsApi<Models>;
|
|
187
|
+
readonly db: Kysely<Db>;
|
|
188
|
+
readonly now: Date;
|
|
189
|
+
upsert<const M extends keyof Models & string>(model: M, match: Matching<Models[M]>, values: Writable<Models[M]>): Promise<Models[M]>;
|
|
190
|
+
replace<const M extends keyof Models & string>(model: M, scope: Matching<Models[M]>, rows: readonly Writable<Models[M]>[], opts: {
|
|
191
|
+
key: readonly (keyof Models[M] & string)[];
|
|
192
|
+
}): Promise<{
|
|
193
|
+
created: number;
|
|
194
|
+
updated: number;
|
|
195
|
+
removed: number;
|
|
196
|
+
}>;
|
|
197
|
+
}
|
|
198
|
+
/** A chosen vessel, kept from first receiving through release (including any turnaround). */
|
|
199
|
+
interface HeldSpan<Id = string> {
|
|
200
|
+
readonly on: Id;
|
|
201
|
+
readonly start: Date;
|
|
202
|
+
readonly end: Date;
|
|
203
|
+
}
|
|
204
|
+
type HeldValue<E extends string, Refs extends string, Id> = E extends unknown ? string extends Refs ? Id : `cover:${E}` extends Refs ? readonly HeldSpan<Id>[] : Id : never;
|
|
205
|
+
/** Covering holds return chosen spans in natural English id order (T2 before T10). */
|
|
206
|
+
type HeldRead<Equipment extends string, Refs extends string, Id> = <E extends Equipment>(equipment: E) => SkipEmptyValue<Refs, HeldValue<E, Refs, Id>>;
|
|
207
|
+
/** Cover candidates share a release; a run that chose no vessel has no held-until time. */
|
|
208
|
+
type UntilValue<E extends string, Refs extends string> = E extends unknown ? string extends Refs ? Date : `cover:${E}` extends Refs ? Date | undefined : Date : never;
|
|
209
|
+
type HeldUntilRead<Equipment extends string, Refs extends string> = <E extends Equipment>(equipment: E) => SkipEmptyValue<Refs, UntilValue<E, Refs>>;
|
|
210
|
+
/** Only an explicitly marked step can have no selected machine or held piece. */
|
|
211
|
+
type SkipEmptyValue<Refs extends string, Value> = string extends Refs ? Value : "skips-empty" extends Refs ? Value | undefined : Value;
|
|
212
|
+
/** The run fields that read undefined when a step skipped. */
|
|
213
|
+
interface SkipEmptyRunFields<Refs extends string, On> {
|
|
214
|
+
readonly on: SkipEmptyValue<Refs, On>;
|
|
215
|
+
readonly order: SkipEmptyValue<Refs, number>;
|
|
216
|
+
}
|
|
217
|
+
interface ShortPlanResult {
|
|
218
|
+
/** Each order left short, with its amount and an operator sentence. */
|
|
219
|
+
short(): readonly ShortOrder[];
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export { type ApplyContext as A, type BuildIssue as B, type Ctx as C, ModelError as M, type SolveResult as S };
|