@etsoo/shared 1.2.19 → 1.2.21
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/lib/cjs/DataTypes.d.ts +21 -21
- package/lib/cjs/DataTypes.js +29 -29
- package/lib/cjs/IActionResult.d.ts +2 -2
- package/lib/cjs/Utils.d.ts +3 -3
- package/lib/mjs/DataTypes.d.ts +21 -21
- package/lib/mjs/DataTypes.js +28 -26
- package/lib/mjs/IActionResult.d.ts +2 -2
- package/lib/mjs/Utils.d.ts +3 -3
- package/package.json +1 -1
- package/src/DataTypes.ts +43 -42
- package/src/IActionResult.ts +4 -5
- package/src/Utils.ts +3 -3
package/lib/cjs/DataTypes.d.ts
CHANGED
|
@@ -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 =
|
|
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
|
/**
|
|
@@ -343,6 +339,18 @@ export declare namespace DataTypes {
|
|
|
343
339
|
* @returns Keys
|
|
344
340
|
*/
|
|
345
341
|
function getEnumKeys<T extends EnumBase, K extends keyof T & string>(input: T): K[];
|
|
342
|
+
/**
|
|
343
|
+
* Get ListType2 item label
|
|
344
|
+
* @param item Item
|
|
345
|
+
* @returns Result
|
|
346
|
+
*/
|
|
347
|
+
function getListItemLabel<D extends ListType2>(item: D): string;
|
|
348
|
+
/**
|
|
349
|
+
* Get object item label
|
|
350
|
+
* @param item Item
|
|
351
|
+
* @returns Result
|
|
352
|
+
*/
|
|
353
|
+
function getObjectItemLabel(item: object): string;
|
|
346
354
|
/**
|
|
347
355
|
* Get object field value
|
|
348
356
|
* @param data Data
|
|
@@ -356,7 +364,7 @@ export declare namespace DataTypes {
|
|
|
356
364
|
* @param key Property name
|
|
357
365
|
* @returns Id value
|
|
358
366
|
*/
|
|
359
|
-
function getIdValue<T extends object, K extends Keys<T,
|
|
367
|
+
function getIdValue<T extends object, K extends Keys<T, IdType>>(data: T, key: K): T[K];
|
|
360
368
|
/**
|
|
361
369
|
* Get object id field value 1
|
|
362
370
|
* @param data Data
|
|
@@ -396,6 +404,10 @@ export declare namespace DataTypes {
|
|
|
396
404
|
*/
|
|
397
405
|
function jsonReplacer(replacer: (this: any, key: string, value: any, path: string) => any): (this: any, key: any, value: any) => any;
|
|
398
406
|
}
|
|
407
|
+
/**
|
|
408
|
+
* Number and string combination id type
|
|
409
|
+
*/
|
|
410
|
+
export type IdType = number | string;
|
|
399
411
|
/**
|
|
400
412
|
* List item with number id type
|
|
401
413
|
*/
|
|
@@ -408,7 +420,7 @@ export type ListType1 = DataTypes.IdLabelItem<string>;
|
|
|
408
420
|
* List item with compatible id and name / label / title
|
|
409
421
|
*/
|
|
410
422
|
export type ListType2 = {
|
|
411
|
-
id:
|
|
423
|
+
id: IdType;
|
|
412
424
|
} & ({
|
|
413
425
|
label: string;
|
|
414
426
|
} | {
|
|
@@ -419,8 +431,8 @@ export type ListType2 = {
|
|
|
419
431
|
/**
|
|
420
432
|
* Id default type
|
|
421
433
|
*/
|
|
422
|
-
export type IdDefaultType<T extends object> = T extends {
|
|
423
|
-
id:
|
|
434
|
+
export type IdDefaultType<T extends object, I extends IdType = IdType> = T extends {
|
|
435
|
+
id: I;
|
|
424
436
|
} ? DataTypes.Keys<T> & 'id' : DataTypes.Keys<T>;
|
|
425
437
|
/**
|
|
426
438
|
* Label default type
|
|
@@ -434,15 +446,3 @@ export type LabelDefaultType<T extends object> = T extends {
|
|
|
434
446
|
export type TitleDefaultType<T extends object> = T extends {
|
|
435
447
|
title: string;
|
|
436
448
|
} ? DataTypes.Keys<T, string> & 'title' : DataTypes.Keys<T, string>;
|
|
437
|
-
/**
|
|
438
|
-
* Get ListType2 item label
|
|
439
|
-
* @param item Item
|
|
440
|
-
* @returns Result
|
|
441
|
-
*/
|
|
442
|
-
export declare function getListItemLabel<D extends ListType2>(item: D): string;
|
|
443
|
-
/**
|
|
444
|
-
* Get object item label
|
|
445
|
-
* @param item Item
|
|
446
|
-
* @returns Result
|
|
447
|
-
*/
|
|
448
|
-
export declare function getObjectItemLabel(item: object): string;
|
package/lib/cjs/DataTypes.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* Before was wrong with {}, from 4.8 unknown = {} | null | undefined
|
|
6
6
|
*/
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.
|
|
8
|
+
exports.DataTypes = void 0;
|
|
9
9
|
/**
|
|
10
10
|
* Interface data types
|
|
11
11
|
*/
|
|
@@ -311,6 +311,34 @@ var DataTypes;
|
|
|
311
311
|
.map((item) => item);
|
|
312
312
|
}
|
|
313
313
|
DataTypes.getEnumKeys = getEnumKeys;
|
|
314
|
+
/**
|
|
315
|
+
* Get ListType2 item label
|
|
316
|
+
* @param item Item
|
|
317
|
+
* @returns Result
|
|
318
|
+
*/
|
|
319
|
+
function getListItemLabel(item) {
|
|
320
|
+
return 'label' in item
|
|
321
|
+
? item.label
|
|
322
|
+
: 'name' in item
|
|
323
|
+
? item.name
|
|
324
|
+
: item.title;
|
|
325
|
+
}
|
|
326
|
+
DataTypes.getListItemLabel = getListItemLabel;
|
|
327
|
+
/**
|
|
328
|
+
* Get object item label
|
|
329
|
+
* @param item Item
|
|
330
|
+
* @returns Result
|
|
331
|
+
*/
|
|
332
|
+
function getObjectItemLabel(item) {
|
|
333
|
+
return 'label' in item
|
|
334
|
+
? `${item.label}`
|
|
335
|
+
: 'name' in item
|
|
336
|
+
? `${item.name}`
|
|
337
|
+
: 'title' in item
|
|
338
|
+
? `${item.title}`
|
|
339
|
+
: `${item}`;
|
|
340
|
+
}
|
|
341
|
+
DataTypes.getObjectItemLabel = getObjectItemLabel;
|
|
314
342
|
/**
|
|
315
343
|
* Get object field value
|
|
316
344
|
* @param data Data
|
|
@@ -429,31 +457,3 @@ var DataTypes;
|
|
|
429
457
|
}
|
|
430
458
|
DataTypes.jsonReplacer = jsonReplacer;
|
|
431
459
|
})(DataTypes || (exports.DataTypes = DataTypes = {}));
|
|
432
|
-
/**
|
|
433
|
-
* Get ListType2 item label
|
|
434
|
-
* @param item Item
|
|
435
|
-
* @returns Result
|
|
436
|
-
*/
|
|
437
|
-
function getListItemLabel(item) {
|
|
438
|
-
return 'label' in item
|
|
439
|
-
? item.label
|
|
440
|
-
: 'name' in item
|
|
441
|
-
? item.name
|
|
442
|
-
: item.title;
|
|
443
|
-
}
|
|
444
|
-
exports.getListItemLabel = getListItemLabel;
|
|
445
|
-
/**
|
|
446
|
-
* Get object item label
|
|
447
|
-
* @param item Item
|
|
448
|
-
* @returns Result
|
|
449
|
-
*/
|
|
450
|
-
function getObjectItemLabel(item) {
|
|
451
|
-
return 'label' in item
|
|
452
|
-
? `${item.label}`
|
|
453
|
-
: 'name' in item
|
|
454
|
-
? `${item.name}`
|
|
455
|
-
: 'title' in item
|
|
456
|
-
? `${item.title}`
|
|
457
|
-
: `${item}`;
|
|
458
|
-
}
|
|
459
|
-
exports.getObjectItemLabel = getObjectItemLabel;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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
|
|
53
|
+
export type IdActionResult<T extends IdType = number> = IActionResult<{
|
|
54
54
|
id: T;
|
|
55
55
|
}>;
|
|
56
56
|
/**
|
package/lib/cjs/Utils.d.ts
CHANGED
|
@@ -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]:
|
|
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]:
|
|
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/lib/mjs/DataTypes.d.ts
CHANGED
|
@@ -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 =
|
|
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
|
/**
|
|
@@ -343,6 +339,18 @@ export declare namespace DataTypes {
|
|
|
343
339
|
* @returns Keys
|
|
344
340
|
*/
|
|
345
341
|
function getEnumKeys<T extends EnumBase, K extends keyof T & string>(input: T): K[];
|
|
342
|
+
/**
|
|
343
|
+
* Get ListType2 item label
|
|
344
|
+
* @param item Item
|
|
345
|
+
* @returns Result
|
|
346
|
+
*/
|
|
347
|
+
function getListItemLabel<D extends ListType2>(item: D): string;
|
|
348
|
+
/**
|
|
349
|
+
* Get object item label
|
|
350
|
+
* @param item Item
|
|
351
|
+
* @returns Result
|
|
352
|
+
*/
|
|
353
|
+
function getObjectItemLabel(item: object): string;
|
|
346
354
|
/**
|
|
347
355
|
* Get object field value
|
|
348
356
|
* @param data Data
|
|
@@ -356,7 +364,7 @@ export declare namespace DataTypes {
|
|
|
356
364
|
* @param key Property name
|
|
357
365
|
* @returns Id value
|
|
358
366
|
*/
|
|
359
|
-
function getIdValue<T extends object, K extends Keys<T,
|
|
367
|
+
function getIdValue<T extends object, K extends Keys<T, IdType>>(data: T, key: K): T[K];
|
|
360
368
|
/**
|
|
361
369
|
* Get object id field value 1
|
|
362
370
|
* @param data Data
|
|
@@ -396,6 +404,10 @@ export declare namespace DataTypes {
|
|
|
396
404
|
*/
|
|
397
405
|
function jsonReplacer(replacer: (this: any, key: string, value: any, path: string) => any): (this: any, key: any, value: any) => any;
|
|
398
406
|
}
|
|
407
|
+
/**
|
|
408
|
+
* Number and string combination id type
|
|
409
|
+
*/
|
|
410
|
+
export type IdType = number | string;
|
|
399
411
|
/**
|
|
400
412
|
* List item with number id type
|
|
401
413
|
*/
|
|
@@ -408,7 +420,7 @@ export type ListType1 = DataTypes.IdLabelItem<string>;
|
|
|
408
420
|
* List item with compatible id and name / label / title
|
|
409
421
|
*/
|
|
410
422
|
export type ListType2 = {
|
|
411
|
-
id:
|
|
423
|
+
id: IdType;
|
|
412
424
|
} & ({
|
|
413
425
|
label: string;
|
|
414
426
|
} | {
|
|
@@ -419,8 +431,8 @@ export type ListType2 = {
|
|
|
419
431
|
/**
|
|
420
432
|
* Id default type
|
|
421
433
|
*/
|
|
422
|
-
export type IdDefaultType<T extends object> = T extends {
|
|
423
|
-
id:
|
|
434
|
+
export type IdDefaultType<T extends object, I extends IdType = IdType> = T extends {
|
|
435
|
+
id: I;
|
|
424
436
|
} ? DataTypes.Keys<T> & 'id' : DataTypes.Keys<T>;
|
|
425
437
|
/**
|
|
426
438
|
* Label default type
|
|
@@ -434,15 +446,3 @@ export type LabelDefaultType<T extends object> = T extends {
|
|
|
434
446
|
export type TitleDefaultType<T extends object> = T extends {
|
|
435
447
|
title: string;
|
|
436
448
|
} ? DataTypes.Keys<T, string> & 'title' : DataTypes.Keys<T, string>;
|
|
437
|
-
/**
|
|
438
|
-
* Get ListType2 item label
|
|
439
|
-
* @param item Item
|
|
440
|
-
* @returns Result
|
|
441
|
-
*/
|
|
442
|
-
export declare function getListItemLabel<D extends ListType2>(item: D): string;
|
|
443
|
-
/**
|
|
444
|
-
* Get object item label
|
|
445
|
-
* @param item Item
|
|
446
|
-
* @returns Result
|
|
447
|
-
*/
|
|
448
|
-
export declare function getObjectItemLabel(item: object): string;
|
package/lib/mjs/DataTypes.js
CHANGED
|
@@ -308,6 +308,34 @@ export var DataTypes;
|
|
|
308
308
|
.map((item) => item);
|
|
309
309
|
}
|
|
310
310
|
DataTypes.getEnumKeys = getEnumKeys;
|
|
311
|
+
/**
|
|
312
|
+
* Get ListType2 item label
|
|
313
|
+
* @param item Item
|
|
314
|
+
* @returns Result
|
|
315
|
+
*/
|
|
316
|
+
function getListItemLabel(item) {
|
|
317
|
+
return 'label' in item
|
|
318
|
+
? item.label
|
|
319
|
+
: 'name' in item
|
|
320
|
+
? item.name
|
|
321
|
+
: item.title;
|
|
322
|
+
}
|
|
323
|
+
DataTypes.getListItemLabel = getListItemLabel;
|
|
324
|
+
/**
|
|
325
|
+
* Get object item label
|
|
326
|
+
* @param item Item
|
|
327
|
+
* @returns Result
|
|
328
|
+
*/
|
|
329
|
+
function getObjectItemLabel(item) {
|
|
330
|
+
return 'label' in item
|
|
331
|
+
? `${item.label}`
|
|
332
|
+
: 'name' in item
|
|
333
|
+
? `${item.name}`
|
|
334
|
+
: 'title' in item
|
|
335
|
+
? `${item.title}`
|
|
336
|
+
: `${item}`;
|
|
337
|
+
}
|
|
338
|
+
DataTypes.getObjectItemLabel = getObjectItemLabel;
|
|
311
339
|
/**
|
|
312
340
|
* Get object field value
|
|
313
341
|
* @param data Data
|
|
@@ -426,29 +454,3 @@ export var DataTypes;
|
|
|
426
454
|
}
|
|
427
455
|
DataTypes.jsonReplacer = jsonReplacer;
|
|
428
456
|
})(DataTypes || (DataTypes = {}));
|
|
429
|
-
/**
|
|
430
|
-
* Get ListType2 item label
|
|
431
|
-
* @param item Item
|
|
432
|
-
* @returns Result
|
|
433
|
-
*/
|
|
434
|
-
export function getListItemLabel(item) {
|
|
435
|
-
return 'label' in item
|
|
436
|
-
? item.label
|
|
437
|
-
: 'name' in item
|
|
438
|
-
? item.name
|
|
439
|
-
: item.title;
|
|
440
|
-
}
|
|
441
|
-
/**
|
|
442
|
-
* Get object item label
|
|
443
|
-
* @param item Item
|
|
444
|
-
* @returns Result
|
|
445
|
-
*/
|
|
446
|
-
export function getObjectItemLabel(item) {
|
|
447
|
-
return 'label' in item
|
|
448
|
-
? `${item.label}`
|
|
449
|
-
: 'name' in item
|
|
450
|
-
? `${item.name}`
|
|
451
|
-
: 'title' in item
|
|
452
|
-
? `${item.title}`
|
|
453
|
-
: `${item}`;
|
|
454
|
-
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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
|
|
53
|
+
export type IdActionResult<T extends IdType = number> = IActionResult<{
|
|
54
54
|
id: T;
|
|
55
55
|
}>;
|
|
56
56
|
/**
|
package/lib/mjs/Utils.d.ts
CHANGED
|
@@ -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]:
|
|
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]:
|
|
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
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 =
|
|
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
|
|
|
@@ -604,6 +599,34 @@ export namespace DataTypes {
|
|
|
604
599
|
.map((item) => <K>item);
|
|
605
600
|
}
|
|
606
601
|
|
|
602
|
+
/**
|
|
603
|
+
* Get ListType2 item label
|
|
604
|
+
* @param item Item
|
|
605
|
+
* @returns Result
|
|
606
|
+
*/
|
|
607
|
+
export function getListItemLabel<D extends ListType2>(item: D) {
|
|
608
|
+
return 'label' in item
|
|
609
|
+
? item.label
|
|
610
|
+
: 'name' in item
|
|
611
|
+
? item.name
|
|
612
|
+
: item.title;
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
/**
|
|
616
|
+
* Get object item label
|
|
617
|
+
* @param item Item
|
|
618
|
+
* @returns Result
|
|
619
|
+
*/
|
|
620
|
+
export function getObjectItemLabel(item: object): string {
|
|
621
|
+
return 'label' in item
|
|
622
|
+
? `${item.label}`
|
|
623
|
+
: 'name' in item
|
|
624
|
+
? `${item.name}`
|
|
625
|
+
: 'title' in item
|
|
626
|
+
? `${item.title}`
|
|
627
|
+
: `${item}`;
|
|
628
|
+
}
|
|
629
|
+
|
|
607
630
|
/**
|
|
608
631
|
* Get object field value
|
|
609
632
|
* @param data Data
|
|
@@ -626,10 +649,10 @@ export namespace DataTypes {
|
|
|
626
649
|
* @param key Property name
|
|
627
650
|
* @returns Id value
|
|
628
651
|
*/
|
|
629
|
-
export function getIdValue<
|
|
630
|
-
T
|
|
631
|
-
K
|
|
632
|
-
|
|
652
|
+
export function getIdValue<T extends object, K extends Keys<T, IdType>>(
|
|
653
|
+
data: T,
|
|
654
|
+
key: K
|
|
655
|
+
): T[K] {
|
|
633
656
|
return data[key];
|
|
634
657
|
}
|
|
635
658
|
|
|
@@ -750,6 +773,11 @@ export namespace DataTypes {
|
|
|
750
773
|
}
|
|
751
774
|
}
|
|
752
775
|
|
|
776
|
+
/**
|
|
777
|
+
* Number and string combination id type
|
|
778
|
+
*/
|
|
779
|
+
export type IdType = number | string;
|
|
780
|
+
|
|
753
781
|
/**
|
|
754
782
|
* List item with number id type
|
|
755
783
|
*/
|
|
@@ -764,15 +792,16 @@ export type ListType1 = DataTypes.IdLabelItem<string>;
|
|
|
764
792
|
* List item with compatible id and name / label / title
|
|
765
793
|
*/
|
|
766
794
|
export type ListType2 = {
|
|
767
|
-
id:
|
|
795
|
+
id: IdType;
|
|
768
796
|
} & ({ label: string } | { name: string } | { title: string });
|
|
769
797
|
|
|
770
798
|
/**
|
|
771
799
|
* Id default type
|
|
772
800
|
*/
|
|
773
|
-
export type IdDefaultType<
|
|
774
|
-
|
|
775
|
-
|
|
801
|
+
export type IdDefaultType<
|
|
802
|
+
T extends object,
|
|
803
|
+
I extends IdType = IdType
|
|
804
|
+
> = T extends { id: I } ? DataTypes.Keys<T> & 'id' : DataTypes.Keys<T>;
|
|
776
805
|
|
|
777
806
|
/**
|
|
778
807
|
* Label default type
|
|
@@ -787,31 +816,3 @@ export type LabelDefaultType<T extends object> = T extends { label: string }
|
|
|
787
816
|
export type TitleDefaultType<T extends object> = T extends { title: string }
|
|
788
817
|
? DataTypes.Keys<T, string> & 'title'
|
|
789
818
|
: DataTypes.Keys<T, string>;
|
|
790
|
-
|
|
791
|
-
/**
|
|
792
|
-
* Get ListType2 item label
|
|
793
|
-
* @param item Item
|
|
794
|
-
* @returns Result
|
|
795
|
-
*/
|
|
796
|
-
export function getListItemLabel<D extends ListType2>(item: D) {
|
|
797
|
-
return 'label' in item
|
|
798
|
-
? item.label
|
|
799
|
-
: 'name' in item
|
|
800
|
-
? item.name
|
|
801
|
-
: item.title;
|
|
802
|
-
}
|
|
803
|
-
|
|
804
|
-
/**
|
|
805
|
-
* Get object item label
|
|
806
|
-
* @param item Item
|
|
807
|
-
* @returns Result
|
|
808
|
-
*/
|
|
809
|
-
export function getObjectItemLabel(item: object): string {
|
|
810
|
-
return 'label' in item
|
|
811
|
-
? `${item.label}`
|
|
812
|
-
: 'name' in item
|
|
813
|
-
? `${item.name}`
|
|
814
|
-
: 'title' in item
|
|
815
|
-
? `${item.title}`
|
|
816
|
-
: `${item}`;
|
|
817
|
-
}
|
package/src/IActionResult.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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
|
|
65
|
-
|
|
66
|
-
|
|
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]:
|
|
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]:
|
|
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;
|