@adobe/aio-cli-plugin-api-mesh 2.3.1 → 2.3.2
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/oclif.manifest.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"2.3.
|
|
1
|
+
{"version":"2.3.2","commands":{"PLUGINNAME":{"id":"PLUGINNAME","description":"Your description here","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"examples":["$ aio PLUGINNAME:some_command"],"flags":{"someflag":{"name":"someflag","type":"option","char":"f","description":"this is some flag"}},"args":[]},"api-mesh:create":{"id":"api-mesh:create","description":"Create a mesh with the given config.","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"flags":{"ignoreCache":{"name":"ignoreCache","type":"boolean","char":"i","description":"Ignore cache and force manual org -> project -> workspace selection","allowNo":false},"autoConfirmAction":{"name":"autoConfirmAction","type":"boolean","char":"c","description":"Auto confirm action prompt. CLI will not check for user approval before executing the action.","allowNo":false},"json":{"name":"json","type":"boolean","description":"Output JSON","allowNo":false},"env":{"name":"env","type":"option","char":"e","description":"Path to env file","default":".env"}},"args":[{"name":"file"}]},"api-mesh:delete":{"id":"api-mesh:delete","description":"Delete the config of a given mesh","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"flags":{"ignoreCache":{"name":"ignoreCache","type":"boolean","char":"i","description":"Ignore cache and force manual org -> project -> workspace selection","allowNo":false},"autoConfirmAction":{"name":"autoConfirmAction","type":"boolean","char":"c","description":"Auto confirm action prompt. CLI will not check for user approval before executing the action.","allowNo":false}},"args":[]},"api-mesh:describe":{"id":"api-mesh:describe","description":"Get details of a mesh","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"flags":{"ignoreCache":{"name":"ignoreCache","type":"boolean","char":"i","description":"Ignore cache and force manual org -> project -> workspace selection","allowNo":false}},"args":[]},"api-mesh:get":{"id":"api-mesh:get","description":"Get the config of a given mesh","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"flags":{"ignoreCache":{"name":"ignoreCache","type":"boolean","char":"i","description":"Ignore cache and force manual org -> project -> workspace selection","allowNo":false},"json":{"name":"json","type":"boolean","description":"Output JSON","allowNo":false}},"args":[{"name":"file"}]},"api-mesh:init":{"id":"api-mesh:init","description":"This command will create a workspace where you can organise your API mesh configuration and other files","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"examples":[{"description":"API mesh workspace init","command":"aio api-mesh init commerce-mesh"},{"description":"API mesh workspace init with flags","command":"aio api-mesh init commerce-mesh --path ./mesh_projects/test_mesh --git y --packageManager yarn"}],"flags":{"path":{"name":"path","type":"option","char":"p","default":"."},"packageManager":{"name":"packageManager","type":"option","char":"m","options":["npm","yarn"]},"git":{"name":"git","type":"option","char":"g","options":["y","n"]}},"args":[{"name":"projectName","description":"Project name","required":true}]},"api-mesh:status":{"id":"api-mesh:status","description":"Get a mesh status with a given meshid.","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"flags":{"ignoreCache":{"name":"ignoreCache","type":"boolean","char":"i","description":"Ignore cache and force manual org -> project -> workspace selection","allowNo":false}},"args":[]},"api-mesh:update":{"id":"api-mesh:update","description":"Update a mesh with the given config.","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"flags":{"ignoreCache":{"name":"ignoreCache","type":"boolean","char":"i","description":"Ignore cache and force manual org -> project -> workspace selection","allowNo":false},"autoConfirmAction":{"name":"autoConfirmAction","type":"boolean","char":"c","description":"Auto confirm action prompt. CLI will not check for user approval before executing the action.","allowNo":false},"env":{"name":"env","type":"option","char":"e","description":"Path to env file","default":".env"}},"args":[{"name":"file"}]},"api-mesh:source:discover":{"id":"api-mesh:source:discover","description":"Return the list of avaliable sources","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"flags":{"confirm":{"name":"confirm","type":"boolean","char":"c","description":"Auto confirm install action prompt. CLI will not check ask user to install source.","allowNo":false}},"args":[]},"api-mesh:source:get":{"id":"api-mesh:source:get","description":"Command returns the content of a specific source.","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"examples":["$ aio api-mesh:source:get -s=<version>@<source_name>","$ aio api-mesh:source:get -s<source_name>","$ aio api-mesh:source:get -m"],"flags":{"confirm":{"name":"confirm","type":"boolean","char":"c","description":"Auto confirm print action prompt. CLI will not check ask user to print source.","allowNo":false},"source":{"name":"source","type":"option","char":"s","description":"Source name"},"multiple":{"name":"multiple","type":"boolean","char":"m","description":"Select multiple sources","allowNo":false}},"args":[]},"api-mesh:source:install":{"id":"api-mesh:source:install","description":"Command to install the source to your API mesh.","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"examples":["$ aio api-mesh:source:install <version>@<source_name>","$ aio api-mesh:source:install <source_name> -v <variable_name>=<variable_value>","$ aio api-mesh:source:install <source_name> -f <path_to_variables_file>"],"flags":{"source":{"name":"source","type":"option","char":"s","description":"Source name"},"confirm":{"name":"confirm","type":"boolean","char":"c","description":"Auto confirm override action prompt. CLI will not check ask user to override source.","allowNo":false},"variable":{"name":"variable","type":"option","char":"v","description":"Variables required for the source"},"variable-file":{"name":"variable-file","type":"option","char":"f","description":"Variables file path"},"ignoreCache":{"name":"ignoreCache","type":"boolean","char":"i","description":"Ignore cache and force manual org -> project -> workspace selection","allowNo":false}},"args":[{"name":"source"}]}}}
|
package/package.json
CHANGED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"meshConfig": {
|
|
3
|
+
"sources": [
|
|
4
|
+
{
|
|
5
|
+
"name": "<json_source_name>",
|
|
6
|
+
"handler": {
|
|
7
|
+
"JsonSchema": {
|
|
8
|
+
"baseUrl": "<json_source__baseurl>",
|
|
9
|
+
"operations": [
|
|
10
|
+
{
|
|
11
|
+
"type": "Query",
|
|
12
|
+
"field": "<query>",
|
|
13
|
+
"path": "<query_path>",
|
|
14
|
+
"method": "POST",
|
|
15
|
+
"requestSchema": "./requestParams.json"
|
|
16
|
+
}
|
|
17
|
+
]
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
],
|
|
22
|
+
"plugins": [
|
|
23
|
+
{
|
|
24
|
+
"hooks": {
|
|
25
|
+
"beforeAll": {
|
|
26
|
+
"composer": "./hooks.js#functionName"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
],
|
|
31
|
+
"files": [
|
|
32
|
+
{
|
|
33
|
+
"path": "./requestParams.json",
|
|
34
|
+
"content": "{\"type\":\"dummyContent\"}"
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"path": "./hooks.js",
|
|
38
|
+
"content": "module.exports.functionName = () => { console.log('beforeAll hook'); }"
|
|
39
|
+
}
|
|
40
|
+
]
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -14,6 +14,7 @@ const mockConsoleCLIInstance = {};
|
|
|
14
14
|
|
|
15
15
|
const CreateCommand = require('../create');
|
|
16
16
|
const sampleCreateMeshConfig = require('../../__fixtures__/sample_mesh.json');
|
|
17
|
+
const meshConfigWithComposerFiles = require('../../__fixtures__/sample_mesh_with_composer_files.json');
|
|
17
18
|
const {
|
|
18
19
|
initSdk,
|
|
19
20
|
initRequestId,
|
|
@@ -165,6 +166,78 @@ describe('create command tests', () => {
|
|
|
165
166
|
`);
|
|
166
167
|
expect(CreateCommand.aliases).toMatchInlineSnapshot(`[]`);
|
|
167
168
|
});
|
|
169
|
+
|
|
170
|
+
test('should pass if a valid mesh config file with composer files are provided', async () => {
|
|
171
|
+
createMesh.mockResolvedValueOnce({
|
|
172
|
+
meshId: 'dummy_mesh_id',
|
|
173
|
+
meshConfig: meshConfigWithComposerFiles.meshConfig,
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
parseSpy.mockResolvedValueOnce({
|
|
177
|
+
args: { file: 'src/commands/__fixtures__/sample_mesh_with_composer_files.json' },
|
|
178
|
+
flags: {
|
|
179
|
+
autoConfirmAction: Promise.resolve(true),
|
|
180
|
+
},
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
const output = await CreateCommand.run();
|
|
184
|
+
|
|
185
|
+
expect(output).toMatchInlineSnapshot(`
|
|
186
|
+
{
|
|
187
|
+
"adobeIdIntegrationsForWorkspace": {
|
|
188
|
+
"apiKey": "dummy_api_key",
|
|
189
|
+
"id": "dummy_id",
|
|
190
|
+
},
|
|
191
|
+
"mesh": {
|
|
192
|
+
"meshConfig": {
|
|
193
|
+
"files": [
|
|
194
|
+
{
|
|
195
|
+
"content": "{"type":"dummyContent"}",
|
|
196
|
+
"path": "./requestParams.json",
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
"content": "module.exports.functionName = () => { console.log('beforeAll hook'); }",
|
|
200
|
+
"path": "./hooks.js",
|
|
201
|
+
},
|
|
202
|
+
],
|
|
203
|
+
"plugins": [
|
|
204
|
+
{
|
|
205
|
+
"hooks": {
|
|
206
|
+
"beforeAll": {
|
|
207
|
+
"composer": "./hooks.js#functionName",
|
|
208
|
+
},
|
|
209
|
+
},
|
|
210
|
+
},
|
|
211
|
+
],
|
|
212
|
+
"sources": [
|
|
213
|
+
{
|
|
214
|
+
"handler": {
|
|
215
|
+
"JsonSchema": {
|
|
216
|
+
"baseUrl": "<json_source__baseurl>",
|
|
217
|
+
"operations": [
|
|
218
|
+
{
|
|
219
|
+
"field": "<query>",
|
|
220
|
+
"method": "POST",
|
|
221
|
+
"path": "<query_path>",
|
|
222
|
+
"requestSchema": "./requestParams.json",
|
|
223
|
+
"type": "Query",
|
|
224
|
+
},
|
|
225
|
+
],
|
|
226
|
+
},
|
|
227
|
+
},
|
|
228
|
+
"name": "<json_source_name>",
|
|
229
|
+
},
|
|
230
|
+
],
|
|
231
|
+
},
|
|
232
|
+
"meshId": "dummy_mesh_id",
|
|
233
|
+
},
|
|
234
|
+
"sdkList": [
|
|
235
|
+
"dummy_service",
|
|
236
|
+
],
|
|
237
|
+
}
|
|
238
|
+
`);
|
|
239
|
+
});
|
|
240
|
+
|
|
168
241
|
test('should fail if create mesh api has failed', async () => {
|
|
169
242
|
createMesh.mockRejectedValueOnce(new Error('create mesh api failed'));
|
|
170
243
|
|
|
@@ -189,6 +262,7 @@ describe('create command tests', () => {
|
|
|
189
262
|
]
|
|
190
263
|
`);
|
|
191
264
|
});
|
|
265
|
+
|
|
192
266
|
test('should create if a valid mesh config file is provided', async () => {
|
|
193
267
|
const runResult = await CreateCommand.run();
|
|
194
268
|
|
|
@@ -295,7 +369,7 @@ describe('create command tests', () => {
|
|
|
295
369
|
let fetchedMeshConfig = sampleCreateMeshConfig;
|
|
296
370
|
fetchedMeshConfig.meshId = 'dummy_id';
|
|
297
371
|
fetchedMeshConfig.meshURL = 'https://tigraph.adobe.io';
|
|
298
|
-
getMesh.
|
|
372
|
+
getMesh.mockResolvedValueOnce(fetchedMeshConfig);
|
|
299
373
|
|
|
300
374
|
const runResult = await CreateCommand.run();
|
|
301
375
|
|
|
@@ -753,7 +827,7 @@ describe('create command tests', () => {
|
|
|
753
827
|
});
|
|
754
828
|
|
|
755
829
|
test('should successfully create a mesh if provided env file is valid, mesh interpolation is successful and interpolated mesh is a valid JSON', async () => {
|
|
756
|
-
parseSpy.
|
|
830
|
+
parseSpy.mockResolvedValueOnce({
|
|
757
831
|
args: { file: 'src/commands/__fixtures__/sample_mesh_with_placeholder' },
|
|
758
832
|
flags: {
|
|
759
833
|
ignoreCache: mockIgnoreCacheFlag,
|
|
@@ -804,7 +878,7 @@ describe('create command tests', () => {
|
|
|
804
878
|
});
|
|
805
879
|
|
|
806
880
|
test('should return error if inputMesh is not a valid JSON', async () => {
|
|
807
|
-
parseSpy.
|
|
881
|
+
parseSpy.mockResolvedValueOnce({
|
|
808
882
|
args: { file: 'src/commands/__fixtures__/sample_invalid_mesh.txt' },
|
|
809
883
|
flags: {
|
|
810
884
|
ignoreCache: mockIgnoreCacheFlag,
|
|
@@ -855,12 +929,12 @@ describe('create command tests', () => {
|
|
|
855
929
|
],
|
|
856
930
|
};
|
|
857
931
|
|
|
858
|
-
createMesh.
|
|
932
|
+
createMesh.mockResolvedValueOnce({
|
|
859
933
|
meshId: 'dummy_mesh_id',
|
|
860
934
|
meshConfig: meshConfig,
|
|
861
935
|
});
|
|
862
936
|
|
|
863
|
-
parseSpy.
|
|
937
|
+
parseSpy.mockResolvedValueOnce({
|
|
864
938
|
args: { file: 'src/commands/__fixtures__/sample_mesh_files.json' },
|
|
865
939
|
flags: {
|
|
866
940
|
autoConfirmAction: Promise.resolve(false),
|
|
@@ -970,7 +1044,7 @@ describe('create command tests', () => {
|
|
|
970
1044
|
});
|
|
971
1045
|
|
|
972
1046
|
test('should fail if the file name is more than 25 characters', async () => {
|
|
973
|
-
parseSpy.
|
|
1047
|
+
parseSpy.mockResolvedValueOnce({
|
|
974
1048
|
args: { file: 'src/commands/__fixtures__/sample_mesh_invalid_file_name.json' },
|
|
975
1049
|
flags: {
|
|
976
1050
|
autoConfirmAction: Promise.resolve(false),
|
|
@@ -998,36 +1072,8 @@ describe('create command tests', () => {
|
|
|
998
1072
|
`);
|
|
999
1073
|
});
|
|
1000
1074
|
|
|
1001
|
-
test('should fail if the file paths in files array and filenames in sources, transforms, additionalResolvers do not match in mesh config', async () => {
|
|
1002
|
-
parseSpy.mockResolvedValue({
|
|
1003
|
-
args: { file: 'src/commands/__fixtures__/sample_mesh_mismatching_path.json' },
|
|
1004
|
-
flags: {
|
|
1005
|
-
autoConfirmAction: Promise.resolve(false),
|
|
1006
|
-
},
|
|
1007
|
-
});
|
|
1008
|
-
|
|
1009
|
-
const output = CreateCommand.run();
|
|
1010
|
-
|
|
1011
|
-
await expect(output).rejects.toEqual(new Error('Input mesh config is not valid.'));
|
|
1012
|
-
|
|
1013
|
-
expect(logSpy.mock.calls).toMatchInlineSnapshot(`
|
|
1014
|
-
[
|
|
1015
|
-
[
|
|
1016
|
-
"Please make sure the file names are matching in meshConfig.",
|
|
1017
|
-
],
|
|
1018
|
-
]
|
|
1019
|
-
`);
|
|
1020
|
-
expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`
|
|
1021
|
-
[
|
|
1022
|
-
[
|
|
1023
|
-
"Input mesh config is not valid.",
|
|
1024
|
-
],
|
|
1025
|
-
]
|
|
1026
|
-
`);
|
|
1027
|
-
});
|
|
1028
|
-
|
|
1029
1075
|
test('should fail if the file is of type other than js, json extension', async () => {
|
|
1030
|
-
parseSpy.
|
|
1076
|
+
parseSpy.mockResolvedValueOnce({
|
|
1031
1077
|
args: { file: 'src/commands/__fixtures__/sample_mesh_invalid_type.json' },
|
|
1032
1078
|
flags: {
|
|
1033
1079
|
autoConfirmAction: Promise.resolve(false),
|
|
@@ -1055,7 +1101,7 @@ describe('create command tests', () => {
|
|
|
1055
1101
|
});
|
|
1056
1102
|
|
|
1057
1103
|
test('should fail if the files do not exist in the mesh directory or subdirectory', async () => {
|
|
1058
|
-
parseSpy.
|
|
1104
|
+
parseSpy.mockResolvedValueOnce({
|
|
1059
1105
|
args: { file: 'src/commands/__fixtures__/sample_mesh_invalid_paths.json' },
|
|
1060
1106
|
flags: {
|
|
1061
1107
|
autoConfirmAction: Promise.resolve(false),
|
|
@@ -1093,7 +1139,7 @@ describe('create command tests', () => {
|
|
|
1093
1139
|
});
|
|
1094
1140
|
|
|
1095
1141
|
test('should fail if import files function fails', async () => {
|
|
1096
|
-
parseSpy.
|
|
1142
|
+
parseSpy.mockResolvedValueOnce({
|
|
1097
1143
|
args: { file: 'src/commands/__fixtures__/sample_mesh_files.json' },
|
|
1098
1144
|
flags: {
|
|
1099
1145
|
autoConfirmAction: Promise.resolve(false),
|
|
@@ -1158,19 +1204,19 @@ describe('create command tests', () => {
|
|
|
1158
1204
|
],
|
|
1159
1205
|
};
|
|
1160
1206
|
|
|
1161
|
-
promptConfirm.
|
|
1207
|
+
promptConfirm.mockResolvedValueOnce(false).mockResolvedValueOnce(true);
|
|
1162
1208
|
|
|
1163
|
-
importFiles.
|
|
1209
|
+
importFiles.mockResolvedValueOnce(meshConfig);
|
|
1164
1210
|
|
|
1165
|
-
createMesh.
|
|
1211
|
+
createMesh.mockResolvedValueOnce({
|
|
1166
1212
|
meshId: 'dummy_mesh_id',
|
|
1167
1213
|
meshConfig: meshConfig,
|
|
1168
1214
|
});
|
|
1169
1215
|
|
|
1170
|
-
parseSpy.
|
|
1216
|
+
parseSpy.mockResolvedValueOnce({
|
|
1171
1217
|
args: { file: 'src/commands/__fixtures__/sample_mesh_with_files_array.json' },
|
|
1172
1218
|
flags: {
|
|
1173
|
-
autoConfirmAction: Promise.resolve(
|
|
1219
|
+
autoConfirmAction: Promise.resolve(true),
|
|
1174
1220
|
},
|
|
1175
1221
|
});
|
|
1176
1222
|
|
|
@@ -1298,12 +1344,12 @@ describe('create command tests', () => {
|
|
|
1298
1344
|
],
|
|
1299
1345
|
};
|
|
1300
1346
|
|
|
1301
|
-
promptConfirm.
|
|
1347
|
+
promptConfirm.mockResolvedValueOnce(true).mockResolvedValueOnce(true);
|
|
1302
1348
|
|
|
1303
|
-
parseSpy.
|
|
1349
|
+
parseSpy.mockResolvedValueOnce({
|
|
1304
1350
|
args: { file: 'src/commands/__fixtures__/sample_mesh_with_files_array.json' },
|
|
1305
1351
|
flags: {
|
|
1306
|
-
autoConfirmAction: Promise.resolve(
|
|
1352
|
+
autoConfirmAction: Promise.resolve(true),
|
|
1307
1353
|
},
|
|
1308
1354
|
});
|
|
1309
1355
|
|
|
@@ -1311,7 +1357,7 @@ describe('create command tests', () => {
|
|
|
1311
1357
|
meshConfig,
|
|
1312
1358
|
});
|
|
1313
1359
|
|
|
1314
|
-
createMesh.
|
|
1360
|
+
createMesh.mockResolvedValueOnce({
|
|
1315
1361
|
meshId: 'dummy_mesh_id',
|
|
1316
1362
|
meshConfig: meshConfig,
|
|
1317
1363
|
});
|
|
@@ -1443,20 +1489,20 @@ describe('create command tests', () => {
|
|
|
1443
1489
|
],
|
|
1444
1490
|
};
|
|
1445
1491
|
|
|
1446
|
-
parseSpy.
|
|
1492
|
+
parseSpy.mockResolvedValueOnce({
|
|
1447
1493
|
args: { file: 'src/commands/__fixtures__/sample_fully_qualified_mesh.json' },
|
|
1448
1494
|
flags: {
|
|
1449
|
-
autoConfirmAction: Promise.resolve(
|
|
1495
|
+
autoConfirmAction: Promise.resolve(true),
|
|
1450
1496
|
},
|
|
1451
1497
|
});
|
|
1452
1498
|
|
|
1453
|
-
promptConfirm.
|
|
1499
|
+
promptConfirm.mockResolvedValueOnce(true);
|
|
1454
1500
|
|
|
1455
1501
|
importFiles.mockResolvedValueOnce({
|
|
1456
1502
|
meshConfig,
|
|
1457
1503
|
});
|
|
1458
1504
|
|
|
1459
|
-
createMesh.
|
|
1505
|
+
createMesh.mockResolvedValueOnce({
|
|
1460
1506
|
meshId: 'dummy_mesh_id',
|
|
1461
1507
|
meshConfig: meshConfig,
|
|
1462
1508
|
});
|
|
@@ -1587,15 +1633,15 @@ describe('create command tests', () => {
|
|
|
1587
1633
|
],
|
|
1588
1634
|
};
|
|
1589
1635
|
|
|
1590
|
-
createMesh.
|
|
1636
|
+
createMesh.mockResolvedValueOnce({
|
|
1591
1637
|
meshId: 'dummy_mesh_id',
|
|
1592
1638
|
meshConfig: meshConfig,
|
|
1593
1639
|
});
|
|
1594
1640
|
|
|
1595
|
-
parseSpy.
|
|
1641
|
+
parseSpy.mockResolvedValueOnce({
|
|
1596
1642
|
args: { file: 'src/commands/__fixtures__/sample_mesh_subdirectory.json' },
|
|
1597
1643
|
flags: {
|
|
1598
|
-
autoConfirmAction: Promise.resolve(
|
|
1644
|
+
autoConfirmAction: Promise.resolve(true),
|
|
1599
1645
|
},
|
|
1600
1646
|
});
|
|
1601
1647
|
|
|
@@ -1702,7 +1748,7 @@ describe('create command tests', () => {
|
|
|
1702
1748
|
});
|
|
1703
1749
|
|
|
1704
1750
|
test('should fail if the file is outside the workspace directory', async () => {
|
|
1705
|
-
parseSpy.
|
|
1751
|
+
parseSpy.mockResolvedValueOnce({
|
|
1706
1752
|
args: { file: 'src/commands/__fixtures__/sample_mesh_outside_workspace_dir.json' },
|
|
1707
1753
|
flags: {
|
|
1708
1754
|
autoConfirmAction: Promise.resolve(false),
|
|
@@ -1729,7 +1775,7 @@ describe('create command tests', () => {
|
|
|
1729
1775
|
});
|
|
1730
1776
|
|
|
1731
1777
|
test('should fail if the file has invalid JSON content', async () => {
|
|
1732
|
-
parseSpy.
|
|
1778
|
+
parseSpy.mockResolvedValueOnce({
|
|
1733
1779
|
args: { file: 'src/commands/__fixtures__/sample_mesh_invalid_file_content.json' },
|
|
1734
1780
|
flags: {
|
|
1735
1781
|
autoConfirmAction: Promise.resolve(false),
|
|
@@ -1766,7 +1812,7 @@ describe('create command tests', () => {
|
|
|
1766
1812
|
});
|
|
1767
1813
|
|
|
1768
1814
|
test('should fail if the file path starts from home directory i.e., path starts with ~/', async () => {
|
|
1769
|
-
parseSpy.
|
|
1815
|
+
parseSpy.mockResolvedValueOnce({
|
|
1770
1816
|
args: { file: 'src/commands/__fixtures__/sample_mesh_path_from_home.json' },
|
|
1771
1817
|
flags: {
|
|
1772
1818
|
autoConfirmAction: Promise.resolve(false),
|
package/src/utils.js
CHANGED
|
@@ -88,7 +88,9 @@ function getFilesInMeshConfig(data, meshConfigName) {
|
|
|
88
88
|
data.meshConfig.sources.transforms?.forEach(transform => {
|
|
89
89
|
transform.replaceField?.replacements.forEach(replacement => {
|
|
90
90
|
if (replacement.composer && !fileURLRegex.test(replacement.composer)) {
|
|
91
|
-
|
|
91
|
+
const [filename] = replacement.composer.split('#');
|
|
92
|
+
|
|
93
|
+
filesList.push(filename);
|
|
92
94
|
}
|
|
93
95
|
});
|
|
94
96
|
});
|
|
@@ -97,16 +99,51 @@ function getFilesInMeshConfig(data, meshConfigName) {
|
|
|
97
99
|
data.meshConfig.transforms?.forEach(transform => {
|
|
98
100
|
transform.replaceField?.replacements.forEach(replacement => {
|
|
99
101
|
if (replacement.composer && !fileURLRegex.test(replacement.composer)) {
|
|
100
|
-
|
|
102
|
+
const [filename] = replacement.composer.split('#');
|
|
103
|
+
|
|
104
|
+
filesList.push(filename);
|
|
101
105
|
}
|
|
102
106
|
});
|
|
103
107
|
});
|
|
104
108
|
|
|
109
|
+
// Hooks Plugin - mesh level
|
|
110
|
+
data.meshConfig.plugins?.forEach(plugin => {
|
|
111
|
+
if (plugin.hooks) {
|
|
112
|
+
if (plugin.hooks.beforeAll) {
|
|
113
|
+
const composer = plugin.hooks.beforeAll.composer;
|
|
114
|
+
|
|
115
|
+
if (composer && !fileURLRegex.test(composer)) {
|
|
116
|
+
const [filename] = composer.split('#');
|
|
117
|
+
|
|
118
|
+
filesList.push(filename);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
// OnFetch plugin - mesh level
|
|
125
|
+
data.meshConfig.plugins?.forEach(plugin => {
|
|
126
|
+
if (plugin.onFetch) {
|
|
127
|
+
plugin.onFetch.forEach(onFetchConfig => {
|
|
128
|
+
const handler = onFetchConfig.handler;
|
|
129
|
+
|
|
130
|
+
if (handler) {
|
|
131
|
+
filesList.push(handler);
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
// remove duplicate files
|
|
138
|
+
filesList = [...new Set(filesList)];
|
|
139
|
+
|
|
140
|
+
logger.info(`Files to be imported: ${filesList.join(', ')}`);
|
|
141
|
+
|
|
105
142
|
try {
|
|
106
143
|
if (filesList.length) {
|
|
107
144
|
checkFilesAreUnderMeshDirectory(filesList, meshConfigName);
|
|
108
145
|
validateFileType(filesList);
|
|
109
|
-
validateFileName(filesList
|
|
146
|
+
validateFileName(filesList);
|
|
110
147
|
}
|
|
111
148
|
} catch (err) {
|
|
112
149
|
logger.error(err.message);
|
|
@@ -226,9 +263,8 @@ function validateFileType(filesList) {
|
|
|
226
263
|
* Validate the filenames
|
|
227
264
|
*
|
|
228
265
|
* @param filesList Files in sources, tranforms or additionalResolvers in the meshConfig
|
|
229
|
-
* @param data MeshConfig
|
|
230
266
|
*/
|
|
231
|
-
function validateFileName(filesList
|
|
267
|
+
function validateFileName(filesList) {
|
|
232
268
|
const filesWithInvalidNames = [];
|
|
233
269
|
|
|
234
270
|
// Check if the file names are less than 25 characters
|
|
@@ -244,17 +280,6 @@ function validateFileName(filesList, data) {
|
|
|
244
280
|
`Mesh file names must be less than 25 characters. The following file(s) are invalid: ${filesWithInvalidNames}.`,
|
|
245
281
|
);
|
|
246
282
|
}
|
|
247
|
-
|
|
248
|
-
// check if the the filePaths in the files array match
|
|
249
|
-
// the fileNames in sources, transforms or additionalResolvers
|
|
250
|
-
|
|
251
|
-
if (data.meshConfig.files) {
|
|
252
|
-
for (let i = 0; i < data.meshConfig.files.length; i++) {
|
|
253
|
-
if (filesList.indexOf(data.meshConfig.files[i].path) == -1) {
|
|
254
|
-
throw new Error(`Please make sure the file names are matching in meshConfig.`);
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
283
|
}
|
|
259
284
|
|
|
260
285
|
/**validates the environment file content
|