katanakit-js 2.2.1 → 2.12.9
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/README.md +72 -437
- package/dist/adapters/astro/astro.service.d.ts +103 -15
- package/dist/adapters/astro/astro.service.d.ts.map +1 -1
- package/dist/adapters/astro/astro.service.js +145 -75
- package/dist/adapters/astro/astro.service.js.map +1 -1
- package/dist/adapters/astro/index.d.ts +1 -1
- package/dist/adapters/astro/index.d.ts.map +1 -1
- package/dist/adapters/astro/index.js +1 -1
- package/dist/adapters/astro/index.js.map +1 -1
- package/dist/adapters/astro/rss.service.d.ts +85 -105
- package/dist/adapters/astro/rss.service.d.ts.map +1 -1
- package/dist/adapters/astro/rss.service.js +172 -168
- package/dist/adapters/astro/rss.service.js.map +1 -1
- package/dist/adapters/astro/seo.service.d.ts +10 -0
- package/dist/adapters/astro/seo.service.d.ts.map +1 -0
- package/dist/adapters/astro/seo.service.js +3 -0
- package/dist/adapters/astro/seo.service.js.map +1 -0
- package/dist/adapters/express/app.d.ts +30 -1
- package/dist/adapters/express/app.d.ts.map +1 -1
- package/dist/adapters/express/app.js +31 -3
- package/dist/adapters/express/app.js.map +1 -1
- package/dist/adapters/express/index.d.ts +2 -2
- package/dist/adapters/express/index.d.ts.map +1 -1
- package/dist/adapters/express/index.js +2 -2
- package/dist/adapters/express/index.js.map +1 -1
- package/dist/adapters/express/main.js +2 -2
- package/dist/adapters/express/main.js.map +1 -1
- package/dist/adapters/express/products.controller.d.ts +67 -8
- package/dist/adapters/express/products.controller.d.ts.map +1 -1
- package/dist/adapters/express/products.controller.js +105 -49
- package/dist/adapters/express/products.controller.js.map +1 -1
- package/dist/adapters/express/server.d.ts +37 -13
- package/dist/adapters/express/server.d.ts.map +1 -1
- package/dist/adapters/express/server.js +118 -53
- package/dist/adapters/express/server.js.map +1 -1
- package/dist/adapters/nuxt/nuxt.service.d.ts +8 -6
- package/dist/adapters/nuxt/nuxt.service.d.ts.map +1 -1
- package/dist/adapters/nuxt/nuxt.service.js +34 -10
- package/dist/adapters/nuxt/nuxt.service.js.map +1 -1
- package/dist/adapters/vue/vue.service.d.ts +5 -2
- package/dist/adapters/vue/vue.service.d.ts.map +1 -1
- package/dist/adapters/vue/vue.service.js +41 -7
- package/dist/adapters/vue/vue.service.js.map +1 -1
- package/dist/config/index.d.ts +2 -1
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +1 -1
- package/dist/config/index.js.map +1 -1
- package/dist/config/seo-meta.types.d.ts +177 -0
- package/dist/config/seo-meta.types.d.ts.map +1 -0
- package/dist/config/seo-meta.types.js +11 -0
- package/dist/config/seo-meta.types.js.map +1 -0
- package/dist/config/seo.service.d.ts +41 -58
- package/dist/config/seo.service.d.ts.map +1 -1
- package/dist/config/seo.service.js +468 -136
- package/dist/config/seo.service.js.map +1 -1
- package/dist/config/site.config.d.ts +10 -50
- package/dist/config/site.config.d.ts.map +1 -1
- package/dist/config/site.config.js +8 -36
- package/dist/config/site.config.js.map +1 -1
- package/dist/core/index.d.ts +1 -3
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +1 -3
- package/dist/core/index.js.map +1 -1
- package/dist/core/services/dates.service.d.ts +149 -22
- package/dist/core/services/dates.service.d.ts.map +1 -1
- package/dist/core/services/dates.service.js +201 -54
- package/dist/core/services/dates.service.js.map +1 -1
- package/dist/core/services/error.service.d.ts +32 -20
- package/dist/core/services/error.service.d.ts.map +1 -1
- package/dist/core/services/error.service.js +44 -32
- package/dist/core/services/error.service.js.map +1 -1
- package/dist/core/services/formatter.service.d.ts +245 -35
- package/dist/core/services/formatter.service.d.ts.map +1 -1
- package/dist/core/services/formatter.service.js +281 -57
- package/dist/core/services/formatter.service.js.map +1 -1
- package/dist/core/services/generator.service.d.ts +115 -26
- package/dist/core/services/generator.service.d.ts.map +1 -1
- package/dist/core/services/generator.service.js +191 -56
- package/dist/core/services/generator.service.js.map +1 -1
- package/dist/core/services/geometry.service.d.ts +369 -39
- package/dist/core/services/geometry.service.d.ts.map +1 -1
- package/dist/core/services/geometry.service.js +424 -66
- package/dist/core/services/geometry.service.js.map +1 -1
- package/dist/core/services/http.service.d.ts +244 -21
- package/dist/core/services/http.service.d.ts.map +1 -1
- package/dist/core/services/http.service.js +419 -98
- package/dist/core/services/http.service.js.map +1 -1
- package/dist/core/services/logger.service.d.ts +95 -29
- package/dist/core/services/logger.service.d.ts.map +1 -1
- package/dist/core/services/logger.service.js +167 -41
- package/dist/core/services/logger.service.js.map +1 -1
- package/dist/core/services/reactive.service.d.ts +146 -19
- package/dist/core/services/reactive.service.d.ts.map +1 -1
- package/dist/core/services/reactive.service.js +278 -137
- package/dist/core/services/reactive.service.js.map +1 -1
- package/dist/core/services/timing.service.d.ts +142 -20
- package/dist/core/services/timing.service.d.ts.map +1 -1
- package/dist/core/services/timing.service.js +324 -185
- package/dist/core/services/timing.service.js.map +1 -1
- package/dist/core/services/utils.service.d.ts +228 -43
- package/dist/core/services/utils.service.d.ts.map +1 -1
- package/dist/core/services/utils.service.js +305 -125
- package/dist/core/services/utils.service.js.map +1 -1
- package/dist/infrastructure/dom/dom.service.d.ts +307 -44
- package/dist/infrastructure/dom/dom.service.d.ts.map +1 -1
- package/dist/infrastructure/dom/dom.service.js +408 -129
- package/dist/infrastructure/dom/dom.service.js.map +1 -1
- package/dist/infrastructure/index.d.ts +0 -3
- package/dist/infrastructure/index.d.ts.map +1 -1
- package/dist/infrastructure/index.js +0 -3
- package/dist/infrastructure/index.js.map +1 -1
- package/dist/infrastructure/observer/observer.service.d.ts +124 -31
- package/dist/infrastructure/observer/observer.service.d.ts.map +1 -1
- package/dist/infrastructure/observer/observer.service.js +227 -131
- package/dist/infrastructure/observer/observer.service.js.map +1 -1
- package/dist/infrastructure/sensors/sensors.service.d.ts +154 -22
- package/dist/infrastructure/sensors/sensors.service.d.ts.map +1 -1
- package/dist/infrastructure/sensors/sensors.service.js +264 -112
- package/dist/infrastructure/sensors/sensors.service.js.map +1 -1
- package/dist/infrastructure/storage/storage.service.d.ts +123 -45
- package/dist/infrastructure/storage/storage.service.d.ts.map +1 -1
- package/dist/infrastructure/storage/storage.service.js +236 -66
- package/dist/infrastructure/storage/storage.service.js.map +1 -1
- package/dist/infrastructure/theme/theme.service.d.ts +93 -29
- package/dist/infrastructure/theme/theme.service.d.ts.map +1 -1
- package/dist/infrastructure/theme/theme.service.js +198 -96
- package/dist/infrastructure/theme/theme.service.js.map +1 -1
- package/dist/infrastructure/viewport/viewport.service.d.ts +233 -35
- package/dist/infrastructure/viewport/viewport.service.d.ts.map +1 -1
- package/dist/infrastructure/viewport/viewport.service.js +358 -139
- package/dist/infrastructure/viewport/viewport.service.js.map +1 -1
- package/dist/infrastructure/worker/worker.service.d.ts +84 -38
- package/dist/infrastructure/worker/worker.service.d.ts.map +1 -1
- package/dist/infrastructure/worker/worker.service.js +234 -133
- package/dist/infrastructure/worker/worker.service.js.map +1 -1
- package/dist/prisma/index.d.ts +2 -0
- package/dist/prisma/index.d.ts.map +1 -0
- package/dist/prisma/index.js +2 -0
- package/dist/prisma/index.js.map +1 -0
- package/dist/prisma/schema.json +11 -33
- package/dist/prisma/use-prisma.d.ts +68 -0
- package/dist/prisma/use-prisma.d.ts.map +1 -0
- package/dist/prisma/use-prisma.js +82 -0
- package/dist/prisma/use-prisma.js.map +1 -0
- package/dist/types/index.d.ts +20 -12
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +124 -125
- package/CHANGELOG.md +0 -101
|
@@ -1,64 +1,211 @@
|
|
|
1
1
|
import { Temporal } from "@js-temporal/polyfill";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Internal helper that adapts flexible inputs into a `PlainDate`.
|
|
4
|
+
*
|
|
5
|
+
* @param date - An ISO date string or a `Temporal.PlainDate`.
|
|
6
|
+
* @returns A `Temporal.PlainDate`.
|
|
4
7
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
function toPlainDate(date) {
|
|
9
|
+
return typeof date === "string" ? Temporal.PlainDate.from(date) : date;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Returns a human-readable diff between two dates as years, months, and days.
|
|
13
|
+
*
|
|
14
|
+
* @param start - Start date (ISO string or `PlainDate`).
|
|
15
|
+
* @param end - End date (ISO string or `PlainDate`).
|
|
16
|
+
* @returns A formatted string, e.g. `"2 years, 3 months and 15 days"`.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* useDiff("2020-01-01", "2022-04-16");
|
|
21
|
+
* // "2 years, 3 months and 15 days"
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export function useDiff(start, end) {
|
|
25
|
+
const startDate = toPlainDate(start);
|
|
26
|
+
const endDate = toPlainDate(end);
|
|
27
|
+
const duration = startDate.until(endDate, { largestUnit: "year" });
|
|
28
|
+
return `${duration.years} years, ${duration.months} months and ${duration.days} days`;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Formats a date input into a localised string using `Intl.DateTimeFormat`.
|
|
32
|
+
*
|
|
33
|
+
* Accepts epoch milliseconds, ISO strings, native `Date` objects,
|
|
34
|
+
* `Temporal.Instant`, or any `Temporal` date/time type.
|
|
35
|
+
*
|
|
36
|
+
* @param dateInput - The value to format.
|
|
37
|
+
* @param locale - BCP 47 locale tag (defaults to `"en"`).
|
|
38
|
+
* @param options - `Intl.DateTimeFormatOptions` (defaults to `{}`).
|
|
39
|
+
* @returns The formatted date string.
|
|
40
|
+
* @throws {Error} If the input cannot be parsed as a date.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* useFormat("2024-06-15"); // "6/15/2024" (en-US)
|
|
45
|
+
* useFormat(Date.now(), "es", { dateStyle: "full" }); // "sábado, 15 de junio de 2024"
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export function useFormat(dateInput, locale = "en", options = {}) {
|
|
49
|
+
let date;
|
|
50
|
+
try {
|
|
51
|
+
if (typeof dateInput === "number") {
|
|
52
|
+
date = Temporal.Instant.fromEpochMilliseconds(dateInput).toZonedDateTimeISO(Temporal.Now.timeZoneId());
|
|
11
53
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
TO_PLAIN_DATE = (date) => typeof date === "string" ? Temporal.PlainDate.from(date) : date;
|
|
16
|
-
useDiff = (start, end) => {
|
|
17
|
-
const startDate = this.TO_PLAIN_DATE(start);
|
|
18
|
-
const endDate = this.TO_PLAIN_DATE(end);
|
|
19
|
-
const duration = startDate.until(endDate, { largestUnit: "year" });
|
|
20
|
-
return `${duration.years} years, ${duration.months} months and ${duration.days} days`;
|
|
21
|
-
};
|
|
22
|
-
useFormat = (dateInput, locale = "en", options = {}) => {
|
|
23
|
-
let date;
|
|
24
|
-
try {
|
|
25
|
-
if (typeof dateInput === "number") {
|
|
26
|
-
date = Temporal.Instant.fromEpochMilliseconds(dateInput).toZonedDateTimeISO(Temporal.Now.timeZoneId());
|
|
27
|
-
}
|
|
28
|
-
else if (typeof dateInput === "string") {
|
|
29
|
-
try {
|
|
30
|
-
date = Temporal.PlainDate.from(dateInput);
|
|
31
|
-
}
|
|
32
|
-
catch {
|
|
33
|
-
date = Temporal.PlainDateTime.from(dateInput);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
else if (dateInput instanceof Date) {
|
|
37
|
-
date = Temporal.Instant.fromEpochMilliseconds(dateInput.getTime()).toZonedDateTimeISO(Temporal.Now.timeZoneId());
|
|
54
|
+
else if (typeof dateInput === "string") {
|
|
55
|
+
try {
|
|
56
|
+
date = Temporal.PlainDate.from(dateInput);
|
|
38
57
|
}
|
|
39
|
-
|
|
40
|
-
date =
|
|
58
|
+
catch {
|
|
59
|
+
date = Temporal.PlainDateTime.from(dateInput);
|
|
41
60
|
}
|
|
42
|
-
else {
|
|
43
|
-
date = dateInput;
|
|
44
|
-
}
|
|
45
|
-
return date.toLocaleString(locale, options);
|
|
46
61
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
62
|
+
else if (dateInput instanceof Date) {
|
|
63
|
+
date = Temporal.Instant.fromEpochMilliseconds(dateInput.getTime()).toZonedDateTimeISO(Temporal.Now.timeZoneId());
|
|
64
|
+
}
|
|
65
|
+
else if (dateInput instanceof Temporal.Instant) {
|
|
66
|
+
date = dateInput.toZonedDateTimeISO(Temporal.Now.timeZoneId());
|
|
50
67
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
68
|
+
else {
|
|
69
|
+
date = dateInput;
|
|
70
|
+
}
|
|
71
|
+
return date.toLocaleString(locale, options);
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
console.error("Invalid date input:", error);
|
|
75
|
+
throw new Error(`Invalid date input: ${dateInput}`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Returns today's date as an ISO date string.
|
|
80
|
+
*
|
|
81
|
+
* @returns The current date in `YYYY-MM-DD` format.
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```ts
|
|
85
|
+
* useNow(); // "2024-06-15"
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
export function useNow() {
|
|
89
|
+
return Temporal.Now.plainDateISO().toString();
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Returns the current date and time as an ISO string (no timezone offset).
|
|
93
|
+
*
|
|
94
|
+
* @returns The current date-time in `YYYY-MM-DDTHH:MM:SS` format.
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```ts
|
|
98
|
+
* useNowDateTime(); // "2024-06-15T14:30:00"
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
export function useNowDateTime() {
|
|
102
|
+
return Temporal.Now.plainDateTimeISO().toString();
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Adds a number of days to a date.
|
|
106
|
+
*
|
|
107
|
+
* @param date - Base date (ISO string or `PlainDate`).
|
|
108
|
+
* @param days - Number of days to add (can be negative).
|
|
109
|
+
* @returns The resulting date as an ISO string.
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```ts
|
|
113
|
+
* useAddDays("2024-01-01", 10); // "2024-01-11"
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
export function useAddDays(date, days) {
|
|
117
|
+
return toPlainDate(date).add({ days }).toString();
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Subtracts a number of days from a date.
|
|
121
|
+
*
|
|
122
|
+
* @param date - Base date (ISO string or `PlainDate`).
|
|
123
|
+
* @param days - Number of days to subtract.
|
|
124
|
+
* @returns The resulting date as an ISO string.
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```ts
|
|
128
|
+
* useSubtractDays("2024-01-11", 10); // "2024-01-01"
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
export function useSubtractDays(date, days) {
|
|
132
|
+
return toPlainDate(date).subtract({ days }).toString();
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Checks whether two dates are equal.
|
|
136
|
+
*
|
|
137
|
+
* @param date1 - First date (ISO string or `PlainDate`).
|
|
138
|
+
* @param date2 - Second date (ISO string or `PlainDate`).
|
|
139
|
+
* @returns `true` if the dates represent the same day.
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* ```ts
|
|
143
|
+
* useIsEqual("2024-06-15", "2024-06-15"); // true
|
|
144
|
+
* useIsEqual("2024-06-15", "2024-06-16"); // false
|
|
145
|
+
* ```
|
|
146
|
+
*/
|
|
147
|
+
export function useIsEqual(date1, date2) {
|
|
148
|
+
return Temporal.PlainDate.compare(toPlainDate(date1), toPlainDate(date2)) === 0;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Checks whether `date1` is before `date2`.
|
|
152
|
+
*
|
|
153
|
+
* @param date1 - First date (ISO string or `PlainDate`).
|
|
154
|
+
* @param date2 - Second date (ISO string or `PlainDate`).
|
|
155
|
+
* @returns `true` if `date1` is strictly before `date2`.
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* ```ts
|
|
159
|
+
* useIsBefore("2024-01-01", "2024-06-15"); // true
|
|
160
|
+
* useIsBefore("2024-06-15", "2024-06-15"); // false
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
163
|
+
export function useIsBefore(date1, date2) {
|
|
164
|
+
return Temporal.PlainDate.compare(toPlainDate(date1), toPlainDate(date2)) < 0;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Checks whether `date1` is after `date2`.
|
|
168
|
+
*
|
|
169
|
+
* @param date1 - First date (ISO string or `PlainDate`).
|
|
170
|
+
* @param date2 - Second date (ISO string or `PlainDate`).
|
|
171
|
+
* @returns `true` if `date1` is strictly after `date2`.
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* ```ts
|
|
175
|
+
* useIsAfter("2024-06-15", "2024-01-01"); // true
|
|
176
|
+
* useIsAfter("2024-06-15", "2024-06-15"); // false
|
|
177
|
+
* ```
|
|
178
|
+
*/
|
|
179
|
+
export function useIsAfter(date1, date2) {
|
|
180
|
+
return Temporal.PlainDate.compare(toPlainDate(date1), toPlainDate(date2)) > 0;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Returns the first day of the month for a given date.
|
|
184
|
+
*
|
|
185
|
+
* @param date - Base date (defaults to today).
|
|
186
|
+
* @returns The first day of the month as an ISO string.
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* ```ts
|
|
190
|
+
* useFirstDayOfMonth("2024-06-15"); // "2024-06-01"
|
|
191
|
+
* ```
|
|
192
|
+
*/
|
|
193
|
+
export function useFirstDayOfMonth(date = Temporal.Now.plainDateISO()) {
|
|
194
|
+
return toPlainDate(date).with({ day: 1 }).toString();
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Returns the last day of the month for a given date.
|
|
198
|
+
*
|
|
199
|
+
* @param date - Base date (defaults to today).
|
|
200
|
+
* @returns The last day of the month as an ISO string.
|
|
201
|
+
*
|
|
202
|
+
* @example
|
|
203
|
+
* ```ts
|
|
204
|
+
* useLastDayOfMonth("2024-02-10"); // "2024-02-29" (leap year)
|
|
205
|
+
* useLastDayOfMonth("2024-06-15"); // "2024-06-30"
|
|
206
|
+
* ```
|
|
207
|
+
*/
|
|
208
|
+
export function useLastDayOfMonth(date = Temporal.Now.plainDateISO()) {
|
|
209
|
+
return toPlainDate(date).add({ months: 1 }).with({ day: 1 }).subtract({ days: 1 }).toString();
|
|
61
210
|
}
|
|
62
|
-
// Singleton instance and destructured exports.
|
|
63
|
-
export const { useDiff, useFormat, useNow, useNowDateTime, useAddDays, useSubtractDays, useIsEqual, useIsBefore, useIsAfter, useFirstDayOfMonth, useLastDayOfMonth, } = DatesService.getInstance();
|
|
64
211
|
//# sourceMappingURL=dates.service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dates.service.js","sourceRoot":"","sources":["../../../src/core/services/dates.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAIjD
|
|
1
|
+
{"version":3,"file":"dates.service.js","sourceRoot":"","sources":["../../../src/core/services/dates.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAIjD;;;;;GAKG;AACH,SAAS,WAAW,CAAC,IAAiC;IACrD,OAAO,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AACxE,CAAC;AAED;;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ize an error into a plain object.
|
|
4
|
+
* Uses sensible defaults based on the status code when message is omitted.
|
|
5
|
+
*
|
|
6
|
+
* @param message - Error message (falls back to status code default)
|
|
7
|
+
* @param code - HTTP status code (default: 400)
|
|
8
|
+
* @returns Serialized error with message and code
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* const err = useErrorSerialize("User not found", 404);
|
|
13
|
+
* // { message: "User not found", code: 404 }
|
|
14
|
+
*
|
|
15
|
+
* const err2 = useErrorSerialize("", 500);
|
|
16
|
+
* // { message: "Internal Server Error", code: 500 }
|
|
17
|
+
* ```
|
|
4
18
|
*/
|
|
5
|
-
export declare
|
|
6
|
-
readonly code: number;
|
|
7
|
-
constructor(message?: string, code?: number);
|
|
8
|
-
useToJson: () => ISerializedError;
|
|
9
|
-
}
|
|
19
|
+
export declare function useErrorSerialize(message?: string, code?: number): ISerializedError;
|
|
10
20
|
/**
|
|
11
|
-
*
|
|
21
|
+
* Create a custom error object. Use with `useLogger` for consistent error logging.
|
|
22
|
+
*
|
|
23
|
+
* @param msg - Error message
|
|
24
|
+
* @param code - HTTP status code
|
|
25
|
+
* @returns Serialized error with message and code
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* import { useErrorCustom, useLogger } from "katanakit-js";
|
|
30
|
+
*
|
|
31
|
+
* const error = useErrorCustom("User not found", 404);
|
|
32
|
+
* useLogger("error", error.message, error);
|
|
33
|
+
* // { message: "User not found", code: 404 }
|
|
34
|
+
* ```
|
|
12
35
|
*/
|
|
13
|
-
export declare
|
|
14
|
-
private static instance;
|
|
15
|
-
private constructor();
|
|
16
|
-
static getInstance(): ErrorFactoryService;
|
|
17
|
-
useBadRequest: (message?: string) => AppError;
|
|
18
|
-
useUnauthorized: (message?: string) => AppError;
|
|
19
|
-
useForbidden: (message?: string) => AppError;
|
|
20
|
-
useNotFound: (message?: string) => AppError;
|
|
21
|
-
useInternal: (message?: string) => AppError;
|
|
22
|
-
useCustom: (message: string, code: number) => AppError;
|
|
23
|
-
}
|
|
24
|
-
export declare const useBadRequest: (message?: string) => AppError, useUnauthorized: (message?: string) => AppError, useForbidden: (message?: string) => AppError, useNotFound: (message?: string) => AppError, useInternal: (message?: string) => AppError, useCustom: (message: string, code: number) => AppError;
|
|
36
|
+
export declare function useErrorCustom(msg: string, code: number): ISerializedError;
|
|
25
37
|
//# sourceMappingURL=error.service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.service.d.ts","sourceRoot":"","sources":["../../../src/core/services/error.service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"error.service.d.ts","sourceRoot":"","sources":["../../../src/core/services/error.service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAW7D;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,SAAK,EAAE,IAAI,SAAM,GAAG,gBAAgB,CAK5E;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,gBAAgB,CAE1E"}
|
|
@@ -1,39 +1,51 @@
|
|
|
1
|
+
/** Default error messages by HTTP status code. */
|
|
2
|
+
const ERROR_DEFAULTS = {
|
|
3
|
+
400: "Bad Request",
|
|
4
|
+
401: "Unauthorized",
|
|
5
|
+
403: "Forbidden",
|
|
6
|
+
404: "Not Found",
|
|
7
|
+
500: "Internal Server Error",
|
|
8
|
+
};
|
|
1
9
|
/**
|
|
2
|
-
*
|
|
10
|
+
* Serialize an error into a plain object.
|
|
11
|
+
* Uses sensible defaults based on the status code when message is omitted.
|
|
12
|
+
*
|
|
13
|
+
* @param message - Error message (falls back to status code default)
|
|
14
|
+
* @param code - HTTP status code (default: 400)
|
|
15
|
+
* @returns Serialized error with message and code
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* const err = useErrorSerialize("User not found", 404);
|
|
20
|
+
* // { message: "User not found", code: 404 }
|
|
21
|
+
*
|
|
22
|
+
* const err2 = useErrorSerialize("", 500);
|
|
23
|
+
* // { message: "Internal Server Error", code: 500 }
|
|
24
|
+
* ```
|
|
3
25
|
*/
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
this.name = "AppError";
|
|
10
|
-
Object.setPrototypeOf(this, AppError.prototype);
|
|
11
|
-
}
|
|
12
|
-
useToJson = () => ({
|
|
13
|
-
name: this.name,
|
|
14
|
-
message: this.message,
|
|
15
|
-
code: this.code,
|
|
16
|
-
});
|
|
26
|
+
export function useErrorSerialize(message = "", code = 400) {
|
|
27
|
+
return {
|
|
28
|
+
message: message || ERROR_DEFAULTS[code] || "Error",
|
|
29
|
+
code,
|
|
30
|
+
};
|
|
17
31
|
}
|
|
18
32
|
/**
|
|
19
|
-
*
|
|
33
|
+
* Create a custom error object. Use with `useLogger` for consistent error logging.
|
|
34
|
+
*
|
|
35
|
+
* @param msg - Error message
|
|
36
|
+
* @param code - HTTP status code
|
|
37
|
+
* @returns Serialized error with message and code
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* import { useErrorCustom, useLogger } from "katanakit-js";
|
|
42
|
+
*
|
|
43
|
+
* const error = useErrorCustom("User not found", 404);
|
|
44
|
+
* useLogger("error", error.message, error);
|
|
45
|
+
* // { message: "User not found", code: 404 }
|
|
46
|
+
* ```
|
|
20
47
|
*/
|
|
21
|
-
export
|
|
22
|
-
|
|
23
|
-
constructor() { }
|
|
24
|
-
static getInstance() {
|
|
25
|
-
if (!ErrorFactoryService.instance) {
|
|
26
|
-
ErrorFactoryService.instance = new ErrorFactoryService();
|
|
27
|
-
}
|
|
28
|
-
return ErrorFactoryService.instance;
|
|
29
|
-
}
|
|
30
|
-
useBadRequest = (message = "Bad Request") => new AppError(message, 400);
|
|
31
|
-
useUnauthorized = (message = "Unauthorized") => new AppError(message, 401);
|
|
32
|
-
useForbidden = (message = "Forbidden") => new AppError(message, 403);
|
|
33
|
-
useNotFound = (message = "Not Found") => new AppError(message, 404);
|
|
34
|
-
useInternal = (message = "Internal Server Error") => new AppError(message, 500);
|
|
35
|
-
useCustom = (message, code) => new AppError(message, code);
|
|
48
|
+
export function useErrorCustom(msg, code) {
|
|
49
|
+
return useErrorSerialize(msg, code);
|
|
36
50
|
}
|
|
37
|
-
// Singleton instance and destructured exports.
|
|
38
|
-
export const { useBadRequest, useUnauthorized, useForbidden, useNotFound, useInternal, useCustom, } = ErrorFactoryService.getInstance();
|
|
39
51
|
//# sourceMappingURL=error.service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.service.js","sourceRoot":"","sources":["../../../src/core/services/error.service.ts"],"names":[],"mappings":"AAEA
|
|
1
|
+
{"version":3,"file":"error.service.js","sourceRoot":"","sources":["../../../src/core/services/error.service.ts"],"names":[],"mappings":"AAEA,kDAAkD;AAClD,MAAM,cAAc,GAA2B;IAC9C,GAAG,EAAE,aAAa;IAClB,GAAG,EAAE,cAAc;IACnB,GAAG,EAAE,WAAW;IAChB,GAAG,EAAE,WAAW;IAChB,GAAG,EAAE,uBAAuB;CAC5B,CAAC;AAEF;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,iBAAiB,CAAC,OAAO,GAAG,EAAE,EAAE,IAAI,GAAG,GAAG;IACzD,OAAO;QACN,OAAO,EAAE,OAAO,IAAI,cAAc,CAAC,IAAI,CAAC,IAAI,OAAO;QACnD,IAAI;KACJ,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,cAAc,CAAC,GAAW,EAAE,IAAY;IACvD,OAAO,iBAAiB,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;AACrC,CAAC"}
|