av6-core 1.3.2 → 1.3.4

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/index.d.mts CHANGED
@@ -145,6 +145,24 @@ interface DynamicCreateInput {
145
145
  interface DynamicUpdateInput extends DynamicCreateInput {
146
146
  id: number;
147
147
  }
148
+ type Simplify<T> = {
149
+ [K in keyof T]: T[K];
150
+ } & {};
151
+ type PathToSelect<P extends string> = P extends `${infer K}.${infer Rest}` ? {
152
+ [Key in K]: PathToSelect<Rest>;
153
+ } : {
154
+ [Key in P]: true;
155
+ };
156
+ type UnionToIntersection<U> = (U extends any ? (x: U) => void : never) extends (x: infer I) => void ? I : never;
157
+ type MergeAll<U> = UnionToIntersection<U> extends infer I ? (I extends object ? Simplify<I> : never) : never;
158
+ type PathsToSelect<Paths extends string> = MergeAll<Paths extends any ? PathToSelect<Paths> : never>;
159
+ type PathValue<Row, P extends string> = Row extends object ? P extends `${infer K}.${infer Rest}` ? K extends keyof Row ? PathValue<Row[K], Rest> : unknown : P extends keyof Row ? Row[P] : unknown : unknown;
160
+ type DtoFromMapping<M extends Record<string, string>, Row> = {
161
+ [K in keyof M]: PathValue<Row, M[K]>;
162
+ };
163
+ type DtoNullOnMissing<M extends Record<string, string>, Row extends object> = {
164
+ [K in keyof M]: Exclude<DtoFromMapping<M, Row>[K], undefined> | null;
165
+ };
148
166
 
149
167
  interface EmployeeCache {
150
168
  id: number;
@@ -270,6 +288,9 @@ interface DropdownRequest {
270
288
  searchText?: string;
271
289
  fixedSearch?: Record<string, ColValue>;
272
290
  fixedNotSearch?: Record<string, ColValue>;
291
+ sortBy?: string;
292
+ sortDir?: "ASC" | "DESC";
293
+ selectColumns?: Record<string, string>;
273
294
  }
274
295
  interface DropdownRequestService<T extends DynamicShortCode> extends DropdownRequest {
275
296
  shortCodeData: T;
@@ -600,4 +621,4 @@ declare class AuditProxy<Module extends string = "OPD" | "PROCEDURE" | "GENERAL_
600
621
  createAuditedService<T extends object>(serviceName: string, service: T): T;
601
622
  }
602
623
 
603
- export { type AuditContext, type AuditContextProvider, AuditCore, type AuditLogPayload, AuditLogger, AuditProxy, type CacheAdapter, type CalculationRes, type ColValue, type CommonCreateRequestRepository, type CommonExcelRequest, type CommonFilterRequest, type CommonFilterWithDate, type CommonServiceResponse, type CommonUpdateRequestRepository, type Config, type Context, type CreateUINConfigRequest, type CrudContext, type CrudDelegate, type DataType, type DeleteParams, type DeleteRequestRepository, type Deps, type DropdownRequest, type DropdownRequestService, type DynamicCreateInput, type DynamicCrudConfig, type DynamicShortCode, type DynamicUpdateInput, type EmitPayload, type EmployeeCache, type ExcelConfig, type ExportExcel, type ExportExcelRequestService, type FetchRequest, type FetchRequestRepository, type FieldConfig, type FieldRules, type FieldType, type FixedSearchRequest, type FixedSearchRequestService, type Helpers, type ImportExcel, type ImportExcelRequestService, type LockUnlockParams, type LockUnlockRequestRepository, type Mapper, type NewFixedSearchRequest, type NewFixedSearchRequestService, type NewSearchRequest, NotificationEmitter, type Op, type PaginatedResponse, type Presence, type Recipient, type RelationConfig, type RelationStrategy, type RelationWriteConfig, type SearchRequest, type SearchRequestService, type ServiceCacheAdapter, type SingleValidationMapping, type SourcePath, type Store, type ToggleActive, type TxClient, type UINConfigDTO, type UINPreviewRequest, type UINSegment, type UINSegmentType, type UIN_RESET_POLICY, type UinDeps, type UniqueConfig, type UpdateConfigByCodeInput, type UpdateStatusRequestRepository, type UpdateUINConfigRequest, type ValidationErrorItem, commonService, customOmit, findDifferences, fromTimestampToSqlDatetime, getDynamicValue, getPattern, interpolate, objectTo2DArray, toNumberOrNull, toUINConfigDTO, uinConfigService, type updateStatusParams };
624
+ export { type AuditContext, type AuditContextProvider, AuditCore, type AuditLogPayload, AuditLogger, AuditProxy, type CacheAdapter, type CalculationRes, type ColValue, type CommonCreateRequestRepository, type CommonExcelRequest, type CommonFilterRequest, type CommonFilterWithDate, type CommonServiceResponse, type CommonUpdateRequestRepository, type Config, type Context, type CreateUINConfigRequest, type CrudContext, type CrudDelegate, type DataType, type DeleteParams, type DeleteRequestRepository, type Deps, type DropdownRequest, type DropdownRequestService, type DtoFromMapping, type DtoNullOnMissing, type DynamicCreateInput, type DynamicCrudConfig, type DynamicShortCode, type DynamicUpdateInput, type EmitPayload, type EmployeeCache, type ExcelConfig, type ExportExcel, type ExportExcelRequestService, type FetchRequest, type FetchRequestRepository, type FieldConfig, type FieldRules, type FieldType, type FixedSearchRequest, type FixedSearchRequestService, type Helpers, type ImportExcel, type ImportExcelRequestService, type LockUnlockParams, type LockUnlockRequestRepository, type Mapper, type MergeAll, type NewFixedSearchRequest, type NewFixedSearchRequestService, type NewSearchRequest, NotificationEmitter, type Op, type PaginatedResponse, type PathToSelect, type PathValue, type PathsToSelect, type Presence, type Recipient, type RelationConfig, type RelationStrategy, type RelationWriteConfig, type SearchRequest, type SearchRequestService, type ServiceCacheAdapter, type Simplify, type SingleValidationMapping, type SourcePath, type Store, type ToggleActive, type TxClient, type UINConfigDTO, type UINPreviewRequest, type UINSegment, type UINSegmentType, type UIN_RESET_POLICY, type UinDeps, type UnionToIntersection, type UniqueConfig, type UpdateConfigByCodeInput, type UpdateStatusRequestRepository, type UpdateUINConfigRequest, type ValidationErrorItem, commonService, customOmit, findDifferences, fromTimestampToSqlDatetime, getDynamicValue, getPattern, interpolate, objectTo2DArray, toNumberOrNull, toUINConfigDTO, uinConfigService, type updateStatusParams };
package/dist/index.d.ts CHANGED
@@ -145,6 +145,24 @@ interface DynamicCreateInput {
145
145
  interface DynamicUpdateInput extends DynamicCreateInput {
146
146
  id: number;
147
147
  }
148
+ type Simplify<T> = {
149
+ [K in keyof T]: T[K];
150
+ } & {};
151
+ type PathToSelect<P extends string> = P extends `${infer K}.${infer Rest}` ? {
152
+ [Key in K]: PathToSelect<Rest>;
153
+ } : {
154
+ [Key in P]: true;
155
+ };
156
+ type UnionToIntersection<U> = (U extends any ? (x: U) => void : never) extends (x: infer I) => void ? I : never;
157
+ type MergeAll<U> = UnionToIntersection<U> extends infer I ? (I extends object ? Simplify<I> : never) : never;
158
+ type PathsToSelect<Paths extends string> = MergeAll<Paths extends any ? PathToSelect<Paths> : never>;
159
+ type PathValue<Row, P extends string> = Row extends object ? P extends `${infer K}.${infer Rest}` ? K extends keyof Row ? PathValue<Row[K], Rest> : unknown : P extends keyof Row ? Row[P] : unknown : unknown;
160
+ type DtoFromMapping<M extends Record<string, string>, Row> = {
161
+ [K in keyof M]: PathValue<Row, M[K]>;
162
+ };
163
+ type DtoNullOnMissing<M extends Record<string, string>, Row extends object> = {
164
+ [K in keyof M]: Exclude<DtoFromMapping<M, Row>[K], undefined> | null;
165
+ };
148
166
 
149
167
  interface EmployeeCache {
150
168
  id: number;
@@ -270,6 +288,9 @@ interface DropdownRequest {
270
288
  searchText?: string;
271
289
  fixedSearch?: Record<string, ColValue>;
272
290
  fixedNotSearch?: Record<string, ColValue>;
291
+ sortBy?: string;
292
+ sortDir?: "ASC" | "DESC";
293
+ selectColumns?: Record<string, string>;
273
294
  }
274
295
  interface DropdownRequestService<T extends DynamicShortCode> extends DropdownRequest {
275
296
  shortCodeData: T;
@@ -600,4 +621,4 @@ declare class AuditProxy<Module extends string = "OPD" | "PROCEDURE" | "GENERAL_
600
621
  createAuditedService<T extends object>(serviceName: string, service: T): T;
601
622
  }
602
623
 
603
- export { type AuditContext, type AuditContextProvider, AuditCore, type AuditLogPayload, AuditLogger, AuditProxy, type CacheAdapter, type CalculationRes, type ColValue, type CommonCreateRequestRepository, type CommonExcelRequest, type CommonFilterRequest, type CommonFilterWithDate, type CommonServiceResponse, type CommonUpdateRequestRepository, type Config, type Context, type CreateUINConfigRequest, type CrudContext, type CrudDelegate, type DataType, type DeleteParams, type DeleteRequestRepository, type Deps, type DropdownRequest, type DropdownRequestService, type DynamicCreateInput, type DynamicCrudConfig, type DynamicShortCode, type DynamicUpdateInput, type EmitPayload, type EmployeeCache, type ExcelConfig, type ExportExcel, type ExportExcelRequestService, type FetchRequest, type FetchRequestRepository, type FieldConfig, type FieldRules, type FieldType, type FixedSearchRequest, type FixedSearchRequestService, type Helpers, type ImportExcel, type ImportExcelRequestService, type LockUnlockParams, type LockUnlockRequestRepository, type Mapper, type NewFixedSearchRequest, type NewFixedSearchRequestService, type NewSearchRequest, NotificationEmitter, type Op, type PaginatedResponse, type Presence, type Recipient, type RelationConfig, type RelationStrategy, type RelationWriteConfig, type SearchRequest, type SearchRequestService, type ServiceCacheAdapter, type SingleValidationMapping, type SourcePath, type Store, type ToggleActive, type TxClient, type UINConfigDTO, type UINPreviewRequest, type UINSegment, type UINSegmentType, type UIN_RESET_POLICY, type UinDeps, type UniqueConfig, type UpdateConfigByCodeInput, type UpdateStatusRequestRepository, type UpdateUINConfigRequest, type ValidationErrorItem, commonService, customOmit, findDifferences, fromTimestampToSqlDatetime, getDynamicValue, getPattern, interpolate, objectTo2DArray, toNumberOrNull, toUINConfigDTO, uinConfigService, type updateStatusParams };
624
+ export { type AuditContext, type AuditContextProvider, AuditCore, type AuditLogPayload, AuditLogger, AuditProxy, type CacheAdapter, type CalculationRes, type ColValue, type CommonCreateRequestRepository, type CommonExcelRequest, type CommonFilterRequest, type CommonFilterWithDate, type CommonServiceResponse, type CommonUpdateRequestRepository, type Config, type Context, type CreateUINConfigRequest, type CrudContext, type CrudDelegate, type DataType, type DeleteParams, type DeleteRequestRepository, type Deps, type DropdownRequest, type DropdownRequestService, type DtoFromMapping, type DtoNullOnMissing, type DynamicCreateInput, type DynamicCrudConfig, type DynamicShortCode, type DynamicUpdateInput, type EmitPayload, type EmployeeCache, type ExcelConfig, type ExportExcel, type ExportExcelRequestService, type FetchRequest, type FetchRequestRepository, type FieldConfig, type FieldRules, type FieldType, type FixedSearchRequest, type FixedSearchRequestService, type Helpers, type ImportExcel, type ImportExcelRequestService, type LockUnlockParams, type LockUnlockRequestRepository, type Mapper, type MergeAll, type NewFixedSearchRequest, type NewFixedSearchRequestService, type NewSearchRequest, NotificationEmitter, type Op, type PaginatedResponse, type PathToSelect, type PathValue, type PathsToSelect, type Presence, type Recipient, type RelationConfig, type RelationStrategy, type RelationWriteConfig, type SearchRequest, type SearchRequestService, type ServiceCacheAdapter, type Simplify, type SingleValidationMapping, type SourcePath, type Store, type ToggleActive, type TxClient, type UINConfigDTO, type UINPreviewRequest, type UINSegment, type UINSegmentType, type UIN_RESET_POLICY, type UinDeps, type UnionToIntersection, type UniqueConfig, type UpdateConfigByCodeInput, type UpdateStatusRequestRepository, type UpdateUINConfigRequest, type ValidationErrorItem, commonService, customOmit, findDifferences, fromTimestampToSqlDatetime, getDynamicValue, getPattern, interpolate, objectTo2DArray, toNumberOrNull, toUINConfigDTO, uinConfigService, type updateStatusParams };
package/dist/index.js CHANGED
@@ -249,6 +249,55 @@ function buildNestedConditionForSingleValue(keys, fieldType, val, isNot = false)
249
249
  [keys[0]]: buildNestedConditionForSingleValue(keys.slice(1), fieldType, val, isNot)
250
250
  };
251
251
  }
252
+ function buildPrismaSelect(mapping) {
253
+ const select = {};
254
+ for (const path of Object.values(mapping)) {
255
+ if (typeof path !== "string") continue;
256
+ const parts = path.split(".").map((s) => s.trim()).filter(Boolean);
257
+ if (!parts.length) continue;
258
+ let cur = select;
259
+ for (let i = 0; i < parts.length; i++) {
260
+ const key = parts[i];
261
+ const isLeaf = i === parts.length - 1;
262
+ if (isLeaf) {
263
+ if (cur[key] && typeof cur[key] === "object") {
264
+ throw new Error(
265
+ `buildPrismaSelect conflict: "${parts.join(".")}" tries to set "${key}=true" but it's already an object`
266
+ );
267
+ }
268
+ cur[key] = true;
269
+ } else {
270
+ if (cur[key] === true) {
271
+ throw new Error(
272
+ `buildPrismaSelect conflict: "${parts.slice(0, i + 1).join(".")}" is already true, cannot nest "${parts.slice(i + 1).join(".")}"`
273
+ );
274
+ }
275
+ if (!cur[key]) cur[key] = {};
276
+ cur = cur[key];
277
+ }
278
+ }
279
+ }
280
+ return select;
281
+ }
282
+ function getByPathOrNull(row, path) {
283
+ const parts = String(path || "").split(".").map((p) => p.trim()).filter(Boolean);
284
+ let cur = row;
285
+ for (const key of parts) {
286
+ if (cur == null) return null;
287
+ cur = cur[key];
288
+ }
289
+ return cur === void 0 ? null : cur;
290
+ }
291
+ function toDynamicDropdownDto(mapping, row) {
292
+ const out = {};
293
+ for (const [dtoKey, path] of Object.entries(mapping)) {
294
+ out[dtoKey] = getByPathOrNull(row, path);
295
+ }
296
+ return out;
297
+ }
298
+ function toDynamicDropdownDtoList(mapping, rows) {
299
+ return rows.map((r) => toDynamicDropdownDto(mapping, r));
300
+ }
252
301
 
253
302
  // src/repository/common.repository.ts
254
303
  var import_util2 = require("util");
@@ -335,7 +384,10 @@ var commonRepository = (serviceDeps) => {
335
384
  searchColumns,
336
385
  shortCodeData,
337
386
  fixedSearch,
338
- fixedNotSearch
387
+ fixedNotSearch,
388
+ sortBy,
389
+ sortDir,
390
+ selectColumns
339
391
  }) {
340
392
  logger.info("entering::commonSearch::repository");
341
393
  const tableName = shortCodeData.tableName;
@@ -355,34 +407,25 @@ var commonRepository = (serviceDeps) => {
355
407
  });
356
408
  whereClause.OR = transformData(whereClause.OR);
357
409
  }
410
+ const orderByClause = {};
411
+ if (sortBy && sortDir) {
412
+ orderByClause[sortBy] = sortDir.toLowerCase();
413
+ }
358
414
  const model = db[tableName];
359
415
  if (!model) {
360
416
  throw new ErrorHandler(400, "Invalid mapping table name");
361
417
  }
362
418
  const fixWhere = typeof shortCodeData.whereClause === "string" ? JSON.parse(shortCodeData.whereClause) : {};
363
- const select = typeof shortCodeData.selectClause === "string" ? JSON.parse(shortCodeData.selectClause) : {};
364
- const selectKeys = Object.keys(select);
365
- const selectValues = Object.values(select);
366
- const selectClause = {};
367
- if (selectValues.length > 0) {
368
- selectValues.forEach((key) => {
369
- selectClause[key] = true;
370
- });
371
- }
419
+ const select = selectColumns ? selectColumns : typeof shortCodeData.selectClause === "string" ? JSON.parse(shortCodeData.selectClause) : {};
420
+ const selectClause = buildPrismaSelect(select);
372
421
  const query = {
373
422
  where: { ...whereClause, ...fixWhere, ...customWhereClause },
374
- select: selectClause
423
+ select: selectClause,
424
+ orderBy: orderByClause
375
425
  };
376
426
  const results = await model.findMany(query);
377
- const toDto = (record) => {
378
- const dto = {};
379
- selectKeys.forEach((keys) => {
380
- dto[keys] = record[select[keys]];
381
- });
382
- return dto;
383
- };
384
427
  if (shortCodeData.isDropDown) {
385
- const dtoRes = results.map((record) => toDto(record));
428
+ const dtoRes = toDynamicDropdownDtoList(select, results);
386
429
  return dtoRes;
387
430
  }
388
431
  logger.info("exiting::commonSearch::repository");
@@ -1557,7 +1600,7 @@ var commonService = (serviceDeps) => {
1557
1600
  async updateConfigByCode(input) {
1558
1601
  logger.info("entering::updateConfigById::service");
1559
1602
  const shortCodeData = await commonRepositoryFactory.updateShortCodeConfigInDb(input);
1560
- const cacheKey = `${REDIS_PREFIX}${CACHE_KEY_NAME}:${shortCodeData.tableName}:all`;
1603
+ const cacheKey = `${REDIS_PREFIX}${CACHE_KEY_NAME}:dynamicShortCode:all`;
1561
1604
  if (shortCodeData) await updateCache(cacheKey, shortCodeData?.shortCode, shortCodeData);
1562
1605
  logger.info("exiting::updateConfigById::service");
1563
1606
  }
package/dist/index.mjs CHANGED
@@ -199,6 +199,55 @@ function buildNestedConditionForSingleValue(keys, fieldType, val, isNot = false)
199
199
  [keys[0]]: buildNestedConditionForSingleValue(keys.slice(1), fieldType, val, isNot)
200
200
  };
201
201
  }
202
+ function buildPrismaSelect(mapping) {
203
+ const select = {};
204
+ for (const path of Object.values(mapping)) {
205
+ if (typeof path !== "string") continue;
206
+ const parts = path.split(".").map((s) => s.trim()).filter(Boolean);
207
+ if (!parts.length) continue;
208
+ let cur = select;
209
+ for (let i = 0; i < parts.length; i++) {
210
+ const key = parts[i];
211
+ const isLeaf = i === parts.length - 1;
212
+ if (isLeaf) {
213
+ if (cur[key] && typeof cur[key] === "object") {
214
+ throw new Error(
215
+ `buildPrismaSelect conflict: "${parts.join(".")}" tries to set "${key}=true" but it's already an object`
216
+ );
217
+ }
218
+ cur[key] = true;
219
+ } else {
220
+ if (cur[key] === true) {
221
+ throw new Error(
222
+ `buildPrismaSelect conflict: "${parts.slice(0, i + 1).join(".")}" is already true, cannot nest "${parts.slice(i + 1).join(".")}"`
223
+ );
224
+ }
225
+ if (!cur[key]) cur[key] = {};
226
+ cur = cur[key];
227
+ }
228
+ }
229
+ }
230
+ return select;
231
+ }
232
+ function getByPathOrNull(row, path) {
233
+ const parts = String(path || "").split(".").map((p) => p.trim()).filter(Boolean);
234
+ let cur = row;
235
+ for (const key of parts) {
236
+ if (cur == null) return null;
237
+ cur = cur[key];
238
+ }
239
+ return cur === void 0 ? null : cur;
240
+ }
241
+ function toDynamicDropdownDto(mapping, row) {
242
+ const out = {};
243
+ for (const [dtoKey, path] of Object.entries(mapping)) {
244
+ out[dtoKey] = getByPathOrNull(row, path);
245
+ }
246
+ return out;
247
+ }
248
+ function toDynamicDropdownDtoList(mapping, rows) {
249
+ return rows.map((r) => toDynamicDropdownDto(mapping, r));
250
+ }
202
251
 
203
252
  // src/repository/common.repository.ts
204
253
  import { isDeepStrictEqual as isDeepStrictEqual2 } from "util";
@@ -285,7 +334,10 @@ var commonRepository = (serviceDeps) => {
285
334
  searchColumns,
286
335
  shortCodeData,
287
336
  fixedSearch,
288
- fixedNotSearch
337
+ fixedNotSearch,
338
+ sortBy,
339
+ sortDir,
340
+ selectColumns
289
341
  }) {
290
342
  logger.info("entering::commonSearch::repository");
291
343
  const tableName = shortCodeData.tableName;
@@ -305,34 +357,25 @@ var commonRepository = (serviceDeps) => {
305
357
  });
306
358
  whereClause.OR = transformData(whereClause.OR);
307
359
  }
360
+ const orderByClause = {};
361
+ if (sortBy && sortDir) {
362
+ orderByClause[sortBy] = sortDir.toLowerCase();
363
+ }
308
364
  const model = db[tableName];
309
365
  if (!model) {
310
366
  throw new ErrorHandler(400, "Invalid mapping table name");
311
367
  }
312
368
  const fixWhere = typeof shortCodeData.whereClause === "string" ? JSON.parse(shortCodeData.whereClause) : {};
313
- const select = typeof shortCodeData.selectClause === "string" ? JSON.parse(shortCodeData.selectClause) : {};
314
- const selectKeys = Object.keys(select);
315
- const selectValues = Object.values(select);
316
- const selectClause = {};
317
- if (selectValues.length > 0) {
318
- selectValues.forEach((key) => {
319
- selectClause[key] = true;
320
- });
321
- }
369
+ const select = selectColumns ? selectColumns : typeof shortCodeData.selectClause === "string" ? JSON.parse(shortCodeData.selectClause) : {};
370
+ const selectClause = buildPrismaSelect(select);
322
371
  const query = {
323
372
  where: { ...whereClause, ...fixWhere, ...customWhereClause },
324
- select: selectClause
373
+ select: selectClause,
374
+ orderBy: orderByClause
325
375
  };
326
376
  const results = await model.findMany(query);
327
- const toDto = (record) => {
328
- const dto = {};
329
- selectKeys.forEach((keys) => {
330
- dto[keys] = record[select[keys]];
331
- });
332
- return dto;
333
- };
334
377
  if (shortCodeData.isDropDown) {
335
- const dtoRes = results.map((record) => toDto(record));
378
+ const dtoRes = toDynamicDropdownDtoList(select, results);
336
379
  return dtoRes;
337
380
  }
338
381
  logger.info("exiting::commonSearch::repository");
@@ -1507,7 +1550,7 @@ var commonService = (serviceDeps) => {
1507
1550
  async updateConfigByCode(input) {
1508
1551
  logger.info("entering::updateConfigById::service");
1509
1552
  const shortCodeData = await commonRepositoryFactory.updateShortCodeConfigInDb(input);
1510
- const cacheKey = `${REDIS_PREFIX}${CACHE_KEY_NAME}:${shortCodeData.tableName}:all`;
1553
+ const cacheKey = `${REDIS_PREFIX}${CACHE_KEY_NAME}:dynamicShortCode:all`;
1511
1554
  if (shortCodeData) await updateCache(cacheKey, shortCodeData?.shortCode, shortCodeData);
1512
1555
  logger.info("exiting::updateConfigById::service");
1513
1556
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "av6-core",
3
- "version": "1.3.2",
3
+ "version": "1.3.4",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",