Skip to content

Commit 86647d0

Browse files
committed
updated the examples for beforeSend/afterSend hooks
1 parent 6c36ac7 commit 86647d0

12 files changed

+93
-41
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,8 @@ To accomplish this, the SDK provides 2 function hooks:
404404

405405
return { url, options };
406406
};
407+
408+
// use the created client as usual...
407409
```
408410
409411
- `afterSend` - triggered after successfully sending the `fetch` request, allowing you to inspect/modify the response object and its parsed data.
@@ -419,6 +421,8 @@ To accomplish this, the SDK provides 2 function hooks:
419421
"additionalField": 123,
420422
});
421423
};
424+
425+
// use the created client as usual...
422426
```
423427
424428
### SSR integration

dist/pocketbase.cjs.d.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,13 +1202,17 @@ declare class Client {
12021202
*
12031203
* Example:
12041204
* ```js
1205-
* client.beforeSend = function (url, options) {
1205+
* const pb = new PocketBase("https://example.com")
1206+
*
1207+
* pb.beforeSend = function (url, options) {
12061208
* options.headers = Object.assign({}, options.headers, {
12071209
* 'X-Custom-Header': 'example',
1208-
* });
1210+
* })
12091211
*
12101212
* return { url, options }
1211-
* };
1213+
* }
1214+
*
1215+
* // use the created client as usual...
12121216
* ```
12131217
*/
12141218
beforeSend?: (url: string, options: SendOptions) => BeforeSendResult | Promise<BeforeSendResult>;
@@ -1220,17 +1224,21 @@ declare class Client {
12201224
*
12211225
* Example:
12221226
* ```js
1223-
* client.afterSend = function (response, data, options) {
1227+
* const pb = new PocketBase("https://example.com")
1228+
*
1229+
* pb.afterSend = function (response, data, options) {
12241230
* if (response.status != 200) {
12251231
* throw new ClientResponseError({
12261232
* url: response.url,
12271233
* status: response.status,
12281234
* response: { ... },
1229-
* });
1235+
* })
12301236
* }
12311237
*
12321238
* return data;
1233-
* };
1239+
* }
1240+
*
1241+
* // use the created client as usual...
12341242
* ```
12351243
*/
12361244
afterSend?: ((response: Response, data: any) => any) & ((response: Response, data: any, options: SendOptions) => any);

dist/pocketbase.cjs.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/pocketbase.es.d.mts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,13 +1245,17 @@ declare class Client {
12451245
*
12461246
* Example:
12471247
* ```js
1248-
* client.beforeSend = function (url, options) {
1248+
* const pb = new PocketBase("https://example.com")
1249+
*
1250+
* pb.beforeSend = function (url, options) {
12491251
* options.headers = Object.assign({}, options.headers, {
12501252
* 'X-Custom-Header': 'example',
1251-
* });
1253+
* })
12521254
*
12531255
* return { url, options }
1254-
* };
1256+
* }
1257+
*
1258+
* // use the created client as usual...
12551259
* ```
12561260
*/
12571261
beforeSend?: (url: string, options: SendOptions) => BeforeSendResult | Promise<BeforeSendResult>;
@@ -1263,17 +1267,21 @@ declare class Client {
12631267
*
12641268
* Example:
12651269
* ```js
1266-
* client.afterSend = function (response, data, options) {
1270+
* const pb = new PocketBase("https://example.com")
1271+
*
1272+
* pb.afterSend = function (response, data, options) {
12671273
* if (response.status != 200) {
12681274
* throw new ClientResponseError({
12691275
* url: response.url,
12701276
* status: response.status,
12711277
* response: { ... },
1272-
* });
1278+
* })
12731279
* }
12741280
*
12751281
* return data;
1276-
* };
1282+
* }
1283+
*
1284+
* // use the created client as usual...
12771285
* ```
12781286
*/
12791287
afterSend?: ((response: Response, data: any) => any) & ((response: Response, data: any, options: SendOptions) => any);

dist/pocketbase.es.d.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,13 +1245,17 @@ declare class Client {
12451245
*
12461246
* Example:
12471247
* ```js
1248-
* client.beforeSend = function (url, options) {
1248+
* const pb = new PocketBase("https://example.com")
1249+
*
1250+
* pb.beforeSend = function (url, options) {
12491251
* options.headers = Object.assign({}, options.headers, {
12501252
* 'X-Custom-Header': 'example',
1251-
* });
1253+
* })
12521254
*
12531255
* return { url, options }
1254-
* };
1256+
* }
1257+
*
1258+
* // use the created client as usual...
12551259
* ```
12561260
*/
12571261
beforeSend?: (url: string, options: SendOptions) => BeforeSendResult | Promise<BeforeSendResult>;
@@ -1263,17 +1267,21 @@ declare class Client {
12631267
*
12641268
* Example:
12651269
* ```js
1266-
* client.afterSend = function (response, data, options) {
1270+
* const pb = new PocketBase("https://example.com")
1271+
*
1272+
* pb.afterSend = function (response, data, options) {
12671273
* if (response.status != 200) {
12681274
* throw new ClientResponseError({
12691275
* url: response.url,
12701276
* status: response.status,
12711277
* response: { ... },
1272-
* });
1278+
* })
12731279
* }
12741280
*
12751281
* return data;
1276-
* };
1282+
* }
1283+
*
1284+
* // use the created client as usual...
12771285
* ```
12781286
*/
12791287
afterSend?: ((response: Response, data: any) => any) & ((response: Response, data: any, options: SendOptions) => any);

dist/pocketbase.es.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/pocketbase.es.mjs.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/pocketbase.iife.d.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,13 +1202,17 @@ declare class Client {
12021202
*
12031203
* Example:
12041204
* ```js
1205-
* client.beforeSend = function (url, options) {
1205+
* const pb = new PocketBase("https://example.com")
1206+
*
1207+
* pb.beforeSend = function (url, options) {
12061208
* options.headers = Object.assign({}, options.headers, {
12071209
* 'X-Custom-Header': 'example',
1208-
* });
1210+
* })
12091211
*
12101212
* return { url, options }
1211-
* };
1213+
* }
1214+
*
1215+
* // use the created client as usual...
12121216
* ```
12131217
*/
12141218
beforeSend?: (url: string, options: SendOptions) => BeforeSendResult | Promise<BeforeSendResult>;
@@ -1220,17 +1224,21 @@ declare class Client {
12201224
*
12211225
* Example:
12221226
* ```js
1223-
* client.afterSend = function (response, data, options) {
1227+
* const pb = new PocketBase("https://example.com")
1228+
*
1229+
* pb.afterSend = function (response, data, options) {
12241230
* if (response.status != 200) {
12251231
* throw new ClientResponseError({
12261232
* url: response.url,
12271233
* status: response.status,
12281234
* response: { ... },
1229-
* });
1235+
* })
12301236
* }
12311237
*
12321238
* return data;
1233-
* };
1239+
* }
1240+
*
1241+
* // use the created client as usual...
12341242
* ```
12351243
*/
12361244
afterSend?: ((response: Response, data: any) => any) & ((response: Response, data: any, options: SendOptions) => any);

dist/pocketbase.iife.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/pocketbase.umd.d.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,13 +1202,17 @@ declare class Client {
12021202
*
12031203
* Example:
12041204
* ```js
1205-
* client.beforeSend = function (url, options) {
1205+
* const pb = new PocketBase("https://example.com")
1206+
*
1207+
* pb.beforeSend = function (url, options) {
12061208
* options.headers = Object.assign({}, options.headers, {
12071209
* 'X-Custom-Header': 'example',
1208-
* });
1210+
* })
12091211
*
12101212
* return { url, options }
1211-
* };
1213+
* }
1214+
*
1215+
* // use the created client as usual...
12121216
* ```
12131217
*/
12141218
beforeSend?: (url: string, options: SendOptions) => BeforeSendResult | Promise<BeforeSendResult>;
@@ -1220,17 +1224,21 @@ declare class Client {
12201224
*
12211225
* Example:
12221226
* ```js
1223-
* client.afterSend = function (response, data, options) {
1227+
* const pb = new PocketBase("https://example.com")
1228+
*
1229+
* pb.afterSend = function (response, data, options) {
12241230
* if (response.status != 200) {
12251231
* throw new ClientResponseError({
12261232
* url: response.url,
12271233
* status: response.status,
12281234
* response: { ... },
1229-
* });
1235+
* })
12301236
* }
12311237
*
12321238
* return data;
1233-
* };
1239+
* }
1240+
*
1241+
* // use the created client as usual...
12341242
* ```
12351243
*/
12361244
afterSend?: ((response: Response, data: any) => any) & ((response: Response, data: any, options: SendOptions) => any);

0 commit comments

Comments
 (0)