(schemaPath?: string, sessionEventsSchema?: JSONSchema7)
| 2806 | // ── RPC Types ─────────────────────────────────────────────────────────────── |
| 2807 | |
| 2808 | async function generateRpc(schemaPath?: string, sessionEventsSchema?: JSONSchema7): Promise<void> { |
| 2809 | console.log("Python: generating RPC types..."); |
| 2810 | const { FetchingJSONSchemaStore, InputData, JSONSchemaInput, quicktype } = await import("quicktype-core"); |
| 2811 | |
| 2812 | const resolvedPath = schemaPath ?? (await getApiSchemaPath()); |
| 2813 | let schema = fixNullableRequiredRefsInApiSchema(cloneSchemaForCodegen((await loadSchemaJson(resolvedPath)) as ApiSchema)); |
| 2814 | if (sessionEventsSchema) { |
| 2815 | const sharedDefinitions = findSharedSchemaDefinitions( |
| 2816 | schema as unknown as Record<string, unknown>, |
| 2817 | sessionEventsSchema as unknown as Record<string, unknown> |
| 2818 | ); |
| 2819 | const reachableDefinitions = collectReachableDefinitionNames(sessionEventsSchema as unknown as Record<string, unknown>); |
| 2820 | const exportedSessionEventTypes = collectPythonSessionEventExportedTypeNames(sessionEventsSchema); |
| 2821 | for (const name of [...sharedDefinitions]) { |
| 2822 | if (!reachableDefinitions.has(name) || !exportedSessionEventTypes.has(name)) { |
| 2823 | sharedDefinitions.delete(name); |
| 2824 | } |
| 2825 | } |
| 2826 | schema = rewriteSharedDefinitionReferences(schema, sharedDefinitions, "session-events.schema.json"); |
| 2827 | } |
| 2828 | |
| 2829 | const allMethods = [ |
| 2830 | ...collectRpcMethods(schema.server || {}), |
| 2831 | ...collectRpcMethods(schema.session || {}), |
| 2832 | ...collectRpcMethods(schema.clientSession || {}), |
| 2833 | ]; |
| 2834 | |
| 2835 | // Build a combined schema for quicktype, including shared definitions from the API schema |
| 2836 | rpcDefinitions = collectDefinitionCollections(schema as Record<string, unknown>); |
| 2837 | const combinedSchema = withSharedDefinitions( |
| 2838 | { |
| 2839 | $schema: "http://json-schema.org/draft-07/schema#", |
| 2840 | }, |
| 2841 | rpcDefinitions |
| 2842 | ); |
| 2843 | |
| 2844 | for (const method of allMethods) { |
| 2845 | const resultSchema = getMethodResultSchema(method); |
| 2846 | if (!isVoidSchema(resultSchema)) { |
| 2847 | const nullableInner = resultSchema ? getNullableInner(resultSchema) : undefined; |
| 2848 | if (!nullableInner) { |
| 2849 | combinedSchema.definitions![pythonResultTypeName(method)] = withRootTitle( |
| 2850 | schemaSourceForNamedDefinition(method.result, resultSchema), |
| 2851 | pythonResultTypeName(method) |
| 2852 | ); |
| 2853 | } |
| 2854 | // For nullable results, the inner type (e.g., SessionFsError) is already in definitions |
| 2855 | } |
| 2856 | const resolvedParams = getMethodParamsSchema(method); |
| 2857 | if (method.params && hasSchemaPayload(resolvedParams)) { |
| 2858 | if (method.rpcMethod.startsWith("session.") && resolvedParams?.properties) { |
| 2859 | const filtered: JSONSchema7 = { |
| 2860 | ...resolvedParams, |
| 2861 | properties: Object.fromEntries( |
| 2862 | Object.entries(resolvedParams.properties).filter(([k]) => k !== "sessionId") |
| 2863 | ), |
| 2864 | required: resolvedParams.required?.filter((r) => r !== "sessionId"), |
| 2865 | }; |
no test coverage detected
searching dependent graphs…