|
1 | 1 | import type { ParsedLine } from "./line.d.ts"; |
2 | 2 | export * from "./line.d.ts"; |
3 | 3 |
|
| 4 | +// utilities |
| 5 | +type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>; |
| 6 | + |
| 7 | +/** scrapboxの行のメタデータ */ |
| 8 | +export interface Line { |
| 9 | + /** 行のid */ id: string; |
| 10 | + /** 行のテキスト */ text: string; |
| 11 | + /** 一番最後に行を編集した人のid */ userId: string; |
| 12 | + /** 行の作成日時 */ created: number; |
| 13 | + /** 行の最終更新日時 */ updated: number; |
| 14 | +} |
| 15 | + |
| 16 | +/** 関連ページのメタデータ */ |
| 17 | +export interface RelatedPage { |
| 18 | + /** ページのid */ id: string; |
| 19 | + /** ページのタイトル */ title: string; |
| 20 | + /** ページのタイトルを小文字にして、` `を`_`に変換したもの */ titleLc: string; |
| 21 | + /** ページのサムネイル画像 */ image: string; |
| 22 | + /** ページのサムネイル本文。最大5行 */ descriptions: string[]; |
| 23 | + /** ページ内のリンク */ linksLc: string[]; |
| 24 | + /** おそらく被リンク数 */ linked: number; |
| 25 | + /** ページの最終更新日時 */ updated: number; |
| 26 | + /** おそらくページの閲覧日時 */ accessed: number; |
| 27 | +} |
| 28 | + |
| 29 | +/** user information */ |
| 30 | +export interface User { |
| 31 | + /** user id */ id: string; |
| 32 | + /** user name */ name: string; |
| 33 | + /** user display name */ displayName: string; |
| 34 | + /** profile image URL */ photo: string; |
| 35 | +} |
| 36 | + |
| 37 | +/** user detailed information */ |
| 38 | +export interface UserInfo extends User { |
| 39 | + /** user e-mail */ email: string; |
| 40 | + /** whether the user is a pro user or not */ pro: boolean; |
| 41 | + /** login provider */ provider: "google" | "microsoft" | "email"; |
| 42 | + /** accountの作成日時 */ created: number; |
| 43 | + /** accountの更新日時 */ updated: number; |
| 44 | +} |
| 45 | + |
| 46 | +/** summary of page information */ |
| 47 | +export interface PageSummary { |
| 48 | + /** ページのid */ id: string; |
| 49 | + /** ページのタイトル */ title: string; |
| 50 | + /** ページのサムネイル画像 |
| 51 | + * 存在しなければ`null` |
| 52 | + */ |
| 53 | + image: string | null; |
| 54 | + /** ページのサムネイル本文。最大5行 */ descriptions: string[]; |
| 55 | + /** ピン留めされていたら1, されていなかったら0 */ pin: 0 | 1; |
| 56 | + /** ページの閲覧回数 */ views: number; |
| 57 | + /** おそらく被リンク数 */ linked: number; |
| 58 | + /** 最新の編集コミットid */ commitId: string; |
| 59 | + /** ページの作成日時 */ created: number; |
| 60 | + /** ページの最終更新日時 */ updated: number; |
| 61 | + /** Date last visitedに使われる最終アクセス日時 */ accessed: number; |
| 62 | + /** page rank */ pageRank: number; |
| 63 | + /** Page historyの最終生成日時 */ snapshotCreated: number | null; |
| 64 | +} |
| 65 | + |
| 66 | +/** page information */ |
| 67 | +export interface Page extends PageSummary { |
| 68 | + /** APIを叩いたuserの最終アクセス日時。おそらくこの値を元にテロメアの未読/既読の判別をしている */ lastAccessed: |
| 69 | + | number |
| 70 | + | null; |
| 71 | + /** 生成されたPage historyの数 */ snapshotCount: number; |
| 72 | + /** 不明。削除されたページだとfalse? */ persistent: boolean; |
| 73 | + /** ページの行情報 */ lines: Line[]; |
| 74 | + /** ページ内のリンク */ links: string[]; |
| 75 | + /** ページ内のアイコン */ icons: string[]; |
| 76 | + /** ページ内に含まれる、scrapbox.ioにアップロードしたファイルへのリンク */ files: string[]; |
| 77 | + /** 関連ページリスト */ |
| 78 | + relatedPages: { |
| 79 | + /** 1 hop links */ links1hop: RelatedPage[]; |
| 80 | + /** 2 hop links */ links2hop: RelatedPage[]; |
| 81 | + /** このページを参照しているページorアイコンがあればtrue */ hasBackLinksOrIcons: boolean; |
| 82 | + }; |
| 83 | + /** 最後にページを更新したユーザー */ user: User; |
| 84 | + /** ページを編集したユーザーのうち、`user`以外の人 */ collaborators: User[]; |
| 85 | +} |
| 86 | + |
| 87 | +/** the response type of https://scrpabox.io/api/pages/:projectname */ |
| 88 | +export type PageListResponse = |
| 89 | + | NotFoundError |
| 90 | + | NotMemberError |
| 91 | + | { |
| 92 | + /** data取得先のproject名 */ projectName: string; |
| 93 | + /** parameterに渡したskipと同じ */ skip: number; |
| 94 | + /** parameterに渡したlimitと同じ */ limit: number; |
| 95 | + /** projectの全ページ数 (中身のないページを除く) */ count: number; |
| 96 | + /** 取得できたページ情報 */ pages: PageSummary[]; |
| 97 | + }; |
| 98 | + |
| 99 | +/** project basic information */ |
| 100 | +export interface Project { |
| 101 | + id: string; |
| 102 | + name: string; |
| 103 | + displayName: string; |
| 104 | + publicVisible: boolean; |
| 105 | + loginStrategies: string[]; |
| 106 | + theme: string; |
| 107 | + gyazoTeamsName: string | null; |
| 108 | + googleAnalyticsCode: string | null; |
| 109 | + image?: string; |
| 110 | + created: number; |
| 111 | + updated: number; |
| 112 | + isMember: boolean; |
| 113 | + plan?: string; |
| 114 | +} |
| 115 | + |
| 116 | +export type NotMemberError = { |
| 117 | + name: "NotMemberError"; |
| 118 | + message: string; |
| 119 | +}; |
| 120 | + |
| 121 | +export type NotFoundError = { |
| 122 | + name: "NotFoundError"; |
| 123 | + message: string; |
| 124 | +}; |
| 125 | + |
| 126 | +/** the response type of https://scrpabox.io/api/projects/:projectname */ |
| 127 | +export type ProjectResponse = |
| 128 | + | NotFoundError |
| 129 | + | NotMemberError |
| 130 | + | ( |
| 131 | + & Omit<Omit<Project, "isMember">, "plan"> |
| 132 | + & ({ isMember: false } | { |
| 133 | + isMember: true; |
| 134 | + plan?: string | null; |
| 135 | + users: UserInfo[]; |
| 136 | + admins: string[]; |
| 137 | + owner: string; |
| 138 | + trialing: boolean; |
| 139 | + trialMaxPages: number; |
| 140 | + skipPayment: boolean; |
| 141 | + uploadFileTo: "gcs"; |
| 142 | + uploadImaegTo: "gyazo" | "gcs"; |
| 143 | + emailAddressPatterns: string[]; |
| 144 | + backuped: number | null; |
| 145 | + }) |
| 146 | + ); |
| 147 | + |
| 148 | +/** the response type of https://scrapbox.io/api/users/me */ |
| 149 | +export type UserResponse = |
| 150 | + | { |
| 151 | + isGuest: true; |
| 152 | + csrfToken: string; |
| 153 | + } |
| 154 | + | ({ |
| 155 | + isGuest: false; |
| 156 | + csrfToken: string; |
| 157 | + config: { |
| 158 | + userScript: boolean; |
| 159 | + emacsBinding: boolean; |
| 160 | + }; |
| 161 | + } & UserInfo); |
| 162 | + |
| 163 | +/** the response type of https://scrapbox.io/api/pages/:projectname/search/titles */ |
| 164 | +export type LinksResponse = |
| 165 | + | NotFoundError |
| 166 | + | NotMemberError |
| 167 | + | { |
| 168 | + message: "Invalid pageId"; |
| 169 | + } |
| 170 | + | { |
| 171 | + /** page id */ id: string; |
| 172 | + /** page title */ title: string; |
| 173 | + /** 画像が存在するかどうか */ hasIcon: boolean; |
| 174 | + /** ページの更新日時 */ updated: number; |
| 175 | + /** ページ内のリンク */ links: string[]; |
| 176 | + }[]; |
| 177 | + |
| 178 | +export type ProjectBackup = { |
| 179 | + name: string; |
| 180 | + displayName: string; |
| 181 | + exported: number; |
| 182 | + pages: { |
| 183 | + id: string; |
| 184 | + title: string; |
| 185 | + created: number; |
| 186 | + updated: number; |
| 187 | + lines: string[]; |
| 188 | + }; |
| 189 | +}; |
| 190 | +export type ProjectBackupWithMetadata = { |
| 191 | + name: string; |
| 192 | + displayName: string; |
| 193 | + exported: number; |
| 194 | + pages: { |
| 195 | + id: string; |
| 196 | + title: string; |
| 197 | + created: number; |
| 198 | + updated: number; |
| 199 | + lines: { text: string; updated: number; created: number }[]; |
| 200 | + }; |
| 201 | +}; |
| 202 | + |
4 | 203 | export type Layout = |
5 | 204 | | "list" |
6 | 205 | | "page" |
|
0 commit comments