Skip to content

Commit

Permalink
[#101] added query parameter types
Browse files Browse the repository at this point in the history
  • Loading branch information
ganigeorgiev committed Dec 8, 2022
1 parent ac38543 commit e860e34
Show file tree
Hide file tree
Showing 26 changed files with 612 additions and 321 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
## (WIP) 0.8.4

- Added types for the action query parameters ([#102](https://github.com/pocketbase/js-sdk/pull/102); thanks @sewera).
```js
BaseQueryParams
ListQueryParams
RecordQueryParams
RecordListQueryParams
LogStatsQueryParams
FileQueryParams
```


## 0.8.3

- Renamed the declaration file extension from `.d.ts` to `.d.mts` to prevent type resolution issues ([#92](https://github.com/pocketbase/js-sdk/issues/92)).


## 0.8.2

- Allowed catching the initial realtime connect error as part of the `subscribe()` Promise resolution.
Expand Down
162 changes: 102 additions & 60 deletions dist/pocketbase.cjs.d.ts

Large diffs are not rendered by default.

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.

164 changes: 103 additions & 61 deletions dist/pocketbase.es.d.mts

Large diffs are not rendered by default.

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.

162 changes: 102 additions & 60 deletions dist/pocketbase.iife.d.ts

Large diffs are not rendered by default.

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.

162 changes: 102 additions & 60 deletions dist/pocketbase.umd.d.ts

Large diffs are not rendered by default.

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.

3 changes: 2 additions & 1 deletion src/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import CollectionService from '@/services/CollectionService';
import LogService from '@/services/LogService';
import RealtimeService from '@/services/RealtimeService';
import Record from '@/models/Record';
import { FileQueryParams } from '@/services/utils/QueryParams';

/**
* PocketBase JS Client.
Expand Down Expand Up @@ -273,7 +274,7 @@ export default class Client {
/**
* Builds and returns an absolute record file url for the provided filename.
*/
getFileUrl(record: Record, filename: string, queryParams = {}): string {
getFileUrl(record: Record, filename: string, queryParams: FileQueryParams = {}): string {
const parts = [];
parts.push("api")
parts.push("files")
Expand Down
14 changes: 14 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ import {
RecordSubscription,
} from '@/services/RecordService';
import { UnsubscribeFunc } from '@/services/RealtimeService';
import {
BaseQueryParams,
ListQueryParams,
RecordQueryParams,
RecordListQueryParams,
LogStatsQueryParams,
FileQueryParams,
} from '@/services/utils/QueryParams';

export {
ClientResponseError,
Expand All @@ -41,6 +49,12 @@ export {
RecordSubscription,
OnStoreChangeFunc,
UnsubscribeFunc,
BaseQueryParams,
ListQueryParams,
RecordQueryParams,
RecordListQueryParams,
LogStatsQueryParams,
FileQueryParams,
};

export default Client;
2 changes: 1 addition & 1 deletion src/models/LogRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default class LogRequest extends BaseModel {
load(data: { [key: string]: any }) {
super.load(data);

// fallback to the ip field for backward compatability
// fallback to the ip field for backward compatibility
data.remoteIp = data.remoteIp || data.ip;

this.url = typeof data.url === 'string' ? data.url : '';
Expand Down
26 changes: 14 additions & 12 deletions src/services/AdminService.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import CrudService from '@/services/utils/CrudService';
import Admin from '@/models/Admin';
import Admin from '@/models/Admin';
import CrudService from '@/services/utils/CrudService';
import { BaseQueryParams } from '@/services/utils/QueryParams';

export type AdminAuthResponse = {
[key: string]: any,
token: string,
admin: Admin,
export interface AdminAuthResponse {
[key: string]: any;

token: string;
admin: Admin;
}

export default class AdminService extends CrudService<Admin> {
Expand Down Expand Up @@ -32,7 +34,7 @@ export default class AdminService extends CrudService<Admin> {
* If the current `client.authStore.model` matches with the updated id, then
* on success the `client.authStore.model` will be updated with the result.
*/
update<T = Admin>(id: string, bodyParams = {}, queryParams = {}): Promise<T> {
update<T = Admin>(id: string, bodyParams = {}, queryParams: BaseQueryParams = {}): Promise<T> {
return super.update<Admin>(id, bodyParams, queryParams).then((item) => {
// update the store state if the updated item id matches with the stored model
if (
Expand All @@ -53,7 +55,7 @@ export default class AdminService extends CrudService<Admin> {
* If the current `client.authStore.model` matches with the deleted id,
* then on success the `client.authStore` will be cleared.
*/
delete(id: string, queryParams = {}): Promise<boolean> {
delete(id: string, queryParams: BaseQueryParams = {}): Promise<boolean> {
return super.delete(id, queryParams).then((success) => {
// clear the store state if the deleted item id matches with the stored model
if (
Expand Down Expand Up @@ -99,7 +101,7 @@ export default class AdminService extends CrudService<Admin> {
email: string,
password: string,
bodyParams = {},
queryParams = {},
queryParams: BaseQueryParams = {},
): Promise<AdminAuthResponse> {
bodyParams = Object.assign({
'identity': email,
Expand All @@ -122,7 +124,7 @@ export default class AdminService extends CrudService<Admin> {
*
* On success this method automatically updates the client's AuthStore data.
*/
authRefresh(bodyParams = {}, queryParams = {}): Promise<AdminAuthResponse> {
authRefresh(bodyParams = {}, queryParams: BaseQueryParams = {}): Promise<AdminAuthResponse> {
return this.client.send(this.baseCrudPath + '/auth-refresh', {
'method': 'POST',
'params': queryParams,
Expand All @@ -136,7 +138,7 @@ export default class AdminService extends CrudService<Admin> {
requestPasswordReset(
email: string,
bodyParams = {},
queryParams = {},
queryParams: BaseQueryParams = {},
): Promise<boolean> {
bodyParams = Object.assign({
'email': email,
Expand All @@ -157,7 +159,7 @@ export default class AdminService extends CrudService<Admin> {
password: string,
passwordConfirm: string,
bodyParams = {},
queryParams = {},
queryParams: BaseQueryParams = {},
): Promise<boolean> {
bodyParams = Object.assign({
'token': passwordResetToken,
Expand Down
11 changes: 8 additions & 3 deletions src/services/CollectionService.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import CrudService from '@/services/utils/CrudService';
import Collection from '@/models/Collection';
import Collection from '@/models/Collection';
import CrudService from '@/services/utils/CrudService';
import { BaseQueryParams } from '@/services/utils/QueryParams';

export default class CollectionService extends CrudService<Collection> {
/**
Expand All @@ -23,7 +24,11 @@ export default class CollectionService extends CrudService<Collection> {
* that are not present in the imported configuration, WILL BE DELETED
* (including their related records data)!
*/
async import(collections: Array<Collection>, deleteMissing: boolean = false, queryParams = {}): Promise<true> {
async import(
collections: Array<Collection>,
deleteMissing: boolean = false,
queryParams: BaseQueryParams = {}
): Promise<true> {
return this.client.send(this.baseCrudPath + '/import', {
'method': 'PUT',
'params': queryParams,
Expand Down
17 changes: 11 additions & 6 deletions src/services/LogService.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
import LogRequest from '@/models/LogRequest';
import ListResult from '@/models/utils/ListResult';
import BaseService from '@/services/utils/BaseService';
import {
BaseQueryParams,
ListQueryParams,
LogStatsQueryParams,
} from '@/services/utils/QueryParams';

export type HourlyStats = {
total: number,
date: string,
export interface HourlyStats {
total: number;
date: string;
}

export default class LogService extends BaseService {
/**
* Returns paginated logged requests list.
*/
getRequestsList(page = 1, perPage = 30, queryParams = {}): Promise<ListResult<LogRequest>> {
getRequestsList(page = 1, perPage = 30, queryParams: ListQueryParams = {}): Promise<ListResult<LogRequest>> {
queryParams = Object.assign({
'page': page,
'perPage': perPage,
Expand Down Expand Up @@ -42,7 +47,7 @@ export default class LogService extends BaseService {
/**
* Returns a single logged request by its id.
*/
getRequest(id: string, queryParams = {}): Promise<LogRequest> {
getRequest(id: string, queryParams: BaseQueryParams = {}): Promise<LogRequest> {
return this.client.send('/api/logs/requests/' + encodeURIComponent(id), {
'method': 'GET',
'params': queryParams
Expand All @@ -52,7 +57,7 @@ export default class LogService extends BaseService {
/**
* Returns request logs statistics.
*/
getRequestsStats(queryParams = {}): Promise<Array<HourlyStats>> {
getRequestsStats(queryParams: LogStatsQueryParams = {}): Promise<Array<HourlyStats>> {
return this.client.send('/api/logs/requests/stats', {
'method': 'GET',
'params': queryParams
Expand Down
Loading

0 comments on commit e860e34

Please sign in to comment.