@kosdev-code/kos-ui-sdk 0.1.0-next.958 → 0.1.0-next.966

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.
@@ -1 +1 @@
1
- {"version":3,"file":"model-type-guards.d.ts","sourceRoot":"","sources":["../../../../../packages/kos-ui-sdk/src/core/util/model-type-guards.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEtD;;GAEG;AACH,eAAO,MAAM,WAAW,GAAI,OAAO,GAAG,KAAG,KAAK,IAAI;IAAE,MAAM,EAAE,MAAM,MAAM,CAAA;CACpC,CAAC;AAErC;;GAEG;AACH,eAAO,MAAM,cAAc,GAAI,OAAO,GAAG,KAAG,KAAK,IAAI,aACd,CAAC;AAExC;;GAEG;AACH,eAAO,MAAM,mBAAmB,GAC9B,OAAO,GAAG,KACT,KAAK,IAAI,kBAAkB,CAAC,GAAG,CACyB,CAAC;AAE5D;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,GACvB,WAAW,GAAG,KACb,aAAa,GAAG,aAAa,EAAE,GAAG,SAepC,CAAC"}
1
+ {"version":3,"file":"model-type-guards.d.ts","sourceRoot":"","sources":["../../../../../packages/kos-ui-sdk/src/core/util/model-type-guards.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEtD;;GAEG;AACH,eAAO,MAAM,WAAW,GAAI,OAAO,GAAG,KAAG,KAAK,IAAI;IAAE,MAAM,EAAE,MAAM,MAAM,CAAA;CACpC,CAAC;AAErC;;GAEG;AACH,eAAO,MAAM,cAAc,GAAI,OAAO,GAAG,KAAG,KAAK,IAAI,aACd,CAAC;AAExC;;GAEG;AACH,eAAO,MAAM,mBAAmB,GAC9B,OAAO,GAAG,KACT,KAAK,IAAI,kBAAkB,CAAC,GAAG,CAIP,CAAC;AAE5B;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,GACvB,WAAW,GAAG,KACb,aAAa,GAAG,aAAa,EAAE,GAAG,SAepC,CAAC"}
package/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const service$8 = require("./software-info-registration-Y1iADHWT.cjs");
3
+ const service$8 = require("./software-info-registration-BAk6JWkz.cjs");
4
4
  const mobx = require("mobx");
5
5
  const log$6 = require("loglevel");
6
6
  const jsxRuntime = require("@emotion/react/jsx-runtime");
@@ -1750,7 +1750,7 @@ const updateRegion = async (region) => {
1750
1750
  regionInfo.updateProperty(region);
1751
1751
  };
1752
1752
  async function getKosServiceApi() {
1753
- const { default: API } = await Promise.resolve().then(() => require("./software-info-registration-Y1iADHWT.cjs")).then((n) => n.service);
1753
+ const { default: API } = await Promise.resolve().then(() => require("./software-info-registration-BAk6JWkz.cjs")).then((n) => n.service);
1754
1754
  return API;
1755
1755
  }
1756
1756
  function kosServiceRequest$7(params) {
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { s as subscribe, p as publish, k as kosParentAware, C as CompanionParentModel, K as KosContextManager, M as MultipleFutureContainerSetup, L as LogConfig, R as ReferenceConfig, T as TroubleAwareSetup, D as DependencyModels, E as ExtensionManager, S as SubscriptionHandlers, a as KosViewModelSymbol, V as ViewModelConfig, b as StateMachineSetup, c as DependencyLifecycle, i as injectStateMachineSupport, d as initializeStateMachine, e as ModelEffects, f as KosModelVisitor, g as KosCore, h as sendKosMessageResponse, j as KosLog, u as uuid, I as INDEX_RECORD_SYMBOL, l as INDEX_COLLECTION_KEY, m as KosContainerIndexEvents, n as isIndexableItem, o as Kos, q as isKosModel, r as ConfigBean, t as configBeanModelId, v as getRegionInfo, w as getRegions, x as Registration, y as getStateBeanData, z as StateBean, A as getStateProps, B as StateProp, F as deleteKeyValue, G as deleteKeyValueNamespace, H as getKeyValue, J as updateKeyValue, N as getLogOverrides, O as getTimezone, P as setDate, Q as setTime, U as setTimezone, W as createOverride, X as getLogStreamBlock, Y as getLogStreamBlocks, Z as getLogStreams, _ as subscribeToLogStream, $ as unsubscribeFromLogStream, a0 as bulkResolveTroubles, a1 as getTroubles, a2 as resolveTrouble, a3 as sendCanvasData, a4 as getDeviceDetails, a5 as getSerialNumber, a6 as getNetworkInterfaces, a7 as getStorageDevices, a8 as getAvailableUpdates, a9 as installUpdate, aa as TranslationContainer, ab as whenReady, ac as KosCoreModelPropertyMapper, ad as CanvasDispatcher, ae as KeyValue, af as destroyKosModel, ag as createClient, ah as kosServiceRequest$8, ai as getSoftwareInfos, aj as getSoftwareInfosWithCancel, ak as BASE_URL, al as kosFetch, am as kosModel, an as kosLoggerAware, ao as kosContainerAware, ap as kosChild, aq as api$8, ar as ObservableData, as as WebSocketTransport, at as kosComputed, au as KosModelRegistrationFactory, av as getKosModelSync, aw as kosAutoEffect, ax as WebSocketEvents, ay as modelHookCache, az as isUpdateable, aA as KosModelState, aB as KosModelEvents, aC as clearModelHookCacheEntry, aD as KosTime, aE as SoftwareInfo, aF as getQueryParams, aG as getKosLocalizationDescriptor, aH as Device, aI as NetworkInterfaceContainer, aJ as Ota, aK as StorageDeviceContainer, aL as TimerManager, aM as TIMER_END, aN as TIMER_EVENT, aO as TOPIC_TIMER_TICK_EVENT, aP as getKosModel, aQ as Trouble, aR as TroubleContainer, aS as UsbUpdateContainer, aT as Registration$1 } from "./software-info-registration-C8kf-pBB.js";
2
- import { aU, aV, aW, aX, aY, aZ, a_, a$, b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, ba, bb, bc, bd, be, bf, bg, bh, bi, bj, bk, bl, bm, bn, bo, bp, bq, br, bs, bt, bu, bv, bw, bx, by, bz, bA, bB, bC, bD, bE, bF, bG, bH, bI, bJ, bK, bL, bM, bN, bO, bP, bQ, bR, bS, bT, bU, bV, bW, bX, bY, bZ, b_, b$, c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, ca, cb, cc, cd, ce, cf, cg, ch, ci, cj, ck, cl, cm, cn, co, cp, cq, cr, cs, ct, cu, cv, cw, cx, cy, cz, cA, cB, cC, cD, cE, cF, cG, cH, cI, cJ, cK, cL, cM, cN, cO, cP, cQ, cR, cS, cT, cU, cV, cW, cX, cY, cZ, c_, c$, d0, d1, d2, d3, d4, d5, d6, d7, d8, d9, da, db, dc, dd, de, df, dg, dh, di, dj, dk, dl, dm, dn, dp, dq, dr, ds, dt, du, dv, dw, dx, dy, dz, dA, dB, dC, dD, dE, dF, dG, dH, dI, dJ, dK, dL, dM, dN, dO, dP, dQ, dR, dS, dT, dU, dV, dW, dX, dY, dZ, d_, d$, e0, e1, e2, e3, e4, e5, e6, e7, e8, e9, ea, eb, ec, ed, ee, ef, eg, eh, ei, ej, ek, el, em, en, eo, ep, eq, er, es, et, eu, ev, ew, ex, ey, ez, eA, eB, eC, eD, eE, eF, eG, eH, eI, eJ, eK, eL, eM, eN, eO, eP, eQ, eR, eS } from "./software-info-registration-C8kf-pBB.js";
1
+ import { s as subscribe, p as publish, k as kosParentAware, C as CompanionParentModel, K as KosContextManager, M as MultipleFutureContainerSetup, L as LogConfig, R as ReferenceConfig, T as TroubleAwareSetup, D as DependencyModels, E as ExtensionManager, S as SubscriptionHandlers, a as KosViewModelSymbol, V as ViewModelConfig, b as StateMachineSetup, c as DependencyLifecycle, i as injectStateMachineSupport, d as initializeStateMachine, e as ModelEffects, f as KosModelVisitor, g as KosCore, h as sendKosMessageResponse, j as KosLog, u as uuid, I as INDEX_RECORD_SYMBOL, l as INDEX_COLLECTION_KEY, m as KosContainerIndexEvents, n as isIndexableItem, o as Kos, q as isKosModel, r as ConfigBean, t as configBeanModelId, v as getRegionInfo, w as getRegions, x as Registration, y as getStateBeanData, z as StateBean, A as getStateProps, B as StateProp, F as deleteKeyValue, G as deleteKeyValueNamespace, H as getKeyValue, J as updateKeyValue, N as getLogOverrides, O as getTimezone, P as setDate, Q as setTime, U as setTimezone, W as createOverride, X as getLogStreamBlock, Y as getLogStreamBlocks, Z as getLogStreams, _ as subscribeToLogStream, $ as unsubscribeFromLogStream, a0 as bulkResolveTroubles, a1 as getTroubles, a2 as resolveTrouble, a3 as sendCanvasData, a4 as getDeviceDetails, a5 as getSerialNumber, a6 as getNetworkInterfaces, a7 as getStorageDevices, a8 as getAvailableUpdates, a9 as installUpdate, aa as TranslationContainer, ab as whenReady, ac as KosCoreModelPropertyMapper, ad as CanvasDispatcher, ae as KeyValue, af as destroyKosModel, ag as createClient, ah as kosServiceRequest$8, ai as getSoftwareInfos, aj as getSoftwareInfosWithCancel, ak as BASE_URL, al as kosFetch, am as kosModel, an as kosLoggerAware, ao as kosContainerAware, ap as kosChild, aq as api$8, ar as ObservableData, as as WebSocketTransport, at as kosComputed, au as KosModelRegistrationFactory, av as getKosModelSync, aw as kosAutoEffect, ax as WebSocketEvents, ay as modelHookCache, az as isUpdateable, aA as KosModelState, aB as KosModelEvents, aC as clearModelHookCacheEntry, aD as KosTime, aE as SoftwareInfo, aF as getQueryParams, aG as getKosLocalizationDescriptor, aH as Device, aI as NetworkInterfaceContainer, aJ as Ota, aK as StorageDeviceContainer, aL as TimerManager, aM as TIMER_END, aN as TIMER_EVENT, aO as TOPIC_TIMER_TICK_EVENT, aP as getKosModel, aQ as Trouble, aR as TroubleContainer, aS as UsbUpdateContainer, aT as Registration$1 } from "./software-info-registration-CefJgWke.js";
2
+ import { aU, aV, aW, aX, aY, aZ, a_, a$, b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, ba, bb, bc, bd, be, bf, bg, bh, bi, bj, bk, bl, bm, bn, bo, bp, bq, br, bs, bt, bu, bv, bw, bx, by, bz, bA, bB, bC, bD, bE, bF, bG, bH, bI, bJ, bK, bL, bM, bN, bO, bP, bQ, bR, bS, bT, bU, bV, bW, bX, bY, bZ, b_, b$, c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, ca, cb, cc, cd, ce, cf, cg, ch, ci, cj, ck, cl, cm, cn, co, cp, cq, cr, cs, ct, cu, cv, cw, cx, cy, cz, cA, cB, cC, cD, cE, cF, cG, cH, cI, cJ, cK, cL, cM, cN, cO, cP, cQ, cR, cS, cT, cU, cV, cW, cX, cY, cZ, c_, c$, d0, d1, d2, d3, d4, d5, d6, d7, d8, d9, da, db, dc, dd, de, df, dg, dh, di, dj, dk, dl, dm, dn, dp, dq, dr, ds, dt, du, dv, dw, dx, dy, dz, dA, dB, dC, dD, dE, dF, dG, dH, dI, dJ, dK, dL, dM, dN, dO, dP, dQ, dR, dS, dT, dU, dV, dW, dX, dY, dZ, d_, d$, e0, e1, e2, e3, e4, e5, e6, e7, e8, e9, ea, eb, ec, ed, ee, ef, eg, eh, ei, ej, ek, el, em, en, eo, ep, eq, er, es, et, eu, ev, ew, ex, ey, ez, eA, eB, eC, eD, eE, eF, eG, eH, eI, eJ, eK, eL, eM, eN, eO, eP, eQ, eR, eS } from "./software-info-registration-CefJgWke.js";
3
3
  import { action, reaction, autorun, makeAutoObservable, runInAction } from "mobx";
4
4
  import { makeAutoObservable as makeAutoObservable2, makeObservable } from "mobx";
5
5
  import log$6 from "loglevel";
@@ -1751,7 +1751,7 @@ const updateRegion = async (region) => {
1751
1751
  regionInfo.updateProperty(region);
1752
1752
  };
1753
1753
  async function getKosServiceApi() {
1754
- const { default: API } = await import("./software-info-registration-C8kf-pBB.js").then((n) => n.eT);
1754
+ const { default: API } = await import("./software-info-registration-CefJgWke.js").then((n) => n.eT);
1755
1755
  return API;
1756
1756
  }
1757
1757
  function kosServiceRequest$7(params) {
@@ -0,0 +1,29 @@
1
+ import { Parser } from 'expr-eval';
2
+ import { KosData } from '../../../core';
3
+ import { ExpressionResult } from './kos-expression-evaluator-model';
4
+ /**
5
+ * An expression parsed once and evaluated against any context object.
6
+ */
7
+ export interface ParsedExpression {
8
+ /** The expression string it was parsed from */
9
+ readonly expression: string;
10
+ /** Evaluate against the given context data; a failure is returned as `error`, not thrown */
11
+ evaluate(contextData: Record<string, unknown>): ExpressionResult;
12
+ }
13
+ /**
14
+ * Parsed expressions keyed by expression string, least recently used evicted
15
+ * first once `limit` is reached.
16
+ */
17
+ export declare class ExpressionParseCache {
18
+ private readonly parser;
19
+ private readonly limit;
20
+ private readonly entries;
21
+ constructor(parser: Parser, limit?: number);
22
+ parse(expression: string): ParsedExpression;
23
+ }
24
+ /**
25
+ * Layers `local` over `base` without copying either: a key `local` owns wins,
26
+ * every other key reads through to `base`.
27
+ */
28
+ export declare const layerContext: (base: KosData<Record<string, unknown>>, local: Record<string, unknown>) => Record<string, unknown>;
29
+ //# sourceMappingURL=expression-parse-cache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"expression-parse-cache.d.ts","sourceRoot":"","sources":["../../../../../../packages/kos-ui-sdk/src/models/models/kos-expression-evaluator/expression-parse-cache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AAEzE;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,+CAA+C;IAC/C,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,4FAA4F;IAC5F,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,gBAAgB,CAAC;CAClE;AA6BD;;;GAGG;AACH,qBAAa,oBAAoB;IAI7B,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,KAAK;IAJxB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAuC;gBAG5C,MAAM,EAAE,MAAM,EACd,KAAK,GAAE,MAA0B;IAGpD,KAAK,CAAC,UAAU,EAAE,MAAM,GAAG,gBAAgB;CAkB5C;AAED;;;GAGG;AACH,eAAO,MAAM,YAAY,GACvB,MAAM,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EACtC,OAAO,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC7B,MAAM,CAAC,MAAM,EAAE,OAAO,CAUrB,CAAC"}
@@ -1,4 +1,5 @@
1
1
  export type { KosExpressionEvaluatorModel, KosExpressionEvaluatorModelImpl, ExpressionResult, NamedExpression, } from './kos-expression-evaluator-model';
2
+ export type { ParsedExpression } from './expression-parse-cache';
2
3
  export type * from './types';
3
4
  export declare const KosExpressionEvaluator: import('../../..').KosModelRegistrationType<import('./kos-expression-evaluator-model').KosExpressionEvaluatorModel<string>, import('./types').KosExpressionEvaluatorOptions>;
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../packages/kos-ui-sdk/src/models/models/kos-expression-evaluator/index.ts"],"names":[],"mappings":"AAEA,YAAY,EACV,2BAA2B,EAC3B,+BAA+B,EAC/B,gBAAgB,EAChB,eAAe,GAChB,MAAM,kCAAkC,CAAC;AAC1C,mBAAmB,SAAS,CAAC;AAE7B,eAAO,MAAM,sBAAsB,8KACW,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../packages/kos-ui-sdk/src/models/models/kos-expression-evaluator/index.ts"],"names":[],"mappings":"AAEA,YAAY,EACV,2BAA2B,EAC3B,+BAA+B,EAC/B,gBAAgB,EAChB,eAAe,GAChB,MAAM,kCAAkC,CAAC;AAC1C,YAAY,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AACjE,mBAAmB,SAAS,CAAC;AAE7B,eAAO,MAAM,sBAAsB,8KACW,CAAC"}
@@ -2,6 +2,7 @@ import { KosModelRegistrationType } from '../../../core';
2
2
  import { IKosDataModel, KosCreationContext } from '../../../core/core/kosModel';
3
3
  import { IKosIdentifiable } from '../../../core/core/types';
4
4
  import { PublicModelInterface } from '../../../core/types';
5
+ import { ParsedExpression } from './expression-parse-cache';
5
6
  import { KosExpressionEvaluatorOptions } from './types';
6
7
  export declare const MODEL_TYPE = "kos-expression-evaluator-model";
7
8
  /**
@@ -18,18 +19,25 @@ export interface NamedExpression {
18
19
  name: string;
19
20
  /** The expression string (JavaScript-like syntax) */
20
21
  expression: string;
21
- /** Getter that returns the cached result */
22
+ /** The current result, re-evaluated only after a context value it read changes */
22
23
  get result(): ExpressionResult;
23
- /** Method to evaluate the expression with given context data */
24
+ /** Evaluate the expression against the given context data */
24
25
  evaluate(contextData: Record<string, unknown>): ExpressionResult;
25
- /** Method to update the cached result */
26
+ /**
27
+ * @deprecated The result is derived from the context data; this has no effect.
28
+ */
26
29
  updateResult(result: ExpressionResult): void;
27
30
  }
28
31
  /**
29
32
  * Evaluates named expressions against context data and keeps their results
30
- * current. Reading `results` re-evaluates every expression, so a
31
- * `kosComponent` or model effect that reads it re-renders when the context data
32
- * or a model added to the context changes.
33
+ * current. Each expression's result is a computed over the context values it
34
+ * reads: it re-evaluates only after one of those values changes, and only when
35
+ * read. A `kosComponent` or model effect that reads `results[name]` re-renders
36
+ * when that expression's result changes, and not for any other expression.
37
+ *
38
+ * `evaluateWithLocalContext` evaluates an expression against the context with
39
+ * a local object layered over it, such as a list row's item, and
40
+ * `parseExpression` returns a cached parse to evaluate against any object.
33
41
  *
34
42
  * Expressions use `expr-eval` syntax, plus the built-in functions `exists(value)`
35
43
  * and `isEmpty(value)` and any `customFunctions` passed in the options. The type
@@ -60,7 +68,8 @@ export declare class KosExpressionEvaluatorModelImpl<T extends string = string>
60
68
  private parser;
61
69
  private _data;
62
70
  private _expressions;
63
- private _results;
71
+ private _parseCache;
72
+ private _resultsView;
64
73
  private _contextRevision;
65
74
  constructor(modelId: string, options: KosExpressionEvaluatorOptions, context: KosCreationContext);
66
75
  /**
@@ -71,7 +80,8 @@ export declare class KosExpressionEvaluatorModelImpl<T extends string = string>
71
80
  get data(): Record<string, unknown>;
72
81
  get contextRevision(): number;
73
82
  /**
74
- * Replace the context data. Every expression re-evaluates against it.
83
+ * Replace the context data. An expression re-evaluates only if a value it
84
+ * read changed.
75
85
  *
76
86
  * @param newData - Complete new context data to replace existing data
77
87
  */
@@ -100,35 +110,60 @@ export declare class KosExpressionEvaluatorModelImpl<T extends string = string>
100
110
  */
101
111
  addModelToContext(key: string, model: unknown): void;
102
112
  /**
103
- * Add a named expression and evaluate it once.
113
+ * Add a named expression. It evaluates on first read. Adding a name that
114
+ * exists replaces that expression.
104
115
  *
105
116
  * @param name - Unique identifier for this expression
106
117
  * @param expressionString - Expression in `expr-eval` syntax
107
118
  * @throws {Error} If the expression has invalid syntax
108
119
  */
109
120
  addExpression(name: T, expressionString: string): void;
121
+ /**
122
+ * Remove a named expression and release the context values it tracks.
123
+ *
124
+ * @param name - The expression name
125
+ * @returns Whether an expression was removed
126
+ */
110
127
  removeExpression(name: T): boolean;
111
128
  getExpression(name: T): NamedExpression | undefined;
112
129
  getExpressionValue(name: T): ExpressionResult | undefined;
113
130
  /**
114
- * The last cached result of an expression, read without re-evaluating. Use it
115
- * in effects that should not depend on the expression's inputs.
131
+ * The result of an expression without a warning when it does not exist. It
132
+ * re-evaluates only if a context value it read changed since the last
133
+ * evaluation, and a reader tracks the result, not the expression's inputs.
116
134
  *
117
- * @param name - The expression name to get the cached result for
118
- * @returns The last cached result, or undefined if expression doesn't exist
135
+ * @param name - The expression name to get the result for
136
+ * @returns The result, or undefined if expression doesn't exist
119
137
  */
120
138
  getCachedExpressionValue(name: T): ExpressionResult | undefined;
121
139
  get expressions(): NamedExpression[];
122
140
  get expressionNames(): T[];
141
+ /**
142
+ * Every expression's result by name. Reading `results[name]` evaluates only
143
+ * that expression, and only if a context value it read changed.
144
+ */
123
145
  get results(): Record<T, ExpressionResult>;
124
- /** Re-evaluate every expression and update the cached results. */
125
- private evaluateAllExpressions;
126
146
  /**
127
- * Evaluate a specific expression and update the cached result if it changed.
147
+ * Parse an expression, or return the cached parse of the same string, to
148
+ * evaluate against any context object.
149
+ *
150
+ * @param expressionString - Expression in `expr-eval` syntax
151
+ * @returns The parsed expression
152
+ * @throws {Error} If the expression has invalid syntax
153
+ */
154
+ parseExpression(expressionString: string): ParsedExpression;
155
+ /**
156
+ * Evaluate an expression against the context data with `localContext`
157
+ * layered over it, without copying either. A key in `localContext` wins over
158
+ * the same context key. Called from a reactive render, the reader tracks only
159
+ * the values the expression read.
160
+ *
161
+ * @param expressionString - Expression in `expr-eval` syntax
162
+ * @param localContext - Values that apply to this evaluation only, such as a row's item
163
+ * @returns The result; a syntax or evaluation failure is returned as `error`
128
164
  */
129
- private evaluateExpression;
130
- /** Store a changed result in the reactive results object. */
131
- private updateResult;
165
+ evaluateWithLocalContext(expressionString: string, localContext?: Record<string, unknown>): ExpressionResult;
166
+ private createResultsView;
132
167
  /**
133
168
  * Add an expression under a generated id and return the id, for use with
134
169
  * `getExpressionValue(id)` or `results[id]`.
@@ -1 +1 @@
1
- {"version":3,"file":"kos-expression-evaluator-model.d.ts","sourceRoot":"","sources":["../../../../../../packages/kos-ui-sdk/src/models/models/kos-expression-evaluator/kos-expression-evaluator-model.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,wBAAwB,EAC9B,MAAM,eAAe,CAAC;AAEvB,OAAO,KAAK,EACV,aAAa,EAEb,kBAAkB,EACnB,MAAM,6BAA6B,CAAC;AACrC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAGhE,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,SAAS,CAAC;AAE7D,eAAO,MAAM,UAAU,mCAAmC,CAAC;AAE3D;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,8EAA8E;IAC9E,KAAK,EAAE,OAAO,CAAC;IACf,6EAA6E;IAC7E,KAAK,CAAC,EAA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;;;;;OAKG;IACH,kBAAkB,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI;IAIrD;;;;;;OAMG;IACH,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI;IAyBrD;;;;;;OAMG;IACH,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI;IAIpD;;;;;;OAMG;IACH,aAAa,CAAC,IAAI,EAAE,CAAC,EAAE,gBAAgB,EAAE,MAAM,GAAG,IAAI;IAwBtD,gBAAgB,CAAC,IAAI,EAAE,CAAC,GAAG,OAAO;IAelC,aAAa,CAAC,IAAI,EAAE,CAAC,GAAG,eAAe,GAAG,SAAS;IAYnD,kBAAkB,CAAC,IAAI,EAAE,CAAC,GAAG,gBAAgB,GAAG,SAAS;IAazD;;;;;;OAMG;IACH,wBAAwB,CAAC,IAAI,EAAE,CAAC,GAAG,gBAAgB,GAAG,SAAS;IAU/D,IAAI,WAAW,IAAI,eAAe,EAAE,CAEnC;IAED,IAAI,eAAe,IAAI,CAAC,EAAE,CAEzB;IAGD,IAAI,OAAO,IAAI,MAAM,CAAC,CAAC,EAAE,gBAAgB,CAAC,CAIzC;IAED,kEAAkE;IAClE,OAAO,CAAC,sBAAsB;IAW9B;;OAEG;IACH,OAAO,CAAC,kBAAkB;IA6B1B,6DAA6D;IAC7D,OAAO,CAAC,YAAY;IAUpB;;;;;;OAMG;IACH,gBAAgB,CAAC,gBAAgB,EAAE,MAAM,GAAG,MAAM;CAUnD"}
1
+ {"version":3,"file":"kos-expression-evaluator-model.d.ts","sourceRoot":"","sources":["../../../../../../packages/kos-ui-sdk/src/models/models/kos-expression-evaluator/kos-expression-evaluator-model.ts"],"names":[],"mappings":"AACA,OAAO,EAOL,KAAK,wBAAwB,EAC9B,MAAM,eAAe,CAAC;AAEvB,OAAO,KAAK,EACV,aAAa,EAEb,kBAAkB,EACnB,MAAM,6BA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AE,gBAAgB,CAAC,CAEzC;IAED;;;;;;;OAOG;IACH,eAAe,CAAC,gBAAgB,EAAE,MAAM,GAAG,gBAAgB;IAI3D;;;;;;;;;OASG;IACH,wBAAwB,CACtB,gBAAgB,EAAE,MAAM,EACxB,YAAY,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GACzC,gBAAgB;IAanB,OAAO,CAAC,iBAAiB;IA2BzB;;;;;;OAMG;IACH,gBAAgB,CAAC,gBAAgB,EAAE,MAAM,GAAG,MAAM;CAUnD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kosdev-code/kos-ui-sdk",
3
- "version": "0.1.0-next.958",
3
+ "version": "0.1.0-next.966",
4
4
  "type": "module",
5
5
  "main": "./index.cjs",
6
6
  "module": "./index.js",
@@ -50,7 +50,7 @@
50
50
  "react-router-dom": "^6.11.2"
51
51
  },
52
52
  "dependencies": {
53
- "@kosdev-code/kos-api-levels": "0.1.0-next.958",
53
+ "@kosdev-code/kos-api-levels": "0.1.0-next.966",
54
54
  "mobx": "^6.9.0",
55
55
  "mobx-react-lite": "^3.4.3",
56
56
  "date-fns": "^2.30.0",
@@ -59,7 +59,7 @@
59
59
  },
60
60
  "kos": {
61
61
  "build": {
62
- "gitHash": "f7c67338e9fa6f1034080da50a2a6a78626f83cd"
62
+ "gitHash": "60210ce6f362699102303542ab936c8dbc284d74"
63
63
  }
64
64
  }
65
65
  }
@@ -3600,7 +3600,7 @@ function createOnceHandler(originalHandler) {
3600
3600
  }
3601
3601
  const isPrintable = (model) => typeof model.toJSON === "function";
3602
3602
  const isKosDataModel = (model) => model[DependencyModels] !== void 0;
3603
- 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;
3604
3604
  const resolveChild = (attribute) => {
3605
3605
  if (!attribute) return void 0;
3606
3606
  if (isKosDataModel(attribute)) return attribute;
@@ -17961,6 +17961,56 @@ Parser.prototype.isOperatorEnabled = function(op) {
17961
17961
  var operators = this.options.operators || {};
17962
17962
  return !(optionName in operators) || !!operators[optionName];
17963
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
+ });
17964
18014
  var __defProp$i = Object.defineProperty;
17965
18015
  var __getOwnPropDesc$m = Object.getOwnPropertyDescriptor;
17966
18016
  var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$i(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
@@ -17973,60 +18023,67 @@ var __decorateClass$m = (decorators, target, key, kind) => {
17973
18023
  };
17974
18024
  var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, key + "", value);
17975
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
+ };
17976
18031
  class ReactiveExpression {
17977
18032
  name;
17978
18033
  expression;
17979
- expr;
17980
- getContextData = null;
17981
- // Cache the last result to allow comparison without re-evaluation
17982
- _lastResult = { value: void 0 };
17983
- constructor(name, expression, expr, getContextData) {
18034
+ parsed;
18035
+ disposed;
18036
+ computedResult;
18037
+ constructor(name, parsed, getContextData) {
17984
18038
  this.name = name;
17985
- this.expression = expression;
17986
- this.expr = expr;
17987
- this.getContextData = getContextData;
17988
- 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
+ );
17989
18046
  }
17990
- /** The cached result, returned without evaluating. */
18047
+ /** The current result, evaluated only if a context value it read changed since the last evaluation. */
17991
18048
  get result() {
17992
- return this._lastResult;
18049
+ return this.computedResult.get();
17993
18050
  }
17994
18051
  /**
17995
- * 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.
17996
18053
  */
17997
- updateResult(result) {
17998
- this._lastResult = result;
18054
+ updateResult(_result) {
18055
+ return;
17999
18056
  }
18000
18057
  /**
18001
- * 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.
18002
18059
  */
18003
18060
  evaluate(contextData) {
18004
- try {
18005
- const value = this.expr.evaluate(contextData);
18006
- return { value, error: void 0 };
18007
- } catch (error) {
18008
- return {
18009
- value: void 0,
18010
- error: error instanceof Error ? error.message : String(error)
18011
- };
18012
- }
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();
18013
18067
  }
18014
18068
  }
18069
+ class ExpressionResultsView {
18070
+ }
18015
18071
  let KosExpressionEvaluatorModelImpl = class {
18016
18072
  id;
18017
18073
  logger;
18018
18074
  parser;
18019
18075
  _data;
18020
18076
  _expressions = /* @__PURE__ */ new Map();
18021
- // Use ObservableData for results to handle dynamic properties properly
18022
- _results;
18077
+ _parseCache;
18078
+ _resultsView;
18023
18079
  _contextRevision = 0;
18024
18080
  constructor(modelId, options, context) {
18025
18081
  this.id = modelId;
18026
18082
  this.logger = context.logger;
18027
18083
  this._data = ObservableData();
18028
- this._results = ObservableData();
18029
18084
  this.parser = new Parser();
18085
+ this._parseCache = new ExpressionParseCache(this.parser);
18086
+ this._resultsView = this.createResultsView();
18030
18087
  this.parser.functions.exists = (value) => value !== void 0 && value !== null;
18031
18088
  this.parser.functions.isEmpty = (value) => {
18032
18089
  if (value === void 0 || value === null) return true;
@@ -18057,7 +18114,8 @@ let KosExpressionEvaluatorModelImpl = class {
18057
18114
  return this._contextRevision;
18058
18115
  }
18059
18116
  /**
18060
- * 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.
18061
18119
  *
18062
18120
  * @param newData - Complete new context data to replace existing data
18063
18121
  */
@@ -18115,7 +18173,8 @@ let KosExpressionEvaluatorModelImpl = class {
18115
18173
  this._data[key] = model;
18116
18174
  }
18117
18175
  /**
18118
- * 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.
18119
18178
  *
18120
18179
  * @param name - Unique identifier for this expression
18121
18180
  * @param expressionString - Expression in `expr-eval` syntax
@@ -18123,25 +18182,31 @@ let KosExpressionEvaluatorModelImpl = class {
18123
18182
  */
18124
18183
  addExpression(name, expressionString) {
18125
18184
  try {
18126
- const expr = this.parser.parse(expressionString);
18185
+ const parsed = this._parseCache.parse(expressionString);
18127
18186
  const reactiveExpression = new ReactiveExpression(
18128
18187
  name,
18129
- expressionString,
18130
- expr,
18131
- () => this.data
18188
+ parsed,
18189
+ () => this._data
18132
18190
  );
18191
+ this._expressions.get(name)?.dispose();
18133
18192
  this._expressions.set(name, reactiveExpression);
18134
- this.evaluateExpression(name);
18135
18193
  this.logger.debug(`Added expression "${name}": ${expressionString}`);
18136
18194
  } catch (error) {
18137
18195
  this.logger.error(`Failed to parse expression "${name}"`, error);
18138
18196
  throw error;
18139
18197
  }
18140
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
+ */
18141
18205
  removeExpression(name) {
18206
+ const expression = this._expressions.get(name);
18142
18207
  const removed = this._expressions.delete(name);
18143
18208
  if (removed) {
18144
- delete this._results[name];
18209
+ expression?.dispose();
18145
18210
  this.logger.debug(`Removed expression "${name}"`);
18146
18211
  } else {
18147
18212
  this.logger.warn(
@@ -18176,11 +18241,12 @@ let KosExpressionEvaluatorModelImpl = class {
18176
18241
  return expression.result;
18177
18242
  }
18178
18243
  /**
18179
- * The last cached result of an expression, read without re-evaluating. Use it
18180
- * 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.
18181
18247
  *
18182
- * @param name - The expression name to get the cached result for
18183
- * @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
18184
18250
  */
18185
18251
  getCachedExpressionValue(name) {
18186
18252
  const expression = this._expressions.get(name);
@@ -18195,53 +18261,64 @@ let KosExpressionEvaluatorModelImpl = class {
18195
18261
  get expressionNames() {
18196
18262
  return Array.from(this._expressions.keys());
18197
18263
  }
18198
- // 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
+ */
18199
18268
  get results() {
18200
- this.evaluateAllExpressions();
18201
- return this._results;
18269
+ return this._resultsView;
18202
18270
  }
18203
- /** Re-evaluate every expression and update the cached results. */
18204
- evaluateAllExpressions() {
18205
- const keys = Array.from(this._expressions.keys());
18206
- keys.forEach((key) => {
18207
- const expression = this._expressions.get(key);
18208
- if (expression) {
18209
- this.evaluateExpression(key);
18210
- }
18211
- });
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);
18212
18281
  }
18213
18282
  /**
18214
- * 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`
18215
18291
  */
18216
- evaluateExpression(name) {
18217
- this.logger.debug(`Evaluating expression: ${String(name)}`);
18218
- const expression = this._expressions.get(name);
18219
- if (!expression) {
18220
- this.logger.warn(`Expression "${String(name)}" not found`);
18221
- return;
18222
- }
18223
- const newResult = expression.evaluate(this.data);
18224
- this.logger.debug(`Expression "${String(name)}" evaluated to:`, newResult);
18225
- const currentResult = expression.result;
18226
- if (newResult.value !== currentResult.value || newResult.error !== currentResult.error) {
18227
- this.logger.debug(
18228
- `Expression "${String(name)}" result changed from`,
18229
- currentResult,
18230
- "to",
18231
- newResult
18232
- );
18233
- expression.updateResult(newResult);
18234
- 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
+ };
18235
18301
  }
18302
+ return parsed.evaluate(layerContext(this._data, localContext));
18236
18303
  }
18237
- /** Store a changed result in the reactive results object. */
18238
- updateResult(name, result) {
18239
- this.logger.debug(
18240
- `ExpressionEvaluator.updateResult called for "${name}":`,
18241
- result
18242
- );
18243
- kosAction(() => {
18244
- 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
+ }
18245
18322
  });
18246
18323
  }
18247
18324
  /**
@@ -24668,4 +24745,4 @@ exports.waitForAppToStart = waitForAppToStart;
24668
24745
  exports.waitForAppsToStart = waitForAppsToStart;
24669
24746
  exports.whenReady = whenReady;
24670
24747
  exports.wrapWithFutureLifecycle = wrapWithFutureLifecycle;
24671
- //# sourceMappingURL=software-info-registration-Y1iADHWT.cjs.map
24748
+ //# sourceMappingURL=software-info-registration-BAk6JWkz.cjs.map