Skip to content

Commit

Permalink
Merge pull request #306 from psteinroe/fix/query-without-wildcard
Browse files Browse the repository at this point in the history
fix: drop QueryWithoutWildcard type
  • Loading branch information
psteinroe authored Oct 23, 2023
2 parents f5ccb7a + e6cb820 commit b9e8205
Show file tree
Hide file tree
Showing 12 changed files with 18 additions and 29 deletions.
7 changes: 7 additions & 0 deletions .changeset/smooth-melons-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@supabase-cache-helpers/postgrest-react-query": patch
"@supabase-cache-helpers/postgrest-core": patch
"@supabase-cache-helpers/postgrest-swr": patch
---

fix: drop QueryWithoutWildcard type
8 changes: 2 additions & 6 deletions packages/postgrest-core/src/fetch/build-normalized-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@ import { buildSelectStatement } from './build-select-statement';
import { buildDedupePath } from './dedupe';
import { extractPathsFromFilters } from '../lib/extract-paths-from-filter';
import { parseSelectParam } from '../lib/parse-select-param';
import {
FilterDefinitions,
Path,
QueryWithoutWildcard,
} from '../lib/query-types';
import { FilterDefinitions, Path } from '../lib/query-types';
import { removeAliasFromDeclaration } from '../lib/remove-alias-from-declaration';

export type BuildNormalizedQueryOps<Q extends string = '*'> = {
query?: QueryWithoutWildcard<Q> | null;
query?: Q | null;
// if true, will not add any paths from the cache to the query
disabled?: boolean;
queriesForTable: () => { paths: Path[]; filters: FilterDefinitions }[];
Expand Down
5 changes: 0 additions & 5 deletions packages/postgrest-core/src/lib/query-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,3 @@ export type OrderDefinition = {
nullsFirst: boolean;
foreignTable?: string;
};

export type QueryWithoutWildcard<QueryString extends string> =
QueryString extends `${infer Any}*${infer Any}`
? 'Wildcard selector is not allowed'
: QueryString;
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
import {
buildDeleteFetcher,
getTable,
QueryWithoutWildcard,
} from '@supabase-cache-helpers/postgrest-core';
import { useMutation } from '@tanstack/react-query';

Expand All @@ -32,7 +31,7 @@ function useDeleteMutation<
>(
qb: PostgrestQueryBuilder<S, T, Re>,
primaryKeys: (keyof T['Row'])[],
query?: QueryWithoutWildcard<Q> | null,
query?: Q | null,
opts?: Omit<
UsePostgrestMutationOpts<S, T, Re, 'DeleteOne', Q, R>,
'mutationFn'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
import {
buildInsertFetcher,
getTable,
QueryWithoutWildcard,
} from '@supabase-cache-helpers/postgrest-core';
import { useMutation } from '@tanstack/react-query';

Expand All @@ -33,7 +32,7 @@ function useInsertMutation<
>(
qb: PostgrestQueryBuilder<S, T, Re>,
primaryKeys: (keyof T['Row'])[],
query?: QueryWithoutWildcard<Q> | null,
query?: Q | null,
opts?: Omit<UsePostgrestMutationOpts<S, T, Re, 'Insert', Q, R>, 'mutationFn'>,
) {
const queriesForTable = useQueriesForTableLoader(getTable(qb));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
import {
buildUpdateFetcher,
getTable,
QueryWithoutWildcard,
} from '@supabase-cache-helpers/postgrest-core';
import { useMutation } from '@tanstack/react-query';

Expand All @@ -32,7 +31,7 @@ function useUpdateMutation<
>(
qb: PostgrestQueryBuilder<S, T, Re>,
primaryKeys: (keyof T['Row'])[],
query?: QueryWithoutWildcard<Q> | null,
query?: Q | null,
opts?: Omit<
UsePostgrestMutationOpts<S, T, Re, 'UpdateOne', Q, R>,
'mutationFn'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
import {
buildUpsertFetcher,
getTable,
QueryWithoutWildcard,
} from '@supabase-cache-helpers/postgrest-core';
import { useMutation } from '@tanstack/react-query';

Expand All @@ -33,7 +32,7 @@ function useUpsertMutation<
>(
qb: PostgrestQueryBuilder<S, T, Re>,
primaryKeys: (keyof T['Row'])[],
query?: QueryWithoutWildcard<Q> | null,
query?: Q | null,
opts?: Omit<UsePostgrestMutationOpts<S, T, Re, 'Upsert', Q, R>, 'mutationFn'>,
) {
const queriesForTable = useQueriesForTableLoader(getTable(qb));
Expand Down
3 changes: 1 addition & 2 deletions packages/postgrest-swr/src/mutate/use-delete-mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
import {
buildDeleteFetcher,
getTable,
QueryWithoutWildcard,
} from '@supabase-cache-helpers/postgrest-core';
import useMutation, { SWRMutationResponse } from 'swr/mutation';

Expand All @@ -34,7 +33,7 @@ function useDeleteMutation<
>(
qb: PostgrestQueryBuilder<S, T, Re>,
primaryKeys: (keyof T['Row'])[],
query?: QueryWithoutWildcard<Q> | null,
query?: Q | null,
opts?: UsePostgrestSWRMutationOpts<S, T, Re, 'DeleteOne', Q, R>,
): SWRMutationResponse<R | null, PostgrestError, string, Partial<T['Row']>> {
const key = useRandomKey();
Expand Down
3 changes: 1 addition & 2 deletions packages/postgrest-swr/src/mutate/use-insert-mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
import {
buildInsertFetcher,
getTable,
QueryWithoutWildcard,
} from '@supabase-cache-helpers/postgrest-core';
import useMutation, { SWRMutationResponse } from 'swr/mutation';

Expand Down Expand Up @@ -35,7 +34,7 @@ function useInsertMutation<
>(
qb: PostgrestQueryBuilder<S, T, Re>,
primaryKeys: (keyof T['Row'])[],
query?: QueryWithoutWildcard<Q> | null,
query?: Q | null,
opts?: UsePostgrestSWRMutationOpts<S, T, Re, 'Insert', Q, R>,
): SWRMutationResponse<R[] | null, PostgrestError, string, T['Insert'][]> {
const key = useRandomKey();
Expand Down
3 changes: 1 addition & 2 deletions packages/postgrest-swr/src/mutate/use-update-mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
import {
buildUpdateFetcher,
getTable,
QueryWithoutWildcard,
} from '@supabase-cache-helpers/postgrest-core';
import useSWRMutation, { SWRMutationResponse } from 'swr/mutation';

Expand All @@ -34,7 +33,7 @@ function useUpdateMutation<
>(
qb: PostgrestQueryBuilder<S, T, Re>,
primaryKeys: (keyof T['Row'])[],
query?: QueryWithoutWildcard<Q> | null,
query?: Q | null,
opts?: UsePostgrestSWRMutationOpts<S, T, Re, 'UpdateOne', Q, R>,
): SWRMutationResponse<R | null, PostgrestError, string, T['Update']> {
const key = useRandomKey();
Expand Down
3 changes: 1 addition & 2 deletions packages/postgrest-swr/src/mutate/use-upsert-mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
import {
buildUpsertFetcher,
getTable,
QueryWithoutWildcard,
} from '@supabase-cache-helpers/postgrest-core';
import useMutation, { SWRMutationResponse } from 'swr/mutation';

Expand Down Expand Up @@ -35,7 +34,7 @@ function useUpsertMutation<
>(
qb: PostgrestQueryBuilder<S, T, Re>,
primaryKeys: (keyof T['Row'])[],
query?: QueryWithoutWildcard<Q> | null,
query?: Q | null,
opts?: UsePostgrestSWRMutationOpts<S, T, Re, 'Upsert', Q, R>,
): SWRMutationResponse<R[] | null, PostgrestError, string, T['Insert'][]> {
const key = useRandomKey();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
import {
buildNormalizedQuery,
PostgrestMutatorOpts,
QueryWithoutWildcard,
} from '@supabase-cache-helpers/postgrest-core';
import { useEffect, useState } from 'react';
import { MutatorOptions as SWRMutatorOptions } from 'swr';
Expand Down Expand Up @@ -77,7 +76,7 @@ function useSubscriptionQuery<
'table'
> & { table: string },
primaryKeys: (keyof T['Row'])[],
query?: QueryWithoutWildcard<Q> | null,
query?: Q | null,
opts?: UseSubscriptionQueryOpts<S, T, Re, Q, R>,
) {
const [status, setStatus] = useState<string>();
Expand Down

2 comments on commit b9e8205

@vercel
Copy link

@vercel vercel bot commented on b9e8205 Oct 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

supabase-cache-helpers-swr-demo – ./examples/swr

supabase-cache-helpers-swr-demo-psteinroe.vercel.app
supabase-cache-helpers-swr-demo-git-main-psteinroe.vercel.app
supabase-cache-helpers-swr.vercel.app

@vercel
Copy link

@vercel vercel bot commented on b9e8205 Oct 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

supabase-cache-helpers-react-query – ./examples/react-query

supabase-cache-helpers-react-query-psteinroe.vercel.app
supabase-cache-helpers-react-query.vercel.app
supabase-cache-helpers-react-query-git-main-psteinroe.vercel.app

Please sign in to comment.