@revolugo/common 6.14.6-beta.0 → 6.14.6
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/package.json +9 -12
- package/src/constants/index.ts +1 -2
- package/src/constants/locales.ts +5 -5
- package/src/icons/index.ts +1 -0
- package/src/types/elements/contact-person.ts +0 -11
- package/src/types/elements/hotel.ts +0 -2
- package/src/types/elements/index.ts +0 -3
- package/src/types/severities.ts +0 -1
- package/src/utils/case-transformers.ts +5 -5
- package/src/utils/images.ts +3 -3
- package/src/utils/index.ts +0 -4
- package/src/constants/hotel-room-offer.ts +0 -11
- package/src/constants/tax.ts +0 -9
- package/src/schemas/cancellation-policies.ts +0 -18
- package/src/schemas/currency.ts +0 -7
- package/src/schemas/hotel-offer-request.ts +0 -43
- package/src/schemas/hotel-offer.ts +0 -58
- package/src/schemas/hotel-room-offer.ts +0 -99
- package/src/schemas/hotel-room.ts +0 -106
- package/src/schemas/hotel.ts +0 -360
- package/src/schemas/index.ts +0 -10
- package/src/schemas/list-polling-meta.ts +0 -43
- package/src/schemas/tag.ts +0 -13
- package/src/schemas/taxes.ts +0 -34
- package/src/types/elements/booking-flow.ts +0 -6
- package/src/types/elements/elements-events.ts +0 -84
- package/src/types/elements/hotel-offers-filters.ts +0 -19
- package/src/utils/get-sanitized-room-count.ts +0 -29
- package/src/utils/is-object.ts +0 -2
- package/src/utils/keys-case-transformer.ts +0 -118
- package/src/utils/transform-schema-keys.ts +0 -143
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import { type CaseTransformer, changeCase } from './case-transformers.ts'
|
|
2
|
-
import { isObject } from './is-object.ts'
|
|
3
|
-
import { mapKeys } from './map-keys.ts'
|
|
4
|
-
|
|
5
|
-
import type {
|
|
6
|
-
CamelCasedProperties,
|
|
7
|
-
CamelCasedPropertiesDeep,
|
|
8
|
-
KebabCasedProperties,
|
|
9
|
-
KebabCasedPropertiesDeep,
|
|
10
|
-
PascalCasedProperties,
|
|
11
|
-
PascalCasedPropertiesDeep,
|
|
12
|
-
SnakeCasedProperties,
|
|
13
|
-
SnakeCasedPropertiesDeep,
|
|
14
|
-
} from 'type-fest'
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Maps CaseTransformer enum to the corresponding type-fest property transformation (shallow).
|
|
18
|
-
* Capital and Slug cases don't have type-fest equivalents, so they preserve the original type.
|
|
19
|
-
*/
|
|
20
|
-
type TransformProperties<
|
|
21
|
-
T,
|
|
22
|
-
C extends CaseTransformer,
|
|
23
|
-
> = C extends CaseTransformer.Camel
|
|
24
|
-
? CamelCasedProperties<T>
|
|
25
|
-
: C extends CaseTransformer.Snake
|
|
26
|
-
? SnakeCasedProperties<T>
|
|
27
|
-
: C extends CaseTransformer.Pascal
|
|
28
|
-
? PascalCasedProperties<T>
|
|
29
|
-
: C extends CaseTransformer.Param
|
|
30
|
-
? KebabCasedProperties<T>
|
|
31
|
-
: T
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Maps CaseTransformer enum to the corresponding type-fest deep property transformation.
|
|
35
|
-
* Capital and Slug cases don't have type-fest equivalents, so they preserve the original type.
|
|
36
|
-
*/
|
|
37
|
-
type TransformPropertiesDeep<
|
|
38
|
-
T,
|
|
39
|
-
C extends CaseTransformer,
|
|
40
|
-
> = C extends CaseTransformer.Camel
|
|
41
|
-
? CamelCasedPropertiesDeep<T>
|
|
42
|
-
: C extends CaseTransformer.Snake
|
|
43
|
-
? SnakeCasedPropertiesDeep<T>
|
|
44
|
-
: C extends CaseTransformer.Pascal
|
|
45
|
-
? PascalCasedPropertiesDeep<T>
|
|
46
|
-
: C extends CaseTransformer.Param
|
|
47
|
-
? KebabCasedPropertiesDeep<T>
|
|
48
|
-
: T
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Transforms object keys based on the specified case transformer.
|
|
52
|
-
* - Arrays: recursively applies transformation to each element
|
|
53
|
-
* - Objects: applies property transformation (shallow by default, deep if Deep=true)
|
|
54
|
-
* - Primitives: returns as-is
|
|
55
|
-
*/
|
|
56
|
-
export type KeysCaseTransformed<
|
|
57
|
-
T,
|
|
58
|
-
C extends CaseTransformer,
|
|
59
|
-
Deep extends boolean = false,
|
|
60
|
-
> = Deep extends true
|
|
61
|
-
? T extends readonly (infer U)[]
|
|
62
|
-
? KeysCaseTransformed<U, C, true>[]
|
|
63
|
-
: T extends object
|
|
64
|
-
? TransformPropertiesDeep<T, C>
|
|
65
|
-
: T
|
|
66
|
-
: T extends readonly (infer U)[]
|
|
67
|
-
? KeysCaseTransformed<U, C>[]
|
|
68
|
-
: T extends object
|
|
69
|
-
? TransformProperties<T, C>
|
|
70
|
-
: T
|
|
71
|
-
|
|
72
|
-
export interface KeysCaseTransformerOptions {
|
|
73
|
-
deep?: boolean
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// Overload: deep transformation
|
|
77
|
-
export function keysCaseTransformer<T, C extends CaseTransformer>(
|
|
78
|
-
obj: T,
|
|
79
|
-
toCase: C,
|
|
80
|
-
options: { deep: true },
|
|
81
|
-
): KeysCaseTransformed<T, C, true>
|
|
82
|
-
|
|
83
|
-
// Overload: shallow transformation (default)
|
|
84
|
-
export function keysCaseTransformer<T, C extends CaseTransformer>(
|
|
85
|
-
obj: T,
|
|
86
|
-
toCase: C,
|
|
87
|
-
options?: { deep?: false },
|
|
88
|
-
): KeysCaseTransformed<T, C>
|
|
89
|
-
|
|
90
|
-
// Implementation
|
|
91
|
-
export function keysCaseTransformer<T, C extends CaseTransformer>(
|
|
92
|
-
obj: T,
|
|
93
|
-
toCase: C,
|
|
94
|
-
options?: KeysCaseTransformerOptions,
|
|
95
|
-
): KeysCaseTransformed<T, C, boolean> {
|
|
96
|
-
if (Array.isArray(obj)) {
|
|
97
|
-
return obj.map(item =>
|
|
98
|
-
keysCaseTransformer(item, toCase, options as { deep: true }),
|
|
99
|
-
) as KeysCaseTransformed<T, C, boolean>
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
if (isObject(obj)) {
|
|
103
|
-
const transformed = mapKeys(obj, key => changeCase(key, toCase))
|
|
104
|
-
if (options?.deep) {
|
|
105
|
-
// Recursively transform nested values
|
|
106
|
-
return Object.fromEntries(
|
|
107
|
-
Object.entries(transformed).map(([k, v]) => [
|
|
108
|
-
k,
|
|
109
|
-
keysCaseTransformer(v, toCase, options as { deep: true }),
|
|
110
|
-
]),
|
|
111
|
-
) as KeysCaseTransformed<T, C, boolean>
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
return transformed as KeysCaseTransformed<T, C, boolean>
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
return obj as KeysCaseTransformed<T, C, boolean>
|
|
118
|
-
}
|
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
import { type ZodTypeAny, z } from 'zod'
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
CASE_TRANSFORMERS_MAPPING,
|
|
5
|
-
type CaseTransformer,
|
|
6
|
-
} from './case-transformers.ts'
|
|
7
|
-
|
|
8
|
-
/* eslint-disable no-underscore-dangle, max-statements */
|
|
9
|
-
|
|
10
|
-
function transformSchemaKeysWithTransformer(
|
|
11
|
-
schema: ZodTypeAny,
|
|
12
|
-
transformer: (str: string) => string,
|
|
13
|
-
): ZodTypeAny {
|
|
14
|
-
let result: ZodTypeAny = schema
|
|
15
|
-
|
|
16
|
-
// Handle ZodObject
|
|
17
|
-
if (schema instanceof z.ZodObject) {
|
|
18
|
-
const shape = schema._def.shape()
|
|
19
|
-
const transformedShape: Record<string, ZodTypeAny> = {}
|
|
20
|
-
|
|
21
|
-
for (const key in shape) {
|
|
22
|
-
if (Object.hasOwn(shape, key)) {
|
|
23
|
-
const transformedKey = transformer(key)
|
|
24
|
-
transformedShape[transformedKey] = transformSchemaKeysWithTransformer(
|
|
25
|
-
shape[key],
|
|
26
|
-
transformer,
|
|
27
|
-
)
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
result = z.object(transformedShape) as ZodTypeAny
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// Handle ZodArray
|
|
35
|
-
else if (schema instanceof z.ZodArray) {
|
|
36
|
-
const { type: elementSchema } = schema._def
|
|
37
|
-
result = z.array(
|
|
38
|
-
transformSchemaKeysWithTransformer(elementSchema, transformer),
|
|
39
|
-
)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// Handle ZodOptional
|
|
43
|
-
else if (schema instanceof z.ZodOptional) {
|
|
44
|
-
const { innerType: innerSchema } = schema._def
|
|
45
|
-
result = transformSchemaKeysWithTransformer(
|
|
46
|
-
innerSchema,
|
|
47
|
-
transformer,
|
|
48
|
-
).optional()
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// Handle ZodNullable
|
|
52
|
-
else if (schema instanceof z.ZodNullable) {
|
|
53
|
-
const { innerType: innerSchema } = schema._def
|
|
54
|
-
result = transformSchemaKeysWithTransformer(
|
|
55
|
-
innerSchema,
|
|
56
|
-
transformer,
|
|
57
|
-
).nullable()
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// Handle ZodDefault
|
|
61
|
-
else if (schema instanceof z.ZodDefault) {
|
|
62
|
-
const { defaultValue, innerType: innerSchema } = schema._def
|
|
63
|
-
result = transformSchemaKeysWithTransformer(
|
|
64
|
-
innerSchema,
|
|
65
|
-
transformer,
|
|
66
|
-
).default(defaultValue())
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// Handle ZodEffects (includes .refine(), .transform(), etc.)
|
|
70
|
-
else if (schema instanceof z.ZodEffects) {
|
|
71
|
-
const { schema: innerSchema } = schema._def
|
|
72
|
-
const transformedInner = transformSchemaKeysWithTransformer(
|
|
73
|
-
innerSchema,
|
|
74
|
-
transformer,
|
|
75
|
-
)
|
|
76
|
-
|
|
77
|
-
// We need to reconstruct the effects
|
|
78
|
-
// This is a simplified version - effects are not transformed, just passed through
|
|
79
|
-
result = transformedInner
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// Handle ZodUnion
|
|
83
|
-
else if (schema instanceof z.ZodUnion) {
|
|
84
|
-
const { options } = schema._def
|
|
85
|
-
const transformedOptions = options.map((option: ZodTypeAny) =>
|
|
86
|
-
transformSchemaKeysWithTransformer(option, transformer),
|
|
87
|
-
)
|
|
88
|
-
result = z.union(
|
|
89
|
-
transformedOptions as [ZodTypeAny, ZodTypeAny, ...ZodTypeAny[]],
|
|
90
|
-
)
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// Handle ZodIntersection
|
|
94
|
-
else if (schema instanceof z.ZodIntersection) {
|
|
95
|
-
const { left, right } = schema._def
|
|
96
|
-
result = z.intersection(
|
|
97
|
-
transformSchemaKeysWithTransformer(left, transformer),
|
|
98
|
-
transformSchemaKeysWithTransformer(right, transformer),
|
|
99
|
-
)
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// Propagate openapi metadata
|
|
103
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
104
|
-
const { openapi } = schema._def as any
|
|
105
|
-
if (openapi && result !== schema) {
|
|
106
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
107
|
-
;(result._def as any).openapi = openapi
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
return result
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Transforms all keys in a Zod schema from one case to another (e.g., snake_case to camelCase).
|
|
115
|
-
* This function recursively transforms all nested schemas as well.
|
|
116
|
-
*
|
|
117
|
-
* @param schema - The Zod schema to transform
|
|
118
|
-
* @param toCase - The target case (e.g., CaseTransformer.Camel)
|
|
119
|
-
* @returns A new Zod schema with transformed keys
|
|
120
|
-
*
|
|
121
|
-
* @example
|
|
122
|
-
* ```ts
|
|
123
|
-
* const snakeSchema = z.object({
|
|
124
|
-
* first_name: z.string(),
|
|
125
|
-
* last_name: z.string(),
|
|
126
|
-
* })
|
|
127
|
-
*
|
|
128
|
-
* const camelSchema = transformSchemaKeys(snakeSchema, CaseTransformer.Camel)
|
|
129
|
-
* // Results in: { firstName: z.string(), lastName: z.string() }
|
|
130
|
-
* ```
|
|
131
|
-
*/
|
|
132
|
-
export function transformSchemaKeys<T extends ZodTypeAny>(
|
|
133
|
-
schema: T,
|
|
134
|
-
toCase: CaseTransformer,
|
|
135
|
-
): T {
|
|
136
|
-
const transformer = CASE_TRANSFORMERS_MAPPING[toCase]
|
|
137
|
-
|
|
138
|
-
if (!transformer) {
|
|
139
|
-
throw new Error(`Unsupported case transformer: ${toCase}`)
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
return transformSchemaKeysWithTransformer(schema, transformer) as T
|
|
143
|
-
}
|