Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vue 3.x Composition API use standard re-write #2

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 45 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ logs
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
Expand All @@ -16,11 +20,12 @@ lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
Expand All @@ -39,12 +44,21 @@ jspm_packages/
# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

Expand All @@ -56,6 +70,35 @@ typings/

# dotenv environment variables file
.env
.env.test

# next.js build output
# parcel-bundler cache (https://parceljs.org/)
.cache

# Next.js build output
.next

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and *not* Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port
43 changes: 33 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,47 @@
# Vue + Supabase
# Vue.js + Supabase

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

## Usage

```
```shell
npm install --save vue-supabase

# OR

yarn add vue-supabase
```

### Using with Vue.js 2.x

```js
import VueSupabase from 'vue-supabase'
This plugin is designed for Vue.js 3, but you can still use it with Vue.js 2. Please take a look at the v1.x.x tag [here](https://github.com/supabase/vue-supabase/tree/v1.x.x).

### Using with Vue.js 3.x

Vue.use(VueSupabase, {
supabaseUrl: "",
supabaseKey: "",
supabaseOptions: {},
```ts
// main.ts
import { createApp } from 'vue';
import { createSupabase } from 'vue-supabase';

import App from './App.vue';

const supabase = createSupabase({
url: "https://xyzcompany.supabase.co",
key: "public-anon-key",
options: {
// ...
};
});

createApp(App)
.use(supabase)
.mount('#app');
```

```js
const { data, error } = await this.$supabase.from("events").select("*");
// App.vue
import { useSupabase } from "vue-supabase";

const supabase = useSupabase();
const { data, error } = await supabase.from("events").select("*");
```
9 changes: 0 additions & 9 deletions index.d.ts

This file was deleted.

19 changes: 0 additions & 19 deletions index.js

This file was deleted.

35 changes: 35 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { createClient, SupabaseClient } from '@supabase/supabase-js';
import { Plugin } from 'vue';

import type { App } from 'vue';
import type { SupabaseClientOptions } from '@supabase/supabase-js';

let client_instance: SupabaseClient;

export interface VueSupabaseOptions {
key: string;
options?: SupabaseClientOptions;
url: string;
};

export const createSupabase = (options: VueSupabaseOptions): Plugin => {
return {
install(app: App) {
const {
key,
options: supabaseOptions = <SupabaseClientOptions>{},
url,
} = options;

client_instance = createClient(url, key, supabaseOptions);
app.config.globalProperties.$supabase = client_instance;
}
}
}

export const useSupabase = (): SupabaseClient => client_instance;

export default {
createSupabase,
useSupabase,
}
47 changes: 27 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,41 +1,48 @@
{
"name": "vue-supabase",
"version": "1.0.4",
"description": "A small wrapper for integrating supabase to Vuejs",
"main": "index.js",
"engine": {
"node": ">= 1"
},
"scripts": {
"test": "npm run test"
},
"version": "2.0.0-beta.1",
"description": "A small wrapper for integrating supabase to Vue.js",
"repository": {
"type": "git",
"url": "git+https://github.com/scottrobertson/vue-supabase.git"
"url": "git+https://github.com/supabase/vue-supabase.git"
},
"author": {
"name": "Scott Robertson"
},
"bugs": "https://github.com/supabase/vue-supabase/issues",
"homepage": "https://github.com/supabase/vue-supabase#readme",
"keywords": [
"vue",
"custom",
"supabase"
],
"author": "Scott Robertson",
"types": "index.d.ts",
"license": "MIT",
"main": "dist/index.js",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"files": [
"index.js",
"index.d.ts"
"dist"
],
"bugs": {
"url": "https://github.com/scottrobertson/vue-supabase/issues"
"engine": {
"node": ">= 1"
},
"scripts": {
"dev": "npm run build:base -- --watch",
"build": "npm run build:base -- --minify --sourcemap --env.NODE_ENV production",
"build:base": "rimraf dist && tsup index.ts --dts --format cjs,esm",
"publish": "npm run build && npm publish"
},
"homepage": "https://github.com/scottrobertson/vue-supabase#readme",
"dependencies": {
"@supabase/supabase-js": "^1.4.2"
"@supabase/supabase-js": "^1.5.1"
},
"peerDependencies": {
"vue": ">=1.x.x"
"vue": ">=3.x.x"
},
"devDependencies": {
"vue": "^2"
"bumpp": "^6.0.6",
"rimraf": "^3.0.2",
"tsup": "^4.6.1",
"typescript": "^4.1.5",
"vue": "^3"
}
}
17 changes: 17 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"compilerOptions": {
"outDir": "dist",
"target": "ES2019",
"module": "commonjs",
"moduleResolution": "node",
"strict": true,
"declaration": true,
"sourceMap": true,
"noUnusedLocals": true,
"esModuleInterop": true,
"baseUrl": "."
},
"include": [
"*.ts"
]
}
Loading