@platforma-sdk/model 1.53.11 → 1.53.13

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 (288) hide show
  1. package/dist/annotations/converter.cjs +11 -11
  2. package/dist/annotations/converter.cjs.map +1 -1
  3. package/dist/annotations/converter.d.ts +1 -1
  4. package/dist/annotations/converter.d.ts.map +1 -1
  5. package/dist/annotations/converter.js +11 -11
  6. package/dist/annotations/converter.js.map +1 -1
  7. package/dist/annotations/index.d.ts +2 -2
  8. package/dist/annotations/types.d.ts +4 -4
  9. package/dist/bconfig/index.d.ts +5 -5
  10. package/dist/bconfig/lambdas.d.ts +7 -7
  11. package/dist/bconfig/lambdas.d.ts.map +1 -1
  12. package/dist/bconfig/normalization.cjs.map +1 -1
  13. package/dist/bconfig/normalization.d.ts +3 -3
  14. package/dist/bconfig/normalization.js.map +1 -1
  15. package/dist/bconfig/types.cjs.map +1 -1
  16. package/dist/bconfig/types.d.ts +2 -2
  17. package/dist/bconfig/types.d.ts.map +1 -1
  18. package/dist/bconfig/types.js.map +1 -1
  19. package/dist/bconfig/util.d.ts +4 -4
  20. package/dist/bconfig/v3.d.ts +3 -3
  21. package/dist/block_api_v1.d.ts +2 -2
  22. package/dist/block_api_v1.d.ts.map +1 -1
  23. package/dist/block_api_v2.d.ts +2 -2
  24. package/dist/block_api_v2.d.ts.map +1 -1
  25. package/dist/block_api_v3.d.ts +3 -3
  26. package/dist/block_migrations.cjs +10 -10
  27. package/dist/block_migrations.cjs.map +1 -1
  28. package/dist/block_migrations.d.ts.map +1 -1
  29. package/dist/block_migrations.js +10 -10
  30. package/dist/block_migrations.js.map +1 -1
  31. package/dist/block_model.cjs +11 -11
  32. package/dist/block_model.cjs.map +1 -1
  33. package/dist/block_model.d.ts +8 -8
  34. package/dist/block_model.d.ts.map +1 -1
  35. package/dist/block_model.js +11 -11
  36. package/dist/block_model.js.map +1 -1
  37. package/dist/block_state_patch.d.ts +2 -2
  38. package/dist/block_state_util.cjs +1 -1
  39. package/dist/block_state_util.cjs.map +1 -1
  40. package/dist/block_state_util.d.ts +3 -3
  41. package/dist/block_state_util.js +1 -1
  42. package/dist/block_state_util.js.map +1 -1
  43. package/dist/block_storage.cjs +10 -10
  44. package/dist/block_storage.cjs.map +1 -1
  45. package/dist/block_storage.d.ts +2 -2
  46. package/dist/block_storage.d.ts.map +1 -1
  47. package/dist/block_storage.js +10 -10
  48. package/dist/block_storage.js.map +1 -1
  49. package/dist/block_storage_vm.cjs +22 -22
  50. package/dist/block_storage_vm.cjs.map +1 -1
  51. package/dist/block_storage_vm.d.ts +1 -1
  52. package/dist/block_storage_vm.d.ts.map +1 -1
  53. package/dist/block_storage_vm.js +22 -22
  54. package/dist/block_storage_vm.js.map +1 -1
  55. package/dist/builder.cjs +32 -23
  56. package/dist/builder.cjs.map +1 -1
  57. package/dist/builder.d.ts +7 -7
  58. package/dist/builder.d.ts.map +1 -1
  59. package/dist/builder.js +32 -23
  60. package/dist/builder.js.map +1 -1
  61. package/dist/components/PFrameForGraphs.cjs +7 -6
  62. package/dist/components/PFrameForGraphs.cjs.map +1 -1
  63. package/dist/components/PFrameForGraphs.d.ts +4 -4
  64. package/dist/components/PFrameForGraphs.d.ts.map +1 -1
  65. package/dist/components/PFrameForGraphs.js +7 -6
  66. package/dist/components/PFrameForGraphs.js.map +1 -1
  67. package/dist/components/PlAnnotations/filter.d.ts +14 -14
  68. package/dist/components/PlAnnotations/filter.d.ts.map +1 -1
  69. package/dist/components/PlAnnotations/filters_ui.cjs +46 -46
  70. package/dist/components/PlAnnotations/filters_ui.cjs.map +1 -1
  71. package/dist/components/PlAnnotations/filters_ui.d.ts +10 -34
  72. package/dist/components/PlAnnotations/filters_ui.d.ts.map +1 -1
  73. package/dist/components/PlAnnotations/filters_ui.js +46 -46
  74. package/dist/components/PlAnnotations/filters_ui.js.map +1 -1
  75. package/dist/components/PlAnnotations/index.d.ts +2 -2
  76. package/dist/components/PlAnnotations/types.d.ts +2 -2
  77. package/dist/components/PlDataTable.cjs +19 -20
  78. package/dist/components/PlDataTable.cjs.map +1 -1
  79. package/dist/components/PlDataTable.d.ts +27 -27
  80. package/dist/components/PlDataTable.d.ts.map +1 -1
  81. package/dist/components/PlDataTable.js +19 -20
  82. package/dist/components/PlDataTable.js.map +1 -1
  83. package/dist/components/PlMultiSequenceAlignment.cjs +2 -2
  84. package/dist/components/PlMultiSequenceAlignment.cjs.map +1 -1
  85. package/dist/components/PlMultiSequenceAlignment.d.ts +6 -6
  86. package/dist/components/PlMultiSequenceAlignment.d.ts.map +1 -1
  87. package/dist/components/PlMultiSequenceAlignment.js +2 -2
  88. package/dist/components/PlMultiSequenceAlignment.js.map +1 -1
  89. package/dist/components/PlSelectionModel.cjs.map +1 -1
  90. package/dist/components/PlSelectionModel.d.ts +1 -1
  91. package/dist/components/PlSelectionModel.js.map +1 -1
  92. package/dist/components/index.d.ts +5 -5
  93. package/dist/config/actions.cjs +39 -39
  94. package/dist/config/actions.cjs.map +1 -1
  95. package/dist/config/actions.d.ts +9 -9
  96. package/dist/config/actions.d.ts.map +1 -1
  97. package/dist/config/actions.js +39 -39
  98. package/dist/config/actions.js.map +1 -1
  99. package/dist/config/actions_kinds.d.ts +30 -30
  100. package/dist/config/actions_kinds.d.ts.map +1 -1
  101. package/dist/config/index.d.ts +6 -6
  102. package/dist/config/model.d.ts +28 -28
  103. package/dist/config/model_meta.d.ts +1 -1
  104. package/dist/config/type_engine.d.ts +3 -3
  105. package/dist/config/type_util.d.ts +2 -2
  106. package/dist/env_value.cjs +1 -1
  107. package/dist/env_value.cjs.map +1 -1
  108. package/dist/env_value.js +1 -1
  109. package/dist/env_value.js.map +1 -1
  110. package/dist/filters/converter.cjs +36 -32
  111. package/dist/filters/converter.cjs.map +1 -1
  112. package/dist/filters/converter.d.ts +2 -2
  113. package/dist/filters/converter.d.ts.map +1 -1
  114. package/dist/filters/converter.js +36 -32
  115. package/dist/filters/converter.js.map +1 -1
  116. package/dist/filters/index.d.ts +2 -2
  117. package/dist/filters/types.d.ts +33 -33
  118. package/dist/filters/types.d.ts.map +1 -1
  119. package/dist/index.d.ts +24 -24
  120. package/dist/internal.cjs +7 -7
  121. package/dist/internal.cjs.map +1 -1
  122. package/dist/internal.d.ts +4 -4
  123. package/dist/internal.d.ts.map +1 -1
  124. package/dist/internal.js +7 -7
  125. package/dist/internal.js.map +1 -1
  126. package/dist/package.json.cjs +1 -1
  127. package/dist/package.json.js +1 -1
  128. package/dist/pframe.cjs +1 -1
  129. package/dist/pframe.cjs.map +1 -1
  130. package/dist/pframe.d.ts +1 -1
  131. package/dist/pframe.js +1 -1
  132. package/dist/pframe.js.map +1 -1
  133. package/dist/pframe_utils/columns.cjs +23 -15
  134. package/dist/pframe_utils/columns.cjs.map +1 -1
  135. package/dist/pframe_utils/columns.d.ts +3 -3
  136. package/dist/pframe_utils/columns.d.ts.map +1 -1
  137. package/dist/pframe_utils/columns.js +23 -15
  138. package/dist/pframe_utils/columns.js.map +1 -1
  139. package/dist/pframe_utils/index.cjs +25 -25
  140. package/dist/pframe_utils/index.cjs.map +1 -1
  141. package/dist/pframe_utils/index.d.ts +3 -3
  142. package/dist/pframe_utils/index.d.ts.map +1 -1
  143. package/dist/pframe_utils/index.js +25 -25
  144. package/dist/pframe_utils/index.js.map +1 -1
  145. package/dist/platforma.d.ts +7 -7
  146. package/dist/platforma.d.ts.map +1 -1
  147. package/dist/raw_globals.cjs +4 -1
  148. package/dist/raw_globals.cjs.map +1 -1
  149. package/dist/raw_globals.d.ts +2 -2
  150. package/dist/raw_globals.d.ts.map +1 -1
  151. package/dist/raw_globals.js +4 -1
  152. package/dist/raw_globals.js.map +1 -1
  153. package/dist/ref_util.cjs +4 -4
  154. package/dist/ref_util.cjs.map +1 -1
  155. package/dist/ref_util.d.ts +1 -1
  156. package/dist/ref_util.js +4 -4
  157. package/dist/ref_util.js.map +1 -1
  158. package/dist/render/accessor.cjs +24 -24
  159. package/dist/render/accessor.cjs.map +1 -1
  160. package/dist/render/accessor.d.ts +10 -10
  161. package/dist/render/accessor.d.ts.map +1 -1
  162. package/dist/render/accessor.js +24 -24
  163. package/dist/render/accessor.js.map +1 -1
  164. package/dist/render/api.cjs +23 -23
  165. package/dist/render/api.cjs.map +1 -1
  166. package/dist/render/api.d.ts +11 -11
  167. package/dist/render/api.d.ts.map +1 -1
  168. package/dist/render/api.js +23 -23
  169. package/dist/render/api.js.map +1 -1
  170. package/dist/render/future.cjs.map +1 -1
  171. package/dist/render/future.d.ts +1 -1
  172. package/dist/render/future.js.map +1 -1
  173. package/dist/render/index.d.ts +6 -6
  174. package/dist/render/internal.cjs +4 -4
  175. package/dist/render/internal.cjs.map +1 -1
  176. package/dist/render/internal.d.ts +7 -7
  177. package/dist/render/internal.d.ts.map +1 -1
  178. package/dist/render/internal.js +4 -4
  179. package/dist/render/internal.js.map +1 -1
  180. package/dist/render/traversal_ops.d.ts +1 -1
  181. package/dist/render/util/axis_filtering.cjs +48 -44
  182. package/dist/render/util/axis_filtering.cjs.map +1 -1
  183. package/dist/render/util/axis_filtering.d.ts +2 -2
  184. package/dist/render/util/axis_filtering.js +48 -44
  185. package/dist/render/util/axis_filtering.js.map +1 -1
  186. package/dist/render/util/column_collection.cjs +42 -35
  187. package/dist/render/util/column_collection.cjs.map +1 -1
  188. package/dist/render/util/column_collection.d.ts +4 -4
  189. package/dist/render/util/column_collection.d.ts.map +1 -1
  190. package/dist/render/util/column_collection.js +42 -35
  191. package/dist/render/util/column_collection.js.map +1 -1
  192. package/dist/render/util/index.d.ts +4 -4
  193. package/dist/render/util/label.cjs +15 -21
  194. package/dist/render/util/label.cjs.map +1 -1
  195. package/dist/render/util/label.d.ts +2 -2
  196. package/dist/render/util/label.d.ts.map +1 -1
  197. package/dist/render/util/label.js +15 -21
  198. package/dist/render/util/label.js.map +1 -1
  199. package/dist/render/util/pcolumn_data.cjs +56 -54
  200. package/dist/render/util/pcolumn_data.cjs.map +1 -1
  201. package/dist/render/util/pcolumn_data.d.ts +5 -5
  202. package/dist/render/util/pcolumn_data.d.ts.map +1 -1
  203. package/dist/render/util/pcolumn_data.js +56 -54
  204. package/dist/render/util/pcolumn_data.js.map +1 -1
  205. package/dist/render/util/pframe_upgraders.cjs +6 -6
  206. package/dist/render/util/pframe_upgraders.cjs.map +1 -1
  207. package/dist/render/util/pframe_upgraders.d.ts +1 -1
  208. package/dist/render/util/pframe_upgraders.d.ts.map +1 -1
  209. package/dist/render/util/pframe_upgraders.js +6 -6
  210. package/dist/render/util/pframe_upgraders.js.map +1 -1
  211. package/dist/render/util/split_selectors.d.ts +1 -1
  212. package/dist/render/util/split_selectors.d.ts.map +1 -1
  213. package/dist/sdk_info.cjs.map +1 -1
  214. package/dist/sdk_info.js.map +1 -1
  215. package/dist/version.cjs.map +1 -1
  216. package/dist/version.js.map +1 -1
  217. package/package.json +24 -22
  218. package/src/annotations/converter.test.ts +98 -101
  219. package/src/annotations/converter.ts +21 -17
  220. package/src/annotations/index.ts +2 -2
  221. package/src/annotations/types.ts +4 -4
  222. package/src/bconfig/index.ts +5 -5
  223. package/src/bconfig/lambdas.ts +10 -12
  224. package/src/bconfig/normalization.ts +5 -5
  225. package/src/bconfig/types.ts +3 -5
  226. package/src/bconfig/util.ts +3 -3
  227. package/src/bconfig/v3.ts +3 -3
  228. package/src/block_api_v1.ts +7 -3
  229. package/src/block_api_v2.ts +7 -3
  230. package/src/block_api_v3.ts +3 -3
  231. package/src/block_migrations.test.ts +66 -67
  232. package/src/block_migrations.ts +16 -16
  233. package/src/block_model.ts +76 -140
  234. package/src/block_state_patch.ts +2 -2
  235. package/src/block_state_util.ts +4 -4
  236. package/src/block_storage.test.ts +106 -99
  237. package/src/block_storage.ts +22 -25
  238. package/src/block_storage_vm.ts +41 -35
  239. package/src/builder.ts +107 -95
  240. package/src/components/PFrameForGraphs.test.ts +261 -255
  241. package/src/components/PFrameForGraphs.ts +35 -22
  242. package/src/components/PlAnnotations/filter.ts +21 -15
  243. package/src/components/PlAnnotations/filters_ui.test.ts +230 -73
  244. package/src/components/PlAnnotations/filters_ui.ts +138 -105
  245. package/src/components/PlAnnotations/index.ts +2 -2
  246. package/src/components/PlAnnotations/types.ts +2 -2
  247. package/src/components/PlDataTable.ts +177 -164
  248. package/src/components/PlMultiSequenceAlignment.ts +11 -18
  249. package/src/components/PlSelectionModel.ts +1 -1
  250. package/src/components/index.ts +5 -5
  251. package/src/config/actions.ts +64 -59
  252. package/src/config/actions_kinds.ts +38 -34
  253. package/src/config/index.ts +6 -6
  254. package/src/config/model.ts +28 -28
  255. package/src/config/model_meta.ts +1 -1
  256. package/src/config/type_engine.ts +3 -3
  257. package/src/config/type_util.ts +2 -2
  258. package/src/env_value.ts +2 -2
  259. package/src/filters/converter.test.ts +185 -144
  260. package/src/filters/converter.ts +47 -35
  261. package/src/filters/index.ts +2 -2
  262. package/src/filters/types.ts +44 -39
  263. package/src/global.d.ts +1 -1
  264. package/src/index.ts +24 -24
  265. package/src/internal.ts +27 -17
  266. package/src/pframe.ts +3 -3
  267. package/src/pframe_utils/columns.ts +81 -31
  268. package/src/pframe_utils/index.ts +65 -43
  269. package/src/platforma.ts +44 -21
  270. package/src/raw_globals.ts +13 -7
  271. package/src/ref_util.ts +6 -6
  272. package/src/render/accessor.ts +43 -44
  273. package/src/render/api.ts +102 -78
  274. package/src/render/future.ts +2 -2
  275. package/src/render/index.ts +6 -6
  276. package/src/render/internal.ts +11 -12
  277. package/src/render/traversal_ops.ts +1 -1
  278. package/src/render/util/axis_filtering.ts +67 -52
  279. package/src/render/util/column_collection.ts +171 -91
  280. package/src/render/util/index.ts +4 -4
  281. package/src/render/util/label.test.ts +139 -139
  282. package/src/render/util/label.ts +42 -33
  283. package/src/render/util/pcolumn_data.ts +111 -75
  284. package/src/render/util/pframe_upgraders.ts +24 -13
  285. package/src/render/util/split_selectors.ts +6 -1
  286. package/src/sdk_info.ts +1 -1
  287. package/src/typing.test.ts +56 -56
  288. package/src/version.ts +1 -1
@@ -1,279 +1,279 @@
1
- import { Annotation, PColumnSpec } from '@milaboratories/pl-model-common';
2
- import { expect, test } from 'vitest';
3
- import { deriveLabels, Trace } from './label';
1
+ import { Annotation, PColumnSpec } from "@milaboratories/pl-model-common";
2
+ import { expect, test } from "vitest";
3
+ import { deriveLabels, Trace } from "./label";
4
4
 
5
5
  function tracesToSpecs(traces: Trace[]) {
6
6
  return traces.map(
7
7
  (t) =>
8
8
  ({
9
- kind: 'PColumn',
10
- name: 'name',
11
- valueType: 'Int',
9
+ kind: "PColumn",
10
+ name: "name",
11
+ valueType: "Int",
12
12
  annotations: {
13
13
  [Annotation.Trace]: JSON.stringify(t),
14
- [Annotation.Label]: 'Label'
14
+ [Annotation.Label]: "Label",
15
15
  },
16
- axesSpec: []
17
- }) satisfies PColumnSpec
16
+ axesSpec: [],
17
+ }) satisfies PColumnSpec,
18
18
  );
19
19
  }
20
20
  test.each<{ name: string; traces: Trace[]; labels: string[] }>([
21
21
  {
22
- name: 'simple',
23
- traces: [[{ type: 't1', label: 'L1' }], [{ type: 't1', label: 'L2' }]],
24
- labels: ['L1', 'L2']
22
+ name: "simple",
23
+ traces: [[{ type: "t1", label: "L1" }], [{ type: "t1", label: "L2" }]],
24
+ labels: ["L1", "L2"],
25
25
  },
26
26
  {
27
- name: 'later wins',
27
+ name: "later wins",
28
28
  traces: [
29
29
  [
30
- { type: 't1', label: 'T1L1' },
31
- { type: 't2', label: 'T2L1' }
30
+ { type: "t1", label: "T1L1" },
31
+ { type: "t2", label: "T2L1" },
32
32
  ],
33
33
  [
34
- { type: 't1', label: 'T1L2' },
35
- { type: 't2', label: 'T2L2' }
36
- ]
34
+ { type: "t1", label: "T1L2" },
35
+ { type: "t2", label: "T2L2" },
36
+ ],
37
37
  ],
38
- labels: ['T2L1', 'T2L2']
38
+ labels: ["T2L1", "T2L2"],
39
39
  },
40
40
  {
41
- name: 'importance wins',
41
+ name: "importance wins",
42
42
  traces: [
43
43
  [
44
- { type: 't1', importance: 100, label: 'T1L1' },
45
- { type: 't2', label: 'T2L1' }
44
+ { type: "t1", importance: 100, label: "T1L1" },
45
+ { type: "t2", label: "T2L1" },
46
46
  ],
47
47
  [
48
- { type: 't1', importance: 100, label: 'T1L2' },
49
- { type: 't2', label: 'T2L2' }
50
- ]
48
+ { type: "t1", importance: 100, label: "T1L2" },
49
+ { type: "t2", label: "T2L2" },
50
+ ],
51
51
  ],
52
- labels: ['T1L1', 'T1L2']
52
+ labels: ["T1L1", "T1L2"],
53
53
  },
54
54
  {
55
- name: 'uniqueness wins',
55
+ name: "uniqueness wins",
56
56
  traces: [
57
57
  [
58
- { type: 't1', label: 'T1L1' },
59
- { type: 't2', label: 'T2L1' }
58
+ { type: "t1", label: "T1L1" },
59
+ { type: "t2", label: "T2L1" },
60
60
  ],
61
61
  [
62
- { type: 't1', label: 'T1L2' },
63
- { type: 't2', label: 'T2L1' }
64
- ]
62
+ { type: "t1", label: "T1L2" },
63
+ { type: "t2", label: "T2L1" },
64
+ ],
65
65
  ],
66
- labels: ['T1L1', 'T1L2']
66
+ labels: ["T1L1", "T1L2"],
67
67
  },
68
68
  {
69
- name: 'combinatoric solution',
69
+ name: "combinatoric solution",
70
70
  traces: [
71
71
  [
72
- { type: 't1', label: 'T1L1' },
73
- { type: 't2', label: 'T2L1' }
72
+ { type: "t1", label: "T1L1" },
73
+ { type: "t2", label: "T2L1" },
74
74
  ],
75
75
  [
76
- { type: 't1', label: 'T1L1' },
77
- { type: 't2', label: 'T2L2' }
76
+ { type: "t1", label: "T1L1" },
77
+ { type: "t2", label: "T2L2" },
78
78
  ],
79
79
  [
80
- { type: 't1', label: 'T1L2' },
81
- { type: 't2', label: 'T2L2' }
82
- ]
80
+ { type: "t1", label: "T1L2" },
81
+ { type: "t2", label: "T2L2" },
82
+ ],
83
83
  ],
84
- labels: ['T1L1 / T2L1', 'T1L1 / T2L2', 'T1L2 / T2L2']
84
+ labels: ["T1L1 / T2L1", "T1L1 / T2L2", "T1L2 / T2L2"],
85
85
  },
86
86
  {
87
- name: 'different importance and id',
87
+ name: "different importance and id",
88
88
  traces: [
89
- [{ type: 'sameType', importance: 10, id: 'id1', label: 'High importance' }],
90
- [{ type: 'sameType', importance: 5, id: 'id2', label: 'Low importance' }]
89
+ [{ type: "sameType", importance: 10, id: "id1", label: "High importance" }],
90
+ [{ type: "sameType", importance: 5, id: "id2", label: "Low importance" }],
91
91
  ],
92
- labels: ['High importance', 'Low importance']
92
+ labels: ["High importance", "Low importance"],
93
93
  },
94
94
  {
95
- name: 'mixed common and different entries',
95
+ name: "mixed common and different entries",
96
96
  traces: [
97
97
  [
98
- { type: 'commonType', importance: 1, id: 'common', label: 'Common entry' },
99
- { type: 'uniqueType', importance: 10, id: 'id1', label: 'Unique entry 1' }
98
+ { type: "commonType", importance: 1, id: "common", label: "Common entry" },
99
+ { type: "uniqueType", importance: 10, id: "id1", label: "Unique entry 1" },
100
100
  ],
101
101
  [
102
- { type: 'commonType', importance: 1, id: 'common', label: 'Common entry' },
103
- { type: 'uniqueType', importance: 5, id: 'id2', label: 'Unique entry 2' }
104
- ]
102
+ { type: "commonType", importance: 1, id: "common", label: "Common entry" },
103
+ { type: "uniqueType", importance: 5, id: "id2", label: "Unique entry 2" },
104
+ ],
105
105
  ],
106
- labels: ['Unique entry 1', 'Unique entry 2']
107
- }
108
- ])('test label derivation: $name', ({ name, traces, labels }) => {
106
+ labels: ["Unique entry 1", "Unique entry 2"],
107
+ },
108
+ ])("test label derivation: $name", ({ traces, labels }) => {
109
109
  expect(deriveLabels(tracesToSpecs(traces), (s) => s).map((r) => r.label)).toEqual(labels);
110
110
  expect(
111
- deriveLabels(tracesToSpecs(traces), (s) => s, { includeNativeLabel: true }).map((r) => r.label)
112
- ).toEqual(labels.map((l) => 'Label / ' + l));
111
+ deriveLabels(tracesToSpecs(traces), (s) => s, { includeNativeLabel: true }).map((r) => r.label),
112
+ ).toEqual(labels.map((l) => "Label / " + l));
113
113
  });
114
114
 
115
- test('test fallback to native labels in label derivation', () => {
115
+ test("test fallback to native labels in label derivation", () => {
116
116
  expect(deriveLabels(tracesToSpecs([[], []]), (s) => s).map((r) => r.label)).toEqual([
117
- 'Label',
118
- 'Label'
117
+ "Label",
118
+ "Label",
119
119
  ]);
120
120
  });
121
121
 
122
122
  test.each<{ name: string; traces: Trace[]; labels: string[] }>([
123
123
  {
124
- name: 'removes redundant low-importance type when high-importance alone suffices',
124
+ name: "removes redundant low-importance type when high-importance alone suffices",
125
125
  traces: [
126
126
  [
127
- { type: 't1', importance: 10, label: 'High1' },
128
- { type: 't2', importance: 1, label: 'Low1' }
127
+ { type: "t1", importance: 10, label: "High1" },
128
+ { type: "t2", importance: 1, label: "Low1" },
129
129
  ],
130
130
  [
131
- { type: 't1', importance: 10, label: 'High2' },
132
- { type: 't2', importance: 1, label: 'Low2' }
133
- ]
131
+ { type: "t1", importance: 10, label: "High2" },
132
+ { type: "t2", importance: 1, label: "Low2" },
133
+ ],
134
134
  ],
135
135
  // Both t1 and t2 distinguish, but t2 (low importance) should be removed since t1 alone suffices
136
- labels: ['High1', 'High2']
136
+ labels: ["High1", "High2"],
137
137
  },
138
138
  {
139
- name: 'keeps both types when both are needed for uniqueness',
139
+ name: "keeps both types when both are needed for uniqueness",
140
140
  traces: [
141
141
  [
142
- { type: 't1', importance: 10, label: 'A' },
143
- { type: 't2', importance: 1, label: 'X' }
142
+ { type: "t1", importance: 10, label: "A" },
143
+ { type: "t2", importance: 1, label: "X" },
144
144
  ],
145
145
  [
146
- { type: 't1', importance: 10, label: 'A' },
147
- { type: 't2', importance: 1, label: 'Y' }
146
+ { type: "t1", importance: 10, label: "A" },
147
+ { type: "t2", importance: 1, label: "Y" },
148
148
  ],
149
149
  [
150
- { type: 't1', importance: 10, label: 'B' },
151
- { type: 't2', importance: 1, label: 'Y' }
152
- ]
150
+ { type: "t1", importance: 10, label: "B" },
151
+ { type: "t2", importance: 1, label: "Y" },
152
+ ],
153
153
  ],
154
154
  // Neither t1 nor t2 alone can distinguish all three, need both
155
- labels: ['A / X', 'A / Y', 'B / Y']
155
+ labels: ["A / X", "A / Y", "B / Y"],
156
156
  },
157
157
  {
158
- name: 'removes multiple redundant types greedily',
158
+ name: "removes multiple redundant types greedily",
159
159
  traces: [
160
160
  [
161
- { type: 't1', importance: 100, label: 'Unique1' },
162
- { type: 't2', importance: 10, label: 'Same' },
163
- { type: 't3', importance: 1, label: 'Same' }
161
+ { type: "t1", importance: 100, label: "Unique1" },
162
+ { type: "t2", importance: 10, label: "Same" },
163
+ { type: "t3", importance: 1, label: "Same" },
164
164
  ],
165
165
  [
166
- { type: 't1', importance: 100, label: 'Unique2' },
167
- { type: 't2', importance: 10, label: 'Same' },
168
- { type: 't3', importance: 1, label: 'Same' }
169
- ]
166
+ { type: "t1", importance: 100, label: "Unique2" },
167
+ { type: "t2", importance: 10, label: "Same" },
168
+ { type: "t3", importance: 1, label: "Same" },
169
+ ],
170
170
  ],
171
171
  // t1 alone distinguishes; t2 and t3 are redundant and should be removed
172
- labels: ['Unique1', 'Unique2']
172
+ labels: ["Unique1", "Unique2"],
173
173
  },
174
174
  {
175
- name: 'fallback case: removes types that do not reduce cardinality',
175
+ name: "fallback case: removes types that do not reduce cardinality",
176
176
  traces: [
177
177
  // Two columns with identical traces - cannot be distinguished
178
178
  [
179
- { type: 't1', importance: 100, label: 'A' },
180
- { type: 't2', importance: 10, label: 'X' },
181
- { type: 't3', importance: 1, label: 'Same' }
179
+ { type: "t1", importance: 100, label: "A" },
180
+ { type: "t2", importance: 10, label: "X" },
181
+ { type: "t3", importance: 1, label: "Same" },
182
182
  ],
183
183
  [
184
- { type: 't1', importance: 100, label: 'A' },
185
- { type: 't2', importance: 10, label: 'X' },
186
- { type: 't3', importance: 1, label: 'Same' }
184
+ { type: "t1", importance: 100, label: "A" },
185
+ { type: "t2", importance: 10, label: "X" },
186
+ { type: "t3", importance: 1, label: "Same" },
187
187
  ],
188
188
  // Third column is different
189
189
  [
190
- { type: 't1', importance: 100, label: 'B' },
191
- { type: 't2', importance: 10, label: 'Y' },
192
- { type: 't3', importance: 1, label: 'Same' }
193
- ]
190
+ { type: "t1", importance: 100, label: "B" },
191
+ { type: "t2", importance: 10, label: "Y" },
192
+ { type: "t3", importance: 1, label: "Same" },
193
+ ],
194
194
  ],
195
195
  // Cannot achieve full uniqueness (2 columns are identical), but t3 (Same) can be removed
196
196
  // since it doesn't help distinguish anything. t1 alone gives cardinality 2.
197
- labels: ['A', 'A', 'B']
198
- }
199
- ])('test label minimization: $name', ({ traces, labels }) => {
197
+ labels: ["A", "A", "B"],
198
+ },
199
+ ])("test label minimization: $name", ({ traces, labels }) => {
200
200
  expect(deriveLabels(tracesToSpecs(traces), (s) => s).map((r) => r.label)).toEqual(labels);
201
201
  });
202
202
 
203
203
  test.each<{ name: string; traces: Trace[]; labels: string[]; forceTraceElements: string[] }>([
204
204
  {
205
- name: 'force one element',
205
+ name: "force one element",
206
206
  traces: [
207
207
  [
208
- { type: 't1', label: 'T1L1' },
209
- { type: 't2', label: 'T2L1' }
208
+ { type: "t1", label: "T1L1" },
209
+ { type: "t2", label: "T2L1" },
210
210
  ],
211
211
  [
212
- { type: 't1', label: 'T1L2' },
213
- { type: 't2', label: 'T2L2' }
214
- ]
212
+ { type: "t1", label: "T1L2" },
213
+ { type: "t2", label: "T2L2" },
214
+ ],
215
215
  ],
216
- labels: ['T1L1', 'T1L2'],
217
- forceTraceElements: ['t1']
216
+ labels: ["T1L1", "T1L2"],
217
+ forceTraceElements: ["t1"],
218
218
  },
219
219
  {
220
- name: 'force multiple elements',
220
+ name: "force multiple elements",
221
221
  traces: [
222
222
  [
223
- { type: 't1', label: 'T1L1' },
224
- { type: 't2', label: 'T2L1' },
225
- { type: 't3', label: 'T3L1' }
223
+ { type: "t1", label: "T1L1" },
224
+ { type: "t2", label: "T2L1" },
225
+ { type: "t3", label: "T3L1" },
226
226
  ],
227
227
  [
228
- { type: 't1', label: 'T1L2' },
229
- { type: 't2', label: 'T2L2' },
230
- { type: 't3', label: 'T3L2' }
231
- ]
228
+ { type: "t1", label: "T1L2" },
229
+ { type: "t2", label: "T2L2" },
230
+ { type: "t3", label: "T3L2" },
231
+ ],
232
232
  ],
233
- labels: ['T1L1 / T3L1', 'T1L2 / T3L2'],
234
- forceTraceElements: ['t1', 't3']
233
+ labels: ["T1L1 / T3L1", "T1L2 / T3L2"],
234
+ forceTraceElements: ["t1", "t3"],
235
235
  },
236
236
  {
237
- name: 'force element not in all traces',
237
+ name: "force element not in all traces",
238
238
  traces: [
239
239
  [
240
- { type: 't1', label: 'T1L1' },
241
- { type: 't2', label: 'T2L1' }
240
+ { type: "t1", label: "T1L1" },
241
+ { type: "t2", label: "T2L1" },
242
242
  ],
243
- [{ type: 't2', label: 'T2L2' }]
243
+ [{ type: "t2", label: "T2L2" }],
244
244
  ],
245
- labels: ['T1L1 / T2L1', 'T2L2'],
246
- forceTraceElements: ['t1']
245
+ labels: ["T1L1 / T2L1", "T2L2"],
246
+ forceTraceElements: ["t1"],
247
247
  },
248
248
  {
249
- name: 'force element with includeNativeLabel',
249
+ name: "force element with includeNativeLabel",
250
250
  traces: [
251
251
  [
252
- { type: 't1', label: 'T1L1' },
253
- { type: 't2', label: 'T2L1' }
252
+ { type: "t1", label: "T1L1" },
253
+ { type: "t2", label: "T2L1" },
254
254
  ],
255
255
  [
256
- { type: 't1', label: 'T1L2' },
257
- { type: 't2', label: 'T2L2' }
258
- ]
256
+ { type: "t1", label: "T1L2" },
257
+ { type: "t2", label: "T2L2" },
258
+ ],
259
259
  ],
260
- labels: ['T1L1', 'T1L2'],
261
- forceTraceElements: ['t1']
262
- }
260
+ labels: ["T1L1", "T1L2"],
261
+ forceTraceElements: ["t1"],
262
+ },
263
263
  ])(
264
- 'test label derivation with forceTraceElements: $name',
264
+ "test label derivation with forceTraceElements: $name",
265
265
  ({ name, traces, labels, forceTraceElements }) => {
266
266
  expect(
267
- deriveLabels(tracesToSpecs(traces), (s) => s, { forceTraceElements }).map((r) => r.label)
267
+ deriveLabels(tracesToSpecs(traces), (s) => s, { forceTraceElements }).map((r) => r.label),
268
268
  ).toEqual(labels);
269
269
 
270
- if (name === 'force element with includeNativeLabel') {
270
+ if (name === "force element with includeNativeLabel") {
271
271
  expect(
272
272
  deriveLabels(tracesToSpecs(traces), (s) => s, {
273
273
  forceTraceElements,
274
- includeNativeLabel: true
275
- }).map((r) => r.label)
276
- ).toEqual(labels.map(l => 'Label / ' + l));
274
+ includeNativeLabel: true,
275
+ }).map((r) => r.label),
276
+ ).toEqual(labels.map((l) => "Label / " + l));
277
277
  }
278
- }
278
+ },
279
279
  );
@@ -1,5 +1,10 @@
1
- import { Annotation, parseJson, readAnnotation, type PObjectSpec } from '@milaboratories/pl-model-common';
2
- import { z } from 'zod';
1
+ import {
2
+ Annotation,
3
+ parseJson,
4
+ readAnnotation,
5
+ type PObjectSpec,
6
+ } from "@milaboratories/pl-model-common";
7
+ import { z } from "zod";
3
8
 
4
9
  export type RecordsWithLabel<T> = {
5
10
  value: T;
@@ -31,16 +36,18 @@ export type Trace = z.infer<typeof Trace>;
31
36
  type FullTrace = FullTraceEntry[];
32
37
 
33
38
  // Define the possible return types for the specExtractor function
34
- type SpecExtractorResult = PObjectSpec | {
35
- spec: PObjectSpec;
36
- prefixTrace?: TraceEntry[];
37
- suffixTrace?: TraceEntry[];
38
- };
39
+ type SpecExtractorResult =
40
+ | PObjectSpec
41
+ | {
42
+ spec: PObjectSpec;
43
+ prefixTrace?: TraceEntry[];
44
+ suffixTrace?: TraceEntry[];
45
+ };
39
46
 
40
47
  const DistancePenalty = 0.001;
41
48
 
42
- const LabelType = '__LABEL__';
43
- const LabelTypeFull = '__LABEL__@1';
49
+ const LabelType = "__LABEL__";
50
+ const LabelTypeFull = "__LABEL__@1";
44
51
 
45
52
  export function deriveLabels<T>(
46
53
  values: T[],
@@ -49,9 +56,10 @@ export function deriveLabels<T>(
49
56
  ): RecordsWithLabel<T>[] {
50
57
  const importances = new Map<string, number>();
51
58
 
52
- const forceTraceElements = (ops.forceTraceElements !== undefined && ops.forceTraceElements.length > 0)
53
- ? new Set(ops.forceTraceElements)
54
- : undefined;
59
+ const forceTraceElements =
60
+ ops.forceTraceElements !== undefined && ops.forceTraceElements.length > 0
61
+ ? new Set(ops.forceTraceElements)
62
+ : undefined;
55
63
 
56
64
  // number of times certain type occurred among all of the
57
65
  const numberOfRecordsWithType = new Map<string, number>();
@@ -63,7 +71,7 @@ export function deriveLabels<T>(
63
71
  let suffixTrace: TraceEntry[] | undefined;
64
72
 
65
73
  // Check if the result is the new structure or just PObjectSpec
66
- if ('spec' in extractorResult && typeof extractorResult.spec === 'object') {
74
+ if ("spec" in extractorResult && typeof extractorResult.spec === "object") {
67
75
  // It's the new structure { spec, prefixTrace?, suffixTrace? }
68
76
  spec = extractorResult.spec;
69
77
  prefixTrace = extractorResult.prefixTrace;
@@ -77,11 +85,7 @@ export function deriveLabels<T>(
77
85
  const traceStr = readAnnotation(spec, Annotation.Trace);
78
86
  const baseTrace = (traceStr ? Trace.safeParse(parseJson(traceStr)).data : undefined) ?? [];
79
87
 
80
- const trace = [
81
- ...(prefixTrace ?? []),
82
- ...baseTrace,
83
- ...(suffixTrace ?? []),
84
- ];
88
+ const trace = [...(prefixTrace ?? []), ...baseTrace, ...(suffixTrace ?? [])];
85
89
 
86
90
  if (label !== undefined) {
87
91
  const labelEntry = { label, type: LabelType, importance: -2 };
@@ -127,7 +131,7 @@ export function deriveLabels<T>(
127
131
  allTypeRecords.sort(([, i1], [, i2]) => i2 - i1);
128
132
 
129
133
  for (const [typeName] of allTypeRecords) {
130
- if (typeName.endsWith('@1') || numberOfRecordsWithType.get(typeName) === values.length)
134
+ if (typeName.endsWith("@1") || numberOfRecordsWithType.get(typeName) === values.length)
131
135
  mainTypes.push(typeName);
132
136
  else secondaryTypes.push(typeName);
133
137
  }
@@ -136,20 +140,20 @@ export function deriveLabels<T>(
136
140
  const result: RecordsWithLabel<T>[] = [];
137
141
  for (let i = 0; i < enrichedRecords.length; i++) {
138
142
  const r = enrichedRecords[i];
139
- const includedTrace = r.fullTrace
140
- .filter((fm) => includedTypes.has(fm.fullType)
141
- || (forceTraceElements && forceTraceElements.has(fm.type)));
143
+ const includedTrace = r.fullTrace.filter(
144
+ (fm) =>
145
+ includedTypes.has(fm.fullType) || (forceTraceElements && forceTraceElements.has(fm.type)),
146
+ );
142
147
  if (includedTrace.length === 0) {
143
148
  if (force)
144
149
  result.push({
145
- label: 'Unlabeled',
150
+ label: "Unlabeled",
146
151
  value: r.value,
147
152
  } satisfies RecordsWithLabel<T>);
148
153
  else return undefined;
149
154
  }
150
- const labelSet = includedTrace
151
- .map((fm) => fm.label);
152
- const sep = ops.separator ?? ' / ';
155
+ const labelSet = includedTrace.map((fm) => fm.label);
156
+ const sep = ops.separator ?? " / ";
153
157
  result.push({
154
158
  label: labelSet.join(sep),
155
159
  value: r.value,
@@ -172,16 +176,21 @@ export function deriveLabels<T>(
172
176
 
173
177
  // Get types sorted by importance ascending (lowest first), excluding forced elements
174
178
  const removableSorted = [...typeSet]
175
- .filter((t) =>
176
- !forceTraceElements?.has(t.split('@')[0])
177
- && !(ops.includeNativeLabel && t === LabelTypeFull))
179
+ .filter(
180
+ (t) =>
181
+ !forceTraceElements?.has(t.split("@")[0]) &&
182
+ !(ops.includeNativeLabel && t === LabelTypeFull),
183
+ )
178
184
  .sort((a, b) => (importances.get(a) ?? 0) - (importances.get(b) ?? 0));
179
185
 
180
186
  for (const typeToRemove of removableSorted) {
181
187
  const reducedSet = new Set(typeSet);
182
188
  reducedSet.delete(typeToRemove);
183
189
  const candidateResult = calculate(reducedSet);
184
- if (candidateResult !== undefined && countUniqueLabels(candidateResult) >= currentCardinality) {
190
+ if (
191
+ candidateResult !== undefined &&
192
+ countUniqueLabels(candidateResult) >= currentCardinality
193
+ ) {
185
194
  typeSet.delete(typeToRemove);
186
195
  }
187
196
  }
@@ -189,7 +198,8 @@ export function deriveLabels<T>(
189
198
  };
190
199
 
191
200
  if (mainTypes.length === 0) {
192
- if (secondaryTypes.length !== 0) throw new Error('Non-empty secondary types list while main types list is empty.');
201
+ if (secondaryTypes.length !== 0)
202
+ throw new Error("Non-empty secondary types list while main types list is empty.");
193
203
  return calculate(new Set(LabelTypeFull), true)!;
194
204
  }
195
205
 
@@ -208,8 +218,7 @@ export function deriveLabels<T>(
208
218
  const currentSet = new Set<string>();
209
219
  if (ops.includeNativeLabel) currentSet.add(LabelTypeFull);
210
220
  for (let i = 0; i < includedTypes; ++i) currentSet.add(mainTypes[i]);
211
- if (additionalType >= 0)
212
- currentSet.add(mainTypes[additionalType]);
221
+ if (additionalType >= 0) currentSet.add(mainTypes[additionalType]);
213
222
 
214
223
  const candidateResult = calculate(currentSet);
215
224