@appsemble/utils 0.20.38 → 0.20.40
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 +4 -4
- package/api/components/schemas/ActionDefinition.js +1 -0
- package/api/components/schemas/ArrayRemapperDefinition.d.ts +2 -0
- package/api/components/schemas/ArrayRemapperDefinition.js +22 -0
- package/api/components/schemas/MatchActionDefinition.d.ts +1 -0
- package/api/components/schemas/MatchActionDefinition.js +35 -0
- package/api/components/schemas/MessageActionDefinition.js +5 -0
- package/api/components/schemas/RemapperDefinition.js +1 -8
- package/api/components/schemas/ResourceUpdateActionDefinition.js +1 -1
- package/api/components/schemas/index.d.ts +2 -0
- package/api/components/schemas/index.js +2 -0
- package/appMessages.js +4 -2
- package/iterApp.js +6 -1
- package/package.json +3 -3
- package/remap.js +4 -1
- package/remap.test.js +9 -0
package/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
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.20.40)
|
|
7
|
+
[](https://codecov.io/gl/appsemble/appsemble)
|
|
8
8
|
[](https://prettier.io)
|
|
9
9
|
|
|
10
10
|
## Installation
|
|
@@ -21,5 +21,5 @@ not guaranteed.
|
|
|
21
21
|
|
|
22
22
|
## License
|
|
23
23
|
|
|
24
|
-
[LGPL-3.0-only](https://gitlab.com/appsemble/appsemble/-/blob/0.20.
|
|
24
|
+
[LGPL-3.0-only](https://gitlab.com/appsemble/appsemble/-/blob/0.20.40/LICENSE.md) ©
|
|
25
25
|
[Appsemble](https://appsemble.com)
|
|
@@ -42,6 +42,7 @@ export const ActionDefinition = {
|
|
|
42
42
|
{ $ref: '#/components/schemas/LinkBackActionDefinition' },
|
|
43
43
|
{ $ref: '#/components/schemas/LinkNextActionDefinition' },
|
|
44
44
|
{ $ref: '#/components/schemas/LogActionDefinition' },
|
|
45
|
+
{ $ref: '#/components/schemas/MatchActionDefinition' },
|
|
45
46
|
{ $ref: '#/components/schemas/MessageActionDefinition' },
|
|
46
47
|
{ $ref: '#/components/schemas/NoopActionDefinition' },
|
|
47
48
|
{ $ref: '#/components/schemas/NotifyActionDefinition' },
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export const ArrayRemapperDefinition = {
|
|
2
|
+
type: 'array',
|
|
3
|
+
description: `If a remapper is an array, it represents a chain of remappers.
|
|
4
|
+
|
|
5
|
+
Each item represents a remapper which is called with the result of the remapper before it.
|
|
6
|
+
|
|
7
|
+
If an array is nested, it will be flattened. This allows you to create reusable remappers and
|
|
8
|
+
reference them using YAML anchors.
|
|
9
|
+
`,
|
|
10
|
+
minItems: 1,
|
|
11
|
+
items: {
|
|
12
|
+
anyOf: [
|
|
13
|
+
{
|
|
14
|
+
$ref: '#/components/schemas/ObjectRemapperDefinition',
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
$ref: '#/components/schemas/ArrayRemapperDefinition',
|
|
18
|
+
},
|
|
19
|
+
],
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=ArrayRemapperDefinition.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const MatchActionDefinition: import("openapi-types").OpenAPIV3.SchemaObject;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { BaseActionDefinition } from './BaseActionDefinition.js';
|
|
2
|
+
import { extendJSONSchema } from './utils.js';
|
|
3
|
+
export const MatchActionDefinition = extendJSONSchema(BaseActionDefinition, {
|
|
4
|
+
type: 'object',
|
|
5
|
+
additionalProperties: false,
|
|
6
|
+
required: ['type', 'match'],
|
|
7
|
+
properties: {
|
|
8
|
+
type: {
|
|
9
|
+
enum: ['match'],
|
|
10
|
+
description: `Run another action if one of the cases is true.
|
|
11
|
+
|
|
12
|
+
Only the first case that equals true is called.`,
|
|
13
|
+
},
|
|
14
|
+
match: {
|
|
15
|
+
type: 'array',
|
|
16
|
+
items: {
|
|
17
|
+
type: 'object',
|
|
18
|
+
additionalProperties: false,
|
|
19
|
+
required: ['case', 'action'],
|
|
20
|
+
description: '',
|
|
21
|
+
properties: {
|
|
22
|
+
case: {
|
|
23
|
+
$ref: '#/components/schemas/RemapperDefinition',
|
|
24
|
+
description: 'The case to be matched.',
|
|
25
|
+
},
|
|
26
|
+
action: {
|
|
27
|
+
$ref: '#/components/schemas/ActionDefinition',
|
|
28
|
+
description: 'Action to be called if the case equals true.',
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
//# sourceMappingURL=MatchActionDefinition.js.map
|
|
@@ -21,6 +21,11 @@ This is useful in combination with action chaining to notify users they have per
|
|
|
21
21
|
default: 'info',
|
|
22
22
|
description: 'The Bulma color to apply to the message.',
|
|
23
23
|
},
|
|
24
|
+
layout: {
|
|
25
|
+
enum: ['bottom', 'top'],
|
|
26
|
+
default: 'bottom',
|
|
27
|
+
description: 'The position of the message on the screen.',
|
|
28
|
+
},
|
|
24
29
|
dismissable: {
|
|
25
30
|
type: 'boolean',
|
|
26
31
|
description: 'Boolean value indicating whether the user is able to dismiss the message manually.',
|
|
@@ -20,14 +20,7 @@ export const RemapperDefinition = {
|
|
|
20
20
|
$ref: '#/components/schemas/ObjectRemapperDefinition',
|
|
21
21
|
},
|
|
22
22
|
{
|
|
23
|
-
|
|
24
|
-
description: `If a remapper is an array, it represents a chain of remappers.
|
|
25
|
-
|
|
26
|
-
Each item represents a remapper which is called with the result of the remapper before it.
|
|
27
|
-
`,
|
|
28
|
-
items: {
|
|
29
|
-
$ref: '#/components/schemas/ObjectRemapperDefinition',
|
|
30
|
-
},
|
|
23
|
+
$ref: '#/components/schemas/ArrayRemapperDefinition',
|
|
31
24
|
},
|
|
32
25
|
],
|
|
33
26
|
};
|
|
@@ -7,6 +7,7 @@ export * from './AppLayoutDefinition.js';
|
|
|
7
7
|
export * from './AppMessages.js';
|
|
8
8
|
export * from './AppOAuth2Secret.js';
|
|
9
9
|
export * from './AppsembleMessages.js';
|
|
10
|
+
export * from './ArrayRemapperDefinition.js';
|
|
10
11
|
export * from './Asset.js';
|
|
11
12
|
export * from './BlockDefinition.js';
|
|
12
13
|
export * from './BlockVersion.js';
|
|
@@ -52,6 +53,7 @@ export * from './LinkBackActionDefinition.js';
|
|
|
52
53
|
export * from './LinkNextActionDefinition.js';
|
|
53
54
|
export * from './LogActionDefinition.js';
|
|
54
55
|
export * from './Member.js';
|
|
56
|
+
export * from './MatchActionDefinition.js';
|
|
55
57
|
export * from './MessageActionDefinition.js';
|
|
56
58
|
export * from './NoopActionDefinition.js';
|
|
57
59
|
export * from './NotificationHookDataDefinition.js';
|
|
@@ -7,6 +7,7 @@ export * from './AppLayoutDefinition.js';
|
|
|
7
7
|
export * from './AppMessages.js';
|
|
8
8
|
export * from './AppOAuth2Secret.js';
|
|
9
9
|
export * from './AppsembleMessages.js';
|
|
10
|
+
export * from './ArrayRemapperDefinition.js';
|
|
10
11
|
export * from './Asset.js';
|
|
11
12
|
export * from './BlockDefinition.js';
|
|
12
13
|
export * from './BlockVersion.js';
|
|
@@ -52,6 +53,7 @@ export * from './LinkBackActionDefinition.js';
|
|
|
52
53
|
export * from './LinkNextActionDefinition.js';
|
|
53
54
|
export * from './LogActionDefinition.js';
|
|
54
55
|
export * from './Member.js';
|
|
56
|
+
export * from './MatchActionDefinition.js';
|
|
55
57
|
export * from './MessageActionDefinition.js';
|
|
56
58
|
export * from './NoopActionDefinition.js';
|
|
57
59
|
export * from './NotificationHookDataDefinition.js';
|
package/appMessages.js
CHANGED
|
@@ -90,7 +90,7 @@ export function extractAppMessages(app, onBlock) {
|
|
|
90
90
|
}
|
|
91
91
|
},
|
|
92
92
|
onPage(page) {
|
|
93
|
-
var _a, _b
|
|
93
|
+
var _a, _b;
|
|
94
94
|
const prefix = `pages.${normalize(page.name)}`;
|
|
95
95
|
messages.app[prefix] = page.name;
|
|
96
96
|
if (page.type === 'tabs') {
|
|
@@ -104,7 +104,9 @@ export function extractAppMessages(app, onBlock) {
|
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
106
|
if (page.type === 'loop') {
|
|
107
|
-
messages.app[`${prefix}.
|
|
107
|
+
messages.app[`${prefix}.steps.first`] = 'first';
|
|
108
|
+
messages.app[`${prefix}.steps`] = 'step';
|
|
109
|
+
messages.app[`${prefix}.steps.last`] = 'last';
|
|
108
110
|
}
|
|
109
111
|
},
|
|
110
112
|
});
|
package/iterApp.js
CHANGED
|
@@ -95,7 +95,12 @@ export function iterPage(page, callbacks, prefix = []) {
|
|
|
95
95
|
: page.tabs.some((tab, index) => iterBlockList(tab.blocks, callbacks, [...prefix, 'tabs', index, 'blocks']))));
|
|
96
96
|
}
|
|
97
97
|
if (page.type === 'loop') {
|
|
98
|
-
|
|
98
|
+
let result = false;
|
|
99
|
+
if ('actions' in page) {
|
|
100
|
+
result = Object.entries(page.actions).some(([key, action]) => iterAction(action, callbacks, [...prefix, 'actions', key]));
|
|
101
|
+
}
|
|
102
|
+
return (result ||
|
|
103
|
+
['steps.first', 'steps', 'steps.last'].some((suffix) => iterBlockList(page.foreach.blocks, callbacks, [...prefix, suffix, 'blocks'])));
|
|
99
104
|
}
|
|
100
105
|
return iterBlockList(page.blocks, callbacks, [...prefix, 'blocks']);
|
|
101
106
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@appsemble/utils",
|
|
3
|
-
"version": "0.20.
|
|
3
|
+
"version": "0.20.40",
|
|
4
4
|
"description": "Utility functions used in Appsemble internally",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"app",
|
|
@@ -31,12 +31,12 @@
|
|
|
31
31
|
"test": "NODE_OPTIONS=--experimental-vm-modules jest"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@appsemble/types": "0.20.
|
|
34
|
+
"@appsemble/types": "0.20.40",
|
|
35
35
|
"axios": "^1.0.0",
|
|
36
36
|
"cron-parser": "^4.0.0",
|
|
37
37
|
"date-fns": "^2.0.0",
|
|
38
38
|
"fast-deep-equal": "^3.0.0",
|
|
39
|
-
"ics": "^
|
|
39
|
+
"ics": "^3.0.0",
|
|
40
40
|
"intl-messageformat": "^10.0.0",
|
|
41
41
|
"jsonschema": "^1.0.0",
|
|
42
42
|
"langmap": "^0.0.16",
|
package/remap.js
CHANGED
|
@@ -21,7 +21,10 @@ export function remap(remapper, input, context) {
|
|
|
21
21
|
return remapper;
|
|
22
22
|
}
|
|
23
23
|
let result = input;
|
|
24
|
-
|
|
24
|
+
// Workaround for ts(2589) Type instantiation is excessively deep and possibly infinite
|
|
25
|
+
const remappers = Array.isArray(remapper)
|
|
26
|
+
? remapper.flat(Number.POSITIVE_INFINITY)
|
|
27
|
+
: [remapper];
|
|
25
28
|
for (const mapper of remappers) {
|
|
26
29
|
const entries = Object.entries(mapper);
|
|
27
30
|
if (entries.length !== 1) {
|
package/remap.test.js
CHANGED
|
@@ -35,6 +35,15 @@ describe('Primitive values', () => {
|
|
|
35
35
|
},
|
|
36
36
|
});
|
|
37
37
|
});
|
|
38
|
+
describe('Nested arrays', () => {
|
|
39
|
+
runTests({
|
|
40
|
+
'flatten remappers': {
|
|
41
|
+
input: { value: 123 },
|
|
42
|
+
mappers: [[[[[{ prop: 'value' }]]]]],
|
|
43
|
+
expected: 123,
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
});
|
|
38
47
|
describe('app', () => {
|
|
39
48
|
runTests({
|
|
40
49
|
'return the app id': {
|