build: don't use stc when building

This commit is contained in:
alina 🌸 2024-08-19 14:08:49 +03:00
parent 748517a8fc
commit 26d1175b26
Signed by: teidesu
SSH key fingerprint: SHA256:uNeCpw6aTSU4aIObXLvHfLkDa82HWH9EiOj9AXOIRpI
15 changed files with 20 additions and 68 deletions

View file

@ -4,7 +4,7 @@ import { dataViewFromBuffer } from '@mtcute/core/utils.js'
import type { TelethonSession } from '../telethon/types.js' import type { TelethonSession } from '../telethon/types.js'
export function serializeGramjsSession(session: TelethonSession) { export function serializeGramjsSession(session: TelethonSession): string {
if (session.authKey.length !== 256) { if (session.authKey.length !== 256) {
throw new MtArgumentError('authKey must be 256 bytes long') throw new MtArgumentError('authKey must be 256 bytes long')
} }

View file

@ -6,7 +6,7 @@ import { serializeIpv4ToBytes, serializeIpv6ToBytes } from '../utils/ip.js'
import type { TelethonSession } from './types.js' import type { TelethonSession } from './types.js'
export function serializeTelethonSession(session: TelethonSession) { export function serializeTelethonSession(session: TelethonSession): string {
if (session.authKey.length !== 256) { if (session.authKey.length !== 256) {
throw new MtArgumentError('authKey must be 256 bytes long') throw new MtArgumentError('authKey must be 256 bytes long')
} }

View file

@ -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) => { return <K extends keyof T>(method: K, isVoid = false) => {
let fn let fn

View file

@ -3,7 +3,7 @@ import type { IStorageDriver } from '../driver.js'
export class MemoryStorageDriver implements IStorageDriver { export class MemoryStorageDriver implements IStorageDriver {
readonly states: Map<string, object> = new Map() 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)) { if (!this.states.has(repo)) {
this.states.set(repo, def()) this.states.set(repo, def())
} }

View file

@ -3,7 +3,6 @@ import { describe, expect, it } from 'vitest'
import { import {
assertTypeIs, assertTypeIs,
assertTypeIsNot, assertTypeIsNot,
hasPresentKey,
hasValueAtKey, hasValueAtKey,
isPresent, isPresent,
mtpAssertTypeIs, 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', () => { describe('hasValueAtKey', () => {
it('should return true for objects with the correct value', () => { it('should return true for objects with the correct value', () => {
expect(hasValueAtKey('a', 1)({ a: 1 })).toBe(true) expect(hasValueAtKey('a', 1)({ a: 1 })).toBe(true)

View file

@ -8,25 +8,6 @@ export function isPresent<T>(t: T | undefined | null | void): t is T {
return t !== undefined && t !== null 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 * Returns a function that can be used to filter down objects
* to the ones that have a specific value V under a key `k`. * 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. * 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 function <T> (a: T & { [k in K]: unknown }): a is T & { [k in K]: V } {
return a[k] === v return a[k] === v
} }

View file

@ -21,7 +21,7 @@ import type { UpdateContext } from './base.js'
*/ */
export class BusinessMessageContext extends BusinessMessage implements UpdateContext<BusinessMessage> { export class BusinessMessageContext extends BusinessMessage implements UpdateContext<BusinessMessage> {
// this is primarily for proper types in filters, so don't bother much with actual value // 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. * List of messages in the message group.

View file

@ -10,7 +10,7 @@ import type { UpdateContext } from './base.js'
* This is a subclass of {@link CallbackQuery}, so all its fields are also available. * This is a subclass of {@link CallbackQuery}, so all its fields are also available.
*/ */
export class CallbackQueryContext extends CallbackQuery implements UpdateContext<CallbackQuery> { export class CallbackQueryContext extends CallbackQuery implements UpdateContext<CallbackQuery> {
readonly _name = 'callback_query' readonly _name = 'callback_query' as const
constructor( constructor(
readonly client: TelegramClient, 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. * This is a subclass of {@link InlineCallbackQuery}, so all its fields are also available.
*/ */
export class InlineCallbackQueryContext extends InlineCallbackQuery implements UpdateContext<InlineCallbackQuery> { export class InlineCallbackQueryContext extends InlineCallbackQuery implements UpdateContext<InlineCallbackQuery> {
readonly _name = 'inline_callback_query' readonly _name = 'inline_callback_query' as const
constructor( constructor(
readonly client: TelegramClient, readonly client: TelegramClient,
@ -100,7 +100,7 @@ export class InlineCallbackQueryContext extends InlineCallbackQuery implements U
export class BusinessCallbackQueryContext export class BusinessCallbackQueryContext
extends BusinessCallbackQuery extends BusinessCallbackQuery
implements UpdateContext<BusinessCallbackQuery> { implements UpdateContext<BusinessCallbackQuery> {
readonly _name = 'business_callback_query' readonly _name = 'business_callback_query' as const
constructor( constructor(
readonly client: TelegramClient, readonly client: TelegramClient,

View file

@ -11,7 +11,7 @@ import type { UpdateContext } from './base.js'
export class ChatJoinRequestUpdateContext export class ChatJoinRequestUpdateContext
extends BotChatJoinRequestUpdate extends BotChatJoinRequestUpdate
implements UpdateContext<BotChatJoinRequestUpdate> { implements UpdateContext<BotChatJoinRequestUpdate> {
readonly _name = 'bot_chat_join_request' readonly _name = 'bot_chat_join_request' as const
constructor( constructor(
readonly client: TelegramClient, readonly client: TelegramClient,

View file

@ -12,7 +12,7 @@ import type { UpdateContext } from './base.js'
* > Inline feedback in [@BotFather](//t.me/botfather) * > Inline feedback in [@BotFather](//t.me/botfather)
*/ */
export class ChosenInlineResultContext extends ChosenInlineResult implements UpdateContext<ChosenInlineResult> { export class ChosenInlineResultContext extends ChosenInlineResult implements UpdateContext<ChosenInlineResult> {
readonly _name = 'chosen_inline_result' readonly _name = 'chosen_inline_result' as const
constructor( constructor(
readonly client: TelegramClient, readonly client: TelegramClient,

View file

@ -10,7 +10,7 @@ import type { UpdateContext } from './base.js'
* This is a subclass of {@link InlineQuery}, so all its fields are also available. * This is a subclass of {@link InlineQuery}, so all its fields are also available.
*/ */
export class InlineQueryContext extends InlineQuery implements UpdateContext<InlineQuery> { export class InlineQueryContext extends InlineQuery implements UpdateContext<InlineQuery> {
readonly _name = 'inline_query' readonly _name = 'inline_query' as const
constructor( constructor(
readonly client: TelegramClient, readonly client: TelegramClient,

View file

@ -21,7 +21,7 @@ import type { UpdateContext } from './base.js'
*/ */
export class MessageContext extends Message implements UpdateContext<Message> { export class MessageContext extends Message implements UpdateContext<Message> {
// this is primarily for proper types in filters, so don't bother much with actual value // 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. * List of messages in the message group.

View file

@ -9,7 +9,7 @@ import type { UpdateContext } from './base.js'
* This is a subclass of {@link PreCheckoutQuery}, so all its fields are also available. * This is a subclass of {@link PreCheckoutQuery}, so all its fields are also available.
*/ */
export class PreCheckoutQueryContext extends PreCheckoutQuery implements UpdateContext<PreCheckoutQuery> { export class PreCheckoutQueryContext extends PreCheckoutQuery implements UpdateContext<PreCheckoutQuery> {
readonly _name = 'pre_checkout_query' readonly _name = 'pre_checkout_query' as const
constructor( constructor(
readonly client: TelegramClient, readonly client: TelegramClient,

View file

@ -9,7 +9,7 @@ import { join } from 'node:path'
import * as readline from 'node:readline' import * as readline from 'node:readline'
import * as cheerio from 'cheerio' import * as cheerio from 'cheerio'
import { hasPresentKey, isPresent } from '@mtcute/core/utils.js' import { isPresent } from '@mtcute/core/utils.js'
import type { import type {
TlEntry, TlEntry,
TlFullSchema, TlFullSchema,
@ -299,17 +299,17 @@ async function main() {
} }
} }
const nonEmptyOptions = chooseOptions.filter(hasPresentKey('entry')) const nonEmptyOptions = chooseOptions.filter(it => it.entry !== undefined)
console.log( console.log(
'Conflict detected (%s) at %s %s:', 'Conflict detected (%s) at %s %s:',
mergeError, mergeError,
nonEmptyOptions[0].entry.kind, nonEmptyOptions[0].entry!.kind,
nonEmptyOptions[0].entry.name, nonEmptyOptions[0].entry!.name,
) )
console.log('0. Remove') console.log('0. Remove')
nonEmptyOptions.forEach((opt, idx) => { 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) { while (true) {

View file

@ -5,7 +5,6 @@ import * as path from 'node:path'
import * as glob from 'glob' import * as glob from 'glob'
import ts from 'typescript' import ts from 'typescript'
import * as stc from '@teidesu/slow-types-compiler'
const __dirname = path.dirname(new URL(import.meta.url).pathname) 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 { } else {
// make shims for esnext resolution (that doesn't respect package.json `exports` field) // make shims for esnext resolution (that doesn't respect package.json `exports` field)
function makeShim(name, target) { function makeShim(name, target) {