@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.js CHANGED
@@ -37089,6 +37089,7 @@ var BaseDomainService = class {
37089
37089
  );
37090
37090
  }
37091
37091
  };
37092
+ var DEFAULT_POLLING_INTERVAL_MS = 3e4;
37092
37093
  var BaseFrontendDomainService = class _BaseFrontendDomainService extends BaseDomainService {
37093
37094
  // ─────────────────────────────────────────────────────────────────────────
37094
37095
  // Constructor
@@ -37114,6 +37115,11 @@ var BaseFrontendDomainService = class _BaseFrontendDomainService extends BaseDom
37114
37115
  this._rollbackStack = [];
37115
37116
  /** Maximum rollback stack size */
37116
37117
  this._maxRollbackStackSize = 10;
37118
+ // ─────────────────────────────────────────────────────────────────────────
37119
+ // Polling Properties
37120
+ // ─────────────────────────────────────────────────────────────────────────
37121
+ /** Polling timer reference */
37122
+ this._pollingTimer = null;
37117
37123
  this.storeHandlers = config.serviceConfig.storeHandlers;
37118
37124
  this.optimisticConfig = config.serviceConfig.optimisticUpdates;
37119
37125
  if (config.mapperClass) {
@@ -38140,6 +38146,87 @@ var BaseFrontendDomainService = class _BaseFrontendDomainService extends BaseDom
38140
38146
  this.logDebug(`Event emitted: ${eventName}`, payload);
38141
38147
  }
38142
38148
  // ─────────────────────────────────────────────────────────────────────────
38149
+ // Polling (Generic Feature)
38150
+ // ─────────────────────────────────────────────────────────────────────────
38151
+ /**
38152
+ * Check if polling is currently active.
38153
+ */
38154
+ get isPolling() {
38155
+ return this._pollingTimer !== null;
38156
+ }
38157
+ /**
38158
+ * Start polling for updates.
38159
+ * Uses `config.pollingInterval` if set, otherwise uses DEFAULT_POLLING_INTERVAL_MS (30s).
38160
+ * Polling calls fetchAll() at the configured interval.
38161
+ *
38162
+ * Override in subclass for custom polling behavior.
38163
+ *
38164
+ * @example
38165
+ * ```typescript
38166
+ * // Start polling with config interval
38167
+ * service.startPolling();
38168
+ *
38169
+ * // Or override in subclass for custom behavior
38170
+ * startPolling(): void {
38171
+ * super.startPolling();
38172
+ * // Custom polling logic
38173
+ * }
38174
+ * ```
38175
+ */
38176
+ startPolling() {
38177
+ if (this._pollingTimer) return;
38178
+ const interval = this.config.pollingInterval || DEFAULT_POLLING_INTERVAL_MS;
38179
+ this._pollingTimer = setInterval(() => {
38180
+ this.fetchAll().catch((error) => {
38181
+ this.logError("Polling fetch failed", { error });
38182
+ });
38183
+ }, interval);
38184
+ this.logDebug("Polling started", { interval });
38185
+ }
38186
+ /**
38187
+ * Stop polling.
38188
+ * Safe to call even if polling is not active.
38189
+ */
38190
+ stopPolling() {
38191
+ if (this._pollingTimer) {
38192
+ clearInterval(this._pollingTimer);
38193
+ this._pollingTimer = null;
38194
+ this.logDebug("Polling stopped");
38195
+ }
38196
+ }
38197
+ // ─────────────────────────────────────────────────────────────────────────
38198
+ // Lifecycle Management
38199
+ // ─────────────────────────────────────────────────────────────────────────
38200
+ /**
38201
+ * Dispose service and cleanup resources.
38202
+ * Stops polling and performs base cleanup.
38203
+ *
38204
+ * Subclasses should override and call super.dispose() to ensure cleanup.
38205
+ *
38206
+ * @example
38207
+ * ```typescript
38208
+ * dispose(): void {
38209
+ * // Custom cleanup
38210
+ * this.customCleanup();
38211
+ * // Always call super
38212
+ * super.dispose();
38213
+ * }
38214
+ * ```
38215
+ */
38216
+ dispose() {
38217
+ this.stopPolling();
38218
+ this.logInfo("Service disposed");
38219
+ }
38220
+ /**
38221
+ * Check if service is available.
38222
+ * Override in subclass for custom availability checks.
38223
+ *
38224
+ * @returns true if service is enabled and in a browser environment
38225
+ */
38226
+ isAvailable() {
38227
+ return this.isServiceEnabled && typeof window !== "undefined";
38228
+ }
38229
+ // ─────────────────────────────────────────────────────────────────────────
38143
38230
  // Error Handling Helpers
38144
38231
  // ─────────────────────────────────────────────────────────────────────────
38145
38232
  /**
@@ -45420,7 +45507,6 @@ var BackendExampleDomainService = class _BackendExampleDomainService extends Bas
45420
45507
  // ─────────────────────────────────────────────────────────────────────────
45421
45508
  };
45422
45509
  var backendExampleDomainService = new BackendExampleDomainService();
45423
- var DEFAULT_POLLING_INTERVAL_MS = 3e4;
45424
45510
  var FrontendExampleDomainService = class _FrontendExampleDomainService extends BaseFrontendDomainService {
45425
45511
  // ─────────────────────────────────────────────────────────────────────────
45426
45512
  // Constructor
@@ -45495,15 +45581,6 @@ var FrontendExampleDomainService = class _FrontendExampleDomainService extends B
45495
45581
  * Required by BaseFrontendDomainService
45496
45582
  */
45497
45583
  this.eventPrefix = "example";
45498
- /**
45499
- * Read-only store keys - inherits error and featureFlags from base
45500
- * No need to redeclare them - they're always included by default
45501
- */
45502
- // protected readStoreKeys = [...super.readStoreKeys]; // Already includes ERROR, FEATURE_FLAGS
45503
- // ─────────────────────────────────────────────────────────────────────────
45504
- // Domain-Specific Properties
45505
- // ─────────────────────────────────────────────────────────────────────────
45506
- this.pollingTimer = null;
45507
45584
  if (this.config.pollingInterval && this.config.pollingInterval > 0) {
45508
45585
  this.startPolling();
45509
45586
  }
@@ -45512,6 +45589,11 @@ var FrontendExampleDomainService = class _FrontendExampleDomainService extends B
45512
45589
  __name(this, "FrontendExampleDomainService");
45513
45590
  }
45514
45591
  static {
45592
+ /**
45593
+ * Read-only store keys - inherits error and featureFlags from base
45594
+ * No need to redeclare them - they're always included by default
45595
+ */
45596
+ // protected readStoreKeys = [...super.readStoreKeys]; // Already includes ERROR, FEATURE_FLAGS
45515
45597
  // ─────────────────────────────────────────────────────────────────────────
45516
45598
  // Static: Service Registry Interface
45517
45599
  // ─────────────────────────────────────────────────────────────────────────
@@ -45545,18 +45627,10 @@ var FrontendExampleDomainService = class _FrontendExampleDomainService extends B
45545
45627
  return service;
45546
45628
  }
45547
45629
  // ─────────────────────────────────────────────────────────────────────────
45548
- // Abstract Implementations (Required by BaseDomainService)
45549
- // ─────────────────────────────────────────────────────────────────────────
45550
- isAvailable() {
45551
- return this.isServiceEnabled && typeof window !== "undefined";
45552
- }
45553
- dispose() {
45554
- this.stopPolling();
45555
- this.logInfo("Service disposed");
45556
- }
45557
- // ─────────────────────────────────────────────────────────────────────────
45558
45630
  // Lifecycle Hooks (Optional Override Examples)
45559
45631
  // ─────────────────────────────────────────────────────────────────────────
45632
+ // Note: isAvailable(), dispose(), startPolling(), stopPolling() are inherited
45633
+ // from BaseFrontendDomainService. Override here only if custom behavior needed.
45560
45634
  /**
45561
45635
  * After fetchAll - emit event (store sync handled automatically)
45562
45636
  * Note: Base class automatically calls syncToStores() which uses storeHandlers
@@ -45604,35 +45678,9 @@ var FrontendExampleDomainService = class _FrontendExampleDomainService extends B
45604
45678
  return CoreEventManager.on(event, handler);
45605
45679
  }
45606
45680
  // ─────────────────────────────────────────────────────────────────────────
45607
- // Polling (Domain-Specific Feature)
45608
- // ─────────────────────────────────────────────────────────────────────────
45609
- /**
45610
- * Start polling for updates
45611
- * Domain-specific feature - not part of base class
45612
- */
45613
- startPolling() {
45614
- if (this.pollingTimer) return;
45615
- const interval = this.config.pollingInterval ?? DEFAULT_POLLING_INTERVAL_MS;
45616
- this.pollingTimer = setInterval(() => {
45617
- this.fetchAll().catch((error) => {
45618
- this.logError("Polling fetch failed", { error });
45619
- });
45620
- }, interval);
45621
- this.logDebug("Polling started", { interval });
45622
- }
45623
- /**
45624
- * Stop polling
45625
- */
45626
- stopPolling() {
45627
- if (this.pollingTimer) {
45628
- clearInterval(this.pollingTimer);
45629
- this.pollingTimer = null;
45630
- this.logDebug("Polling stopped");
45631
- }
45632
- }
45633
- // ─────────────────────────────────────────────────────────────────────────
45634
45681
  // Demo Methods - fetchAll() with Query Examples
45635
45682
  // ─────────────────────────────────────────────────────────────────────────
45683
+ // Note: startPolling() and stopPolling() are inherited from BaseFrontendDomainService
45636
45684
  /**
45637
45685
  * Demo: Fetch all examples with optional filters
45638
45686
  * Demonstrates the fetchAll() method with typed query parameters