Skip to content

User data

Types and utilities for interacting with the user data stored on the user’s device.

Example

import { ... } from '@wuespace/telestion/user-data';

Type Aliases

Dashboard

type Dashboard: object;

Alpha

Represents a dashboard.

Type declaration

layout
layout: string[][] = layoutSchema;

The layout of the dashboard.

title
title: string;

The title of the dashboard.

See

dashboardSchema


WidgetInstance

type WidgetInstance: object;

Represents a widget instance.

Type declaration

configuration
configuration: Record<string, Json>;

The configuration of the widget.

type
type: string;

The type ID of the widget.

This is used to determine which widget type to use to render the widget.

See

Widget.id

See

widgetInstanceSchema

Variables

dashboardSchema

const dashboardSchema: ZodObject<Dashboard>;

Represents the schema for a dashboard.


idSchema

const idSchema: ZodString;

A regular expression that matches valid identifiers.

Used for dashboard and widget instance IDs.

See

WidgetInstance


jsonSchema

const jsonSchema: z.ZodType<Json>;

layoutSchema

const layoutSchema: ZodArray<ZodArray<ZodUnion<[ZodString, ZodLiteral<".">]>, "many">, "many">;

A schema that matches valid layout configurations.


semverRegExp

const semverRegExp: RegExp;

A regular expression that matches semantic version numbers.

Taken from https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string


userDataSchema

const userDataSchema: ZodObject<UserData>;

The schema for the user data.

See

UserData


widgetInstanceSchema

const widgetInstanceSchema: ZodObject<WidgetInstance>;

Represents the schema for a widget instance.

See

WidgetInstance

Functions

getBlankUserData()

function getBlankUserData(version): UserData

Returns a new blank user data object.

Parameters

version

string

the current application version

Returns

UserData


getEmptyDashboard()

function getEmptyDashboard(): readonly [string, Dashboard]

Returns a new and empty dashboard with a unique id.

Returns

readonly [string, Dashboard]


getUserData()

function getUserData(): undefined | {
  dashboards: Record<string, {
     layout: string[][];
     title: string;
    }>;
  version: string;
  widgetInstances: Record<string, {
     configuration: Record<string, Json>;
     type: string;
    }>;
}

Retrieves user data from local storage.

Returns

undefined | { dashboards: Record<string, { layout: string[][]; title: string; }>; version: string; widgetInstances: Record<string, { configuration: Record<string, Json>; type: string; }>; }

The user data if found in local storage, otherwise undefined.


removeUserData()

function removeUserData(): void

Removes the user data from local storage.

Returns

void


setUserData()

function setUserData(newUserData): void

Sets the user data in the local storage based on the given input.

Parameters

newUserData

The new user data to be set.

dashboards

Record<string, { layout: string[][]; title: string; }> = ...

The user’s dashboards.

version

string = ...

The version of the client that created this user data.

widgetInstances

Record<string, { configuration: Record<string, Json>; type: string; }> = ...

The user’s widget instances.

Returns

void

References

UserData

Re-exports UserData