@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/index.mjs
CHANGED
|
@@ -3188,16 +3188,32 @@ var Core = class _Core {
|
|
|
3188
3188
|
*/
|
|
3189
3189
|
this._logger = null;
|
|
3190
3190
|
}
|
|
3191
|
+
static {
|
|
3192
|
+
/**
|
|
3193
|
+
* Logger transport config (set during initialize)
|
|
3194
|
+
*/
|
|
3195
|
+
this._loggerTransport = "pino";
|
|
3196
|
+
}
|
|
3191
3197
|
/**
|
|
3192
3198
|
* Get or create the Core logger
|
|
3193
3199
|
*/
|
|
3194
3200
|
static get logger() {
|
|
3195
3201
|
_Core._logger ??= new PackageLogger({
|
|
3196
3202
|
packageName: "core",
|
|
3197
|
-
service: "Core"
|
|
3203
|
+
service: "Core",
|
|
3204
|
+
transport: _Core._loggerTransport
|
|
3198
3205
|
});
|
|
3199
3206
|
return _Core._logger;
|
|
3200
3207
|
}
|
|
3208
|
+
/**
|
|
3209
|
+
* Configure logger transport (call before first log)
|
|
3210
|
+
*/
|
|
3211
|
+
static configureLogger(transport) {
|
|
3212
|
+
if (transport && transport !== _Core._loggerTransport) {
|
|
3213
|
+
_Core._loggerTransport = transport;
|
|
3214
|
+
_Core._logger = null;
|
|
3215
|
+
}
|
|
3216
|
+
}
|
|
3201
3217
|
/**
|
|
3202
3218
|
* Log a message during initialization.
|
|
3203
3219
|
* Uses PackageLogger, respects verbose flag.
|
|
@@ -3489,6 +3505,7 @@ var Core = class _Core {
|
|
|
3489
3505
|
* Initialize all core services
|
|
3490
3506
|
*/
|
|
3491
3507
|
static async initialize(options = {}) {
|
|
3508
|
+
_Core.configureLogger(options.logger?.transport);
|
|
3492
3509
|
if (_Core.initialized) {
|
|
3493
3510
|
_Core.log("Already initialized, returning existing services", options.verbose);
|
|
3494
3511
|
return _Core._coreServices;
|
|
@@ -4857,6 +4874,43 @@ var BaseFrontendDomainService = class extends BaseDomainService {
|
|
|
4857
4874
|
}
|
|
4858
4875
|
}
|
|
4859
4876
|
// ─────────────────────────────────────────────────────────────────────────
|
|
4877
|
+
// Response Unwrapping
|
|
4878
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
4879
|
+
/**
|
|
4880
|
+
* Unwrap response data if responseDataKey is configured.
|
|
4881
|
+
*
|
|
4882
|
+
* Handles wrapped API responses (e.g., SuccessResponseStandard) by extracting
|
|
4883
|
+
* the actual data from a nested property. Supports nested keys with dot notation.
|
|
4884
|
+
*
|
|
4885
|
+
* @param data - Raw response data from fetcher
|
|
4886
|
+
* @returns Unwrapped data or original data if no key configured
|
|
4887
|
+
*
|
|
4888
|
+
* @example
|
|
4889
|
+
* ```typescript
|
|
4890
|
+
* // Simple key: responseDataKey: 'data'
|
|
4891
|
+
* // Input: { success: true, message: '...', data: [...], codeStatus: 200 }
|
|
4892
|
+
* // Output: [...]
|
|
4893
|
+
*
|
|
4894
|
+
* // Nested key: responseDataKey: 'data.items'
|
|
4895
|
+
* // Input: { data: { items: [...], total: 100 } }
|
|
4896
|
+
* // Output: [...]
|
|
4897
|
+
* ```
|
|
4898
|
+
*/
|
|
4899
|
+
unwrapResponseData(data) {
|
|
4900
|
+
const key = this.config.responseDataKey;
|
|
4901
|
+
if (!key) return data;
|
|
4902
|
+
const keys = key.split(".");
|
|
4903
|
+
let result = data;
|
|
4904
|
+
for (const k of keys) {
|
|
4905
|
+
if (result && typeof result === "object" && k in result) {
|
|
4906
|
+
result = result[k];
|
|
4907
|
+
} else {
|
|
4908
|
+
return data;
|
|
4909
|
+
}
|
|
4910
|
+
}
|
|
4911
|
+
return result;
|
|
4912
|
+
}
|
|
4913
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
4860
4914
|
// Generic CRUD Operations
|
|
4861
4915
|
// ─────────────────────────────────────────────────────────────────────────
|
|
4862
4916
|
/**
|
|
@@ -4921,7 +4975,8 @@ var BaseFrontendDomainService = class extends BaseDomainService {
|
|
|
4921
4975
|
}
|
|
4922
4976
|
);
|
|
4923
4977
|
}
|
|
4924
|
-
const
|
|
4978
|
+
const rawData = this.unwrapResponseData(response.data);
|
|
4979
|
+
const entities = (rawData ?? []).map((dto) => this.mapper.toDomain(dto));
|
|
4925
4980
|
this.syncEntitiesToStore(entities);
|
|
4926
4981
|
await this.afterFetchAll?.(entities, query);
|
|
4927
4982
|
this.emitEvent("fetched", {
|
|
@@ -4973,7 +5028,8 @@ var BaseFrontendDomainService = class extends BaseDomainService {
|
|
|
4973
5028
|
cause: response.error ?? void 0
|
|
4974
5029
|
});
|
|
4975
5030
|
}
|
|
4976
|
-
const
|
|
5031
|
+
const rawData = this.unwrapResponseData(response.data);
|
|
5032
|
+
const entity = rawData ? this.mapper.toDomain(rawData) : null;
|
|
4977
5033
|
if (entity) {
|
|
4978
5034
|
await this.afterFetchById?.(entity);
|
|
4979
5035
|
}
|
|
@@ -5055,7 +5111,8 @@ var BaseFrontendDomainService = class extends BaseDomainService {
|
|
|
5055
5111
|
}
|
|
5056
5112
|
);
|
|
5057
5113
|
}
|
|
5058
|
-
const
|
|
5114
|
+
const rawData = this.unwrapResponseData(response.data);
|
|
5115
|
+
const entity = this.mapper.toDomain(rawData);
|
|
5059
5116
|
let storeState;
|
|
5060
5117
|
if (isOptimistic && optimisticEntity) {
|
|
5061
5118
|
const tempId = optimisticEntity.id;
|
|
@@ -5148,7 +5205,8 @@ var BaseFrontendDomainService = class extends BaseDomainService {
|
|
|
5148
5205
|
}
|
|
5149
5206
|
);
|
|
5150
5207
|
}
|
|
5151
|
-
const
|
|
5208
|
+
const rawData = this.unwrapResponseData(response.data);
|
|
5209
|
+
const serverEntity = this.mapper.toDomain(rawData);
|
|
5152
5210
|
let finalEntity = serverEntity;
|
|
5153
5211
|
if (isOptimistic && optimisticStoreState) {
|
|
5154
5212
|
finalEntity = this.resolveConflict({ id, ...data }, serverEntity);
|
|
@@ -12574,14 +12632,15 @@ var FrontendExampleDomainService = class _FrontendExampleDomainService extends B
|
|
|
12574
12632
|
autoFetch: false,
|
|
12575
12633
|
pollingInterval: 0,
|
|
12576
12634
|
...config,
|
|
12635
|
+
// Unwrap SuccessResponseStandard: { success, message, data, codeStatus }
|
|
12636
|
+
// Base class will extract 'data' property automatically
|
|
12637
|
+
responseDataKey: "data",
|
|
12577
12638
|
// Fetchers - using apiClient directly for testing/example purposes
|
|
12578
12639
|
// In production, these would be imported from @plyaz/api services
|
|
12579
12640
|
// Note: Validation is handled by validator class, mapping by mapper class
|
|
12580
12641
|
fetchers: {
|
|
12581
12642
|
fetchAll: /* @__PURE__ */ __name(async (query) => {
|
|
12582
|
-
return this.apiClient.get(apiBasePath, {
|
|
12583
|
-
params: query
|
|
12584
|
-
});
|
|
12643
|
+
return this.apiClient.get(apiBasePath, { params: query });
|
|
12585
12644
|
}, "fetchAll"),
|
|
12586
12645
|
fetchById: /* @__PURE__ */ __name(async (id) => {
|
|
12587
12646
|
return this.apiClient.get(`${apiBasePath}/${id}`);
|
|
@@ -12591,10 +12650,7 @@ var FrontendExampleDomainService = class _FrontendExampleDomainService extends B
|
|
|
12591
12650
|
}, "create"),
|
|
12592
12651
|
update: /* @__PURE__ */ __name(async (payload) => {
|
|
12593
12652
|
const { id, data } = payload;
|
|
12594
|
-
return this.apiClient.patch(
|
|
12595
|
-
`${apiBasePath}/${id}`,
|
|
12596
|
-
data
|
|
12597
|
-
);
|
|
12653
|
+
return this.apiClient.patch(`${apiBasePath}/${id}`, data);
|
|
12598
12654
|
}, "update"),
|
|
12599
12655
|
delete: /* @__PURE__ */ __name(async (id) => {
|
|
12600
12656
|
return this.apiClient.delete(`${apiBasePath}/${id}`);
|