@jxsuite/runtime 4.1.0 → 5.1.0

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.
package/src/pointer.ts CHANGED
@@ -16,6 +16,8 @@
16
16
  * @docs framework/concepts/references
17
17
  */
18
18
 
19
+ import type { JxScope, JxScopeValue } from "./types.ts";
20
+
19
21
  /** `~1` is `/` and `~0` is `~`; RFC 6901 §4 fixes this order so `~01` becomes `~1`, not `/`. */
20
22
  export function unescapeToken(token: string): string {
21
23
  return token.replaceAll("~1", "/").replaceAll("~0", "~");
@@ -45,14 +47,18 @@ export function refSegments(path: string): string[] {
45
47
  /**
46
48
  * Walk a value along a `$ref` path, or `undefined` where the path leaves the object.
47
49
  *
48
- * @param {unknown} root
50
+ * @param {JxScopeValue} root - A scope, or any member read from one
49
51
  * @param {string} path
50
- * @returns {unknown}
52
+ * @returns {JxScopeValue}
51
53
  */
52
- export function readPath(root: unknown, path: string): unknown {
54
+ export function readPath(root: JxScopeValue, path: string): JxScopeValue {
53
55
  let current = root;
54
56
  for (const key of refSegments(path)) {
55
- current = (current as Record<string, unknown> | null | undefined)?.[key];
57
+ /* SAFETY: `?.` stops at null and undefined, and every other JavaScript value, primitives
58
+ included, answers a member read by name (a string's `length`, an array's index). Reading by
59
+ name is how the runtime sees any object, as the `JxScope` record of its members, so the
60
+ member it answers is one more scope member. */
61
+ current = (current as JxScope | null | undefined)?.[key];
56
62
  }
57
63
  return current;
58
64
  }