@kosdev-code/kos-dispense-sdk 2.0.45 → 2.0.46

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 (121) hide show
  1. package/dispense-registration-manager-o2X21qmP.js +1972 -0
  2. package/dispense-registration-manager-o2X21qmP.js.map +1 -0
  3. package/dispense-registration-manager-oEcu0aLL.cjs +2 -0
  4. package/dispense-registration-manager-oEcu0aLL.cjs.map +1 -0
  5. package/extension-utils-CJ5qRklm.cjs +2 -0
  6. package/extension-utils-CJ5qRklm.cjs.map +1 -0
  7. package/extension-utils-CbCKII-5.js +381 -0
  8. package/extension-utils-CbCKII-5.js.map +1 -0
  9. package/index.cjs +1 -142
  10. package/index.cjs.map +1 -1
  11. package/index.d.ts +1 -2
  12. package/index.d.ts.map +1 -1
  13. package/index.js +103 -133
  14. package/index.js.map +1 -1
  15. package/models/models/assembly/assembly-model.d.ts +0 -4
  16. package/models/models/assembly/assembly-model.d.ts.map +1 -1
  17. package/models/models/assembly/pump-utils.d.ts.map +1 -1
  18. package/models/models/availability/availability-model.d.ts.map +1 -1
  19. package/models/models/board/board-container-model.d.ts +0 -4
  20. package/models/models/board/board-container-model.d.ts.map +1 -1
  21. package/models/models/board/board-model.d.ts +0 -4
  22. package/models/models/board/board-model.d.ts.map +1 -1
  23. package/models/models/device-assembly/device-assembly-model.d.ts +0 -4
  24. package/models/models/device-assembly/device-assembly-model.d.ts.map +1 -1
  25. package/models/models/generic-pour/generic-pour-model.d.ts +13 -54
  26. package/models/models/generic-pour/generic-pour-model.d.ts.map +1 -1
  27. package/models/models/generic-pour/index.d.ts +2 -2
  28. package/models/models/generic-pour/index.d.ts.map +1 -1
  29. package/models/models/generic-pour/types/index.d.ts +0 -1
  30. package/models/models/holder/holder-model.d.ts.map +1 -1
  31. package/models/models/holder-container/holder-container-model.d.ts.map +1 -1
  32. package/models/models/ingredient/ingredient-model.d.ts.map +1 -1
  33. package/models/models/ingredient-container/ingredient-container-model.d.ts.map +1 -1
  34. package/models/models/nozzle/index.d.ts +1 -1
  35. package/models/models/nozzle/index.d.ts.map +1 -1
  36. package/models/models/nozzle/nozzle-model.d.ts +10 -28
  37. package/models/models/nozzle/nozzle-model.d.ts.map +1 -1
  38. package/models/models/nozzle/types/index.d.ts +0 -8
  39. package/models/models/pump/pump-model.d.ts.map +1 -1
  40. package/models/models/pump/types/index.d.ts +2 -7
  41. package/models/models/pump-container/pump-container-model.d.ts.map +1 -1
  42. package/models/models/types/assembly.d.ts +0 -4
  43. package/models/models/types/assembly.d.ts.map +1 -1
  44. package/models/models/types/intent.d.ts +0 -98
  45. package/models/models/types/intent.d.ts.map +1 -1
  46. package/models/models/types/pouring.d.ts +3 -1
  47. package/models/models/types/pouring.d.ts.map +1 -1
  48. package/models/utils/dispense-registration-manager.d.ts +2 -2
  49. package/models/utils/extension-utils.d.ts +18 -90
  50. package/models/utils/extension-utils.d.ts.map +1 -1
  51. package/models/utils/service.d.ts +12 -16
  52. package/models/utils/service.d.ts.map +1 -1
  53. package/models.cjs +1 -47
  54. package/models.cjs.map +1 -1
  55. package/models.js +37 -40
  56. package/package.json +2 -19
  57. package/pump-provider-BQcKWjr8.cjs +2 -0
  58. package/pump-provider-BQcKWjr8.cjs.map +1 -0
  59. package/pump-provider-Bv-OLySq.js +1238 -0
  60. package/pump-provider-Bv-OLySq.js.map +1 -0
  61. package/ui/contexts/cui-kit/cui-kit.d.ts +4 -4
  62. package/ui/contexts/cui-kit/cui-kit.d.ts.map +1 -1
  63. package/ui/hooks/cui-kit/use-beverages.d.ts +2 -3
  64. package/ui/hooks/cui-kit/use-beverages.d.ts.map +1 -1
  65. package/ui/hooks/cui-kit/use-brands.d.ts +1 -1
  66. package/ui/hooks/cui-kit/use-brands.d.ts.map +1 -1
  67. package/ui/hooks/cui-kit/use-cui-kit.d.ts +2 -3
  68. package/ui/hooks/cui-kit/use-cui-kit.d.ts.map +1 -1
  69. package/ui/hooks/cui-kit/use-dispense-lifecycle.d.ts +1 -2
  70. package/ui/hooks/cui-kit/use-dispense-lifecycle.d.ts.map +1 -1
  71. package/ui/hooks/cui-kit/use-flavors.d.ts +1 -1
  72. package/ui/hooks/cui-kit/use-flavors.d.ts.map +1 -1
  73. package/ui/hooks/generic-pour/use-generic-pour.d.ts +2 -3
  74. package/ui/hooks/generic-pour/use-generic-pour.d.ts.map +1 -1
  75. package/ui/hooks/nozzle-pour/use-nozzle-pour.d.ts +2 -6
  76. package/ui/hooks/nozzle-pour/use-nozzle-pour.d.ts.map +1 -1
  77. package/ui/hooks/pour/use-pour.d.ts +3 -8
  78. package/ui/hooks/pour/use-pour.d.ts.map +1 -1
  79. package/ui/hooks/utils/pour-strategy/hold-to-pour-strategy.d.ts.map +1 -1
  80. package/ui/hooks/utils/pour-strategy/pour-strategy.d.ts +9 -2
  81. package/ui/hooks/utils/pour-strategy/pour-strategy.d.ts.map +1 -1
  82. package/ui/hooks/utils/pour-strategy/tap-to-pour-strategy.d.ts.map +1 -1
  83. package/ui/index.d.ts +0 -1
  84. package/ui/index.d.ts.map +1 -1
  85. package/ui.cjs +1 -73
  86. package/ui.cjs.map +1 -1
  87. package/ui.js +65 -66
  88. package/dispense-registration-manager-C7GGaZ47.js +0 -2673
  89. package/dispense-registration-manager-C7GGaZ47.js.map +0 -1
  90. package/dispense-registration-manager-lQhkTFKW.cjs +0 -2671
  91. package/dispense-registration-manager-lQhkTFKW.cjs.map +0 -1
  92. package/extension-utils-50g2ril2.cjs +0 -500
  93. package/extension-utils-50g2ril2.cjs.map +0 -1
  94. package/extension-utils-Dt00FOJq.js +0 -501
  95. package/extension-utils-Dt00FOJq.js.map +0 -1
  96. package/extensions/control-pour-extension.d.ts +0 -70
  97. package/extensions/control-pour-extension.d.ts.map +0 -1
  98. package/extensions/index.d.ts +0 -2
  99. package/extensions/index.d.ts.map +0 -1
  100. package/kos-models.json +0 -180
  101. package/models/utils/openapi-index.d.ts +0 -2
  102. package/models/utils/openapi-index.d.ts.map +0 -1
  103. package/models/utils/services/dispense/1.6.5/openapi.d.ts +0 -845
  104. package/models/utils/services/dispense/1.6.5/service.d.ts +0 -122
  105. package/models/utils/services/dispense/1.6.5/service.d.ts.map +0 -1
  106. package/models/utils/services/dispense/1.8.1/openapi.d.ts +0 -1653
  107. package/models/utils/services/dispense/1.8.1/service.d.ts +0 -122
  108. package/models/utils/services/dispense/1.8.1/service.d.ts.map +0 -1
  109. package/models/utils/services/dispense/daily/openapi.d.ts +0 -1820
  110. package/models/utils/services/dispense/daily/service.d.ts +0 -122
  111. package/models/utils/services/dispense/daily/service.d.ts.map +0 -1
  112. package/models/utils/services-index.d.ts +0 -4
  113. package/models/utils/services-index.d.ts.map +0 -1
  114. package/pump-provider-CBFev3qg.cjs +0 -1824
  115. package/pump-provider-CBFev3qg.cjs.map +0 -1
  116. package/pump-provider-DyxEmFRT.js +0 -1825
  117. package/pump-provider-DyxEmFRT.js.map +0 -1
  118. package/ui/hooks/cui-kit/dispense-topics.d.ts +0 -47
  119. package/ui/hooks/cui-kit/dispense-topics.d.ts.map +0 -1
  120. package/ui/utils/pour-context.d.ts +0 -8
  121. package/ui/utils/pour-context.d.ts.map +0 -1
@@ -0,0 +1,1972 @@
1
+ var gt = Object.defineProperty;
2
+ var ht = (e, t, r) => t in e ? gt(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
+ var o = (e, t, r) => (ht(e, typeof t != "symbol" ? t + "" : t, r), r);
4
+ import { kosModel as I, Kos as v, isKosModel as P, resolveServiceUrl as S, ServiceFactory as C, KosLog as m, KosModelContainer as R, KosExtensionUtils as T, kosChild as M, FetchError as yt, ExtensionManager as g, EXTENSION_TROUBLE_MAPPER as Me, EXTENSION_TROUBLE_DATA_MAPPER as W, getKosModelSync as N, kosDependency as ce, TroubleContainer as Be, troubleByTypeReducer as Ue, kosAction as h, kosTopicHandler as Q, DependencyLifecycle as Ge, getKosModel as Fe, FutureManager as pe, kosFuture as ue, FutureHandler as je, EXTENSION_FEATURE_FLAG_RESOLVER as It, isKosDataModel as ft, ChildModels as mt, KosFeatureFlags as bt, kosParentAware as vt, createPropKey as Pt, MultipleFutureHandler as _t, arraysEqual as Mt, getAllKosCompanionModels as E, EventBus as _, KosContextManager as ze, destroyKosModel as Ot, SingletonKosModelRegistrationFactory as Et, KosModelRegistrationFactory as wt, KosModelRegistry as $t, RegistrationManager as O, registerCoreModels as St, registerLegacyModel as Ct } 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.AssemblyFeatureFlags = "kos.assembly.feature.flags", e))(u || {}), z = /* @__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))(z || {}), Rt = Object.getOwnPropertyDescriptor, zt = (e, t, r, a) => {
7
+ for (var i = a > 1 ? void 0 : a ? Rt(t, r) : t, s = e.length - 1, n; s >= 0; s--)
8
+ (n = e[s]) && (i = n(i) || i);
9
+ return i;
10
+ };
11
+ const G = "ingredient-model";
12
+ let be = class {
13
+ constructor(e, {
14
+ name: t,
15
+ type: r,
16
+ data: a,
17
+ ingredientId: i,
18
+ ...s
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 = a, Object.assign(this, s);
26
+ }
27
+ updateModel({
28
+ name: e,
29
+ type: t,
30
+ data: r,
31
+ ingredientId: a,
32
+ ...i
33
+ }) {
34
+ this.name = e, this.type = t, this.ingredientId = a, this.data = r, Object.assign(this, i);
35
+ }
36
+ // -------------------LIFECYCLE----------------------------
37
+ // -------------------ENTITY----------------------------
38
+ };
39
+ be = zt([
40
+ I(G)
41
+ ], be);
42
+ const He = {
43
+ registration: {
44
+ [G]: {
45
+ class: be,
46
+ singleton: !1
47
+ }
48
+ },
49
+ type: G,
50
+ predicate: P(G),
51
+ factory: v.Factory.create(G)
52
+ }, { URL: Ke } = S("INGREDIENT_SERVICE"), { getOne: Dt } = C.build({
53
+ basePath: `${Ke}/api/ext/dispense/ingredients`
54
+ }), Tt = async () => await Dt({
55
+ urlOverride: `${Ke}/api/ext/dispense/ingredients`
56
+ });
57
+ var Nt = Object.defineProperty, Lt = Object.getOwnPropertyDescriptor, Ve = (e, t, r, a) => {
58
+ for (var i = a > 1 ? void 0 : a ? Lt(t, r) : t, s = e.length - 1, n; s >= 0; s--)
59
+ (n = e[s]) && (i = (a ? n(t, r, i) : n(i)) || i);
60
+ return a && i && Nt(t, r, i), i;
61
+ };
62
+ const F = "ingredient-container-model", xt = m.createLogger({ name: "ingredient-container-model" });
63
+ let ae = 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
+ xt.debug(`loading ingredient container ${this.id}`);
84
+ const t = await Tt();
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
+ }), a = (t == null ? void 0 : t.data) ?? {};
91
+ for (const s of Object.keys(a))
92
+ for (const n of ((i = t == null ? void 0 : t.data) == null ? void 0 : i[s]) || []) {
93
+ const l = await T.executeDataMapperExtension({
94
+ extension: u.IngredientMapper,
95
+ data: n,
96
+ contextData: r
97
+ }), c = await T.executePropertyMapperExtension({
98
+ extension: u.IngredientTypeMapper,
99
+ data: n,
100
+ contextData: r
101
+ }), p = {
102
+ ...n,
103
+ type: c || n.type,
104
+ ...l,
105
+ data: l
106
+ }, y = He.factory(n.id)(
107
+ p
108
+ );
109
+ this.ingredients.addModel(y);
110
+ }
111
+ }
112
+ // -------------------ENTITY----------------------------
113
+ };
114
+ Ve([
115
+ M
116
+ ], ae.prototype, "ingredients", 2);
117
+ ae = Ve([
118
+ I(F)
119
+ ], ae);
120
+ const ke = {
121
+ registration: {
122
+ [F]: {
123
+ class: ae,
124
+ singleton: !0
125
+ }
126
+ },
127
+ type: F,
128
+ predicate: P(F),
129
+ factory: v.Singleton.create(F)
130
+ }, { URL: ge } = S("HOLDER_SERVICE"), { getAll: At, postModel: Ye, deleteModel: Bt } = C.build({
131
+ basePath: `${ge}/api/kos/holders`
132
+ }), Ut = m.createLogger({
133
+ name: "holder-service",
134
+ group: "Services"
135
+ }), ri = async () => await At({}), Gt = async (e, t) => {
136
+ if (!e || !t)
137
+ throw new Error("Missing holderPath or ingredientId");
138
+ return await Ye({
139
+ model: { holderPath: e, ingredientId: t },
140
+ urlOverride: `${ge}/api/ext/dispense/assignments`
141
+ });
142
+ }, Ft = async (e) => {
143
+ if (!e)
144
+ throw new Error("Missing holderPath");
145
+ return await Bt({
146
+ id: e,
147
+ urlOverride: `${ge}/api/ext/dispense/assignments/${e}`
148
+ });
149
+ }, jt = async (e) => {
150
+ if (!e)
151
+ throw new Error("Missing holderPath");
152
+ return Ut.debug(
153
+ `sending POST request to /api/ext/dispense/pumpEvents/replaceLine/${e}`
154
+ ), await Ye({
155
+ model: {},
156
+ urlOverride: `${ge}/api/ext/dispense/pumpEvents/replaceLine/${e}`
157
+ });
158
+ }, { URL: se } = S("ASSIGNMENT_SERVICE"), { getAll: Ht, postModel: Ze, deleteModel: Kt } = C.build({
159
+ destinationAddress: "",
160
+ basePath: `${se}/api/ext/dispense/assignments`
161
+ }), ne = window.kosUseFos, ii = async () => await Ht({ fos: ne }), Vt = async (e, t) => {
162
+ var i, s, n, l;
163
+ const r = JSON.stringify(t), a = `${se}/api/ext/dispense/assignments`;
164
+ try {
165
+ const c = await Ze({
166
+ model: { holderPath: e, factoryJson: r },
167
+ urlOverride: a
168
+ });
169
+ return (c == null ? void 0 : c.status) === 200 && ((i = c == null ? void 0 : c.data) != null && i.error) ? [c.data.error || "unknownError", c.data] : [void 0, c == null ? void 0 : c.data];
170
+ } catch (c) {
171
+ if (c instanceof yt)
172
+ return [
173
+ ((n = (s = c.payload) == null ? void 0 : s.data) == null ? void 0 : n.error) || "unknownError",
174
+ (l = c.payload) == null ? void 0 : l.data
175
+ ];
176
+ }
177
+ return ["unknownError", void 0];
178
+ }, ai = async (e) => {
179
+ const t = ne ? `${se}/api/ingredients/assignments/${e.holderPath}` : `${se}/api/ext/dispense/assignments`;
180
+ return await Ze({
181
+ model: { ...e, fuelGauge: 680 },
182
+ fos: ne,
183
+ urlOverride: t
184
+ });
185
+ }, si = async (e) => await Kt({ id: e, fos: ne });
186
+ var kt = Object.defineProperty, Yt = Object.getOwnPropertyDescriptor, he = (e, t, r, a) => {
187
+ for (var i = a > 1 ? void 0 : a ? Yt(t, r) : t, s = e.length - 1, n; s >= 0; s--)
188
+ (n = e[s]) && (i = (a ? n(t, r, i) : n(i)) || i);
189
+ return a && i && kt(t, r, i), i;
190
+ };
191
+ const j = z.Holder, De = m.createLogger({ name: "holder-model" });
192
+ g[Me].register(
193
+ "holder",
194
+ async (e) => {
195
+ const t = [];
196
+ return t.push(...e.data.holderPaths), t;
197
+ }
198
+ );
199
+ g[W].register(
200
+ "pump",
201
+ async (e) => {
202
+ if (e.data.pumpPath) {
203
+ const { model: t } = N(
204
+ e.data.pumpPath
205
+ );
206
+ if (t) {
207
+ const r = t.ingredientId ? N(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
+ g[W].register(
219
+ "holder",
220
+ async (e) => e.data.holderNames.length > 0 ? {
221
+ holderName: e.data.holderNames[0] || ""
222
+ } : {}
223
+ );
224
+ g[W].register(
225
+ "container",
226
+ async (e) => {
227
+ if (e.data.ingredients.length > 0) {
228
+ const t = e.data.ingredients[0], { model: r } = N(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 Zt extends Error {
239
+ constructor(r, a) {
240
+ super(a);
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: a,
250
+ ingredientId: i,
251
+ ingredientType: s,
252
+ slice: n,
253
+ group: l,
254
+ data: c,
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 = s, this.ingredientSource = a, this.ingredientId = i, this.group = l, this.slice = n, this.enjoyByDate = p, this.data = c, 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: a,
281
+ ingredientType: i,
282
+ group: s,
283
+ slice: n,
284
+ enjoyByDate: l,
285
+ data: c
286
+ }) {
287
+ this.path = e, this.name = t, this.ingredientId = a, this.ingredientType = i, this.ingredientSource = r, this.enjoyByDate = l, this.slice = n, this.group = s, this.data = c;
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, a = r ? this.pumps.getModel(r) : this.pumps.data[0];
313
+ return a == null ? void 0 : a.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
+ Ue,
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 && h(() => {
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 Vt(this.path, e);
400
+ if (t)
401
+ throw new Zt(
402
+ t,
403
+ `Failed to perform rfid override on holder ${this.id}`
404
+ );
405
+ return h(() => {
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 Gt(this.path, e) : await Ft(this.path), h(() => {
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
+ he([
448
+ M
449
+ ], L.prototype, "pumps", 2);
450
+ he([
451
+ ce({ modelType: ke.type })
452
+ ], L.prototype, "ingredientContainer", 2);
453
+ he([
454
+ ce({ modelType: Be.type })
455
+ ], L.prototype, "troubleContainer", 2);
456
+ L = he([
457
+ I(j)
458
+ ], L);
459
+ const Xe = {
460
+ registration: {
461
+ [j]: {
462
+ class: L,
463
+ singleton: !1
464
+ }
465
+ },
466
+ type: j,
467
+ predicate: P(j),
468
+ factory: v.Factory.create(j)
469
+ }, Xt = async (e, t) => {
470
+ var Re;
471
+ const r = g.propertyMapper.executeMapper(
472
+ u.HolderIngredientMapper,
473
+ t
474
+ ), a = g.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: s, path: n, ingredientId: l, ingType: c, ingSource: p, slice: y, ...U } = t, f = { ...U, ...i }, D = y || { pos: 0 }, re = {
482
+ name: s,
483
+ path: n,
484
+ ingredientId: r || l,
485
+ ingredientType: a || c,
486
+ ingredientSource: p,
487
+ enjoyByDate: (Re = t.container) != null && Re.enjoyByDate ? new Date(t.container.enjoyByDate) : void 0,
488
+ slice: D,
489
+ group: e,
490
+ data: f
491
+ };
492
+ return Xe.factory(t.path)(re);
493
+ }, { URL: Jt } = S("ASSEMBLY_SERVICE"), { getOne: qt } = C.build({
494
+ basePath: `${Jt}/api/kos/device/assemblies`
495
+ }), Wt = m.createLogger({
496
+ name: "assembly-service",
497
+ group: "Services"
498
+ }), Je = async () => (Wt.debug("sending GET for assembly"), await qt({}));
499
+ var Qt = Object.defineProperty, er = Object.getOwnPropertyDescriptor, ye = (e, t, r, a) => {
500
+ for (var i = a > 1 ? void 0 : a ? er(t, r) : t, s = e.length - 1, n; s >= 0; s--)
501
+ (n = e[s]) && (i = (a ? n(t, r, i) : n(i)) || i);
502
+ return a && i && Qt(t, r, i), i;
503
+ };
504
+ const H = "board-container-model", qe = "/kos/hardware/board/linked", We = "/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 ${qe} event ${e}`), e ? this.updateBoard(e) : this.logger.debug("- boardLinkEvent is undefined");
536
+ }
537
+ handleBoardUnlinkEvent(e) {
538
+ this.logger.debug(
539
+ `handling ${We} 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: Ge.INIT,
549
+ topic: qe,
550
+ websocket: !0
551
+ })
552
+ ], x.prototype, "handleBoardLinkEvent", 1);
553
+ ye([
554
+ Q({
555
+ lifecycle: Ge.INIT,
556
+ topic: We,
557
+ websocket: !0
558
+ })
559
+ ], x.prototype, "handleBoardUnlinkEvent", 1);
560
+ x = ye([
561
+ I(H)
562
+ ], x);
563
+ const tr = async (e) => {
564
+ const t = e.data.boardPath, { model: r } = N(t);
565
+ return {
566
+ boardName: (r == null ? void 0 : r.name) || ""
567
+ };
568
+ };
569
+ var rr = Object.defineProperty, ir = Object.getOwnPropertyDescriptor, Qe = (e, t, r, a) => {
570
+ for (var i = a > 1 ? void 0 : a ? ir(t, r) : t, s = e.length - 1, n; s >= 0; s--)
571
+ (n = e[s]) && (i = (a ? n(t, r, i) : n(i)) || i);
572
+ return a && i && rr(t, r, i), i;
573
+ };
574
+ const K = z.PumpContainer;
575
+ var et = /* @__PURE__ */ ((e) => (e.byBoard = "byBoard", e.byType = "byType", e.byNozzle = "byNozzle", e))(et || {});
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: P(K),
639
+ factory: v.Singleton.create(
640
+ K
641
+ )
642
+ }, tt = async (e) => {
643
+ const t = [], { model: r } = await Fe(e);
644
+ return r && (t.push(r.boardPath), t.push(r.nozzlePath), t.push(r.holderPath)), t;
645
+ }, ar = async (e) => {
646
+ const t = [], r = e.data.pumpPath;
647
+ t.push(r);
648
+ const a = await tt(r);
649
+ return [...t, ...a];
650
+ }, sr = async (e) => {
651
+ const t = [], r = e.data.boardPath;
652
+ t.push(e.data.boardPath);
653
+ const a = await Fe(
654
+ Oe.type
655
+ );
656
+ if (a != null && a.model) {
657
+ const s = a.model.models.getIndexByKey(
658
+ et.byBoard,
659
+ r
660
+ ).map(
661
+ (l) => tt(l.path)
662
+ );
663
+ (await Promise.allSettled(s)).forEach((l) => {
664
+ l.status === "fulfilled" && l.value.forEach((c) => t.push(c));
665
+ });
666
+ }
667
+ return Array.from(new Set(t));
668
+ };
669
+ var nr = Object.getOwnPropertyDescriptor, or = (e, t, r, a) => {
670
+ for (var i = a > 1 ? void 0 : a ? nr(t, r) : t, s = e.length - 1, n; s >= 0; s--)
671
+ (n = e[s]) && (i = n(i) || i);
672
+ return i;
673
+ };
674
+ const V = "board-model", Te = (e, t) => {
675
+ const { type: r, name: a, path: i, linked: s, instanceId: n, link: l, ...c } = e;
676
+ t.type = r, t.name = a, t.path = i, t.linked = s, t.link = Object.freeze(l), t.instanceId = n, Object.assign(t, c);
677
+ };
678
+ g[Me].register(
679
+ "board",
680
+ sr
681
+ );
682
+ g[W].register(
683
+ "board",
684
+ tr
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, Te(t, this);
696
+ }
697
+ updateModel(e) {
698
+ Te(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 rt = {
712
+ registration: {
713
+ [V]: {
714
+ class: ve,
715
+ singleton: !1
716
+ }
717
+ },
718
+ type: V,
719
+ predicate: P(V),
720
+ factory: v.Factory.create(V)
721
+ }, it = {
722
+ registration: {
723
+ [H]: {
724
+ class: x,
725
+ singleton: !0
726
+ },
727
+ ...rt.registration
728
+ },
729
+ type: H,
730
+ predicate: P(H),
731
+ factory: v.Singleton.create(
732
+ H
733
+ )
734
+ };
735
+ var dr = Object.defineProperty, lr = Object.getOwnPropertyDescriptor, Ie = (e, t, r, a) => {
736
+ for (var i = a > 1 ? void 0 : a ? lr(t, r) : t, s = e.length - 1, n; s >= 0; s--)
737
+ (n = e[s]) && (i = (a ? n(t, r, i) : n(i)) || i);
738
+ return a && i && dr(t, r, i), i;
739
+ };
740
+ const k = z.HolderContainer, cr = "/kos/insertion/insert/start", pr = "/kos/insertion/insert/complete", ur = "/kos/insertion/insert/update", gr = "/kos/insertion/remove", hr = "/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: (a) => a.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, a, 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 = (a = e.slice) == null ? void 0 : a.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
+ h(() => {
772
+ var s, n, l;
773
+ const a = r.ingredientId, i = this.holders.getModel(r.path);
774
+ i && (this.logger.info(
775
+ `Received insertion event for holder ${i.path}`
776
+ ), i.updateIngredient(a), i.slice.currentVolMl = (s = r.slice) == null ? void 0 : s.currentVolMl, i.slice.maxVolMl = (n = r.slice) == null ? void 0 : n.maxVolMl, (l = r == null ? void 0 : r.container) != null && l.enjoyByDate ? i.enjoyByDate = new Date(r.container.enjoyByDate) : i.enjoyByDate = void 0, r.pumps.forEach((c) => {
777
+ h(() => {
778
+ const p = i.pumps.getModel(c.path);
779
+ p && (p.ingredientId = c.ingredientId, p.inserted = c.inserted, p.prevIngredientId = c.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
+ gr,
804
+ hr
805
+ ],
806
+ websocket: !0
807
+ })
808
+ ], A.prototype, "handleInsertion", 1);
809
+ A = Ie([
810
+ I(k)
811
+ ], A);
812
+ const at = {
813
+ registration: {
814
+ [k]: {
815
+ class: A,
816
+ singleton: !0
817
+ }
818
+ },
819
+ type: k,
820
+ predicate: P(k),
821
+ factory: v.Singleton.create(
822
+ k
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: a, path: i, linked: s, instanceId: n, ...l } = e, c = { ...l, ...t }, p = {
830
+ type: r,
831
+ name: a,
832
+ path: i,
833
+ linked: s,
834
+ instanceId: n,
835
+ ...c
836
+ }, y = rt.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 } = S("PUMP_SERVICE"), { postModel: br, getOne: vr } = C.build({
845
+ basePath: `${Ee}/api/kos/holders`
846
+ });
847
+ m.createLogger({
848
+ name: "pump-service",
849
+ group: "Services"
850
+ });
851
+ const Pr = async ({
852
+ intent: e,
853
+ pumpId: t,
854
+ tracker: r
855
+ }) => {
856
+ const a = `${Ee}/api/ext/dispense/nozzle/nozzle/pipeline/ingredient/pour/${t}/${e}`, i = await br({ model: {}, urlOverride: a, 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`, a = await vr({ urlOverride: r });
860
+ return a != null && a.data ? a.data : { volume: -1 };
861
+ };
862
+ var Mr = Object.defineProperty, Or = Object.getOwnPropertyDescriptor, we = (e, t, r, a) => {
863
+ for (var i = a > 1 ? void 0 : a ? Or(t, r) : t, s = e.length - 1, n; s >= 0; s--)
864
+ (n = e[s]) && (i = (a ? n(t, r, i) : n(i)) || i);
865
+ return a && i && Mr(t, r, i), i;
866
+ };
867
+ const Y = z.Pump;
868
+ g[Me].register(
869
+ "pump",
870
+ ar
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: a,
893
+ boardPath: i,
894
+ nozzlePath: s,
895
+ name: n,
896
+ path: l,
897
+ childPump: c,
898
+ virtual: p,
899
+ prevIngredientId: y,
900
+ ...U
901
+ } = t;
902
+ this.inserted = r, this.type = t.type, this.ingredientId = t.ingredientId, this.holderPath = a, this.boardPath = i, this.nozzlePath = s, this.name = n, this.path = l, this.childPump = !!c, this.virtual = !!p, this.prevIngredientId = y, Object.assign(this, U), this.futureHandler = new je(this);
903
+ }
904
+ updateModel(e) {
905
+ const {
906
+ inserted: t,
907
+ holderPath: r,
908
+ boardPath: a,
909
+ nozzlePath: i,
910
+ childPump: s,
911
+ name: n,
912
+ path: l,
913
+ ...c
914
+ } = e;
915
+ this.inserted = t, this.type = e.type, this.ingredientId = e.ingredientId, this.holderPath = r, this.boardPath = a, this.nozzlePath = i, this.childPump = this.childPump ? this.childPump : !!s, this.name = n, this.path = l, this.prevIngredientId = e.prevIngredientId, Object.assign(this, c);
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
+ Ue,
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 && h(() => {
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()), h(() => {
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 a = await Pr({
967
+ tracker: t,
968
+ intent: r,
969
+ pumpId: this.path
970
+ });
971
+ return this.currentState === d.POUR_STARTING && h(() => {
972
+ this.currentState = d.POURING;
973
+ }), a == null ? void 0 : a.data;
974
+ } else
975
+ throw new Error(`Cannot pour in state ${this.currentState}`);
976
+ } catch (a) {
977
+ throw m.error(a), this.currentState = d.IDLE, a;
978
+ }
979
+ }
980
+ // -------------------ENTITY----------------------------
981
+ };
982
+ we([
983
+ ce({ modelType: Be.type })
984
+ ], q.prototype, "troubleContainer", 2);
985
+ we([
986
+ ue()
987
+ ], q.prototype, "performIntent", 1);
988
+ q = we([
989
+ I(Y)
990
+ ], q);
991
+ const st = {
992
+ registration: {
993
+ [Y]: {
994
+ class: q,
995
+ singleton: !1
996
+ }
997
+ },
998
+ type: Y,
999
+ predicate: P(Y),
1000
+ factory: v.Factory.create(Y)
1001
+ }, Er = m.createLogger({ name: "pump-utils" }), wr = (e, t) => {
1002
+ const r = (t.pumps ?? []).length > 1, a = {
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 = st.factory(t.path)(a);
1015
+ return i.updateModel(a), i;
1016
+ }, nt = (e) => (t) => (r) => (a) => {
1017
+ var l;
1018
+ Er.debug(`adding pump ${a.name}`);
1019
+ const i = wr(r.path, a);
1020
+ e.addModel(i);
1021
+ const s = i.holderPath, n = t.holders.getModel(s);
1022
+ n == null || n.pumps.addModel(i), n != null && n.nozzlePaths.includes(r.path) || n == null || n.nozzlePaths.push(r.path), (l = a == null ? void 0 : a.pumps) == null || l.forEach((c) => {
1023
+ const p = i.holderPath, y = {
1024
+ ...c,
1025
+ childPump: !0,
1026
+ holderPath: p,
1027
+ ingredientId: i.ingredientId
1028
+ };
1029
+ nt(e)(t)(r)(y);
1030
+ });
1031
+ };
1032
+ var $r = Object.defineProperty, Sr = Object.getOwnPropertyDescriptor, ee = (e, t, r, a) => {
1033
+ for (var i = a > 1 ? void 0 : a ? Sr(t, r) : t, s = e.length - 1, n; s >= 0; s--)
1034
+ (n = e[s]) && (i = (a ? n(t, r, i) : n(i)) || i);
1035
+ return a && i && $r(t, r, i), i;
1036
+ };
1037
+ const Z = "assembly-model", Cr = "assembly-data", Rr = "assembly-raw-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 = at.factory({}), this.boardContainer = it.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(), g[It].execute(
1091
+ u.AssemblyFeatureFlags,
1092
+ this
1093
+ );
1094
+ }
1095
+ async load(e) {
1096
+ this.logger.debug(`loading assembly ${this.id}`);
1097
+ const t = await Je();
1098
+ if ((t == null ? void 0 : t.status) === 200) {
1099
+ const r = await T.executeDataMapperExtension({
1100
+ extension: u.AssemblyMapper,
1101
+ data: t.data,
1102
+ contextData: {}
1103
+ });
1104
+ e.set(Cr, r), Object.assign(this, r), Object.entries(r).forEach(([a, i]) => {
1105
+ ft(i) && (this.logger.debug(`adding child model ${a} from extension data`), this[mt][a] = !0);
1106
+ }), e.set(Rr, t.data);
1107
+ for await (const a of t.data.assemblies) {
1108
+ const {
1109
+ boards: i = [],
1110
+ holders: s = {},
1111
+ nozzles: n = [],
1112
+ core: l,
1113
+ name: c,
1114
+ path: p,
1115
+ ...y
1116
+ } = a;
1117
+ this.logger.debug(`adding assembly ${c}`), Object.keys(y).forEach((f) => {
1118
+ bt.enableFeature(f);
1119
+ });
1120
+ for await (const f of i)
1121
+ this.logger.debug(`adding board ${f.name}`), await mr(this.boardContainer)(f);
1122
+ for await (const [f, D] of Object.entries(
1123
+ s ?? {}
1124
+ ))
1125
+ for await (const re of D) {
1126
+ this.logger.debug(`adding holder ${re.name}`);
1127
+ const Ce = await Xt(f, re);
1128
+ this.holderContainer.holders.addModel(Ce);
1129
+ }
1130
+ const U = nt(this.pumpContainer)(
1131
+ this.holderContainer
1132
+ );
1133
+ n.forEach((f) => {
1134
+ this._nozzlePaths.add(f.path);
1135
+ const D = U(f);
1136
+ f.pumps.forEach(D);
1137
+ });
1138
+ }
1139
+ }
1140
+ }
1141
+ };
1142
+ ee([
1143
+ ce({
1144
+ modelType: "trouble-container-model"
1145
+ })
1146
+ ], w.prototype, "troubleContainer", 2);
1147
+ ee([
1148
+ M
1149
+ ], w.prototype, "holderContainer", 2);
1150
+ ee([
1151
+ M
1152
+ ], w.prototype, "boardContainer", 2);
1153
+ ee([
1154
+ M
1155
+ ], w.prototype, "pumpContainer", 2);
1156
+ w = ee([
1157
+ I(Z)
1158
+ ], w);
1159
+ const ot = {
1160
+ registration: {
1161
+ [Z]: {
1162
+ class: w,
1163
+ singleton: !0
1164
+ }
1165
+ },
1166
+ type: Z,
1167
+ predicate: P(Z),
1168
+ factory: v.Singleton.create(Z)
1169
+ };
1170
+ var zr = Object.getOwnPropertyDescriptor, Dr = (e, t, r, a) => {
1171
+ for (var i = a > 1 ? void 0 : a ? zr(t, r) : t, s = e.length - 1, n; s >= 0; s--)
1172
+ (n = e[s]) && (i = n(i) || i);
1173
+ return i;
1174
+ };
1175
+ const X = z.Availability;
1176
+ let Pe = class {
1177
+ constructor(e, t, r) {
1178
+ o(this, "id");
1179
+ o(this, "data");
1180
+ o(this, "properties");
1181
+ o(this, "available");
1182
+ o(this, "visible");
1183
+ o(this, "groupId");
1184
+ o(this, "rawId");
1185
+ o(this, "altId");
1186
+ o(this, "type");
1187
+ o(this, "note");
1188
+ o(this, "taggedIds");
1189
+ o(this, "parentId");
1190
+ o(this, "logger");
1191
+ 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, this.properties = t.properties || {};
1192
+ }
1193
+ updateModel(e) {
1194
+ 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;
1195
+ }
1196
+ updateAvailability(e) {
1197
+ this.available = e;
1198
+ }
1199
+ // -------------------LIFECYCLE----------------------------
1200
+ // -------------------ENTITY----------------------------
1201
+ };
1202
+ Pe = Dr([
1203
+ vt(),
1204
+ I(X)
1205
+ ], Pe);
1206
+ const _e = {
1207
+ registration: {
1208
+ [X]: {
1209
+ class: Pe,
1210
+ singleton: !1
1211
+ }
1212
+ },
1213
+ type: X,
1214
+ predicate: P(X),
1215
+ factory: v.Factory.create(
1216
+ X
1217
+ )
1218
+ }, { URL: B } = S("NOZZLE_SERVICE"), { postModel: $e, deleteModel: Tr, getOne: Nr } = C.build({
1219
+ basePath: `${B}/api/nozzle`
1220
+ }), Lr = async (e, t) => {
1221
+ const r = await $e({
1222
+ model: {},
1223
+ urlOverride: `${B}/api/ext/dispense/nozzle/${e}/pipeline/beverage/pour`,
1224
+ ordered: !0,
1225
+ tracker: t
1226
+ });
1227
+ return r != null && r.data && pe.initiateFuture(r.data), r;
1228
+ }, xr = async (e, t, r) => {
1229
+ const a = await $e({
1230
+ model: {},
1231
+ urlOverride: `${B}/api/ext/dispense/nozzle/${t}/pipeline/beverage/fixed/${e}`,
1232
+ ordered: !0,
1233
+ tracker: r
1234
+ });
1235
+ return a != null && a.data && pe.initiateFuture(a.data), a;
1236
+ }, Ne = async (e) => await Nr({
1237
+ urlOverride: `${B}${e}/pipeline/beverage/availability`
1238
+ }), Ar = async (e, t) => await $e({
1239
+ model: t,
1240
+ urlOverride: `${B}/api/ext/dispense/nozzle/${e}/pipeline/beverage/select`
1241
+ }), Br = async (e) => await Tr({
1242
+ id: e,
1243
+ urlOverride: `${B}/api/ext/dispense/nozzle/${e}/pipeline/beverage/select`
1244
+ });
1245
+ var Ur = Object.defineProperty, Gr = Object.getOwnPropertyDescriptor, te = (e, t, r, a) => {
1246
+ for (var i = a > 1 ? void 0 : a ? Gr(t, r) : t, s = e.length - 1, n; s >= 0; s--)
1247
+ (n = e[s]) && (i = (a ? n(t, r, i) : n(i)) || i);
1248
+ return a && i && Ur(t, r, i), i;
1249
+ };
1250
+ const J = z.Nozzle, Fr = Pt(
1251
+ "beverageTopicPrefix"
1252
+ ), ie = (e) => e.onPourStart !== void 0 && e.onPourCancel !== void 0 && e.onPourProgress !== void 0, Le = "/kos/nozzle/pour/started", jr = "/kos/nozzle/pour/progress", fe = "/kos/nozzle/pour/cancel";
1253
+ let $ = class {
1254
+ constructor(e, t, r) {
1255
+ /** the unique identifier for this nozzle.*/
1256
+ o(this, "id");
1257
+ o(this, "path");
1258
+ o(this, "logger");
1259
+ o(this, "name");
1260
+ o(this, "_selectedBeverage");
1261
+ o(this, "_selectedBrand");
1262
+ o(this, "_additionalItems");
1263
+ o(this, "_availabilityItems");
1264
+ o(this, "futureHandler");
1265
+ o(this, "currentState", d.IDLE);
1266
+ o(this, "beverageTopicPrefix");
1267
+ o(this, "topicPrefix");
1268
+ o(this, "urlPrefix");
1269
+ 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 _t(this), this._availabilityItems = new R({
1270
+ indexMap: {
1271
+ byGroup: "groupId",
1272
+ byParent: "parentId"
1273
+ },
1274
+ parentId: e
1275
+ }), this.logger = r.logger;
1276
+ }
1277
+ /**
1278
+ * The availability nodes that can be dispensed from this nozzle.
1279
+ * This is a subset of the availability for the entire dispenser
1280
+ * and is determined by the nodes associated with a nozzle.
1281
+ */
1282
+ get beverages() {
1283
+ return this._availabilityItems.getIndexByKey("byGroup", "beverages");
1284
+ }
1285
+ /**
1286
+ * The availability nodes that have been grouped into the "brands" group.
1287
+ *
1288
+ */
1289
+ get brands() {
1290
+ return this._availabilityItems.getIndexByKey("byGroup", "brands");
1291
+ }
1292
+ get visibleBrands() {
1293
+ return this.brands.filter((e) => e.visible);
1294
+ }
1295
+ get visibleBeverages() {
1296
+ return this.beverages.filter((e) => e.visible);
1297
+ }
1298
+ /**
1299
+ * A derived value that indicates if the nozzle is currently pouring a beverage.
1300
+ * @readonly
1301
+ */
1302
+ get isPouring() {
1303
+ var e;
1304
+ 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;
1305
+ }
1306
+ /**
1307
+ * A derived value that indicates if the nozzle is currently available to pour a beverage.
1308
+ *
1309
+ * This will generally be determined by whether there is a currently selected pourable AND
1310
+ * the nozzle is not currently pouring.
1311
+ *
1312
+ * The value is observable and will change when the selected pourable changes or the nozzle
1313
+ * starts or stops pouring.
1314
+ * @readonly
1315
+ * */
1316
+ get canPour() {
1317
+ return !!this._selectedBeverage && this._selectedBeverage.available && this.currentState === d.IDLE;
1318
+ }
1319
+ /**
1320
+ * The selected pourable for this nozzle. Its shape is determined by the results of the
1321
+ * {@link ExtensionType.SelectedPourableMapper} extension.
1322
+ * @readonly
1323
+ *
1324
+ * */
1325
+ get selectedPourable() {
1326
+ return {
1327
+ beverage: this._selectedBeverage,
1328
+ additional: this._additionalItems
1329
+ };
1330
+ }
1331
+ get future() {
1332
+ return this.futureHandler.getFuture();
1333
+ }
1334
+ get pourProgress() {
1335
+ var e;
1336
+ return ((e = this.future) == null ? void 0 : e.progress) ?? 0;
1337
+ }
1338
+ updateModel() {
1339
+ }
1340
+ // -------------------LIFECYCLE----------------------------
1341
+ setSelectedBrand(e) {
1342
+ this._selectedBrand = e, this._selectedBeverage = void 0;
1343
+ }
1344
+ get selectedBrand() {
1345
+ return this._selectedBrand;
1346
+ }
1347
+ /**
1348
+ * Set the values used to determine the selected pourable for this nozzle.
1349
+ *
1350
+ * @param pourable The pourable to set.
1351
+ * @param pourable.beverage The beverage selected.
1352
+ * @param pourable.additional The additional items such as flavors or other items that could be incorporated
1353
+ * into the pourable.
1354
+ * */
1355
+ async setSelectedPourable({
1356
+ beverage: e,
1357
+ additional: t,
1358
+ context: r
1359
+ }) {
1360
+ if (!e) {
1361
+ const l = await Br(this.name);
1362
+ if ((l == null ? void 0 : l.status) !== 200)
1363
+ throw new Error("Failed to clear pourable");
1364
+ this._selectedBeverage = void 0;
1365
+ return;
1366
+ }
1367
+ if (e === this._selectedBeverage && Mt(this._additionalItems, t)) {
1368
+ this.logger.info("No change in selected pourable");
1369
+ return;
1370
+ }
1371
+ this._selectedBeverage = e, this._additionalItems = t;
1372
+ let a = await g.dataMapper.executeMapper(
1373
+ u.SelectedPourableMapper,
1374
+ {
1375
+ beverage: e,
1376
+ additional: t,
1377
+ context: r
1378
+ }
1379
+ );
1380
+ const i = {
1381
+ bevId: e.rawId
1382
+ };
1383
+ (!a || Object.keys(a).length === 0) && (this.logger.info(
1384
+ `No selected pourable mapper defined, using the default payload ${i}`
1385
+ ), a = i);
1386
+ const s = a ?? i, n = await Ar(this.name, s);
1387
+ if ((n == null ? void 0 : n.status) !== 200)
1388
+ throw new Error("Failed to select pourable");
1389
+ }
1390
+ /**
1391
+ * Utility method that will return the availability nodes that belong to the specified
1392
+ * group as defined in the dispenser beverage graph. For example, a dispenser
1393
+ * implementation may group availability nodes by Brand, Beverage, or Flavors
1394
+ *
1395
+ * @param groupId The group to filter by.
1396
+ * @returns The availability nodes that are available to be dispensed from this nozzle
1397
+ * and are in the specified group.
1398
+ * */
1399
+ getGroupAvailabilityItems(e) {
1400
+ return this._availabilityItems.getIndexByKey(
1401
+ "byGroup",
1402
+ e
1403
+ );
1404
+ }
1405
+ /**
1406
+ * Utility method that will return the availability nodes that are tagged with the specified parent id.
1407
+ *
1408
+ * This is useful when brandsets use the taggedIds property to associate nodes with a parent node. For example,
1409
+ * when organizing a brandset into brands and beverages, the brand nodes will be tagged with the beverage nodes.
1410
+ *
1411
+ * @param parentId - The parent id to filter by.
1412
+ * @returns the availability nodes that are tagged with the specified parent id.
1413
+ */
1414
+ getAvailabilityByParent(e) {
1415
+ return this._availabilityItems.getIndexByKey(
1416
+ "byParent",
1417
+ e
1418
+ );
1419
+ }
1420
+ updateIfCurrent(e, t) {
1421
+ this.currentState === e && h(() => {
1422
+ this.currentState = t;
1423
+ });
1424
+ }
1425
+ onFutureUpdate(e) {
1426
+ E(this).forEach((a) => {
1427
+ ie(a) && a.onPourProgress(e);
1428
+ });
1429
+ const r = {
1430
+ nozzleId: this.id,
1431
+ progress: e.progress,
1432
+ status: e.status,
1433
+ clientData: e.clientData,
1434
+ futureId: e.futureId,
1435
+ remainingTimeMs: e.remainingTimeMs,
1436
+ endState: e.endState,
1437
+ reason: e.reason,
1438
+ timeRemaining: e.timeRemaining
1439
+ };
1440
+ _.publish(jr, r), e.endState && h(() => {
1441
+ this.currentState = d.IDLE;
1442
+ });
1443
+ }
1444
+ async pour(e) {
1445
+ var t;
1446
+ try {
1447
+ if (this.currentState === d.IDLE) {
1448
+ if (this.updateIfCurrent(d.IDLE, d.POUR_STARTING), !e)
1449
+ throw new Error("No tracker provided");
1450
+ const r = await Lr(this.name, e);
1451
+ this.updateIfCurrent(d.POUR_STARTING, d.POURING), E(this).forEach((i) => {
1452
+ var s;
1453
+ ie(i) && ((s = i.onPourStart) == null || s.call(i));
1454
+ });
1455
+ const a = {
1456
+ nozzleId: this.id,
1457
+ type: "free"
1458
+ };
1459
+ if (_.publish(Le, a), (t = r == null ? void 0 : r.data) != null && t.endState) {
1460
+ this.updateIfCurrent(d.POURING, d.IDLE);
1461
+ const i = {
1462
+ nozzleId: this.id
1463
+ };
1464
+ _.publish(fe, i);
1465
+ }
1466
+ return r;
1467
+ } else
1468
+ throw new Error(`Cannot pour in state ${this.currentState}`);
1469
+ } catch (r) {
1470
+ throw this.logger.error(r), this.currentState = d.IDLE, r;
1471
+ }
1472
+ }
1473
+ async fixedPour(e, t) {
1474
+ var r;
1475
+ try {
1476
+ if (this.currentState === d.IDLE) {
1477
+ if (this.currentState = d.POUR_STARTING, !t)
1478
+ throw new Error("No tracker provided");
1479
+ const a = await xr(e, this.name, t);
1480
+ this.currentState === d.POUR_STARTING && h(() => {
1481
+ this.currentState = d.POURING;
1482
+ }), E(this).forEach((s) => {
1483
+ var n;
1484
+ ie(s) && ((n = s.onPourStart) == null || n.call(s));
1485
+ });
1486
+ const i = {
1487
+ nozzleId: this.id,
1488
+ type: "fixed"
1489
+ };
1490
+ if (_.publish(Le, i), (r = a == null ? void 0 : a.data) != null && r.endState) {
1491
+ this.updateIfCurrent(d.POURING, d.IDLE);
1492
+ const s = {
1493
+ nozzleId: this.id
1494
+ };
1495
+ _.publish(fe, s);
1496
+ }
1497
+ return a;
1498
+ } else
1499
+ throw new Error(`Cannot pour in state ${this.currentState}`);
1500
+ } catch (a) {
1501
+ throw this.logger.error(a), this.currentState = d.IDLE, a;
1502
+ }
1503
+ }
1504
+ /**
1505
+ * An action that will cancel a pour for this nozzle.
1506
+ * */
1507
+ async cancelPour() {
1508
+ var e;
1509
+ if (this.currentState === d.POURING || this.currentState === d.POUR_STARTING) {
1510
+ this.currentState = d.POUR_CANCELING, await ((e = this.futureHandler.getFuture()) == null ? void 0 : e.cancelFuture()), h(() => {
1511
+ this.currentState = d.IDLE;
1512
+ }), E(this).forEach((r) => {
1513
+ var a;
1514
+ ie(r) && ((a = r.onPourCancel) == null || a.call(r));
1515
+ });
1516
+ const t = {
1517
+ nozzleId: this.id
1518
+ };
1519
+ _.publish(fe, t);
1520
+ } else
1521
+ this.logger.warn(`Cannot cancel pour in state ${this.currentState}`);
1522
+ }
1523
+ updateGroupMembers() {
1524
+ this._availabilityItems.data.forEach((e) => {
1525
+ (e.taggedIds || []).forEach((r) => {
1526
+ const a = this._availabilityItems.data.find(
1527
+ (i) => i.rawId === r
1528
+ );
1529
+ a && a.parentId !== e.id && (a.parentId = e.id, this._availabilityItems.updateModel(a));
1530
+ });
1531
+ });
1532
+ }
1533
+ async reload() {
1534
+ this.logger.info(`reloading nozzle ${this.id}`);
1535
+ const e = ze.getContext(this.id);
1536
+ e != null && e.get(u.AvailabilityLoader);
1537
+ const t = await Ne(this.urlPrefix);
1538
+ if ((t == null ? void 0 : t.status) !== 200 || !(t != null && t.data)) {
1539
+ this.logger.error("Failed to load nozzle availability");
1540
+ return;
1541
+ }
1542
+ const r = t == null ? void 0 : t.data;
1543
+ r && await this.updateAvailability(r);
1544
+ }
1545
+ /** @internal */
1546
+ async load(e) {
1547
+ var a, i;
1548
+ this.logger.debug(`loading nozzle ${this.id}`);
1549
+ const t = await Ne(this.urlPrefix);
1550
+ if ((t == null ? void 0 : t.status) !== 200)
1551
+ throw new Error("Failed to load nozzle availability");
1552
+ const r = await g.loader.executeLoader(
1553
+ u.AvailabilityLoader,
1554
+ {}
1555
+ );
1556
+ e == null || e.set(u.AvailabilityLoader, r), e == null || e.set(Se.type, this);
1557
+ for (const s of Object.keys((a = t.data) == null ? void 0 : a.groups) || [])
1558
+ for (const n of ((i = t.data) == null ? void 0 : i.groups[s]) || []) {
1559
+ const l = await g.dataMapper.executeMapper(
1560
+ u.AvailabilityMapper,
1561
+ { ...n, groupId: s },
1562
+ r
1563
+ ), c = {
1564
+ ...n,
1565
+ note: n.note ?? void 0,
1566
+ kosParentId: this.id,
1567
+ rawId: n.id,
1568
+ groupId: s,
1569
+ data: l,
1570
+ properties: n.properties || {}
1571
+ }, p = _e.factory(
1572
+ `${this.id}-${s}-${n.id}`
1573
+ )(c);
1574
+ this._availabilityItems.addModel(p);
1575
+ }
1576
+ this.updateGroupMembers();
1577
+ }
1578
+ async updateAvailability(e) {
1579
+ const t = ze.getContext(this.id), r = (t == null ? void 0 : t.get(u.AvailabilityLoader)) || {};
1580
+ if (e.rebuild) {
1581
+ this.logger.info(
1582
+ `Received rebuild update for nozzle ${this.path}, rebuilding entire availability set`
1583
+ );
1584
+ for (const a of Object.keys(e == null ? void 0 : e.groups) || []) {
1585
+ this._availabilityItems.getIndexByKey("group", a).filter(
1586
+ (s) => !e.groups[a].find(
1587
+ (n) => `${this.id}-${a}-${n.id}` === s.id
1588
+ )
1589
+ ).forEach((s) => {
1590
+ this.logger.info(
1591
+ `Removing beverage ${s.id} from nozzle ${this.path} due to rebuild update`
1592
+ ), this._availabilityItems.removeModel(s.id), Ot(s);
1593
+ });
1594
+ for (const s of (e == null ? void 0 : e.groups[a]) || []) {
1595
+ const n = await g.dataMapper.executeMapper(
1596
+ u.AvailabilityMapper,
1597
+ { ...s, groupId: a },
1598
+ r
1599
+ ), l = {
1600
+ ...s,
1601
+ note: s.note ?? void 0,
1602
+ kosParentId: this.id,
1603
+ groupId: a,
1604
+ rawId: s.id,
1605
+ data: n,
1606
+ taggedIds: s.taggedIds,
1607
+ properties: s.properties || {}
1608
+ }, c = this._availabilityItems.getModel(
1609
+ `${this.id}-${a}-${s.id}`
1610
+ );
1611
+ if (c)
1612
+ c.available !== l.available && this.logger.info(
1613
+ `Updating availability of beverage ${c.id} in nozzle ${this.path} to ${l.available}`
1614
+ ), c.updateModel(l);
1615
+ else {
1616
+ this.logger.info(
1617
+ `Adding beverage ${s.id} to nozzle ${this.path}`
1618
+ );
1619
+ const p = _e.factory(
1620
+ `${this.id}-${a}-${s.id}`
1621
+ )(l);
1622
+ this._availabilityItems.addModel(p);
1623
+ }
1624
+ }
1625
+ }
1626
+ } else {
1627
+ this.logger.info(
1628
+ `Received delta update for nozzle ${this.path}, updating availability nodes`
1629
+ );
1630
+ for (const a of Object.keys(e == null ? void 0 : e.groups) || [])
1631
+ for (const i of (e == null ? void 0 : e.groups[a]) || []) {
1632
+ const s = await g.dataMapper.executeMapper(
1633
+ u.AvailabilityMapper,
1634
+ { ...i, groupId: a },
1635
+ r
1636
+ ), n = {
1637
+ ...i,
1638
+ note: i.note ?? void 0,
1639
+ kosParentId: this.id,
1640
+ groupId: a,
1641
+ rawId: i.id,
1642
+ data: s,
1643
+ type: i.type,
1644
+ taggedIds: i.taggedIds,
1645
+ properties: i.properties || {}
1646
+ }, l = this._availabilityItems.getModel(
1647
+ `${this.id}-${a}-${i.id}`
1648
+ );
1649
+ l && (l.available !== n.available && this.logger.info(
1650
+ `Updating availability of beverage ${l.id} in nozzle ${this.path} to ${n.available}`
1651
+ ), l.updateModel(n));
1652
+ }
1653
+ }
1654
+ this.updateGroupMembers();
1655
+ }
1656
+ // -------------------ENTITY----------------------------
1657
+ };
1658
+ te([
1659
+ M
1660
+ ], $.prototype, "_availabilityItems", 2);
1661
+ te([
1662
+ ue()
1663
+ ], $.prototype, "pour", 1);
1664
+ te([
1665
+ ue()
1666
+ ], $.prototype, "fixedPour", 1);
1667
+ te([
1668
+ Q({
1669
+ topic: `${Fr}/availability`,
1670
+ websocket: !0
1671
+ })
1672
+ ], $.prototype, "updateAvailability", 1);
1673
+ $ = te([
1674
+ I(J)
1675
+ ], $);
1676
+ const Se = {
1677
+ registration: {
1678
+ [J]: {
1679
+ class: $,
1680
+ singleton: !1
1681
+ }
1682
+ },
1683
+ type: J,
1684
+ predicate: P(J),
1685
+ factory: v.Factory.create(J)
1686
+ };
1687
+ var Hr = Object.defineProperty, Kr = Object.getOwnPropertyDescriptor, dt = (e, t, r, a) => {
1688
+ for (var i = a > 1 ? void 0 : a ? Kr(t, r) : t, s = e.length - 1, n; s >= 0; s--)
1689
+ (n = e[s]) && (i = (a ? n(t, r, i) : n(i)) || i);
1690
+ return a && i && Hr(t, r, i), i;
1691
+ };
1692
+ const lt = "device-assembly-model";
1693
+ let de = class {
1694
+ constructor(e, t, r) {
1695
+ o(this, "id");
1696
+ o(this, "deviceNozzles");
1697
+ o(this, "logger");
1698
+ this.id = e, this.logger = r.logger, this.deviceNozzles = new R();
1699
+ }
1700
+ // -------------------LIFECYCLE----------------------------
1701
+ async init() {
1702
+ this.logger.debug(`initializing device-assembly ${this.id}`);
1703
+ }
1704
+ getNozzle(e) {
1705
+ return this.deviceNozzles.getModel(e);
1706
+ }
1707
+ get nozzlePaths() {
1708
+ return this.deviceNozzles.data.map((e) => e.path);
1709
+ }
1710
+ async load() {
1711
+ this.logger.debug(`loading device-assembly ${this.id}`);
1712
+ const e = await Je();
1713
+ (e == null ? void 0 : e.status) === 200 && e.data.assemblies.map((r) => r.nozzles ?? []).flat().forEach((r) => {
1714
+ var n;
1715
+ const a = r.path, i = ((n = r.pipelines.find((l) => l.name === "beverage")) == null ? void 0 : n.topicPrefix) || "", s = Se.factory(a)({
1716
+ path: r.path,
1717
+ name: r.name,
1718
+ urlPrefix: r.urlPrefix,
1719
+ topicPrefix: r.topicPrefix,
1720
+ beverageTopicPrefix: i
1721
+ });
1722
+ this.deviceNozzles.addModel(s);
1723
+ });
1724
+ }
1725
+ };
1726
+ dt([
1727
+ M
1728
+ ], de.prototype, "deviceNozzles", 2);
1729
+ de = dt([
1730
+ I(lt)
1731
+ ], de);
1732
+ const Vr = new Et({
1733
+ class: de,
1734
+ type: lt
1735
+ }), { URL: ct } = S("GENERIC_POUR_SERVICE"), { postModel: kr } = C.build({
1736
+ basePath: `${ct}/api/nozzle`
1737
+ }), Yr = async (e, t) => {
1738
+ const r = await kr({
1739
+ model: {},
1740
+ urlOverride: `${ct}${e}`,
1741
+ ordered: !0,
1742
+ tracker: t
1743
+ });
1744
+ return r != null && r.data && pe.initiateFuture(r.data), r;
1745
+ };
1746
+ var Zr = Object.defineProperty, Xr = Object.getOwnPropertyDescriptor, pt = (e, t, r, a) => {
1747
+ for (var i = a > 1 ? void 0 : a ? Xr(t, r) : t, s = e.length - 1, n; s >= 0; s--)
1748
+ (n = e[s]) && (i = (a ? n(t, r, i) : n(i)) || i);
1749
+ return a && i && Zr(t, r, i), i;
1750
+ };
1751
+ const ut = "generic-pour-model", Jr = "/kos/generic/pour/started", qr = "/kos/generic/pour/progress", xe = "/kos/generic/pour/cancel", me = (e) => e.onPourStart !== void 0 && e.onPourCancel !== void 0 && e.onPourProgress !== void 0;
1752
+ let le = class {
1753
+ constructor(e, t, r) {
1754
+ o(this, "id");
1755
+ o(this, "currentState", d.IDLE);
1756
+ o(this, "servicePathFactory");
1757
+ o(this, "pourType");
1758
+ o(this, "logger");
1759
+ o(this, "futureHandler");
1760
+ o(this, "selectedId");
1761
+ this.id = e, this.logger = r.logger, this.futureHandler = new je(this), this.servicePathFactory = t.servicePathFactory, this.pourType = t.pourType || "free", this.selectedId = t.selectedId;
1762
+ }
1763
+ get servicePath() {
1764
+ return this.selectedId ? this.servicePathFactory(this.selectedId) : "";
1765
+ }
1766
+ async pour(e) {
1767
+ var t;
1768
+ try {
1769
+ if (this.currentState === d.IDLE) {
1770
+ if (this.updateIfCurrent(d.IDLE, d.POUR_STARTING), !e)
1771
+ throw new Error("No tracker provided");
1772
+ const r = await Yr(this.servicePath, e);
1773
+ this.updateIfCurrent(d.POUR_STARTING, d.POURING), E(this).forEach((i) => {
1774
+ var s;
1775
+ me(i) && ((s = i.onPourStart) == null || s.call(i));
1776
+ });
1777
+ const a = {
1778
+ pourTarget: this.id,
1779
+ type: this.pourType
1780
+ };
1781
+ if (_.publish(Jr, a), (t = r == null ? void 0 : r.data) != null && t.endState) {
1782
+ this.updateIfCurrent(d.POURING, d.IDLE);
1783
+ const i = {
1784
+ pourTarget: this.id
1785
+ };
1786
+ _.publish(xe, i);
1787
+ }
1788
+ return r;
1789
+ } else
1790
+ throw new Error(`Cannot pour in state ${this.currentState}`);
1791
+ } catch (r) {
1792
+ throw this.logger.error(r), this.currentState = d.IDLE, r;
1793
+ }
1794
+ }
1795
+ async cancelPour() {
1796
+ var e;
1797
+ if (this.currentState === d.POURING || this.currentState === d.POUR_STARTING) {
1798
+ this.currentState = d.POUR_CANCELING, await ((e = this.futureHandler.getFuture()) == null ? void 0 : e.cancelFuture()), h(() => {
1799
+ this.currentState = d.IDLE;
1800
+ }), E(this).forEach((r) => {
1801
+ var a;
1802
+ me(r) && ((a = r.onPourCancel) == null || a.call(r));
1803
+ });
1804
+ const t = {
1805
+ pourTarget: this.id
1806
+ };
1807
+ _.publish(xe, t);
1808
+ }
1809
+ this.currentState === d.IDLE ? this.logger.info("Pour already idle, nothing to cancel.") : this.logger.warn(`Cannot cancel pour in state ${this.currentState}`);
1810
+ }
1811
+ updateIfCurrent(e, t) {
1812
+ this.currentState === e && h(() => {
1813
+ this.currentState = t;
1814
+ });
1815
+ }
1816
+ /**
1817
+ * A derived value that indicates if the nozzle is currently pouring a beverage.
1818
+ * @readonly
1819
+ */
1820
+ get isPouring() {
1821
+ var e;
1822
+ 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;
1823
+ }
1824
+ /**
1825
+ * A derived value that indicates if the pour target is currently available to pour a beverage.
1826
+ *
1827
+ * Generally this means that the pour target is currently idle and not in the process of pouring, initiating a pour, or canceling a pour.
1828
+ * The value is observable and will change when the selected pourable changes or the pour target
1829
+ * starts or stops pouring.
1830
+ * @readonly
1831
+ * */
1832
+ get canPour() {
1833
+ return this.currentState === d.IDLE;
1834
+ }
1835
+ get future() {
1836
+ return this.futureHandler.getFuture();
1837
+ }
1838
+ get pourProgress() {
1839
+ var e;
1840
+ return ((e = this.future) == null ? void 0 : e.progress) ?? 0;
1841
+ }
1842
+ onFutureUpdate(e) {
1843
+ E(this).forEach((r) => {
1844
+ me(r) && r.onPourProgress(e);
1845
+ });
1846
+ const t = {
1847
+ pourTarget: this.id,
1848
+ progress: e.progress,
1849
+ status: e.status,
1850
+ clientData: e.clientData,
1851
+ futureId: e.futureId,
1852
+ remainingTimeMs: e.remainingTimeMs,
1853
+ endState: e.endState,
1854
+ reason: e.reason,
1855
+ timeRemaining: e.timeRemaining
1856
+ };
1857
+ _.publish(qr, t), e.endState && h(() => {
1858
+ this.currentState = d.IDLE;
1859
+ });
1860
+ }
1861
+ // -------------------LIFECYCLE----------------------------
1862
+ async init() {
1863
+ this.logger.debug(`initializing generic-pour ${this.id}`);
1864
+ }
1865
+ async load() {
1866
+ this.logger.debug(`loading generic-pour ${this.id}`);
1867
+ }
1868
+ };
1869
+ pt([
1870
+ ue()
1871
+ ], le.prototype, "pour", 1);
1872
+ le = pt([
1873
+ I(ut)
1874
+ ], le);
1875
+ const ni = new wt({
1876
+ class: le,
1877
+ type: ut
1878
+ }), Ae = {
1879
+ ...ke.registration,
1880
+ ...He.registration,
1881
+ ...at.registration,
1882
+ ...Xe.registration,
1883
+ ...Se.registration,
1884
+ ...st.registration,
1885
+ ...Oe.registration,
1886
+ ..._e.registration,
1887
+ ...ot.registration,
1888
+ ...it.registration
1889
+ }, Wr = (e) => () => (St(e)(), Vr.register(), Object.keys(Ae).forEach((t) => {
1890
+ const r = Ae[t];
1891
+ Ct(e)(t, r);
1892
+ }), g[W].register(
1893
+ "FirmwareUpdateInProgressTrouble",
1894
+ async (t) => {
1895
+ var r;
1896
+ if ((r = t.data) != null && r.deviceId) {
1897
+ const { model: a } = N(
1898
+ ot.type
1899
+ );
1900
+ if (a) {
1901
+ const i = a.boards.find(
1902
+ (s) => s.id === t.data.deviceId
1903
+ ) ? N(t.data.deviceId).model : void 0;
1904
+ return {
1905
+ devices: i ? i.name : ""
1906
+ };
1907
+ }
1908
+ }
1909
+ return {};
1910
+ }
1911
+ ), {
1912
+ preload: O.model.preloadModel(e),
1913
+ model: O.model.register(e),
1914
+ companion: O.companion.register(e),
1915
+ legacy: O.model.registerLegacyModel(e)
1916
+ }), b = {
1917
+ ...$t
1918
+ };
1919
+ b.dispense = {
1920
+ models: Wr(b)
1921
+ };
1922
+ b.preload = O.model.preloadModel(b);
1923
+ b.model = O.model.register(b);
1924
+ b.companion = O.companion.register(b);
1925
+ b.legacy = O.model.registerLegacyModel(b);
1926
+ const oi = b;
1927
+ export {
1928
+ ot as A,
1929
+ x as B,
1930
+ Cr as C,
1931
+ z as D,
1932
+ u as E,
1933
+ Ne as F,
1934
+ ni as G,
1935
+ Xe as H,
1936
+ He as I,
1937
+ xr as J,
1938
+ oi as K,
1939
+ Lr as L,
1940
+ Ar as M,
1941
+ Se as N,
1942
+ Yr as O,
1943
+ st as P,
1944
+ qe as T,
1945
+ Rr as a,
1946
+ _e as b,
1947
+ We as c,
1948
+ it as d,
1949
+ rt as e,
1950
+ Vr as f,
1951
+ at as g,
1952
+ ke as h,
1953
+ Oe as i,
1954
+ et as j,
1955
+ Ae as k,
1956
+ d as l,
1957
+ Tt as m,
1958
+ ai as n,
1959
+ Gt as o,
1960
+ si as p,
1961
+ ii as q,
1962
+ Wr as r,
1963
+ ri as s,
1964
+ jt as t,
1965
+ Vt as u,
1966
+ Ft as v,
1967
+ Je as w,
1968
+ _r as x,
1969
+ Pr as y,
1970
+ Br as z
1971
+ };
1972
+ //# sourceMappingURL=dispense-registration-manager-o2X21qmP.js.map