@punks/backend-core 0.0.27 → 0.0.29
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/cjs/index.js +65 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/index.d.ts +1 -0
- package/dist/cjs/types/models/index.d.ts +1 -0
- package/dist/cjs/types/models/trees.d.ts +8 -0
- package/dist/cjs/types/utils/array.d.ts +1 -0
- package/dist/cjs/types/utils/index.d.ts +1 -0
- package/dist/cjs/types/utils/objects.d.ts +4 -0
- package/dist/cjs/types/utils/trees.d.ts +7 -0
- package/dist/cjs/types/utils/trees.spec.d.ts +1 -0
- package/dist/esm/index.js +63 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/index.d.ts +1 -0
- package/dist/esm/types/models/index.d.ts +1 -0
- package/dist/esm/types/models/trees.d.ts +8 -0
- package/dist/esm/types/utils/array.d.ts +1 -0
- package/dist/esm/types/utils/index.d.ts +1 -0
- package/dist/esm/types/utils/objects.d.ts +4 -0
- package/dist/esm/types/utils/trees.d.ts +7 -0
- package/dist/esm/types/utils/trees.spec.d.ts +1 -0
- package/dist/index.d.ts +22 -1
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./trees";
|
|
@@ -21,4 +21,5 @@ export declare const distinct: <T>(values: T[]) => T[];
|
|
|
21
21
|
export declare const distinctElements: <T>(values: T[], comparer: (value: T) => any) => T[];
|
|
22
22
|
export declare const jsonDistinct: <T>(values: T[]) => T[];
|
|
23
23
|
export declare const iterate: <T>(values: T[], action: (item: T, next?: T | undefined, prev?: T | undefined) => void) => void;
|
|
24
|
+
export declare const groupBy: <TKey, TValue>(values: TValue[], keySelector: (value: TValue) => TKey) => Map<TKey, TValue[]>;
|
|
24
25
|
export {};
|
|
@@ -6,6 +6,7 @@ export * from "./strings";
|
|
|
6
6
|
export * from "./objects";
|
|
7
7
|
export * from "./text";
|
|
8
8
|
export * from "./threading";
|
|
9
|
+
export { buildTree, TreeNodeBuilder } from "./trees";
|
|
9
10
|
export * from "./mappings";
|
|
10
11
|
export * from "./uid";
|
|
11
12
|
export { ExcelSheetDefinition, ExcelKeyTransform, ExcelColumnDefinition as ExcelRowBuilder, ExcelParseOptions, excelBuild, excelParse, } from "./xls";
|
|
@@ -2,3 +2,7 @@ export declare const removeUndefinedProps: <T extends Record<string, any>>(obj:
|
|
|
2
2
|
recursive?: boolean;
|
|
3
3
|
}) => T;
|
|
4
4
|
export declare const isNullOrUndefined: (value: any) => boolean;
|
|
5
|
+
export declare const buildObject: <T>(...props: {
|
|
6
|
+
key: string;
|
|
7
|
+
value: any;
|
|
8
|
+
}[]) => T;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ITree, ITreeNode } from "../models";
|
|
2
|
+
export type TreeNodeBuilder<TKey, TRecord, TTreeNode extends ITreeNode<TKey, TRecord>> = {
|
|
3
|
+
idSelector: (record: TRecord) => TKey;
|
|
4
|
+
parentIdSelector: (record: TRecord) => TKey | undefined;
|
|
5
|
+
additionalPropsBuilder?: (record: TRecord, ancestors: TRecord[], children: TRecord[]) => Promise<Omit<TTreeNode, "id" | "children" | "value">>;
|
|
6
|
+
};
|
|
7
|
+
export declare const buildTree: <TKey, TRecord, TTreeNode extends ITreeNode<TKey, TRecord>>(data: TRecord[], nodeBuilder: TreeNodeBuilder<TKey, TRecord, TTreeNode>) => Promise<ITree<TKey, TRecord>>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.d.ts
CHANGED
|
@@ -42,6 +42,15 @@ declare class Log {
|
|
|
42
42
|
static getLogger(loggerName: string): ILogger;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
interface ITreeNode<TKey, TValue> {
|
|
46
|
+
id: TKey;
|
|
47
|
+
value: TValue;
|
|
48
|
+
children: ITreeNode<TKey, TValue>[];
|
|
49
|
+
}
|
|
50
|
+
interface ITree<TKey, TValue> {
|
|
51
|
+
root: ITreeNode<TKey, TValue>[];
|
|
52
|
+
}
|
|
53
|
+
|
|
45
54
|
type RichText = PortableTextBlock[];
|
|
46
55
|
|
|
47
56
|
declare const range: (start: number, end: number) => number[];
|
|
@@ -67,6 +76,7 @@ declare const distinct: <T>(values: T[]) => T[];
|
|
|
67
76
|
declare const distinctElements: <T>(values: T[], comparer: (value: T) => any) => T[];
|
|
68
77
|
declare const jsonDistinct: <T>(values: T[]) => T[];
|
|
69
78
|
declare const iterate: <T>(values: T[], action: (item: T, next?: T | undefined, prev?: T | undefined) => void) => void;
|
|
79
|
+
declare const groupBy: <TKey, TValue>(values: TValue[], keySelector: (value: TValue) => TKey) => Map<TKey, TValue[]>;
|
|
70
80
|
|
|
71
81
|
declare const csvParse: (data: string | string[] | Buffer, separator?: string) => Record<string, any>[];
|
|
72
82
|
interface CsvColumnDefinition<T> {
|
|
@@ -101,11 +111,22 @@ declare const removeUndefinedProps: <T extends Record<string, any>>(obj: T, opti
|
|
|
101
111
|
recursive?: boolean;
|
|
102
112
|
}) => T;
|
|
103
113
|
declare const isNullOrUndefined: (value: any) => boolean;
|
|
114
|
+
declare const buildObject: <T>(...props: {
|
|
115
|
+
key: string;
|
|
116
|
+
value: any;
|
|
117
|
+
}[]) => T;
|
|
104
118
|
|
|
105
119
|
declare const pluralize: (word: string) => string;
|
|
106
120
|
|
|
107
121
|
declare function sleep(ms: number): Promise<unknown>;
|
|
108
122
|
|
|
123
|
+
type TreeNodeBuilder<TKey, TRecord, TTreeNode extends ITreeNode<TKey, TRecord>> = {
|
|
124
|
+
idSelector: (record: TRecord) => TKey;
|
|
125
|
+
parentIdSelector: (record: TRecord) => TKey | undefined;
|
|
126
|
+
additionalPropsBuilder?: (record: TRecord, ancestors: TRecord[], children: TRecord[]) => Promise<Omit<TTreeNode, "id" | "children" | "value">>;
|
|
127
|
+
};
|
|
128
|
+
declare const buildTree: <TKey, TRecord, TTreeNode extends ITreeNode<TKey, TRecord>>(data: TRecord[], nodeBuilder: TreeNodeBuilder<TKey, TRecord, TTreeNode>) => Promise<ITree<TKey, TRecord>>;
|
|
129
|
+
|
|
109
130
|
declare const mapOrThrow: <T>({ mapper, throw: throwFn, }: {
|
|
110
131
|
mapper: () => T | undefined;
|
|
111
132
|
throw: () => void;
|
|
@@ -134,4 +155,4 @@ type ExcelParseOptions = {
|
|
|
134
155
|
};
|
|
135
156
|
declare const excelParse: (file: string | ArrayBuffer, options?: ExcelParseOptions) => any[];
|
|
136
157
|
|
|
137
|
-
export { CsvColumnDefinition as ColumnDefinition, CsvBuildOptions, Dict, ExcelKeyTransform, ExcelParseOptions, ExcelColumnDefinition as ExcelRowBuilder, ExcelSheetDefinition, ILogger, ILoggerProvider, IResolveServiceOptions, IServiceLocator, Log, LogLevel, RichText, byField, byFieldDesc, camelToKebabCase, camelToSnakeCase, csvBuild, csvParse, distinct, distinctElements, ensureDirectory, ensureStartSlash, ensureTailingSlash, excelBuild, excelParse, first, flatten, getDirectoryFilePaths, getDirectoryPath, indexes, isNullOrUndefined, iterate, joinPath, jsonDistinct, last, mapOrThrow, newUuid, notNull, notUndefined, pluralize, range, removeUndefinedProps, selectMany, sleep, sort, splitPath, toCamelCase, toDict, toItemsDict, toItemsMap, toMap, toTitleCase, trim, trimEnd, trimStart };
|
|
158
|
+
export { CsvColumnDefinition as ColumnDefinition, CsvBuildOptions, Dict, ExcelKeyTransform, ExcelParseOptions, ExcelColumnDefinition as ExcelRowBuilder, ExcelSheetDefinition, ILogger, ILoggerProvider, IResolveServiceOptions, IServiceLocator, ITree, ITreeNode, Log, LogLevel, RichText, TreeNodeBuilder, buildObject, buildTree, byField, byFieldDesc, camelToKebabCase, camelToSnakeCase, csvBuild, csvParse, distinct, distinctElements, ensureDirectory, ensureStartSlash, ensureTailingSlash, excelBuild, excelParse, first, flatten, getDirectoryFilePaths, getDirectoryPath, groupBy, indexes, isNullOrUndefined, iterate, joinPath, jsonDistinct, last, mapOrThrow, newUuid, notNull, notUndefined, pluralize, range, removeUndefinedProps, selectMany, sleep, sort, splitPath, toCamelCase, toDict, toItemsDict, toItemsMap, toMap, toTitleCase, trim, trimEnd, trimStart };
|