fix(tl): automatically resolve conflicts if layer is different
This commit is contained in:
parent
ef68b414ad
commit
596362bb89
2 changed files with 27 additions and 18 deletions
|
@ -473,7 +473,6 @@ async function addDocumentation(obj) {
|
||||||
// converts telegram's json to tl
|
// converts telegram's json to tl
|
||||||
function convertJsonToTl(json) {
|
function convertJsonToTl(json) {
|
||||||
// their json schema uses signed integers for ids, we use unsigned, so we need to convert them
|
// 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 lines = []
|
||||||
const objectToLine = (cls) => {
|
const objectToLine = (cls) => {
|
||||||
|
@ -562,7 +561,15 @@ async function main() {
|
||||||
|
|
||||||
const first = convertTlToJson(apiTlTdlib, 'api')
|
const first = convertTlToJson(apiTlTdlib, 'api')
|
||||||
const second = convertTlToJson(apiTlDesktop, '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.apiLayer = apiTdlibLayer + ''
|
||||||
ret.api = first
|
ret.api = first
|
||||||
|
|
|
@ -102,11 +102,11 @@ function createTlSchemaIndex(schema) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// merge schema `b` into `a` (does not copy)
|
// merge schema `b` into `a` (does not copy)
|
||||||
async function mergeSchemas(a, b) {
|
async function mergeSchemas(a, b, conflict = null) {
|
||||||
const rl = require('readline').createInterface({
|
const rl = conflict === null ? require('readline').createInterface({
|
||||||
input: process.stdin,
|
input: process.stdin,
|
||||||
output: process.stdout,
|
output: process.stdout,
|
||||||
})
|
}) : null
|
||||||
|
|
||||||
const input = (q) => new Promise((res) => rl.question(q, res))
|
const input = (q) => new Promise((res) => rl.question(q, res))
|
||||||
|
|
||||||
|
@ -141,21 +141,23 @@ async function mergeSchemas(a, b) {
|
||||||
|
|
||||||
// check for conflict
|
// check for conflict
|
||||||
if (objA.id !== objB.id) {
|
if (objA.id !== objB.id) {
|
||||||
console.log('! CONFLICT !')
|
let keep = conflict
|
||||||
console.log('Schema A (tdlib): %s', stringifyType(objA))
|
if (conflict === null) {
|
||||||
console.log('Schema B (tdesktop): %s', stringifyType(objB))
|
console.log('! CONFLICT !')
|
||||||
|
console.log('Schema A (tdlib): %s', stringifyType(objA))
|
||||||
|
console.log('Schema B (tdesktop): %s', stringifyType(objB))
|
||||||
|
|
||||||
let keep
|
while (true) {
|
||||||
while (true) {
|
keep = await input('Which to keep? [A/B] > ')
|
||||||
keep = await input('Which to keep? [A/B] > ')
|
keep = keep.toUpperCase()
|
||||||
keep = keep.toUpperCase()
|
|
||||||
|
|
||||||
if (keep !== 'A' && keep !== 'B') {
|
if (keep !== 'A' && keep !== 'B') {
|
||||||
console.log('Invalid input! Please type A or B')
|
console.log('Invalid input! Please type A or B')
|
||||||
continue
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (keep === 'B') {
|
if (keep === 'B') {
|
||||||
|
@ -191,7 +193,7 @@ async function mergeSchemas(a, b) {
|
||||||
delete obj._type
|
delete obj._type
|
||||||
})
|
})
|
||||||
|
|
||||||
rl.close()
|
if (rl) rl.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { mergeSchemas }
|
module.exports = { mergeSchemas }
|
||||||
|
|
Loading…
Reference in a new issue