{"id":22055454,"url":"https://github.com/calasanmarko/trpc-swift","last_synced_at":"2025-05-12T15:38:30.131Z","repository":{"id":207460146,"uuid":"719233071","full_name":"calasanmarko/trpc-swift","owner":"calasanmarko","description":"Generates native Swift clients for tRPC apps.","archived":false,"fork":false,"pushed_at":"2025-04-02T12:40:34.000Z","size":364,"stargazers_count":35,"open_issues_count":8,"forks_count":6,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-19T15:57:01.696Z","etag":null,"topics":["ios","rpc","swift","trpc","ts","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/trpc-swift","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/calasanmarko.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-11-15T18:34:47.000Z","updated_at":"2025-04-16T04:46:04.000Z","dependencies_parsed_at":"2023-11-15T23:26:17.790Z","dependency_job_id":"65f66366-24c9-4003-95e9-93c387bfd30f","html_url":"https://github.com/calasanmarko/trpc-swift","commit_stats":{"total_commits":82,"total_committers":4,"mean_commits":20.5,"dds":"0.41463414634146345","last_synced_commit":"d4fb0620b6d86570ee1b545c89454b4fcc9502a2"},"previous_names":["calasanmarko/trpc-swift"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/calasanmarko%2Ftrpc-swift","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/calasanmarko%2Ftrpc-swift/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/calasanmarko%2Ftrpc-swift/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/calasanmarko%2Ftrpc-swift/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/calasanmarko","download_url":"https://codeload.github.com/calasanmarko/trpc-swift/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251670771,"owners_count":21625116,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ios","rpc","swift","trpc","ts","typescript"],"created_at":"2024-11-30T16:07:19.038Z","updated_at":"2025-05-12T15:38:30.052Z","avatar_url":"https://github.com/calasanmarko.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# trpc-swift\n\nGenerates native Swift clients for tRPC apps.\n\n# Installation\n\nAvailable as a npm package.\n\n```\nnpm install --save-dev trpc-swift\n```\n\n# Usage\n\n```\nUsage: trpc-swift -r [routerName] -i [routerPath] -o [outputPath]\nOptions:\n  -r, --router-name  Set the router name that should be found in the input file\n  -i, --input        Set the path where the tRPC input tRPC router is located\n  -o, --output       Set the output path for the generated Swift client\n  -g, --global-mode  Control which models are placed by default in the global scope.\n      all            All named models will be placed in the global scope by default.\n      top            Only named models directly referenced by routes will be placed in the global scope by default.\n      none           No models will be placed in the global scope by default.\n  -p, --public       Assign the public access modifier for all generated Swift models and routes.\n  -a, --alias        Create public type aliases for all models in the global scope.\n  -s, --shared       Create a shared singleton instance of the generated Swift client.\n  -h, --help         Display this help message\n  -q, --quiet        Run in quiet mode (no output except for fatal errors)\n```\n\n# Generation\n\nAll routes in the input router are automatically detected and converted into Swift classes. Nested routers create nested Swift classes, tRPC procedures get converted into Swift methods. All referenced Zod input/output schemas, as well as their children get converted into Swift structures.\n\nFor instance, the following tRPC router and Zod schemas:\n\n```\nextendZodWithSwift(z);\n\nconst userSchema = z\n    .object({\n        id: z.string().uuid(),\n        name: z.object({\n            first: z.string(),\n            middle: z.string().optional(),\n            last: z.string(),\n        }),\n        email: z.string().optional(),\n        dateCreated: z.date(),\n    })\n    .swift({\n        name: \"User\",\n    });\n\nexport const appRouter = router({\n    user: router({\n        get: authClientProcedure\n            .meta({\n                swift: {\n                    description: \"Fetches a user by ID.\",\n                },\n            })\n            .input(\n                z.object({\n                    id: userSchema.shape.id,\n                })\n            )\n            .output(userSchema)\n            .query(/** some implementation */),\n    }),\n});\n```\n\nwill result in the following generated Swift client:\n\n```\nclass AppRouter: TRPCClientData {\n    lazy var user = UserRoute(clientData: self)\n\n    // Scaffolding omitted\n\n    init(baseUrl: URL? = nil, middlewares: [TRPCMiddleware] = []) {\n        self.baseUrl = baseUrl\n        self.baseMiddlewares = middlewares\n    }\n\n    struct User: Codable, Equatable {\n        var id: String\n        struct Name: Codable, Equatable {\n            var first: String\n            var middle: String?\n            var last: String\n        }\n        var name: Name\n        var email: String?\n        var dateCreated: Date\n    }\n\n    class UserRoute: TRPCClientData {\n        let clientData: TRPCClientData\n\n        // Scaffolding omitted...\n\n        struct GetInputType: Codable, Equatable {\n            var id: String\n        }\n\n        /// Fetches a user by ID.\n        func get(input: GetInputType) async throws -\u003e User {\n            return try await TRPCClient.shared.sendQuery(url: url.appendingPathExtension(\"get\"), middlewares: middlewares, input: input)\n        }\n    }\n}\n```\n\nThe generated Swift class is self-contained, handles networking and routing. All you need to do is add it to your Swift project.\n\n# License\n\nMade by Marko Calasan, 2023.\n\nThis product is licensed under the MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcalasanmarko%2Ftrpc-swift","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcalasanmarko%2Ftrpc-swift","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcalasanmarko%2Ftrpc-swift/lists"}