Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions packages/nativescript-supabase/supabase-storage/COMPATIBILITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# NativeScript Supabase Storage — Upstream Compatibility

This package is a fork of `@supabase/storage-js` with targeted overrides for NativeScript. The directory structure mirrors upstream (`lib/common/`, `packages/`) to simplify future syncs.

## What we change

### File uploads use native HTTP (`StorageFileApi`)

The `upload()`, `update()`, and `uploadToSignedUrl()` methods bypass the standard `fetch()`-based upload path. Instead, they use `@klippa/nativescript-http`:

- **`HTTPFormData` / `HTTPFormDataEntry`** replace the browser `FormData` API.
- **Platform-specific file handling:** when `fileBody` is a `string` (file path), it is resolved natively:
- Android: `new java.io.File(fileBody)`
- iOS: `NSData.dataWithContentsOfURL(NSURL.URLWithString(fileBody))`
- **`Http.request()`** is called directly instead of going through the shared `post()`/`put()` fetch helpers.

All other methods (download, list, move, copy, signed URLs, info, exists, bucket operations, vectors, analytics) use the standard `fetch()`-based code path unchanged.

### `resolveResponse` / `resolveFetch` (helpers)

- `resolveResponse` returns the global `Response` directly — the upstream `cross-fetch` dynamic import is removed since NativeScript provides `Response` globally.
- `resolveFetch` has `@ts-ignore` annotations on the spread calls to suppress a TypeScript tuple-type error that only appears under strict NativeScript tsconfig settings.

## What we do NOT change

Everything else is a 1:1 copy of upstream, including:

- `BaseApiClient` (handleOperation, throwOnError, setHeader)
- Error classes and namespace system (storage / vectors)
- Fetch helpers (get, post, put, head, remove, vectorsApi)
- Header normalization
- `StorageBucketApi` (with useNewHostname, ListBucketOptions, BucketType support)
- Non-upload `StorageFileApi` methods (download, info, exists, list, listV2, createSignedUrl, createSignedUrls, getPublicUrl, move, copy, remove)
- `BlobDownloadBuilder` / `StreamDownloadBuilder`
- `StorageAnalyticsClient` (Iceberg)
- `StorageVectorsClient` and all vector API classes
- All types

## Syncing with upstream

When updating from a new version of `@supabase/storage-js`:

1. Diff the upstream `src/` tree against our `lib/` + `packages/` tree.
2. Apply upstream changes to all files **except** the two upload methods in `packages/StorageFileApi.ts` and the two helpers noted above.
3. For the upload methods, merge any new options/fields (e.g. `metadata`, `headers`) into the NativeScript-specific code path while keeping the `Http.request()` / `HTTPFormData` machinery.
4. Run `npx nx run nativescript-supabase:build` to verify.
32 changes: 22 additions & 10 deletions packages/nativescript-supabase/supabase-storage/StorageClient.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
import StorageFileApi from './lib/StorageFileApi';
import StorageBucketApi from './lib/StorageBucketApi';
import { Fetch } from './lib/fetch';
import StorageFileApi from './packages/StorageFileApi';
import StorageBucketApi from './packages/StorageBucketApi';
import StorageAnalyticsClient from './packages/StorageAnalyticsClient';
import { Fetch } from './lib/common/fetch';
import { StorageVectorsClient } from './packages/StorageVectorsClient';

export interface StorageClientOptions {
useNewHostname?: boolean;
}

export class StorageClient extends StorageBucketApi {
constructor(url: string, headers: { [key: string]: string } = {}, fetch?: Fetch) {
super(url, headers, fetch);
constructor(url: string, headers: { [key: string]: string } = {}, fetch?: Fetch, opts?: StorageClientOptions) {
super(url, headers, fetch, opts);
}

/**
* Perform file operation in a bucket.
*
* @param id The bucket id to operate on.
*/
from(id: string): StorageFileApi {
return new StorageFileApi(this.url, this.headers, id, this.fetch);
}

get vectors(): StorageVectorsClient {
return new StorageVectorsClient(this.url + '/vector', {
headers: this.headers,
fetch: this.fetch,
});
}

get analytics(): StorageAnalyticsClient {
return new StorageAnalyticsClient(this.url + '/iceberg', this.headers, this.fetch);
}
}
16 changes: 14 additions & 2 deletions packages/nativescript-supabase/supabase-storage/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
export { StorageClient as StorageClient } from './StorageClient';
export { StorageClient } from './StorageClient';
export type { StorageClientOptions } from './StorageClient';
export { default as StorageAnalyticsClient } from './packages/StorageAnalyticsClient';

// Vector Storage
export { StorageVectorsClient, VectorBucketScope, VectorIndexScope } from './packages/StorageVectorsClient';
export type { StorageVectorsClientOptions } from './packages/StorageVectorsClient';
export { default as VectorBucketApi } from './packages/VectorBucketApi';
export { default as VectorDataApi } from './packages/VectorDataApi';
export { default as VectorIndexApi } from './packages/VectorIndexApi';
export type { CreateIndexOptions } from './packages/VectorIndexApi';

// Types and Errors
export * from './lib/types';
export * from './lib/errors';
export * from './lib/common/errors';

This file was deleted.

Loading
Loading