@kosdev-code/kos-dispense-sdk 2.1.37 → 2.1.39

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 (65) hide show
  1. package/dispense-registration-manager-C6k10ipu.cjs +2698 -0
  2. package/dispense-registration-manager-C6k10ipu.cjs.map +1 -0
  3. package/dispense-registration-manager-lJlcyq5G.js +2700 -0
  4. package/dispense-registration-manager-lJlcyq5G.js.map +1 -0
  5. package/{extension-utils-CKwcGuFf.js → extension-utils-AS0Z5eod.js} +194 -157
  6. package/{extension-utils-CKwcGuFf.js.map → extension-utils-AS0Z5eod.js.map} +1 -1
  7. package/extension-utils-DNbm2KRk.cjs +500 -0
  8. package/{extension-utils-BDyaRwRN.cjs.map → extension-utils-DNbm2KRk.cjs.map} +1 -1
  9. package/extensions/control-pour-extension.d.ts +16 -16
  10. package/index.cjs +142 -1
  11. package/index.cjs.map +1 -1
  12. package/index.d.ts +2 -2
  13. package/index.d.ts.map +1 -1
  14. package/index.js +125 -120
  15. package/index.js.map +1 -1
  16. package/kos-models.json +1 -1
  17. package/models/models/assembly/assembly-model.d.ts +4 -0
  18. package/models/models/assembly/assembly-model.d.ts.map +1 -1
  19. package/models/models/assembly/holder-utils.d.ts.map +1 -1
  20. package/models/models/availability/availability-model.d.ts.map +1 -1
  21. package/models/models/board/board-container-model.d.ts +4 -0
  22. package/models/models/board/board-container-model.d.ts.map +1 -1
  23. package/models/models/board/board-model.d.ts +4 -0
  24. package/models/models/board/board-model.d.ts.map +1 -1
  25. package/models/models/device-assembly/device-assembly-model.d.ts +4 -0
  26. package/models/models/device-assembly/device-assembly-model.d.ts.map +1 -1
  27. package/models/models/generic-pour/generic-pour-model.d.ts +34 -0
  28. package/models/models/generic-pour/generic-pour-model.d.ts.map +1 -1
  29. package/models/models/holder/holder-model.d.ts.map +1 -1
  30. package/models/models/holder/types/index.d.ts +2 -0
  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/nozzle-model.d.ts +16 -0
  35. package/models/models/nozzle/nozzle-model.d.ts.map +1 -1
  36. package/models/models/pump/pump-model.d.ts.map +1 -1
  37. package/models/models/pump-container/pump-container-model.d.ts.map +1 -1
  38. package/models/models/types/assembly.d.ts +1 -0
  39. package/models/models/types/assembly.d.ts.map +1 -1
  40. package/models/utils/service.d.ts +4 -0
  41. package/models/utils/service.d.ts.map +1 -1
  42. package/models/utils/services/dispense/1.6.5/service.d.ts +4 -0
  43. package/models/utils/services/dispense/1.6.5/service.d.ts.map +1 -1
  44. package/models/utils/services/dispense/1.8.1/service.d.ts +4 -0
  45. package/models/utils/services/dispense/1.8.1/service.d.ts.map +1 -1
  46. package/models/utils/services/dispense/daily/service.d.ts +4 -0
  47. package/models/utils/services/dispense/daily/service.d.ts.map +1 -1
  48. package/models.cjs +47 -1
  49. package/models.cjs.map +1 -1
  50. package/models.js +40 -40
  51. package/package.json +15 -2
  52. package/pump-provider-BSEusYig.js +1825 -0
  53. package/{pump-provider-Ch6zq4Sj.js.map → pump-provider-BSEusYig.js.map} +1 -1
  54. package/pump-provider-D4Ed_gH6.cjs +1824 -0
  55. package/{pump-provider-CTELJBW5.cjs.map → pump-provider-D4Ed_gH6.cjs.map} +1 -1
  56. package/ui.cjs +73 -1
  57. package/ui.cjs.map +1 -1
  58. package/ui.js +67 -67
  59. package/dispense-registration-manager-BCQZ-87v.js +0 -2020
  60. package/dispense-registration-manager-BCQZ-87v.js.map +0 -1
  61. package/dispense-registration-manager-Cj0565Ze.cjs +0 -2
  62. package/dispense-registration-manager-Cj0565Ze.cjs.map +0 -1
  63. package/extension-utils-BDyaRwRN.cjs +0 -2
  64. package/pump-provider-CTELJBW5.cjs +0 -2
  65. package/pump-provider-Ch6zq4Sj.js +0 -1308
@@ -0,0 +1,2700 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => {
4
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+ return value;
6
+ };
7
+ import { kosModel, Kos, isKosModel, resolveServiceUrl, ServiceFactory, KosLog, KosModelContainer, KosExtensionUtils, kosChild, FetchError, ExtensionManager, EXTENSION_TROUBLE_MAPPER, EXTENSION_TROUBLE_DATA_MAPPER, getKosModelSync, kosDependency, kosTroubleAware, kosAction, kosTopicHandler, DependencyLifecycle, getKosModel, FutureManager, kosFuture, FutureHandler, EXTENSION_FEATURE_FLAG_RESOLVER, isKosDataModel, ChildModels, KosFeatureFlags, kosParentAware, createPropKey, kosStateEntry, kosStateExit, kosStateGuard, kosLoggerAware, kosStateMachine, MultipleFutureHandler, arraysEqual, getAllKosCompanionModels, EventBus, KosContextManager, destroyKosModel, SingletonKosModelRegistrationFactory, kosFutureAware, ObservableData, KosModelRegistrationFactory, KosModelRegistry as KosModelRegistry$1, RegistrationManager, registerCoreModels, registerLegacyModel } from "@kosdev-code/kos-ui-sdk";
8
+ import "react";
9
+ var ExtensionType = /* @__PURE__ */ ((ExtensionType2) => {
10
+ ExtensionType2["IngredientLoader"] = "kos.ingredient.loader";
11
+ ExtensionType2["IngredientMapper"] = "kos.ingredient.mapper";
12
+ ExtensionType2["IngredientIndex"] = "kos.ingredient.index";
13
+ ExtensionType2["IngredientTypeMapper"] = "kos.ingredient.type.mapper";
14
+ ExtensionType2["HolderTypeMapper"] = "kos.holder.type.mapper";
15
+ ExtensionType2["HolderMapper"] = "kos.holder.mapper";
16
+ ExtensionType2["HolderIndex"] = "kos.holder.index";
17
+ ExtensionType2["HolderIngredientMapper"] = "kos.holder.ingredient.mapper";
18
+ ExtensionType2["AvailabilityMapper"] = "kos.availability.mapper";
19
+ ExtensionType2["AvailabilityLoader"] = "kos.availability.loader";
20
+ ExtensionType2["SelectedPourableMapper"] = "kos.selected.pourable.mapper";
21
+ ExtensionType2["AssemblyMapper"] = "kos.assembly.mapper";
22
+ ExtensionType2["BoardMapper"] = "kos.board.mapper";
23
+ ExtensionType2["BoardIndex"] = "kos.board.index";
24
+ ExtensionType2["PumpIndex"] = "kos.pump.index";
25
+ ExtensionType2["AssemblyFeatureFlags"] = "kos.assembly.feature.flags";
26
+ return ExtensionType2;
27
+ })(ExtensionType || {});
28
+ var DispenseModelType = /* @__PURE__ */ ((DispenseModelType2) => {
29
+ DispenseModelType2["Nozzle"] = "nozzle-model";
30
+ DispenseModelType2["Availability"] = "availability-model";
31
+ DispenseModelType2["Holder"] = "holder-model";
32
+ DispenseModelType2["HolderContainer"] = "holder-container-model";
33
+ DispenseModelType2["IngredientContainer"] = "ingredient-container-model";
34
+ DispenseModelType2["Ingredient"] = "ingredient-model";
35
+ DispenseModelType2["Pump"] = "pump-model";
36
+ DispenseModelType2["PumpContainer"] = "pump-container-model";
37
+ return DispenseModelType2;
38
+ })(DispenseModelType || {});
39
+ var __getOwnPropDesc$c = Object.getOwnPropertyDescriptor;
40
+ var __decorateClass$c = (decorators, target, key, kind) => {
41
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$c(target, key) : target;
42
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
43
+ if (decorator = decorators[i])
44
+ result = decorator(result) || result;
45
+ return result;
46
+ };
47
+ const MODEL_TYPE$c = "ingredient-model";
48
+ let IngredientModelImpl = class {
49
+ constructor(modelId, {
50
+ name,
51
+ type,
52
+ data,
53
+ ingredientId,
54
+ ...rest
55
+ }) {
56
+ __publicField(this, "id");
57
+ __publicField(this, "ingredientId");
58
+ __publicField(this, "name");
59
+ __publicField(this, "type");
60
+ __publicField(this, "data");
61
+ this.id = modelId;
62
+ this.ingredientId = ingredientId;
63
+ this.name = name;
64
+ this.type = type;
65
+ this.data = data;
66
+ Object.assign(this, rest);
67
+ }
68
+ updateModel({
69
+ name,
70
+ type,
71
+ data,
72
+ ingredientId,
73
+ ...rest
74
+ }) {
75
+ this.name = name;
76
+ this.type = type;
77
+ this.ingredientId = ingredientId;
78
+ this.data = data;
79
+ Object.assign(this, rest);
80
+ }
81
+ // -------------------LIFECYCLE----------------------------
82
+ // -------------------ENTITY----------------------------
83
+ };
84
+ IngredientModelImpl = __decorateClass$c([
85
+ kosModel(MODEL_TYPE$c)
86
+ ], IngredientModelImpl);
87
+ const Ingredient = {
88
+ registration: {
89
+ [MODEL_TYPE$c]: {
90
+ class: IngredientModelImpl,
91
+ singleton: false
92
+ }
93
+ },
94
+ type: MODEL_TYPE$c,
95
+ predicate: isKosModel(MODEL_TYPE$c),
96
+ factory: Kos.Factory.create(MODEL_TYPE$c)
97
+ };
98
+ const { URL: URL$6 } = resolveServiceUrl("INGREDIENT_SERVICE");
99
+ const { getOne: getOne$3 } = ServiceFactory.build({
100
+ basePath: `${URL$6}/api/ext/dispense/ingredients`
101
+ });
102
+ const getIngredients = async () => {
103
+ const response = await getOne$3({
104
+ urlOverride: `${URL$6}/api/ext/dispense/ingredients`
105
+ });
106
+ return response;
107
+ };
108
+ var __defProp$9 = Object.defineProperty;
109
+ var __getOwnPropDesc$b = Object.getOwnPropertyDescriptor;
110
+ var __decorateClass$b = (decorators, target, key, kind) => {
111
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$b(target, key) : target;
112
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
113
+ if (decorator = decorators[i])
114
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
115
+ if (kind && result)
116
+ __defProp$9(target, key, result);
117
+ return result;
118
+ };
119
+ const MODEL_TYPE$b = "ingredient-container-model";
120
+ const log$3 = KosLog.createLogger({ name: "ingredient-container-model" });
121
+ let IngredientContainerModelImpl = class {
122
+ constructor(modelId, options) {
123
+ __publicField(this, "id");
124
+ __publicField(this, "ingredients");
125
+ this.id = modelId;
126
+ this.ingredients = new KosModelContainer({
127
+ indexMap: {
128
+ ingredientType: "type"
129
+ },
130
+ extensionId: ExtensionType.IngredientIndex,
131
+ parentId: modelId
132
+ });
133
+ }
134
+ updateModel() {
135
+ }
136
+ // -------------------LIFECYCLE----------------------------
137
+ getIngredientsByType(type) {
138
+ return this.ingredients.getIndexByKey("ingredientType", type);
139
+ }
140
+ async load(context) {
141
+ var _a;
142
+ log$3.debug(`loading ingredient container ${this.id}`);
143
+ const allIngredients = await getIngredients();
144
+ if ((allIngredients == null ? void 0 : allIngredients.status) !== 200) {
145
+ throw new Error("Failed to load ingredients");
146
+ }
147
+ const ingredientContext = await KosExtensionUtils.executeLoaderExtension({
148
+ context,
149
+ extension: ExtensionType.IngredientLoader
150
+ });
151
+ const ingredientData = (allIngredients == null ? void 0 : allIngredients.data) ?? {};
152
+ for (const key of Object.keys(ingredientData)) {
153
+ for (const ingredientData2 of ((_a = allIngredients == null ? void 0 : allIngredients.data) == null ? void 0 : _a[key]) || []) {
154
+ const data = await KosExtensionUtils.executeDataMapperExtension({
155
+ extension: ExtensionType.IngredientMapper,
156
+ data: ingredientData2,
157
+ contextData: ingredientContext
158
+ });
159
+ const type = await KosExtensionUtils.executePropertyMapperExtension({
160
+ extension: ExtensionType.IngredientTypeMapper,
161
+ data: ingredientData2,
162
+ contextData: ingredientContext
163
+ });
164
+ const ingredientOptions = {
165
+ ...ingredientData2,
166
+ type: type || ingredientData2.type,
167
+ ...data,
168
+ data
169
+ };
170
+ const ingredient = Ingredient.factory(ingredientData2.id)(
171
+ ingredientOptions
172
+ );
173
+ this.ingredients.addModel(ingredient);
174
+ }
175
+ }
176
+ }
177
+ // -------------------ENTITY----------------------------
178
+ };
179
+ __decorateClass$b([
180
+ kosChild
181
+ ], IngredientContainerModelImpl.prototype, "ingredients", 2);
182
+ IngredientContainerModelImpl = __decorateClass$b([
183
+ kosModel(MODEL_TYPE$b)
184
+ ], IngredientContainerModelImpl);
185
+ const IngredientContainer = {
186
+ registration: {
187
+ [MODEL_TYPE$b]: {
188
+ class: IngredientContainerModelImpl,
189
+ singleton: true
190
+ }
191
+ },
192
+ type: MODEL_TYPE$b,
193
+ predicate: isKosModel(MODEL_TYPE$b),
194
+ factory: Kos.Singleton.create(MODEL_TYPE$b)
195
+ };
196
+ const { URL: URL$5 } = resolveServiceUrl("HOLDER_SERVICE");
197
+ const { getAll: getAll$1, postModel: postModel$4, deleteModel: deleteModel$2 } = ServiceFactory.build({
198
+ basePath: `${URL$5}/api/kos/holders`
199
+ });
200
+ const log$2 = KosLog.createLogger({
201
+ name: "holder-service",
202
+ group: "Services"
203
+ });
204
+ const getHolders = async () => {
205
+ const response = await getAll$1({});
206
+ return response;
207
+ };
208
+ const assignHolderIngredient = async (holderPath, ingredientId) => {
209
+ if (!holderPath || !ingredientId) {
210
+ throw new Error("Missing holderPath or ingredientId");
211
+ }
212
+ const response = await postModel$4({
213
+ model: { holderPath, ingredientId },
214
+ urlOverride: `${URL$5}/api/ext/dispense/assignments`
215
+ });
216
+ return response;
217
+ };
218
+ const unassignHolderIngredient = async (holderPath) => {
219
+ if (!holderPath) {
220
+ throw new Error("Missing holderPath");
221
+ }
222
+ const response = await deleteModel$2({
223
+ id: holderPath,
224
+ urlOverride: `${URL$5}/api/ext/dispense/assignments/${holderPath}`
225
+ });
226
+ return response;
227
+ };
228
+ const replaceLine = async (holderPath) => {
229
+ if (!holderPath)
230
+ throw new Error("Missing holderPath");
231
+ log$2.debug(
232
+ `sending POST request to /api/ext/dispense/pumpEvents/replaceLine/${holderPath}`
233
+ );
234
+ const response = await postModel$4({
235
+ model: {},
236
+ urlOverride: `${URL$5}/api/ext/dispense/pumpEvents/replaceLine/${holderPath}`
237
+ });
238
+ return response;
239
+ };
240
+ const { URL: URL$4 } = resolveServiceUrl("ASSIGNMENT_SERVICE");
241
+ const { getAll, postModel: postModel$3, deleteModel: deleteModel$1 } = ServiceFactory.build({
242
+ destinationAddress: "",
243
+ basePath: `${URL$4}/api/ext/dispense/assignments`
244
+ });
245
+ const useFos = window.kosUseFos;
246
+ const getAssignments = async () => {
247
+ const response = await getAll({ fos: useFos });
248
+ return response;
249
+ };
250
+ const sendRfidOverride = async (holderPath, overrides) => {
251
+ var _a, _b, _c, _d;
252
+ const factoryJson = JSON.stringify(overrides);
253
+ const url = `${URL$4}/api/ext/dispense/assignments`;
254
+ try {
255
+ const response = await postModel$3({
256
+ model: { holderPath, factoryJson },
257
+ urlOverride: url
258
+ });
259
+ if ((response == null ? void 0 : response.status) === 200 && ((_a = response == null ? void 0 : response.data) == null ? void 0 : _a.error)) {
260
+ return [response.data.error || "unknownError", response.data];
261
+ }
262
+ return [void 0, response == null ? void 0 : response.data];
263
+ } catch (error) {
264
+ if (error instanceof FetchError) {
265
+ return [
266
+ ((_c = (_b = error.payload) == null ? void 0 : _b.data) == null ? void 0 : _c.error) || "unknownError",
267
+ (_d = error.payload) == null ? void 0 : _d.data
268
+ ];
269
+ }
270
+ }
271
+ return ["unknownError", void 0];
272
+ };
273
+ const addAssignment = async (assignment) => {
274
+ const url = useFos ? `${URL$4}/api/ingredients/assignments/${assignment.holderPath}` : `${URL$4}/api/ext/dispense/assignments`;
275
+ const response = await postModel$3({
276
+ model: { ...assignment, fuelGauge: 680 },
277
+ fos: useFos,
278
+ urlOverride: url
279
+ });
280
+ return response;
281
+ };
282
+ const deleteAssignment = async (id) => {
283
+ const response = await deleteModel$1({ id, fos: useFos });
284
+ return response;
285
+ };
286
+ var __defProp$8 = Object.defineProperty;
287
+ var __getOwnPropDesc$a = Object.getOwnPropertyDescriptor;
288
+ var __decorateClass$a = (decorators, target, key, kind) => {
289
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$a(target, key) : target;
290
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
291
+ if (decorator = decorators[i])
292
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
293
+ if (kind && result)
294
+ __defProp$8(target, key, result);
295
+ return result;
296
+ };
297
+ const MODEL_TYPE$a = DispenseModelType.Holder;
298
+ const log$1 = KosLog.createLogger({ name: "holder-model" });
299
+ ExtensionManager[EXTENSION_TROUBLE_MAPPER].register(
300
+ "holder",
301
+ async (trouble) => {
302
+ const result = [];
303
+ result.push(...trouble.data.holderPaths);
304
+ return result;
305
+ }
306
+ );
307
+ ExtensionManager[EXTENSION_TROUBLE_DATA_MAPPER].register(
308
+ "pump",
309
+ async (trouble) => {
310
+ if (trouble.data.pumpPath) {
311
+ const { model: pumpModel } = getKosModelSync(
312
+ trouble.data.pumpPath
313
+ );
314
+ if (pumpModel) {
315
+ const ingredientModel = pumpModel.ingredientId ? getKosModelSync(pumpModel.ingredientId).model : void 0;
316
+ return {
317
+ ingredientId: pumpModel.ingredientId,
318
+ ingredientName: (ingredientModel == null ? void 0 : ingredientModel.displayName) ?? ((ingredientModel == null ? void 0 : ingredientModel.name) || ""),
319
+ childPumpName: pumpModel.name
320
+ };
321
+ }
322
+ }
323
+ return {};
324
+ }
325
+ );
326
+ ExtensionManager[EXTENSION_TROUBLE_DATA_MAPPER].register(
327
+ "holder",
328
+ async (trouble) => {
329
+ if (trouble.data.holderNames.length > 0) {
330
+ const holderName = trouble.data.holderNames[0];
331
+ return {
332
+ holderName: holderName || ""
333
+ };
334
+ }
335
+ return {};
336
+ }
337
+ );
338
+ ExtensionManager[EXTENSION_TROUBLE_DATA_MAPPER].register(
339
+ "container",
340
+ async (trouble) => {
341
+ if (trouble.data.ingredients.length > 0) {
342
+ const ingredientId = trouble.data.ingredients[0];
343
+ const { model } = getKosModelSync(ingredientId);
344
+ return {
345
+ ingredientName: (model == null ? void 0 : model.displayName) ?? ((model == null ? void 0 : model.name) || ""),
346
+ ingredients: trouble.data.ingredients ? trouble.data.ingredients : [],
347
+ unknonwnIngredientId: trouble.data.unknonwnIngredientId ?? ""
348
+ };
349
+ }
350
+ return {};
351
+ }
352
+ );
353
+ class AssignmentError extends Error {
354
+ constructor(type, message) {
355
+ super(message);
356
+ __publicField(this, "type");
357
+ this.name = "AssignmentError";
358
+ this.type = type;
359
+ }
360
+ }
361
+ let HolderModelImpl = class {
362
+ constructor(modelId, {
363
+ path,
364
+ name,
365
+ ingredientSource,
366
+ ingredientId,
367
+ ingredientType,
368
+ slice,
369
+ group,
370
+ data,
371
+ enjoyByDate,
372
+ attributes
373
+ }, context) {
374
+ __publicField(this, "id");
375
+ __publicField(this, "path");
376
+ __publicField(this, "name");
377
+ __publicField(this, "ingredientId");
378
+ __publicField(this, "ingredientType");
379
+ __publicField(this, "ingredientSource");
380
+ __publicField(this, "group");
381
+ __publicField(this, "slice");
382
+ __publicField(this, "logger");
383
+ __publicField(this, "data");
384
+ __publicField(this, "enjoyByDate");
385
+ __publicField(this, "attributes");
386
+ __publicField(this, "pumps");
387
+ __publicField(this, "ingredientContainer");
388
+ this.id = modelId;
389
+ this.path = path;
390
+ this.name = name;
391
+ this.ingredientType = ingredientType;
392
+ this.ingredientSource = ingredientSource;
393
+ this.ingredientId = ingredientId;
394
+ this.group = group;
395
+ this.slice = slice;
396
+ this.enjoyByDate = enjoyByDate;
397
+ this.data = data;
398
+ this.pumps = new KosModelContainer({
399
+ parentId: modelId,
400
+ sortKey: "path"
401
+ });
402
+ this.attributes = attributes || {};
403
+ this.logger = context.logger;
404
+ }
405
+ updateModel({
406
+ path,
407
+ name,
408
+ ingredientSource,
409
+ ingredientId,
410
+ ingredientType,
411
+ group,
412
+ slice,
413
+ enjoyByDate,
414
+ data
415
+ }) {
416
+ this.path = path;
417
+ this.name = name;
418
+ this.ingredientId = ingredientId;
419
+ this.ingredientType = ingredientType;
420
+ this.ingredientSource = ingredientSource;
421
+ this.enjoyByDate = enjoyByDate;
422
+ this.slice = slice;
423
+ this.group = group;
424
+ this.data = data;
425
+ }
426
+ get hasEnjoyByDate() {
427
+ return !!this.enjoyByDate && !this.unassigned;
428
+ }
429
+ get hasEnjoyByWarning() {
430
+ var _a;
431
+ return ((_a = this.troublesByType["EnjoyByTrouble"]) == null ? void 0 : _a.length) > 0;
432
+ }
433
+ get nozzlePaths() {
434
+ return this.pumps.data.map((pump) => pump.nozzlePath);
435
+ }
436
+ async cancelPour() {
437
+ await Promise.all(
438
+ this.pumps.data.filter((pump) => pump.isPouring).map((pump) => pump.cancelPour())
439
+ );
440
+ }
441
+ get canPour() {
442
+ return !this.shouldDefer && this.pumps.data.every((pump) => pump.canPour);
443
+ }
444
+ get isPouring() {
445
+ const _isPouring = this.pumps.data.some((pump) => pump.isPouring);
446
+ this.logger.debug(`isPouring: ${!!_isPouring}`);
447
+ return _isPouring;
448
+ }
449
+ async performIntent(props) {
450
+ const intent = typeof props === "string" ? props : props.intent;
451
+ const pumpPath = typeof props === "string" ? void 0 : props.pumpPath;
452
+ const pump = pumpPath ? this.pumps.getModel(pumpPath) : this.pumps.data[0];
453
+ return pump == null ? void 0 : pump.performIntent({ intent });
454
+ }
455
+ get pourState() {
456
+ const state = this.pumps.data.reduce((resolvedState, pump) => {
457
+ if (pump.pouringState) {
458
+ return pump.pouringState;
459
+ }
460
+ return resolvedState;
461
+ }, "");
462
+ return state;
463
+ }
464
+ get nozzlePath() {
465
+ var _a;
466
+ return (_a = this.pumps.data[0]) == null ? void 0 : _a.nozzlePath;
467
+ }
468
+ get pumpPaths() {
469
+ return this.pumps.data.map((pump) => pump.id);
470
+ }
471
+ get sortedPumps() {
472
+ return this.pumps.data.sort((a, b) => {
473
+ if (a.virtual && !b.virtual) {
474
+ return -1;
475
+ }
476
+ if (!a.virtual && b.virtual) {
477
+ return 1;
478
+ }
479
+ return a.name.localeCompare(b.name);
480
+ });
481
+ }
482
+ get ingredient() {
483
+ var _a;
484
+ if (!this.ingredientId) {
485
+ return void 0;
486
+ }
487
+ const ingredient = (_a = this.ingredientContainer) == null ? void 0 : _a.ingredients.getModel(
488
+ this.ingredientId
489
+ );
490
+ return ingredient;
491
+ }
492
+ get ingredientName() {
493
+ if (this.ingredient) {
494
+ return this.ingredient.displayName ?? this.ingredient.name;
495
+ } else if (this.ingredientId) {
496
+ return "unknown";
497
+ } else {
498
+ return "";
499
+ }
500
+ }
501
+ get previousIngredient() {
502
+ var _a;
503
+ if (!this.prevIngredientId) {
504
+ return void 0;
505
+ }
506
+ const ingredient = (_a = this.ingredientContainer) == null ? void 0 : _a.ingredients.getModel(
507
+ this.prevIngredientId
508
+ );
509
+ return ingredient;
510
+ }
511
+ get previousIngredientName() {
512
+ if (this.previousIngredient) {
513
+ return this.previousIngredient.displayName ?? this.previousIngredient.name;
514
+ } else if (this.prevIngredientId) {
515
+ return "unknown";
516
+ } else {
517
+ return "";
518
+ }
519
+ }
520
+ get prevIngredientId() {
521
+ var _a, _b;
522
+ return (_b = (_a = this.pumps.data) == null ? void 0 : _a[0]) == null ? void 0 : _b.prevIngredientId;
523
+ }
524
+ get unassigned() {
525
+ return (!this.ingredientId || this.ingredientId === "0") && (!this.prevIngredientId || this.prevIngredientId === "0");
526
+ }
527
+ get removed() {
528
+ return (!this.ingredientId || this.ingredientId === "0") && this.prevIngredientId !== void 0 && this.prevIngredientId !== "0";
529
+ }
530
+ get maxVolume() {
531
+ return this.slice.maxVolMl ?? 0;
532
+ }
533
+ get remainingVolume() {
534
+ return this.slice.currentVolMl ?? 0;
535
+ }
536
+ get hasMaxVolume() {
537
+ return this.slice.maxVolMl !== void 0;
538
+ }
539
+ get hasRemainingVolume() {
540
+ return this.slice.currentVolMl !== void 0;
541
+ }
542
+ get fillPercent() {
543
+ return this.remainingVolume <= 0 ? 0 : Math.floor((this.remainingVolume || 1) / (this.maxVolume || 1) * 100);
544
+ }
545
+ get hasFuelGuage() {
546
+ return this.hasMaxVolume && this.hasRemainingVolume;
547
+ }
548
+ updateIngredient(ingredientId) {
549
+ if (this.ingredientId === ingredientId) {
550
+ return;
551
+ }
552
+ kosAction(() => {
553
+ this.ingredientId = ingredientId;
554
+ });
555
+ }
556
+ async resolveIntentVolume(intent) {
557
+ const pump = this.pumps.data[0];
558
+ if (!pump) {
559
+ return { volume: -1 };
560
+ }
561
+ return pump.resolveIntentVolume(intent);
562
+ }
563
+ async overrideRfidCode(overrides) {
564
+ if (!overrides) {
565
+ throw new Error("Invalid override");
566
+ }
567
+ try {
568
+ const [error, result] = await sendRfidOverride(this.path, overrides);
569
+ if (error) {
570
+ throw new AssignmentError(
571
+ error,
572
+ `Failed to perform rfid override on holder ${this.id}`
573
+ );
574
+ }
575
+ kosAction(() => {
576
+ this.ingredientId = result == null ? void 0 : result.ingredientId;
577
+ });
578
+ return result;
579
+ } catch (e) {
580
+ log$1.error(`Failed to perform rfid override on holder ${this.id}`, e);
581
+ throw e;
582
+ }
583
+ }
584
+ async assignIngredient(ingredientId) {
585
+ try {
586
+ if (ingredientId) {
587
+ await assignHolderIngredient(this.path, ingredientId);
588
+ } else {
589
+ await unassignHolderIngredient(this.path);
590
+ }
591
+ kosAction(() => {
592
+ this.ingredientId = ingredientId;
593
+ });
594
+ } catch (e) {
595
+ log$1.error(`Failed to perform assign ingredient to holder ${this.id}`, e);
596
+ throw e;
597
+ }
598
+ }
599
+ /**
600
+ * @kosApiLevel 3
601
+ */
602
+ get shouldDefer() {
603
+ return this.troubles.some((trouble) => trouble.shouldDefer);
604
+ }
605
+ async replaceLine() {
606
+ await replaceLine(this.path);
607
+ return;
608
+ }
609
+ // -------------------LIFECYCLE----------------------------
610
+ // ----------------------------------
611
+ // UNCOMMENT FOR TESTING FUEL GAUGE
612
+ // ----------------------------------
613
+ // async load() {
614
+ // const random = Math.max(1000, Math.floor(Math.random() * 5000));
615
+ // this.slice.maxVolMl = 1000;
616
+ // setInterval(() => {
617
+ // kosAction(() => {
618
+ // if (this.remainingVolume < -100) {
619
+ // this.slice.maxVolMl = 1000;
620
+ // this.slice.currentVolMl = this.maxVolume;
621
+ // } else {
622
+ // this.slice.currentVolMl = this.remainingVolume - 50;
623
+ // }
624
+ // });
625
+ // }, random);
626
+ // }
627
+ // -------------------ENTITY----------------------------
628
+ };
629
+ __decorateClass$a([
630
+ kosChild
631
+ ], HolderModelImpl.prototype, "pumps", 2);
632
+ __decorateClass$a([
633
+ kosDependency({ modelType: IngredientContainer.type })
634
+ ], HolderModelImpl.prototype, "ingredientContainer", 2);
635
+ HolderModelImpl = __decorateClass$a([
636
+ kosModel(MODEL_TYPE$a),
637
+ kosTroubleAware()
638
+ ], HolderModelImpl);
639
+ const Holder = {
640
+ registration: {
641
+ [MODEL_TYPE$a]: {
642
+ class: HolderModelImpl,
643
+ singleton: false
644
+ }
645
+ },
646
+ type: MODEL_TYPE$a,
647
+ predicate: isKosModel(MODEL_TYPE$a),
648
+ factory: Kos.Factory.create(MODEL_TYPE$a)
649
+ };
650
+ const mapAssemblyHolderToModel = async (group, holderData) => {
651
+ var _a;
652
+ const _ingredientId = ExtensionManager.propertyMapper.executeMapper(
653
+ ExtensionType.HolderIngredientMapper,
654
+ holderData
655
+ );
656
+ const type = ExtensionManager.propertyMapper.executeMapper(
657
+ ExtensionType.HolderTypeMapper,
658
+ holderData
659
+ ) || holderData.ingType;
660
+ const holderExtData = await KosExtensionUtils.executeDataMapperExtension({
661
+ extension: ExtensionType.HolderMapper,
662
+ data: holderData,
663
+ contextData: {}
664
+ });
665
+ const {
666
+ name,
667
+ path,
668
+ ingredientId,
669
+ ingType,
670
+ ingSource,
671
+ slice,
672
+ attributes,
673
+ ...rest
674
+ } = holderData;
675
+ const extData = { ...rest, ...holderExtData };
676
+ const sliceData = slice || { pos: 0 };
677
+ const holderOptions = {
678
+ name,
679
+ path,
680
+ ingredientId: _ingredientId || ingredientId,
681
+ ingredientType: type || ingType,
682
+ ingredientSource: ingSource,
683
+ enjoyByDate: ((_a = holderData.container) == null ? void 0 : _a.enjoyByDate) ? new Date(holderData.container.enjoyByDate) : void 0,
684
+ slice: sliceData,
685
+ group,
686
+ attributes,
687
+ data: extData
688
+ };
689
+ const holder = Holder.factory(holderData.path)(holderOptions);
690
+ return holder;
691
+ };
692
+ const { URL: URL$3 } = resolveServiceUrl("ASSEMBLY_SERVICE");
693
+ const { getOne: getOne$2 } = ServiceFactory.build({
694
+ basePath: `${URL$3}/api/kos/device/assemblies`
695
+ });
696
+ const log = KosLog.createLogger({
697
+ name: "assembly-service",
698
+ group: "Services"
699
+ });
700
+ const getAssembly = async () => {
701
+ log.debug("sending GET for assembly");
702
+ const response = await getOne$2({});
703
+ return response;
704
+ };
705
+ var __defProp$7 = Object.defineProperty;
706
+ var __getOwnPropDesc$9 = Object.getOwnPropertyDescriptor;
707
+ var __decorateClass$9 = (decorators, target, key, kind) => {
708
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$9(target, key) : target;
709
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
710
+ if (decorator = decorators[i])
711
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
712
+ if (kind && result)
713
+ __defProp$7(target, key, result);
714
+ return result;
715
+ };
716
+ const MODEL_TYPE$9 = "board-container-model";
717
+ const TOPIC_BOARD_LINKED = "/kos/hardware/board/linked";
718
+ const TOPIC_BOARD_UNLINKED = "/kos/hardware/board/unlinked";
719
+ let BoardContainerModel = class {
720
+ constructor(modelId, options, context) {
721
+ __publicField(this, "id");
722
+ __publicField(this, "logger");
723
+ __publicField(this, "models");
724
+ this.id = modelId;
725
+ this.logger = context.logger;
726
+ this.models = new KosModelContainer({
727
+ parentId: modelId,
728
+ extensionId: ExtensionType.BoardIndex
729
+ });
730
+ }
731
+ get boardList() {
732
+ return this.models.data;
733
+ }
734
+ updateModel() {
735
+ }
736
+ addModel(model) {
737
+ this.models.addModel(model);
738
+ }
739
+ removeModel(id) {
740
+ this.models.removeModel(id);
741
+ }
742
+ updateBoard(boardLinkEvent) {
743
+ const boardId = boardLinkEvent.path;
744
+ const board = this.models.getModel(boardId);
745
+ if (!board) {
746
+ this.logger.warn(`board ${boardId} not found`);
747
+ return;
748
+ }
749
+ board.updateModel(boardLinkEvent);
750
+ }
751
+ handleBoardLinkEvent(boardLinkEvent) {
752
+ this.logger.debug(`handling ${TOPIC_BOARD_LINKED} event ${boardLinkEvent}`);
753
+ if (boardLinkEvent) {
754
+ this.updateBoard(boardLinkEvent);
755
+ } else {
756
+ this.logger.debug(`- boardLinkEvent is undefined`);
757
+ }
758
+ }
759
+ handleBoardUnlinkEvent(boardLinkEvent) {
760
+ this.logger.debug(
761
+ `handling ${TOPIC_BOARD_UNLINKED} event ${boardLinkEvent}`
762
+ );
763
+ if (boardLinkEvent) {
764
+ this.updateBoard(boardLinkEvent);
765
+ } else {
766
+ this.logger.debug(`- boardLinkEvent is undefined`);
767
+ }
768
+ }
769
+ };
770
+ __decorateClass$9([
771
+ kosChild
772
+ ], BoardContainerModel.prototype, "models", 2);
773
+ __decorateClass$9([
774
+ kosTopicHandler({
775
+ lifecycle: DependencyLifecycle.INIT,
776
+ topic: TOPIC_BOARD_LINKED,
777
+ websocket: true
778
+ })
779
+ ], BoardContainerModel.prototype, "handleBoardLinkEvent", 1);
780
+ __decorateClass$9([
781
+ kosTopicHandler({
782
+ lifecycle: DependencyLifecycle.INIT,
783
+ topic: TOPIC_BOARD_UNLINKED,
784
+ websocket: true
785
+ })
786
+ ], BoardContainerModel.prototype, "handleBoardUnlinkEvent", 1);
787
+ BoardContainerModel = __decorateClass$9([
788
+ kosModel(MODEL_TYPE$9)
789
+ ], BoardContainerModel);
790
+ const boardTroubleDataMapper = async (trouble) => {
791
+ const boardPath = trouble.data.boardPath;
792
+ const { model } = getKosModelSync(boardPath);
793
+ return {
794
+ boardName: (model == null ? void 0 : model.name) || ""
795
+ };
796
+ };
797
+ var __defProp$6 = Object.defineProperty;
798
+ var __getOwnPropDesc$8 = Object.getOwnPropertyDescriptor;
799
+ var __decorateClass$8 = (decorators, target, key, kind) => {
800
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$8(target, key) : target;
801
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
802
+ if (decorator = decorators[i])
803
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
804
+ if (kind && result)
805
+ __defProp$6(target, key, result);
806
+ return result;
807
+ };
808
+ const MODEL_TYPE$8 = DispenseModelType.PumpContainer;
809
+ var PumpIndex = /* @__PURE__ */ ((PumpIndex2) => {
810
+ PumpIndex2["byBoard"] = "byBoard";
811
+ PumpIndex2["byType"] = "byType";
812
+ PumpIndex2["byNozzle"] = "byNozzle";
813
+ return PumpIndex2;
814
+ })(PumpIndex || {});
815
+ let PumpContainerModelImpl = class {
816
+ constructor(modelId, options) {
817
+ __publicField(this, "id");
818
+ __publicField(this, "pumps");
819
+ this.id = modelId;
820
+ this.pumps = new KosModelContainer({
821
+ indexMap: {
822
+ byNozzle: (pump) => pump.nozzlePaths,
823
+ byBoard: (pump) => pump.boardPath,
824
+ byType: "type"
825
+ },
826
+ parentId: modelId,
827
+ extensionId: ExtensionType.PumpIndex
828
+ });
829
+ }
830
+ /**
831
+ * The collection of pump models.
832
+ */
833
+ get pumpModels() {
834
+ return this.pumps.data;
835
+ }
836
+ /**
837
+ * The collection of pump paths.
838
+ */
839
+ get pumpPaths() {
840
+ return this.pumpModels.map((pump) => pump.path);
841
+ }
842
+ addModel(model) {
843
+ this.pumps.addModel(model);
844
+ }
845
+ removeModel(id) {
846
+ this.pumps.removeModel(id);
847
+ }
848
+ getModel(id) {
849
+ return this.pumps.getModel(id);
850
+ }
851
+ get models() {
852
+ return this.pumps;
853
+ }
854
+ get data() {
855
+ return this.pumps.data;
856
+ }
857
+ updateModel() {
858
+ }
859
+ // -------------------LIFECYCLE----------------------------
860
+ async load() {
861
+ }
862
+ // -------------------ENTITY----------------------------
863
+ };
864
+ __decorateClass$8([
865
+ kosChild
866
+ ], PumpContainerModelImpl.prototype, "pumps", 2);
867
+ PumpContainerModelImpl = __decorateClass$8([
868
+ kosModel(MODEL_TYPE$8)
869
+ ], PumpContainerModelImpl);
870
+ const PumpContainer = {
871
+ registration: {
872
+ [MODEL_TYPE$8]: {
873
+ class: PumpContainerModelImpl,
874
+ singleton: true
875
+ }
876
+ },
877
+ type: MODEL_TYPE$8,
878
+ predicate: isKosModel(MODEL_TYPE$8),
879
+ factory: Kos.Singleton.create(
880
+ MODEL_TYPE$8
881
+ )
882
+ };
883
+ const getPumpRelatedPaths = async (pumpPath) => {
884
+ const result = [];
885
+ const { model } = await getKosModel(pumpPath);
886
+ if (model) {
887
+ result.push(model.boardPath);
888
+ result.push(model.nozzlePath);
889
+ result.push(model.holderPath);
890
+ }
891
+ return result;
892
+ };
893
+ const pumpTroubleResolver = async (trouble) => {
894
+ const result = [];
895
+ const pumpPath = trouble.data.pumpPath;
896
+ result.push(pumpPath);
897
+ const relatedPaths = await getPumpRelatedPaths(pumpPath);
898
+ return [...result, ...relatedPaths];
899
+ };
900
+ const boardTroubleResolver = async (trouble) => {
901
+ const result = [];
902
+ const boardPath = trouble.data.boardPath;
903
+ result.push(trouble.data.boardPath);
904
+ const pumpContainer = await getKosModel(
905
+ PumpContainer.type
906
+ );
907
+ if (pumpContainer == null ? void 0 : pumpContainer.model) {
908
+ const boardPumps = pumpContainer.model.models.getIndexByKey(
909
+ PumpIndex.byBoard,
910
+ boardPath
911
+ );
912
+ const pumpPromises = boardPumps.map(
913
+ (pump) => getPumpRelatedPaths(pump.path)
914
+ );
915
+ const pumpResults = await Promise.allSettled(pumpPromises);
916
+ pumpResults.forEach((r) => {
917
+ if (r.status === "fulfilled") {
918
+ r.value.forEach((path) => result.push(path));
919
+ }
920
+ });
921
+ }
922
+ return Array.from(new Set(result));
923
+ };
924
+ var __getOwnPropDesc$7 = Object.getOwnPropertyDescriptor;
925
+ var __decorateClass$7 = (decorators, target, key, kind) => {
926
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$7(target, key) : target;
927
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
928
+ if (decorator = decorators[i])
929
+ result = decorator(result) || result;
930
+ return result;
931
+ };
932
+ const MODEL_TYPE$7 = "board-model";
933
+ const mapOptionsToModel = (options, model) => {
934
+ const { type, name, path, linked, instanceId, link, ...rest } = options;
935
+ model.type = type;
936
+ model.name = name;
937
+ model.path = path;
938
+ model.linked = linked;
939
+ model.link = Object.freeze(link);
940
+ model.instanceId = instanceId;
941
+ Object.assign(model, rest);
942
+ };
943
+ ExtensionManager[EXTENSION_TROUBLE_MAPPER].register(
944
+ "board",
945
+ boardTroubleResolver
946
+ );
947
+ ExtensionManager[EXTENSION_TROUBLE_DATA_MAPPER].register(
948
+ "board",
949
+ boardTroubleDataMapper
950
+ );
951
+ let BoardModelImpl = class {
952
+ constructor(modelId, options, context) {
953
+ __publicField(this, "id");
954
+ __publicField(this, "type");
955
+ __publicField(this, "name");
956
+ __publicField(this, "path");
957
+ __publicField(this, "linked");
958
+ __publicField(this, "instanceId");
959
+ __publicField(this, "logger");
960
+ this.id = modelId;
961
+ this.logger = context.logger;
962
+ mapOptionsToModel(options, this);
963
+ }
964
+ updateModel(options) {
965
+ mapOptionsToModel(options, this);
966
+ }
967
+ // -------------------LIFECYCLE----------------------------
968
+ async init() {
969
+ this.logger.debug(`initializing board ${this.id}`);
970
+ }
971
+ async load() {
972
+ this.logger.debug(`loading board ${this.id}`);
973
+ }
974
+ };
975
+ BoardModelImpl = __decorateClass$7([
976
+ kosModel(MODEL_TYPE$7)
977
+ ], BoardModelImpl);
978
+ const Board = {
979
+ registration: {
980
+ [MODEL_TYPE$7]: {
981
+ class: BoardModelImpl,
982
+ singleton: false
983
+ }
984
+ },
985
+ type: MODEL_TYPE$7,
986
+ predicate: isKosModel(MODEL_TYPE$7),
987
+ factory: Kos.Factory.create(MODEL_TYPE$7)
988
+ };
989
+ const BoardContainer = {
990
+ registration: {
991
+ [MODEL_TYPE$9]: {
992
+ class: BoardContainerModel,
993
+ singleton: true
994
+ },
995
+ ...Board.registration
996
+ },
997
+ type: MODEL_TYPE$9,
998
+ predicate: isKosModel(MODEL_TYPE$9),
999
+ factory: Kos.Singleton.create(
1000
+ MODEL_TYPE$9
1001
+ )
1002
+ };
1003
+ var __defProp$5 = Object.defineProperty;
1004
+ var __getOwnPropDesc$6 = Object.getOwnPropertyDescriptor;
1005
+ var __decorateClass$6 = (decorators, target, key, kind) => {
1006
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$6(target, key) : target;
1007
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
1008
+ if (decorator = decorators[i])
1009
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
1010
+ if (kind && result)
1011
+ __defProp$5(target, key, result);
1012
+ return result;
1013
+ };
1014
+ const MODEL_TYPE$6 = DispenseModelType.HolderContainer;
1015
+ const TOPIC_INSERT_START = "/kos/insertion/insert/start";
1016
+ const TOPIC_INSERT_COMPLETE = "/kos/insertion/insert/complete";
1017
+ const TOPIC_INSERT_UPDATE = "/kos/insertion/insert/update";
1018
+ const TOPIC_REMOVE = "/kos/insertion/remove";
1019
+ const TOPIC_REPLACE_LINE = "/kos/pumpEvent/replaceLine";
1020
+ const TOPIC_HOLDER_CHANGED = "/kos/handle/*";
1021
+ let HolderContainerModelImpl = class {
1022
+ constructor(modelId, _options, context) {
1023
+ __publicField(this, "id");
1024
+ __publicField(this, "holders");
1025
+ __publicField(this, "logger");
1026
+ this.id = modelId;
1027
+ this.holders = new KosModelContainer({
1028
+ indexMap: {
1029
+ nozzle: (holder) => holder.nozzlePaths,
1030
+ group: "group"
1031
+ },
1032
+ parentId: modelId,
1033
+ extensionId: ExtensionType.HolderIndex
1034
+ });
1035
+ this.logger = context.logger;
1036
+ }
1037
+ updateModel() {
1038
+ }
1039
+ handleHolderEvents(event) {
1040
+ var _a, _b, _c;
1041
+ KosLog.ifDebug(
1042
+ () => this.logger.debug("Received holder change event", JSON.stringify(event))
1043
+ );
1044
+ const holder = this.holders.getModel(event.path);
1045
+ if (holder) {
1046
+ this.logger.info(
1047
+ `Received change event for holder ${holder.path}. Updating fuel gauge data.`
1048
+ );
1049
+ holder.slice.currentVolMl = (_a = event.slice) == null ? void 0 : _a.currentVolMl;
1050
+ holder.slice.maxVolMl = (_b = event.slice) == null ? void 0 : _b.maxVolMl;
1051
+ if ((_c = event == null ? void 0 : event.container) == null ? void 0 : _c.enjoyByDate) {
1052
+ holder.enjoyByDate = new Date(event.container.enjoyByDate);
1053
+ } else {
1054
+ holder.enjoyByDate = void 0;
1055
+ }
1056
+ }
1057
+ }
1058
+ handleInsertion(data) {
1059
+ KosLog.ifDebug(
1060
+ () => this.logger.debug("Received insertion event", JSON.stringify(data))
1061
+ );
1062
+ const wrappedData = Array.isArray(data) ? data : [data];
1063
+ wrappedData.forEach((event) => {
1064
+ kosAction(() => {
1065
+ var _a, _b, _c;
1066
+ const ingredientId = event.ingredientId;
1067
+ const holder = this.holders.getModel(event.path);
1068
+ if (holder) {
1069
+ this.logger.info(
1070
+ `Received insertion event for holder ${holder.path}`
1071
+ );
1072
+ holder.updateIngredient(ingredientId);
1073
+ holder.slice.currentVolMl = (_a = event.slice) == null ? void 0 : _a.currentVolMl;
1074
+ holder.slice.maxVolMl = (_b = event.slice) == null ? void 0 : _b.maxVolMl;
1075
+ if ((_c = event == null ? void 0 : event.container) == null ? void 0 : _c.enjoyByDate) {
1076
+ holder.enjoyByDate = new Date(event.container.enjoyByDate);
1077
+ } else {
1078
+ holder.enjoyByDate = void 0;
1079
+ }
1080
+ event.pumps.forEach((pump) => {
1081
+ kosAction(() => {
1082
+ const pumpModel = holder.pumps.getModel(pump.path);
1083
+ if (pumpModel) {
1084
+ pumpModel.ingredientId = pump.ingredientId;
1085
+ pumpModel.inserted = pump.inserted;
1086
+ pumpModel.prevIngredientId = pump.prevIngredientId;
1087
+ }
1088
+ });
1089
+ });
1090
+ }
1091
+ });
1092
+ });
1093
+ }
1094
+ // -------------------ENTITY----------------------------
1095
+ };
1096
+ __decorateClass$6([
1097
+ kosChild
1098
+ ], HolderContainerModelImpl.prototype, "holders", 2);
1099
+ __decorateClass$6([
1100
+ kosTopicHandler({
1101
+ topic: TOPIC_HOLDER_CHANGED,
1102
+ websocket: true,
1103
+ condition: (event, model) => model.holders.getModel(event.path) !== void 0
1104
+ })
1105
+ ], HolderContainerModelImpl.prototype, "handleHolderEvents", 1);
1106
+ __decorateClass$6([
1107
+ kosTopicHandler({
1108
+ topic: [
1109
+ TOPIC_INSERT_START,
1110
+ TOPIC_INSERT_COMPLETE,
1111
+ TOPIC_INSERT_UPDATE,
1112
+ TOPIC_REMOVE,
1113
+ TOPIC_REPLACE_LINE
1114
+ ],
1115
+ websocket: true
1116
+ })
1117
+ ], HolderContainerModelImpl.prototype, "handleInsertion", 1);
1118
+ HolderContainerModelImpl = __decorateClass$6([
1119
+ kosModel(MODEL_TYPE$6)
1120
+ ], HolderContainerModelImpl);
1121
+ const HolderContainer = {
1122
+ registration: {
1123
+ [MODEL_TYPE$6]: {
1124
+ class: HolderContainerModelImpl,
1125
+ singleton: true
1126
+ }
1127
+ },
1128
+ type: MODEL_TYPE$6,
1129
+ predicate: isKosModel(MODEL_TYPE$6),
1130
+ factory: Kos.Singleton.create(
1131
+ MODEL_TYPE$6
1132
+ )
1133
+ };
1134
+ const Logger$1 = KosLog.createLogger({ name: "board-utils" });
1135
+ const mapAssemblyBoardToModel = async (board) => {
1136
+ const boardExtData = await KosExtensionUtils.executeDataMapperExtension({
1137
+ extension: ExtensionType.BoardMapper,
1138
+ data: board,
1139
+ contextData: {}
1140
+ });
1141
+ const { type, name, path, linked, instanceId, ...rest } = board;
1142
+ const extData = { ...rest, ...boardExtData };
1143
+ const options = {
1144
+ type,
1145
+ name,
1146
+ path,
1147
+ linked,
1148
+ instanceId,
1149
+ ...extData
1150
+ };
1151
+ const boardModel = Board.factory(board.path)(options);
1152
+ boardModel.updateModel(options);
1153
+ return boardModel;
1154
+ };
1155
+ const assemblyBoardMap = (boardContainer) => async (board) => {
1156
+ Logger$1.debug(`adding board ${board.name}`);
1157
+ const boardModel = await mapAssemblyBoardToModel(board);
1158
+ boardContainer.addModel(boardModel);
1159
+ };
1160
+ var PourState = /* @__PURE__ */ ((PourState2) => {
1161
+ PourState2["IDLE"] = "IDLE";
1162
+ PourState2["POURING"] = "POURING";
1163
+ PourState2["POUR_STARTING"] = "POUR_STARTING";
1164
+ PourState2["POUR_CANCELING"] = "POUR_CANCELING";
1165
+ return PourState2;
1166
+ })(PourState || {});
1167
+ const { URL: URL$2 } = resolveServiceUrl("PUMP_SERVICE");
1168
+ const { postModel: postModel$2, getOne: getOne$1 } = ServiceFactory.build({
1169
+ basePath: `${URL$2}/api/kos/holders`
1170
+ });
1171
+ KosLog.createLogger({
1172
+ name: "pump-service",
1173
+ group: "Services"
1174
+ });
1175
+ const sendIntent = async ({
1176
+ intent,
1177
+ pumpId,
1178
+ tracker
1179
+ }) => {
1180
+ const url = `${URL$2}/api/ext/dispense/nozzle/nozzle/pipeline/ingredient/pour/${pumpId}/${intent}`;
1181
+ const response = await postModel$2({ model: {}, urlOverride: url, tracker });
1182
+ if (response == null ? void 0 : response.data) {
1183
+ FutureManager.initiateFuture(response.data);
1184
+ }
1185
+ return response;
1186
+ };
1187
+ const getIntentVolume = async (pumpId, intent) => {
1188
+ const url = `${URL$2}/api/ext/dispense/nozzle/nozzle/pipeline/ingredient/intent/${pumpId}/${intent}/volume`;
1189
+ const response = await getOne$1({ urlOverride: url });
1190
+ if (!(response == null ? void 0 : response.data)) {
1191
+ return { volume: -1 };
1192
+ }
1193
+ return response.data;
1194
+ };
1195
+ var __defProp$4 = Object.defineProperty;
1196
+ var __getOwnPropDesc$5 = Object.getOwnPropertyDescriptor;
1197
+ var __decorateClass$5 = (decorators, target, key, kind) => {
1198
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$5(target, key) : target;
1199
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
1200
+ if (decorator = decorators[i])
1201
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
1202
+ if (kind && result)
1203
+ __defProp$4(target, key, result);
1204
+ return result;
1205
+ };
1206
+ const MODEL_TYPE$5 = DispenseModelType.Pump;
1207
+ ExtensionManager[EXTENSION_TROUBLE_MAPPER].register(
1208
+ "pump",
1209
+ pumpTroubleResolver
1210
+ );
1211
+ let PumpModelImpl = class {
1212
+ constructor(modelId, options) {
1213
+ __publicField(this, "id");
1214
+ __publicField(this, "inserted");
1215
+ __publicField(this, "type");
1216
+ __publicField(this, "virtual");
1217
+ __publicField(this, "ingredientId");
1218
+ __publicField(this, "holderPath");
1219
+ __publicField(this, "boardPath");
1220
+ __publicField(this, "nozzlePath");
1221
+ __publicField(this, "childPump");
1222
+ __publicField(this, "name");
1223
+ __publicField(this, "path");
1224
+ __publicField(this, "prevIngredientId");
1225
+ /**
1226
+ * @kosApiLevel 12
1227
+ */
1228
+ __publicField(this, "state");
1229
+ __publicField(this, "futureHandler");
1230
+ __publicField(this, "currentState", PourState.IDLE);
1231
+ this.id = modelId;
1232
+ const {
1233
+ inserted,
1234
+ holderPath,
1235
+ boardPath,
1236
+ nozzlePath,
1237
+ name,
1238
+ path,
1239
+ childPump,
1240
+ virtual,
1241
+ prevIngredientId,
1242
+ state,
1243
+ ...rest
1244
+ } = options;
1245
+ this.inserted = inserted;
1246
+ this.type = options.type;
1247
+ this.ingredientId = options.ingredientId;
1248
+ this.holderPath = holderPath;
1249
+ this.boardPath = boardPath;
1250
+ this.nozzlePath = nozzlePath;
1251
+ this.name = name;
1252
+ this.path = path;
1253
+ this.childPump = !!childPump;
1254
+ this.virtual = !!virtual;
1255
+ this.prevIngredientId = prevIngredientId;
1256
+ this.state = state;
1257
+ Object.assign(this, rest);
1258
+ this.futureHandler = new FutureHandler(this);
1259
+ }
1260
+ updateModel(options) {
1261
+ const {
1262
+ inserted,
1263
+ holderPath,
1264
+ boardPath,
1265
+ nozzlePath,
1266
+ childPump,
1267
+ name,
1268
+ path,
1269
+ ...rest
1270
+ } = options;
1271
+ this.inserted = inserted;
1272
+ this.type = options.type;
1273
+ this.ingredientId = options.ingredientId;
1274
+ this.holderPath = holderPath;
1275
+ this.boardPath = boardPath;
1276
+ this.nozzlePath = nozzlePath;
1277
+ this.childPump = this.childPump ? this.childPump : !!childPump;
1278
+ this.name = name;
1279
+ this.path = path;
1280
+ this.prevIngredientId = options.prevIngredientId;
1281
+ Object.assign(this, rest);
1282
+ }
1283
+ // -------------------LIFECYCLE----------------------------
1284
+ get pouringState() {
1285
+ var _a;
1286
+ return ((_a = this.future) == null ? void 0 : _a.endState) || "";
1287
+ }
1288
+ get isPouring() {
1289
+ var _a;
1290
+ return !!(this.future && !((_a = this.future) == null ? void 0 : _a.endState)) || this.currentState === PourState.POUR_STARTING || this.currentState === PourState.POURING;
1291
+ }
1292
+ get canPour() {
1293
+ return !!this.ingredientId && !this.isPouring;
1294
+ }
1295
+ onFutureUpdate(future) {
1296
+ if (future.endState) {
1297
+ kosAction(() => {
1298
+ this.currentState = PourState.IDLE;
1299
+ });
1300
+ }
1301
+ }
1302
+ async cancelPour() {
1303
+ var _a;
1304
+ if (this.currentState === PourState.POURING || this.currentState === PourState.POUR_STARTING) {
1305
+ this.currentState = PourState.POUR_CANCELING;
1306
+ await ((_a = this.future) == null ? void 0 : _a.cancelFuture());
1307
+ kosAction(() => {
1308
+ this.currentState = PourState.IDLE;
1309
+ });
1310
+ } else {
1311
+ KosLog.warn(`Cannot cancel pour in state ${this.currentState}`);
1312
+ }
1313
+ }
1314
+ get future() {
1315
+ return this.futureHandler.future;
1316
+ }
1317
+ async resolveIntentVolume(intent) {
1318
+ return await getIntentVolume(this.path, intent);
1319
+ }
1320
+ async performIntent(props, tracker) {
1321
+ const intent = typeof props === "string" ? props : props.intent;
1322
+ if (!intent) {
1323
+ throw new Error("No intent provided");
1324
+ }
1325
+ try {
1326
+ if (this.currentState === PourState.IDLE) {
1327
+ this.currentState = PourState.POUR_STARTING;
1328
+ if (!tracker) {
1329
+ throw new Error("No tracker provided");
1330
+ }
1331
+ const result = await sendIntent({
1332
+ tracker,
1333
+ intent,
1334
+ pumpId: this.path
1335
+ });
1336
+ if (this.currentState === PourState.POUR_STARTING) {
1337
+ kosAction(() => {
1338
+ this.currentState = PourState.POURING;
1339
+ });
1340
+ }
1341
+ return result == null ? void 0 : result.data;
1342
+ } else {
1343
+ throw new Error(`Cannot pour in state ${this.currentState}`);
1344
+ }
1345
+ } catch (e) {
1346
+ KosLog.error(e);
1347
+ this.currentState = PourState.IDLE;
1348
+ throw e;
1349
+ }
1350
+ }
1351
+ // -------------------ENTITY----------------------------
1352
+ };
1353
+ __decorateClass$5([
1354
+ kosFuture()
1355
+ ], PumpModelImpl.prototype, "performIntent", 1);
1356
+ PumpModelImpl = __decorateClass$5([
1357
+ kosModel(MODEL_TYPE$5)
1358
+ ], PumpModelImpl);
1359
+ const Pump = {
1360
+ registration: {
1361
+ [MODEL_TYPE$5]: {
1362
+ class: PumpModelImpl,
1363
+ singleton: false
1364
+ }
1365
+ },
1366
+ type: MODEL_TYPE$5,
1367
+ predicate: isKosModel(MODEL_TYPE$5),
1368
+ factory: Kos.Factory.create(MODEL_TYPE$5)
1369
+ };
1370
+ const Logger = KosLog.createLogger({ name: "pump-utils" });
1371
+ const mapAssemblyPumpToModel = (nozzlePath, pump) => {
1372
+ const virtual = (pump.pumps ?? []).length > 1;
1373
+ const options = {
1374
+ boardPath: pump.boardPath,
1375
+ holderPath: pump.holderPath,
1376
+ ingredientId: pump.ingredientId,
1377
+ childPump: !!pump.childPump,
1378
+ virtual,
1379
+ inserted: pump.inserted,
1380
+ name: pump.name,
1381
+ path: pump.path,
1382
+ type: pump.type,
1383
+ nozzlePath,
1384
+ prevIngredientId: pump.prevIngredientId,
1385
+ state: pump.state
1386
+ };
1387
+ const pumpModel = Pump.factory(pump.path)(options);
1388
+ pumpModel.updateModel(options);
1389
+ return pumpModel;
1390
+ };
1391
+ const assemblyPumpMap = (pumpContainer) => (holderContainer) => (nozzle) => (assemblyPump) => {
1392
+ var _a;
1393
+ try {
1394
+ Logger.debug(`adding pump ${assemblyPump.name}`);
1395
+ const pump = mapAssemblyPumpToModel(nozzle.path, assemblyPump);
1396
+ pumpContainer.addModel(pump);
1397
+ const holderPath = pump.holderPath;
1398
+ const holder = holderContainer.holders.getModel(holderPath);
1399
+ holder == null ? void 0 : holder.pumps.addModel(pump);
1400
+ if (!(holder == null ? void 0 : holder.nozzlePaths.includes(nozzle.path))) {
1401
+ holder == null ? void 0 : holder.nozzlePaths.push(nozzle.path);
1402
+ }
1403
+ (_a = assemblyPump == null ? void 0 : assemblyPump.pumps) == null ? void 0 : _a.forEach((subPump) => {
1404
+ const subHolderPath = pump.holderPath;
1405
+ const subPumpData = {
1406
+ ...subPump,
1407
+ childPump: true,
1408
+ holderPath: subHolderPath,
1409
+ ingredientId: pump.ingredientId
1410
+ };
1411
+ assemblyPumpMap(pumpContainer)(holderContainer)(nozzle)(subPumpData);
1412
+ });
1413
+ } catch (error) {
1414
+ Logger.error(`Error mapping assembly pump: ${error}`);
1415
+ throw error;
1416
+ }
1417
+ };
1418
+ var __defProp$3 = Object.defineProperty;
1419
+ var __getOwnPropDesc$4 = Object.getOwnPropertyDescriptor;
1420
+ var __decorateClass$4 = (decorators, target, key, kind) => {
1421
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$4(target, key) : target;
1422
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
1423
+ if (decorator = decorators[i])
1424
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
1425
+ if (kind && result)
1426
+ __defProp$3(target, key, result);
1427
+ return result;
1428
+ };
1429
+ const MODEL_TYPE$4 = "assembly-model";
1430
+ const CONTEXT_ASSEMBLY_DATA = "assembly-data";
1431
+ const CONTEXT_ASSEMBLY_RAW_DATA = "assembly-raw-data";
1432
+ let AssemblyModelImpl = class {
1433
+ constructor(modelId, _options, context) {
1434
+ __publicField(this, "id");
1435
+ __publicField(this, "_nozzlePaths", /* @__PURE__ */ new Set());
1436
+ __publicField(this, "troubleContainer");
1437
+ __publicField(this, "holderContainer");
1438
+ __publicField(this, "boardContainer");
1439
+ __publicField(this, "pumpContainer");
1440
+ __publicField(this, "logger");
1441
+ this.id = modelId;
1442
+ this.holderContainer = HolderContainer.factory({});
1443
+ this.boardContainer = BoardContainer.factory({});
1444
+ this.pumpContainer = PumpContainer.factory({});
1445
+ this.logger = context.logger;
1446
+ }
1447
+ updateModel(_options) {
1448
+ }
1449
+ get allHolders() {
1450
+ return this.holderContainer.holders.data;
1451
+ }
1452
+ get holderGroups() {
1453
+ return this.holderContainer.holders.getIndexKeys("group");
1454
+ }
1455
+ get nozzlePaths() {
1456
+ return Array.from(this._nozzlePaths);
1457
+ }
1458
+ getHoldersByGroup(group) {
1459
+ return this.holderContainer.holders.getIndexByKey("group", group);
1460
+ }
1461
+ getHoldersByNozzle(nozzlePath) {
1462
+ return this.holderContainer.holders.getIndexByKey("nozzle", nozzlePath);
1463
+ }
1464
+ /**
1465
+ * Returns a map of the pumps associated with each nozzle
1466
+ *
1467
+ * Can be used in conjunction with the nozzlePaths to get the pumps associated with each nozzle
1468
+ * @returns Record<string, PumpModel[]>
1469
+ */
1470
+ get pumpsByNozzle() {
1471
+ return this.pumpContainer.models.idx.byNozzle;
1472
+ }
1473
+ /**
1474
+ * Returns a list of all fo the pumps paths across the entire assembly.
1475
+ */
1476
+ get pumpPaths() {
1477
+ return this.pumpContainer.models.data.map((pump) => pump.path);
1478
+ }
1479
+ get boards() {
1480
+ return this.boardContainer.boardList;
1481
+ }
1482
+ // -------------------LIFECYCLE----------------------------
1483
+ async init() {
1484
+ this.logger.debug(`initializing assembly ${this.id}`);
1485
+ }
1486
+ async ready() {
1487
+ var _a;
1488
+ (_a = this.troubleContainer) == null ? void 0 : _a.troubles.increment();
1489
+ ExtensionManager[EXTENSION_FEATURE_FLAG_RESOLVER].execute(
1490
+ ExtensionType.AssemblyFeatureFlags,
1491
+ this
1492
+ );
1493
+ }
1494
+ async load(context) {
1495
+ this.logger.debug(`loading assembly ${this.id}`);
1496
+ const result = await getAssembly();
1497
+ if ((result == null ? void 0 : result.status) === 200) {
1498
+ const data = await KosExtensionUtils.executeDataMapperExtension({
1499
+ extension: ExtensionType.AssemblyMapper,
1500
+ data: result.data,
1501
+ contextData: {}
1502
+ });
1503
+ context.set(CONTEXT_ASSEMBLY_DATA, data);
1504
+ Object.assign(this, data);
1505
+ Object.entries(data).forEach(([key, value]) => {
1506
+ if (isKosDataModel(value)) {
1507
+ this.logger.debug(`adding child model ${key} from extension data`);
1508
+ this[ChildModels][key] = true;
1509
+ }
1510
+ });
1511
+ context.set(CONTEXT_ASSEMBLY_RAW_DATA, result.data);
1512
+ for await (const assembly of result.data.assemblies) {
1513
+ const {
1514
+ boards = [],
1515
+ holders: assemblyHolders = {},
1516
+ nozzles = [],
1517
+ core: _core,
1518
+ name,
1519
+ path: _path,
1520
+ ...rest
1521
+ } = assembly;
1522
+ this.logger.debug(`adding assembly ${name}`);
1523
+ this.logger.warn(`Assembly rest keys: ${Object.keys(rest).join(", ")}`);
1524
+ Object.keys(rest).forEach((key) => {
1525
+ var _a;
1526
+ this.logger.warn(`Enabling feature flag: ${key}`);
1527
+ KosFeatureFlags.enableFeature(key);
1528
+ context.set(`assembly-feature-${key}`, rest[key]);
1529
+ if (((_a = rest[key]["state"]) == null ? void 0 : _a["path"]) !== void 0) {
1530
+ const statePath = rest[key]["state"]["path"];
1531
+ this.logger.warn(`Feature flag ${key} state path: ${statePath}`);
1532
+ context.set(`assembly-state-path-${key}`, statePath);
1533
+ }
1534
+ });
1535
+ for await (const board of boards) {
1536
+ this.logger.debug(`adding board ${board.name}`);
1537
+ const mapper = assemblyBoardMap(this.boardContainer);
1538
+ await mapper(board);
1539
+ }
1540
+ for await (const [group, holders] of Object.entries(
1541
+ assemblyHolders ?? {}
1542
+ )) {
1543
+ for await (const holder of holders) {
1544
+ this.logger.debug(`adding holder ${holder.name}`);
1545
+ const holderModel = await mapAssemblyHolderToModel(group, holder);
1546
+ this.holderContainer.holders.addModel(holderModel);
1547
+ }
1548
+ }
1549
+ const nozzlePumpMap = assemblyPumpMap(this.pumpContainer)(
1550
+ this.holderContainer
1551
+ );
1552
+ nozzles.forEach((nozzle) => {
1553
+ this._nozzlePaths.add(nozzle.path);
1554
+ const pumpMap = nozzlePumpMap(nozzle);
1555
+ nozzle.pumps.forEach(pumpMap);
1556
+ });
1557
+ }
1558
+ }
1559
+ }
1560
+ };
1561
+ __decorateClass$4([
1562
+ kosDependency({
1563
+ modelType: "trouble-container-model"
1564
+ })
1565
+ ], AssemblyModelImpl.prototype, "troubleContainer", 2);
1566
+ __decorateClass$4([
1567
+ kosChild
1568
+ ], AssemblyModelImpl.prototype, "holderContainer", 2);
1569
+ __decorateClass$4([
1570
+ kosChild
1571
+ ], AssemblyModelImpl.prototype, "boardContainer", 2);
1572
+ __decorateClass$4([
1573
+ kosChild
1574
+ ], AssemblyModelImpl.prototype, "pumpContainer", 2);
1575
+ AssemblyModelImpl = __decorateClass$4([
1576
+ kosModel(MODEL_TYPE$4)
1577
+ ], AssemblyModelImpl);
1578
+ const Assembly = {
1579
+ registration: {
1580
+ [MODEL_TYPE$4]: {
1581
+ class: AssemblyModelImpl,
1582
+ singleton: true
1583
+ }
1584
+ },
1585
+ type: MODEL_TYPE$4,
1586
+ predicate: isKosModel(MODEL_TYPE$4),
1587
+ factory: Kos.Singleton.create(MODEL_TYPE$4)
1588
+ };
1589
+ var __getOwnPropDesc$3 = Object.getOwnPropertyDescriptor;
1590
+ var __decorateClass$3 = (decorators, target, key, kind) => {
1591
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$3(target, key) : target;
1592
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
1593
+ if (decorator = decorators[i])
1594
+ result = decorator(result) || result;
1595
+ return result;
1596
+ };
1597
+ const MODEL_TYPE$3 = DispenseModelType.Availability;
1598
+ let AvailabilityModelImpl = class {
1599
+ constructor(modelId, options, context) {
1600
+ __publicField(this, "id");
1601
+ __publicField(this, "data");
1602
+ __publicField(this, "properties");
1603
+ __publicField(this, "available");
1604
+ __publicField(this, "visible");
1605
+ __publicField(this, "groupId");
1606
+ __publicField(this, "rawId");
1607
+ __publicField(this, "altId");
1608
+ __publicField(this, "type");
1609
+ __publicField(this, "note");
1610
+ __publicField(this, "taggedIds");
1611
+ __publicField(this, "parentId");
1612
+ __publicField(this, "logger");
1613
+ this.id = modelId;
1614
+ this.taggedIds = options.taggedIds || [];
1615
+ this.logger = context.logger;
1616
+ this.available = options.available;
1617
+ this.visible = options.visible;
1618
+ this.groupId = options.groupId;
1619
+ this.rawId = options.rawId;
1620
+ this.altId = options.altId;
1621
+ this.type = options.type;
1622
+ this.parentId = options.kosParentId;
1623
+ this.data = options.data;
1624
+ this.note = options.note;
1625
+ this.properties = options.properties || {};
1626
+ }
1627
+ updateModel(options) {
1628
+ this.taggedIds = options.taggedIds || [];
1629
+ this.available = options.available;
1630
+ this.visible = options.visible;
1631
+ this.groupId = options.groupId;
1632
+ this.rawId = options.rawId;
1633
+ this.altId = options.altId;
1634
+ this.type = options.type;
1635
+ this.data = options.data;
1636
+ }
1637
+ updateAvailability(available) {
1638
+ this.available = available;
1639
+ }
1640
+ // -------------------LIFECYCLE----------------------------
1641
+ // -------------------ENTITY----------------------------
1642
+ };
1643
+ AvailabilityModelImpl = __decorateClass$3([
1644
+ kosParentAware(),
1645
+ kosModel(MODEL_TYPE$3)
1646
+ ], AvailabilityModelImpl);
1647
+ const Availability = {
1648
+ registration: {
1649
+ [MODEL_TYPE$3]: {
1650
+ class: AvailabilityModelImpl,
1651
+ singleton: false
1652
+ }
1653
+ },
1654
+ type: MODEL_TYPE$3,
1655
+ predicate: isKosModel(MODEL_TYPE$3),
1656
+ factory: Kos.Factory.create(
1657
+ MODEL_TYPE$3
1658
+ )
1659
+ };
1660
+ const { URL: URL$1 } = resolveServiceUrl("NOZZLE_SERVICE");
1661
+ const { postModel: postModel$1, deleteModel, getOne } = ServiceFactory.build({
1662
+ basePath: `${URL$1}/api/nozzle`
1663
+ });
1664
+ const pourPourable = async (nozzleId, tracker) => {
1665
+ const response = await postModel$1({
1666
+ model: {},
1667
+ urlOverride: `${URL$1}/api/ext/dispense/nozzle/${nozzleId}/pipeline/beverage/pour`,
1668
+ ordered: true,
1669
+ tracker
1670
+ });
1671
+ if (response == null ? void 0 : response.data) {
1672
+ FutureManager.initiateFuture(response.data);
1673
+ }
1674
+ return response;
1675
+ };
1676
+ const pourNamedPourable = async (name, nozzleId, tracker) => {
1677
+ const response = await postModel$1({
1678
+ model: {},
1679
+ urlOverride: `${URL$1}/api/ext/dispense/nozzle/${nozzleId}/pipeline/beverage/fixed/${name}`,
1680
+ ordered: true,
1681
+ tracker
1682
+ });
1683
+ if (response == null ? void 0 : response.data) {
1684
+ FutureManager.initiateFuture(response.data);
1685
+ }
1686
+ return response;
1687
+ };
1688
+ const getAvailability = async (urlPrefix) => {
1689
+ const response = await getOne({
1690
+ urlOverride: `${URL$1}${urlPrefix}/pipeline/beverage/availability`
1691
+ });
1692
+ return response;
1693
+ };
1694
+ const selectPourable = async (nozzleId, payload) => {
1695
+ const response = await postModel$1({
1696
+ model: payload,
1697
+ urlOverride: `${URL$1}/api/ext/dispense/nozzle/${nozzleId}/pipeline/beverage/select`
1698
+ });
1699
+ return response;
1700
+ };
1701
+ const clearPourable = async (nozzleId) => {
1702
+ const response = await deleteModel({
1703
+ id: nozzleId,
1704
+ urlOverride: `${URL$1}/api/ext/dispense/nozzle/${nozzleId}/pipeline/beverage/select`
1705
+ });
1706
+ return response;
1707
+ };
1708
+ var __defProp$2 = Object.defineProperty;
1709
+ var __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor;
1710
+ var __decorateClass$2 = (decorators, target, key, kind) => {
1711
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key) : target;
1712
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
1713
+ if (decorator = decorators[i])
1714
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
1715
+ if (kind && result)
1716
+ __defProp$2(target, key, result);
1717
+ return result;
1718
+ };
1719
+ const MODEL_TYPE$2 = DispenseModelType.Nozzle;
1720
+ const PROP_BEVERAGE_TOPIC_PREFIX = createPropKey(
1721
+ "beverageTopicPrefix"
1722
+ );
1723
+ const isPourAware$1 = (model) => model.onPourStart !== void 0 && model.onPourCancel !== void 0 && model.onPourProgress !== void 0;
1724
+ const TOPIC_NOZZLE_POUR_STARTED = "/kos/nozzle/pour/started";
1725
+ const TOPIC_NOZZLE_POUR_PROGRESS = "/kos/nozzle/pour/progress";
1726
+ const TOPIC_NOZZLE_POUR_CANCEL = "/kos/nozzle/pour/cancel";
1727
+ let NozzleModelImpl = class {
1728
+ constructor(modelId, options) {
1729
+ /** the unique identifier for this nozzle.*/
1730
+ __publicField(this, "id");
1731
+ __publicField(this, "path");
1732
+ __publicField(this, "name");
1733
+ __publicField(this, "_selectedBeverage");
1734
+ __publicField(this, "_selectedBrand");
1735
+ __publicField(this, "_additionalItems");
1736
+ __publicField(this, "_availabilityItems");
1737
+ __publicField(this, "futureHandler");
1738
+ __publicField(this, "beverageTopicPrefix");
1739
+ __publicField(this, "topicPrefix");
1740
+ __publicField(this, "urlPrefix");
1741
+ this.id = modelId;
1742
+ this.path = options.path;
1743
+ this.name = options.name;
1744
+ this.beverageTopicPrefix = options.beverageTopicPrefix;
1745
+ this.topicPrefix = options.topicPrefix;
1746
+ this.urlPrefix = options.urlPrefix;
1747
+ this._selectedBeverage = void 0;
1748
+ this._selectedBrand = void 0;
1749
+ this._additionalItems = [];
1750
+ this.futureHandler = new MultipleFutureHandler(this);
1751
+ this._availabilityItems = new KosModelContainer({
1752
+ indexMap: {
1753
+ byGroup: "groupId",
1754
+ byParent: "parentId"
1755
+ },
1756
+ parentId: modelId
1757
+ });
1758
+ }
1759
+ /**
1760
+ * The availability nodes that can be dispensed from this nozzle.
1761
+ * This is a subset of the availability for the entire dispenser
1762
+ * and is determined by the nodes associated with a nozzle.
1763
+ */
1764
+ get beverages() {
1765
+ return this._availabilityItems.getIndexByKey("byGroup", "beverages");
1766
+ }
1767
+ /**
1768
+ * The availability nodes that have been grouped into the "brands" group.
1769
+ *
1770
+ */
1771
+ get brands() {
1772
+ return this._availabilityItems.getIndexByKey("byGroup", "brands");
1773
+ }
1774
+ get visibleBrands() {
1775
+ return this.brands.filter((brand) => brand.visible);
1776
+ }
1777
+ get visibleBeverages() {
1778
+ return this.beverages.filter((beverage) => beverage.visible);
1779
+ }
1780
+ /**
1781
+ * A derived value that indicates if the nozzle is currently pouring a beverage.
1782
+ * @readonly
1783
+ */
1784
+ get isPouring() {
1785
+ var _a;
1786
+ return !!(this.futureHandler.getFuture() && !((_a = this.futureHandler.getFuture()) == null ? void 0 : _a.endState)) || this.currentState === PourState.POUR_STARTING || this.currentState === PourState.POURING || this.currentState === PourState.POUR_CANCELING;
1787
+ }
1788
+ /**
1789
+ * A derived value that indicates if the nozzle is currently available to pour a beverage.
1790
+ *
1791
+ * This will generally be determined by whether there is a currently selected pourable AND
1792
+ * the nozzle is not currently pouring.
1793
+ *
1794
+ * The value is observable and will change when the selected pourable changes or the nozzle
1795
+ * starts or stops pouring.
1796
+ * @readonly
1797
+ * */
1798
+ get canPour() {
1799
+ return !!this._selectedBeverage && this._selectedBeverage.available && this.currentState === PourState.IDLE;
1800
+ }
1801
+ /**
1802
+ * The selected pourable for this nozzle. Its shape is determined by the results of the
1803
+ * {@link ExtensionType.SelectedPourableMapper} extension.
1804
+ * @readonly
1805
+ *
1806
+ * */
1807
+ get selectedPourable() {
1808
+ return {
1809
+ beverage: this._selectedBeverage,
1810
+ additional: this._additionalItems
1811
+ };
1812
+ }
1813
+ get future() {
1814
+ return this.futureHandler.getFuture();
1815
+ }
1816
+ get pourProgress() {
1817
+ var _a;
1818
+ return ((_a = this.future) == null ? void 0 : _a.progress) ?? 0;
1819
+ }
1820
+ updateModel() {
1821
+ }
1822
+ // -------------------LIFECYCLE----------------------------
1823
+ setSelectedBrand(brand, _context) {
1824
+ if (_context) {
1825
+ this.logger.debug(`context is currenty being ignored when setting brand`);
1826
+ }
1827
+ this._selectedBrand = brand;
1828
+ this._selectedBeverage = void 0;
1829
+ }
1830
+ get selectedBrand() {
1831
+ return this._selectedBrand;
1832
+ }
1833
+ /**
1834
+ * Set the values used to determine the selected pourable for this nozzle.
1835
+ *
1836
+ * @param pourable The pourable to set.
1837
+ * @param pourable.beverage The beverage selected.
1838
+ * @param pourable.additional The additional items such as flavors or other items that could be incorporated
1839
+ * into the pourable.
1840
+ * */
1841
+ async setSelectedPourable({ beverage, additional, context }, forceUpdate = false) {
1842
+ if (!beverage) {
1843
+ const response2 = await clearPourable(this.name);
1844
+ if ((response2 == null ? void 0 : response2.status) !== 200) {
1845
+ throw new Error("Failed to clear pourable");
1846
+ }
1847
+ this._selectedBeverage = void 0;
1848
+ return;
1849
+ }
1850
+ if (!forceUpdate && beverage === this._selectedBeverage && arraysEqual(this._additionalItems, additional)) {
1851
+ this.logger.info("No change in selected pourable");
1852
+ return;
1853
+ }
1854
+ this._selectedBeverage = beverage;
1855
+ this._additionalItems = additional;
1856
+ let selectedPayload;
1857
+ try {
1858
+ selectedPayload = await ExtensionManager.dataMapper.executeMapper(
1859
+ ExtensionType.SelectedPourableMapper,
1860
+ {
1861
+ beverage,
1862
+ additional,
1863
+ context
1864
+ }
1865
+ );
1866
+ } catch (e) {
1867
+ this.logger.error(
1868
+ `Error executing SelectedPourableMapper, falling back to default payload. Error: ${e}`
1869
+ );
1870
+ selectedPayload = void 0;
1871
+ }
1872
+ const defaultPayload = {
1873
+ bevId: beverage.rawId
1874
+ };
1875
+ if (!selectedPayload || Object.keys(selectedPayload).length === 0) {
1876
+ this.logger.info(
1877
+ `No selected pourable mapper defined, using the default payload ${defaultPayload}`
1878
+ );
1879
+ selectedPayload = defaultPayload;
1880
+ }
1881
+ const payload = selectedPayload ?? defaultPayload;
1882
+ const response = await selectPourable(this.name, payload);
1883
+ if ((response == null ? void 0 : response.status) !== 200) {
1884
+ throw new Error("Failed to select pourable");
1885
+ }
1886
+ }
1887
+ /**
1888
+ * Utility method that will return the availability nodes that belong to the specified
1889
+ * group as defined in the dispenser beverage graph. For example, a dispenser
1890
+ * implementation may group availability nodes by Brand, Beverage, or Flavors
1891
+ *
1892
+ * @param groupId The group to filter by.
1893
+ * @returns The availability nodes that are available to be dispensed from this nozzle
1894
+ * and are in the specified group.
1895
+ * */
1896
+ getGroupAvailabilityItems(groupId) {
1897
+ return this._availabilityItems.getIndexByKey(
1898
+ "byGroup",
1899
+ groupId
1900
+ );
1901
+ }
1902
+ /**
1903
+ * Utility method that will return the availability nodes that are tagged with the specified parent id.
1904
+ *
1905
+ * This is useful when brandsets use the taggedIds property to associate nodes with a parent node. For example,
1906
+ * when organizing a brandset into brands and beverages, the brand nodes will be tagged with the beverage nodes.
1907
+ *
1908
+ * @param parentId - The parent id to filter by.
1909
+ * @returns the availability nodes that are tagged with the specified parent id.
1910
+ */
1911
+ getAvailabilityByParent(parentId) {
1912
+ return this._availabilityItems.getIndexByKey(
1913
+ "byParent",
1914
+ parentId
1915
+ );
1916
+ }
1917
+ handlePouringStart() {
1918
+ this.logger.info("Pour started");
1919
+ getAllKosCompanionModels(this).forEach((model) => {
1920
+ var _a;
1921
+ if (isPourAware$1(model)) {
1922
+ (_a = model.onPourStart) == null ? void 0 : _a.call(model);
1923
+ }
1924
+ });
1925
+ }
1926
+ handlePouringEnd() {
1927
+ this.logger.info("Pour ended");
1928
+ }
1929
+ handleCancelStart() {
1930
+ this.logger.info("Pour canceling");
1931
+ }
1932
+ handleCanceled() {
1933
+ this.logger.info("Pour canceled");
1934
+ getAllKosCompanionModels(this).forEach((model) => {
1935
+ var _a;
1936
+ if (isPourAware$1(model)) {
1937
+ (_a = model.onPourCancel) == null ? void 0 : _a.call(model);
1938
+ }
1939
+ });
1940
+ const evt = {
1941
+ nozzleId: this.id
1942
+ };
1943
+ EventBus.publish(TOPIC_NOZZLE_POUR_CANCEL, evt);
1944
+ }
1945
+ // ============================================================================
1946
+ // Future Lifecycle Handler
1947
+ // ============================================================================
1948
+ onFutureUpdate(future) {
1949
+ const companions = getAllKosCompanionModels(this);
1950
+ companions.forEach((model) => {
1951
+ if (isPourAware$1(model)) {
1952
+ model.onPourProgress(future);
1953
+ }
1954
+ });
1955
+ const evt = {
1956
+ nozzleId: this.id,
1957
+ progress: future.progress,
1958
+ status: future.status,
1959
+ clientData: future.clientData,
1960
+ futureId: future.futureId,
1961
+ remainingTimeMs: future.remainingTimeMs,
1962
+ endState: future.endState,
1963
+ reason: future.reason,
1964
+ timeRemaining: future.timeRemaining
1965
+ };
1966
+ EventBus.publish(TOPIC_NOZZLE_POUR_PROGRESS, evt);
1967
+ if (future.endState) {
1968
+ kosAction(() => {
1969
+ if (this.currentState === PourState.POURING) {
1970
+ this.transition("POUR_COMPLETED");
1971
+ }
1972
+ });
1973
+ }
1974
+ }
1975
+ // Inherits throwOnInvalid: false from class
1976
+ async pour(tracker) {
1977
+ var _a;
1978
+ try {
1979
+ this.transition("START_POUR");
1980
+ if (!tracker) {
1981
+ throw new Error("No tracker provided");
1982
+ }
1983
+ const result = await pourPourable(this.name, tracker);
1984
+ this.transition("POUR_ACTIVE");
1985
+ const evt = {
1986
+ nozzleId: this.id,
1987
+ type: "free"
1988
+ };
1989
+ EventBus.publish(TOPIC_NOZZLE_POUR_STARTED, evt);
1990
+ if ((_a = result == null ? void 0 : result.data) == null ? void 0 : _a.endState) {
1991
+ this.transition("POUR_COMPLETED");
1992
+ }
1993
+ return result;
1994
+ } catch (e) {
1995
+ this.logger.error(e);
1996
+ if (this.currentState !== PourState.IDLE) {
1997
+ this.transition("POUR_COMPLETED");
1998
+ }
1999
+ throw e;
2000
+ }
2001
+ }
2002
+ // Inherits throwOnInvalid: false from class
2003
+ async fixedPour(name, tracker) {
2004
+ var _a;
2005
+ try {
2006
+ this.transition("START_POUR");
2007
+ if (!tracker) {
2008
+ throw new Error("No tracker provided");
2009
+ }
2010
+ const result = await pourNamedPourable(name, this.name, tracker);
2011
+ this.transition("POUR_ACTIVE");
2012
+ const evt = {
2013
+ nozzleId: this.id,
2014
+ type: "fixed"
2015
+ };
2016
+ EventBus.publish(TOPIC_NOZZLE_POUR_STARTED, evt);
2017
+ if ((_a = result == null ? void 0 : result.data) == null ? void 0 : _a.endState) {
2018
+ this.transition("POUR_COMPLETED");
2019
+ }
2020
+ return result;
2021
+ } catch (e) {
2022
+ this.logger.error(e);
2023
+ if (this.currentState !== PourState.IDLE) {
2024
+ this.transition("POUR_COMPLETED");
2025
+ }
2026
+ throw e;
2027
+ }
2028
+ }
2029
+ // Inherits throwOnInvalid: false - silently ignore if already idle
2030
+ async cancelPour() {
2031
+ var _a;
2032
+ this.transition("CANCEL_POUR");
2033
+ await ((_a = this.futureHandler.getFuture()) == null ? void 0 : _a.cancelFuture());
2034
+ this.transition("POUR_CANCELED");
2035
+ }
2036
+ updateGroupMembers() {
2037
+ this._availabilityItems.data.forEach((item) => {
2038
+ const taggedIds = item.taggedIds || [];
2039
+ taggedIds.forEach((taggedId) => {
2040
+ const childItem = this._availabilityItems.data.find(
2041
+ (beverage) => beverage.rawId === taggedId
2042
+ );
2043
+ if (childItem && childItem.parentId !== item.id) {
2044
+ childItem.parentId = item.id;
2045
+ this._availabilityItems.updateModel(childItem);
2046
+ }
2047
+ });
2048
+ });
2049
+ }
2050
+ async reload() {
2051
+ this.logger.info(`reloading nozzle ${this.id}`);
2052
+ const context = KosContextManager.getContext(this.id);
2053
+ (context == null ? void 0 : context.get(ExtensionType.AvailabilityLoader)) || {};
2054
+ const availability = await getAvailability(this.urlPrefix);
2055
+ if ((availability == null ? void 0 : availability.status) !== 200 || !(availability == null ? void 0 : availability.data)) {
2056
+ this.logger.error("Failed to load nozzle availability");
2057
+ return;
2058
+ }
2059
+ const update = availability == null ? void 0 : availability.data;
2060
+ if (update) {
2061
+ await this.updateAvailability(update);
2062
+ }
2063
+ }
2064
+ /** @internal */
2065
+ async load(context) {
2066
+ var _a, _b;
2067
+ this.logger.debug(`loading nozzle ${this.id}`);
2068
+ const availability = await getAvailability(this.urlPrefix);
2069
+ if ((availability == null ? void 0 : availability.status) !== 200) {
2070
+ throw new Error("Failed to load nozzle availability");
2071
+ }
2072
+ const beverageContext = await ExtensionManager.loader.executeLoader(
2073
+ ExtensionType.AvailabilityLoader,
2074
+ {}
2075
+ );
2076
+ context == null ? void 0 : context.set(ExtensionType.AvailabilityLoader, beverageContext);
2077
+ context == null ? void 0 : context.set(Nozzle.type, this);
2078
+ for (const group of Object.keys((_a = availability.data) == null ? void 0 : _a.groups) || []) {
2079
+ for (const beverageData of ((_b = availability.data) == null ? void 0 : _b.groups[group]) || []) {
2080
+ const extensionData = await ExtensionManager.dataMapper.executeMapper(
2081
+ ExtensionType.AvailabilityMapper,
2082
+ { ...beverageData, groupId: group },
2083
+ beverageContext
2084
+ );
2085
+ const beverageOptions = {
2086
+ ...beverageData,
2087
+ note: beverageData.note ?? void 0,
2088
+ kosParentId: this.id,
2089
+ rawId: beverageData.id,
2090
+ groupId: group,
2091
+ data: extensionData,
2092
+ properties: beverageData.properties || {}
2093
+ };
2094
+ const beverage = Availability.factory(
2095
+ `${this.id}-${group}-${beverageData.id}`
2096
+ )(beverageOptions);
2097
+ this._availabilityItems.addModel(beverage);
2098
+ }
2099
+ }
2100
+ this.updateGroupMembers();
2101
+ }
2102
+ async updateAvailability(update) {
2103
+ const context = KosContextManager.getContext(this.id);
2104
+ const beverageContext = (context == null ? void 0 : context.get(ExtensionType.AvailabilityLoader)) || {};
2105
+ if (update.rebuild) {
2106
+ for (const group of Object.keys(update == null ? void 0 : update.groups) || []) {
2107
+ const deletedBeverages = this._availabilityItems.getIndexByKey("group", group).filter(
2108
+ (beverage) => !update.groups[group].find(
2109
+ (b) => `${this.id}-${group}-${b.id}` === beverage.id
2110
+ )
2111
+ );
2112
+ deletedBeverages.forEach((beverage) => {
2113
+ this._availabilityItems.removeModel(beverage.id);
2114
+ destroyKosModel(beverage);
2115
+ });
2116
+ for (const beverageData of (update == null ? void 0 : update.groups[group]) || []) {
2117
+ const extensionData = await ExtensionManager.dataMapper.executeMapper(
2118
+ ExtensionType.AvailabilityMapper,
2119
+ { ...beverageData, groupId: group },
2120
+ beverageContext
2121
+ );
2122
+ const beverageOptions = {
2123
+ ...beverageData,
2124
+ note: beverageData.note ?? void 0,
2125
+ kosParentId: this.id,
2126
+ groupId: group,
2127
+ rawId: beverageData.id,
2128
+ data: extensionData,
2129
+ taggedIds: beverageData.taggedIds,
2130
+ properties: beverageData.properties || {}
2131
+ };
2132
+ const existing = this._availabilityItems.getModel(
2133
+ `${this.id}-${group}-${beverageData.id}`
2134
+ );
2135
+ if (existing) {
2136
+ existing.updateModel(beverageOptions);
2137
+ } else {
2138
+ const beverage = Availability.factory(
2139
+ `${this.id}-${group}-${beverageData.id}`
2140
+ )(beverageOptions);
2141
+ this._availabilityItems.addModel(beverage);
2142
+ }
2143
+ }
2144
+ }
2145
+ } else {
2146
+ for (const group of Object.keys(update == null ? void 0 : update.groups) || []) {
2147
+ for (const beverageData of (update == null ? void 0 : update.groups[group]) || []) {
2148
+ const extensionData = await ExtensionManager.dataMapper.executeMapper(
2149
+ ExtensionType.AvailabilityMapper,
2150
+ { ...beverageData, groupId: group },
2151
+ beverageContext
2152
+ );
2153
+ const beverageOptions = {
2154
+ ...beverageData,
2155
+ note: beverageData.note ?? void 0,
2156
+ kosParentId: this.id,
2157
+ groupId: group,
2158
+ rawId: beverageData.id,
2159
+ data: extensionData,
2160
+ type: beverageData.type,
2161
+ taggedIds: beverageData.taggedIds,
2162
+ properties: beverageData.properties || {}
2163
+ };
2164
+ const existing = this._availabilityItems.getModel(
2165
+ `${this.id}-${group}-${beverageData.id}`
2166
+ );
2167
+ if (existing) {
2168
+ existing.updateModel(beverageOptions);
2169
+ }
2170
+ }
2171
+ }
2172
+ }
2173
+ this.updateGroupMembers();
2174
+ }
2175
+ // -------------------ENTITY----------------------------
2176
+ };
2177
+ __decorateClass$2([
2178
+ kosChild
2179
+ ], NozzleModelImpl.prototype, "_availabilityItems", 2);
2180
+ __decorateClass$2([
2181
+ kosStateEntry(PourState.POURING)
2182
+ ], NozzleModelImpl.prototype, "handlePouringStart", 1);
2183
+ __decorateClass$2([
2184
+ kosStateExit(PourState.POURING)
2185
+ ], NozzleModelImpl.prototype, "handlePouringEnd", 1);
2186
+ __decorateClass$2([
2187
+ kosStateEntry(PourState.POUR_CANCELING)
2188
+ ], NozzleModelImpl.prototype, "handleCancelStart", 1);
2189
+ __decorateClass$2([
2190
+ kosStateExit(PourState.POUR_CANCELING)
2191
+ ], NozzleModelImpl.prototype, "handleCanceled", 1);
2192
+ __decorateClass$2([
2193
+ kosFuture(),
2194
+ kosStateGuard({ allowedStates: [PourState.IDLE] })
2195
+ ], NozzleModelImpl.prototype, "pour", 1);
2196
+ __decorateClass$2([
2197
+ kosFuture(),
2198
+ kosStateGuard({ allowedStates: [PourState.IDLE] })
2199
+ ], NozzleModelImpl.prototype, "fixedPour", 1);
2200
+ __decorateClass$2([
2201
+ kosStateGuard({
2202
+ allowedStates: [PourState.POUR_STARTING, PourState.POURING]
2203
+ })
2204
+ ], NozzleModelImpl.prototype, "cancelPour", 1);
2205
+ __decorateClass$2([
2206
+ kosTopicHandler({
2207
+ topic: `${PROP_BEVERAGE_TOPIC_PREFIX}/availability`,
2208
+ websocket: true
2209
+ })
2210
+ ], NozzleModelImpl.prototype, "updateAvailability", 1);
2211
+ NozzleModelImpl = __decorateClass$2([
2212
+ kosModel({ modelTypeId: MODEL_TYPE$2, singleton: false }),
2213
+ kosLoggerAware(),
2214
+ kosStateMachine(
2215
+ {
2216
+ initial: PourState.IDLE,
2217
+ initializeAt: DependencyLifecycle.READY,
2218
+ states: {
2219
+ [PourState.IDLE]: {
2220
+ on: {
2221
+ START_POUR: PourState.POUR_STARTING
2222
+ }
2223
+ },
2224
+ [PourState.POUR_STARTING]: {
2225
+ on: {
2226
+ POUR_ACTIVE: PourState.POURING,
2227
+ CANCEL_POUR: PourState.POUR_CANCELING,
2228
+ POUR_COMPLETED: PourState.IDLE
2229
+ }
2230
+ },
2231
+ [PourState.POURING]: {
2232
+ on: {
2233
+ CANCEL_POUR: PourState.POUR_CANCELING,
2234
+ POUR_COMPLETED: PourState.IDLE
2235
+ }
2236
+ },
2237
+ [PourState.POUR_CANCELING]: {
2238
+ on: {
2239
+ POUR_CANCELED: PourState.IDLE
2240
+ }
2241
+ }
2242
+ }
2243
+ },
2244
+ {
2245
+ trackHistory: false,
2246
+ throwOnInvalid: false
2247
+ // Gracefully ignore invalid state calls (expected runtime scenarios)
2248
+ }
2249
+ )
2250
+ ], NozzleModelImpl);
2251
+ const Nozzle = {
2252
+ registration: {
2253
+ [MODEL_TYPE$2]: {
2254
+ class: NozzleModelImpl,
2255
+ singleton: false
2256
+ }
2257
+ },
2258
+ type: MODEL_TYPE$2,
2259
+ predicate: isKosModel(MODEL_TYPE$2),
2260
+ factory: Kos.Factory.create(MODEL_TYPE$2)
2261
+ };
2262
+ var __defProp$1 = Object.defineProperty;
2263
+ var __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor;
2264
+ var __decorateClass$1 = (decorators, target, key, kind) => {
2265
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target;
2266
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
2267
+ if (decorator = decorators[i])
2268
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
2269
+ if (kind && result)
2270
+ __defProp$1(target, key, result);
2271
+ return result;
2272
+ };
2273
+ const MODEL_TYPE$1 = "device-assembly-model";
2274
+ let DeviceAssemblyModelImpl = class {
2275
+ constructor(modelId, _options, context) {
2276
+ __publicField(this, "id");
2277
+ __publicField(this, "deviceNozzles");
2278
+ __publicField(this, "logger");
2279
+ this.id = modelId;
2280
+ this.logger = context.logger;
2281
+ this.deviceNozzles = new KosModelContainer();
2282
+ }
2283
+ // -------------------LIFECYCLE----------------------------
2284
+ async init() {
2285
+ this.logger.debug(`initializing device-assembly ${this.id}`);
2286
+ }
2287
+ getNozzle(path) {
2288
+ return this.deviceNozzles.getModel(path);
2289
+ }
2290
+ get nozzlePaths() {
2291
+ return this.deviceNozzles.data.map((nozzle) => nozzle.path);
2292
+ }
2293
+ async load() {
2294
+ this.logger.debug(`loading device-assembly ${this.id}`);
2295
+ const result = await getAssembly();
2296
+ if ((result == null ? void 0 : result.status) === 200) {
2297
+ const nozzles = result.data.assemblies.map((assembly) => assembly.nozzles ?? []).flat();
2298
+ nozzles.forEach((nozzleData) => {
2299
+ var _a;
2300
+ const nozzleId = nozzleData.path;
2301
+ const beverageTopicPrefix = ((_a = nozzleData.pipelines.find((pipeline) => pipeline.name === "beverage")) == null ? void 0 : _a.topicPrefix) || "";
2302
+ const nozzle = Nozzle.factory(nozzleId)({
2303
+ path: nozzleData.path,
2304
+ name: nozzleData.name,
2305
+ urlPrefix: nozzleData.urlPrefix,
2306
+ topicPrefix: nozzleData.topicPrefix,
2307
+ beverageTopicPrefix
2308
+ });
2309
+ this.deviceNozzles.addModel(nozzle);
2310
+ });
2311
+ }
2312
+ }
2313
+ };
2314
+ __decorateClass$1([
2315
+ kosChild
2316
+ ], DeviceAssemblyModelImpl.prototype, "deviceNozzles", 2);
2317
+ DeviceAssemblyModelImpl = __decorateClass$1([
2318
+ kosModel(MODEL_TYPE$1)
2319
+ ], DeviceAssemblyModelImpl);
2320
+ const DeviceAssembly = new SingletonKosModelRegistrationFactory({
2321
+ class: DeviceAssemblyModelImpl,
2322
+ type: MODEL_TYPE$1
2323
+ });
2324
+ const { URL } = resolveServiceUrl("GENERIC_POUR_SERVICE");
2325
+ const { postModel } = ServiceFactory.build({
2326
+ basePath: `${URL}/api/nozzle`
2327
+ });
2328
+ const pourOnTarget = async (path, tracker) => {
2329
+ const response = await postModel({
2330
+ model: {},
2331
+ urlOverride: `${URL}${path}`,
2332
+ ordered: true,
2333
+ tracker
2334
+ });
2335
+ if (response == null ? void 0 : response.data) {
2336
+ FutureManager.initiateFuture(response.data);
2337
+ }
2338
+ return response;
2339
+ };
2340
+ var __defProp2 = Object.defineProperty;
2341
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
2342
+ var __decorateClass = (decorators, target, key, kind) => {
2343
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
2344
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
2345
+ if (decorator = decorators[i])
2346
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
2347
+ if (kind && result)
2348
+ __defProp2(target, key, result);
2349
+ return result;
2350
+ };
2351
+ const MODEL_TYPE = "generic-pour-model";
2352
+ const TOPIC_GENERIC_POUR_STARTED = "/kos/generic/pour/started";
2353
+ const TOPIC_GENERIC_POUR_PROGRESS = "/kos/generic/pour/progress";
2354
+ const TOPIC_GENERIC_POUR_CANCEL = "/kos/generic/pour/cancel";
2355
+ const isPourAware = (model) => model.onPourStart !== void 0 && model.onPourCancel !== void 0 && model.onPourProgress !== void 0;
2356
+ let GenericPourModelImpl = class {
2357
+ constructor(modelId, options) {
2358
+ __publicField(this, "id");
2359
+ /**
2360
+ * @kosApiLevel 5
2361
+ */
2362
+ __publicField(this, "servicePathFactory");
2363
+ __publicField(this, "pourType");
2364
+ /**
2365
+ * @kosApiLevel 5
2366
+ */
2367
+ __publicField(this, "selectedId");
2368
+ __publicField(this, "state");
2369
+ this.id = modelId;
2370
+ this.futureHandler = new FutureHandler(this);
2371
+ this.servicePathFactory = options.servicePathFactory;
2372
+ this.pourType = options.pourType || "free";
2373
+ this.selectedId = options.selectedId;
2374
+ this.state = ObservableData(options.initialData || {});
2375
+ }
2376
+ get servicePath() {
2377
+ if (!this.selectedId) {
2378
+ return "";
2379
+ }
2380
+ return this.servicePathFactory(this.selectedId, this.state);
2381
+ }
2382
+ /**
2383
+ * @kosApiLevel 12
2384
+ */
2385
+ updateContextData(key, value) {
2386
+ this.state[key] = value;
2387
+ }
2388
+ /**
2389
+ * @kosApiLevel 12
2390
+ */
2391
+ removeContextData(key) {
2392
+ delete this.state[key];
2393
+ }
2394
+ /**
2395
+ * @kosApiLevel 12
2396
+ */
2397
+ clearContextData() {
2398
+ this.state = ObservableData();
2399
+ }
2400
+ /**
2401
+ * @kosApiLevel 14
2402
+ */
2403
+ updateModel(options) {
2404
+ if (options.pourType) {
2405
+ this.pourType = options.pourType;
2406
+ }
2407
+ if (options.initialData) {
2408
+ this.state.setValues(options.initialData);
2409
+ }
2410
+ }
2411
+ handlePouringStart() {
2412
+ this.logger.info("Pour started");
2413
+ getAllKosCompanionModels(this).forEach((model) => {
2414
+ var _a;
2415
+ if (isPourAware(model)) {
2416
+ (_a = model.onPourStart) == null ? void 0 : _a.call(model);
2417
+ }
2418
+ });
2419
+ const evt = {
2420
+ pourTarget: this.id,
2421
+ type: this.pourType
2422
+ };
2423
+ EventBus.publish(TOPIC_GENERIC_POUR_STARTED, evt);
2424
+ }
2425
+ handlePouringEnd() {
2426
+ this.logger.info("Pour ended");
2427
+ }
2428
+ handleCancelStart() {
2429
+ this.logger.info("Pour canceling");
2430
+ }
2431
+ handleCanceled() {
2432
+ this.logger.info("Pour canceled");
2433
+ getAllKosCompanionModels(this).forEach((model) => {
2434
+ var _a;
2435
+ if (isPourAware(model)) {
2436
+ (_a = model.onPourCancel) == null ? void 0 : _a.call(model);
2437
+ }
2438
+ });
2439
+ const evt = {
2440
+ pourTarget: this.id
2441
+ };
2442
+ EventBus.publish(TOPIC_GENERIC_POUR_CANCEL, evt);
2443
+ }
2444
+ // Inherits throwOnInvalid: false from class
2445
+ async pour(tracker) {
2446
+ var _a;
2447
+ try {
2448
+ this.transition("START_POUR");
2449
+ if (!tracker) {
2450
+ throw new Error("No tracker provided");
2451
+ }
2452
+ const result = await pourOnTarget(this.servicePath, tracker);
2453
+ this.transition("POUR_ACTIVE");
2454
+ if ((_a = result == null ? void 0 : result.data) == null ? void 0 : _a.endState) {
2455
+ this.transition("POUR_COMPLETED");
2456
+ }
2457
+ return result;
2458
+ } catch (e) {
2459
+ this.logger.error(e);
2460
+ if (this.currentState !== PourState.IDLE) {
2461
+ this.transition("POUR_COMPLETED");
2462
+ }
2463
+ throw e;
2464
+ }
2465
+ }
2466
+ // Inherits throwOnInvalid: false - silently ignore if already idle
2467
+ async cancelPour() {
2468
+ var _a;
2469
+ this.transition("CANCEL_POUR");
2470
+ await ((_a = this.futureHandler.getFuture()) == null ? void 0 : _a.cancelFuture());
2471
+ this.transition("POUR_CANCELED");
2472
+ }
2473
+ // ============================================================================
2474
+ // Computed Properties
2475
+ // ============================================================================
2476
+ /**
2477
+ * A derived value that indicates if the nozzle is currently pouring a beverage.
2478
+ * @readonly
2479
+ */
2480
+ get isPouring() {
2481
+ var _a;
2482
+ return !!(this.future && !((_a = this.future) == null ? void 0 : _a.endState)) || this.currentState === PourState.POUR_STARTING || this.currentState === PourState.POURING || this.currentState === PourState.POUR_CANCELING;
2483
+ }
2484
+ /**
2485
+ * A derived value that indicates if the pour target is currently available to pour a beverage.
2486
+ *
2487
+ * Generally this means that the pour target is currently idle and not in the process of pouring,
2488
+ * initiating a pour, or canceling a pour.
2489
+ * The value is observable and will change when the selected pourable changes or the pour target
2490
+ * starts or stops pouring.
2491
+ * @readonly
2492
+ */
2493
+ get canPour() {
2494
+ return this.currentState === PourState.IDLE;
2495
+ }
2496
+ get pourProgress() {
2497
+ return this.progress ?? 0;
2498
+ }
2499
+ // ============================================================================
2500
+ // Future Lifecycle Handler
2501
+ // ============================================================================
2502
+ onFutureUpdate(future) {
2503
+ getAllKosCompanionModels(this).forEach((model) => {
2504
+ if (isPourAware(model)) {
2505
+ model.onPourProgress(future);
2506
+ }
2507
+ });
2508
+ const evt = {
2509
+ pourTarget: this.id,
2510
+ progress: future.progress,
2511
+ status: future.status,
2512
+ clientData: future.clientData,
2513
+ futureId: future.futureId,
2514
+ remainingTimeMs: future.remainingTimeMs,
2515
+ endState: future.endState,
2516
+ reason: future.reason,
2517
+ timeRemaining: future.timeRemaining
2518
+ };
2519
+ EventBus.publish(TOPIC_GENERIC_POUR_PROGRESS, evt);
2520
+ if (future.endState) {
2521
+ kosAction(() => {
2522
+ if (this.currentState === PourState.POURING) {
2523
+ this.transition("POUR_COMPLETED");
2524
+ }
2525
+ });
2526
+ }
2527
+ }
2528
+ };
2529
+ __decorateClass([
2530
+ kosStateEntry(PourState.POURING)
2531
+ ], GenericPourModelImpl.prototype, "handlePouringStart", 1);
2532
+ __decorateClass([
2533
+ kosStateExit(PourState.POURING)
2534
+ ], GenericPourModelImpl.prototype, "handlePouringEnd", 1);
2535
+ __decorateClass([
2536
+ kosStateEntry(PourState.POUR_CANCELING)
2537
+ ], GenericPourModelImpl.prototype, "handleCancelStart", 1);
2538
+ __decorateClass([
2539
+ kosStateExit(PourState.POUR_CANCELING)
2540
+ ], GenericPourModelImpl.prototype, "handleCanceled", 1);
2541
+ __decorateClass([
2542
+ kosFuture(),
2543
+ kosStateGuard({ allowedStates: [PourState.IDLE] })
2544
+ ], GenericPourModelImpl.prototype, "pour", 1);
2545
+ __decorateClass([
2546
+ kosStateGuard({
2547
+ allowedStates: [PourState.POUR_STARTING, PourState.POURING]
2548
+ })
2549
+ ], GenericPourModelImpl.prototype, "cancelPour", 1);
2550
+ GenericPourModelImpl = __decorateClass([
2551
+ kosModel(MODEL_TYPE),
2552
+ kosLoggerAware(),
2553
+ kosFutureAware(),
2554
+ kosStateMachine(
2555
+ {
2556
+ initial: PourState.IDLE,
2557
+ initializeAt: DependencyLifecycle.READY,
2558
+ states: {
2559
+ [PourState.IDLE]: {
2560
+ on: {
2561
+ START_POUR: PourState.POUR_STARTING
2562
+ }
2563
+ },
2564
+ [PourState.POUR_STARTING]: {
2565
+ on: {
2566
+ POUR_ACTIVE: PourState.POURING,
2567
+ CANCEL_POUR: PourState.POUR_CANCELING,
2568
+ POUR_COMPLETED: PourState.IDLE
2569
+ }
2570
+ },
2571
+ [PourState.POURING]: {
2572
+ on: {
2573
+ CANCEL_POUR: PourState.POUR_CANCELING,
2574
+ POUR_COMPLETED: PourState.IDLE
2575
+ }
2576
+ },
2577
+ [PourState.POUR_CANCELING]: {
2578
+ on: {
2579
+ POUR_CANCELED: PourState.IDLE
2580
+ }
2581
+ }
2582
+ }
2583
+ },
2584
+ {
2585
+ trackHistory: false,
2586
+ throwOnInvalid: false
2587
+ // Gracefully ignore invalid state calls (expected runtime scenarios)
2588
+ }
2589
+ )
2590
+ ], GenericPourModelImpl);
2591
+ const GenericPour = new KosModelRegistrationFactory({
2592
+ class: GenericPourModelImpl,
2593
+ type: MODEL_TYPE
2594
+ });
2595
+ const kosModels = {
2596
+ ...IngredientContainer.registration,
2597
+ ...Ingredient.registration,
2598
+ ...HolderContainer.registration,
2599
+ ...Holder.registration,
2600
+ ...Nozzle.registration,
2601
+ ...Pump.registration,
2602
+ ...PumpContainer.registration,
2603
+ ...Availability.registration,
2604
+ ...Assembly.registration,
2605
+ ...BoardContainer.registration
2606
+ };
2607
+ const registerDispenseModels = (root) => () => {
2608
+ registerCoreModels(root)();
2609
+ DeviceAssembly.register();
2610
+ Object.keys(kosModels).forEach((key) => {
2611
+ const model = kosModels[key];
2612
+ registerLegacyModel(root)(key, model);
2613
+ });
2614
+ ExtensionManager[EXTENSION_TROUBLE_DATA_MAPPER].register(
2615
+ "FirmwareUpdateInProgressTrouble",
2616
+ async (trouble) => {
2617
+ var _a;
2618
+ if ((_a = trouble.data) == null ? void 0 : _a.deviceId) {
2619
+ const { model: assemblyModel } = getKosModelSync(
2620
+ Assembly.type
2621
+ );
2622
+ if (assemblyModel) {
2623
+ const boardModel = assemblyModel.boards.find(
2624
+ (b) => b.id === trouble.data.deviceId
2625
+ ) ? getKosModelSync(trouble.data.deviceId).model : void 0;
2626
+ return {
2627
+ devices: boardModel ? boardModel.name : ""
2628
+ };
2629
+ }
2630
+ }
2631
+ return {};
2632
+ }
2633
+ );
2634
+ return {
2635
+ preload: RegistrationManager.model.preloadModel(root),
2636
+ model: RegistrationManager.model.register(root),
2637
+ companion: RegistrationManager.companion.register(root),
2638
+ legacy: RegistrationManager.model.registerLegacyModel(root)
2639
+ };
2640
+ };
2641
+ const _KosModelRegistry = {
2642
+ ...KosModelRegistry$1
2643
+ };
2644
+ _KosModelRegistry.dispense = {
2645
+ models: registerDispenseModels(_KosModelRegistry)
2646
+ };
2647
+ _KosModelRegistry.preload = RegistrationManager.model.preloadModel(_KosModelRegistry);
2648
+ _KosModelRegistry.model = RegistrationManager.model.register(_KosModelRegistry);
2649
+ _KosModelRegistry.companion = RegistrationManager.companion.register(_KosModelRegistry);
2650
+ _KosModelRegistry.legacy = RegistrationManager.model.registerLegacyModel(_KosModelRegistry);
2651
+ const KosModelRegistry = _KosModelRegistry;
2652
+ export {
2653
+ Assembly as A,
2654
+ BoardContainerModel as B,
2655
+ CONTEXT_ASSEMBLY_DATA as C,
2656
+ DispenseModelType as D,
2657
+ ExtensionType as E,
2658
+ getIntentVolume as F,
2659
+ GenericPour as G,
2660
+ Holder as H,
2661
+ Ingredient as I,
2662
+ sendIntent as J,
2663
+ KosModelRegistry as K,
2664
+ clearPourable as L,
2665
+ getAvailability as M,
2666
+ Nozzle as N,
2667
+ pourNamedPourable as O,
2668
+ Pump as P,
2669
+ pourPourable as Q,
2670
+ selectPourable as R,
2671
+ pourOnTarget as S,
2672
+ TOPIC_BOARD_LINKED as T,
2673
+ CONTEXT_ASSEMBLY_RAW_DATA as a,
2674
+ Availability as b,
2675
+ TOPIC_BOARD_UNLINKED as c,
2676
+ BoardContainer as d,
2677
+ Board as e,
2678
+ DeviceAssembly as f,
2679
+ TOPIC_GENERIC_POUR_CANCEL as g,
2680
+ TOPIC_GENERIC_POUR_PROGRESS as h,
2681
+ TOPIC_GENERIC_POUR_STARTED as i,
2682
+ HolderContainer as j,
2683
+ IngredientContainer as k,
2684
+ PumpContainer as l,
2685
+ PumpIndex as m,
2686
+ PourState as n,
2687
+ kosModels as o,
2688
+ getIngredients as p,
2689
+ addAssignment as q,
2690
+ registerDispenseModels as r,
2691
+ assignHolderIngredient as s,
2692
+ deleteAssignment as t,
2693
+ getAssignments as u,
2694
+ getHolders as v,
2695
+ replaceLine as w,
2696
+ sendRfidOverride as x,
2697
+ unassignHolderIngredient as y,
2698
+ getAssembly as z
2699
+ };
2700
+ //# sourceMappingURL=dispense-registration-manager-lJlcyq5G.js.map