Skip to content

Commit dfe1b7f

Browse files
Merge pull request #5 from sduduzog/use-vue-demi
Use vue demi to support Vue2 and Vue3
2 parents 6a15079 + 732dc69 commit dfe1b7f

File tree

5 files changed

+119
-91
lines changed

5 files changed

+119
-91
lines changed

README.md

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22

33
A supa simple wrapper around Supabase.js to enable usage within Vue.
44

5-
## Usage
6-
7-
```
5+
## Installation
6+
```bash
7+
# Vue 3.x
88
yarn add vue-supabase
9+
# Vue 2.x
10+
yarn add @vue/composition-api vue-supabase
911
```
10-
11-
12+
Note: Currently `@vue/composition-api` is required for this package to work for projects using Vue 2.x even if the composition api is not used in that particular project
13+
## Usage
14+
### Vue 2.x
1215
```js
1316
import VueSupabase from 'vue-supabase'
1417

@@ -19,6 +22,31 @@ Vue.use(VueSupabase, {
1922
});
2023
```
2124

25+
### Vue 3.x
26+
```js
27+
import VueSupabase from 'vue-supabase'
28+
29+
const app = createApp(...)
30+
31+
app.use(VueSupabase, {
32+
supabaseUrl: '',
33+
supaaseKey: '',
34+
supabaseOptions: {},
35+
})
36+
37+
app.mount(...)
38+
```
39+
40+
### Options API
2241
```js
2342
const { data, error } = await this.$supabase.from("events").select("*");
2443
```
44+
45+
### Composition API
46+
```js
47+
import { useSupabase } from 'vue-supabase';
48+
49+
const supabase = useSupabase()
50+
51+
const { data, error } = await supabase.from("events").select("*");
52+
```

index.d.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,15 @@ declare module 'vue/types/vue' {
77
$supabase: SupabaseClient
88
}
99
}
10+
11+
/**
12+
* Used to get the injected instance of SupabaseClient.
13+
* If using Vuejs 2.x, this function will be undefined, please use
14+
* `this.$supabase` instead.
15+
* @returns SupabaseClient
16+
*/
17+
export function useSupabase(key?: string): SupabaseClient;
18+
19+
export default {
20+
install(Vue: typeof Vue, options: any): void
21+
}

index.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,31 @@
11
'use strict';
2+
const { isVue3, inject } = require('vue-demi');
23

34
const { createClient } = require('@supabase/supabase-js')
45

5-
module.exports = {
6-
install: function (Vue, options) {
7-
const supabase = createClient(options.supabaseUrl, options.supabaseKey, options.supabaseOptions)
6+
const supabaseSymbol = Symbol('supabase');
87

9-
Object.defineProperties(Vue.prototype, {
8+
function useSupabase() {
9+
return inject(supabaseSymbol);
10+
}
11+
12+
function install(app, options) {
13+
const supabase = createClient(options.supabaseUrl, options.supabaseKey, options.supabaseOptions)
14+
15+
if (isVue3){
16+
app.config.globalProperties.$supabase = supabase;
17+
app.provide(supabaseSymbol, supabase);
18+
} else {
19+
Object.defineProperties(app.prototype, {
1020
$supabase: {
1121
get: function() {
1222
return supabase;
1323
},
1424
},
1525
});
16-
17-
Vue.supabase = supabase;
26+
app.supabase = supabase;
1827
}
19-
}
28+
}
29+
30+
exports.install = install;
31+
exports.useSupabase = useSupabase;

package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,11 @@
3030
},
3131
"homepage": "https://github.com/scottrobertson/vue-supabase#readme",
3232
"dependencies": {
33-
"@supabase/supabase-js": "^1.4.2"
33+
"@supabase/supabase-js": "^1.4.2",
34+
"vue-demi": "^0.11.2"
3435
},
3536
"peerDependencies": {
36-
"vue": ">=1.x.x"
37-
},
38-
"devDependencies": {
39-
"vue": "^2"
37+
"@vue/composition-api": "^1.0.4",
38+
"vue": "^2.0.0 || >=3.0.0"
4039
}
4140
}

yarn.lock

Lines changed: 51 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,54 @@
22
# yarn lockfile v1
33

44

5-
"@supabase/gotrue-js@^1.11.2":
6-
version "1.11.2"
7-
resolved "https://registry.yarnpkg.com/@supabase/gotrue-js/-/gotrue-js-1.11.2.tgz#51e20124b4740903aa5a33a7d8ade16ac9303d07"
8-
integrity sha512-QYrA8wYTwofJcwQ5hWkg7HyDenykxSMUMImo7Um884EPHIhyZMJaCw9DK+p87f7HJ6rdYvCDF20LK1GcsMOB0A==
5+
"@supabase/gotrue-js@^1.16.6":
6+
version "1.16.6"
7+
resolved "https://registry.yarnpkg.com/@supabase/gotrue-js/-/gotrue-js-1.16.6.tgz#d9d63740b11ad51d2f8d6c68e9ac16bb83439888"
8+
integrity sha512-tLaG4G4sMW2P1hyq05Nr0jM/6AbdiWkjOPbM+QZsuVSsNbZ/z+BNxuE5q+6zHOnoP+YKEHup7x9xKR0zy2UqUQ==
99
dependencies:
1010
cross-fetch "^3.0.6"
1111

12-
"@supabase/postgrest-js@^0.24.4":
13-
version "0.24.5"
14-
resolved "https://registry.yarnpkg.com/@supabase/postgrest-js/-/postgrest-js-0.24.5.tgz#bfad12442bd7eef2e44d7698c08f3cd72e63f712"
15-
integrity sha512-DJWynRWLIVSnEHGWsPoLd7hjVO9MekPPWHwKUX/8uJnRS+SGj61EnvC5EIB2DkmSQSO0HJHXRt90nwvnTG/YVA==
12+
"@supabase/postgrest-js@^0.33.0":
13+
version "0.33.0"
14+
resolved "https://registry.yarnpkg.com/@supabase/postgrest-js/-/postgrest-js-0.33.0.tgz#36e0bfd0f79a0fa01a4bb7c7881ee463fd7d60a8"
15+
integrity sha512-og6Evdkan7Qp6+tOch7Pyq+ZWMnrCQtPHWwPpsN5A3iYQSro2yn21Yvazs9qAFoWAeTGNkuTOVpShT5Mbc9WcQ==
1616
dependencies:
1717
cross-fetch "^3.0.6"
1818

19-
"@supabase/realtime-js@^1.0.6":
20-
version "1.0.6"
21-
resolved "https://registry.yarnpkg.com/@supabase/realtime-js/-/realtime-js-1.0.6.tgz#d4cb1a9351cc8c836ee3f1392742a4466e0d7424"
22-
integrity sha512-qzYYBzXteYsqQYlLzoYwee2OloWn3w8YzUFbDYFUPdkUwLs01OIqsm+lRCzKDivmyn2G0FJQjloWcF4BF5TyBg==
19+
"@supabase/realtime-js@^1.0.11":
20+
version "1.0.11"
21+
resolved "https://registry.yarnpkg.com/@supabase/realtime-js/-/realtime-js-1.0.11.tgz#2b3a0b7822bcb8b2cf6201ec3c34220be23f40de"
22+
integrity sha512-jE8/8I64VpEygEbrd9+RBZBIREo43Vacy8exef1QlyRegblG2VtqqK96BiQSaVG5ZwXumOs6Igl8kgyrDqUAPg==
2323
dependencies:
2424
"@types/websocket" "^1.0.1"
25-
query-string "^6.12.1"
26-
websocket "^1.0.31"
25+
websocket "^1.0.34"
26+
27+
"@supabase/storage-js@^1.2.2":
28+
version "1.2.2"
29+
resolved "https://registry.yarnpkg.com/@supabase/storage-js/-/storage-js-1.2.2.tgz#6eeef2d1365af2497b35ae6c6384f5dfbd75f5b6"
30+
integrity sha512-EJ2BsfD7Mc+fXJqRef3YiWF8kg/GhBdxIil7EzmrAFBSJ3VCbN4sqzvCCUYK2dtNICUV3JOKh5SBX2RrgROIOA==
31+
dependencies:
32+
cross-fetch "^3.1.0"
2733

2834
"@supabase/supabase-js@^1.4.2":
29-
version "1.4.2"
30-
resolved "https://registry.yarnpkg.com/@supabase/supabase-js/-/supabase-js-1.4.2.tgz#ebd6a7459b9c401def80cff9431d1cd445cccadd"
31-
integrity sha512-qczdclPR85glzKjg0ed9bnKUt0HoxFq47MTsUN5MEQ5w5uk/dpnF2MYawLR7ATgoXCokxdWWB2pdzjbBTrTpUQ==
35+
version "1.18.1"
36+
resolved "https://registry.yarnpkg.com/@supabase/supabase-js/-/supabase-js-1.18.1.tgz#58fa3dfff3a1f86c169c83330282120195f6c5f1"
37+
integrity sha512-YZhp867/HV9Az8icouAJ7S2j1SV4ZlshvQ1wTR0aV+Em+TTj9ZiS6GVykCjKn2SE2cUfG/wgmaXm9tiKecUhFg==
3238
dependencies:
33-
"@supabase/gotrue-js" "^1.11.2"
34-
"@supabase/postgrest-js" "^0.24.4"
35-
"@supabase/realtime-js" "^1.0.6"
39+
"@supabase/gotrue-js" "^1.16.6"
40+
"@supabase/postgrest-js" "^0.33.0"
41+
"@supabase/realtime-js" "^1.0.11"
42+
"@supabase/storage-js" "^1.2.2"
3643

3744
"@types/node@*":
38-
version "14.14.31"
39-
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.31.tgz#72286bd33d137aa0d152d47ec7c1762563d34055"
40-
integrity sha512-vFHy/ezP5qI0rFgJ7aQnjDXwAMrG0KqqIH7tQG5PPv3BWBayOPIQNBjVc/P6hhdZfMx51REc6tfDNXHUio893g==
45+
version "16.3.2"
46+
resolved "https://registry.yarnpkg.com/@types/node/-/node-16.3.2.tgz#655432817f83b51ac869c2d51dd8305fb8342e16"
47+
integrity sha512-jJs9ErFLP403I+hMLGnqDRWT0RYKSvArxuBVh2veudHV7ifEC1WAmjJADacZ7mRbA2nWgHtn8xyECMAot0SkAw==
4148

4249
"@types/websocket@^1.0.1":
43-
version "1.0.1"
44-
resolved "https://registry.yarnpkg.com/@types/websocket/-/websocket-1.0.1.tgz#039272c196c2c0e4868a0d8a1a27bbb86e9e9138"
45-
integrity sha512-f5WLMpezwVxCLm1xQe/kdPpQIOmL0TXYx2O15VYfYzc7hTIdxiOoOvez+McSIw3b7z/1zGovew9YSL7+h4h7/Q==
50+
version "1.0.3"
51+
resolved "https://registry.yarnpkg.com/@types/websocket/-/websocket-1.0.3.tgz#49e09f939afd0ccdee4f7108d4712ec9feb0f153"
52+
integrity sha512-ZdoTSwmDsKR7l1I8fpfQtmTI/hUwlOvE3q0iyJsp4tXU0MkdrYowimDzwxjhQvxU4qjhHLd3a6ig0OXRbLgIdw==
4653
dependencies:
4754
"@types/node" "*"
4855

@@ -53,10 +60,10 @@ bufferutil@^4.0.1:
5360
dependencies:
5461
node-gyp-build "^4.2.0"
5562

56-
cross-fetch@^3.0.6:
57-
version "3.0.6"
58-
resolved "https://registry.yarnpkg.com/cross-fetch/-/cross-fetch-3.0.6.tgz#3a4040bc8941e653e0e9cf17f29ebcd177d3365c"
59-
integrity sha512-KBPUbqgFjzWlVcURG+Svp9TlhA5uliYtiNx/0r8nv0pdypeQCRJ9IaSIc3q/x3q8t3F75cHuwxVql1HFGHCNJQ==
63+
cross-fetch@^3.0.6, cross-fetch@^3.1.0:
64+
version "3.1.4"
65+
resolved "https://registry.yarnpkg.com/cross-fetch/-/cross-fetch-3.1.4.tgz#9723f3a3a247bf8b89039f3a380a9244e8fa2f39"
66+
integrity sha512-1eAtFWdIubi6T4XPy6ei9iUFoKpUkIF971QLN8lIvvvwueI65+Nw5haMNKUwfJxabqlIIDODJKGrQ66gxC0PbQ==
6067
dependencies:
6168
node-fetch "2.6.1"
6269

@@ -75,11 +82,6 @@ debug@^2.2.0:
7582
dependencies:
7683
ms "2.0.0"
7784

78-
decode-uri-component@^0.2.0:
79-
version "0.2.0"
80-
resolved "https://registry.yarnpkg.com/decode-uri-component/-/decode-uri-component-0.2.0.tgz#eb3913333458775cb84cd1a1fae062106bb87545"
81-
integrity sha1-6zkTMzRYd1y4TNGh+uBiEGu4dUU=
82-
8385
es5-ext@^0.10.35, es5-ext@^0.10.50:
8486
version "0.10.53"
8587
resolved "https://registry.yarnpkg.com/es5-ext/-/es5-ext-0.10.53.tgz#93c5a3acfdbef275220ad72644ad02ee18368de1"
@@ -113,11 +115,6 @@ ext@^1.1.2:
113115
dependencies:
114116
type "^2.0.0"
115117

116-
filter-obj@^1.1.0:
117-
version "1.1.0"
118-
resolved "https://registry.yarnpkg.com/filter-obj/-/filter-obj-1.1.0.tgz#9b311112bc6c6127a16e016c6c5d7f19e0805c5b"
119-
integrity sha1-mzERErxsYSehbgFsbF1/GeCAXFs=
120-
121118
is-typedarray@^1.0.0:
122119
version "1.0.0"
123120
resolved "https://registry.yarnpkg.com/is-typedarray/-/is-typedarray-1.0.0.tgz#e479c80858df0c1b11ddda6940f96011fcda4a9a"
@@ -143,35 +140,15 @@ node-gyp-build@^4.2.0:
143140
resolved "https://registry.yarnpkg.com/node-gyp-build/-/node-gyp-build-4.2.3.tgz#ce6277f853835f718829efb47db20f3e4d9c4739"
144141
integrity sha512-MN6ZpzmfNCRM+3t57PTJHgHyw/h4OWnZ6mR8P5j/uZtqQr46RRuDE/P+g3n0YR/AiYXeWixZZzaip77gdICfRg==
145142

146-
query-string@^6.12.1:
147-
version "6.14.1"
148-
resolved "https://registry.yarnpkg.com/query-string/-/query-string-6.14.1.tgz#7ac2dca46da7f309449ba0f86b1fd28255b0c86a"
149-
integrity sha512-XDxAeVmpfu1/6IjyT/gXHOl+S0vQ9owggJ30hhWKdHAsNPOcasn5o9BW0eejZqL2e4vMjhAxoW3jVHcD6mbcYw==
150-
dependencies:
151-
decode-uri-component "^0.2.0"
152-
filter-obj "^1.1.0"
153-
split-on-first "^1.0.0"
154-
strict-uri-encode "^2.0.0"
155-
156-
split-on-first@^1.0.0:
157-
version "1.1.0"
158-
resolved "https://registry.yarnpkg.com/split-on-first/-/split-on-first-1.1.0.tgz#f610afeee3b12bce1d0c30425e76398b78249a5f"
159-
integrity sha512-43ZssAJaMusuKWL8sKUBQXHWOpq8d6CfN/u1p4gUzfJkM05C8rxTmYrkIPTXapZpORA6LkkzcUulJ8FqA7Uudw==
160-
161-
strict-uri-encode@^2.0.0:
162-
version "2.0.0"
163-
resolved "https://registry.yarnpkg.com/strict-uri-encode/-/strict-uri-encode-2.0.0.tgz#b9c7330c7042862f6b142dc274bbcc5866ce3546"
164-
integrity sha1-ucczDHBChi9rFC3CdLvMWGbONUY=
165-
166143
type@^1.0.1:
167144
version "1.2.0"
168145
resolved "https://registry.yarnpkg.com/type/-/type-1.2.0.tgz#848dd7698dafa3e54a6c479e759c4bc3f18847a0"
169146
integrity sha512-+5nt5AAniqsCnu2cEQQdpzCAh33kVx8n0VoFidKpB1dVVLAN/F+bgVOqOJqOnEnrhp222clB5p3vUlD+1QAnfg==
170147

171148
type@^2.0.0:
172-
version "2.3.0"
173-
resolved "https://registry.yarnpkg.com/type/-/type-2.3.0.tgz#ada7c045f07ead08abf9e2edd29be1a0c0661132"
174-
integrity sha512-rgPIqOdfK/4J9FhiVrZ3cveAjRRo5rsQBAIhnylX874y1DX/kEKSVdLsnuHB6l1KTjHyU01VjiMBHgU2adejyg==
149+
version "2.5.0"
150+
resolved "https://registry.yarnpkg.com/type/-/type-2.5.0.tgz#0a2e78c2e77907b252abe5f298c1b01c63f0db3d"
151+
integrity sha512-180WMDQaIMm3+7hGXWf12GtdniDEy7nYcyFMKJn/eZz/6tSLXrUN9V0wKSbMjej0I1WHWbpREDEKHtqPQa9NNw==
175152

176153
typedarray-to-buffer@^3.1.5:
177154
version "3.1.5"
@@ -181,21 +158,21 @@ typedarray-to-buffer@^3.1.5:
181158
is-typedarray "^1.0.0"
182159

183160
utf-8-validate@^5.0.2:
184-
version "5.0.4"
185-
resolved "https://registry.yarnpkg.com/utf-8-validate/-/utf-8-validate-5.0.4.tgz#72a1735983ddf7a05a43a9c6b67c5ce1c910f9b8"
186-
integrity sha512-MEF05cPSq3AwJ2C7B7sHAA6i53vONoZbMGX8My5auEVm6W+dJ2Jd/TZPyGJ5CH42V2XtbI5FD28HeHeqlPzZ3Q==
161+
version "5.0.5"
162+
resolved "https://registry.yarnpkg.com/utf-8-validate/-/utf-8-validate-5.0.5.tgz#dd32c2e82c72002dc9f02eb67ba6761f43456ca1"
163+
integrity sha512-+pnxRYsS/axEpkrrEpzYfNZGXp0IjC/9RIxwM5gntY4Koi8SHmUGSfxfWqxZdRxrtaoVstuOzUp/rbs3JSPELQ==
187164
dependencies:
188165
node-gyp-build "^4.2.0"
189166

190-
vue@^2:
191-
version "2.6.12"
192-
resolved "https://registry.yarnpkg.com/vue/-/vue-2.6.12.tgz#f5ebd4fa6bd2869403e29a896aed4904456c9123"
193-
integrity sha512-uhmLFETqPPNyuLLbsKz6ioJ4q7AZHzD8ZVFNATNyICSZouqP2Sz0rotWQC8UNBF6VGSCs5abnKJoStA6JbCbfg==
167+
vue-demi@^0.11.2:
168+
version "0.11.2"
169+
resolved "https://registry.yarnpkg.com/vue-demi/-/vue-demi-0.11.2.tgz#faa06da53887c493a695b997f4fcb4784a667990"
170+
integrity sha512-J+X8Au6BhQdcej6LY4O986634hZLu55L0ewU2j8my7WIKlu8cK0dqmdUxqVHHMd/cMrKKZ9SywB/id6aLhwCtA==
194171

195-
websocket@^1.0.31:
196-
version "1.0.33"
197-
resolved "https://registry.yarnpkg.com/websocket/-/websocket-1.0.33.tgz#407f763fc58e74a3fa41ca3ae5d78d3f5e3b82a5"
198-
integrity sha512-XwNqM2rN5eh3G2CUQE3OHZj+0xfdH42+OFK6LdC2yqiC0YU8e5UK0nYre220T0IyyN031V/XOvtHvXozvJYFWA==
172+
websocket@^1.0.34:
173+
version "1.0.34"
174+
resolved "https://registry.yarnpkg.com/websocket/-/websocket-1.0.34.tgz#2bdc2602c08bf2c82253b730655c0ef7dcab3111"
175+
integrity sha512-PRDso2sGwF6kM75QykIesBijKSVceR6jL2G8NGYyq2XrItNC2P5/qL5XeR056GhA+Ly7JMFvJb9I312mJfmqnQ==
199176
dependencies:
200177
bufferutil "^4.0.1"
201178
debug "^2.2.0"

0 commit comments

Comments
 (0)