Skip to content

Commit cb030e3

Browse files
authored
Merge pull request #5 from StudioLambda/chore/audit-low-severity-issues
Fix low-severity audit issues across codebase
2 parents 79217a5 + d72a761 commit cb030e3

File tree

10 files changed

+34
-34
lines changed

10 files changed

+34
-34
lines changed

src/query/options.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export interface Configuration extends Options {
3232
*
3333
* By default it does not use any broadcast channel.
3434
* If a broadcast channel is provided, query
35-
* won't close automatically, therefore, the responsability
35+
* won't close automatically, therefore, the responsibility
3636
* of closing the broadcast channel is up to the user.
3737
*/
3838
readonly broadcast?: BroadcastChannel
@@ -107,7 +107,7 @@ export interface BroadcastPayload {
107107
/**
108108
* The event name.
109109
*/
110-
readonly event: QueryEvent
110+
readonly event: `${QueryEvent}:${string}`
111111

112112
/**
113113
* The event detail.
@@ -150,14 +150,14 @@ export type FetcherFunction<T = unknown> = {
150150
}
151151

152152
/**
153-
* The mutate function options.
153+
* The hydrate function options.
154154
*/
155155
export interface HydrateOptions<T = unknown> {
156156
/**
157157
* Custom expiration function for the hydrated item, overriding
158158
* the default expiration configuration.
159159
*/
160-
expiration?: ExpirationOptionFunction<T>
160+
readonly expiration?: ExpirationOptionFunction<T>
161161
}
162162

163163
/**
@@ -168,7 +168,7 @@ export interface MutateOptions<T = unknown> {
168168
* Custom expiration function for the mutated item, overriding
169169
* the default expiration configuration.
170170
*/
171-
expiration?: ExpirationOptionFunction<T>
171+
readonly expiration?: ExpirationOptionFunction<T>
172172
}
173173

174174
/**
@@ -211,7 +211,7 @@ export type SequenceFunction = {
211211
* for one or more keys after a refetching event occurs.
212212
*/
213213
export type NextFunction = {
214-
<T = unknown>(keys: string | { [K in keyof T]: string }): Promise<T>
214+
<T = unknown>(keys: string | { [K in keyof T]: string }, signal?: AbortSignal): Promise<T>
215215
}
216216

217217
/**
@@ -227,7 +227,7 @@ export type StreamFunction = {
227227
* Allows partial updates to the configuration options.
228228
*/
229229
export type ConfigureFunction = {
230-
(options?: Partial<Configuration>): void
230+
(options?: Configuration): void
231231
}
232232

233233
/**
@@ -289,7 +289,7 @@ export interface Query {
289289
/**
290290
* Emit is able to send events to active subscribers
291291
* with the given payload. It is a low level API
292-
* and should be used with case.
292+
* and should be used with care.
293293
*/
294294
readonly emit: EmitFunction
295295

@@ -311,7 +311,7 @@ export interface Query {
311311
/**
312312
* Mutates the key with a given optimistic value.
313313
* The mutated value is considered expired and will be
314-
* replaced immediatly if a refetch happens.
314+
* replaced immediately if a refetch happens.
315315
*/
316316
readonly mutate: MutateFunction
317317

@@ -324,8 +324,8 @@ export interface Query {
324324
readonly abort: AbortFunction
325325

326326
/**
327-
* Forgets the given keys from the cache.
328-
* Removes items from both, the cache and resolvers.
327+
* Forgets the given keys from the items cache.
328+
* Does not remove any resolvers.
329329
*/
330330
readonly forget: ForgetFunction
331331

src/query/query.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ describe.concurrent('query', function () {
741741
const event = await promise
742742

743743
expect(event).toBeDefined()
744-
expect(event).toBeDefined()
744+
expect(event.detail).toBe('works')
745745
})
746746

747747
it('uses the same promises for the same result', ({ expect, signal }) => {

src/query/query.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ import {
2222
} from 'query:options'
2323

2424
/**
25-
* Stores the default fetcher function.
25+
* Creates a default fetcher function that performs JSON requests
26+
* using the provided fetch implementation.
2627
*/
2728
export function defaultFetcher<T>(
2829
fetch: (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>
@@ -70,7 +71,7 @@ export function createQuery(instanceOptions?: Configuration): Query {
7071
*
7172
* By default it does not use any broadcast channel.
7273
* If a broadcast channel is provided, query
73-
* won't close automatically, therefore, the responsability
74+
* won't close automatically, therefore, the responsibility
7475
* of closing the broadcast channel is up to the user.
7576
*/
7677
let broadcast = instanceOptions?.broadcast
@@ -153,7 +154,7 @@ export function createQuery(instanceOptions?: Configuration): Query {
153154
* does have a payload parameter that will contain relevant
154155
* information depending on the event type.
155156
* If there's a pending resolver for that key, the `refetching`
156-
* event is fired immediatly.
157+
* event is fired immediately.
157158
*/
158159
function subscribe<T = unknown>(
159160
key: string,
@@ -163,7 +164,7 @@ export function createQuery(instanceOptions?: Configuration): Query {
163164
events.addEventListener(`${event}:${key}`, listener)
164165
const value = resolversCache.get(key)
165166

166-
// For the refetching event, we want to immediatly return if there's
167+
// For the refetching event, we want to immediately return if there's
167168
// a pending resolver.
168169
if (event === 'refetching' && value !== undefined) {
169170
emit(key, event, value.item)
@@ -177,7 +178,7 @@ export function createQuery(instanceOptions?: Configuration): Query {
177178
/**
178179
* Mutates the key with a given optimistic value.
179180
* The mutated value is considered expired and will be
180-
* replaced immediatly if a refetch happens when expired
181+
* replaced immediately if a refetch happens when expired
181182
* is true. If expired is false, the value expiration time
182183
* is added as if it was a valid data refetched. Alternatively
183184
* you can provide a Date to decide when the expiration happens.
@@ -224,7 +225,7 @@ export function createQuery(instanceOptions?: Configuration): Query {
224225
}
225226

226227
/**
227-
* Determines if the given key is currently resolving.
228+
* Returns all keys currently stored in the specified cache.
228229
*/
229230
function keys(type: CacheType = 'items'): readonly string[] {
230231
return Array.from(type === 'items' ? itemsCache.keys() : resolversCache.keys())
@@ -335,7 +336,7 @@ export function createQuery(instanceOptions?: Configuration): Query {
335336
const fetcher = (options?.fetcher ?? instanceFetcher) as FetcherFunction<T>
336337

337338
/**
338-
* Determines if we can return a sale item
339+
* Determines if we can return a stale item.
339340
* If true, it will return the previous stale item
340341
* stored in the cache if it has expired. It will attempt
341342
* to revalidate it in the background. If false, the returned
@@ -384,7 +385,7 @@ export function createQuery(instanceOptions?: Configuration): Query {
384385
// before we write to the cache, bail out to avoid writing
385386
// stale data that contradicts the abort.
386387
if (controller.signal.aborted) {
387-
reject(controller.signal.reason as Error)
388+
reject(controller.signal.reason)
388389
return
389390
}
390391

@@ -418,7 +419,7 @@ export function createQuery(instanceOptions?: Configuration): Query {
418419
emit(key, 'error', error)
419420

420421
// Throw back the error.
421-
reject(error as Error)
422+
reject(error)
422423
}
423424
}
424425
})
@@ -461,13 +462,13 @@ export function createQuery(instanceOptions?: Configuration): Query {
461462
// in the background.
462463
if (hasExpired && stale) {
463464
// We have to silence the error to avoid unhandled promises.
464-
// Refer to the error event if you need full controll of errors.
465+
// Refer to the error event if you need full control of errors.
465466
refetch(key).catch(() => {})
466467

467468
return cached.item as Promise<T>
468469
}
469470

470-
// The item has expired but we dont allow stale
471+
// The item has expired but we don't allow stale
471472
// responses so we need to wait for the revalidation.
472473
if (hasExpired) {
473474
return refetch(key)

src/react/components/QueryPrefetch.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ describe.concurrent('QueryPrefetch', function () {
2828
const query = createQuery({ fetcher })
2929
const promise = query.once('/user', 'refetching')
3030

31-
// eslint-disable-next-line
31+
// oxlint-disable-next-line
3232
await act(async function () {
3333
createRoot(container).render(
3434
<QueryProvider query={query}>

src/react/components/QueryPrefetchTags.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ export interface QueryPrefetchTagsProps extends Additional {
4343
* }
4444
* ```
4545
*/
46-
export function QueryPrefetchTags({ keys, children, ...options }: QueryPrefetchTagsProps) {
47-
useQueryPrefetch(keys, options)
46+
export function QueryPrefetchTags({ keys, children, query, ...linkProps }: QueryPrefetchTagsProps) {
47+
useQueryPrefetch(keys, { query })
4848

4949
const tags = keys.map((key) => (
50-
<link key={key} rel="preload" href={key} as="fetch" {...options} />
50+
<link key={key} rel="preload" href={key} as="fetch" {...linkProps} />
5151
))
5252

5353
return (

src/react/components/QueryProvider.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ describe.concurrent('QueryProvider', function () {
2727
const query = createQuery({ fetcher })
2828
const promise = query.once('/user', 'refetching')
2929

30-
// eslint-disable-next-line
30+
// oxlint-disable-next-line
3131
await act(async function () {
3232
createRoot(container).render(
3333
<QueryProvider query={query}>

src/react/components/QueryTransition.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ export interface QueryTransitionProps {
99
/**
1010
* Indicates whether a transition is currently pending.
1111
*/
12-
isPending: boolean
12+
readonly isPending: boolean
1313

1414
/**
1515
* The function to start a transition, typically from useTransition.
1616
*/
17-
startTransition: TransitionStartFunction
17+
readonly startTransition: TransitionStartFunction
1818

1919
/**
2020
* The child elements that will have access to the transition context.
2121
*/
22-
children?: ReactNode
22+
readonly children?: ReactNode
2323
}
2424

2525
/**

src/react/hooks/useQuery.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ describe.concurrent('useQuery', function () {
2222
const container = document.createElement('div')
2323
const promise = query.next<string>('/user')
2424

25-
// eslint-disable-next-line
25+
// oxlint-disable-next-line
2626
await act(async function () {
2727
createRoot(container).render(
2828
<Suspense fallback="loading">

src/react/hooks/useQueryPrefetch.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ describe.concurrent('useQueryPrefetch', function () {
2323

2424
const promise = query.next<[string, string]>(['/user', '/config'])
2525

26-
// eslint-disable-next-line
26+
// oxlint-disable-next-line
2727
await act(async function () {
2828
createRoot(container).render(
2929
<Suspense fallback="loading">

tsconfig.base.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
"esModuleInterop": true,
1414
"declaration": true,
1515
"emitDeclarationOnly": true,
16-
"skipDefaultLibCheck": true,
1716
"skipLibCheck": true,
1817
"noUnusedLocals": true,
1918
"noUnusedParameters": true,

0 commit comments

Comments
 (0)