@aws-amplify/amplify-util-uibuilder 1.10.0 → 1.10.1-rds-1.0
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/CHANGELOG.md +11 -0
- package/package.json +7 -7
- package/src/__tests__/.eslintrc.js +0 -9
- package/src/__tests__/__snapshots__/syncAmplifyUiComponents.test.ts.snap +0 -46
- package/src/__tests__/cloneComponentsFromEnv.test.ts +0 -79
- package/src/__tests__/detachedFormCleanup.test.ts +0 -77
- package/src/__tests__/generateComponents.test.ts +0 -342
- package/src/__tests__/getAmplifyDataSchema.test.ts +0 -82
- package/src/__tests__/handleEvents.test.ts +0 -27
- package/src/__tests__/help.test.ts +0 -10
- package/src/__tests__/mock.json +0 -1
- package/src/__tests__/notifyMissingPackages.test.ts +0 -86
- package/src/__tests__/package.json +0 -3
- package/src/__tests__/prePushHandler.test.ts +0 -116
- package/src/__tests__/shouldRenderComponents.test.ts +0 -112
- package/src/__tests__/storageManager.test.ts +0 -45
- package/src/__tests__/syncAmplifyUiComponents.test.ts +0 -309
- package/src/__tests__/utils/getApiConfiguration.test.ts +0 -41
- package/src/__tests__/utils.ts +0 -72
- package/src/__tests__/version.test.ts +0 -10
- package/src/clients/amplify-studio-client.ts +0 -320
- package/src/clients/index.ts +0 -1
- package/src/commands/cloneComponentsFromEnv.ts +0 -53
- package/src/commands/generateComponents.ts +0 -125
- package/src/commands/help.ts +0 -8
- package/src/commands/utils/codegenResources.ts +0 -23
- package/src/commands/utils/detachedFormCleanup.ts +0 -54
- package/src/commands/utils/environmentHelpers.ts +0 -32
- package/src/commands/utils/extractArgs.ts +0 -25
- package/src/commands/utils/featureFlags.ts +0 -61
- package/src/commands/utils/getApiConfiguration.ts +0 -73
- package/src/commands/utils/getUiBuilderComponentsPath.ts +0 -21
- package/src/commands/utils/index.ts +0 -9
- package/src/commands/utils/notifyMissingPackages.ts +0 -47
- package/src/commands/utils/shouldRenderComponents.ts +0 -48
- package/src/commands/utils/storageManager.ts +0 -13
- package/src/commands/utils/syncAmplifyUiBuilderComponents.ts +0 -232
- package/src/commands/version.ts +0 -9
- package/src/event-handlers/handle-PostEnvAdd.ts +0 -16
- package/src/event-handlers/handle-PostPull.ts +0 -15
- package/src/event-handlers/handle-PostPush.ts +0 -15
- package/src/event-handlers/handle-PrePush.ts +0 -15
- package/src/index.ts +0 -26
- package/src/utils/prePushHandler.ts +0 -51
- package/tsconfig.json +0 -9
- package/tsconfig.tsbuildinfo +0 -1
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { run as runPostPull } from '../event-handlers/handle-PostPull';
|
|
2
|
-
import { run as runPostPush } from '../event-handlers/handle-PostPush';
|
|
3
|
-
import { run as generateComponents } from '../commands/generateComponents';
|
|
4
|
-
|
|
5
|
-
jest.mock('../commands/generateComponents');
|
|
6
|
-
|
|
7
|
-
describe('can handle events', () => {
|
|
8
|
-
let context: any;
|
|
9
|
-
|
|
10
|
-
beforeEach(() => {
|
|
11
|
-
context = {
|
|
12
|
-
amplify: {
|
|
13
|
-
invokePluginMethod: jest.fn(),
|
|
14
|
-
},
|
|
15
|
-
};
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it('handles postPull', async () => {
|
|
19
|
-
await runPostPull(context);
|
|
20
|
-
expect(generateComponents).toHaveBeenCalledWith(context, 'PostPull');
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it('handles postPush', async () => {
|
|
24
|
-
await runPostPush(context);
|
|
25
|
-
expect(generateComponents).toHaveBeenCalledWith(context, 'PostPush');
|
|
26
|
-
});
|
|
27
|
-
});
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
jest.mock('@aws-amplify/amplify-prompts');
|
|
2
|
-
import { printer } from '@aws-amplify/amplify-prompts';
|
|
3
|
-
import { run } from '../commands/help';
|
|
4
|
-
printer.info = jest.fn();
|
|
5
|
-
describe('can run help script', () => {
|
|
6
|
-
it('runs help script', async () => {
|
|
7
|
-
await run();
|
|
8
|
-
expect(printer.info).toBeCalledTimes(1);
|
|
9
|
-
});
|
|
10
|
-
});
|
package/src/__tests__/mock.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import * as printerDependency from '@aws-amplify/amplify-prompts';
|
|
2
|
-
import * as JSONUtilitiesDependency from '@aws-amplify/amplify-cli-core';
|
|
3
|
-
import { notifyMissingPackages } from '../commands/utils/notifyMissingPackages';
|
|
4
|
-
import { $TSContext } from '@aws-amplify/amplify-cli-core';
|
|
5
|
-
jest.mock('@aws-amplify/amplify-prompts');
|
|
6
|
-
jest.mock('@aws-amplify/amplify-cli-core');
|
|
7
|
-
printerDependency.printer.info = jest.fn();
|
|
8
|
-
printerDependency.printer.debug = jest.fn();
|
|
9
|
-
printerDependency.printer.warn = jest.fn();
|
|
10
|
-
|
|
11
|
-
describe('should notify when packages are missing', () => {
|
|
12
|
-
beforeEach(() => {
|
|
13
|
-
jest.resetAllMocks();
|
|
14
|
-
JSONUtilitiesDependency.JSONUtilities.readJson = jest.fn().mockImplementation(() => ({
|
|
15
|
-
projectPath: __dirname,
|
|
16
|
-
dependencies: [],
|
|
17
|
-
}));
|
|
18
|
-
});
|
|
19
|
-
it('skips notification if localEnv path cannot be determined', async () => {
|
|
20
|
-
const context = {
|
|
21
|
-
input: {
|
|
22
|
-
options: {
|
|
23
|
-
localEnvFilePath: 'fake',
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
};
|
|
27
|
-
notifyMissingPackages(context as unknown as $TSContext, false);
|
|
28
|
-
expect(printerDependency.printer.debug).toBeCalledTimes(1);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it('skips notification if package.json cannot be determined', async () => {
|
|
32
|
-
JSONUtilitiesDependency.JSONUtilities.readJson = jest.fn().mockImplementation(() => ({
|
|
33
|
-
projectPath: 'asdf',
|
|
34
|
-
dependencies: [],
|
|
35
|
-
}));
|
|
36
|
-
const context = {
|
|
37
|
-
input: {
|
|
38
|
-
options: {
|
|
39
|
-
localEnvFilePath: __dirname + '/mock.json',
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
};
|
|
43
|
-
notifyMissingPackages(context as unknown as $TSContext, false);
|
|
44
|
-
expect(printerDependency.printer.debug).toBeCalledTimes(1);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('notifies for all missing dependencies', async () => {
|
|
48
|
-
const context = {
|
|
49
|
-
input: {
|
|
50
|
-
options: {
|
|
51
|
-
localEnvFilePath: __dirname + '/mock.json',
|
|
52
|
-
},
|
|
53
|
-
},
|
|
54
|
-
};
|
|
55
|
-
notifyMissingPackages(context as unknown as $TSContext, true);
|
|
56
|
-
expect(printerDependency.printer.warn).toBeCalledTimes(3);
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it('notifies for partial missing dependencies', async () => {
|
|
60
|
-
JSONUtilitiesDependency.JSONUtilities.readJson = jest.fn().mockImplementation(() => ({
|
|
61
|
-
projectPath: __dirname,
|
|
62
|
-
dependencies: { '@aws-amplify/ui-react': '4.6.0' },
|
|
63
|
-
}));
|
|
64
|
-
const context = {
|
|
65
|
-
input: {
|
|
66
|
-
options: {
|
|
67
|
-
localEnvFilePath: __dirname + '/mock.json',
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
|
-
};
|
|
71
|
-
notifyMissingPackages(context as unknown as $TSContext);
|
|
72
|
-
expect(printerDependency.printer.warn).toBeCalledTimes(1);
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
it('notifies for all dependencies except storage if user is not using StorageManager', () => {
|
|
76
|
-
const context = {
|
|
77
|
-
input: {
|
|
78
|
-
options: {
|
|
79
|
-
localEnvFilePath: __dirname + '/mock.json',
|
|
80
|
-
},
|
|
81
|
-
},
|
|
82
|
-
};
|
|
83
|
-
notifyMissingPackages(context as unknown as $TSContext, false);
|
|
84
|
-
expect(printerDependency.printer.warn).toBeCalledTimes(2);
|
|
85
|
-
});
|
|
86
|
-
});
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
// aws-sdk, @aws-amplify/amplify-cli-core, amplify-prompts are in package dependencies
|
|
2
|
-
import aws from 'aws-sdk'; // eslint-disable-line import/no-extraneous-dependencies
|
|
3
|
-
import { Form } from 'aws-sdk/clients/amplifyuibuilder'; // eslint-disable-line import/no-extraneous-dependencies
|
|
4
|
-
import { printer } from '@aws-amplify/amplify-prompts'; // eslint-disable-line import/no-extraneous-dependencies
|
|
5
|
-
import * as utils from '../commands/utils';
|
|
6
|
-
import { prePushHandler } from '../utils/prePushHandler';
|
|
7
|
-
import { isDataStoreEnabled } from '@aws-amplify/amplify-category-api';
|
|
8
|
-
|
|
9
|
-
jest.mock('../commands/utils');
|
|
10
|
-
jest.mock('@aws-amplify/amplify-cli-core');
|
|
11
|
-
jest.mock('../commands/utils/featureFlags', () => ({
|
|
12
|
-
getTransformerVersion: jest.fn().mockImplementation(() => 2),
|
|
13
|
-
}));
|
|
14
|
-
jest.mock('@aws-amplify/amplify-category-api', () => ({
|
|
15
|
-
...jest.requireActual('@aws-amplify/amplify-category-api'),
|
|
16
|
-
isDataStoreEnabled: jest.fn(),
|
|
17
|
-
}));
|
|
18
|
-
|
|
19
|
-
const awsMock = aws as any;
|
|
20
|
-
const utilsMock = utils as any;
|
|
21
|
-
const isDataStoreEnabledMocked = jest.mocked(isDataStoreEnabled);
|
|
22
|
-
|
|
23
|
-
utilsMock.shouldRenderComponents = jest.fn().mockImplementation(() => true);
|
|
24
|
-
|
|
25
|
-
describe('handlePrePush', () => {
|
|
26
|
-
let context: any;
|
|
27
|
-
let mockedExport: jest.Mock<any, any>;
|
|
28
|
-
let exportedForms: Form[];
|
|
29
|
-
|
|
30
|
-
beforeEach(() => {
|
|
31
|
-
isDataStoreEnabledMocked.mockResolvedValue(true);
|
|
32
|
-
context = {
|
|
33
|
-
amplify: {
|
|
34
|
-
invokePluginMethod: jest.fn().mockResolvedValue({ models: { Comment: {} } }),
|
|
35
|
-
},
|
|
36
|
-
input: {
|
|
37
|
-
options: {
|
|
38
|
-
appId: 'testAppId',
|
|
39
|
-
envName: 'testEnvName',
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
exportedForms = [
|
|
45
|
-
{
|
|
46
|
-
name: 'BlogCreateForm',
|
|
47
|
-
formActionType: 'create',
|
|
48
|
-
fields: {},
|
|
49
|
-
style: {},
|
|
50
|
-
schemaVersion: '1.0',
|
|
51
|
-
sectionalElements: {},
|
|
52
|
-
appId: '1234',
|
|
53
|
-
environmentName: 'staging',
|
|
54
|
-
dataType: {
|
|
55
|
-
dataSourceType: 'DataStore',
|
|
56
|
-
dataTypeName: 'Blog',
|
|
57
|
-
},
|
|
58
|
-
id: '12345',
|
|
59
|
-
},
|
|
60
|
-
{
|
|
61
|
-
name: 'BlogUpdateForm',
|
|
62
|
-
formActionType: 'update',
|
|
63
|
-
fields: {},
|
|
64
|
-
style: {},
|
|
65
|
-
schemaVersion: '1.0',
|
|
66
|
-
sectionalElements: {},
|
|
67
|
-
appId: '1234',
|
|
68
|
-
environmentName: 'staging',
|
|
69
|
-
dataType: {
|
|
70
|
-
dataSourceType: 'DataStore',
|
|
71
|
-
dataTypeName: 'Blog',
|
|
72
|
-
},
|
|
73
|
-
id: '12345',
|
|
74
|
-
},
|
|
75
|
-
];
|
|
76
|
-
|
|
77
|
-
mockedExport = jest.fn(() => ({
|
|
78
|
-
entities: exportedForms,
|
|
79
|
-
}));
|
|
80
|
-
|
|
81
|
-
awsMock.AmplifyUIBuilder = jest.fn(() => ({
|
|
82
|
-
exportForms: jest.fn(() => ({
|
|
83
|
-
promise: () => mockedExport(),
|
|
84
|
-
})),
|
|
85
|
-
getMetadata: jest.fn(() => ({
|
|
86
|
-
promise: jest.fn(() => ({
|
|
87
|
-
features: {
|
|
88
|
-
autoGenerateForms: 'true',
|
|
89
|
-
autoGenerateViews: 'true',
|
|
90
|
-
formFeatureFlags: {
|
|
91
|
-
isRelationshipSupported: 'false',
|
|
92
|
-
isNonModelSupported: 'false',
|
|
93
|
-
},
|
|
94
|
-
},
|
|
95
|
-
})),
|
|
96
|
-
})),
|
|
97
|
-
}));
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
it('runs handlePrePush', async () => {
|
|
101
|
-
utilsMock.isFormDetachedFromModel = jest.fn().mockReturnValue(true);
|
|
102
|
-
utilsMock.isFormSchemaCustomized = jest.fn().mockReturnValue(true);
|
|
103
|
-
const spy = jest.spyOn(printer, 'warn');
|
|
104
|
-
await prePushHandler(context);
|
|
105
|
-
expect(spy).toHaveBeenCalledWith(
|
|
106
|
-
'The following forms will no longer be available because the connected data model no longer exists: BlogCreateForm, BlogUpdateForm',
|
|
107
|
-
);
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
it('runs handlePrePush without schema', async () => {
|
|
111
|
-
context.amplify.invokePluginMethod = jest.fn().mockResolvedValue(null);
|
|
112
|
-
const spy = jest.spyOn(printer, 'debug');
|
|
113
|
-
await prePushHandler(context);
|
|
114
|
-
expect(spy).toHaveBeenCalledWith('Local schema not found');
|
|
115
|
-
});
|
|
116
|
-
});
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
2
|
-
import { $TSContext } from '@aws-amplify/amplify-cli-core';
|
|
3
|
-
import aws from 'aws-sdk'; // eslint-disable-line import/no-extraneous-dependencies
|
|
4
|
-
import { shouldRenderComponents } from '../commands/utils/shouldRenderComponents';
|
|
5
|
-
|
|
6
|
-
const awsMock = aws as any;
|
|
7
|
-
|
|
8
|
-
jest.mock('@aws-amplify/amplify-cli-core', () => ({
|
|
9
|
-
...jest.requireActual('@aws-amplify/amplify-cli-core'),
|
|
10
|
-
stateManager: {
|
|
11
|
-
getProjectConfig: jest.fn().mockReturnValue({
|
|
12
|
-
providers: ['awscloudformation'],
|
|
13
|
-
frontend: 'javascript',
|
|
14
|
-
javascript: {
|
|
15
|
-
framework: 'react',
|
|
16
|
-
},
|
|
17
|
-
}),
|
|
18
|
-
},
|
|
19
|
-
}));
|
|
20
|
-
|
|
21
|
-
jest.mock('../clients', () => ({
|
|
22
|
-
AmplifyStudioClient: {
|
|
23
|
-
isAmplifyApp: jest.fn().mockReturnValue(true),
|
|
24
|
-
},
|
|
25
|
-
}));
|
|
26
|
-
|
|
27
|
-
describe('should render components', () => {
|
|
28
|
-
let context: $TSContext | any;
|
|
29
|
-
|
|
30
|
-
beforeAll(async () => {
|
|
31
|
-
// set metadata response
|
|
32
|
-
awsMock.AmplifyUIBuilder = jest.fn(() => ({
|
|
33
|
-
getMetadata: jest.fn(() => ({
|
|
34
|
-
promise: jest.fn(() => ({
|
|
35
|
-
features: {
|
|
36
|
-
autoGenerateForms: 'true',
|
|
37
|
-
autoGenerateViews: 'true',
|
|
38
|
-
formFeatureFlags: {
|
|
39
|
-
isRelationshipSupported: 'false',
|
|
40
|
-
isNonModelSupported: 'false',
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
})),
|
|
44
|
-
})),
|
|
45
|
-
}));
|
|
46
|
-
context = {
|
|
47
|
-
input: {
|
|
48
|
-
options: {
|
|
49
|
-
'no-codegen': false,
|
|
50
|
-
appId: 'testAppId',
|
|
51
|
-
envName: 'testEnvName',
|
|
52
|
-
},
|
|
53
|
-
},
|
|
54
|
-
};
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it('works with a valid config', async () => {
|
|
58
|
-
const shouldIt = await shouldRenderComponents(context);
|
|
59
|
-
expect(shouldIt).toBe(true);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it("doesn't work if --no-codegen flag is set", async () => {
|
|
63
|
-
context.input.options['no-codegen'] = true;
|
|
64
|
-
const shouldIt = await shouldRenderComponents(context);
|
|
65
|
-
expect(shouldIt).toBe(false);
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it("doesn't work if provider is not awscloudformation", async () => {
|
|
69
|
-
jest.mock('@aws-amplify/amplify-cli-core', () => ({
|
|
70
|
-
stateManager: {
|
|
71
|
-
getProjectConfig: jest.fn().mockReturnValue({
|
|
72
|
-
providers: [],
|
|
73
|
-
frontend: 'javascript',
|
|
74
|
-
javascript: {
|
|
75
|
-
framework: 'react',
|
|
76
|
-
},
|
|
77
|
-
}),
|
|
78
|
-
},
|
|
79
|
-
}));
|
|
80
|
-
const shouldIt = await shouldRenderComponents(context);
|
|
81
|
-
expect(shouldIt).toBe(false);
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it('should return false if frontend is ios', async () => {
|
|
85
|
-
jest.mock('@aws-amplify/amplify-cli-core', () => ({
|
|
86
|
-
stateManager: {
|
|
87
|
-
getProjectConfig: jest.fn().mockReturnValue({
|
|
88
|
-
providers: [],
|
|
89
|
-
frontend: 'ios',
|
|
90
|
-
}),
|
|
91
|
-
},
|
|
92
|
-
}));
|
|
93
|
-
const shouldIt = await shouldRenderComponents(context);
|
|
94
|
-
expect(shouldIt).toBe(false);
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it('should return false if frontend is vue', async () => {
|
|
98
|
-
jest.mock('@aws-amplify/amplify-cli-core', () => ({
|
|
99
|
-
stateManager: {
|
|
100
|
-
getProjectConfig: jest.fn().mockReturnValue({
|
|
101
|
-
providers: [],
|
|
102
|
-
frontend: 'javascript',
|
|
103
|
-
javascript: {
|
|
104
|
-
framework: 'vue',
|
|
105
|
-
},
|
|
106
|
-
}),
|
|
107
|
-
},
|
|
108
|
-
}));
|
|
109
|
-
const shouldIt = await shouldRenderComponents(context);
|
|
110
|
-
expect(shouldIt).toBe(false);
|
|
111
|
-
});
|
|
112
|
-
});
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { hasStorageField } from '../commands/utils';
|
|
2
|
-
import { Form } from 'aws-sdk/clients/amplifyuibuilder';
|
|
3
|
-
|
|
4
|
-
const formWithNoCustomization: Form = {
|
|
5
|
-
id: 'f-123456',
|
|
6
|
-
appId: '123',
|
|
7
|
-
environmentName: 'staging',
|
|
8
|
-
schemaVersion: '1.0',
|
|
9
|
-
name: 'BlogCreateForm',
|
|
10
|
-
formActionType: 'create',
|
|
11
|
-
dataType: {
|
|
12
|
-
dataSourceType: 'DataStore',
|
|
13
|
-
dataTypeName: 'Blog',
|
|
14
|
-
},
|
|
15
|
-
fields: {},
|
|
16
|
-
sectionalElements: {},
|
|
17
|
-
style: {},
|
|
18
|
-
cta: {},
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
const formWithNoStorageField: Form = {
|
|
22
|
-
...formWithNoCustomization,
|
|
23
|
-
dataType: { dataSourceType: 'Custom', dataTypeName: 'Blog' },
|
|
24
|
-
fields: {
|
|
25
|
-
name: { inputType: { type: 'TextField' } },
|
|
26
|
-
},
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
const formWithStorageField: Form = {
|
|
30
|
-
...formWithNoCustomization,
|
|
31
|
-
dataType: { dataSourceType: 'Custom', dataTypeName: 'Blog' },
|
|
32
|
-
fields: {
|
|
33
|
-
name: { inputType: { type: 'StorageField' } },
|
|
34
|
-
},
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
describe('hasStorageManager', () => {
|
|
38
|
-
it('should return false for form with no StorageManager config', () => {
|
|
39
|
-
expect(hasStorageField(formWithNoStorageField)).toBe(false);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('should return true for form with StorageManager config', () => {
|
|
43
|
-
expect(hasStorageField(formWithStorageField)).toBe(true);
|
|
44
|
-
});
|
|
45
|
-
});
|