@appsemble/utils 0.29.8 → 0.29.9
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/api/paths/assets.js +10 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +2 -2
- package/validateAppMessages.d.ts +5 -0
- package/validateAppMessages.js +71 -0
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.29.9)
|
|
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.
|
|
29
|
+
[LGPL-3.0-only](https://gitlab.com/appsemble/appsemble/-/blob/0.29.9/LICENSE.md) ©
|
|
30
30
|
[Appsemble](https://appsemble.com)
|
package/api/paths/assets.js
CHANGED
|
@@ -187,6 +187,16 @@ export const paths = {
|
|
|
187
187
|
},
|
|
188
188
|
},
|
|
189
189
|
},
|
|
190
|
+
head: {
|
|
191
|
+
tags: ['asset'],
|
|
192
|
+
description: 'Get the headers for a single asset',
|
|
193
|
+
operationId: 'getAssetHeadersById',
|
|
194
|
+
responses: {
|
|
195
|
+
200: {
|
|
196
|
+
description: 'The asset that matches the given id.',
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
},
|
|
190
200
|
delete: {
|
|
191
201
|
tags: ['asset'],
|
|
192
202
|
description: 'Remove an existing asset',
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@appsemble/utils",
|
|
3
|
-
"version": "0.29.
|
|
3
|
+
"version": "0.29.9",
|
|
4
4
|
"description": "Utility functions used in Appsemble internally",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"app",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"test": "vitest"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@appsemble/types": "0.29.
|
|
40
|
+
"@appsemble/types": "0.29.9",
|
|
41
41
|
"axios": "^1.0.0",
|
|
42
42
|
"cron-parser": "^4.0.0",
|
|
43
43
|
"date-fns": "^2.0.0",
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type AppDefinition, type AppsembleMessages } from '@appsemble/types';
|
|
2
|
+
export declare class AppMessageValidationError extends Error {
|
|
3
|
+
constructor(message: string);
|
|
4
|
+
}
|
|
5
|
+
export declare function validateMessages(messages: AppsembleMessages, app: AppDefinition): void;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { extractAppMessages } from './appMessages.js';
|
|
2
|
+
import { normalizeBlockName } from './blockUtils.js';
|
|
3
|
+
import { has } from './has.js';
|
|
4
|
+
export class AppMessageValidationError extends Error {
|
|
5
|
+
constructor(message) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = 'AppMessageValidationError';
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export function validateMessages(messages, app) {
|
|
11
|
+
var _a, _b;
|
|
12
|
+
const blockMessageKeys = {};
|
|
13
|
+
const extractedMessages = extractAppMessages(app, (block) => {
|
|
14
|
+
const type = normalizeBlockName(block.type);
|
|
15
|
+
if (blockMessageKeys[type]) {
|
|
16
|
+
blockMessageKeys[type][block.version] = {};
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
blockMessageKeys[type] = {
|
|
20
|
+
[block.version]: {},
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
if (messages.messageIds) {
|
|
25
|
+
Object.keys(messages.messageIds).map((key) => {
|
|
26
|
+
if (typeof messages.messageIds[key] !== 'string') {
|
|
27
|
+
throw new AppMessageValidationError(`Not allowed to have non-string message ${messages.messageIds[key]}`);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
if (messages.app) {
|
|
32
|
+
Object.keys(messages.app).map((key) => {
|
|
33
|
+
const match = /^(pages\.[\dA-Za-z-]+(\..+)?)\.blocks\.\d+.+/.exec(key);
|
|
34
|
+
if ((!has(extractedMessages === null || extractedMessages === void 0 ? void 0 : extractedMessages.app, key) || typeof messages.app[key] !== 'string') && !match) {
|
|
35
|
+
throw new AppMessageValidationError(`Invalid key ${key}`);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
const blockMessages = {};
|
|
40
|
+
if (messages.blocks) {
|
|
41
|
+
for (const key of Object.keys(messages.blocks)) {
|
|
42
|
+
if (!has(blockMessageKeys, key)) {
|
|
43
|
+
throw new AppMessageValidationError(`Invalid translation key: blocks.${key}\nThis block is not used in the app`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const coreMessages = (_a = messages.core) !== null && _a !== void 0 ? _a : {};
|
|
48
|
+
for (const [key, value] of Object.entries(coreMessages)) {
|
|
49
|
+
if (!value || typeof value !== 'string') {
|
|
50
|
+
throw new AppMessageValidationError(`Invalid translation key: core.${key}`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
for (const [blockName] of Object.entries(blockMessageKeys)) {
|
|
54
|
+
if ((_b = messages.blocks) === null || _b === void 0 ? void 0 : _b[blockName]) {
|
|
55
|
+
blockMessages[blockName] = {};
|
|
56
|
+
for (const [version, oldValues] of Object.entries(messages.blocks[blockName])) {
|
|
57
|
+
if (!has(blockMessageKeys[blockName], version)) {
|
|
58
|
+
throw new AppMessageValidationError(`Invalid translation key: blocks.${blockName}.${version}
|
|
59
|
+
This block version is not used in the app`);
|
|
60
|
+
}
|
|
61
|
+
for (const [oldValueKey, oldValue] of Object.entries(messages.blocks[blockName][version])) {
|
|
62
|
+
if (typeof oldValue !== 'string') {
|
|
63
|
+
throw new AppMessageValidationError(`Invalid translation key: blocks.${blockName}.${version}.${oldValueKey}`);
|
|
64
|
+
}
|
|
65
|
+
blockMessages[blockName][version] = oldValues;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=validateAppMessages.js.map
|