From 19e5f6454587bbb698d0e5a98f2fedda8e661859 Mon Sep 17 00:00:00 2001 From: Ian Saultz <52051793+atierian@users.noreply.github.com> Date: Tue, 23 Jul 2024 10:33:11 -0400 Subject: [PATCH] use nested root mis within each conversationroute --- .../1/ModelIntrospectionSchema.json | 40 +- ...c-model-introspection-visitor.test.ts.snap | 269 ++++++++-- .../interfaces/introspection/model-schema.ts | 11 +- .../src/validate-cjs.js | 2 +- .../appsync-model-introspection-visitor.ts | 461 +++++++++++------- 5 files changed, 555 insertions(+), 228 deletions(-) diff --git a/packages/appsync-modelgen-plugin/schemas/introspection/1/ModelIntrospectionSchema.json b/packages/appsync-modelgen-plugin/schemas/introspection/1/ModelIntrospectionSchema.json index 4486eafa5..c36636056 100644 --- a/packages/appsync-modelgen-plugin/schemas/introspection/1/ModelIntrospectionSchema.json +++ b/packages/appsync-modelgen-plugin/schemas/introspection/1/ModelIntrospectionSchema.json @@ -548,6 +548,18 @@ "SchemaConversationRoute": { "type": "object", "properties": { + "name": { + "type": "string" + }, + "models": { + "$ref": "#/definitions/SchemaModels" + }, + "nonModels": { + "$ref": "#/definitions/SchemaNonModels" + }, + "enums": { + "$ref": "#/definitions/SchemaEnums" + }, "conversation": { "$ref": "#/definitions/SchemaConversation" }, @@ -556,6 +568,10 @@ } }, "required": [ + "name", + "models", + "nonModels", + "enums", "conversation", "message" ], @@ -564,32 +580,20 @@ "SchemaConversation": { "type": "object", "properties": { - "create": { - "$ref": "#/definitions/SchemaMutation" - }, - "get": { - "$ref": "#/definitions/SchemaQuery" - }, - "delete": { - "$ref": "#/definitions/SchemaMutation" - }, - "list": { - "$ref": "#/definitions/SchemaQuery" + "modelName": { + "type": "string" } }, "required": [ - "create", - "get", - "delete", - "list" + "modelName" ], "additionalProperties": false }, "SchemaConversationMessage": { "type": "object", "properties": { - "list": { - "$ref": "#/definitions/SchemaQuery" + "modelName": { + "type": "string" }, "subscribe": { "$ref": "#/definitions/SchemaSubscription" @@ -599,7 +603,7 @@ } }, "required": [ - "list", + "modelName", "subscribe", "send" ], diff --git a/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-model-introspection-visitor.test.ts.snap b/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-model-introspection-visitor.test.ts.snap index a52fb5050..940aab0a2 100644 --- a/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-model-introspection-visitor.test.ts.snap +++ b/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-model-introspection-visitor.test.ts.snap @@ -6,59 +6,248 @@ exports[`Conversation Route Introspection Visitor Metadata snapshot should gener \\"models\\": {}, \\"enums\\": {}, \\"nonModels\\": {}, - \\"conversationRoutes\\": { + \\"conversations\\": { \\"pirateChat\\": { - \\"conversation\\": { - \\"create\\": { - \\"name\\": \\"createConversationpirateChat\\", - \\"isArray\\": false, - \\"type\\": { - \\"model\\": \\"ConversationpirateChat\\" - }, - \\"isRequired\\": false - }, - \\"get\\": { - \\"name\\": \\"getConversationpirateChat\\", - \\"isArray\\": false, - \\"type\\": { - \\"model\\": \\"ConversationpirateChat\\" - }, - \\"isRequired\\": false, - \\"arguments\\": { + \\"name\\": \\"pirateChat\\", + \\"models\\": { + \\"ConversationPirateChat\\": { + \\"name\\": \\"ConversationPirateChat\\", + \\"fields\\": { \\"id\\": { \\"name\\": \\"id\\", \\"isArray\\": false, + \\"type\\": \\"ID\\", \\"isRequired\\": true, - \\"type\\": \\"String\\" + \\"attributes\\": [] + }, + \\"name\\": { + \\"name\\": \\"name\\", + \\"isArray\\": false, + \\"type\\": \\"String\\", + \\"isRequired\\": false, + \\"attributes\\": [] + }, + \\"metadata\\": { + \\"name\\": \\"metadata\\", + \\"isArray\\": false, + \\"type\\": \\"AWSJSON\\", + \\"isRequired\\": false, + \\"attributes\\": [] + }, + \\"messages\\": { + \\"name\\": \\"messages\\", + \\"isArray\\": true, + \\"type\\": { + \\"model\\": \\"ConversationMessagePirateChat\\" + }, + \\"isRequired\\": false, + \\"attributes\\": [], + \\"isArrayNullable\\": true, + \\"association\\": { + \\"connectionType\\": \\"HAS_MANY\\", + \\"associatedWith\\": [ + \\"conversationid\\" + ] + } + }, + \\"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\\": \\"ConversationPirateChats\\", + \\"attributes\\": [ + { + \\"type\\": \\"model\\", + \\"properties\\": { + \\"subscriptions\\": { + \\"level\\": \\"off\\" + }, + \\"mutations\\": { + \\"update\\": null + } + } + }, + { + \\"type\\": \\"auth\\", + \\"properties\\": { + \\"rules\\": [ + { + \\"provider\\": \\"userPools\\", + \\"ownerField\\": \\"owner\\", + \\"allow\\": \\"owner\\", + \\"identityClaim\\": \\"cognito:username\\", + \\"operations\\": [ + \\"create\\", + \\"update\\", + \\"delete\\", + \\"read\\" + ] + } + ] + } + } + ], + \\"primaryKeyInfo\\": { + \\"isCustomPrimaryKey\\": false, + \\"primaryKeyFieldName\\": \\"id\\", + \\"sortKeyFieldNames\\": [] } }, - \\"delete\\": { - \\"name\\": \\"deleteConversationpirateChat\\", - \\"isArray\\": false, - \\"type\\": { - \\"model\\": \\"ConversationpirateChat\\" - }, - \\"isRequired\\": false, - \\"arguments\\": { + \\"ConversationMessagePirateChat\\": { + \\"name\\": \\"ConversationMessagePirateChat\\", + \\"fields\\": { \\"id\\": { \\"name\\": \\"id\\", \\"isArray\\": false, + \\"type\\": \\"ID\\", + \\"isRequired\\": true, + \\"attributes\\": [] + }, + \\"conversationId\\": { + \\"name\\": \\"conversationId\\", + \\"isArray\\": false, + \\"type\\": \\"ID\\", \\"isRequired\\": true, - \\"type\\": \\"String\\" + \\"attributes\\": [] + }, + \\"conversation\\": { + \\"name\\": \\"conversation\\", + \\"isArray\\": false, + \\"type\\": { + \\"model\\": \\"ConversationPirateChat\\" + }, + \\"isRequired\\": false, + \\"attributes\\": [], + \\"association\\": { + \\"connectionType\\": \\"BELONGS_TO\\", + \\"targetNames\\": [ + \\"conversationId\\" + ] + } + }, + \\"sender\\": { + \\"name\\": \\"sender\\", + \\"isArray\\": false, + \\"type\\": { + \\"enum\\": \\"ConversationMessageSender\\" + }, + \\"isRequired\\": false, + \\"attributes\\": [] + }, + \\"content\\": { + \\"name\\": \\"content\\", + \\"isArray\\": false, + \\"type\\": \\"String\\", + \\"isRequired\\": false, + \\"attributes\\": [] + }, + \\"context\\": { + \\"name\\": \\"context\\", + \\"isArray\\": false, + \\"type\\": \\"AWSJSON\\", + \\"isRequired\\": false, + \\"attributes\\": [] + }, + \\"uiComponents\\": { + \\"name\\": \\"uiComponents\\", + \\"isArray\\": true, + \\"type\\": \\"AWSJSON\\", + \\"isRequired\\": false, + \\"attributes\\": [], + \\"isArrayNullable\\": true + }, + \\"assistantContent\\": { + \\"name\\": \\"assistantContent\\", + \\"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 } - } - }, - \\"list\\": { - \\"name\\": \\"listConversationpirateChat\\", - \\"isArray\\": true, - \\"type\\": { - \\"model\\": \\"ConversationpirateChat\\" }, - \\"isRequired\\": false + \\"syncable\\": true, + \\"pluralName\\": \\"ConversationMessagePirateChats\\", + \\"attributes\\": [ + { + \\"type\\": \\"model\\", + \\"properties\\": { + \\"subscriptions\\": {}, + \\"mutations\\": { + \\"update\\": null + } + } + }, + { + \\"type\\": \\"auth\\", + \\"properties\\": { + \\"rules\\": [ + { + \\"provider\\": \\"userPools\\", + \\"ownerField\\": \\"owner\\", + \\"allow\\": \\"owner\\", + \\"identityClaim\\": \\"cognito:username\\", + \\"operations\\": [ + \\"create\\", + \\"update\\", + \\"delete\\", + \\"read\\" + ] + } + ] + } + } + ], + \\"primaryKeyInfo\\": { + \\"isCustomPrimaryKey\\": false, + \\"primaryKeyFieldName\\": \\"id\\", + \\"sortKeyFieldNames\\": [] + } + } + }, + \\"nonModels\\": {}, + \\"enums\\": { + \\"ConversationMessageSender\\": { + \\"name\\": \\"ConversationMessageSender\\", + \\"values\\": [ + \\"user\\", + \\"assistant\\" + ] } }, + \\"conversation\\": { + \\"modelName\\": \\"ConversationPirateChat\\" + }, \\"message\\": { + \\"modelName\\": \\"ConversationMessagePirateChat\\", \\"send\\": { \\"name\\": \\"pirateChat\\", \\"isArray\\": false, @@ -82,13 +271,13 @@ exports[`Conversation Route Introspection Visitor Metadata snapshot should gener \\"subscribe\\": { \\"isArray\\": false, \\"isRequired\\": false, - \\"name\\": \\"onAssistantMessageResponsepirateChat\\", + \\"name\\": \\"onAssistantMessageResponsePirateChat\\", \\"type\\": { - \\"model\\": \\"ConversationMessagepirateChat\\" + \\"model\\": \\"ConversationMessagePirateChat\\" }, \\"arguments\\": { - \\"sessionId\\": { - \\"name\\": \\"sessionId\\", + \\"conversationId\\": { + \\"name\\": \\"conversationId\\", \\"isArray\\": false, \\"isRequired\\": true, \\"type\\": \\"ID\\" diff --git a/packages/appsync-modelgen-plugin/src/interfaces/introspection/model-schema.ts b/packages/appsync-modelgen-plugin/src/interfaces/introspection/model-schema.ts index 1c198b183..7fa972f78 100644 --- a/packages/appsync-modelgen-plugin/src/interfaces/introspection/model-schema.ts +++ b/packages/appsync-modelgen-plugin/src/interfaces/introspection/model-schema.ts @@ -34,19 +34,20 @@ export type SchemaInputs = Record; export type SchemaConversationRoutes = Record; export type SchemaConversationRoute = { + name: string; + models: SchemaModels; + nonModels: SchemaNonModels; + enums: SchemaEnums; conversation: SchemaConversation; message: SchemaConversationMessage; } export type SchemaConversation = { - create: SchemaMutation; - get: SchemaQuery; - delete: SchemaMutation; - list: SchemaQuery; + modelName: string; } export type SchemaConversationMessage = { - list: SchemaQuery; + modelName: string; subscribe: SchemaSubscription; send: SchemaMutation; } diff --git a/packages/appsync-modelgen-plugin/src/validate-cjs.js b/packages/appsync-modelgen-plugin/src/validate-cjs.js index af6f90d93..7a458ac48 100644 --- a/packages/appsync-modelgen-plugin/src/validate-cjs.js +++ b/packages/appsync-modelgen-plugin/src/validate-cjs.js @@ -1 +1 @@ -"use strict";module.exports = validate10;module.exports.default = validate10;const schema11 = {"$schema":"http://json-schema.org/draft-07/schema#","type":"object","properties":{"version":{"type":"number","const":1},"models":{"$ref":"#/definitions/SchemaModels"},"nonModels":{"$ref":"#/definitions/SchemaNonModels"},"enums":{"$ref":"#/definitions/SchemaEnums"},"queries":{"$ref":"#/definitions/SchemaQueries"},"mutations":{"$ref":"#/definitions/SchemaMutations"},"subscriptions":{"$ref":"#/definitions/SchemaSubscriptions"},"inputs":{"$ref":"#/definitions/SchemaInputs"},"conversations":{"$ref":"#/definitions/SchemaConversationRoutes"}},"required":["version","models","nonModels","enums"],"additionalProperties":false,"description":"Root Schema Representation","definitions":{"SchemaModels":{"$ref":"#/definitions/Record%3Cstring%2CSchemaModel%3E","description":"Top-level Entities on a Schema"},"Record":{"type":"object","additionalProperties":{"$ref":"#/definitions/SchemaModel"}},"SchemaModel":{"type":"object","properties":{"name":{"type":"string"},"attributes":{"type":"array","items":{"$ref":"#/definitions/ModelAttribute"}},"fields":{"$ref":"#/definitions/Fields"},"pluralName":{"type":"string"},"syncable":{"type":"boolean"},"primaryKeyInfo":{"$ref":"#/definitions/PrimaryKeyInfo"}},"required":["name","fields","pluralName","primaryKeyInfo"],"additionalProperties":false},"ModelAttribute":{"type":"object","properties":{"type":{"type":"string"},"properties":{"type":"object"}},"required":["type"],"additionalProperties":false},"Fields":{"$ref":"#/definitions/Record%3Cstring%2CField%3E","description":"Field Definition"},"Record":{"type":"object","additionalProperties":{"$ref":"#/definitions/Field"}},"Field":{"type":"object","properties":{"name":{"type":"string"},"type":{"$ref":"#/definitions/FieldType"},"isArray":{"type":"boolean"},"isRequired":{"type":"boolean"},"isReadOnly":{"type":"boolean"},"isArrayNullable":{"type":"boolean"},"attributes":{"type":"array","items":{"$ref":"#/definitions/FieldAttribute"}},"association":{"$ref":"#/definitions/AssociationType"},"arguments":{"$ref":"#/definitions/Arguments"}},"required":["name","type","isArray","isRequired"],"additionalProperties":false},"FieldType":{"anyOf":[{"$ref":"#/definitions/ScalarType"},{"type":"object","properties":{"enum":{"type":"string"}},"required":["enum"],"additionalProperties":false},{"type":"object","properties":{"model":{"type":"string"}},"required":["model"],"additionalProperties":false},{"type":"object","properties":{"nonModel":{"type":"string"}},"required":["nonModel"],"additionalProperties":false}]},"ScalarType":{"type":"string","enum":["ID","String","Int","Float","AWSDate","AWSTime","AWSDateTime","AWSTimestamp","AWSEmail","AWSURL","AWSIPAddress","Boolean","AWSJSON","AWSPhone"]},"FieldAttribute":{"$ref":"#/definitions/ModelAttribute"},"AssociationType":{"anyOf":[{"$ref":"#/definitions/AssociationHasMany"},{"$ref":"#/definitions/AssociationHasOne"},{"$ref":"#/definitions/AssociationBelongsTo"}]},"AssociationHasMany":{"type":"object","additionalProperties":false,"properties":{"connectionType":{"$ref":"#/definitions/CodeGenConnectionType"},"associatedWith":{"type":"array","items":{"type":"string"}}},"required":["associatedWith","connectionType"]},"CodeGenConnectionType":{"type":"string","enum":["HAS_ONE","BELONGS_TO","HAS_MANY"],"description":"Field-level Relationship Definitions"},"AssociationHasOne":{"type":"object","additionalProperties":false,"properties":{"connectionType":{"$ref":"#/definitions/CodeGenConnectionType"},"associatedWith":{"type":"array","items":{"type":"string"}},"targetNames":{"type":"array","items":{"type":"string"}}},"required":["associatedWith","connectionType","targetNames"]},"AssociationBelongsTo":{"type":"object","additionalProperties":false,"properties":{"connectionType":{"$ref":"#/definitions/CodeGenConnectionType"},"targetNames":{"type":"array","items":{"type":"string"}}},"required":["connectionType","targetNames"]},"Arguments":{"$ref":"#/definitions/Record%3Cstring%2CArgument%3E"},"Record":{"type":"object","additionalProperties":{"$ref":"#/definitions/Argument"}},"Argument":{"type":"object","properties":{"name":{"type":"string"},"type":{"$ref":"#/definitions/InputFieldType"},"isArray":{"type":"boolean"},"isRequired":{"type":"boolean"},"isArrayNullable":{"type":"boolean"}},"required":["name","type","isArray","isRequired"],"additionalProperties":false},"InputFieldType":{"anyOf":[{"$ref":"#/definitions/ScalarType"},{"type":"object","properties":{"enum":{"type":"string"}},"required":["enum"],"additionalProperties":false},{"type":"object","properties":{"input":{"type":"string"}},"required":["input"],"additionalProperties":false}]},"PrimaryKeyInfo":{"type":"object","properties":{"isCustomPrimaryKey":{"type":"boolean"},"primaryKeyFieldName":{"type":"string"},"sortKeyFieldNames":{"type":"array","items":{"type":"string"}}},"required":["isCustomPrimaryKey","primaryKeyFieldName","sortKeyFieldNames"],"additionalProperties":false},"SchemaNonModels":{"$ref":"#/definitions/Record%3Cstring%2CSchemaNonModel%3E"},"Record":{"type":"object","additionalProperties":{"$ref":"#/definitions/SchemaNonModel"}},"SchemaNonModel":{"type":"object","properties":{"name":{"type":"string"},"fields":{"$ref":"#/definitions/Fields"}},"required":["name","fields"],"additionalProperties":false},"SchemaEnums":{"$ref":"#/definitions/Record%3Cstring%2CSchemaEnum%3E"},"Record":{"type":"object","additionalProperties":{"$ref":"#/definitions/SchemaEnum"}},"SchemaEnum":{"type":"object","properties":{"name":{"type":"string"},"values":{"type":"array","items":{"type":"string"}}},"required":["name","values"],"additionalProperties":false},"SchemaQueries":{"$ref":"#/definitions/Record%3Cstring%2CSchemaQuery%3E"},"Record":{"type":"object","additionalProperties":{"$ref":"#/definitions/SchemaQuery"}},"SchemaQuery":{"$ref":"#/definitions/Pick%3CField%2C(%22name%22%7C%22type%22%7C%22isArray%22%7C%22isRequired%22%7C%22isArrayNullable%22%7C%22arguments%22)%3E"},"Pick":{"type":"object","properties":{"name":{"type":"string"},"type":{"$ref":"#/definitions/FieldType"},"isArray":{"type":"boolean"},"isRequired":{"type":"boolean"},"isArrayNullable":{"type":"boolean"},"arguments":{"$ref":"#/definitions/Arguments"}},"required":["name","type","isArray","isRequired"],"additionalProperties":false},"SchemaMutations":{"$ref":"#/definitions/Record%3Cstring%2CSchemaMutation%3E"},"Record":{"type":"object","additionalProperties":{"$ref":"#/definitions/SchemaMutation"}},"SchemaMutation":{"$ref":"#/definitions/SchemaQuery"},"SchemaSubscriptions":{"$ref":"#/definitions/Record%3Cstring%2CSchemaSubscription%3E"},"Record":{"type":"object","additionalProperties":{"$ref":"#/definitions/SchemaSubscription"}},"SchemaSubscription":{"$ref":"#/definitions/SchemaQuery"},"SchemaInputs":{"$ref":"#/definitions/Record%3Cstring%2CInput%3E"},"Record":{"type":"object","additionalProperties":{"$ref":"#/definitions/Input"}},"Input":{"type":"object","properties":{"name":{"type":"string"},"attributes":{"$ref":"#/definitions/Arguments"}},"required":["name","attributes"],"additionalProperties":false,"description":"Input Definition"},"SchemaConversationRoutes":{"$ref":"#/definitions/Record%3Cstring%2CSchemaConversationRoute%3E"},"Record":{"type":"object","additionalProperties":{"$ref":"#/definitions/SchemaConversationRoute"}},"SchemaConversationRoute":{"type":"object","properties":{"conversation":{"$ref":"#/definitions/SchemaConversation"},"message":{"$ref":"#/definitions/SchemaConversationMessage"}},"required":["conversation","message"],"additionalProperties":false},"SchemaConversation":{"type":"object","properties":{"create":{"$ref":"#/definitions/SchemaMutation"},"get":{"$ref":"#/definitions/SchemaQuery"},"delete":{"$ref":"#/definitions/SchemaMutation"},"list":{"$ref":"#/definitions/SchemaQuery"}},"required":["create","get","delete","list"],"additionalProperties":false},"SchemaConversationMessage":{"type":"object","properties":{"list":{"$ref":"#/definitions/SchemaQuery"},"subscribe":{"$ref":"#/definitions/SchemaSubscription"},"send":{"$ref":"#/definitions/SchemaMutation"}},"required":["list","subscribe","send"],"additionalProperties":false}}};const func2 = Object.prototype.hasOwnProperty;const schema12 = {"type":"object","additionalProperties":{"$ref":"#/definitions/SchemaModel"}};const schema13 = {"type":"object","properties":{"name":{"type":"string"},"attributes":{"type":"array","items":{"$ref":"#/definitions/ModelAttribute"}},"fields":{"$ref":"#/definitions/Fields"},"pluralName":{"type":"string"},"syncable":{"type":"boolean"},"primaryKeyInfo":{"$ref":"#/definitions/PrimaryKeyInfo"}},"required":["name","fields","pluralName","primaryKeyInfo"],"additionalProperties":false};const schema14 = {"type":"object","properties":{"type":{"type":"string"},"properties":{"type":"object"}},"required":["type"],"additionalProperties":false};const schema31 = {"type":"object","properties":{"isCustomPrimaryKey":{"type":"boolean"},"primaryKeyFieldName":{"type":"string"},"sortKeyFieldNames":{"type":"array","items":{"type":"string"}}},"required":["isCustomPrimaryKey","primaryKeyFieldName","sortKeyFieldNames"],"additionalProperties":false};const schema15 = {"type":"object","additionalProperties":{"$ref":"#/definitions/Field"}};const schema16 = {"type":"object","properties":{"name":{"type":"string"},"type":{"$ref":"#/definitions/FieldType"},"isArray":{"type":"boolean"},"isRequired":{"type":"boolean"},"isReadOnly":{"type":"boolean"},"isArrayNullable":{"type":"boolean"},"attributes":{"type":"array","items":{"$ref":"#/definitions/FieldAttribute"}},"association":{"$ref":"#/definitions/AssociationType"},"arguments":{"$ref":"#/definitions/Arguments"}},"required":["name","type","isArray","isRequired"],"additionalProperties":false};const schema17 = {"anyOf":[{"$ref":"#/definitions/ScalarType"},{"type":"object","properties":{"enum":{"type":"string"}},"required":["enum"],"additionalProperties":false},{"type":"object","properties":{"model":{"type":"string"}},"required":["model"],"additionalProperties":false},{"type":"object","properties":{"nonModel":{"type":"string"}},"required":["nonModel"],"additionalProperties":false}]};const schema18 = {"type":"string","enum":["ID","String","Int","Float","AWSDate","AWSTime","AWSDateTime","AWSTimestamp","AWSEmail","AWSURL","AWSIPAddress","Boolean","AWSJSON","AWSPhone"]};function validate15(data, {instancePath="", parentData, parentDataProperty, rootData=data}={}){let vErrors = null;let errors = 0;const _errs0 = errors;let valid0 = false;const _errs1 = errors;if(typeof data !== "string"){const err0 = {instancePath,schemaPath:"#/definitions/ScalarType/type",keyword:"type",params:{type: "string"},message:"must be string"};if(vErrors === null){vErrors = [err0];}else {vErrors.push(err0);}errors++;}if(!((((((((((((((data === "ID") || (data === "String")) || (data === "Int")) || (data === "Float")) || (data === "AWSDate")) || (data === "AWSTime")) || (data === "AWSDateTime")) || (data === "AWSTimestamp")) || (data === "AWSEmail")) || (data === "AWSURL")) || (data === "AWSIPAddress")) || (data === "Boolean")) || (data === "AWSJSON")) || (data === "AWSPhone"))){const err1 = {instancePath,schemaPath:"#/definitions/ScalarType/enum",keyword:"enum",params:{allowedValues: schema18.enum},message:"must be equal to one of the allowed values"};if(vErrors === null){vErrors = [err1];}else {vErrors.push(err1);}errors++;}var _valid0 = _errs1 === errors;valid0 = valid0 || _valid0;if(!valid0){const _errs4 = errors;if(errors === _errs4){if(data && typeof data == "object" && !Array.isArray(data)){let missing0;if((data.enum === undefined) && (missing0 = "enum")){const err2 = {instancePath,schemaPath:"#/anyOf/1/required",keyword:"required",params:{missingProperty: missing0},message:"must have required property '"+missing0+"'"};if(vErrors === null){vErrors = [err2];}else {vErrors.push(err2);}errors++;}else {const _errs6 = errors;for(const key0 in data){if(!(key0 === "enum")){const err3 = {instancePath,schemaPath:"#/anyOf/1/additionalProperties",keyword:"additionalProperties",params:{additionalProperty: key0},message:"must NOT have additional properties"};if(vErrors === null){vErrors = [err3];}else {vErrors.push(err3);}errors++;break;}}if(_errs6 === errors){if(data.enum !== undefined){if(typeof data.enum !== "string"){const err4 = {instancePath:instancePath+"/enum",schemaPath:"#/anyOf/1/properties/enum/type",keyword:"type",params:{type: "string"},message:"must be string"};if(vErrors === null){vErrors = [err4];}else {vErrors.push(err4);}errors++;}}}}}else {const err5 = {instancePath,schemaPath:"#/anyOf/1/type",keyword:"type",params:{type: "object"},message:"must be object"};if(vErrors === null){vErrors = [err5];}else {vErrors.push(err5);}errors++;}}var _valid0 = _errs4 === errors;valid0 = valid0 || _valid0;if(!valid0){const _errs9 = errors;if(errors === _errs9){if(data && typeof data == "object" && !Array.isArray(data)){let missing1;if((data.model === undefined) && (missing1 = "model")){const err6 = {instancePath,schemaPath:"#/anyOf/2/required",keyword:"required",params:{missingProperty: missing1},message:"must have required property '"+missing1+"'"};if(vErrors === null){vErrors = [err6];}else {vErrors.push(err6);}errors++;}else {const _errs11 = errors;for(const key1 in data){if(!(key1 === "model")){const err7 = {instancePath,schemaPath:"#/anyOf/2/additionalProperties",keyword:"additionalProperties",params:{additionalProperty: key1},message:"must NOT have additional properties"};if(vErrors === null){vErrors = [err7];}else {vErrors.push(err7);}errors++;break;}}if(_errs11 === errors){if(data.model !== undefined){if(typeof data.model !== "string"){const err8 = {instancePath:instancePath+"/model",schemaPath:"#/anyOf/2/properties/model/type",keyword:"type",params:{type: "string"},message:"must be string"};if(vErrors === null){vErrors = [err8];}else {vErrors.push(err8);}errors++;}}}}}else {const err9 = {instancePath,schemaPath:"#/anyOf/2/type",keyword:"type",params:{type: "object"},message:"must be object"};if(vErrors === null){vErrors = [err9];}else {vErrors.push(err9);}errors++;}}var _valid0 = _errs9 === errors;valid0 = valid0 || _valid0;if(!valid0){const _errs14 = errors;if(errors === _errs14){if(data && typeof data == "object" && !Array.isArray(data)){let missing2;if((data.nonModel === undefined) && (missing2 = "nonModel")){const err10 = {instancePath,schemaPath:"#/anyOf/3/required",keyword:"required",params:{missingProperty: missing2},message:"must have required property '"+missing2+"'"};if(vErrors === null){vErrors = [err10];}else {vErrors.push(err10);}errors++;}else {const _errs16 = errors;for(const key2 in data){if(!(key2 === "nonModel")){const err11 = {instancePath,schemaPath:"#/anyOf/3/additionalProperties",keyword:"additionalProperties",params:{additionalProperty: key2},message:"must NOT have additional properties"};if(vErrors === null){vErrors = [err11];}else {vErrors.push(err11);}errors++;break;}}if(_errs16 === errors){if(data.nonModel !== undefined){if(typeof data.nonModel !== "string"){const err12 = {instancePath:instancePath+"/nonModel",schemaPath:"#/anyOf/3/properties/nonModel/type",keyword:"type",params:{type: "string"},message:"must be string"};if(vErrors === null){vErrors = [err12];}else {vErrors.push(err12);}errors++;}}}}}else {const err13 = {instancePath,schemaPath:"#/anyOf/3/type",keyword:"type",params:{type: "object"},message:"must be object"};if(vErrors === null){vErrors = [err13];}else {vErrors.push(err13);}errors++;}}var _valid0 = _errs14 === errors;valid0 = valid0 || _valid0;}}}if(!valid0){const err14 = {instancePath,schemaPath:"#/anyOf",keyword:"anyOf",params:{},message:"must match a schema in anyOf"};if(vErrors === null){vErrors = [err14];}else {vErrors.push(err14);}errors++;validate15.errors = vErrors;return false;}else {errors = _errs0;if(vErrors !== null){if(_errs0){vErrors.length = _errs0;}else {vErrors = null;}}}validate15.errors = vErrors;return errors === 0;}const schema20 = {"anyOf":[{"$ref":"#/definitions/AssociationHasMany"},{"$ref":"#/definitions/AssociationHasOne"},{"$ref":"#/definitions/AssociationBelongsTo"}]};const schema21 = {"type":"object","additionalProperties":false,"properties":{"connectionType":{"$ref":"#/definitions/CodeGenConnectionType"},"associatedWith":{"type":"array","items":{"type":"string"}}},"required":["associatedWith","connectionType"]};const schema22 = {"type":"string","enum":["HAS_ONE","BELONGS_TO","HAS_MANY"],"description":"Field-level Relationship Definitions"};function validate18(data, {instancePath="", parentData, parentDataProperty, rootData=data}={}){let vErrors = null;let errors = 0;if(errors === 0){if(data && typeof data == "object" && !Array.isArray(data)){let missing0;if(((data.associatedWith === undefined) && (missing0 = "associatedWith")) || ((data.connectionType === undefined) && (missing0 = "connectionType"))){validate18.errors = [{instancePath,schemaPath:"#/required",keyword:"required",params:{missingProperty: missing0},message:"must have required property '"+missing0+"'"}];return false;}else {const _errs1 = errors;for(const key0 in data){if(!((key0 === "connectionType") || (key0 === "associatedWith"))){validate18.errors = [{instancePath,schemaPath:"#/additionalProperties",keyword:"additionalProperties",params:{additionalProperty: key0},message:"must NOT have additional properties"}];return false;break;}}if(_errs1 === errors){if(data.connectionType !== undefined){let data0 = data.connectionType;const _errs2 = errors;if(typeof data0 !== "string"){validate18.errors = [{instancePath:instancePath+"/connectionType",schemaPath:"#/definitions/CodeGenConnectionType/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}if(!(((data0 === "HAS_ONE") || (data0 === "BELONGS_TO")) || (data0 === "HAS_MANY"))){validate18.errors = [{instancePath:instancePath+"/connectionType",schemaPath:"#/definitions/CodeGenConnectionType/enum",keyword:"enum",params:{allowedValues: schema22.enum},message:"must be equal to one of the allowed values"}];return false;}var valid0 = _errs2 === errors;}else {var valid0 = true;}if(valid0){if(data.associatedWith !== undefined){let data1 = data.associatedWith;const _errs5 = errors;if(errors === _errs5){if(Array.isArray(data1)){var valid2 = true;const len0 = data1.length;for(let i0=0; i0":{"type":"object","additionalProperties":{"$ref":"#/definitions/SchemaModel"}},"SchemaModel":{"type":"object","properties":{"name":{"type":"string"},"attributes":{"type":"array","items":{"$ref":"#/definitions/ModelAttribute"}},"fields":{"$ref":"#/definitions/Fields"},"pluralName":{"type":"string"},"syncable":{"type":"boolean"},"primaryKeyInfo":{"$ref":"#/definitions/PrimaryKeyInfo"}},"required":["name","fields","pluralName","primaryKeyInfo"],"additionalProperties":false},"ModelAttribute":{"type":"object","properties":{"type":{"type":"string"},"properties":{"type":"object"}},"required":["type"],"additionalProperties":false},"Fields":{"$ref":"#/definitions/Record%3Cstring%2CField%3E","description":"Field Definition"},"Record":{"type":"object","additionalProperties":{"$ref":"#/definitions/Field"}},"Field":{"type":"object","properties":{"name":{"type":"string"},"type":{"$ref":"#/definitions/FieldType"},"isArray":{"type":"boolean"},"isRequired":{"type":"boolean"},"isReadOnly":{"type":"boolean"},"isArrayNullable":{"type":"boolean"},"attributes":{"type":"array","items":{"$ref":"#/definitions/FieldAttribute"}},"association":{"$ref":"#/definitions/AssociationType"},"arguments":{"$ref":"#/definitions/Arguments"}},"required":["name","type","isArray","isRequired"],"additionalProperties":false},"FieldType":{"anyOf":[{"$ref":"#/definitions/ScalarType"},{"type":"object","properties":{"enum":{"type":"string"}},"required":["enum"],"additionalProperties":false},{"type":"object","properties":{"model":{"type":"string"}},"required":["model"],"additionalProperties":false},{"type":"object","properties":{"nonModel":{"type":"string"}},"required":["nonModel"],"additionalProperties":false}]},"ScalarType":{"type":"string","enum":["ID","String","Int","Float","AWSDate","AWSTime","AWSDateTime","AWSTimestamp","AWSEmail","AWSURL","AWSIPAddress","Boolean","AWSJSON","AWSPhone"]},"FieldAttribute":{"$ref":"#/definitions/ModelAttribute"},"AssociationType":{"anyOf":[{"$ref":"#/definitions/AssociationHasMany"},{"$ref":"#/definitions/AssociationHasOne"},{"$ref":"#/definitions/AssociationBelongsTo"}]},"AssociationHasMany":{"type":"object","additionalProperties":false,"properties":{"connectionType":{"$ref":"#/definitions/CodeGenConnectionType"},"associatedWith":{"type":"array","items":{"type":"string"}}},"required":["associatedWith","connectionType"]},"CodeGenConnectionType":{"type":"string","enum":["HAS_ONE","BELONGS_TO","HAS_MANY"],"description":"Field-level Relationship Definitions"},"AssociationHasOne":{"type":"object","additionalProperties":false,"properties":{"connectionType":{"$ref":"#/definitions/CodeGenConnectionType"},"associatedWith":{"type":"array","items":{"type":"string"}},"targetNames":{"type":"array","items":{"type":"string"}}},"required":["associatedWith","connectionType","targetNames"]},"AssociationBelongsTo":{"type":"object","additionalProperties":false,"properties":{"connectionType":{"$ref":"#/definitions/CodeGenConnectionType"},"targetNames":{"type":"array","items":{"type":"string"}}},"required":["connectionType","targetNames"]},"Arguments":{"$ref":"#/definitions/Record%3Cstring%2CArgument%3E"},"Record":{"type":"object","additionalProperties":{"$ref":"#/definitions/Argument"}},"Argument":{"type":"object","properties":{"name":{"type":"string"},"type":{"$ref":"#/definitions/InputFieldType"},"isArray":{"type":"boolean"},"isRequired":{"type":"boolean"},"isArrayNullable":{"type":"boolean"}},"required":["name","type","isArray","isRequired"],"additionalProperties":false},"InputFieldType":{"anyOf":[{"$ref":"#/definitions/ScalarType"},{"type":"object","properties":{"enum":{"type":"string"}},"required":["enum"],"additionalProperties":false},{"type":"object","properties":{"input":{"type":"string"}},"required":["input"],"additionalProperties":false}]},"PrimaryKeyInfo":{"type":"object","properties":{"isCustomPrimaryKey":{"type":"boolean"},"primaryKeyFieldName":{"type":"string"},"sortKeyFieldNames":{"type":"array","items":{"type":"string"}}},"required":["isCustomPrimaryKey","primaryKeyFieldName","sortKeyFieldNames"],"additionalProperties":false},"SchemaNonModels":{"$ref":"#/definitions/Record%3Cstring%2CSchemaNonModel%3E"},"Record":{"type":"object","additionalProperties":{"$ref":"#/definitions/SchemaNonModel"}},"SchemaNonModel":{"type":"object","properties":{"name":{"type":"string"},"fields":{"$ref":"#/definitions/Fields"}},"required":["name","fields"],"additionalProperties":false},"SchemaEnums":{"$ref":"#/definitions/Record%3Cstring%2CSchemaEnum%3E"},"Record":{"type":"object","additionalProperties":{"$ref":"#/definitions/SchemaEnum"}},"SchemaEnum":{"type":"object","properties":{"name":{"type":"string"},"values":{"type":"array","items":{"type":"string"}}},"required":["name","values"],"additionalProperties":false},"SchemaQueries":{"$ref":"#/definitions/Record%3Cstring%2CSchemaQuery%3E"},"Record":{"type":"object","additionalProperties":{"$ref":"#/definitions/SchemaQuery"}},"SchemaQuery":{"$ref":"#/definitions/Pick%3CField%2C(%22name%22%7C%22type%22%7C%22isArray%22%7C%22isRequired%22%7C%22isArrayNullable%22%7C%22arguments%22)%3E"},"Pick":{"type":"object","properties":{"name":{"type":"string"},"type":{"$ref":"#/definitions/FieldType"},"isArray":{"type":"boolean"},"isRequired":{"type":"boolean"},"isArrayNullable":{"type":"boolean"},"arguments":{"$ref":"#/definitions/Arguments"}},"required":["name","type","isArray","isRequired"],"additionalProperties":false},"SchemaMutations":{"$ref":"#/definitions/Record%3Cstring%2CSchemaMutation%3E"},"Record":{"type":"object","additionalProperties":{"$ref":"#/definitions/SchemaMutation"}},"SchemaMutation":{"$ref":"#/definitions/SchemaQuery"},"SchemaSubscriptions":{"$ref":"#/definitions/Record%3Cstring%2CSchemaSubscription%3E"},"Record":{"type":"object","additionalProperties":{"$ref":"#/definitions/SchemaSubscription"}},"SchemaSubscription":{"$ref":"#/definitions/SchemaQuery"},"SchemaInputs":{"$ref":"#/definitions/Record%3Cstring%2CInput%3E"},"Record":{"type":"object","additionalProperties":{"$ref":"#/definitions/Input"}},"Input":{"type":"object","properties":{"name":{"type":"string"},"attributes":{"$ref":"#/definitions/Arguments"}},"required":["name","attributes"],"additionalProperties":false,"description":"Input Definition"},"SchemaConversationRoutes":{"$ref":"#/definitions/Record%3Cstring%2CSchemaConversationRoute%3E"},"Record":{"type":"object","additionalProperties":{"$ref":"#/definitions/SchemaConversationRoute"}},"SchemaConversationRoute":{"type":"object","properties":{"name":{"type":"string"},"models":{"$ref":"#/definitions/SchemaModels"},"nonModels":{"$ref":"#/definitions/SchemaNonModels"},"enums":{"$ref":"#/definitions/SchemaEnums"},"conversation":{"$ref":"#/definitions/SchemaConversation"},"message":{"$ref":"#/definitions/SchemaConversationMessage"}},"required":["name","models","nonModels","enums","conversation","message"],"additionalProperties":false},"SchemaConversation":{"type":"object","properties":{"modelName":{"type":"string"}},"required":["modelName"],"additionalProperties":false},"SchemaConversationMessage":{"type":"object","properties":{"modelName":{"type":"string"},"subscribe":{"$ref":"#/definitions/SchemaSubscription"},"send":{"$ref":"#/definitions/SchemaMutation"}},"required":["modelName","subscribe","send"],"additionalProperties":false}}};const func2 = Object.prototype.hasOwnProperty;const schema12 = {"type":"object","additionalProperties":{"$ref":"#/definitions/SchemaModel"}};const schema13 = {"type":"object","properties":{"name":{"type":"string"},"attributes":{"type":"array","items":{"$ref":"#/definitions/ModelAttribute"}},"fields":{"$ref":"#/definitions/Fields"},"pluralName":{"type":"string"},"syncable":{"type":"boolean"},"primaryKeyInfo":{"$ref":"#/definitions/PrimaryKeyInfo"}},"required":["name","fields","pluralName","primaryKeyInfo"],"additionalProperties":false};const schema14 = {"type":"object","properties":{"type":{"type":"string"},"properties":{"type":"object"}},"required":["type"],"additionalProperties":false};const schema31 = {"type":"object","properties":{"isCustomPrimaryKey":{"type":"boolean"},"primaryKeyFieldName":{"type":"string"},"sortKeyFieldNames":{"type":"array","items":{"type":"string"}}},"required":["isCustomPrimaryKey","primaryKeyFieldName","sortKeyFieldNames"],"additionalProperties":false};const schema15 = {"type":"object","additionalProperties":{"$ref":"#/definitions/Field"}};const schema16 = {"type":"object","properties":{"name":{"type":"string"},"type":{"$ref":"#/definitions/FieldType"},"isArray":{"type":"boolean"},"isRequired":{"type":"boolean"},"isReadOnly":{"type":"boolean"},"isArrayNullable":{"type":"boolean"},"attributes":{"type":"array","items":{"$ref":"#/definitions/FieldAttribute"}},"association":{"$ref":"#/definitions/AssociationType"},"arguments":{"$ref":"#/definitions/Arguments"}},"required":["name","type","isArray","isRequired"],"additionalProperties":false};const schema17 = {"anyOf":[{"$ref":"#/definitions/ScalarType"},{"type":"object","properties":{"enum":{"type":"string"}},"required":["enum"],"additionalProperties":false},{"type":"object","properties":{"model":{"type":"string"}},"required":["model"],"additionalProperties":false},{"type":"object","properties":{"nonModel":{"type":"string"}},"required":["nonModel"],"additionalProperties":false}]};const schema18 = {"type":"string","enum":["ID","String","Int","Float","AWSDate","AWSTime","AWSDateTime","AWSTimestamp","AWSEmail","AWSURL","AWSIPAddress","Boolean","AWSJSON","AWSPhone"]};function validate15(data, {instancePath="", parentData, parentDataProperty, rootData=data}={}){let vErrors = null;let errors = 0;const _errs0 = errors;let valid0 = false;const _errs1 = errors;if(typeof data !== "string"){const err0 = {instancePath,schemaPath:"#/definitions/ScalarType/type",keyword:"type",params:{type: "string"},message:"must be string"};if(vErrors === null){vErrors = [err0];}else {vErrors.push(err0);}errors++;}if(!((((((((((((((data === "ID") || (data === "String")) || (data === "Int")) || (data === "Float")) || (data === "AWSDate")) || (data === "AWSTime")) || (data === "AWSDateTime")) || (data === "AWSTimestamp")) || (data === "AWSEmail")) || (data === "AWSURL")) || (data === "AWSIPAddress")) || (data === "Boolean")) || (data === "AWSJSON")) || (data === "AWSPhone"))){const err1 = {instancePath,schemaPath:"#/definitions/ScalarType/enum",keyword:"enum",params:{allowedValues: schema18.enum},message:"must be equal to one of the allowed values"};if(vErrors === null){vErrors = [err1];}else {vErrors.push(err1);}errors++;}var _valid0 = _errs1 === errors;valid0 = valid0 || _valid0;if(!valid0){const _errs4 = errors;if(errors === _errs4){if(data && typeof data == "object" && !Array.isArray(data)){let missing0;if((data.enum === undefined) && (missing0 = "enum")){const err2 = {instancePath,schemaPath:"#/anyOf/1/required",keyword:"required",params:{missingProperty: missing0},message:"must have required property '"+missing0+"'"};if(vErrors === null){vErrors = [err2];}else {vErrors.push(err2);}errors++;}else {const _errs6 = errors;for(const key0 in data){if(!(key0 === "enum")){const err3 = {instancePath,schemaPath:"#/anyOf/1/additionalProperties",keyword:"additionalProperties",params:{additionalProperty: key0},message:"must NOT have additional properties"};if(vErrors === null){vErrors = [err3];}else {vErrors.push(err3);}errors++;break;}}if(_errs6 === errors){if(data.enum !== undefined){if(typeof data.enum !== "string"){const err4 = {instancePath:instancePath+"/enum",schemaPath:"#/anyOf/1/properties/enum/type",keyword:"type",params:{type: "string"},message:"must be string"};if(vErrors === null){vErrors = [err4];}else {vErrors.push(err4);}errors++;}}}}}else {const err5 = {instancePath,schemaPath:"#/anyOf/1/type",keyword:"type",params:{type: "object"},message:"must be object"};if(vErrors === null){vErrors = [err5];}else {vErrors.push(err5);}errors++;}}var _valid0 = _errs4 === errors;valid0 = valid0 || _valid0;if(!valid0){const _errs9 = errors;if(errors === _errs9){if(data && typeof data == "object" && !Array.isArray(data)){let missing1;if((data.model === undefined) && (missing1 = "model")){const err6 = {instancePath,schemaPath:"#/anyOf/2/required",keyword:"required",params:{missingProperty: missing1},message:"must have required property '"+missing1+"'"};if(vErrors === null){vErrors = [err6];}else {vErrors.push(err6);}errors++;}else {const _errs11 = errors;for(const key1 in data){if(!(key1 === "model")){const err7 = {instancePath,schemaPath:"#/anyOf/2/additionalProperties",keyword:"additionalProperties",params:{additionalProperty: key1},message:"must NOT have additional properties"};if(vErrors === null){vErrors = [err7];}else {vErrors.push(err7);}errors++;break;}}if(_errs11 === errors){if(data.model !== undefined){if(typeof data.model !== "string"){const err8 = {instancePath:instancePath+"/model",schemaPath:"#/anyOf/2/properties/model/type",keyword:"type",params:{type: "string"},message:"must be string"};if(vErrors === null){vErrors = [err8];}else {vErrors.push(err8);}errors++;}}}}}else {const err9 = {instancePath,schemaPath:"#/anyOf/2/type",keyword:"type",params:{type: "object"},message:"must be object"};if(vErrors === null){vErrors = [err9];}else {vErrors.push(err9);}errors++;}}var _valid0 = _errs9 === errors;valid0 = valid0 || _valid0;if(!valid0){const _errs14 = errors;if(errors === _errs14){if(data && typeof data == "object" && !Array.isArray(data)){let missing2;if((data.nonModel === undefined) && (missing2 = "nonModel")){const err10 = {instancePath,schemaPath:"#/anyOf/3/required",keyword:"required",params:{missingProperty: missing2},message:"must have required property '"+missing2+"'"};if(vErrors === null){vErrors = [err10];}else {vErrors.push(err10);}errors++;}else {const _errs16 = errors;for(const key2 in data){if(!(key2 === "nonModel")){const err11 = {instancePath,schemaPath:"#/anyOf/3/additionalProperties",keyword:"additionalProperties",params:{additionalProperty: key2},message:"must NOT have additional properties"};if(vErrors === null){vErrors = [err11];}else {vErrors.push(err11);}errors++;break;}}if(_errs16 === errors){if(data.nonModel !== undefined){if(typeof data.nonModel !== "string"){const err12 = {instancePath:instancePath+"/nonModel",schemaPath:"#/anyOf/3/properties/nonModel/type",keyword:"type",params:{type: "string"},message:"must be string"};if(vErrors === null){vErrors = [err12];}else {vErrors.push(err12);}errors++;}}}}}else {const err13 = {instancePath,schemaPath:"#/anyOf/3/type",keyword:"type",params:{type: "object"},message:"must be object"};if(vErrors === null){vErrors = [err13];}else {vErrors.push(err13);}errors++;}}var _valid0 = _errs14 === errors;valid0 = valid0 || _valid0;}}}if(!valid0){const err14 = {instancePath,schemaPath:"#/anyOf",keyword:"anyOf",params:{},message:"must match a schema in anyOf"};if(vErrors === null){vErrors = [err14];}else {vErrors.push(err14);}errors++;validate15.errors = vErrors;return false;}else {errors = _errs0;if(vErrors !== null){if(_errs0){vErrors.length = _errs0;}else {vErrors = null;}}}validate15.errors = vErrors;return errors === 0;}const schema20 = {"anyOf":[{"$ref":"#/definitions/AssociationHasMany"},{"$ref":"#/definitions/AssociationHasOne"},{"$ref":"#/definitions/AssociationBelongsTo"}]};const schema21 = {"type":"object","additionalProperties":false,"properties":{"connectionType":{"$ref":"#/definitions/CodeGenConnectionType"},"associatedWith":{"type":"array","items":{"type":"string"}}},"required":["associatedWith","connectionType"]};const schema22 = {"type":"string","enum":["HAS_ONE","BELONGS_TO","HAS_MANY"],"description":"Field-level Relationship Definitions"};function validate18(data, {instancePath="", parentData, parentDataProperty, rootData=data}={}){let vErrors = null;let errors = 0;if(errors === 0){if(data && typeof data == "object" && !Array.isArray(data)){let missing0;if(((data.associatedWith === undefined) && (missing0 = "associatedWith")) || ((data.connectionType === undefined) && (missing0 = "connectionType"))){validate18.errors = [{instancePath,schemaPath:"#/required",keyword:"required",params:{missingProperty: missing0},message:"must have required property '"+missing0+"'"}];return false;}else {const _errs1 = errors;for(const key0 in data){if(!((key0 === "connectionType") || (key0 === "associatedWith"))){validate18.errors = [{instancePath,schemaPath:"#/additionalProperties",keyword:"additionalProperties",params:{additionalProperty: key0},message:"must NOT have additional properties"}];return false;break;}}if(_errs1 === errors){if(data.connectionType !== undefined){let data0 = data.connectionType;const _errs2 = errors;if(typeof data0 !== "string"){validate18.errors = [{instancePath:instancePath+"/connectionType",schemaPath:"#/definitions/CodeGenConnectionType/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}if(!(((data0 === "HAS_ONE") || (data0 === "BELONGS_TO")) || (data0 === "HAS_MANY"))){validate18.errors = [{instancePath:instancePath+"/connectionType",schemaPath:"#/definitions/CodeGenConnectionType/enum",keyword:"enum",params:{allowedValues: schema22.enum},message:"must be equal to one of the allowed values"}];return false;}var valid0 = _errs2 === errors;}else {var valid0 = true;}if(valid0){if(data.associatedWith !== undefined){let data1 = data.associatedWith;const _errs5 = errors;if(errors === _errs5){if(Array.isArray(data1)){var valid2 = true;const len0 = data1.length;for(let i0=0; i0 directive.name === 'conversation')) { return acc; } - const { route, inputs } = this.generateConversationMetadata(mutationObj) - return { ...acc, [mutationObj.name]: route } + return { ...acc, [mutationObj.name]: this.generateConversationMetadata(mutationObj) } }, {}); const subscriptions = Object.values(this.subscriptionMap).reduce((acc, subscriptionObj: CodeGenSubscription) => { // Skip the field if the field type is union/interface @@ -247,191 +247,324 @@ export class AppSyncModelIntrospectionVisitor< return operationMeta as V; } - private generateConversationMetadata(mutationObj: CodeGenMutation): { route: SchemaConversationRoute, inputs: CodeGenInputObjectMap} { - const routeName = pascalCase(mutationObj.name) - const route: SchemaConversationRoute = { - conversation: { - create: { - name: `createConversation${routeName}`, - isArray: false, - type: { - model: `Conversation${routeName}` - }, - isRequired: false, + private generateConversationMetadata(mutationObj: CodeGenMutation): SchemaConversationRoute { + const routeName = pascalCase(mutationObj.name) + const conversationModelName = `Conversation${routeName}`; + const pluarlizedConversationModelName = plural(conversationModelName); + const conversationMessageModelName = `ConversationMessage${routeName}`; + const pluarlizedConversationMessageModelName = plural(conversationMessageModelName); + // TODO: clean up schema model definition. Use utilities and/or move to a separate function. + // The conversation / conversation message model definitions shouldn't be repeated here. + // There should be a single source of truth within the transformer that's imported here - + // similar to how the directive definitions work today. + const conversationModel: SchemaModel = { + name: conversationModelName, + fields: { + id: { + name: 'id', + isArray: false, + type: 'ID', + isRequired: true, + attributes: [] + }, + name: { + name: 'name', + isArray: false, + type: 'String', + isRequired: false, + attributes: [] + }, + metadata: { + name: 'metadata', + isArray: false, + type: 'AWSJSON', + isRequired: false, + attributes: [] + }, + messages: { + name: 'messages', + isArray: true, + type: { + model: conversationMessageModelName }, - get: { - name: `getConversation${routeName}`, - isArray: false, - type: { model: `Conversation${routeName}` }, - isRequired: false, - arguments: { - 'id': { - name: 'id', - isArray: false, - isRequired: true, - type: 'String', - } + isRequired: false, + attributes: [], + isArrayNullable: true, + association: { + connectionType: CodeGenConnectionType.HAS_MANY, + associatedWith: [ + 'conversationid' + ] + } + }, + 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: pluarlizedConversationModelName, + attributes: [ + { + type: 'model', + properties: { + subscriptions: { + level: 'off' + }, + mutations: { + update: null } - }, - delete: { - name: `deleteConversation${routeName}`, - isArray: false, - type: { model: `Conversation${routeName}` }, - isRequired: false, - arguments: { - 'id': { - name: 'id', - isArray: false, - isRequired: true, - type: 'String', + } + }, + { + type: 'auth', + properties: { + rules: [ + { + provider: 'userPools', + ownerField: 'owner', + allow: 'owner', + identityClaim: 'cognito:username', + operations: [ + 'create', + 'update', + 'delete', + 'read' + ] } - } + ] + } + } + ], + primaryKeyInfo: { + isCustomPrimaryKey: false, + primaryKeyFieldName: 'id', + sortKeyFieldNames: [] + } + } + + const conversationMessageModel: SchemaModel = { + name: conversationMessageModelName, + fields: { + id: { + name: 'id', + isArray: false, + type: 'ID', + isRequired: true, + attributes: [] + }, + conversationId: { + name: 'conversationId', + isArray: false, + type: 'ID', + isRequired: true, + attributes: [] + }, + conversation: { + name: 'conversation', + isArray: false, + type: { + model: conversationModelName }, - list: { - name: `listConversation${routeName}`, - isArray: true, - type: { - model: `Conversation${routeName}` - }, - isRequired: false, + isRequired: false, + attributes: [], + association: { + connectionType: CodeGenConnectionType.BELONGS_TO, + targetNames: [ + 'conversationId' + ] } }, - message: { - send: this.generateGraphQLOperationMetadata(mutationObj), - subscribe: { - isArray: false, - isRequired: false, - name: `onAssistantMessageResponse${routeName}`, - type: { model: `ConversationMessage${routeName}` }, - arguments: { - 'sessionId': { - name: 'sessionId', - isArray: false, - isRequired: true, - type: 'ID', - }, - } + sender: { + name: 'sender', + isArray: false, + type: { + enum: 'ConversationMessageSender' }, - list: { - name: `listConversationMessage${routeName}`, - isArray: true, - type: { - nonModel: `ModelConversationMessage${routeName}Connection` - }, - isRequired: false, - arguments: { - filter: { - name: 'filter', - isArray: false, - isRequired: false, - type: { - input: `ModelConversationMessage${routeName}FilterInput` - }, - }, - limit: { - name: 'limit', - type: 'Int', - isArray: false, - isRequired: false, - }, - nextToken: { - name: 'nextToken', - isRequired: false, - type: 'String', - isArray: false - } + isRequired: false, + attributes: [] + }, + content: { + name: 'content', + isArray: false, + type: 'String', + isRequired: false, + attributes: [] + }, + context: { + name: 'context', + isArray: false, + type: 'AWSJSON', + isRequired: false, + attributes: [] + }, + uiComponents: { + name: 'uiComponents', + isArray: true, + type: 'AWSJSON', + isRequired: false, + attributes: [], + isArrayNullable: true + }, + assistantContent: { + name: 'assistantContent', + 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: pluarlizedConversationMessageModelName, + attributes: [ + { + type: 'model', + properties: { + subscriptions: {}, + mutations: { + update: null } } + }, + { + type: 'auth', + properties: { + rules: [ + { + provider: 'userPools', + ownerField: 'owner', + allow: 'owner', + identityClaim: 'cognito:username', + operations: [ + 'create', + 'update', + 'delete', + 'read' + ] + } + ] + } } - }; + ], + primaryKeyInfo: { + isCustomPrimaryKey: false, + primaryKeyFieldName: 'id', + sortKeyFieldNames: [] + } + }; - const listMessagesReturnTypeName = `ModelConversationMessage${routeName}Connection` - const nonModelTypes: Record = { - [listMessagesReturnTypeName]: { - name: listMessagesReturnTypeName, - fields: { - items: { - isArray: true, + const route: SchemaConversationRoute = { + name: mutationObj.name, + models: { + [conversationModelName]: conversationModel, + [conversationMessageModelName]: conversationMessageModel + }, + nonModels: {}, + enums: { + ConversationMessageSender: { + name: 'ConversationMessageSender', + values: ['user', 'assistant'], + } + }, + conversation: { + modelName: conversationModelName + }, + message: { + modelName: conversationMessageModelName, + send: this.generateGraphQLOperationMetadata(mutationObj), + subscribe: { + isArray: false, + isRequired: false, + name: `onAssistantMessageResponse${routeName}`, + type: { model: `ConversationMessage${routeName}` }, + arguments: { + 'conversationId': { + name: 'conversationId', + isArray: false, isRequired: true, - name: 'items', - type: { - model: `ConversationMessage${routeName}` - }, + type: 'ID', }, - nextToken: { - isArray: false, - isRequired: false, - name: 'nextToken', - type: 'String', - } - }, + } } } + }; - const listMessagesInputName = `ModelConversationMessage${routeName}FilterInput`; - const inputs: CodeGenInputObjectMap = { - [listMessagesInputName]: { - name: listMessagesInputName, - inputValues: [ - { - name: 'conversationId', - type: 'ModelIdInput', - isList: false, - isNullable: true, - directives: [], - } - ], - type: 'input' - } - }; - - return { route, inputs }; + return route; } + protected getType(gqlType: string): FieldType | InputFieldType | UnionFieldType | InterfaceFieldType { - // Todo: Handle unlisted scalars - if (gqlType in METADATA_SCALAR_MAP) { - return METADATA_SCALAR_MAP[gqlType] as FieldType; - } - if (gqlType in this.enumMap) { - return { enum: this.enumMap[gqlType].name }; - } - if (gqlType in this.nonModelMap) { - return { nonModel: gqlType }; - } - if (gqlType in this.modelMap) { - return { model: gqlType }; - } - if (gqlType in this.inputObjectMap) { - return { input: gqlType } - } - if (gqlType in this.unionMap) { - return { union: gqlType } - } - if (gqlType in this.interfaceMap) { - return { interface: gqlType } - } - throw new Error(`Unknown type ${gqlType} found during model introspection schema generation`); + // Todo: Handle unlisted scalars + if (gqlType in METADATA_SCALAR_MAP) { + return METADATA_SCALAR_MAP[gqlType] as FieldType; + } + if (gqlType in this.enumMap) { + return { enum: this.enumMap[gqlType].name }; + } + if (gqlType in this.nonModelMap) { + return { nonModel: gqlType }; + } + if (gqlType in this.modelMap) { + return { model: gqlType }; + } + if (gqlType in this.inputObjectMap) { + return { input: gqlType } + } + if (gqlType in this.unionMap) { + return { union: gqlType } + } + if (gqlType in this.interfaceMap) { + return { interface: gqlType } } + throw new Error(`Unknown type ${gqlType} found during model introspection schema generation`); +} private generateModelPrimaryKeyInfo(model: CodeGenModel): PrimaryKeyInfo { - const primaryKeyField = this.getModelPrimaryKeyField(model); - if (primaryKeyField && primaryKeyField.primaryKeyInfo) { - const { primaryKeyType, sortKeyFields } = primaryKeyField.primaryKeyInfo; - return { - isCustomPrimaryKey: primaryKeyType === CodeGenPrimaryKeyType.CustomId, - primaryKeyFieldName: this.getFieldName(primaryKeyField), - sortKeyFieldNames: sortKeyFields.map(field => this.getFieldName(field)) - }; - } - throw new Error(`No primary key found for model ${model.name}`); + const primaryKeyField = this.getModelPrimaryKeyField(model); + if (primaryKeyField && primaryKeyField.primaryKeyInfo) { + const { primaryKeyType, sortKeyFields } = primaryKeyField.primaryKeyInfo; + return { + isCustomPrimaryKey: primaryKeyType === CodeGenPrimaryKeyType.CustomId, + primaryKeyFieldName: this.getFieldName(primaryKeyField), + sortKeyFieldNames: sortKeyFields.map(field => this.getFieldName(field)) + }; } + throw new Error(`No primary key found for model ${model.name}`); +} private isUnionFieldType = (obj: any): obj is UnionFieldType => { - return typeof obj === 'object' && typeof obj.union === 'string'; - } + return typeof obj === 'object' && typeof obj.union === 'string'; +} private isInterfaceFieldType = (obj: any): obj is InterfaceFieldType => { - return typeof obj === 'object' && typeof obj.interface === 'string'; - } + return typeof obj === 'object' && typeof obj.interface === 'string'; +} }