@kosdev-code/kos-ui-sdk 0.1.0-next.948 → 0.1.0-next.962

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 (66) hide show
  1. package/.kos.json +2 -1
  2. package/core/core/decorators/kos-container-aware-reconcile.test-d.d.ts +2 -0
  3. package/core/core/decorators/kos-container-aware-reconcile.test-d.d.ts.map +1 -0
  4. package/core/core/decorators/kos-container-aware.d.ts +150 -88
  5. package/core/core/decorators/kos-container-aware.d.ts.map +1 -1
  6. package/core/core/decorators/kos-reload-aware.d.ts +10 -8
  7. package/core/core/decorators/kos-reload-aware.d.ts.map +1 -1
  8. package/core/core/decorators/kosModel.d.ts.map +1 -1
  9. package/core/core/kosCore.d.ts +4 -1
  10. package/core/core/kosCore.d.ts.map +1 -1
  11. package/core/core/kosModel.d.ts +16 -8
  12. package/core/core/kosModel.d.ts.map +1 -1
  13. package/core/core/lifecycle/constants.d.ts +6 -2
  14. package/core/core/lifecycle/constants.d.ts.map +1 -1
  15. package/core/core/lifecycle/kosCoreLifecycle.d.ts +11 -1
  16. package/core/core/lifecycle/kosCoreLifecycle.d.ts.map +1 -1
  17. package/core/core/lifecycle/kosModelLifecycle.d.ts +6 -0
  18. package/core/core/lifecycle/kosModelLifecycle.d.ts.map +1 -1
  19. package/core/core/lifecycle/model-machine.d.ts +6 -0
  20. package/core/core/lifecycle/model-machine.d.ts.map +1 -1
  21. package/core/core/model/kos-fsm-manager.d.ts +6 -0
  22. package/core/core/model/kos-fsm-manager.d.ts.map +1 -1
  23. package/core/core/reconnect/reconnect-fixture.d.ts +17 -0
  24. package/core/core/reconnect/reconnect-fixture.d.ts.map +1 -0
  25. package/core/core/transport/transport.d.ts +1 -1
  26. package/core/core/transport/transport.d.ts.map +1 -1
  27. package/core/core/transport/webSocketTransport.d.ts +10 -0
  28. package/core/core/transport/webSocketTransport.d.ts.map +1 -1
  29. package/core/util/model-type-guards.d.ts.map +1 -1
  30. package/index.cjs +134 -90
  31. package/index.cjs.map +1 -1
  32. package/index.js +163 -119
  33. package/index.js.map +1 -1
  34. package/models/models/config-bean/config-bean-model.d.ts +9 -0
  35. package/models/models/config-bean/config-bean-model.d.ts.map +1 -1
  36. package/models/models/gpio-chip/gpio-chip-builders.d.ts +14 -0
  37. package/models/models/gpio-chip/gpio-chip-builders.d.ts.map +1 -0
  38. package/models/models/gpio-chip/gpio-chip-container-model.d.ts +2 -1
  39. package/models/models/gpio-chip/gpio-chip-container-model.d.ts.map +1 -1
  40. package/models/models/kos-expression-evaluator/expression-parse-cache.d.ts +29 -0
  41. package/models/models/kos-expression-evaluator/expression-parse-cache.d.ts.map +1 -0
  42. package/models/models/kos-expression-evaluator/index.d.ts +1 -0
  43. package/models/models/kos-expression-evaluator/index.d.ts.map +1 -1
  44. package/models/models/kos-expression-evaluator/kos-expression-evaluator-model.d.ts +54 -19
  45. package/models/models/kos-expression-evaluator/kos-expression-evaluator-model.d.ts.map +1 -1
  46. package/models/models/trouble-container/trouble-builders.d.ts +11 -0
  47. package/models/models/trouble-container/trouble-builders.d.ts.map +1 -0
  48. package/models/models/trouble-container/trouble-container-model.d.ts +2 -1
  49. package/models/models/trouble-container/trouble-container-model.d.ts.map +1 -1
  50. package/package.json +3 -3
  51. package/{software-info-registration-CY_E6Rw7.cjs → software-info-registration-BAk6JWkz.cjs} +595 -214
  52. package/software-info-registration-BAk6JWkz.cjs.map +1 -0
  53. package/{software-info-registration-CuuEsH8v.js → software-info-registration-CefJgWke.js} +624 -243
  54. package/software-info-registration-CefJgWke.js.map +1 -0
  55. package/testing.cjs +1 -1
  56. package/testing.js +1 -1
  57. package/ui/components/connection-dev-button/connection-dev-button-styles.d.ts +9 -0
  58. package/ui/components/connection-dev-button/connection-dev-button-styles.d.ts.map +1 -0
  59. package/ui/components/connection-dev-button/index.d.ts +36 -0
  60. package/ui/components/connection-dev-button/index.d.ts.map +1 -0
  61. package/ui/components/connection-dev-button/use-connection-dev-state.d.ts +29 -0
  62. package/ui/components/connection-dev-button/use-connection-dev-state.d.ts.map +1 -0
  63. package/ui/components/index.d.ts +1 -0
  64. package/ui/components/index.d.ts.map +1 -1
  65. package/software-info-registration-CY_E6Rw7.cjs.map +0 -1
  66. package/software-info-registration-CuuEsH8v.js.map +0 -1
@@ -850,7 +850,8 @@ function kosContainerAware(options) {
850
850
  includeGetters,
851
851
  modelsProperty,
852
852
  containerOptions,
853
- legacy: options?.legacy || false
853
+ legacy: options?.legacy || false,
854
+ reconcile: options?.reconcile
854
855
  };
855
856
  return target;
856
857
  };
@@ -2317,6 +2318,66 @@ class KosModelContainer {
2317
2318
  };
2318
2319
  }
2319
2320
  }
2321
+ const deltas = (projectedModels, currentModels) => {
2322
+ const newIds = projectedModels.map((entity) => entity.id);
2323
+ const currentIds = currentModels.map((entity) => entity.id);
2324
+ const toRemove = currentIds.filter((modelId) => !newIds.includes(modelId));
2325
+ return toRemove;
2326
+ };
2327
+ const DEFAULT_REMOVE_MAPPER = (id) => id;
2328
+ const DEFAULT_ID_MAPPER = (entity) => entity;
2329
+ const resolveContainerDeltas = ({
2330
+ container,
2331
+ onAddItem,
2332
+ onUpdateItem,
2333
+ onRemoveItem = DEFAULT_REMOVE_MAPPER,
2334
+ idMapper = DEFAULT_ID_MAPPER
2335
+ }) => (entities) => {
2336
+ const mappedEntities = entities.map(idMapper);
2337
+ const toRemove = deltas(mappedEntities, container.data);
2338
+ const removedIds = toRemove.map(onRemoveItem).filter(Boolean);
2339
+ container.removeAll(removedIds);
2340
+ const toAdd = mappedEntities.map((entity) => {
2341
+ const existing = container.getModel(entity.id);
2342
+ if (!existing) {
2343
+ return onAddItem(entity);
2344
+ } else if (onUpdateItem) {
2345
+ return onUpdateItem(entity, existing);
2346
+ } else {
2347
+ return onAddItem(entity);
2348
+ }
2349
+ }).filter(Boolean);
2350
+ container.addAll(toAdd);
2351
+ };
2352
+ const resolveListDeltas = ({
2353
+ container,
2354
+ onAddItem,
2355
+ onRemoveItem = DEFAULT_REMOVE_MAPPER,
2356
+ idMapper = DEFAULT_ID_MAPPER
2357
+ }) => (entities) => {
2358
+ const mappedLayers = entities.map(idMapper);
2359
+ const toRemove = deltas(mappedLayers, container.models);
2360
+ toRemove.forEach(onRemoveItem);
2361
+ mappedLayers.forEach(onAddItem);
2362
+ };
2363
+ const resolveItemListDeltas = ({
2364
+ items,
2365
+ onAddItem,
2366
+ onRemoveItem,
2367
+ idMapper = DEFAULT_ID_MAPPER
2368
+ }) => (entities) => {
2369
+ const mappedLayers = entities.map(idMapper);
2370
+ const toRemove = deltas(mappedLayers, items);
2371
+ toRemove.forEach(onRemoveItem);
2372
+ mappedLayers.forEach(onAddItem);
2373
+ };
2374
+ const processId = (id, prefix = "parent-") => {
2375
+ let _id = id;
2376
+ if (_id.startsWith(prefix)) {
2377
+ _id = _id.replace(prefix, "");
2378
+ }
2379
+ return _id;
2380
+ };
2320
2381
  var KosModelState = /* @__PURE__ */ ((KosModelState2) => {
2321
2382
  KosModelState2["CREATING"] = `creating`;
2322
2383
  KosModelState2["CREATED"] = `created`;
@@ -2338,6 +2399,9 @@ var KosModelState = /* @__PURE__ */ ((KosModelState2) => {
2338
2399
  KosModelState2["ACTIVE"] = "active";
2339
2400
  KosModelState2["ACTIVATING"] = "activating";
2340
2401
  KosModelState2["DEACTIVATING"] = "deactivating";
2402
+ KosModelState2["RELOADING"] = `reloading`;
2403
+ KosModelState2["REATTACHING"] = `reattaching`;
2404
+ KosModelState2["RELOAD_READYING"] = `reload_readying`;
2341
2405
  return KosModelState2;
2342
2406
  })(KosModelState || {});
2343
2407
  var KosModelEvents = /* @__PURE__ */ ((KosModelEvents2) => {
@@ -2353,6 +2417,7 @@ var KosModelEvents = /* @__PURE__ */ ((KosModelEvents2) => {
2353
2417
  KosModelEvents2["GO_ACTIVE"] = "go_active";
2354
2418
  KosModelEvents2["GO_INACTIVE"] = "go_inactive";
2355
2419
  KosModelEvents2["TIMEOUT"] = "timeout";
2420
+ KosModelEvents2["RELOAD"] = `reload`;
2356
2421
  return KosModelEvents2;
2357
2422
  })(KosModelEvents || {});
2358
2423
  const whenReady = async (dataModel) => {
@@ -3040,6 +3105,23 @@ function injectTroubleAwareSupport(modelInstance) {
3040
3105
  configurable: true
3041
3106
  });
3042
3107
  }
3108
+ function createContainerReconcile(container, reconcile) {
3109
+ const { create, update, idMapper, filter, afterCreate } = reconcile;
3110
+ const apply = resolveContainerDeltas({
3111
+ container,
3112
+ onAddItem: (dto) => {
3113
+ const model = create(dto);
3114
+ afterCreate?.(model, dto);
3115
+ return model;
3116
+ },
3117
+ onUpdateItem: update ? (dto, existing) => {
3118
+ update(dto, existing);
3119
+ return null;
3120
+ } : void 0,
3121
+ idMapper
3122
+ });
3123
+ return (list) => apply(filter ? list.filter(filter) : list);
3124
+ }
3043
3125
  function injectContainerAwareSupport(modelInstance, modelId) {
3044
3126
  const containerSetup = modelInstance[ContainerAwareSetup];
3045
3127
  if (!containerSetup) return;
@@ -3049,7 +3131,8 @@ function injectContainerAwareSupport(modelInstance, modelId) {
3049
3131
  includeGetters,
3050
3132
  modelsProperty,
3051
3133
  containerOptions,
3052
- legacy
3134
+ legacy,
3135
+ reconcile
3053
3136
  } = containerSetup;
3054
3137
  const finalContainerOptions = {
3055
3138
  ...containerOptions,
@@ -3079,6 +3162,9 @@ function injectContainerAwareSupport(modelInstance, modelId) {
3079
3162
  modelInstance.removeAndDestroy = async (id) => container.removeAndDestroy(id);
3080
3163
  modelInstance.removeAndDestroyAll = async (ids) => container.removeAndDestroyAll(ids);
3081
3164
  }
3165
+ if (reconcile) {
3166
+ modelInstance.reconcile = createContainerReconcile(container, reconcile);
3167
+ }
3082
3168
  if (includeGetters) {
3083
3169
  Object.defineProperty(modelInstance, modelsProperty, {
3084
3170
  get() {
@@ -3514,7 +3600,7 @@ function createOnceHandler(originalHandler) {
3514
3600
  }
3515
3601
  const isPrintable = (model) => typeof model.toJSON === "function";
3516
3602
  const isKosDataModel = (model) => model[DependencyModels] !== void 0;
3517
- const isKosModelContainer = (model) => model.revision !== void 0 && model.index !== void 0;
3603
+ const isKosModelContainer = (model) => typeof model === "object" && model !== null && model.revision !== void 0 && model.index !== void 0;
3518
3604
  const resolveChild = (attribute) => {
3519
3605
  if (!attribute) return void 0;
3520
3606
  if (isKosDataModel(attribute)) return attribute;
@@ -4693,6 +4779,14 @@ const onlineMachine = (model) => {
4693
4779
  const machine = (model) => {
4694
4780
  const active = activeMachine(model).service;
4695
4781
  const online = onlineMachine(model).service;
4782
+ const setStatus = (status) => kosAction(() => {
4783
+ model.status = status;
4784
+ });
4785
+ const failed = robot3.transition(
4786
+ `error`,
4787
+ KosModelState.FAILED,
4788
+ robot3.action(() => setStatus(KosModelState.FAILED))
4789
+ );
4696
4790
  return robot3.createMachine(KosModelState.CREATING, {
4697
4791
  [KosModelState.CREATING]: robot3.state(
4698
4792
  robot3.transition(KosModelEvents.CREATE, KosModelState.CREATED)
@@ -4798,6 +4892,7 @@ const machine = (model) => {
4798
4892
  robot3.action(model.unload?.bind(model))
4799
4893
  ),
4800
4894
  robot3.transition(KosModelEvents.RESET, KosModelState.RESETTING),
4895
+ robot3.transition(KosModelEvents.RELOAD, KosModelState.RELOADING),
4801
4896
  robot3.transition(
4802
4897
  KosModelEvents.GO_ONLINE,
4803
4898
  KosModelState.READY,
@@ -4827,6 +4922,49 @@ const machine = (model) => {
4827
4922
  })
4828
4923
  )
4829
4924
  ),
4925
+ [KosModelState.RELOADING]: robot3.invoke(
4926
+ () => {
4927
+ setStatus(KosModelState.RELOADING);
4928
+ return model.reloadData();
4929
+ },
4930
+ robot3.transition(`done`, KosModelState.REATTACHING),
4931
+ robot3.transition(
4932
+ `error`,
4933
+ KosModelState.REATTACHING,
4934
+ robot3.action((_ctx, event) => {
4935
+ KosLog.error(
4936
+ `Model ${model.modelId} - ${model.modelTypeName} failed to reload; its data stays as it was. ${String(
4937
+ event?.error
4938
+ )}`
4939
+ );
4940
+ })
4941
+ )
4942
+ ),
4943
+ [KosModelState.REATTACHING]: robot3.invoke(
4944
+ () => {
4945
+ setStatus(KosModelState.REATTACHING);
4946
+ return model.reattach();
4947
+ },
4948
+ robot3.transition(`done`, KosModelState.RELOAD_READYING),
4949
+ failed
4950
+ ),
4951
+ [KosModelState.RELOAD_READYING]: robot3.invoke(
4952
+ () => {
4953
+ setStatus(KosModelState.READYING);
4954
+ return model.ready();
4955
+ },
4956
+ robot3.transition(
4957
+ `done`,
4958
+ KosModelState.READY,
4959
+ robot3.action(() => {
4960
+ setStatus(KosModelState.READY);
4961
+ if (!KosCore.getInstance().isOnline) {
4962
+ online.send(KosModelEvents.GO_OFFLINE);
4963
+ }
4964
+ })
4965
+ ),
4966
+ failed
4967
+ ),
4830
4968
  [KosModelState.UNLOADED]: robot3.state(),
4831
4969
  [KosModelState.FAILED]: robot3.state()
4832
4970
  });
@@ -4905,6 +5043,26 @@ class KosFSMManager {
4905
5043
  this.disposer = void 0;
4906
5044
  });
4907
5045
  }
5046
+ /**
5047
+ * Re-enters a READY model through RELOADING, REATTACHING and READYING and
5048
+ * resolves once it is READY again; rejects if it fails. A model that is not
5049
+ * READY is left alone.
5050
+ */
5051
+ async reload() {
5052
+ if (this.current !== KosModelState.READY) {
5053
+ this.log.debug(
5054
+ `Model ${this.model.modelId} is ${this.current}, not READY; skipping reload`
5055
+ );
5056
+ return;
5057
+ }
5058
+ this.service.send(KosModelEvents.RELOAD);
5059
+ await mobx.when(
5060
+ () => this.model.status === KosModelState.READY || this.model.status === KosModelState.FAILED
5061
+ );
5062
+ if (this.model.status === KosModelState.FAILED) {
5063
+ throw new Error(`reload failed for model ${this.model.modelId}`);
5064
+ }
5065
+ }
4908
5066
  /**
4909
5067
  * Checks if a given target maps to status, activeStatus, or onlineStatus.
4910
5068
  * Online/offline transitions are tracked on model.onlineStatus because the
@@ -8856,9 +9014,9 @@ class MockInterceptorTransport {
8856
9014
  this.inner.send(data);
8857
9015
  }
8858
9016
  }
8859
- close() {
9017
+ close(code, reason) {
8860
9018
  this.unregisterInjector();
8861
- return this.inner.close();
9019
+ return this.inner.close(code, reason);
8862
9020
  }
8863
9021
  addEventListener(type, listener, options) {
8864
9022
  this.inner.addEventListener(type, listener, options);
@@ -9393,13 +9551,9 @@ class WebSocketTransport {
9393
9551
  if (connectionEstablished) {
9394
9552
  log$v.warn("Connection Established");
9395
9553
  this.reconnectAttempts = 0;
9396
- publish(
9397
- WebSocketEvents.CONNECTED,
9398
- WebSocketEvents.CONNECTED
9399
- );
9400
- if (initialized) {
9401
- publish(WebSocketEvents.RELOAD, WebSocketEvents.RELOAD);
9402
- }
9554
+ publish(WebSocketEvents.CONNECTED, {
9555
+ reconnect: initialized
9556
+ });
9403
9557
  initialized = true;
9404
9558
  }
9405
9559
  }
@@ -9574,6 +9728,13 @@ ${dstAddr}topics:${topic}
9574
9728
  status: `success`
9575
9729
  };
9576
9730
  }
9731
+ dropConnection() {
9732
+ if (!this.connectionEstablished) {
9733
+ log$v.debug("dropConnection ignored: the connection is already closed");
9734
+ return;
9735
+ }
9736
+ this.socket?.socket.close(1e3);
9737
+ }
9577
9738
  get token() {
9578
9739
  return this._token;
9579
9740
  }
@@ -10761,18 +10922,63 @@ class KosModel {
10761
10922
  );
10762
10923
  this.subscriptionManager?.registerAll(lifecycle);
10763
10924
  }
10764
- /**
10765
- * The counterpart of `unload()` for a reload that keeps the instance: every
10766
- * manager `unload()` disposed comes back, not only the subscriptions.
10767
- * @internal
10768
- */
10769
- restoreAfterReload() {
10770
- this.onlineLifecycleManager?.register();
10925
+ /** Narrow, framework-owned teardown for a reload; never the author's unload(). */
10926
+ suspendForReload() {
10927
+ this.subscriptionManager?.disposeAll();
10928
+ this.effectManager?.disposeAll();
10929
+ this.httpRouteManager?.dispose();
10930
+ this.onlineLifecycleManager?.dispose();
10931
+ kosAction(() => {
10932
+ this.loaded = false;
10933
+ });
10934
+ }
10935
+ /** @internal */
10936
+ async reloadData() {
10937
+ log$u.info(`reloading model ${this.modelTypeName} with id ${this.modelId}`);
10938
+ this.suspendForReload();
10939
+ const data = this.modelData;
10940
+ if (typeof data?.reload === "function" && !data[SelfManagedReload]) {
10941
+ await data.reload();
10942
+ }
10943
+ }
10944
+ /** @internal */
10945
+ async reattach() {
10946
+ log$u.info(`reattaching model ${this.modelTypeName} with id ${this.modelId}`);
10947
+ kosAction(() => {
10948
+ this.loaded = true;
10949
+ });
10771
10950
  this.subscriptionManager?.registerAll();
10772
10951
  this.httpRouteManager?.registerAll();
10773
10952
  this.effectManager?.setup();
10774
- kosAction(() => {
10775
- this.loaded = true;
10953
+ this.onlineLifecycleManager?.register();
10954
+ await this.reenterChildren();
10955
+ }
10956
+ // A READY child runs its own reload sequence; one created by reload() and
10957
+ // still booting is awaited through its normal lifecycle.
10958
+ async reenterChildren() {
10959
+ const children = this.getChildren();
10960
+ const ready = children.filter(
10961
+ (child) => child.fsm.current === KosModelState.READY
10962
+ );
10963
+ const booting = children.filter(
10964
+ (child) => child.fsm.current !== KosModelState.READY && child.fsm.current !== KosModelState.UNLOADED
10965
+ );
10966
+ const [reloaded] = await Promise.all([
10967
+ Promise.allSettled(ready.map((child) => child.fsm.reload())),
10968
+ executeListLifecycle(
10969
+ this,
10970
+ booting,
10971
+ Transitions.READY,
10972
+ DependencyLifecycle.READY
10973
+ )
10974
+ ]);
10975
+ reloaded.forEach((result, index) => {
10976
+ if (result.status === "rejected") {
10977
+ log$u.error(
10978
+ `reload of child ${ready[index].modelId} of ${this.modelId} failed`,
10979
+ result.reason
10980
+ );
10981
+ }
10776
10982
  });
10777
10983
  }
10778
10984
  /**
@@ -11352,6 +11558,9 @@ var KosCoreState = /* @__PURE__ */ ((KosCoreState2) => {
11352
11558
  KosCoreState2["UNLOADING"] = `unloading`;
11353
11559
  KosCoreState2["UNLOADED"] = `unloaded`;
11354
11560
  KosCoreState2["RELOADING"] = `reloading`;
11561
+ KosCoreState2["RECONNECTING"] = `reconnecting`;
11562
+ KosCoreState2["RECONNECT_INTERRUPTED"] = `reconnect_interrupted`;
11563
+ KosCoreState2["RECONNECT_PENDING"] = `reconnect_pending`;
11355
11564
  KosCoreState2["FAILED"] = `failed`;
11356
11565
  return KosCoreState2;
11357
11566
  })(KosCoreState || {});
@@ -11363,6 +11572,7 @@ var KosCoreEvents = /* @__PURE__ */ ((KosCoreEvents2) => {
11363
11572
  KosCoreEvents2["GO_OFFLINE"] = `go_offline`;
11364
11573
  KosCoreEvents2["UNLOAD"] = `unload`;
11365
11574
  KosCoreEvents2["RELOAD"] = `reload`;
11575
+ KosCoreEvents2["RECONNECT"] = `reconnect`;
11366
11576
  return KosCoreEvents2;
11367
11577
  })(KosCoreEvents || {});
11368
11578
  const reportFailure = async (step, run) => {
@@ -11409,8 +11619,23 @@ const coreFsm = (core) => {
11409
11619
  });
11410
11620
  const online = robot3.interpret(
11411
11621
  onlineMachine2,
11412
- (_service) => log$M.debug(_service.machine.current)
11622
+ (_service) => log$M.debug(`KOS Core connection: ${_service.machine.current}`)
11623
+ );
11624
+ const syncOnline = () => online.send(
11625
+ core.transport.connectionEstablished ? "go_online" : "go_offline"
11626
+ /* GO_OFFLINE */
11413
11627
  );
11628
+ const setReconnecting = (reconnecting) => mobx.runInAction(() => {
11629
+ core.reconnecting = reconnecting;
11630
+ });
11631
+ const reconnectDone = robot3.action(() => setReconnecting(false));
11632
+ const reconnectedOnline = robot3.action(() => {
11633
+ setReconnecting(false);
11634
+ online.send(
11635
+ "go_online"
11636
+ /* GO_ONLINE */
11637
+ );
11638
+ });
11414
11639
  const failed = robot3.transition(
11415
11640
  `error`,
11416
11641
  "failed",
@@ -11495,10 +11720,56 @@ const coreFsm = (core) => {
11495
11720
  mobx.runInAction(() => {
11496
11721
  core.status = "ready";
11497
11722
  });
11723
+ syncOnline();
11498
11724
  })
11499
11725
  ),
11500
11726
  failed
11501
11727
  ),
11728
+ [
11729
+ "reconnecting"
11730
+ /* RECONNECTING */
11731
+ ]: robot3.invoke(
11732
+ () => reportFailure("reconnecting", () => core.reload()),
11733
+ robot3.transition(`done`, "ready", reconnectedOnline),
11734
+ robot3.transition(`error`, "ready", reconnectedOnline),
11735
+ robot3.transition(
11736
+ "go_offline",
11737
+ "reconnect_interrupted"
11738
+ /* RECONNECT_INTERRUPTED */
11739
+ )
11740
+ ),
11741
+ [
11742
+ "reconnect_interrupted"
11743
+ /* RECONNECT_INTERRUPTED */
11744
+ ]: robot3.state(
11745
+ robot3.transition(`done`, "ready", reconnectDone),
11746
+ robot3.transition(`error`, "ready", reconnectDone),
11747
+ robot3.transition(
11748
+ "reconnect",
11749
+ "reconnect_pending"
11750
+ /* RECONNECT_PENDING */
11751
+ )
11752
+ ),
11753
+ [
11754
+ "reconnect_pending"
11755
+ /* RECONNECT_PENDING */
11756
+ ]: robot3.state(
11757
+ robot3.transition(
11758
+ `done`,
11759
+ "reconnecting"
11760
+ /* RECONNECTING */
11761
+ ),
11762
+ robot3.transition(
11763
+ `error`,
11764
+ "reconnecting"
11765
+ /* RECONNECTING */
11766
+ ),
11767
+ robot3.transition(
11768
+ "go_offline",
11769
+ "reconnect_interrupted"
11770
+ /* RECONNECT_INTERRUPTED */
11771
+ )
11772
+ ),
11502
11773
  [
11503
11774
  "reloading"
11504
11775
  /* RELOADING */
@@ -11524,6 +11795,11 @@ const coreFsm = (core) => {
11524
11795
  "reloading"
11525
11796
  /* RELOADING */
11526
11797
  ),
11798
+ robot3.transition(
11799
+ "reconnect",
11800
+ "reconnecting",
11801
+ robot3.action(() => setReconnecting(true))
11802
+ ),
11527
11803
  robot3.transition(
11528
11804
  "unload",
11529
11805
  "unloaded",
@@ -11557,7 +11833,7 @@ const coreFsm = (core) => {
11557
11833
  });
11558
11834
  const service2 = robot3.interpret(
11559
11835
  machine2,
11560
- (_service) => log$M.debug(_service.machine.current)
11836
+ (_service) => log$M.debug(`KOS Core state: ${_service.machine.current}`)
11561
11837
  );
11562
11838
  return { service: service2, online };
11563
11839
  };
@@ -11635,6 +11911,15 @@ const rejectAfterDelay = (ms, model) => {
11635
11911
  };
11636
11912
  const isReloadable = (model) => typeof model.reload === "function";
11637
11913
  const isSelfManagedReload = (model) => !!model[SelfManagedReload];
11914
+ const isCoreReloaded = (model) => isReloadable(model.modelData) && !isSelfManagedReload(model.modelData);
11915
+ const addDescendants = (model, into) => {
11916
+ model.getChildren().forEach((child) => {
11917
+ if (!into.has(child)) {
11918
+ into.add(child);
11919
+ addDescendants(child, into);
11920
+ }
11921
+ });
11922
+ };
11638
11923
  const isUnloadable = (model) => typeof model.unload === "function";
11639
11924
  var AuthState = /* @__PURE__ */ ((AuthState2) => {
11640
11925
  AuthState2["LOGGED_IN"] = "logged_in";
@@ -11652,6 +11937,7 @@ class KosCore {
11652
11937
  authState;
11653
11938
  isOnline;
11654
11939
  _reloading;
11940
+ reconnecting;
11655
11941
  _unloading;
11656
11942
  lifecycleStarted = false;
11657
11943
  connectionAlias;
@@ -11663,6 +11949,7 @@ class KosCore {
11663
11949
  this.status = KosCoreState.CREATED;
11664
11950
  this.authState = "logged_out";
11665
11951
  this._reloading = false;
11952
+ this.reconnecting = false;
11666
11953
  this._unloading = false;
11667
11954
  mobx.makeAutoObservable(this);
11668
11955
  subscribe("token", (data) => {
@@ -11673,12 +11960,11 @@ class KosCore {
11673
11960
  subscribe(WebSocketEvents.DISCONNECTED, () => {
11674
11961
  this.fsmService.service.send(KosCoreEvents.GO_OFFLINE);
11675
11962
  });
11676
- subscribe(WebSocketEvents.CONNECTED, async () => {
11677
- await this.whenReady();
11678
- this.modelManager.models.forEach(
11679
- (model) => model.onlineLifecycleManager?.register()
11963
+ subscribe(WebSocketEvents.CONNECTED, (msg) => {
11964
+ const reconnect = msg?.body?.reconnect;
11965
+ this.fsmService.service.send(
11966
+ reconnect ? KosCoreEvents.RECONNECT : KosCoreEvents.GO_ONLINE
11680
11967
  );
11681
- this.fsmService.service.send(KosCoreEvents.GO_ONLINE);
11682
11968
  });
11683
11969
  subscribe("/studioServer/auth/LOGGED_IN", () => {
11684
11970
  mobx.runInAction(() => {
@@ -11755,64 +12041,74 @@ alias:${alias}
11755
12041
  this.fsmService.service.send(KosCoreEvents.CREATE);
11756
12042
  }
11757
12043
  get onlineStatus() {
11758
- return this.isOnline && !this._reloading && !this._unloading;
12044
+ return this.isOnline && !this.reloading && !this._unloading;
11759
12045
  }
11760
12046
  get reloading() {
11761
- return this._reloading;
12047
+ return this._reloading || this.reconnecting;
11762
12048
  }
11763
12049
  get unloading() {
11764
12050
  return this._unloading;
11765
12051
  }
11766
12052
  async reload() {
11767
- const currentTime = Date.now();
11768
12053
  if (this._reloading) {
11769
12054
  log$r.info("reload already in progress");
11770
12055
  return;
11771
12056
  }
11772
12057
  this._reloading = true;
11773
- log$r.warn("reloading KOS Core");
11774
- log$r.warn("reloading preloaded models");
11775
- const modelManager = this.modelManager;
11776
- for (const model of modelManager.preloadedModels) {
11777
- if (isReloadable(model.modelData)) {
11778
- if (isSelfManagedReload(model.modelData)) {
11779
- log$r.info(`skipping self-managed model ${model.modelId}`);
11780
- continue;
12058
+ try {
12059
+ log$r.warn("reloading KOS Core");
12060
+ log$r.warn("reloading preloaded models");
12061
+ const modelManager = this.modelManager;
12062
+ const preloaded = [...modelManager.preloadedModels];
12063
+ const covered = /* @__PURE__ */ new Set();
12064
+ modelManager.models.filter((model) => isCoreReloaded(model)).forEach((model) => addDescendants(model, covered));
12065
+ const reloadRoot = async (model) => {
12066
+ await this.reloadOne(model);
12067
+ addDescendants(model, covered);
12068
+ };
12069
+ for (const model of preloaded) {
12070
+ if (isReloadable(model.modelData) && !covered.has(model)) {
12071
+ if (isSelfManagedReload(model.modelData)) {
12072
+ log$r.info(`skipping self-managed model ${model.modelId}`);
12073
+ continue;
12074
+ }
12075
+ log$r.info(`reloading model ${model.modelId}`);
12076
+ await reloadRoot(model);
12077
+ log$r.info(`reloading model ${model.modelId} complete`);
11781
12078
  }
11782
- log$r.info(`reloading model ${model.modelId}`);
11783
- await this.reloadModel(model, model.modelData);
11784
- log$r.info(`reloading model ${model.modelId} complete`);
11785
12079
  }
11786
- }
11787
- for (const model of modelManager.models) {
11788
- if (!modelManager.preloadedModels.includes(model) && isReloadable(model.modelData)) {
11789
- if (isSelfManagedReload(model.modelData)) {
11790
- log$r.info(`skipping self-managed model ${model.modelId}`);
11791
- continue;
12080
+ for (const model of [...modelManager.models]) {
12081
+ if (!preloaded.includes(model) && isReloadable(model.modelData) && !covered.has(model)) {
12082
+ if (isSelfManagedReload(model.modelData)) {
12083
+ log$r.info(`skipping self-managed model ${model.modelId}`);
12084
+ continue;
12085
+ }
12086
+ log$r.warn(`reloading model ${model.modelId}`);
12087
+ await reloadRoot(model);
11792
12088
  }
11793
- log$r.warn(`reloading model ${model.modelId}`);
11794
- await this.reloadModel(model, model.modelData);
11795
12089
  }
11796
- }
11797
- const elapsed = Date.now() - currentTime;
11798
- setTimeout(() => {
12090
+ } finally {
11799
12091
  mobx.runInAction(() => {
11800
12092
  log$r.warn("reloading KOS Core complete");
11801
12093
  this._reloading = false;
11802
12094
  });
11803
- }, 1e3 - elapsed);
12095
+ }
11804
12096
  }
11805
- // unload() must finish before reload() starts, and whatever it disposed must
11806
- // come back afterwards; the data model's reload() only refreshes data.
11807
- async reloadModel(model, data) {
11808
- await model.unload?.();
11809
- await data.reload();
11810
- model.restoreAfterReload?.();
12097
+ // reload never calls unload(); the model machine owns the narrow teardown
12098
+ async reloadOne(model) {
12099
+ try {
12100
+ await model.fsm.reload();
12101
+ } catch (e) {
12102
+ log$r.error(`reload of ${model.modelId} failed`, e);
12103
+ }
11811
12104
  }
11812
12105
  async online() {
11813
12106
  log$r.debug("KOS Core going online");
11814
12107
  await this._transport.whenReady();
11815
12108
  log$r.debug("KOS Transport Ready. Calling online() for models");
12109
+ this.modelManager.models.forEach(
12110
+ (model) => model.onlineLifecycleManager?.register()
12111
+ );
11816
12112
  publish("/kosCore/online", "/kosCore/online");
11817
12113
  console.timeEnd("kosCore:startup");
11818
12114
  }
@@ -13624,6 +13920,20 @@ let ConfigBeanModelImpl = class {
13624
13920
  */
13625
13921
  async load() {
13626
13922
  log$k.debug(`loading config bean ${this.path}`);
13923
+ await this.fetchBean();
13924
+ }
13925
+ /**
13926
+ * @internal
13927
+ *
13928
+ * @remarks
13929
+ * Fetches the bean again and updates its values and schema in place, so a
13930
+ * KOS Core reload after a reconnect leaves the same instance current.
13931
+ */
13932
+ async reload() {
13933
+ log$k.debug(`reloading config bean ${this.path}`);
13934
+ await this.fetchBean();
13935
+ }
13936
+ async fetchBean() {
13627
13937
  const response = await this._getConfigBean(
13628
13938
  this.path,
13629
13939
  this.serviceBasePath,
@@ -17651,6 +17961,56 @@ Parser.prototype.isOperatorEnabled = function(op) {
17651
17961
  var operators = this.options.operators || {};
17652
17962
  return !(optionName in operators) || !!operators[optionName];
17653
17963
  };
17964
+ class CompiledExpression {
17965
+ expression;
17966
+ expr;
17967
+ constructor(expression, expr) {
17968
+ this.expression = expression;
17969
+ this.expr = expr;
17970
+ }
17971
+ evaluate(contextData) {
17972
+ try {
17973
+ return { value: this.expr.evaluate(contextData), error: void 0 };
17974
+ } catch (error) {
17975
+ return {
17976
+ value: void 0,
17977
+ error: error instanceof Error ? error.message : String(error)
17978
+ };
17979
+ }
17980
+ }
17981
+ }
17982
+ const PARSE_CACHE_LIMIT = 500;
17983
+ class ExpressionParseCache {
17984
+ constructor(parser, limit = PARSE_CACHE_LIMIT) {
17985
+ this.parser = parser;
17986
+ this.limit = limit;
17987
+ }
17988
+ parser;
17989
+ limit;
17990
+ entries = /* @__PURE__ */ new Map();
17991
+ parse(expression) {
17992
+ const cached = this.entries.get(expression);
17993
+ if (cached) {
17994
+ this.entries.delete(expression);
17995
+ this.entries.set(expression, cached);
17996
+ return cached;
17997
+ }
17998
+ const parsed = new CompiledExpression(
17999
+ expression,
18000
+ this.parser.parse(expression)
18001
+ );
18002
+ this.entries.set(expression, parsed);
18003
+ if (this.entries.size > this.limit) {
18004
+ const oldest = this.entries.keys().next().value;
18005
+ if (oldest !== void 0) this.entries.delete(oldest);
18006
+ }
18007
+ return parsed;
18008
+ }
18009
+ }
18010
+ const layerContext = (base, local) => new Proxy(local, {
18011
+ get: (target, key) => typeof key === "string" && !Object.prototype.hasOwnProperty.call(target, key) ? base[key] : Reflect.get(target, key),
18012
+ has: (target, key) => Object.prototype.hasOwnProperty.call(target, key) || typeof key === "string" && base.has(key)
18013
+ });
17654
18014
  var __defProp$i = Object.defineProperty;
17655
18015
  var __getOwnPropDesc$m = Object.getOwnPropertyDescriptor;
17656
18016
  var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$i(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
@@ -17663,60 +18023,67 @@ var __decorateClass$m = (decorators, target, key, kind) => {
17663
18023
  };
17664
18024
  var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, key + "", value);
17665
18025
  const MODEL_TYPE$l = "kos-expression-evaluator-model";
18026
+ const sameResult = (a, b) => Object.is(a.value, b.value) && a.error === b.error;
18027
+ const DISPOSED_RESULT = {
18028
+ value: void 0,
18029
+ error: void 0
18030
+ };
17666
18031
  class ReactiveExpression {
17667
18032
  name;
17668
18033
  expression;
17669
- expr;
17670
- getContextData = null;
17671
- // Cache the last result to allow comparison without re-evaluation
17672
- _lastResult = { value: void 0 };
17673
- constructor(name, expression, expr, getContextData) {
18034
+ parsed;
18035
+ disposed;
18036
+ computedResult;
18037
+ constructor(name, parsed, getContextData) {
17674
18038
  this.name = name;
17675
- this.expression = expression;
17676
- this.expr = expr;
17677
- this.getContextData = getContextData;
17678
- this._lastResult = { value: void 0, error: void 0 };
18039
+ this.expression = parsed.expression;
18040
+ this.parsed = parsed;
18041
+ this.disposed = kosObservable.box(false);
18042
+ this.computedResult = kosComputed(
18043
+ () => this.disposed.get() ? DISPOSED_RESULT : this.evaluate(getContextData()),
18044
+ { keepAlive: true, equals: sameResult, name: `expression:${name}` }
18045
+ );
17679
18046
  }
17680
- /** The cached result, returned without evaluating. */
18047
+ /** The current result, evaluated only if a context value it read changed since the last evaluation. */
17681
18048
  get result() {
17682
- return this._lastResult;
18049
+ return this.computedResult.get();
17683
18050
  }
17684
18051
  /**
17685
- * Update the cached result. Called by the parent model after evaluation.
18052
+ * @deprecated The result is derived from the context data; this has no effect.
17686
18053
  */
17687
- updateResult(result) {
17688
- this._lastResult = result;
18054
+ updateResult(_result) {
18055
+ return;
17689
18056
  }
17690
18057
  /**
17691
- * Evaluate the expression against the given context data. The cached result is unchanged.
18058
+ * Evaluate the expression against the given context data. The result is unchanged.
17692
18059
  */
17693
18060
  evaluate(contextData) {
17694
- try {
17695
- const value = this.expr.evaluate(contextData);
17696
- return { value, error: void 0 };
17697
- } catch (error) {
17698
- return {
17699
- value: void 0,
17700
- error: error instanceof Error ? error.message : String(error)
17701
- };
17702
- }
18061
+ return this.parsed.evaluate(contextData);
18062
+ }
18063
+ /** Release every context value the result tracks. */
18064
+ dispose() {
18065
+ kosAction(() => this.disposed.set(true));
18066
+ this.computedResult.get();
17703
18067
  }
17704
18068
  }
18069
+ class ExpressionResultsView {
18070
+ }
17705
18071
  let KosExpressionEvaluatorModelImpl = class {
17706
18072
  id;
17707
18073
  logger;
17708
18074
  parser;
17709
18075
  _data;
17710
18076
  _expressions = /* @__PURE__ */ new Map();
17711
- // Use ObservableData for results to handle dynamic properties properly
17712
- _results;
18077
+ _parseCache;
18078
+ _resultsView;
17713
18079
  _contextRevision = 0;
17714
18080
  constructor(modelId, options, context) {
17715
18081
  this.id = modelId;
17716
18082
  this.logger = context.logger;
17717
18083
  this._data = ObservableData();
17718
- this._results = ObservableData();
17719
18084
  this.parser = new Parser();
18085
+ this._parseCache = new ExpressionParseCache(this.parser);
18086
+ this._resultsView = this.createResultsView();
17720
18087
  this.parser.functions.exists = (value) => value !== void 0 && value !== null;
17721
18088
  this.parser.functions.isEmpty = (value) => {
17722
18089
  if (value === void 0 || value === null) return true;
@@ -17747,7 +18114,8 @@ let KosExpressionEvaluatorModelImpl = class {
17747
18114
  return this._contextRevision;
17748
18115
  }
17749
18116
  /**
17750
- * Replace the context data. Every expression re-evaluates against it.
18117
+ * Replace the context data. An expression re-evaluates only if a value it
18118
+ * read changed.
17751
18119
  *
17752
18120
  * @param newData - Complete new context data to replace existing data
17753
18121
  */
@@ -17805,7 +18173,8 @@ let KosExpressionEvaluatorModelImpl = class {
17805
18173
  this._data[key] = model;
17806
18174
  }
17807
18175
  /**
17808
- * Add a named expression and evaluate it once.
18176
+ * Add a named expression. It evaluates on first read. Adding a name that
18177
+ * exists replaces that expression.
17809
18178
  *
17810
18179
  * @param name - Unique identifier for this expression
17811
18180
  * @param expressionString - Expression in `expr-eval` syntax
@@ -17813,25 +18182,31 @@ let KosExpressionEvaluatorModelImpl = class {
17813
18182
  */
17814
18183
  addExpression(name, expressionString) {
17815
18184
  try {
17816
- const expr = this.parser.parse(expressionString);
18185
+ const parsed = this._parseCache.parse(expressionString);
17817
18186
  const reactiveExpression = new ReactiveExpression(
17818
18187
  name,
17819
- expressionString,
17820
- expr,
17821
- () => this.data
18188
+ parsed,
18189
+ () => this._data
17822
18190
  );
18191
+ this._expressions.get(name)?.dispose();
17823
18192
  this._expressions.set(name, reactiveExpression);
17824
- this.evaluateExpression(name);
17825
18193
  this.logger.debug(`Added expression "${name}": ${expressionString}`);
17826
18194
  } catch (error) {
17827
18195
  this.logger.error(`Failed to parse expression "${name}"`, error);
17828
18196
  throw error;
17829
18197
  }
17830
18198
  }
18199
+ /**
18200
+ * Remove a named expression and release the context values it tracks.
18201
+ *
18202
+ * @param name - The expression name
18203
+ * @returns Whether an expression was removed
18204
+ */
17831
18205
  removeExpression(name) {
18206
+ const expression = this._expressions.get(name);
17832
18207
  const removed = this._expressions.delete(name);
17833
18208
  if (removed) {
17834
- delete this._results[name];
18209
+ expression?.dispose();
17835
18210
  this.logger.debug(`Removed expression "${name}"`);
17836
18211
  } else {
17837
18212
  this.logger.warn(
@@ -17866,11 +18241,12 @@ let KosExpressionEvaluatorModelImpl = class {
17866
18241
  return expression.result;
17867
18242
  }
17868
18243
  /**
17869
- * The last cached result of an expression, read without re-evaluating. Use it
17870
- * in effects that should not depend on the expression's inputs.
18244
+ * The result of an expression without a warning when it does not exist. It
18245
+ * re-evaluates only if a context value it read changed since the last
18246
+ * evaluation, and a reader tracks the result, not the expression's inputs.
17871
18247
  *
17872
- * @param name - The expression name to get the cached result for
17873
- * @returns The last cached result, or undefined if expression doesn't exist
18248
+ * @param name - The expression name to get the result for
18249
+ * @returns The result, or undefined if expression doesn't exist
17874
18250
  */
17875
18251
  getCachedExpressionValue(name) {
17876
18252
  const expression = this._expressions.get(name);
@@ -17885,53 +18261,64 @@ let KosExpressionEvaluatorModelImpl = class {
17885
18261
  get expressionNames() {
17886
18262
  return Array.from(this._expressions.keys());
17887
18263
  }
17888
- // Evaluates on access so readers track the context data each expression uses
18264
+ /**
18265
+ * Every expression's result by name. Reading `results[name]` evaluates only
18266
+ * that expression, and only if a context value it read changed.
18267
+ */
17889
18268
  get results() {
17890
- this.evaluateAllExpressions();
17891
- return this._results;
18269
+ return this._resultsView;
17892
18270
  }
17893
- /** Re-evaluate every expression and update the cached results. */
17894
- evaluateAllExpressions() {
17895
- const keys = Array.from(this._expressions.keys());
17896
- keys.forEach((key) => {
17897
- const expression = this._expressions.get(key);
17898
- if (expression) {
17899
- this.evaluateExpression(key);
17900
- }
17901
- });
18271
+ /**
18272
+ * Parse an expression, or return the cached parse of the same string, to
18273
+ * evaluate against any context object.
18274
+ *
18275
+ * @param expressionString - Expression in `expr-eval` syntax
18276
+ * @returns The parsed expression
18277
+ * @throws {Error} If the expression has invalid syntax
18278
+ */
18279
+ parseExpression(expressionString) {
18280
+ return this._parseCache.parse(expressionString);
17902
18281
  }
17903
18282
  /**
17904
- * Evaluate a specific expression and update the cached result if it changed.
18283
+ * Evaluate an expression against the context data with `localContext`
18284
+ * layered over it, without copying either. A key in `localContext` wins over
18285
+ * the same context key. Called from a reactive render, the reader tracks only
18286
+ * the values the expression read.
18287
+ *
18288
+ * @param expressionString - Expression in `expr-eval` syntax
18289
+ * @param localContext - Values that apply to this evaluation only, such as a row's item
18290
+ * @returns The result; a syntax or evaluation failure is returned as `error`
17905
18291
  */
17906
- evaluateExpression(name) {
17907
- this.logger.debug(`Evaluating expression: ${String(name)}`);
17908
- const expression = this._expressions.get(name);
17909
- if (!expression) {
17910
- this.logger.warn(`Expression "${String(name)}" not found`);
17911
- return;
17912
- }
17913
- const newResult = expression.evaluate(this.data);
17914
- this.logger.debug(`Expression "${String(name)}" evaluated to:`, newResult);
17915
- const currentResult = expression.result;
17916
- if (newResult.value !== currentResult.value || newResult.error !== currentResult.error) {
17917
- this.logger.debug(
17918
- `Expression "${String(name)}" result changed from`,
17919
- currentResult,
17920
- "to",
17921
- newResult
17922
- );
17923
- expression.updateResult(newResult);
17924
- this.updateResult(name, newResult);
18292
+ evaluateWithLocalContext(expressionString, localContext = {}) {
18293
+ let parsed;
18294
+ try {
18295
+ parsed = this._parseCache.parse(expressionString);
18296
+ } catch (error) {
18297
+ return {
18298
+ value: void 0,
18299
+ error: error instanceof Error ? error.message : String(error)
18300
+ };
17925
18301
  }
18302
+ return parsed.evaluate(layerContext(this._data, localContext));
17926
18303
  }
17927
- /** Store a changed result in the reactive results object. */
17928
- updateResult(name, result) {
17929
- this.logger.debug(
17930
- `ExpressionEvaluator.updateResult called for "${name}":`,
17931
- result
17932
- );
17933
- kosAction(() => {
17934
- this._results[name] = result;
18304
+ createResultsView() {
18305
+ const lookup = (key) => typeof key === "string" ? this._expressions.get(key) : void 0;
18306
+ return new Proxy(new ExpressionResultsView(), {
18307
+ get: (target, key, receiver) => {
18308
+ const expression = lookup(key);
18309
+ return expression ? expression.result : Reflect.get(target, key, receiver);
18310
+ },
18311
+ has: (target, key) => lookup(key) !== void 0 || Reflect.has(target, key),
18312
+ ownKeys: () => Array.from(this._expressions.keys()),
18313
+ getOwnPropertyDescriptor: (_target, key) => {
18314
+ const expression = lookup(key);
18315
+ return expression ? {
18316
+ value: expression.result,
18317
+ enumerable: true,
18318
+ configurable: true,
18319
+ writable: false
18320
+ } : void 0;
18321
+ }
17935
18322
  });
17936
18323
  }
17937
18324
  /**
@@ -18944,30 +19331,6 @@ const LogStreamContainer = new SingletonKosModelRegistrationFactory({
18944
19331
  LogStreamContainer.addRelatedModel(LogStream);
18945
19332
  LogStreamContainer.addRelatedModel(LogBlockContainer);
18946
19333
  LogStreamContainer.addRelatedModel(LogBlock);
18947
- const isRankedInfo = (i) => i?.rank !== void 0;
18948
- const isRoleAwareInfo = (i) => i?.visibleRole !== void 0;
18949
- const isColorAwareInfo = (i) => i?.color !== void 0;
18950
- const defaultTroubleRankMapper = (trouble) => {
18951
- const info = trouble.info ?? {};
18952
- if (isRankedInfo(info)) {
18953
- return info.rank;
18954
- }
18955
- return 0;
18956
- };
18957
- const defaultTroubleColorMapper = (trouble) => {
18958
- const info = trouble.info ?? {};
18959
- if (isColorAwareInfo(info)) {
18960
- return info.color;
18961
- }
18962
- return "orange";
18963
- };
18964
- const defaultTroubleRoleMapper = (trouble) => {
18965
- const info = trouble.info ?? {};
18966
- if (isRoleAwareInfo(info)) {
18967
- return info.visibleRole;
18968
- }
18969
- return "TECHNICIAN";
18970
- };
18971
19334
  const { URL: URL$7 } = resolveServiceUrl();
18972
19335
  const { getAll: getAll$4, postModel: postModel$1 } = ServiceFactory.build({
18973
19336
  basePath: `${URL$7}/api/kos/troubles`
@@ -19034,6 +19397,30 @@ const bulkResolveTroubles = async (troubleIds, servicePath = "/api/kos/troubles"
19034
19397
  return futureResponse;
19035
19398
  }
19036
19399
  };
19400
+ const isRankedInfo = (i) => i?.rank !== void 0;
19401
+ const isRoleAwareInfo = (i) => i?.visibleRole !== void 0;
19402
+ const isColorAwareInfo = (i) => i?.color !== void 0;
19403
+ const defaultTroubleRankMapper = (trouble) => {
19404
+ const info = trouble.info ?? {};
19405
+ if (isRankedInfo(info)) {
19406
+ return info.rank;
19407
+ }
19408
+ return 0;
19409
+ };
19410
+ const defaultTroubleColorMapper = (trouble) => {
19411
+ const info = trouble.info ?? {};
19412
+ if (isColorAwareInfo(info)) {
19413
+ return info.color;
19414
+ }
19415
+ return "orange";
19416
+ };
19417
+ const defaultTroubleRoleMapper = (trouble) => {
19418
+ const info = trouble.info ?? {};
19419
+ if (isRoleAwareInfo(info)) {
19420
+ return info.visibleRole;
19421
+ }
19422
+ return "TECHNICIAN";
19423
+ };
19037
19424
  const EXTENSION_TROUBLE_DATA_MAPPER = "troubleDataMapper";
19038
19425
  const troubleMappers$1 = /* @__PURE__ */ new Map();
19039
19426
  registerExtensionPoint(EXTENSION_TROUBLE_DATA_MAPPER, {
@@ -19321,29 +19708,24 @@ const Trouble = {
19321
19708
  predicate: isKosModel(MODEL_TYPE$e),
19322
19709
  factory: Kos.Factory.create(MODEL_TYPE$e)
19323
19710
  };
19324
- var __defProp$b = Object.defineProperty;
19325
- var __getOwnPropDesc$e = Object.getOwnPropertyDescriptor;
19326
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
19327
- var __decorateClass$e = (decorators, target, key, kind) => {
19328
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$e(target, key) : target;
19329
- for (var i = decorators.length - 1, decorator; i >= 0; i--)
19330
- if (decorator = decorators[i])
19331
- result = (kind ? decorator(target, key, result) : decorator(result)) || result;
19332
- if (kind && result) __defProp$b(target, key, result);
19333
- return result;
19334
- };
19335
- var __publicField = (obj, key, value) => __defNormalProp(obj, key + "", value);
19336
- const addTrouble = (trouble) => {
19337
- const options = {
19711
+ function mapTroubleToOptions(dto) {
19712
+ const { trouble } = dto;
19713
+ return {
19338
19714
  ...trouble,
19715
+ servicePath: dto.servicePath,
19339
19716
  rank: troubleRankMapper(trouble),
19340
19717
  color: troubleColorMapper(trouble),
19341
19718
  role: troubleRoleMapper(trouble),
19342
- id: String(trouble.id)
19719
+ id: String(trouble.id),
19720
+ rawJson: trouble
19343
19721
  };
19344
- const newTrouble = Trouble.factory(`trouble-${trouble.id}`)(options);
19345
- return newTrouble;
19346
- };
19722
+ }
19723
+ function createTroubleModel(dto) {
19724
+ return Trouble.factory(dto.id)(mapTroubleToOptions(dto));
19725
+ }
19726
+ function mapTroubleToDto(trouble, servicePath) {
19727
+ return { id: `trouble-${trouble.id}`, servicePath, trouble };
19728
+ }
19347
19729
  function troubleRankMapper(trouble) {
19348
19730
  const _rank = ExtensionManager.propertyMapper.hasMapper(
19349
19731
  KosCoreModelPropertyMapper.TroubleRank
@@ -19371,6 +19753,18 @@ function troubleRoleMapper(trouble) {
19371
19753
  ) : defaultTroubleRoleMapper(trouble);
19372
19754
  return role.toLowerCase();
19373
19755
  }
19756
+ var __defProp$b = Object.defineProperty;
19757
+ var __getOwnPropDesc$e = Object.getOwnPropertyDescriptor;
19758
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
19759
+ var __decorateClass$e = (decorators, target, key, kind) => {
19760
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$e(target, key) : target;
19761
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
19762
+ if (decorator = decorators[i])
19763
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
19764
+ if (kind && result) __defProp$b(target, key, result);
19765
+ return result;
19766
+ };
19767
+ var __publicField = (obj, key, value) => __defNormalProp(obj, key + "", value);
19374
19768
  const MODEL_TYPE$d = "trouble-container-model";
19375
19769
  class Troubles {
19376
19770
  static INDEX_TROUBLES_BY_IFACE = "byIface";
@@ -19391,30 +19785,21 @@ let TroubleContainerModelImpl = class {
19391
19785
  async reload() {
19392
19786
  this.logger.info("reloading trouble container");
19393
19787
  const _troubles = await getTroubles(this.servicePath);
19394
- const incoming = _troubles?.data ?? [];
19395
- const incomingKeys = new Set(incoming.map((t) => `trouble-${t.id}`));
19396
- const toRemove = this.troubles.data.map((m) => m.id).filter((id) => !incomingKeys.has(id));
19397
- const toAdd = incoming.filter((t) => !this.troubles.getModel(`trouble-${t.id}`)).map(addTrouble);
19398
- this.troubles.removeAll(toRemove);
19399
- this.troubles.addAll(toAdd);
19788
+ this.reconcile(
19789
+ (_troubles?.data ?? []).map(
19790
+ (trouble) => mapTroubleToDto(trouble, this.servicePath)
19791
+ )
19792
+ );
19400
19793
  }
19401
19794
  async load() {
19402
19795
  this.logger.debug("loading trouble container");
19403
19796
  try {
19404
19797
  const _troubles = await getTroubles(this.servicePath);
19405
- _troubles?.data.forEach((trouble) => {
19406
- const options = {
19407
- ...trouble,
19408
- servicePath: this.servicePath,
19409
- rank: troubleRankMapper(trouble),
19410
- color: troubleColorMapper(trouble),
19411
- role: troubleRoleMapper(trouble),
19412
- id: String(trouble.id),
19413
- rawJson: trouble
19414
- };
19415
- const newTrouble = Trouble.factory(`trouble-${trouble.id}`)(options);
19416
- this.troubles.addModel(newTrouble);
19417
- });
19798
+ this.reconcile(
19799
+ (_troubles?.data ?? []).map(
19800
+ (trouble) => mapTroubleToDto(trouble, this.servicePath)
19801
+ )
19802
+ );
19418
19803
  } catch (e) {
19419
19804
  this.logger.error(e);
19420
19805
  throw e;
@@ -19433,20 +19818,11 @@ let TroubleContainerModelImpl = class {
19433
19818
  }
19434
19819
  }
19435
19820
  handleTroubleAdded(trouble) {
19436
- const options = {
19437
- ...trouble,
19438
- servicePath: this.servicePath,
19439
- rank: troubleRankMapper(trouble),
19440
- color: troubleColorMapper(trouble),
19441
- role: troubleRoleMapper(trouble),
19442
- id: String(trouble.id),
19443
- rawJson: trouble
19444
- };
19445
- if (options.role === "NONE") {
19821
+ const dto = mapTroubleToDto(trouble, this.servicePath);
19822
+ if (mapTroubleToOptions(dto).role === "NONE") {
19446
19823
  return;
19447
19824
  }
19448
- const newTrouble = Trouble.factory(`trouble-${trouble.id}`)(options);
19449
- this.troubles.addModel(newTrouble);
19825
+ this.troubles.addModel(createTroubleModel(dto));
19450
19826
  }
19451
19827
  };
19452
19828
  __publicField(TroubleContainerModelImpl, "Registration");
@@ -19477,7 +19853,8 @@ TroubleContainerModelImpl = __decorateClass$e([
19477
19853
  [Troubles.INDEX_TROUBLES_BY_DEFERRED]: "deferred"
19478
19854
  },
19479
19855
  sortKey: Troubles.SORT_KEY_RANK
19480
- }
19856
+ },
19857
+ reconcile: { create: createTroubleModel }
19481
19858
  })
19482
19859
  ], TroubleContainerModelImpl);
19483
19860
  const TroubleContainer = TroubleContainerModelImpl.Registration;
@@ -24322,6 +24699,7 @@ exports.parseWildcardSegment = parseWildcardSegment;
24322
24699
  exports.pipe = pipe;
24323
24700
  exports.post = post;
24324
24701
  exports.preloadKosModel = preloadKosModel;
24702
+ exports.processId = processId;
24325
24703
  exports.publish = publish;
24326
24704
  exports.put = put;
24327
24705
  exports.registerCompanionModel = registerCompanionModel;
@@ -24333,9 +24711,12 @@ exports.registerLegacyModel = registerLegacyModel;
24333
24711
  exports.resetKosModel = resetKosModel;
24334
24712
  exports.resolveBaseUrl = resolveBaseUrl;
24335
24713
  exports.resolveChild = resolveChild;
24714
+ exports.resolveContainerDeltas = resolveContainerDeltas;
24715
+ exports.resolveItemListDeltas = resolveItemListDeltas;
24336
24716
  exports.resolveKosCompanion = resolveKosCompanion;
24337
24717
  exports.resolveKosContext = resolveKosContext;
24338
24718
  exports.resolveKosProfiles = resolveKosProfiles;
24719
+ exports.resolveListDeltas = resolveListDeltas;
24339
24720
  exports.resolveServiceRequestParameters = resolveServiceRequestParameters;
24340
24721
  exports.resolveServiceUrl = resolveServiceUrl;
24341
24722
  exports.resolveTrouble = resolveTrouble;
@@ -24364,4 +24745,4 @@ exports.waitForAppToStart = waitForAppToStart;
24364
24745
  exports.waitForAppsToStart = waitForAppsToStart;
24365
24746
  exports.whenReady = whenReady;
24366
24747
  exports.wrapWithFutureLifecycle = wrapWithFutureLifecycle;
24367
- //# sourceMappingURL=software-info-registration-CY_E6Rw7.cjs.map
24748
+ //# sourceMappingURL=software-info-registration-BAk6JWkz.cjs.map