supabase-javascript 2.98.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +177 -0
- package/package.json +45 -0
- package/scripts/postinstall.js +180 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Supabase, Inc. and contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
# Supabase CLI
|
|
2
|
+
|
|
3
|
+
[](https://coveralls.io/github/supabase/cli?branch=develop) [](https://bitbucket.org/supabase-cli/setup-cli/pipelines) [
|
|
4
|
+
](https://gitlab.com/sweatybridge/setup-cli/-/pipelines)
|
|
5
|
+
|
|
6
|
+
[Supabase](https://supabase.io) is an open source Firebase alternative. We're building the features of Firebase using enterprise-grade open source tools.
|
|
7
|
+
|
|
8
|
+
This repository contains all the functionality for Supabase CLI.
|
|
9
|
+
|
|
10
|
+
- [x] Running Supabase locally
|
|
11
|
+
- [x] Managing database migrations
|
|
12
|
+
- [x] Creating and deploying Supabase Functions
|
|
13
|
+
- [x] Generating types directly from your database schema
|
|
14
|
+
- [x] Making authenticated HTTP requests to [Management API](https://supabase.com/docs/reference/api/introduction)
|
|
15
|
+
|
|
16
|
+
## Getting started
|
|
17
|
+
|
|
18
|
+
### Install the CLI
|
|
19
|
+
|
|
20
|
+
Available via [NPM](https://www.npmjs.com) as dev dependency. To install:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm i supabase --save-dev
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
When installing with yarn 4, you need to disable experimental fetch with the following nodejs config.
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
NODE_OPTIONS=--no-experimental-fetch yarn add supabase
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
> **Note**
|
|
33
|
+
For Bun versions below v1.0.17, you must add `supabase` as a [trusted dependency](https://bun.sh/guides/install/trusted) before running `bun add -D supabase`.
|
|
34
|
+
|
|
35
|
+
<details>
|
|
36
|
+
<summary><b>macOS</b></summary>
|
|
37
|
+
|
|
38
|
+
Available via [Homebrew](https://brew.sh). To install:
|
|
39
|
+
|
|
40
|
+
```sh
|
|
41
|
+
brew install supabase/tap/supabase
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
To install the beta release channel:
|
|
45
|
+
|
|
46
|
+
```sh
|
|
47
|
+
brew install supabase/tap/supabase-beta
|
|
48
|
+
brew link --overwrite supabase-beta
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
To upgrade:
|
|
52
|
+
|
|
53
|
+
```sh
|
|
54
|
+
brew upgrade supabase
|
|
55
|
+
```
|
|
56
|
+
</details>
|
|
57
|
+
|
|
58
|
+
<details>
|
|
59
|
+
<summary><b>Windows</b></summary>
|
|
60
|
+
|
|
61
|
+
Available via [Scoop](https://scoop.sh). To install:
|
|
62
|
+
|
|
63
|
+
```powershell
|
|
64
|
+
scoop bucket add supabase https://github.com/supabase/scoop-bucket.git
|
|
65
|
+
scoop install supabase
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
To upgrade:
|
|
69
|
+
|
|
70
|
+
```powershell
|
|
71
|
+
scoop update supabase
|
|
72
|
+
```
|
|
73
|
+
</details>
|
|
74
|
+
|
|
75
|
+
<details>
|
|
76
|
+
<summary><b>Linux</b></summary>
|
|
77
|
+
|
|
78
|
+
Available via [Homebrew](https://brew.sh) and Linux packages.
|
|
79
|
+
|
|
80
|
+
#### via Homebrew
|
|
81
|
+
|
|
82
|
+
To install:
|
|
83
|
+
|
|
84
|
+
```sh
|
|
85
|
+
brew install supabase/tap/supabase
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
To upgrade:
|
|
89
|
+
|
|
90
|
+
```sh
|
|
91
|
+
brew upgrade supabase
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
#### via Linux packages
|
|
95
|
+
|
|
96
|
+
Linux packages are provided in [Releases](https://github.com/supabase/cli/releases). To install, download the `.apk`/`.deb`/`.rpm`/`.pkg.tar.zst` file depending on your package manager and run the respective commands.
|
|
97
|
+
|
|
98
|
+
```sh
|
|
99
|
+
sudo apk add --allow-untrusted <...>.apk
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
```sh
|
|
103
|
+
sudo dpkg -i <...>.deb
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
```sh
|
|
107
|
+
sudo rpm -i <...>.rpm
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
```sh
|
|
111
|
+
sudo pacman -U <...>.pkg.tar.zst
|
|
112
|
+
```
|
|
113
|
+
</details>
|
|
114
|
+
|
|
115
|
+
<details>
|
|
116
|
+
<summary><b>Other Platforms</b></summary>
|
|
117
|
+
|
|
118
|
+
You can also install the CLI via [go modules](https://go.dev/ref/mod#go-install) without the help of package managers.
|
|
119
|
+
|
|
120
|
+
```sh
|
|
121
|
+
go install github.com/supabase/cli@latest
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Add a symlink to the binary in `$PATH` for easier access:
|
|
125
|
+
|
|
126
|
+
```sh
|
|
127
|
+
ln -s "$(go env GOPATH)/bin/cli" /usr/bin/supabase
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
This works on other non-standard Linux distros.
|
|
131
|
+
</details>
|
|
132
|
+
|
|
133
|
+
<details>
|
|
134
|
+
<summary><b>Community Maintained Packages</b></summary>
|
|
135
|
+
|
|
136
|
+
Available via [pkgx](https://pkgx.sh/). Package script [here](https://github.com/pkgxdev/pantry/blob/main/projects/supabase.com/cli/package.yml).
|
|
137
|
+
To install in your working directory:
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
pkgx install supabase
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Available via [Nixpkgs](https://nixos.org/). Package script [here](https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/tools/supabase-cli/default.nix).
|
|
144
|
+
</details>
|
|
145
|
+
|
|
146
|
+
### Run the CLI
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
supabase bootstrap
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
Or using npx:
|
|
153
|
+
|
|
154
|
+
```bash
|
|
155
|
+
npx supabase bootstrap
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
The bootstrap command will guide you through the process of setting up a Supabase project using one of the [starter](https://github.com/supabase-community/supabase-samples/blob/main/samples.json) templates.
|
|
159
|
+
|
|
160
|
+
## Docs
|
|
161
|
+
|
|
162
|
+
Command & config reference can be found [here](https://supabase.com/docs/reference/cli/about).
|
|
163
|
+
|
|
164
|
+
## Breaking changes
|
|
165
|
+
|
|
166
|
+
We follow semantic versioning for changes that directly impact CLI commands, flags, and configurations.
|
|
167
|
+
|
|
168
|
+
However, due to dependencies on other service images, we cannot guarantee that schema migrations, seed.sql, and generated types will always work for the same CLI major version. If you need such guarantees, we encourage you to pin a specific version of CLI in package.json.
|
|
169
|
+
|
|
170
|
+
## Developing
|
|
171
|
+
|
|
172
|
+
To run from source:
|
|
173
|
+
|
|
174
|
+
```sh
|
|
175
|
+
# Go >= 1.22
|
|
176
|
+
go run . help
|
|
177
|
+
```
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "supabase-javascript",
|
|
3
|
+
"version": "2.98.2",
|
|
4
|
+
"description": "Supabase CLI",
|
|
5
|
+
"repository": "supabase/cli",
|
|
6
|
+
"homepage": "https://supabase.com/docs/reference/cli",
|
|
7
|
+
"bugs": "https://github.com/supabase/cli/issues",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"author": "Supabase",
|
|
10
|
+
"type": "module",
|
|
11
|
+
"engines": {
|
|
12
|
+
"npm": ">=8"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"scripts"
|
|
16
|
+
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"postinstall": "node scripts/postinstall.js"
|
|
19
|
+
},
|
|
20
|
+
"bin": {
|
|
21
|
+
"supabase": "bin/supabase"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"bin-links": "^6.0.0",
|
|
25
|
+
"https-proxy-agent": "^9.0.0",
|
|
26
|
+
"node-fetch": "^3.3.2",
|
|
27
|
+
"tar": "7.5.13"
|
|
28
|
+
},
|
|
29
|
+
"release": {
|
|
30
|
+
"branches": [
|
|
31
|
+
{
|
|
32
|
+
"name": "+([0-9])?(.{+([0-9]),x}).x",
|
|
33
|
+
"channel": "hotfix"
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"name": "develop",
|
|
37
|
+
"channel": "latest"
|
|
38
|
+
}
|
|
39
|
+
],
|
|
40
|
+
"plugins": [
|
|
41
|
+
"@semantic-release/commit-analyzer",
|
|
42
|
+
"@semantic-release/git"
|
|
43
|
+
]
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// Ref 1: https://github.com/sanathkr/go-npm
|
|
4
|
+
// Ref 2: https://medium.com/xendit-engineering/how-we-repurposed-npm-to-publish-and-distribute-our-go-binaries-for-internal-cli-23981b80911b
|
|
5
|
+
"use strict";
|
|
6
|
+
|
|
7
|
+
import binLinks from "bin-links";
|
|
8
|
+
import { createHash } from "crypto";
|
|
9
|
+
import fs from "fs";
|
|
10
|
+
import fetch from "node-fetch";
|
|
11
|
+
import { Agent } from "https";
|
|
12
|
+
import { HttpsProxyAgent } from "https-proxy-agent";
|
|
13
|
+
import path from "path";
|
|
14
|
+
import { extract } from "tar";
|
|
15
|
+
import zlib from "zlib";
|
|
16
|
+
|
|
17
|
+
// Mapping from Node's `process.arch` to Golang's `$GOARCH`
|
|
18
|
+
const ARCH_MAPPING = {
|
|
19
|
+
x64: "amd64",
|
|
20
|
+
arm64: "arm64",
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
// Mapping between Node's `process.platform` to Golang's
|
|
24
|
+
const PLATFORM_MAPPING = {
|
|
25
|
+
darwin: "darwin",
|
|
26
|
+
linux: "linux",
|
|
27
|
+
win32: "windows",
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const arch = ARCH_MAPPING[process.arch];
|
|
31
|
+
const platform = PLATFORM_MAPPING[process.platform];
|
|
32
|
+
|
|
33
|
+
// TODO: import pkg from "../package.json" assert { type: "json" };
|
|
34
|
+
const readPackageJson = async () => {
|
|
35
|
+
const contents = await fs.promises.readFile("package.json");
|
|
36
|
+
return JSON.parse(contents);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// Build the download url from package.json
|
|
40
|
+
const getDownloadUrl = (packageJson) => {
|
|
41
|
+
const pkgName = packageJson.name;
|
|
42
|
+
const version = packageJson.version;
|
|
43
|
+
const repo = packageJson.repository;
|
|
44
|
+
const url = `https://github.com/${repo}/releases/download/v${version}/${pkgName}_${platform}_${arch}.tar.gz`;
|
|
45
|
+
return url;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const fetchAndParseCheckSumFile = async (packageJson, agent) => {
|
|
49
|
+
const version = packageJson.version;
|
|
50
|
+
const pkgName = packageJson.name;
|
|
51
|
+
const repo = packageJson.repository;
|
|
52
|
+
const checksumFileUrl = `https://github.com/${repo}/releases/download/v${version}/${pkgName}_${version}_checksums.txt`;
|
|
53
|
+
|
|
54
|
+
// Fetch the checksum file
|
|
55
|
+
console.info("Downloading", checksumFileUrl);
|
|
56
|
+
const response = await fetch(checksumFileUrl, { agent });
|
|
57
|
+
if (response.ok) {
|
|
58
|
+
const checkSumContent = await response.text();
|
|
59
|
+
const lines = checkSumContent.split("\n");
|
|
60
|
+
|
|
61
|
+
const checksums = {};
|
|
62
|
+
for (const line of lines) {
|
|
63
|
+
const [checksum, packageName] = line.split(/\s+/);
|
|
64
|
+
checksums[packageName] = checksum;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return checksums;
|
|
68
|
+
} else {
|
|
69
|
+
console.error(
|
|
70
|
+
"Could not fetch checksum file",
|
|
71
|
+
response.status,
|
|
72
|
+
response.statusText
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const errGlobal = `Installing Supabase CLI as a global module is not supported.
|
|
78
|
+
Please use one of the supported package managers: https://github.com/supabase/cli#install-the-cli
|
|
79
|
+
`;
|
|
80
|
+
const errChecksum = "Checksum mismatch. Downloaded data might be corrupted.";
|
|
81
|
+
const errUnsupported = `Installation is not supported for ${process.platform} ${process.arch}`;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Reads the configuration from application's package.json,
|
|
85
|
+
* downloads the binary from package url and stores at
|
|
86
|
+
* ./bin in the package's root.
|
|
87
|
+
*
|
|
88
|
+
* See: https://docs.npmjs.com/files/package.json#bin
|
|
89
|
+
*/
|
|
90
|
+
async function main() {
|
|
91
|
+
const yarnGlobal = JSON.parse(
|
|
92
|
+
process.env.npm_config_argv || "{}"
|
|
93
|
+
).original?.includes("global");
|
|
94
|
+
if (process.env.npm_config_global || yarnGlobal) {
|
|
95
|
+
throw errGlobal;
|
|
96
|
+
}
|
|
97
|
+
if (!arch || !platform) {
|
|
98
|
+
throw errUnsupported;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Read from package.json and prepare for the installation.
|
|
102
|
+
const pkg = await readPackageJson();
|
|
103
|
+
if (platform === "windows") {
|
|
104
|
+
// Update bin path in package.json
|
|
105
|
+
pkg.bin[pkg.name] += ".exe";
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Prepare the installation path by creating the directory if it doesn't exist.
|
|
109
|
+
const binPath = pkg.bin[pkg.name];
|
|
110
|
+
const binDir = path.dirname(binPath);
|
|
111
|
+
await fs.promises.mkdir(binDir, { recursive: true });
|
|
112
|
+
|
|
113
|
+
// Create the agent that will be used for all the fetch requests later.
|
|
114
|
+
const proxyUrl =
|
|
115
|
+
process.env.npm_config_https_proxy ||
|
|
116
|
+
process.env.npm_config_http_proxy ||
|
|
117
|
+
process.env.npm_config_proxy;
|
|
118
|
+
// Keeps the TCP connection alive when sending multiple requests
|
|
119
|
+
// Ref: https://github.com/node-fetch/node-fetch/issues/1735
|
|
120
|
+
const agent = proxyUrl
|
|
121
|
+
? new HttpsProxyAgent(proxyUrl, { keepAlive: true })
|
|
122
|
+
: new Agent({ keepAlive: true });
|
|
123
|
+
|
|
124
|
+
// First, fetch the checksum map.
|
|
125
|
+
const checksumMap = await fetchAndParseCheckSumFile(pkg, agent);
|
|
126
|
+
|
|
127
|
+
// Then, download the binary.
|
|
128
|
+
const url = getDownloadUrl(pkg);
|
|
129
|
+
console.info("Downloading", url);
|
|
130
|
+
const resp = await fetch(url, { agent });
|
|
131
|
+
const hash = createHash("sha256");
|
|
132
|
+
const pkgNameWithPlatform = `${pkg.name}_${platform}_${arch}.tar.gz`;
|
|
133
|
+
|
|
134
|
+
// Then, decompress the binary -- we will first Un-GZip, then we will untar.
|
|
135
|
+
const ungz = zlib.createGunzip();
|
|
136
|
+
const binName = path.basename(binPath);
|
|
137
|
+
const untar = extract({ cwd: binDir }, [binName]);
|
|
138
|
+
|
|
139
|
+
// Update the hash with the binary data as it's being downloaded.
|
|
140
|
+
resp.body
|
|
141
|
+
.on("data", (chunk) => {
|
|
142
|
+
hash.update(chunk);
|
|
143
|
+
})
|
|
144
|
+
// Pipe the data to the ungz stream.
|
|
145
|
+
.pipe(ungz);
|
|
146
|
+
|
|
147
|
+
// After the ungz stream has ended, verify the checksum.
|
|
148
|
+
ungz
|
|
149
|
+
.on("end", () => {
|
|
150
|
+
const expectedChecksum = checksumMap?.[pkgNameWithPlatform];
|
|
151
|
+
// Skip verification if we can't find the file checksum
|
|
152
|
+
if (!expectedChecksum) {
|
|
153
|
+
console.warn("Skipping checksum verification");
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
const calculatedChecksum = hash.digest("hex");
|
|
157
|
+
if (calculatedChecksum !== expectedChecksum) {
|
|
158
|
+
throw errChecksum;
|
|
159
|
+
}
|
|
160
|
+
console.info("Checksum verified.");
|
|
161
|
+
})
|
|
162
|
+
// Pipe the data to the untar stream.
|
|
163
|
+
.pipe(untar);
|
|
164
|
+
|
|
165
|
+
// Wait for the untar stream to finish.
|
|
166
|
+
await new Promise((resolve, reject) => {
|
|
167
|
+
untar.on("error", reject);
|
|
168
|
+
untar.on("end", () => resolve());
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
// Link the binaries in postinstall to support yarn
|
|
172
|
+
await binLinks({
|
|
173
|
+
path: path.resolve("."),
|
|
174
|
+
pkg: { ...pkg, bin: { [pkg.name]: binPath } },
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
console.info("Installed Supabase CLI successfully");
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
await main();
|