Merge branch 'master' of github.com:supabase/monorepo

This commit is contained in:
Copple
2020-01-09 14:07:41 +08:00
15 changed files with 8784 additions and 129 deletions

View File

@@ -12,7 +12,7 @@
"test:examples": "node examples/",
"cover": "nyc --check-coverage npm run test:only",
"build": "cross-env BABEL_ENV=production babel src --out-dir lib",
"prepublish": "npm run clean && npm run test && npm run build"
"prepublish": "npm run clean && npm run build"
},
"files": [
"lib",
@@ -40,9 +40,9 @@
"babel-plugin-add-module-exports": "^1.0.0",
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.6.1",
"babel-preset-minify": "^0.5.0",
"babel-preset-minify": "^0.3.0",
"chai": "^4.1.2",
"cross-env": "^5.1.3",
"cross-env": "^5.2.1",
"mocha": "^6.1.3",
"nyc": "^13.3.0",
"rimraf": "^2.6.2"

View File

@@ -1,10 +1,10 @@
import { Socket } from 'phoenix-channels'
export default class BaseChannel {
constructor(tableName, apiSocket){
constructor(tableName, apiSocket, uuid){
this.socket = new Socket(apiSocket)
this.uuid = uuid
this.channel = this.socket.channel(tableName)
this.listeners = {}
this.start()
@@ -17,23 +17,7 @@ export default class BaseChannel {
}
on(eventName, callbackFunction){
let ref = this.channel.on(eventName, callbackFunction)
this.listeners[ref] = eventName
return ref
}
off(eventName, ref = null){
// if ref is null, we just want to remove everything that has the eventName
if(typeof ref === 'null'){
for (var ref in this.listeners){
let eventNameValue = this.listeners[ref]
if(eventName === eventNameValue){
this.off(eventName, ref)
}
}
}
this.channel.off(eventName, ref)
this.channel.on(eventName, callbackFunction)
}
start(){

View File

@@ -34,7 +34,7 @@ class BaseRequest extends Request {
*
* @param {string|object} The user, bearer token, or user/pass object.
* @param {string|void} The pass or undefined.
* @returns {ApiRequest} The API request object.
* @returns {BaseRequest} The API request object.
*/
auth (user, pass) {
@@ -56,7 +56,7 @@ class BaseRequest extends Request {
* All values are prefixed with `eq.`.
*
* @param {object} The object to match against.
* @returns {ApiRequest} The API request object.
* @returns {BaseRequest} The API request object.
*/
match (query) {
@@ -70,7 +70,7 @@ class BaseRequest extends Request {
* set as a query string value. Also always forces a root @id column.
*
* @param {string} The unformatted select string.
* @returns {ApiRequest} The API request object.
* @returns {BaseRequest} The API request object.
*/
select (select) {
@@ -87,7 +87,7 @@ class BaseRequest extends Request {
* @param {string} The property name to order by.
* @param {bool} True for descending results, false by default.
* @param {bool} True for nulls first, false by default.
* @returns {ApiRequest} The API request object.
* @returns {BaseRequest} The API request object.
*/
order (property, ascending = false, nullsFirst = false) {
@@ -101,7 +101,7 @@ class BaseRequest extends Request {
*
* @param {number} The first object to select.
* @param {number|void} The last object to select.
* @returns {ApiRequest} The API request object.
* @returns {BaseRequest} The API request object.
*/
range (from, to) {
@@ -114,7 +114,7 @@ class BaseRequest extends Request {
* Sets the header which signifies to PostgREST the response must be a single
* object or 404.
*
* @returns {ApiRequest} The API request object.
* @returns {BaseRequest} The API request object.
*/
single () {
@@ -135,20 +135,22 @@ class BaseRequest extends Request {
return reject(error)
}
const { body, headers } = response
const { body, headers, status, statusCode, statusText } = response
const contentRange = headers['content-range']
if (Array.isArray(body) && contentRange && contentRangeStructure.test(contentRange)) {
body.fullLength = parseInt(contentRangeStructure.exec(contentRange)[3], 10)
}
return resolve(body)
const returnBody = { body, status, statusCode, statusText}
return resolve(returnBody)
})
)
}
/**
* Makes the ApiRequest object then-able. Allows for usage with
* Makes the BaseRequest object then-able. Allows for usage with
* `Promise.resolve` and async/await contexts. Just a proxy for `.then()` on
* the promise returned from `.end()`.
*
@@ -178,13 +180,13 @@ class BaseRequest extends Request {
*
* @param {string} The name of the column.
* @param {any} The value of the column to be filtered.
* @returns {ApiRequest} The API request object.
* @returns {BaseRequest} The API request object.
*/
const filters = ['eq', 'gt', 'lt', 'gte', 'lte', 'like', 'ilike', 'is', 'in', 'not']
filters.forEach(filter =>
ApiRequest.prototype[filter] = function filterValue (name, value) {
BaseRequest.prototype[filter] = function filterValue (name, value) {
return this.query(`${name}=${filter}.${Array.isArray(value) ? value.join(',') : value}`)
}
)

View File

@@ -1,20 +1,32 @@
import BaseRequest from './BaseRequest'
import BaseChannel from './BaseChannel'
import { uuid } from './utils/Helpers'
class SupabaseClient {
constructor(supbaseUrl, supabaseKey, options) {
constructor(supabaseUrl, supabaseKey, options) {
this.supabaseUrl = supabaseUrl
this.supabaseKey = supabaseKey
// this will be the case for now
this.restUrl = supabaseUrl
this.apiSocket = ''
this.subscriptions = {}
}
/**
* @todo
*/
subscribe (tableName) {
return new BaseChannel(tableName, this.apiSocket)
subscribe(tableName) {
let uuid = uuid()
this.subscriptions[uuid] = new BaseChannel(tableName, this.apiSocket, uuid)
return this.subscriptions[uuid]
}
unsubscribe(subscription){
subscription.stop()
delete this.subscriptions[subscription.uuid]
}
/**
@@ -26,9 +38,10 @@ class SupabaseClient {
* @returns {BaseRequest} The API request object.
*/
request (method, path) {
request(method, path) {
return new BaseRequest(method, this.restUrl + path)
}
}
/**
@@ -38,23 +51,23 @@ class SupabaseClient {
* @returns {BaseRequest} The API request object.
*/
const methods = ['POST', 'GET', 'PATCH', 'PUT', 'DELETE']
const methods = ['POST', 'GET', 'PATCH', 'DELETE']
methods.forEach(method =>
SupabaseClient.prototype[method.toLowerCase()] = tableName => {
path = `/${tableName}`
methods.forEach(method => {
SupabaseClient.prototype[method.toLowerCase()] = function requestMethod(tableName) {
let path = `/${tableName}`
return this.request(method, path)
}
)
})
const createClient = (supabaseUrl, supabaseKey, options = {}) => {
return new SupabaseClient(supabseUrl, supabaseKey, options)
return new SupabaseClient(supabaseUrl, supabaseKey, options)
}
export { createClient }
/**
* TO BE REMOVED SOON
* TO BE REMOVED SOON
*/
// const defaultAwesomeFunction = (name) => {

View File

@@ -0,0 +1,8 @@
export function uuid() {
function s4() {
return Math.floor((1 + Math.random()) * 0x10000)
.toString(16)
.substring(1)
}
return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4()
}

View File

@@ -35,4 +35,18 @@ services:
KONG_PROXY_ACCESS_LOG: /dev/stdout
KONG_PROXY_ERROR_LOG: /dev/stderr
KONG_ADMIN_LISTEN: 0.0.0.0:8001
# frontend:
# build: ./frontend
# ports:
# - "3333:3000"
# realtime:
# image: supabase/realtime
# ports:
# - "4001:4000"
# environment:
# POSTGRES_USER: supabase
# POSTGRES_PASSWORD: postgres
# POSTGRES_PORT: 5432

25
test/frontend/.gitignore vendored Normal file
View File

@@ -0,0 +1,25 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.js
# testing
/coverage
# next.js
/.next/
/out/
# production
/build
# misc
.DS_Store
.env*
# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

12
test/frontend/Dockerfile Normal file
View File

@@ -0,0 +1,12 @@
FROM node:10
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
CMD [ "npm", "start" ]

55
test/frontend/README.md Normal file
View File

@@ -0,0 +1,55 @@
# With Dotenv example
## Deploy your own
Deploy the example using [ZEIT Now](https://zeit.co/now):
[![Deploy with ZEIT Now](https://zeit.co/button)](https://zeit.co/new/project?template=https://github.com/zeit/next.js/tree/canary/examples/with-dotenv)
## How to use
### Using `create-next-app`
Execute [`create-next-app`](https://github.com/zeit/next.js/tree/canary/packages/create-next-app) with [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) or [npx](https://github.com/zkat/npx#readme) to bootstrap the example:
```bash
npx create-next-app --example with-dotenv with-dotenv-app
# or
yarn create next-app --example with-dotenv with-dotenv-app
```
### Download manually
Download the example:
```bash
curl https://codeload.github.com/zeit/next.js/tar.gz/canary | tar -xz --strip=2 next.js-canary/examples/with-dotenv
cd with-dotenv
```
Install it and run:
```bash
npm install
npm run dev
# or
yarn
yarn dev
```
Deploy it to the cloud with [now](https://zeit.co/now) ([download](https://zeit.co/download)):
```bash
now
```
## The idea behind the example
This example shows how to inline env vars.
**Please note**:
- It is a bad practice to commit env vars to a repository. Thats why you should normally [gitignore](https://git-scm.com/docs/gitignore) your `.env` file.
- In this example, as soon as you reference an env var in your code, it will automatically be made publicly available and exposed to the client.
- If you want to have more centralized control of what is exposed to the client check out the example [with-universal-configuration-build-time](../with-universal-configuration-build-time).
- Env vars are set (inlined) at build time. If you need to configure your app at runtime, check out [examples/with-universal-configuration-runtime](../with-universal-configuration-runtime).

View File

@@ -0,0 +1,7 @@
require('dotenv').config()
module.exports = {
// env: {
// // Reference a variable that was defined in the .env file and make it available at Build Time
// SOCKET_URL: process.env.SOCKET_URL,
// },
}

8502
test/frontend/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,18 @@
{
"name": "with-dotenv",
"version": "1.0.0",
"scripts": {
"dev": "next -p 8080",
"build": "next build",
"start": "next start"
},
"dependencies": {
"@supabase/supabase-js": "file:../../../../../desktop/supabase/monorepo/libraries/supabase-js",
"dns": "^0.2.2",
"dotenv": "^8.2.0",
"next": "latest",
"react": "^16.7.0",
"react-dom": "^16.7.0"
},
"license": "ISC"
}

View File

@@ -0,0 +1,38 @@
import { createClient } from '@supabase/supabase-js'
export default class Index extends React.Component {
constructor() {
super()
this.supabase = createClient("http://localhost:8000/rest/v0", "")
}
componentDidMount() {
this.loadData()
}
async loadData() {
let countries = await this.supabase.get('countries')
console.log('Here are the list of countries: ', countries)
}
render() {
return (
<div style={styles.main}>
<h1>Test Suite</h1>
<br/>
</div>
)
}
}
const styles = {
main: { fontFamily: 'monospace', padding: 30 },
pre: {
whiteSpace: 'pre',
overflow: 'auto',
background: '#333',
maxHeight: 200,
borderRadius: 6,
padding: 5,
},
code: { display: 'block', wordWrap: 'normal', color: '#fff' },
}

View File

@@ -20,147 +20,124 @@ SET default_tablespace = '';
SET default_with_oids = false;
--
-- Name: companies; Type: TABLE; Schema: public; Owner: supabase
-- Name: cities; Type: TABLE; Schema: public; Owner: supabase
--
CREATE TABLE public.companies (
company_id integer NOT NULL,
company_name character varying(255) NOT NULL,
employee_count smallint
CREATE TABLE public.cities (
id bigint NOT NULL,
name character varying(255) NOT NULL,
country_id integer NOT NULL
);
ALTER TABLE public.companies OWNER TO supabase;
ALTER TABLE public.cities OWNER TO supabase;
--
-- Name: companies_company_id_seq; Type: SEQUENCE; Schema: public; Owner: supabase
-- Name: cities_id_seq; Type: SEQUENCE; Schema: public; Owner: supabase
--
CREATE SEQUENCE public.companies_company_id_seq
AS integer
ALTER TABLE public.cities ALTER COLUMN id ADD GENERATED BY DEFAULT AS IDENTITY (
SEQUENCE NAME public.cities_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER TABLE public.companies_company_id_seq OWNER TO supabase;
--
-- Name: companies_company_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: supabase
--
ALTER SEQUENCE public.companies_company_id_seq OWNED BY public.companies.company_id;
--
-- Name: users; Type: TABLE; Schema: public; Owner: supabase
--
CREATE TABLE public.users (
user_id integer NOT NULL,
user_name character varying(255) NOT NULL,
company_id integer NOT NULL
CACHE 1
);
ALTER TABLE public.users OWNER TO supabase;
--
-- Name: users_user_id_seq; Type: SEQUENCE; Schema: public; Owner: supabase
-- Name: countries; Type: TABLE; Schema: public; Owner: supabase
--
CREATE SEQUENCE public.users_user_id_seq
AS integer
CREATE TABLE public.countries (
id bigint NOT NULL,
name character varying(255) NOT NULL,
iso2 character varying(5) NOT NULL,
continent character varying(255) NOT NULL
);
ALTER TABLE public.countries OWNER TO supabase;
--
-- Name: countries_id_seq; Type: SEQUENCE; Schema: public; Owner: supabase
--
ALTER TABLE public.countries ALTER COLUMN id ADD GENERATED BY DEFAULT AS IDENTITY (
SEQUENCE NAME public.countries_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER TABLE public.users_user_id_seq OWNER TO supabase;
--
-- Name: users_user_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: supabase
--
ALTER SEQUENCE public.users_user_id_seq OWNED BY public.users.user_id;
CACHE 1
);
--
-- Name: companies company_id; Type: DEFAULT; Schema: public; Owner: supabase
-- Data for Name: cities; Type: TABLE DATA; Schema: public; Owner: supabase
--
ALTER TABLE ONLY public.companies ALTER COLUMN company_id SET DEFAULT nextval('public.companies_company_id_seq'::regclass);
--
-- Name: users user_id; Type: DEFAULT; Schema: public; Owner: supabase
--
ALTER TABLE ONLY public.users ALTER COLUMN user_id SET DEFAULT nextval('public.users_user_id_seq'::regclass);
--
-- Data for Name: companies; Type: TABLE DATA; Schema: public; Owner: supabase
--
COPY public.companies (company_id, company_name, employee_count) FROM stdin;
1 Pied Piper 10
2 Hooli 1000
3 Yao Net 100
4 See Food App \N
COPY public.cities (id, name, country_id) FROM stdin;
1 Rio de Janeiro 1
2 Beijing 2
3 Paris 3
4 Auckland 4
5 Lagos 5
6 San Francisco 6
\.
--
-- Data for Name: users; Type: TABLE DATA; Schema: public; Owner: supabase
-- Data for Name: countries; Type: TABLE DATA; Schema: public; Owner: supabase
--
COPY public.users (user_id, user_name, company_id) FROM stdin;
1 Richard Hendrix 1
2 Gavin Belson 2
COPY public.countries (id, name, iso2, continent) FROM stdin;
1 Brazil BR South America
2 China CN Asia
3 France FR Europe
4 New Zealand NZ Oceania
5 Nigeria NG Africa
6 United States US North America
\.
--
-- Name: companies_company_id_seq; Type: SEQUENCE SET; Schema: public; Owner: supabase
-- Name: cities_id_seq; Type: SEQUENCE SET; Schema: public; Owner: supabase
--
SELECT pg_catalog.setval('public.companies_company_id_seq', 4, true);
SELECT pg_catalog.setval('public.cities_id_seq', 6, true);
--
-- Name: users_user_id_seq; Type: SEQUENCE SET; Schema: public; Owner: supabase
-- Name: countries_id_seq; Type: SEQUENCE SET; Schema: public; Owner: supabase
--
SELECT pg_catalog.setval('public.users_user_id_seq', 2, true);
SELECT pg_catalog.setval('public.countries_id_seq', 6, true);
--
-- Name: companies companies_pkey; Type: CONSTRAINT; Schema: public; Owner: supabase
-- Name: cities cities_pkey; Type: CONSTRAINT; Schema: public; Owner: supabase
--
ALTER TABLE ONLY public.companies
ADD CONSTRAINT companies_pkey PRIMARY KEY (company_id);
ALTER TABLE ONLY public.cities
ADD CONSTRAINT cities_pkey PRIMARY KEY (id);
--
-- Name: users users_pkey; Type: CONSTRAINT; Schema: public; Owner: supabase
-- Name: countries countries_pkey; Type: CONSTRAINT; Schema: public; Owner: supabase
--
ALTER TABLE ONLY public.users
ADD CONSTRAINT users_pkey PRIMARY KEY (user_id);
ALTER TABLE ONLY public.countries
ADD CONSTRAINT countries_pkey PRIMARY KEY (id);
--
-- Name: users users_company_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: supabase
-- Name: cities cities_countries_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: supabase
--
ALTER TABLE ONLY public.users
ADD CONSTRAINT users_company_id_fkey FOREIGN KEY (company_id) REFERENCES public.companies(company_id) ON DELETE CASCADE;
ALTER TABLE ONLY public.cities
ADD CONSTRAINT cities_countries_id_fkey FOREIGN KEY (country_id) REFERENCES public.countries(id) ON DELETE CASCADE;
--

View File

@@ -715,7 +715,7 @@ Value to match.
```js {3}
supabase
.get(tableName)
.is(columnName, filterArray)
.in(columnName, filterArray)
```
</div>
@@ -725,7 +725,7 @@ supabase
```js {3}
supabase
.patch(tableName)
.is(columnName, filterArray)
.in(columnName, filterArray)
```
</div>
@@ -735,7 +735,7 @@ supabase
```js {3}
supabase
.delete(tableName)
.is(columnName, filterArray)
.in(columnName, filterArray)
```
</div>