@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
package/dist/index.mjs
CHANGED
|
@@ -4857,6 +4857,43 @@ var BaseFrontendDomainService = class extends BaseDomainService {
|
|
|
4857
4857
|
}
|
|
4858
4858
|
}
|
|
4859
4859
|
// ─────────────────────────────────────────────────────────────────────────
|
|
4860
|
+
// Response Unwrapping
|
|
4861
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
4862
|
+
/**
|
|
4863
|
+
* Unwrap response data if responseDataKey is configured.
|
|
4864
|
+
*
|
|
4865
|
+
* Handles wrapped API responses (e.g., SuccessResponseStandard) by extracting
|
|
4866
|
+
* the actual data from a nested property. Supports nested keys with dot notation.
|
|
4867
|
+
*
|
|
4868
|
+
* @param data - Raw response data from fetcher
|
|
4869
|
+
* @returns Unwrapped data or original data if no key configured
|
|
4870
|
+
*
|
|
4871
|
+
* @example
|
|
4872
|
+
* ```typescript
|
|
4873
|
+
* // Simple key: responseDataKey: 'data'
|
|
4874
|
+
* // Input: { success: true, message: '...', data: [...], codeStatus: 200 }
|
|
4875
|
+
* // Output: [...]
|
|
4876
|
+
*
|
|
4877
|
+
* // Nested key: responseDataKey: 'data.items'
|
|
4878
|
+
* // Input: { data: { items: [...], total: 100 } }
|
|
4879
|
+
* // Output: [...]
|
|
4880
|
+
* ```
|
|
4881
|
+
*/
|
|
4882
|
+
unwrapResponseData(data) {
|
|
4883
|
+
const key = this.config.responseDataKey;
|
|
4884
|
+
if (!key) return data;
|
|
4885
|
+
const keys = key.split(".");
|
|
4886
|
+
let result = data;
|
|
4887
|
+
for (const k of keys) {
|
|
4888
|
+
if (result && typeof result === "object" && k in result) {
|
|
4889
|
+
result = result[k];
|
|
4890
|
+
} else {
|
|
4891
|
+
return data;
|
|
4892
|
+
}
|
|
4893
|
+
}
|
|
4894
|
+
return result;
|
|
4895
|
+
}
|
|
4896
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
4860
4897
|
// Generic CRUD Operations
|
|
4861
4898
|
// ─────────────────────────────────────────────────────────────────────────
|
|
4862
4899
|
/**
|
|
@@ -4921,7 +4958,8 @@ var BaseFrontendDomainService = class extends BaseDomainService {
|
|
|
4921
4958
|
}
|
|
4922
4959
|
);
|
|
4923
4960
|
}
|
|
4924
|
-
const
|
|
4961
|
+
const rawData = this.unwrapResponseData(response.data);
|
|
4962
|
+
const entities = (rawData ?? []).map((dto) => this.mapper.toDomain(dto));
|
|
4925
4963
|
this.syncEntitiesToStore(entities);
|
|
4926
4964
|
await this.afterFetchAll?.(entities, query);
|
|
4927
4965
|
this.emitEvent("fetched", {
|
|
@@ -4973,7 +5011,8 @@ var BaseFrontendDomainService = class extends BaseDomainService {
|
|
|
4973
5011
|
cause: response.error ?? void 0
|
|
4974
5012
|
});
|
|
4975
5013
|
}
|
|
4976
|
-
const
|
|
5014
|
+
const rawData = this.unwrapResponseData(response.data);
|
|
5015
|
+
const entity = rawData ? this.mapper.toDomain(rawData) : null;
|
|
4977
5016
|
if (entity) {
|
|
4978
5017
|
await this.afterFetchById?.(entity);
|
|
4979
5018
|
}
|
|
@@ -5055,7 +5094,8 @@ var BaseFrontendDomainService = class extends BaseDomainService {
|
|
|
5055
5094
|
}
|
|
5056
5095
|
);
|
|
5057
5096
|
}
|
|
5058
|
-
const
|
|
5097
|
+
const rawData = this.unwrapResponseData(response.data);
|
|
5098
|
+
const entity = this.mapper.toDomain(rawData);
|
|
5059
5099
|
let storeState;
|
|
5060
5100
|
if (isOptimistic && optimisticEntity) {
|
|
5061
5101
|
const tempId = optimisticEntity.id;
|
|
@@ -5148,7 +5188,8 @@ var BaseFrontendDomainService = class extends BaseDomainService {
|
|
|
5148
5188
|
}
|
|
5149
5189
|
);
|
|
5150
5190
|
}
|
|
5151
|
-
const
|
|
5191
|
+
const rawData = this.unwrapResponseData(response.data);
|
|
5192
|
+
const serverEntity = this.mapper.toDomain(rawData);
|
|
5152
5193
|
let finalEntity = serverEntity;
|
|
5153
5194
|
if (isOptimistic && optimisticStoreState) {
|
|
5154
5195
|
finalEntity = this.resolveConflict({ id, ...data }, serverEntity);
|
|
@@ -12574,14 +12615,15 @@ var FrontendExampleDomainService = class _FrontendExampleDomainService extends B
|
|
|
12574
12615
|
autoFetch: false,
|
|
12575
12616
|
pollingInterval: 0,
|
|
12576
12617
|
...config,
|
|
12618
|
+
// Unwrap SuccessResponseStandard: { success, message, data, codeStatus }
|
|
12619
|
+
// Base class will extract 'data' property automatically
|
|
12620
|
+
responseDataKey: "data",
|
|
12577
12621
|
// Fetchers - using apiClient directly for testing/example purposes
|
|
12578
12622
|
// In production, these would be imported from @plyaz/api services
|
|
12579
12623
|
// Note: Validation is handled by validator class, mapping by mapper class
|
|
12580
12624
|
fetchers: {
|
|
12581
12625
|
fetchAll: /* @__PURE__ */ __name(async (query) => {
|
|
12582
|
-
return this.apiClient.get(apiBasePath, {
|
|
12583
|
-
params: query
|
|
12584
|
-
});
|
|
12626
|
+
return this.apiClient.get(apiBasePath, { params: query });
|
|
12585
12627
|
}, "fetchAll"),
|
|
12586
12628
|
fetchById: /* @__PURE__ */ __name(async (id) => {
|
|
12587
12629
|
return this.apiClient.get(`${apiBasePath}/${id}`);
|
|
@@ -12591,10 +12633,7 @@ var FrontendExampleDomainService = class _FrontendExampleDomainService extends B
|
|
|
12591
12633
|
}, "create"),
|
|
12592
12634
|
update: /* @__PURE__ */ __name(async (payload) => {
|
|
12593
12635
|
const { id, data } = payload;
|
|
12594
|
-
return this.apiClient.patch(
|
|
12595
|
-
`${apiBasePath}/${id}`,
|
|
12596
|
-
data
|
|
12597
|
-
);
|
|
12636
|
+
return this.apiClient.patch(`${apiBasePath}/${id}`, data);
|
|
12598
12637
|
}, "update"),
|
|
12599
12638
|
delete: /* @__PURE__ */ __name(async (id) => {
|
|
12600
12639
|
return this.apiClient.delete(`${apiBasePath}/${id}`);
|