@nu-art/ts-common 0.202.91 → 0.202.93

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,4 +1,4 @@
1
- import { ApiException } from "./exceptions";
1
+ import { ApiException } from './exceptions';
2
2
  import { ApiError_GeneralErrorMessage } from './types';
3
3
  export declare const HttpCodes: {
4
4
  readonly _1XX: {
@@ -33,56 +33,134 @@ export declare const HttpCodes: {
33
33
  readonly BAD_REQUEST: ((userMessage: string, debugMessage?: string, cause?: Error) => ApiException<ApiError_GeneralErrorMessage>) & {
34
34
  code: number;
35
35
  };
36
- readonly UNAUTHORIZED: 401;
37
- readonly PAYMENT_REQUIRED: 402;
36
+ readonly UNAUTHORIZED: ((userMessage: string, debugMessage?: string, cause?: Error) => ApiException<ApiError_GeneralErrorMessage>) & {
37
+ code: number;
38
+ };
39
+ readonly PAYMENT_REQUIRED: ((userMessage: string, debugMessage?: string, cause?: Error) => ApiException<ApiError_GeneralErrorMessage>) & {
40
+ code: number;
41
+ };
38
42
  readonly FORBIDDEN: ((userMessage: string, debugMessage?: string, cause?: Error) => ApiException<ApiError_GeneralErrorMessage>) & {
39
43
  code: number;
40
44
  };
41
- readonly NOT_FOUND: 404;
42
- readonly METHOD_NOT_ALLOWED: 405;
43
- readonly NOT_ACCEPTABLE: 406;
44
- readonly PROXY_AUTHENTICATION_REQUIRED: 407;
45
- readonly REQUEST_TIMEOUT: 408;
46
- readonly CONFLICT: 409;
47
- readonly GONE: 410;
48
- readonly LENGTH_REQUIRED: 411;
49
- readonly PRECONDITION_FAILED: 412;
50
- readonly PAYLOAD_TOO_LARGE: 413;
51
- readonly URI_TOO_LONG: 414;
52
- readonly UNSUPPORTED_MEDIA_TYPE: 415;
53
- readonly RANGE_NOT_SATISFIABLE: 416;
54
- readonly EXPECTATION_FAILED: 417;
55
- readonly IM_A_TEAPOT: 418;
56
- readonly MISDIRECTED_REQUEST: 421;
57
- readonly UNPROCESSABLE_ENTITY: 422;
58
- readonly LOCKED: 423;
59
- readonly FAILED_DEPENDENCY: 424;
60
- readonly TOO_EARLY: 425;
61
- readonly UPGRADE_REQUIRED: 426;
62
- readonly PRECONDITION_REQUIRED: 428;
63
- readonly TOO_MANY_REQUESTS: 429;
64
- readonly REQUEST_HEADER_FIELDS_TOO_LARGE: 431;
65
- readonly UNAVAILABLE_FOR_LEGAL_REASONS: 451;
66
- readonly ENTITY_ALREADY_EXISTS: 460;
45
+ readonly NOT_FOUND: ((userMessage: string, debugMessage?: string, cause?: Error) => ApiException<ApiError_GeneralErrorMessage>) & {
46
+ code: number;
47
+ };
48
+ readonly METHOD_NOT_ALLOWED: ((userMessage: string, debugMessage?: string, cause?: Error) => ApiException<ApiError_GeneralErrorMessage>) & {
49
+ code: number;
50
+ };
51
+ readonly NOT_ACCEPTABLE: ((userMessage: string, debugMessage?: string, cause?: Error) => ApiException<ApiError_GeneralErrorMessage>) & {
52
+ code: number;
53
+ };
54
+ readonly PROXY_AUTHENTICATION_REQUIRED: ((userMessage: string, debugMessage?: string, cause?: Error) => ApiException<ApiError_GeneralErrorMessage>) & {
55
+ code: number;
56
+ };
57
+ readonly REQUEST_TIMEOUT: ((userMessage: string, debugMessage?: string, cause?: Error) => ApiException<ApiError_GeneralErrorMessage>) & {
58
+ code: number;
59
+ };
60
+ readonly CONFLICT: ((userMessage: string, debugMessage?: string, cause?: Error) => ApiException<ApiError_GeneralErrorMessage>) & {
61
+ code: number;
62
+ };
63
+ readonly GONE: ((userMessage: string, debugMessage?: string, cause?: Error) => ApiException<ApiError_GeneralErrorMessage>) & {
64
+ code: number;
65
+ };
66
+ readonly LENGTH_REQUIRED: ((userMessage: string, debugMessage?: string, cause?: Error) => ApiException<ApiError_GeneralErrorMessage>) & {
67
+ code: number;
68
+ };
69
+ readonly PRECONDITION_FAILED: ((userMessage: string, debugMessage?: string, cause?: Error) => ApiException<ApiError_GeneralErrorMessage>) & {
70
+ code: number;
71
+ };
72
+ readonly PAYLOAD_TOO_LARGE: ((userMessage: string, debugMessage?: string, cause?: Error) => ApiException<ApiError_GeneralErrorMessage>) & {
73
+ code: number;
74
+ };
75
+ readonly URI_TOO_LONG: ((userMessage: string, debugMessage?: string, cause?: Error) => ApiException<ApiError_GeneralErrorMessage>) & {
76
+ code: number;
77
+ };
78
+ readonly UNSUPPORTED_MEDIA_TYPE: ((userMessage: string, debugMessage?: string, cause?: Error) => ApiException<ApiError_GeneralErrorMessage>) & {
79
+ code: number;
80
+ };
81
+ readonly RANGE_NOT_SATISFIABLE: ((userMessage: string, debugMessage?: string, cause?: Error) => ApiException<ApiError_GeneralErrorMessage>) & {
82
+ code: number;
83
+ };
84
+ readonly EXPECTATION_FAILED: ((userMessage: string, debugMessage?: string, cause?: Error) => ApiException<ApiError_GeneralErrorMessage>) & {
85
+ code: number;
86
+ };
87
+ readonly IM_A_TEAPOT: ((userMessage: string, debugMessage?: string, cause?: Error) => ApiException<ApiError_GeneralErrorMessage>) & {
88
+ code: number;
89
+ };
90
+ readonly MISDIRECTED_REQUEST: ((userMessage: string, debugMessage?: string, cause?: Error) => ApiException<ApiError_GeneralErrorMessage>) & {
91
+ code: number;
92
+ };
93
+ readonly UNPROCESSABLE_ENTITY: ((userMessage: string, debugMessage?: string, cause?: Error) => ApiException<ApiError_GeneralErrorMessage>) & {
94
+ code: number;
95
+ };
96
+ readonly LOCKED: ((userMessage: string, debugMessage?: string, cause?: Error) => ApiException<ApiError_GeneralErrorMessage>) & {
97
+ code: number;
98
+ };
99
+ readonly FAILED_DEPENDENCY: ((userMessage: string, debugMessage?: string, cause?: Error) => ApiException<ApiError_GeneralErrorMessage>) & {
100
+ code: number;
101
+ };
102
+ readonly TOO_EARLY: ((userMessage: string, debugMessage?: string, cause?: Error) => ApiException<ApiError_GeneralErrorMessage>) & {
103
+ code: number;
104
+ };
105
+ readonly UPGRADE_REQUIRED: ((userMessage: string, debugMessage?: string, cause?: Error) => ApiException<ApiError_GeneralErrorMessage>) & {
106
+ code: number;
107
+ };
108
+ readonly PRECONDITION_REQUIRED: ((userMessage: string, debugMessage?: string, cause?: Error) => ApiException<ApiError_GeneralErrorMessage>) & {
109
+ code: number;
110
+ };
111
+ readonly TOO_MANY_REQUESTS: ((userMessage: string, debugMessage?: string, cause?: Error) => ApiException<ApiError_GeneralErrorMessage>) & {
112
+ code: number;
113
+ };
114
+ readonly REQUEST_HEADER_FIELDS_TOO_LARGE: ((userMessage: string, debugMessage?: string, cause?: Error) => ApiException<ApiError_GeneralErrorMessage>) & {
115
+ code: number;
116
+ };
117
+ readonly UNAVAILABLE_FOR_LEGAL_REASONS: ((userMessage: string, debugMessage?: string, cause?: Error) => ApiException<ApiError_GeneralErrorMessage>) & {
118
+ code: number;
119
+ };
120
+ readonly ENTITY_ALREADY_EXISTS: ((userMessage: string, debugMessage?: string, cause?: Error) => ApiException<ApiError_GeneralErrorMessage>) & {
121
+ code: number;
122
+ };
67
123
  readonly ENTITY_IS_OUTDATED: ((userMessage: string, debugMessage?: string, cause?: Error) => ApiException<ApiError_GeneralErrorMessage>) & {
68
124
  code: number;
69
125
  };
70
- readonly OPERATION_FAILED: 490;
126
+ readonly OPERATION_FAILED: ((userMessage: string, debugMessage?: string, cause?: Error) => ApiException<ApiError_GeneralErrorMessage>) & {
127
+ code: number;
128
+ };
71
129
  };
72
130
  readonly _5XX: {
73
- readonly INTERNAL_SERVER_ERROR: 500;
131
+ readonly INTERNAL_SERVER_ERROR: ((userMessage: string, debugMessage?: string, cause?: Error) => ApiException<ApiError_GeneralErrorMessage>) & {
132
+ code: number;
133
+ };
74
134
  readonly NOT_IMPLEMENTED: ((userMessage: string, debugMessage?: string, cause?: Error) => ApiException<ApiError_GeneralErrorMessage>) & {
75
135
  code: number;
76
136
  };
77
- readonly BAD_GATEWAY: 502;
78
- readonly SERVICE_UNAVAILABLE: 503;
79
- readonly GATEWAY_TIMEOUT: 504;
80
- readonly HTTP_VERSION_NOT_SUPPORTED: 505;
81
- readonly VARIANT_ALSO_NEGOTIATES: 506;
82
- readonly INSUFFICIENT_STORAGE: 507;
83
- readonly LOOP_DETECTED: 508;
84
- readonly NOT_EXTENDED: 510;
85
- readonly NETWORK_AUTHENTICATION_REQUIRED: 511;
137
+ readonly BAD_GATEWAY: ((userMessage: string, debugMessage?: string, cause?: Error) => ApiException<ApiError_GeneralErrorMessage>) & {
138
+ code: number;
139
+ };
140
+ readonly SERVICE_UNAVAILABLE: ((userMessage: string, debugMessage?: string, cause?: Error) => ApiException<ApiError_GeneralErrorMessage>) & {
141
+ code: number;
142
+ };
143
+ readonly GATEWAY_TIMEOUT: ((userMessage: string, debugMessage?: string, cause?: Error) => ApiException<ApiError_GeneralErrorMessage>) & {
144
+ code: number;
145
+ };
146
+ readonly HTTP_VERSION_NOT_SUPPORTED: ((userMessage: string, debugMessage?: string, cause?: Error) => ApiException<ApiError_GeneralErrorMessage>) & {
147
+ code: number;
148
+ };
149
+ readonly VARIANT_ALSO_NEGOTIATES: ((userMessage: string, debugMessage?: string, cause?: Error) => ApiException<ApiError_GeneralErrorMessage>) & {
150
+ code: number;
151
+ };
152
+ readonly INSUFFICIENT_STORAGE: ((userMessage: string, debugMessage?: string, cause?: Error) => ApiException<ApiError_GeneralErrorMessage>) & {
153
+ code: number;
154
+ };
155
+ readonly LOOP_DETECTED: ((userMessage: string, debugMessage?: string, cause?: Error) => ApiException<ApiError_GeneralErrorMessage>) & {
156
+ code: number;
157
+ };
158
+ readonly NOT_EXTENDED: ((userMessage: string, debugMessage?: string, cause?: Error) => ApiException<ApiError_GeneralErrorMessage>) & {
159
+ code: number;
160
+ };
161
+ readonly NETWORK_AUTHENTICATION_REQUIRED: ((userMessage: string, debugMessage?: string, cause?: Error) => ApiException<ApiError_GeneralErrorMessage>) & {
162
+ code: number;
163
+ };
86
164
  readonly DEBUG_WHO_CALLED_THIS: 555;
87
165
  readonly BAD_IMPLEMENTATION: 560;
88
166
  readonly IMPLEMENTATION_MISSION: 561;
@@ -40,51 +40,51 @@ exports.HttpCodes = {
40
40
  },
41
41
  _4XX: {
42
42
  BAD_REQUEST: createGeneralError(400),
43
- UNAUTHORIZED: 401,
44
- PAYMENT_REQUIRED: 402,
43
+ UNAUTHORIZED: createGeneralError(401),
44
+ PAYMENT_REQUIRED: createGeneralError(402),
45
45
  FORBIDDEN: createGeneralError(403),
46
- NOT_FOUND: 404,
47
- METHOD_NOT_ALLOWED: 405,
48
- NOT_ACCEPTABLE: 406,
49
- PROXY_AUTHENTICATION_REQUIRED: 407,
50
- REQUEST_TIMEOUT: 408,
51
- CONFLICT: 409,
52
- GONE: 410,
53
- LENGTH_REQUIRED: 411,
54
- PRECONDITION_FAILED: 412,
55
- PAYLOAD_TOO_LARGE: 413,
56
- URI_TOO_LONG: 414,
57
- UNSUPPORTED_MEDIA_TYPE: 415,
58
- RANGE_NOT_SATISFIABLE: 416,
59
- EXPECTATION_FAILED: 417,
60
- IM_A_TEAPOT: 418,
61
- MISDIRECTED_REQUEST: 421,
62
- UNPROCESSABLE_ENTITY: 422,
63
- LOCKED: 423,
64
- FAILED_DEPENDENCY: 424,
65
- TOO_EARLY: 425,
66
- UPGRADE_REQUIRED: 426,
67
- PRECONDITION_REQUIRED: 428,
68
- TOO_MANY_REQUESTS: 429,
69
- REQUEST_HEADER_FIELDS_TOO_LARGE: 431,
70
- UNAVAILABLE_FOR_LEGAL_REASONS: 451,
46
+ NOT_FOUND: createGeneralError(404),
47
+ METHOD_NOT_ALLOWED: createGeneralError(405),
48
+ NOT_ACCEPTABLE: createGeneralError(406),
49
+ PROXY_AUTHENTICATION_REQUIRED: createGeneralError(407),
50
+ REQUEST_TIMEOUT: createGeneralError(408),
51
+ CONFLICT: createGeneralError(409),
52
+ GONE: createGeneralError(410),
53
+ LENGTH_REQUIRED: createGeneralError(411),
54
+ PRECONDITION_FAILED: createGeneralError(412),
55
+ PAYLOAD_TOO_LARGE: createGeneralError(413),
56
+ URI_TOO_LONG: createGeneralError(414),
57
+ UNSUPPORTED_MEDIA_TYPE: createGeneralError(415),
58
+ RANGE_NOT_SATISFIABLE: createGeneralError(416),
59
+ EXPECTATION_FAILED: createGeneralError(417),
60
+ IM_A_TEAPOT: createGeneralError(418),
61
+ MISDIRECTED_REQUEST: createGeneralError(421),
62
+ UNPROCESSABLE_ENTITY: createGeneralError(422),
63
+ LOCKED: createGeneralError(423),
64
+ FAILED_DEPENDENCY: createGeneralError(424),
65
+ TOO_EARLY: createGeneralError(425),
66
+ UPGRADE_REQUIRED: createGeneralError(426),
67
+ PRECONDITION_REQUIRED: createGeneralError(428),
68
+ TOO_MANY_REQUESTS: createGeneralError(429),
69
+ REQUEST_HEADER_FIELDS_TOO_LARGE: createGeneralError(431),
70
+ UNAVAILABLE_FOR_LEGAL_REASONS: createGeneralError(451),
71
71
  //custom
72
- ENTITY_ALREADY_EXISTS: 460,
72
+ ENTITY_ALREADY_EXISTS: createGeneralError(460),
73
73
  ENTITY_IS_OUTDATED: createGeneralError(461),
74
- OPERATION_FAILED: 490,
74
+ OPERATION_FAILED: createGeneralError(490),
75
75
  },
76
76
  _5XX: {
77
- INTERNAL_SERVER_ERROR: 500,
77
+ INTERNAL_SERVER_ERROR: createGeneralError(500),
78
78
  NOT_IMPLEMENTED: createGeneralError(501),
79
- BAD_GATEWAY: 502,
80
- SERVICE_UNAVAILABLE: 503,
81
- GATEWAY_TIMEOUT: 504,
82
- HTTP_VERSION_NOT_SUPPORTED: 505,
83
- VARIANT_ALSO_NEGOTIATES: 506,
84
- INSUFFICIENT_STORAGE: 507,
85
- LOOP_DETECTED: 508,
86
- NOT_EXTENDED: 510,
87
- NETWORK_AUTHENTICATION_REQUIRED: 511,
79
+ BAD_GATEWAY: createGeneralError(502),
80
+ SERVICE_UNAVAILABLE: createGeneralError(503),
81
+ GATEWAY_TIMEOUT: createGeneralError(504),
82
+ HTTP_VERSION_NOT_SUPPORTED: createGeneralError(505),
83
+ VARIANT_ALSO_NEGOTIATES: createGeneralError(506),
84
+ INSUFFICIENT_STORAGE: createGeneralError(507),
85
+ LOOP_DETECTED: createGeneralError(508),
86
+ NOT_EXTENDED: createGeneralError(510),
87
+ NETWORK_AUTHENTICATION_REQUIRED: createGeneralError(511),
88
88
  //custom
89
89
  DEBUG_WHO_CALLED_THIS: 555,
90
90
  BAD_IMPLEMENTATION: 560,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nu-art/ts-common",
3
- "version": "0.202.91",
3
+ "version": "0.202.93",
4
4
  "description": "js and ts infra",
5
5
  "keywords": [
6
6
  "TacB0sS",
@@ -9,9 +9,7 @@ function dbObjectToId(i) {
9
9
  }
10
10
  exports.dbObjectToId = dbObjectToId;
11
11
  function removeDBObjectKeys(instance) {
12
- const _instance = (0, object_tools_1.deepClone)(instance);
13
- exports.KeysOfDB_Object.forEach(key => delete _instance[key]);
14
- return _instance;
12
+ return deleteKeysObject(instance, exports.KeysOfDB_Object);
15
13
  }
16
14
  exports.removeDBObjectKeys = removeDBObjectKeys;
17
15
  function deleteKeysObject(instance, keysToRemove) {
@@ -9,4 +9,12 @@
9
9
  * @param timeout The debounce timer
10
10
  * @param defaultCallback The default timer for the default event to be fired.
11
11
  */
12
- export declare const debounce: <Args extends any[]>(func: (...params: Args) => void, timeout?: number, defaultCallback?: number) => (...args: Args) => void;
12
+ export declare const debounce: <Args extends any[]>(func: (...params: Args) => any | Promise<any>, timeout?: number, defaultCallback?: number) => (...args: Args) => void;
13
+ export type AwaitedDebounceInstance<Args extends any[], ReturnValue> = (...args: Args) => Promise<ReturnValue | undefined>;
14
+ type DebounceParams<Args extends any[], ReturnValue = any> = {
15
+ func: (...params: Args) => Promise<ReturnValue>;
16
+ timeout?: number;
17
+ fallbackTimeout?: number;
18
+ };
19
+ export declare const awaitedDebounce: <Args extends any[], ReturnValue = any>(params: DebounceParams<Args, ReturnValue>) => AwaitedDebounceInstance<Args, ReturnValue>;
20
+ export {};
package/utils/ui-tools.js CHANGED
@@ -1,6 +1,15 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.debounce = void 0;
12
+ exports.awaitedDebounce = exports.debounce = void 0;
4
13
  /**
5
14
  *
6
15
  * Creates a debounce function with a debounce and default timers
@@ -31,3 +40,33 @@ const debounce = (func, timeout = 500, defaultCallback = 1000) => {
31
40
  };
32
41
  };
33
42
  exports.debounce = debounce;
43
+ const awaitedDebounce = (params) => {
44
+ const timers = {};
45
+ const _clearTimeout = (timer) => {
46
+ clearTimeout(timers[timer]);
47
+ delete timers[timer];
48
+ };
49
+ const _clearTimeouts = () => {
50
+ _clearTimeout('timer');
51
+ _clearTimeout('fallbackTimer');
52
+ };
53
+ return (...args) => {
54
+ return new Promise((resolve) => {
55
+ var _a, _b;
56
+ const timeout = (_a = params.timeout) !== null && _a !== void 0 ? _a : 500;
57
+ _clearTimeout('timer');
58
+ timers.timer = setTimeout(() => __awaiter(void 0, void 0, void 0, function* () {
59
+ _clearTimeouts();
60
+ resolve(yield params.func(...args));
61
+ }), timeout);
62
+ if (!timers.fallbackTimer) {
63
+ const fallbackTimeout = (_b = params.fallbackTimeout) !== null && _b !== void 0 ? _b : 1000;
64
+ timers.fallbackTimer = setTimeout(() => __awaiter(void 0, void 0, void 0, function* () {
65
+ _clearTimeouts();
66
+ resolve(yield params.func(...args));
67
+ }), fallbackTimeout);
68
+ }
69
+ });
70
+ };
71
+ };
72
+ exports.awaitedDebounce = awaitedDebounce;