From 5918f7a7a0a5d542d21f99d1a7d9acf8ee9e603b Mon Sep 17 00:00:00 2001 From: takker99 <37929109+takker99@users.noreply.github.com> Date: Tue, 4 Jan 2022 11:52:06 +0900 Subject: [PATCH 1/3] :boom: Specify whether to have metadata by the type parameter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit JSDocなどもつけた --- api/response.ts | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/api/response.ts b/api/response.ts index 06e02ab..71004a0 100644 --- a/api/response.ts +++ b/api/response.ts @@ -130,27 +130,23 @@ export interface SearchedTitle { /** ページ内のリンク */ links: string[]; } -export interface ProjectBackup { - name: string; - displayName: string; - exported: number; - pages: { - id: PageId; - title: string; - created: number; - updated: number; - lines: string[]; - }; +/** exportもしくはbackupをとったときのページデータ */ +export interface ExportPage { + /** page's title */ title: string; + /** ページの最終更新日時 (UNIX時刻) */ updated: number; + /** ページの最終作成日時 (UNIX時刻) */ created: number; + /** page ID */ id: string; + /** ページ本文 + * + * `hasMetadata === true`のときは行のmetadataが入る + * それ以外の場合は行のテキストが入る + */ + lines: hasMetadata extends true ? Omit[] + : string[]; } -export interface ProjectBackupWithMetadata { - name: string; - displayName: string; - exported: number; - pages: { - id: PageId; - title: string; - created: number; - updated: number; - lines: Omit[]; - }; +export interface ExportData { + /** project's name */ name: string; + /** project's display name */ displayName: string; + /** このデータを生成した日時 (UNIX時刻) */ exported: number; + /** exported pages */ pages: ExportPage[]; } From 58723996b126681d5c766f5e502cb51147ec832c Mon Sep 17 00:00:00 2001 From: takker99 <37929109+takker99@users.noreply.github.com> Date: Tue, 4 Jan 2022 12:08:20 +0900 Subject: [PATCH 2/3] :sparkles: Add type definitions of import data --- api/response.ts | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/api/response.ts b/api/response.ts index 71004a0..e3d13c5 100644 --- a/api/response.ts +++ b/api/response.ts @@ -144,9 +144,48 @@ export interface ExportPage { lines: hasMetadata extends true ? Omit[] : string[]; } + export interface ExportData { /** project's name */ name: string; /** project's display name */ displayName: string; /** このデータを生成した日時 (UNIX時刻) */ exported: number; /** exported pages */ pages: ExportPage[]; } + +/** メタデータ無しインポート用ページデータ */ +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?: number; + /** 行の最終作成日時 (UNIX時刻) */ created?: number; +} +/** メタデータ付きインポート用ページデータ */ +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; +} From a16a3162a732787e85014a3cf07899934f571077 Mon Sep 17 00:00:00 2001 From: takker99 <37929109+takker99@users.noreply.github.com> Date: Tue, 4 Jan 2022 12:10:20 +0900 Subject: [PATCH 3/3] :boom: s/export/exported MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 語形をimportedに揃えた --- api/response.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/api/response.ts b/api/response.ts index e3d13c5..26bb1e5 100644 --- a/api/response.ts +++ b/api/response.ts @@ -131,7 +131,7 @@ export interface SearchedTitle { } /** exportもしくはbackupをとったときのページデータ */ -export interface ExportPage { +export interface ExportedPage { /** page's title */ title: string; /** ページの最終更新日時 (UNIX時刻) */ updated: number; /** ページの最終作成日時 (UNIX時刻) */ created: number; @@ -145,11 +145,11 @@ export interface ExportPage { : string[]; } -export interface ExportData { +export interface ExportedData { /** project's name */ name: string; /** project's display name */ displayName: string; /** このデータを生成した日時 (UNIX時刻) */ exported: number; - /** exported pages */ pages: ExportPage[]; + /** exported pages */ pages: ExportedPage[]; } /** メタデータ無しインポート用ページデータ */