entropic-bond 1.53.1 → 1.53.3

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.
@@ -33,6 +33,13 @@ export interface DocumentReference {
33
33
  storedInCollection: string;
34
34
  };
35
35
  }
36
+ export interface DocumentChange {
37
+ before: Persistent | undefined;
38
+ after: Persistent;
39
+ params: {
40
+ [key: string]: any;
41
+ };
42
+ }
36
43
  type PersistentPropertyCollection = {
37
44
  [className: string]: PersistentProperty[];
38
45
  };
@@ -190,18 +197,32 @@ export declare class Persistent {
190
197
  }
191
198
  type CollectionPathCallback = (value: Persistent, prop: PersistentProperty) => string;
192
199
  type ValidatorFunction<T extends Persistent, P extends ClassPropNames<T>> = (value: T[P], property: PersistentProperty, persistentInstance: T) => boolean;
200
+ export type OwnerCollectionResolver = (ownerClassName: string, params: {}) => string;
201
+ /**
202
+ * Cached properties configuration
203
+ * @param cachedProps an array of properties whose values should be stored in the reference object
204
+ * @param updater a function that is called when the referenced object is updated
205
+ * @param ownerCollectionResolver a function that returns the collection path where the reference is stored
206
+ * @see persistentReferenceWithCachedProps
207
+ * @see persistentPureReferenceWithCachedProps
208
+ */
209
+ export type CachedPropsConfig<T extends Persistent> = {
210
+ cachedProps: ClassPropNamesOfType<T, Primitive>[];
211
+ updater?: (event: DocumentChange, property: PersistentProperty) => Promise<void>;
212
+ ownerCollectionResolver?: OwnerCollectionResolver;
213
+ };
193
214
  export interface PersistentProperty {
194
215
  name: string;
195
216
  isReference?: boolean;
196
217
  isPureReference?: boolean;
197
218
  storeInCollection?: string | CollectionPathCallback;
198
219
  subCollection?: string;
199
- cachedProps?: ClassPropNames<Persistent>[];
200
220
  toObjectSpecial?: (classObj: any) => any;
201
221
  fromObjectSpecial?: (obj: any) => any;
202
222
  searchableArray?: boolean;
203
223
  validator?: ValidatorFunction<any, any>;
204
224
  typeName?: string | string[];
225
+ cachedPropsConfig?: CachedPropsConfig<Persistent>;
205
226
  }
206
227
  /**
207
228
  * Decorator for a property that you want to persist.
@@ -225,10 +246,24 @@ export declare function persistentReference(target: Persistent, property: string
225
246
  * Decorator to declare a persistent reference (see @persistentReference) that stores
226
247
  * the values in cachedProps as values in the reference object. This is useful
227
248
  * when you are not able to wait for population of referenced properties.
228
- * @param cachedProps the properties whose values should be stored in the reference object
249
+ * @param cachedPropsConfig Pass an array of properties whose values should be stored in the reference object or an object
250
+ * with the cachedProps configuration.
229
251
  * @param storedInCollection indicates the path of the collection where this reference is stored
252
+ * @param propTypeName the accepted type name or type names of the property
253
+ * @see persistentReference
254
+ * @see CachedPropsConfig
255
+ * @see persistentPureReferenceWithCachedProps
256
+ * @sample
257
+ * class UserGroup extends Persistent {
258
+ * @persistentReferenceWithCachedProps( ['name', 'email'], 'Customer/Clients', 'User' ) private _friend: User
259
+ * }
260
+ *
261
+ * class SpecialUserGroup extends Persistent {
262
+ * @persistentReferenceWithCachedProps( { cachedProps: ['name', 'email'], updater: async ( event, prop ) => {
263
+ * // do something when the referenced user is updated
264
+ * }}, undefined, [ 'SpecialUser', 'User' ] ) private _friend: User
230
265
  */
231
- export declare function persistentReferenceWithCachedProps<T extends Persistent>(cachedProps: ClassPropNamesOfType<T, Primitive>[], storeInCollection?: string | CollectionPathCallback, propTypeName?: string | string[]): (target: Persistent, property: string) => void;
266
+ export declare function persistentReferenceWithCachedProps<T extends Persistent>(cachedPropsConfig: CachedPropsConfig<T> | ClassPropNamesOfType<T, Primitive>[], storeInCollection?: string | CollectionPathCallback, propTypeName?: string | string[]): (target: Persistent, property: string) => void;
232
267
  /**
233
268
  * Decorator for a property that is a reference to a persistent object.
234
269
  * In this case, and contrary to the @persistentReference decorator, the reference
@@ -241,18 +276,28 @@ export declare function persistentPureReference(target: Persistent, property: st
241
276
  * Decorator to declare a persistent property as a pure reference (see @persistentPureReference) that stores
242
277
  * the values of the properties listed in cachedProps as values in the reference object. This is useful
243
278
  * when you only need a few properties to be available without needing to populate the referenced property.
244
- * @param cachedProps the properties whose values should be stored in the reference object
279
+ * @param cachedPropsConfig Pass an array of properties whose values should be stored in the reference object or an object
280
+ * with the cachedProps configuration.
245
281
  * @param storedInCollection indicates the path of the collection where this reference is stored
282
+ * @param propTypeName the accepted type name or type names of the property
246
283
  * @see persistentReferenceWithCachedProps
247
284
  * @see persistentPureReference
285
+ * @see CachedPropsConfig
286
+ * @see persistentReferenceWithCachedProps
248
287
  * @sample
249
- * class User extends Persistent {
250
- * @persistentPureReferenceWithCachedProps( ['name', 'email'] ) private _friend: User
288
+ * class UserGroup extends Persistent {
289
+ * @persistentPureReferenceWithCachedProps( ['name', 'email'], 'Customer/Clients', 'User' ) private _friend: User
290
+ * }
291
+ *
292
+ * class SpecialUserGroup extends Persistent {
293
+ * @persistentPureReferenceWithCachedProps( { cachedProps: ['name', 'email'], updater: async ( event, prop ) => {
294
+ * // do something when the referenced user is updated
295
+ * }}, undefined, [ 'SpecialUser', 'User' ] ) private _friend: User
251
296
  * }
252
297
  * // the reference object will contain the properties name and email of the referenced user
253
298
  * // without having to populate the _friend property
254
299
  */
255
- export declare function persistentPureReferenceWithCachedProps<T extends Persistent>(cachedProps: ClassPropNamesOfType<T, Primitive>[], storeInCollection?: string | CollectionPathCallback, propTypeName?: string | string[]): (target: Persistent, property: string) => void;
300
+ export declare function persistentPureReferenceWithCachedProps<T extends Persistent>(cachedPropsConfig: CachedPropsConfig<T> | ClassPropNamesOfType<T, Primitive>[], storeInCollection?: string | CollectionPathCallback, propTypeName?: string | string[]): (target: Persistent, property: string) => void;
256
301
  export declare function persistentParser(options?: Partial<PersistentProperty>): (target: Persistent, property: string) => void;
257
302
  /**
258
303
  * Decorator to register a persistent class. Entropic Bond needs that you register
@@ -53,7 +53,7 @@ export type QueryObject<T> = {
53
53
  };
54
54
  };
55
55
  export type DocumentListenerUninstaller = () => void;
56
- interface DocumentChange {
56
+ export interface DocumentChange {
57
57
  before: Persistent | undefined;
58
58
  after: Persistent;
59
59
  params: {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "entropic-bond",
3
3
  "type": "module",
4
- "version": "1.53.1",
4
+ "version": "1.53.3",
5
5
  "description": "Tidy up your messy components",
6
6
  "main": "./lib/entropic-bond.umd.cjs",
7
7
  "module": "./lib/entropic-bond.js",