Skip to content

Commit

Permalink
added experimental expand, filter, fields, custom query and headers p…
Browse files Browse the repository at this point in the history
…arameters support for the realtime subscriptions
  • Loading branch information
ganigeorgiev committed Oct 24, 2023
1 parent 03baa50 commit f99b697
Show file tree
Hide file tree
Showing 22 changed files with 243 additions and 243 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
## 0.20.0-rc

- Added experimental `expand`, `filter`, `fields`, custom query and headers parameters support for the realtime subscriptions.
```js
pb.collection("example").subscribe("*", (e) => {
...
}, { filter: "someField > 10" });
```
_This works only with PocketBase v0.20.0-rc._


## 0.19.0

- Added `pb.filter(rawExpr, params?)` helper to construct a filter string with placeholder parameters populated from an object.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,7 @@ const pb = new PocketBase(baseUrl = '/', authStore = LocalAuthStore);
//
// You can use the returned UnsubscribeFunc to remove a single registered subscription.
// If you want to remove all subscriptions related to the topic use unsubscribe(topic).
🔓 pb.collection(collectionIdOrName).subscribe(topic, callback);
🔓 pb.collection(collectionIdOrName).subscribe(topic, callback, options = {});

// Unsubscribe from all registered subscriptions to the specified topic ("*" or recordId).
// If topic is not set, then it will remove all registered collection subscriptions.
Expand Down Expand Up @@ -1011,7 +1011,7 @@ const pb = new PocketBase(baseUrl = '/', authStore = LocalAuthStore);
```js
// Initialize the realtime connection (if not already) and register the subscription listener.
🔓 pb.realtime.subscribe(topic, callback);
🔓 pb.realtime.subscribe(topic, callback, options = {});

// Unsubscribe from all subscription listeners with the specified topic.
🔓 pb.realtime.unsubscribe(topic?);
Expand Down
21 changes: 6 additions & 15 deletions dist/pocketbase.cjs.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ declare class RealtimeService extends BaseService {
clientId: string;
private eventSource;
private subscriptions;
private lastSentTopics;
private lastSentSubscriptions;
private connectTimeoutId;
private maxConnectTimeout;
private reconnectTimeoutId;
Expand All @@ -478,7 +478,7 @@ declare class RealtimeService extends BaseService {
* If the SSE connection is not started yet,
* this method will also initialize it.
*/
subscribe(topic: string, callback: (data: any) => void): Promise<UnsubscribeFunc>;
subscribe(topic: string, callback: (data: any) => void, options?: SendOptions): Promise<UnsubscribeFunc>;
/**
* Unsubscribe from all subscription listeners with the specified topic.
*
Expand All @@ -499,7 +499,7 @@ declare class RealtimeService extends BaseService {
* The related sse connection will be autoclosed if after the
* unsubscribe operation there are no active subscriptions left.
*/
unsubscribeByPrefix(topicPrefix: string): Promise<void>;
unsubscribeByPrefix(keyPrefix: string): Promise<void>;
/**
* Unsubscribe from all subscriptions matching the specified topic and listener function.
*
Expand All @@ -513,7 +513,8 @@ declare class RealtimeService extends BaseService {
private hasSubscriptionListeners;
private submitSubscriptions;
private getSubscriptionsCancelKey;
private getNonEmptySubscriptionTopics;
private getSubscriptionsByTopic;
private getNonEmptySubscriptionKeys;
private addAllSubscriptionListeners;
private removeAllSubscriptionListeners;
private connect;
Expand Down Expand Up @@ -587,16 +588,6 @@ declare class RecordService<M = RecordModel> extends CrudService<M> {
// ---------------------------------------------------------------
// Realtime handlers
// ---------------------------------------------------------------
/**
* @deprecated Use subscribe(recordId, callback) instead.
*
* Subscribe to the realtime changes of a single record in the collection.
*/
subscribeOne<T = M>(recordId: string, callback: (data: RecordSubscription<T>) => void): Promise<UnsubscribeFunc>;
/**
* @deprecated This form of subscribe is deprecated. Please use `subscribe("*", callback)`.
*/
subscribe<T = M>(callback: (data: RecordSubscription<T>) => void): Promise<UnsubscribeFunc>;
/**
* Subscribe to realtime changes to the specified topic ("*" or record id).
*
Expand All @@ -610,7 +601,7 @@ declare class RecordService<M = RecordModel> extends CrudService<M> {
* You can use the returned `UnsubscribeFunc` to remove only a single subscription.
* Or use `unsubscribe(topic)` if you want to remove all subscriptions attached to the topic.
*/
subscribe<T = M>(topic: string, callback: (data: RecordSubscription<T>) => void): Promise<UnsubscribeFunc>;
subscribe<T = M>(topic: string, callback: (data: RecordSubscription<T>) => void, options?: SendOptions): Promise<UnsubscribeFunc>;
/**
* Unsubscribe from all subscriptions of the specified topic
* ("*" or record id).
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.

25 changes: 9 additions & 16 deletions dist/pocketbase.es.d.mts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ interface AuthOptions extends CommonOptions {
*/
autoRefreshThreshold?: number;
}
// modifies in place the provided options by moving unknown send options as query parameters.
declare function normalizeUnknownQueryParams(options?: SendOptions): void;
interface appleClientSecret {
secret: string;
}
Expand Down Expand Up @@ -479,7 +481,7 @@ declare class RealtimeService extends BaseService {
clientId: string;
private eventSource;
private subscriptions;
private lastSentTopics;
private lastSentSubscriptions;
private connectTimeoutId;
private maxConnectTimeout;
private reconnectTimeoutId;
Expand All @@ -499,7 +501,7 @@ declare class RealtimeService extends BaseService {
* If the SSE connection is not started yet,
* this method will also initialize it.
*/
subscribe(topic: string, callback: (data: any) => void): Promise<UnsubscribeFunc>;
subscribe(topic: string, callback: (data: any) => void, options?: SendOptions): Promise<UnsubscribeFunc>;
/**
* Unsubscribe from all subscription listeners with the specified topic.
*
Expand All @@ -520,7 +522,7 @@ declare class RealtimeService extends BaseService {
* The related sse connection will be autoclosed if after the
* unsubscribe operation there are no active subscriptions left.
*/
unsubscribeByPrefix(topicPrefix: string): Promise<void>;
unsubscribeByPrefix(keyPrefix: string): Promise<void>;
/**
* Unsubscribe from all subscriptions matching the specified topic and listener function.
*
Expand All @@ -534,7 +536,8 @@ declare class RealtimeService extends BaseService {
private hasSubscriptionListeners;
private submitSubscriptions;
private getSubscriptionsCancelKey;
private getNonEmptySubscriptionTopics;
private getSubscriptionsByTopic;
private getNonEmptySubscriptionKeys;
private addAllSubscriptionListeners;
private removeAllSubscriptionListeners;
private connect;
Expand Down Expand Up @@ -608,16 +611,6 @@ declare class RecordService<M = RecordModel> extends CrudService<M> {
// ---------------------------------------------------------------
// Realtime handlers
// ---------------------------------------------------------------
/**
* @deprecated Use subscribe(recordId, callback) instead.
*
* Subscribe to the realtime changes of a single record in the collection.
*/
subscribeOne<T = M>(recordId: string, callback: (data: RecordSubscription<T>) => void): Promise<UnsubscribeFunc>;
/**
* @deprecated This form of subscribe is deprecated. Please use `subscribe("*", callback)`.
*/
subscribe<T = M>(callback: (data: RecordSubscription<T>) => void): Promise<UnsubscribeFunc>;
/**
* Subscribe to realtime changes to the specified topic ("*" or record id).
*
Expand All @@ -631,7 +624,7 @@ declare class RecordService<M = RecordModel> extends CrudService<M> {
* You can use the returned `UnsubscribeFunc` to remove only a single subscription.
* Or use `unsubscribe(topic)` if you want to remove all subscriptions attached to the topic.
*/
subscribe<T = M>(topic: string, callback: (data: RecordSubscription<T>) => void): Promise<UnsubscribeFunc>;
subscribe<T = M>(topic: string, callback: (data: RecordSubscription<T>) => void, options?: SendOptions): Promise<UnsubscribeFunc>;
/**
* Unsubscribe from all subscriptions of the specified topic
* ("*" or record id).
Expand Down Expand Up @@ -1292,4 +1285,4 @@ declare function getTokenPayload(token: string): {
* @param [expirationThreshold] Time in seconds that will be subtracted from the token `exp` property.
*/
declare function isTokenExpired(token: string, expirationThreshold?: number): boolean;
export { Client as default, BeforeSendResult, ClientResponseError, ListResult, BaseModel, AdminModel, SchemaField, CollectionModel, ExternalAuthModel, LogRequestModel, RecordModel, SendOptions, CommonOptions, ListOptions, FullListOptions, RecordOptions, RecordListOptions, RecordFullListOptions, LogStatsOptions, FileOptions, AuthOptions, CrudService, AdminAuthResponse, AdminService, CollectionService, HourlyStats, LogService, UnsubscribeFunc, RealtimeService, RecordAuthResponse, AuthProviderInfo, AuthMethodsList, RecordSubscription, OAuth2UrlCallback, OAuth2AuthConfig, RecordService, AuthModel, OnStoreChangeFunc, BaseAuthStore, LocalAuthStore, AsyncSaveFunc, AsyncClearFunc, AsyncAuthStore, getTokenPayload, isTokenExpired, ParseOptions, cookieParse, SerializeOptions, cookieSerialize };
export { Client as default, BeforeSendResult, ClientResponseError, ListResult, BaseModel, AdminModel, SchemaField, CollectionModel, ExternalAuthModel, LogRequestModel, RecordModel, SendOptions, CommonOptions, ListOptions, FullListOptions, RecordOptions, RecordListOptions, RecordFullListOptions, LogStatsOptions, FileOptions, AuthOptions, normalizeUnknownQueryParams, CrudService, AdminAuthResponse, AdminService, CollectionService, HourlyStats, LogService, UnsubscribeFunc, RealtimeService, RecordAuthResponse, AuthProviderInfo, AuthMethodsList, RecordSubscription, OAuth2UrlCallback, OAuth2AuthConfig, RecordService, AuthModel, OnStoreChangeFunc, BaseAuthStore, LocalAuthStore, AsyncSaveFunc, AsyncClearFunc, AsyncAuthStore, getTokenPayload, isTokenExpired, ParseOptions, cookieParse, SerializeOptions, cookieSerialize };
25 changes: 9 additions & 16 deletions dist/pocketbase.es.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ interface AuthOptions extends CommonOptions {
*/
autoRefreshThreshold?: number;
}
// modifies in place the provided options by moving unknown send options as query parameters.
declare function normalizeUnknownQueryParams(options?: SendOptions): void;
interface appleClientSecret {
secret: string;
}
Expand Down Expand Up @@ -479,7 +481,7 @@ declare class RealtimeService extends BaseService {
clientId: string;
private eventSource;
private subscriptions;
private lastSentTopics;
private lastSentSubscriptions;
private connectTimeoutId;
private maxConnectTimeout;
private reconnectTimeoutId;
Expand All @@ -499,7 +501,7 @@ declare class RealtimeService extends BaseService {
* If the SSE connection is not started yet,
* this method will also initialize it.
*/
subscribe(topic: string, callback: (data: any) => void): Promise<UnsubscribeFunc>;
subscribe(topic: string, callback: (data: any) => void, options?: SendOptions): Promise<UnsubscribeFunc>;
/**
* Unsubscribe from all subscription listeners with the specified topic.
*
Expand All @@ -520,7 +522,7 @@ declare class RealtimeService extends BaseService {
* The related sse connection will be autoclosed if after the
* unsubscribe operation there are no active subscriptions left.
*/
unsubscribeByPrefix(topicPrefix: string): Promise<void>;
unsubscribeByPrefix(keyPrefix: string): Promise<void>;
/**
* Unsubscribe from all subscriptions matching the specified topic and listener function.
*
Expand All @@ -534,7 +536,8 @@ declare class RealtimeService extends BaseService {
private hasSubscriptionListeners;
private submitSubscriptions;
private getSubscriptionsCancelKey;
private getNonEmptySubscriptionTopics;
private getSubscriptionsByTopic;
private getNonEmptySubscriptionKeys;
private addAllSubscriptionListeners;
private removeAllSubscriptionListeners;
private connect;
Expand Down Expand Up @@ -608,16 +611,6 @@ declare class RecordService<M = RecordModel> extends CrudService<M> {
// ---------------------------------------------------------------
// Realtime handlers
// ---------------------------------------------------------------
/**
* @deprecated Use subscribe(recordId, callback) instead.
*
* Subscribe to the realtime changes of a single record in the collection.
*/
subscribeOne<T = M>(recordId: string, callback: (data: RecordSubscription<T>) => void): Promise<UnsubscribeFunc>;
/**
* @deprecated This form of subscribe is deprecated. Please use `subscribe("*", callback)`.
*/
subscribe<T = M>(callback: (data: RecordSubscription<T>) => void): Promise<UnsubscribeFunc>;
/**
* Subscribe to realtime changes to the specified topic ("*" or record id).
*
Expand All @@ -631,7 +624,7 @@ declare class RecordService<M = RecordModel> extends CrudService<M> {
* You can use the returned `UnsubscribeFunc` to remove only a single subscription.
* Or use `unsubscribe(topic)` if you want to remove all subscriptions attached to the topic.
*/
subscribe<T = M>(topic: string, callback: (data: RecordSubscription<T>) => void): Promise<UnsubscribeFunc>;
subscribe<T = M>(topic: string, callback: (data: RecordSubscription<T>) => void, options?: SendOptions): Promise<UnsubscribeFunc>;
/**
* Unsubscribe from all subscriptions of the specified topic
* ("*" or record id).
Expand Down Expand Up @@ -1292,4 +1285,4 @@ declare function getTokenPayload(token: string): {
* @param [expirationThreshold] Time in seconds that will be subtracted from the token `exp` property.
*/
declare function isTokenExpired(token: string, expirationThreshold?: number): boolean;
export { Client as default, BeforeSendResult, ClientResponseError, ListResult, BaseModel, AdminModel, SchemaField, CollectionModel, ExternalAuthModel, LogRequestModel, RecordModel, SendOptions, CommonOptions, ListOptions, FullListOptions, RecordOptions, RecordListOptions, RecordFullListOptions, LogStatsOptions, FileOptions, AuthOptions, CrudService, AdminAuthResponse, AdminService, CollectionService, HourlyStats, LogService, UnsubscribeFunc, RealtimeService, RecordAuthResponse, AuthProviderInfo, AuthMethodsList, RecordSubscription, OAuth2UrlCallback, OAuth2AuthConfig, RecordService, AuthModel, OnStoreChangeFunc, BaseAuthStore, LocalAuthStore, AsyncSaveFunc, AsyncClearFunc, AsyncAuthStore, getTokenPayload, isTokenExpired, ParseOptions, cookieParse, SerializeOptions, cookieSerialize };
export { Client as default, BeforeSendResult, ClientResponseError, ListResult, BaseModel, AdminModel, SchemaField, CollectionModel, ExternalAuthModel, LogRequestModel, RecordModel, SendOptions, CommonOptions, ListOptions, FullListOptions, RecordOptions, RecordListOptions, RecordFullListOptions, LogStatsOptions, FileOptions, AuthOptions, normalizeUnknownQueryParams, CrudService, AdminAuthResponse, AdminService, CollectionService, HourlyStats, LogService, UnsubscribeFunc, RealtimeService, RecordAuthResponse, AuthProviderInfo, AuthMethodsList, RecordSubscription, OAuth2UrlCallback, OAuth2AuthConfig, RecordService, AuthModel, OnStoreChangeFunc, BaseAuthStore, LocalAuthStore, AsyncSaveFunc, AsyncClearFunc, AsyncAuthStore, getTokenPayload, isTokenExpired, ParseOptions, cookieParse, SerializeOptions, cookieSerialize };
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.

21 changes: 6 additions & 15 deletions dist/pocketbase.iife.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ declare class RealtimeService extends BaseService {
clientId: string;
private eventSource;
private subscriptions;
private lastSentTopics;
private lastSentSubscriptions;
private connectTimeoutId;
private maxConnectTimeout;
private reconnectTimeoutId;
Expand All @@ -478,7 +478,7 @@ declare class RealtimeService extends BaseService {
* If the SSE connection is not started yet,
* this method will also initialize it.
*/
subscribe(topic: string, callback: (data: any) => void): Promise<UnsubscribeFunc>;
subscribe(topic: string, callback: (data: any) => void, options?: SendOptions): Promise<UnsubscribeFunc>;
/**
* Unsubscribe from all subscription listeners with the specified topic.
*
Expand All @@ -499,7 +499,7 @@ declare class RealtimeService extends BaseService {
* The related sse connection will be autoclosed if after the
* unsubscribe operation there are no active subscriptions left.
*/
unsubscribeByPrefix(topicPrefix: string): Promise<void>;
unsubscribeByPrefix(keyPrefix: string): Promise<void>;
/**
* Unsubscribe from all subscriptions matching the specified topic and listener function.
*
Expand All @@ -513,7 +513,8 @@ declare class RealtimeService extends BaseService {
private hasSubscriptionListeners;
private submitSubscriptions;
private getSubscriptionsCancelKey;
private getNonEmptySubscriptionTopics;
private getSubscriptionsByTopic;
private getNonEmptySubscriptionKeys;
private addAllSubscriptionListeners;
private removeAllSubscriptionListeners;
private connect;
Expand Down Expand Up @@ -587,16 +588,6 @@ declare class RecordService<M = RecordModel> extends CrudService<M> {
// ---------------------------------------------------------------
// Realtime handlers
// ---------------------------------------------------------------
/**
* @deprecated Use subscribe(recordId, callback) instead.
*
* Subscribe to the realtime changes of a single record in the collection.
*/
subscribeOne<T = M>(recordId: string, callback: (data: RecordSubscription<T>) => void): Promise<UnsubscribeFunc>;
/**
* @deprecated This form of subscribe is deprecated. Please use `subscribe("*", callback)`.
*/
subscribe<T = M>(callback: (data: RecordSubscription<T>) => void): Promise<UnsubscribeFunc>;
/**
* Subscribe to realtime changes to the specified topic ("*" or record id).
*
Expand All @@ -610,7 +601,7 @@ declare class RecordService<M = RecordModel> extends CrudService<M> {
* You can use the returned `UnsubscribeFunc` to remove only a single subscription.
* Or use `unsubscribe(topic)` if you want to remove all subscriptions attached to the topic.
*/
subscribe<T = M>(topic: string, callback: (data: RecordSubscription<T>) => void): Promise<UnsubscribeFunc>;
subscribe<T = M>(topic: string, callback: (data: RecordSubscription<T>) => void, options?: SendOptions): Promise<UnsubscribeFunc>;
/**
* Unsubscribe from all subscriptions of the specified topic
* ("*" or record id).
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.

Loading

0 comments on commit f99b697

Please sign in to comment.