Skip to content

Commit

Permalink
feat: migrate from pinia stores to TanStack Query (#247) (#251)
Browse files Browse the repository at this point in the history
Co-authored-by: gromdimon <[email protected]>
  • Loading branch information
holtgrewe and gromdimon authored Sep 25, 2024
1 parent 9a7538a commit 60bd628
Show file tree
Hide file tree
Showing 34 changed files with 4,053 additions and 140 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# log files
/*.log

# nodejs
/node_modules

Expand Down
73 changes: 73 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,76 @@ proto-ts:

.PHONY: proto
proto: proto-fetch proto-ts format lint

.PHONY: openapi
openapi: \
openapi-cadaPrio-ts \
openapi-dotty-ts \
openapi-variantValidator-ts \
openapi-viguno-ts \
format \
lint

.PHONY: openapi-cadaPrio-fetch
openapi-cadaPrio-fetch:
mkdir -p ext/cadaPrio-api

rm -f ext/cadaPrio-api/openapi.yaml
docker pull ghcr.io/bihealth/cada-prio:main
docker run ghcr.io/bihealth/cada-prio:main cada-prio utils dump-openapi-yaml /dev/stdout \
| grep -v '^+' \
> ext/cadaPrio-api/openapi.yaml

.PHONY: openapi-cadaPrio-ts
openapi-cadaPrio-ts: openapi-cadaPrio-fetch
rm -rf ext/cadaPrio-api/src/lib
mkdir -p ext/cadaPrio-api/src
npx @hey-api/openapi-ts --file openapi-ts.config.cadaPrio.ts

.PHONY: openapi-dotty-fetch
openapi-dotty-fetch:
mkdir -p ext/dotty-api

rm -f ext/dotty-api/openapi.yaml
docker pull ghcr.io/bihealth/dotty:main
docker run ghcr.io/bihealth/dotty:main python -m dotty.main \
| grep -v '^+' \
> ext/dotty-api/openapi.yaml

.PHONY: openapi-dotty-ts
openapi-dotty-ts: openapi-dotty-fetch
rm -rf ext/dotty-api/src/lib
mkdir -p ext/dotty-api/src
npx @hey-api/openapi-ts --file openapi-ts.config.dotty.ts

.PHONY: openapi-variantValidator-fetch
openapi-variantValidator-fetch:
mkdir -p ext/variantValidator-api

rm -f ext/variantValidator-api/openapi.yaml
wget -O ext/variantValidator-api/openapi.yaml \
https://rest.variantvalidator.org/swagger.json

.PHONY: openapi-variantValidator-ts
openapi-variantValidator-ts: openapi-variantValidator-fetch
rm -rf ext/variantValidator-api/src/lib
mkdir -p ext/variantValidator-api/src
npx @hey-api/openapi-ts --file openapi-ts.config.variantValidator.ts

.PHONY: openapi-viguno-fetch
openapi-viguno-fetch:
rm -rf ext/viguno-api/openapi.yaml
mkdir -p ext/viguno-api

docker pull ghcr.io/varfish-org/viguno:main
docker run -t ghcr.io/varfish-org/viguno:main \
exec viguno server schema --output-file /dev/stdout \
| grep -v ' INFO' \
| grep -v '^+' \
> ext/viguno-api/openapi.yaml

.PHONY: openapi-viguno-ts
openapi-viguno-ts: openapi-viguno-fetch
rm -rf ext/viguno-api/src/lib
mkdir -p ext/viguno-api/src
npx @hey-api/openapi-ts --file openapi-ts.config.viguno.ts
82 changes: 82 additions & 0 deletions ext/cadaPrio-api/openapi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
components:
schemas:
HTTPValidationError:
properties:
detail:
items:
$ref: '#/components/schemas/ValidationError'
title: Detail
type: array
title: HTTPValidationError
type: object
ValidationError:
properties:
loc:
items:
anyOf:
- type: string
- type: integer
title: Location
type: array
msg:
title: Message
type: string
type:
title: Error Type
type: string
required:
- loc
- msg
- type
title: ValidationError
type: object
info:
description: A phenotype-based gene prioritization tool.
title: cada-prio
version: 0.6.1
openapi: 3.1.0
paths:
/api/v1/predict:
get:
description: Predict genes for a given set of HPO terms and optionally genes.
operationId: handle_predict_api_v1_predict_get
parameters:
- example: HP:0000098,HP:0000218,HP:0000486
in: query
name: hpo_terms
required: true
schema:
title: Hpo Terms
type: string
- example: FBN1,TTN,BRCA1
in: query
name: genes
required: false
schema:
anyOf:
- type: string
- type: 'null'
title: Genes
responses:
'200':
content:
application/json:
schema: {}
description: Successful Response
'422':
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPValidationError'
description: Validation Error
summary: Handle Predict
/api/v1/version:
get:
operationId: version_api_v1_version_get
responses:
'200':
content:
application/json:
schema: {}
description: Successful Response
summary: Version
78 changes: 78 additions & 0 deletions ext/cadaPrio-api/src/lib/@tanstack/vue-query.gen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// This file is auto-generated by @hey-api/openapi-ts
import type { Options } from '@hey-api/client-fetch'
import { queryOptions } from '@tanstack/vue-query'

import { client, handlePredictApiV1PredictGet, versionApiV1VersionGet } from '../services.gen'
import type { HandlePredictApiV1PredictGetData } from '../types.gen'

type QueryKey<TOptions extends Options> = [
Pick<TOptions, 'baseUrl' | 'body' | 'headers' | 'path' | 'query'> & {
_id: string
_infinite?: boolean
}
]

const createQueryKey = <TOptions extends Options>(
id: string,
options?: TOptions,
infinite?: boolean
): QueryKey<TOptions>[0] => {
const params: QueryKey<TOptions>[0] = {
_id: id,
baseUrl: client.getConfig().baseUrl
} as QueryKey<TOptions>[0]
if (infinite) {
params._infinite = infinite
}
if (options?.body) {
params.body = options.body
}
if (options?.headers) {
params.headers = options.headers
}
if (options?.path) {
params.path = options.path
}
if (options?.query) {
params.query = options.query
}
return params
}

export const handlePredictApiV1PredictGetQueryKey = (
options: Options<HandlePredictApiV1PredictGetData>
) => [createQueryKey('handlePredictApiV1PredictGet', options)]

export const handlePredictApiV1PredictGetOptions = (
options: Options<HandlePredictApiV1PredictGetData>
) => {
return queryOptions({
queryFn: async ({ queryKey }) => {
const { data } = await handlePredictApiV1PredictGet({
...options,
...queryKey[0],
throwOnError: true
})
return data
},
queryKey: handlePredictApiV1PredictGetQueryKey(options)
})
}

export const versionApiV1VersionGetQueryKey = (options?: Options) => [
createQueryKey('versionApiV1VersionGet', options)
]

export const versionApiV1VersionGetOptions = (options?: Options) => {
return queryOptions({
queryFn: async ({ queryKey }) => {
const { data } = await versionApiV1VersionGet({
...options,
...queryKey[0],
throwOnError: true
})
return data
},
queryKey: versionApiV1VersionGetQueryKey(options)
})
}
4 changes: 4 additions & 0 deletions ext/cadaPrio-api/src/lib/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// This file is auto-generated by @hey-api/openapi-ts
export * from './schemas.gen'
export * from './services.gen'
export * from './types.gen'
45 changes: 45 additions & 0 deletions ext/cadaPrio-api/src/lib/schemas.gen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// This file is auto-generated by @hey-api/openapi-ts

export const $HTTPValidationError = {
properties: {
detail: {
items: {
$ref: '#/components/schemas/ValidationError'
},
title: 'Detail',
type: 'array'
}
},
title: 'HTTPValidationError',
type: 'object'
} as const

export const $ValidationError = {
properties: {
loc: {
items: {
anyOf: [
{
type: 'string'
},
{
type: 'integer'
}
]
},
title: 'Location',
type: 'array'
},
msg: {
title: 'Message',
type: 'string'
},
type: {
title: 'Error Type',
type: 'string'
}
},
required: ['loc', 'msg', 'type'],
title: 'ValidationError',
type: 'object'
} as const
45 changes: 45 additions & 0 deletions ext/cadaPrio-api/src/lib/services.gen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// This file is auto-generated by @hey-api/openapi-ts
import { type Options, createClient, createConfig } from '@hey-api/client-fetch'

import type {
HandlePredictApiV1PredictGetData,
HandlePredictApiV1PredictGetError,
HandlePredictApiV1PredictGetResponse,
VersionApiV1VersionGetError,
VersionApiV1VersionGetResponse
} from './types.gen'

export const client = createClient(createConfig())

/**
* Handle Predict
* Predict genes for a given set of HPO terms and optionally genes.
*/
export const handlePredictApiV1PredictGet = <ThrowOnError extends boolean = false>(
options: Options<HandlePredictApiV1PredictGetData, ThrowOnError>
) => {
return (options?.client ?? client).get<
HandlePredictApiV1PredictGetResponse,
HandlePredictApiV1PredictGetError,
ThrowOnError
>({
...options,
url: '/api/v1/predict'
})
}

/**
* Version
*/
export const versionApiV1VersionGet = <ThrowOnError extends boolean = false>(
options?: Options<unknown, ThrowOnError>
) => {
return (options?.client ?? client).get<
VersionApiV1VersionGetResponse,
VersionApiV1VersionGetError,
ThrowOnError
>({
...options,
url: '/api/v1/version'
})
}
26 changes: 26 additions & 0 deletions ext/cadaPrio-api/src/lib/types.gen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// This file is auto-generated by @hey-api/openapi-ts

export type HTTPValidationError = {
detail?: Array<ValidationError>
}

export type ValidationError = {
loc: Array<string | number>
msg: string
type: string
}

export type HandlePredictApiV1PredictGetData = {
query: {
genes?: string | null
hpo_terms: string
}
}

export type HandlePredictApiV1PredictGetResponse = unknown

export type HandlePredictApiV1PredictGetError = HTTPValidationError

export type VersionApiV1VersionGetResponse = unknown

export type VersionApiV1VersionGetError = unknown
Loading

0 comments on commit 60bd628

Please sign in to comment.