Skip to content

Commit 78bee26

Browse files
committed
fix: address pr comments
1 parent 4976409 commit 78bee26

4 files changed

Lines changed: 11 additions & 6 deletions

File tree

packages/clients/tanstack-query/src/common/client.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ import type { QueryClient } from '@tanstack/query-core';
22
import type { InvalidationPredicate, QueryInfo } from '@zenstackhq/client-helpers';
33
import { parseQueryKey } from './query-key.js';
44

5+
/** Strips a trailing slash from an endpoint URL. */
6+
export function normalizeEndpoint(endpoint: string) {
7+
return endpoint.replace(/\/$/, '');
8+
}
9+
510
export function invalidateQueriesMatchingPredicate(queryClient: QueryClient, predicate: InvalidationPredicate) {
611
return queryClient.invalidateQueries({
712
predicate: ({ queryKey }) => {

packages/clients/tanstack-query/src/react.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ import type {
6565
} from '@zenstackhq/orm';
6666
import type { GetModels, SchemaDef } from '@zenstackhq/schema';
6767
import { createContext, useContext } from 'react';
68-
import { getAllQueries, invalidateQueriesMatchingPredicate } from './common/client.js';
68+
import { getAllQueries, invalidateQueriesMatchingPredicate, normalizeEndpoint } from './common/client.js';
6969
import { CUSTOM_PROC_ROUTE_NAME } from './common/constants.js';
7070
import { getQueryKey } from './common/query-key.js';
7171
import { makeTransactionMutationFn, makeTransactionOnSuccess } from './common/transaction.js';
@@ -832,7 +832,7 @@ function useFetchOptions(options: QueryContext | undefined) {
832832
const { endpoint, fetch, logging } = useHooksContext();
833833
// options take precedence over context
834834
return {
835-
endpoint: options?.endpoint ?? endpoint,
835+
endpoint: normalizeEndpoint(options?.endpoint ?? endpoint),
836836
fetch: options?.fetch ?? fetch,
837837
logging: options?.logging ?? logging,
838838
};

packages/clients/tanstack-query/src/svelte/index.svelte.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ import type {
6262
} from '@zenstackhq/orm';
6363
import type { GetModels, SchemaDef } from '@zenstackhq/schema';
6464
import { getContext, setContext } from 'svelte';
65-
import { getAllQueries, invalidateQueriesMatchingPredicate } from '../common/client.js';
65+
import { getAllQueries, invalidateQueriesMatchingPredicate, normalizeEndpoint } from '../common/client.js';
6666
import { CUSTOM_PROC_ROUTE_NAME } from '../common/constants.js';
6767
import { getQueryKey } from '../common/query-key.js';
6868
import { makeTransactionMutationFn, makeTransactionOnSuccess } from '../common/transaction.js';
@@ -741,7 +741,7 @@ function useFetchOptions(options: Accessor<QueryContext> | undefined) {
741741
const optionsValue = options?.();
742742
// options take precedence over context
743743
return {
744-
endpoint: optionsValue?.endpoint ?? endpoint,
744+
endpoint: normalizeEndpoint(optionsValue?.endpoint ?? endpoint),
745745
fetch: optionsValue?.fetch ?? fetch,
746746
logging: optionsValue?.logging ?? logging,
747747
};

packages/clients/tanstack-query/src/vue.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ import type {
6060
} from '@zenstackhq/orm';
6161
import type { GetModels, SchemaDef } from '@zenstackhq/schema';
6262
import { computed, inject, provide, toValue, unref, type MaybeRefOrGetter, type Ref, type UnwrapRef } from 'vue';
63-
import { getAllQueries, invalidateQueriesMatchingPredicate } from './common/client.js';
63+
import { getAllQueries, invalidateQueriesMatchingPredicate, normalizeEndpoint } from './common/client.js';
6464
import { CUSTOM_PROC_ROUTE_NAME } from './common/constants.js';
6565
import { getQueryKey } from './common/query-key.js';
6666
import { makeTransactionMutationFn, makeTransactionOnSuccess } from './common/transaction.js';
@@ -762,7 +762,7 @@ function useFetchOptions(options: MaybeRefOrGetter<QueryContext | undefined>) {
762762
const optionsValue = toValue(options);
763763
// options take precedence over context
764764
return {
765-
endpoint: optionsValue?.endpoint ?? endpoint,
765+
endpoint: normalizeEndpoint(optionsValue?.endpoint ?? endpoint),
766766
fetch: optionsValue?.fetch ?? fetch,
767767
logging: optionsValue?.logging ?? logging,
768768
};

0 commit comments

Comments
 (0)