@appsemble/utils 0.37.5 → 0.38.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/README.md +3 -3
- package/appMessages.js +5 -2
- package/package.json +4 -4
- package/serializeResource.d.ts +2 -1
- package/serializeResource.js +11 -6
package/README.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
#  Appsemble Utilities
|
|
2
2
|
|
|
3
3
|
> Internal utility functions used across multiple Appsemble projects.
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/@appsemble/utils)
|
|
6
|
-
[](https://gitlab.com/appsemble/appsemble/-/releases/0.38.0)
|
|
7
7
|
[](https://prettier.io)
|
|
8
8
|
|
|
9
9
|
## Table of Contents
|
|
@@ -26,5 +26,5 @@ not guaranteed.
|
|
|
26
26
|
|
|
27
27
|
## License
|
|
28
28
|
|
|
29
|
-
[LGPL-3.0-only](https://gitlab.com/appsemble/appsemble/-/blob/0.
|
|
29
|
+
[LGPL-3.0-only](https://gitlab.com/appsemble/appsemble/-/blob/0.38.0/LICENSE.md) ©
|
|
30
30
|
[Appsemble](https://appsemble.com)
|
package/appMessages.js
CHANGED
|
@@ -106,9 +106,12 @@ export function extractAppMessages(app, onBlock) {
|
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
108
|
if (page.type === 'loop') {
|
|
109
|
-
messages.
|
|
109
|
+
Object.assign(messages.messageIds, findMessageIds(page.start?.name), findMessageIds(page.end?.name));
|
|
110
|
+
messages.app[`${prefix}.steps.first`] =
|
|
111
|
+
(typeof page.start?.name === 'string' ? page.start.name : '') || 'first';
|
|
110
112
|
messages.app[`${prefix}.steps`] = 'step';
|
|
111
|
-
messages.app[`${prefix}.steps.last`] =
|
|
113
|
+
messages.app[`${prefix}.steps.last`] =
|
|
114
|
+
(typeof page.end?.name === 'string' ? page.end.name : '') || 'last';
|
|
112
115
|
}
|
|
113
116
|
},
|
|
114
117
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@appsemble/utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.38.0",
|
|
4
4
|
"description": "Utility functions used in Appsemble internally",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"app",
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
"test": "vitest"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@appsemble/lang-sdk": "0.
|
|
43
|
-
"@appsemble/types": "0.
|
|
42
|
+
"@appsemble/lang-sdk": "0.38.0",
|
|
43
|
+
"@appsemble/types": "0.38.0",
|
|
44
44
|
"@fortawesome/fontawesome-common-types": "^6.0.0",
|
|
45
45
|
"axios": "^1.0.0",
|
|
46
46
|
"langmap": "^0.0.16",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"@types/langmap": "0.0.3",
|
|
53
53
|
"bulma": "=0.9.4",
|
|
54
54
|
"koas-core": "0.7.0",
|
|
55
|
-
"vitest": "
|
|
55
|
+
"vitest": "4.1.11"
|
|
56
56
|
},
|
|
57
57
|
"engines": {
|
|
58
58
|
"node": ">=24"
|
package/serializeResource.d.ts
CHANGED
|
@@ -3,8 +3,9 @@ import { type JsonValue } from 'type-fest';
|
|
|
3
3
|
* Works on a resource on the client, for example passed from the form block
|
|
4
4
|
*
|
|
5
5
|
* @param data The resource to be serialized, optionally containing asset blobs
|
|
6
|
+
* @param onAsset Called with the index and resource path of each serialized asset
|
|
6
7
|
* @returns A FormData instance containing the resource and an array of the assets
|
|
7
8
|
* referenced from the resource
|
|
8
9
|
*/
|
|
9
|
-
export declare function serializeResource(data: any): FormData | JsonValue;
|
|
10
|
+
export declare function serializeResource(data: any, onAsset?: (index: number, path: (number | string)[]) => void): FormData | JsonValue;
|
|
10
11
|
export declare function deserializeResource(data: any, schema?: unknown): any;
|
package/serializeResource.js
CHANGED
|
@@ -1,25 +1,30 @@
|
|
|
1
|
-
import { mapValues } from './mapValues.js';
|
|
2
1
|
/**
|
|
3
2
|
* Works on a resource on the client, for example passed from the form block
|
|
4
3
|
*
|
|
5
4
|
* @param data The resource to be serialized, optionally containing asset blobs
|
|
5
|
+
* @param onAsset Called with the index and resource path of each serialized asset
|
|
6
6
|
* @returns A FormData instance containing the resource and an array of the assets
|
|
7
7
|
* referenced from the resource
|
|
8
8
|
*/
|
|
9
|
-
export function serializeResource(data) {
|
|
9
|
+
export function serializeResource(data, onAsset) {
|
|
10
10
|
const assets = [];
|
|
11
|
-
const extractAssets = (value) => {
|
|
11
|
+
const extractAssets = (value, path = []) => {
|
|
12
12
|
if (Array.isArray(value)) {
|
|
13
|
-
return value.map(extractAssets);
|
|
13
|
+
return value.map((item, index) => extractAssets(item, [...path, index]));
|
|
14
14
|
}
|
|
15
15
|
if (value instanceof Blob) {
|
|
16
|
-
|
|
16
|
+
const index = assets.push(value) - 1;
|
|
17
|
+
onAsset?.(index, path);
|
|
18
|
+
return String(index);
|
|
17
19
|
}
|
|
18
20
|
if (value instanceof Date) {
|
|
19
21
|
return value.toJSON();
|
|
20
22
|
}
|
|
21
23
|
if (value && typeof value === 'object') {
|
|
22
|
-
return
|
|
24
|
+
return Object.fromEntries(Object.entries(value).map(([key, item]) => [
|
|
25
|
+
key,
|
|
26
|
+
extractAssets(item, [...path, key]),
|
|
27
|
+
]));
|
|
23
28
|
}
|
|
24
29
|
return value;
|
|
25
30
|
};
|