chore: format everything

This commit is contained in:
canove
2025-05-06 12:10:19 -03:00
parent 04afa20244
commit fa706d0b50
76 changed files with 8241 additions and 7142 deletions

View File

@@ -8,7 +8,7 @@ export class USyncContactProtocol implements USyncQueryProtocol {
getQueryElement(): BinaryNode {
return {
tag: 'contact',
attrs: {},
attrs: {}
}
}
@@ -17,16 +17,16 @@ export class USyncContactProtocol implements USyncQueryProtocol {
return {
tag: 'contact',
attrs: {},
content: user.phone,
content: user.phone
}
}
parser(node: BinaryNode): boolean {
if(node.tag === 'contact') {
if (node.tag === 'contact') {
assertNodeErrorFree(node)
return node?.attrs?.type === 'in'
}
return false
}
}
}

View File

@@ -15,7 +15,7 @@ export type DeviceListData = {
}
export type ParsedDeviceInfo = {
deviceList?: DeviceListData[]
deviceList?: DeviceListData[]
keyIndex?: KeyIndexData
}
@@ -26,8 +26,8 @@ export class USyncDeviceProtocol implements USyncQueryProtocol {
return {
tag: 'devices',
attrs: {
version: '2',
},
version: '2'
}
}
}
@@ -42,16 +42,16 @@ export class USyncDeviceProtocol implements USyncQueryProtocol {
const deviceList: DeviceListData[] = []
let keyIndex: KeyIndexData | undefined = undefined
if(node.tag === 'devices') {
if (node.tag === 'devices') {
assertNodeErrorFree(node)
const deviceListNode = getBinaryNodeChild(node, 'device-list')
const keyIndexNode = getBinaryNodeChild(node, 'key-index-list')
if(Array.isArray(deviceListNode?.content)) {
for(const { tag, attrs } of deviceListNode.content) {
if (Array.isArray(deviceListNode?.content)) {
for (const { tag, attrs } of deviceListNode.content) {
const id = +attrs.id
const keyIndex = +attrs['key-index']
if(tag === 'device') {
if (tag === 'device') {
deviceList.push({
id,
keyIndex,
@@ -61,7 +61,7 @@ export class USyncDeviceProtocol implements USyncQueryProtocol {
}
}
if(keyIndexNode?.tag === 'key-index-list') {
if (keyIndexNode?.tag === 'key-index-list') {
keyIndex = {
timestamp: +keyIndexNode.attrs['ts'],
signedKeyIndex: keyIndexNode?.content as Uint8Array,
@@ -75,4 +75,4 @@ export class USyncDeviceProtocol implements USyncQueryProtocol {
keyIndex
}
}
}
}

View File

@@ -12,7 +12,7 @@ export class USyncDisappearingModeProtocol implements USyncQueryProtocol {
getQueryElement(): BinaryNode {
return {
tag: 'disappearing_mode',
attrs: {},
attrs: {}
}
}
@@ -21,15 +21,15 @@ export class USyncDisappearingModeProtocol implements USyncQueryProtocol {
}
parser(node: BinaryNode): DisappearingModeData | undefined {
if(node.tag === 'status') {
if (node.tag === 'status') {
assertNodeErrorFree(node)
const duration: number = +node?.attrs.duration
const setAt = new Date(+(node?.attrs.t || 0) * 1000)
return {
duration,
setAt,
setAt
}
}
}
}
}

View File

@@ -12,7 +12,7 @@ export class USyncStatusProtocol implements USyncQueryProtocol {
getQueryElement(): BinaryNode {
return {
tag: 'status',
attrs: {},
attrs: {}
}
}
@@ -21,24 +21,24 @@ export class USyncStatusProtocol implements USyncQueryProtocol {
}
parser(node: BinaryNode): StatusData | undefined {
if(node.tag === 'status') {
if (node.tag === 'status') {
assertNodeErrorFree(node)
let status: string | null = node?.content!.toString()
const setAt = new Date(+(node?.attrs.t || 0) * 1000)
if(!status) {
if(+node.attrs?.code === 401) {
if (!status) {
if (+node.attrs?.code === 401) {
status = ''
} else {
status = null
}
} else if(typeof status === 'string' && status.length === 0) {
} else if (typeof status === 'string' && status.length === 0) {
status = null
}
return {
status,
setAt,
setAt
}
}
}
}
}

View File

@@ -3,21 +3,21 @@ import { BinaryNode, getBinaryNodeChild, getBinaryNodeChildren, getBinaryNodeChi
import { USyncUser } from '../USyncUser'
export type BotProfileCommand = {
name: string
description: string
name: string
description: string
}
export type BotProfileInfo = {
jid: string
name: string
attributes: string
description: string
category: string
isDefault: boolean
prompts: string[]
personaId: string
commands: BotProfileCommand[]
commandsDescription: string
jid: string
name: string
attributes: string
description: string
category: string
isDefault: boolean
prompts: string[]
personaId: string
commands: BotProfileCommand[]
commandsDescription: string
}
export class USyncBotProfileProtocol implements USyncQueryProtocol {
@@ -26,7 +26,7 @@ export class USyncBotProfileProtocol implements USyncQueryProtocol {
getQueryElement(): BinaryNode {
return {
tag: 'bot',
attrs: { },
attrs: {},
content: [{ tag: 'profile', attrs: { v: '1' } }]
}
}
@@ -34,14 +34,14 @@ export class USyncBotProfileProtocol implements USyncQueryProtocol {
getUserElement(user: USyncUser): BinaryNode {
return {
tag: 'bot',
attrs: { },
content: [{ tag: 'profile', attrs: { 'persona_id': user.personaId } }]
attrs: {},
content: [{ tag: 'profile', attrs: { persona_id: user.personaId } }]
}
}
parser(node: BinaryNode): BotProfileInfo {
const botNode = getBinaryNodeChild(node, 'bot')
const profile = getBinaryNodeChild(botNode, 'profile')
const botNode = getBinaryNodeChild(node, 'bot')
const profile = getBinaryNodeChild(botNode, 'profile')
const commandsNode = getBinaryNodeChild(profile, 'commands')
const promptsNode = getBinaryNodeChild(profile, 'prompts')
@@ -49,21 +49,20 @@ export class USyncBotProfileProtocol implements USyncQueryProtocol {
const commands: BotProfileCommand[] = []
const prompts: string[] = []
for(const command of getBinaryNodeChildren(commandsNode, 'command')) {
commands.push({
for (const command of getBinaryNodeChildren(commandsNode, 'command')) {
commands.push({
name: getBinaryNodeChildString(command, 'name')!,
description: getBinaryNodeChildString(command, 'description')!
})
}
for(const prompt of getBinaryNodeChildren(promptsNode, 'prompt')) {
prompts.push(`${getBinaryNodeChildString(prompt, 'emoji')!} ${getBinaryNodeChildString(prompt, 'text')!}`)
for (const prompt of getBinaryNodeChildren(promptsNode, 'prompt')) {
prompts.push(`${getBinaryNodeChildString(prompt, 'emoji')!} ${getBinaryNodeChildString(prompt, 'text')!}`)
}
return {
isDefault: !!getBinaryNodeChild(profile, 'default'),
jid: node.attrs.jid,
isDefault: !!getBinaryNodeChild(profile, 'default'),
jid: node.attrs.jid,
name: getBinaryNodeChildString(profile, 'name')!,
attributes: getBinaryNodeChildString(profile, 'attributes')!,
description: getBinaryNodeChildString(profile, 'description')!,

View File

@@ -7,7 +7,7 @@ export class USyncLIDProtocol implements USyncQueryProtocol {
getQueryElement(): BinaryNode {
return {
tag: 'lid',
attrs: {},
attrs: {}
}
}
@@ -16,7 +16,7 @@ export class USyncLIDProtocol implements USyncQueryProtocol {
}
parser(node: BinaryNode): string | null {
if(node.tag === 'lid') {
if (node.tag === 'lid') {
return node.attrs.val
}

View File

@@ -1,4 +1,4 @@
export * from './USyncDeviceProtocol'
export * from './USyncContactProtocol'
export * from './USyncStatusProtocol'
export * from './USyncDisappearingModeProtocol'
export * from './USyncDisappearingModeProtocol'

View File

@@ -2,14 +2,19 @@ import { USyncQueryProtocol } from '../Types/USync'
import { BinaryNode, getBinaryNodeChild } from '../WABinary'
import { USyncBotProfileProtocol } from './Protocols/UsyncBotProfileProtocol'
import { USyncLIDProtocol } from './Protocols/UsyncLIDProtocol'
import { USyncContactProtocol, USyncDeviceProtocol, USyncDisappearingModeProtocol, USyncStatusProtocol } from './Protocols'
import {
USyncContactProtocol,
USyncDeviceProtocol,
USyncDisappearingModeProtocol,
USyncStatusProtocol
} from './Protocols'
import { USyncUser } from './USyncUser'
export type USyncQueryResultList = { [protocol: string]: unknown, id: string }
export type USyncQueryResultList = { [protocol: string]: unknown; id: string }
export type USyncQueryResult = {
list: USyncQueryResultList[]
sideList: USyncQueryResultList[]
list: USyncQueryResultList[]
sideList: USyncQueryResultList[]
}
export class USyncQuery {
@@ -41,18 +46,20 @@ export class USyncQuery {
}
parseUSyncQueryResult(result: BinaryNode): USyncQueryResult | undefined {
if(result.attrs.type !== 'result') {
if (result.attrs.type !== 'result') {
return
}
const protocolMap = Object.fromEntries(this.protocols.map((protocol) => {
return [protocol.name, protocol.parser]
}))
const protocolMap = Object.fromEntries(
this.protocols.map(protocol => {
return [protocol.name, protocol.parser]
})
)
const queryResult: USyncQueryResult = {
// TODO: implement errors etc.
list: [],
sideList: [],
sideList: []
}
const usyncNode = getBinaryNodeChild(result, 'usync')
@@ -62,18 +69,24 @@ export class USyncQuery {
//const resultNode = getBinaryNodeChild(usyncNode, 'result')
const listNode = getBinaryNodeChild(usyncNode, 'list')
if(Array.isArray(listNode?.content) && typeof listNode !== 'undefined') {
queryResult.list = listNode.content.map((node) => {
if (Array.isArray(listNode?.content) && typeof listNode !== 'undefined') {
queryResult.list = listNode.content.map(node => {
const id = node?.attrs.jid
const data = Array.isArray(node?.content) ? Object.fromEntries(node.content.map((content) => {
const protocol = content.tag
const parser = protocolMap[protocol]
if(parser) {
return [protocol, parser(content)]
} else {
return [protocol, null]
}
}).filter(([, b]) => b !== null) as [string, unknown][]) : {}
const data = Array.isArray(node?.content)
? Object.fromEntries(
node.content
.map(content => {
const protocol = content.tag
const parser = protocolMap[protocol]
if (parser) {
return [protocol, parser(content)]
} else {
return [protocol, null]
}
})
.filter(([, b]) => b !== null) as [string, unknown][]
)
: {}
return { ...data, id }
})
}

View File

@@ -26,7 +26,7 @@ export class USyncUser {
}
withPersonaId(personaId: string) {
this.personaId = personaId
return this
this.personaId = personaId
return this
}
}

View File

@@ -1,3 +1,3 @@
export * from './Protocols'
export * from './USyncQuery'
export * from './USyncUser'
export * from './USyncUser'