@kosdev-code/kos-ui-sdk 3.0.35 → 3.0.37

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 (37) hide show
  1. package/core/core/model/kos-subscription-manager.d.ts.map +1 -1
  2. package/core/core/transport/mock/future-simulator.d.ts +5 -1
  3. package/core/core/transport/mock/future-simulator.d.ts.map +1 -1
  4. package/core/core/transport/mock/mock-config.d.ts.map +1 -1
  5. package/core/core/transport/mock/mock-interceptor.d.ts.map +1 -1
  6. package/core/core/transport/mock/mock-registry.d.ts +14 -5
  7. package/core/core/transport/mock/mock-registry.d.ts.map +1 -1
  8. package/core/core/transport/mock/mock-types.d.ts +63 -0
  9. package/core/core/transport/mock/mock-types.d.ts.map +1 -1
  10. package/core/util/index.d.ts +2 -0
  11. package/core/util/index.d.ts.map +1 -1
  12. package/core/util/kos-local-topic.d.ts +73 -0
  13. package/core/util/kos-local-topic.d.ts.map +1 -0
  14. package/core/util/kos-topic-client.d.ts +79 -0
  15. package/core/util/kos-topic-client.d.ts.map +1 -0
  16. package/index.cjs +77 -7
  17. package/index.cjs.map +1 -1
  18. package/index.js +286 -216
  19. package/index.js.map +1 -1
  20. package/models/models/storage-device/storage-device-container-model.d.ts +4 -3
  21. package/models/models/storage-device/storage-device-container-model.d.ts.map +1 -1
  22. package/models/utils/index.d.ts +1 -0
  23. package/models/utils/index.d.ts.map +1 -1
  24. package/models/utils/topics/kos/daily/topic.d.ts +74 -0
  25. package/models/utils/topics/kos/daily/topic.d.ts.map +1 -0
  26. package/models/utils/topics/kos/daily/topics.d.ts +1026 -0
  27. package/models/utils/topics-index.d.ts +8 -0
  28. package/models/utils/topics-index.d.ts.map +1 -0
  29. package/package.json +2 -2
  30. package/{software-info-registration-Co9Wq_-n.js → software-info-registration-BqhJP3ww.js} +457 -328
  31. package/software-info-registration-BqhJP3ww.js.map +1 -0
  32. package/{software-info-registration-C-fplY8u.cjs → software-info-registration-DTbgaSeR.cjs} +156 -27
  33. package/software-info-registration-DTbgaSeR.cjs.map +1 -0
  34. package/testing.cjs +1 -1
  35. package/testing.js +1 -1
  36. package/software-info-registration-C-fplY8u.cjs.map +0 -1
  37. package/software-info-registration-Co9Wq_-n.js.map +0 -1
@@ -7573,6 +7573,43 @@ class KosMockFutureSimulator {
7573
7573
  }
7574
7574
  return void 0;
7575
7575
  }
7576
+ endWith(method, pattern, options) {
7577
+ const ended = /* @__PURE__ */ new Set();
7578
+ return this.deps.transformFuture(
7579
+ method,
7580
+ pattern,
7581
+ (future) => {
7582
+ if (ended.has(future.id)) {
7583
+ if (future.endState) {
7584
+ ended.delete(future.id);
7585
+ }
7586
+ return null;
7587
+ }
7588
+ if (future.endState === "CANCEL") {
7589
+ return void 0;
7590
+ }
7591
+ const reached = !!future.endState || options.atProgress !== void 0 && (future.progress ?? 0) >= options.atProgress;
7592
+ if (!reached) {
7593
+ return void 0;
7594
+ }
7595
+ if (!future.endState) {
7596
+ const simulated = this.futures.get(future.id);
7597
+ if (simulated) {
7598
+ simulated.dispose();
7599
+ } else {
7600
+ ended.add(future.id);
7601
+ }
7602
+ }
7603
+ return {
7604
+ ...future,
7605
+ endState: options.endState,
7606
+ reason: options.reason,
7607
+ remainingTimeMs: 0
7608
+ };
7609
+ },
7610
+ { description: `futures end with ${options.endState}` }
7611
+ );
7612
+ }
7576
7613
  get active() {
7577
7614
  return [...this.futures.values()].filter((handle) => !handle.done);
7578
7615
  }
@@ -8311,6 +8348,8 @@ const log$M = KosLog.createLogger({
8311
8348
  });
8312
8349
  const asWireValue = (value) => typeof value === "string" ? value : JSON.stringify(value);
8313
8350
  const configTopic = (beanId) => `/kos/config/${beanId}`;
8351
+ const DEVICE_CONFIG_BASE = "/api/kos/config";
8352
+ const STUDIO_CONFIG_BASE = "/api/config";
8314
8353
  const changeEnvelope = (props, previousValues = {}) => {
8315
8354
  return {
8316
8355
  changes: Object.entries(props).map(([attr, value]) => {
@@ -8334,9 +8373,10 @@ function createConfigFacade(registry) {
8334
8373
  const inject = (beanId, injection) => {
8335
8374
  const current = { ...injection.props };
8336
8375
  const schema = injection.schema ?? {};
8376
+ const base = injection.studio ? STUDIO_CONFIG_BASE : DEVICE_CONFIG_BASE;
8337
8377
  const transformerHandle = registry.transformResponse(
8338
8378
  "GET",
8339
- `/api/kos/config/details/${beanId}/:depth`,
8379
+ `${base}/details/${beanId}/:depth`,
8340
8380
  (body) => {
8341
8381
  if (!body || typeof body !== "object") {
8342
8382
  return void 0;
@@ -8364,7 +8404,7 @@ function createConfigFacade(registry) {
8364
8404
  { description: `config.inject ${beanId}` }
8365
8405
  );
8366
8406
  const routeHandle = registry.post(
8367
- `/api/kos/config/${beanId}`,
8407
+ `${base}/${beanId}`,
8368
8408
  (req) => {
8369
8409
  const requested = req.json();
8370
8410
  if (!requested) {
@@ -8430,7 +8470,8 @@ class KosMockRegistry {
8430
8470
  state = /* @__PURE__ */ new Map();
8431
8471
  futures = new KosMockFutureSimulator({
8432
8472
  emitFrame: (frame) => this.publishFrame(frame),
8433
- ensureCancelRoutes: () => this.ensureFutureCancelRoutes()
8473
+ ensureCancelRoutes: () => this.ensureFutureCancelRoutes(),
8474
+ transformFuture: (method, pattern, transform, options) => this.transformFuture(method, pattern, transform, options)
8434
8475
  });
8435
8476
  recorder = new KosMockRecorder();
8436
8477
  config = createConfigFacade(this);
@@ -8467,13 +8508,85 @@ class KosMockRegistry {
8467
8508
  disable: remove
8468
8509
  };
8469
8510
  }
8511
+ futureTransformers = [];
8512
+ // Requests by tracker: the only link from a future frame to its endpoint.
8513
+ trackedRequests = /* @__PURE__ */ new Map();
8514
+ transformFuture(method, pattern, transform, options = {}) {
8515
+ const registered = {
8516
+ id: options.id ?? uuid(),
8517
+ method,
8518
+ pattern,
8519
+ compiled: compileRoutePattern(pattern),
8520
+ transform,
8521
+ description: options.description
8522
+ };
8523
+ this.futureTransformers.push(registered);
8524
+ const remove = () => {
8525
+ this.futureTransformers = this.futureTransformers.filter(
8526
+ (candidate) => candidate.id !== registered.id
8527
+ );
8528
+ };
8529
+ return {
8530
+ id: registered.id,
8531
+ remove,
8532
+ enable: () => void 0,
8533
+ disable: remove
8534
+ };
8535
+ }
8536
+ /** Runs a `kos.future` frame through the future transformers. */
8537
+ transformFutureFrame(frame, headers, body) {
8538
+ let future;
8539
+ try {
8540
+ future = JSON.parse(body);
8541
+ } catch {
8542
+ return frame;
8543
+ }
8544
+ const tracker = future?.tracker;
8545
+ const request = tracker ? this.trackedRequests.get(tracker) : void 0;
8546
+ if (!tracker || !request) {
8547
+ return frame;
8548
+ }
8549
+ if (future.endState) {
8550
+ this.trackedRequests.delete(tracker);
8551
+ }
8552
+ const matching = this.futureTransformers.filter(
8553
+ (transformer) => methodMatches(transformer.method, request.method) && matchRoutePattern(transformer.compiled, request.path) !== void 0
8554
+ );
8555
+ let current = future;
8556
+ let changed = false;
8557
+ for (const transformer of matching) {
8558
+ try {
8559
+ const result = transformer.transform(current, { request });
8560
+ if (result === null) {
8561
+ return void 0;
8562
+ }
8563
+ if (result !== void 0) {
8564
+ current = result;
8565
+ changed = true;
8566
+ }
8567
+ } catch (error) {
8568
+ log$L.error(
8569
+ `KosMock future transformer for ${transformer.method} ${transformer.pattern} threw`,
8570
+ error?.message
8571
+ );
8572
+ }
8573
+ }
8574
+ if (!changed) {
8575
+ return frame;
8576
+ }
8577
+ return encodeRawFrame(
8578
+ { ...headers, [KOS_MOCK_TRANSFORMED_HEADER]: "true" },
8579
+ JSON.stringify(current)
8580
+ );
8581
+ }
8470
8582
  /**
8471
- * Interceptor seam: patches a matching inbound response frame through the
8472
- * transformer chain before it reaches the app. Returns the (possibly
8473
- * modified) frame. Internal.
8583
+ * Interceptor seam: patches a matching inbound response or future frame
8584
+ * through its transformer chain before it reaches the app. Returns the
8585
+ * (possibly modified) frame, or undefined when a future transformer dropped
8586
+ * it. Internal.
8474
8587
  */
8475
8588
  transformInboundFrame(frame) {
8476
- if (this.transformers.length === 0) {
8589
+ if (this.transformers.length === 0 && this.futureTransformers.length === 0) {
8477
8590
  return frame;
8478
8591
  }
8479
8592
  let headers;
@@ -8485,7 +8598,7 @@ class KosMockRegistry {
8485
8598
  }
8486
8599
  const responseId = headers["response-id"];
8487
8600
  if (!responseId) {
8488
- return frame;
8601
+ return headers["type"] === KOS_FUTURE_TYPE && this.futureTransformers.length > 0 ? this.transformFutureFrame(frame, headers, body) : frame;
8489
8602
  }
8490
8603
  const request = this.pendingRequests.get(responseId);
8491
8604
  this.pendingRequests.delete(responseId);
@@ -8566,7 +8679,7 @@ class KosMockRegistry {
8566
8679
  const hasRequestObservers = [...this.observers].some(
8567
8680
  (observer) => observer.onRequest
8568
8681
  );
8569
- if (!hasRequestObservers && this.transformers.length === 0) {
8682
+ if (!hasRequestObservers && this.transformers.length === 0 && this.futureTransformers.length === 0) {
8570
8683
  return;
8571
8684
  }
8572
8685
  const frame = decodeRequestFrame(data);
@@ -8583,6 +8696,15 @@ class KosMockRegistry {
8583
8696
  tracker: frame.tracker,
8584
8697
  rawBody: frame.rawBody
8585
8698
  };
8699
+ if (this.futureTransformers.length > 0 && frame.tracker) {
8700
+ if (this.trackedRequests.size >= PENDING_REQUEST_CAP) {
8701
+ const oldest = this.trackedRequests.keys().next().value;
8702
+ if (oldest !== void 0) {
8703
+ this.trackedRequests.delete(oldest);
8704
+ }
8705
+ }
8706
+ this.trackedRequests.set(frame.tracker, observation);
8707
+ }
8586
8708
  if (this.transformers.length > 0) {
8587
8709
  if (this.pendingRequests.size >= PENDING_REQUEST_CAP) {
8588
8710
  const oldest = this.pendingRequests.keys().next().value;
@@ -8828,14 +8950,16 @@ class KosMockRegistry {
8828
8950
  enabled: this.enabled,
8829
8951
  standalone: this.standalone,
8830
8952
  routes: this.list(),
8831
- transformers: this.transformers.map((transformer) => {
8832
- return {
8833
- id: transformer.id,
8834
- method: transformer.method,
8835
- pattern: transformer.pattern,
8836
- description: transformer.description
8837
- };
8838
- }),
8953
+ transformers: [...this.transformers, ...this.futureTransformers].map(
8954
+ (transformer) => {
8955
+ return {
8956
+ id: transformer.id,
8957
+ method: transformer.method,
8958
+ pattern: transformer.pattern,
8959
+ description: transformer.description
8960
+ };
8961
+ }
8962
+ ),
8839
8963
  setups: this.setups.active().map((setup) => {
8840
8964
  return { name: setup.name, url: setup.url };
8841
8965
  }),
@@ -8851,6 +8975,8 @@ class KosMockRegistry {
8851
8975
  [...this.playbacks].forEach((playback) => playback.stop());
8852
8976
  this.routes = [];
8853
8977
  this.transformers = [];
8978
+ this.futureTransformers = [];
8979
+ this.trackedRequests.clear();
8854
8980
  this.pendingRequests.clear();
8855
8981
  this.cancelRoutesRegistered = false;
8856
8982
  this.emitters.forEach((timer) => clearInterval(timer));
@@ -9165,6 +9291,9 @@ class MockInterceptorTransport {
9165
9291
  */
9166
9292
  deliver(frame) {
9167
9293
  const transformed = this.registry.transformInboundFrame(frame);
9294
+ if (transformed === void 0) {
9295
+ return;
9296
+ }
9168
9297
  this.messageHandler?.({ data: transformed });
9169
9298
  this.registry.noteInboundFrame(transformed);
9170
9299
  }
@@ -10204,13 +10333,11 @@ class KosSubscriptionManager {
10204
10333
  };
10205
10334
  }
10206
10335
  resolvePropKey(template) {
10207
- const propRegex = /.*({PROP_(.+)})/;
10208
- let topic = template.includes("{MODEL_ID}") ? template.replace("{MODEL_ID}", this.modelId) : template;
10209
- const match = topic.match(propRegex);
10210
- if (match && match[2] in this.modelData) {
10211
- topic = topic.replace(match[1], this.modelData[match[2]]);
10212
- }
10213
- return topic;
10336
+ const topic = template.includes("{MODEL_ID}") ? template.replace("{MODEL_ID}", this.modelId) : template;
10337
+ return topic.replace(
10338
+ /{PROP_([^}]+)}/g,
10339
+ (placeholder, propName) => propName in this.modelData ? this.modelData[propName] : placeholder
10340
+ );
10214
10341
  }
10215
10342
  // ===== FLOW CONTROL METHODS =====
10216
10343
  async subscribeWithFlowControl(config2, resolvedTopic, lifecycle) {
@@ -23652,6 +23779,7 @@ var __decorateClass$6 = (decorators, target, key, kind) => {
23652
23779
  };
23653
23780
  const MODEL_TYPE$5 = "storage-device-container-model";
23654
23781
  const TOPIC_STORAGE_AVAILABILITY = "/kos/storage";
23782
+ const isInsertedStorage = (device) => !device.local;
23655
23783
  let StorageDeviceContainerModelImpl = class {
23656
23784
  id;
23657
23785
  logger;
@@ -23690,7 +23818,8 @@ let StorageDeviceContainerModelImpl = class {
23690
23818
  get volumes() {
23691
23819
  return this.data;
23692
23820
  }
23693
- handleStorageAvailability(devices) {
23821
+ handleStorageAvailability(payload) {
23822
+ const devices = payload.filter(isInsertedStorage);
23694
23823
  const toRemove = this._models.data.filter(
23695
23824
  (model) => !devices.find((device) => device.id === model.id)
23696
23825
  );
@@ -23718,7 +23847,7 @@ let StorageDeviceContainerModelImpl = class {
23718
23847
  async load() {
23719
23848
  this.logger.debug(`loading storage-device-container container ${this.id}`);
23720
23849
  const storageDevices = await getStorageDevices();
23721
- storageDevices.forEach((storageDevice) => {
23850
+ storageDevices.filter(isInsertedStorage).forEach((storageDevice) => {
23722
23851
  if (storageDevice.deviceType !== "disk") {
23723
23852
  const options = {
23724
23853
  ...storageDevice,
@@ -25409,4 +25538,4 @@ exports.waitForRequest = waitForRequest;
25409
25538
  exports.whenReady = whenReady;
25410
25539
  exports.withCancellation = withCancellation;
25411
25540
  exports.wrapWithFutureLifecycle = wrapWithFutureLifecycle;
25412
- //# sourceMappingURL=software-info-registration-C-fplY8u.cjs.map
25541
+ //# sourceMappingURL=software-info-registration-DTbgaSeR.cjs.map