Skip to content

Commit

Permalink
loosen the getUrl() type checks
Browse files Browse the repository at this point in the history
  • Loading branch information
ganigeorgiev committed Aug 28, 2023
1 parent 78bf16c commit fa26b1c
Show file tree
Hide file tree
Showing 17 changed files with 31 additions and 22 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.17.3-WIP

- Loosen the type check when calling `pb.files.getUrl(user, filename)` to allow passing the `pb.authStore.model` without type assertion.


## 0.17.2

- Fixed mulitple File/Blob array values not transformed properly to their FormData equivalent when an object syntax is used.
Expand Down
4 changes: 2 additions & 2 deletions dist/pocketbase.cjs.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -841,9 +841,9 @@ declare class FileService extends BaseService {
/**
* Builds and returns an absolute record file url for the provided filename.
*/
getUrl(record: Pick<{
getUrl(record: {
[key: string]: any;
}, "id" | "collectionId" | "collectionName">, filename: string, queryParams?: FileOptions): string;
}, filename: string, queryParams?: FileOptions): string;
/**
* Requests a new private file access token for the current auth model (admin or record).
*/
Expand Down
2 changes: 1 addition & 1 deletion dist/pocketbase.cjs.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/pocketbase.cjs.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/pocketbase.es.d.mts
Original file line number Diff line number Diff line change
Expand Up @@ -862,9 +862,9 @@ declare class FileService extends BaseService {
/**
* Builds and returns an absolute record file url for the provided filename.
*/
getUrl(record: Pick<{
getUrl(record: {
[key: string]: any;
}, "id" | "collectionId" | "collectionName">, filename: string, queryParams?: FileOptions): string;
}, filename: string, queryParams?: FileOptions): string;
/**
* Requests a new private file access token for the current auth model (admin or record).
*/
Expand Down
4 changes: 2 additions & 2 deletions dist/pocketbase.es.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -862,9 +862,9 @@ declare class FileService extends BaseService {
/**
* Builds and returns an absolute record file url for the provided filename.
*/
getUrl(record: Pick<{
getUrl(record: {
[key: string]: any;
}, "id" | "collectionId" | "collectionName">, filename: string, queryParams?: FileOptions): string;
}, filename: string, queryParams?: FileOptions): string;
/**
* Requests a new private file access token for the current auth model (admin or record).
*/
Expand Down
2 changes: 1 addition & 1 deletion dist/pocketbase.es.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/pocketbase.es.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/pocketbase.es.mjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/pocketbase.es.mjs.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/pocketbase.iife.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -841,9 +841,9 @@ declare class FileService extends BaseService {
/**
* Builds and returns an absolute record file url for the provided filename.
*/
getUrl(record: Pick<{
getUrl(record: {
[key: string]: any;
}, "id" | "collectionId" | "collectionName">, filename: string, queryParams?: FileOptions): string;
}, filename: string, queryParams?: FileOptions): string;
/**
* Requests a new private file access token for the current auth model (admin or record).
*/
Expand Down
2 changes: 1 addition & 1 deletion dist/pocketbase.iife.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/pocketbase.iife.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/pocketbase.umd.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -841,9 +841,9 @@ declare class FileService extends BaseService {
/**
* Builds and returns an absolute record file url for the provided filename.
*/
getUrl(record: Pick<{
getUrl(record: {
[key: string]: any;
}, "id" | "collectionId" | "collectionName">, filename: string, queryParams?: FileOptions): string;
}, filename: string, queryParams?: FileOptions): string;
/**
* Requests a new private file access token for the current auth model (admin or record).
*/
Expand Down
2 changes: 1 addition & 1 deletion dist/pocketbase.umd.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/pocketbase.umd.js.map

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions src/services/FileService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ export class FileService extends BaseService {
* Builds and returns an absolute record file url for the provided filename.
*/
getUrl(
record: Pick<{[key:string]:any}, 'id' | 'collectionId' | 'collectionName'>,
record: {[key:string]:any},
filename: string,
queryParams: FileOptions = {}
): string {
if (!filename || !record?.id) {
if (
!filename ||
!record?.id ||
!(record?.collectionId || record?.collectionName)
) {
return '';
}

Expand Down

0 comments on commit fa26b1c

Please sign in to comment.