@plyaz/core 1.9.3 → 1.9.4

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.
package/dist/index.mjs CHANGED
@@ -4593,6 +4593,7 @@ var BaseDomainService = class {
4593
4593
  );
4594
4594
  }
4595
4595
  };
4596
+ var DEFAULT_POLLING_INTERVAL_MS = 3e4;
4596
4597
  var BaseFrontendDomainService = class _BaseFrontendDomainService extends BaseDomainService {
4597
4598
  // ─────────────────────────────────────────────────────────────────────────
4598
4599
  // Constructor
@@ -4618,6 +4619,11 @@ var BaseFrontendDomainService = class _BaseFrontendDomainService extends BaseDom
4618
4619
  this._rollbackStack = [];
4619
4620
  /** Maximum rollback stack size */
4620
4621
  this._maxRollbackStackSize = 10;
4622
+ // ─────────────────────────────────────────────────────────────────────────
4623
+ // Polling Properties
4624
+ // ─────────────────────────────────────────────────────────────────────────
4625
+ /** Polling timer reference */
4626
+ this._pollingTimer = null;
4621
4627
  this.storeHandlers = config.serviceConfig.storeHandlers;
4622
4628
  this.optimisticConfig = config.serviceConfig.optimisticUpdates;
4623
4629
  if (config.mapperClass) {
@@ -5644,6 +5650,87 @@ var BaseFrontendDomainService = class _BaseFrontendDomainService extends BaseDom
5644
5650
  this.logDebug(`Event emitted: ${eventName}`, payload);
5645
5651
  }
5646
5652
  // ─────────────────────────────────────────────────────────────────────────
5653
+ // Polling (Generic Feature)
5654
+ // ─────────────────────────────────────────────────────────────────────────
5655
+ /**
5656
+ * Check if polling is currently active.
5657
+ */
5658
+ get isPolling() {
5659
+ return this._pollingTimer !== null;
5660
+ }
5661
+ /**
5662
+ * Start polling for updates.
5663
+ * Uses `config.pollingInterval` if set, otherwise uses DEFAULT_POLLING_INTERVAL_MS (30s).
5664
+ * Polling calls fetchAll() at the configured interval.
5665
+ *
5666
+ * Override in subclass for custom polling behavior.
5667
+ *
5668
+ * @example
5669
+ * ```typescript
5670
+ * // Start polling with config interval
5671
+ * service.startPolling();
5672
+ *
5673
+ * // Or override in subclass for custom behavior
5674
+ * startPolling(): void {
5675
+ * super.startPolling();
5676
+ * // Custom polling logic
5677
+ * }
5678
+ * ```
5679
+ */
5680
+ startPolling() {
5681
+ if (this._pollingTimer) return;
5682
+ const interval = this.config.pollingInterval || DEFAULT_POLLING_INTERVAL_MS;
5683
+ this._pollingTimer = setInterval(() => {
5684
+ this.fetchAll().catch((error) => {
5685
+ this.logError("Polling fetch failed", { error });
5686
+ });
5687
+ }, interval);
5688
+ this.logDebug("Polling started", { interval });
5689
+ }
5690
+ /**
5691
+ * Stop polling.
5692
+ * Safe to call even if polling is not active.
5693
+ */
5694
+ stopPolling() {
5695
+ if (this._pollingTimer) {
5696
+ clearInterval(this._pollingTimer);
5697
+ this._pollingTimer = null;
5698
+ this.logDebug("Polling stopped");
5699
+ }
5700
+ }
5701
+ // ─────────────────────────────────────────────────────────────────────────
5702
+ // Lifecycle Management
5703
+ // ─────────────────────────────────────────────────────────────────────────
5704
+ /**
5705
+ * Dispose service and cleanup resources.
5706
+ * Stops polling and performs base cleanup.
5707
+ *
5708
+ * Subclasses should override and call super.dispose() to ensure cleanup.
5709
+ *
5710
+ * @example
5711
+ * ```typescript
5712
+ * dispose(): void {
5713
+ * // Custom cleanup
5714
+ * this.customCleanup();
5715
+ * // Always call super
5716
+ * super.dispose();
5717
+ * }
5718
+ * ```
5719
+ */
5720
+ dispose() {
5721
+ this.stopPolling();
5722
+ this.logInfo("Service disposed");
5723
+ }
5724
+ /**
5725
+ * Check if service is available.
5726
+ * Override in subclass for custom availability checks.
5727
+ *
5728
+ * @returns true if service is enabled and in a browser environment
5729
+ */
5730
+ isAvailable() {
5731
+ return this.isServiceEnabled && typeof window !== "undefined";
5732
+ }
5733
+ // ─────────────────────────────────────────────────────────────────────────
5647
5734
  // Error Handling Helpers
5648
5735
  // ─────────────────────────────────────────────────────────────────────────
5649
5736
  /**
@@ -12924,7 +13011,6 @@ var BackendExampleDomainService = class _BackendExampleDomainService extends Bas
12924
13011
  // ─────────────────────────────────────────────────────────────────────────
12925
13012
  };
12926
13013
  var backendExampleDomainService = new BackendExampleDomainService();
12927
- var DEFAULT_POLLING_INTERVAL_MS = 3e4;
12928
13014
  var FrontendExampleDomainService = class _FrontendExampleDomainService extends BaseFrontendDomainService {
12929
13015
  // ─────────────────────────────────────────────────────────────────────────
12930
13016
  // Constructor
@@ -12999,15 +13085,6 @@ var FrontendExampleDomainService = class _FrontendExampleDomainService extends B
12999
13085
  * Required by BaseFrontendDomainService
13000
13086
  */
13001
13087
  this.eventPrefix = "example";
13002
- /**
13003
- * Read-only store keys - inherits error and featureFlags from base
13004
- * No need to redeclare them - they're always included by default
13005
- */
13006
- // protected readStoreKeys = [...super.readStoreKeys]; // Already includes ERROR, FEATURE_FLAGS
13007
- // ─────────────────────────────────────────────────────────────────────────
13008
- // Domain-Specific Properties
13009
- // ─────────────────────────────────────────────────────────────────────────
13010
- this.pollingTimer = null;
13011
13088
  if (this.config.pollingInterval && this.config.pollingInterval > 0) {
13012
13089
  this.startPolling();
13013
13090
  }
@@ -13016,6 +13093,11 @@ var FrontendExampleDomainService = class _FrontendExampleDomainService extends B
13016
13093
  __name(this, "FrontendExampleDomainService");
13017
13094
  }
13018
13095
  static {
13096
+ /**
13097
+ * Read-only store keys - inherits error and featureFlags from base
13098
+ * No need to redeclare them - they're always included by default
13099
+ */
13100
+ // protected readStoreKeys = [...super.readStoreKeys]; // Already includes ERROR, FEATURE_FLAGS
13019
13101
  // ─────────────────────────────────────────────────────────────────────────
13020
13102
  // Static: Service Registry Interface
13021
13103
  // ─────────────────────────────────────────────────────────────────────────
@@ -13049,18 +13131,10 @@ var FrontendExampleDomainService = class _FrontendExampleDomainService extends B
13049
13131
  return service;
13050
13132
  }
13051
13133
  // ─────────────────────────────────────────────────────────────────────────
13052
- // Abstract Implementations (Required by BaseDomainService)
13053
- // ─────────────────────────────────────────────────────────────────────────
13054
- isAvailable() {
13055
- return this.isServiceEnabled && typeof window !== "undefined";
13056
- }
13057
- dispose() {
13058
- this.stopPolling();
13059
- this.logInfo("Service disposed");
13060
- }
13061
- // ─────────────────────────────────────────────────────────────────────────
13062
13134
  // Lifecycle Hooks (Optional Override Examples)
13063
13135
  // ─────────────────────────────────────────────────────────────────────────
13136
+ // Note: isAvailable(), dispose(), startPolling(), stopPolling() are inherited
13137
+ // from BaseFrontendDomainService. Override here only if custom behavior needed.
13064
13138
  /**
13065
13139
  * After fetchAll - emit event (store sync handled automatically)
13066
13140
  * Note: Base class automatically calls syncToStores() which uses storeHandlers
@@ -13108,35 +13182,9 @@ var FrontendExampleDomainService = class _FrontendExampleDomainService extends B
13108
13182
  return CoreEventManager.on(event, handler);
13109
13183
  }
13110
13184
  // ─────────────────────────────────────────────────────────────────────────
13111
- // Polling (Domain-Specific Feature)
13112
- // ─────────────────────────────────────────────────────────────────────────
13113
- /**
13114
- * Start polling for updates
13115
- * Domain-specific feature - not part of base class
13116
- */
13117
- startPolling() {
13118
- if (this.pollingTimer) return;
13119
- const interval = this.config.pollingInterval ?? DEFAULT_POLLING_INTERVAL_MS;
13120
- this.pollingTimer = setInterval(() => {
13121
- this.fetchAll().catch((error) => {
13122
- this.logError("Polling fetch failed", { error });
13123
- });
13124
- }, interval);
13125
- this.logDebug("Polling started", { interval });
13126
- }
13127
- /**
13128
- * Stop polling
13129
- */
13130
- stopPolling() {
13131
- if (this.pollingTimer) {
13132
- clearInterval(this.pollingTimer);
13133
- this.pollingTimer = null;
13134
- this.logDebug("Polling stopped");
13135
- }
13136
- }
13137
- // ─────────────────────────────────────────────────────────────────────────
13138
13185
  // Demo Methods - fetchAll() with Query Examples
13139
13186
  // ─────────────────────────────────────────────────────────────────────────
13187
+ // Note: startPolling() and stopPolling() are inherited from BaseFrontendDomainService
13140
13188
  /**
13141
13189
  * Demo: Fetch all examples with optional filters
13142
13190
  * Demonstrates the fetchAll() method with typed query parameters