Skip to content
This repository was archived by the owner on Oct 9, 2025. It is now read-only.

Commit a35ddbd

Browse files
fenositslenny
authored andcommitted
feat: list-v2 endpoint
1 parent d0e7dc2 commit a35ddbd

File tree

7 files changed

+74
-24
lines changed

7 files changed

+74
-24
lines changed

infra/docker-compose.yml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,9 @@ services:
4949
context: ./postgres
5050
ports:
5151
- 5432:5432
52-
command:
53-
- postgres
54-
- -c
55-
- wal_level=logical
52+
command: postgres -c config_file=/etc/postgresql/postgresql.conf
5653
environment:
57-
POSTGRES_DB: postgres
58-
POSTGRES_USER: postgres
5954
POSTGRES_PASSWORD: postgres
60-
POSTGRES_PORT: 5432
6155
healthcheck:
6256
test: [ "CMD-SHELL", "pg_isready" ]
6357
interval: 10s

infra/postgres/Dockerfile

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,10 @@
1-
FROM supabase/postgres:0.13.0
2-
3-
COPY 00-initial-schema.sql /docker-entrypoint-initdb.d/00-initial-schema.sql
4-
COPY auth-schema.sql /docker-entrypoint-initdb.d/01-auth-schema.sql
5-
COPY storage-schema.sql /docker-entrypoint-initdb.d/02-storage-schema.sql
1+
FROM supabase/postgres:15.8.1.044
2+
#
3+
#COPY 00-initial-schema.sql /docker-entrypoint-initdb.d/00-initial-schema.sql
4+
#COPY auth-schema.sql /docker-entrypoint-initdb.d/01-auth-schema.sql
5+
#COPY storage-schema.sql /docker-entrypoint-initdb.d/02-storage-schema.sql
66

77
# Build time defaults
8-
ARG build_POSTGRES_DB=postgres
9-
ARG build_POSTGRES_USER=postgres
10-
ARG build_POSTGRES_PASSWORD=postgres
11-
ARG build_POSTGRES_PORT=5432
128

13-
# Run time values
14-
ENV POSTGRES_DB=$build_POSTGRES_DB
15-
ENV POSTGRES_USER=$build_POSTGRES_USER
16-
ENV POSTGRES_PASSWORD=$build_POSTGRES_PASSWORD
17-
ENV POSTGRES_PORT=$build_POSTGRES_PORT
189

1910
EXPOSE 5432

infra/postgres/storage-schema.sql

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ alter default privileges in schema storage grant all on tables to postgres, anon
55
alter default privileges in schema storage grant all on functions to postgres, anon, authenticated, service_role;
66
alter default privileges in schema storage grant all on sequences to postgres, anon, authenticated, service_role;
77

8-
DROP TABLE IF EXISTS "storage"."buckets";
98
CREATE TABLE "storage"."buckets" (
109
"id" text not NULL,
1110
"name" text NOT NULL,
@@ -17,7 +16,6 @@ CREATE TABLE "storage"."buckets" (
1716
);
1817
CREATE UNIQUE INDEX "bname" ON "storage"."buckets" USING BTREE ("name");
1918

20-
DROP TABLE IF EXISTS "storage"."objects";
2119
CREATE TABLE "storage"."objects" (
2220
"id" uuid NOT NULL DEFAULT extensions.uuid_generate_v4(),
2321
"bucket_id" text,

infra/storage/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
FROM supabase/storage-api:v1.8.2
1+
FROM supabase/storage-api:v1.19.1
22

33
RUN apk add curl --no-cache

src/lib/types.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,18 @@ export interface SearchOptions {
101101
search?: string
102102
}
103103

104+
export interface SearchV2Options {
105+
limit?: number
106+
prefix?: string
107+
cursor?: string
108+
with_delimiter?: boolean
109+
}
110+
111+
export interface SearchV2Result {
112+
folders: { name: string }[]
113+
objects: FileObject[]
114+
}
115+
104116
export interface FetchParameters {
105117
/**
106118
* Pass in an AbortController's signal to cancel the request.

src/packages/StorageFileApi.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import {
1010
DestinationOptions,
1111
FileObjectV2,
1212
Camelize,
13+
SearchV2Options,
14+
SearchV2Result,
1315
} from '../lib/types'
1416

1517
const DEFAULT_SEARCH_OPTIONS = {
@@ -771,6 +773,43 @@ export default class StorageFileApi {
771773
}
772774
}
773775

776+
/**
777+
* @experimental this method signature might change in the future
778+
* @param options search options
779+
* @param parameters
780+
*/
781+
async listV2(
782+
options?: SearchV2Options,
783+
parameters?: FetchParameters
784+
): Promise<
785+
| {
786+
data: SearchV2Result[]
787+
error: null
788+
}
789+
| {
790+
data: null
791+
error: StorageError
792+
}
793+
> {
794+
try {
795+
const body = { ...options }
796+
const data = await post(
797+
this.fetch,
798+
`${this.url}/object/list-v2/${this.bucketId}`,
799+
body,
800+
{ headers: this.headers },
801+
parameters
802+
)
803+
return { data, error: null }
804+
} catch (error) {
805+
if (isStorageError(error)) {
806+
return { data: null, error }
807+
}
808+
809+
throw error
810+
}
811+
}
812+
774813
protected encodeMetadata(metadata: Record<string, any>) {
775814
return JSON.stringify(metadata)
776815
}

test/storageFileApi.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,22 @@ describe('Object API', () => {
378378
])
379379
})
380380

381+
test('list objects V2', async () => {
382+
await storage.from(bucketName).upload(uploadPath, file)
383+
const res = await storage.from(bucketName).listV2({
384+
prefix: 'testpath',
385+
})
386+
387+
expect(res.error).toBeNull()
388+
expect(res.data).toEqual(
389+
expect.objectContaining({
390+
hasNext: false,
391+
folders: [],
392+
objects: expect.arrayContaining([expect.objectContaining({ name: uploadPath })]),
393+
})
394+
)
395+
})
396+
381397
test('move object to different path', async () => {
382398
const newPath = `testpath/file-moved-${Date.now()}.txt`
383399
await storage.from(bucketName).upload(uploadPath, file)

0 commit comments

Comments
 (0)