@aws-amplify/amplify-util-uibuilder 1.5.0 → 1.6.0-cdkv2.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.
Files changed (69) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/amplify-plugin.json +10 -3
  3. package/lib/clients/amplify-studio-client.d.ts +13 -2
  4. package/lib/clients/amplify-studio-client.d.ts.map +1 -1
  5. package/lib/clients/amplify-studio-client.js +85 -17
  6. package/lib/clients/amplify-studio-client.js.map +1 -1
  7. package/lib/commands/generateComponents.d.ts.map +1 -1
  8. package/lib/commands/generateComponents.js +33 -15
  9. package/lib/commands/generateComponents.js.map +1 -1
  10. package/lib/commands/help.d.ts +1 -1
  11. package/lib/commands/help.d.ts.map +1 -1
  12. package/lib/commands/help.js +2 -2
  13. package/lib/commands/help.js.map +1 -1
  14. package/lib/commands/utils/codegenResources.d.ts +12 -2
  15. package/lib/commands/utils/codegenResources.d.ts.map +1 -1
  16. package/lib/commands/utils/codegenResources.js +70 -3
  17. package/lib/commands/utils/codegenResources.js.map +1 -1
  18. package/lib/commands/utils/featureFlags.d.ts +2 -0
  19. package/lib/commands/utils/featureFlags.d.ts.map +1 -0
  20. package/lib/commands/utils/featureFlags.js +35 -0
  21. package/lib/commands/utils/featureFlags.js.map +1 -0
  22. package/lib/commands/utils/getUiBuilderComponentsPath.d.ts.map +1 -1
  23. package/lib/commands/utils/getUiBuilderComponentsPath.js.map +1 -1
  24. package/lib/commands/utils/shouldRenderComponents.d.ts +1 -1
  25. package/lib/commands/utils/shouldRenderComponents.d.ts.map +1 -1
  26. package/lib/commands/utils/shouldRenderComponents.js +14 -8
  27. package/lib/commands/utils/shouldRenderComponents.js.map +1 -1
  28. package/lib/commands/utils/syncAmplifyUiBuilderComponents.d.ts +12 -20
  29. package/lib/commands/utils/syncAmplifyUiBuilderComponents.d.ts.map +1 -1
  30. package/lib/commands/utils/syncAmplifyUiBuilderComponents.js +36 -3
  31. package/lib/commands/utils/syncAmplifyUiBuilderComponents.js.map +1 -1
  32. package/lib/commands/version.d.ts +1 -1
  33. package/lib/commands/version.d.ts.map +1 -1
  34. package/lib/commands/version.js +2 -2
  35. package/lib/commands/version.js.map +1 -1
  36. package/lib/event-handlers/handle-PostEnvAdd.d.ts +1 -1
  37. package/lib/event-handlers/handle-PostEnvAdd.d.ts.map +1 -1
  38. package/lib/event-handlers/handle-PostEnvAdd.js +4 -6
  39. package/lib/event-handlers/handle-PostEnvAdd.js.map +1 -1
  40. package/lib/event-handlers/handle-PostPull.d.ts +1 -1
  41. package/lib/event-handlers/handle-PostPull.d.ts.map +1 -1
  42. package/lib/event-handlers/handle-PostPull.js +4 -3
  43. package/lib/event-handlers/handle-PostPull.js.map +1 -1
  44. package/lib/event-handlers/handle-PostPush.d.ts +3 -0
  45. package/lib/event-handlers/handle-PostPush.d.ts.map +1 -0
  46. package/lib/event-handlers/handle-PostPush.js +15 -0
  47. package/lib/event-handlers/handle-PostPush.js.map +1 -0
  48. package/package.json +7 -6
  49. package/src/__tests__/cloneComponentsFromEnv.test.ts +17 -6
  50. package/src/__tests__/createUiBuilderComponent.test.ts +21 -3
  51. package/src/__tests__/generateComponents.test.ts +43 -15
  52. package/src/__tests__/getAmplifyDataSchema.test.ts +51 -19
  53. package/src/__tests__/shouldRenderComponents.test.ts +51 -4
  54. package/src/__tests__/syncAmplifyUiComponents.test.ts +113 -8
  55. package/src/__tests__/utils.ts +70 -0
  56. package/src/clients/amplify-studio-client.ts +157 -69
  57. package/src/commands/generateComponents.ts +43 -16
  58. package/src/commands/help.ts +5 -2
  59. package/src/commands/utils/codegenResources.ts +108 -4
  60. package/src/commands/utils/featureFlags.ts +62 -0
  61. package/src/commands/utils/getUiBuilderComponentsPath.ts +7 -2
  62. package/src/commands/utils/shouldRenderComponents.ts +20 -8
  63. package/src/commands/utils/syncAmplifyUiBuilderComponents.ts +76 -29
  64. package/src/commands/version.ts +5 -2
  65. package/src/event-handlers/handle-PostEnvAdd.ts +8 -6
  66. package/src/event-handlers/handle-PostPull.ts +7 -3
  67. package/src/event-handlers/handle-PostPush.ts +15 -0
  68. package/tsconfig.tsbuildinfo +1 -1
  69. 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 { createUiBuilderComponent, createUiBuilderTheme } from './codegenResources';
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
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
13
- export const generateUiBuilderComponents = (context: $TSContext, componentSchemas: any[], dataSchema?: GenericDataSchema): ({
14
- resultType: string;
15
- component: StudioComponent;
16
- schemaName?: undefined;
17
- error?: undefined;
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
- resultType: string;
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
+ };
@@ -1,6 +1,9 @@
1
1
  import { printer } from 'amplify-prompts';
2
2
  import path from 'path';
3
3
 
4
- export async function run() {
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
- export async function run(context: $TSContext) {
5
+ /**
6
+ *
7
+ * runs after adding an environment
8
+ */
9
+ export const run = async (context: $TSContext): Promise<void> => {
5
10
  try {
6
- await context.amplify.invokePluginMethod(context, 'ui-builder', undefined, 'executeAmplifyCommand', [
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
- export async function run(context: $TSContext) {
5
+ /**
6
+ * The code to run after a pull.
7
+ */
8
+ export const run = async (context: $TSContext): Promise<void> => {
5
9
  try {
6
- await context.amplify.invokePluginMethod(context, 'ui-builder', undefined, 'executeAmplifyCommand', [context, 'generateComponents']);
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
+ };