@webstudio-is/postgrest 0.252.1
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 +661 -0
- package/README.md +51 -0
- package/package.json +29 -0
- package/playground/domains.ts +54 -0
- package/playground/pnpm-playground +8 -0
- package/src/__generated__/db-types.ts +1176 -0
- package/src/index.server.ts +16 -0
- package/supabase/SQL-TESTS-AI.md +161 -0
- package/supabase/tests/cleanup-builds.sql +227 -0
- package/supabase/tests/latest-builds-domains.sql +516 -0
- package/supabase/tests/latest-builds-projects.sql +808 -0
- package/supabase/tests/project-domains.sql +77 -0
- package/tsconfig.json +3 -0
package/README.md
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# Postgrest
|
|
2
|
+
|
|
3
|
+
## Postgrest-js
|
|
4
|
+
|
|
5
|
+
[postgrest-js best doc](https://supabase.com/docs/reference/javascript/select)
|
|
6
|
+
|
|
7
|
+
## Generated Types
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm generate-types
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
or in case of non devcontainer environment
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
docker compose exec -iT app bash
|
|
17
|
+
cd /workspaces/webstudio/packages/postgrest
|
|
18
|
+
pnpm generate-types
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Playground
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
pnpm playground ./playground/{file}.ts
|
|
25
|
+
# OR
|
|
26
|
+
pnpm tsx --env-file ../../apps/builder/.env ./playground/{file}.ts
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Next steps.
|
|
30
|
+
|
|
31
|
+
Use https://supabase.com/docs/reference/cli/supabase-db-start or directly https://github.com/djrobstep/migra for migrations.
|
|
32
|
+
|
|
33
|
+
Supabase can be used with `--db-url` flag to not reproduce "local" env
|
|
34
|
+
|
|
35
|
+
## Sql testing
|
|
36
|
+
|
|
37
|
+
```sql
|
|
38
|
+
CREATE SCHEMA IF NOT EXISTS pgtap;
|
|
39
|
+
DROP EXTENSION pgtap;
|
|
40
|
+
CREATE EXTENSION IF NOT EXISTS pgtap WITH SCHEMA pgtap;
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
pnpx supabase test new latest-builds
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
```shell
|
|
48
|
+
docker run --rm --network host -v ./supabase/tests:/tests -e PGOPTIONS='--search_path=pgtap,public' supabase/pg_prove:3.36 pg_prove -d "postgresql://postgres:pass@localhost/webstudio" --ext .sql /tests
|
|
49
|
+
# OR
|
|
50
|
+
pnpm run db-test
|
|
51
|
+
```
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@webstudio-is/postgrest",
|
|
3
|
+
"version": "0.252.1",
|
|
4
|
+
"description": "Webstudio Project Build",
|
|
5
|
+
"author": "Webstudio <github@webstudio.is>",
|
|
6
|
+
"homepage": "https://webstudio.is",
|
|
7
|
+
"license": "AGPL-3.0-or-later",
|
|
8
|
+
"private": false,
|
|
9
|
+
"type": "module",
|
|
10
|
+
"exports": {
|
|
11
|
+
"./index.server": {
|
|
12
|
+
"webstudio": "./src/index.server.ts",
|
|
13
|
+
"import": "./src/index.server.ts"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"sideEffects": false,
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@supabase/postgrest-js": "^1.19.3"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@webstudio-is/tsconfig": "1.0.7"
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"typecheck": "tsgo --noEmit",
|
|
25
|
+
"generate-types": "pnpx supabase gen types --lang=typescript --db-url postgresql://postgres:pass@localhost/webstudio > ./src/__generated__/db-types.ts && prettier --write ./src/__generated__/db-types.ts",
|
|
26
|
+
"playground": "pnpm tsx --env-file ../../apps/builder/.env",
|
|
27
|
+
"db-test": "docker run --rm --network host -v ./supabase/tests:/tests -e PGOPTIONS='--search_path=pgtap,public' supabase/pg_prove:3.36 pg_prove -d ${DIRECT_URL:-postgresql://postgres:pass@localhost/webstudio} --ext .sql /tests"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
#!/usr/bin/env ./playground/pnpm-playground
|
|
2
|
+
|
|
3
|
+
import { createClient } from "../src/index.server";
|
|
4
|
+
|
|
5
|
+
const client = createClient(
|
|
6
|
+
process.env.POSTGREST_URL!,
|
|
7
|
+
process.env.POSTGREST_API_KEY!
|
|
8
|
+
);
|
|
9
|
+
|
|
10
|
+
const result = await client
|
|
11
|
+
.from("Project")
|
|
12
|
+
.select("domainsVirtual(*, latestBuildVirtual(*))")
|
|
13
|
+
.eq("id", "090e6e14-ae50-4b2e-bd22-71733cec05bb");
|
|
14
|
+
|
|
15
|
+
console.info(JSON.stringify(result, null, " "));
|
|
16
|
+
|
|
17
|
+
/*
|
|
18
|
+
const domain = "hello.world";
|
|
19
|
+
const result = await client
|
|
20
|
+
.from("Domain")
|
|
21
|
+
.upsert(
|
|
22
|
+
{
|
|
23
|
+
id: crypto.randomUUID(),
|
|
24
|
+
domain,
|
|
25
|
+
status: "INITIALIZING",
|
|
26
|
+
error: null,
|
|
27
|
+
},
|
|
28
|
+
{ onConflict: "domain", ignoreDuplicates: false }
|
|
29
|
+
)
|
|
30
|
+
.eq("domain", domain)
|
|
31
|
+
.select("*");
|
|
32
|
+
|
|
33
|
+
console.info(JSON.stringify(result, null, " "));
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
/*
|
|
37
|
+
const result = await client
|
|
38
|
+
.from("ProjectWithDomain")
|
|
39
|
+
.select("Domain(*), latestBuildVirtual(*)")
|
|
40
|
+
.eq("projectId", "1bbe90ae-f0b3-4b2d-925f-26c75f824344");
|
|
41
|
+
|
|
42
|
+
const result = await client
|
|
43
|
+
.from("Project")
|
|
44
|
+
.select(
|
|
45
|
+
"ProjectDomain(Domain(*), latestBuildVirtual(*)), latestBuildVirtual(*)"
|
|
46
|
+
)
|
|
47
|
+
.eq("id", "1bbe90ae-f0b3-4b2d-925f-26c75f824344");
|
|
48
|
+
|
|
49
|
+
if (result.error) {
|
|
50
|
+
throw result.error;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
console.info(JSON.stringify(result.data, null, " "));
|
|
54
|
+
*/
|