@soleil-se/app-util 5.10.0 → 5.11.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/CHANGELOG.md +13 -0
- package/client/fetch-json/index.d.ts +48 -15
- package/client/fetch-json/index.js +91 -25
- package/client/index.d.ts +3 -3
- package/client/index.js +1 -1
- package/client/svelte/4/index.d.ts +4 -4
- package/client/svelte/4/index.js +2 -2
- package/client/svelte/5/index.d.ts +4 -6
- package/client/svelte/5/index.js +2 -4
- package/client/svelte/index.d.ts +2 -2
- package/client/svelte/index.js +1 -1
- package/client/url-params/index.d.ts +10 -7
- package/client/url-params/index.js +3 -4
- package/common/index.d.ts +81 -81
- package/package.json +3 -3
- package/server/app-data/index.d.ts +84 -0
- package/server/app-data/index.js +155 -0
- package/server/global-app-data/index.d.ts +84 -0
- package/server/global-app-data/index.js +155 -0
- package/server/svelte/4/index.d.ts +3 -3
- package/server/svelte/4/index.js +2 -2
- package/server/svelte/5/index.d.ts +3 -5
- package/server/svelte/5/index.js +2 -3
- package/server/svelte/index.d.ts +2 -2
- package/server/svelte/index.js +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,19 @@ All notable changes to this project will be documented in this file.
|
|
|
7
7
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
8
8
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
9
9
|
|
|
10
|
+
## [5.11.0] - 2025-09-04
|
|
11
|
+
|
|
12
|
+
- Add type-safe wrapper for `@sitevision/api/server/appData` and `@sitevision/api/server/globalAppData`.
|
|
13
|
+
- Adjust types for `fetchJson` and `urlParams` to work better with TypeScript.
|
|
14
|
+
|
|
15
|
+
## [5.10.1] - 2025-06-26
|
|
16
|
+
|
|
17
|
+
- Adjust types for rendering functions.
|
|
18
|
+
|
|
19
|
+
## [5.10.0] - 2025-05-30
|
|
20
|
+
|
|
21
|
+
- Add new utility function `preventDefault` to prevent default behavior of events in a more readable way.
|
|
22
|
+
|
|
10
23
|
## [5.9.1] - 2025-03-27
|
|
11
24
|
|
|
12
25
|
- Update type definitions.
|
|
@@ -4,20 +4,53 @@
|
|
|
4
4
|
* `https://` will be left as is. Other URI:s willbe converted to match a route in the current app
|
|
5
5
|
* with `getRouteUri`.
|
|
6
6
|
*
|
|
7
|
+
* @template T
|
|
7
8
|
* @param {string} uri - The URI to fetch JSON data from.
|
|
8
|
-
* @param {
|
|
9
|
-
* @
|
|
10
|
-
* @
|
|
11
|
-
* @param {object} options.body - The body to include in the request.
|
|
12
|
-
* @param {number} options.retries - The number of retries to attempt in case of a timeout error.
|
|
13
|
-
* @param {object} options.headers - The headers to be included in the request.
|
|
14
|
-
* @returns {Promise<object>} A promise that resolves to the JSON response.
|
|
15
|
-
* @throws {Error} If the response is not successful or cannot be parsed as JSON.
|
|
9
|
+
* @param {Options} [options] - The options for the fetch request with some extensions.
|
|
10
|
+
* @returns {Promise<T>} A promise that resolves to the JSON response.
|
|
11
|
+
* @throws {FetchError} If the response is not successful or cannot be parsed as JSON.
|
|
16
12
|
*/
|
|
17
|
-
export default function fetchJson(uri: string, options?:
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
13
|
+
export default function fetchJson<T>(uri: string, options?: Options): Promise<T>;
|
|
14
|
+
/**
|
|
15
|
+
* @typedef {Object} ExtensionOptions
|
|
16
|
+
* @property {{ [key: string]: unknown }} [params] - The parameters to be included in the request
|
|
17
|
+
* URL.
|
|
18
|
+
* @property {number} [retries=0] - The number of retries to attempt in case of a timeout error.
|
|
19
|
+
*
|
|
20
|
+
* @typedef {RequestInit & ExtensionOptions} Options
|
|
21
|
+
*/
|
|
22
|
+
/**
|
|
23
|
+
* Custom error class for fetch-related errors with additional HTTP context.
|
|
24
|
+
*/
|
|
25
|
+
export class FetchError extends Error {
|
|
26
|
+
/**
|
|
27
|
+
* @param {string} message - The error message.
|
|
28
|
+
* @param {Object} [options] - Error options.
|
|
29
|
+
* @param {number} [options.status] - HTTP status code.
|
|
30
|
+
* @param {boolean} [options.aborted=false] - Whether the request was aborted.
|
|
31
|
+
* @param {Object.<string, unknown>} [options.additionalProps] - Additional properties.
|
|
32
|
+
*/
|
|
33
|
+
constructor(message: string, { status, aborted, ...additionalProps }?: {
|
|
34
|
+
status?: number;
|
|
35
|
+
aborted?: boolean;
|
|
36
|
+
additionalProps?: {
|
|
37
|
+
[x: string]: unknown;
|
|
38
|
+
};
|
|
39
|
+
});
|
|
40
|
+
status: number;
|
|
41
|
+
aborted: boolean;
|
|
42
|
+
}
|
|
43
|
+
export type ExtensionOptions = {
|
|
44
|
+
/**
|
|
45
|
+
* - The parameters to be included in the request
|
|
46
|
+
* URL.
|
|
47
|
+
*/
|
|
48
|
+
params?: {
|
|
49
|
+
[key: string]: unknown;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* - The number of retries to attempt in case of a timeout error.
|
|
53
|
+
*/
|
|
54
|
+
retries?: number;
|
|
55
|
+
};
|
|
56
|
+
export type Options = RequestInit & ExtensionOptions;
|
|
@@ -1,5 +1,46 @@
|
|
|
1
1
|
import { getRouteUri, stringifyParams } from '../../common';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* @typedef {Object} ExtensionOptions
|
|
5
|
+
* @property {{ [key: string]: unknown }} [params] - The parameters to be included in the request
|
|
6
|
+
* URL.
|
|
7
|
+
* @property {number} [retries=0] - The number of retries to attempt in case of a timeout error.
|
|
8
|
+
*
|
|
9
|
+
* @typedef {RequestInit & ExtensionOptions} Options
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Custom error class for fetch-related errors with additional HTTP context.
|
|
14
|
+
*/
|
|
15
|
+
export class FetchError extends Error {
|
|
16
|
+
/**
|
|
17
|
+
* @param {string} message - The error message.
|
|
18
|
+
* @param {Object} [options] - Error options.
|
|
19
|
+
* @param {number} [options.status] - HTTP status code.
|
|
20
|
+
* @param {boolean} [options.aborted=false] - Whether the request was aborted.
|
|
21
|
+
* @param {Object.<string, unknown>} [options.additionalProps] - Additional properties.
|
|
22
|
+
*/
|
|
23
|
+
constructor(message, { status, aborted = false, ...additionalProps } = {}) {
|
|
24
|
+
super(message);
|
|
25
|
+
this.name = 'FetchError';
|
|
26
|
+
this.status = status;
|
|
27
|
+
this.aborted = aborted;
|
|
28
|
+
|
|
29
|
+
// Add any additional properties from the error response
|
|
30
|
+
Object.entries(additionalProps).forEach(([key, value]) => {
|
|
31
|
+
if (key !== 'message' && key !== 'status' && key !== 'aborted') {
|
|
32
|
+
this[key] = value;
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Builds the URL for the request, handling different URI formats.
|
|
40
|
+
* @param {string} uri - The URI to convert to a full URL.
|
|
41
|
+
* @param {{ [key: string]: unknown }} params - Query parameters to include in the URL.
|
|
42
|
+
* @returns {string} The complete URL for the request.
|
|
43
|
+
*/
|
|
3
44
|
function getUrl(uri, params) {
|
|
4
45
|
if (uri.startsWith('/rest-api') || uri.startsWith('/appresource') || uri.startsWith('/edit-app-config') || !uri.startsWith('/')) {
|
|
5
46
|
return uri + stringifyParams(params, { addQueryPrefix: true });
|
|
@@ -7,6 +48,11 @@ function getUrl(uri, params) {
|
|
|
7
48
|
return getRouteUri(uri, params);
|
|
8
49
|
}
|
|
9
50
|
|
|
51
|
+
/**
|
|
52
|
+
* Attempts to parse response text as JSON.
|
|
53
|
+
* @param {Response} response - The fetch Response object.
|
|
54
|
+
* @returns {Promise<unknown | undefined>} The parsed JSON object or undefined if parsing fails.
|
|
55
|
+
*/
|
|
10
56
|
async function toJson(response) {
|
|
11
57
|
const text = await response.text();
|
|
12
58
|
try {
|
|
@@ -16,31 +62,51 @@ async function toJson(response) {
|
|
|
16
62
|
}
|
|
17
63
|
}
|
|
18
64
|
|
|
65
|
+
/**
|
|
66
|
+
* Creates a FetchError object from a failed response, including JSON error details.
|
|
67
|
+
* @param {Response} response - The failed fetch Response object.
|
|
68
|
+
* @returns {Promise<FetchError>} A FetchError with additional properties from the response JSON.
|
|
69
|
+
*/
|
|
19
70
|
async function responseError(response) {
|
|
20
71
|
const json = await toJson(response) || {};
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
72
|
+
const message = json?.message || response?.statusText;
|
|
73
|
+
return new FetchError(message, {
|
|
74
|
+
status: response.status,
|
|
75
|
+
aborted: false,
|
|
76
|
+
...json,
|
|
24
77
|
});
|
|
25
|
-
error.status = response.status;
|
|
26
|
-
return error;
|
|
27
78
|
}
|
|
28
79
|
|
|
80
|
+
/**
|
|
81
|
+
* Handles the fetch response, throwing errors for non-OK responses and parsing JSON.
|
|
82
|
+
* @param {Response} response - The fetch Response object.
|
|
83
|
+
* @returns {Promise<unknown>} The parsed JSON response.
|
|
84
|
+
* @throws {FetchError} If the response is not OK or cannot be parsed as JSON.
|
|
85
|
+
*/
|
|
29
86
|
async function handleResponse(response) {
|
|
30
87
|
if (!response.ok) {
|
|
31
88
|
throw await responseError(response);
|
|
32
89
|
}
|
|
33
90
|
const json = await toJson(response);
|
|
34
91
|
if (!json) {
|
|
35
|
-
throw new
|
|
92
|
+
throw new FetchError('Response could not be parsed as JSON.');
|
|
36
93
|
}
|
|
37
94
|
return json;
|
|
38
95
|
}
|
|
39
96
|
|
|
97
|
+
/**
|
|
98
|
+
* Checks if the current context is a SiteVision widget/dashboard.
|
|
99
|
+
* @returns {boolean} True if running in a widget context.
|
|
100
|
+
*/
|
|
40
101
|
function isWidget() {
|
|
41
102
|
return !!window?.sv?.PageContext?.dashboardId;
|
|
42
103
|
}
|
|
43
104
|
|
|
105
|
+
/**
|
|
106
|
+
* Modifies request options for widget context by adding required parameters and headers.
|
|
107
|
+
* @param {Options} options - The original request options.
|
|
108
|
+
* @returns {Options} Modified options with widget-specific parameters and headers.
|
|
109
|
+
*/
|
|
44
110
|
function getWidgetOptions(options) {
|
|
45
111
|
return {
|
|
46
112
|
...options,
|
|
@@ -55,29 +121,17 @@ function getWidgetOptions(options) {
|
|
|
55
121
|
};
|
|
56
122
|
}
|
|
57
123
|
|
|
58
|
-
/**
|
|
59
|
-
* @typedef {Object} ExtensionOptions
|
|
60
|
-
* @property {Object<string,any>} params - The parameters to be included in the request URL.
|
|
61
|
-
* @property {number} retries - The number of retries to attempt in case of a timeout error.
|
|
62
|
-
*
|
|
63
|
-
* @typedef {RequestInit & ExtensionOptions} Options
|
|
64
|
-
*/
|
|
65
|
-
|
|
66
124
|
/**
|
|
67
125
|
* Fetches JSON data from a specified URI.
|
|
68
126
|
* URI:s starting with `/rest-api`, `/appresource`, `/edit-app-config` or a protocol, for example
|
|
69
127
|
* `https://` will be left as is. Other URI:s willbe converted to match a route in the current app
|
|
70
128
|
* with `getRouteUri`.
|
|
71
129
|
*
|
|
130
|
+
* @template T
|
|
72
131
|
* @param {string} uri - The URI to fetch JSON data from.
|
|
73
|
-
* @param {Options} options - The options for the fetch request with some extensions.
|
|
74
|
-
* @
|
|
75
|
-
* @
|
|
76
|
-
* @param {object} options.body - The body to include in the request.
|
|
77
|
-
* @param {number} options.retries - The number of retries to attempt in case of a timeout error.
|
|
78
|
-
* @param {object} options.headers - The headers to be included in the request.
|
|
79
|
-
* @returns {Promise<Object>} A promise that resolves to the JSON response.
|
|
80
|
-
* @throws {Error} If the response is not successful or cannot be parsed as JSON.
|
|
132
|
+
* @param {Options} [options] - The options for the fetch request with some extensions.
|
|
133
|
+
* @returns {Promise<T>} A promise that resolves to the JSON response.
|
|
134
|
+
* @throws {FetchError} If the response is not successful or cannot be parsed as JSON.
|
|
81
135
|
*/
|
|
82
136
|
export default function fetchJson(uri, options = {}) {
|
|
83
137
|
const { params = {}, retries = 0, ...rest } = isWidget() ? getWidgetOptions(options) : options;
|
|
@@ -89,8 +143,20 @@ export default function fetchJson(uri, options = {}) {
|
|
|
89
143
|
if (isTimeout && retries > 0) {
|
|
90
144
|
return fetchJson(uri, { ...rest, params, retries: retries - 1 });
|
|
91
145
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
146
|
+
|
|
147
|
+
// Handle abort errors
|
|
148
|
+
if (error.name === 'AbortError') {
|
|
149
|
+
return Promise.reject(new FetchError(error.message, {
|
|
150
|
+
status: error.status,
|
|
151
|
+
aborted: true,
|
|
152
|
+
}));
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Re-throw FetchError as-is, convert other errors
|
|
156
|
+
if (error instanceof FetchError) {
|
|
157
|
+
return Promise.reject(error);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return Promise.reject(new FetchError(error.message, { status: error.status || 500 }));
|
|
95
161
|
});
|
|
96
162
|
}
|
package/client/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { default as
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
1
|
+
export { default as preventDefault } from "./prevent-default";
|
|
2
|
+
export { getUrlParam, getUrlParams, setUrlParams, updateUrlParams, clearUrlParams } from "./url-params";
|
|
3
|
+
export { default as fetchJson, FetchError } from "./fetch-json";
|
package/client/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/** @typedef {import('svelte').SvelteComponent} Component */
|
|
2
2
|
/**
|
|
3
3
|
* Renders a client side Svelte application.
|
|
4
|
-
* @param {Component} App Svelte app root component.
|
|
4
|
+
* @param {Component<any>} App Svelte app root component.
|
|
5
5
|
* @param {object} [settings={}] Settings object.
|
|
6
6
|
* @param {HTMLElement} [settings.target] Target where app should be mounted.
|
|
7
|
-
* @param {
|
|
7
|
+
* @param {Record<string, any>} [settings.props] Root component props.
|
|
8
8
|
* @param {boolean} [settings.hydrate=target.hasChildNodes()] Instructs Svelte to upgrade existing
|
|
9
9
|
* DOM (usually from server-side rendering) rather than creating new elements. By default the app
|
|
10
10
|
* will hydrate when the target has any child nodes.
|
|
@@ -12,9 +12,9 @@
|
|
|
12
12
|
* rather than waiting for subsequent state changes.
|
|
13
13
|
* @return {Component} Initialized Svelte component.
|
|
14
14
|
*/
|
|
15
|
-
export function render(App:
|
|
15
|
+
export function render(App: any, { target, props, intro, hydrate, }?: {
|
|
16
16
|
target?: HTMLElement;
|
|
17
|
-
props?:
|
|
17
|
+
props?: Record<string, any>;
|
|
18
18
|
hydrate?: boolean;
|
|
19
19
|
intro?: boolean;
|
|
20
20
|
}): Component;
|
package/client/svelte/4/index.js
CHANGED
|
@@ -2,10 +2,10 @@ import { setAppProps } from '../../../common';
|
|
|
2
2
|
/** @typedef {import('svelte').SvelteComponent} Component */
|
|
3
3
|
/**
|
|
4
4
|
* Renders a client side Svelte application.
|
|
5
|
-
* @param {Component} App Svelte app root component.
|
|
5
|
+
* @param {Component<any>} App Svelte app root component.
|
|
6
6
|
* @param {object} [settings={}] Settings object.
|
|
7
7
|
* @param {HTMLElement} [settings.target] Target where app should be mounted.
|
|
8
|
-
* @param {
|
|
8
|
+
* @param {Record<string, any>} [settings.props] Root component props.
|
|
9
9
|
* @param {boolean} [settings.hydrate=target.hasChildNodes()] Instructs Svelte to upgrade existing
|
|
10
10
|
* DOM (usually from server-side rendering) rather than creating new elements. By default the app
|
|
11
11
|
* will hydrate when the target has any child nodes.
|
|
@@ -1,20 +1,18 @@
|
|
|
1
|
-
/** @typedef {import('svelte').Component} Component */
|
|
2
1
|
/**
|
|
3
2
|
* Renders a client side Svelte application.
|
|
4
|
-
* @param {Component} App Svelte app root component.
|
|
3
|
+
* @param {import('svelte').Component<any>} App Svelte app root component.
|
|
5
4
|
* @param {object} [settings={}] Settings object.
|
|
6
5
|
* @param {HTMLElement} [settings.target] Target where app should be mounted.
|
|
7
|
-
* @param {
|
|
6
|
+
* @param {Record<string, any>} [settings.props] Root component props.
|
|
8
7
|
* @param {boolean} [settings.hydrate=target.hasChildNodes()] Instructs Svelte to upgrade existing
|
|
9
8
|
* DOM (usually from server-side rendering) rather than creating new elements. By default the app
|
|
10
9
|
* will hydrate when the target has any child nodes.
|
|
11
10
|
* @param {boolean} [settings.intro=false] If true, will play transitions on initial render,
|
|
12
11
|
* rather than waiting for subsequent state changes.
|
|
13
12
|
*/
|
|
14
|
-
export function render(App: Component
|
|
13
|
+
export function render(App: import('svelte').Component<any>, { target, props, hydrate, intro, }?: {
|
|
15
14
|
target?: HTMLElement;
|
|
16
|
-
props?:
|
|
15
|
+
props?: Record<string, any>;
|
|
17
16
|
hydrate?: boolean;
|
|
18
17
|
intro?: boolean;
|
|
19
18
|
}): void;
|
|
20
|
-
export type Component = import('svelte').Component;
|
package/client/svelte/5/index.js
CHANGED
|
@@ -3,14 +3,12 @@ import { mount as svelteMount, hydrate as svelteHydrate } from 'svelte';
|
|
|
3
3
|
|
|
4
4
|
import { setAppProps } from '../../../common';
|
|
5
5
|
|
|
6
|
-
/** @typedef {import('svelte').Component} Component */
|
|
7
|
-
|
|
8
6
|
/**
|
|
9
7
|
* Renders a client side Svelte application.
|
|
10
|
-
* @param {Component} App Svelte app root component.
|
|
8
|
+
* @param {import('svelte').Component<any>} App Svelte app root component.
|
|
11
9
|
* @param {object} [settings={}] Settings object.
|
|
12
10
|
* @param {HTMLElement} [settings.target] Target where app should be mounted.
|
|
13
|
-
* @param {
|
|
11
|
+
* @param {Record<string, any>} [settings.props] Root component props.
|
|
14
12
|
* @param {boolean} [settings.hydrate=target.hasChildNodes()] Instructs Svelte to upgrade existing
|
|
15
13
|
* DOM (usually from server-side rendering) rather than creating new elements. By default the app
|
|
16
14
|
* will hydrate when the target has any child nodes.
|
package/client/svelte/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Renders a client side Svelte 3 or 4 application.
|
|
3
3
|
* @deprecated Use rendering function for specific Svelte version instead.
|
|
4
4
|
* `import { render } from '@soleil-api/webapp-util/client/svelte/{3|4|5}';`
|
|
5
|
-
* @param {import('svelte').SvelteComponent} App Svelte app root component.
|
|
5
|
+
* @param {import('svelte').SvelteComponent<any>} App Svelte app root component.
|
|
6
6
|
* @param {object} [settings={}] Settings object.
|
|
7
7
|
* @param {string} [settings.target] Target where app should be mounted.
|
|
8
8
|
* @param {string} [settings.props] Root component props.
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* rather than waiting for subsequent state changes.
|
|
14
14
|
* @return {import('svelte').SvelteComponent} Initialized Svelte component.
|
|
15
15
|
*/
|
|
16
|
-
export function render(App: import('svelte').SvelteComponent
|
|
16
|
+
export function render(App: import('svelte').SvelteComponent<any>, settings?: {
|
|
17
17
|
target?: string;
|
|
18
18
|
props?: string;
|
|
19
19
|
hydrate?: boolean;
|
package/client/svelte/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import { render as render4 } from './4';
|
|
|
4
4
|
* Renders a client side Svelte 3 or 4 application.
|
|
5
5
|
* @deprecated Use rendering function for specific Svelte version instead.
|
|
6
6
|
* `import { render } from '@soleil-api/webapp-util/client/svelte/{3|4|5}';`
|
|
7
|
-
* @param {import('svelte').SvelteComponent} App Svelte app root component.
|
|
7
|
+
* @param {import('svelte').SvelteComponent<any>} App Svelte app root component.
|
|
8
8
|
* @param {object} [settings={}] Settings object.
|
|
9
9
|
* @param {string} [settings.target] Target where app should be mounted.
|
|
10
10
|
* @param {string} [settings.props] Root component props.
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Set query parameters in the url-field.
|
|
3
|
-
* @param {
|
|
4
|
-
* @param {Object} [options] Optional options.
|
|
5
|
-
* @param {Boolean} [options.scoped = false] If parameter keys should be scoped to current app.
|
|
3
|
+
* @param {{ [key: string]: unknown }} params - Values to be set.
|
|
6
4
|
*/
|
|
7
|
-
export function setUrlParams(params:
|
|
5
|
+
export function setUrlParams(params: {
|
|
6
|
+
[key: string]: unknown;
|
|
7
|
+
}): void;
|
|
8
8
|
/**
|
|
9
9
|
* Get query parameter from the url-field.
|
|
10
|
+
* @param {string} key - The key of the parameter to get.
|
|
10
11
|
*/
|
|
11
|
-
export function getUrlParam(key:
|
|
12
|
+
export function getUrlParam(key: string): any;
|
|
12
13
|
/**
|
|
13
14
|
* Get query parameters from the url-field.
|
|
14
15
|
*/
|
|
@@ -19,9 +20,11 @@ export function getUrlParams(): {};
|
|
|
19
20
|
export function clearUrlParams(): void;
|
|
20
21
|
/**
|
|
21
22
|
* Updates query parameters in the url-field.
|
|
22
|
-
* @param {
|
|
23
|
+
* @param {{ [key: string]: unknown }} params - Values to be updated.
|
|
23
24
|
*/
|
|
24
|
-
export function updateUrlParams(params:
|
|
25
|
+
export function updateUrlParams(params: {
|
|
26
|
+
[key: string]: unknown;
|
|
27
|
+
}): void;
|
|
25
28
|
declare namespace _default {
|
|
26
29
|
export { getUrlParam };
|
|
27
30
|
export { setUrlParams };
|
|
@@ -4,9 +4,7 @@ const isEmpty = (obj) => Object.keys(obj).length === 0 && obj.constructor === Ob
|
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Set query parameters in the url-field.
|
|
7
|
-
* @param {
|
|
8
|
-
* @param {Object} [options] Optional options.
|
|
9
|
-
* @param {Boolean} [options.scoped = false] If parameter keys should be scoped to current app.
|
|
7
|
+
* @param {{ [key: string]: unknown }} params - Values to be set.
|
|
10
8
|
*/
|
|
11
9
|
export function setUrlParams(params) {
|
|
12
10
|
const path = (isEmpty(params) ? window.location.pathname : `?${stringifyParams(params)}`);
|
|
@@ -16,6 +14,7 @@ export function setUrlParams(params) {
|
|
|
16
14
|
|
|
17
15
|
/**
|
|
18
16
|
* Get query parameter from the url-field.
|
|
17
|
+
* @param {string} key - The key of the parameter to get.
|
|
19
18
|
*/
|
|
20
19
|
export function getUrlParam(key) {
|
|
21
20
|
const params = parseParams(window.location.search);
|
|
@@ -40,7 +39,7 @@ export function clearUrlParams() {
|
|
|
40
39
|
|
|
41
40
|
/**
|
|
42
41
|
* Updates query parameters in the url-field.
|
|
43
|
-
* @param {
|
|
42
|
+
* @param {{ [key: string]: unknown }} params - Values to be updated.
|
|
44
43
|
*/
|
|
45
44
|
export function updateUrlParams(params) {
|
|
46
45
|
setUrlParams(Object.assign(getUrlParams(), params));
|
package/common/index.d.ts
CHANGED
|
@@ -1,81 +1,81 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Get a prefixed namespace unique for app.
|
|
3
|
-
* @param {string} [prefix='app']
|
|
4
|
-
* @return {string} - Prefixed namespace.
|
|
5
|
-
*/
|
|
6
|
-
export function getNamespace(prefix?: string): string;
|
|
7
|
-
/**
|
|
8
|
-
* Generate a unique identifier with a random UUID without dashes.
|
|
9
|
-
* @param {string} prefix Prefix for the identifier.
|
|
10
|
-
* @returns {string} Unique identifier.
|
|
11
|
-
*/
|
|
12
|
-
export function generateId(prefix?: string): string;
|
|
13
|
-
/**
|
|
14
|
-
* Stringify an object to a query string compatible with Sitevision.
|
|
15
|
-
* @param {Object} params Object with parameters to stringify.
|
|
16
|
-
* @param {Object} [options] Optional options.
|
|
17
|
-
* @param {Boolean} [options.addQueryPrefix = false] If a leading ? should be added to the string.
|
|
18
|
-
* @returns Stringified parameters.
|
|
19
|
-
*/
|
|
20
|
-
export function stringifyParams(params?: any, { addQueryPrefix }?: {
|
|
21
|
-
addQueryPrefix?: boolean;
|
|
22
|
-
}): string;
|
|
23
|
-
/**
|
|
24
|
-
* Parse an URL or URI to an object containing its query parameters.
|
|
25
|
-
* @param {String} url URL or URI to be parsed, must start with or contain "?".
|
|
26
|
-
* @returns Object with parsed parameters.
|
|
27
|
-
*/
|
|
28
|
-
export function parseParams(url?: string): {};
|
|
29
|
-
/**
|
|
30
|
-
* Get URI for a route, same as `getStandaloneUrl` in Sitevision router.
|
|
31
|
-
* @param {string} route A route.
|
|
32
|
-
* @param {object} params Query parameters.
|
|
33
|
-
* @returns {string} URI for route.
|
|
34
|
-
*/
|
|
35
|
-
export function getRouteUri(route?: string, params?: object): string;
|
|
36
|
-
/**
|
|
37
|
-
* Get URI for a view, same as `getUrl` in Sitevision router.
|
|
38
|
-
* @deprecated Not used in WebApps 2.
|
|
39
|
-
* @param {string} route A route.
|
|
40
|
-
* @returns {string} URI for view.
|
|
41
|
-
*/
|
|
42
|
-
export function getViewUri(route?: string, params?: any): string;
|
|
43
|
-
/**
|
|
44
|
-
* Get URI for a resource.
|
|
45
|
-
* @param {string} resource A resource.
|
|
46
|
-
* @returns {string} URI for a resource.
|
|
47
|
-
*/
|
|
48
|
-
export function getResourceUri(resource?: string): string;
|
|
49
|
-
export function setAppProps(data: any): void;
|
|
50
|
-
/**
|
|
51
|
-
* Get appData value or object that is passed to app when rendering.
|
|
52
|
-
* @export
|
|
53
|
-
* @param {string} [key] - Key for value.
|
|
54
|
-
* @return {*|object} - Value or object.
|
|
55
|
-
*/
|
|
56
|
-
export function getAppProps(key?: string): any | object;
|
|
57
|
-
/**
|
|
58
|
-
* If the current code is running on the server.
|
|
59
|
-
* @constant {boolean}
|
|
60
|
-
*/
|
|
61
|
-
export const isServer: any;
|
|
62
|
-
/**
|
|
63
|
-
* If the current code is running in the browser.
|
|
64
|
-
* @constant {boolean}
|
|
65
|
-
*/
|
|
66
|
-
export const isBrowser: boolean;
|
|
67
|
-
/**
|
|
68
|
-
* DOM friendly unique identifier for the WebApp.
|
|
69
|
-
* @constant {string}
|
|
70
|
-
*/
|
|
71
|
-
export const appId: string;
|
|
72
|
-
/**
|
|
73
|
-
* If the WebApp is running in offline mode or not.
|
|
74
|
-
* @constant {boolean}
|
|
75
|
-
*/
|
|
76
|
-
export const isOffline: boolean;
|
|
77
|
-
/**
|
|
78
|
-
* If the WebApp is running in online mode or not.
|
|
79
|
-
* @constant {boolean}
|
|
80
|
-
*/
|
|
81
|
-
export const isOnline: boolean;
|
|
1
|
+
/**
|
|
2
|
+
* Get a prefixed namespace unique for app.
|
|
3
|
+
* @param {string} [prefix='app']
|
|
4
|
+
* @return {string} - Prefixed namespace.
|
|
5
|
+
*/
|
|
6
|
+
export function getNamespace(prefix?: string): string;
|
|
7
|
+
/**
|
|
8
|
+
* Generate a unique identifier with a random UUID without dashes.
|
|
9
|
+
* @param {string} prefix Prefix for the identifier.
|
|
10
|
+
* @returns {string} Unique identifier.
|
|
11
|
+
*/
|
|
12
|
+
export function generateId(prefix?: string): string;
|
|
13
|
+
/**
|
|
14
|
+
* Stringify an object to a query string compatible with Sitevision.
|
|
15
|
+
* @param {Object} params Object with parameters to stringify.
|
|
16
|
+
* @param {Object} [options] Optional options.
|
|
17
|
+
* @param {Boolean} [options.addQueryPrefix = false] If a leading ? should be added to the string.
|
|
18
|
+
* @returns Stringified parameters.
|
|
19
|
+
*/
|
|
20
|
+
export function stringifyParams(params?: any, { addQueryPrefix }?: {
|
|
21
|
+
addQueryPrefix?: boolean;
|
|
22
|
+
}): string;
|
|
23
|
+
/**
|
|
24
|
+
* Parse an URL or URI to an object containing its query parameters.
|
|
25
|
+
* @param {String} url URL or URI to be parsed, must start with or contain "?".
|
|
26
|
+
* @returns Object with parsed parameters.
|
|
27
|
+
*/
|
|
28
|
+
export function parseParams(url?: string): {};
|
|
29
|
+
/**
|
|
30
|
+
* Get URI for a route, same as `getStandaloneUrl` in Sitevision router.
|
|
31
|
+
* @param {string} route A route.
|
|
32
|
+
* @param {object} params Query parameters.
|
|
33
|
+
* @returns {string} URI for route.
|
|
34
|
+
*/
|
|
35
|
+
export function getRouteUri(route?: string, params?: object): string;
|
|
36
|
+
/**
|
|
37
|
+
* Get URI for a view, same as `getUrl` in Sitevision router.
|
|
38
|
+
* @deprecated Not used in WebApps 2.
|
|
39
|
+
* @param {string} route A route.
|
|
40
|
+
* @returns {string} URI for view.
|
|
41
|
+
*/
|
|
42
|
+
export function getViewUri(route?: string, params?: any): string;
|
|
43
|
+
/**
|
|
44
|
+
* Get URI for a resource.
|
|
45
|
+
* @param {string} resource A resource.
|
|
46
|
+
* @returns {string} URI for a resource.
|
|
47
|
+
*/
|
|
48
|
+
export function getResourceUri(resource?: string): string;
|
|
49
|
+
export function setAppProps(data: any): void;
|
|
50
|
+
/**
|
|
51
|
+
* Get appData value or object that is passed to app when rendering.
|
|
52
|
+
* @export
|
|
53
|
+
* @param {string} [key] - Key for value.
|
|
54
|
+
* @return {*|object} - Value or object.
|
|
55
|
+
*/
|
|
56
|
+
export function getAppProps(key?: string): any | object;
|
|
57
|
+
/**
|
|
58
|
+
* If the current code is running on the server.
|
|
59
|
+
* @constant {boolean}
|
|
60
|
+
*/
|
|
61
|
+
export const isServer: any;
|
|
62
|
+
/**
|
|
63
|
+
* If the current code is running in the browser.
|
|
64
|
+
* @constant {boolean}
|
|
65
|
+
*/
|
|
66
|
+
export const isBrowser: boolean;
|
|
67
|
+
/**
|
|
68
|
+
* DOM friendly unique identifier for the WebApp.
|
|
69
|
+
* @constant {string}
|
|
70
|
+
*/
|
|
71
|
+
export const appId: string;
|
|
72
|
+
/**
|
|
73
|
+
* If the WebApp is running in offline mode or not.
|
|
74
|
+
* @constant {boolean}
|
|
75
|
+
*/
|
|
76
|
+
export const isOffline: boolean;
|
|
77
|
+
/**
|
|
78
|
+
* If the WebApp is running in online mode or not.
|
|
79
|
+
* @constant {boolean}
|
|
80
|
+
*/
|
|
81
|
+
export const isOnline: boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soleil-se/app-util",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.11.0",
|
|
4
4
|
"description": "Utility functions for WebApps, RESTApps and Widgets in Sitevision.",
|
|
5
5
|
"main": "./common/index.js",
|
|
6
6
|
"author": "Soleil AB",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"@sitevision/api": "*"
|
|
24
24
|
},
|
|
25
25
|
"scripts": {
|
|
26
|
-
"create-type-definitions": "node ../../utils/createTypeDefinitions.js ./common/index.js
|
|
26
|
+
"create-type-definitions": "node ../../utils/createTypeDefinitions.js ./common/index.js ./client/index.js ./client/svelte/index.js ./client/svelte/3/index.js ./client/svelte/4/index.js ./client/svelte/5/index.js ./server/index.js ./server/svelte/index.js ./server/svelte/3/index.js ./server/svelte/4/index.js ./server/svelte/5/index.js ./server/app-data/index.js ./server/global-app-data/index.js"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "972710bfa1a879efbd9ff95f6e2562eef4dd31d3"
|
|
29
29
|
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
export default appData;
|
|
2
|
+
declare namespace appData {
|
|
3
|
+
/**
|
|
4
|
+
* Get a value from app data, same as get in \@sitevision/api/server/appData.
|
|
5
|
+
* @param {string} key - The key of app data to retrieve.
|
|
6
|
+
* @param {...string} [properties] - The keys of the properties to retrieve from a JCR Node.
|
|
7
|
+
* @returns {unknown} The value of the app data or a properties of a JCR Node.
|
|
8
|
+
*/
|
|
9
|
+
function get(key: string, ...properties?: string[]): unknown;
|
|
10
|
+
/**
|
|
11
|
+
* Get a value from app data as an array, same as getArray in \@sitevision/api/server/appData.
|
|
12
|
+
* @param {string} key - The key of app data to retrieve.
|
|
13
|
+
* @returns {import('@sitevision/api/types/javax/jcr/Node').Node[] | string[]} An array of JCR
|
|
14
|
+
* Nodes for list components or value wrapped in an array for single type components.
|
|
15
|
+
*/
|
|
16
|
+
function getArray(key: string): string[] | import("@sitevision/api/types/javax/jcr/Node").Node[];
|
|
17
|
+
/**
|
|
18
|
+
* Get a string value from app data.
|
|
19
|
+
* @param {string} key - The key of app data to retrieve.
|
|
20
|
+
* @returns {string | undefined} The string value or undefined if not set.
|
|
21
|
+
*/
|
|
22
|
+
function getString(key: string): string | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* Get a boolean value from app data.
|
|
25
|
+
* @param {string} key - The key of app data to retrieve.
|
|
26
|
+
* @returns {boolean | undefined} The boolean value or undefined if not set.
|
|
27
|
+
*/
|
|
28
|
+
function getBoolean(key: string): boolean | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* Get a number value from app data.
|
|
31
|
+
* @param {string} key - The key of app data to retrieve.
|
|
32
|
+
* @returns {number | undefined} The number value, undefined if not set or not a number.
|
|
33
|
+
*/
|
|
34
|
+
function getNumber(key: string): number | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* Get an array of nodes from app data.
|
|
37
|
+
* @param {string} key - The key of app data to retrieve.
|
|
38
|
+
* @returns {import('@sitevision/api/types/javax/jcr/Node').Node[]} The array of nodes or an
|
|
39
|
+
* empty array if not set.
|
|
40
|
+
*/
|
|
41
|
+
function getNodes(key: string): import("@sitevision/api/types/javax/jcr/Node").Node[];
|
|
42
|
+
/**
|
|
43
|
+
* Get an array of strings from app data.
|
|
44
|
+
* @param {string} key - The key of app data to retrieve.
|
|
45
|
+
* @returns {string[]} The array of strings or an empty array if not set.
|
|
46
|
+
*/
|
|
47
|
+
function getStrings(key: string): string[];
|
|
48
|
+
/**
|
|
49
|
+
* Get a JCR Node from app data.
|
|
50
|
+
* @param {string} key - The key of the property to retrieve.
|
|
51
|
+
* @returns {import('@sitevision/api/types/javax/jcr/Node').Node | undefined} The JCR Node or
|
|
52
|
+
* undefined if not set.
|
|
53
|
+
*/
|
|
54
|
+
function getNode(key: string): import("@sitevision/api/types/javax/jcr/Node").Node;
|
|
55
|
+
/**
|
|
56
|
+
* Get a string property from a JCR Node referenced in app data.
|
|
57
|
+
* @param {string} key - The key of the app data value.
|
|
58
|
+
* @param {string} property - The property to retrieve from the node.
|
|
59
|
+
* @returns {string | undefined} The string property value or undefined if not set.
|
|
60
|
+
*/
|
|
61
|
+
function getStringProperty(key: string, property: string): string | undefined;
|
|
62
|
+
/**
|
|
63
|
+
* Get a string array property or a single string wrapped in an array from a JCR Node referenced
|
|
64
|
+
* in app data.
|
|
65
|
+
* @param {string} key - The key of app data to retrieve.
|
|
66
|
+
* @param {string} property - The property to retrieve from the node.
|
|
67
|
+
* @returns {string[]} The array of strings or an empty array if not set.
|
|
68
|
+
*/
|
|
69
|
+
function getStringsProperty(key: string, property: string): string[];
|
|
70
|
+
/**
|
|
71
|
+
* Get a boolean property from a JCR Node referenced in app data.
|
|
72
|
+
* @param {string} key - The key of the app data value.
|
|
73
|
+
* @param {string} property - The property to retrieve from the node.
|
|
74
|
+
* @returns {boolean | undefined} The boolean property value or undefined if not set.
|
|
75
|
+
*/
|
|
76
|
+
function getBooleanProperty(key: string, property: string): boolean | undefined;
|
|
77
|
+
/**
|
|
78
|
+
* Get a number property from a JCR Node referenced in app data.
|
|
79
|
+
* @param {string} key - The key of the app data value.
|
|
80
|
+
* @param {string} property - The property to retrieve from the node.
|
|
81
|
+
* @returns {number | undefined} The number property value, undefined if not set or not a number.
|
|
82
|
+
*/
|
|
83
|
+
function getNumberProperty(key: string, property: string): number | undefined;
|
|
84
|
+
}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import appDataSv from '@sitevision/api/server/appData';
|
|
2
|
+
import InstanceTypeUtil from '@sitevision/api/server/InstanceTypeUtil';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Converts the value returned by appData.get to a string representation.
|
|
6
|
+
* @param {any} value - The value to convert.
|
|
7
|
+
* @returns {string | undefined} - The string representation of the value or undefined if not a
|
|
8
|
+
* string.
|
|
9
|
+
*/
|
|
10
|
+
function toString(value) {
|
|
11
|
+
if (value === null || value === undefined) return undefined;
|
|
12
|
+
return value.toString();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Converts the value returned by appData.get to a boolean representation.
|
|
17
|
+
* @param {any} value - The value to convert.
|
|
18
|
+
* @returns {boolean | undefined} - The boolean representation of the value or undefined if not a
|
|
19
|
+
* boolean.
|
|
20
|
+
*/
|
|
21
|
+
function toBoolean(value) {
|
|
22
|
+
if (value === undefined || value === null) return undefined;
|
|
23
|
+
return !!value;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Converts the value returned by appData.get to a number representation.
|
|
28
|
+
* @param {any} value - The value to convert.
|
|
29
|
+
* @returns {number | undefined} - The number representation of the value or undefined if not a
|
|
30
|
+
* number.
|
|
31
|
+
*/
|
|
32
|
+
function toNumber(value) {
|
|
33
|
+
if (value === undefined || value === null) return undefined;
|
|
34
|
+
const num = +value;
|
|
35
|
+
return Number.isNaN(num) ? undefined : num;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const appData = {
|
|
39
|
+
/**
|
|
40
|
+
* Get a value from app data, same as get in \@sitevision/api/server/appData.
|
|
41
|
+
* @param {string} key - The key of app data to retrieve.
|
|
42
|
+
* @param {...string} [properties] - The keys of the properties to retrieve from a JCR Node.
|
|
43
|
+
* @returns {unknown} The value of the app data or a properties of a JCR Node.
|
|
44
|
+
*/
|
|
45
|
+
get(key, ...properties) {
|
|
46
|
+
return appDataSv.get(key, ...properties);
|
|
47
|
+
},
|
|
48
|
+
/**
|
|
49
|
+
* Get a value from app data as an array, same as getArray in \@sitevision/api/server/appData.
|
|
50
|
+
* @param {string} key - The key of app data to retrieve.
|
|
51
|
+
* @returns {import('@sitevision/api/types/javax/jcr/Node').Node[] | string[]} An array of JCR
|
|
52
|
+
* Nodes for list components or value wrapped in an array for single type components.
|
|
53
|
+
*/
|
|
54
|
+
getArray(key) {
|
|
55
|
+
return appDataSv.getArray(key);
|
|
56
|
+
},
|
|
57
|
+
/**
|
|
58
|
+
* Get a string value from app data.
|
|
59
|
+
* @param {string} key - The key of app data to retrieve.
|
|
60
|
+
* @returns {string | undefined} The string value or undefined if not set.
|
|
61
|
+
*/
|
|
62
|
+
getString(key) {
|
|
63
|
+
return toString(appDataSv.get(key));
|
|
64
|
+
},
|
|
65
|
+
/**
|
|
66
|
+
* Get a boolean value from app data.
|
|
67
|
+
* @param {string} key - The key of app data to retrieve.
|
|
68
|
+
* @returns {boolean | undefined} The boolean value or undefined if not set.
|
|
69
|
+
*/
|
|
70
|
+
getBoolean(key) {
|
|
71
|
+
return toBoolean(appDataSv.get(key));
|
|
72
|
+
},
|
|
73
|
+
/**
|
|
74
|
+
* Get a number value from app data.
|
|
75
|
+
* @param {string} key - The key of app data to retrieve.
|
|
76
|
+
* @returns {number | undefined} The number value, undefined if not set or not a number.
|
|
77
|
+
*/
|
|
78
|
+
getNumber(key) {
|
|
79
|
+
return toNumber(appDataSv.get(key));
|
|
80
|
+
},
|
|
81
|
+
/**
|
|
82
|
+
* Get an array of nodes from app data.
|
|
83
|
+
* @param {string} key - The key of app data to retrieve.
|
|
84
|
+
* @returns {import('@sitevision/api/types/javax/jcr/Node').Node[]} The array of nodes or an
|
|
85
|
+
* empty array if not set.
|
|
86
|
+
*/
|
|
87
|
+
getNodes(key) {
|
|
88
|
+
return appDataSv.getArray(key)?.filter((v) => InstanceTypeUtil.isNode(v)) || [];
|
|
89
|
+
},
|
|
90
|
+
/**
|
|
91
|
+
* Get an array of strings from app data.
|
|
92
|
+
* @param {string} key - The key of app data to retrieve.
|
|
93
|
+
* @returns {string[]} The array of strings or an empty array if not set.
|
|
94
|
+
*/
|
|
95
|
+
getStrings(key) {
|
|
96
|
+
return appDataSv.getArray(key)
|
|
97
|
+
?.map((v) => toString(v))
|
|
98
|
+
?.filter((v) => v !== undefined) || [];
|
|
99
|
+
},
|
|
100
|
+
/**
|
|
101
|
+
* Get a JCR Node from app data.
|
|
102
|
+
* @param {string} key - The key of the property to retrieve.
|
|
103
|
+
* @returns {import('@sitevision/api/types/javax/jcr/Node').Node | undefined} The JCR Node or
|
|
104
|
+
* undefined if not set.
|
|
105
|
+
*/
|
|
106
|
+
getNode(key) {
|
|
107
|
+
return appDataSv.getNode(key) ?? undefined;
|
|
108
|
+
},
|
|
109
|
+
/**
|
|
110
|
+
* Get a string property from a JCR Node referenced in app data.
|
|
111
|
+
* @param {string} key - The key of the app data value.
|
|
112
|
+
* @param {string} property - The property to retrieve from the node.
|
|
113
|
+
* @returns {string | undefined} The string property value or undefined if not set.
|
|
114
|
+
*/
|
|
115
|
+
getStringProperty(key, property) {
|
|
116
|
+
return toString(appDataSv.get(key, property));
|
|
117
|
+
},
|
|
118
|
+
/**
|
|
119
|
+
* Get a string array property or a single string wrapped in an array from a JCR Node referenced
|
|
120
|
+
* in app data.
|
|
121
|
+
* @param {string} key - The key of app data to retrieve.
|
|
122
|
+
* @param {string} property - The property to retrieve from the node.
|
|
123
|
+
* @returns {string[]} The array of strings or an empty array if not set.
|
|
124
|
+
*/
|
|
125
|
+
getStringsProperty(key, property) {
|
|
126
|
+
let value = appDataSv.get(key, property);
|
|
127
|
+
if (Array.isArray(value)) {
|
|
128
|
+
return value
|
|
129
|
+
?.map((v) => toString(v))
|
|
130
|
+
?.filter((v) => v !== undefined) || [];
|
|
131
|
+
}
|
|
132
|
+
value = toString(value);
|
|
133
|
+
return value ? [value] : [];
|
|
134
|
+
},
|
|
135
|
+
/**
|
|
136
|
+
* Get a boolean property from a JCR Node referenced in app data.
|
|
137
|
+
* @param {string} key - The key of the app data value.
|
|
138
|
+
* @param {string} property - The property to retrieve from the node.
|
|
139
|
+
* @returns {boolean | undefined} The boolean property value or undefined if not set.
|
|
140
|
+
*/
|
|
141
|
+
getBooleanProperty(key, property) {
|
|
142
|
+
return toBoolean(appDataSv.get(key, property));
|
|
143
|
+
},
|
|
144
|
+
/**
|
|
145
|
+
* Get a number property from a JCR Node referenced in app data.
|
|
146
|
+
* @param {string} key - The key of the app data value.
|
|
147
|
+
* @param {string} property - The property to retrieve from the node.
|
|
148
|
+
* @returns {number | undefined} The number property value, undefined if not set or not a number.
|
|
149
|
+
*/
|
|
150
|
+
getNumberProperty(key, property) {
|
|
151
|
+
return toNumber(appDataSv.get(key, property));
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
export default appData;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
export default globalAppData;
|
|
2
|
+
declare namespace globalAppData {
|
|
3
|
+
/**
|
|
4
|
+
* Get a value from app data, same as get in \@sitevision/api/server/appData.
|
|
5
|
+
* @param {string} key - The key of app data to retrieve.
|
|
6
|
+
* @param {...string} [properties] - The keys of the properties to retrieve from a JCR Node.
|
|
7
|
+
* @returns {unknown} The value of the app data or a properties of a JCR Node.
|
|
8
|
+
*/
|
|
9
|
+
function get(key: string, ...properties?: string[]): unknown;
|
|
10
|
+
/**
|
|
11
|
+
* Get a value from app data as an array, same as getArray in \@sitevision/api/server/appData.
|
|
12
|
+
* @param {string} key - The key of app data to retrieve.
|
|
13
|
+
* @returns {import('@sitevision/api/types/javax/jcr/Node').Node[] | string[]} An array of JCR
|
|
14
|
+
* Nodes for list components or value wrapped in an array for single type components.
|
|
15
|
+
*/
|
|
16
|
+
function getArray(key: string): string[] | import("@sitevision/api/types/javax/jcr/Node").Node[];
|
|
17
|
+
/**
|
|
18
|
+
* Get a string value from app data.
|
|
19
|
+
* @param {string} key - The key of app data to retrieve.
|
|
20
|
+
* @returns {string | undefined} The string value or undefined if not set.
|
|
21
|
+
*/
|
|
22
|
+
function getString(key: string): string | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* Get a boolean value from app data.
|
|
25
|
+
* @param {string} key - The key of app data to retrieve.
|
|
26
|
+
* @returns {boolean | undefined} The boolean value or undefined if not set.
|
|
27
|
+
*/
|
|
28
|
+
function getBoolean(key: string): boolean | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* Get a number value from app data.
|
|
31
|
+
* @param {string} key - The key of app data to retrieve.
|
|
32
|
+
* @returns {number | undefined} The number value, undefined if not set or not a number.
|
|
33
|
+
*/
|
|
34
|
+
function getNumber(key: string): number | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* Get an array of nodes from app data.
|
|
37
|
+
* @param {string} key - The key of app data to retrieve.
|
|
38
|
+
* @returns {import('@sitevision/api/types/javax/jcr/Node').Node[]} The array of nodes or an
|
|
39
|
+
* empty array if not set.
|
|
40
|
+
*/
|
|
41
|
+
function getNodes(key: string): import("@sitevision/api/types/javax/jcr/Node").Node[];
|
|
42
|
+
/**
|
|
43
|
+
* Get an array of strings from app data.
|
|
44
|
+
* @param {string} key - The key of app data to retrieve.
|
|
45
|
+
* @returns {string[]} The array of strings or an empty array if not set.
|
|
46
|
+
*/
|
|
47
|
+
function getStrings(key: string): string[];
|
|
48
|
+
/**
|
|
49
|
+
* Get a JCR Node from app data.
|
|
50
|
+
* @param {string} key - The key of the property to retrieve.
|
|
51
|
+
* @returns {import('@sitevision/api/types/javax/jcr/Node').Node | undefined} The JCR Node or
|
|
52
|
+
* undefined if not set.
|
|
53
|
+
*/
|
|
54
|
+
function getNode(key: string): import("@sitevision/api/types/javax/jcr/Node").Node;
|
|
55
|
+
/**
|
|
56
|
+
* Get a string property from a JCR Node referenced in app data.
|
|
57
|
+
* @param {string} key - The key of the app data value.
|
|
58
|
+
* @param {string} property - The property to retrieve from the node.
|
|
59
|
+
* @returns {string | undefined} The string property value or undefined if not set.
|
|
60
|
+
*/
|
|
61
|
+
function getStringProperty(key: string, property: string): string | undefined;
|
|
62
|
+
/**
|
|
63
|
+
* Get a string array property or a single string wrapped in an array from a JCR Node referenced
|
|
64
|
+
* in app data.
|
|
65
|
+
* @param {string} key - The key of app data to retrieve.
|
|
66
|
+
* @param {string} property - The property to retrieve from the node.
|
|
67
|
+
* @returns {string[]} The array of strings or an empty array if not set.
|
|
68
|
+
*/
|
|
69
|
+
function getStringsProperty(key: string, property: string): string[];
|
|
70
|
+
/**
|
|
71
|
+
* Get a boolean property from a JCR Node referenced in app data.
|
|
72
|
+
* @param {string} key - The key of the app data value.
|
|
73
|
+
* @param {string} property - The property to retrieve from the node.
|
|
74
|
+
* @returns {boolean | undefined} The boolean property value or undefined if not set.
|
|
75
|
+
*/
|
|
76
|
+
function getBooleanProperty(key: string, property: string): boolean | undefined;
|
|
77
|
+
/**
|
|
78
|
+
* Get a number property from a JCR Node referenced in app data.
|
|
79
|
+
* @param {string} key - The key of the app data value.
|
|
80
|
+
* @param {string} property - The property to retrieve from the node.
|
|
81
|
+
* @returns {number | undefined} The number property value, undefined if not set or not a number.
|
|
82
|
+
*/
|
|
83
|
+
function getNumberProperty(key: string, property: string): number | undefined;
|
|
84
|
+
}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import appDataSv from '@sitevision/api/server/globalAppData';
|
|
2
|
+
import InstanceTypeUtil from '@sitevision/api/server/InstanceTypeUtil';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Converts the value returned by appData.get to a string representation.
|
|
6
|
+
* @param {any} value - The value to convert.
|
|
7
|
+
* @returns {string | undefined} - The string representation of the value or undefined if not a
|
|
8
|
+
* string.
|
|
9
|
+
*/
|
|
10
|
+
function toString(value) {
|
|
11
|
+
if (value === null || value === undefined) return undefined;
|
|
12
|
+
return value.toString();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Converts the value returned by appData.get to a boolean representation.
|
|
17
|
+
* @param {any} value - The value to convert.
|
|
18
|
+
* @returns {boolean | undefined} - The boolean representation of the value or undefined if not a
|
|
19
|
+
* boolean.
|
|
20
|
+
*/
|
|
21
|
+
function toBoolean(value) {
|
|
22
|
+
if (value === undefined || value === null) return undefined;
|
|
23
|
+
return !!value;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Converts the value returned by appData.get to a number representation.
|
|
28
|
+
* @param {any} value - The value to convert.
|
|
29
|
+
* @returns {number | undefined} - The number representation of the value or undefined if not a
|
|
30
|
+
* number.
|
|
31
|
+
*/
|
|
32
|
+
function toNumber(value) {
|
|
33
|
+
if (value === undefined || value === null) return undefined;
|
|
34
|
+
const num = +value;
|
|
35
|
+
return Number.isNaN(num) ? undefined : num;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const globalAppData = {
|
|
39
|
+
/**
|
|
40
|
+
* Get a value from app data, same as get in \@sitevision/api/server/appData.
|
|
41
|
+
* @param {string} key - The key of app data to retrieve.
|
|
42
|
+
* @param {...string} [properties] - The keys of the properties to retrieve from a JCR Node.
|
|
43
|
+
* @returns {unknown} The value of the app data or a properties of a JCR Node.
|
|
44
|
+
*/
|
|
45
|
+
get(key, ...properties) {
|
|
46
|
+
return appDataSv.get(key, ...properties);
|
|
47
|
+
},
|
|
48
|
+
/**
|
|
49
|
+
* Get a value from app data as an array, same as getArray in \@sitevision/api/server/appData.
|
|
50
|
+
* @param {string} key - The key of app data to retrieve.
|
|
51
|
+
* @returns {import('@sitevision/api/types/javax/jcr/Node').Node[] | string[]} An array of JCR
|
|
52
|
+
* Nodes for list components or value wrapped in an array for single type components.
|
|
53
|
+
*/
|
|
54
|
+
getArray(key) {
|
|
55
|
+
return appDataSv.getArray(key);
|
|
56
|
+
},
|
|
57
|
+
/**
|
|
58
|
+
* Get a string value from app data.
|
|
59
|
+
* @param {string} key - The key of app data to retrieve.
|
|
60
|
+
* @returns {string | undefined} The string value or undefined if not set.
|
|
61
|
+
*/
|
|
62
|
+
getString(key) {
|
|
63
|
+
return toString(appDataSv.get(key));
|
|
64
|
+
},
|
|
65
|
+
/**
|
|
66
|
+
* Get a boolean value from app data.
|
|
67
|
+
* @param {string} key - The key of app data to retrieve.
|
|
68
|
+
* @returns {boolean | undefined} The boolean value or undefined if not set.
|
|
69
|
+
*/
|
|
70
|
+
getBoolean(key) {
|
|
71
|
+
return toBoolean(appDataSv.get(key));
|
|
72
|
+
},
|
|
73
|
+
/**
|
|
74
|
+
* Get a number value from app data.
|
|
75
|
+
* @param {string} key - The key of app data to retrieve.
|
|
76
|
+
* @returns {number | undefined} The number value, undefined if not set or not a number.
|
|
77
|
+
*/
|
|
78
|
+
getNumber(key) {
|
|
79
|
+
return toNumber(appDataSv.get(key));
|
|
80
|
+
},
|
|
81
|
+
/**
|
|
82
|
+
* Get an array of nodes from app data.
|
|
83
|
+
* @param {string} key - The key of app data to retrieve.
|
|
84
|
+
* @returns {import('@sitevision/api/types/javax/jcr/Node').Node[]} The array of nodes or an
|
|
85
|
+
* empty array if not set.
|
|
86
|
+
*/
|
|
87
|
+
getNodes(key) {
|
|
88
|
+
return appDataSv.getArray(key)?.filter((v) => InstanceTypeUtil.isNode(v)) || [];
|
|
89
|
+
},
|
|
90
|
+
/**
|
|
91
|
+
* Get an array of strings from app data.
|
|
92
|
+
* @param {string} key - The key of app data to retrieve.
|
|
93
|
+
* @returns {string[]} The array of strings or an empty array if not set.
|
|
94
|
+
*/
|
|
95
|
+
getStrings(key) {
|
|
96
|
+
return appDataSv.getArray(key)
|
|
97
|
+
?.map((v) => toString(v))
|
|
98
|
+
?.filter((v) => v !== undefined) || [];
|
|
99
|
+
},
|
|
100
|
+
/**
|
|
101
|
+
* Get a JCR Node from app data.
|
|
102
|
+
* @param {string} key - The key of the property to retrieve.
|
|
103
|
+
* @returns {import('@sitevision/api/types/javax/jcr/Node').Node | undefined} The JCR Node or
|
|
104
|
+
* undefined if not set.
|
|
105
|
+
*/
|
|
106
|
+
getNode(key) {
|
|
107
|
+
return appDataSv.getNode(key) ?? undefined;
|
|
108
|
+
},
|
|
109
|
+
/**
|
|
110
|
+
* Get a string property from a JCR Node referenced in app data.
|
|
111
|
+
* @param {string} key - The key of the app data value.
|
|
112
|
+
* @param {string} property - The property to retrieve from the node.
|
|
113
|
+
* @returns {string | undefined} The string property value or undefined if not set.
|
|
114
|
+
*/
|
|
115
|
+
getStringProperty(key, property) {
|
|
116
|
+
return toString(appDataSv.get(key, property));
|
|
117
|
+
},
|
|
118
|
+
/**
|
|
119
|
+
* Get a string array property or a single string wrapped in an array from a JCR Node referenced
|
|
120
|
+
* in app data.
|
|
121
|
+
* @param {string} key - The key of app data to retrieve.
|
|
122
|
+
* @param {string} property - The property to retrieve from the node.
|
|
123
|
+
* @returns {string[]} The array of strings or an empty array if not set.
|
|
124
|
+
*/
|
|
125
|
+
getStringsProperty(key, property) {
|
|
126
|
+
let value = appDataSv.get(key, property);
|
|
127
|
+
if (Array.isArray(value)) {
|
|
128
|
+
return value
|
|
129
|
+
?.map((v) => toString(v))
|
|
130
|
+
?.filter((v) => v !== undefined) || [];
|
|
131
|
+
}
|
|
132
|
+
value = toString(value);
|
|
133
|
+
return value ? [value] : [];
|
|
134
|
+
},
|
|
135
|
+
/**
|
|
136
|
+
* Get a boolean property from a JCR Node referenced in app data.
|
|
137
|
+
* @param {string} key - The key of the app data value.
|
|
138
|
+
* @param {string} property - The property to retrieve from the node.
|
|
139
|
+
* @returns {boolean | undefined} The boolean property value or undefined if not set.
|
|
140
|
+
*/
|
|
141
|
+
getBooleanProperty(key, property) {
|
|
142
|
+
return toBoolean(appDataSv.get(key, property));
|
|
143
|
+
},
|
|
144
|
+
/**
|
|
145
|
+
* Get a number property from a JCR Node referenced in app data.
|
|
146
|
+
* @param {string} key - The key of the app data value.
|
|
147
|
+
* @param {string} property - The property to retrieve from the node.
|
|
148
|
+
* @returns {number | undefined} The number property value, undefined if not set or not a number.
|
|
149
|
+
*/
|
|
150
|
+
getNumberProperty(key, property) {
|
|
151
|
+
return toNumber(appDataSv.get(key, property));
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
export default globalAppData;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/** @typedef {import('svelte').SvelteComponent} Component */
|
|
2
2
|
/**
|
|
3
3
|
* Returns HTML for a server rendered Svelte app.
|
|
4
|
-
* @param {Component} App Svelte component that is root of app.
|
|
5
|
-
* @param {
|
|
4
|
+
* @param {Component<any>} App Svelte component that is root of app.
|
|
5
|
+
* @param {Record<string, any>} props Props passed to root component.
|
|
6
6
|
* @return {string} HTML for the server rendered app.
|
|
7
7
|
*/
|
|
8
|
-
export function render(App:
|
|
8
|
+
export function render(App: any, props: Record<string, any>): string;
|
|
9
9
|
export type Component = import('svelte').SvelteComponent;
|
package/server/svelte/4/index.js
CHANGED
|
@@ -2,8 +2,8 @@ import { setAppProps } from '../../../common';
|
|
|
2
2
|
/** @typedef {import('svelte').SvelteComponent} Component */
|
|
3
3
|
/**
|
|
4
4
|
* Returns HTML for a server rendered Svelte app.
|
|
5
|
-
* @param {Component} App Svelte component that is root of app.
|
|
6
|
-
* @param {
|
|
5
|
+
* @param {Component<any>} App Svelte component that is root of app.
|
|
6
|
+
* @param {Record<string, any>} props Props passed to root component.
|
|
7
7
|
* @return {string} HTML for the server rendered app.
|
|
8
8
|
*/
|
|
9
9
|
export function render(App, props) {
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
/** @typedef {import('svelte').Component} Component */
|
|
2
1
|
/**
|
|
3
2
|
* Returns HTML for a server rendered Svelte app.
|
|
4
|
-
* @param {Component} App Svelte component that is root of app.
|
|
5
|
-
* @param {
|
|
3
|
+
* @param {import('svelte').Component<any>} App Svelte component that is root of app.
|
|
4
|
+
* @param {Record<string, any>} props Props passed to root component.
|
|
6
5
|
* @return {string} HTML for the server rendered app.
|
|
7
6
|
*/
|
|
8
|
-
export function render(App: Component
|
|
9
|
-
export type Component = import('svelte').Component;
|
|
7
|
+
export function render(App: import('svelte').Component<any>, props: Record<string, any>): string;
|
package/server/svelte/5/index.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { render as svelteRender } from 'svelte/server';
|
|
2
2
|
import { appId, setAppProps } from '../../../common';
|
|
3
3
|
|
|
4
|
-
/** @typedef {import('svelte').Component} Component */
|
|
5
4
|
/**
|
|
6
5
|
* Returns HTML for a server rendered Svelte app.
|
|
7
|
-
* @param {Component} App Svelte component that is root of app.
|
|
8
|
-
* @param {
|
|
6
|
+
* @param {import('svelte').Component<any>} App Svelte component that is root of app.
|
|
7
|
+
* @param {Record<string, any>} props Props passed to root component.
|
|
9
8
|
* @return {string} HTML for the server rendered app.
|
|
10
9
|
*/
|
|
11
10
|
export function render(App, props) {
|
package/server/svelte/index.d.ts
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* Returns HTML for a server rendered Svelte 3 or 4 app.
|
|
3
3
|
* @deprecated Use rendering function for specific Svelte version instead.
|
|
4
4
|
* `import { render } from '@soleil-api/webapp-util/server/svelte/{3|4|5}';`
|
|
5
|
-
* @param {import('svelte').SvelteComponent} App Svelte component that is root of app.
|
|
5
|
+
* @param {import('svelte').SvelteComponent<any>} App Svelte component that is root of app.
|
|
6
6
|
* @param {object} props Props passed to root component.
|
|
7
7
|
* @return {string} HTML for the server rendered app.
|
|
8
8
|
*/
|
|
9
|
-
export function render(App: import('svelte').SvelteComponent
|
|
9
|
+
export function render(App: import('svelte').SvelteComponent<any>, props: object): string;
|
package/server/svelte/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import { render as render4 } from './4';
|
|
|
4
4
|
* Returns HTML for a server rendered Svelte 3 or 4 app.
|
|
5
5
|
* @deprecated Use rendering function for specific Svelte version instead.
|
|
6
6
|
* `import { render } from '@soleil-api/webapp-util/server/svelte/{3|4|5}';`
|
|
7
|
-
* @param {import('svelte').SvelteComponent} App Svelte component that is root of app.
|
|
7
|
+
* @param {import('svelte').SvelteComponent<any>} App Svelte component that is root of app.
|
|
8
8
|
* @param {object} props Props passed to root component.
|
|
9
9
|
* @return {string} HTML for the server rendered app.
|
|
10
10
|
*/
|