@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.
@@ -4374,6 +4374,7 @@ var BaseDomainService = class {
4374
4374
  );
4375
4375
  }
4376
4376
  };
4377
+ var DEFAULT_POLLING_INTERVAL_MS = 3e4;
4377
4378
  var BaseFrontendDomainService = class _BaseFrontendDomainService extends BaseDomainService {
4378
4379
  // ─────────────────────────────────────────────────────────────────────────
4379
4380
  // Constructor
@@ -4399,6 +4400,11 @@ var BaseFrontendDomainService = class _BaseFrontendDomainService extends BaseDom
4399
4400
  this._rollbackStack = [];
4400
4401
  /** Maximum rollback stack size */
4401
4402
  this._maxRollbackStackSize = 10;
4403
+ // ─────────────────────────────────────────────────────────────────────────
4404
+ // Polling Properties
4405
+ // ─────────────────────────────────────────────────────────────────────────
4406
+ /** Polling timer reference */
4407
+ this._pollingTimer = null;
4402
4408
  this.storeHandlers = config.serviceConfig.storeHandlers;
4403
4409
  this.optimisticConfig = config.serviceConfig.optimisticUpdates;
4404
4410
  if (config.mapperClass) {
@@ -5425,6 +5431,87 @@ var BaseFrontendDomainService = class _BaseFrontendDomainService extends BaseDom
5425
5431
  this.logDebug(`Event emitted: ${eventName}`, payload);
5426
5432
  }
5427
5433
  // ─────────────────────────────────────────────────────────────────────────
5434
+ // Polling (Generic Feature)
5435
+ // ─────────────────────────────────────────────────────────────────────────
5436
+ /**
5437
+ * Check if polling is currently active.
5438
+ */
5439
+ get isPolling() {
5440
+ return this._pollingTimer !== null;
5441
+ }
5442
+ /**
5443
+ * Start polling for updates.
5444
+ * Uses `config.pollingInterval` if set, otherwise uses DEFAULT_POLLING_INTERVAL_MS (30s).
5445
+ * Polling calls fetchAll() at the configured interval.
5446
+ *
5447
+ * Override in subclass for custom polling behavior.
5448
+ *
5449
+ * @example
5450
+ * ```typescript
5451
+ * // Start polling with config interval
5452
+ * service.startPolling();
5453
+ *
5454
+ * // Or override in subclass for custom behavior
5455
+ * startPolling(): void {
5456
+ * super.startPolling();
5457
+ * // Custom polling logic
5458
+ * }
5459
+ * ```
5460
+ */
5461
+ startPolling() {
5462
+ if (this._pollingTimer) return;
5463
+ const interval = this.config.pollingInterval || DEFAULT_POLLING_INTERVAL_MS;
5464
+ this._pollingTimer = setInterval(() => {
5465
+ this.fetchAll().catch((error) => {
5466
+ this.logError("Polling fetch failed", { error });
5467
+ });
5468
+ }, interval);
5469
+ this.logDebug("Polling started", { interval });
5470
+ }
5471
+ /**
5472
+ * Stop polling.
5473
+ * Safe to call even if polling is not active.
5474
+ */
5475
+ stopPolling() {
5476
+ if (this._pollingTimer) {
5477
+ clearInterval(this._pollingTimer);
5478
+ this._pollingTimer = null;
5479
+ this.logDebug("Polling stopped");
5480
+ }
5481
+ }
5482
+ // ─────────────────────────────────────────────────────────────────────────
5483
+ // Lifecycle Management
5484
+ // ─────────────────────────────────────────────────────────────────────────
5485
+ /**
5486
+ * Dispose service and cleanup resources.
5487
+ * Stops polling and performs base cleanup.
5488
+ *
5489
+ * Subclasses should override and call super.dispose() to ensure cleanup.
5490
+ *
5491
+ * @example
5492
+ * ```typescript
5493
+ * dispose(): void {
5494
+ * // Custom cleanup
5495
+ * this.customCleanup();
5496
+ * // Always call super
5497
+ * super.dispose();
5498
+ * }
5499
+ * ```
5500
+ */
5501
+ dispose() {
5502
+ this.stopPolling();
5503
+ this.logInfo("Service disposed");
5504
+ }
5505
+ /**
5506
+ * Check if service is available.
5507
+ * Override in subclass for custom availability checks.
5508
+ *
5509
+ * @returns true if service is enabled and in a browser environment
5510
+ */
5511
+ isAvailable() {
5512
+ return this.isServiceEnabled && typeof window !== "undefined";
5513
+ }
5514
+ // ─────────────────────────────────────────────────────────────────────────
5428
5515
  // Error Handling Helpers
5429
5516
  // ─────────────────────────────────────────────────────────────────────────
5430
5517
  /**
@@ -6303,7 +6390,6 @@ var ExampleMapperClass = class extends BaseMapper {
6303
6390
  };
6304
6391
 
6305
6392
  // src/domain/example/FrontendExampleDomainService.ts
6306
- var DEFAULT_POLLING_INTERVAL_MS = 3e4;
6307
6393
  var FrontendExampleDomainService = class _FrontendExampleDomainService extends BaseFrontendDomainService {
6308
6394
  // ─────────────────────────────────────────────────────────────────────────
6309
6395
  // Constructor
@@ -6378,15 +6464,6 @@ var FrontendExampleDomainService = class _FrontendExampleDomainService extends B
6378
6464
  * Required by BaseFrontendDomainService
6379
6465
  */
6380
6466
  this.eventPrefix = "example";
6381
- /**
6382
- * Read-only store keys - inherits error and featureFlags from base
6383
- * No need to redeclare them - they're always included by default
6384
- */
6385
- // protected readStoreKeys = [...super.readStoreKeys]; // Already includes ERROR, FEATURE_FLAGS
6386
- // ─────────────────────────────────────────────────────────────────────────
6387
- // Domain-Specific Properties
6388
- // ─────────────────────────────────────────────────────────────────────────
6389
- this.pollingTimer = null;
6390
6467
  if (this.config.pollingInterval && this.config.pollingInterval > 0) {
6391
6468
  this.startPolling();
6392
6469
  }
@@ -6395,6 +6472,11 @@ var FrontendExampleDomainService = class _FrontendExampleDomainService extends B
6395
6472
  __name(this, "FrontendExampleDomainService");
6396
6473
  }
6397
6474
  static {
6475
+ /**
6476
+ * Read-only store keys - inherits error and featureFlags from base
6477
+ * No need to redeclare them - they're always included by default
6478
+ */
6479
+ // protected readStoreKeys = [...super.readStoreKeys]; // Already includes ERROR, FEATURE_FLAGS
6398
6480
  // ─────────────────────────────────────────────────────────────────────────
6399
6481
  // Static: Service Registry Interface
6400
6482
  // ─────────────────────────────────────────────────────────────────────────
@@ -6428,18 +6510,10 @@ var FrontendExampleDomainService = class _FrontendExampleDomainService extends B
6428
6510
  return service;
6429
6511
  }
6430
6512
  // ─────────────────────────────────────────────────────────────────────────
6431
- // Abstract Implementations (Required by BaseDomainService)
6432
- // ─────────────────────────────────────────────────────────────────────────
6433
- isAvailable() {
6434
- return this.isServiceEnabled && typeof window !== "undefined";
6435
- }
6436
- dispose() {
6437
- this.stopPolling();
6438
- this.logInfo("Service disposed");
6439
- }
6440
- // ─────────────────────────────────────────────────────────────────────────
6441
6513
  // Lifecycle Hooks (Optional Override Examples)
6442
6514
  // ─────────────────────────────────────────────────────────────────────────
6515
+ // Note: isAvailable(), dispose(), startPolling(), stopPolling() are inherited
6516
+ // from BaseFrontendDomainService. Override here only if custom behavior needed.
6443
6517
  /**
6444
6518
  * After fetchAll - emit event (store sync handled automatically)
6445
6519
  * Note: Base class automatically calls syncToStores() which uses storeHandlers
@@ -6487,35 +6561,9 @@ var FrontendExampleDomainService = class _FrontendExampleDomainService extends B
6487
6561
  return CoreEventManager.on(event, handler);
6488
6562
  }
6489
6563
  // ─────────────────────────────────────────────────────────────────────────
6490
- // Polling (Domain-Specific Feature)
6491
- // ─────────────────────────────────────────────────────────────────────────
6492
- /**
6493
- * Start polling for updates
6494
- * Domain-specific feature - not part of base class
6495
- */
6496
- startPolling() {
6497
- if (this.pollingTimer) return;
6498
- const interval = this.config.pollingInterval ?? DEFAULT_POLLING_INTERVAL_MS;
6499
- this.pollingTimer = setInterval(() => {
6500
- this.fetchAll().catch((error) => {
6501
- this.logError("Polling fetch failed", { error });
6502
- });
6503
- }, interval);
6504
- this.logDebug("Polling started", { interval });
6505
- }
6506
- /**
6507
- * Stop polling
6508
- */
6509
- stopPolling() {
6510
- if (this.pollingTimer) {
6511
- clearInterval(this.pollingTimer);
6512
- this.pollingTimer = null;
6513
- this.logDebug("Polling stopped");
6514
- }
6515
- }
6516
- // ─────────────────────────────────────────────────────────────────────────
6517
6564
  // Demo Methods - fetchAll() with Query Examples
6518
6565
  // ─────────────────────────────────────────────────────────────────────────
6566
+ // Note: startPolling() and stopPolling() are inherited from BaseFrontendDomainService
6519
6567
  /**
6520
6568
  * Demo: Fetch all examples with optional filters
6521
6569
  * Demonstrates the fetchAll() method with typed query parameters