build: build with vite (major cleanup part2) #67
15 changed files with 20 additions and 68 deletions
|
@ -4,7 +4,7 @@ import { dataViewFromBuffer } from '@mtcute/core/utils.js'
|
|||
|
||||
import type { TelethonSession } from '../telethon/types.js'
|
||||
|
||||
export function serializeGramjsSession(session: TelethonSession) {
|
||||
export function serializeGramjsSession(session: TelethonSession): string {
|
||||
if (session.authKey.length !== 256) {
|
||||
throw new MtArgumentError('authKey must be 256 bytes long')
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ import { serializeIpv4ToBytes, serializeIpv6ToBytes } from '../utils/ip.js'
|
|||
|
||||
import type { TelethonSession } from './types.js'
|
||||
|
||||
export function serializeTelethonSession(session: TelethonSession) {
|
||||
export function serializeTelethonSession(session: TelethonSession): string {
|
||||
if (session.authKey.length !== 256) {
|
||||
throw new MtArgumentError('authKey must be 256 bytes long')
|
||||
}
|
||||
|
|
|
@ -68,7 +68,7 @@ export class WorkerInvoker {
|
|||
}
|
||||
}
|
||||
|
||||
makeBinder<T>(target: InvokeTarget) {
|
||||
makeBinder<T>(target: InvokeTarget): <K extends keyof T>(method: K, isVoid?: boolean) => T[K] {
|
||||
return <K extends keyof T>(method: K, isVoid = false) => {
|
||||
let fn
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ import type { IStorageDriver } from '../driver.js'
|
|||
export class MemoryStorageDriver implements IStorageDriver {
|
||||
readonly states: Map<string, object> = new Map()
|
||||
|
||||
getState<T extends object>(repo: string, def: () => T) {
|
||||
getState<T extends object>(repo: string, def: () => T): T {
|
||||
if (!this.states.has(repo)) {
|
||||
this.states.set(repo, def())
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ import { describe, expect, it } from 'vitest'
|
|||
import {
|
||||
assertTypeIs,
|
||||
assertTypeIsNot,
|
||||
hasPresentKey,
|
||||
hasValueAtKey,
|
||||
isPresent,
|
||||
mtpAssertTypeIs,
|
||||
|
@ -23,24 +22,6 @@ describe('isPresent', () => {
|
|||
})
|
||||
})
|
||||
|
||||
describe('hasPresentKey', () => {
|
||||
it('should return true for objects with present keys', () => {
|
||||
expect(hasPresentKey('a')({ a: 1 })).toBe(true)
|
||||
expect(hasPresentKey('a')({ a: 1, b: 2 })).toBe(true)
|
||||
})
|
||||
|
||||
it('should return false for objects with undefined/null keys', () => {
|
||||
expect(hasPresentKey('a')({ a: undefined })).toBe(false)
|
||||
expect(hasPresentKey('a')({ a: null })).toBe(false)
|
||||
expect(hasPresentKey('a')({ a: undefined, b: 2 })).toBe(false)
|
||||
expect(hasPresentKey('a')({ a: null, b: 2 })).toBe(false)
|
||||
})
|
||||
|
||||
it('should return false for objects without the key', () => {
|
||||
expect(hasPresentKey('a')({ b: 2 })).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('hasValueAtKey', () => {
|
||||
it('should return true for objects with the correct value', () => {
|
||||
expect(hasValueAtKey('a', 1)({ a: 1 })).toBe(true)
|
||||
|
|
|
@ -8,25 +8,6 @@ export function isPresent<T>(t: T | undefined | null | void): t is T {
|
|||
return t !== undefined && t !== null
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a function that can be used to filter down objects
|
||||
* to the ones that have a defined non-null value under the key `k`.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* const filesWithUrl = files.filter(file => file.url);
|
||||
* files[0].url // In this case, TS might still treat this as undefined/null
|
||||
*
|
||||
* const filesWithUrl = files.filter(hasPresentKey("url"));
|
||||
* files[0].url // TS will know that this is present
|
||||
* ```
|
||||
*/
|
||||
export function hasPresentKey<K extends string | number | symbol>(k: K) {
|
||||
return function <T, V> (a: T & { [k in K]?: V | null }): a is T & { [k in K]: V } {
|
||||
return a[k] !== undefined && a[k] !== null
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a function that can be used to filter down objects
|
||||
* to the ones that have a specific value V under a key `k`.
|
||||
|
@ -44,7 +25,8 @@ export function hasPresentKey<K extends string | number | symbol>(k: K) {
|
|||
* files[0].imageUrl // TS will know this is present, because already it excluded the other union members.
|
||||
* ```
|
||||
*/
|
||||
export function hasValueAtKey<const K extends string | number | symbol, const V>(k: K, v: V) {
|
||||
export function hasValueAtKey<const K extends string | number | symbol, const V>(k: K, v: V):
|
||||
<T>(a: T & { [k in K]: unknown }) => a is T & { [k in K]: V } {
|
||||
return function <T> (a: T & { [k in K]: unknown }): a is T & { [k in K]: V } {
|
||||
return a[k] === v
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ import type { UpdateContext } from './base.js'
|
|||
*/
|
||||
export class BusinessMessageContext extends BusinessMessage implements UpdateContext<BusinessMessage> {
|
||||
// this is primarily for proper types in filters, so don't bother much with actual value
|
||||
readonly _name = 'new_business_message'
|
||||
readonly _name = 'new_business_message' as const
|
||||
|
||||
/**
|
||||
* List of messages in the message group.
|
||||
|
|
|
@ -10,7 +10,7 @@ import type { UpdateContext } from './base.js'
|
|||
* This is a subclass of {@link CallbackQuery}, so all its fields are also available.
|
||||
*/
|
||||
export class CallbackQueryContext extends CallbackQuery implements UpdateContext<CallbackQuery> {
|
||||
readonly _name = 'callback_query'
|
||||
readonly _name = 'callback_query' as const
|
||||
|
||||
constructor(
|
||||
readonly client: TelegramClient,
|
||||
|
@ -67,7 +67,7 @@ export class CallbackQueryContext extends CallbackQuery implements UpdateContext
|
|||
* This is a subclass of {@link InlineCallbackQuery}, so all its fields are also available.
|
||||
*/
|
||||
export class InlineCallbackQueryContext extends InlineCallbackQuery implements UpdateContext<InlineCallbackQuery> {
|
||||
readonly _name = 'inline_callback_query'
|
||||
readonly _name = 'inline_callback_query' as const
|
||||
|
||||
constructor(
|
||||
readonly client: TelegramClient,
|
||||
|
@ -100,7 +100,7 @@ export class InlineCallbackQueryContext extends InlineCallbackQuery implements U
|
|||
export class BusinessCallbackQueryContext
|
||||
extends BusinessCallbackQuery
|
||||
implements UpdateContext<BusinessCallbackQuery> {
|
||||
readonly _name = 'business_callback_query'
|
||||
readonly _name = 'business_callback_query' as const
|
||||
|
||||
constructor(
|
||||
readonly client: TelegramClient,
|
||||
|
|
|
@ -11,7 +11,7 @@ import type { UpdateContext } from './base.js'
|
|||
export class ChatJoinRequestUpdateContext
|
||||
extends BotChatJoinRequestUpdate
|
||||
implements UpdateContext<BotChatJoinRequestUpdate> {
|
||||
readonly _name = 'bot_chat_join_request'
|
||||
readonly _name = 'bot_chat_join_request' as const
|
||||
|
||||
constructor(
|
||||
readonly client: TelegramClient,
|
||||
|
|
|
@ -12,7 +12,7 @@ import type { UpdateContext } from './base.js'
|
|||
* > Inline feedback in [@BotFather](//t.me/botfather)
|
||||
*/
|
||||
export class ChosenInlineResultContext extends ChosenInlineResult implements UpdateContext<ChosenInlineResult> {
|
||||
readonly _name = 'chosen_inline_result'
|
||||
readonly _name = 'chosen_inline_result' as const
|
||||
|
||||
constructor(
|
||||
readonly client: TelegramClient,
|
||||
|
|
|
@ -10,7 +10,7 @@ import type { UpdateContext } from './base.js'
|
|||
* This is a subclass of {@link InlineQuery}, so all its fields are also available.
|
||||
*/
|
||||
export class InlineQueryContext extends InlineQuery implements UpdateContext<InlineQuery> {
|
||||
readonly _name = 'inline_query'
|
||||
readonly _name = 'inline_query' as const
|
||||
|
||||
constructor(
|
||||
readonly client: TelegramClient,
|
||||
|
|
|
@ -21,7 +21,7 @@ import type { UpdateContext } from './base.js'
|
|||
*/
|
||||
export class MessageContext extends Message implements UpdateContext<Message> {
|
||||
// this is primarily for proper types in filters, so don't bother much with actual value
|
||||
readonly _name = 'new_message'
|
||||
readonly _name = 'new_message' as const
|
||||
|
||||
/**
|
||||
* List of messages in the message group.
|
||||
|
|
|
@ -9,7 +9,7 @@ import type { UpdateContext } from './base.js'
|
|||
* This is a subclass of {@link PreCheckoutQuery}, so all its fields are also available.
|
||||
*/
|
||||
export class PreCheckoutQueryContext extends PreCheckoutQuery implements UpdateContext<PreCheckoutQuery> {
|
||||
readonly _name = 'pre_checkout_query'
|
||||
readonly _name = 'pre_checkout_query' as const
|
||||
|
||||
constructor(
|
||||
readonly client: TelegramClient,
|
||||
|
|
|
@ -9,7 +9,7 @@ import { join } from 'node:path'
|
|||
import * as readline from 'node:readline'
|
||||
|
||||
import * as cheerio from 'cheerio'
|
||||
import { hasPresentKey, isPresent } from '@mtcute/core/utils.js'
|
||||
import { isPresent } from '@mtcute/core/utils.js'
|
||||
import type {
|
||||
TlEntry,
|
||||
TlFullSchema,
|
||||
|
@ -299,17 +299,17 @@ async function main() {
|
|||
}
|
||||
}
|
||||
|
||||
const nonEmptyOptions = chooseOptions.filter(hasPresentKey('entry'))
|
||||
const nonEmptyOptions = chooseOptions.filter(it => it.entry !== undefined)
|
||||
|
||||
console.log(
|
||||
'Conflict detected (%s) at %s %s:',
|
||||
mergeError,
|
||||
nonEmptyOptions[0].entry.kind,
|
||||
nonEmptyOptions[0].entry.name,
|
||||
nonEmptyOptions[0].entry!.kind,
|
||||
nonEmptyOptions[0].entry!.name,
|
||||
)
|
||||
console.log('0. Remove')
|
||||
nonEmptyOptions.forEach((opt, idx) => {
|
||||
console.log(`${idx + 1}. ${opt.schema.name}: (${opt.entry.kind}) ${writeTlEntryToString(opt.entry)}`)
|
||||
console.log(`${idx + 1}. ${opt.schema.name}: (${opt.entry!.kind}) ${writeTlEntryToString(opt.entry!)}`)
|
||||
})
|
||||
|
||||
while (true) {
|
||||
|
|
|
@ -5,7 +5,6 @@ import * as path from 'node:path'
|
|||
|
||||
import * as glob from 'glob'
|
||||
import ts from 'typescript'
|
||||
import * as stc from '@teidesu/slow-types-compiler'
|
||||
|
||||
const __dirname = path.dirname(new URL(import.meta.url).pathname)
|
||||
|
||||
|
@ -570,16 +569,6 @@ if (IS_JSR) {
|
|||
)
|
||||
}
|
||||
}
|
||||
|
||||
console.log('[i] Processing with slow-types-compiler...')
|
||||
const project = stc.createProject()
|
||||
stc.processPackage(project, denoJson)
|
||||
const unsavedSourceFiles = project.getSourceFiles().filter(s => !s.isSaved())
|
||||
|
||||
if (unsavedSourceFiles.length > 0) {
|
||||
console.log('[v] Changed %d files', unsavedSourceFiles.length)
|
||||
project.saveSync()
|
||||
}
|
||||
} else {
|
||||
// make shims for esnext resolution (that doesn't respect package.json `exports` field)
|
||||
function makeShim(name, target) {
|
||||
|
|
Loading…
Reference in a new issue