@appsemble/utils 0.25.2 → 0.26.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/paths/apps.js +6 -0
- package/api/paths/oauth2Login.js +1 -1
- package/examples.d.ts +24 -0
- package/examples.js +668 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +4 -4
- package/reference-schemas/remappers/arrays.js +8 -147
- package/reference-schemas/remappers/conditionals.js +9 -53
- package/reference-schemas/remappers/data.js +8 -66
- package/reference-schemas/remappers/dates.js +7 -42
- package/reference-schemas/remappers/objects.js +4 -66
- package/reference-schemas/remappers/strings.js +4 -32
- package/reference-schemas/remappers/unsorted.js +2 -24
- package/remap.test.js +8 -0
package/examples.js
ADDED
|
@@ -0,0 +1,668 @@
|
|
|
1
|
+
import { IntlMessageFormat } from 'intl-messageformat';
|
|
2
|
+
import { stringify } from 'yaml';
|
|
3
|
+
export const examples = {
|
|
4
|
+
None: {
|
|
5
|
+
input: null,
|
|
6
|
+
remapper: '',
|
|
7
|
+
result: '',
|
|
8
|
+
},
|
|
9
|
+
'app.id': {
|
|
10
|
+
input: null,
|
|
11
|
+
remapper: {
|
|
12
|
+
app: 'id',
|
|
13
|
+
},
|
|
14
|
+
result: 0,
|
|
15
|
+
},
|
|
16
|
+
'app.locale': {
|
|
17
|
+
input: null,
|
|
18
|
+
remapper: {
|
|
19
|
+
app: 'locale',
|
|
20
|
+
},
|
|
21
|
+
result: 'en',
|
|
22
|
+
},
|
|
23
|
+
'app.url': {
|
|
24
|
+
input: null,
|
|
25
|
+
remapper: {
|
|
26
|
+
app: 'url',
|
|
27
|
+
},
|
|
28
|
+
result: 'https://example-app.example-organization.example.com',
|
|
29
|
+
},
|
|
30
|
+
appMember: {
|
|
31
|
+
input: null,
|
|
32
|
+
remapper: {},
|
|
33
|
+
result: {},
|
|
34
|
+
skip: true,
|
|
35
|
+
},
|
|
36
|
+
array: {
|
|
37
|
+
input: ['a', 'b', 'c'],
|
|
38
|
+
remapper: {
|
|
39
|
+
'array.map': {
|
|
40
|
+
'object.from': {
|
|
41
|
+
index: {
|
|
42
|
+
array: 'index',
|
|
43
|
+
},
|
|
44
|
+
length: {
|
|
45
|
+
array: 'length',
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
result: [
|
|
51
|
+
{
|
|
52
|
+
index: 0,
|
|
53
|
+
length: 3,
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
index: 1,
|
|
57
|
+
length: 3,
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
index: 2,
|
|
61
|
+
length: 3,
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
},
|
|
65
|
+
'array.append': {
|
|
66
|
+
input: [
|
|
67
|
+
{
|
|
68
|
+
name: 'Peter',
|
|
69
|
+
occupation: 'Delivery driver',
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
name: 'Otto',
|
|
73
|
+
occupation: 'Scientist',
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
name: 'Harry',
|
|
77
|
+
occupation: 'CEO',
|
|
78
|
+
},
|
|
79
|
+
],
|
|
80
|
+
remapper: {
|
|
81
|
+
'array.append': [
|
|
82
|
+
{
|
|
83
|
+
'object.from': {
|
|
84
|
+
name: 'James',
|
|
85
|
+
occupation: 'News reporter',
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
],
|
|
89
|
+
},
|
|
90
|
+
result: [
|
|
91
|
+
{
|
|
92
|
+
name: 'Peter',
|
|
93
|
+
occupation: 'Delivery driver',
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
name: 'Otto',
|
|
97
|
+
occupation: 'Scientist',
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
name: 'Harry',
|
|
101
|
+
occupation: 'CEO',
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
name: 'James',
|
|
105
|
+
occupation: 'News reporter',
|
|
106
|
+
},
|
|
107
|
+
],
|
|
108
|
+
},
|
|
109
|
+
'array.find': {
|
|
110
|
+
input: [
|
|
111
|
+
{
|
|
112
|
+
name: 'Craig',
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
name: 'Joey',
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
name: 'Stuart',
|
|
119
|
+
},
|
|
120
|
+
],
|
|
121
|
+
remapper: {
|
|
122
|
+
'array.find': {
|
|
123
|
+
equals: [
|
|
124
|
+
{
|
|
125
|
+
prop: 'name',
|
|
126
|
+
},
|
|
127
|
+
'Craig',
|
|
128
|
+
],
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
result: {
|
|
132
|
+
name: 'Craig',
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
'array.from': {
|
|
136
|
+
input: null,
|
|
137
|
+
remapper: {
|
|
138
|
+
'array.from': ['Peter', 'Otto', 'Harry'],
|
|
139
|
+
},
|
|
140
|
+
result: ['Peter', 'Otto', 'Harry'],
|
|
141
|
+
},
|
|
142
|
+
'array.map': {
|
|
143
|
+
input: [
|
|
144
|
+
{
|
|
145
|
+
name: 'Peter',
|
|
146
|
+
occupation: 'Delivery driver',
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
name: 'Otto',
|
|
150
|
+
occupation: 'Scientist',
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
name: 'Harry',
|
|
154
|
+
occupation: 'CEO',
|
|
155
|
+
},
|
|
156
|
+
],
|
|
157
|
+
remapper: {
|
|
158
|
+
'array.map': {
|
|
159
|
+
'object.omit': ['name'],
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
result: [
|
|
163
|
+
{
|
|
164
|
+
occupation: 'Delivery driver',
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
occupation: 'Scientist',
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
occupation: 'CEO',
|
|
171
|
+
},
|
|
172
|
+
],
|
|
173
|
+
},
|
|
174
|
+
'array.map.1': {
|
|
175
|
+
input: [
|
|
176
|
+
{
|
|
177
|
+
name: 'Peter',
|
|
178
|
+
occupation: 'Delivery driver',
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
name: 'Otto',
|
|
182
|
+
occupation: 'Scientist',
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
name: 'Harry',
|
|
186
|
+
occupation: 'CEO',
|
|
187
|
+
},
|
|
188
|
+
],
|
|
189
|
+
remapper: [
|
|
190
|
+
{
|
|
191
|
+
'array.map': {
|
|
192
|
+
if: {
|
|
193
|
+
condition: {
|
|
194
|
+
equals: [
|
|
195
|
+
{
|
|
196
|
+
prop: 'occupation',
|
|
197
|
+
},
|
|
198
|
+
'Scientist',
|
|
199
|
+
],
|
|
200
|
+
},
|
|
201
|
+
else: null,
|
|
202
|
+
then: {
|
|
203
|
+
'object.from': {
|
|
204
|
+
name: {
|
|
205
|
+
prop: 'name',
|
|
206
|
+
},
|
|
207
|
+
occupation: {
|
|
208
|
+
prop: 'occupation',
|
|
209
|
+
},
|
|
210
|
+
},
|
|
211
|
+
},
|
|
212
|
+
},
|
|
213
|
+
},
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
'null.strip': null,
|
|
217
|
+
},
|
|
218
|
+
],
|
|
219
|
+
result: [
|
|
220
|
+
{
|
|
221
|
+
name: 'Otto',
|
|
222
|
+
occupation: 'Scientist',
|
|
223
|
+
},
|
|
224
|
+
],
|
|
225
|
+
},
|
|
226
|
+
'array.omit': {
|
|
227
|
+
input: [
|
|
228
|
+
{
|
|
229
|
+
name: 'Peter',
|
|
230
|
+
occupation: 'Delivery driver',
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
name: 'Otto',
|
|
234
|
+
occupation: 'Scientist',
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
name: 'Harry',
|
|
238
|
+
occupation: 'CEO',
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
name: 'James',
|
|
242
|
+
occupation: 'News reporter',
|
|
243
|
+
},
|
|
244
|
+
],
|
|
245
|
+
remapper: {
|
|
246
|
+
'array.omit': [3],
|
|
247
|
+
},
|
|
248
|
+
result: [
|
|
249
|
+
{
|
|
250
|
+
name: 'Peter',
|
|
251
|
+
occupation: 'Delivery driver',
|
|
252
|
+
},
|
|
253
|
+
{
|
|
254
|
+
name: 'Otto',
|
|
255
|
+
occupation: 'Scientist',
|
|
256
|
+
},
|
|
257
|
+
{
|
|
258
|
+
name: 'Harry',
|
|
259
|
+
occupation: 'CEO',
|
|
260
|
+
},
|
|
261
|
+
],
|
|
262
|
+
},
|
|
263
|
+
'array.unique': {
|
|
264
|
+
input: [1, 1, 2, 3],
|
|
265
|
+
remapper: {
|
|
266
|
+
'array.unique': null,
|
|
267
|
+
},
|
|
268
|
+
result: [1, 2, 3],
|
|
269
|
+
},
|
|
270
|
+
'assign.history': {
|
|
271
|
+
input: null,
|
|
272
|
+
remapper: {},
|
|
273
|
+
result: {},
|
|
274
|
+
skip: true,
|
|
275
|
+
},
|
|
276
|
+
context: {
|
|
277
|
+
input: null,
|
|
278
|
+
remapper: {},
|
|
279
|
+
result: {},
|
|
280
|
+
skip: true,
|
|
281
|
+
},
|
|
282
|
+
'date.add': {
|
|
283
|
+
input: '2023-06-30T14:50:19.601Z',
|
|
284
|
+
remapper: [
|
|
285
|
+
{
|
|
286
|
+
'date.now': null,
|
|
287
|
+
},
|
|
288
|
+
{
|
|
289
|
+
'date.add': '1w',
|
|
290
|
+
},
|
|
291
|
+
{
|
|
292
|
+
'date.format': null,
|
|
293
|
+
},
|
|
294
|
+
],
|
|
295
|
+
result: '2023-07-07T14:50:19.601Z',
|
|
296
|
+
skip: true,
|
|
297
|
+
},
|
|
298
|
+
'date.format': {
|
|
299
|
+
input: '2023-07-03',
|
|
300
|
+
remapper: {
|
|
301
|
+
'date.format': null,
|
|
302
|
+
},
|
|
303
|
+
result: '2023-07-02T22:00:00.000Z',
|
|
304
|
+
skip: true,
|
|
305
|
+
},
|
|
306
|
+
'date.now': {
|
|
307
|
+
input: null,
|
|
308
|
+
remapper: {
|
|
309
|
+
'date.now': null,
|
|
310
|
+
},
|
|
311
|
+
result: 'Mon Jul 03 2023 11:47:18 GMT+0200 (Midden-Europese zomertijd)',
|
|
312
|
+
skip: true,
|
|
313
|
+
},
|
|
314
|
+
'date.parse': {
|
|
315
|
+
input: '02/11/2014',
|
|
316
|
+
remapper: {
|
|
317
|
+
'date.parse': 'MM/dd/yyyy',
|
|
318
|
+
},
|
|
319
|
+
result: 'Tue Feb 11 2014 00:00:00',
|
|
320
|
+
skip: true,
|
|
321
|
+
},
|
|
322
|
+
equals: {
|
|
323
|
+
input: { inputValue: 'example', expectedValue: 'example' },
|
|
324
|
+
remapper: {
|
|
325
|
+
equals: [{ prop: 'inputValue' }, { prop: 'expectedValue' }],
|
|
326
|
+
},
|
|
327
|
+
result: true,
|
|
328
|
+
},
|
|
329
|
+
'from.history': {
|
|
330
|
+
input: null,
|
|
331
|
+
remapper: {},
|
|
332
|
+
result: {},
|
|
333
|
+
skip: true,
|
|
334
|
+
},
|
|
335
|
+
gt: {
|
|
336
|
+
input: { stock: 100 },
|
|
337
|
+
remapper: { gt: [{ prop: 'stock' }, 5] },
|
|
338
|
+
result: true,
|
|
339
|
+
},
|
|
340
|
+
history: {
|
|
341
|
+
input: null,
|
|
342
|
+
remapper: {},
|
|
343
|
+
result: {},
|
|
344
|
+
skip: true,
|
|
345
|
+
},
|
|
346
|
+
ics: {
|
|
347
|
+
input: null,
|
|
348
|
+
remapper: {},
|
|
349
|
+
result: {},
|
|
350
|
+
skip: true,
|
|
351
|
+
},
|
|
352
|
+
'if.then': {
|
|
353
|
+
input: { guess: 4 },
|
|
354
|
+
remapper: {
|
|
355
|
+
if: {
|
|
356
|
+
condition: {
|
|
357
|
+
equals: [
|
|
358
|
+
{
|
|
359
|
+
prop: 'guess',
|
|
360
|
+
},
|
|
361
|
+
4,
|
|
362
|
+
],
|
|
363
|
+
},
|
|
364
|
+
then: {
|
|
365
|
+
static: 'You guessed right!',
|
|
366
|
+
},
|
|
367
|
+
else: {
|
|
368
|
+
static: 'You guessed wrong!',
|
|
369
|
+
},
|
|
370
|
+
},
|
|
371
|
+
},
|
|
372
|
+
result: 'You guessed right!',
|
|
373
|
+
},
|
|
374
|
+
'if.else': {
|
|
375
|
+
input: { guess: 5 },
|
|
376
|
+
remapper: {
|
|
377
|
+
if: {
|
|
378
|
+
condition: {
|
|
379
|
+
equals: [
|
|
380
|
+
{
|
|
381
|
+
prop: 'guess',
|
|
382
|
+
},
|
|
383
|
+
4,
|
|
384
|
+
],
|
|
385
|
+
},
|
|
386
|
+
then: {
|
|
387
|
+
static: 'You guessed right!',
|
|
388
|
+
},
|
|
389
|
+
else: {
|
|
390
|
+
static: 'You guessed wrong!',
|
|
391
|
+
},
|
|
392
|
+
},
|
|
393
|
+
},
|
|
394
|
+
result: 'You guessed wrong!',
|
|
395
|
+
},
|
|
396
|
+
log: {
|
|
397
|
+
input: null,
|
|
398
|
+
remapper: {},
|
|
399
|
+
result: {},
|
|
400
|
+
skip: true,
|
|
401
|
+
},
|
|
402
|
+
lt: {
|
|
403
|
+
input: { stock: 4 },
|
|
404
|
+
remapper: { lt: [{ prop: 'stock' }, 5] },
|
|
405
|
+
result: true,
|
|
406
|
+
},
|
|
407
|
+
match: {
|
|
408
|
+
input: { Gem: 'Ruby' },
|
|
409
|
+
remapper: {
|
|
410
|
+
match: [
|
|
411
|
+
{
|
|
412
|
+
case: {
|
|
413
|
+
equals: [
|
|
414
|
+
{
|
|
415
|
+
prop: 'Gem',
|
|
416
|
+
},
|
|
417
|
+
'Diamond',
|
|
418
|
+
],
|
|
419
|
+
},
|
|
420
|
+
value: 100,
|
|
421
|
+
},
|
|
422
|
+
{
|
|
423
|
+
case: {
|
|
424
|
+
equals: [
|
|
425
|
+
{
|
|
426
|
+
prop: 'Gem',
|
|
427
|
+
},
|
|
428
|
+
'Ruby',
|
|
429
|
+
],
|
|
430
|
+
},
|
|
431
|
+
value: 75,
|
|
432
|
+
},
|
|
433
|
+
{
|
|
434
|
+
case: {
|
|
435
|
+
equals: [
|
|
436
|
+
{
|
|
437
|
+
prop: 'Gem',
|
|
438
|
+
},
|
|
439
|
+
'Gold',
|
|
440
|
+
],
|
|
441
|
+
},
|
|
442
|
+
value: 50,
|
|
443
|
+
},
|
|
444
|
+
{
|
|
445
|
+
case: {
|
|
446
|
+
equals: [
|
|
447
|
+
{
|
|
448
|
+
prop: 'Gem',
|
|
449
|
+
},
|
|
450
|
+
'Sapphire',
|
|
451
|
+
],
|
|
452
|
+
},
|
|
453
|
+
value: 25,
|
|
454
|
+
result: {},
|
|
455
|
+
},
|
|
456
|
+
],
|
|
457
|
+
},
|
|
458
|
+
result: 75,
|
|
459
|
+
},
|
|
460
|
+
not: {
|
|
461
|
+
input: { number: 3 },
|
|
462
|
+
remapper: { not: [{ prop: 'number' }, 4] },
|
|
463
|
+
result: true,
|
|
464
|
+
},
|
|
465
|
+
'null.strip': {
|
|
466
|
+
input: null,
|
|
467
|
+
remapper: {},
|
|
468
|
+
result: {},
|
|
469
|
+
skip: true,
|
|
470
|
+
},
|
|
471
|
+
'object.assign': {
|
|
472
|
+
input: {
|
|
473
|
+
title: 'Weekly fishing 21',
|
|
474
|
+
},
|
|
475
|
+
remapper: {
|
|
476
|
+
'object.assign': {
|
|
477
|
+
author: 'John Doe',
|
|
478
|
+
},
|
|
479
|
+
},
|
|
480
|
+
result: {
|
|
481
|
+
author: 'John Doe',
|
|
482
|
+
title: 'Weekly fishing 21',
|
|
483
|
+
},
|
|
484
|
+
},
|
|
485
|
+
'object.from': {
|
|
486
|
+
input: null,
|
|
487
|
+
remapper: {
|
|
488
|
+
'object.from': {
|
|
489
|
+
email: 'example@hotmail.com',
|
|
490
|
+
username: 'Chris Taub',
|
|
491
|
+
},
|
|
492
|
+
},
|
|
493
|
+
result: {
|
|
494
|
+
email: 'example@hotmail.com',
|
|
495
|
+
username: 'Chris Taub',
|
|
496
|
+
},
|
|
497
|
+
},
|
|
498
|
+
'object.omit': {
|
|
499
|
+
input: {
|
|
500
|
+
author: 'John Doe',
|
|
501
|
+
content: {
|
|
502
|
+
interview: '...',
|
|
503
|
+
introduction: 'This is the introduction for the new weekly fishing issue',
|
|
504
|
+
paragraph1: '...',
|
|
505
|
+
},
|
|
506
|
+
title: 'Weekly fishing 21',
|
|
507
|
+
},
|
|
508
|
+
remapper: {
|
|
509
|
+
'object.omit': ['author', ['content', 'interview']],
|
|
510
|
+
},
|
|
511
|
+
result: {
|
|
512
|
+
content: {
|
|
513
|
+
introduction: 'This is the introduction for the new weekly fishing issue',
|
|
514
|
+
paragraph1: '...',
|
|
515
|
+
},
|
|
516
|
+
title: 'Weekly fishing 21',
|
|
517
|
+
},
|
|
518
|
+
},
|
|
519
|
+
'omit.history': {
|
|
520
|
+
input: null,
|
|
521
|
+
remapper: {},
|
|
522
|
+
result: {},
|
|
523
|
+
skip: true,
|
|
524
|
+
},
|
|
525
|
+
page: {
|
|
526
|
+
input: null,
|
|
527
|
+
remapper: {},
|
|
528
|
+
result: {},
|
|
529
|
+
skip: true,
|
|
530
|
+
},
|
|
531
|
+
prop: {
|
|
532
|
+
input: {
|
|
533
|
+
age: 52,
|
|
534
|
+
name: 'John',
|
|
535
|
+
},
|
|
536
|
+
remapper: {
|
|
537
|
+
prop: 'name',
|
|
538
|
+
},
|
|
539
|
+
result: 'John',
|
|
540
|
+
},
|
|
541
|
+
'random.choice': {
|
|
542
|
+
input: null,
|
|
543
|
+
remapper: {},
|
|
544
|
+
result: {},
|
|
545
|
+
skip: true,
|
|
546
|
+
},
|
|
547
|
+
'random.float': {
|
|
548
|
+
input: null,
|
|
549
|
+
remapper: {},
|
|
550
|
+
result: {},
|
|
551
|
+
skip: true,
|
|
552
|
+
},
|
|
553
|
+
'random.integer': {
|
|
554
|
+
input: null,
|
|
555
|
+
remapper: {},
|
|
556
|
+
result: {},
|
|
557
|
+
skip: true,
|
|
558
|
+
},
|
|
559
|
+
'random.string': {
|
|
560
|
+
input: null,
|
|
561
|
+
remapper: {},
|
|
562
|
+
result: {},
|
|
563
|
+
skip: true,
|
|
564
|
+
},
|
|
565
|
+
root: {
|
|
566
|
+
input: 'input',
|
|
567
|
+
remapper: { root: null },
|
|
568
|
+
result: 'input',
|
|
569
|
+
},
|
|
570
|
+
static: {
|
|
571
|
+
input: null,
|
|
572
|
+
remapper: {
|
|
573
|
+
static: 'Hello!',
|
|
574
|
+
},
|
|
575
|
+
result: 'Hello!',
|
|
576
|
+
},
|
|
577
|
+
step: {
|
|
578
|
+
input: null,
|
|
579
|
+
remapper: {},
|
|
580
|
+
result: {},
|
|
581
|
+
skip: true,
|
|
582
|
+
},
|
|
583
|
+
'string.case': {
|
|
584
|
+
input: 'Patrick',
|
|
585
|
+
remapper: {
|
|
586
|
+
'string.case': 'upper',
|
|
587
|
+
},
|
|
588
|
+
result: 'PATRICK',
|
|
589
|
+
},
|
|
590
|
+
'string.format': {
|
|
591
|
+
input: {
|
|
592
|
+
lotteryPrize: '5000',
|
|
593
|
+
},
|
|
594
|
+
remapper: {
|
|
595
|
+
'string.format': {
|
|
596
|
+
template: 'You have won €{lotteryAmount} in the lottery!!',
|
|
597
|
+
values: {
|
|
598
|
+
lotteryAmount: {
|
|
599
|
+
prop: 'lotteryPrize',
|
|
600
|
+
},
|
|
601
|
+
},
|
|
602
|
+
},
|
|
603
|
+
},
|
|
604
|
+
result: 'You have won €5000 in the lottery!!',
|
|
605
|
+
},
|
|
606
|
+
'string.replace': {
|
|
607
|
+
input: 'Eindhoven is the best city in the Netherlands',
|
|
608
|
+
remapper: {
|
|
609
|
+
'string.replace': {
|
|
610
|
+
'(best*)\\w+': 'cleanest',
|
|
611
|
+
},
|
|
612
|
+
},
|
|
613
|
+
result: 'Eindhoven is the cleanest city in the Netherlands',
|
|
614
|
+
},
|
|
615
|
+
translate: {
|
|
616
|
+
input: null,
|
|
617
|
+
remapper: {},
|
|
618
|
+
result: {},
|
|
619
|
+
skip: true,
|
|
620
|
+
},
|
|
621
|
+
user: {
|
|
622
|
+
input: null,
|
|
623
|
+
remapper: {},
|
|
624
|
+
result: {},
|
|
625
|
+
skip: true,
|
|
626
|
+
},
|
|
627
|
+
};
|
|
628
|
+
/**
|
|
629
|
+
* @param remapper The remapper example to use.
|
|
630
|
+
* @param options The options specifying how to display the example.
|
|
631
|
+
* @returns Example based on the input options.
|
|
632
|
+
*/
|
|
633
|
+
export function schemaExample(remapper, options) {
|
|
634
|
+
const { exclude = [], input = 'inline', result } = options !== null && options !== void 0 ? options : {};
|
|
635
|
+
let example = '';
|
|
636
|
+
if (!exclude.includes('input')) {
|
|
637
|
+
const spacing = input === 'pretty' && 2;
|
|
638
|
+
example += `Input:\n\n\`\`\`json\n${JSON.stringify(examples[remapper].input, null, spacing)}\n\`\`\`\n`;
|
|
639
|
+
}
|
|
640
|
+
if (!exclude.includes('remapper')) {
|
|
641
|
+
example += `\`\`\`yaml\n${stringify(examples[remapper].remapper)}\n\`\`\`\n`;
|
|
642
|
+
}
|
|
643
|
+
if (!exclude.includes('result')) {
|
|
644
|
+
const spacing = result === 'pretty' && 2;
|
|
645
|
+
example += `Result:\n\n\`\`\`json\n${JSON.stringify(examples[remapper].result, null, spacing)}\n\`\`\`\n`;
|
|
646
|
+
}
|
|
647
|
+
return example;
|
|
648
|
+
}
|
|
649
|
+
export function createExampleContext(url, lang, userInfo, history) {
|
|
650
|
+
return {
|
|
651
|
+
getMessage: ({ defaultMessage }) => new IntlMessageFormat(defaultMessage, lang, undefined),
|
|
652
|
+
url: String(url),
|
|
653
|
+
appUrl: `${url.protocol}//example-app.example-organization.${url.host}`,
|
|
654
|
+
userInfo: userInfo !== null && userInfo !== void 0 ? userInfo : {
|
|
655
|
+
sub: 'default-example-sub',
|
|
656
|
+
name: 'default-example-name',
|
|
657
|
+
email: 'default@example.com',
|
|
658
|
+
email_verified: false,
|
|
659
|
+
},
|
|
660
|
+
context: {},
|
|
661
|
+
history: history !== null && history !== void 0 ? history : ['Default example value'],
|
|
662
|
+
appId: 0,
|
|
663
|
+
locale: 'en',
|
|
664
|
+
pageData: { default: 'Page data' },
|
|
665
|
+
appMember: userInfo === null || userInfo === void 0 ? void 0 : userInfo.appMember,
|
|
666
|
+
};
|
|
667
|
+
}
|
|
668
|
+
//# sourceMappingURL=examples.js.map
|
package/index.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ export * from './string.js';
|
|
|
23
23
|
export * from './theme.js';
|
|
24
24
|
export * from './langmap.js';
|
|
25
25
|
export * from './i18n.js';
|
|
26
|
+
export * from './examples.js';
|
|
26
27
|
export * from './serverActions.js';
|
|
27
28
|
export * from './validation.js';
|
|
28
29
|
export * from './convertToCsv.js';
|
package/index.js
CHANGED
|
@@ -23,6 +23,7 @@ export * from './string.js';
|
|
|
23
23
|
export * from './theme.js';
|
|
24
24
|
export * from './langmap.js';
|
|
25
25
|
export * from './i18n.js';
|
|
26
|
+
export * from './examples.js';
|
|
26
27
|
export * from './serverActions.js';
|
|
27
28
|
export * from './validation.js';
|
|
28
29
|
export * from './convertToCsv.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@appsemble/utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.26.0",
|
|
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.
|
|
40
|
+
"@appsemble/types": "0.26.0",
|
|
41
41
|
"axios": "^1.0.0",
|
|
42
42
|
"cron-parser": "^4.0.0",
|
|
43
43
|
"date-fns": "^2.0.0",
|
|
@@ -51,6 +51,7 @@
|
|
|
51
51
|
"openapi-types": "^12.0.0",
|
|
52
52
|
"parse-duration": "^1.0.0",
|
|
53
53
|
"postcss": "^8.0.0",
|
|
54
|
+
"yaml": "^2.0.0",
|
|
54
55
|
"type-fest": "^4.0.0"
|
|
55
56
|
},
|
|
56
57
|
"devDependencies": {
|
|
@@ -59,8 +60,7 @@
|
|
|
59
60
|
"@types/lcm": "^0.0.2",
|
|
60
61
|
"bulma": "0.9.3",
|
|
61
62
|
"koas-core": "^0.7.0",
|
|
62
|
-
"vitest": "^1.0.0"
|
|
63
|
-
"yaml": "^2.0.0"
|
|
63
|
+
"vitest": "^1.0.0"
|
|
64
64
|
},
|
|
65
65
|
"engines": {
|
|
66
66
|
"node": ">=18"
|