@aws-amplify/amplify-util-uibuilder 1.5.0 → 1.6.0-cdkv2.1
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 +24 -0
- package/amplify-plugin.json +10 -3
- package/lib/clients/amplify-studio-client.d.ts +13 -2
- package/lib/clients/amplify-studio-client.d.ts.map +1 -1
- package/lib/clients/amplify-studio-client.js +85 -17
- package/lib/clients/amplify-studio-client.js.map +1 -1
- package/lib/commands/generateComponents.d.ts.map +1 -1
- package/lib/commands/generateComponents.js +33 -15
- package/lib/commands/generateComponents.js.map +1 -1
- package/lib/commands/help.d.ts +1 -1
- package/lib/commands/help.d.ts.map +1 -1
- package/lib/commands/help.js +2 -2
- package/lib/commands/help.js.map +1 -1
- package/lib/commands/utils/codegenResources.d.ts +12 -2
- package/lib/commands/utils/codegenResources.d.ts.map +1 -1
- package/lib/commands/utils/codegenResources.js +70 -3
- package/lib/commands/utils/codegenResources.js.map +1 -1
- package/lib/commands/utils/featureFlags.d.ts +2 -0
- package/lib/commands/utils/featureFlags.d.ts.map +1 -0
- package/lib/commands/utils/featureFlags.js +35 -0
- package/lib/commands/utils/featureFlags.js.map +1 -0
- package/lib/commands/utils/getUiBuilderComponentsPath.d.ts.map +1 -1
- package/lib/commands/utils/getUiBuilderComponentsPath.js.map +1 -1
- package/lib/commands/utils/shouldRenderComponents.d.ts +1 -1
- package/lib/commands/utils/shouldRenderComponents.d.ts.map +1 -1
- package/lib/commands/utils/shouldRenderComponents.js +14 -8
- package/lib/commands/utils/shouldRenderComponents.js.map +1 -1
- package/lib/commands/utils/syncAmplifyUiBuilderComponents.d.ts +12 -20
- package/lib/commands/utils/syncAmplifyUiBuilderComponents.d.ts.map +1 -1
- package/lib/commands/utils/syncAmplifyUiBuilderComponents.js +36 -3
- package/lib/commands/utils/syncAmplifyUiBuilderComponents.js.map +1 -1
- package/lib/commands/version.d.ts +1 -1
- package/lib/commands/version.d.ts.map +1 -1
- package/lib/commands/version.js +2 -2
- package/lib/commands/version.js.map +1 -1
- package/lib/event-handlers/handle-PostEnvAdd.d.ts +1 -1
- package/lib/event-handlers/handle-PostEnvAdd.d.ts.map +1 -1
- package/lib/event-handlers/handle-PostEnvAdd.js +4 -6
- package/lib/event-handlers/handle-PostEnvAdd.js.map +1 -1
- package/lib/event-handlers/handle-PostPull.d.ts +1 -1
- package/lib/event-handlers/handle-PostPull.d.ts.map +1 -1
- package/lib/event-handlers/handle-PostPull.js +4 -3
- package/lib/event-handlers/handle-PostPull.js.map +1 -1
- package/lib/event-handlers/handle-PostPush.d.ts +3 -0
- package/lib/event-handlers/handle-PostPush.d.ts.map +1 -0
- package/lib/event-handlers/handle-PostPush.js +15 -0
- package/lib/event-handlers/handle-PostPush.js.map +1 -0
- package/package.json +8 -7
- package/src/__tests__/cloneComponentsFromEnv.test.ts +17 -6
- package/src/__tests__/createUiBuilderComponent.test.ts +21 -3
- package/src/__tests__/generateComponents.test.ts +43 -15
- package/src/__tests__/getAmplifyDataSchema.test.ts +51 -19
- package/src/__tests__/shouldRenderComponents.test.ts +51 -4
- package/src/__tests__/syncAmplifyUiComponents.test.ts +113 -8
- package/src/__tests__/utils.ts +70 -0
- package/src/clients/amplify-studio-client.ts +157 -69
- package/src/commands/generateComponents.ts +43 -16
- package/src/commands/help.ts +5 -2
- package/src/commands/utils/codegenResources.ts +108 -4
- package/src/commands/utils/featureFlags.ts +62 -0
- package/src/commands/utils/getUiBuilderComponentsPath.ts +7 -2
- package/src/commands/utils/shouldRenderComponents.ts +20 -8
- package/src/commands/utils/syncAmplifyUiBuilderComponents.ts +76 -29
- package/src/commands/version.ts +5 -2
- package/src/event-handlers/handle-PostEnvAdd.ts +8 -6
- package/src/event-handlers/handle-PostPull.ts +7 -3
- package/src/event-handlers/handle-PostPush.ts +15 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/src/__tests__/handleEvents.test.ts +0 -21
|
@@ -1,30 +1,43 @@
|
|
|
1
1
|
import { printer } from 'amplify-prompts';
|
|
2
2
|
import { $TSContext } from 'amplify-cli-core';
|
|
3
3
|
import {
|
|
4
|
-
StudioComponent, StudioTheme, GenericDataSchema,
|
|
4
|
+
StudioComponent, StudioTheme, GenericDataSchema, StudioForm, StudioSchema,checkIsSupportedAsForm
|
|
5
5
|
} from '@aws-amplify/codegen-ui';
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
createUiBuilderComponent,
|
|
8
|
+
createUiBuilderForm,
|
|
9
|
+
createUiBuilderTheme,
|
|
10
|
+
generateBaseForms,
|
|
11
|
+
} from './codegenResources';
|
|
7
12
|
import { getUiBuilderComponentsPath } from './getUiBuilderComponentsPath';
|
|
8
13
|
|
|
14
|
+
type CodegenResponse<T extends StudioSchema> =
|
|
15
|
+
| {
|
|
16
|
+
resultType: 'SUCCESS';
|
|
17
|
+
schema: T;
|
|
18
|
+
schemaName?: string;
|
|
19
|
+
}
|
|
20
|
+
| {
|
|
21
|
+
resultType: 'FAILURE';
|
|
22
|
+
schemaName: string;
|
|
23
|
+
error: Error;
|
|
24
|
+
schema?: T;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
// TODO: when types are updated in codegen-ui reference mappers here so the arguments accepted are not any
|
|
28
|
+
|
|
9
29
|
/**
|
|
10
30
|
* Returns instances of StudioComponent from the component schemas
|
|
11
31
|
*/
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
} | {
|
|
19
|
-
resultType: string;
|
|
20
|
-
schemaName: string;
|
|
21
|
-
error: Error;
|
|
22
|
-
component?: undefined;
|
|
23
|
-
})[] => {
|
|
24
|
-
const componentResults = componentSchemas.map(schema => {
|
|
32
|
+
export const generateUiBuilderComponents = (
|
|
33
|
+
context: $TSContext,
|
|
34
|
+
componentSchemas: any[], // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
35
|
+
dataSchema?: GenericDataSchema,
|
|
36
|
+
): CodegenResponse<StudioComponent>[] => {
|
|
37
|
+
const componentResults = componentSchemas.map<CodegenResponse<StudioComponent>>(schema => {
|
|
25
38
|
try {
|
|
26
39
|
const component = createUiBuilderComponent(context, schema, dataSchema);
|
|
27
|
-
return { resultType: 'SUCCESS', component };
|
|
40
|
+
return { resultType: 'SUCCESS', schema: component };
|
|
28
41
|
} catch (e) {
|
|
29
42
|
printer.debug(`Failure caught processing ${schema.name}`);
|
|
30
43
|
printer.debug(e);
|
|
@@ -44,21 +57,11 @@ export const generateUiBuilderComponents = (context: $TSContext, componentSchema
|
|
|
44
57
|
* Returns instances of StudioTheme from theme schemas
|
|
45
58
|
*/
|
|
46
59
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
47
|
-
export const generateUiBuilderThemes = (context: $TSContext, themeSchemas: any[]):
|
|
48
|
-
|
|
49
|
-
theme: StudioTheme;
|
|
50
|
-
schemaName?: undefined;
|
|
51
|
-
error?: undefined;
|
|
52
|
-
} | {
|
|
53
|
-
resultType: string;
|
|
54
|
-
schemaName: string;
|
|
55
|
-
error: Error;
|
|
56
|
-
theme?: undefined;
|
|
57
|
-
})[] => {
|
|
58
|
-
const themeResults = themeSchemas.map(schema => {
|
|
60
|
+
export const generateUiBuilderThemes = (context: $TSContext, themeSchemas: any[]): CodegenResponse<StudioTheme>[] => {
|
|
61
|
+
const themeResults = themeSchemas.map<CodegenResponse<StudioTheme>>(schema => {
|
|
59
62
|
try {
|
|
60
63
|
const theme = createUiBuilderTheme(context, schema);
|
|
61
|
-
return { resultType: 'SUCCESS', theme };
|
|
64
|
+
return { resultType: 'SUCCESS', schema: theme };
|
|
62
65
|
} catch (e) {
|
|
63
66
|
printer.debug(`Failure caught processing ${schema.name}`);
|
|
64
67
|
printer.debug(e);
|
|
@@ -71,3 +74,47 @@ export const generateUiBuilderThemes = (context: $TSContext, themeSchemas: any[]
|
|
|
71
74
|
);
|
|
72
75
|
return themeResults;
|
|
73
76
|
};
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Returns instances of StudioForm from form schemas
|
|
80
|
+
*/
|
|
81
|
+
export const generateUiBuilderForms = (
|
|
82
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
83
|
+
context: $TSContext,
|
|
84
|
+
formSchemas: any[],
|
|
85
|
+
dataSchema?: GenericDataSchema,
|
|
86
|
+
autoGenerateForms?: boolean,
|
|
87
|
+
): CodegenResponse<StudioForm>[] => {
|
|
88
|
+
const modelMap: { [model: string]: Set<'create' | 'update'> } = {};
|
|
89
|
+
if (dataSchema?.dataSourceType === 'DataStore' && autoGenerateForms) {
|
|
90
|
+
Object.entries(dataSchema.models).forEach(([name, model]) => {
|
|
91
|
+
if(checkIsSupportedAsForm(model) && !model.isJoinTable) {
|
|
92
|
+
modelMap[name] = new Set(['create', 'update']);
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
const codegenForm = (schema: StudioForm): CodegenResponse<StudioForm> => {
|
|
97
|
+
try {
|
|
98
|
+
const form = createUiBuilderForm(context, schema, dataSchema);
|
|
99
|
+
return { resultType: 'SUCCESS', schema: form };
|
|
100
|
+
} catch (e) {
|
|
101
|
+
printer.debug(`Failure caught processing ${schema.name}`);
|
|
102
|
+
printer.debug(e);
|
|
103
|
+
return { resultType: 'FAILURE', schemaName: schema.name, error: e };
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
const formResults = formSchemas.map((schema: StudioForm) => {
|
|
107
|
+
if (schema?.dataType && schema.dataType?.dataSourceType === 'DataStore') {
|
|
108
|
+
modelMap[schema.dataType.dataTypeName]?.delete(schema.formActionType);
|
|
109
|
+
}
|
|
110
|
+
return codegenForm(schema);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
// append remaining models
|
|
114
|
+
formResults.push(...generateBaseForms(modelMap).map(codegenForm));
|
|
115
|
+
|
|
116
|
+
printer.debug(
|
|
117
|
+
`Generated ${formResults.filter(result => result.resultType === 'SUCCESS').length} forms in ${getUiBuilderComponentsPath(context)}`,
|
|
118
|
+
);
|
|
119
|
+
return formResults;
|
|
120
|
+
};
|
package/src/commands/version.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { printer } from 'amplify-prompts';
|
|
2
2
|
import path from 'path';
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* runs version command
|
|
6
|
+
*/
|
|
7
|
+
export const run = async (): Promise<void> => {
|
|
5
8
|
printer.info((await import(path.join(__dirname, '..', '..', 'package.json'))).version);
|
|
6
|
-
}
|
|
9
|
+
};
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { $TSContext } from 'amplify-cli-core';
|
|
2
2
|
import { printer } from 'amplify-prompts';
|
|
3
|
+
import { run as cloneComponentsFromEnv } from '../commands/cloneComponentsFromEnv';
|
|
3
4
|
|
|
4
|
-
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* runs after adding an environment
|
|
8
|
+
*/
|
|
9
|
+
export const run = async (context: $TSContext): Promise<void> => {
|
|
5
10
|
try {
|
|
6
|
-
await
|
|
7
|
-
context,
|
|
8
|
-
'cloneComponentsFromEnv',
|
|
9
|
-
]);
|
|
11
|
+
await cloneComponentsFromEnv(context);
|
|
10
12
|
} catch (e) {
|
|
11
13
|
// Swallow all errors from the uibuilder plugin
|
|
12
14
|
printer.debug(e);
|
|
13
15
|
}
|
|
14
|
-
}
|
|
16
|
+
};
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import { $TSContext } from 'amplify-cli-core';
|
|
2
2
|
import { printer } from 'amplify-prompts';
|
|
3
|
+
import { run as generateComponents } from '../commands/generateComponents';
|
|
3
4
|
|
|
4
|
-
|
|
5
|
+
/**
|
|
6
|
+
* The code to run after a pull.
|
|
7
|
+
*/
|
|
8
|
+
export const run = async (context: $TSContext): Promise<void> => {
|
|
5
9
|
try {
|
|
6
|
-
await
|
|
10
|
+
await generateComponents(context);
|
|
7
11
|
} catch (e) {
|
|
8
12
|
// Swallow all errors from the uibuilder plugin
|
|
9
13
|
printer.debug(e);
|
|
10
14
|
}
|
|
11
|
-
}
|
|
15
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { $TSContext } from 'amplify-cli-core';
|
|
2
|
+
import { printer } from 'amplify-prompts';
|
|
3
|
+
import { run as generateComponents } from '../commands/generateComponents';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The code to run after a push
|
|
7
|
+
*/
|
|
8
|
+
export const run = async (context: $TSContext): Promise<void> => {
|
|
9
|
+
try {
|
|
10
|
+
await generateComponents(context);
|
|
11
|
+
} catch (e) {
|
|
12
|
+
// Swallow all errors from the uibuilder plugin
|
|
13
|
+
printer.debug(e);
|
|
14
|
+
}
|
|
15
|
+
};
|