@plyaz/core 1.8.1 → 1.8.2

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.
@@ -2391,10 +2391,16 @@ var init_ServiceRegistry = __esm({
2391
2391
  return initPromise;
2392
2392
  }
2393
2393
  /** Build stores for service injection */
2394
- static buildStoresForService(config) {
2394
+ // eslint-disable-next-line complexity
2395
+ static buildStoresForService(config, entry) {
2395
2396
  const allKeys = /* @__PURE__ */ new Set();
2396
2397
  if (config.store) {
2397
2398
  allKeys.add(config.store);
2399
+ } else if ("primaryStoreKey" in entry.service && typeof entry.service.primaryStoreKey === "string") {
2400
+ allKeys.add(entry.service.primaryStoreKey);
2401
+ _ServiceRegistry.logger.debug(
2402
+ `Auto-resolved store key '${entry.service.primaryStoreKey}' from service class`
2403
+ );
2398
2404
  }
2399
2405
  if (config.readStores) {
2400
2406
  config.readStores.forEach((key) => allKeys.add(key));
@@ -2432,7 +2438,7 @@ var init_ServiceRegistry = __esm({
2432
2438
  const observability = _ServiceRegistry.buildObservabilityConfig(config, entry);
2433
2439
  const storage = await _ServiceRegistry.buildStorageConfig(config, entry);
2434
2440
  const notifications = await _ServiceRegistry.buildNotificationsConfig(config, entry);
2435
- const stores = _ServiceRegistry.buildStoresForService(config);
2441
+ const stores = _ServiceRegistry.buildStoresForService(config, entry);
2436
2442
  let observabilityInstance = observability?.instance;
2437
2443
  if (observability?.dedicated && observability.config) {
2438
2444
  observabilityInstance = await _ServiceRegistry.createDedicatedObservability(
@@ -4439,13 +4445,14 @@ var init_BaseFrontendDomainService = __esm({
4439
4445
  init_BaseDomainService();
4440
4446
  init_CoreEventManager();
4441
4447
  init_CoreInitializer();
4442
- BaseFrontendDomainService = class extends BaseDomainService {
4448
+ BaseFrontendDomainService = class _BaseFrontendDomainService extends BaseDomainService {
4443
4449
  // ─────────────────────────────────────────────────────────────────────────
4444
4450
  // Constructor
4445
4451
  // ─────────────────────────────────────────────────────────────────────────
4446
4452
  // eslint-disable-next-line complexity
4447
4453
  constructor(config) {
4448
- super(config);
4454
+ const resolvedConfig = _BaseFrontendDomainService.resolveApiClientConfig(config);
4455
+ super(resolvedConfig);
4449
4456
  // ─────────────────────────────────────────────────────────────────────────
4450
4457
  // Store Properties
4451
4458
  // ─────────────────────────────────────────────────────────────────────────
@@ -4471,6 +4478,11 @@ var init_BaseFrontendDomainService = __esm({
4471
4478
  const serviceConfig = config.serviceConfig;
4472
4479
  if (serviceConfig.store !== void 0) {
4473
4480
  this.primaryStoreKey = serviceConfig.store;
4481
+ } else {
4482
+ const staticKey = this.constructor.primaryStoreKey;
4483
+ if (staticKey) {
4484
+ this.primaryStoreKey = staticKey;
4485
+ }
4474
4486
  }
4475
4487
  if (serviceConfig.readStores !== void 0) {
4476
4488
  this.readStoreKeys = Array.from(
@@ -4516,6 +4528,36 @@ var init_BaseFrontendDomainService = __esm({
4516
4528
  static {
4517
4529
  __name(this, "BaseFrontendDomainService");
4518
4530
  }
4531
+ /**
4532
+ * Auto-resolve apiClientConfig from serviceConfig.apiBasePath if not explicitly provided.
4533
+ * This reduces boilerplate in child services - they only need to set apiBasePath in config.
4534
+ *
4535
+ * Priority:
4536
+ * 1. Explicit apiClientConfig.baseURL (full control)
4537
+ * 2. serviceConfig.apiBasePath (auto-constructed, merged with injected options)
4538
+ * 3. undefined (no API client)
4539
+ *
4540
+ * When auto-constructing, merges injected API options (headers, timeout, etc.)
4541
+ * with the service's apiBasePath as baseURL.
4542
+ */
4543
+ static resolveApiClientConfig(config) {
4544
+ if (config.apiClientConfig?.baseURL) {
4545
+ return config;
4546
+ }
4547
+ const apiBasePath = config.serviceConfig.apiBasePath;
4548
+ if (apiBasePath) {
4549
+ const injectedOptions = config.injected?.api ? {} : config.apiClientConfig ?? {};
4550
+ return {
4551
+ ...config,
4552
+ apiClientConfig: {
4553
+ ...injectedOptions,
4554
+ baseURL: apiBasePath
4555
+ // Service's apiBasePath always takes precedence
4556
+ }
4557
+ };
4558
+ }
4559
+ return config;
4560
+ }
4519
4561
  // ─────────────────────────────────────────────────────────────────────────
4520
4562
  // Store Management (Public API)
4521
4563
  // ─────────────────────────────────────────────────────────────────────────
@@ -7747,8 +7789,6 @@ var init_FrontendExampleDomainService = __esm({
7747
7789
  super({
7748
7790
  serviceName: "ExampleFrontendService",
7749
7791
  supportedRuntimes: ["frontend"],
7750
- // API client config - uses injected options or creates from apiBasePath
7751
- apiClientConfig: options?.apiClient?.options ?? { baseURL: apiBasePath },
7752
7792
  serviceConfig: {
7753
7793
  enabled: true,
7754
7794
  apiBasePath,
@@ -7812,10 +7852,6 @@ var init_FrontendExampleDomainService = __esm({
7812
7852
  * Required by BaseFrontendDomainService
7813
7853
  */
7814
7854
  this.eventPrefix = "example";
7815
- /**
7816
- * Primary store key - the store this service can mutate
7817
- */
7818
- this.primaryStoreKey = STORE_KEYS.EXAMPLE;
7819
7855
  /**
7820
7856
  * Read-only store keys - inherits error and featureFlags from base
7821
7857
  * No need to redeclare them - they're always included by default
@@ -7838,6 +7874,14 @@ var init_FrontendExampleDomainService = __esm({
7838
7874
  // ─────────────────────────────────────────────────────────────────────────
7839
7875
  this.serviceKey = SERVICE_KEYS.EXAMPLE_FRONTEND;
7840
7876
  }
7877
+ static {
7878
+ /**
7879
+ * Primary store key for this service.
7880
+ * Used by ServiceRegistry to auto-inject the store if not specified in config.
7881
+ * Also used by base class constructor to set instance primaryStoreKey.
7882
+ */
7883
+ this.primaryStoreKey = STORE_KEYS.EXAMPLE;
7884
+ }
7841
7885
  /**
7842
7886
  * Factory method for ServiceRegistry auto-initialization.
7843
7887
  * Creates and initializes the service instance.