diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index de66c75..71ff822 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,4 +15,4 @@ jobs: - name: Run lint run: deno lint - name: Run type check - run: deno cache mod.ts + run: deno cache rest.ts userscript.ts diff --git a/base.ts b/base.ts index 92891d5..b32b216 100644 --- a/base.ts +++ b/base.ts @@ -1,5 +1,5 @@ /** scrapboxの行のメタデータ */ -export interface Line { +export interface BaseLine { /** 行のid */ id: LineId; /** 行のテキスト */ text: string; /** 一番最後に行を編集した人のid */ userId: UserId; @@ -8,20 +8,54 @@ export interface Line { } /** basic information about a page */ -export interface Page { - /** the id of a page */ id: PageId; - /** the title of a page */ title: string; +export interface BasePage { + id: PageId; + + /** 最新の編集コミットid */ + commitId: CommitId; + + /** the title of a page */ + title: string; + /** the thumbnail URL of a page if exists * * set to `null` if not exists */ image: string | null; + /** the thumbnail text of a page. + * * the maximum number of lines is 5. */ descriptions: string[]; - /** ページの最終更新日時 */ updated: UnixTime; - /** Date last visitedに使われる最終アクセス日時 */ accessed: UnixTime; + + /** ピン留めの状態を表す数値 + * + * - 0: ピンされてない + * - 0以外: ピンされている + */ + pin: number; + + /** ページの作成日時 */ + created: UnixTime; + + /** ページの最終更新日時 */ + updated: UnixTime; + + /** Date last visitedに使われる最終アクセス日時 */ + accessed: UnixTime; + + /** Page historyの最終生成日時 */ + snapshotCreated: UnixTime | null; + + /** ページの閲覧回数 */ + views: number; + + /** 被リンク数 */ + linked: number; + + /** page rank */ + pageRank: number; } /** the user id */ diff --git a/blocks.ts b/blocks.ts index 1a868fc..167328c 100644 --- a/blocks.ts +++ b/blocks.ts @@ -1,8 +1,8 @@ import type { Node, NodeWithoutIndent } from "./nodes.ts"; -import type { Line as LineBase } from "./base.ts"; +import type { BaseLine } from "./base.ts"; export type Line = - & LineBase + & BaseLine & { section: { /** section number */ diff --git a/mod.ts b/mod.ts deleted file mode 100644 index cfe8878..0000000 --- a/mod.ts +++ /dev/null @@ -1,6 +0,0 @@ -export * from "./response.ts"; -export * from "./error.ts"; -export * from "./base.ts"; -export type { Scrapbox } from "./userscript.ts"; -import * as UserScript from "./userscript.ts"; -export { UserScript }; diff --git a/response.ts b/response.ts index 7da921c..ba367de 100644 --- a/response.ts +++ b/response.ts @@ -1,7 +1,6 @@ import { - CommitId, - Line, - Page as PageBase, + BaseLine, + BasePage, PageId, ProjectId, StringLc, @@ -10,7 +9,7 @@ import { } from "./base.ts"; /** 関連ページのメタデータ */ -export interface RelatedPage extends PageBase { +export interface RelatedPage extends BasePage { /** ページ内のリンク */ linksLc: StringLc[]; /** おそらく被リンク数 */ linked: number; } @@ -32,19 +31,8 @@ export interface UserInfo extends User { /** accountの更新日時 */ updated: UnixTime; } -/** summary of page information */ -export interface PageSummary extends PageBase { - /** ピン留めされていたら1, されていなかったら0 */ pin: 0 | 1; - /** ページの閲覧回数 */ views: number; - /** おそらく被リンク数 */ linked: number; - /** 最新の編集コミットid */ commitId: CommitId; - /** ページの作成日時 */ created: UnixTime; - /** page rank */ pageRank: number; - /** Page historyの最終生成日時 */ snapshotCreated: UnixTime | null; -} - /** page information */ -export interface Page extends PageSummary { +export interface Page extends BasePage { /** APIを叩いたuserの最終アクセス日時。 * * おそらくこの値を元にテロメアの未読/既読の判別をしている @@ -52,7 +40,7 @@ export interface Page extends PageSummary { lastAccessed: UnixTime | null; /** 生成されたPage historyの数 */ snapshotCount: number; /** 不明。削除されたページだとfalse? */ persistent: boolean; - /** ページの行情報 */ lines: Line[]; + /** ページの行情報 */ lines: BaseLine[]; /** ページ内のリンク */ links: string[]; /** ページ内のアイコン */ icons: string[]; /** ページ内に含まれる、scrapbox.ioにアップロードしたファイルへのリンク */ @@ -74,7 +62,7 @@ export interface PageList { /** parameterに渡したskipと同じ */ skip: number; /** parameterに渡したlimitと同じ */ limit: number; /** projectの全ページ数 (中身のないページを除く) */ count: number; - /** 取得できたページ情報 */ pages: PageSummary[]; + /** 取得できたページ情報 */ pages: BasePage[]; } /** project information which isn't joined */ @@ -128,7 +116,7 @@ export type UserResponse = GuestUser | MemberUser; /** the response type of https://scrapbox.io/api/pages/:projectname/search/titles */ export interface SearchedTitle - extends Pick { + extends Pick { /** 画像が存在するかどうか */ hasIcon: boolean; /** ページ内のリンク */ links: string[]; } @@ -141,7 +129,7 @@ export interface ExportedPage * `hasMetadata === true`のときは行のmetadataが入る * それ以外の場合は行のテキストが入る */ - lines: hasMetadata extends true ? Omit[] + lines: hasMetadata extends true ? Omit[] : string[]; } diff --git a/rest.ts b/rest.ts new file mode 100644 index 0000000..2d8b8ed --- /dev/null +++ b/rest.ts @@ -0,0 +1,5 @@ +/** @module types used at REST API */ + +export * from "./base.ts"; +export * from "./response.ts"; +export * from "./error.ts"; diff --git a/scrapbox.ts b/scrapbox.ts index c662ccf..dbf972a 100644 --- a/scrapbox.ts +++ b/scrapbox.ts @@ -4,7 +4,7 @@ /// import type { Line } from "./blocks.ts"; -import type { Page as PageBase, StringLc } from "./base.ts"; +import type { BasePage, StringLc } from "./base.ts"; import type { PartialLayout } from "./layout.ts"; import type { AddMenuInit, Item, PageMenu } from "./pageMenu.ts"; import type { EventEmitter } from "./deps/events.ts"; @@ -57,7 +57,7 @@ export type Scrapbox = /** get the current project name */ get name(): string; /** get the dictionary used for comupletion */ - get pages(): Page[]; + get pages(): Candidate[]; }; } & ( @@ -84,7 +84,7 @@ export type Scrapbox = ); /** 入力補完に使われる辞書 */ -export interface Page extends Pick { +export interface Candidate extends Pick { /** true when the page has contents */ exists: boolean; /** whether the page contains any image */ hasIcon?: boolean; /** lower case style of the page title */ titleLc: StringLc; diff --git a/userscript.ts b/userscript.ts index 4303ea1..ec5a3c8 100644 --- a/userscript.ts +++ b/userscript.ts @@ -1,3 +1,6 @@ +/** @module types used at UserScript */ + +export * from "./base.ts"; export * from "./blocks.ts"; export * from "./nodes.ts"; export * from "./layout.ts";