/** * What `StyledTable` saves under a table's `uniqueKey`, each setting in its own entry: `${uniqueKey}${suffix}`. The sorting * (`:sorting`), column widths (`:column-sizing`), page size (`:page-size`), column order (`:column-order`) and column visibility * (`:column-visibility`). A test pins this list to the key functions of the hooks that write them. */ export declare const TABLE_SETTINGS_SUFFIXES: readonly [":sorting", ":column-sizing", ":page-size", ":column-order", ":column-visibility"]; /** One entry kept under a key that is not the table's `uniqueKey` plus a suffix, moved from its old key to its new one. */ export interface LegacyRawEntry { /** The old key, named exactly. */ from: string; /** The key that holds the entry now. */ to: string; } export interface LegacyTableSettings { /** The table's `uniqueKey` now, the one the entries are copied to. Without one there is nothing to migrate to. */ newKey: string | undefined; /** * The old key, or the old keys, of the **current scope**: the current user, tenant and context, and the current patient or * record where the old key held one. Name them exactly: the entries under these keys are copied to `newKey` and removed. * When an entry exists under several, the first key listed wins; the others are removed. An empty list, or none, means the * app has no current scope to name, and then nothing is copied and **nothing is removed**: the old entries are what the next * visit with a scope can still carry over, and a clean-up must never run before the copy has been tried. */ oldKeys?: string | readonly (string | undefined)[]; /** * More old keys to remove without copying them, for entries that cannot be merged into one (another patient's, another * record's of the same table). It is given each stored key that ends in a known suffix, **with the suffix taken off**, and * answers whether that is an old key of this table. Match only this table's own old prefix for the current user and * tenant, never another table's, user's or tenant's; escape every part you put in a pattern. It is asked only when * `oldKeys` names a current scope, never about `newKey` or one of `oldKeys`, and a matcher that throws is ignored: the * entries of `oldKeys` are still migrated. */ matchOldKey?: (oldKey: string) => boolean; /** * Entries kept under keys that are **not** `newKey` plus a suffix, which the app named itself: a `persistColumnOrderKey` * that carried a record id (`…ColumnOrder-${row.id}`), the key of an app's own visibility hook. Name them as old → new * pairs for the current scope. The same rules as for `oldKeys`: each is copied to its `to` once, only if `to` has no entry * of its own, and `from` is removed once that copy has been tried (not when it was refused); with no pairs, nothing is * copied or removed. When several pairs share a `to`, the first `from` that has an entry wins. */ rawEntries?: readonly LegacyRawEntry[]; /** * The page size this table opens with when the user has saved none: its `pageSize` prop, or `DEFAULT_TABLE_PAGE_SIZE` when it sets * none. It repairs what 3.138.2 and 3.139.0 wrote: a `StyledTable` with a `uniqueKey` saved its page size **when it mounted**, so a table * that opened before its migration (no patient selected yet) already holds the default under the new key, a value the user never chose. * The migration copies only what the new key lacks, so it would keep that default and delete the old size. With this option, **when the * new key's `:page-size` equals it and the old entry holds a different valid page size, the old entry wins**: it is copied over the * new one (and counted as a copy, so the revision goes up), then the old is removed as usual. A new entry that differs from the default * is a choice the user made and is kept, and so is a new entry when the old one is not a valid page size. A user who had deliberately * chosen the default itself under the new key cannot be told from the library's write, and gets the old size. Without this option * nothing changes. It applies to `:page-size` only, and not to raw pairs. */ defaultPageSize?: number; /** * More old raw keys to remove without copying them: another record's of the same table. It is asked about a stored key only * if the key starts with the `to` of a pair, so it can never reach a key that does not begin with the name the table's * settings now have; and never about a `to`, a `from`, `newKey` itself, or a table-settings entry (`newKey`, a `to` or a * `from`, plus a suffix). Asked * only when `rawEntries` names a current scope. Match exactly, and anchor both ends: a name that merely starts the same is * another table's. A matcher that throws is ignored. */ matchRawKey?: (storedKey: string) => boolean; } /** The scope of a migration as one string, `''` when the app names none: what the hook runs again for. */ export declare const legacyTableSettingsScope: ({ newKey, oldKeys, rawEntries, defaultPageSize }: LegacyTableSettings) => string; /** * Carries a table's saved settings from its old keys to its current ones (ASMA-8698). An app that changes a table's key, for * example to take a patient id out of it, would otherwise lose every user's saved sort, widths, page size, order and * visibility. For each of the five entries `StyledTable` saves under `newKey` (`TABLE_SETTINGS_SUFFIXES`), and for each * old → new pair of `rawEntries` (the keys the app named itself): * * 1. the entry of the first old key that has one is **copied** to the new key, but only if the new key has no entry of its own * (one exception, the page size under `defaultPageSize`: see that option): what the user saved under the new key is never * overwritten; * 2. then the old entries are **removed**: those of every old key named, and those the matchers accept. * * Nothing is removed before its copy is written: when storage is full or blocked the old entries stay, and the next call tries * again. A call changes nothing once the old entries are gone, so it is safe to repeat (React StrictMode runs it twice). With * nothing to migrate it only looks for the old entries (one read for each old key and suffix, one for each `from`, none for a * new key) and writes nothing. With no current scope named (`oldKeys` empty, `rawEntries` empty) nothing is copied and nothing * is removed, whatever a matcher would match. It never throws. * * **Returns the number of entries it copied** (`0` when it copied nothing: no scope, nothing to migrate, entries the new key already * had that were only removed, or a copy that storage refused). That is how an app learns that a table which is already showing has * new entries to read: see the `revision` {@link useLegacyTableSettingsMigration} returns. * * Key generation stays in the app: it builds `newKey`, `oldKeys` and the raw pairs with the same helpers that build the table's * keys. Run it before the table first reads its storage; {@link useLegacyTableSettingsMigration} does that. */ export declare const migrateLegacyTableSettings: (settings: LegacyTableSettings) => number;