The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Adds some basic templating for API
Coppledbd86781633f
diff --git a/apps/reference/_api/usage.mdx b/apps/reference/_api/usage.mdxindex 5f5bd57fa83..dffc811a487 100644--- a/apps/reference/_api/usage.mdx+++ b/apps/reference/_api/usage.mdx@@ -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: '[email protected]',- password: 'example-password',-})-```+### Lists all organizations+```+/v1/organizations+```-### Attributes-- param-signup-options+### Creates an organization-- param-options+```+/v1/organizations+```-### 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().+### Gets all projects that belong to the authenticated user-### Examples+```+/v1/projects+```-#### Sign up with email+### Creates a project-```js-const { user, session, error } = await supabase.auth.signUp({- email: '[email protected]',- password: 'example-password',-})```--+/v1/projects+```diff --git a/package-lock.json b/package-lock.jsonindex 3235f55380a..467a8685112 100644--- a/package-lock.json+++ b/package-lock.json@@ -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",diff --git a/packages/spec/package-lock.json b/packages/spec/package-lock.jsonindex 91576449398..5ed476c0b73 100644--- a/packages/spec/package-lock.json+++ b/packages/spec/package-lock.json@@ -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",diff --git a/packages/spec/package.json b/packages/spec/package.jsonindex 80b8ccadb35..b8edf824beb 100644--- a/packages/spec/package.json+++ b/packages/spec/package.json@@ -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": {diff --git a/packages/spec/src/docs/api.ts b/packages/spec/src/docs/api.tsnew file mode 100644index 00000000000..b317e3f3cd2--- /dev/null+++ b/packages/spec/src/docs/api.ts@@ -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,++// }+// }diff --git a/packages/spec/src/docs/helpers.ts b/packages/spec/src/docs/helpers.tsindex f7f812d4b11..cf58f6e69ad 100644--- a/packages/spec/src/docs/helpers.ts+++ b/packages/spec/src/docs/helpers.ts@@ -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+ })+ )diff --git a/packages/spec/src/docs/index.ts b/packages/spec/src/docs/index.tsindex ae2fce8b39c..52db59d6507 100644--- a/packages/spec/src/docs/index.ts+++ b/packages/spec/src/docs/index.ts@@ -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)breakdiff --git a/packages/spec/src/docs/templates/ApiTemplate.ts b/packages/spec/src/docs/templates/ApiTemplate.tsnew file mode 100644index 00000000000..9be269bd4ac--- /dev/null+++ b/packages/spec/src/docs/templates/ApiTemplate.ts@@ -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