@platforma-sdk/model 1.86.3 → 1.86.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. package/dist/columns/column_providers/providers.cjs +10 -2
  2. package/dist/columns/column_providers/providers.cjs.map +1 -1
  3. package/dist/columns/column_providers/providers.d.ts.map +1 -1
  4. package/dist/columns/column_providers/providers.js +11 -3
  5. package/dist/columns/column_providers/providers.js.map +1 -1
  6. package/dist/columns/data_column.cjs +20 -19
  7. package/dist/columns/data_column.cjs.map +1 -1
  8. package/dist/columns/data_column.d.ts +8 -4
  9. package/dist/columns/data_column.d.ts.map +1 -1
  10. package/dist/columns/data_column.js +21 -20
  11. package/dist/columns/data_column.js.map +1 -1
  12. package/dist/components/PlDatasetSelector/build_dataset_options.cjs +1 -1
  13. package/dist/components/PlDatasetSelector/build_dataset_options.cjs.map +1 -1
  14. package/dist/components/PlDatasetSelector/build_dataset_options.js +2 -2
  15. package/dist/components/PlDatasetSelector/build_dataset_options.js.map +1 -1
  16. package/dist/package.cjs +1 -1
  17. package/dist/package.js +1 -1
  18. package/package.json +7 -7
  19. package/src/columns/__test_helpers__/collection_driver.ts +10 -8
  20. package/src/columns/__test_helpers__/stub_registry.ts +6 -8
  21. package/src/columns/column_providers/providers.test.ts +45 -0
  22. package/src/columns/column_providers/providers.ts +20 -7
  23. package/src/columns/columns_collection.test.ts +39 -0
  24. package/src/columns/data_column.test.ts +10 -0
  25. package/src/columns/data_column.ts +23 -19
  26. package/src/components/PlDatasetSelector/build_dataset_options.ts +7 -4
  27. package/src/labels/derive_distinct_labels.test.ts +1 -1
@@ -84,7 +84,7 @@ var AccessorColumnsProviderImpl = class extends _milaboratories_pl_model_common.
84
84
  }
85
85
  getColumns() {
86
86
  if (this.cachedColumns !== void 0) return this.cachedColumns;
87
- return this.cachedColumns = Array.from(this.entries.values()).map((e) => require_data_column.DataColumn.fromAccessor(e)).filter((v) => !(0, es_toolkit.isNil)(v));
87
+ return this.cachedColumns = Array.from(this.entries.values(), columnUnlessAbsent).filter((column) => column !== void 0);
88
88
  }
89
89
  };
90
90
  /**
@@ -106,9 +106,17 @@ var ResultPoolColumnsProviderImpl = class extends _milaboratories_pl_model_commo
106
106
  }
107
107
  getColumns() {
108
108
  if (this.cachedColumns !== void 0) return this.cachedColumns;
109
- return this.cachedColumns = Array.from(this.getPObjectEntries().values()).map((e) => require_data_column.DataColumn.fromAccessor(e)).filter((v) => !(0, es_toolkit.isNil)(v));
109
+ return this.cachedColumns = Array.from(this.getPObjectEntries().values(), columnUnlessAbsent).filter((column) => column !== void 0);
110
110
  }
111
111
  };
112
+ function columnUnlessAbsent(entry) {
113
+ try {
114
+ return require_data_column.DataColumn.fromAccessor(entry);
115
+ } catch (error) {
116
+ if (error instanceof require_data_column.ColumnAbsentError) return void 0;
117
+ throw error;
118
+ }
119
+ }
112
120
  function hashRawPool(rawPool) {
113
121
  return rawPool.map((b) => `${b.blockId}\x1f${b.prodCtx ?? ""}\x1f${b.stagingCtx ?? ""}\x1f${b.prodIncomplete ? 1 : 0}\x1f${b.stagingIncomplete ? 1 : 0}`).join("");
114
122
  }
@@ -1 +1 @@
1
- {"version":3,"file":"providers.cjs","names":["isNil","TreeNodeAccessor","LRUCache","getCfgRenderCtx","DataColumn","AccessorEntriesProvider","ResultPoolEntriesProvider"],"sources":["../../../src/columns/column_providers/providers.ts"],"sourcesContent":["import {\n AccessorEntriesProvider,\n ResultPoolEntriesProvider,\n type PColumn,\n type PObjectId,\n type UpstreamBlockCtx,\n} from \"@milaboratories/pl-model-common\";\nimport { AccessorHandle, PColumnDataUniversal, TreeNodeAccessor } from \"../../render\";\nimport { DataColumn, DataColumnRecipe } from \"../data_column\";\nimport { getCfgRenderCtx } from \"../../internal\";\nimport { isNil } from \"es-toolkit\";\nimport { LRUCache } from \"lru-cache\";\n\n/**\n * Data source for sandbox column-list builders. Has nothing to say about\n * id-resolution — `ColumnRegistry` (in `@milaboratories/pl-model-common`)\n * consumes the separate `ColumnEntriesProvider` interface for that.\n *\n * Same name as the factory function below — they merge into one TS\n * declaration: `ColumnsProvider` is callable AND the interface type.\n */\nexport interface ColumnsProvider {\n /** Returns all currently known PColumn columns as lazy views. */\n getColumns(): DataColumnRecipe<PObjectId>[];\n /** Whether the provider has finished enumerating all its columns. */\n isFinal(): boolean;\n}\n\n/**\n * Unified memoised factory dispatching to the right provider flavour by the\n * source shape:\n * - `TreeNodeAccessor` → {@link AccessorColumnsProvider}\n * (indexed by `root.handle`, walks the accessor tree once per root).\n * - `UpstreamBlockCtx<AccessorHandle>[]` (or omitted — pulled from the\n * ambient ctx) → {@link ResultPoolColumnsProvider}\n * (indexed by a content-hash of the block list).\n *\n * Both branches return cached instances within their LRU window, so repeated\n * calls with the same source skip re-walking / re-hashing.\n */\nexport function ColumnsProvider(\n source?: TreeNodeAccessor | ReadonlyArray<UpstreamBlockCtx<AccessorHandle>>,\n) {\n if (isNil(source) || Array.isArray(source)) {\n return ResultPoolColumnsProvider(source);\n } else if (source instanceof TreeNodeAccessor) {\n return AccessorColumnsProvider(source);\n } else {\n throw new Error(\"Unknown columns provider source\");\n }\n}\n\n/**\n * Memoised constructor — same `root.handle` returns the same\n * {@link AccessorColumnsProviderImpl}, so `indexAccessorRoot` runs once per\n * accessor root (within the LRU window).\n */\nconst _accessorProviderCache = new LRUCache<AccessorHandle, AccessorColumnsProviderImpl>({\n max: 64,\n});\nexport function AccessorColumnsProvider(root: TreeNodeAccessor): AccessorColumnsProvider {\n let provider = _accessorProviderCache.get(root.handle);\n if (provider === undefined) {\n provider = new AccessorColumnsProviderImpl(root);\n _accessorProviderCache.set(root.handle, provider);\n }\n return provider;\n}\n\n/**\n * Memoised constructor — same `rawPool` content returns the same\n * {@link ResultPoolColumnsProviderImpl}, so `indexPoolBlock` runs once per\n * pool snapshot (within the LRU window).\n */\nconst _resultPoolProviderCache = new LRUCache<string, ResultPoolColumnsProviderImpl>({ max: 4 });\nexport function ResultPoolColumnsProvider(\n rawPool: ReadonlyArray<\n UpstreamBlockCtx<AccessorHandle>\n > = getCfgRenderCtx().getUpstreamBlockCtx(),\n): ResultPoolColumnsProvider {\n const key = hashRawPool(rawPool);\n let provider = _resultPoolProviderCache.get(key);\n if (provider === undefined) {\n provider = new ResultPoolColumnsProviderImpl(rawPool);\n _resultPoolProviderCache.set(key, provider);\n }\n return provider;\n}\n\n/**\n * Simple provider wrapping an array of PColumns. Sandbox-only —\n * implements {@link ColumnsProvider} (lazy-view enumeration). It is *not* an\n * id-index source — `ColumnRegistry` does not consume it.\n */\nexport class ArrayColumnsProvider implements ColumnsProvider {\n private readonly columns: DataColumnRecipe<PObjectId>[];\n\n constructor(\n columns: ReadonlyArray<PColumn<undefined | PColumnDataUniversal> | DataColumnRecipe<PObjectId>>,\n private readonly _isFinal: boolean,\n ) {\n this.columns = columns.map((c) => DataColumn.fromColumn(c));\n }\n\n getColumns(): DataColumnRecipe<PObjectId>[] {\n return this.columns;\n }\n\n isFinal(): boolean {\n return this._isFinal;\n }\n}\n\n/**\n * Sandbox-specific provider over a {@link TreeNodeAccessor} root. Uses the\n * accessor's own `resolvePath` as the canonical root path for id construction,\n * and adds `getColumns()` returning {@link DataColumnRecipe<PObjectId>}s on top of the generic\n * entries index.\n */\nexport class AccessorColumnsProviderImpl\n extends AccessorEntriesProvider<TreeNodeAccessor>\n implements ColumnsProvider\n{\n private cachedColumns?: DataColumnRecipe<PObjectId>[];\n\n constructor(root: TreeNodeAccessor) {\n super(root, root.resolvePath);\n }\n\n getColumns(): DataColumnRecipe<PObjectId>[] {\n if (this.cachedColumns !== undefined) return this.cachedColumns;\n return (this.cachedColumns = Array.from(this.entries.values())\n .map((e) => DataColumn.fromAccessor(e))\n .filter((v): v is DataColumnRecipe<PObjectId> => !isNil(v)));\n }\n}\n\n/** Public type alias — value of the same name is the memoised factory above. */\nexport type AccessorColumnsProvider = AccessorColumnsProviderImpl;\n\n/**\n * Sandbox-specific result-pool provider. Accepts the raw handle-shaped blocks\n * returned by {@link GlobalCfgRenderCtxMethods.getUpstreamBlockCtx} and\n * wraps them into {@link TreeNodeAccessor}s, then adds `getColumns()`.\n */\nexport class ResultPoolColumnsProviderImpl\n extends ResultPoolEntriesProvider<TreeNodeAccessor>\n implements ColumnsProvider\n{\n private cachedColumns?: DataColumnRecipe<PObjectId>[];\n\n constructor(\n rawPool: ReadonlyArray<\n UpstreamBlockCtx<AccessorHandle>\n > = getCfgRenderCtx().getUpstreamBlockCtx(),\n ) {\n const blocks = rawPool.map((b) => ({\n blockId: b.blockId,\n prodCtx:\n b.prodCtx !== undefined\n ? new TreeNodeAccessor(b.prodCtx, [b.blockId, \"prodCtx\"])\n : undefined,\n stagingCtx:\n b.stagingCtx !== undefined\n ? new TreeNodeAccessor(b.stagingCtx, [b.blockId, \"stagingCtx\"])\n : undefined,\n prodIncomplete: b.prodIncomplete,\n stagingIncomplete: b.stagingIncomplete,\n }));\n\n super(blocks);\n }\n\n getColumns(): DataColumnRecipe<PObjectId>[] {\n if (this.cachedColumns !== undefined) return this.cachedColumns;\n return (this.cachedColumns = Array.from(this.getPObjectEntries().values())\n .map((e) => DataColumn.fromAccessor(e))\n .filter((v): v is DataColumnRecipe<PObjectId> => !isNil(v)));\n }\n}\n\n/** Public type alias — value of the same name is the memoised factory above. */\nexport type ResultPoolColumnsProvider = ResultPoolColumnsProviderImpl;\n\nfunction hashRawPool(rawPool: ReadonlyArray<UpstreamBlockCtx<AccessorHandle>>): string {\n return rawPool\n .map(\n (b) =>\n `${b.blockId}\\x1f${b.prodCtx ?? \"\"}\\x1f${b.stagingCtx ?? \"\"}\\x1f${\n b.prodIncomplete ? 1 : 0\n }\\x1f${b.stagingIncomplete ? 1 : 0}`,\n )\n .join(\"\\x1e\");\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAwCA,SAAgB,gBACd,QACA;CACA,KAAA,GAAIA,WAAAA,MAAAA,CAAM,MAAM,KAAK,MAAM,QAAQ,MAAM,GACvC,OAAO,0BAA0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W,aAAa,CAAC,CAAC,CAAC,CACtC,QAAQ,MAAwC,EAAA,GAACJ,WAAAA,MAAAA,CAAM,CAAC,CAAC;CAC9D;AACF;;;;;;AAUA,IAAa,gCAAb,cACUM,gCAAAA,0BAEV;CACE;CAEA,YACE,UAEIH,iBAAAA,gBAAgB,CAAC,CAAC,oBAAoB,GAC1C;EACA,MAAM,SAAS,QAAQ,KAAK,OAAO;GACjC,SAAS,EAAE;GACX,SACE,EAAE,YAAY,KAAA,IACV,IAAIF,iBAAAA,iBAAiB,EAAE,SAAS,CAAC,EAAE,SAAS,SAAS,CAAC,IACtD,KAAA;GACN,YACE,EAAE,eAAe,KAAA,IACb,IAAIA,iBAAAA,iBAAiB,EAAE,YAAY,CAAC,EAAE,SAAS,YAAY,CAAC,IAC5D,KAAA;GACN,gBAAgB,EAAE;GAClB,mBAAmB,EAAE;EACvB,EAAE;EAEF,MAAM,MAAM;CACd;CAEA,aAA4C;EAC1C,IAAI,KAAK,kBAAkB,KAAA,GAAW,OAAO,KAAK;EAClD,OAAQ,KAAK,gBAAgB,MAAM,KAAK,KAAK,kBAAkB,CAAC,CAAC,OAAO,CAAC,CAAC,CACvE,KAAK,MAAMG,oBAAAA,WAAW,aAAa,CAAC,CAAC,CAAC,CACtC,QAAQ,MAAwC,EAAA,GAACJ,WAAAA,MAAAA,CAAM,CAAC,CAAC;CAC9D;AACF;AAKA,SAAS,YAAY,SAAkE;CACrF,OAAO,QACJ,KACE,MACC,GAAG,EAAE,QAAQ,MAAM,EAAE,WAAW,GAAG,MAAM,EAAE,cAAc,GAAG,MAC1D,EAAE,iBAAiB,IAAI,EACxB,MAAM,EAAE,oBAAoB,IAAI,GACrC,CAAC,CACA,KAAK,GAAM;AAChB"}
1
+ {"version":3,"file":"providers.cjs","names":["isNil","TreeNodeAccessor","LRUCache","getCfgRenderCtx","DataColumn","AccessorEntriesProvider","ResultPoolEntriesProvider","ColumnAbsentError"],"sources":["../../../src/columns/column_providers/providers.ts"],"sourcesContent":["import {\n AccessorEntriesProvider,\n ResultPoolEntriesProvider,\n type LeafEntry,\n type PColumn,\n type PObjectId,\n type UpstreamBlockCtx,\n} from \"@milaboratories/pl-model-common\";\nimport { AccessorHandle, PColumnDataUniversal, TreeNodeAccessor } from \"../../render\";\nimport { ColumnAbsentError, DataColumn, DataColumnRecipe } from \"../data_column\";\nimport { getCfgRenderCtx } from \"../../internal\";\nimport { isNil } from \"es-toolkit\";\nimport { LRUCache } from \"lru-cache\";\n\n/**\n * Data source for sandbox column-list builders. Has nothing to say about\n * id-resolution — `ColumnRegistry` (in `@milaboratories/pl-model-common`)\n * consumes the separate `ColumnEntriesProvider` interface for that.\n *\n * Same name as the factory function below — they merge into one TS\n * declaration: `ColumnsProvider` is callable AND the interface type.\n */\nexport interface ColumnsProvider {\n /** Returns all currently known PColumn columns as lazy views. */\n getColumns(): DataColumnRecipe<PObjectId>[];\n /** Whether the provider has finished enumerating all its columns. */\n isFinal(): boolean;\n}\n\n/**\n * Unified memoised factory dispatching to the right provider flavour by the\n * source shape:\n * - `TreeNodeAccessor` → {@link AccessorColumnsProvider}\n * (indexed by `root.handle`, walks the accessor tree once per root).\n * - `UpstreamBlockCtx<AccessorHandle>[]` (or omitted — pulled from the\n * ambient ctx) → {@link ResultPoolColumnsProvider}\n * (indexed by a content-hash of the block list).\n *\n * Both branches return cached instances within their LRU window, so repeated\n * calls with the same source skip re-walking / re-hashing.\n */\nexport function ColumnsProvider(\n source?: TreeNodeAccessor | ReadonlyArray<UpstreamBlockCtx<AccessorHandle>>,\n) {\n if (isNil(source) || Array.isArray(source)) {\n return ResultPoolColumnsProvider(source);\n } else if (source instanceof TreeNodeAccessor) {\n return AccessorColumnsProvider(source);\n } else {\n throw new Error(\"Unknown columns provider source\");\n }\n}\n\n/**\n * Memoised constructor — same `root.handle` returns the same\n * {@link AccessorColumnsProviderImpl}, so `indexAccessorRoot` runs once per\n * accessor root (within the LRU window).\n */\nconst _accessorProviderCache = new LRUCache<AccessorHandle, AccessorColumnsProviderImpl>({\n max: 64,\n});\nexport function AccessorColumnsProvider(root: TreeNodeAccessor): AccessorColumnsProvider {\n let provider = _accessorProviderCache.get(root.handle);\n if (provider === undefined) {\n provider = new AccessorColumnsProviderImpl(root);\n _accessorProviderCache.set(root.handle, provider);\n }\n return provider;\n}\n\n/**\n * Memoised constructor — same `rawPool` content returns the same\n * {@link ResultPoolColumnsProviderImpl}, so `indexPoolBlock` runs once per\n * pool snapshot (within the LRU window).\n */\nconst _resultPoolProviderCache = new LRUCache<string, ResultPoolColumnsProviderImpl>({ max: 4 });\nexport function ResultPoolColumnsProvider(\n rawPool: ReadonlyArray<\n UpstreamBlockCtx<AccessorHandle>\n > = getCfgRenderCtx().getUpstreamBlockCtx(),\n): ResultPoolColumnsProvider {\n const key = hashRawPool(rawPool);\n let provider = _resultPoolProviderCache.get(key);\n if (provider === undefined) {\n provider = new ResultPoolColumnsProviderImpl(rawPool);\n _resultPoolProviderCache.set(key, provider);\n }\n return provider;\n}\n\n/**\n * Simple provider wrapping an array of PColumns. Sandbox-only —\n * implements {@link ColumnsProvider} (lazy-view enumeration). It is *not* an\n * id-index source — `ColumnRegistry` does not consume it.\n */\nexport class ArrayColumnsProvider implements ColumnsProvider {\n private readonly columns: DataColumnRecipe<PObjectId>[];\n\n constructor(\n columns: ReadonlyArray<PColumn<undefined | PColumnDataUniversal> | DataColumnRecipe<PObjectId>>,\n private readonly _isFinal: boolean,\n ) {\n this.columns = columns.map((c) => DataColumn.fromColumn(c));\n }\n\n getColumns(): DataColumnRecipe<PObjectId>[] {\n return this.columns;\n }\n\n isFinal(): boolean {\n return this._isFinal;\n }\n}\n\n/**\n * Sandbox-specific provider over a {@link TreeNodeAccessor} root. Uses the\n * accessor's own `resolvePath` as the canonical root path for id construction,\n * and adds `getColumns()` returning {@link DataColumnRecipe<PObjectId>}s on top of the generic\n * entries index.\n */\nexport class AccessorColumnsProviderImpl\n extends AccessorEntriesProvider<TreeNodeAccessor>\n implements ColumnsProvider\n{\n private cachedColumns?: DataColumnRecipe<PObjectId>[];\n\n constructor(root: TreeNodeAccessor) {\n super(root, root.resolvePath);\n }\n\n getColumns(): DataColumnRecipe<PObjectId>[] {\n if (this.cachedColumns !== undefined) return this.cachedColumns;\n return (this.cachedColumns = Array.from(this.entries.values(), columnUnlessAbsent).filter(\n (column) => column !== undefined,\n ));\n }\n}\n\n/** Public type alias — value of the same name is the memoised factory above. */\nexport type AccessorColumnsProvider = AccessorColumnsProviderImpl;\n\n/**\n * Sandbox-specific result-pool provider. Accepts the raw handle-shaped blocks\n * returned by {@link GlobalCfgRenderCtxMethods.getUpstreamBlockCtx} and\n * wraps them into {@link TreeNodeAccessor}s, then adds `getColumns()`.\n */\nexport class ResultPoolColumnsProviderImpl\n extends ResultPoolEntriesProvider<TreeNodeAccessor>\n implements ColumnsProvider\n{\n private cachedColumns?: DataColumnRecipe<PObjectId>[];\n\n constructor(\n rawPool: ReadonlyArray<\n UpstreamBlockCtx<AccessorHandle>\n > = getCfgRenderCtx().getUpstreamBlockCtx(),\n ) {\n const blocks = rawPool.map((b) => ({\n blockId: b.blockId,\n prodCtx:\n b.prodCtx !== undefined\n ? new TreeNodeAccessor(b.prodCtx, [b.blockId, \"prodCtx\"])\n : undefined,\n stagingCtx:\n b.stagingCtx !== undefined\n ? new TreeNodeAccessor(b.stagingCtx, [b.blockId, \"stagingCtx\"])\n : undefined,\n prodIncomplete: b.prodIncomplete,\n stagingIncomplete: b.stagingIncomplete,\n }));\n\n super(blocks);\n }\n\n getColumns(): DataColumnRecipe<PObjectId>[] {\n if (this.cachedColumns !== undefined) return this.cachedColumns;\n return (this.cachedColumns = Array.from(\n this.getPObjectEntries().values(),\n columnUnlessAbsent,\n ).filter((column) => column !== undefined));\n }\n}\n\n/** Public type alias — value of the same name is the memoised factory above. */\nexport type ResultPoolColumnsProvider = ResultPoolColumnsProviderImpl;\n\nfunction columnUnlessAbsent(\n entry: LeafEntry<TreeNodeAccessor>,\n): DataColumnRecipe<PObjectId> | undefined {\n try {\n return DataColumn.fromAccessor(entry);\n } catch (error) {\n if (error instanceof ColumnAbsentError) return undefined;\n throw error;\n }\n}\n\nfunction hashRawPool(rawPool: ReadonlyArray<UpstreamBlockCtx<AccessorHandle>>): string {\n return rawPool\n .map(\n (b) =>\n `${b.blockId}\\x1f${b.prodCtx ?? \"\"}\\x1f${b.stagingCtx ?? \"\"}\\x1f${\n b.prodIncomplete ? 1 : 0\n }\\x1f${b.stagingIncomplete ? 1 : 0}`,\n )\n .join(\"\\x1e\");\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAyCA,SAAgB,gBACd,QACA;CACA,KAAA,GAAIA,WAAAA,MAAAA,CAAM,MAAM,KAAK,MAAM,QAAQ,MAAM,GACvC,OAAO,0BAA0B,MAAM;MAClC,IAAI,kBAAkBC,iBAAAA,kBAC3B,OAAO,wBAAwB,MAAM;MAErC,MAAM,IAAI,MAAM,iCAAiC;AAErD;;;;;;AAOA,MAAM,yBAAyB,IAAIC,UAAAA,SAAsD,EACvF,KAAK,GACP,CAAC;AACD,SAAgB,wBAAwB,MAAiD;CACvF,IAAI,WAAW,uBAAuB,IAAI,KAAK,MAAM;CACrD,IAAI,aAAa,KAAA,GAAW;EAC1B,WAAW,IAAI,4BAA4B,IAAI;EAC/C,uBAAuB,IAAI,KAAK,QAAQ,QAAQ;CAClD;CACA,OAAO;AACT;;;;;;AAOA,MAAM,2BAA2B,IAAIA,UAAAA,SAAgD,EAAE,KAAK,EAAE,CAAC;AAC/F,SAAgB,0BACd,UAEIC,iBAAAA,gBAAgB,CAAC,CAAC,oBAAoB,GACf;CAC3B,MAAM,MAAM,YAAY,OAAO;CAC/B,IAAI,WAAW,yBAAyB,IAAI,GAAG;CAC/C,IAAI,aAAa,KAAA,GAAW;EAC1B,WAAW,IAAI,8BAA8B,OAAO;EACpD,yBAAyB,IAAI,KAAK,QAAQ;CAC5C;CACA,OAAO;AACT;;;;;;AAOA,IAAa,uBAAb,MAA6D;CAKxC;CAJnB;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a,KAAK;CACtC,SAAS,OAAO;EACd,IAAI,iBAAiBG,oBAAAA,mBAAmB,OAAO,KAAA;EAC/C,MAAM;CACR;AACF;AAEA,SAAS,YAAY,SAAkE;CACrF,OAAO,QACJ,KACE,MACC,GAAG,EAAE,QAAQ,MAAM,EAAE,WAAW,GAAG,MAAM,EAAE,cAAc,GAAG,MAC1D,EAAE,iBAAiB,IAAI,EACxB,MAAM,EAAE,oBAAoB,IAAI,GACrC,CAAC,CACA,KAAK,GAAM;AAChB"}
@@ -1 +1 @@
1
- {"version":3,"file":"providers.d.ts","names":[],"sources":["../../../src/columns/column_providers/providers.ts"],"mappings":";;;;;;;;;;;;;iBAqBiB;;EAEf,cAAc,iBAAiB;;EAE/B;;;;;;;;;;;;;;wBAec,gBACd,SAAS,mBAAmB,cAAc,iBAAiB,mBAAgB,8BAAA;wBAmB7D,wBAAwB,MAAM,mBAAmB;wBAejD,0BACd,UAAS,cACP,iBAAiB,mBAElB;;;;;;qBAeU,gCAAgC;mBAKxB;mBAJF;EAEjB,YACE,SAAS,cAAc,oBAAoB,wBAAwB,iBAAiB,aACnE;EAKnB,cAAc,iBAAiB;EAI/B;;;;;;;;qBAWW,oCACH,wBAAwB,6BACrB;UAEH;EAER,YAAY,MAAM;EAIlB,cAAc,iBAAiB;;;YASrB,0BAA0B;;;;;;qBAOzB,sCACH,0BAA0B,6BACvB;UAEH;EAER,YACE,UAAS,cACP,iBAAiB;EAoBrB,cAAc,iBAAiB;;;YASrB,4BAA4B"}
1
+ {"version":3,"file":"providers.d.ts","names":[],"sources":["../../../src/columns/column_providers/providers.ts"],"mappings":";;;;;;;;;;;;;iBAsBiB;;EAEf,cAAc,iBAAiB;;EAE/B;;;;;;;;;;;;;;wBAec,gBACd,SAAS,mBAAmB,cAAc,iBAAiB,mBAAgB,8BAAA;wBAmB7D,wBAAwB,MAAM,mBAAmB;wBAejD,0BACd,UAAS,cACP,iBAAiB,mBAElB;;;;;;qBAeU,gCAAgC;mBAKxB;mBAJF;EAEjB,YACE,SAAS,cAAc,oBAAoB,wBAAwB,iBAAiB,aACnE;EAKnB,cAAc,iBAAiB;EAI/B;;;;;;;;qBAWW,oCACH,wBAAwB,6BACrB;UAEH;EAER,YAAY,MAAM;EAIlB,cAAc,iBAAiB;;;YASrB,0BAA0B;;;;;;qBAOzB,sCACH,0BAA0B,6BACvB;UAEH;EAER,YACE,UAAS,cACP,iBAAiB;EAoBrB,cAAc,iBAAiB;;;YAUrB,4BAA4B"}
@@ -1,7 +1,7 @@
1
1
  import { getCfgRenderCtx } from "../../internal.js";
2
2
  import { TreeNodeAccessor } from "../../render/accessor.js";
3
3
  import "../../render/index.js";
4
- import { DataColumn } from "../data_column.js";
4
+ import { ColumnAbsentError, DataColumn } from "../data_column.js";
5
5
  import { AccessorEntriesProvider, ResultPoolEntriesProvider } from "@milaboratories/pl-model-common";
6
6
  import { isNil } from "es-toolkit";
7
7
  import { LRUCache } from "lru-cache";
@@ -84,7 +84,7 @@ var AccessorColumnsProviderImpl = class extends AccessorEntriesProvider {
84
84
  }
85
85
  getColumns() {
86
86
  if (this.cachedColumns !== void 0) return this.cachedColumns;
87
- return this.cachedColumns = Array.from(this.entries.values()).map((e) => DataColumn.fromAccessor(e)).filter((v) => !isNil(v));
87
+ return this.cachedColumns = Array.from(this.entries.values(), columnUnlessAbsent).filter((column) => column !== void 0);
88
88
  }
89
89
  };
90
90
  /**
@@ -106,9 +106,17 @@ var ResultPoolColumnsProviderImpl = class extends ResultPoolEntriesProvider {
106
106
  }
107
107
  getColumns() {
108
108
  if (this.cachedColumns !== void 0) return this.cachedColumns;
109
- return this.cachedColumns = Array.from(this.getPObjectEntries().values()).map((e) => DataColumn.fromAccessor(e)).filter((v) => !isNil(v));
109
+ return this.cachedColumns = Array.from(this.getPObjectEntries().values(), columnUnlessAbsent).filter((column) => column !== void 0);
110
110
  }
111
111
  };
112
+ function columnUnlessAbsent(entry) {
113
+ try {
114
+ return DataColumn.fromAccessor(entry);
115
+ } catch (error) {
116
+ if (error instanceof ColumnAbsentError) return void 0;
117
+ throw error;
118
+ }
119
+ }
112
120
  function hashRawPool(rawPool) {
113
121
  return rawPool.map((b) => `${b.blockId}\x1f${b.prodCtx ?? ""}\x1f${b.stagingCtx ?? ""}\x1f${b.prodIncomplete ? 1 : 0}\x1f${b.stagingIncomplete ? 1 : 0}`).join("");
114
122
  }
@@ -1 +1 @@
1
- {"version":3,"file":"providers.js","names":[],"sources":["../../../src/columns/column_providers/providers.ts"],"sourcesContent":["import {\n AccessorEntriesProvider,\n ResultPoolEntriesProvider,\n type PColumn,\n type PObjectId,\n type UpstreamBlockCtx,\n} from \"@milaboratories/pl-model-common\";\nimport { AccessorHandle, PColumnDataUniversal, TreeNodeAccessor } from \"../../render\";\nimport { DataColumn, DataColumnRecipe } from \"../data_column\";\nimport { getCfgRenderCtx } from \"../../internal\";\nimport { isNil } from \"es-toolkit\";\nimport { LRUCache } from \"lru-cache\";\n\n/**\n * Data source for sandbox column-list builders. Has nothing to say about\n * id-resolution — `ColumnRegistry` (in `@milaboratories/pl-model-common`)\n * consumes the separate `ColumnEntriesProvider` interface for that.\n *\n * Same name as the factory function below — they merge into one TS\n * declaration: `ColumnsProvider` is callable AND the interface type.\n */\nexport interface ColumnsProvider {\n /** Returns all currently known PColumn columns as lazy views. */\n getColumns(): DataColumnRecipe<PObjectId>[];\n /** Whether the provider has finished enumerating all its columns. */\n isFinal(): boolean;\n}\n\n/**\n * Unified memoised factory dispatching to the right provider flavour by the\n * source shape:\n * - `TreeNodeAccessor` → {@link AccessorColumnsProvider}\n * (indexed by `root.handle`, walks the accessor tree once per root).\n * - `UpstreamBlockCtx<AccessorHandle>[]` (or omitted — pulled from the\n * ambient ctx) → {@link ResultPoolColumnsProvider}\n * (indexed by a content-hash of the block list).\n *\n * Both branches return cached instances within their LRU window, so repeated\n * calls with the same source skip re-walking / re-hashing.\n */\nexport function ColumnsProvider(\n source?: TreeNodeAccessor | ReadonlyArray<UpstreamBlockCtx<AccessorHandle>>,\n) {\n if (isNil(source) || Array.isArray(source)) {\n return ResultPoolColumnsProvider(source);\n } else if (source instanceof TreeNodeAccessor) {\n return AccessorColumnsProvider(source);\n } else {\n throw new Error(\"Unknown columns provider source\");\n }\n}\n\n/**\n * Memoised constructor — same `root.handle` returns the same\n * {@link AccessorColumnsProviderImpl}, so `indexAccessorRoot` runs once per\n * accessor root (within the LRU window).\n */\nconst _accessorProviderCache = new LRUCache<AccessorHandle, AccessorColumnsProviderImpl>({\n max: 64,\n});\nexport function AccessorColumnsProvider(root: TreeNodeAccessor): AccessorColumnsProvider {\n let provider = _accessorProviderCache.get(root.handle);\n if (provider === undefined) {\n provider = new AccessorColumnsProviderImpl(root);\n _accessorProviderCache.set(root.handle, provider);\n }\n return provider;\n}\n\n/**\n * Memoised constructor — same `rawPool` content returns the same\n * {@link ResultPoolColumnsProviderImpl}, so `indexPoolBlock` runs once per\n * pool snapshot (within the LRU window).\n */\nconst _resultPoolProviderCache = new LRUCache<string, ResultPoolColumnsProviderImpl>({ max: 4 });\nexport function ResultPoolColumnsProvider(\n rawPool: ReadonlyArray<\n UpstreamBlockCtx<AccessorHandle>\n > = getCfgRenderCtx().getUpstreamBlockCtx(),\n): ResultPoolColumnsProvider {\n const key = hashRawPool(rawPool);\n let provider = _resultPoolProviderCache.get(key);\n if (provider === undefined) {\n provider = new ResultPoolColumnsProviderImpl(rawPool);\n _resultPoolProviderCache.set(key, provider);\n }\n return provider;\n}\n\n/**\n * Simple provider wrapping an array of PColumns. Sandbox-only —\n * implements {@link ColumnsProvider} (lazy-view enumeration). It is *not* an\n * id-index source — `ColumnRegistry` does not consume it.\n */\nexport class ArrayColumnsProvider implements ColumnsProvider {\n private readonly columns: DataColumnRecipe<PObjectId>[];\n\n constructor(\n columns: ReadonlyArray<PColumn<undefined | PColumnDataUniversal> | DataColumnRecipe<PObjectId>>,\n private readonly _isFinal: boolean,\n ) {\n this.columns = columns.map((c) => DataColumn.fromColumn(c));\n }\n\n getColumns(): DataColumnRecipe<PObjectId>[] {\n return this.columns;\n }\n\n isFinal(): boolean {\n return this._isFinal;\n }\n}\n\n/**\n * Sandbox-specific provider over a {@link TreeNodeAccessor} root. Uses the\n * accessor's own `resolvePath` as the canonical root path for id construction,\n * and adds `getColumns()` returning {@link DataColumnRecipe<PObjectId>}s on top of the generic\n * entries index.\n */\nexport class AccessorColumnsProviderImpl\n extends AccessorEntriesProvider<TreeNodeAccessor>\n implements ColumnsProvider\n{\n private cachedColumns?: DataColumnRecipe<PObjectId>[];\n\n constructor(root: TreeNodeAccessor) {\n super(root, root.resolvePath);\n }\n\n getColumns(): DataColumnRecipe<PObjectId>[] {\n if (this.cachedColumns !== undefined) return this.cachedColumns;\n return (this.cachedColumns = Array.from(this.entries.values())\n .map((e) => DataColumn.fromAccessor(e))\n .filter((v): v is DataColumnRecipe<PObjectId> => !isNil(v)));\n }\n}\n\n/** Public type alias — value of the same name is the memoised factory above. */\nexport type AccessorColumnsProvider = AccessorColumnsProviderImpl;\n\n/**\n * Sandbox-specific result-pool provider. Accepts the raw handle-shaped blocks\n * returned by {@link GlobalCfgRenderCtxMethods.getUpstreamBlockCtx} and\n * wraps them into {@link TreeNodeAccessor}s, then adds `getColumns()`.\n */\nexport class ResultPoolColumnsProviderImpl\n extends ResultPoolEntriesProvider<TreeNodeAccessor>\n implements ColumnsProvider\n{\n private cachedColumns?: DataColumnRecipe<PObjectId>[];\n\n constructor(\n rawPool: ReadonlyArray<\n UpstreamBlockCtx<AccessorHandle>\n > = getCfgRenderCtx().getUpstreamBlockCtx(),\n ) {\n const blocks = rawPool.map((b) => ({\n blockId: b.blockId,\n prodCtx:\n b.prodCtx !== undefined\n ? new TreeNodeAccessor(b.prodCtx, [b.blockId, \"prodCtx\"])\n : undefined,\n stagingCtx:\n b.stagingCtx !== undefined\n ? new TreeNodeAccessor(b.stagingCtx, [b.blockId, \"stagingCtx\"])\n : undefined,\n prodIncomplete: b.prodIncomplete,\n stagingIncomplete: b.stagingIncomplete,\n }));\n\n super(blocks);\n }\n\n getColumns(): DataColumnRecipe<PObjectId>[] {\n if (this.cachedColumns !== undefined) return this.cachedColumns;\n return (this.cachedColumns = Array.from(this.getPObjectEntries().values())\n .map((e) => DataColumn.fromAccessor(e))\n .filter((v): v is DataColumnRecipe<PObjectId> => !isNil(v)));\n }\n}\n\n/** Public type alias — value of the same name is the memoised factory above. */\nexport type ResultPoolColumnsProvider = ResultPoolColumnsProviderImpl;\n\nfunction hashRawPool(rawPool: ReadonlyArray<UpstreamBlockCtx<AccessorHandle>>): string {\n return rawPool\n .map(\n (b) =>\n `${b.blockId}\\x1f${b.prodCtx ?? \"\"}\\x1f${b.stagingCtx ?? \"\"}\\x1f${\n b.prodIncomplete ? 1 : 0\n }\\x1f${b.stagingIncomplete ? 1 : 0}`,\n )\n .join(\"\\x1e\");\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAwCA,SAAgB,gBACd,QACA;CACA,IAAI,MAAM,MAAM,KAAK,MAAM,QAAQ,MAAM,GACvC,OAAO,0BAA0B,MAAM;MAClC,IAAI,kBAAkB,kBAC3B,OAAO,wBAAwB,MAAM;MAErC,MAAM,IAAI,MAAM,iCAAiC;AAErD;;;;;;AAOA,MAAM,yBAAyB,IAAI,SAAsD,EACvF,KAAK,GACP,CAAC;AACD,SAAgB,wBAAwB,MAAiD;CACvF,IAAI,WAAW,uBAAuB,IAAI,KAAK,MAAM;CACrD,IAAI,aAAa,KAAA,GAAW;EAC1B,WAAW,IAAI,4BAA4B,IAAI;EAC/C,uBAAuB,IAAI,KAAK,QAAQ,QAAQ;CAClD;CACA,OAAO;AACT;;;;;;AAOA,MAAM,2BAA2B,IAAI,SAAgD,EAAE,KAAK,EAAE,CAAC;AAC/F,SAAgB,0BACd,UAEI,gBAAgB,CAAC,CAAC,oBAAoB,GACf;CAC3B,MAAM,MAAM,YAAY,OAAO;CAC/B,IAAI,WAAW,yBAAyB,IAAI,GAAG;CAC/C,IAAI,aAAa,KAAA,GAAW;EAC1B,WAA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ACvE,KAAK,MAAM,WAAW,aAAa,CAAC,CAAC,CAAC,CACtC,QAAQ,MAAwC,CAAC,MAAM,CAAC,CAAC;CAC9D;AACF;AAKA,SAAS,YAAY,SAAkE;CACrF,OAAO,QACJ,KACE,MACC,GAAG,EAAE,QAAQ,MAAM,EAAE,WAAW,GAAG,MAAM,EAAE,cAAc,GAAG,MAC1D,EAAE,iBAAiB,IAAI,EACxB,MAAM,EAAE,oBAAoB,IAAI,GACrC,CAAC,CACA,KAAK,GAAM;AAChB"}
1
+ {"version":3,"file":"providers.js","names":[],"sources":["../../../src/columns/column_providers/providers.ts"],"sourcesContent":["import {\n AccessorEntriesProvider,\n ResultPoolEntriesProvider,\n type LeafEntry,\n type PColumn,\n type PObjectId,\n type UpstreamBlockCtx,\n} from \"@milaboratories/pl-model-common\";\nimport { AccessorHandle, PColumnDataUniversal, TreeNodeAccessor } from \"../../render\";\nimport { ColumnAbsentError, DataColumn, DataColumnRecipe } from \"../data_column\";\nimport { getCfgRenderCtx } from \"../../internal\";\nimport { isNil } from \"es-toolkit\";\nimport { LRUCache } from \"lru-cache\";\n\n/**\n * Data source for sandbox column-list builders. Has nothing to say about\n * id-resolution — `ColumnRegistry` (in `@milaboratories/pl-model-common`)\n * consumes the separate `ColumnEntriesProvider` interface for that.\n *\n * Same name as the factory function below — they merge into one TS\n * declaration: `ColumnsProvider` is callable AND the interface type.\n */\nexport interface ColumnsProvider {\n /** Returns all currently known PColumn columns as lazy views. */\n getColumns(): DataColumnRecipe<PObjectId>[];\n /** Whether the provider has finished enumerating all its columns. */\n isFinal(): boolean;\n}\n\n/**\n * Unified memoised factory dispatching to the right provider flavour by the\n * source shape:\n * - `TreeNodeAccessor` → {@link AccessorColumnsProvider}\n * (indexed by `root.handle`, walks the accessor tree once per root).\n * - `UpstreamBlockCtx<AccessorHandle>[]` (or omitted — pulled from the\n * ambient ctx) → {@link ResultPoolColumnsProvider}\n * (indexed by a content-hash of the block list).\n *\n * Both branches return cached instances within their LRU window, so repeated\n * calls with the same source skip re-walking / re-hashing.\n */\nexport function ColumnsProvider(\n source?: TreeNodeAccessor | ReadonlyArray<UpstreamBlockCtx<AccessorHandle>>,\n) {\n if (isNil(source) || Array.isArray(source)) {\n return ResultPoolColumnsProvider(source);\n } else if (source instanceof TreeNodeAccessor) {\n return AccessorColumnsProvider(source);\n } else {\n throw new Error(\"Unknown columns provider source\");\n }\n}\n\n/**\n * Memoised constructor — same `root.handle` returns the same\n * {@link AccessorColumnsProviderImpl}, so `indexAccessorRoot` runs once per\n * accessor root (within the LRU window).\n */\nconst _accessorProviderCache = new LRUCache<AccessorHandle, AccessorColumnsProviderImpl>({\n max: 64,\n});\nexport function AccessorColumnsProvider(root: TreeNodeAccessor): AccessorColumnsProvider {\n let provider = _accessorProviderCache.get(root.handle);\n if (provider === undefined) {\n provider = new AccessorColumnsProviderImpl(root);\n _accessorProviderCache.set(root.handle, provider);\n }\n return provider;\n}\n\n/**\n * Memoised constructor — same `rawPool` content returns the same\n * {@link ResultPoolColumnsProviderImpl}, so `indexPoolBlock` runs once per\n * pool snapshot (within the LRU window).\n */\nconst _resultPoolProviderCache = new LRUCache<string, ResultPoolColumnsProviderImpl>({ max: 4 });\nexport function ResultPoolColumnsProvider(\n rawPool: ReadonlyArray<\n UpstreamBlockCtx<AccessorHandle>\n > = getCfgRenderCtx().getUpstreamBlockCtx(),\n): ResultPoolColumnsProvider {\n const key = hashRawPool(rawPool);\n let provider = _resultPoolProviderCache.get(key);\n if (provider === undefined) {\n provider = new ResultPoolColumnsProviderImpl(rawPool);\n _resultPoolProviderCache.set(key, provider);\n }\n return provider;\n}\n\n/**\n * Simple provider wrapping an array of PColumns. Sandbox-only —\n * implements {@link ColumnsProvider} (lazy-view enumeration). It is *not* an\n * id-index source — `ColumnRegistry` does not consume it.\n */\nexport class ArrayColumnsProvider implements ColumnsProvider {\n private readonly columns: DataColumnRecipe<PObjectId>[];\n\n constructor(\n columns: ReadonlyArray<PColumn<undefined | PColumnDataUniversal> | DataColumnRecipe<PObjectId>>,\n private readonly _isFinal: boolean,\n ) {\n this.columns = columns.map((c) => DataColumn.fromColumn(c));\n }\n\n getColumns(): DataColumnRecipe<PObjectId>[] {\n return this.columns;\n }\n\n isFinal(): boolean {\n return this._isFinal;\n }\n}\n\n/**\n * Sandbox-specific provider over a {@link TreeNodeAccessor} root. Uses the\n * accessor's own `resolvePath` as the canonical root path for id construction,\n * and adds `getColumns()` returning {@link DataColumnRecipe<PObjectId>}s on top of the generic\n * entries index.\n */\nexport class AccessorColumnsProviderImpl\n extends AccessorEntriesProvider<TreeNodeAccessor>\n implements ColumnsProvider\n{\n private cachedColumns?: DataColumnRecipe<PObjectId>[];\n\n constructor(root: TreeNodeAccessor) {\n super(root, root.resolvePath);\n }\n\n getColumns(): DataColumnRecipe<PObjectId>[] {\n if (this.cachedColumns !== undefined) return this.cachedColumns;\n return (this.cachedColumns = Array.from(this.entries.values(), columnUnlessAbsent).filter(\n (column) => column !== undefined,\n ));\n }\n}\n\n/** Public type alias — value of the same name is the memoised factory above. */\nexport type AccessorColumnsProvider = AccessorColumnsProviderImpl;\n\n/**\n * Sandbox-specific result-pool provider. Accepts the raw handle-shaped blocks\n * returned by {@link GlobalCfgRenderCtxMethods.getUpstreamBlockCtx} and\n * wraps them into {@link TreeNodeAccessor}s, then adds `getColumns()`.\n */\nexport class ResultPoolColumnsProviderImpl\n extends ResultPoolEntriesProvider<TreeNodeAccessor>\n implements ColumnsProvider\n{\n private cachedColumns?: DataColumnRecipe<PObjectId>[];\n\n constructor(\n rawPool: ReadonlyArray<\n UpstreamBlockCtx<AccessorHandle>\n > = getCfgRenderCtx().getUpstreamBlockCtx(),\n ) {\n const blocks = rawPool.map((b) => ({\n blockId: b.blockId,\n prodCtx:\n b.prodCtx !== undefined\n ? new TreeNodeAccessor(b.prodCtx, [b.blockId, \"prodCtx\"])\n : undefined,\n stagingCtx:\n b.stagingCtx !== undefined\n ? new TreeNodeAccessor(b.stagingCtx, [b.blockId, \"stagingCtx\"])\n : undefined,\n prodIncomplete: b.prodIncomplete,\n stagingIncomplete: b.stagingIncomplete,\n }));\n\n super(blocks);\n }\n\n getColumns(): DataColumnRecipe<PObjectId>[] {\n if (this.cachedColumns !== undefined) return this.cachedColumns;\n return (this.cachedColumns = Array.from(\n this.getPObjectEntries().values(),\n columnUnlessAbsent,\n ).filter((column) => column !== undefined));\n }\n}\n\n/** Public type alias — value of the same name is the memoised factory above. */\nexport type ResultPoolColumnsProvider = ResultPoolColumnsProviderImpl;\n\nfunction columnUnlessAbsent(\n entry: LeafEntry<TreeNodeAccessor>,\n): DataColumnRecipe<PObjectId> | undefined {\n try {\n return DataColumn.fromAccessor(entry);\n } catch (error) {\n if (error instanceof ColumnAbsentError) return undefined;\n throw error;\n }\n}\n\nfunction hashRawPool(rawPool: ReadonlyArray<UpstreamBlockCtx<AccessorHandle>>): string {\n return rawPool\n .map(\n (b) =>\n `${b.blockId}\\x1f${b.prodCtx ?? \"\"}\\x1f${b.stagingCtx ?? \"\"}\\x1f${\n b.prodIncomplete ? 1 : 0\n }\\x1f${b.stagingIncomplete ? 1 : 0}`,\n )\n .join(\"\\x1e\");\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAyCA,SAAgB,gBACd,QACA;CACA,IAAI,MAAM,MAAM,KAAK,MAAM,QAAQ,MAAM,GACvC,OAAO,0BAA0B,MAAM;MAClC,IAAI,kBAAkB,kBAC3B,OAAO,wBAAwB,MAAM;MAErC,MAAM,IAAI,MAAM,iCAAiC;AAErD;;;;;;AAOA,MAAM,yBAAyB,IAAI,SAAsD,EACvF,KAAK,GACP,CAAC;AACD,SAAgB,wBAAwB,MAAiD;CACvF,IAAI,WAAW,uBAAuB,IAAI,KAAK,MAAM;CACrD,IAAI,aAAa,KAAA,GAAW;EAC1B,WAAW,IAAI,4BAA4B,IAAI;EAC/C,uBAAuB,IAAI,KAAK,QAAQ,QAAQ;CAClD;CACA,OAAO;AACT;;;;;;AAOA,MAAM,2BAA2B,IAAI,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d;CAEA,aAA4C;EAC1C,IAAI,KAAK,kBAAkB,KAAA,GAAW,OAAO,KAAK;EAClD,OAAQ,KAAK,gBAAgB,MAAM,KACjC,KAAK,kBAAkB,CAAC,CAAC,OAAO,GAChC,kBACF,CAAC,CAAC,QAAQ,WAAW,WAAW,KAAA,CAAS;CAC3C;AACF;AAKA,SAAS,mBACP,OACyC;CACzC,IAAI;EACF,OAAO,WAAW,aAAa,KAAK;CACtC,SAAS,OAAO;EACd,IAAI,iBAAiB,mBAAmB,OAAO,KAAA;EAC/C,MAAM;CACR;AACF;AAEA,SAAS,YAAY,SAAkE;CACrF,OAAO,QACJ,KACE,MACC,GAAG,EAAE,QAAQ,MAAM,EAAE,WAAW,GAAG,MAAM,EAAE,cAAc,GAAG,MAC1D,EAAE,iBAAiB,IAAI,EACxB,MAAM,EAAE,oBAAoB,IAAI,GACrC,CAAC,CACA,KAAK,GAAM;AAChB"}
@@ -77,8 +77,9 @@ var DataColumnImpl = class DataColumnImpl {
77
77
  * Resolve via the ambient {@link ColumnRegistry}. Spec is resolved eagerly:
78
78
  * returns `undefined` if the leaf isn't reachable yet (resolving). Throws
79
79
  * {@link ColumnAbsentError} when every relevant accessor is `inputsLocked`
80
- * and the column did not appear — the column will not exist in this ctx.
81
- * Data and dataStatus stay lazy.
80
+ * and the column did not appear, or when the id names an export that is not
81
+ * a column (a `kind: "File"` object, for example) — the column will not
82
+ * exist in this ctx. Data and dataStatus stay lazy.
82
83
  */
83
84
  static fromId(id, { ctx } = {}) {
84
85
  const registry = new _milaboratories_pl_model_common.ColumnRegistry(require_index.getCtxProviders({ ctx }));
@@ -87,17 +88,7 @@ var DataColumnImpl = class DataColumnImpl {
87
88
  if (registry.isFinal()) throw new ColumnAbsentError(id);
88
89
  return;
89
90
  }
90
- const spec = readSpecAccessor(leaf);
91
- if ((0, es_toolkit.isNil)(spec)) {
92
- if (leaf.accessor.getInputsLocked()) throw new ColumnAbsentError(id);
93
- return;
94
- }
95
- if (!spec.hasData()) return void 0;
96
- return new DataColumnImpl(id, {
97
- getSpec: () => spec.getDataAsJson(),
98
- getData: () => readDataAccessor(leaf),
99
- getDataStatus: () => readDataStatus(leaf)
100
- });
91
+ return DataColumnImpl.fromAccessor(leaf);
101
92
  }
102
93
  /** {@link PlRef} wrapper over {@link fromId}. */
103
94
  static fromPlRef(ref) {
@@ -106,17 +97,19 @@ var DataColumnImpl = class DataColumnImpl {
106
97
  /**
107
98
  * Bind directly to an accessor-backed {@link LeafEntry} — no registry.
108
99
  * Throws {@link ColumnAbsentError} if the leaf has no spec field and its
109
- * accessor is `inputsLocked`. Returns `undefined` while still resolving.
100
+ * accessor is `inputsLocked`, or if it names an export that is not a column.
101
+ * Returns `undefined` while still resolving.
110
102
  */
111
103
  static fromAccessor(entry) {
112
- const spec = readSpecAccessor(entry);
113
- if ((0, es_toolkit.isNil)(spec)) {
104
+ if ((0, es_toolkit.isNil)(readSpecAccessor(entry))) {
114
105
  if (entry.accessor.getInputsLocked()) throw new ColumnAbsentError(entry.id);
115
106
  return;
116
107
  }
117
- if (!spec.hasData()) return void 0;
108
+ 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);
118
111
  return new DataColumnImpl(entry.id, {
119
- getSpec: () => spec.getDataAsJson(),
112
+ getSpec: () => spec,
120
113
  getData: () => readDataAccessor(entry),
121
114
  getDataStatus: () => readDataStatus(entry)
122
115
  });
@@ -138,7 +131,9 @@ var DataColumnImpl = class DataColumnImpl {
138
131
  * Distinguishes `present` / `resolving` / `absent` for a {@link PObjectId}
139
132
  * in the active render ctx. Falls back to the registry's `isFinal()`
140
133
  * when the id has no entry — only then we can say `absent` instead of
141
- * `resolving`.
134
+ * `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 throw
136
+ * {@link ColumnAbsentError}.
142
137
  */
143
138
  static getStatusById(id, { ctx } = {}) {
144
139
  const registry = new _milaboratories_pl_model_common.ColumnRegistry(require_index.getCtxProviders({ ctx }));
@@ -207,6 +202,12 @@ const readSpecAccessor = memoizeByEntry(({ accessor, name }) => accessor.travers
207
202
  assertFieldType: "Input",
208
203
  ignoreError: true
209
204
  }));
205
+ /** The leaf's spec, or `undefined` until the spec resource has data. */
206
+ const readSpec = memoizeByEntry((entry) => {
207
+ const spec = readSpecAccessor(entry);
208
+ if ((0, es_toolkit.isNil)(spec) || !spec.hasData()) return void 0;
209
+ return spec.getDataAsJson();
210
+ });
210
211
  /**
211
212
  * Per-entry counterpart to {@link readDataStatus}: tells whether the leaf's
212
213
  * **spec** can be read in this ctx, and — for the negative cases —
@@ -1 +1 @@
1
- {"version":3,"file":"data_column.cjs","names":["ColumnOverriddenRecipe","ColumnRegistry","getCtxProviders","isNil","createGlobalPObjectId","isPlRef","isPColumn","LRUCache"],"sources":["../../src/columns/data_column.ts"],"sourcesContent":["import {\n ColumnRegistry,\n createGlobalPObjectId,\n isPColumn,\n isPlRef,\n PlRef,\n PObjectId,\n type ColumnUniversalId,\n type LeafEntry,\n type PColumn,\n type PColumnSpec,\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 — the column will not exist in this ctx.\n * 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 const spec = readSpecAccessor(leaf);\n if (isNil(spec)) {\n if (leaf.accessor.getInputsLocked()) throw new ColumnAbsentError(id);\n return undefined;\n }\n if (!spec.hasData()) return undefined;\n return new DataColumnImpl(id, {\n getSpec: () => spec.getDataAsJson<PColumnSpec>(),\n getData: () => readDataAccessor(leaf),\n getDataStatus: () => readDataStatus(leaf),\n });\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`. Returns `undefined` while still resolving.\n */\n static fromAccessor(entry: LeafEntry<TreeNodeAccessor>): undefined | DataColumnRecipe<PObjectId> {\n const spec = readSpecAccessor(entry);\n if (isNil(spec)) {\n if (entry.accessor.getInputsLocked()) throw new ColumnAbsentError(entry.id);\n return undefined;\n }\n if (!spec.hasData()) return undefined;\n return new DataColumnImpl(entry.id, {\n getSpec: () => spec.getDataAsJson<PColumnSpec>(),\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`.\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/**\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":";;;;;;;;;;;;;;;;;AAgEA,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,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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tE,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,IAAII,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 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,OAAO,CAAC,KAAK,EAAE;CACjB;CAEA,UAAuB;EACrB,IAAI,KAAK,cAAc,KAAA,GACrB,KAAK,YAAY,EAAE,OAAO,KAAK,QAAQ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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"}
@@ -72,8 +72,9 @@ export declare class DataColumnImpl implements DataColumnRecipe<PObjectId> {
72
72
  * Resolve via the ambient {@link ColumnRegistry}. Spec is resolved eagerly:
73
73
  * returns `undefined` if the leaf isn't reachable yet (resolving). Throws
74
74
  * {@link ColumnAbsentError} when every relevant accessor is `inputsLocked`
75
- * and the column did not appear — the column will not exist in this ctx.
76
- * Data and dataStatus stay lazy.
75
+ * and the column did not appear, or when the id names an export that is not
76
+ * a column (a `kind: "File"` object, for example) — the column will not
77
+ * exist in this ctx. Data and dataStatus stay lazy.
77
78
  */
78
79
  static fromId(id: PObjectId, { ctx }?: {
79
80
  ctx?: GlobalCfgRenderCtx;
@@ -83,7 +84,8 @@ export declare class DataColumnImpl implements DataColumnRecipe<PObjectId> {
83
84
  /**
84
85
  * Bind directly to an accessor-backed {@link LeafEntry} — no registry.
85
86
  * Throws {@link ColumnAbsentError} if the leaf has no spec field and its
86
- * accessor is `inputsLocked`. Returns `undefined` while still resolving.
87
+ * accessor is `inputsLocked`, or if it names an export that is not a column.
88
+ * Returns `undefined` while still resolving.
87
89
  */
88
90
  static fromAccessor(entry: LeafEntry<TreeNodeAccessor>): undefined | DataColumnRecipe<PObjectId>;
89
91
  /**
@@ -95,7 +97,9 @@ export declare class DataColumnImpl implements DataColumnRecipe<PObjectId> {
95
97
  * Distinguishes `present` / `resolving` / `absent` for a {@link PObjectId}
96
98
  * in the active render ctx. Falls back to the registry's `isFinal()`
97
99
  * when the id has no entry — only then we can say `absent` instead of
98
- * `resolving`.
100
+ * `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 throw
102
+ * {@link ColumnAbsentError}.
99
103
  */
100
104
  static getStatusById(id: PObjectId, { ctx }?: {
101
105
  ctx?: GlobalCfgRenderCtx;
@@ -1 +1 @@
1
- {"version":3,"file":"data_column.d.ts","names":[],"sources":["../../src/columns/data_column.ts"],"mappings":";;;;;YA2BY,eAAe;YACf,yBAAyB;;;;;;;;;;;;;;;;iBAkBpB,iBACf,WAAW,iBAAiB,wBACpB,aAAa;;EAErB,WAAW;;;;;;;;;;;;;qBAcA,0BAA0B;WACT,IAAI;EAAhC,YAA4B,IAAI;;;;;;;;;;;qBAerB,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;;SAqBzB,UAAU,KAAK,oBAAoB,iBAAiB;;;;;;SASpD,aAAa,OAAO,UAAU,gCAAgC,iBAAiB;;;;;SAkB/E,WACL,QAAQ,QAAQ,cAAc,iBAAiB,aAC9C,iBAAiB;;;;;;;SAoBb,cACL,IAAI,aACF;IAAS,MAAM;MAChB;;SAQI,iBACL,KAAK,OACL;IAAQ,MAAM;MACb;;SAKI,oBAAoB,OAAO,UAAU,oBAAoB;;;YAMt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,6 +1,6 @@
1
1
  import { ColumnOverriddenRecipe } from "./column_recipes/column_overrided_recipe.js";
2
2
  import { getCtxProviders } from "./column_providers/index.js";
3
- import { ColumnRegistry, createGlobalPObjectId, isPColumn, isPlRef } from "@milaboratories/pl-model-common";
3
+ import { ColumnRegistry, createGlobalPObjectId, isPColumn, isPColumnSpec, isPlRef } from "@milaboratories/pl-model-common";
4
4
  import { isNil } from "es-toolkit";
5
5
  import { LRUCache } from "lru-cache";
6
6
  // src/columns/data_column.ts
@@ -77,8 +77,9 @@ var DataColumnImpl = class DataColumnImpl {
77
77
  * Resolve via the ambient {@link ColumnRegistry}. Spec is resolved eagerly:
78
78
  * returns `undefined` if the leaf isn't reachable yet (resolving). Throws
79
79
  * {@link ColumnAbsentError} when every relevant accessor is `inputsLocked`
80
- * and the column did not appear — the column will not exist in this ctx.
81
- * Data and dataStatus stay lazy.
80
+ * and the column did not appear, or when the id names an export that is not
81
+ * a column (a `kind: "File"` object, for example) — the column will not
82
+ * exist in this ctx. Data and dataStatus stay lazy.
82
83
  */
83
84
  static fromId(id, { ctx } = {}) {
84
85
  const registry = new ColumnRegistry(getCtxProviders({ ctx }));
@@ -87,17 +88,7 @@ var DataColumnImpl = class DataColumnImpl {
87
88
  if (registry.isFinal()) throw new ColumnAbsentError(id);
88
89
  return;
89
90
  }
90
- const spec = readSpecAccessor(leaf);
91
- if (isNil(spec)) {
92
- if (leaf.accessor.getInputsLocked()) throw new ColumnAbsentError(id);
93
- return;
94
- }
95
- if (!spec.hasData()) return void 0;
96
- return new DataColumnImpl(id, {
97
- getSpec: () => spec.getDataAsJson(),
98
- getData: () => readDataAccessor(leaf),
99
- getDataStatus: () => readDataStatus(leaf)
100
- });
91
+ return DataColumnImpl.fromAccessor(leaf);
101
92
  }
102
93
  /** {@link PlRef} wrapper over {@link fromId}. */
103
94
  static fromPlRef(ref) {
@@ -106,17 +97,19 @@ var DataColumnImpl = class DataColumnImpl {
106
97
  /**
107
98
  * Bind directly to an accessor-backed {@link LeafEntry} — no registry.
108
99
  * Throws {@link ColumnAbsentError} if the leaf has no spec field and its
109
- * accessor is `inputsLocked`. Returns `undefined` while still resolving.
100
+ * accessor is `inputsLocked`, or if it names an export that is not a column.
101
+ * Returns `undefined` while still resolving.
110
102
  */
111
103
  static fromAccessor(entry) {
112
- const spec = readSpecAccessor(entry);
113
- if (isNil(spec)) {
104
+ if (isNil(readSpecAccessor(entry))) {
114
105
  if (entry.accessor.getInputsLocked()) throw new ColumnAbsentError(entry.id);
115
106
  return;
116
107
  }
117
- if (!spec.hasData()) return void 0;
108
+ const spec = readSpec(entry);
109
+ if (spec === void 0) return void 0;
110
+ if (!isPColumnSpec(spec)) throw new ColumnAbsentError(entry.id);
118
111
  return new DataColumnImpl(entry.id, {
119
- getSpec: () => spec.getDataAsJson(),
112
+ getSpec: () => spec,
120
113
  getData: () => readDataAccessor(entry),
121
114
  getDataStatus: () => readDataStatus(entry)
122
115
  });
@@ -138,7 +131,9 @@ var DataColumnImpl = class DataColumnImpl {
138
131
  * Distinguishes `present` / `resolving` / `absent` for a {@link PObjectId}
139
132
  * in the active render ctx. Falls back to the registry's `isFinal()`
140
133
  * when the id has no entry — only then we can say `absent` instead of
141
- * `resolving`.
134
+ * `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 throw
136
+ * {@link ColumnAbsentError}.
142
137
  */
143
138
  static getStatusById(id, { ctx } = {}) {
144
139
  const registry = new ColumnRegistry(getCtxProviders({ ctx }));
@@ -207,6 +202,12 @@ const readSpecAccessor = memoizeByEntry(({ accessor, name }) => accessor.travers
207
202
  assertFieldType: "Input",
208
203
  ignoreError: true
209
204
  }));
205
+ /** The leaf's spec, or `undefined` until the spec resource has data. */
206
+ const readSpec = memoizeByEntry((entry) => {
207
+ const spec = readSpecAccessor(entry);
208
+ if (isNil(spec) || !spec.hasData()) return void 0;
209
+ return spec.getDataAsJson();
210
+ });
210
211
  /**
211
212
  * Per-entry counterpart to {@link readDataStatus}: tells whether the leaf's
212
213
  * **spec** can be read in this ctx, and — for the negative cases —
@@ -1 +1 @@
1
- {"version":3,"file":"data_column.js","names":[],"sources":["../../src/columns/data_column.ts"],"sourcesContent":["import {\n ColumnRegistry,\n createGlobalPObjectId,\n isPColumn,\n isPlRef,\n PlRef,\n PObjectId,\n type ColumnUniversalId,\n type LeafEntry,\n type PColumn,\n type PColumnSpec,\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 — the column will not exist in this ctx.\n * 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 const spec = readSpecAccessor(leaf);\n if (isNil(spec)) {\n if (leaf.accessor.getInputsLocked()) throw new ColumnAbsentError(id);\n return undefined;\n }\n if (!spec.hasData()) return undefined;\n return new DataColumnImpl(id, {\n getSpec: () => spec.getDataAsJson<PColumnSpec>(),\n getData: () => readDataAccessor(leaf),\n getDataStatus: () => readDataStatus(leaf),\n });\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`. Returns `undefined` while still resolving.\n */\n static fromAccessor(entry: LeafEntry<TreeNodeAccessor>): undefined | DataColumnRecipe<PObjectId> {\n const spec = readSpecAccessor(entry);\n if (isNil(spec)) {\n if (entry.accessor.getInputsLocked()) throw new ColumnAbsentError(entry.id);\n return undefined;\n }\n if (!spec.hasData()) return undefined;\n return new DataColumnImpl(entry.id, {\n getSpec: () => spec.getDataAsJson<PColumnSpec>(),\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`.\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/**\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":";;;;;;;;;;;;;;;;;AAgEA,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,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,OAAO,uBAAuB,KAAK,MAAM,SAAS;CACpD;;;;;;;;CASA,OAAO,OACL,IACA,EAAE,QAAsC,CAAC,GACA;EACzC,MAAM,WAAW,IAAI,eAAe,gBAAgB,EAAE,IAAI,CAAC,CAAC;EAC5D,MAAM,OAAO,SAAS,QAAQ,EAAE;EAChC,IAAI,MAAM,I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B,gBACtB,EAAE,UAAU,WACX,SAAS,SAAS;CAAE,OAAO,GAAG,KAAK;CAAQ,iBAAiB;CAAS,aAAa;AAAK,CAAC,CAC5F;;;;;;;;;;;;AAaA,SAAS,mBAAmB,OAA4D;CACtF,MAAM,OAAO,iBAAiB,KAAK;CACnC,IAAI,MAAM,IAAI,GAAG,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,IAAI,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.js","names":[],"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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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,IAAI,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"}
@@ -18,7 +18,7 @@ function toPredicate(opt) {
18
18
  function buildDatasetOptions(ctx, opts) {
19
19
  const primaryPredicate = toPredicate(opts?.primary);
20
20
  const filterPredicate = toPredicate(opts?.filter);
21
- const options = ctx.resultPool.getOptions(primaryPredicate, { refsWithEnrichments: opts?.requireEnrichments ?? true });
21
+ const options = ctx.resultPool.getOptions((spec) => (0, _milaboratories_pl_model_common.isPColumnSpec)(spec) && primaryPredicate(spec), { refsWithEnrichments: opts?.requireEnrichments ?? true });
22
22
  if (options.length === 0) return [];
23
23
  const refMap = require_filter_discovery.buildRefMap(ctx.resultPool.getSpecs().entries);
24
24
  const withEnrichments = opts?.withEnrichments ?? false;
@@ -1 +1 @@
1
- {"version":3,"file":"build_dataset_options.cjs","names":["multiColumnSelectorsToPredicate","buildRefMap","ColumnsProvider","getCtxProviders","findFilterColumns","filterMatchesToOptions","findEnrichmentColumns","enrichmentVariantsToRefs"],"sources":["../../../src/components/PlDatasetSelector/build_dataset_options.ts"],"sourcesContent":["import type { MultiColumnSelector, Option, PObjectSpec } from \"@milaboratories/pl-model-common\";\nimport { multiColumnSelectorsToPredicate } from \"@milaboratories/pl-model-common\";\nimport type { DeriveLabelsOptions } from \"../../labels/derive_distinct_labels\";\nimport type { RenderCtxBase } from \"../../render\";\nimport type { DatasetOption } from \"./dataset_selection\";\nimport { buildRefMap, filterMatchesToOptions, findFilterColumns } from \"./filter_discovery\";\nimport { enrichmentVariantsToRefs, findEnrichmentColumns } from \"./enrichment_discovery\";\nimport { ColumnsProvider, getCtxProviders } from \"../../columns\";\n\ntype SpecPredicateOption =\n | MultiColumnSelector\n | MultiColumnSelector[]\n | ((spec: PObjectSpec) => boolean);\n\nfunction toPredicate(opt: SpecPredicateOption | undefined): (spec: PObjectSpec) => boolean {\n if (opt === undefined) return () => true;\n return typeof opt === \"function\" ? opt : multiColumnSelectorsToPredicate(opt);\n}\n\nexport type BuildDatasetOptions = {\n /** Which result pool columns qualify as datasets. Defaults to all. */\n primary?: SpecPredicateOption;\n /**\n * Restricts which result pool columns are considered as filters. Intersected\n * with the built-in `pl7.app/isSubset: \"true\"` constraint. Defaults to\n * accept-all.\n */\n filter?: SpecPredicateOption;\n /**\n * Formatting options forwarded to label derivation for both filter and\n * enrichment rows. `formatters.native` on the filter path is overridden\n * — see `FilterMatchOptions.labelOptions`.\n */\n labelOptions?: DeriveLabelsOptions;\n /**\n * Enables enrichment discovery and filters hits attached to\n * `DatasetOption.enrichments`. Use `() => true` to accept all; omit to disable.\n */\n withEnrichments?: SpecPredicateOption;\n /** Maximum linker hops considered. Only used when `withEnrichments` is set. */\n enrichmentMaxHops?: number;\n /**\n * Whether the dataset refs in the returned options carry `requireEnrichments: true`.\n * A block that stores such a ref depends on every block that enriches the dataset.\n * Set `false` for a block that only needs the dataset and its filters. Defaults to `true`.\n */\n requireEnrichments?: boolean;\n};\n\n/**\n * Usage:\n * ```ts\n * .output(\"datasetOptions\", (ctx) => buildDatasetOptions(ctx))\n * ```\n */\nexport function buildDatasetOptions(\n ctx: RenderCtxBase,\n opts?: BuildDatasetOptions,\n): DatasetOption[] | undefined {\n const primaryPredicate = toPredicate(opts?.primary);\n const filterPredicate = toPredicate(opts?.filter);\n\n const options = ctx.resultPool.getOptions(primaryPredicate, {\n refsWithEnrichments: opts?.requireEnrichments ?? true,\n });\n if (options.length === 0) return [];\n\n const refMap = buildRefMap(ctx.resultPool.getSpecs().entries);\n\n const withEnrichments = opts?.withEnrichments ?? false;\n const filterSource = ColumnsProvider(ctx.ctx.getUpstreamBlockCtx());\n // Hoist providers once: getCtxProviders walks the full output tree, so\n // calling it per dataset option would be O(N × tree).\n const enrichmentSources = withEnrichments ? getCtxProviders(ctx) : undefined;\n\n return options.map((primary: Option): DatasetOption => {\n const datasetSpec = ctx.resultPool.getPColumnSpecByRef(primary.ref);\n if (!datasetSpec) return { primary };\n\n const filterMatches = findFilterColumns({\n sources: [filterSource],\n anchorSpec: datasetSpec,\n }).filter((m) => filterPredicate(m.getSpec()!));\n\n const filters =\n filterMatches.length === 0\n ? undefined\n : filterMatchesToOptions(filterMatches, {\n refsByObjectId: refMap,\n datasetSpec,\n labelOptions: opts?.labelOptions,\n });\n\n let enrichments;\n if (enrichmentSources && withEnrichments) {\n const enrichmentVariants = findEnrichmentColumns({\n sources: enrichmentSources,\n anchorSpec: datasetSpec,\n maxHops: opts?.enrichmentMaxHops,\n ...(typeof withEnrichments === \"function\"\n ? { predicate: withEnrichments }\n : { include: withEnrichments }),\n });\n if (enrichmentVariants.length > 0) {\n enrichments = enrichmentVariantsToRefs(enrichmentVariants, opts?.labelOptions);\n }\n }\n\n return {\n primary,\n ...(filters !== undefined && filters.length > 0 ? { filters } : {}),\n ...(enrichments !== undefined && enrichments.length > 0 ? { enrichments } : {}),\n };\n });\n}\n"],"mappings":";;;;;;;AAcA,SAAS,YAAY,KAAsE;CACzF,IAAI,QAAQ,KAAA,GAAW,a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,oBAAoB,MAAM,YAAY;EAEjF;EAEA,OAAO;GACL;GACA,GAAI,YAAY,KAAA,KAAa,QAAQ,SAAS,IAAI,EAAE,QAAQ,IAAI,CAAC;GACjE,GAAI,gBAAgB,KAAA,KAAa,YAAY,SAAS,IAAI,EAAE,YAAY,IAAI,CAAC;EAC/E;CACF,CAAC;AACH"}
1
+ {"version":3,"file":"build_dataset_options.cjs","names":["multiColumnSelectorsToPredicate","isPColumnSpec","buildRefMap","ColumnsProvider","getCtxProviders","findFilterColumns","filterMatchesToOptions","findEnrichmentColumns","enrichmentVariantsToRefs"],"sources":["../../../src/components/PlDatasetSelector/build_dataset_options.ts"],"sourcesContent":["import type { MultiColumnSelector, Option, PObjectSpec } from \"@milaboratories/pl-model-common\";\nimport { isPColumnSpec, multiColumnSelectorsToPredicate } from \"@milaboratories/pl-model-common\";\nimport type { DeriveLabelsOptions } from \"../../labels/derive_distinct_labels\";\nimport type { RenderCtxBase } from \"../../render\";\nimport type { DatasetOption } from \"./dataset_selection\";\nimport { buildRefMap, filterMatchesToOptions, findFilterColumns } from \"./filter_discovery\";\nimport { enrichmentVariantsToRefs, findEnrichmentColumns } from \"./enrichment_discovery\";\nimport { ColumnsProvider, getCtxProviders } from \"../../columns\";\n\ntype SpecPredicateOption =\n | MultiColumnSelector\n | MultiColumnSelector[]\n | ((spec: PObjectSpec) => boolean);\n\nfunction toPredicate(opt: SpecPredicateOption | undefined): (spec: PObjectSpec) => boolean {\n if (opt === undefined) return () => true;\n return typeof opt === \"function\" ? opt : multiColumnSelectorsToPredicate(opt);\n}\n\nexport type BuildDatasetOptions = {\n /** Which result pool columns qualify as datasets. Defaults to all. */\n primary?: SpecPredicateOption;\n /**\n * Restricts which result pool columns are considered as filters. Intersected\n * with the built-in `pl7.app/isSubset: \"true\"` constraint. Defaults to\n * accept-all.\n */\n filter?: SpecPredicateOption;\n /**\n * Formatting options forwarded to label derivation for both filter and\n * enrichment rows. `formatters.native` on the filter path is overridden\n * — see `FilterMatchOptions.labelOptions`.\n */\n labelOptions?: DeriveLabelsOptions;\n /**\n * Enables enrichment discovery and filters hits attached to\n * `DatasetOption.enrichments`. Use `() => true` to accept all; omit to disable.\n */\n withEnrichments?: SpecPredicateOption;\n /** Maximum linker hops considered. Only used when `withEnrichments` is set. */\n enrichmentMaxHops?: number;\n /**\n * Whether the dataset refs in the returned options carry `requireEnrichments: true`.\n * A block that stores such a ref depends on every block that enriches the dataset.\n * Set `false` for a block that only needs the dataset and its filters. Defaults to `true`.\n */\n requireEnrichments?: boolean;\n};\n\n/**\n * Usage:\n * ```ts\n * .output(\"datasetOptions\", (ctx) => buildDatasetOptions(ctx))\n * ```\n */\nexport function buildDatasetOptions(\n ctx: RenderCtxBase,\n opts?: BuildDatasetOptions,\n): DatasetOption[] | undefined {\n const primaryPredicate = toPredicate(opts?.primary);\n const filterPredicate = toPredicate(opts?.filter);\n\n const options = ctx.resultPool.getOptions(\n (spec) => isPColumnSpec(spec) && primaryPredicate(spec),\n {\n refsWithEnrichments: opts?.requireEnrichments ?? true,\n },\n );\n if (options.length === 0) return [];\n\n const refMap = buildRefMap(ctx.resultPool.getSpecs().entries);\n\n const withEnrichments = opts?.withEnrichments ?? false;\n const filterSource = ColumnsProvider(ctx.ctx.getUpstreamBlockCtx());\n // Hoist providers once: getCtxProviders walks the full output tree, so\n // calling it per dataset option would be O(N × tree).\n const enrichmentSources = withEnrichments ? getCtxProviders(ctx) : undefined;\n\n return options.map((primary: Option): DatasetOption => {\n const datasetSpec = ctx.resultPool.getPColumnSpecByRef(primary.ref);\n if (!datasetSpec) return { primary };\n\n const filterMatches = findFilterColumns({\n sources: [filterSource],\n anchorSpec: datasetSpec,\n }).filter((m) => filterPredicate(m.getSpec()!));\n\n const filters =\n filterMatches.length === 0\n ? undefined\n : filterMatchesToOptions(filterMatches, {\n refsByObjectId: refMap,\n datasetSpec,\n labelOptions: opts?.labelOptions,\n });\n\n let enrichments;\n if (enrichmentSources && withEnrichments) {\n const enrichmentVariants = findEnrichmentColumns({\n sources: enrichmentSources,\n anchorSpec: datasetSpec,\n maxHops: opts?.enrichmentMaxHops,\n ...(typeof withEnrichments === \"function\"\n ? { predicate: withEnrichments }\n : { include: withEnrichments }),\n });\n if (enrichmentVariants.length > 0) {\n enrichments = enrichmentVariantsToRefs(enrichmentVariants, opts?.labelOptions);\n }\n }\n\n return {\n primary,\n ...(filters !== undefined && filters.length > 0 ? { filters } : {}),\n ...(enrichments !== undefined && enrichments.length > 0 ? { enrichments } : {}),\n };\n });\n}\n"],"mappings":";;;;;;;AAcA,SAAS,YAAY,KAAsE;CACzF,IAAI,QAAQ,KAAA,GAAW,aAAa;CACpC,OAAO,OAAO,QAAQ,aAAa,OAAA,GAAMA,gCAAAA,gCAAAA,CAAgC,GAAG;AAC9E;;;;;;;AAsCA,SAAgB,oBACd,KACA,MAC6B;CAC7B,MAAM,mBAAmB,YAAY,MAAM,OAAO;CAClD,MAAM,kBAAkB,YAAY,MAAM,MAAM;CAEhD,MAAM,UAAU,IAAI,WAAW,YAC5B,UAAA,GAASC,gCAAAA,cAAAA,CAAc,IAAI,KAAK,iBAAiB,IAAI,GACtD,EACE,qBAAqB,MAAM,sBAAsB,KACnD,CACF;CACA,IAAI,QAAQ,WAAW,GAAG,OAAO,CAAC;CAElC,MAAM,SAASC,yBAAAA,YAAY,IAAI,WAAW,SAAS,CAAC,CAAC,OAAO;CAE5D,MAAM,kBAAkB,MAAM,mBAAmB;CACjD,MAAM,eAAeC,kBAAAA,gBAAgB,IAAI,IAAI,oBAAoB,CAAC;CAGlE,MAAM,oBAAoB,kBAAkBC,cAAAA,gBAAgB,GAAG,IAAI,KAAA;CAEnE,OAAO,QAAQ,KAAK,YAAmC;EACrD,MAAM,cAAc,IAAI,WAAW,oBAAoB,QAAQ,GAAG;EAClE,IAAI,CAAC,aAAa,OAAO,EAAE,QAAQ;EAEnC,MAAM,gBAAgBC,yBAAAA,kBAAkB;GACtC,SAAS,CAAC,YAAY;GACtB,YAAY;EACd,CAAC,CAAC,CAAC,QAAQ,MAAM,gBAAgB,EAAE,QAAQ,CAAE,CAAC;EAE9C,MAAM,UACJ,cAAc,WAAW,IACrB,KAAA,IACAC,yBAAAA,uBAAuB,eAAe;GACpC,gBAAgB;GAChB;GACA,cAAc,MAAM;EACtB,CAAC;EAEP,IAAI;EACJ,IAAI,qBAAqB,iBAAiB;GACxC,MAAM,qBAAqBC,6BAAAA,sBAAsB;IAC/C,SAAS;IACT,YAAY;IACZ,SAAS,MAAM;IACf,GAAI,OAAO,oBAAoB,aAC3B,EAAE,WAAW,gBAAgB,IAC7B,EAAE,SAAS,gBAAgB;GACjC,CAAC;GACD,IAAI,mBAAmB,SAAS,GAC9B,cAAcC,6BAAAA,yBAAyB,oBAAoB,MAAM,YAAY;EAEjF;EAEA,OAAO;GACL;GACA,GAAI,YAAY,KAAA,KAAa,QAAQ,SAAS,IAAI,EAAE,QAAQ,IAAI,CAAC;GACjE,GAAI,gBAAgB,KAAA,KAAa,YAAY,SAAS,IAAI,EAAE,YAAY,IAAI,CAAC;EAC/E;CACF,CAAC;AACH"}
@@ -3,7 +3,7 @@ import { getCtxProviders } from "../../columns/column_providers/index.js";
3
3
  import "../../columns/index.js";
4
4
  import { buildRefMap, filterMatchesToOptions, findFilterColumns } from "./filter_discovery.js";
5
5
  import { enrichmentVariantsToRefs, findEnrichmentColumns } from "./enrichment_discovery.js";
6
- import { multiColumnSelectorsToPredicate } from "@milaboratories/pl-model-common";
6
+ import { isPColumnSpec, multiColumnSelectorsToPredicate } from "@milaboratories/pl-model-common";
7
7
  // src/components/PlDatasetSelector/build_dataset_options.ts
8
8
  function toPredicate(opt) {
9
9
  if (opt === void 0) return () => true;
@@ -18,7 +18,7 @@ function toPredicate(opt) {
18
18
  function buildDatasetOptions(ctx, opts) {
19
19
  const primaryPredicate = toPredicate(opts?.primary);
20
20
  const filterPredicate = toPredicate(opts?.filter);
21
- const options = ctx.resultPool.getOptions(primaryPredicate, { refsWithEnrichments: opts?.requireEnrichments ?? true });
21
+ const options = ctx.resultPool.getOptions((spec) => isPColumnSpec(spec) && primaryPredicate(spec), { refsWithEnrichments: opts?.requireEnrichments ?? true });
22
22
  if (options.length === 0) return [];
23
23
  const refMap = buildRefMap(ctx.resultPool.getSpecs().entries);
24
24
  const withEnrichments = opts?.withEnrichments ?? false;
@@ -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 { multiColumnSelectorsToPredicate } from \"@milaboratories/pl-model-common\";\nimport type { DeriveLabelsOptions } from \"../../labels/derive_distinct_labels\";\nimport type { RenderCtxBase } from \"../../render\";\nimport type { DatasetOption } from \"./dataset_selection\";\nimport { buildRefMap, filterMatchesToOptions, findFilterColumns } from \"./filter_discovery\";\nimport { enrichmentVariantsToRefs, findEnrichmentColumns } from \"./enrichment_discovery\";\nimport { ColumnsProvider, getCtxProviders } from \"../../columns\";\n\ntype SpecPredicateOption =\n | MultiColumnSelector\n | MultiColumnSelector[]\n | ((spec: PObjectSpec) => boolean);\n\nfunction toPredicate(opt: SpecPredicateOption | undefined): (spec: PObjectSpec) => boolean {\n if (opt === undefined) return () => true;\n return typeof opt === \"function\" ? opt : multiColumnSelectorsToPredicate(opt);\n}\n\nexport type BuildDatasetOptions = {\n /** Which result pool columns qualify as datasets. Defaults to all. */\n primary?: SpecPredicateOption;\n /**\n * Restricts which result pool columns are considered as filters. Intersected\n * with the built-in `pl7.app/isSubset: \"true\"` constraint. Defaults to\n * accept-all.\n */\n filter?: SpecPredicateOption;\n /**\n * Formatting options forwarded to label derivation for both filter and\n * enrichment rows. `formatters.native` on the filter path is overridden\n * — see `FilterMatchOptions.labelOptions`.\n */\n labelOptions?: DeriveLabelsOptions;\n /**\n * Enables enrichment discovery and filters hits attached to\n * `DatasetOption.enrichments`. Use `() => true` to accept all; omit to disable.\n */\n withEnrichments?: SpecPredicateOption;\n /** Maximum linker hops considered. Only used when `withEnrichments` is set. */\n enrichmentMaxHops?: number;\n /**\n * Whether the dataset refs in the returned options carry `requireEnrichments: true`.\n * A block that stores such a ref depends on every block that enriches the dataset.\n * Set `false` for a block that only needs the dataset and its filters. Defaults to `true`.\n */\n requireEnrichments?: boolean;\n};\n\n/**\n * Usage:\n * ```ts\n * .output(\"datasetOptions\", (ctx) => buildDatasetOptions(ctx))\n * ```\n */\nexport function buildDatasetOptions(\n ctx: RenderCtxBase,\n opts?: BuildDatasetOptions,\n): DatasetOption[] | undefined {\n const primaryPredicate = toPredicate(opts?.primary);\n const filterPredicate = toPredicate(opts?.filter);\n\n const options = ctx.resultPool.getOptions(primaryPredicate, {\n refsWithEnrichments: opts?.requireEnrichments ?? true,\n });\n if (options.length === 0) return [];\n\n const refMap = buildRefMap(ctx.resultPool.getSpecs().entries);\n\n const withEnrichments = opts?.withEnrichments ?? false;\n const filterSource = ColumnsProvider(ctx.ctx.getUpstreamBlockCtx());\n // Hoist providers once: getCtxProviders walks the full output tree, so\n // calling it per dataset option would be O(N × tree).\n const enrichmentSources = withEnrichments ? getCtxProviders(ctx) : undefined;\n\n return options.map((primary: Option): DatasetOption => {\n const datasetSpec = ctx.resultPool.getPColumnSpecByRef(primary.ref);\n if (!datasetSpec) return { primary };\n\n const filterMatches = findFilterColumns({\n sources: [filterSource],\n anchorSpec: datasetSpec,\n }).filter((m) => filterPredicate(m.getSpec()!));\n\n const filters =\n filterMatches.length === 0\n ? undefined\n : filterMatchesToOptions(filterMatches, {\n refsByObjectId: refMap,\n datasetSpec,\n labelOptions: opts?.labelOptions,\n });\n\n let enrichments;\n if (enrichmentSources && withEnrichments) {\n const enrichmentVariants = findEnrichmentColumns({\n sources: enrichmentSources,\n anchorSpec: datasetSpec,\n maxHops: opts?.enrichmentMaxHops,\n ...(typeof withEnrichments === \"function\"\n ? { predicate: withEnrichments }\n : { include: withEnrichments }),\n });\n if (enrichmentVariants.length > 0) {\n enrichments = enrichmentVariantsToRefs(enrichmentVariants, opts?.labelOptions);\n }\n }\n\n return {\n primary,\n ...(filters !== undefined && filters.length > 0 ? { filters } : {}),\n ...(enrichments !== undefined && enrichments.length > 0 ? { enrichments } : {}),\n };\n });\n}\n"],"mappings":";;;;;;;AAcA,SAAS,YAAY,KAAsE;CACzF,IAAI,QAAQ,KAAA,GAAW,aAAa;CACpC,OAAO,OAAO,QAAQ,aAAa,MAAM,gCAAgC,GAAG;AAC9E;;;;;;;AAsCA,SAAgB,oBACd,KACA,MAC6B;CAC7B,MAAM,mBAAmB,YAAY,MAAM,OAAO;CAClD,MAAM,kBAAkB,YAAY,MAAM,MAAM;CAEhD,MAAM,UAAU,IAAI,WAAW,WAAW,kBAAkB,EAC1D,qBAAqB,MAAM,sBAAsB,KACnD,CAAC;CACD,IAAI,QAAQ,WAAW,GAAG,OAAO,CAAC;CAElC,MAAM,SAAS,YAAY,IAAI,WAAW,SAAS,CAAC,CAAC,OAAO;CAE5D,MAAM,kBAAkB,MAAM,mBAAmB;CACjD,MAAM,eAAe,gBAAgB,IAAI,IAAI,oBAAoB,CAAC;CAGlE,MAAM,oBAAoB,kBAAkB,gBAAgB,GAAG,IAAI,KAAA;CAEnE,OAAO,QAAQ,KAAK,YAAmC;EACrD,MAAM,cAAc,IAAI,WAAW,oBAAoB,QAAQ,GAAG;EAClE,IAAI,CAAC,aAAa,OAAO,EAAE,QAAQ;EAEnC,MAAM,gBAAgB,kBAAkB;GACtC,SAAS,CAAC,YAAY;GACtB,YAAY;EACd,CAAC,CAAC,CAAC,QAAQ,MAAM,gBAAgB,EAAE,QAAQ,CAAE,CAAC;EAE9C,MAAM,UACJ,cAAc,WAAW,IACrB,KAAA,IACA,uBAAuB,eAAe;GACpC,gBAAgB;GAChB;GACA,cAAc,MAAM;EACtB,CAAC;EAEP,IAAI;EACJ,IAAI,qBAAqB,iBAAiB;GACxC,MAAM,qBAAqB,sBAAsB;IAC/C,SAAS;IACT,YAAY;IACZ,SAAS,MAAM;IACf,GAAI,OAAO,oBAAoB,aAC3B,EAAE,WAAW,gBAAgB,IAC7B,EAAE,SAAS,gBAAgB;GACjC,CAAC;GACD,IAAI,mBAAmB,SAAS,GAC9B,cAAc,yBAAyB,oBAAoB,MAAM,YAAY;EAEjF;EAEA,OAAO;GACL;GACA,GAAI,YAAY,KAAA,KAAa,QAAQ,SAAS,IAAI,EAAE,QAAQ,IAAI,CAAC;GACjE,GAAI,gBAAgB,KAAA,KAAa,YAAY,SAAS,IAAI,EAAE,YAAY,IAAI,CAAC;EAC/E;CACF,CAAC;AACH"}
1
+ {"version":3,"file":"build_dataset_options.js","names":[],"sources":["../../../src/components/PlDatasetSelector/build_dataset_options.ts"],"sourcesContent":["import type { MultiColumnSelector, Option, PObjectSpec } from \"@milaboratories/pl-model-common\";\nimport { isPColumnSpec, multiColumnSelectorsToPredicate } from \"@milaboratories/pl-model-common\";\nimport type { DeriveLabelsOptions } from \"../../labels/derive_distinct_labels\";\nimport type { RenderCtxBase } from \"../../render\";\nimport type { DatasetOption } from \"./dataset_selection\";\nimport { buildRefMap, filterMatchesToOptions, findFilterColumns } from \"./filter_discovery\";\nimport { enrichmentVariantsToRefs, findEnrichmentColumns } from \"./enrichment_discovery\";\nimport { ColumnsProvider, getCtxProviders } from \"../../columns\";\n\ntype SpecPredicateOption =\n | MultiColumnSelector\n | MultiColumnSelector[]\n | ((spec: PObjectSpec) => boolean);\n\nfunction toPredicate(opt: SpecPredicateOption | undefined): (spec: PObjectSpec) => boolean {\n if (opt === undefined) return () => true;\n return typeof opt === \"function\" ? opt : multiColumnSelectorsToPredicate(opt);\n}\n\nexport type BuildDatasetOptions = {\n /** Which result pool columns qualify as datasets. Defaults to all. */\n primary?: SpecPredicateOption;\n /**\n * Restricts which result pool columns are considered as filters. Intersected\n * with the built-in `pl7.app/isSubset: \"true\"` constraint. Defaults to\n * accept-all.\n */\n filter?: SpecPredicateOption;\n /**\n * Formatting options forwarded to label derivation for both filter and\n * enrichment rows. `formatters.native` on the filter path is overridden\n * — see `FilterMatchOptions.labelOptions`.\n */\n labelOptions?: DeriveLabelsOptions;\n /**\n * Enables enrichment discovery and filters hits attached to\n * `DatasetOption.enrichments`. Use `() => true` to accept all; omit to disable.\n */\n withEnrichments?: SpecPredicateOption;\n /** Maximum linker hops considered. Only used when `withEnrichments` is set. */\n enrichmentMaxHops?: number;\n /**\n * Whether the dataset refs in the returned options carry `requireEnrichments: true`.\n * A block that stores such a ref depends on every block that enriches the dataset.\n * Set `false` for a block that only needs the dataset and its filters. Defaults to `true`.\n */\n requireEnrichments?: boolean;\n};\n\n/**\n * Usage:\n * ```ts\n * .output(\"datasetOptions\", (ctx) => buildDatasetOptions(ctx))\n * ```\n */\nexport function buildDatasetOptions(\n ctx: RenderCtxBase,\n opts?: BuildDatasetOptions,\n): DatasetOption[] | undefined {\n const primaryPredicate = toPredicate(opts?.primary);\n const filterPredicate = toPredicate(opts?.filter);\n\n const options = ctx.resultPool.getOptions(\n (spec) => isPColumnSpec(spec) && primaryPredicate(spec),\n {\n refsWithEnrichments: opts?.requireEnrichments ?? true,\n },\n );\n if (options.length === 0) return [];\n\n const refMap = buildRefMap(ctx.resultPool.getSpecs().entries);\n\n const withEnrichments = opts?.withEnrichments ?? false;\n const filterSource = ColumnsProvider(ctx.ctx.getUpstreamBlockCtx());\n // Hoist providers once: getCtxProviders walks the full output tree, so\n // calling it per dataset option would be O(N × tree).\n const enrichmentSources = withEnrichments ? getCtxProviders(ctx) : undefined;\n\n return options.map((primary: Option): DatasetOption => {\n const datasetSpec = ctx.resultPool.getPColumnSpecByRef(primary.ref);\n if (!datasetSpec) return { primary };\n\n const filterMatches = findFilterColumns({\n sources: [filterSource],\n anchorSpec: datasetSpec,\n }).filter((m) => filterPredicate(m.getSpec()!));\n\n const filters =\n filterMatches.length === 0\n ? undefined\n : filterMatchesToOptions(filterMatches, {\n refsByObjectId: refMap,\n datasetSpec,\n labelOptions: opts?.labelOptions,\n });\n\n let enrichments;\n if (enrichmentSources && withEnrichments) {\n const enrichmentVariants = findEnrichmentColumns({\n sources: enrichmentSources,\n anchorSpec: datasetSpec,\n maxHops: opts?.enrichmentMaxHops,\n ...(typeof withEnrichments === \"function\"\n ? { predicate: withEnrichments }\n : { include: withEnrichments }),\n });\n if (enrichmentVariants.length > 0) {\n enrichments = enrichmentVariantsToRefs(enrichmentVariants, opts?.labelOptions);\n }\n }\n\n return {\n primary,\n ...(filters !== undefined && filters.length > 0 ? { filters } : {}),\n ...(enrichments !== undefined && enrichments.length > 0 ? { enrichments } : {}),\n };\n });\n}\n"],"mappings":";;;;;;;AAcA,SAAS,YAAY,KAAsE;CACzF,IAAI,QAAQ,KAAA,GAAW,aAAa;CACpC,OAAO,OAAO,QAAQ,aAAa,MAAM,gCAAgC,GAAG;AAC9E;;;;;;;AAsCA,SAAgB,oBACd,KACA,MAC6B;CAC7B,MAAM,mBAAmB,YAAY,MAAM,OAAO;CAClD,MAAM,kBAAkB,YAAY,MAAM,MAAM;CAEhD,MAAM,UAAU,IAAI,WAAW,YAC5B,SAAS,cAAc,IAAI,KAAK,iBAAiB,IAAI,GACtD,EACE,qBAAqB,MAAM,sBAAsB,KACnD,CACF;CACA,IAAI,QAAQ,WAAW,GAAG,OAAO,CAAC;CAElC,MAAM,SAAS,YAAY,IAAI,WAAW,SAAS,CAAC,CAAC,OAAO;CAE5D,MAAM,kBAAkB,MAAM,mBAAmB;CACjD,MAAM,eAAe,gBAAgB,IAAI,IAAI,oBAAoB,CAAC;CAGlE,MAAM,oBAAoB,kBAAkB,gBAAgB,GAAG,IAAI,KAAA;CAEnE,OAAO,QAAQ,KAAK,YAAmC;EACrD,MAAM,cAAc,IAAI,WAAW,oBAAoB,QAAQ,GAAG;EAClE,IAAI,CAAC,aAAa,OAAO,EAAE,QAAQ;EAEnC,MAAM,gBAAgB,kBAAkB;GACtC,SAAS,CAAC,YAAY;GACtB,YAAY;EACd,CAAC,CAAC,CAAC,QAAQ,MAAM,gBAAgB,EAAE,QAAQ,CAAE,CAAC;EAE9C,MAAM,UACJ,cAAc,WAAW,IACrB,KAAA,IACA,uBAAuB,eAAe;GACpC,gBAAgB;GAChB;GACA,cAAc,MAAM;EACtB,CAAC;EAEP,IAAI;EACJ,IAAI,qBAAqB,iBAAiB;GACxC,MAAM,qBAAqB,sBAAsB;IAC/C,SAAS;IACT,YAAY;IACZ,SAAS,MAAM;IACf,GAAI,OAAO,oBAAoB,aAC3B,EAAE,WAAW,gBAAgB,IAC7B,EAAE,SAAS,gBAAgB;GACjC,CAAC;GACD,IAAI,mBAAmB,SAAS,GAC9B,cAAc,yBAAyB,oBAAoB,MAAM,YAAY;EAEjF;EAEA,OAAO;GACL;GACA,GAAI,YAAY,KAAA,KAAa,QAAQ,SAAS,IAAI,EAAE,QAAQ,IAAI,CAAC;GACjE,GAAI,gBAAgB,KAAA,KAAa,YAAY,SAAS,IAAI,EAAE,YAAY,IAAI,CAAC;EAC/E;CACF,CAAC;AACH"}
package/dist/package.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  // package.json
2
- var version = "1.86.3";
2
+ var version = "1.86.5";
3
3
  Object.defineProperty(exports, "version", {
4
4
  enumerable: true,
5
5
  get: function() {
package/dist/package.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // package.json
2
- var version = "1.86.3";
2
+ var version = "1.86.5";
3
3
  export { version };
4
4
 
5
5
  //# sourceMappingURL=package.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platforma-sdk/model",
3
- "version": "1.86.3",
3
+ "version": "1.86.5",
4
4
  "description": "Platforma.bio SDK / Block Model",
5
5
  "files": [
6
6
  "./dist/**/*",
@@ -27,9 +27,9 @@
27
27
  "dependencies": {
28
28
  "@milaboratories/helpers": "1.14.6",
29
29
  "@milaboratories/pl-error-like": "1.12.10",
30
- "@milaboratories/pl-model-common": "1.54.1",
31
- "@milaboratories/pl-model-middle-layer": "1.34.5",
32
- "@milaboratories/ptabler-expression-js": "1.2.45",
30
+ "@milaboratories/pl-model-common": "1.54.2",
31
+ "@milaboratories/pl-model-middle-layer": "1.34.6",
32
+ "@milaboratories/ptabler-expression-js": "1.2.46",
33
33
  "canonicalize": "~2.1.0",
34
34
  "es-toolkit": "^1.39.10",
35
35
  "fast-json-patch": "^3.1.1",
@@ -39,9 +39,9 @@
39
39
  },
40
40
  "devDependencies": {
41
41
  "@milaboratories/build-configs": "2.0.2",
42
- "@milaboratories/columns-collection-driver": "0.2.11",
43
- "@milaboratories/pf-driver": "1.9.11",
44
- "@milaboratories/pf-spec-driver": "1.5.11",
42
+ "@milaboratories/columns-collection-driver": "0.2.12",
43
+ "@milaboratories/pf-driver": "1.9.12",
44
+ "@milaboratories/pf-spec-driver": "1.5.12",
45
45
  "@milaboratories/ts-builder": "1.7.3",
46
46
  "@milaboratories/ts-configs": "1.4.0",
47
47
  "@platforma-sdk/block-kind": "1.1.0",
@@ -18,11 +18,11 @@ import type {
18
18
  ColumnsCollectionDriverHost,
19
19
  ColumnsCollectionDriverModel,
20
20
  LeafEntry,
21
- PColumnSpec,
22
21
  PObjectId,
22
+ PObjectSpec,
23
23
  ServiceName,
24
24
  } from "@milaboratories/pl-model-common";
25
- import { extractPObjectId, Services } from "@milaboratories/pl-model-common";
25
+ import { extractPObjectId, isPColumnSpec, Services } from "@milaboratories/pl-model-common";
26
26
  import { ColumnsCollectionDriverImpl } from "@milaboratories/columns-collection-driver";
27
27
  import { SpecDriver } from "@milaboratories/pf-spec-driver";
28
28
  import type { GlobalCfgRenderCtx } from "../../render/internal";
@@ -34,7 +34,7 @@ import { DataColumn, type DataColumnRecipe } from "../data_column";
34
34
  export interface TestCollectionDriverHandle {
35
35
  readonly driver: ColumnsCollectionDriverModel;
36
36
  /** Register `(id → spec)` pairs the driver will see via `resolveSpec`. */
37
- register(columns: ReadonlyArray<{ readonly id: PObjectId; readonly spec: PColumnSpec }>): void;
37
+ register(columns: ReadonlyArray<{ readonly id: PObjectId; readonly spec: PObjectSpec }>): void;
38
38
  /**
39
39
  * Install a minimal `globalThis.cfgRenderCtx` so `getService("columnsCollection")`
40
40
  * resolves to this driver and registered columns are reachable via
@@ -72,7 +72,7 @@ const PFRAME_SPEC_METHODS: ReadonlyArray<string> = [
72
72
  ];
73
73
 
74
74
  export function createTestCollectionDriver(): TestCollectionDriverHandle {
75
- const specMap = new Map<PObjectId, PColumnSpec>();
75
+ const specMap = new Map<PObjectId, PObjectSpec>();
76
76
  const specDriver = new SpecDriver();
77
77
  const impl = new ColumnsCollectionDriverImpl();
78
78
 
@@ -87,7 +87,7 @@ export function createTestCollectionDriver(): TestCollectionDriverHandle {
87
87
 
88
88
  const driver: ColumnsCollectionDriverModel = {
89
89
  create: (sources) => impl.create(sources, bindings).key,
90
- isEmpty: (h) => impl.isEmpty(h),
90
+ isEmpty: (h) => impl.isEmpty(h, bindings),
91
91
  isFinal: (h) => impl.isFinal(h),
92
92
  getColumns: (h) => impl.getColumns(h, bindings),
93
93
  addSource: (h, srcs) => impl.addSource(h, srcs, bindings).key,
@@ -157,7 +157,7 @@ export function createTestCollectionDriver(): TestCollectionDriverHandle {
157
157
  * - `getInputsLocked()` → `true` (no pending resolution).
158
158
  */
159
159
  function buildStubProvider(
160
- specMap: ReadonlyMap<PObjectId, PColumnSpec>,
160
+ specMap: ReadonlyMap<PObjectId, PObjectSpec>,
161
161
  ): ColumnEntriesProvider<TreeNodeAccessor> & ColumnsProvider {
162
162
  const entries = new Map<PObjectId, LeafEntry<TreeNodeAccessor>>();
163
163
  for (const [id, spec] of specMap) {
@@ -165,7 +165,9 @@ function buildStubProvider(
165
165
  }
166
166
  const columns: DataColumnRecipe<PObjectId>[] = [];
167
167
  for (const [id, spec] of specMap) {
168
- columns.push(DataColumn.fromColumn({ id, spec, data: undefined as never }));
168
+ if (isPColumnSpec(spec)) {
169
+ columns.push(DataColumn.fromColumn({ id, spec, data: undefined as never }));
170
+ }
169
171
  }
170
172
  return {
171
173
  getPObjectEntries: () => entries,
@@ -174,7 +176,7 @@ function buildStubProvider(
174
176
  };
175
177
  }
176
178
 
177
- function stubAccessorFor(id: PObjectId, spec: PColumnSpec): TreeNodeAccessor {
179
+ function stubAccessorFor(id: PObjectId, spec: PObjectSpec): TreeNodeAccessor {
178
180
  const specField = `${id}.spec`;
179
181
  const specHolder = {
180
182
  getDataAsJson: <T>() => spec as unknown as T,
@@ -23,7 +23,9 @@ import type {
23
23
  LeafEntry,
24
24
  PColumnSpec,
25
25
  PObjectId,
26
+ PObjectSpec,
26
27
  } from "@milaboratories/pl-model-common";
28
+ import { isPColumnSpec } from "@milaboratories/pl-model-common";
27
29
  import type { GlobalCfgRenderCtx } from "../../render/internal";
28
30
  import type { TreeNodeAccessor } from "../../render/accessor";
29
31
  import { _ctxProvidersCache } from "../column_providers";
@@ -33,7 +35,7 @@ import { DataColumn, type DataColumnRecipe } from "../data_column";
33
35
  /** Fine-grained per-leaf stub config. Defaults match the shorthand form. */
34
36
  export type StubLeafConfig = {
35
37
  /** Spec returned by `${id}.spec` traverse. Omit to simulate a missing field. */
36
- spec?: PColumnSpec;
38
+ spec?: PObjectSpec;
37
39
  /** Drives `leaf.accessor.getInputsLocked()`. Default `true`. */
38
40
  accessorLocked?: boolean;
39
41
  /** Drives `spec.hasData()` (ignored when `spec` is omitted). Default `true`. */
@@ -63,7 +65,7 @@ function buildStubProvider(
63
65
  (acc, [id, raw]) => {
64
66
  const cfg = normalizeLeafInput(raw);
65
67
  acc.entries.set(id, { accessor: stubAccessorFor(id, cfg), name: id, id });
66
- if (cfg.spec !== undefined && cfg.specHasData) {
68
+ if (cfg.spec !== undefined && cfg.specHasData && isPColumnSpec(cfg.spec)) {
67
69
  acc.columns.push(DataColumn.fromColumn({ id, spec: cfg.spec, data: undefined as never }));
68
70
  }
69
71
  return acc;
@@ -81,13 +83,13 @@ function buildStubProvider(
81
83
  }
82
84
 
83
85
  type NormalizedLeafConfig = {
84
- spec?: PColumnSpec;
86
+ spec?: PObjectSpec;
85
87
  accessorLocked: boolean;
86
88
  specHasData: boolean;
87
89
  };
88
90
 
89
91
  function normalizeLeafInput(raw: StubLeafInput): NormalizedLeafConfig {
90
- if (isPColumnSpec(raw)) {
92
+ if ("kind" in raw) {
91
93
  return { spec: raw, accessorLocked: true, specHasData: true };
92
94
  }
93
95
  return {
@@ -97,10 +99,6 @@ function normalizeLeafInput(raw: StubLeafInput): NormalizedLeafConfig {
97
99
  };
98
100
  }
99
101
 
100
- function isPColumnSpec(v: StubLeafInput): v is PColumnSpec {
101
- return typeof v === "object" && v !== null && "kind" in v;
102
- }
103
-
104
102
  let stubAccessorSeq = 0;
105
103
 
106
104
  function stubAccessorFor(id: PObjectId, cfg: NormalizedLeafConfig): TreeNodeAccessor {
@@ -0,0 +1,45 @@
1
+ import type { PObjectSpec } from "@milaboratories/pl-model-common";
2
+ import { ResourceTypeName } from "@milaboratories/pl-model-common";
3
+ import { afterEach, expect, test } from "vitest";
4
+ import type { AccessorHandle } from "../../render/internal";
5
+ import { TreeNodeAccessor } from "../../render/accessor";
6
+ import { AccessorColumnsProviderImpl } from "./providers";
7
+
8
+ const rootHandle = "pframe" as AccessorHandle;
9
+
10
+ function installPFrameCtx(specs: Record<string, PObjectSpec>): void {
11
+ const fieldOf = (step: string | { field: string }) =>
12
+ typeof step === "string" ? step : step.field;
13
+ const specOf = (handle: AccessorHandle) => specs[handle.slice(`${rootHandle}/`.length)];
14
+ (globalThis as { cfgRenderCtx?: unknown }).cfgRenderCtx = {
15
+ resolveWithCommon: (
16
+ handle: AccessorHandle,
17
+ _options: unknown,
18
+ step: string | { field: string },
19
+ ) => {
20
+ const name = fieldOf(step).slice(0, -".spec".length);
21
+ if (handle !== rootHandle || specs[name] === undefined) {
22
+ return undefined;
23
+ }
24
+ return `${rootHandle}/${name}` as AccessorHandle;
25
+ },
26
+ getResourceType: () => ({ name: ResourceTypeName.PFrame, version: "1" }),
27
+ getInputsLocked: () => true,
28
+ listInputFields: () => Object.keys(specs).map((name) => `${name}.spec`),
29
+ hasData: () => true,
30
+ getDataAsString: (handle: AccessorHandle) => JSON.stringify(specOf(handle)),
31
+ };
32
+ }
33
+
34
+ afterEach(() => {
35
+ delete (globalThis as { cfgRenderCtx?: unknown }).cfgRenderCtx;
36
+ });
37
+
38
+ test("getColumns skips an export that is not a column", () => {
39
+ installPFrameCtx({
40
+ clones: { kind: "PColumn", name: "clones", valueType: "Int", axesSpec: [] },
41
+ library: { kind: "File", name: "library" },
42
+ });
43
+ const provider = new AccessorColumnsProviderImpl(new TreeNodeAccessor(rootHandle, ["main"]));
44
+ expect(provider.getColumns().map((column) => column.getSpec().name)).toEqual(["clones"]);
45
+ });
@@ -1,12 +1,13 @@
1
1
  import {
2
2
  AccessorEntriesProvider,
3
3
  ResultPoolEntriesProvider,
4
+ type LeafEntry,
4
5
  type PColumn,
5
6
  type PObjectId,
6
7
  type UpstreamBlockCtx,
7
8
  } from "@milaboratories/pl-model-common";
8
9
  import { AccessorHandle, PColumnDataUniversal, TreeNodeAccessor } from "../../render";
9
- import { DataColumn, DataColumnRecipe } from "../data_column";
10
+ import { ColumnAbsentError, DataColumn, DataColumnRecipe } from "../data_column";
10
11
  import { getCfgRenderCtx } from "../../internal";
11
12
  import { isNil } from "es-toolkit";
12
13
  import { LRUCache } from "lru-cache";
@@ -129,9 +130,9 @@ export class AccessorColumnsProviderImpl
129
130
 
130
131
  getColumns(): DataColumnRecipe<PObjectId>[] {
131
132
  if (this.cachedColumns !== undefined) return this.cachedColumns;
132
- return (this.cachedColumns = Array.from(this.entries.values())
133
- .map((e) => DataColumn.fromAccessor(e))
134
- .filter((v): v is DataColumnRecipe<PObjectId> => !isNil(v)));
133
+ return (this.cachedColumns = Array.from(this.entries.values(), columnUnlessAbsent).filter(
134
+ (column) => column !== undefined,
135
+ ));
135
136
  }
136
137
  }
137
138
 
@@ -173,15 +174,27 @@ export class ResultPoolColumnsProviderImpl
173
174
 
174
175
  getColumns(): DataColumnRecipe<PObjectId>[] {
175
176
  if (this.cachedColumns !== undefined) return this.cachedColumns;
176
- return (this.cachedColumns = Array.from(this.getPObjectEntries().values())
177
- .map((e) => DataColumn.fromAccessor(e))
178
- .filter((v): v is DataColumnRecipe<PObjectId> => !isNil(v)));
177
+ return (this.cachedColumns = Array.from(
178
+ this.getPObjectEntries().values(),
179
+ columnUnlessAbsent,
180
+ ).filter((column) => column !== undefined));
179
181
  }
180
182
  }
181
183
 
182
184
  /** Public type alias — value of the same name is the memoised factory above. */
183
185
  export type ResultPoolColumnsProvider = ResultPoolColumnsProviderImpl;
184
186
 
187
+ function columnUnlessAbsent(
188
+ entry: LeafEntry<TreeNodeAccessor>,
189
+ ): DataColumnRecipe<PObjectId> | undefined {
190
+ try {
191
+ return DataColumn.fromAccessor(entry);
192
+ } catch (error) {
193
+ if (error instanceof ColumnAbsentError) return undefined;
194
+ throw error;
195
+ }
196
+ }
197
+
185
198
  function hashRawPool(rawPool: ReadonlyArray<UpstreamBlockCtx<AccessorHandle>>): string {
186
199
  return rawPool
187
200
  .map(
@@ -79,6 +79,23 @@ describe("ColumnsCollection.isEmpty", () => {
79
79
  const c = { id: gid("c1"), spec: spec("col1") };
80
80
  expect(makeCollection([c]).isEmpty()).toBe(false);
81
81
  });
82
+
83
+ test("driver: true when the only export is not a column", () => {
84
+ const file = { id: gid("library"), spec: { kind: "File", name: "library" } };
85
+ handle.register([file]);
86
+ const collection = handle.driver.create([{ kind: "ids", ids: [file.id], isFinal: true }]);
87
+ expect(handle.driver.isEmpty(collection)).toBe(true);
88
+ });
89
+
90
+ test("driver: lists an id only once its spec is readable", () => {
91
+ const late = { id: gid("late"), spec: spec("late") };
92
+ const collection = handle.driver.create([{ kind: "ids", ids: [late.id], isFinal: true }]);
93
+ expect(handle.driver.getColumns(collection)).toEqual([]);
94
+ expect(handle.driver.isEmpty(collection)).toBe(true);
95
+ handle.register([late]);
96
+ expect(handle.driver.getColumns(collection)).toEqual([late.id]);
97
+ expect(handle.driver.isEmpty(collection)).toBe(false);
98
+ });
82
99
  });
83
100
 
84
101
  describe("ColumnsCollection.isFinal", () => {
@@ -114,6 +131,28 @@ describe("ColumnsCollection.getColumnIds", () => {
114
131
  });
115
132
  });
116
133
 
134
+ describe("ColumnsCollection driver getColumns", () => {
135
+ test("drops ids whose spec is not a column", () => {
136
+ const column = { id: gid("c1"), spec: spec("col1") };
137
+ const file = { id: gid("library"), spec: { kind: "File", name: "library" } };
138
+ handle.register([column, file]);
139
+ const collection = handle.driver.create([
140
+ { kind: "ids", ids: [column.id, file.id], isFinal: true },
141
+ ]);
142
+ expect(handle.driver.getColumns(collection)).toEqual([column.id]);
143
+ });
144
+
145
+ test("filter over a collection with a file export returns only columns", () => {
146
+ const column = { id: gid("c1"), spec: spec("col1") };
147
+ const file = { id: gid("library"), spec: { kind: "File", name: "library" } };
148
+ handle.register([column, file]);
149
+ const collection = handle.driver.create([
150
+ { kind: "ids", ids: [column.id, file.id], isFinal: true },
151
+ ]);
152
+ expect(handle.driver.getColumns(handle.driver.filter(collection, {}))).toEqual([column.id]);
153
+ });
154
+ });
155
+
117
156
  describe("ColumnsCollection.addSource", () => {
118
157
  test("returns new instance, original unchanged", () => {
119
158
  const c1 = { id: gid("c1"), spec: spec("col1") };
@@ -5,6 +5,7 @@ import {
5
5
  SpecOverrides,
6
6
  type PColumnSpec,
7
7
  type PObjectId,
8
+ type PObjectSpec,
8
9
  } from "@milaboratories/pl-model-common";
9
10
  import { ColumnAbsentError, DataColumnImpl } from "./data_column";
10
11
  import { _ctxProvidersCache } from "./column_providers";
@@ -33,6 +34,8 @@ const baseLeaf = createLocalPObjectId(["main", "out"], "col-1");
33
34
 
34
35
  const stubSpec = { kind: "PColumn", name: "stub" } as unknown as PColumnSpec;
35
36
 
37
+ const fileSpec: PObjectSpec = { kind: "File", name: "library" };
38
+
36
39
  function lazyOf(id: PObjectId, spec: PColumnSpec = stubSpec) {
37
40
  return DataColumnImpl.fromColumn({ id, spec, data: undefined });
38
41
  }
@@ -166,6 +169,13 @@ describe("DataColumnImpl resolution: fromId / fromAccessor / getStatus", () => {
166
169
  expect(DataColumnImpl.fromAccessor(entry)).toBeUndefined();
167
170
  });
168
171
 
172
+ test("an export that is not a column: fromId and fromAccessor throw, status tracks only resolution", () => {
173
+ installStubRegistry(mockCtx, { [baseLeaf]: { spec: fileSpec } });
174
+ expect(() => DataColumnImpl.fromId(baseLeaf)).toThrow(ColumnAbsentError);
175
+ expect(() => DataColumnImpl.fromAccessor(pluckLeafEntry(baseLeaf))).toThrow(ColumnAbsentError);
176
+ expect(DataColumnImpl.getStatusById(baseLeaf)).toBe("present");
177
+ });
178
+
169
179
  test("getStatusById returns 'absent' / 'resolving' / 'present' across configurations", () => {
170
180
  // present — spec with data on a locked, populated leaf.
171
181
  installStubRegistry(mockCtx, { [baseLeaf]: stubSpec });
@@ -2,6 +2,7 @@ import {
2
2
  ColumnRegistry,
3
3
  createGlobalPObjectId,
4
4
  isPColumn,
5
+ isPColumnSpec,
5
6
  isPlRef,
6
7
  PlRef,
7
8
  PObjectId,
@@ -9,6 +10,7 @@ import {
9
10
  type LeafEntry,
10
11
  type PColumn,
11
12
  type PColumnSpec,
13
+ type PObjectSpec,
12
14
  type SpecOverrides,
13
15
  type SpecQuery,
14
16
  } from "@milaboratories/pl-model-common";
@@ -134,8 +136,9 @@ export class DataColumnImpl implements DataColumnRecipe<PObjectId> {
134
136
  * Resolve via the ambient {@link ColumnRegistry}. Spec is resolved eagerly:
135
137
  * returns `undefined` if the leaf isn't reachable yet (resolving). Throws
136
138
  * {@link ColumnAbsentError} when every relevant accessor is `inputsLocked`
137
- * and the column did not appear — the column will not exist in this ctx.
138
- * Data and dataStatus stay lazy.
139
+ * and the column did not appear, or when the id names an export that is not
140
+ * a column (a `kind: "File"` object, for example) — the column will not
141
+ * exist in this ctx. Data and dataStatus stay lazy.
139
142
  */
140
143
  static fromId(
141
144
  id: PObjectId,
@@ -147,17 +150,7 @@ export class DataColumnImpl implements DataColumnRecipe<PObjectId> {
147
150
  if (registry.isFinal()) throw new ColumnAbsentError(id);
148
151
  return undefined;
149
152
  }
150
- const spec = readSpecAccessor(leaf);
151
- if (isNil(spec)) {
152
- if (leaf.accessor.getInputsLocked()) throw new ColumnAbsentError(id);
153
- return undefined;
154
- }
155
- if (!spec.hasData()) return undefined;
156
- return new DataColumnImpl(id, {
157
- getSpec: () => spec.getDataAsJson<PColumnSpec>(),
158
- getData: () => readDataAccessor(leaf),
159
- getDataStatus: () => readDataStatus(leaf),
160
- });
153
+ return DataColumnImpl.fromAccessor(leaf);
161
154
  }
162
155
 
163
156
  /** {@link PlRef} wrapper over {@link fromId}. */
@@ -168,17 +161,19 @@ export class DataColumnImpl implements DataColumnRecipe<PObjectId> {
168
161
  /**
169
162
  * Bind directly to an accessor-backed {@link LeafEntry} — no registry.
170
163
  * Throws {@link ColumnAbsentError} if the leaf has no spec field and its
171
- * accessor is `inputsLocked`. Returns `undefined` while still resolving.
164
+ * accessor is `inputsLocked`, or if it names an export that is not a column.
165
+ * Returns `undefined` while still resolving.
172
166
  */
173
167
  static fromAccessor(entry: LeafEntry<TreeNodeAccessor>): undefined | DataColumnRecipe<PObjectId> {
174
- const spec = readSpecAccessor(entry);
175
- if (isNil(spec)) {
168
+ if (isNil(readSpecAccessor(entry))) {
176
169
  if (entry.accessor.getInputsLocked()) throw new ColumnAbsentError(entry.id);
177
170
  return undefined;
178
171
  }
179
- if (!spec.hasData()) return undefined;
172
+ const spec = readSpec(entry);
173
+ if (spec === undefined) return undefined;
174
+ if (!isPColumnSpec(spec)) throw new ColumnAbsentError(entry.id);
180
175
  return new DataColumnImpl(entry.id, {
181
- getSpec: () => spec.getDataAsJson<PColumnSpec>(),
176
+ getSpec: () => spec,
182
177
  getData: () => readDataAccessor(entry),
183
178
  getDataStatus: () => readDataStatus(entry),
184
179
  });
@@ -208,7 +203,9 @@ export class DataColumnImpl implements DataColumnRecipe<PObjectId> {
208
203
  * Distinguishes `present` / `resolving` / `absent` for a {@link PObjectId}
209
204
  * in the active render ctx. Falls back to the registry's `isFinal()`
210
205
  * when the id has no entry — only then we can say `absent` instead of
211
- * `resolving`.
206
+ * `resolving`. The status tells only whether the spec is readable: for an
207
+ * export that is not a column it is `present`, and the factories throw
208
+ * {@link ColumnAbsentError}.
212
209
  */
213
210
  static getStatusById(
214
211
  id: PObjectId,
@@ -306,6 +303,13 @@ const readSpecAccessor = memoizeByEntry(
306
303
  accessor.traverse({ field: `${name}.spec`, assertFieldType: "Input", ignoreError: true }),
307
304
  );
308
305
 
306
+ /** The leaf's spec, or `undefined` until the spec resource has data. */
307
+ const readSpec = memoizeByEntry((entry: LeafEntry<TreeNodeAccessor>): undefined | PObjectSpec => {
308
+ const spec = readSpecAccessor(entry);
309
+ if (isNil(spec) || !spec.hasData()) return undefined;
310
+ return spec.getDataAsJson<PObjectSpec>();
311
+ });
312
+
309
313
  /**
310
314
  * Per-entry counterpart to {@link readDataStatus}: tells whether the leaf's
311
315
  * **spec** can be read in this ctx, and — for the negative cases —
@@ -1,5 +1,5 @@
1
1
  import type { MultiColumnSelector, Option, PObjectSpec } from "@milaboratories/pl-model-common";
2
- import { multiColumnSelectorsToPredicate } from "@milaboratories/pl-model-common";
2
+ import { isPColumnSpec, multiColumnSelectorsToPredicate } from "@milaboratories/pl-model-common";
3
3
  import type { DeriveLabelsOptions } from "../../labels/derive_distinct_labels";
4
4
  import type { RenderCtxBase } from "../../render";
5
5
  import type { DatasetOption } from "./dataset_selection";
@@ -60,9 +60,12 @@ export function buildDatasetOptions(
60
60
  const primaryPredicate = toPredicate(opts?.primary);
61
61
  const filterPredicate = toPredicate(opts?.filter);
62
62
 
63
- const options = ctx.resultPool.getOptions(primaryPredicate, {
64
- refsWithEnrichments: opts?.requireEnrichments ?? true,
65
- });
63
+ const options = ctx.resultPool.getOptions(
64
+ (spec) => isPColumnSpec(spec) && primaryPredicate(spec),
65
+ {
66
+ refsWithEnrichments: opts?.requireEnrichments ?? true,
67
+ },
68
+ );
66
69
  if (options.length === 0) return [];
67
70
 
68
71
  const refMap = buildRefMap(ctx.resultPool.getSpecs().entries);
@@ -234,7 +234,7 @@ test("cluster-id preset: colliding columns are distinguished by a token they hav
234
234
  {
235
235
  type: "milaboratories.samples-and-data/dataset",
236
236
  importance: 100,
237
- label: "MB135 + Podocytes",
237
+ label: "Sample A + Cells",
238
238
  },
239
239
  {
240
240
  type: "milaboratories.mixcr-amplicon-alignment",