From 2f8f6431d1ff894939485c47d42775162cee740f Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 16 May 2021 18:18:45 +0900 Subject: :v: --- src/endpoints.ts | 2 +- src/entities.ts | 123 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/index.ts | 5 +-- src/types.ts | 123 ------------------------------------------------------- test-d/api.ts | 14 +++++++ test-d/index.ts | 1 - 6 files changed, 140 insertions(+), 128 deletions(-) create mode 100644 src/entities.ts delete mode 100644 src/types.ts create mode 100644 test-d/api.ts delete mode 100644 test-d/index.ts diff --git a/src/endpoints.ts b/src/endpoints.ts index c9f89fd438..7c0fe6b836 100644 --- a/src/endpoints.ts +++ b/src/endpoints.ts @@ -1,4 +1,4 @@ -import { ID, InstanceMetadata, Note, OriginType, Page, ServerInfo, Stats, User, UserSorting } from './types'; +import { ID, InstanceMetadata, Note, OriginType, Page, ServerInfo, Stats, User, UserSorting } from './entities'; type TODO = Record; diff --git a/src/entities.ts b/src/entities.ts new file mode 100644 index 0000000000..64124f45b5 --- /dev/null +++ b/src/entities.ts @@ -0,0 +1,123 @@ +export type ID = string; + +export type User = { + id: ID; + username: string; + host: string | null; + name: string; + onlineStatus: 'online' | 'active' | 'offline' | 'unknown'; + avatarUrl: string; + avatarBlurhash: string; + emojis: { + name: string; + url: string; + }[]; +}; + +export type DriveFile = { + id: ID; + createdAt: string; + isSensitive: boolean; + name: string; + thumbnailUrl: string; + url: string; + type: string; + size: number; + md5: string; + blurhash: string; + properties: Record; +}; + +export type Note = { + id: ID; + createdAt: string; + text: string | null; + cw: string | null; + user: User; + userId: User['id']; + reply?: Note; + replyId: Note['id']; + renote?: Note; + renoteId: Note['id']; + files: DriveFile[]; + fileIds: DriveFile['id'][]; + visibility: 'public' | 'home' | 'followers' | 'specified'; + myReaction?: string; + reactions: Record; + poll?: { + expiresAt: string | null; + multiple: boolean; + choices: { + isVoted: boolean; + text: string; + votes: number; + }[]; + }; + emojis: { + name: string; + url: string; + }[]; +}; + +export type InstanceMetadata = { + emojis: { + category: string; + }[]; + ads: { + id: ID; + ratio: number; + place: string; + url: string; + imageUrl: string; + }[]; +}; + +export type ServerInfo = { + machine: string; + cpu: { + model: string; + cores: number; + }; + mem: { + total: number; + }; + fs: { + total: number; + used: number; + }; +}; + +export type Stats = { + notesCount: number; + originalNotesCount: number; + usersCount: number; + originalUsersCount: number; + instances: number; + driveUsageLocal: number; + driveUsageRemote: number; +}; + +export type Page = { + id: ID; + createdAt: Date; + updatedAt: Date; + userId: User['id']; + user: User; + content: Record[]; + variables: Record[]; + title: string; + name: string; + summary: string | null; + hideTitleWhenPinned: boolean; + alignCenter: boolean; + font: string; + script: string; + eyeCatchingImageId: DriveFile['id'] | null; + eyeCatchingImage: DriveFile | null; + attachedFiles: any; + likedCount: number; + isLiked?: boolean; +}; + +export type UserSorting = '+follower' | '-follower' | '+createdAt' | '-createdAt' | '+updatedAt' | '-updatedAt'; +export type OriginType = 'combined' | 'local' | 'remote'; diff --git a/src/index.ts b/src/index.ts index 399f8ff1dc..b5f5a5629c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,13 +1,12 @@ -import { APIClient } from './api'; import { Endpoints } from './endpoints'; import Stream from './streaming'; import { Acct } from './acct'; export { - APIClient, Endpoints, Stream, Acct }; -export * as entities from './types'; +export * as api from './api'; +export * as entities from './entities'; diff --git a/src/types.ts b/src/types.ts deleted file mode 100644 index 64124f45b5..0000000000 --- a/src/types.ts +++ /dev/null @@ -1,123 +0,0 @@ -export type ID = string; - -export type User = { - id: ID; - username: string; - host: string | null; - name: string; - onlineStatus: 'online' | 'active' | 'offline' | 'unknown'; - avatarUrl: string; - avatarBlurhash: string; - emojis: { - name: string; - url: string; - }[]; -}; - -export type DriveFile = { - id: ID; - createdAt: string; - isSensitive: boolean; - name: string; - thumbnailUrl: string; - url: string; - type: string; - size: number; - md5: string; - blurhash: string; - properties: Record; -}; - -export type Note = { - id: ID; - createdAt: string; - text: string | null; - cw: string | null; - user: User; - userId: User['id']; - reply?: Note; - replyId: Note['id']; - renote?: Note; - renoteId: Note['id']; - files: DriveFile[]; - fileIds: DriveFile['id'][]; - visibility: 'public' | 'home' | 'followers' | 'specified'; - myReaction?: string; - reactions: Record; - poll?: { - expiresAt: string | null; - multiple: boolean; - choices: { - isVoted: boolean; - text: string; - votes: number; - }[]; - }; - emojis: { - name: string; - url: string; - }[]; -}; - -export type InstanceMetadata = { - emojis: { - category: string; - }[]; - ads: { - id: ID; - ratio: number; - place: string; - url: string; - imageUrl: string; - }[]; -}; - -export type ServerInfo = { - machine: string; - cpu: { - model: string; - cores: number; - }; - mem: { - total: number; - }; - fs: { - total: number; - used: number; - }; -}; - -export type Stats = { - notesCount: number; - originalNotesCount: number; - usersCount: number; - originalUsersCount: number; - instances: number; - driveUsageLocal: number; - driveUsageRemote: number; -}; - -export type Page = { - id: ID; - createdAt: Date; - updatedAt: Date; - userId: User['id']; - user: User; - content: Record[]; - variables: Record[]; - title: string; - name: string; - summary: string | null; - hideTitleWhenPinned: boolean; - alignCenter: boolean; - font: string; - script: string; - eyeCatchingImageId: DriveFile['id'] | null; - eyeCatchingImage: DriveFile | null; - attachedFiles: any; - likedCount: number; - isLiked?: boolean; -}; - -export type UserSorting = '+follower' | '-follower' | '+createdAt' | '-createdAt' | '+updatedAt' | '-updatedAt'; -export type OriginType = 'combined' | 'local' | 'remote'; diff --git a/test-d/api.ts b/test-d/api.ts new file mode 100644 index 0000000000..32357c2a3b --- /dev/null +++ b/test-d/api.ts @@ -0,0 +1,14 @@ +/** + * Unit testing TypeScript types. + * with https://github.com/SamVerschueren/tsd + */ + +import { expectType } from 'tsd'; +import * as Misskey from '../src'; + +describe('API', () => { + test('returns node that has sprcified type', async () => { + const res = await Misskey.api.request('https://misskey.test', 'meta', { detail: true }, 'TOKEN'); + expectType(res); + }); +}); diff --git a/test-d/index.ts b/test-d/index.ts deleted file mode 100644 index e6fafcc4ff..0000000000 --- a/test-d/index.ts +++ /dev/null @@ -1 +0,0 @@ -// RESERVED -- cgit v1.2.3-freya