@appsemble/utils 0.20.15 → 0.20.17
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/ActionDefinition.js.map +1 -1
- package/api/components/schemas/ActionDefinition.ts +1 -0
- package/api/components/schemas/EachActionDefinition.d.ts +1 -0
- package/api/components/schemas/EachActionDefinition.js +22 -0
- package/api/components/schemas/EachActionDefinition.js.map +1 -0
- package/api/components/schemas/EachActionDefinition.ts +22 -0
- package/api/components/schemas/JSONSchemaAnyOf.js +3 -1
- package/api/components/schemas/JSONSchemaAnyOf.js.map +1 -1
- package/api/components/schemas/JSONSchemaAnyOf.ts +3 -1
- package/api/components/schemas/JSONSchemaArray.js +5 -2
- package/api/components/schemas/JSONSchemaArray.js.map +1 -1
- package/api/components/schemas/JSONSchemaArray.ts +5 -2
- package/api/components/schemas/JSONSchemaBoolean.js +6 -3
- package/api/components/schemas/JSONSchemaBoolean.js.map +1 -1
- package/api/components/schemas/JSONSchemaBoolean.ts +6 -3
- package/api/components/schemas/JSONSchemaEnum.js +6 -3
- package/api/components/schemas/JSONSchemaEnum.js.map +1 -1
- package/api/components/schemas/JSONSchemaEnum.ts +6 -3
- package/api/components/schemas/JSONSchemaInteger.js +6 -3
- package/api/components/schemas/JSONSchemaInteger.js.map +1 -1
- package/api/components/schemas/JSONSchemaInteger.ts +6 -3
- package/api/components/schemas/JSONSchemaMultiType.js +3 -1
- package/api/components/schemas/JSONSchemaMultiType.js.map +1 -1
- package/api/components/schemas/JSONSchemaMultiType.ts +3 -1
- package/api/components/schemas/JSONSchemaNot.js +3 -1
- package/api/components/schemas/JSONSchemaNot.js.map +1 -1
- package/api/components/schemas/JSONSchemaNot.ts +3 -1
- package/api/components/schemas/JSONSchemaNumber.js +6 -3
- package/api/components/schemas/JSONSchemaNumber.js.map +1 -1
- package/api/components/schemas/JSONSchemaNumber.ts +6 -3
- package/api/components/schemas/JSONSchemaObject.js +7 -4
- package/api/components/schemas/JSONSchemaObject.js.map +1 -1
- package/api/components/schemas/JSONSchemaObject.ts +7 -4
- package/api/components/schemas/JSONSchemaString.js +6 -3
- package/api/components/schemas/JSONSchemaString.js.map +1 -1
- package/api/components/schemas/JSONSchemaString.ts +6 -3
- package/api/components/schemas/ObjectRemapperDefinition.js +72 -0
- package/api/components/schemas/ObjectRemapperDefinition.js.map +1 -1
- package/api/components/schemas/ObjectRemapperDefinition.ts +74 -0
- package/api/components/schemas/index.d.ts +1 -0
- package/api/components/schemas/index.js +1 -0
- package/api/components/schemas/index.js.map +1 -1
- package/api/components/schemas/index.ts +1 -0
- package/blockUtils.js +1 -0
- package/blockUtils.js.map +1 -1
- package/blockUtils.ts +1 -0
- package/iterApp.js +3 -0
- package/iterApp.js.map +1 -1
- package/iterApp.ts +4 -0
- package/jsonschema.js +1 -0
- package/jsonschema.js.map +1 -1
- package/jsonschema.ts +1 -0
- package/miscellaneous.js +1 -0
- package/miscellaneous.js.map +1 -1
- package/miscellaneous.ts +1 -0
- package/package.json +2 -2
- package/remap.d.ts +1 -0
- package/remap.js +25 -0
- package/remap.js.map +1 -1
- package/remap.test.js +44 -1
- package/remap.test.js.map +1 -1
- package/remap.test.ts +48 -1
- package/remap.ts +27 -0
- package/types.ts +0 -2
package/remap.test.ts
CHANGED
|
@@ -10,12 +10,13 @@ interface TestCase {
|
|
|
10
10
|
messages?: AppMessages['messages'];
|
|
11
11
|
userInfo?: UserInfo;
|
|
12
12
|
context?: Record<string, any>;
|
|
13
|
+
history?: unknown[];
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
function runTests(tests: Record<string, TestCase>): void {
|
|
16
17
|
it.each(Object.entries(tests))(
|
|
17
18
|
'should %s',
|
|
18
|
-
(name, { context, expected, input, mappers, messages, userInfo }) => {
|
|
19
|
+
(name, { context, expected, history, input, mappers, messages, userInfo }) => {
|
|
19
20
|
const result = remap(mappers, input, {
|
|
20
21
|
getMessage: ({ defaultMessage, id }) =>
|
|
21
22
|
new IntlMessageFormat(messages?.messageIds?.[id] ?? defaultMessage),
|
|
@@ -23,6 +24,7 @@ function runTests(tests: Record<string, TestCase>): void {
|
|
|
23
24
|
appUrl: 'https://example.com',
|
|
24
25
|
userInfo,
|
|
25
26
|
context,
|
|
27
|
+
history,
|
|
26
28
|
appId: 6789,
|
|
27
29
|
locale: 'en',
|
|
28
30
|
pageData: { hello: 'Page data' },
|
|
@@ -776,6 +778,51 @@ describe('root', () => {
|
|
|
776
778
|
});
|
|
777
779
|
});
|
|
778
780
|
|
|
781
|
+
describe('history', () => {
|
|
782
|
+
runTests({
|
|
783
|
+
'return the first history item': {
|
|
784
|
+
input: { input: 'data' },
|
|
785
|
+
history: [{ old: 'monke' }, { latest: 'monke' }],
|
|
786
|
+
mappers: [{ prop: 'input' }, { history: 0 }],
|
|
787
|
+
expected: { old: 'monke' },
|
|
788
|
+
},
|
|
789
|
+
});
|
|
790
|
+
});
|
|
791
|
+
|
|
792
|
+
describe('assign.history', () => {
|
|
793
|
+
runTests({
|
|
794
|
+
'assign the second history item props defined in prop remappers to the output': {
|
|
795
|
+
input: { input: 'data' },
|
|
796
|
+
history: [{ old: 'monke' }, { rescue: 'monke', sadge: 'monke' }],
|
|
797
|
+
mappers: [{ 'assign.history': { index: 1, props: { happy: { prop: 'rescue' } } } }],
|
|
798
|
+
expected: { input: 'data', happy: 'monke' },
|
|
799
|
+
},
|
|
800
|
+
});
|
|
801
|
+
});
|
|
802
|
+
|
|
803
|
+
describe('omit.history', () => {
|
|
804
|
+
runTests({
|
|
805
|
+
'assign the second history item props to the output except omitted props': {
|
|
806
|
+
input: { input: 'data' },
|
|
807
|
+
history: [{ old: 'monke' }, { rescue: 'monke', sadge: 'monke' }],
|
|
808
|
+
mappers: [{ 'omit.history': { index: 1, keys: ['sadge'] } }],
|
|
809
|
+
expected: { input: 'data', rescue: 'monke' },
|
|
810
|
+
},
|
|
811
|
+
'not assign nested omitted props': {
|
|
812
|
+
input: { input: 'data' },
|
|
813
|
+
history: [{ rescue: 'monke', nested: { sadge: 'monke', safe: 'monke' } }],
|
|
814
|
+
mappers: [{ 'omit.history': { index: 0, keys: [['nested', 'sadge']] } }],
|
|
815
|
+
expected: { input: 'data', rescue: 'monke', nested: { safe: 'monke' } },
|
|
816
|
+
},
|
|
817
|
+
'handle non existing properties': {
|
|
818
|
+
input: { input: 'data' },
|
|
819
|
+
history: [{ rescue: 'monke', nested: { happy: 'monke', safe: 'monke' } }],
|
|
820
|
+
mappers: [{ 'omit.history': { index: 0, keys: [['nested', 'nonexistent']] } }],
|
|
821
|
+
expected: { input: 'data', rescue: 'monke', nested: { happy: 'monke', safe: 'monke' } },
|
|
822
|
+
},
|
|
823
|
+
});
|
|
824
|
+
});
|
|
825
|
+
|
|
779
826
|
describe('string.case', () => {
|
|
780
827
|
runTests({
|
|
781
828
|
'convert a string to upper case': {
|
package/remap.ts
CHANGED
|
@@ -79,6 +79,7 @@ export interface RemapperContext {
|
|
|
79
79
|
|
|
80
80
|
interface InternalContext extends RemapperContext {
|
|
81
81
|
root?: unknown;
|
|
82
|
+
history?: unknown[];
|
|
82
83
|
|
|
83
84
|
array?: {
|
|
84
85
|
index: number;
|
|
@@ -352,6 +353,32 @@ const mapperImplementations: MapperImplementations = {
|
|
|
352
353
|
|
|
353
354
|
root: (args, input, context) => context.root,
|
|
354
355
|
|
|
356
|
+
history: (index, input, context) => context.history?.[index],
|
|
357
|
+
|
|
358
|
+
'assign.history': ({ index, props }, input: any, context) => ({
|
|
359
|
+
...input,
|
|
360
|
+
...mapValues(props, (mapper) => remap(mapper, context.history[index], context)),
|
|
361
|
+
}),
|
|
362
|
+
|
|
363
|
+
'omit.history'({ index, keys }, input: Record<string, any>, context) {
|
|
364
|
+
const result = { ...(context.history[index] as Record<string, any>) };
|
|
365
|
+
for (const key of keys) {
|
|
366
|
+
if (Array.isArray(key)) {
|
|
367
|
+
key.reduce((acc, k, i) => {
|
|
368
|
+
if (i === key.length - 1) {
|
|
369
|
+
delete acc[k];
|
|
370
|
+
} else {
|
|
371
|
+
return acc?.[k];
|
|
372
|
+
}
|
|
373
|
+
return acc;
|
|
374
|
+
}, result);
|
|
375
|
+
} else {
|
|
376
|
+
delete result[key];
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
return { ...input, ...result };
|
|
380
|
+
},
|
|
381
|
+
|
|
355
382
|
'string.case'(stringCase, input) {
|
|
356
383
|
if (stringCase === 'lower') {
|
|
357
384
|
return String(input).toLowerCase();
|