Skip to content

fix(deno-udd): Update Deno dependencies #176

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 14, 2024
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
4 changes: 2 additions & 2 deletions .github/workflows/udd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ jobs:
- name: Update dependencies
run: >
deno run --allow-net --allow-read --allow-write=deps/
--allow-run=deno https://deno.land/x/udd@0.7.2/main.ts deps/*.ts
--test="deno test --allow-read --allow-write"
--allow-run=deno https://deno.land/x/udd@0.8.2/main.ts deps/*.ts
--test="deno test --allow-read"
- name: Create Pull Request
uses: peter-evans/create-pull-request@v3
with:
Expand Down
5 changes: 3 additions & 2 deletions deps/scrapbox-rest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export type {
NotPrivilegeError,
Page,
PageList,
PageSnapshot,
PageSnapshotList,
PageSnapshotResult,
ProjectId,
ProjectResponse,
ProjectSearchResult,
Expand All @@ -25,4 +26,4 @@ export type {
SessionError,
Snapshot,
TweetInfo,
} from "https://raw.githubusercontent.com/scrapbox-jp/types/0.7.1/rest.ts";
} from "https://raw.githubusercontent.com/scrapbox-jp/types/0.9.0/rest.ts";
4 changes: 2 additions & 2 deletions deps/scrapbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ export type {
BaseLine,
Line,
Scrapbox,
} from "https://raw.githubusercontent.com/scrapbox-jp/types/0.7.1/userscript.ts";
} from "https://raw.githubusercontent.com/scrapbox-jp/types/0.9.0/userscript.ts";
export type {
BaseStore,
} from "https://raw.githubusercontent.com/scrapbox-jp/types/0.7.1/baseStore.ts";
} from "https://raw.githubusercontent.com/scrapbox-jp/types/0.9.0/baseStore.ts";
export * from "https://esm.sh/@progfay/[email protected]";
138 changes: 0 additions & 138 deletions rest/getSnapshots.ts

This file was deleted.

2 changes: 1 addition & 1 deletion rest/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export * from "./project.ts";
export * from "./profile.ts";
export * from "./replaceLinks.ts";
export * from "./page-data.ts";
export * from "./getSnapshots.ts";
export * from "./snapshot.ts";
export * from "./link.ts";
export * from "./search.ts";
export * from "./getWebPageTitle.ts";
Expand Down
93 changes: 93 additions & 0 deletions rest/snapshot.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import type {
ErrorLike,
NotFoundError,
NotLoggedInError,
NotMemberError,
PageSnapshotList,
PageSnapshotResult,
} from "../deps/scrapbox-rest.ts";
import { cookie } from "./auth.ts";
import { BaseOptions, Result, setDefaults } from "./util.ts";
import { makeError } from "./error.ts";

/** 不正な`timestampId`を渡されたときに発生するエラー */
export interface InvalidPageSnapshotIdError extends ErrorLike {
name: "InvalidPageSnapshotIdError";
}

/** get a page snapshot
*
* @param options connect.sid etc.
*/
export const getSnapshot = async (
project: string,
pageId: string,
timestampId: string,
options?: BaseOptions,
): Promise<
Result<
PageSnapshotResult,
| NotFoundError
| NotLoggedInError
| NotMemberError
| InvalidPageSnapshotIdError
>
> => {
const { sid, hostName, fetch } = setDefaults(options ?? {});

const req = new Request(
`https://${hostName}/api/page-snapshots/${project}/${pageId}/${timestampId}`,
sid ? { headers: { Cookie: cookie(sid) } } : undefined,
);

const res = await fetch(req);

if (!res.ok) {
if (res.status === 422) {
return {
ok: false,
value: {
name: "InvalidPageSnapshotIdError",
message: await res.text(),
},
};
}
return makeError<NotFoundError | NotLoggedInError | NotMemberError>(res);
}

const value = (await res.json()) as PageSnapshotResult;
return { ok: true, value };
};

/**
* Retrieves the timestamp IDs for a specific page in a project.
*
* @param project - The name of the project.
* @param pageId - The ID of the page.
* @param options - Optional configuration options.
* @returns A promise that resolves to a {@link Result} object containing the page snapshot list if successful,
* or an error if the request fails.
*/
export const getTimestampIds = async (
project: string,
pageId: string,
options?: BaseOptions,
): Promise<
Result<PageSnapshotList, NotFoundError | NotLoggedInError | NotMemberError>
> => {
const { sid, hostName, fetch } = setDefaults(options ?? {});

const req = new Request(
`https://${hostName}/api/page-snapshots/${project}/${pageId}`,
sid ? { headers: { Cookie: cookie(sid) } } : undefined,
);

const res = await fetch(req);

if (!res.ok) {
return makeError<NotFoundError | NotLoggedInError | NotMemberError>(res);
}

const value = (await res.json()) as PageSnapshotList;
return { ok: true, value };
};
Loading