@appsemble/utils 0.28.0 → 0.28.3
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/components/schemas/App.js +2 -1
- package/api/paths/apps.js +1 -0
- package/examples.js +6 -0
- package/package.json +2 -2
- package/reference-schemas/remappers/data.js +2 -2
- package/remap.d.ts +1 -0
- package/remap.js +7 -4
- package/remap.test.js +7 -5
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.28.3)
|
|
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.28.
|
|
29
|
+
[LGPL-3.0-only](https://gitlab.com/appsemble/appsemble/-/blob/0.28.3/LICENSE.md) ©
|
|
30
30
|
[Appsemble](https://appsemble.com)
|
|
@@ -19,7 +19,8 @@ This value will be generated automatically by the API.
|
|
|
19
19
|
path: {
|
|
20
20
|
type: 'string',
|
|
21
21
|
minLength: 1,
|
|
22
|
-
|
|
22
|
+
// Max app name size + appended random data by [`setAppPath`](./packages/server/utils/app.ts)
|
|
23
|
+
maxLength: 41,
|
|
23
24
|
pattern: normalized.source,
|
|
24
25
|
description: `The URL path segment on which this app is reachable.
|
|
25
26
|
|
package/api/paths/apps.js
CHANGED
package/examples.js
CHANGED
|
@@ -44,6 +44,9 @@ export const examples = {
|
|
|
44
44
|
length: {
|
|
45
45
|
array: 'length',
|
|
46
46
|
},
|
|
47
|
+
item: {
|
|
48
|
+
array: 'item',
|
|
49
|
+
},
|
|
47
50
|
},
|
|
48
51
|
},
|
|
49
52
|
},
|
|
@@ -51,14 +54,17 @@ export const examples = {
|
|
|
51
54
|
{
|
|
52
55
|
index: 0,
|
|
53
56
|
length: 3,
|
|
57
|
+
item: 'a',
|
|
54
58
|
},
|
|
55
59
|
{
|
|
56
60
|
index: 1,
|
|
57
61
|
length: 3,
|
|
62
|
+
item: 'b',
|
|
58
63
|
},
|
|
59
64
|
{
|
|
60
65
|
index: 2,
|
|
61
66
|
length: 3,
|
|
67
|
+
item: 'c',
|
|
62
68
|
},
|
|
63
69
|
],
|
|
64
70
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@appsemble/utils",
|
|
3
|
-
"version": "0.28.
|
|
3
|
+
"version": "0.28.3",
|
|
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.28.
|
|
40
|
+
"@appsemble/types": "0.28.3",
|
|
41
41
|
"axios": "^1.0.0",
|
|
42
42
|
"cron-parser": "^4.0.0",
|
|
43
43
|
"date-fns": "^2.0.0",
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { schemaExample } from '../../examples.js';
|
|
2
2
|
export const dataRemappers = {
|
|
3
3
|
array: {
|
|
4
|
-
enum: ['index', 'length'],
|
|
5
|
-
description: `Get the current array.map’s index or
|
|
4
|
+
enum: ['index', 'length', 'item'],
|
|
5
|
+
description: `Get the current array.map’s index, length or the current item.
|
|
6
6
|
|
|
7
7
|
Returns nothing when not in the context of \`array.map’s\`.
|
|
8
8
|
|
package/remap.d.ts
CHANGED
package/remap.js
CHANGED
|
@@ -195,16 +195,19 @@ const mapperImplementations = {
|
|
|
195
195
|
var _a;
|
|
196
196
|
return (_a = input === null || input === void 0 ? void 0 : input.map((item, index) => remap(mapper, item, {
|
|
197
197
|
...context,
|
|
198
|
-
array: { index, length: input.length },
|
|
198
|
+
array: { index, length: input.length, item },
|
|
199
199
|
}))) !== null && _a !== void 0 ? _a : [];
|
|
200
200
|
},
|
|
201
201
|
'array.unique'(mapper, input, context) {
|
|
202
202
|
if (!Array.isArray(input)) {
|
|
203
203
|
return input;
|
|
204
204
|
}
|
|
205
|
-
const remapped = input.map((
|
|
206
|
-
?
|
|
207
|
-
: remap(mapper,
|
|
205
|
+
const remapped = input.map((item, index) => mapper == null
|
|
206
|
+
? item
|
|
207
|
+
: remap(mapper, item, {
|
|
208
|
+
...context,
|
|
209
|
+
array: { index, length: input.length, item },
|
|
210
|
+
}));
|
|
208
211
|
return input.filter((value, index) => {
|
|
209
212
|
for (let i = 0; i < index; i += 1) {
|
|
210
213
|
if (equal(remapped[index], remapped[i])) {
|
package/remap.test.js
CHANGED
|
@@ -756,12 +756,13 @@ describe('array', () => {
|
|
|
756
756
|
'object.from': {
|
|
757
757
|
index: [{ array: 'index' }],
|
|
758
758
|
length: [{ array: 'length' }],
|
|
759
|
+
item: [{ array: 'item' }],
|
|
759
760
|
},
|
|
760
761
|
},
|
|
761
762
|
],
|
|
762
|
-
expected: { index: undefined, length: undefined },
|
|
763
|
+
expected: { index: undefined, length: undefined, item: undefined },
|
|
763
764
|
},
|
|
764
|
-
'return the index and
|
|
765
|
+
'return the index, length and item if in the context of array.map': {
|
|
765
766
|
input: { array: [{ value: 'a' }, { value: 'b' }, { value: 'c' }] },
|
|
766
767
|
mappers: [
|
|
767
768
|
{ prop: 'array' },
|
|
@@ -772,15 +773,16 @@ describe('array', () => {
|
|
|
772
773
|
value: [{ prop: 'value' }],
|
|
773
774
|
index: [{ array: 'index' }],
|
|
774
775
|
length: [{ array: 'length' }],
|
|
776
|
+
item: [{ array: 'item' }],
|
|
775
777
|
},
|
|
776
778
|
},
|
|
777
779
|
],
|
|
778
780
|
},
|
|
779
781
|
],
|
|
780
782
|
expected: [
|
|
781
|
-
{ value: 'a', index: 0, length: 3 },
|
|
782
|
-
{ value: 'b', index: 1, length: 3 },
|
|
783
|
-
{ value: 'c', index: 2, length: 3 },
|
|
783
|
+
{ value: 'a', index: 0, length: 3, item: { value: 'a' } },
|
|
784
|
+
{ value: 'b', index: 1, length: 3, item: { value: 'b' } },
|
|
785
|
+
{ value: 'c', index: 2, length: 3, item: { value: 'c' } },
|
|
784
786
|
],
|
|
785
787
|
},
|
|
786
788
|
});
|