@plyaz/core 1.5.21 → 1.6.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/domain/base/BaseFrontendDomainService.d.ts +21 -0
- package/dist/domain/base/BaseFrontendDomainService.d.ts.map +1 -1
- package/dist/domain/example/FrontendExampleDomainService.d.ts.map +1 -1
- package/dist/entry-backend.js +50 -11
- package/dist/entry-backend.js.map +1 -1
- package/dist/entry-backend.mjs +50 -11
- package/dist/entry-backend.mjs.map +1 -1
- package/dist/entry-frontend-browser.js +50 -11
- package/dist/entry-frontend-browser.js.map +1 -1
- package/dist/entry-frontend-browser.mjs +50 -11
- package/dist/entry-frontend-browser.mjs.map +1 -1
- package/dist/entry-frontend.js +50 -11
- package/dist/entry-frontend.js.map +1 -1
- package/dist/entry-frontend.mjs +50 -11
- package/dist/entry-frontend.mjs.map +1 -1
- package/dist/index.js +50 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +50 -11
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
|
@@ -4627,6 +4627,43 @@ var BaseFrontendDomainService = class extends BaseDomainService {
|
|
|
4627
4627
|
}
|
|
4628
4628
|
}
|
|
4629
4629
|
// ─────────────────────────────────────────────────────────────────────────
|
|
4630
|
+
// Response Unwrapping
|
|
4631
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
4632
|
+
/**
|
|
4633
|
+
* Unwrap response data if responseDataKey is configured.
|
|
4634
|
+
*
|
|
4635
|
+
* Handles wrapped API responses (e.g., SuccessResponseStandard) by extracting
|
|
4636
|
+
* the actual data from a nested property. Supports nested keys with dot notation.
|
|
4637
|
+
*
|
|
4638
|
+
* @param data - Raw response data from fetcher
|
|
4639
|
+
* @returns Unwrapped data or original data if no key configured
|
|
4640
|
+
*
|
|
4641
|
+
* @example
|
|
4642
|
+
* ```typescript
|
|
4643
|
+
* // Simple key: responseDataKey: 'data'
|
|
4644
|
+
* // Input: { success: true, message: '...', data: [...], codeStatus: 200 }
|
|
4645
|
+
* // Output: [...]
|
|
4646
|
+
*
|
|
4647
|
+
* // Nested key: responseDataKey: 'data.items'
|
|
4648
|
+
* // Input: { data: { items: [...], total: 100 } }
|
|
4649
|
+
* // Output: [...]
|
|
4650
|
+
* ```
|
|
4651
|
+
*/
|
|
4652
|
+
unwrapResponseData(data) {
|
|
4653
|
+
const key = this.config.responseDataKey;
|
|
4654
|
+
if (!key) return data;
|
|
4655
|
+
const keys = key.split(".");
|
|
4656
|
+
let result = data;
|
|
4657
|
+
for (const k of keys) {
|
|
4658
|
+
if (result && typeof result === "object" && k in result) {
|
|
4659
|
+
result = result[k];
|
|
4660
|
+
} else {
|
|
4661
|
+
return data;
|
|
4662
|
+
}
|
|
4663
|
+
}
|
|
4664
|
+
return result;
|
|
4665
|
+
}
|
|
4666
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
4630
4667
|
// Generic CRUD Operations
|
|
4631
4668
|
// ─────────────────────────────────────────────────────────────────────────
|
|
4632
4669
|
/**
|
|
@@ -4691,7 +4728,8 @@ var BaseFrontendDomainService = class extends BaseDomainService {
|
|
|
4691
4728
|
}
|
|
4692
4729
|
);
|
|
4693
4730
|
}
|
|
4694
|
-
const
|
|
4731
|
+
const rawData = this.unwrapResponseData(response.data);
|
|
4732
|
+
const entities = (rawData ?? []).map((dto) => this.mapper.toDomain(dto));
|
|
4695
4733
|
this.syncEntitiesToStore(entities);
|
|
4696
4734
|
await this.afterFetchAll?.(entities, query);
|
|
4697
4735
|
this.emitEvent("fetched", {
|
|
@@ -4743,7 +4781,8 @@ var BaseFrontendDomainService = class extends BaseDomainService {
|
|
|
4743
4781
|
cause: response.error ?? void 0
|
|
4744
4782
|
});
|
|
4745
4783
|
}
|
|
4746
|
-
const
|
|
4784
|
+
const rawData = this.unwrapResponseData(response.data);
|
|
4785
|
+
const entity = rawData ? this.mapper.toDomain(rawData) : null;
|
|
4747
4786
|
if (entity) {
|
|
4748
4787
|
await this.afterFetchById?.(entity);
|
|
4749
4788
|
}
|
|
@@ -4825,7 +4864,8 @@ var BaseFrontendDomainService = class extends BaseDomainService {
|
|
|
4825
4864
|
}
|
|
4826
4865
|
);
|
|
4827
4866
|
}
|
|
4828
|
-
const
|
|
4867
|
+
const rawData = this.unwrapResponseData(response.data);
|
|
4868
|
+
const entity = this.mapper.toDomain(rawData);
|
|
4829
4869
|
let storeState;
|
|
4830
4870
|
if (isOptimistic && optimisticEntity) {
|
|
4831
4871
|
const tempId = optimisticEntity.id;
|
|
@@ -4918,7 +4958,8 @@ var BaseFrontendDomainService = class extends BaseDomainService {
|
|
|
4918
4958
|
}
|
|
4919
4959
|
);
|
|
4920
4960
|
}
|
|
4921
|
-
const
|
|
4961
|
+
const rawData = this.unwrapResponseData(response.data);
|
|
4962
|
+
const serverEntity = this.mapper.toDomain(rawData);
|
|
4922
4963
|
let finalEntity = serverEntity;
|
|
4923
4964
|
if (isOptimistic && optimisticStoreState) {
|
|
4924
4965
|
finalEntity = this.resolveConflict({ id, ...data }, serverEntity);
|
|
@@ -5945,14 +5986,15 @@ var FrontendExampleDomainService = class _FrontendExampleDomainService extends B
|
|
|
5945
5986
|
autoFetch: false,
|
|
5946
5987
|
pollingInterval: 0,
|
|
5947
5988
|
...config,
|
|
5989
|
+
// Unwrap SuccessResponseStandard: { success, message, data, codeStatus }
|
|
5990
|
+
// Base class will extract 'data' property automatically
|
|
5991
|
+
responseDataKey: "data",
|
|
5948
5992
|
// Fetchers - using apiClient directly for testing/example purposes
|
|
5949
5993
|
// In production, these would be imported from @plyaz/api services
|
|
5950
5994
|
// Note: Validation is handled by validator class, mapping by mapper class
|
|
5951
5995
|
fetchers: {
|
|
5952
5996
|
fetchAll: /* @__PURE__ */ __name(async (query) => {
|
|
5953
|
-
return this.apiClient.get(apiBasePath, {
|
|
5954
|
-
params: query
|
|
5955
|
-
});
|
|
5997
|
+
return this.apiClient.get(apiBasePath, { params: query });
|
|
5956
5998
|
}, "fetchAll"),
|
|
5957
5999
|
fetchById: /* @__PURE__ */ __name(async (id) => {
|
|
5958
6000
|
return this.apiClient.get(`${apiBasePath}/${id}`);
|
|
@@ -5962,10 +6004,7 @@ var FrontendExampleDomainService = class _FrontendExampleDomainService extends B
|
|
|
5962
6004
|
}, "create"),
|
|
5963
6005
|
update: /* @__PURE__ */ __name(async (payload) => {
|
|
5964
6006
|
const { id, data } = payload;
|
|
5965
|
-
return this.apiClient.patch(
|
|
5966
|
-
`${apiBasePath}/${id}`,
|
|
5967
|
-
data
|
|
5968
|
-
);
|
|
6007
|
+
return this.apiClient.patch(`${apiBasePath}/${id}`, data);
|
|
5969
6008
|
}, "update"),
|
|
5970
6009
|
delete: /* @__PURE__ */ __name(async (id) => {
|
|
5971
6010
|
return this.apiClient.delete(`${apiBasePath}/${id}`);
|