Skip to content

Commit

Permalink
refactor: better structure classes
Browse files Browse the repository at this point in the history
  • Loading branch information
zSoulweaver committed Aug 1, 2024
1 parent b324a70 commit b0e829c
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 54 deletions.
8 changes: 3 additions & 5 deletions example/get-channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import { inspect } from 'bun'

const kient = new Kient()
const res = await kient.api.channel.get('channel_01GFZ7V9JR2H2AM2B3ZP7EDVKF')
console.log(
inspect(res.channel.raw(), {
colors: true,
}),
)

console.log(res.channel.toJSON())
console.log(res.user.toJSON())
1 change: 0 additions & 1 deletion example/get-clips.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ import { inspect } from 'bun'
const kient = new Kient()
const res = await kient.api.channel.clips('channel_01GFZ7V9JR2H2AM2B3ZP7EDVKF')

console.log(res[0].title)
console.log(res[0].toJSON())
2 changes: 1 addition & 1 deletion src/api/api-base.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Kient } from '../kient'

export class APIBase {
readonly kient: Kient
protected readonly kient: Kient

constructor(kient: Kient) {
this.kient = kient
Expand Down
29 changes: 0 additions & 29 deletions src/structures/base.ts

This file was deleted.

24 changes: 17 additions & 7 deletions src/structures/channel.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
import { Base, Expose } from './base'
// biome-ignore lint/style/useImportType: deepkit/type
import { serialize, Group } from '@deepkit/type'
import type { Kient } from '../kient'

export class Channel extends Base {
@Expose id!: string
@Expose slug!: string
@Expose banner_picture!: string
@Expose description?: string
@Expose followers_count?: number
export class Channel {
constructor(
public kient: Kient & Group<'exclude'>,

public id: string,
public slug: string,
public banner_picture: string,
public description: string,
public followers_count: number,
) {}

toJSON() {
return serialize<Channel>(this, { groupsExclude: ['exclude'] })
}
}
16 changes: 13 additions & 3 deletions src/structures/chatroom.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import { Expose } from './base'
// biome-ignore lint/style/useImportType: deepkit/type
import { serialize, Group } from '@deepkit/type'
import type { Kient } from '../kient'

export class Chatroom {
@Expose id!: string
@Expose channel_id!: string
constructor(
public kient: Kient & Group<'exclude'>,

public id: string,
public channel_id: string,
) {}

toJSON() {
return serialize<Chatroom>(this, { groupsExclude: ['exclude'] })
}
}
12 changes: 11 additions & 1 deletion src/structures/panel.ts
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
export class Panel {}
// biome-ignore lint/style/useImportType: deepkit/type
import { serialize, Group } from '@deepkit/type'
import type { Kient } from '../kient'

export class Panel {
constructor(public kient: Kient & Group<'exclude'>) {}

toJSON() {
return serialize<Panel>(this, { groupsExclude: ['exclude'] })
}
}
12 changes: 11 additions & 1 deletion src/structures/social.ts
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
export class Social {}
// biome-ignore lint/style/useImportType: deepkit/type
import { serialize, Group } from '@deepkit/type'
import type { Kient } from '../kient'

export class Social {
constructor(public kient: Kient & Group<'exclude'>) {}

toJSON() {
return serialize<Social>(this, { groupsExclude: ['exclude'] })
}
}
22 changes: 16 additions & 6 deletions src/structures/user.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
import { Base, Expose } from './base'
// biome-ignore lint/style/useImportType: deepkit/type
import { serialize, Group } from '@deepkit/type'
import type { Kient } from '../kient'

export class User extends Base {
@Expose id!: string
@Expose username!: string
@Expose is_verified!: boolean
@Expose profile_picture!: string
export class User {
constructor(
public kient: Kient & Group<'exclude'>,

public id: string,
public username: string,
public is_verified: boolean,
public profile_picture: string,
) {}

toJSON() {
return serialize<User>(this, { groupsExclude: ['exclude'] })
}
}

0 comments on commit b0e829c

Please sign in to comment.