@kosdev-code/kos-dispense-sdk 2.0.12 → 2.0.16

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.
Files changed (62) hide show
  1. package/dispense-registration-manager-BXNJ1hUZ.cjs +2 -0
  2. package/dispense-registration-manager-BXNJ1hUZ.cjs.map +1 -0
  3. package/dispense-registration-manager-UjShRcvq.js +1933 -0
  4. package/dispense-registration-manager-UjShRcvq.js.map +1 -0
  5. package/{extension-utils-CMoNCoHG.js → extension-utils-DrKHgDXC.js} +53 -49
  6. package/{extension-utils-CMoNCoHG.js.map → extension-utils-DrKHgDXC.js.map} +1 -1
  7. package/extension-utils-lo_uDdh9.cjs +2 -0
  8. package/{extension-utils-BMU452cN.cjs.map → extension-utils-lo_uDdh9.cjs.map} +1 -1
  9. package/index.cjs +1 -1
  10. package/index.d.ts +1 -0
  11. package/index.d.ts.map +1 -1
  12. package/index.js +91 -86
  13. package/models/models/generic-pour/generic-pour-model.d.ts +52 -0
  14. package/models/models/generic-pour/generic-pour-model.d.ts.map +1 -0
  15. package/models/models/generic-pour/generic-pour-registration.d.ts +87 -0
  16. package/models/models/generic-pour/generic-pour-registration.d.ts.map +1 -0
  17. package/models/models/generic-pour/index.d.ts +5 -0
  18. package/models/models/generic-pour/index.d.ts.map +1 -0
  19. package/models/models/generic-pour/services/generic-pour-services.d.ts +16 -0
  20. package/models/models/generic-pour/services/generic-pour-services.d.ts.map +1 -0
  21. package/models/models/generic-pour/services/index.d.ts +2 -0
  22. package/models/models/generic-pour/services/index.d.ts.map +1 -0
  23. package/models/models/generic-pour/types/index.d.ts +5 -0
  24. package/models/models/index.d.ts +1 -0
  25. package/models/models/index.d.ts.map +1 -1
  26. package/models/models/nozzle/nozzle-model.d.ts.map +1 -1
  27. package/models.cjs +1 -1
  28. package/models.js +18 -16
  29. package/package.json +3 -3
  30. package/pump-provider-DMGN5lvz.cjs +2 -0
  31. package/pump-provider-DMGN5lvz.cjs.map +1 -0
  32. package/pump-provider-DpNSFHld.js +1065 -0
  33. package/pump-provider-DpNSFHld.js.map +1 -0
  34. package/ui/hooks/generic-pour/index.d.ts +3 -0
  35. package/ui/hooks/generic-pour/index.d.ts.map +1 -0
  36. package/ui/hooks/generic-pour/use-generic-pour.d.ts +14 -0
  37. package/ui/hooks/generic-pour/use-generic-pour.d.ts.map +1 -0
  38. package/ui/hooks/generic-pour/with-generic-pour.d.ts +14 -0
  39. package/ui/hooks/generic-pour/with-generic-pour.d.ts.map +1 -0
  40. package/ui/hooks/index.d.ts +2 -0
  41. package/ui/hooks/index.d.ts.map +1 -1
  42. package/ui/hooks/pour/index.d.ts +2 -0
  43. package/ui/hooks/pour/index.d.ts.map +1 -0
  44. package/ui/hooks/pour/use-pour.d.ts +50 -0
  45. package/ui/hooks/pour/use-pour.d.ts.map +1 -0
  46. package/ui/hooks/utils/pour-strategy/hold-to-pour-strategy.d.ts.map +1 -1
  47. package/ui/hooks/utils/pour-strategy/pour-strategy.d.ts +12 -4
  48. package/ui/hooks/utils/pour-strategy/pour-strategy.d.ts.map +1 -1
  49. package/ui/hooks/utils/pour-strategy/tap-or-hold-to-pour-intent-strategy.d.ts +2 -2
  50. package/ui/hooks/utils/pour-strategy/tap-or-hold-to-pour-intent-strategy.d.ts.map +1 -1
  51. package/ui/hooks/utils/pour-strategy/tap-to-pour-strategy.d.ts.map +1 -1
  52. package/ui.cjs +1 -1
  53. package/ui.js +42 -39
  54. package/dispense-registration-manager-BtVe7yFS.js +0 -1770
  55. package/dispense-registration-manager-BtVe7yFS.js.map +0 -1
  56. package/dispense-registration-manager-CcV-anPv.cjs +0 -2
  57. package/dispense-registration-manager-CcV-anPv.cjs.map +0 -1
  58. package/extension-utils-BMU452cN.cjs +0 -2
  59. package/pump-provider-3XH9JScg.js +0 -1016
  60. package/pump-provider-3XH9JScg.js.map +0 -1
  61. package/pump-provider-CyLiBpMN.cjs +0 -2
  62. package/pump-provider-CyLiBpMN.cjs.map +0 -1
@@ -0,0 +1,1933 @@
1
+ var pt = Object.defineProperty;
2
+ var ut = (e, t, r) => t in e ? pt(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
+ var o = (e, t, r) => (ut(e, typeof t != "symbol" ? t + "" : t, r), r);
4
+ import { kosModel as I, isKosModel as v, Kos as b, resolveServiceUrl as C, ServiceFactory as S, KosLog as m, KosModelContainer as R, KosExtensionUtils as T, kosChild as M, FetchError as ht, ExtensionManager as h, EXTENSION_TROUBLE_MAPPER as Me, EXTENSION_TROUBLE_DATA_MAPPER as W, getKosModelSync as z, kosDependency as ce, TroubleContainer as xe, troubleByTypeReducer as Ae, kosAction as g, kosTopicHandler as Q, DependencyLifecycle as Be, getKosModel as Ue, FutureManager as pe, kosFuture as ue, FutureHandler as Ge, isKosDataModel as gt, ChildModels as yt, KosFeatureFlags as It, kosParentAware as ft, createPropKey as mt, MultipleFutureHandler as Pt, arraysEqual as vt, getAllKosCompanionModels as E, EventBus as _, KosContextManager as bt, destroyKosModel as _t, SingletonKosModelRegistrationFactory as Mt, KosModelRegistrationFactory as Ot, KosModelRegistry as Et, RegistrationManager as O, registerCoreModels as wt, registerLegacyModel as $t } from "@kosdev-code/kos-ui-sdk";
5
+ import "react";
6
+ var u = /* @__PURE__ */ ((e) => (e.IngredientLoader = "kos.ingredient.loader", e.IngredientMapper = "kos.ingredient.mapper", e.IngredientIndex = "kos.ingredient.index", e.IngredientTypeMapper = "kos.ingredient.type.mapper", e.HolderTypeMapper = "kos.holder.type.mapper", e.HolderMapper = "kos.holder.mapper", e.HolderIndex = "kos.holder.index", e.HolderIngredientMapper = "kos.holder.ingredient.mapper", e.AvailabilityMapper = "kos.availability.mapper", e.AvailabilityLoader = "kos.availability.loader", e.SelectedPourableMapper = "kos.selected.pourable.mapper", e.AssemblyMapper = "kos.assembly.mapper", e.BoardMapper = "kos.board.mapper", e.BoardIndex = "kos.board.index", e.PumpIndex = "kos.pump.index", e))(u || {}), D = /* @__PURE__ */ ((e) => (e.Nozzle = "nozzle-model", e.Availability = "availability-model", e.Holder = "holder-model", e.HolderContainer = "holder-container-model", e.IngredientContainer = "ingredient-container-model", e.Ingredient = "ingredient-model", e.Pump = "pump-model", e.PumpContainer = "pump-container-model", e))(D || {}), Ct = Object.defineProperty, St = Object.getOwnPropertyDescriptor, Rt = (e, t, r, n) => {
7
+ for (var i = n > 1 ? void 0 : n ? St(t, r) : t, a = e.length - 1, s; a >= 0; a--)
8
+ (s = e[a]) && (i = (n ? s(t, r, i) : s(i)) || i);
9
+ return n && i && Ct(t, r, i), i;
10
+ };
11
+ const G = "ingredient-model";
12
+ let Pe = class {
13
+ constructor(e, {
14
+ name: t,
15
+ type: r,
16
+ data: n,
17
+ ingredientId: i,
18
+ ...a
19
+ }) {
20
+ o(this, "id");
21
+ o(this, "ingredientId");
22
+ o(this, "name");
23
+ o(this, "type");
24
+ o(this, "data");
25
+ this.id = e, this.ingredientId = i, this.name = t, this.type = r, this.data = n, Object.assign(this, a);
26
+ }
27
+ updateModel({
28
+ name: e,
29
+ type: t,
30
+ data: r,
31
+ ingredientId: n,
32
+ ...i
33
+ }) {
34
+ this.name = e, this.type = t, this.ingredientId = n, this.data = r, Object.assign(this, i);
35
+ }
36
+ // -------------------LIFECYCLE----------------------------
37
+ // -------------------ENTITY----------------------------
38
+ };
39
+ Pe = Rt([
40
+ I(G)
41
+ ], Pe);
42
+ const je = {
43
+ registration: {
44
+ [G]: {
45
+ class: Pe,
46
+ singleton: !1
47
+ }
48
+ },
49
+ type: G,
50
+ predicate: v(G),
51
+ factory: b.Factory.create(G)
52
+ }, { URL: Fe } = C("INGREDIENT_SERVICE"), { getOne: Dt } = S.build({
53
+ basePath: `${Fe}/api/ext/dispense/ingredients`
54
+ }), Nt = async () => await Dt({
55
+ urlOverride: `${Fe}/api/ext/dispense/ingredients`
56
+ });
57
+ var Tt = Object.defineProperty, zt = Object.getOwnPropertyDescriptor, He = (e, t, r, n) => {
58
+ for (var i = n > 1 ? void 0 : n ? zt(t, r) : t, a = e.length - 1, s; a >= 0; a--)
59
+ (s = e[a]) && (i = (n ? s(t, r, i) : s(i)) || i);
60
+ return n && i && Tt(t, r, i), i;
61
+ };
62
+ const j = "ingredient-container-model", Lt = m.createLogger({ name: "ingredient-container-model" });
63
+ let ne = class {
64
+ constructor(e, t) {
65
+ o(this, "id");
66
+ o(this, "ingredients");
67
+ this.id = e, this.ingredients = new R({
68
+ indexMap: {
69
+ ingredientType: "type"
70
+ },
71
+ extensionId: u.IngredientIndex,
72
+ parentId: e
73
+ });
74
+ }
75
+ updateModel() {
76
+ }
77
+ // -------------------LIFECYCLE----------------------------
78
+ getIngredientsByType(e) {
79
+ return this.ingredients.getIndexByKey("ingredientType", e);
80
+ }
81
+ async load(e) {
82
+ var i;
83
+ Lt.debug(`loading ingredient container ${this.id}`);
84
+ const t = await Nt();
85
+ if ((t == null ? void 0 : t.status) !== 200)
86
+ throw new Error("Failed to load ingredients");
87
+ const r = await T.executeLoaderExtension({
88
+ context: e,
89
+ extension: u.IngredientLoader
90
+ }), n = (t == null ? void 0 : t.data) ?? {};
91
+ for (const a of Object.keys(n))
92
+ for (const s of ((i = t == null ? void 0 : t.data) == null ? void 0 : i[a]) || []) {
93
+ const c = await T.executeDataMapperExtension({
94
+ extension: u.IngredientMapper,
95
+ data: s,
96
+ contextData: r
97
+ }), l = await T.executePropertyMapperExtension({
98
+ extension: u.IngredientTypeMapper,
99
+ data: s,
100
+ contextData: r
101
+ }), p = {
102
+ ...s,
103
+ type: l || s.type,
104
+ ...c,
105
+ data: c
106
+ }, y = je.factory(s.id)(
107
+ p
108
+ );
109
+ this.ingredients.addModel(y);
110
+ }
111
+ }
112
+ // -------------------ENTITY----------------------------
113
+ };
114
+ He([
115
+ M
116
+ ], ne.prototype, "ingredients", 2);
117
+ ne = He([
118
+ I(j)
119
+ ], ne);
120
+ const Ke = {
121
+ registration: {
122
+ [j]: {
123
+ class: ne,
124
+ singleton: !0
125
+ }
126
+ },
127
+ type: j,
128
+ predicate: v(j),
129
+ factory: b.Singleton.create(j)
130
+ }, { URL: he } = C("HOLDER_SERVICE"), { getAll: xt, postModel: Ve, deleteModel: At } = S.build({
131
+ basePath: `${he}/api/kos/holders`
132
+ }), Bt = m.createLogger({
133
+ name: "holder-service",
134
+ group: "Services"
135
+ }), ii = async () => await xt({}), Ut = async (e, t) => {
136
+ if (!e || !t)
137
+ throw new Error("Missing holderPath or ingredientId");
138
+ return await Ve({
139
+ model: { holderPath: e, ingredientId: t },
140
+ urlOverride: `${he}/api/ext/dispense/assignments`
141
+ });
142
+ }, Gt = async (e) => {
143
+ if (!e)
144
+ throw new Error("Missing holderPath");
145
+ return await At({
146
+ id: e,
147
+ urlOverride: `${he}/api/ext/dispense/assignments/${e}`
148
+ });
149
+ }, jt = async (e) => {
150
+ if (!e)
151
+ throw new Error("Missing holderPath");
152
+ return Bt.debug(
153
+ `sending POST request to /api/ext/dispense/pumpEvents/replaceLine/${e}`
154
+ ), await Ve({
155
+ model: {},
156
+ urlOverride: `${he}/api/ext/dispense/pumpEvents/replaceLine/${e}`
157
+ });
158
+ }, { URL: ae } = C("ASSIGNMENT_SERVICE"), { getAll: Ft, postModel: Ye, deleteModel: Ht } = S.build({
159
+ destinationAddress: "",
160
+ basePath: `${ae}/api/ext/dispense/assignments`
161
+ }), se = window.kosUseFos, ni = async () => await Ft({ fos: se }), Kt = async (e, t) => {
162
+ var i, a, s, c;
163
+ const r = JSON.stringify(t), n = `${ae}/api/ext/dispense/assignments`;
164
+ try {
165
+ const l = await Ye({
166
+ model: { holderPath: e, factoryJson: r },
167
+ urlOverride: n
168
+ });
169
+ return (l == null ? void 0 : l.status) === 200 && ((i = l == null ? void 0 : l.data) != null && i.error) ? [l.data.error || "unknownError", l.data] : [void 0, l == null ? void 0 : l.data];
170
+ } catch (l) {
171
+ if (l instanceof ht)
172
+ return [
173
+ ((s = (a = l.payload) == null ? void 0 : a.data) == null ? void 0 : s.error) || "unknownError",
174
+ (c = l.payload) == null ? void 0 : c.data
175
+ ];
176
+ }
177
+ return ["unknownError", void 0];
178
+ }, ai = async (e) => {
179
+ const t = se ? `${ae}/api/ingredients/assignments/${e.holderPath}` : `${ae}/api/ext/dispense/assignments`;
180
+ return await Ye({
181
+ model: { ...e, fuelGauge: 680 },
182
+ fos: se,
183
+ urlOverride: t
184
+ });
185
+ }, si = async (e) => await Ht({ id: e, fos: se });
186
+ var Vt = Object.defineProperty, Yt = Object.getOwnPropertyDescriptor, ge = (e, t, r, n) => {
187
+ for (var i = n > 1 ? void 0 : n ? Yt(t, r) : t, a = e.length - 1, s; a >= 0; a--)
188
+ (s = e[a]) && (i = (n ? s(t, r, i) : s(i)) || i);
189
+ return n && i && Vt(t, r, i), i;
190
+ };
191
+ const F = D.Holder, De = m.createLogger({ name: "holder-model" });
192
+ h[Me].register(
193
+ "holder",
194
+ async (e) => {
195
+ const t = [];
196
+ return t.push(...e.data.holderPaths), t;
197
+ }
198
+ );
199
+ h[W].register(
200
+ "pump",
201
+ async (e) => {
202
+ if (e.data.pumpPath) {
203
+ const { model: t } = z(
204
+ e.data.pumpPath
205
+ );
206
+ if (t) {
207
+ const r = t.ingredientId ? z(t.ingredientId).model : void 0;
208
+ return {
209
+ ingredientId: t.ingredientId,
210
+ ingredientName: (r == null ? void 0 : r.displayName) ?? ((r == null ? void 0 : r.name) || ""),
211
+ childPumpName: t.name
212
+ };
213
+ }
214
+ }
215
+ return {};
216
+ }
217
+ );
218
+ h[W].register(
219
+ "holder",
220
+ async (e) => e.data.holderNames.length > 0 ? {
221
+ holderName: e.data.holderNames[0] || ""
222
+ } : {}
223
+ );
224
+ h[W].register(
225
+ "container",
226
+ async (e) => {
227
+ if (e.data.ingredients.length > 0) {
228
+ const t = e.data.ingredients[0], { model: r } = z(t);
229
+ return {
230
+ ingredientName: (r == null ? void 0 : r.displayName) ?? ((r == null ? void 0 : r.name) || ""),
231
+ ingredients: e.data.ingredients ? e.data.ingredients : [],
232
+ unknonwnIngredientId: e.data.unknonwnIngredientId ?? ""
233
+ };
234
+ }
235
+ return {};
236
+ }
237
+ );
238
+ class kt extends Error {
239
+ constructor(r, n) {
240
+ super(n);
241
+ o(this, "type");
242
+ this.name = "AssignmentError", this.type = r;
243
+ }
244
+ }
245
+ let L = class {
246
+ constructor(e, {
247
+ path: t,
248
+ name: r,
249
+ ingredientSource: n,
250
+ ingredientId: i,
251
+ ingredientType: a,
252
+ slice: s,
253
+ group: c,
254
+ data: l,
255
+ enjoyByDate: p
256
+ }, y) {
257
+ o(this, "id");
258
+ o(this, "path");
259
+ o(this, "name");
260
+ o(this, "ingredientId");
261
+ o(this, "ingredientType");
262
+ o(this, "ingredientSource");
263
+ o(this, "group");
264
+ o(this, "slice");
265
+ o(this, "logger");
266
+ o(this, "data");
267
+ o(this, "enjoyByDate");
268
+ o(this, "pumps");
269
+ o(this, "ingredientContainer");
270
+ o(this, "troubleContainer");
271
+ this.id = e, this.path = t, this.name = r, this.ingredientType = a, this.ingredientSource = n, this.ingredientId = i, this.group = c, this.slice = s, this.enjoyByDate = p, this.data = l, this.pumps = new R({
272
+ parentId: e,
273
+ sortKey: "path"
274
+ }), this.logger = y.logger;
275
+ }
276
+ updateModel({
277
+ path: e,
278
+ name: t,
279
+ ingredientSource: r,
280
+ ingredientId: n,
281
+ ingredientType: i,
282
+ group: a,
283
+ slice: s,
284
+ enjoyByDate: c,
285
+ data: l
286
+ }) {
287
+ this.path = e, this.name = t, this.ingredientId = n, this.ingredientType = i, this.ingredientSource = r, this.enjoyByDate = c, this.slice = s, this.group = a, this.data = l;
288
+ }
289
+ get hasEnjoyByDate() {
290
+ return !!this.enjoyByDate && !this.unassigned;
291
+ }
292
+ get hasEnjoyByWarning() {
293
+ var e;
294
+ return ((e = this.troublesByType.EnjoyByTrouble) == null ? void 0 : e.length) > 0;
295
+ }
296
+ get nozzlePaths() {
297
+ return this.pumps.data.map((e) => e.nozzlePath);
298
+ }
299
+ async cancelPour() {
300
+ await Promise.all(
301
+ this.pumps.data.filter((e) => e.isPouring).map((e) => e.cancelPour())
302
+ );
303
+ }
304
+ get canPour() {
305
+ return !this.shouldDefer && this.pumps.data.every((e) => e.canPour);
306
+ }
307
+ get isPouring() {
308
+ const e = this.pumps.data.some((t) => t.isPouring);
309
+ return this.logger.debug(`isPouring: ${!!e}`), e;
310
+ }
311
+ async performIntent(e) {
312
+ const t = typeof e == "string" ? e : e.intent, r = typeof e == "string" ? void 0 : e.pumpPath, n = r ? this.pumps.getModel(r) : this.pumps.data[0];
313
+ return n == null ? void 0 : n.performIntent({ intent: t });
314
+ }
315
+ get pourState() {
316
+ return this.pumps.data.reduce((t, r) => r.pouringState ? r.pouringState : t, "");
317
+ }
318
+ get nozzlePath() {
319
+ var e;
320
+ return (e = this.pumps.data[0]) == null ? void 0 : e.nozzlePath;
321
+ }
322
+ get pumpPaths() {
323
+ return this.pumps.data.map((e) => e.id);
324
+ }
325
+ get sortedPumps() {
326
+ return this.pumps.data.sort((e, t) => e.virtual && !t.virtual ? -1 : !e.virtual && t.virtual ? 1 : e.name.localeCompare(t.name));
327
+ }
328
+ get ingredient() {
329
+ var t;
330
+ return this.ingredientId ? (t = this.ingredientContainer) == null ? void 0 : t.ingredients.getModel(
331
+ this.ingredientId
332
+ ) : void 0;
333
+ }
334
+ get ingredientName() {
335
+ return this.ingredient ? this.ingredient.displayName ?? this.ingredient.name : this.ingredientId ? "unknown" : "";
336
+ }
337
+ get previousIngredient() {
338
+ var t;
339
+ return this.prevIngredientId ? (t = this.ingredientContainer) == null ? void 0 : t.ingredients.getModel(
340
+ this.prevIngredientId
341
+ ) : void 0;
342
+ }
343
+ get previousIngredientName() {
344
+ return this.previousIngredient ? this.previousIngredient.displayName ?? this.previousIngredient.name : this.prevIngredientId ? "unknown" : "";
345
+ }
346
+ get troubles() {
347
+ return this.troubleContainer.troubles.getIndexByKey("byIface", this.path).sort((e, t) => t.rank - e.rank);
348
+ }
349
+ get troubleStatus() {
350
+ return "";
351
+ }
352
+ get troublesByType() {
353
+ return this.troubles.reduce(
354
+ Ae,
355
+ {}
356
+ );
357
+ }
358
+ get prevIngredientId() {
359
+ var e, t;
360
+ return (t = (e = this.pumps.data) == null ? void 0 : e[0]) == null ? void 0 : t.prevIngredientId;
361
+ }
362
+ get unassigned() {
363
+ return (!this.ingredientId || this.ingredientId === "0") && (!this.prevIngredientId || this.prevIngredientId === "0");
364
+ }
365
+ get removed() {
366
+ return (!this.ingredientId || this.ingredientId === "0") && this.prevIngredientId !== void 0 && this.prevIngredientId !== "0";
367
+ }
368
+ get maxVolume() {
369
+ return this.slice.maxVolMl ?? 0;
370
+ }
371
+ get remainingVolume() {
372
+ return this.slice.currentVolMl ?? 0;
373
+ }
374
+ get hasMaxVolume() {
375
+ return this.slice.maxVolMl !== void 0;
376
+ }
377
+ get hasRemainingVolume() {
378
+ return this.slice.currentVolMl !== void 0;
379
+ }
380
+ get fillPercent() {
381
+ return this.remainingVolume <= 0 ? 0 : Math.floor((this.remainingVolume || 1) / (this.maxVolume || 1) * 100);
382
+ }
383
+ get hasFuelGuage() {
384
+ return this.hasMaxVolume && this.hasRemainingVolume;
385
+ }
386
+ updateIngredient(e) {
387
+ this.ingredientId !== e && g(() => {
388
+ this.ingredientId = e;
389
+ });
390
+ }
391
+ async resolveIntentVolume(e) {
392
+ const t = this.pumps.data[0];
393
+ return t ? t.resolveIntentVolume(e) : { volume: -1 };
394
+ }
395
+ async overrideRfidCode(e) {
396
+ if (!e)
397
+ throw new Error("Invalid override");
398
+ try {
399
+ const [t, r] = await Kt(this.path, e);
400
+ if (t)
401
+ throw new kt(
402
+ t,
403
+ `Failed to perform rfid override on holder ${this.id}`
404
+ );
405
+ return g(() => {
406
+ this.ingredientId = r == null ? void 0 : r.ingredientId;
407
+ }), r;
408
+ } catch (t) {
409
+ throw De.error(`Failed to perform rfid override on holder ${this.id}`, t), t;
410
+ }
411
+ }
412
+ async assignIngredient(e) {
413
+ try {
414
+ e ? await Ut(this.path, e) : await Gt(this.path), g(() => {
415
+ this.ingredientId = e;
416
+ });
417
+ } catch (t) {
418
+ throw De.error(`Failed to perform assign ingredient to holder ${this.id}`, t), t;
419
+ }
420
+ }
421
+ get shouldDefer() {
422
+ return this.troubles.some((e) => e.shouldDefer);
423
+ }
424
+ async replaceLine() {
425
+ await jt(this.path);
426
+ }
427
+ // -------------------LIFECYCLE----------------------------
428
+ // ----------------------------------
429
+ // UNCOMMENT FOR TESTING FUEL GAUGE
430
+ // ----------------------------------
431
+ // async load() {
432
+ // const random = Math.max(1000, Math.floor(Math.random() * 5000));
433
+ // this.slice.maxVolMl = 1000;
434
+ // setInterval(() => {
435
+ // kosAction(() => {
436
+ // if (this.remainingVolume < -100) {
437
+ // this.slice.maxVolMl = 1000;
438
+ // this.slice.currentVolMl = this.maxVolume;
439
+ // } else {
440
+ // this.slice.currentVolMl = this.remainingVolume - 50;
441
+ // }
442
+ // });
443
+ // }, random);
444
+ // }
445
+ // -------------------ENTITY----------------------------
446
+ };
447
+ ge([
448
+ M
449
+ ], L.prototype, "pumps", 2);
450
+ ge([
451
+ ce({ modelType: Ke.type })
452
+ ], L.prototype, "ingredientContainer", 2);
453
+ ge([
454
+ ce({ modelType: xe.type })
455
+ ], L.prototype, "troubleContainer", 2);
456
+ L = ge([
457
+ I(F)
458
+ ], L);
459
+ const ke = {
460
+ registration: {
461
+ [F]: {
462
+ class: L,
463
+ singleton: !1
464
+ }
465
+ },
466
+ type: F,
467
+ predicate: v(F),
468
+ factory: b.Factory.create(F)
469
+ }, Zt = async (e, t) => {
470
+ var Re;
471
+ const r = h.propertyMapper.executeMapper(
472
+ u.HolderIngredientMapper,
473
+ t
474
+ ), n = h.propertyMapper.executeMapper(
475
+ u.HolderTypeMapper,
476
+ t
477
+ ) || t.ingType, i = await T.executeDataMapperExtension({
478
+ extension: u.HolderMapper,
479
+ data: t,
480
+ contextData: {}
481
+ }), { name: a, path: s, ingredientId: c, ingType: l, ingSource: p, slice: y, ...U } = t, f = { ...U, ...i }, N = y || { pos: 0 }, re = {
482
+ name: a,
483
+ path: s,
484
+ ingredientId: r || c,
485
+ ingredientType: n || l,
486
+ ingredientSource: p,
487
+ enjoyByDate: (Re = t.container) != null && Re.enjoyByDate ? new Date(t.container.enjoyByDate) : void 0,
488
+ slice: N,
489
+ group: e,
490
+ data: f
491
+ };
492
+ return ke.factory(t.path)(re);
493
+ }, { URL: Jt } = C("ASSEMBLY_SERVICE"), { getOne: Xt } = S.build({
494
+ basePath: `${Jt}/api/kos/device/assemblies`
495
+ }), qt = m.createLogger({
496
+ name: "assembly-service",
497
+ group: "Services"
498
+ }), Ze = async () => (qt.debug("sending GET for assembly"), await Xt({}));
499
+ var Wt = Object.defineProperty, Qt = Object.getOwnPropertyDescriptor, ye = (e, t, r, n) => {
500
+ for (var i = n > 1 ? void 0 : n ? Qt(t, r) : t, a = e.length - 1, s; a >= 0; a--)
501
+ (s = e[a]) && (i = (n ? s(t, r, i) : s(i)) || i);
502
+ return n && i && Wt(t, r, i), i;
503
+ };
504
+ const H = "board-container-model", Je = "/kos/hardware/board/linked", Xe = "/kos/hardware/board/unlinked";
505
+ let x = class {
506
+ constructor(e, t, r) {
507
+ o(this, "id");
508
+ o(this, "logger");
509
+ o(this, "models");
510
+ this.id = e, this.logger = r.logger, this.models = new R({
511
+ parentId: e,
512
+ extensionId: u.BoardIndex
513
+ });
514
+ }
515
+ get boardList() {
516
+ return this.models.data;
517
+ }
518
+ updateModel() {
519
+ }
520
+ addModel(e) {
521
+ this.models.addModel(e);
522
+ }
523
+ removeModel(e) {
524
+ this.models.removeModel(e);
525
+ }
526
+ updateBoard(e) {
527
+ const t = e.path, r = this.models.getModel(t);
528
+ if (!r) {
529
+ this.logger.warn(`board ${t} not found`);
530
+ return;
531
+ }
532
+ r.updateModel(e);
533
+ }
534
+ handleBoardLinkEvent(e) {
535
+ this.logger.debug(`handling ${Je} event ${e}`), e ? this.updateBoard(e) : this.logger.debug("- boardLinkEvent is undefined");
536
+ }
537
+ handleBoardUnlinkEvent(e) {
538
+ this.logger.debug(
539
+ `handling ${Xe} event ${e}`
540
+ ), e ? this.updateBoard(e) : this.logger.debug("- boardLinkEvent is undefined");
541
+ }
542
+ };
543
+ ye([
544
+ M
545
+ ], x.prototype, "models", 2);
546
+ ye([
547
+ Q({
548
+ lifecycle: Be.INIT,
549
+ topic: Je,
550
+ websocket: !0
551
+ })
552
+ ], x.prototype, "handleBoardLinkEvent", 1);
553
+ ye([
554
+ Q({
555
+ lifecycle: Be.INIT,
556
+ topic: Xe,
557
+ websocket: !0
558
+ })
559
+ ], x.prototype, "handleBoardUnlinkEvent", 1);
560
+ x = ye([
561
+ I(H)
562
+ ], x);
563
+ const er = async (e) => {
564
+ const t = e.data.boardPath, { model: r } = z(t);
565
+ return {
566
+ boardName: (r == null ? void 0 : r.name) || ""
567
+ };
568
+ };
569
+ var tr = Object.defineProperty, rr = Object.getOwnPropertyDescriptor, qe = (e, t, r, n) => {
570
+ for (var i = n > 1 ? void 0 : n ? rr(t, r) : t, a = e.length - 1, s; a >= 0; a--)
571
+ (s = e[a]) && (i = (n ? s(t, r, i) : s(i)) || i);
572
+ return n && i && tr(t, r, i), i;
573
+ };
574
+ const K = D.PumpContainer;
575
+ var We = /* @__PURE__ */ ((e) => (e.byBoard = "byBoard", e.byType = "byType", e.byNozzle = "byNozzle", e))(We || {});
576
+ let oe = class {
577
+ constructor(e, t) {
578
+ o(this, "id");
579
+ o(this, "pumps");
580
+ this.id = e, this.pumps = new R({
581
+ indexMap: {
582
+ byNozzle: (r) => r.nozzlePaths,
583
+ byBoard: (r) => r.boardPath,
584
+ byType: "type"
585
+ },
586
+ parentId: e,
587
+ extensionId: u.PumpIndex
588
+ });
589
+ }
590
+ /**
591
+ * The collection of pump models.
592
+ */
593
+ get pumpModels() {
594
+ return this.pumps.data;
595
+ }
596
+ /**
597
+ * The collection of pump paths.
598
+ */
599
+ get pumpPaths() {
600
+ return this.pumpModels.map((e) => e.path);
601
+ }
602
+ addModel(e) {
603
+ this.pumps.addModel(e);
604
+ }
605
+ removeModel(e) {
606
+ this.pumps.removeModel(e);
607
+ }
608
+ getModel(e) {
609
+ return this.pumps.getModel(e);
610
+ }
611
+ get models() {
612
+ return this.pumps;
613
+ }
614
+ get data() {
615
+ return this.pumps.data;
616
+ }
617
+ updateModel() {
618
+ }
619
+ // -------------------LIFECYCLE----------------------------
620
+ async load() {
621
+ }
622
+ // -------------------ENTITY----------------------------
623
+ };
624
+ qe([
625
+ M
626
+ ], oe.prototype, "pumps", 2);
627
+ oe = qe([
628
+ I(K)
629
+ ], oe);
630
+ const Oe = {
631
+ registration: {
632
+ [K]: {
633
+ class: oe,
634
+ singleton: !0
635
+ }
636
+ },
637
+ type: K,
638
+ predicate: v(K),
639
+ factory: b.Singleton.create(
640
+ K
641
+ )
642
+ }, Qe = async (e) => {
643
+ const t = [], { model: r } = await Ue(e);
644
+ return r && (t.push(r.boardPath), t.push(r.nozzlePath), t.push(r.holderPath)), t;
645
+ }, ir = async (e) => {
646
+ const t = [], r = e.data.pumpPath;
647
+ t.push(r);
648
+ const n = await Qe(r);
649
+ return [...t, ...n];
650
+ }, nr = async (e) => {
651
+ const t = [], r = e.data.boardPath;
652
+ t.push(e.data.boardPath);
653
+ const n = await Ue(
654
+ Oe.type
655
+ );
656
+ if (n != null && n.model) {
657
+ const a = n.model.models.getIndexByKey(
658
+ We.byBoard,
659
+ r
660
+ ).map(
661
+ (c) => Qe(c.path)
662
+ );
663
+ (await Promise.allSettled(a)).forEach((c) => {
664
+ c.status === "fulfilled" && c.value.forEach((l) => t.push(l));
665
+ });
666
+ }
667
+ return Array.from(new Set(t));
668
+ };
669
+ var ar = Object.defineProperty, sr = Object.getOwnPropertyDescriptor, or = (e, t, r, n) => {
670
+ for (var i = n > 1 ? void 0 : n ? sr(t, r) : t, a = e.length - 1, s; a >= 0; a--)
671
+ (s = e[a]) && (i = (n ? s(t, r, i) : s(i)) || i);
672
+ return n && i && ar(t, r, i), i;
673
+ };
674
+ const V = "board-model", Ne = (e, t) => {
675
+ const { type: r, name: n, path: i, linked: a, instanceId: s, link: c, ...l } = e;
676
+ t.type = r, t.name = n, t.path = i, t.linked = a, t.link = Object.freeze(c), t.instanceId = s, Object.assign(t, l);
677
+ };
678
+ h[Me].register(
679
+ "board",
680
+ nr
681
+ );
682
+ h[W].register(
683
+ "board",
684
+ er
685
+ );
686
+ let ve = class {
687
+ constructor(e, t, r) {
688
+ o(this, "id");
689
+ o(this, "type");
690
+ o(this, "name");
691
+ o(this, "path");
692
+ o(this, "linked");
693
+ o(this, "instanceId");
694
+ o(this, "logger");
695
+ this.id = e, this.logger = r.logger, Ne(t, this);
696
+ }
697
+ updateModel(e) {
698
+ Ne(e, this);
699
+ }
700
+ // -------------------LIFECYCLE----------------------------
701
+ async init() {
702
+ this.logger.debug(`initializing board ${this.id}`);
703
+ }
704
+ async load() {
705
+ this.logger.debug(`loading board ${this.id}`);
706
+ }
707
+ };
708
+ ve = or([
709
+ I(V)
710
+ ], ve);
711
+ const et = {
712
+ registration: {
713
+ [V]: {
714
+ class: ve,
715
+ singleton: !1
716
+ }
717
+ },
718
+ type: V,
719
+ predicate: v(V),
720
+ factory: b.Factory.create(V)
721
+ }, tt = {
722
+ registration: {
723
+ [H]: {
724
+ class: x,
725
+ singleton: !0
726
+ },
727
+ ...et.registration
728
+ },
729
+ type: H,
730
+ predicate: v(H),
731
+ factory: b.Singleton.create(
732
+ H
733
+ )
734
+ };
735
+ var dr = Object.defineProperty, lr = Object.getOwnPropertyDescriptor, Ie = (e, t, r, n) => {
736
+ for (var i = n > 1 ? void 0 : n ? lr(t, r) : t, a = e.length - 1, s; a >= 0; a--)
737
+ (s = e[a]) && (i = (n ? s(t, r, i) : s(i)) || i);
738
+ return n && i && dr(t, r, i), i;
739
+ };
740
+ const Y = D.HolderContainer, cr = "/kos/insertion/insert/start", pr = "/kos/insertion/insert/complete", ur = "/kos/insertion/insert/update", hr = "/kos/insertion/remove", gr = "/kos/pumpEvent/replaceLine", yr = "/kos/handle/*";
741
+ let A = class {
742
+ constructor(e, t, r) {
743
+ o(this, "id");
744
+ o(this, "holders");
745
+ o(this, "logger");
746
+ this.id = e, this.holders = new R({
747
+ indexMap: {
748
+ nozzle: (n) => n.nozzlePaths,
749
+ group: "group"
750
+ },
751
+ parentId: e,
752
+ extensionId: u.HolderIndex
753
+ }), this.logger = r.logger;
754
+ }
755
+ updateModel() {
756
+ }
757
+ handleHolderEvents(e) {
758
+ var r, n, i;
759
+ m.ifDebug(
760
+ () => this.logger.debug("Received holder change event", JSON.stringify(e))
761
+ );
762
+ const t = this.holders.getModel(e.path);
763
+ t && (this.logger.info(
764
+ `Received change event for holder ${t.path}. Updating fuel gauge data.`
765
+ ), t.slice.currentVolMl = (r = e.slice) == null ? void 0 : r.currentVolMl, t.slice.maxVolMl = (n = e.slice) == null ? void 0 : n.maxVolMl, (i = e == null ? void 0 : e.container) != null && i.enjoyByDate ? t.enjoyByDate = new Date(e.container.enjoyByDate) : t.enjoyByDate = void 0);
766
+ }
767
+ handleInsertion(e) {
768
+ m.ifDebug(
769
+ () => this.logger.debug("Received insertion event", JSON.stringify(e))
770
+ ), (Array.isArray(e) ? e : [e]).forEach((r) => {
771
+ g(() => {
772
+ var a, s, c;
773
+ const n = r.ingredientId, i = this.holders.getModel(r.path);
774
+ i && (this.logger.info(
775
+ `Received insertion event for holder ${i.path}`
776
+ ), i.updateIngredient(n), i.slice.currentVolMl = (a = r.slice) == null ? void 0 : a.currentVolMl, i.slice.maxVolMl = (s = r.slice) == null ? void 0 : s.maxVolMl, (c = r == null ? void 0 : r.container) != null && c.enjoyByDate ? i.enjoyByDate = new Date(r.container.enjoyByDate) : i.enjoyByDate = void 0, r.pumps.forEach((l) => {
777
+ g(() => {
778
+ const p = i.pumps.getModel(l.path);
779
+ p && (p.ingredientId = l.ingredientId, p.inserted = l.inserted, p.prevIngredientId = l.prevIngredientId);
780
+ });
781
+ }));
782
+ });
783
+ });
784
+ }
785
+ // -------------------ENTITY----------------------------
786
+ };
787
+ Ie([
788
+ M
789
+ ], A.prototype, "holders", 2);
790
+ Ie([
791
+ Q({
792
+ topic: yr,
793
+ websocket: !0,
794
+ condition: (e, t) => t.holders.getModel(e.path) !== void 0
795
+ })
796
+ ], A.prototype, "handleHolderEvents", 1);
797
+ Ie([
798
+ Q({
799
+ topic: [
800
+ cr,
801
+ pr,
802
+ ur,
803
+ hr,
804
+ gr
805
+ ],
806
+ websocket: !0
807
+ })
808
+ ], A.prototype, "handleInsertion", 1);
809
+ A = Ie([
810
+ I(Y)
811
+ ], A);
812
+ const rt = {
813
+ registration: {
814
+ [Y]: {
815
+ class: A,
816
+ singleton: !0
817
+ }
818
+ },
819
+ type: Y,
820
+ predicate: v(Y),
821
+ factory: b.Singleton.create(
822
+ Y
823
+ )
824
+ }, Ir = m.createLogger({ name: "board-utils" }), fr = async (e) => {
825
+ const t = await T.executeDataMapperExtension({
826
+ extension: u.BoardMapper,
827
+ data: e,
828
+ contextData: {}
829
+ }), { type: r, name: n, path: i, linked: a, instanceId: s, ...c } = e, l = { ...c, ...t }, p = {
830
+ type: r,
831
+ name: n,
832
+ path: i,
833
+ linked: a,
834
+ instanceId: s,
835
+ ...l
836
+ }, y = et.factory(e.path)(p);
837
+ return y.updateModel(p), y;
838
+ }, mr = (e) => async (t) => {
839
+ Ir.debug(`adding board ${t.name}`);
840
+ const r = await fr(t);
841
+ e.addModel(r);
842
+ };
843
+ var d = /* @__PURE__ */ ((e) => (e.IDLE = "IDLE", e.POURING = "POURING", e.POUR_STARTING = "POUR_STARTING", e.POUR_CANCELING = "POUR_CANCELING", e.POUR_CANCELED = "POUR_CANCELED", e.POUR_COMPLETE = "POUR_COMPLETE", e))(d || {});
844
+ const { URL: Ee } = C("PUMP_SERVICE"), { postModel: Pr, getOne: vr } = S.build({
845
+ basePath: `${Ee}/api/kos/holders`
846
+ });
847
+ m.createLogger({
848
+ name: "pump-service",
849
+ group: "Services"
850
+ });
851
+ const br = async ({
852
+ intent: e,
853
+ pumpId: t,
854
+ tracker: r
855
+ }) => {
856
+ const n = `${Ee}/api/ext/dispense/nozzle/nozzle/pipeline/ingredient/pour/${t}/${e}`, i = await Pr({ model: {}, urlOverride: n, tracker: r });
857
+ return i != null && i.data && pe.initiateFuture(i.data), i;
858
+ }, _r = async (e, t) => {
859
+ const r = `${Ee}/api/ext/dispense/nozzle/nozzle/pipeline/ingredient/intent/${e}/${t}/volume`, n = await vr({ urlOverride: r });
860
+ return n != null && n.data ? n.data : { volume: -1 };
861
+ };
862
+ var Mr = Object.defineProperty, Or = Object.getOwnPropertyDescriptor, we = (e, t, r, n) => {
863
+ for (var i = n > 1 ? void 0 : n ? Or(t, r) : t, a = e.length - 1, s; a >= 0; a--)
864
+ (s = e[a]) && (i = (n ? s(t, r, i) : s(i)) || i);
865
+ return n && i && Mr(t, r, i), i;
866
+ };
867
+ const k = D.Pump;
868
+ h[Me].register(
869
+ "pump",
870
+ ir
871
+ );
872
+ let q = class {
873
+ constructor(e, t) {
874
+ o(this, "id");
875
+ o(this, "inserted");
876
+ o(this, "type");
877
+ o(this, "virtual");
878
+ o(this, "ingredientId");
879
+ o(this, "holderPath");
880
+ o(this, "boardPath");
881
+ o(this, "nozzlePath");
882
+ o(this, "childPump");
883
+ o(this, "name");
884
+ o(this, "path");
885
+ o(this, "prevIngredientId");
886
+ o(this, "troubleContainer");
887
+ o(this, "futureHandler");
888
+ o(this, "currentState", d.IDLE);
889
+ this.id = e;
890
+ const {
891
+ inserted: r,
892
+ holderPath: n,
893
+ boardPath: i,
894
+ nozzlePath: a,
895
+ name: s,
896
+ path: c,
897
+ childPump: l,
898
+ virtual: p,
899
+ prevIngredientId: y,
900
+ ...U
901
+ } = t;
902
+ this.inserted = r, this.type = t.type, this.ingredientId = t.ingredientId, this.holderPath = n, this.boardPath = i, this.nozzlePath = a, this.name = s, this.path = c, this.childPump = !!l, this.virtual = !!p, this.prevIngredientId = y, Object.assign(this, U), this.futureHandler = new Ge(this);
903
+ }
904
+ updateModel(e) {
905
+ const {
906
+ inserted: t,
907
+ holderPath: r,
908
+ boardPath: n,
909
+ nozzlePath: i,
910
+ childPump: a,
911
+ name: s,
912
+ path: c,
913
+ ...l
914
+ } = e;
915
+ this.inserted = t, this.type = e.type, this.ingredientId = e.ingredientId, this.holderPath = r, this.boardPath = n, this.nozzlePath = i, this.childPump = this.childPump ? this.childPump : !!a, this.name = s, this.path = c, this.prevIngredientId = e.prevIngredientId, Object.assign(this, l);
916
+ }
917
+ // -------------------LIFECYCLE----------------------------
918
+ get troubles() {
919
+ return this.troubleContainer.troubles.getIndexByKey("byIface", this.path).sort((e, t) => t.rank - e.rank);
920
+ }
921
+ get troubleStatus() {
922
+ return "";
923
+ }
924
+ get troublesByType() {
925
+ return this.troubles.reduce(
926
+ Ae,
927
+ {}
928
+ );
929
+ }
930
+ get pouringState() {
931
+ var e;
932
+ return ((e = this.future) == null ? void 0 : e.endState) || "";
933
+ }
934
+ get isPouring() {
935
+ var e;
936
+ return !!(this.future && !((e = this.future) != null && e.endState)) || this.currentState === d.POUR_STARTING || this.currentState === d.POURING;
937
+ }
938
+ get canPour() {
939
+ return !!this.ingredientId && !this.isPouring;
940
+ }
941
+ onFutureUpdate(e) {
942
+ e.endState && g(() => {
943
+ this.currentState = d.IDLE;
944
+ });
945
+ }
946
+ async cancelPour() {
947
+ var e;
948
+ this.currentState === d.POURING || this.currentState === d.POUR_STARTING ? (this.currentState = d.POUR_CANCELING, await ((e = this.future) == null ? void 0 : e.cancelFuture()), g(() => {
949
+ this.currentState = d.IDLE;
950
+ })) : m.warn(`Cannot cancel pour in state ${this.currentState}`);
951
+ }
952
+ get future() {
953
+ return this.futureHandler.future;
954
+ }
955
+ async resolveIntentVolume(e) {
956
+ return await _r(this.path, e);
957
+ }
958
+ async performIntent(e, t) {
959
+ const r = typeof e == "string" ? e : e.intent;
960
+ if (!r)
961
+ throw new Error("No intent provided");
962
+ try {
963
+ if (this.currentState === d.IDLE) {
964
+ if (this.currentState = d.POUR_STARTING, !t)
965
+ throw new Error("No tracker provided");
966
+ const n = await br({
967
+ tracker: t,
968
+ intent: r,
969
+ pumpId: this.path
970
+ });
971
+ return this.currentState === d.POUR_STARTING && g(() => {
972
+ this.currentState = d.POURING;
973
+ }), n == null ? void 0 : n.data;
974
+ } else
975
+ throw new Error(`Cannot pour in state ${this.currentState}`);
976
+ } catch (n) {
977
+ throw m.error(n), this.currentState = d.IDLE, n;
978
+ }
979
+ }
980
+ // -------------------ENTITY----------------------------
981
+ };
982
+ we([
983
+ ce({ modelType: xe.type })
984
+ ], q.prototype, "troubleContainer", 2);
985
+ we([
986
+ ue()
987
+ ], q.prototype, "performIntent", 1);
988
+ q = we([
989
+ I(k)
990
+ ], q);
991
+ const it = {
992
+ registration: {
993
+ [k]: {
994
+ class: q,
995
+ singleton: !1
996
+ }
997
+ },
998
+ type: k,
999
+ predicate: v(k),
1000
+ factory: b.Factory.create(k)
1001
+ }, Er = m.createLogger({ name: "pump-utils" }), wr = (e, t) => {
1002
+ const r = (t.pumps ?? []).length > 1, n = {
1003
+ boardPath: t.boardPath,
1004
+ holderPath: t.holderPath,
1005
+ ingredientId: t.ingredientId,
1006
+ childPump: !!t.childPump,
1007
+ virtual: r,
1008
+ inserted: t.inserted,
1009
+ name: t.name,
1010
+ path: t.path,
1011
+ type: t.type,
1012
+ nozzlePath: e,
1013
+ prevIngredientId: t.prevIngredientId
1014
+ }, i = it.factory(t.path)(n);
1015
+ return i.updateModel(n), i;
1016
+ }, nt = (e) => (t) => (r) => (n) => {
1017
+ var c;
1018
+ Er.debug(`adding pump ${n.name}`);
1019
+ const i = wr(r.path, n);
1020
+ e.addModel(i);
1021
+ const a = i.holderPath, s = t.holders.getModel(a);
1022
+ s == null || s.pumps.addModel(i), s != null && s.nozzlePaths.includes(r.path) || s == null || s.nozzlePaths.push(r.path), (c = n == null ? void 0 : n.pumps) == null || c.forEach((l) => {
1023
+ const p = i.holderPath, y = {
1024
+ ...l,
1025
+ childPump: !0,
1026
+ holderPath: p,
1027
+ ingredientId: i.ingredientId
1028
+ };
1029
+ nt(e)(t)(r)(y);
1030
+ });
1031
+ };
1032
+ var $r = Object.defineProperty, Cr = Object.getOwnPropertyDescriptor, ee = (e, t, r, n) => {
1033
+ for (var i = n > 1 ? void 0 : n ? Cr(t, r) : t, a = e.length - 1, s; a >= 0; a--)
1034
+ (s = e[a]) && (i = (n ? s(t, r, i) : s(i)) || i);
1035
+ return n && i && $r(t, r, i), i;
1036
+ };
1037
+ const Z = "assembly-model", Sr = "assembly-data";
1038
+ let w = class {
1039
+ constructor(e, t, r) {
1040
+ o(this, "id");
1041
+ o(this, "_nozzlePaths", /* @__PURE__ */ new Set());
1042
+ o(this, "troubleContainer");
1043
+ o(this, "holderContainer");
1044
+ o(this, "boardContainer");
1045
+ o(this, "pumpContainer");
1046
+ o(this, "logger");
1047
+ this.id = e, this.holderContainer = rt.factory({}), this.boardContainer = tt.factory({}), this.pumpContainer = Oe.factory({}), this.logger = r.logger;
1048
+ }
1049
+ updateModel(e) {
1050
+ }
1051
+ get allHolders() {
1052
+ return this.holderContainer.holders.data;
1053
+ }
1054
+ get holderGroups() {
1055
+ return this.holderContainer.holders.getIndexKeys("group");
1056
+ }
1057
+ get nozzlePaths() {
1058
+ return Array.from(this._nozzlePaths);
1059
+ }
1060
+ getHoldersByGroup(e) {
1061
+ return this.holderContainer.holders.getIndexByKey("group", e);
1062
+ }
1063
+ getHoldersByNozzle(e) {
1064
+ return this.holderContainer.holders.getIndexByKey("nozzle", e);
1065
+ }
1066
+ /**
1067
+ * Returns a map of the pumps associated with each nozzle
1068
+ *
1069
+ * Can be used in conjunction with the nozzlePaths to get the pumps associated with each nozzle
1070
+ * @returns Record<string, PumpModel[]>
1071
+ */
1072
+ get pumpsByNozzle() {
1073
+ return this.pumpContainer.models.idx.byNozzle;
1074
+ }
1075
+ /**
1076
+ * Returns a list of all fo the pumps paths across the entire assembly.
1077
+ */
1078
+ get pumpPaths() {
1079
+ return this.pumpContainer.models.data.map((e) => e.path);
1080
+ }
1081
+ get boards() {
1082
+ return this.boardContainer.boardList;
1083
+ }
1084
+ // -------------------LIFECYCLE----------------------------
1085
+ async init() {
1086
+ this.logger.debug(`initializing assembly ${this.id}`);
1087
+ }
1088
+ async ready() {
1089
+ var e;
1090
+ (e = this.troubleContainer) == null || e.troubles.increment();
1091
+ }
1092
+ async load(e) {
1093
+ this.logger.debug(`loading assembly ${this.id}`);
1094
+ const t = await Ze();
1095
+ if ((t == null ? void 0 : t.status) === 200) {
1096
+ const r = await T.executeDataMapperExtension({
1097
+ extension: u.AssemblyMapper,
1098
+ data: t.data,
1099
+ contextData: {}
1100
+ });
1101
+ e.set(Sr, r), Object.assign(this, r), Object.entries(r).forEach(([n, i]) => {
1102
+ gt(i) && (this.logger.debug(`adding child model ${n} from extension data`), this[yt][n] = !0);
1103
+ });
1104
+ for await (const n of t.data.assemblies) {
1105
+ const {
1106
+ boards: i,
1107
+ holders: a,
1108
+ nozzles: s,
1109
+ core: c,
1110
+ name: l,
1111
+ path: p,
1112
+ ...y
1113
+ } = n;
1114
+ this.logger.debug(`adding assembly ${l}`), Object.keys(y).forEach((f) => {
1115
+ It.enableFeature(f);
1116
+ });
1117
+ for await (const f of i)
1118
+ this.logger.debug(`adding board ${f.name}`), await mr(this.boardContainer)(f);
1119
+ for await (const [f, N] of Object.entries(a))
1120
+ for await (const re of N) {
1121
+ this.logger.debug(`adding holder ${re.name}`);
1122
+ const Se = await Zt(f, re);
1123
+ this.holderContainer.holders.addModel(Se);
1124
+ }
1125
+ const U = nt(this.pumpContainer)(
1126
+ this.holderContainer
1127
+ );
1128
+ s.forEach((f) => {
1129
+ this._nozzlePaths.add(f.path);
1130
+ const N = U(f);
1131
+ f.pumps.forEach(N);
1132
+ });
1133
+ }
1134
+ }
1135
+ }
1136
+ };
1137
+ ee([
1138
+ ce({
1139
+ modelType: "trouble-container-model"
1140
+ })
1141
+ ], w.prototype, "troubleContainer", 2);
1142
+ ee([
1143
+ M
1144
+ ], w.prototype, "holderContainer", 2);
1145
+ ee([
1146
+ M
1147
+ ], w.prototype, "boardContainer", 2);
1148
+ ee([
1149
+ M
1150
+ ], w.prototype, "pumpContainer", 2);
1151
+ w = ee([
1152
+ I(Z)
1153
+ ], w);
1154
+ const at = {
1155
+ registration: {
1156
+ [Z]: {
1157
+ class: w,
1158
+ singleton: !0
1159
+ }
1160
+ },
1161
+ type: Z,
1162
+ predicate: v(Z),
1163
+ factory: b.Singleton.create(Z)
1164
+ };
1165
+ var Rr = Object.defineProperty, Dr = Object.getOwnPropertyDescriptor, Nr = (e, t, r, n) => {
1166
+ for (var i = n > 1 ? void 0 : n ? Dr(t, r) : t, a = e.length - 1, s; a >= 0; a--)
1167
+ (s = e[a]) && (i = (n ? s(t, r, i) : s(i)) || i);
1168
+ return n && i && Rr(t, r, i), i;
1169
+ };
1170
+ const J = D.Availability;
1171
+ let be = class {
1172
+ constructor(e, t, r) {
1173
+ o(this, "id");
1174
+ o(this, "data");
1175
+ o(this, "available");
1176
+ o(this, "visible");
1177
+ o(this, "groupId");
1178
+ o(this, "rawId");
1179
+ o(this, "altId");
1180
+ o(this, "type");
1181
+ o(this, "note");
1182
+ o(this, "taggedIds");
1183
+ o(this, "parentId");
1184
+ o(this, "logger");
1185
+ this.id = e, this.taggedIds = t.taggedIds || [], this.logger = r.logger, this.available = t.available, this.visible = t.visible, this.groupId = t.groupId, this.rawId = t.rawId, this.altId = t.altId, this.type = t.type, this.parentId = t.kosParentId, this.data = t.data, this.note = t.note;
1186
+ }
1187
+ updateModel(e) {
1188
+ this.taggedIds = e.taggedIds || [], this.available = e.available, this.visible = e.visible, this.groupId = e.groupId, this.rawId = e.rawId, this.altId = e.altId, this.type = e.type, this.data = e.data;
1189
+ }
1190
+ updateAvailability(e) {
1191
+ this.available = e;
1192
+ }
1193
+ // -------------------LIFECYCLE----------------------------
1194
+ // -------------------ENTITY----------------------------
1195
+ };
1196
+ be = Nr([
1197
+ ft(),
1198
+ I(J)
1199
+ ], be);
1200
+ const _e = {
1201
+ registration: {
1202
+ [J]: {
1203
+ class: be,
1204
+ singleton: !1
1205
+ }
1206
+ },
1207
+ type: J,
1208
+ predicate: v(J),
1209
+ factory: b.Factory.create(
1210
+ J
1211
+ )
1212
+ }, { URL: B } = C("NOZZLE_SERVICE"), { postModel: $e, deleteModel: Tr, getOne: zr } = S.build({
1213
+ basePath: `${B}/api/nozzle`
1214
+ }), Lr = async (e, t) => {
1215
+ const r = await $e({
1216
+ model: {},
1217
+ urlOverride: `${B}/api/ext/dispense/nozzle/${e}/pipeline/beverage/pour`,
1218
+ ordered: !0,
1219
+ tracker: t
1220
+ });
1221
+ return r != null && r.data && pe.initiateFuture(r.data), r;
1222
+ }, xr = async (e, t, r) => {
1223
+ const n = await $e({
1224
+ model: {},
1225
+ urlOverride: `${B}/api/ext/dispense/nozzle/${t}/pipeline/beverage/fixed/${e}`,
1226
+ ordered: !0,
1227
+ tracker: r
1228
+ });
1229
+ return n != null && n.data && pe.initiateFuture(n.data), n;
1230
+ }, Ar = async (e) => await zr({
1231
+ urlOverride: `${B}${e}/pipeline/beverage/availability`
1232
+ }), Br = async (e, t) => await $e({
1233
+ model: t,
1234
+ urlOverride: `${B}/api/ext/dispense/nozzle/${e}/pipeline/beverage/select`
1235
+ }), Ur = async (e) => await Tr({
1236
+ id: e,
1237
+ urlOverride: `${B}/api/ext/dispense/nozzle/${e}/pipeline/beverage/select`
1238
+ });
1239
+ var Gr = Object.defineProperty, jr = Object.getOwnPropertyDescriptor, te = (e, t, r, n) => {
1240
+ for (var i = n > 1 ? void 0 : n ? jr(t, r) : t, a = e.length - 1, s; a >= 0; a--)
1241
+ (s = e[a]) && (i = (n ? s(t, r, i) : s(i)) || i);
1242
+ return n && i && Gr(t, r, i), i;
1243
+ };
1244
+ const X = D.Nozzle, Fr = mt(
1245
+ "beverageTopicPrefix"
1246
+ ), ie = (e) => e.onPourStart !== void 0 && e.onPourCancel !== void 0 && e.onPourProgress !== void 0, Te = "/kos/nozzle/pour/started", Hr = "/kos/nozzle/pour/progress", fe = "/kos/nozzle/pour/cancel";
1247
+ let $ = class {
1248
+ constructor(e, t, r) {
1249
+ /** the unique identifier for this nozzle.*/
1250
+ o(this, "id");
1251
+ o(this, "path");
1252
+ o(this, "logger");
1253
+ o(this, "name");
1254
+ o(this, "_selectedBeverage");
1255
+ o(this, "_selectedBrand");
1256
+ o(this, "_additionalItems");
1257
+ o(this, "_availabilityItems");
1258
+ o(this, "futureHandler");
1259
+ o(this, "currentState", d.IDLE);
1260
+ o(this, "beverageTopicPrefix");
1261
+ o(this, "topicPrefix");
1262
+ o(this, "urlPrefix");
1263
+ this.id = e, this.path = t.path, this.name = t.name, this.beverageTopicPrefix = t.beverageTopicPrefix, this.topicPrefix = t.topicPrefix, this.urlPrefix = t.urlPrefix, this._selectedBeverage = void 0, this._selectedBrand = void 0, this._additionalItems = [], this.futureHandler = new Pt(this), this._availabilityItems = new R({
1264
+ indexMap: {
1265
+ byGroup: "groupId",
1266
+ byParent: "parentId"
1267
+ },
1268
+ parentId: e
1269
+ }), this.logger = r.logger;
1270
+ }
1271
+ /**
1272
+ * The availability nodes that can be dispensed from this nozzle.
1273
+ * This is a subset of the availability for the entire dispenser
1274
+ * and is determined by the nodes associated with a nozzle.
1275
+ */
1276
+ get beverages() {
1277
+ return this._availabilityItems.getIndexByKey("byGroup", "beverages");
1278
+ }
1279
+ /**
1280
+ * The availability nodes that have been grouped into the "brands" group.
1281
+ *
1282
+ */
1283
+ get brands() {
1284
+ return this._availabilityItems.getIndexByKey("byGroup", "brands");
1285
+ }
1286
+ get visibleBrands() {
1287
+ return this.brands.filter((e) => e.visible);
1288
+ }
1289
+ get visibleBeverages() {
1290
+ return this.beverages.filter((e) => e.visible);
1291
+ }
1292
+ /**
1293
+ * A derived value that indicates if the nozzle is currently pouring a beverage.
1294
+ * @readonly
1295
+ */
1296
+ get isPouring() {
1297
+ var e;
1298
+ return !!(this.futureHandler.getFuture() && !((e = this.futureHandler.getFuture()) != null && e.endState)) || this.currentState === d.POUR_STARTING || this.currentState === d.POURING || this.currentState === d.POUR_CANCELING;
1299
+ }
1300
+ /**
1301
+ * A derived value that indicates if the nozzle is currently available to pour a beverage.
1302
+ *
1303
+ * This will generally be determined by whether there is a currently selected pourable AND
1304
+ * the nozzle is not currently pouring.
1305
+ *
1306
+ * The value is observable and will change when the selected pourable changes or the nozzle
1307
+ * starts or stops pouring.
1308
+ * @readonly
1309
+ * */
1310
+ get canPour() {
1311
+ return !!this._selectedBeverage && this._selectedBeverage.available && this.currentState === d.IDLE;
1312
+ }
1313
+ /**
1314
+ * The selected pourable for this nozzle. Its shape is determined by the results of the
1315
+ * {@link ExtensionType.SelectedPourableMapper} extension.
1316
+ * @readonly
1317
+ *
1318
+ * */
1319
+ get selectedPourable() {
1320
+ return {
1321
+ beverage: this._selectedBeverage,
1322
+ additional: this._additionalItems
1323
+ };
1324
+ }
1325
+ get future() {
1326
+ return this.futureHandler.getFuture();
1327
+ }
1328
+ get pourProgress() {
1329
+ var e;
1330
+ return ((e = this.future) == null ? void 0 : e.progress) ?? 0;
1331
+ }
1332
+ updateModel() {
1333
+ }
1334
+ // -------------------LIFECYCLE----------------------------
1335
+ setSelectedBrand(e) {
1336
+ this._selectedBrand = e, this._selectedBeverage = void 0;
1337
+ }
1338
+ get selectedBrand() {
1339
+ return this._selectedBrand;
1340
+ }
1341
+ /**
1342
+ * Set the values used to determine the selected pourable for this nozzle.
1343
+ *
1344
+ * @param pourable The pourable to set.
1345
+ * @param pourable.beverage The beverage selected.
1346
+ * @param pourable.additional The additional items such as flavors or other items that could be incorporated
1347
+ * into the pourable.
1348
+ * */
1349
+ async setSelectedPourable({
1350
+ beverage: e,
1351
+ additional: t,
1352
+ context: r
1353
+ }) {
1354
+ if (!e) {
1355
+ const c = await Ur(this.name);
1356
+ if ((c == null ? void 0 : c.status) !== 200)
1357
+ throw new Error("Failed to clear pourable");
1358
+ this._selectedBeverage = void 0;
1359
+ return;
1360
+ }
1361
+ if (e === this._selectedBeverage && vt(this._additionalItems, t)) {
1362
+ this.logger.info("No change in selected pourable");
1363
+ return;
1364
+ }
1365
+ this._selectedBeverage = e, this._additionalItems = t;
1366
+ let n = await h.dataMapper.executeMapper(
1367
+ u.SelectedPourableMapper,
1368
+ {
1369
+ beverage: e,
1370
+ additional: t,
1371
+ context: r
1372
+ }
1373
+ );
1374
+ const i = {
1375
+ bevId: e.rawId
1376
+ };
1377
+ (!n || Object.keys(n).length === 0) && (this.logger.info(
1378
+ `No selected pourable mapper defined, using the default payload ${i}`
1379
+ ), n = i);
1380
+ const a = n ?? i, s = await Br(this.name, a);
1381
+ if ((s == null ? void 0 : s.status) !== 200)
1382
+ throw new Error("Failed to select pourable");
1383
+ }
1384
+ /**
1385
+ * Utility method that will return the availability nodes that belong to the specified
1386
+ * group as defined in the dispenser beverage graph. For example, a dispenser
1387
+ * implementation may group availability nodes by Brand, Beverage, or Flavors
1388
+ *
1389
+ * @param groupId The group to filter by.
1390
+ * @returns The availability nodes that are available to be dispensed from this nozzle
1391
+ * and are in the specified group.
1392
+ * */
1393
+ getGroupAvailabilityItems(e) {
1394
+ return this._availabilityItems.getIndexByKey(
1395
+ "byGroup",
1396
+ e
1397
+ );
1398
+ }
1399
+ /**
1400
+ * Utility method that will return the availability nodes that are tagged with the specified parent id.
1401
+ *
1402
+ * This is useful when brandsets use the taggedIds property to associate nodes with a parent node. For example,
1403
+ * when organizing a brandset into brands and beverages, the brand nodes will be tagged with the beverage nodes.
1404
+ *
1405
+ * @param parentId - The parent id to filter by.
1406
+ * @returns the availability nodes that are tagged with the specified parent id.
1407
+ */
1408
+ getAvailabilityByParent(e) {
1409
+ return this._availabilityItems.getIndexByKey(
1410
+ "byParent",
1411
+ e
1412
+ );
1413
+ }
1414
+ updateIfCurrent(e, t) {
1415
+ this.currentState === e && g(() => {
1416
+ this.currentState = t;
1417
+ });
1418
+ }
1419
+ onFutureUpdate(e) {
1420
+ E(this).forEach((n) => {
1421
+ ie(n) && n.onPourProgress(e);
1422
+ });
1423
+ const r = {
1424
+ nozzleId: this.id,
1425
+ progress: e.progress,
1426
+ status: e.status,
1427
+ clientData: e.clientData,
1428
+ futureId: e.futureId,
1429
+ remainingTimeMs: e.remainingTimeMs,
1430
+ endState: e.endState,
1431
+ reason: e.reason,
1432
+ timeRemaining: e.timeRemaining
1433
+ };
1434
+ _.publish(Hr, r), e.endState && g(() => {
1435
+ this.currentState = d.IDLE;
1436
+ });
1437
+ }
1438
+ async pour(e) {
1439
+ var t;
1440
+ try {
1441
+ if (this.currentState === d.IDLE) {
1442
+ if (this.updateIfCurrent(d.IDLE, d.POUR_STARTING), !e)
1443
+ throw new Error("No tracker provided");
1444
+ const r = await Lr(this.name, e);
1445
+ this.updateIfCurrent(d.POUR_STARTING, d.POURING), E(this).forEach((i) => {
1446
+ var a;
1447
+ ie(i) && ((a = i.onPourStart) == null || a.call(i));
1448
+ });
1449
+ const n = {
1450
+ nozzleId: this.id,
1451
+ type: "free"
1452
+ };
1453
+ if (_.publish(Te, n), (t = r == null ? void 0 : r.data) != null && t.endState) {
1454
+ this.updateIfCurrent(d.POURING, d.IDLE);
1455
+ const i = {
1456
+ nozzleId: this.id
1457
+ };
1458
+ _.publish(fe, i);
1459
+ }
1460
+ return r;
1461
+ } else
1462
+ throw new Error(`Cannot pour in state ${this.currentState}`);
1463
+ } catch (r) {
1464
+ throw this.logger.error(r), this.currentState = d.IDLE, r;
1465
+ }
1466
+ }
1467
+ async fixedPour(e, t) {
1468
+ var r;
1469
+ try {
1470
+ if (this.currentState === d.IDLE) {
1471
+ if (this.currentState = d.POUR_STARTING, !t)
1472
+ throw new Error("No tracker provided");
1473
+ const n = await xr(e, this.name, t);
1474
+ this.currentState === d.POUR_STARTING && g(() => {
1475
+ this.currentState = d.POURING;
1476
+ }), E(this).forEach((a) => {
1477
+ var s;
1478
+ ie(a) && ((s = a.onPourStart) == null || s.call(a));
1479
+ });
1480
+ const i = {
1481
+ nozzleId: this.id,
1482
+ type: "fixed"
1483
+ };
1484
+ if (_.publish(Te, i), (r = n == null ? void 0 : n.data) != null && r.endState) {
1485
+ this.updateIfCurrent(d.POURING, d.IDLE);
1486
+ const a = {
1487
+ nozzleId: this.id
1488
+ };
1489
+ _.publish(fe, a);
1490
+ }
1491
+ return n;
1492
+ } else
1493
+ throw new Error(`Cannot pour in state ${this.currentState}`);
1494
+ } catch (n) {
1495
+ throw this.logger.error(n), this.currentState = d.IDLE, n;
1496
+ }
1497
+ }
1498
+ /**
1499
+ * An action that will cancel a pour for this nozzle.
1500
+ * */
1501
+ async cancelPour() {
1502
+ var e;
1503
+ if (this.currentState === d.POURING || this.currentState === d.POUR_STARTING) {
1504
+ this.currentState = d.POUR_CANCELING, await ((e = this.futureHandler.getFuture()) == null ? void 0 : e.cancelFuture()), g(() => {
1505
+ this.currentState = d.IDLE;
1506
+ }), E(this).forEach((r) => {
1507
+ var n;
1508
+ ie(r) && ((n = r.onPourCancel) == null || n.call(r));
1509
+ });
1510
+ const t = {
1511
+ nozzleId: this.id
1512
+ };
1513
+ _.publish(fe, t);
1514
+ } else
1515
+ this.logger.warn(`Cannot cancel pour in state ${this.currentState}`);
1516
+ }
1517
+ updateGroupMembers() {
1518
+ this._availabilityItems.data.forEach((e) => {
1519
+ (e.taggedIds || []).forEach((r) => {
1520
+ const n = this._availabilityItems.data.find(
1521
+ (i) => i.rawId === r
1522
+ );
1523
+ n && n.parentId !== e.id && (n.parentId = e.id, this._availabilityItems.updateModel(n));
1524
+ });
1525
+ });
1526
+ }
1527
+ /** @internal */
1528
+ async load(e) {
1529
+ var n, i;
1530
+ this.logger.debug(`loading nozzle ${this.id}`);
1531
+ const t = await Ar(this.urlPrefix);
1532
+ if ((t == null ? void 0 : t.status) !== 200)
1533
+ throw new Error("Failed to load nozzle availability");
1534
+ const r = await h.loader.executeLoader(
1535
+ u.AvailabilityLoader,
1536
+ {}
1537
+ );
1538
+ e == null || e.set(u.AvailabilityLoader, r), e == null || e.set(Ce.type, this);
1539
+ for (const a of Object.keys((n = t.data) == null ? void 0 : n.groups) || [])
1540
+ for (const s of ((i = t.data) == null ? void 0 : i.groups[a]) || []) {
1541
+ const c = await h.dataMapper.executeMapper(
1542
+ u.AvailabilityMapper,
1543
+ { ...s, groupId: a },
1544
+ r
1545
+ ), l = {
1546
+ ...s,
1547
+ note: s.note ?? void 0,
1548
+ kosParentId: this.id,
1549
+ rawId: s.id,
1550
+ groupId: a,
1551
+ data: c
1552
+ }, p = _e.factory(
1553
+ `${this.id}-${a}-${s.id}`
1554
+ )(l);
1555
+ this._availabilityItems.addModel(p);
1556
+ }
1557
+ this.updateGroupMembers();
1558
+ }
1559
+ async updateAvailability(e) {
1560
+ const t = bt.getContext(this.id), r = (t == null ? void 0 : t.get(u.AvailabilityLoader)) || {};
1561
+ if (e.rebuild)
1562
+ for (const n of Object.keys(e == null ? void 0 : e.groups) || []) {
1563
+ this._availabilityItems.getIndexByKey("group", n).filter(
1564
+ (a) => !e.groups[n].find(
1565
+ (s) => `${this.id}-${n}-${s.id}` === a.id
1566
+ )
1567
+ ).forEach((a) => {
1568
+ this._availabilityItems.removeModel(a.id), _t(a);
1569
+ });
1570
+ for (const a of (e == null ? void 0 : e.groups[n]) || []) {
1571
+ const s = await h.dataMapper.executeMapper(
1572
+ u.AvailabilityMapper,
1573
+ { ...a, groupId: n },
1574
+ r
1575
+ ), c = {
1576
+ ...a,
1577
+ note: a.note ?? void 0,
1578
+ kosParentId: this.id,
1579
+ groupId: n,
1580
+ rawId: a.id,
1581
+ data: s,
1582
+ taggedIds: a.taggedIds
1583
+ }, l = this._availabilityItems.getModel(
1584
+ `${this.id}-${n}-${a.id}`
1585
+ );
1586
+ if (l)
1587
+ l.updateModel(c);
1588
+ else {
1589
+ const p = _e.factory(
1590
+ `${this.id}-${n}-${a.id}`
1591
+ )(c);
1592
+ this._availabilityItems.addModel(p);
1593
+ }
1594
+ }
1595
+ }
1596
+ else
1597
+ for (const n of Object.keys(e == null ? void 0 : e.groups) || [])
1598
+ for (const i of (e == null ? void 0 : e.groups[n]) || []) {
1599
+ const a = await h.dataMapper.executeMapper(
1600
+ u.AvailabilityMapper,
1601
+ { ...i, groupId: n },
1602
+ r
1603
+ ), s = {
1604
+ ...i,
1605
+ note: i.note ?? void 0,
1606
+ kosParentId: this.id,
1607
+ groupId: n,
1608
+ rawId: i.id,
1609
+ data: a,
1610
+ type: i.type,
1611
+ taggedIds: i.taggedIds
1612
+ }, c = this._availabilityItems.getModel(
1613
+ `${this.id}-${n}-${i.id}`
1614
+ );
1615
+ c && c.updateModel(s);
1616
+ }
1617
+ this.updateGroupMembers();
1618
+ }
1619
+ // -------------------ENTITY----------------------------
1620
+ };
1621
+ te([
1622
+ M
1623
+ ], $.prototype, "_availabilityItems", 2);
1624
+ te([
1625
+ ue()
1626
+ ], $.prototype, "pour", 1);
1627
+ te([
1628
+ ue()
1629
+ ], $.prototype, "fixedPour", 1);
1630
+ te([
1631
+ Q({
1632
+ topic: `${Fr}/availability`,
1633
+ websocket: !0
1634
+ })
1635
+ ], $.prototype, "updateAvailability", 1);
1636
+ $ = te([
1637
+ I(X)
1638
+ ], $);
1639
+ const Ce = {
1640
+ registration: {
1641
+ [X]: {
1642
+ class: $,
1643
+ singleton: !1
1644
+ }
1645
+ },
1646
+ type: X,
1647
+ predicate: v(X),
1648
+ factory: b.Factory.create(X)
1649
+ };
1650
+ var Kr = Object.defineProperty, Vr = Object.getOwnPropertyDescriptor, st = (e, t, r, n) => {
1651
+ for (var i = n > 1 ? void 0 : n ? Vr(t, r) : t, a = e.length - 1, s; a >= 0; a--)
1652
+ (s = e[a]) && (i = (n ? s(t, r, i) : s(i)) || i);
1653
+ return n && i && Kr(t, r, i), i;
1654
+ };
1655
+ const ot = "device-assembly-model";
1656
+ let de = class {
1657
+ constructor(e, t, r) {
1658
+ o(this, "id");
1659
+ o(this, "deviceNozzles");
1660
+ o(this, "logger");
1661
+ this.id = e, this.logger = r.logger, this.deviceNozzles = new R();
1662
+ }
1663
+ // -------------------LIFECYCLE----------------------------
1664
+ async init() {
1665
+ this.logger.debug(`initializing device-assembly ${this.id}`);
1666
+ }
1667
+ getNozzle(e) {
1668
+ return this.deviceNozzles.getModel(e);
1669
+ }
1670
+ get nozzlePaths() {
1671
+ return this.deviceNozzles.data.map((e) => e.path);
1672
+ }
1673
+ async load() {
1674
+ this.logger.debug(`loading device-assembly ${this.id}`);
1675
+ const e = await Ze();
1676
+ (e == null ? void 0 : e.status) === 200 && e.data.assemblies.map((r) => r.nozzles).flat().forEach((r) => {
1677
+ var s;
1678
+ const n = r.path, i = ((s = r.pipelines.find((c) => c.name === "beverage")) == null ? void 0 : s.topicPrefix) || "", a = Ce.factory(n)({
1679
+ path: r.path,
1680
+ name: r.name,
1681
+ urlPrefix: r.urlPrefix,
1682
+ topicPrefix: r.topicPrefix,
1683
+ beverageTopicPrefix: i
1684
+ });
1685
+ this.deviceNozzles.addModel(a);
1686
+ });
1687
+ }
1688
+ };
1689
+ st([
1690
+ M
1691
+ ], de.prototype, "deviceNozzles", 2);
1692
+ de = st([
1693
+ I(ot)
1694
+ ], de);
1695
+ const Yr = new Mt({
1696
+ class: de,
1697
+ type: ot
1698
+ }), { URL: dt } = C("GENERIC_POUR_SERVICE"), { postModel: kr } = S.build({
1699
+ basePath: `${dt}/api/nozzle`
1700
+ }), Zr = async (e, t) => {
1701
+ const r = await kr({
1702
+ model: {},
1703
+ urlOverride: `${dt}${e}`,
1704
+ ordered: !0,
1705
+ tracker: t
1706
+ });
1707
+ return r != null && r.data && pe.initiateFuture(r.data), r;
1708
+ };
1709
+ var Jr = Object.defineProperty, Xr = Object.getOwnPropertyDescriptor, lt = (e, t, r, n) => {
1710
+ for (var i = n > 1 ? void 0 : n ? Xr(t, r) : t, a = e.length - 1, s; a >= 0; a--)
1711
+ (s = e[a]) && (i = (n ? s(t, r, i) : s(i)) || i);
1712
+ return n && i && Jr(t, r, i), i;
1713
+ };
1714
+ const ct = "generic-pour-model", qr = "/kos/generic/pour/started", Wr = "/kos/generic/pour/progress", ze = "/kos/generic/pour/cancel", me = (e) => e.onPourStart !== void 0 && e.onPourCancel !== void 0 && e.onPourProgress !== void 0;
1715
+ let le = class {
1716
+ constructor(e, t, r) {
1717
+ o(this, "id");
1718
+ o(this, "currentState", d.IDLE);
1719
+ o(this, "servicePathFactory");
1720
+ o(this, "pourType");
1721
+ o(this, "logger");
1722
+ o(this, "futureHandler");
1723
+ o(this, "selectedId");
1724
+ this.id = e, this.logger = r.logger, this.futureHandler = new Ge(this), this.servicePathFactory = t.servicePathFactory, this.pourType = t.pourType || "free", this.selectedId = t.selectedId;
1725
+ }
1726
+ get servicePath() {
1727
+ return this.selectedId ? this.servicePathFactory(this.selectedId) : "";
1728
+ }
1729
+ async pour(e) {
1730
+ var t;
1731
+ try {
1732
+ if (this.currentState === d.IDLE) {
1733
+ if (this.updateIfCurrent(d.IDLE, d.POUR_STARTING), !e)
1734
+ throw new Error("No tracker provided");
1735
+ const r = await Zr(this.servicePath, e);
1736
+ this.updateIfCurrent(d.POUR_STARTING, d.POURING), E(this).forEach((i) => {
1737
+ var a;
1738
+ me(i) && ((a = i.onPourStart) == null || a.call(i));
1739
+ });
1740
+ const n = {
1741
+ pourTarget: this.id,
1742
+ type: this.pourType
1743
+ };
1744
+ if (_.publish(qr, n), (t = r == null ? void 0 : r.data) != null && t.endState) {
1745
+ this.updateIfCurrent(d.POURING, d.IDLE);
1746
+ const i = {
1747
+ pourTarget: this.id
1748
+ };
1749
+ _.publish(ze, i);
1750
+ }
1751
+ return r;
1752
+ } else
1753
+ throw new Error(`Cannot pour in state ${this.currentState}`);
1754
+ } catch (r) {
1755
+ throw this.logger.error(r), this.currentState = d.IDLE, r;
1756
+ }
1757
+ }
1758
+ async cancelPour() {
1759
+ var e;
1760
+ if (this.currentState === d.POURING || this.currentState === d.POUR_STARTING) {
1761
+ this.currentState = d.POUR_CANCELING, await ((e = this.futureHandler.getFuture()) == null ? void 0 : e.cancelFuture()), g(() => {
1762
+ this.currentState = d.IDLE;
1763
+ }), E(this).forEach((r) => {
1764
+ var n;
1765
+ me(r) && ((n = r.onPourCancel) == null || n.call(r));
1766
+ });
1767
+ const t = {
1768
+ pourTarget: this.id
1769
+ };
1770
+ _.publish(ze, t);
1771
+ }
1772
+ this.currentState === d.IDLE ? this.logger.info("Pour already idle, nothing to cancel.") : this.logger.warn(`Cannot cancel pour in state ${this.currentState}`);
1773
+ }
1774
+ updateIfCurrent(e, t) {
1775
+ this.currentState === e && g(() => {
1776
+ this.currentState = t;
1777
+ });
1778
+ }
1779
+ /**
1780
+ * A derived value that indicates if the nozzle is currently pouring a beverage.
1781
+ * @readonly
1782
+ */
1783
+ get isPouring() {
1784
+ var e;
1785
+ return !!(this.futureHandler.getFuture() && !((e = this.futureHandler.getFuture()) != null && e.endState)) || this.currentState === d.POUR_STARTING || this.currentState === d.POURING || this.currentState === d.POUR_CANCELING;
1786
+ }
1787
+ /**
1788
+ * A derived value that indicates if the pour target is currently available to pour a beverage.
1789
+ *
1790
+ * Generally this means that the pour target is currently idle and not in the process of pouring, initiating a pour, or canceling a pour.
1791
+ * The value is observable and will change when the selected pourable changes or the pour target
1792
+ * starts or stops pouring.
1793
+ * @readonly
1794
+ * */
1795
+ get canPour() {
1796
+ return this.currentState === d.IDLE;
1797
+ }
1798
+ get future() {
1799
+ return this.futureHandler.getFuture();
1800
+ }
1801
+ get pourProgress() {
1802
+ var e;
1803
+ return ((e = this.future) == null ? void 0 : e.progress) ?? 0;
1804
+ }
1805
+ onFutureUpdate(e) {
1806
+ E(this).forEach((r) => {
1807
+ me(r) && r.onPourProgress(e);
1808
+ });
1809
+ const t = {
1810
+ pourTarget: this.id,
1811
+ progress: e.progress,
1812
+ status: e.status,
1813
+ clientData: e.clientData,
1814
+ futureId: e.futureId,
1815
+ remainingTimeMs: e.remainingTimeMs,
1816
+ endState: e.endState,
1817
+ reason: e.reason,
1818
+ timeRemaining: e.timeRemaining
1819
+ };
1820
+ _.publish(Wr, t), e.endState && g(() => {
1821
+ this.currentState = d.IDLE;
1822
+ });
1823
+ }
1824
+ // -------------------LIFECYCLE----------------------------
1825
+ async init() {
1826
+ this.logger.debug(`initializing generic-pour ${this.id}`);
1827
+ }
1828
+ async load() {
1829
+ this.logger.debug(`loading generic-pour ${this.id}`);
1830
+ }
1831
+ };
1832
+ lt([
1833
+ ue()
1834
+ ], le.prototype, "pour", 1);
1835
+ le = lt([
1836
+ I(ct)
1837
+ ], le);
1838
+ const oi = new Ot({
1839
+ class: le,
1840
+ type: ct
1841
+ }), Le = {
1842
+ ...Ke.registration,
1843
+ ...je.registration,
1844
+ ...rt.registration,
1845
+ ...ke.registration,
1846
+ ...Ce.registration,
1847
+ ...it.registration,
1848
+ ...Oe.registration,
1849
+ ..._e.registration,
1850
+ ...at.registration,
1851
+ ...tt.registration
1852
+ }, Qr = (e) => () => (wt(e)(), Yr.register(), Object.keys(Le).forEach((t) => {
1853
+ const r = Le[t];
1854
+ $t(e)(t, r);
1855
+ }), h[W].register(
1856
+ "FirmwareUpdateInProgressTrouble",
1857
+ async (t) => {
1858
+ var r;
1859
+ if ((r = t.data) != null && r.deviceId) {
1860
+ const { model: n } = z(
1861
+ at.type
1862
+ );
1863
+ if (n) {
1864
+ const i = n.boards.find(
1865
+ (a) => a.id === t.data.deviceId
1866
+ ) ? z(t.data.deviceId).model : void 0;
1867
+ return {
1868
+ devices: i ? i.name : ""
1869
+ };
1870
+ }
1871
+ }
1872
+ return {};
1873
+ }
1874
+ ), {
1875
+ preload: O.model.preloadModel(e),
1876
+ model: O.model.register(e),
1877
+ companion: O.companion.register(e),
1878
+ legacy: O.model.registerLegacyModel(e)
1879
+ }), P = {
1880
+ ...Et
1881
+ };
1882
+ P.dispense = {
1883
+ models: Qr(P)
1884
+ };
1885
+ P.preload = O.model.preloadModel(P);
1886
+ P.model = O.model.register(P);
1887
+ P.companion = O.companion.register(P);
1888
+ P.legacy = O.model.registerLegacyModel(P);
1889
+ const di = P;
1890
+ export {
1891
+ at as A,
1892
+ x as B,
1893
+ xr as C,
1894
+ D,
1895
+ u as E,
1896
+ Lr as F,
1897
+ oi as G,
1898
+ ke as H,
1899
+ je as I,
1900
+ Br as J,
1901
+ di as K,
1902
+ Zr as L,
1903
+ Ce as N,
1904
+ it as P,
1905
+ Je as T,
1906
+ _e as a,
1907
+ Xe as b,
1908
+ tt as c,
1909
+ et as d,
1910
+ Yr as e,
1911
+ rt as f,
1912
+ Ke as g,
1913
+ Oe as h,
1914
+ We as i,
1915
+ d as j,
1916
+ Le as k,
1917
+ Nt as l,
1918
+ ai as m,
1919
+ Ut as n,
1920
+ si as o,
1921
+ ni as p,
1922
+ ii as q,
1923
+ Qr as r,
1924
+ jt as s,
1925
+ Kt as t,
1926
+ Gt as u,
1927
+ Ze as v,
1928
+ _r as w,
1929
+ br as x,
1930
+ Ur as y,
1931
+ Ar as z
1932
+ };
1933
+ //# sourceMappingURL=dispense-registration-manager-UjShRcvq.js.map