@aws-amplify/amplify-util-uibuilder 1.6.5 → 1.6.6-rc.4b3db16df.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 (57) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/amplify-plugin.json +3 -1
  3. package/lib/clients/amplify-studio-client.d.ts +1 -0
  4. package/lib/clients/amplify-studio-client.d.ts.map +1 -1
  5. package/lib/clients/amplify-studio-client.js +13 -0
  6. package/lib/clients/amplify-studio-client.js.map +1 -1
  7. package/lib/commands/cloneComponentsFromEnv.js +2 -2
  8. package/lib/commands/cloneComponentsFromEnv.js.map +1 -1
  9. package/lib/commands/generateComponents.d.ts +1 -1
  10. package/lib/commands/generateComponents.d.ts.map +1 -1
  11. package/lib/commands/generateComponents.js +15 -3
  12. package/lib/commands/generateComponents.js.map +1 -1
  13. package/lib/commands/utils/detachedFormCleanup.d.ts +11 -0
  14. package/lib/commands/utils/detachedFormCleanup.d.ts.map +1 -0
  15. package/lib/commands/utils/detachedFormCleanup.js +44 -0
  16. package/lib/commands/utils/detachedFormCleanup.js.map +1 -0
  17. package/lib/commands/utils/index.d.ts +1 -0
  18. package/lib/commands/utils/index.d.ts.map +1 -1
  19. package/lib/commands/utils/index.js +1 -0
  20. package/lib/commands/utils/index.js.map +1 -1
  21. package/lib/commands/utils/shouldRenderComponents.d.ts.map +1 -1
  22. package/lib/commands/utils/shouldRenderComponents.js +7 -5
  23. package/lib/commands/utils/shouldRenderComponents.js.map +1 -1
  24. package/lib/commands/utils/syncAmplifyUiBuilderComponents.d.ts.map +1 -1
  25. package/lib/commands/utils/syncAmplifyUiBuilderComponents.js +3 -1
  26. package/lib/commands/utils/syncAmplifyUiBuilderComponents.js.map +1 -1
  27. package/lib/event-handlers/handle-PostPull.js +1 -1
  28. package/lib/event-handlers/handle-PostPull.js.map +1 -1
  29. package/lib/event-handlers/handle-PostPush.js +1 -1
  30. package/lib/event-handlers/handle-PostPush.js.map +1 -1
  31. package/lib/event-handlers/handle-PrePush.d.ts +3 -0
  32. package/lib/event-handlers/handle-PrePush.d.ts.map +1 -0
  33. package/lib/event-handlers/handle-PrePush.js +15 -0
  34. package/lib/event-handlers/handle-PrePush.js.map +1 -0
  35. package/lib/utils/prePushHandler.d.ts +3 -0
  36. package/lib/utils/prePushHandler.d.ts.map +1 -0
  37. package/lib/utils/prePushHandler.js +35 -0
  38. package/lib/utils/prePushHandler.js.map +1 -0
  39. package/package.json +8 -6
  40. package/src/__tests__/detachedFormCleanup.test.ts +78 -0
  41. package/src/__tests__/generateComponents.test.ts +13 -11
  42. package/src/__tests__/handleEvents.test.ts +27 -0
  43. package/src/__tests__/prePushHandler.test.ts +105 -0
  44. package/src/__tests__/shouldRenderComponents.test.ts +48 -35
  45. package/src/__tests__/syncAmplifyUiComponents.test.ts +3 -3
  46. package/src/clients/amplify-studio-client.ts +13 -0
  47. package/src/commands/cloneComponentsFromEnv.ts +1 -1
  48. package/src/commands/generateComponents.ts +30 -4
  49. package/src/commands/utils/detachedFormCleanup.ts +55 -0
  50. package/src/commands/utils/index.ts +1 -0
  51. package/src/commands/utils/shouldRenderComponents.ts +7 -5
  52. package/src/commands/utils/syncAmplifyUiBuilderComponents.ts +3 -1
  53. package/src/event-handlers/handle-PostPull.ts +1 -1
  54. package/src/event-handlers/handle-PostPush.ts +1 -1
  55. package/src/event-handlers/handle-PrePush.ts +15 -0
  56. package/src/utils/prePushHandler.ts +51 -0
  57. package/tsconfig.tsbuildinfo +1 -1
@@ -0,0 +1,15 @@
1
+ import { $TSContext } from 'amplify-cli-core';
2
+ import { printer } from 'amplify-prompts';
3
+ import { prePushHandler } from '../utils/prePushHandler';
4
+
5
+ /**
6
+ * The code to run before a push.
7
+ */
8
+ export const run = async (context: $TSContext): Promise<void> => {
9
+ try {
10
+ await prePushHandler(context);
11
+ } catch (e) {
12
+ // Swallow all errors from the uibuilder plugin
13
+ printer.debug(e);
14
+ }
15
+ };
@@ -0,0 +1,51 @@
1
+ import { $TSContext } from 'amplify-cli-core';
2
+ import type { Schema } from '@aws-amplify/datastore';
3
+ import { printer } from 'amplify-prompts';
4
+ import AmplifyUIBuilder from 'aws-sdk/clients/amplifyuibuilder';
5
+ import { AmplifyStudioClient } from '../clients';
6
+ import { isFormDetachedFromModel, isFormSchemaCustomized, shouldRenderComponents } from '../commands/utils';
7
+
8
+ /**
9
+ * Handles showing a warning for detached forms pre-push.
10
+ */
11
+ export const prePushHandler = async (context: $TSContext): Promise<void> => {
12
+ if (!(await shouldRenderComponents(context))) {
13
+ return;
14
+ }
15
+ const studioClient = await AmplifyStudioClient.setClientInfo(context);
16
+ const [formSchemas, localSchema] = await Promise.all<[Promise<{
17
+ entities: AmplifyUIBuilder.Form[];
18
+ }>, Promise<Schema>]>([
19
+ studioClient.listForms(),
20
+ context.amplify.invokePluginMethod(
21
+ context,
22
+ 'codegen',
23
+ undefined,
24
+ 'getModelIntrospection',
25
+ [context],
26
+ ),
27
+ ]);
28
+
29
+ if (!localSchema) {
30
+ printer.debug('Local schema not found');
31
+ return;
32
+ }
33
+ printDetachedFormsWarning(formSchemas, localSchema);
34
+ };
35
+
36
+ const printDetachedFormsWarning = (formSchemas: { entities: AmplifyUIBuilder.Form[] }, localSchema: Schema): void => {
37
+ const modelNames = new Set(Object.keys(localSchema.models));
38
+ const detachedCustomForms: string[] = [];
39
+
40
+ formSchemas.entities.forEach(form => {
41
+ // Only show warnings for schema's that have customization, otherwise it's the same as
42
+ // an autogenerated form.
43
+ if (isFormDetachedFromModel(form, modelNames) && isFormSchemaCustomized(form)) {
44
+ detachedCustomForms.push(form.name);
45
+ }
46
+ });
47
+
48
+ if (detachedCustomForms.length > 0) {
49
+ printer.warn(`The following form${detachedCustomForms.length === 1 ? '' : 's'} will no longer be available because the connected data model no longer exists: ${detachedCustomForms.join(', ')}`);
50
+ }
51
+ };