diff --git a/api/commits/project/pageId.ts b/api/commits/project/pageId.ts new file mode 100644 index 0000000..aba1d7b --- /dev/null +++ b/api/commits/project/pageId.ts @@ -0,0 +1,114 @@ +import type { + CommitId, + LineId, + PageId, + StringLc, + UnixTime, + UserId, +} from "../../../base.ts"; +import type { + ChangeLine, + CharsCountChange, + DeleteChange, + DescriptionsChange, + FilesChange, + HelpFeelsChange, + ImageChange, + InfoboxDefinitionChange, + InsertChange, + LinesCountChange, + PinChange, +} from "../../../change.ts"; + +/** the response type of /api/commits/:projectname/:pageid */ +export interface CommitsResponse { + /** 指定したページのcommits */ + commits: Commit[]; +} + +/** Scrapboxのページの編集commit */ +export interface Commit { + id: CommitId; + + /** 一つ前のcommitのID + * + * 存在しないときは`null`になる + */ + parentId: CommitId | null; + + pageId: PageId; + + /** commitの作成者 */ + userId: UserId; + + /** commitの作成日時 */ + created: UnixTime; + + /** 変更内容 */ + changes: Change[]; + + /** 詳細不明 */ + kind: "page"; +} +/** ページの変更内容 */ +export type Change = + | InsertChange + | UpdateChange + | DeleteChange + | LinksChange + | ProjectLinksChange + | IconsChange + | DescriptionsChange + | ImageChange + | FilesChange + | HelpFeelsChange + | InfoboxDefinitionChange + | TitleChange + | LinesCountChange + | CharsCountChange + | PinChange; + +/** 既存の行を書き換える変更 */ +export interface UpdateChange { + /** 書き換える行のID */ + _update: LineId; + + /** 行の変更内容 */ + lines: ChangeLine; +} + +/** ページ中のリンクが変更されると発生する */ +export interface LinksChange { + /** 新しいリンク */ + links: string[]; + + /** 新しいリンク */ + linksLc: StringLc[]; +} + +/** ページ中のproject linksが変更されると発生する */ +export interface ProjectLinksChange { + /** 新しいリンク */ + projectLinks: string[]; + + /** 新しいリンク */ + projectLinksLc: StringLc[]; +} + +/** ページ中のiconsが変更されると発生する */ +export interface IconsChange { + /** 新しいicons */ + icons: string[]; + + /** 新しいicons */ + iconsLc: StringLc[]; +} + +/** ページのタイトルが変更されると発生する */ +export interface TitleChange { + /** 新しいタイトル */ + title: string; + + /** 新しいタイトル */ + titleLc: StringLc; +} diff --git a/api/embed-text/twitter.ts b/api/embed-text/twitter.ts new file mode 100644 index 0000000..971876d --- /dev/null +++ b/api/embed-text/twitter.ts @@ -0,0 +1,11 @@ +/** the response type of /api/embed-text/twitter */ +export interface TweetInfo { + /** Tweet本文 */ + description?: string; + + /** Tweet投稿者の表示名 */ + screenName: string; + + /** Tweetに添付された画像 */ + images: string[]; +} diff --git a/api/page-data/export/project.ts b/api/page-data/export/project.ts new file mode 100644 index 0000000..a002530 --- /dev/null +++ b/api/page-data/export/project.ts @@ -0,0 +1,35 @@ +import type { BaseLine, UnixTime } from "../../../base.ts"; +import type { Page, UserInfo } from "../../pages/project/title.ts"; + +/** exportしたときのページデータ */ +export interface ExportedPage + extends Pick { + /** ページ本文 + * + * `hasMetadata === true`のときは行のmetadataが入る + * それ以外の場合は行のテキストが入る + */ + lines: hasMetadata extends true ? Omit[] : string[]; +} + +/** JSON data exported from https://scrapbox.io/api/page-data/export/:projectname.json */ +export interface ExportedData { + /** project's name */ + name: string; + + /** project's display name */ + displayName: string; + + /** このデータを生成した日時 (UNIX時刻) */ + exported: UnixTime; + + /** project members */ + users: UserForExport[]; + + /** exported pages */ + pages: ExportedPage[]; +} + +/** user infomation included in exported data */ +export interface UserForExport + extends Pick {} diff --git a/api/page-data/import/project.ts b/api/page-data/import/project.ts new file mode 100644 index 0000000..7da5ed5 --- /dev/null +++ b/api/page-data/import/project.ts @@ -0,0 +1,47 @@ +import type { UnixTime } from "../../../base.ts"; + +/** JSON data for importing by https://scrapbox.io/api/page-data/import/:projectname.json */ +export interface ImportedData { + /** pages importing to a project */ + pages: hasMetadata extends true ? ImportedPage[] : ImportedLightPage[]; +} + +/** メタデータ無しインポート用ページデータ */ +export interface ImportedLightPage { + /** page's title + * + * `title` should be equal to `lines[0]` + */ + title: string; + + /** page's text + * + * `lines[0]` should be equal to `title` + */ + lines: string[]; +} +/** インポート用メタデータ付き行データ */ +export interface ImportedLine { + /** line text */ + text: string; + + /** 行の最終更新日時 (UNIX時刻) */ + updated?: UnixTime; + + /** 行の最終作成日時 (UNIX時刻) */ + created?: UnixTime; +} +/** メタデータ付きインポート用ページデータ */ +export interface ImportedPage { + /** page's title + * + * `title` should be equal to `lines[0].text` + */ + title: string; + + /** page's line data + * + * `lines[0].text` should be equal to `title` + */ + lines: ImportedLine[]; +} diff --git a/api/page-snapshots/project/pageId.ts b/api/page-snapshots/project/pageId.ts new file mode 100644 index 0000000..345c9af --- /dev/null +++ b/api/page-snapshots/project/pageId.ts @@ -0,0 +1,14 @@ +import type { PageId, UnixTime } from "../../../base.ts"; + +/** the response type of /api/page-snapshots/:projectname/:pageid */ +export interface PageSnapshotList { + pageId: PageId; + + /** 作成されているsnapshotsのtimestamp idのリスト */ + timestamps: SnapshotTimestamp[]; +} + +export interface SnapshotTimestamp { + id: string; + created: UnixTime; +} diff --git a/api/page-snapshots/project/pageId/timestampId.ts b/api/page-snapshots/project/pageId/timestampId.ts new file mode 100644 index 0000000..0648013 --- /dev/null +++ b/api/page-snapshots/project/pageId/timestampId.ts @@ -0,0 +1,26 @@ +import type { BaseLine, BasePage, UnixTime } from "../../../../base.ts"; +import type { User } from "../../../pages/project/title.ts"; + +/** the response type of /api/page-snapshots/:projectname/:pageid/:timestampid */ +export interface PageSnapshotResult { + page: PageWithSnapshot; + + snapshot: Snapshot; +} + +export interface PageWithSnapshot extends BasePage { + user: Pick; + lastupdateUser: Pick | null; +} + +/** a page snapshot */ +export interface Snapshot { + /** snapshotを撮ったときのページタイトル */ + title: string; + + /** snapshotの作成日時 */ + created: UnixTime; + + /** snapshotしたページ本文 */ + lines: BaseLine[]; +} diff --git a/api/pages/project.ts b/api/pages/project.ts new file mode 100644 index 0000000..cf850b1 --- /dev/null +++ b/api/pages/project.ts @@ -0,0 +1,19 @@ +import type { BasePage } from "../../base.ts"; + +/** the response type of https://scrpabox.io/api/pages/:projectname */ +export interface PageList { + /** data取得先のproject名 */ + projectName: string; + + /** parameterに渡したskipと同じ */ + skip: number; + + /** parameterに渡したlimitと同じ */ + limit: number; + + /** projectの全ページ数 (中身のないページを除く) */ + count: number; + + /** 取得できたページ情報 */ + pages: BasePage[]; +} diff --git a/api/pages/project/search/files.ts b/api/pages/project/search/files.ts new file mode 100644 index 0000000..93880bd --- /dev/null +++ b/api/pages/project/search/files.ts @@ -0,0 +1,13 @@ +import type { FoundPage, SearchResult } from "./query.ts"; + +/** the response type of /api/pages/:projectname/search/files */ +export interface FileSearchResult + extends Omit { + /** 見つかったページ */ + pages: FoundPageByFile[]; +} + +/** /api/pages/:projectname/search/files で見つかったページ */ +export interface FoundPageByFile extends FoundPage { + file: string; +} diff --git a/api/pages/project/search/query.ts b/api/pages/project/search/query.ts new file mode 100644 index 0000000..d8d2a70 --- /dev/null +++ b/api/pages/project/search/query.ts @@ -0,0 +1,62 @@ +import type { PageId } from "../../../../base.ts"; + +/** the response type of /api/pages/:projectname/search/query */ +export interface SearchResult { + /** 検索したprojectの名前 */ + projectName: string; + + /** 検索文字列 */ + searchQuery: string; + + /** 検索語句 */ + query: SearchQuery; + + /** 検索件数の上限 */ + limit: number; + + /** 検索件数 */ + count: number; + + /** 検索文字列と完全一致するタイトルが見つかったら`true` */ + existsExactTitleMatch: boolean; + + field: "title" | "helpfeels" | "lines"; + + /** 全文検索エンジンの名前 */ + backend: string; + + /** 見つかったページ */ + pages: FoundPage[]; +} + +/** /api/pages/:projectname/search/query で見つかったページ */ +export interface FoundPage { + id: PageId; + + /** page title */ + title: string; + + /** page thumbnail + * + * 無いときは空文字が入る + */ + image: string; + + /** 検索語句の中で、このページに含まれている語句 */ + words: string[]; + + /** 検索語句に一致した行 + * + * タイトル行のみが一致した場合は、検索語句の有無にかかわらずその次の行のみが入る + */ + lines: string[]; +} + +/** 検索クエリ */ +export interface SearchQuery { + /** AND検索に使う語句 */ + words: string[]; + + /** NOT検索に使う語句 */ + excludes: string[]; +} diff --git a/api/pages/project/search/titles.ts b/api/pages/project/search/titles.ts new file mode 100644 index 0000000..d11fb41 --- /dev/null +++ b/api/pages/project/search/titles.ts @@ -0,0 +1,11 @@ +import type { BasePage } from "../../../../base.ts"; + +/** the response type of https://scrapbox.io/api/pages/:projectname/search/titles */ +export interface SearchedTitle + extends Pick { + /** thumbnail URL */ + image?: string; + + /** ページ内のリンク */ + links: string[]; +} diff --git a/api/pages/project/search/watch-list.ts b/api/pages/project/search/watch-list.ts new file mode 100644 index 0000000..8c012fe --- /dev/null +++ b/api/pages/project/search/watch-list.ts @@ -0,0 +1,31 @@ +import type { ProjectId } from "../../../../base.ts"; +import type { SearchQuery } from "./query.ts"; + +/** the response type of /api/projects/search/query and /api/projects/search/watch-list */ +export interface ProjectSearchResult { + /** 検索文字列 */ + searchQuery: string; + + /** 検索語句 */ + query: SearchQuery; + + /** 見つかったprojects */ + projects: FoundProject[]; +} + +/** /api/projects/search/query や /api/projects/search/watch-list で見つかったproject */ +export interface FoundProject { + _id: ProjectId; + + /** project name */ + name: string; + + /** projectの表示名 */ + displayName: string; + + /** project favicon + * + * 無いときは`null`が入るかproperty自体が存在しない + */ + image?: string | null; +} diff --git a/api/pages/project/title.ts b/api/pages/project/title.ts new file mode 100644 index 0000000..090b744 --- /dev/null +++ b/api/pages/project/title.ts @@ -0,0 +1,170 @@ +import type { + BaseLine, + BasePage, + StringLc, + UnixTime, + UserId, +} from "../../../base.ts"; +import type { SearchQuery } from "./search/query.ts"; + +/** user information */ +export interface User { + id: UserId; + + /** user name */ + name: string; + + /** user display name */ + displayName: string; + + /** profile image URL */ + photo: string; +} + +/** user detailed information */ +export interface UserInfo extends User { + /** user e-mail */ + email: string; + + /** whether the user is a pro user or not */ + pro: boolean; + + /** login provider */ + provider: "google" | "microsoft" | "email"; + + /** creation time of the account */ + created: UnixTime; + + /** update time of the account */ + updated: UnixTime; +} + +/** page information */ +export interface Page extends BasePage { + /** APIを叩いたuserの最終アクセス日時。 + * + * おそらくこの値を元にテロメアの未読/既読の判別をしている + */ + lastAccessed: UnixTime | null; + + /** 生成されたPage historyの数 */ + snapshotCount: number; + + /** 空リンクだと`false` */ + persistent: boolean; + + /** ページの行情報 */ + lines: BaseLine[]; + + /** ページ内のリンク */ + links: string[]; + + /** ページ内の外部プロジェクトリンク */ + projectLinks: string[]; + + /** ページ内のアイコン */ + icons: string[]; + + /** ページ内に含まれる、scrapbox.ioにアップロードしたファイルのfile id */ + files: string[]; + + infoboxDefinition: string[]; + + infoboxResult: InfoboxResult[]; + + infoboxDisableLinks: string[]; + + /** 関連ページリスト */ + relatedPages: RelatedPages; + + /** ページを作成したユーザー */ + user: User; + + /** 最後にページを更新したユーザー */ + lastUpdateUser: User; + + /** ページを編集したユーザーのうち、`user`以外の人 */ + collaborators: User[]; +} + +export interface RelatedPages { + /** 1 hop links */ + links1hop: RelatedPage[]; + + /** 2 hop links */ + links2hop: RelatedPage[]; + + /** external links */ + projectLinks1hop: ProjectRelatedPage[]; + + /** このページを参照しているページorアイコンがあればtrue */ + hasBackLinksOrIcons: boolean; + + /** 2 hop searchのquery */ + search: string; + + /** 全文検索エンジンの名前 */ + searchBackend: string; +} + +export interface InfoboxResult { + title: string; + + infobox: Record; + + hallucination: boolean; + + truncated: boolean; +} + +/** 関連ページのメタデータ */ +export interface RelatedPage extends + Pick< + BasePage, + | "id" + | "title" + | "image" + | "descriptions" + | "linked" + | "pageRank" + | "created" + | "updated" + | "accessed" + > { + /** page title */ + titleLc: StringLc; + + /** + * links1hopの場合:ページ内の全てのリンク + * + * links2hopの場合:ページ内の全てのリンクのうち、`Page.links`に含まれるリンク + */ + linksLc: StringLc[]; + + infoboxResult: InfoboxResult[]; + + infoboxDisableLinks: string[]; + + search?: SearchQuery; +} + +/** 外部プロジェクトの関連ページ */ +export interface ProjectRelatedPage extends + Pick< + BasePage, + | "id" + | "title" + | "image" + | "descriptions" + | "linked" + | "updated" + | "accessed" + > { + /** page title */ + titleLc: StringLc; + + created: number | null; + + /** project name */ + projectName: string; +} diff --git a/api/project-backup/project/backupId.ts b/api/project-backup/project/backupId.ts new file mode 100644 index 0000000..6fcc62d --- /dev/null +++ b/api/project-backup/project/backupId.ts @@ -0,0 +1,27 @@ +import type { BaseLine, StringLc, UnixTime } from "../../../base.ts"; +import type { Page } from "../../pages/project/title.ts"; + +/** backupされるページデータ */ +export interface BackupedPage + extends Pick { + /** ページ本文 */ + lines: Pick[]; + + /** ページに含まれているリンク*/ + linksLc: StringLc[]; +} + +/** project backup data */ +export interface BackupData { + /** project's name */ + name: string; + + /** project's display name */ + displayName: string; + + /** このデータを生成した日時 (UNIX時刻) */ + exported: UnixTime; + + /** backuped pages */ + pages: BackupedPage[]; +} diff --git a/api/project-backup/project/list.ts b/api/project-backup/project/list.ts new file mode 100644 index 0000000..e69de29 diff --git a/api/projects.ts b/api/projects.ts new file mode 100644 index 0000000..7459b5e --- /dev/null +++ b/api/projects.ts @@ -0,0 +1,6 @@ +import type { Project } from "./projects/project.ts"; + +/** the response type of /api/projects */ +export interface ProjectResponse { + projects: Project[]; +} diff --git a/api/projects/project.ts b/api/projects/project.ts new file mode 100644 index 0000000..04d961c --- /dev/null +++ b/api/projects/project.ts @@ -0,0 +1,76 @@ +import type { ProjectId, UnixTime, UserId } from "../../base.ts"; +import type { UserInfo } from "../pages/project/title.ts"; + +/** project information */ +export interface Project { + id: ProjectId; + + name: string; + + displayName: string; + + publicVisible: boolean; + + loginStrategies: string[]; + + /** planの種類 + * + * public projectの場合は`null`になる + * + * 古いprojectだとpropertyが生えていない + */ + plan?: string | null; + + theme: string; + + gyazoTeamsName: string | null; + + translation: boolean; + + infobox: boolean; + + created: UnixTime; + + updated: UnixTime; + + isMember: boolean; + + trialing: boolean; +} + +/** project information which isn't joined */ +export interface NotMemberProject + extends Omit { + image?: string; + + isMember: false; +} + +/** project information which is joined */ +export interface MemberProject extends Omit { + isMember: true; + + image?: string; + + users: UserInfo[]; + + admins: UserId[]; + + owner: UserId; + + isUserPageExists: boolean; + + trialMaxPages: number; + + skipPayment: boolean; + + uploadFileTo: "gcs"; + + uploadImaegTo: "gyazo" | "gcs"; + + emailAddressPatterns: string[]; + + projectScript: boolean; + + backuped: UnixTime | null; +} diff --git a/api/users/me.ts b/api/users/me.ts new file mode 100644 index 0000000..58e5f8c --- /dev/null +++ b/api/users/me.ts @@ -0,0 +1,22 @@ +import type { UserInfo } from "../pages/project/title.ts"; + +/** the response type of https://scrapbox.io/api/users/me */ +export type UserResponse = GuestUser | MemberUser; + +export interface GuestUser { + isGuest: true; + + csrfToken: string; +} + +export interface MemberUser extends UserInfo { + isGuest: false; + + csrfToken: string; + + config: { + userScript: boolean; + + emacsBinding: boolean; + }; +} diff --git a/change.ts b/change.ts index 2875b43..956444a 100644 --- a/change.ts +++ b/change.ts @@ -1,77 +1,93 @@ -import type { LineId, StringLc } from "./base.ts"; -import type { - ChangeLine, - CharsCountChange, - DeleteChange, - DescriptionsChange, - FilesChange, - HelpFeelsChange, - ImageChange, - InfoboxDefinitionChange, - InsertChange, - LinesCountChange, - PinChange, -} from "./websocket/change.ts"; - -/** ページの変更内容 */ -export type Change = - | InsertChange - | UpdateChange - | DeleteChange - | LinksChange - | ProjectLinksChange - | IconsChange - | DescriptionsChange - | ImageChange - | FilesChange - | HelpFeelsChange - | InfoboxDefinitionChange - | TitleChange - | LinesCountChange - | CharsCountChange - | PinChange; - -/** 既存の行を書き換える変更 */ -export interface UpdateChange { - /** 書き換える行のID */ - _update: LineId; - - /** 行の変更内容 */ - lines: ChangeLine; +import type { BasePage, LineId } from "./base.ts"; + +/** 行を新規作成する変更 */ +export interface InsertChange { + /** このIDが示す行の上に挿入する + * + * 末尾に挿入するときは`"_end"`を指定する + */ + _insert: LineId; + + /** 挿入する行のデータ */ + lines: NewLine; +} + +export interface NewLine { + /** 新しく挿入する行のID */ + id: LineId; + + /** 行のテキスト */ + text: string; } -/** ページ中のリンクが変更されると発生する */ -export interface LinksChange { - /** 新しいリンク */ - links: string[]; +export interface ChangeLine { + /**変更前の文字列*/ + origText: string; - /** 新しいリンク */ - linksLc: StringLc[]; + /**変更後の文字列*/ + text: string; } -/** ページ中のproject linksが変更されると発生する */ -export interface ProjectLinksChange { - /** 新しいリンク */ - projectLinks: string[]; +/** 既存の行を削除する変更 */ +export interface DeleteChange { + /** 削除する行のID */ + _delete: LineId; + + /** 常に `-1` */ + lines: -1; +} - /** 新しいリンク */ - projectLinksLc: StringLc[]; +/** ページのサムネイル本文が変更されると発生する */ +export interface DescriptionsChange { + /** 新しいサムネイル本文 */ + descriptions: string[]; } -/** ページ中のiconsが変更されると発生する */ -export interface IconsChange { - /** 新しいicons */ - icons: string[]; +/** ページのサムネイルが変更されると発生する */ +export interface ImageChange { + /** 新しいサムネイルのURL + * + * サムネイルがなくなったときは`null`になる + */ + image: string | null; +} - /** 新しいicons */ - iconsLc: StringLc[]; +export interface FilesChange { + /** Array of file IDs + * + * These IDs reference files that have been uploaded to the page. + * Files can include images, documents, or other attachments. + */ + files: string[]; } -/** ページのタイトルが変更されると発生する */ -export interface TitleChange { - /** 新しいタイトル */ - title: string; +export interface HelpFeelsChange { + /** Array of Helpfeel entries without the leading "? " prefix + * + * Helpfeel is a Scrapbox notation for creating help/documentation entries. + * Example: "? How to use" becomes "How to use" in this array. + * These entries are used to build the page's help documentation. + */ + helpfeels: string[]; +} + +export interface InfoboxDefinitionChange { + /** Array of trimmed lines from infobox tables + * + * Contains lines from tables marked with either `table:infobox` or `table:cosense` + */ + infoboxDefinition: string[]; +} + +export interface LinesCountChange { + linesCount: number; +} + +export interface CharsCountChange { + charsCount: number; +} - /** 新しいタイトル */ - titleLc: StringLc; +/** ページのピンの状態が変更されると発生する */ +export interface PinChange { + pin: BasePage["pin"]; } diff --git a/commit.ts b/commit.ts deleted file mode 100644 index 9502829..0000000 --- a/commit.ts +++ /dev/null @@ -1,27 +0,0 @@ -import type { CommitId, PageId, UnixTime, UserId } from "./base.ts"; -import type { Change } from "./change.ts"; - -/** Scrapboxのページの編集commit */ -export interface Commit { - id: CommitId; - - /** 一つ前のcommitのID - * - * 存在しないときは`null`になる - */ - parentId: CommitId | null; - - pageId: PageId; - - /** commitの作成者 */ - userId: UserId; - - /** commitの作成日時 */ - created: UnixTime; - - /** 変更内容 */ - changes: Change[]; - - /** 詳細不明 */ - kind: "page"; -} diff --git a/response.ts b/response.ts deleted file mode 100644 index 8387448..0000000 --- a/response.ts +++ /dev/null @@ -1,560 +0,0 @@ -import type { - BaseLine, - BasePage, - PageId, - ProjectId, - StringLc, - UnixTime, - UserId, -} from "./base.ts"; -import type { Commit } from "./commit.ts"; - -/** user information */ -export interface User { - id: UserId; - - /** user name */ - name: string; - - /** user display name */ - displayName: string; - - /** profile image URL */ - photo: string; -} - -/** user detailed information */ -export interface UserInfo extends User { - /** user e-mail */ - email: string; - - /** whether the user is a pro user or not */ - pro: boolean; - - /** login provider */ - provider: "google" | "microsoft" | "email"; - - /** creation time of the account */ - created: UnixTime; - - /** update time of the account */ - updated: UnixTime; -} - -/** page information */ -export interface Page extends BasePage { - /** APIを叩いたuserの最終アクセス日時。 - * - * おそらくこの値を元にテロメアの未読/既読の判別をしている - */ - lastAccessed: UnixTime | null; - - /** 生成されたPage historyの数 */ - snapshotCount: number; - - /** 空リンクだと`false` */ - persistent: boolean; - - /** ページの行情報 */ - lines: BaseLine[]; - - /** ページ内のリンク */ - links: string[]; - - /** ページ内の外部プロジェクトリンク */ - projectLinks: string[]; - - /** ページ内のアイコン */ - icons: string[]; - - /** ページ内に含まれる、scrapbox.ioにアップロードしたファイルのfile id */ - files: string[]; - - infoboxDefinition: string[]; - - infoboxResult: InfoboxResult[]; - - infoboxDisableLinks: string[]; - - /** 関連ページリスト */ - relatedPages: RelatedPages; - - /** ページを作成したユーザー */ - user: User; - - /** 最後にページを更新したユーザー */ - lastUpdateUser: User; - - /** ページを編集したユーザーのうち、`user`以外の人 */ - collaborators: User[]; -} - -export interface RelatedPages { - /** 1 hop links */ - links1hop: RelatedPage[]; - - /** 2 hop links */ - links2hop: RelatedPage[]; - - /** external links */ - projectLinks1hop: ProjectRelatedPage[]; - - /** このページを参照しているページorアイコンがあればtrue */ - hasBackLinksOrIcons: boolean; - - /** 2 hop searchのquery */ - search: string; - - /** 全文検索エンジンの名前 */ - searchBackend: string; -} - -export interface InfoboxResult { - title: string; - - infobox: Record; - - hallucination: boolean; - - truncated: boolean; -} - -/** 関連ページのメタデータ */ -export interface RelatedPage extends - Pick< - BasePage, - | "id" - | "title" - | "image" - | "descriptions" - | "linked" - | "pageRank" - | "created" - | "updated" - | "accessed" - > { - /** page title */ - titleLc: StringLc; - - /** - * links1hopの場合:ページ内の全てのリンク - * - * links2hopの場合:ページ内の全てのリンクのうち、`Page.links`に含まれるリンク - */ - linksLc: StringLc[]; - - infoboxResult: InfoboxResult[]; - - infoboxDisableLinks: string[]; - - search?: SearchQuery; -} - -/** 外部プロジェクトの関連ページ */ -export interface ProjectRelatedPage extends - Pick< - BasePage, - | "id" - | "title" - | "image" - | "descriptions" - | "linked" - | "updated" - | "accessed" - > { - /** page title */ - titleLc: StringLc; - - created: number | null; - - /** project name */ - projectName: string; -} - -/** the response type of https://scrpabox.io/api/pages/:projectname */ -export interface PageList { - /** data取得先のproject名 */ - projectName: string; - - /** parameterに渡したskipと同じ */ - skip: number; - - /** parameterに渡したlimitと同じ */ - limit: number; - - /** projectの全ページ数 (中身のないページを除く) */ - count: number; - - /** 取得できたページ情報 */ - pages: BasePage[]; -} - -/** project information */ -export interface Project { - id: ProjectId; - - name: string; - - displayName: string; - - publicVisible: boolean; - - loginStrategies: string[]; - - /** planの種類 - * - * public projectの場合は`null`になる - * - * 古いprojectだとpropertyが生えていない - */ - plan?: string | null; - - theme: string; - - gyazoTeamsName: string | null; - - translation: boolean; - - infobox: boolean; - - created: UnixTime; - - updated: UnixTime; - - isMember: boolean; - - trialing: boolean; -} - -/** the response type of /api/projects */ -export interface ProjectResponse { - projects: Project[]; -} - -/** project information which isn't joined */ -export interface NotMemberProject - extends Omit { - image?: string; - - isMember: false; -} - -/** project information which is joined */ -export interface MemberProject extends Omit { - isMember: true; - - image?: string; - - users: UserInfo[]; - - admins: UserId[]; - - owner: UserId; - - isUserPageExists: boolean; - - trialMaxPages: number; - - skipPayment: boolean; - - uploadFileTo: "gcs"; - - uploadImaegTo: "gyazo" | "gcs"; - - emailAddressPatterns: string[]; - - projectScript: boolean; - - backuped: UnixTime | null; -} - -export interface GuestUser { - isGuest: true; - - csrfToken: string; -} - -export interface MemberUser extends UserInfo { - isGuest: false; - - csrfToken: string; - - config: { - userScript: boolean; - - emacsBinding: boolean; - }; -} - -/** the response type of https://scrapbox.io/api/users/me */ -export type UserResponse = GuestUser | MemberUser; - -/** the response type of https://scrapbox.io/api/pages/:projectname/search/titles */ -export interface SearchedTitle - extends Pick { - /** thumbnail URL */ - image?: string; - - /** ページ内のリンク */ - links: string[]; -} - -/** exportしたときのページデータ */ -export interface ExportedPage - extends Pick { - /** ページ本文 - * - * `hasMetadata === true`のときは行のmetadataが入る - * それ以外の場合は行のテキストが入る - */ - lines: hasMetadata extends true ? Omit[] : string[]; -} - -/** JSON data exported from https://scrapbox.io/api/page-data/export/:projectname.json */ -export interface ExportedData { - /** project's name */ - name: string; - - /** project's display name */ - displayName: string; - - /** このデータを生成した日時 (UNIX時刻) */ - exported: UnixTime; - - /** project members */ - users: UserForExport[]; - - /** exported pages */ - pages: ExportedPage[]; -} - -/** user infomation included in exported data */ -export interface UserForExport - extends Pick {} - -/** backupされるページデータ */ -export interface BackupedPage - extends Pick { - /** ページ本文 */ - lines: Pick[]; - - /** ページに含まれているリンク*/ - linksLc: StringLc[]; -} - -/** project backup data */ -export interface BackupData { - /** project's name */ - name: string; - - /** project's display name */ - displayName: string; - - /** このデータを生成した日時 (UNIX時刻) */ - exported: UnixTime; - - /** backuped pages */ - pages: BackupedPage[]; -} - -/** メタデータ無しインポート用ページデータ */ -export interface ImportedLightPage { - /** page's title - * - * `title` should be equal to `lines[0]` - */ - title: string; - - /** page's text - * - * `lines[0]` should be equal to `title` - */ - lines: string[]; -} -/** インポート用メタデータ付き行データ */ -export interface ImportedLine { - /** line text */ - text: string; - - /** 行の最終更新日時 (UNIX時刻) */ - updated?: UnixTime; - - /** 行の最終作成日時 (UNIX時刻) */ - created?: UnixTime; -} -/** メタデータ付きインポート用ページデータ */ -export interface ImportedPage { - /** page's title - * - * `title` should be equal to `lines[0].text` - */ - title: string; - - /** page's line data - * - * `lines[0].text` should be equal to `title` - */ - lines: ImportedLine[]; -} -/** JSON data for importing by https://scrapbox.io/api/page-data/import/:projectname.json */ -export interface ImportedData { - /** pages importing to a project */ - pages: hasMetadata extends true ? ImportedPage[] : ImportedLightPage[]; -} - -/** the response type of /api/embed-text/twitter */ -export interface TweetInfo { - /** Tweet本文 */ - description?: string; - - /** Tweet投稿者の表示名 */ - screenName: string; - - /** Tweetに添付された画像 */ - images: string[]; -} - -/** the response type of /api/pages/:projectname/search/titles */ -export interface SearchResult { - /** 検索したprojectの名前 */ - projectName: string; - - /** 検索文字列 */ - searchQuery: string; - - /** 検索語句 */ - query: SearchQuery; - - /** 検索件数の上限 */ - limit: number; - - /** 検索件数 */ - count: number; - - /** 検索文字列と完全一致するタイトルが見つかったら`true` */ - existsExactTitleMatch: boolean; - - field: "title" | "helpfeels" | "lines"; - - /** 全文検索エンジンの名前 */ - backend: string; - - /** 見つかったページ */ - pages: FoundPage[]; -} - -/** /api/pages/:projectname/search/titles で見つかったページ */ -export interface FoundPage { - id: PageId; - - /** page title */ - title: string; - - /** page thumbnail - * - * 無いときは空文字が入る - */ - image: string; - - /** 検索語句の中で、このページに含まれている語句 */ - words: string[]; - - /** 検索語句に一致した行 - * - * タイトル行のみが一致した場合は、検索語句の有無にかかわらずその次の行のみが入る - */ - lines: string[]; -} - -/** the response type of /api/pages/:projectname/search/files */ -export interface FileSearchResult - extends Omit { - /** 見つかったページ */ - pages: FoundPageByFile[]; -} - -/** /api/pages/:projectname/search/files で見つかったページ */ -export interface FoundPageByFile extends FoundPage { - file: string; -} - -/** the response type of /api/projects/search/query and /api/projects/search/watch-list */ -export interface ProjectSearchResult { - /** 検索文字列 */ - searchQuery: string; - - /** 検索語句 */ - query: SearchQuery; - - /** 見つかったprojects */ - projects: FoundProject[]; -} - -/** /api/projects/search/query や /api/projects/search/watch-list で見つかったproject */ -export interface FoundProject { - _id: ProjectId; - - /** project name */ - name: string; - - /** projectの表示名 */ - displayName: string; - - /** project favicon - * - * 無いときは`null`が入るかproperty自体が存在しない - */ - image?: string | null; -} - -/** 検索クエリ */ -export interface SearchQuery { - /** AND検索に使う語句 */ - words: string[]; - - /** NOT検索に使う語句 */ - excludes: string[]; -} - -/** the response type of /api/commits/:projectname/:pageid */ -export interface CommitsResponse { - /** 指定したページのcommits */ - commits: Commit[]; -} - -/** the response type of /api/page-snapshots/:projectname/:pageid */ -export interface PageSnapshotList { - pageId: PageId; - - /** 作成されているsnapshotsのtimestamp idのリスト */ - timestamps: SnapshotTimestamp[]; -} - -export interface SnapshotTimestamp { - id: string; - created: UnixTime; -} - -/** the response type of /api/page-snapshots/:projectname/:pageid/:timestampid */ -export interface PageSnapshotResult { - page: PageWithSnapshot; - - snapshot: Snapshot; -} - -export interface PageWithSnapshot extends BasePage { - user: Pick; - lastupdateUser: Pick | null; -} - -/** a page snapshot */ -export interface Snapshot { - /** snapshotを撮ったときのページタイトル */ - title: string; - - /** snapshotの作成日時 */ - created: UnixTime; - - /** snapshotしたページ本文 */ - lines: BaseLine[]; -} diff --git a/rest.ts b/rest.ts index 6049fd3..c712b11 100644 --- a/rest.ts +++ b/rest.ts @@ -4,7 +4,23 @@ */ export * from "./base.ts"; -export * from "./commit.ts"; export * from "./change.ts"; -export * from "./response.ts"; export * from "./error.ts"; + +export * from "./api/commits/project/pageId.ts"; +export * from "./api/embed-text/twitter.ts"; +export * from "./api/page-data/export/project.ts"; +export * from "./api/page-data/import/project.ts"; +export * from "./api/page-snapshots/project/pageId.ts"; +export * from "./api/page-snapshots/project/pageId/timestampId.ts"; +export * from "./api/pages/project/search/files.ts"; +export * from "./api/pages/project/search/query.ts"; +export * from "./api/pages/project/search/titles.ts"; +export * from "./api/pages/project/search/watch-list.ts"; +export * from "./api/pages/project/title.ts"; +export * from "./api/pages/project.ts"; +export * from "./api/project-backup/project/backupId.ts"; +export * from "./api/project-backup/project/list.ts"; +export * from "./api/projects/project.ts"; +export * from "./api/projects.ts"; +export * from "./api/users/me.ts"; diff --git a/websocket/change.ts b/websocket/change.ts index dd23c6b..98012fe 100644 --- a/websocket/change.ts +++ b/websocket/change.ts @@ -1,4 +1,16 @@ -import type { BasePage, LineId } from "../base.ts"; +import type { + ChangeLine, + CharsCountChange, + DeleteChange, + DescriptionsChange, + FilesChange, + HelpFeelsChange, + ImageChange, + InfoboxDefinitionChange, + InsertChange, + LinesCountChange, + PinChange, +} from "../change.ts"; /** Changes to push to the cosense server */ export type ChangeToPush = @@ -18,48 +30,12 @@ export type ChangeToPush = | CharsCountChange | PinChange; -/** 行を新規作成する変更 */ -export interface InsertChange { - /** このIDが示す行の上に挿入する - * - * 末尾に挿入するときは`"_end"`を指定する - */ - _insert: LineId; - - /** 挿入する行のデータ */ - lines: NewLine; -} -export interface NewLine { - /** 新しく挿入する行のID */ - id: LineId; - - /** 行のテキスト */ - text: string; -} - export interface UpdateChange { _update: string; lines: Pick; noTimestampUpdate?: unknown; } -export interface ChangeLine { - /**変更前の文字列*/ - origText: string; - - /**変更後の文字列*/ - text: string; -} - -/** 既存の行を削除する変更 */ -export interface DeleteChange { - /** 削除する行のID */ - _delete: LineId; - - /** 常に `-1` */ - lines: -1; -} - export interface LinksChange { links: string[]; } @@ -72,64 +48,10 @@ export interface IconsChange { icons: string[]; } -/** ページのサムネイル本文が変更されると発生する */ -export interface DescriptionsChange { - /** 新しいサムネイル本文 */ - descriptions: string[]; -} - -/** ページのサムネイルが変更されると発生する */ -export interface ImageChange { - /** 新しいサムネイルのURL - * - * サムネイルがなくなったときは`null`になる - */ - image: string | null; -} - export interface TitleChange { title: string; } -export interface FilesChange { - /** Array of file IDs - * - * These IDs reference files that have been uploaded to the page. - * Files can include images, documents, or other attachments. - */ - files: string[]; -} -export interface HelpFeelsChange { - /** Array of Helpfeel entries without the leading "? " prefix - * - * Helpfeel is a Scrapbox notation for creating help/documentation entries. - * Example: "? How to use" becomes "How to use" in this array. - * These entries are used to build the page's help documentation. - */ - helpfeels: string[]; -} - -export interface InfoboxDefinitionChange { - /** Array of trimmed lines from infobox tables - * - * Contains lines from tables marked with either `table:infobox` or `table:cosense` - */ - infoboxDefinition: string[]; -} - -export interface LinesCountChange { - linesCount: number; -} - -export interface CharsCountChange { - charsCount: number; -} - -/** ページのピンの状態が変更されると発生する */ -export interface PinChange { - pin: BasePage["pin"]; -} - export interface DeletePageChange { deleted: true; merged?: true; diff --git a/websocket/event.ts b/websocket/event.ts index 6a00217..c5539e8 100644 --- a/websocket/event.ts +++ b/websocket/event.ts @@ -1,17 +1,19 @@ import type { CommitId, PageId, ProjectId, UserId } from "../base.ts"; -import type { User } from "../response.ts"; import type { ChangeToPush, - DeleteChange, DeletePageChange, - DescriptionsChange, IconsChange, - ImageChange, - InsertChange, LinksChange, TitleChange, UpdateChange, } from "./change.ts"; +import type { + DeleteChange, + DescriptionsChange, + ImageChange, + InsertChange, +} from "../change.ts"; +import type { User } from "../api/pages/project/title.ts"; export interface EmitEventMap { "socket.io-request": (