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 browser/websocket/pull.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { getProfile } from "../../rest/profile.ts";
import { getProject } from "../../rest/project.ts";
import type { HTTPError } from "../../rest/responseIntoResult.ts";
import type { AbortError, NetworkError } from "../../rest/robustFetch.ts";
import type { BaseOptions } from "../../rest/util.ts";
import type { BaseOptions } from "../../rest/options.ts";

export interface PushMetadata extends Page {
projectId: string;
Expand Down
2 changes: 1 addition & 1 deletion rest/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createOk, mapForResult, type Result } from "option-t/plain_result";
import { getProfile } from "./profile.ts";
import type { HTTPError } from "./responseIntoResult.ts";
import type { AbortError, NetworkError } from "./robustFetch.ts";
import type { BaseOptions } from "./util.ts";
import type { BaseOptions } from "./options.ts";

/** HTTP headerのCookieに入れる文字列を作る
*
Expand Down
28 changes: 9 additions & 19 deletions rest/getCodeBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type {
} from "@cosense/types/rest";
import { cookie } from "./auth.ts";
import { encodeTitleURI } from "../title.ts";
import { type BaseOptions, setDefaults } from "./util.ts";
import { type BaseOptions, setDefaults } from "./options.ts";
import {
isErr,
mapAsyncForResult,
Expand All @@ -15,7 +15,7 @@ import {
} from "option-t/plain_result";
import { type HTTPError, responseIntoResult } from "./responseIntoResult.ts";
import { parseHTTPError } from "./parseHTTPError.ts";
import type { AbortError, NetworkError } from "./robustFetch.ts";
import type { FetchError } from "./mod.ts";

const getCodeBlock_toRequest: GetCodeBlock["toRequest"] = (
project,
Expand Down Expand Up @@ -70,30 +70,20 @@ export interface GetCodeBlock {
* @param res 応答
* @return コード
*/
fromResponse: (res: Response) => Promise<
Result<
string,
NotFoundError | NotLoggedInError | NotMemberError | HTTPError
>
>;
fromResponse: (res: Response) => Promise<Result<string, CodeBlockError>>;

(
project: string,
title: string,
filename: string,
options?: BaseOptions,
): Promise<
Result<
string,
| NotFoundError
| NotLoggedInError
| NotMemberError
| NetworkError
| AbortError
| HTTPError
>
>;
): Promise<Result<string, CodeBlockError | FetchError>>;
}
export type CodeBlockError =
| NotFoundError
| NotLoggedInError
| NotMemberError
| HTTPError;

/** 指定したコードブロック中のテキストを取得する
*
Expand Down
13 changes: 5 additions & 8 deletions rest/getGyazoToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import type { NotLoggedInError } from "@cosense/types/rest";
import { cookie } from "./auth.ts";
import { parseHTTPError } from "./parseHTTPError.ts";
import { type HTTPError, responseIntoResult } from "./responseIntoResult.ts";
import type { AbortError, NetworkError } from "./robustFetch.ts";
import { type BaseOptions, setDefaults } from "./util.ts";
import { type BaseOptions, setDefaults } from "./options.ts";
import type { FetchError } from "./mod.ts";

export interface GetGyazoTokenOptions extends BaseOptions {
/** Gyazo Teamsのチーム名
Expand All @@ -20,19 +20,16 @@ export interface GetGyazoTokenOptions extends BaseOptions {
gyazoTeamsName?: string;
}

export type GyazoTokenError = NotLoggedInError | HTTPError;

/** Gyazo OAuth uploadで使うaccess tokenを取得する
*
* @param init connect.sidなど
* @return access token
*/
export const getGyazoToken = async (
init?: GetGyazoTokenOptions,
): Promise<
Result<
string | undefined,
NotLoggedInError | NetworkError | AbortError | HTTPError
>
> => {
): Promise<Result<string | undefined, GyazoTokenError | FetchError>> => {
const { fetch, sid, hostName, gyazoTeamsName } = setDefaults(init ?? {});
const req = new Request(
`https://${hostName}/api/login/gyazo/oauth-upload/token${
Expand Down
22 changes: 9 additions & 13 deletions rest/getTweetInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@ import type {
import { cookie, getCSRFToken } from "./auth.ts";
import { parseHTTPError } from "./parseHTTPError.ts";
import { type HTTPError, responseIntoResult } from "./responseIntoResult.ts";
import type { AbortError, NetworkError } from "./robustFetch.ts";
import { type ExtendedOptions, setDefaults } from "./util.ts";
import { type ExtendedOptions, setDefaults } from "./options.ts";
import type { FetchError } from "./mod.ts";

export type TweetInfoError =
| SessionError
| InvalidURLError
| BadRequestError
| HTTPError;

/** 指定したTweetの情報を取得する
*
Expand All @@ -28,17 +34,7 @@ import { type ExtendedOptions, setDefaults } from "./util.ts";
export const getTweetInfo = async (
url: string | URL,
init?: ExtendedOptions,
): Promise<
Result<
TweetInfo,
| SessionError
| InvalidURLError
| BadRequestError
| NetworkError
| AbortError
| HTTPError
>
> => {
): Promise<Result<TweetInfo, TweetInfoError | FetchError>> => {
const { sid, hostName, fetch, csrf } = setDefaults(init ?? {});

const csrfResult = await orElseAsyncForResult(
Expand Down
22 changes: 9 additions & 13 deletions rest/getWebPageTitle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,14 @@ import type {
import { cookie, getCSRFToken } from "./auth.ts";
import { parseHTTPError } from "./parseHTTPError.ts";
import { type HTTPError, responseIntoResult } from "./responseIntoResult.ts";
import type { AbortError, NetworkError } from "./robustFetch.ts";
import { type ExtendedOptions, setDefaults } from "./util.ts";
import { type ExtendedOptions, setDefaults } from "./options.ts";
import type { FetchError } from "./mod.ts";

export type WebPageTitleError =
| SessionError
| InvalidURLError
| BadRequestError
| HTTPError;

/** 指定したURLのweb pageのtitleをscrapboxのserver経由で取得する
*
Expand All @@ -27,17 +33,7 @@ import { type ExtendedOptions, setDefaults } from "./util.ts";
export const getWebPageTitle = async (
url: string | URL,
init?: ExtendedOptions,
): Promise<
Result<
string,
| SessionError
| InvalidURLError
| BadRequestError
| NetworkError
| AbortError
| HTTPError
>
> => {
): Promise<Result<string, WebPageTitleError | FetchError>> => {
const { sid, hostName, fetch, csrf } = setDefaults(init ?? {});

const csrfResult = await orElseAsyncForResult(
Expand Down
42 changes: 11 additions & 31 deletions rest/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import type {
import { cookie } from "./auth.ts";
import { parseHTTPError } from "./parseHTTPError.ts";
import { type HTTPError, responseIntoResult } from "./responseIntoResult.ts";
import type { AbortError, NetworkError } from "./robustFetch.ts";
import { type BaseOptions, setDefaults } from "./util.ts";
import { type BaseOptions, setDefaults } from "./options.ts";
import type { FetchError } from "./mod.ts";

/** 不正なfollowingIdを渡されたときに発生するエラー */
export interface InvalidFollowingIdError extends ErrorLike {
Expand All @@ -33,24 +33,20 @@ export interface GetLinksResult {
followingId: string;
}

export type LinksError =
| NotFoundError
| NotLoggedInError
| InvalidFollowingIdError
| HTTPError;

/** 指定したprojectのリンクデータを取得する
*
* @param project データを取得したいproject
*/
export const getLinks = async (
project: string,
options?: GetLinksOptions,
): Promise<
Result<
GetLinksResult,
| NotFoundError
| NotLoggedInError
| InvalidFollowingIdError
| NetworkError
| AbortError
| HTTPError
>
> => {
): Promise<Result<GetLinksResult, LinksError | FetchError>> => {
const { sid, hostName, fetch, followingId } = setDefaults(options ?? {});

const req = new Request(
Expand Down Expand Up @@ -96,15 +92,7 @@ export async function* readLinksBulk(
project: string,
options?: BaseOptions,
): AsyncGenerator<
Result<
SearchedTitle[],
| NotFoundError
| NotLoggedInError
| InvalidFollowingIdError
| NetworkError
| AbortError
| HTTPError
>,
Result<SearchedTitle[], LinksError | FetchError>,
void,
unknown
> {
Expand All @@ -131,15 +119,7 @@ export async function* readLinks(
project: string,
options?: BaseOptions,
): AsyncGenerator<
Result<
SearchedTitle,
| NotFoundError
| NotLoggedInError
| InvalidFollowingIdError
| NetworkError
| AbortError
| HTTPError
>,
Result<SearchedTitle, LinksError | FetchError>,
void,
unknown
> {
Expand Down
11 changes: 9 additions & 2 deletions rest/mod.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/** Cosense REST API wrapper
*
* @module
*/

export * from "./pages.ts";
export * from "./table.ts";
export * from "./project.ts";
Expand All @@ -11,9 +16,11 @@ export * from "./getWebPageTitle.ts";
export * from "./getTweetInfo.ts";
export * from "./getGyazoToken.ts";
export * from "./auth.ts";
export * from "./util.ts";
export * from "./parseHTTPError.ts";
export type { BaseOptions, ExtendedOptions } from "./options.ts";
export * from "./getCodeBlocks.ts";
export * from "./getCodeBlock.ts";
export * from "./uploadToGCS.ts";
export * from "./getCachedAt.ts";

export type { HTTPError } from "./responseIntoResult.ts";
export type { AbortError, FetchError, NetworkError } from "./robustFetch.ts";
File renamed without changes.
29 changes: 17 additions & 12 deletions rest/page-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,15 @@ import type {
import { cookie, getCSRFToken } from "./auth.ts";
import { parseHTTPError } from "./parseHTTPError.ts";
import { type HTTPError, responseIntoResult } from "./responseIntoResult.ts";
import type { AbortError, NetworkError } from "./robustFetch.ts";
import { type BaseOptions, type ExtendedOptions, setDefaults } from "./util.ts";
import {
type BaseOptions,
type ExtendedOptions,
setDefaults,
} from "./options.ts";
import type { FetchError } from "./mod.ts";

export type ImportPagesError = HTTPError;

/** projectにページをインポートする
*
* @param project - インポート先のprojectの名前
Expand All @@ -30,7 +37,7 @@ export const importPages = async (
data: ImportedData<boolean>,
init: ExtendedOptions,
): Promise<
Result<string, NetworkError | AbortError | HTTPError>
Result<string, ImportPagesError | FetchError>
> => {
if (data.pages.length === 0) return createOk("No pages to import.");

Expand Down Expand Up @@ -72,6 +79,12 @@ export const importPages = async (
);
};

export type ExportPagesError =
| NotFoundError
| NotPrivilegeError
| NotLoggedInError
| HTTPError;

/** `exportPages`の認証情報 */
export interface ExportInit<withMetadata extends true | false>
extends BaseOptions {
Expand All @@ -85,15 +98,7 @@ export const exportPages = async <withMetadata extends true | false>(
project: string,
init: ExportInit<withMetadata>,
): Promise<
Result<
ExportedData<withMetadata>,
| NotFoundError
| NotPrivilegeError
| NotLoggedInError
| NetworkError
| AbortError
| HTTPError
>
Result<ExportedData<withMetadata>, ExportPagesError | FetchError>
> => {
const { sid, hostName, fetch, metadata } = setDefaults(init ?? {});

Expand Down
Loading