mirror of
https://github.com/supabase/supabase.git
synced 2026-10-05 09:25:06 +03:00
Adds some basic templating for API
This commit is contained in:
1 parent
fbb584236a
commit
dbd8678163
8 files changed
+190
-38
No files matched your search
@@ -5,7 +5,6 @@ title: Usage
|
||||
|
||||
<!-- AUTOGENERATED: DO NOT EDIT DIRECTLY IF THIS IS VERSION "next" -->
|
||||
|
||||
An isomorphic Javascript library for GoTrue.
|
||||
|
||||
|
||||
|
||||
@@ -14,50 +13,37 @@ An isomorphic Javascript library for GoTrue.
|
||||
|
||||
|
||||
|
||||
## New user signup
|
||||
|
||||
```js
|
||||
const { user, session, error } = await gotrue.signUp({
|
||||
email: 'example@email.com',
|
||||
password: 'example-password',
|
||||
})
|
||||
### Lists all organizations
|
||||
|
||||
```
|
||||
/v1/organizations
|
||||
```
|
||||
|
||||
|
||||
### Attributes
|
||||
|
||||
### Creates an organization
|
||||
|
||||
- param-signup-options
|
||||
|
||||
- param-options
|
||||
|
||||
|
||||
|
||||
### Notes
|
||||
|
||||
- By default, the user will need to verify their email address before logging in. If you would like to change this, you can disable "Email Confirmations" by going to Authentication -> Settings on [app.supabase.com](https://app.supabase.com)
|
||||
- If "Email Confirmations" is turned on, a `user` is returned but `session` will be null
|
||||
- If "Email Confirmations" is turned off, both a `user` and a `session` will be returned
|
||||
- When the user confirms their email address, they will be redirected to localhost:3000 by default. To change this, you can go to Authentication -> Settings on [app.supabase.com](https://app.supabase.com)
|
||||
- If signUp() is called for an existing confirmed user:
|
||||
- If "Enable email confirmations" is enabled on the "Authentication" -> "Settings" page, an obfuscated / fake user object will be returned.
|
||||
- If "Enable email confirmations" is disabled, an error with a message "User already registered" will be returned.
|
||||
- To check if a user already exists, refer to getUser().
|
||||
|
||||
|
||||
### Examples
|
||||
|
||||
|
||||
|
||||
#### Sign up with email
|
||||
|
||||
```js
|
||||
const { user, session, error } = await supabase.auth.signUp({
|
||||
email: 'example@email.com',
|
||||
password: 'example-password',
|
||||
})
|
||||
```
|
||||
/v1/organizations
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
### Gets all projects that belong to the authenticated user
|
||||
|
||||
```
|
||||
/v1/projects
|
||||
```
|
||||
|
||||
|
||||
|
||||
### Creates a project
|
||||
|
||||
```
|
||||
/v1/projects
|
||||
```
|
||||
|
||||
|
||||
Generated
+17
@@ -17952,6 +17952,11 @@
|
||||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/openapi-types": {
|
||||
"version": "12.0.0",
|
||||
"resolved": "https://registry.npmjs.org/openapi-types/-/openapi-types-12.0.0.tgz",
|
||||
"integrity": "sha512-6Wd9k8nmGQHgCbehZCP6wwWcfXcvinhybUTBatuhjRsCxUIujuYFZc9QnGeae75CyHASewBtxs0HX/qwREReUw=="
|
||||
},
|
||||
"node_modules/opener": {
|
||||
"version": "1.5.2",
|
||||
"resolved": "https://registry.npmjs.org/opener/-/opener-1.5.2.tgz",
|
||||
@@ -25937,8 +25942,13 @@
|
||||
"integrity": "sha512-ErcLnoyB60lVB3jpeTOI2m2Cif3I6mTyjPiNs1/L/5cH+7FzbqzprLxwWgQtWQCIJCbzaZ2lh8AFEIo4He47XQ=="
|
||||
},
|
||||
"packages/spec": {
|
||||
"name": "@supabase/generator",
|
||||
"version": "0.0.0",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"lodash": "^4.17.21",
|
||||
"openapi-types": "^12.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"ejs": "^3.1.8",
|
||||
"js-yaml": "^4.1.0",
|
||||
@@ -29354,6 +29364,8 @@
|
||||
"requires": {
|
||||
"ejs": "^3.1.8",
|
||||
"js-yaml": "^4.1.0",
|
||||
"lodash": "*",
|
||||
"openapi-types": "^12.0.0",
|
||||
"ts-node": "^10.9.1"
|
||||
},
|
||||
"dependencies": {
|
||||
@@ -38896,6 +38908,11 @@
|
||||
"is-wsl": "^2.2.0"
|
||||
}
|
||||
},
|
||||
"openapi-types": {
|
||||
"version": "12.0.0",
|
||||
"resolved": "https://registry.npmjs.org/openapi-types/-/openapi-types-12.0.0.tgz",
|
||||
"integrity": "sha512-6Wd9k8nmGQHgCbehZCP6wwWcfXcvinhybUTBatuhjRsCxUIujuYFZc9QnGeae75CyHASewBtxs0HX/qwREReUw=="
|
||||
},
|
||||
"opener": {
|
||||
"version": "1.5.2",
|
||||
"resolved": "https://registry.npmjs.org/opener/-/opener-1.5.2.tgz",
|
||||
|
||||
Generated
+39
@@ -9,8 +9,11 @@
|
||||
"version": "0.0.0",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@types/lodash": "^4.14.182",
|
||||
"ejs": "^3.1.8",
|
||||
"js-yaml": "^4.1.0",
|
||||
"lodash": "^4.17.21",
|
||||
"openapi-types": "^12.0.0",
|
||||
"ts-node": "^10.9.1"
|
||||
}
|
||||
},
|
||||
@@ -75,6 +78,12 @@
|
||||
"integrity": "sha512-yOlFc+7UtL/89t2ZhjPvvB/DeAr3r+Dq58IgzsFkOAvVC6NMJXmCGjbptdXdR9qsX7pKcTL+s87FtYREi2dEEQ==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@types/lodash": {
|
||||
"version": "4.14.182",
|
||||
"resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.182.tgz",
|
||||
"integrity": "sha512-/THyiqyQAP9AfARo4pF+aCGcyiQ94tX/Is2I7HofNRqoYLgN1PBoOWu2/zTA5zMxzP5EFutMtWtGAFRKUe961Q==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@types/node": {
|
||||
"version": "18.6.3",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.6.3.tgz",
|
||||
@@ -291,6 +300,12 @@
|
||||
"js-yaml": "bin/js-yaml.js"
|
||||
}
|
||||
},
|
||||
"node_modules/lodash": {
|
||||
"version": "4.17.21",
|
||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
|
||||
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/make-error": {
|
||||
"version": "1.3.6",
|
||||
"resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz",
|
||||
@@ -309,6 +324,12 @@
|
||||
"node": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/openapi-types": {
|
||||
"version": "12.0.0",
|
||||
"resolved": "https://registry.npmjs.org/openapi-types/-/openapi-types-12.0.0.tgz",
|
||||
"integrity": "sha512-6Wd9k8nmGQHgCbehZCP6wwWcfXcvinhybUTBatuhjRsCxUIujuYFZc9QnGeae75CyHASewBtxs0HX/qwREReUw==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/supports-color": {
|
||||
"version": "7.2.0",
|
||||
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz",
|
||||
@@ -450,6 +471,12 @@
|
||||
"integrity": "sha512-yOlFc+7UtL/89t2ZhjPvvB/DeAr3r+Dq58IgzsFkOAvVC6NMJXmCGjbptdXdR9qsX7pKcTL+s87FtYREi2dEEQ==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/lodash": {
|
||||
"version": "4.14.182",
|
||||
"resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.182.tgz",
|
||||
"integrity": "sha512-/THyiqyQAP9AfARo4pF+aCGcyiQ94tX/Is2I7HofNRqoYLgN1PBoOWu2/zTA5zMxzP5EFutMtWtGAFRKUe961Q==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/node": {
|
||||
"version": "18.6.3",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.6.3.tgz",
|
||||
@@ -620,6 +647,12 @@
|
||||
"argparse": "^2.0.1"
|
||||
}
|
||||
},
|
||||
"lodash": {
|
||||
"version": "4.17.21",
|
||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
|
||||
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==",
|
||||
"dev": true
|
||||
},
|
||||
"make-error": {
|
||||
"version": "1.3.6",
|
||||
"resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz",
|
||||
@@ -635,6 +668,12 @@
|
||||
"brace-expansion": "^1.1.7"
|
||||
}
|
||||
},
|
||||
"openapi-types": {
|
||||
"version": "12.0.0",
|
||||
"resolved": "https://registry.npmjs.org/openapi-types/-/openapi-types-12.0.0.tgz",
|
||||
"integrity": "sha512-6Wd9k8nmGQHgCbehZCP6wwWcfXcvinhybUTBatuhjRsCxUIujuYFZc9QnGeae75CyHASewBtxs0HX/qwREReUw==",
|
||||
"dev": true
|
||||
},
|
||||
"supports-color": {
|
||||
"version": "7.2.0",
|
||||
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz",
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
"types": "./index.tsx",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"api:gen": "npm run api:gen:paths",
|
||||
"api:gen:paths": "ts-node ./index.ts gen --type api --input ../../spec/api_v0_openapi.json --output ../../apps/reference/_api/usage.mdx",
|
||||
"cli:gen": "npm run cli:gen:commands && npm run cli:gen:config",
|
||||
"cli:gen:commands": "ts-node ./index.ts gen --type command --input ../../spec/cli_v1_commands.yaml --output ../../apps/reference/_cli/usage.mdx ",
|
||||
"cli:gen:config": "ts-node ./index.ts gen --type config --input ../../spec/cli_v1_config.yaml --output ../../apps/reference/_cli/config.mdx",
|
||||
@@ -15,10 +17,12 @@
|
||||
"supabase-dart:gen": "npm run supabase-dart:gen:sdk",
|
||||
"supabase-dart:gen:sdk": "ts-node ./index.ts gen --type sdk --input ../../spec/supabase_dart_sdk.yaml --output ../../apps/reference/_supabase_dart/usage.mdx "
|
||||
},
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"@types/lodash": "^4.14.182",
|
||||
"ejs": "^3.1.8",
|
||||
"js-yaml": "^4.1.0",
|
||||
"lodash": "^4.17.21",
|
||||
"openapi-types": "^12.0.0",
|
||||
"ts-node": "^10.9.1"
|
||||
},
|
||||
"prettier": {
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
import template from './templates/ApiTemplate'
|
||||
import { toArrayWithKey } from './helpers'
|
||||
import { OpenAPIV3 } from 'openapi-types'
|
||||
const fs = require('fs')
|
||||
const ejs = require('ejs')
|
||||
const Helpers = require('./Helpers')
|
||||
const { writeToDisk } = Helpers
|
||||
|
||||
export default async function gen(inputFileName: string, outputDir: string) {
|
||||
const specRaw = fs.readFileSync(inputFileName, 'utf8')
|
||||
const spec = JSON.parse(specRaw)
|
||||
// console.log('spec', spec.openapi)
|
||||
|
||||
switch (spec.openapi) {
|
||||
case '3.0.0':
|
||||
await gen_v3(spec, outputDir)
|
||||
break
|
||||
|
||||
default:
|
||||
console.log('Unrecognized specification version:', spec.clispec)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Versioned Generator
|
||||
*/
|
||||
async function gen_v3(spec: OpenAPIV3.Document, dest: string) {
|
||||
const paths = Object.entries(spec.paths)
|
||||
.map(([key, path], i) => {
|
||||
return {
|
||||
path: key,
|
||||
operations: toArrayWithKey(path!, 'operation'),
|
||||
}
|
||||
})
|
||||
.filter((x) => x.path.indexOf('/v1') === 0)
|
||||
|
||||
const content = ejs.render(template, {
|
||||
info: spec.info,
|
||||
paths,
|
||||
})
|
||||
// console.log(content)
|
||||
// Write to disk
|
||||
await writeToDisk(dest, content)
|
||||
console.log('Saved: ', dest)
|
||||
}
|
||||
|
||||
// const pathsToArrays = (pathObject: {
|
||||
// path: string
|
||||
// get?: object
|
||||
// post?: object
|
||||
// patch?: object
|
||||
// delete?: object
|
||||
// }) => {
|
||||
// return {
|
||||
// path: pathObject.path,
|
||||
|
||||
// }
|
||||
// }
|
||||
@@ -1,4 +1,5 @@
|
||||
import fs from 'fs'
|
||||
import _ from 'lodash'
|
||||
|
||||
export const slugify = (text: string) => {
|
||||
return text
|
||||
@@ -22,3 +23,14 @@ export const writeToDisk = (fileName: string, content: any) => {
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert Object to Array of values
|
||||
*/
|
||||
export const toArrayWithKey = (obj: object, keyAs: string) =>
|
||||
_.values(
|
||||
_.mapValues(obj, (value: any, key: string) => {
|
||||
value[keyAs] = key
|
||||
return value
|
||||
})
|
||||
)
|
||||
@@ -1,3 +1,4 @@
|
||||
import ApiGenerator from './api'
|
||||
import CliGenerator from './cli'
|
||||
import ConfigGenerator from './config'
|
||||
import SdkGenerator from './sdk'
|
||||
@@ -12,6 +13,10 @@ export default async function DocGenerator({
|
||||
type: 'cli' | 'config' | 'sdk' | 'api'
|
||||
}) {
|
||||
switch (type) {
|
||||
case 'api':
|
||||
await ApiGenerator(input, output)
|
||||
break
|
||||
|
||||
case 'cli':
|
||||
await CliGenerator(input, output)
|
||||
break
|
||||
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
const template = `
|
||||
---
|
||||
id: usage
|
||||
title: Usage
|
||||
---
|
||||
|
||||
<!-- AUTOGENERATED: DO NOT EDIT DIRECTLY IF THIS IS VERSION "next" -->
|
||||
|
||||
<%- info.description %>
|
||||
|
||||
|
||||
<!-- AUTOGENERATED: DO NOT EDIT DIRECTLY IF THIS IS VERSION "next" -->
|
||||
|
||||
|
||||
<% paths.forEach(function(path){ %>
|
||||
<% path.operations.forEach(function(operation){ %>
|
||||
|
||||
### <%- operation.summary %>
|
||||
|
||||
\`\`\`
|
||||
<%- path.path %>
|
||||
\`\`\`
|
||||
|
||||
<% }); %>
|
||||
<% }); %>
|
||||
|
||||
|
||||
`.trim()
|
||||
|
||||
export default template
|
||||
Reference in new issue
Block a user