@appsemble/utils 0.20.44 → 0.21.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/api/components/schemas/ActionDefinition.js +1 -0
- package/api/components/schemas/ObjectRemapperDefinition.js +6 -504
- package/api/components/schemas/RequestActionDefinition.js +1 -1
- package/api/components/schemas/ScimPatchOp.d.ts +2 -0
- package/api/components/schemas/ScimPatchOp.js +47 -0
- package/api/components/schemas/ScimSecret.d.ts +2 -0
- package/api/components/schemas/ScimSecret.js +16 -0
- package/api/components/schemas/ScimUser.d.ts +2 -0
- package/api/components/schemas/ScimUser.js +60 -0
- package/api/components/schemas/TeamMembersActionDefinition.d.ts +1 -0
- package/api/components/schemas/TeamMembersActionDefinition.js +18 -0
- package/api/components/schemas/index.d.ts +4 -0
- package/api/components/schemas/index.js +4 -0
- package/api/components/securitySchemes/index.d.ts +1 -0
- package/api/components/securitySchemes/index.js +1 -0
- package/api/components/securitySchemes/scim.d.ts +2 -0
- package/api/components/securitySchemes/scim.js +6 -0
- package/api/index.d.ts +18 -1
- package/api/index.js +8 -1
- package/api/index.test.js +1 -1
- package/api/paths/appScimEndpoints.d.ts +2 -0
- package/api/paths/appScimEndpoints.js +260 -0
- package/api/paths/appScimSecrets.d.ts +2 -0
- package/api/paths/appScimSecrets.js +45 -0
- package/api/paths/apps.js +18 -1
- package/api/paths/index.js +4 -0
- package/appMessages.test.js +1 -1
- package/iterApp.test.js +44 -48
- package/jsonschema.test.js +8 -8
- package/package.json +3 -3
- package/reference-schemas/remappers/arrays.d.ts +2 -0
- package/reference-schemas/remappers/arrays.js +334 -0
- package/reference-schemas/remappers/conditionals.d.ts +2 -0
- package/reference-schemas/remappers/conditionals.js +93 -0
- package/reference-schemas/remappers/data.d.ts +2 -0
- package/reference-schemas/remappers/data.js +321 -0
- package/reference-schemas/remappers/dates.d.ts +2 -0
- package/reference-schemas/remappers/dates.js +38 -0
- package/reference-schemas/remappers/history.d.ts +2 -0
- package/reference-schemas/remappers/history.js +246 -0
- package/reference-schemas/remappers/index.d.ts +9 -0
- package/reference-schemas/remappers/index.js +10 -0
- package/reference-schemas/remappers/objects.d.ts +2 -0
- package/reference-schemas/remappers/objects.js +157 -0
- package/reference-schemas/remappers/randoms.d.ts +2 -0
- package/reference-schemas/remappers/randoms.js +35 -0
- package/reference-schemas/remappers/strings.d.ts +2 -0
- package/reference-schemas/remappers/strings.js +81 -0
- package/reference-schemas/remappers/unsorted.d.ts +2 -0
- package/reference-schemas/remappers/unsorted.js +71 -0
- package/remap.js +1 -1
- package/remap.test.js +20 -16
- package/serverActions.js +5 -0
- package/vitest.config.d.ts +2 -0
package/iterApp.test.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { iterAction, iterApp, iterBlock, iterBlockList, iterPage } from './iterApp.js';
|
|
2
2
|
describe('iterAction', () => {
|
|
3
3
|
it('should call the appropriate callbacks', () => {
|
|
4
|
-
const onAction =
|
|
5
|
-
const onBlockList =
|
|
4
|
+
const onAction = vi.fn();
|
|
5
|
+
const onBlockList = vi.fn();
|
|
6
6
|
const action = {
|
|
7
7
|
type: 'dialog',
|
|
8
8
|
blocks: [{ type: 'list', version: '0.1.2' }],
|
|
@@ -13,8 +13,8 @@ describe('iterAction', () => {
|
|
|
13
13
|
expect(result).toBe(false);
|
|
14
14
|
});
|
|
15
15
|
it('should abort if the onAction callback returns true', () => {
|
|
16
|
-
const onAction =
|
|
17
|
-
const onBlockList =
|
|
16
|
+
const onAction = vi.fn().mockReturnValue(true);
|
|
17
|
+
const onBlockList = vi.fn();
|
|
18
18
|
const action = {
|
|
19
19
|
type: 'dialog',
|
|
20
20
|
blocks: [{ type: 'list', version: '0.1.2' }],
|
|
@@ -25,8 +25,8 @@ describe('iterAction', () => {
|
|
|
25
25
|
expect(result).toBe(true);
|
|
26
26
|
});
|
|
27
27
|
it('should call onAction for onSuccess', () => {
|
|
28
|
-
const onAction =
|
|
29
|
-
const onBlockList =
|
|
28
|
+
const onAction = vi.fn();
|
|
29
|
+
const onBlockList = vi.fn();
|
|
30
30
|
const action = {
|
|
31
31
|
type: 'noop',
|
|
32
32
|
onSuccess: {
|
|
@@ -40,10 +40,8 @@ describe('iterAction', () => {
|
|
|
40
40
|
expect(result).toBe(false);
|
|
41
41
|
});
|
|
42
42
|
it('should return true if onAction returns true for onSuccess', () => {
|
|
43
|
-
const onAction =
|
|
44
|
-
|
|
45
|
-
.mockImplementation((a, [prefix]) => prefix === 'onSuccess');
|
|
46
|
-
const onBlockList = import.meta.jest.fn();
|
|
43
|
+
const onAction = vi.fn().mockImplementation((a, [prefix]) => prefix === 'onSuccess');
|
|
44
|
+
const onBlockList = vi.fn();
|
|
47
45
|
const action = {
|
|
48
46
|
type: 'noop',
|
|
49
47
|
onSuccess: {
|
|
@@ -57,8 +55,8 @@ describe('iterAction', () => {
|
|
|
57
55
|
expect(result).toBe(true);
|
|
58
56
|
});
|
|
59
57
|
it('should call onAction for onError', () => {
|
|
60
|
-
const onAction =
|
|
61
|
-
const onBlockList =
|
|
58
|
+
const onAction = vi.fn();
|
|
59
|
+
const onBlockList = vi.fn();
|
|
62
60
|
const action = {
|
|
63
61
|
type: 'noop',
|
|
64
62
|
onError: {
|
|
@@ -72,10 +70,8 @@ describe('iterAction', () => {
|
|
|
72
70
|
expect(result).toBe(false);
|
|
73
71
|
});
|
|
74
72
|
it('should return true if onAction returns true for onError', () => {
|
|
75
|
-
const onAction =
|
|
76
|
-
|
|
77
|
-
.mockImplementation((a, [prefix]) => prefix === 'onError');
|
|
78
|
-
const onBlockList = import.meta.jest.fn();
|
|
73
|
+
const onAction = vi.fn().mockImplementation((a, [prefix]) => prefix === 'onError');
|
|
74
|
+
const onBlockList = vi.fn();
|
|
79
75
|
const action = {
|
|
80
76
|
type: 'noop',
|
|
81
77
|
onError: {
|
|
@@ -89,7 +85,7 @@ describe('iterAction', () => {
|
|
|
89
85
|
expect(result).toBe(true);
|
|
90
86
|
});
|
|
91
87
|
it('should call then and else for conditional actions', () => {
|
|
92
|
-
const onAction =
|
|
88
|
+
const onAction = vi.fn();
|
|
93
89
|
const action = {
|
|
94
90
|
type: 'condition',
|
|
95
91
|
if: true,
|
|
@@ -103,8 +99,8 @@ describe('iterAction', () => {
|
|
|
103
99
|
expect(result).toBe(false);
|
|
104
100
|
});
|
|
105
101
|
it('should return the return value of iterBlockList', () => {
|
|
106
|
-
const onAction =
|
|
107
|
-
const onBlockList =
|
|
102
|
+
const onAction = vi.fn();
|
|
103
|
+
const onBlockList = vi.fn().mockReturnValue(true);
|
|
108
104
|
const action = {
|
|
109
105
|
type: 'dialog',
|
|
110
106
|
blocks: [{ type: 'list', version: '0.1.2' }],
|
|
@@ -118,8 +114,8 @@ describe('iterAction', () => {
|
|
|
118
114
|
expect(result).toBe(true);
|
|
119
115
|
});
|
|
120
116
|
it('should not call iterBlockList if the action has no blocks', () => {
|
|
121
|
-
const onAction =
|
|
122
|
-
const onBlockList =
|
|
117
|
+
const onAction = vi.fn();
|
|
118
|
+
const onBlockList = vi.fn();
|
|
123
119
|
const action = {
|
|
124
120
|
type: 'log',
|
|
125
121
|
};
|
|
@@ -134,8 +130,8 @@ describe('iterAction', () => {
|
|
|
134
130
|
});
|
|
135
131
|
describe('iterBlock', () => {
|
|
136
132
|
it('should call the appropriate callbacks', () => {
|
|
137
|
-
const onAction =
|
|
138
|
-
const onBlock =
|
|
133
|
+
const onAction = vi.fn();
|
|
134
|
+
const onBlock = vi.fn();
|
|
139
135
|
const block = {
|
|
140
136
|
type: 'list',
|
|
141
137
|
version: '1.2.3',
|
|
@@ -151,8 +147,8 @@ describe('iterBlock', () => {
|
|
|
151
147
|
expect(result).toBe(false);
|
|
152
148
|
});
|
|
153
149
|
it('should abort if onBlock returns true', () => {
|
|
154
|
-
const onAction =
|
|
155
|
-
const onBlock =
|
|
150
|
+
const onAction = vi.fn();
|
|
151
|
+
const onBlock = vi.fn().mockReturnValue(true);
|
|
156
152
|
const block = {
|
|
157
153
|
type: 'list',
|
|
158
154
|
version: '1.2.3',
|
|
@@ -168,8 +164,8 @@ describe('iterBlock', () => {
|
|
|
168
164
|
expect(result).toBe(true);
|
|
169
165
|
});
|
|
170
166
|
it('should return the return value of onAction', () => {
|
|
171
|
-
const onAction =
|
|
172
|
-
const onBlock =
|
|
167
|
+
const onAction = vi.fn().mockReturnValue(true);
|
|
168
|
+
const onBlock = vi.fn();
|
|
173
169
|
const block = {
|
|
174
170
|
type: 'list',
|
|
175
171
|
version: '1.2.3',
|
|
@@ -187,8 +183,8 @@ describe('iterBlock', () => {
|
|
|
187
183
|
});
|
|
188
184
|
describe('iterBlockList', () => {
|
|
189
185
|
it('should call the appropriate callbacks', () => {
|
|
190
|
-
const onBlock =
|
|
191
|
-
const onBlockList =
|
|
186
|
+
const onBlock = vi.fn();
|
|
187
|
+
const onBlockList = vi.fn();
|
|
192
188
|
const blocks = [
|
|
193
189
|
{
|
|
194
190
|
type: 'list',
|
|
@@ -206,8 +202,8 @@ describe('iterBlockList', () => {
|
|
|
206
202
|
expect(result).toBe(false);
|
|
207
203
|
});
|
|
208
204
|
it('should abort if onBlockList returns true', () => {
|
|
209
|
-
const onBlock =
|
|
210
|
-
const onBlockList =
|
|
205
|
+
const onBlock = vi.fn();
|
|
206
|
+
const onBlockList = vi.fn().mockReturnValue(true);
|
|
211
207
|
const blocks = [
|
|
212
208
|
{
|
|
213
209
|
type: 'list',
|
|
@@ -227,8 +223,8 @@ describe('iterBlockList', () => {
|
|
|
227
223
|
});
|
|
228
224
|
describe('iterPage', () => {
|
|
229
225
|
it('should iterate over a page', () => {
|
|
230
|
-
const onBlockList =
|
|
231
|
-
const onPage =
|
|
226
|
+
const onBlockList = vi.fn();
|
|
227
|
+
const onPage = vi.fn();
|
|
232
228
|
const page = {
|
|
233
229
|
name: 'Page',
|
|
234
230
|
blocks: [],
|
|
@@ -239,8 +235,8 @@ describe('iterPage', () => {
|
|
|
239
235
|
expect(result).toBe(false);
|
|
240
236
|
});
|
|
241
237
|
it('should abort if onPage returns true', () => {
|
|
242
|
-
const onBlockList =
|
|
243
|
-
const onPage =
|
|
238
|
+
const onBlockList = vi.fn();
|
|
239
|
+
const onPage = vi.fn().mockReturnValue(true);
|
|
244
240
|
const page = {
|
|
245
241
|
name: 'Page',
|
|
246
242
|
blocks: [],
|
|
@@ -251,8 +247,8 @@ describe('iterPage', () => {
|
|
|
251
247
|
expect(result).toBe(true);
|
|
252
248
|
});
|
|
253
249
|
it('should iterate a flow page', () => {
|
|
254
|
-
const onBlockList =
|
|
255
|
-
const onPage =
|
|
250
|
+
const onBlockList = vi.fn();
|
|
251
|
+
const onPage = vi.fn();
|
|
256
252
|
const page = {
|
|
257
253
|
name: 'Page',
|
|
258
254
|
type: 'flow',
|
|
@@ -269,8 +265,8 @@ describe('iterPage', () => {
|
|
|
269
265
|
expect(result).toBe(false);
|
|
270
266
|
});
|
|
271
267
|
it('should iterate a tabs page', () => {
|
|
272
|
-
const onBlockList =
|
|
273
|
-
const onPage =
|
|
268
|
+
const onBlockList = vi.fn();
|
|
269
|
+
const onPage = vi.fn();
|
|
274
270
|
const page = {
|
|
275
271
|
name: 'Page',
|
|
276
272
|
type: 'tabs',
|
|
@@ -287,8 +283,8 @@ describe('iterPage', () => {
|
|
|
287
283
|
expect(result).toBe(false);
|
|
288
284
|
});
|
|
289
285
|
it('should call onAction for page actions', () => {
|
|
290
|
-
const onAction =
|
|
291
|
-
const onPage =
|
|
286
|
+
const onAction = vi.fn();
|
|
287
|
+
const onPage = vi.fn();
|
|
292
288
|
const page = {
|
|
293
289
|
name: 'Page',
|
|
294
290
|
type: 'flow',
|
|
@@ -305,9 +301,9 @@ describe('iterPage', () => {
|
|
|
305
301
|
expect(result).toBe(false);
|
|
306
302
|
});
|
|
307
303
|
it('should call onAction and onBlockList for pages with actions and sub pages', () => {
|
|
308
|
-
const onAction =
|
|
309
|
-
const onPage =
|
|
310
|
-
const onBlockList =
|
|
304
|
+
const onAction = vi.fn();
|
|
305
|
+
const onPage = vi.fn();
|
|
306
|
+
const onBlockList = vi.fn();
|
|
311
307
|
const page = {
|
|
312
308
|
name: 'Page',
|
|
313
309
|
type: 'flow',
|
|
@@ -342,7 +338,7 @@ describe('iterPage', () => {
|
|
|
342
338
|
});
|
|
343
339
|
describe('iterApp', () => {
|
|
344
340
|
it('should iterate over the page of an app', () => {
|
|
345
|
-
const onPage =
|
|
341
|
+
const onPage = vi.fn();
|
|
346
342
|
const app = {
|
|
347
343
|
name: 'App',
|
|
348
344
|
defaultPage: 'Page',
|
|
@@ -358,7 +354,7 @@ describe('iterApp', () => {
|
|
|
358
354
|
expect(result).toBe(false);
|
|
359
355
|
});
|
|
360
356
|
it('should abort page iteration if a callback returns true', () => {
|
|
361
|
-
const onPage =
|
|
357
|
+
const onPage = vi.fn().mockReturnValue(true);
|
|
362
358
|
const app = {
|
|
363
359
|
name: 'App',
|
|
364
360
|
defaultPage: 'Page 1',
|
|
@@ -379,7 +375,7 @@ describe('iterApp', () => {
|
|
|
379
375
|
expect(result).toBe(true);
|
|
380
376
|
});
|
|
381
377
|
it('should iterate over cron jobs', () => {
|
|
382
|
-
const onAction =
|
|
378
|
+
const onAction = vi.fn();
|
|
383
379
|
const app = {
|
|
384
380
|
name: 'App',
|
|
385
381
|
defaultPage: 'Page 1',
|
|
@@ -396,7 +392,7 @@ describe('iterApp', () => {
|
|
|
396
392
|
expect(result).toBe(false);
|
|
397
393
|
});
|
|
398
394
|
it('should abort cron iteration if a callback returns true', () => {
|
|
399
|
-
const onAction =
|
|
395
|
+
const onAction = vi.fn().mockReturnValue(true);
|
|
400
396
|
const app = {
|
|
401
397
|
name: 'App',
|
|
402
398
|
defaultPage: 'Page 1',
|
package/jsonschema.test.js
CHANGED
|
@@ -161,7 +161,7 @@ describe('combineSchemas', () => {
|
|
|
161
161
|
});
|
|
162
162
|
describe('iterJSONSchema', () => {
|
|
163
163
|
it('should handle properties', () => {
|
|
164
|
-
const onSchema =
|
|
164
|
+
const onSchema = vi.fn();
|
|
165
165
|
const schema = {
|
|
166
166
|
type: 'object',
|
|
167
167
|
properties: {
|
|
@@ -174,7 +174,7 @@ describe('iterJSONSchema', () => {
|
|
|
174
174
|
expect(onSchema).toHaveBeenCalledWith(schema.properties.foo);
|
|
175
175
|
});
|
|
176
176
|
it('should handle additionalProperties', () => {
|
|
177
|
-
const onSchema =
|
|
177
|
+
const onSchema = vi.fn();
|
|
178
178
|
const schema = {
|
|
179
179
|
type: 'object',
|
|
180
180
|
additionalProperties: { description: 'foo' },
|
|
@@ -185,7 +185,7 @@ describe('iterJSONSchema', () => {
|
|
|
185
185
|
expect(onSchema).toHaveBeenCalledWith(schema.additionalProperties);
|
|
186
186
|
});
|
|
187
187
|
it('should handle an items object', () => {
|
|
188
|
-
const onSchema =
|
|
188
|
+
const onSchema = vi.fn();
|
|
189
189
|
const schema = {
|
|
190
190
|
type: 'array',
|
|
191
191
|
items: { description: 'foo' },
|
|
@@ -196,7 +196,7 @@ describe('iterJSONSchema', () => {
|
|
|
196
196
|
expect(onSchema).toHaveBeenCalledWith(schema.items);
|
|
197
197
|
});
|
|
198
198
|
it('should handle an items array', () => {
|
|
199
|
-
const onSchema =
|
|
199
|
+
const onSchema = vi.fn();
|
|
200
200
|
const schema = {
|
|
201
201
|
type: 'array',
|
|
202
202
|
items: [{ description: 'foo' }, { description: 'bar' }],
|
|
@@ -208,7 +208,7 @@ describe('iterJSONSchema', () => {
|
|
|
208
208
|
expect(onSchema).toHaveBeenCalledWith(schema.items[1]);
|
|
209
209
|
});
|
|
210
210
|
it('should handle additionalItems', () => {
|
|
211
|
-
const onSchema =
|
|
211
|
+
const onSchema = vi.fn();
|
|
212
212
|
const schema = {
|
|
213
213
|
type: 'array',
|
|
214
214
|
additionalItems: { description: 'foo' },
|
|
@@ -219,7 +219,7 @@ describe('iterJSONSchema', () => {
|
|
|
219
219
|
expect(onSchema).toHaveBeenCalledWith(schema.additionalItems);
|
|
220
220
|
});
|
|
221
221
|
it('should handle anyOf', () => {
|
|
222
|
-
const onSchema =
|
|
222
|
+
const onSchema = vi.fn();
|
|
223
223
|
const schema = {
|
|
224
224
|
type: 'array',
|
|
225
225
|
anyOf: [{ description: 'foo' }],
|
|
@@ -230,7 +230,7 @@ describe('iterJSONSchema', () => {
|
|
|
230
230
|
expect(onSchema).toHaveBeenCalledWith(schema.anyOf[0]);
|
|
231
231
|
});
|
|
232
232
|
it('should handle oneOf', () => {
|
|
233
|
-
const onSchema =
|
|
233
|
+
const onSchema = vi.fn();
|
|
234
234
|
const schema = {
|
|
235
235
|
type: 'array',
|
|
236
236
|
oneOf: [{ description: 'foo' }],
|
|
@@ -241,7 +241,7 @@ describe('iterJSONSchema', () => {
|
|
|
241
241
|
expect(onSchema).toHaveBeenCalledWith(schema.oneOf[0]);
|
|
242
242
|
});
|
|
243
243
|
it('should handle allOf', () => {
|
|
244
|
-
const onSchema =
|
|
244
|
+
const onSchema = vi.fn();
|
|
245
245
|
const schema = {
|
|
246
246
|
type: 'array',
|
|
247
247
|
allOf: [{ description: 'foo' }],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@appsemble/utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.21.0",
|
|
4
4
|
"description": "Utility functions used in Appsemble internally",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"app",
|
|
@@ -28,10 +28,10 @@
|
|
|
28
28
|
],
|
|
29
29
|
"scripts": {
|
|
30
30
|
"prepack": "tsc --noEmit false",
|
|
31
|
-
"test": "
|
|
31
|
+
"test": "vitest"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@appsemble/types": "0.
|
|
34
|
+
"@appsemble/types": "0.21.0",
|
|
35
35
|
"axios": "^1.0.0",
|
|
36
36
|
"cron-parser": "^4.0.0",
|
|
37
37
|
"date-fns": "^2.0.0",
|
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
export const arrayRemappers = {
|
|
2
|
+
'array.map': {
|
|
3
|
+
$ref: '#/components/schemas/RemapperDefinition',
|
|
4
|
+
description: `
|
|
5
|
+
The remapper goes through the given array and applies the given remappers on each individual item.
|
|
6
|
+
This can be very handy when sorting arrays by certain data. The remapper always returns an array.
|
|
7
|
+
Output can be an empty array if the supplied data isn’t an array.
|
|
8
|
+
|
|
9
|
+
For example, if you want to sort through a list of people and only get their occupations you can do
|
|
10
|
+
the following:
|
|
11
|
+
|
|
12
|
+
Input:
|
|
13
|
+
|
|
14
|
+
\`\`\`json
|
|
15
|
+
[
|
|
16
|
+
{
|
|
17
|
+
"name": "Peter",
|
|
18
|
+
"occupation": "Delivery driver"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"name": "Otto",
|
|
22
|
+
"occupation": "Scientist"
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"name": "Harry",
|
|
26
|
+
"occupation": "CEO"
|
|
27
|
+
}
|
|
28
|
+
]
|
|
29
|
+
\`\`\`
|
|
30
|
+
|
|
31
|
+
\`\`\`yaml
|
|
32
|
+
array.map:
|
|
33
|
+
object.omit:
|
|
34
|
+
- name
|
|
35
|
+
\`\`\`
|
|
36
|
+
|
|
37
|
+
Result:
|
|
38
|
+
|
|
39
|
+
\`\`\`json
|
|
40
|
+
[{ "occupation": "Delivery driver" }, { "occupation": "Scientist" }, { "occupation": "CEO" }]
|
|
41
|
+
\`\`\`
|
|
42
|
+
|
|
43
|
+
Another great use for \`array.map\` is to combine it with the \`if\` remapper and sort your arrays on
|
|
44
|
+
specific values.
|
|
45
|
+
|
|
46
|
+
Using the same input data from the previous example, look at how you can change the code to get
|
|
47
|
+
people from a specific occupation:
|
|
48
|
+
|
|
49
|
+
\`\`\`yaml
|
|
50
|
+
- array.map:
|
|
51
|
+
if:
|
|
52
|
+
condition: { equals: [{ prop: occupation }, Scientist] }
|
|
53
|
+
then:
|
|
54
|
+
object.from:
|
|
55
|
+
name:
|
|
56
|
+
prop: name
|
|
57
|
+
occupation:
|
|
58
|
+
prop: occupation
|
|
59
|
+
else: null
|
|
60
|
+
- null.strip: null
|
|
61
|
+
\`\`\`
|
|
62
|
+
|
|
63
|
+
Result:
|
|
64
|
+
|
|
65
|
+
\`\`\`json
|
|
66
|
+
[
|
|
67
|
+
{
|
|
68
|
+
"name": "Otto",
|
|
69
|
+
"occupation": "Scientist"
|
|
70
|
+
}
|
|
71
|
+
]
|
|
72
|
+
\`\`\`
|
|
73
|
+
|
|
74
|
+
Because \`array.map\` returns an array, every item has to return something. This is why we have to
|
|
75
|
+
return the full object with the data we want in the \`then\` section. It’s also why we return \`null\`.
|
|
76
|
+
This results in an array consisting of \`null\` values and objects with actual data in them. To solve
|
|
77
|
+
this problem, we use the \`null.strip\` remapper to remove any null values which results in a clean
|
|
78
|
+
array.
|
|
79
|
+
`,
|
|
80
|
+
},
|
|
81
|
+
'array.unique': {
|
|
82
|
+
$ref: '#/components/schemas/RemapperDefinition',
|
|
83
|
+
description: `
|
|
84
|
+
Filters out unique values from an array. The value Remapper is applied to each entry in the array
|
|
85
|
+
using its result to determine uniqueness.
|
|
86
|
+
|
|
87
|
+
If the value Remapper results in undefined or null, the entire entry is used for uniqueness.
|
|
88
|
+
|
|
89
|
+
If the input is not an array, the input is returned without any modifications.
|
|
90
|
+
|
|
91
|
+
Input:
|
|
92
|
+
|
|
93
|
+
\`\`\`json
|
|
94
|
+
[1, 1, 2, 3]
|
|
95
|
+
\`\`\`
|
|
96
|
+
|
|
97
|
+
\`\`\`yaml
|
|
98
|
+
array.unique: null
|
|
99
|
+
\`\`\`
|
|
100
|
+
|
|
101
|
+
Result:
|
|
102
|
+
|
|
103
|
+
\`\`\`json
|
|
104
|
+
[1, 2, 3]
|
|
105
|
+
\`\`\`
|
|
106
|
+
|
|
107
|
+
You can also check for more complex values in arrays. The remapper accepts remappers as well, so you
|
|
108
|
+
can also use entire objects to check for unique values.
|
|
109
|
+
|
|
110
|
+
For this example, we have the following extended data with some duplicate values:
|
|
111
|
+
|
|
112
|
+
\`\`\`json
|
|
113
|
+
[
|
|
114
|
+
{
|
|
115
|
+
"name": "Peter",
|
|
116
|
+
"occupation": "Delivery driver",
|
|
117
|
+
"age": 19
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
"name": "Peter",
|
|
121
|
+
"occupation": "Photographer",
|
|
122
|
+
"age": 19
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
"name": "Otto",
|
|
126
|
+
"occupation": "Scientist",
|
|
127
|
+
"age": 50
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
"name": "Harry",
|
|
131
|
+
"occupation": "CEO",
|
|
132
|
+
"age": 20
|
|
133
|
+
}
|
|
134
|
+
]
|
|
135
|
+
\`\`\`
|
|
136
|
+
|
|
137
|
+
We can be fairly sure in this list of people the first two Peters are the same person but with a
|
|
138
|
+
different occupation. To get more complex unique values from here, we can do the following:
|
|
139
|
+
|
|
140
|
+
\`\`\`yaml
|
|
141
|
+
array.unique:
|
|
142
|
+
object.from:
|
|
143
|
+
name: { prop: name }
|
|
144
|
+
age: { prop: age }
|
|
145
|
+
\`\`\`
|
|
146
|
+
|
|
147
|
+
This then checks the array for unique values in both the \`name\` and \`age\` fields. The result of this
|
|
148
|
+
remapper is a filtered list:
|
|
149
|
+
|
|
150
|
+
\`\`\`json
|
|
151
|
+
[
|
|
152
|
+
{
|
|
153
|
+
"name": "Peter",
|
|
154
|
+
"occupation": "Delivery driver",
|
|
155
|
+
"age": 19
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
"name": "Otto",
|
|
159
|
+
"occupation": "Scientist",
|
|
160
|
+
"age": 50
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
"name": "Harry",
|
|
164
|
+
"occupation": "CEO",
|
|
165
|
+
"age": 20
|
|
166
|
+
}
|
|
167
|
+
]
|
|
168
|
+
\`\`\`
|
|
169
|
+
`,
|
|
170
|
+
},
|
|
171
|
+
'array.from': {
|
|
172
|
+
type: 'array',
|
|
173
|
+
items: {
|
|
174
|
+
$ref: '#/components/schemas/RemapperDefinition',
|
|
175
|
+
},
|
|
176
|
+
description: `
|
|
177
|
+
Creates a new array based on a provided array of remappers. This array can also consist of static
|
|
178
|
+
values.
|
|
179
|
+
|
|
180
|
+
For example:
|
|
181
|
+
|
|
182
|
+
\`\`\`yaml
|
|
183
|
+
array.from:
|
|
184
|
+
- Peter
|
|
185
|
+
- Otto
|
|
186
|
+
- Harry
|
|
187
|
+
\`\`\`
|
|
188
|
+
|
|
189
|
+
\`\`\`json
|
|
190
|
+
["Peter", "Otto", "Harry"]
|
|
191
|
+
\`\`\`
|
|
192
|
+
|
|
193
|
+
This remapper can also be used to convert given data into an array.
|
|
194
|
+
|
|
195
|
+
Input:
|
|
196
|
+
|
|
197
|
+
\`\`\`json
|
|
198
|
+
{
|
|
199
|
+
"name": "Peter",
|
|
200
|
+
"occupation": "Delivery driver"
|
|
201
|
+
}
|
|
202
|
+
\`\`\`
|
|
203
|
+
|
|
204
|
+
\`\`\`yaml
|
|
205
|
+
array.from:
|
|
206
|
+
- root: null # Takes the data passed to this remapper, explained more in the 'Data' page
|
|
207
|
+
\`\`\`
|
|
208
|
+
|
|
209
|
+
Result:
|
|
210
|
+
|
|
211
|
+
\`\`\`json
|
|
212
|
+
[
|
|
213
|
+
{
|
|
214
|
+
"name": "Peter",
|
|
215
|
+
"occupation": "Delivery driver"
|
|
216
|
+
}
|
|
217
|
+
]
|
|
218
|
+
\`\`\`
|
|
219
|
+
`,
|
|
220
|
+
},
|
|
221
|
+
'array.append': {
|
|
222
|
+
type: 'array',
|
|
223
|
+
items: {
|
|
224
|
+
$ref: '#/components/schemas/RemapperDefinition',
|
|
225
|
+
},
|
|
226
|
+
description: `
|
|
227
|
+
Append new values to the end of an array. If the input is not an array an empty array is returned.
|
|
228
|
+
|
|
229
|
+
Using the array from the previous example, we can add a new object on top of it using this remapper:
|
|
230
|
+
|
|
231
|
+
\`\`\`yaml
|
|
232
|
+
array.append:
|
|
233
|
+
- object.from:
|
|
234
|
+
name: James
|
|
235
|
+
occupation: News reporter
|
|
236
|
+
\`\`\`
|
|
237
|
+
|
|
238
|
+
Result:
|
|
239
|
+
|
|
240
|
+
\`\`\`json
|
|
241
|
+
[
|
|
242
|
+
{
|
|
243
|
+
"name": "Peter",
|
|
244
|
+
"occupation": "Delivery driver"
|
|
245
|
+
},
|
|
246
|
+
{
|
|
247
|
+
"name": "Otto",
|
|
248
|
+
"occupation": "Scientist"
|
|
249
|
+
},
|
|
250
|
+
{
|
|
251
|
+
"name": "Harry",
|
|
252
|
+
"occupation": "CEO"
|
|
253
|
+
},
|
|
254
|
+
{
|
|
255
|
+
"name": "James",
|
|
256
|
+
"occupation": "News reporter"
|
|
257
|
+
}
|
|
258
|
+
]
|
|
259
|
+
\`\`\`
|
|
260
|
+
`,
|
|
261
|
+
},
|
|
262
|
+
'array.omit': {
|
|
263
|
+
type: 'array',
|
|
264
|
+
items: {
|
|
265
|
+
$ref: '#/components/schemas/RemapperDefinition',
|
|
266
|
+
},
|
|
267
|
+
description: `
|
|
268
|
+
Remove values from an array. The input is expected to be the index(es) of the items to be deleted.
|
|
269
|
+
Accepts an array of static or remapper values.
|
|
270
|
+
|
|
271
|
+
With the previous example we added a new person to the list of people, so now we can remove that
|
|
272
|
+
person. We already know the index of this person in the array is \`3\`, so it’s easy:
|
|
273
|
+
|
|
274
|
+
\`\`\`yaml
|
|
275
|
+
array.omit:
|
|
276
|
+
- 3
|
|
277
|
+
\`\`\`
|
|
278
|
+
|
|
279
|
+
Result:
|
|
280
|
+
|
|
281
|
+
\`\`\`json
|
|
282
|
+
[
|
|
283
|
+
{
|
|
284
|
+
"name": "Peter",
|
|
285
|
+
"occupation": "Delivery driver"
|
|
286
|
+
},
|
|
287
|
+
{
|
|
288
|
+
"name": "Otto",
|
|
289
|
+
"occupation": "Scientist"
|
|
290
|
+
},
|
|
291
|
+
{
|
|
292
|
+
"name": "Harry",
|
|
293
|
+
"occupation": "CEO"
|
|
294
|
+
}
|
|
295
|
+
]
|
|
296
|
+
\`\`\`
|
|
297
|
+
|
|
298
|
+
However, usually we don’t know the exact index of the item we want to delete. Because the remapper
|
|
299
|
+
accepts remappers as input we can get the desired item’s ID from another source as well. Take the
|
|
300
|
+
following example:
|
|
301
|
+
|
|
302
|
+
In this example we assume the data from the previous example is passed to this table block using a
|
|
303
|
+
data loader’s emitting event called “people”. When the user clicks on one of the people in the
|
|
304
|
+
table, it gets the list of people again. Using the index of this person, and the \`array.omit\`
|
|
305
|
+
remapper, the person gets removed from the list.
|
|
306
|
+
|
|
307
|
+
\`\`\`yaml
|
|
308
|
+
type: table
|
|
309
|
+
version: 0.20.38
|
|
310
|
+
events:
|
|
311
|
+
listen:
|
|
312
|
+
data: people
|
|
313
|
+
parameters:
|
|
314
|
+
fields:
|
|
315
|
+
- label: Name
|
|
316
|
+
value: { prop: name }
|
|
317
|
+
onClick: removePerson
|
|
318
|
+
- label: Occupation
|
|
319
|
+
value: { prop: occupation }
|
|
320
|
+
actions:
|
|
321
|
+
removePerson:
|
|
322
|
+
type: resource.query
|
|
323
|
+
resource: citizensNYC
|
|
324
|
+
remapAfter:
|
|
325
|
+
array.omit:
|
|
326
|
+
- context: index # This gets the index of the item in the table, explained more in the 'Data' page.
|
|
327
|
+
onSuccess:
|
|
328
|
+
type: resource.update
|
|
329
|
+
resource: citizensNYC
|
|
330
|
+
\`\`\`
|
|
331
|
+
`,
|
|
332
|
+
},
|
|
333
|
+
};
|
|
334
|
+
//# sourceMappingURL=arrays.js.map
|