ta_data_mas 0.0.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/README.md +42 -0
- package/apps/api/.prettierrc +4 -0
- package/apps/api/README.md +98 -0
- package/apps/api/drizzle/0000_right_drax.sql +87 -0
- package/apps/api/drizzle/meta/0000_snapshot.json +588 -0
- package/apps/api/drizzle/meta/_journal.json +13 -0
- package/apps/api/drizzle.config.ts +12 -0
- package/apps/api/eslint.config.mjs +35 -0
- package/apps/api/nest-cli.json +8 -0
- package/apps/api/package.json +99 -0
- package/apps/api/src/app.controller.spec.ts +25 -0
- package/apps/api/src/app.controller.ts +9 -0
- package/apps/api/src/app.module.ts +37 -0
- package/apps/api/src/app.service.ts +8 -0
- package/apps/api/src/auth/auth.controller.ts +113 -0
- package/apps/api/src/auth/auth.module.ts +15 -0
- package/apps/api/src/auth/auth.service.ts +309 -0
- package/apps/api/src/auth/decorators/current-user-decorator.ts +10 -0
- package/apps/api/src/auth/decorators/require-org-role-decorator.ts +7 -0
- package/apps/api/src/auth/dto/login.dto.ts +10 -0
- package/apps/api/src/auth/dto/register.dto.ts +14 -0
- package/apps/api/src/auth/guards/jwt-auth-guard.ts +40 -0
- package/apps/api/src/auth/guards/org-role.guards.ts +60 -0
- package/apps/api/src/db/db.module.ts +9 -0
- package/apps/api/src/db/drizzle.service.ts +16 -0
- package/apps/api/src/db/schema/index.ts +6 -0
- package/apps/api/src/db/schema/organizations.ts +30 -0
- package/apps/api/src/db/schema/projects.ts +26 -0
- package/apps/api/src/db/schema/query-history.ts +16 -0
- package/apps/api/src/db/schema/storage-buckets.ts +17 -0
- package/apps/api/src/db/schema/storage-objects.ts +18 -0
- package/apps/api/src/db/schema/users.ts +14 -0
- package/apps/api/src/main.ts +51 -0
- package/apps/api/src/members/dto/invite-member-dto.ts +6 -0
- package/apps/api/src/members/dto/update-role.dto.ts +8 -0
- package/apps/api/src/members/invite.service.ts +147 -0
- package/apps/api/src/members/members.controller.ts +56 -0
- package/apps/api/src/members/members.module.ts +13 -0
- package/apps/api/src/members/members.service.ts +85 -0
- package/apps/api/src/orgs/dto/create-org.dto.ts +8 -0
- package/apps/api/src/orgs/orgs.controller.ts +27 -0
- package/apps/api/src/orgs/orgs.module.ts +12 -0
- package/apps/api/src/orgs/orgs.service.ts +86 -0
- package/apps/api/src/project-api/project-api.controller.ts +95 -0
- package/apps/api/src/project-api/project-api.module.ts +12 -0
- package/apps/api/src/project-api/project-api.service.ts +196 -0
- package/apps/api/src/project-api/project-key.guard.ts +45 -0
- package/apps/api/src/project-api/query-parser.ts +129 -0
- package/apps/api/src/project-auth/dto/magic-link.dto.ts +7 -0
- package/apps/api/src/project-auth/dto/signin.dto.ts +10 -0
- package/apps/api/src/project-auth/dto/signup.dto.ts +11 -0
- package/apps/api/src/project-auth/project-auth-dashboard.controller.ts +35 -0
- package/apps/api/src/project-auth/project-auth.controller.ts +111 -0
- package/apps/api/src/project-auth/project-auth.module.ts +13 -0
- package/apps/api/src/project-auth/project-auth.service.ts +440 -0
- package/apps/api/src/projects/dto/create-project.dto.ts +9 -0
- package/apps/api/src/projects/projects.controller.ts +34 -0
- package/apps/api/src/projects/projects.module.ts +12 -0
- package/apps/api/src/projects/projects.service.ts +136 -0
- package/apps/api/src/realtime/realtime-socket.type.ts +14 -0
- package/apps/api/src/realtime/realtime.controller.ts +63 -0
- package/apps/api/src/realtime/realtime.gateway.ts +150 -0
- package/apps/api/src/realtime/realtime.module.ts +14 -0
- package/apps/api/src/realtime/realtime.service.ts +101 -0
- package/apps/api/src/realtime/trigger.service.ts +95 -0
- package/apps/api/src/sql-editor/dto/execute-query.dto.ts +7 -0
- package/apps/api/src/sql-editor/sql-editor.controller.ts +28 -0
- package/apps/api/src/sql-editor/sql-editor.module.ts +12 -0
- package/apps/api/src/sql-editor/sql-editor.service.ts +154 -0
- package/apps/api/src/storage/project-storage.controller.ts +140 -0
- package/apps/api/src/storage/storage.controller.ts +118 -0
- package/apps/api/src/storage/storage.module.ts +15 -0
- package/apps/api/src/storage/storage.service.ts +191 -0
- package/apps/api/src/storage/uploadthing.ts +23 -0
- package/apps/api/src/table-editor/dto/alter-table.dto.ts +15 -0
- package/apps/api/src/table-editor/dto/create-table.dto.ts +54 -0
- package/apps/api/src/table-editor/table-editor.controller.ts +117 -0
- package/apps/api/src/table-editor/table-editor.module.ts +12 -0
- package/apps/api/src/table-editor/table-editor.service.ts +366 -0
- package/apps/api/test/app.e2e-spec.ts +29 -0
- package/apps/api/test/jest-e2e.json +9 -0
- package/apps/api/tsconfig.build.json +4 -0
- package/apps/api/tsconfig.json +25 -0
- package/apps/web/.env.example +12 -0
- package/apps/web/AGENTS.md +9 -0
- package/apps/web/CLAUDE.md +1 -0
- package/apps/web/README.md +36 -0
- package/apps/web/components.json +25 -0
- package/apps/web/eslint.config.mjs +18 -0
- package/apps/web/next.config.ts +11 -0
- package/apps/web/package.json +48 -0
- package/apps/web/postcss.config.mjs +7 -0
- package/apps/web/public/file.svg +1 -0
- package/apps/web/public/globe.svg +1 -0
- package/apps/web/public/logo.svg +4 -0
- package/apps/web/public/next.svg +1 -0
- package/apps/web/public/vercel.svg +1 -0
- package/apps/web/public/window.svg +1 -0
- package/apps/web/src/app/(dashboard)/layout.tsx +33 -0
- package/apps/web/src/app/(dashboard)/organizations/(list)/layout.tsx +7 -0
- package/apps/web/src/app/(dashboard)/organizations/(list)/new/page.tsx +26 -0
- package/apps/web/src/app/(dashboard)/organizations/(list)/page.tsx +44 -0
- package/apps/web/src/app/(dashboard)/organizations/[slug]/[projectSlug]/api/page.tsx +13 -0
- package/apps/web/src/app/(dashboard)/organizations/[slug]/[projectSlug]/auth/layout.tsx +19 -0
- package/apps/web/src/app/(dashboard)/organizations/[slug]/[projectSlug]/auth/page.tsx +10 -0
- package/apps/web/src/app/(dashboard)/organizations/[slug]/[projectSlug]/auth/providers/page.tsx +19 -0
- package/apps/web/src/app/(dashboard)/organizations/[slug]/[projectSlug]/auth/url-configuration/page.tsx +24 -0
- package/apps/web/src/app/(dashboard)/organizations/[slug]/[projectSlug]/auth/users/page.tsx +13 -0
- package/apps/web/src/app/(dashboard)/organizations/[slug]/[projectSlug]/database/page.tsx +29 -0
- package/apps/web/src/app/(dashboard)/organizations/[slug]/[projectSlug]/realtime/page.tsx +28 -0
- package/apps/web/src/app/(dashboard)/organizations/[slug]/[projectSlug]/sql/page.tsx +21 -0
- package/apps/web/src/app/(dashboard)/organizations/[slug]/[projectSlug]/storage/page.tsx +28 -0
- package/apps/web/src/app/(dashboard)/organizations/[slug]/layout.tsx +20 -0
- package/apps/web/src/app/(dashboard)/organizations/[slug]/projects/page.tsx +62 -0
- package/apps/web/src/app/(dashboard)/organizations/[slug]/settings/members/page.tsx +28 -0
- package/apps/web/src/app/(dashboard)/organizations/[slug]/settings/page.tsx +10 -0
- package/apps/web/src/app/(dashboard)/settings/page.tsx +12 -0
- package/apps/web/src/app/dashboard/page.tsx +14 -0
- package/apps/web/src/app/favicon.ico +0 -0
- package/apps/web/src/app/globals.css +115 -0
- package/apps/web/src/app/layout.tsx +36 -0
- package/apps/web/src/app/login/page.tsx +199 -0
- package/apps/web/src/app/page.tsx +100 -0
- package/apps/web/src/app/register/page.tsx +218 -0
- package/apps/web/src/components/app-sidebar.tsx +301 -0
- package/apps/web/src/components/navbar.tsx +63 -0
- package/apps/web/src/components/topNav.tsx +68 -0
- package/apps/web/src/components/ui/avatar.tsx +112 -0
- package/apps/web/src/components/ui/badge.tsx +48 -0
- package/apps/web/src/components/ui/button.tsx +66 -0
- package/apps/web/src/components/ui/card.tsx +102 -0
- package/apps/web/src/components/ui/checkbox.tsx +32 -0
- package/apps/web/src/components/ui/dialog.tsx +168 -0
- package/apps/web/src/components/ui/dropdown-menu.tsx +269 -0
- package/apps/web/src/components/ui/field.tsx +238 -0
- package/apps/web/src/components/ui/input.tsx +19 -0
- package/apps/web/src/components/ui/label.tsx +24 -0
- package/apps/web/src/components/ui/resizable.tsx +50 -0
- package/apps/web/src/components/ui/scroll-area.tsx +55 -0
- package/apps/web/src/components/ui/select.tsx +192 -0
- package/apps/web/src/components/ui/separator.tsx +28 -0
- package/apps/web/src/components/ui/sheet.tsx +147 -0
- package/apps/web/src/components/ui/sidebar.tsx +703 -0
- package/apps/web/src/components/ui/skeleton.tsx +13 -0
- package/apps/web/src/components/ui/switch.tsx +33 -0
- package/apps/web/src/components/ui/table.tsx +116 -0
- package/apps/web/src/components/ui/tooltip.tsx +57 -0
- package/apps/web/src/features/api-docs/api-docs-client.tsx +227 -0
- package/apps/web/src/features/api-docs/api-docs-helpers.server.ts +86 -0
- package/apps/web/src/features/auth/action.ts +67 -0
- package/apps/web/src/features/auth/client.schema.ts +13 -0
- package/apps/web/src/features/auth/constants.ts +6 -0
- package/apps/web/src/features/auth/cookies.ts +86 -0
- package/apps/web/src/features/auth/server.schema.ts +11 -0
- package/apps/web/src/features/auth/sign-out.ts +17 -0
- package/apps/web/src/features/members/action.ts +66 -0
- package/apps/web/src/features/members/client.schema.ts +11 -0
- package/apps/web/src/features/members/constants.ts +8 -0
- package/apps/web/src/features/members/members-client.tsx +198 -0
- package/apps/web/src/features/members/members-helpers.server.ts +21 -0
- package/apps/web/src/features/members/server.schema.ts +19 -0
- package/apps/web/src/features/organization/action.ts +45 -0
- package/apps/web/src/features/organization/client.schema.ts +5 -0
- package/apps/web/src/features/organization/constants.tsx +3 -0
- package/apps/web/src/features/organization/create-org-form.tsx +66 -0
- package/apps/web/src/features/organization/organization-helpers.server.ts +35 -0
- package/apps/web/src/features/organization/server.schema.ts +10 -0
- package/apps/web/src/features/project-auth/project-auth-action.ts +78 -0
- package/apps/web/src/features/project-auth/project-auth-client.schema.ts +18 -0
- package/apps/web/src/features/project-auth/project-auth-constants.ts +8 -0
- package/apps/web/src/features/project-auth/project-auth-helpers.server.ts +39 -0
- package/apps/web/src/features/project-auth/project-auth-providers.tsx +222 -0
- package/apps/web/src/features/project-auth/project-auth-server.schema.ts +22 -0
- package/apps/web/src/features/project-auth/project-auth-shell.tsx +106 -0
- package/apps/web/src/features/project-auth/project-auth-url-config.tsx +151 -0
- package/apps/web/src/features/project-auth/project-auth-users.tsx +138 -0
- package/apps/web/src/features/projects/action.ts +46 -0
- package/apps/web/src/features/projects/client.schema.ts +9 -0
- package/apps/web/src/features/projects/constants.ts +6 -0
- package/apps/web/src/features/projects/create-project-modal.tsx +117 -0
- package/apps/web/src/features/projects/project-helpers.server.ts +38 -0
- package/apps/web/src/features/projects/server.schema.ts +10 -0
- package/apps/web/src/features/realtime/realtime-client.tsx +294 -0
- package/apps/web/src/features/realtime/realtime-helpers.server.ts +40 -0
- package/apps/web/src/features/sql-editor/sql-editor-client.tsx +324 -0
- package/apps/web/src/features/sql-editor/sql-editor-helpers.server.ts +22 -0
- package/apps/web/src/features/storage/storage-client.tsx +500 -0
- package/apps/web/src/features/storage/storage-helpers.server.ts +36 -0
- package/apps/web/src/features/table-editor/action.ts +97 -0
- package/apps/web/src/features/table-editor/add-column-dialog.tsx +184 -0
- package/apps/web/src/features/table-editor/client.schema.ts +36 -0
- package/apps/web/src/features/table-editor/create-table-drawer.tsx +542 -0
- package/apps/web/src/features/table-editor/server.schema.ts +41 -0
- package/apps/web/src/features/table-editor/table-editor-client.tsx +737 -0
- package/apps/web/src/features/table-editor/table-editor-helpers.server.ts +39 -0
- package/apps/web/src/hooks/use-mobile.ts +19 -0
- package/apps/web/src/lib/axios.ts +8 -0
- package/apps/web/src/lib/utils.ts +6 -0
- package/apps/web/src/proxy.ts +72 -0
- package/apps/web/src/server-utils/utils.ts +10 -0
- package/apps/web/tsconfig.json +34 -0
- package/package.json +22 -0
- package/packages/apiDatabase-js/package.json +39 -0
- package/packages/apiDatabase-js/src/auth/index.ts +121 -0
- package/packages/apiDatabase-js/src/client.ts +25 -0
- package/packages/apiDatabase-js/src/db/index.ts +15 -0
- package/packages/apiDatabase-js/src/db/query-builder.ts +194 -0
- package/packages/apiDatabase-js/src/index.ts +16 -0
- package/packages/apiDatabase-js/src/realtime/index.ts +84 -0
- package/packages/apiDatabase-js/src/storage/index.ts +130 -0
- package/packages/apiDatabase-js/tsconfig.json +13 -0
- package/packages/apiDatabase-js/tsdown.config.ts +20 -0
- package/packages/constants/package.json +6 -0
- package/packages/constants/src/index.ts +76 -0
- package/packages/tsconfig.json +13 -0
- package/packages/tsdown.config.ts +20 -0
- package/packages/types/package.json +6 -0
- package/packages/types/src/index.ts +254 -0
- package/pnpm-workspace.yaml +10 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { io, type Socket } from "socket.io-client";
|
|
2
|
+
import { REALTIME_EVENTS } from "@apiDatabase/constants";
|
|
3
|
+
import type { RealtimeEvent } from "@apiDatabase/types";
|
|
4
|
+
|
|
5
|
+
export type RealtimeCallback = (event: RealtimeEvent) => void;
|
|
6
|
+
|
|
7
|
+
function getRealtimeSocketUrl(projectUrl: string): string {
|
|
8
|
+
const origin = new URL(projectUrl).origin;
|
|
9
|
+
// NestJS gateway namespace is /realtime on the API host, NOT under /api
|
|
10
|
+
return `${origin}/realtime`;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export class apiDatabaseRealtime {
|
|
14
|
+
private socket: Socket | null = null;
|
|
15
|
+
private callbacks = new Map<string, Set<RealtimeCallback>>();
|
|
16
|
+
|
|
17
|
+
constructor(
|
|
18
|
+
private projectUrl: string,
|
|
19
|
+
private apiKey: string,
|
|
20
|
+
) {}
|
|
21
|
+
|
|
22
|
+
private connect(): Socket {
|
|
23
|
+
if (this.socket?.connected) return this.socket;
|
|
24
|
+
|
|
25
|
+
this.socket = io(getRealtimeSocketUrl(this.projectUrl), {
|
|
26
|
+
auth: { token: this.apiKey },
|
|
27
|
+
transports: ["websocket", "polling"],
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
this.socket.on("connect", () => {
|
|
31
|
+
for (const table of this.callbacks.keys()) {
|
|
32
|
+
this.socket?.emit(REALTIME_EVENTS.SUBSCRIBE, table);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
this.socket.on(REALTIME_EVENTS.EVENT, (event: RealtimeEvent) => {
|
|
37
|
+
const handlers = this.callbacks.get(event.table);
|
|
38
|
+
handlers?.forEach((cb) => cb(event));
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
this.socket.on(REALTIME_EVENTS.ERROR, (msg: string) => {
|
|
42
|
+
console.error("[apiDatabase-js] realtime error:", msg);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
return this.socket;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
subscribe(table: string, callback: RealtimeCallback): () => void {
|
|
49
|
+
const socket = this.connect();
|
|
50
|
+
|
|
51
|
+
if (!this.callbacks.has(table)) {
|
|
52
|
+
this.callbacks.set(table, new Set());
|
|
53
|
+
socket.emit(REALTIME_EVENTS.SUBSCRIBE, table);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
this.callbacks.get(table)!.add(callback);
|
|
57
|
+
|
|
58
|
+
return () => this.unsubscribe(table, callback);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
unsubscribe(table: string, callback?: RealtimeCallback): void {
|
|
62
|
+
if (!callback) {
|
|
63
|
+
this.callbacks.delete(table);
|
|
64
|
+
this.socket?.emit(REALTIME_EVENTS.UNSUBSCRIBE, table);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const handlers = this.callbacks.get(table);
|
|
69
|
+
if (!handlers) return;
|
|
70
|
+
|
|
71
|
+
handlers.delete(callback);
|
|
72
|
+
|
|
73
|
+
if (handlers.size === 0) {
|
|
74
|
+
this.callbacks.delete(table);
|
|
75
|
+
this.socket?.emit(REALTIME_EVENTS.UNSUBSCRIBE, table);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
disconnect(): void {
|
|
80
|
+
this.socket?.disconnect();
|
|
81
|
+
this.socket = null;
|
|
82
|
+
this.callbacks.clear();
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { genUploader } from "uploadthing/client";
|
|
2
|
+
import type { StorageObject } from "@apiDatabase/types";
|
|
3
|
+
|
|
4
|
+
type StorageUploadRouter = {
|
|
5
|
+
bucketUploader: {
|
|
6
|
+
input: undefined;
|
|
7
|
+
output: null;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export interface StorageResult<T> {
|
|
12
|
+
data: T | null;
|
|
13
|
+
error: string | null;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async function apiFetch<T>(
|
|
17
|
+
url: string,
|
|
18
|
+
apiKey: string,
|
|
19
|
+
init?: RequestInit,
|
|
20
|
+
): Promise<StorageResult<T>> {
|
|
21
|
+
try {
|
|
22
|
+
const res = await fetch(url, {
|
|
23
|
+
...init,
|
|
24
|
+
headers: {
|
|
25
|
+
Authorization: `Bearer ${apiKey}`,
|
|
26
|
+
"Content-Type": "application/json",
|
|
27
|
+
...init?.headers,
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
if (!res.ok) {
|
|
32
|
+
const err = (await res.json().catch(() => ({}))) as { message?: string };
|
|
33
|
+
return { data: null, error: err.message ?? `HTTP ${res.status}` };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const data = (await res.json()) as T;
|
|
37
|
+
return { data, error: null };
|
|
38
|
+
} catch (err: unknown) {
|
|
39
|
+
const message = err instanceof Error ? err.message : "Network error";
|
|
40
|
+
return { data: null, error: message };
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export class StorageBucketRef {
|
|
45
|
+
constructor(
|
|
46
|
+
private projectUrl: string,
|
|
47
|
+
private apiKey: string,
|
|
48
|
+
private bucketName: string,
|
|
49
|
+
) {}
|
|
50
|
+
|
|
51
|
+
private storageBase(): string {
|
|
52
|
+
const bucket = encodeURIComponent(this.bucketName);
|
|
53
|
+
return `${this.projectUrl}/storage/buckets/${bucket}`;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async list(): Promise<StorageResult<StorageObject[]>> {
|
|
57
|
+
return apiFetch<StorageObject[]>(
|
|
58
|
+
`${this.storageBase()}/objects`,
|
|
59
|
+
this.apiKey,
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async upload(file: File): Promise<StorageResult<StorageObject>> {
|
|
64
|
+
try {
|
|
65
|
+
const uploadUrl = `${this.storageBase()}/upload`;
|
|
66
|
+
const { uploadFiles } = genUploader({
|
|
67
|
+
url: uploadUrl,
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
const uploaded = await uploadFiles("bucketUploader", {
|
|
71
|
+
files: [file],
|
|
72
|
+
headers: { Authorization: `Bearer ${this.apiKey}` },
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
const utFile = uploaded[0];
|
|
76
|
+
if (!utFile) {
|
|
77
|
+
return { data: null, error: "Upload returned no files" };
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return apiFetch<StorageObject>(
|
|
81
|
+
`${this.storageBase()}/objects`,
|
|
82
|
+
this.apiKey,
|
|
83
|
+
{
|
|
84
|
+
method: "POST",
|
|
85
|
+
body: JSON.stringify({
|
|
86
|
+
name: utFile.name,
|
|
87
|
+
size: utFile.size,
|
|
88
|
+
type: file.type || "application/octet-stream",
|
|
89
|
+
utKey: utFile.key,
|
|
90
|
+
url: utFile.url,
|
|
91
|
+
}),
|
|
92
|
+
},
|
|
93
|
+
);
|
|
94
|
+
} catch (err: unknown) {
|
|
95
|
+
const message = err instanceof Error ? err.message : "Upload failed";
|
|
96
|
+
return { data: null, error: message };
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
async remove(objectId: string): Promise<StorageResult<{ message: string }>> {
|
|
101
|
+
return apiFetch<{ message: string }>(
|
|
102
|
+
`${this.projectUrl}/storage/objects/${objectId}`,
|
|
103
|
+
this.apiKey,
|
|
104
|
+
{ method: "DELETE" },
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async getSignedUrl(
|
|
109
|
+
objectId: string,
|
|
110
|
+
): Promise<StorageResult<{ url: string }>> {
|
|
111
|
+
return apiFetch<{ url: string }>(
|
|
112
|
+
`${this.projectUrl}/storage/objects/${objectId}/signed-url`,
|
|
113
|
+
this.apiKey,
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export class ApiDatabaseStorage {
|
|
119
|
+
constructor(
|
|
120
|
+
private projectUrl: string,
|
|
121
|
+
private apiKey: string,
|
|
122
|
+
) {}
|
|
123
|
+
|
|
124
|
+
from(bucketName: string): StorageBucketRef {
|
|
125
|
+
return new StorageBucketRef(this.projectUrl, this.apiKey, bucketName);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// const bucket = supabavolt.storage.from('test');
|
|
130
|
+
// const {data: files} = await bucket.list();
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { defineConfig } from "tsdown";
|
|
2
|
+
|
|
3
|
+
export default defineConfig({
|
|
4
|
+
entry: ["src/index.ts"],
|
|
5
|
+
format: ["cjs", "esm"],
|
|
6
|
+
platform: "browser",
|
|
7
|
+
dts: true,
|
|
8
|
+
clean: true,
|
|
9
|
+
sourcemap: true,
|
|
10
|
+
minify: false,
|
|
11
|
+
deps: {
|
|
12
|
+
neverBundle: ["@apiDatabase/types"],
|
|
13
|
+
alwaysBundle: [
|
|
14
|
+
"socket.io-client",
|
|
15
|
+
"@apiDatabase/constants",
|
|
16
|
+
"uploadthing",
|
|
17
|
+
"uploadthing/client",
|
|
18
|
+
],
|
|
19
|
+
},
|
|
20
|
+
});
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
export const COOKIE_KEYS = {
|
|
2
|
+
ACCESS_TOKEN: "access_token",
|
|
3
|
+
REFRESH_TOKEN: "refresh_token",
|
|
4
|
+
} as const;
|
|
5
|
+
|
|
6
|
+
export const ORG_ROLES = {
|
|
7
|
+
ADMIN: "admin",
|
|
8
|
+
DEVELOPER: "developer",
|
|
9
|
+
} as const;
|
|
10
|
+
|
|
11
|
+
export const INVITE_EXPIRES_IN = "24h";
|
|
12
|
+
|
|
13
|
+
export const PROJECT_KEY_ROLES = {
|
|
14
|
+
ANON: "anon",
|
|
15
|
+
SERVICE_ROLE: "service_role",
|
|
16
|
+
} as const;
|
|
17
|
+
|
|
18
|
+
export const COLUMN_TYPES = [
|
|
19
|
+
"text",
|
|
20
|
+
"integer",
|
|
21
|
+
"bigint",
|
|
22
|
+
"boolean",
|
|
23
|
+
"timestamp",
|
|
24
|
+
"uuid",
|
|
25
|
+
"jsonb",
|
|
26
|
+
"numeric",
|
|
27
|
+
] as const;
|
|
28
|
+
|
|
29
|
+
export const TABLE_EDITOR_INTENT = {
|
|
30
|
+
CREATE_TABLE: "CREATE_TABLE",
|
|
31
|
+
DELETE_TABLE: "DELETE_TABLE",
|
|
32
|
+
FETCH_TABLE: "FETCH_TABLE",
|
|
33
|
+
ADD_COLUMN: "ADD_COLUMN",
|
|
34
|
+
} as const;
|
|
35
|
+
|
|
36
|
+
export type TableEditorIntent =
|
|
37
|
+
(typeof TABLE_EDITOR_INTENT)[keyof typeof TABLE_EDITOR_INTENT];
|
|
38
|
+
|
|
39
|
+
export const RESERVED_QUERY_PARAMS = new Set([
|
|
40
|
+
"select",
|
|
41
|
+
"order",
|
|
42
|
+
"limit",
|
|
43
|
+
"offset",
|
|
44
|
+
]);
|
|
45
|
+
|
|
46
|
+
export const FILTER_OPERATORS = {
|
|
47
|
+
eq: "=",
|
|
48
|
+
neq: "!=",
|
|
49
|
+
gt: ">",
|
|
50
|
+
gte: ">=",
|
|
51
|
+
lt: "<",
|
|
52
|
+
lte: "<=",
|
|
53
|
+
like: "LIKE",
|
|
54
|
+
ilike: "ILIKE",
|
|
55
|
+
is: "IS",
|
|
56
|
+
} as const;
|
|
57
|
+
|
|
58
|
+
export type FilterOperator = keyof typeof FILTER_OPERATORS;
|
|
59
|
+
|
|
60
|
+
// REALTIME
|
|
61
|
+
export const REALTIME_EVENTS = {
|
|
62
|
+
SUBSCRIBE: "subscribe",
|
|
63
|
+
UNSUBSCRIBE: "unsubscribe",
|
|
64
|
+
EVENT: "event",
|
|
65
|
+
ERROR: "error",
|
|
66
|
+
} as const;
|
|
67
|
+
|
|
68
|
+
// ─── Project Auth ─────────────────────────────────────────────────────────────
|
|
69
|
+
|
|
70
|
+
export const AUTH_PROVIDERS = {
|
|
71
|
+
EMAIL: "email",
|
|
72
|
+
GOOGLE: "google",
|
|
73
|
+
GITHUB: "github",
|
|
74
|
+
} as const;
|
|
75
|
+
|
|
76
|
+
export const MAGIC_LINK_EXPIRES_IN = "15m";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { defineConfig } from "tsdown";
|
|
2
|
+
|
|
3
|
+
export default defineConfig({
|
|
4
|
+
entry: ["src/index.ts"],
|
|
5
|
+
format: ["cjs", "esm"],
|
|
6
|
+
platform: "browser",
|
|
7
|
+
dts: true,
|
|
8
|
+
clean: true,
|
|
9
|
+
sourcemap: true,
|
|
10
|
+
minify: false,
|
|
11
|
+
deps: {
|
|
12
|
+
neverBundle: ["@apiDatabase/types"],
|
|
13
|
+
alwaysBundle: [
|
|
14
|
+
"socket.io-client",
|
|
15
|
+
"@apiDatabase/constants",
|
|
16
|
+
"uploadthing",
|
|
17
|
+
"uploadthing/client",
|
|
18
|
+
],
|
|
19
|
+
},
|
|
20
|
+
});
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
export interface User {
|
|
2
|
+
id: string;
|
|
3
|
+
email: string;
|
|
4
|
+
name: string | null;
|
|
5
|
+
avatarUrl: string | null;
|
|
6
|
+
createdAt: string;
|
|
7
|
+
updatedAt: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export type OrgRole = "admin" | "developer";
|
|
11
|
+
|
|
12
|
+
export interface Organization {
|
|
13
|
+
id: string;
|
|
14
|
+
name: string;
|
|
15
|
+
slug: string;
|
|
16
|
+
createdAt: string;
|
|
17
|
+
updatedAt: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface OrgMember {
|
|
21
|
+
id: string;
|
|
22
|
+
orgId: string;
|
|
23
|
+
userId: string;
|
|
24
|
+
role: OrgRole;
|
|
25
|
+
createdAt: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface Project {
|
|
29
|
+
id: string;
|
|
30
|
+
orgId: string;
|
|
31
|
+
name: string;
|
|
32
|
+
slug: string;
|
|
33
|
+
dbSchema: string;
|
|
34
|
+
projectUrl: string;
|
|
35
|
+
anonKey: string;
|
|
36
|
+
serviceRoleKey: string;
|
|
37
|
+
createdAt: string;
|
|
38
|
+
updatedAt: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface RegisterInput {
|
|
42
|
+
email: string;
|
|
43
|
+
password: string;
|
|
44
|
+
name: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface LoginInput {
|
|
48
|
+
email: string;
|
|
49
|
+
password: string;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface AuthTokens {
|
|
53
|
+
accessToken: string;
|
|
54
|
+
refreshToken: string;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface JwtPayload {
|
|
58
|
+
sub: string;
|
|
59
|
+
email: string;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface CreateOrgInput {
|
|
63
|
+
name: string;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface OrganizationWithMeta extends Organization {
|
|
67
|
+
memberCount: number;
|
|
68
|
+
projectCount: number;
|
|
69
|
+
role: OrgRole;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export interface OrgMemberWithUser {
|
|
73
|
+
id: string;
|
|
74
|
+
role: OrgRole;
|
|
75
|
+
createdAt: string;
|
|
76
|
+
user: {
|
|
77
|
+
id: string;
|
|
78
|
+
name: string | null;
|
|
79
|
+
email: string;
|
|
80
|
+
avatarUrl: string | null;
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface InviteMemberInput {
|
|
85
|
+
email: string;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export interface UpdateRoleInput {
|
|
89
|
+
role: OrgRole;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export interface CreateProjectInput {
|
|
93
|
+
name: string;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export interface ProjectWithOrg extends Project {
|
|
97
|
+
org: Pick<Organization, "id" | "name" | "slug">;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export type ColumnType =
|
|
101
|
+
| "text"
|
|
102
|
+
| "integer"
|
|
103
|
+
| "bigint"
|
|
104
|
+
| "boolean"
|
|
105
|
+
| "timestamp"
|
|
106
|
+
| "uuid"
|
|
107
|
+
| "jsonb"
|
|
108
|
+
| "numeric"
|
|
109
|
+
| "array";
|
|
110
|
+
|
|
111
|
+
export interface TableColumn {
|
|
112
|
+
name: string;
|
|
113
|
+
type: ColumnType;
|
|
114
|
+
isNullable: boolean;
|
|
115
|
+
isPrimaryKey: boolean;
|
|
116
|
+
defaultValue: string | null;
|
|
117
|
+
foreignKey: {
|
|
118
|
+
table: string;
|
|
119
|
+
column: string;
|
|
120
|
+
} | null;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export interface TableInfo {
|
|
124
|
+
name: string;
|
|
125
|
+
columns: TableColumn[];
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export interface CreateColumnInput {
|
|
129
|
+
name: string;
|
|
130
|
+
type: ColumnType;
|
|
131
|
+
isNullable: boolean;
|
|
132
|
+
isPrimaryKey: boolean;
|
|
133
|
+
defaultValue?: string;
|
|
134
|
+
foreignKeyTable?: string;
|
|
135
|
+
foreignKeyColumn?: string;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export interface CreateTableInput {
|
|
139
|
+
name: string;
|
|
140
|
+
columns: CreateColumnInput[];
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// API DOCS
|
|
144
|
+
export interface ProjectApiEndpoint {
|
|
145
|
+
method: "GET" | "POST" | "PATCH" | "DELETE";
|
|
146
|
+
path: string;
|
|
147
|
+
description: string;
|
|
148
|
+
example: string;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export interface ProjectApiDocs {
|
|
152
|
+
projectUrl: string;
|
|
153
|
+
anonKey: string;
|
|
154
|
+
serviceRoleKey: string;
|
|
155
|
+
tables: {
|
|
156
|
+
name: string;
|
|
157
|
+
endpoints: ProjectApiEndpoint[];
|
|
158
|
+
}[];
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export interface ProjectBySlugResponse {
|
|
162
|
+
projects: Project;
|
|
163
|
+
organizations: Organization;
|
|
164
|
+
org_members: OrgMember;
|
|
165
|
+
}
|
|
166
|
+
// SQL EDITOR
|
|
167
|
+
export interface QueryResult {
|
|
168
|
+
rows: Record<string, unknown>[];
|
|
169
|
+
columns: string[];
|
|
170
|
+
rowCount: number;
|
|
171
|
+
executionTimeMs: number;
|
|
172
|
+
command?: string;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export interface QueryHistoryItem {
|
|
176
|
+
id: string;
|
|
177
|
+
projectId: string;
|
|
178
|
+
sql: string;
|
|
179
|
+
executionTimeMs: number;
|
|
180
|
+
rowCount: number;
|
|
181
|
+
createdAt: string;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export type RealtimeEventType = "INSERT" | "UPDATE" | "DELETE";
|
|
185
|
+
|
|
186
|
+
export interface RealtimeEvent {
|
|
187
|
+
type: RealtimeEventType;
|
|
188
|
+
table: string;
|
|
189
|
+
record: Record<string, unknown>;
|
|
190
|
+
oldRecord?: Record<string, unknown>; // only on UPDATE and DELETE
|
|
191
|
+
projectId: string;
|
|
192
|
+
timestamp: string;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export type BucketAccess = "public" | "private";
|
|
196
|
+
|
|
197
|
+
export interface StorageBucket {
|
|
198
|
+
id: string;
|
|
199
|
+
projectId: string;
|
|
200
|
+
name: string;
|
|
201
|
+
access: BucketAccess;
|
|
202
|
+
createdAt: string;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export interface StorageObject {
|
|
206
|
+
id: string;
|
|
207
|
+
bucketId: string;
|
|
208
|
+
name: string;
|
|
209
|
+
size: number;
|
|
210
|
+
mimeType: string;
|
|
211
|
+
utKey: string; // UploadThing file key — used to delete or get signed URL
|
|
212
|
+
url: string; // public URL (public buckets) or empty string (private)
|
|
213
|
+
createdAt: string;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export interface CreateBucketInput {
|
|
217
|
+
name: string;
|
|
218
|
+
access: BucketAccess;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
export interface ProjectAuthUser {
|
|
222
|
+
id: string;
|
|
223
|
+
email: string;
|
|
224
|
+
emailVerified: boolean;
|
|
225
|
+
provider: "email" | "google" | "github";
|
|
226
|
+
createdAt: string;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
export interface SignUpInput {
|
|
230
|
+
email: string;
|
|
231
|
+
password: string;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
export interface SignInInput {
|
|
235
|
+
email: string;
|
|
236
|
+
password: string;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
export interface MagicLinkInput {
|
|
240
|
+
email: string;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
export interface ProjectOAuthSettings {
|
|
244
|
+
siteUrl: string | null;
|
|
245
|
+
googleClientId: string | null;
|
|
246
|
+
googleClientSecret: string | null;
|
|
247
|
+
githubClientId: string | null;
|
|
248
|
+
githubClientSecret: string | null;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
export interface ProjectAuthResponse {
|
|
252
|
+
user: { id: string; email: string };
|
|
253
|
+
accessToken: string;
|
|
254
|
+
}
|