ia-common 1.1.1-beta.34 → 1.1.1-beta.37

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.
@@ -1,6 +1,10 @@
1
1
  export declare const ONE_MB: number;
2
2
  export declare const TEN_MB: number;
3
3
  export declare const FIFTY_MB: number;
4
+ export type lorem = Record<FileFormatEnum, {
5
+ mimeTypes: string[];
6
+ defaultSize: number;
7
+ }>;
4
8
  export declare enum FileFormatEnum {
5
9
  PDF = "application/pdf",
6
10
  MP3 = "audio/mp3",
@@ -9,13 +13,15 @@ export declare enum FileFormatEnum {
9
13
  JPEG = "image/jpeg",
10
14
  PNG = "image/png"
11
15
  }
12
- export declare namespace FileFormatConfig {
13
- /** get allowed MIME types for a file format */
14
- function getAllowedMimeTypes(format: FileFormatEnum): string[];
15
- /** check if a MIME type is allowed for a format */
16
+ export declare namespace FileFormatEnum {
17
+ const mimeTypeMap: Map<FileFormatEnum, readonly string[]>;
18
+ const sizeMap: Map<FileFormatEnum, number>;
19
+ /** Get allowed MIME types for a file format */
20
+ function getAllowedMimeTypes(format: FileFormatEnum): readonly string[];
21
+ /** Check if a MIME type is allowed for a format */
16
22
  function isMimeTypeAllowed(format: FileFormatEnum, mimeType: string): boolean;
17
- /** get max file size (bytes) with optional fallback */
18
- function getMaxSize(format: FileFormatEnum, fallback: number): number;
19
- /** get allowed mime types from formats */
23
+ /** Get default max file size in bytes */
24
+ function defaultSize(format: FileFormatEnum): number;
25
+ /** Get all allowed MIME types from multiple formats */
20
26
  function getAllowedMimeTypesFromFormats(formats: FileFormatEnum[]): string[];
21
27
  }
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FileFormatConfig = exports.FileFormatEnum = exports.FIFTY_MB = exports.TEN_MB = exports.ONE_MB = void 0;
3
+ exports.FileFormatEnum = exports.FIFTY_MB = exports.TEN_MB = exports.ONE_MB = void 0;
4
+ const _model_1 = require("../@model");
4
5
  exports.ONE_MB = 1 * 1024 * 1024;
5
6
  exports.TEN_MB = 10 * 1024 * 1024;
6
7
  exports.FIFTY_MB = 50 * 1024 * 1024;
7
- // give me an enum for each file mime type agains the actual format
8
8
  var FileFormatEnum;
9
9
  (function (FileFormatEnum) {
10
10
  FileFormatEnum["PDF"] = "application/pdf";
@@ -14,48 +14,120 @@ var FileFormatEnum;
14
14
  FileFormatEnum["JPEG"] = "image/jpeg";
15
15
  FileFormatEnum["PNG"] = "image/png";
16
16
  })(FileFormatEnum || (exports.FileFormatEnum = FileFormatEnum = {}));
17
- var FileFormatConfig;
18
- (function (FileFormatConfig) {
19
- /** MIME types allowed for each file format */
20
- const mimeTypeMap = new Map([
21
- [FileFormatEnum.PDF, ["application/pdf"]],
22
- [FileFormatEnum.MP3, ["audio/mpeg", "audio/mp3"]],
23
- [FileFormatEnum.MP4, ["video/mp4"]],
24
- [FileFormatEnum.JPEG, ["image/jpeg"]],
25
- [FileFormatEnum.PNG, ["image/png"]],
26
- ]);
27
- /** Default max file size (in bytes) per format */
28
- const sizeMap = new Map([
29
- [FileFormatEnum.PDF, 1 * 1024 * 1024], // 1 MB
30
- [FileFormatEnum.MP3, 10 * 1024 * 1024],
31
- [FileFormatEnum.MP4, 50 * 1024 * 1024],
32
- [FileFormatEnum.JPEG, 2 * 1024 * 1024],
33
- [FileFormatEnum.PNG, 2 * 1024 * 1024],
34
- ]);
35
- /** get allowed MIME types for a file format */
17
+ // Now build the maps inside the namespace
18
+ (function (FileFormatEnum) {
19
+ // Define the configuration object with full compile-time exhaustiveness
20
+ const fileFormatConfig = {
21
+ [FileFormatEnum.PDF]: {
22
+ mimeTypes: ["application/pdf"],
23
+ defaultSize: 1 * 1024 * 1024, // 1 MB
24
+ },
25
+ [FileFormatEnum.MP3]: {
26
+ mimeTypes: ["audio/mpeg", "audio/mp3"],
27
+ defaultSize: 10 * 1024 * 1024, // 10 MB
28
+ },
29
+ [FileFormatEnum.MPEG]: {
30
+ mimeTypes: ["audio/mpeg"],
31
+ defaultSize: 10 * 1024 * 1024, // 10 MB
32
+ },
33
+ [FileFormatEnum.MP4]: {
34
+ mimeTypes: ["video/mp4"],
35
+ defaultSize: 50 * 1024 * 1024, // 50 MB
36
+ },
37
+ [FileFormatEnum.JPEG]: {
38
+ mimeTypes: ["image/jpeg"],
39
+ defaultSize: 1 * 1024 * 1024, // 1 MB
40
+ },
41
+ [FileFormatEnum.PNG]: {
42
+ mimeTypes: ["image/png"],
43
+ defaultSize: 1 * 1024 * 1024, // 1 MB
44
+ },
45
+ };
46
+ FileFormatEnum.mimeTypeMap = new Map(Object.entries(fileFormatConfig).map(([key, config]) => [
47
+ key,
48
+ config.mimeTypes,
49
+ ]));
50
+ FileFormatEnum.sizeMap = new Map(Object.entries(fileFormatConfig).map(([key, config]) => [
51
+ key,
52
+ config.defaultSize,
53
+ ]));
54
+ /** Get allowed MIME types for a file format */
36
55
  function getAllowedMimeTypes(format) {
37
56
  var _a;
38
- return (_a = mimeTypeMap.get(format)) !== null && _a !== void 0 ? _a : [];
57
+ return (_a = FileFormatEnum.mimeTypeMap.get(format)) !== null && _a !== void 0 ? _a : [];
39
58
  }
40
- FileFormatConfig.getAllowedMimeTypes = getAllowedMimeTypes;
41
- /** check if a MIME type is allowed for a format */
59
+ FileFormatEnum.getAllowedMimeTypes = getAllowedMimeTypes;
60
+ /** Check if a MIME type is allowed for a format */
42
61
  function isMimeTypeAllowed(format, mimeType) {
43
62
  return getAllowedMimeTypes(format).includes(mimeType);
44
63
  }
45
- FileFormatConfig.isMimeTypeAllowed = isMimeTypeAllowed;
46
- /** get max file size (bytes) with optional fallback */
47
- function getMaxSize(format, fallback) {
48
- var _a;
49
- return (_a = sizeMap.get(format)) !== null && _a !== void 0 ? _a : fallback;
64
+ FileFormatEnum.isMimeTypeAllowed = isMimeTypeAllowed;
65
+ /** Get default max file size in bytes */
66
+ function defaultSize(format) {
67
+ const size = FileFormatEnum.sizeMap.get(format);
68
+ if (size === undefined) {
69
+ throw new _model_1.AppBadRequestException({
70
+ key: `${format}`,
71
+ message: [`No default size set for format: ${format}`],
72
+ });
73
+ }
74
+ return size;
50
75
  }
51
- FileFormatConfig.getMaxSize = getMaxSize;
52
- /** get allowed mime types from formats */
76
+ FileFormatEnum.defaultSize = defaultSize;
77
+ /** Get all allowed MIME types from multiple formats */
53
78
  function getAllowedMimeTypesFromFormats(formats) {
54
- const allowedMimeTypes = [];
55
- for (const format of formats) {
56
- allowedMimeTypes.push(this.getAllowedMimeTypes(format));
57
- }
58
- return allowedMimeTypes.flat();
79
+ return formats.flatMap((format) => [...getAllowedMimeTypes(format)]);
59
80
  }
60
- FileFormatConfig.getAllowedMimeTypesFromFormats = getAllowedMimeTypesFromFormats;
61
- })(FileFormatConfig || (exports.FileFormatConfig = FileFormatConfig = {}));
81
+ FileFormatEnum.getAllowedMimeTypesFromFormats = getAllowedMimeTypesFromFormats;
82
+ })(FileFormatEnum || (exports.FileFormatEnum = FileFormatEnum = {}));
83
+ // export namespace FileFormatEnum {
84
+ // /** MIME types allowed for each file format */
85
+ // const mimeTypeMap = new Map<FileFormatEnum, string[]>([
86
+ // [FileFormatEnum.PDF, ["application/pdf"]],
87
+ // [FileFormatEnum.MP3, ["audio/mpeg", "audio/mp3"]],
88
+ // [FileFormatEnum.MP4, ["video/mp4"]],
89
+ // [FileFormatEnum.JPEG, ["image/jpeg"]],
90
+ // [FileFormatEnum.PNG, ["image/png"]],
91
+ // ]);
92
+ // /** Default max file size (in bytes) per format */
93
+ // const sizeMap = new Map<FileFormatEnum, number>([
94
+ // [FileFormatEnum.PDF, 1 * 1024 * 1024], // 1 MB
95
+ // [FileFormatEnum.MP3, 10 * 1024 * 1024],
96
+ // [FileFormatEnum.MP4, 50 * 1024 * 1024],
97
+ // [FileFormatEnum.JPEG, 2 * 1024 * 1024],
98
+ // [FileFormatEnum.PNG, 2 * 1024 * 1024],
99
+ // ]);
100
+ // /** get allowed MIME types for a file format */
101
+ // export function getAllowedMimeTypes(format: FileFormatEnum): string[] {
102
+ // return mimeTypeMap.get(format) ?? [];
103
+ // }
104
+ // /** check if a MIME type is allowed for a format */
105
+ // export function isMimeTypeAllowed(
106
+ // format: FileFormatEnum,
107
+ // mimeType: string
108
+ // ): boolean {
109
+ // return getAllowedMimeTypes(format).includes(mimeType);
110
+ // }
111
+ // /** get max file size (bytes) with optional fallback */
112
+ // export function defaultSize(format: FileFormatEnum): number {
113
+ // const size = sizeMap.get(format);
114
+ // if (!size) {
115
+ // // need to keep this if-check as map.get returns T | undefined
116
+ // throw new AppBadRequestException({
117
+ // key: `${format}`,
118
+ // message: [`No default size set for ${format}`],
119
+ // });
120
+ // }
121
+ // return size;
122
+ // }
123
+ // /** get allowed mime types from formats */
124
+ // export function getAllowedMimeTypesFromFormats(
125
+ // formats: FileFormatEnum[]
126
+ // ): string[] {
127
+ // const allowedMimeTypes: string[] = [];
128
+ // for (const format of formats) {
129
+ // allowedMimeTypes.push(this.getAllowedMimeTypes(format));
130
+ // }
131
+ // return allowedMimeTypes.flat();
132
+ // }
133
+ // }
@@ -5,31 +5,29 @@ const constants_1 = require("../../constants");
5
5
  exports.corporateActionAdviceFileUploadConfig = [
6
6
  {
7
7
  name: "noteDocument",
8
- size: constants_1.FileFormatConfig.getMaxSize(constants_1.FileFormatEnum.PDF, constants_1.ONE_MB),
8
+ size: constants_1.FileFormatEnum.defaultSize(constants_1.FileFormatEnum.PDF),
9
9
  count: 1,
10
10
  isRequired: false,
11
- format: constants_1.FileFormatConfig.getAllowedMimeTypesFromFormats([
11
+ format: constants_1.FileFormatEnum.getAllowedMimeTypesFromFormats([
12
12
  constants_1.FileFormatEnum.JPEG,
13
13
  constants_1.FileFormatEnum.PDF,
14
14
  ]),
15
15
  },
16
16
  {
17
17
  name: "voiceDocument",
18
- size: constants_1.FileFormatConfig.getMaxSize(constants_1.FileFormatEnum.MP3, constants_1.TEN_MB),
18
+ size: constants_1.FileFormatEnum.defaultSize(constants_1.FileFormatEnum.MP3),
19
19
  count: 1,
20
20
  isRequired: false,
21
- format: constants_1.FileFormatConfig.getAllowedMimeTypesFromFormats([
21
+ format: constants_1.FileFormatEnum.getAllowedMimeTypesFromFormats([
22
22
  constants_1.FileFormatEnum.MP3,
23
23
  constants_1.FileFormatEnum.MPEG,
24
24
  ]),
25
25
  },
26
26
  {
27
27
  name: "videoDocument",
28
- size: constants_1.FileFormatConfig.getMaxSize(constants_1.FileFormatEnum.MP4, constants_1.FIFTY_MB),
28
+ size: constants_1.FileFormatEnum.defaultSize(constants_1.FileFormatEnum.MP4),
29
29
  count: 1,
30
30
  isRequired: false,
31
- format: constants_1.FileFormatConfig.getAllowedMimeTypesFromFormats([
32
- constants_1.FileFormatEnum.MP4,
33
- ]),
31
+ format: constants_1.FileFormatEnum.getAllowedMimeTypesFromFormats([constants_1.FileFormatEnum.MP4]),
34
32
  },
35
33
  ];
@@ -1,4 +1,4 @@
1
1
  export interface IDeleteDocumentDetails<T> {
2
- key: keyof T;
2
+ key: Extract<keyof T, string>;
3
3
  urls: string[];
4
4
  }
@@ -5,31 +5,29 @@ const constants_1 = require("../../constants");
5
5
  exports.equityAdviceFileUploadConfig = [
6
6
  {
7
7
  name: "noteDocument",
8
- size: constants_1.FileFormatConfig.getMaxSize(constants_1.FileFormatEnum.PDF, constants_1.ONE_MB),
8
+ size: constants_1.FileFormatEnum.defaultSize(constants_1.FileFormatEnum.PDF),
9
9
  count: 1,
10
10
  isRequired: false,
11
- format: constants_1.FileFormatConfig.getAllowedMimeTypesFromFormats([
11
+ format: constants_1.FileFormatEnum.getAllowedMimeTypesFromFormats([
12
12
  constants_1.FileFormatEnum.JPEG,
13
13
  constants_1.FileFormatEnum.PDF,
14
14
  ]),
15
15
  },
16
16
  {
17
17
  name: "voiceDocument",
18
- size: constants_1.FileFormatConfig.getMaxSize(constants_1.FileFormatEnum.MP3, constants_1.TEN_MB),
18
+ size: constants_1.FileFormatEnum.defaultSize(constants_1.FileFormatEnum.MP3),
19
19
  count: 1,
20
20
  isRequired: false,
21
- format: constants_1.FileFormatConfig.getAllowedMimeTypesFromFormats([
21
+ format: constants_1.FileFormatEnum.getAllowedMimeTypesFromFormats([
22
22
  constants_1.FileFormatEnum.MP3,
23
23
  constants_1.FileFormatEnum.MPEG,
24
24
  ]),
25
25
  },
26
26
  {
27
27
  name: "videoDocument",
28
- size: constants_1.FileFormatConfig.getMaxSize(constants_1.FileFormatEnum.MP4, constants_1.FIFTY_MB),
28
+ size: constants_1.FileFormatEnum.defaultSize(constants_1.FileFormatEnum.MP4),
29
29
  count: 1,
30
30
  isRequired: false,
31
- format: constants_1.FileFormatConfig.getAllowedMimeTypesFromFormats([
32
- constants_1.FileFormatEnum.MP4,
33
- ]),
31
+ format: constants_1.FileFormatEnum.getAllowedMimeTypesFromFormats([constants_1.FileFormatEnum.MP4]),
34
32
  },
35
33
  ];
@@ -1,5 +1,6 @@
1
1
  import { AdviceTransactionType, AdviceType, InvestDurationType } from "../../enum";
2
2
  import { EntityEnum, EnumEntityType, IEntityUpdateDto } from "../entity";
3
+ import { IDeleteDocumentDetails } from "./delete-document-details.interface";
3
4
  export interface IEquityAdviceUpdateDto {
4
5
  type?: AdviceType;
5
6
  stockName?: string;
@@ -16,8 +17,5 @@ export interface IEquityAdviceUpdateDto {
16
17
  rationale?: string;
17
18
  }
18
19
  export interface IEquityAdviceUpdateDtoV2 extends IEntityUpdateDto<EnumEntityType<EntityEnum.EQUITY_ADVICE>> {
19
- }
20
- export interface IDeleteDocumentDetails<T extends IEntityUpdateDto<EnumEntityType<EntityEnum>>> {
21
- key: keyof T;
22
- urls: string[];
20
+ deleteDocumentDetails?: IDeleteDocumentDetails<EnumEntityType<EntityEnum.EQUITY_ADVICE>>[];
23
21
  }
@@ -5,31 +5,29 @@ const constants_1 = require("../../constants");
5
5
  exports.mutualFundAdviceFileUploadConfig = [
6
6
  {
7
7
  name: "noteDocument",
8
- size: constants_1.FileFormatConfig.getMaxSize(constants_1.FileFormatEnum.PDF, constants_1.ONE_MB),
8
+ size: constants_1.FileFormatEnum.defaultSize(constants_1.FileFormatEnum.PDF),
9
9
  count: 1,
10
10
  isRequired: false,
11
- format: constants_1.FileFormatConfig.getAllowedMimeTypesFromFormats([
11
+ format: constants_1.FileFormatEnum.getAllowedMimeTypesFromFormats([
12
12
  constants_1.FileFormatEnum.JPEG,
13
13
  constants_1.FileFormatEnum.PDF,
14
14
  ]),
15
15
  },
16
16
  {
17
17
  name: "voiceDocument",
18
- size: constants_1.FileFormatConfig.getMaxSize(constants_1.FileFormatEnum.MP3, constants_1.TEN_MB),
18
+ size: constants_1.FileFormatEnum.defaultSize(constants_1.FileFormatEnum.MP3),
19
19
  count: 1,
20
20
  isRequired: false,
21
- format: constants_1.FileFormatConfig.getAllowedMimeTypesFromFormats([
21
+ format: constants_1.FileFormatEnum.getAllowedMimeTypesFromFormats([
22
22
  constants_1.FileFormatEnum.MP3,
23
23
  constants_1.FileFormatEnum.MPEG,
24
24
  ]),
25
25
  },
26
26
  {
27
27
  name: "videoDocument",
28
- size: constants_1.FileFormatConfig.getMaxSize(constants_1.FileFormatEnum.MP4, constants_1.FIFTY_MB),
28
+ size: constants_1.FileFormatEnum.defaultSize(constants_1.FileFormatEnum.MP4),
29
29
  count: 1,
30
30
  isRequired: false,
31
- format: constants_1.FileFormatConfig.getAllowedMimeTypesFromFormats([
32
- constants_1.FileFormatEnum.MP4,
33
- ]),
31
+ format: constants_1.FileFormatEnum.getAllowedMimeTypesFromFormats([constants_1.FileFormatEnum.MP4]),
34
32
  },
35
33
  ];
@@ -5,31 +5,29 @@ const constants_1 = require("../../constants");
5
5
  exports.nfoAdviceFileUploadConfig = [
6
6
  {
7
7
  name: "noteDocument",
8
- size: constants_1.FileFormatConfig.getMaxSize(constants_1.FileFormatEnum.PDF, constants_1.ONE_MB),
8
+ size: constants_1.FileFormatEnum.defaultSize(constants_1.FileFormatEnum.PDF),
9
9
  count: 1,
10
10
  isRequired: false,
11
- format: constants_1.FileFormatConfig.getAllowedMimeTypesFromFormats([
11
+ format: constants_1.FileFormatEnum.getAllowedMimeTypesFromFormats([
12
12
  constants_1.FileFormatEnum.JPEG,
13
13
  constants_1.FileFormatEnum.PDF,
14
14
  ]),
15
15
  },
16
16
  {
17
17
  name: "voiceDocument",
18
- size: constants_1.FileFormatConfig.getMaxSize(constants_1.FileFormatEnum.MP3, constants_1.TEN_MB),
18
+ size: constants_1.FileFormatEnum.defaultSize(constants_1.FileFormatEnum.MP3),
19
19
  count: 1,
20
20
  isRequired: false,
21
- format: constants_1.FileFormatConfig.getAllowedMimeTypesFromFormats([
21
+ format: constants_1.FileFormatEnum.getAllowedMimeTypesFromFormats([
22
22
  constants_1.FileFormatEnum.MP3,
23
23
  constants_1.FileFormatEnum.MPEG,
24
24
  ]),
25
25
  },
26
26
  {
27
27
  name: "videoDocument",
28
- size: constants_1.FileFormatConfig.getMaxSize(constants_1.FileFormatEnum.MP4, constants_1.FIFTY_MB),
28
+ size: constants_1.FileFormatEnum.defaultSize(constants_1.FileFormatEnum.MP4),
29
29
  count: 1,
30
30
  isRequired: false,
31
- format: constants_1.FileFormatConfig.getAllowedMimeTypesFromFormats([
32
- constants_1.FileFormatEnum.MP4,
33
- ]),
31
+ format: constants_1.FileFormatEnum.getAllowedMimeTypesFromFormats([constants_1.FileFormatEnum.MP4]),
34
32
  },
35
33
  ];
@@ -13,7 +13,6 @@ export declare function transformDate<T extends {
13
13
  date: string;
14
14
  }>;
15
15
  export declare function groupByFunction<T, K>(list: T[], keyGetter: (input: T) => K): Map<K, T[]>;
16
- export declare function toDateFromEpoch(epoch: number): Date;
17
16
  /**
18
17
  * Deeply merges the properties of the `source` object into the `target` object.
19
18
  *
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.camelCaseToTitle = exports.derivePermissionGroup = exports.getDuplicates = exports.getPropertyFilterByPermissionFn = exports.groupByOneToOneFunction = exports.deepMerge = exports.toDateFromEpoch = exports.groupByFunction = exports.transformDate = exports.getStringValues = exports.getTodayISTEpoch = void 0;
12
+ exports.camelCaseToTitle = exports.derivePermissionGroup = exports.getDuplicates = exports.getPropertyFilterByPermissionFn = exports.groupByOneToOneFunction = exports.deepMerge = exports.groupByFunction = exports.transformDate = exports.getStringValues = exports.getTodayISTEpoch = void 0;
13
13
  const _enum_1 = require("../@enum");
14
14
  const _type_1 = require("../@type");
15
15
  const model_1 = require("../model");
@@ -48,10 +48,6 @@ function groupByFunction(list, keyGetter) {
48
48
  return map;
49
49
  }
50
50
  exports.groupByFunction = groupByFunction;
51
- function toDateFromEpoch(epoch) {
52
- return new Date(epoch);
53
- }
54
- exports.toDateFromEpoch = toDateFromEpoch;
55
51
  /**
56
52
  * Deeply merges the properties of the `source` object into the `target` object.
57
53
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ia-common",
3
- "version": "1.1.1-beta.34",
3
+ "version": "1.1.1-beta.37",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",