-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/main' into feature/add-vue-que…
…ry-package * upstream/main: chore: update versions Update tests Changeset Add tests and fixes for deletes with useSubscriptionQuery fix(deps): update dependency eslint-config-universe to v12.1.0 chore: update versions Add changeset Adding additional base case and tests fix: correctly parse and sort using JSON expressions chore(deps): update react monorepo to v18.3.0 fix(deps): update nextjs monorepo to v14.2.0 chore(deps): update dependency @testing-library/react to v14.3.0
- Loading branch information
Showing
20 changed files
with
151 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { get } from '../../src/lib/get'; | ||
|
||
describe('get', () => { | ||
it.each([ | ||
[{ a: 1 }, 'a', undefined, 1], // simple case | ||
[{ a: 1 }, 'b', 2, 2], // default case | ||
[{ a: 1 }, '', undefined, undefined], // empty case | ||
[{ a: { b: 1 } }, 'a.b', undefined, 1], // dot syntax | ||
[{ a: { b: 1 } }, 'a,b', undefined, 1], // comma syntax | ||
[{ a: { b: 1 } }, 'a[b]', undefined, 1], // bracket syntax | ||
[{ a: { b: { c: { d: 1 } } } }, 'a.b,c.[d]', undefined, 1], // combination syntax | ||
[{ a: { b: 1 } }, 'a->b', undefined, 1], // json value syntax | ||
[{ a: { b: 1 } }, 'a->>b', undefined, '1'], // json string syntax | ||
[{ a: [1, 2] }, 'a->0', undefined, 1], // json array value syntax | ||
[{ a: [1, 2] }, 'a->>0', undefined, '1'], // json array string syntax | ||
[{ a: { b: { c: 1 } } }, 'a->b->c', undefined, 1], // nested json syntax | ||
[{ a: { b: { c: 1 } } }, 'a->b->>c', undefined, '1'], | ||
[{ a: { b: [1, 2] } }, 'a.b->0', undefined, 1], | ||
[{ a: { b: [1, 2] } }, 'a.b->>0', undefined, '1'], | ||
[{ a: { b: 1 } }, 'a->0', undefined, undefined], // not an array | ||
[{ a: [1, 2] }, 'a->2', undefined, undefined], // missing array value | ||
])('get(%j, "%s", %s) should be %s', (obj, path, defaultValue, expected) => { | ||
expect(get(obj, path, defaultValue)).toEqual(expected); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,22 @@ | ||
export const get = (obj: any, path: string, defaultValue: any = undefined) => { | ||
const travel = (regexp: RegExp) => | ||
String.prototype.split | ||
.call(path, regexp) | ||
.filter(Boolean) | ||
.reduce( | ||
(res, key) => (res !== null && res !== undefined ? res[key] : res), | ||
obj, | ||
); | ||
const result = travel(/[,[\]]+?/) || travel(/[,[\].]+?/); | ||
const split = path.split(/((?:\.|,|\[|\]|->>|->)+)/g); | ||
let result: any = obj; | ||
for (let i = -1; i < split.length; i += 2) { | ||
const separator = split[i]; | ||
let key: string | number = split[i + 1]; | ||
if (!key) { | ||
continue; | ||
} | ||
if (separator?.endsWith('->') || separator?.endsWith('->>')) { | ||
if (/^\d+$/.test(key)) { | ||
key = parseInt(key, 10); | ||
} | ||
} | ||
if (separator?.endsWith('->>')) { | ||
result = `${result ? result[key] : result}`; | ||
} else { | ||
result = result ? result[key] : result; | ||
} | ||
} | ||
return result === undefined || result === obj ? defaultValue : result; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@supabase-cache-helpers/postgrest-react-query", | ||
"version": "1.6.2", | ||
"version": "1.6.4", | ||
"author": "Philipp Steinrötter <[email protected]>", | ||
"homepage": "https://supabase-cache-helpers.vercel.app", | ||
"bugs": { | ||
|
@@ -58,7 +58,7 @@ | |
"devDependencies": { | ||
"@supabase/supabase-js": "2.38.5", | ||
"@supabase/postgrest-js": "1.9.0", | ||
"@testing-library/react": "14.2.0", | ||
"@testing-library/react": "14.3.0", | ||
"@testing-library/jest-dom": "6.4.0", | ||
"jest-environment-jsdom": "29.7.0", | ||
"@types/jest": "29.5.0", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@supabase-cache-helpers/postgrest-swr", | ||
"version": "1.7.1", | ||
"version": "1.7.3", | ||
"author": "Philipp Steinrötter <[email protected]>", | ||
"homepage": "https://supabase-cache-helpers.vercel.app", | ||
"bugs": { | ||
|
@@ -67,7 +67,7 @@ | |
"@supabase/postgrest-js": "1.9.0", | ||
"@supabase/supabase-js": "2.38.5", | ||
"@testing-library/jest-dom": "6.4.0", | ||
"@testing-library/react": "14.2.0", | ||
"@testing-library/react": "14.3.0", | ||
"@types/jest": "29.5.0", | ||
"@types/react": "18.2.0", | ||
"dotenv": "16.4.0", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters