@platforma-sdk/model 1.86.5 → 1.88.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/block_api_v3.d.ts +9 -0
- package/dist/block_api_v3.d.ts.map +1 -1
- package/dist/block_model.cjs +89 -9
- package/dist/block_model.cjs.map +1 -1
- package/dist/block_model.d.ts +81 -19
- package/dist/block_model.d.ts.map +1 -1
- package/dist/block_model.js +89 -9
- package/dist/block_model.js.map +1 -1
- package/dist/block_storage_callbacks.cjs +128 -25
- package/dist/block_storage_callbacks.cjs.map +1 -1
- package/dist/block_storage_callbacks.js +129 -26
- package/dist/block_storage_callbacks.js.map +1 -1
- package/dist/block_storage_facade.cjs.map +1 -1
- package/dist/block_storage_facade.d.ts +37 -4
- package/dist/block_storage_facade.d.ts.map +1 -1
- package/dist/block_storage_facade.js.map +1 -1
- package/dist/columns/column_providers/providers.cjs +2 -10
- package/dist/columns/column_providers/providers.cjs.map +1 -1
- package/dist/columns/column_providers/providers.d.ts.map +1 -1
- package/dist/columns/column_providers/providers.js +3 -11
- package/dist/columns/column_providers/providers.js.map +1 -1
- package/dist/columns/column_recipes/index.cjs +2 -2
- package/dist/columns/column_recipes/index.cjs.map +1 -1
- package/dist/columns/column_recipes/index.d.ts +2 -3
- package/dist/columns/column_recipes/index.d.ts.map +1 -1
- package/dist/columns/column_recipes/index.js +2 -2
- package/dist/columns/column_recipes/index.js.map +1 -1
- package/dist/columns/column_values.cjs +126 -0
- package/dist/columns/column_values.cjs.map +1 -0
- package/dist/columns/column_values.d.ts +65 -0
- package/dist/columns/column_values.d.ts.map +1 -0
- package/dist/columns/column_values.js +124 -0
- package/dist/columns/column_values.js.map +1 -0
- package/dist/columns/data_column.cjs +12 -42
- package/dist/columns/data_column.cjs.map +1 -1
- package/dist/columns/data_column.d.ts +10 -26
- package/dist/columns/data_column.d.ts.map +1 -1
- package/dist/columns/data_column.js +13 -42
- package/dist/columns/data_column.js.map +1 -1
- package/dist/columns/index.cjs +4 -1
- package/dist/columns/index.d.ts +3 -2
- package/dist/columns/index.js +3 -2
- package/dist/index.cjs +6 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.js +4 -2
- package/dist/package.cjs +1 -1
- package/dist/package.js +1 -1
- package/dist/pframe_utils/column_value_options.cjs +85 -0
- package/dist/pframe_utils/column_value_options.cjs.map +1 -0
- package/dist/pframe_utils/column_value_options.d.ts +14 -0
- package/dist/pframe_utils/column_value_options.d.ts.map +1 -0
- package/dist/pframe_utils/column_value_options.js +85 -0
- package/dist/pframe_utils/column_value_options.js.map +1 -0
- package/dist/pframe_utils/index.cjs +2 -0
- package/dist/pframe_utils/index.cjs.map +1 -1
- package/dist/pframe_utils/index.d.ts +2 -1
- package/dist/pframe_utils/index.d.ts.map +1 -1
- package/dist/pframe_utils/index.js +2 -1
- package/dist/pframe_utils/index.js.map +1 -1
- package/package.json +7 -7
- package/src/args_issues.test.ts +532 -0
- package/src/block_api_v3.ts +10 -0
- package/src/block_model.ts +146 -32
- package/src/block_storage_callbacks.ts +174 -43
- package/src/block_storage_facade.ts +36 -6
- package/src/columns/column_providers/providers.ts +3 -15
- package/src/columns/column_recipes/column_recipes.test.ts +11 -15
- package/src/columns/column_recipes/index.ts +2 -3
- package/src/columns/column_values.test.ts +183 -0
- package/src/columns/column_values.ts +194 -0
- package/src/columns/data_column.test.ts +13 -14
- package/src/columns/data_column.ts +12 -41
- package/src/columns/index.ts +1 -0
- package/src/pframe_utils/column_value_options.test.ts +126 -0
- package/src/pframe_utils/column_value_options.ts +111 -0
- package/src/pframe_utils/index.ts +1 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { GlobalCfgRenderCtx, PColumnDataUniversal } from "../render/internal.js";
|
|
2
|
+
import { DataColumnRecipe } from "./data_column.js";
|
|
3
|
+
import { ColumnRecipe } from "./column_recipes/index.js";
|
|
4
|
+
import { ColumnUniversalId, ColumnValueId, PColumn, PFrameHandle, PObjectId } from "@milaboratories/pl-model-common";
|
|
5
|
+
/** Drop-down option for a value of a column — column-value-id valued. */
|
|
6
|
+
export type ColumnValueOption = {
|
|
7
|
+
readonly value: ColumnValueId;
|
|
8
|
+
readonly label: string;
|
|
9
|
+
};
|
|
10
|
+
/** A column a value picker offers the values of, or labels them by. */
|
|
11
|
+
export type ColumnValueOptionsColumn = ColumnUniversalId | PColumn<undefined | PColumnDataUniversal> | DataColumnRecipe | ColumnRecipe;
|
|
12
|
+
/**
|
|
13
|
+
* What a UI reads the options of a value picker from: a frame holding the value column, and the
|
|
14
|
+
* label column while there is one, as long as the value column is there. `valueColumn` is the
|
|
15
|
+
* column the options are values of, so the UI can tell a model that still describes an earlier
|
|
16
|
+
* pick. `frameColumns` names both columns as the frame holds them.
|
|
17
|
+
*/
|
|
18
|
+
export type ColumnValueOptionsModel = {
|
|
19
|
+
readonly type: "resolving";
|
|
20
|
+
readonly valueColumn: ColumnUniversalId;
|
|
21
|
+
} | {
|
|
22
|
+
readonly type: "absent";
|
|
23
|
+
readonly valueColumn: ColumnUniversalId;
|
|
24
|
+
} | {
|
|
25
|
+
readonly type: "present";
|
|
26
|
+
readonly valueColumn: ColumnUniversalId;
|
|
27
|
+
readonly frame: PFrameHandle;
|
|
28
|
+
readonly frameColumns: {
|
|
29
|
+
readonly value: PObjectId;
|
|
30
|
+
/** `null` when the values label themselves. */
|
|
31
|
+
readonly label: PObjectId | null;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* The model of a value picker over the values of `valueColumn`, for a model output; the UI reads
|
|
36
|
+
* the options through it (`usePlColumnValueOptions`, `PlColumnValueDropdown`). Each option is a
|
|
37
|
+
* value of `valueColumn`, labelled by the value of `labelColumn` in the same row, or by the value
|
|
38
|
+
* itself when no label column is given.
|
|
39
|
+
*
|
|
40
|
+
* `absent` once the value column is gone: a stored id may name a column its upstream block no
|
|
41
|
+
* longer produces. A label column that is gone leaves the values to label themselves; one that is
|
|
42
|
+
* still resolving keeps the model resolving.
|
|
43
|
+
*/
|
|
44
|
+
export declare function createColumnValueOptions(columns: {
|
|
45
|
+
readonly valueColumn: ColumnValueOptionsColumn;
|
|
46
|
+
readonly labelColumn?: ColumnValueOptionsColumn;
|
|
47
|
+
}, deps?: {
|
|
48
|
+
readonly ctx?: GlobalCfgRenderCtx;
|
|
49
|
+
}): ColumnValueOptionsModel;
|
|
50
|
+
/**
|
|
51
|
+
* Distinct `values` of `column` as options, each a column value id naming the column, labelled
|
|
52
|
+
* by the value itself and ordered naturally by label ("R2" before "R10"). Empty values are not
|
|
53
|
+
* offered.
|
|
54
|
+
*/
|
|
55
|
+
export declare function deriveColumnValueOptions(column: ColumnUniversalId, values: readonly string[]): ColumnValueOption[];
|
|
56
|
+
/**
|
|
57
|
+
* Distinct values of `column` among `rows` as options, each a column value id naming the column,
|
|
58
|
+
* labelled by the label of the first row holding the value, and ordered naturally by label ("R2"
|
|
59
|
+
* before "R10"). Empty values are not offered; a value whose label is empty labels itself.
|
|
60
|
+
*/
|
|
61
|
+
export declare function deriveLabelledColumnValueOptions(column: ColumnUniversalId, rows: readonly {
|
|
62
|
+
readonly value: string;
|
|
63
|
+
readonly label: string;
|
|
64
|
+
}[]): ColumnValueOption[];
|
|
65
|
+
//# sourceMappingURL=column_values.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"column_values.d.ts","names":[],"sources":["../../src/columns/column_values.ts"],"mappings":";;;;;YAkBY;WACD,OAAO;WACP;;;YAIC,2BACR,oBACA,oBAAoB,wBACpB,mBACA;;;;;;;YAQQ;WACG;WAA4B,aAAa;;WACzC;WAAyB,aAAa;;WAEtC;WACA,aAAa;WACb,OAAO;WACP;aACE,OAAO;;aAEP,OAAO;;;;;;;;;;;;;wBAcR,yBACd;WACW,aAAa;WACb,cAAc;GAEzB;WAAkB,MAAM;IACvB;;;;;;wBA0Ba,yBACd,QAAQ,mBACR,4BACC;;;;;;wBAYa,iCACd,QAAQ,mBACR;WAA0B;WAAwB;MACjD"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { getCfgRenderCtx } from "../internal.js";
|
|
2
|
+
import { finalizePColumnData } from "../render/api.js";
|
|
3
|
+
import { ColumnRecipe } from "./column_recipes/index.js";
|
|
4
|
+
import { createColumnValueId, extractPObjectId, isPColumn } from "@milaboratories/pl-model-common";
|
|
5
|
+
// src/columns/column_values.ts
|
|
6
|
+
/**
|
|
7
|
+
* The model of a value picker over the values of `valueColumn`, for a model output; the UI reads
|
|
8
|
+
* the options through it (`usePlColumnValueOptions`, `PlColumnValueDropdown`). Each option is a
|
|
9
|
+
* value of `valueColumn`, labelled by the value of `labelColumn` in the same row, or by the value
|
|
10
|
+
* itself when no label column is given.
|
|
11
|
+
*
|
|
12
|
+
* `absent` once the value column is gone: a stored id may name a column its upstream block no
|
|
13
|
+
* longer produces. A label column that is gone leaves the values to label themselves; one that is
|
|
14
|
+
* still resolving keeps the model resolving.
|
|
15
|
+
*/
|
|
16
|
+
function createColumnValueOptions(columns, deps) {
|
|
17
|
+
const ctx = deps?.ctx ?? getCfgRenderCtx();
|
|
18
|
+
const value = frameEntryOf(columns.valueColumn, ctx);
|
|
19
|
+
const valueColumn = value.id;
|
|
20
|
+
if (value.status !== "present") return {
|
|
21
|
+
type: value.status,
|
|
22
|
+
valueColumn
|
|
23
|
+
};
|
|
24
|
+
const label = columns.labelColumn === void 0 ? void 0 : frameEntryOf(columns.labelColumn, ctx);
|
|
25
|
+
if (label?.status === "resolving") return {
|
|
26
|
+
type: "resolving",
|
|
27
|
+
valueColumn
|
|
28
|
+
};
|
|
29
|
+
const labelled = label?.status === "present" && label.frameId !== value.frameId ? label : void 0;
|
|
30
|
+
return {
|
|
31
|
+
type: "present",
|
|
32
|
+
valueColumn,
|
|
33
|
+
frame: ctx.createPFrame(labelled === void 0 ? [value.def] : [value.def, labelled.def]),
|
|
34
|
+
frameColumns: {
|
|
35
|
+
value: value.frameId,
|
|
36
|
+
label: labelled?.frameId ?? null
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Distinct `values` of `column` as options, each a column value id naming the column, labelled
|
|
42
|
+
* by the value itself and ordered naturally by label ("R2" before "R10"). Empty values are not
|
|
43
|
+
* offered.
|
|
44
|
+
*/
|
|
45
|
+
function deriveColumnValueOptions(column, values) {
|
|
46
|
+
return deriveLabelledColumnValueOptions(column, values.map((value) => ({
|
|
47
|
+
value,
|
|
48
|
+
label: value
|
|
49
|
+
})));
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Distinct values of `column` among `rows` as options, each a column value id naming the column,
|
|
53
|
+
* labelled by the label of the first row holding the value, and ordered naturally by label ("R2"
|
|
54
|
+
* before "R10"). Empty values are not offered; a value whose label is empty labels itself.
|
|
55
|
+
*/
|
|
56
|
+
function deriveLabelledColumnValueOptions(column, rows) {
|
|
57
|
+
const options = /* @__PURE__ */ new Map();
|
|
58
|
+
for (const { value, label } of rows) {
|
|
59
|
+
if (value === "" || options.has(value)) continue;
|
|
60
|
+
options.set(value, {
|
|
61
|
+
value: createColumnValueId({
|
|
62
|
+
column,
|
|
63
|
+
value
|
|
64
|
+
}),
|
|
65
|
+
label: label === "" ? value : label
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
return [...options.values()].sort((a, b) => compareNatural(a.label, b.label));
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* A column given by id or by a recipe goes into the frame by its id, which the frame holds as the
|
|
72
|
+
* bare id of its leaf; a materialised column goes in as it is.
|
|
73
|
+
*/
|
|
74
|
+
function frameEntryOf(column, ctx) {
|
|
75
|
+
if (typeof column === "string") return {
|
|
76
|
+
id: column,
|
|
77
|
+
status: ColumnRecipe.getStatus(column, { ctx }),
|
|
78
|
+
frameId: extractPObjectId(column),
|
|
79
|
+
def: column
|
|
80
|
+
};
|
|
81
|
+
if (isPColumn(column)) return {
|
|
82
|
+
id: column.id,
|
|
83
|
+
status: "present",
|
|
84
|
+
frameId: column.id,
|
|
85
|
+
def: finalizePColumnData(column)
|
|
86
|
+
};
|
|
87
|
+
return {
|
|
88
|
+
id: column.id,
|
|
89
|
+
status: column.getDataStatus(),
|
|
90
|
+
frameId: extractPObjectId(column.id),
|
|
91
|
+
def: column.id
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
const CHUNKS = /\d+|\D+/g;
|
|
95
|
+
/**
|
|
96
|
+
* Natural order: runs of digits compare as numbers, other text case-insensitively, so "R2"
|
|
97
|
+
* comes before "R10". The model runtime has no `Intl`.
|
|
98
|
+
*/
|
|
99
|
+
function compareNatural(a, b) {
|
|
100
|
+
const chunksA = a.match(CHUNKS) ?? [];
|
|
101
|
+
const chunksB = b.match(CHUNKS) ?? [];
|
|
102
|
+
for (let i = 0; i < Math.min(chunksA.length, chunksB.length); i++) {
|
|
103
|
+
const order = compareChunks(chunksA[i], chunksB[i]);
|
|
104
|
+
if (order !== 0) return order;
|
|
105
|
+
}
|
|
106
|
+
return chunksA.length - chunksB.length || compareStrings(a, b);
|
|
107
|
+
}
|
|
108
|
+
function compareChunks(a, b) {
|
|
109
|
+
if (isDigits(a) && isDigits(b)) {
|
|
110
|
+
const numberA = a.replace(/^0+(?=\d)/, "");
|
|
111
|
+
const numberB = b.replace(/^0+(?=\d)/, "");
|
|
112
|
+
return numberA.length - numberB.length || compareStrings(numberA, numberB);
|
|
113
|
+
}
|
|
114
|
+
return compareStrings(a.toLowerCase(), b.toLowerCase());
|
|
115
|
+
}
|
|
116
|
+
function isDigits(chunk) {
|
|
117
|
+
return chunk.charCodeAt(0) >= 48 && chunk.charCodeAt(0) <= 57;
|
|
118
|
+
}
|
|
119
|
+
function compareStrings(a, b) {
|
|
120
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
121
|
+
}
|
|
122
|
+
export { createColumnValueOptions, deriveColumnValueOptions, deriveLabelledColumnValueOptions };
|
|
123
|
+
|
|
124
|
+
//# sourceMappingURL=column_values.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"column_values.js","names":[],"sources":["../../src/columns/column_values.ts"],"sourcesContent":["import {\n createColumnValueId,\n extractPObjectId,\n isPColumn,\n type ColumnUniversalId,\n type ColumnValueId,\n type PColumn,\n type PFrameHandle,\n type PObjectId,\n} from \"@milaboratories/pl-model-common\";\nimport { finalizePColumnData } from \"../render/api\";\nimport type { GlobalCfgRenderCtx, PColumnDataUniversal } from \"../render/internal\";\nimport { getCfgRenderCtx } from \"../internal\";\nimport { ColumnRecipe } from \"./column_recipes\";\nimport type { ColumnResolutionStatus } from \"./column_recipes/types\";\nimport type { DataColumnRecipe } from \"./data_column\";\n\n/** Drop-down option for a value of a column — column-value-id valued. */\nexport type ColumnValueOption = {\n readonly value: ColumnValueId;\n readonly label: string;\n};\n\n/** A column a value picker offers the values of, or labels them by. */\nexport type ColumnValueOptionsColumn =\n | ColumnUniversalId\n | PColumn<undefined | PColumnDataUniversal>\n | DataColumnRecipe\n | ColumnRecipe;\n\n/**\n * What a UI reads the options of a value picker from: a frame holding the value column, and the\n * label column while there is one, as long as the value column is there. `valueColumn` is the\n * column the options are values of, so the UI can tell a model that still describes an earlier\n * pick. `frameColumns` names both columns as the frame holds them.\n */\nexport type ColumnValueOptionsModel =\n | { readonly type: \"resolving\"; readonly valueColumn: ColumnUniversalId }\n | { readonly type: \"absent\"; readonly valueColumn: ColumnUniversalId }\n | {\n readonly type: \"present\";\n readonly valueColumn: ColumnUniversalId;\n readonly frame: PFrameHandle;\n readonly frameColumns: {\n readonly value: PObjectId;\n /** `null` when the values label themselves. */\n readonly label: PObjectId | null;\n };\n };\n\n/**\n * The model of a value picker over the values of `valueColumn`, for a model output; the UI reads\n * the options through it (`usePlColumnValueOptions`, `PlColumnValueDropdown`). Each option is a\n * value of `valueColumn`, labelled by the value of `labelColumn` in the same row, or by the value\n * itself when no label column is given.\n *\n * `absent` once the value column is gone: a stored id may name a column its upstream block no\n * longer produces. A label column that is gone leaves the values to label themselves; one that is\n * still resolving keeps the model resolving.\n */\nexport function createColumnValueOptions(\n columns: {\n readonly valueColumn: ColumnValueOptionsColumn;\n readonly labelColumn?: ColumnValueOptionsColumn;\n },\n deps?: { readonly ctx?: GlobalCfgRenderCtx },\n): ColumnValueOptionsModel {\n const ctx = deps?.ctx ?? getCfgRenderCtx();\n const value = frameEntryOf(columns.valueColumn, ctx);\n const valueColumn = value.id;\n if (value.status !== \"present\") return { type: value.status, valueColumn };\n\n const label =\n columns.labelColumn === undefined ? undefined : frameEntryOf(columns.labelColumn, ctx);\n if (label?.status === \"resolving\") return { type: \"resolving\", valueColumn };\n const labelled =\n label?.status === \"present\" && label.frameId !== value.frameId ? label : undefined;\n\n const frame = ctx.createPFrame(labelled === undefined ? [value.def] : [value.def, labelled.def]);\n return {\n type: \"present\",\n valueColumn,\n frame,\n frameColumns: { value: value.frameId, label: labelled?.frameId ?? null },\n };\n}\n\n/**\n * Distinct `values` of `column` as options, each a column value id naming the column, labelled\n * by the value itself and ordered naturally by label (\"R2\" before \"R10\"). Empty values are not\n * offered.\n */\nexport function deriveColumnValueOptions(\n column: ColumnUniversalId,\n values: readonly string[],\n): ColumnValueOption[] {\n return deriveLabelledColumnValueOptions(\n column,\n values.map((value) => ({ value, label: value })),\n );\n}\n\n/**\n * Distinct values of `column` among `rows` as options, each a column value id naming the column,\n * labelled by the label of the first row holding the value, and ordered naturally by label (\"R2\"\n * before \"R10\"). Empty values are not offered; a value whose label is empty labels itself.\n */\nexport function deriveLabelledColumnValueOptions(\n column: ColumnUniversalId,\n rows: readonly { readonly value: string; readonly label: string }[],\n): ColumnValueOption[] {\n const options = new Map<string, ColumnValueOption>();\n for (const { value, label } of rows) {\n if (value === \"\" || options.has(value)) continue;\n options.set(value, {\n value: createColumnValueId({ column, value }),\n label: label === \"\" ? value : label,\n });\n }\n return [...options.values()].sort((a, b) => compareNatural(a.label, b.label));\n}\n\n// Internals\n\n/** A column as a frame is made of it: its id, its status, and what the frame is created from. */\ntype FrameEntry = {\n readonly id: ColumnUniversalId;\n readonly status: ColumnResolutionStatus;\n readonly frameId: PObjectId;\n readonly def: Parameters<GlobalCfgRenderCtx[\"createPFrame\"]>[0][number];\n};\n\n/**\n * A column given by id or by a recipe goes into the frame by its id, which the frame holds as the\n * bare id of its leaf; a materialised column goes in as it is.\n */\nfunction frameEntryOf(column: ColumnValueOptionsColumn, ctx: GlobalCfgRenderCtx): FrameEntry {\n if (typeof column === \"string\") {\n return {\n id: column,\n status: ColumnRecipe.getStatus(column, { ctx }),\n frameId: extractPObjectId(column),\n def: column,\n };\n }\n if (isPColumn<undefined | PColumnDataUniversal>(column)) {\n return {\n id: column.id,\n status: \"present\",\n frameId: column.id,\n def: finalizePColumnData(column),\n };\n }\n return {\n id: column.id,\n status: column.getDataStatus(),\n frameId: extractPObjectId(column.id),\n def: column.id,\n };\n}\n\nconst CHUNKS = /\\d+|\\D+/g;\n\n/**\n * Natural order: runs of digits compare as numbers, other text case-insensitively, so \"R2\"\n * comes before \"R10\". The model runtime has no `Intl`.\n */\nfunction compareNatural(a: string, b: string): number {\n const chunksA = a.match(CHUNKS) ?? [];\n const chunksB = b.match(CHUNKS) ?? [];\n for (let i = 0; i < Math.min(chunksA.length, chunksB.length); i++) {\n const order = compareChunks(chunksA[i], chunksB[i]);\n if (order !== 0) return order;\n }\n return chunksA.length - chunksB.length || compareStrings(a, b);\n}\n\nfunction compareChunks(a: string, b: string): number {\n if (isDigits(a) && isDigits(b)) {\n // Compared as digit strings, so numbers of any length keep their order.\n const numberA = a.replace(/^0+(?=\\d)/, \"\");\n const numberB = b.replace(/^0+(?=\\d)/, \"\");\n return numberA.length - numberB.length || compareStrings(numberA, numberB);\n }\n return compareStrings(a.toLowerCase(), b.toLowerCase());\n}\n\nfunction isDigits(chunk: string): boolean {\n return chunk.charCodeAt(0) >= 48 && chunk.charCodeAt(0) <= 57;\n}\n\nfunction compareStrings(a: string, b: string): number {\n return a < b ? -1 : a > b ? 1 : 0;\n}\n"],"mappings":";;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toolkit = require("es-toolkit");
|
|
|
5
5
|
let lru_cache = require("lru-cache");
|
|
6
6
|
// src/columns/data_column.ts
|
|
7
7
|
/**
|
|
8
|
-
* Thrown by leaf-recipe factories when the requested column is provably
|
|
9
|
-
* absent in the active render ctx — i.e. every relevant accessor reports
|
|
10
|
-
* `inputsLocked` and the column did not appear. Distinct from the
|
|
11
|
-
* `undefined` return that the factories still use for the "resolving" case
|
|
12
|
-
* (the column may still appear later).
|
|
13
|
-
*
|
|
14
|
-
* Catch at the boundary (resolver / filter+sort wiring / data-table assembly)
|
|
15
|
-
* when partial absence should be surfaced to the user rather than silently
|
|
16
|
-
* producing an empty result.
|
|
17
|
-
*/
|
|
18
|
-
var ColumnAbsentError = class extends Error {
|
|
19
|
-
id;
|
|
20
|
-
constructor(id) {
|
|
21
|
-
super(`Column is absent in the active render ctx and will not appear: ${id}`);
|
|
22
|
-
this.id = id;
|
|
23
|
-
this.name = "ColumnAbsentError";
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
/**
|
|
27
8
|
* The leaf-recipe building block: a {@link DataColumnRecipe} whose `id` is a bare
|
|
28
9
|
* {@link PObjectId} and whose readers are bound to a single tree-accessor
|
|
29
10
|
* leaf. Layered encodings (Overridden / Discovered / Filtered) are reified
|
|
@@ -75,19 +56,14 @@ var DataColumnImpl = class DataColumnImpl {
|
|
|
75
56
|
}
|
|
76
57
|
/**
|
|
77
58
|
* Resolve via the ambient {@link ColumnRegistry}. Spec is resolved eagerly:
|
|
78
|
-
* returns `undefined`
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
* exist in this ctx. Data and dataStatus stay lazy.
|
|
59
|
+
* returns `undefined` unless the id names a column whose spec is readable in
|
|
60
|
+
* this ctx — while it is resolving, when it is absent, and when the id names
|
|
61
|
+
* an export that is not a column (a `kind: "File"` object, for example).
|
|
62
|
+
* Data and dataStatus stay lazy.
|
|
83
63
|
*/
|
|
84
64
|
static fromId(id, { ctx } = {}) {
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
if ((0, es_toolkit.isNil)(leaf)) {
|
|
88
|
-
if (registry.isFinal()) throw new ColumnAbsentError(id);
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
65
|
+
const leaf = new _milaboratories_pl_model_common.ColumnRegistry(require_index.getCtxProviders({ ctx })).resolve(id);
|
|
66
|
+
if ((0, es_toolkit.isNil)(leaf)) return void 0;
|
|
91
67
|
return DataColumnImpl.fromAccessor(leaf);
|
|
92
68
|
}
|
|
93
69
|
/** {@link PlRef} wrapper over {@link fromId}. */
|
|
@@ -96,18 +72,13 @@ var DataColumnImpl = class DataColumnImpl {
|
|
|
96
72
|
}
|
|
97
73
|
/**
|
|
98
74
|
* Bind directly to an accessor-backed {@link LeafEntry} — no registry.
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
75
|
+
* Returns `undefined` unless the leaf's spec is readable and is a column
|
|
76
|
+
* spec: while the spec is resolving, when it is absent, and for an export
|
|
77
|
+
* that is not a column.
|
|
102
78
|
*/
|
|
103
79
|
static fromAccessor(entry) {
|
|
104
|
-
if ((0, es_toolkit.isNil)(readSpecAccessor(entry))) {
|
|
105
|
-
if (entry.accessor.getInputsLocked()) throw new ColumnAbsentError(entry.id);
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
80
|
const spec = readSpec(entry);
|
|
109
|
-
if (spec === void 0) return void 0;
|
|
110
|
-
if (!(0, _milaboratories_pl_model_common.isPColumnSpec)(spec)) throw new ColumnAbsentError(entry.id);
|
|
81
|
+
if (spec === void 0 || !(0, _milaboratories_pl_model_common.isPColumnSpec)(spec)) return void 0;
|
|
111
82
|
return new DataColumnImpl(entry.id, {
|
|
112
83
|
getSpec: () => spec,
|
|
113
84
|
getData: () => readDataAccessor(entry),
|
|
@@ -132,8 +103,8 @@ var DataColumnImpl = class DataColumnImpl {
|
|
|
132
103
|
* in the active render ctx. Falls back to the registry's `isFinal()`
|
|
133
104
|
* when the id has no entry — only then we can say `absent` instead of
|
|
134
105
|
* `resolving`. The status tells only whether the spec is readable: for an
|
|
135
|
-
* export that is not a column it is `present`, and the factories
|
|
136
|
-
*
|
|
106
|
+
* export that is not a column it is `present`, and the factories return
|
|
107
|
+
* `undefined`.
|
|
137
108
|
*/
|
|
138
109
|
static getStatusById(id, { ctx } = {}) {
|
|
139
110
|
const registry = new _milaboratories_pl_model_common.ColumnRegistry(require_index.getCtxProviders({ ctx }));
|
|
@@ -243,7 +214,6 @@ function memoizeByEntry(fn) {
|
|
|
243
214
|
return hit.value;
|
|
244
215
|
};
|
|
245
216
|
}
|
|
246
|
-
exports.ColumnAbsentError = ColumnAbsentError;
|
|
247
217
|
exports.DataColumn = DataColumn;
|
|
248
218
|
exports.DataColumnImpl = DataColumnImpl;
|
|
249
219
|
exports.isDataColumn = isDataColumn;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data_column.cjs","names":["ColumnOverriddenRecipe","ColumnRegistry","getCtxProviders","isNil","createGlobalPObjectId","isPColumnSpec","isPlRef","isPColumn","LRUCache"],"sources":["../../src/columns/data_column.ts"],"sourcesContent":["import {\n ColumnRegistry,\n createGlobalPObjectId,\n isPColumn,\n isPColumnSpec,\n isPlRef,\n PlRef,\n PObjectId,\n type ColumnUniversalId,\n type LeafEntry,\n type PColumn,\n type PColumnSpec,\n type PObjectSpec,\n type SpecOverrides,\n type SpecQuery,\n} from \"@milaboratories/pl-model-common\";\nimport type { GlobalCfgRenderCtx, PColumnDataUniversal } from \"../render/internal\";\nimport { getCtxProviders } from \"./column_providers\";\nimport { isNil } from \"es-toolkit\";\nimport { LRUCache } from \"lru-cache\";\nimport { TreeNodeAccessor } from \"../render\";\nimport type {\n ColumnFieldStatus,\n ColumnRecipe,\n ColumnRecipeId,\n ColumnResolutionStatus,\n} from \"./column_recipes/types\";\nimport { ColumnOverriddenRecipe } from \"./column_recipes/column_overrided_recipe\";\n\nexport type DataColumnId = PObjectId;\nexport type ColumnData = undefined | PColumnDataUniversal;\nexport type { ColumnFieldStatus, ColumnResolutionStatus } from \"./column_recipes/types\";\n\n/**\n * A {@link ColumnRecipe} that can be read directly in the sandbox: its\n * {@link getData} is guaranteed to be consistent with {@link getSpec}.\n *\n * This is a *capability*, not a class. Only two recipe shapes carry it — a\n * bare leaf and a spec-override over a bare leaf — because those are the only\n * ones whose data still matches their spec. An axis-filtered recipe drops axes\n * from its spec while the underlying data keeps them, and a discovered recipe\n * only materialises after a join; neither can be read here, so neither\n * implements this interface.\n *\n * Narrow to it with `hasReachableData(recipe)` rather than testing for a concrete\n * class — which recipe classes exist is an implementation detail behind\n * `recipe.id`.\n */\nexport interface DataColumnRecipe<\n ID extends ColumnRecipeId = ColumnRecipeId,\n> extends ColumnRecipe<ID> {\n /** Column data, consistent with {@link ColumnRecipe.getSpec}. */\n getData(): ColumnData;\n}\n\n/**\n * Thrown by leaf-recipe factories when the requested column is provably\n * absent in the active render ctx — i.e. every relevant accessor reports\n * `inputsLocked` and the column did not appear. Distinct from the\n * `undefined` return that the factories still use for the \"resolving\" case\n * (the column may still appear later).\n *\n * Catch at the boundary (resolver / filter+sort wiring / data-table assembly)\n * when partial absence should be surfaced to the user rather than silently\n * producing an empty result.\n */\nexport class ColumnAbsentError extends Error {\n constructor(public readonly id: ColumnUniversalId) {\n super(`Column is absent in the active render ctx and will not appear: ${id}`);\n this.name = \"ColumnAbsentError\";\n }\n}\n\n/**\n * The leaf-recipe building block: a {@link DataColumnRecipe} whose `id` is a bare\n * {@link PObjectId} and whose readers are bound to a single tree-accessor\n * leaf. Layered encodings (Overridden / Discovered / Filtered) are reified\n * through their dedicated recipe classes and reference leaf columns by id.\n *\n * Internal — consumers hold the {@link DataColumnRecipe} interface and construct\n * through the {@link DataColumnRecipe} dispatcher.\n */\nexport class DataColumnImpl implements DataColumnRecipe<PObjectId> {\n private specCache?: { readonly value: PColumnSpec };\n private dataCache?: { readonly value: ColumnData };\n private dataStatusCache?: { readonly value: ColumnFieldStatus };\n\n private constructor(\n public readonly id: PObjectId,\n private readonly options: {\n getSpec: () => PColumnSpec;\n getData: () => ColumnData;\n getDataStatus: () => ColumnFieldStatus;\n },\n ) {}\n\n /** A leaf-recipe references exactly one column — its own id. */\n getReferencedIds(): PObjectId[] {\n return [this.id];\n }\n\n getSpec(): PColumnSpec {\n if (this.specCache === undefined) {\n this.specCache = { value: this.options.getSpec() };\n }\n return this.specCache.value;\n }\n\n /** Leaf-shaped — points straight at `this.id`. */\n getQuery(): SpecQuery {\n return { type: \"column\", column: this.id } as SpecQuery;\n }\n\n getData(): ColumnData {\n if (this.dataCache === undefined) this.dataCache = { value: this.options.getData() };\n return this.dataCache.value;\n }\n\n getDataStatus(): ColumnFieldStatus {\n if (this.dataStatusCache === undefined) {\n this.dataStatusCache = { value: this.options.getDataStatus() };\n }\n return this.dataStatusCache.value;\n }\n\n /**\n * Overlay overrides → produces a {@link ColumnOverriddenRecipe} wrapping\n * this leaf. The leaf itself stays bare (id remains a plain PObjectId);\n * layering lives entirely in the recipe wrappers.\n */\n withSpecs(overrides: SpecOverrides): ColumnRecipe {\n return ColumnOverriddenRecipe.wrap(this, overrides);\n }\n\n /**\n * Resolve via the ambient {@link ColumnRegistry}. Spec is resolved eagerly:\n * returns `undefined` if the leaf isn't reachable yet (resolving). Throws\n * {@link ColumnAbsentError} when every relevant accessor is `inputsLocked`\n * and the column did not appear, or when the id names an export that is not\n * a column (a `kind: \"File\"` object, for example) — the column will not\n * exist in this ctx. Data and dataStatus stay lazy.\n */\n static fromId(\n id: PObjectId,\n { ctx }: { ctx?: GlobalCfgRenderCtx } = {},\n ): undefined | DataColumnRecipe<PObjectId> {\n const registry = new ColumnRegistry(getCtxProviders({ ctx }));\n const leaf = registry.resolve(id);\n if (isNil(leaf)) {\n if (registry.isFinal()) throw new ColumnAbsentError(id);\n return undefined;\n }\n return DataColumnImpl.fromAccessor(leaf);\n }\n\n /** {@link PlRef} wrapper over {@link fromId}. */\n static fromPlRef(ref: PlRef): undefined | DataColumnRecipe<PObjectId> {\n return DataColumnImpl.fromId(createGlobalPObjectId(ref.blockId, ref.name));\n }\n\n /**\n * Bind directly to an accessor-backed {@link LeafEntry} — no registry.\n * Throws {@link ColumnAbsentError} if the leaf has no spec field and its\n * accessor is `inputsLocked`, or if it names an export that is not a column.\n * Returns `undefined` while still resolving.\n */\n static fromAccessor(entry: LeafEntry<TreeNodeAccessor>): undefined | DataColumnRecipe<PObjectId> {\n if (isNil(readSpecAccessor(entry))) {\n if (entry.accessor.getInputsLocked()) throw new ColumnAbsentError(entry.id);\n return undefined;\n }\n const spec = readSpec(entry);\n if (spec === undefined) return undefined;\n if (!isPColumnSpec(spec)) throw new ColumnAbsentError(entry.id);\n return new DataColumnImpl(entry.id, {\n getSpec: () => spec,\n getData: () => readDataAccessor(entry),\n getDataStatus: () => readDataStatus(entry),\n });\n }\n\n /**\n * Wrap a materialised {@link PColumn}. If the input is already a\n * {@link DataColumnRecipe} leaf it is returned as-is.\n */\n static fromColumn(\n column: PColumn<ColumnData> | DataColumnRecipe<PObjectId>,\n ): DataColumnRecipe<PObjectId> {\n if (column instanceof DataColumnImpl) return column;\n // `DataColumnRecipe` is an interface, so `instanceof` above does not remove it\n // from the union. The only implementation carrying a bare `PObjectId` is\n // `DataColumnImpl` (wrappers expose `ColumnUniversalId`), so anything\n // reaching here is a materialised `PColumn`.\n const pColumn = column as PColumn<ColumnData>;\n return new DataColumnImpl(pColumn.id, {\n getSpec: () => pColumn.spec,\n getData: () => pColumn.data,\n getDataStatus: () => \"present\",\n });\n }\n\n /**\n * Distinguishes `present` / `resolving` / `absent` for a {@link PObjectId}\n * in the active render ctx. Falls back to the registry's `isFinal()`\n * when the id has no entry — only then we can say `absent` instead of\n * `resolving`. The status tells only whether the spec is readable: for an\n * export that is not a column it is `present`, and the factories throw\n * {@link ColumnAbsentError}.\n */\n static getStatusById(\n id: PObjectId,\n { ctx }: { ctx?: GlobalCfgRenderCtx } = {},\n ): ColumnResolutionStatus {\n const registry = new ColumnRegistry(getCtxProviders({ ctx }));\n const leaf = registry.resolve(id);\n if (isNil(leaf)) return registry.isFinal() ? \"absent\" : \"resolving\";\n return getLeafEntryStatus(leaf);\n }\n\n /** {@link PlRef} wrapper over {@link getStatusById}. */\n static getStatusByPlRef(\n ref: PlRef,\n opts: { ctx?: GlobalCfgRenderCtx } = {},\n ): ColumnResolutionStatus {\n return DataColumnImpl.getStatusById(createGlobalPObjectId(ref.blockId, ref.name), opts);\n }\n\n /** No registry — reads straight off the entry's accessor. */\n static getStatusByAccessor(entry: LeafEntry<TreeNodeAccessor>): ColumnResolutionStatus {\n return getLeafEntryStatus(entry);\n }\n}\n\n/** Anything the {@link DataColumnRecipe} dispatcher can build a leaf from. */\nexport type DataColumnSource =\n | PObjectId\n | PlRef\n | LeafEntry<TreeNodeAccessor>\n | PColumn<ColumnData>\n | DataColumnRecipe<PObjectId>;\n\n/**\n * Unified dispatcher — picks the right `DataColumnImpl.fromX` by source\n * shape. For ambiguous inputs callers can still use the explicit factories\n * (also attached as properties: `DataColumn.fromId`, `.fromPlRef`,\n * `.fromAccessor`, `.fromColumn`).\n */\nfunction DataColumnDispatch(\n source: DataColumnSource,\n opts: { ctx?: GlobalCfgRenderCtx } = {},\n): undefined | DataColumnRecipe<PObjectId> {\n if (typeof source === \"string\") return DataColumnImpl.fromId(source, opts);\n if (source instanceof DataColumnImpl) return source;\n // `DataColumnRecipe` is an interface — `instanceof` above cannot remove it from\n // the union, and only `DataColumnImpl` implements it with a bare id.\n const rest = source as LeafEntry<TreeNodeAccessor> | PlRef | PColumn<ColumnData>;\n if (\"accessor\" in rest) return DataColumnImpl.fromAccessor(rest);\n if (isPlRef(rest)) return DataColumnImpl.fromPlRef(rest);\n if (isPColumn(rest)) return DataColumnImpl.fromColumn(rest);\n throw new Error(\"DataColumn: unknown source shape\");\n}\n\n/**\n * Polymorphic counterpart to {@link DataColumnDispatch}: returns the\n * {@link ColumnResolutionStatus} for any factory input without constructing\n * the recipe. For already-materialised sources ({@link PColumn} value,\n * existing {@link DataColumnRecipe}) status is `present` by construction.\n */\nfunction DataColumnGetStatus(\n source: DataColumnSource,\n opts: { ctx?: GlobalCfgRenderCtx } = {},\n): ColumnResolutionStatus {\n if (typeof source === \"string\") return DataColumnImpl.getStatusById(source, opts);\n if (source instanceof DataColumnImpl) return \"present\";\n const rest = source as LeafEntry<TreeNodeAccessor> | PlRef | PColumn<ColumnData>;\n if (\"accessor\" in rest) return DataColumnImpl.getStatusByAccessor(rest);\n if (isPlRef(rest)) return DataColumnImpl.getStatusByPlRef(rest, opts);\n if (isPColumn(rest)) return \"present\";\n throw new Error(\"DataColumn.getStatus: unknown source shape\");\n}\n\nexport const DataColumn = Object.assign(DataColumnDispatch, {\n fromId: DataColumnImpl.fromId,\n fromPlRef: DataColumnImpl.fromPlRef,\n fromAccessor: DataColumnImpl.fromAccessor,\n fromColumn: DataColumnImpl.fromColumn,\n getStatus: DataColumnGetStatus,\n getStatusById: DataColumnImpl.getStatusById,\n getStatusByPlRef: DataColumnImpl.getStatusByPlRef,\n getStatusByAccessor: DataColumnImpl.getStatusByAccessor,\n});\n\n/**\n * Type-guard narrowing to a bare leaf — a {@link DataColumnRecipe} whose `id` is a\n * plain {@link PObjectId}.\n */\nexport function isDataColumn(value: unknown): value is DataColumnRecipe<PObjectId> {\n return value instanceof DataColumnImpl;\n}\n\nconst readSpecAccessor = memoizeByEntry(\n ({ accessor, name }: LeafEntry<TreeNodeAccessor>): undefined | TreeNodeAccessor =>\n accessor.traverse({ field: `${name}.spec`, assertFieldType: \"Input\", ignoreError: true }),\n);\n\n/** The leaf's spec, or `undefined` until the spec resource has data. */\nconst readSpec = memoizeByEntry((entry: LeafEntry<TreeNodeAccessor>): undefined | PObjectSpec => {\n const spec = readSpecAccessor(entry);\n if (isNil(spec) || !spec.hasData()) return undefined;\n return spec.getDataAsJson<PObjectSpec>();\n});\n\n/**\n * Per-entry counterpart to {@link readDataStatus}: tells whether the leaf's\n * **spec** can be read in this ctx, and — for the negative cases —\n * distinguishes `resolving` from `absent` via `getInputsLocked()`.\n *\n * - spec field not yet on the entry's accessor + inputs locked → `absent`\n * - spec field not yet on the entry's accessor + still resolving → `resolving`\n * - spec resource present but bytes not yet written → `resolving`\n * (transient — the spec resource is connected, just unfilled)\n * - spec resource present and `hasData()` → `present`\n */\nfunction getLeafEntryStatus(entry: LeafEntry<TreeNodeAccessor>): ColumnResolutionStatus {\n const spec = readSpecAccessor(entry);\n if (isNil(spec)) return entry.accessor.getInputsLocked() ? \"absent\" : \"resolving\";\n if (!spec.hasData()) return \"resolving\";\n return \"present\";\n}\n\nconst readDataAccessor = memoizeByEntry(\n ({ accessor, name }: LeafEntry<TreeNodeAccessor>): undefined | TreeNodeAccessor =>\n accessor.traverse({ field: `${name}.data`, assertFieldType: \"Input\", ignoreError: true }),\n);\n\nconst readDataStatus = memoizeByEntry(\n ({ accessor, name }: LeafEntry<TreeNodeAccessor>): ColumnFieldStatus => {\n if (accessor.listInputFields().includes(`${name}.data`)) return \"present\";\n return accessor.getInputsLocked() ? \"absent\" : \"resolving\";\n },\n);\n\nfunction memoizeByEntry<R>(\n fn: (entry: LeafEntry<TreeNodeAccessor>) => R,\n): (entry: LeafEntry<TreeNodeAccessor>) => R {\n const cache = new LRUCache<string, { value: R }>({ max: 1000 });\n return (entry) => {\n const key = `${entry.accessor.handle}:${entry.name}`;\n let hit = cache.get(key);\n if (!hit) cache.set(key, (hit = { value: fn(entry) }));\n return hit.value;\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAkEA,IAAa,oBAAb,cAAuC,MAAM;CACf;CAA5B,YAAY,IAAuC;EACjD,MAAM,kEAAkE,IAAI;EADlD,KAAA,KAAA;EAE1B,KAAK,OAAO;CACd;AACF;;;;;;;;;;AAWA,IAAa,iBAAb,MAAa,eAAsD;CAM/C;CACC;CANnB;CACA;CACA;CAEA,YACE,IACA,SAKA;EANgB,KAAA,KAAA;EACC,KAAA,UAAA;CAKhB;;CAGH,mBAAgC;EAC9B,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G,OAAO,MAAM,SAAS,gBAAgB,IAAI,WAAW;CACtE,IAAI,CAAC,KAAK,QAAQ,GAAG,OAAO;CAC5B,OAAO;AACT;AAEA,MAAM,mBAAmB,gBACtB,EAAE,UAAU,WACX,SAAS,SAAS;CAAE,OAAO,GAAG,KAAK;CAAQ,iBAAiB;CAAS,aAAa;AAAK,CAAC,CAC5F;AAEA,MAAM,iBAAiB,gBACpB,EAAE,UAAU,WAA2D;CACtE,IAAI,SAAS,gBAAgB,CAAC,CAAC,SAAS,GAAG,KAAK,MAAM,GAAG,OAAO;CAChE,OAAO,SAAS,gBAAgB,IAAI,WAAW;AACjD,CACF;AAEA,SAAS,eACP,IAC2C;CAC3C,MAAM,QAAQ,IAAIK,UAAAA,SAA+B,EAAE,KAAK,IAAK,CAAC;CAC9D,QAAQ,UAAU;EAChB,MAAM,MAAM,GAAG,MAAM,SAAS,OAAO,GAAG,MAAM;EAC9C,IAAI,MAAM,MAAM,IAAI,GAAG;EACvB,IAAI,CAAC,KAAK,MAAM,IAAI,KAAM,MAAM,EAAE,OAAO,GAAG,KAAK,EAAE,CAAE;EACrD,OAAO,IAAI;CACb;AACF"}
|
|
1
|
+
{"version":3,"file":"data_column.cjs","names":["ColumnOverriddenRecipe","ColumnRegistry","getCtxProviders","isNil","createGlobalPObjectId","isPColumnSpec","isPlRef","isPColumn","LRUCache"],"sources":["../../src/columns/data_column.ts"],"sourcesContent":["import {\n ColumnRegistry,\n createGlobalPObjectId,\n isPColumn,\n isPColumnSpec,\n isPlRef,\n PlRef,\n PObjectId,\n type LeafEntry,\n type PColumn,\n type PColumnSpec,\n type PObjectSpec,\n type SpecOverrides,\n type SpecQuery,\n} from \"@milaboratories/pl-model-common\";\nimport type { GlobalCfgRenderCtx, PColumnDataUniversal } from \"../render/internal\";\nimport { getCtxProviders } from \"./column_providers\";\nimport { isNil } from \"es-toolkit\";\nimport { LRUCache } from \"lru-cache\";\nimport { TreeNodeAccessor } from \"../render\";\nimport type {\n ColumnFieldStatus,\n ColumnRecipe,\n ColumnRecipeId,\n ColumnResolutionStatus,\n} from \"./column_recipes/types\";\nimport { ColumnOverriddenRecipe } from \"./column_recipes/column_overrided_recipe\";\n\nexport type DataColumnId = PObjectId;\nexport type ColumnData = undefined | PColumnDataUniversal;\nexport type { ColumnFieldStatus, ColumnResolutionStatus } from \"./column_recipes/types\";\n\n/**\n * A {@link ColumnRecipe} that can be read directly in the sandbox: its\n * {@link getData} is guaranteed to be consistent with {@link getSpec}.\n *\n * This is a *capability*, not a class. Only two recipe shapes carry it — a\n * bare leaf and a spec-override over a bare leaf — because those are the only\n * ones whose data still matches their spec. An axis-filtered recipe drops axes\n * from its spec while the underlying data keeps them, and a discovered recipe\n * only materialises after a join; neither can be read here, so neither\n * implements this interface.\n *\n * Narrow to it with `hasReachableData(recipe)` rather than testing for a concrete\n * class — which recipe classes exist is an implementation detail behind\n * `recipe.id`.\n */\nexport interface DataColumnRecipe<\n ID extends ColumnRecipeId = ColumnRecipeId,\n> extends ColumnRecipe<ID> {\n /** Column data, consistent with {@link ColumnRecipe.getSpec}. */\n getData(): ColumnData;\n}\n\n/**\n * The leaf-recipe building block: a {@link DataColumnRecipe} whose `id` is a bare\n * {@link PObjectId} and whose readers are bound to a single tree-accessor\n * leaf. Layered encodings (Overridden / Discovered / Filtered) are reified\n * through their dedicated recipe classes and reference leaf columns by id.\n *\n * Internal — consumers hold the {@link DataColumnRecipe} interface and construct\n * through the {@link DataColumnRecipe} dispatcher.\n */\nexport class DataColumnImpl implements DataColumnRecipe<PObjectId> {\n private specCache?: { readonly value: PColumnSpec };\n private dataCache?: { readonly value: ColumnData };\n private dataStatusCache?: { readonly value: ColumnFieldStatus };\n\n private constructor(\n public readonly id: PObjectId,\n private readonly options: {\n getSpec: () => PColumnSpec;\n getData: () => ColumnData;\n getDataStatus: () => ColumnFieldStatus;\n },\n ) {}\n\n /** A leaf-recipe references exactly one column — its own id. */\n getReferencedIds(): PObjectId[] {\n return [this.id];\n }\n\n getSpec(): PColumnSpec {\n if (this.specCache === undefined) {\n this.specCache = { value: this.options.getSpec() };\n }\n return this.specCache.value;\n }\n\n /** Leaf-shaped — points straight at `this.id`. */\n getQuery(): SpecQuery {\n return { type: \"column\", column: this.id } as SpecQuery;\n }\n\n getData(): ColumnData {\n if (this.dataCache === undefined) this.dataCache = { value: this.options.getData() };\n return this.dataCache.value;\n }\n\n getDataStatus(): ColumnFieldStatus {\n if (this.dataStatusCache === undefined) {\n this.dataStatusCache = { value: this.options.getDataStatus() };\n }\n return this.dataStatusCache.value;\n }\n\n /**\n * Overlay overrides → produces a {@link ColumnOverriddenRecipe} wrapping\n * this leaf. The leaf itself stays bare (id remains a plain PObjectId);\n * layering lives entirely in the recipe wrappers.\n */\n withSpecs(overrides: SpecOverrides): ColumnRecipe {\n return ColumnOverriddenRecipe.wrap(this, overrides);\n }\n\n /**\n * Resolve via the ambient {@link ColumnRegistry}. Spec is resolved eagerly:\n * returns `undefined` unless the id names a column whose spec is readable in\n * this ctx — while it is resolving, when it is absent, and when the id names\n * an export that is not a column (a `kind: \"File\"` object, for example).\n * Data and dataStatus stay lazy.\n */\n static fromId(\n id: PObjectId,\n { ctx }: { ctx?: GlobalCfgRenderCtx } = {},\n ): undefined | DataColumnRecipe<PObjectId> {\n const leaf = new ColumnRegistry(getCtxProviders({ ctx })).resolve(id);\n if (isNil(leaf)) return undefined;\n return DataColumnImpl.fromAccessor(leaf);\n }\n\n /** {@link PlRef} wrapper over {@link fromId}. */\n static fromPlRef(ref: PlRef): undefined | DataColumnRecipe<PObjectId> {\n return DataColumnImpl.fromId(createGlobalPObjectId(ref.blockId, ref.name));\n }\n\n /**\n * Bind directly to an accessor-backed {@link LeafEntry} — no registry.\n * Returns `undefined` unless the leaf's spec is readable and is a column\n * spec: while the spec is resolving, when it is absent, and for an export\n * that is not a column.\n */\n static fromAccessor(entry: LeafEntry<TreeNodeAccessor>): undefined | DataColumnRecipe<PObjectId> {\n const spec = readSpec(entry);\n if (spec === undefined || !isPColumnSpec(spec)) return undefined;\n return new DataColumnImpl(entry.id, {\n getSpec: () => spec,\n getData: () => readDataAccessor(entry),\n getDataStatus: () => readDataStatus(entry),\n });\n }\n\n /**\n * Wrap a materialised {@link PColumn}. If the input is already a\n * {@link DataColumnRecipe} leaf it is returned as-is.\n */\n static fromColumn(\n column: PColumn<ColumnData> | DataColumnRecipe<PObjectId>,\n ): DataColumnRecipe<PObjectId> {\n if (column instanceof DataColumnImpl) return column;\n // `DataColumnRecipe` is an interface, so `instanceof` above does not remove it\n // from the union. The only implementation carrying a bare `PObjectId` is\n // `DataColumnImpl` (wrappers expose `ColumnUniversalId`), so anything\n // reaching here is a materialised `PColumn`.\n const pColumn = column as PColumn<ColumnData>;\n return new DataColumnImpl(pColumn.id, {\n getSpec: () => pColumn.spec,\n getData: () => pColumn.data,\n getDataStatus: () => \"present\",\n });\n }\n\n /**\n * Distinguishes `present` / `resolving` / `absent` for a {@link PObjectId}\n * in the active render ctx. Falls back to the registry's `isFinal()`\n * when the id has no entry — only then we can say `absent` instead of\n * `resolving`. The status tells only whether the spec is readable: for an\n * export that is not a column it is `present`, and the factories return\n * `undefined`.\n */\n static getStatusById(\n id: PObjectId,\n { ctx }: { ctx?: GlobalCfgRenderCtx } = {},\n ): ColumnResolutionStatus {\n const registry = new ColumnRegistry(getCtxProviders({ ctx }));\n const leaf = registry.resolve(id);\n if (isNil(leaf)) return registry.isFinal() ? \"absent\" : \"resolving\";\n return getLeafEntryStatus(leaf);\n }\n\n /** {@link PlRef} wrapper over {@link getStatusById}. */\n static getStatusByPlRef(\n ref: PlRef,\n opts: { ctx?: GlobalCfgRenderCtx } = {},\n ): ColumnResolutionStatus {\n return DataColumnImpl.getStatusById(createGlobalPObjectId(ref.blockId, ref.name), opts);\n }\n\n /** No registry — reads straight off the entry's accessor. */\n static getStatusByAccessor(entry: LeafEntry<TreeNodeAccessor>): ColumnResolutionStatus {\n return getLeafEntryStatus(entry);\n }\n}\n\n/** Anything the {@link DataColumnRecipe} dispatcher can build a leaf from. */\nexport type DataColumnSource =\n | PObjectId\n | PlRef\n | LeafEntry<TreeNodeAccessor>\n | PColumn<ColumnData>\n | DataColumnRecipe<PObjectId>;\n\n/**\n * Unified dispatcher — picks the right `DataColumnImpl.fromX` by source\n * shape. For ambiguous inputs callers can still use the explicit factories\n * (also attached as properties: `DataColumn.fromId`, `.fromPlRef`,\n * `.fromAccessor`, `.fromColumn`).\n */\nfunction DataColumnDispatch(\n source: DataColumnSource,\n opts: { ctx?: GlobalCfgRenderCtx } = {},\n): undefined | DataColumnRecipe<PObjectId> {\n if (typeof source === \"string\") return DataColumnImpl.fromId(source, opts);\n if (source instanceof DataColumnImpl) return source;\n // `DataColumnRecipe` is an interface — `instanceof` above cannot remove it from\n // the union, and only `DataColumnImpl` implements it with a bare id.\n const rest = source as LeafEntry<TreeNodeAccessor> | PlRef | PColumn<ColumnData>;\n if (\"accessor\" in rest) return DataColumnImpl.fromAccessor(rest);\n if (isPlRef(rest)) return DataColumnImpl.fromPlRef(rest);\n if (isPColumn(rest)) return DataColumnImpl.fromColumn(rest);\n throw new Error(\"DataColumn: unknown source shape\");\n}\n\n/**\n * Polymorphic counterpart to {@link DataColumnDispatch}: returns the\n * {@link ColumnResolutionStatus} for any factory input without constructing\n * the recipe. For already-materialised sources ({@link PColumn} value,\n * existing {@link DataColumnRecipe}) status is `present` by construction.\n */\nfunction DataColumnGetStatus(\n source: DataColumnSource,\n opts: { ctx?: GlobalCfgRenderCtx } = {},\n): ColumnResolutionStatus {\n if (typeof source === \"string\") return DataColumnImpl.getStatusById(source, opts);\n if (source instanceof DataColumnImpl) return \"present\";\n const rest = source as LeafEntry<TreeNodeAccessor> | PlRef | PColumn<ColumnData>;\n if (\"accessor\" in rest) return DataColumnImpl.getStatusByAccessor(rest);\n if (isPlRef(rest)) return DataColumnImpl.getStatusByPlRef(rest, opts);\n if (isPColumn(rest)) return \"present\";\n throw new Error(\"DataColumn.getStatus: unknown source shape\");\n}\n\nexport const DataColumn = Object.assign(DataColumnDispatch, {\n fromId: DataColumnImpl.fromId,\n fromPlRef: DataColumnImpl.fromPlRef,\n fromAccessor: DataColumnImpl.fromAccessor,\n fromColumn: DataColumnImpl.fromColumn,\n getStatus: DataColumnGetStatus,\n getStatusById: DataColumnImpl.getStatusById,\n getStatusByPlRef: DataColumnImpl.getStatusByPlRef,\n getStatusByAccessor: DataColumnImpl.getStatusByAccessor,\n});\n\n/**\n * Type-guard narrowing to a bare leaf — a {@link DataColumnRecipe} whose `id` is a\n * plain {@link PObjectId}.\n */\nexport function isDataColumn(value: unknown): value is DataColumnRecipe<PObjectId> {\n return value instanceof DataColumnImpl;\n}\n\nconst readSpecAccessor = memoizeByEntry(\n ({ accessor, name }: LeafEntry<TreeNodeAccessor>): undefined | TreeNodeAccessor =>\n accessor.traverse({ field: `${name}.spec`, assertFieldType: \"Input\", ignoreError: true }),\n);\n\n/** The leaf's spec, or `undefined` until the spec resource has data. */\nconst readSpec = memoizeByEntry((entry: LeafEntry<TreeNodeAccessor>): undefined | PObjectSpec => {\n const spec = readSpecAccessor(entry);\n if (isNil(spec) || !spec.hasData()) return undefined;\n return spec.getDataAsJson<PObjectSpec>();\n});\n\n/**\n * Per-entry counterpart to {@link readDataStatus}: tells whether the leaf's\n * **spec** can be read in this ctx, and — for the negative cases —\n * distinguishes `resolving` from `absent` via `getInputsLocked()`.\n *\n * - spec field not yet on the entry's accessor + inputs locked → `absent`\n * - spec field not yet on the entry's accessor + still resolving → `resolving`\n * - spec resource present but bytes not yet written → `resolving`\n * (transient — the spec resource is connected, just unfilled)\n * - spec resource present and `hasData()` → `present`\n */\nfunction getLeafEntryStatus(entry: LeafEntry<TreeNodeAccessor>): ColumnResolutionStatus {\n const spec = readSpecAccessor(entry);\n if (isNil(spec)) return entry.accessor.getInputsLocked() ? \"absent\" : \"resolving\";\n if (!spec.hasData()) return \"resolving\";\n return \"present\";\n}\n\nconst readDataAccessor = memoizeByEntry(\n ({ accessor, name }: LeafEntry<TreeNodeAccessor>): undefined | TreeNodeAccessor =>\n accessor.traverse({ field: `${name}.data`, assertFieldType: \"Input\", ignoreError: true }),\n);\n\nconst readDataStatus = memoizeByEntry(\n ({ accessor, name }: LeafEntry<TreeNodeAccessor>): ColumnFieldStatus => {\n if (accessor.listInputFields().includes(`${name}.data`)) return \"present\";\n return accessor.getInputsLocked() ? \"absent\" : \"resolving\";\n },\n);\n\nfunction memoizeByEntry<R>(\n fn: (entry: LeafEntry<TreeNodeAccessor>) => R,\n): (entry: LeafEntry<TreeNodeAccessor>) => R {\n const cache = new LRUCache<string, { value: R }>({ max: 1000 });\n return (entry) => {\n const key = `${entry.accessor.handle}:${entry.name}`;\n let hit = cache.get(key);\n if (!hit) cache.set(key, (hit = { value: fn(entry) }));\n return hit.value;\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;AA+DA,IAAa,iBAAb,MAAa,eAAsD;CAM/C;CACC;CANnB;CACA;CACA;CAEA,YACE,IACA,SAKA;EANgB,KAAA,KAAA;EACC,KAAA,UAAA;CAKhB;;CAGH,mBAAgC;EAC9B,OAAO,CAAC,KAAK,EAAE;CACjB;CAEA,UAAuB;EACrB,IAAI,KAAK,cAAc,KAAA,GACrB,KAAK,YAAY,EAAE,OAAO,KAAK,QAAQ,QAAQ,EAAE;EAEnD,OAAO,KAAK,UAAU;CACxB;;CAGA,WAAsB;EACpB,OAAO;GAAE,MAAM;GAAU,QAAQ,KAAK;EAAG;CAC3C;CAEA,UAAsB;EACpB,IAAI,KAAK,cAAc,KAAA,GAAW,KAAK,YAAY,EAAE,OAAO,KAAK,QAAQ,QAAQ,EAAE;EACnF,OAAO,KAAK,UAAU;CACxB;CAEA,gBAAmC;EACjC,IAAI,KAAK,oBAAoB,KAAA,GAC3B,KAAK,kBAAkB,EAAE,OAAO,KAAK,QAAQ,cAAc,EAAE;EAE/D,OAAO,KAAK,gBAAgB;CAC9B;;;;;;CAOA,UAAU,WAAwC;EAChD,OAAOA,gCAAAA,uBAAuB,KAAK,MAAM,S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
3
3
|
import "../render/index.js";
|
|
4
4
|
import { ColumnFieldStatus, ColumnRecipe, ColumnRecipeId, ColumnResolutionStatus } from "./column_recipes/types.js";
|
|
5
|
-
import {
|
|
5
|
+
import { LeafEntry, PColumn, PColumnSpec, PObjectId, PlRef, SpecOverrides, SpecQuery } from "@milaboratories/pl-model-common";
|
|
6
6
|
export type DataColumnId = PObjectId;
|
|
7
7
|
export type ColumnData = undefined | PColumnDataUniversal;
|
|
8
8
|
/**
|
|
@@ -24,21 +24,6 @@ export interface DataColumnRecipe<ID extends ColumnRecipeId = ColumnRecipeId> ex
|
|
|
24
24
|
/** Column data, consistent with {@link ColumnRecipe.getSpec}. */
|
|
25
25
|
getData(): ColumnData;
|
|
26
26
|
}
|
|
27
|
-
/**
|
|
28
|
-
* Thrown by leaf-recipe factories when the requested column is provably
|
|
29
|
-
* absent in the active render ctx — i.e. every relevant accessor reports
|
|
30
|
-
* `inputsLocked` and the column did not appear. Distinct from the
|
|
31
|
-
* `undefined` return that the factories still use for the "resolving" case
|
|
32
|
-
* (the column may still appear later).
|
|
33
|
-
*
|
|
34
|
-
* Catch at the boundary (resolver / filter+sort wiring / data-table assembly)
|
|
35
|
-
* when partial absence should be surfaced to the user rather than silently
|
|
36
|
-
* producing an empty result.
|
|
37
|
-
*/
|
|
38
|
-
export declare class ColumnAbsentError extends Error {
|
|
39
|
-
readonly id: ColumnUniversalId;
|
|
40
|
-
constructor(id: ColumnUniversalId);
|
|
41
|
-
}
|
|
42
27
|
/**
|
|
43
28
|
* The leaf-recipe building block: a {@link DataColumnRecipe} whose `id` is a bare
|
|
44
29
|
* {@link PObjectId} and whose readers are bound to a single tree-accessor
|
|
@@ -70,11 +55,10 @@ export declare class DataColumnImpl implements DataColumnRecipe<PObjectId> {
|
|
|
70
55
|
withSpecs(overrides: SpecOverrides): ColumnRecipe;
|
|
71
56
|
/**
|
|
72
57
|
* Resolve via the ambient {@link ColumnRegistry}. Spec is resolved eagerly:
|
|
73
|
-
* returns `undefined`
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
* exist in this ctx. Data and dataStatus stay lazy.
|
|
58
|
+
* returns `undefined` unless the id names a column whose spec is readable in
|
|
59
|
+
* this ctx — while it is resolving, when it is absent, and when the id names
|
|
60
|
+
* an export that is not a column (a `kind: "File"` object, for example).
|
|
61
|
+
* Data and dataStatus stay lazy.
|
|
78
62
|
*/
|
|
79
63
|
static fromId(id: PObjectId, { ctx }?: {
|
|
80
64
|
ctx?: GlobalCfgRenderCtx;
|
|
@@ -83,9 +67,9 @@ export declare class DataColumnImpl implements DataColumnRecipe<PObjectId> {
|
|
|
83
67
|
static fromPlRef(ref: PlRef): undefined | DataColumnRecipe<PObjectId>;
|
|
84
68
|
/**
|
|
85
69
|
* Bind directly to an accessor-backed {@link LeafEntry} — no registry.
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
70
|
+
* Returns `undefined` unless the leaf's spec is readable and is a column
|
|
71
|
+
* spec: while the spec is resolving, when it is absent, and for an export
|
|
72
|
+
* that is not a column.
|
|
89
73
|
*/
|
|
90
74
|
static fromAccessor(entry: LeafEntry<TreeNodeAccessor>): undefined | DataColumnRecipe<PObjectId>;
|
|
91
75
|
/**
|
|
@@ -98,8 +82,8 @@ export declare class DataColumnImpl implements DataColumnRecipe<PObjectId> {
|
|
|
98
82
|
* in the active render ctx. Falls back to the registry's `isFinal()`
|
|
99
83
|
* when the id has no entry — only then we can say `absent` instead of
|
|
100
84
|
* `resolving`. The status tells only whether the spec is readable: for an
|
|
101
|
-
* export that is not a column it is `present`, and the factories
|
|
102
|
-
*
|
|
85
|
+
* export that is not a column it is `present`, and the factories return
|
|
86
|
+
* `undefined`.
|
|
103
87
|
*/
|
|
104
88
|
static getStatusById(id: PObjectId, { ctx }?: {
|
|
105
89
|
ctx?: GlobalCfgRenderCtx;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data_column.d.ts","names":[],"sources":["../../src/columns/data_column.ts"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"data_column.d.ts","names":[],"sources":["../../src/columns/data_column.ts"],"mappings":";;;;;YA4BY,eAAe;YACf,yBAAyB;;;;;;;;;;;;;;;;iBAkBpB,iBACf,WAAW,iBAAiB,wBACpB,aAAa;;EAErB,WAAW;;;;;;;;;;;qBAYA,0BAA0B,iBAAiB;WAMpC,IAAI;mBACH;UANX;UACA;UACA;UAED;;EAUP,oBAAoB;EAIpB,WAAW;;EAQX,YAAY;EAIZ,WAAW;EAKX,iBAAiB;;;;;;EAYjB,UAAU,WAAW,gBAAgB;;;;;;;;SAW9B,OACL,IAAI,aACF;IAAS,MAAM;kBACJ,iBAAiB;;SAOzB,UAAU,KAAK,oBAAoB,iBAAiB;;;;;;;SAUpD,aAAa,OAAO,UAAU,gCAAgC,iBAAiB;;;;;SAc/E,WACL,QAAQ,QAAQ,cAAc,iBAAiB,aAC9C,iBAAiB;;;;;;;;;SAsBb,cACL,IAAI,aACF;IAAS,MAAM;MAChB;;SAQI,iBACL,KAAK,OACL;IAAQ,MAAM;MACb;;SAKI,oBAAoB,OAAO,UAAU,oBAAoB;;;YAMtD,mBACR,YACA,QACA,UAAU,oBACV,QAAQ,cACR,iBAAiB;;;;;;;iBAQZ,mBACP,QAAQ,kBACR;EAAQ,MAAM;gBACD,iBAAiB;;;;;;;iBAkBvB,oBACP,QAAQ,kBACR;EAAQ,MAAM;IACb;qBAUU,mBAAU;;;;;;;;;;;;;;wBAeP,aAAa,iBAAiB,SAAS,iBAAiB"}
|
|
@@ -5,25 +5,6 @@ import { isNil } from "es-toolkit";
|
|
|
5
5
|
import { LRUCache } from "lru-cache";
|
|
6
6
|
// src/columns/data_column.ts
|
|
7
7
|
/**
|
|
8
|
-
* Thrown by leaf-recipe factories when the requested column is provably
|
|
9
|
-
* absent in the active render ctx — i.e. every relevant accessor reports
|
|
10
|
-
* `inputsLocked` and the column did not appear. Distinct from the
|
|
11
|
-
* `undefined` return that the factories still use for the "resolving" case
|
|
12
|
-
* (the column may still appear later).
|
|
13
|
-
*
|
|
14
|
-
* Catch at the boundary (resolver / filter+sort wiring / data-table assembly)
|
|
15
|
-
* when partial absence should be surfaced to the user rather than silently
|
|
16
|
-
* producing an empty result.
|
|
17
|
-
*/
|
|
18
|
-
var ColumnAbsentError = class extends Error {
|
|
19
|
-
id;
|
|
20
|
-
constructor(id) {
|
|
21
|
-
super(`Column is absent in the active render ctx and will not appear: ${id}`);
|
|
22
|
-
this.id = id;
|
|
23
|
-
this.name = "ColumnAbsentError";
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
/**
|
|
27
8
|
* The leaf-recipe building block: a {@link DataColumnRecipe} whose `id` is a bare
|
|
28
9
|
* {@link PObjectId} and whose readers are bound to a single tree-accessor
|
|
29
10
|
* leaf. Layered encodings (Overridden / Discovered / Filtered) are reified
|
|
@@ -75,19 +56,14 @@ var DataColumnImpl = class DataColumnImpl {
|
|
|
75
56
|
}
|
|
76
57
|
/**
|
|
77
58
|
* Resolve via the ambient {@link ColumnRegistry}. Spec is resolved eagerly:
|
|
78
|
-
* returns `undefined`
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
* exist in this ctx. Data and dataStatus stay lazy.
|
|
59
|
+
* returns `undefined` unless the id names a column whose spec is readable in
|
|
60
|
+
* this ctx — while it is resolving, when it is absent, and when the id names
|
|
61
|
+
* an export that is not a column (a `kind: "File"` object, for example).
|
|
62
|
+
* Data and dataStatus stay lazy.
|
|
83
63
|
*/
|
|
84
64
|
static fromId(id, { ctx } = {}) {
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
if (isNil(leaf)) {
|
|
88
|
-
if (registry.isFinal()) throw new ColumnAbsentError(id);
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
65
|
+
const leaf = new ColumnRegistry(getCtxProviders({ ctx })).resolve(id);
|
|
66
|
+
if (isNil(leaf)) return void 0;
|
|
91
67
|
return DataColumnImpl.fromAccessor(leaf);
|
|
92
68
|
}
|
|
93
69
|
/** {@link PlRef} wrapper over {@link fromId}. */
|
|
@@ -96,18 +72,13 @@ var DataColumnImpl = class DataColumnImpl {
|
|
|
96
72
|
}
|
|
97
73
|
/**
|
|
98
74
|
* Bind directly to an accessor-backed {@link LeafEntry} — no registry.
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
75
|
+
* Returns `undefined` unless the leaf's spec is readable and is a column
|
|
76
|
+
* spec: while the spec is resolving, when it is absent, and for an export
|
|
77
|
+
* that is not a column.
|
|
102
78
|
*/
|
|
103
79
|
static fromAccessor(entry) {
|
|
104
|
-
if (isNil(readSpecAccessor(entry))) {
|
|
105
|
-
if (entry.accessor.getInputsLocked()) throw new ColumnAbsentError(entry.id);
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
80
|
const spec = readSpec(entry);
|
|
109
|
-
if (spec === void 0) return void 0;
|
|
110
|
-
if (!isPColumnSpec(spec)) throw new ColumnAbsentError(entry.id);
|
|
81
|
+
if (spec === void 0 || !isPColumnSpec(spec)) return void 0;
|
|
111
82
|
return new DataColumnImpl(entry.id, {
|
|
112
83
|
getSpec: () => spec,
|
|
113
84
|
getData: () => readDataAccessor(entry),
|
|
@@ -132,8 +103,8 @@ var DataColumnImpl = class DataColumnImpl {
|
|
|
132
103
|
* in the active render ctx. Falls back to the registry's `isFinal()`
|
|
133
104
|
* when the id has no entry — only then we can say `absent` instead of
|
|
134
105
|
* `resolving`. The status tells only whether the spec is readable: for an
|
|
135
|
-
* export that is not a column it is `present`, and the factories
|
|
136
|
-
*
|
|
106
|
+
* export that is not a column it is `present`, and the factories return
|
|
107
|
+
* `undefined`.
|
|
137
108
|
*/
|
|
138
109
|
static getStatusById(id, { ctx } = {}) {
|
|
139
110
|
const registry = new ColumnRegistry(getCtxProviders({ ctx }));
|
|
@@ -243,6 +214,6 @@ function memoizeByEntry(fn) {
|
|
|
243
214
|
return hit.value;
|
|
244
215
|
};
|
|
245
216
|
}
|
|
246
|
-
export {
|
|
217
|
+
export { DataColumn, DataColumnImpl, isDataColumn };
|
|
247
218
|
|
|
248
219
|
//# sourceMappingURL=data_column.js.map
|