diff --git a/example/components/FilmList.tsx b/example/components/FilmList.tsx index 6a89aa4..029c944 100644 --- a/example/components/FilmList.tsx +++ b/example/components/FilmList.tsx @@ -55,9 +55,7 @@ export const FilmList = ({ node.id === id) - .getWithDefault(false)} + isActive={activeFilm.map((id) => node.id === id).getOr(false)} onPress={onPressFilm} /> ); diff --git a/package.json b/package.json index c378fbd..90c86db 100644 --- a/package.json +++ b/package.json @@ -50,8 +50,8 @@ }, "dependencies": { "@0no-co/graphql.web": "^1.0.6", - "@swan-io/boxed": "^2.1.1", - "@swan-io/request": "^1.0.4", + "@swan-io/boxed": "^2.2.1", + "@swan-io/request": "^1.0.5", "ts-pattern": "^5.1.0" }, "peerDependencies": { diff --git a/src/cache/cache.ts b/src/cache/cache.ts index 4ff895e..8c06e3b 100644 --- a/src/cache/cache.ts +++ b/src/cache/cache.ts @@ -94,7 +94,7 @@ export class ClientCache { const serializedVariables = serializeVariables(variables); const documentCache = Option.fromNullable( this.operationCache.get(documentNode), - ).getWithDefault(new Map()); + ).getOr(new Map()); documentCache.set(serializedVariables, Option.Some(data)); this.operationCache.set(documentNode, documentCache); } diff --git a/src/cache/read.ts b/src/cache/read.ts index 052a026..b0f284c 100644 --- a/src/cache/read.ts +++ b/src/cache/read.ts @@ -264,7 +264,7 @@ export const readOperationFromCache = ( previous .flatMap((previous) => previous.toOption()) .map((previous) => deepEqual(value, previous)) - .getWithDefault(false) + .getOr(false) ) { return previous; } else { diff --git a/src/client.ts b/src/client.ts index ff35820..664b30c 100644 --- a/src/client.ts +++ b/src/client.ts @@ -51,7 +51,7 @@ const defaultMakeRequest: MakeRequest = ({ method: "POST", responseType: "json", headers, - withCredentials: Option.fromNullable(withCredentials).getWithDefault(false), + withCredentials: Option.fromNullable(withCredentials).getOr(false), body: JSON.stringify({ operationName, query: print(document), @@ -185,9 +185,7 @@ export class Client { this.getTransformedDocumentsForRequest(document); const operationName = - getExecutableOperationName(transformedDocument).getWithDefault( - "Untitled", - ); + getExecutableOperationName(transformedDocument).getOr("Untitled"); const variablesAsRecord = variables as Record; @@ -211,9 +209,7 @@ export class Client { return this.makeRequest({ url: this.url, operationName, - document: possiblyOptimizedQuery.getWithDefault( - transformedDocumentsForRequest, - ), + document: possiblyOptimizedQuery.getOr(transformedDocumentsForRequest), variables: variablesAsRecord, ...overrides, headers: { diff --git a/src/graphql/ast.ts b/src/graphql/ast.ts index 394fc5c..d2eebae 100644 --- a/src/graphql/ast.ts +++ b/src/graphql/ast.ts @@ -289,7 +289,7 @@ export const addIdIfPreviousSelected = ( ...newSelectionSet.selections, ] as readonly SelectionNode[], })) - .getWithDefault(newSelectionSet); + .getOr(newSelectionSet); }; export const isExcluded = ( diff --git a/src/react/useDeferredQuery.ts b/src/react/useDeferredQuery.ts index 0f66741..304a3be 100644 --- a/src/react/useDeferredQuery.ts +++ b/src/react/useDeferredQuery.ts @@ -62,7 +62,7 @@ export const useDeferredQuery = ( const asyncData = useMemo(() => { return data .map((value) => AsyncData.Done(value as Result)) - .getWithDefault(AsyncData.NotAsked()); + .getOr(AsyncData.NotAsked()); }, [data]); const runQuery = useCallback( diff --git a/src/react/useQuery.ts b/src/react/useQuery.ts index dc347d3..b048d27 100644 --- a/src/react/useQuery.ts +++ b/src/react/useQuery.ts @@ -88,7 +88,7 @@ export const useQuery = ( const asyncData = useMemo(() => { return data .map((value) => AsyncData.Done(value as Result)) - .getWithDefault(AsyncData.Loading()); + .getOr(AsyncData.Loading()); }, [data]); const previousAsyncData = usePreviousValue(asyncData); diff --git a/test/__snapshots__/cache.test.ts.snap b/test/__snapshots__/cache.test.ts.snap index 96279dd..0c135ee 100644 --- a/test/__snapshots__/cache.test.ts.snap +++ b/test/__snapshots__/cache.test.ts.snap @@ -725,9 +725,9 @@ Map { `; exports[`Write & read in cache 7`] = ` -t { +{ "tag": "Some", - "value": t { + "value": { "tag": "Ok", "value": { "__typename": "Query", @@ -818,6 +818,8 @@ t { ], }, }, + Symbol(__boxed_type__): "Result", }, + Symbol(__boxed_type__): "Option", } `; diff --git a/test/cache.test.ts b/test/cache.test.ts index 3628a64..5e466cb 100644 --- a/test/cache.test.ts +++ b/test/cache.test.ts @@ -176,13 +176,13 @@ test("Write & read in cache", () => { expect( optimizeQuery(cache, preparedOtherAppQuery, { id: "1" }) .map(print) - .getWithDefault("no delta"), + .getOr("no delta"), ).toMatchSnapshot(); expect( optimizeQuery(cache, preparedAppQueryWithExtraArrayInfo, { id: "1" }) .map(print) - .getWithDefault("no delta"), + .getOr("no delta"), ).toMatchSnapshot(); const cache2 = new ClientCache({ interfaceToTypes: {} }); diff --git a/yarn.lock b/yarn.lock index 52f0316..31120c7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1444,15 +1444,15 @@ resolved "https://registry.yarnpkg.com/@sinclair/typebox/-/typebox-0.27.8.tgz#6667fac16c436b5434a387a34dedb013198f6e6e" integrity sha512-+Fj43pSMwJs4KRrH/938Uf+uAELIgVBmQzg/q1YG10djyfA3TnrU8N8XzqCh/okZdszqBQTZf96idMfE5lnwTA== -"@swan-io/boxed@^2.1.1": - version "2.1.1" - resolved "https://registry.yarnpkg.com/@swan-io/boxed/-/boxed-2.1.1.tgz#bdf17d725270c8560d2371972427b6f7e80da5d8" - integrity sha512-NzmIVAnJuzuPwm8ZR4I9tUpuo9qjtVNA7aTSZYdSvcJ+y7NTyt9+tCi4y87T3m8hACN2ATMqvTmRtHOSDIIz7w== +"@swan-io/boxed@^2.2.1": + version "2.2.1" + resolved "https://registry.yarnpkg.com/@swan-io/boxed/-/boxed-2.2.1.tgz#adda3c08bad0215a90cfced371817484ef90ad50" + integrity sha512-jJiiVd9CzVPQUb8OuFeGddruTkbLBNCiL2RvN8Jt+Eul7EMkXB/gY4dUYffxyLMDnn2t3EaZahYQ+yHvtLxzDg== -"@swan-io/request@^1.0.4": - version "1.0.4" - resolved "https://registry.yarnpkg.com/@swan-io/request/-/request-1.0.4.tgz#9578892306b92c335b064051e165a55268817d14" - integrity sha512-3KguAxPCJ0EBlETij2volJw68k4lOw4nxjw1SkjStyjA50awFxx5UwgUeGfocsDbI7EwPqs1oH3E23hoAcni5w== +"@swan-io/request@^1.0.5": + version "1.0.5" + resolved "https://registry.yarnpkg.com/@swan-io/request/-/request-1.0.5.tgz#3e4fd8e0d699bde18fa7338939c4f2de92ab7dae" + integrity sha512-inXD6hBUmbbDyzAAL30yEaIuSmTCjzyGpQwejdTTDE63qNnDpOVj4SZzsMgph8q1xCq5r3tLm5QgvN2HGuneIw== "@types/estree@1.0.5", "@types/estree@^1.0.0": version "1.0.5"