@yuneta/gobj-ui 7.23.46 → 7.23.47

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/README.md CHANGED
@@ -1388,7 +1388,7 @@ backend** — asking is an action and belongs in the view's own FSM:
1388
1388
 
1389
1389
  | | |
1390
1390
  |---|---|
1391
- | `yui_asset_id(ref)` / `yui_asset_ids(ref)` | the id(s) a column names. Reads a single-valued fkey (`"assets^<id>^as_foto"`), an array fkey, and an expanded ref (`{id}`). An empty column answers nothing rather than throwing |
1391
+ | `yui_asset_id(ref)` / `yui_asset_ids(ref)` | the id(s) a column names. A link comes back in whichever shape the READER asked for — the stored `"assets^<id>^as_foto"`, the bare `"<id>"` that `fkey_only_id` collapses it to, or an expanded `{id}` — and either alone or in a list, because an unset single-valued fkey is still an empty list. All of them are read; an empty column answers nothing rather than throwing |
1392
1392
  | `yui_asset_src(answer)` | the two shapes into one `src`. `null` when the answer carries neither — never an empty string, because `<img src="">` reloads the page in some browsers |
1393
1393
  | `yui_asset_element(answer, opts)` | the element, picked from the **content type the backend stored**: `<img>`, `<video>` or `<audio>`. Video and audio are assets too, and an `<img>` whose src is a film shows the broken box this exists to remove |
1394
1394
  | `yui_asset_missing(detail, opts)` | the marker, for when there is nothing to show |
@@ -67047,8 +67047,9 @@ function register_c_yui_period() {
67047
67047
  function ref_to_id(ref) {
67048
67048
  if (!ref) return null;
67049
67049
  if (typeof ref === "string") {
67050
+ if (ref.indexOf("^") < 0) return ref;
67050
67051
  const parts = ref.split("^");
67051
- return parts.length >= 2 ? parts[1] : null;
67052
+ return parts.length >= 2 && parts[1] ? parts[1] : null;
67052
67053
  }
67053
67054
  if (typeof ref === "object" && typeof ref.id === "string") return ref.id;
67054
67055
  return null;
@@ -67042,8 +67042,9 @@ function register_c_yui_period() {
67042
67042
  function ref_to_id(ref) {
67043
67043
  if (!ref) return null;
67044
67044
  if (typeof ref === "string") {
67045
+ if (ref.indexOf("^") < 0) return ref;
67045
67046
  const parts = ref.split("^");
67046
- return parts.length >= 2 ? parts[1] : null;
67047
+ return parts.length >= 2 && parts[1] ? parts[1] : null;
67047
67048
  }
67048
67049
  if (typeof ref === "object" && typeof ref.id === "string") return ref.id;
67049
67050
  return null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yuneta/gobj-ui",
3
- "version": "7.23.46",
3
+ "version": "7.23.47",
4
4
  "type": "module",
5
5
  "main": "dist/gobj-ui.cjs.js",
6
6
  "module": "dist/gobj-ui.es.js",
package/src/yui_asset.js CHANGED
@@ -22,10 +22,22 @@ import {
22
22
  import "./yui_asset.css";
23
23
 
24
24
  /*
25
- * A treedb fkey is `topic^id^hook`, and a column holds either one of them
26
- * (a single-valued fkey, like a device's photo) or a list (an array fkey,
27
- * like the plans of a bay). An expanded ref -- what `refs` options give
28
- * back -- is an object carrying the id instead.
25
+ * A column that holds a link comes back in one of THREE shapes, and which
26
+ * one is the READER's choice, not the schema's:
27
+ *
28
+ * "assets^<id>^as_foto" the stored fkey, as it is persisted;
29
+ * "<id>" what `fkey_only_id` collapses it to, which is
30
+ * what a caller asks for when it wants clean ids;
31
+ * {id: "<id>", ...} an expanded ref, from the `refs` options.
32
+ *
33
+ * And a column holds either ONE of them (a single-valued fkey, like a
34
+ * device's photo) or a LIST (an array fkey, like the plans of a bay) --
35
+ * and an UNSET single-valued fkey still comes back as an empty list.
36
+ *
37
+ * Reading only the first shape was a real bug: against a backend that
38
+ * reads with `fkey_only_id` every link looked like no link at all. The
39
+ * `^` is what tells the two string shapes apart, and an id can never carry
40
+ * one -- that is why the qualified key uses `.` and not `^`.
29
41
  */
30
42
  function ref_to_id(ref)
31
43
  {
@@ -33,8 +45,11 @@ function ref_to_id(ref)
33
45
  return null;
34
46
  }
35
47
  if(typeof ref === "string") {
48
+ if(ref.indexOf("^") < 0) {
49
+ return ref; // already only the id
50
+ }
36
51
  const parts = ref.split("^");
37
- return parts.length >= 2? parts[1]: null;
52
+ return parts.length >= 2 && parts[1]? parts[1]: null;
38
53
  }
39
54
  if(typeof ref === "object" && typeof ref.id === "string") {
40
55
  return ref.id;
@@ -27,6 +27,26 @@ test("reads every id out of an array fkey, in order", () => {
27
27
  expect(yui_asset_id(["assets^p1^as_plano", "assets^p2^as_plano"])).toBe("p1");
28
28
  });
29
29
 
30
+ /*
31
+ * `fkey_only_id` is a normal way to read a node -- yunovatios reads every
32
+ * device that way -- and it collapses a link to the bare id. Reading only
33
+ * the `topic^id^hook` form made every such link look like no link at all.
34
+ */
35
+ test("reads a link collapsed by fkey_only_id, list or bare", () => {
36
+ expect(yui_asset_id(["7b09b140"])).toBe("7b09b140");
37
+ expect(yui_asset_id("7b09b140")).toBe("7b09b140");
38
+ expect(yui_asset_ids(["p1", "p2"])).toEqual(["p1", "p2"]);
39
+ });
40
+
41
+ /*
42
+ * An UNSET single-valued fkey comes back as an EMPTY LIST, not as an empty
43
+ * string: that is the shape of "this device has no photo".
44
+ */
45
+ test("an unset single-valued fkey is an empty list", () => {
46
+ expect(yui_asset_id([])).toBe(null);
47
+ expect(yui_asset_ids([])).toEqual([]);
48
+ });
49
+
30
50
  test("reads an EXPANDED ref, which is what the refs options give back", () => {
31
51
  expect(yui_asset_id({id: "abc123", content_type: "image/jpeg"})).toBe("abc123");
32
52
  });
@@ -41,9 +61,8 @@ test("an empty or malformed column yields nothing, and does not throw", () => {
41
61
  expect(yui_asset_ids("")).toEqual([]);
42
62
  expect(yui_asset_ids([])).toEqual([]);
43
63
  expect(yui_asset_id(null)).toBe(null);
44
- expect(yui_asset_id("not-an-fkey")).toBe(null);
45
64
  expect(yui_asset_id({})).toBe(null);
46
- expect(yui_asset_ids(["assets^ok^as_foto", "rubbish", null])).toEqual(["ok"]);
65
+ expect(yui_asset_ids(["assets^ok^as_foto", null, ""])).toEqual(["ok"]);
47
66
  });
48
67
 
49
68
  /*