Skip to content

Commit

Permalink
Replace openapi-typescript-fetch with openapi-fetch in Toolshed
Browse files Browse the repository at this point in the history
  • Loading branch information
davelopez committed Jul 12, 2024
1 parent 438a861 commit cb3499c
Show file tree
Hide file tree
Showing 17 changed files with 178 additions and 153 deletions.
2 changes: 1 addition & 1 deletion lib/tool_shed/webapp/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"e": "^0.2.2",
"graphql": "^16.6.0",
"graphql-tag": "^2.12.6",
"openapi-typescript-fetch": "^1.1.3",
"openapi-fetch": "^0.10.2",
"pinia": "^2.0.28",
"quasar": "^2.5.0",
"vue": "^3.2.6",
Expand Down
18 changes: 11 additions & 7 deletions lib/tool_shed/webapp/frontend/src/components/RegisterPage.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup lang="ts">
import { ref } from "vue"
import ModalForm from "@/components/ModalForm.vue"
import { fetcher } from "@/schema"
import { client } from "@/schema"
import { notify } from "@/util"
import router from "@/router"
import { AUTH_FORM_INPUT_PROPS } from "@/constants"
Expand All @@ -12,19 +12,23 @@ const confirm = ref("")
const username = ref("")
const title = ref("Register")
const createFetcher = fetcher.path("/api_internal/register").method("post").create()
// type Response = components["schemas"]["UiRegisterResponse"]
async function onRegister() {
// TODO: handle confirm and implement bear_field.
// let data: Response
try {
const { data } = await createFetcher({
email: email.value,
password: password.value,
username: username.value,
bear_field: "",
const { data } = await client.POST("/api_internal/register", {
body: {
email: email.value,
password: password.value,
username: username.value,
bear_field: "",
},
})
if (!data) {
throw new Error("No data returned")
}
const query = {
activation_error: data.activation_error ? "true" : "false",
activation_sent: data.activation_sent ? "true" : "false",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<script setup lang="ts">
import { fetcher } from "@/schema"
import { client } from "@/schema"
import { notify, notifyOnCatch } from "@/util"
const resetFetcher = fetcher.path("/api/repositories/{encoded_repository_id}/reset_metadata").method("post").create()
async function resetMetadata() {
resetFetcher({ encoded_repository_id: props.repositoryId })
client
.POST("/api/repositories/{encoded_repository_id}/reset_metadata", {
params: { path: { encoded_repository_id: props.repositoryId } },
})
.catch(notifyOnCatch)
.then(() => {
notify("Repository metadata reset.")
Expand Down
38 changes: 21 additions & 17 deletions lib/tool_shed/webapp/frontend/src/components/RevisionActions.vue
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
<script setup lang="ts">
import { computed } from "vue"
import { RevisionMetadata } from "@/schema"
import { fetcher } from "@/schema"
import { client } from "@/schema"
import { notify, notifyOnCatch } from "@/util"
const setMaliciousFetcher = fetcher
.path("/api/repositories/{encoded_repository_id}/revisions/{changeset_revision}/malicious")
.method("put")
.create()
const unsetMaliciousFetcher = fetcher
.path("/api/repositories/{encoded_repository_id}/revisions/{changeset_revision}/malicious")
.method("delete")
.create()
interface RevisionActionsProps {
repositoryId: string
Expand All @@ -20,27 +12,39 @@ interface RevisionActionsProps {
const props = defineProps<RevisionActionsProps>()
async function setMalicious() {
setMaliciousFetcher({
encoded_repository_id: props.repositoryId,
changeset_revision: props.currentMetadata.changeset_revision,
})
client
.PUT("/api/repositories/{encoded_repository_id}/revisions/{changeset_revision}/malicious", {
params: {
path: {
encoded_repository_id: props.repositoryId,
changeset_revision: props.currentMetadata.changeset_revision,
},
},
})
.catch(notifyOnCatch)
.then(() => {
notify("Marked repository as malicious")
emits("update")
})
}
async function unsetMalicious() {
unsetMaliciousFetcher({
encoded_repository_id: props.repositoryId,
changeset_revision: props.currentMetadata.changeset_revision,
})
client
.DELETE("/api/repositories/{encoded_repository_id}/revisions/{changeset_revision}/malicious", {
params: {
path: {
encoded_repository_id: props.repositoryId,
changeset_revision: props.currentMetadata.changeset_revision,
},
},
})
.catch(notifyOnCatch)
.then(() => {
notify("Un-marked repository as malicious")
emits("update")
})
}
const malicious = computed(() => props.currentMetadata.malicious)
type Emits = {
(eventName: "update"): void
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
<script setup lang="ts">
import { ref } from "vue"
import { fetcher, components } from "@/schema"
import { client, components } from "@/schema"
import PageContainer from "@/components/PageContainer.vue"
const searchIndexer = fetcher.path("/api/tools/build_search_index").method("put").create()
type IndexResults = components["schemas"]["BuildSearchIndexResponse"]
const searchResults = ref(null as IndexResults | null)
const searchResults = ref<IndexResults>()
async function onIndex() {
const { data } = await searchIndexer({})
const { data } = await client.PUT("/api/tools/build_search_index")
searchResults.value = data
}
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { ref } from "vue"
import ModalForm from "@/components/ModalForm.vue"
import { AUTH_FORM_INPUT_PROPS } from "@/constants"
import { fetcher } from "@/schema"
import { client } from "@/schema"
import { errorMessage } from "@/util"
import ErrorBanner from "@/components/ErrorBanner.vue"
import router from "@/router"
Expand All @@ -11,13 +11,15 @@ const current = ref("")
const password = ref("")
const confirm = ref("")
const error = ref<string | null>(null)
const changePasswordFetcher = fetcher.path("/api_internal/change_password").method("put").create()
async function onChange() {
changePasswordFetcher({
current: current.value,
password: password.value,
})
client
.PUT("/api_internal/change_password", {
body: {
current: current.value,
password: password.value,
},
})
.then(() => {
router.push("/")
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
<script setup lang="ts">
import { ref, watch } from "vue"
import RepositoryPage from "./RepositoryPage.vue"
import { fetcher } from "@/schema"
import { client } from "@/schema"
import type { Repository } from "@/schema/types"
import LoadingDiv from "@/components/LoadingDiv.vue"
import ErrorBanner from "@/components/ErrorBanner.vue"
const indexFetcher = fetcher.path("/api/repositories").method("get").create()
interface CitableRepositoryPageProps {
username: string
repositoryName: string
Expand All @@ -18,7 +16,14 @@ const error = ref<string | null>(null)
async function update() {
error.value = null
const { data } = await indexFetcher({ owner: props.username, name: props.repositoryName })
const { data } = await client.GET("/api/repositories", {
params: {
query: {
owner: props.username,
name: props.repositoryName,
},
},
})
if (data instanceof Array) {
if (data.length == 0) {
error.value = `Repository ${props.username}/${props.repositoryName} is not found`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
<script setup lang="ts">
import { ref, computed } from "vue"
import PageContainer from "@/components/PageContainer.vue"
import { fetcher } from "@/schema"
import { client } from "@/schema"
import { notify, copyAndNotify, notifyOnCatch } from "@/util"
import ConfigFileContents from "@/components/ConfigFileContents.vue"
const apiKeyFetcher = fetcher.path("/api/users/{encoded_user_id}/api_key").method("get").create()
const deleteKeyFetcher = fetcher.path("/api/users/{encoded_user_id}/api_key").method("delete").create()
const recreateKeyFetcher = fetcher.path("/api/users/{encoded_user_id}/api_key").method("post").create()
const apiKey = ref(null as string | null)
const planemoConfig = computed(
() =>
Expand All @@ -26,15 +22,28 @@ async function copyKey() {
const params = { encoded_user_id: "current" }
async function init() {
apiKeyFetcher(params)
client
.GET("/api/users/{encoded_user_id}/api_key", {
params: {
path: params,
},
})
.then(({ data }) => {
if (!data) {
throw Error("Error fetching API key")
}
apiKey.value = data
})
.catch(notifyOnCatch)
}
async function deleteKey() {
deleteKeyFetcher(params)
client
.DELETE("/api/users/{encoded_user_id}/api_key", {
params: {
path: params,
},
})
.then(() => {
apiKey.value = null
notify("API key deactivated")
Expand All @@ -43,8 +52,16 @@ async function deleteKey() {
}
async function recreateKey() {
recreateKeyFetcher(params)
client
.POST("/api/users/{encoded_user_id}/api_key", {
params: {
path: params,
},
})
.then(({ data }) => {
if (!data) {
throw Error("Error re-generating API key")
}
apiKey.value = data
notify("Re-generated API key")
})
Expand Down Expand Up @@ -76,7 +93,7 @@ void init()
alternate means to access your account and should be treated with the same care as your login password.
</p>
<p>
Add the following block to your Planemo configuration file (typically found in
Add the following block to your Planemo configuration file (typically) found in
<code>~/.planemo.yml</code> in your
</p>
<config-file-contents name=".planemo.yml" :contents="planemoConfig" what="Planemo configuration" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { computed, ref, watch } from "vue"
import PageContainer from "@/components/PageContainer.vue"
import RepositoryGrid from "@/components/RepositoriesGrid.vue"
import { type RepositoryGridItem, type OnScroll } from "@/components/RepositoriesGridInterface"
import { fetcher, components } from "@/schema"
const searchFetcher = fetcher.path("/api/repositories").method("get").create()
import { client, components } from "@/schema"
const query = ref("")
const page = ref(1)
Expand All @@ -15,11 +14,18 @@ type RepositorySearchHit = components["schemas"]["RepositorySearchHit"]
async function doQuery() {
const queryValue = query.value
const { data } = await searchFetcher({ q: queryValue, page: page.value, page_size: 10 })
const { data } = await client.GET("/api/repositories", {
params: {
query: { q: queryValue, page: page.value, page_size: 10 },
},
})
if (query.value != queryValue) {
console.log("query changed.... not using these results...")
return
}
if (!data) {
throw Error("Server response error.")
}
if ("hits" in data) {
if (page.value == 1) {
hits.value = data.hits
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,10 @@ import ConfigFileContents from "@/components/ConfigFileContents.vue"
import RepositoryLinks from "@/components/RepositoryLinks.vue"
import RepositoryExplore from "@/components/RepositoryExplore.vue"
import { type RevisionMetadata } from "@/schema"
import { fetcher } from "@/schema"
import { client } from "@/schema"
import { notifyOnCatch } from "@/util"
import { UPDATING_WITH_PLANEMO_URL, EPHEMERIS_TRAINING } from "@/constants"
const readmeFetcher = fetcher
.path("/api/repositories/{encoded_repository_id}/revisions/{changeset_revision}/readmes")
.method("get")
.create()
const deprecateFetcher = fetcher.path("/api/repositories/{encoded_repository_id}/deprecated").method("put").create()
const undeprecateFetcher = fetcher
.path("/api/repositories/{encoded_repository_id}/deprecated")
.method("delete")
.create()
interface RepositoryProps {
repositoryId: string
changesetRevision?: string | null
Expand All @@ -41,14 +30,24 @@ function onUpdate() {
async function onDeprecate() {
const repositoryId = repository.value?.id
if (repositoryId) {
deprecateFetcher({ encoded_repository_id: repositoryId }).then(onUpdate).catch(notifyOnCatch)
client
.PUT("/api/repositories/{encoded_repository_id}/deprecated", {
params: { path: { encoded_repository_id: repositoryId } },
})
.then(onUpdate)
.catch(notifyOnCatch)
}
}
async function onUndeprecate() {
const repositoryId = repository.value?.id
if (repositoryId) {
undeprecateFetcher({ encoded_repository_id: repositoryId }).then(onUpdate).catch(notifyOnCatch)
client
.DELETE("/api/repositories/{encoded_repository_id}/deprecated", {
params: { path: { encoded_repository_id: repositoryId } },
})
.then(onUpdate)
.catch(notifyOnCatch)
}
}
Expand Down Expand Up @@ -133,10 +132,15 @@ watch(
watch(currentRevision, () => {
if (currentRevision.value) {
readmeFetcher({
encoded_repository_id: props.repositoryId,
changeset_revision: currentRevision.value,
})
client
.GET("/api/repositories/{encoded_repository_id}/revisions/{changeset_revision}/readmes", {
params: {
path: {
encoded_repository_id: props.repositoryId,
changeset_revision: currentRevision.value,
},
},
})
.then((response) => {
if (response.data) {
readmes.value = response.data
Expand Down
Loading

0 comments on commit cb3499c

Please sign in to comment.