entropic-bond 1.53.5 → 1.53.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,6 @@
1
1
  import { Persistent, PersistentObject, Collections, PersistentProperty } from '../persistent/persistent';
2
2
  import { ClassPropNames } from '../types/utility-types';
3
+ import { Unsubscriber } from '../observable/observable';
3
4
  export type DocumentObject = PersistentObject<Persistent>;
4
5
  /**
5
6
  * The query operators
@@ -53,14 +54,16 @@ export type QueryObject<T> = {
53
54
  };
54
55
  };
55
56
  export type DocumentListenerUninstaller = () => void;
56
- export interface DocumentChange {
57
- before: Persistent | undefined;
58
- after: Persistent;
57
+ export type DocumentChangeType = 'create' | 'update' | 'delete';
58
+ export interface DocumentChange<T extends Persistent | DocumentObject> {
59
+ before: T | undefined;
60
+ after: T | undefined;
59
61
  params: {
60
62
  [key: string]: any;
61
63
  };
64
+ type: DocumentChangeType;
62
65
  }
63
- export type DocumentChangeListerner = (change: DocumentChange) => void;
66
+ export type DocumentChangeListerner<T extends Persistent | DocumentObject> = (change: DocumentChange<T>) => void;
64
67
  export interface DocumentChangeListernerHandler {
65
68
  uninstall: DocumentListenerUninstaller;
66
69
  nativeHandler: unknown;
@@ -70,7 +73,7 @@ type CachedPropsUpdateCallback = (doc: Persistent, prop: PersistentProperty) =>
70
73
  export interface CachedPropsUpdaterConfig {
71
74
  onUpdate?: CachedPropsUpdateCallback;
72
75
  noThrowOnNonImplementedListener?: boolean;
73
- documentChangeListerner?: (prop: PersistentProperty, listener: DocumentChangeListerner) => DocumentChangeListernerHandler | undefined;
76
+ documentChangeListerner?: (prop: PersistentProperty, listener: DocumentChangeListerner<Persistent>) => DocumentChangeListernerHandler | undefined;
74
77
  }
75
78
  interface PropWithOwner {
76
79
  prop: PersistentProperty;
@@ -95,7 +98,7 @@ export declare abstract class DataSource {
95
98
  * @returns a function that uninstalls the listener. If the returned value is undefined
96
99
  * the method documentChangeListerner has not been implemented in the concrete data source
97
100
  */
98
- protected subscribeToDocumentChangeListerner(collectionPathToListen: string, listener: DocumentChangeListerner): DocumentChangeListernerHandler | undefined;
101
+ protected subscribeToDocumentChangeListerner(collectionPathToListen: string, listener: DocumentChangeListerner<DocumentObject>): DocumentChangeListernerHandler | undefined;
99
102
  /**
100
103
  * Retrieves a document by id
101
104
  * Implement the required logic to retrieve a document by id from your concrete
@@ -155,6 +158,8 @@ export declare abstract class DataSource {
155
158
  * @see QueryObject
156
159
  */
157
160
  abstract count(queryObject: QueryObject<DocumentObject>, collectionName: string): Promise<number>;
161
+ abstract onCollectionChange(query: QueryObject<DocumentObject>, collectionName: string, listener: DocumentChangeListerner<DocumentObject>): Unsubscriber;
162
+ abstract onDocumentChange(documentPath: string, documentId: string, listener: DocumentChangeListerner<DocumentObject>): Unsubscriber;
158
163
  /**
159
164
  * Utility method to convert a query object to a property path query object
160
165
  *
@@ -170,7 +175,7 @@ export declare abstract class DataSource {
170
175
  static toPropertyPathOperations<T extends Persistent>(operations: QueryOperation<T>[]): QueryOperation<T>[];
171
176
  static isArrayOperator(operator: QueryOperator): boolean;
172
177
  private static toPropertyPathValue;
173
- static onDocumentChange(event: DocumentChange, propsToUpdate: PropWithOwner[]): Promise<Promise<[Promise<void>[]]>[] | undefined>;
178
+ static onDocumentChange(event: DocumentChange<DocumentObject>, propsToUpdate: PropWithOwner[]): Promise<Promise<[Promise<void>[]]>[] | undefined>;
174
179
  private static onUpdate;
175
180
  }
176
181
  export {};
@@ -1,3 +1,4 @@
1
+ import { Unsubscriber } from '../observable/observable';
1
2
  import { Collections, Persistent, PersistentObject } from '../persistent/persistent';
2
3
  import { DataSource, DocumentChangeListerner, DocumentChangeListernerHandler, DocumentObject, QueryObject } from './data-source';
3
4
  export interface JsonRawData {
@@ -40,6 +41,8 @@ export declare class JsonDataSource extends DataSource {
40
41
  delete(id: string, collectionName: string): Promise<void>;
41
42
  next(limit?: number): Promise<DocumentObject[]>;
42
43
  count(queryObject: QueryObject<DocumentObject>, collectionName: string): Promise<number>;
44
+ onCollectionChange(query: QueryObject<DocumentObject>, collectionName: string, listener: DocumentChangeListerner<DocumentObject>): Unsubscriber;
45
+ onDocumentChange(collectionName: string, documentId: string, listener: DocumentChangeListerner<DocumentObject>): Unsubscriber;
43
46
  /**
44
47
  * @returns the raw data store data as a JSON object
45
48
  */
@@ -51,7 +54,7 @@ export declare class JsonDataSource extends DataSource {
51
54
  wait(): Promise<any[]>;
52
55
  private incCursor;
53
56
  simulateError(error: string | ErrorOnOperation | undefined): this;
54
- protected subscribeToDocumentChangeListerner(collectionNameToListen: string, listener: DocumentChangeListerner): DocumentChangeListernerHandler | undefined;
57
+ protected subscribeToDocumentChangeListerner(collectionNameToListen: string, listener: DocumentChangeListerner<DocumentObject>): DocumentChangeListernerHandler | undefined;
55
58
  private notifyChange;
56
59
  private decCursor;
57
60
  private queryProcessor;
@@ -67,5 +70,7 @@ export declare class JsonDataSource extends DataSource {
67
70
  private _simulateDelay;
68
71
  private _pendingPromises;
69
72
  private _simulateError;
70
- private _listener;
73
+ private _documentListeners;
74
+ private _collectionListeners;
75
+ private _serverCollectionListeners;
71
76
  }
@@ -1,6 +1,7 @@
1
+ import { Unsubscriber } from '../observable/observable';
1
2
  import { Persistent } from '../persistent/persistent';
2
3
  import { ClassPropNames, PropPath, PropPathType } from '../types/utility-types';
3
- import { DataSource, QueryOperator, QueryObject, QueryOrder } from './data-source';
4
+ import { DataSource, QueryOperator, QueryObject, QueryOrder, DocumentChangeListerner } from './data-source';
4
5
  /**
5
6
  * Provides abstraction to the database access. You should gain access to a Model
6
7
  * object through the Store.getModel method instead of its constructor.
@@ -60,6 +61,9 @@ export declare class Model<T extends Persistent> {
60
61
  * @returns a promise resolving to a collection of matched documents
61
62
  */
62
63
  next<U extends T>(limit?: number): Promise<U[]>;
64
+ onDocumentChange(collectionPathToListen: string, documentId: string, listener: DocumentChangeListerner<T>): Unsubscriber;
65
+ onCollectionChange(query: Query<T>, listener: DocumentChangeListerner<T>): Unsubscriber;
66
+ private toPersistentChangeObject;
63
67
  private mapToInstance;
64
68
  /**
65
69
  * Normalizes the query object to match the data source requirements.
@@ -233,6 +237,7 @@ export declare class Query<T extends Persistent> {
233
237
  * const count = await query.where( 'name', '==', 'John' ).count()
234
238
  */
235
239
  count(): Promise<number>;
240
+ getQueryObject(): QueryObject<T>;
236
241
  private queryObject;
237
242
  private model;
238
243
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "entropic-bond",
3
3
  "type": "module",
4
- "version": "1.53.5",
4
+ "version": "1.53.7",
5
5
  "description": "Tidy up your messy components",
6
6
  "main": "./lib/entropic-bond.umd.cjs",
7
7
  "module": "./lib/entropic-bond.js",