Comparing version 2.0.3 to 2.0.4
@@ -6,2 +6,3 @@ import react, { FC, PropsWithChildren, MutableRefObject } from 'react'; | ||
declare const MUTATE_EVENT = 2; | ||
declare const ERROR_REVALIDATE_EVENT = 3; | ||
@@ -11,2 +12,3 @@ declare const constants_FOCUS_EVENT: typeof FOCUS_EVENT; | ||
declare const constants_MUTATE_EVENT: typeof MUTATE_EVENT; | ||
declare const constants_ERROR_REVALIDATE_EVENT: typeof ERROR_REVALIDATE_EVENT; | ||
declare namespace constants { | ||
@@ -17,2 +19,3 @@ export { | ||
constants_MUTATE_EVENT as MUTATE_EVENT, | ||
constants_ERROR_REVALIDATE_EVENT as ERROR_REVALIDATE_EVENT, | ||
}; | ||
@@ -241,3 +244,3 @@ } | ||
} | ||
type KeyedMutator<Data> = (data?: Data | Promise<Data> | MutatorCallback<Data>, opts?: boolean | MutatorOptions<Data>) => Promise<Data | undefined>; | ||
type KeyedMutator<Data> = (data?: Data | Promise<Data | undefined> | MutatorCallback<Data>, opts?: boolean | MutatorOptions<Data>) => Promise<Data | undefined>; | ||
type SWRConfiguration<Data = any, Error = any, Fn extends BareFetcher<any> = BareFetcher<any>> = Partial<PublicConfiguration<Data, Error, Fn>>; | ||
@@ -264,3 +267,3 @@ type SWROptions<Data> = SWRConfiguration<Data, Error, Fetcher<Data, Key>>; | ||
type Revalidator = (revalidateOpts?: RevalidatorOptions) => Promise<boolean> | void; | ||
type RevalidateEvent = typeof FOCUS_EVENT | typeof RECONNECT_EVENT | typeof MUTATE_EVENT; | ||
type RevalidateEvent = typeof FOCUS_EVENT | typeof RECONNECT_EVENT | typeof MUTATE_EVENT | typeof ERROR_REVALIDATE_EVENT; | ||
type RevalidateCallbackReturnType = { | ||
@@ -270,4 +273,5 @@ [FOCUS_EVENT]: void; | ||
[MUTATE_EVENT]: Promise<boolean>; | ||
[ERROR_REVALIDATE_EVENT]: void; | ||
}; | ||
type RevalidateCallback = <K extends RevalidateEvent>(type: K) => RevalidateCallbackReturnType[K]; | ||
type RevalidateCallback = <K extends RevalidateEvent>(type: K, opts?: any) => RevalidateCallbackReturnType[K]; | ||
interface Cache<Data = any> { | ||
@@ -274,0 +278,0 @@ keys(): IterableIterator<string>; |
@@ -215,2 +215,3 @@ import React, { useEffect, useLayoutEffect, createContext, useContext, useMemo, useState, createElement, useRef, useCallback } from 'react'; | ||
const MUTATE_EVENT = 2; | ||
const ERROR_REVALIDATE_EVENT = 3; | ||
@@ -221,3 +222,4 @@ var constants = { | ||
RECONNECT_EVENT: RECONNECT_EVENT, | ||
MUTATE_EVENT: MUTATE_EVENT | ||
MUTATE_EVENT: MUTATE_EVENT, | ||
ERROR_REVALIDATE_EVENT: ERROR_REVALIDATE_EVENT | ||
}; | ||
@@ -402,4 +404,4 @@ | ||
if (subs) { | ||
for(let i = subs.length; i--;){ | ||
subs[i](value, prev); | ||
for (const fn of subs){ | ||
fn(value, prev); | ||
} | ||
@@ -406,0 +408,0 @@ } |
@@ -221,2 +221,3 @@ Object.defineProperty(exports, '__esModule', { value: true }); | ||
const MUTATE_EVENT = 2; | ||
const ERROR_REVALIDATE_EVENT = 3; | ||
@@ -227,3 +228,4 @@ var constants = { | ||
RECONNECT_EVENT: RECONNECT_EVENT, | ||
MUTATE_EVENT: MUTATE_EVENT | ||
MUTATE_EVENT: MUTATE_EVENT, | ||
ERROR_REVALIDATE_EVENT: ERROR_REVALIDATE_EVENT | ||
}; | ||
@@ -408,4 +410,4 @@ | ||
if (subs) { | ||
for(let i = subs.length; i--;){ | ||
subs[i](value, prev); | ||
for (const fn of subs){ | ||
fn(value, prev); | ||
} | ||
@@ -412,0 +414,0 @@ } |
import { useRef, useMemo, useCallback, useDebugValue } from 'react'; | ||
import { useSyncExternalStore } from 'use-sync-external-store/shim/index.js'; | ||
import { OBJECT, SWRConfig as SWRConfig$1, defaultConfig, withArgs, SWRGlobalState, serialize, createCacheHelper, isUndefined, getTimestamp, UNDEFINED, isFunction, internalMutate, useIsomorphicLayoutEffect, subscribeCallback, IS_SERVER, rAF, IS_REACT_LEGACY, mergeObjects, revalidateEvents } from 'swr/_internal'; | ||
import { OBJECT, SWRConfig as SWRConfig$1, defaultConfig, withArgs, SWRGlobalState, serialize, createCacheHelper, isUndefined, getTimestamp, UNDEFINED, isFunction, revalidateEvents, internalMutate, useIsomorphicLayoutEffect, subscribeCallback, IS_SERVER, rAF, IS_REACT_LEGACY, mergeObjects } from 'swr/_internal'; | ||
export { mutate, preload, useSWRConfig } from 'swr/_internal'; | ||
@@ -286,3 +286,8 @@ | ||
// When retrying, deduplication is always enabled. | ||
currentConfig.onErrorRetry(err, key, currentConfig, revalidate, { | ||
currentConfig.onErrorRetry(err, key, currentConfig, (_opts)=>{ | ||
const revalidators = EVENT_REVALIDATORS[key]; | ||
if (revalidators && revalidators[0]) { | ||
revalidators[0](revalidateEvents.ERROR_REVALIDATE_EVENT, _opts); | ||
} | ||
}, { | ||
retryCount: (opts.retryCount || 0) + 1, | ||
@@ -341,3 +346,3 @@ dedupe: true | ||
let nextFocusRevalidatedAt = 0; | ||
const onRevalidate = (type)=>{ | ||
const onRevalidate = (type, opts = {})=>{ | ||
if (type == revalidateEvents.FOCUS_EVENT) { | ||
@@ -355,2 +360,4 @@ const now = Date.now(); | ||
return revalidate(); | ||
} else if (type == revalidateEvents.ERROR_REVALIDATE_EVENT) { | ||
return revalidate(opts); | ||
} | ||
@@ -357,0 +364,0 @@ return; |
@@ -287,3 +287,8 @@ Object.defineProperty(exports, '__esModule', { value: true }); | ||
// When retrying, deduplication is always enabled. | ||
currentConfig.onErrorRetry(err, key, currentConfig, revalidate, { | ||
currentConfig.onErrorRetry(err, key, currentConfig, (_opts)=>{ | ||
const revalidators = EVENT_REVALIDATORS[key]; | ||
if (revalidators && revalidators[0]) { | ||
revalidators[0](_internal.revalidateEvents.ERROR_REVALIDATE_EVENT, _opts); | ||
} | ||
}, { | ||
retryCount: (opts.retryCount || 0) + 1, | ||
@@ -342,3 +347,3 @@ dedupe: true | ||
let nextFocusRevalidatedAt = 0; | ||
const onRevalidate = (type)=>{ | ||
const onRevalidate = (type, opts = {})=>{ | ||
if (type == _internal.revalidateEvents.FOCUS_EVENT) { | ||
@@ -356,2 +361,4 @@ const now = Date.now(); | ||
return revalidate(); | ||
} else if (type == _internal.revalidateEvents.ERROR_REVALIDATE_EVENT) { | ||
return revalidate(opts); | ||
} | ||
@@ -358,0 +365,0 @@ return; |
@@ -1,2 +0,2 @@ | ||
import { Key, MutatorOptions, SWRResponse } from 'swr'; | ||
import { Key, SWRResponse } from 'swr'; | ||
@@ -8,8 +8,13 @@ type FetcherResponse<Data> = Data | Promise<Data>; | ||
type MutationFetcher<Data = unknown, ExtraArg = unknown, SWRKey extends Key = Key> = SWRKey extends () => infer Arg | null | undefined | false ? (key: Arg, options: FetcherOptions<ExtraArg>) => FetcherResponse<Data> : SWRKey extends null | undefined | false ? never : SWRKey extends infer Arg ? (key: Arg, options: FetcherOptions<ExtraArg>) => FetcherResponse<Data> : never; | ||
type SWRMutationConfiguration<Data, Error, ExtraArg = any, SWRMutationKey extends Key = Key> = MutatorOptions<Data> & { | ||
type SWRMutationConfiguration<Data, Error, ExtraArg = any, SWRMutationKey extends Key = Key, SWRData = any> = { | ||
revalidate?: boolean; | ||
populateCache?: boolean | ((result: Data, currentData: SWRData | undefined) => SWRData); | ||
optimisticData?: SWRData | ((currentData?: SWRData) => SWRData); | ||
rollbackOnError?: boolean | ((error: unknown) => boolean); | ||
throwOnError?: boolean; | ||
fetcher?: MutationFetcher<Data, ExtraArg, SWRMutationKey>; | ||
onSuccess?: (data: Data, key: string, config: Readonly<SWRMutationConfiguration<Data, Error, ExtraArg, SWRMutationKey>>) => void; | ||
onError?: (err: Error, key: string, config: Readonly<SWRMutationConfiguration<Data, Error, ExtraArg, SWRMutationKey>>) => void; | ||
onSuccess?: (data: Data, key: string, config: Readonly<SWRMutationConfiguration<Data, Error, ExtraArg, SWRMutationKey, SWRData>>) => void; | ||
onError?: (err: Error, key: string, config: Readonly<SWRMutationConfiguration<Data, Error, ExtraArg, SWRMutationKey, SWRData>>) => void; | ||
}; | ||
interface SWRMutationResponse<Data = any, Error = any, ExtraArg = any, SWRMutationKey extends Key = Key> extends Pick<SWRResponse<Data, Error>, 'data' | 'error'> { | ||
interface SWRMutationResponse<Data = any, Error = any, ExtraArg = never, SWRMutationKey extends Key = Key> extends Pick<SWRResponse<Data, Error>, 'data' | 'error'> { | ||
/** | ||
@@ -23,3 +28,3 @@ * Indicates if the mutation is in progress. | ||
*/ | ||
trigger: (extraArgument?: ExtraArg, options?: SWRMutationConfiguration<Data, Error, ExtraArg, SWRMutationKey>) => Promise<Data | undefined>; | ||
trigger: [ExtraArg] extends [never] ? <SWRData = Data>(extraArgument?: null, options?: SWRMutationConfiguration<Data, Error, ExtraArg, SWRMutationKey, SWRData>) => Promise<Data | undefined> : <SWRData = Data>(extraArgument: ExtraArg, options?: SWRMutationConfiguration<Data, Error, ExtraArg, SWRMutationKey, SWRData>) => Promise<Data | undefined>; | ||
/** | ||
@@ -30,3 +35,3 @@ * Function to reset the mutation state (`data`, `error`, and `isMutating`). | ||
} | ||
type SWRMutationHook = <Data = any, Error = any, SWRMutationKey extends Key = Key, ExtraArg = any>( | ||
type SWRMutationHook = <Data = any, Error = any, SWRMutationKey extends Key = Key, ExtraArg = never>( | ||
/** | ||
@@ -33,0 +38,0 @@ * The key of the resource that will be mutated. It should be the same key |
{ | ||
"name": "swr", | ||
"version": "2.0.3", | ||
"version": "2.0.4", | ||
"description": "React Hooks library for remote data fetching", | ||
@@ -13,3 +13,3 @@ "keywords": [ | ||
], | ||
"packageManager": "pnpm@7.1.0", | ||
"packageManager": "pnpm@7.26.1", | ||
"main": "./core/dist/index.js", | ||
@@ -70,5 +70,6 @@ "module": "./core/dist/index.esm.js", | ||
"csb:build": "pnpm build", | ||
"clean": "pnpm -r run clean", | ||
"clean": "pnpm -r run clean && rimraf playwright-report test-result", | ||
"watch": "pnpm -r run watch", | ||
"build": "pnpm build-package _internal && pnpm build-package core && pnpm build-package infinite && pnpm build-package immutable && pnpm build-package mutation", | ||
"build:e2e": "pnpm next build e2e/site", | ||
"build-package": "bunchee index.ts --cwd", | ||
@@ -85,2 +86,3 @@ "types:check": "pnpm -r run types:check", | ||
"test": "jest", | ||
"test:e2e": "playwright test", | ||
"run-all-checks": "pnpm types:check && pnpm lint && pnpm test && pnpm test-typing" | ||
@@ -95,3 +97,3 @@ }, | ||
"devDependencies": { | ||
"@swc/core": "^1.3.22", | ||
"@swc/core": "^1.3.29", | ||
"@swc/jest": "0.2.24", | ||
@@ -101,28 +103,28 @@ "@testing-library/jest-dom": "^5.16.5", | ||
"@type-challenges/utils": "0.1.1", | ||
"@types/jest": "^29.2.4", | ||
"@types/node": "^18.11.13", | ||
"@types/react": "^18.0.26", | ||
"@types/jest": "^29.4.0", | ||
"@types/node": "^18.11.18", | ||
"@types/react": "^18.0.27", | ||
"@types/use-sync-external-store": "^0.0.3", | ||
"@typescript-eslint/eslint-plugin": "5.46.1", | ||
"@typescript-eslint/parser": "5.46.1", | ||
"@typescript-eslint/eslint-plugin": "5.49.0", | ||
"@typescript-eslint/parser": "5.49.0", | ||
"bunchee": "2.2.0", | ||
"eslint": "8.29.0", | ||
"eslint-config-prettier": "8.5.0", | ||
"eslint": "8.32.0", | ||
"eslint-config-prettier": "8.6.0", | ||
"eslint-plugin-jest-dom": "4.0.3", | ||
"eslint-plugin-react": "7.31.11", | ||
"eslint-plugin-react": "7.32.1", | ||
"eslint-plugin-react-hooks": "4.6.0", | ||
"eslint-plugin-testing-library": "5.9.1", | ||
"husky": "8.0.2", | ||
"jest": "29.3.1", | ||
"jest-environment-jsdom": "29.3.1", | ||
"lint-staged": "13.0.3", | ||
"next": "^13.0.6", | ||
"prettier": "2.8.1", | ||
"publint": "^0.1.8", | ||
"eslint-plugin-testing-library": "5.10.0", | ||
"husky": "8.0.3", | ||
"jest": "29.4.1", | ||
"jest-environment-jsdom": "29.4.1", | ||
"lint-staged": "13.1.0", | ||
"next": "^13.1.6", | ||
"prettier": "2.8.3", | ||
"publint": "^0.1.9", | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0", | ||
"rimraf": "3.0.2", | ||
"rimraf": "4.1.2", | ||
"swr": "workspace:*", | ||
"tslib": "2.4.1", | ||
"typescript": "4.9.4" | ||
"typescript": "4.9.4", | ||
"@playwright/test": "^1.30.0" | ||
}, | ||
@@ -129,0 +131,0 @@ "peerDependencies": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
231571
5189