Skip to content
This repository was archived by the owner on Jan 23, 2026. It is now read-only.

Commit e7941ca

Browse files
committed
feat: list-v2 endpoint
1 parent 6bf02b9 commit e7941ca

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
@@ -97,6 +97,18 @@ export interface SearchOptions {
9797
search?: string
9898
}
9999

100+
export interface SearchV2Options {
101+
limit?: number
102+
prefix?: string
103+
cursor?: string
104+
with_delimiter?: boolean
105+
}
106+
107+
export interface SearchV2Result {
108+
folders: { name: string }[]
109+
objects: FileObject[]
110+
}
111+
100112
export interface FetchParameters {
101113
/**
102114
* 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 = {
@@ -788,6 +790,43 @@ export default class StorageFileApi {
788790
}
789791
}
790792

793+
/**
794+
* @experimental this method signature might change in the future
795+
* @param options search options
796+
* @param parameters
797+
*/
798+
async listV2(
799+
options?: SearchV2Options,
800+
parameters?: FetchParameters
801+
): Promise<
802+
| {
803+
data: SearchV2Result[]
804+
error: null
805+
}
806+
| {
807+
data: null
808+
error: StorageError
809+
}
810+
> {
811+
try {
812+
const body = { ...options }
813+
const data = await post(
814+
this.fetch,
815+
`${this.url}/object/list-v2/${this.bucketId}`,
816+
body,
817+
{ headers: this.headers },
818+
parameters
819+
)
820+
return { data, error: null }
821+
} catch (error) {
822+
if (isStorageError(error)) {
823+
return { data: null, error }
824+
}
825+
826+
throw error
827+
}
828+
}
829+
791830
protected encodeMetadata(metadata: Record<string, any>) {
792831
return JSON.stringify(metadata)
793832
}

test/storageFileApi.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,22 @@ describe('Object API', () => {
319319
])
320320
})
321321

322+
test('list objects V2', async () => {
323+
await storage.from(bucketName).upload(uploadPath, file)
324+
const res = await storage.from(bucketName).listV2({
325+
prefix: 'testpath',
326+
})
327+
328+
expect(res.error).toBeNull()
329+
expect(res.data).toEqual(
330+
expect.objectContaining({
331+
hasNext: false,
332+
folders: [],
333+
objects: expect.arrayContaining([expect.objectContaining({ name: uploadPath })]),
334+
})
335+
)
336+
})
337+
322338
test('move object to different path', async () => {
323339
const newPath = `testpath/file-moved-${Date.now()}.txt`
324340
await storage.from(bucketName).upload(uploadPath, file)

0 commit comments

Comments
 (0)