Skip to content

Commit

Permalink
Merge pull request #46 from h3poteto/type
Browse files Browse the repository at this point in the history
Use type instead of interface for entities
  • Loading branch information
h3poteto authored May 30, 2019
2 parents e954bcc + 60dd098 commit ede7964
Show file tree
Hide file tree
Showing 33 changed files with 172 additions and 153 deletions.
7 changes: 7 additions & 0 deletions example/typescript/instance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Mastodon, { Instance } from 'megalodon'

const BASE_URL: string = 'http://mstdn.jp'

Mastodon.get<Instance>('/api/v1/instance', {}, BASE_URL).then(res => {
console.log(res)
})
6 changes: 3 additions & 3 deletions src/entities/account.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Emoji from './emoji'
import Source from './source'
import { Emoji } from './emoji'
import { Source } from './source'

export default interface Account {
export type Account = {
id: string
username: string
acct: string
Expand Down
2 changes: 1 addition & 1 deletion src/entities/application.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default interface Application {
export type Application = {
name: string
website: string | null
}
2 changes: 1 addition & 1 deletion src/entities/attachment.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default interface Attachment {
export type Attachment = {
id: string
type: 'unknown' | 'image' | 'gifv' | 'video'
url: string
Expand Down
2 changes: 1 addition & 1 deletion src/entities/card.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default interface Card {
export type Card = {
url: string
title: string
description: string
Expand Down
4 changes: 2 additions & 2 deletions src/entities/context.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Status from './status'
import { Status } from './status'

export default interface Context {
export type Context = {
ancestors: Array<Status>
descendants: Array<Status>
}
6 changes: 3 additions & 3 deletions src/entities/conversation.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Account from './account'
import Status from './status'
import { Account } from './account'
import { Status } from './status'

export default interface Conversation {
export type Conversation = {
id: string
accounts: Array<Account>
last_status: Status | null
Expand Down
2 changes: 1 addition & 1 deletion src/entities/emoji.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default interface Emoji {
export type Emoji = {
shortcode: string
static_url: string
url: string
Expand Down
2 changes: 1 addition & 1 deletion src/entities/field.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default interface Field {
export type Field = {
name: string
value: string
verified_at: string | null
Expand Down
2 changes: 1 addition & 1 deletion src/entities/filter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default interface Filter {
export type Filter = {
id: string
phrase: string
context: Array<string>
Expand Down
2 changes: 1 addition & 1 deletion src/entities/history.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default interface History {
export type History = {
day: string
uses: number
accounts: number
Expand Down
8 changes: 4 additions & 4 deletions src/entities/instance.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Account from './account'
import URLs from './urls'
import Stats from './stats'
import { Account } from './account'
import { URLs } from './urls'
import { Stats } from './stats'

export default interface Instance {
export type Instance = {
uri: string
title: string
description: string
Expand Down
2 changes: 1 addition & 1 deletion src/entities/list.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default interface List {
export type List = {
id: string
title: string
}
2 changes: 1 addition & 1 deletion src/entities/mention.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default interface Mention {
export type Mention = {
id: string
username: string
url: string
Expand Down
6 changes: 3 additions & 3 deletions src/entities/notification.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Account from './account'
import Status from './status'
import { Account } from './account'
import { Status } from './status'

export default interface Notification {
export type Notification = {
account: Account
created_at: string
id: string
Expand Down
2 changes: 1 addition & 1 deletion src/entities/push_subscription.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default interface PushSubscription {
export type PushSubscription = {
id: string
endpoint: string
server_key: string
Expand Down
2 changes: 1 addition & 1 deletion src/entities/relationship.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default interface Relationship {
export type Relationship = {
id: string
following: boolean
followed_by: boolean
Expand Down
8 changes: 4 additions & 4 deletions src/entities/results.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Account from './account'
import Status from './status'
import Tag from './tag'
import { Account } from './account'
import { Status } from './status'
import { Tag } from './tag'

export default interface Results {
export type Results = {
accounts: Array<Account>
statuses: Array<Status>
hashtags: Array<Tag>
Expand Down
4 changes: 2 additions & 2 deletions src/entities/scheduled_status.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Attachment from './attachment'
import { Attachment } from './attachment'

export default interface ScheduledStatus {
export type ScheduledStatus = {
id: string
scheduled_at: string
params: object
Expand Down
2 changes: 1 addition & 1 deletion src/entities/source.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default interface Source {
export type Source = {
privacy: string | null
sensitive: boolean | null
language: string | null
Expand Down
2 changes: 1 addition & 1 deletion src/entities/stats.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default interface Stats {
export type Stats = {
user_count: number
status_count: number
domain_count: number
Expand Down
16 changes: 8 additions & 8 deletions src/entities/status.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import Account from './account'
import Application from './application'
import Mention from './mention'
import Tag from './tag'
import Attachment from './attachment'
import Emoji from './emoji'
import Card from './card'
import { Account } from './account'
import { Application } from './application'
import { Mention } from './mention'
import { Tag } from './tag'
import { Attachment } from './attachment'
import { Emoji } from './emoji'
import { Card } from './card'

export default interface Status {
export type Status = {
id: string
uri: string
url: string
Expand Down
2 changes: 1 addition & 1 deletion src/entities/status_params.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default interface StatusParams {
export type StatusParams = {
text: string
in_reply_to_id: string | null
media_ids: Array<string> | null
Expand Down
4 changes: 2 additions & 2 deletions src/entities/tag.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import History from './history'
import { History } from './history'

export default interface Tag {
export type Tag = {
name: string
url: string
history: Array<History> | null
Expand Down
2 changes: 1 addition & 1 deletion src/entities/token.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default interface Token {
export type Token = {
access_token: string
token_type: string
scope: string
Expand Down
2 changes: 1 addition & 1 deletion src/entities/urls.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export default interface URLs {
export type URLs = {
streaming_api: string
}
50 changes: 25 additions & 25 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,31 @@ import OAuth from './oauth'
/**
* Entities
*/
import Account from './entities/account'
import Application from './entities/application'
import Attachment from './entities/attachment'
import Card from './entities/card'
import Context from './entities/context'
import Conversation from './entities/conversation'
import Emoji from './entities/emoji'
import Field from './entities/field'
import Filter from './entities/filter'
import History from './entities/history'
import Instance from './entities/instance'
import List from './entities/list'
import Mention from './entities/mention'
import Notification from './entities/notification'
import PushSubscription from './entities/push_subscription'
import Relationship from './entities/relationship'
import Results from './entities/results'
import ScheduledStatus from './entities/scheduled_status'
import Source from './entities/source'
import Stats from './entities/stats'
import Status from './entities/status'
import StatusParams from './entities/status_params'
import Tag from './entities/tag'
import Token from './entities/token'
import URLs from './entities/urls'
import { Account } from './entities/account'
import { Application } from './entities/application'
import { Attachment } from './entities/attachment'
import { Card } from './entities/card'
import { Context } from './entities/context'
import { Conversation } from './entities/conversation'
import { Emoji } from './entities/emoji'
import { Field } from './entities/field'
import { Filter } from './entities/filter'
import { History } from './entities/history'
import { Instance } from './entities/instance'
import { List } from './entities/list'
import { Mention } from './entities/mention'
import { Notification } from './entities/notification'
import { PushSubscription } from './entities/push_subscription'
import { Relationship } from './entities/relationship'
import { Results } from './entities/results'
import { ScheduledStatus } from './entities/scheduled_status'
import { Source } from './entities/source'
import { Stats } from './entities/stats'
import { Status } from './entities/status'
import { StatusParams } from './entities/status_params'
import { Tag } from './entities/tag'
import { Token } from './entities/token'
import { URLs } from './entities/urls'

export {
StreamListener,
Expand Down
Loading

0 comments on commit ede7964

Please sign in to comment.