@kalutskii/foundation 0.6.20 → 0.6.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.ts +19 -1
- package/dist/index.js +6 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -174,6 +174,24 @@ declare const formatTime: (time: Date, { locale, tz }?: {
|
|
|
174
174
|
tz?: string;
|
|
175
175
|
}) => string;
|
|
176
176
|
|
|
177
|
+
/**
|
|
178
|
+
* Recursively replaces dots in a string with underscores in a type-safe manner.
|
|
179
|
+
* Example: `ReplaceDotsWithUnderscores<'foo.bar.baz.ok'>` → `'foo_bar_baz_ok'`.
|
|
180
|
+
*/
|
|
181
|
+
type ReplaceDotsWithUnderscores<T extends string> = T extends `${infer A}.${infer B}` ? `${A}_${ReplaceDotsWithUnderscores<B>}` : T;
|
|
182
|
+
/**
|
|
183
|
+
* Type-safe record mapping string values to ergonomic enum-like keys.
|
|
184
|
+
* Keys are uppercased and dots are replaced with underscores.
|
|
185
|
+
*/
|
|
186
|
+
type StringEnumRecord<T extends readonly string[]> = Readonly<{
|
|
187
|
+
[Value in T[number] as Uppercase<ReplaceDotsWithUnderscores<Value>>]: Value;
|
|
188
|
+
}>;
|
|
189
|
+
/**
|
|
190
|
+
* Creates an immutable enum-like record from a readonly string array.
|
|
191
|
+
* Example: `['foo.s', 'baz'] as const` → `{ FOO_S: 'foo.s', BAZ: 'baz' }`.
|
|
192
|
+
*/
|
|
193
|
+
declare function createStringEnumRecord<const T extends readonly string[]>(values: T): StringEnumRecord<T>;
|
|
194
|
+
|
|
177
195
|
/**
|
|
178
196
|
* Safely executes functions and handles errors without using try/catch in the calling code.
|
|
179
197
|
* Example usage: `safeExecute(() => fetchData(), (error) => console.error(error))`
|
|
@@ -338,4 +356,4 @@ declare const asQuery: <T extends z.ZodTypeAny>(schema: T) => z.ZodPreprocess<T>
|
|
|
338
356
|
*/
|
|
339
357
|
declare const isPlainObject: (value: unknown) => value is Record<string, unknown>;
|
|
340
358
|
|
|
341
|
-
export { type APIContractData, type APIContractError, type APIContractResult, type APIError, type APISuccess, type AsQuery, type AtLeastOne, EXCEPTION_STATUS_CODES, type ExceptionStatusCode, type FetchResult, type JWTServiceOptions, type JWTSignOptions, type MeasuredExecution, type Payload, type PayloadSchema, SUCCESS_STATUS_CODES, type Simplify, type SuccessStatusCode, ZodJWTService, type ZodPaginationOptions, asQuery, failure, fetchAndThrow, fetchSafely, formatTime, generateRandomString, getColoredHTTPStatus, getFormattedDate, getFormattedTime, getUTCOffset, getZonedTime, honoLoggingHandler, isPlainObject, log, measureExecutionTime, onHandlerError, parseQueryValue, respond, safeExecute, sqlWhere, success, zodAtLeastOne, zodPaginationSchema, zodPaginationShape };
|
|
359
|
+
export { type APIContractData, type APIContractError, type APIContractResult, type APIError, type APISuccess, type AsQuery, type AtLeastOne, EXCEPTION_STATUS_CODES, type ExceptionStatusCode, type FetchResult, type JWTServiceOptions, type JWTSignOptions, type MeasuredExecution, type Payload, type PayloadSchema, type ReplaceDotsWithUnderscores, SUCCESS_STATUS_CODES, type Simplify, type StringEnumRecord, type SuccessStatusCode, ZodJWTService, type ZodPaginationOptions, asQuery, createStringEnumRecord, failure, fetchAndThrow, fetchSafely, formatTime, generateRandomString, getColoredHTTPStatus, getFormattedDate, getFormattedTime, getUTCOffset, getZonedTime, honoLoggingHandler, isPlainObject, log, measureExecutionTime, onHandlerError, parseQueryValue, respond, safeExecute, sqlWhere, success, zodAtLeastOne, zodPaginationSchema, zodPaginationShape };
|
package/dist/index.js
CHANGED
|
@@ -142,6 +142,11 @@ async function fetchAndThrow(fetcher) {
|
|
|
142
142
|
return response.data;
|
|
143
143
|
}
|
|
144
144
|
|
|
145
|
+
// src/utilities/enums.utilities.ts
|
|
146
|
+
function createStringEnumRecord(values) {
|
|
147
|
+
return Object.freeze(Object.fromEntries(values.map((value) => [value.replace(/\./g, "_").toUpperCase(), value])));
|
|
148
|
+
}
|
|
149
|
+
|
|
145
150
|
// src/utilities/execution.utilities.ts
|
|
146
151
|
async function safeExecute(fn, onError) {
|
|
147
152
|
try {
|
|
@@ -260,6 +265,7 @@ export {
|
|
|
260
265
|
SUCCESS_STATUS_CODES,
|
|
261
266
|
ZodJWTService,
|
|
262
267
|
asQuery,
|
|
268
|
+
createStringEnumRecord,
|
|
263
269
|
failure,
|
|
264
270
|
fetchAndThrow,
|
|
265
271
|
fetchSafely,
|