@superbright/indexeddb-orm 1.0.15 → 1.0.16
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.
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d="//web.inresiapp.com",
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d="//web.inresiapp.com",f="/placeholder.jpg",h=t=>t?t.startsWith("?")?t:`?${t}`:"",s=t=>{if(typeof t=="string")return t;if(typeof t=="number"||typeof t=="boolean")return String(t)},A=(t,r)=>s(r.propertySlug)??s(r.property_slug)??t,S=(t,r,e=d)=>`${e}/${r}/unit/${t}/explore`,a=(t,r=f,e)=>{const l=(t==null?void 0:t.imageSignature)??e;return!(t!=null&&t.CFURL)||!(t!=null&&t.name)||!l?r:`${t.CFURL}${t.name}${h(l)}`};function U(t){return{data:t}}function v(t,r,e){var i,b;e==null||e.origin;const l=(e==null?void 0:e.placeholderImage)??f,o=((i=t.hits)==null?void 0:i.map(m=>{var y,p;const n=m._source??{},_=typeof n.name=="string"?n.name:typeof n.title=="string"?n.title:"";s(n.slug)??s(n.unit_slug);const g=s(n.propertySlug)??s(n.property_slug)??A(r,n)??r,c={...n,name:_,imageUrl:a(n.image,l,t.imageSignature),secondaryImageUrl:a((y=n.additionalImages)==null?void 0:y[0],l,t.imageSignature),tertiaryImageUrl:a((p=n.additionalImages)==null?void 0:p[1],l,t.imageSignature)};return g&&!c.propertySlug&&(c.propertySlug=g),c}))??[];return{total:((b=t.total)==null?void 0:b.value)??o.length,maxScore:t.max_score??null,type:t.type??"units",hits:o}}const I={asap:"ASAP",next_month:"Next Month","2_3_months":"2-3 Months",all:"Just Browsing"},u={0:"Studio",1:"1 Bed",2:"2 Bed",3:"3+ Bed"},E=new Set(Object.values(u)),L=t=>{if(!t||t.length===0)return;const r=new Set;for(const e of t){if(typeof e=="number"){const o=u[e];o&&r.add(o);continue}const l=e.split(",").map(o=>o.trim());for(const o of l){const i=Number.parseInt(o,10);!Number.isNaN(i)&&u[i]?r.add(u[i]):E.has(o)&&r.add(o)}}return r.size>0?Array.from(r):void 0},F=t=>({date_availability:t.date_availability&&t.date_availability.length>0?t.date_availability.map(e=>I[e]??e):void 0,qty_bedrooms:L(t.qty_bedrooms),base_price:t.base_price??void 0,highlights:t.highlights??[]});exports.DEFAULT_PLACEHOLDER_IMAGE=f;exports.DEFAULT_WEB_ORIGIN=d;exports.buildExploreUrl=S;exports.buildImageUrl=a;exports.transformUnitsApiResponse=U;exports.transformUnitsApiResponseToClient=v;exports.transformUnitsApiResponseToClientFilters=F;
|
|
2
2
|
//# sourceMappingURL=transformers.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transformers.cjs","sources":["../../../src/features/units/transformers.ts"],"sourcesContent":["export const DEFAULT_WEB_ORIGIN = \"//web.inresiapp.com\";\nexport const DEFAULT_PLACEHOLDER_IMAGE = \"/placeholder.jpg\";\n\nexport interface UnitImageApiResponse {\n CFURL?: string;\n name?: string;\n signature?: string;\n}\n\nexport interface UnitSourceApiResponse extends Record<string, unknown> {\n id?: number | string;\n name?: string;\n title?: string;\n slug?: string;\n base_price?: number;\n qty_bedrooms?: number | string;\n qty_bathrooms?: number | string;\n totalSqFt?: number;\n dim_sq_ft?: number | string;\n amenities?: unknown;\n highlights?: unknown;\n date_availability?: string | Date | null;\n unitSetAvailableOn?: string | Date | null;\n image?: UnitImageApiResponse;\n additionalImages?: UnitImageApiResponse[];\n}\n\nexport interface UnitHitApiResponse<\n Source extends Record<string, unknown> = UnitSourceApiResponse,\n> {\n _index?: string;\n _id?: string;\n _score?: number;\n _source?: Source;\n}\n\nexport interface UnitsTotalInfo {\n value: number;\n relation?: string;\n}\n\nexport interface UnitsDataApiResponse<\n Source extends Record<string, unknown> = UnitSourceApiResponse,\n> {\n total?: UnitsTotalInfo;\n max_score?: number | null;\n hits?: UnitHitApiResponse<Source>[];\n type?: string;\n}\n\nexport interface UnitsApiResponse<\n Source extends Record<string, unknown> = UnitSourceApiResponse,\n> {\n data: UnitsDataApiResponse<Source>;\n}\n\nexport type TransformedUnit<\n Source extends Record<string, unknown> = UnitSourceApiResponse,\n> = Source & {\n name: string;\n imageUrl: string;\n secondaryImageUrl?: string;\n tertiaryImageUrl?: string;\n};\n\nexport interface UnitsClientList<\n Source extends Record<string, unknown> = UnitSourceApiResponse,\n> {\n total: number;\n maxScore: number | null;\n type: string;\n hits: TransformedUnit<Source>[];\n}\n\nexport interface TransformUnitsOptions {\n origin?: string;\n placeholderImage?: string;\n}\n\nconst normalizeSignature = (signature?: string): string => {\n if (!signature) return \"\";\n return signature.startsWith(\"?\") ? signature : `?${signature}`;\n};\n\nconst coerceString = (value: unknown): string | undefined => {\n if (typeof value === \"string\") return value;\n if (typeof value === \"number\" || typeof value === \"boolean\") {\n return String(value);\n }\n return undefined;\n};\n\nconst propertySlugFallback = (\n defaultSlug: string,\n source: UnitSourceApiResponse,\n): string | undefined => {\n const slug =\n coerceString((source as any).propertySlug) ??\n coerceString((source as any).property_slug);\n return slug ?? defaultSlug;\n};\n\nexport const buildExploreUrl = (\n unitSlug: string,\n propertySlug: string,\n origin = DEFAULT_WEB_ORIGIN,\n): string => `${origin}/${propertySlug}/unit/${unitSlug}/explore`;\n\nexport const buildImageUrl = (\n image?: UnitImageApiResponse,\n placeholder = DEFAULT_PLACEHOLDER_IMAGE,\n): string => {\n if (!image?.CFURL || !image?.name || !image?.signature) return placeholder;\n return `${image.CFURL}${image.name}${normalizeSignature(image.signature)}`;\n};\n\nexport function transformUnitsApiResponse<\n Source extends Record<string, unknown> = UnitSourceApiResponse,\n>(apiResponse: UnitsDataApiResponse<Source>): UnitsApiResponse<Source> {\n return { data: apiResponse };\n}\n\nexport function transformUnitsApiResponseToClient<\n Source extends Record<string, unknown> = UnitSourceApiResponse,\n>(\n apiResponse: UnitsDataApiResponse<Source>,\n propertySlug: string,\n options?: TransformUnitsOptions,\n): UnitsClientList<Source> {\n const origin = options?.origin ?? DEFAULT_WEB_ORIGIN;\n const placeholderImage = options?.placeholderImage ?? DEFAULT_PLACEHOLDER_IMAGE;\n\n const hits =\n apiResponse.hits?.map((hit) => {\n const source = (hit._source ?? {}) as Source & UnitSourceApiResponse;\n const unit_name =\n typeof source.name === \"string\"\n ? source.name\n : typeof source.title === \"string\"\n ? source.title\n : \"\";\n\n const slugCandidate =\n coerceString(source.slug) ?? coerceString((source as any).unit_slug) ?? \"\";\n const resolvedPropertySlug =\n coerceString((source as any).propertySlug) ??\n coerceString((source as any).property_slug) ??\n propertySlugFallback(propertySlug, source) ??\n propertySlug;\n\n const normalized: TransformedUnit<Source> = {\n ...(source as Source),\n name: unit_name,\n // slug: buildExploreUrl(slugCandidate, resolvedPropertySlug ?? \"\", origin),\n imageUrl: buildImageUrl(source.image, placeholderImage),\n secondaryImageUrl: buildImageUrl(source.additionalImages?.[0], placeholderImage),\n tertiaryImageUrl: buildImageUrl(source.additionalImages?.[1], placeholderImage),\n };\n\n\n\n if (\n resolvedPropertySlug &&\n !(normalized as Record<string, unknown>).propertySlug\n ) {\n (normalized as Record<string, unknown>).propertySlug = resolvedPropertySlug;\n }\n\n return normalized;\n }) ?? [];\n return {\n total: apiResponse.total?.value ?? hits.length,\n maxScore: apiResponse.max_score ?? null,\n type: apiResponse.type ?? \"units\",\n hits,\n };\n}\n\nexport interface UnitsFilterParams {\n date_availability?: string[];\n qty_bedrooms?: (number | string)[];\n base_price?: number | null;\n highlights?: string[];\n}\n\nexport interface UnitsClientFilters {\n date_availability?: string[];\n qty_bedrooms?: string[];\n base_price?: number;\n highlights: string[];\n}\n\nconst reverseAvailabilityMap: Record<string, string> = {\n asap: \"ASAP\",\n next_month: \"Next Month\",\n \"2_3_months\": \"2-3 Months\",\n all: \"Just Browsing\",\n};\n\nconst reverseBedroomMap: Record<number, string> = {\n 0: \"Studio\",\n 1: \"1 Bed\",\n 2: \"2 Bed\",\n 3: \"3+ Bed\",\n};\n\nconst bedroomLabels = new Set(Object.values(reverseBedroomMap));\n\nconst normalizeBedrooms = (\n bedrooms?: (number | string)[],\n): string[] | undefined => {\n if (!bedrooms || bedrooms.length === 0) return undefined;\n\n const result = new Set<string>();\n\n for (const bedroom of bedrooms) {\n if (typeof bedroom === \"number\") {\n const label = reverseBedroomMap[bedroom];\n if (label) result.add(label);\n continue;\n }\n\n const values = bedroom.split(\",\").map((v) => v.trim());\n\n for (const value of values) {\n const parsed = Number.parseInt(value, 10);\n if (!Number.isNaN(parsed) && reverseBedroomMap[parsed]) {\n result.add(reverseBedroomMap[parsed]);\n } else if (bedroomLabels.has(value)) {\n result.add(value);\n }\n }\n }\n\n return result.size > 0 ? Array.from(result) : undefined;\n};\n\nexport const transformUnitsApiResponseToClientFilters = (\n params: UnitsFilterParams,\n): UnitsClientFilters => {\n const dateAvailabilityLabels =\n params.date_availability && params.date_availability.length > 0\n ? params.date_availability.map(\n (value) => reverseAvailabilityMap[value] ?? value,\n )\n : undefined;\n\n return {\n date_availability: dateAvailabilityLabels,\n qty_bedrooms: normalizeBedrooms(params.qty_bedrooms),\n base_price: params.base_price ?? undefined,\n highlights: params.highlights ?? [],\n };\n};\n"],"names":["DEFAULT_WEB_ORIGIN","DEFAULT_PLACEHOLDER_IMAGE","normalizeSignature","signature","coerceString","value","propertySlugFallback","defaultSlug","source","buildExploreUrl","unitSlug","propertySlug","origin","buildImageUrl","image","placeholder","transformUnitsApiResponse","apiResponse","transformUnitsApiResponseToClient","options","placeholderImage","hits","_a","hit","unit_name","resolvedPropertySlug","normalized","_b","reverseAvailabilityMap","reverseBedroomMap","bedroomLabels","normalizeBedrooms","bedrooms","result","bedroom","label","values","v","parsed","transformUnitsApiResponseToClientFilters","params"],"mappings":"gFAAO,MAAMA,EAAqB,sBACrBC,EAA4B,mBA8EnCC,EAAsBC,GACrBA,EACEA,EAAU,WAAW,GAAG,EAAIA,EAAY,IAAIA,CAAS,GADrC,GAInBC,EAAgB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J,aAAc0B,EAAkBS,EAAO,YAAY,EACnD,WAAYA,EAAO,YAAc,OACjC,WAAYA,EAAO,YAAc,CAAA,CAAC"}
|
|
1
|
+
{"version":3,"file":"transformers.cjs","sources":["../../../src/features/units/transformers.ts"],"sourcesContent":["export const DEFAULT_WEB_ORIGIN = \"//web.inresiapp.com\";\nexport const DEFAULT_PLACEHOLDER_IMAGE = \"/placeholder.jpg\";\n\nexport interface UnitImageApiResponse {\n CFURL?: string;\n name?: string;\n imageSignature?: string;\n}\n\nexport interface UnitSourceApiResponse extends Record<string, unknown> {\n id?: number | string;\n name?: string;\n title?: string;\n slug?: string;\n base_price?: number;\n qty_bedrooms?: number | string;\n qty_bathrooms?: number | string;\n totalSqFt?: number;\n dim_sq_ft?: number | string;\n amenities?: unknown;\n highlights?: unknown;\n date_availability?: string | Date | null;\n unitSetAvailableOn?: string | Date | null;\n image: UnitImageApiResponse;\n additionalImages?: UnitImageApiResponse[];\n}\n\nexport interface UnitHitApiResponse<\n Source extends Record<string, unknown> = UnitSourceApiResponse,\n> {\n _index?: string;\n _id?: string;\n _score?: number;\n _source?: Source;\n}\n\nexport interface UnitsTotalInfo {\n value: number;\n relation?: string;\n}\n\nexport interface UnitsDataApiResponse<\n Source extends Record<string, unknown> = UnitSourceApiResponse,\n> {\n total?: UnitsTotalInfo;\n max_score?: number | null;\n hits?: UnitHitApiResponse<Source>[];\n type?: string;\n imageSignature?: string;\n}\n\nexport interface UnitsApiResponse<\n Source extends Record<string, unknown> = UnitSourceApiResponse,\n> {\n data: UnitsDataApiResponse<Source>;\n}\n\nexport type TransformedUnit<\n Source extends Record<string, unknown> = UnitSourceApiResponse,\n> = Source & {\n name: string;\n imageUrl: string;\n secondaryImageUrl?: string;\n tertiaryImageUrl?: string;\n};\n\nexport interface UnitsClientList<\n Source extends Record<string, unknown> = UnitSourceApiResponse,\n> {\n total: number;\n maxScore: number | null;\n type: string;\n hits: TransformedUnit<Source>[];\n}\n\nexport interface TransformUnitsOptions {\n origin?: string;\n placeholderImage?: string;\n}\n\nconst normalizeSignature = (signature?: string): string => {\n if (!signature) return \"\";\n return signature.startsWith(\"?\") ? signature : `?${signature}`;\n};\n\nconst coerceString = (value: unknown): string | undefined => {\n if (typeof value === \"string\") return value;\n if (typeof value === \"number\" || typeof value === \"boolean\") {\n return String(value);\n }\n return undefined;\n};\n\nconst propertySlugFallback = (\n defaultSlug: string,\n source: UnitSourceApiResponse,\n): string | undefined => {\n const slug =\n coerceString((source as any).propertySlug) ??\n coerceString((source as any).property_slug);\n return slug ?? defaultSlug;\n};\n\nexport const buildExploreUrl = (\n unitSlug: string,\n propertySlug: string,\n origin = DEFAULT_WEB_ORIGIN,\n): string => `${origin}/${propertySlug}/unit/${unitSlug}/explore`;\n\nexport const buildImageUrl = (\n image: UnitImageApiResponse | undefined,\n placeholder = DEFAULT_PLACEHOLDER_IMAGE,\n fallbackSignature?: string,\n): string => {\n const signature = image?.imageSignature ?? fallbackSignature;\n if (!image?.CFURL || !image?.name || !signature) return placeholder;\n return `${image.CFURL}${image.name}${normalizeSignature(signature)}`;\n};\n\nexport function transformUnitsApiResponse<\n Source extends Record<string, unknown> = UnitSourceApiResponse,\n>(apiResponse: UnitsDataApiResponse<Source>): UnitsApiResponse<Source> {\n return { data: apiResponse };\n}\n\nexport function transformUnitsApiResponseToClient<\n Source extends Record<string, unknown> = UnitSourceApiResponse,\n>(\n apiResponse: UnitsDataApiResponse<Source>,\n propertySlug: string,\n options?: TransformUnitsOptions,\n): UnitsClientList<Source> {\n const origin = options?.origin ?? DEFAULT_WEB_ORIGIN;\n const placeholderImage = options?.placeholderImage ?? DEFAULT_PLACEHOLDER_IMAGE;\n\n const hits =\n apiResponse.hits?.map((hit) => {\n const source = (hit._source ?? {}) as Source & UnitSourceApiResponse;\n const unit_name =\n typeof source.name === \"string\"\n ? source.name\n : typeof source.title === \"string\"\n ? source.title\n : \"\";\n\n const slugCandidate =\n coerceString(source.slug) ?? coerceString((source as any).unit_slug) ?? \"\";\n const resolvedPropertySlug =\n coerceString((source as any).propertySlug) ??\n coerceString((source as any).property_slug) ??\n propertySlugFallback(propertySlug, source) ??\n propertySlug;\n\n const normalized: TransformedUnit<Source> = {\n ...(source as Source),\n name: unit_name,\n imageUrl: buildImageUrl(source.image, placeholderImage, apiResponse.imageSignature),\n secondaryImageUrl: buildImageUrl(source.additionalImages?.[0], placeholderImage, apiResponse.imageSignature),\n tertiaryImageUrl: buildImageUrl(source.additionalImages?.[1], placeholderImage, apiResponse.imageSignature),\n };\n\n\n\n if (\n resolvedPropertySlug &&\n !(normalized as Record<string, unknown>).propertySlug\n ) {\n (normalized as Record<string, unknown>).propertySlug = resolvedPropertySlug;\n }\n\n return normalized;\n }) ?? [];\n return {\n total: apiResponse.total?.value ?? hits.length,\n maxScore: apiResponse.max_score ?? null,\n type: apiResponse.type ?? \"units\",\n hits,\n };\n}\n\nexport interface UnitsFilterParams {\n date_availability?: string[];\n qty_bedrooms?: (number | string)[];\n base_price?: number | null;\n highlights?: string[];\n}\n\nexport interface UnitsClientFilters {\n date_availability?: string[];\n qty_bedrooms?: string[];\n base_price?: number;\n highlights: string[];\n}\n\nconst reverseAvailabilityMap: Record<string, string> = {\n asap: \"ASAP\",\n next_month: \"Next Month\",\n \"2_3_months\": \"2-3 Months\",\n all: \"Just Browsing\",\n};\n\nconst reverseBedroomMap: Record<number, string> = {\n 0: \"Studio\",\n 1: \"1 Bed\",\n 2: \"2 Bed\",\n 3: \"3+ Bed\",\n};\n\nconst bedroomLabels = new Set(Object.values(reverseBedroomMap));\n\nconst normalizeBedrooms = (\n bedrooms?: (number | string)[],\n): string[] | undefined => {\n if (!bedrooms || bedrooms.length === 0) return undefined;\n\n const result = new Set<string>();\n\n for (const bedroom of bedrooms) {\n if (typeof bedroom === \"number\") {\n const label = reverseBedroomMap[bedroom];\n if (label) result.add(label);\n continue;\n }\n\n const values = bedroom.split(\",\").map((v) => v.trim());\n\n for (const value of values) {\n const parsed = Number.parseInt(value, 10);\n if (!Number.isNaN(parsed) && reverseBedroomMap[parsed]) {\n result.add(reverseBedroomMap[parsed]);\n } else if (bedroomLabels.has(value)) {\n result.add(value);\n }\n }\n }\n\n return result.size > 0 ? Array.from(result) : undefined;\n};\n\nexport const transformUnitsApiResponseToClientFilters = (\n params: UnitsFilterParams,\n): UnitsClientFilters => {\n const dateAvailabilityLabels =\n params.date_availability && params.date_availability.length > 0\n ? params.date_availability.map(\n (value) => reverseAvailabilityMap[value] ?? value,\n )\n : undefined;\n\n return {\n date_availability: dateAvailabilityLabels,\n qty_bedrooms: normalizeBedrooms(params.qty_bedrooms),\n base_price: params.base_price ?? undefined,\n highlights: params.highlights ?? [],\n };\n};\n"],"names":["DEFAULT_WEB_ORIGIN","DEFAULT_PLACEHOLDER_IMAGE","normalizeSignature","signature","coerceString","value","propertySlugFallback","defaultSlug","source","buildExploreUrl","unitSlug","propertySlug","origin","buildImageUrl","image","placeholder","fallbackSignature","transformUnitsApiResponse","apiResponse","transformUnitsApiResponseToClient","options","placeholderImage","hits","_a","hit","unit_name","resolvedPropertySlug","normalized","_b","reverseAvailabilityMap","reverseBedroomMap","bedroomLabels","normalizeBedrooms","bedrooms","result","bedroom","label","values","v","parsed","transformUnitsApiResponseToClientFilters","params"],"mappings":"gFAAO,MAAMA,EAAqB,sBACrBC,EAA4B,mBA+EnCC,EAAsBC,GACrBA,EACEA,EAAU,WAAW,GAAG,EAAIA,EAAY,IAAIA,CAAS,GADrC,GAInBC,EAAgBC,GAAuC,CAC3D,GAAI,OAAOA,GAAU,SAAU,OAAOA,EACtC,GAAI,OAAOA,GAAU,UAAY,OAAOA,GAAU,UAChD,OAAO,OAAOA,CAAK,CAGvB,EAEMC,EAAuB,CAC3BC,EACAC,IAGEJ,EAAcI,EAAe,YAAY,GACzCJ,EAAcI,EAAe,aAAa,GAC7BD,EAGJE,EAAkB,CAC7BC,EACAC,EACAC,EAASZ,IACE,GAAGY,CAAM,IAAID,CAAY,SAASD,CAAQ,WAE1CG,EAAgB,CAC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;
|
|
6
|
-
|
|
6
|
+
imageSignature?: string;
|
|
7
7
|
}
|
|
8
8
|
export interface UnitSourceApiResponse extends Record<string, unknown> {
|
|
9
9
|
id?: number | string;
|
|
@@ -19,7 +19,7 @@ export interface UnitSourceApiResponse extends Record<string, unknown> {
|
|
|
19
19
|
highlights?: unknown;
|
|
20
20
|
date_availability?: string | Date | null;
|
|
21
21
|
unitSetAvailableOn?: string | Date | null;
|
|
22
|
-
image
|
|
22
|
+
image: UnitImageApiResponse;
|
|
23
23
|
additionalImages?: UnitImageApiResponse[];
|
|
24
24
|
}
|
|
25
25
|
export interface UnitHitApiResponse<Source extends Record<string, unknown> = UnitSourceApiResponse> {
|
|
@@ -37,6 +37,7 @@ export interface UnitsDataApiResponse<Source extends Record<string, unknown> = U
|
|
|
37
37
|
max_score?: number | null;
|
|
38
38
|
hits?: UnitHitApiResponse<Source>[];
|
|
39
39
|
type?: string;
|
|
40
|
+
imageSignature?: string;
|
|
40
41
|
}
|
|
41
42
|
export interface UnitsApiResponse<Source extends Record<string, unknown> = UnitSourceApiResponse> {
|
|
42
43
|
data: UnitsDataApiResponse<Source>;
|
|
@@ -58,7 +59,7 @@ export interface TransformUnitsOptions {
|
|
|
58
59
|
placeholderImage?: string;
|
|
59
60
|
}
|
|
60
61
|
export declare const buildExploreUrl: (unitSlug: string, propertySlug: string, origin?: string) => string;
|
|
61
|
-
export declare const buildImageUrl: (image
|
|
62
|
+
export declare const buildImageUrl: (image: UnitImageApiResponse | undefined, placeholder?: string, fallbackSignature?: string) => string;
|
|
62
63
|
export declare function transformUnitsApiResponse<Source extends Record<string, unknown> = UnitSourceApiResponse>(apiResponse: UnitsDataApiResponse<Source>): UnitsApiResponse<Source>;
|
|
63
64
|
export declare function transformUnitsApiResponseToClient<Source extends Record<string, unknown> = UnitSourceApiResponse>(apiResponse: UnitsDataApiResponse<Source>, propertySlug: string, options?: TransformUnitsOptions): UnitsClientList<Source>;
|
|
64
65
|
export interface UnitsFilterParams {
|
|
@@ -1,27 +1,29 @@
|
|
|
1
|
-
const b = "//web.inresiapp.com",
|
|
1
|
+
const b = "//web.inresiapp.com", m = "/placeholder.jpg", h = (t) => t ? t.startsWith("?") ? t : `?${t}` : "", a = (t) => {
|
|
2
2
|
if (typeof t == "string") return t;
|
|
3
3
|
if (typeof t == "number" || typeof t == "boolean")
|
|
4
4
|
return String(t);
|
|
5
|
-
},
|
|
5
|
+
}, S = (t, r) => a(r.propertySlug) ?? a(r.property_slug) ?? t, I = (t, r, e = b) => `${e}/${r}/unit/${t}/explore`, c = (t, r = m, e) => {
|
|
6
|
+
const l = (t == null ? void 0 : t.imageSignature) ?? e;
|
|
7
|
+
return !(t != null && t.CFURL) || !(t != null && t.name) || !l ? r : `${t.CFURL}${t.name}${h(l)}`;
|
|
8
|
+
};
|
|
6
9
|
function L(t) {
|
|
7
10
|
return { data: t };
|
|
8
11
|
}
|
|
9
|
-
function x(t,
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
var
|
|
14
|
-
const n =
|
|
15
|
-
|
|
16
|
-
const
|
|
12
|
+
function x(t, r, e) {
|
|
13
|
+
var i, d;
|
|
14
|
+
e == null || e.origin;
|
|
15
|
+
const l = (e == null ? void 0 : e.placeholderImage) ?? m, o = ((i = t.hits) == null ? void 0 : i.map((p) => {
|
|
16
|
+
var f, g;
|
|
17
|
+
const n = p._source ?? {}, _ = typeof n.name == "string" ? n.name : typeof n.title == "string" ? n.title : "";
|
|
18
|
+
a(n.slug) ?? a(n.unit_slug);
|
|
19
|
+
const y = a(n.propertySlug) ?? a(n.property_slug) ?? S(r, n) ?? r, u = {
|
|
17
20
|
...n,
|
|
18
|
-
name:
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
tertiaryImageUrl: u((f = n.additionalImages) == null ? void 0 : f[1], i)
|
|
21
|
+
name: _,
|
|
22
|
+
imageUrl: c(n.image, l, t.imageSignature),
|
|
23
|
+
secondaryImageUrl: c((f = n.additionalImages) == null ? void 0 : f[0], l, t.imageSignature),
|
|
24
|
+
tertiaryImageUrl: c((g = n.additionalImages) == null ? void 0 : g[1], l, t.imageSignature)
|
|
23
25
|
};
|
|
24
|
-
return
|
|
26
|
+
return y && !u.propertySlug && (u.propertySlug = y), u;
|
|
25
27
|
})) ?? [];
|
|
26
28
|
return {
|
|
27
29
|
total: ((d = t.total) == null ? void 0 : d.value) ?? o.length,
|
|
@@ -30,45 +32,45 @@ function x(t, e, r) {
|
|
|
30
32
|
hits: o
|
|
31
33
|
};
|
|
32
34
|
}
|
|
33
|
-
const
|
|
35
|
+
const v = {
|
|
34
36
|
asap: "ASAP",
|
|
35
37
|
next_month: "Next Month",
|
|
36
38
|
"2_3_months": "2-3 Months",
|
|
37
39
|
all: "Just Browsing"
|
|
38
|
-
},
|
|
40
|
+
}, s = {
|
|
39
41
|
0: "Studio",
|
|
40
42
|
1: "1 Bed",
|
|
41
43
|
2: "2 Bed",
|
|
42
44
|
3: "3+ Bed"
|
|
43
|
-
},
|
|
45
|
+
}, A = new Set(Object.values(s)), U = (t) => {
|
|
44
46
|
if (!t || t.length === 0) return;
|
|
45
|
-
const
|
|
46
|
-
for (const
|
|
47
|
-
if (typeof
|
|
48
|
-
const o =
|
|
49
|
-
o &&
|
|
47
|
+
const r = /* @__PURE__ */ new Set();
|
|
48
|
+
for (const e of t) {
|
|
49
|
+
if (typeof e == "number") {
|
|
50
|
+
const o = s[e];
|
|
51
|
+
o && r.add(o);
|
|
50
52
|
continue;
|
|
51
53
|
}
|
|
52
|
-
const
|
|
53
|
-
for (const o of
|
|
54
|
-
const
|
|
55
|
-
!Number.isNaN(
|
|
54
|
+
const l = e.split(",").map((o) => o.trim());
|
|
55
|
+
for (const o of l) {
|
|
56
|
+
const i = Number.parseInt(o, 10);
|
|
57
|
+
!Number.isNaN(i) && s[i] ? r.add(s[i]) : A.has(o) && r.add(o);
|
|
56
58
|
}
|
|
57
59
|
}
|
|
58
|
-
return
|
|
60
|
+
return r.size > 0 ? Array.from(r) : void 0;
|
|
59
61
|
}, B = (t) => ({
|
|
60
62
|
date_availability: t.date_availability && t.date_availability.length > 0 ? t.date_availability.map(
|
|
61
|
-
(
|
|
63
|
+
(e) => v[e] ?? e
|
|
62
64
|
) : void 0,
|
|
63
65
|
qty_bedrooms: U(t.qty_bedrooms),
|
|
64
66
|
base_price: t.base_price ?? void 0,
|
|
65
67
|
highlights: t.highlights ?? []
|
|
66
68
|
});
|
|
67
69
|
export {
|
|
68
|
-
|
|
70
|
+
m as DEFAULT_PLACEHOLDER_IMAGE,
|
|
69
71
|
b as DEFAULT_WEB_ORIGIN,
|
|
70
72
|
I as buildExploreUrl,
|
|
71
|
-
|
|
73
|
+
c as buildImageUrl,
|
|
72
74
|
L as transformUnitsApiResponse,
|
|
73
75
|
x as transformUnitsApiResponseToClient,
|
|
74
76
|
B as transformUnitsApiResponseToClientFilters
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transformers.mjs","sources":["../../../src/features/units/transformers.ts"],"sourcesContent":["export const DEFAULT_WEB_ORIGIN = \"//web.inresiapp.com\";\nexport const DEFAULT_PLACEHOLDER_IMAGE = \"/placeholder.jpg\";\n\nexport interface UnitImageApiResponse {\n CFURL?: string;\n name?: string;\n signature?: string;\n}\n\nexport interface UnitSourceApiResponse extends Record<string, unknown> {\n id?: number | string;\n name?: string;\n title?: string;\n slug?: string;\n base_price?: number;\n qty_bedrooms?: number | string;\n qty_bathrooms?: number | string;\n totalSqFt?: number;\n dim_sq_ft?: number | string;\n amenities?: unknown;\n highlights?: unknown;\n date_availability?: string | Date | null;\n unitSetAvailableOn?: string | Date | null;\n image?: UnitImageApiResponse;\n additionalImages?: UnitImageApiResponse[];\n}\n\nexport interface UnitHitApiResponse<\n Source extends Record<string, unknown> = UnitSourceApiResponse,\n> {\n _index?: string;\n _id?: string;\n _score?: number;\n _source?: Source;\n}\n\nexport interface UnitsTotalInfo {\n value: number;\n relation?: string;\n}\n\nexport interface UnitsDataApiResponse<\n Source extends Record<string, unknown> = UnitSourceApiResponse,\n> {\n total?: UnitsTotalInfo;\n max_score?: number | null;\n hits?: UnitHitApiResponse<Source>[];\n type?: string;\n}\n\nexport interface UnitsApiResponse<\n Source extends Record<string, unknown> = UnitSourceApiResponse,\n> {\n data: UnitsDataApiResponse<Source>;\n}\n\nexport type TransformedUnit<\n Source extends Record<string, unknown> = UnitSourceApiResponse,\n> = Source & {\n name: string;\n imageUrl: string;\n secondaryImageUrl?: string;\n tertiaryImageUrl?: string;\n};\n\nexport interface UnitsClientList<\n Source extends Record<string, unknown> = UnitSourceApiResponse,\n> {\n total: number;\n maxScore: number | null;\n type: string;\n hits: TransformedUnit<Source>[];\n}\n\nexport interface TransformUnitsOptions {\n origin?: string;\n placeholderImage?: string;\n}\n\nconst normalizeSignature = (signature?: string): string => {\n if (!signature) return \"\";\n return signature.startsWith(\"?\") ? signature : `?${signature}`;\n};\n\nconst coerceString = (value: unknown): string | undefined => {\n if (typeof value === \"string\") return value;\n if (typeof value === \"number\" || typeof value === \"boolean\") {\n return String(value);\n }\n return undefined;\n};\n\nconst propertySlugFallback = (\n defaultSlug: string,\n source: UnitSourceApiResponse,\n): string | undefined => {\n const slug =\n coerceString((source as any).propertySlug) ??\n coerceString((source as any).property_slug);\n return slug ?? defaultSlug;\n};\n\nexport const buildExploreUrl = (\n unitSlug: string,\n propertySlug: string,\n origin = DEFAULT_WEB_ORIGIN,\n): string => `${origin}/${propertySlug}/unit/${unitSlug}/explore`;\n\nexport const buildImageUrl = (\n image?: UnitImageApiResponse,\n placeholder = DEFAULT_PLACEHOLDER_IMAGE,\n): string => {\n if (!image?.CFURL || !image?.name || !image?.signature) return placeholder;\n return `${image.CFURL}${image.name}${normalizeSignature(image.signature)}`;\n};\n\nexport function transformUnitsApiResponse<\n Source extends Record<string, unknown> = UnitSourceApiResponse,\n>(apiResponse: UnitsDataApiResponse<Source>): UnitsApiResponse<Source> {\n return { data: apiResponse };\n}\n\nexport function transformUnitsApiResponseToClient<\n Source extends Record<string, unknown> = UnitSourceApiResponse,\n>(\n apiResponse: UnitsDataApiResponse<Source>,\n propertySlug: string,\n options?: TransformUnitsOptions,\n): UnitsClientList<Source> {\n const origin = options?.origin ?? DEFAULT_WEB_ORIGIN;\n const placeholderImage = options?.placeholderImage ?? DEFAULT_PLACEHOLDER_IMAGE;\n\n const hits =\n apiResponse.hits?.map((hit) => {\n const source = (hit._source ?? {}) as Source & UnitSourceApiResponse;\n const unit_name =\n typeof source.name === \"string\"\n ? source.name\n : typeof source.title === \"string\"\n ? source.title\n : \"\";\n\n const slugCandidate =\n coerceString(source.slug) ?? coerceString((source as any).unit_slug) ?? \"\";\n const resolvedPropertySlug =\n coerceString((source as any).propertySlug) ??\n coerceString((source as any).property_slug) ??\n propertySlugFallback(propertySlug, source) ??\n propertySlug;\n\n const normalized: TransformedUnit<Source> = {\n ...(source as Source),\n name: unit_name,\n // slug: buildExploreUrl(slugCandidate, resolvedPropertySlug ?? \"\", origin),\n imageUrl: buildImageUrl(source.image, placeholderImage),\n secondaryImageUrl: buildImageUrl(source.additionalImages?.[0], placeholderImage),\n tertiaryImageUrl: buildImageUrl(source.additionalImages?.[1], placeholderImage),\n };\n\n\n\n if (\n resolvedPropertySlug &&\n !(normalized as Record<string, unknown>).propertySlug\n ) {\n (normalized as Record<string, unknown>).propertySlug = resolvedPropertySlug;\n }\n\n return normalized;\n }) ?? [];\n return {\n total: apiResponse.total?.value ?? hits.length,\n maxScore: apiResponse.max_score ?? null,\n type: apiResponse.type ?? \"units\",\n hits,\n };\n}\n\nexport interface UnitsFilterParams {\n date_availability?: string[];\n qty_bedrooms?: (number | string)[];\n base_price?: number | null;\n highlights?: string[];\n}\n\nexport interface UnitsClientFilters {\n date_availability?: string[];\n qty_bedrooms?: string[];\n base_price?: number;\n highlights: string[];\n}\n\nconst reverseAvailabilityMap: Record<string, string> = {\n asap: \"ASAP\",\n next_month: \"Next Month\",\n \"2_3_months\": \"2-3 Months\",\n all: \"Just Browsing\",\n};\n\nconst reverseBedroomMap: Record<number, string> = {\n 0: \"Studio\",\n 1: \"1 Bed\",\n 2: \"2 Bed\",\n 3: \"3+ Bed\",\n};\n\nconst bedroomLabels = new Set(Object.values(reverseBedroomMap));\n\nconst normalizeBedrooms = (\n bedrooms?: (number | string)[],\n): string[] | undefined => {\n if (!bedrooms || bedrooms.length === 0) return undefined;\n\n const result = new Set<string>();\n\n for (const bedroom of bedrooms) {\n if (typeof bedroom === \"number\") {\n const label = reverseBedroomMap[bedroom];\n if (label) result.add(label);\n continue;\n }\n\n const values = bedroom.split(\",\").map((v) => v.trim());\n\n for (const value of values) {\n const parsed = Number.parseInt(value, 10);\n if (!Number.isNaN(parsed) && reverseBedroomMap[parsed]) {\n result.add(reverseBedroomMap[parsed]);\n } else if (bedroomLabels.has(value)) {\n result.add(value);\n }\n }\n }\n\n return result.size > 0 ? Array.from(result) : undefined;\n};\n\nexport const transformUnitsApiResponseToClientFilters = (\n params: UnitsFilterParams,\n): UnitsClientFilters => {\n const dateAvailabilityLabels =\n params.date_availability && params.date_availability.length > 0\n ? params.date_availability.map(\n (value) => reverseAvailabilityMap[value] ?? value,\n )\n : undefined;\n\n return {\n date_availability: dateAvailabilityLabels,\n qty_bedrooms: normalizeBedrooms(params.qty_bedrooms),\n base_price: params.base_price ?? undefined,\n highlights: params.highlights ?? [],\n };\n};\n"],"names":["DEFAULT_WEB_ORIGIN","DEFAULT_PLACEHOLDER_IMAGE","normalizeSignature","signature","coerceString","value","propertySlugFallback","defaultSlug","source","buildExploreUrl","unitSlug","propertySlug","origin","buildImageUrl","image","placeholder","transformUnitsApiResponse","apiResponse","transformUnitsApiResponseToClient","options","_a","_b","placeholderImage","hits","hit","unit_name","resolvedPropertySlug","normalized","reverseAvailabilityMap","reverseBedroomMap","bedroomLabels","normalizeBedrooms","bedrooms","result","bedroom","label","values","v","parsed","transformUnitsApiResponseToClientFilters","params"],"mappings":"AAAO,MAAMA,IAAqB,uBACrBC,IAA4B,oBA8EnC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kBS,CAAM,IACnDL,EAAO,IAAIJ,EAAkBS,CAAM,CAAC,IAC3BR,EAAc,IAAIzB,CAAK,KAChC4B,EAAO,IAAI5B,CAAK;AAAA,IAEpB;AAAA,EACF;AAEA,SAAO4B,EAAO,OAAO,IAAI,MAAM,KAAKA,CAAM,IAAI;AAChD,GAEaM,IAA2C,CACtDC,OASO;AAAA,EACL,mBAPAA,EAAO,qBAAqBA,EAAO,kBAAkB,SAAS,IAC1DA,EAAO,kBAAkB;AAAA,IACvB,CAACnC,MAAUuB,EAAuBvB,CAAK,KAAKA;AAAA,EAAA,IAE9C;AAAA,EAIJ,cAAc0B,EAAkBS,EAAO,YAAY;AAAA,EACnD,YAAYA,EAAO,cAAc;AAAA,EACjC,YAAYA,EAAO,cAAc,CAAA;AAAC;"}
|
|
1
|
+
{"version":3,"file":"transformers.mjs","sources":["../../../src/features/units/transformers.ts"],"sourcesContent":["export const DEFAULT_WEB_ORIGIN = \"//web.inresiapp.com\";\nexport const DEFAULT_PLACEHOLDER_IMAGE = \"/placeholder.jpg\";\n\nexport interface UnitImageApiResponse {\n CFURL?: string;\n name?: string;\n imageSignature?: string;\n}\n\nexport interface UnitSourceApiResponse extends Record<string, unknown> {\n id?: number | string;\n name?: string;\n title?: string;\n slug?: string;\n base_price?: number;\n qty_bedrooms?: number | string;\n qty_bathrooms?: number | string;\n totalSqFt?: number;\n dim_sq_ft?: number | string;\n amenities?: unknown;\n highlights?: unknown;\n date_availability?: string | Date | null;\n unitSetAvailableOn?: string | Date | null;\n image: UnitImageApiResponse;\n additionalImages?: UnitImageApiResponse[];\n}\n\nexport interface UnitHitApiResponse<\n Source extends Record<string, unknown> = UnitSourceApiResponse,\n> {\n _index?: string;\n _id?: string;\n _score?: number;\n _source?: Source;\n}\n\nexport interface UnitsTotalInfo {\n value: number;\n relation?: string;\n}\n\nexport interface UnitsDataApiResponse<\n Source extends Record<string, unknown> = UnitSourceApiResponse,\n> {\n total?: UnitsTotalInfo;\n max_score?: number | null;\n hits?: UnitHitApiResponse<Source>[];\n type?: string;\n imageSignature?: string;\n}\n\nexport interface UnitsApiResponse<\n Source extends Record<string, unknown> = UnitSourceApiResponse,\n> {\n data: UnitsDataApiResponse<Source>;\n}\n\nexport type TransformedUnit<\n Source extends Record<string, unknown> = UnitSourceApiResponse,\n> = Source & {\n name: string;\n imageUrl: string;\n secondaryImageUrl?: string;\n tertiaryImageUrl?: string;\n};\n\nexport interface UnitsClientList<\n Source extends Record<string, unknown> = UnitSourceApiResponse,\n> {\n total: number;\n maxScore: number | null;\n type: string;\n hits: TransformedUnit<Source>[];\n}\n\nexport interface TransformUnitsOptions {\n origin?: string;\n placeholderImage?: string;\n}\n\nconst normalizeSignature = (signature?: string): string => {\n if (!signature) return \"\";\n return signature.startsWith(\"?\") ? signature : `?${signature}`;\n};\n\nconst coerceString = (value: unknown): string | undefined => {\n if (typeof value === \"string\") return value;\n if (typeof value === \"number\" || typeof value === \"boolean\") {\n return String(value);\n }\n return undefined;\n};\n\nconst propertySlugFallback = (\n defaultSlug: string,\n source: UnitSourceApiResponse,\n): string | undefined => {\n const slug =\n coerceString((source as any).propertySlug) ??\n coerceString((source as any).property_slug);\n return slug ?? defaultSlug;\n};\n\nexport const buildExploreUrl = (\n unitSlug: string,\n propertySlug: string,\n origin = DEFAULT_WEB_ORIGIN,\n): string => `${origin}/${propertySlug}/unit/${unitSlug}/explore`;\n\nexport const buildImageUrl = (\n image: UnitImageApiResponse | undefined,\n placeholder = DEFAULT_PLACEHOLDER_IMAGE,\n fallbackSignature?: string,\n): string => {\n const signature = image?.imageSignature ?? fallbackSignature;\n if (!image?.CFURL || !image?.name || !signature) return placeholder;\n return `${image.CFURL}${image.name}${normalizeSignature(signature)}`;\n};\n\nexport function transformUnitsApiResponse<\n Source extends Record<string, unknown> = UnitSourceApiResponse,\n>(apiResponse: UnitsDataApiResponse<Source>): UnitsApiResponse<Source> {\n return { data: apiResponse };\n}\n\nexport function transformUnitsApiResponseToClient<\n Source extends Record<string, unknown> = UnitSourceApiResponse,\n>(\n apiResponse: UnitsDataApiResponse<Source>,\n propertySlug: string,\n options?: TransformUnitsOptions,\n): UnitsClientList<Source> {\n const origin = options?.origin ?? DEFAULT_WEB_ORIGIN;\n const placeholderImage = options?.placeholderImage ?? DEFAULT_PLACEHOLDER_IMAGE;\n\n const hits =\n apiResponse.hits?.map((hit) => {\n const source = (hit._source ?? {}) as Source & UnitSourceApiResponse;\n const unit_name =\n typeof source.name === \"string\"\n ? source.name\n : typeof source.title === \"string\"\n ? source.title\n : \"\";\n\n const slugCandidate =\n coerceString(source.slug) ?? coerceString((source as any).unit_slug) ?? \"\";\n const resolvedPropertySlug =\n coerceString((source as any).propertySlug) ??\n coerceString((source as any).property_slug) ??\n propertySlugFallback(propertySlug, source) ??\n propertySlug;\n\n const normalized: TransformedUnit<Source> = {\n ...(source as Source),\n name: unit_name,\n imageUrl: buildImageUrl(source.image, placeholderImage, apiResponse.imageSignature),\n secondaryImageUrl: buildImageUrl(source.additionalImages?.[0], placeholderImage, apiResponse.imageSignature),\n tertiaryImageUrl: buildImageUrl(source.additionalImages?.[1], placeholderImage, apiResponse.imageSignature),\n };\n\n\n\n if (\n resolvedPropertySlug &&\n !(normalized as Record<string, unknown>).propertySlug\n ) {\n (normalized as Record<string, unknown>).propertySlug = resolvedPropertySlug;\n }\n\n return normalized;\n }) ?? [];\n return {\n total: apiResponse.total?.value ?? hits.length,\n maxScore: apiResponse.max_score ?? null,\n type: apiResponse.type ?? \"units\",\n hits,\n };\n}\n\nexport interface UnitsFilterParams {\n date_availability?: string[];\n qty_bedrooms?: (number | string)[];\n base_price?: number | null;\n highlights?: string[];\n}\n\nexport interface UnitsClientFilters {\n date_availability?: string[];\n qty_bedrooms?: string[];\n base_price?: number;\n highlights: string[];\n}\n\nconst reverseAvailabilityMap: Record<string, string> = {\n asap: \"ASAP\",\n next_month: \"Next Month\",\n \"2_3_months\": \"2-3 Months\",\n all: \"Just Browsing\",\n};\n\nconst reverseBedroomMap: Record<number, string> = {\n 0: \"Studio\",\n 1: \"1 Bed\",\n 2: \"2 Bed\",\n 3: \"3+ Bed\",\n};\n\nconst bedroomLabels = new Set(Object.values(reverseBedroomMap));\n\nconst normalizeBedrooms = (\n bedrooms?: (number | string)[],\n): string[] | undefined => {\n if (!bedrooms || bedrooms.length === 0) return undefined;\n\n const result = new Set<string>();\n\n for (const bedroom of bedrooms) {\n if (typeof bedroom === \"number\") {\n const label = reverseBedroomMap[bedroom];\n if (label) result.add(label);\n continue;\n }\n\n const values = bedroom.split(\",\").map((v) => v.trim());\n\n for (const value of values) {\n const parsed = Number.parseInt(value, 10);\n if (!Number.isNaN(parsed) && reverseBedroomMap[parsed]) {\n result.add(reverseBedroomMap[parsed]);\n } else if (bedroomLabels.has(value)) {\n result.add(value);\n }\n }\n }\n\n return result.size > 0 ? Array.from(result) : undefined;\n};\n\nexport const transformUnitsApiResponseToClientFilters = (\n params: UnitsFilterParams,\n): UnitsClientFilters => {\n const dateAvailabilityLabels =\n params.date_availability && params.date_availability.length > 0\n ? params.date_availability.map(\n (value) => reverseAvailabilityMap[value] ?? value,\n )\n : undefined;\n\n return {\n date_availability: dateAvailabilityLabels,\n qty_bedrooms: normalizeBedrooms(params.qty_bedrooms),\n base_price: params.base_price ?? undefined,\n highlights: params.highlights ?? [],\n };\n};\n"],"names":["DEFAULT_WEB_ORIGIN","DEFAULT_PLACEHOLDER_IMAGE","normalizeSignature","signature","coerceString","value","propertySlugFallback","defaultSlug","source","buildExploreUrl","unitSlug","propertySlug","origin","buildImageUrl","image","placeholder","fallbackSignature","transformUnitsApiResponse","apiResponse","transformUnitsApiResponseToClient","options","_a","_b","placeholderImage","hits","hit","unit_name","resolvedPropertySlug","normalized","reverseAvailabilityMap","reverseBedroomMap","bedroomLabels","normalizeBedrooms","bedrooms","result","bedroom","label","values","v","parsed","transformUnitsApiResponseToClientFilters","params"],"mappings":"AAAO,MAAMA,IAAqB,uBACrBC,IAA4B,oBA+EnCC,IAAqB,CAACC,M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