@appsemble/lang-sdk 0.33.7
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/BasicValidator.d.ts +56 -0
- package/BasicValidator.js +174 -0
- package/LICENSE.md +126 -0
- package/README.md +119 -0
- package/allActions.d.ts +1 -0
- package/allActions.js +11 -0
- package/appMembers.d.ts +1 -0
- package/appMembers.js +9 -0
- package/authorization.d.ts +10 -0
- package/authorization.js +147 -0
- package/blockUtils.d.ts +31 -0
- package/blockUtils.js +65 -0
- package/constants/baseTheme.d.ts +2 -0
- package/constants/baseTheme.js +16 -0
- package/constants/fonts.d.ts +6 -0
- package/constants/fonts.js +1607 -0
- package/constants/index.d.ts +4 -0
- package/constants/index.js +5 -0
- package/constants/locale.d.ts +4 -0
- package/constants/locale.js +5 -0
- package/constants/patterns.d.ts +41 -0
- package/constants/patterns.js +42 -0
- package/examples.d.ts +23 -0
- package/examples.js +975 -0
- package/findPageByName.d.ts +2 -0
- package/findPageByName.js +15 -0
- package/ics.d.ts +3 -0
- package/ics.js +41 -0
- package/index.d.ts +18 -0
- package/index.js +19 -0
- package/iterApp.d.ts +64 -0
- package/iterApp.js +150 -0
- package/jsonPointer.d.ts +18 -0
- package/jsonPointer.js +24 -0
- package/jsonschema.d.ts +54 -0
- package/jsonschema.js +185 -0
- package/mapValues.d.ts +1 -0
- package/mapValues.js +8 -0
- package/miscellaneous.d.ts +38 -0
- package/miscellaneous.js +66 -0
- package/noop.d.ts +4 -0
- package/noop.js +6 -0
- package/normalize.d.ts +13 -0
- package/normalize.js +24 -0
- package/package.json +66 -0
- package/reference-schemas/actions/appMember.d.ts +2 -0
- package/reference-schemas/actions/appMember.js +21 -0
- package/reference-schemas/actions/flow.d.ts +2 -0
- package/reference-schemas/actions/flow.js +13 -0
- package/reference-schemas/actions/group.d.ts +2 -0
- package/reference-schemas/actions/group.js +13 -0
- package/reference-schemas/actions/index.d.ts +7 -0
- package/reference-schemas/actions/index.js +8 -0
- package/reference-schemas/actions/link.d.ts +2 -0
- package/reference-schemas/actions/link.js +9 -0
- package/reference-schemas/actions/miscellaneous.d.ts +2 -0
- package/reference-schemas/actions/miscellaneous.js +43 -0
- package/reference-schemas/actions/resources.d.ts +2 -0
- package/reference-schemas/actions/resources.js +19 -0
- package/reference-schemas/actions/storage.d.ts +2 -0
- package/reference-schemas/actions/storage.js +15 -0
- package/reference-schemas/index.d.ts +2 -0
- package/reference-schemas/index.js +3 -0
- package/reference-schemas/remappers/arrays.d.ts +2 -0
- package/reference-schemas/remappers/arrays.js +297 -0
- package/reference-schemas/remappers/conditionals.d.ts +2 -0
- package/reference-schemas/remappers/conditionals.js +167 -0
- package/reference-schemas/remappers/config.d.ts +2 -0
- package/reference-schemas/remappers/config.js +13 -0
- package/reference-schemas/remappers/data.d.ts +2 -0
- package/reference-schemas/remappers/data.js +394 -0
- package/reference-schemas/remappers/dates.d.ts +2 -0
- package/reference-schemas/remappers/dates.js +94 -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 +12 -0
- package/reference-schemas/remappers/index.js +13 -0
- package/reference-schemas/remappers/numbers.d.ts +2 -0
- package/reference-schemas/remappers/numbers.js +30 -0
- package/reference-schemas/remappers/objects.d.ts +2 -0
- package/reference-schemas/remappers/objects.js +127 -0
- package/reference-schemas/remappers/odata.d.ts +2 -0
- package/reference-schemas/remappers/odata.js +95 -0
- package/reference-schemas/remappers/randoms.d.ts +2 -0
- package/reference-schemas/remappers/randoms.js +82 -0
- package/reference-schemas/remappers/strings.d.ts +2 -0
- package/reference-schemas/remappers/strings.js +93 -0
- package/reference-schemas/remappers/unsorted.d.ts +2 -0
- package/reference-schemas/remappers/unsorted.js +276 -0
- package/remap.d.ts +75 -0
- package/remap.js +691 -0
- package/schemas/AppDefinition.d.ts +2 -0
- package/schemas/AppDefinition.js +126 -0
- package/schemas/AppLayoutDefinition.d.ts +2 -0
- package/schemas/AppLayoutDefinition.js +59 -0
- package/schemas/AppMemberPropertyDefinition.d.ts +2 -0
- package/schemas/AppMemberPropertyDefinition.js +49 -0
- package/schemas/AppMembersDefinition.d.ts +2 -0
- package/schemas/AppMembersDefinition.js +17 -0
- package/schemas/ArrayRemapperDefinition.d.ts +2 -0
- package/schemas/ArrayRemapperDefinition.js +22 -0
- package/schemas/BasePageDefinition.d.ts +2 -0
- package/schemas/BasePageDefinition.js +92 -0
- package/schemas/BlockDefinition.d.ts +2 -0
- package/schemas/BlockDefinition.js +94 -0
- package/schemas/ContainerDefinition.d.ts +2 -0
- package/schemas/ContainerDefinition.js +52 -0
- package/schemas/ContainerPageDefinition.d.ts +1 -0
- package/schemas/ContainerPageDefinition.js +56 -0
- package/schemas/ControllerDefinition.d.ts +2 -0
- package/schemas/ControllerDefinition.js +17 -0
- package/schemas/CronDefinition.d.ts +2 -0
- package/schemas/CronDefinition.js +20 -0
- package/schemas/CustomFontDefinition.d.ts +2 -0
- package/schemas/CustomFontDefinition.js +20 -0
- package/schemas/EventsDefinition.d.ts +2 -0
- package/schemas/EventsDefinition.js +29 -0
- package/schemas/FilterParametersDefinition.d.ts +2 -0
- package/schemas/FilterParametersDefinition.js +15 -0
- package/schemas/FlowPageActionsDefinition.d.ts +2 -0
- package/schemas/FlowPageActionsDefinition.js +23 -0
- package/schemas/FlowPageDefinition.d.ts +1 -0
- package/schemas/FlowPageDefinition.js +37 -0
- package/schemas/GoogleFontDefinition.d.ts +2 -0
- package/schemas/GoogleFontDefinition.js +22 -0
- package/schemas/LoopPageActionsDefinition.d.ts +2 -0
- package/schemas/LoopPageActionsDefinition.js +24 -0
- package/schemas/LoopPageDefinition.d.ts +1 -0
- package/schemas/LoopPageDefinition.js +32 -0
- package/schemas/NotificationHookDataDefinition.d.ts +2 -0
- package/schemas/NotificationHookDataDefinition.js +24 -0
- package/schemas/NotificationHookDefinition.d.ts +2 -0
- package/schemas/NotificationHookDefinition.js +32 -0
- package/schemas/ObjectRemapperDefinition.d.ts +2 -0
- package/schemas/ObjectRemapperDefinition.js +17 -0
- package/schemas/PageActionsDefinition.d.ts +2 -0
- package/schemas/PageActionsDefinition.js +12 -0
- package/schemas/PageDefinition.d.ts +1 -0
- package/schemas/PageDefinition.js +26 -0
- package/schemas/RemapperDefinition.d.ts +2 -0
- package/schemas/RemapperDefinition.js +27 -0
- package/schemas/ResourceDefinition.d.ts +2 -0
- package/schemas/ResourceDefinition.js +263 -0
- package/schemas/ResourceHistoryDefinition.d.ts +2 -0
- package/schemas/ResourceHistoryDefinition.js +14 -0
- package/schemas/ResourceHooksDefinition.d.ts +2 -0
- package/schemas/ResourceHooksDefinition.js +10 -0
- package/schemas/ResourceViewDefinition.d.ts +2 -0
- package/schemas/ResourceViewDefinition.js +24 -0
- package/schemas/SecurityCronDefinition.d.ts +2 -0
- package/schemas/SecurityCronDefinition.js +26 -0
- package/schemas/SecurityDefaultDefinition.d.ts +2 -0
- package/schemas/SecurityDefaultDefinition.js +34 -0
- package/schemas/SecurityDefinition.d.ts +2 -0
- package/schemas/SecurityDefinition.js +17 -0
- package/schemas/SecurityGuestDefinition.d.ts +2 -0
- package/schemas/SecurityGuestDefinition.js +26 -0
- package/schemas/SecurityRoleDefinition.d.ts +2 -0
- package/schemas/SecurityRoleDefinition.js +35 -0
- package/schemas/SubPage.d.ts +2 -0
- package/schemas/SubPage.js +36 -0
- package/schemas/TabsPageDefinition.d.ts +1 -0
- package/schemas/TabsPageDefinition.js +46 -0
- package/schemas/Theme.d.ts +2 -0
- package/schemas/Theme.js +81 -0
- package/schemas/WebhookDefinition.d.ts +2 -0
- package/schemas/WebhookDefinition.js +17 -0
- package/schemas/actions/ActionDefinition.d.ts +2 -0
- package/schemas/actions/ActionDefinition.js +95 -0
- package/schemas/actions/AnalyticsActionDefinition.d.ts +1 -0
- package/schemas/actions/AnalyticsActionDefinition.js +25 -0
- package/schemas/actions/AppMemberCurrentPatchActionDefinition.d.ts +1 -0
- package/schemas/actions/AppMemberCurrentPatchActionDefinition.js +30 -0
- package/schemas/actions/AppMemberDeleteActionDefinition.d.ts +1 -0
- package/schemas/actions/AppMemberDeleteActionDefinition.js +20 -0
- package/schemas/actions/AppMemberInviteActionDefinition.d.ts +1 -0
- package/schemas/actions/AppMemberInviteActionDefinition.js +24 -0
- package/schemas/actions/AppMemberLoginActionDefinition.d.ts +1 -0
- package/schemas/actions/AppMemberLoginActionDefinition.js +24 -0
- package/schemas/actions/AppMemberLogoutActionDefinition.d.ts +1 -0
- package/schemas/actions/AppMemberLogoutActionDefinition.js +14 -0
- package/schemas/actions/AppMemberPropertiesPatchActionDefinition.d.ts +1 -0
- package/schemas/actions/AppMemberPropertiesPatchActionDefinition.js +26 -0
- package/schemas/actions/AppMemberQueryActionDefinition.d.ts +1 -0
- package/schemas/actions/AppMemberQueryActionDefinition.js +24 -0
- package/schemas/actions/AppMemberRegisterActionDefinition.d.ts +1 -0
- package/schemas/actions/AppMemberRegisterActionDefinition.js +43 -0
- package/schemas/actions/AppMemberRoleUpdateActionDefinition.d.ts +1 -0
- package/schemas/actions/AppMemberRoleUpdateActionDefinition.js +27 -0
- package/schemas/actions/BaseActionDefinition.d.ts +2 -0
- package/schemas/actions/BaseActionDefinition.js +10 -0
- package/schemas/actions/ConditionActionDefinition.d.ts +1 -0
- package/schemas/actions/ConditionActionDefinition.js +30 -0
- package/schemas/actions/ControllerActionDefinition.d.ts +1 -0
- package/schemas/actions/ControllerActionDefinition.js +18 -0
- package/schemas/actions/CsvParseActionDefinition.d.ts +1 -0
- package/schemas/actions/CsvParseActionDefinition.js +22 -0
- package/schemas/actions/DialogActionDefinition.d.ts +1 -0
- package/schemas/actions/DialogActionDefinition.js +40 -0
- package/schemas/actions/DialogErrorActionDefinition.d.ts +1 -0
- package/schemas/actions/DialogErrorActionDefinition.js +17 -0
- package/schemas/actions/DialogOkActionDefinition.d.ts +1 -0
- package/schemas/actions/DialogOkActionDefinition.js +17 -0
- package/schemas/actions/DownloadActionDefinition.d.ts +1 -0
- package/schemas/actions/DownloadActionDefinition.js +19 -0
- package/schemas/actions/EachActionDefinition.d.ts +1 -0
- package/schemas/actions/EachActionDefinition.js +26 -0
- package/schemas/actions/EmailActionDefinition.d.ts +1 -0
- package/schemas/actions/EmailActionDefinition.js +54 -0
- package/schemas/actions/EventActionDefinition.d.ts +1 -0
- package/schemas/actions/EventActionDefinition.js +27 -0
- package/schemas/actions/FlowBackActionDefinition.d.ts +1 -0
- package/schemas/actions/FlowBackActionDefinition.js +16 -0
- package/schemas/actions/FlowCancelActionDefinition.d.ts +1 -0
- package/schemas/actions/FlowCancelActionDefinition.js +14 -0
- package/schemas/actions/FlowFinishActionDefinition.d.ts +1 -0
- package/schemas/actions/FlowFinishActionDefinition.js +16 -0
- package/schemas/actions/FlowNextActionDefinition.d.ts +1 -0
- package/schemas/actions/FlowNextActionDefinition.js +17 -0
- package/schemas/actions/FlowToActionDefinition.d.ts +1 -0
- package/schemas/actions/FlowToActionDefinition.js +21 -0
- package/schemas/actions/GroupMemberDeleteActionDefinition.d.ts +1 -0
- package/schemas/actions/GroupMemberDeleteActionDefinition.js +18 -0
- package/schemas/actions/GroupMemberInviteActionDefinition.d.ts +1 -0
- package/schemas/actions/GroupMemberInviteActionDefinition.js +26 -0
- package/schemas/actions/GroupMemberQueryActionDefinition.d.ts +1 -0
- package/schemas/actions/GroupMemberQueryActionDefinition.js +18 -0
- package/schemas/actions/GroupMemberRoleUpdateActionDefinition.d.ts +1 -0
- package/schemas/actions/GroupMemberRoleUpdateActionDefinition.js +22 -0
- package/schemas/actions/GroupQueryActionDefinition.d.ts +1 -0
- package/schemas/actions/GroupQueryActionDefinition.js +14 -0
- package/schemas/actions/LinkActionDefinition.d.ts +1 -0
- package/schemas/actions/LinkActionDefinition.js +29 -0
- package/schemas/actions/LinkBackActionDefinition.d.ts +1 -0
- package/schemas/actions/LinkBackActionDefinition.js +14 -0
- package/schemas/actions/LinkNextActionDefinition.d.ts +1 -0
- package/schemas/actions/LinkNextActionDefinition.js +14 -0
- package/schemas/actions/LogActionDefinition.d.ts +1 -0
- package/schemas/actions/LogActionDefinition.js +22 -0
- package/schemas/actions/MatchActionDefinition.d.ts +1 -0
- package/schemas/actions/MatchActionDefinition.js +35 -0
- package/schemas/actions/MessageActionDefinition.d.ts +1 -0
- package/schemas/actions/MessageActionDefinition.js +40 -0
- package/schemas/actions/NoopActionDefinition.d.ts +1 -0
- package/schemas/actions/NoopActionDefinition.js +17 -0
- package/schemas/actions/NotifyActionDefinition.d.ts +1 -0
- package/schemas/actions/NotifyActionDefinition.js +32 -0
- package/schemas/actions/RequestActionDefinition.d.ts +1 -0
- package/schemas/actions/RequestActionDefinition.js +75 -0
- package/schemas/actions/ResourceCountActionDefinition.d.ts +1 -0
- package/schemas/actions/ResourceCountActionDefinition.js +22 -0
- package/schemas/actions/ResourceCreateActionDefinition.d.ts +1 -0
- package/schemas/actions/ResourceCreateActionDefinition.js +18 -0
- package/schemas/actions/ResourceDeleteActionDefinition.d.ts +1 -0
- package/schemas/actions/ResourceDeleteActionDefinition.js +18 -0
- package/schemas/actions/ResourceDeleteAllActionDefinition.d.ts +1 -0
- package/schemas/actions/ResourceDeleteAllActionDefinition.js +21 -0
- package/schemas/actions/ResourceDeleteBulkActionDefinition.d.ts +1 -0
- package/schemas/actions/ResourceDeleteBulkActionDefinition.js +18 -0
- package/schemas/actions/ResourceGetActionDefinition.d.ts +1 -0
- package/schemas/actions/ResourceGetActionDefinition.js +25 -0
- package/schemas/actions/ResourceHistoryGetActionDefinition.d.ts +1 -0
- package/schemas/actions/ResourceHistoryGetActionDefinition.js +18 -0
- package/schemas/actions/ResourcePatchActionDefinition.d.ts +1 -0
- package/schemas/actions/ResourcePatchActionDefinition.js +21 -0
- package/schemas/actions/ResourceQueryActionDefinition.d.ts +1 -0
- package/schemas/actions/ResourceQueryActionDefinition.js +26 -0
- package/schemas/actions/ResourceSubscriptionStatusActionDefinition.d.ts +1 -0
- package/schemas/actions/ResourceSubscriptionStatusActionDefinition.js +23 -0
- package/schemas/actions/ResourceSubscriptionSubscribeActionDefinition.d.ts +1 -0
- package/schemas/actions/ResourceSubscriptionSubscribeActionDefinition.js +23 -0
- package/schemas/actions/ResourceSubscriptionToggleActionDefinition.d.ts +1 -0
- package/schemas/actions/ResourceSubscriptionToggleActionDefinition.js +23 -0
- package/schemas/actions/ResourceSubscriptionUnsubscribeActionDefinition.d.ts +1 -0
- package/schemas/actions/ResourceSubscriptionUnsubscribeActionDefinition.js +23 -0
- package/schemas/actions/ResourceUpdateActionDefinition.d.ts +1 -0
- package/schemas/actions/ResourceUpdateActionDefinition.js +18 -0
- package/schemas/actions/ResourceUpdatePositionsActionDefinition.d.ts +1 -0
- package/schemas/actions/ResourceUpdatePositionsActionDefinition.js +21 -0
- package/schemas/actions/ShareActionDefinition.d.ts +1 -0
- package/schemas/actions/ShareActionDefinition.js +30 -0
- package/schemas/actions/StaticActionDefinition.d.ts +1 -0
- package/schemas/actions/StaticActionDefinition.js +20 -0
- package/schemas/actions/StorageAppendActionDefinition.d.ts +1 -0
- package/schemas/actions/StorageAppendActionDefinition.js +43 -0
- package/schemas/actions/StorageDeleteActionDefinition.d.ts +1 -0
- package/schemas/actions/StorageDeleteActionDefinition.js +31 -0
- package/schemas/actions/StorageReadActionDefinition.d.ts +1 -0
- package/schemas/actions/StorageReadActionDefinition.js +32 -0
- package/schemas/actions/StorageSubtractActionDefinition.d.ts +1 -0
- package/schemas/actions/StorageSubtractActionDefinition.js +35 -0
- package/schemas/actions/StorageUpdateActionDefinition.d.ts +1 -0
- package/schemas/actions/StorageUpdateActionDefinition.js +46 -0
- package/schemas/actions/StorageWriteActionDefinition.d.ts +1 -0
- package/schemas/actions/StorageWriteActionDefinition.js +46 -0
- package/schemas/actions/ThrowActionDefinition.d.ts +1 -0
- package/schemas/actions/ThrowActionDefinition.js +17 -0
- package/schemas/index.d.ts +121 -0
- package/schemas/index.js +122 -0
- package/schemas/json/BaseJSONSchema.d.ts +2 -0
- package/schemas/json/BaseJSONSchema.js +24 -0
- package/schemas/json/JSONPointer.d.ts +1 -0
- package/schemas/json/JSONPointer.js +20 -0
- package/schemas/json/JSONSchema.d.ts +2 -0
- package/schemas/json/JSONSchema.js +20 -0
- package/schemas/json/JSONSchemaAnyOf.d.ts +1 -0
- package/schemas/json/JSONSchemaAnyOf.js +26 -0
- package/schemas/json/JSONSchemaArray.d.ts +1 -0
- package/schemas/json/JSONSchemaArray.js +47 -0
- package/schemas/json/JSONSchemaBoolean.d.ts +1 -0
- package/schemas/json/JSONSchemaBoolean.js +37 -0
- package/schemas/json/JSONSchemaConst.d.ts +1 -0
- package/schemas/json/JSONSchemaConst.js +16 -0
- package/schemas/json/JSONSchemaEnum.d.ts +1 -0
- package/schemas/json/JSONSchemaEnum.js +36 -0
- package/schemas/json/JSONSchemaInteger.d.ts +1 -0
- package/schemas/json/JSONSchemaInteger.js +55 -0
- package/schemas/json/JSONSchemaMultiType.d.ts +1 -0
- package/schemas/json/JSONSchemaMultiType.js +48 -0
- package/schemas/json/JSONSchemaNot.d.ts +1 -0
- package/schemas/json/JSONSchemaNot.js +23 -0
- package/schemas/json/JSONSchemaNull.d.ts +1 -0
- package/schemas/json/JSONSchemaNull.js +16 -0
- package/schemas/json/JSONSchemaNumber.d.ts +1 -0
- package/schemas/json/JSONSchemaNumber.js +63 -0
- package/schemas/json/JSONSchemaObject.d.ts +1 -0
- package/schemas/json/JSONSchemaObject.js +74 -0
- package/schemas/json/JSONSchemaOneOf.d.ts +1 -0
- package/schemas/json/JSONSchemaOneOf.js +24 -0
- package/schemas/json/JSONSchemaRemapper.d.ts +1 -0
- package/schemas/json/JSONSchemaRemapper.js +19 -0
- package/schemas/json/JSONSchemaRoot.d.ts +1 -0
- package/schemas/json/JSONSchemaRoot.js +21 -0
- package/schemas/json/JSONSchemaString.d.ts +1 -0
- package/schemas/json/JSONSchemaString.js +107 -0
- package/schemas/utils/extendJSONSchema.d.ts +13 -0
- package/schemas/utils/extendJSONSchema.js +34 -0
- package/serverActions.d.ts +2 -0
- package/serverActions.js +21 -0
- package/string.d.ts +23 -0
- package/string.js +30 -0
- package/types/ActionError.d.ts +38 -0
- package/types/ActionError.js +30 -0
- package/types/action.d.ts +51 -0
- package/types/action.js +2 -0
- package/types/actionDefinition.d.ts +605 -0
- package/types/actionDefinition.js +2 -0
- package/types/block.d.ts +81 -0
- package/types/block.js +2 -0
- package/types/bulma.d.ts +5 -0
- package/types/bulma.js +2 -0
- package/types/container.d.ts +46 -0
- package/types/container.js +2 -0
- package/types/core.d.ts +322 -0
- package/types/core.js +2 -0
- package/types/http.d.ts +6 -0
- package/types/http.js +2 -0
- package/types/index.d.ts +115 -0
- package/types/index.js +17 -0
- package/types/layout.d.ts +2 -0
- package/types/layout.js +2 -0
- package/types/member.d.ts +43 -0
- package/types/member.js +2 -0
- package/types/permission.d.ts +102 -0
- package/types/permission.js +104 -0
- package/types/remapper.d.ts +584 -0
- package/types/remapper.js +2 -0
- package/types/resource.d.ts +145 -0
- package/types/resource.js +2 -0
- package/types/roles.d.ts +20 -0
- package/types/roles.js +61 -0
- package/types/security.d.ts +42 -0
- package/types/security.js +2 -0
- package/types/theme.d.ts +54 -0
- package/types/theme.js +2 -0
- package/validation.d.ts +25 -0
- package/validation.js +1237 -0
package/remap.js
ADDED
|
@@ -0,0 +1,691 @@
|
|
|
1
|
+
import { filter, literalValues, param } from '@odata/parser';
|
|
2
|
+
import { addMilliseconds, format, parse, parseISO } from 'date-fns';
|
|
3
|
+
import equal from 'fast-deep-equal';
|
|
4
|
+
import { XMLParser } from 'fast-xml-parser';
|
|
5
|
+
import { createEvent } from 'ics';
|
|
6
|
+
import parseDuration from 'parse-duration';
|
|
7
|
+
import { getDuration, processLocation } from './ics.js';
|
|
8
|
+
import { mapValues } from './mapValues.js';
|
|
9
|
+
import { has, stripNullValues } from './miscellaneous.js';
|
|
10
|
+
class RemapperError extends TypeError {
|
|
11
|
+
constructor(message, remapper) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.name = 'RemapperError';
|
|
14
|
+
this.remapper = remapper;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function isPlainObject(value) {
|
|
18
|
+
return value != null && typeof value === 'object' && !Array.isArray(value);
|
|
19
|
+
}
|
|
20
|
+
function isEqualArray(a, b) {
|
|
21
|
+
if (a.length !== b.length) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
return a.every((val, i) => val === b[i]);
|
|
25
|
+
}
|
|
26
|
+
function isEqualObject(a, b) {
|
|
27
|
+
const aKeys = Object.keys(a);
|
|
28
|
+
const bKeys = Object.keys(b);
|
|
29
|
+
if (aKeys.length !== bKeys.length) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
return aKeys.every((key) => bKeys.includes(key) && equal(a[key], b[key]));
|
|
33
|
+
}
|
|
34
|
+
function isNumber(a) {
|
|
35
|
+
return a !== undefined && a != null && a !== '' && !Number.isNaN(Number(a));
|
|
36
|
+
}
|
|
37
|
+
export function remap(remapper, input, context) {
|
|
38
|
+
if (typeof remapper === 'string' ||
|
|
39
|
+
typeof remapper === 'number' ||
|
|
40
|
+
typeof remapper === 'boolean' ||
|
|
41
|
+
remapper == null) {
|
|
42
|
+
return remapper;
|
|
43
|
+
}
|
|
44
|
+
let result = input;
|
|
45
|
+
// Workaround for ts(2589) Type instantiation is excessively deep and possibly infinite
|
|
46
|
+
const remappers = Array.isArray(remapper)
|
|
47
|
+
? remapper.flat(Number.POSITIVE_INFINITY)
|
|
48
|
+
: [remapper];
|
|
49
|
+
for (const mapper of remappers) {
|
|
50
|
+
const entries = Object.entries(mapper);
|
|
51
|
+
if (entries.length !== 1) {
|
|
52
|
+
console.error(mapper);
|
|
53
|
+
throw new RemapperError(`Remapper has multiple keys: ${Object.keys(mapper)
|
|
54
|
+
.map((key) => JSON.stringify(key))
|
|
55
|
+
.join(', ')}`, mapper);
|
|
56
|
+
}
|
|
57
|
+
const [[name, args]] = entries;
|
|
58
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
59
|
+
if (!has(mapperImplementations, name)) {
|
|
60
|
+
console.error(mapper);
|
|
61
|
+
throw new RemapperError(`Remapper name does not exist: ${JSON.stringify(name)}`, mapper);
|
|
62
|
+
}
|
|
63
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
64
|
+
const implementation = mapperImplementations[name];
|
|
65
|
+
result = implementation(args, result, { root: input, ...context });
|
|
66
|
+
}
|
|
67
|
+
return result;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Implementations of all remappers.
|
|
71
|
+
*
|
|
72
|
+
* All arguments are deferred from remappers.
|
|
73
|
+
*
|
|
74
|
+
* @see Remappers
|
|
75
|
+
*/
|
|
76
|
+
const mapperImplementations = {
|
|
77
|
+
app(prop, input, context) {
|
|
78
|
+
if (prop === 'id') {
|
|
79
|
+
return context.appId;
|
|
80
|
+
}
|
|
81
|
+
if (prop === 'locale') {
|
|
82
|
+
return context.locale;
|
|
83
|
+
}
|
|
84
|
+
if (prop === 'url') {
|
|
85
|
+
return context.appUrl;
|
|
86
|
+
}
|
|
87
|
+
throw new Error(`Unknown app property: ${prop}`);
|
|
88
|
+
},
|
|
89
|
+
page(prop, input, context) {
|
|
90
|
+
if (prop === 'data') {
|
|
91
|
+
return context.pageData;
|
|
92
|
+
}
|
|
93
|
+
if (prop === 'url') {
|
|
94
|
+
return context.url;
|
|
95
|
+
}
|
|
96
|
+
throw new Error(`Unknown page property: ${prop}`);
|
|
97
|
+
},
|
|
98
|
+
context(prop, input, context) {
|
|
99
|
+
let result = context.context;
|
|
100
|
+
for (const p of String(prop).split('.')) {
|
|
101
|
+
if (result == null) {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
result = result[p];
|
|
105
|
+
}
|
|
106
|
+
return result ?? null;
|
|
107
|
+
},
|
|
108
|
+
variable(name, input, context) {
|
|
109
|
+
if (context.getVariable) {
|
|
110
|
+
return context.getVariable(name);
|
|
111
|
+
}
|
|
112
|
+
return { variable: name };
|
|
113
|
+
},
|
|
114
|
+
equals(mappers, input, context) {
|
|
115
|
+
if (mappers.length <= 1) {
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
118
|
+
const values = mappers.map((mapper) => remap(mapper, input, context));
|
|
119
|
+
return values.every((value) => equal(values[0], value));
|
|
120
|
+
},
|
|
121
|
+
not(mappers, input, context) {
|
|
122
|
+
if (mappers.length <= 1) {
|
|
123
|
+
return !remap(mappers[0], input, context);
|
|
124
|
+
}
|
|
125
|
+
const [firstValue, ...otherValues] = mappers.map((mapper) => remap(mapper, input, context));
|
|
126
|
+
return !otherValues.some((value) => equal(firstValue, value));
|
|
127
|
+
},
|
|
128
|
+
or(mappers, input, context) {
|
|
129
|
+
const values = mappers.map((mapper) => Boolean(remap(mapper, input, context)));
|
|
130
|
+
return values.length > 0 ? values.includes(true) : true;
|
|
131
|
+
},
|
|
132
|
+
and(mappers, input, context) {
|
|
133
|
+
const values = mappers.map((mapper) => remap(mapper, input, context));
|
|
134
|
+
return values.every(Boolean);
|
|
135
|
+
},
|
|
136
|
+
step(mapper, input, context) {
|
|
137
|
+
// eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error
|
|
138
|
+
// @ts-ignore 18048 variable is possibly undefined (strictNullChecks)
|
|
139
|
+
return context.stepRef.current[mapper];
|
|
140
|
+
},
|
|
141
|
+
'tab.name'(mapper, input, context) {
|
|
142
|
+
// eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error
|
|
143
|
+
// @ts-ignore 18048 variable is possibly undefined (strictNullChecks)
|
|
144
|
+
return context.tabRef.current.name;
|
|
145
|
+
},
|
|
146
|
+
gt: ([left, right], input, context) =>
|
|
147
|
+
// eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error
|
|
148
|
+
// @ts-ignore Messed up - 2571 Object is of type 'unknown'.
|
|
149
|
+
remap(left, input, context) > remap(right, input, context),
|
|
150
|
+
lt: ([left, right], input, context) =>
|
|
151
|
+
// eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error
|
|
152
|
+
// @ts-ignore Messed up - 2571 Object is of type 'unknown'.
|
|
153
|
+
remap(left, input, context) < remap(right, input, context),
|
|
154
|
+
ics(mappers, input, context) {
|
|
155
|
+
let event;
|
|
156
|
+
const mappedStart = remap(mappers.start, input, context);
|
|
157
|
+
const start = mappedStart instanceof Date ? mappedStart : parseISO(mappedStart);
|
|
158
|
+
const sharedAttributes = {
|
|
159
|
+
start: [
|
|
160
|
+
start.getUTCFullYear(),
|
|
161
|
+
start.getUTCMonth() + 1,
|
|
162
|
+
start.getUTCDate(),
|
|
163
|
+
start.getUTCHours(),
|
|
164
|
+
start.getUTCMinutes(),
|
|
165
|
+
],
|
|
166
|
+
startInputType: 'utc',
|
|
167
|
+
startOutputType: 'utc',
|
|
168
|
+
title: remap(mappers.title, input, context),
|
|
169
|
+
description: remap(mappers.description ?? null, input, context),
|
|
170
|
+
url: remap(mappers.url ?? null, input, context),
|
|
171
|
+
location: remap(mappers.location ?? null, input, context),
|
|
172
|
+
geo: processLocation(remap(mappers.coordinates ?? null, input, context)),
|
|
173
|
+
productId: context.appUrl,
|
|
174
|
+
};
|
|
175
|
+
if ('end' in mappers) {
|
|
176
|
+
const mappedEnd = remap(mappers.end, input, context);
|
|
177
|
+
const end = mappedEnd instanceof Date ? mappedEnd : parseISO(mappedEnd);
|
|
178
|
+
event = {
|
|
179
|
+
...sharedAttributes,
|
|
180
|
+
endInputType: 'utc',
|
|
181
|
+
endOutputType: 'utc',
|
|
182
|
+
end: [
|
|
183
|
+
end.getUTCFullYear(),
|
|
184
|
+
end.getUTCMonth() + 1,
|
|
185
|
+
end.getUTCDate(),
|
|
186
|
+
end.getUTCHours(),
|
|
187
|
+
end.getUTCMinutes(),
|
|
188
|
+
],
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
event = {
|
|
193
|
+
...sharedAttributes,
|
|
194
|
+
duration: getDuration(remap(mappers.duration, input, context)),
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
const { error, value } = createEvent(event);
|
|
198
|
+
if (error) {
|
|
199
|
+
throw error;
|
|
200
|
+
}
|
|
201
|
+
return value;
|
|
202
|
+
},
|
|
203
|
+
if(mappers, input, context) {
|
|
204
|
+
const condition = remap(mappers.condition, input, context);
|
|
205
|
+
return remap(condition ? mappers.then : mappers.else, input, context);
|
|
206
|
+
},
|
|
207
|
+
match(mappers, input, context) {
|
|
208
|
+
return (remap(mappers.find((mapper) => remap(mapper.case, input, context))?.value ?? null, input, context) ?? null);
|
|
209
|
+
},
|
|
210
|
+
'object.from': (mappers, input, context) => mapValues(mappers, (mapper) => remap(mapper, input, context)),
|
|
211
|
+
'object.assign': (mappers, input, context) => ({
|
|
212
|
+
...input,
|
|
213
|
+
...mapValues(mappers, (mapper) => remap(mapper, input, context)),
|
|
214
|
+
}),
|
|
215
|
+
// eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error
|
|
216
|
+
// @ts-ignore 2322 ... is not assignable to type (strictNullChecks)
|
|
217
|
+
'object.omit'(keys, input) {
|
|
218
|
+
const result = { ...input };
|
|
219
|
+
for (const key of keys) {
|
|
220
|
+
if (Array.isArray(key)) {
|
|
221
|
+
let acc = result;
|
|
222
|
+
for (const [index, k] of key.entries()) {
|
|
223
|
+
if (index === key.length - 1) {
|
|
224
|
+
delete acc[k];
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
acc = acc?.[k];
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
delete result[key];
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
return result;
|
|
236
|
+
},
|
|
237
|
+
'object.compare'([remapper1, remapper2], input, context) {
|
|
238
|
+
const remapped1 = remap(remapper1, input, context);
|
|
239
|
+
const remapped2 = remap(remapper2, input, context);
|
|
240
|
+
function deepDiff(object1, object2) {
|
|
241
|
+
const stack = [{ obj1: object1, obj2: object2, path: [] }];
|
|
242
|
+
const diffs = [];
|
|
243
|
+
while (stack.length !== 0) {
|
|
244
|
+
const { obj1, obj2, path } = stack.pop();
|
|
245
|
+
const keys = new Set([...Object.keys(obj1 || {}), ...Object.keys(obj2 || {})]);
|
|
246
|
+
for (const key of keys) {
|
|
247
|
+
const val1 = obj1?.[key];
|
|
248
|
+
const val2 = obj2?.[key];
|
|
249
|
+
const currentPath = [...path, key];
|
|
250
|
+
if (isPlainObject(val1) && isPlainObject(val2)) {
|
|
251
|
+
stack.push({ obj1: val1, obj2: val2, path: currentPath });
|
|
252
|
+
}
|
|
253
|
+
else if (Array.isArray(val1) && Array.isArray(val2) && !isEqualArray(val1, val2)) {
|
|
254
|
+
diffs.push({ path: currentPath, type: 'changed', from: val1, to: val2 });
|
|
255
|
+
}
|
|
256
|
+
else if (!(key in obj1)) {
|
|
257
|
+
diffs.push({ path: currentPath, type: 'added', value: val2 });
|
|
258
|
+
}
|
|
259
|
+
else if (!(key in obj2)) {
|
|
260
|
+
diffs.push({ path: currentPath, type: 'removed', value: val1 });
|
|
261
|
+
}
|
|
262
|
+
else if (val1 !== val2) {
|
|
263
|
+
diffs.push({ path: currentPath, type: 'changed', from: val1, to: val2 });
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
return diffs;
|
|
268
|
+
}
|
|
269
|
+
if (!isPlainObject(remapped1) || !isPlainObject(remapped2)) {
|
|
270
|
+
return [];
|
|
271
|
+
}
|
|
272
|
+
return deepDiff(remapped1, remapped2);
|
|
273
|
+
},
|
|
274
|
+
'object.explode'(property, input) {
|
|
275
|
+
if (!isPlainObject(input)) {
|
|
276
|
+
return [];
|
|
277
|
+
}
|
|
278
|
+
const { [property]: arrayValue, ...rest } = input;
|
|
279
|
+
if (!Array.isArray(arrayValue)) {
|
|
280
|
+
return [];
|
|
281
|
+
}
|
|
282
|
+
return arrayValue.map((item) => ({
|
|
283
|
+
...rest,
|
|
284
|
+
...item,
|
|
285
|
+
}));
|
|
286
|
+
},
|
|
287
|
+
type(args, input) {
|
|
288
|
+
// eslint-disable-next-line eqeqeq
|
|
289
|
+
if (input === null) {
|
|
290
|
+
return null;
|
|
291
|
+
}
|
|
292
|
+
if (Array.isArray(input)) {
|
|
293
|
+
return 'array';
|
|
294
|
+
}
|
|
295
|
+
return typeof input;
|
|
296
|
+
},
|
|
297
|
+
// eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error
|
|
298
|
+
// @ts-ignore 2322 ... is not assignable to type (strictNullChecks)
|
|
299
|
+
'array.map': (mapper, input, context) => input?.map((item, index) => remap(mapper, item, {
|
|
300
|
+
...context,
|
|
301
|
+
array: {
|
|
302
|
+
index,
|
|
303
|
+
length: input.length,
|
|
304
|
+
item,
|
|
305
|
+
prevItem: input[index - 1],
|
|
306
|
+
nextItem: input[index + 1],
|
|
307
|
+
},
|
|
308
|
+
})) ?? [],
|
|
309
|
+
'array.contains'(mapper, input, context) {
|
|
310
|
+
if (!Array.isArray(input)) {
|
|
311
|
+
return false;
|
|
312
|
+
}
|
|
313
|
+
const remapped = remap(mapper, input, context);
|
|
314
|
+
if (isPlainObject(remapped)) {
|
|
315
|
+
return input.some((item) => isEqualObject(item, remapped ?? {}));
|
|
316
|
+
}
|
|
317
|
+
if (Array.isArray(remapped)) {
|
|
318
|
+
return input.some((item) => isEqualArray(item, remapped));
|
|
319
|
+
}
|
|
320
|
+
return input.includes(remapped);
|
|
321
|
+
},
|
|
322
|
+
'array.unique'(mapper, input, context) {
|
|
323
|
+
if (!Array.isArray(input)) {
|
|
324
|
+
return input;
|
|
325
|
+
}
|
|
326
|
+
const remapped = input.map((item, index) => mapper == null
|
|
327
|
+
? item
|
|
328
|
+
: remap(mapper, item, {
|
|
329
|
+
...context,
|
|
330
|
+
array: {
|
|
331
|
+
index,
|
|
332
|
+
length: input.length,
|
|
333
|
+
item,
|
|
334
|
+
prevItem: input[index - 1],
|
|
335
|
+
nextItem: input[index + 1],
|
|
336
|
+
},
|
|
337
|
+
}));
|
|
338
|
+
return input.filter((value, index) => {
|
|
339
|
+
for (let i = 0; i < index; i += 1) {
|
|
340
|
+
if (equal(remapped[index], remapped[i])) {
|
|
341
|
+
return false;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
return true;
|
|
345
|
+
});
|
|
346
|
+
},
|
|
347
|
+
// eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error
|
|
348
|
+
// @ts-ignore 2322 ... is not assignable to type (strictNullChecks)
|
|
349
|
+
array: (prop, input, context) => context.array?.[prop],
|
|
350
|
+
// eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error
|
|
351
|
+
// @ts-ignore 2322 ... is not assignable to type (strictNullChecks)
|
|
352
|
+
'array.filter'(mapper, input, context) {
|
|
353
|
+
if (!Array.isArray(input)) {
|
|
354
|
+
console.error(`${input} is not an array!`);
|
|
355
|
+
return null;
|
|
356
|
+
}
|
|
357
|
+
return input?.filter((item, index) => {
|
|
358
|
+
const remapped = remap(mapper, item, {
|
|
359
|
+
...context,
|
|
360
|
+
array: {
|
|
361
|
+
index,
|
|
362
|
+
length: input.length,
|
|
363
|
+
item,
|
|
364
|
+
prevItem: input[index - 1],
|
|
365
|
+
nextItem: input[index + 1],
|
|
366
|
+
},
|
|
367
|
+
});
|
|
368
|
+
return remapped;
|
|
369
|
+
});
|
|
370
|
+
},
|
|
371
|
+
// eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error
|
|
372
|
+
// @ts-ignore 2322 ... is not assignable to type (strictNullChecks)
|
|
373
|
+
'array.find'(mapper, input, context) {
|
|
374
|
+
if (!Array.isArray(input)) {
|
|
375
|
+
console.error(`${input} is not an array!`);
|
|
376
|
+
return null;
|
|
377
|
+
}
|
|
378
|
+
return (input?.find((item) => {
|
|
379
|
+
const remapped = remap(mapper, item, context);
|
|
380
|
+
switch (typeof remapped) {
|
|
381
|
+
case 'boolean':
|
|
382
|
+
return remap(mapper, item, context) ? item : null;
|
|
383
|
+
default:
|
|
384
|
+
return equal(remapped, item) ? item : null;
|
|
385
|
+
}
|
|
386
|
+
}) ?? null);
|
|
387
|
+
},
|
|
388
|
+
'array.from': (mappers, input, context) => mappers.map((mapper) => remap(mapper, input, context)),
|
|
389
|
+
'array.append': (mappers, input, context) => Array.isArray(input)
|
|
390
|
+
? input.concat(mappers.map((mapper) => remap(mapper, input, context)))
|
|
391
|
+
: [],
|
|
392
|
+
'array.omit'(mappers, input, context) {
|
|
393
|
+
const indices = new Set(mappers.map((mapper) => {
|
|
394
|
+
const remapped = remap(mapper, input, context);
|
|
395
|
+
if (typeof remapped === 'number') {
|
|
396
|
+
return remapped;
|
|
397
|
+
}
|
|
398
|
+
}));
|
|
399
|
+
return Array.isArray(input) ? input.filter((value, i) => !indices.has(i)) : [];
|
|
400
|
+
},
|
|
401
|
+
'array.flatten'(mapper, input, context) {
|
|
402
|
+
if (!Array.isArray(input)) {
|
|
403
|
+
return input;
|
|
404
|
+
}
|
|
405
|
+
const depth = remap(mapper, input, context);
|
|
406
|
+
return input.flat(depth || Number.POSITIVE_INFINITY);
|
|
407
|
+
},
|
|
408
|
+
static: (input) => input,
|
|
409
|
+
prop(prop, obj, context) {
|
|
410
|
+
let result = obj;
|
|
411
|
+
if (result == null) {
|
|
412
|
+
return result;
|
|
413
|
+
}
|
|
414
|
+
if (Array.isArray(prop)) {
|
|
415
|
+
if (prop.every((item) => typeof item === 'number' || typeof item === 'string')) {
|
|
416
|
+
// This runs if the provided value is an array of property names or indexes
|
|
417
|
+
for (const p of [prop].flat()) {
|
|
418
|
+
result = result[p];
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
else if (prop.every((item) => typeof item === 'object' && !Array.isArray(item))) {
|
|
422
|
+
// This runs if the provided value is an array of remappers
|
|
423
|
+
const remapped = remap(prop, obj, context);
|
|
424
|
+
if (typeof remapped === 'number' || typeof remapped === 'string') {
|
|
425
|
+
result = result[remapped];
|
|
426
|
+
}
|
|
427
|
+
else {
|
|
428
|
+
console.error(`Invalid remapper ${JSON.stringify(prop)}`);
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
else if (typeof prop === 'object') {
|
|
433
|
+
if (prop == null) {
|
|
434
|
+
result = result.null;
|
|
435
|
+
return result;
|
|
436
|
+
}
|
|
437
|
+
// This runs if the provided value is a remapper
|
|
438
|
+
const remapped = remap(prop, result, context);
|
|
439
|
+
if (typeof remapped === 'number' || typeof remapped === 'string') {
|
|
440
|
+
result = result[remapped];
|
|
441
|
+
}
|
|
442
|
+
else {
|
|
443
|
+
console.error(`Invalid remapper ${JSON.stringify(prop)}`);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
else if (typeof prop === 'number' || typeof prop === 'string') {
|
|
447
|
+
result =
|
|
448
|
+
Array.isArray(result) && typeof prop === 'number' && prop < 0
|
|
449
|
+
? result[result.length + prop]
|
|
450
|
+
: result[prop];
|
|
451
|
+
}
|
|
452
|
+
return result;
|
|
453
|
+
},
|
|
454
|
+
'number.parse'(remapper, input, context) {
|
|
455
|
+
if (!remapper) {
|
|
456
|
+
const inputConverted = Number(input);
|
|
457
|
+
if (!Number.isNaN(inputConverted)) {
|
|
458
|
+
return inputConverted;
|
|
459
|
+
}
|
|
460
|
+
return input;
|
|
461
|
+
}
|
|
462
|
+
const remapped = remap(remapper, input, context);
|
|
463
|
+
const remappedConverted = Number(remapped);
|
|
464
|
+
if (!Number.isNaN(remappedConverted)) {
|
|
465
|
+
return remappedConverted;
|
|
466
|
+
}
|
|
467
|
+
return remapped;
|
|
468
|
+
},
|
|
469
|
+
// eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error
|
|
470
|
+
// @ts-ignore 2322 ... is not assignable to type (strictNullChecks)
|
|
471
|
+
'date.parse': (fmt, input) => (fmt ? parse(input, fmt, new Date()) : parseISO(input)),
|
|
472
|
+
'date.now': () => new Date(),
|
|
473
|
+
'date.add'(time, input) {
|
|
474
|
+
const expireDuration = parseDuration(time);
|
|
475
|
+
if (!expireDuration || !input || (!Number.isFinite(input) && !(input instanceof Date))) {
|
|
476
|
+
return input;
|
|
477
|
+
}
|
|
478
|
+
return addMilliseconds(input, expireDuration);
|
|
479
|
+
},
|
|
480
|
+
'date.format'(args, input) {
|
|
481
|
+
const date = input instanceof Date
|
|
482
|
+
? input
|
|
483
|
+
: typeof input === 'number'
|
|
484
|
+
? new Date(input)
|
|
485
|
+
: parseISO(String(input));
|
|
486
|
+
return args ? format(date, args) : date.toJSON();
|
|
487
|
+
},
|
|
488
|
+
'null.strip': (args, input) => stripNullValues(input, args || {}),
|
|
489
|
+
// eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error
|
|
490
|
+
// @ts-ignore 2322 ... is not assignable to type (strictNullChecks)
|
|
491
|
+
'random.choice': (args, input) => Array.isArray(input) ? input[Math.floor(Math.random() * input.length)] : input,
|
|
492
|
+
'random.integer'(args) {
|
|
493
|
+
const min = Math.min(...args);
|
|
494
|
+
const max = Math.max(...args);
|
|
495
|
+
return Math.floor(Math.random() * (max - min) + min);
|
|
496
|
+
},
|
|
497
|
+
'random.float'(args) {
|
|
498
|
+
const min = Math.min(...args);
|
|
499
|
+
const max = Math.max(...args);
|
|
500
|
+
return Math.random() * (max - min) + min;
|
|
501
|
+
},
|
|
502
|
+
'random.string'(args) {
|
|
503
|
+
const result = [];
|
|
504
|
+
const characters = [...new Set(args.choice.split(''))];
|
|
505
|
+
for (let i = 0; i <= args.length; i += 1) {
|
|
506
|
+
result.push(characters[Math.floor(Math.random() * characters.length)]);
|
|
507
|
+
}
|
|
508
|
+
return result.join('');
|
|
509
|
+
},
|
|
510
|
+
root: (args, input, context) => context.root,
|
|
511
|
+
// eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error
|
|
512
|
+
// @ts-ignore 2322 ... is not assignable to type (strictNullChecks)
|
|
513
|
+
len: (args, input) => input?.length,
|
|
514
|
+
history: (index, input, context) => context.history?.[index],
|
|
515
|
+
'from.history': ({ index, props }, input, context) => mapValues(props, (mapper) => remap(mapper, context.history?.[index], context)),
|
|
516
|
+
'assign.history': ({ index, props }, input, context) => ({
|
|
517
|
+
...input,
|
|
518
|
+
...mapValues(props, (mapper) => remap(mapper, context.history?.[index], context)),
|
|
519
|
+
}),
|
|
520
|
+
// eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error
|
|
521
|
+
// @ts-ignore 2322 ... is not assignable to type (strictNullChecks)
|
|
522
|
+
'omit.history'({ index, keys }, input, context) {
|
|
523
|
+
const result = { ...context.history?.[index] };
|
|
524
|
+
for (const key of keys) {
|
|
525
|
+
if (Array.isArray(key)) {
|
|
526
|
+
let acc = result;
|
|
527
|
+
for (const [i, k] of key.entries()) {
|
|
528
|
+
if (i === key.length - 1) {
|
|
529
|
+
delete acc[k];
|
|
530
|
+
}
|
|
531
|
+
else {
|
|
532
|
+
acc = acc?.[k];
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
else {
|
|
537
|
+
delete result[key];
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
return { ...input, ...result };
|
|
541
|
+
},
|
|
542
|
+
'string.case'(stringCase, input) {
|
|
543
|
+
if (stringCase === 'lower') {
|
|
544
|
+
return String(input).toLowerCase();
|
|
545
|
+
}
|
|
546
|
+
if (stringCase === 'upper') {
|
|
547
|
+
return String(input).toUpperCase();
|
|
548
|
+
}
|
|
549
|
+
return input;
|
|
550
|
+
},
|
|
551
|
+
'string.contains'(stringToCheck, input) {
|
|
552
|
+
if (!(typeof input === 'string')) {
|
|
553
|
+
return false;
|
|
554
|
+
}
|
|
555
|
+
return input.includes(stringToCheck);
|
|
556
|
+
},
|
|
557
|
+
// eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error
|
|
558
|
+
// @ts-ignore 2322 ... is not assignable to type (strictNullChecks)
|
|
559
|
+
'string.startsWith'(substring, input) {
|
|
560
|
+
if (typeof substring === 'string') {
|
|
561
|
+
return input.startsWith(substring);
|
|
562
|
+
}
|
|
563
|
+
if (substring.strict || substring.strict === undefined) {
|
|
564
|
+
return input.startsWith(substring.substring);
|
|
565
|
+
}
|
|
566
|
+
return input.toLowerCase().startsWith(substring.substring.toLowerCase());
|
|
567
|
+
},
|
|
568
|
+
// eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error
|
|
569
|
+
// @ts-ignore 2322 ... is not assignable to type (strictNullChecks)
|
|
570
|
+
'string.endsWith'(substring, input) {
|
|
571
|
+
if (typeof substring === 'string') {
|
|
572
|
+
return input.endsWith(substring);
|
|
573
|
+
}
|
|
574
|
+
if (substring.strict || substring.strict === undefined) {
|
|
575
|
+
return input.endsWith(substring.substring);
|
|
576
|
+
}
|
|
577
|
+
return input.toLowerCase().endsWith(substring.substring.toLowerCase());
|
|
578
|
+
},
|
|
579
|
+
// eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error
|
|
580
|
+
// @ts-ignore 2322 null is not assignable to type (strictNullChecks)
|
|
581
|
+
slice(sliceIndex, input) {
|
|
582
|
+
try {
|
|
583
|
+
return Array.isArray(sliceIndex) ? input.slice(...sliceIndex) : input.slice(sliceIndex);
|
|
584
|
+
}
|
|
585
|
+
catch {
|
|
586
|
+
return null;
|
|
587
|
+
}
|
|
588
|
+
},
|
|
589
|
+
log(level, input, context) {
|
|
590
|
+
console[level ?? 'info'](JSON.stringify({ input, context }, null, 2));
|
|
591
|
+
return input;
|
|
592
|
+
},
|
|
593
|
+
'string.format'({ messageId, template, values }, input, context) {
|
|
594
|
+
try {
|
|
595
|
+
const remappedMessageId = remap(messageId ?? null, input, context);
|
|
596
|
+
const message = context.getMessage({ id: remappedMessageId, defaultMessage: template });
|
|
597
|
+
return message.format(values ? mapValues(values, (val) => remap(val, input, context)) : undefined);
|
|
598
|
+
}
|
|
599
|
+
catch (error) {
|
|
600
|
+
if (messageId) {
|
|
601
|
+
return `{${messageId}}`;
|
|
602
|
+
}
|
|
603
|
+
return error.message;
|
|
604
|
+
}
|
|
605
|
+
},
|
|
606
|
+
'string.replace'(values, input) {
|
|
607
|
+
const [[regex, replacer]] = Object.entries(values);
|
|
608
|
+
return String(input).replaceAll(new RegExp(regex, 'gm'), replacer);
|
|
609
|
+
},
|
|
610
|
+
translate(messageId, input, context) {
|
|
611
|
+
const remappedId = remap(messageId, input, context);
|
|
612
|
+
if (typeof remappedId !== 'string') {
|
|
613
|
+
return null;
|
|
614
|
+
}
|
|
615
|
+
const message = context.getMessage({ id: remappedId });
|
|
616
|
+
return message.format() || `{${remappedId}}`;
|
|
617
|
+
},
|
|
618
|
+
'app.member': (property, input, context) => context.appMemberInfo?.[property],
|
|
619
|
+
container(property, input, context) {
|
|
620
|
+
// This value is replaced when the request is made
|
|
621
|
+
// By using the value of the release name
|
|
622
|
+
const namespace = 'companion-containers-appsemble';
|
|
623
|
+
const appName = context.appUrl.split('.')[0].replace(/^https?:\/\//, '');
|
|
624
|
+
const endpoint = property.split('/').slice(1).join('/');
|
|
625
|
+
const containerName = `${property.split('/')[0]}-${appName}-${context.appId}`
|
|
626
|
+
.replaceAll(' ', '-')
|
|
627
|
+
.toLowerCase();
|
|
628
|
+
const url = `http://${containerName}.${namespace}.svc.cluster.local/${endpoint}`;
|
|
629
|
+
return url;
|
|
630
|
+
},
|
|
631
|
+
'filter.from'(values, input, context) {
|
|
632
|
+
let result = filter();
|
|
633
|
+
for (const [field, { comparator, type, value }] of Object.entries(values)) {
|
|
634
|
+
const remapped = remap(value, input, context);
|
|
635
|
+
const remappedDefined = remapped === undefined ? null : remapped;
|
|
636
|
+
const literal = type === 'String' && remapped != null
|
|
637
|
+
? literalValues[type](String(remappedDefined).replaceAll("'", "''").replaceAll('\\', '\\\\'))
|
|
638
|
+
: literalValues[type === 'Number' ? 'Decimal' : type](remappedDefined);
|
|
639
|
+
result = result.field(field)[comparator](literal);
|
|
640
|
+
}
|
|
641
|
+
return String(param().filter(result)).replace(/^\$filter=/, '');
|
|
642
|
+
},
|
|
643
|
+
'order.from'(values) {
|
|
644
|
+
return String(param().orderby(Object.entries(values).map(([key, order]) => ({ field: key, order })))).replace('$orderby=', '');
|
|
645
|
+
},
|
|
646
|
+
'xml.parse'(value, input, context) {
|
|
647
|
+
const parser = new XMLParser({
|
|
648
|
+
ignoreAttributes: false,
|
|
649
|
+
attributeNamePrefix: '',
|
|
650
|
+
});
|
|
651
|
+
try {
|
|
652
|
+
return parser.parse(remap(value, input, context) || '');
|
|
653
|
+
}
|
|
654
|
+
catch (error) {
|
|
655
|
+
console.error(error);
|
|
656
|
+
return {};
|
|
657
|
+
}
|
|
658
|
+
},
|
|
659
|
+
defined(value, input, context) {
|
|
660
|
+
const remapped = remap(value, input, context);
|
|
661
|
+
return remapped !== undefined && remapped != null;
|
|
662
|
+
},
|
|
663
|
+
maths(value, input, context) {
|
|
664
|
+
const { a, b, operation } = value;
|
|
665
|
+
const aRemapped = remap(a, input, context);
|
|
666
|
+
const bRemapped = remap(b, input, context);
|
|
667
|
+
if (!isNumber(aRemapped) || !isNumber(bRemapped)) {
|
|
668
|
+
return -1;
|
|
669
|
+
}
|
|
670
|
+
const na = Number(aRemapped);
|
|
671
|
+
const nb = Number(bRemapped);
|
|
672
|
+
switch (operation) {
|
|
673
|
+
case 'add':
|
|
674
|
+
return na + nb;
|
|
675
|
+
case 'subtract':
|
|
676
|
+
return na - nb;
|
|
677
|
+
case 'multiply':
|
|
678
|
+
return na * nb;
|
|
679
|
+
case 'divide':
|
|
680
|
+
if (nb === 0) {
|
|
681
|
+
return -1;
|
|
682
|
+
}
|
|
683
|
+
return na / nb;
|
|
684
|
+
case 'mod':
|
|
685
|
+
return na % nb;
|
|
686
|
+
default:
|
|
687
|
+
return -1;
|
|
688
|
+
}
|
|
689
|
+
},
|
|
690
|
+
};
|
|
691
|
+
//# sourceMappingURL=remap.js.map
|