ref0-git 0.0.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/app/apps/github/.dev.vars.example +6 -0
- package/app/apps/github/README.md +70 -0
- package/app/apps/github/THIRD_PARTY_NOTICES.md +214 -0
- package/app/apps/github/components.json +25 -0
- package/app/apps/github/generated/git-rest.ts +10444 -0
- package/app/apps/github/generated/routeTree.gen.ts +1242 -0
- package/app/apps/github/migrations/postgres/0001_auth.sql +46 -0
- package/app/apps/github/migrations/sql/0001_auth.sql +19 -0
- package/app/apps/github/migrations/sql/0002_passkeys.sql +9 -0
- package/app/apps/github/migrations/sql/0003_orgs.sql +22 -0
- package/app/apps/github/migrations/sql/0004_avatars.sql +6 -0
- package/app/apps/github/package.json +80 -0
- package/app/apps/github/src/branches/branch-list.tsx +385 -0
- package/app/apps/github/src/branches/branches.ts +55 -0
- package/app/apps/github/src/clients/allowed.ts +213 -0
- package/app/apps/github/src/clients/at-most.ts +17 -0
- package/app/apps/github/src/clients/avatars.ts +410 -0
- package/app/apps/github/src/clients/cached.ts +65 -0
- package/app/apps/github/src/clients/calls.ts +160 -0
- package/app/apps/github/src/clients/clients.ts +82 -0
- package/app/apps/github/src/clients/graphql.ts +50 -0
- package/app/apps/github/src/clients/host-answer.ts +28 -0
- package/app/apps/github/src/clients/host-calls.ts +382 -0
- package/app/apps/github/src/clients/icon-bytes.ts +203 -0
- package/app/apps/github/src/clients/proxy.ts +59 -0
- package/app/apps/github/src/clients/session-ended.ts +18 -0
- package/app/apps/github/src/clients/transfers.ts +212 -0
- package/app/apps/github/src/code/breadcrumbs.tsx +50 -0
- package/app/apps/github/src/code/code-page.tsx +147 -0
- package/app/apps/github/src/code/code-tree.tsx +338 -0
- package/app/apps/github/src/code/controls.tsx +230 -0
- package/app/apps/github/src/code/file-view.tsx +450 -0
- package/app/apps/github/src/code/files.ts +332 -0
- package/app/apps/github/src/code/folder-list.tsx +122 -0
- package/app/apps/github/src/code/go-to-file.tsx +131 -0
- package/app/apps/github/src/code/highlighted.tsx +58 -0
- package/app/apps/github/src/code/lines.ts +46 -0
- package/app/apps/github/src/code/load.ts +147 -0
- package/app/apps/github/src/code/markdown-files.ts +58 -0
- package/app/apps/github/src/code/places.ts +88 -0
- package/app/apps/github/src/code/ref-pages.ts +179 -0
- package/app/apps/github/src/code/ref-switcher.tsx +203 -0
- package/app/apps/github/src/code/refs.ts +142 -0
- package/app/apps/github/src/code/repo-home.tsx +240 -0
- package/app/apps/github/src/code/repo.ts +105 -0
- package/app/apps/github/src/code/saved-reads.ts +199 -0
- package/app/apps/github/src/code/saved.ts +110 -0
- package/app/apps/github/src/code/tree-fold.ts +186 -0
- package/app/apps/github/src/code/trees.ts +136 -0
- package/app/apps/github/src/components/avatar-picture.ts +53 -0
- package/app/apps/github/src/components/avatar-url.ts +16 -0
- package/app/apps/github/src/components/confirm-action.tsx +100 -0
- package/app/apps/github/src/components/count.tsx +24 -0
- package/app/apps/github/src/components/create-button.tsx +38 -0
- package/app/apps/github/src/components/file-icons/file-icons.css +225 -0
- package/app/apps/github/src/components/file-icons/file-icons.tsx +138 -0
- package/app/apps/github/src/components/filter.tsx +35 -0
- package/app/apps/github/src/components/hotkeys/hotkeys.tsx +255 -0
- package/app/apps/github/src/components/item-list.tsx +65 -0
- package/app/apps/github/src/components/language-dot.tsx +29 -0
- package/app/apps/github/src/components/list-toolbar.tsx +82 -0
- package/app/apps/github/src/components/markdown/editor.tsx +57 -0
- package/app/apps/github/src/components/markdown/markdown.css +177 -0
- package/app/apps/github/src/components/markdown/markdown.tsx +82 -0
- package/app/apps/github/src/components/owner-card.tsx +196 -0
- package/app/apps/github/src/components/pull-status.tsx +34 -0
- package/app/apps/github/src/components/recent.ts +41 -0
- package/app/apps/github/src/components/relative-time.tsx +78 -0
- package/app/apps/github/src/components/repos/icon-hashes.ts +91 -0
- package/app/apps/github/src/components/repos/new-repo-form.tsx +196 -0
- package/app/apps/github/src/components/repos/repo-icon.tsx +47 -0
- package/app/apps/github/src/components/repos/repo-list.tsx +528 -0
- package/app/apps/github/src/components/repos/your-repos.tsx +124 -0
- package/app/apps/github/src/components/review-state.tsx +75 -0
- package/app/apps/github/src/components/route-dialog.tsx +137 -0
- package/app/apps/github/src/components/save-button.tsx +58 -0
- package/app/apps/github/src/components/shell/app-shell.tsx +164 -0
- package/app/apps/github/src/components/shell/create-org-dialog.tsx +118 -0
- package/app/apps/github/src/components/shell/create-row.tsx +49 -0
- package/app/apps/github/src/components/shell/link-menu.tsx +94 -0
- package/app/apps/github/src/components/shell/nav-user.tsx +97 -0
- package/app/apps/github/src/components/shell/owner-repos.tsx +247 -0
- package/app/apps/github/src/components/shell/owner-switcher.tsx +104 -0
- package/app/apps/github/src/components/shell/repo-switcher.tsx +179 -0
- package/app/apps/github/src/components/shell/sections.ts +31 -0
- package/app/apps/github/src/components/shell/submenu-chevron.ts +147 -0
- package/app/apps/github/src/components/signin/device-card.tsx +139 -0
- package/app/apps/github/src/components/signin/login-form.tsx +88 -0
- package/app/apps/github/src/components/signin/signin-page.tsx +33 -0
- package/app/apps/github/src/components/signin/signup-form.tsx +106 -0
- package/app/apps/github/src/components/states/live-status.tsx +42 -0
- package/app/apps/github/src/components/states/states.tsx +126 -0
- package/app/apps/github/src/components/tab-indicator.tsx +143 -0
- package/app/apps/github/src/components/theme-choice.tsx +108 -0
- package/app/apps/github/src/components/theme-provider.tsx +126 -0
- package/app/apps/github/src/components/tones.ts +23 -0
- package/app/apps/github/src/components/ui/alert-dialog.tsx +187 -0
- package/app/apps/github/src/components/ui/alert.tsx +78 -0
- package/app/apps/github/src/components/ui/avatar.tsx +106 -0
- package/app/apps/github/src/components/ui/badge.tsx +51 -0
- package/app/apps/github/src/components/ui/breadcrumb.tsx +124 -0
- package/app/apps/github/src/components/ui/button-group.tsx +87 -0
- package/app/apps/github/src/components/ui/button.tsx +61 -0
- package/app/apps/github/src/components/ui/calendar.tsx +221 -0
- package/app/apps/github/src/components/ui/card.tsx +102 -0
- package/app/apps/github/src/components/ui/checkbox.tsx +26 -0
- package/app/apps/github/src/components/ui/collapsible.tsx +19 -0
- package/app/apps/github/src/components/ui/combobox.tsx +304 -0
- package/app/apps/github/src/components/ui/command.tsx +208 -0
- package/app/apps/github/src/components/ui/dialog.tsx +156 -0
- package/app/apps/github/src/components/ui/dropdown-menu.tsx +290 -0
- package/app/apps/github/src/components/ui/empty.tsx +100 -0
- package/app/apps/github/src/components/ui/field.tsx +236 -0
- package/app/apps/github/src/components/ui/hover-card.tsx +48 -0
- package/app/apps/github/src/components/ui/input-group.tsx +163 -0
- package/app/apps/github/src/components/ui/input.tsx +19 -0
- package/app/apps/github/src/components/ui/item.tsx +201 -0
- package/app/apps/github/src/components/ui/kbd.tsx +27 -0
- package/app/apps/github/src/components/ui/label.tsx +33 -0
- package/app/apps/github/src/components/ui/popover.tsx +87 -0
- package/app/apps/github/src/components/ui/radio-group.tsx +35 -0
- package/app/apps/github/src/components/ui/select.tsx +198 -0
- package/app/apps/github/src/components/ui/separator.tsx +22 -0
- package/app/apps/github/src/components/ui/sheet.tsx +138 -0
- package/app/apps/github/src/components/ui/sidebar.tsx +724 -0
- package/app/apps/github/src/components/ui/skeleton.tsx +13 -0
- package/app/apps/github/src/components/ui/sonner.tsx +47 -0
- package/app/apps/github/src/components/ui/styles.css +242 -0
- package/app/apps/github/src/components/ui/table.tsx +113 -0
- package/app/apps/github/src/components/ui/tabs.tsx +79 -0
- package/app/apps/github/src/components/ui/textarea.tsx +17 -0
- package/app/apps/github/src/components/ui/title.ts +6 -0
- package/app/apps/github/src/components/ui/toggle-group.tsx +89 -0
- package/app/apps/github/src/components/ui/toggle.tsx +42 -0
- package/app/apps/github/src/components/ui/tooltip.tsx +63 -0
- package/app/apps/github/src/components/user-avatar.tsx +145 -0
- package/app/apps/github/src/components/view-tabs.tsx +42 -0
- package/app/apps/github/src/context/context.ts +133 -0
- package/app/apps/github/src/diffs/blobs.ts +94 -0
- package/app/apps/github/src/diffs/diff-view.tsx +155 -0
- package/app/apps/github/src/diffs/files.ts +121 -0
- package/app/apps/github/src/diffs/hunks.tsx +454 -0
- package/app/apps/github/src/diffs/patch.ts +131 -0
- package/app/apps/github/src/diffs/rows.ts +137 -0
- package/app/apps/github/src/history/commit-diff.ts +54 -0
- package/app/apps/github/src/history/commit-list.tsx +207 -0
- package/app/apps/github/src/history/commit-page.tsx +147 -0
- package/app/apps/github/src/history/history.ts +129 -0
- package/app/apps/github/src/hooks/allowed.ts +31 -0
- package/app/apps/github/src/hooks/answers.ts +65 -0
- package/app/apps/github/src/hooks/avatars.ts +54 -0
- package/app/apps/github/src/hooks/draft.ts +38 -0
- package/app/apps/github/src/hooks/open-counts.ts +127 -0
- package/app/apps/github/src/hooks/profiles.ts +120 -0
- package/app/apps/github/src/hooks/repos.ts +440 -0
- package/app/apps/github/src/hooks/use-mobile.ts +19 -0
- package/app/apps/github/src/hooks/viewer.ts +39 -0
- package/app/apps/github/src/inbox/count.ts +70 -0
- package/app/apps/github/src/inbox/inbox-item.tsx +66 -0
- package/app/apps/github/src/inbox/inbox-page.tsx +572 -0
- package/app/apps/github/src/inbox/marks.ts +130 -0
- package/app/apps/github/src/inbox/release-tags.ts +65 -0
- package/app/apps/github/src/inbox/search.ts +97 -0
- package/app/apps/github/src/inbox/subjects.ts +184 -0
- package/app/apps/github/src/inbox/subscription-controls.tsx +184 -0
- package/app/apps/github/src/inbox/subscriptions.ts +189 -0
- package/app/apps/github/src/inbox/threads.ts +198 -0
- package/app/apps/github/src/issues/changes.ts +332 -0
- package/app/apps/github/src/issues/counts.ts +62 -0
- package/app/apps/github/src/issues/issue-list.tsx +682 -0
- package/app/apps/github/src/issues/issue-page.tsx +533 -0
- package/app/apps/github/src/issues/issues.ts +566 -0
- package/app/apps/github/src/issues/label-dialog.tsx +310 -0
- package/app/apps/github/src/issues/labels-page.tsx +119 -0
- package/app/apps/github/src/issues/new-issue.tsx +79 -0
- package/app/apps/github/src/issues/parts.tsx +71 -0
- package/app/apps/github/src/issues/picker.tsx +298 -0
- package/app/apps/github/src/issues/search.ts +238 -0
- package/app/apps/github/src/issues/sidebar.tsx +236 -0
- package/app/apps/github/src/lib/cn.ts +8 -0
- package/app/apps/github/src/lib/highlighting.ts +13 -0
- package/app/apps/github/src/live/follow.ts +129 -0
- package/app/apps/github/src/live/sse.ts +74 -0
- package/app/apps/github/src/live/use-follow.ts +37 -0
- package/app/apps/github/src/markdown/README.md +53 -0
- package/app/apps/github/src/markdown/allowed-html.ts +69 -0
- package/app/apps/github/src/markdown/context.ts +206 -0
- package/app/apps/github/src/markdown/images.ts +81 -0
- package/app/apps/github/src/markdown/lookup.ts +127 -0
- package/app/apps/github/src/markdown/patches.ts +299 -0
- package/app/apps/github/src/markdown/query.ts +25 -0
- package/app/apps/github/src/markdown/references.ts +158 -0
- package/app/apps/github/src/markdown/render.ts +103 -0
- package/app/apps/github/src/names/owners.ts +51 -0
- package/app/apps/github/src/names/repos.ts +24 -0
- package/app/apps/github/src/palette/palette.tsx +562 -0
- package/app/apps/github/src/palette/recent.ts +116 -0
- package/app/apps/github/src/palette/rows.tsx +487 -0
- package/app/apps/github/src/palette/server.ts +107 -0
- package/app/apps/github/src/palette/targets.ts +306 -0
- package/app/apps/github/src/policy.ts +606 -0
- package/app/apps/github/src/private-repos.ts +47 -0
- package/app/apps/github/src/pulls/compare-page.tsx +342 -0
- package/app/apps/github/src/pulls/files-tab.tsx +776 -0
- package/app/apps/github/src/pulls/live.ts +124 -0
- package/app/apps/github/src/pulls/merge-box.tsx +367 -0
- package/app/apps/github/src/pulls/merge-button.ts +86 -0
- package/app/apps/github/src/pulls/pull-list.tsx +235 -0
- package/app/apps/github/src/pulls/pull-page.tsx +474 -0
- package/app/apps/github/src/pulls/pull.ts +468 -0
- package/app/apps/github/src/pulls/pulls.ts +318 -0
- package/app/apps/github/src/pulls/review.ts +350 -0
- package/app/apps/github/src/pulls/search.ts +130 -0
- package/app/apps/github/src/queue/queue-page.tsx +405 -0
- package/app/apps/github/src/queue/queue.ts +231 -0
- package/app/apps/github/src/releases/latest-release.tsx +55 -0
- package/app/apps/github/src/releases/overview.tsx +30 -0
- package/app/apps/github/src/releases/release-form.tsx +353 -0
- package/app/apps/github/src/releases/release-list.tsx +173 -0
- package/app/apps/github/src/releases/release-view.tsx +183 -0
- package/app/apps/github/src/releases/releases.ts +308 -0
- package/app/apps/github/src/releases/tag-list.tsx +134 -0
- package/app/apps/github/src/router.tsx +46 -0
- package/app/apps/github/src/routes/$owner/$repo/_code/blob/$.tsx +33 -0
- package/app/apps/github/src/routes/$owner/$repo/_code/tree/$.tsx +28 -0
- package/app/apps/github/src/routes/$owner/$repo/_code.tsx +11 -0
- package/app/apps/github/src/routes/$owner/$repo/_releases/releases/index.tsx +19 -0
- package/app/apps/github/src/routes/$owner/$repo/_releases/tags.tsx +19 -0
- package/app/apps/github/src/routes/$owner/$repo/_releases.tsx +23 -0
- package/app/apps/github/src/routes/$owner/$repo/branches.tsx +39 -0
- package/app/apps/github/src/routes/$owner/$repo/commit/$sha.tsx +34 -0
- package/app/apps/github/src/routes/$owner/$repo/commits/$.tsx +42 -0
- package/app/apps/github/src/routes/$owner/$repo/compare/$.tsx +19 -0
- package/app/apps/github/src/routes/$owner/$repo/index.tsx +24 -0
- package/app/apps/github/src/routes/$owner/$repo/issues/$number.tsx +50 -0
- package/app/apps/github/src/routes/$owner/$repo/issues/index.tsx +53 -0
- package/app/apps/github/src/routes/$owner/$repo/issues/new.tsx +43 -0
- package/app/apps/github/src/routes/$owner/$repo/labels.tsx +22 -0
- package/app/apps/github/src/routes/$owner/$repo/pull/$number/checks.tsx +15 -0
- package/app/apps/github/src/routes/$owner/$repo/pull/$number/commits.tsx +15 -0
- package/app/apps/github/src/routes/$owner/$repo/pull/$number/files.tsx +15 -0
- package/app/apps/github/src/routes/$owner/$repo/pull/$number/index.tsx +19 -0
- package/app/apps/github/src/routes/$owner/$repo/pull/$number/route.tsx +52 -0
- package/app/apps/github/src/routes/$owner/$repo/pulls/index.tsx +48 -0
- package/app/apps/github/src/routes/$owner/$repo/queue.tsx +22 -0
- package/app/apps/github/src/routes/$owner/$repo/releases/edit/$.tsx +58 -0
- package/app/apps/github/src/routes/$owner/$repo/releases/new.tsx +40 -0
- package/app/apps/github/src/routes/$owner/$repo/releases/tag/$.tsx +35 -0
- package/app/apps/github/src/routes/$owner/$repo/route.tsx +102 -0
- package/app/apps/github/src/routes/$owner/$repo/settings/access.tsx +9 -0
- package/app/apps/github/src/routes/$owner/$repo/settings/hooks/index.tsx +16 -0
- package/app/apps/github/src/routes/$owner/$repo/settings/hooks/new.tsx +25 -0
- package/app/apps/github/src/routes/$owner/$repo/settings/index.tsx +17 -0
- package/app/apps/github/src/routes/$owner/$repo/settings/route.tsx +28 -0
- package/app/apps/github/src/routes/$owner/$repo/settings/rules.tsx +12 -0
- package/app/apps/github/src/routes/$owner/$repo/tokens.tsx +16 -0
- package/app/apps/github/src/routes/$owner/index.tsx +45 -0
- package/app/apps/github/src/routes/-nav.tsx +293 -0
- package/app/apps/github/src/routes/-root-testing.ts +107 -0
- package/app/apps/github/src/routes/__root.tsx +225 -0
- package/app/apps/github/src/routes/api.auth.$.ts +18 -0
- package/app/apps/github/src/routes/downloads/$owner/$repo/$asset.tsx +10 -0
- package/app/apps/github/src/routes/file-icons[.]svg.ts +21 -0
- package/app/apps/github/src/routes/icons/$owner/$repo.tsx +14 -0
- package/app/apps/github/src/routes/icons/$owner/index.tsx +14 -0
- package/app/apps/github/src/routes/icons/index.tsx +12 -0
- package/app/apps/github/src/routes/index.tsx +48 -0
- package/app/apps/github/src/routes/login.tsx +24 -0
- package/app/apps/github/src/routes/login_.code.tsx +31 -0
- package/app/apps/github/src/routes/new.tsx +91 -0
- package/app/apps/github/src/routes/notifications.tsx +20 -0
- package/app/apps/github/src/routes/orgs/$owner/issues.tsx +8 -0
- package/app/apps/github/src/routes/orgs/$owner/pulls.tsx +8 -0
- package/app/apps/github/src/routes/orgs/$owner/releases.tsx +8 -0
- package/app/apps/github/src/routes/orgs/$owner/route.tsx +25 -0
- package/app/apps/github/src/routes/orgs/$owner/settings.tsx +30 -0
- package/app/apps/github/src/routes/orgs/$owner/tokens.tsx +15 -0
- package/app/apps/github/src/routes/settings.tsx +54 -0
- package/app/apps/github/src/routes/signup.tsx +24 -0
- package/app/apps/github/src/routes/uploads/$owner/$repo/$release.tsx +10 -0
- package/app/apps/github/src/seed/acme.ts +498 -0
- package/app/apps/github/src/seed/licenses.ts +114 -0
- package/app/apps/github/src/seed/seed.ts +528 -0
- package/app/apps/github/src/server.ts +97 -0
- package/app/apps/github/src/settings/account-avatar.tsx +43 -0
- package/app/apps/github/src/settings/avatar-section.tsx +140 -0
- package/app/apps/github/src/settings/avatar.ts +58 -0
- package/app/apps/github/src/settings/general-settings.tsx +439 -0
- package/app/apps/github/src/settings/general.ts +73 -0
- package/app/apps/github/src/settings/hook-form.tsx +195 -0
- package/app/apps/github/src/settings/hook-list.tsx +166 -0
- package/app/apps/github/src/settings/hooks.ts +87 -0
- package/app/apps/github/src/settings/org-settings.tsx +228 -0
- package/app/apps/github/src/settings/orgs.ts +116 -0
- package/app/apps/github/src/settings/rule-list.tsx +72 -0
- package/app/apps/github/src/settings/rules.ts +27 -0
- package/app/apps/github/src/settings/settings-layout.tsx +114 -0
- package/app/apps/github/src/signin/approval.ts +186 -0
- package/app/apps/github/src/signin/auth-client.ts +127 -0
- package/app/apps/github/src/signin/auth.ts +753 -0
- package/app/apps/github/src/signin/avatars.ts +126 -0
- package/app/apps/github/src/signin/client-ip.ts +39 -0
- package/app/apps/github/src/signin/credentials.ts +26 -0
- package/app/apps/github/src/signin/device-code.ts +95 -0
- package/app/apps/github/src/signin/device-prompt.ts +125 -0
- package/app/apps/github/src/signin/errors.ts +135 -0
- package/app/apps/github/src/signin/host-session.ts +68 -0
- package/app/apps/github/src/signin/orgs.ts +283 -0
- package/app/apps/github/src/signin/owner-names.ts +183 -0
- package/app/apps/github/src/signin/person-lock.ts +104 -0
- package/app/apps/github/src/signin/seal.ts +88 -0
- package/app/apps/github/src/signin/seed-people.ts +92 -0
- package/app/apps/github/src/signin/session.ts +48 -0
- package/app/apps/github/src/signin/unborn.ts +110 -0
- package/app/apps/github/src/signin/viewer-orgs.ts +47 -0
- package/app/apps/github/src/signin/viewer.ts +74 -0
- package/app/apps/github/src/signin/with-headers.ts +14 -0
- package/app/apps/github/src/tokens/tokens-page.tsx +529 -0
- package/app/apps/github/src/tokens/tokens.ts +54 -0
- package/app/apps/github/tsconfig.json +25 -0
- package/app/apps/github/tsconfig.worker.json +24 -0
- package/app/apps/github/vite.config.ts +21 -0
- package/app/pnpm-workspace.yaml +216 -0
- package/app/tsconfig.base.json +127 -0
- package/dist/LICENSE +202 -0
- package/dist/cli/child.mjs +42 -0
- package/dist/cli/commands.mjs +23 -0
- package/dist/cli/credentials.mjs +84 -0
- package/dist/cli/documents.mjs +214 -0
- package/dist/cli/events.mjs +55 -0
- package/dist/cli/failure.mjs +105 -0
- package/dist/cli/folders.mjs +32 -0
- package/dist/cli/git-remote-ref0.d.mts +1 -0
- package/dist/cli/git-remote-ref0.mjs +29 -0
- package/dist/cli/git.mjs +69 -0
- package/dist/cli/helpers.mjs +184 -0
- package/dist/cli/hosts.mjs +127 -0
- package/dist/cli/node.mjs +15 -0
- package/dist/cli/output.mjs +135 -0
- package/dist/cli/prompt.mjs +35 -0
- package/dist/cli/queue.mjs +215 -0
- package/dist/cli/ref0-git.d.mts +1 -0
- package/dist/cli/ref0-git.mjs +144 -0
- package/dist/cli/repos.mjs +162 -0
- package/dist/cli/resources.mjs +131 -0
- package/dist/cli/run-end.mjs +57 -0
- package/dist/cli/runtime.mjs +50 -0
- package/dist/cli/setup.mjs +1410 -0
- package/dist/cli/sign-in.mjs +162 -0
- package/dist/cli/sign-ins.mjs +136 -0
- package/dist/cli/sqlite.mjs +28 -0
- package/dist/cli/tokens.mjs +141 -0
- package/dist/cli/vendor.mjs +123 -0
- package/dist/init/app.mjs +231 -0
- package/dist/init/astro.mjs +49 -0
- package/dist/init/choices.mjs +497 -0
- package/dist/init/cloudflare.mjs +324 -0
- package/dist/init/create.mjs +151 -0
- package/dist/init/detect.mjs +297 -0
- package/dist/init/files.mjs +80 -0
- package/dist/init/frameworks.mjs +248 -0
- package/dist/init/git-module.mjs +49 -0
- package/dist/init/github-routes.mjs +66 -0
- package/dist/init/jsonc.mjs +143 -0
- package/dist/init/metadata.mjs +48 -0
- package/dist/init/mounts.mjs +109 -0
- package/dist/init/next.mjs +203 -0
- package/dist/init/node-app.mjs +189 -0
- package/dist/init/node.mjs +460 -0
- package/dist/init/nuxt.mjs +115 -0
- package/dist/init/output.mjs +21 -0
- package/dist/init/plan.mjs +82 -0
- package/dist/init/range-major.mjs +257 -0
- package/dist/init/react-router.mjs +59 -0
- package/dist/init/routes.mjs +148 -0
- package/dist/init/shell.mjs +4 -0
- package/dist/init/stores.mjs +51 -0
- package/dist/init/sveltekit.mjs +139 -0
- package/dist/init/template.mjs +142 -0
- package/dist/init/templates.mjs +343 -0
- package/dist/init/vercel.mjs +384 -0
- package/dist/init/versions.mjs +32 -0
- package/dist/init/workspace.mjs +20 -0
- package/package.json +48 -6
- package/README.md +0 -5
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
InfiniteData,
|
|
3
|
+
InfiniteQueryExecuteOptions,
|
|
4
|
+
QueryClient,
|
|
5
|
+
QueryExecuteOptions,
|
|
6
|
+
QueryKey,
|
|
7
|
+
} from '@tanstack/react-query';
|
|
8
|
+
|
|
9
|
+
/** What a read ahead keeps of its answer, or of its failure: nothing. */
|
|
10
|
+
const ignore = () => undefined;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Whether a draw waits for `key`'s read: nothing is cached, or a write invalidated it, so the
|
|
14
|
+
* person sees what they just changed.
|
|
15
|
+
*/
|
|
16
|
+
const mustWait = (client: QueryClient, key: QueryKey) => {
|
|
17
|
+
const state = client.getQueryState(key);
|
|
18
|
+
|
|
19
|
+
return state?.data === undefined || state.isInvalidated;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* What a loader draws: `options`' cached data at once, read again behind when it's past its
|
|
24
|
+
* `staleTime`, or read first when nothing is cached or a write invalidated it. A page the tab has
|
|
25
|
+
* read draws without waiting on the network, as F10 asks. A page's `useQuery` of it updates in
|
|
26
|
+
* place once the refresh answers; a loader's own data updates on the next navigation.
|
|
27
|
+
*/
|
|
28
|
+
export const cached = <Data, Key extends QueryKey>(
|
|
29
|
+
client: QueryClient,
|
|
30
|
+
options: QueryExecuteOptions<Data, Error, Data, Data, Key>,
|
|
31
|
+
): Promise<Data> => {
|
|
32
|
+
if (mustWait(client, options.queryKey)) return client.query(options);
|
|
33
|
+
|
|
34
|
+
// Within its `staleTime` this answers from the cache and asks nothing; past it, it reads again.
|
|
35
|
+
void client.query(options).catch(ignore);
|
|
36
|
+
|
|
37
|
+
return client.query({ ...options, staleTime: 'static' });
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/** `cached`, for a list read a page at a time: its pages so far, refreshed behind when stale. */
|
|
41
|
+
export const cachedPages = <Page, Key extends QueryKey, Param>(
|
|
42
|
+
client: QueryClient,
|
|
43
|
+
options: InfiniteQueryExecuteOptions<Page, Error, InfiniteData<Page, Param>, Key, Param>,
|
|
44
|
+
): Promise<InfiniteData<Page, Param>> => {
|
|
45
|
+
if (mustWait(client, options.queryKey)) return client.infiniteQuery(options);
|
|
46
|
+
|
|
47
|
+
void client.infiniteQuery(options).catch(ignore);
|
|
48
|
+
|
|
49
|
+
return client.infiniteQuery({ ...options, staleTime: 'static' });
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* `cached`, for a read a page wants ready but can draw without: a failure leaves the page's own
|
|
54
|
+
* query to show it and try again, as `prefetchQuery` did.
|
|
55
|
+
*/
|
|
56
|
+
export const readAhead = <Data, Key extends QueryKey>(
|
|
57
|
+
client: QueryClient,
|
|
58
|
+
options: QueryExecuteOptions<Data, Error, Data, Data, Key>,
|
|
59
|
+
): Promise<void> => cached(client, options).then(ignore, ignore);
|
|
60
|
+
|
|
61
|
+
/** `readAhead`, for a list read a page at a time, as `prefetchInfiniteQuery` did. */
|
|
62
|
+
export const readPagesAhead = <Page, Key extends QueryKey, Param>(
|
|
63
|
+
client: QueryClient,
|
|
64
|
+
options: InfiniteQueryExecuteOptions<Page, Error, InfiniteData<Page, Param>, Key, Param>,
|
|
65
|
+
): Promise<void> => cachedPages(client, options).then(ignore, ignore);
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import * as Schema from 'effect/Schema';
|
|
2
|
+
|
|
3
|
+
import type { ApiFetch } from '../context/context.ts';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The APIs the app calls: GitHub's REST and GraphQL, through the drop-in, Git's REST, and the
|
|
7
|
+
* drop-in's raw route, which streams an LFS file's object as the viewer (Q506).
|
|
8
|
+
*/
|
|
9
|
+
export type ApiName = 'github' | 'graphql' | 'git' | 'raw';
|
|
10
|
+
|
|
11
|
+
/** An HTTP date, as `Last-Modified` sends one: `Sun, 23 Nov 2026 20:15:00 GMT`. */
|
|
12
|
+
const httpDate = /^[A-Z][a-z]{2}, \d{2} [A-Z][a-z]{2} \d{4} \d{2}:\d{2}:\d{2} GMT$/;
|
|
13
|
+
|
|
14
|
+
/** One call, as the browser hands it to the server: never with a credential, which only the server adds. */
|
|
15
|
+
const ApiCall = Schema.Struct({
|
|
16
|
+
api: Schema.Literals(['github', 'graphql', 'git', 'raw']),
|
|
17
|
+
method: Schema.Literals(['GET', 'HEAD', 'POST', 'PUT', 'PATCH', 'DELETE']),
|
|
18
|
+
/** The path under the API's base, with its query: `/user/repos?sort=updated`. */
|
|
19
|
+
path: Schema.String.check(Schema.isStartingWith('/')),
|
|
20
|
+
/** The body as bytes, so a blob's or an upload's survive the trip as they were. */
|
|
21
|
+
body: Schema.optional(Schema.Uint8Array),
|
|
22
|
+
contentType: Schema.optional(Schema.String),
|
|
23
|
+
accept: Schema.optional(Schema.String),
|
|
24
|
+
/** A stream's cursor, resumed after: a `seq` or an event's ID, as `Last-Event-ID` sends it. */
|
|
25
|
+
lastEventId: Schema.optional(Schema.String.check(Schema.isPattern(/^\d{1,15}$/))),
|
|
26
|
+
/** The copy a poll holds, by the `Last-Modified` its answer sent: an HTTP date, and nothing else. */
|
|
27
|
+
ifModifiedSince: Schema.optional(Schema.String.check(Schema.isPattern(httpDate))),
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
export type ApiCall = typeof ApiCall.Type;
|
|
31
|
+
|
|
32
|
+
/** Where each API's paths start on the app's origin. */
|
|
33
|
+
export const apiBases: Readonly<Record<ApiName, string>> = {
|
|
34
|
+
github: '/api/v3',
|
|
35
|
+
graphql: '',
|
|
36
|
+
git: '',
|
|
37
|
+
raw: '',
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const gitRoots: ReadonlySet<string> = new Set(['/me', '/repos', '/tokens']);
|
|
41
|
+
|
|
42
|
+
/** A queue's ID of `kind`, as Git's `queue/ids.ts` makes one: `e_r_…_41`. */
|
|
43
|
+
const queueIdOf = (kind: 'e' | 'c' | 'h') => `${kind}_r_[A-Za-z0-9_-]{16}_[1-9][0-9]{0,14}`;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Git's queue's own URLs, by an entry's, a hold's or a candidate's ID, as `rest/queue.ts` serves
|
|
47
|
+
* them: only these, and only by an ID a queue makes, so no Smart HTTP URL of a repo an owner named
|
|
48
|
+
* `queue` holds is one, as `/queue/entries/git-upload-pack` would be.
|
|
49
|
+
*/
|
|
50
|
+
const queuePath = new RegExp(
|
|
51
|
+
`^/queue/(entries/${queueIdOf('e')}(/holds)?|holds/${queueIdOf('h')}|candidates/${queueIdOf('c')}/(report|retry))$`,
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
/** The raw route's URLs: `/{owner}/{repo}/raw/{ref}/{path}`, and no other root path. */
|
|
55
|
+
const rawPath = /^\/[^/]+\/[^/]+\/raw\/[^/]+\/[^/]/;
|
|
56
|
+
|
|
57
|
+
/** Whether `pathname` is one of `api`'s own URLs: never sign-in's, Smart HTTP's or the app's. */
|
|
58
|
+
const ownedBy = (api: ApiName, pathname: string) => {
|
|
59
|
+
switch (api) {
|
|
60
|
+
case 'github':
|
|
61
|
+
return pathname.startsWith('/api/v3/');
|
|
62
|
+
case 'graphql':
|
|
63
|
+
return pathname === '/api/graphql';
|
|
64
|
+
case 'git':
|
|
65
|
+
return (
|
|
66
|
+
gitRoots.has(pathname) ||
|
|
67
|
+
pathname.startsWith('/repos/') ||
|
|
68
|
+
pathname.startsWith('/tokens/') ||
|
|
69
|
+
queuePath.test(pathname)
|
|
70
|
+
);
|
|
71
|
+
case 'raw':
|
|
72
|
+
return rawPath.test(pathname);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
/** A browser's call, checked: anything else throws, which the server function answers as a 500. */
|
|
77
|
+
export const parseCall = Schema.decodeUnknownSync(ApiCall);
|
|
78
|
+
|
|
79
|
+
/** `url` when it's one of `api`'s own URLs on `origin`, or `undefined`. */
|
|
80
|
+
const withinApi = (api: ApiName, origin: string, url: URL) =>
|
|
81
|
+
url.origin === origin && ownedBy(api, url.pathname) ? url : undefined;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* The URL `call` names on `origin`, or `undefined` when it would leave its API, as a `..` past
|
|
85
|
+
* `/api/v3` to `/login/oauth/access_token` would, or when it's a raw call that only reads.
|
|
86
|
+
*/
|
|
87
|
+
export const callUrl = (origin: string, call: ApiCall): URL | undefined =>
|
|
88
|
+
call.api === 'raw' && call.method !== 'GET'
|
|
89
|
+
? undefined
|
|
90
|
+
: withinApi(call.api, origin, new URL(`${apiBases[call.api]}${call.path}`, origin));
|
|
91
|
+
|
|
92
|
+
/** The call openapi-fetch's `request` makes, for the browser to hand the server, body and all. */
|
|
93
|
+
export const callOf = async (api: ApiName, request: Request): Promise<ApiCall> => {
|
|
94
|
+
const url = new URL(request.url);
|
|
95
|
+
const bytes = new Uint8Array(await request.arrayBuffer());
|
|
96
|
+
|
|
97
|
+
return parseCall({
|
|
98
|
+
api,
|
|
99
|
+
method: request.method,
|
|
100
|
+
path: `${url.pathname.slice(apiBases[api].length)}${url.search}`,
|
|
101
|
+
body: bytes.length === 0 ? undefined : bytes,
|
|
102
|
+
contentType: request.headers.get('content-type') ?? undefined,
|
|
103
|
+
accept: request.headers.get('accept') ?? 'application/json',
|
|
104
|
+
lastEventId: request.headers.get('last-event-id') ?? undefined,
|
|
105
|
+
ifModifiedSince: request.headers.get('if-modified-since') ?? undefined,
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
/** How many redirects a call follows: Git sends one for a renamed repo. */
|
|
110
|
+
const redirectsFollowed = 5;
|
|
111
|
+
|
|
112
|
+
const isRedirect = (status: number) => [301, 302, 303, 307, 308].includes(status);
|
|
113
|
+
|
|
114
|
+
/** Who a forwarded call is from, and where it goes. */
|
|
115
|
+
export interface Forwarding {
|
|
116
|
+
readonly origin: string;
|
|
117
|
+
/** The session's token, or `undefined` to call as no one. */
|
|
118
|
+
readonly token: string | undefined;
|
|
119
|
+
readonly api: ApiFetch;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* `call`, sent to its API with the token, and the API's answer. A redirect is followed here, as
|
|
124
|
+
* the token's holder, while it stays within the call's API: a browser following it would arrive
|
|
125
|
+
* without the token. One that leaves the API, or a sixth, answers 502.
|
|
126
|
+
*/
|
|
127
|
+
export const forward = async (call: ApiCall, forwarding: Forwarding): Promise<Response> => {
|
|
128
|
+
let url = callUrl(forwarding.origin, call);
|
|
129
|
+
if (url === undefined) return Response.json({ message: 'Not an API URL' }, { status: 400 });
|
|
130
|
+
|
|
131
|
+
const headers = new Headers({ accept: call.accept ?? 'application/json' });
|
|
132
|
+
if (call.contentType !== undefined) headers.set('content-type', call.contentType);
|
|
133
|
+
|
|
134
|
+
if (call.lastEventId !== undefined) headers.set('last-event-id', call.lastEventId);
|
|
135
|
+
|
|
136
|
+
if (call.ifModifiedSince !== undefined) headers.set('if-modified-since', call.ifModifiedSince);
|
|
137
|
+
|
|
138
|
+
if (forwarding.token !== undefined) headers.set('authorization', `Bearer ${forwarding.token}`);
|
|
139
|
+
|
|
140
|
+
let method: string = call.method;
|
|
141
|
+
// Copied onto an ArrayBuffer of its own, which a request's body takes.
|
|
142
|
+
let body = call.body === undefined ? null : new Uint8Array(call.body);
|
|
143
|
+
|
|
144
|
+
for (let followed = 0; ; followed += 1) {
|
|
145
|
+
const answer = await forwarding.api(new Request(url, { method, headers, body }));
|
|
146
|
+
const location = answer.headers.get('location');
|
|
147
|
+
if (!isRedirect(answer.status) || location === null) return answer;
|
|
148
|
+
|
|
149
|
+
await answer.body?.cancel();
|
|
150
|
+
url = withinApi(call.api, forwarding.origin, new URL(location, url));
|
|
151
|
+
|
|
152
|
+
if (url === undefined || followed === redirectsFollowed) {
|
|
153
|
+
return Response.json({ message: 'The API redirected outside itself' }, { status: 502 });
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// As fetch does: a 303, or a 301 or 302 after a POST, asks for the new place's GET.
|
|
157
|
+
const asGet = answer.status === 303 || (method === 'POST' && answer.status < 303);
|
|
158
|
+
if (asGet && method !== 'HEAD') [method, body] = ['GET', null];
|
|
159
|
+
}
|
|
160
|
+
};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { paths as GitHubPaths } from '@octokit/openapi-types';
|
|
2
|
+
import createClient from 'openapi-fetch';
|
|
3
|
+
import createQueryHooks from 'openapi-react-query';
|
|
4
|
+
import type * as Schema from 'effect/Schema';
|
|
5
|
+
|
|
6
|
+
import type { paths as GitPaths } from '../../generated/git-rest.ts';
|
|
7
|
+
import { apiBases, callOf, type ApiName } from './calls.ts';
|
|
8
|
+
import { answered, graphqlRequest, mutated, type Variables } from './graphql.ts';
|
|
9
|
+
import { callApi } from './proxy.ts';
|
|
10
|
+
import { endedHeader, sessionEnded } from './session-ended.ts';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The clients' URLs name only a path: this origin is a placeholder `callApi` drops, so one client
|
|
14
|
+
* builds the same calls in the browser and on the server.
|
|
15
|
+
*/
|
|
16
|
+
const placeholder = 'http://api.invalid';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* openapi-fetch's `fetch`, sending each request through `callApi` to the server. Aborting the
|
|
20
|
+
* request aborts the call, and with it a stream the API was sending. An answer whose session
|
|
21
|
+
* ended tells the shell, which reloads the page's data as a visitor's.
|
|
22
|
+
*/
|
|
23
|
+
const viaServer = (api: ApiName) => async (request: Request) => {
|
|
24
|
+
const answer = await callApi({ data: await callOf(api, request), signal: request.signal });
|
|
25
|
+
if (answer.headers.has(endedHeader)) sessionEnded();
|
|
26
|
+
|
|
27
|
+
return answer;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/** GitHub's REST, typed by `@octokit/openapi-types`, through the drop-in. */
|
|
31
|
+
export const github = createClient<GitHubPaths>({
|
|
32
|
+
baseUrl: `${placeholder}${apiBases.github}`,
|
|
33
|
+
fetch: viaServer('github'),
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
/** Git's REST, typed from its OpenAPI document. */
|
|
37
|
+
export const git = createClient<GitPaths>({
|
|
38
|
+
baseUrl: `${placeholder}${apiBases.git}`,
|
|
39
|
+
fetch: viaServer('git'),
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* A call to `path` under `api`'s base that no client types: an Event Stream's, whose URLs the
|
|
44
|
+
* drop-in names in its answers, and a stream's body, which the caller reads as it comes.
|
|
45
|
+
*/
|
|
46
|
+
export const callAt = (api: ApiName, path: string, init?: RequestInit) =>
|
|
47
|
+
viaServer(api)(new Request(`${placeholder}${apiBases[api]}${path}`, init));
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The drop-in's raw route at `path`, `/{owner}/{repo}/raw/{ref}/{path}`, read as the viewer: an
|
|
51
|
+
* LFS file's object, or its pointer when the bucket lacks it (Q506). The page reads the bytes and
|
|
52
|
+
* shows or saves them itself, so nothing points the browser at the route (Q310).
|
|
53
|
+
*/
|
|
54
|
+
export const raw = (path: string) => callAt('raw', path);
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* `operation`, a GraphQL mutation the drop-in serves at `/api/graphql`, sent with `variables`. A
|
|
58
|
+
* refusal throws `what` with GitHub's words for its first error, or the status.
|
|
59
|
+
*/
|
|
60
|
+
export const mutate = async (what: string, operation: string, variables: Variables) =>
|
|
61
|
+
mutated(what, await callAt('graphql', '/api/graphql', graphqlRequest(operation, variables)));
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* `operation`, a GraphQL query the drop-in serves at `/api/graphql`, sent with `variables`: its
|
|
65
|
+
* answer's `data`, as `schema` reads it, or `answered`'s throw.
|
|
66
|
+
*/
|
|
67
|
+
export const query = async <A>(
|
|
68
|
+
what: string,
|
|
69
|
+
operation: string,
|
|
70
|
+
variables: Variables,
|
|
71
|
+
schema: Schema.Decoder<A>,
|
|
72
|
+
) =>
|
|
73
|
+
answered(
|
|
74
|
+
what,
|
|
75
|
+
await callAt('graphql', '/api/graphql', graphqlRequest(operation, variables)),
|
|
76
|
+
schema,
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
/** TanStack Query's hooks and options over each client. */
|
|
80
|
+
export const githubQueries = createQueryHooks(github);
|
|
81
|
+
|
|
82
|
+
export const gitQueries = createQueryHooks(git);
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import * as Option from 'effect/Option';
|
|
2
|
+
import * as Schema from 'effect/Schema';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A GraphQL answer's `data`, its errors, as GitHub words them, or a refusal's `message`, as REST
|
|
6
|
+
* words one, such as a 401's "Bad credentials".
|
|
7
|
+
*/
|
|
8
|
+
const GraphQLAnswer = Schema.Struct({
|
|
9
|
+
data: Schema.optional(Schema.Unknown),
|
|
10
|
+
errors: Schema.optional(Schema.Array(Schema.Struct({ message: Schema.String }))),
|
|
11
|
+
message: Schema.optional(Schema.String),
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
const decodeGraphQLAnswer = Schema.decodeUnknownOption(Schema.fromJsonString(GraphQLAnswer));
|
|
15
|
+
|
|
16
|
+
/** An operation's variables: its strings, its numbers, and `null` for one it leaves out. */
|
|
17
|
+
export type Variables = Readonly<Record<string, string | number | null>>;
|
|
18
|
+
|
|
19
|
+
/** `operation` with `variables`, as `/api/graphql` takes a request. */
|
|
20
|
+
export const graphqlRequest = (operation: string, variables: Variables): RequestInit => ({
|
|
21
|
+
method: 'POST',
|
|
22
|
+
headers: { 'content-type': 'application/json' },
|
|
23
|
+
body: JSON.stringify({ query: operation, variables }),
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* An operation's `answer`: its `data`, as `schema` reads it, or a throw of `what` with its first
|
|
28
|
+
* error's words, else its refusal's, else its status.
|
|
29
|
+
*/
|
|
30
|
+
export const answered = async <A>(
|
|
31
|
+
what: string,
|
|
32
|
+
answer: Response,
|
|
33
|
+
schema: Schema.Decoder<A>,
|
|
34
|
+
): Promise<A> => {
|
|
35
|
+
const said = decodeGraphQLAnswer(await answer.text());
|
|
36
|
+
const {
|
|
37
|
+
data,
|
|
38
|
+
errors = [],
|
|
39
|
+
message,
|
|
40
|
+
} = Option.getOrElse(said, (): typeof GraphQLAnswer.Type => ({}));
|
|
41
|
+
const [first] = errors;
|
|
42
|
+
if (answer.ok && first === undefined) return Schema.decodeUnknownSync(schema)(data);
|
|
43
|
+
|
|
44
|
+
throw new Error(`${what}: ${first?.message ?? message ?? answer.status}`);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/** A mutation's `answer`: nothing once it's done, or `answered`'s throw. */
|
|
48
|
+
export const mutated = async (what: string, answer: Response) => {
|
|
49
|
+
await answered(what, answer, Schema.Unknown);
|
|
50
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import * as Option from 'effect/Option';
|
|
2
|
+
import * as Schema from 'effect/Schema';
|
|
3
|
+
|
|
4
|
+
import { type HostAsk, hostCall } from './host-calls.ts';
|
|
5
|
+
|
|
6
|
+
const Refusal = Schema.Struct({ message: Schema.String });
|
|
7
|
+
|
|
8
|
+
const refusalOf = Schema.decodeUnknownOption(Refusal);
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* `ask`'s answer as a page reads it: its body, read as `answered`, which meets a 204 with nothing;
|
|
12
|
+
* or an error in the refusal's own words.
|
|
13
|
+
*/
|
|
14
|
+
export const hostAnswer = async <S extends Schema.Decoder<unknown>>(
|
|
15
|
+
ask: HostAsk,
|
|
16
|
+
answered: S,
|
|
17
|
+
): Promise<S['Type']> => {
|
|
18
|
+
const answer = await hostCall({ data: ask });
|
|
19
|
+
const body: unknown = answer.status === 204 ? undefined : await answer.json();
|
|
20
|
+
if (answer.ok) return Schema.decodeUnknownSync(answered)(body);
|
|
21
|
+
|
|
22
|
+
const said = Option.match(refusalOf(body), {
|
|
23
|
+
onNone: () => `${answer.status}`,
|
|
24
|
+
onSome: (refusal) => refusal.message,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
throw new Error(said);
|
|
28
|
+
};
|