GramJs: Auto-generate reduced schema (#1615)

This commit is contained in:
Alexander Zinchuk 2022-01-05 17:45:31 +01:00
parent e2ee40371d
commit 0fc3d6e36b
5 changed files with 250 additions and 1203 deletions

View File

@ -3,27 +3,56 @@ const path = require('path');
require('./types-generator/generate');
function generateSchema(input, output, reducedMethods) {
let apiTl = fs.readFileSync(
path.resolve(__dirname, input),
'utf-8',
);
if (reducedMethods) {
apiTl = stripTl(apiTl);
const methodList = JSON.parse(fs.readFileSync(
path.resolve(__dirname, reducedMethods),
'utf-8',
));
let isFunction = false;
const reducedApiTl = [];
for (const line of apiTl.split('\n')) {
if (!line) {
continue;
}
const match = line.match(/---(\w+)---/);
if (match) {
const [, followingTypes] = match;
isFunction = followingTypes === 'functions';
reducedApiTl.push(line);
continue;
}
if (!isFunction) {
reducedApiTl.push(line);
} else if (methodList.includes(line.match(/([\w.]+)#/)[1])) {
reducedApiTl.push(line);
}
}
apiTl = reducedApiTl.join('\n');
}
fs.writeFileSync(
path.resolve(__dirname, output),
`module.exports = \`${stripTl(apiTl)}\`;`,
);
}
function main() {
const args = process.argv.slice(2);
const FULL_SCHEMA = args.length && args[0] === 'full';
const apiTl = fs.readFileSync(
path.resolve(__dirname, `./static/api${!FULL_SCHEMA ? '.reduced' : ''}.tl`),
'utf-8',
);
fs.writeFileSync(
path.resolve(__dirname, './apiTl.js'),
`module.exports = \`${stripTl(apiTl)}\`;`,
);
const schemaTl = fs.readFileSync(
path.resolve(__dirname, `./static/schema${!FULL_SCHEMA ? '.reduced' : ''}.tl`),
'utf-8',
);
fs.writeFileSync(
path.resolve(__dirname, './schemaTl.js'),
`module.exports = \`${stripTl(schemaTl)}\`;`,
);
generateSchema('./static/api.tl', './apiTl.js', !FULL_SCHEMA && './static/api.json');
generateSchema('./static/schema.tl', './schemaTl.js', !FULL_SCHEMA && './static/schema.json');
}
function stripTl(tl) {

View File

@ -0,0 +1,194 @@
[
"initConnection",
"invokeWithLayer",
"auth.sendCode",
"auth.signUp",
"auth.signIn",
"auth.logOut",
"auth.resetAuthorizations",
"auth.exportAuthorization",
"auth.importAuthorization",
"auth.bindTempAuthKey",
"auth.checkPassword",
"auth.requestPasswordRecovery",
"auth.resendCode",
"auth.cancelCode",
"auth.dropTempAuthKeys",
"auth.exportLoginToken",
"auth.importLoginToken",
"account.registerDevice",
"account.unregisterDevice",
"account.updateNotifySettings",
"account.getNotifySettings",
"account.updateProfile",
"account.updateStatus",
"account.getWallPapers",
"account.checkUsername",
"account.updateUsername",
"account.getPrivacy",
"account.setPrivacy",
"account.getAuthorizations",
"account.resetAuthorization",
"account.getPassword",
"account.getPasswordSettings",
"account.updatePasswordSettings",
"account.sendConfirmPhoneCode",
"account.confirmPhone",
"account.getTmpPassword",
"account.sendVerifyPhoneCode",
"account.confirmPasswordEmail",
"account.getContactSignUpNotification",
"account.setContactSignUpNotification",
"account.getNotifyExceptions",
"account.uploadWallPaper",
"account.setContentSettings",
"account.getContentSettings",
"users.getUsers",
"users.getFullUser",
"contacts.getContacts",
"contacts.importContacts",
"contacts.deleteContacts",
"contacts.block",
"contacts.unblock",
"contacts.getBlocked",
"contacts.search",
"contacts.resolveUsername",
"contacts.getTopPeers",
"contacts.addContact",
"messages.getMessages",
"messages.getDialogs",
"messages.getHistory",
"messages.search",
"messages.readHistory",
"messages.deleteHistory",
"messages.deleteMessages",
"messages.receivedMessages",
"messages.setTyping",
"messages.sendMessage",
"messages.sendMedia",
"messages.forwardMessages",
"messages.report",
"messages.getChats",
"messages.getFullChat",
"messages.editChatTitle",
"messages.editChatPhoto",
"messages.addChatUser",
"messages.deleteChatUser",
"messages.createChat",
"messages.getDhConfig",
"messages.readMessageContents",
"messages.getStickers",
"messages.getAllStickers",
"messages.getWebPagePreview",
"messages.exportChatInvite",
"messages.checkChatInvite",
"messages.importChatInvite",
"messages.getStickerSet",
"messages.installStickerSet",
"messages.uninstallStickerSet",
"messages.startBot",
"messages.migrateChat",
"messages.searchGlobal",
"messages.getDocumentByHash",
"messages.getSavedGifs",
"messages.getInlineBotResults",
"messages.sendInlineBotResult",
"messages.editMessage",
"messages.getBotCallbackAnswer",
"messages.getPeerDialogs",
"messages.saveDraft",
"messages.getFeaturedStickers",
"messages.readFeaturedStickers",
"messages.getRecentStickers",
"messages.getCommonChats",
"messages.getWebPage",
"messages.toggleDialogPin",
"messages.getPinnedDialogs",
"messages.uploadMedia",
"messages.getFavedStickers",
"messages.faveSticker",
"messages.sendMultiMedia",
"messages.searchStickerSets",
"messages.markDialogUnread",
"messages.updatePinnedMessage",
"messages.sendVote",
"messages.getOnlines",
"messages.editChatAbout",
"messages.editChatDefaultBannedRights",
"messages.getEmojiKeywordsDifference",
"messages.getScheduledHistory",
"messages.sendScheduledMessages",
"messages.deleteScheduledMessages",
"messages.getPollVotes",
"messages.getDialogFilters",
"messages.getSuggestedDialogFilters",
"messages.updateDialogFilter",
"messages.getReplies",
"messages.getDiscussionMessage",
"messages.readDiscussion",
"messages.unpinAllMessages",
"messages.deleteChat",
"messages.getMessageReadParticipants",
"messages.toggleNoForwards",
"messages.saveDefaultSendAs",
"updates.getState",
"updates.getDifference",
"updates.getChannelDifference",
"photos.uploadProfilePhoto",
"photos.getUserPhotos",
"upload.saveFilePart",
"upload.getFile",
"upload.saveBigFilePart",
"upload.getWebFile",
"help.getConfig",
"help.getNearestDc",
"help.getSupport",
"help.acceptTermsOfService",
"help.getCountriesList",
"channels.readHistory",
"channels.deleteMessages",
"channels.getMessages",
"channels.getParticipants",
"channels.getParticipant",
"channels.getChannels",
"channels.getFullChannel",
"channels.createChannel",
"channels.editAdmin",
"channels.editTitle",
"channels.editPhoto",
"channels.checkUsername",
"channels.updateUsername",
"channels.joinChannel",
"channels.leaveChannel",
"channels.inviteToChannel",
"channels.deleteChannel",
"channels.toggleSignatures",
"channels.editBanned",
"channels.readMessageContents",
"channels.togglePreHistoryHidden",
"channels.getGroupsForDiscussion",
"channels.setDiscussionGroup",
"channels.getSendAs",
"channels.viewSponsoredMessage",
"channels.getSponsoredMessages",
"payments.getPaymentForm",
"payments.getPaymentReceipt",
"payments.validateRequestedInfo",
"payments.sendPaymentForm",
"payments.getSavedInfo",
"langpack.getLangPack",
"langpack.getStrings",
"langpack.getLanguages",
"folders.editPeerFolders",
"phone.createGroupCall",
"phone.joinGroupCall",
"phone.leaveGroupCall",
"phone.discardGroupCall",
"phone.getGroupCall",
"phone.getGroupParticipants",
"phone.editGroupCallParticipant",
"phone.exportGroupCallInvite",
"phone.toggleGroupCallStartSubscription",
"phone.joinGroupCallPresentation",
"phone.leaveGroupCallPresentation"
]

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,10 @@
[
"req_pq",
"req_pq_multi",
"req_pq_multi_new",
"req_DH_params",
"set_client_DH_params",
"destroy_auth_key",
"ping",
"ping_delay_disconnect"
]

View File

@ -1,39 +0,0 @@
resPQ#05162463 nonce:int128 server_nonce:int128 pq:string server_public_key_fingerprints:Vector<long> = ResPQ;
p_q_inner_data#83c95aec pq:string p:string q:string nonce:int128 server_nonce:int128 new_nonce:int256 = P_Q_inner_data;
server_DH_params_fail#79cb045d nonce:int128 server_nonce:int128 new_nonce_hash:int128 = Server_DH_Params;
server_DH_params_ok#d0e8075c nonce:int128 server_nonce:int128 encrypted_answer:string = Server_DH_Params;
server_DH_inner_data#b5890dba nonce:int128 server_nonce:int128 g:int dh_prime:string g_a:string server_time:int = Server_DH_inner_data;
client_DH_inner_data#6643b654 nonce:int128 server_nonce:int128 retry_id:long g_b:string = Client_DH_Inner_Data;
dh_gen_ok#3bcbf734 nonce:int128 server_nonce:int128 new_nonce_hash1:int128 = Set_client_DH_params_answer;
dh_gen_retry#46dc1fb9 nonce:int128 server_nonce:int128 new_nonce_hash2:int128 = Set_client_DH_params_answer;
dh_gen_fail#a69dae02 nonce:int128 server_nonce:int128 new_nonce_hash3:int128 = Set_client_DH_params_answer;
destroy_auth_key_ok#f660e1d4 = DestroyAuthKeyRes;
destroy_auth_key_none#0a9f2259 = DestroyAuthKeyRes;
destroy_auth_key_fail#ea109b13 = DestroyAuthKeyRes;
---functions---
req_pq#60469778 nonce:int128 = ResPQ;
req_pq_multi#be7e8ef1 nonce:int128 = ResPQ;
req_pq_multi_new#51b410fd nonce:int128 = ResPQ;
req_DH_params#d712e4be nonce:int128 server_nonce:int128 p:string q:string public_key_fingerprint:long encrypted_data:string = Server_DH_Params;
set_client_DH_params#f5045f1f nonce:int128 server_nonce:int128 encrypted_data:string = Set_client_DH_params_answer;
destroy_auth_key#d1435160 = DestroyAuthKeyRes;
---types---
msgs_ack#62d6b459 msg_ids:Vector<long> = MsgsAck;
bad_msg_notification#a7eff811 bad_msg_id:long bad_msg_seqno:int error_code:int = BadMsgNotification;
bad_server_salt#edab447b bad_msg_id:long bad_msg_seqno:int error_code:int new_server_salt:long = BadMsgNotification;
msgs_state_req#da69fb52 msg_ids:Vector<long> = MsgsStateReq;
msgs_state_info#04deb57d req_msg_id:long info:string = MsgsStateInfo;
msgs_all_info#8cc0d131 msg_ids:Vector<long> info:string = MsgsAllInfo;
msg_detailed_info#276d3ec6 msg_id:long answer_msg_id:long bytes:int status:int = MsgDetailedInfo;
msg_new_detailed_info#809db6df answer_msg_id:long bytes:int status:int = MsgDetailedInfo;
msg_resend_req#7d861a08 msg_ids:Vector<long> = MsgResendReq;
rpc_error#2144ca19 error_code:int error_message:string = RpcError;
future_salt#0949d9dc valid_since:int valid_until:int salt:long = FutureSalt;
future_salts#ae500895 req_msg_id:long now:int salts:vector<future_salt> = FutureSalts;
pong#347773c5 msg_id:long ping_id:long = Pong;
destroy_session_ok#e22045fc session_id:long = DestroySessionRes;
destroy_session_none#62d350c9 session_id:long = DestroySessionRes;
new_session_created#9ec20908 first_msg_id:long unique_id:long server_salt:long = NewSession;
---functions---
ping#7abe77ec ping_id:long = Pong;
ping_delay_disconnect#f3427b8c ping_id:long disconnect_delay:int = Pong;