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