@platforma-sdk/model 1.91.0 → 1.94.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 (39) hide show
  1. package/dist/components/PlDatasetSelector/build_dataset_options.cjs +43 -33
  2. package/dist/components/PlDatasetSelector/build_dataset_options.cjs.map +1 -1
  3. package/dist/components/PlDatasetSelector/build_dataset_options.d.ts +6 -2
  4. package/dist/components/PlDatasetSelector/build_dataset_options.d.ts.map +1 -1
  5. package/dist/components/PlDatasetSelector/build_dataset_options.js +46 -36
  6. package/dist/components/PlDatasetSelector/build_dataset_options.js.map +1 -1
  7. package/dist/components/PlDatasetSelector/dataset_selection.cjs.map +1 -1
  8. package/dist/components/PlDatasetSelector/dataset_selection.d.ts +13 -4
  9. package/dist/components/PlDatasetSelector/dataset_selection.d.ts.map +1 -1
  10. package/dist/components/PlDatasetSelector/dataset_selection.js.map +1 -1
  11. package/dist/components/PlDatasetSelector/enrichment_discovery.cjs +20 -26
  12. package/dist/components/PlDatasetSelector/enrichment_discovery.cjs.map +1 -1
  13. package/dist/components/PlDatasetSelector/enrichment_discovery.js +22 -28
  14. package/dist/components/PlDatasetSelector/enrichment_discovery.js.map +1 -1
  15. package/dist/components/PlDatasetSelector/filter_discovery.cjs +6 -14
  16. package/dist/components/PlDatasetSelector/filter_discovery.cjs.map +1 -1
  17. package/dist/components/PlDatasetSelector/filter_discovery.d.ts +5 -10
  18. package/dist/components/PlDatasetSelector/filter_discovery.d.ts.map +1 -1
  19. package/dist/components/PlDatasetSelector/filter_discovery.js +8 -13
  20. package/dist/components/PlDatasetSelector/filter_discovery.js.map +1 -1
  21. package/dist/components/PlDatasetSelector/index.cjs +0 -1
  22. package/dist/components/PlDatasetSelector/index.d.ts +3 -3
  23. package/dist/components/PlDatasetSelector/index.js +2 -2
  24. package/dist/components/index.cjs +0 -1
  25. package/dist/components/index.d.ts +3 -3
  26. package/dist/components/index.js +2 -2
  27. package/dist/index.cjs +0 -1
  28. package/dist/index.d.ts +3 -3
  29. package/dist/index.js +2 -2
  30. package/dist/package.cjs +1 -1
  31. package/dist/package.js +1 -1
  32. package/package.json +7 -7
  33. package/src/columns/__test_helpers__/collection_driver.ts +45 -5
  34. package/src/components/PlDatasetSelector/build_dataset_options.test.ts +195 -0
  35. package/src/components/PlDatasetSelector/build_dataset_options.ts +86 -63
  36. package/src/components/PlDatasetSelector/dataset_selection.ts +14 -4
  37. package/src/components/PlDatasetSelector/enrichment_discovery.ts +26 -35
  38. package/src/components/PlDatasetSelector/filter_discovery.test.ts +16 -53
  39. package/src/components/PlDatasetSelector/filter_discovery.ts +10 -20
@@ -1,14 +1,10 @@
1
- const require_providers = require("../../columns/column_providers/providers.cjs");
2
- const require_index = require("../../columns/column_providers/index.cjs");
1
+ const require_derive_distinct_labels = require("../../labels/derive_distinct_labels.cjs");
2
+ const require_columns_collection = require("../../columns/columns_collection.cjs");
3
3
  require("../../columns/index.cjs");
4
4
  const require_filter_discovery = require("./filter_discovery.cjs");
5
5
  const require_enrichment_discovery = require("./enrichment_discovery.cjs");
6
6
  let _milaboratories_pl_model_common = require("@milaboratories/pl-model-common");
7
7
  // src/components/PlDatasetSelector/build_dataset_options.ts
8
- function toPredicate(opt) {
9
- if (opt === void 0) return () => true;
10
- return typeof opt === "function" ? opt : (0, _milaboratories_pl_model_common.multiColumnSelectorsToPredicate)(opt);
11
- }
12
8
  /**
13
9
  * Usage:
14
10
  * ```ts
@@ -16,43 +12,57 @@ function toPredicate(opt) {
16
12
  * ```
17
13
  */
18
14
  function buildDatasetOptions(ctx, opts) {
19
- const primaryPredicate = toPredicate(opts?.primary);
15
+ const pool = require_columns_collection.ColumnsCollection(["result_pool"], { ctx: ctx.ctx });
16
+ const datasets = findDatasets(pool, opts?.primary).flatMap((column) => {
17
+ const producer = (0, _milaboratories_pl_model_common.columnProducer)(column.id);
18
+ return producer === void 0 ? [] : [{
19
+ column,
20
+ producer
21
+ }];
22
+ });
23
+ if (datasets.length === 0) return [];
24
+ const labels = require_derive_distinct_labels.deriveDistinctLabels(datasets.map(({ column }) => column.getSpec()));
25
+ const requireEnrichments = opts?.requireEnrichments ?? true;
20
26
  const filterPredicate = toPredicate(opts?.filter);
21
- const options = ctx.resultPool.getOptions((spec) => (0, _milaboratories_pl_model_common.isPColumnSpec)(spec) && primaryPredicate(spec), { refsWithEnrichments: opts?.requireEnrichments ?? true });
22
- if (options.length === 0) return [];
23
- const refMap = require_filter_discovery.buildRefMap(ctx.resultPool.getSpecs().entries);
24
- const withEnrichments = opts?.withEnrichments ?? false;
25
- const filterSource = require_providers.ColumnsProvider(ctx.ctx.getUpstreamBlockCtx());
26
- const enrichmentSources = withEnrichments ? require_index.getCtxProviders(ctx) : void 0;
27
- return options.map((primary) => {
28
- const datasetSpec = ctx.resultPool.getPColumnSpecByRef(primary.ref);
29
- if (!datasetSpec) return { primary };
30
- const filterMatches = require_filter_discovery.findFilterColumns({
31
- sources: [filterSource],
27
+ const withEnrichments = opts?.withEnrichments;
28
+ const enrichmentSearch = withEnrichments === void 0 ? void 0 : {
29
+ sources: [require_columns_collection.ColumnsCollection(["current_block", pool], { ctx: ctx.ctx })],
30
+ maxHops: opts?.enrichmentMaxHops,
31
+ ...typeof withEnrichments === "function" ? { predicate: withEnrichments } : { include: withEnrichments }
32
+ };
33
+ return datasets.map(({ column, producer }, i) => {
34
+ const datasetSpec = column.getSpec();
35
+ const primary = {
36
+ ref: (0, _milaboratories_pl_model_common.createPlRef)(producer.blockId, producer.name, requireEnrichments),
37
+ label: labels[i]
38
+ };
39
+ const filters = require_filter_discovery.filterMatchesToOptions(require_filter_discovery.findFilterColumns({
40
+ sources: [pool],
32
41
  anchorSpec: datasetSpec
33
- }).filter((m) => filterPredicate(m.getSpec()));
34
- const filters = filterMatches.length === 0 ? void 0 : require_filter_discovery.filterMatchesToOptions(filterMatches, {
35
- refsByObjectId: refMap,
42
+ }).filter((match) => filterPredicate(match.getSpec())), {
36
43
  datasetSpec,
37
44
  labelOptions: opts?.labelOptions
38
45
  });
39
- let enrichments;
40
- if (enrichmentSources && withEnrichments) {
41
- const enrichmentVariants = require_enrichment_discovery.findEnrichmentColumns({
42
- sources: enrichmentSources,
43
- anchorSpec: datasetSpec,
44
- maxHops: opts?.enrichmentMaxHops,
45
- ...typeof withEnrichments === "function" ? { predicate: withEnrichments } : { include: withEnrichments }
46
- });
47
- if (enrichmentVariants.length > 0) enrichments = require_enrichment_discovery.enrichmentVariantsToRefs(enrichmentVariants, opts?.labelOptions);
48
- }
46
+ const enrichments = enrichmentSearch === void 0 ? [] : require_enrichment_discovery.labelEnrichments(require_enrichment_discovery.findEnrichmentColumns({
47
+ ...enrichmentSearch,
48
+ anchorSpec: datasetSpec
49
+ }), opts?.labelOptions);
49
50
  return {
50
51
  primary,
51
- ...filters !== void 0 && filters.length > 0 ? { filters } : {},
52
- ...enrichments !== void 0 && enrichments.length > 0 ? { enrichments } : {}
52
+ ...filters.length > 0 ? { filters } : {},
53
+ ...enrichments.length > 0 ? { enrichments } : {}
53
54
  };
54
55
  });
55
56
  }
57
+ function toPredicate(opt) {
58
+ if (opt === void 0) return () => true;
59
+ return typeof opt === "function" ? opt : (0, _milaboratories_pl_model_common.multiColumnSelectorsToPredicate)(opt);
60
+ }
61
+ function findDatasets(pool, primary) {
62
+ if (primary === void 0) return pool.getColumns();
63
+ if (typeof primary === "function") return pool.getColumns().filter((column) => primary(column.getSpec()));
64
+ return pool.filter({ include: primary }).getColumns();
65
+ }
56
66
  exports.buildDatasetOptions = buildDatasetOptions;
57
67
 
58
68
  //# sourceMappingURL=build_dataset_options.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"build_dataset_options.cjs","names":["multiColumnSelectorsToPredicate","isPColumnSpec","buildRefMap","ColumnsProvider","getCtxProviders","findFilterColumns","filterMatchesToOptions","findEnrichmentColumns","enrichmentVariantsToRefs"],"sources":["../../../src/components/PlDatasetSelector/build_dataset_options.ts"],"sourcesContent":["import type { MultiColumnSelector, Option, PObjectSpec } from \"@milaboratories/pl-model-common\";\nimport { isPColumnSpec, multiColumnSelectorsToPredicate } from \"@milaboratories/pl-model-common\";\nimport type { DeriveLabelsOptions } from \"../../labels/derive_distinct_labels\";\nimport type { RenderCtxBase } from \"../../render\";\nimport type { DatasetOption } from \"./dataset_selection\";\nimport { buildRefMap, filterMatchesToOptions, findFilterColumns } from \"./filter_discovery\";\nimport { enrichmentVariantsToRefs, findEnrichmentColumns } from \"./enrichment_discovery\";\nimport { ColumnsProvider, getCtxProviders } from \"../../columns\";\n\ntype SpecPredicateOption =\n | MultiColumnSelector\n | MultiColumnSelector[]\n | ((spec: PObjectSpec) => boolean);\n\nfunction toPredicate(opt: SpecPredicateOption | undefined): (spec: PObjectSpec) => boolean {\n if (opt === undefined) return () => true;\n return typeof opt === \"function\" ? opt : multiColumnSelectorsToPredicate(opt);\n}\n\nexport type BuildDatasetOptions = {\n /** Which result pool columns qualify as datasets. Defaults to all. */\n primary?: SpecPredicateOption;\n /**\n * Restricts which result pool columns are considered as filters. Intersected\n * with the built-in `pl7.app/isSubset: \"true\"` constraint. Defaults to\n * accept-all.\n */\n filter?: SpecPredicateOption;\n /**\n * Formatting options forwarded to label derivation for both filter and\n * enrichment rows. `formatters.native` on the filter path is overridden\n * — see `FilterMatchOptions.labelOptions`.\n */\n labelOptions?: DeriveLabelsOptions;\n /**\n * Enables enrichment discovery and filters hits attached to\n * `DatasetOption.enrichments`. Use `() => true` to accept all; omit to disable.\n */\n withEnrichments?: SpecPredicateOption;\n /** Maximum linker hops considered. Only used when `withEnrichments` is set. */\n enrichmentMaxHops?: number;\n /**\n * Whether the dataset refs in the returned options carry `requireEnrichments: true`.\n * A block that stores such a ref depends on every block that enriches the dataset.\n * Set `false` for a block that only needs the dataset and its filters. Defaults to `true`.\n */\n requireEnrichments?: boolean;\n};\n\n/**\n * Usage:\n * ```ts\n * .output(\"datasetOptions\", (ctx) => buildDatasetOptions(ctx))\n * ```\n */\nexport function buildDatasetOptions(\n ctx: RenderCtxBase,\n opts?: BuildDatasetOptions,\n): DatasetOption[] | undefined {\n const primaryPredicate = toPredicate(opts?.primary);\n const filterPredicate = toPredicate(opts?.filter);\n\n const options = ctx.resultPool.getOptions(\n (spec) => isPColumnSpec(spec) && primaryPredicate(spec),\n {\n refsWithEnrichments: opts?.requireEnrichments ?? true,\n },\n );\n if (options.length === 0) return [];\n\n const refMap = buildRefMap(ctx.resultPool.getSpecs().entries);\n\n const withEnrichments = opts?.withEnrichments ?? false;\n const filterSource = ColumnsProvider(ctx.ctx.getUpstreamBlockCtx());\n // Hoist providers once: getCtxProviders walks the full output tree, so\n // calling it per dataset option would be O(N × tree).\n const enrichmentSources = withEnrichments ? getCtxProviders(ctx) : undefined;\n\n return options.map((primary: Option): DatasetOption => {\n const datasetSpec = ctx.resultPool.getPColumnSpecByRef(primary.ref);\n if (!datasetSpec) return { primary };\n\n const filterMatches = findFilterColumns({\n sources: [filterSource],\n anchorSpec: datasetSpec,\n }).filter((m) => filterPredicate(m.getSpec()!));\n\n const filters =\n filterMatches.length === 0\n ? undefined\n : filterMatchesToOptions(filterMatches, {\n refsByObjectId: refMap,\n datasetSpec,\n labelOptions: opts?.labelOptions,\n });\n\n let enrichments;\n if (enrichmentSources && withEnrichments) {\n const enrichmentVariants = findEnrichmentColumns({\n sources: enrichmentSources,\n anchorSpec: datasetSpec,\n maxHops: opts?.enrichmentMaxHops,\n ...(typeof withEnrichments === \"function\"\n ? { predicate: withEnrichments }\n : { include: withEnrichments }),\n });\n if (enrichmentVariants.length > 0) {\n enrichments = enrichmentVariantsToRefs(enrichmentVariants, opts?.labelOptions);\n }\n }\n\n return {\n primary,\n ...(filters !== undefined && filters.length > 0 ? { filters } : {}),\n ...(enrichments !== undefined && enrichments.length > 0 ? { enrichments } : {}),\n };\n });\n}\n"],"mappings":";;;;;;;AAcA,SAAS,YAAY,KAAsE;CACzF,IAAI,QAAQ,KAAA,GAAW,aAAa;CACpC,OAAO,OAAO,QAAQ,aAAa,OAAA,GAAMA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yBAAyB,oBAAoB,MAAM,YAAY;EAEjF;EAEA,OAAO;GACL;GACA,GAAI,YAAY,KAAA,KAAa,QAAQ,SAAS,IAAI,EAAE,QAAQ,IAAI,CAAC;GACjE,GAAI,gBAAgB,KAAA,KAAa,YAAY,SAAS,IAAI,EAAE,YAAY,IAAI,CAAC;EAC/E;CACF,CAAC;AACH"}
1
+ {"version":3,"file":"build_dataset_options.cjs","names":["ColumnsCollection","columnProducer","deriveDistinctLabels","createPlRef","filterMatchesToOptions","findFilterColumns","labelEnrichments","findEnrichmentColumns","multiColumnSelectorsToPredicate"],"sources":["../../../src/components/PlDatasetSelector/build_dataset_options.ts"],"sourcesContent":["import type { MultiColumnSelector, Option, PObjectSpec } from \"@milaboratories/pl-model-common\";\nimport {\n columnProducer,\n createPlRef,\n multiColumnSelectorsToPredicate,\n} from \"@milaboratories/pl-model-common\";\nimport type { ColumnRecipe } from \"../../columns\";\nimport { ColumnsCollection } from \"../../columns\";\nimport {\n deriveDistinctLabels,\n type DeriveLabelsOptions,\n} from \"../../labels/derive_distinct_labels\";\nimport type { RenderCtxBase } from \"../../render\";\nimport type { DatasetOption } from \"./dataset_selection\";\nimport { filterMatchesToOptions, findFilterColumns } from \"./filter_discovery\";\nimport { findEnrichmentColumns, labelEnrichments } from \"./enrichment_discovery\";\n\nexport type BuildDatasetOptions = {\n /**\n * Which result pool columns qualify as datasets. Defaults to all. A selector\n * is matched by the host; a predicate reads the spec of every result pool\n * column, so prefer a selector when it can say the same.\n */\n primary?: SpecPredicateOption;\n /**\n * Restricts which result pool columns are considered as filters. Intersected\n * with the built-in `pl7.app/isSubset: \"true\"` constraint. Defaults to\n * accept-all.\n */\n filter?: SpecPredicateOption;\n /**\n * Formatting options forwarded to label derivation for both filter and\n * enrichment rows. `formatters.native` on the filter path is overridden\n * — see `FilterMatchOptions.labelOptions`.\n */\n labelOptions?: DeriveLabelsOptions;\n /**\n * Enables enrichment discovery and filters hits attached to\n * `DatasetOption.enrichments`. Use `() => true` to accept all; omit to disable.\n */\n withEnrichments?: SpecPredicateOption;\n /** Maximum linker hops considered. Only used when `withEnrichments` is set. */\n enrichmentMaxHops?: number;\n /**\n * Whether the dataset refs in the returned options carry `requireEnrichments: true`.\n * A block that stores such a ref depends on every block that enriches the dataset.\n * Set `false` for a block that only needs the dataset and its filters. Defaults to `true`.\n */\n requireEnrichments?: boolean;\n};\n\n/**\n * Usage:\n * ```ts\n * .output(\"datasetOptions\", (ctx) => buildDatasetOptions(ctx))\n * ```\n */\nexport function buildDatasetOptions(\n ctx: RenderCtxBase,\n opts?: BuildDatasetOptions,\n): DatasetOption[] | undefined {\n const pool = ColumnsCollection([\"result_pool\"], { ctx: ctx.ctx });\n\n // A dataset is stored as a reference to a block output, so only a column\n // that is one can be offered.\n const datasets = findDatasets(pool, opts?.primary).flatMap((column) => {\n const producer = columnProducer(column.id);\n return producer === undefined ? [] : [{ column, producer }];\n });\n if (datasets.length === 0) return [];\n\n const labels = deriveDistinctLabels(datasets.map(({ column }) => column.getSpec()));\n const requireEnrichments = opts?.requireEnrichments ?? true;\n const filterPredicate = toPredicate(opts?.filter);\n\n const withEnrichments = opts?.withEnrichments;\n const enrichmentSearch =\n withEnrichments === undefined\n ? undefined\n : {\n // Enrichments are also looked for among this block's own columns.\n // Built once: every dataset searches the same set.\n sources: [ColumnsCollection([\"current_block\", pool], { ctx: ctx.ctx })],\n maxHops: opts?.enrichmentMaxHops,\n ...(typeof withEnrichments === \"function\"\n ? { predicate: withEnrichments }\n : { include: withEnrichments }),\n };\n\n return datasets.map(({ column, producer }, i): DatasetOption => {\n const datasetSpec = column.getSpec();\n const primary: Option = {\n ref: createPlRef(producer.blockId, producer.name, requireEnrichments),\n label: labels[i],\n };\n\n const filters = filterMatchesToOptions(\n findFilterColumns({ sources: [pool], anchorSpec: datasetSpec }).filter((match) =>\n filterPredicate(match.getSpec()),\n ),\n { datasetSpec, labelOptions: opts?.labelOptions },\n );\n\n const enrichments =\n enrichmentSearch === undefined\n ? []\n : labelEnrichments(\n findEnrichmentColumns({ ...enrichmentSearch, anchorSpec: datasetSpec }),\n opts?.labelOptions,\n );\n\n return {\n primary,\n ...(filters.length > 0 ? { filters } : {}),\n ...(enrichments.length > 0 ? { enrichments } : {}),\n };\n });\n}\n\n// Internals\n\ntype SpecPredicateOption =\n | MultiColumnSelector\n | MultiColumnSelector[]\n | ((spec: PObjectSpec) => boolean);\n\nfunction toPredicate(opt: SpecPredicateOption | undefined): (spec: PObjectSpec) => boolean {\n if (opt === undefined) return () => true;\n return typeof opt === \"function\" ? opt : multiColumnSelectorsToPredicate(opt);\n}\n\nfunction findDatasets(\n pool: ColumnsCollection,\n primary: SpecPredicateOption | undefined,\n): ColumnRecipe[] {\n if (primary === undefined) return pool.getColumns();\n if (typeof primary === \"function\") {\n return pool.getColumns().filter((column) => primary(column.getSpec()));\n }\n return pool.filter({ include: primary }).getColumns();\n}\n"],"mappings":";;;;;;;;;;;;;AAyDA,SAAgB,oBACd,KACA,MAC6B;CAC7B,MAAM,OAAOA,2BAAAA,kBAAkB,CAAC,aAAa,GAAG,EAAE,KAAK,IAAI,IAAI,CAAC;CAIhE,MAAM,WAAW,aAAa,MAAM,MAAM,OAAO,CAAC,CAAC,SAAS,WAAW;EACrE,MAAM,YAAA,GAAWC,gCAAAA,eAAAA,CAAe,OAAO,EAAE;EACzC,OAAO,aAAa,KAAA,IAAY,CAAC,IAAI,CAAC;GAAE;GAAQ;EAAS,CAAC;CAC5D,CAAC;CACD,IAAI,SAAS,WAAW,GAAG,OAAO,CAAC;CAEnC,MAAM,SAASC,+BAAAA,qBAAqB,SAAS,KAAK,EAAE,aAAa,OAAO,QAAQ,CAAC,CAAC;CAClF,MAAM,qBAAqB,MAAM,sBAAsB;CACvD,MAAM,kBAAkB,YAAY,MAAM,MAAM;CAEhD,MAAM,kBAAkB,MAAM;CAC9B,MAAM,mBACJ,oBAAoB,KAAA,IAChB,KAAA,IACA;EAGE,SAAS,CAACF,2BAAAA,kBAAkB,CAAC,i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WAAW;AACtD"}
@@ -3,9 +3,12 @@ import { RenderCtxBase } from "../../render/api.js";
3
3
  import "../../render/index.js";
4
4
  import { DatasetOption } from "./dataset_selection.js";
5
5
  import { MultiColumnSelector, PObjectSpec } from "@milaboratories/pl-model-common";
6
- type SpecPredicateOption = MultiColumnSelector | MultiColumnSelector[] | ((spec: PObjectSpec) => boolean);
7
6
  export type BuildDatasetOptions = {
8
- /** Which result pool columns qualify as datasets. Defaults to all. */
7
+ /**
8
+ * Which result pool columns qualify as datasets. Defaults to all. A selector
9
+ * is matched by the host; a predicate reads the spec of every result pool
10
+ * column, so prefer a selector when it can say the same.
11
+ */
9
12
  primary?: SpecPredicateOption;
10
13
  /**
11
14
  * Restricts which result pool columns are considered as filters. Intersected
@@ -40,5 +43,6 @@ export type BuildDatasetOptions = {
40
43
  * ```
41
44
  */
42
45
  export declare function buildDatasetOptions(ctx: RenderCtxBase, opts?: BuildDatasetOptions): DatasetOption[] | undefined;
46
+ type SpecPredicateOption = MultiColumnSelector | MultiColumnSelector[] | ((spec: PObjectSpec) => boolean);
43
47
  export {};
44
48
  //# sourceMappingURL=build_dataset_options.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"build_dataset_options.d.ts","names":[],"sources":["../../../src/components/PlDatasetSelector/build_dataset_options.ts"],"mappings":";;;;;KASK,sBACD,sBACA,0BACE,MAAM;YAOA;;EAEV,UAAU;;;;;;EAMV,SAAS;;;;;;EAMT,eAAe;;;;;EAKf,kBAAkB;;EAElB;;;;;;EAMA;;;;;;;;wBASc,oBACd,KAAK,eACL,OAAO,sBACN"}
1
+ {"version":3,"file":"build_dataset_options.d.ts","names":[],"sources":["../../../src/components/PlDatasetSelector/build_dataset_options.ts"],"mappings":";;;;;YAiBY;;;;;;EAMV,UAAU;;;;;;EAMV,SAAS;;;;;;EAMT,eAAe;;;;;EAKf,kBAAkB;;EAElB;;;;;;EAMA;;;;;;;;wBASc,oBACd,KAAK,eACL,OAAO,sBACN;KA6DE,sBACD,sBACA,0BACE,MAAM"}
@@ -1,14 +1,10 @@
1
- import { ColumnsProvider } from "../../columns/column_providers/providers.js";
2
- import { getCtxProviders } from "../../columns/column_providers/index.js";
1
+ import { deriveDistinctLabels } from "../../labels/derive_distinct_labels.js";
2
+ import { ColumnsCollection } from "../../columns/columns_collection.js";
3
3
  import "../../columns/index.js";
4
- import { buildRefMap, filterMatchesToOptions, findFilterColumns } from "./filter_discovery.js";
5
- import { enrichmentVariantsToRefs, findEnrichmentColumns } from "./enrichment_discovery.js";
6
- import { isPColumnSpec, multiColumnSelectorsToPredicate } from "@milaboratories/pl-model-common";
4
+ import { filterMatchesToOptions, findFilterColumns } from "./filter_discovery.js";
5
+ import { findEnrichmentColumns, labelEnrichments } from "./enrichment_discovery.js";
6
+ import { columnProducer, createPlRef, multiColumnSelectorsToPredicate } from "@milaboratories/pl-model-common";
7
7
  // src/components/PlDatasetSelector/build_dataset_options.ts
8
- function toPredicate(opt) {
9
- if (opt === void 0) return () => true;
10
- return typeof opt === "function" ? opt : multiColumnSelectorsToPredicate(opt);
11
- }
12
8
  /**
13
9
  * Usage:
14
10
  * ```ts
@@ -16,43 +12,57 @@ function toPredicate(opt) {
16
12
  * ```
17
13
  */
18
14
  function buildDatasetOptions(ctx, opts) {
19
- const primaryPredicate = toPredicate(opts?.primary);
15
+ const pool = ColumnsCollection(["result_pool"], { ctx: ctx.ctx });
16
+ const datasets = findDatasets(pool, opts?.primary).flatMap((column) => {
17
+ const producer = columnProducer(column.id);
18
+ return producer === void 0 ? [] : [{
19
+ column,
20
+ producer
21
+ }];
22
+ });
23
+ if (datasets.length === 0) return [];
24
+ const labels = deriveDistinctLabels(datasets.map(({ column }) => column.getSpec()));
25
+ const requireEnrichments = opts?.requireEnrichments ?? true;
20
26
  const filterPredicate = toPredicate(opts?.filter);
21
- const options = ctx.resultPool.getOptions((spec) => isPColumnSpec(spec) && primaryPredicate(spec), { refsWithEnrichments: opts?.requireEnrichments ?? true });
22
- if (options.length === 0) return [];
23
- const refMap = buildRefMap(ctx.resultPool.getSpecs().entries);
24
- const withEnrichments = opts?.withEnrichments ?? false;
25
- const filterSource = ColumnsProvider(ctx.ctx.getUpstreamBlockCtx());
26
- const enrichmentSources = withEnrichments ? getCtxProviders(ctx) : void 0;
27
- return options.map((primary) => {
28
- const datasetSpec = ctx.resultPool.getPColumnSpecByRef(primary.ref);
29
- if (!datasetSpec) return { primary };
30
- const filterMatches = findFilterColumns({
31
- sources: [filterSource],
27
+ const withEnrichments = opts?.withEnrichments;
28
+ const enrichmentSearch = withEnrichments === void 0 ? void 0 : {
29
+ sources: [ColumnsCollection(["current_block", pool], { ctx: ctx.ctx })],
30
+ maxHops: opts?.enrichmentMaxHops,
31
+ ...typeof withEnrichments === "function" ? { predicate: withEnrichments } : { include: withEnrichments }
32
+ };
33
+ return datasets.map(({ column, producer }, i) => {
34
+ const datasetSpec = column.getSpec();
35
+ const primary = {
36
+ ref: createPlRef(producer.blockId, producer.name, requireEnrichments),
37
+ label: labels[i]
38
+ };
39
+ const filters = filterMatchesToOptions(findFilterColumns({
40
+ sources: [pool],
32
41
  anchorSpec: datasetSpec
33
- }).filter((m) => filterPredicate(m.getSpec()));
34
- const filters = filterMatches.length === 0 ? void 0 : filterMatchesToOptions(filterMatches, {
35
- refsByObjectId: refMap,
42
+ }).filter((match) => filterPredicate(match.getSpec())), {
36
43
  datasetSpec,
37
44
  labelOptions: opts?.labelOptions
38
45
  });
39
- let enrichments;
40
- if (enrichmentSources && withEnrichments) {
41
- const enrichmentVariants = findEnrichmentColumns({
42
- sources: enrichmentSources,
43
- anchorSpec: datasetSpec,
44
- maxHops: opts?.enrichmentMaxHops,
45
- ...typeof withEnrichments === "function" ? { predicate: withEnrichments } : { include: withEnrichments }
46
- });
47
- if (enrichmentVariants.length > 0) enrichments = enrichmentVariantsToRefs(enrichmentVariants, opts?.labelOptions);
48
- }
46
+ const enrichments = enrichmentSearch === void 0 ? [] : labelEnrichments(findEnrichmentColumns({
47
+ ...enrichmentSearch,
48
+ anchorSpec: datasetSpec
49
+ }), opts?.labelOptions);
49
50
  return {
50
51
  primary,
51
- ...filters !== void 0 && filters.length > 0 ? { filters } : {},
52
- ...enrichments !== void 0 && enrichments.length > 0 ? { enrichments } : {}
52
+ ...filters.length > 0 ? { filters } : {},
53
+ ...enrichments.length > 0 ? { enrichments } : {}
53
54
  };
54
55
  });
55
56
  }
57
+ function toPredicate(opt) {
58
+ if (opt === void 0) return () => true;
59
+ return typeof opt === "function" ? opt : multiColumnSelectorsToPredicate(opt);
60
+ }
61
+ function findDatasets(pool, primary) {
62
+ if (primary === void 0) return pool.getColumns();
63
+ if (typeof primary === "function") return pool.getColumns().filter((column) => primary(column.getSpec()));
64
+ return pool.filter({ include: primary }).getColumns();
65
+ }
56
66
  export { buildDatasetOptions };
57
67
 
58
68
  //# sourceMappingURL=build_dataset_options.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"build_dataset_options.js","names":[],"sources":["../../../src/components/PlDatasetSelector/build_dataset_options.ts"],"sourcesContent":["import type { MultiColumnSelector, Option, PObjectSpec } from \"@milaboratories/pl-model-common\";\nimport { isPColumnSpec, multiColumnSelectorsToPredicate } from \"@milaboratories/pl-model-common\";\nimport type { DeriveLabelsOptions } from \"../../labels/derive_distinct_labels\";\nimport type { RenderCtxBase } from \"../../render\";\nimport type { DatasetOption } from \"./dataset_selection\";\nimport { buildRefMap, filterMatchesToOptions, findFilterColumns } from \"./filter_discovery\";\nimport { enrichmentVariantsToRefs, findEnrichmentColumns } from \"./enrichment_discovery\";\nimport { ColumnsProvider, getCtxProviders } from \"../../columns\";\n\ntype SpecPredicateOption =\n | MultiColumnSelector\n | MultiColumnSelector[]\n | ((spec: PObjectSpec) => boolean);\n\nfunction toPredicate(opt: SpecPredicateOption | undefined): (spec: PObjectSpec) => boolean {\n if (opt === undefined) return () => true;\n return typeof opt === \"function\" ? opt : multiColumnSelectorsToPredicate(opt);\n}\n\nexport type BuildDatasetOptions = {\n /** Which result pool columns qualify as datasets. Defaults to all. */\n primary?: SpecPredicateOption;\n /**\n * Restricts which result pool columns are considered as filters. Intersected\n * with the built-in `pl7.app/isSubset: \"true\"` constraint. Defaults to\n * accept-all.\n */\n filter?: SpecPredicateOption;\n /**\n * Formatting options forwarded to label derivation for both filter and\n * enrichment rows. `formatters.native` on the filter path is overridden\n * — see `FilterMatchOptions.labelOptions`.\n */\n labelOptions?: DeriveLabelsOptions;\n /**\n * Enables enrichment discovery and filters hits attached to\n * `DatasetOption.enrichments`. Use `() => true` to accept all; omit to disable.\n */\n withEnrichments?: SpecPredicateOption;\n /** Maximum linker hops considered. Only used when `withEnrichments` is set. */\n enrichmentMaxHops?: number;\n /**\n * Whether the dataset refs in the returned options carry `requireEnrichments: true`.\n * A block that stores such a ref depends on every block that enriches the dataset.\n * Set `false` for a block that only needs the dataset and its filters. Defaults to `true`.\n */\n requireEnrichments?: boolean;\n};\n\n/**\n * Usage:\n * ```ts\n * .output(\"datasetOptions\", (ctx) => buildDatasetOptions(ctx))\n * ```\n */\nexport function buildDatasetOptions(\n ctx: RenderCtxBase,\n opts?: BuildDatasetOptions,\n): DatasetOption[] | undefined {\n const primaryPredicate = toPredicate(opts?.primary);\n const filterPredicate = toPredicate(opts?.filter);\n\n const options = ctx.resultPool.getOptions(\n (spec) => isPColumnSpec(spec) && primaryPredicate(spec),\n {\n refsWithEnrichments: opts?.requireEnrichments ?? true,\n },\n );\n if (options.length === 0) return [];\n\n const refMap = buildRefMap(ctx.resultPool.getSpecs().entries);\n\n const withEnrichments = opts?.withEnrichments ?? false;\n const filterSource = ColumnsProvider(ctx.ctx.getUpstreamBlockCtx());\n // Hoist providers once: getCtxProviders walks the full output tree, so\n // calling it per dataset option would be O(N × tree).\n const enrichmentSources = withEnrichments ? getCtxProviders(ctx) : undefined;\n\n return options.map((primary: Option): DatasetOption => {\n const datasetSpec = ctx.resultPool.getPColumnSpecByRef(primary.ref);\n if (!datasetSpec) return { primary };\n\n const filterMatches = findFilterColumns({\n sources: [filterSource],\n anchorSpec: datasetSpec,\n }).filter((m) => filterPredicate(m.getSpec()!));\n\n const filters =\n filterMatches.length === 0\n ? undefined\n : filterMatchesToOptions(filterMatches, {\n refsByObjectId: refMap,\n datasetSpec,\n labelOptions: opts?.labelOptions,\n });\n\n let enrichments;\n if (enrichmentSources && withEnrichments) {\n const enrichmentVariants = findEnrichmentColumns({\n sources: enrichmentSources,\n anchorSpec: datasetSpec,\n maxHops: opts?.enrichmentMaxHops,\n ...(typeof withEnrichments === \"function\"\n ? { predicate: withEnrichments }\n : { include: withEnrichments }),\n });\n if (enrichmentVariants.length > 0) {\n enrichments = enrichmentVariantsToRefs(enrichmentVariants, opts?.labelOptions);\n }\n }\n\n return {\n primary,\n ...(filters !== undefined && filters.length > 0 ? { filters } : {}),\n ...(enrichments !== undefined && enrichments.length > 0 ? { enrichments } : {}),\n };\n });\n}\n"],"mappings":";;;;;;;AAcA,SAAS,YAAY,KAAsE;CACzF,IAAI,QAAQ,KAAA,GAAW,aAAa;CACpC,OAAO,OAAO,QAAQ,aAAa,MAAM,gCAAgC,GAAG;AAC9E;;;;;;;AAsCA,SAAgB,oBACd,KACA,MAC6B;CAC7B,MAAM,mBAAmB,YAAY,MAAM,OAAO;CAClD,MAAM,kBAAkB,YAAY,MAAM,MAAM;CAEhD,MAAM,UAAU,IAAI,WAAW,YAC5B,SAAS,cAAc,IAAI,KAAK,iBAAiB,IAAI,GACtD,EACE,qBAAqB,MAAM,sBAAsB,KACnD,CACF;CACA,IAAI,QAAQ,WAAW,GAAG,OAAO,CAAC;CAElC,MAAM,SAAS,YAAY,IAAI,WAAW,SAAS,CAAC,CAAC,OAAO;CAE5D,MAAM,kBAAkB,MAAM,mBAAmB;CACjD,MAAM,eAAe,gBAAgB,IAAI,IAAI,oBAAoB,CAAC;CAGlE,MAAM,oBAAoB,kBAAkB,gBAAgB,GAAG,IAAI,KAAA;CAEnE,OAAO,QAAQ,KAAK,YAAmC;EACrD,MAAM,cAAc,IAAI,WAAW,oBAAoB,QAAQ,GAAG;EAClE,IAAI,CAAC,aAAa,OAAO,EAAE,QAAQ;EAEnC,MAAM,gBAAgB,kBAAkB;GACtC,SAAS,CAAC,YAAY;GACtB,YAAY;EACd,CAAC,CAAC,CAAC,QAAQ,MAAM,gBAAgB,EAAE,QAAQ,CAAE,CAAC;EAE9C,MAAM,UACJ,cAAc,WAAW,IACrB,KAAA,IACA,uBAAuB,eAAe;GACpC,gBAAgB;GAChB;GACA,cAAc,MAAM;EACtB,CAAC;EAEP,IAAI;EACJ,IAAI,qBAAqB,iBAAiB;GACxC,MAAM,qBAAqB,sBAAsB;IAC/C,SAAS;IACT,YAAY;IACZ,SAAS,MAAM;IACf,GAAI,OAAO,oBAAoB,aAC3B,EAAE,WAAW,gBAAgB,IAC7B,EAAE,SAAS,gBAAgB;GACjC,CAAC;GACD,IAAI,mBAAmB,SAAS,GAC9B,cAAc,yBAAyB,oBAAoB,MAAM,YAAY;EAEjF;EAEA,OAAO;GACL;GACA,GAAI,YAAY,KAAA,KAAa,QAAQ,SAAS,IAAI,EAAE,QAAQ,IAAI,CAAC;GACjE,GAAI,gBAAgB,KAAA,KAAa,YAAY,SAAS,IAAI,EAAE,YAAY,IAAI,CAAC;EAC/E;CACF,CAAC;AACH"}
1
+ {"version":3,"file":"build_dataset_options.js","names":[],"sources":["../../../src/components/PlDatasetSelector/build_dataset_options.ts"],"sourcesContent":["import type { MultiColumnSelector, Option, PObjectSpec } from \"@milaboratories/pl-model-common\";\nimport {\n columnProducer,\n createPlRef,\n multiColumnSelectorsToPredicate,\n} from \"@milaboratories/pl-model-common\";\nimport type { ColumnRecipe } from \"../../columns\";\nimport { ColumnsCollection } from \"../../columns\";\nimport {\n deriveDistinctLabels,\n type DeriveLabelsOptions,\n} from \"../../labels/derive_distinct_labels\";\nimport type { RenderCtxBase } from \"../../render\";\nimport type { DatasetOption } from \"./dataset_selection\";\nimport { filterMatchesToOptions, findFilterColumns } from \"./filter_discovery\";\nimport { findEnrichmentColumns, labelEnrichments } from \"./enrichment_discovery\";\n\nexport type BuildDatasetOptions = {\n /**\n * Which result pool columns qualify as datasets. Defaults to all. A selector\n * is matched by the host; a predicate reads the spec of every result pool\n * column, so prefer a selector when it can say the same.\n */\n primary?: SpecPredicateOption;\n /**\n * Restricts which result pool columns are considered as filters. Intersected\n * with the built-in `pl7.app/isSubset: \"true\"` constraint. Defaults to\n * accept-all.\n */\n filter?: SpecPredicateOption;\n /**\n * Formatting options forwarded to label derivation for both filter and\n * enrichment rows. `formatters.native` on the filter path is overridden\n * — see `FilterMatchOptions.labelOptions`.\n */\n labelOptions?: DeriveLabelsOptions;\n /**\n * Enables enrichment discovery and filters hits attached to\n * `DatasetOption.enrichments`. Use `() => true` to accept all; omit to disable.\n */\n withEnrichments?: SpecPredicateOption;\n /** Maximum linker hops considered. Only used when `withEnrichments` is set. */\n enrichmentMaxHops?: number;\n /**\n * Whether the dataset refs in the returned options carry `requireEnrichments: true`.\n * A block that stores such a ref depends on every block that enriches the dataset.\n * Set `false` for a block that only needs the dataset and its filters. Defaults to `true`.\n */\n requireEnrichments?: boolean;\n};\n\n/**\n * Usage:\n * ```ts\n * .output(\"datasetOptions\", (ctx) => buildDatasetOptions(ctx))\n * ```\n */\nexport function buildDatasetOptions(\n ctx: RenderCtxBase,\n opts?: BuildDatasetOptions,\n): DatasetOption[] | undefined {\n const pool = ColumnsCollection([\"result_pool\"], { ctx: ctx.ctx });\n\n // A dataset is stored as a reference to a block output, so only a column\n // that is one can be offered.\n const datasets = findDatasets(pool, opts?.primary).flatMap((column) => {\n const producer = columnProducer(column.id);\n return producer === undefined ? [] : [{ column, producer }];\n });\n if (datasets.length === 0) return [];\n\n const labels = deriveDistinctLabels(datasets.map(({ column }) => column.getSpec()));\n const requireEnrichments = opts?.requireEnrichments ?? true;\n const filterPredicate = toPredicate(opts?.filter);\n\n const withEnrichments = opts?.withEnrichments;\n const enrichmentSearch =\n withEnrichments === undefined\n ? undefined\n : {\n // Enrichments are also looked for among this block's own columns.\n // Built once: every dataset searches the same set.\n sources: [ColumnsCollection([\"current_block\", pool], { ctx: ctx.ctx })],\n maxHops: opts?.enrichmentMaxHops,\n ...(typeof withEnrichments === \"function\"\n ? { predicate: withEnrichments }\n : { include: withEnrichments }),\n };\n\n return datasets.map(({ column, producer }, i): DatasetOption => {\n const datasetSpec = column.getSpec();\n const primary: Option = {\n ref: createPlRef(producer.blockId, producer.name, requireEnrichments),\n label: labels[i],\n };\n\n const filters = filterMatchesToOptions(\n findFilterColumns({ sources: [pool], anchorSpec: datasetSpec }).filter((match) =>\n filterPredicate(match.getSpec()),\n ),\n { datasetSpec, labelOptions: opts?.labelOptions },\n );\n\n const enrichments =\n enrichmentSearch === undefined\n ? []\n : labelEnrichments(\n findEnrichmentColumns({ ...enrichmentSearch, anchorSpec: datasetSpec }),\n opts?.labelOptions,\n );\n\n return {\n primary,\n ...(filters.length > 0 ? { filters } : {}),\n ...(enrichments.length > 0 ? { enrichments } : {}),\n };\n });\n}\n\n// Internals\n\ntype SpecPredicateOption =\n | MultiColumnSelector\n | MultiColumnSelector[]\n | ((spec: PObjectSpec) => boolean);\n\nfunction toPredicate(opt: SpecPredicateOption | undefined): (spec: PObjectSpec) => boolean {\n if (opt === undefined) return () => true;\n return typeof opt === \"function\" ? opt : multiColumnSelectorsToPredicate(opt);\n}\n\nfunction findDatasets(\n pool: ColumnsCollection,\n primary: SpecPredicateOption | undefined,\n): ColumnRecipe[] {\n if (primary === undefined) return pool.getColumns();\n if (typeof primary === \"function\") {\n return pool.getColumns().filter((column) => primary(column.getSpec()));\n }\n return pool.filter({ include: primary }).getColumns();\n}\n"],"mappings":";;;;;;;;;;;;;AAyDA,SAAgB,oBACd,KACA,MAC6B;CAC7B,MAAM,OAAO,kBAAkB,CAAC,aAAa,GAAG,EAAE,KAAK,IAAI,IAAI,CAAC;CAIhE,MAAM,WAAW,aAAa,MAAM,MAAM,OAAO,CAAC,CAAC,SAAS,WAAW;EACrE,MAAM,WAAW,eAAe,OAAO,E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W,aAAa;CACpC,OAAO,OAAO,QAAQ,aAAa,MAAM,gCAAgC,GAAG;AAC9E;AAEA,SAAS,aACP,MACA,SACgB;CAChB,IAAI,YAAY,KAAA,GAAW,OAAO,KAAK,WAAW;CAClD,IAAI,OAAO,YAAY,YACrB,OAAO,KAAK,WAAW,CAAC,CAAC,QAAQ,WAAW,QAAQ,OAAO,QAAQ,CAAC,CAAC;CAEvE,OAAO,KAAK,OAAO,EAAE,SAAS,QAAQ,CAAC,CAAC,CAAC,WAAW;AACtD"}
@@ -1 +1 @@
1
- {"version":3,"file":"dataset_selection.cjs","names":[],"sources":["../../../src/components/PlDatasetSelector/dataset_selection.ts"],"sourcesContent":["import type { LabeledEnrichmentRefs, Option, PrimaryRef } from \"@milaboratories/pl-model-common\";\n\n/** Dataset picker entry: user picks {@link primary}, gets {@link enrichments} attached. */\nexport type DatasetOption = {\n readonly primary: Option;\n readonly filters?: readonly Option[];\n readonly enrichments?: LabeledEnrichmentRefs;\n};\n\n/**\n * Picked dataset bundle emitted by `PlDatasetSelector`. Stored opaquely in\n * block data; block authors unbundle inside their args resolver.\n */\nexport type DatasetSelection = {\n readonly __isDatasetSelection: \"v1\";\n readonly primary: PrimaryRef;\n readonly enrichments?: LabeledEnrichmentRefs;\n};\n\nexport function isDatasetSelection(value: unknown): value is DatasetSelection {\n return (\n typeof value === \"object\" &&\n value !== null &&\n (value as { __isDatasetSelection?: unknown }).__isDatasetSelection === \"v1\" &&\n \"primary\" in value\n );\n}\n\nexport function createDatasetSelection(\n primary: PrimaryRef,\n enrichments?: LabeledEnrichmentRefs,\n): DatasetSelection {\n if (enrichments !== undefined && enrichments.length > 0) {\n return { __isDatasetSelection: \"v1\", primary, enrichments };\n }\n return { __isDatasetSelection: \"v1\", primary };\n}\n"],"mappings":";AAmBA,SAAgB,mBAAmB,OAA2C;CAC5E,OACE,OAAO,UAAU,YACjB,UAAU,QACT,MAA6C,yBAAyB,QACvE,aAAa;AAEjB;AAEA,SAAgB,uBACd,SACA,aACkB;CAClB,IAAI,gBAAgB,KAAA,KAAa,YAAY,SAAS,GACpD,OAAO;EAAE,sBAAsB;EAAM;EAAS;CAAY;CAE5D,OAAO;EAAE,sBAAsB;EAAM;CAAQ;AAC/C"}
1
+ {"version":3,"file":"dataset_selection.cjs","names":[],"sources":["../../../src/components/PlDatasetSelector/dataset_selection.ts"],"sourcesContent":["import type { ColumnUniversalId, Option, PrimaryRef } from \"@milaboratories/pl-model-common\";\n\n/**\n * A column joined to a dataset without being picked by the user, with the header\n * it is exported under. The id names a block output reached from the dataset\n * through linker columns, so a workflow can find the column by the id alone.\n */\nexport type DatasetEnrichment = {\n readonly id: ColumnUniversalId;\n readonly label: string;\n};\n\n/** Dataset picker entry: user picks {@link primary}, gets {@link enrichments} attached. */\nexport type DatasetOption = {\n readonly primary: Option;\n readonly filters?: readonly Option[];\n readonly enrichments?: readonly DatasetEnrichment[];\n};\n\n/**\n * Picked dataset bundle emitted by `PlDatasetSelector`. Stored opaquely in\n * block data; block authors unbundle inside their args resolver.\n */\nexport type DatasetSelection = {\n readonly __isDatasetSelection: \"v1\";\n readonly primary: PrimaryRef;\n readonly enrichments?: readonly DatasetEnrichment[];\n};\n\nexport function isDatasetSelection(value: unknown): value is DatasetSelection {\n return (\n typeof value === \"object\" &&\n value !== null &&\n (value as { __isDatasetSelection?: unknown }).__isDatasetSelection === \"v1\" &&\n \"primary\" in value\n );\n}\n\nexport function createDatasetSelection(\n primary: PrimaryRef,\n enrichments?: readonly DatasetEnrichment[],\n): DatasetSelection {\n if (enrichments !== undefined && enrichments.length > 0) {\n return { __isDatasetSelection: \"v1\", primary, enrichments };\n }\n return { __isDatasetSelection: \"v1\", primary };\n}\n"],"mappings":";AA6BA,SAAgB,mBAAmB,OAA2C;CAC5E,OACE,OAAO,UAAU,YACjB,UAAU,QACT,MAA6C,yBAAyB,QACvE,aAAa;AAEjB;AAEA,SAAgB,uBACd,SACA,aACkB;CAClB,IAAI,gBAAgB,KAAA,KAAa,YAAY,SAAS,GACpD,OAAO;EAAE,sBAAsB;EAAM;EAAS;CAAY;CAE5D,OAAO;EAAE,sBAAsB;EAAM;CAAQ;AAC/C"}
@@ -1,9 +1,18 @@
1
- import { LabeledEnrichmentRefs, Option, PrimaryRef } from "@milaboratories/pl-model-common";
1
+ import { ColumnUniversalId, Option, PrimaryRef } from "@milaboratories/pl-model-common";
2
+ /**
3
+ * A column joined to a dataset without being picked by the user, with the header
4
+ * it is exported under. The id names a block output reached from the dataset
5
+ * through linker columns, so a workflow can find the column by the id alone.
6
+ */
7
+ export type DatasetEnrichment = {
8
+ readonly id: ColumnUniversalId;
9
+ readonly label: string;
10
+ };
2
11
  /** Dataset picker entry: user picks {@link primary}, gets {@link enrichments} attached. */
3
12
  export type DatasetOption = {
4
13
  readonly primary: Option;
5
14
  readonly filters?: readonly Option[];
6
- readonly enrichments?: LabeledEnrichmentRefs;
15
+ readonly enrichments?: readonly DatasetEnrichment[];
7
16
  };
8
17
  /**
9
18
  * Picked dataset bundle emitted by `PlDatasetSelector`. Stored opaquely in
@@ -12,8 +21,8 @@ export type DatasetOption = {
12
21
  export type DatasetSelection = {
13
22
  readonly __isDatasetSelection: "v1";
14
23
  readonly primary: PrimaryRef;
15
- readonly enrichments?: LabeledEnrichmentRefs;
24
+ readonly enrichments?: readonly DatasetEnrichment[];
16
25
  };
17
26
  export declare function isDatasetSelection(value: unknown): value is DatasetSelection;
18
- export declare function createDatasetSelection(primary: PrimaryRef, enrichments?: LabeledEnrichmentRefs): DatasetSelection;
27
+ export declare function createDatasetSelection(primary: PrimaryRef, enrichments?: readonly DatasetEnrichment[]): DatasetSelection;
19
28
  //# sourceMappingURL=dataset_selection.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"dataset_selection.d.ts","names":[],"sources":["../../../src/components/PlDatasetSelector/dataset_selection.ts"],"mappings":";;YAGY;WACD,SAAS;WACT,mBAAmB;WACnB,cAAc;;;;;;YAOb;WACD;WACA,SAAS;WACT,cAAc;;wBAGT,mBAAmB,iBAAiB,SAAS;wBAS7C,uBACd,SAAS,YACT,cAAc,wBACb"}
1
+ {"version":3,"file":"dataset_selection.d.ts","names":[],"sources":["../../../src/components/PlDatasetSelector/dataset_selection.ts"],"mappings":";;;;;;YAOY;WACD,IAAI;WACJ;;;YAIC;WACD,SAAS;WACT,mBAAmB;WACnB,uBAAuB;;;;;;YAOtB;WACD;WACA,SAAS;WACT,uBAAuB;;wBAGlB,mBAAmB,iBAAiB,SAAS;wBAS7C,uBACd,SAAS,YACT,uBAAuB,sBACtB"}
@@ -1 +1 @@
1
- {"version":3,"file":"dataset_selection.js","names":[],"sources":["../../../src/components/PlDatasetSelector/dataset_selection.ts"],"sourcesContent":["import type { LabeledEnrichmentRefs, Option, PrimaryRef } from \"@milaboratories/pl-model-common\";\n\n/** Dataset picker entry: user picks {@link primary}, gets {@link enrichments} attached. */\nexport type DatasetOption = {\n readonly primary: Option;\n readonly filters?: readonly Option[];\n readonly enrichments?: LabeledEnrichmentRefs;\n};\n\n/**\n * Picked dataset bundle emitted by `PlDatasetSelector`. Stored opaquely in\n * block data; block authors unbundle inside their args resolver.\n */\nexport type DatasetSelection = {\n readonly __isDatasetSelection: \"v1\";\n readonly primary: PrimaryRef;\n readonly enrichments?: LabeledEnrichmentRefs;\n};\n\nexport function isDatasetSelection(value: unknown): value is DatasetSelection {\n return (\n typeof value === \"object\" &&\n value !== null &&\n (value as { __isDatasetSelection?: unknown }).__isDatasetSelection === \"v1\" &&\n \"primary\" in value\n );\n}\n\nexport function createDatasetSelection(\n primary: PrimaryRef,\n enrichments?: LabeledEnrichmentRefs,\n): DatasetSelection {\n if (enrichments !== undefined && enrichments.length > 0) {\n return { __isDatasetSelection: \"v1\", primary, enrichments };\n }\n return { __isDatasetSelection: \"v1\", primary };\n}\n"],"mappings":";AAmBA,SAAgB,mBAAmB,OAA2C;CAC5E,OACE,OAAO,UAAU,YACjB,UAAU,QACT,MAA6C,yBAAyB,QACvE,aAAa;AAEjB;AAEA,SAAgB,uBACd,SACA,aACkB;CAClB,IAAI,gBAAgB,KAAA,KAAa,YAAY,SAAS,GACpD,OAAO;EAAE,sBAAsB;EAAM;EAAS;CAAY;CAE5D,OAAO;EAAE,sBAAsB;EAAM;CAAQ;AAC/C"}
1
+ {"version":3,"file":"dataset_selection.js","names":[],"sources":["../../../src/components/PlDatasetSelector/dataset_selection.ts"],"sourcesContent":["import type { ColumnUniversalId, Option, PrimaryRef } from \"@milaboratories/pl-model-common\";\n\n/**\n * A column joined to a dataset without being picked by the user, with the header\n * it is exported under. The id names a block output reached from the dataset\n * through linker columns, so a workflow can find the column by the id alone.\n */\nexport type DatasetEnrichment = {\n readonly id: ColumnUniversalId;\n readonly label: string;\n};\n\n/** Dataset picker entry: user picks {@link primary}, gets {@link enrichments} attached. */\nexport type DatasetOption = {\n readonly primary: Option;\n readonly filters?: readonly Option[];\n readonly enrichments?: readonly DatasetEnrichment[];\n};\n\n/**\n * Picked dataset bundle emitted by `PlDatasetSelector`. Stored opaquely in\n * block data; block authors unbundle inside their args resolver.\n */\nexport type DatasetSelection = {\n readonly __isDatasetSelection: \"v1\";\n readonly primary: PrimaryRef;\n readonly enrichments?: readonly DatasetEnrichment[];\n};\n\nexport function isDatasetSelection(value: unknown): value is DatasetSelection {\n return (\n typeof value === \"object\" &&\n value !== null &&\n (value as { __isDatasetSelection?: unknown }).__isDatasetSelection === \"v1\" &&\n \"primary\" in value\n );\n}\n\nexport function createDatasetSelection(\n primary: PrimaryRef,\n enrichments?: readonly DatasetEnrichment[],\n): DatasetSelection {\n if (enrichments !== undefined && enrichments.length > 0) {\n return { __isDatasetSelection: \"v1\", primary, enrichments };\n }\n return { __isDatasetSelection: \"v1\", primary };\n}\n"],"mappings":";AA6BA,SAAgB,mBAAmB,OAA2C;CAC5E,OACE,OAAO,UAAU,YACjB,UAAU,QACT,MAA6C,yBAAyB,QACvE,aAAa;AAEjB;AAEA,SAAgB,uBACd,SACA,aACkB;CAClB,IAAI,gBAAgB,KAAA,KAAa,YAAY,SAAS,GACpD,OAAO;EAAE,sBAAsB;EAAM;EAAS;CAAY;CAE5D,OAAO;EAAE,sBAAsB;EAAM;CAAQ;AAC/C"}
@@ -8,6 +8,9 @@ let _milaboratories_pl_model_common = require("@milaboratories/pl-model-common")
8
8
  * Linker-reached hits attached to the anchor primary. Drops zero-hop variants
9
9
  * (filters / the primary itself) and structural hits (subset, linker, label
10
10
  * columns). Narrow further with `include` selectors or a `predicate`.
11
+ *
12
+ * A hit is kept only when a workflow can find it by its id: the hit and every
13
+ * linker leading to it are block outputs.
11
14
  */
12
15
  function findEnrichmentColumns(options) {
13
16
  const include = options.include === void 0 ? void 0 : Array.isArray(options.include) ? options.include : [options.include];
@@ -25,45 +28,36 @@ function findEnrichmentColumns(options) {
25
28
  const predicate = options.predicate;
26
29
  return columns.filter((v) => {
27
30
  if (require_utils.hasSingleDataColumn(v)) return false;
28
- if (predicate !== void 0 && !predicate(v.getSpec())) return false;
29
- if (!(0, _milaboratories_pl_model_common.isGlobalPObjectId)((0, _milaboratories_pl_model_common.extractPObjectId)(v.id))) return false;
30
- if (require_utils.collectLinkerIds(v).some((id) => !(0, _milaboratories_pl_model_common.isGlobalPObjectId)(id))) return false;
31
- return true;
31
+ if (!reachesBlockOutputs(v.id)) return false;
32
+ return predicate === void 0 || predicate(v.getSpec());
32
33
  });
33
34
  }
34
35
  /**
35
- * Pair each variant with a path-disambiguated label (so export headers stay
36
- * unique) and carry hit/linker `PObjectId`s through verbatim. Propagates
37
- * `qualifications.forHit`; `forQueries` is re-derived by the table builder.
36
+ * Pairs each column with a label that tells apart the same hit reached through
37
+ * different linkers, so export headers stay unique.
38
38
  */
39
- function enrichmentVariantsToRefs(variants, labelOptions) {
39
+ function labelEnrichments(variants, labelOptions) {
40
40
  if (variants.length === 0) return [];
41
- const linkerIdsByVariant = variants.map((v) => require_utils.collectLinkerIds(v));
42
- const hitQualsByVariant = variants.map((v) => [...require_utils.hitQualifications(v)]);
43
- const entries = variants.map((variant, i) => ({
41
+ const entries = variants.map((variant) => ({
44
42
  spec: variant.getSpec(),
45
43
  linkerPath: require_utils.collectLinkerColumns(variant).map((linker) => ({ spec: linker.getSpec() })),
46
44
  qualifications: {
47
- forHit: hitQualsByVariant[i],
45
+ forHit: [...require_utils.hitQualifications(variant)],
48
46
  forQueries: require_utils.queriesQualifications(variant)
49
47
  }
50
48
  }));
51
49
  const labels = require_derive_distinct_labels.deriveDistinctLabels(entries, labelOptions);
52
- return variants.map((variant, i) => {
53
- const path = linkerIdsByVariant[i].length === 0 ? void 0 : linkerIdsByVariant[i].map((id) => ({
54
- type: "linker",
55
- linker: id
56
- }));
57
- return {
58
- ref: (0, _milaboratories_pl_model_common.createEnrichmentRef)((0, _milaboratories_pl_model_common.extractPObjectId)(variant.id), {
59
- path,
60
- qualifications: hitQualsByVariant[i]
61
- }),
62
- label: labels[i]
63
- };
64
- });
50
+ return variants.map((variant, i) => ({
51
+ id: variant.id,
52
+ label: labels[i]
53
+ }));
54
+ }
55
+ function reachesBlockOutputs(id) {
56
+ if (!(0, _milaboratories_pl_model_common.isColumnDiscoveredId)(id)) return false;
57
+ const key = (0, _milaboratories_pl_model_common.parseColumnDiscoveredId)(id);
58
+ return [key.column, ...(key.path ?? []).map((step) => step.column)].every(_milaboratories_pl_model_common.isGlobalPObjectId);
65
59
  }
66
- exports.enrichmentVariantsToRefs = enrichmentVariantsToRefs;
67
60
  exports.findEnrichmentColumns = findEnrichmentColumns;
61
+ exports.labelEnrichments = labelEnrichments;
68
62
 
69
63
  //# sourceMappingURL=enrichment_discovery.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"enrichment_discovery.cjs","names":["ColumnsCollection","Annotation","hasSingleDataColumn","isGlobalPObjectId","extractPObjectId","collectLinkerIds","hitQualifications","collectLinkerColumns","queriesQualifications","deriveDistinctLabels","createEnrichmentRef"],"sources":["../../../src/components/PlDatasetSelector/enrichment_discovery.ts"],"sourcesContent":["import {\n Annotation,\n createEnrichmentRef,\n extractPObjectId,\n isGlobalPObjectId,\n} from \"@milaboratories/pl-model-common\";\nimport type {\n ColumnsCollectionDriverModel,\n EnrichmentStep,\n LabeledEnrichmentRef,\n LabeledEnrichmentRefs,\n MultiColumnSelector,\n PColumnSpec,\n PObjectSpec,\n} from \"@milaboratories/pl-model-common\";\nimport type { ColumnRecipe, ColumnsSource } from \"../../columns\";\nimport {\n hasSingleDataColumn,\n ColumnsCollection,\n collectLinkerIds,\n hitQualifications,\n collectLinkerColumns,\n queriesQualifications,\n} from \"../../columns\";\nimport {\n deriveDistinctLabels,\n type DeriveLabelsOptions,\n type Entry,\n} from \"../../labels/derive_distinct_labels\";\n\nexport interface FindEnrichmentColumnsOptions {\n sources: ReadonlyArray<ColumnsSource>;\n anchorSpec: PColumnSpec;\n maxHops?: number;\n include?: MultiColumnSelector | MultiColumnSelector[];\n predicate?: (spec: PObjectSpec) => boolean;\n /** Override the resolved `columnsCollection` service (primarily for tests). */\n driver?: ColumnsCollectionDriverModel;\n}\n\n/**\n * Linker-reached hits attached to the anchor primary. Drops zero-hop variants\n * (filters / the primary itself) and structural hits (subset, linker, label\n * columns). Narrow further with `include` selectors or a `predicate`.\n */\nexport function findEnrichmentColumns(options: FindEnrichmentColumnsOptions): ColumnRecipe[] {\n const include =\n options.include === undefined\n ? undefined\n : Array.isArray(options.include)\n ? options.include\n : [options.include];\n\n const columns = ColumnsCollection([...options.sources], { driver: options.driver })\n .discover({\n anchors: { main: options.anchorSpec },\n mode: \"enrichment\",\n maxHops: options.maxHops ?? 4,\n include,\n exclude: [\n { annotations: { [Annotation.IsSubset]: \"true\" } },\n { annotations: { [Annotation.IsLinkerColumn]: \"true\" } },\n { name: Annotation.Label },\n ],\n })\n .getColumns();\n\n const predicate = options.predicate;\n return columns.filter((v) => {\n if (hasSingleDataColumn(v)) return false;\n if (predicate !== undefined && !predicate(v.getSpec())) return false;\n if (!isGlobalPObjectId(extractPObjectId(v.id))) return false;\n if (collectLinkerIds(v).some((id) => !isGlobalPObjectId(id))) return false;\n return true;\n });\n}\n\n/**\n * Pair each variant with a path-disambiguated label (so export headers stay\n * unique) and carry hit/linker `PObjectId`s through verbatim. Propagates\n * `qualifications.forHit`; `forQueries` is re-derived by the table builder.\n */\nexport function enrichmentVariantsToRefs(\n variants: ColumnRecipe[],\n labelOptions?: DeriveLabelsOptions,\n): LabeledEnrichmentRefs {\n if (variants.length === 0) return [];\n\n const linkerIdsByVariant = variants.map((v) => collectLinkerIds(v));\n const hitQualsByVariant = variants.map((v) => [...hitQualifications(v)]);\n\n const entries: Entry[] = variants.map((variant, i) => ({\n spec: variant.getSpec(),\n linkerPath: collectLinkerColumns(variant).map((linker) => ({ spec: linker.getSpec() })),\n qualifications: {\n forHit: hitQualsByVariant[i],\n forQueries: queriesQualifications(variant),\n },\n }));\n const labels = deriveDistinctLabels(entries, labelOptions);\n\n return variants.map((variant, i): LabeledEnrichmentRef => {\n const path: undefined | EnrichmentStep[] =\n linkerIdsByVariant[i].length === 0\n ? undefined\n : linkerIdsByVariant[i].map((id) => ({ type: \"linker\", linker: id }));\n return {\n ref: createEnrichmentRef(extractPObjectId(variant.id), {\n path,\n qualifications: hitQualsByVariant[i],\n }),\n label: labels[i],\n };\n });\n}\n"],"mappings":";;;;;;;;;;;AA6CA,SAAgB,sBAAsB,SAAuD;CAC3F,MAAM,UACJ,QAAQ,YAAY,KAAA,IAChB,KAAA,IACA,MAAM,QAAQ,QAAQ,OAAO,IAC3B,QAAQ,UACR,CAAC,QAAQ,OAAO;CAExB,MAAM,UAAUA,2BAAAA,kBAAkB,CAAC,GAAG,QAAQ,OAAO,GAAG,EAAE,QAAQ,QAAQ,OAAO,CAAC,CAAC,CAChF,SAAS;EACR,SAAS,EAAE,MAAM,QAAQ,WAAW;EACpC,MAAM;EACN,SAAS,QAAQ,WAAW;EAC5B;EACA,SAAS;GACP,EAAE,aAAa,GAAGC,gCAAAA,WAAW,WAAW,OAAO,EAAE;GACjD,EAAE,aAAa,GAAGA,gCAAAA,WAAW,iBAA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E;EACxE,OAAO;GACL,MAAA,GAAKC,gCAAAA,oBAAAA,EAAAA,GAAoBN,gCAAAA,iBAAAA,CAAiB,QAAQ,EAAE,GAAG;IACrD;IACA,gBAAgB,kBAAkB;GACpC,CAAC;GACD,OAAO,OAAO;EAChB;CACF,CAAC;AACH"}
1
+ {"version":3,"file":"enrichment_discovery.cjs","names":["ColumnsCollection","Annotation","hasSingleDataColumn","collectLinkerColumns","hitQualifications","queriesQualifications","deriveDistinctLabels","isColumnDiscoveredId","parseColumnDiscoveredId","isGlobalPObjectId"],"sources":["../../../src/components/PlDatasetSelector/enrichment_discovery.ts"],"sourcesContent":["import {\n Annotation,\n isColumnDiscoveredId,\n isGlobalPObjectId,\n parseColumnDiscoveredId,\n} from \"@milaboratories/pl-model-common\";\nimport type {\n ColumnsCollectionDriverModel,\n ColumnUniversalId,\n MultiColumnSelector,\n PColumnSpec,\n PObjectSpec,\n} from \"@milaboratories/pl-model-common\";\nimport type { ColumnRecipe, ColumnsSource, ColumnsSourceShorthand } from \"../../columns\";\nimport {\n hasSingleDataColumn,\n ColumnsCollection,\n hitQualifications,\n collectLinkerColumns,\n queriesQualifications,\n} from \"../../columns\";\nimport {\n deriveDistinctLabels,\n type DeriveLabelsOptions,\n type Entry,\n} from \"../../labels/derive_distinct_labels\";\nimport type { DatasetEnrichment } from \"./dataset_selection\";\n\nexport interface FindEnrichmentColumnsOptions {\n sources: ReadonlyArray<ColumnsCollection | ColumnsSource | ColumnsSourceShorthand>;\n anchorSpec: PColumnSpec;\n maxHops?: number;\n include?: MultiColumnSelector | MultiColumnSelector[];\n predicate?: (spec: PObjectSpec) => boolean;\n /** Override the resolved `columnsCollection` service (primarily for tests). */\n driver?: ColumnsCollectionDriverModel;\n}\n\n/**\n * Linker-reached hits attached to the anchor primary. Drops zero-hop variants\n * (filters / the primary itself) and structural hits (subset, linker, label\n * columns). Narrow further with `include` selectors or a `predicate`.\n *\n * A hit is kept only when a workflow can find it by its id: the hit and every\n * linker leading to it are block outputs.\n */\nexport function findEnrichmentColumns(options: FindEnrichmentColumnsOptions): ColumnRecipe[] {\n const include =\n options.include === undefined\n ? undefined\n : Array.isArray(options.include)\n ? options.include\n : [options.include];\n\n const columns = ColumnsCollection([...options.sources], { driver: options.driver })\n .discover({\n anchors: { main: options.anchorSpec },\n mode: \"enrichment\",\n maxHops: options.maxHops ?? 4,\n include,\n exclude: [\n { annotations: { [Annotation.IsSubset]: \"true\" } },\n { annotations: { [Annotation.IsLinkerColumn]: \"true\" } },\n { name: Annotation.Label },\n ],\n })\n .getColumns();\n\n const predicate = options.predicate;\n return columns.filter((v) => {\n if (hasSingleDataColumn(v)) return false;\n if (!reachesBlockOutputs(v.id)) return false;\n return predicate === undefined || predicate(v.getSpec());\n });\n}\n\n/**\n * Pairs each column with a label that tells apart the same hit reached through\n * different linkers, so export headers stay unique.\n */\nexport function labelEnrichments(\n variants: ColumnRecipe[],\n labelOptions?: DeriveLabelsOptions,\n): DatasetEnrichment[] {\n if (variants.length === 0) return [];\n\n const entries: Entry[] = variants.map((variant) => ({\n spec: variant.getSpec(),\n linkerPath: collectLinkerColumns(variant).map((linker) => ({ spec: linker.getSpec() })),\n qualifications: {\n forHit: [...hitQualifications(variant)],\n forQueries: queriesQualifications(variant),\n },\n }));\n const labels = deriveDistinctLabels(entries, labelOptions);\n\n return variants.map((variant, i): DatasetEnrichment => ({ id: variant.id, label: labels[i] }));\n}\n\n// Internals\n\nfunction reachesBlockOutputs(id: ColumnUniversalId): boolean {\n if (!isColumnDiscoveredId(id)) return false;\n const key = parseColumnDiscoveredId(id);\n return [key.column, ...(key.path ?? []).map((step) => step.column)].every(isGlobalPObjectId);\n}\n"],"mappings":";;;;;;;;;;;;;;AA8CA,SAAgB,sBAAsB,SAAuD;CAC3F,MAAM,UACJ,QAAQ,YAAY,KAAA,IAChB,KAAA,IACA,MAAM,QAAQ,QAAQ,OAAO,IAC3B,QAAQ,UACR,CAAC,QAAQ,OAAO;CAExB,MAAM,UAAUA,2BAA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,wBAAAA,CAAwB,EAAE;CACtC,OAAO,CAAC,IAAI,QAAQ,IAAI,IAAI,QAAQ,CAAC,EAAA,CAAG,KAAK,SAAS,KAAK,MAAM,CAAC,CAAC,CAAC,MAAMC,gCAAAA,iBAAiB;AAC7F"}
@@ -1,13 +1,16 @@
1
1
  import { deriveDistinctLabels } from "../../labels/derive_distinct_labels.js";
2
2
  import { ColumnsCollection } from "../../columns/columns_collection.js";
3
- import { collectLinkerColumns, collectLinkerIds, hasSingleDataColumn, hitQualifications, queriesQualifications } from "../../columns/utils.js";
3
+ import { collectLinkerColumns, hasSingleDataColumn, hitQualifications, queriesQualifications } from "../../columns/utils.js";
4
4
  import "../../columns/index.js";
5
- import { Annotation, createEnrichmentRef, extractPObjectId, isGlobalPObjectId } from "@milaboratories/pl-model-common";
5
+ import { Annotation, isColumnDiscoveredId, isGlobalPObjectId, parseColumnDiscoveredId } from "@milaboratories/pl-model-common";
6
6
  // src/components/PlDatasetSelector/enrichment_discovery.ts
7
7
  /**
8
8
  * Linker-reached hits attached to the anchor primary. Drops zero-hop variants
9
9
  * (filters / the primary itself) and structural hits (subset, linker, label
10
10
  * columns). Narrow further with `include` selectors or a `predicate`.
11
+ *
12
+ * A hit is kept only when a workflow can find it by its id: the hit and every
13
+ * linker leading to it are block outputs.
11
14
  */
12
15
  function findEnrichmentColumns(options) {
13
16
  const include = options.include === void 0 ? void 0 : Array.isArray(options.include) ? options.include : [options.include];
@@ -25,44 +28,35 @@ function findEnrichmentColumns(options) {
25
28
  const predicate = options.predicate;
26
29
  return columns.filter((v) => {
27
30
  if (hasSingleDataColumn(v)) return false;
28
- if (predicate !== void 0 && !predicate(v.getSpec())) return false;
29
- if (!isGlobalPObjectId(extractPObjectId(v.id))) return false;
30
- if (collectLinkerIds(v).some((id) => !isGlobalPObjectId(id))) return false;
31
- return true;
31
+ if (!reachesBlockOutputs(v.id)) return false;
32
+ return predicate === void 0 || predicate(v.getSpec());
32
33
  });
33
34
  }
34
35
  /**
35
- * Pair each variant with a path-disambiguated label (so export headers stay
36
- * unique) and carry hit/linker `PObjectId`s through verbatim. Propagates
37
- * `qualifications.forHit`; `forQueries` is re-derived by the table builder.
36
+ * Pairs each column with a label that tells apart the same hit reached through
37
+ * different linkers, so export headers stay unique.
38
38
  */
39
- function enrichmentVariantsToRefs(variants, labelOptions) {
39
+ function labelEnrichments(variants, labelOptions) {
40
40
  if (variants.length === 0) return [];
41
- const linkerIdsByVariant = variants.map((v) => collectLinkerIds(v));
42
- const hitQualsByVariant = variants.map((v) => [...hitQualifications(v)]);
43
- const entries = variants.map((variant, i) => ({
41
+ const entries = variants.map((variant) => ({
44
42
  spec: variant.getSpec(),
45
43
  linkerPath: collectLinkerColumns(variant).map((linker) => ({ spec: linker.getSpec() })),
46
44
  qualifications: {
47
- forHit: hitQualsByVariant[i],
45
+ forHit: [...hitQualifications(variant)],
48
46
  forQueries: queriesQualifications(variant)
49
47
  }
50
48
  }));
51
49
  const labels = deriveDistinctLabels(entries, labelOptions);
52
- return variants.map((variant, i) => {
53
- const path = linkerIdsByVariant[i].length === 0 ? void 0 : linkerIdsByVariant[i].map((id) => ({
54
- type: "linker",
55
- linker: id
56
- }));
57
- return {
58
- ref: createEnrichmentRef(extractPObjectId(variant.id), {
59
- path,
60
- qualifications: hitQualsByVariant[i]
61
- }),
62
- label: labels[i]
63
- };
64
- });
50
+ return variants.map((variant, i) => ({
51
+ id: variant.id,
52
+ label: labels[i]
53
+ }));
54
+ }
55
+ function reachesBlockOutputs(id) {
56
+ if (!isColumnDiscoveredId(id)) return false;
57
+ const key = parseColumnDiscoveredId(id);
58
+ return [key.column, ...(key.path ?? []).map((step) => step.column)].every(isGlobalPObjectId);
65
59
  }
66
- export { enrichmentVariantsToRefs, findEnrichmentColumns };
60
+ export { findEnrichmentColumns, labelEnrichments };
67
61
 
68
62
  //# sourceMappingURL=enrichment_discovery.js.map