@kronor/dtv 9.0.0 → 9.1.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/index.es.js +11105 -11067
- package/dist/types/framework/cached-value.d.ts +11 -0
- package/dist/types/framework/result.d.ts +6 -0
- package/dist/types/framework/serial-queue.d.ts +11 -0
- package/dist/types/framework/useUserDataManager.d.ts +8 -7
- package/dist/types/framework/user-data-errors.d.ts +8 -0
- package/dist/types/framework/user-data-manager.d.ts +7 -1
- package/dist/types/framework/user-data-storage.d.ts +17 -0
- package/dist/types/framework/user-data.d.ts +5 -0
- package/package.json +1 -1
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A cached copy of a value: computed on first read (not when created) and kept from then
|
|
3
|
+
* on, and replaceable when the caller learns of a newer value. Reading never recomputes
|
|
4
|
+
* once a value is kept.
|
|
5
|
+
*/
|
|
6
|
+
export type CachedValue<T> = {
|
|
7
|
+
(): T;
|
|
8
|
+
/** Replaces the kept value and returns it. */
|
|
9
|
+
set(value: T): T;
|
|
10
|
+
};
|
|
11
|
+
export declare function cachedValue<T>(compute: () => T): CachedValue<T>;
|
|
@@ -22,6 +22,10 @@ export declare function match<E, T, R>({ whenError: fnE, whenSuccess: fnT }: {
|
|
|
22
22
|
whenError: (e: E) => R;
|
|
23
23
|
whenSuccess: (t: T) => R;
|
|
24
24
|
}, value: Result<E, T>): R;
|
|
25
|
+
/** Chains a step that can itself fail; a failure short-circuits. */
|
|
26
|
+
export declare function flatMap<E, A, B>(next: (value: A) => Result<E, B>, value: Result<E, A>): Result<E, B>;
|
|
27
|
+
/** The success value, or `fallback` for a failure. */
|
|
28
|
+
export declare function getOrElse<E, T>(fallback: T, value: Result<E, T>): T;
|
|
25
29
|
export declare const Result: {
|
|
26
30
|
readonly failure: typeof failure;
|
|
27
31
|
readonly success: typeof success;
|
|
@@ -30,6 +34,8 @@ export declare const Result: {
|
|
|
30
34
|
readonly mapResult: typeof mapResult;
|
|
31
35
|
readonly mapFailure: typeof mapFailure;
|
|
32
36
|
readonly bimap: typeof bimap;
|
|
37
|
+
readonly flatMap: typeof flatMap;
|
|
38
|
+
readonly getOrElse: typeof getOrElse;
|
|
33
39
|
readonly unwrapResult: typeof unwrapResult;
|
|
34
40
|
readonly match: typeof match;
|
|
35
41
|
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runs async tasks one after another, in the order they were enqueued. A failing task
|
|
3
|
+
* fails only for its own caller; the tasks after it still run.
|
|
4
|
+
*/
|
|
5
|
+
export type SerialQueue = {
|
|
6
|
+
enqueue<T>(task: () => Promise<T>): Promise<T>;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* @param after Tasks start only once this promise has settled, whatever its outcome.
|
|
10
|
+
*/
|
|
11
|
+
export declare function createSerialQueue(after?: Promise<unknown>): SerialQueue;
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import type { FilterGroups } from './filters';
|
|
2
2
|
import type { SavedFilter, SavedFilterId } from './saved-filters';
|
|
3
3
|
import type { FilterState } from './state';
|
|
4
|
-
import type { UserPreferences
|
|
4
|
+
import type { UserPreferences } from './user-data';
|
|
5
5
|
import { type UserDataManagerOptions } from './user-data-manager';
|
|
6
6
|
import type { ViewId } from './view';
|
|
7
7
|
export declare function useUserDataManager(filterGroupsByViewId: Record<ViewId, FilterGroups>, currentViewId: ViewId, options: UserDataManagerOptions): {
|
|
8
|
+
isReady: boolean;
|
|
8
9
|
preferences: UserPreferences;
|
|
9
|
-
viewData: ViewData;
|
|
10
|
+
viewData: import("./user-data").ViewData;
|
|
10
11
|
savedFilters: SavedFilter[];
|
|
11
12
|
updatePreferences: (updateFunc: (prev: UserPreferences) => UserPreferences) => Promise<UserPreferences>;
|
|
12
|
-
setRowsPerPage: (viewId: ViewId, rowsPerPage: number) => Promise<ViewData>;
|
|
13
|
-
setColumnOrder: (viewId: ViewId, order: string[] | null) => Promise<ViewData>;
|
|
14
|
-
setHiddenColumns: (viewId: ViewId, hidden: string[]) => Promise<ViewData>;
|
|
15
|
-
setSyncFilterStateToUserData: (viewId: ViewId, enabled: boolean) => Promise<ViewData>;
|
|
16
|
-
setPersistedFilterState: (viewId: ViewId, filterState: FilterState | null) => Promise<ViewData>;
|
|
13
|
+
setRowsPerPage: (viewId: ViewId, rowsPerPage: number) => Promise<import("./user-data").ViewData>;
|
|
14
|
+
setColumnOrder: (viewId: ViewId, order: string[] | null) => Promise<import("./user-data").ViewData>;
|
|
15
|
+
setHiddenColumns: (viewId: ViewId, hidden: string[]) => Promise<import("./user-data").ViewData>;
|
|
16
|
+
setSyncFilterStateToUserData: (viewId: ViewId, enabled: boolean) => Promise<import("./user-data").ViewData>;
|
|
17
|
+
setPersistedFilterState: (viewId: ViewId, filterState: FilterState | null) => Promise<import("./user-data").ViewData>;
|
|
17
18
|
createFilter: (filter: Omit<SavedFilter, "id" | "createdAt" | "formatRevision">) => Promise<void>;
|
|
18
19
|
updateFilter: (viewId: ViewId, savedFilterId: SavedFilterId, updates: Partial<Pick<SavedFilter, "name" | "state">>) => Promise<void>;
|
|
19
20
|
deleteFilter: (viewId: ViewId, savedFilterId: SavedFilterId) => Promise<void>;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import type { ShowToastOptions } from './toast';
|
|
2
|
+
import type { UserDataStorageError } from './user-data-storage';
|
|
3
|
+
export declare const errorMessage: (err: unknown) => string;
|
|
4
|
+
export declare function userDataStorageErrorToMessage(error: UserDataStorageError): string;
|
|
2
5
|
export type UserDataManagerError = {
|
|
3
6
|
kind: 'externalSaveFailed';
|
|
4
7
|
message: string;
|
|
@@ -7,7 +10,12 @@ export type UserDataManagerError = {
|
|
|
7
10
|
kind: 'externalLoadFailed';
|
|
8
11
|
message: string;
|
|
9
12
|
cause?: unknown;
|
|
13
|
+
} | {
|
|
14
|
+
kind: 'localStorageFailed';
|
|
15
|
+
message: string;
|
|
16
|
+
cause?: unknown;
|
|
10
17
|
};
|
|
11
18
|
export declare function externalSaveFailed(message: string, cause?: unknown): UserDataManagerError;
|
|
12
19
|
export declare function externalLoadFailed(message: string, cause?: unknown): UserDataManagerError;
|
|
20
|
+
export declare function localStorageFailed(error: UserDataStorageError): UserDataManagerError;
|
|
13
21
|
export declare function userDataManagerErrorToToast(err: UserDataManagerError): ShowToastOptions;
|
|
@@ -5,12 +5,19 @@ import { UserDataJson, UserPreferences, ViewData } from './user-data';
|
|
|
5
5
|
import { ViewId } from './view';
|
|
6
6
|
import type { ShowToastFn } from './toast';
|
|
7
7
|
import { Result } from './result';
|
|
8
|
+
import { USER_DATA_LOCALSTORAGE_KEY } from './user-data-storage';
|
|
9
|
+
export { USER_DATA_LOCALSTORAGE_KEY };
|
|
8
10
|
export interface UserDataManager {
|
|
9
11
|
/**
|
|
10
12
|
* Resolves once an optional async load callback has completed (success or failure).
|
|
11
13
|
* Useful for callers that need to await remote/user-provided hydration.
|
|
12
14
|
*/
|
|
13
15
|
ready: Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* Re-reads the user data another tab wrote to localStorage, so this tab works from
|
|
18
|
+
* that revision and content. Meant for a `storage` event listener.
|
|
19
|
+
*/
|
|
20
|
+
refreshFromLocalStorage(): void;
|
|
14
21
|
getPreferences(): UserPreferences;
|
|
15
22
|
updatePreferences(updateFunc: (prev: UserPreferences) => UserPreferences): Promise<UserPreferences>;
|
|
16
23
|
getViewData(viewId: ViewId): ViewData;
|
|
@@ -24,7 +31,6 @@ export interface UserDataManager {
|
|
|
24
31
|
updateFilter(viewId: ViewId, savedFilterId: SavedFilterId, updates: Partial<Pick<SavedFilter, 'name' | 'state'>>): Promise<void>;
|
|
25
32
|
deleteFilter(viewId: ViewId, savedFilterId: SavedFilterId): Promise<void>;
|
|
26
33
|
}
|
|
27
|
-
export declare const USER_DATA_LOCALSTORAGE_KEY = "dtvUserData";
|
|
28
34
|
export interface UserDataLoadAPI {
|
|
29
35
|
showToast?: ShowToastFn;
|
|
30
36
|
/** Result functions to construct operation results */
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { UserDataJson } from './user-data';
|
|
2
|
+
import { Result } from './result';
|
|
3
|
+
export declare const USER_DATA_LOCALSTORAGE_KEY = "dtvUserData";
|
|
4
|
+
export type UserDataStorageError =
|
|
5
|
+
/** localStorage threw: disabled, full, or otherwise unavailable. */
|
|
6
|
+
{
|
|
7
|
+
kind: 'inaccessible';
|
|
8
|
+
cause: unknown;
|
|
9
|
+
}
|
|
10
|
+
/** What is stored is not user data JSON. */
|
|
11
|
+
| {
|
|
12
|
+
kind: 'malformed';
|
|
13
|
+
cause: unknown;
|
|
14
|
+
};
|
|
15
|
+
/** The stored user data JSON; `null` when nothing is stored. */
|
|
16
|
+
export declare function readUserDataJson(): Result<UserDataStorageError, UserDataJson | null>;
|
|
17
|
+
export declare function writeUserDataJson(userDataJson: UserDataJson): Result<UserDataStorageError, void>;
|
|
@@ -56,3 +56,8 @@ export declare function defaultUserData(): UserData;
|
|
|
56
56
|
export declare function defaultViewData(): ViewData;
|
|
57
57
|
export declare function toUserDataJson(data: UserData, filterGroupsByViewId: Record<ViewId, FilterGroups>): UserDataJson;
|
|
58
58
|
export declare function fromUserDataJson(json: UserDataJson, filterGroupsByViewId: Record<ViewId, FilterGroups>): UserData;
|
|
59
|
+
/**
|
|
60
|
+
* Per-view JSON layered left to right, later layers winning; missing layers are skipped.
|
|
61
|
+
* Used to carry views a manager has no schema for along with the ones it writes.
|
|
62
|
+
*/
|
|
63
|
+
export declare function mergeViewsJson(...layers: Array<Record<ViewId, ViewDataJson> | null | undefined>): Record<ViewId, ViewDataJson>;
|