Skip to content

Commit f839c29

Browse files
committed
feat: initial commit
0 parents  commit f839c29

28 files changed

+2825
-0
lines changed

.config/.lintstagedrc.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
'*.{js,ts,tsx}': ['yarn lint:fix'],
3+
'*.{json,md,yaml}': ['yarn lint:format'],
4+
}

.config/commitlint.config.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
extends: ['@commitlint/config-conventional'],
3+
}

.config/husky/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
_

.config/husky/commit-msg

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
npx commitlint --config .config/commitlint.config.js --edit $1

.config/husky/pre-commit

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
npx lint-staged --config .config/.lintstagedrc.js

.envrc.example

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export VITE_SUPABASE_URL=
2+
export VITE_SUPABASE_KEY=

.eslintignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
dist/
2+
node_modules/
3+
playground/types/supabase.ts

.eslintrc.js

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
module.exports = {
2+
root: true,
3+
parser: '@typescript-eslint/parser',
4+
parserOptions: {
5+
ecmaVersion: 8,
6+
sourceType: 'module',
7+
ecmaFeatures: {
8+
impliedStrict: true,
9+
experimentalObjectRestSpread: true,
10+
},
11+
allowImportExportEverywhere: true,
12+
},
13+
plugins: ['@typescript-eslint', 'import'],
14+
extends: [
15+
'eslint:recommended',
16+
'plugin:@typescript-eslint/recommended',
17+
'plugin:import/errors',
18+
'plugin:import/warnings',
19+
'plugin:import/typescript',
20+
'plugin:jest-dom/recommended',
21+
'plugin:testing-library/react',
22+
'plugin:react/recommended',
23+
'plugin:react-hooks/recommended',
24+
'plugin:prettier/recommended',
25+
'prettier',
26+
],
27+
rules: {
28+
// `@typescript-eslint`
29+
// https://github.com/typescript-eslint/typescript-eslint
30+
'@typescript-eslint/explicit-module-boundary-types': 'off',
31+
'@typescript-eslint/no-explicit-any': 'off',
32+
'@typescript-eslint/no-unused-vars': [
33+
2,
34+
{
35+
argsIgnorePattern: '^_',
36+
},
37+
],
38+
// `eslint-plugin-import`
39+
// https://github.com/benmosher/eslint-plugin-import
40+
'import/order': [
41+
'error',
42+
{
43+
groups: ['external', 'internal'],
44+
'newlines-between': 'always-and-inside-groups',
45+
},
46+
],
47+
'sort-imports': [
48+
'warn',
49+
{
50+
ignoreCase: false,
51+
ignoreDeclarationSort: true,
52+
ignoreMemberSort: false,
53+
},
54+
],
55+
},
56+
settings: {
57+
'import/parsers': {
58+
'@typescript-eslint/parser': ['.ts', '.tsx'],
59+
},
60+
'import/resolver': {
61+
typescript: {
62+
alwaysTryTypes: true,
63+
},
64+
},
65+
react: {
66+
version: 'detect',
67+
},
68+
},
69+
env: {
70+
es6: true,
71+
browser: true,
72+
node: true,
73+
jest: true,
74+
},
75+
}

.github/README.md

Whitespace-only changes.

.github/dependabot.yaml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: 'npm'
4+
directory: '/'
5+
schedule:
6+
interval: 'monthly'
7+
open-pull-requests-limit: 0
8+
9+
- package-ecosystem: 'github-actions'
10+
directory: '/'
11+
schedule:
12+
interval: 'monthly'

.github/workflows/lint.yaml

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Lint
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: [main]
7+
8+
jobs:
9+
lint:
10+
name: Lint
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
node-version: [14]
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v2
18+
19+
- name: Set up Node ${{ matrix.node-version }}
20+
uses: actions/setup-node@v2
21+
with:
22+
node-version: ${{ matrix.node-version }}
23+
24+
- name: Load yarn cache
25+
uses: actions/[email protected]
26+
id: yarn-cache
27+
with:
28+
path: ./node_modules
29+
key: ${{ runner.os }}-yarn-cache-${{ hashFiles('**/yarn.lock') }}
30+
restore-keys: ${{ runner.os }}-yarn-cache-
31+
32+
- name: Install dependencies
33+
if: steps.yarn-cache.outputs.cache-hit != 'true'
34+
run: yarn --frozen-lockfile
35+
36+
- name: Lint code
37+
run: yarn lint
38+
39+
- name: Check types
40+
run: yarn lint:types
41+
42+
- name: Format other files
43+
run: yarn lint:format --check

.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.DS_Store
2+
.envrc
3+
.eslintcache
4+
dist/
5+
node_modules/
6+
yarn-debug.log*
7+
yarn-error.log*

.prettierignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
dist/
2+
node_modules/
3+
playground/types/supabase.ts
4+
yarn.lock

.prettierrc.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module.exports = {
2+
arrowParens: 'always',
3+
endOfLine: 'lf',
4+
printWidth: 80,
5+
semi: false,
6+
singleQuote: true,
7+
tabWidth: 4,
8+
trailingComma: 'all',
9+
overrides: [
10+
{
11+
files: '*.yaml',
12+
options: {
13+
tabWidth: 2,
14+
},
15+
},
16+
],
17+
}

.vim/coc-settings.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"eslint.autoFixOnSave": true,
3+
"eslint.probe": [
4+
"css",
5+
"javascript",
6+
"javascriptreact",
7+
"json",
8+
"markdown",
9+
"typescript",
10+
"typescriptreact"
11+
],
12+
"eslint.packageManager": "yarn"
13+
}

index.html

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<link rel="icon" type="image/svg+xml" href="/playground/favicon.svg" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>Vite Playground</title>
8+
</head>
9+
<body>
10+
<div id="root"></div>
11+
<script type="module" src="/playground/main.tsx"></script>
12+
</body>
13+
</html>

package.json

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
"name": "react-hook-supabase",
3+
"version": "1.0.0",
4+
"description": "React Hooks library for Supabase",
5+
"main": "./dist/index.cjs.js",
6+
"module": "./dist/index.es.js",
7+
"types": "./dist/types/index.d.ts",
8+
"files": [
9+
"dist"
10+
],
11+
"repository": "tmm/react-hook-supabase",
12+
"license": "MIT",
13+
"scripts": {
14+
"build": "vite build && tsc --emitDeclarationOnly",
15+
"build:watch": "vite build --watch",
16+
"clean": "rimraf dist",
17+
"dev": "vite",
18+
"gen": "npx openapi-typescript $VITE_SUPABASE_URL/rest/v1/?apikey=$VITE_SUPABASE_KEY --output playground/types/supabase.ts",
19+
"lint": "eslint . --cache",
20+
"lint:fix": "yarn lint --fix",
21+
"lint:format": "prettier --write .",
22+
"lint:types": "tsc --noEmit",
23+
"predev": "yarn gen",
24+
"prepare": "husky install .config/husky"
25+
},
26+
"peerDependencies": {
27+
"@supabase/supabase-js": "^1.11.6",
28+
"react": "^16.11.0 || ^17.0.0"
29+
},
30+
"devDependencies": {
31+
"@commitlint/config-conventional": "^12.1.1",
32+
"@supabase/postgrest-js": "^0.28.1",
33+
"@supabase/supabase-js": "^1.11.6",
34+
"@testing-library/react-hooks": "^5.1.1",
35+
"@types/node": "^14.14.41",
36+
"@types/react": "^17.0.3",
37+
"@typescript-eslint/eslint-plugin": "^4.22.0",
38+
"@typescript-eslint/parser": "^4.22.0",
39+
"eslint": "^7.24.0",
40+
"eslint-config-prettier": "^8.2.0",
41+
"eslint-import-resolver-typescript": "^2.4.0",
42+
"eslint-plugin-import": "^2.22.1",
43+
"eslint-plugin-jest-dom": "^3.8.0",
44+
"eslint-plugin-prettier": "^3.4.0",
45+
"eslint-plugin-react": "^7.23.2",
46+
"eslint-plugin-react-hooks": "^4.2.0",
47+
"eslint-plugin-testing-library": "^4.1.0",
48+
"husky": "^6.0.0",
49+
"prettier": "^2.2.1",
50+
"react": "^17.0.2",
51+
"react-dom": "^17.0.2",
52+
"react-hook-supabase": "file:./",
53+
"rimraf": "^3.0.2",
54+
"typescript": "^4.2.4",
55+
"vite": "^2.2.1"
56+
}
57+
}

playground/app.tsx

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import * as React from 'react'
2+
import { useState } from 'react'
3+
import { useSelect } from 'react-hook-supabase'
4+
5+
import { definitions } from './types/supabase'
6+
7+
const continents = [
8+
'Africa',
9+
'Antarctica',
10+
'Asia',
11+
'Europe',
12+
'Oceania',
13+
'North America',
14+
'South America',
15+
]
16+
17+
export const App: React.FC = () => {
18+
const [continent, setContinent] = useState(continents[0])
19+
const { data, loading } = useSelect<definitions['countries']>({
20+
table: 'countries',
21+
filter: (query) => query.filter('continent', 'eq', continent),
22+
})
23+
24+
// 1. Trigger update if filter changes
25+
// 2. Run reexecute with new filter function inside
26+
const changeContinent = () => {
27+
const currentIndex = continents.indexOf(continent)
28+
const nextIndex =
29+
currentIndex + 1 === continents.length ? 0 : currentIndex + 1
30+
setContinent(continents[nextIndex])
31+
}
32+
33+
return (
34+
<div>
35+
<h1>Countries of {continent}</h1>
36+
<button onClick={changeContinent}>Change continent</button>
37+
{loading || !data ? (
38+
<div>Loading...</div>
39+
) : (
40+
<ul>
41+
{data.map((x) => (
42+
<li key={x.id}>{x.name}</li>
43+
))}
44+
</ul>
45+
)}
46+
</div>
47+
)
48+
}

playground/favicon.svg

+15
Loading

playground/main.tsx

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import * as React from 'react'
2+
import * as ReactDOM from 'react-dom'
3+
import { createClient } from '@supabase/supabase-js'
4+
import { Provider } from 'react-hook-supabase'
5+
6+
import { App } from './app'
7+
8+
const client = createClient(
9+
import.meta.env.VITE_SUPABASE_URL as string,
10+
import.meta.env.VITE_SUPABASE_KEY as string,
11+
)
12+
13+
ReactDOM.render(
14+
<React.StrictMode>
15+
<Provider value={client}>
16+
<App />
17+
</Provider>
18+
</React.StrictMode>,
19+
document.getElementById('root'),
20+
)

0 commit comments

Comments
 (0)