@milaboratories/pl-middle-layer 2.10.0 → 2.11.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.
Files changed (181) hide show
  1. package/dist/block_registry/registry-v2-provider.cjs +8 -1
  2. package/dist/block_registry/registry-v2-provider.cjs.map +1 -1
  3. package/dist/block_registry/registry-v2-provider.d.ts.map +1 -1
  4. package/dist/block_registry/registry-v2-provider.js +8 -1
  5. package/dist/block_registry/registry-v2-provider.js.map +1 -1
  6. package/dist/index.cjs +25 -1
  7. package/dist/index.d.ts +12 -5
  8. package/dist/index.js +5 -3
  9. package/dist/js_render/bundle_bytecode_cache.cjs +6 -1
  10. package/dist/js_render/bundle_bytecode_cache.cjs.map +1 -1
  11. package/dist/js_render/bundle_bytecode_cache.js +6 -1
  12. package/dist/js_render/bundle_bytecode_cache.js.map +1 -1
  13. package/dist/js_render/column_registry.cjs +17 -0
  14. package/dist/js_render/column_registry.cjs.map +1 -1
  15. package/dist/js_render/column_registry.js +16 -1
  16. package/dist/js_render/column_registry.js.map +1 -1
  17. package/dist/js_render/computable_context.cjs +1 -1
  18. package/dist/js_render/computable_context.js +1 -1
  19. package/dist/js_render/context.cjs +3 -2
  20. package/dist/js_render/context.cjs.map +1 -1
  21. package/dist/js_render/context.js +3 -2
  22. package/dist/js_render/context.js.map +1 -1
  23. package/dist/js_render/index.cjs +1 -1
  24. package/dist/js_render/index.cjs.map +1 -1
  25. package/dist/js_render/index.js +1 -1
  26. package/dist/js_render/index.js.map +1 -1
  27. package/dist/js_render/service_injectors.cjs +2 -9
  28. package/dist/js_render/service_injectors.cjs.map +1 -1
  29. package/dist/js_render/service_injectors.js +2 -9
  30. package/dist/js_render/service_injectors.js.map +1 -1
  31. package/dist/middle_layer/block.cjs +48 -0
  32. package/dist/middle_layer/block.cjs.map +1 -1
  33. package/dist/middle_layer/block.js +51 -4
  34. package/dist/middle_layer/block.js.map +1 -1
  35. package/dist/middle_layer/block_pack_description.cjs +80 -0
  36. package/dist/middle_layer/block_pack_description.cjs.map +1 -0
  37. package/dist/middle_layer/block_pack_description.d.ts +36 -0
  38. package/dist/middle_layer/block_pack_description.d.ts.map +1 -0
  39. package/dist/middle_layer/block_pack_description.js +78 -0
  40. package/dist/middle_layer/block_pack_description.js.map +1 -0
  41. package/dist/middle_layer/build_stamp.cjs +1 -1
  42. package/dist/middle_layer/build_stamp.js +1 -1
  43. package/dist/middle_layer/index.cjs +11 -0
  44. package/dist/middle_layer/index.d.ts +8 -2
  45. package/dist/middle_layer/index.js +3 -1
  46. package/dist/middle_layer/legacy_project_holds.cjs +61 -0
  47. package/dist/middle_layer/legacy_project_holds.cjs.map +1 -0
  48. package/dist/middle_layer/legacy_project_holds.js +61 -0
  49. package/dist/middle_layer/legacy_project_holds.js.map +1 -0
  50. package/dist/middle_layer/middle_layer.cjs +22 -24
  51. package/dist/middle_layer/middle_layer.cjs.map +1 -1
  52. package/dist/middle_layer/middle_layer.d.ts +13 -3
  53. package/dist/middle_layer/middle_layer.d.ts.map +1 -1
  54. package/dist/middle_layer/middle_layer.js +21 -23
  55. package/dist/middle_layer/middle_layer.js.map +1 -1
  56. package/dist/middle_layer/pool_columns.cjs +160 -0
  57. package/dist/middle_layer/pool_columns.cjs.map +1 -0
  58. package/dist/middle_layer/pool_columns.d.ts +59 -0
  59. package/dist/middle_layer/pool_columns.d.ts.map +1 -0
  60. package/dist/middle_layer/pool_columns.js +157 -0
  61. package/dist/middle_layer/pool_columns.js.map +1 -0
  62. package/dist/middle_layer/pool_frame.cjs +82 -0
  63. package/dist/middle_layer/pool_frame.cjs.map +1 -0
  64. package/dist/middle_layer/pool_frame.d.ts +37 -0
  65. package/dist/middle_layer/pool_frame.d.ts.map +1 -0
  66. package/dist/middle_layer/pool_frame.js +81 -0
  67. package/dist/middle_layer/pool_frame.js.map +1 -0
  68. package/dist/middle_layer/pool_table.cjs +66 -0
  69. package/dist/middle_layer/pool_table.cjs.map +1 -0
  70. package/dist/middle_layer/pool_table.d.ts +27 -0
  71. package/dist/middle_layer/pool_table.d.ts.map +1 -0
  72. package/dist/middle_layer/pool_table.js +66 -0
  73. package/dist/middle_layer/pool_table.js.map +1 -0
  74. package/dist/middle_layer/project.cjs +89 -23
  75. package/dist/middle_layer/project.cjs.map +1 -1
  76. package/dist/middle_layer/project.d.ts +70 -4
  77. package/dist/middle_layer/project.d.ts.map +1 -1
  78. package/dist/middle_layer/project.js +89 -22
  79. package/dist/middle_layer/project.js.map +1 -1
  80. package/dist/middle_layer/rich_column_query.cjs +180 -0
  81. package/dist/middle_layer/rich_column_query.cjs.map +1 -0
  82. package/dist/middle_layer/rich_column_query.d.ts +34 -0
  83. package/dist/middle_layer/rich_column_query.d.ts.map +1 -0
  84. package/dist/middle_layer/rich_column_query.js +176 -0
  85. package/dist/middle_layer/rich_column_query.js.map +1 -0
  86. package/dist/model/args.cjs +23 -0
  87. package/dist/model/args.cjs.map +1 -1
  88. package/dist/model/args.js +24 -2
  89. package/dist/model/args.js.map +1 -1
  90. package/dist/model/args_derivation.cjs +60 -2
  91. package/dist/model/args_derivation.cjs.map +1 -1
  92. package/dist/model/args_derivation.d.ts +73 -3
  93. package/dist/model/args_derivation.d.ts.map +1 -1
  94. package/dist/model/args_derivation.js +60 -3
  95. package/dist/model/args_derivation.js.map +1 -1
  96. package/dist/model/block_pack_spec.cjs.map +1 -1
  97. package/dist/model/block_pack_spec.d.ts +3 -3
  98. package/dist/model/block_pack_spec.d.ts.map +1 -1
  99. package/dist/model/block_pack_spec.js.map +1 -1
  100. package/dist/model/block_params_model.cjs +42 -0
  101. package/dist/model/block_params_model.cjs.map +1 -0
  102. package/dist/model/block_params_model.d.ts +45 -0
  103. package/dist/model/block_params_model.d.ts.map +1 -0
  104. package/dist/model/block_params_model.js +42 -0
  105. package/dist/model/block_params_model.js.map +1 -0
  106. package/dist/model/index.d.ts +3 -1
  107. package/dist/model/project_helper.cjs +50 -6
  108. package/dist/model/project_helper.cjs.map +1 -1
  109. package/dist/model/project_helper.d.ts +25 -1
  110. package/dist/model/project_helper.d.ts.map +1 -1
  111. package/dist/model/project_helper.js +51 -7
  112. package/dist/model/project_helper.js.map +1 -1
  113. package/dist/model/template_spec.d.ts +18 -0
  114. package/dist/model/template_spec.d.ts.map +1 -1
  115. package/dist/mutator/block-pack/block_pack.cjs +90 -3
  116. package/dist/mutator/block-pack/block_pack.cjs.map +1 -1
  117. package/dist/mutator/block-pack/block_pack.d.ts +16 -0
  118. package/dist/mutator/block-pack/block_pack.d.ts.map +1 -1
  119. package/dist/mutator/block-pack/block_pack.js +91 -5
  120. package/dist/mutator/block-pack/block_pack.js.map +1 -1
  121. package/dist/mutator/block-pack/required_capabilities.cjs +16 -0
  122. package/dist/mutator/block-pack/required_capabilities.cjs.map +1 -1
  123. package/dist/mutator/block-pack/required_capabilities.js +16 -1
  124. package/dist/mutator/block-pack/required_capabilities.js.map +1 -1
  125. package/dist/mutator/project.cjs +4 -0
  126. package/dist/mutator/project.cjs.map +1 -1
  127. package/dist/mutator/project.d.ts +1 -1
  128. package/dist/mutator/project.d.ts.map +1 -1
  129. package/dist/mutator/project.js +4 -0
  130. package/dist/mutator/project.js.map +1 -1
  131. package/dist/mutator/template/template_cache.cjs +8 -1
  132. package/dist/mutator/template/template_cache.cjs.map +1 -1
  133. package/dist/mutator/template/template_cache.d.ts +7 -3
  134. package/dist/mutator/template/template_cache.d.ts.map +1 -1
  135. package/dist/mutator/template/template_cache.js +8 -1
  136. package/dist/mutator/template/template_cache.js.map +1 -1
  137. package/package.json +9 -9
  138. package/src/block_registry/registry-v2-provider.test.ts +23 -0
  139. package/src/block_registry/registry-v2-provider.ts +11 -1
  140. package/src/index.ts +2 -0
  141. package/src/js_render/bundle_bytecode_cache.ts +15 -4
  142. package/src/js_render/column_registry.ts +24 -3
  143. package/src/js_render/context.ts +4 -3
  144. package/src/js_render/index.ts +3 -2
  145. package/src/js_render/service_injectors.ts +2 -11
  146. package/src/middle_layer/block.ts +61 -2
  147. package/src/middle_layer/block_pack_description.test.ts +235 -0
  148. package/src/middle_layer/block_pack_description.ts +143 -0
  149. package/src/middle_layer/index.ts +9 -1
  150. package/src/middle_layer/legacy_project_holds.test.ts +133 -0
  151. package/src/middle_layer/legacy_project_holds.ts +73 -0
  152. package/src/middle_layer/middle_layer.ts +27 -28
  153. package/src/middle_layer/pool_columns.test.ts +217 -0
  154. package/src/middle_layer/pool_columns.ts +250 -0
  155. package/src/middle_layer/pool_frame.test.ts +144 -0
  156. package/src/middle_layer/pool_frame.ts +127 -0
  157. package/src/middle_layer/pool_table.test.ts +182 -0
  158. package/src/middle_layer/pool_table.ts +98 -0
  159. package/src/middle_layer/project.ts +135 -32
  160. package/src/middle_layer/rich_column_query.test.ts +311 -0
  161. package/src/middle_layer/rich_column_query.ts +214 -0
  162. package/src/model/args.test.ts +23 -1
  163. package/src/model/args.ts +29 -1
  164. package/src/model/args_derivation.test.ts +129 -12
  165. package/src/model/args_derivation.ts +112 -8
  166. package/src/model/block_pack_spec.ts +3 -2
  167. package/src/model/block_params_model.test.ts +194 -0
  168. package/src/model/block_params_model.ts +117 -0
  169. package/src/model/index.ts +6 -0
  170. package/src/model/project_helper.ts +101 -20
  171. package/src/model/template_spec.ts +21 -0
  172. package/src/mutator/block-pack/block_pack.test.ts +10 -1
  173. package/src/mutator/block-pack/block_pack.ts +102 -2
  174. package/src/mutator/block-pack/block_pack_load.test.ts +52 -0
  175. package/src/mutator/block-pack/required_capabilities.ts +25 -0
  176. package/src/mutator/project-v3.test.ts +27 -16
  177. package/src/mutator/project.ts +5 -0
  178. package/src/mutator/template/template_cache.ts +26 -3
  179. package/src/pool/result_pool_markers.test.ts +47 -0
  180. package/src/test/block_packs.ts +12 -0
  181. package/src/test/fake_project.ts +33 -6
@@ -0,0 +1,160 @@
1
+ const require_project_model = require("../model/project_model.cjs");
2
+ const require_project_model_util = require("../model/project_model_util.cjs");
3
+ const require_usingCtx = require("../_virtual/_@oxc-project_runtime@0.155.0/helpers/esm/usingCtx.cjs");
4
+ const require_upstream_block_ctx = require("../pool/upstream_block_ctx.cjs");
5
+ const require_column_registry = require("../js_render/column_registry.cjs");
6
+ let _milaboratories_ts_helpers = require("@milaboratories/ts-helpers");
7
+ let _milaboratories_pl_model_common = require("@milaboratories/pl-model-common");
8
+ let _milaboratories_computable = require("@milaboratories/computable");
9
+ // src/middle_layer/pool_columns.ts
10
+ /**
11
+ * The columns of a project's result pool with their specs, no data, as a block's model gets them
12
+ * from `ColumnsCollection(["result_pool"])`, filtered the way its `filter` does. Computed only when
13
+ * its value is asked for; reads the order of the blocks and the results of the blocks in view.
14
+ *
15
+ * @throws (from the value) when `viewAs` is not a block of the project
16
+ */
17
+ function poolColumns(prjEntry, query, env) {
18
+ return _milaboratories_computable.Computable.make((ctx) => {
19
+ try {
20
+ var _usingCtx$1 = require_usingCtx.default();
21
+ const upstream = poolView(ctx, prjEntry, query.viewAs);
22
+ if (upstream === void 0) return {
23
+ columns: [],
24
+ isComplete: true
25
+ };
26
+ const registry = require_column_registry.buildColumnRegistry({ upstreamBlockCtxes: upstream });
27
+ const host = {
28
+ resolveAccessor: () => {
29
+ throw new Error("A result pool listing has no accessor sources.");
30
+ },
31
+ getUpstreamBlockCtxes: () => upstream,
32
+ getSpecDriver: () => (0, _milaboratories_ts_helpers.notEmpty)(env.serviceRegistry.get(_milaboratories_pl_model_common.Services.PFrameSpec), "PFrameSpec service"),
33
+ resolveSpec: (id) => require_column_registry.resolveColumnSpec(registry, id)
34
+ };
35
+ const driver = (0, _milaboratories_ts_helpers.notEmpty)(env.serviceRegistry.get(_milaboratories_pl_model_common.Services.ColumnsCollection), "ColumnsCollection service");
36
+ const pool = _usingCtx$1.u(driver.create([{ kind: "result_pool" }], host));
37
+ const isComplete = driver.isFinal(pool.key);
38
+ let ids;
39
+ if (query.anchors !== void 0) try {
40
+ var _usingCtx3 = require_usingCtx.default();
41
+ const discovered = _usingCtx3.u(driver.discover(pool.key, {
42
+ include: query.include,
43
+ exclude: query.exclude,
44
+ anchors: query.anchors,
45
+ mode: query.mode ?? "enrichment",
46
+ maxHops: query.maxHops ?? 4
47
+ }, host));
48
+ ids = driver.getColumns(discovered.key, host);
49
+ } catch (_) {
50
+ _usingCtx3.e = _;
51
+ } finally {
52
+ _usingCtx3.d();
53
+ }
54
+ else if (query.include === void 0 && query.exclude === void 0) ids = driver.getColumns(pool.key, host);
55
+ else try {
56
+ var _usingCtx4 = require_usingCtx.default();
57
+ const filtered = _usingCtx4.u(driver.filter(pool.key, {
58
+ include: query.include,
59
+ exclude: query.exclude
60
+ }, host));
61
+ ids = driver.getColumns(filtered.key, host);
62
+ } catch (_) {
63
+ _usingCtx4.e = _;
64
+ } finally {
65
+ _usingCtx4.d();
66
+ }
67
+ const columns = [];
68
+ for (const id of ids) {
69
+ const column = poolColumnOf(registry, id);
70
+ if (column !== void 0) columns.push(column);
71
+ }
72
+ return {
73
+ columns,
74
+ isComplete
75
+ };
76
+ } catch (_) {
77
+ _usingCtx$1.e = _;
78
+ } finally {
79
+ _usingCtx$1.d();
80
+ }
81
+ });
82
+ }
83
+ /**
84
+ * The pool columns `ids` stand for, each looked up by its id as `viewAs` sees the pool, in the order
85
+ * of `ids`; `undefined` for an id that is no column of that pool. Unlike {@link poolColumns}, which
86
+ * lists one of several columns with the same spec, this finds each of them by its id.
87
+ *
88
+ * @throws (from the value) when `viewAs` is not a block of the project
89
+ */
90
+ function poolColumnsById(prjEntry, ids, viewAs) {
91
+ return _milaboratories_computable.Computable.make((ctx) => {
92
+ const upstream = poolView(ctx, prjEntry, viewAs);
93
+ if (upstream === void 0) return ids.map(() => void 0);
94
+ const registry = require_column_registry.buildColumnRegistry({ upstreamBlockCtxes: upstream });
95
+ return ids.map((id) => {
96
+ try {
97
+ return poolColumnOf(registry, id);
98
+ } catch {
99
+ return;
100
+ }
101
+ });
102
+ });
103
+ }
104
+ /**
105
+ * The pool column `id` stands for: the column of the registry its leaf is, with the spec the id
106
+ * makes of it. `undefined` when the leaf is not a column a block exports, or has no spec yet.
107
+ */
108
+ function poolColumnOf(registry, id) {
109
+ const leaf = (0, _milaboratories_pl_model_common.extractPObjectId)(id);
110
+ const leafRef = poolRefOf(leaf);
111
+ if (leafRef === void 0) return void 0;
112
+ const leafSpec = require_column_registry.resolveColumnSpec(registry, leaf);
113
+ if (leafSpec === void 0 || !(0, _milaboratories_pl_model_common.isPColumnSpec)(leafSpec)) return void 0;
114
+ const path = linkerPath(id);
115
+ return {
116
+ columnId: id,
117
+ ...id === leaf ? { ref: leafRef } : {},
118
+ exportName: leafRef.name,
119
+ ...path !== void 0 ? { path } : {},
120
+ producedBy: (0, _milaboratories_pl_model_common.asBlockId)(leafRef.blockId),
121
+ spec: (0, _milaboratories_pl_model_common.reconstructSpecFromId)(leafSpec, id)
122
+ };
123
+ }
124
+ /**
125
+ * The ids of the linker columns a discovered id was reached through, read through the filtered
126
+ * and overridden ids wrapped around it; `undefined` for an id with no discovered layer or no path.
127
+ */
128
+ function linkerPath(id) {
129
+ let key = (0, _milaboratories_pl_model_common.parseColumnIdSafely)(id);
130
+ while ((0, _milaboratories_pl_model_common.isColumnFilteredKey)(key) || (0, _milaboratories_pl_model_common.isColumnOverriddenKey)(key)) key = (0, _milaboratories_pl_model_common.parseColumnIdSafely)(key.source);
131
+ if (!(0, _milaboratories_pl_model_common.isColumnDiscoveredKey)(key) || key.path === void 0 || key.path.length === 0) return void 0;
132
+ return key.path.map((step) => step.column);
133
+ }
134
+ /**
135
+ * The contexts of the blocks whose results the pool holds as `viewAs` sees it: the block and every
136
+ * block above it; by default the last block of the project, which sees every block's results.
137
+ * `undefined` for a project with no blocks.
138
+ *
139
+ * @throws when `viewAs` is not a block of the project
140
+ */
141
+ function poolView(ctx, prjEntry, viewAs) {
142
+ const prj = ctx.accessor(prjEntry).node();
143
+ const structure = (0, _milaboratories_ts_helpers.notEmpty)(prj.getKeyValueAsJson(require_project_model.ProjectStructureKey));
144
+ const blockIds = [...require_project_model_util.allBlocks(structure)].map((b) => b.id);
145
+ const block = viewAs ?? blockIds.at(-1);
146
+ if (block === void 0) return void 0;
147
+ if (!blockIds.includes(block)) throw new Error(`Block ${block} not found in the project.`);
148
+ return require_upstream_block_ctx.collectUpstreamBlockCtx(ctx, prjEntry, block);
149
+ }
150
+ /** The reference a result-pool column id stands for: the id is that reference as canonical JSON. */
151
+ function poolRefOf(columnId) {
152
+ const parsed = _milaboratories_pl_model_common.PlRef.safeParse((0, _milaboratories_pl_model_common.parseJsonSafely)(columnId));
153
+ return parsed.success ? parsed.data : void 0;
154
+ }
155
+ exports.poolColumns = poolColumns;
156
+ exports.poolColumnsById = poolColumnsById;
157
+ exports.poolRefOf = poolRefOf;
158
+ exports.poolView = poolView;
159
+
160
+ //# sourceMappingURL=pool_columns.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pool_columns.cjs","names":["Computable","buildColumnRegistry","notEmpty","Services","resolveColumnSpec","extractPObjectId","isPColumnSpec","asBlockId","reconstructSpecFromId","parseColumnIdSafely","isColumnFilteredKey","isColumnOverriddenKey","isColumnDiscoveredKey","ProjectStructureKey","allBlocks","collectUpstreamBlockCtx","PlRef","parseJsonSafely"],"sources":["../../src/middle_layer/pool_columns.ts"],"sourcesContent":["import { Computable, type ComputableCtx } from \"@milaboratories/computable\";\nimport type { PlTreeEntry, PlTreeNodeAccessor } from \"@milaboratories/pl-tree\";\nimport { notEmpty } from \"@milaboratories/ts-helpers\";\nimport {\n asBlockId,\n extractPObjectId,\n isColumnDiscoveredKey,\n isColumnFilteredKey,\n isColumnOverriddenKey,\n isPColumnSpec,\n parseColumnIdSafely,\n parseJsonSafely,\n PlRef,\n reconstructSpecFromId,\n Services,\n type AnchorEntry,\n type BlockId,\n type ColumnRegistry,\n type ColumnsCollectionDriver,\n type ColumnsCollectionDriverHost,\n type ColumnSelector,\n type ColumnUniversalId,\n type MatchingMode,\n type PColumnSpec,\n type PObjectId,\n type UpstreamBlockCtx,\n} from \"@milaboratories/pl-model-common\";\nimport { buildColumnRegistry, resolveColumnSpec } from \"../js_render/column_registry\";\nimport type { ProjectStructure } from \"../model/project_model\";\nimport { ProjectStructureKey } from \"../model/project_model\";\nimport { allBlocks } from \"../model/project_model_util\";\nimport { collectUpstreamBlockCtx } from \"../pool/upstream_block_ctx\";\nimport type { MiddleLayerEnvironment } from \"./middle_layer\";\n\n/** One column of a project's result pool: its spec and how a block points at it. */\nexport interface PoolColumn {\n /**\n * The id a block's model gets for the column from `ColumnsCollection([\"result_pool\"])`: the\n * `GlobalPObjectId` of an exported column, or, found from anchors, a discovered id around it.\n */\n readonly columnId: ColumnUniversalId;\n /**\n * The reference a block stores in its data or args to point at the column: the object form of\n * `columnId`, set only when `columnId` is the `GlobalPObjectId` of an exported column.\n */\n readonly ref?: PlRef;\n /** The name under which the block exports the column the id comes down to. */\n readonly exportName: string;\n /** Of a discovered id: the ids of the linker columns it was reached through, in order. */\n readonly path?: ColumnUniversalId[];\n /** The block that exports the column the id comes down to. */\n readonly producedBy: BlockId;\n /** The spec the id stands for: the exported spec with what the id changes in it applied. */\n readonly spec: PColumnSpec;\n}\n\n/** The result-pool columns of a project, as {@link poolColumns} lists them. */\nexport interface PoolColumns {\n readonly columns: PoolColumn[];\n /**\n * False while a block whose results the view covers is still being calculated: more columns\n * may come.\n */\n readonly isComplete: boolean;\n}\n\n/** Which columns of the result pool {@link poolColumns} lists. */\nexport interface PoolColumnsQuery {\n /**\n * List the pool as this block sees it: the columns exported by the block and every block above\n * it. Default: as the last block of the project sees it, which is every block's columns.\n */\n readonly viewAs?: BlockId;\n /**\n * Keep only columns matching these selectors, as a block model passes them to\n * `ColumnsCollection([\"result_pool\"]).filter({ include })`.\n */\n readonly include?: ColumnSelector;\n /** Drop columns matching these selectors, as `filter({ exclude })` does. */\n readonly exclude?: ColumnSelector;\n /**\n * List the columns reachable from these columns, through linker columns too, as\n * `ColumnsCollection([\"result_pool\"]).discover({ anchors })` does: with discovered ids.\n */\n readonly anchors?: Record<string, AnchorEntry>;\n /** How axes of a discovered column may match the anchors' (default `enrichment`). */\n readonly mode?: MatchingMode;\n /** The most linker columns between an anchor and a discovered column (default 4). */\n readonly maxHops?: number;\n}\n\n/** What {@link poolColumns} reads besides the project tree. */\nexport type PoolColumnsEnv = Pick<MiddleLayerEnvironment, \"serviceRegistry\">;\n\n/**\n * The columns of a project's result pool with their specs, no data, as a block's model gets them\n * from `ColumnsCollection([\"result_pool\"])`, filtered the way its `filter` does. Computed only when\n * its value is asked for; reads the order of the blocks and the results of the blocks in view.\n *\n * @throws (from the value) when `viewAs` is not a block of the project\n */\nexport function poolColumns(\n prjEntry: PlTreeEntry,\n query: PoolColumnsQuery,\n env: PoolColumnsEnv,\n): Computable<PoolColumns> {\n return Computable.make((ctx) => {\n const upstream = poolView(ctx, prjEntry, query.viewAs);\n if (upstream === undefined) return { columns: [], isComplete: true };\n const registry = buildColumnRegistry({ upstreamBlockCtxes: upstream });\n const host: ColumnsCollectionDriverHost<PlTreeNodeAccessor> = {\n resolveAccessor: () => {\n throw new Error(\"A result pool listing has no accessor sources.\");\n },\n getUpstreamBlockCtxes: () => upstream,\n getSpecDriver: () =>\n notEmpty(env.serviceRegistry.get(Services.PFrameSpec), \"PFrameSpec service\"),\n resolveSpec: (id) => resolveColumnSpec(registry, id),\n };\n const driver: ColumnsCollectionDriver = notEmpty(\n env.serviceRegistry.get(Services.ColumnsCollection),\n \"ColumnsCollection service\",\n );\n\n using pool = driver.create([{ kind: \"result_pool\" }], host);\n const isComplete = driver.isFinal(pool.key);\n let ids: ColumnUniversalId[];\n if (query.anchors !== undefined) {\n using discovered = driver.discover(\n pool.key,\n {\n include: query.include,\n exclude: query.exclude,\n anchors: query.anchors,\n mode: query.mode ?? \"enrichment\",\n maxHops: query.maxHops ?? 4,\n },\n host,\n );\n ids = driver.getColumns(discovered.key, host);\n } else if (query.include === undefined && query.exclude === undefined) {\n ids = driver.getColumns(pool.key, host);\n } else {\n using filtered = driver.filter(\n pool.key,\n { include: query.include, exclude: query.exclude },\n host,\n );\n ids = driver.getColumns(filtered.key, host);\n }\n\n const columns: PoolColumn[] = [];\n for (const id of ids) {\n const column = poolColumnOf(registry, id);\n if (column !== undefined) columns.push(column);\n }\n return { columns, isComplete };\n });\n}\n\n/**\n * The pool columns `ids` stand for, each looked up by its id as `viewAs` sees the pool, in the order\n * of `ids`; `undefined` for an id that is no column of that pool. Unlike {@link poolColumns}, which\n * lists one of several columns with the same spec, this finds each of them by its id.\n *\n * @throws (from the value) when `viewAs` is not a block of the project\n */\nexport function poolColumnsById(\n prjEntry: PlTreeEntry,\n ids: readonly ColumnUniversalId[],\n viewAs: BlockId | undefined,\n): Computable<(PoolColumn | undefined)[]> {\n return Computable.make((ctx) => {\n const upstream = poolView(ctx, prjEntry, viewAs);\n if (upstream === undefined) return ids.map(() => undefined);\n const registry = buildColumnRegistry({ upstreamBlockCtxes: upstream });\n return ids.map((id) => {\n try {\n return poolColumnOf(registry, id);\n } catch {\n // An id whose layers do not fit the column, e.g. a filter of an axis it does not have.\n return undefined;\n }\n });\n });\n}\n\n/**\n * The pool column `id` stands for: the column of the registry its leaf is, with the spec the id\n * makes of it. `undefined` when the leaf is not a column a block exports, or has no spec yet.\n */\nfunction poolColumnOf(\n registry: ColumnRegistry<PlTreeNodeAccessor>,\n id: ColumnUniversalId,\n): PoolColumn | undefined {\n const leaf = extractPObjectId(id);\n const leafRef = poolRefOf(leaf);\n if (leafRef === undefined) return undefined;\n const leafSpec = resolveColumnSpec(registry, leaf);\n if (leafSpec === undefined || !isPColumnSpec(leafSpec)) return undefined;\n const path = linkerPath(id);\n return {\n columnId: id,\n ...(id === leaf ? { ref: leafRef } : {}),\n exportName: leafRef.name,\n ...(path !== undefined ? { path } : {}),\n producedBy: asBlockId(leafRef.blockId),\n spec: reconstructSpecFromId(leafSpec, id),\n };\n}\n\n/**\n * The ids of the linker columns a discovered id was reached through, read through the filtered\n * and overridden ids wrapped around it; `undefined` for an id with no discovered layer or no path.\n */\nfunction linkerPath(id: ColumnUniversalId): ColumnUniversalId[] | undefined {\n let key = parseColumnIdSafely(id);\n while (isColumnFilteredKey(key) || isColumnOverriddenKey(key))\n key = parseColumnIdSafely(key.source);\n if (!isColumnDiscoveredKey(key) || key.path === undefined || key.path.length === 0)\n return undefined;\n return key.path.map((step) => step.column);\n}\n\n/**\n * The contexts of the blocks whose results the pool holds as `viewAs` sees it: the block and every\n * block above it; by default the last block of the project, which sees every block's results.\n * `undefined` for a project with no blocks.\n *\n * @throws when `viewAs` is not a block of the project\n */\nexport function poolView(\n ctx: ComputableCtx,\n prjEntry: PlTreeEntry,\n viewAs: BlockId | undefined,\n): UpstreamBlockCtx<PlTreeNodeAccessor>[] | undefined {\n const prj = ctx.accessor(prjEntry).node();\n const structure = notEmpty(prj.getKeyValueAsJson<ProjectStructure>(ProjectStructureKey));\n const blockIds = [...allBlocks(structure)].map((b) => b.id);\n const block = viewAs ?? blockIds.at(-1);\n if (block === undefined) return undefined;\n if (!blockIds.includes(block)) throw new Error(`Block ${block} not found in the project.`);\n return collectUpstreamBlockCtx(ctx, prjEntry, block);\n}\n\n/** The reference a result-pool column id stands for: the id is that reference as canonical JSON. */\nexport function poolRefOf(columnId: PObjectId): PlRef | undefined {\n const parsed = PlRef.safeParse(parseJsonSafely(columnId));\n return parsed.success ? parsed.data : undefined;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAqGA,SAAgB,YACd,UACA,OACA,KACyB;CACzB,OAAOA,2BAAAA,WAAW,MAAM,QAAQ;;;GAC9B,MAAM,WAAW,SAAS,KAAK,UAAU,MAAM,MAAM;GACrD,IAAI,aAAa,KAAA,GAAW,OAAO;IAAE,SAAS,CAAC;IAAG,YAAY;GAAK;GACnE,MAAM,WAAWC,wBAAAA,oBAAoB,EAAE,oBAAoB,SAAS,CAAC;GACrE,MAAM,OAAwD;IAC5D,uBAAuB;KACrB,MAAM,IAAI,MAAM,gDAAgD;IAClE;IACA,6BAA6B;IAC7B,sBAAA,GACEC,2BAAAA,SAAAA,CAAS,IAAI,gBAAgB,IAAIC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C3C;;;;;;;;AASA,SAAgB,SACd,KACA,UACA,QACoD;CACpD,MAAM,MAAM,IAAI,SAAS,QAAQ,CAAC,CAAC,KAAK;CACxC,MAAM,aAAA,GAAYV,2BAAAA,SAAAA,CAAS,IAAI,kBAAoCW,sBAAAA,mBAAmB,CAAC;CACvF,MAAM,WAAW,CAAC,GAAGC,2BAAAA,UAAU,SAAS,CAAC,CAAC,CAAC,KAAK,MAAM,EAAE,EAAE;CAC1D,MAAM,QAAQ,UAAU,SAAS,GAAG,EAAE;CACtC,IAAI,UAAU,KAAA,GAAW,OAAO,KAAA;CAChC,IAAI,CAAC,SAAS,SAAS,KAAK,GAAG,MAAM,IAAI,MAAM,SAAS,MAAM,2BAA2B;CACzF,OAAOC,2BAAAA,wBAAwB,KAAK,UAAU,KAAK;AACrD;;AAGA,SAAgB,UAAU,UAAwC;CAChE,MAAM,SAASC,gCAAAA,MAAM,WAAA,GAAUC,gCAAAA,gBAAAA,CAAgB,QAAQ,CAAC;CACxD,OAAO,OAAO,UAAU,OAAO,OAAO,KAAA;AACxC"}
@@ -0,0 +1,59 @@
1
+ import "./middle_layer.js";
2
+ import { AnchorEntry, BlockId, ColumnSelector, ColumnUniversalId, MatchingMode, PColumnSpec, PObjectId, PlRef } from "@milaboratories/pl-model-common";
3
+ import { Computable } from "@milaboratories/computable";
4
+ import { PlTreeNodeAccessor } from "@milaboratories/pl-tree";
5
+ /** One column of a project's result pool: its spec and how a block points at it. */
6
+ export interface PoolColumn {
7
+ /**
8
+ * The id a block's model gets for the column from `ColumnsCollection(["result_pool"])`: the
9
+ * `GlobalPObjectId` of an exported column, or, found from anchors, a discovered id around it.
10
+ */
11
+ readonly columnId: ColumnUniversalId;
12
+ /**
13
+ * The reference a block stores in its data or args to point at the column: the object form of
14
+ * `columnId`, set only when `columnId` is the `GlobalPObjectId` of an exported column.
15
+ */
16
+ readonly ref?: PlRef;
17
+ /** The name under which the block exports the column the id comes down to. */
18
+ readonly exportName: string;
19
+ /** Of a discovered id: the ids of the linker columns it was reached through, in order. */
20
+ readonly path?: ColumnUniversalId[];
21
+ /** The block that exports the column the id comes down to. */
22
+ readonly producedBy: BlockId;
23
+ /** The spec the id stands for: the exported spec with what the id changes in it applied. */
24
+ readonly spec: PColumnSpec;
25
+ }
26
+ /** The result-pool columns of a project, as {@link poolColumns} lists them. */
27
+ export interface PoolColumns {
28
+ readonly columns: PoolColumn[];
29
+ /**
30
+ * False while a block whose results the view covers is still being calculated: more columns
31
+ * may come.
32
+ */
33
+ readonly isComplete: boolean;
34
+ }
35
+ /** Which columns of the result pool {@link poolColumns} lists. */
36
+ export interface PoolColumnsQuery {
37
+ /**
38
+ * List the pool as this block sees it: the columns exported by the block and every block above
39
+ * it. Default: as the last block of the project sees it, which is every block's columns.
40
+ */
41
+ readonly viewAs?: BlockId;
42
+ /**
43
+ * Keep only columns matching these selectors, as a block model passes them to
44
+ * `ColumnsCollection(["result_pool"]).filter({ include })`.
45
+ */
46
+ readonly include?: ColumnSelector;
47
+ /** Drop columns matching these selectors, as `filter({ exclude })` does. */
48
+ readonly exclude?: ColumnSelector;
49
+ /**
50
+ * List the columns reachable from these columns, through linker columns too, as
51
+ * `ColumnsCollection(["result_pool"]).discover({ anchors })` does: with discovered ids.
52
+ */
53
+ readonly anchors?: Record<string, AnchorEntry>;
54
+ /** How axes of a discovered column may match the anchors' (default `enrichment`). */
55
+ readonly mode?: MatchingMode;
56
+ /** The most linker columns between an anchor and a discovered column (default 4). */
57
+ readonly maxHops?: number;
58
+ }
59
+ //# sourceMappingURL=pool_columns.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pool_columns.d.ts","names":[],"sources":["../../src/middle_layer/pool_columns.ts"],"mappings":";;;;;iBAmCiB;;;;;WAKN,UAAU;;;;;WAKV,MAAM;;WAEN;;WAEA,OAAO;;WAEP,YAAY;;WAEZ,MAAM;;;iBAIA;WACN,SAAS;;;;;WAKT;;;iBAIM;;;;;WAKN,SAAS;;;;;WAKT,UAAU;;WAEV,UAAU;;;;;WAKV,UAAU,eAAe;;WAEzB,OAAO;;WAEP"}
@@ -0,0 +1,157 @@
1
+ import { ProjectStructureKey } from "../model/project_model.js";
2
+ import { allBlocks } from "../model/project_model_util.js";
3
+ import _usingCtx from "../_virtual/_@oxc-project_runtime@0.155.0/helpers/esm/usingCtx.js";
4
+ import { collectUpstreamBlockCtx } from "../pool/upstream_block_ctx.js";
5
+ import { buildColumnRegistry, resolveColumnSpec } from "../js_render/column_registry.js";
6
+ import { notEmpty } from "@milaboratories/ts-helpers";
7
+ import { PlRef, Services, asBlockId, extractPObjectId, isColumnDiscoveredKey, isColumnFilteredKey, isColumnOverriddenKey, isPColumnSpec, parseColumnIdSafely, parseJsonSafely, reconstructSpecFromId } from "@milaboratories/pl-model-common";
8
+ import { Computable } from "@milaboratories/computable";
9
+ // src/middle_layer/pool_columns.ts
10
+ /**
11
+ * The columns of a project's result pool with their specs, no data, as a block's model gets them
12
+ * from `ColumnsCollection(["result_pool"])`, filtered the way its `filter` does. Computed only when
13
+ * its value is asked for; reads the order of the blocks and the results of the blocks in view.
14
+ *
15
+ * @throws (from the value) when `viewAs` is not a block of the project
16
+ */
17
+ function poolColumns(prjEntry, query, env) {
18
+ return Computable.make((ctx) => {
19
+ try {
20
+ var _usingCtx$1 = _usingCtx();
21
+ const upstream = poolView(ctx, prjEntry, query.viewAs);
22
+ if (upstream === void 0) return {
23
+ columns: [],
24
+ isComplete: true
25
+ };
26
+ const registry = buildColumnRegistry({ upstreamBlockCtxes: upstream });
27
+ const host = {
28
+ resolveAccessor: () => {
29
+ throw new Error("A result pool listing has no accessor sources.");
30
+ },
31
+ getUpstreamBlockCtxes: () => upstream,
32
+ getSpecDriver: () => notEmpty(env.serviceRegistry.get(Services.PFrameSpec), "PFrameSpec service"),
33
+ resolveSpec: (id) => resolveColumnSpec(registry, id)
34
+ };
35
+ const driver = notEmpty(env.serviceRegistry.get(Services.ColumnsCollection), "ColumnsCollection service");
36
+ const pool = _usingCtx$1.u(driver.create([{ kind: "result_pool" }], host));
37
+ const isComplete = driver.isFinal(pool.key);
38
+ let ids;
39
+ if (query.anchors !== void 0) try {
40
+ var _usingCtx3 = _usingCtx();
41
+ const discovered = _usingCtx3.u(driver.discover(pool.key, {
42
+ include: query.include,
43
+ exclude: query.exclude,
44
+ anchors: query.anchors,
45
+ mode: query.mode ?? "enrichment",
46
+ maxHops: query.maxHops ?? 4
47
+ }, host));
48
+ ids = driver.getColumns(discovered.key, host);
49
+ } catch (_) {
50
+ _usingCtx3.e = _;
51
+ } finally {
52
+ _usingCtx3.d();
53
+ }
54
+ else if (query.include === void 0 && query.exclude === void 0) ids = driver.getColumns(pool.key, host);
55
+ else try {
56
+ var _usingCtx4 = _usingCtx();
57
+ const filtered = _usingCtx4.u(driver.filter(pool.key, {
58
+ include: query.include,
59
+ exclude: query.exclude
60
+ }, host));
61
+ ids = driver.getColumns(filtered.key, host);
62
+ } catch (_) {
63
+ _usingCtx4.e = _;
64
+ } finally {
65
+ _usingCtx4.d();
66
+ }
67
+ const columns = [];
68
+ for (const id of ids) {
69
+ const column = poolColumnOf(registry, id);
70
+ if (column !== void 0) columns.push(column);
71
+ }
72
+ return {
73
+ columns,
74
+ isComplete
75
+ };
76
+ } catch (_) {
77
+ _usingCtx$1.e = _;
78
+ } finally {
79
+ _usingCtx$1.d();
80
+ }
81
+ });
82
+ }
83
+ /**
84
+ * The pool columns `ids` stand for, each looked up by its id as `viewAs` sees the pool, in the order
85
+ * of `ids`; `undefined` for an id that is no column of that pool. Unlike {@link poolColumns}, which
86
+ * lists one of several columns with the same spec, this finds each of them by its id.
87
+ *
88
+ * @throws (from the value) when `viewAs` is not a block of the project
89
+ */
90
+ function poolColumnsById(prjEntry, ids, viewAs) {
91
+ return Computable.make((ctx) => {
92
+ const upstream = poolView(ctx, prjEntry, viewAs);
93
+ if (upstream === void 0) return ids.map(() => void 0);
94
+ const registry = buildColumnRegistry({ upstreamBlockCtxes: upstream });
95
+ return ids.map((id) => {
96
+ try {
97
+ return poolColumnOf(registry, id);
98
+ } catch {
99
+ return;
100
+ }
101
+ });
102
+ });
103
+ }
104
+ /**
105
+ * The pool column `id` stands for: the column of the registry its leaf is, with the spec the id
106
+ * makes of it. `undefined` when the leaf is not a column a block exports, or has no spec yet.
107
+ */
108
+ function poolColumnOf(registry, id) {
109
+ const leaf = extractPObjectId(id);
110
+ const leafRef = poolRefOf(leaf);
111
+ if (leafRef === void 0) return void 0;
112
+ const leafSpec = resolveColumnSpec(registry, leaf);
113
+ if (leafSpec === void 0 || !isPColumnSpec(leafSpec)) return void 0;
114
+ const path = linkerPath(id);
115
+ return {
116
+ columnId: id,
117
+ ...id === leaf ? { ref: leafRef } : {},
118
+ exportName: leafRef.name,
119
+ ...path !== void 0 ? { path } : {},
120
+ producedBy: asBlockId(leafRef.blockId),
121
+ spec: reconstructSpecFromId(leafSpec, id)
122
+ };
123
+ }
124
+ /**
125
+ * The ids of the linker columns a discovered id was reached through, read through the filtered
126
+ * and overridden ids wrapped around it; `undefined` for an id with no discovered layer or no path.
127
+ */
128
+ function linkerPath(id) {
129
+ let key = parseColumnIdSafely(id);
130
+ while (isColumnFilteredKey(key) || isColumnOverriddenKey(key)) key = parseColumnIdSafely(key.source);
131
+ if (!isColumnDiscoveredKey(key) || key.path === void 0 || key.path.length === 0) return void 0;
132
+ return key.path.map((step) => step.column);
133
+ }
134
+ /**
135
+ * The contexts of the blocks whose results the pool holds as `viewAs` sees it: the block and every
136
+ * block above it; by default the last block of the project, which sees every block's results.
137
+ * `undefined` for a project with no blocks.
138
+ *
139
+ * @throws when `viewAs` is not a block of the project
140
+ */
141
+ function poolView(ctx, prjEntry, viewAs) {
142
+ const prj = ctx.accessor(prjEntry).node();
143
+ const structure = notEmpty(prj.getKeyValueAsJson(ProjectStructureKey));
144
+ const blockIds = [...allBlocks(structure)].map((b) => b.id);
145
+ const block = viewAs ?? blockIds.at(-1);
146
+ if (block === void 0) return void 0;
147
+ if (!blockIds.includes(block)) throw new Error(`Block ${block} not found in the project.`);
148
+ return collectUpstreamBlockCtx(ctx, prjEntry, block);
149
+ }
150
+ /** The reference a result-pool column id stands for: the id is that reference as canonical JSON. */
151
+ function poolRefOf(columnId) {
152
+ const parsed = PlRef.safeParse(parseJsonSafely(columnId));
153
+ return parsed.success ? parsed.data : void 0;
154
+ }
155
+ export { poolColumns, poolColumnsById, poolRefOf, poolView };
156
+
157
+ //# sourceMappingURL=pool_columns.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pool_columns.js","names":[],"sources":["../../src/middle_layer/pool_columns.ts"],"sourcesContent":["import { Computable, type ComputableCtx } from \"@milaboratories/computable\";\nimport type { PlTreeEntry, PlTreeNodeAccessor } from \"@milaboratories/pl-tree\";\nimport { notEmpty } from \"@milaboratories/ts-helpers\";\nimport {\n asBlockId,\n extractPObjectId,\n isColumnDiscoveredKey,\n isColumnFilteredKey,\n isColumnOverriddenKey,\n isPColumnSpec,\n parseColumnIdSafely,\n parseJsonSafely,\n PlRef,\n reconstructSpecFromId,\n Services,\n type AnchorEntry,\n type BlockId,\n type ColumnRegistry,\n type ColumnsCollectionDriver,\n type ColumnsCollectionDriverHost,\n type ColumnSelector,\n type ColumnUniversalId,\n type MatchingMode,\n type PColumnSpec,\n type PObjectId,\n type UpstreamBlockCtx,\n} from \"@milaboratories/pl-model-common\";\nimport { buildColumnRegistry, resolveColumnSpec } from \"../js_render/column_registry\";\nimport type { ProjectStructure } from \"../model/project_model\";\nimport { ProjectStructureKey } from \"../model/project_model\";\nimport { allBlocks } from \"../model/project_model_util\";\nimport { collectUpstreamBlockCtx } from \"../pool/upstream_block_ctx\";\nimport type { MiddleLayerEnvironment } from \"./middle_layer\";\n\n/** One column of a project's result pool: its spec and how a block points at it. */\nexport interface PoolColumn {\n /**\n * The id a block's model gets for the column from `ColumnsCollection([\"result_pool\"])`: the\n * `GlobalPObjectId` of an exported column, or, found from anchors, a discovered id around it.\n */\n readonly columnId: ColumnUniversalId;\n /**\n * The reference a block stores in its data or args to point at the column: the object form of\n * `columnId`, set only when `columnId` is the `GlobalPObjectId` of an exported column.\n */\n readonly ref?: PlRef;\n /** The name under which the block exports the column the id comes down to. */\n readonly exportName: string;\n /** Of a discovered id: the ids of the linker columns it was reached through, in order. */\n readonly path?: ColumnUniversalId[];\n /** The block that exports the column the id comes down to. */\n readonly producedBy: BlockId;\n /** The spec the id stands for: the exported spec with what the id changes in it applied. */\n readonly spec: PColumnSpec;\n}\n\n/** The result-pool columns of a project, as {@link poolColumns} lists them. */\nexport interface PoolColumns {\n readonly columns: PoolColumn[];\n /**\n * False while a block whose results the view covers is still being calculated: more columns\n * may come.\n */\n readonly isComplete: boolean;\n}\n\n/** Which columns of the result pool {@link poolColumns} lists. */\nexport interface PoolColumnsQuery {\n /**\n * List the pool as this block sees it: the columns exported by the block and every block above\n * it. Default: as the last block of the project sees it, which is every block's columns.\n */\n readonly viewAs?: BlockId;\n /**\n * Keep only columns matching these selectors, as a block model passes them to\n * `ColumnsCollection([\"result_pool\"]).filter({ include })`.\n */\n readonly include?: ColumnSelector;\n /** Drop columns matching these selectors, as `filter({ exclude })` does. */\n readonly exclude?: ColumnSelector;\n /**\n * List the columns reachable from these columns, through linker columns too, as\n * `ColumnsCollection([\"result_pool\"]).discover({ anchors })` does: with discovered ids.\n */\n readonly anchors?: Record<string, AnchorEntry>;\n /** How axes of a discovered column may match the anchors' (default `enrichment`). */\n readonly mode?: MatchingMode;\n /** The most linker columns between an anchor and a discovered column (default 4). */\n readonly maxHops?: number;\n}\n\n/** What {@link poolColumns} reads besides the project tree. */\nexport type PoolColumnsEnv = Pick<MiddleLayerEnvironment, \"serviceRegistry\">;\n\n/**\n * The columns of a project's result pool with their specs, no data, as a block's model gets them\n * from `ColumnsCollection([\"result_pool\"])`, filtered the way its `filter` does. Computed only when\n * its value is asked for; reads the order of the blocks and the results of the blocks in view.\n *\n * @throws (from the value) when `viewAs` is not a block of the project\n */\nexport function poolColumns(\n prjEntry: PlTreeEntry,\n query: PoolColumnsQuery,\n env: PoolColumnsEnv,\n): Computable<PoolColumns> {\n return Computable.make((ctx) => {\n const upstream = poolView(ctx, prjEntry, query.viewAs);\n if (upstream === undefined) return { columns: [], isComplete: true };\n const registry = buildColumnRegistry({ upstreamBlockCtxes: upstream });\n const host: ColumnsCollectionDriverHost<PlTreeNodeAccessor> = {\n resolveAccessor: () => {\n throw new Error(\"A result pool listing has no accessor sources.\");\n },\n getUpstreamBlockCtxes: () => upstream,\n getSpecDriver: () =>\n notEmpty(env.serviceRegistry.get(Services.PFrameSpec), \"PFrameSpec service\"),\n resolveSpec: (id) => resolveColumnSpec(registry, id),\n };\n const driver: ColumnsCollectionDriver = notEmpty(\n env.serviceRegistry.get(Services.ColumnsCollection),\n \"ColumnsCollection service\",\n );\n\n using pool = driver.create([{ kind: \"result_pool\" }], host);\n const isComplete = driver.isFinal(pool.key);\n let ids: ColumnUniversalId[];\n if (query.anchors !== undefined) {\n using discovered = driver.discover(\n pool.key,\n {\n include: query.include,\n exclude: query.exclude,\n anchors: query.anchors,\n mode: query.mode ?? \"enrichment\",\n maxHops: query.maxHops ?? 4,\n },\n host,\n );\n ids = driver.getColumns(discovered.key, host);\n } else if (query.include === undefined && query.exclude === undefined) {\n ids = driver.getColumns(pool.key, host);\n } else {\n using filtered = driver.filter(\n pool.key,\n { include: query.include, exclude: query.exclude },\n host,\n );\n ids = driver.getColumns(filtered.key, host);\n }\n\n const columns: PoolColumn[] = [];\n for (const id of ids) {\n const column = poolColumnOf(registry, id);\n if (column !== undefined) columns.push(column);\n }\n return { columns, isComplete };\n });\n}\n\n/**\n * The pool columns `ids` stand for, each looked up by its id as `viewAs` sees the pool, in the order\n * of `ids`; `undefined` for an id that is no column of that pool. Unlike {@link poolColumns}, which\n * lists one of several columns with the same spec, this finds each of them by its id.\n *\n * @throws (from the value) when `viewAs` is not a block of the project\n */\nexport function poolColumnsById(\n prjEntry: PlTreeEntry,\n ids: readonly ColumnUniversalId[],\n viewAs: BlockId | undefined,\n): Computable<(PoolColumn | undefined)[]> {\n return Computable.make((ctx) => {\n const upstream = poolView(ctx, prjEntry, viewAs);\n if (upstream === undefined) return ids.map(() => undefined);\n const registry = buildColumnRegistry({ upstreamBlockCtxes: upstream });\n return ids.map((id) => {\n try {\n return poolColumnOf(registry, id);\n } catch {\n // An id whose layers do not fit the column, e.g. a filter of an axis it does not have.\n return undefined;\n }\n });\n });\n}\n\n/**\n * The pool column `id` stands for: the column of the registry its leaf is, with the spec the id\n * makes of it. `undefined` when the leaf is not a column a block exports, or has no spec yet.\n */\nfunction poolColumnOf(\n registry: ColumnRegistry<PlTreeNodeAccessor>,\n id: ColumnUniversalId,\n): PoolColumn | undefined {\n const leaf = extractPObjectId(id);\n const leafRef = poolRefOf(leaf);\n if (leafRef === undefined) return undefined;\n const leafSpec = resolveColumnSpec(registry, leaf);\n if (leafSpec === undefined || !isPColumnSpec(leafSpec)) return undefined;\n const path = linkerPath(id);\n return {\n columnId: id,\n ...(id === leaf ? { ref: leafRef } : {}),\n exportName: leafRef.name,\n ...(path !== undefined ? { path } : {}),\n producedBy: asBlockId(leafRef.blockId),\n spec: reconstructSpecFromId(leafSpec, id),\n };\n}\n\n/**\n * The ids of the linker columns a discovered id was reached through, read through the filtered\n * and overridden ids wrapped around it; `undefined` for an id with no discovered layer or no path.\n */\nfunction linkerPath(id: ColumnUniversalId): ColumnUniversalId[] | undefined {\n let key = parseColumnIdSafely(id);\n while (isColumnFilteredKey(key) || isColumnOverriddenKey(key))\n key = parseColumnIdSafely(key.source);\n if (!isColumnDiscoveredKey(key) || key.path === undefined || key.path.length === 0)\n return undefined;\n return key.path.map((step) => step.column);\n}\n\n/**\n * The contexts of the blocks whose results the pool holds as `viewAs` sees it: the block and every\n * block above it; by default the last block of the project, which sees every block's results.\n * `undefined` for a project with no blocks.\n *\n * @throws when `viewAs` is not a block of the project\n */\nexport function poolView(\n ctx: ComputableCtx,\n prjEntry: PlTreeEntry,\n viewAs: BlockId | undefined,\n): UpstreamBlockCtx<PlTreeNodeAccessor>[] | undefined {\n const prj = ctx.accessor(prjEntry).node();\n const structure = notEmpty(prj.getKeyValueAsJson<ProjectStructure>(ProjectStructureKey));\n const blockIds = [...allBlocks(structure)].map((b) => b.id);\n const block = viewAs ?? blockIds.at(-1);\n if (block === undefined) return undefined;\n if (!blockIds.includes(block)) throw new Error(`Block ${block} not found in the project.`);\n return collectUpstreamBlockCtx(ctx, prjEntry, block);\n}\n\n/** The reference a result-pool column id stands for: the id is that reference as canonical JSON. */\nexport function poolRefOf(columnId: PObjectId): PlRef | undefined {\n const parsed = PlRef.safeParse(parseJsonSafely(columnId));\n return parsed.success ? parsed.data : undefined;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAqGA,SAAgB,YACd,UACA,OACA,KACyB;CACzB,OAAO,WAAW,MAAM,QAAQ;;;GAC9B,MAAM,WAAW,SAAS,KAAK,UAAU,MAAM,MAAM;GACrD,IAAI,aAAa,KAAA,GAAW,OAAO;IAAE,SAAS,CAAC;IAAG,YAAY;GAAK;GACnE,MAAM,WAAW,oBAAoB,EAAE,oBAAoB,SAAS,CAAC;GACrE,MAAM,OAAwD;IAC5D,uBAAuB;KACrB,MAAM,IAAI,MAAM,gDAAgD;IAClE;IACA,6BAA6B;IAC7B,qBACE,SAAS,IAAI,gBAAgB,IAAI,SAAS,UAAU,GAAG,oBAAoB;IAC7E,cAAc,OAAO,kBAAkB,UAAU,EAAE;GACrD;GACA,MAAM,SAAkC,SACtC,IAAI,gBAAgB,IAAI,SAAS,iBAAiB,GAClD,2BACF;GAEA,MAAM,OAAA,YAAA,EAAO,OAAO,OAAO,CAAC,EAAE,MAAM,cAAc,CAAC,GAAG,IAAI,CAAA;GAC1D,MAAM,aAAa,OAAO,QAAQ,KAAK,GAAG;GAC1C,IAAI;GACJ,IAAI,MAAM,YAAY,KAAA,GAAW,IAAA;;IAC/B,MAAM,aAAA,WAAA,EAAa,OAAO,SACxB,KAAK,KACL;KACE,SAAS,MAAM;KACf,SAAS,MAAM;KAC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E;CAC1B,OAAO;EACL,UAAU;EACV,GAAI,OAAO,OAAO,EAAE,KAAK,QAAQ,IAAI,CAAC;EACtC,YAAY,QAAQ;EACpB,GAAI,SAAS,KAAA,IAAY,EAAE,KAAK,IAAI,CAAC;EACrC,YAAY,UAAU,QAAQ,OAAO;EACrC,MAAM,sBAAsB,UAAU,EAAE;CAC1C;AACF;;;;;AAMA,SAAS,WAAW,IAAwD;CAC1E,IAAI,MAAM,oBAAoB,EAAE;CAChC,OAAO,oBAAoB,GAAG,KAAK,sBAAsB,GAAG,GAC1D,MAAM,oBAAoB,IAAI,MAAM;CACtC,IAAI,CAAC,sBAAsB,GAAG,KAAK,IAAI,SAAS,KAAA,KAAa,IAAI,KAAK,WAAW,GAC/E,OAAO,KAAA;CACT,OAAO,IAAI,KAAK,KAAK,SAAS,KAAK,MAAM;AAC3C;;;;;;;;AASA,SAAgB,SACd,KACA,UACA,QACoD;CACpD,MAAM,MAAM,IAAI,SAAS,QAAQ,CAAC,CAAC,KAAK;CACxC,MAAM,YAAY,SAAS,IAAI,kBAAoC,mBAAmB,CAAC;CACvF,MAAM,WAAW,CAAC,GAAG,UAAU,SAAS,CAAC,CAAC,CAAC,KAAK,MAAM,EAAE,EAAE;CAC1D,MAAM,QAAQ,UAAU,SAAS,GAAG,EAAE;CACtC,IAAI,UAAU,KAAA,GAAW,OAAO,KAAA;CAChC,IAAI,CAAC,SAAS,SAAS,KAAK,GAAG,MAAM,IAAI,MAAM,SAAS,MAAM,2BAA2B;CACzF,OAAO,wBAAwB,KAAK,UAAU,KAAK;AACrD;;AAGA,SAAgB,UAAU,UAAwC;CAChE,MAAM,SAAS,MAAM,UAAU,gBAAgB,QAAQ,CAAC;CACxD,OAAO,OAAO,UAAU,OAAO,OAAO,KAAA;AACxC"}
@@ -0,0 +1,82 @@
1
+ const require_usingCtx = require("../_virtual/_@oxc-project_runtime@0.155.0/helpers/esm/usingCtx.cjs");
2
+ const require_column_registry = require("../js_render/column_registry.cjs");
3
+ const require_pool_columns = require("./pool_columns.cjs");
4
+ let _milaboratories_pl_model_common = require("@milaboratories/pl-model-common");
5
+ let _milaboratories_computable = require("@milaboratories/computable");
6
+ // src/middle_layer/pool_frame.ts
7
+ /**
8
+ * What keeps the column `id` stands for from being read; `undefined` for a column ready to read.
9
+ * Its readiness is that of its leaf, the exported column the id comes down to.
10
+ */
11
+ function poolColumnProblem(registry, id) {
12
+ const leafId = (0, _milaboratories_pl_model_common.extractPObjectId)(id);
13
+ const leaf = registry.resolve(leafId);
14
+ if (leaf === void 0) return { issue: "unknown" };
15
+ if (require_column_registry.resolveColumnSpec(registry, leafId) === void 0) return { issue: "notReady" };
16
+ const data = leaf.accessor.traverseOrError({
17
+ field: `${leaf.name}.data`,
18
+ assertFieldType: "Input",
19
+ allowPermanentAbsence: true
20
+ });
21
+ if (data === void 0) return { issue: leaf.accessor.getInputsLocked() ? "noData" : "notReady" };
22
+ if (!data.ok) return {
23
+ issue: "failed",
24
+ message: data.error.message
25
+ };
26
+ if (!data.value.getIsReadyOrError()) return { issue: "notReady" };
27
+ const error = data.value.getError();
28
+ if (error !== void 0) return {
29
+ issue: "failed",
30
+ message: error.getDataAsString() ?? "the data is an error"
31
+ };
32
+ }
33
+ /**
34
+ * A PFrame over columns of a project's result pool, by the ids {@link poolColumns} lists, with no
35
+ * block involved: what reads the values of a pool column. Each column of the frame has the id it
36
+ * was asked by, so values read from it are named after that id, and the spec that id gives, the
37
+ * one {@link poolColumns} lists: an overridden id renames axes in the frame too.
38
+ *
39
+ * Every column must be ready: an unknown column, one whose data is missing, still being calculated
40
+ * or failed, and one whose id filters an axis are refused, and nothing is built.
41
+ *
42
+ * The frame is made when the value is first asked for and lives as long as the computable's state:
43
+ * `resetState()` releases it. Ask for the value once.
44
+ */
45
+ function poolFrame(prjEntry, ids, env) {
46
+ return _milaboratories_computable.Computable.make((ctx) => {
47
+ try {
48
+ var _usingCtx$1 = require_usingCtx.default();
49
+ const registry = require_column_registry.buildColumnRegistry({ upstreamBlockCtxes: require_pool_columns.poolView(ctx, prjEntry, void 0) ?? [] });
50
+ const unique = [...new Set(ids)];
51
+ const refused = unique.flatMap((columnId) => {
52
+ if (require_column_registry.hasAxisFilters(columnId)) return [{
53
+ columnId,
54
+ issue: "filtered"
55
+ }];
56
+ const problem = poolColumnProblem(registry, columnId);
57
+ return problem === void 0 ? [] : [{
58
+ columnId,
59
+ ...problem
60
+ }];
61
+ });
62
+ if (refused.length > 0) return {
63
+ type: "refused",
64
+ refused
65
+ };
66
+ const guard = _usingCtx$1.u(new _milaboratories_pl_model_common.PoolEntryGuard(env.driverKit.pFrameDriver.createPFrame(unique.map((id) => require_column_registry.resolvePFrameColumnById(registry, id)))));
67
+ ctx.addOnDestroy(guard.entry.unref);
68
+ return {
69
+ type: "ok",
70
+ handle: guard.keep().key
71
+ };
72
+ } catch (_) {
73
+ _usingCtx$1.e = _;
74
+ } finally {
75
+ _usingCtx$1.d();
76
+ }
77
+ });
78
+ }
79
+ exports.poolColumnProblem = poolColumnProblem;
80
+ exports.poolFrame = poolFrame;
81
+
82
+ //# sourceMappingURL=pool_frame.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pool_frame.cjs","names":["extractPObjectId","resolveColumnSpec","Computable","buildColumnRegistry","poolView","hasAxisFilters","PoolEntryGuard","resolvePFrameColumnById"],"sources":["../../src/middle_layer/pool_frame.ts"],"sourcesContent":["import { Computable } from \"@milaboratories/computable\";\nimport type { PlTreeEntry, PlTreeNodeAccessor } from \"@milaboratories/pl-tree\";\nimport {\n extractPObjectId,\n PoolEntryGuard,\n type ColumnRegistry,\n type ColumnUniversalId,\n type PFrameHandle,\n} from \"@milaboratories/pl-model-common\";\nimport {\n buildColumnRegistry,\n hasAxisFilters,\n resolveColumnSpec,\n resolvePFrameColumnById,\n} from \"../js_render/column_registry\";\nimport type { InternalPFrameDriver } from \"../pool/driver\";\nimport { poolView } from \"./pool_columns\";\n\n/**\n * Why a column of the result pool cannot be read:\n * - `unknown`: no block of the project exports a column with this id;\n * - `noData`: the column has a spec but no data, e.g. it comes from a block's pre-run only, or its\n * block has not run;\n * - `notReady`: its spec or data is still being calculated;\n * - `failed`: its data is an error.\n */\nexport type PoolColumnIssue = \"unknown\" | \"noData\" | \"notReady\" | \"failed\";\n\n/** What keeps a column of the result pool from being read, as {@link poolColumnProblem} says. */\nexport interface PoolColumnProblem {\n readonly issue: PoolColumnIssue;\n /** The error of a `failed` column. */\n readonly message?: string;\n}\n\n/**\n * What keeps the column `id` stands for from being read; `undefined` for a column ready to read.\n * Its readiness is that of its leaf, the exported column the id comes down to.\n */\nexport function poolColumnProblem(\n registry: ColumnRegistry<PlTreeNodeAccessor>,\n id: ColumnUniversalId,\n): PoolColumnProblem | undefined {\n const leafId = extractPObjectId(id);\n const leaf = registry.resolve(leafId);\n if (leaf === undefined) return { issue: \"unknown\" };\n if (resolveColumnSpec(registry, leafId) === undefined) return { issue: \"notReady\" };\n const data = leaf.accessor.traverseOrError({\n field: `${leaf.name}.data`,\n assertFieldType: \"Input\",\n allowPermanentAbsence: true,\n });\n // A result list still open may get the field yet.\n if (data === undefined) return { issue: leaf.accessor.getInputsLocked() ? \"noData\" : \"notReady\" };\n if (!data.ok) return { issue: \"failed\", message: data.error.message };\n if (!data.value.getIsReadyOrError()) return { issue: \"notReady\" };\n const error = data.value.getError();\n if (error !== undefined)\n return { issue: \"failed\", message: error.getDataAsString() ?? \"the data is an error\" };\n return undefined;\n}\n\n/**\n * Why {@link poolFrame} refused a column: a {@link PoolColumnIssue}, or `filtered` for an id that\n * filters an axis, whose values would be those of the whole column it filters.\n */\nexport type PoolFrameIssue = PoolColumnIssue | \"filtered\";\n\n/** A column {@link poolFrame} refused, and why. */\nexport interface PoolFrameRefusal {\n readonly columnId: ColumnUniversalId;\n readonly issue: PoolFrameIssue;\n /** The error of a `failed` column. */\n readonly message?: string;\n}\n\n/**\n * What {@link poolFrame} computes: the handle of the frame, or, with nothing built, the columns it\n * refused.\n */\nexport type PoolFrame =\n | { readonly type: \"ok\"; readonly handle: PFrameHandle }\n | { readonly type: \"refused\"; readonly refused: readonly PoolFrameRefusal[] };\n\n/** What {@link poolFrame} uses besides the project tree: the driver that builds the frame. */\nexport type PoolFrameEnv = {\n readonly driverKit: { readonly pFrameDriver: Pick<InternalPFrameDriver, \"createPFrame\"> };\n};\n\n/**\n * A PFrame over columns of a project's result pool, by the ids {@link poolColumns} lists, with no\n * block involved: what reads the values of a pool column. Each column of the frame has the id it\n * was asked by, so values read from it are named after that id, and the spec that id gives, the\n * one {@link poolColumns} lists: an overridden id renames axes in the frame too.\n *\n * Every column must be ready: an unknown column, one whose data is missing, still being calculated\n * or failed, and one whose id filters an axis are refused, and nothing is built.\n *\n * The frame is made when the value is first asked for and lives as long as the computable's state:\n * `resetState()` releases it. Ask for the value once.\n */\nexport function poolFrame(\n prjEntry: PlTreeEntry,\n ids: readonly ColumnUniversalId[],\n env: PoolFrameEnv,\n): Computable<PoolFrame> {\n return Computable.make((ctx): PoolFrame => {\n const registry = buildColumnRegistry({\n upstreamBlockCtxes: poolView(ctx, prjEntry, undefined) ?? [],\n });\n const unique = [...new Set(ids)];\n const refused = unique.flatMap((columnId): PoolFrameRefusal[] => {\n if (hasAxisFilters(columnId)) return [{ columnId, issue: \"filtered\" }];\n const problem = poolColumnProblem(registry, columnId);\n return problem === undefined ? [] : [{ columnId, ...problem }];\n });\n if (refused.length > 0) return { type: \"refused\", refused };\n\n using guard = new PoolEntryGuard(\n env.driverKit.pFrameDriver.createPFrame(\n unique.map((id) => resolvePFrameColumnById(registry, id)),\n ),\n );\n ctx.addOnDestroy(guard.entry.unref);\n return { type: \"ok\", handle: guard.keep().key };\n });\n}\n"],"mappings":";;;;;;;;;;AAuCA,SAAgB,kBACd,UACA,IAC+B;CAC/B,MAAM,UAAA,GAASA,gCAAAA,iBAAAA,CAAiB,EAAE;CAClC,MAAM,OAAO,SAAS,QAAQ,MAAM;CACpC,IAAI,SAAS,KAAA,GAAW,OAAO,EAAE,OAAO,U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OAAOC,wBAAAA,wBAAwB,UAAU,EAAE,CAAC,CAC1D,CACF,CAAA;GACA,IAAI,aAAa,MAAM,MAAM,KAAK;GAClC,OAAO;IAAE,MAAM;IAAM,QAAQ,MAAM,KAAK,CAAC,CAAC;GAAI;;;;;;CAChD,CAAC;AACH"}
@@ -0,0 +1,37 @@
1
+ import "../pool/driver.js";
2
+ import { ColumnRegistry, ColumnUniversalId, PFrameHandle } from "@milaboratories/pl-model-common";
3
+ import { Computable } from "@milaboratories/computable";
4
+ import { PlTreeNodeAccessor } from "@milaboratories/pl-tree";
5
+ /**
6
+ * Why a column of the result pool cannot be read:
7
+ * - `unknown`: no block of the project exports a column with this id;
8
+ * - `noData`: the column has a spec but no data, e.g. it comes from a block's pre-run only, or its
9
+ * block has not run;
10
+ * - `notReady`: its spec or data is still being calculated;
11
+ * - `failed`: its data is an error.
12
+ */
13
+ export type PoolColumnIssue = "unknown" | "noData" | "notReady" | "failed";
14
+ /**
15
+ * Why {@link poolFrame} refused a column: a {@link PoolColumnIssue}, or `filtered` for an id that
16
+ * filters an axis, whose values would be those of the whole column it filters.
17
+ */
18
+ export type PoolFrameIssue = PoolColumnIssue | "filtered";
19
+ /** A column {@link poolFrame} refused, and why. */
20
+ export interface PoolFrameRefusal {
21
+ readonly columnId: ColumnUniversalId;
22
+ readonly issue: PoolFrameIssue;
23
+ /** The error of a `failed` column. */
24
+ readonly message?: string;
25
+ }
26
+ /**
27
+ * What {@link poolFrame} computes: the handle of the frame, or, with nothing built, the columns it
28
+ * refused.
29
+ */
30
+ export type PoolFrame = {
31
+ readonly type: "ok";
32
+ readonly handle: PFrameHandle;
33
+ } | {
34
+ readonly type: "refused";
35
+ readonly refused: readonly PoolFrameRefusal[];
36
+ };
37
+ //# sourceMappingURL=pool_frame.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pool_frame.d.ts","names":[],"sources":["../../src/middle_layer/pool_frame.ts"],"mappings":";;;;;;;;;;;;YA0BY;;;;;YAwCA,iBAAiB;;iBAGZ;WACN,UAAU;WACV,OAAO;;WAEP;;;;;;YAOC;WACG;WAAqB,QAAQ;;WAC7B;WAA0B,kBAAkB"}