From abbe30b9cf6673d81d3254b4c4714956c20ce70a Mon Sep 17 00:00:00 2001 From: Aaron S Date: Tue, 22 Oct 2024 10:57:23 -0500 Subject: [PATCH] Updates from comments --- .../appsync-modelgen-plugin/src/preset.ts | 21 + .../appsync-modelgen-plugin/src/types/sync.ts | 24 +- .../__snapshots__/models.test.ts.snap | 6588 +++++++++++++++++ .../src/__tests__/models.test.ts | 33 +- 4 files changed, 6640 insertions(+), 26 deletions(-) diff --git a/packages/appsync-modelgen-plugin/src/preset.ts b/packages/appsync-modelgen-plugin/src/preset.ts index 267342d4..549ee1da 100644 --- a/packages/appsync-modelgen-plugin/src/preset.ts +++ b/packages/appsync-modelgen-plugin/src/preset.ts @@ -32,6 +32,16 @@ export type AppSyncModelCodeGenPresetConfig = { isDataStoreEnabled?: boolean; }; +/** + * NOTE: The different codegen target presets restructure the options to meet the needs of the target plugin + * None of this remapping interacts with the pluginMap or cache interface, so we can reuse all logic if we strip out + * the pluginMap and cache, then re-introduce them in the returned preset. + */ + +/** + * Internal types that represent the options without the pluginMap and cache, which we will use in each of our + * target preset option construction implementations + */ type GenerateOptions = Omit; type PresetFnArgs = Omit, 'cache' | 'pluginMap'>; @@ -351,13 +361,18 @@ const buildGenerations = (options: PresetFnArgs): GenerateOptions[] => { } }; + + /** * @internal + * The presetSync interface uses our SyncTypes __without__ promise/async typing */ export const presetSync: SyncTypes.OutputPreset = { buildGeneratesSection: (options: SyncTypes.PresetFnArgs): SyncTypes.GenerateOptions[] => { + // Extract cache and pluginMap from the options const {cache, pluginMap, ...otherOptions} = options; + // Generate the list of options and re-introduce the pluginMap and cache return buildGenerations(otherOptions).map((config: GenerateOptions) => ({ pluginMap, cache, @@ -366,10 +381,16 @@ export const presetSync: SyncTypes.OutputPreset } } +/** + * @internal + * The preset interface uses the @graphql-codegen/core interfaces __with__ promise/async typing + */ export const preset: Types.OutputPreset = { buildGeneratesSection: (options: Types.PresetFnArgs): Types.GenerateOptions[] => { + // Extract cache and pluginMap from the options const {cache, pluginMap, ...otherOptions} = options; + // Generate the list of options and re-introduce the pluginMap and cache return buildGenerations(otherOptions).map((config: GenerateOptions) => ({ pluginMap, cache, diff --git a/packages/appsync-modelgen-plugin/src/types/sync.ts b/packages/appsync-modelgen-plugin/src/types/sync.ts index 550d83ad..99c61a22 100644 --- a/packages/appsync-modelgen-plugin/src/types/sync.ts +++ b/packages/appsync-modelgen-plugin/src/types/sync.ts @@ -3,17 +3,27 @@ import { Types, PluginFunction as PluginFunctionAsync, CodegenPlugin as CodegenP type PluginMapContainer = Pick; type CacheContainer = Pick; -export type SyncPluginMap = Omit & { +/** + * SyncPluginMap replaces the plugin function return type for all plugins in the plugin map + * The object attribute we need to operate on is: Obj['pluginMap'][string]['plugin'] + * Use Omit to remove and & to replace each object layer + */ +type SyncPluginMap = Omit & { pluginMap: { - [name: string]: Omit & { - plugin: ( - ...args: Parameters - ) => Awaited>; - }; + [K in keyof Obj['pluginMap']]: Omit & { + plugin: ( + ...args: Parameters + ) => Awaited>; + } }; }; -export type SyncCache = Omit & { +/** + * SyncCache replaces the cache function return type + * The object attribute we need to operate on is: Obj['cache'] + * Use Omit to remove and & to replace the object layer + */ +type SyncCache = Omit & { cache?: ((namespace: string, key: string, factory: () => T) => T) | undefined }; diff --git a/packages/graphql-generator/src/__tests__/__snapshots__/models.test.ts.snap b/packages/graphql-generator/src/__tests__/__snapshots__/models.test.ts.snap index 20b0de51..ae4f2cd6 100644 --- a/packages/graphql-generator/src/__tests__/__snapshots__/models.test.ts.snap +++ b/packages/graphql-generator/src/__tests__/__snapshots__/models.test.ts.snap @@ -3294,6 +3294,6594 @@ public struct Post: Model { } `; +exports[`generateModels with does not fail on custom directives 1`] = ` +Object { + "model-introspection.json": "{ + \\"version\\": 1, + \\"models\\": {}, + \\"enums\\": {}, + \\"nonModels\\": { + \\"Blog\\": { + \\"name\\": \\"Blog\\", + \\"fields\\": { + \\"id\\": { + \\"name\\": \\"id\\", + \\"isArray\\": false, + \\"type\\": \\"ID\\", + \\"isRequired\\": true, + \\"attributes\\": [] + }, + \\"name\\": { + \\"name\\": \\"name\\", + \\"isArray\\": false, + \\"type\\": \\"String\\", + \\"isRequired\\": true, + \\"attributes\\": [] + } + } + } + } +}", +} +`; + +exports[`generateModels with does not fail on custom directives 2`] = ` +Object { + "model-introspection.json": "{ + \\"version\\": 1, + \\"models\\": {}, + \\"enums\\": {}, + \\"nonModels\\": { + \\"Blog\\": { + \\"name\\": \\"Blog\\", + \\"fields\\": { + \\"id\\": { + \\"name\\": \\"id\\", + \\"isArray\\": false, + \\"type\\": \\"ID\\", + \\"isRequired\\": true, + \\"attributes\\": [] + }, + \\"name\\": { + \\"name\\": \\"name\\", + \\"isArray\\": false, + \\"type\\": \\"String\\", + \\"isRequired\\": true, + \\"attributes\\": [] + } + } + } + } +}", +} +`; + +exports[`generateModels with improve pluralization swift 1`] = ` +Object { + "AmplifyModels.swift": "// swiftlint:disable all +import Amplify +import Foundation + +// Contains the set of classes that conforms to the \`Model\` protocol. + +final public class AmplifyModels: AmplifyModelRegistration { + public let version: String = \\"165944a36979cd395e3b22145bbfeff0\\" + + public func registerModels(registry: ModelRegistry.Type) { + ModelRegistry.register(modelType: Blog.self) + ModelRegistry.register(modelType: Post.self) + ModelRegistry.register(modelType: Comment.self) + } +}", + "Blog+Schema.swift": "// swiftlint:disable all +import Amplify +import Foundation + +extension Blog { + // MARK: - CodingKeys + public enum CodingKeys: String, ModelKey { + case id + case name + case posts + case createdAt + case updatedAt + } + + public static let keys = CodingKeys.self + // MARK: - ModelSchema + + public static let schema = defineSchema { model in + let blog = Blog.keys + + model.listPluralName = \\"Blogs\\" + model.syncPluralName = \\"Blogs\\" + + model.attributes( + .primaryKey(fields: [blog.id]) + ) + + model.fields( + .field(blog.id, is: .required, ofType: .string), + .field(blog.name, is: .required, ofType: .string), + .hasMany(blog.posts, is: .optional, ofType: Post.self, associatedWith: Post.keys.blog), + .field(blog.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime), + .field(blog.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime) + ) + } + public class Path: ModelPath { } + + public static var rootPath: PropertyContainerPath? { Path() } +} + +extension Blog: ModelIdentifiable { + public typealias IdentifierFormat = ModelIdentifierFormat.Default + public typealias IdentifierProtocol = DefaultModelIdentifier +} +extension ModelPath where ModelType == Blog { + public var id: FieldPath { + string(\\"id\\") + } + public var name: FieldPath { + string(\\"name\\") + } + public var posts: ModelPath { + Post.Path(name: \\"posts\\", isCollection: true, parent: self) + } + public var createdAt: FieldPath { + datetime(\\"createdAt\\") + } + public var updatedAt: FieldPath { + datetime(\\"updatedAt\\") + } +}", + "Blog.swift": "// swiftlint:disable all +import Amplify +import Foundation + +public struct Blog: Model { + public let id: String + public var name: String + public var posts: List? + public var createdAt: Temporal.DateTime? + public var updatedAt: Temporal.DateTime? + + public init(id: String = UUID().uuidString, + name: String, + posts: List? = []) { + self.init(id: id, + name: name, + posts: posts, + createdAt: nil, + updatedAt: nil) + } + internal init(id: String = UUID().uuidString, + name: String, + posts: List? = [], + createdAt: Temporal.DateTime? = nil, + updatedAt: Temporal.DateTime? = nil) { + self.id = id + self.name = name + self.posts = posts + self.createdAt = createdAt + self.updatedAt = updatedAt + } +}", + "Comment+Schema.swift": "// swiftlint:disable all +import Amplify +import Foundation + +extension Comment { + // MARK: - CodingKeys + public enum CodingKeys: String, ModelKey { + case id + case post + case content + case createdAt + case updatedAt + } + + public static let keys = CodingKeys.self + // MARK: - ModelSchema + + public static let schema = defineSchema { model in + let comment = Comment.keys + + model.listPluralName = \\"Comments\\" + model.syncPluralName = \\"Comments\\" + + model.attributes( + .primaryKey(fields: [comment.id]) + ) + + model.fields( + .field(comment.id, is: .required, ofType: .string), + .belongsTo(comment.post, is: .optional, ofType: Post.self, targetNames: [\\"postCommentsId\\"]), + .field(comment.content, is: .required, ofType: .string), + .field(comment.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime), + .field(comment.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime) + ) + } + public class Path: ModelPath { } + + public static var rootPath: PropertyContainerPath? { Path() } +} + +extension Comment: ModelIdentifiable { + public typealias IdentifierFormat = ModelIdentifierFormat.Default + public typealias IdentifierProtocol = DefaultModelIdentifier +} +extension ModelPath where ModelType == Comment { + public var id: FieldPath { + string(\\"id\\") + } + public var post: ModelPath { + Post.Path(name: \\"post\\", parent: self) + } + public var content: FieldPath { + string(\\"content\\") + } + public var createdAt: FieldPath { + datetime(\\"createdAt\\") + } + public var updatedAt: FieldPath { + datetime(\\"updatedAt\\") + } +}", + "Comment.swift": "// swiftlint:disable all +import Amplify +import Foundation + +public struct Comment: Model { + public let id: String + internal var _post: LazyReference + public var post: Post? { + get async throws { + try await _post.get() + } + } + public var content: String + public var createdAt: Temporal.DateTime? + public var updatedAt: Temporal.DateTime? + + public init(id: String = UUID().uuidString, + post: Post? = nil, + content: String) { + self.init(id: id, + post: post, + content: content, + createdAt: nil, + updatedAt: nil) + } + internal init(id: String = UUID().uuidString, + post: Post? = nil, + content: String, + createdAt: Temporal.DateTime? = nil, + updatedAt: Temporal.DateTime? = nil) { + self.id = id + self._post = LazyReference(post) + self.content = content + self.createdAt = createdAt + self.updatedAt = updatedAt + } + public mutating func setPost(_ post: Post? = nil) { + self._post = LazyReference(post) + } + public init(from decoder: Decoder) throws { + let values = try decoder.container(keyedBy: CodingKeys.self) + id = try values.decode(String.self, forKey: .id) + _post = try values.decodeIfPresent(LazyReference.self, forKey: .post) ?? LazyReference(identifiers: nil) + content = try values.decode(String.self, forKey: .content) + createdAt = try? values.decode(Temporal.DateTime?.self, forKey: .createdAt) + updatedAt = try? values.decode(Temporal.DateTime?.self, forKey: .updatedAt) + } + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(id, forKey: .id) + try container.encode(_post, forKey: .post) + try container.encode(content, forKey: .content) + try container.encode(createdAt, forKey: .createdAt) + try container.encode(updatedAt, forKey: .updatedAt) + } +}", + "Post+Schema.swift": "// swiftlint:disable all +import Amplify +import Foundation + +extension Post { + // MARK: - CodingKeys + public enum CodingKeys: String, ModelKey { + case id + case title + case blog + case comments + case createdAt + case updatedAt + } + + public static let keys = CodingKeys.self + // MARK: - ModelSchema + + public static let schema = defineSchema { model in + let post = Post.keys + + model.listPluralName = \\"Posts\\" + model.syncPluralName = \\"Posts\\" + + model.attributes( + .primaryKey(fields: [post.id]) + ) + + model.fields( + .field(post.id, is: .required, ofType: .string), + .field(post.title, is: .required, ofType: .string), + .belongsTo(post.blog, is: .optional, ofType: Blog.self, targetNames: [\\"blogPostsId\\"]), + .hasMany(post.comments, is: .optional, ofType: Comment.self, associatedWith: Comment.keys.post), + .field(post.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime), + .field(post.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime) + ) + } + public class Path: ModelPath { } + + public static var rootPath: PropertyContainerPath? { Path() } +} + +extension Post: ModelIdentifiable { + public typealias IdentifierFormat = ModelIdentifierFormat.Default + public typealias IdentifierProtocol = DefaultModelIdentifier +} +extension ModelPath where ModelType == Post { + public var id: FieldPath { + string(\\"id\\") + } + public var title: FieldPath { + string(\\"title\\") + } + public var blog: ModelPath { + Blog.Path(name: \\"blog\\", parent: self) + } + public var comments: ModelPath { + Comment.Path(name: \\"comments\\", isCollection: true, parent: self) + } + public var createdAt: FieldPath { + datetime(\\"createdAt\\") + } + public var updatedAt: FieldPath { + datetime(\\"updatedAt\\") + } +}", + "Post.swift": "// swiftlint:disable all +import Amplify +import Foundation + +public struct Post: Model { + public let id: String + public var title: String + internal var _blog: LazyReference + public var blog: Blog? { + get async throws { + try await _blog.get() + } + } + public var comments: List? + public var createdAt: Temporal.DateTime? + public var updatedAt: Temporal.DateTime? + + public init(id: String = UUID().uuidString, + title: String, + blog: Blog? = nil, + comments: List? = []) { + self.init(id: id, + title: title, + blog: blog, + comments: comments, + createdAt: nil, + updatedAt: nil) + } + internal init(id: String = UUID().uuidString, + title: String, + blog: Blog? = nil, + comments: List? = [], + createdAt: Temporal.DateTime? = nil, + updatedAt: Temporal.DateTime? = nil) { + self.id = id + self.title = title + self._blog = LazyReference(blog) + self.comments = comments + self.createdAt = createdAt + self.updatedAt = updatedAt + } + public mutating func setBlog(_ blog: Blog? = nil) { + self._blog = LazyReference(blog) + } + public init(from decoder: Decoder) throws { + let values = try decoder.container(keyedBy: CodingKeys.self) + id = try values.decode(String.self, forKey: .id) + title = try values.decode(String.self, forKey: .title) + _blog = try values.decodeIfPresent(LazyReference.self, forKey: .blog) ?? LazyReference(identifiers: nil) + comments = try values.decodeIfPresent(List?.self, forKey: .comments) ?? .init() + createdAt = try? values.decode(Temporal.DateTime?.self, forKey: .createdAt) + updatedAt = try? values.decode(Temporal.DateTime?.self, forKey: .updatedAt) + } + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(id, forKey: .id) + try container.encode(title, forKey: .title) + try container.encode(_blog, forKey: .blog) + try container.encode(comments, forKey: .comments) + try container.encode(createdAt, forKey: .createdAt) + try container.encode(updatedAt, forKey: .updatedAt) + } +}", +} +`; + +exports[`generateModels with improve pluralization swift 2`] = ` +Object { + "AmplifyModels.swift": "// swiftlint:disable all +import Amplify +import Foundation + +// Contains the set of classes that conforms to the \`Model\` protocol. + +final public class AmplifyModels: AmplifyModelRegistration { + public let version: String = \\"165944a36979cd395e3b22145bbfeff0\\" + + public func registerModels(registry: ModelRegistry.Type) { + ModelRegistry.register(modelType: Blog.self) + ModelRegistry.register(modelType: Post.self) + ModelRegistry.register(modelType: Comment.self) + } +}", + "Blog+Schema.swift": "// swiftlint:disable all +import Amplify +import Foundation + +extension Blog { + // MARK: - CodingKeys + public enum CodingKeys: String, ModelKey { + case id + case name + case posts + case createdAt + case updatedAt + } + + public static let keys = CodingKeys.self + // MARK: - ModelSchema + + public static let schema = defineSchema { model in + let blog = Blog.keys + + model.listPluralName = \\"Blogs\\" + model.syncPluralName = \\"Blogs\\" + + model.attributes( + .primaryKey(fields: [blog.id]) + ) + + model.fields( + .field(blog.id, is: .required, ofType: .string), + .field(blog.name, is: .required, ofType: .string), + .hasMany(blog.posts, is: .optional, ofType: Post.self, associatedWith: Post.keys.blog), + .field(blog.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime), + .field(blog.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime) + ) + } + public class Path: ModelPath { } + + public static var rootPath: PropertyContainerPath? { Path() } +} + +extension Blog: ModelIdentifiable { + public typealias IdentifierFormat = ModelIdentifierFormat.Default + public typealias IdentifierProtocol = DefaultModelIdentifier +} +extension ModelPath where ModelType == Blog { + public var id: FieldPath { + string(\\"id\\") + } + public var name: FieldPath { + string(\\"name\\") + } + public var posts: ModelPath { + Post.Path(name: \\"posts\\", isCollection: true, parent: self) + } + public var createdAt: FieldPath { + datetime(\\"createdAt\\") + } + public var updatedAt: FieldPath { + datetime(\\"updatedAt\\") + } +}", + "Blog.swift": "// swiftlint:disable all +import Amplify +import Foundation + +public struct Blog: Model { + public let id: String + public var name: String + public var posts: List? + public var createdAt: Temporal.DateTime? + public var updatedAt: Temporal.DateTime? + + public init(id: String = UUID().uuidString, + name: String, + posts: List? = []) { + self.init(id: id, + name: name, + posts: posts, + createdAt: nil, + updatedAt: nil) + } + internal init(id: String = UUID().uuidString, + name: String, + posts: List? = [], + createdAt: Temporal.DateTime? = nil, + updatedAt: Temporal.DateTime? = nil) { + self.id = id + self.name = name + self.posts = posts + self.createdAt = createdAt + self.updatedAt = updatedAt + } +}", + "Comment+Schema.swift": "// swiftlint:disable all +import Amplify +import Foundation + +extension Comment { + // MARK: - CodingKeys + public enum CodingKeys: String, ModelKey { + case id + case post + case content + case createdAt + case updatedAt + } + + public static let keys = CodingKeys.self + // MARK: - ModelSchema + + public static let schema = defineSchema { model in + let comment = Comment.keys + + model.listPluralName = \\"Comments\\" + model.syncPluralName = \\"Comments\\" + + model.attributes( + .primaryKey(fields: [comment.id]) + ) + + model.fields( + .field(comment.id, is: .required, ofType: .string), + .belongsTo(comment.post, is: .optional, ofType: Post.self, targetNames: [\\"postCommentsId\\"]), + .field(comment.content, is: .required, ofType: .string), + .field(comment.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime), + .field(comment.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime) + ) + } + public class Path: ModelPath { } + + public static var rootPath: PropertyContainerPath? { Path() } +} + +extension Comment: ModelIdentifiable { + public typealias IdentifierFormat = ModelIdentifierFormat.Default + public typealias IdentifierProtocol = DefaultModelIdentifier +} +extension ModelPath where ModelType == Comment { + public var id: FieldPath { + string(\\"id\\") + } + public var post: ModelPath { + Post.Path(name: \\"post\\", parent: self) + } + public var content: FieldPath { + string(\\"content\\") + } + public var createdAt: FieldPath { + datetime(\\"createdAt\\") + } + public var updatedAt: FieldPath { + datetime(\\"updatedAt\\") + } +}", + "Comment.swift": "// swiftlint:disable all +import Amplify +import Foundation + +public struct Comment: Model { + public let id: String + internal var _post: LazyReference + public var post: Post? { + get async throws { + try await _post.get() + } + } + public var content: String + public var createdAt: Temporal.DateTime? + public var updatedAt: Temporal.DateTime? + + public init(id: String = UUID().uuidString, + post: Post? = nil, + content: String) { + self.init(id: id, + post: post, + content: content, + createdAt: nil, + updatedAt: nil) + } + internal init(id: String = UUID().uuidString, + post: Post? = nil, + content: String, + createdAt: Temporal.DateTime? = nil, + updatedAt: Temporal.DateTime? = nil) { + self.id = id + self._post = LazyReference(post) + self.content = content + self.createdAt = createdAt + self.updatedAt = updatedAt + } + public mutating func setPost(_ post: Post? = nil) { + self._post = LazyReference(post) + } + public init(from decoder: Decoder) throws { + let values = try decoder.container(keyedBy: CodingKeys.self) + id = try values.decode(String.self, forKey: .id) + _post = try values.decodeIfPresent(LazyReference.self, forKey: .post) ?? LazyReference(identifiers: nil) + content = try values.decode(String.self, forKey: .content) + createdAt = try? values.decode(Temporal.DateTime?.self, forKey: .createdAt) + updatedAt = try? values.decode(Temporal.DateTime?.self, forKey: .updatedAt) + } + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(id, forKey: .id) + try container.encode(_post, forKey: .post) + try container.encode(content, forKey: .content) + try container.encode(createdAt, forKey: .createdAt) + try container.encode(updatedAt, forKey: .updatedAt) + } +}", + "Post+Schema.swift": "// swiftlint:disable all +import Amplify +import Foundation + +extension Post { + // MARK: - CodingKeys + public enum CodingKeys: String, ModelKey { + case id + case title + case blog + case comments + case createdAt + case updatedAt + } + + public static let keys = CodingKeys.self + // MARK: - ModelSchema + + public static let schema = defineSchema { model in + let post = Post.keys + + model.listPluralName = \\"Posts\\" + model.syncPluralName = \\"Posts\\" + + model.attributes( + .primaryKey(fields: [post.id]) + ) + + model.fields( + .field(post.id, is: .required, ofType: .string), + .field(post.title, is: .required, ofType: .string), + .belongsTo(post.blog, is: .optional, ofType: Blog.self, targetNames: [\\"blogPostsId\\"]), + .hasMany(post.comments, is: .optional, ofType: Comment.self, associatedWith: Comment.keys.post), + .field(post.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime), + .field(post.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime) + ) + } + public class Path: ModelPath { } + + public static var rootPath: PropertyContainerPath? { Path() } +} + +extension Post: ModelIdentifiable { + public typealias IdentifierFormat = ModelIdentifierFormat.Default + public typealias IdentifierProtocol = DefaultModelIdentifier +} +extension ModelPath where ModelType == Post { + public var id: FieldPath { + string(\\"id\\") + } + public var title: FieldPath { + string(\\"title\\") + } + public var blog: ModelPath { + Blog.Path(name: \\"blog\\", parent: self) + } + public var comments: ModelPath { + Comment.Path(name: \\"comments\\", isCollection: true, parent: self) + } + public var createdAt: FieldPath { + datetime(\\"createdAt\\") + } + public var updatedAt: FieldPath { + datetime(\\"updatedAt\\") + } +}", + "Post.swift": "// swiftlint:disable all +import Amplify +import Foundation + +public struct Post: Model { + public let id: String + public var title: String + internal var _blog: LazyReference + public var blog: Blog? { + get async throws { + try await _blog.get() + } + } + public var comments: List? + public var createdAt: Temporal.DateTime? + public var updatedAt: Temporal.DateTime? + + public init(id: String = UUID().uuidString, + title: String, + blog: Blog? = nil, + comments: List? = []) { + self.init(id: id, + title: title, + blog: blog, + comments: comments, + createdAt: nil, + updatedAt: nil) + } + internal init(id: String = UUID().uuidString, + title: String, + blog: Blog? = nil, + comments: List? = [], + createdAt: Temporal.DateTime? = nil, + updatedAt: Temporal.DateTime? = nil) { + self.id = id + self.title = title + self._blog = LazyReference(blog) + self.comments = comments + self.createdAt = createdAt + self.updatedAt = updatedAt + } + public mutating func setBlog(_ blog: Blog? = nil) { + self._blog = LazyReference(blog) + } + public init(from decoder: Decoder) throws { + let values = try decoder.container(keyedBy: CodingKeys.self) + id = try values.decode(String.self, forKey: .id) + title = try values.decode(String.self, forKey: .title) + _blog = try values.decodeIfPresent(LazyReference.self, forKey: .blog) ?? LazyReference(identifiers: nil) + comments = try values.decodeIfPresent(List?.self, forKey: .comments) ?? .init() + createdAt = try? values.decode(Temporal.DateTime?.self, forKey: .createdAt) + updatedAt = try? values.decode(Temporal.DateTime?.self, forKey: .updatedAt) + } + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(id, forKey: .id) + try container.encode(title, forKey: .title) + try container.encode(_blog, forKey: .blog) + try container.encode(comments, forKey: .comments) + try container.encode(createdAt, forKey: .createdAt) + try container.encode(updatedAt, forKey: .updatedAt) + } +}", +} +`; + +exports[`generateModels with targets basic 1`] = ` +Object { + "com/amplifyframework/datastore/generated/model/AmplifyModelProvider.java": "package com.amplifyframework.datastore.generated.model; + +import com.amplifyframework.util.Immutable; +import com.amplifyframework.core.model.Model; +import com.amplifyframework.core.model.ModelProvider; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; +/** + * Contains the set of model classes that implement {@link Model} + * interface. + */ + +public final class AmplifyModelProvider implements ModelProvider { + private static final String AMPLIFY_MODEL_VERSION = \\"165944a36979cd395e3b22145bbfeff0\\"; + private static AmplifyModelProvider amplifyGeneratedModelInstance; + private AmplifyModelProvider() { + + } + + public static synchronized AmplifyModelProvider getInstance() { + if (amplifyGeneratedModelInstance == null) { + amplifyGeneratedModelInstance = new AmplifyModelProvider(); + } + return amplifyGeneratedModelInstance; + } + + /** + * Get a set of the model classes. + * + * @return a set of the model classes. + */ + @Override + public Set> models() { + final Set> modifiableSet = new HashSet<>( + Arrays.>asList(Blog.class, Post.class, Comment.class) + ); + + return Immutable.of(modifiableSet); + + } + + /** + * Get the version of the models. + * + * @return the version string of the models. + */ + @Override + public String version() { + return AMPLIFY_MODEL_VERSION; + } +} +", + "com/amplifyframework/datastore/generated/model/Blog.java": "package com.amplifyframework.datastore.generated.model; + +import com.amplifyframework.core.model.annotations.HasMany; +import com.amplifyframework.core.model.ModelList; +import com.amplifyframework.core.model.temporal.Temporal; +import com.amplifyframework.core.model.ModelIdentifier; + +import java.util.List; +import java.util.UUID; +import java.util.Objects; + +import androidx.core.util.ObjectsCompat; + +import com.amplifyframework.core.model.Model; +import com.amplifyframework.core.model.annotations.Index; +import com.amplifyframework.core.model.annotations.ModelConfig; +import com.amplifyframework.core.model.annotations.ModelField; +import com.amplifyframework.core.model.query.predicate.QueryField; + +import static com.amplifyframework.core.model.query.predicate.QueryField.field; + +/** This is an auto generated class representing the Blog type in your schema. */ +@SuppressWarnings(\\"all\\") +@ModelConfig(pluralName = \\"Blogs\\", type = Model.Type.USER, version = 1, hasLazySupport = true) +public final class Blog implements Model { + public static final BlogPath rootPath = new BlogPath(\\"root\\", false, null); + public static final QueryField ID = field(\\"Blog\\", \\"id\\"); + public static final QueryField NAME = field(\\"Blog\\", \\"name\\"); + private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; + private final @ModelField(targetType=\\"String\\", isRequired = true) String name; + private final @ModelField(targetType=\\"Post\\") @HasMany(associatedWith = \\"blog\\", type = Post.class) ModelList posts = null; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; + /** @deprecated This API is internal to Amplify and should not be used. */ + @Deprecated + public String resolveIdentifier() { + return id; + } + + public String getId() { + return id; + } + + public String getName() { + return name; + } + + public ModelList getPosts() { + return posts; + } + + public Temporal.DateTime getCreatedAt() { + return createdAt; + } + + public Temporal.DateTime getUpdatedAt() { + return updatedAt; + } + + private Blog(String id, String name) { + this.id = id; + this.name = name; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if(obj == null || getClass() != obj.getClass()) { + return false; + } else { + Blog blog = (Blog) obj; + return ObjectsCompat.equals(getId(), blog.getId()) && + ObjectsCompat.equals(getName(), blog.getName()) && + ObjectsCompat.equals(getCreatedAt(), blog.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), blog.getUpdatedAt()); + } + } + + @Override + public int hashCode() { + return new StringBuilder() + .append(getId()) + .append(getName()) + .append(getCreatedAt()) + .append(getUpdatedAt()) + .toString() + .hashCode(); + } + + @Override + public String toString() { + return new StringBuilder() + .append(\\"Blog {\\") + .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") + .append(\\"name=\\" + String.valueOf(getName()) + \\", \\") + .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) + .append(\\"}\\") + .toString(); + } + + public static NameStep builder() { + return new Builder(); + } + + /** + * WARNING: This method should not be used to build an instance of this object for a CREATE mutation. + * This is a convenience method to return an instance of the object with only its ID populated + * to be used in the context of a parameter in a delete mutation or referencing a foreign key + * in a relationship. + * @param id the id of the existing item this instance will represent + * @return an instance of this model with only ID populated + */ + public static Blog justId(String id) { + return new Blog( + id, + null + ); + } + + public CopyOfBuilder copyOfBuilder() { + return new CopyOfBuilder(id, + name); + } + public interface NameStep { + BuildStep name(String name); + } + + + public interface BuildStep { + Blog build(); + BuildStep id(String id); + } + + + public static class Builder implements NameStep, BuildStep { + private String id; + private String name; + public Builder() { + + } + + private Builder(String id, String name) { + this.id = id; + this.name = name; + } + + @Override + public Blog build() { + String id = this.id != null ? this.id : UUID.randomUUID().toString(); + + return new Blog( + id, + name); + } + + @Override + public BuildStep name(String name) { + Objects.requireNonNull(name); + this.name = name; + return this; + } + + /** + * @param id id + * @return Current Builder instance, for fluent method chaining + */ + public BuildStep id(String id) { + this.id = id; + return this; + } + } + + + public final class CopyOfBuilder extends Builder { + private CopyOfBuilder(String id, String name) { + super(id, name); + Objects.requireNonNull(name); + } + + @Override + public CopyOfBuilder name(String name) { + return (CopyOfBuilder) super.name(name); + } + } + + + public static class BlogIdentifier extends ModelIdentifier { + private static final long serialVersionUID = 1L; + public BlogIdentifier(String id) { + super(id); + } + } + +} +", + "com/amplifyframework/datastore/generated/model/BlogPath.java": "package com.amplifyframework.datastore.generated.model; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import com.amplifyframework.core.model.ModelPath; +import com.amplifyframework.core.model.PropertyPath; + +/** This is an auto generated class representing the ModelPath for the Blog type in your schema. */ +public final class BlogPath extends ModelPath { + private PostPath posts; + BlogPath(@NonNull String name, @NonNull Boolean isCollection, @Nullable PropertyPath parent) { + super(name, isCollection, parent, Blog.class); + } + + public synchronized PostPath getPosts() { + if (posts == null) { + posts = new PostPath(\\"posts\\", true, this); + } + return posts; + } +} +", + "com/amplifyframework/datastore/generated/model/Comment.java": "package com.amplifyframework.datastore.generated.model; + +import com.amplifyframework.core.model.annotations.BelongsTo; +import com.amplifyframework.core.model.ModelReference; +import com.amplifyframework.core.model.LoadedModelReferenceImpl; +import com.amplifyframework.core.model.temporal.Temporal; +import com.amplifyframework.core.model.ModelIdentifier; + +import java.util.List; +import java.util.UUID; +import java.util.Objects; + +import androidx.core.util.ObjectsCompat; + +import com.amplifyframework.core.model.Model; +import com.amplifyframework.core.model.annotations.Index; +import com.amplifyframework.core.model.annotations.ModelConfig; +import com.amplifyframework.core.model.annotations.ModelField; +import com.amplifyframework.core.model.query.predicate.QueryField; + +import static com.amplifyframework.core.model.query.predicate.QueryField.field; + +/** This is an auto generated class representing the Comment type in your schema. */ +@SuppressWarnings(\\"all\\") +@ModelConfig(pluralName = \\"Comments\\", type = Model.Type.USER, version = 1, hasLazySupport = true) +public final class Comment implements Model { + public static final CommentPath rootPath = new CommentPath(\\"root\\", false, null); + public static final QueryField ID = field(\\"Comment\\", \\"id\\"); + public static final QueryField POST = field(\\"Comment\\", \\"postCommentsId\\"); + public static final QueryField CONTENT = field(\\"Comment\\", \\"content\\"); + private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; + private final @ModelField(targetType=\\"Post\\") @BelongsTo(targetName = \\"postCommentsId\\", targetNames = {\\"postCommentsId\\"}, type = Post.class) ModelReference post; + private final @ModelField(targetType=\\"String\\", isRequired = true) String content; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; + /** @deprecated This API is internal to Amplify and should not be used. */ + @Deprecated + public String resolveIdentifier() { + return id; + } + + public String getId() { + return id; + } + + public ModelReference getPost() { + return post; + } + + public String getContent() { + return content; + } + + public Temporal.DateTime getCreatedAt() { + return createdAt; + } + + public Temporal.DateTime getUpdatedAt() { + return updatedAt; + } + + private Comment(String id, ModelReference post, String content) { + this.id = id; + this.post = post; + this.content = content; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if(obj == null || getClass() != obj.getClass()) { + return false; + } else { + Comment comment = (Comment) obj; + return ObjectsCompat.equals(getId(), comment.getId()) && + ObjectsCompat.equals(getPost(), comment.getPost()) && + ObjectsCompat.equals(getContent(), comment.getContent()) && + ObjectsCompat.equals(getCreatedAt(), comment.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), comment.getUpdatedAt()); + } + } + + @Override + public int hashCode() { + return new StringBuilder() + .append(getId()) + .append(getPost()) + .append(getContent()) + .append(getCreatedAt()) + .append(getUpdatedAt()) + .toString() + .hashCode(); + } + + @Override + public String toString() { + return new StringBuilder() + .append(\\"Comment {\\") + .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") + .append(\\"post=\\" + String.valueOf(getPost()) + \\", \\") + .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") + .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) + .append(\\"}\\") + .toString(); + } + + public static ContentStep builder() { + return new Builder(); + } + + /** + * WARNING: This method should not be used to build an instance of this object for a CREATE mutation. + * This is a convenience method to return an instance of the object with only its ID populated + * to be used in the context of a parameter in a delete mutation or referencing a foreign key + * in a relationship. + * @param id the id of the existing item this instance will represent + * @return an instance of this model with only ID populated + */ + public static Comment justId(String id) { + return new Comment( + id, + null, + null + ); + } + + public CopyOfBuilder copyOfBuilder() { + return new CopyOfBuilder(id, + post, + content); + } + public interface ContentStep { + BuildStep content(String content); + } + + + public interface BuildStep { + Comment build(); + BuildStep id(String id); + BuildStep post(Post post); + } + + + public static class Builder implements ContentStep, BuildStep { + private String id; + private String content; + private ModelReference post; + public Builder() { + + } + + private Builder(String id, ModelReference post, String content) { + this.id = id; + this.post = post; + this.content = content; + } + + @Override + public Comment build() { + String id = this.id != null ? this.id : UUID.randomUUID().toString(); + + return new Comment( + id, + post, + content); + } + + @Override + public BuildStep content(String content) { + Objects.requireNonNull(content); + this.content = content; + return this; + } + + @Override + public BuildStep post(Post post) { + this.post = new LoadedModelReferenceImpl<>(post); + return this; + } + + /** + * @param id id + * @return Current Builder instance, for fluent method chaining + */ + public BuildStep id(String id) { + this.id = id; + return this; + } + } + + + public final class CopyOfBuilder extends Builder { + private CopyOfBuilder(String id, ModelReference post, String content) { + super(id, post, content); + Objects.requireNonNull(content); + } + + @Override + public CopyOfBuilder content(String content) { + return (CopyOfBuilder) super.content(content); + } + + @Override + public CopyOfBuilder post(Post post) { + return (CopyOfBuilder) super.post(post); + } + } + + + public static class CommentIdentifier extends ModelIdentifier { + private static final long serialVersionUID = 1L; + public CommentIdentifier(String id) { + super(id); + } + } + +} +", + "com/amplifyframework/datastore/generated/model/CommentPath.java": "package com.amplifyframework.datastore.generated.model; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import com.amplifyframework.core.model.ModelPath; +import com.amplifyframework.core.model.PropertyPath; + +/** This is an auto generated class representing the ModelPath for the Comment type in your schema. */ +public final class CommentPath extends ModelPath { + private PostPath post; + CommentPath(@NonNull String name, @NonNull Boolean isCollection, @Nullable PropertyPath parent) { + super(name, isCollection, parent, Comment.class); + } + + public synchronized PostPath getPost() { + if (post == null) { + post = new PostPath(\\"post\\", false, this); + } + return post; + } +} +", + "com/amplifyframework/datastore/generated/model/Post.java": "package com.amplifyframework.datastore.generated.model; + +import com.amplifyframework.core.model.annotations.BelongsTo; +import com.amplifyframework.core.model.ModelReference; +import com.amplifyframework.core.model.LoadedModelReferenceImpl; +import com.amplifyframework.core.model.annotations.HasMany; +import com.amplifyframework.core.model.ModelList; +import com.amplifyframework.core.model.temporal.Temporal; +import com.amplifyframework.core.model.ModelIdentifier; + +import java.util.List; +import java.util.UUID; +import java.util.Objects; + +import androidx.core.util.ObjectsCompat; + +import com.amplifyframework.core.model.Model; +import com.amplifyframework.core.model.annotations.Index; +import com.amplifyframework.core.model.annotations.ModelConfig; +import com.amplifyframework.core.model.annotations.ModelField; +import com.amplifyframework.core.model.query.predicate.QueryField; + +import static com.amplifyframework.core.model.query.predicate.QueryField.field; + +/** This is an auto generated class representing the Post type in your schema. */ +@SuppressWarnings(\\"all\\") +@ModelConfig(pluralName = \\"Posts\\", type = Model.Type.USER, version = 1, hasLazySupport = true) +public final class Post implements Model { + public static final PostPath rootPath = new PostPath(\\"root\\", false, null); + public static final QueryField ID = field(\\"Post\\", \\"id\\"); + public static final QueryField TITLE = field(\\"Post\\", \\"title\\"); + public static final QueryField BLOG = field(\\"Post\\", \\"blogPostsId\\"); + private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; + private final @ModelField(targetType=\\"String\\", isRequired = true) String title; + private final @ModelField(targetType=\\"Blog\\") @BelongsTo(targetName = \\"blogPostsId\\", targetNames = {\\"blogPostsId\\"}, type = Blog.class) ModelReference blog; + private final @ModelField(targetType=\\"Comment\\") @HasMany(associatedWith = \\"post\\", type = Comment.class) ModelList comments = null; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; + /** @deprecated This API is internal to Amplify and should not be used. */ + @Deprecated + public String resolveIdentifier() { + return id; + } + + public String getId() { + return id; + } + + public String getTitle() { + return title; + } + + public ModelReference getBlog() { + return blog; + } + + public ModelList getComments() { + return comments; + } + + public Temporal.DateTime getCreatedAt() { + return createdAt; + } + + public Temporal.DateTime getUpdatedAt() { + return updatedAt; + } + + private Post(String id, String title, ModelReference blog) { + this.id = id; + this.title = title; + this.blog = blog; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if(obj == null || getClass() != obj.getClass()) { + return false; + } else { + Post post = (Post) obj; + return ObjectsCompat.equals(getId(), post.getId()) && + ObjectsCompat.equals(getTitle(), post.getTitle()) && + ObjectsCompat.equals(getBlog(), post.getBlog()) && + ObjectsCompat.equals(getCreatedAt(), post.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), post.getUpdatedAt()); + } + } + + @Override + public int hashCode() { + return new StringBuilder() + .append(getId()) + .append(getTitle()) + .append(getBlog()) + .append(getCreatedAt()) + .append(getUpdatedAt()) + .toString() + .hashCode(); + } + + @Override + public String toString() { + return new StringBuilder() + .append(\\"Post {\\") + .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") + .append(\\"title=\\" + String.valueOf(getTitle()) + \\", \\") + .append(\\"blog=\\" + String.valueOf(getBlog()) + \\", \\") + .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) + .append(\\"}\\") + .toString(); + } + + public static TitleStep builder() { + return new Builder(); + } + + /** + * WARNING: This method should not be used to build an instance of this object for a CREATE mutation. + * This is a convenience method to return an instance of the object with only its ID populated + * to be used in the context of a parameter in a delete mutation or referencing a foreign key + * in a relationship. + * @param id the id of the existing item this instance will represent + * @return an instance of this model with only ID populated + */ + public static Post justId(String id) { + return new Post( + id, + null, + null + ); + } + + public CopyOfBuilder copyOfBuilder() { + return new CopyOfBuilder(id, + title, + blog); + } + public interface TitleStep { + BuildStep title(String title); + } + + + public interface BuildStep { + Post build(); + BuildStep id(String id); + BuildStep blog(Blog blog); + } + + + public static class Builder implements TitleStep, BuildStep { + private String id; + private String title; + private ModelReference blog; + public Builder() { + + } + + private Builder(String id, String title, ModelReference blog) { + this.id = id; + this.title = title; + this.blog = blog; + } + + @Override + public Post build() { + String id = this.id != null ? this.id : UUID.randomUUID().toString(); + + return new Post( + id, + title, + blog); + } + + @Override + public BuildStep title(String title) { + Objects.requireNonNull(title); + this.title = title; + return this; + } + + @Override + public BuildStep blog(Blog blog) { + this.blog = new LoadedModelReferenceImpl<>(blog); + return this; + } + + /** + * @param id id + * @return Current Builder instance, for fluent method chaining + */ + public BuildStep id(String id) { + this.id = id; + return this; + } + } + + + public final class CopyOfBuilder extends Builder { + private CopyOfBuilder(String id, String title, ModelReference blog) { + super(id, title, blog); + Objects.requireNonNull(title); + } + + @Override + public CopyOfBuilder title(String title) { + return (CopyOfBuilder) super.title(title); + } + + @Override + public CopyOfBuilder blog(Blog blog) { + return (CopyOfBuilder) super.blog(blog); + } + } + + + public static class PostIdentifier extends ModelIdentifier { + private static final long serialVersionUID = 1L; + public PostIdentifier(String id) { + super(id); + } + } + +} +", + "com/amplifyframework/datastore/generated/model/PostPath.java": "package com.amplifyframework.datastore.generated.model; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import com.amplifyframework.core.model.ModelPath; +import com.amplifyframework.core.model.PropertyPath; + +/** This is an auto generated class representing the ModelPath for the Post type in your schema. */ +public final class PostPath extends ModelPath { + private BlogPath blog; + private CommentPath comments; + PostPath(@NonNull String name, @NonNull Boolean isCollection, @Nullable PropertyPath parent) { + super(name, isCollection, parent, Post.class); + } + + public synchronized BlogPath getBlog() { + if (blog == null) { + blog = new BlogPath(\\"blog\\", false, this); + } + return blog; + } + + public synchronized CommentPath getComments() { + if (comments == null) { + comments = new CommentPath(\\"comments\\", true, this); + } + return comments; + } +} +", +} +`; + +exports[`generateModels with targets basic 2`] = ` +Object { + "AmplifyModels.swift": "// swiftlint:disable all +import Amplify +import Foundation + +// Contains the set of classes that conforms to the \`Model\` protocol. + +final public class AmplifyModels: AmplifyModelRegistration { + public let version: String = \\"165944a36979cd395e3b22145bbfeff0\\" + + public func registerModels(registry: ModelRegistry.Type) { + ModelRegistry.register(modelType: Blog.self) + ModelRegistry.register(modelType: Post.self) + ModelRegistry.register(modelType: Comment.self) + } +}", + "Blog+Schema.swift": "// swiftlint:disable all +import Amplify +import Foundation + +extension Blog { + // MARK: - CodingKeys + public enum CodingKeys: String, ModelKey { + case id + case name + case posts + case createdAt + case updatedAt + } + + public static let keys = CodingKeys.self + // MARK: - ModelSchema + + public static let schema = defineSchema { model in + let blog = Blog.keys + + model.listPluralName = \\"Blogs\\" + model.syncPluralName = \\"Blogs\\" + + model.attributes( + .primaryKey(fields: [blog.id]) + ) + + model.fields( + .field(blog.id, is: .required, ofType: .string), + .field(blog.name, is: .required, ofType: .string), + .hasMany(blog.posts, is: .optional, ofType: Post.self, associatedWith: Post.keys.blog), + .field(blog.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime), + .field(blog.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime) + ) + } + public class Path: ModelPath { } + + public static var rootPath: PropertyContainerPath? { Path() } +} + +extension Blog: ModelIdentifiable { + public typealias IdentifierFormat = ModelIdentifierFormat.Default + public typealias IdentifierProtocol = DefaultModelIdentifier +} +extension ModelPath where ModelType == Blog { + public var id: FieldPath { + string(\\"id\\") + } + public var name: FieldPath { + string(\\"name\\") + } + public var posts: ModelPath { + Post.Path(name: \\"posts\\", isCollection: true, parent: self) + } + public var createdAt: FieldPath { + datetime(\\"createdAt\\") + } + public var updatedAt: FieldPath { + datetime(\\"updatedAt\\") + } +}", + "Blog.swift": "// swiftlint:disable all +import Amplify +import Foundation + +public struct Blog: Model { + public let id: String + public var name: String + public var posts: List? + public var createdAt: Temporal.DateTime? + public var updatedAt: Temporal.DateTime? + + public init(id: String = UUID().uuidString, + name: String, + posts: List? = []) { + self.init(id: id, + name: name, + posts: posts, + createdAt: nil, + updatedAt: nil) + } + internal init(id: String = UUID().uuidString, + name: String, + posts: List? = [], + createdAt: Temporal.DateTime? = nil, + updatedAt: Temporal.DateTime? = nil) { + self.id = id + self.name = name + self.posts = posts + self.createdAt = createdAt + self.updatedAt = updatedAt + } +}", + "Comment+Schema.swift": "// swiftlint:disable all +import Amplify +import Foundation + +extension Comment { + // MARK: - CodingKeys + public enum CodingKeys: String, ModelKey { + case id + case post + case content + case createdAt + case updatedAt + } + + public static let keys = CodingKeys.self + // MARK: - ModelSchema + + public static let schema = defineSchema { model in + let comment = Comment.keys + + model.listPluralName = \\"Comments\\" + model.syncPluralName = \\"Comments\\" + + model.attributes( + .primaryKey(fields: [comment.id]) + ) + + model.fields( + .field(comment.id, is: .required, ofType: .string), + .belongsTo(comment.post, is: .optional, ofType: Post.self, targetNames: [\\"postCommentsId\\"]), + .field(comment.content, is: .required, ofType: .string), + .field(comment.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime), + .field(comment.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime) + ) + } + public class Path: ModelPath { } + + public static var rootPath: PropertyContainerPath? { Path() } +} + +extension Comment: ModelIdentifiable { + public typealias IdentifierFormat = ModelIdentifierFormat.Default + public typealias IdentifierProtocol = DefaultModelIdentifier +} +extension ModelPath where ModelType == Comment { + public var id: FieldPath { + string(\\"id\\") + } + public var post: ModelPath { + Post.Path(name: \\"post\\", parent: self) + } + public var content: FieldPath { + string(\\"content\\") + } + public var createdAt: FieldPath { + datetime(\\"createdAt\\") + } + public var updatedAt: FieldPath { + datetime(\\"updatedAt\\") + } +}", + "Comment.swift": "// swiftlint:disable all +import Amplify +import Foundation + +public struct Comment: Model { + public let id: String + internal var _post: LazyReference + public var post: Post? { + get async throws { + try await _post.get() + } + } + public var content: String + public var createdAt: Temporal.DateTime? + public var updatedAt: Temporal.DateTime? + + public init(id: String = UUID().uuidString, + post: Post? = nil, + content: String) { + self.init(id: id, + post: post, + content: content, + createdAt: nil, + updatedAt: nil) + } + internal init(id: String = UUID().uuidString, + post: Post? = nil, + content: String, + createdAt: Temporal.DateTime? = nil, + updatedAt: Temporal.DateTime? = nil) { + self.id = id + self._post = LazyReference(post) + self.content = content + self.createdAt = createdAt + self.updatedAt = updatedAt + } + public mutating func setPost(_ post: Post? = nil) { + self._post = LazyReference(post) + } + public init(from decoder: Decoder) throws { + let values = try decoder.container(keyedBy: CodingKeys.self) + id = try values.decode(String.self, forKey: .id) + _post = try values.decodeIfPresent(LazyReference.self, forKey: .post) ?? LazyReference(identifiers: nil) + content = try values.decode(String.self, forKey: .content) + createdAt = try? values.decode(Temporal.DateTime?.self, forKey: .createdAt) + updatedAt = try? values.decode(Temporal.DateTime?.self, forKey: .updatedAt) + } + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(id, forKey: .id) + try container.encode(_post, forKey: .post) + try container.encode(content, forKey: .content) + try container.encode(createdAt, forKey: .createdAt) + try container.encode(updatedAt, forKey: .updatedAt) + } +}", + "Post+Schema.swift": "// swiftlint:disable all +import Amplify +import Foundation + +extension Post { + // MARK: - CodingKeys + public enum CodingKeys: String, ModelKey { + case id + case title + case blog + case comments + case createdAt + case updatedAt + } + + public static let keys = CodingKeys.self + // MARK: - ModelSchema + + public static let schema = defineSchema { model in + let post = Post.keys + + model.listPluralName = \\"Posts\\" + model.syncPluralName = \\"Posts\\" + + model.attributes( + .primaryKey(fields: [post.id]) + ) + + model.fields( + .field(post.id, is: .required, ofType: .string), + .field(post.title, is: .required, ofType: .string), + .belongsTo(post.blog, is: .optional, ofType: Blog.self, targetNames: [\\"blogPostsId\\"]), + .hasMany(post.comments, is: .optional, ofType: Comment.self, associatedWith: Comment.keys.post), + .field(post.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime), + .field(post.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime) + ) + } + public class Path: ModelPath { } + + public static var rootPath: PropertyContainerPath? { Path() } +} + +extension Post: ModelIdentifiable { + public typealias IdentifierFormat = ModelIdentifierFormat.Default + public typealias IdentifierProtocol = DefaultModelIdentifier +} +extension ModelPath where ModelType == Post { + public var id: FieldPath { + string(\\"id\\") + } + public var title: FieldPath { + string(\\"title\\") + } + public var blog: ModelPath { + Blog.Path(name: \\"blog\\", parent: self) + } + public var comments: ModelPath { + Comment.Path(name: \\"comments\\", isCollection: true, parent: self) + } + public var createdAt: FieldPath { + datetime(\\"createdAt\\") + } + public var updatedAt: FieldPath { + datetime(\\"updatedAt\\") + } +}", + "Post.swift": "// swiftlint:disable all +import Amplify +import Foundation + +public struct Post: Model { + public let id: String + public var title: String + internal var _blog: LazyReference + public var blog: Blog? { + get async throws { + try await _blog.get() + } + } + public var comments: List? + public var createdAt: Temporal.DateTime? + public var updatedAt: Temporal.DateTime? + + public init(id: String = UUID().uuidString, + title: String, + blog: Blog? = nil, + comments: List? = []) { + self.init(id: id, + title: title, + blog: blog, + comments: comments, + createdAt: nil, + updatedAt: nil) + } + internal init(id: String = UUID().uuidString, + title: String, + blog: Blog? = nil, + comments: List? = [], + createdAt: Temporal.DateTime? = nil, + updatedAt: Temporal.DateTime? = nil) { + self.id = id + self.title = title + self._blog = LazyReference(blog) + self.comments = comments + self.createdAt = createdAt + self.updatedAt = updatedAt + } + public mutating func setBlog(_ blog: Blog? = nil) { + self._blog = LazyReference(blog) + } + public init(from decoder: Decoder) throws { + let values = try decoder.container(keyedBy: CodingKeys.self) + id = try values.decode(String.self, forKey: .id) + title = try values.decode(String.self, forKey: .title) + _blog = try values.decodeIfPresent(LazyReference.self, forKey: .blog) ?? LazyReference(identifiers: nil) + comments = try values.decodeIfPresent(List?.self, forKey: .comments) ?? .init() + createdAt = try? values.decode(Temporal.DateTime?.self, forKey: .createdAt) + updatedAt = try? values.decode(Temporal.DateTime?.self, forKey: .updatedAt) + } + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(id, forKey: .id) + try container.encode(title, forKey: .title) + try container.encode(_blog, forKey: .blog) + try container.encode(comments, forKey: .comments) + try container.encode(createdAt, forKey: .createdAt) + try container.encode(updatedAt, forKey: .updatedAt) + } +}", +} +`; + +exports[`generateModels with targets basic 3`] = ` +Object { + "index.d.ts": "import { ModelInit, MutableModel, __modelMeta__, ManagedIdentifier } from \\"@aws-amplify/datastore\\"; +// @ts-ignore +import { LazyLoading, LazyLoadingDisabled, AsyncCollection, AsyncItem } from \\"@aws-amplify/datastore\\"; + + + + + +type EagerBlog = { + readonly [__modelMeta__]: { + identifier: ManagedIdentifier; + readOnlyFields: 'createdAt' | 'updatedAt'; + }; + readonly id: string; + readonly name: string; + readonly posts?: (Post | null)[] | null; + readonly createdAt?: string | null; + readonly updatedAt?: string | null; +} + +type LazyBlog = { + readonly [__modelMeta__]: { + identifier: ManagedIdentifier; + readOnlyFields: 'createdAt' | 'updatedAt'; + }; + readonly id: string; + readonly name: string; + readonly posts: AsyncCollection; + readonly createdAt?: string | null; + readonly updatedAt?: string | null; +} + +export declare type Blog = LazyLoading extends LazyLoadingDisabled ? EagerBlog : LazyBlog + +export declare const Blog: (new (init: ModelInit) => Blog) & { + copyOf(source: Blog, mutator: (draft: MutableModel) => MutableModel | void): Blog; +} + +type EagerPost = { + readonly [__modelMeta__]: { + identifier: ManagedIdentifier; + readOnlyFields: 'createdAt' | 'updatedAt'; + }; + readonly id: string; + readonly title: string; + readonly blog?: Blog | null; + readonly comments?: (Comment | null)[] | null; + readonly createdAt?: string | null; + readonly updatedAt?: string | null; + readonly blogPostsId?: string | null; +} + +type LazyPost = { + readonly [__modelMeta__]: { + identifier: ManagedIdentifier; + readOnlyFields: 'createdAt' | 'updatedAt'; + }; + readonly id: string; + readonly title: string; + readonly blog: AsyncItem; + readonly comments: AsyncCollection; + readonly createdAt?: string | null; + readonly updatedAt?: string | null; + readonly blogPostsId?: string | null; +} + +export declare type Post = LazyLoading extends LazyLoadingDisabled ? EagerPost : LazyPost + +export declare const Post: (new (init: ModelInit) => Post) & { + copyOf(source: Post, mutator: (draft: MutableModel) => MutableModel | void): Post; +} + +type EagerComment = { + readonly [__modelMeta__]: { + identifier: ManagedIdentifier; + readOnlyFields: 'createdAt' | 'updatedAt'; + }; + readonly id: string; + readonly post?: Post | null; + readonly content: string; + readonly createdAt?: string | null; + readonly updatedAt?: string | null; + readonly postCommentsId?: string | null; +} + +type LazyComment = { + readonly [__modelMeta__]: { + identifier: ManagedIdentifier; + readOnlyFields: 'createdAt' | 'updatedAt'; + }; + readonly id: string; + readonly post: AsyncItem; + readonly content: string; + readonly createdAt?: string | null; + readonly updatedAt?: string | null; + readonly postCommentsId?: string | null; +} + +export declare type Comment = LazyLoading extends LazyLoadingDisabled ? EagerComment : LazyComment + +export declare const Comment: (new (init: ModelInit) => Comment) & { + copyOf(source: Comment, mutator: (draft: MutableModel) => MutableModel | void): Comment; +}", + "index.js": "// @ts-check +import { initSchema } from '@aws-amplify/datastore'; +import { schema } from './schema'; + + + +const { Blog, Post, Comment } = initSchema(schema); + +export { + Blog, + Post, + Comment +};", + "schema.d.ts": "import { Schema } from '@aws-amplify/datastore'; + +export declare const schema: Schema;", + "schema.js": "export const schema = { + \\"models\\": { + \\"Blog\\": { + \\"name\\": \\"Blog\\", + \\"fields\\": { + \\"id\\": { + \\"name\\": \\"id\\", + \\"isArray\\": false, + \\"type\\": \\"ID\\", + \\"isRequired\\": true, + \\"attributes\\": [] + }, + \\"name\\": { + \\"name\\": \\"name\\", + \\"isArray\\": false, + \\"type\\": \\"String\\", + \\"isRequired\\": true, + \\"attributes\\": [] + }, + \\"posts\\": { + \\"name\\": \\"posts\\", + \\"isArray\\": true, + \\"type\\": { + \\"model\\": \\"Post\\" + }, + \\"isRequired\\": false, + \\"attributes\\": [], + \\"isArrayNullable\\": true, + \\"association\\": { + \\"connectionType\\": \\"HAS_MANY\\", + \\"associatedWith\\": [ + \\"blogPostsId\\" + ] + } + }, + \\"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\\": \\"Blogs\\", + \\"attributes\\": [ + { + \\"type\\": \\"model\\", + \\"properties\\": {} + } + ] + }, + \\"Post\\": { + \\"name\\": \\"Post\\", + \\"fields\\": { + \\"id\\": { + \\"name\\": \\"id\\", + \\"isArray\\": false, + \\"type\\": \\"ID\\", + \\"isRequired\\": true, + \\"attributes\\": [] + }, + \\"title\\": { + \\"name\\": \\"title\\", + \\"isArray\\": false, + \\"type\\": \\"String\\", + \\"isRequired\\": true, + \\"attributes\\": [] + }, + \\"blog\\": { + \\"name\\": \\"blog\\", + \\"isArray\\": false, + \\"type\\": { + \\"model\\": \\"Blog\\" + }, + \\"isRequired\\": false, + \\"attributes\\": [], + \\"association\\": { + \\"connectionType\\": \\"BELONGS_TO\\", + \\"targetNames\\": [ + \\"blogPostsId\\" + ] + } + }, + \\"comments\\": { + \\"name\\": \\"comments\\", + \\"isArray\\": true, + \\"type\\": { + \\"model\\": \\"Comment\\" + }, + \\"isRequired\\": false, + \\"attributes\\": [], + \\"isArrayNullable\\": true, + \\"association\\": { + \\"connectionType\\": \\"HAS_MANY\\", + \\"associatedWith\\": [ + \\"postCommentsId\\" + ] + } + }, + \\"createdAt\\": { + \\"name\\": \\"createdAt\\", + \\"isArray\\": false, + \\"type\\": \\"AWSDateTime\\", + \\"isRequired\\": false, + \\"attributes\\": [], + \\"isReadOnly\\": true + }, + \\"updatedAt\\": { + \\"name\\": \\"updatedAt\\", + \\"isArray\\": false, + \\"type\\": \\"AWSDateTime\\", + \\"isRequired\\": false, + \\"attributes\\": [], + \\"isReadOnly\\": true + }, + \\"blogPostsId\\": { + \\"name\\": \\"blogPostsId\\", + \\"isArray\\": false, + \\"type\\": \\"ID\\", + \\"isRequired\\": false, + \\"attributes\\": [] + } + }, + \\"syncable\\": true, + \\"pluralName\\": \\"Posts\\", + \\"attributes\\": [ + { + \\"type\\": \\"model\\", + \\"properties\\": {} + } + ] + }, + \\"Comment\\": { + \\"name\\": \\"Comment\\", + \\"fields\\": { + \\"id\\": { + \\"name\\": \\"id\\", + \\"isArray\\": false, + \\"type\\": \\"ID\\", + \\"isRequired\\": true, + \\"attributes\\": [] + }, + \\"post\\": { + \\"name\\": \\"post\\", + \\"isArray\\": false, + \\"type\\": { + \\"model\\": \\"Post\\" + }, + \\"isRequired\\": false, + \\"attributes\\": [], + \\"association\\": { + \\"connectionType\\": \\"BELONGS_TO\\", + \\"targetNames\\": [ + \\"postCommentsId\\" + ] + } + }, + \\"content\\": { + \\"name\\": \\"content\\", + \\"isArray\\": false, + \\"type\\": \\"String\\", + \\"isRequired\\": true, + \\"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 + }, + \\"postCommentsId\\": { + \\"name\\": \\"postCommentsId\\", + \\"isArray\\": false, + \\"type\\": \\"ID\\", + \\"isRequired\\": false, + \\"attributes\\": [] + } + }, + \\"syncable\\": true, + \\"pluralName\\": \\"Comments\\", + \\"attributes\\": [ + { + \\"type\\": \\"model\\", + \\"properties\\": {} + } + ] + } + }, + \\"enums\\": {}, + \\"nonModels\\": {}, + \\"codegenVersion\\": \\"3.4.4\\", + \\"version\\": \\"920118e6cbedacf9fdf58bb983d59a94\\" +};", +} +`; + +exports[`generateModels with targets basic 4`] = ` +Object { + "index.ts": "import { ModelInit, MutableModel, PersistentModelConstructor } from \\"@aws-amplify/datastore\\"; +import { initSchema } from \\"@aws-amplify/datastore\\"; + +import { schema } from \\"./schema\\"; + + + +type EagerBlogModel = { + readonly [__modelMeta__]: { + identifier: ManagedIdentifier; + readOnlyFields: 'createdAt' | 'updatedAt'; + }; + readonly id: string; + readonly name: string; + readonly posts?: (PostModel | null)[] | null; + readonly createdAt?: string | null; + readonly updatedAt?: string | null; +} + +type LazyBlogModel = { + readonly [__modelMeta__]: { + identifier: ManagedIdentifier; + readOnlyFields: 'createdAt' | 'updatedAt'; + }; + readonly id: string; + readonly name: string; + readonly posts: AsyncCollection; + readonly createdAt?: string | null; + readonly updatedAt?: string | null; +} + +export declare type BlogModel = LazyLoading extends LazyLoadingDisabled ? EagerBlogModel : LazyBlogModel + +export declare const BlogModel: (new (init: ModelInit) => BlogModel) & { + copyOf(source: BlogModel, mutator: (draft: MutableModel) => MutableModel | void): BlogModel; +} + +type EagerPostModel = { + readonly [__modelMeta__]: { + identifier: ManagedIdentifier; + readOnlyFields: 'createdAt' | 'updatedAt'; + }; + readonly id: string; + readonly title: string; + readonly blog?: BlogModel | null; + readonly comments?: (CommentModel | null)[] | null; + readonly createdAt?: string | null; + readonly updatedAt?: string | null; + readonly blogPostsId?: string | null; +} + +type LazyPostModel = { + readonly [__modelMeta__]: { + identifier: ManagedIdentifier; + readOnlyFields: 'createdAt' | 'updatedAt'; + }; + readonly id: string; + readonly title: string; + readonly blog: AsyncItem; + readonly comments: AsyncCollection; + readonly createdAt?: string | null; + readonly updatedAt?: string | null; + readonly blogPostsId?: string | null; +} + +export declare type PostModel = LazyLoading extends LazyLoadingDisabled ? EagerPostModel : LazyPostModel + +export declare const PostModel: (new (init: ModelInit) => PostModel) & { + copyOf(source: PostModel, mutator: (draft: MutableModel) => MutableModel | void): PostModel; +} + +type EagerCommentModel = { + readonly [__modelMeta__]: { + identifier: ManagedIdentifier; + readOnlyFields: 'createdAt' | 'updatedAt'; + }; + readonly id: string; + readonly post?: PostModel | null; + readonly content: string; + readonly createdAt?: string | null; + readonly updatedAt?: string | null; + readonly postCommentsId?: string | null; +} + +type LazyCommentModel = { + readonly [__modelMeta__]: { + identifier: ManagedIdentifier; + readOnlyFields: 'createdAt' | 'updatedAt'; + }; + readonly id: string; + readonly post: AsyncItem; + readonly content: string; + readonly createdAt?: string | null; + readonly updatedAt?: string | null; + readonly postCommentsId?: string | null; +} + +export declare type CommentModel = LazyLoading extends LazyLoadingDisabled ? EagerCommentModel : LazyCommentModel + +export declare const CommentModel: (new (init: ModelInit) => CommentModel) & { + copyOf(source: CommentModel, mutator: (draft: MutableModel) => MutableModel | void): CommentModel; +} + + + +const { Blog, Post, Comment } = initSchema(schema) as { + Blog: PersistentModelConstructor; + Post: PersistentModelConstructor; + Comment: PersistentModelConstructor; +}; + +export { + Blog, + Post, + Comment +};", + "schema.ts": "import { Schema } from \\"@aws-amplify/datastore\\"; + +export const schema: Schema = { + \\"models\\": { + \\"Blog\\": { + \\"name\\": \\"Blog\\", + \\"fields\\": { + \\"id\\": { + \\"name\\": \\"id\\", + \\"isArray\\": false, + \\"type\\": \\"ID\\", + \\"isRequired\\": true, + \\"attributes\\": [] + }, + \\"name\\": { + \\"name\\": \\"name\\", + \\"isArray\\": false, + \\"type\\": \\"String\\", + \\"isRequired\\": true, + \\"attributes\\": [] + }, + \\"posts\\": { + \\"name\\": \\"posts\\", + \\"isArray\\": true, + \\"type\\": { + \\"model\\": \\"Post\\" + }, + \\"isRequired\\": false, + \\"attributes\\": [], + \\"isArrayNullable\\": true, + \\"association\\": { + \\"connectionType\\": \\"HAS_MANY\\", + \\"associatedWith\\": [ + \\"blogPostsId\\" + ] + } + }, + \\"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\\": \\"Blogs\\", + \\"attributes\\": [ + { + \\"type\\": \\"model\\", + \\"properties\\": {} + } + ] + }, + \\"Post\\": { + \\"name\\": \\"Post\\", + \\"fields\\": { + \\"id\\": { + \\"name\\": \\"id\\", + \\"isArray\\": false, + \\"type\\": \\"ID\\", + \\"isRequired\\": true, + \\"attributes\\": [] + }, + \\"title\\": { + \\"name\\": \\"title\\", + \\"isArray\\": false, + \\"type\\": \\"String\\", + \\"isRequired\\": true, + \\"attributes\\": [] + }, + \\"blog\\": { + \\"name\\": \\"blog\\", + \\"isArray\\": false, + \\"type\\": { + \\"model\\": \\"Blog\\" + }, + \\"isRequired\\": false, + \\"attributes\\": [], + \\"association\\": { + \\"connectionType\\": \\"BELONGS_TO\\", + \\"targetNames\\": [ + \\"blogPostsId\\" + ] + } + }, + \\"comments\\": { + \\"name\\": \\"comments\\", + \\"isArray\\": true, + \\"type\\": { + \\"model\\": \\"Comment\\" + }, + \\"isRequired\\": false, + \\"attributes\\": [], + \\"isArrayNullable\\": true, + \\"association\\": { + \\"connectionType\\": \\"HAS_MANY\\", + \\"associatedWith\\": [ + \\"postCommentsId\\" + ] + } + }, + \\"createdAt\\": { + \\"name\\": \\"createdAt\\", + \\"isArray\\": false, + \\"type\\": \\"AWSDateTime\\", + \\"isRequired\\": false, + \\"attributes\\": [], + \\"isReadOnly\\": true + }, + \\"updatedAt\\": { + \\"name\\": \\"updatedAt\\", + \\"isArray\\": false, + \\"type\\": \\"AWSDateTime\\", + \\"isRequired\\": false, + \\"attributes\\": [], + \\"isReadOnly\\": true + }, + \\"blogPostsId\\": { + \\"name\\": \\"blogPostsId\\", + \\"isArray\\": false, + \\"type\\": \\"ID\\", + \\"isRequired\\": false, + \\"attributes\\": [] + } + }, + \\"syncable\\": true, + \\"pluralName\\": \\"Posts\\", + \\"attributes\\": [ + { + \\"type\\": \\"model\\", + \\"properties\\": {} + } + ] + }, + \\"Comment\\": { + \\"name\\": \\"Comment\\", + \\"fields\\": { + \\"id\\": { + \\"name\\": \\"id\\", + \\"isArray\\": false, + \\"type\\": \\"ID\\", + \\"isRequired\\": true, + \\"attributes\\": [] + }, + \\"post\\": { + \\"name\\": \\"post\\", + \\"isArray\\": false, + \\"type\\": { + \\"model\\": \\"Post\\" + }, + \\"isRequired\\": false, + \\"attributes\\": [], + \\"association\\": { + \\"connectionType\\": \\"BELONGS_TO\\", + \\"targetNames\\": [ + \\"postCommentsId\\" + ] + } + }, + \\"content\\": { + \\"name\\": \\"content\\", + \\"isArray\\": false, + \\"type\\": \\"String\\", + \\"isRequired\\": true, + \\"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 + }, + \\"postCommentsId\\": { + \\"name\\": \\"postCommentsId\\", + \\"isArray\\": false, + \\"type\\": \\"ID\\", + \\"isRequired\\": false, + \\"attributes\\": [] + } + }, + \\"syncable\\": true, + \\"pluralName\\": \\"Comments\\", + \\"attributes\\": [ + { + \\"type\\": \\"model\\", + \\"properties\\": {} + } + ] + } + }, + \\"enums\\": {}, + \\"nonModels\\": {}, + \\"codegenVersion\\": \\"3.4.4\\", + \\"version\\": \\"920118e6cbedacf9fdf58bb983d59a94\\" +};", +} +`; + +exports[`generateModels with targets basic 5`] = ` +Object { + "Blog.dart": "/* +* Copyright 2021 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. +* A copy of the License is located at +* +* http://aws.amazon.com/apache2.0 +* +* or in the \\"license\\" file accompanying this file. This file 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. +*/ + +// NOTE: This file is generated and may not follow lint rules defined in your app +// Generated files can be excluded from analysis in analysis_options.yaml +// For more info, see: https://dart.dev/guides/language/analysis-options#excluding-code-from-analysis + +// ignore_for_file: public_member_api_docs, annotate_overrides, dead_code, dead_codepublic_member_api_docs, depend_on_referenced_packages, file_names, library_private_types_in_public_api, no_leading_underscores_for_library_prefixes, no_leading_underscores_for_local_identifiers, non_constant_identifier_names, null_check_on_nullable_type_parameter, override_on_non_overriding_member, prefer_adjacent_string_concatenation, prefer_const_constructors, prefer_if_null_operators, prefer_interpolation_to_compose_strings, slash_for_doc_comments, sort_child_properties_last, unnecessary_const, unnecessary_constructor_name, unnecessary_late, unnecessary_new, unnecessary_null_aware_assignments, unnecessary_nullable_for_final_variable_declarations, unnecessary_string_interpolations, use_build_context_synchronously + +import 'ModelProvider.dart'; +import 'package:amplify_core/amplify_core.dart' as amplify_core; +import 'package:collection/collection.dart'; + + +/** This is an auto generated class representing the Blog type in your schema. */ +class Blog extends amplify_core.Model { + static const classType = const _BlogModelType(); + final String id; + final String? _name; + final List? _posts; + final amplify_core.TemporalDateTime? _createdAt; + final amplify_core.TemporalDateTime? _updatedAt; + + @override + getInstanceType() => classType; + + @Deprecated('[getId] is being deprecated in favor of custom primary key feature. Use getter [modelIdentifier] to get model identifier.') + @override + String getId() => id; + + BlogModelIdentifier get modelIdentifier { + return BlogModelIdentifier( + id: id + ); + } + + String get name { + try { + return _name!; + } catch(e) { + throw amplify_core.AmplifyCodeGenModelException( + amplify_core.AmplifyExceptionMessages.codeGenRequiredFieldForceCastExceptionMessage, + recoverySuggestion: + amplify_core.AmplifyExceptionMessages.codeGenRequiredFieldForceCastRecoverySuggestion, + underlyingException: e.toString() + ); + } + } + + List? get posts { + return _posts; + } + + amplify_core.TemporalDateTime? get createdAt { + return _createdAt; + } + + amplify_core.TemporalDateTime? get updatedAt { + return _updatedAt; + } + + const Blog._internal({required this.id, required name, posts, createdAt, updatedAt}): _name = name, _posts = posts, _createdAt = createdAt, _updatedAt = updatedAt; + + factory Blog({String? id, required String name, List? posts}) { + return Blog._internal( + id: id == null ? amplify_core.UUID.getUUID() : id, + name: name, + posts: posts != null ? List.unmodifiable(posts) : posts); + } + + bool equals(Object other) { + return this == other; + } + + @override + bool operator ==(Object other) { + if (identical(other, this)) return true; + return other is Blog && + id == other.id && + _name == other._name && + DeepCollectionEquality().equals(_posts, other._posts); + } + + @override + int get hashCode => toString().hashCode; + + @override + String toString() { + var buffer = new StringBuffer(); + + buffer.write(\\"Blog {\\"); + buffer.write(\\"id=\\" + \\"$id\\" + \\", \\"); + buffer.write(\\"name=\\" + \\"$_name\\" + \\", \\"); + buffer.write(\\"createdAt=\\" + (_createdAt != null ? _createdAt!.format() : \\"null\\") + \\", \\"); + buffer.write(\\"updatedAt=\\" + (_updatedAt != null ? _updatedAt!.format() : \\"null\\")); + buffer.write(\\"}\\"); + + return buffer.toString(); + } + + Blog copyWith({String? name, List? posts}) { + return Blog._internal( + id: id, + name: name ?? this.name, + posts: posts ?? this.posts); + } + + Blog copyWithModelFieldValues({ + ModelFieldValue? name, + ModelFieldValue?>? posts + }) { + return Blog._internal( + id: id, + name: name == null ? this.name : name.value, + posts: posts == null ? this.posts : posts.value + ); + } + + Blog.fromJson(Map json) + : id = json['id'], + _name = json['name'], + _posts = json['posts'] is Map + ? (json['posts']['items'] is List + ? (json['posts']['items'] as List) + .where((e) => e != null) + .map((e) => Post.fromJson(new Map.from(e))) + .toList() + : null) + : (json['posts'] is List + ? (json['posts'] as List) + .where((e) => e?['serializedData'] != null) + .map((e) => Post.fromJson(new Map.from(e?['serializedData']))) + .toList() + : null), + _createdAt = json['createdAt'] != null ? amplify_core.TemporalDateTime.fromString(json['createdAt']) : null, + _updatedAt = json['updatedAt'] != null ? amplify_core.TemporalDateTime.fromString(json['updatedAt']) : null; + + Map toJson() => { + 'id': id, 'name': _name, 'posts': _posts?.map((Post? e) => e?.toJson()).toList(), 'createdAt': _createdAt?.format(), 'updatedAt': _updatedAt?.format() + }; + + Map toMap() => { + 'id': id, + 'name': _name, + 'posts': _posts, + 'createdAt': _createdAt, + 'updatedAt': _updatedAt + }; + + static final amplify_core.QueryModelIdentifier MODEL_IDENTIFIER = amplify_core.QueryModelIdentifier(); + static final ID = amplify_core.QueryField(fieldName: \\"id\\"); + static final NAME = amplify_core.QueryField(fieldName: \\"name\\"); + static final POSTS = amplify_core.QueryField( + fieldName: \\"posts\\", + fieldType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.model, ofModelName: 'Post')); + static var schema = amplify_core.Model.defineSchema(define: (amplify_core.ModelSchemaDefinition modelSchemaDefinition) { + modelSchemaDefinition.name = \\"Blog\\"; + modelSchemaDefinition.pluralName = \\"Blogs\\"; + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.id()); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.field( + key: Blog.NAME, + isRequired: true, + ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.string) + )); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.hasMany( + key: Blog.POSTS, + isRequired: false, + ofModelName: 'Post', + associatedKey: Post.BLOG + )); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.nonQueryField( + fieldName: 'createdAt', + isRequired: false, + isReadOnly: true, + ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.dateTime) + )); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.nonQueryField( + fieldName: 'updatedAt', + isRequired: false, + isReadOnly: true, + ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.dateTime) + )); + }); +} + +class _BlogModelType extends amplify_core.ModelType { + const _BlogModelType(); + + @override + Blog fromJson(Map jsonData) { + return Blog.fromJson(jsonData); + } + + @override + String modelName() { + return 'Blog'; + } +} + +/** + * This is an auto generated class representing the model identifier + * of [Blog] in your schema. + */ +class BlogModelIdentifier implements amplify_core.ModelIdentifier { + final String id; + + /** Create an instance of BlogModelIdentifier using [id] the primary key. */ + const BlogModelIdentifier({ + required this.id}); + + @override + Map serializeAsMap() => ({ + 'id': id + }); + + @override + List> serializeAsList() => serializeAsMap() + .entries + .map((entry) => ({ entry.key: entry.value })) + .toList(); + + @override + String serializeAsString() => serializeAsMap().values.join('#'); + + @override + String toString() => 'BlogModelIdentifier(id: $id)'; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + + return other is BlogModelIdentifier && + id == other.id; + } + + @override + int get hashCode => + id.hashCode; +}", + "Comment.dart": "/* +* Copyright 2021 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. +* A copy of the License is located at +* +* http://aws.amazon.com/apache2.0 +* +* or in the \\"license\\" file accompanying this file. This file 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. +*/ + +// NOTE: This file is generated and may not follow lint rules defined in your app +// Generated files can be excluded from analysis in analysis_options.yaml +// For more info, see: https://dart.dev/guides/language/analysis-options#excluding-code-from-analysis + +// ignore_for_file: public_member_api_docs, annotate_overrides, dead_code, dead_codepublic_member_api_docs, depend_on_referenced_packages, file_names, library_private_types_in_public_api, no_leading_underscores_for_library_prefixes, no_leading_underscores_for_local_identifiers, non_constant_identifier_names, null_check_on_nullable_type_parameter, override_on_non_overriding_member, prefer_adjacent_string_concatenation, prefer_const_constructors, prefer_if_null_operators, prefer_interpolation_to_compose_strings, slash_for_doc_comments, sort_child_properties_last, unnecessary_const, unnecessary_constructor_name, unnecessary_late, unnecessary_new, unnecessary_null_aware_assignments, unnecessary_nullable_for_final_variable_declarations, unnecessary_string_interpolations, use_build_context_synchronously + +import 'ModelProvider.dart'; +import 'package:amplify_core/amplify_core.dart' as amplify_core; + + +/** This is an auto generated class representing the Comment type in your schema. */ +class Comment extends amplify_core.Model { + static const classType = const _CommentModelType(); + final String id; + final Post? _post; + final String? _content; + final amplify_core.TemporalDateTime? _createdAt; + final amplify_core.TemporalDateTime? _updatedAt; + + @override + getInstanceType() => classType; + + @Deprecated('[getId] is being deprecated in favor of custom primary key feature. Use getter [modelIdentifier] to get model identifier.') + @override + String getId() => id; + + CommentModelIdentifier get modelIdentifier { + return CommentModelIdentifier( + id: id + ); + } + + Post? get post { + return _post; + } + + String get content { + try { + return _content!; + } catch(e) { + throw amplify_core.AmplifyCodeGenModelException( + amplify_core.AmplifyExceptionMessages.codeGenRequiredFieldForceCastExceptionMessage, + recoverySuggestion: + amplify_core.AmplifyExceptionMessages.codeGenRequiredFieldForceCastRecoverySuggestion, + underlyingException: e.toString() + ); + } + } + + amplify_core.TemporalDateTime? get createdAt { + return _createdAt; + } + + amplify_core.TemporalDateTime? get updatedAt { + return _updatedAt; + } + + const Comment._internal({required this.id, post, required content, createdAt, updatedAt}): _post = post, _content = content, _createdAt = createdAt, _updatedAt = updatedAt; + + factory Comment({String? id, Post? post, required String content}) { + return Comment._internal( + id: id == null ? amplify_core.UUID.getUUID() : id, + post: post, + content: content); + } + + bool equals(Object other) { + return this == other; + } + + @override + bool operator ==(Object other) { + if (identical(other, this)) return true; + return other is Comment && + id == other.id && + _post == other._post && + _content == other._content; + } + + @override + int get hashCode => toString().hashCode; + + @override + String toString() { + var buffer = new StringBuffer(); + + buffer.write(\\"Comment {\\"); + buffer.write(\\"id=\\" + \\"$id\\" + \\", \\"); + buffer.write(\\"post=\\" + (_post != null ? _post!.toString() : \\"null\\") + \\", \\"); + buffer.write(\\"content=\\" + \\"$_content\\" + \\", \\"); + buffer.write(\\"createdAt=\\" + (_createdAt != null ? _createdAt!.format() : \\"null\\") + \\", \\"); + buffer.write(\\"updatedAt=\\" + (_updatedAt != null ? _updatedAt!.format() : \\"null\\")); + buffer.write(\\"}\\"); + + return buffer.toString(); + } + + Comment copyWith({Post? post, String? content}) { + return Comment._internal( + id: id, + post: post ?? this.post, + content: content ?? this.content); + } + + Comment copyWithModelFieldValues({ + ModelFieldValue? post, + ModelFieldValue? content + }) { + return Comment._internal( + id: id, + post: post == null ? this.post : post.value, + content: content == null ? this.content : content.value + ); + } + + Comment.fromJson(Map json) + : id = json['id'], + _post = json['post'] != null + ? json['post']['serializedData'] != null + ? Post.fromJson(new Map.from(json['post']['serializedData'])) + : Post.fromJson(new Map.from(json['post'])) + : null, + _content = json['content'], + _createdAt = json['createdAt'] != null ? amplify_core.TemporalDateTime.fromString(json['createdAt']) : null, + _updatedAt = json['updatedAt'] != null ? amplify_core.TemporalDateTime.fromString(json['updatedAt']) : null; + + Map toJson() => { + 'id': id, 'post': _post?.toJson(), 'content': _content, 'createdAt': _createdAt?.format(), 'updatedAt': _updatedAt?.format() + }; + + Map toMap() => { + 'id': id, + 'post': _post, + 'content': _content, + 'createdAt': _createdAt, + 'updatedAt': _updatedAt + }; + + static final amplify_core.QueryModelIdentifier MODEL_IDENTIFIER = amplify_core.QueryModelIdentifier(); + static final ID = amplify_core.QueryField(fieldName: \\"id\\"); + static final POST = amplify_core.QueryField( + fieldName: \\"post\\", + fieldType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.model, ofModelName: 'Post')); + static final CONTENT = amplify_core.QueryField(fieldName: \\"content\\"); + static var schema = amplify_core.Model.defineSchema(define: (amplify_core.ModelSchemaDefinition modelSchemaDefinition) { + modelSchemaDefinition.name = \\"Comment\\"; + modelSchemaDefinition.pluralName = \\"Comments\\"; + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.id()); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.belongsTo( + key: Comment.POST, + isRequired: false, + targetNames: ['postCommentsId'], + ofModelName: 'Post' + )); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.field( + key: Comment.CONTENT, + isRequired: true, + ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.string) + )); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.nonQueryField( + fieldName: 'createdAt', + isRequired: false, + isReadOnly: true, + ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.dateTime) + )); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.nonQueryField( + fieldName: 'updatedAt', + isRequired: false, + isReadOnly: true, + ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.dateTime) + )); + }); +} + +class _CommentModelType extends amplify_core.ModelType { + const _CommentModelType(); + + @override + Comment fromJson(Map jsonData) { + return Comment.fromJson(jsonData); + } + + @override + String modelName() { + return 'Comment'; + } +} + +/** + * This is an auto generated class representing the model identifier + * of [Comment] in your schema. + */ +class CommentModelIdentifier implements amplify_core.ModelIdentifier { + final String id; + + /** Create an instance of CommentModelIdentifier using [id] the primary key. */ + const CommentModelIdentifier({ + required this.id}); + + @override + Map serializeAsMap() => ({ + 'id': id + }); + + @override + List> serializeAsList() => serializeAsMap() + .entries + .map((entry) => ({ entry.key: entry.value })) + .toList(); + + @override + String serializeAsString() => serializeAsMap().values.join('#'); + + @override + String toString() => 'CommentModelIdentifier(id: $id)'; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + + return other is CommentModelIdentifier && + id == other.id; + } + + @override + int get hashCode => + id.hashCode; +}", + "ModelProvider.dart": "/* +* Copyright 2021 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. +* A copy of the License is located at +* +* http://aws.amazon.com/apache2.0 +* +* or in the \\"license\\" file accompanying this file. This file 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. +*/ + +// NOTE: This file is generated and may not follow lint rules defined in your app +// Generated files can be excluded from analysis in analysis_options.yaml +// For more info, see: https://dart.dev/guides/language/analysis-options#excluding-code-from-analysis + +// ignore_for_file: public_member_api_docs, annotate_overrides, dead_code, dead_codepublic_member_api_docs, depend_on_referenced_packages, file_names, library_private_types_in_public_api, no_leading_underscores_for_library_prefixes, no_leading_underscores_for_local_identifiers, non_constant_identifier_names, null_check_on_nullable_type_parameter, override_on_non_overriding_member, prefer_adjacent_string_concatenation, prefer_const_constructors, prefer_if_null_operators, prefer_interpolation_to_compose_strings, slash_for_doc_comments, sort_child_properties_last, unnecessary_const, unnecessary_constructor_name, unnecessary_late, unnecessary_new, unnecessary_null_aware_assignments, unnecessary_nullable_for_final_variable_declarations, unnecessary_string_interpolations, use_build_context_synchronously + +import 'package:amplify_core/amplify_core.dart' as amplify_core; +import 'Blog.dart'; +import 'Comment.dart'; +import 'Post.dart'; + +export 'Blog.dart'; +export 'Comment.dart'; +export 'Post.dart'; + +class ModelProvider implements amplify_core.ModelProviderInterface { + @override + String version = \\"165944a36979cd395e3b22145bbfeff0\\"; + @override + List modelSchemas = [Blog.schema, Comment.schema, Post.schema]; + @override + List customTypeSchemas = []; + static final ModelProvider _instance = ModelProvider(); + + static ModelProvider get instance => _instance; + + amplify_core.ModelType getModelTypeByModelName(String modelName) { + switch(modelName) { + case \\"Blog\\": + return Blog.classType; + case \\"Comment\\": + return Comment.classType; + case \\"Post\\": + return Post.classType; + default: + throw Exception(\\"Failed to find model in model provider for model name: \\" + modelName); + } + } +} + + +class ModelFieldValue { + const ModelFieldValue.value(this.value); + + final T value; +} +", + "Post.dart": "/* +* Copyright 2021 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. +* A copy of the License is located at +* +* http://aws.amazon.com/apache2.0 +* +* or in the \\"license\\" file accompanying this file. This file 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. +*/ + +// NOTE: This file is generated and may not follow lint rules defined in your app +// Generated files can be excluded from analysis in analysis_options.yaml +// For more info, see: https://dart.dev/guides/language/analysis-options#excluding-code-from-analysis + +// ignore_for_file: public_member_api_docs, annotate_overrides, dead_code, dead_codepublic_member_api_docs, depend_on_referenced_packages, file_names, library_private_types_in_public_api, no_leading_underscores_for_library_prefixes, no_leading_underscores_for_local_identifiers, non_constant_identifier_names, null_check_on_nullable_type_parameter, override_on_non_overriding_member, prefer_adjacent_string_concatenation, prefer_const_constructors, prefer_if_null_operators, prefer_interpolation_to_compose_strings, slash_for_doc_comments, sort_child_properties_last, unnecessary_const, unnecessary_constructor_name, unnecessary_late, unnecessary_new, unnecessary_null_aware_assignments, unnecessary_nullable_for_final_variable_declarations, unnecessary_string_interpolations, use_build_context_synchronously + +import 'ModelProvider.dart'; +import 'package:amplify_core/amplify_core.dart' as amplify_core; +import 'package:collection/collection.dart'; + + +/** This is an auto generated class representing the Post type in your schema. */ +class Post extends amplify_core.Model { + static const classType = const _PostModelType(); + final String id; + final String? _title; + final Blog? _blog; + final List? _comments; + final amplify_core.TemporalDateTime? _createdAt; + final amplify_core.TemporalDateTime? _updatedAt; + + @override + getInstanceType() => classType; + + @Deprecated('[getId] is being deprecated in favor of custom primary key feature. Use getter [modelIdentifier] to get model identifier.') + @override + String getId() => id; + + PostModelIdentifier get modelIdentifier { + return PostModelIdentifier( + id: id + ); + } + + String get title { + try { + return _title!; + } catch(e) { + throw amplify_core.AmplifyCodeGenModelException( + amplify_core.AmplifyExceptionMessages.codeGenRequiredFieldForceCastExceptionMessage, + recoverySuggestion: + amplify_core.AmplifyExceptionMessages.codeGenRequiredFieldForceCastRecoverySuggestion, + underlyingException: e.toString() + ); + } + } + + Blog? get blog { + return _blog; + } + + List? get comments { + return _comments; + } + + amplify_core.TemporalDateTime? get createdAt { + return _createdAt; + } + + amplify_core.TemporalDateTime? get updatedAt { + return _updatedAt; + } + + const Post._internal({required this.id, required title, blog, comments, createdAt, updatedAt}): _title = title, _blog = blog, _comments = comments, _createdAt = createdAt, _updatedAt = updatedAt; + + factory Post({String? id, required String title, Blog? blog, List? comments}) { + return Post._internal( + id: id == null ? amplify_core.UUID.getUUID() : id, + title: title, + blog: blog, + comments: comments != null ? List.unmodifiable(comments) : comments); + } + + bool equals(Object other) { + return this == other; + } + + @override + bool operator ==(Object other) { + if (identical(other, this)) return true; + return other is Post && + id == other.id && + _title == other._title && + _blog == other._blog && + DeepCollectionEquality().equals(_comments, other._comments); + } + + @override + int get hashCode => toString().hashCode; + + @override + String toString() { + var buffer = new StringBuffer(); + + buffer.write(\\"Post {\\"); + buffer.write(\\"id=\\" + \\"$id\\" + \\", \\"); + buffer.write(\\"title=\\" + \\"$_title\\" + \\", \\"); + buffer.write(\\"blog=\\" + (_blog != null ? _blog!.toString() : \\"null\\") + \\", \\"); + buffer.write(\\"createdAt=\\" + (_createdAt != null ? _createdAt!.format() : \\"null\\") + \\", \\"); + buffer.write(\\"updatedAt=\\" + (_updatedAt != null ? _updatedAt!.format() : \\"null\\")); + buffer.write(\\"}\\"); + + return buffer.toString(); + } + + Post copyWith({String? title, Blog? blog, List? comments}) { + return Post._internal( + id: id, + title: title ?? this.title, + blog: blog ?? this.blog, + comments: comments ?? this.comments); + } + + Post copyWithModelFieldValues({ + ModelFieldValue? title, + ModelFieldValue? blog, + ModelFieldValue?>? comments + }) { + return Post._internal( + id: id, + title: title == null ? this.title : title.value, + blog: blog == null ? this.blog : blog.value, + comments: comments == null ? this.comments : comments.value + ); + } + + Post.fromJson(Map json) + : id = json['id'], + _title = json['title'], + _blog = json['blog'] != null + ? json['blog']['serializedData'] != null + ? Blog.fromJson(new Map.from(json['blog']['serializedData'])) + : Blog.fromJson(new Map.from(json['blog'])) + : null, + _comments = json['comments'] is Map + ? (json['comments']['items'] is List + ? (json['comments']['items'] as List) + .where((e) => e != null) + .map((e) => Comment.fromJson(new Map.from(e))) + .toList() + : null) + : (json['comments'] is List + ? (json['comments'] as List) + .where((e) => e?['serializedData'] != null) + .map((e) => Comment.fromJson(new Map.from(e?['serializedData']))) + .toList() + : null), + _createdAt = json['createdAt'] != null ? amplify_core.TemporalDateTime.fromString(json['createdAt']) : null, + _updatedAt = json['updatedAt'] != null ? amplify_core.TemporalDateTime.fromString(json['updatedAt']) : null; + + Map toJson() => { + 'id': id, 'title': _title, 'blog': _blog?.toJson(), 'comments': _comments?.map((Comment? e) => e?.toJson()).toList(), 'createdAt': _createdAt?.format(), 'updatedAt': _updatedAt?.format() + }; + + Map toMap() => { + 'id': id, + 'title': _title, + 'blog': _blog, + 'comments': _comments, + 'createdAt': _createdAt, + 'updatedAt': _updatedAt + }; + + static final amplify_core.QueryModelIdentifier MODEL_IDENTIFIER = amplify_core.QueryModelIdentifier(); + static final ID = amplify_core.QueryField(fieldName: \\"id\\"); + static final TITLE = amplify_core.QueryField(fieldName: \\"title\\"); + static final BLOG = amplify_core.QueryField( + fieldName: \\"blog\\", + fieldType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.model, ofModelName: 'Blog')); + static final COMMENTS = amplify_core.QueryField( + fieldName: \\"comments\\", + fieldType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.model, ofModelName: 'Comment')); + static var schema = amplify_core.Model.defineSchema(define: (amplify_core.ModelSchemaDefinition modelSchemaDefinition) { + modelSchemaDefinition.name = \\"Post\\"; + modelSchemaDefinition.pluralName = \\"Posts\\"; + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.id()); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.field( + key: Post.TITLE, + isRequired: true, + ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.string) + )); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.belongsTo( + key: Post.BLOG, + isRequired: false, + targetNames: ['blogPostsId'], + ofModelName: 'Blog' + )); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.hasMany( + key: Post.COMMENTS, + isRequired: false, + ofModelName: 'Comment', + associatedKey: Comment.POST + )); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.nonQueryField( + fieldName: 'createdAt', + isRequired: false, + isReadOnly: true, + ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.dateTime) + )); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.nonQueryField( + fieldName: 'updatedAt', + isRequired: false, + isReadOnly: true, + ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.dateTime) + )); + }); +} + +class _PostModelType extends amplify_core.ModelType { + const _PostModelType(); + + @override + Post fromJson(Map jsonData) { + return Post.fromJson(jsonData); + } + + @override + String modelName() { + return 'Post'; + } +} + +/** + * This is an auto generated class representing the model identifier + * of [Post] in your schema. + */ +class PostModelIdentifier implements amplify_core.ModelIdentifier { + final String id; + + /** Create an instance of PostModelIdentifier using [id] the primary key. */ + const PostModelIdentifier({ + required this.id}); + + @override + Map serializeAsMap() => ({ + 'id': id + }); + + @override + List> serializeAsList() => serializeAsMap() + .entries + .map((entry) => ({ entry.key: entry.value })) + .toList(); + + @override + String serializeAsString() => serializeAsMap().values.join('#'); + + @override + String toString() => 'PostModelIdentifier(id: $id)'; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + + return other is PostModelIdentifier && + id == other.id; + } + + @override + int get hashCode => + id.hashCode; +}", +} +`; + +exports[`generateModels with targets basic 6`] = ` +Object { + "model-introspection.json": "{ + \\"version\\": 1, + \\"models\\": { + \\"Blog\\": { + \\"name\\": \\"Blog\\", + \\"fields\\": { + \\"id\\": { + \\"name\\": \\"id\\", + \\"isArray\\": false, + \\"type\\": \\"ID\\", + \\"isRequired\\": true, + \\"attributes\\": [] + }, + \\"name\\": { + \\"name\\": \\"name\\", + \\"isArray\\": false, + \\"type\\": \\"String\\", + \\"isRequired\\": true, + \\"attributes\\": [] + }, + \\"posts\\": { + \\"name\\": \\"posts\\", + \\"isArray\\": true, + \\"type\\": { + \\"model\\": \\"Post\\" + }, + \\"isRequired\\": false, + \\"attributes\\": [], + \\"isArrayNullable\\": true, + \\"association\\": { + \\"connectionType\\": \\"HAS_MANY\\", + \\"associatedWith\\": [ + \\"blogPostsId\\" + ] + } + }, + \\"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\\": \\"Blogs\\", + \\"attributes\\": [ + { + \\"type\\": \\"model\\", + \\"properties\\": {} + } + ], + \\"primaryKeyInfo\\": { + \\"isCustomPrimaryKey\\": false, + \\"primaryKeyFieldName\\": \\"id\\", + \\"sortKeyFieldNames\\": [] + } + }, + \\"Post\\": { + \\"name\\": \\"Post\\", + \\"fields\\": { + \\"id\\": { + \\"name\\": \\"id\\", + \\"isArray\\": false, + \\"type\\": \\"ID\\", + \\"isRequired\\": true, + \\"attributes\\": [] + }, + \\"title\\": { + \\"name\\": \\"title\\", + \\"isArray\\": false, + \\"type\\": \\"String\\", + \\"isRequired\\": true, + \\"attributes\\": [] + }, + \\"blog\\": { + \\"name\\": \\"blog\\", + \\"isArray\\": false, + \\"type\\": { + \\"model\\": \\"Blog\\" + }, + \\"isRequired\\": false, + \\"attributes\\": [], + \\"association\\": { + \\"connectionType\\": \\"BELONGS_TO\\", + \\"targetNames\\": [ + \\"blogPostsId\\" + ] + } + }, + \\"comments\\": { + \\"name\\": \\"comments\\", + \\"isArray\\": true, + \\"type\\": { + \\"model\\": \\"Comment\\" + }, + \\"isRequired\\": false, + \\"attributes\\": [], + \\"isArrayNullable\\": true, + \\"association\\": { + \\"connectionType\\": \\"HAS_MANY\\", + \\"associatedWith\\": [ + \\"postCommentsId\\" + ] + } + }, + \\"createdAt\\": { + \\"name\\": \\"createdAt\\", + \\"isArray\\": false, + \\"type\\": \\"AWSDateTime\\", + \\"isRequired\\": false, + \\"attributes\\": [], + \\"isReadOnly\\": true + }, + \\"updatedAt\\": { + \\"name\\": \\"updatedAt\\", + \\"isArray\\": false, + \\"type\\": \\"AWSDateTime\\", + \\"isRequired\\": false, + \\"attributes\\": [], + \\"isReadOnly\\": true + }, + \\"blogPostsId\\": { + \\"name\\": \\"blogPostsId\\", + \\"isArray\\": false, + \\"type\\": \\"ID\\", + \\"isRequired\\": false, + \\"attributes\\": [] + } + }, + \\"syncable\\": true, + \\"pluralName\\": \\"Posts\\", + \\"attributes\\": [ + { + \\"type\\": \\"model\\", + \\"properties\\": {} + } + ], + \\"primaryKeyInfo\\": { + \\"isCustomPrimaryKey\\": false, + \\"primaryKeyFieldName\\": \\"id\\", + \\"sortKeyFieldNames\\": [] + } + }, + \\"Comment\\": { + \\"name\\": \\"Comment\\", + \\"fields\\": { + \\"id\\": { + \\"name\\": \\"id\\", + \\"isArray\\": false, + \\"type\\": \\"ID\\", + \\"isRequired\\": true, + \\"attributes\\": [] + }, + \\"post\\": { + \\"name\\": \\"post\\", + \\"isArray\\": false, + \\"type\\": { + \\"model\\": \\"Post\\" + }, + \\"isRequired\\": false, + \\"attributes\\": [], + \\"association\\": { + \\"connectionType\\": \\"BELONGS_TO\\", + \\"targetNames\\": [ + \\"postCommentsId\\" + ] + } + }, + \\"content\\": { + \\"name\\": \\"content\\", + \\"isArray\\": false, + \\"type\\": \\"String\\", + \\"isRequired\\": true, + \\"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 + }, + \\"postCommentsId\\": { + \\"name\\": \\"postCommentsId\\", + \\"isArray\\": false, + \\"type\\": \\"ID\\", + \\"isRequired\\": false, + \\"attributes\\": [] + } + }, + \\"syncable\\": true, + \\"pluralName\\": \\"Comments\\", + \\"attributes\\": [ + { + \\"type\\": \\"model\\", + \\"properties\\": {} + } + ], + \\"primaryKeyInfo\\": { + \\"isCustomPrimaryKey\\": false, + \\"primaryKeyFieldName\\": \\"id\\", + \\"sortKeyFieldNames\\": [] + } + } + }, + \\"enums\\": {}, + \\"nonModels\\": {} +}", +} +`; + +exports[`generateModels with targets basic 7`] = ` +Object { + "com/amplifyframework/datastore/generated/model/AmplifyModelProvider.java": "package com.amplifyframework.datastore.generated.model; + +import com.amplifyframework.util.Immutable; +import com.amplifyframework.core.model.Model; +import com.amplifyframework.core.model.ModelProvider; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; +/** + * Contains the set of model classes that implement {@link Model} + * interface. + */ + +public final class AmplifyModelProvider implements ModelProvider { + private static final String AMPLIFY_MODEL_VERSION = \\"165944a36979cd395e3b22145bbfeff0\\"; + private static AmplifyModelProvider amplifyGeneratedModelInstance; + private AmplifyModelProvider() { + + } + + public static synchronized AmplifyModelProvider getInstance() { + if (amplifyGeneratedModelInstance == null) { + amplifyGeneratedModelInstance = new AmplifyModelProvider(); + } + return amplifyGeneratedModelInstance; + } + + /** + * Get a set of the model classes. + * + * @return a set of the model classes. + */ + @Override + public Set> models() { + final Set> modifiableSet = new HashSet<>( + Arrays.>asList(Blog.class, Post.class, Comment.class) + ); + + return Immutable.of(modifiableSet); + + } + + /** + * Get the version of the models. + * + * @return the version string of the models. + */ + @Override + public String version() { + return AMPLIFY_MODEL_VERSION; + } +} +", + "com/amplifyframework/datastore/generated/model/Blog.java": "package com.amplifyframework.datastore.generated.model; + +import com.amplifyframework.core.model.annotations.HasMany; +import com.amplifyframework.core.model.ModelList; +import com.amplifyframework.core.model.temporal.Temporal; +import com.amplifyframework.core.model.ModelIdentifier; + +import java.util.List; +import java.util.UUID; +import java.util.Objects; + +import androidx.core.util.ObjectsCompat; + +import com.amplifyframework.core.model.Model; +import com.amplifyframework.core.model.annotations.Index; +import com.amplifyframework.core.model.annotations.ModelConfig; +import com.amplifyframework.core.model.annotations.ModelField; +import com.amplifyframework.core.model.query.predicate.QueryField; + +import static com.amplifyframework.core.model.query.predicate.QueryField.field; + +/** This is an auto generated class representing the Blog type in your schema. */ +@SuppressWarnings(\\"all\\") +@ModelConfig(pluralName = \\"Blogs\\", type = Model.Type.USER, version = 1, hasLazySupport = true) +public final class Blog implements Model { + public static final BlogPath rootPath = new BlogPath(\\"root\\", false, null); + public static final QueryField ID = field(\\"Blog\\", \\"id\\"); + public static final QueryField NAME = field(\\"Blog\\", \\"name\\"); + private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; + private final @ModelField(targetType=\\"String\\", isRequired = true) String name; + private final @ModelField(targetType=\\"Post\\") @HasMany(associatedWith = \\"blog\\", type = Post.class) ModelList posts = null; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; + /** @deprecated This API is internal to Amplify and should not be used. */ + @Deprecated + public String resolveIdentifier() { + return id; + } + + public String getId() { + return id; + } + + public String getName() { + return name; + } + + public ModelList getPosts() { + return posts; + } + + public Temporal.DateTime getCreatedAt() { + return createdAt; + } + + public Temporal.DateTime getUpdatedAt() { + return updatedAt; + } + + private Blog(String id, String name) { + this.id = id; + this.name = name; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if(obj == null || getClass() != obj.getClass()) { + return false; + } else { + Blog blog = (Blog) obj; + return ObjectsCompat.equals(getId(), blog.getId()) && + ObjectsCompat.equals(getName(), blog.getName()) && + ObjectsCompat.equals(getCreatedAt(), blog.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), blog.getUpdatedAt()); + } + } + + @Override + public int hashCode() { + return new StringBuilder() + .append(getId()) + .append(getName()) + .append(getCreatedAt()) + .append(getUpdatedAt()) + .toString() + .hashCode(); + } + + @Override + public String toString() { + return new StringBuilder() + .append(\\"Blog {\\") + .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") + .append(\\"name=\\" + String.valueOf(getName()) + \\", \\") + .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) + .append(\\"}\\") + .toString(); + } + + public static NameStep builder() { + return new Builder(); + } + + /** + * WARNING: This method should not be used to build an instance of this object for a CREATE mutation. + * This is a convenience method to return an instance of the object with only its ID populated + * to be used in the context of a parameter in a delete mutation or referencing a foreign key + * in a relationship. + * @param id the id of the existing item this instance will represent + * @return an instance of this model with only ID populated + */ + public static Blog justId(String id) { + return new Blog( + id, + null + ); + } + + public CopyOfBuilder copyOfBuilder() { + return new CopyOfBuilder(id, + name); + } + public interface NameStep { + BuildStep name(String name); + } + + + public interface BuildStep { + Blog build(); + BuildStep id(String id); + } + + + public static class Builder implements NameStep, BuildStep { + private String id; + private String name; + public Builder() { + + } + + private Builder(String id, String name) { + this.id = id; + this.name = name; + } + + @Override + public Blog build() { + String id = this.id != null ? this.id : UUID.randomUUID().toString(); + + return new Blog( + id, + name); + } + + @Override + public BuildStep name(String name) { + Objects.requireNonNull(name); + this.name = name; + return this; + } + + /** + * @param id id + * @return Current Builder instance, for fluent method chaining + */ + public BuildStep id(String id) { + this.id = id; + return this; + } + } + + + public final class CopyOfBuilder extends Builder { + private CopyOfBuilder(String id, String name) { + super(id, name); + Objects.requireNonNull(name); + } + + @Override + public CopyOfBuilder name(String name) { + return (CopyOfBuilder) super.name(name); + } + } + + + public static class BlogIdentifier extends ModelIdentifier { + private static final long serialVersionUID = 1L; + public BlogIdentifier(String id) { + super(id); + } + } + +} +", + "com/amplifyframework/datastore/generated/model/BlogPath.java": "package com.amplifyframework.datastore.generated.model; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import com.amplifyframework.core.model.ModelPath; +import com.amplifyframework.core.model.PropertyPath; + +/** This is an auto generated class representing the ModelPath for the Blog type in your schema. */ +public final class BlogPath extends ModelPath { + private PostPath posts; + BlogPath(@NonNull String name, @NonNull Boolean isCollection, @Nullable PropertyPath parent) { + super(name, isCollection, parent, Blog.class); + } + + public synchronized PostPath getPosts() { + if (posts == null) { + posts = new PostPath(\\"posts\\", true, this); + } + return posts; + } +} +", + "com/amplifyframework/datastore/generated/model/Comment.java": "package com.amplifyframework.datastore.generated.model; + +import com.amplifyframework.core.model.annotations.BelongsTo; +import com.amplifyframework.core.model.ModelReference; +import com.amplifyframework.core.model.LoadedModelReferenceImpl; +import com.amplifyframework.core.model.temporal.Temporal; +import com.amplifyframework.core.model.ModelIdentifier; + +import java.util.List; +import java.util.UUID; +import java.util.Objects; + +import androidx.core.util.ObjectsCompat; + +import com.amplifyframework.core.model.Model; +import com.amplifyframework.core.model.annotations.Index; +import com.amplifyframework.core.model.annotations.ModelConfig; +import com.amplifyframework.core.model.annotations.ModelField; +import com.amplifyframework.core.model.query.predicate.QueryField; + +import static com.amplifyframework.core.model.query.predicate.QueryField.field; + +/** This is an auto generated class representing the Comment type in your schema. */ +@SuppressWarnings(\\"all\\") +@ModelConfig(pluralName = \\"Comments\\", type = Model.Type.USER, version = 1, hasLazySupport = true) +public final class Comment implements Model { + public static final CommentPath rootPath = new CommentPath(\\"root\\", false, null); + public static final QueryField ID = field(\\"Comment\\", \\"id\\"); + public static final QueryField POST = field(\\"Comment\\", \\"postCommentsId\\"); + public static final QueryField CONTENT = field(\\"Comment\\", \\"content\\"); + private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; + private final @ModelField(targetType=\\"Post\\") @BelongsTo(targetName = \\"postCommentsId\\", targetNames = {\\"postCommentsId\\"}, type = Post.class) ModelReference post; + private final @ModelField(targetType=\\"String\\", isRequired = true) String content; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; + /** @deprecated This API is internal to Amplify and should not be used. */ + @Deprecated + public String resolveIdentifier() { + return id; + } + + public String getId() { + return id; + } + + public ModelReference getPost() { + return post; + } + + public String getContent() { + return content; + } + + public Temporal.DateTime getCreatedAt() { + return createdAt; + } + + public Temporal.DateTime getUpdatedAt() { + return updatedAt; + } + + private Comment(String id, ModelReference post, String content) { + this.id = id; + this.post = post; + this.content = content; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if(obj == null || getClass() != obj.getClass()) { + return false; + } else { + Comment comment = (Comment) obj; + return ObjectsCompat.equals(getId(), comment.getId()) && + ObjectsCompat.equals(getPost(), comment.getPost()) && + ObjectsCompat.equals(getContent(), comment.getContent()) && + ObjectsCompat.equals(getCreatedAt(), comment.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), comment.getUpdatedAt()); + } + } + + @Override + public int hashCode() { + return new StringBuilder() + .append(getId()) + .append(getPost()) + .append(getContent()) + .append(getCreatedAt()) + .append(getUpdatedAt()) + .toString() + .hashCode(); + } + + @Override + public String toString() { + return new StringBuilder() + .append(\\"Comment {\\") + .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") + .append(\\"post=\\" + String.valueOf(getPost()) + \\", \\") + .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") + .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) + .append(\\"}\\") + .toString(); + } + + public static ContentStep builder() { + return new Builder(); + } + + /** + * WARNING: This method should not be used to build an instance of this object for a CREATE mutation. + * This is a convenience method to return an instance of the object with only its ID populated + * to be used in the context of a parameter in a delete mutation or referencing a foreign key + * in a relationship. + * @param id the id of the existing item this instance will represent + * @return an instance of this model with only ID populated + */ + public static Comment justId(String id) { + return new Comment( + id, + null, + null + ); + } + + public CopyOfBuilder copyOfBuilder() { + return new CopyOfBuilder(id, + post, + content); + } + public interface ContentStep { + BuildStep content(String content); + } + + + public interface BuildStep { + Comment build(); + BuildStep id(String id); + BuildStep post(Post post); + } + + + public static class Builder implements ContentStep, BuildStep { + private String id; + private String content; + private ModelReference post; + public Builder() { + + } + + private Builder(String id, ModelReference post, String content) { + this.id = id; + this.post = post; + this.content = content; + } + + @Override + public Comment build() { + String id = this.id != null ? this.id : UUID.randomUUID().toString(); + + return new Comment( + id, + post, + content); + } + + @Override + public BuildStep content(String content) { + Objects.requireNonNull(content); + this.content = content; + return this; + } + + @Override + public BuildStep post(Post post) { + this.post = new LoadedModelReferenceImpl<>(post); + return this; + } + + /** + * @param id id + * @return Current Builder instance, for fluent method chaining + */ + public BuildStep id(String id) { + this.id = id; + return this; + } + } + + + public final class CopyOfBuilder extends Builder { + private CopyOfBuilder(String id, ModelReference post, String content) { + super(id, post, content); + Objects.requireNonNull(content); + } + + @Override + public CopyOfBuilder content(String content) { + return (CopyOfBuilder) super.content(content); + } + + @Override + public CopyOfBuilder post(Post post) { + return (CopyOfBuilder) super.post(post); + } + } + + + public static class CommentIdentifier extends ModelIdentifier { + private static final long serialVersionUID = 1L; + public CommentIdentifier(String id) { + super(id); + } + } + +} +", + "com/amplifyframework/datastore/generated/model/CommentPath.java": "package com.amplifyframework.datastore.generated.model; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import com.amplifyframework.core.model.ModelPath; +import com.amplifyframework.core.model.PropertyPath; + +/** This is an auto generated class representing the ModelPath for the Comment type in your schema. */ +public final class CommentPath extends ModelPath { + private PostPath post; + CommentPath(@NonNull String name, @NonNull Boolean isCollection, @Nullable PropertyPath parent) { + super(name, isCollection, parent, Comment.class); + } + + public synchronized PostPath getPost() { + if (post == null) { + post = new PostPath(\\"post\\", false, this); + } + return post; + } +} +", + "com/amplifyframework/datastore/generated/model/Post.java": "package com.amplifyframework.datastore.generated.model; + +import com.amplifyframework.core.model.annotations.BelongsTo; +import com.amplifyframework.core.model.ModelReference; +import com.amplifyframework.core.model.LoadedModelReferenceImpl; +import com.amplifyframework.core.model.annotations.HasMany; +import com.amplifyframework.core.model.ModelList; +import com.amplifyframework.core.model.temporal.Temporal; +import com.amplifyframework.core.model.ModelIdentifier; + +import java.util.List; +import java.util.UUID; +import java.util.Objects; + +import androidx.core.util.ObjectsCompat; + +import com.amplifyframework.core.model.Model; +import com.amplifyframework.core.model.annotations.Index; +import com.amplifyframework.core.model.annotations.ModelConfig; +import com.amplifyframework.core.model.annotations.ModelField; +import com.amplifyframework.core.model.query.predicate.QueryField; + +import static com.amplifyframework.core.model.query.predicate.QueryField.field; + +/** This is an auto generated class representing the Post type in your schema. */ +@SuppressWarnings(\\"all\\") +@ModelConfig(pluralName = \\"Posts\\", type = Model.Type.USER, version = 1, hasLazySupport = true) +public final class Post implements Model { + public static final PostPath rootPath = new PostPath(\\"root\\", false, null); + public static final QueryField ID = field(\\"Post\\", \\"id\\"); + public static final QueryField TITLE = field(\\"Post\\", \\"title\\"); + public static final QueryField BLOG = field(\\"Post\\", \\"blogPostsId\\"); + private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; + private final @ModelField(targetType=\\"String\\", isRequired = true) String title; + private final @ModelField(targetType=\\"Blog\\") @BelongsTo(targetName = \\"blogPostsId\\", targetNames = {\\"blogPostsId\\"}, type = Blog.class) ModelReference blog; + private final @ModelField(targetType=\\"Comment\\") @HasMany(associatedWith = \\"post\\", type = Comment.class) ModelList comments = null; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; + /** @deprecated This API is internal to Amplify and should not be used. */ + @Deprecated + public String resolveIdentifier() { + return id; + } + + public String getId() { + return id; + } + + public String getTitle() { + return title; + } + + public ModelReference getBlog() { + return blog; + } + + public ModelList getComments() { + return comments; + } + + public Temporal.DateTime getCreatedAt() { + return createdAt; + } + + public Temporal.DateTime getUpdatedAt() { + return updatedAt; + } + + private Post(String id, String title, ModelReference blog) { + this.id = id; + this.title = title; + this.blog = blog; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if(obj == null || getClass() != obj.getClass()) { + return false; + } else { + Post post = (Post) obj; + return ObjectsCompat.equals(getId(), post.getId()) && + ObjectsCompat.equals(getTitle(), post.getTitle()) && + ObjectsCompat.equals(getBlog(), post.getBlog()) && + ObjectsCompat.equals(getCreatedAt(), post.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), post.getUpdatedAt()); + } + } + + @Override + public int hashCode() { + return new StringBuilder() + .append(getId()) + .append(getTitle()) + .append(getBlog()) + .append(getCreatedAt()) + .append(getUpdatedAt()) + .toString() + .hashCode(); + } + + @Override + public String toString() { + return new StringBuilder() + .append(\\"Post {\\") + .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") + .append(\\"title=\\" + String.valueOf(getTitle()) + \\", \\") + .append(\\"blog=\\" + String.valueOf(getBlog()) + \\", \\") + .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) + .append(\\"}\\") + .toString(); + } + + public static TitleStep builder() { + return new Builder(); + } + + /** + * WARNING: This method should not be used to build an instance of this object for a CREATE mutation. + * This is a convenience method to return an instance of the object with only its ID populated + * to be used in the context of a parameter in a delete mutation or referencing a foreign key + * in a relationship. + * @param id the id of the existing item this instance will represent + * @return an instance of this model with only ID populated + */ + public static Post justId(String id) { + return new Post( + id, + null, + null + ); + } + + public CopyOfBuilder copyOfBuilder() { + return new CopyOfBuilder(id, + title, + blog); + } + public interface TitleStep { + BuildStep title(String title); + } + + + public interface BuildStep { + Post build(); + BuildStep id(String id); + BuildStep blog(Blog blog); + } + + + public static class Builder implements TitleStep, BuildStep { + private String id; + private String title; + private ModelReference blog; + public Builder() { + + } + + private Builder(String id, String title, ModelReference blog) { + this.id = id; + this.title = title; + this.blog = blog; + } + + @Override + public Post build() { + String id = this.id != null ? this.id : UUID.randomUUID().toString(); + + return new Post( + id, + title, + blog); + } + + @Override + public BuildStep title(String title) { + Objects.requireNonNull(title); + this.title = title; + return this; + } + + @Override + public BuildStep blog(Blog blog) { + this.blog = new LoadedModelReferenceImpl<>(blog); + return this; + } + + /** + * @param id id + * @return Current Builder instance, for fluent method chaining + */ + public BuildStep id(String id) { + this.id = id; + return this; + } + } + + + public final class CopyOfBuilder extends Builder { + private CopyOfBuilder(String id, String title, ModelReference blog) { + super(id, title, blog); + Objects.requireNonNull(title); + } + + @Override + public CopyOfBuilder title(String title) { + return (CopyOfBuilder) super.title(title); + } + + @Override + public CopyOfBuilder blog(Blog blog) { + return (CopyOfBuilder) super.blog(blog); + } + } + + + public static class PostIdentifier extends ModelIdentifier { + private static final long serialVersionUID = 1L; + public PostIdentifier(String id) { + super(id); + } + } + +} +", + "com/amplifyframework/datastore/generated/model/PostPath.java": "package com.amplifyframework.datastore.generated.model; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import com.amplifyframework.core.model.ModelPath; +import com.amplifyframework.core.model.PropertyPath; + +/** This is an auto generated class representing the ModelPath for the Post type in your schema. */ +public final class PostPath extends ModelPath { + private BlogPath blog; + private CommentPath comments; + PostPath(@NonNull String name, @NonNull Boolean isCollection, @Nullable PropertyPath parent) { + super(name, isCollection, parent, Post.class); + } + + public synchronized BlogPath getBlog() { + if (blog == null) { + blog = new BlogPath(\\"blog\\", false, this); + } + return blog; + } + + public synchronized CommentPath getComments() { + if (comments == null) { + comments = new CommentPath(\\"comments\\", true, this); + } + return comments; + } +} +", +} +`; + +exports[`generateModels with targets basic 8`] = ` +Object { + "AmplifyModels.swift": "// swiftlint:disable all +import Amplify +import Foundation + +// Contains the set of classes that conforms to the \`Model\` protocol. + +final public class AmplifyModels: AmplifyModelRegistration { + public let version: String = \\"165944a36979cd395e3b22145bbfeff0\\" + + public func registerModels(registry: ModelRegistry.Type) { + ModelRegistry.register(modelType: Blog.self) + ModelRegistry.register(modelType: Post.self) + ModelRegistry.register(modelType: Comment.self) + } +}", + "Blog+Schema.swift": "// swiftlint:disable all +import Amplify +import Foundation + +extension Blog { + // MARK: - CodingKeys + public enum CodingKeys: String, ModelKey { + case id + case name + case posts + case createdAt + case updatedAt + } + + public static let keys = CodingKeys.self + // MARK: - ModelSchema + + public static let schema = defineSchema { model in + let blog = Blog.keys + + model.listPluralName = \\"Blogs\\" + model.syncPluralName = \\"Blogs\\" + + model.attributes( + .primaryKey(fields: [blog.id]) + ) + + model.fields( + .field(blog.id, is: .required, ofType: .string), + .field(blog.name, is: .required, ofType: .string), + .hasMany(blog.posts, is: .optional, ofType: Post.self, associatedWith: Post.keys.blog), + .field(blog.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime), + .field(blog.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime) + ) + } + public class Path: ModelPath { } + + public static var rootPath: PropertyContainerPath? { Path() } +} + +extension Blog: ModelIdentifiable { + public typealias IdentifierFormat = ModelIdentifierFormat.Default + public typealias IdentifierProtocol = DefaultModelIdentifier +} +extension ModelPath where ModelType == Blog { + public var id: FieldPath { + string(\\"id\\") + } + public var name: FieldPath { + string(\\"name\\") + } + public var posts: ModelPath { + Post.Path(name: \\"posts\\", isCollection: true, parent: self) + } + public var createdAt: FieldPath { + datetime(\\"createdAt\\") + } + public var updatedAt: FieldPath { + datetime(\\"updatedAt\\") + } +}", + "Blog.swift": "// swiftlint:disable all +import Amplify +import Foundation + +public struct Blog: Model { + public let id: String + public var name: String + public var posts: List? + public var createdAt: Temporal.DateTime? + public var updatedAt: Temporal.DateTime? + + public init(id: String = UUID().uuidString, + name: String, + posts: List? = []) { + self.init(id: id, + name: name, + posts: posts, + createdAt: nil, + updatedAt: nil) + } + internal init(id: String = UUID().uuidString, + name: String, + posts: List? = [], + createdAt: Temporal.DateTime? = nil, + updatedAt: Temporal.DateTime? = nil) { + self.id = id + self.name = name + self.posts = posts + self.createdAt = createdAt + self.updatedAt = updatedAt + } +}", + "Comment+Schema.swift": "// swiftlint:disable all +import Amplify +import Foundation + +extension Comment { + // MARK: - CodingKeys + public enum CodingKeys: String, ModelKey { + case id + case post + case content + case createdAt + case updatedAt + } + + public static let keys = CodingKeys.self + // MARK: - ModelSchema + + public static let schema = defineSchema { model in + let comment = Comment.keys + + model.listPluralName = \\"Comments\\" + model.syncPluralName = \\"Comments\\" + + model.attributes( + .primaryKey(fields: [comment.id]) + ) + + model.fields( + .field(comment.id, is: .required, ofType: .string), + .belongsTo(comment.post, is: .optional, ofType: Post.self, targetNames: [\\"postCommentsId\\"]), + .field(comment.content, is: .required, ofType: .string), + .field(comment.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime), + .field(comment.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime) + ) + } + public class Path: ModelPath { } + + public static var rootPath: PropertyContainerPath? { Path() } +} + +extension Comment: ModelIdentifiable { + public typealias IdentifierFormat = ModelIdentifierFormat.Default + public typealias IdentifierProtocol = DefaultModelIdentifier +} +extension ModelPath where ModelType == Comment { + public var id: FieldPath { + string(\\"id\\") + } + public var post: ModelPath { + Post.Path(name: \\"post\\", parent: self) + } + public var content: FieldPath { + string(\\"content\\") + } + public var createdAt: FieldPath { + datetime(\\"createdAt\\") + } + public var updatedAt: FieldPath { + datetime(\\"updatedAt\\") + } +}", + "Comment.swift": "// swiftlint:disable all +import Amplify +import Foundation + +public struct Comment: Model { + public let id: String + internal var _post: LazyReference + public var post: Post? { + get async throws { + try await _post.get() + } + } + public var content: String + public var createdAt: Temporal.DateTime? + public var updatedAt: Temporal.DateTime? + + public init(id: String = UUID().uuidString, + post: Post? = nil, + content: String) { + self.init(id: id, + post: post, + content: content, + createdAt: nil, + updatedAt: nil) + } + internal init(id: String = UUID().uuidString, + post: Post? = nil, + content: String, + createdAt: Temporal.DateTime? = nil, + updatedAt: Temporal.DateTime? = nil) { + self.id = id + self._post = LazyReference(post) + self.content = content + self.createdAt = createdAt + self.updatedAt = updatedAt + } + public mutating func setPost(_ post: Post? = nil) { + self._post = LazyReference(post) + } + public init(from decoder: Decoder) throws { + let values = try decoder.container(keyedBy: CodingKeys.self) + id = try values.decode(String.self, forKey: .id) + _post = try values.decodeIfPresent(LazyReference.self, forKey: .post) ?? LazyReference(identifiers: nil) + content = try values.decode(String.self, forKey: .content) + createdAt = try? values.decode(Temporal.DateTime?.self, forKey: .createdAt) + updatedAt = try? values.decode(Temporal.DateTime?.self, forKey: .updatedAt) + } + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(id, forKey: .id) + try container.encode(_post, forKey: .post) + try container.encode(content, forKey: .content) + try container.encode(createdAt, forKey: .createdAt) + try container.encode(updatedAt, forKey: .updatedAt) + } +}", + "Post+Schema.swift": "// swiftlint:disable all +import Amplify +import Foundation + +extension Post { + // MARK: - CodingKeys + public enum CodingKeys: String, ModelKey { + case id + case title + case blog + case comments + case createdAt + case updatedAt + } + + public static let keys = CodingKeys.self + // MARK: - ModelSchema + + public static let schema = defineSchema { model in + let post = Post.keys + + model.listPluralName = \\"Posts\\" + model.syncPluralName = \\"Posts\\" + + model.attributes( + .primaryKey(fields: [post.id]) + ) + + model.fields( + .field(post.id, is: .required, ofType: .string), + .field(post.title, is: .required, ofType: .string), + .belongsTo(post.blog, is: .optional, ofType: Blog.self, targetNames: [\\"blogPostsId\\"]), + .hasMany(post.comments, is: .optional, ofType: Comment.self, associatedWith: Comment.keys.post), + .field(post.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime), + .field(post.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime) + ) + } + public class Path: ModelPath { } + + public static var rootPath: PropertyContainerPath? { Path() } +} + +extension Post: ModelIdentifiable { + public typealias IdentifierFormat = ModelIdentifierFormat.Default + public typealias IdentifierProtocol = DefaultModelIdentifier +} +extension ModelPath where ModelType == Post { + public var id: FieldPath { + string(\\"id\\") + } + public var title: FieldPath { + string(\\"title\\") + } + public var blog: ModelPath { + Blog.Path(name: \\"blog\\", parent: self) + } + public var comments: ModelPath { + Comment.Path(name: \\"comments\\", isCollection: true, parent: self) + } + public var createdAt: FieldPath { + datetime(\\"createdAt\\") + } + public var updatedAt: FieldPath { + datetime(\\"updatedAt\\") + } +}", + "Post.swift": "// swiftlint:disable all +import Amplify +import Foundation + +public struct Post: Model { + public let id: String + public var title: String + internal var _blog: LazyReference + public var blog: Blog? { + get async throws { + try await _blog.get() + } + } + public var comments: List? + public var createdAt: Temporal.DateTime? + public var updatedAt: Temporal.DateTime? + + public init(id: String = UUID().uuidString, + title: String, + blog: Blog? = nil, + comments: List? = []) { + self.init(id: id, + title: title, + blog: blog, + comments: comments, + createdAt: nil, + updatedAt: nil) + } + internal init(id: String = UUID().uuidString, + title: String, + blog: Blog? = nil, + comments: List? = [], + createdAt: Temporal.DateTime? = nil, + updatedAt: Temporal.DateTime? = nil) { + self.id = id + self.title = title + self._blog = LazyReference(blog) + self.comments = comments + self.createdAt = createdAt + self.updatedAt = updatedAt + } + public mutating func setBlog(_ blog: Blog? = nil) { + self._blog = LazyReference(blog) + } + public init(from decoder: Decoder) throws { + let values = try decoder.container(keyedBy: CodingKeys.self) + id = try values.decode(String.self, forKey: .id) + title = try values.decode(String.self, forKey: .title) + _blog = try values.decodeIfPresent(LazyReference.self, forKey: .blog) ?? LazyReference(identifiers: nil) + comments = try values.decodeIfPresent(List?.self, forKey: .comments) ?? .init() + createdAt = try? values.decode(Temporal.DateTime?.self, forKey: .createdAt) + updatedAt = try? values.decode(Temporal.DateTime?.self, forKey: .updatedAt) + } + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(id, forKey: .id) + try container.encode(title, forKey: .title) + try container.encode(_blog, forKey: .blog) + try container.encode(comments, forKey: .comments) + try container.encode(createdAt, forKey: .createdAt) + try container.encode(updatedAt, forKey: .updatedAt) + } +}", +} +`; + +exports[`generateModels with targets basic 9`] = ` +Object { + "index.d.ts": "import { ModelInit, MutableModel, __modelMeta__, ManagedIdentifier } from \\"@aws-amplify/datastore\\"; +// @ts-ignore +import { LazyLoading, LazyLoadingDisabled, AsyncCollection, AsyncItem } from \\"@aws-amplify/datastore\\"; + + + + + +type EagerBlog = { + readonly [__modelMeta__]: { + identifier: ManagedIdentifier; + readOnlyFields: 'createdAt' | 'updatedAt'; + }; + readonly id: string; + readonly name: string; + readonly posts?: (Post | null)[] | null; + readonly createdAt?: string | null; + readonly updatedAt?: string | null; +} + +type LazyBlog = { + readonly [__modelMeta__]: { + identifier: ManagedIdentifier; + readOnlyFields: 'createdAt' | 'updatedAt'; + }; + readonly id: string; + readonly name: string; + readonly posts: AsyncCollection; + readonly createdAt?: string | null; + readonly updatedAt?: string | null; +} + +export declare type Blog = LazyLoading extends LazyLoadingDisabled ? EagerBlog : LazyBlog + +export declare const Blog: (new (init: ModelInit) => Blog) & { + copyOf(source: Blog, mutator: (draft: MutableModel) => MutableModel | void): Blog; +} + +type EagerPost = { + readonly [__modelMeta__]: { + identifier: ManagedIdentifier; + readOnlyFields: 'createdAt' | 'updatedAt'; + }; + readonly id: string; + readonly title: string; + readonly blog?: Blog | null; + readonly comments?: (Comment | null)[] | null; + readonly createdAt?: string | null; + readonly updatedAt?: string | null; + readonly blogPostsId?: string | null; +} + +type LazyPost = { + readonly [__modelMeta__]: { + identifier: ManagedIdentifier; + readOnlyFields: 'createdAt' | 'updatedAt'; + }; + readonly id: string; + readonly title: string; + readonly blog: AsyncItem; + readonly comments: AsyncCollection; + readonly createdAt?: string | null; + readonly updatedAt?: string | null; + readonly blogPostsId?: string | null; +} + +export declare type Post = LazyLoading extends LazyLoadingDisabled ? EagerPost : LazyPost + +export declare const Post: (new (init: ModelInit) => Post) & { + copyOf(source: Post, mutator: (draft: MutableModel) => MutableModel | void): Post; +} + +type EagerComment = { + readonly [__modelMeta__]: { + identifier: ManagedIdentifier; + readOnlyFields: 'createdAt' | 'updatedAt'; + }; + readonly id: string; + readonly post?: Post | null; + readonly content: string; + readonly createdAt?: string | null; + readonly updatedAt?: string | null; + readonly postCommentsId?: string | null; +} + +type LazyComment = { + readonly [__modelMeta__]: { + identifier: ManagedIdentifier; + readOnlyFields: 'createdAt' | 'updatedAt'; + }; + readonly id: string; + readonly post: AsyncItem; + readonly content: string; + readonly createdAt?: string | null; + readonly updatedAt?: string | null; + readonly postCommentsId?: string | null; +} + +export declare type Comment = LazyLoading extends LazyLoadingDisabled ? EagerComment : LazyComment + +export declare const Comment: (new (init: ModelInit) => Comment) & { + copyOf(source: Comment, mutator: (draft: MutableModel) => MutableModel | void): Comment; +}", + "index.js": "// @ts-check +import { initSchema } from '@aws-amplify/datastore'; +import { schema } from './schema'; + + + +const { Blog, Post, Comment } = initSchema(schema); + +export { + Blog, + Post, + Comment +};", + "schema.d.ts": "import { Schema } from '@aws-amplify/datastore'; + +export declare const schema: Schema;", + "schema.js": "export const schema = { + \\"models\\": { + \\"Blog\\": { + \\"name\\": \\"Blog\\", + \\"fields\\": { + \\"id\\": { + \\"name\\": \\"id\\", + \\"isArray\\": false, + \\"type\\": \\"ID\\", + \\"isRequired\\": true, + \\"attributes\\": [] + }, + \\"name\\": { + \\"name\\": \\"name\\", + \\"isArray\\": false, + \\"type\\": \\"String\\", + \\"isRequired\\": true, + \\"attributes\\": [] + }, + \\"posts\\": { + \\"name\\": \\"posts\\", + \\"isArray\\": true, + \\"type\\": { + \\"model\\": \\"Post\\" + }, + \\"isRequired\\": false, + \\"attributes\\": [], + \\"isArrayNullable\\": true, + \\"association\\": { + \\"connectionType\\": \\"HAS_MANY\\", + \\"associatedWith\\": [ + \\"blogPostsId\\" + ] + } + }, + \\"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\\": \\"Blogs\\", + \\"attributes\\": [ + { + \\"type\\": \\"model\\", + \\"properties\\": {} + } + ] + }, + \\"Post\\": { + \\"name\\": \\"Post\\", + \\"fields\\": { + \\"id\\": { + \\"name\\": \\"id\\", + \\"isArray\\": false, + \\"type\\": \\"ID\\", + \\"isRequired\\": true, + \\"attributes\\": [] + }, + \\"title\\": { + \\"name\\": \\"title\\", + \\"isArray\\": false, + \\"type\\": \\"String\\", + \\"isRequired\\": true, + \\"attributes\\": [] + }, + \\"blog\\": { + \\"name\\": \\"blog\\", + \\"isArray\\": false, + \\"type\\": { + \\"model\\": \\"Blog\\" + }, + \\"isRequired\\": false, + \\"attributes\\": [], + \\"association\\": { + \\"connectionType\\": \\"BELONGS_TO\\", + \\"targetNames\\": [ + \\"blogPostsId\\" + ] + } + }, + \\"comments\\": { + \\"name\\": \\"comments\\", + \\"isArray\\": true, + \\"type\\": { + \\"model\\": \\"Comment\\" + }, + \\"isRequired\\": false, + \\"attributes\\": [], + \\"isArrayNullable\\": true, + \\"association\\": { + \\"connectionType\\": \\"HAS_MANY\\", + \\"associatedWith\\": [ + \\"postCommentsId\\" + ] + } + }, + \\"createdAt\\": { + \\"name\\": \\"createdAt\\", + \\"isArray\\": false, + \\"type\\": \\"AWSDateTime\\", + \\"isRequired\\": false, + \\"attributes\\": [], + \\"isReadOnly\\": true + }, + \\"updatedAt\\": { + \\"name\\": \\"updatedAt\\", + \\"isArray\\": false, + \\"type\\": \\"AWSDateTime\\", + \\"isRequired\\": false, + \\"attributes\\": [], + \\"isReadOnly\\": true + }, + \\"blogPostsId\\": { + \\"name\\": \\"blogPostsId\\", + \\"isArray\\": false, + \\"type\\": \\"ID\\", + \\"isRequired\\": false, + \\"attributes\\": [] + } + }, + \\"syncable\\": true, + \\"pluralName\\": \\"Posts\\", + \\"attributes\\": [ + { + \\"type\\": \\"model\\", + \\"properties\\": {} + } + ] + }, + \\"Comment\\": { + \\"name\\": \\"Comment\\", + \\"fields\\": { + \\"id\\": { + \\"name\\": \\"id\\", + \\"isArray\\": false, + \\"type\\": \\"ID\\", + \\"isRequired\\": true, + \\"attributes\\": [] + }, + \\"post\\": { + \\"name\\": \\"post\\", + \\"isArray\\": false, + \\"type\\": { + \\"model\\": \\"Post\\" + }, + \\"isRequired\\": false, + \\"attributes\\": [], + \\"association\\": { + \\"connectionType\\": \\"BELONGS_TO\\", + \\"targetNames\\": [ + \\"postCommentsId\\" + ] + } + }, + \\"content\\": { + \\"name\\": \\"content\\", + \\"isArray\\": false, + \\"type\\": \\"String\\", + \\"isRequired\\": true, + \\"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 + }, + \\"postCommentsId\\": { + \\"name\\": \\"postCommentsId\\", + \\"isArray\\": false, + \\"type\\": \\"ID\\", + \\"isRequired\\": false, + \\"attributes\\": [] + } + }, + \\"syncable\\": true, + \\"pluralName\\": \\"Comments\\", + \\"attributes\\": [ + { + \\"type\\": \\"model\\", + \\"properties\\": {} + } + ] + } + }, + \\"enums\\": {}, + \\"nonModels\\": {}, + \\"codegenVersion\\": \\"3.4.4\\", + \\"version\\": \\"920118e6cbedacf9fdf58bb983d59a94\\" +};", +} +`; + +exports[`generateModels with targets basic 10`] = ` +Object { + "index.ts": "import { ModelInit, MutableModel, PersistentModelConstructor } from \\"@aws-amplify/datastore\\"; +import { initSchema } from \\"@aws-amplify/datastore\\"; + +import { schema } from \\"./schema\\"; + + + +type EagerBlogModel = { + readonly [__modelMeta__]: { + identifier: ManagedIdentifier; + readOnlyFields: 'createdAt' | 'updatedAt'; + }; + readonly id: string; + readonly name: string; + readonly posts?: (PostModel | null)[] | null; + readonly createdAt?: string | null; + readonly updatedAt?: string | null; +} + +type LazyBlogModel = { + readonly [__modelMeta__]: { + identifier: ManagedIdentifier; + readOnlyFields: 'createdAt' | 'updatedAt'; + }; + readonly id: string; + readonly name: string; + readonly posts: AsyncCollection; + readonly createdAt?: string | null; + readonly updatedAt?: string | null; +} + +export declare type BlogModel = LazyLoading extends LazyLoadingDisabled ? EagerBlogModel : LazyBlogModel + +export declare const BlogModel: (new (init: ModelInit) => BlogModel) & { + copyOf(source: BlogModel, mutator: (draft: MutableModel) => MutableModel | void): BlogModel; +} + +type EagerPostModel = { + readonly [__modelMeta__]: { + identifier: ManagedIdentifier; + readOnlyFields: 'createdAt' | 'updatedAt'; + }; + readonly id: string; + readonly title: string; + readonly blog?: BlogModel | null; + readonly comments?: (CommentModel | null)[] | null; + readonly createdAt?: string | null; + readonly updatedAt?: string | null; + readonly blogPostsId?: string | null; +} + +type LazyPostModel = { + readonly [__modelMeta__]: { + identifier: ManagedIdentifier; + readOnlyFields: 'createdAt' | 'updatedAt'; + }; + readonly id: string; + readonly title: string; + readonly blog: AsyncItem; + readonly comments: AsyncCollection; + readonly createdAt?: string | null; + readonly updatedAt?: string | null; + readonly blogPostsId?: string | null; +} + +export declare type PostModel = LazyLoading extends LazyLoadingDisabled ? EagerPostModel : LazyPostModel + +export declare const PostModel: (new (init: ModelInit) => PostModel) & { + copyOf(source: PostModel, mutator: (draft: MutableModel) => MutableModel | void): PostModel; +} + +type EagerCommentModel = { + readonly [__modelMeta__]: { + identifier: ManagedIdentifier; + readOnlyFields: 'createdAt' | 'updatedAt'; + }; + readonly id: string; + readonly post?: PostModel | null; + readonly content: string; + readonly createdAt?: string | null; + readonly updatedAt?: string | null; + readonly postCommentsId?: string | null; +} + +type LazyCommentModel = { + readonly [__modelMeta__]: { + identifier: ManagedIdentifier; + readOnlyFields: 'createdAt' | 'updatedAt'; + }; + readonly id: string; + readonly post: AsyncItem; + readonly content: string; + readonly createdAt?: string | null; + readonly updatedAt?: string | null; + readonly postCommentsId?: string | null; +} + +export declare type CommentModel = LazyLoading extends LazyLoadingDisabled ? EagerCommentModel : LazyCommentModel + +export declare const CommentModel: (new (init: ModelInit) => CommentModel) & { + copyOf(source: CommentModel, mutator: (draft: MutableModel) => MutableModel | void): CommentModel; +} + + + +const { Blog, Post, Comment } = initSchema(schema) as { + Blog: PersistentModelConstructor; + Post: PersistentModelConstructor; + Comment: PersistentModelConstructor; +}; + +export { + Blog, + Post, + Comment +};", + "schema.ts": "import { Schema } from \\"@aws-amplify/datastore\\"; + +export const schema: Schema = { + \\"models\\": { + \\"Blog\\": { + \\"name\\": \\"Blog\\", + \\"fields\\": { + \\"id\\": { + \\"name\\": \\"id\\", + \\"isArray\\": false, + \\"type\\": \\"ID\\", + \\"isRequired\\": true, + \\"attributes\\": [] + }, + \\"name\\": { + \\"name\\": \\"name\\", + \\"isArray\\": false, + \\"type\\": \\"String\\", + \\"isRequired\\": true, + \\"attributes\\": [] + }, + \\"posts\\": { + \\"name\\": \\"posts\\", + \\"isArray\\": true, + \\"type\\": { + \\"model\\": \\"Post\\" + }, + \\"isRequired\\": false, + \\"attributes\\": [], + \\"isArrayNullable\\": true, + \\"association\\": { + \\"connectionType\\": \\"HAS_MANY\\", + \\"associatedWith\\": [ + \\"blogPostsId\\" + ] + } + }, + \\"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\\": \\"Blogs\\", + \\"attributes\\": [ + { + \\"type\\": \\"model\\", + \\"properties\\": {} + } + ] + }, + \\"Post\\": { + \\"name\\": \\"Post\\", + \\"fields\\": { + \\"id\\": { + \\"name\\": \\"id\\", + \\"isArray\\": false, + \\"type\\": \\"ID\\", + \\"isRequired\\": true, + \\"attributes\\": [] + }, + \\"title\\": { + \\"name\\": \\"title\\", + \\"isArray\\": false, + \\"type\\": \\"String\\", + \\"isRequired\\": true, + \\"attributes\\": [] + }, + \\"blog\\": { + \\"name\\": \\"blog\\", + \\"isArray\\": false, + \\"type\\": { + \\"model\\": \\"Blog\\" + }, + \\"isRequired\\": false, + \\"attributes\\": [], + \\"association\\": { + \\"connectionType\\": \\"BELONGS_TO\\", + \\"targetNames\\": [ + \\"blogPostsId\\" + ] + } + }, + \\"comments\\": { + \\"name\\": \\"comments\\", + \\"isArray\\": true, + \\"type\\": { + \\"model\\": \\"Comment\\" + }, + \\"isRequired\\": false, + \\"attributes\\": [], + \\"isArrayNullable\\": true, + \\"association\\": { + \\"connectionType\\": \\"HAS_MANY\\", + \\"associatedWith\\": [ + \\"postCommentsId\\" + ] + } + }, + \\"createdAt\\": { + \\"name\\": \\"createdAt\\", + \\"isArray\\": false, + \\"type\\": \\"AWSDateTime\\", + \\"isRequired\\": false, + \\"attributes\\": [], + \\"isReadOnly\\": true + }, + \\"updatedAt\\": { + \\"name\\": \\"updatedAt\\", + \\"isArray\\": false, + \\"type\\": \\"AWSDateTime\\", + \\"isRequired\\": false, + \\"attributes\\": [], + \\"isReadOnly\\": true + }, + \\"blogPostsId\\": { + \\"name\\": \\"blogPostsId\\", + \\"isArray\\": false, + \\"type\\": \\"ID\\", + \\"isRequired\\": false, + \\"attributes\\": [] + } + }, + \\"syncable\\": true, + \\"pluralName\\": \\"Posts\\", + \\"attributes\\": [ + { + \\"type\\": \\"model\\", + \\"properties\\": {} + } + ] + }, + \\"Comment\\": { + \\"name\\": \\"Comment\\", + \\"fields\\": { + \\"id\\": { + \\"name\\": \\"id\\", + \\"isArray\\": false, + \\"type\\": \\"ID\\", + \\"isRequired\\": true, + \\"attributes\\": [] + }, + \\"post\\": { + \\"name\\": \\"post\\", + \\"isArray\\": false, + \\"type\\": { + \\"model\\": \\"Post\\" + }, + \\"isRequired\\": false, + \\"attributes\\": [], + \\"association\\": { + \\"connectionType\\": \\"BELONGS_TO\\", + \\"targetNames\\": [ + \\"postCommentsId\\" + ] + } + }, + \\"content\\": { + \\"name\\": \\"content\\", + \\"isArray\\": false, + \\"type\\": \\"String\\", + \\"isRequired\\": true, + \\"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 + }, + \\"postCommentsId\\": { + \\"name\\": \\"postCommentsId\\", + \\"isArray\\": false, + \\"type\\": \\"ID\\", + \\"isRequired\\": false, + \\"attributes\\": [] + } + }, + \\"syncable\\": true, + \\"pluralName\\": \\"Comments\\", + \\"attributes\\": [ + { + \\"type\\": \\"model\\", + \\"properties\\": {} + } + ] + } + }, + \\"enums\\": {}, + \\"nonModels\\": {}, + \\"codegenVersion\\": \\"3.4.4\\", + \\"version\\": \\"920118e6cbedacf9fdf58bb983d59a94\\" +};", +} +`; + +exports[`generateModels with targets basic 11`] = ` +Object { + "Blog.dart": "/* +* Copyright 2021 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. +* A copy of the License is located at +* +* http://aws.amazon.com/apache2.0 +* +* or in the \\"license\\" file accompanying this file. This file 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. +*/ + +// NOTE: This file is generated and may not follow lint rules defined in your app +// Generated files can be excluded from analysis in analysis_options.yaml +// For more info, see: https://dart.dev/guides/language/analysis-options#excluding-code-from-analysis + +// ignore_for_file: public_member_api_docs, annotate_overrides, dead_code, dead_codepublic_member_api_docs, depend_on_referenced_packages, file_names, library_private_types_in_public_api, no_leading_underscores_for_library_prefixes, no_leading_underscores_for_local_identifiers, non_constant_identifier_names, null_check_on_nullable_type_parameter, override_on_non_overriding_member, prefer_adjacent_string_concatenation, prefer_const_constructors, prefer_if_null_operators, prefer_interpolation_to_compose_strings, slash_for_doc_comments, sort_child_properties_last, unnecessary_const, unnecessary_constructor_name, unnecessary_late, unnecessary_new, unnecessary_null_aware_assignments, unnecessary_nullable_for_final_variable_declarations, unnecessary_string_interpolations, use_build_context_synchronously + +import 'ModelProvider.dart'; +import 'package:amplify_core/amplify_core.dart' as amplify_core; +import 'package:collection/collection.dart'; + + +/** This is an auto generated class representing the Blog type in your schema. */ +class Blog extends amplify_core.Model { + static const classType = const _BlogModelType(); + final String id; + final String? _name; + final List? _posts; + final amplify_core.TemporalDateTime? _createdAt; + final amplify_core.TemporalDateTime? _updatedAt; + + @override + getInstanceType() => classType; + + @Deprecated('[getId] is being deprecated in favor of custom primary key feature. Use getter [modelIdentifier] to get model identifier.') + @override + String getId() => id; + + BlogModelIdentifier get modelIdentifier { + return BlogModelIdentifier( + id: id + ); + } + + String get name { + try { + return _name!; + } catch(e) { + throw amplify_core.AmplifyCodeGenModelException( + amplify_core.AmplifyExceptionMessages.codeGenRequiredFieldForceCastExceptionMessage, + recoverySuggestion: + amplify_core.AmplifyExceptionMessages.codeGenRequiredFieldForceCastRecoverySuggestion, + underlyingException: e.toString() + ); + } + } + + List? get posts { + return _posts; + } + + amplify_core.TemporalDateTime? get createdAt { + return _createdAt; + } + + amplify_core.TemporalDateTime? get updatedAt { + return _updatedAt; + } + + const Blog._internal({required this.id, required name, posts, createdAt, updatedAt}): _name = name, _posts = posts, _createdAt = createdAt, _updatedAt = updatedAt; + + factory Blog({String? id, required String name, List? posts}) { + return Blog._internal( + id: id == null ? amplify_core.UUID.getUUID() : id, + name: name, + posts: posts != null ? List.unmodifiable(posts) : posts); + } + + bool equals(Object other) { + return this == other; + } + + @override + bool operator ==(Object other) { + if (identical(other, this)) return true; + return other is Blog && + id == other.id && + _name == other._name && + DeepCollectionEquality().equals(_posts, other._posts); + } + + @override + int get hashCode => toString().hashCode; + + @override + String toString() { + var buffer = new StringBuffer(); + + buffer.write(\\"Blog {\\"); + buffer.write(\\"id=\\" + \\"$id\\" + \\", \\"); + buffer.write(\\"name=\\" + \\"$_name\\" + \\", \\"); + buffer.write(\\"createdAt=\\" + (_createdAt != null ? _createdAt!.format() : \\"null\\") + \\", \\"); + buffer.write(\\"updatedAt=\\" + (_updatedAt != null ? _updatedAt!.format() : \\"null\\")); + buffer.write(\\"}\\"); + + return buffer.toString(); + } + + Blog copyWith({String? name, List? posts}) { + return Blog._internal( + id: id, + name: name ?? this.name, + posts: posts ?? this.posts); + } + + Blog copyWithModelFieldValues({ + ModelFieldValue? name, + ModelFieldValue?>? posts + }) { + return Blog._internal( + id: id, + name: name == null ? this.name : name.value, + posts: posts == null ? this.posts : posts.value + ); + } + + Blog.fromJson(Map json) + : id = json['id'], + _name = json['name'], + _posts = json['posts'] is Map + ? (json['posts']['items'] is List + ? (json['posts']['items'] as List) + .where((e) => e != null) + .map((e) => Post.fromJson(new Map.from(e))) + .toList() + : null) + : (json['posts'] is List + ? (json['posts'] as List) + .where((e) => e?['serializedData'] != null) + .map((e) => Post.fromJson(new Map.from(e?['serializedData']))) + .toList() + : null), + _createdAt = json['createdAt'] != null ? amplify_core.TemporalDateTime.fromString(json['createdAt']) : null, + _updatedAt = json['updatedAt'] != null ? amplify_core.TemporalDateTime.fromString(json['updatedAt']) : null; + + Map toJson() => { + 'id': id, 'name': _name, 'posts': _posts?.map((Post? e) => e?.toJson()).toList(), 'createdAt': _createdAt?.format(), 'updatedAt': _updatedAt?.format() + }; + + Map toMap() => { + 'id': id, + 'name': _name, + 'posts': _posts, + 'createdAt': _createdAt, + 'updatedAt': _updatedAt + }; + + static final amplify_core.QueryModelIdentifier MODEL_IDENTIFIER = amplify_core.QueryModelIdentifier(); + static final ID = amplify_core.QueryField(fieldName: \\"id\\"); + static final NAME = amplify_core.QueryField(fieldName: \\"name\\"); + static final POSTS = amplify_core.QueryField( + fieldName: \\"posts\\", + fieldType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.model, ofModelName: 'Post')); + static var schema = amplify_core.Model.defineSchema(define: (amplify_core.ModelSchemaDefinition modelSchemaDefinition) { + modelSchemaDefinition.name = \\"Blog\\"; + modelSchemaDefinition.pluralName = \\"Blogs\\"; + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.id()); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.field( + key: Blog.NAME, + isRequired: true, + ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.string) + )); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.hasMany( + key: Blog.POSTS, + isRequired: false, + ofModelName: 'Post', + associatedKey: Post.BLOG + )); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.nonQueryField( + fieldName: 'createdAt', + isRequired: false, + isReadOnly: true, + ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.dateTime) + )); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.nonQueryField( + fieldName: 'updatedAt', + isRequired: false, + isReadOnly: true, + ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.dateTime) + )); + }); +} + +class _BlogModelType extends amplify_core.ModelType { + const _BlogModelType(); + + @override + Blog fromJson(Map jsonData) { + return Blog.fromJson(jsonData); + } + + @override + String modelName() { + return 'Blog'; + } +} + +/** + * This is an auto generated class representing the model identifier + * of [Blog] in your schema. + */ +class BlogModelIdentifier implements amplify_core.ModelIdentifier { + final String id; + + /** Create an instance of BlogModelIdentifier using [id] the primary key. */ + const BlogModelIdentifier({ + required this.id}); + + @override + Map serializeAsMap() => ({ + 'id': id + }); + + @override + List> serializeAsList() => serializeAsMap() + .entries + .map((entry) => ({ entry.key: entry.value })) + .toList(); + + @override + String serializeAsString() => serializeAsMap().values.join('#'); + + @override + String toString() => 'BlogModelIdentifier(id: $id)'; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + + return other is BlogModelIdentifier && + id == other.id; + } + + @override + int get hashCode => + id.hashCode; +}", + "Comment.dart": "/* +* Copyright 2021 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. +* A copy of the License is located at +* +* http://aws.amazon.com/apache2.0 +* +* or in the \\"license\\" file accompanying this file. This file 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. +*/ + +// NOTE: This file is generated and may not follow lint rules defined in your app +// Generated files can be excluded from analysis in analysis_options.yaml +// For more info, see: https://dart.dev/guides/language/analysis-options#excluding-code-from-analysis + +// ignore_for_file: public_member_api_docs, annotate_overrides, dead_code, dead_codepublic_member_api_docs, depend_on_referenced_packages, file_names, library_private_types_in_public_api, no_leading_underscores_for_library_prefixes, no_leading_underscores_for_local_identifiers, non_constant_identifier_names, null_check_on_nullable_type_parameter, override_on_non_overriding_member, prefer_adjacent_string_concatenation, prefer_const_constructors, prefer_if_null_operators, prefer_interpolation_to_compose_strings, slash_for_doc_comments, sort_child_properties_last, unnecessary_const, unnecessary_constructor_name, unnecessary_late, unnecessary_new, unnecessary_null_aware_assignments, unnecessary_nullable_for_final_variable_declarations, unnecessary_string_interpolations, use_build_context_synchronously + +import 'ModelProvider.dart'; +import 'package:amplify_core/amplify_core.dart' as amplify_core; + + +/** This is an auto generated class representing the Comment type in your schema. */ +class Comment extends amplify_core.Model { + static const classType = const _CommentModelType(); + final String id; + final Post? _post; + final String? _content; + final amplify_core.TemporalDateTime? _createdAt; + final amplify_core.TemporalDateTime? _updatedAt; + + @override + getInstanceType() => classType; + + @Deprecated('[getId] is being deprecated in favor of custom primary key feature. Use getter [modelIdentifier] to get model identifier.') + @override + String getId() => id; + + CommentModelIdentifier get modelIdentifier { + return CommentModelIdentifier( + id: id + ); + } + + Post? get post { + return _post; + } + + String get content { + try { + return _content!; + } catch(e) { + throw amplify_core.AmplifyCodeGenModelException( + amplify_core.AmplifyExceptionMessages.codeGenRequiredFieldForceCastExceptionMessage, + recoverySuggestion: + amplify_core.AmplifyExceptionMessages.codeGenRequiredFieldForceCastRecoverySuggestion, + underlyingException: e.toString() + ); + } + } + + amplify_core.TemporalDateTime? get createdAt { + return _createdAt; + } + + amplify_core.TemporalDateTime? get updatedAt { + return _updatedAt; + } + + const Comment._internal({required this.id, post, required content, createdAt, updatedAt}): _post = post, _content = content, _createdAt = createdAt, _updatedAt = updatedAt; + + factory Comment({String? id, Post? post, required String content}) { + return Comment._internal( + id: id == null ? amplify_core.UUID.getUUID() : id, + post: post, + content: content); + } + + bool equals(Object other) { + return this == other; + } + + @override + bool operator ==(Object other) { + if (identical(other, this)) return true; + return other is Comment && + id == other.id && + _post == other._post && + _content == other._content; + } + + @override + int get hashCode => toString().hashCode; + + @override + String toString() { + var buffer = new StringBuffer(); + + buffer.write(\\"Comment {\\"); + buffer.write(\\"id=\\" + \\"$id\\" + \\", \\"); + buffer.write(\\"post=\\" + (_post != null ? _post!.toString() : \\"null\\") + \\", \\"); + buffer.write(\\"content=\\" + \\"$_content\\" + \\", \\"); + buffer.write(\\"createdAt=\\" + (_createdAt != null ? _createdAt!.format() : \\"null\\") + \\", \\"); + buffer.write(\\"updatedAt=\\" + (_updatedAt != null ? _updatedAt!.format() : \\"null\\")); + buffer.write(\\"}\\"); + + return buffer.toString(); + } + + Comment copyWith({Post? post, String? content}) { + return Comment._internal( + id: id, + post: post ?? this.post, + content: content ?? this.content); + } + + Comment copyWithModelFieldValues({ + ModelFieldValue? post, + ModelFieldValue? content + }) { + return Comment._internal( + id: id, + post: post == null ? this.post : post.value, + content: content == null ? this.content : content.value + ); + } + + Comment.fromJson(Map json) + : id = json['id'], + _post = json['post'] != null + ? json['post']['serializedData'] != null + ? Post.fromJson(new Map.from(json['post']['serializedData'])) + : Post.fromJson(new Map.from(json['post'])) + : null, + _content = json['content'], + _createdAt = json['createdAt'] != null ? amplify_core.TemporalDateTime.fromString(json['createdAt']) : null, + _updatedAt = json['updatedAt'] != null ? amplify_core.TemporalDateTime.fromString(json['updatedAt']) : null; + + Map toJson() => { + 'id': id, 'post': _post?.toJson(), 'content': _content, 'createdAt': _createdAt?.format(), 'updatedAt': _updatedAt?.format() + }; + + Map toMap() => { + 'id': id, + 'post': _post, + 'content': _content, + 'createdAt': _createdAt, + 'updatedAt': _updatedAt + }; + + static final amplify_core.QueryModelIdentifier MODEL_IDENTIFIER = amplify_core.QueryModelIdentifier(); + static final ID = amplify_core.QueryField(fieldName: \\"id\\"); + static final POST = amplify_core.QueryField( + fieldName: \\"post\\", + fieldType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.model, ofModelName: 'Post')); + static final CONTENT = amplify_core.QueryField(fieldName: \\"content\\"); + static var schema = amplify_core.Model.defineSchema(define: (amplify_core.ModelSchemaDefinition modelSchemaDefinition) { + modelSchemaDefinition.name = \\"Comment\\"; + modelSchemaDefinition.pluralName = \\"Comments\\"; + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.id()); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.belongsTo( + key: Comment.POST, + isRequired: false, + targetNames: ['postCommentsId'], + ofModelName: 'Post' + )); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.field( + key: Comment.CONTENT, + isRequired: true, + ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.string) + )); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.nonQueryField( + fieldName: 'createdAt', + isRequired: false, + isReadOnly: true, + ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.dateTime) + )); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.nonQueryField( + fieldName: 'updatedAt', + isRequired: false, + isReadOnly: true, + ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.dateTime) + )); + }); +} + +class _CommentModelType extends amplify_core.ModelType { + const _CommentModelType(); + + @override + Comment fromJson(Map jsonData) { + return Comment.fromJson(jsonData); + } + + @override + String modelName() { + return 'Comment'; + } +} + +/** + * This is an auto generated class representing the model identifier + * of [Comment] in your schema. + */ +class CommentModelIdentifier implements amplify_core.ModelIdentifier { + final String id; + + /** Create an instance of CommentModelIdentifier using [id] the primary key. */ + const CommentModelIdentifier({ + required this.id}); + + @override + Map serializeAsMap() => ({ + 'id': id + }); + + @override + List> serializeAsList() => serializeAsMap() + .entries + .map((entry) => ({ entry.key: entry.value })) + .toList(); + + @override + String serializeAsString() => serializeAsMap().values.join('#'); + + @override + String toString() => 'CommentModelIdentifier(id: $id)'; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + + return other is CommentModelIdentifier && + id == other.id; + } + + @override + int get hashCode => + id.hashCode; +}", + "ModelProvider.dart": "/* +* Copyright 2021 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. +* A copy of the License is located at +* +* http://aws.amazon.com/apache2.0 +* +* or in the \\"license\\" file accompanying this file. This file 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. +*/ + +// NOTE: This file is generated and may not follow lint rules defined in your app +// Generated files can be excluded from analysis in analysis_options.yaml +// For more info, see: https://dart.dev/guides/language/analysis-options#excluding-code-from-analysis + +// ignore_for_file: public_member_api_docs, annotate_overrides, dead_code, dead_codepublic_member_api_docs, depend_on_referenced_packages, file_names, library_private_types_in_public_api, no_leading_underscores_for_library_prefixes, no_leading_underscores_for_local_identifiers, non_constant_identifier_names, null_check_on_nullable_type_parameter, override_on_non_overriding_member, prefer_adjacent_string_concatenation, prefer_const_constructors, prefer_if_null_operators, prefer_interpolation_to_compose_strings, slash_for_doc_comments, sort_child_properties_last, unnecessary_const, unnecessary_constructor_name, unnecessary_late, unnecessary_new, unnecessary_null_aware_assignments, unnecessary_nullable_for_final_variable_declarations, unnecessary_string_interpolations, use_build_context_synchronously + +import 'package:amplify_core/amplify_core.dart' as amplify_core; +import 'Blog.dart'; +import 'Comment.dart'; +import 'Post.dart'; + +export 'Blog.dart'; +export 'Comment.dart'; +export 'Post.dart'; + +class ModelProvider implements amplify_core.ModelProviderInterface { + @override + String version = \\"165944a36979cd395e3b22145bbfeff0\\"; + @override + List modelSchemas = [Blog.schema, Comment.schema, Post.schema]; + @override + List customTypeSchemas = []; + static final ModelProvider _instance = ModelProvider(); + + static ModelProvider get instance => _instance; + + amplify_core.ModelType getModelTypeByModelName(String modelName) { + switch(modelName) { + case \\"Blog\\": + return Blog.classType; + case \\"Comment\\": + return Comment.classType; + case \\"Post\\": + return Post.classType; + default: + throw Exception(\\"Failed to find model in model provider for model name: \\" + modelName); + } + } +} + + +class ModelFieldValue { + const ModelFieldValue.value(this.value); + + final T value; +} +", + "Post.dart": "/* +* Copyright 2021 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. +* A copy of the License is located at +* +* http://aws.amazon.com/apache2.0 +* +* or in the \\"license\\" file accompanying this file. This file 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. +*/ + +// NOTE: This file is generated and may not follow lint rules defined in your app +// Generated files can be excluded from analysis in analysis_options.yaml +// For more info, see: https://dart.dev/guides/language/analysis-options#excluding-code-from-analysis + +// ignore_for_file: public_member_api_docs, annotate_overrides, dead_code, dead_codepublic_member_api_docs, depend_on_referenced_packages, file_names, library_private_types_in_public_api, no_leading_underscores_for_library_prefixes, no_leading_underscores_for_local_identifiers, non_constant_identifier_names, null_check_on_nullable_type_parameter, override_on_non_overriding_member, prefer_adjacent_string_concatenation, prefer_const_constructors, prefer_if_null_operators, prefer_interpolation_to_compose_strings, slash_for_doc_comments, sort_child_properties_last, unnecessary_const, unnecessary_constructor_name, unnecessary_late, unnecessary_new, unnecessary_null_aware_assignments, unnecessary_nullable_for_final_variable_declarations, unnecessary_string_interpolations, use_build_context_synchronously + +import 'ModelProvider.dart'; +import 'package:amplify_core/amplify_core.dart' as amplify_core; +import 'package:collection/collection.dart'; + + +/** This is an auto generated class representing the Post type in your schema. */ +class Post extends amplify_core.Model { + static const classType = const _PostModelType(); + final String id; + final String? _title; + final Blog? _blog; + final List? _comments; + final amplify_core.TemporalDateTime? _createdAt; + final amplify_core.TemporalDateTime? _updatedAt; + + @override + getInstanceType() => classType; + + @Deprecated('[getId] is being deprecated in favor of custom primary key feature. Use getter [modelIdentifier] to get model identifier.') + @override + String getId() => id; + + PostModelIdentifier get modelIdentifier { + return PostModelIdentifier( + id: id + ); + } + + String get title { + try { + return _title!; + } catch(e) { + throw amplify_core.AmplifyCodeGenModelException( + amplify_core.AmplifyExceptionMessages.codeGenRequiredFieldForceCastExceptionMessage, + recoverySuggestion: + amplify_core.AmplifyExceptionMessages.codeGenRequiredFieldForceCastRecoverySuggestion, + underlyingException: e.toString() + ); + } + } + + Blog? get blog { + return _blog; + } + + List? get comments { + return _comments; + } + + amplify_core.TemporalDateTime? get createdAt { + return _createdAt; + } + + amplify_core.TemporalDateTime? get updatedAt { + return _updatedAt; + } + + const Post._internal({required this.id, required title, blog, comments, createdAt, updatedAt}): _title = title, _blog = blog, _comments = comments, _createdAt = createdAt, _updatedAt = updatedAt; + + factory Post({String? id, required String title, Blog? blog, List? comments}) { + return Post._internal( + id: id == null ? amplify_core.UUID.getUUID() : id, + title: title, + blog: blog, + comments: comments != null ? List.unmodifiable(comments) : comments); + } + + bool equals(Object other) { + return this == other; + } + + @override + bool operator ==(Object other) { + if (identical(other, this)) return true; + return other is Post && + id == other.id && + _title == other._title && + _blog == other._blog && + DeepCollectionEquality().equals(_comments, other._comments); + } + + @override + int get hashCode => toString().hashCode; + + @override + String toString() { + var buffer = new StringBuffer(); + + buffer.write(\\"Post {\\"); + buffer.write(\\"id=\\" + \\"$id\\" + \\", \\"); + buffer.write(\\"title=\\" + \\"$_title\\" + \\", \\"); + buffer.write(\\"blog=\\" + (_blog != null ? _blog!.toString() : \\"null\\") + \\", \\"); + buffer.write(\\"createdAt=\\" + (_createdAt != null ? _createdAt!.format() : \\"null\\") + \\", \\"); + buffer.write(\\"updatedAt=\\" + (_updatedAt != null ? _updatedAt!.format() : \\"null\\")); + buffer.write(\\"}\\"); + + return buffer.toString(); + } + + Post copyWith({String? title, Blog? blog, List? comments}) { + return Post._internal( + id: id, + title: title ?? this.title, + blog: blog ?? this.blog, + comments: comments ?? this.comments); + } + + Post copyWithModelFieldValues({ + ModelFieldValue? title, + ModelFieldValue? blog, + ModelFieldValue?>? comments + }) { + return Post._internal( + id: id, + title: title == null ? this.title : title.value, + blog: blog == null ? this.blog : blog.value, + comments: comments == null ? this.comments : comments.value + ); + } + + Post.fromJson(Map json) + : id = json['id'], + _title = json['title'], + _blog = json['blog'] != null + ? json['blog']['serializedData'] != null + ? Blog.fromJson(new Map.from(json['blog']['serializedData'])) + : Blog.fromJson(new Map.from(json['blog'])) + : null, + _comments = json['comments'] is Map + ? (json['comments']['items'] is List + ? (json['comments']['items'] as List) + .where((e) => e != null) + .map((e) => Comment.fromJson(new Map.from(e))) + .toList() + : null) + : (json['comments'] is List + ? (json['comments'] as List) + .where((e) => e?['serializedData'] != null) + .map((e) => Comment.fromJson(new Map.from(e?['serializedData']))) + .toList() + : null), + _createdAt = json['createdAt'] != null ? amplify_core.TemporalDateTime.fromString(json['createdAt']) : null, + _updatedAt = json['updatedAt'] != null ? amplify_core.TemporalDateTime.fromString(json['updatedAt']) : null; + + Map toJson() => { + 'id': id, 'title': _title, 'blog': _blog?.toJson(), 'comments': _comments?.map((Comment? e) => e?.toJson()).toList(), 'createdAt': _createdAt?.format(), 'updatedAt': _updatedAt?.format() + }; + + Map toMap() => { + 'id': id, + 'title': _title, + 'blog': _blog, + 'comments': _comments, + 'createdAt': _createdAt, + 'updatedAt': _updatedAt + }; + + static final amplify_core.QueryModelIdentifier MODEL_IDENTIFIER = amplify_core.QueryModelIdentifier(); + static final ID = amplify_core.QueryField(fieldName: \\"id\\"); + static final TITLE = amplify_core.QueryField(fieldName: \\"title\\"); + static final BLOG = amplify_core.QueryField( + fieldName: \\"blog\\", + fieldType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.model, ofModelName: 'Blog')); + static final COMMENTS = amplify_core.QueryField( + fieldName: \\"comments\\", + fieldType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.model, ofModelName: 'Comment')); + static var schema = amplify_core.Model.defineSchema(define: (amplify_core.ModelSchemaDefinition modelSchemaDefinition) { + modelSchemaDefinition.name = \\"Post\\"; + modelSchemaDefinition.pluralName = \\"Posts\\"; + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.id()); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.field( + key: Post.TITLE, + isRequired: true, + ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.string) + )); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.belongsTo( + key: Post.BLOG, + isRequired: false, + targetNames: ['blogPostsId'], + ofModelName: 'Blog' + )); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.hasMany( + key: Post.COMMENTS, + isRequired: false, + ofModelName: 'Comment', + associatedKey: Comment.POST + )); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.nonQueryField( + fieldName: 'createdAt', + isRequired: false, + isReadOnly: true, + ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.dateTime) + )); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.nonQueryField( + fieldName: 'updatedAt', + isRequired: false, + isReadOnly: true, + ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.dateTime) + )); + }); +} + +class _PostModelType extends amplify_core.ModelType { + const _PostModelType(); + + @override + Post fromJson(Map jsonData) { + return Post.fromJson(jsonData); + } + + @override + String modelName() { + return 'Post'; + } +} + +/** + * This is an auto generated class representing the model identifier + * of [Post] in your schema. + */ +class PostModelIdentifier implements amplify_core.ModelIdentifier { + final String id; + + /** Create an instance of PostModelIdentifier using [id] the primary key. */ + const PostModelIdentifier({ + required this.id}); + + @override + Map serializeAsMap() => ({ + 'id': id + }); + + @override + List> serializeAsList() => serializeAsMap() + .entries + .map((entry) => ({ entry.key: entry.value })) + .toList(); + + @override + String serializeAsString() => serializeAsMap().values.join('#'); + + @override + String toString() => 'PostModelIdentifier(id: $id)'; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + + return other is PostModelIdentifier && + id == other.id; + } + + @override + int get hashCode => + id.hashCode; +}", +} +`; + +exports[`generateModels with targets basic 12`] = ` +Object { + "model-introspection.json": "{ + \\"version\\": 1, + \\"models\\": { + \\"Blog\\": { + \\"name\\": \\"Blog\\", + \\"fields\\": { + \\"id\\": { + \\"name\\": \\"id\\", + \\"isArray\\": false, + \\"type\\": \\"ID\\", + \\"isRequired\\": true, + \\"attributes\\": [] + }, + \\"name\\": { + \\"name\\": \\"name\\", + \\"isArray\\": false, + \\"type\\": \\"String\\", + \\"isRequired\\": true, + \\"attributes\\": [] + }, + \\"posts\\": { + \\"name\\": \\"posts\\", + \\"isArray\\": true, + \\"type\\": { + \\"model\\": \\"Post\\" + }, + \\"isRequired\\": false, + \\"attributes\\": [], + \\"isArrayNullable\\": true, + \\"association\\": { + \\"connectionType\\": \\"HAS_MANY\\", + \\"associatedWith\\": [ + \\"blogPostsId\\" + ] + } + }, + \\"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\\": \\"Blogs\\", + \\"attributes\\": [ + { + \\"type\\": \\"model\\", + \\"properties\\": {} + } + ], + \\"primaryKeyInfo\\": { + \\"isCustomPrimaryKey\\": false, + \\"primaryKeyFieldName\\": \\"id\\", + \\"sortKeyFieldNames\\": [] + } + }, + \\"Post\\": { + \\"name\\": \\"Post\\", + \\"fields\\": { + \\"id\\": { + \\"name\\": \\"id\\", + \\"isArray\\": false, + \\"type\\": \\"ID\\", + \\"isRequired\\": true, + \\"attributes\\": [] + }, + \\"title\\": { + \\"name\\": \\"title\\", + \\"isArray\\": false, + \\"type\\": \\"String\\", + \\"isRequired\\": true, + \\"attributes\\": [] + }, + \\"blog\\": { + \\"name\\": \\"blog\\", + \\"isArray\\": false, + \\"type\\": { + \\"model\\": \\"Blog\\" + }, + \\"isRequired\\": false, + \\"attributes\\": [], + \\"association\\": { + \\"connectionType\\": \\"BELONGS_TO\\", + \\"targetNames\\": [ + \\"blogPostsId\\" + ] + } + }, + \\"comments\\": { + \\"name\\": \\"comments\\", + \\"isArray\\": true, + \\"type\\": { + \\"model\\": \\"Comment\\" + }, + \\"isRequired\\": false, + \\"attributes\\": [], + \\"isArrayNullable\\": true, + \\"association\\": { + \\"connectionType\\": \\"HAS_MANY\\", + \\"associatedWith\\": [ + \\"postCommentsId\\" + ] + } + }, + \\"createdAt\\": { + \\"name\\": \\"createdAt\\", + \\"isArray\\": false, + \\"type\\": \\"AWSDateTime\\", + \\"isRequired\\": false, + \\"attributes\\": [], + \\"isReadOnly\\": true + }, + \\"updatedAt\\": { + \\"name\\": \\"updatedAt\\", + \\"isArray\\": false, + \\"type\\": \\"AWSDateTime\\", + \\"isRequired\\": false, + \\"attributes\\": [], + \\"isReadOnly\\": true + }, + \\"blogPostsId\\": { + \\"name\\": \\"blogPostsId\\", + \\"isArray\\": false, + \\"type\\": \\"ID\\", + \\"isRequired\\": false, + \\"attributes\\": [] + } + }, + \\"syncable\\": true, + \\"pluralName\\": \\"Posts\\", + \\"attributes\\": [ + { + \\"type\\": \\"model\\", + \\"properties\\": {} + } + ], + \\"primaryKeyInfo\\": { + \\"isCustomPrimaryKey\\": false, + \\"primaryKeyFieldName\\": \\"id\\", + \\"sortKeyFieldNames\\": [] + } + }, + \\"Comment\\": { + \\"name\\": \\"Comment\\", + \\"fields\\": { + \\"id\\": { + \\"name\\": \\"id\\", + \\"isArray\\": false, + \\"type\\": \\"ID\\", + \\"isRequired\\": true, + \\"attributes\\": [] + }, + \\"post\\": { + \\"name\\": \\"post\\", + \\"isArray\\": false, + \\"type\\": { + \\"model\\": \\"Post\\" + }, + \\"isRequired\\": false, + \\"attributes\\": [], + \\"association\\": { + \\"connectionType\\": \\"BELONGS_TO\\", + \\"targetNames\\": [ + \\"postCommentsId\\" + ] + } + }, + \\"content\\": { + \\"name\\": \\"content\\", + \\"isArray\\": false, + \\"type\\": \\"String\\", + \\"isRequired\\": true, + \\"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 + }, + \\"postCommentsId\\": { + \\"name\\": \\"postCommentsId\\", + \\"isArray\\": false, + \\"type\\": \\"ID\\", + \\"isRequired\\": false, + \\"attributes\\": [] + } + }, + \\"syncable\\": true, + \\"pluralName\\": \\"Comments\\", + \\"attributes\\": [ + { + \\"type\\": \\"model\\", + \\"properties\\": {} + } + ], + \\"primaryKeyInfo\\": { + \\"isCustomPrimaryKey\\": false, + \\"primaryKeyFieldName\\": \\"id\\", + \\"sortKeyFieldNames\\": [] + } + } + }, + \\"enums\\": {}, + \\"nonModels\\": {} +}", +} +`; + exports[`generateModelsSync does not fail on custom directives 1`] = ` Object { "model-introspection.json": "{ diff --git a/packages/graphql-generator/src/__tests__/models.test.ts b/packages/graphql-generator/src/__tests__/models.test.ts index af45785a..c8795405 100644 --- a/packages/graphql-generator/src/__tests__/models.test.ts +++ b/packages/graphql-generator/src/__tests__/models.test.ts @@ -2,6 +2,7 @@ import { generateModels, generateModelsSync, GenerateModelsOptions, ModelsTarget import { readSchema } from './utils'; const generators = ['generateModels', 'generateModelsSync'] as const; +const targets: ModelsTarget[] = ['java', 'swift', 'javascript', 'typescript', 'dart', 'introspection']; async function runGenerator(generator: (typeof generators)[number], options: GenerateModelsOptions) { if (generator === 'generateModels') { @@ -11,32 +12,28 @@ async function runGenerator(generator: (typeof generators)[number], options: Gen } } -generators.forEach((generator) => { - describe(generator, () => { +describe.each(generators)('generateModels with', (generator) => { describe('targets', () => { - const targets: ModelsTarget[] = ['java', 'swift', 'javascript', 'typescript', 'dart', 'introspection']; - targets.forEach(target => { - test(`basic ${target}`, async () => { - const options: GenerateModelsOptions = { - schema: readSchema('blog-model.graphql'), - target, - }; - const models = await runGenerator(generator, options); - expect(models).toMatchSnapshot(); - }); - }); - - test(`improve pluralization swift`, async () => { + test.each(targets)(`basic`, async (target) => { const options: GenerateModelsOptions = { schema: readSchema('blog-model.graphql'), - target: 'swift', - improvePluralization: true, + target, }; const models = await runGenerator(generator, options); expect(models).toMatchSnapshot(); }); }); + test(`improve pluralization swift`, async () => { + const options: GenerateModelsOptions = { + schema: readSchema('blog-model.graphql'), + target: 'swift', + improvePluralization: true, + }; + const models = await runGenerator(generator, options); + expect(models).toMatchSnapshot(); + }); + test('does not fail on custom directives', async () => { const options: GenerateModelsOptions = { schema: ` @@ -54,9 +51,7 @@ generators.forEach((generator) => { expect(models).toMatchSnapshot(); }); }); -}); -const targets: ModelsTarget[] = ['java', 'swift', 'javascript', 'typescript', 'dart', 'introspection']; targets.forEach(target => { test(`both generates generate the same basic ${target}`, async () => { const options: GenerateModelsOptions = {