From f39902d026ee66f584b18efc3d93c496db034630 Mon Sep 17 00:00:00 2001 From: Guilherme Souza Date: Tue, 2 Jul 2024 12:10:30 -0300 Subject: [PATCH] fix(typegen): swift generator (#790) * fix(typegen): swift generator * chore: add swift type generation to README --- README.md | 2 + src/server/constants.ts | 6 +- src/server/templates/swift.ts | 151 +++++---- test/server/typegen.ts | 598 +++++++++++++++++++--------------- 4 files changed, 424 insertions(+), 333 deletions(-) diff --git a/README.md b/README.md index e49bd68d..f81f4673 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,7 @@ Helpers: - [ ] `/generators` - [ ] GET `/openapi`: Generate Open API - [ ] GET `/typescript`: Generate Typescript types + - [ ] GET `/swift`: Generate Swift types (beta) ## Quickstart @@ -105,6 +106,7 @@ where `` is one of: - `typescript` - `go` +- `swift` (beta) To use your own database connection string instead of the provided test database, run: `PG_META_DB_URL=postgresql://postgres:postgres@localhost:5432/postgres npm run gen:types:` diff --git a/src/server/constants.ts b/src/server/constants.ts index f7447c45..80052e00 100644 --- a/src/server/constants.ts +++ b/src/server/constants.ts @@ -41,8 +41,10 @@ export const GENERATE_TYPES_INCLUDED_SCHEMAS = GENERATE_TYPES : [] export const GENERATE_TYPES_DETECT_ONE_TO_ONE_RELATIONSHIPS = process.env.PG_META_GENERATE_TYPES_DETECT_ONE_TO_ONE_RELATIONSHIPS === 'true' -export const GENERATE_TYPES_SWIFT_ACCESS_CONTROL = - (process.env.PG_META_GENERATE_TYPES_SWIFT_ACCESS_CONTROL as AccessControl) || 'internal' +export const GENERATE_TYPES_SWIFT_ACCESS_CONTROL = process.env + .PG_META_GENERATE_TYPES_SWIFT_ACCESS_CONTROL + ? (process.env.PG_META_GENERATE_TYPES_SWIFT_ACCESS_CONTROL as AccessControl) + : 'internal' export const DEFAULT_POOL_CONFIG: PoolConfig = { max: 1, connectionTimeoutMillis: PG_CONN_TIMEOUT_SECS * 1000, diff --git a/src/server/templates/swift.ts b/src/server/templates/swift.ts index a10972e4..fee24297 100644 --- a/src/server/templates/swift.ts +++ b/src/server/templates/swift.ts @@ -9,6 +9,7 @@ import type { PostgresView, } from '../../lib/index.js' import type { GeneratorMetadata } from '../../lib/generators.js' +import { PostgresForeignTable } from '../../lib/types.js' type Operation = 'Select' | 'Insert' | 'Update' export type AccessControl = 'internal' | 'public' | 'private' | 'package' @@ -57,7 +58,7 @@ function pgEnumToSwiftEnum(pgEnum: PostgresType): SwiftEnum { } function pgTypeToSwiftStruct( - table: PostgresTable | PostgresView | PostgresMaterializedView, + table: PostgresTable | PostgresForeignTable | PostgresView | PostgresMaterializedView, columns: PostgresColumn[] | undefined, operation: Operation, { @@ -205,75 +206,80 @@ function generateStruct( export const apply = async ({ schemas, tables, + foreignTables, views, materializedViews, columns, types, accessControl, }: GeneratorMetadata & SwiftGeneratorOptions): Promise => { - const columnsByTableId = columns - .sort(({ name: a }, { name: b }) => a.localeCompare(b)) - .reduce( - (acc, curr) => { - acc[curr.table_id] ??= [] - acc[curr.table_id].push(curr) - return acc - }, - {} as Record - ) - - const compositeTypes = types.filter((type) => type.attributes.length > 0) - const enums = types - .filter((type) => type.enums.length > 0) - .sort(({ name: a }, { name: b }) => a.localeCompare(b)) - - const swiftEnums = enums.map((enum_) => { - return { schema: enum_.schema, enum_: pgEnumToSwiftEnum(enum_) } - }) - - const swiftStructForTables = tables.flatMap((table) => - (['Select', 'Insert', 'Update'] as Operation[]).map((operation) => - pgTypeToSwiftStruct(table, columnsByTableId[table.id], operation, { types, views, tables }) - ) - ) - - const swiftStructForViews = views.map((view) => - pgTypeToSwiftStruct(view, columnsByTableId[view.id], 'Select', { types, views, tables }) + const columnsByTableId = Object.fromEntries( + [...tables, ...foreignTables, ...views, ...materializedViews].map((t) => [t.id, []]) ) - const swiftStructForMaterializedViews = materializedViews.map((materializedView) => - pgTypeToSwiftStruct(materializedView, columnsByTableId[materializedView.id], 'Select', { - types, - views, - tables, - }) - ) - - const swiftStructForCompositeTypes = compositeTypes.map((type) => - pgCompositeTypeToSwiftStruct(type, { types, views, tables }) - ) + columns + .filter((c) => c.table_id in columnsByTableId) + .sort(({ name: a }, { name: b }) => a.localeCompare(b)) + .forEach((c) => columnsByTableId[c.table_id].push(c)) let output = [ 'import Foundation', 'import Supabase', '', - ...schemas.flatMap((schema) => [ - `${accessControl} enum ${formatForSwiftSchemaName(schema.name)} {`, - ...swiftEnums.flatMap(({ enum_ }) => generateEnum(enum_, { accessControl, level: 1 })), - ...swiftStructForTables.flatMap((struct) => - generateStruct(struct, { accessControl, level: 1 }) - ), - ...swiftStructForViews.flatMap((struct) => - generateStruct(struct, { accessControl, level: 1 }) - ), - ...swiftStructForMaterializedViews.flatMap((struct) => - generateStruct(struct, { accessControl, level: 1 }) - ), - ...swiftStructForCompositeTypes.flatMap((struct) => - generateStruct(struct, { accessControl, level: 1 }) - ), - '}', - ]), + ...schemas + .sort(({ name: a }, { name: b }) => a.localeCompare(b)) + .flatMap((schema) => { + const schemaTables = [...tables, ...foreignTables] + .filter((table) => table.schema === schema.name) + .sort(({ name: a }, { name: b }) => a.localeCompare(b)) + + const schemaViews = [...views, ...materializedViews] + .filter((table) => table.schema === schema.name) + .sort(({ name: a }, { name: b }) => a.localeCompare(b)) + + const schemaEnums = types + .filter((type) => type.schema === schema.name && type.enums.length > 0) + .sort(({ name: a }, { name: b }) => a.localeCompare(b)) + + const schemaCompositeTypes = types + .filter((type) => type.schema === schema.name && type.attributes.length > 0) + .sort(({ name: a }, { name: b }) => a.localeCompare(b)) + + return [ + `${accessControl} enum ${formatForSwiftSchemaName(schema.name)} {`, + ...schemaEnums.flatMap((enum_) => + generateEnum(pgEnumToSwiftEnum(enum_), { accessControl, level: 1 }) + ), + ...schemaTables.flatMap((table) => + (['Select', 'Insert', 'Update'] as Operation[]) + .map((operation) => + pgTypeToSwiftStruct(table, columnsByTableId[table.id], operation, { + types, + views, + tables, + }) + ) + .flatMap((struct) => generateStruct(struct, { accessControl, level: 1 })) + ), + ...schemaViews.flatMap((view) => + generateStruct( + pgTypeToSwiftStruct(view, columnsByTableId[view.id], 'Select', { + types, + views, + tables, + }), + { accessControl, level: 1 } + ) + ), + ...schemaCompositeTypes.flatMap((type) => + generateStruct(pgCompositeTypeToSwiftStruct(type, { types, views, tables }), { + accessControl, + level: 1, + }) + ), + '}', + ] + }), ] return output.join('\n') @@ -360,15 +366,34 @@ function ident(level: number, options: { width: number } = { width: 2 }): string * formatForSwiftTypeName('pokemon_center') // PokemonCenter * formatForSwiftTypeName('victory-road') // VictoryRoad * formatForSwiftTypeName('pokemon league') // PokemonLeague + * formatForSwiftTypeName('_key_id_context') // _KeyIdContext * ``` */ function formatForSwiftTypeName(name: string): string { - return name - .split(/[^a-zA-Z0-9]/) - .map((word) => `${word[0].toUpperCase()}${word.slice(1)}`) - .join('') + // Preserve the initial underscore if it exists + let prefix = '' + if (name.startsWith('_')) { + prefix = '_' + name = name.slice(1) // Remove the initial underscore for processing + } + + return ( + prefix + + name + .split(/[^a-zA-Z0-9]+/) + .map((word) => { + if (word) { + return `${word[0].toUpperCase()}${word.slice(1)}` + } else { + return '' + } + }) + .join('') + ) } +const SWIFT_KEYWORDS = ['in', 'default'] + /** * Converts a Postgres name to pascalCase. * @@ -381,11 +406,13 @@ function formatForSwiftTypeName(name: string): string { * ``` */ function formatForSwiftPropertyName(name: string): string { - return name + const propertyName = name .split(/[^a-zA-Z0-9]/) .map((word, index) => { const lowerWord = word.toLowerCase() return index !== 0 ? lowerWord.charAt(0).toUpperCase() + lowerWord.slice(1) : lowerWord }) .join('') + + return SWIFT_KEYWORDS.includes(propertyName) ? `\`${propertyName}\`` : propertyName } diff --git a/test/server/typegen.ts b/test/server/typegen.ts index 19744628..1c0f914f 100644 --- a/test/server/typegen.ts +++ b/test/server/typegen.ts @@ -1778,132 +1778,114 @@ test('typegen: swift', async () => { case active = "ACTIVE" case inactive = "INACTIVE" } - internal struct UsersSelect: Codable, Hashable, Sendable, Identifiable { - internal let id: Int64 - internal let name: String? - internal let status: UserStatus? + internal struct CategorySelect: Codable, Hashable, Sendable { + internal let id: Int32 + internal let name: String internal enum CodingKeys: String, CodingKey { case id = "id" case name = "name" - case status = "status" } } - internal struct UsersInsert: Codable, Hashable, Sendable, Identifiable { - internal let id: Int64? - internal let name: String? - internal let status: UserStatus? + internal struct CategoryInsert: Codable, Hashable, Sendable { + internal let id: Int32? + internal let name: String internal enum CodingKeys: String, CodingKey { case id = "id" case name = "name" - case status = "status" } } - internal struct UsersUpdate: Codable, Hashable, Sendable, Identifiable { - internal let id: Int64? + internal struct CategoryUpdate: Codable, Hashable, Sendable { + internal let id: Int32? internal let name: String? - internal let status: UserStatus? internal enum CodingKeys: String, CodingKey { case id = "id" case name = "name" - case status = "status" } } - internal struct TodosSelect: Codable, Hashable, Sendable, Identifiable { - internal let details: String? + internal struct EmptySelect: Codable, Hashable, Sendable { + } + internal struct EmptyInsert: Codable, Hashable, Sendable { + } + internal struct EmptyUpdate: Codable, Hashable, Sendable { + } + internal struct ForeignTableSelect: Codable, Hashable, Sendable { internal let id: Int64 - internal let userId: Int64 + internal let name: String? + internal let status: UserStatus? internal enum CodingKeys: String, CodingKey { - case details = "details" case id = "id" - case userId = "user-id" + case name = "name" + case status = "status" } } - internal struct TodosInsert: Codable, Hashable, Sendable, Identifiable { - internal let details: String? - internal let id: Int64? - internal let userId: Int64 + internal struct ForeignTableInsert: Codable, Hashable, Sendable { + internal let id: Int64 + internal let name: String? + internal let status: UserStatus? internal enum CodingKeys: String, CodingKey { - case details = "details" case id = "id" - case userId = "user-id" + case name = "name" + case status = "status" } } - internal struct TodosUpdate: Codable, Hashable, Sendable, Identifiable { - internal let details: String? + internal struct ForeignTableUpdate: Codable, Hashable, Sendable { internal let id: Int64? - internal let userId: Int64? + internal let name: String? + internal let status: UserStatus? internal enum CodingKeys: String, CodingKey { - case details = "details" case id = "id" - case userId = "user-id" + case name = "name" + case status = "status" } } - internal struct UsersAuditSelect: Codable, Hashable, Sendable, Identifiable { - internal let createdAt: String? - internal let id: Int64 - internal let previousValue: AnyJSON? - internal let userId: Int64? + internal struct MemesSelect: Codable, Hashable, Sendable { + internal let category: Int32? + internal let createdAt: String + internal let id: Int32 + internal let metadata: AnyJSON? + internal let name: String + internal let status: MemeStatus? internal enum CodingKeys: String, CodingKey { + case category = "category" case createdAt = "created_at" case id = "id" - case previousValue = "previous_value" - case userId = "user_id" + case metadata = "metadata" + case name = "name" + case status = "status" } } - internal struct UsersAuditInsert: Codable, Hashable, Sendable, Identifiable { - internal let createdAt: String? - internal let id: Int64? - internal let previousValue: AnyJSON? - internal let userId: Int64? + internal struct MemesInsert: Codable, Hashable, Sendable { + internal let category: Int32? + internal let createdAt: String + internal let id: Int32? + internal let metadata: AnyJSON? + internal let name: String + internal let status: MemeStatus? internal enum CodingKeys: String, CodingKey { + case category = "category" case createdAt = "created_at" case id = "id" - case previousValue = "previous_value" - case userId = "user_id" + case metadata = "metadata" + case name = "name" + case status = "status" } } - internal struct UsersAuditUpdate: Codable, Hashable, Sendable, Identifiable { + internal struct MemesUpdate: Codable, Hashable, Sendable { + internal let category: Int32? internal let createdAt: String? - internal let id: Int64? - internal let previousValue: AnyJSON? - internal let userId: Int64? + internal let id: Int32? + internal let metadata: AnyJSON? + internal let name: String? + internal let status: MemeStatus? internal enum CodingKeys: String, CodingKey { + case category = "category" case createdAt = "created_at" case id = "id" - case previousValue = "previous_value" - case userId = "user_id" - } - } - internal struct UserDetailsSelect: Codable, Hashable, Sendable { - internal let details: String? - internal let userId: Int64 - internal enum CodingKeys: String, CodingKey { - case details = "details" - case userId = "user_id" - } - } - internal struct UserDetailsInsert: Codable, Hashable, Sendable { - internal let details: String? - internal let userId: Int64 - internal enum CodingKeys: String, CodingKey { - case details = "details" - case userId = "user_id" - } - } - internal struct UserDetailsUpdate: Codable, Hashable, Sendable { - internal let details: String? - internal let userId: Int64? - internal enum CodingKeys: String, CodingKey { - case details = "details" - case userId = "user_id" + case metadata = "metadata" + case name = "name" + case status = "status" } } - internal struct EmptySelect: Codable, Hashable, Sendable { - } - internal struct EmptyInsert: Codable, Hashable, Sendable { - } - internal struct EmptyUpdate: Codable, Hashable, Sendable { - } internal struct TableWithOtherTablesRowTypeSelect: Codable, Hashable, Sendable { internal let col1: UserDetailsSelect? internal let col2: AViewSelect? @@ -1955,89 +1937,81 @@ test('typegen: swift', async () => { case otherId = "other_id" } } - internal struct CategorySelect: Codable, Hashable, Sendable { - internal let id: Int32 - internal let name: String + internal struct TodosSelect: Codable, Hashable, Sendable, Identifiable { + internal let details: String? + internal let id: Int64 + internal let userId: Int64 internal enum CodingKeys: String, CodingKey { + case details = "details" case id = "id" - case name = "name" + case userId = "user-id" } } - internal struct CategoryInsert: Codable, Hashable, Sendable { - internal let id: Int32? - internal let name: String + internal struct TodosInsert: Codable, Hashable, Sendable, Identifiable { + internal let details: String? + internal let id: Int64? + internal let userId: Int64 internal enum CodingKeys: String, CodingKey { + case details = "details" case id = "id" - case name = "name" + case userId = "user-id" } } - internal struct CategoryUpdate: Codable, Hashable, Sendable { - internal let id: Int32? - internal let name: String? + internal struct TodosUpdate: Codable, Hashable, Sendable, Identifiable { + internal let details: String? + internal let id: Int64? + internal let userId: Int64? internal enum CodingKeys: String, CodingKey { + case details = "details" case id = "id" - case name = "name" + case userId = "user-id" } } - internal struct MemesSelect: Codable, Hashable, Sendable { - internal let category: Int32? - internal let createdAt: String - internal let id: Int32 - internal let metadata: AnyJSON? - internal let name: String - internal let status: MemeStatus? + internal struct UserDetailsSelect: Codable, Hashable, Sendable { + internal let details: String? + internal let userId: Int64 internal enum CodingKeys: String, CodingKey { - case category = "category" - case createdAt = "created_at" - case id = "id" - case metadata = "metadata" - case name = "name" - case status = "status" + case details = "details" + case userId = "user_id" } } - internal struct MemesInsert: Codable, Hashable, Sendable { - internal let category: Int32? - internal let createdAt: String - internal let id: Int32? - internal let metadata: AnyJSON? - internal let name: String - internal let status: MemeStatus? + internal struct UserDetailsInsert: Codable, Hashable, Sendable { + internal let details: String? + internal let userId: Int64 internal enum CodingKeys: String, CodingKey { - case category = "category" - case createdAt = "created_at" - case id = "id" - case metadata = "metadata" - case name = "name" - case status = "status" + case details = "details" + case userId = "user_id" } } - internal struct MemesUpdate: Codable, Hashable, Sendable { - internal let category: Int32? - internal let createdAt: String? - internal let id: Int32? - internal let metadata: AnyJSON? + internal struct UserDetailsUpdate: Codable, Hashable, Sendable { + internal let details: String? + internal let userId: Int64? + internal enum CodingKeys: String, CodingKey { + case details = "details" + case userId = "user_id" + } + } + internal struct UsersSelect: Codable, Hashable, Sendable, Identifiable { + internal let id: Int64 internal let name: String? - internal let status: MemeStatus? + internal let status: UserStatus? internal enum CodingKeys: String, CodingKey { - case category = "category" - case createdAt = "created_at" case id = "id" - case metadata = "metadata" case name = "name" case status = "status" } } - internal struct TodosViewSelect: Codable, Hashable, Sendable { - internal let details: String? + internal struct UsersInsert: Codable, Hashable, Sendable, Identifiable { internal let id: Int64? - internal let userId: Int64? + internal let name: String? + internal let status: UserStatus? internal enum CodingKeys: String, CodingKey { - case details = "details" case id = "id" - case userId = "user-id" + case name = "name" + case status = "status" } } - internal struct UsersViewSelect: Codable, Hashable, Sendable { + internal struct UsersUpdate: Codable, Hashable, Sendable, Identifiable { internal let id: Int64? internal let name: String? internal let status: UserStatus? @@ -2047,21 +2021,77 @@ test('typegen: swift', async () => { case status = "status" } } - internal struct AViewSelect: Codable, Hashable, Sendable { - internal let id: Int64? + internal struct UsersAuditSelect: Codable, Hashable, Sendable, Identifiable { + internal let createdAt: String? + internal let id: Int64 + internal let previousValue: AnyJSON? + internal let userId: Int64? internal enum CodingKeys: String, CodingKey { + case createdAt = "created_at" case id = "id" + case previousValue = "previous_value" + case userId = "user_id" } } - internal struct TodosMatviewSelect: Codable, Hashable, Sendable { - internal let details: String? + internal struct UsersAuditInsert: Codable, Hashable, Sendable, Identifiable { + internal let createdAt: String? internal let id: Int64? + internal let previousValue: AnyJSON? internal let userId: Int64? internal enum CodingKeys: String, CodingKey { - case details = "details" + case createdAt = "created_at" case id = "id" - case userId = "user-id" - } + case previousValue = "previous_value" + case userId = "user_id" + } + } + internal struct UsersAuditUpdate: Codable, Hashable, Sendable, Identifiable { + internal let createdAt: String? + internal let id: Int64? + internal let previousValue: AnyJSON? + internal let userId: Int64? + internal enum CodingKeys: String, CodingKey { + case createdAt = "created_at" + case id = "id" + case previousValue = "previous_value" + case userId = "user_id" + } + } + internal struct AViewSelect: Codable, Hashable, Sendable { + internal let id: Int64? + internal enum CodingKeys: String, CodingKey { + case id = "id" + } + } + internal struct TodosMatviewSelect: Codable, Hashable, Sendable { + internal let details: String? + internal let id: Int64? + internal let userId: Int64? + internal enum CodingKeys: String, CodingKey { + case details = "details" + case id = "id" + case userId = "user-id" + } + } + internal struct TodosViewSelect: Codable, Hashable, Sendable { + internal let details: String? + internal let id: Int64? + internal let userId: Int64? + internal enum CodingKeys: String, CodingKey { + case details = "details" + case id = "id" + case userId = "user-id" + } + } + internal struct UsersViewSelect: Codable, Hashable, Sendable { + internal let id: Int64? + internal let name: String? + internal let status: UserStatus? + internal enum CodingKeys: String, CodingKey { + case id = "id" + case name = "name" + case status = "status" + } } internal struct CompositeTypeWithArrayAttribute: Codable, Hashable, Sendable { internal let MyTextArray: AnyJSON @@ -2093,132 +2123,114 @@ test('typegen: swift w/ public access control', async () => { case active = "ACTIVE" case inactive = "INACTIVE" } - public struct UsersSelect: Codable, Hashable, Sendable, Identifiable { - public let id: Int64 - public let name: String? - public let status: UserStatus? + public struct CategorySelect: Codable, Hashable, Sendable { + public let id: Int32 + public let name: String public enum CodingKeys: String, CodingKey { case id = "id" case name = "name" - case status = "status" } } - public struct UsersInsert: Codable, Hashable, Sendable, Identifiable { - public let id: Int64? - public let name: String? - public let status: UserStatus? + public struct CategoryInsert: Codable, Hashable, Sendable { + public let id: Int32? + public let name: String public enum CodingKeys: String, CodingKey { case id = "id" case name = "name" - case status = "status" } } - public struct UsersUpdate: Codable, Hashable, Sendable, Identifiable { - public let id: Int64? + public struct CategoryUpdate: Codable, Hashable, Sendable { + public let id: Int32? public let name: String? - public let status: UserStatus? public enum CodingKeys: String, CodingKey { case id = "id" case name = "name" - case status = "status" } } - public struct TodosSelect: Codable, Hashable, Sendable, Identifiable { - public let details: String? + public struct EmptySelect: Codable, Hashable, Sendable { + } + public struct EmptyInsert: Codable, Hashable, Sendable { + } + public struct EmptyUpdate: Codable, Hashable, Sendable { + } + public struct ForeignTableSelect: Codable, Hashable, Sendable { public let id: Int64 - public let userId: Int64 + public let name: String? + public let status: UserStatus? public enum CodingKeys: String, CodingKey { - case details = "details" case id = "id" - case userId = "user-id" + case name = "name" + case status = "status" } } - public struct TodosInsert: Codable, Hashable, Sendable, Identifiable { - public let details: String? - public let id: Int64? - public let userId: Int64 + public struct ForeignTableInsert: Codable, Hashable, Sendable { + public let id: Int64 + public let name: String? + public let status: UserStatus? public enum CodingKeys: String, CodingKey { - case details = "details" case id = "id" - case userId = "user-id" + case name = "name" + case status = "status" } } - public struct TodosUpdate: Codable, Hashable, Sendable, Identifiable { - public let details: String? + public struct ForeignTableUpdate: Codable, Hashable, Sendable { public let id: Int64? - public let userId: Int64? + public let name: String? + public let status: UserStatus? public enum CodingKeys: String, CodingKey { - case details = "details" case id = "id" - case userId = "user-id" + case name = "name" + case status = "status" } } - public struct UsersAuditSelect: Codable, Hashable, Sendable, Identifiable { - public let createdAt: String? - public let id: Int64 - public let previousValue: AnyJSON? - public let userId: Int64? + public struct MemesSelect: Codable, Hashable, Sendable { + public let category: Int32? + public let createdAt: String + public let id: Int32 + public let metadata: AnyJSON? + public let name: String + public let status: MemeStatus? public enum CodingKeys: String, CodingKey { + case category = "category" case createdAt = "created_at" case id = "id" - case previousValue = "previous_value" - case userId = "user_id" + case metadata = "metadata" + case name = "name" + case status = "status" } } - public struct UsersAuditInsert: Codable, Hashable, Sendable, Identifiable { - public let createdAt: String? - public let id: Int64? - public let previousValue: AnyJSON? - public let userId: Int64? + public struct MemesInsert: Codable, Hashable, Sendable { + public let category: Int32? + public let createdAt: String + public let id: Int32? + public let metadata: AnyJSON? + public let name: String + public let status: MemeStatus? public enum CodingKeys: String, CodingKey { + case category = "category" case createdAt = "created_at" case id = "id" - case previousValue = "previous_value" - case userId = "user_id" + case metadata = "metadata" + case name = "name" + case status = "status" } } - public struct UsersAuditUpdate: Codable, Hashable, Sendable, Identifiable { + public struct MemesUpdate: Codable, Hashable, Sendable { + public let category: Int32? public let createdAt: String? - public let id: Int64? - public let previousValue: AnyJSON? - public let userId: Int64? + public let id: Int32? + public let metadata: AnyJSON? + public let name: String? + public let status: MemeStatus? public enum CodingKeys: String, CodingKey { + case category = "category" case createdAt = "created_at" case id = "id" - case previousValue = "previous_value" - case userId = "user_id" - } - } - public struct UserDetailsSelect: Codable, Hashable, Sendable { - public let details: String? - public let userId: Int64 - public enum CodingKeys: String, CodingKey { - case details = "details" - case userId = "user_id" - } - } - public struct UserDetailsInsert: Codable, Hashable, Sendable { - public let details: String? - public let userId: Int64 - public enum CodingKeys: String, CodingKey { - case details = "details" - case userId = "user_id" - } - } - public struct UserDetailsUpdate: Codable, Hashable, Sendable { - public let details: String? - public let userId: Int64? - public enum CodingKeys: String, CodingKey { - case details = "details" - case userId = "user_id" + case metadata = "metadata" + case name = "name" + case status = "status" } } - public struct EmptySelect: Codable, Hashable, Sendable { - } - public struct EmptyInsert: Codable, Hashable, Sendable { - } - public struct EmptyUpdate: Codable, Hashable, Sendable { - } public struct TableWithOtherTablesRowTypeSelect: Codable, Hashable, Sendable { public let col1: UserDetailsSelect? public let col2: AViewSelect? @@ -2270,96 +2282,124 @@ test('typegen: swift w/ public access control', async () => { case otherId = "other_id" } } - public struct CategorySelect: Codable, Hashable, Sendable { - public let id: Int32 - public let name: String + public struct TodosSelect: Codable, Hashable, Sendable, Identifiable { + public let details: String? + public let id: Int64 + public let userId: Int64 public enum CodingKeys: String, CodingKey { + case details = "details" case id = "id" - case name = "name" + case userId = "user-id" } } - public struct CategoryInsert: Codable, Hashable, Sendable { - public let id: Int32? - public let name: String + public struct TodosInsert: Codable, Hashable, Sendable, Identifiable { + public let details: String? + public let id: Int64? + public let userId: Int64 public enum CodingKeys: String, CodingKey { + case details = "details" case id = "id" - case name = "name" + case userId = "user-id" } } - public struct CategoryUpdate: Codable, Hashable, Sendable { - public let id: Int32? + public struct TodosUpdate: Codable, Hashable, Sendable, Identifiable { + public let details: String? + public let id: Int64? + public let userId: Int64? + public enum CodingKeys: String, CodingKey { + case details = "details" + case id = "id" + case userId = "user-id" + } + } + public struct UserDetailsSelect: Codable, Hashable, Sendable { + public let details: String? + public let userId: Int64 + public enum CodingKeys: String, CodingKey { + case details = "details" + case userId = "user_id" + } + } + public struct UserDetailsInsert: Codable, Hashable, Sendable { + public let details: String? + public let userId: Int64 + public enum CodingKeys: String, CodingKey { + case details = "details" + case userId = "user_id" + } + } + public struct UserDetailsUpdate: Codable, Hashable, Sendable { + public let details: String? + public let userId: Int64? + public enum CodingKeys: String, CodingKey { + case details = "details" + case userId = "user_id" + } + } + public struct UsersSelect: Codable, Hashable, Sendable, Identifiable { + public let id: Int64 public let name: String? + public let status: UserStatus? public enum CodingKeys: String, CodingKey { case id = "id" case name = "name" + case status = "status" } } - public struct MemesSelect: Codable, Hashable, Sendable { - public let category: Int32? - public let createdAt: String - public let id: Int32 - public let metadata: AnyJSON? - public let name: String - public let status: MemeStatus? + public struct UsersInsert: Codable, Hashable, Sendable, Identifiable { + public let id: Int64? + public let name: String? + public let status: UserStatus? public enum CodingKeys: String, CodingKey { - case category = "category" - case createdAt = "created_at" case id = "id" - case metadata = "metadata" case name = "name" case status = "status" } } - public struct MemesInsert: Codable, Hashable, Sendable { - public let category: Int32? - public let createdAt: String - public let id: Int32? - public let metadata: AnyJSON? - public let name: String - public let status: MemeStatus? + public struct UsersUpdate: Codable, Hashable, Sendable, Identifiable { + public let id: Int64? + public let name: String? + public let status: UserStatus? public enum CodingKeys: String, CodingKey { - case category = "category" - case createdAt = "created_at" case id = "id" - case metadata = "metadata" case name = "name" case status = "status" } } - public struct MemesUpdate: Codable, Hashable, Sendable { - public let category: Int32? + public struct UsersAuditSelect: Codable, Hashable, Sendable, Identifiable { public let createdAt: String? - public let id: Int32? - public let metadata: AnyJSON? - public let name: String? - public let status: MemeStatus? + public let id: Int64 + public let previousValue: AnyJSON? + public let userId: Int64? public enum CodingKeys: String, CodingKey { - case category = "category" case createdAt = "created_at" case id = "id" - case metadata = "metadata" - case name = "name" - case status = "status" + case previousValue = "previous_value" + case userId = "user_id" } } - public struct TodosViewSelect: Codable, Hashable, Sendable { - public let details: String? + public struct UsersAuditInsert: Codable, Hashable, Sendable, Identifiable { + public let createdAt: String? public let id: Int64? + public let previousValue: AnyJSON? public let userId: Int64? public enum CodingKeys: String, CodingKey { - case details = "details" + case createdAt = "created_at" case id = "id" - case userId = "user-id" + case previousValue = "previous_value" + case userId = "user_id" } } - public struct UsersViewSelect: Codable, Hashable, Sendable { + public struct UsersAuditUpdate: Codable, Hashable, Sendable, Identifiable { + public let createdAt: String? public let id: Int64? - public let name: String? - public let status: UserStatus? + public let previousValue: AnyJSON? + public let userId: Int64? public enum CodingKeys: String, CodingKey { + case createdAt = "created_at" case id = "id" - case name = "name" - case status = "status" + case previousValue = "previous_value" + case userId = "user_id" } } public struct AViewSelect: Codable, Hashable, Sendable { @@ -2378,6 +2418,26 @@ test('typegen: swift w/ public access control', async () => { case userId = "user-id" } } + public struct TodosViewSelect: Codable, Hashable, Sendable { + public let details: String? + public let id: Int64? + public let userId: Int64? + public enum CodingKeys: String, CodingKey { + case details = "details" + case id = "id" + case userId = "user-id" + } + } + public struct UsersViewSelect: Codable, Hashable, Sendable { + public let id: Int64? + public let name: String? + public let status: UserStatus? + public enum CodingKeys: String, CodingKey { + case id = "id" + case name = "name" + case status = "status" + } + } public struct CompositeTypeWithArrayAttribute: Codable, Hashable, Sendable { public let MyTextArray: AnyJSON public enum CodingKeys: String, CodingKey {