@katn30/trakr 2.2.1 → 4.0.0

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.
@@ -221,6 +221,10 @@ interface IdAssignment {
221
221
  value: number;
222
222
  }
223
223
  declare function AutoId<This extends object, Value>(_target: undefined, context: ClassFieldDecoratorContext<This, Value>): void;
224
+ declare function Id<This extends object, Value>(_target: undefined, context: ClassFieldDecoratorContext<This, Value>): void;
225
+ declare function getIdentityProperties(proto: object): string[];
226
+ declare function getIdentity(obj: object): unknown;
227
+ declare function getIdentityObject(obj: object): Record<string, unknown>;
224
228
 
225
229
  interface StateTarget {
226
230
  trackingId: number;
@@ -414,4 +418,91 @@ declare function Tracked(validator?: (self: any, newValue: any) => string | unde
414
418
  <T extends TrackedObject, V>(target: (this: T) => V, context: ClassGetterDecoratorContext<T, V>): (this: T) => V;
415
419
  };
416
420
 
417
- export { AutoId, type ITracked, type IdAssignment, type PropertyScope, State, Tracked, TrackedCollection, TrackedCollectionChanged, TrackedObject, type TrackedPropertyChanged, Tracker, TrackerSession, TypedEvent };
421
+ interface GeneratedEvent<TEventType extends string = string, TPayload = Record<string, unknown>> {
422
+ eventType: TEventType;
423
+ payload: TPayload;
424
+ trackingId?: number;
425
+ targetId?: unknown;
426
+ }
427
+ interface EventLifecycleOptions<TEventType extends string = string> {
428
+ itemAdded?: TEventType;
429
+ itemRemoved?: TEventType;
430
+ }
431
+
432
+ declare class EventTracker extends Tracker {
433
+ withContext<T>(ctx: unknown, action: () => T): T;
434
+ onCommit(keys?: IdAssignment[]): void;
435
+ generateEvents<TEventType extends string = string>(): GeneratedEvent<TEventType>[];
436
+ }
437
+
438
+ interface HistoryOptions<TSelf = any, TValue = any> {
439
+ entryFactory: (self: TSelf, newValue: TValue, oldValue: TValue, change: Change, ctx?: unknown) => unknown;
440
+ }
441
+ type HistoryConfig = boolean | HistoryOptions;
442
+ interface EventPropertyOptions {
443
+ eventType?: string;
444
+ history?: HistoryConfig;
445
+ coalesceWithin?: number;
446
+ }
447
+
448
+ interface EventTrackedOptions {
449
+ coalesceWithin?: number;
450
+ eventType?: string;
451
+ history?: HistoryConfig;
452
+ }
453
+ declare function EventTracked(validator?: (self: any, newValue: any) => string | undefined, onChange?: (self: any, newValue: any, oldValue: any) => void, options?: EventTrackedOptions): {
454
+ <T extends TrackedObject, V>(target: ClassAccessorDecoratorTarget<T, V>, context: ClassAccessorDecoratorContext<T, V>): ClassAccessorDecoratorResult<T, V>;
455
+ <T extends TrackedObject, V>(target: (this: T, value: V) => void, context: ClassSetterDecoratorContext<T, V>): (this: T, value: V) => void;
456
+ <T extends TrackedObject, V>(target: (this: T) => V, context: ClassGetterDecoratorContext<T, V>): (this: T) => V;
457
+ };
458
+
459
+ interface CollectionHistoryOptions<T = any> {
460
+ entryFactory: (self: T, change: Change, ctx?: unknown) => unknown;
461
+ }
462
+ type CollectionHistoryConfig = boolean | CollectionHistoryOptions;
463
+ interface EventTrackedCollectionOptions<T = any, TEventType extends string = string> extends EventLifecycleOptions<TEventType> {
464
+ eventType?: TEventType;
465
+ history?: CollectionHistoryConfig;
466
+ owner?: {
467
+ object: TrackedObject;
468
+ property: string;
469
+ };
470
+ }
471
+ interface CollectionOp {
472
+ op: "add" | "remove" | "change";
473
+ item?: TrackedObject;
474
+ identity?: unknown;
475
+ diff?: Record<string, unknown>;
476
+ raw?: unknown;
477
+ snapshot?: Record<string, unknown>;
478
+ }
479
+ declare class EventTrackedCollection<T, TEventType extends string = string> extends TrackedCollection<T> {
480
+ private readonly _eventOptions;
481
+ private readonly _historyOps;
482
+ private readonly _baselineItems;
483
+ constructor(tracker: Tracker, items?: T[], validator?: (value: T[]) => string | undefined, options?: EventTrackedCollectionOptions<T, TEventType>);
484
+ /** @internal */
485
+ get _lifecycleOptions(): EventLifecycleOptions<TEventType> | undefined;
486
+ /** @internal */
487
+ get _aggregateOptions(): EventTrackedCollectionOptions<T, TEventType> | undefined;
488
+ /** @internal */
489
+ get _historyOpsList(): CollectionOp[];
490
+ /** @internal */
491
+ _clearHistoryOps(): void;
492
+ /** @internal */
493
+ _isInBaseline(item: T): boolean;
494
+ /** @internal */
495
+ _baselineListSnapshot(): T[];
496
+ /** @internal */
497
+ _rebaseline(): void;
498
+ private _isAggregateMode;
499
+ private _isHistoryMode;
500
+ private _validateItemHasIdentity;
501
+ private _attachItemChangeWatchers;
502
+ private _recordAddOp;
503
+ private _recordRemoveOp;
504
+ private _recordChangeOpDiff;
505
+ private _recordChangeOp;
506
+ }
507
+
508
+ export { AutoId, type CollectionHistoryConfig, type CollectionHistoryOptions, type EventLifecycleOptions, type EventPropertyOptions, EventTracked, EventTrackedCollection, type EventTrackedCollectionOptions, type EventTrackedOptions, EventTracker, type GeneratedEvent, type HistoryConfig, type HistoryOptions, type ITracked, Id, type IdAssignment, type PropertyScope, State, Tracked, TrackedCollection, TrackedCollectionChanged, TrackedObject, type TrackedPropertyChanged, Tracker, TrackerSession, TypedEvent, getIdentity, getIdentityObject, getIdentityProperties };
@@ -221,6 +221,10 @@ interface IdAssignment {
221
221
  value: number;
222
222
  }
223
223
  declare function AutoId<This extends object, Value>(_target: undefined, context: ClassFieldDecoratorContext<This, Value>): void;
224
+ declare function Id<This extends object, Value>(_target: undefined, context: ClassFieldDecoratorContext<This, Value>): void;
225
+ declare function getIdentityProperties(proto: object): string[];
226
+ declare function getIdentity(obj: object): unknown;
227
+ declare function getIdentityObject(obj: object): Record<string, unknown>;
224
228
 
225
229
  interface StateTarget {
226
230
  trackingId: number;
@@ -414,4 +418,91 @@ declare function Tracked(validator?: (self: any, newValue: any) => string | unde
414
418
  <T extends TrackedObject, V>(target: (this: T) => V, context: ClassGetterDecoratorContext<T, V>): (this: T) => V;
415
419
  };
416
420
 
417
- export { AutoId, type ITracked, type IdAssignment, type PropertyScope, State, Tracked, TrackedCollection, TrackedCollectionChanged, TrackedObject, type TrackedPropertyChanged, Tracker, TrackerSession, TypedEvent };
421
+ interface GeneratedEvent<TEventType extends string = string, TPayload = Record<string, unknown>> {
422
+ eventType: TEventType;
423
+ payload: TPayload;
424
+ trackingId?: number;
425
+ targetId?: unknown;
426
+ }
427
+ interface EventLifecycleOptions<TEventType extends string = string> {
428
+ itemAdded?: TEventType;
429
+ itemRemoved?: TEventType;
430
+ }
431
+
432
+ declare class EventTracker extends Tracker {
433
+ withContext<T>(ctx: unknown, action: () => T): T;
434
+ onCommit(keys?: IdAssignment[]): void;
435
+ generateEvents<TEventType extends string = string>(): GeneratedEvent<TEventType>[];
436
+ }
437
+
438
+ interface HistoryOptions<TSelf = any, TValue = any> {
439
+ entryFactory: (self: TSelf, newValue: TValue, oldValue: TValue, change: Change, ctx?: unknown) => unknown;
440
+ }
441
+ type HistoryConfig = boolean | HistoryOptions;
442
+ interface EventPropertyOptions {
443
+ eventType?: string;
444
+ history?: HistoryConfig;
445
+ coalesceWithin?: number;
446
+ }
447
+
448
+ interface EventTrackedOptions {
449
+ coalesceWithin?: number;
450
+ eventType?: string;
451
+ history?: HistoryConfig;
452
+ }
453
+ declare function EventTracked(validator?: (self: any, newValue: any) => string | undefined, onChange?: (self: any, newValue: any, oldValue: any) => void, options?: EventTrackedOptions): {
454
+ <T extends TrackedObject, V>(target: ClassAccessorDecoratorTarget<T, V>, context: ClassAccessorDecoratorContext<T, V>): ClassAccessorDecoratorResult<T, V>;
455
+ <T extends TrackedObject, V>(target: (this: T, value: V) => void, context: ClassSetterDecoratorContext<T, V>): (this: T, value: V) => void;
456
+ <T extends TrackedObject, V>(target: (this: T) => V, context: ClassGetterDecoratorContext<T, V>): (this: T) => V;
457
+ };
458
+
459
+ interface CollectionHistoryOptions<T = any> {
460
+ entryFactory: (self: T, change: Change, ctx?: unknown) => unknown;
461
+ }
462
+ type CollectionHistoryConfig = boolean | CollectionHistoryOptions;
463
+ interface EventTrackedCollectionOptions<T = any, TEventType extends string = string> extends EventLifecycleOptions<TEventType> {
464
+ eventType?: TEventType;
465
+ history?: CollectionHistoryConfig;
466
+ owner?: {
467
+ object: TrackedObject;
468
+ property: string;
469
+ };
470
+ }
471
+ interface CollectionOp {
472
+ op: "add" | "remove" | "change";
473
+ item?: TrackedObject;
474
+ identity?: unknown;
475
+ diff?: Record<string, unknown>;
476
+ raw?: unknown;
477
+ snapshot?: Record<string, unknown>;
478
+ }
479
+ declare class EventTrackedCollection<T, TEventType extends string = string> extends TrackedCollection<T> {
480
+ private readonly _eventOptions;
481
+ private readonly _historyOps;
482
+ private readonly _baselineItems;
483
+ constructor(tracker: Tracker, items?: T[], validator?: (value: T[]) => string | undefined, options?: EventTrackedCollectionOptions<T, TEventType>);
484
+ /** @internal */
485
+ get _lifecycleOptions(): EventLifecycleOptions<TEventType> | undefined;
486
+ /** @internal */
487
+ get _aggregateOptions(): EventTrackedCollectionOptions<T, TEventType> | undefined;
488
+ /** @internal */
489
+ get _historyOpsList(): CollectionOp[];
490
+ /** @internal */
491
+ _clearHistoryOps(): void;
492
+ /** @internal */
493
+ _isInBaseline(item: T): boolean;
494
+ /** @internal */
495
+ _baselineListSnapshot(): T[];
496
+ /** @internal */
497
+ _rebaseline(): void;
498
+ private _isAggregateMode;
499
+ private _isHistoryMode;
500
+ private _validateItemHasIdentity;
501
+ private _attachItemChangeWatchers;
502
+ private _recordAddOp;
503
+ private _recordRemoveOp;
504
+ private _recordChangeOpDiff;
505
+ private _recordChangeOp;
506
+ }
507
+
508
+ export { AutoId, type CollectionHistoryConfig, type CollectionHistoryOptions, type EventLifecycleOptions, type EventPropertyOptions, EventTracked, EventTrackedCollection, type EventTrackedCollectionOptions, type EventTrackedOptions, EventTracker, type GeneratedEvent, type HistoryConfig, type HistoryOptions, type ITracked, Id, type IdAssignment, type PropertyScope, State, Tracked, TrackedCollection, TrackedCollectionChanged, TrackedObject, type TrackedPropertyChanged, Tracker, TrackerSession, TypedEvent, getIdentity, getIdentityObject, getIdentityProperties };