@platforma-sdk/model 1.91.0 → 1.92.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/PlDatasetSelector/build_dataset_options.cjs +43 -33
- package/dist/components/PlDatasetSelector/build_dataset_options.cjs.map +1 -1
- package/dist/components/PlDatasetSelector/build_dataset_options.d.ts +6 -2
- package/dist/components/PlDatasetSelector/build_dataset_options.d.ts.map +1 -1
- package/dist/components/PlDatasetSelector/build_dataset_options.js +46 -36
- package/dist/components/PlDatasetSelector/build_dataset_options.js.map +1 -1
- package/dist/components/PlDatasetSelector/dataset_selection.cjs.map +1 -1
- package/dist/components/PlDatasetSelector/dataset_selection.d.ts +13 -4
- package/dist/components/PlDatasetSelector/dataset_selection.d.ts.map +1 -1
- package/dist/components/PlDatasetSelector/dataset_selection.js.map +1 -1
- package/dist/components/PlDatasetSelector/enrichment_discovery.cjs +20 -26
- package/dist/components/PlDatasetSelector/enrichment_discovery.cjs.map +1 -1
- package/dist/components/PlDatasetSelector/enrichment_discovery.js +22 -28
- package/dist/components/PlDatasetSelector/enrichment_discovery.js.map +1 -1
- package/dist/components/PlDatasetSelector/filter_discovery.cjs +6 -14
- package/dist/components/PlDatasetSelector/filter_discovery.cjs.map +1 -1
- package/dist/components/PlDatasetSelector/filter_discovery.d.ts +5 -10
- package/dist/components/PlDatasetSelector/filter_discovery.d.ts.map +1 -1
- package/dist/components/PlDatasetSelector/filter_discovery.js +8 -13
- package/dist/components/PlDatasetSelector/filter_discovery.js.map +1 -1
- package/dist/components/PlDatasetSelector/index.cjs +0 -1
- package/dist/components/PlDatasetSelector/index.d.ts +3 -3
- package/dist/components/PlDatasetSelector/index.js +2 -2
- package/dist/components/index.cjs +0 -1
- package/dist/components/index.d.ts +3 -3
- package/dist/components/index.js +2 -2
- package/dist/index.cjs +0 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/package.cjs +1 -1
- package/dist/package.js +1 -1
- package/package.json +7 -7
- package/src/columns/__test_helpers__/collection_driver.ts +45 -5
- package/src/components/PlDatasetSelector/build_dataset_options.test.ts +195 -0
- package/src/components/PlDatasetSelector/build_dataset_options.ts +86 -63
- package/src/components/PlDatasetSelector/dataset_selection.ts +14 -4
- package/src/components/PlDatasetSelector/enrichment_discovery.ts +26 -35
- package/src/components/PlDatasetSelector/filter_discovery.test.ts +16 -53
- package/src/components/PlDatasetSelector/filter_discovery.ts +10 -20
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
const
|
|
2
|
-
const
|
|
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
|
|
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
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return
|
|
28
|
-
const datasetSpec =
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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((
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
|
52
|
-
...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":["
|
|
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,iBAAiB,IAAI,GAAG,EAAE,KAAK,IAAI,IAAI,CAAC,CAAC;EACtE,SAAS,MAAM;EACf,GAAI,OAAO,oBAAoB,aAC3B,EAAE,WAAW,gBAAgB,IAC7B,EAAE,SAAS,gBAAgB;CACjC;CAEN,OAAO,SAAS,KAAK,EAAE,QAAQ,YAAY,MAAqB;EAC9D,MAAM,cAAc,OAAO,QAAQ;EACnC,MAAM,UAAkB;GACtB,MAAA,GAAKG,gCAAAA,YAAAA,CAAY,SAAS,SAAS,SAAS,MAAM,kBAAkB;GACpE,OAAO,OAAO;EAChB;EAEA,MAAM,UAAUC,yBAAAA,uBACdC,yBAAAA,kBAAkB;GAAE,SAAS,CAAC,IAAI;GAAG,YAAY;EAAY,CAAC,CAAC,CAAC,QAAQ,UACtE,gBAAgB,MAAM,QAAQ,CAAC,CACjC,GACA;GAAE;GAAa,cAAc,MAAM;EAAa,CAClD;EAEA,MAAM,cACJ,qBAAqB,KAAA,IACjB,CAAC,IACDC,6BAAAA,iBACEC,6BAAAA,sBAAsB;GAAE,GAAG;GAAkB,YAAY;EAAY,CAAC,GACtE,MAAM,YACR;EAEN,OAAO;GACL;GACA,GAAI,QAAQ,SAAS,IAAI,EAAE,QAAQ,IAAI,CAAC;GACxC,GAAI,YAAY,SAAS,IAAI,EAAE,YAAY,IAAI,CAAC;EAClD;CACF,CAAC;AACH;AASA,SAAS,YAAY,KAAsE;CACzF,IAAI,QAAQ,KAAA,GAAW,aAAa;CACpC,OAAO,OAAO,QAAQ,aAAa,OAAA,GAAMC,gCAAAA,gCAAAA,CAAgC,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"}
|
|
@@ -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
|
-
/**
|
|
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":";;;;;
|
|
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 {
|
|
2
|
-
import {
|
|
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 {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
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
|
|
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
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return
|
|
28
|
-
const datasetSpec =
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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((
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
|
52
|
-
...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 {
|
|
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,EAAE;EACzC,OAAO,aAAa,KAAA,IAAY,CAAC,IAAI,CAAC;GAAE;GAAQ;EAAS,CAAC;CAC5D,CAAC;CACD,IAAI,SAAS,WAAW,GAAG,OAAO,CAAC;CAEnC,MAAM,SAAS,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,CAAC,kBAAkB,CAAC,iBAAiB,IAAI,GAAG,EAAE,KAAK,IAAI,IAAI,CAAC,CAAC;EACtE,SAAS,MAAM;EACf,GAAI,OAAO,oBAAoB,aAC3B,EAAE,WAAW,gBAAgB,IAC7B,EAAE,SAAS,gBAAgB;CACjC;CAEN,OAAO,SAAS,KAAK,EAAE,QAAQ,YAAY,MAAqB;EAC9D,MAAM,cAAc,OAAO,QAAQ;EACnC,MAAM,UAAkB;GACtB,KAAK,YAAY,SAAS,SAAS,SAAS,MAAM,kBAAkB;GACpE,OAAO,OAAO;EAChB;EAEA,MAAM,UAAU,uBACd,kBAAkB;GAAE,SAAS,CAAC,IAAI;GAAG,YAAY;EAAY,CAAC,CAAC,CAAC,QAAQ,UACtE,gBAAgB,MAAM,QAAQ,CAAC,CACjC,GACA;GAAE;GAAa,cAAc,MAAM;EAAa,CAClD;EAEA,MAAM,cACJ,qBAAqB,KAAA,IACjB,CAAC,IACD,iBACE,sBAAsB;GAAE,GAAG;GAAkB,YAAY;EAAY,CAAC,GACtE,MAAM,YACR;EAEN,OAAO;GACL;GACA,GAAI,QAAQ,SAAS,IAAI,EAAE,QAAQ,IAAI,CAAC;GACxC,GAAI,YAAY,SAAS,IAAI,EAAE,YAAY,IAAI,CAAC;EAClD;CACF,CAAC;AACH;AASA,SAAS,YAAY,KAAsE;CACzF,IAAI,QAAQ,KAAA,GAAW,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 {
|
|
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 {
|
|
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?:
|
|
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?:
|
|
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?:
|
|
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":"
|
|
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 {
|
|
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 (
|
|
29
|
-
|
|
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
|
-
*
|
|
36
|
-
*
|
|
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
|
|
39
|
+
function labelEnrichments(variants, labelOptions) {
|
|
40
40
|
if (variants.length === 0) return [];
|
|
41
|
-
const
|
|
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:
|
|
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
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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","
|
|
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,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,iBAAiB,OAAO,EAAE;GACvD,EAAE,MAAMA,gCAAAA,WAAW,MAAM;EAC3B;CACF,CAAC,CAAC,CACD,WAAW;CAEd,MAAM,YAAY,QAAQ;CAC1B,OAAO,QAAQ,QAAQ,MAAM;EAC3B,IAAIC,cAAAA,oBAAoB,CAAC,GAAG,OAAO;EACnC,IAAI,CAAC,oBAAoB,EAAE,EAAE,GAAG,OAAO;EACvC,OAAO,cAAc,KAAA,KAAa,UAAU,EAAE,QAAQ,CAAC;CACzD,CAAC;AACH;;;;;AAMA,SAAgB,iBACd,UACA,cACqB;CACrB,IAAI,SAAS,WAAW,GAAG,OAAO,CAAC;CAEnC,MAAM,UAAmB,SAAS,KAAK,aAAa;EAClD,MAAM,QAAQ,QAAQ;EACtB,YAAYC,cAAAA,qBAAqB,OAAO,CAAC,CAAC,KAAK,YAAY,EAAE,MAAM,OAAO,QAAQ,EAAE,EAAE;EACtF,gBAAgB;GACd,QAAQ,CAAC,GAAGC,cAAAA,kBAAkB,OAAO,CAAC;GACtC,YAAYC,cAAAA,sBAAsB,OAAO;EAC3C;CACF,EAAE;CACF,MAAM,SAASC,+BAAAA,qBAAqB,SAAS,YAAY;CAEzD,OAAO,SAAS,KAAK,SAAS,OAA0B;EAAE,IAAI,QAAQ;EAAI,OAAO,OAAO;CAAG,EAAE;AAC/F;AAIA,SAAS,oBAAoB,IAAgC;CAC3D,IAAI,EAAA,GAACC,gCAAAA,qBAAAA,CAAqB,EAAE,GAAG,OAAO;CACtC,MAAM,OAAA,GAAMC,gCAAAA,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,
|
|
3
|
+
import { collectLinkerColumns, hasSingleDataColumn, hitQualifications, queriesQualifications } from "../../columns/utils.js";
|
|
4
4
|
import "../../columns/index.js";
|
|
5
|
-
import { Annotation,
|
|
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 (
|
|
29
|
-
|
|
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
|
-
*
|
|
36
|
-
*
|
|
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
|
|
39
|
+
function labelEnrichments(variants, labelOptions) {
|
|
40
40
|
if (variants.length === 0) return [];
|
|
41
|
-
const
|
|
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:
|
|
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
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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 {
|
|
60
|
+
export { findEnrichmentColumns, labelEnrichments };
|
|
67
61
|
|
|
68
62
|
//# sourceMappingURL=enrichment_discovery.js.map
|