(apiSchema: ApiSchema)
| 1967 | } |
| 1968 | |
| 1969 | function generateRpcCode(apiSchema: ApiSchema): string { |
| 1970 | const defCollections = collectDefinitionCollections( |
| 1971 | apiSchema as unknown as Record<string, unknown>, |
| 1972 | ); |
| 1973 | |
| 1974 | const serverMethods = apiSchema.server |
| 1975 | ? collectRpcMethods(apiSchema.server as Record<string, unknown>) |
| 1976 | : []; |
| 1977 | const sessionMethods = apiSchema.session |
| 1978 | ? collectRpcMethods(apiSchema.session as Record<string, unknown>) |
| 1979 | : []; |
| 1980 | |
| 1981 | const clientRoot = buildNamespaceTree("ClientRpc", serverMethods, ""); |
| 1982 | const sessionRoot = buildNamespaceTree( |
| 1983 | "SessionRpc", |
| 1984 | sessionMethods, |
| 1985 | "session.", |
| 1986 | ); |
| 1987 | |
| 1988 | const out: string[] = []; |
| 1989 | out.push( |
| 1990 | "//! Auto-generated typed JSON-RPC namespace — do not edit manually.", |
| 1991 | ); |
| 1992 | out.push("//!"); |
| 1993 | out.push( |
| 1994 | "//! Generated from `api.schema.json` by `scripts/codegen/rust.ts`. The", |
| 1995 | ); |
| 1996 | out.push( |
| 1997 | "//! [`ClientRpc`] and [`SessionRpc`] view structs let callers reach every", |
| 1998 | ); |
| 1999 | out.push( |
| 2000 | "//! protocol method through a typed namespace tree, so wire method names", |
| 2001 | ); |
| 2002 | out.push( |
| 2003 | "//! and request/response shapes live in exactly one place — this file.", |
| 2004 | ); |
| 2005 | out.push(""); |
| 2006 | out.push("#![allow(missing_docs)]"); |
| 2007 | out.push("#![allow(clippy::too_many_arguments)]"); |
| 2008 | out.push("#![allow(deprecated)]"); |
| 2009 | out.push("#![allow(dead_code)]"); |
| 2010 | out.push(""); |
| 2011 | out.push("use super::api_types::{rpc_methods, *};"); |
| 2012 | const externalTypeRefs = new Map<string, Set<string>>(); |
| 2013 | const recordExternalTypeRef = (ref: string | undefined): void => { |
| 2014 | if (!ref) return; |
| 2015 | const externalRef = parseExternalSchemaRef(ref); |
| 2016 | if (!externalRef) return; |
| 2017 | let typeNames = externalTypeRefs.get(externalRef.schemaFile); |
| 2018 | if (!typeNames) { |
| 2019 | typeNames = new Set<string>(); |
| 2020 | externalTypeRefs.set(externalRef.schemaFile, typeNames); |
| 2021 | } |
| 2022 | typeNames.add(externalRef.definitionName); |
| 2023 | }; |
| 2024 | for (const method of [...serverMethods, ...sessionMethods]) { |
| 2025 | recordExternalTypeRef(method.params?.$ref); |
| 2026 | recordExternalTypeRef(method.result?.$ref); |
no test coverage detected
searching dependent graphs…