@platforma-sdk/model 1.86.5 → 1.88.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/block_api_v3.d.ts +9 -0
- package/dist/block_api_v3.d.ts.map +1 -1
- package/dist/block_model.cjs +89 -9
- package/dist/block_model.cjs.map +1 -1
- package/dist/block_model.d.ts +81 -19
- package/dist/block_model.d.ts.map +1 -1
- package/dist/block_model.js +89 -9
- package/dist/block_model.js.map +1 -1
- package/dist/block_storage_callbacks.cjs +128 -25
- package/dist/block_storage_callbacks.cjs.map +1 -1
- package/dist/block_storage_callbacks.js +129 -26
- package/dist/block_storage_callbacks.js.map +1 -1
- package/dist/block_storage_facade.cjs.map +1 -1
- package/dist/block_storage_facade.d.ts +37 -4
- package/dist/block_storage_facade.d.ts.map +1 -1
- package/dist/block_storage_facade.js.map +1 -1
- package/dist/columns/column_providers/providers.cjs +2 -10
- package/dist/columns/column_providers/providers.cjs.map +1 -1
- package/dist/columns/column_providers/providers.d.ts.map +1 -1
- package/dist/columns/column_providers/providers.js +3 -11
- package/dist/columns/column_providers/providers.js.map +1 -1
- package/dist/columns/column_recipes/index.cjs +2 -2
- package/dist/columns/column_recipes/index.cjs.map +1 -1
- package/dist/columns/column_recipes/index.d.ts +2 -3
- package/dist/columns/column_recipes/index.d.ts.map +1 -1
- package/dist/columns/column_recipes/index.js +2 -2
- package/dist/columns/column_recipes/index.js.map +1 -1
- package/dist/columns/column_values.cjs +126 -0
- package/dist/columns/column_values.cjs.map +1 -0
- package/dist/columns/column_values.d.ts +65 -0
- package/dist/columns/column_values.d.ts.map +1 -0
- package/dist/columns/column_values.js +124 -0
- package/dist/columns/column_values.js.map +1 -0
- package/dist/columns/data_column.cjs +12 -42
- package/dist/columns/data_column.cjs.map +1 -1
- package/dist/columns/data_column.d.ts +10 -26
- package/dist/columns/data_column.d.ts.map +1 -1
- package/dist/columns/data_column.js +13 -42
- package/dist/columns/data_column.js.map +1 -1
- package/dist/columns/index.cjs +4 -1
- package/dist/columns/index.d.ts +3 -2
- package/dist/columns/index.js +3 -2
- package/dist/index.cjs +6 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.js +4 -2
- package/dist/package.cjs +1 -1
- package/dist/package.js +1 -1
- package/dist/pframe_utils/column_value_options.cjs +85 -0
- package/dist/pframe_utils/column_value_options.cjs.map +1 -0
- package/dist/pframe_utils/column_value_options.d.ts +14 -0
- package/dist/pframe_utils/column_value_options.d.ts.map +1 -0
- package/dist/pframe_utils/column_value_options.js +85 -0
- package/dist/pframe_utils/column_value_options.js.map +1 -0
- package/dist/pframe_utils/index.cjs +2 -0
- package/dist/pframe_utils/index.cjs.map +1 -1
- package/dist/pframe_utils/index.d.ts +2 -1
- package/dist/pframe_utils/index.d.ts.map +1 -1
- package/dist/pframe_utils/index.js +2 -1
- package/dist/pframe_utils/index.js.map +1 -1
- package/package.json +7 -7
- package/src/args_issues.test.ts +532 -0
- package/src/block_api_v3.ts +10 -0
- package/src/block_model.ts +146 -32
- package/src/block_storage_callbacks.ts +174 -43
- package/src/block_storage_facade.ts +36 -6
- package/src/columns/column_providers/providers.ts +3 -15
- package/src/columns/column_recipes/column_recipes.test.ts +11 -15
- package/src/columns/column_recipes/index.ts +2 -3
- package/src/columns/column_values.test.ts +183 -0
- package/src/columns/column_values.ts +194 -0
- package/src/columns/data_column.test.ts +13 -14
- package/src/columns/data_column.ts +12 -41
- package/src/columns/index.ts +1 -0
- package/src/pframe_utils/column_value_options.test.ts +126 -0
- package/src/pframe_utils/column_value_options.ts +111 -0
- package/src/pframe_utils/index.ts +1 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { MutateStoragePayload } from "./block_storage.js";
|
|
2
2
|
import { ConfigRenderLambda } from "./bconfig/lambdas.js";
|
|
3
3
|
import "./bconfig/index.js";
|
|
4
|
-
import { StringifiedJson } from "@milaboratories/pl-model-common";
|
|
4
|
+
import { ArgsIssue, StringifiedJson } from "@milaboratories/pl-model-common";
|
|
5
5
|
/**
|
|
6
6
|
* The current facade version. This value is used for `requiresModelAPIVersion`
|
|
7
7
|
* feature flag in BlockModelV3.
|
|
@@ -93,27 +93,60 @@ export interface BlockStorageFacade {
|
|
|
93
93
|
};
|
|
94
94
|
/**
|
|
95
95
|
* Derive args from storage.
|
|
96
|
-
* Called to get block configuration args from storage.
|
|
96
|
+
* Called to get block configuration args from storage, and whether the block may run them.
|
|
97
|
+
*
|
|
98
|
+
* A middle layer that predates args issues reads only `error` and `value`, and each variant
|
|
99
|
+
* means the same to it as before: `value` is runnable args, `error` is no args. A block built
|
|
100
|
+
* with an SDK that predates args issues returns `{ error }` or `{ value }` with no `issues`.
|
|
101
|
+
*
|
|
97
102
|
* @param storageJson - Storage as JSON string
|
|
98
|
-
* @returns
|
|
103
|
+
* @returns One of:
|
|
104
|
+
* - `{ error }`: `args()` threw, so there are no args;
|
|
105
|
+
* - `{ error, args, issues }`: args were built, but the block's `argsIssues()` found errors in
|
|
106
|
+
* them, so the block must not run; `error` joins the error messages, `issues` lists every
|
|
107
|
+
* issue;
|
|
108
|
+
* - `{ value, issues }`: args the block may run; `issues` holds the warnings.
|
|
99
109
|
*/
|
|
100
110
|
[BlockStorageFacadeCallbacks.ArgsDerive]: (storageJson: StringifiedJson) => {
|
|
101
111
|
error: string;
|
|
112
|
+
} | {
|
|
113
|
+
error: string;
|
|
114
|
+
args: unknown;
|
|
115
|
+
issues: ArgsIssue[];
|
|
102
116
|
} | {
|
|
103
117
|
error?: undefined;
|
|
104
118
|
value: unknown;
|
|
119
|
+
issues: ArgsIssue[];
|
|
105
120
|
};
|
|
106
121
|
/**
|
|
107
122
|
* Derive prerunArgs from storage.
|
|
108
123
|
* Called to get prerun args; falls back to args callback if not registered.
|
|
124
|
+
*
|
|
125
|
+
* A block with its own prerunArgs is staged with them unless its `prerunArgsIssues()` finds errors
|
|
126
|
+
* in them. A block without its own prerunArgs is staged with its args unless its `argsIssues()`
|
|
127
|
+
* finds errors in them.
|
|
128
|
+
*
|
|
129
|
+
* A middle layer that predates args issues reads only `error` and `value`: `value` is args to
|
|
130
|
+
* stage, `error` skips staging. A block built with an SDK that predates args issues returns
|
|
131
|
+
* `{ error }` or `{ value }` with no `issues`.
|
|
132
|
+
*
|
|
109
133
|
* @param storageJson - Storage as JSON string
|
|
110
|
-
* @returns
|
|
134
|
+
* @returns One of:
|
|
135
|
+
* - `{ error }`: the lambda building the prerun args threw;
|
|
136
|
+
* - `{ error, issues }`: prerun args were built, but errors were found in them, so the block
|
|
137
|
+
* is not staged; `error` joins the error messages, `issues` lists every issue;
|
|
138
|
+
* - `{ value, issues }`: args to stage, `undefined` to skip staging; `issues` holds the
|
|
139
|
+
* warnings.
|
|
111
140
|
*/
|
|
112
141
|
[BlockStorageFacadeCallbacks.PrerunArgsDerive]: (storageJson: StringifiedJson) => {
|
|
113
142
|
error: string;
|
|
143
|
+
} | {
|
|
144
|
+
error: string;
|
|
145
|
+
issues: ArgsIssue[];
|
|
114
146
|
} | {
|
|
115
147
|
error?: undefined;
|
|
116
148
|
value: unknown;
|
|
149
|
+
issues: ArgsIssue[];
|
|
117
150
|
};
|
|
118
151
|
/**
|
|
119
152
|
* Get initial storage JSON for new blocks.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block_storage_facade.d.ts","names":[],"sources":["../src/block_storage_facade.ts"],"mappings":";;;;;;;;qBA8Da;;;;;;;;;;qBAeA;WACX;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;;;;;;qBAmBW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA0BI;;;;;;;;GAQd,4BAA4B,sBAC3B,oBAAoB,iBACpB,SAAS,yBACN;;;;;;;GAQJ,4BAA4B,oBAC3B,aAAa,gCACV;;;;;;;GAQJ,4BAA4B,kBAC3B,oBAAoB;IAEhB;;IAEA;IACA,gBAAgB;IAChB
|
|
1
|
+
{"version":3,"file":"block_storage_facade.d.ts","names":[],"sources":["../src/block_storage_facade.ts"],"mappings":";;;;;;;;qBA8Da;;;;;;;;;;qBAeA;WACX;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;;;;;;qBAmBW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA0BI;;;;;;;;GAQd,4BAA4B,sBAC3B,oBAAoB,iBACpB,SAAS,yBACN;;;;;;;GAQJ,4BAA4B,oBAC3B,aAAa,gCACV;;;;;;;GAQJ,4BAA4B,kBAC3B,oBAAoB;IAEhB;;IAEA;IACA,gBAAgB;IAChB;;;;;;;;;;;;;;;;;;GAmBL,4BAA4B,cAC3B,aAAa;IAET;;IACA;IAAe;IAAe,QAAQ;;IACtC;IAAmB;IAAgB,QAAQ;;;;;;;;;;;;;;;;;;;;;;GAsBhD,4BAA4B,oBAC3B,aAAa;IAET;;IACA;IAAe,QAAQ;;IACvB;IAAmB;IAAgB,QAAQ;;;;;;;GAOhD,4BAA4B,uBAAuB;;;;;;;;;;;;;;;;;GAkBnD,4BAA4B,8BAC3B,aAAa;IACR;;IAAoB;IAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6C7C,4BAA4B,4BAC3B,YAAY,iBACZ,cAAc;IACT;;IAAoB;IAAmB,aAAa;;;;;;;;;;;;;;;;;;;;;;GAsB1D,4BAA4B,gCAC3B,YAAY;IACP;;IAAoB;;;;wBAIb,wBAAwB,WAAW"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block_storage_facade.js","names":[],"sources":["../src/block_storage_facade.ts"],"sourcesContent":["/**\n * Block Storage Facade - Contract between bundled blocks and middle layer.\n *\n * ============================================================================\n * VERSIONING\n * ============================================================================\n *\n * Blocks declare their model API version via the `requiresModelAPIVersion` feature flag\n * (see BlockCodeKnownFeatureFlags). This determines how the middle layer manages block state:\n *\n * - Version 1: Legacy BlockModel - state is {args, uiState}, managed directly by middle layer\n * - Version 2: BlockModelV3 - uses blockStorage with VM-based callbacks (this facade)\n *\n * This facade (BlockStorageFacade) is used by blocks with `requiresModelAPIVersion: 2`.\n * The version number matches the model API version for clarity.\n *\n * ============================================================================\n * BACKWARD COMPATIBILITY WARNING\n * ============================================================================\n *\n * This file documents the FACADE between the SDK (bundled into blocks) and the\n * middle layer. Once a block is published, its SDK version is frozen. The middle\n * layer must support ALL previously released callback signatures indefinitely.\n *\n * RULES:\n * 1. NEVER change the signature of existing callbacks\n * 2. NEVER remove existing callbacks\n * 3. New callbacks CAN be added (old blocks won't register them, middle layer\n * should handle missing callbacks gracefully)\n * 4. Callback return types can be EXTENDED (add optional fields) but not changed\n * 5. Callback parameter types should remain compatible (middle layer may need\n * to handle both old and new formats)\n *\n * The facade consists of callbacks registered via `tryRegisterCallback()` with\n * the `__pl_` prefix. These are registered by the SDK when a block loads and\n * called by the middle layer to perform operations.\n *\n * ============================================================================\n * WHAT CAN BE CHANGED FREELY\n * ============================================================================\n *\n * - Middle layer code (lib/node/pl-middle-layer)\n * - SDK internal implementation (as long as callback contracts are preserved)\n * - SDK exports used ONLY by middle layer (not by blocks themselves)\n * - New SDK features that don't affect existing callbacks\n *\n * @module block_storage_facade\n */\n\nimport type { MutateStoragePayload } from \"./block_storage\";\nimport type { ConfigRenderLambda } from \"./bconfig\";\nimport { createRenderLambda, tryRegisterCallback } from \"./internal\";\nimport type { StringifiedJson } from \"@milaboratories/pl-model-common\";\n\n// =============================================================================\n// Facade Version\n// =============================================================================\n\n/**\n * The current facade version. This value is used for `requiresModelAPIVersion`\n * feature flag in BlockModelV3.\n */\nexport const BLOCK_STORAGE_FACADE_VERSION = 2;\n\n// =============================================================================\n// Facade Callback Names\n// =============================================================================\n\n/**\n * All facade callback names as constants.\n * These are the source of truth - the interface is derived from these.\n *\n * IMPORTANT: When adding a new callback:\n * 1. Add the constant here\n * 2. Add the callback signature to FacadeCallbackTypes below\n * 3. The BlockStorageFacade type will automatically include it\n */\nexport const BlockStorageFacadeCallbacks = {\n StorageApplyUpdate: \"__pl_storage_applyUpdate\",\n StorageDebugView: \"__pl_storage_debugView\",\n StorageMigrate: \"__pl_storage_migrate\",\n ArgsDerive: \"__pl_args_derive\",\n PrerunArgsDerive: \"__pl_prerunArgs_derive\",\n StorageInitial: \"__pl_storage_initial\",\n InitializationParamsDerive: \"__pl_initializationParams_derive\",\n StorageInitialFromParams: \"__pl_storage_initialFromParams\",\n InitializationParamsValidate: \"__pl_initializationParams_validate\",\n} as const;\n\n/**\n * Creates a map of lambda handles from a callbacks constant object.\n * Keys are the callback string values (e.g., '__pl_storage_applyUpdate').\n */\nfunction createFacadeHandles<T extends Record<string, string>>(\n callbacks: T,\n): { [K in T[keyof T]]: ConfigRenderLambda } {\n return Object.fromEntries(\n Object.values(callbacks).map((handle) => [handle, createRenderLambda({ handle })]),\n ) as { [K in T[keyof T]]: ConfigRenderLambda };\n}\n\n/**\n * Lambda handles for facade callbacks.\n * Used by the middle layer to invoke callbacks via executeSingleLambda().\n */\nexport const BlockStorageFacadeHandles = createFacadeHandles(BlockStorageFacadeCallbacks);\n\n// =============================================================================\n// Facade Interface (source of truth for callback signatures)\n// =============================================================================\n\n/**\n * The complete facade interface between bundled blocks (SDK) and middle layer.\n *\n * This interface defines ALL callbacks that a block registers. The middle layer\n * calls these callbacks to perform storage operations.\n *\n * ALL types are inlined to simplify versioning - when a callback changes,\n * the entire signature is visible in one place.\n *\n * BACKWARD COMPATIBILITY:\n * - This interface can only be EXTENDED, never shrunk\n * - Existing callback signatures MUST NOT change\n * - Middle layer should use Partial<BlockStorageFacade> when dealing with\n * blocks of unknown version (older blocks may not have all callbacks)\n *\n * Each callback is documented with:\n * - Purpose and when it's called\n * - Parameter descriptions\n * - Return value description\n */\nexport interface BlockStorageFacade {\n /**\n * Apply state update to storage.\n * Called when UI updates block state (setState) or plugin data.\n * @param currentStorageJson - Current storage as JSON string\n * @param payload - Update payload with operation type and value\n * @returns Updated storage as JSON string\n */\n [BlockStorageFacadeCallbacks.StorageApplyUpdate]: (\n currentStorageJson: StringifiedJson,\n payload: MutateStoragePayload,\n ) => StringifiedJson;\n\n /**\n * Get debug view of storage.\n * Called by developer tools to inspect storage state.\n * @param storageJson - Storage as JSON string (or undefined for new blocks)\n * @returns JSON string containing StorageDebugView\n */\n [BlockStorageFacadeCallbacks.StorageDebugView]: (\n storageJson: StringifiedJson | undefined,\n ) => StringifiedJson;\n\n /**\n * Run storage migration.\n * Called when block loads to migrate data to latest version.\n * @param currentStorageJson - Current storage as JSON string (or undefined for new blocks)\n * @returns Migration result - either error or success with new storage\n */\n [BlockStorageFacadeCallbacks.StorageMigrate]: (\n currentStorageJson: StringifiedJson | undefined,\n ) =>\n | { error: string }\n | {\n error?: undefined;\n newStorageJson: StringifiedJson;\n info: string;\n };\n\n /**\n * Derive args from storage.\n * Called to get block configuration args from storage.\n * @param storageJson - Storage as JSON string\n * @returns Args derivation result - either error or derived value\n */\n [BlockStorageFacadeCallbacks.ArgsDerive]: (\n storageJson: StringifiedJson,\n ) => { error: string } | { error?: undefined; value: unknown };\n\n /**\n * Derive prerunArgs from storage.\n * Called to get prerun args; falls back to args callback if not registered.\n * @param storageJson - Storage as JSON string\n * @returns Args derivation result - either error or derived value\n */\n [BlockStorageFacadeCallbacks.PrerunArgsDerive]: (\n storageJson: StringifiedJson,\n ) => { error: string } | { error?: undefined; value: unknown };\n\n /**\n * Get initial storage JSON for new blocks.\n * Called when creating a new block to get complete initial storage.\n * @returns Initial storage as JSON string\n */\n [BlockStorageFacadeCallbacks.StorageInitial]: () => StringifiedJson;\n\n /**\n * Derive this block's template entry params from storage.\n * Called when exporting the project as a template.\n *\n * Every V3 block declares `.templateParams()` — the model does not build without\n * it — so every export produces params. A block whose state carries nothing worth\n * restoring returns `{}`, which is written out and used as-is by init.\n *\n * The returned params are written out exactly as they come back, references included: the\n * template engine carrying them recognizes nothing in there, and the block that receives\n * them on the way back in is what repoints them. The caller supplies everything else in the\n * entry — `id`, `kind` — so the lambda cannot set them.\n *\n * @param storageJson - Storage as JSON string\n * @returns Either an error, or the params to write\n */\n [BlockStorageFacadeCallbacks.InitializationParamsDerive]: (\n storageJson: StringifiedJson,\n ) => { error: string } | { error?: undefined; value: unknown };\n\n /**\n * Get initial storage JSON for a block created from params.\n * Called when applying a template, once per entry that carries `params`.\n *\n * The mirror image of {@link BlockStorageFacadeCallbacks.InitializationParamsDerive}:\n * that one turns storage into params, this one turns params into storage. Every\n * applied entry comes through here, including one whose file omitted `params` —\n * an omitted key is read as `{}` and checked like any other value, so no entry\n * reaches a block without passing its kind's contract.\n * {@link BlockStorageFacadeCallbacks.StorageInitial} stays the UI-creation path,\n * where there are genuinely no params.\n *\n * Separate from `StorageInitial` rather than an optional argument to it,\n * deliberately: a block bundled with an older SDK does not register this\n * callback at all, so the caller sees it missing and can say so. Widening\n * `StorageInitial` would instead have that block silently ignore the params and\n * produce a default-initialized block that looks successfully applied.\n *\n * The params arrive as ordinary live params — references are `PlRef`s, already\n * pointing at the ids the target project just assigned. Resolution happens in\n * the engine, before this call, so a block's init factory never handles a\n * template-local reference.\n *\n * Errors are returned, not thrown: a factory rejecting params it cannot use is\n * an expected outcome for a hand-written template file, and every entry's\n * problem is reported together.\n *\n * **Also where the entry's references are pointed at this project.** Params reach here\n * exactly as the file held them: nothing between the block that exported them and this call\n * marks a reference, reads one, or rewrites one, because recognizing one means knowing the\n * reference system and this bundle is where that knowledge lives. `blockIdsJson` maps each\n * template-local entry id to the block id it was given, holding the entries created so far —\n * so an id it does not name is left alone, and a reference to an entry created later names\n * nothing rather than naming the wrong block.\n *\n * Relocating and initializing are one call rather than two because every call\n * re-instantiates the runtime and re-evaluates the whole model bundle: splitting them would\n * parse the block twice per entry to produce an intermediate only the second half reads.\n *\n * @param paramsJson - The entry's params as JSON string, as the file held them\n * @param blockIdsJson - template-local entry id → assigned block id, as a JSON object\n * @returns Either an error, or the initial storage as JSON string\n */\n [BlockStorageFacadeCallbacks.StorageInitialFromParams]: (\n paramsJson: StringifiedJson,\n blockIdsJson: StringifiedJson,\n ) => { error: string } | { error?: undefined; storageJson: StringifiedJson };\n\n /**\n * Check params against this block's kind, creating nothing.\n *\n * Called once per entry before a template is applied, so params a kind rejects are\n * reported against the entry that carries them while there is still no project — the\n * same reason references and ids are checked before construction starts. Applying\n * without this call is safe but worse: `StorageInitialFromParams` runs the same check\n * and refuses, by which point earlier entries have already been created.\n *\n * A pass carries nothing back but its own absence of error: every kind declares a\n * parser, so a pass means the params were checked against the contract, not merely\n * that they were valid JSON.\n *\n * Reference ids inside the params may be placeholders at this point: the check runs\n * before blocks exist, so what is verified is the shape of the params, not what they\n * point at.\n *\n * @param paramsJson The entry's params as JSON string\n * @returns Why the params were rejected, or nothing\n */\n [BlockStorageFacadeCallbacks.InitializationParamsValidate]: (\n paramsJson: StringifiedJson,\n ) => { error: string } | { error?: undefined };\n}\n\n/** Register all facade callbacks at once. Ensures all required callbacks are provided. */\nexport function registerFacadeCallbacks(callbacks: BlockStorageFacade): void {\n for (const key of Object.values(BlockStorageFacadeCallbacks)) {\n tryRegisterCallback(key, callbacks[key] as (...args: any[]) => any);\n }\n}\n"],"mappings":";;;;;;AA8DA,MAAa,+BAA+B;;;;;;;;;;AAe5C,MAAa,8BAA8B;CACzC,oBAAoB;CACpB,kBAAkB;CAClB,gBAAgB;CAChB,YAAY;CACZ,kBAAkB;CAClB,gBAAgB;CAChB,4BAA4B;CAC5B,0BAA0B;CAC1B,8BAA8B;AAChC;;;;;AAMA,SAAS,oBACP,WAC2C;CAC3C,OAAO,OAAO,YACZ,OAAO,OAAO,SAAS,CAAC,CAAC,KAAK,WAAW,CAAC,QAAQ,mBAAmB,EAAE,OAAO,CAAC,CAAC,CAAC,CACnF;AACF;;;;;AAMA,MAAa,4BAA4B,oBAAoB,2BAA2B;;AA0LxF,SAAgB,wBAAwB,WAAqC;CAC3E,KAAK,MAAM,OAAO,OAAO,OAAO,2BAA2B,GACzD,oBAAoB,KAAK,UAAU,IAA+B;AAEtE"}
|
|
1
|
+
{"version":3,"file":"block_storage_facade.js","names":[],"sources":["../src/block_storage_facade.ts"],"sourcesContent":["/**\n * Block Storage Facade - Contract between bundled blocks and middle layer.\n *\n * ============================================================================\n * VERSIONING\n * ============================================================================\n *\n * Blocks declare their model API version via the `requiresModelAPIVersion` feature flag\n * (see BlockCodeKnownFeatureFlags). This determines how the middle layer manages block state:\n *\n * - Version 1: Legacy BlockModel - state is {args, uiState}, managed directly by middle layer\n * - Version 2: BlockModelV3 - uses blockStorage with VM-based callbacks (this facade)\n *\n * This facade (BlockStorageFacade) is used by blocks with `requiresModelAPIVersion: 2`.\n * The version number matches the model API version for clarity.\n *\n * ============================================================================\n * BACKWARD COMPATIBILITY WARNING\n * ============================================================================\n *\n * This file documents the FACADE between the SDK (bundled into blocks) and the\n * middle layer. Once a block is published, its SDK version is frozen. The middle\n * layer must support ALL previously released callback signatures indefinitely.\n *\n * RULES:\n * 1. NEVER change the signature of existing callbacks\n * 2. NEVER remove existing callbacks\n * 3. New callbacks CAN be added (old blocks won't register them, middle layer\n * should handle missing callbacks gracefully)\n * 4. Callback return types can be EXTENDED (add optional fields) but not changed\n * 5. Callback parameter types should remain compatible (middle layer may need\n * to handle both old and new formats)\n *\n * The facade consists of callbacks registered via `tryRegisterCallback()` with\n * the `__pl_` prefix. These are registered by the SDK when a block loads and\n * called by the middle layer to perform operations.\n *\n * ============================================================================\n * WHAT CAN BE CHANGED FREELY\n * ============================================================================\n *\n * - Middle layer code (lib/node/pl-middle-layer)\n * - SDK internal implementation (as long as callback contracts are preserved)\n * - SDK exports used ONLY by middle layer (not by blocks themselves)\n * - New SDK features that don't affect existing callbacks\n *\n * @module block_storage_facade\n */\n\nimport type { MutateStoragePayload } from \"./block_storage\";\nimport type { ConfigRenderLambda } from \"./bconfig\";\nimport { createRenderLambda, tryRegisterCallback } from \"./internal\";\nimport type { ArgsIssue, StringifiedJson } from \"@milaboratories/pl-model-common\";\n\n// =============================================================================\n// Facade Version\n// =============================================================================\n\n/**\n * The current facade version. This value is used for `requiresModelAPIVersion`\n * feature flag in BlockModelV3.\n */\nexport const BLOCK_STORAGE_FACADE_VERSION = 2;\n\n// =============================================================================\n// Facade Callback Names\n// =============================================================================\n\n/**\n * All facade callback names as constants.\n * These are the source of truth - the interface is derived from these.\n *\n * IMPORTANT: When adding a new callback:\n * 1. Add the constant here\n * 2. Add the callback signature to FacadeCallbackTypes below\n * 3. The BlockStorageFacade type will automatically include it\n */\nexport const BlockStorageFacadeCallbacks = {\n StorageApplyUpdate: \"__pl_storage_applyUpdate\",\n StorageDebugView: \"__pl_storage_debugView\",\n StorageMigrate: \"__pl_storage_migrate\",\n ArgsDerive: \"__pl_args_derive\",\n PrerunArgsDerive: \"__pl_prerunArgs_derive\",\n StorageInitial: \"__pl_storage_initial\",\n InitializationParamsDerive: \"__pl_initializationParams_derive\",\n StorageInitialFromParams: \"__pl_storage_initialFromParams\",\n InitializationParamsValidate: \"__pl_initializationParams_validate\",\n} as const;\n\n/**\n * Creates a map of lambda handles from a callbacks constant object.\n * Keys are the callback string values (e.g., '__pl_storage_applyUpdate').\n */\nfunction createFacadeHandles<T extends Record<string, string>>(\n callbacks: T,\n): { [K in T[keyof T]]: ConfigRenderLambda } {\n return Object.fromEntries(\n Object.values(callbacks).map((handle) => [handle, createRenderLambda({ handle })]),\n ) as { [K in T[keyof T]]: ConfigRenderLambda };\n}\n\n/**\n * Lambda handles for facade callbacks.\n * Used by the middle layer to invoke callbacks via executeSingleLambda().\n */\nexport const BlockStorageFacadeHandles = createFacadeHandles(BlockStorageFacadeCallbacks);\n\n// =============================================================================\n// Facade Interface (source of truth for callback signatures)\n// =============================================================================\n\n/**\n * The complete facade interface between bundled blocks (SDK) and middle layer.\n *\n * This interface defines ALL callbacks that a block registers. The middle layer\n * calls these callbacks to perform storage operations.\n *\n * ALL types are inlined to simplify versioning - when a callback changes,\n * the entire signature is visible in one place.\n *\n * BACKWARD COMPATIBILITY:\n * - This interface can only be EXTENDED, never shrunk\n * - Existing callback signatures MUST NOT change\n * - Middle layer should use Partial<BlockStorageFacade> when dealing with\n * blocks of unknown version (older blocks may not have all callbacks)\n *\n * Each callback is documented with:\n * - Purpose and when it's called\n * - Parameter descriptions\n * - Return value description\n */\nexport interface BlockStorageFacade {\n /**\n * Apply state update to storage.\n * Called when UI updates block state (setState) or plugin data.\n * @param currentStorageJson - Current storage as JSON string\n * @param payload - Update payload with operation type and value\n * @returns Updated storage as JSON string\n */\n [BlockStorageFacadeCallbacks.StorageApplyUpdate]: (\n currentStorageJson: StringifiedJson,\n payload: MutateStoragePayload,\n ) => StringifiedJson;\n\n /**\n * Get debug view of storage.\n * Called by developer tools to inspect storage state.\n * @param storageJson - Storage as JSON string (or undefined for new blocks)\n * @returns JSON string containing StorageDebugView\n */\n [BlockStorageFacadeCallbacks.StorageDebugView]: (\n storageJson: StringifiedJson | undefined,\n ) => StringifiedJson;\n\n /**\n * Run storage migration.\n * Called when block loads to migrate data to latest version.\n * @param currentStorageJson - Current storage as JSON string (or undefined for new blocks)\n * @returns Migration result - either error or success with new storage\n */\n [BlockStorageFacadeCallbacks.StorageMigrate]: (\n currentStorageJson: StringifiedJson | undefined,\n ) =>\n | { error: string }\n | {\n error?: undefined;\n newStorageJson: StringifiedJson;\n info: string;\n };\n\n /**\n * Derive args from storage.\n * Called to get block configuration args from storage, and whether the block may run them.\n *\n * A middle layer that predates args issues reads only `error` and `value`, and each variant\n * means the same to it as before: `value` is runnable args, `error` is no args. A block built\n * with an SDK that predates args issues returns `{ error }` or `{ value }` with no `issues`.\n *\n * @param storageJson - Storage as JSON string\n * @returns One of:\n * - `{ error }`: `args()` threw, so there are no args;\n * - `{ error, args, issues }`: args were built, but the block's `argsIssues()` found errors in\n * them, so the block must not run; `error` joins the error messages, `issues` lists every\n * issue;\n * - `{ value, issues }`: args the block may run; `issues` holds the warnings.\n */\n [BlockStorageFacadeCallbacks.ArgsDerive]: (\n storageJson: StringifiedJson,\n ) =>\n | { error: string }\n | { error: string; args: unknown; issues: ArgsIssue[] }\n | { error?: undefined; value: unknown; issues: ArgsIssue[] };\n\n /**\n * Derive prerunArgs from storage.\n * Called to get prerun args; falls back to args callback if not registered.\n *\n * A block with its own prerunArgs is staged with them unless its `prerunArgsIssues()` finds errors\n * in them. A block without its own prerunArgs is staged with its args unless its `argsIssues()`\n * finds errors in them.\n *\n * A middle layer that predates args issues reads only `error` and `value`: `value` is args to\n * stage, `error` skips staging. A block built with an SDK that predates args issues returns\n * `{ error }` or `{ value }` with no `issues`.\n *\n * @param storageJson - Storage as JSON string\n * @returns One of:\n * - `{ error }`: the lambda building the prerun args threw;\n * - `{ error, issues }`: prerun args were built, but errors were found in them, so the block\n * is not staged; `error` joins the error messages, `issues` lists every issue;\n * - `{ value, issues }`: args to stage, `undefined` to skip staging; `issues` holds the\n * warnings.\n */\n [BlockStorageFacadeCallbacks.PrerunArgsDerive]: (\n storageJson: StringifiedJson,\n ) =>\n | { error: string }\n | { error: string; issues: ArgsIssue[] }\n | { error?: undefined; value: unknown; issues: ArgsIssue[] };\n\n /**\n * Get initial storage JSON for new blocks.\n * Called when creating a new block to get complete initial storage.\n * @returns Initial storage as JSON string\n */\n [BlockStorageFacadeCallbacks.StorageInitial]: () => StringifiedJson;\n\n /**\n * Derive this block's template entry params from storage.\n * Called when exporting the project as a template.\n *\n * Every V3 block declares `.templateParams()` — the model does not build without\n * it — so every export produces params. A block whose state carries nothing worth\n * restoring returns `{}`, which is written out and used as-is by init.\n *\n * The returned params are written out exactly as they come back, references included: the\n * template engine carrying them recognizes nothing in there, and the block that receives\n * them on the way back in is what repoints them. The caller supplies everything else in the\n * entry — `id`, `kind` — so the lambda cannot set them.\n *\n * @param storageJson - Storage as JSON string\n * @returns Either an error, or the params to write\n */\n [BlockStorageFacadeCallbacks.InitializationParamsDerive]: (\n storageJson: StringifiedJson,\n ) => { error: string } | { error?: undefined; value: unknown };\n\n /**\n * Get initial storage JSON for a block created from params.\n * Called when applying a template, once per entry that carries `params`.\n *\n * The mirror image of {@link BlockStorageFacadeCallbacks.InitializationParamsDerive}:\n * that one turns storage into params, this one turns params into storage. Every\n * applied entry comes through here, including one whose file omitted `params` —\n * an omitted key is read as `{}` and checked like any other value, so no entry\n * reaches a block without passing its kind's contract.\n * {@link BlockStorageFacadeCallbacks.StorageInitial} stays the UI-creation path,\n * where there are genuinely no params.\n *\n * Separate from `StorageInitial` rather than an optional argument to it,\n * deliberately: a block bundled with an older SDK does not register this\n * callback at all, so the caller sees it missing and can say so. Widening\n * `StorageInitial` would instead have that block silently ignore the params and\n * produce a default-initialized block that looks successfully applied.\n *\n * The params arrive as ordinary live params — references are `PlRef`s, already\n * pointing at the ids the target project just assigned. Resolution happens in\n * the engine, before this call, so a block's init factory never handles a\n * template-local reference.\n *\n * Errors are returned, not thrown: a factory rejecting params it cannot use is\n * an expected outcome for a hand-written template file, and every entry's\n * problem is reported together.\n *\n * **Also where the entry's references are pointed at this project.** Params reach here\n * exactly as the file held them: nothing between the block that exported them and this call\n * marks a reference, reads one, or rewrites one, because recognizing one means knowing the\n * reference system and this bundle is where that knowledge lives. `blockIdsJson` maps each\n * template-local entry id to the block id it was given, holding the entries created so far —\n * so an id it does not name is left alone, and a reference to an entry created later names\n * nothing rather than naming the wrong block.\n *\n * Relocating and initializing are one call rather than two because every call\n * re-instantiates the runtime and re-evaluates the whole model bundle: splitting them would\n * parse the block twice per entry to produce an intermediate only the second half reads.\n *\n * @param paramsJson - The entry's params as JSON string, as the file held them\n * @param blockIdsJson - template-local entry id → assigned block id, as a JSON object\n * @returns Either an error, or the initial storage as JSON string\n */\n [BlockStorageFacadeCallbacks.StorageInitialFromParams]: (\n paramsJson: StringifiedJson,\n blockIdsJson: StringifiedJson,\n ) => { error: string } | { error?: undefined; storageJson: StringifiedJson };\n\n /**\n * Check params against this block's kind, creating nothing.\n *\n * Called once per entry before a template is applied, so params a kind rejects are\n * reported against the entry that carries them while there is still no project — the\n * same reason references and ids are checked before construction starts. Applying\n * without this call is safe but worse: `StorageInitialFromParams` runs the same check\n * and refuses, by which point earlier entries have already been created.\n *\n * A pass carries nothing back but its own absence of error: every kind declares a\n * parser, so a pass means the params were checked against the contract, not merely\n * that they were valid JSON.\n *\n * Reference ids inside the params may be placeholders at this point: the check runs\n * before blocks exist, so what is verified is the shape of the params, not what they\n * point at.\n *\n * @param paramsJson The entry's params as JSON string\n * @returns Why the params were rejected, or nothing\n */\n [BlockStorageFacadeCallbacks.InitializationParamsValidate]: (\n paramsJson: StringifiedJson,\n ) => { error: string } | { error?: undefined };\n}\n\n/** Register all facade callbacks at once. Ensures all required callbacks are provided. */\nexport function registerFacadeCallbacks(callbacks: BlockStorageFacade): void {\n for (const key of Object.values(BlockStorageFacadeCallbacks)) {\n tryRegisterCallback(key, callbacks[key] as (...args: any[]) => any);\n }\n}\n"],"mappings":";;;;;;AA8DA,MAAa,+BAA+B;;;;;;;;;;AAe5C,MAAa,8BAA8B;CACzC,oBAAoB;CACpB,kBAAkB;CAClB,gBAAgB;CAChB,YAAY;CACZ,kBAAkB;CAClB,gBAAgB;CAChB,4BAA4B;CAC5B,0BAA0B;CAC1B,8BAA8B;AAChC;;;;;AAMA,SAAS,oBACP,WAC2C;CAC3C,OAAO,OAAO,YACZ,OAAO,OAAO,SAAS,CAAC,CAAC,KAAK,WAAW,CAAC,QAAQ,mBAAmB,EAAE,OAAO,CAAC,CAAC,CAAC,CACnF;AACF;;;;;AAMA,MAAa,4BAA4B,oBAAoB,2BAA2B;;AAwNxF,SAAgB,wBAAwB,WAAqC;CAC3E,KAAK,MAAM,OAAO,OAAO,OAAO,2BAA2B,GACzD,oBAAoB,KAAK,UAAU,IAA+B;AAEtE"}
|
|
@@ -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(),
|
|
87
|
+
return this.cachedColumns = Array.from(this.entries.values(), require_data_column.DataColumn.fromAccessor).filter((column) => column !== void 0);
|
|
88
88
|
}
|
|
89
89
|
};
|
|
90
90
|
/**
|
|
@@ -106,17 +106,9 @@ 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(),
|
|
109
|
+
return this.cachedColumns = Array.from(this.getPObjectEntries().values(), require_data_column.DataColumn.fromAccessor).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
|
-
}
|
|
120
112
|
function hashRawPool(rawPool) {
|
|
121
113
|
return rawPool.map((b) => `${b.blockId}\x1f${b.prodCtx ?? ""}\x1f${b.stagingCtx ?? ""}\x1f${b.prodIncomplete ? 1 : 0}\x1f${b.stagingIncomplete ? 1 : 0}`).join("");
|
|
122
114
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"providers.cjs","names":["isNil","TreeNodeAccessor","LRUCache","getCfgRenderCtx","DataColumn","AccessorEntriesProvider","ResultPoolEntriesProvider"
|
|
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(), DataColumn.fromAccessor).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 DataColumn.fromAccessor,\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 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;C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K,gBAAgB,MAAM,KAAK,KAAK,QAAQ,OAAO,GAAGD,oBAAAA,WAAW,YAAY,CAAC,CAAC,QACrF,WAAW,WAAW,KAAA,CACzB;CACF;AACF;;;;;;AAUA,IAAa,gCAAb,cACUE,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,KACjC,KAAK,kBAAkB,CAAC,CAAC,OAAO,GAChCG,oBAAAA,WAAW,YACb,CAAC,CAAC,QAAQ,WAAW,WAAW,KAAA,CAAS;CAC3C;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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"providers.d.ts","names":[],"sources":["../../../src/columns/column_providers/providers.ts"],"mappings":";;;;;;;;;;;;;
|
|
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;;;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 {
|
|
4
|
+
import { 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(),
|
|
87
|
+
return this.cachedColumns = Array.from(this.entries.values(), DataColumn.fromAccessor).filter((column) => column !== void 0);
|
|
88
88
|
}
|
|
89
89
|
};
|
|
90
90
|
/**
|
|
@@ -106,17 +106,9 @@ 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(),
|
|
109
|
+
return this.cachedColumns = Array.from(this.getPObjectEntries().values(), DataColumn.fromAccessor).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
|
-
}
|
|
120
112
|
function hashRawPool(rawPool) {
|
|
121
113
|
return rawPool.map((b) => `${b.blockId}\x1f${b.prodCtx ?? ""}\x1f${b.stagingCtx ?? ""}\x1f${b.prodIncomplete ? 1 : 0}\x1f${b.stagingIncomplete ? 1 : 0}`).join("");
|
|
122
114
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"providers.js","names":[],"sources":["../../../src/columns/column_providers/providers.ts"],"sourcesContent":["import {\n AccessorEntriesProvider,\n ResultPoolEntriesProvider,\n type
|
|
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(), DataColumn.fromAccessor).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 DataColumn.fromAccessor,\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 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,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B,EAAE,SAAS,CAAC,EAAE,SAAS,SAAS,CAAC,IACtD,KAAA;GACN,YACE,EAAE,eAAe,KAAA,IACb,IAAI,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,KACjC,KAAK,kBAAkB,CAAC,CAAC,OAAO,GAChC,WAAW,YACb,CAAC,CAAC,QAAQ,WAAW,WAAW,KAAA,CAAS;CAC3C;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"}
|
|
@@ -41,8 +41,8 @@ function ColumnRecipeBuild(id, opts = {}) {
|
|
|
41
41
|
* Resolution status counterpart to {@link ColumnRecipeBuild}. Dispatches on
|
|
42
42
|
* the parsed id shape to the matching `getStatusBy*` static — never
|
|
43
43
|
* constructs the recipe. Use this at boundaries (resolver, filter/sort
|
|
44
|
-
* targets) to
|
|
45
|
-
*
|
|
44
|
+
* targets) to tell an `absent` column from a `resolving` one: the recipe
|
|
45
|
+
* factory returns `undefined` for both.
|
|
46
46
|
*/
|
|
47
47
|
function ColumnRecipeGetStatus(id, opts = {}) {
|
|
48
48
|
const parsed = (0, _milaboratories_pl_model_common.parseColumnIdSafely)(id);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["parseColumnIdSafely","isPObjectKey","DataColumn","isColumnDiscoveredKey","ColumnDiscoveredRecipe","isColumnOverriddenKey","ColumnOverriddenRecipe","isColumnFilteredKey","ColumnFilteredRecipe"],"sources":["../../../src/columns/column_recipes/index.ts"],"sourcesContent":["import {\n isColumnDiscoveredKey,\n isColumnOverriddenKey,\n parseColumnIdSafely,\n type ColumnUniversalId,\n type PObjectId,\n isPObjectKey,\n isColumnFilteredKey,\n} from \"@milaboratories/pl-model-common\";\nimport type { GlobalCfgRenderCtx } from \"../../render/internal\";\nimport { DataColumn } from \"../data_column\";\nimport { ColumnDiscoveredRecipe } from \"./column_discovered_recipe\";\nimport { ColumnFilteredRecipe } from \"./column_filtered_recipe\";\nimport { ColumnOverriddenRecipe } from \"./column_overrided_recipe\";\nimport type {\n ColumnRecipe as ColumnRecipeBase,\n ColumnRecipeId,\n ColumnResolutionStatus,\n} from \"./types\";\n\nexport type { ColumnFieldStatus, ColumnRecipeId, ColumnResolutionStatus, SpecQuery } from \"./types\";\nexport {
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["parseColumnIdSafely","isPObjectKey","DataColumn","isColumnDiscoveredKey","ColumnDiscoveredRecipe","isColumnOverriddenKey","ColumnOverriddenRecipe","isColumnFilteredKey","ColumnFilteredRecipe"],"sources":["../../../src/columns/column_recipes/index.ts"],"sourcesContent":["import {\n isColumnDiscoveredKey,\n isColumnOverriddenKey,\n parseColumnIdSafely,\n type ColumnUniversalId,\n type PObjectId,\n isPObjectKey,\n isColumnFilteredKey,\n} from \"@milaboratories/pl-model-common\";\nimport type { GlobalCfgRenderCtx } from \"../../render/internal\";\nimport { DataColumn } from \"../data_column\";\nimport { ColumnDiscoveredRecipe } from \"./column_discovered_recipe\";\nimport { ColumnFilteredRecipe } from \"./column_filtered_recipe\";\nimport { ColumnOverriddenRecipe } from \"./column_overrided_recipe\";\nimport type {\n ColumnRecipe as ColumnRecipeBase,\n ColumnRecipeId,\n ColumnResolutionStatus,\n} from \"./types\";\n\nexport type { ColumnFieldStatus, ColumnRecipeId, ColumnResolutionStatus, SpecQuery } from \"./types\";\nexport { ColumnDiscoveredRecipe } from \"./column_discovered_recipe\";\nexport { ColumnFilteredRecipe } from \"./column_filtered_recipe\";\nexport { ColumnOverriddenRecipe } from \"./column_overrided_recipe\";\n\n// Re-declare the interface locally so the name can merge with the dispatcher\n// value declared below: a single name `ColumnRecipe` resolves to the\n// interface in type position and to the factory function (`Object.assign`d\n// with `.getStatus`) in value position.\n// (Type-only re-exports do not participate in TS declaration merging.)\nexport interface ColumnRecipe<\n ID extends ColumnRecipeId = ColumnRecipeId,\n> extends ColumnRecipeBase<ID> {}\n\n/**\n * Build a `ColumnRecipe` from a stringified id. Dispatches to the matching\n * concrete recipe variant based on the id's encoding and recurses on\n * wrappers' inner `source`:\n *\n * - bare {@link PObjectId} (non-JSON) → `DataColumnRecipe.fromId`\n * - `ColumnDiscoveredKey` → {@link ColumnDiscoveredRecipe}\n * - `ColumnOverriddenKey { source, specOverrides }` → recurse on `source`,\n * then {@link ColumnOverriddenRecipe.wrap}\n * - `ColumnFilteredKey { source, axisFilters }` → recurse on `source`,\n * then {@link ColumnFilteredRecipe.wrap}\n *\n * Returns `undefined` for unsupported variants (e.g. AnchoredPColumnId,\n * which needs an anchor map to resolve) or when a nested source itself\n * cannot be built.\n */\nfunction ColumnRecipeBuild(\n id: ColumnUniversalId,\n opts: { ctx?: GlobalCfgRenderCtx } = {},\n): undefined | ColumnRecipe {\n const parsed = parseColumnIdSafely(id);\n\n if (isPObjectKey(parsed)) {\n return DataColumn.fromId(id as PObjectId, opts);\n }\n\n if (isColumnDiscoveredKey(parsed)) {\n return ColumnDiscoveredRecipe.fromKey(parsed, opts);\n }\n\n if (isColumnOverriddenKey(parsed)) {\n const inner = ColumnRecipe(parsed.source, opts);\n if (inner === undefined) return undefined;\n return ColumnOverriddenRecipe.wrap(inner, parsed.specOverrides);\n }\n\n if (isColumnFilteredKey(parsed)) {\n // ColumnFilteredKey.source is a stringified ColumnUniversalId (leaf or\n // any nested wrapper). Legacy `FilteredPColumnId` with an AnchoredPColumnId\n // (object) source is not supported here — guard against it explicitly.\n if (typeof parsed.source !== \"string\") {\n throw new Error(\n `Unsupported ColumnRecipe id variant: filtered column with non-string source (${JSON.stringify(parsed.source)})`,\n );\n }\n const inner = ColumnRecipe(parsed.source, opts);\n if (inner === undefined) return undefined;\n return ColumnFilteredRecipe.wrap(inner, parsed.axisFilters);\n }\n\n throw new Error(`Unsupported ColumnRecipe id variant: ${id}`);\n}\n\n/**\n * Resolution status counterpart to {@link ColumnRecipeBuild}. Dispatches on\n * the parsed id shape to the matching `getStatusBy*` static — never\n * constructs the recipe. Use this at boundaries (resolver, filter/sort\n * targets) to tell an `absent` column from a `resolving` one: the recipe\n * factory returns `undefined` for both.\n */\nfunction ColumnRecipeGetStatus(\n id: ColumnUniversalId,\n opts: { ctx?: GlobalCfgRenderCtx } = {},\n): ColumnResolutionStatus {\n const parsed = parseColumnIdSafely(id);\n if (isPObjectKey(parsed)) return DataColumn.getStatusById(id as PObjectId, opts);\n if (isColumnDiscoveredKey(parsed)) return ColumnDiscoveredRecipe.getStatusByKey(parsed, opts);\n if (isColumnOverriddenKey(parsed)) return ColumnOverriddenRecipe.getStatusByKey(parsed, opts);\n if (isColumnFilteredKey(parsed)) return ColumnFilteredRecipe.getStatusByKey(parsed, opts);\n throw new Error(`Unsupported ColumnRecipe id variant: ${id}`);\n}\n\nexport const ColumnRecipe: typeof ColumnRecipeBuild & {\n readonly getStatus: typeof ColumnRecipeGetStatus;\n} = Object.assign(ColumnRecipeBuild, {\n getStatus: ColumnRecipeGetStatus,\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAkDA,SAAS,kBACP,IACA,OAAqC,CAAC,GACZ;CAC1B,MAAM,UAAA,GAASA,gCAAAA,oBAAAA,CAAoB,EAAE;CAErC,KAAA,GAAIC,gCAAAA,aAAAA,CAAa,MAAM,GACrB,OAAOC,oBAAAA,WAAW,OAAO,IAAiB,IAAI;CAGhD,KAAA,GAAIC,gCAAAA,sBAAAA,CAAsB,MAAM,GAC9B,OAAOC,iCAAAA,uBAAuB,QAAQ,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"../../render/internal.js";
|
|
2
2
|
import { ColumnFieldStatus, ColumnRecipe as ColumnRecipe$1, ColumnRecipeId, ColumnResolutionStatus, SpecQuery as SpecQuery$1 } from "./types.js";
|
|
3
|
-
import { ColumnAbsentError } from "../data_column.js";
|
|
4
3
|
import { ColumnDiscoveredRecipe } from "./column_discovered_recipe.js";
|
|
5
4
|
import { ColumnFilteredRecipe } from "./column_filtered_recipe.js";
|
|
6
5
|
import { ColumnOverriddenRecipe } from "./column_overrided_recipe.js";
|
|
@@ -29,8 +28,8 @@ declare function ColumnRecipeBuild(id: ColumnUniversalId, opts?: {
|
|
|
29
28
|
* Resolution status counterpart to {@link ColumnRecipeBuild}. Dispatches on
|
|
30
29
|
* the parsed id shape to the matching `getStatusBy*` static — never
|
|
31
30
|
* constructs the recipe. Use this at boundaries (resolver, filter/sort
|
|
32
|
-
* targets) to
|
|
33
|
-
*
|
|
31
|
+
* targets) to tell an `absent` column from a `resolving` one: the recipe
|
|
32
|
+
* factory returns `undefined` for both.
|
|
34
33
|
*/
|
|
35
34
|
declare function ColumnRecipeGetStatus(id: ColumnUniversalId, opts?: {
|
|
36
35
|
ctx?: GlobalCfgRenderCtx;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":["ColumnRecipeBase"],"sources":["../../../src/columns/column_recipes/index.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":["ColumnRecipeBase"],"sources":["../../../src/columns/column_recipes/index.ts"],"mappings":";;;;;;iBA8BiB,aACf,WAAW,iBAAiB,wBACpBA,eAAiB;;;;;;;;;;;;;;;;;iBAkBlB,kBACP,IAAI,mBACJ;EAAQ,MAAM;gBACD;;;;;;;;iBAyCN,sBACP,IAAI,mBACJ;EAAQ,MAAM;IACb;qBASU,qBAAqB;WACvB,kBAAkB"}
|
|
@@ -41,8 +41,8 @@ function ColumnRecipeBuild(id, opts = {}) {
|
|
|
41
41
|
* Resolution status counterpart to {@link ColumnRecipeBuild}. Dispatches on
|
|
42
42
|
* the parsed id shape to the matching `getStatusBy*` static — never
|
|
43
43
|
* constructs the recipe. Use this at boundaries (resolver, filter/sort
|
|
44
|
-
* targets) to
|
|
45
|
-
*
|
|
44
|
+
* targets) to tell an `absent` column from a `resolving` one: the recipe
|
|
45
|
+
* factory returns `undefined` for both.
|
|
46
46
|
*/
|
|
47
47
|
function ColumnRecipeGetStatus(id, opts = {}) {
|
|
48
48
|
const parsed = parseColumnIdSafely(id);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../src/columns/column_recipes/index.ts"],"sourcesContent":["import {\n isColumnDiscoveredKey,\n isColumnOverriddenKey,\n parseColumnIdSafely,\n type ColumnUniversalId,\n type PObjectId,\n isPObjectKey,\n isColumnFilteredKey,\n} from \"@milaboratories/pl-model-common\";\nimport type { GlobalCfgRenderCtx } from \"../../render/internal\";\nimport { DataColumn } from \"../data_column\";\nimport { ColumnDiscoveredRecipe } from \"./column_discovered_recipe\";\nimport { ColumnFilteredRecipe } from \"./column_filtered_recipe\";\nimport { ColumnOverriddenRecipe } from \"./column_overrided_recipe\";\nimport type {\n ColumnRecipe as ColumnRecipeBase,\n ColumnRecipeId,\n ColumnResolutionStatus,\n} from \"./types\";\n\nexport type { ColumnFieldStatus, ColumnRecipeId, ColumnResolutionStatus, SpecQuery } from \"./types\";\nexport {
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/columns/column_recipes/index.ts"],"sourcesContent":["import {\n isColumnDiscoveredKey,\n isColumnOverriddenKey,\n parseColumnIdSafely,\n type ColumnUniversalId,\n type PObjectId,\n isPObjectKey,\n isColumnFilteredKey,\n} from \"@milaboratories/pl-model-common\";\nimport type { GlobalCfgRenderCtx } from \"../../render/internal\";\nimport { DataColumn } from \"../data_column\";\nimport { ColumnDiscoveredRecipe } from \"./column_discovered_recipe\";\nimport { ColumnFilteredRecipe } from \"./column_filtered_recipe\";\nimport { ColumnOverriddenRecipe } from \"./column_overrided_recipe\";\nimport type {\n ColumnRecipe as ColumnRecipeBase,\n ColumnRecipeId,\n ColumnResolutionStatus,\n} from \"./types\";\n\nexport type { ColumnFieldStatus, ColumnRecipeId, ColumnResolutionStatus, SpecQuery } from \"./types\";\nexport { ColumnDiscoveredRecipe } from \"./column_discovered_recipe\";\nexport { ColumnFilteredRecipe } from \"./column_filtered_recipe\";\nexport { ColumnOverriddenRecipe } from \"./column_overrided_recipe\";\n\n// Re-declare the interface locally so the name can merge with the dispatcher\n// value declared below: a single name `ColumnRecipe` resolves to the\n// interface in type position and to the factory function (`Object.assign`d\n// with `.getStatus`) in value position.\n// (Type-only re-exports do not participate in TS declaration merging.)\nexport interface ColumnRecipe<\n ID extends ColumnRecipeId = ColumnRecipeId,\n> extends ColumnRecipeBase<ID> {}\n\n/**\n * Build a `ColumnRecipe` from a stringified id. Dispatches to the matching\n * concrete recipe variant based on the id's encoding and recurses on\n * wrappers' inner `source`:\n *\n * - bare {@link PObjectId} (non-JSON) → `DataColumnRecipe.fromId`\n * - `ColumnDiscoveredKey` → {@link ColumnDiscoveredRecipe}\n * - `ColumnOverriddenKey { source, specOverrides }` → recurse on `source`,\n * then {@link ColumnOverriddenRecipe.wrap}\n * - `ColumnFilteredKey { source, axisFilters }` → recurse on `source`,\n * then {@link ColumnFilteredRecipe.wrap}\n *\n * Returns `undefined` for unsupported variants (e.g. AnchoredPColumnId,\n * which needs an anchor map to resolve) or when a nested source itself\n * cannot be built.\n */\nfunction ColumnRecipeBuild(\n id: ColumnUniversalId,\n opts: { ctx?: GlobalCfgRenderCtx } = {},\n): undefined | ColumnRecipe {\n const parsed = parseColumnIdSafely(id);\n\n if (isPObjectKey(parsed)) {\n return DataColumn.fromId(id as PObjectId, opts);\n }\n\n if (isColumnDiscoveredKey(parsed)) {\n return ColumnDiscoveredRecipe.fromKey(parsed, opts);\n }\n\n if (isColumnOverriddenKey(parsed)) {\n const inner = ColumnRecipe(parsed.source, opts);\n if (inner === undefined) return undefined;\n return ColumnOverriddenRecipe.wrap(inner, parsed.specOverrides);\n }\n\n if (isColumnFilteredKey(parsed)) {\n // ColumnFilteredKey.source is a stringified ColumnUniversalId (leaf or\n // any nested wrapper). Legacy `FilteredPColumnId` with an AnchoredPColumnId\n // (object) source is not supported here — guard against it explicitly.\n if (typeof parsed.source !== \"string\") {\n throw new Error(\n `Unsupported ColumnRecipe id variant: filtered column with non-string source (${JSON.stringify(parsed.source)})`,\n );\n }\n const inner = ColumnRecipe(parsed.source, opts);\n if (inner === undefined) return undefined;\n return ColumnFilteredRecipe.wrap(inner, parsed.axisFilters);\n }\n\n throw new Error(`Unsupported ColumnRecipe id variant: ${id}`);\n}\n\n/**\n * Resolution status counterpart to {@link ColumnRecipeBuild}. Dispatches on\n * the parsed id shape to the matching `getStatusBy*` static — never\n * constructs the recipe. Use this at boundaries (resolver, filter/sort\n * targets) to tell an `absent` column from a `resolving` one: the recipe\n * factory returns `undefined` for both.\n */\nfunction ColumnRecipeGetStatus(\n id: ColumnUniversalId,\n opts: { ctx?: GlobalCfgRenderCtx } = {},\n): ColumnResolutionStatus {\n const parsed = parseColumnIdSafely(id);\n if (isPObjectKey(parsed)) return DataColumn.getStatusById(id as PObjectId, opts);\n if (isColumnDiscoveredKey(parsed)) return ColumnDiscoveredRecipe.getStatusByKey(parsed, opts);\n if (isColumnOverriddenKey(parsed)) return ColumnOverriddenRecipe.getStatusByKey(parsed, opts);\n if (isColumnFilteredKey(parsed)) return ColumnFilteredRecipe.getStatusByKey(parsed, opts);\n throw new Error(`Unsupported ColumnRecipe id variant: ${id}`);\n}\n\nexport const ColumnRecipe: typeof ColumnRecipeBuild & {\n readonly getStatus: typeof ColumnRecipeGetStatus;\n} = Object.assign(ColumnRecipeBuild, {\n getStatus: ColumnRecipeGetStatus,\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAkDA,SAAS,kBACP,IACA,OAAqC,CAAC,GACZ;CAC1B,MAAM,SAAS,oBAAoB,EAAE;CAErC,IAAI,aAAa,MAAM,GACrB,OAAO,WAAW,OAAO,IAAiB,IAAI;CAGhD,IAAI,sBAAsB,MAAM,GAC9B,OAAO,uBAAuB,QAAQ,QAAQ,IAAI;CAGpD,IAAI,sBAAsB,MAAM,GAAG;EACjC,MAAM,QAAQ,aAAa,OAAO,QAAQ,IAAI;EAC9C,IAAI,UAAU,KAAA,GAAW,OAAO,KAAA;EAChC,OAAO,uBAAuB,KAAK,OAAO,OAAO,aAAa;CAChE;CAEA,IAAI,oBAAoB,MAAM,GAAG;EAI/B,IAAI,OAAO,OAAO,WAAW,UAC3B,MAAM,IAAI,MACR,gFAAgF,KAAK,UAAU,OAAO,MAAM,EAAE,EAChH;EAEF,MAAM,QAAQ,aAAa,OAAO,QAAQ,IAAI;EAC9C,IAAI,UAAU,KAAA,GAAW,OAAO,KAAA;EAChC,OAAO,qBAAqB,KAAK,OAAO,OAAO,WAAW;CAC5D;CAEA,MAAM,IAAI,MAAM,wCAAwC,IAAI;AAC9D;;;;;;;;AASA,SAAS,sBACP,IACA,OAAqC,CAAC,GACd;CACxB,MAAM,SAAS,oBAAoB,EAAE;CACrC,IAAI,aAAa,MAAM,GAAG,OAAO,WAAW,cAAc,IAAiB,IAAI;CAC/E,IAAI,sBAAsB,MAAM,GAAG,OAAO,uBAAuB,eAAe,QAAQ,IAAI;CAC5F,IAAI,sBAAsB,MAAM,GAAG,OAAO,uBAAuB,eAAe,QAAQ,IAAI;CAC5F,IAAI,oBAAoB,MAAM,GAAG,OAAO,qBAAqB,eAAe,QAAQ,IAAI;CACxF,MAAM,IAAI,MAAM,wCAAwC,IAAI;AAC9D;AAEA,MAAa,eAET,OAAO,OAAO,mBAAmB,EACnC,WAAW,sBACb,CAAC"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
const require_internal = require("../internal.cjs");
|
|
2
|
+
const require_api = require("../render/api.cjs");
|
|
3
|
+
const require_index = require("./column_recipes/index.cjs");
|
|
4
|
+
let _milaboratories_pl_model_common = require("@milaboratories/pl-model-common");
|
|
5
|
+
// src/columns/column_values.ts
|
|
6
|
+
/**
|
|
7
|
+
* The model of a value picker over the values of `valueColumn`, for a model output; the UI reads
|
|
8
|
+
* the options through it (`usePlColumnValueOptions`, `PlColumnValueDropdown`). Each option is a
|
|
9
|
+
* value of `valueColumn`, labelled by the value of `labelColumn` in the same row, or by the value
|
|
10
|
+
* itself when no label column is given.
|
|
11
|
+
*
|
|
12
|
+
* `absent` once the value column is gone: a stored id may name a column its upstream block no
|
|
13
|
+
* longer produces. A label column that is gone leaves the values to label themselves; one that is
|
|
14
|
+
* still resolving keeps the model resolving.
|
|
15
|
+
*/
|
|
16
|
+
function createColumnValueOptions(columns, deps) {
|
|
17
|
+
const ctx = deps?.ctx ?? require_internal.getCfgRenderCtx();
|
|
18
|
+
const value = frameEntryOf(columns.valueColumn, ctx);
|
|
19
|
+
const valueColumn = value.id;
|
|
20
|
+
if (value.status !== "present") return {
|
|
21
|
+
type: value.status,
|
|
22
|
+
valueColumn
|
|
23
|
+
};
|
|
24
|
+
const label = columns.labelColumn === void 0 ? void 0 : frameEntryOf(columns.labelColumn, ctx);
|
|
25
|
+
if (label?.status === "resolving") return {
|
|
26
|
+
type: "resolving",
|
|
27
|
+
valueColumn
|
|
28
|
+
};
|
|
29
|
+
const labelled = label?.status === "present" && label.frameId !== value.frameId ? label : void 0;
|
|
30
|
+
return {
|
|
31
|
+
type: "present",
|
|
32
|
+
valueColumn,
|
|
33
|
+
frame: ctx.createPFrame(labelled === void 0 ? [value.def] : [value.def, labelled.def]),
|
|
34
|
+
frameColumns: {
|
|
35
|
+
value: value.frameId,
|
|
36
|
+
label: labelled?.frameId ?? null
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Distinct `values` of `column` as options, each a column value id naming the column, labelled
|
|
42
|
+
* by the value itself and ordered naturally by label ("R2" before "R10"). Empty values are not
|
|
43
|
+
* offered.
|
|
44
|
+
*/
|
|
45
|
+
function deriveColumnValueOptions(column, values) {
|
|
46
|
+
return deriveLabelledColumnValueOptions(column, values.map((value) => ({
|
|
47
|
+
value,
|
|
48
|
+
label: value
|
|
49
|
+
})));
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Distinct values of `column` among `rows` as options, each a column value id naming the column,
|
|
53
|
+
* labelled by the label of the first row holding the value, and ordered naturally by label ("R2"
|
|
54
|
+
* before "R10"). Empty values are not offered; a value whose label is empty labels itself.
|
|
55
|
+
*/
|
|
56
|
+
function deriveLabelledColumnValueOptions(column, rows) {
|
|
57
|
+
const options = /* @__PURE__ */ new Map();
|
|
58
|
+
for (const { value, label } of rows) {
|
|
59
|
+
if (value === "" || options.has(value)) continue;
|
|
60
|
+
options.set(value, {
|
|
61
|
+
value: (0, _milaboratories_pl_model_common.createColumnValueId)({
|
|
62
|
+
column,
|
|
63
|
+
value
|
|
64
|
+
}),
|
|
65
|
+
label: label === "" ? value : label
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
return [...options.values()].sort((a, b) => compareNatural(a.label, b.label));
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* A column given by id or by a recipe goes into the frame by its id, which the frame holds as the
|
|
72
|
+
* bare id of its leaf; a materialised column goes in as it is.
|
|
73
|
+
*/
|
|
74
|
+
function frameEntryOf(column, ctx) {
|
|
75
|
+
if (typeof column === "string") return {
|
|
76
|
+
id: column,
|
|
77
|
+
status: require_index.ColumnRecipe.getStatus(column, { ctx }),
|
|
78
|
+
frameId: (0, _milaboratories_pl_model_common.extractPObjectId)(column),
|
|
79
|
+
def: column
|
|
80
|
+
};
|
|
81
|
+
if ((0, _milaboratories_pl_model_common.isPColumn)(column)) return {
|
|
82
|
+
id: column.id,
|
|
83
|
+
status: "present",
|
|
84
|
+
frameId: column.id,
|
|
85
|
+
def: require_api.finalizePColumnData(column)
|
|
86
|
+
};
|
|
87
|
+
return {
|
|
88
|
+
id: column.id,
|
|
89
|
+
status: column.getDataStatus(),
|
|
90
|
+
frameId: (0, _milaboratories_pl_model_common.extractPObjectId)(column.id),
|
|
91
|
+
def: column.id
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
const CHUNKS = /\d+|\D+/g;
|
|
95
|
+
/**
|
|
96
|
+
* Natural order: runs of digits compare as numbers, other text case-insensitively, so "R2"
|
|
97
|
+
* comes before "R10". The model runtime has no `Intl`.
|
|
98
|
+
*/
|
|
99
|
+
function compareNatural(a, b) {
|
|
100
|
+
const chunksA = a.match(CHUNKS) ?? [];
|
|
101
|
+
const chunksB = b.match(CHUNKS) ?? [];
|
|
102
|
+
for (let i = 0; i < Math.min(chunksA.length, chunksB.length); i++) {
|
|
103
|
+
const order = compareChunks(chunksA[i], chunksB[i]);
|
|
104
|
+
if (order !== 0) return order;
|
|
105
|
+
}
|
|
106
|
+
return chunksA.length - chunksB.length || compareStrings(a, b);
|
|
107
|
+
}
|
|
108
|
+
function compareChunks(a, b) {
|
|
109
|
+
if (isDigits(a) && isDigits(b)) {
|
|
110
|
+
const numberA = a.replace(/^0+(?=\d)/, "");
|
|
111
|
+
const numberB = b.replace(/^0+(?=\d)/, "");
|
|
112
|
+
return numberA.length - numberB.length || compareStrings(numberA, numberB);
|
|
113
|
+
}
|
|
114
|
+
return compareStrings(a.toLowerCase(), b.toLowerCase());
|
|
115
|
+
}
|
|
116
|
+
function isDigits(chunk) {
|
|
117
|
+
return chunk.charCodeAt(0) >= 48 && chunk.charCodeAt(0) <= 57;
|
|
118
|
+
}
|
|
119
|
+
function compareStrings(a, b) {
|
|
120
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
121
|
+
}
|
|
122
|
+
exports.createColumnValueOptions = createColumnValueOptions;
|
|
123
|
+
exports.deriveColumnValueOptions = deriveColumnValueOptions;
|
|
124
|
+
exports.deriveLabelledColumnValueOptions = deriveLabelledColumnValueOptions;
|
|
125
|
+
|
|
126
|
+
//# sourceMappingURL=column_values.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"column_values.cjs","names":["getCfgRenderCtx","createColumnValueId","ColumnRecipe","extractPObjectId","isPColumn","finalizePColumnData"],"sources":["../../src/columns/column_values.ts"],"sourcesContent":["import {\n createColumnValueId,\n extractPObjectId,\n isPColumn,\n type ColumnUniversalId,\n type ColumnValueId,\n type PColumn,\n type PFrameHandle,\n type PObjectId,\n} from \"@milaboratories/pl-model-common\";\nimport { finalizePColumnData } from \"../render/api\";\nimport type { GlobalCfgRenderCtx, PColumnDataUniversal } from \"../render/internal\";\nimport { getCfgRenderCtx } from \"../internal\";\nimport { ColumnRecipe } from \"./column_recipes\";\nimport type { ColumnResolutionStatus } from \"./column_recipes/types\";\nimport type { DataColumnRecipe } from \"./data_column\";\n\n/** Drop-down option for a value of a column — column-value-id valued. */\nexport type ColumnValueOption = {\n readonly value: ColumnValueId;\n readonly label: string;\n};\n\n/** A column a value picker offers the values of, or labels them by. */\nexport type ColumnValueOptionsColumn =\n | ColumnUniversalId\n | PColumn<undefined | PColumnDataUniversal>\n | DataColumnRecipe\n | ColumnRecipe;\n\n/**\n * What a UI reads the options of a value picker from: a frame holding the value column, and the\n * label column while there is one, as long as the value column is there. `valueColumn` is the\n * column the options are values of, so the UI can tell a model that still describes an earlier\n * pick. `frameColumns` names both columns as the frame holds them.\n */\nexport type ColumnValueOptionsModel =\n | { readonly type: \"resolving\"; readonly valueColumn: ColumnUniversalId }\n | { readonly type: \"absent\"; readonly valueColumn: ColumnUniversalId }\n | {\n readonly type: \"present\";\n readonly valueColumn: ColumnUniversalId;\n readonly frame: PFrameHandle;\n readonly frameColumns: {\n readonly value: PObjectId;\n /** `null` when the values label themselves. */\n readonly label: PObjectId | null;\n };\n };\n\n/**\n * The model of a value picker over the values of `valueColumn`, for a model output; the UI reads\n * the options through it (`usePlColumnValueOptions`, `PlColumnValueDropdown`). Each option is a\n * value of `valueColumn`, labelled by the value of `labelColumn` in the same row, or by the value\n * itself when no label column is given.\n *\n * `absent` once the value column is gone: a stored id may name a column its upstream block no\n * longer produces. A label column that is gone leaves the values to label themselves; one that is\n * still resolving keeps the model resolving.\n */\nexport function createColumnValueOptions(\n columns: {\n readonly valueColumn: ColumnValueOptionsColumn;\n readonly labelColumn?: ColumnValueOptionsColumn;\n },\n deps?: { readonly ctx?: GlobalCfgRenderCtx },\n): ColumnValueOptionsModel {\n const ctx = deps?.ctx ?? getCfgRenderCtx();\n const value = frameEntryOf(columns.valueColumn, ctx);\n const valueColumn = value.id;\n if (value.status !== \"present\") return { type: value.status, valueColumn };\n\n const label =\n columns.labelColumn === undefined ? undefined : frameEntryOf(columns.labelColumn, ctx);\n if (label?.status === \"resolving\") return { type: \"resolving\", valueColumn };\n const labelled =\n label?.status === \"present\" && label.frameId !== value.frameId ? label : undefined;\n\n const frame = ctx.createPFrame(labelled === undefined ? [value.def] : [value.def, labelled.def]);\n return {\n type: \"present\",\n valueColumn,\n frame,\n frameColumns: { value: value.frameId, label: labelled?.frameId ?? null },\n };\n}\n\n/**\n * Distinct `values` of `column` as options, each a column value id naming the column, labelled\n * by the value itself and ordered naturally by label (\"R2\" before \"R10\"). Empty values are not\n * offered.\n */\nexport function deriveColumnValueOptions(\n column: ColumnUniversalId,\n values: readonly string[],\n): ColumnValueOption[] {\n return deriveLabelledColumnValueOptions(\n column,\n values.map((value) => ({ value, label: value })),\n );\n}\n\n/**\n * Distinct values of `column` among `rows` as options, each a column value id naming the column,\n * labelled by the label of the first row holding the value, and ordered naturally by label (\"R2\"\n * before \"R10\"). Empty values are not offered; a value whose label is empty labels itself.\n */\nexport function deriveLabelledColumnValueOptions(\n column: ColumnUniversalId,\n rows: readonly { readonly value: string; readonly label: string }[],\n): ColumnValueOption[] {\n const options = new Map<string, ColumnValueOption>();\n for (const { value, label } of rows) {\n if (value === \"\" || options.has(value)) continue;\n options.set(value, {\n value: createColumnValueId({ column, value }),\n label: label === \"\" ? value : label,\n });\n }\n return [...options.values()].sort((a, b) => compareNatural(a.label, b.label));\n}\n\n// Internals\n\n/** A column as a frame is made of it: its id, its status, and what the frame is created from. */\ntype FrameEntry = {\n readonly id: ColumnUniversalId;\n readonly status: ColumnResolutionStatus;\n readonly frameId: PObjectId;\n readonly def: Parameters<GlobalCfgRenderCtx[\"createPFrame\"]>[0][number];\n};\n\n/**\n * A column given by id or by a recipe goes into the frame by its id, which the frame holds as the\n * bare id of its leaf; a materialised column goes in as it is.\n */\nfunction frameEntryOf(column: ColumnValueOptionsColumn, ctx: GlobalCfgRenderCtx): FrameEntry {\n if (typeof column === \"string\") {\n return {\n id: column,\n status: ColumnRecipe.getStatus(column, { ctx }),\n frameId: extractPObjectId(column),\n def: column,\n };\n }\n if (isPColumn<undefined | PColumnDataUniversal>(column)) {\n return {\n id: column.id,\n status: \"present\",\n frameId: column.id,\n def: finalizePColumnData(column),\n };\n }\n return {\n id: column.id,\n status: column.getDataStatus(),\n frameId: extractPObjectId(column.id),\n def: column.id,\n };\n}\n\nconst CHUNKS = /\\d+|\\D+/g;\n\n/**\n * Natural order: runs of digits compare as numbers, other text case-insensitively, so \"R2\"\n * comes before \"R10\". The model runtime has no `Intl`.\n */\nfunction compareNatural(a: string, b: string): number {\n const chunksA = a.match(CHUNKS) ?? [];\n const chunksB = b.match(CHUNKS) ?? [];\n for (let i = 0; i < Math.min(chunksA.length, chunksB.length); i++) {\n const order = compareChunks(chunksA[i], chunksB[i]);\n if (order !== 0) return order;\n }\n return chunksA.length - chunksB.length || compareStrings(a, b);\n}\n\nfunction compareChunks(a: string, b: string): number {\n if (isDigits(a) && isDigits(b)) {\n // Compared as digit strings, so numbers of any length keep their order.\n const numberA = a.replace(/^0+(?=\\d)/, \"\");\n const numberB = b.replace(/^0+(?=\\d)/, \"\");\n return numberA.length - numberB.length || compareStrings(numberA, numberB);\n }\n return compareStrings(a.toLowerCase(), b.toLowerCase());\n}\n\nfunction isDigits(chunk: string): boolean {\n return chunk.charCodeAt(0) >= 48 && chunk.charCodeAt(0) <= 57;\n}\n\nfunction compareStrings(a: string, b: string): number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