appData
A type-safe wrapper for @sitevision/api/server/appData
that provides convenient methods for
retrieving and converting app data values with proper type handling.
All methods in will return undefined
or empty arrays instead of inconsistent values when
values are missing or cannot be converted to the expected type.
getString(key)
Section titled “getString(key)”Get a string value from app data.
Param | Type | Description |
---|---|---|
key | string | The key of app data to retrieve. |
Returns: string | undefined
- The string value or undefined if not set.
import appData from '@soleil-se/app-util/server/app-data';
const name = appData.getString('name');console.log(`Hello, ${name}!`);
// Default values are set with nullish coalescing (??)const name = appData.getString('name') ?? 'Default name';
getBoolean(key)
Section titled “getBoolean(key)”Get a boolean value from app data.
Param | Type | Description |
---|---|---|
key | string | The key of app data to retrieve. |
Returns: boolean | undefined
- The boolean value or undefined if not set.
import appData from '@soleil-se/app-util/server/app-data';
const isEnabled = appData.getBoolean('isEnabled');if (isEnabled) { // Something is enabled}
// Default values are set with nullish coalescing (??)const isEnabled = appData.getBoolean('isEnabled') ?? false;
getNumber(key)
Section titled “getNumber(key)”Get a number value from app data.
Param | Type | Description |
---|---|---|
key | string | The key of app data to retrieve. |
Returns: number | undefined
- The number value, undefined if not set or not a valid number.
import appData from '@soleil-se/app-util/server/app-data';
const maxItems = appData.getNumber('maxItems');console.log(`Maximum items: ${maxItems}`);
// Default values are set with nullish coalescing (??)const maxItems = appData.getNumber('maxItems') ?? 10;
getNodes(key)
Section titled “getNodes(key)”Get an array of JCR Nodes from app data, filtering out non-node values.
Param | Type | Description |
---|---|---|
key | string | The key of app data to retrieve. |
Returns: Node[]
- The array of nodes or an empty array if not set.
import appData from '@soleil-se/app-util/server/app-data';
const contentNodes = appData.getNodes('nodes');contentNodes.forEach(node => { // Process each node console.log(node.getName());});
getStrings(key)
Section titled “getStrings(key)”Get an array of strings from app data.
Param | Type | Description |
---|---|---|
key | string | The key of app data to retrieve. |
Returns: string[]
- The array of strings or an empty array if not set.
import appData from '@soleil-se/app-util/server/app-data';
const tags = appData.getStrings('tags');tags.forEach(tag => { console.log(`Tag: ${tag}`);});
getNode(key)
Section titled “getNode(key)”Get a single JCR Node from app data.
Param | Type | Description |
---|---|---|
key | string | The key of the property to retrieve. |
Returns: Node | undefined
- The JCR Node or undefined if not set.
import appData from '@soleil-se/app-util/server/app-data';
const node = appData.getNode('node');console.log(node?.getIdentifier());
// Default values are set with nullish coalescing (??)const node = appData.getNode('node') ?? defaultNode;
getStringProperty(key, property)
Section titled “getStringProperty(key, property)”Get a string property from a JCR Node referenced in app data.
Param | Type | Description |
---|---|---|
key | string | The key of the app data value. |
property | string | The property to retrieve from the node. |
Returns: string | undefined
- The string property value or undefined if not set.
import appData from '@soleil-se/app-util/server/app-data';
const displayName = appData.getStringProperty('node', 'displayName');console.log(`Page display name: ${displayName}`);
// Default values are set with nullish coalescing (??)const displayName = appData.getStringProperty('node', 'displayName') ?? 'Default Display Name';
getStringsProperty(key, property)
Section titled “getStringsProperty(key, property)”Get a string array property or a single string wrapped in an array from a JCR Node referenced in app data.
Param | Type | Description |
---|---|---|
key | string | The key of the app data value. |
property | string | The property to retrieve from the node. |
Returns: string[]
- The array of strings or an empty array if not set.
import appData from '@soleil-se/app-util/server/app-data';
const multipleValueMetadata = appData.getStringsProperty('node', 'multipleValueMetadata');console.log(`Multiple value metadata: ${multipleValueMetadata.join(', ')}`);
getBooleanProperty(key, property)
Section titled “getBooleanProperty(key, property)”Get a boolean property from a JCR Node referenced in app data.
Param | Type | Description |
---|---|---|
key | string | The key of the app data value. |
property | string | The property to retrieve from the node. |
Returns: boolean | undefined
- The boolean property value or undefined if not set.
import appData from '@soleil-se/app-util/server/app-data';
const isPublished = appData.getBooleanProperty('node', 'published');if (isPublished) { // Content is published}
// Default values are set with nullish coalescing (??)const isPublished = appData.getBooleanProperty('node', 'published') ?? false;
getNumberProperty(key, property)
Section titled “getNumberProperty(key, property)”Get a number property from a JCR Node referenced in app data.
Param | Type | Description |
---|---|---|
key | string | The key of the app data value. |
property | string | The property to retrieve from the node. |
Returns: number | undefined
- The number property value, undefined if not set or not a valid number.
import appData from '@soleil-se/app-util/server/app-data';
const publishDateTimestamp = appData.getNumberProperty('node', 'publishDate');console.log(`Publish date timestamp: ${publishDateTimestamp}`);
// Default values are set with nullish coalescing (??)const publishDate = appData.getNumberProperty('node', 'publishDate') ?? Date.now();
get(key, …properties)
Section titled “get(key, …properties)”Get a raw value from app data.
This is identical to the get
method in @sitevision/api/server/appData
.
Param | Type | Description |
---|---|---|
key | string | The key of app data to retrieve. |
string[] | The keys of the properties to retrieve from a JCR Node. |
Returns: unknown
- The value of the app data or properties of a JCR Node.
import appData from '@soleil-se/app-util/server/app-data';
const value = appData.get('value');const displayName = appData.get('node', 'displayName');
// Default values are set with nullish coalescing (??)const value = appData.get('value') ?? 'Default value';
getArray(key)
Section titled “getArray(key)”Get a value from app data as an array.
This is identical to the getArray
method in @sitevision/api/server/appData
.
Param | Type | Description |
---|---|---|
key | string | The key of app data to retrieve. |
Returns: Node[] | string[]
- An array of JCR Nodes for list components or value wrapped in an array for single type components.
import appData from '@soleil-se/app-util/server/app-data';
const nodes = appData.getArray('nodes');
Default values
Section titled “Default values”Default values can be set using the nullish coalescing operator (??
).
import appData from '@soleil-se/app-util/server/app-data';
const title = appData.getString('title') ?? 'Default Title';console.log(`Title: ${title}`);