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

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