fix(tl): automatically resolve conflicts if layer is different

This commit is contained in:
teidesu 2021-06-27 15:06:42 +03:00
parent ef68b414ad
commit 596362bb89
2 changed files with 27 additions and 18 deletions

View file

@ -473,7 +473,6 @@ async function addDocumentation(obj) {
// converts telegram's json to tl
function convertJsonToTl(json) {
// their json schema uses signed integers for ids, we use unsigned, so we need to convert them
const signedInt32ToUnsigned = (val) => (val < 0 ? val + 0x100000000 : val)
const lines = []
const objectToLine = (cls) => {
@ -562,7 +561,15 @@ async function main() {
const first = convertTlToJson(apiTlTdlib, 'api')
const second = convertTlToJson(apiTlDesktop, 'api')
await mergeSchemas(first, second)
const onConflict =
apiDesktopLayer === apiTdlibLayer
? null // manual conflict resolving
: apiTdlibLayer > apiDesktopLayer // use ctor from newer schema
? 'A'
: 'B'
await mergeSchemas(first, second, onConflict)
ret.apiLayer = apiTdlibLayer + ''
ret.api = first

View file

@ -102,11 +102,11 @@ function createTlSchemaIndex(schema) {
}
// merge schema `b` into `a` (does not copy)
async function mergeSchemas(a, b) {
const rl = require('readline').createInterface({
async function mergeSchemas(a, b, conflict = null) {
const rl = conflict === null ? require('readline').createInterface({
input: process.stdin,
output: process.stdout,
})
}) : null
const input = (q) => new Promise((res) => rl.question(q, res))
@ -141,21 +141,23 @@ async function mergeSchemas(a, b) {
// check for conflict
if (objA.id !== objB.id) {
console.log('! CONFLICT !')
console.log('Schema A (tdlib): %s', stringifyType(objA))
console.log('Schema B (tdesktop): %s', stringifyType(objB))
let keep = conflict
if (conflict === null) {
console.log('! CONFLICT !')
console.log('Schema A (tdlib): %s', stringifyType(objA))
console.log('Schema B (tdesktop): %s', stringifyType(objB))
let keep
while (true) {
keep = await input('Which to keep? [A/B] > ')
keep = keep.toUpperCase()
while (true) {
keep = await input('Which to keep? [A/B] > ')
keep = keep.toUpperCase()
if (keep !== 'A' && keep !== 'B') {
console.log('Invalid input! Please type A or B')
continue
if (keep !== 'A' && keep !== 'B') {
console.log('Invalid input! Please type A or B')
continue
}
break
}
break
}
if (keep === 'B') {
@ -191,7 +193,7 @@ async function mergeSchemas(a, b) {
delete obj._type
})
rl.close()
if (rl) rl.close()
}
module.exports = { mergeSchemas }