-
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Move entities and repositories under the namespace
BREAKING CHANGE: You have to import `mastodon` to use any entity instead of importing single entity directly
- Loading branch information
Showing
118 changed files
with
124 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ | |
"serializers", | ||
"shortcode", | ||
"subprotocol", | ||
"subresource", | ||
"typedoc", | ||
"unassign", | ||
"unbookmark", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
import type { mastodon } from 'masto'; | ||
import { login } from 'masto'; | ||
|
||
const masto = await login({ | ||
url: 'https://example.com', | ||
accessToken: 'YOUR TOKEN', | ||
}); | ||
|
||
await masto.v1.statuses.create({ | ||
const s: mastodon.v1.Status = await masto.v1.statuses.create({ | ||
status: 'Hello from #mastojs!', | ||
visibility: 'public', | ||
}); | ||
|
||
console.log(s); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,8 @@ | ||
import { SemVer } from 'semver'; | ||
|
||
import { MastoClient } from './api'; | ||
import { InstanceRepository } from './api/v1/repositories'; | ||
import type { MastoConfigProps } from './config'; | ||
import { MastoConfig } from './config'; | ||
import { HttpNativeImpl } from './http'; | ||
import type { LogType } from './logger'; | ||
import { LoggerConsoleImpl } from './logger'; | ||
import { SerializerNativeImpl } from './serializers'; | ||
import type { Writable } from './utils/writable'; | ||
import { WsNativeImpl } from './ws'; | ||
|
||
export type LoginParams = Omit< | ||
MastoConfigProps, | ||
'streamingApiUrl' | 'version' | 'logLevel' | ||
> & { logLevel?: LogType }; | ||
|
||
export const login = async (params: LoginParams): Promise<MastoClient> => { | ||
const draft: Writable<MastoConfigProps> = { | ||
streamingApiUrl: '', | ||
...params, | ||
}; | ||
const serializer = new SerializerNativeImpl(); | ||
|
||
{ | ||
const config = new MastoConfig(draft, serializer); | ||
const http = new HttpNativeImpl(serializer, config); | ||
const instance = await new InstanceRepository(http, config).fetch(); | ||
draft.version = new SemVer(instance.version); | ||
draft.streamingApiUrl = instance.urls.streamingApi; | ||
} | ||
|
||
const config = new MastoConfig(draft, serializer); | ||
const logger = new LoggerConsoleImpl(config.getLogLevel()); | ||
const ws = new WsNativeImpl(config, serializer); | ||
const http = new HttpNativeImpl(serializer, config, logger); | ||
|
||
logger.debug('Masto.js initialised', config); | ||
|
||
return new MastoClient(http, ws, config); | ||
}; | ||
|
||
export * from './api'; | ||
export * from './decorators'; | ||
export * from './errors'; | ||
export * from './config'; | ||
export * from './http'; | ||
export * from './logger'; | ||
export * from './login'; | ||
export * as mastodon from './mastodon'; | ||
export * from './paginator'; | ||
export * from './serializers'; | ||
export * from './ws'; | ||
export * from './config'; | ||
export * from './paginator'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import type { RequestInit } from '@mastojs/ponyfills'; | ||
import { SemVer } from 'semver'; | ||
|
||
import type { MastoConfigProps } from './config'; | ||
import { MastoConfig } from './config'; | ||
import { HttpNativeImpl } from './http'; | ||
import type { LogType } from './logger'; | ||
import { LoggerConsoleImpl } from './logger'; | ||
import { Client } from './mastodon'; | ||
import { InstanceRepository } from './mastodon/v2/repositories'; | ||
import { SerializerNativeImpl } from './serializers'; | ||
import type { Writable } from './utils'; | ||
import { WsNativeImpl } from './ws'; | ||
|
||
export type LoginParams = { | ||
/** URL of your instance */ | ||
readonly url: string; | ||
/** Log level to print to your console */ | ||
readonly logLevel?: LogType; | ||
/** Access token of your account */ | ||
readonly accessToken?: string; | ||
/** Timeout in milliseconds */ | ||
readonly timeout?: number; | ||
readonly defaultRequestInit?: Omit<RequestInit, 'body' | 'method'>; | ||
readonly disableVersionCheck?: boolean; | ||
readonly disableDeprecatedWarning?: boolean; | ||
}; | ||
|
||
export const login = async (params: LoginParams): Promise<Client> => { | ||
const draft: Writable<MastoConfigProps> = { | ||
url: params.url, | ||
streamingApiUrl: '', | ||
logLevel: params.logLevel, | ||
accessToken: params.accessToken, | ||
timeout: params.timeout, | ||
defaultRequestInit: params.defaultRequestInit, | ||
disableVersionCheck: params.disableVersionCheck, | ||
disableDeprecatedWarning: params.disableDeprecatedWarning, | ||
}; | ||
const serializer = new SerializerNativeImpl(); | ||
|
||
{ | ||
const config = new MastoConfig(draft, serializer); | ||
const http = new HttpNativeImpl(serializer, config); | ||
const instance = await new InstanceRepository(http, config).fetch(); | ||
draft.version = new SemVer(instance.version); | ||
draft.streamingApiUrl = instance.configuration.urls.streamingApi; | ||
} | ||
|
||
const config = new MastoConfig(draft, serializer); | ||
const logger = new LoggerConsoleImpl(config.getLogLevel()); | ||
const ws = new WsNativeImpl(config, serializer); | ||
const http = new HttpNativeImpl(serializer, config, logger); | ||
|
||
logger.debug('Masto.js initialised', config); | ||
return new Client(http, ws, config); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export * as V1 from './v1'; | ||
export * as V2 from './v2'; | ||
export * as v1 from './v1'; | ||
export * as v2 from './v2'; | ||
export * from './repository'; | ||
export * from './client'; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
src/api/v2/entities/search.ts → src/mastodon/v2/entities/search.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
import type { V1 } from '../..'; | ||
import type { v1 } from '../..'; | ||
|
||
/** | ||
* Represents the results of a search. | ||
* @see https://docs.joinmastodon.org/entities/Search/ | ||
*/ | ||
export interface Search { | ||
/** Accounts which match the given query */ | ||
accounts: V1.Account[]; | ||
accounts: v1.Account[]; | ||
/** Statuses which match the given query */ | ||
statuses: V1.Status[]; | ||
statuses: v1.Status[]; | ||
/** Hashtags which match the given query */ | ||
hashtags: V1.Tag[]; | ||
hashtags: v1.Tag[]; | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters