2018-04-07 07:36:40 +00:00
|
|
|
export type obj = { [x: string]: any };
|
2019-09-26 19:58:28 +00:00
|
|
|
export type ApObject = IObject | string | (IObject | string)[];
|
2018-04-07 06:39:40 +00:00
|
|
|
|
|
|
|
export interface IObject {
|
2022-04-17 04:26:31 +00:00
|
|
|
'@context': string | string[] | obj | obj[];
|
2021-06-01 10:17:17 +00:00
|
|
|
type: string | string[];
|
2018-04-07 06:39:40 +00:00
|
|
|
id?: string;
|
|
|
|
summary?: string;
|
2018-04-07 21:55:26 +00:00
|
|
|
published?: string;
|
2019-09-26 19:58:28 +00:00
|
|
|
cc?: ApObject;
|
|
|
|
to?: ApObject;
|
|
|
|
attributedTo: ApObject;
|
2018-04-08 19:08:56 +00:00
|
|
|
attachment?: any[];
|
|
|
|
inReplyTo?: any;
|
2019-03-06 13:55:47 +00:00
|
|
|
replies?: ICollection;
|
2019-04-13 09:58:29 +00:00
|
|
|
content?: string;
|
2019-03-06 13:55:47 +00:00
|
|
|
name?: string;
|
|
|
|
startTime?: Date;
|
|
|
|
endTime?: Date;
|
2018-04-08 19:08:56 +00:00
|
|
|
icon?: any;
|
|
|
|
image?: any;
|
2020-04-11 09:27:58 +00:00
|
|
|
url?: ApObject;
|
2020-04-03 13:51:38 +00:00
|
|
|
href?: string;
|
|
|
|
tag?: IObject | IObject[];
|
2018-08-19 09:08:29 +00:00
|
|
|
sensitive?: boolean;
|
2018-04-07 06:39:40 +00:00
|
|
|
}
|
|
|
|
|
2019-06-28 09:54:10 +00:00
|
|
|
/**
|
|
|
|
* Get array of ActivityStreams Objects id
|
|
|
|
*/
|
2019-09-26 19:58:28 +00:00
|
|
|
export function getApIds(value: ApObject | undefined): string[] {
|
2019-06-28 09:54:10 +00:00
|
|
|
if (value == null) return [];
|
|
|
|
const array = Array.isArray(value) ? value : [value];
|
|
|
|
return array.map(x => getApId(x));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get first ActivityStreams Object id
|
|
|
|
*/
|
2019-09-26 19:58:28 +00:00
|
|
|
export function getOneApId(value: ApObject): string {
|
2019-06-28 09:54:10 +00:00
|
|
|
const firstOne = Array.isArray(value) ? value[0] : value;
|
|
|
|
return getApId(firstOne);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get ActivityStreams Object id
|
|
|
|
*/
|
|
|
|
export function getApId(value: string | IObject): string {
|
|
|
|
if (typeof value === 'string') return value;
|
|
|
|
if (typeof value.id === 'string') return value.id;
|
2022-04-17 04:14:29 +00:00
|
|
|
throw new Error('cannot detemine id');
|
2019-06-28 09:54:10 +00:00
|
|
|
}
|
|
|
|
|
2021-05-31 04:04:13 +00:00
|
|
|
/**
|
|
|
|
* Get ActivityStreams Object type
|
|
|
|
*/
|
|
|
|
export function getApType(value: IObject): string {
|
|
|
|
if (typeof value.type === 'string') return value.type;
|
|
|
|
if (Array.isArray(value.type) && typeof value.type[0] === 'string') return value.type[0];
|
2022-04-17 04:14:29 +00:00
|
|
|
throw new Error('cannot detect type');
|
2021-05-31 04:04:13 +00:00
|
|
|
}
|
|
|
|
|
2020-04-11 09:27:58 +00:00
|
|
|
export function getOneApHrefNullable(value: ApObject | undefined): string | undefined {
|
|
|
|
const firstOne = Array.isArray(value) ? value[0] : value;
|
|
|
|
return getApHrefNullable(firstOne);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getApHrefNullable(value: string | IObject | undefined): string | undefined {
|
|
|
|
if (typeof value === 'string') return value;
|
|
|
|
if (typeof value?.href === 'string') return value.href;
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
2018-04-07 07:14:35 +00:00
|
|
|
export interface IActivity extends IObject {
|
|
|
|
//type: 'Activity';
|
|
|
|
actor: IObject | string;
|
|
|
|
object: IObject | string;
|
|
|
|
target?: IObject | string;
|
2020-05-08 23:21:42 +00:00
|
|
|
/** LD-Signature */
|
|
|
|
signature?: {
|
|
|
|
type: string;
|
|
|
|
created: Date;
|
|
|
|
creator: string;
|
|
|
|
domain?: string;
|
|
|
|
nonce?: string;
|
|
|
|
signatureValue: string;
|
|
|
|
};
|
2018-04-07 07:14:35 +00:00
|
|
|
}
|
|
|
|
|
2018-04-07 06:39:40 +00:00
|
|
|
export interface ICollection extends IObject {
|
|
|
|
type: 'Collection';
|
|
|
|
totalItems: number;
|
2019-09-26 19:58:28 +00:00
|
|
|
items: ApObject;
|
2018-04-07 06:39:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface IOrderedCollection extends IObject {
|
|
|
|
type: 'OrderedCollection';
|
|
|
|
totalItems: number;
|
2019-09-26 19:58:28 +00:00
|
|
|
orderedItems: ApObject;
|
2018-04-07 06:39:40 +00:00
|
|
|
}
|
|
|
|
|
2020-01-29 16:38:05 +00:00
|
|
|
export const validPost = ['Note', 'Question', 'Article', 'Audio', 'Document', 'Image', 'Page', 'Video', 'Event'];
|
2019-06-28 09:54:10 +00:00
|
|
|
|
2021-05-31 04:04:13 +00:00
|
|
|
export const isPost = (object: IObject): object is IPost =>
|
|
|
|
validPost.includes(getApType(object));
|
|
|
|
|
2020-01-29 16:38:05 +00:00
|
|
|
export interface IPost extends IObject {
|
|
|
|
type: 'Note' | 'Question' | 'Article' | 'Audio' | 'Document' | 'Image' | 'Page' | 'Video' | 'Event';
|
2022-06-10 05:31:58 +00:00
|
|
|
source?: {
|
|
|
|
content: string;
|
|
|
|
mediaType: string;
|
|
|
|
};
|
2019-04-13 09:58:29 +00:00
|
|
|
_misskey_quote?: string;
|
2019-12-14 18:37:54 +00:00
|
|
|
quoteUrl?: string;
|
2019-10-28 21:01:14 +00:00
|
|
|
_misskey_talk: boolean;
|
2018-04-07 21:55:26 +00:00
|
|
|
}
|
|
|
|
|
2019-03-07 12:19:32 +00:00
|
|
|
export interface IQuestion extends IObject {
|
|
|
|
type: 'Note' | 'Question';
|
2022-06-10 05:31:58 +00:00
|
|
|
source?: {
|
|
|
|
content: string;
|
|
|
|
mediaType: string;
|
|
|
|
};
|
2019-04-13 09:58:29 +00:00
|
|
|
_misskey_quote?: string;
|
2019-12-14 18:37:54 +00:00
|
|
|
quoteUrl?: string;
|
2019-03-07 12:19:32 +00:00
|
|
|
oneOf?: IQuestionChoice[];
|
|
|
|
anyOf?: IQuestionChoice[];
|
|
|
|
endTime?: Date;
|
2019-07-19 18:20:06 +00:00
|
|
|
closed?: Date;
|
2019-03-07 12:19:32 +00:00
|
|
|
}
|
|
|
|
|
2019-06-28 09:54:10 +00:00
|
|
|
export const isQuestion = (object: IObject): object is IQuestion =>
|
2021-05-31 04:04:13 +00:00
|
|
|
getApType(object) === 'Note' || getApType(object) === 'Question';
|
2019-06-28 09:54:10 +00:00
|
|
|
|
2019-03-07 12:19:32 +00:00
|
|
|
interface IQuestionChoice {
|
|
|
|
name?: string;
|
|
|
|
replies?: ICollection;
|
|
|
|
_misskey_votes?: number;
|
|
|
|
}
|
2020-07-10 21:19:49 +00:00
|
|
|
export interface ITombstone extends IObject {
|
|
|
|
type: 'Tombstone';
|
|
|
|
formerType?: string;
|
|
|
|
deleted?: Date;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const isTombstone = (object: IObject): object is ITombstone =>
|
2021-05-31 04:04:13 +00:00
|
|
|
getApType(object) === 'Tombstone';
|
2019-03-07 12:19:32 +00:00
|
|
|
|
2020-05-08 23:25:23 +00:00
|
|
|
export const validActor = ['Person', 'Service', 'Group', 'Organization', 'Application'];
|
2019-04-10 18:09:12 +00:00
|
|
|
|
2021-07-10 14:14:57 +00:00
|
|
|
export const isActor = (object: IObject): object is IActor =>
|
2021-05-31 04:04:13 +00:00
|
|
|
validActor.includes(getApType(object));
|
|
|
|
|
2021-07-10 14:14:57 +00:00
|
|
|
export interface IActor extends IObject {
|
2020-05-08 23:25:23 +00:00
|
|
|
type: 'Person' | 'Service' | 'Organization' | 'Group' | 'Application';
|
2019-10-28 11:34:01 +00:00
|
|
|
name?: string;
|
|
|
|
preferredUsername?: string;
|
|
|
|
manuallyApprovesFollowers?: boolean;
|
2020-12-11 12:16:20 +00:00
|
|
|
discoverable?: boolean;
|
2021-07-10 14:14:57 +00:00
|
|
|
inbox: string;
|
2019-10-28 11:34:01 +00:00
|
|
|
sharedInbox?: string; // 後方互換性のため
|
2021-07-10 14:14:57 +00:00
|
|
|
publicKey?: {
|
2019-10-28 11:34:01 +00:00
|
|
|
id: string;
|
|
|
|
publicKeyPem: string;
|
|
|
|
};
|
|
|
|
followers?: string | ICollection | IOrderedCollection;
|
|
|
|
following?: string | ICollection | IOrderedCollection;
|
|
|
|
featured?: string | IOrderedCollection;
|
2021-07-10 14:14:57 +00:00
|
|
|
outbox: string | IOrderedCollection;
|
2019-10-28 11:34:01 +00:00
|
|
|
endpoints?: {
|
|
|
|
sharedInbox?: string;
|
|
|
|
};
|
2020-06-21 05:09:01 +00:00
|
|
|
'vcard:bday'?: string;
|
|
|
|
'vcard:Address'?: string;
|
2018-04-08 19:08:56 +00:00
|
|
|
}
|
|
|
|
|
2018-04-07 06:39:40 +00:00
|
|
|
export const isCollection = (object: IObject): object is ICollection =>
|
2021-05-31 04:04:13 +00:00
|
|
|
getApType(object) === 'Collection';
|
2018-04-07 06:39:40 +00:00
|
|
|
|
|
|
|
export const isOrderedCollection = (object: IObject): object is IOrderedCollection =>
|
2021-05-31 04:04:13 +00:00
|
|
|
getApType(object) === 'OrderedCollection';
|
2018-04-07 06:39:40 +00:00
|
|
|
|
|
|
|
export const isCollectionOrOrderedCollection = (object: IObject): object is ICollection | IOrderedCollection =>
|
|
|
|
isCollection(object) || isOrderedCollection(object);
|
2018-04-07 07:14:35 +00:00
|
|
|
|
2020-04-03 13:51:38 +00:00
|
|
|
export interface IApPropertyValue extends IObject {
|
|
|
|
type: 'PropertyValue';
|
|
|
|
identifier: IApPropertyValue;
|
|
|
|
name: string;
|
|
|
|
value: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const isPropertyValue = (object: IObject): object is IApPropertyValue =>
|
|
|
|
object &&
|
2021-05-31 04:04:13 +00:00
|
|
|
getApType(object) === 'PropertyValue' &&
|
2020-04-03 13:51:38 +00:00
|
|
|
typeof object.name === 'string' &&
|
|
|
|
typeof (object as any).value === 'string';
|
|
|
|
|
|
|
|
export interface IApMention extends IObject {
|
|
|
|
type: 'Mention';
|
|
|
|
href: string;
|
|
|
|
}
|
|
|
|
|
2022-06-24 10:44:22 +00:00
|
|
|
export const isMention = (object: IObject): object is IApMention =>
|
2021-05-31 04:04:13 +00:00
|
|
|
getApType(object) === 'Mention' &&
|
2020-04-03 13:51:38 +00:00
|
|
|
typeof object.href === 'string';
|
|
|
|
|
|
|
|
export interface IApHashtag extends IObject {
|
|
|
|
type: 'Hashtag';
|
|
|
|
name: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const isHashtag = (object: IObject): object is IApHashtag =>
|
2021-05-31 04:04:13 +00:00
|
|
|
getApType(object) === 'Hashtag' &&
|
2020-04-03 13:51:38 +00:00
|
|
|
typeof object.name === 'string';
|
|
|
|
|
|
|
|
export interface IApEmoji extends IObject {
|
|
|
|
type: 'Emoji';
|
|
|
|
updated: Date;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const isEmoji = (object: IObject): object is IApEmoji =>
|
2021-05-31 04:04:13 +00:00
|
|
|
getApType(object) === 'Emoji' && !Array.isArray(object.icon) && object.icon.url != null;
|
2020-04-03 13:51:38 +00:00
|
|
|
|
2018-04-07 07:14:35 +00:00
|
|
|
export interface ICreate extends IActivity {
|
|
|
|
type: 'Create';
|
|
|
|
}
|
|
|
|
|
2018-04-07 07:36:40 +00:00
|
|
|
export interface IDelete extends IActivity {
|
|
|
|
type: 'Delete';
|
|
|
|
}
|
|
|
|
|
2019-03-07 12:19:32 +00:00
|
|
|
export interface IUpdate extends IActivity {
|
|
|
|
type: 'Update';
|
|
|
|
}
|
|
|
|
|
2019-12-14 18:37:19 +00:00
|
|
|
export interface IRead extends IActivity {
|
|
|
|
type: 'Read';
|
|
|
|
}
|
|
|
|
|
2018-04-07 07:14:35 +00:00
|
|
|
export interface IUndo extends IActivity {
|
|
|
|
type: 'Undo';
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface IFollow extends IActivity {
|
|
|
|
type: 'Follow';
|
|
|
|
}
|
2018-04-07 07:36:40 +00:00
|
|
|
|
|
|
|
export interface IAccept extends IActivity {
|
|
|
|
type: 'Accept';
|
|
|
|
}
|
|
|
|
|
2018-05-31 15:42:37 +00:00
|
|
|
export interface IReject extends IActivity {
|
|
|
|
type: 'Reject';
|
|
|
|
}
|
|
|
|
|
2018-10-02 07:27:36 +00:00
|
|
|
export interface IAdd extends IActivity {
|
|
|
|
type: 'Add';
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface IRemove extends IActivity {
|
|
|
|
type: 'Remove';
|
|
|
|
}
|
|
|
|
|
2018-04-07 08:05:14 +00:00
|
|
|
export interface ILike extends IActivity {
|
2020-02-07 12:37:24 +00:00
|
|
|
type: 'Like' | 'EmojiReaction' | 'EmojiReact';
|
2019-04-13 09:58:29 +00:00
|
|
|
_misskey_reaction?: string;
|
2018-04-07 08:05:14 +00:00
|
|
|
}
|
|
|
|
|
2018-04-07 21:55:26 +00:00
|
|
|
export interface IAnnounce extends IActivity {
|
|
|
|
type: 'Announce';
|
|
|
|
}
|
|
|
|
|
2018-10-29 11:32:42 +00:00
|
|
|
export interface IBlock extends IActivity {
|
|
|
|
type: 'Block';
|
|
|
|
}
|
|
|
|
|
2020-05-08 23:25:23 +00:00
|
|
|
export interface IFlag extends IActivity {
|
|
|
|
type: 'Flag';
|
|
|
|
}
|
|
|
|
|
2021-05-31 04:04:13 +00:00
|
|
|
export const isCreate = (object: IObject): object is ICreate => getApType(object) === 'Create';
|
|
|
|
export const isDelete = (object: IObject): object is IDelete => getApType(object) === 'Delete';
|
|
|
|
export const isUpdate = (object: IObject): object is IUpdate => getApType(object) === 'Update';
|
|
|
|
export const isRead = (object: IObject): object is IRead => getApType(object) === 'Read';
|
|
|
|
export const isUndo = (object: IObject): object is IUndo => getApType(object) === 'Undo';
|
|
|
|
export const isFollow = (object: IObject): object is IFollow => getApType(object) === 'Follow';
|
|
|
|
export const isAccept = (object: IObject): object is IAccept => getApType(object) === 'Accept';
|
|
|
|
export const isReject = (object: IObject): object is IReject => getApType(object) === 'Reject';
|
|
|
|
export const isAdd = (object: IObject): object is IAdd => getApType(object) === 'Add';
|
|
|
|
export const isRemove = (object: IObject): object is IRemove => getApType(object) === 'Remove';
|
|
|
|
export const isLike = (object: IObject): object is ILike => getApType(object) === 'Like' || getApType(object) === 'EmojiReaction' || getApType(object) === 'EmojiReact';
|
|
|
|
export const isAnnounce = (object: IObject): object is IAnnounce => getApType(object) === 'Announce';
|
|
|
|
export const isBlock = (object: IObject): object is IBlock => getApType(object) === 'Block';
|
|
|
|
export const isFlag = (object: IObject): object is IFlag => getApType(object) === 'Flag';
|