@nordcraft/search 1.0.39 → 1.0.40
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/dist/rules/actions/legacyActionRule.js +144 -2
- package/dist/rules/actions/legacyActionRule.js.map +1 -1
- package/dist/rules/actions/legacyActionRule.test.js +235 -1
- package/dist/rules/actions/legacyActionRule.test.js.map +1 -1
- package/dist/rules/formulas/legacyFormulaRule.js +5 -23
- package/dist/rules/formulas/legacyFormulaRule.js.map +1 -1
- package/dist/rules/formulas/noReferenceProjectFormulaRule.js +73 -58
- package/dist/rules/formulas/noReferenceProjectFormulaRule.js.map +1 -1
- package/dist/rules/formulas/noReferenceProjectFormulaRule.test.js +34 -1
- package/dist/rules/formulas/noReferenceProjectFormulaRule.test.js.map +1 -1
- package/dist/util/helpers.js +13 -3
- package/dist/util/helpers.js.map +1 -1
- package/package.json +2 -2
- package/src/rules/actions/legacyActionRule.test.ts +245 -1
- package/src/rules/actions/legacyActionRule.ts +166 -4
- package/src/rules/formulas/legacyFormulaRule.ts +9 -31
- package/src/rules/formulas/noReferenceProjectFormulaRule.test.ts +36 -1
- package/src/rules/formulas/noReferenceProjectFormulaRule.ts +78 -64
- package/src/types.d.ts +7 -1
- package/src/util/helpers.ts +28 -4
|
@@ -1,79 +1,94 @@
|
|
|
1
1
|
import { ToddleComponent } from '@nordcraft/core/dist/component/ToddleComponent';
|
|
2
2
|
import { isToddleFormula } from '@nordcraft/core/dist/formula/formulaTypes';
|
|
3
|
+
import { omit } from '@nordcraft/core/dist/utils/collections';
|
|
3
4
|
import { ToddleApiService } from '@nordcraft/ssr/dist/ToddleApiService';
|
|
4
5
|
import { ToddleRoute } from '@nordcraft/ssr/dist/ToddleRoute';
|
|
5
6
|
export const noReferenceProjectFormulaRule = {
|
|
6
7
|
code: 'no-reference project formula',
|
|
7
8
|
level: 'warning',
|
|
8
9
|
category: 'No References',
|
|
9
|
-
visit: (report,
|
|
10
|
-
if (
|
|
10
|
+
visit: (report, details) => {
|
|
11
|
+
if (hasReferences(details)) {
|
|
11
12
|
return;
|
|
12
13
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
14
|
+
report(details.path, undefined, ['delete-project-formula']);
|
|
15
|
+
},
|
|
16
|
+
fixes: {
|
|
17
|
+
'delete-project-formula': (data) => {
|
|
18
|
+
if (hasReferences(data)) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
return omit(data.files, data.path);
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
const hasReferences = ({ value, files, nodeType, memo }) => {
|
|
26
|
+
if (nodeType !== 'project-formula' || value.exported === true) {
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
// Check in all API services first, since that should be quick
|
|
30
|
+
for (const apiService of Object.values(files.services ?? {})) {
|
|
31
|
+
const service = new ToddleApiService({
|
|
32
|
+
service: apiService,
|
|
33
|
+
globalFormulas: { formulas: files.formulas, packages: files.packages },
|
|
34
|
+
});
|
|
35
|
+
const formulas = service.formulasInService();
|
|
36
|
+
for (const { path: _formulaPath, formula } of formulas) {
|
|
37
|
+
// Check if the formula is used in the formula
|
|
38
|
+
if (checkFormula(formula, value.name)) {
|
|
39
|
+
return true;
|
|
25
40
|
}
|
|
26
41
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
42
|
+
}
|
|
43
|
+
// Check routes before components, since they should be quicker
|
|
44
|
+
for (const projectRoute of Object.values(files.routes ?? {})) {
|
|
45
|
+
const route = new ToddleRoute({
|
|
46
|
+
route: projectRoute,
|
|
47
|
+
globalFormulas: { formulas: files.formulas, packages: files.packages },
|
|
48
|
+
});
|
|
49
|
+
const formulas = route.formulasInRoute();
|
|
50
|
+
for (const { path: _formulaPath, formula } of formulas) {
|
|
51
|
+
// Check if the formula is used in the formula
|
|
52
|
+
if (checkFormula(formula, value.name)) {
|
|
53
|
+
return true;
|
|
39
54
|
}
|
|
40
55
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
}
|
|
57
|
+
const componentFormulaReferences = memo('componentFormulaReferences', () => {
|
|
58
|
+
const usedFormulas = new Set();
|
|
59
|
+
for (const component of Object.values(files.components)) {
|
|
60
|
+
const c = new ToddleComponent({
|
|
61
|
+
// Enforce that the component is not undefined since we're iterating
|
|
62
|
+
component: component,
|
|
63
|
+
getComponent: (name) => files.components[name],
|
|
64
|
+
packageName: undefined,
|
|
65
|
+
globalFormulas: {
|
|
66
|
+
formulas: files.formulas,
|
|
67
|
+
packages: files.packages,
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
for (const { formula } of c.formulasInComponent()) {
|
|
71
|
+
if (formula.type === 'function') {
|
|
72
|
+
usedFormulas.add(formula.name);
|
|
58
73
|
}
|
|
59
74
|
}
|
|
60
|
-
return usedFormulas;
|
|
61
|
-
});
|
|
62
|
-
if (componentFormulaReferences.has(value.name)) {
|
|
63
|
-
return;
|
|
64
75
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
76
|
+
return usedFormulas;
|
|
77
|
+
});
|
|
78
|
+
if (componentFormulaReferences.has(value.name)) {
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
// TODO: Memoize similar to above. We need have a helper class `ToddleFormula` with `ToddleFormula.normalizeFormulas()`
|
|
82
|
+
for (const f of Object.values(files.formulas ?? {})) {
|
|
83
|
+
if (f.name === value.name) {
|
|
84
|
+
continue;
|
|
74
85
|
}
|
|
75
|
-
|
|
76
|
-
|
|
86
|
+
// Check if the formula is used in the formula
|
|
87
|
+
if (isToddleFormula(f) && checkFormula(f.formula, value.name)) {
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return false;
|
|
77
92
|
};
|
|
78
93
|
const checkArguments = (args, formulaName) => {
|
|
79
94
|
args.forEach((a) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"noReferenceProjectFormulaRule.js","sourceRoot":"","sources":["../../../src/rules/formulas/noReferenceProjectFormulaRule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,gDAAgD,CAAA;AAEhF,OAAO,EAAE,eAAe,EAAE,MAAM,2CAA2C,CAAA;AAC3E,OAAO,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAA;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAA;AAG7D,MAAM,CAAC,MAAM,6BAA6B,GAAe;IACvD,IAAI,EAAE,8BAA8B;IACpC,KAAK,EAAE,SAAS;IAChB,QAAQ,EAAE,eAAe;IACzB,KAAK,EAAE,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,
|
|
1
|
+
{"version":3,"file":"noReferenceProjectFormulaRule.js","sourceRoot":"","sources":["../../../src/rules/formulas/noReferenceProjectFormulaRule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,gDAAgD,CAAA;AAEhF,OAAO,EAAE,eAAe,EAAE,MAAM,2CAA2C,CAAA;AAC3E,OAAO,EAAE,IAAI,EAAE,MAAM,wCAAwC,CAAA;AAC7D,OAAO,EA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,GAAG,CAAC,OAAgB,EAAE,WAAmB,EAAE,EAAE;IAC7D,IAAI,OAAO,CAAC,IAAI,KAAK,UAAU,IAAI,OAAO,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;QAChE,OAAO,IAAI,CAAA;IACb,CAAC;IACD,IACE,OAAO,CAAC,IAAI,KAAK,QAAQ;QACzB,OAAO,CAAC,IAAI,KAAK,OAAO;QACxB,OAAO,CAAC,IAAI,KAAK,IAAI;QACrB,OAAO,CAAC,IAAI,KAAK,KAAK;QACtB,OAAO,CAAC,IAAI,KAAK,OAAO,EACxB,CAAC;QACD,cAAc,CAAC,OAAO,CAAC,SAAS,IAAI,EAAE,EAAE,WAAW,CAAC,CAAA;IACtD,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC,CAAA"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { describe, expect, test } from 'bun:test';
|
|
2
|
+
import { fixProject } from '../../fixProject';
|
|
2
3
|
import { searchProject } from '../../searchProject';
|
|
3
4
|
import { noReferenceProjectFormulaRule } from './noReferenceProjectFormulaRule';
|
|
4
|
-
describe('noReferenceFormulaRule', () => {
|
|
5
|
+
describe('find noReferenceFormulaRule', () => {
|
|
5
6
|
test('should detect unused global formulas', () => {
|
|
6
7
|
const problems = Array.from(searchProject({
|
|
7
8
|
files: {
|
|
@@ -267,4 +268,36 @@ describe('noReferenceFormulaRule', () => {
|
|
|
267
268
|
expect(problems).toHaveLength(0);
|
|
268
269
|
});
|
|
269
270
|
});
|
|
271
|
+
describe('fix noReferenceFormulaRule', () => {
|
|
272
|
+
test('should remove unused global formulas', () => {
|
|
273
|
+
const projectFiles = {
|
|
274
|
+
formulas: {
|
|
275
|
+
'my-formula': {
|
|
276
|
+
name: 'my-formula',
|
|
277
|
+
arguments: [],
|
|
278
|
+
formula: {
|
|
279
|
+
type: 'value',
|
|
280
|
+
value: 'value',
|
|
281
|
+
},
|
|
282
|
+
},
|
|
283
|
+
},
|
|
284
|
+
components: {
|
|
285
|
+
test: {
|
|
286
|
+
name: 'test',
|
|
287
|
+
nodes: {},
|
|
288
|
+
formulas: {},
|
|
289
|
+
apis: {},
|
|
290
|
+
attributes: {},
|
|
291
|
+
variables: {},
|
|
292
|
+
},
|
|
293
|
+
},
|
|
294
|
+
};
|
|
295
|
+
const fixedProject = fixProject({
|
|
296
|
+
files: projectFiles,
|
|
297
|
+
rule: noReferenceProjectFormulaRule,
|
|
298
|
+
fixType: 'delete-project-formula',
|
|
299
|
+
});
|
|
300
|
+
expect(fixedProject.formulas).toEqual({});
|
|
301
|
+
});
|
|
302
|
+
});
|
|
270
303
|
//# sourceMappingURL=noReferenceProjectFormulaRule.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"noReferenceProjectFormulaRule.test.js","sourceRoot":"","sources":["../../../src/rules/formulas/noReferenceProjectFormulaRule.test.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"noReferenceProjectFormulaRule.test.js","sourceRoot":"","sources":["../../../src/rules/formulas/noReferenceProjectFormulaRule.test.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UAAU,CAAA;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACnD,OAAO,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAA;AAE/E,QAAQ,CAAC,6BAA6B,EAAE,GAAG,EAAE;IAC3C,IAAI,CAAC,sCAAsC,EAAE,GAAG,EAAE;QAChD,MAAM,QAAQ,GAAG,KAAK,CAAC,IAAI,CACzB,aAAa,CAAC;YACZ,KAAK,EAAE;gBACL,QAAQ,EAAE;oBACR,YAAY,EAAE;wBACZ,IAAI,EAAE,YAAY;wBAClB,SAAS,EAAE,EAAE;wBACb,OAAO,EAAE;4BACP,IAAI,EAAE,OAAO;4BACb,KAAK,EAAE,OAAO;y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B,KAAK,EAAE,YAAY;YACnB,IAAI,EAAE,6BAA6B;YACnC,OAAO,EAAE,wBAAwB;SAClC,CAAC,CAAA;QACF,MAAM,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;IAC3C,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
package/dist/util/helpers.js
CHANGED
|
@@ -32,14 +32,11 @@ const LEGACY_CUSTOM_ACTIONS = new Set([
|
|
|
32
32
|
'If',
|
|
33
33
|
'PreventDefault',
|
|
34
34
|
'StopPropagation',
|
|
35
|
-
'Copy To Clipboard',
|
|
36
35
|
'CopyToClipboard',
|
|
37
36
|
'UpdateVariable',
|
|
38
|
-
'Update Variable',
|
|
39
37
|
'Update URL parameter',
|
|
40
38
|
'updateUrlParameters',
|
|
41
39
|
'UpdateQueryParam',
|
|
42
|
-
'Update Query',
|
|
43
40
|
'Fetch',
|
|
44
41
|
'SetTimeout',
|
|
45
42
|
'SetInterval',
|
|
@@ -48,6 +45,7 @@ const LEGACY_CUSTOM_ACTIONS = new Set([
|
|
|
48
45
|
'GoToURL',
|
|
49
46
|
'TriggerEvent',
|
|
50
47
|
'Set session cookies',
|
|
48
|
+
'@toddle/setSessionCookies',
|
|
51
49
|
]);
|
|
52
50
|
const INTERACTIVE_CONTENT = [
|
|
53
51
|
{ tag: 'button' },
|
|
@@ -78,4 +76,16 @@ export const interactiveContentElementDefinition = (element) => INTERACTIVE_CONT
|
|
|
78
76
|
}
|
|
79
77
|
return true;
|
|
80
78
|
});
|
|
79
|
+
export const ARRAY_ARGUMENT_MAPPINGS = { List: 'Array' };
|
|
80
|
+
export const PREDICATE_ARGUMENT_MAPPINGS = {
|
|
81
|
+
...ARRAY_ARGUMENT_MAPPINGS,
|
|
82
|
+
'Predicate fx': 'Formula',
|
|
83
|
+
};
|
|
84
|
+
export const renameArguments = (mappings, args) => args?.map((arg) => ({
|
|
85
|
+
...arg,
|
|
86
|
+
// Let's adjust the names
|
|
87
|
+
name: typeof arg.name === 'string'
|
|
88
|
+
? (mappings[arg.name] ?? arg.name)
|
|
89
|
+
: arg.name,
|
|
90
|
+
})) ?? [];
|
|
81
91
|
//# sourceMappingURL=helpers.js.map
|
package/dist/util/helpers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/util/helpers.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/util/helpers.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAA;AAE3D;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,EAC9B,IAAI,EACJ,YAAY,GAAG,EAAE,GAIlB;IACC,OAAO,CACL,YAAY,CAAC,MAAM,KAAK,CAAC;QACzB,YAAY,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,EAAE;QAChC,2EAA2E;QAC3E,oCAAoC;QACpC,WAAW,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CACjE,CACF,CAAA;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,qBAAqB,CAAC,EACpC,IAAI,EACJ,YAAY,GAIb;IACC,OAAO,YAAY,CAAC,IAAI,CACtB,CAAC,WAAW,EAAE,EAAE,CACd,IAAI,CAAC,MAAM,KAAK,WAAW,CAAC,MAAM;QAClC,WAAW,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAC/C,CAAA;AACH,CAAC;AAED,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,KAAkB,EACU,EAAE;IAC9B,QAAQ,KAAK,CAAC,IAAI,EAAE,CAAC;QACnB,KAAK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json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://github.com/nordcraftengine/nordcraft",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@nordcraft/ssr": "1.0.
|
|
8
|
+
"@nordcraft/ssr": "1.0.40",
|
|
9
9
|
"jsondiffpatch": "0.7.3"
|
|
10
10
|
},
|
|
11
11
|
"scripts": {
|
|
@@ -18,5 +18,5 @@
|
|
|
18
18
|
"test:watch:only": "bun test --watch --only"
|
|
19
19
|
},
|
|
20
20
|
"files": ["dist", "src"],
|
|
21
|
-
"version": "1.0.
|
|
21
|
+
"version": "1.0.40"
|
|
22
22
|
}
|
|
@@ -1,8 +1,14 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ActionModel,
|
|
3
|
+
ElementNodeModel,
|
|
4
|
+
} from '@nordcraft/core/dist/component/component.types'
|
|
5
|
+
import type { ProjectFiles } from '@nordcraft/ssr/dist/ssr.types'
|
|
1
6
|
import { describe, expect, test } from 'bun:test'
|
|
7
|
+
import { fixProject } from '../../fixProject'
|
|
2
8
|
import { searchProject } from '../../searchProject'
|
|
3
9
|
import { legacyActionRule } from './legacyActionRule'
|
|
4
10
|
|
|
5
|
-
describe('
|
|
11
|
+
describe('find legacyActions', () => {
|
|
6
12
|
test('should detect legacy actions used in components', () => {
|
|
7
13
|
const problems = Array.from(
|
|
8
14
|
searchProject({
|
|
@@ -90,3 +96,241 @@ describe('legacyAction', () => {
|
|
|
90
96
|
expect(problems).toHaveLength(0)
|
|
91
97
|
})
|
|
92
98
|
})
|
|
99
|
+
|
|
100
|
+
describe('fix legacyActions', () => {
|
|
101
|
+
test('should replace the If action with a Switch action', () => {
|
|
102
|
+
const legacyIfAction: ActionModel = {
|
|
103
|
+
name: 'If',
|
|
104
|
+
events: {
|
|
105
|
+
true: {
|
|
106
|
+
actions: [
|
|
107
|
+
{
|
|
108
|
+
name: '@toddle/logToConsole',
|
|
109
|
+
arguments: [
|
|
110
|
+
{
|
|
111
|
+
name: 'Label',
|
|
112
|
+
description: 'A label for the message.',
|
|
113
|
+
formula: { type: 'value', value: '' },
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
name: 'Data',
|
|
117
|
+
type: { type: 'Any' },
|
|
118
|
+
description: 'The data you want to log to the console.',
|
|
119
|
+
formula: {
|
|
120
|
+
type: 'value',
|
|
121
|
+
value: '<Data>',
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
],
|
|
125
|
+
label: 'Log to console',
|
|
126
|
+
group: 'debugging',
|
|
127
|
+
description: 'Log a message to the browser console.',
|
|
128
|
+
},
|
|
129
|
+
],
|
|
130
|
+
},
|
|
131
|
+
false: {
|
|
132
|
+
actions: [
|
|
133
|
+
{
|
|
134
|
+
name: '@toddle/logToConsole',
|
|
135
|
+
arguments: [
|
|
136
|
+
{
|
|
137
|
+
name: 'Label',
|
|
138
|
+
description: 'A label for the message.',
|
|
139
|
+
formula: { type: 'value', value: '' },
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
name: 'Data',
|
|
143
|
+
type: { type: 'Any' },
|
|
144
|
+
description: 'The data you want to log to the console.',
|
|
145
|
+
formula: {
|
|
146
|
+
type: 'value',
|
|
147
|
+
value: '<Data>',
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
],
|
|
151
|
+
label: 'Log to console',
|
|
152
|
+
group: 'debugging',
|
|
153
|
+
description: 'Log a message to the browser console.',
|
|
154
|
+
},
|
|
155
|
+
],
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
arguments: [
|
|
159
|
+
{
|
|
160
|
+
name: 'Condition',
|
|
161
|
+
formula: { type: 'value', value: true },
|
|
162
|
+
},
|
|
163
|
+
],
|
|
164
|
+
}
|
|
165
|
+
const projectFiles: ProjectFiles = {
|
|
166
|
+
formulas: {},
|
|
167
|
+
components: {
|
|
168
|
+
apiComponent: {
|
|
169
|
+
name: 'test',
|
|
170
|
+
nodes: {
|
|
171
|
+
root: {
|
|
172
|
+
tag: 'p',
|
|
173
|
+
type: 'element',
|
|
174
|
+
attrs: {},
|
|
175
|
+
style: {},
|
|
176
|
+
events: {
|
|
177
|
+
click: {
|
|
178
|
+
trigger: 'click',
|
|
179
|
+
actions: [legacyIfAction],
|
|
180
|
+
},
|
|
181
|
+
},
|
|
182
|
+
classes: {},
|
|
183
|
+
children: [],
|
|
184
|
+
},
|
|
185
|
+
},
|
|
186
|
+
formulas: {},
|
|
187
|
+
apis: {},
|
|
188
|
+
attributes: {},
|
|
189
|
+
variables: {},
|
|
190
|
+
},
|
|
191
|
+
},
|
|
192
|
+
}
|
|
193
|
+
const fixedProject = fixProject({
|
|
194
|
+
files: projectFiles,
|
|
195
|
+
rule: legacyActionRule,
|
|
196
|
+
fixType: 'replace-legacy-action',
|
|
197
|
+
})
|
|
198
|
+
const fixedAction = (
|
|
199
|
+
fixedProject.components['apiComponent']?.nodes['root'] as ElementNodeModel
|
|
200
|
+
).events['click'].actions[0]
|
|
201
|
+
expect(fixedAction).toMatchInlineSnapshot(`
|
|
202
|
+
{
|
|
203
|
+
"cases": [
|
|
204
|
+
{
|
|
205
|
+
"actions": [
|
|
206
|
+
{
|
|
207
|
+
"arguments": [
|
|
208
|
+
{
|
|
209
|
+
"description": "A label for the message.",
|
|
210
|
+
"formula": {
|
|
211
|
+
"type": "value",
|
|
212
|
+
"value": "",
|
|
213
|
+
},
|
|
214
|
+
"name": "Label",
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
"description": "The data you want to log to the console.",
|
|
218
|
+
"formula": {
|
|
219
|
+
"type": "value",
|
|
220
|
+
"value": "<Data>",
|
|
221
|
+
},
|
|
222
|
+
"name": "Data",
|
|
223
|
+
"type": {
|
|
224
|
+
"type": "Any",
|
|
225
|
+
},
|
|
226
|
+
},
|
|
227
|
+
],
|
|
228
|
+
"description": "Log a message to the browser console.",
|
|
229
|
+
"group": "debugging",
|
|
230
|
+
"label": "Log to console",
|
|
231
|
+
"name": "@toddle/logToConsole",
|
|
232
|
+
},
|
|
233
|
+
],
|
|
234
|
+
"condition": {
|
|
235
|
+
"type": "value",
|
|
236
|
+
"value": true,
|
|
237
|
+
},
|
|
238
|
+
},
|
|
239
|
+
],
|
|
240
|
+
"default": {
|
|
241
|
+
"actions": [
|
|
242
|
+
{
|
|
243
|
+
"arguments": [
|
|
244
|
+
{
|
|
245
|
+
"description": "A label for the message.",
|
|
246
|
+
"formula": {
|
|
247
|
+
"type": "value",
|
|
248
|
+
"value": "",
|
|
249
|
+
},
|
|
250
|
+
"name": "Label",
|
|
251
|
+
},
|
|
252
|
+
{
|
|
253
|
+
"description": "The data you want to log to the console.",
|
|
254
|
+
"formula": {
|
|
255
|
+
"type": "value",
|
|
256
|
+
"value": "<Data>",
|
|
257
|
+
},
|
|
258
|
+
"name": "Data",
|
|
259
|
+
"type": {
|
|
260
|
+
"type": "Any",
|
|
261
|
+
},
|
|
262
|
+
},
|
|
263
|
+
],
|
|
264
|
+
"description": "Log a message to the browser console.",
|
|
265
|
+
"group": "debugging",
|
|
266
|
+
"label": "Log to console",
|
|
267
|
+
"name": "@toddle/logToConsole",
|
|
268
|
+
},
|
|
269
|
+
],
|
|
270
|
+
},
|
|
271
|
+
"type": "Switch",
|
|
272
|
+
}
|
|
273
|
+
`)
|
|
274
|
+
})
|
|
275
|
+
test('should replace the TriggerEvent action with the builtin action', () => {
|
|
276
|
+
const legacyAction: ActionModel = {
|
|
277
|
+
name: 'TriggerEvent',
|
|
278
|
+
arguments: [
|
|
279
|
+
{
|
|
280
|
+
name: 'name',
|
|
281
|
+
formula: { type: 'value', value: 'sdfsdf' },
|
|
282
|
+
},
|
|
283
|
+
{
|
|
284
|
+
name: 'data',
|
|
285
|
+
formula: { type: 'value', value: 'test' },
|
|
286
|
+
},
|
|
287
|
+
],
|
|
288
|
+
}
|
|
289
|
+
const projectFiles: ProjectFiles = {
|
|
290
|
+
formulas: {},
|
|
291
|
+
components: {
|
|
292
|
+
apiComponent: {
|
|
293
|
+
name: 'test',
|
|
294
|
+
nodes: {
|
|
295
|
+
root: {
|
|
296
|
+
tag: 'p',
|
|
297
|
+
type: 'element',
|
|
298
|
+
attrs: {},
|
|
299
|
+
style: {},
|
|
300
|
+
events: {
|
|
301
|
+
click: {
|
|
302
|
+
trigger: 'click',
|
|
303
|
+
actions: [legacyAction],
|
|
304
|
+
},
|
|
305
|
+
},
|
|
306
|
+
classes: {},
|
|
307
|
+
children: [],
|
|
308
|
+
},
|
|
309
|
+
},
|
|
310
|
+
formulas: {},
|
|
311
|
+
apis: {},
|
|
312
|
+
attributes: {},
|
|
313
|
+
variables: {},
|
|
314
|
+
},
|
|
315
|
+
},
|
|
316
|
+
}
|
|
317
|
+
const fixedProject = fixProject({
|
|
318
|
+
files: projectFiles,
|
|
319
|
+
rule: legacyActionRule,
|
|
320
|
+
fixType: 'replace-legacy-action',
|
|
321
|
+
})
|
|
322
|
+
const fixedAction = (
|
|
323
|
+
fixedProject.components['apiComponent']?.nodes['root'] as ElementNodeModel
|
|
324
|
+
).events['click'].actions[0]
|
|
325
|
+
expect(fixedAction).toMatchInlineSnapshot(`
|
|
326
|
+
{
|
|
327
|
+
"data": {
|
|
328
|
+
"type": "value",
|
|
329
|
+
"value": "test",
|
|
330
|
+
},
|
|
331
|
+
"event": "sdfsdf",
|
|
332
|
+
"type": "TriggerEvent",
|
|
333
|
+
}
|
|
334
|
+
`)
|
|
335
|
+
})
|
|
336
|
+
})
|