@kalutskii/foundation 0.6.10 → 0.6.11
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 +1 -71
- package/dist/index.js +0 -39
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -315,76 +315,6 @@ type ZodPaginationOptions = z.infer<typeof zodPaginationSchema>;
|
|
|
315
315
|
*/
|
|
316
316
|
declare const refinePagination: (options?: ZodPaginationOptions) => ZodPaginationOptions;
|
|
317
317
|
|
|
318
|
-
type ZodShape = Record<string, z.ZodTypeAny>;
|
|
319
|
-
type AnyZodObject = z.ZodObject<ZodShape>;
|
|
320
|
-
type UnionToIntersection<T> = (T extends unknown ? (value: T) => void : never) extends (value: infer I) => void ? I : never;
|
|
321
|
-
type UnwrapOptional<T extends z.ZodTypeAny> = T extends z.ZodOptional<infer Inner> ? Inner : T;
|
|
322
|
-
type IsOptional<T extends z.ZodTypeAny> = T extends z.ZodOptional<z.ZodTypeAny> ? true : false;
|
|
323
|
-
type Optionalize<TSchema extends z.ZodTypeAny, TShouldOptionalize extends boolean> = TShouldOptionalize extends true ? z.ZodOptional<TSchema> : TSchema;
|
|
324
|
-
type FlattenObjectField<TSchema extends z.ZodTypeAny> = UnwrapOptional<TSchema> extends z.ZodObject<infer InnerShape extends ZodShape> ? {
|
|
325
|
-
[K in keyof InnerShape]: Optionalize<InnerShape[K], IsOptional<TSchema>>;
|
|
326
|
-
} : never;
|
|
327
|
-
type FlattenNestedObjectFields<TShape extends ZodShape> = {
|
|
328
|
-
[K in keyof TShape]: FlattenObjectField<TShape[K]>;
|
|
329
|
-
}[keyof TShape];
|
|
330
|
-
/**
|
|
331
|
-
* The resulting shape after all nested `z.ZodObject` fields have been lifted to the top level.
|
|
332
|
-
* Primitive fields are kept as-is; nested object fields are replaced with their inner keys.
|
|
333
|
-
* If the parent field was optional, all promoted inner fields become optional as well.
|
|
334
|
-
*/
|
|
335
|
-
type FlattenZodShape<TShape extends ZodShape> = {
|
|
336
|
-
[K in keyof TShape as UnwrapOptional<TShape[K]> extends AnyZodObject ? never : K]: TShape[K];
|
|
337
|
-
} & UnionToIntersection<FlattenNestedObjectFields<TShape>>;
|
|
338
|
-
|
|
339
|
-
/**
|
|
340
|
-
* Recursively lifts all nested `z.ZodObject` fields to the top level of the shape.
|
|
341
|
-
* Primitive fields are preserved as-is. If the parent field was optional, all promoted
|
|
342
|
-
* inner keys become optional to avoid requiring fields that were previously nested under an optional object.
|
|
343
|
-
*
|
|
344
|
-
* ```ts
|
|
345
|
-
* const flat = flattenZodShape({
|
|
346
|
-
* name: z.string(),
|
|
347
|
-
* address: z.object({ city: z.string(), zip: z.string() }).optional(),
|
|
348
|
-
* });
|
|
349
|
-
* // { name: z.string(), city: z.string().optional(), zip: z.string().optional() }
|
|
350
|
-
* ```
|
|
351
|
-
*/
|
|
352
|
-
declare const flattenZodShape: <TShape extends ZodShape>(shape: TShape) => FlattenZodShape<TShape>;
|
|
353
|
-
/**
|
|
354
|
-
* Builds a strict flat query schema from a nested `z.ZodObject`.
|
|
355
|
-
* All nested object fields are lifted to the top level while preserving optionality,
|
|
356
|
-
* making the result suitable for validating flat query parameter objects.
|
|
357
|
-
*
|
|
358
|
-
* ```ts
|
|
359
|
-
* const schema = asQuerySchema(
|
|
360
|
-
* z.object({
|
|
361
|
-
* search: z.string().optional(),
|
|
362
|
-
* sort: z.object({ field: z.string(), order: z.enum(['asc', 'desc']) }).optional(),
|
|
363
|
-
* })
|
|
364
|
-
* );
|
|
365
|
-
*
|
|
366
|
-
* schema.parse({ search: 'foo', field: 'name', order: 'asc' });
|
|
367
|
-
* // { search: 'foo', field: 'name', order: 'asc' }
|
|
368
|
-
* ```
|
|
369
|
-
*/
|
|
370
|
-
declare const asQuerySchema: <TShape extends ZodShape>(schema: z.ZodObject<TShape>) => z.ZodObject<FlattenZodShape<TShape> extends infer T ? { -readonly [P in keyof T]: T[P]; } : never, z.core.$strict>;
|
|
371
|
-
|
|
372
|
-
/**
|
|
373
|
-
* Checks if the provided schema is an instance of `z.ZodObject`.
|
|
374
|
-
* @returns `true` if the schema is a `z.ZodObject`, `false` otherwise.
|
|
375
|
-
*/
|
|
376
|
-
declare const isZodObject: (schema: z.ZodTypeAny) => schema is AnyZodObject;
|
|
377
|
-
/**
|
|
378
|
-
* Checks if the provided schema is an instance of `z.ZodOptional`.
|
|
379
|
-
* @returns `true` if the schema is a `z.ZodOptional`, `false` otherwise.
|
|
380
|
-
*/
|
|
381
|
-
declare const isZodOptional: (schema: z.ZodTypeAny) => schema is z.ZodOptional<z.ZodTypeAny>;
|
|
382
|
-
/**
|
|
383
|
-
* Unwraps a `z.ZodOptional` schema to retrieve its inner schema.
|
|
384
|
-
* If the provided schema is not optional, it is returned unchanged.
|
|
385
|
-
*/
|
|
386
|
-
declare const unwrapOptional: (schema: z.ZodTypeAny) => z.ZodTypeAny;
|
|
387
|
-
|
|
388
318
|
declare const parseQueryValue: (value: unknown) => unknown;
|
|
389
319
|
/**
|
|
390
320
|
* Query parameters always arrive as strings, even when they semantically represent numbers
|
|
@@ -411,4 +341,4 @@ declare const asQuery: <T extends z.ZodTypeAny>(schema: T) => z.ZodPreprocess<T>
|
|
|
411
341
|
*/
|
|
412
342
|
declare const isPlainObject: (value: unknown) => value is Record<string, unknown>;
|
|
413
343
|
|
|
414
|
-
export { type APIContractData, type APIContractError, type APIContractResult, type APIError, type APISuccess, type
|
|
344
|
+
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, refinePagination, respond, safeExecute, sqlWhere, success, zodPaginationSchema, zodPaginationShape };
|
package/dist/index.js
CHANGED
|
@@ -246,40 +246,6 @@ var zodPaginationSchema = z2.object({
|
|
|
246
246
|
});
|
|
247
247
|
var zodPaginationShape = zodPaginationSchema.shape;
|
|
248
248
|
|
|
249
|
-
// src/zod-flatten/zod-flatten.schemas.ts
|
|
250
|
-
import z4 from "zod";
|
|
251
|
-
|
|
252
|
-
// src/zod-flatten/zod-flatten.utilities.ts
|
|
253
|
-
import z3 from "zod";
|
|
254
|
-
var isZodObject = (schema) => {
|
|
255
|
-
return schema instanceof z3.ZodObject;
|
|
256
|
-
};
|
|
257
|
-
var isZodOptional = (schema) => {
|
|
258
|
-
return schema instanceof z3.ZodOptional;
|
|
259
|
-
};
|
|
260
|
-
var unwrapOptional = (schema) => {
|
|
261
|
-
return isZodOptional(schema) ? schema.unwrap() : schema;
|
|
262
|
-
};
|
|
263
|
-
|
|
264
|
-
// src/zod-flatten/zod-flatten.schemas.ts
|
|
265
|
-
var flattenZodShape = (shape) => {
|
|
266
|
-
const flat = {};
|
|
267
|
-
for (const [key, schema] of Object.entries(shape)) {
|
|
268
|
-
const unwrappedSchema = unwrapOptional(schema);
|
|
269
|
-
if (isZodObject(unwrappedSchema) === false) {
|
|
270
|
-
flat[key] = schema;
|
|
271
|
-
continue;
|
|
272
|
-
}
|
|
273
|
-
for (const [innerKey, innerSchema] of Object.entries(unwrappedSchema.shape)) {
|
|
274
|
-
flat[innerKey] = isZodOptional(schema) ? innerSchema.optional() : innerSchema;
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
return flat;
|
|
278
|
-
};
|
|
279
|
-
var asQuerySchema = (schema) => {
|
|
280
|
-
return z4.object(flattenZodShape(schema.shape)).strict();
|
|
281
|
-
};
|
|
282
|
-
|
|
283
249
|
// src/zod-validation/zod-validation.utilities.ts
|
|
284
250
|
var isPlainObject = (value) => {
|
|
285
251
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -289,11 +255,9 @@ export {
|
|
|
289
255
|
SUCCESS_STATUS_CODES,
|
|
290
256
|
ZodJWTService,
|
|
291
257
|
asQuery,
|
|
292
|
-
asQuerySchema,
|
|
293
258
|
failure,
|
|
294
259
|
fetchAndThrow,
|
|
295
260
|
fetchSafely,
|
|
296
|
-
flattenZodShape,
|
|
297
261
|
formatTime,
|
|
298
262
|
generateRandomString,
|
|
299
263
|
getColoredHTTPStatus,
|
|
@@ -303,8 +267,6 @@ export {
|
|
|
303
267
|
getZonedTime,
|
|
304
268
|
honoLoggingHandler,
|
|
305
269
|
isPlainObject,
|
|
306
|
-
isZodObject,
|
|
307
|
-
isZodOptional,
|
|
308
270
|
log,
|
|
309
271
|
measureExecutionTime,
|
|
310
272
|
onHandlerError,
|
|
@@ -314,7 +276,6 @@ export {
|
|
|
314
276
|
safeExecute,
|
|
315
277
|
sqlWhere,
|
|
316
278
|
success,
|
|
317
|
-
unwrapOptional,
|
|
318
279
|
zodPaginationSchema,
|
|
319
280
|
zodPaginationShape
|
|
320
281
|
};
|