@plyaz/core 1.5.21 → 1.7.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.
package/dist/index.js CHANGED
@@ -35684,16 +35684,32 @@ var Core = class _Core {
35684
35684
  */
35685
35685
  this._logger = null;
35686
35686
  }
35687
+ static {
35688
+ /**
35689
+ * Logger transport config (set during initialize)
35690
+ */
35691
+ this._loggerTransport = "pino";
35692
+ }
35687
35693
  /**
35688
35694
  * Get or create the Core logger
35689
35695
  */
35690
35696
  static get logger() {
35691
35697
  _Core._logger ??= new logger$1.PackageLogger({
35692
35698
  packageName: "core",
35693
- service: "Core"
35699
+ service: "Core",
35700
+ transport: _Core._loggerTransport
35694
35701
  });
35695
35702
  return _Core._logger;
35696
35703
  }
35704
+ /**
35705
+ * Configure logger transport (call before first log)
35706
+ */
35707
+ static configureLogger(transport) {
35708
+ if (transport && transport !== _Core._loggerTransport) {
35709
+ _Core._loggerTransport = transport;
35710
+ _Core._logger = null;
35711
+ }
35712
+ }
35697
35713
  /**
35698
35714
  * Log a message during initialization.
35699
35715
  * Uses PackageLogger, respects verbose flag.
@@ -35985,6 +36001,7 @@ var Core = class _Core {
35985
36001
  * Initialize all core services
35986
36002
  */
35987
36003
  static async initialize(options = {}) {
36004
+ _Core.configureLogger(options.logger?.transport);
35988
36005
  if (_Core.initialized) {
35989
36006
  _Core.log("Already initialized, returning existing services", options.verbose);
35990
36007
  return _Core._coreServices;
@@ -37353,6 +37370,43 @@ var BaseFrontendDomainService = class extends BaseDomainService {
37353
37370
  }
37354
37371
  }
37355
37372
  // ─────────────────────────────────────────────────────────────────────────
37373
+ // Response Unwrapping
37374
+ // ─────────────────────────────────────────────────────────────────────────
37375
+ /**
37376
+ * Unwrap response data if responseDataKey is configured.
37377
+ *
37378
+ * Handles wrapped API responses (e.g., SuccessResponseStandard) by extracting
37379
+ * the actual data from a nested property. Supports nested keys with dot notation.
37380
+ *
37381
+ * @param data - Raw response data from fetcher
37382
+ * @returns Unwrapped data or original data if no key configured
37383
+ *
37384
+ * @example
37385
+ * ```typescript
37386
+ * // Simple key: responseDataKey: 'data'
37387
+ * // Input: { success: true, message: '...', data: [...], codeStatus: 200 }
37388
+ * // Output: [...]
37389
+ *
37390
+ * // Nested key: responseDataKey: 'data.items'
37391
+ * // Input: { data: { items: [...], total: 100 } }
37392
+ * // Output: [...]
37393
+ * ```
37394
+ */
37395
+ unwrapResponseData(data) {
37396
+ const key = this.config.responseDataKey;
37397
+ if (!key) return data;
37398
+ const keys = key.split(".");
37399
+ let result2 = data;
37400
+ for (const k of keys) {
37401
+ if (result2 && typeof result2 === "object" && k in result2) {
37402
+ result2 = result2[k];
37403
+ } else {
37404
+ return data;
37405
+ }
37406
+ }
37407
+ return result2;
37408
+ }
37409
+ // ─────────────────────────────────────────────────────────────────────────
37356
37410
  // Generic CRUD Operations
37357
37411
  // ─────────────────────────────────────────────────────────────────────────
37358
37412
  /**
@@ -37417,7 +37471,8 @@ var BaseFrontendDomainService = class extends BaseDomainService {
37417
37471
  }
37418
37472
  );
37419
37473
  }
37420
- const entities = (response.data ?? []).map((dto) => this.mapper.toDomain(dto));
37474
+ const rawData = this.unwrapResponseData(response.data);
37475
+ const entities = (rawData ?? []).map((dto) => this.mapper.toDomain(dto));
37421
37476
  this.syncEntitiesToStore(entities);
37422
37477
  await this.afterFetchAll?.(entities, query);
37423
37478
  this.emitEvent("fetched", {
@@ -37469,7 +37524,8 @@ var BaseFrontendDomainService = class extends BaseDomainService {
37469
37524
  cause: response.error ?? void 0
37470
37525
  });
37471
37526
  }
37472
- const entity = response.data ? this.mapper.toDomain(response.data) : null;
37527
+ const rawData = this.unwrapResponseData(response.data);
37528
+ const entity = rawData ? this.mapper.toDomain(rawData) : null;
37473
37529
  if (entity) {
37474
37530
  await this.afterFetchById?.(entity);
37475
37531
  }
@@ -37551,7 +37607,8 @@ var BaseFrontendDomainService = class extends BaseDomainService {
37551
37607
  }
37552
37608
  );
37553
37609
  }
37554
- const entity = this.mapper.toDomain(response.data);
37610
+ const rawData = this.unwrapResponseData(response.data);
37611
+ const entity = this.mapper.toDomain(rawData);
37555
37612
  let storeState;
37556
37613
  if (isOptimistic && optimisticEntity) {
37557
37614
  const tempId = optimisticEntity.id;
@@ -37644,7 +37701,8 @@ var BaseFrontendDomainService = class extends BaseDomainService {
37644
37701
  }
37645
37702
  );
37646
37703
  }
37647
- const serverEntity = this.mapper.toDomain(response.data);
37704
+ const rawData = this.unwrapResponseData(response.data);
37705
+ const serverEntity = this.mapper.toDomain(rawData);
37648
37706
  let finalEntity = serverEntity;
37649
37707
  if (isOptimistic && optimisticStoreState) {
37650
37708
  finalEntity = this.resolveConflict({ id, ...data }, serverEntity);
@@ -45070,14 +45128,15 @@ var FrontendExampleDomainService = class _FrontendExampleDomainService extends B
45070
45128
  autoFetch: false,
45071
45129
  pollingInterval: 0,
45072
45130
  ...config,
45131
+ // Unwrap SuccessResponseStandard: { success, message, data, codeStatus }
45132
+ // Base class will extract 'data' property automatically
45133
+ responseDataKey: "data",
45073
45134
  // Fetchers - using apiClient directly for testing/example purposes
45074
45135
  // In production, these would be imported from @plyaz/api services
45075
45136
  // Note: Validation is handled by validator class, mapping by mapper class
45076
45137
  fetchers: {
45077
45138
  fetchAll: /* @__PURE__ */ __name(async (query) => {
45078
- return this.apiClient.get(apiBasePath, {
45079
- params: query
45080
- });
45139
+ return this.apiClient.get(apiBasePath, { params: query });
45081
45140
  }, "fetchAll"),
45082
45141
  fetchById: /* @__PURE__ */ __name(async (id) => {
45083
45142
  return this.apiClient.get(`${apiBasePath}/${id}`);
@@ -45087,10 +45146,7 @@ var FrontendExampleDomainService = class _FrontendExampleDomainService extends B
45087
45146
  }, "create"),
45088
45147
  update: /* @__PURE__ */ __name(async (payload) => {
45089
45148
  const { id, data } = payload;
45090
- return this.apiClient.patch(
45091
- `${apiBasePath}/${id}`,
45092
- data
45093
- );
45149
+ return this.apiClient.patch(`${apiBasePath}/${id}`, data);
45094
45150
  }, "update"),
45095
45151
  delete: /* @__PURE__ */ __name(async (id) => {
45096
45152
  return this.apiClient.delete(`${apiBasePath}/${id}`);