diff --git a/packages/misskey-js/jest.config.cjs b/packages/megalodon/jest.config.ts similarity index 83% rename from packages/misskey-js/jest.config.cjs rename to packages/megalodon/jest.config.ts index 1230a4b5e2..1aaa88a347 100644 --- a/packages/misskey-js/jest.config.cjs +++ b/packages/megalodon/jest.config.ts @@ -3,7 +3,16 @@ * https://jestjs.io/docs/en/configuration.html */ -module.exports = { +// https://kulshekhar.github.io/ts-jest/docs/getting-started/presets#createdefaultesmpresetoptions +import { createDefaultEsmPreset, type JestConfigWithTsJest } from 'ts-jest'; + +const presetConfig = createDefaultEsmPreset({ + tsconfig: '/tsconfig.json' +}); + +export default { + ...presetConfig, + // All imported modules in your tests should be mocked automatically // automock: false, @@ -20,7 +29,7 @@ module.exports = { // collectCoverage: false, // An array of glob patterns indicating a set of files for which coverage information should be collected - // collectCoverageFrom: undefined, + collectCoverageFrom: ['src/**/*.ts'], // The directory where Jest should output its coverage files coverageDirectory: "coverage", @@ -60,7 +69,8 @@ module.exports = { // globalTeardown: undefined, // A set of global variables that need to be available in all test environments - // globals: {}, + // globals: { + // }, // The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers. // maxWorkers: "50%", @@ -79,6 +89,10 @@ module.exports = { // "tsx", // "node" // ], + moduleFileExtensions: [ + "ts", + "js" + ], // A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module moduleNameMapper: { @@ -103,7 +117,8 @@ module.exports = { // notifyMode: "failure-change", // A preset that is used as a base for Jest's configuration - // preset: undefined, + //preset: "ts-jest/presets/js-with-ts-esm", + // "preset": "ts-jest/presets/default", // Run tests from one or more projects // projects: undefined, @@ -118,17 +133,17 @@ module.exports = { // resetModules: false, // A path to a custom resolver - // resolver: undefined, + // resolver: './jest-resolver.cjs', // Automatically restore mock state between every test - // restoreMocks: false, + restoreMocks: true, // The root directory that Jest should scan for tests and modules within // rootDir: undefined, // A list of paths to directories that Jest should use to search for files in roots: [ - "" + "/test" ], // Allows you to use a custom runner instead of Jest's default test runner @@ -157,9 +172,7 @@ module.exports = { // The glob patterns Jest uses to detect test files testMatch: [ - "**/__tests__/**/*.[jt]s?(x)", - "**/?(*.)+(spec|test).[tj]s?(x)", - "/test/**/*" + "/test/**/*.spec.ts" ], // An array of regexp pattern strings that are matched against all test paths, matched tests are skipped @@ -183,9 +196,14 @@ module.exports = { // timers: "real", // A map from regular expressions to paths to transformers - transform: { - "^.+\\.(t|j)sx?$": ["@swc/jest"], - }, + // transform: { + // "^.+\\.(ts|tsx)$": [ + // "ts-jest", + // { + // "tsconfig": "tsconfig.json" + // } + // ] + // }, // An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation // transformIgnorePatterns: [ @@ -204,4 +222,17 @@ module.exports = { // Whether to use watchman for file crawling // watchman: true, -}; + + // extensionsToTreatAsEsm: ['.ts'], + + // testTimeout: 60000, + + // // Let Jest kill the test worker whenever it grows too much + // // (It seems there's a known memory leak issue in Node.js' vm.Script used by Jest) + // // https://github.com/facebook/jest/issues/11956 + // maxWorkers: 1, // Make it use worker (that can be killed and restarted) + // logHeapUsage: true, // To debug when out-of-memory happens on CI + // workerIdleMemoryLimit: '1GiB', // Limit the worker to 1GB (GitHub Workflows dies at 2GB) + // + // maxConcurrency: 32, +} satisfies JestConfigWithTsJest; diff --git a/packages/megalodon/package.json b/packages/megalodon/package.json index 71ebaebff5..7fc07a09f7 100644 --- a/packages/megalodon/package.json +++ b/packages/megalodon/package.json @@ -1,12 +1,17 @@ { "name": "megalodon", + "type": "module", "version": "7.0.1", + "private": true, "description": "Mastodon API client for node.js and browser", "main": "./lib/src/index.js", "typings": "./lib/src/index.d.ts", "scripts": { - "build": "tsc -p ./", - "test": "cross-env NODE_ENV=test jest -u --maxWorkers=3" + "build": "tsc -p tsconfig.json", + "typecheck": "tsc -p tsconfig.json --noEmit", + "lint": "pnpm run typecheck", + "jest": "cross-env NODE_ENV=test node --no-experimental-require-module --experimental-vm-modules --experimental-import-meta-resolve node_modules/jest/bin/jest.js --coverage --detectOpenHandles", + "test": "pnpm run jest" }, "engines": { "node": "^22.0.0" @@ -28,42 +33,23 @@ "bugs": { "url": "https://github.com/h3poteto/megalodon/issues" }, - "jest": { - "moduleFileExtensions": [ - "ts", - "js" - ], - "moduleNameMapper": { - "^@/(.+)": "/src/$1", - "^~/(.+)": "/$1" - }, - "testMatch": [ - "**/test/**/*.spec.ts" - ], - "preset": "ts-jest/presets/default", - "transform": { - "^.+\\.(ts|tsx)$": [ - "ts-jest", - { - "tsconfig": "tsconfig.json" - } - ] - }, - "testEnvironment": "node" - }, "homepage": "https://github.com/h3poteto/megalodon#readme", "dependencies": { "axios": "1.12.2", "dayjs": "1.11.18", "form-data": "4.0.4", - "oauth": "0.10.2", - "typescript": "5.9.2" + "oauth": "0.10.2" }, "devDependencies": { + "@jest/globals": "30.1.2", "@types/jest": "30.0.0", + "@types/node": "22.18.1", "@types/oauth": "0.9.6", "jest": "30.1.3", + "jest-mock": "30.0.5", "jest-worker": "30.1.0", - "ts-jest": "29.4.4" + "ts-jest": "29.4.4", + "ts-node": "10.9.2", + "typescript": "5.9.2" } } diff --git a/packages/megalodon/src/converter.ts b/packages/megalodon/src/converter.ts index f768fc9304..d51c56e049 100644 --- a/packages/megalodon/src/converter.ts +++ b/packages/megalodon/src/converter.ts @@ -1,3 +1,3 @@ -import MisskeyAPI from "./misskey/api_client"; +import * as MisskeyAPI from "./misskey/api_client.js"; -export default MisskeyAPI.Converter; \ No newline at end of file +export default MisskeyAPI.Converter; diff --git a/packages/megalodon/src/detector.ts b/packages/megalodon/src/detector.ts index ba95d96816..43f8dbe66d 100644 --- a/packages/megalodon/src/detector.ts +++ b/packages/megalodon/src/detector.ts @@ -1,5 +1,5 @@ -import axios, { AxiosRequestConfig } from 'axios' -import { NodeinfoError } from './megalodon' +import axios, { type AxiosRequestConfig } from 'axios' +import { NodeinfoError } from './megalodon.js' const NODEINFO_10 = 'http://nodeinfo.diaspora.software/ns/schema/1.0' const NODEINFO_20 = 'http://nodeinfo.diaspora.software/ns/schema/2.0' diff --git a/packages/megalodon/src/entities/account.ts b/packages/megalodon/src/entities/account.ts index e2219dd041..58996193f1 100644 --- a/packages/megalodon/src/entities/account.ts +++ b/packages/megalodon/src/entities/account.ts @@ -1,36 +1,35 @@ -/// -/// -/// -/// -namespace Entity { - export type Account = { - id: string - fqn?: string - username: string - acct: string - display_name: string - locked: boolean - discoverable?: boolean - group?: boolean | null - noindex?: boolean | null - suspended?: boolean | null - limited?: boolean | null - created_at: string - followers_count: number - following_count: number - statuses_count: number - note: string - url: string - avatar: string - avatar_static: string - header: string - header_static: string - emojis: Array - moved: Account | null - fields: Array - bot: boolean | null - source?: Source - role?: Role - mute_expires_at?: string - } +import type { Emoji } from './emoji.js'; +import type { Field } from './field.js'; +import type { Source } from './source.js'; +import type { Role } from './role.js'; + +export interface Account { + id: string + fqn?: string + username: string + acct: string + display_name: string + locked: boolean + discoverable?: boolean + group?: boolean | null + noindex?: boolean | null + suspended?: boolean | null + limited?: boolean | null + created_at: string + followers_count: number + following_count: number + statuses_count: number + note: string + url: string + avatar: string + avatar_static: string + header: string + header_static: string + emojis: Array + moved: Account | null + fields: Array + bot: boolean | null + source?: Source + role?: Role + mute_expires_at?: string } diff --git a/packages/megalodon/src/entities/activity.ts b/packages/megalodon/src/entities/activity.ts index 2494916a92..b646622f6f 100644 --- a/packages/megalodon/src/entities/activity.ts +++ b/packages/megalodon/src/entities/activity.ts @@ -1,8 +1,6 @@ -namespace Entity { - export type Activity = { - week: string - statuses: string - logins: string - registrations: string - } +export interface Activity { + week: string + statuses: string + logins: string + registrations: string } diff --git a/packages/megalodon/src/entities/announcement.ts b/packages/megalodon/src/entities/announcement.ts index 0db9c23bbe..898963d9dc 100644 --- a/packages/megalodon/src/entities/announcement.ts +++ b/packages/megalodon/src/entities/announcement.ts @@ -1,40 +1,39 @@ -/// +import type { StatusTag } from './status.js'; +import type { Emoji } from './emoji.js'; -namespace Entity { - export type Announcement = { - id: string - content: string - starts_at: string | null - ends_at: string | null - published: boolean - all_day: boolean - published_at: string - updated_at: string | null - read: boolean | null - mentions: Array - statuses: Array - tags: Array - emojis: Array - reactions: Array - } - - export type AnnouncementAccount = { - id: string - username: string - url: string - acct: string - } - - export type AnnouncementStatus = { - id: string - url: string - } - - export type AnnouncementReaction = { - name: string - count: number - me: boolean | null - url: string | null - static_url: string | null - } +export interface Announcement { + id: string + content: string + starts_at: string | null + ends_at: string | null + published: boolean + all_day: boolean + published_at: string + updated_at: string | null + read: boolean | null + mentions: Array + statuses: Array + tags: Array + emojis: Array + reactions: Array +} + +export interface AnnouncementAccount { + id: string + username: string + url: string + acct: string +} + +export interface AnnouncementStatus { + id: string + url: string +} + +export interface AnnouncementReaction { + name: string + count: number + me: boolean | null + url: string | null + static_url: string | null } diff --git a/packages/megalodon/src/entities/application.ts b/packages/megalodon/src/entities/application.ts index 3af64fcf96..3cca04cf75 100644 --- a/packages/megalodon/src/entities/application.ts +++ b/packages/megalodon/src/entities/application.ts @@ -1,7 +1,5 @@ -namespace Entity { - export type Application = { - name: string - website?: string | null - vapid_key?: string | null - } +export interface Application { + name: string + website?: string | null + vapid_key?: string | null } diff --git a/packages/megalodon/src/entities/async_attachment.ts b/packages/megalodon/src/entities/async_attachment.ts index b383f90c58..0433656bb2 100644 --- a/packages/megalodon/src/entities/async_attachment.ts +++ b/packages/megalodon/src/entities/async_attachment.ts @@ -1,14 +1,13 @@ -/// -namespace Entity { - export type AsyncAttachment = { - id: string - type: 'unknown' | 'image' | 'gifv' | 'video' | 'audio' - url: string | null - remote_url: string | null - preview_url: string - text_url: string | null - meta: Meta | null - description: string | null - blurhash: string | null - } +import type { Meta } from './attachment.js'; + +export interface AsyncAttachment { + id: string + type: 'unknown' | 'image' | 'gifv' | 'video' | 'audio' + url: string | null + remote_url: string | null + preview_url: string + text_url: string | null + meta: Meta | null + description: string | null + blurhash: string | null } diff --git a/packages/megalodon/src/entities/attachment.ts b/packages/megalodon/src/entities/attachment.ts index aab1deadea..7522a293ef 100644 --- a/packages/megalodon/src/entities/attachment.ts +++ b/packages/megalodon/src/entities/attachment.ts @@ -1,49 +1,47 @@ -namespace Entity { - export type Sub = { - // For Image, Gifv, and Video - width?: number - height?: number - size?: string - aspect?: number +export type Sub = { + // For Image, Gifv, and Video + width?: number + height?: number + size?: string + aspect?: number - // For Gifv and Video - frame_rate?: string + // For Gifv and Video + frame_rate?: string - // For Audio, Gifv, and Video - duration?: number - bitrate?: number - } - - export type Focus = { - x: number - y: number - } - - export type Meta = { - original?: Sub - small?: Sub - focus?: Focus - length?: string - duration?: number - fps?: number - size?: string - width?: number - height?: number - aspect?: number - audio_encode?: string - audio_bitrate?: string - audio_channel?: string - } - - export type Attachment = { - id: string - type: 'unknown' | 'image' | 'gifv' | 'video' | 'audio' - url: string - remote_url: string | null - preview_url: string | null - text_url: string | null - meta: Meta | null - description: string | null - blurhash: string | null - } + // For Audio, Gifv, and Video + duration?: number + bitrate?: number +} + +export interface Focus { + x: number + y: number +} + +export interface Meta { + original?: Sub + small?: Sub + focus?: Focus + length?: string + duration?: number + fps?: number + size?: string + width?: number + height?: number + aspect?: number + audio_encode?: string + audio_bitrate?: string + audio_channel?: string +} + +export interface Attachment { + id: string + type: 'unknown' | 'image' | 'gifv' | 'video' | 'audio' + url: string + remote_url: string | null + preview_url: string | null + text_url: string | null + meta: Meta | null + description: string | null + blurhash: string | null } diff --git a/packages/megalodon/src/entities/card.ts b/packages/megalodon/src/entities/card.ts index 1ef6f5e4d6..9db55b9246 100644 --- a/packages/megalodon/src/entities/card.ts +++ b/packages/megalodon/src/entities/card.ts @@ -1,18 +1,16 @@ -namespace Entity { - export type Card = { - url: string - title: string - description: string - type: 'link' | 'photo' | 'video' | 'rich' - image: string | null - author_name: string | null - author_url: string | null - provider_name: string | null - provider_url: string | null - html: string | null - width: number | null - height: number | null - embed_url: string | null - blurhash: string | null - } +export interface Card { + url: string + title: string + description: string + type: 'link' | 'photo' | 'video' | 'rich' + image: string | null + author_name: string | null + author_url: string | null + provider_name: string | null + provider_url: string | null + html: string | null + width: number | null + height: number | null + embed_url: string | null + blurhash: string | null } diff --git a/packages/megalodon/src/entities/context.ts b/packages/megalodon/src/entities/context.ts index 3f2eda58f7..a80e334e31 100644 --- a/packages/megalodon/src/entities/context.ts +++ b/packages/megalodon/src/entities/context.ts @@ -1,8 +1,6 @@ -/// +import type { Status } from './status.js'; -namespace Entity { - export type Context = { - ancestors: Array - descendants: Array - } +export interface Context { + ancestors: Array + descendants: Array } diff --git a/packages/megalodon/src/entities/conversation.ts b/packages/megalodon/src/entities/conversation.ts index cdadf1e0f2..d67e3f4b98 100644 --- a/packages/megalodon/src/entities/conversation.ts +++ b/packages/megalodon/src/entities/conversation.ts @@ -1,11 +1,9 @@ -/// -/// +import type { Account } from './account.js'; +import type { Status } from './status.js'; -namespace Entity { - export type Conversation = { - id: string - accounts: Array - last_status: Status | null - unread: boolean - } +export interface Conversation { + id: string + accounts: Array + last_status: Status | null + unread: boolean } diff --git a/packages/megalodon/src/entities/emoji.ts b/packages/megalodon/src/entities/emoji.ts index 546ef818f9..f617167aea 100644 --- a/packages/megalodon/src/entities/emoji.ts +++ b/packages/megalodon/src/entities/emoji.ts @@ -1,9 +1,7 @@ -namespace Entity { - export type Emoji = { - shortcode: string - static_url: string - url: string - visible_in_picker: boolean - category?: string - } +export interface Emoji { + shortcode: string + static_url: string + url: string + visible_in_picker: boolean + category?: string } diff --git a/packages/megalodon/src/entities/featured_tag.ts b/packages/megalodon/src/entities/featured_tag.ts index 06ae6d7a9d..3e7bcb155e 100644 --- a/packages/megalodon/src/entities/featured_tag.ts +++ b/packages/megalodon/src/entities/featured_tag.ts @@ -1,8 +1,6 @@ -namespace Entity { - export type FeaturedTag = { - id: string - name: string - statuses_count: number - last_status_at: string - } +export interface FeaturedTag { + id: string + name: string + statuses_count: number + last_status_at: string } diff --git a/packages/megalodon/src/entities/field.ts b/packages/megalodon/src/entities/field.ts index 71ce3c0cfa..5d635133b1 100644 --- a/packages/megalodon/src/entities/field.ts +++ b/packages/megalodon/src/entities/field.ts @@ -1,7 +1,5 @@ -namespace Entity { - export type Field = { - name: string - value: string - verified_at?: string | null - } +export interface Field { + name: string + value: string + verified_at?: string | null } diff --git a/packages/megalodon/src/entities/filter.ts b/packages/megalodon/src/entities/filter.ts index ffbacb7287..0e064fe134 100644 --- a/packages/megalodon/src/entities/filter.ts +++ b/packages/megalodon/src/entities/filter.ts @@ -1,12 +1,10 @@ -namespace Entity { - export type Filter = { - id: string - phrase: string - context: Array - expires_at: string | null - irreversible: boolean - whole_word: boolean - } - - export type FilterContext = string +export interface Filter { + id: string + phrase: string + context: Array + expires_at: string | null + irreversible: boolean + whole_word: boolean } + +export type FilterContext = string diff --git a/packages/megalodon/src/entities/follow_request.ts b/packages/megalodon/src/entities/follow_request.ts index 84ea4d02c8..ab1c811faa 100644 --- a/packages/megalodon/src/entities/follow_request.ts +++ b/packages/megalodon/src/entities/follow_request.ts @@ -1,27 +1,25 @@ -/// -/// +import type { Emoji } from './emoji.js'; +import type { Field } from './field.js'; -namespace Entity { - export type FollowRequest = { - id: number - username: string - acct: string - display_name: string - locked: boolean - bot: boolean - discoverable?: boolean - group: boolean - created_at: string - note: string - url: string - avatar: string - avatar_static: string - header: string - header_static: string - followers_count: number - following_count: number - statuses_count: number - emojis: Array - fields: Array - } +export interface FollowRequest { + id: number + username: string + acct: string + display_name: string + locked: boolean + bot: boolean + discoverable?: boolean + group: boolean + created_at: string + note: string + url: string + avatar: string + avatar_static: string + header: string + header_static: string + followers_count: number + following_count: number + statuses_count: number + emojis: Array + fields: Array } diff --git a/packages/megalodon/src/entities/history.ts b/packages/megalodon/src/entities/history.ts index 0709694260..3aee331a2a 100644 --- a/packages/megalodon/src/entities/history.ts +++ b/packages/megalodon/src/entities/history.ts @@ -1,7 +1,5 @@ -namespace Entity { - export type History = { - day: string - uses: number - accounts: number - } +export interface History { + day: string + uses: number + accounts: number } diff --git a/packages/megalodon/src/entities/identity_proof.ts b/packages/megalodon/src/entities/identity_proof.ts index ff857addb0..0fe00f3a73 100644 --- a/packages/megalodon/src/entities/identity_proof.ts +++ b/packages/megalodon/src/entities/identity_proof.ts @@ -1,9 +1,7 @@ -namespace Entity { - export type IdentityProof = { - provider: string - provider_username: string - updated_at: string - proof_url: string - profile_url: string - } +export interface IdentityProof { + provider: string + provider_username: string + updated_at: string + proof_url: string + profile_url: string } diff --git a/packages/megalodon/src/entities/instance.ts b/packages/megalodon/src/entities/instance.ts index 7849a94aa7..1a8b925584 100644 --- a/packages/megalodon/src/entities/instance.ts +++ b/packages/megalodon/src/entities/instance.ts @@ -1,40 +1,38 @@ -/// -/// -/// +import type { URLs } from './urls.js'; +import type { Stats } from './stats.js'; +import type { Account } from './account.js'; -namespace Entity { - export type Instance = { - uri: string - title: string - description: string - email: string - version: string - thumbnail: string | null - urls: URLs - stats: Stats - languages: Array - registrations: boolean - approval_required: boolean - invites_enabled?: boolean - configuration: { - statuses: { - max_characters: number - max_media_attachments?: number - characters_reserved_per_url?: number - } - polls?: { - max_options: number - max_characters_per_option: number - min_expiration: number - max_expiration: number - } - } - contact_account?: Account - rules?: Array - } - - export type InstanceRule = { - id: string - text: string - } +export interface Instance { + uri: string + title: string + description: string + email: string + version: string + thumbnail: string | null + urls: URLs + stats: Stats + languages: Array + registrations: boolean + approval_required: boolean + invites_enabled?: boolean + configuration: { + statuses: { + max_characters: number + max_media_attachments?: number + characters_reserved_per_url?: number + } + polls?: { + max_options: number + max_characters_per_option: number + min_expiration: number + max_expiration: number + } + } + contact_account?: Account + rules?: Array +} + +export interface InstanceRule { + id: string + text: string } diff --git a/packages/megalodon/src/entities/list.ts b/packages/megalodon/src/entities/list.ts index 281f02b110..0886fa76a5 100644 --- a/packages/megalodon/src/entities/list.ts +++ b/packages/megalodon/src/entities/list.ts @@ -1,10 +1,8 @@ -namespace Entity { - export type List = { - id: string - title: string - replies_policy?: RepliesPolicy | null - exclusive?: RepliesPolicy | null - } - - export type RepliesPolicy = 'followed' | 'list' | 'none' +export interface List { + id: string + title: string + replies_policy?: RepliesPolicy | null + exclusive?: RepliesPolicy | null } + +export type RepliesPolicy = 'followed' | 'list' | 'none' diff --git a/packages/megalodon/src/entities/marker.ts b/packages/megalodon/src/entities/marker.ts index 33cb98a10c..e5fa0ec6d7 100644 --- a/packages/megalodon/src/entities/marker.ts +++ b/packages/megalodon/src/entities/marker.ts @@ -1,15 +1,13 @@ -namespace Entity { - export type Marker = { - home?: { - last_read_id: string - version: number - updated_at: string - } - notifications?: { - last_read_id: string - version: number - updated_at: string - unread_count?: number - } - } +export interface Marker { + home?: { + last_read_id: string + version: number + updated_at: string + } + notifications?: { + last_read_id: string + version: number + updated_at: string + unread_count?: number + } } diff --git a/packages/megalodon/src/entities/mention.ts b/packages/megalodon/src/entities/mention.ts index 046912971c..29f162e750 100644 --- a/packages/megalodon/src/entities/mention.ts +++ b/packages/megalodon/src/entities/mention.ts @@ -1,8 +1,6 @@ -namespace Entity { - export type Mention = { - id: string - username: string - url: string - acct: string - } +export interface Mention { + id: string + username: string + url: string + acct: string } diff --git a/packages/megalodon/src/entities/notification.ts b/packages/megalodon/src/entities/notification.ts index 653d235d99..6d8d4191b8 100644 --- a/packages/megalodon/src/entities/notification.ts +++ b/packages/megalodon/src/entities/notification.ts @@ -1,16 +1,14 @@ -/// -/// +import type { Account } from './account.js'; +import type { Status } from './status.js'; -namespace Entity { - export type Notification = { - account: Account - created_at: string - id: string - status?: Status - emoji?: string - type: NotificationType - target?: Account - } - - export type NotificationType = string +export interface Notification { + account: Account + created_at: string + id: string + status?: Status + emoji?: string + type: NotificationType + target?: Account } + +export type NotificationType = string diff --git a/packages/megalodon/src/entities/poll.ts b/packages/megalodon/src/entities/poll.ts index 42e7f69ac1..f5cfdc53ae 100644 --- a/packages/megalodon/src/entities/poll.ts +++ b/packages/megalodon/src/entities/poll.ts @@ -1,15 +1,13 @@ -/// +import type { PollOption } from './poll_option.js'; -namespace Entity { - export type Poll = { - id: string - expires_at: string | null - expired: boolean - multiple: boolean - votes_count: number - options: Array - voted: boolean - emojis?: [] - own_votes?: Array - } +export interface Poll { + id: string + expires_at: string | null + expired: boolean + multiple: boolean + votes_count: number + options: Array + voted: boolean + emojis?: [] + own_votes?: Array } diff --git a/packages/megalodon/src/entities/poll_option.ts b/packages/megalodon/src/entities/poll_option.ts index ae4c638498..66d1a22500 100644 --- a/packages/megalodon/src/entities/poll_option.ts +++ b/packages/megalodon/src/entities/poll_option.ts @@ -1,6 +1,4 @@ -namespace Entity { - export type PollOption = { - title: string - votes_count: number | null - } +export interface PollOption { + title: string + votes_count: number | null } diff --git a/packages/megalodon/src/entities/preferences.ts b/packages/megalodon/src/entities/preferences.ts index cb5797c4ce..2abf4f9346 100644 --- a/packages/megalodon/src/entities/preferences.ts +++ b/packages/megalodon/src/entities/preferences.ts @@ -1,9 +1,7 @@ -namespace Entity { - export type Preferences = { - 'posting:default:visibility': 'public' | 'unlisted' | 'private' | 'direct' - 'posting:default:sensitive': boolean - 'posting:default:language': string | null - 'reading:expand:media': 'default' | 'show_all' | 'hide_all' - 'reading:expand:spoilers': boolean - } +export interface Preferences { + 'posting:default:visibility': 'public' | 'unlisted' | 'private' | 'direct' + 'posting:default:sensitive': boolean + 'posting:default:language': string | null + 'reading:expand:media': 'default' | 'show_all' | 'hide_all' + 'reading:expand:spoilers': boolean } diff --git a/packages/megalodon/src/entities/push_subscription.ts b/packages/megalodon/src/entities/push_subscription.ts index fe7464e8e2..e28f6507c7 100644 --- a/packages/megalodon/src/entities/push_subscription.ts +++ b/packages/megalodon/src/entities/push_subscription.ts @@ -1,16 +1,14 @@ -namespace Entity { - export type Alerts = { - follow: boolean - favourite: boolean - mention: boolean - reblog: boolean - poll: boolean - } - - export type PushSubscription = { - id: string - endpoint: string - server_key: string - alerts: Alerts - } +export interface Alerts { + follow: boolean + favourite: boolean + mention: boolean + reblog: boolean + poll: boolean +} + +export interface PushSubscription { + id: string + endpoint: string + server_key: string + alerts: Alerts } diff --git a/packages/megalodon/src/entities/reaction.ts b/packages/megalodon/src/entities/reaction.ts index 3315eded50..08fc17846a 100644 --- a/packages/megalodon/src/entities/reaction.ts +++ b/packages/megalodon/src/entities/reaction.ts @@ -1,12 +1,10 @@ -/// +import type { Account } from './account.js'; -namespace Entity { - export type Reaction = { - count: number - me: boolean - name: string - accounts?: Array - url?: string - static_url?: string - } +export type Reaction = { + count: number + me: boolean + name: string + accounts?: Array + url?: string + static_url?: string } diff --git a/packages/megalodon/src/entities/relationship.ts b/packages/megalodon/src/entities/relationship.ts index eb8daf9c7b..dcab19195d 100644 --- a/packages/megalodon/src/entities/relationship.ts +++ b/packages/megalodon/src/entities/relationship.ts @@ -1,18 +1,16 @@ -namespace Entity { - export type Relationship = { - id: string - following: boolean - followed_by: boolean - blocking: boolean - blocked_by: boolean - muting: boolean - muting_notifications: boolean - requested: boolean - requested_by?: boolean - domain_blocking: boolean - showing_reblogs: boolean - endorsed: boolean - notifying: boolean - note: string | null - } +export type Relationship = { + id: string + following: boolean + followed_by: boolean + blocking: boolean + blocked_by: boolean + muting: boolean + muting_notifications: boolean + requested: boolean + requested_by?: boolean + domain_blocking: boolean + showing_reblogs: boolean + endorsed: boolean + notifying: boolean + note: string | null } diff --git a/packages/megalodon/src/entities/report.ts b/packages/megalodon/src/entities/report.ts index 353886a344..69e91e17b0 100644 --- a/packages/megalodon/src/entities/report.ts +++ b/packages/megalodon/src/entities/report.ts @@ -1,18 +1,16 @@ -/// +import type { Account } from './account.js'; -namespace Entity { - export type Report = { - id: string - action_taken: boolean - action_taken_at: string | null - status_ids: Array | null - rule_ids: Array | null - // These parameters don't exist in Pleroma - category: Category | null - comment: string | null - forwarded: boolean | null - target_account?: Account | null - } - - export type Category = 'spam' | 'violation' | 'other' +export interface Report { + id: string + action_taken: boolean + action_taken_at: string | null + status_ids: Array | null + rule_ids: Array | null + // These parameters don't exist in Pleroma + category: Category | null + comment: string | null + forwarded: boolean | null + target_account?: Account | null } + +export type Category = 'spam' | 'violation' | 'other' diff --git a/packages/megalodon/src/entities/results.ts b/packages/megalodon/src/entities/results.ts index fe168de67b..ccf871c36e 100644 --- a/packages/megalodon/src/entities/results.ts +++ b/packages/megalodon/src/entities/results.ts @@ -1,11 +1,9 @@ -/// -/// -/// +import type { Account } from './account.js'; +import type { Status } from './status.js'; +import type { Tag } from './tag.js'; -namespace Entity { - export type Results = { - accounts: Array - statuses: Array - hashtags: Array - } +export interface Results { + accounts: Array + statuses: Array + hashtags: Array } diff --git a/packages/megalodon/src/entities/role.ts b/packages/megalodon/src/entities/role.ts index caaae9ea12..af7e9cad18 100644 --- a/packages/megalodon/src/entities/role.ts +++ b/packages/megalodon/src/entities/role.ts @@ -1,5 +1,3 @@ -namespace Entity { - export type Role = { - name: string - } +export interface Role { + name: string } diff --git a/packages/megalodon/src/entities/scheduled_status.ts b/packages/megalodon/src/entities/scheduled_status.ts index 561a5b9f2c..1bd402260e 100644 --- a/packages/megalodon/src/entities/scheduled_status.ts +++ b/packages/megalodon/src/entities/scheduled_status.ts @@ -1,10 +1,9 @@ -/// -/// -namespace Entity { - export type ScheduledStatus = { - id: string - scheduled_at: string - params: StatusParams - media_attachments: Array | null - } +import type { StatusParams } from './status_params.js'; +import type { Attachment } from './attachment.js'; + +export interface ScheduledStatus { + id: string + scheduled_at: string + params: StatusParams + media_attachments: Array | null } diff --git a/packages/megalodon/src/entities/source.ts b/packages/megalodon/src/entities/source.ts index d87cf55d85..dd602b5a7f 100644 --- a/packages/megalodon/src/entities/source.ts +++ b/packages/megalodon/src/entities/source.ts @@ -1,10 +1,9 @@ -/// -namespace Entity { - export type Source = { - privacy: string | null - sensitive: boolean | null - language: string | null - note: string - fields: Array - } +import type { Field } from './field.js'; + +export interface Source { + privacy: string | null + sensitive: boolean | null + language: string | null + note: string + fields: Array } diff --git a/packages/megalodon/src/entities/stats.ts b/packages/megalodon/src/entities/stats.ts index 76f0bad34c..1bf26a3974 100644 --- a/packages/megalodon/src/entities/stats.ts +++ b/packages/megalodon/src/entities/stats.ts @@ -1,7 +1,5 @@ -namespace Entity { - export type Stats = { - user_count: number - status_count: number - domain_count: number - } +export interface Stats { + user_count: number + status_count: number + domain_count: number } diff --git a/packages/megalodon/src/entities/status.ts b/packages/megalodon/src/entities/status.ts index 8ef473d274..8d185bdf88 100644 --- a/packages/megalodon/src/entities/status.ts +++ b/packages/megalodon/src/entities/status.ts @@ -1,50 +1,48 @@ -/// -/// -/// -/// -/// -/// -/// -/// +import type { Emoji } from './emoji.js'; +import type { Account } from './account.js'; +import type { Attachment } from './attachment.js'; +import type { Mention } from './mention.js'; +import type { Card } from './card.js'; +import type { Poll } from './poll.js'; +import type { Application } from './application.js'; +import type { Reaction } from './reaction.js'; -namespace Entity { - export type Status = { - id: string - uri: string - url: string - account: Account - in_reply_to_id: string | null - in_reply_to_account_id: string | null - reblog: Status | null - content: string - plain_content?: string | null - created_at: string - edited_at: string | null - emojis: Emoji[] - replies_count: number - reblogs_count: number - favourites_count: number - reblogged: boolean | null - favourited: boolean | null - muted: boolean | null - sensitive: boolean - spoiler_text: string - visibility: 'public' | 'unlisted' | 'private' | 'direct' - media_attachments: Array - mentions: Array - tags: Array - card: Card | null - poll: Poll | null - application: Application | null - language: string | null - pinned: boolean | null - emoji_reactions: Array - quote: Status | boolean | null - bookmarked: boolean - } - - export type StatusTag = { - name: string - url: string - } +export interface Status { + id: string + uri: string + url: string + account: Account + in_reply_to_id: string | null + in_reply_to_account_id: string | null + reblog: Status | null + content: string + plain_content?: string | null + created_at: string + edited_at: string | null + emojis: Emoji[] + replies_count: number + reblogs_count: number + favourites_count: number + reblogged: boolean | null + favourited: boolean | null + muted: boolean | null + sensitive: boolean + spoiler_text: string + visibility: 'public' | 'unlisted' | 'private' | 'direct' + media_attachments: Array + mentions: Array + tags: Array + card: Card | null + poll: Poll | null + application: Application | null + language: string | null + pinned: boolean | null + emoji_reactions: Array + quote: Status | boolean | null + bookmarked: boolean +} + +export interface StatusTag { + name: string + url: string } diff --git a/packages/megalodon/src/entities/status_edit.ts b/packages/megalodon/src/entities/status_edit.ts index 4040b4ff90..9767deb778 100644 --- a/packages/megalodon/src/entities/status_edit.ts +++ b/packages/megalodon/src/entities/status_edit.ts @@ -1,23 +1,16 @@ -/// -/// -/// -/// -/// -/// -/// -/// -/// +import type { Account } from './account.js'; +import type { Emoji } from './emoji.js'; +import type { Attachment } from './attachment.js'; +import type { Poll } from './poll.js'; -namespace Entity { - export type StatusEdit = { - account: Account; - content: string; - plain_content: string | null; - created_at: string; - emojis: Emoji[]; - sensitive: boolean; - spoiler_text: string; - media_attachments: Array; - poll: Poll | null; - }; +export interface StatusEdit { + account: Account; + content: string; + plain_content: string | null; + created_at: string; + emojis: Emoji[]; + sensitive: boolean; + spoiler_text: string; + media_attachments: Array; + poll: Poll | null; } diff --git a/packages/megalodon/src/entities/status_params.ts b/packages/megalodon/src/entities/status_params.ts index 82d7890868..799447ddf6 100644 --- a/packages/megalodon/src/entities/status_params.ts +++ b/packages/megalodon/src/entities/status_params.ts @@ -1,12 +1,10 @@ -namespace Entity { - export type StatusParams = { - text: string - in_reply_to_id: string | null - media_ids: Array | null - sensitive: boolean | null - spoiler_text: string | null - visibility: 'public' | 'unlisted' | 'private' | 'direct' | null - scheduled_at: string | null - application_id: number | null - } +export interface StatusParams { + text: string + in_reply_to_id: string | null + media_ids: Array | null + sensitive: boolean | null + spoiler_text: string | null + visibility: 'public' | 'unlisted' | 'private' | 'direct' | null + scheduled_at: string | null + application_id: number | null } diff --git a/packages/megalodon/src/entities/status_source.ts b/packages/megalodon/src/entities/status_source.ts index 0de7030ed5..7125b577d8 100644 --- a/packages/megalodon/src/entities/status_source.ts +++ b/packages/megalodon/src/entities/status_source.ts @@ -1,7 +1,5 @@ -namespace Entity { - export type StatusSource = { - id: string - text: string - spoiler_text: string - } +export interface StatusSource { + id: string + text: string + spoiler_text: string } diff --git a/packages/megalodon/src/entities/tag.ts b/packages/megalodon/src/entities/tag.ts index ddc5fe92be..ab71ef4ef5 100644 --- a/packages/megalodon/src/entities/tag.ts +++ b/packages/megalodon/src/entities/tag.ts @@ -1,10 +1,8 @@ -/// +import type { History } from './history.js'; -namespace Entity { - export type Tag = { - name: string - url: string - history: Array - following?: boolean - } +export interface Tag { + name: string + url: string + history: Array + following?: boolean } diff --git a/packages/megalodon/src/entities/token.ts b/packages/megalodon/src/entities/token.ts index 6fa28e39b5..3656d8951b 100644 --- a/packages/megalodon/src/entities/token.ts +++ b/packages/megalodon/src/entities/token.ts @@ -1,8 +1,6 @@ -namespace Entity { - export type Token = { - access_token: string - token_type: string - scope: string - created_at: number - } +export interface Token { + access_token: string + token_type: string + scope: string + created_at: number } diff --git a/packages/megalodon/src/entities/urls.ts b/packages/megalodon/src/entities/urls.ts index 4a980d589d..70aae2f6a0 100644 --- a/packages/megalodon/src/entities/urls.ts +++ b/packages/megalodon/src/entities/urls.ts @@ -1,5 +1,3 @@ -namespace Entity { - export type URLs = { - streaming_api: string - } +export interface URLs { + streaming_api: string } diff --git a/packages/megalodon/src/entity.ts b/packages/megalodon/src/entity.ts index 387981cec0..2a216ea048 100644 --- a/packages/megalodon/src/entity.ts +++ b/packages/megalodon/src/entity.ts @@ -1,40 +1,40 @@ -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// - -export default Entity +export type * from './entities/account.js'; +export type * from './entities/activity.js'; +export type * from './entities/announcement.js'; +export type * from './entities/application.js'; +export type * from './entities/async_attachment.js'; +export type * from './entities/attachment.js'; +export type * from './entities/card.js'; +export type * from './entities/context.js'; +export type * from './entities/conversation.js'; +export type * from './entities/emoji.js'; +export type * from './entities/featured_tag.js'; +export type * from './entities/field.js'; +export type * from './entities/filter.js'; +export type * from './entities/follow_request.js'; +export type * from './entities/history.js'; +export type * from './entities/identity_proof.js'; +export type * from './entities/instance.js'; +export type * from './entities/list.js'; +export type * from './entities/marker.js'; +export type * from './entities/mention.js'; +export type * from './entities/notification.js'; +export type * from './entities/poll.js'; +export type * from './entities/poll_option.js'; +export type * from './entities/preferences.js'; +export type * from './entities/push_subscription.js'; +export type * from './entities/reaction.js'; +export type * from './entities/relationship.js'; +export type * from './entities/report.js'; +export type * from './entities/results.js'; +export type * from './entities/role.js'; +export type * from './entities/scheduled_status.js'; +export type * from './entities/source.js'; +export type * from './entities/stats.js'; +export type * from './entities/status.js'; +export type * from './entities/status_edit.js'; +export type * from './entities/status_params.js'; +export type * from './entities/status_source.js'; +export type * from './entities/tag.js'; +export type * from './entities/token.js'; +export type * from './entities/urls.js'; diff --git a/packages/megalodon/src/filter_context.ts b/packages/megalodon/src/filter_context.ts index c69be98cd2..e6fef7f96b 100644 --- a/packages/megalodon/src/filter_context.ts +++ b/packages/megalodon/src/filter_context.ts @@ -1,11 +1,7 @@ -import Entity from './entity' +import type * as Entity from './entity.js' -namespace FilterContext { - export const Home: Entity.FilterContext = 'home' - export const Notifications: Entity.FilterContext = 'notifications' - export const Public: Entity.FilterContext = 'public' - export const Thread: Entity.FilterContext = 'thread' - export const Account: Entity.FilterContext = 'account' -} - -export default FilterContext +export const Home: Entity.FilterContext = 'home' +export const Notifications: Entity.FilterContext = 'notifications' +export const Public: Entity.FilterContext = 'public' +export const Thread: Entity.FilterContext = 'thread' +export const Account: Entity.FilterContext = 'account' diff --git a/packages/megalodon/src/index.ts b/packages/megalodon/src/index.ts index e13e1a1faf..79aebfb330 100644 --- a/packages/megalodon/src/index.ts +++ b/packages/megalodon/src/index.ts @@ -1,15 +1,15 @@ -import Response from './response' -import OAuth from './oauth' -import { isCancel, RequestCanceledError } from './cancel' -import { MegalodonInterface } from './megalodon' -import { detector } from './detector' -import Misskey from './misskey' -import Entity from './entity' -import * as NotificationType from './notification' -import FilterContext from './filter_context' -import Converter from './converter' -import MastodonEntity from './mastodon/entity'; -import MisskeyEntity from './misskey/entity'; +import { type Response } from './response.js' +import * as OAuth from './oauth.js' +import { isCancel, RequestCanceledError } from './cancel.js' +import { type MegalodonInterface } from './megalodon.js' +import { detector } from './detector.js' +import Misskey from './misskey.js' +import * as Entity from './entity.js' +import * as NotificationType from './notification.js' +import * as FilterContext from './filter_context.js' +import Converter from './converter.js' +import * as MastodonEntity from './mastodon/entity.js'; +import * as MisskeyEntity from './misskey/entity.js'; export { type Response, diff --git a/packages/megalodon/src/mastodon/entities/account.ts b/packages/megalodon/src/mastodon/entities/account.ts index 9055fdd915..800e35f2ef 100644 --- a/packages/megalodon/src/mastodon/entities/account.ts +++ b/packages/megalodon/src/mastodon/entities/account.ts @@ -1,35 +1,34 @@ -/// -/// -/// -/// -namespace MastodonEntity { - export type Account = { - id: string - username: string - acct: string - display_name: string - locked: boolean - discoverable?: boolean - group: boolean | null - noindex: boolean | null - suspended: boolean | null - limited: boolean | null - created_at: string - followers_count: number - following_count: number - statuses_count: number - note: string - url: string - avatar: string - avatar_static: string - header: string - header_static: string - emojis: Array - moved: Account | null - fields: Array - bot: boolean - source?: Source - role?: Role - mute_expires_at?: string - } +import type { Emoji } from './emoji.js'; +import type { Field } from './field.js'; +import type { Source } from './source.js'; +import type { Role } from './role.js'; + +export interface Account { + id: string + username: string + acct: string + display_name: string + locked: boolean + discoverable?: boolean + group: boolean | null + noindex: boolean | null + suspended: boolean | null + limited: boolean | null + created_at: string + followers_count: number + following_count: number + statuses_count: number + note: string + url: string + avatar: string + avatar_static: string + header: string + header_static: string + emojis: Array + moved: Account | null + fields: Array + bot: boolean + source?: Source + role?: Role + mute_expires_at?: string } diff --git a/packages/megalodon/src/mastodon/entities/activity.ts b/packages/megalodon/src/mastodon/entities/activity.ts index 3e84c9df07..b646622f6f 100644 --- a/packages/megalodon/src/mastodon/entities/activity.ts +++ b/packages/megalodon/src/mastodon/entities/activity.ts @@ -1,8 +1,6 @@ -namespace MastodonEntity { - export type Activity = { - week: string - statuses: string - logins: string - registrations: string - } +export interface Activity { + week: string + statuses: string + logins: string + registrations: string } diff --git a/packages/megalodon/src/mastodon/entities/announcement.ts b/packages/megalodon/src/mastodon/entities/announcement.ts index 426112e76f..a62664ad23 100644 --- a/packages/megalodon/src/mastodon/entities/announcement.ts +++ b/packages/megalodon/src/mastodon/entities/announcement.ts @@ -1,40 +1,39 @@ -/// +import type { Emoji } from './emoji.js'; +import type { StatusTag } from './status.js'; -namespace MastodonEntity { - export type Announcement = { - id: string - content: string - starts_at: string | null - ends_at: string | null - published: boolean - all_day: boolean - published_at: string - updated_at: string - read: boolean | null - mentions: Array - statuses: Array - tags: Array - emojis: Array - reactions: Array - } - - export type AnnouncementAccount = { - id: string - username: string - url: string - acct: string - } - - export type AnnouncementStatus = { - id: string - url: string - } - - export type AnnouncementReaction = { - name: string - count: number - me: boolean | null - url: string | null - static_url: string | null - } +export interface Announcement { + id: string + content: string + starts_at: string | null + ends_at: string | null + published: boolean + all_day: boolean + published_at: string + updated_at: string + read: boolean | null + mentions: Array + statuses: Array + tags: Array + emojis: Array + reactions: Array +} + +export interface AnnouncementAccount { + id: string + username: string + url: string + acct: string +} + +export interface AnnouncementStatus { + id: string + url: string +} + +export interface AnnouncementReaction { + name: string + count: number + me: boolean | null + url: string | null + static_url: string | null } diff --git a/packages/megalodon/src/mastodon/entities/application.ts b/packages/megalodon/src/mastodon/entities/application.ts index f402152bf6..4f64b18fd0 100644 --- a/packages/megalodon/src/mastodon/entities/application.ts +++ b/packages/megalodon/src/mastodon/entities/application.ts @@ -1,10 +1,8 @@ -namespace MastodonEntity { - export type Application = { - name: string - website?: string | null - vapid_key?: string | null - scopes: string[] - redirect_uris: string[] - redirect_uri?: string - } +export interface Application { + name: string + website?: string | null + vapid_key?: string | null + scopes: string[] + redirect_uris: string[] + redirect_uri?: string } diff --git a/packages/megalodon/src/mastodon/entities/async_attachment.ts b/packages/megalodon/src/mastodon/entities/async_attachment.ts index 45f574d645..0433656bb2 100644 --- a/packages/megalodon/src/mastodon/entities/async_attachment.ts +++ b/packages/megalodon/src/mastodon/entities/async_attachment.ts @@ -1,14 +1,13 @@ -/// -namespace MastodonEntity { - export type AsyncAttachment = { - id: string - type: 'unknown' | 'image' | 'gifv' | 'video' | 'audio' - url: string | null - remote_url: string | null - preview_url: string - text_url: string | null - meta: Meta | null - description: string | null - blurhash: string | null - } +import type { Meta } from './attachment.js'; + +export interface AsyncAttachment { + id: string + type: 'unknown' | 'image' | 'gifv' | 'video' | 'audio' + url: string | null + remote_url: string | null + preview_url: string + text_url: string | null + meta: Meta | null + description: string | null + blurhash: string | null } diff --git a/packages/megalodon/src/mastodon/entities/attachment.ts b/packages/megalodon/src/mastodon/entities/attachment.ts index ec51c5bcab..7522a293ef 100644 --- a/packages/megalodon/src/mastodon/entities/attachment.ts +++ b/packages/megalodon/src/mastodon/entities/attachment.ts @@ -1,49 +1,47 @@ -namespace MastodonEntity { - export type Sub = { - // For Image, Gifv, and Video - width?: number - height?: number - size?: string - aspect?: number +export type Sub = { + // For Image, Gifv, and Video + width?: number + height?: number + size?: string + aspect?: number - // For Gifv and Video - frame_rate?: string + // For Gifv and Video + frame_rate?: string - // For Audio, Gifv, and Video - duration?: number - bitrate?: number - } - - export type Focus = { - x: number - y: number - } - - export type Meta = { - original?: Sub - small?: Sub - focus?: Focus - length?: string - duration?: number - fps?: number - size?: string - width?: number - height?: number - aspect?: number - audio_encode?: string - audio_bitrate?: string - audio_channel?: string - } - - export type Attachment = { - id: string - type: 'unknown' | 'image' | 'gifv' | 'video' | 'audio' - url: string - remote_url: string | null - preview_url: string | null - text_url: string | null - meta: Meta | null - description: string | null - blurhash: string | null - } + // For Audio, Gifv, and Video + duration?: number + bitrate?: number +} + +export interface Focus { + x: number + y: number +} + +export interface Meta { + original?: Sub + small?: Sub + focus?: Focus + length?: string + duration?: number + fps?: number + size?: string + width?: number + height?: number + aspect?: number + audio_encode?: string + audio_bitrate?: string + audio_channel?: string +} + +export interface Attachment { + id: string + type: 'unknown' | 'image' | 'gifv' | 'video' | 'audio' + url: string + remote_url: string | null + preview_url: string | null + text_url: string | null + meta: Meta | null + description: string | null + blurhash: string | null } diff --git a/packages/megalodon/src/mastodon/entities/card.ts b/packages/megalodon/src/mastodon/entities/card.ts index 9058de7f7c..756aaeacfb 100644 --- a/packages/megalodon/src/mastodon/entities/card.ts +++ b/packages/megalodon/src/mastodon/entities/card.ts @@ -1,18 +1,16 @@ -namespace MastodonEntity { - export type Card = { - url: string - title: string - description: string - type: 'link' | 'photo' | 'video' | 'rich' - image: string | null - author_name: string - author_url: string - provider_name: string - provider_url: string - html: string - width: number - height: number - embed_url: string - blurhash: string | null - } +export interface Card { + url: string + title: string + description: string + type: 'link' | 'photo' | 'video' | 'rich' + image: string | null + author_name: string + author_url: string + provider_name: string + provider_url: string + html: string + width: number + height: number + embed_url: string + blurhash: string | null } diff --git a/packages/megalodon/src/mastodon/entities/context.ts b/packages/megalodon/src/mastodon/entities/context.ts index c2b6e26822..a80e334e31 100644 --- a/packages/megalodon/src/mastodon/entities/context.ts +++ b/packages/megalodon/src/mastodon/entities/context.ts @@ -1,8 +1,6 @@ -/// +import type { Status } from './status.js'; -namespace MastodonEntity { - export type Context = { - ancestors: Array - descendants: Array - } +export interface Context { + ancestors: Array + descendants: Array } diff --git a/packages/megalodon/src/mastodon/entities/conversation.ts b/packages/megalodon/src/mastodon/entities/conversation.ts index 0ee3f1d7f9..d67e3f4b98 100644 --- a/packages/megalodon/src/mastodon/entities/conversation.ts +++ b/packages/megalodon/src/mastodon/entities/conversation.ts @@ -1,11 +1,9 @@ -/// -/// +import type { Account } from './account.js'; +import type { Status } from './status.js'; -namespace MastodonEntity { - export type Conversation = { - id: string - accounts: Array - last_status: Status | null - unread: boolean - } +export interface Conversation { + id: string + accounts: Array + last_status: Status | null + unread: boolean } diff --git a/packages/megalodon/src/mastodon/entities/emoji.ts b/packages/megalodon/src/mastodon/entities/emoji.ts index 5434914323..f617167aea 100644 --- a/packages/megalodon/src/mastodon/entities/emoji.ts +++ b/packages/megalodon/src/mastodon/entities/emoji.ts @@ -1,9 +1,7 @@ -namespace MastodonEntity { - export type Emoji = { - shortcode: string - static_url: string - url: string - visible_in_picker: boolean - category?: string - } +export interface Emoji { + shortcode: string + static_url: string + url: string + visible_in_picker: boolean + category?: string } diff --git a/packages/megalodon/src/mastodon/entities/featured_tag.ts b/packages/megalodon/src/mastodon/entities/featured_tag.ts index a2628b98c4..3e7bcb155e 100644 --- a/packages/megalodon/src/mastodon/entities/featured_tag.ts +++ b/packages/megalodon/src/mastodon/entities/featured_tag.ts @@ -1,8 +1,6 @@ -namespace MastodonEntity { - export type FeaturedTag = { - id: string - name: string - statuses_count: number - last_status_at: string - } +export interface FeaturedTag { + id: string + name: string + statuses_count: number + last_status_at: string } diff --git a/packages/megalodon/src/mastodon/entities/field.ts b/packages/megalodon/src/mastodon/entities/field.ts index b6ada5d132..63d0a4c7f2 100644 --- a/packages/megalodon/src/mastodon/entities/field.ts +++ b/packages/megalodon/src/mastodon/entities/field.ts @@ -1,7 +1,5 @@ -namespace MastodonEntity { - export type Field = { - name: string - value: string - verified_at: string | null - } +export interface Field { + name: string + value: string + verified_at: string | null } diff --git a/packages/megalodon/src/mastodon/entities/filter.ts b/packages/megalodon/src/mastodon/entities/filter.ts index 1e17e61b21..0e064fe134 100644 --- a/packages/megalodon/src/mastodon/entities/filter.ts +++ b/packages/megalodon/src/mastodon/entities/filter.ts @@ -1,12 +1,10 @@ -namespace MastodonEntity { - export type Filter = { - id: string - phrase: string - context: Array - expires_at: string | null - irreversible: boolean - whole_word: boolean - } - - export type FilterContext = string +export interface Filter { + id: string + phrase: string + context: Array + expires_at: string | null + irreversible: boolean + whole_word: boolean } + +export type FilterContext = string diff --git a/packages/megalodon/src/mastodon/entities/history.ts b/packages/megalodon/src/mastodon/entities/history.ts index cc1a3b4fb3..3aee331a2a 100644 --- a/packages/megalodon/src/mastodon/entities/history.ts +++ b/packages/megalodon/src/mastodon/entities/history.ts @@ -1,7 +1,5 @@ -namespace MastodonEntity { - export type History = { - day: string - uses: number - accounts: number - } +export interface History { + day: string + uses: number + accounts: number } diff --git a/packages/megalodon/src/mastodon/entities/identity_proof.ts b/packages/megalodon/src/mastodon/entities/identity_proof.ts index a4dab9eaf0..0fe00f3a73 100644 --- a/packages/megalodon/src/mastodon/entities/identity_proof.ts +++ b/packages/megalodon/src/mastodon/entities/identity_proof.ts @@ -1,9 +1,7 @@ -namespace MastodonEntity { - export type IdentityProof = { - provider: string - provider_username: string - updated_at: string - proof_url: string - profile_url: string - } +export interface IdentityProof { + provider: string + provider_username: string + updated_at: string + proof_url: string + profile_url: string } diff --git a/packages/megalodon/src/mastodon/entities/instance.ts b/packages/megalodon/src/mastodon/entities/instance.ts index ab0875a273..17be00c88c 100644 --- a/packages/megalodon/src/mastodon/entities/instance.ts +++ b/packages/megalodon/src/mastodon/entities/instance.ts @@ -1,56 +1,54 @@ -/// -/// -/// +import type { Account } from './account.js'; +import type { URLs } from './urls.js'; +import type { Stats } from './stats.js'; -namespace MastodonEntity { - export type Instance = { - uri: string - title: string - description: string - email: string - version: string - thumbnail: string | null - urls: URLs - stats: Stats - languages: Array - registrations: boolean - approval_required: boolean - invites_enabled: boolean - max_toot_chars?: number - configuration: { - statuses: { - max_characters: number - max_media_attachments: number - characters_reserved_per_url: number - } - media_attachments: { - supported_mime_types: Array - image_size_limit: number - image_matrix_limit: number - video_size_limit: number - video_frame_limit: number - video_matrix_limit: number - } - polls: { - max_options: number - max_characters_per_option: number - min_expiration: number - max_expiration: number - } - accounts: { - max_featured_tags: number; - max_pinned_statuses: number; - } - reactions: { - max_reactions: number, - } - } - contact_account: Account | null - rules: Array - } - - export type InstanceRule = { - id: string - text: string - } +export type Instance = { + uri: string + title: string + description: string + email: string + version: string + thumbnail: string | null + urls: URLs + stats: Stats + languages: Array + registrations: boolean + approval_required: boolean + invites_enabled: boolean + max_toot_chars?: number + configuration: { + statuses: { + max_characters: number + max_media_attachments: number + characters_reserved_per_url: number + } + media_attachments: { + supported_mime_types: Array + image_size_limit: number + image_matrix_limit: number + video_size_limit: number + video_frame_limit: number + video_matrix_limit: number + } + polls: { + max_options: number + max_characters_per_option: number + min_expiration: number + max_expiration: number + } + accounts: { + max_featured_tags: number; + max_pinned_statuses: number; + } + reactions: { + max_reactions: number, + } + } + contact_account: Account | null + rules: Array +} + +export interface InstanceRule { + id: string + text: string } diff --git a/packages/megalodon/src/mastodon/entities/list.ts b/packages/megalodon/src/mastodon/entities/list.ts index 503499839f..fb157b0bf1 100644 --- a/packages/megalodon/src/mastodon/entities/list.ts +++ b/packages/megalodon/src/mastodon/entities/list.ts @@ -1,9 +1,7 @@ -namespace MastodonEntity { - export type List = { - id: string - title: string - replies_policy: RepliesPolicy - } - - export type RepliesPolicy = 'followed' | 'list' | 'none' +export interface List { + id: string + title: string + replies_policy: RepliesPolicy } + +export type RepliesPolicy = 'followed' | 'list' | 'none' diff --git a/packages/megalodon/src/mastodon/entities/marker.ts b/packages/megalodon/src/mastodon/entities/marker.ts index 1b0983e2b3..8616988afa 100644 --- a/packages/megalodon/src/mastodon/entities/marker.ts +++ b/packages/megalodon/src/mastodon/entities/marker.ts @@ -1,14 +1,12 @@ -namespace MastodonEntity { - export type Marker = { - home: { - last_read_id: string - version: number - updated_at: string - } - notifications: { - last_read_id: string - version: number - updated_at: string - } - } +export interface Marker { + home: { + last_read_id: string + version: number + updated_at: string + } + notifications: { + last_read_id: string + version: number + updated_at: string + } } diff --git a/packages/megalodon/src/mastodon/entities/mention.ts b/packages/megalodon/src/mastodon/entities/mention.ts index ddc99d93e6..29f162e750 100644 --- a/packages/megalodon/src/mastodon/entities/mention.ts +++ b/packages/megalodon/src/mastodon/entities/mention.ts @@ -1,8 +1,6 @@ -namespace MastodonEntity { - export type Mention = { - id: string - username: string - url: string - acct: string - } +export interface Mention { + id: string + username: string + url: string + acct: string } diff --git a/packages/megalodon/src/mastodon/entities/notification.ts b/packages/megalodon/src/mastodon/entities/notification.ts index ad5519bae4..7918292c65 100644 --- a/packages/megalodon/src/mastodon/entities/notification.ts +++ b/packages/megalodon/src/mastodon/entities/notification.ts @@ -1,14 +1,12 @@ -/// -/// +import type { Account } from './account.js'; +import type { Status } from './status.js'; -namespace MastodonEntity { - export type Notification = { - account: Account - created_at: string - id: string - status?: Status - type: NotificationType - } - - export type NotificationType = string +export interface Notification { + account: Account + created_at: string + id: string + status?: Status + type: NotificationType } + +export type NotificationType = string diff --git a/packages/megalodon/src/mastodon/entities/poll.ts b/packages/megalodon/src/mastodon/entities/poll.ts index eaf09050f9..faf05ad524 100644 --- a/packages/megalodon/src/mastodon/entities/poll.ts +++ b/packages/megalodon/src/mastodon/entities/poll.ts @@ -1,13 +1,11 @@ -/// +import type { PollOption } from './poll_option.js'; -namespace MastodonEntity { - export type Poll = { - id: string - expires_at: string | null - expired: boolean - multiple: boolean - votes_count: number - options: Array - voted: boolean - } +export interface Poll { + id: string + expires_at: string | null + expired: boolean + multiple: boolean + votes_count: number + options: Array + voted: boolean } diff --git a/packages/megalodon/src/mastodon/entities/poll_option.ts b/packages/megalodon/src/mastodon/entities/poll_option.ts index d3c14190fb..66d1a22500 100644 --- a/packages/megalodon/src/mastodon/entities/poll_option.ts +++ b/packages/megalodon/src/mastodon/entities/poll_option.ts @@ -1,6 +1,4 @@ -namespace MastodonEntity { - export type PollOption = { - title: string - votes_count: number | null - } +export interface PollOption { + title: string + votes_count: number | null } diff --git a/packages/megalodon/src/mastodon/entities/preferences.ts b/packages/megalodon/src/mastodon/entities/preferences.ts index 3c8cc953c0..2abf4f9346 100644 --- a/packages/megalodon/src/mastodon/entities/preferences.ts +++ b/packages/megalodon/src/mastodon/entities/preferences.ts @@ -1,9 +1,7 @@ -namespace MastodonEntity { - export type Preferences = { - 'posting:default:visibility': 'public' | 'unlisted' | 'private' | 'direct' - 'posting:default:sensitive': boolean - 'posting:default:language': string | null - 'reading:expand:media': 'default' | 'show_all' | 'hide_all' - 'reading:expand:spoilers': boolean - } +export interface Preferences { + 'posting:default:visibility': 'public' | 'unlisted' | 'private' | 'direct' + 'posting:default:sensitive': boolean + 'posting:default:language': string | null + 'reading:expand:media': 'default' | 'show_all' | 'hide_all' + 'reading:expand:spoilers': boolean } diff --git a/packages/megalodon/src/mastodon/entities/push_subscription.ts b/packages/megalodon/src/mastodon/entities/push_subscription.ts index ad96ea685f..e28f6507c7 100644 --- a/packages/megalodon/src/mastodon/entities/push_subscription.ts +++ b/packages/megalodon/src/mastodon/entities/push_subscription.ts @@ -1,16 +1,14 @@ -namespace MastodonEntity { - export type Alerts = { - follow: boolean - favourite: boolean - mention: boolean - reblog: boolean - poll: boolean - } - - export type PushSubscription = { - id: string - endpoint: string - server_key: string - alerts: Alerts - } +export interface Alerts { + follow: boolean + favourite: boolean + mention: boolean + reblog: boolean + poll: boolean +} + +export interface PushSubscription { + id: string + endpoint: string + server_key: string + alerts: Alerts } diff --git a/packages/megalodon/src/mastodon/entities/reaction.ts b/packages/megalodon/src/mastodon/entities/reaction.ts index 370eeb5cbe..0494de89f4 100644 --- a/packages/megalodon/src/mastodon/entities/reaction.ts +++ b/packages/megalodon/src/mastodon/entities/reaction.ts @@ -1,16 +1,7 @@ -/* - * SPDX-FileCopyrightText: hazelnoot and other Sharkey contributors - * SPDX-License-Identifier: AGPL-3.0-only - */ - -/// - -namespace MastodonEntity { - export type Reaction = { - name: string - count: number - me?: boolean - url?: string - static_url?: string - } +export interface Reaction { + name: string + count: number + me?: boolean + url?: string + static_url?: string } diff --git a/packages/megalodon/src/mastodon/entities/relationship.ts b/packages/megalodon/src/mastodon/entities/relationship.ts index f868a64063..43bfd4f90d 100644 --- a/packages/megalodon/src/mastodon/entities/relationship.ts +++ b/packages/megalodon/src/mastodon/entities/relationship.ts @@ -1,19 +1,17 @@ -namespace MastodonEntity { - export type Relationship = { - id: string - following: boolean - followed_by: boolean - blocking: boolean - blocked_by: boolean - muting: boolean - muting_notifications: boolean - requested: boolean - requested_by: boolean - domain_blocking: boolean - showing_reblogs: boolean - endorsed: boolean - notifying: boolean - note: string - languages: Array - } +export interface Relationship { + id: string + following: boolean + followed_by: boolean + blocking: boolean + blocked_by: boolean + muting: boolean + muting_notifications: boolean + requested: boolean + requested_by: boolean + domain_blocking: boolean + showing_reblogs: boolean + endorsed: boolean + notifying: boolean + note: string + languages: Array } diff --git a/packages/megalodon/src/mastodon/entities/report.ts b/packages/megalodon/src/mastodon/entities/report.ts index 0eba265a35..e4763d0c1c 100644 --- a/packages/megalodon/src/mastodon/entities/report.ts +++ b/packages/megalodon/src/mastodon/entities/report.ts @@ -1,17 +1,15 @@ -/// +import type { Account } from './account.js'; -namespace MastodonEntity { - export type Report = { - id: string - action_taken: boolean - action_taken_at: string | null - category: Category - comment: string - forwarded: boolean - status_ids: Array | null - rule_ids: Array | null - target_account: Account - } - - export type Category = 'spam' | 'violation' | 'other' +export interface Report { + id: string + action_taken: boolean + action_taken_at: string | null + category: Category + comment: string + forwarded: boolean + status_ids: Array | null + rule_ids: Array | null + target_account: Account } + +export type Category = 'spam' | 'violation' | 'other' diff --git a/packages/megalodon/src/mastodon/entities/results.ts b/packages/megalodon/src/mastodon/entities/results.ts index a1c9065435..ccf871c36e 100644 --- a/packages/megalodon/src/mastodon/entities/results.ts +++ b/packages/megalodon/src/mastodon/entities/results.ts @@ -1,11 +1,9 @@ -/// -/// -/// +import type { Account } from './account.js'; +import type { Status } from './status.js'; +import type { Tag } from './tag.js'; -namespace MastodonEntity { - export type Results = { - accounts: Array - statuses: Array - hashtags: Array - } +export interface Results { + accounts: Array + statuses: Array + hashtags: Array } diff --git a/packages/megalodon/src/mastodon/entities/role.ts b/packages/megalodon/src/mastodon/entities/role.ts index ebfad59c1e..af7e9cad18 100644 --- a/packages/megalodon/src/mastodon/entities/role.ts +++ b/packages/megalodon/src/mastodon/entities/role.ts @@ -1,5 +1,3 @@ -namespace MastodonEntity { - export type Role = { - name: string - } +export interface Role { + name: string } diff --git a/packages/megalodon/src/mastodon/entities/scheduled_status.ts b/packages/megalodon/src/mastodon/entities/scheduled_status.ts index 2388311acc..9eb064beaa 100644 --- a/packages/megalodon/src/mastodon/entities/scheduled_status.ts +++ b/packages/megalodon/src/mastodon/entities/scheduled_status.ts @@ -1,10 +1,9 @@ -/// -/// -namespace MastodonEntity { - export type ScheduledStatus = { - id: string - scheduled_at: string - params: StatusParams - media_attachments: Array - } +import type { StatusParams } from './status_params.js'; +import type { Attachment } from './attachment.js'; + +export interface ScheduledStatus { + id: string + scheduled_at: string + params: StatusParams + media_attachments: Array } diff --git a/packages/megalodon/src/mastodon/entities/source.ts b/packages/megalodon/src/mastodon/entities/source.ts index c104602172..dd602b5a7f 100644 --- a/packages/megalodon/src/mastodon/entities/source.ts +++ b/packages/megalodon/src/mastodon/entities/source.ts @@ -1,10 +1,9 @@ -/// -namespace MastodonEntity { - export type Source = { - privacy: string | null - sensitive: boolean | null - language: string | null - note: string - fields: Array - } +import type { Field } from './field.js'; + +export interface Source { + privacy: string | null + sensitive: boolean | null + language: string | null + note: string + fields: Array } diff --git a/packages/megalodon/src/mastodon/entities/stats.ts b/packages/megalodon/src/mastodon/entities/stats.ts index 925da85010..1bf26a3974 100644 --- a/packages/megalodon/src/mastodon/entities/stats.ts +++ b/packages/megalodon/src/mastodon/entities/stats.ts @@ -1,7 +1,5 @@ -namespace MastodonEntity { - export type Stats = { - user_count: number - status_count: number - domain_count: number - } +export interface Stats { + user_count: number + status_count: number + domain_count: number } diff --git a/packages/megalodon/src/mastodon/entities/status.ts b/packages/megalodon/src/mastodon/entities/status.ts index 76472a8580..e9d1231846 100644 --- a/packages/megalodon/src/mastodon/entities/status.ts +++ b/packages/megalodon/src/mastodon/entities/status.ts @@ -1,53 +1,50 @@ -/// -/// -/// -/// -/// -/// -/// -/// -/// +import type { Attachment } from './attachment.js'; +import type { Mention } from './mention.js'; +import type { Card } from './card.js'; +import type { Poll } from './poll.js'; +import type { Application } from './application.js'; +import type { Reaction } from './reaction.js'; +import type { Account } from './account.js'; +import type { Emoji } from './emoji.js'; -namespace MastodonEntity { - export type Status = { - id: string - uri: string - url: string - account: Account - in_reply_to_id: string | null - in_reply_to_account_id: string | null - reblog: Status | null - content: string - created_at: string - edited_at?: string | null - emojis: Emoji[] - replies_count: number - reblogs_count: number - favourites_count: number - reblogged: boolean | null - favourited: boolean | null - muted: boolean | null - sensitive: boolean - spoiler_text: string - visibility: 'public' | 'unlisted' | 'private' | 'direct' - media_attachments: Array - mentions: Array - tags: Array - card: Card | null - poll: Poll | null - application: Application | null - language: string | null - pinned: boolean | null - bookmarked?: boolean - // These parameters are unique parameters in fedibird.com for quote. - quote_id?: string - quote?: Status | null - // These parameters are unique to glitch-soc for emoji reactions. - reactions?: Reaction[] - } - - export type StatusTag = { - name: string - url: string - } +export interface Status { + id: string + uri: string + url: string + account: Account + in_reply_to_id: string | null + in_reply_to_account_id: string | null + reblog: Status | null + content: string + created_at: string + edited_at?: string | null + emojis: Emoji[] + replies_count: number + reblogs_count: number + favourites_count: number + reblogged: boolean | null + favourited: boolean | null + muted: boolean | null + sensitive: boolean + spoiler_text: string + visibility: 'public' | 'unlisted' | 'private' | 'direct' + media_attachments: Array + mentions: Array + tags: Array + card: Card | null + poll: Poll | null + application: Application | null + language: string | null + pinned: boolean | null + bookmarked?: boolean + // These parameters are unique parameters in fedibird.com for quote. + quote_id?: string + quote?: Status | null + // These parameters are unique to glitch-soc for emoji reactions. + reactions?: Reaction[] +} + +export interface StatusTag { + name: string + url: string } diff --git a/packages/megalodon/src/mastodon/entities/status_params.ts b/packages/megalodon/src/mastodon/entities/status_params.ts index 1b6ffb7ddc..8f9eed68e8 100644 --- a/packages/megalodon/src/mastodon/entities/status_params.ts +++ b/packages/megalodon/src/mastodon/entities/status_params.ts @@ -1,12 +1,10 @@ -namespace MastodonEntity { - export type StatusParams = { - text: string - in_reply_to_id: string | null - media_ids: Array | null - sensitive: boolean | null - spoiler_text: string | null - visibility: 'public' | 'unlisted' | 'private' | 'direct' | null - scheduled_at: string | null - application_id: number - } +export interface StatusParams { + text: string + in_reply_to_id: string | null + media_ids: Array | null + sensitive: boolean | null + spoiler_text: string | null + visibility: 'public' | 'unlisted' | 'private' | 'direct' | null + scheduled_at: string | null + application_id: number } diff --git a/packages/megalodon/src/mastodon/entities/status_source.ts b/packages/megalodon/src/mastodon/entities/status_source.ts index f8ca42c032..7125b577d8 100644 --- a/packages/megalodon/src/mastodon/entities/status_source.ts +++ b/packages/megalodon/src/mastodon/entities/status_source.ts @@ -1,7 +1,5 @@ -namespace MastodonEntity { - export type StatusSource = { - id: string - text: string - spoiler_text: string - } +export interface StatusSource { + id: string + text: string + spoiler_text: string } diff --git a/packages/megalodon/src/mastodon/entities/tag.ts b/packages/megalodon/src/mastodon/entities/tag.ts index 8a10ad58b9..ab71ef4ef5 100644 --- a/packages/megalodon/src/mastodon/entities/tag.ts +++ b/packages/megalodon/src/mastodon/entities/tag.ts @@ -1,10 +1,8 @@ -/// +import type { History } from './history.js'; -namespace MastodonEntity { - export type Tag = { - name: string - url: string - history: Array - following?: boolean - } +export interface Tag { + name: string + url: string + history: Array + following?: boolean } diff --git a/packages/megalodon/src/mastodon/entities/token.ts b/packages/megalodon/src/mastodon/entities/token.ts index 128663ecfd..3656d8951b 100644 --- a/packages/megalodon/src/mastodon/entities/token.ts +++ b/packages/megalodon/src/mastodon/entities/token.ts @@ -1,8 +1,6 @@ -namespace MastodonEntity { - export type Token = { - access_token: string - token_type: string - scope: string - created_at: number - } +export interface Token { + access_token: string + token_type: string + scope: string + created_at: number } diff --git a/packages/megalodon/src/mastodon/entities/urls.ts b/packages/megalodon/src/mastodon/entities/urls.ts index 4f6b55a4c1..70aae2f6a0 100644 --- a/packages/megalodon/src/mastodon/entities/urls.ts +++ b/packages/megalodon/src/mastodon/entities/urls.ts @@ -1,5 +1,3 @@ -namespace MastodonEntity { - export type URLs = { - streaming_api: string - } +export interface URLs { + streaming_api: string } diff --git a/packages/megalodon/src/mastodon/entity.ts b/packages/megalodon/src/mastodon/entity.ts index 10a3aa71c4..692c484d95 100644 --- a/packages/megalodon/src/mastodon/entity.ts +++ b/packages/megalodon/src/mastodon/entity.ts @@ -1,40 +1,37 @@ -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// - -export default MastodonEntity +export type * from './entities/account.js'; +export type * from './entities/activity.js'; +export type * from './entities/announcement.js'; +export type * from './entities/application.js'; +export type * from './entities/async_attachment.js'; +export type * from './entities/attachment.js'; +export type * from './entities/card.js'; +export type * from './entities/context.js'; +export type * from './entities/conversation.js'; +export type * from './entities/emoji.js'; +export type * from './entities/featured_tag.js'; +export type * from './entities/field.js'; +export type * from './entities/filter.js'; +export type * from './entities/history.js'; +export type * from './entities/identity_proof.js'; +export type * from './entities/instance.js'; +export type * from './entities/list.js'; +export type * from './entities/marker.js'; +export type * from './entities/mention.js'; +export type * from './entities/notification.js'; +export type * from './entities/poll.js'; +export type * from './entities/poll_option.js'; +export type * from './entities/preferences.js'; +export type * from './entities/push_subscription.js'; +export type * from './entities/reaction.js'; +export type * from './entities/relationship.js'; +export type * from './entities/report.js'; +export type * from './entities/results.js'; +export type * from './entities/role.js'; +export type * from './entities/scheduled_status.js'; +export type * from './entities/source.js'; +export type * from './entities/stats.js'; +export type * from './entities/status.js'; +export type * from './entities/status_params.js'; +export type * from './entities/tag.js'; +export type * from './entities/token.js'; +export type * from './entities/urls.js'; diff --git a/packages/megalodon/src/megalodon.ts b/packages/megalodon/src/megalodon.ts index 4257e545df..5bde31ff82 100644 --- a/packages/megalodon/src/megalodon.ts +++ b/packages/megalodon/src/megalodon.ts @@ -1,6 +1,6 @@ -import Response from './response' -import OAuth from './oauth' -import Entity from './entity' +import { type Response } from './response.js' +import * as OAuth from './oauth.js' +import * as Entity from './entity.js' export interface MegalodonInterface { /** diff --git a/packages/megalodon/src/misskey.ts b/packages/megalodon/src/misskey.ts index 88a815d35e..f7f69b9168 100644 --- a/packages/megalodon/src/misskey.ts +++ b/packages/megalodon/src/misskey.ts @@ -1,11 +1,12 @@ import FormData from 'form-data' import fs from 'fs'; -import MisskeyAPI from './misskey/api_client' -import { DEFAULT_UA } from './default' -import OAuth from './oauth' -import Response from './response' -import { MegalodonInterface, NoImplementedError, ArgumentError, UnexpectedError } from './megalodon' -import { UnknownNotificationTypeError } from './notification' +import * as MisskeyAPI from './misskey/api_client.js' +import { DEFAULT_UA } from './default.js' +import * as OAuth from './oauth.js' +import { type Response } from './response.js' +import * as Entity from './entity.js' +import { type MegalodonInterface, NoImplementedError, ArgumentError, UnexpectedError } from './megalodon.js' +import { UnknownNotificationTypeError } from './notification.js' export default class Misskey implements MegalodonInterface { public client: MisskeyAPI.Interface @@ -717,7 +718,7 @@ export default class Misskey implements MegalodonInterface { /** * POST /api/users/reactions */ - public async getReactions(userId: string, options?: { limit?: number; max_id?: string; min_id?: string }): Promise> { + public async getReactions(userId: string, options?: { limit?: number; max_id?: string; min_id?: string }): Promise> { let params = { userId, }; diff --git a/packages/megalodon/src/misskey/api_client.ts b/packages/megalodon/src/misskey/api_client.ts index 659184d156..cf75309043 100644 --- a/packages/megalodon/src/misskey/api_client.ts +++ b/packages/megalodon/src/misskey/api_client.ts @@ -1,651 +1,620 @@ -import axios, { AxiosResponse, AxiosRequestConfig } from 'axios' +import axios, { type AxiosResponse, type AxiosRequestConfig } from 'axios' import dayjs from 'dayjs' -import { DEFAULT_UA } from '../default' -import Response from '../response' -import MisskeyEntity from './entity' -import MegalodonEntity from '../entity' -import MisskeyNotificationType from './notification' -import * as NotificationType from '../notification' -import { UnknownNotificationTypeError } from '../notification'; +import { DEFAULT_UA } from '../default.js' +import { type Response } from '../response.js' +import * as Entity from './entity.js' +import * as MegalodonEntity from '../entity.js' +import * as MisskeyNotificationType from './notification.js' +import * as NotificationType from '../notification.js' +import { UnknownNotificationTypeError } from '../notification.js'; -namespace MisskeyAPI { - export namespace Entity { - export type Announcement = MisskeyEntity.Announcement - export type App = MisskeyEntity.App - export type Blocking = MisskeyEntity.Blocking - export type Choice = MisskeyEntity.Choice - export type CreatedNote = MisskeyEntity.CreatedNote - export type Emoji = MisskeyEntity.Emoji - export type Favorite = MisskeyEntity.Favorite - export type File = MisskeyEntity.File - export type Follower = MisskeyEntity.Follower - export type Following = MisskeyEntity.Following - export type FollowRequest = MisskeyEntity.FollowRequest - export type Hashtag = MisskeyEntity.Hashtag - export type List = MisskeyEntity.List - export type Meta = MisskeyEntity.Meta - export type Mute = MisskeyEntity.Mute - export type Note = MisskeyEntity.Note - export type Notification = MisskeyEntity.Notification - export type Poll = MisskeyEntity.Poll - export type Reaction = MisskeyEntity.Reaction - export type NoteReaction = MisskeyEntity.NoteReaction - export type Relation = MisskeyEntity.Relation - export type User = MisskeyEntity.User - export type UserDetail = MisskeyEntity.UserDetail - export type UserKey = MisskeyEntity.UserKey - export type Session = MisskeyEntity.Session - export type Stats = MisskeyEntity.Stats - } +export type * as Entity from './entity.js'; - export namespace Converter { - export const announcement = (a: Entity.Announcement): MegalodonEntity.Announcement => ({ - id: a.id, - content: a.title + '\n' + a.text, - starts_at: null, - ends_at: null, - published: true, - all_day: true, - published_at: a.createdAt, - updated_at: a.updatedAt, - read: a.isRead !== undefined ? a.isRead : null, - mentions: [], - statuses: [], - tags: [], - emojis: [], - reactions: [] - }) +export namespace Converter { + export const announcement = (a: Entity.Announcement): MegalodonEntity.Announcement => ({ + id: a.id, + content: a.title + '\n' + a.text, + starts_at: null, + ends_at: null, + published: true, + all_day: true, + published_at: a.createdAt, + updated_at: a.updatedAt, + read: a.isRead !== undefined ? a.isRead : null, + mentions: [], + statuses: [], + tags: [], + emojis: [], + reactions: [] + }) - export const emoji = (e: Entity.Emoji): MegalodonEntity.Emoji => { - return { - shortcode: e.name, - static_url: e.url, - url: e.url, - visible_in_picker: true, - category: e.category - } - } + export const emoji = (e: Entity.Emoji): MegalodonEntity.Emoji => { + return { + shortcode: e.name, + static_url: e.url, + url: e.url, + visible_in_picker: true, + category: e.category + } + } - export const user = (u: Entity.User, host: string | null = null): MegalodonEntity.Account => { - let acct = u.username; - host ? host = host.replace("https://", "") : undefined; - let acctUrl = `https://${host || u.host || host}/@${ - u.username - }`; - if (u.host) { - acct = `${u.username}@${u.host}`; - acctUrl = `https://${u.host}/@${u.username}`; + export const user = (u: Entity.User, host: string | null = null): MegalodonEntity.Account => { + let acct = u.username; + host ? host = host.replace("https://", "") : undefined; + let acctUrl = `https://${host || u.host || host}/@${ + u.username + }`; + if (u.host) { + acct = `${u.username}@${u.host}`; + acctUrl = `https://${u.host}/@${u.username}`; + } + const fqn = `${u.username}@${u.host ?? host}`; + return { + id: u.id, + fqn: fqn, + username: u.username, + acct: acct, + display_name: u.name ? u.name : '', + locked: false, + group: null, + noindex: null, + suspended: null, + limited: null, + created_at: u.createdAt ? u.createdAt : '', + followers_count: u.followersCount ? u.followersCount : 0, + following_count: u.followingCount ? u.followingCount : 0, + statuses_count: u.notesCount ? u.notesCount : 0, + note: u.description ? u.description : '', + url: u.uri ?? acctUrl, + avatar: u.avatarUrl ? u.avatarUrl : 'https://dev.joinsharkey.org/static-assets/avatar.png', + avatar_static: u.avatarUrl ? u.avatarUrl : 'https://dev.joinsharkey.org/static-assets/avatar.png', + header: u.bannerUrl ? u.bannerUrl : 'https://dev.joinsharkey.org/static-assets/transparent.png', + header_static: u.bannerUrl ? u.bannerUrl : 'https://dev.joinsharkey.org/static-assets/transparent.png', + emojis: mapEmojis(u.emojis), + moved: null, + fields: [], + bot: null + } + } + + export const userDetail = (u: Entity.UserDetail, host: string | null = null): MegalodonEntity.Account => { + let acct = u.username; + host ? host = host.replace("https://", "") : undefined; + let acctUrl = `https://${u.host || host}/@${u.username}`; + if (u.host) { + acct = `${u.username}@${u.host}`; + acctUrl = `https://${u.host}/@${u.username}`; + } + return { + id: u.id, + username: u.username, + acct: acct, + display_name: u.name ? u.name : '', + locked: u.isLocked, + group: null, + noindex: null, + suspended: null, + limited: null, + created_at: u.createdAt, + followers_count: u.followersCount, + following_count: u.followingCount, + statuses_count: u.notesCount, + note: u.description ? u.description.replace(/\n|\\n/g, "
") : '', + url: u.uri ?? acctUrl, + avatar: u.avatarUrl ? u.avatarUrl : 'https://dev.joinsharkey.org/static-assets/avatar.png', + avatar_static: u.avatarUrl ? u.avatarUrl : 'https://dev.joinsharkey.org/static-assets/avatar.png', + header: u.bannerUrl ? u.bannerUrl : 'https://dev.joinsharkey.org/static-assets/transparent.png', + header_static: u.bannerUrl ? u.bannerUrl : 'https://dev.joinsharkey.org/static-assets/transparent.png', + emojis: mapEmojis(u.emojis), + moved: null, + fields: [], + bot: u.isBot + } + } + + export const userPreferences = (v: "public" | "unlisted" | "private" | "direct"): MegalodonEntity.Preferences => { + return { + "reading:expand:media": "default", + "reading:expand:spoilers": false, + "posting:default:language": "english", + "posting:default:sensitive": false, + "posting:default:visibility": v, + }; + }; + + export const visibility = (v: 'public' | 'home' | 'followers' | 'specified'): 'public' | 'unlisted' | 'private' | 'direct' => { + switch (v) { + case 'public': + return v + case 'home': + return 'unlisted' + case 'followers': + return 'private' + case 'specified': + return 'direct' + } + } + + export const encodeVisibility = (v: 'public' | 'unlisted' | 'private' | 'direct'): 'public' | 'home' | 'followers' | 'specified' => { + switch (v) { + case 'public': + return v + case 'unlisted': + return 'home' + case 'private': + return 'followers' + case 'direct': + return 'specified' + } + } + + export const fileType = (s: string): 'unknown' | 'image' | 'gifv' | 'video' | 'audio' => { + if (s === 'image/gif') { + return 'gifv' + } + if (s.includes('image')) { + return 'image' + } + if (s.includes('video')) { + return 'video' + } + if (s.includes('audio')) { + return 'audio' + } + return 'unknown' + } + + export const file = (f: Entity.File): MegalodonEntity.Attachment => { + return { + id: f.id, + type: fileType(f.type), + url: f.url, + remote_url: f.url, + preview_url: f.thumbnailUrl, + text_url: f.url, + meta: { + width: f.properties.width, + height: f.properties.height + }, + description: f.comment ? f.comment : null, + blurhash: f.blurhash ? f.blurhash : null + } + } + + export const follower = (f: Entity.Follower): MegalodonEntity.Account => { + return user(f.follower) + } + + export const following = (f: Entity.Following): MegalodonEntity.Account => { + return user(f.followee) + } + + export const relation = (r: Entity.Relation): MegalodonEntity.Relationship => { + return { + id: r.id, + following: r.isFollowing, + followed_by: r.isFollowed, + blocking: r.isBlocking, + blocked_by: r.isBlocked, + muting: r.isMuted, + muting_notifications: r.isMuted, + requested: r.hasPendingFollowRequestFromYou, + requested_by: r.hasPendingFollowRequestToYou, + domain_blocking: r.isInstanceMuted ?? false, + showing_reblogs: !r.isRenoteMuted, + endorsed: false, + notifying: !r.isMuted, + note: r.memo ?? '', + } + } + + export const choice = (c: Entity.Choice): MegalodonEntity.PollOption => { + return { + title: c.text, + votes_count: c.votes + } + } + + export const poll = (p: Entity.Poll, id: string): MegalodonEntity.Poll => { + const now = dayjs() + const expire = dayjs(p.expiresAt) + const count = p.choices.reduce((sum, choice) => sum + choice.votes, 0) + return { + id: id, + expires_at: p.expiresAt, + expired: now.isAfter(expire), + multiple: p.multiple, + votes_count: count, + options: Array.isArray(p.choices) ? p.choices.map(c => choice(c)) : [], + voted: Array.isArray(p.choices) ? p.choices.some(c => c.isVoted) : false, + own_votes: Array.isArray(p.choices) ? p.choices.filter((c) => c.isVoted).map((c) => p.choices.indexOf(c)) : [], + emojis: [], + } + } + + export const note = (n: Entity.Note, host: string | null = null): MegalodonEntity.Status => { + host ? host = host.replace("https://", "") : null; + return { + id: n.id, + uri: n.uri ? n.uri : host ? `https://${host}/notes/${n.id}` : '', + url: n.url ? n.url : host ? `https://${host}/notes/${n.id}` : '', + account: user(n.user, n.user.host ? n.user.host : host ? host : null), + in_reply_to_id: n.replyId, + in_reply_to_account_id: n.reply?.userId ?? null, + reblog: n.renote ? note(n.renote, n.user.host ? n.user.host : host ? host : null) : null, + content: n.text + ? n.text + .replace(/&/g, '&') + .replace(//g, '>') + .replace(/"/g, '"') + .replace(/'/g, ''') + .replace(/`/g, '`') + .replace(/\r?\n/g, '
') + : '', + plain_content: n.text ? n.text : null, + created_at: n.createdAt, + edited_at: n.updatedAt || null, + // TODO this is probably wrong + emojis: mapEmojis(n.emojis).concat(mapReactionEmojis(n.reactionEmojis)), + replies_count: n.repliesCount, + reblogs_count: n.renoteCount, + favourites_count: getTotalReactions(n.reactions), + reblogged: false, + favourited: !!n.myReaction, + muted: false, + sensitive: Array.isArray(n.files) ? n.files.some(f => f.isSensitive) : false, + spoiler_text: n.cw ? n.cw : '', + visibility: visibility(n.visibility), + media_attachments: Array.isArray(n.files) ? n.files.map(f => file(f)) : [], + mentions: [], + tags: [], + card: null, + poll: n.poll ? poll(n.poll, n.id) : null, + application: null, + language: null, + pinned: null, + emoji_reactions: typeof n.reactions === 'object' ? mapReactions(n.reactions, n.reactionEmojis, n.myReaction) : [], + bookmarked: false, + quote: n.renote && n.text ? note(n.renote, n.user.host ? n.user.host : host ? host : null) : null + } + } + + export const notesource = (n: Entity.Note): MegalodonEntity.StatusSource => { + return { + id: n.id, + text: n.text ?? '', + spoiler_text: n.cw ? n.cw : '' + } + } + + const mapEmojis = (e: Array | { [key: string]: string }): Array => { + if (Array.isArray(e)) { + return e.map(e => emoji(e)) + } else if (e) { + return mapReactionEmojis(e) + } else { + return [] + } + } + + export const getTotalReactions = (r: { [key: string]: number }): number => { + return Object.values(r).length > 0 ? Object.values(r).reduce( + (previousValue, currentValue) => previousValue + currentValue, + ) : 0; + }; + + export const mapReactions = (r: { [key: string]: number }, e: Record, myReaction?: string): Array => { + return Object.entries(r).map(([key, count]) => { + const me = myReaction != null && key === myReaction; + + // Name is equal to the key for native emoji reactions, and as a fallback. + let name = key; + + // Custom emoji have a leading / trailing ":", which we need to remove. + const match = key.match(/^:([^@:]+)(@[^:]+)?:$/); + if (match) { + const [, prefix, host] = match; + + // Local custom emoji end in "@.", which we need to remove. + if (host && host !== '@.') { + name = prefix + host; + } else { + name = prefix; + } } - const fqn = `${u.username}@${u.host ?? host}`; - return { - id: u.id, - fqn: fqn, - username: u.username, - acct: acct, - display_name: u.name ? u.name : '', - locked: false, - group: null, - noindex: null, - suspended: null, - limited: null, - created_at: u.createdAt ? u.createdAt : '', - followers_count: u.followersCount ? u.followersCount : 0, - following_count: u.followingCount ? u.followingCount : 0, - statuses_count: u.notesCount ? u.notesCount : 0, - note: u.description ? u.description : '', - url: u.uri ?? acctUrl, - avatar: u.avatarUrl ? u.avatarUrl : 'https://dev.joinsharkey.org/static-assets/avatar.png', - avatar_static: u.avatarUrl ? u.avatarUrl : 'https://dev.joinsharkey.org/static-assets/avatar.png', - header: u.bannerUrl ? u.bannerUrl : 'https://dev.joinsharkey.org/static-assets/transparent.png', - header_static: u.bannerUrl ? u.bannerUrl : 'https://dev.joinsharkey.org/static-assets/transparent.png', - emojis: mapEmojis(u.emojis), - moved: null, - fields: [], - bot: null - } - } - export const userDetail = (u: Entity.UserDetail, host: string | null = null): MegalodonEntity.Account => { - let acct = u.username; - host ? host = host.replace("https://", "") : undefined; - let acctUrl = `https://${u.host || host}/@${u.username}`; - if (u.host) { - acct = `${u.username}@${u.host}`; - acctUrl = `https://${u.host}/@${u.username}`; - } - return { - id: u.id, - username: u.username, - acct: acct, - display_name: u.name ? u.name : '', - locked: u.isLocked, - group: null, - noindex: null, - suspended: null, - limited: null, - created_at: u.createdAt, - followers_count: u.followersCount, - following_count: u.followingCount, - statuses_count: u.notesCount, - note: u.description ? u.description.replace(/\n|\\n/g, "
") : '', - url: u.uri ?? acctUrl, - avatar: u.avatarUrl ? u.avatarUrl : 'https://dev.joinsharkey.org/static-assets/avatar.png', - avatar_static: u.avatarUrl ? u.avatarUrl : 'https://dev.joinsharkey.org/static-assets/avatar.png', - header: u.bannerUrl ? u.bannerUrl : 'https://dev.joinsharkey.org/static-assets/transparent.png', - header_static: u.bannerUrl ? u.bannerUrl : 'https://dev.joinsharkey.org/static-assets/transparent.png', - emojis: mapEmojis(u.emojis), - moved: null, - fields: [], - bot: u.isBot - } - } - - export const userPreferences = (v: "public" | "unlisted" | "private" | "direct"): MegalodonEntity.Preferences => { return { - "reading:expand:media": "default", - "reading:expand:spoilers": false, - "posting:default:language": "english", - "posting:default:sensitive": false, - "posting:default:visibility": v, - }; - }; + count, + me, + name, + url: e[name], + static_url: e[name], + } + }) + } - export const visibility = (v: 'public' | 'home' | 'followers' | 'specified'): 'public' | 'unlisted' | 'private' | 'direct' => { - switch (v) { - case 'public': - return v - case 'home': - return 'unlisted' - case 'followers': - return 'private' - case 'specified': - return 'direct' - } - } + // TODO implement other properties + const mapReactionEmojis = (r: { [key: string]: string }): Array => { + return Object.keys(r).map(key => ({ + shortcode: key, + static_url: r[key], + url: r[key], + visible_in_picker: true, + category: '' + })) + } - export const encodeVisibility = (v: 'public' | 'unlisted' | 'private' | 'direct'): 'public' | 'home' | 'followers' | 'specified' => { - switch (v) { - case 'public': - return v - case 'unlisted': - return 'home' - case 'private': - return 'followers' - case 'direct': - return 'specified' - } - } + export const reactions = (r: Array): Array => { + const result: Array = [] + r.map(e => { + const i = result.findIndex(res => res.name === e.type) + if (i >= 0) { + result[i].count++ + } else { + result.push({ + count: 1, + me: false, + name: e.type, + }) + } + }) + return result + } - export const fileType = (s: string): 'unknown' | 'image' | 'gifv' | 'video' | 'audio' => { - if (s === 'image/gif') { - return 'gifv' - } - if (s.includes('image')) { - return 'image' - } - if (s.includes('video')) { - return 'video' - } - if (s.includes('audio')) { - return 'audio' - } - return 'unknown' - } + export const noteToConversation = (n: Entity.Note): MegalodonEntity.Conversation => { + const accounts: Array = [user(n.user)] + if (n.reply) { + accounts.push(user(n.reply.user)) + } + return { + id: n.id, + accounts: accounts, + last_status: note(n), + unread: false + } + } - export const file = (f: Entity.File): MegalodonEntity.Attachment => { - return { - id: f.id, - type: fileType(f.type), - url: f.url, - remote_url: f.url, - preview_url: f.thumbnailUrl, - text_url: f.url, - meta: { - width: f.properties.width, - height: f.properties.height - }, - description: f.comment ? f.comment : null, - blurhash: f.blurhash ? f.blurhash : null - } - } + export const list = (l: Entity.List): MegalodonEntity.List => ({ + id: l.id, + title: l.name, + exclusive: null + }) - export const follower = (f: Entity.Follower): MegalodonEntity.Account => { - return user(f.follower) - } + export const encodeNotificationType = ( + e: MegalodonEntity.NotificationType + ): Entity.NotificationType | UnknownNotificationTypeError => { + switch (e) { + case NotificationType.Follow: + return MisskeyNotificationType.Follow + case NotificationType.Mention: + return MisskeyNotificationType.Reply + case NotificationType.Favourite: + case NotificationType.EmojiReaction: + return MisskeyNotificationType.Reaction + case NotificationType.Reblog: + return MisskeyNotificationType.Renote + case NotificationType.PollVote: + return MisskeyNotificationType.PollVote + case NotificationType.FollowRequest: + return MisskeyNotificationType.ReceiveFollowRequest + default: + return new UnknownNotificationTypeError() + } + } - export const following = (f: Entity.Following): MegalodonEntity.Account => { - return user(f.followee) - } + export const decodeNotificationType = ( + e: Entity.NotificationType + ): MegalodonEntity.NotificationType | UnknownNotificationTypeError => { + switch (e) { + case MisskeyNotificationType.Follow: + return NotificationType.Follow + case MisskeyNotificationType.Mention: + case MisskeyNotificationType.Reply: + return NotificationType.Mention + case MisskeyNotificationType.Renote: + case MisskeyNotificationType.Quote: + return NotificationType.Reblog + case MisskeyNotificationType.Reaction: + return NotificationType.EmojiReaction + case MisskeyNotificationType.PollVote: + return NotificationType.PollVote + case MisskeyNotificationType.ReceiveFollowRequest: + return NotificationType.FollowRequest + case MisskeyNotificationType.FollowRequestAccepted: + return NotificationType.Follow + default: + return new UnknownNotificationTypeError() + } + } - export const relation = (r: Entity.Relation): MegalodonEntity.Relationship => { - return { - id: r.id, - following: r.isFollowing, - followed_by: r.isFollowed, - blocking: r.isBlocking, - blocked_by: r.isBlocked, - muting: r.isMuted, - muting_notifications: r.isMuted, - requested: r.hasPendingFollowRequestFromYou, - requested_by: r.hasPendingFollowRequestToYou, - domain_blocking: r.isInstanceMuted ?? false, - showing_reblogs: !r.isRenoteMuted, - endorsed: false, - notifying: !r.isMuted, - note: r.memo ?? '', - } - } + export const notification = (n: Entity.Notification): MegalodonEntity.Notification | UnknownNotificationTypeError => { + const notificationType = decodeNotificationType(n.type) + if (notificationType instanceof UnknownNotificationTypeError) { + return notificationType + } + let notification = { + id: n.id, + account: user(n.user), + created_at: n.createdAt, + type: notificationType + } + if (n.note) { + notification = Object.assign(notification, { + status: note(n.note) + }) + } + if (n.reaction) { + notification = Object.assign(notification, { + emoji: n.reaction + }) + } + return notification + } - export const choice = (c: Entity.Choice): MegalodonEntity.PollOption => { - return { - title: c.text, - votes_count: c.votes - } - } + export const stats = (s: Entity.Stats): MegalodonEntity.Stats => { + return { + user_count: s.originalUsersCount, + status_count: s.originalNotesCount, + domain_count: s.instances + } + } - export const poll = (p: Entity.Poll, id: string): MegalodonEntity.Poll => { - const now = dayjs() - const expire = dayjs(p.expiresAt) - const count = p.choices.reduce((sum, choice) => sum + choice.votes, 0) - return { - id: id, - expires_at: p.expiresAt, - expired: now.isAfter(expire), - multiple: p.multiple, - votes_count: count, - options: Array.isArray(p.choices) ? p.choices.map(c => choice(c)) : [], - voted: Array.isArray(p.choices) ? p.choices.some(c => c.isVoted) : false, - own_votes: Array.isArray(p.choices) ? p.choices.filter((c) => c.isVoted).map((c) => p.choices.indexOf(c)) : [], - emojis: [], - } - } - - export const note = (n: Entity.Note, host: string | null = null): MegalodonEntity.Status => { - host ? host = host.replace("https://", "") : null; - return { - id: n.id, - uri: n.uri ? n.uri : host ? `https://${host}/notes/${n.id}` : '', - url: n.url ? n.url : host ? `https://${host}/notes/${n.id}` : '', - account: user(n.user, n.user.host ? n.user.host : host ? host : null), - in_reply_to_id: n.replyId, - in_reply_to_account_id: n.reply?.userId ?? null, - reblog: n.renote ? note(n.renote, n.user.host ? n.user.host : host ? host : null) : null, - content: n.text - ? n.text - .replace(/&/g, '&') - .replace(//g, '>') - .replace(/"/g, '"') - .replace(/'/g, ''') - .replace(/`/g, '`') - .replace(/\r?\n/g, '
') - : '', - plain_content: n.text ? n.text : null, - created_at: n.createdAt, - edited_at: n.updatedAt || null, - // TODO this is probably wrong - emojis: mapEmojis(n.emojis).concat(mapReactionEmojis(n.reactionEmojis)), - replies_count: n.repliesCount, - reblogs_count: n.renoteCount, - favourites_count: getTotalReactions(n.reactions), - reblogged: false, - favourited: !!n.myReaction, - muted: false, - sensitive: Array.isArray(n.files) ? n.files.some(f => f.isSensitive) : false, - spoiler_text: n.cw ? n.cw : '', - visibility: visibility(n.visibility), - media_attachments: Array.isArray(n.files) ? n.files.map(f => file(f)) : [], - mentions: [], - tags: [], - card: null, - poll: n.poll ? poll(n.poll, n.id) : null, - application: null, - language: null, - pinned: null, - emoji_reactions: typeof n.reactions === 'object' ? mapReactions(n.reactions, n.reactionEmojis, n.myReaction) : [], - bookmarked: false, - quote: n.renote && n.text ? note(n.renote, n.user.host ? n.user.host : host ? host : null) : null - } - } - - export const notesource = (n: Entity.Note): MegalodonEntity.StatusSource => { - return { - id: n.id, - text: n.text ?? '', - spoiler_text: n.cw ? n.cw : '' - } - } - - const mapEmojis = (e: Array | { [key: string]: string }): Array => { - if (Array.isArray(e)) { - return e.map(e => emoji(e)) - } else if (e) { - return mapReactionEmojis(e) - } else { - return [] - } - } - - export const getTotalReactions = (r: { [key: string]: number }): number => { - return Object.values(r).length > 0 ? Object.values(r).reduce( - (previousValue, currentValue) => previousValue + currentValue, - ) : 0; - }; - - export const mapReactions = (r: { [key: string]: number }, e: Record, myReaction?: string): Array => { - return Object.entries(r).map(([key, count]) => { - const me = myReaction != null && key === myReaction; - - // Name is equal to the key for native emoji reactions, and as a fallback. - let name = key; - - // Custom emoji have a leading / trailing ":", which we need to remove. - const match = key.match(/^:([^@:]+)(@[^:]+)?:$/); - if (match) { - const [, prefix, host] = match; - - // Local custom emoji end in "@.", which we need to remove. - if (host && host !== '@.') { - name = prefix + host; - } else { - name = prefix; - } + export const meta = (m: Entity.Meta, s: Entity.Stats): MegalodonEntity.Instance => { + const wss = m.uri.replace(/^https:\/\//, 'wss://') + return { + uri: m.uri, + title: m.name, + description: m.description, + email: m.maintainerEmail, + version: m.version, + thumbnail: m.bannerUrl, + urls: { + streaming_api: `${wss}/streaming` + }, + stats: stats(s), + languages: m.langs, + registrations: !m.disableRegistration, + approval_required: false, + configuration: { + statuses: { + max_characters: m.maxNoteTextLength, + max_media_attachments: m.policies.clipLimit } - - return { - count, - me, - name, - url: e[name], - static_url: e[name], - } - }) - } - - // TODO implement other properties - const mapReactionEmojis = (r: { [key: string]: string }): Array => { - return Object.keys(r).map(key => ({ - shortcode: key, - static_url: r[key], - url: r[key], - visible_in_picker: true, - category: '' - })) - } - - export const reactions = (r: Array): Array => { - const result: Array = [] - r.map(e => { - const i = result.findIndex(res => res.name === e.type) - if (i >= 0) { - result[i].count++ - } else { - result.push({ - count: 1, - me: false, - name: e.type, - }) - } - }) - return result - } - - export const noteToConversation = (n: Entity.Note): MegalodonEntity.Conversation => { - const accounts: Array = [user(n.user)] - if (n.reply) { - accounts.push(user(n.reply.user)) - } - return { - id: n.id, - accounts: accounts, - last_status: note(n), - unread: false - } - } - - export const list = (l: Entity.List): MegalodonEntity.List => ({ - id: l.id, - title: l.name, - exclusive: null - }) - - export const encodeNotificationType = ( - e: MegalodonEntity.NotificationType - ): MisskeyEntity.NotificationType | UnknownNotificationTypeError => { - switch (e) { - case NotificationType.Follow: - return MisskeyNotificationType.Follow - case NotificationType.Mention: - return MisskeyNotificationType.Reply - case NotificationType.Favourite: - case NotificationType.EmojiReaction: - return MisskeyNotificationType.Reaction - case NotificationType.Reblog: - return MisskeyNotificationType.Renote - case NotificationType.PollVote: - return MisskeyNotificationType.PollVote - case NotificationType.FollowRequest: - return MisskeyNotificationType.ReceiveFollowRequest - default: - return new UnknownNotificationTypeError() - } - } - - export const decodeNotificationType = ( - e: MisskeyEntity.NotificationType - ): MegalodonEntity.NotificationType | UnknownNotificationTypeError => { - switch (e) { - case MisskeyNotificationType.Follow: - return NotificationType.Follow - case MisskeyNotificationType.Mention: - case MisskeyNotificationType.Reply: - return NotificationType.Mention - case MisskeyNotificationType.Renote: - case MisskeyNotificationType.Quote: - return NotificationType.Reblog - case MisskeyNotificationType.Reaction: - return NotificationType.EmojiReaction - case MisskeyNotificationType.PollVote: - return NotificationType.PollVote - case MisskeyNotificationType.ReceiveFollowRequest: - return NotificationType.FollowRequest - case MisskeyNotificationType.FollowRequestAccepted: - return NotificationType.Follow - default: - return new UnknownNotificationTypeError() - } - } - - export const notification = (n: Entity.Notification): MegalodonEntity.Notification | UnknownNotificationTypeError => { - const notificationType = decodeNotificationType(n.type) - if (notificationType instanceof UnknownNotificationTypeError) { - return notificationType - } - let notification = { - id: n.id, - account: user(n.user), - created_at: n.createdAt, - type: notificationType - } - if (n.note) { - notification = Object.assign(notification, { - status: note(n.note) - }) - } - if (n.reaction) { - notification = Object.assign(notification, { - emoji: n.reaction - }) - } - return notification - } - - export const stats = (s: Entity.Stats): MegalodonEntity.Stats => { - return { - user_count: s.originalUsersCount, - status_count: s.originalNotesCount, - domain_count: s.instances - } - } - - export const meta = (m: Entity.Meta, s: Entity.Stats): MegalodonEntity.Instance => { - const wss = m.uri.replace(/^https:\/\//, 'wss://') - return { - uri: m.uri, - title: m.name, - description: m.description, - email: m.maintainerEmail, - version: m.version, - thumbnail: m.bannerUrl, - urls: { - streaming_api: `${wss}/streaming` - }, - stats: stats(s), - languages: m.langs, - registrations: !m.disableRegistration, - approval_required: false, - configuration: { - statuses: { - max_characters: m.maxNoteTextLength, - max_media_attachments: m.policies.clipLimit - } - } - } - } - - export const hashtag = (h: Entity.Hashtag): MegalodonEntity.Tag => { - return { - name: h.tag, - url: h.tag, - history: [], - following: false - } - } - } - - export const DEFAULT_SCOPE = [ - 'read:account', - 'write:account', - 'read:blocks', - 'write:blocks', - 'read:drive', - 'write:drive', - 'read:favorites', - 'write:favorites', - 'read:following', - 'write:following', - 'read:mutes', - 'write:mutes', - 'write:notes', - 'read:notifications', - 'write:notifications', - 'read:reactions', - 'write:reactions', - 'write:votes' - ] - - /** - * Interface - */ - export interface Interface { - get(path: string, params?: any, headers?: { [key: string]: string }): Promise> - post(path: string, params?: any, headers?: { [key: string]: string }): Promise> - cancel(): void - } - - /** - * Misskey API client. - * - * Using axios for request, you will handle promises. - */ - export class Client implements Interface { - private accessToken: string | null - private baseUrl: string - private userAgent: string - private abortController: AbortController - - /** - * @param baseUrl hostname or base URL - * @param accessToken access token from OAuth2 authorization - * @param userAgent UserAgent is specified in header on request. - */ - constructor(baseUrl: string, accessToken: string | null, userAgent: string = DEFAULT_UA) { - this.accessToken = accessToken - this.baseUrl = baseUrl - this.userAgent = userAgent - this.abortController = new AbortController(); - } - - /** - * GET request to misskey API. - **/ - public async get(path: string, params: any = {}, headers: { [key: string]: string } = {}): Promise> { - if (!headers['Authorization'] && this.accessToken) { - headers['Authorization'] = `Bearer ${this.accessToken}`; - } - if (!headers['User-Agent']) { - headers['User-Agent'] = this.userAgent; } + } + } - let options: AxiosRequestConfig = { - params: params, - headers, - maxContentLength: Infinity, - maxBodyLength: Infinity, - signal: this.abortController.signal, - } - return axios.get(this.baseUrl + path, options).then((resp: AxiosResponse) => { - const res: Response = { - data: resp.data, - status: resp.status, - statusText: resp.statusText, - headers: resp.headers - } - return res - }) - } - - /** - * POST request to misskey REST API. - * @param path relative path from baseUrl - * @param params Form data - * @param headers Request header object - */ - public async post(path: string, params: any = {}, headers: { [key: string]: string } = {}): Promise> { - if (!headers['Authorization'] && this.accessToken) { - headers['Authorization'] = `Bearer ${this.accessToken}`; - } - if (!headers['User-Agent']) { - headers['User-Agent'] = this.userAgent; - } - - let options: AxiosRequestConfig = { - headers: headers, - maxContentLength: Infinity, - maxBodyLength: Infinity, - signal: this.abortController.signal, - } - - return axios.post(this.baseUrl + path, params, options).then((resp: AxiosResponse) => { - const res: Response = { - data: resp.data, - status: resp.status, - statusText: resp.statusText, - headers: resp.headers - } - return res - }) - } - - /** - * Cancel all requests in this instance. - * @returns void - */ - public cancel(): void { - return this.abortController.abort() - } - } + export const hashtag = (h: Entity.Hashtag): MegalodonEntity.Tag => { + return { + name: h.tag, + url: h.tag, + history: [], + following: false + } + } } -export default MisskeyAPI +export const DEFAULT_SCOPE = [ + 'read:account', + 'write:account', + 'read:blocks', + 'write:blocks', + 'read:drive', + 'write:drive', + 'read:favorites', + 'write:favorites', + 'read:following', + 'write:following', + 'read:mutes', + 'write:mutes', + 'write:notes', + 'read:notifications', + 'write:notifications', + 'read:reactions', + 'write:reactions', + 'write:votes' +] + +/** + * Interface + */ +export interface Interface { + get(path: string, params?: any, headers?: { [key: string]: string }): Promise> + post(path: string, params?: any, headers?: { [key: string]: string }): Promise> + cancel(): void +} + +/** + * Misskey API client. + * + * Using axios for request, you will handle promises. + */ +export class Client implements Interface { + private accessToken: string | null + private baseUrl: string + private userAgent: string + private abortController: AbortController + + /** + * @param baseUrl hostname or base URL + * @param accessToken access token from OAuth2 authorization + * @param userAgent UserAgent is specified in header on request. + */ + constructor(baseUrl: string, accessToken: string | null, userAgent: string = DEFAULT_UA) { + this.accessToken = accessToken + this.baseUrl = baseUrl + this.userAgent = userAgent + this.abortController = new AbortController(); + } + + /** + * GET request to misskey API. + **/ + public async get(path: string, params: any = {}, headers: { [key: string]: string } = {}): Promise> { + if (!headers['Authorization'] && this.accessToken) { + headers['Authorization'] = `Bearer ${this.accessToken}`; + } + if (!headers['User-Agent']) { + headers['User-Agent'] = this.userAgent; + } + + let options: AxiosRequestConfig = { + params: params, + headers, + maxContentLength: Infinity, + maxBodyLength: Infinity, + signal: this.abortController.signal, + } + return axios.get(this.baseUrl + path, options).then((resp: AxiosResponse) => { + const res: Response = { + data: resp.data, + status: resp.status, + statusText: resp.statusText, + headers: resp.headers + } + return res + }) + } + + /** + * POST request to misskey REST API. + * @param path relative path from baseUrl + * @param params Form data + * @param headers Request header object + */ + public async post(path: string, params: any = {}, headers: { [key: string]: string } = {}): Promise> { + if (!headers['Authorization'] && this.accessToken) { + headers['Authorization'] = `Bearer ${this.accessToken}`; + } + if (!headers['User-Agent']) { + headers['User-Agent'] = this.userAgent; + } + + let options: AxiosRequestConfig = { + headers: headers, + maxContentLength: Infinity, + maxBodyLength: Infinity, + signal: this.abortController.signal, + } + + return axios.post(this.baseUrl + path, params, options).then((resp: AxiosResponse) => { + const res: Response = { + data: resp.data, + status: resp.status, + statusText: resp.statusText, + headers: resp.headers + } + return res + }) + } + + /** + * Cancel all requests in this instance. + * @returns void + */ + public cancel(): void { + return this.abortController.abort() + } +} diff --git a/packages/megalodon/src/misskey/entities/GetAll.ts b/packages/megalodon/src/misskey/entities/GetAll.ts index 94ace2f184..e7312e5a1f 100644 --- a/packages/megalodon/src/misskey/entities/GetAll.ts +++ b/packages/megalodon/src/misskey/entities/GetAll.ts @@ -1,6 +1,4 @@ -namespace MisskeyEntity { - export type GetAll = { - tutorial: number; - defaultNoteVisibility: "public" | "home" | "followers" | "specified"; - }; +export interface GetAll { + tutorial: number; + defaultNoteVisibility: "public" | "home" | "followers" | "specified"; } diff --git a/packages/megalodon/src/misskey/entities/announcement.ts b/packages/megalodon/src/misskey/entities/announcement.ts index ec1739a75a..63bbaa6d3f 100644 --- a/packages/megalodon/src/misskey/entities/announcement.ts +++ b/packages/megalodon/src/misskey/entities/announcement.ts @@ -1,11 +1,9 @@ -namespace MisskeyEntity { - export type Announcement = { - id: string - createdAt: string - updatedAt: string | null - text: string - title: string - imageurl: string | null - isRead?: boolean - } +export interface Announcement { + id: string + createdAt: string + updatedAt: string | null + text: string + title: string + imageurl: string | null + isRead?: boolean } diff --git a/packages/megalodon/src/misskey/entities/app.ts b/packages/megalodon/src/misskey/entities/app.ts index 49c431596f..33dc2bf723 100644 --- a/packages/megalodon/src/misskey/entities/app.ts +++ b/packages/megalodon/src/misskey/entities/app.ts @@ -1,9 +1,7 @@ -namespace MisskeyEntity { - export type App = { - id: string - name: string - callbackUrl: string - permission: Array - secret?: string - } +export interface App { + id: string + name: string + callbackUrl: string + permission: Array + secret?: string } diff --git a/packages/megalodon/src/misskey/entities/blocking.ts b/packages/megalodon/src/misskey/entities/blocking.ts index 9900a777bf..5282827288 100644 --- a/packages/megalodon/src/misskey/entities/blocking.ts +++ b/packages/megalodon/src/misskey/entities/blocking.ts @@ -1,10 +1,8 @@ -/// +import type { UserDetail } from './userDetail.js'; -namespace MisskeyEntity { - export type Blocking = { - id: string - createdAt: string - blockeeId: string - blockee: UserDetail - } +export interface Blocking { + id: string + createdAt: string + blockeeId: string + blockee: UserDetail } diff --git a/packages/megalodon/src/misskey/entities/createdNote.ts b/packages/megalodon/src/misskey/entities/createdNote.ts index 88ba600401..80443fc974 100644 --- a/packages/megalodon/src/misskey/entities/createdNote.ts +++ b/packages/megalodon/src/misskey/entities/createdNote.ts @@ -1,7 +1,5 @@ -/// +import type { Note } from './note.js'; -namespace MisskeyEntity { - export type CreatedNote = { - createdNote: Note - } +export interface CreatedNote { + createdNote: Note } diff --git a/packages/megalodon/src/misskey/entities/emoji.ts b/packages/megalodon/src/misskey/entities/emoji.ts index 2bd4c8c730..a5ad9e9cbc 100644 --- a/packages/megalodon/src/misskey/entities/emoji.ts +++ b/packages/megalodon/src/misskey/entities/emoji.ts @@ -1,8 +1,6 @@ -namespace MisskeyEntity { - export type Emoji = { - name: string - url: string - aliases: Array - category: string - } +export interface Emoji { + name: string + url: string + aliases: Array + category: string } diff --git a/packages/megalodon/src/misskey/entities/favorite.ts b/packages/megalodon/src/misskey/entities/favorite.ts index 8ed7a54bfe..d02acbd288 100644 --- a/packages/megalodon/src/misskey/entities/favorite.ts +++ b/packages/megalodon/src/misskey/entities/favorite.ts @@ -1,10 +1,8 @@ -/// +import type { Note } from './note.js'; -namespace MisskeyEntity { - export type Favorite = { - id: string - createdAt: string - noteId: string - note: Note - } +export interface Favorite { + id: string + createdAt: string + noteId: string + note: Note } diff --git a/packages/megalodon/src/misskey/entities/field.ts b/packages/megalodon/src/misskey/entities/field.ts index 1e61178e56..1089cb4221 100644 --- a/packages/megalodon/src/misskey/entities/field.ts +++ b/packages/megalodon/src/misskey/entities/field.ts @@ -1,8 +1,6 @@ -namespace MisskeyEntity { - export type Field = { - name: string; - value: string; - verified?: string; - verified_at?: string; - }; +export interface Field { + name: string; + value: string; + verified?: string; + verified_at?: string; } diff --git a/packages/megalodon/src/misskey/entities/file.ts b/packages/megalodon/src/misskey/entities/file.ts index 3bb0272fda..e96e843235 100644 --- a/packages/megalodon/src/misskey/entities/file.ts +++ b/packages/megalodon/src/misskey/entities/file.ts @@ -1,20 +1,18 @@ -namespace MisskeyEntity { - export type File = { - id: string - createdAt: string - name: string - type: string - md5: string - size: number - isSensitive: boolean - properties: { - width: number - height: number - avgColor: string - } - url: string - comment?: string - blurhash?: string - thumbnailUrl: string - } +export interface File { + id: string + createdAt: string + name: string + type: string + md5: string + size: number + isSensitive: boolean + properties: { + width: number + height: number + avgColor: string + } + url: string + comment?: string + blurhash?: string + thumbnailUrl: string } diff --git a/packages/megalodon/src/misskey/entities/followRequest.ts b/packages/megalodon/src/misskey/entities/followRequest.ts index bd2777b2de..d1f559cfa1 100644 --- a/packages/megalodon/src/misskey/entities/followRequest.ts +++ b/packages/megalodon/src/misskey/entities/followRequest.ts @@ -1,9 +1,7 @@ -/// +import type { User } from './user.js'; -namespace MisskeyEntity { - export type FollowRequest = { - id: string - follower: User - followee: User - } +export interface FollowRequest { + id: string + follower: User + followee: User } diff --git a/packages/megalodon/src/misskey/entities/follower.ts b/packages/megalodon/src/misskey/entities/follower.ts index 70ef632e1d..60ff84f85e 100644 --- a/packages/megalodon/src/misskey/entities/follower.ts +++ b/packages/megalodon/src/misskey/entities/follower.ts @@ -1,11 +1,9 @@ -/// +import type { UserDetail } from './userDetail.js'; -namespace MisskeyEntity { - export type Follower = { - id: string - createdAt: string - followeeId: string - followerId: string - follower: UserDetail - } +export interface Follower { + id: string + createdAt: string + followeeId: string + followerId: string + follower: UserDetail } diff --git a/packages/megalodon/src/misskey/entities/following.ts b/packages/megalodon/src/misskey/entities/following.ts index 927a913545..099874d44b 100644 --- a/packages/megalodon/src/misskey/entities/following.ts +++ b/packages/megalodon/src/misskey/entities/following.ts @@ -1,11 +1,9 @@ -/// +import type { UserDetail } from './userDetail.js'; -namespace MisskeyEntity { - export type Following = { - id: string - createdAt: string - followeeId: string - followerId: string - followee: UserDetail - } +export interface Following { + id: string + createdAt: string + followeeId: string + followerId: string + followee: UserDetail } diff --git a/packages/megalodon/src/misskey/entities/hashtag.ts b/packages/megalodon/src/misskey/entities/hashtag.ts index 6a3fe43ad5..a8978f0f60 100644 --- a/packages/megalodon/src/misskey/entities/hashtag.ts +++ b/packages/megalodon/src/misskey/entities/hashtag.ts @@ -1,7 +1,5 @@ -namespace MisskeyEntity { - export type Hashtag = { - tag: string - chart: Array - usersCount: number - } +export interface Hashtag { + tag: string + chart: Array + usersCount: number } diff --git a/packages/megalodon/src/misskey/entities/list.ts b/packages/megalodon/src/misskey/entities/list.ts index 8167d29810..6112c157b3 100644 --- a/packages/megalodon/src/misskey/entities/list.ts +++ b/packages/megalodon/src/misskey/entities/list.ts @@ -1,8 +1,6 @@ -namespace MisskeyEntity { - export type List = { - id: string - createdAt: string - name: string - userIds: Array - } +export interface List { + id: string + createdAt: string + name: string + userIds: Array } diff --git a/packages/megalodon/src/misskey/entities/meta.ts b/packages/megalodon/src/misskey/entities/meta.ts index 73a0104bdd..b0feaa2aad 100644 --- a/packages/megalodon/src/misskey/entities/meta.ts +++ b/packages/megalodon/src/misskey/entities/meta.ts @@ -1,49 +1,47 @@ -/// +import type { Emoji } from './emoji.js'; -namespace MisskeyEntity { - export type Meta = { - maintainerName: string - maintainerEmail: string - name: string - version: string - uri: string - description: string - langs: Array - disableRegistration: boolean - disableLocalTimeline: boolean - bannerUrl: string - maxNoteTextLength: number - emojis: Array - policies: { - gtlAvailable: boolean - btlAvailable: boolean - ltlAvailable: boolean - canPublicNote: boolean - canImportNotes: boolean - canInvite: boolean - canManageCustomEmojis: boolean - canHideAds: boolean - driveCapacityMb: number - pinLimit: number - antennaLimit: number - wordMuteLimit: number - webhookLimit: number - clipLimit: number - noteEachClipsLimit: number - userListLimit: number - userEachUserListsLimit: number - rateLimitFactor: number - } - features: { - registration: boolean - emailRequiredForSignup: boolean - elasticsearch: boolean - hcaptcha: boolean - recaptcha: boolean - turnstile: boolean - objectStorage: boolean - serviceWorker: boolean - miauth: boolean - } - } +export interface Meta { + maintainerName: string + maintainerEmail: string + name: string + version: string + uri: string + description: string + langs: Array + disableRegistration: boolean + disableLocalTimeline: boolean + bannerUrl: string + maxNoteTextLength: number + emojis: Array + policies: { + gtlAvailable: boolean + btlAvailable: boolean + ltlAvailable: boolean + canPublicNote: boolean + canImportNotes: boolean + canInvite: boolean + canManageCustomEmojis: boolean + canHideAds: boolean + driveCapacityMb: number + pinLimit: number + antennaLimit: number + wordMuteLimit: number + webhookLimit: number + clipLimit: number + noteEachClipsLimit: number + userListLimit: number + userEachUserListsLimit: number + rateLimitFactor: number + } + features: { + registration: boolean + emailRequiredForSignup: boolean + elasticsearch: boolean + hcaptcha: boolean + recaptcha: boolean + turnstile: boolean + objectStorage: boolean + serviceWorker: boolean + miauth: boolean + } } diff --git a/packages/megalodon/src/misskey/entities/mute.ts b/packages/megalodon/src/misskey/entities/mute.ts index 3cd7ae4090..96c48efd31 100644 --- a/packages/megalodon/src/misskey/entities/mute.ts +++ b/packages/megalodon/src/misskey/entities/mute.ts @@ -1,10 +1,8 @@ -/// +import type { UserDetail } from './userDetail.js'; -namespace MisskeyEntity { - export type Mute = { - id: string - createdAt: string - muteeId: string - mutee: UserDetail - } +export interface Mute { + id: string + createdAt: string + muteeId: string + mutee: UserDetail } diff --git a/packages/megalodon/src/misskey/entities/note.ts b/packages/megalodon/src/misskey/entities/note.ts index a7b208b153..760548953a 100644 --- a/packages/megalodon/src/misskey/entities/note.ts +++ b/packages/megalodon/src/misskey/entities/note.ts @@ -1,36 +1,34 @@ -/// -/// -/// -/// +import type { User } from './user.js'; +import type { Emoji } from './emoji.js'; +import type { Poll } from './poll.js'; +import type { File } from './file.js'; -namespace MisskeyEntity { - export type Note = { - id: string - createdAt: string - updatedAt?: string | null - userId: string - user: User - text: string | null - cw: string | null - visibility: 'public' | 'home' | 'followers' | 'specified' - renoteCount: number - repliesCount: number - reactions: { [key: string]: number } - // This field includes only remote emojis - reactionEmojis: { [key: string]: string } - emojis: Array | { [key: string]: string } - fileIds: Array - files: Array - replyId: string | null - renoteId: string | null - uri?: string - url?: string - reply?: Note - renote?: Note - viaMobile?: boolean - tags?: Array - poll?: Poll - mentions?: Array - myReaction?: string - } +export interface Note { + id: string + createdAt: string + updatedAt?: string | null + userId: string + user: User + text: string | null + cw: string | null + visibility: 'public' | 'home' | 'followers' | 'specified' + renoteCount: number + repliesCount: number + reactions: { [key: string]: number } + // This field includes only remote emojis + reactionEmojis: { [key: string]: string } + emojis: Array | { [key: string]: string } + fileIds: Array + files: Array + replyId: string | null + renoteId: string | null + uri?: string + url?: string + reply?: Note + renote?: Note + viaMobile?: boolean + tags?: Array + poll?: Poll + mentions?: Array + myReaction?: string } diff --git a/packages/megalodon/src/misskey/entities/notification.ts b/packages/megalodon/src/misskey/entities/notification.ts index c331a1ec85..18386369df 100644 --- a/packages/megalodon/src/misskey/entities/notification.ts +++ b/packages/megalodon/src/misskey/entities/notification.ts @@ -1,17 +1,15 @@ -/// -/// +import type { User } from './user.js'; +import type { Note } from './note.js'; -namespace MisskeyEntity { - export type Notification = { - id: string - createdAt: string - // https://github.com/syuilo/misskey/blob/056942391aee135eb6c77aaa63f6ed5741d701a6/src/models/entities/notification.ts#L50-L62 - type: NotificationType - userId: string - user: User - note?: Note - reaction?: string - } - - export type NotificationType = string +export interface Notification { + id: string + createdAt: string + // https://github.com/syuilo/misskey/blob/056942391aee135eb6c77aaa63f6ed5741d701a6/src/models/entities/notification.ts#L50-L62 + type: NotificationType + userId: string + user: User + note?: Note + reaction?: string } + +export type NotificationType = string diff --git a/packages/megalodon/src/misskey/entities/poll.ts b/packages/megalodon/src/misskey/entities/poll.ts index a3f1d971a3..e3383f2e7a 100644 --- a/packages/megalodon/src/misskey/entities/poll.ts +++ b/packages/megalodon/src/misskey/entities/poll.ts @@ -1,13 +1,11 @@ -namespace MisskeyEntity { - export type Choice = { - text: string - votes: number - isVoted: boolean - } - - export type Poll = { - multiple: boolean - expiresAt: string - choices: Array - } +export interface Choice { + text: string + votes: number + isVoted: boolean +} + +export interface Poll { + multiple: boolean + expiresAt: string + choices: Array } diff --git a/packages/megalodon/src/misskey/entities/reaction.ts b/packages/megalodon/src/misskey/entities/reaction.ts index de959b2627..db46e2b07f 100644 --- a/packages/megalodon/src/misskey/entities/reaction.ts +++ b/packages/megalodon/src/misskey/entities/reaction.ts @@ -1,15 +1,13 @@ -/// -/// +import type { User } from './user.js'; +import type { Note } from './note.js'; -namespace MisskeyEntity { - export type Reaction = { - id: string - createdAt: string - user: User - type: string - } - - export type NoteReaction = Reaction & { - note: Note - } +export interface Reaction { + id: string + createdAt: string + user: User + type: string +} + +export interface NoteReaction extends Reaction { + note: Note } diff --git a/packages/megalodon/src/misskey/entities/relation.ts b/packages/megalodon/src/misskey/entities/relation.ts index a43dfbab4e..a213bf4372 100644 --- a/packages/megalodon/src/misskey/entities/relation.ts +++ b/packages/megalodon/src/misskey/entities/relation.ts @@ -1,15 +1,13 @@ -namespace MisskeyEntity { - export type Relation = { - id: string - isFollowing: boolean - hasPendingFollowRequestFromYou: boolean - hasPendingFollowRequestToYou: boolean - isFollowed: boolean - isBlocking: boolean - isBlocked: boolean - isMuted: boolean - isRenoteMuted: boolean - isInstanceMuted?: boolean - memo?: string | null - } +export interface Relation { + id: string + isFollowing: boolean + hasPendingFollowRequestFromYou: boolean + hasPendingFollowRequestToYou: boolean + isFollowed: boolean + isBlocking: boolean + isBlocked: boolean + isMuted: boolean + isRenoteMuted: boolean + isInstanceMuted?: boolean + memo?: string | null } diff --git a/packages/megalodon/src/misskey/entities/session.ts b/packages/megalodon/src/misskey/entities/session.ts index 47fe9cf826..6f2f787546 100644 --- a/packages/megalodon/src/misskey/entities/session.ts +++ b/packages/megalodon/src/misskey/entities/session.ts @@ -1,6 +1,4 @@ -namespace MisskeyEntity { - export type Session = { - token: string - url: string - } +export interface Session { + token: string + url: string } diff --git a/packages/megalodon/src/misskey/entities/stats.ts b/packages/megalodon/src/misskey/entities/stats.ts index 7f080efda9..5e9761f8ba 100644 --- a/packages/megalodon/src/misskey/entities/stats.ts +++ b/packages/megalodon/src/misskey/entities/stats.ts @@ -1,9 +1,7 @@ -namespace MisskeyEntity { - export type Stats = { - notesCount: number - originalNotesCount: number - usersCount: number - originalUsersCount: number - instances: number - } +export interface Stats { + notesCount: number + originalNotesCount: number + usersCount: number + originalUsersCount: number + instances: number } diff --git a/packages/megalodon/src/misskey/entities/user.ts b/packages/megalodon/src/misskey/entities/user.ts index e5e5592701..820b699d95 100644 --- a/packages/megalodon/src/misskey/entities/user.ts +++ b/packages/megalodon/src/misskey/entities/user.ts @@ -1,20 +1,18 @@ -/// +import type { Emoji } from './emoji.js'; -namespace MisskeyEntity { - export type User = { - id: string - name: string - username: string - createdAt?: string - description?: string - followingCount?: number - followersCount?: number - notesCount?: number - host: string | null - avatarUrl: string - uri?: string - bannerUrl?: string | null - avatarColor: string - emojis: Array | { [key: string]: string } - } +export interface User { + id: string + name: string + username: string + createdAt?: string + description?: string + followingCount?: number + followersCount?: number + notesCount?: number + host: string | null + avatarUrl: string + uri?: string + bannerUrl?: string | null + avatarColor: string + emojis: Array | { [key: string]: string } } diff --git a/packages/megalodon/src/misskey/entities/userDetail.ts b/packages/megalodon/src/misskey/entities/userDetail.ts index 0a59278605..5b00c528f1 100644 --- a/packages/megalodon/src/misskey/entities/userDetail.ts +++ b/packages/megalodon/src/misskey/entities/userDetail.ts @@ -1,34 +1,32 @@ -/// -/// +import type { Emoji } from './emoji.js'; +import type { Note } from './note.js'; -namespace MisskeyEntity { - export type UserDetail = { - id: string - name: string - username: string - host: string | null - avatarUrl: string - avatarColor: string - isAdmin: boolean - isModerator: boolean - isBot: boolean - isCat: boolean - speakAsCat: boolean - emojis: Array | { [key: string]: string } - createdAt: string - bannerUrl: string - uri: string - bannerColor: string - isLocked: boolean - isSilenced: boolean - isSuspended: boolean - description: string - followersCount: number - followingCount: number - notesCount: number - avatarId: string - bannerId: string - pinnedNoteIds?: Array - pinnedNotes?: Array - } +export interface UserDetail { + id: string + name: string + username: string + host: string | null + avatarUrl: string + avatarColor: string + isAdmin: boolean + isModerator: boolean + isBot: boolean + isCat: boolean + speakAsCat: boolean + emojis: Array | { [key: string]: string } + createdAt: string + bannerUrl: string + uri: string + bannerColor: string + isLocked: boolean + isSilenced: boolean + isSuspended: boolean + description: string + followersCount: number + followingCount: number + notesCount: number + avatarId: string + bannerId: string + pinnedNoteIds?: Array + pinnedNotes?: Array } diff --git a/packages/megalodon/src/misskey/entities/userkey.ts b/packages/megalodon/src/misskey/entities/userkey.ts index 5b66e95b82..3875ad4c47 100644 --- a/packages/megalodon/src/misskey/entities/userkey.ts +++ b/packages/megalodon/src/misskey/entities/userkey.ts @@ -1,8 +1,6 @@ -/// +import type { User } from './user.js'; -namespace MisskeyEntity { - export type UserKey = { - accessToken: string - user: User - } +export interface UserKey { + accessToken: string + user: User } diff --git a/packages/megalodon/src/misskey/entity.ts b/packages/megalodon/src/misskey/entity.ts index 8498517be9..150d06924b 100644 --- a/packages/megalodon/src/misskey/entity.ts +++ b/packages/megalodon/src/misskey/entity.ts @@ -1,26 +1,26 @@ -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// - -export default MisskeyEntity +export type * from './entities/announcement.js'; +export type * from './entities/app.js'; +export type * from './entities/blocking.js'; +export type * from './entities/createdNote.js'; +export type * from './entities/emoji.js'; +export type * from './entities/favorite.js'; +export type * from './entities/field.js'; +export type * from './entities/file.js'; +export type * from './entities/follower.js'; +export type * from './entities/following.js'; +export type * from './entities/followRequest.js'; +export type * from './entities/GetAll.js'; +export type * from './entities/hashtag.js'; +export type * from './entities/list.js'; +export type * from './entities/meta.js'; +export type * from './entities/mute.js'; +export type * from './entities/note.js'; +export type * from './entities/notification.js'; +export type * from './entities/poll.js'; +export type * from './entities/reaction.js'; +export type * from './entities/relation.js'; +export type * from './entities/session.js'; +export type * from './entities/stats.js'; +export type * from './entities/user.js'; +export type * from './entities/userDetail.js'; +export type * from './entities/userkey.js'; diff --git a/packages/megalodon/src/misskey/notification.ts b/packages/megalodon/src/misskey/notification.ts index 2909762c15..d081e2cd2b 100644 --- a/packages/megalodon/src/misskey/notification.ts +++ b/packages/megalodon/src/misskey/notification.ts @@ -1,16 +1,13 @@ -import MisskeyEntity from './entity' +import * as MisskeyEntity from './entity.js' -namespace MisskeyNotificationType { - export const Follow: MisskeyEntity.NotificationType = 'follow' - export const Mention: MisskeyEntity.NotificationType = 'mention' - export const Reply: MisskeyEntity.NotificationType = 'reply' - export const Renote: MisskeyEntity.NotificationType = 'renote' - export const Quote: MisskeyEntity.NotificationType = 'quote' - export const Reaction: MisskeyEntity.NotificationType = 'reaction' - export const PollVote: MisskeyEntity.NotificationType = 'pollVote' - export const ReceiveFollowRequest: MisskeyEntity.NotificationType = 'receiveFollowRequest' - export const FollowRequestAccepted: MisskeyEntity.NotificationType = 'followRequestAccepted' - export const GroupInvited: MisskeyEntity.NotificationType = 'groupInvited' -} +export const Follow: MisskeyEntity.NotificationType = 'follow' +export const Mention: MisskeyEntity.NotificationType = 'mention' +export const Reply: MisskeyEntity.NotificationType = 'reply' +export const Renote: MisskeyEntity.NotificationType = 'renote' +export const Quote: MisskeyEntity.NotificationType = 'quote' +export const Reaction: MisskeyEntity.NotificationType = 'reaction' +export const PollVote: MisskeyEntity.NotificationType = 'pollVote' +export const ReceiveFollowRequest: MisskeyEntity.NotificationType = 'receiveFollowRequest' +export const FollowRequestAccepted: MisskeyEntity.NotificationType = 'followRequestAccepted' +export const GroupInvited: MisskeyEntity.NotificationType = 'groupInvited' -export default MisskeyNotificationType diff --git a/packages/megalodon/src/oauth.ts b/packages/megalodon/src/oauth.ts index 3c3ceb9deb..bab94a0558 100644 --- a/packages/megalodon/src/oauth.ts +++ b/packages/megalodon/src/oauth.ts @@ -1,109 +1,101 @@ -/** - * OAuth - * Response data when oauth request. - **/ -namespace OAuth { - export type AppDataFromServer = { - id: string - name: string - website: string | null - redirect_uri: string - client_id: string - client_secret: string - } - - export type TokenDataFromServer = { - access_token: string - token_type: string - scope: string - created_at: number - expires_in: number | null - refresh_token: string | null - } - - export class AppData { - public url: string | null - public session_token: string | null - constructor( - public id: string, - public name: string, - public website: string | null, - public redirect_uri: string, - public client_id: string, - public client_secret: string - ) { - this.url = null - this.session_token = null - } - - /** - * Serialize raw application data from server - * @param raw from server - */ - static from(raw: AppDataFromServer) { - return new this(raw.id, raw.name, raw.website, raw.redirect_uri, raw.client_id, raw.client_secret) - } - - get redirectUri() { - return this.redirect_uri - } - get clientId() { - return this.client_id - } - get clientSecret() { - return this.client_secret - } - } - - export class TokenData { - public _scope: string - constructor( - public access_token: string, - public token_type: string, - scope: string, - public created_at: number, - public expires_in: number | null = null, - public refresh_token: string | null = null - ) { - this._scope = scope - } - - /** - * Serialize raw token data from server - * @param raw from server - */ - static from(raw: TokenDataFromServer) { - return new this(raw.access_token, raw.token_type, raw.scope, raw.created_at, raw.expires_in, raw.refresh_token) - } - - /** - * OAuth Aceess Token - */ - get accessToken() { - return this.access_token - } - get tokenType() { - return this.token_type - } - get scope() { - return this._scope - } - /** - * Application ID - */ - get createdAt() { - return this.created_at - } - get expiresIn() { - return this.expires_in - } - /** - * OAuth Refresh Token - */ - get refreshToken() { - return this.refresh_token - } - } +export interface AppDataFromServer { + id: string + name: string + website: string | null + redirect_uri: string + client_id: string + client_secret: string } -export default OAuth +export interface TokenDataFromServer { + access_token: string + token_type: string + scope: string + created_at: number + expires_in: number | null + refresh_token: string | null +} + +export class AppData { + public url: string | null + public session_token: string | null + constructor( + public id: string, + public name: string, + public website: string | null, + public redirect_uri: string, + public client_id: string, + public client_secret: string + ) { + this.url = null + this.session_token = null + } + + /** + * Serialize raw application data from server + * @param raw from server + */ + static from(raw: AppDataFromServer) { + return new this(raw.id, raw.name, raw.website, raw.redirect_uri, raw.client_id, raw.client_secret) + } + + get redirectUri() { + return this.redirect_uri + } + get clientId() { + return this.client_id + } + get clientSecret() { + return this.client_secret + } +} + +export class TokenData { + public _scope: string + constructor( + public access_token: string, + public token_type: string, + scope: string, + public created_at: number, + public expires_in: number | null = null, + public refresh_token: string | null = null + ) { + this._scope = scope + } + + /** + * Serialize raw token data from server + * @param raw from server + */ + static from(raw: TokenDataFromServer) { + return new this(raw.access_token, raw.token_type, raw.scope, raw.created_at, raw.expires_in, raw.refresh_token) + } + + /** + * OAuth Aceess Token + */ + get accessToken() { + return this.access_token + } + get tokenType() { + return this.token_type + } + get scope() { + return this._scope + } + /** + * Application ID + */ + get createdAt() { + return this.created_at + } + get expiresIn() { + return this.expires_in + } + /** + * OAuth Refresh Token + */ + get refreshToken() { + return this.refresh_token + } +} diff --git a/packages/megalodon/src/parser.ts b/packages/megalodon/src/parser.ts index 67abff797d..55efdf5646 100644 --- a/packages/megalodon/src/parser.ts +++ b/packages/megalodon/src/parser.ts @@ -1,5 +1,5 @@ import { EventEmitter } from 'events' -import Entity from './entity' +import * as Entity from './entity.js' /** * Parser diff --git a/packages/megalodon/src/response.ts b/packages/megalodon/src/response.ts index e275962034..0e1dacedf7 100644 --- a/packages/megalodon/src/response.ts +++ b/packages/megalodon/src/response.ts @@ -1,8 +1,6 @@ -type Response = { +export type Response = { data: T status: number statusText: string headers: any } - -export default Response diff --git a/packages/megalodon/test/integration/misskey.spec.ts b/packages/megalodon/test/integration/misskey.spec.ts index 84d85498d6..f4115eeb50 100644 --- a/packages/megalodon/test/integration/misskey.spec.ts +++ b/packages/megalodon/test/integration/misskey.spec.ts @@ -1,8 +1,15 @@ -import MisskeyEntity from '@/misskey/entity' -import MisskeyNotificationType from '@/misskey/notification' -import Misskey from '@/misskey' -import * as MegalodonNotificationType from '@/notification' -import axios, { AxiosHeaders, AxiosResponse, InternalAxiosRequestConfig } from 'axios' +import * as MisskeyEntity from '../../src/misskey/entity.js' +import * as MisskeyNotificationType from '../../src/misskey/notification.js' +import * as Misskey from '../../src/misskey.js' +import * as MegalodonNotificationType from '../../src/notification.js' +import * as Entity from '../../src/entity.js' +import axios, { + AxiosHeaders, + type AxiosResponse, + type InternalAxiosRequestConfig, + type CancelTokenSource +} from 'axios' +import { jest } from '@jest/globals'; jest.mock('axios') @@ -122,20 +129,19 @@ const groupInvited: MisskeyEntity.Notification = { type: MisskeyNotificationType.GroupInvited } -;(axios.CancelToken.source as any).mockImplementation(() => { +jest.spyOn(axios.CancelToken, 'source').mockImplementation(() => { return { token: { throwIfRequested: () => {}, - promise: { - then: () => {}, - catch: () => {} - } - } - } -}) + promise: new Promise(() => {}), + reason: undefined, + }, + cancel: () => {}, + } satisfies CancelTokenSource; +}); describe('getNotifications', () => { - const client = new Misskey('http://localhost', 'sample token') + const client = new Misskey.default('http://localhost', 'sample token') const cases: Array<{ event: MisskeyEntity.Notification; expected: Entity.NotificationType; title: string }> = [ { event: follow, @@ -195,7 +201,7 @@ describe('getNotifications', () => { headers: {}, config: config } - ;(axios.post as any).mockResolvedValue(mockResponse) + jest.spyOn(axios, 'post').mockResolvedValueOnce(mockResponse); const res = await client.getNotifications() expect(res.data[0].type).toEqual(c.expected) }) @@ -211,7 +217,7 @@ describe('getNotifications', () => { headers: {}, config: config } - ;(axios.post as any).mockResolvedValue(mockResponse) + jest.spyOn(axios, 'post').mockResolvedValueOnce(mockResponse); const res = await client.getNotifications() expect(res.data).toEqual([]) }) diff --git a/packages/megalodon/test/unit/misskey/api_client.spec.ts b/packages/megalodon/test/unit/misskey/api_client.spec.ts index 96e7122ea6..672f6325b6 100644 --- a/packages/megalodon/test/unit/misskey/api_client.spec.ts +++ b/packages/megalodon/test/unit/misskey/api_client.spec.ts @@ -1,8 +1,8 @@ -import MisskeyAPI from '@/misskey/api_client' -import MegalodonEntity from '@/entity' -import MisskeyEntity from '@/misskey/entity' -import * as MegalodonNotificationType from '@/notification' -import MisskeyNotificationType from '@/misskey/notification' +import * as MisskeyAPI from '../../../src/misskey/api_client.js' +import * as MegalodonEntity from '../../../src/entity.js' +import * as MisskeyEntity from '../../../src/misskey/entity.js' +import * as MegalodonNotificationType from '../../../src/notification.js' +import * as MisskeyNotificationType from '../../../src/misskey/notification.js' const user: MisskeyEntity.User = { id: '1', diff --git a/packages/megalodon/test/unit/parser.spec.ts b/packages/megalodon/test/unit/parser.spec.ts index 74264552d6..503776fd50 100644 --- a/packages/megalodon/test/unit/parser.spec.ts +++ b/packages/megalodon/test/unit/parser.spec.ts @@ -1,5 +1,6 @@ -import { Parser } from '@/parser' -import Entity from '@/entity' +import { Parser } from '../../src/parser.js' +import * as Entity from '../../src/entity.js' +import { jest } from '@jest/globals'; const account: Entity.Account = { id: '1', diff --git a/packages/megalodon/tsconfig.json b/packages/megalodon/tsconfig.json index bcf4bd59b1..bd6dede2e4 100644 --- a/packages/megalodon/tsconfig.json +++ b/packages/megalodon/tsconfig.json @@ -1,102 +1,20 @@ { + "$schema": "https://json.schemastore.org/tsconfig", + "extends": "../shared/tsconfig.node.json", "compilerOptions": { - /* Basic Options */ - "target": "ES2022", - /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */ - "module": "commonjs", - /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ - "lib": [ - "ES2022", - "dom" - ], - /* Specify library files to be included in the compilation. */ - // "allowJs": true, /* Allow javascript files to be compiled. */ - // "checkJs": true, /* Report errors in .js files. */ - // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ + "types": ["node", "jest"], "declaration": true, - /* Generates corresponding '.d.ts' file. */ "declarationMap": true, - /* Generates a sourcemap for each corresponding '.d.ts' file. */ - // "sourceMap": true, /* Generates corresponding '.map' file. */ - // "outFile": "./", /* Concatenate and emit output to single file. */ + "sourceMap": true, + "inlineSources": true, + "removeComments": false, "outDir": "./lib", - /* Redirect output structure to the directory. */ "rootDir": "./", - /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ - // "composite": true, /* Enable project compilation */ - "removeComments": true, - /* Do not emit comments to output. */ - // "noEmit": true, /* Do not emit outputs. */ - // "importHelpers": true, /* Import emit helpers from 'tslib'. */ - "downlevelIteration": false, - /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ - "isolatedModules": true, - /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ - "incremental": true, - /* Strict Type-Checking Options */ - "strict": true, - /* Enable all strict type-checking options. */ - "noImplicitAny": true, - /* Raise error on expressions and declarations with an implied 'any' type. */ - "strictNullChecks": true, - /* Enable strict null checks. */ - "strictFunctionTypes": true, - /* Enable strict checking of function types. */ - "strictPropertyInitialization": true, - /* Enable strict checking of property initialization in classes. */ - "noImplicitThis": true, - /* Raise error on 'this' expressions with an implied 'any' type. */ - "alwaysStrict": true, - /* Parse in strict mode and emit "use strict" for each source file. */ - - /* Additional Checks */ - "noUnusedLocals": true, - /* Report errors on unused locals. */ - "noUnusedParameters": true, - /* Report errors on unused parameters. */ - "noImplicitReturns": true, - /* Report error when not all code paths in function return a value. */ - "noFallthroughCasesInSwitch": true, - /* Report errors for fallthrough cases in switch statement. */ - "skipLibCheck": true, - /* Module Resolution Options */ - "moduleResolution": "node", - /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ - "baseUrl": "./", - /* Base directory to resolve non-absolute module names. */ - "paths": { - "@*": [ - "src*" - ], - "~*": [ - "./*" - ] - }, - /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ - // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ - // "typeRoots": [], /* List of folders to include type definitions from. */ - // "types": [], /* Type declaration files to be included in compilation. */ - // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ - "esModuleInterop": true, - /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ - // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ - - /* Source Map Options */ - // "sourceRoot": "./", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ - // "mapRoot": "./", /* Specify the location where debugger should locate map files instead of generated locations. */ - "inlineSourceMap": false, - /* Emit a single file with source maps instead of having a separate file. */ - "inlineSources": false, - /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ - - /* Experimental Options */ - "experimentalDecorators": true - /* Enables experimental support for ES7 decorators. */ - // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ }, "include": [ "./src", - "./test" + "./test", + "./jest.config.ts" ], "exclude": [ "node_modules",