From a69c1e69d45bca89b27aeb546149ba40f824ec26 Mon Sep 17 00:00:00 2001 From: Andrew Chou Date: Thu, 9 Jan 2025 15:28:02 -0500 Subject: [PATCH] use Writeable instead of Mutable in type naming --- src/hooks/documents.ts | 14 +++++----- src/index.ts | 6 ++--- src/lib/react-query/documents.ts | 46 +++++++++++++++++--------------- 3 files changed, 35 insertions(+), 31 deletions(-) diff --git a/src/hooks/documents.ts b/src/hooks/documents.ts index 8cd558f..808c131 100644 --- a/src/hooks/documents.ts +++ b/src/hooks/documents.ts @@ -12,7 +12,7 @@ import { documentByVersionIdQueryOptions, documentsQueryOptions, updateDocumentMutationOptions, - type MutableDocumentType, + type WriteableDocumentType, } from '../lib/react-query/documents.js' import { useSingleProject } from './projects.js' @@ -45,7 +45,7 @@ type ReadHookResult = { * } * ``` */ -export function useSingleDocByDocId({ +export function useSingleDocByDocId({ projectId, docType, docId, @@ -101,7 +101,7 @@ export function useSingleDocByDocId({ * } * ``` */ -export function useSingleDocByVersionId({ +export function useSingleDocByVersionId({ projectId, docType, versionId, @@ -166,7 +166,7 @@ export function useSingleDocByVersionId({ * } * ``` */ -export function useManyDocs({ +export function useManyDocs({ projectId, docType, includeDeleted, @@ -203,7 +203,7 @@ export function useManyDocs({ * @param opts.docType Document type to create. * @param opts.projectId Public ID of project to create document for. */ -export function useCreateDocument({ +export function useCreateDocument({ docType, projectId, }: { @@ -231,7 +231,7 @@ export function useCreateDocument({ * @param opts.docType Document type to update. * @param opts.projectId Public ID of project document belongs to. */ -export function useUpdateDocument({ +export function useUpdateDocument({ docType, projectId, }: { @@ -259,7 +259,7 @@ export function useUpdateDocument({ * @param opts.docType Document type to delete. * @param opts.projectId Public ID of project document belongs to. */ -export function useDeleteDocument({ +export function useDeleteDocument({ docType, projectId, }: { diff --git a/src/index.ts b/src/index.ts index 4f4df93..caaf1f6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -47,9 +47,9 @@ export { getDocumentByVersionIdQueryKey, getDocumentsQueryKey, getManyDocumentsQueryKey, - type MutableDocument, - type MutableDocumentType, - type MutableValue, + type WriteableDocument, + type WriteableDocumentType, + type WriteableValue, } from './lib/react-query/documents.js' export { getInvitesQueryKey, diff --git a/src/lib/react-query/documents.ts b/src/lib/react-query/documents.ts index 2317e33..4a904ea 100644 --- a/src/lib/react-query/documents.ts +++ b/src/lib/react-query/documents.ts @@ -15,20 +15,20 @@ import { ROOT_QUERY_KEY, } from './shared.js' -export type MutableDocumentType = Extract< +export type WriteableDocumentType = Extract< MapeoDoc['schemaName'], 'field' | 'observation' | 'preset' | 'track' | 'remoteDetectionAlert' > -export type MutableValue = Extract< +export type WriteableValue = Extract< MapeoValue, { schemaName: D } > -export type MutableDocument = Extract< +export type WriteableDocument = Extract< MapeoDoc, { schemaName: D } > -export function getDocumentsQueryKey({ +export function getDocumentsQueryKey({ projectId, docType, }: { @@ -38,7 +38,7 @@ export function getDocumentsQueryKey({ return [ROOT_QUERY_KEY, 'projects', projectId, docType] as const } -export function getManyDocumentsQueryKey({ +export function getManyDocumentsQueryKey({ projectId, docType, includeDeleted, @@ -58,7 +58,7 @@ export function getManyDocumentsQueryKey({ ] as const } -export function getDocumentByDocIdQueryKey({ +export function getDocumentByDocIdQueryKey({ projectId, docType, docId, @@ -79,7 +79,9 @@ export function getDocumentByDocIdQueryKey({ ] as const } -export function getDocumentByVersionIdQueryKey({ +export function getDocumentByVersionIdQueryKey< + D extends WriteableDocumentType, +>({ projectId, docType, versionId, @@ -100,7 +102,7 @@ export function getDocumentByVersionIdQueryKey({ ] as const } -export function documentsQueryOptions({ +export function documentsQueryOptions({ projectApi, projectId, docType, @@ -131,7 +133,7 @@ export function documentsQueryOptions({ } export function documentByDocumentIdQueryOptions< - D extends MutableDocumentType, + D extends WriteableDocumentType, >({ projectApi, projectId, @@ -163,7 +165,9 @@ export function documentByDocumentIdQueryOptions< }) } -export function documentByVersionIdQueryOptions({ +export function documentByVersionIdQueryOptions< + D extends WriteableDocumentType, +>({ projectApi, projectId, docType, @@ -190,7 +194,7 @@ export function documentByVersionIdQueryOptions({ }) } -export function createDocumentMutationOptions({ +export function createDocumentMutationOptions({ docType, projectApi, projectId, @@ -205,7 +209,7 @@ export function createDocumentMutationOptions({ ...baseMutationOptions(), mutationFn: async ({ value, - }): Promise & { forks: Array }> => { + }): Promise & { forks: Array }> => { // @ts-expect-error TS not handling this well return projectApi[docType].create({ ...value, @@ -221,13 +225,13 @@ export function createDocumentMutationOptions({ }) }, } satisfies UseMutationOptions< - MutableDocument & { forks: Array }, + WriteableDocument & { forks: Array }, Error, - { value: Omit, 'schemaName'> } + { value: Omit, 'schemaName'> } > } -export function updateDocumentMutationOptions({ +export function updateDocumentMutationOptions({ docType, projectApi, projectId, @@ -243,7 +247,7 @@ export function updateDocumentMutationOptions({ mutationFn: async ({ versionId, value, - }): Promise & { forks: Array }> => { + }): Promise & { forks: Array }> => { // @ts-expect-error TS not handling this well return projectApi[docType].update(versionId, value) }, @@ -256,16 +260,16 @@ export function updateDocumentMutationOptions({ }) }, } satisfies UseMutationOptions< - MutableDocument & { forks: Array }, + WriteableDocument & { forks: Array }, Error, { versionId: string - value: Omit, 'schemaName'> + value: Omit, 'schemaName'> } > } -export function deleteDocumentMutationOptions({ +export function deleteDocumentMutationOptions({ docType, projectApi, projectId, @@ -280,7 +284,7 @@ export function deleteDocumentMutationOptions({ ...baseMutationOptions(), mutationFn: async ({ docId, - }): Promise & { forks: Array }> => { + }): Promise & { forks: Array }> => { // @ts-expect-error TS not handling this well return projectApi[docType].delete(docId) }, @@ -293,7 +297,7 @@ export function deleteDocumentMutationOptions({ }) }, } satisfies UseMutationOptions< - MutableDocument & { forks: Array }, + WriteableDocument & { forks: Array }, Error, { docId: string } >