Skip to content

Commit c0fb73e

Browse files
fix: update response.ts imports to targeted_response.ts
- Update imports in page-data.ts, link.ts, parseHTTPError.ts, and pages.ts - Remove deno.lock for clean environment setup
1 parent ebc97a9 commit c0fb73e

20 files changed

+273
-260
lines changed

deno.lock

Lines changed: 0 additions & 177 deletions
This file was deleted.

docs/migration-guide-0.30.0.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44

55
### REST API Changes
66

7-
The REST API has been completely redesigned to improve type safety, reduce dependencies, and better align with web standards. The main changes are:
7+
The REST API has been completely redesigned to improve type safety, reduce
8+
dependencies, and better align with web standards. The main changes are:
89

910
1. Removal of `option-t` dependency
10-
- All `Result` types from `option-t/plain_result` have been replaced with `ScrapboxResponse`
11+
- All `Result` types from `option-t/plain_result` have been replaced with
12+
`ScrapboxResponse`
1113
- No more `unwrapOk`, `isErr`, or other option-t utilities
1214

1315
2. New `ScrapboxResponse` class
@@ -19,6 +21,7 @@ The REST API has been completely redesigned to improve type safety, reduce depen
1921
### Before and After Examples
2022

2123
#### Before (v0.29.x):
24+
2225
```typescript
2326
import { isErr, unwrapOk } from "option-t/plain_result";
2427

@@ -32,6 +35,7 @@ console.log("Name:", profile.name);
3235
```
3336

3437
#### After (v0.30.0):
38+
3539
```typescript
3640
const response = await getProfile();
3741
if (!response.ok) {
@@ -83,17 +87,18 @@ console.log("Name:", response.data.name);
8387
```typescript
8488
// Access headers
8589
const contentType = response.headers.get("content-type");
86-
90+
8791
// Access raw body
8892
const text = await response.text();
89-
93+
9094
// Parse JSON with type safety
9195
const json = await response.json();
9296
```
9397

9498
### Common Patterns
9599

96100
1. **Status-based Error Handling**:
101+
97102
```typescript
98103
const response = await getSnapshot(project, pageId, timestampId);
99104

@@ -114,15 +119,17 @@ console.log(response.data);
114119
```
115120

116121
2. **Type-safe JSON Parsing**:
122+
117123
```typescript
118124
const response = await getTweetInfo(tweetUrl);
119125
if (response.ok) {
120-
const tweet = response.data; // Properly typed as TweetInfo
126+
const tweet = response.data; // Properly typed as TweetInfo
121127
console.log(tweet.text);
122128
}
123129
```
124130

125131
3. **Working with Headers**:
132+
126133
```typescript
127134
const response = await uploadToGCS(file, projectId);
128135
if (!response.ok && response.headers.get("Content-Type")?.includes("/xml")) {
@@ -134,6 +141,8 @@ if (!response.ok && response.headers.get("Content-Type")?.includes("/xml")) {
134141
### Need Help?
135142

136143
If you encounter any issues during migration, please:
144+
137145
1. Check the examples in this guide
138-
2. Review the [API documentation](https://jsr.io/@takker/scrapbox-userscript-std)
146+
2. Review the
147+
[API documentation](https://jsr.io/@takker/scrapbox-userscript-std)
139148
3. Open an issue on GitHub if you need further assistance

rest/auth.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { getProfile } from "./profile.ts";
22
import type { TargetedResponse } from "./targeted_response.ts";
3-
import { createSuccessResponse, createErrorResponse } from "./utils.ts";
3+
import { createErrorResponse, createSuccessResponse } from "./utils.ts";
44
import type { HTTPError } from "./responseIntoResult.ts";
55
import type { AbortError, NetworkError } from "./robustFetch.ts";
66
import type { ExtendedOptions } from "./options.ts";
@@ -17,7 +17,12 @@ export const cookie = (sid: string): string => `connect.sid=${sid}`;
1717
*/
1818
export const getCSRFToken = async (
1919
init?: ExtendedOptions,
20-
): Promise<TargetedResponse<200 | 400 | 404 | 0 | 499, string | NetworkError | AbortError | HTTPError>> => {
20+
): Promise<
21+
TargetedResponse<
22+
200 | 400 | 404 | 0 | 499,
23+
string | NetworkError | AbortError | HTTPError
24+
>
25+
> => {
2126
// deno-lint-ignore no-explicit-any
2227
const csrf = init?.csrf ?? (globalThis as any)._csrf;
2328
if (csrf) return createSuccessResponse(csrf);

rest/getCodeBlock.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ import { encodeTitleURI } from "../title.ts";
88
import { type BaseOptions, setDefaults } from "./options.ts";
99
import { parseHTTPError } from "./parseHTTPError.ts";
1010
import type { TargetedResponse } from "./targeted_response.ts";
11-
import { createSuccessResponse, createErrorResponse, createTargetedResponse } from "./utils.ts";
11+
import {
12+
createErrorResponse,
13+
createSuccessResponse,
14+
createTargetedResponse,
15+
} from "./utils.ts";
1216
import type { FetchError } from "./mod.ts";
1317

1418
const getCodeBlock_toRequest: GetCodeBlock["toRequest"] = (
@@ -30,7 +34,10 @@ const getCodeBlock_toRequest: GetCodeBlock["toRequest"] = (
3034
const getCodeBlock_fromResponse: GetCodeBlock["fromResponse"] = async (res) => {
3135
const response = createTargetedResponse<200 | 400 | 404, CodeBlockError>(res);
3236

33-
if (response.status === 404 && response.headers.get("Content-Type")?.includes?.("text/plain")) {
37+
if (
38+
response.status === 404 &&
39+
response.headers.get("Content-Type")?.includes?.("text/plain")
40+
) {
3441
return createErrorResponse(404, {
3542
name: "NotFoundError",
3643
message: "Code block is not found",
@@ -71,14 +78,18 @@ export interface GetCodeBlock {
7178
* @param res 応答
7279
* @return コード
7380
*/
74-
fromResponse: (res: Response) => Promise<TargetedResponse<200 | 400 | 404, string | CodeBlockError>>;
81+
fromResponse: (
82+
res: Response,
83+
) => Promise<TargetedResponse<200 | 400 | 404, string | CodeBlockError>>;
7584

7685
(
7786
project: string,
7887
title: string,
7988
filename: string,
8089
options?: BaseOptions,
81-
): Promise<TargetedResponse<200 | 400 | 404, string | CodeBlockError | FetchError>>;
90+
): Promise<
91+
TargetedResponse<200 | 400 | 404, string | CodeBlockError | FetchError>
92+
>;
8293
}
8394
export type CodeBlockError =
8495
| NotFoundError

rest/getGyazoToken.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ import { cookie } from "./auth.ts";
33
import { parseHTTPError } from "./parseHTTPError.ts";
44
import { type BaseOptions, setDefaults } from "./options.ts";
55
import type { TargetedResponse } from "./targeted_response.ts";
6-
import { createSuccessResponse, createErrorResponse, createTargetedResponse } from "./utils.ts";
6+
import {
7+
createErrorResponse,
8+
createSuccessResponse,
9+
createTargetedResponse,
10+
} from "./utils.ts";
711
import type { FetchError } from "./mod.ts";
812

913
export interface GetGyazoTokenOptions extends BaseOptions {
@@ -23,7 +27,12 @@ export type GyazoTokenError = NotLoggedInError | HTTPError;
2327
*/
2428
export const getGyazoToken = async (
2529
init?: GetGyazoTokenOptions,
26-
): Promise<TargetedResponse<200 | 400 | 404, string | undefined | GyazoTokenError | FetchError>> => {
30+
): Promise<
31+
TargetedResponse<
32+
200 | 400 | 404,
33+
string | undefined | GyazoTokenError | FetchError
34+
>
35+
> => {
2736
const { fetch, sid, hostName, gyazoTeamsName } = setDefaults(init ?? {});
2837
const req = new Request(
2938
`https://${hostName}/api/login/gyazo/oauth-upload/token${
@@ -33,7 +42,9 @@ export const getGyazoToken = async (
3342
);
3443

3544
const res = await fetch(req);
36-
const response = createTargetedResponse<200 | 400 | 404, GyazoTokenError>(res);
45+
const response = createTargetedResponse<200 | 400 | 404, GyazoTokenError>(
46+
res,
47+
);
3748

3849
await parseHTTPError(response, ["NotLoggedInError"]);
3950

0 commit comments

Comments
 (0)