From 54f5c71156e34281678c3456effe0cc0a805617d Mon Sep 17 00:00:00 2001 From: Justin Shih Date: Thu, 28 Jul 2022 17:12:13 -0700 Subject: [PATCH] chore: tidying forms renderer --- ...studio-ui-codegen-react-forms.test.ts.snap | 76 ++-- .../form-renderer-helper.test.ts.snap | 2 - .../react-forms/form-renderer-helper.test.ts | 20 +- .../studio-ui-codegen-react-forms.test.ts | 6 +- .../lib/amplify-ui-renderers/form.ts | 36 +- .../lib/forms/form-renderer-helper.ts | 59 +-- .../lib/forms/react-form-renderer.ts | 29 +- .../form-to-component.test.ts | 1 + .../lib/types/form/form-metadata.ts | 2 +- packages/codegen-ui/lib/types/form/index.ts | 2 +- .../test-generator/lib/forms/form-create.json | 35 +- .../test-generator/lib/forms/form-update.json | 22 +- .../lib/generators/BrowserTestGenerator.ts | 11 +- .../lib/generators/NodeTestGenerator.ts | 5 +- packages/test-generator/lib/models/schema.ts | 364 ++++++++++++++++++ 15 files changed, 495 insertions(+), 175 deletions(-) create mode 100644 packages/test-generator/lib/models/schema.ts diff --git a/packages/codegen-ui-react/lib/__tests__/__snapshots__/studio-ui-codegen-react-forms.test.ts.snap b/packages/codegen-ui-react/lib/__tests__/__snapshots__/studio-ui-codegen-react-forms.test.ts.snap index 55d59ab8e..5e901375f 100644 --- a/packages/codegen-ui-react/lib/__tests__/__snapshots__/studio-ui-codegen-react-forms.test.ts.snap +++ b/packages/codegen-ui-react/lib/__tests__/__snapshots__/studio-ui-codegen-react-forms.test.ts.snap @@ -14,25 +14,23 @@ export default function customDataForm(props) { const { onSubmit: customDataFormOnSubmit, onCancel, + onValidate, overrides, ...rest } = props; const [nameFieldError, setNameFieldError] = useStateMutationAction({}); const [emailFieldError, setEmailFieldError] = useStateMutationAction({}); - const [customDataFormFields, setCustomDataFormFields] = - useStateMutationAction({}); + const [modelFields, setModelFields] = useStateMutationAction({}); const [formValid, setFormValid] = useStateMutationAction(true); return (
{ event.preventDefault(); if (onSubmitBefore) { - setCustomDataFormFields( - onSubmitBefore({ fields: customDataFormFields }) - ); + setModelFields(onSubmitBefore({ fields: modelFields })); } try { - await DataStore.save(new Post(customDataFormFields)); + await DataStore.save(new Post(modelFields)); if (onSubmitComplete) { onSubmitComplete({ saveSuccessful: true }); } @@ -155,32 +153,40 @@ import React from \\"react\\"; import { validateField } from \\"./utils.js\\"; import { getOverrideProps, - useDataStoreCreateAction, useStateMutationAction, } from \\"@aws-amplify/ui-react/internal\\"; import { Post } from \\"../models\\"; -import { schema } from \\"../models/schema\\"; import { Button, Flex, Grid, TextField } from \\"@aws-amplify/ui-react\\"; import { DataStore } from \\"aws-amplify\\"; export default function myPostForm(props) { - const { onSubmitBefore, onSubmitComplete, onCancel, overrides, ...rest } = - props; - const [myPostFormFields, setMyPostFormFields] = useStateMutationAction({}); + const { + onSubmitBefore, + onSubmitComplete, + onCancel, + onValidate, + overrides, + ...rest + } = props; + const [captionFieldError, setCaptionFieldError] = useStateMutationAction({}); + const [usernameFieldError, setUsernameFieldError] = useStateMutationAction( + {} + ); + const [post_urlFieldError, setPost_urlFieldError] = useStateMutationAction( + {} + ); + const [profile_urlFieldError, setProfile_urlFieldError] = + useStateMutationAction({}); + const [modelFields, setModelFields] = useStateMutationAction({}); const [formValid, setFormValid] = useStateMutationAction(true); - const myPostFormOnSubmit = useDataStoreCreateAction({ - model: Post, - fields: myPostFormFields, - schema: schema, - }); return ( { event.preventDefault(); if (onSubmitBefore) { - setMyPostFormFields(onSubmitBefore({ fields: myPostFormFields })); + setModelFields(onSubmitBefore({ fields: modelFields })); } try { - await DataStore.save(new Post(myPostFormFields)); + await DataStore.save(new Post(modelFields)); if (onSubmitComplete) { onSubmitComplete({ saveSuccessful: true }); } @@ -376,33 +382,41 @@ import React from \\"react\\"; import { validateField } from \\"./utils.js\\"; import { getOverrideProps, - useDataStoreUpdateAction, useStateMutationAction, } from \\"@aws-amplify/ui-react/internal\\"; import { Post } from \\"../models\\"; -import { schema } from \\"../models/schema\\"; import { Button, Flex, Grid, TextField } from \\"@aws-amplify/ui-react\\"; import { DataStore } from \\"aws-amplify\\"; export default function myPostForm(props) { - const { id, onSubmitBefore, onSubmitComplete, onCancel, overrides, ...rest } = - props; - const [myPostFormFields, setMyPostFormFields] = useStateMutationAction({}); + const { + id, + onSubmitBefore, + onSubmitComplete, + onCancel, + onValidate, + overrides, + ...rest + } = props; + const [captionFieldError, setCaptionFieldError] = useStateMutationAction({}); + const [usernameFieldError, setUsernameFieldError] = useStateMutationAction( + {} + ); + const [post_urlFieldError, setPost_urlFieldError] = useStateMutationAction( + {} + ); + const [profile_urlFieldError, setProfile_urlFieldError] = + useStateMutationAction({}); + const [modelFields, setModelFields] = useStateMutationAction({}); const [formValid, setFormValid] = useStateMutationAction(true); - const myPostFormOnSubmit = useDataStoreUpdateAction({ - model: Post, - fields: myPostFormFields, - id: id, - schema: schema, - }); return ( { event.preventDefault(); if (onSubmitBefore) { - setMyPostFormFields(onSubmitBefore({ fields: myPostFormFields })); + setModelFields(onSubmitBefore({ fields: modelFields })); } try { - await DataStore.save(new Post(myPostFormFields)); + await DataStore.save(new Post(modelFields)); if (onSubmitComplete) { onSubmitComplete({ saveSuccessful: true }); } diff --git a/packages/codegen-ui-react/lib/__tests__/react-forms/__snapshots__/form-renderer-helper.test.ts.snap b/packages/codegen-ui-react/lib/__tests__/react-forms/__snapshots__/form-renderer-helper.test.ts.snap index 2632d9563..86979cc15 100644 --- a/packages/codegen-ui-react/lib/__tests__/react-forms/__snapshots__/form-renderer-helper.test.ts.snap +++ b/packages/codegen-ui-react/lib/__tests__/react-forms/__snapshots__/form-renderer-helper.test.ts.snap @@ -1,7 +1,5 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`form-render utils should generate a datastore function 1`] = `"const mySampleFormOnSubmit = useDataStoreCreateAction({ model: Post, fields: mySampleFormFields, schema: schema });"`; - exports[`form-render utils should generate before & complete types if datastore config is set 1`] = ` "{ onSubmitBefore?: (fields: Record) => Record; diff --git a/packages/codegen-ui-react/lib/__tests__/react-forms/form-renderer-helper.test.ts b/packages/codegen-ui-react/lib/__tests__/react-forms/form-renderer-helper.test.ts index 055114649..07b71e280 100644 --- a/packages/codegen-ui-react/lib/__tests__/react-forms/form-renderer-helper.test.ts +++ b/packages/codegen-ui-react/lib/__tests__/react-forms/form-renderer-helper.test.ts @@ -15,8 +15,7 @@ */ import { StudioForm } from '@aws-amplify/codegen-ui'; import { EmitHint, Node } from 'typescript'; -import { ImportCollection } from '../../imports'; -import { buildFormPropNode, buildDataStoreActionStatement } from '../../forms'; +import { buildFormPropNode } from '../../forms'; import { buildPrinter, defaultRenderConfig } from '../../react-studio-template-renderer-helper'; describe('form-render utils', () => { @@ -29,23 +28,6 @@ describe('form-render utils', () => { }; }); - it('should generate a datastore function', () => { - const form: StudioForm = { - id: '123', - name: 'mySampleForm', - formActionType: 'create', - dataType: { dataSourceType: 'DataStore', dataTypeName: 'Post' }, - fields: {}, - sectionalElements: {}, - style: {}, - }; - const importCollection = new ImportCollection(); - const mutationStatement: any = buildDataStoreActionStatement(form, importCollection); - expect(mutationStatement).toBeDefined(); - const node = printNode(mutationStatement); - expect(node).toMatchSnapshot(); - }); - it('should generate before & complete types if datastore config is set', () => { const form: StudioForm = { id: '123', diff --git a/packages/codegen-ui-react/lib/__tests__/studio-ui-codegen-react-forms.test.ts b/packages/codegen-ui-react/lib/__tests__/studio-ui-codegen-react-forms.test.ts index d83ad50e1..01edf7488 100644 --- a/packages/codegen-ui-react/lib/__tests__/studio-ui-codegen-react-forms.test.ts +++ b/packages/codegen-ui-react/lib/__tests__/studio-ui-codegen-react-forms.test.ts @@ -51,7 +51,7 @@ describe('amplify form renderer tests', () => { 'forms/post-datastore-create', 'datastore/post', ); - expect(componentText).toContain('useDataStoreCreateAction'); + expect(componentText).toContain('DataStore.save'); expect(componentText).toMatchSnapshot(); expect(declaration).toMatchSnapshot(); }); @@ -61,7 +61,7 @@ describe('amplify form renderer tests', () => { 'forms/post-datastore-update', 'datastore/post', ); - expect(componentText).toContain('useDataStoreUpdateAction'); + expect(componentText).toContain('DataStore.save'); expect(componentText).toMatchSnapshot(); expect(declaration).toMatchSnapshot(); }); @@ -70,7 +70,7 @@ describe('amplify form renderer tests', () => { describe('custom form tests', () => { it('should render a custom backed form', () => { const { componentText, declaration } = generateWithAmplifyFormRenderer('forms/post-custom-create', undefined); - expect(componentText.replace(/\s/g, '')).toContain('setCustomDataFormFields(onSubmitBefore'); + expect(componentText.replace(/\s/g, '')).toContain('setModelFields(onSubmitBefore'); expect(componentText).toMatchSnapshot(); expect(declaration).toMatchSnapshot(); }); diff --git a/packages/codegen-ui-react/lib/amplify-ui-renderers/form.ts b/packages/codegen-ui-react/lib/amplify-ui-renderers/form.ts index f55b9b5a8..324aa2cec 100644 --- a/packages/codegen-ui-react/lib/amplify-ui-renderers/form.ts +++ b/packages/codegen-ui-react/lib/amplify-ui-renderers/form.ts @@ -23,9 +23,8 @@ import { } from '@aws-amplify/codegen-ui'; import { factory, JsxAttribute, JsxChild, JsxElement, JsxOpeningElement, SyntaxKind } from 'typescript'; import { ReactComponentRenderer } from '../react-component-renderer'; -import { buildOpeningElementProperties, getStateName, getSetStateName } from '../react-component-render-helper'; +import { buildOpeningElementProperties } from '../react-component-render-helper'; import { ImportCollection } from '../imports'; -import { FieldStateVariable } from '../forms/form-renderer-helper'; export default class FormRenderer extends ReactComponentRenderer { constructor( @@ -72,7 +71,6 @@ export default class FormRenderer extends ReactComponentRenderer = { create: 'Amplify.DataStoreCreateItemAction', @@ -77,59 +77,6 @@ export const buildFieldStateStatements = (formName: string, importCollection: Im ), ); }; -/** - * - * @param form StudioForm - * @param importCollection ImportCollection - * @returns ActionStatement - * renders the state variable for datastore and adds imports - * - * ex. for form create - * const myFormonSubmit = useDataStoreCreateAction({ - * model: myModel, - * fields: myFormFields, - * schema: schema - * }); - */ -export const buildDataStoreActionStatement = (form: StudioForm, importCollection: ImportCollection) => { - const { - dataType: { dataTypeName }, - formActionType, - } = form; - const actionHookImportValue = getActionHookImportValue(FormTypeDataStoreMap[formActionType]); - importCollection.addMappedImport(actionHookImportValue); - importCollection.addImport(ImportSource.LOCAL_MODELS, dataTypeName); - const properties = [ - // model name - factory.createPropertyAssignment(factory.createIdentifier('model'), factory.createIdentifier(dataTypeName)), - // fields object name - factory.createPropertyAssignment( - factory.createIdentifier('fields'), - factory.createIdentifier(getStateName(FieldStateVariable(form.name))), - ), - ]; - if (formActionType === 'update') { - properties.push(factory.createPropertyAssignment(factory.createIdentifier('id'), factory.createIdentifier('id'))); - } - addSchemaToArguments(properties, importCollection); - - return factory.createVariableStatement( - undefined, - factory.createVariableDeclarationList( - [ - factory.createVariableDeclaration( - factory.createIdentifier(getActionIdentifier(form.name, 'onSubmit')), - undefined, - undefined, - factory.createCallExpression(factory.createIdentifier(actionHookImportValue), undefined, [ - factory.createObjectLiteralExpression(properties, false), - ]), - ), - ], - NodeFlags.Const, - ), - ); -}; export const buildMutationBindings = (form: StudioForm) => { const { @@ -316,7 +263,7 @@ export const buildStateMutationStatement = (name: string, defaultValue: Expressi ); }; -export const buildOnChangeStatement = (fieldName: string, id: string) => { +export const buildOnChangeStatement = (fieldName: string, id?: string) => { return factory.createJsxAttribute( factory.createIdentifier('onChange'), factory.createJsxExpression( diff --git a/packages/codegen-ui-react/lib/forms/react-form-renderer.ts b/packages/codegen-ui-react/lib/forms/react-form-renderer.ts index 218478e12..872749bd8 100644 --- a/packages/codegen-ui-react/lib/forms/react-form-renderer.ts +++ b/packages/codegen-ui-react/lib/forms/react-form-renderer.ts @@ -46,7 +46,7 @@ import { SyntaxKind, TypeAliasDeclaration, } from 'typescript'; -import { ImportCollection, ImportValue } from '../imports'; +import { ImportCollection, ImportSource, ImportValue } from '../imports'; import { PrimitiveTypeParameter, Primitive } from '../primitive'; import { getComponentPropName } from '../react-component-render-helper'; import { ReactOutputManager } from '../react-output-manager'; @@ -58,13 +58,7 @@ import { transpile, } from '../react-studio-template-renderer-helper'; import { RequiredKeys } from '../utils/type-utils'; -import { - buildFieldStateStatements, - buildFormPropNode, - buildDataStoreActionStatement, - buildMutationBindings, - buildStateMutationStatement, -} from './form-renderer-helper'; +import { buildFormPropNode, buildMutationBindings, buildStateMutationStatement } from './form-renderer-helper'; export abstract class ReactFormTemplateRenderer extends StudioTemplateRenderer< string, @@ -297,7 +291,10 @@ export abstract class ReactFormTemplateRenderer extends StudioTemplateRenderer< // add in hooks for before/complete with ds and basic onSubmit with props elements.push(...buildMutationBindings(this.component)); - + // add onValidate prop + elements.push( + factory.createBindingElement(undefined, undefined, factory.createIdentifier('onValidate'), undefined), + ); // overrides elements.push(factory.createBindingElement(undefined, undefined, factory.createIdentifier('overrides'), undefined)); @@ -328,20 +325,20 @@ export abstract class ReactFormTemplateRenderer extends StudioTemplateRenderer< ), ), ); - if (this.componentMetadata.formMetadata?.onValidationFields) { - const fields = Object.keys(this.componentMetadata.formMetadata?.onValidationFields); - - fields.forEach((field) => { + if (this.componentMetadata.formMetadata?.onChangeFields.length) { + this.componentMetadata.formMetadata?.onChangeFields.forEach((field) => { statements.push(buildStateMutationStatement(`${field}FieldError`, factory.createObjectLiteralExpression())); }); this.importCollection.addMappedImport(ImportValue.VALIDATE_FIELD); } - statements.push(buildFieldStateStatements(this.component.name, this.importCollection)); + this.importCollection.addMappedImport(ImportValue.USE_STATE_MUTATION_ACTION); + + statements.push(buildStateMutationStatement('modelFields', factory.createObjectLiteralExpression())); statements.push(buildStateMutationStatement('formValid', factory.createTrue())); - // build data source action + // add model import for datastore type if (this.component.dataType.dataSourceType === 'DataStore') { - statements.push(buildDataStoreActionStatement(this.component, this.importCollection)); + this.importCollection.addImport(ImportSource.LOCAL_MODELS, this.component.dataType.dataTypeName); } return statements; } diff --git a/packages/codegen-ui/lib/__tests__/generate-form-definition/form-to-component.test.ts b/packages/codegen-ui/lib/__tests__/generate-form-definition/form-to-component.test.ts index 6bf1f4b1a..6b96ad435 100644 --- a/packages/codegen-ui/lib/__tests__/generate-form-definition/form-to-component.test.ts +++ b/packages/codegen-ui/lib/__tests__/generate-form-definition/form-to-component.test.ts @@ -19,6 +19,7 @@ import { StudioForm } from '../../types'; describe('formToComponent', () => { it('should map datastore model fields', () => { const myForm: StudioForm = { + id: '123', name: 'mySampleForm', formActionType: 'create', dataType: { dataSourceType: 'DataStore', dataTypeName: 'Post' }, diff --git a/packages/codegen-ui/lib/types/form/form-metadata.ts b/packages/codegen-ui/lib/types/form/form-metadata.ts index 1b6fe578a..0fe4098a4 100644 --- a/packages/codegen-ui/lib/types/form/form-metadata.ts +++ b/packages/codegen-ui/lib/types/form/form-metadata.ts @@ -16,7 +16,7 @@ import { FieldValidationConfiguration } from './form-validation'; export type FormMetadata = { - id: string; + id?: string; name: string; fieldState: string; onChangeFields: string[]; diff --git a/packages/codegen-ui/lib/types/form/index.ts b/packages/codegen-ui/lib/types/form/index.ts index 371dddfa3..8955e2da5 100644 --- a/packages/codegen-ui/lib/types/form/index.ts +++ b/packages/codegen-ui/lib/types/form/index.ts @@ -39,7 +39,7 @@ type StudioFormActionType = 'create' | 'update'; * This is the base type for all StudioForms */ export type StudioForm = { - id: string; + id?: string; name: string; diff --git a/packages/test-generator/lib/forms/form-create.json b/packages/test-generator/lib/forms/form-create.json index ba837b4c3..4081bcdb0 100644 --- a/packages/test-generator/lib/forms/form-create.json +++ b/packages/test-generator/lib/forms/form-create.json @@ -1,42 +1,51 @@ { + "id": "123", "name": "FormCreate", "formActionType": "create", "dataType": { - "dataSourceType": "Custom", - "dataTypeName": "Post" + "dataSourceType": "DataStore", + "dataTypeName": "User" }, "fields": { - "name": { + "firstName": { "inputType": { "required": true, "type": "TextField", - "name": "name", - "defaultValue": "John Doe" + "name": "firstName", + "defaultValue": "John" }, - "label": "name", + "label": "First Name", "validations": [ { "type": "Required" } ] }, - "email": { + "loggedInColor": { "inputType": { "required": true, "type": "TextField", - "name": "email", + "name": "loggedInColor", "defaultValue": "johndoe@amplify.com" }, - "label": "E-mail", + "label": "Logged In Color", "validations": [ { "type": "Required" - }, - { - "type": "Email", - "validationMessage": "Email should be required" } ] + }, + "loggedOutColor": { + "excluded": true + }, + "lastName": { + "excluded": true + }, + "age": { + "excluded": true + }, + "isLoggedIn": { + "excluded": true } }, "sectionalElements": {}, diff --git a/packages/test-generator/lib/forms/form-update.json b/packages/test-generator/lib/forms/form-update.json index 5c2acc701..5a20ca505 100644 --- a/packages/test-generator/lib/forms/form-update.json +++ b/packages/test-generator/lib/forms/form-update.json @@ -1,33 +1,37 @@ { + "id": "123", "name": "FormUpdate", "formActionType": "update", "dataType": { - "dataSourceType": "Custom", - "dataTypeName": "Post" + "dataSourceType": "DataStore", + "dataTypeName": "UserPreference" }, "fields": { - "name": { + "favoriteColor": { + "position": { + "fixed": "first" + }, "inputType": { "required": true, "type": "TextField", - "name": "name", + "name": "favoriteColor", "defaultValue": "John Doe" }, - "label": "name", + "label": "Favorite Color", "validations": [ { "type": "Required" } ] }, - "email": { + "createdAt": { "inputType": { "required": true, "type": "TextField", - "name": "email", - "defaultValue": "johndoe@amplify.com" + "name": "createdat", + "defaultValue": "123456" }, - "label": "E-mail" + "label": "Created At" } }, "sectionalElements": {}, diff --git a/packages/test-generator/lib/generators/BrowserTestGenerator.ts b/packages/test-generator/lib/generators/BrowserTestGenerator.ts index 506766697..974810c20 100644 --- a/packages/test-generator/lib/generators/BrowserTestGenerator.ts +++ b/packages/test-generator/lib/generators/BrowserTestGenerator.ts @@ -15,7 +15,13 @@ */ /* Test Generator to be used in the browser environment */ -import { FormMetadata, StudioComponent, StudioForm, StudioTheme } from '@aws-amplify/codegen-ui'; +import { + FormMetadata, + getGenericFromDataStore, + StudioComponent, + StudioForm, + StudioTheme, +} from '@aws-amplify/codegen-ui'; import { AmplifyRenderer, ReactThemeStudioTemplateRenderer, @@ -23,6 +29,7 @@ import { ReactUtilsStudioTemplateRenderer, AmplifyFormRenderer, } from '@aws-amplify/codegen-ui-react'; +import schema from '../models/schema'; import { TestGenerator } from './TestGenerator'; export class BrowserTestGenerator extends TestGenerator { @@ -53,7 +60,7 @@ export class BrowserTestGenerator extends TestGenerator { } renderForm(form: StudioForm) { - return new AmplifyFormRenderer(form, undefined, this.renderConfig).renderComponentOnly(); + return new AmplifyFormRenderer(form, getGenericFromDataStore(schema), this.renderConfig).renderComponentOnly(); } renderTheme(theme: StudioTheme) { diff --git a/packages/test-generator/lib/generators/NodeTestGenerator.ts b/packages/test-generator/lib/generators/NodeTestGenerator.ts index b044bad0b..6e311f8ab 100644 --- a/packages/test-generator/lib/generators/NodeTestGenerator.ts +++ b/packages/test-generator/lib/generators/NodeTestGenerator.ts @@ -23,6 +23,7 @@ import { StudioComponent, StudioTheme, StudioForm, + getGenericFromDataStore, } from '@aws-amplify/codegen-ui'; import { AmplifyRenderer, @@ -31,6 +32,7 @@ import { ReactUtilsStudioTemplateRenderer, AmplifyFormRenderer, } from '@aws-amplify/codegen-ui-react'; +import schema from '../models/schema'; import { TestGenerator, TestGeneratorParams } from './TestGenerator'; export class NodeTestGenerator extends TestGenerator { @@ -62,8 +64,9 @@ export class NodeTestGenerator extends TestGenerator { this.themeRendererFactory = new StudioTemplateRendererFactory( (theme: StudioTheme) => new ReactThemeStudioTemplateRenderer(theme, this.renderConfig), ); + this.formRendererFactory = new StudioTemplateRendererFactory( - (form: StudioForm) => new AmplifyFormRenderer(form, undefined, this.renderConfig), + (form: StudioForm) => new AmplifyFormRenderer(form, getGenericFromDataStore(schema), this.renderConfig), ); this.indexRendererFactory = new StudioTemplateRendererFactory( (schemas: (StudioComponent | StudioForm | StudioTheme)[]) => diff --git a/packages/test-generator/lib/models/schema.ts b/packages/test-generator/lib/models/schema.ts new file mode 100644 index 000000000..a03ca7c9a --- /dev/null +++ b/packages/test-generator/lib/models/schema.ts @@ -0,0 +1,364 @@ +/* + Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + + Licensed under the Apache License, Version 2.0 (the "License"). + You may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ +import { Schema } from '@aws-amplify/codegen-ui'; + +export default { + models: { + UserPreference: { + name: 'UserPreference', + fields: { + id: { + name: 'id', + isArray: false, + type: 'ID', + isRequired: true, + attributes: [], + }, + favoriteColor: { + name: 'favoriteColor', + isArray: false, + type: 'String', + isRequired: false, + attributes: [], + }, + createdAt: { + name: 'createdAt', + isArray: false, + type: 'AWSDateTime', + isRequired: false, + attributes: [], + isReadOnly: true, + }, + updatedAt: { + name: 'updatedAt', + isArray: false, + type: 'AWSDateTime', + isRequired: false, + attributes: [], + isReadOnly: true, + }, + }, + syncable: true, + pluralName: 'UserPreferences', + attributes: [ + { + type: 'model', + properties: {}, + }, + { + type: 'auth', + properties: { + rules: [ + { + allow: 'public', + operations: ['create', 'update', 'delete', 'read'], + }, + ], + }, + }, + ], + }, + User: { + name: 'User', + fields: { + id: { + name: 'id', + isArray: false, + type: 'ID', + isRequired: true, + attributes: [], + }, + firstName: { + name: 'firstName', + isArray: false, + type: 'String', + isRequired: false, + attributes: [], + }, + lastName: { + name: 'lastName', + isArray: false, + type: 'String', + isRequired: false, + attributes: [], + }, + age: { + name: 'age', + isArray: false, + type: 'Int', + isRequired: false, + attributes: [], + }, + isLoggedIn: { + name: 'isLoggedIn', + isArray: false, + type: 'Boolean', + isRequired: false, + attributes: [], + }, + loggedInColor: { + name: 'loggedInColor', + isArray: false, + type: 'String', + isRequired: false, + attributes: [], + }, + loggedOutColor: { + name: 'loggedOutColor', + isArray: false, + type: 'String', + isRequired: false, + attributes: [], + }, + createdAt: { + name: 'createdAt', + isArray: false, + type: 'AWSDateTime', + isRequired: false, + attributes: [], + isReadOnly: true, + }, + updatedAt: { + name: 'updatedAt', + isArray: false, + type: 'AWSDateTime', + isRequired: false, + attributes: [], + isReadOnly: true, + }, + }, + syncable: true, + pluralName: 'Users', + attributes: [ + { + type: 'model', + properties: {}, + }, + { + type: 'auth', + properties: { + rules: [ + { + allow: 'public', + operations: ['create', 'update', 'delete', 'read'], + }, + ], + }, + }, + ], + }, + Listing: { + name: 'Listing', + fields: { + id: { + name: 'id', + isArray: false, + type: 'ID', + isRequired: true, + attributes: [], + }, + title: { + name: 'title', + isArray: false, + type: 'String', + isRequired: false, + attributes: [], + }, + priceUSD: { + name: 'priceUSD', + isArray: false, + type: 'Int', + isRequired: false, + attributes: [], + }, + description: { + name: 'description', + isArray: false, + type: 'String', + isRequired: false, + attributes: [], + }, + createdAt: { + name: 'createdAt', + isArray: false, + type: 'AWSDateTime', + isRequired: false, + attributes: [], + isReadOnly: true, + }, + updatedAt: { + name: 'updatedAt', + isArray: false, + type: 'AWSDateTime', + isRequired: false, + attributes: [], + isReadOnly: true, + }, + }, + syncable: true, + pluralName: 'Listings', + attributes: [ + { + type: 'model', + properties: {}, + }, + { + type: 'auth', + properties: { + rules: [ + { + allow: 'public', + operations: ['create', 'update', 'delete', 'read'], + }, + ], + }, + }, + ], + }, + ComplexModel: { + name: 'ComplexModel', + fields: { + id: { + name: 'id', + isArray: false, + type: 'ID', + isRequired: true, + attributes: [], + }, + listElement: { + name: 'listElement', + isArray: true, + type: 'String', + isRequired: true, + attributes: [], + isArrayNullable: false, + }, + myCustomField: { + name: 'myCustomField', + isArray: false, + type: { + nonModel: 'CustomType', + }, + isRequired: false, + attributes: [], + }, + createdAt: { + name: 'createdAt', + isArray: false, + type: 'AWSDateTime', + isRequired: false, + attributes: [], + isReadOnly: true, + }, + updatedAt: { + name: 'updatedAt', + isArray: false, + type: 'AWSDateTime', + isRequired: false, + attributes: [], + isReadOnly: true, + }, + }, + syncable: true, + pluralName: 'ComplexModels', + attributes: [ + { + type: 'model', + properties: {}, + }, + { + type: 'auth', + properties: { + rules: [ + { + allow: 'public', + operations: ['create', 'update', 'delete', 'read'], + }, + ], + }, + }, + ], + }, + Class: { + name: 'Class', + fields: { + id: { + name: 'id', + isArray: false, + type: 'ID', + isRequired: true, + attributes: [], + }, + name: { + name: 'name', + isArray: false, + type: 'String', + isRequired: false, + attributes: [], + }, + }, + syncable: true, + pluralName: 'Classes', + attributes: [ + { + type: 'model', + properties: {}, + }, + { + type: 'auth', + properties: { + rules: [ + { + allow: 'public', + operations: ['create', 'update', 'delete', 'read'], + }, + ], + }, + }, + ], + }, + }, + enums: {}, + nonModels: { + CustomType: { + name: 'CustomType', + fields: { + StringVal: { + name: 'StringVal', + isArray: false, + type: 'String', + isRequired: false, + attributes: [], + }, + NumVal: { + name: 'NumVal', + isArray: false, + type: 'Int', + isRequired: false, + attributes: [], + }, + BoolVal: { + name: 'BoolVal', + isArray: false, + type: 'Boolean', + isRequired: false, + attributes: [], + }, + }, + }, + }, + version: 'f6252c821249b6b1abda9fb24481c5a4', +} as Schema;