@freshpointcz/fresh-core 0.0.19 → 0.0.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/dist/index.d.mts +431 -164
- package/dist/index.d.ts +431 -164
- package/dist/index.js +936 -490
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +866 -465
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,117 +1,39 @@
|
|
|
1
|
+
import { FindOperator, BaseEntity, FindOptionsOrder, ColumnOptions, Repository, EntityTarget, EntityManager, ObjectLiteral, EntitySubscriberInterface, InsertEvent, UpdateEvent, SoftRemoveEvent, TransactionCommitEvent, DataSourceOptions } from 'typeorm';
|
|
1
2
|
import dayjs, { Dayjs } from 'dayjs';
|
|
2
|
-
import { BaseEntity, ColumnOptions, Repository, EntityTarget, EntityManager, ObjectLiteral, EntitySubscriberInterface, InsertEvent, UpdateEvent, SoftRemoveEvent, TransactionCommitEvent, DataSourceOptions } from 'typeorm';
|
|
3
3
|
import { Job } from 'node-schedule';
|
|
4
4
|
import * as _eslint_core from '@eslint/core';
|
|
5
5
|
import * as typescript_eslint_dist_compatibility_types from 'typescript-eslint/dist/compatibility-types';
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
7
|
+
declare const AMOUNT_UNIT: {
|
|
8
|
+
readonly 1: {
|
|
9
|
+
readonly symbol: "g";
|
|
10
|
+
readonly translations: {
|
|
11
|
+
readonly en: "gram";
|
|
12
|
+
readonly cs: "gram";
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
readonly 2: {
|
|
16
|
+
readonly symbol: "kg";
|
|
17
|
+
readonly translations: {
|
|
18
|
+
readonly en: "kilogram";
|
|
19
|
+
readonly cs: "kilogram";
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
readonly 3: {
|
|
23
|
+
readonly symbol: "ml";
|
|
24
|
+
readonly translations: {
|
|
25
|
+
readonly en: "milliliter";
|
|
26
|
+
readonly cs: "mililitr";
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
readonly 4: {
|
|
30
|
+
readonly symbol: "l";
|
|
31
|
+
readonly translations: {
|
|
32
|
+
readonly en: "liter";
|
|
33
|
+
readonly cs: "litr";
|
|
34
|
+
};
|
|
35
|
+
};
|
|
35
36
|
};
|
|
36
|
-
/**
|
|
37
|
-
* Deferred promise is like "fake" which is used to manually resolve/reject later on with different promise
|
|
38
|
-
* With resolve and reject outside for easier change of promise
|
|
39
|
-
* is used as placeholder untill real promise is assigned
|
|
40
|
-
*/
|
|
41
|
-
declare function createDeferred<T>(): Deferred<T>;
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Experimental class to maintain just one promise for some process flow.
|
|
45
|
-
* Currently is in singleton design, so can be used only in one proces. (currently: all-product-availability-per-day)
|
|
46
|
-
*/
|
|
47
|
-
declare class SinglePromiseWaiter<T = any> {
|
|
48
|
-
private static _instance;
|
|
49
|
-
static getInstance<T = any>(): SinglePromiseWaiter<any>;
|
|
50
|
-
private _promise;
|
|
51
|
-
get promise(): Promise<T> | null;
|
|
52
|
-
set promise(promise: Promise<T> | null);
|
|
53
|
-
get hasPromise(): boolean;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
declare function isValidCron(expr: string): boolean;
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Abstract base class implementing a per-subclass Singleton pattern.
|
|
60
|
-
*
|
|
61
|
-
* Each subclass of `Singleton` can have exactly one instance.
|
|
62
|
-
* Instantiation is guarded at runtime: calling `new` multiple times
|
|
63
|
-
* will always return the first created instance for that subclass.
|
|
64
|
-
*
|
|
65
|
-
* Instances are stored internally in a static map keyed by constructor
|
|
66
|
-
* function, allowing independent singleton instances per subclass.
|
|
67
|
-
*
|
|
68
|
-
* ⚠️ Important:
|
|
69
|
-
* - Subclasses MUST NOT override the constructor unless they fully
|
|
70
|
-
* understand the consequences.
|
|
71
|
-
* - Initialization logic must be placed in {@link onInit}, not the constructor.
|
|
72
|
-
* - The constructor may return an existing instance, which is legal in JS
|
|
73
|
-
* but mildly unsettling.
|
|
74
|
-
*/
|
|
75
|
-
declare abstract class Singleton {
|
|
76
|
-
/**
|
|
77
|
-
* Internal registry of singleton instances.
|
|
78
|
-
* One instance per subclass constructor.
|
|
79
|
-
*/
|
|
80
|
-
private static instances;
|
|
81
|
-
/**
|
|
82
|
-
* Creates or returns the singleton instance for the subclass.
|
|
83
|
-
*
|
|
84
|
-
* If an instance already exists for the subclass, that instance is
|
|
85
|
-
* returned instead of creating a new one.
|
|
86
|
-
*
|
|
87
|
-
* @param callOnInit - Whether to call {@link onInit} for a newly
|
|
88
|
-
* created instance. Ignored if the instance already exists.
|
|
89
|
-
*/
|
|
90
|
-
constructor(callOnInit?: boolean);
|
|
91
|
-
/**
|
|
92
|
-
* Retrieves the singleton instance for the calling subclass.
|
|
93
|
-
*
|
|
94
|
-
* If no instance exists, a new one is created using the provided
|
|
95
|
-
* constructor arguments.
|
|
96
|
-
*
|
|
97
|
-
* Intended to be used by subclasses as a protected factory method.
|
|
98
|
-
*
|
|
99
|
-
* @typeParam T - The concrete subclass type.
|
|
100
|
-
* @param args - Arguments forwarded to the subclass constructor.
|
|
101
|
-
* @returns The singleton instance of the subclass.
|
|
102
|
-
*/
|
|
103
|
-
protected static getInstance<T>(this: new (...args: any[]) => T, ...args: ConstructorParameters<any>): T;
|
|
104
|
-
/**
|
|
105
|
-
* Lifecycle hook called once when the singleton instance is first created.
|
|
106
|
-
*
|
|
107
|
-
* Subclasses must implement this method instead of relying on the
|
|
108
|
-
* constructor for initialization logic.
|
|
109
|
-
*
|
|
110
|
-
* This method is guaranteed to be called at most once per subclass
|
|
111
|
-
* instance.
|
|
112
|
-
*/
|
|
113
|
-
protected abstract onInit(): void | Promise<void>;
|
|
114
|
-
}
|
|
115
37
|
|
|
116
38
|
type Status = "ok" | "error" | "not-authorized" | "not-authenticated" | "internal-server-error" | "validation-error";
|
|
117
39
|
|
|
@@ -132,6 +54,36 @@ declare class StatusDto {
|
|
|
132
54
|
constructor(status: Status, details?: string, timestamp?: string);
|
|
133
55
|
}
|
|
134
56
|
|
|
57
|
+
/**
|
|
58
|
+
* Converts optional date range strings into a TypeORM `FindOperator<Date>`.
|
|
59
|
+
*
|
|
60
|
+
* - Both provided → `Between(from, to)`
|
|
61
|
+
* - Only `from` → `MoreThanOrEqual(from)`
|
|
62
|
+
* - Only `to` → `LessThanOrEqual(to)`
|
|
63
|
+
* - Neither → `undefined`
|
|
64
|
+
*
|
|
65
|
+
* @param from - ISO date string for the lower bound (inclusive).
|
|
66
|
+
* @param to - ISO date string for the upper bound (inclusive).
|
|
67
|
+
* @returns A TypeORM date range operator, or `undefined` if no bounds are provided.
|
|
68
|
+
*/
|
|
69
|
+
declare function buildDateRange(from?: string, to?: string): FindOperator<Date> | undefined;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Converts optional sort query params into a TypeORM `FindOptionsOrder` object.
|
|
73
|
+
*
|
|
74
|
+
* Defaults to `ASC` if `sortBy` is provided but `sortOrder` is omitted.
|
|
75
|
+
* Returns `undefined` if no sort field is specified, leaving the order to TypeORM's default.
|
|
76
|
+
*
|
|
77
|
+
* @param sortBy - Entity field to sort by.
|
|
78
|
+
* @param sortOrder - Sort direction. Defaults to `"ASC"`.
|
|
79
|
+
* @returns A `FindOptionsOrder` object, or `undefined` if `sortBy` is not provided.
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* buildOrder("createdAt", "DESC") // → { createdAt: "DESC" }
|
|
83
|
+
* buildOrder() // → undefined
|
|
84
|
+
*/
|
|
85
|
+
declare function buildOrder<TEntity extends BaseEntity, TSortableFields extends keyof TEntity>(sortBy?: TSortableFields, sortOrder?: "ASC" | "DESC"): FindOptionsOrder<TEntity> | undefined;
|
|
86
|
+
|
|
135
87
|
/**
|
|
136
88
|
* Pagination parameters used to describe the current page slice of a query.
|
|
137
89
|
*
|
|
@@ -200,6 +152,21 @@ declare function getPaginationParams(params?: Partial<PaginationParams>): Pagina
|
|
|
200
152
|
*/
|
|
201
153
|
declare const DEFAULT_PAGINATION_PARAMS: PaginationParams;
|
|
202
154
|
|
|
155
|
+
/**
|
|
156
|
+
* Converts optional pagination query params into a `PaginationParams` object
|
|
157
|
+
* with a pre-calculated `skip` offset for TypeORM queries.
|
|
158
|
+
*
|
|
159
|
+
* Defaults to page `1` and limit `1000` if only one side is provided.
|
|
160
|
+
* Returns `undefined` if neither param is present, allowing the caller
|
|
161
|
+
* to opt out of pagination entirely.
|
|
162
|
+
*
|
|
163
|
+
* @param page - 1-based page number. Must be ≥ 1 if provided.
|
|
164
|
+
* @param limit - Maximum number of records per page. Must be ≥ 0 if provided.
|
|
165
|
+
* @returns Resolved `PaginationParams` with `skip`, or `undefined` if both params are absent.
|
|
166
|
+
* @throws {ApiError} `400 BAD_REQUEST` if `page < 1` or `limit < 0`.
|
|
167
|
+
*/
|
|
168
|
+
declare function buildPagination(page?: number, limit?: number): PaginationParams | undefined;
|
|
169
|
+
|
|
203
170
|
/**
|
|
204
171
|
* Converts {@link PaginationParams} into the `take`/`skip` shape expected by
|
|
205
172
|
* TypeORM's `find`, `findAndCount`, and `findOne` options.
|
|
@@ -362,36 +329,88 @@ interface PaginatedList<T> {
|
|
|
362
329
|
*/
|
|
363
330
|
declare function listAll<T>(fetchPage: (pagination: PaginationParams) => Promise<PaginatedList<T>>, batchSize?: number): Promise<T[]>;
|
|
364
331
|
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
332
|
+
/**
|
|
333
|
+
* Abstract base class implementing a per-subclass Singleton pattern.
|
|
334
|
+
*
|
|
335
|
+
* Each subclass of `Singleton` can have exactly one instance.
|
|
336
|
+
* Instantiation is guarded at runtime: calling `new` multiple times
|
|
337
|
+
* will always return the first created instance for that subclass.
|
|
338
|
+
*
|
|
339
|
+
* Instances are stored internally in a static map keyed by constructor
|
|
340
|
+
* function, allowing independent singleton instances per subclass.
|
|
341
|
+
*
|
|
342
|
+
* ⚠️ Important:
|
|
343
|
+
* - Subclasses MUST NOT override the constructor unless they fully
|
|
344
|
+
* understand the consequences.
|
|
345
|
+
* - Initialization logic must be placed in {@link onInit}, not the constructor.
|
|
346
|
+
* - The constructor may return an existing instance, which is legal in JS
|
|
347
|
+
* but mildly unsettling.
|
|
348
|
+
*/
|
|
349
|
+
declare abstract class Singleton {
|
|
350
|
+
/**
|
|
351
|
+
* Internal registry of singleton instances.
|
|
352
|
+
* One instance per subclass constructor.
|
|
353
|
+
*/
|
|
354
|
+
private static instances;
|
|
355
|
+
/**
|
|
356
|
+
* Creates or returns the singleton instance for the subclass.
|
|
357
|
+
*
|
|
358
|
+
* If an instance already exists for the subclass, that instance is
|
|
359
|
+
* returned instead of creating a new one.
|
|
360
|
+
*
|
|
361
|
+
* @param callOnInit - Whether to call {@link onInit} for a newly
|
|
362
|
+
* created instance. Ignored if the instance already exists.
|
|
363
|
+
*/
|
|
364
|
+
constructor(callOnInit?: boolean);
|
|
365
|
+
/**
|
|
366
|
+
* Retrieves the singleton instance for the calling subclass.
|
|
367
|
+
*
|
|
368
|
+
* If no instance exists, a new one is created using the provided
|
|
369
|
+
* constructor arguments.
|
|
370
|
+
*
|
|
371
|
+
* Intended to be used by subclasses as a protected factory method.
|
|
372
|
+
*
|
|
373
|
+
* @typeParam T - The concrete subclass type.
|
|
374
|
+
* @param args - Arguments forwarded to the subclass constructor.
|
|
375
|
+
* @returns The singleton instance of the subclass.
|
|
376
|
+
*/
|
|
377
|
+
protected static getInstance<T>(this: new (...args: any[]) => T, ...args: ConstructorParameters<any>): T;
|
|
378
|
+
/**
|
|
379
|
+
* Lifecycle hook called once when the singleton instance is first created.
|
|
380
|
+
*
|
|
381
|
+
* Subclasses must implement this method instead of relying on the
|
|
382
|
+
* constructor for initialization logic.
|
|
383
|
+
*
|
|
384
|
+
* This method is guaranteed to be called at most once per subclass
|
|
385
|
+
* instance.
|
|
386
|
+
*/
|
|
387
|
+
protected abstract onInit(): void | Promise<void>;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
type Deferred<T> = {
|
|
391
|
+
promise: Promise<T>;
|
|
392
|
+
resolve: (value: T) => void;
|
|
393
|
+
reject: (err: any) => void;
|
|
394
394
|
};
|
|
395
|
+
/**
|
|
396
|
+
* Deferred promise is like "fake" which is used to manually resolve/reject later on with different promise
|
|
397
|
+
* With resolve and reject outside for easier change of promise
|
|
398
|
+
* is used as placeholder untill real promise is assigned
|
|
399
|
+
*/
|
|
400
|
+
declare function createDeferred<T>(): Deferred<T>;
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* Experimental class to maintain just one promise for some process flow.
|
|
404
|
+
* Currently is in singleton design, so can be used only in one proces. (currently: all-product-availability-per-day)
|
|
405
|
+
*/
|
|
406
|
+
declare class SinglePromiseWaiter<T = any> {
|
|
407
|
+
private static _instance;
|
|
408
|
+
static getInstance<T = any>(): SinglePromiseWaiter<any>;
|
|
409
|
+
private _promise;
|
|
410
|
+
get promise(): Promise<T> | null;
|
|
411
|
+
set promise(promise: Promise<T> | null);
|
|
412
|
+
get hasPromise(): boolean;
|
|
413
|
+
}
|
|
395
414
|
|
|
396
415
|
/**
|
|
397
416
|
* Default Entity with needed columns for every basic entity `id`, `uuid`, `created_at`, `updated_at` and `deleted_at`;
|
|
@@ -864,6 +883,29 @@ declare const TO_BINARY_FLAG: (v: number | boolean | null | undefined) => Binary
|
|
|
864
883
|
*/
|
|
865
884
|
declare function runWithConcurrency<T>(items: T[], concurrency: number, worker: (item: T) => Promise<void>): Promise<void>;
|
|
866
885
|
|
|
886
|
+
/**
|
|
887
|
+
* Resolves a path parameter ID string to either a numeric ID or a UUID (any version).
|
|
888
|
+
*
|
|
889
|
+
* tsoa always provides path parameters as strings, so this utility determines
|
|
890
|
+
* the intended type by checking whether the value is purely numeric.
|
|
891
|
+
*
|
|
892
|
+
* @param id - Raw path parameter string
|
|
893
|
+
* @returns Parsed `number` if the value is numeric, otherwise the original `string`.
|
|
894
|
+
*
|
|
895
|
+
* @example
|
|
896
|
+
* resolvePathParameterId("42") // → 42
|
|
897
|
+
* resolvePathParameterId("550e8400-e29b-41d4-a716-446655440000") // → "550e8400-..."
|
|
898
|
+
*
|
|
899
|
+
* // Typical tsoa usage:
|
|
900
|
+
* \@Get("{id}")
|
|
901
|
+
* public async getUserById(\@Request() req: ExRequest, \@Path() id: string) {
|
|
902
|
+
* const userId = resolvePathParameterId(id); // number | string
|
|
903
|
+
* }
|
|
904
|
+
*/
|
|
905
|
+
declare function resolvePathParameterId(id: string): string | number;
|
|
906
|
+
|
|
907
|
+
declare function isValidCron(expr: string): boolean;
|
|
908
|
+
|
|
867
909
|
type TransformMap<TIn, TOut, K extends keyof TIn & keyof TOut> = Partial<{
|
|
868
910
|
[P in K]: (val: TIn[P]) => TOut[P];
|
|
869
911
|
}>;
|
|
@@ -876,34 +918,28 @@ type TransformMap<TIn, TOut, K extends keyof TIn & keyof TOut> = Partial<{
|
|
|
876
918
|
*/
|
|
877
919
|
declare function buildPatch<TOut extends Record<string, any>, TIn extends Record<string, any>, K extends keyof TIn & keyof TOut = keyof TIn & keyof TOut>(data: Partial<TIn>, keys: readonly K[], transforms?: TransformMap<TIn, TOut, K>): Partial<Pick<TOut, K>>;
|
|
878
920
|
|
|
879
|
-
type Maybe<T> = T | null;
|
|
880
921
|
/**
|
|
881
|
-
*
|
|
882
|
-
*
|
|
883
|
-
* WARNING:
|
|
884
|
-
* `undefined` is NOT accepted by this function.
|
|
885
|
-
* If you need `undefined` support, it must be handled
|
|
886
|
-
* before calling this guard or explicitly allowed elsewhere.
|
|
887
|
-
*
|
|
888
|
-
* @typeParam T - The underlying non-nullable type
|
|
889
|
-
* @param v - Value to validate
|
|
890
|
-
* @param inner - Typeguard function for the underlying type `T`
|
|
891
|
-
*
|
|
892
|
-
* @returns `true` if the value is `null` or satisfies the inner typeguard
|
|
922
|
+
* Static DateUtils class
|
|
893
923
|
*/
|
|
894
|
-
declare
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
924
|
+
declare class DateUtils {
|
|
925
|
+
/** Holidays 2025-2030 as YYYY-MM-DD strings */
|
|
926
|
+
static HOLIDAYS_STR: readonly string[];
|
|
927
|
+
/** Holidays 2025-2030 as UTC timestamps */
|
|
928
|
+
static HOLIDAYS: readonly number[];
|
|
929
|
+
static fromISOtoSQLtimestamp(ts?: string): string;
|
|
930
|
+
static toSQLtimestamp(ts: Dayjs): string;
|
|
931
|
+
static fromSQLtimestamp(mysqlDate: string): Dayjs;
|
|
932
|
+
static getSqlTimestampFromNowCzech(): string;
|
|
933
|
+
static fromISO(isoDate: string): Dayjs;
|
|
934
|
+
static getDate(ts: string): dayjs.Dayjs;
|
|
935
|
+
static getNow(): Dayjs;
|
|
936
|
+
static getNowCzech(): Dayjs;
|
|
937
|
+
static clone(ts: Dayjs): Dayjs;
|
|
938
|
+
static getLastSunday(weeksOffset?: number): Dayjs;
|
|
939
|
+
static dayInWeek(ts?: Dayjs): 1 | 2 | 3 | 4 | 5 | 6 | 7;
|
|
940
|
+
static isWorkdayDay(ts: Dayjs): boolean;
|
|
941
|
+
static getDiffInMinutesWithNow(inputTime: Dayjs): number;
|
|
942
|
+
static isInLastDays(numOfDays: number, timestampInput: string | Dayjs): boolean;
|
|
907
943
|
}
|
|
908
944
|
|
|
909
945
|
/**
|
|
@@ -996,8 +1032,26 @@ declare abstract class FreshJob<T = void> extends Singleton {
|
|
|
996
1032
|
abstract invoke(): T | Promise<T>;
|
|
997
1033
|
}
|
|
998
1034
|
|
|
1035
|
+
type Maybe<T> = T | null;
|
|
1036
|
+
/**
|
|
1037
|
+
* Validates a value that may be `null` or given type
|
|
1038
|
+
*
|
|
1039
|
+
* WARNING:
|
|
1040
|
+
* `undefined` is NOT accepted by this function.
|
|
1041
|
+
* If you need `undefined` support, it must be handled
|
|
1042
|
+
* before calling this guard or explicitly allowed elsewhere.
|
|
1043
|
+
*
|
|
1044
|
+
* @typeParam T - The underlying non-nullable type
|
|
1045
|
+
* @param v - Value to validate
|
|
1046
|
+
* @param inner - Typeguard function for the underlying type `T`
|
|
1047
|
+
*
|
|
1048
|
+
* @returns `true` if the value is `null` or satisfies the inner typeguard
|
|
1049
|
+
*/
|
|
1050
|
+
declare function isMaybe<T>(v: unknown, inner: (x: unknown) => x is T): v is Maybe<T>;
|
|
1051
|
+
|
|
999
1052
|
type CardNumber = `${number}${number}${number}${number}`;
|
|
1000
1053
|
|
|
1054
|
+
/** @deprecated use {@link FreshError} instead */
|
|
1001
1055
|
declare class ApiError extends Error {
|
|
1002
1056
|
private _statusCode;
|
|
1003
1057
|
get statusCode(): number;
|
|
@@ -1018,6 +1072,219 @@ declare class BusinessWarning extends Error {
|
|
|
1018
1072
|
constructor(code: string, message: string);
|
|
1019
1073
|
}
|
|
1020
1074
|
|
|
1075
|
+
/**
|
|
1076
|
+
* Options for {@link FreshError} and its subclasses.
|
|
1077
|
+
*/
|
|
1078
|
+
interface FreshErrorOptions {
|
|
1079
|
+
/**
|
|
1080
|
+
* The original error that caused this one.
|
|
1081
|
+
* Preserved for error chaining and accessible via `error.cause`.
|
|
1082
|
+
*/
|
|
1083
|
+
cause?: unknown;
|
|
1084
|
+
}
|
|
1085
|
+
/**
|
|
1086
|
+
* Base class for all application HTTP errors.
|
|
1087
|
+
*
|
|
1088
|
+
* Extend this class to create typed, status-specific errors with a hardcoded
|
|
1089
|
+
* HTTP status code and status string. Direct instantiation is allowed but
|
|
1090
|
+
* subclasses are preferred for consistent error identity.
|
|
1091
|
+
*
|
|
1092
|
+
* `error.name` is automatically set to the subclass name, so stack traces
|
|
1093
|
+
* and logs show `UnauthorizedError` instead of the generic `Error`.
|
|
1094
|
+
*
|
|
1095
|
+
* @example
|
|
1096
|
+
* // Without cause
|
|
1097
|
+
* throw new FreshError(HttpStatus.NOT_FOUND, "error", "User not found");
|
|
1098
|
+
*
|
|
1099
|
+
* // With cause — preserves the original error for logging/debugging
|
|
1100
|
+
* try {
|
|
1101
|
+
* await db.findUser(id);
|
|
1102
|
+
* } catch (err) {
|
|
1103
|
+
* throw new FreshError(HttpStatus.INTERNAL_SERVER_ERROR, "internal-server-error", "DB query failed", { cause: err });
|
|
1104
|
+
* }
|
|
1105
|
+
*/
|
|
1106
|
+
declare class FreshError extends Error {
|
|
1107
|
+
/** HTTP status code sent in the response. */
|
|
1108
|
+
readonly statusCode: number;
|
|
1109
|
+
/** Structured response body describing the error. */
|
|
1110
|
+
readonly statusDto: StatusDto;
|
|
1111
|
+
constructor(statusCode: HttpStatus, status: Status, detail?: string, options?: FreshErrorOptions);
|
|
1112
|
+
}
|
|
1113
|
+
|
|
1114
|
+
/** 400 — The request is malformed or contains invalid parameters. */
|
|
1115
|
+
declare class BadRequestError extends FreshError {
|
|
1116
|
+
constructor(detail?: string, options?: FreshErrorOptions);
|
|
1117
|
+
}
|
|
1118
|
+
/** 401 — Authentication is required or the provided credentials are invalid. */
|
|
1119
|
+
declare class UnauthorizedError extends FreshError {
|
|
1120
|
+
constructor(detail?: string, options?: FreshErrorOptions);
|
|
1121
|
+
}
|
|
1122
|
+
/** 402 — Payment is required to access the requested resource. */
|
|
1123
|
+
declare class PaymentRequiredError extends FreshError {
|
|
1124
|
+
constructor(detail?: string, options?: FreshErrorOptions);
|
|
1125
|
+
}
|
|
1126
|
+
/** 403 — The caller is authenticated but lacks permission to access the resource. */
|
|
1127
|
+
declare class ForbiddenError extends FreshError {
|
|
1128
|
+
constructor(detail?: string, options?: FreshErrorOptions);
|
|
1129
|
+
}
|
|
1130
|
+
/** 404 — The requested resource does not exist. */
|
|
1131
|
+
declare class NotFoundError extends FreshError {
|
|
1132
|
+
constructor(detail?: string, options?: FreshErrorOptions);
|
|
1133
|
+
}
|
|
1134
|
+
/** 405 — The HTTP method is not supported for this endpoint. */
|
|
1135
|
+
declare class MethodNotAllowedError extends FreshError {
|
|
1136
|
+
constructor(detail?: string, options?: FreshErrorOptions);
|
|
1137
|
+
}
|
|
1138
|
+
/** 406 — The server cannot produce a response matching the client's `Accept` headers. */
|
|
1139
|
+
declare class NotAcceptableError extends FreshError {
|
|
1140
|
+
constructor(detail?: string, options?: FreshErrorOptions);
|
|
1141
|
+
}
|
|
1142
|
+
/** 407 — Authentication with the proxy is required before the request can proceed. */
|
|
1143
|
+
declare class ProxyAuthenticationRequiredError extends FreshError {
|
|
1144
|
+
constructor(detail?: string, options?: FreshErrorOptions);
|
|
1145
|
+
}
|
|
1146
|
+
/** 408 — The server timed out waiting for the client to complete the request. */
|
|
1147
|
+
declare class RequestTimeoutError extends FreshError {
|
|
1148
|
+
constructor(detail?: string, options?: FreshErrorOptions);
|
|
1149
|
+
}
|
|
1150
|
+
/** 409 — The request conflicts with the current state of the resource. */
|
|
1151
|
+
declare class ConflictError extends FreshError {
|
|
1152
|
+
constructor(detail?: string, options?: FreshErrorOptions);
|
|
1153
|
+
}
|
|
1154
|
+
/** 410 — The resource has been permanently removed and will not return. */
|
|
1155
|
+
declare class GoneError extends FreshError {
|
|
1156
|
+
constructor(detail?: string, options?: FreshErrorOptions);
|
|
1157
|
+
}
|
|
1158
|
+
/** 411 — The request must include a `Content-Length` header. */
|
|
1159
|
+
declare class LengthRequiredError extends FreshError {
|
|
1160
|
+
constructor(detail?: string, options?: FreshErrorOptions);
|
|
1161
|
+
}
|
|
1162
|
+
/** 412 — A precondition in the request headers was not met. */
|
|
1163
|
+
declare class PreconditionFailedError extends FreshError {
|
|
1164
|
+
constructor(detail?: string, options?: FreshErrorOptions);
|
|
1165
|
+
}
|
|
1166
|
+
/** 413 — The request body exceeds the server's size limit. */
|
|
1167
|
+
declare class PayloadTooLargeError extends FreshError {
|
|
1168
|
+
constructor(detail?: string, options?: FreshErrorOptions);
|
|
1169
|
+
}
|
|
1170
|
+
/** 414 — The request URI is longer than the server is willing to process. */
|
|
1171
|
+
declare class UriTooLongError extends FreshError {
|
|
1172
|
+
constructor(detail?: string, options?: FreshErrorOptions);
|
|
1173
|
+
}
|
|
1174
|
+
/** 415 — The request's `Content-Type` is not supported by the server. */
|
|
1175
|
+
declare class UnsupportedMediaTypeError extends FreshError {
|
|
1176
|
+
constructor(detail?: string, options?: FreshErrorOptions);
|
|
1177
|
+
}
|
|
1178
|
+
/** 416 — The `Range` header in the request cannot be satisfied by the resource. */
|
|
1179
|
+
declare class RangeNotSatisfiableError extends FreshError {
|
|
1180
|
+
constructor(detail?: string, options?: FreshErrorOptions);
|
|
1181
|
+
}
|
|
1182
|
+
/** 417 — The expectation in the `Expect` request header could not be met. */
|
|
1183
|
+
declare class ExpectationFailedError extends FreshError {
|
|
1184
|
+
constructor(detail?: string, options?: FreshErrorOptions);
|
|
1185
|
+
}
|
|
1186
|
+
/** 418 — The server refuses to brew coffee because it is, permanently, a teapot. */
|
|
1187
|
+
declare class ImATeapotError extends FreshError {
|
|
1188
|
+
constructor(detail?: string, options?: FreshErrorOptions);
|
|
1189
|
+
}
|
|
1190
|
+
/** 421 — The request was directed at a server that cannot produce a response. */
|
|
1191
|
+
declare class MisdirectedRequestError extends FreshError {
|
|
1192
|
+
constructor(detail?: string, options?: FreshErrorOptions);
|
|
1193
|
+
}
|
|
1194
|
+
/** 422 — The request is well-formed but contains semantic errors. */
|
|
1195
|
+
declare class UnprocessableEntityError extends FreshError {
|
|
1196
|
+
constructor(detail?: string, options?: FreshErrorOptions);
|
|
1197
|
+
}
|
|
1198
|
+
/** 423 — The resource is locked and cannot be accessed. */
|
|
1199
|
+
declare class LockedError extends FreshError {
|
|
1200
|
+
constructor(detail?: string, options?: FreshErrorOptions);
|
|
1201
|
+
}
|
|
1202
|
+
/** 424 — The request failed because a dependency it relies on also failed. */
|
|
1203
|
+
declare class FailedDependencyError extends FreshError {
|
|
1204
|
+
constructor(detail?: string, options?: FreshErrorOptions);
|
|
1205
|
+
}
|
|
1206
|
+
/** 425 — The server is unwilling to process a request that may be replayed. */
|
|
1207
|
+
declare class TooEarlyError extends FreshError {
|
|
1208
|
+
constructor(detail?: string, options?: FreshErrorOptions);
|
|
1209
|
+
}
|
|
1210
|
+
/** 426 — The client must switch to a different protocol to proceed. */
|
|
1211
|
+
declare class UpgradeRequiredError extends FreshError {
|
|
1212
|
+
constructor(detail?: string, options?: FreshErrorOptions);
|
|
1213
|
+
}
|
|
1214
|
+
/** 428 — The request must be conditional (e.g. missing `If-Match` header). */
|
|
1215
|
+
declare class PreconditionRequiredError extends FreshError {
|
|
1216
|
+
constructor(detail?: string, options?: FreshErrorOptions);
|
|
1217
|
+
}
|
|
1218
|
+
/** 429 — The client has sent too many requests in a given time window. */
|
|
1219
|
+
declare class TooManyRequestsError extends FreshError {
|
|
1220
|
+
constructor(detail?: string, options?: FreshErrorOptions);
|
|
1221
|
+
}
|
|
1222
|
+
/** 431 — The request headers are too large for the server to process. */
|
|
1223
|
+
declare class RequestHeaderFieldsTooLargeError extends FreshError {
|
|
1224
|
+
constructor(detail?: string, options?: FreshErrorOptions);
|
|
1225
|
+
}
|
|
1226
|
+
/** 451 — The resource is unavailable due to legal restrictions. */
|
|
1227
|
+
declare class UnavailableForLegalReasonsError extends FreshError {
|
|
1228
|
+
constructor(detail?: string, options?: FreshErrorOptions);
|
|
1229
|
+
}
|
|
1230
|
+
/** 500 — The server encountered an unexpected condition. */
|
|
1231
|
+
declare class InternalServerError extends FreshError {
|
|
1232
|
+
constructor(detail?: string, options?: FreshErrorOptions);
|
|
1233
|
+
}
|
|
1234
|
+
/** 501 — The server does not support the functionality required to fulfil the request. */
|
|
1235
|
+
declare class NotImplementedError extends FreshError {
|
|
1236
|
+
constructor(detail?: string, options?: FreshErrorOptions);
|
|
1237
|
+
}
|
|
1238
|
+
/** 502 — The upstream server returned an invalid response. */
|
|
1239
|
+
declare class BadGatewayError extends FreshError {
|
|
1240
|
+
constructor(detail?: string, options?: FreshErrorOptions);
|
|
1241
|
+
}
|
|
1242
|
+
/** 503 — The server is temporarily unavailable, usually due to maintenance or overload. */
|
|
1243
|
+
declare class ServiceUnavailableError extends FreshError {
|
|
1244
|
+
constructor(detail?: string, options?: FreshErrorOptions);
|
|
1245
|
+
}
|
|
1246
|
+
/** 504 — The upstream server did not respond in time. */
|
|
1247
|
+
declare class GatewayTimeoutError extends FreshError {
|
|
1248
|
+
constructor(detail?: string, options?: FreshErrorOptions);
|
|
1249
|
+
}
|
|
1250
|
+
/** 505 — The HTTP version used in the request is not supported by the server. */
|
|
1251
|
+
declare class HttpVersionNotSupportedError extends FreshError {
|
|
1252
|
+
constructor(detail?: string, options?: FreshErrorOptions);
|
|
1253
|
+
}
|
|
1254
|
+
/** 506 — The server has a configuration error resulting in circular content negotiation. */
|
|
1255
|
+
declare class VariantAlsoNegotiatesError extends FreshError {
|
|
1256
|
+
constructor(detail?: string, options?: FreshErrorOptions);
|
|
1257
|
+
}
|
|
1258
|
+
/** 507 — The server cannot store the representation needed to complete the request. */
|
|
1259
|
+
declare class InsufficientStorageError extends FreshError {
|
|
1260
|
+
constructor(detail?: string, options?: FreshErrorOptions);
|
|
1261
|
+
}
|
|
1262
|
+
/** 508 — The server detected an infinite loop while processing the request. */
|
|
1263
|
+
declare class LoopDetectedError extends FreshError {
|
|
1264
|
+
constructor(detail?: string, options?: FreshErrorOptions);
|
|
1265
|
+
}
|
|
1266
|
+
/** 510 — Further extensions to the request are required for the server to fulfil it. */
|
|
1267
|
+
declare class NotExtendedError extends FreshError {
|
|
1268
|
+
constructor(detail?: string, options?: FreshErrorOptions);
|
|
1269
|
+
}
|
|
1270
|
+
/** 511 — The client must authenticate to gain network access (e.g. captive portal). */
|
|
1271
|
+
declare class NetworkAuthenticationRequiredError extends FreshError {
|
|
1272
|
+
constructor(detail?: string, options?: FreshErrorOptions);
|
|
1273
|
+
}
|
|
1274
|
+
|
|
1275
|
+
declare abstract class DataHelper<T> {
|
|
1276
|
+
private _data?;
|
|
1277
|
+
private _dataPromise;
|
|
1278
|
+
protected deviceIds: Promise<number[]>;
|
|
1279
|
+
constructor(startDataRetrieve: boolean | undefined, deviceIds: Promise<number[]>);
|
|
1280
|
+
protected get data(): Maybe<T> | undefined;
|
|
1281
|
+
protected set data(value: Maybe<T>);
|
|
1282
|
+
protected get dataPromise(): Maybe<Promise<Maybe<T>>>;
|
|
1283
|
+
protected set dataPromise(value: Maybe<Promise<Maybe<T>>>);
|
|
1284
|
+
getData(): Promise<Maybe<T>>;
|
|
1285
|
+
abstract startDataRetrieval(): Promise<Maybe<T>>;
|
|
1286
|
+
}
|
|
1287
|
+
|
|
1021
1288
|
declare const FRESH_ESLINT_CONFIG: {
|
|
1022
1289
|
files: string[];
|
|
1023
1290
|
ignores: string[];
|
|
@@ -1095,4 +1362,4 @@ interface HealthCheckResult {
|
|
|
1095
1362
|
};
|
|
1096
1363
|
}
|
|
1097
1364
|
|
|
1098
|
-
export { AMOUNT_UNIT, ActionCommandCode, ApiError, BaseEntityChangeSubscriber, type BinaryFlag, BusinessWarning, type CardNumber, Category, DEFAULT_PAGINATION_PARAMS, DataHelper, DateUtils, type Deferred, DepotPoolStatus, Device, type EntityChangeEvent, FreshDao, FreshEntity, FreshHyperEntity, FreshJob, FreshTranslationBase, type HealthCheckResult, HttpStatus, type IsDecimalOptions, LanguageCode, Manufacturer, type Maybe, type PaginatedList, type PaginationMeta, type PaginationParams, PaymentMethod, PG_DATA_SOURCE_OPTIONS as PgDataSourceOptions, Product, SinglePromiseWaiter, Singleton, type Status, StatusDto, Subcategory, TO_BINARY_FLAG, TimestampColumn, TransactionType, buildPatch, constructTypeormPagination, createDeferred, FRESH_ESLINT_CONFIG as freshEslintConfig, getPaginationMeta, getPaginationParams, hasOwn, isDecimal, isEnumValue, isFlag01, isMaybe, isNumber, isNumberInRange, isObject, isString, isValidCron, listAll, parsePaginationFromURL, runWithConcurrency, toDecimal };
|
|
1365
|
+
export { AMOUNT_UNIT, ActionCommandCode, ApiError, BadGatewayError, BadRequestError, BaseEntityChangeSubscriber, type BinaryFlag, BusinessWarning, type CardNumber, Category, ConflictError, DEFAULT_PAGINATION_PARAMS, DataHelper, DateUtils, type Deferred, DepotPoolStatus, Device, type EntityChangeEvent, ExpectationFailedError, FailedDependencyError, ForbiddenError, FreshDao, FreshEntity, FreshError, type FreshErrorOptions, FreshHyperEntity, FreshJob, FreshTranslationBase, GatewayTimeoutError, GoneError, type HealthCheckResult, HttpStatus, HttpVersionNotSupportedError, ImATeapotError, InsufficientStorageError, InternalServerError, type IsDecimalOptions, LanguageCode, LengthRequiredError, LockedError, LoopDetectedError, Manufacturer, type Maybe, MethodNotAllowedError, MisdirectedRequestError, NetworkAuthenticationRequiredError, NotAcceptableError, NotExtendedError, NotFoundError, NotImplementedError, type PaginatedList, type PaginationMeta, type PaginationParams, PayloadTooLargeError, PaymentMethod, PaymentRequiredError, PG_DATA_SOURCE_OPTIONS as PgDataSourceOptions, PreconditionFailedError, PreconditionRequiredError, Product, ProxyAuthenticationRequiredError, RangeNotSatisfiableError, RequestHeaderFieldsTooLargeError, RequestTimeoutError, ServiceUnavailableError, SinglePromiseWaiter, Singleton, type Status, StatusDto, Subcategory, TO_BINARY_FLAG, TimestampColumn, TooEarlyError, TooManyRequestsError, TransactionType, UnauthorizedError, UnavailableForLegalReasonsError, UnprocessableEntityError, UnsupportedMediaTypeError, UpgradeRequiredError, UriTooLongError, VariantAlsoNegotiatesError, buildDateRange, buildOrder, buildPagination, buildPatch, constructTypeormPagination, createDeferred, FRESH_ESLINT_CONFIG as freshEslintConfig, getPaginationMeta, getPaginationParams, hasOwn, isDecimal, isEnumValue, isFlag01, isMaybe, isNumber, isNumberInRange, isObject, isString, isValidCron, listAll, parsePaginationFromURL, resolvePathParameterId, runWithConcurrency, toDecimal };
|