@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/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 +68 -12
- package/dist/entry-backend.js.map +1 -1
- package/dist/entry-backend.mjs +68 -12
- package/dist/entry-backend.mjs.map +1 -1
- package/dist/entry-frontend-browser.js +68 -12
- package/dist/entry-frontend-browser.js.map +1 -1
- package/dist/entry-frontend-browser.mjs +68 -12
- package/dist/entry-frontend-browser.mjs.map +1 -1
- package/dist/entry-frontend.js +68 -12
- package/dist/entry-frontend.js.map +1 -1
- package/dist/entry-frontend.mjs +68 -12
- package/dist/entry-frontend.mjs.map +1 -1
- package/dist/index.js +68 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +68 -12
- package/dist/index.mjs.map +1 -1
- package/dist/init/CoreInitializer.d.ts +8 -0
- package/dist/init/CoreInitializer.d.ts.map +1 -1
- package/dist/init/nestjs/index.js +18 -1
- package/dist/init/nestjs/index.js.map +1 -1
- package/dist/init/nestjs/index.mjs +18 -1
- package/dist/init/nestjs/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/entry-frontend.mjs
CHANGED
|
@@ -2562,16 +2562,32 @@ var Core = class _Core {
|
|
|
2562
2562
|
*/
|
|
2563
2563
|
this._logger = null;
|
|
2564
2564
|
}
|
|
2565
|
+
static {
|
|
2566
|
+
/**
|
|
2567
|
+
* Logger transport config (set during initialize)
|
|
2568
|
+
*/
|
|
2569
|
+
this._loggerTransport = "pino";
|
|
2570
|
+
}
|
|
2565
2571
|
/**
|
|
2566
2572
|
* Get or create the Core logger
|
|
2567
2573
|
*/
|
|
2568
2574
|
static get logger() {
|
|
2569
2575
|
_Core._logger ??= new PackageLogger({
|
|
2570
2576
|
packageName: "core",
|
|
2571
|
-
service: "Core"
|
|
2577
|
+
service: "Core",
|
|
2578
|
+
transport: _Core._loggerTransport
|
|
2572
2579
|
});
|
|
2573
2580
|
return _Core._logger;
|
|
2574
2581
|
}
|
|
2582
|
+
/**
|
|
2583
|
+
* Configure logger transport (call before first log)
|
|
2584
|
+
*/
|
|
2585
|
+
static configureLogger(transport) {
|
|
2586
|
+
if (transport && transport !== _Core._loggerTransport) {
|
|
2587
|
+
_Core._loggerTransport = transport;
|
|
2588
|
+
_Core._logger = null;
|
|
2589
|
+
}
|
|
2590
|
+
}
|
|
2575
2591
|
/**
|
|
2576
2592
|
* Log a message during initialization.
|
|
2577
2593
|
* Uses PackageLogger, respects verbose flag.
|
|
@@ -2863,6 +2879,7 @@ var Core = class _Core {
|
|
|
2863
2879
|
* Initialize all core services
|
|
2864
2880
|
*/
|
|
2865
2881
|
static async initialize(options = {}) {
|
|
2882
|
+
_Core.configureLogger(options.logger?.transport);
|
|
2866
2883
|
if (_Core.initialized) {
|
|
2867
2884
|
_Core.log("Already initialized, returning existing services", options.verbose);
|
|
2868
2885
|
return _Core._coreServices;
|
|
@@ -4627,6 +4644,43 @@ var BaseFrontendDomainService = class extends BaseDomainService {
|
|
|
4627
4644
|
}
|
|
4628
4645
|
}
|
|
4629
4646
|
// ─────────────────────────────────────────────────────────────────────────
|
|
4647
|
+
// Response Unwrapping
|
|
4648
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
4649
|
+
/**
|
|
4650
|
+
* Unwrap response data if responseDataKey is configured.
|
|
4651
|
+
*
|
|
4652
|
+
* Handles wrapped API responses (e.g., SuccessResponseStandard) by extracting
|
|
4653
|
+
* the actual data from a nested property. Supports nested keys with dot notation.
|
|
4654
|
+
*
|
|
4655
|
+
* @param data - Raw response data from fetcher
|
|
4656
|
+
* @returns Unwrapped data or original data if no key configured
|
|
4657
|
+
*
|
|
4658
|
+
* @example
|
|
4659
|
+
* ```typescript
|
|
4660
|
+
* // Simple key: responseDataKey: 'data'
|
|
4661
|
+
* // Input: { success: true, message: '...', data: [...], codeStatus: 200 }
|
|
4662
|
+
* // Output: [...]
|
|
4663
|
+
*
|
|
4664
|
+
* // Nested key: responseDataKey: 'data.items'
|
|
4665
|
+
* // Input: { data: { items: [...], total: 100 } }
|
|
4666
|
+
* // Output: [...]
|
|
4667
|
+
* ```
|
|
4668
|
+
*/
|
|
4669
|
+
unwrapResponseData(data) {
|
|
4670
|
+
const key = this.config.responseDataKey;
|
|
4671
|
+
if (!key) return data;
|
|
4672
|
+
const keys = key.split(".");
|
|
4673
|
+
let result = data;
|
|
4674
|
+
for (const k of keys) {
|
|
4675
|
+
if (result && typeof result === "object" && k in result) {
|
|
4676
|
+
result = result[k];
|
|
4677
|
+
} else {
|
|
4678
|
+
return data;
|
|
4679
|
+
}
|
|
4680
|
+
}
|
|
4681
|
+
return result;
|
|
4682
|
+
}
|
|
4683
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
4630
4684
|
// Generic CRUD Operations
|
|
4631
4685
|
// ─────────────────────────────────────────────────────────────────────────
|
|
4632
4686
|
/**
|
|
@@ -4691,7 +4745,8 @@ var BaseFrontendDomainService = class extends BaseDomainService {
|
|
|
4691
4745
|
}
|
|
4692
4746
|
);
|
|
4693
4747
|
}
|
|
4694
|
-
const
|
|
4748
|
+
const rawData = this.unwrapResponseData(response.data);
|
|
4749
|
+
const entities = (rawData ?? []).map((dto) => this.mapper.toDomain(dto));
|
|
4695
4750
|
this.syncEntitiesToStore(entities);
|
|
4696
4751
|
await this.afterFetchAll?.(entities, query);
|
|
4697
4752
|
this.emitEvent("fetched", {
|
|
@@ -4743,7 +4798,8 @@ var BaseFrontendDomainService = class extends BaseDomainService {
|
|
|
4743
4798
|
cause: response.error ?? void 0
|
|
4744
4799
|
});
|
|
4745
4800
|
}
|
|
4746
|
-
const
|
|
4801
|
+
const rawData = this.unwrapResponseData(response.data);
|
|
4802
|
+
const entity = rawData ? this.mapper.toDomain(rawData) : null;
|
|
4747
4803
|
if (entity) {
|
|
4748
4804
|
await this.afterFetchById?.(entity);
|
|
4749
4805
|
}
|
|
@@ -4825,7 +4881,8 @@ var BaseFrontendDomainService = class extends BaseDomainService {
|
|
|
4825
4881
|
}
|
|
4826
4882
|
);
|
|
4827
4883
|
}
|
|
4828
|
-
const
|
|
4884
|
+
const rawData = this.unwrapResponseData(response.data);
|
|
4885
|
+
const entity = this.mapper.toDomain(rawData);
|
|
4829
4886
|
let storeState;
|
|
4830
4887
|
if (isOptimistic && optimisticEntity) {
|
|
4831
4888
|
const tempId = optimisticEntity.id;
|
|
@@ -4918,7 +4975,8 @@ var BaseFrontendDomainService = class extends BaseDomainService {
|
|
|
4918
4975
|
}
|
|
4919
4976
|
);
|
|
4920
4977
|
}
|
|
4921
|
-
const
|
|
4978
|
+
const rawData = this.unwrapResponseData(response.data);
|
|
4979
|
+
const serverEntity = this.mapper.toDomain(rawData);
|
|
4922
4980
|
let finalEntity = serverEntity;
|
|
4923
4981
|
if (isOptimistic && optimisticStoreState) {
|
|
4924
4982
|
finalEntity = this.resolveConflict({ id, ...data }, serverEntity);
|
|
@@ -5945,14 +6003,15 @@ var FrontendExampleDomainService = class _FrontendExampleDomainService extends B
|
|
|
5945
6003
|
autoFetch: false,
|
|
5946
6004
|
pollingInterval: 0,
|
|
5947
6005
|
...config,
|
|
6006
|
+
// Unwrap SuccessResponseStandard: { success, message, data, codeStatus }
|
|
6007
|
+
// Base class will extract 'data' property automatically
|
|
6008
|
+
responseDataKey: "data",
|
|
5948
6009
|
// Fetchers - using apiClient directly for testing/example purposes
|
|
5949
6010
|
// In production, these would be imported from @plyaz/api services
|
|
5950
6011
|
// Note: Validation is handled by validator class, mapping by mapper class
|
|
5951
6012
|
fetchers: {
|
|
5952
6013
|
fetchAll: /* @__PURE__ */ __name(async (query) => {
|
|
5953
|
-
return this.apiClient.get(apiBasePath, {
|
|
5954
|
-
params: query
|
|
5955
|
-
});
|
|
6014
|
+
return this.apiClient.get(apiBasePath, { params: query });
|
|
5956
6015
|
}, "fetchAll"),
|
|
5957
6016
|
fetchById: /* @__PURE__ */ __name(async (id) => {
|
|
5958
6017
|
return this.apiClient.get(`${apiBasePath}/${id}`);
|
|
@@ -5962,10 +6021,7 @@ var FrontendExampleDomainService = class _FrontendExampleDomainService extends B
|
|
|
5962
6021
|
}, "create"),
|
|
5963
6022
|
update: /* @__PURE__ */ __name(async (payload) => {
|
|
5964
6023
|
const { id, data } = payload;
|
|
5965
|
-
return this.apiClient.patch(
|
|
5966
|
-
`${apiBasePath}/${id}`,
|
|
5967
|
-
data
|
|
5968
|
-
);
|
|
6024
|
+
return this.apiClient.patch(`${apiBasePath}/${id}`, data);
|
|
5969
6025
|
}, "update"),
|
|
5970
6026
|
delete: /* @__PURE__ */ __name(async (id) => {
|
|
5971
6027
|
return this.apiClient.delete(`${apiBasePath}/${id}`);
|