Skip to content

Commit

Permalink
nothing major, just qol
Browse files Browse the repository at this point in the history
- ci script now runs before publish
- src now included in build
- made some edits upon reading typescript performance wiki.
- implemented RawTimelineResponse type.
- TimelineUser class properties now `readonly`
- vite.config.ts renamed to vitest.config.ts (more appropriate since we aren't using Vite)
  • Loading branch information
Owen3H committed Sep 19, 2023
1 parent f798145 commit e9aba39
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 33 deletions.
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
"default": "./dist/index.cjs"
},
"scripts": {
"prepublishOnly": "pnpm run ci",
"test-dist": "node src/tests/test.js",
"test": "vitest run --config ./vite.config.ts",
"test": "vitest run --config vitest.config.ts",
"coverage": "vitest run --coverage",
"clean": "npx rimraf dist",
"build": "pnpm run clean && npx rollup -c && tsc --declaration true --emitDeclarationOnly",
"build": "pnpm run clean && npx rollup -c && pnpm run dts",
"dts": "tsc --declaration true --emitDeclarationOnly true --declarationMap true",
"lint": "eslint .",
"ci": "pnpm run lint && pnpm run test && pnpm run build"
},
Expand Down Expand Up @@ -68,6 +70,7 @@
"vitest": "^0.34.1"
},
"files": [
"src",
"dist",
"LICENSE",
"README.md",
Expand Down
45 changes: 23 additions & 22 deletions src/classes/timeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import User from "./user.js"
import {
PuppeteerConfig,
RawTimelineEntry,
RawTimelineResponse,
RawTimelineTweet, RawTimelineUser,
TweetOptions, UserEntities
} from "../types.js"
Expand Down Expand Up @@ -85,7 +86,7 @@ export default class Timeline {
const data = extractTimelineData(html)
if (!data) throw new ParseError('Script tag not found or JSON data missing.')

const timeline = JSON.parse(data)
const timeline = JSON.parse(data) as RawTimelineResponse
return timeline?.props?.pageProps?.timeline?.entries
}

Expand Down Expand Up @@ -185,27 +186,27 @@ class TimelineTweet {
}

class TimelineUser extends User {
blocking: boolean
createdAt: string
defaultProfile: boolean
defaultProfileImage: boolean
description: string
entities: UserEntities
followersCount: number
friendsCount: number
statusesCount: number
likesCount: number
mediaCount: number
location: string
protected: boolean
url: string
time_zone: string
listedCount: number
utc_offset: number
notifications: boolean
following: boolean
followedBy: boolean
followRequestSent: boolean
readonly blocking: boolean
readonly createdAt: string
readonly defaultProfile: boolean
readonly defaultProfileImage: boolean
readonly description: string
readonly entities: UserEntities
readonly followersCount: number
readonly friendsCount: number
readonly statusesCount: number
readonly likesCount: number
readonly mediaCount: number
readonly location: string
readonly protected: boolean
readonly url: string
readonly time_zone: string
readonly listedCount: number
readonly utc_offset: number
readonly notifications: boolean
readonly following: boolean
readonly followedBy: boolean
readonly followRequestSent: boolean

constructor(data: RawTimelineUser) {
super(data)
Expand Down
20 changes: 15 additions & 5 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type DeepInfer<T> = {
}

type LaunchOptions = DeepInfer<PuppeteerLaunchOptions>
export type PuppeteerConfig = LaunchOptions & {
export interface PuppeteerConfig extends LaunchOptions {
browser?: Browser
page?: Page
autoClose?: boolean
Expand All @@ -37,12 +37,12 @@ export type BaseUser = {
id_str: string
}

export type UserMention = BaseUser & {
export interface UserMention extends BaseUser {
id?: number
indices: number[]
}

export type RawTimelineUser = BaseUser & {
export interface RawTimelineUser extends BaseUser {
blocking: boolean
created_at: string
default_profile: boolean
Expand Down Expand Up @@ -85,7 +85,7 @@ export type TweetEntities = {
user_mentions: UserMention[]
}

export type TweetMedia = UrlEntity & {
export interface TweetMedia extends UrlEntity {
features: DynamicProps<[]>
id_str: string
media_url?: string
Expand Down Expand Up @@ -122,6 +122,16 @@ export type MediaSize = {
resize: string
}

export type RawTimelineResponse = {
props: {
pageProps: {
timeline: {
entries: RawTimelineEntry[]
}
}
}
}

export type RawTimelineEntry = {
type: string
entry_id: string
Expand Down Expand Up @@ -160,7 +170,7 @@ export type RawTweet = {
user: RawUser
}

export type RawUser = BaseUser & {
export interface RawUser extends BaseUser {
is_blue_verified: boolean
profile_image_url_https: string
verified: boolean
Expand Down
15 changes: 11 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,26 @@
"module": "NodeNext",
"target": "ES2017",
"moduleResolution": "NodeNext",
"outDir": "dist",
"types": ["node"],
"skipDefaultLibCheck": true,
"skipLibCheck": true,
"importHelpers": true,
"allowJs": true,
"esModuleInterop": true,
"noEmitOnError": true,
"strictFunctionTypes": true,
"baseUrl": ".",
"paths": {
"tslib" : ["node_modules/tslib/tslib.d.ts"]
},
"types": ["node"],
"outDir": "dist"
}
},
"include": ["src"],
"exclude": ["node_modules", "dist", "src/tests"]
"exclude": [
"node_modules",
"dist",
"src/tests",
"vitest.config.ts",
"rollup.config.mjs"
]
}
File renamed without changes.

0 comments on commit e9aba39

Please sign in to comment.