Skip to content

Commit

Permalink
added BaseModel helper aliases and preparations for the u upcoming Po…
Browse files Browse the repository at this point in the history
…cketBase v0.14.0 release
  • Loading branch information
ganigeorgiev committed Mar 24, 2023
1 parent 31d5931 commit b9a3ca1
Show file tree
Hide file tree
Showing 26 changed files with 373 additions and 116 deletions.
16 changes: 14 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
## 0.13.0-rc
## 0.13.0

- Added `Collection.indexes` prop for the new indexes support that comes with PocketBase v0.14.0.
- Aliased all `BaseModel` helpers with `$` equivalent to avoid conflicts with the dynamic record props ([#169](https://github.com/pocketbase/js-sdk/issues/169)).
```js
isNew -> $isNew
load(data) -> $load(data)
clone() -> $clone()
export() -> $export()
// ...
```
_For backward compatibility, the old helpers will still continue to work if the record doesn't have a conflicting field name._
- Updated `pb.beforeSend` and `pb.afterSend` signatures to allow returning and awaiting an optional `Promise` ([#166](https://github.com/pocketbase/js-sdk/pull/166); thanks @Bobby-McBobface).
- Added `Collection.indexes` field for the new collection indexes support in the upcoming PocketBase v0.14.0.
- Added `pb.settings.generateAppleClientSecret()` for sending a request to generate Apple OAuth2 client secret in the upcoming PocketBase v0.14.0.
## 0.12.1
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,18 @@ Official JavaScript SDK (browser and node) for interacting with the [PocketBase

```html
<script src="/path/to/dist/pocketbase.umd.js"></script>
<script type="text/javascript">
const pb = new PocketBase("https://example.com")
...
</script>
```

_OR if you are using ES modules:_
```html
<script type="module">
import PocketBase from '/path/to/dist/pocketbase.es.mjs'
const pb = new PocketBase("https://example.com")
...
</script>
```
Expand Down Expand Up @@ -806,6 +812,9 @@ const pb = new PocketBase(baseUrl = '/', authStore = LocalAuthStore);
// Sends a test email (verification, password-reset, email-change).
🔐 pb.settings.testEmail(toEmail, template, queryParams = {});
// Generates a new Apple OAuth2 client secret.
🔐 pb.settings.generateAppleClientSecret(clientId, teamId, keyId, privateKey, duration, bodyParams = {}, queryParams = {});
```

---
Expand Down
71 changes: 52 additions & 19 deletions dist/pocketbase.cjs.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,45 @@ declare abstract class BaseModel {
[key: string]: any;
});
/**
* Loads `data` into the current model.
* Alias of this.$load(data).
*/
load(data: {
[key: string]: any;
}): void;
/**
* Returns whether the current loaded data represent a stored db record.
* Loads `data` into the current model.
*/
$load(data: {
[key: string]: any;
}): void;
/**
* Alias of this.$isNew.
*/
get isNew(): boolean;
/**
* Creates a deep clone of the current model.
* Returns whether the current loaded data represent a stored db record.
*/
get $isNew(): boolean;
/**
* Alias of this.clone().
*/
clone(): BaseModel;
/**
* Exports all model properties as a new plain object.
* Creates a deep clone of the current model.
*/
$clone(): BaseModel;
/**
* Alias of this.$export().
*/
export(): {
[key: string]: any;
};
/**
* Exports all model properties as a new plain object.
*/
$export(): {
[key: string]: any;
};
}
declare class Record extends BaseModel {
collectionId: string;
Expand All @@ -47,22 +67,22 @@ declare class Record extends BaseModel {
/**
* @inheritdoc
*/
load(data: {
$load(data: {
[key: string]: any;
}): void;
/**
* Loads the provided expand items and recursively normalizes each
* item to a `Record|Array<Record>`.
*/
private loadExpand;
private _loadExpand;
}
declare class Admin extends BaseModel {
avatar: number;
email: string;
/**
* @inheritdoc
*/
load(data: {
$load(data: {
[key: string]: any;
}): void;
}
Expand Down Expand Up @@ -180,6 +200,9 @@ interface LogStatsQueryParams extends BaseQueryParams {
interface FileQueryParams extends BaseQueryParams {
thumb?: string;
}
interface appleClientSecret {
secret: string;
}
declare class SettingsService extends BaseService {
/**
* Fetch all available app settings.
Expand All @@ -206,6 +229,10 @@ declare class SettingsService extends BaseService {
* - email-change
*/
testEmail(toEmail: string, emailTemplate: string, queryParams?: BaseQueryParams): Promise<boolean>;
/**
* Generates a new Apple OAuth2 client secret.
*/
generateAppleClientSecret(clientId: string, teamId: string, keyId: string, privateKey: string, duration: number, bodyParams?: {}, queryParams?: BaseQueryParams): Promise<appleClientSecret>;
}
declare class ListResult<M = BaseModel> {
page: number;
Expand Down Expand Up @@ -386,7 +413,7 @@ declare class ExternalAuth extends BaseModel {
/**
* @inheritdoc
*/
load(data: {
$load(data: {
[key: string]: any;
}): void;
}
Expand Down Expand Up @@ -658,12 +685,6 @@ declare class SchemaField {
constructor(data?: {
[key: string]: any;
});
/**
* Loads `data` into the field.
*/
load(data: {
[key: string]: any;
}): void;
}
declare class Collection extends BaseModel {
name: string;
Expand All @@ -682,21 +703,33 @@ declare class Collection extends BaseModel {
/**
* @inheritdoc
*/
load(data: {
$load(data: {
[key: string]: any;
}): void;
/**
* Checks if the current model is "base" collection.
* @deprecated Please use $isBase instead.
*/
get isBase(): boolean;
/**
* Checks if the current model is "auth" collection.
* Checks if the current model is "base" collection.
*/
get $isBase(): boolean;
/**
* @deprecated Please use $isAuth instead.
*/
get isAuth(): boolean;
/**
* Checks if the current model is "view" collection.
* Checks if the current model is "auth" collection.
*/
get $isAuth(): boolean;
/**
* @deprecated Please use $isView instead.
*/
get isView(): boolean;
/**
* Checks if the current model is "view" collection.
*/
get $isView(): boolean;
}
declare class CollectionService extends CrudService<Collection> {
/**
Expand Down Expand Up @@ -733,7 +766,7 @@ declare class LogRequest extends BaseModel {
/**
* @inheritdoc
*/
load(data: {
$load(data: {
[key: string]: any;
}): void;
}
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.

71 changes: 52 additions & 19 deletions dist/pocketbase.es.d.mts
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,45 @@ declare abstract class BaseModel {
[key: string]: any;
});
/**
* Loads `data` into the current model.
* Alias of this.$load(data).
*/
load(data: {
[key: string]: any;
}): void;
/**
* Returns whether the current loaded data represent a stored db record.
* Loads `data` into the current model.
*/
$load(data: {
[key: string]: any;
}): void;
/**
* Alias of this.$isNew.
*/
get isNew(): boolean;
/**
* Creates a deep clone of the current model.
* Returns whether the current loaded data represent a stored db record.
*/
get $isNew(): boolean;
/**
* Alias of this.clone().
*/
clone(): BaseModel;
/**
* Exports all model properties as a new plain object.
* Creates a deep clone of the current model.
*/
$clone(): BaseModel;
/**
* Alias of this.$export().
*/
export(): {
[key: string]: any;
};
/**
* Exports all model properties as a new plain object.
*/
$export(): {
[key: string]: any;
};
}
declare class Record extends BaseModel {
collectionId: string;
Expand All @@ -47,22 +67,22 @@ declare class Record extends BaseModel {
/**
* @inheritdoc
*/
load(data: {
$load(data: {
[key: string]: any;
}): void;
/**
* Loads the provided expand items and recursively normalizes each
* item to a `Record|Array<Record>`.
*/
private loadExpand;
private _loadExpand;
}
declare class Admin extends BaseModel {
avatar: number;
email: string;
/**
* @inheritdoc
*/
load(data: {
$load(data: {
[key: string]: any;
}): void;
}
Expand Down Expand Up @@ -180,6 +200,9 @@ interface LogStatsQueryParams extends BaseQueryParams {
interface FileQueryParams extends BaseQueryParams {
thumb?: string;
}
interface appleClientSecret {
secret: string;
}
declare class SettingsService extends BaseService {
/**
* Fetch all available app settings.
Expand All @@ -206,6 +229,10 @@ declare class SettingsService extends BaseService {
* - email-change
*/
testEmail(toEmail: string, emailTemplate: string, queryParams?: BaseQueryParams): Promise<boolean>;
/**
* Generates a new Apple OAuth2 client secret.
*/
generateAppleClientSecret(clientId: string, teamId: string, keyId: string, privateKey: string, duration: number, bodyParams?: {}, queryParams?: BaseQueryParams): Promise<appleClientSecret>;
}
declare class ListResult<M = BaseModel> {
page: number;
Expand Down Expand Up @@ -386,7 +413,7 @@ declare class ExternalAuth extends BaseModel {
/**
* @inheritdoc
*/
load(data: {
$load(data: {
[key: string]: any;
}): void;
}
Expand Down Expand Up @@ -658,12 +685,6 @@ declare class SchemaField {
constructor(data?: {
[key: string]: any;
});
/**
* Loads `data` into the field.
*/
load(data: {
[key: string]: any;
}): void;
}
declare class Collection extends BaseModel {
name: string;
Expand All @@ -682,21 +703,33 @@ declare class Collection extends BaseModel {
/**
* @inheritdoc
*/
load(data: {
$load(data: {
[key: string]: any;
}): void;
/**
* Checks if the current model is "base" collection.
* @deprecated Please use $isBase instead.
*/
get isBase(): boolean;
/**
* Checks if the current model is "auth" collection.
* Checks if the current model is "base" collection.
*/
get $isBase(): boolean;
/**
* @deprecated Please use $isAuth instead.
*/
get isAuth(): boolean;
/**
* Checks if the current model is "view" collection.
* Checks if the current model is "auth" collection.
*/
get $isAuth(): boolean;
/**
* @deprecated Please use $isView instead.
*/
get isView(): boolean;
/**
* Checks if the current model is "view" collection.
*/
get $isView(): boolean;
}
declare class CollectionService extends CrudService<Collection> {
/**
Expand Down Expand Up @@ -733,7 +766,7 @@ declare class LogRequest extends BaseModel {
/**
* @inheritdoc
*/
load(data: {
$load(data: {
[key: string]: any;
}): void;
}
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.

Loading

0 comments on commit b9a3ca1

Please sign in to comment.