@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.
@@ -2720,16 +2720,32 @@ var init_CoreInitializer = __esm({
2720
2720
  */
2721
2721
  this._logger = null;
2722
2722
  }
2723
+ static {
2724
+ /**
2725
+ * Logger transport config (set during initialize)
2726
+ */
2727
+ this._loggerTransport = "pino";
2728
+ }
2723
2729
  /**
2724
2730
  * Get or create the Core logger
2725
2731
  */
2726
2732
  static get logger() {
2727
2733
  _Core._logger ??= new PackageLogger({
2728
2734
  packageName: "core",
2729
- service: "Core"
2735
+ service: "Core",
2736
+ transport: _Core._loggerTransport
2730
2737
  });
2731
2738
  return _Core._logger;
2732
2739
  }
2740
+ /**
2741
+ * Configure logger transport (call before first log)
2742
+ */
2743
+ static configureLogger(transport) {
2744
+ if (transport && transport !== _Core._loggerTransport) {
2745
+ _Core._loggerTransport = transport;
2746
+ _Core._logger = null;
2747
+ }
2748
+ }
2733
2749
  /**
2734
2750
  * Log a message during initialization.
2735
2751
  * Uses PackageLogger, respects verbose flag.
@@ -3021,6 +3037,7 @@ var init_CoreInitializer = __esm({
3021
3037
  * Initialize all core services
3022
3038
  */
3023
3039
  static async initialize(options = {}) {
3040
+ _Core.configureLogger(options.logger?.transport);
3024
3041
  if (_Core.initialized) {
3025
3042
  _Core.log("Already initialized, returning existing services", options.verbose);
3026
3043
  return _Core._coreServices;
@@ -4798,6 +4815,43 @@ var init_BaseFrontendDomainService = __esm({
4798
4815
  }
4799
4816
  }
4800
4817
  // ─────────────────────────────────────────────────────────────────────────
4818
+ // Response Unwrapping
4819
+ // ─────────────────────────────────────────────────────────────────────────
4820
+ /**
4821
+ * Unwrap response data if responseDataKey is configured.
4822
+ *
4823
+ * Handles wrapped API responses (e.g., SuccessResponseStandard) by extracting
4824
+ * the actual data from a nested property. Supports nested keys with dot notation.
4825
+ *
4826
+ * @param data - Raw response data from fetcher
4827
+ * @returns Unwrapped data or original data if no key configured
4828
+ *
4829
+ * @example
4830
+ * ```typescript
4831
+ * // Simple key: responseDataKey: 'data'
4832
+ * // Input: { success: true, message: '...', data: [...], codeStatus: 200 }
4833
+ * // Output: [...]
4834
+ *
4835
+ * // Nested key: responseDataKey: 'data.items'
4836
+ * // Input: { data: { items: [...], total: 100 } }
4837
+ * // Output: [...]
4838
+ * ```
4839
+ */
4840
+ unwrapResponseData(data) {
4841
+ const key = this.config.responseDataKey;
4842
+ if (!key) return data;
4843
+ const keys = key.split(".");
4844
+ let result = data;
4845
+ for (const k of keys) {
4846
+ if (result && typeof result === "object" && k in result) {
4847
+ result = result[k];
4848
+ } else {
4849
+ return data;
4850
+ }
4851
+ }
4852
+ return result;
4853
+ }
4854
+ // ─────────────────────────────────────────────────────────────────────────
4801
4855
  // Generic CRUD Operations
4802
4856
  // ─────────────────────────────────────────────────────────────────────────
4803
4857
  /**
@@ -4862,7 +4916,8 @@ var init_BaseFrontendDomainService = __esm({
4862
4916
  }
4863
4917
  );
4864
4918
  }
4865
- const entities = (response.data ?? []).map((dto) => this.mapper.toDomain(dto));
4919
+ const rawData = this.unwrapResponseData(response.data);
4920
+ const entities = (rawData ?? []).map((dto) => this.mapper.toDomain(dto));
4866
4921
  this.syncEntitiesToStore(entities);
4867
4922
  await this.afterFetchAll?.(entities, query);
4868
4923
  this.emitEvent("fetched", {
@@ -4914,7 +4969,8 @@ var init_BaseFrontendDomainService = __esm({
4914
4969
  cause: response.error ?? void 0
4915
4970
  });
4916
4971
  }
4917
- const entity = response.data ? this.mapper.toDomain(response.data) : null;
4972
+ const rawData = this.unwrapResponseData(response.data);
4973
+ const entity = rawData ? this.mapper.toDomain(rawData) : null;
4918
4974
  if (entity) {
4919
4975
  await this.afterFetchById?.(entity);
4920
4976
  }
@@ -4996,7 +5052,8 @@ var init_BaseFrontendDomainService = __esm({
4996
5052
  }
4997
5053
  );
4998
5054
  }
4999
- const entity = this.mapper.toDomain(response.data);
5055
+ const rawData = this.unwrapResponseData(response.data);
5056
+ const entity = this.mapper.toDomain(rawData);
5000
5057
  let storeState;
5001
5058
  if (isOptimistic && optimisticEntity) {
5002
5059
  const tempId = optimisticEntity.id;
@@ -5089,7 +5146,8 @@ var init_BaseFrontendDomainService = __esm({
5089
5146
  }
5090
5147
  );
5091
5148
  }
5092
- const serverEntity = this.mapper.toDomain(response.data);
5149
+ const rawData = this.unwrapResponseData(response.data);
5150
+ const serverEntity = this.mapper.toDomain(rawData);
5093
5151
  let finalEntity = serverEntity;
5094
5152
  if (isOptimistic && optimisticStoreState) {
5095
5153
  finalEntity = this.resolveConflict({ id, ...data }, serverEntity);
@@ -7570,14 +7628,15 @@ var init_FrontendExampleDomainService = __esm({
7570
7628
  autoFetch: false,
7571
7629
  pollingInterval: 0,
7572
7630
  ...config,
7631
+ // Unwrap SuccessResponseStandard: { success, message, data, codeStatus }
7632
+ // Base class will extract 'data' property automatically
7633
+ responseDataKey: "data",
7573
7634
  // Fetchers - using apiClient directly for testing/example purposes
7574
7635
  // In production, these would be imported from @plyaz/api services
7575
7636
  // Note: Validation is handled by validator class, mapping by mapper class
7576
7637
  fetchers: {
7577
7638
  fetchAll: /* @__PURE__ */ __name(async (query) => {
7578
- return this.apiClient.get(apiBasePath, {
7579
- params: query
7580
- });
7639
+ return this.apiClient.get(apiBasePath, { params: query });
7581
7640
  }, "fetchAll"),
7582
7641
  fetchById: /* @__PURE__ */ __name(async (id) => {
7583
7642
  return this.apiClient.get(`${apiBasePath}/${id}`);
@@ -7587,10 +7646,7 @@ var init_FrontendExampleDomainService = __esm({
7587
7646
  }, "create"),
7588
7647
  update: /* @__PURE__ */ __name(async (payload) => {
7589
7648
  const { id, data } = payload;
7590
- return this.apiClient.patch(
7591
- `${apiBasePath}/${id}`,
7592
- data
7593
- );
7649
+ return this.apiClient.patch(`${apiBasePath}/${id}`, data);
7594
7650
  }, "update"),
7595
7651
  delete: /* @__PURE__ */ __name(async (id) => {
7596
7652
  return this.apiClient.delete(`${apiBasePath}/${id}`);