@omnia/velcron 6.100.8-dev

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.
Files changed (114) hide show
  1. package/README.md +6 -0
  2. package/actions/ActionResults.d.ts +4 -0
  3. package/actions/ActionResults.js +14 -0
  4. package/actions/Alert.d.ts +2 -0
  5. package/actions/Alert.js +12 -0
  6. package/actions/Array.d.ts +3 -0
  7. package/actions/Array.js +22 -0
  8. package/actions/Debounce.d.ts +2 -0
  9. package/actions/Debounce.js +43 -0
  10. package/actions/Delay.d.ts +2 -0
  11. package/actions/Delay.js +14 -0
  12. package/actions/Emit.d.ts +2 -0
  13. package/actions/Emit.js +25 -0
  14. package/actions/Http.d.ts +2 -0
  15. package/actions/Http.js +32 -0
  16. package/actions/IActionHandler.d.ts +5 -0
  17. package/actions/IActionHandler.js +2 -0
  18. package/actions/Log.d.ts +2 -0
  19. package/actions/Log.js +10 -0
  20. package/actions/MsGraph.d.ts +2 -0
  21. package/actions/MsGraph.js +16 -0
  22. package/actions/MsSharePoint.d.ts +2 -0
  23. package/actions/MsSharePoint.js +17 -0
  24. package/actions/index.d.ts +11 -0
  25. package/actions/index.js +14 -0
  26. package/index.d.ts +6 -0
  27. package/index.js +9 -0
  28. package/internal-do-not-import-from-here/shared/models/Bring.d.ts +23 -0
  29. package/internal-do-not-import-from-here/shared/models/Bring.js +2 -0
  30. package/internal-do-not-import-from-here/shared/models/Broadcasting.d.ts +25 -0
  31. package/internal-do-not-import-from-here/shared/models/Broadcasting.js +12 -0
  32. package/internal-do-not-import-from-here/shared/models/Future.d.ts +44 -0
  33. package/internal-do-not-import-from-here/shared/models/Future.js +122 -0
  34. package/internal-do-not-import-from-here/shared/models/Guid.d.ts +17 -0
  35. package/internal-do-not-import-from-here/shared/models/Guid.js +51 -0
  36. package/internal-do-not-import-from-here/shared/models/OmniaSharedBootstrapData.d.ts +32 -0
  37. package/internal-do-not-import-from-here/shared/models/OmniaSharedBootstrapData.js +2 -0
  38. package/internal-do-not-import-from-here/shared/models/Realtime.d.ts +40 -0
  39. package/internal-do-not-import-from-here/shared/models/Realtime.js +40 -0
  40. package/internal-do-not-import-from-here/shared/models/SharedConstants.d.ts +5 -0
  41. package/internal-do-not-import-from-here/shared/models/SharedConstants.js +9 -0
  42. package/internal-do-not-import-from-here/shared/models/StringExtensions.d.ts +6 -0
  43. package/internal-do-not-import-from-here/shared/models/StringExtensions.js +3 -0
  44. package/internal-do-not-import-from-here/shared/models/Tenant.d.ts +4 -0
  45. package/internal-do-not-import-from-here/shared/models/Tenant.js +2 -0
  46. package/internal-do-not-import-from-here/shared/models/Tokens.d.ts +14 -0
  47. package/internal-do-not-import-from-here/shared/models/Tokens.js +2 -0
  48. package/internal-do-not-import-from-here/shared/models/Topic.d.ts +10 -0
  49. package/internal-do-not-import-from-here/shared/models/Topic.js +2 -0
  50. package/internal-do-not-import-from-here/shared/models/WorkerProxyFuncs.d.ts +8 -0
  51. package/internal-do-not-import-from-here/shared/models/WorkerProxyFuncs.js +14 -0
  52. package/internal-do-not-import-from-here/shared/models/Workers.d.ts +29 -0
  53. package/internal-do-not-import-from-here/shared/models/Workers.js +8 -0
  54. package/internal-do-not-import-from-here/shared/models/index.d.ts +14 -0
  55. package/internal-do-not-import-from-here/shared/models/index.js +18 -0
  56. package/internal-do-not-import-from-here/shared/models/theming/BlueprintDefinition.d.ts +27 -0
  57. package/internal-do-not-import-from-here/shared/models/theming/BlueprintDefinition.js +2 -0
  58. package/internal-do-not-import-from-here/shared/models/theming/OmniaThemes.d.ts +5 -0
  59. package/internal-do-not-import-from-here/shared/models/theming/OmniaThemes.js +18 -0
  60. package/internal-do-not-import-from-here/shared/models/theming/ThemeDefinitionV2.d.ts +61 -0
  61. package/internal-do-not-import-from-here/shared/models/theming/ThemeDefinitionV2.js +24 -0
  62. package/internal-do-not-import-from-here/shared/models/theming/ThemeMethods.d.ts +11 -0
  63. package/internal-do-not-import-from-here/shared/models/theming/ThemeMethods.js +143 -0
  64. package/internal-do-not-import-from-here/shared/models/theming/TypographyDefinition.d.ts +29 -0
  65. package/internal-do-not-import-from-here/shared/models/theming/TypographyDefinition.js +11 -0
  66. package/internal-do-not-import-from-here/shared/models/theming/index.d.ts +4 -0
  67. package/internal-do-not-import-from-here/shared/models/theming/index.js +7 -0
  68. package/models/ActionHooks.d.ts +12 -0
  69. package/models/ActionHooks.js +2 -0
  70. package/models/Enums.d.ts +53 -0
  71. package/models/Enums.js +65 -0
  72. package/models/VelcronDefinitions.d.ts +265 -0
  73. package/models/VelcronDefinitions.js +8 -0
  74. package/models/VelcronDescriptors.d.ts +35 -0
  75. package/models/VelcronDescriptors.js +2 -0
  76. package/models/VelcronEvents.d.ts +16 -0
  77. package/models/VelcronEvents.js +2 -0
  78. package/models/VelcronTypes.d.ts +10 -0
  79. package/models/VelcronTypes.js +2 -0
  80. package/models/VelcronUnitProvider.d.ts +5 -0
  81. package/models/VelcronUnitProvider.js +2 -0
  82. package/models/ViewModelAndContext.d.ts +4 -0
  83. package/models/ViewModelAndContext.js +2 -0
  84. package/models/index.d.ts +8 -0
  85. package/models/index.js +11 -0
  86. package/package.json +27 -0
  87. package/parser/TextValue.d.ts +4 -0
  88. package/parser/TextValue.js +9 -0
  89. package/parser/VelcronActions.d.ts +42 -0
  90. package/parser/VelcronActions.js +460 -0
  91. package/parser/VelcronConstants.d.ts +30 -0
  92. package/parser/VelcronConstants.js +33 -0
  93. package/parser/VelcronData.d.ts +39 -0
  94. package/parser/VelcronData.js +634 -0
  95. package/parser/VelcronLogger.d.ts +6 -0
  96. package/parser/VelcronLogger.js +18 -0
  97. package/parser/VelcronRenderers.d.ts +41 -0
  98. package/parser/VelcronRenderers.js +125 -0
  99. package/parser/VelcronStyles.d.ts +12 -0
  100. package/parser/VelcronStyles.js +159 -0
  101. package/parser/index.d.ts +7 -0
  102. package/parser/index.js +10 -0
  103. package/stores/ReactivitySystem.d.ts +5 -0
  104. package/stores/ReactivitySystem.js +12 -0
  105. package/stores/VelcronStore.d.ts +12 -0
  106. package/stores/VelcronStore.js +23 -0
  107. package/stores/VelcronTheming.d.ts +19 -0
  108. package/stores/VelcronTheming.js +49 -0
  109. package/stores/index.d.ts +3 -0
  110. package/stores/index.js +6 -0
  111. package/utilities/ColorUtility.d.ts +1 -0
  112. package/utilities/ColorUtility.js +45 -0
  113. package/utilities/index.d.ts +1 -0
  114. package/utilities/index.js +4 -0
@@ -0,0 +1,39 @@
1
+ import { VelcronAppDefinition, VelcronDefinition, VelcronRenderContext, DeferredPromise } from "../models";
2
+ export interface ParseResult<T> {
3
+ is: boolean;
4
+ value: T;
5
+ }
6
+ export declare class VelcronData {
7
+ static dataBind(renderContext: VelcronRenderContext, text: string): string;
8
+ static addCtxToVariableNames(template: string, skipIfNameStartsWith?: string, skipIfNameMatches?: Array<string>, overridePrefixWhenNameMatches?: {
9
+ [name: string]: string;
10
+ }): string;
11
+ static evauluateJs(template: string, renderContext: VelcronRenderContext, overrideNamesMatching?: {}): any;
12
+ private static variables;
13
+ static deleteVariables(id: string): void;
14
+ static getVariable<T>(name: string, renderContext: VelcronRenderContext): ParseResult<T>;
15
+ static setVariables(eventId: string, varsToSet: object): void;
16
+ static evaluateSet(path: string, value: any, renderContext: VelcronRenderContext): void;
17
+ static evaluateArray(template: string, renderContext: VelcronRenderContext): Array<any> | null;
18
+ static evaluateBoolean(template: string | Boolean, renderContext: VelcronRenderContext): boolean | null;
19
+ static tryParseBoolean(bool: any): ParseResult<boolean | null>;
20
+ static isString(text: any): boolean;
21
+ static isBoolean(value: any): boolean;
22
+ static isNumber(value: any): boolean;
23
+ static isUndefined(value: any): boolean;
24
+ static isArray(obj: any): obj is ExtendArray;
25
+ static isObject(value: any): boolean;
26
+ static extendObject(obj: any): any;
27
+ static getOrSetObjectByPath<T>(object: Object, path: string, value?: any): T | null;
28
+ static getOrSetObjectByPathUsingRenderContext<T>(renderContext: VelcronRenderContext, path: string, value?: any): T;
29
+ static getTokens(template: any, removeBrackets: boolean): string[];
30
+ static ensureEventId(event: string): string;
31
+ static ensureKeys(ui: VelcronDefinition | VelcronAppDefinition, generateNewKeys?: boolean): void;
32
+ static removeKeys(ui: VelcronDefinition | VelcronAppDefinition): void;
33
+ static generateId(): string;
34
+ static createDeferredPromise<T>(): DeferredPromise<T>;
35
+ }
36
+ interface ExtendArray extends Array<any> {
37
+ take: (amount: number) => Array<any>;
38
+ }
39
+ export {};
@@ -0,0 +1,634 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VelcronData = void 0;
4
+ const models_1 = require("../models");
5
+ const VelcronConstants_1 = require("./VelcronConstants");
6
+ const VelcronLogger_1 = require("./VelcronLogger");
7
+ const TextValue_1 = require("./TextValue");
8
+ class VelcronData {
9
+ static dataBind(renderContext, text) {
10
+ if (!VelcronData.isString(text)) {
11
+ return text;
12
+ }
13
+ const tokens = this.getTokens(text, false);
14
+ tokens.forEach((token) => {
15
+ let data = this.getOrSetObjectByPathUsingRenderContext(renderContext, token.replace(/\s*{{\s*|\s*}}\s*/g, ""));
16
+ if (data instanceof TextValue_1.TextValue) {
17
+ data = data.value;
18
+ }
19
+ text = text.replace(token, data);
20
+ });
21
+ return text;
22
+ }
23
+ static addCtxToVariableNames(template, skipIfNameStartsWith, skipIfNameMatches, overridePrefixWhenNameMatches) {
24
+ const re = new RegExp(/[^0-9a-z-.'$]/, "gi");
25
+ const results = [];
26
+ let match;
27
+ let lastIndex;
28
+ while (lastIndex = re.lastIndex, match = re.exec(template)) {
29
+ const text = template.substring(lastIndex, match.index);
30
+ if (text.length > 0 && text.startsWith("'") === false && text.endsWith("'") === false) {
31
+ results.push({ text: text, index: lastIndex });
32
+ }
33
+ }
34
+ results.push({ text: template.substring(lastIndex), index: lastIndex });
35
+ let appendedLenght = 0;
36
+ results.forEach((variableMatch) => {
37
+ //variable name cant start as a number
38
+ //'' is not allowed as variable name we used it in regex so if a value is set
39
+ //containing same name as a variable it will not be replaced
40
+ if (isNaN(variableMatch.text.substring(0, 1)) && (!variableMatch.text.startsWith("'")) && variableMatch.text.length > 0) {
41
+ if (skipIfNameStartsWith && variableMatch.text.startsWith(skipIfNameStartsWith) || skipIfNameMatches && skipIfNameMatches.filter(p => p === variableMatch.text).length > 0) { }
42
+ else {
43
+ let subName = variableMatch.text;
44
+ if (subName.startsWith(VelcronConstants_1.VelcronConstants.state.stateRootToken)) {
45
+ subName = subName.substring(VelcronConstants_1.VelcronConstants.state.stateRootToken.length + 1);
46
+ }
47
+ let prefix = variableMatch.text.startsWith(VelcronConstants_1.VelcronConstants.state.stateRootToken) ? "rootCtx " : "currentCtx";
48
+ if (overridePrefixWhenNameMatches && overridePrefixWhenNameMatches[variableMatch.text]) {
49
+ prefix = overridePrefixWhenNameMatches[variableMatch.text];
50
+ }
51
+ else if (overridePrefixWhenNameMatches && variableMatch.text.indexOf(".") > -1) {
52
+ //TODO: If this gets issues we need make overridePrefixWhenNameMatches to contain settings object
53
+ const toMatch = variableMatch.text.substring(0, variableMatch.text.indexOf("."));
54
+ if (overridePrefixWhenNameMatches[toMatch]) {
55
+ prefix = overridePrefixWhenNameMatches[toMatch];
56
+ subName = variableMatch.text.substring(toMatch.length + 1);
57
+ }
58
+ }
59
+ const newName = `${prefix.trim()}.${subName}`;
60
+ template = template.substring(0, (variableMatch.index + appendedLenght)) + newName + template.substring((variableMatch.index + appendedLenght) + variableMatch.text.length);
61
+ appendedLenght = +prefix.length + 1;
62
+ }
63
+ }
64
+ });
65
+ return template;
66
+ }
67
+ static evauluateJs(template, renderContext, overrideNamesMatching = null) {
68
+ const obj = [];
69
+ const names = [];
70
+ let propertiesToEval = {};
71
+ if (renderContext.properties) {
72
+ //Custom component properties evaluation
73
+ propertiesToEval = {};
74
+ Object.keys(renderContext.properties).forEach((key) => {
75
+ propertiesToEval[key] = "properties";
76
+ });
77
+ names.push("properties");
78
+ obj.push(renderContext.properties);
79
+ }
80
+ else if (overrideNamesMatching) {
81
+ propertiesToEval = overrideNamesMatching;
82
+ }
83
+ const reservedWords = [
84
+ "null",
85
+ "return"
86
+ ];
87
+ template = VelcronData.addCtxToVariableNames(template, undefined, reservedWords, propertiesToEval);
88
+ names.push("rootCtx");
89
+ names.push("currentCtx");
90
+ obj.push(renderContext.rootContext);
91
+ obj.push(renderContext.currentContext);
92
+ //TODO we shouls try catch and return info
93
+ const evalResult = Function(...names, "\"use strict\";return " + template)(...obj);
94
+ return evalResult;
95
+ }
96
+ static deleteVariables(id) {
97
+ if (VelcronData.variables[id]) {
98
+ delete VelcronData.variables[id];
99
+ }
100
+ }
101
+ static getVariable(name, renderContext) {
102
+ const variables = VelcronData.variables;
103
+ const result = { is: false, value: undefined };
104
+ if (renderContext.id &&
105
+ variables.hasOwnProperty(renderContext.id) &&
106
+ variables[renderContext.id].hasOwnProperty(name)) {
107
+ result.value = variables[renderContext.id][name];
108
+ result.is = true;
109
+ }
110
+ return result;
111
+ }
112
+ static setVariables(eventId, varsToSet) {
113
+ const variables = VelcronData.variables;
114
+ if (!variables[eventId]) {
115
+ variables[eventId] = {};
116
+ }
117
+ Object.keys(varsToSet).forEach((key) => {
118
+ variables[eventId][key] = varsToSet[key];
119
+ });
120
+ }
121
+ static evaluateSet(path, value, renderContext) {
122
+ const obj = [];
123
+ const names = [];
124
+ let assignOperator = models_1.AssignOperators.equals;
125
+ path = path.trim();
126
+ const variables = VelcronData.variables;
127
+ let isReturnValueSet = false;
128
+ let runEvaluation = true;
129
+ let runAssignment = true;
130
+ let directVariableAssignment = false;
131
+ let variableReassignmentFromPath = false;
132
+ let variableReassignmentFromValue = false;
133
+ let variableReassignmentFromValueIsFromVariable = false;
134
+ let pathSubLength = 0;
135
+ if (!path) {
136
+ return;
137
+ }
138
+ if (path === VelcronConstants_1.VelcronConstants.events.returnValueVariableName) {
139
+ isReturnValueSet = true;
140
+ path = value;
141
+ }
142
+ //Increment or decrement assignment
143
+ if (path.endsWith(models_1.AssignOperators.plusPlus) || path.endsWith(models_1.AssignOperators.minusMinus)) {
144
+ //increment or decrement after wont work since we dont operate on the real object
145
+ VelcronLogger_1.VelcronLogger.logActionError(`Only prefix increment/decrement operator is supported: ${path}`);
146
+ return;
147
+ }
148
+ else if (path.endsWith(models_1.AssignOperators.equalsPlus)) {
149
+ assignOperator = models_1.AssignOperators.equalsPlus;
150
+ path = path.substring(0, path.length - models_1.AssignOperators.equalsPlus.length);
151
+ }
152
+ else if (path.endsWith(models_1.AssignOperators.plusEquals)) {
153
+ assignOperator = models_1.AssignOperators.plusEquals;
154
+ path = path.substring(0, path.length - models_1.AssignOperators.plusEquals.length);
155
+ }
156
+ else if (path.endsWith(models_1.AssignOperators.equalsQuestion)) {
157
+ assignOperator = models_1.AssignOperators.equalsQuestion;
158
+ path = path.substring(0, path.length - models_1.AssignOperators.equalsQuestion.length);
159
+ runAssignment = false;
160
+ }
161
+ else if (path.startsWith(models_1.AssignOperators.plusPlus) || path.startsWith(models_1.AssignOperators.minusMinus)) {
162
+ assignOperator = path.substring(0, 2);
163
+ path = path.substring(2);
164
+ }
165
+ else if (path.endsWith(models_1.AssignOperators.equals)) {
166
+ assignOperator = models_1.AssignOperators.equals;
167
+ path = path.substring(0, path.length - models_1.AssignOperators.equals.length);
168
+ }
169
+ else if (path.endsWith(models_1.AssignOperators.equalsExclamation)) {
170
+ assignOperator = models_1.AssignOperators.equalsExclamation;
171
+ path = path.substring(0, path.length - models_1.AssignOperators.equalsExclamation.length);
172
+ }
173
+ path = path.trim();
174
+ //Support both var and let for local variables at the moment
175
+ if (path.startsWith("var ") || path.startsWith("let ")) {
176
+ pathSubLength = 4;
177
+ directVariableAssignment = true;
178
+ }
179
+ else if (renderContext.id &&
180
+ variables.hasOwnProperty(renderContext.id) &&
181
+ VelcronData.getOrSetObjectByPath(variables[renderContext.id], path) != undefined) {
182
+ variableReassignmentFromPath = true;
183
+ //value = VelcronData.getOrSetObjectByPath(variables[renderContext.id], value);
184
+ }
185
+ else if (renderContext.id &&
186
+ VelcronData.isString(value) &&
187
+ variables.hasOwnProperty(renderContext.id) &&
188
+ VelcronData.getOrSetObjectByPath(variables[renderContext.id], value) != undefined) {
189
+ variableReassignmentFromValue = true;
190
+ if (variables[renderContext.id] && variables[renderContext.id][path] != undefined) {
191
+ variableReassignmentFromValueIsFromVariable = true;
192
+ }
193
+ }
194
+ if (directVariableAssignment || variableReassignmentFromPath || variableReassignmentFromValue || isReturnValueSet) {
195
+ //Set result to temp variable
196
+ if (renderContext.id && !variables[renderContext.id]) {
197
+ variables[renderContext.id] = {};
198
+ }
199
+ if (VelcronData.isString(value) || value instanceof TextValue_1.TextValue) {
200
+ if (value instanceof TextValue_1.TextValue) {
201
+ //If the text value is returned from an action
202
+ //let text = 'Hello world' => return text
203
+ //Then we create TextValue class so we know that it is a string
204
+ //Action1 prints text from functions > Action2 returns text > Action 3 returns text
205
+ //The support is in the DataBind to bind the text value from the TextValue class
206
+ }
207
+ else {
208
+ let strValue = value.trim();
209
+ //Direct string assignment remove the ' ' in the string
210
+ if (strValue.startsWith("'") && strValue.endsWith(("'"))) {
211
+ strValue = strValue.substring(1, strValue.length - 1);
212
+ value = new TextValue_1.TextValue(VelcronData.dataBind(renderContext, strValue));
213
+ }
214
+ else if (renderContext.id && variableReassignmentFromValue) {
215
+ //Get the variable from value = parameter value
216
+ //@show(show): @data.loading = show
217
+ //value = variables[renderContext.id][value];
218
+ value = VelcronData.getOrSetObjectByPath(variables[renderContext.id], value);
219
+ }
220
+ else if (renderContext.id && variables[renderContext.id][path.substring(pathSubLength)]) {
221
+ //Try to get from previously assigned variable
222
+ value = variables[renderContext.id][path.substring(pathSubLength)];
223
+ }
224
+ else {
225
+ //Try get value from rootContext or currentContext
226
+ value = VelcronData.getOrSetObjectByPathUsingRenderContext(renderContext, value);
227
+ }
228
+ }
229
+ }
230
+ if (renderContext?.parent?.id && isReturnValueSet) {
231
+ const toSet = {};
232
+ toSet[VelcronConstants_1.VelcronConstants.events.returnValueVariableName] = value;
233
+ VelcronData.setVariables(renderContext.parent.id, toSet);
234
+ //variables[renderContext.parent.id][VelcronConstants.events.returnValueVariableName] = value;
235
+ }
236
+ else if (renderContext.id && !variableReassignmentFromValue) {
237
+ variables[renderContext.id][path.substring(pathSubLength)] = value;
238
+ }
239
+ runEvaluation = false;
240
+ runAssignment = false;
241
+ if (variableReassignmentFromValue && !variableReassignmentFromValueIsFromVariable) {
242
+ //runAssignment = true;
243
+ runEvaluation = true;
244
+ }
245
+ }
246
+ const existingVal = VelcronData.getOrSetObjectByPathUsingRenderContext(renderContext, path);
247
+ if (assignOperator === models_1.AssignOperators.equals || assignOperator === models_1.AssignOperators.equalsExclamation) {
248
+ //debugger;
249
+ if (typeof existingVal === "boolean" && typeof value !== "boolean") {
250
+ if (assignOperator === models_1.AssignOperators.equalsExclamation) {
251
+ value = !existingVal;
252
+ }
253
+ const isBool = VelcronData.tryParseBoolean(value);
254
+ if (isBool.is) {
255
+ value = isBool.value;
256
+ }
257
+ else {
258
+ VelcronLogger_1.VelcronLogger.logDataError(`Error setting boolean value for property with path ${path} the source datatype is not a boolean`);
259
+ }
260
+ }
261
+ else if (typeof existingVal === "number" && typeof value !== "number") {
262
+ if (isNaN(value)) {
263
+ VelcronLogger_1.VelcronLogger.logDataError(`The view model property ${path} is a number but the value tried to be set is a string. Its not allowed to change type of source property`);
264
+ }
265
+ value = parseInt(value);
266
+ }
267
+ }
268
+ if (runAssignment) {
269
+ if (VelcronData.isString(value) && value.startsWith("'") && value.endsWith("'")) {
270
+ // Value is string assignment
271
+ // "$state.title = 'Hello'"
272
+ value = value.substring(1, value.length - 1);
273
+ }
274
+ else if (assignOperator && VelcronData.isString(value)) {
275
+ //Value is assignment from renderContext
276
+ // "$state.title = title" or "$state.title = $state.anotherTitle"
277
+ if (value === "this") {
278
+ // $state.currentItem = this (this means currentContext)
279
+ value = renderContext.currentContext;
280
+ }
281
+ else {
282
+ if (value === "null") {
283
+ //$state.currentItem = null;
284
+ value = null;
285
+ }
286
+ else {
287
+ //try get value from render context
288
+ value = VelcronData.getOrSetObjectByPathUsingRenderContext(renderContext, value);
289
+ }
290
+ }
291
+ }
292
+ }
293
+ if (runEvaluation) {
294
+ if (path.indexOf(VelcronConstants_1.VelcronConstants.state.stateRootToken) > -1) {
295
+ path = path.replace(VelcronConstants_1.VelcronConstants.state.stateRootToken, "rootCtx");
296
+ }
297
+ else {
298
+ path = path.replace(path, `currentCtx.${path}`);
299
+ }
300
+ if (renderContext.id &&
301
+ variables.hasOwnProperty(renderContext.id) &&
302
+ VelcronData.getOrSetObjectByPath(variables[renderContext.id], value) != undefined) {
303
+ value = VelcronData.getOrSetObjectByPath(variables[renderContext.id], value);
304
+ }
305
+ let template = path;
306
+ if (assignOperator === models_1.AssignOperators.plusPlus || assignOperator === models_1.AssignOperators.minusMinus) {
307
+ //++var or --var
308
+ template = assignOperator + path;
309
+ }
310
+ else if (assignOperator === models_1.AssignOperators.equalsPlus || assignOperator === models_1.AssignOperators.plusEquals) {
311
+ if (Array.isArray(existingVal)) {
312
+ names.push("value");
313
+ obj.push(value);
314
+ const method = assignOperator === models_1.AssignOperators.equalsPlus ? "push" : "unshift";
315
+ if (Array.isArray(value)) {
316
+ template = `value.forEach((v)=>{ ${path}.${method}(v) })`;
317
+ }
318
+ else {
319
+ template = `${path}.${method}(value)`;
320
+ }
321
+ }
322
+ }
323
+ else if (assignOperator === models_1.AssignOperators.equalsQuestion) {
324
+ if (Array.isArray(existingVal)) {
325
+ //fix this
326
+ value = VelcronData.addCtxToVariableNames(value, ".");
327
+ const pattern = /(?:^|\W)\.(\w+)(?!\w)/;
328
+ const re = new RegExp(pattern, "g");
329
+ let match;
330
+ while ((match = re.exec(value)) != null) {
331
+ if (match.index) {
332
+ value = value.substring(0, (match.index)) + ` $$$obj${match[0].trim()}` + value.substring(match.index + match[0].length);
333
+ }
334
+ }
335
+ template = `${template} = ${template}.filter($$$obj => ${value});`;
336
+ }
337
+ }
338
+ else {
339
+ //var = val
340
+ names.push("value");
341
+ obj.push(value);
342
+ template = `${path}=value`;
343
+ }
344
+ names.push("rootCtx");
345
+ names.push("currentCtx");
346
+ obj.push(renderContext.rootContext);
347
+ obj.push(renderContext.currentContext);
348
+ //TODO we shouls try catch and return info
349
+ try {
350
+ const evalResult = Function(...names, "\"use strict\";" + template)(...obj);
351
+ }
352
+ catch (error) {
353
+ VelcronLogger_1.VelcronLogger.logDataError(`Error in VelcronData: ${error}`);
354
+ }
355
+ }
356
+ }
357
+ static evaluateArray(template, renderContext) {
358
+ let result = null;
359
+ const evalResult = VelcronData.evauluateJs(template, renderContext);
360
+ if (Array.isArray(evalResult)) {
361
+ result = evalResult;
362
+ }
363
+ else {
364
+ VelcronLogger_1.VelcronLogger.logDataError(`Cant evaluate ${template} to a Array`);
365
+ }
366
+ return result;
367
+ }
368
+ static evaluateBoolean(template, renderContext) {
369
+ if (VelcronData.isUndefined(template)) {
370
+ return false;
371
+ }
372
+ if (VelcronData.isBoolean(template)) {
373
+ return template;
374
+ }
375
+ const evalResult = VelcronData.evauluateJs(template, renderContext);
376
+ if (evalResult === null || VelcronData.isUndefined(evalResult)) {
377
+ return false;
378
+ }
379
+ const parseRes = this.tryParseBoolean(evalResult);
380
+ let result = null;
381
+ if (parseRes.is) {
382
+ result = parseRes.value;
383
+ }
384
+ else {
385
+ VelcronLogger_1.VelcronLogger.logDataError(`Cant evaluate ${template} to a boolean`);
386
+ }
387
+ return result;
388
+ }
389
+ static tryParseBoolean(bool) {
390
+ const result = {
391
+ is: false,
392
+ value: null
393
+ };
394
+ if (typeof bool === "boolean") {
395
+ result.value = bool;
396
+ result.is = true;
397
+ }
398
+ else if (typeof bool === "string") {
399
+ switch (bool.toLowerCase().trim()) {
400
+ case "true":
401
+ result.value = true;
402
+ result.is = true;
403
+ break;
404
+ case "false":
405
+ case null:
406
+ result.value = false;
407
+ result.is = true;
408
+ break;
409
+ }
410
+ }
411
+ return result;
412
+ }
413
+ static isString(text) {
414
+ return typeof text === "string" || text instanceof String;
415
+ }
416
+ static isBoolean(value) {
417
+ return typeof value === "boolean" ? true : false;
418
+ }
419
+ static isNumber(value) {
420
+ return !isNaN(value);
421
+ }
422
+ static isUndefined(value) {
423
+ return typeof value === "undefined";
424
+ }
425
+ static isArray(obj) {
426
+ return Array.isArray(obj);
427
+ }
428
+ static isObject(value) {
429
+ return typeof value === "object" &&
430
+ !Array.isArray(value) &&
431
+ value !== null;
432
+ }
433
+ static extendObject(obj) {
434
+ //Give objects some powerups
435
+ if (VelcronData.isUndefined(obj)) {
436
+ return obj;
437
+ }
438
+ if (VelcronData.isArray(obj)) {
439
+ //obj.take(5) => returns 5 items
440
+ obj.take = (amount) => {
441
+ return obj = obj.slice(0, amount);
442
+ };
443
+ }
444
+ return obj;
445
+ }
446
+ static getOrSetObjectByPath(object, path, value = undefined) {
447
+ if (typeof path !== "string") {
448
+ return null;
449
+ }
450
+ if (path === "") {
451
+ //If we pass $state = root we just return object
452
+ return object;
453
+ }
454
+ path = path.replace(/\[(\w+)\]/g, ".$1"); // convert indexes to properties
455
+ path = path.replace(/^\./, ""); // strip a leading dot
456
+ const a = path.split(".");
457
+ const lastParent = null;
458
+ for (let i = 0, n = a.length; i < n; ++i) {
459
+ const k = a[i];
460
+ if (object.hasOwnProperty(k)) {
461
+ //
462
+ if (typeof value !== "undefined" && (i + 1) == a.length) {
463
+ if (Array.isArray(object[k]) && typeof value === "string" || value instanceof String) {
464
+ //Support resetting Arrays
465
+ if (value.trim() === "[]") {
466
+ value = [];
467
+ }
468
+ }
469
+ else if (typeof object[k] === "boolean") {
470
+ const isBool = VelcronData.tryParseBoolean(value);
471
+ if (isBool.is) {
472
+ value = isBool.value;
473
+ }
474
+ else {
475
+ VelcronLogger_1.VelcronLogger.logDataError(`Error setting boolean value for property with name ${k} the source datatype is not a boolean`);
476
+ }
477
+ }
478
+ object[k] = VelcronData.extendObject(value);
479
+ }
480
+ object = VelcronData.extendObject(object[k]);
481
+ }
482
+ else {
483
+ //If the property does not exist we create it to make it reactive
484
+ //Todo this only works if the parent object exists already
485
+ //we should throw warning/exception
486
+ // if (value) {
487
+ // Vue.set(object, k, value);
488
+ // }
489
+ return null;
490
+ }
491
+ }
492
+ return object;
493
+ }
494
+ static getOrSetObjectByPathUsingRenderContext(renderContext, path, value = undefined) {
495
+ let result;
496
+ if (VelcronData.isUndefined(path)) {
497
+ return result;
498
+ }
499
+ const variables = VelcronData.variables;
500
+ if (renderContext.id &&
501
+ variables.hasOwnProperty(renderContext.id) &&
502
+ variables[renderContext.id].hasOwnProperty(value)) {
503
+ result = variables[renderContext.id][value];
504
+ }
505
+ else if (renderContext.id &&
506
+ variables.hasOwnProperty(renderContext.id) &&
507
+ variables[renderContext.id].hasOwnProperty(path)) {
508
+ result = variables[renderContext.id][path];
509
+ }
510
+ else if (path.startsWith(VelcronConstants_1.VelcronConstants.properties.propsToken + ".")) {
511
+ //props in a custom component $props.
512
+ path = path.substring(VelcronConstants_1.VelcronConstants.properties.propsToken.length + 1);
513
+ const propObj = VelcronData.getOrSetObjectByPath(renderContext.properties, path);
514
+ if (VelcronData.isString(propObj)) {
515
+ const propString = propObj;
516
+ path = VelcronData.dataBind(renderContext, propString);
517
+ result = path;
518
+ }
519
+ result = propObj;
520
+ }
521
+ else {
522
+ const tokens = VelcronData.getTokens(path, true);
523
+ if (tokens.length > 0) {
524
+ path = tokens[0];
525
+ }
526
+ let object = null;
527
+ if (path.startsWith(`${VelcronConstants_1.VelcronConstants.state.stateRootToken}.`) || path === VelcronConstants_1.VelcronConstants.state.stateRootToken) {
528
+ //Fetch from the data object
529
+ object = renderContext.rootContext;
530
+ path = path.substring(6);
531
+ }
532
+ else {
533
+ //Fetch from current ctx
534
+ object = renderContext.currentContext;
535
+ }
536
+ if (VelcronData.isObject(object)) {
537
+ result = VelcronData.getOrSetObjectByPath(object, path, value);
538
+ }
539
+ else {
540
+ //For example if you bind to Array of ["string"] the currentContext is only a string so we just return the object without mapping path
541
+ result = object;
542
+ }
543
+ }
544
+ return result;
545
+ }
546
+ static getTokens(template, removeBrackets) {
547
+ const tokens = [];
548
+ if (template) {
549
+ template.replace(removeBrackets ? /{{\s*(.+?)\s*}}/g : /(\{{.+?\}})/g, (foundToken, token) => {
550
+ const tokenWithVar = removeBrackets ? token : foundToken;
551
+ tokens.push(tokenWithVar);
552
+ return tokenWithVar;
553
+ });
554
+ }
555
+ return tokens;
556
+ }
557
+ static ensureEventId(event) {
558
+ return event.startsWith(VelcronConstants_1.VelcronConstants.events.idTokenStart) ?
559
+ event :
560
+ VelcronConstants_1.VelcronConstants.events.idTokenStart + VelcronData.generateId() + VelcronConstants_1.VelcronConstants.events.idTokenEnd + " " + event;
561
+ }
562
+ static ensureKeys(ui, generateNewKeys = false) {
563
+ if (!ui.key || generateNewKeys) {
564
+ ui.key = VelcronData.generateId();
565
+ }
566
+ if (ui.events) {
567
+ Object.keys(ui.events).forEach((key) => {
568
+ const evArr = ui.events ? ui.events[key] : [];
569
+ //Only the first item in the events array need id
570
+ if (evArr.length > 0 && !evArr[0].startsWith(VelcronConstants_1.VelcronConstants.events.idTokenStart)) {
571
+ evArr[0] = VelcronData.ensureEventId(evArr[0]);
572
+ }
573
+ });
574
+ }
575
+ Object.keys(ui).forEach((key) => {
576
+ if (Array.isArray(ui[key])) {
577
+ ui[key].forEach((item) => {
578
+ if (!item.key || generateNewKeys) {
579
+ item.key = VelcronData.generateId();
580
+ }
581
+ VelcronData.ensureKeys(item, generateNewKeys);
582
+ });
583
+ }
584
+ });
585
+ }
586
+ static removeKeys(ui) {
587
+ if (ui.key) {
588
+ delete ui.key;
589
+ }
590
+ if (ui.events) {
591
+ Object.keys(ui.events).forEach((key) => {
592
+ const evArr = ui.events ? ui.events[key] : [];
593
+ if (evArr.length > 0 && evArr[0].startsWith(VelcronConstants_1.VelcronConstants.events.idTokenStart)) {
594
+ evArr[0] = evArr[0].substring(VelcronConstants_1.VelcronConstants.events.idTokenStart.length + VelcronData.generateId().length + VelcronConstants_1.VelcronConstants.events.idTokenEnd.length).trim();
595
+ }
596
+ });
597
+ }
598
+ if (ui.actions) {
599
+ const appDef = ui;
600
+ if (appDef.actions) {
601
+ Object.keys(appDef.actions).forEach((key) => {
602
+ const actionArr = appDef.actions ? appDef.actions[key] : [];
603
+ if (actionArr.length > 0 && actionArr[0].startsWith(VelcronConstants_1.VelcronConstants.events.idTokenStart)) {
604
+ actionArr[0] = actionArr[0].substring(VelcronConstants_1.VelcronConstants.events.idTokenStart.length + VelcronData.generateId().length + VelcronConstants_1.VelcronConstants.events.idTokenEnd.length).trim();
605
+ }
606
+ });
607
+ }
608
+ }
609
+ Object.keys(ui).forEach((key) => {
610
+ if (Array.isArray(ui[key])) {
611
+ ui[key].forEach((item) => {
612
+ if (item.key) {
613
+ delete item.key;
614
+ }
615
+ VelcronData.removeKeys(item);
616
+ });
617
+ }
618
+ });
619
+ }
620
+ static generateId() {
621
+ const firstPart = (Math.random() * 46656) | 0;
622
+ const secondPart = (Math.random() * 46656) | 0;
623
+ return (("000" + firstPart.toString(36)).slice(-3) + ("000" + secondPart.toString(36)).slice(-3)).toString();
624
+ }
625
+ static createDeferredPromise() {
626
+ let resolve, reject;
627
+ const promise = new Promise((res, rej) => {
628
+ [resolve, reject] = [res, rej];
629
+ });
630
+ return { promise, reject, resolve };
631
+ }
632
+ }
633
+ exports.VelcronData = VelcronData;
634
+ VelcronData.variables = {};
@@ -0,0 +1,6 @@
1
+ export declare class VelcronLogger {
2
+ static logDataError(log: string): void;
3
+ static logActionError(log: string): void;
4
+ static logError(log: string): void;
5
+ static logCustomComponentError(log: string): void;
6
+ }