fix: proto-extract auto-convert required to optional for proto3 compatibility
This commit implements a permanent fix for the proto extraction process to handle WhatsApp's recent changes where they mark certain fields as "required" in their JavaScript metadata. Changes: 1. proto-extract/index.js: - Added automatic conversion of 'required' to 'optional' after proto generation - Proto3 spec doesn't support 'required' keyword (only proto2 does) - All fields in proto3 are implicitly optional by default 2. WAProto/WAProto.proto: - Updated to WhatsApp version 2.3000.1033472679 (latest) - All 27 'required' fields converted to 'optional' - Now compiles successfully with protoc 3. WAProto/index.d.ts & index.js: - Regenerated with correct proto3 syntax - index.d.ts now has 14,572 lines (was 2 lines when broken) - Full TypeScript definitions restored Impact: - ✅ Build now succeeds (was failing with proto3 required error) - ✅ Tests: 582/583 passing (99.8%) - ✅ Lint: 0 errors, 239 warnings - ✅ Future proto updates will auto-fix 'required' fields Technical details: WhatsApp Web still uses proto3 but now marks certain fields as "required" in their JS metadata. The extractor was copying these flags directly, causing invalid proto3 syntax. This fix ensures all 'required' keywords are converted to 'optional' after extraction, maintaining proto3 compliance. https://claude.ai/code/session_015R3U3kiprQiNTTNNt31Sg6
This commit is contained in:
@@ -499,7 +499,12 @@ async function findAppModules() {
|
||||
const decodedProto = Object.keys(decodedProtoMap).sort();
|
||||
const sortedStr = decodedProto.map((d) => decodedProtoMap[d]).join('\n');
|
||||
|
||||
const decodedProtoStr = `syntax = "proto3";\npackage proto;\n\n/// WhatsApp Version: ${whatsAppVersion}\n\n${sortedStr}`;
|
||||
let decodedProtoStr = `syntax = "proto3";\npackage proto;\n\n/// WhatsApp Version: ${whatsAppVersion}\n\n${sortedStr}`;
|
||||
|
||||
// Fix: proto3 doesn't support 'required' keyword (only proto2 does)
|
||||
// Convert all 'required' fields to 'optional' for proto3 compatibility
|
||||
decodedProtoStr = decodedProtoStr.replace(/(\n\s+)required /g, '$1optional ');
|
||||
|
||||
const destinationPath = '../WAProto/WAProto.proto';
|
||||
await fs.writeFile(destinationPath, decodedProtoStr);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user