@aws-amplify/amplify-util-uibuilder 1.6.8 → 1.6.9-mxp.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 +12 -0
- package/amplify-plugin.json +2 -11
- package/lib/clients/amplify-studio-client.d.ts +8 -8
- package/lib/clients/amplify-studio-client.d.ts.map +1 -1
- package/lib/clients/amplify-studio-client.js +19 -21
- package/lib/clients/amplify-studio-client.js.map +1 -1
- package/lib/commands/cloneComponentsFromEnv.d.ts.map +1 -1
- package/lib/commands/cloneComponentsFromEnv.js +2 -1
- package/lib/commands/cloneComponentsFromEnv.js.map +1 -1
- package/lib/commands/generateComponents.js +10 -10
- package/lib/commands/generateComponents.js.map +1 -1
- package/lib/commands/utils/codegenResources.d.ts +4 -4
- package/lib/commands/utils/codegenResources.d.ts.map +1 -1
- package/lib/commands/utils/codegenResources.js +2 -2
- package/lib/commands/utils/codegenResources.js.map +1 -1
- package/lib/commands/utils/detachedFormCleanup.d.ts.map +1 -1
- package/lib/commands/utils/detachedFormCleanup.js +1 -2
- package/lib/commands/utils/detachedFormCleanup.js.map +1 -1
- package/lib/commands/utils/environmentHelpers.d.ts +2 -2
- package/lib/commands/utils/environmentHelpers.d.ts.map +1 -1
- package/lib/commands/utils/featureFlags.d.ts.map +1 -1
- package/lib/commands/utils/featureFlags.js.map +1 -1
- package/lib/commands/utils/index.js +5 -1
- package/lib/commands/utils/index.js.map +1 -1
- package/lib/commands/utils/notifyMissingPackages.d.ts.map +1 -1
- package/lib/commands/utils/notifyMissingPackages.js.map +1 -1
- package/lib/commands/utils/syncAmplifyUiBuilderComponents.d.ts +3 -3
- package/lib/commands/utils/syncAmplifyUiBuilderComponents.d.ts.map +1 -1
- package/lib/commands/utils/syncAmplifyUiBuilderComponents.js +9 -6
- package/lib/commands/utils/syncAmplifyUiBuilderComponents.js.map +1 -1
- package/lib/commands/version.js +7 -2
- package/lib/commands/version.js.map +1 -1
- package/lib/utils/prePushHandler.d.ts.map +1 -1
- package/lib/utils/prePushHandler.js +2 -5
- package/lib/utils/prePushHandler.js.map +1 -1
- package/package.json +6 -6
- package/src/__tests__/createUiBuilderComponent.test.ts +4 -2
- package/src/__tests__/detachedFormCleanup.test.ts +3 -6
- package/src/__tests__/generateComponents.test.ts +1 -1
- package/src/__tests__/getAmplifyDataSchema.test.ts +2 -1
- package/src/__tests__/notifyMissingPackages.test.ts +5 -4
- package/src/__tests__/package.json +2 -2
- package/src/__tests__/prePushHandler.test.ts +7 -7
- package/src/__tests__/shouldRenderComponents.test.ts +8 -8
- package/src/__tests__/syncAmplifyUiComponents.test.ts +54 -53
- package/src/__tests__/utils.ts +2 -3
- package/src/clients/amplify-studio-client.ts +4 -8
- package/src/commands/cloneComponentsFromEnv.ts +4 -6
- package/src/commands/generateComponents.ts +12 -12
- package/src/commands/utils/codegenResources.ts +14 -15
- package/src/commands/utils/detachedFormCleanup.ts +6 -6
- package/src/commands/utils/featureFlags.ts +3 -4
- package/src/commands/utils/notifyMissingPackages.ts +1 -3
- package/src/commands/utils/syncAmplifyUiBuilderComponents.ts +12 -18
- package/src/event-handlers/handle-PrePush.ts +1 -1
- package/src/utils/prePushHandler.ts +20 -16
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -26,9 +26,7 @@ import {
|
|
|
26
26
|
ReactThemeStudioTemplateRendererOptions,
|
|
27
27
|
} from '@aws-amplify/codegen-ui-react';
|
|
28
28
|
import { printer } from 'amplify-prompts';
|
|
29
|
-
import {
|
|
30
|
-
$TSContext, AmplifyCategories, AmplifySupportedService, stateManager,
|
|
31
|
-
} from 'amplify-cli-core';
|
|
29
|
+
import { $TSContext, AmplifyCategories, AmplifySupportedService, stateManager } from 'amplify-cli-core';
|
|
32
30
|
import { getUiBuilderComponentsPath } from './getUiBuilderComponentsPath';
|
|
33
31
|
import { AmplifyStudioClient } from '../../clients';
|
|
34
32
|
|
|
@@ -68,7 +66,8 @@ export const createUiBuilderTheme = (
|
|
|
68
66
|
): StudioTheme => {
|
|
69
67
|
const uiBuilderComponentsPath = getUiBuilderComponentsPath(context);
|
|
70
68
|
const rendererFactory = new StudioTemplateRendererFactory(
|
|
71
|
-
(component: StudioTheme) =>
|
|
69
|
+
(component: StudioTheme) =>
|
|
70
|
+
new ReactThemeStudioTemplateRenderer(component, config, options) as unknown as StudioTemplateRenderer<
|
|
72
71
|
unknown,
|
|
73
72
|
StudioTheme,
|
|
74
73
|
FrameworkOutputManager<unknown>,
|
|
@@ -99,7 +98,8 @@ export const createUiBuilderTheme = (
|
|
|
99
98
|
export const createUiBuilderForm = (context: $TSContext, schema: StudioForm, dataSchema?: GenericDataSchema): StudioForm => {
|
|
100
99
|
const uiBuilderComponentsPath = getUiBuilderComponentsPath(context);
|
|
101
100
|
const rendererFactory = new StudioTemplateRendererFactory(
|
|
102
|
-
(form: StudioForm) =>
|
|
101
|
+
(form: StudioForm) =>
|
|
102
|
+
new AmplifyFormRenderer(form, dataSchema, config) as unknown as StudioTemplateRenderer<
|
|
103
103
|
unknown,
|
|
104
104
|
StudioForm,
|
|
105
105
|
FrameworkOutputManager<unknown>,
|
|
@@ -130,7 +130,8 @@ export const createUiBuilderForm = (context: $TSContext, schema: StudioForm, dat
|
|
|
130
130
|
export const generateAmplifyUiBuilderIndexFile = (context: $TSContext, schemas: StudioSchema[]): void => {
|
|
131
131
|
const uiBuilderComponentsPath = getUiBuilderComponentsPath(context);
|
|
132
132
|
const rendererFactory = new StudioTemplateRendererFactory(
|
|
133
|
-
(schema: StudioSchema[]) =>
|
|
133
|
+
(schema: StudioSchema[]) =>
|
|
134
|
+
new ReactIndexStudioTemplateRenderer(schema, config) as unknown as StudioTemplateRenderer<
|
|
134
135
|
unknown,
|
|
135
136
|
StudioSchema[],
|
|
136
137
|
FrameworkOutputManager<unknown>,
|
|
@@ -145,7 +146,7 @@ export const generateAmplifyUiBuilderIndexFile = (context: $TSContext, schemas:
|
|
|
145
146
|
});
|
|
146
147
|
|
|
147
148
|
try {
|
|
148
|
-
if(schemas.length) {
|
|
149
|
+
if (schemas.length) {
|
|
149
150
|
rendererManager.renderSchemaToTemplate(schemas);
|
|
150
151
|
}
|
|
151
152
|
} catch (e) {
|
|
@@ -166,7 +167,7 @@ type UtilFileChecks = {
|
|
|
166
167
|
export const generateAmplifyUiBuilderUtilFile = (context: $TSContext, { hasForms, hasViews }: UtilFileChecks): void => {
|
|
167
168
|
const uiBuilderComponentsPath = getUiBuilderComponentsPath(context);
|
|
168
169
|
const rendererFactory = new StudioTemplateRendererFactory(
|
|
169
|
-
(utils: UtilTemplateType[]) =>
|
|
170
|
+
(utils: UtilTemplateType[]) => new ReactUtilsStudioTemplateRenderer(utils, config),
|
|
170
171
|
);
|
|
171
172
|
|
|
172
173
|
const outputPathDir = uiBuilderComponentsPath;
|
|
@@ -202,9 +203,7 @@ export const generateAmplifyUiBuilderUtilFile = (context: $TSContext, { hasForms
|
|
|
202
203
|
* If models are available, they will be populated in the models field of the returned object.
|
|
203
204
|
* If they're not available, it will return undefined
|
|
204
205
|
*/
|
|
205
|
-
export const getAmplifyDataSchema = async (
|
|
206
|
-
studioClient: AmplifyStudioClient,
|
|
207
|
-
): Promise<GenericDataSchema | undefined> => {
|
|
206
|
+
export const getAmplifyDataSchema = async (studioClient: AmplifyStudioClient): Promise<GenericDataSchema | undefined> => {
|
|
208
207
|
if (!studioClient.isGraphQLSupported) {
|
|
209
208
|
return undefined;
|
|
210
209
|
}
|
|
@@ -231,8 +230,8 @@ export const getAmplifyDataSchema = async (
|
|
|
231
230
|
/**
|
|
232
231
|
* generates base create/update froms from names
|
|
233
232
|
*/
|
|
234
|
-
export const generateBaseForms = (modelMap: {[model: string]: Set<'create' | 'update'>}): StudioForm[] => {
|
|
235
|
-
const getSchema = (name: string, type: 'create' | 'update')
|
|
233
|
+
export const generateBaseForms = (modelMap: { [model: string]: Set<'create' | 'update'> }): StudioForm[] => {
|
|
234
|
+
const getSchema = (name: string, type: 'create' | 'update'): StudioForm => ({
|
|
236
235
|
name: `${name}${type === 'create' ? 'CreateForm' : 'UpdateForm'}`,
|
|
237
236
|
formActionType: type,
|
|
238
237
|
dataType: { dataSourceType: 'DataStore', dataTypeName: name },
|
|
@@ -242,10 +241,10 @@ export const generateBaseForms = (modelMap: {[model: string]: Set<'create' | 'up
|
|
|
242
241
|
cta: {},
|
|
243
242
|
});
|
|
244
243
|
|
|
245
|
-
const schemas
|
|
244
|
+
const schemas: StudioForm[] = [];
|
|
246
245
|
|
|
247
246
|
Object.entries(modelMap).forEach(([name, set]) => {
|
|
248
|
-
set.forEach(type => schemas.push(getSchema(name, type)));
|
|
247
|
+
set.forEach((type) => schemas.push(getSchema(name, type)));
|
|
249
248
|
});
|
|
250
249
|
return schemas;
|
|
251
250
|
};
|
|
@@ -25,7 +25,7 @@ export const isFormSchemaCustomized = (formSchema: StudioForm | Form): boolean =
|
|
|
25
25
|
|
|
26
26
|
// Check style
|
|
27
27
|
// If not empty, at least one style must be defined
|
|
28
|
-
return Object.values(style).some(styleConfig => styleConfig !== undefined);
|
|
28
|
+
return Object.values(style).some((styleConfig) => styleConfig !== undefined);
|
|
29
29
|
};
|
|
30
30
|
|
|
31
31
|
/**
|
|
@@ -36,19 +36,19 @@ export const isStudioForm = (schema: StudioSchema | undefined): schema is Studio
|
|
|
36
36
|
return 'formActionType' in schema;
|
|
37
37
|
};
|
|
38
38
|
|
|
39
|
-
export const deleteDetachedForms = async (detachedForms: {id: string
|
|
40
|
-
const deleteForm = async ({id, name}: {id: string
|
|
39
|
+
export const deleteDetachedForms = async (detachedForms: { id: string; name: string }[], studioClient: AmplifyStudioClient) => {
|
|
40
|
+
const deleteForm = async ({ id, name }: { id: string; name: string }) => {
|
|
41
41
|
try {
|
|
42
42
|
// Try to delete the form but don't stop any other operations if it fails
|
|
43
43
|
await studioClient.deleteForm(id);
|
|
44
|
-
return {status: 'SUCCESS', message: `Deleted detached form ${name}`};
|
|
44
|
+
return { status: 'SUCCESS', message: `Deleted detached form ${name}` };
|
|
45
45
|
} catch (error) {
|
|
46
|
-
return {status: 'FAIL', message: `Failed to delete detached form ${name}`}
|
|
46
|
+
return { status: 'FAIL', message: `Failed to delete detached form ${name}` };
|
|
47
47
|
}
|
|
48
48
|
};
|
|
49
49
|
for await (const status of asyncPool(5, detachedForms, deleteForm)) {
|
|
50
50
|
printer.debug(status.message);
|
|
51
|
-
}
|
|
51
|
+
}
|
|
52
52
|
};
|
|
53
53
|
|
|
54
54
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
/* eslint-disable spellcheck/spell-checker */
|
|
2
|
-
import {
|
|
3
|
-
FeatureFlags, pathManager, stateManager,
|
|
4
|
-
} from 'amplify-cli-core';
|
|
2
|
+
import { FeatureFlags, pathManager, stateManager } from 'amplify-cli-core';
|
|
5
3
|
import { printer } from 'amplify-prompts';
|
|
6
4
|
|
|
7
5
|
// This is copy-pasta from the category api until they can expose the method to plugins
|
|
@@ -9,7 +7,8 @@ import { printer } from 'amplify-prompts';
|
|
|
9
7
|
/**
|
|
10
8
|
* Shorthand for Feature flag retrieval.
|
|
11
9
|
*/
|
|
12
|
-
const useExperimentalPipelinedTransformerFF = (): boolean =>
|
|
10
|
+
const useExperimentalPipelinedTransformerFF = (): boolean =>
|
|
11
|
+
FeatureFlags.getBoolean('graphQLTransformer.useExperimentalPipelinedTransformer');
|
|
13
12
|
const transformerVersionFF = (): number => FeatureFlags.getNumber('graphQLTransformer.transformerVersion');
|
|
14
13
|
|
|
15
14
|
/**
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
pathManager, JSONUtilities, $TSContext, $TSAny,
|
|
3
|
-
} from 'amplify-cli-core';
|
|
1
|
+
import { pathManager, JSONUtilities, $TSContext, $TSAny } from 'amplify-cli-core';
|
|
4
2
|
import { printer } from 'amplify-prompts';
|
|
5
3
|
import fs from 'fs-extra';
|
|
6
4
|
import path from 'path';
|
|
@@ -1,14 +1,7 @@
|
|
|
1
1
|
import { printer } from 'amplify-prompts';
|
|
2
2
|
import { $TSContext } from 'amplify-cli-core';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
} from '@aws-amplify/codegen-ui';
|
|
6
|
-
import {
|
|
7
|
-
createUiBuilderComponent,
|
|
8
|
-
createUiBuilderForm,
|
|
9
|
-
createUiBuilderTheme,
|
|
10
|
-
generateBaseForms,
|
|
11
|
-
} from './codegenResources';
|
|
3
|
+
import { StudioComponent, StudioTheme, GenericDataSchema, StudioForm, StudioSchema, checkIsSupportedAsForm } from '@aws-amplify/codegen-ui';
|
|
4
|
+
import { createUiBuilderComponent, createUiBuilderForm, createUiBuilderTheme, generateBaseForms } from './codegenResources';
|
|
12
5
|
import { getUiBuilderComponentsPath } from './getUiBuilderComponentsPath';
|
|
13
6
|
|
|
14
7
|
type CodegenResponse<T extends StudioSchema> =
|
|
@@ -34,7 +27,7 @@ export const generateUiBuilderComponents = (
|
|
|
34
27
|
componentSchemas: any[], // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
35
28
|
dataSchema?: GenericDataSchema,
|
|
36
29
|
): CodegenResponse<StudioComponent>[] => {
|
|
37
|
-
const componentResults = componentSchemas.map<CodegenResponse<StudioComponent>>(schema => {
|
|
30
|
+
const componentResults = componentSchemas.map<CodegenResponse<StudioComponent>>((schema) => {
|
|
38
31
|
try {
|
|
39
32
|
const component = createUiBuilderComponent(context, schema, dataSchema);
|
|
40
33
|
return { resultType: 'SUCCESS', schema: component };
|
|
@@ -46,7 +39,7 @@ export const generateUiBuilderComponents = (
|
|
|
46
39
|
});
|
|
47
40
|
|
|
48
41
|
printer.debug(
|
|
49
|
-
`Generated ${componentResults.filter(result => result.resultType === 'SUCCESS').length} components in ${getUiBuilderComponentsPath(
|
|
42
|
+
`Generated ${componentResults.filter((result) => result.resultType === 'SUCCESS').length} components in ${getUiBuilderComponentsPath(
|
|
50
43
|
context,
|
|
51
44
|
)}`,
|
|
52
45
|
);
|
|
@@ -61,7 +54,7 @@ export const generateUiBuilderThemes = (context: $TSContext, themeSchemas: any[]
|
|
|
61
54
|
if (themeSchemas.length === 0) {
|
|
62
55
|
return [generateDefaultTheme(context)];
|
|
63
56
|
}
|
|
64
|
-
const themeResults = themeSchemas.map<CodegenResponse<StudioTheme>>(schema => {
|
|
57
|
+
const themeResults = themeSchemas.map<CodegenResponse<StudioTheme>>((schema) => {
|
|
65
58
|
try {
|
|
66
59
|
const theme = createUiBuilderTheme(context, schema);
|
|
67
60
|
return { resultType: 'SUCCESS', schema: theme };
|
|
@@ -73,7 +66,7 @@ export const generateUiBuilderThemes = (context: $TSContext, themeSchemas: any[]
|
|
|
73
66
|
});
|
|
74
67
|
|
|
75
68
|
printer.debug(
|
|
76
|
-
`Generated ${themeResults.filter(result => result.resultType === 'SUCCESS').length} themes in ${getUiBuilderComponentsPath(context)}`,
|
|
69
|
+
`Generated ${themeResults.filter((result) => result.resultType === 'SUCCESS').length} themes in ${getUiBuilderComponentsPath(context)}`,
|
|
77
70
|
);
|
|
78
71
|
return themeResults;
|
|
79
72
|
};
|
|
@@ -84,9 +77,7 @@ export const generateUiBuilderThemes = (context: $TSContext, themeSchemas: any[]
|
|
|
84
77
|
const generateDefaultTheme = (context: $TSContext): CodegenResponse<StudioTheme> => {
|
|
85
78
|
try {
|
|
86
79
|
const theme = createUiBuilderTheme(context, { name: 'studioTheme', values: [] }, { renderDefaultTheme: true });
|
|
87
|
-
printer.debug(
|
|
88
|
-
`Generated default theme in ${getUiBuilderComponentsPath(context)}`,
|
|
89
|
-
);
|
|
80
|
+
printer.debug(`Generated default theme in ${getUiBuilderComponentsPath(context)}`);
|
|
90
81
|
return { resultType: 'SUCCESS', schema: theme };
|
|
91
82
|
} catch (e) {
|
|
92
83
|
printer.debug(`Failure caught rendering default theme`);
|
|
@@ -121,7 +112,10 @@ export const generateUiBuilderForms = (
|
|
|
121
112
|
printer.debug(`Failure caught processing ${schema.name}`);
|
|
122
113
|
printer.debug(e);
|
|
123
114
|
return {
|
|
124
|
-
resultType: 'FAILURE',
|
|
115
|
+
resultType: 'FAILURE',
|
|
116
|
+
schemaName: schema.name,
|
|
117
|
+
schema,
|
|
118
|
+
error: e,
|
|
125
119
|
};
|
|
126
120
|
}
|
|
127
121
|
};
|
|
@@ -136,7 +130,7 @@ export const generateUiBuilderForms = (
|
|
|
136
130
|
formResults.push(...generateBaseForms(modelMap).map(codegenForm));
|
|
137
131
|
|
|
138
132
|
printer.debug(
|
|
139
|
-
`Generated ${formResults.filter(result => result.resultType === 'SUCCESS').length} forms in ${getUiBuilderComponentsPath(context)}`,
|
|
133
|
+
`Generated ${formResults.filter((result) => result.resultType === 'SUCCESS').length} forms in ${getUiBuilderComponentsPath(context)}`,
|
|
140
134
|
);
|
|
141
135
|
return formResults;
|
|
142
136
|
};
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { $TSContext } from 'amplify-cli-core';
|
|
2
|
-
import type { Schema } from '@aws-amplify/datastore';
|
|
3
2
|
import { printer } from 'amplify-prompts';
|
|
4
3
|
import AmplifyUIBuilder from 'aws-sdk/clients/amplifyuibuilder';
|
|
5
4
|
import { AmplifyStudioClient } from '../clients';
|
|
6
5
|
import { isFormDetachedFromModel, isFormSchemaCustomized, shouldRenderComponents } from '../commands/utils';
|
|
7
6
|
|
|
7
|
+
// TODO: replace this type when amplify-codegen package export official types
|
|
8
|
+
type Schema = {
|
|
9
|
+
models: Record<string, unknown>;
|
|
10
|
+
};
|
|
11
|
+
|
|
8
12
|
/**
|
|
9
13
|
* Handles showing a warning for detached forms pre-push.
|
|
10
14
|
*/
|
|
@@ -13,18 +17,14 @@ export const prePushHandler = async (context: $TSContext): Promise<void> => {
|
|
|
13
17
|
return;
|
|
14
18
|
}
|
|
15
19
|
const studioClient = await AmplifyStudioClient.setClientInfo(context);
|
|
16
|
-
const [formSchemas, localSchema] = await Promise.all<
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
'getModelIntrospection',
|
|
25
|
-
[context],
|
|
26
|
-
),
|
|
27
|
-
]);
|
|
20
|
+
const [formSchemas, localSchema] = await Promise.all<
|
|
21
|
+
[
|
|
22
|
+
Promise<{
|
|
23
|
+
entities: AmplifyUIBuilder.Form[];
|
|
24
|
+
}>,
|
|
25
|
+
Promise<Schema>,
|
|
26
|
+
]
|
|
27
|
+
>([studioClient.listForms(), context.amplify.invokePluginMethod(context, 'codegen', undefined, 'getModelIntrospection', [context])]);
|
|
28
28
|
|
|
29
29
|
if (!localSchema) {
|
|
30
30
|
printer.debug('Local schema not found');
|
|
@@ -37,7 +37,7 @@ const printDetachedFormsWarning = (formSchemas: { entities: AmplifyUIBuilder.For
|
|
|
37
37
|
const modelNames = new Set(Object.keys(localSchema.models));
|
|
38
38
|
const detachedCustomForms: string[] = [];
|
|
39
39
|
|
|
40
|
-
formSchemas.entities.forEach(form => {
|
|
40
|
+
formSchemas.entities.forEach((form) => {
|
|
41
41
|
// Only show warnings for schema's that have customization, otherwise it's the same as
|
|
42
42
|
// an autogenerated form.
|
|
43
43
|
if (isFormDetachedFromModel(form, modelNames) && isFormSchemaCustomized(form)) {
|
|
@@ -46,6 +46,10 @@ const printDetachedFormsWarning = (formSchemas: { entities: AmplifyUIBuilder.For
|
|
|
46
46
|
});
|
|
47
47
|
|
|
48
48
|
if (detachedCustomForms.length > 0) {
|
|
49
|
-
printer.warn(
|
|
49
|
+
printer.warn(
|
|
50
|
+
`The following form${
|
|
51
|
+
detachedCustomForms.length === 1 ? '' : 's'
|
|
52
|
+
} will no longer be available because the connected data model no longer exists: ${detachedCustomForms.join(', ')}`,
|
|
53
|
+
);
|
|
50
54
|
}
|
|
51
|
-
};
|
|
55
|
+
};
|