Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
46 changes: 40 additions & 6 deletions base.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** scrapboxの行のメタデータ */
export interface Line {
export interface BaseLine {
/** 行のid */ id: LineId;
/** 行のテキスト */ text: string;
/** 一番最後に行を編集した人のid */ userId: UserId;
Expand All @@ -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 */
Expand Down
4 changes: 2 additions & 2 deletions blocks.ts
Original file line number Diff line number Diff line change
@@ -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 */
Expand Down
6 changes: 0 additions & 6 deletions mod.ts

This file was deleted.

28 changes: 8 additions & 20 deletions response.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
CommitId,
Line,
Page as PageBase,
BaseLine,
BasePage,
PageId,
ProjectId,
StringLc,
Expand All @@ -10,7 +9,7 @@ import {
} from "./base.ts";

/** 関連ページのメタデータ */
export interface RelatedPage extends PageBase {
export interface RelatedPage extends BasePage {
/** ページ内のリンク */ linksLc: StringLc[];
/** おそらく被リンク数 */ linked: number;
}
Expand All @@ -32,27 +31,16 @@ 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の最終アクセス日時。
*
* おそらくこの値を元にテロメアの未読/既読の判別をしている
*/
lastAccessed: UnixTime | null;
/** 生成されたPage historyの数 */ snapshotCount: number;
/** 不明。削除されたページだとfalse? */ persistent: boolean;
/** ページの行情報 */ lines: Line[];
/** ページの行情報 */ lines: BaseLine[];
/** ページ内のリンク */ links: string[];
/** ページ内のアイコン */ icons: string[];
/** ページ内に含まれる、scrapbox.ioにアップロードしたファイルへのリンク */
Expand All @@ -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 */
Expand Down Expand Up @@ -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<PageBase, "id" | "title" | "updated"> {
extends Pick<BasePage, "id" | "title" | "updated"> {
/** 画像が存在するかどうか */ hasIcon: boolean;
/** ページ内のリンク */ links: string[];
}
Expand All @@ -141,7 +129,7 @@ export interface ExportedPage<hasMetadata extends true | false = false>
* `hasMetadata === true`のときは行のmetadataが入る
* それ以外の場合は行のテキストが入る
*/
lines: hasMetadata extends true ? Omit<Line, "id" | "userId">[]
lines: hasMetadata extends true ? Omit<BaseLine, "id" | "userId">[]
: string[];
}

Expand Down
5 changes: 5 additions & 0 deletions rest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/** @module types used at REST API */

export * from "./base.ts";
export * from "./response.ts";
export * from "./error.ts";
6 changes: 3 additions & 3 deletions scrapbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/// <reference lib="deno.ns" />

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";
Expand Down Expand Up @@ -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[];
};
}
& (
Expand All @@ -84,7 +84,7 @@ export type Scrapbox =
);

/** 入力補完に使われる辞書 */
export interface Page extends Pick<PageBase, "id" | "title" | "updated"> {
export interface Candidate extends Pick<BasePage, "id" | "title" | "updated"> {
/** 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;
Expand Down
3 changes: 3 additions & 0 deletions userscript.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down