diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e676bf6..174078b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,7 +1,7 @@ name: ci env: - DENO_VERSION: 1.x + DENO_VERSION: 2.x on: [push, pull_request] @@ -10,7 +10,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: denoland/setup-deno@v1 + - uses: denoland/setup-deno@v2 with: deno-version: ${{ env.DENO_VERSION }} - name: Check fmt & lint & type check & test diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 10c9d01..db1f23c 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -2,7 +2,7 @@ name: publish env: - DENO_VERSION: 1.x + DENO_VERSION: 2.x on: push: @@ -18,7 +18,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: denoland/setup-deno@v1 + - uses: denoland/setup-deno@v2 with: deno-version: ${{ env.DENO_VERSION }} - name: Publish on tag diff --git a/browser/dom/getCachedLines.ts b/browser/dom/getCachedLines.ts index 2f5f2e0..2a0b1ba 100644 --- a/browser/dom/getCachedLines.ts +++ b/browser/dom/getCachedLines.ts @@ -1,11 +1,14 @@ import type { Line, Scrapbox } from "@cosense/types/userscript"; declare const scrapbox: Scrapbox; -let isLatestData = false; -let lines: typeof scrapbox.Page.lines = null; +let isLatestData = /* @__PURE__ */ false; +let lines: Line[] | null = /* @__PURE__ */ null; -scrapbox.addListener("lines:changed", () => isLatestData = false); -scrapbox.addListener("layout:changed", () => isLatestData = false); +let initialize: (() => void) | undefined = () => { + scrapbox.addListener("lines:changed", () => isLatestData = false); + scrapbox.addListener("layout:changed", () => isLatestData = false); + initialize = undefined; +}; /** scrapbox.Page.linesをcacheして取得する * @@ -14,6 +17,7 @@ scrapbox.addListener("layout:changed", () => isLatestData = false); * @return `scrapbox.Page.lines`と同じ。常に最新のものが返される */ export const getCachedLines = (): readonly Line[] | null => { + initialize?.(); if (!isLatestData) { lines = scrapbox.Page.lines; isLatestData = true; diff --git a/browser/dom/textInputEventListener.ts b/browser/dom/textInputEventListener.ts index 4bb05ba..3f1c76f 100644 --- a/browser/dom/textInputEventListener.ts +++ b/browser/dom/textInputEventListener.ts @@ -7,11 +7,34 @@ declare const scrapbox: Scrapbox; * - second key: listener * - value: encoded options */ -const listenerMap = new Map< +const listenerMap = /* @__PURE__ */ new Map< keyof HTMLElementEventMap, Map> >(); -const onceListenerMap = new Map>(); +const onceListenerMap = /* @__PURE__ */ new Map< + EventListener, + Map +>(); + +/** re-register event listeners when the layout changes */ +let reRegister: (() => void) | undefined = () => { + scrapbox.on("layout:changed", () => { + const textinput = textInput(); + if (!textinput) return; + for (const [name, argMap] of listenerMap) { + for (const [listener, encodedOptions] of argMap) { + for (const encoded of encodedOptions) { + textinput.addEventListener( + name, + listener as EventListener, + decode(encoded), + ); + } + } + } + }); + reRegister = undefined; +}; /** `#text-input`に対してイベントリスナーを追加する * @@ -30,6 +53,7 @@ export const addTextInputEventListener = ( ) => unknown, options?: boolean | AddEventListenerOptions, ): void => { + reRegister?.(); const argMap = listenerMap.get(name) ?? new Map>(); const encodedOptions = argMap.get(listener as EventListener) ?? new Set(); if (encodedOptions.has(encode(options))) return; @@ -62,23 +86,6 @@ export const addTextInputEventListener = ( textinput.addEventListener(name, listener, options); }; -// re-register event listeners when the layout changes -scrapbox.on("layout:changed", () => { - const textinput = textInput(); - if (!textinput) return; - for (const [name, argMap] of listenerMap) { - for (const [listener, encodedOptions] of argMap) { - for (const encoded of encodedOptions) { - textinput.addEventListener( - name, - listener as EventListener, - decode(encoded), - ); - } - } - } -}); - export const removeTextInputEventListener = < K extends keyof HTMLElementEventMap, >( @@ -86,6 +93,7 @@ export const removeTextInputEventListener = < listener: (event: HTMLElementEventMap[K]) => unknown, options?: boolean | AddEventListenerOptions, ): void => { + reRegister?.(); const argMap = listenerMap.get(name); if (!argMap) return; const encodedOptions = argMap.get(listener as EventListener); diff --git a/deno.lock b/deno.lock index a6f715e..a104694 100644 --- a/deno.lock +++ b/deno.lock @@ -1,173 +1,176 @@ { - "version": "3", - "packages": { - "specifiers": { - "jsr:@core/unknownutil@^4.0.0": "jsr:@core/unknownutil@4.3.0", - "jsr:@cosense/types@0.10": "jsr:@cosense/types@0.10.1", - "jsr:@progfay/scrapbox-parser@9": "jsr:@progfay/scrapbox-parser@9.1.5", - "jsr:@std/assert@1": "jsr:@std/assert@1.0.7", - "jsr:@std/assert@^1.0.7": "jsr:@std/assert@1.0.7", - "jsr:@std/async@1": "jsr:@std/async@1.0.8", - "jsr:@std/async@^1.0.8": "jsr:@std/async@1.0.8", - "jsr:@std/bytes@^1.0.2": "jsr:@std/bytes@1.0.2", - "jsr:@std/data-structures@^1.0.4": "jsr:@std/data-structures@1.0.4", - "jsr:@std/encoding@1": "jsr:@std/encoding@1.0.5", - "jsr:@std/fs@^1.0.5": "jsr:@std/fs@1.0.5", - "jsr:@std/internal@^1.0.5": "jsr:@std/internal@1.0.5", - "jsr:@std/json@^1.0.0": "jsr:@std/json@1.0.1", - "jsr:@std/path@^1.0.7": "jsr:@std/path@1.0.8", - "jsr:@std/path@^1.0.8": "jsr:@std/path@1.0.8", - "jsr:@std/streams@^1.0.7": "jsr:@std/streams@1.0.7", - "jsr:@std/testing@1": "jsr:@std/testing@1.0.4", - "jsr:@takker/md5@0.1": "jsr:@takker/md5@0.1.0", - "npm:option-t@^50.0.0": "npm:option-t@50.0.0", - "npm:socket.io-client@^4.7.5": "npm:socket.io-client@4.8.1" - }, - "jsr": { - "@core/unknownutil@4.3.0": { - "integrity": "538a3687ffa81028e91d148818047df219663d0da671d906cecd165581ae55cc" - }, - "@cosense/types@0.10.1": { - "integrity": "13d2488a02c7b0b035a265bc3299affbdab1ea5b607516379685965cd37b2058" - }, - "@progfay/scrapbox-parser@9.1.5": { - "integrity": "729a086b6675dd4a216875757c918c6bbea329d6e35e410516a16bbd6c468369" - }, - "@std/assert@1.0.7": { - "integrity": "64ce9fac879e0b9f3042a89b3c3f8ccfc9c984391af19e2087513a79d73e28c3", - "dependencies": [ - "jsr:@std/internal@^1.0.5" - ] - }, - "@std/async@1.0.6": { - "integrity": "6d262156dd35c4a72ee1a2f8679be40264f370cfb92e2e13d4eca2ae05e16f34" - }, - "@std/async@1.0.7": { - "integrity": "f4fadc0124432e37cba11e8b3880164661a664de00a65118d976848f32f96290" - }, - "@std/async@1.0.8": { - "integrity": "c057c5211a0f1d12e7dcd111ab430091301b8d64b4250052a79d277383bc3ba7" - }, - "@std/bytes@1.0.2": { - "integrity": "fbdee322bbd8c599a6af186a1603b3355e59a5fb1baa139f8f4c3c9a1b3e3d57" - }, - "@std/data-structures@1.0.4": { - "integrity": "fa0e20c11eb9ba673417450915c750a0001405a784e2a4e0c3725031681684a0" - }, - "@std/encoding@1.0.5": { - "integrity": "ecf363d4fc25bd85bd915ff6733a7e79b67e0e7806334af15f4645c569fefc04" - }, - "@std/fs@1.0.5": { - "integrity": "41806ad6823d0b5f275f9849a2640d87e4ef67c51ee1b8fb02426f55e02fd44e", - "dependencies": [ - "jsr:@std/path@^1.0.7" - ] - }, - "@std/internal@1.0.5": { - "integrity": "54a546004f769c1ac9e025abd15a76b6671ddc9687e2313b67376125650dc7ba" - }, - "@std/json@1.0.1": { - "integrity": "1f0f70737e8827f9acca086282e903677bc1bb0c8ffcd1f21bca60039563049f", - "dependencies": [ - "jsr:@std/streams@^1.0.7" - ] - }, - "@std/path@1.0.8": { - "integrity": "548fa456bb6a04d3c1a1e7477986b6cffbce95102d0bb447c67c4ee70e0364be" - }, - "@std/streams@1.0.7": { - "integrity": "1a93917ca0c58c01b2bfb93647189229b1702677f169b6fb61ad6241cd2e499b", - "dependencies": [ - "jsr:@std/bytes@^1.0.2" - ] - }, - "@std/testing@1.0.4": { - "integrity": "ca1368d720b183f572d40c469bb9faf09643ddd77b54f8b44d36ae6b94940576", - "dependencies": [ - "jsr:@std/assert@^1.0.7", - "jsr:@std/async@^1.0.8", - "jsr:@std/data-structures@^1.0.4", - "jsr:@std/fs@^1.0.5", - "jsr:@std/internal@^1.0.5", - "jsr:@std/path@^1.0.8" - ] - }, - "@takker/md5@0.1.0": { - "integrity": "4c423d8247aadf7bcb1eb83c727bf28c05c21906e916517395d00aa157b6eae0" - } - }, - "npm": { - "@socket.io/component-emitter@3.1.2": { - "integrity": "sha512-9BCxFwvbGg/RsZK9tjXd8s4UcwR0MWeFQ1XEKIQVVvAGJyINdrqKMcTRyLoK8Rse1GjzLV9cwjWV1olXRWEXVA==", - "dependencies": {} - }, - "debug@4.3.7": { - "integrity": "sha512-Er2nc/H7RrMXZBFCEim6TCmMk02Z8vLC2Rbi1KEBggpo0fS6l0S1nnapwmIi3yW/+GOJap1Krg4w0Hg80oCqgQ==", - "dependencies": { - "ms": "ms@2.1.3" - } - }, - "engine.io-client@6.6.2": { - "integrity": "sha512-TAr+NKeoVTjEVW8P3iHguO1LO6RlUz9O5Y8o7EY0fU+gY1NYqas7NN3slpFtbXEsLMHk0h90fJMfKjRkQ0qUIw==", - "dependencies": { - "@socket.io/component-emitter": "@socket.io/component-emitter@3.1.2", - "debug": "debug@4.3.7", - "engine.io-parser": "engine.io-parser@5.2.3", - "ws": "ws@8.17.1", - "xmlhttprequest-ssl": "xmlhttprequest-ssl@2.1.2" - } - }, - "engine.io-parser@5.2.3": { - "integrity": "sha512-HqD3yTBfnBxIrbnM1DoD6Pcq8NECnh8d4As1Qgh0z5Gg3jRRIqijury0CL3ghu/edArpUYiYqQiDUQBIs4np3Q==", - "dependencies": {} - }, - "ms@2.1.3": { - "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", - "dependencies": {} - }, - "option-t@50.0.0": { - "integrity": "sha512-zHw9Et+SfAx3Xtl9LagyAjyyzC3pNONEinTAOmZN2IKL0dYa6dthjzwuSRueJ2gLkaTiinQjRDGo/1mKSl70hg==", - "dependencies": {} - }, - "socket.io-client@4.8.1": { - "integrity": "sha512-hJVXfu3E28NmzGk8o1sHhN3om52tRvwYeidbj7xKy2eIIse5IoKX3USlS6Tqt3BHAtflLIkCQBkzVrEEfWUyYQ==", - "dependencies": { - "@socket.io/component-emitter": "@socket.io/component-emitter@3.1.2", - "debug": "debug@4.3.7", - "engine.io-client": "engine.io-client@6.6.2", - "socket.io-parser": "socket.io-parser@4.2.4" - } - }, - "socket.io-parser@4.2.4": { - "integrity": "sha512-/GbIKmo8ioc+NIWIhwdecY0ge+qVBSMdgxGygevmdHj24bsfgtCmcUUcQ5ZzcylGFHsN3k4HB4Cgkl96KVnuew==", - "dependencies": { - "@socket.io/component-emitter": "@socket.io/component-emitter@3.1.2", - "debug": "debug@4.3.7" - } - }, - "ws@8.17.1": { - "integrity": "sha512-6XQFvXTkbfUOZOKKILFG1PDK2NDQs4azKQl26T0YS5CxqWLgXajbPZ+h4gZekJyRqFU8pvnbAbbs/3TgRPy+GQ==", - "dependencies": {} - }, - "xmlhttprequest-ssl@2.1.2": { - "integrity": "sha512-TEU+nJVUUnA4CYJFLvK5X9AOeH4KvDvhIfm0vV1GaQRtchnG0hgK5p8hw/xjv8cunWYCsiPCSDzObPyhEwq3KQ==", - "dependencies": {} - } + "version": "4", + "specifiers": { + "jsr:@core/unknownutil@4": "4.3.0", + "jsr:@cosense/types@0.10": "0.10.1", + "jsr:@progfay/scrapbox-parser@9": "9.1.5", + "jsr:@std/assert@1": "1.0.7", + "jsr:@std/assert@^1.0.7": "1.0.7", + "jsr:@std/async@1": "1.0.8", + "jsr:@std/async@^1.0.8": "1.0.8", + "jsr:@std/bytes@^1.0.2": "1.0.2", + "jsr:@std/data-structures@^1.0.4": "1.0.4", + "jsr:@std/encoding@1": "1.0.5", + "jsr:@std/fs@^1.0.5": "1.0.5", + "jsr:@std/internal@^1.0.5": "1.0.5", + "jsr:@std/json@1": "1.0.1", + "jsr:@std/path@^1.0.7": "1.0.8", + "jsr:@std/path@^1.0.8": "1.0.8", + "jsr:@std/streams@^1.0.7": "1.0.7", + "jsr:@std/testing@1": "1.0.4", + "jsr:@takker/gyazo@*": "0.3.0", + "jsr:@takker/md5@0.1": "0.1.0", + "npm:option-t@*": "50.0.0", + "npm:option-t@50": "50.0.0", + "npm:option-t@^49.1.0": "49.3.0", + "npm:socket.io-client@^4.7.5": "4.8.1" + }, + "jsr": { + "@core/unknownutil@4.3.0": { + "integrity": "538a3687ffa81028e91d148818047df219663d0da671d906cecd165581ae55cc" + }, + "@cosense/types@0.10.1": { + "integrity": "13d2488a02c7b0b035a265bc3299affbdab1ea5b607516379685965cd37b2058" + }, + "@progfay/scrapbox-parser@9.1.5": { + "integrity": "729a086b6675dd4a216875757c918c6bbea329d6e35e410516a16bbd6c468369" + }, + "@std/assert@1.0.7": { + "integrity": "64ce9fac879e0b9f3042a89b3c3f8ccfc9c984391af19e2087513a79d73e28c3", + "dependencies": [ + "jsr:@std/internal" + ] + }, + "@std/async@1.0.6": { + "integrity": "6d262156dd35c4a72ee1a2f8679be40264f370cfb92e2e13d4eca2ae05e16f34" + }, + "@std/async@1.0.7": { + "integrity": "f4fadc0124432e37cba11e8b3880164661a664de00a65118d976848f32f96290" + }, + "@std/async@1.0.8": { + "integrity": "c057c5211a0f1d12e7dcd111ab430091301b8d64b4250052a79d277383bc3ba7" + }, + "@std/bytes@1.0.2": { + "integrity": "fbdee322bbd8c599a6af186a1603b3355e59a5fb1baa139f8f4c3c9a1b3e3d57" + }, + "@std/data-structures@1.0.4": { + "integrity": "fa0e20c11eb9ba673417450915c750a0001405a784e2a4e0c3725031681684a0" + }, + "@std/encoding@1.0.5": { + "integrity": "ecf363d4fc25bd85bd915ff6733a7e79b67e0e7806334af15f4645c569fefc04" + }, + "@std/fs@1.0.5": { + "integrity": "41806ad6823d0b5f275f9849a2640d87e4ef67c51ee1b8fb02426f55e02fd44e", + "dependencies": [ + "jsr:@std/path@^1.0.7" + ] + }, + "@std/internal@1.0.5": { + "integrity": "54a546004f769c1ac9e025abd15a76b6671ddc9687e2313b67376125650dc7ba" + }, + "@std/json@1.0.1": { + "integrity": "1f0f70737e8827f9acca086282e903677bc1bb0c8ffcd1f21bca60039563049f", + "dependencies": [ + "jsr:@std/streams" + ] + }, + "@std/path@1.0.8": { + "integrity": "548fa456bb6a04d3c1a1e7477986b6cffbce95102d0bb447c67c4ee70e0364be" + }, + "@std/streams@1.0.7": { + "integrity": "1a93917ca0c58c01b2bfb93647189229b1702677f169b6fb61ad6241cd2e499b", + "dependencies": [ + "jsr:@std/bytes" + ] + }, + "@std/testing@1.0.4": { + "integrity": "ca1368d720b183f572d40c469bb9faf09643ddd77b54f8b44d36ae6b94940576", + "dependencies": [ + "jsr:@std/assert@^1.0.7", + "jsr:@std/async@^1.0.8", + "jsr:@std/data-structures", + "jsr:@std/fs", + "jsr:@std/internal", + "jsr:@std/path@^1.0.8" + ] + }, + "@takker/gyazo@0.3.0": { + "integrity": "fb8d602e3d76ac95bc0dc648480ef5165e5e964ecf17a9daea8bda4c0aa0028a", + "dependencies": [ + "npm:option-t@^49.1.0" + ] + }, + "@takker/md5@0.1.0": { + "integrity": "4c423d8247aadf7bcb1eb83c727bf28c05c21906e916517395d00aa157b6eae0" + } + }, + "npm": { + "@socket.io/component-emitter@3.1.2": { + "integrity": "sha512-9BCxFwvbGg/RsZK9tjXd8s4UcwR0MWeFQ1XEKIQVVvAGJyINdrqKMcTRyLoK8Rse1GjzLV9cwjWV1olXRWEXVA==" + }, + "debug@4.3.7": { + "integrity": "sha512-Er2nc/H7RrMXZBFCEim6TCmMk02Z8vLC2Rbi1KEBggpo0fS6l0S1nnapwmIi3yW/+GOJap1Krg4w0Hg80oCqgQ==", + "dependencies": [ + "ms" + ] + }, + "engine.io-client@6.6.2": { + "integrity": "sha512-TAr+NKeoVTjEVW8P3iHguO1LO6RlUz9O5Y8o7EY0fU+gY1NYqas7NN3slpFtbXEsLMHk0h90fJMfKjRkQ0qUIw==", + "dependencies": [ + "@socket.io/component-emitter", + "debug", + "engine.io-parser", + "ws", + "xmlhttprequest-ssl" + ] + }, + "engine.io-parser@5.2.3": { + "integrity": "sha512-HqD3yTBfnBxIrbnM1DoD6Pcq8NECnh8d4As1Qgh0z5Gg3jRRIqijury0CL3ghu/edArpUYiYqQiDUQBIs4np3Q==" + }, + "ms@2.1.3": { + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==" + }, + "option-t@49.3.0": { + "integrity": "sha512-MQFSbqNnjEzQahREx7r1tESmK2UctFK+zmwmnHpBHROJvoRGM9tDMWi53B6ePyFJyAiggRRV9cuXedkpLBeC8w==" + }, + "option-t@50.0.0": { + "integrity": "sha512-zHw9Et+SfAx3Xtl9LagyAjyyzC3pNONEinTAOmZN2IKL0dYa6dthjzwuSRueJ2gLkaTiinQjRDGo/1mKSl70hg==" + }, + "socket.io-client@4.8.1": { + "integrity": "sha512-hJVXfu3E28NmzGk8o1sHhN3om52tRvwYeidbj7xKy2eIIse5IoKX3USlS6Tqt3BHAtflLIkCQBkzVrEEfWUyYQ==", + "dependencies": [ + "@socket.io/component-emitter", + "debug", + "engine.io-client", + "socket.io-parser" + ] + }, + "socket.io-parser@4.2.4": { + "integrity": "sha512-/GbIKmo8ioc+NIWIhwdecY0ge+qVBSMdgxGygevmdHj24bsfgtCmcUUcQ5ZzcylGFHsN3k4HB4Cgkl96KVnuew==", + "dependencies": [ + "@socket.io/component-emitter", + "debug" + ] + }, + "ws@8.17.1": { + "integrity": "sha512-6XQFvXTkbfUOZOKKILFG1PDK2NDQs4azKQl26T0YS5CxqWLgXajbPZ+h4gZekJyRqFU8pvnbAbbs/3TgRPy+GQ==" + }, + "xmlhttprequest-ssl@2.1.2": { + "integrity": "sha512-TEU+nJVUUnA4CYJFLvK5X9AOeH4KvDvhIfm0vV1GaQRtchnG0hgK5p8hw/xjv8cunWYCsiPCSDzObPyhEwq3KQ==" } }, - "remote": {}, "workspace": { "dependencies": [ - "jsr:@core/unknownutil@^4.0.0", + "jsr:@core/unknownutil@4", "jsr:@cosense/types@0.10", "jsr:@progfay/scrapbox-parser@9", "jsr:@std/assert@1", "jsr:@std/async@1", "jsr:@std/encoding@1", - "jsr:@std/json@^1.0.0", + "jsr:@std/json@1", "jsr:@std/testing@1", "jsr:@takker/md5@0.1", - "npm:option-t@^50.0.0", + "npm:option-t@50", "npm:socket.io-client@^4.7.5" ] } diff --git a/rest/getCodeBlock.ts b/rest/getCodeBlock.ts index 4a43dfd..42a25f4 100644 --- a/rest/getCodeBlock.ts +++ b/rest/getCodeBlock.ts @@ -92,16 +92,20 @@ export type CodeBlockError = * @param filename 取得したいコードブロックのファイル名 * @param options オプション */ -export const getCodeBlock: GetCodeBlock = async ( - project, - title, - filename, - options, -) => { - const req = getCodeBlock_toRequest(project, title, filename, options); - const res = await setDefaults(options ?? {}).fetch(req); - return isErr(res) ? res : getCodeBlock_fromResponse(unwrapOk(res)); -}; +export const getCodeBlock: GetCodeBlock = /* @__PURE__ */ (() => { + const fn: GetCodeBlock = async ( + project, + title, + filename, + options, + ) => { + const req = getCodeBlock_toRequest(project, title, filename, options); + const res = await setDefaults(options ?? {}).fetch(req); + return isErr(res) ? res : getCodeBlock_fromResponse(unwrapOk(res)); + }; + + fn.toRequest = getCodeBlock_toRequest; + fn.fromResponse = getCodeBlock_fromResponse; -getCodeBlock.toRequest = getCodeBlock_toRequest; -getCodeBlock.fromResponse = getCodeBlock_fromResponse; + return fn; +})(); diff --git a/rest/link.ts b/rest/link.ts index 369da87..49cbbd3 100644 --- a/rest/link.ts +++ b/rest/link.ts @@ -106,16 +106,19 @@ const getLinks_fromResponse: GetLinks["fromResponse"] = async (response) => * * @param project データを取得したいproject */ -export const getLinks: GetLinks = async (project, options) => { - const res = await setDefaults(options ?? {}).fetch( - getLinks_toRequest(project, options), - ); - if (isErr(res)) return res; - return getLinks_fromResponse(unwrapOk(res)); -}; +export const getLinks: GetLinks = /* @__PURE__ */ (() => { + const fn: GetLinks = async (project, options) => { + const res = await setDefaults(options ?? {}).fetch( + getLinks_toRequest(project, options), + ); + if (isErr(res)) return res; + return getLinks_fromResponse(unwrapOk(res)); + }; -getLinks.toRequest = getLinks_toRequest; -getLinks.fromResponse = getLinks_fromResponse; + fn.toRequest = getLinks_toRequest; + fn.fromResponse = getLinks_fromResponse; + return fn; +})(); /** 指定したprojectの全てのリンクデータを取得する * diff --git a/rest/pages.ts b/rest/pages.ts index bd757fd..bc86592 100644 --- a/rest/pages.ts +++ b/rest/pages.ts @@ -121,20 +121,24 @@ export type PageError = * @param title 取得したいページのtitle 大文字小文字は問わない * @param options オプション */ -export const getPage: GetPage = async ( - project, - title, - options, -) => - andThenAsyncForResult( - await setDefaults(options ?? {}).fetch( - getPage_toRequest(project, title, options), - ), - (input) => getPage_fromResponse(input), - ); +export const getPage: GetPage = /* @__PURE__ */ (() => { + const fn: GetPage = async ( + project, + title, + options, + ) => + andThenAsyncForResult( + await setDefaults(options ?? {}).fetch( + getPage_toRequest(project, title, options), + ), + (input) => getPage_fromResponse(input), + ); -getPage.toRequest = getPage_toRequest; -getPage.fromResponse = getPage_fromResponse; + fn.toRequest = getPage_toRequest; + fn.fromResponse = getPage_fromResponse; + + return fn; +})(); /** Options for `listPages()` */ export interface ListPagesOption extends BaseOptions { @@ -231,16 +235,20 @@ const listPages_fromResponse: ListPages["fromResponse"] = async (res) => * @param project 一覧したいproject * @param options オプション 取得範囲や並び順を決める */ -export const listPages: ListPages = async ( - project, - options?, -) => - andThenAsyncForResult( - await setDefaults(options ?? {})?.fetch( - listPages_toRequest(project, options), - ), - listPages_fromResponse, - ); +export const listPages: ListPages = /* @__PURE__ */ (() => { + const fn: ListPages = async ( + project, + options?, + ) => + andThenAsyncForResult( + await setDefaults(options ?? {})?.fetch( + listPages_toRequest(project, options), + ), + listPages_fromResponse, + ); + + fn.toRequest = listPages_toRequest; + fn.fromResponse = listPages_fromResponse; -listPages.toRequest = listPages_toRequest; -listPages.fromResponse = listPages_fromResponse; + return fn; +})(); diff --git a/rest/parseHTTPError.ts b/rest/parseHTTPError.ts index 54f6d00..003ed9b 100644 --- a/rest/parseHTTPError.ts +++ b/rest/parseHTTPError.ts @@ -80,7 +80,7 @@ export const parseHTTPError = async < } }; -const isLoginStrategies = isLiteralOneOf( +const isLoginStrategies = /* @__PURE__ */ isLiteralOneOf( [ "google", "github", diff --git a/rest/profile.ts b/rest/profile.ts index d18b5d6..6e29310 100644 --- a/rest/profile.ts +++ b/rest/profile.ts @@ -52,14 +52,17 @@ const getProfile_fromResponse: GetProfile["fromResponse"] = (response) => async (res) => (await res.json()) as MemberUser | GuestUser, ); -export const getProfile: GetProfile = async (init) => { - const { fetch, ...rest } = setDefaults(init ?? {}); +export const getProfile: GetProfile = /* @__PURE__ */ (() => { + const fn: GetProfile = async (init) => { + const { fetch, ...rest } = setDefaults(init ?? {}); - const resResult = await fetch(getProfile_toRequest(rest)); - return isErr(resResult) - ? resResult - : getProfile_fromResponse(unwrapOk(resResult)); -}; + const resResult = await fetch(getProfile_toRequest(rest)); + return isErr(resResult) + ? resResult + : getProfile_fromResponse(unwrapOk(resResult)); + }; -getProfile.toRequest = getProfile_toRequest; -getProfile.fromResponse = getProfile_fromResponse; + fn.toRequest = getProfile_toRequest; + fn.fromResponse = getProfile_fromResponse; + return fn; +})(); diff --git a/rest/project.ts b/rest/project.ts index c352d02..24de85d 100644 --- a/rest/project.ts +++ b/rest/project.ts @@ -83,21 +83,25 @@ const getProject_fromResponse: GetProject["fromResponse"] = async (res) => * @param project project name to get * @param init connect.sid etc. */ -export const getProject: GetProject = async ( - project, - init, -) => { - const { fetch } = setDefaults(init ?? {}); +export const getProject: GetProject = /* @__PURE__ */ (() => { + const fn: GetProject = async ( + project, + init, + ) => { + const { fetch } = setDefaults(init ?? {}); - const req = getProject_toRequest(project, init); - const res = await fetch(req); - if (isErr(res)) return res; + const req = getProject_toRequest(project, init); + const res = await fetch(req); + if (isErr(res)) return res; - return getProject_fromResponse(unwrapOk(res)); -}; + return getProject_fromResponse(unwrapOk(res)); + }; + + fn.toRequest = getProject_toRequest; + fn.fromResponse = getProject_fromResponse; -getProject.toRequest = getProject_toRequest; -getProject.fromResponse = getProject_fromResponse; + return fn; +})(); export interface ListProjects { /** /api/project の要求を組み立てる @@ -155,17 +159,21 @@ const ListProject_fromResponse: ListProjects["fromResponse"] = async (res) => * @param projectIds project ids. This must have more than 1 id * @param init connect.sid etc. */ -export const listProjects: ListProjects = async ( - projectIds, - init, -) => { - const { fetch } = setDefaults(init ?? {}); +export const listProjects: ListProjects = /* @__PURE__ */ (() => { + const fn: ListProjects = async ( + projectIds, + init, + ) => { + const { fetch } = setDefaults(init ?? {}); - const res = await fetch(ListProject_toRequest(projectIds, init)); - if (isErr(res)) return res; + const res = await fetch(ListProject_toRequest(projectIds, init)); + if (isErr(res)) return res; - return ListProject_fromResponse(unwrapOk(res)); -}; + return ListProject_fromResponse(unwrapOk(res)); + }; + + fn.toRequest = ListProject_toRequest; + fn.fromResponse = ListProject_fromResponse; -listProjects.toRequest = ListProject_toRequest; -listProjects.fromResponse = ListProject_fromResponse; + return fn; +})(); diff --git a/rest/table.ts b/rest/table.ts index c34d381..b013265 100644 --- a/rest/table.ts +++ b/rest/table.ts @@ -97,18 +97,22 @@ export interface GetTable { * @param filename テーブルの名前 * @param options オプション */ -export const getTable: GetTable = async ( - project, - title, - filename, - options, -) => { - const { fetch } = setDefaults(options ?? {}); - const req = getTable_toRequest(project, title, filename, options); - const res = await fetch(req); - if (isErr(res)) return res; - return await getTable_fromResponse(unwrapOk(res)); -}; +export const getTable: GetTable = /* @__PURE__ */ (() => { + const fn: GetTable = async ( + project, + title, + filename, + options, + ) => { + const { fetch } = setDefaults(options ?? {}); + const req = getTable_toRequest(project, title, filename, options); + const res = await fetch(req); + if (isErr(res)) return res; + return await getTable_fromResponse(unwrapOk(res)); + }; + + fn.toRequest = getTable_toRequest; + fn.fromResponse = getTable_fromResponse; -getTable.toRequest = getTable_toRequest; -getTable.fromResponse = getTable_fromResponse; + return fn; +})(); diff --git a/script.ts b/script.ts new file mode 100644 index 0000000..7837ff7 --- /dev/null +++ b/script.ts @@ -0,0 +1 @@ +import "./browser/dom/mod.ts";