@etsoo/shared 1.2.20 → 1.2.22

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.
@@ -133,10 +133,6 @@ export declare namespace DataTypes {
133
133
  * Placement type
134
134
  */
135
135
  type Placement = keyof typeof PlacementEnum;
136
- /**
137
- * Number and string combination id type
138
- */
139
- type IdType = number | string;
140
136
  /**
141
137
  * Add and edit data type
142
138
  * ChangedFields for editing case
@@ -240,7 +236,7 @@ export declare namespace DataTypes {
240
236
  /**
241
237
  * Get specific type keys
242
238
  */
243
- type Keys<T extends object, R = string | number> = {
239
+ type Keys<T extends object, R = IdType> = {
244
240
  [k in keyof T]: T[k] extends R ? k : never;
245
241
  }[keyof T];
246
242
  /**
@@ -368,7 +364,7 @@ export declare namespace DataTypes {
368
364
  * @param key Property name
369
365
  * @returns Id value
370
366
  */
371
- function getIdValue<T extends object, K extends Keys<T, string | number>>(data: T, key: K): T[K];
367
+ function getIdValue<T extends object, K extends Keys<T, IdType>>(data: T, key: K): T[K];
372
368
  /**
373
369
  * Get object id field value 1
374
370
  * @param data Data
@@ -408,6 +404,10 @@ export declare namespace DataTypes {
408
404
  */
409
405
  function jsonReplacer(replacer: (this: any, key: string, value: any, path: string) => any): (this: any, key: any, value: any) => any;
410
406
  }
407
+ /**
408
+ * Number and string combination id type
409
+ */
410
+ export type IdType = number | string;
411
411
  /**
412
412
  * List item with number id type
413
413
  */
@@ -420,7 +420,7 @@ export type ListType1 = DataTypes.IdLabelItem<string>;
420
420
  * List item with compatible id and name / label / title
421
421
  */
422
422
  export type ListType2 = {
423
- id: DataTypes.IdType;
423
+ id: IdType;
424
424
  } & ({
425
425
  label: string;
426
426
  } | {
@@ -431,9 +431,9 @@ export type ListType2 = {
431
431
  /**
432
432
  * Id default type
433
433
  */
434
- export type IdDefaultType<T extends object> = T extends {
435
- id: number | string;
436
- } ? DataTypes.Keys<T> & 'id' : DataTypes.Keys<T>;
434
+ export type IdDefaultType<T extends object, I extends IdType = IdType> = T extends {
435
+ id: I;
436
+ } ? DataTypes.Keys<T, I> & 'id' : DataTypes.Keys<T, I>;
437
437
  /**
438
438
  * Label default type
439
439
  */
@@ -1,4 +1,4 @@
1
- import { DataTypes } from './DataTypes';
1
+ import { IdType } from './DataTypes';
2
2
  /**
3
3
  * Result errors
4
4
  * Indexable type
@@ -50,7 +50,7 @@ export interface IActionResult<D extends object = {}> {
50
50
  /**
51
51
  * Action result with id data
52
52
  */
53
- export type IdActionResult<T extends DataTypes.IdType = number> = IActionResult<{
53
+ export type IdActionResult<T extends IdType = number> = IActionResult<{
54
54
  id: T;
55
55
  }>;
56
56
  /**
@@ -1,4 +1,4 @@
1
- import { DataTypes } from './DataTypes';
1
+ import { DataTypes, IdType } from './DataTypes';
2
2
  import { ParsedPath } from './types/ParsedPath';
3
3
  declare global {
4
4
  interface String {
@@ -102,7 +102,7 @@ export declare namespace Utils {
102
102
  * @returns Result
103
103
  */
104
104
  function exclude<T extends {
105
- [P in D]: DataTypes.IdType;
105
+ [P in D]: IdType;
106
106
  }, D extends string = 'id'>(items: T[], field: D, ...excludedValues: T[D][]): T[];
107
107
  /**
108
108
  * Async exclude specific items
@@ -112,7 +112,7 @@ export declare namespace Utils {
112
112
  * @returns Result
113
113
  */
114
114
  function excludeAsync<T extends {
115
- [P in D]: DataTypes.IdType;
115
+ [P in D]: IdType;
116
116
  }, D extends string = 'id'>(items: Promise<T[] | undefined>, field: D, ...excludedValues: T[D][]): Promise<T[] | undefined>;
117
117
  /**
118
118
  * Format inital character to lower case or upper case
@@ -133,10 +133,6 @@ export declare namespace DataTypes {
133
133
  * Placement type
134
134
  */
135
135
  type Placement = keyof typeof PlacementEnum;
136
- /**
137
- * Number and string combination id type
138
- */
139
- type IdType = number | string;
140
136
  /**
141
137
  * Add and edit data type
142
138
  * ChangedFields for editing case
@@ -240,7 +236,7 @@ export declare namespace DataTypes {
240
236
  /**
241
237
  * Get specific type keys
242
238
  */
243
- type Keys<T extends object, R = string | number> = {
239
+ type Keys<T extends object, R = IdType> = {
244
240
  [k in keyof T]: T[k] extends R ? k : never;
245
241
  }[keyof T];
246
242
  /**
@@ -368,7 +364,7 @@ export declare namespace DataTypes {
368
364
  * @param key Property name
369
365
  * @returns Id value
370
366
  */
371
- function getIdValue<T extends object, K extends Keys<T, string | number>>(data: T, key: K): T[K];
367
+ function getIdValue<T extends object, K extends Keys<T, IdType>>(data: T, key: K): T[K];
372
368
  /**
373
369
  * Get object id field value 1
374
370
  * @param data Data
@@ -408,6 +404,10 @@ export declare namespace DataTypes {
408
404
  */
409
405
  function jsonReplacer(replacer: (this: any, key: string, value: any, path: string) => any): (this: any, key: any, value: any) => any;
410
406
  }
407
+ /**
408
+ * Number and string combination id type
409
+ */
410
+ export type IdType = number | string;
411
411
  /**
412
412
  * List item with number id type
413
413
  */
@@ -420,7 +420,7 @@ export type ListType1 = DataTypes.IdLabelItem<string>;
420
420
  * List item with compatible id and name / label / title
421
421
  */
422
422
  export type ListType2 = {
423
- id: DataTypes.IdType;
423
+ id: IdType;
424
424
  } & ({
425
425
  label: string;
426
426
  } | {
@@ -431,9 +431,9 @@ export type ListType2 = {
431
431
  /**
432
432
  * Id default type
433
433
  */
434
- export type IdDefaultType<T extends object> = T extends {
435
- id: number | string;
436
- } ? DataTypes.Keys<T> & 'id' : DataTypes.Keys<T>;
434
+ export type IdDefaultType<T extends object, I extends IdType = IdType> = T extends {
435
+ id: I;
436
+ } ? DataTypes.Keys<T, I> & 'id' : DataTypes.Keys<T, I>;
437
437
  /**
438
438
  * Label default type
439
439
  */
@@ -1,4 +1,4 @@
1
- import { DataTypes } from './DataTypes';
1
+ import { IdType } from './DataTypes';
2
2
  /**
3
3
  * Result errors
4
4
  * Indexable type
@@ -50,7 +50,7 @@ export interface IActionResult<D extends object = {}> {
50
50
  /**
51
51
  * Action result with id data
52
52
  */
53
- export type IdActionResult<T extends DataTypes.IdType = number> = IActionResult<{
53
+ export type IdActionResult<T extends IdType = number> = IActionResult<{
54
54
  id: T;
55
55
  }>;
56
56
  /**
@@ -1,4 +1,4 @@
1
- import { DataTypes } from './DataTypes';
1
+ import { DataTypes, IdType } from './DataTypes';
2
2
  import { ParsedPath } from './types/ParsedPath';
3
3
  declare global {
4
4
  interface String {
@@ -102,7 +102,7 @@ export declare namespace Utils {
102
102
  * @returns Result
103
103
  */
104
104
  function exclude<T extends {
105
- [P in D]: DataTypes.IdType;
105
+ [P in D]: IdType;
106
106
  }, D extends string = 'id'>(items: T[], field: D, ...excludedValues: T[D][]): T[];
107
107
  /**
108
108
  * Async exclude specific items
@@ -112,7 +112,7 @@ export declare namespace Utils {
112
112
  * @returns Result
113
113
  */
114
114
  function excludeAsync<T extends {
115
- [P in D]: DataTypes.IdType;
115
+ [P in D]: IdType;
116
116
  }, D extends string = 'id'>(items: Promise<T[] | undefined>, field: D, ...excludedValues: T[D][]): Promise<T[] | undefined>;
117
117
  /**
118
118
  * Format inital character to lower case or upper case
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/shared",
3
- "version": "1.2.20",
3
+ "version": "1.2.22",
4
4
  "description": "TypeScript shared utilities and functions",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
package/src/DataTypes.ts CHANGED
@@ -172,11 +172,6 @@ export namespace DataTypes {
172
172
  */
173
173
  export type Placement = keyof typeof PlacementEnum;
174
174
 
175
- /**
176
- * Number and string combination id type
177
- */
178
- export type IdType = number | string;
179
-
180
175
  /**
181
176
  * Add and edit data type
182
177
  * ChangedFields for editing case
@@ -300,7 +295,7 @@ export namespace DataTypes {
300
295
  /**
301
296
  * Get specific type keys
302
297
  */
303
- export type Keys<T extends object, R = string | number> = {
298
+ export type Keys<T extends object, R = IdType> = {
304
299
  [k in keyof T]: T[k] extends R ? k : never;
305
300
  }[keyof T];
306
301
 
@@ -654,10 +649,10 @@ export namespace DataTypes {
654
649
  * @param key Property name
655
650
  * @returns Id value
656
651
  */
657
- export function getIdValue<
658
- T extends object,
659
- K extends Keys<T, string | number>
660
- >(data: T, key: K): T[K] {
652
+ export function getIdValue<T extends object, K extends Keys<T, IdType>>(
653
+ data: T,
654
+ key: K
655
+ ): T[K] {
661
656
  return data[key];
662
657
  }
663
658
 
@@ -778,6 +773,11 @@ export namespace DataTypes {
778
773
  }
779
774
  }
780
775
 
776
+ /**
777
+ * Number and string combination id type
778
+ */
779
+ export type IdType = number | string;
780
+
781
781
  /**
782
782
  * List item with number id type
783
783
  */
@@ -792,15 +792,16 @@ export type ListType1 = DataTypes.IdLabelItem<string>;
792
792
  * List item with compatible id and name / label / title
793
793
  */
794
794
  export type ListType2 = {
795
- id: DataTypes.IdType;
795
+ id: IdType;
796
796
  } & ({ label: string } | { name: string } | { title: string });
797
797
 
798
798
  /**
799
799
  * Id default type
800
800
  */
801
- export type IdDefaultType<T extends object> = T extends { id: number | string }
802
- ? DataTypes.Keys<T> & 'id'
803
- : DataTypes.Keys<T>;
801
+ export type IdDefaultType<
802
+ T extends object,
803
+ I extends IdType = IdType
804
+ > = T extends { id: I } ? DataTypes.Keys<T, I> & 'id' : DataTypes.Keys<T, I>;
804
805
 
805
806
  /**
806
807
  * Label default type
@@ -1,4 +1,4 @@
1
- import { DataTypes } from './DataTypes';
1
+ import { IdType } from './DataTypes';
2
2
 
3
3
  /**
4
4
  * Result errors
@@ -61,10 +61,9 @@ export interface IActionResult<D extends object = {}> {
61
61
  /**
62
62
  * Action result with id data
63
63
  */
64
- export type IdActionResult<T extends DataTypes.IdType = number> =
65
- IActionResult<{
66
- id: T;
67
- }>;
64
+ export type IdActionResult<T extends IdType = number> = IActionResult<{
65
+ id: T;
66
+ }>;
68
67
 
69
68
  /**
70
69
  * Action result with dynamic data
package/src/Utils.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { DataTypes } from './DataTypes';
1
+ import { DataTypes, IdType } from './DataTypes';
2
2
  import isEqual from 'lodash.isequal';
3
3
  import { DateUtils } from './DateUtils';
4
4
  import { ParsedPath } from './types/ParsedPath';
@@ -247,7 +247,7 @@ export namespace Utils {
247
247
  * @returns Result
248
248
  */
249
249
  export function exclude<
250
- T extends { [P in D]: DataTypes.IdType },
250
+ T extends { [P in D]: IdType },
251
251
  D extends string = 'id'
252
252
  >(items: T[], field: D, ...excludedValues: T[D][]) {
253
253
  return items.filter((item) => !excludedValues.includes(item[field]));
@@ -261,7 +261,7 @@ export namespace Utils {
261
261
  * @returns Result
262
262
  */
263
263
  export async function excludeAsync<
264
- T extends { [P in D]: DataTypes.IdType },
264
+ T extends { [P in D]: IdType },
265
265
  D extends string = 'id'
266
266
  >(items: Promise<T[] | undefined>, field: D, ...excludedValues: T[D][]) {
267
267
  const result = await items;