@superbright/indexeddb-orm 0.1.3 โ 0.1.5
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 +21 -20
- package/dist/adapters/dexie.d.ts +14 -0
- package/dist/adapters/structured-store.d.ts +44 -0
- package/dist/adapters/zustand-store.d.ts +54 -0
- package/dist/api/favorites.d.ts +4 -0
- package/dist/api/properties.d.ts +22 -0
- package/dist/api/users.d.ts +5 -0
- package/dist/db.d.ts +15 -0
- package/dist/debug.d.ts +2 -0
- package/dist/errors.d.ts +8 -0
- package/dist/features/units/transformers.d.ts +75 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +14 -0
- package/dist/index.mjs +779 -569
- package/dist/index.mjs.map +1 -1
- package/dist/schema.d.ts +2880 -0
- package/dist/storage.d.ts +14 -0
- package/dist/stores/store.d.ts +42 -0
- package/dist/units/favorites.d.ts +7 -0
- package/dist/validation.d.ts +7 -0
- package/package.json +21 -20
package/README.md
CHANGED
|
@@ -166,7 +166,7 @@ const properties = useStore(state => state.properties);
|
|
|
166
166
|
|
|
167
167
|
// App data
|
|
168
168
|
const filters = useStore(state => state.filters);
|
|
169
|
-
const
|
|
169
|
+
const unitResults = useStore(state => state.unitResults);
|
|
170
170
|
const resultsMode = useStore(state => state.resultsMode);
|
|
171
171
|
|
|
172
172
|
// Unit state helper
|
|
@@ -176,24 +176,25 @@ const unitState = useUnitState("unit-123");
|
|
|
176
176
|
|
|
177
177
|
### Direct Store Methods
|
|
178
178
|
|
|
179
|
-
For advanced use cases,
|
|
179
|
+
For advanced use cases, the core store methods are available. Prefer the structured actions shown above for most scenarios.
|
|
180
180
|
|
|
181
181
|
```typescript
|
|
182
182
|
// Property operations
|
|
183
|
-
await store.getCurrentProperty()
|
|
184
|
-
await store.setCurrentProperty(propertyId, slug)
|
|
185
|
-
await store.getPropertyData(propertyId)
|
|
186
|
-
|
|
187
|
-
// Unit
|
|
188
|
-
await store.
|
|
189
|
-
await store.
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
await store.
|
|
194
|
-
await store.
|
|
183
|
+
await store.getCurrentProperty();
|
|
184
|
+
await store.setCurrentProperty(propertyId, slug);
|
|
185
|
+
await store.getPropertyData(propertyId);
|
|
186
|
+
|
|
187
|
+
// Unit results cache
|
|
188
|
+
await store.setUnitResults(transformedUnits.hits);
|
|
189
|
+
await store.clearUnitResults();
|
|
190
|
+
|
|
191
|
+
// Filters
|
|
192
|
+
await store.setFilters({ bedrooms: [1, 2] });
|
|
193
|
+
await store.setTempFilters({ cost: 2500 });
|
|
194
|
+
await store.submitFilterUpdate();
|
|
195
195
|
```
|
|
196
196
|
|
|
197
|
+
|
|
197
198
|
## ๐ ๏ธ Development
|
|
198
199
|
|
|
199
200
|
### Local Development Setup
|
|
@@ -233,6 +234,7 @@ pnpm dev
|
|
|
233
234
|
- **๐ Property Management**: Create properties, set current property, retrieve property data
|
|
234
235
|
- **โญ Unit Actions**: Toggle favorites, mark units as viewed, get unit state
|
|
235
236
|
- **๐ Filter Operations**: Set filters, reset to defaults, submit filter updates
|
|
237
|
+
- **๐งช Search & Results**: Set results mode and sort order, run a mock search that populates unit results, and clear results
|
|
236
238
|
- **๐ Questionnaire & Tours**: Set questionnaire results, manage tour contact data
|
|
237
239
|
- **๐ Real-time State View**: Live view of database state and action logs
|
|
238
240
|
- **๐ ๏ธ Developer Tools Integration**: Inspect IndexedDB directly in DevTools โ Application โ IndexedDB โ `inresi-orm`
|
|
@@ -286,9 +288,9 @@ import type {
|
|
|
286
288
|
StructuredStoreActions,
|
|
287
289
|
Filters,
|
|
288
290
|
QueryParams,
|
|
289
|
-
UnitData,
|
|
290
291
|
TourContactData,
|
|
291
|
-
|
|
292
|
+
UserPropertyState,
|
|
293
|
+
Unit,
|
|
292
294
|
ZustandUnifiedStoreState,
|
|
293
295
|
} from "@superbright/indexeddb-orm";
|
|
294
296
|
```
|
|
@@ -299,11 +301,11 @@ Built-in Zod schemas ensure data integrity:
|
|
|
299
301
|
|
|
300
302
|
```typescript
|
|
301
303
|
// Example schema usage
|
|
302
|
-
import { FiltersSchema,
|
|
304
|
+
import { FiltersSchema, UnitSchema } from "@superbright/indexeddb-orm";
|
|
303
305
|
|
|
304
306
|
// Validate data at runtime
|
|
305
307
|
const validatedFilters = FiltersSchema.parse(userInput);
|
|
306
|
-
const validatedUnit =
|
|
308
|
+
const validatedUnit = UnitSchema.parse(transformedUnit);
|
|
307
309
|
```
|
|
308
310
|
|
|
309
311
|
## ๐ง Configuration
|
|
@@ -352,8 +354,7 @@ configureValidation("strict"); // "strict" | "warn" | "off"
|
|
|
352
354
|
## ๐ Documentation
|
|
353
355
|
|
|
354
356
|
- [Consuming App Guide](./CONSUMING_APP_GUIDE.md) - Complete integration guide
|
|
355
|
-
- [Migration
|
|
356
|
-
- [Property Store Guide](./docs/property-store.md) - Property-specific usage
|
|
357
|
+
- [Structured Store Migration](./docs/structured-store-migration.md) - Move to the structured API
|
|
357
358
|
- [App Store Guide](./docs/app-store-guide.md) - App state management
|
|
358
359
|
|
|
359
360
|
## ๐ง Legacy API
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import Dexie, { type Table } from "dexie";
|
|
2
|
+
export interface KV {
|
|
3
|
+
key: string;
|
|
4
|
+
value: unknown;
|
|
5
|
+
}
|
|
6
|
+
export interface OrmDexieTables {
|
|
7
|
+
users: Table<any, string>;
|
|
8
|
+
kv: Table<KV, string>;
|
|
9
|
+
}
|
|
10
|
+
export declare class OrmDexie extends Dexie {
|
|
11
|
+
users: OrmDexieTables["users"];
|
|
12
|
+
kv: OrmDexieTables["kv"];
|
|
13
|
+
constructor(name?: string);
|
|
14
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structured store wrapper (preferred DX)
|
|
3
|
+
*
|
|
4
|
+
* This layer wraps the flat Zustand adapter with domainโgrouped actions
|
|
5
|
+
* for a more discoverable API in apps. It does not add new behavior โ
|
|
6
|
+
* it simply organizes calls like:
|
|
7
|
+
* - `property.unit.favorites.toggle` โ `toggleFavorite`
|
|
8
|
+
* - `property.unit.viewed.mark` โ `markUnitAsViewed`
|
|
9
|
+
* - `filters.set/submit/...` โ filter methods
|
|
10
|
+
*/
|
|
11
|
+
import { type ZustandUnifiedStoreState, type Filters, type TourContactData, type QueryParams } from "./zustand-store";
|
|
12
|
+
export interface StructuredStoreActions {
|
|
13
|
+
property: {
|
|
14
|
+
unit: {
|
|
15
|
+
favorites: {
|
|
16
|
+
toggle: (unitId: string) => Promise<void>;
|
|
17
|
+
};
|
|
18
|
+
viewed: {
|
|
19
|
+
mark: (unitId: string, slug: string) => Promise<void>;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
questionnaire: {
|
|
23
|
+
setResults: (results: unknown) => Promise<void>;
|
|
24
|
+
};
|
|
25
|
+
tour: {
|
|
26
|
+
setContactedOn: () => Promise<void>;
|
|
27
|
+
getContactedOn: () => Promise<string | null>;
|
|
28
|
+
setContactData: (data: TourContactData) => Promise<void>;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
filters: {
|
|
32
|
+
set: (filters: Partial<Filters>) => Promise<void>;
|
|
33
|
+
setTemp: (filters: Partial<Filters>) => Promise<void>;
|
|
34
|
+
setToDefault: () => Promise<void>;
|
|
35
|
+
commitTemp: <K extends keyof Filters>(key: K, defaultValue: Filters[K]) => Promise<void>;
|
|
36
|
+
commitAvailability: () => Promise<void>;
|
|
37
|
+
submit: () => Promise<void>;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
export declare function createStructuredStoreActions(store: ZustandUnifiedStoreState, get?: () => ZustandUnifiedStoreState): StructuredStoreActions;
|
|
41
|
+
export type StructuredStore = ZustandUnifiedStoreState & StructuredStoreActions;
|
|
42
|
+
export declare function createStructuredStore(options?: {
|
|
43
|
+
onFilterUpdate?: (apiParams: QueryParams) => void;
|
|
44
|
+
}): (set: any, get: any) => StructuredStore;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { UserPropertyState, Filters, QueryParams, ResultsMode, SortBy, TourContactData, Unit } from "../schema";
|
|
2
|
+
export interface ZustandUnifiedStoreState {
|
|
3
|
+
properties: Record<string, UserPropertyState>;
|
|
4
|
+
currentPropertyId: string | null;
|
|
5
|
+
currentPropertySlug: string | null;
|
|
6
|
+
hasPreviouslySearched: string[];
|
|
7
|
+
unitResults: Unit[];
|
|
8
|
+
filters: Filters;
|
|
9
|
+
tempFilters: Filters;
|
|
10
|
+
apiFilters: QueryParams;
|
|
11
|
+
resultsMode: ResultsMode;
|
|
12
|
+
resolvedQuestionnaireValues: Record<string, string[]>;
|
|
13
|
+
sortBy: SortBy;
|
|
14
|
+
filtersLoaded: boolean;
|
|
15
|
+
initializeProperty: (propertyId: string, slug: string) => Promise<void>;
|
|
16
|
+
setCurrentProperty: (propertyId: string, slug?: string) => Promise<void>;
|
|
17
|
+
setCurrentPropertySlug: (slug: string) => Promise<void>;
|
|
18
|
+
setHasPreviouslySearched: (slug: string) => Promise<void>;
|
|
19
|
+
toggleFavorite: (unitId: string) => Promise<void>;
|
|
20
|
+
markUnitAsViewed: (unitId: string, slug: string) => Promise<void>;
|
|
21
|
+
setTourContactedOn: () => Promise<void>;
|
|
22
|
+
getTourContactedOn: () => Promise<string | null>;
|
|
23
|
+
setQuestionnaireResults: (results: unknown) => Promise<void>;
|
|
24
|
+
setTourContactData: (data: TourContactData) => Promise<void>;
|
|
25
|
+
setUnitResults: (units: unknown) => Promise<void>;
|
|
26
|
+
clearUnitResults: () => Promise<void>;
|
|
27
|
+
setFilters: (filters: Partial<Filters>) => Promise<void>;
|
|
28
|
+
setTempFilters: (filters: Partial<Filters>) => Promise<void>;
|
|
29
|
+
setFiltersToDefault: () => Promise<void>;
|
|
30
|
+
setApiFilters: (filters: Partial<QueryParams>) => Promise<void>;
|
|
31
|
+
handleTempFilterChange: <K extends keyof Filters>(key: K, value: Filters[K]) => Promise<void>;
|
|
32
|
+
submitFilterUpdate: () => Promise<void>;
|
|
33
|
+
setResultsMode: (mode: ResultsMode) => Promise<void>;
|
|
34
|
+
setSortBy: (sortBy: SortBy) => Promise<void>;
|
|
35
|
+
setResolvedQuestionnaireValues: (name: string, values: string[]) => Promise<void>;
|
|
36
|
+
getUnitState: (unitId: string) => {
|
|
37
|
+
isFavorite: boolean;
|
|
38
|
+
viewedDate: string;
|
|
39
|
+
};
|
|
40
|
+
getResultsUrl: () => Promise<string | null>;
|
|
41
|
+
getCurrentProperty: () => Promise<UserPropertyState | null>;
|
|
42
|
+
getPropertyData: (propertyId?: string) => Promise<UserPropertyState | null>;
|
|
43
|
+
_hydrate: () => Promise<void>;
|
|
44
|
+
_initialize: () => Promise<void>;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* @deprecated For new apps, use `createStructuredStore` from `./structured-store`.
|
|
48
|
+
* This flat adapter remains for migration/advanced cases.
|
|
49
|
+
*/
|
|
50
|
+
export declare function createZustandUnifiedStore(options?: {
|
|
51
|
+
onFilterUpdate?: (apiParams: QueryParams) => void;
|
|
52
|
+
}): (set: any, get: any) => ZustandUnifiedStoreState;
|
|
53
|
+
export declare function createUseUnitState(): (useStore: any) => (unitId: string) => any;
|
|
54
|
+
export type { UnitData, UserPropertyState, Filters, QueryParams, ResultsMode, SortBy, TourContactData, Unit } from "../schema";
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare function getFavoritedUnitsForProperty(propertyId: string | number): Promise<string[]>;
|
|
2
|
+
export declare function setFavoriteUnit(propertyId: string | number, unitId: string, on: boolean): Promise<string[]>;
|
|
3
|
+
export declare function toggleFavoriteUnit(propertyId: string | number, unitId: string): Promise<string[]>;
|
|
4
|
+
export declare function isUnitFavorited(propertyId: string | number, unitId: string): Promise<boolean>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type TourContactData, type UserPropertyState, type PropertyStoreData } from "../schema";
|
|
2
|
+
export type { ViewedUnit, TourContactData, UserPropertyState, PropertyStoreData } from "../schema";
|
|
3
|
+
export declare class PropertyStore {
|
|
4
|
+
private getState;
|
|
5
|
+
private setState;
|
|
6
|
+
setHasPreviouslySearched(slug: string): Promise<void>;
|
|
7
|
+
setTourContactedOn(): Promise<void>;
|
|
8
|
+
getTourContactedOn(): Promise<string | null>;
|
|
9
|
+
setQuestionnaireResults(results: unknown): Promise<void>;
|
|
10
|
+
setTourContactData(data: TourContactData): Promise<void>;
|
|
11
|
+
toggleFavorite(unitId: string): Promise<void>;
|
|
12
|
+
markUnitAsViewed(unitId: string, slug: string): Promise<void>;
|
|
13
|
+
getUnitState(unitId: string): Promise<{
|
|
14
|
+
isFavorite: boolean;
|
|
15
|
+
viewedDate: string;
|
|
16
|
+
}>;
|
|
17
|
+
getPropertyData(propertyId?: string | number): Promise<UserPropertyState | null>;
|
|
18
|
+
getCurrentProperty(): Promise<UserPropertyState | null>;
|
|
19
|
+
getFullState(): Promise<PropertyStoreData>;
|
|
20
|
+
initializeProperty(propertyId: string | number, slug: string): Promise<void>;
|
|
21
|
+
}
|
|
22
|
+
export declare const propertyStore: PropertyStore;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type User } from "../schema";
|
|
2
|
+
export type IdGenerator = () => string;
|
|
3
|
+
export declare const defaultIdGenerator: IdGenerator;
|
|
4
|
+
export declare function ensureUser(gen?: IdGenerator): Promise<User>;
|
|
5
|
+
export declare const getUserUUID: (gen?: IdGenerator) => Promise<string>;
|
package/dist/db.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { OrmDexie } from "./adapters/dexie";
|
|
2
|
+
import { type ValidationMode } from "./validation";
|
|
3
|
+
export type OrmOptions = {
|
|
4
|
+
dbName?: string;
|
|
5
|
+
onReset?: (reason: "incompatible" | "versionchange" | "blocked") => void;
|
|
6
|
+
onError?: (err: unknown) => void;
|
|
7
|
+
validation?: {
|
|
8
|
+
mode?: ValidationMode;
|
|
9
|
+
onIssue?: (ctx: string, details: unknown) => void;
|
|
10
|
+
validateReads?: boolean;
|
|
11
|
+
dropInvalidOnRead?: boolean;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
export declare function getDB(opts?: OrmOptions): Promise<OrmDexie>;
|
|
15
|
+
export declare function resetDB(dbName?: string): Promise<void>;
|
package/dist/debug.d.ts
ADDED
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare class SchemaMismatchError extends Error {
|
|
2
|
+
detail?: unknown | undefined;
|
|
3
|
+
constructor(message: string, detail?: unknown | undefined);
|
|
4
|
+
}
|
|
5
|
+
export declare class OpenDBError extends Error {
|
|
6
|
+
detail?: unknown | undefined;
|
|
7
|
+
constructor(message: string, detail?: unknown | undefined);
|
|
8
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
export declare const DEFAULT_WEB_ORIGIN = "//web.inresiapp.com";
|
|
2
|
+
export declare const DEFAULT_PLACEHOLDER_IMAGE = "/placeholder.jpg";
|
|
3
|
+
export interface UnitImageApiResponse {
|
|
4
|
+
CFURL?: string;
|
|
5
|
+
name?: string;
|
|
6
|
+
signature?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface UnitSourceApiResponse extends Record<string, unknown> {
|
|
9
|
+
id?: number | string;
|
|
10
|
+
name?: string;
|
|
11
|
+
title?: string;
|
|
12
|
+
slug?: string;
|
|
13
|
+
cost?: number;
|
|
14
|
+
bedrooms?: number;
|
|
15
|
+
bathrooms?: number;
|
|
16
|
+
totalSqFt?: number;
|
|
17
|
+
amenities?: unknown;
|
|
18
|
+
highlights?: unknown;
|
|
19
|
+
availability?: string | Date | null;
|
|
20
|
+
image?: UnitImageApiResponse;
|
|
21
|
+
additionalImages?: UnitImageApiResponse[];
|
|
22
|
+
}
|
|
23
|
+
export interface UnitHitApiResponse<Source extends Record<string, unknown> = UnitSourceApiResponse> {
|
|
24
|
+
_index?: string;
|
|
25
|
+
_id?: string;
|
|
26
|
+
_score?: number;
|
|
27
|
+
_source?: Source;
|
|
28
|
+
}
|
|
29
|
+
export interface UnitsTotalInfo {
|
|
30
|
+
value: number;
|
|
31
|
+
relation?: string;
|
|
32
|
+
}
|
|
33
|
+
export interface UnitsDataApiResponse<Source extends Record<string, unknown> = UnitSourceApiResponse> {
|
|
34
|
+
total?: UnitsTotalInfo;
|
|
35
|
+
max_score?: number | null;
|
|
36
|
+
hits?: UnitHitApiResponse<Source>[];
|
|
37
|
+
type?: string;
|
|
38
|
+
}
|
|
39
|
+
export interface UnitsApiResponse<Source extends Record<string, unknown> = UnitSourceApiResponse> {
|
|
40
|
+
data: UnitsDataApiResponse<Source>;
|
|
41
|
+
}
|
|
42
|
+
export type TransformedUnit<Source extends Record<string, unknown> = UnitSourceApiResponse> = Source & {
|
|
43
|
+
title: string;
|
|
44
|
+
slug: string;
|
|
45
|
+
imageUrl: string;
|
|
46
|
+
secondaryImageUrl?: string;
|
|
47
|
+
tertiaryImageUrl?: string;
|
|
48
|
+
};
|
|
49
|
+
export interface UnitsClientList<Source extends Record<string, unknown> = UnitSourceApiResponse> {
|
|
50
|
+
total: number;
|
|
51
|
+
maxScore: number | null;
|
|
52
|
+
type: string;
|
|
53
|
+
hits: TransformedUnit<Source>[];
|
|
54
|
+
}
|
|
55
|
+
export interface TransformUnitsOptions {
|
|
56
|
+
origin?: string;
|
|
57
|
+
placeholderImage?: string;
|
|
58
|
+
}
|
|
59
|
+
export declare const buildExploreUrl: (unitSlug: string, propertySlug: string, origin?: string) => string;
|
|
60
|
+
export declare const buildImageUrl: (image?: UnitImageApiResponse, placeholder?: string) => string;
|
|
61
|
+
export declare function transformUnitsApiResponse<Source extends Record<string, unknown> = UnitSourceApiResponse>(apiResponse: UnitsDataApiResponse<Source>): UnitsApiResponse<Source>;
|
|
62
|
+
export declare function transformUnitsApiResponseToClient<Source extends Record<string, unknown> = UnitSourceApiResponse>(apiResponse: UnitsDataApiResponse<Source>, propertySlug: string, options?: TransformUnitsOptions): UnitsClientList<Source>;
|
|
63
|
+
export interface UnitsFilterParams {
|
|
64
|
+
availability?: string[];
|
|
65
|
+
bedrooms?: (number | string)[];
|
|
66
|
+
cost?: number | null;
|
|
67
|
+
highlights?: string[];
|
|
68
|
+
}
|
|
69
|
+
export interface UnitsClientFilters {
|
|
70
|
+
availability?: string[];
|
|
71
|
+
bedrooms?: string[];
|
|
72
|
+
cost?: number;
|
|
73
|
+
highlights: string[];
|
|
74
|
+
}
|
|
75
|
+
export declare const transformUnitsApiResponseToClientFilters: (params: UnitsFilterParams) => UnitsClientFilters;
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("zod"),at=require("dexie");var U=typeof document<"u"?document.currentScript:null;class B extends Error{constructor(t,e){super(t),this.detail=e,this.name="SchemaMismatchError"}}class Q extends Error{constructor(t,e){super(t),this.detail=e,this.name="OpenDBError"}}class R extends at{constructor(t="inresi-orm"){super(t),this.version(m).stores({users:"uuid",kv:"key"}),this.users=this.table("users"),this.kv=this.table("kv")}}let O="strict",b;function x(a){a.mode&&(O=a.mode),b=a.onIssue}function D(a,t,e){const r=a.safeParse(t);if(r.success)return r.data;const s=r.error.flatten();if(b==null||b(e,s),O==="strict")throw new B(`ORM schema mismatch in ${e}`,s);return O==="warn"&&console.warn(`ORM schema mismatch in ${e}`,s),null}const it={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},I="manifest",nt=n.z.object({schemaVersion:n.z.number().int()});let h=null,f=null;const L=Symbol("validationInstalled");function C(a,t){const e=a;if(e[L])return;if(e[L]=!0,((i,o,c)=>{i.hook("creating",(u,y)=>{const p=D(o,y,`${c}.creating`);if(!p)throw new Error(`Rejected invalid ${c} on create`);return p}),i.hook("updating",(u,y,p)=>{const d={...p,...u};return D(o,d,`${c}.updating`)?u:{}})})(a.users,g,"users"),(t==null?void 0:t.validateReads)??!0){const i=(t==null?void 0:t.dropInvalidOnRead)??!0;((c,u,y)=>{c.hook("reading",p=>{const d=D(u,p,`${y}.reading`);return d||(i?void 0:p)})})(a.users,g,"users")}}function st(){try{if(typeof{url:typeof document>"u"?require("url").pathToFileURL(__filename).href:U&&U.tagName.toUpperCase()==="SCRIPT"&&U.src||new URL("index.cjs",document.baseURI).href}<"u"&&it)return!1}catch{}try{if(typeof process<"u"&&process.env)return process.env.NODE_ENV!=="production"}catch{}return!1}async function w(a={}){if(h)return h;if(f)return f;const t=a.dbName??"inresi-orm";return f=(async()=>{var e,r,s,i;try{const o=st()?"warn":"strict";x({mode:((e=a.validation)==null?void 0:e.mode)??o,onIssue:(r=a.validation)==null?void 0:r.onIssue});const c=new R(t);c.on("versionchange",()=>{var d;try{c.close()}finally{(d=a.onReset)==null||d.call(a,"versionchange")}}),c.on("blocked",()=>{var d;(d=a.onReset)==null||d.call(a,"blocked")}),await c.open();const u=await c.kv.get(I),y=(u==null?void 0:u.value)??null;if(!y)return await c.transaction("rw",c.kv,async()=>{await c.kv.put({key:I,value:{schemaVersion:m}})}),C(c,a.validation),h=c,c;const p=nt.safeParse(y);if(!p.success||p.data.schemaVersion!==m){await c.delete();const d=new R(t);return d.on("versionchange",()=>{var S;try{d.close()}finally{(S=a.onReset)==null||S.call(a,"versionchange")}}),d.on("blocked",()=>{var S;(S=a.onReset)==null||S.call(a,"blocked")}),await d.open(),await d.kv.put({key:I,value:{schemaVersion:m}}),C(d,a.validation),(s=a.onReset)==null||s.call(a,"incompatible"),h=d,d}return C(c,a.validation),h=c,c}catch(o){throw(i=a.onError)==null||i.call(a,o),new Q("Failed to open IndexedDB",o)}finally{f=null}})(),f}async function ot(a){const t=a??"inresi-orm";if(h)try{await h.close()}catch{}await new R(t).delete(),h=null}async function A(a){const e=await(await w()).kv.get(a);return(e==null?void 0:e.value)??null}async function E(a,t){await(await w()).kv.put({key:a,value:t})}async function ct(a){await(await w()).kv.delete(a)}function lt(a){const t=new Map,e=(a==null?void 0:a.prefix)??"",r=s=>`${e}${s}`;return{async getItem(s){try{const o=await(await w()).kv.get(r(s));return o?JSON.stringify(o.value):null}catch(i){if(a!=null&&a.fallbackToMemory)return t.get(r(s))??null;throw i}},async setItem(s,i){try{await(await w()).kv.put({key:r(s),value:JSON.parse(i)})}catch(o){if(a!=null&&a.fallbackToMemory){t.set(r(s),i);return}throw o}},async removeItem(s){try{await(await w()).kv.delete(r(s))}catch(i){if(a!=null&&a.fallbackToMemory){t.delete(r(s));return}throw i}}}}const N=n.z.object({unitId:n.z.string(),viewedDate:n.z.string()}),H=n.z.object({timezone:n.z.string(),favouriteUnits:n.z.array(n.z.string()).optional(),preferences:n.z.record(n.z.unknown())}),q=n.z.object({id:n.z.string(),slug:n.z.string(),favoritedUnits:n.z.array(n.z.string()),tourContactedOn:n.z.string().nullable(),viewedUnits:n.z.array(N),questionnaireResults:n.z.unknown().nullable().optional(),tourContactData:H.nullable().optional()}),ut=n.z.object({data:n.z.record(q),propertySlug:n.z.string().nullable(),propertyId:n.z.string().nullable(),hasPreviouslySearched:n.z.array(n.z.string())}),dt={data:{},propertySlug:null,propertyId:null,hasPreviouslySearched:[]};class J{async getState(){return await A("property")??dt}async setState(t){const e=await this.getState(),r=t(e);await E("property",r)}async setData(t){await this.setState(e=>({...e,data:t}))}async setPropertySlug(t){await this.setState(e=>({...e,propertySlug:t}))}async setPropertyId(t){await this.setState(e=>({...e,propertyId:t}))}async removeData(t){await this.setState(e=>({...e,data:Object.entries(e.data).filter(([r])=>r!==t).reduce((r,[s,i])=>({...r,[s]:i}),{})}))}async clearData(){await this.setState(t=>({...t,data:{}}))}async setHasPreviouslySearched(t){await this.setState(e=>({...e,hasPreviouslySearched:Array.from(new Set([...e.hasPreviouslySearched,t]))}))}async setTourContactedOn(){await this.setState(t=>{const e=t.propertyId;if(!e)return t;const r=t.data[e];return r?{...t,data:{...t.data,[e]:{...r,tourContactedOn:new Date().toISOString()}}}:t})}async getTourContactedOn(){var r;const t=await this.getState(),e=t.propertyId;return e?((r=t.data[e])==null?void 0:r.tourContactedOn)??null:null}async setQuestionnaireResults(t){await this.setState(e=>{const r=e.propertyId;if(!r)return e;const s=e.data[r];return s?{...e,data:{...e.data,[r]:{...s,questionnaireResults:t}}}:e})}async setTourContactData(t){await this.setState(e=>{const r=e.propertyId;if(!r)return e;const s=e.data[r];return s?{...e,data:{...e.data,[r]:{...s,tourContactData:t}}}:e})}async toggleFavorite(t){await this.setState(e=>{const r=e.propertyId;if(!r)return e;const s=e.data[r];if(!s)return e;const o=s.favoritedUnits.includes(t)?s.favoritedUnits.filter(c=>c!==t):[...s.favoritedUnits,t];return{...e,data:{...e.data,[r]:{...s,favoritedUnits:o}}}})}async markUnitAsViewed(t,e){const r=new Date,s=`${String(r.getMonth()+1).padStart(2,"0")}/${String(r.getDate()).padStart(2,"0")}`;await this.setState(i=>{const o=i.propertyId;if(!o)return i;const c=i.data[o];if(!c)return i;const u=[...c.viewedUnits.filter(y=>y.unitId!==t),{unitId:t,viewedDate:s}];return{...i,data:{...i.data,[o]:{...c,viewedUnits:u}}}}),typeof window<"u"&&window.open(`//${e}`,"_blank")}async getUnitState(t){var s;const e=await this.getState(),r=e.propertyId?e.data[e.propertyId]:null;return{isFavorite:(r==null?void 0:r.favoritedUnits.includes(t))??!1,viewedDate:((s=r==null?void 0:r.viewedUnits.find(i=>i.unitId===t))==null?void 0:s.viewedDate)??""}}async getPropertyData(t){const e=await this.getState(),r=t??e.propertyId;return r?e.data[r]??null:null}async getCurrentProperty(){const t=await this.getState();return t.propertyId?t.data[t.propertyId]??null:null}async getFullState(){return this.getState()}async initializeProperty(t,e){await this.setState(r=>r.data[t]?{...r,propertyId:t,propertySlug:e}:{...r,propertyId:t,propertySlug:e,data:{...r.data,[t]:{id:t,slug:e,favoritedUnits:[],tourContactedOn:null,viewedUnits:[],questionnaireResults:null,tourContactData:null}}})}}const yt=new J,G=n.z.object({isFavorite:n.z.boolean().optional(),viewedDate:n.z.string().optional()}),V=n.z.object({availability:n.z.union([n.z.string(),n.z.array(n.z.string())]).nullable().optional(),bedrooms:n.z.array(n.z.number()).nullable().optional(),cost:n.z.number().nullable().optional(),highlights:n.z.array(n.z.string()).optional()}),K=n.z.object({limit:n.z.number().default(10),page:n.z.number().default(1),availability:n.z.array(n.z.string()).optional(),bedrooms:n.z.array(n.z.number()).optional(),cost:n.z.number().nullable().optional(),highlights:n.z.array(n.z.string()).optional()}),pt=n.z.object({data:n.z.record(G),filters:V,tempFilters:V,apiFilters:K,resultsMode:n.z.enum(["all","bestFit","closestMatch","favorites"]),propertySlug:n.z.string().nullable(),resolvedQuestionnaireValues:n.z.record(n.z.array(n.z.string())),sortBy:n.z.enum(["relevance","newest","priceLowToHigh","priceHighToLow"]),filtersLoaded:n.z.boolean()});n.z.object({isFavorite:n.z.boolean().optional(),viewedDate:n.z.string().optional()});const wt=n.z.object({unitId:n.z.string(),viewedDate:n.z.string()}),ht=n.z.object({timezone:n.z.string(),favouriteUnits:n.z.array(n.z.string()).optional(),preferences:n.z.record(n.z.unknown())}),gt=n.z.object({id:n.z.string(),slug:n.z.string(),favoritedUnits:n.z.array(n.z.string()),tourContactedOn:n.z.string().nullable(),viewedUnits:n.z.array(wt),questionnaireResults:n.z.unknown().nullable().optional(),tourContactData:ht.nullable().optional()}),_=n.z.object({availability:n.z.union([n.z.string(),n.z.array(n.z.string())]).nullable().optional(),bedrooms:n.z.array(n.z.number()).nullable().optional(),cost:n.z.number().nullable().optional(),highlights:n.z.array(n.z.string()).optional()}),St=n.z.object({limit:n.z.number().default(10),page:n.z.number().default(1),availability:n.z.array(n.z.string()).optional(),bedrooms:n.z.array(n.z.number()).optional(),cost:n.z.number().nullable().optional(),highlights:n.z.array(n.z.string()).optional()}),ft=n.z.object({properties:n.z.record(gt),currentPropertyId:n.z.string().nullable(),currentPropertySlug:n.z.string().nullable(),hasPreviouslySearched:n.z.array(n.z.string()),filters:_,tempFilters:_,apiFilters:St,resultsMode:n.z.enum(["all","bestFit","closestMatch","favorites"]),resolvedQuestionnaireValues:n.z.record(n.z.array(n.z.string())),sortBy:n.z.enum(["relevance","newest","priceLowToHigh","priceHighToLow"]),filtersLoaded:n.z.boolean()}),M={availability:void 0,bedrooms:void 0,cost:void 0,highlights:void 0},k={properties:{},currentPropertyId:null,currentPropertySlug:null,hasPreviouslySearched:[],filters:M,tempFilters:M,apiFilters:{limit:10,page:1},resultsMode:"all",resolvedQuestionnaireValues:{},sortBy:"relevance",filtersLoaded:!1};class Z{async getState(){const t=await A("app");return t?{...k,...t,properties:t.properties??{}}:k}async setState(t){const e=await this.getState(),r=t(e);await E("app",r)}async initializeProperty(t,e){await this.setState(r=>r.properties&&r.properties[t]?{...r,currentPropertyId:t,currentPropertySlug:e}:{...r,currentPropertyId:t,currentPropertySlug:e,properties:{...r.properties,[t]:{id:t,slug:e,favoritedUnits:[],tourContactedOn:null,viewedUnits:[],questionnaireResults:null,tourContactData:null}}})}async setCurrentProperty(t,e){await this.setState(r=>({...r,currentPropertyId:t,currentPropertySlug:e||r.currentPropertySlug}))}async setCurrentPropertySlug(t){await this.setState(e=>({...e,currentPropertySlug:t}))}async setHasPreviouslySearched(t){await this.setState(e=>({...e,hasPreviouslySearched:Array.from(new Set([...e.hasPreviouslySearched,t]))}))}async toggleFavorite(t){await this.setState(e=>{const r=e.currentPropertyId;if(!r)return e;const s=e.properties[r];if(!s)return e;const o=s.favoritedUnits.includes(t)?s.favoritedUnits.filter(c=>c!==t):[...s.favoritedUnits,t];return{...e,properties:{...e.properties,[r]:{...s,favoritedUnits:o}}}})}async markUnitAsViewed(t,e){const r=new Date,s=`${String(r.getMonth()+1).padStart(2,"0")}/${String(r.getDate()).padStart(2,"0")}`;await this.setState(i=>{const o=i.currentPropertyId;if(!o)return i;const c=i.properties[o];if(!c)return i;const u=[...c.viewedUnits.filter(y=>y.unitId!==t),{unitId:t,viewedDate:s}];return{...i,properties:{...i.properties,[o]:{...c,viewedUnits:u}}}}),typeof window<"u"&&window.open(`//${e}`,"_blank")}async setTourContactedOn(){await this.setState(t=>{const e=t.currentPropertyId;if(!e)return t;const r=t.properties[e];return r?{...t,properties:{...t.properties,[e]:{...r,tourContactedOn:new Date().toISOString()}}}:t})}async getTourContactedOn(){var r;const t=await this.getState(),e=t.currentPropertyId;return e?((r=t.properties[e])==null?void 0:r.tourContactedOn)??null:null}async setQuestionnaireResults(t){await this.setState(e=>{const r=e.currentPropertyId;if(!r)return e;const s=e.properties[r];return s?{...e,properties:{...e.properties,[r]:{...s,questionnaireResults:t}}}:e})}async setTourContactData(t){await this.setState(e=>{const r=e.currentPropertyId;if(!r)return e;const s=e.properties[r];return s?{...e,properties:{...e.properties,[r]:{...s,tourContactData:t}}}:e})}async setFilters(t){await this.setState(e=>({...e,filters:{...e.filters,...t}}))}async setTempFilters(t){await this.setState(e=>({...e,tempFilters:{...e.tempFilters,...t}}))}async setFiltersToDefault(){await this.setState(t=>({...t,filters:M}))}async setApiFilters(t){await this.setState(e=>({...e,apiFilters:{...e.apiFilters,...t}}))}async handleTempFilterChange(t,e){await this.setState(r=>({...r,tempFilters:{...r.tempFilters,[t]:e}}))}async commitTempFilterChange(t,e){const s=(await this.getState()).tempFilters[t]??e;await this.handleTempFilterChange(t,s),await this.submitFilterUpdate()}async handleFilterCommitIndexDB(t){await this.setState(e=>{const r={...e.apiFilters,availability:t.availability||[],bedrooms:t.bedrooms||[],cost:t.cost||null,highlights:t.highlights||[]};return{...e,filters:{...e.filters,...t},apiFilters:r}})}async commitAvailabilityChange(){await this.submitFilterUpdate()}async submitFilterUpdate(){await this.setState(t=>{const e={...t.apiFilters,availability:t.filters.availability||[],bedrooms:t.filters.bedrooms||[],cost:t.filters.cost||null,highlights:t.filters.highlights||[]};return{...t,apiFilters:e}})}async setResultsMode(t){await this.setState(e=>({...e,resultsMode:t}))}async setSortBy(t){await this.setState(e=>({...e,sortBy:t}))}async setResolvedQuestionnaireValues(t,e){await this.setState(r=>({...r,resolvedQuestionnaireValues:{...r.resolvedQuestionnaireValues,[t]:e}}))}async getUnitState(t){var s;const e=await this.getState(),r=e.currentPropertyId?e.properties[e.currentPropertyId]:null;return{isFavorite:(r==null?void 0:r.favoritedUnits.includes(t))??!1,viewedDate:((s=r==null?void 0:r.viewedUnits.find(i=>i.unitId===t))==null?void 0:s.viewedDate)??""}}async getResultsUrl(){const t=await this.getState();return t.currentPropertySlug?`/${t.currentPropertySlug}/results`:null}async getCurrentProperty(){const t=await this.getState();return t.currentPropertyId?t.properties[t.currentPropertyId]??null:null}async getPropertyData(t){const e=await this.getState(),r=t??e.currentPropertyId;return r?e.properties[r]??null:null}async getFullState(){return this.getState()}async initialize(){const t=await this.getState();Object.keys(t.properties).length===0&&!t.filtersLoaded&&await this.setState(e=>({...k,...e,filtersLoaded:!0}))}async loadPersistedFilters(){await this.setState(t=>({...t,filtersLoaded:!0}))}async setData(t){await this.setState(e=>({...e,properties:t}))}async setPropertySlug(t){await this.setCurrentPropertySlug(t)}async setPropertyId(t){await this.setCurrentProperty(t)}async removeData(t){await this.setState(e=>{const{[t]:r,...s}=e.properties;return{...e,properties:s}})}async clearData(){await this.setState(t=>({...t,properties:{}}))}}const l=new Z,m=1,g=n.z.object({uuid:n.z.string().uuid()}),z=n.z.object({propertyId:n.z.string()||n.z.number(),unitIds:n.z.array(n.z.string())}),v="user",Y=()=>{var a;return typeof((a=globalThis.crypto)==null?void 0:a.randomUUID)=="function"?globalThis.crypto.randomUUID():(()=>{var r,s;const t=((s=(r=globalThis.crypto)==null?void 0:r.getRandomValues)==null?void 0:s.call(r,new Uint8Array(16)))??Uint8Array.from({length:16},()=>Math.random()*256|0);t[6]=t[6]&15|64,t[8]=t[8]&63|128;const e=[...t].map(i=>i.toString(16).padStart(2,"0")).join("");return`${e.slice(0,8)}-${e.slice(8,12)}-${e.slice(12,16)}-${e.slice(16,20)}-${e.slice(20)}`})()},T=a=>{var t,e;return((t=a==null?void 0:a.value)==null?void 0:t.useruuid)??((e=a==null?void 0:a.value)==null?void 0:e.uuid)};async function P(a=Y){const t=await w(),e=T(await t.kv.get(v));if(e){const r=await t.users.get(e);if(r)return g.parse(r)}try{return await t.transaction("rw",t.kv,t.users,async()=>{const r=T(await t.kv.get(v));if(r){const o=await t.users.get(r);if(o)return g.parse(o)}const s=a();await t.kv.add({key:v,value:{useruuid:s}});const i=g.parse({uuid:s,createdAt:new Date().toISOString()});return await t.users.add(i),i})}catch(r){if((r==null?void 0:r.name)==="ConstraintError"){const s=T(await t.kv.get(v));if(s){const i=await t.users.get(s);if(i)return g.parse(i)}}throw r}}const mt=async a=>(await P(a)).uuid;async function W(){const a=await w(),t={};for(const e of a.tables)t[e.name]=await e.toArray();return t}async function vt(a="inresi-orm-export.json"){if(typeof window>"u"||typeof document>"u")throw new Error("exportJSON can only run in a browser.");const t=await W(),e=new Blob([JSON.stringify(t,null,2)],{type:"application/json"}),r=document.createElement("a");r.href=URL.createObjectURL(e),r.download=a,document.body.appendChild(r),r.click(),r.remove(),URL.revokeObjectURL(r.href)}const X=(a,t)=>`favorites:${a}:${t}`;async function F(a){const t=await w(),{uuid:e}=await P(),r=X(e,String(a)),s=await t.kv.get(r),i=s?z.safeParse(s.value):null;return i!=null&&i.success?i.data.unitIds:[]}async function j(a,t,e){const r=await w(),{uuid:s}=await P(),i=X(s,String(a));return r.transaction("rw",r.kv,async()=>{const o=await r.kv.get(i),c=o&&z.safeParse(o.value).success?o.value:{unitIds:[],updatedAt:new Date().toISOString()},u=new Set(c.unitIds);e?u.add(t):u.delete(t);const y={unitIds:[...u],updatedAt:new Date().toISOString()},p=z.parse(y);return await r.kv.put({key:i,value:p}),p.unitIds})}async function tt(a,t){const r=!(await F(a)).includes(t);return j(a,t,r)}async function et(a,t){return(await F(a)).includes(t)}function $(a){return(t,e)=>{const r=async()=>{const i=await l.getFullState();t({properties:i.properties,currentPropertyId:i.currentPropertyId,currentPropertySlug:i.currentPropertySlug,hasPreviouslySearched:i.hasPreviouslySearched,filters:i.filters,tempFilters:i.tempFilters,apiFilters:i.apiFilters,resultsMode:i.resultsMode,resolvedQuestionnaireValues:i.resolvedQuestionnaireValues,sortBy:i.sortBy,filtersLoaded:i.filtersLoaded})},s=async()=>{if(a!=null&&a.onFilterUpdate){const i=(await l.getFullState()).apiFilters;a.onFilterUpdate(i)}};return{properties:{},currentPropertyId:null,currentPropertySlug:null,hasPreviouslySearched:[],units:{},filters:{availability:void 0,bedrooms:void 0,cost:void 0,highlights:void 0},tempFilters:{availability:void 0,bedrooms:void 0,cost:void 0,highlights:void 0},apiFilters:{limit:10,page:1},resultsMode:"all",resolvedQuestionnaireValues:{},sortBy:"relevance",filtersLoaded:!1,async initializeProperty(i,o){await l.initializeProperty(i,o),await r()},async setCurrentProperty(i,o){await l.setCurrentProperty(i,o),t({currentPropertyId:i,...o&&{currentPropertySlug:o}})},async setCurrentPropertySlug(i){await l.setCurrentPropertySlug(i),t({currentPropertySlug:i})},async setHasPreviouslySearched(i){await l.setHasPreviouslySearched(i),await r()},async toggleFavorite(i){await l.toggleFavorite(i),await r()},async markUnitAsViewed(i,o){await l.markUnitAsViewed(i,o),await r()},async setTourContactedOn(){await l.setTourContactedOn(),await r()},getTourContactedOn:l.getTourContactedOn.bind(l),async setQuestionnaireResults(i){await l.setQuestionnaireResults(i),await r()},async setTourContactData(i){await l.setTourContactData(i),await r()},async setFilters(i){await l.setFilters(i);const o=e();t({filters:{...o.filters,...i}})},async setTempFilters(i){await l.setTempFilters(i);const o=e();t({tempFilters:{...o.tempFilters,...i}})},async setFiltersToDefault(){await l.setFiltersToDefault(),t({filters:{availability:void 0,bedrooms:void 0,cost:void 0,highlights:void 0}})},async setApiFilters(i){await l.setApiFilters(i);const o=e();t({apiFilters:{...o.apiFilters,...i}})},async handleTempFilterChange(i,o){await l.handleTempFilterChange(i,o);const c=e();t({tempFilters:{...c.tempFilters,[i]:o}})},async commitTempFilterChange(i,o){await l.commitTempFilterChange(i,o),await r(),await s()},async handleFilterCommitIndexDB(i){await l.handleFilterCommitIndexDB(i),await r(),await s()},async commitAvailabilityChange(){await l.commitAvailabilityChange(),await r(),await s()},async submitFilterUpdate(){await l.submitFilterUpdate(),await r(),await s()},async setResultsMode(i){await l.setResultsMode(i),t({resultsMode:i})},async setSortBy(i){await l.setSortBy(i),t({sortBy:i})},async setResolvedQuestionnaireValues(i,o){await l.setResolvedQuestionnaireValues(i,o);const c=e();t({resolvedQuestionnaireValues:{...c.resolvedQuestionnaireValues,[i]:o}})},getUnitState(i){var u;const o=e(),c=o.currentPropertyId?o.properties[o.currentPropertyId]:null;return{isFavorite:(c==null?void 0:c.favoritedUnits.includes(i))??!1,viewedDate:((u=c==null?void 0:c.viewedUnits.find(y=>y.unitId===i))==null?void 0:u.viewedDate)??""}},getResultsUrl:l.getResultsUrl.bind(l),getCurrentProperty:l.getCurrentProperty.bind(l),getPropertyData:l.getPropertyData.bind(l),async setData(i){await l.setData(i),t({properties:i})},async setPropertySlug(i){await l.setPropertySlug(i),t({currentPropertySlug:i})},async setPropertyId(i){await l.setPropertyId(i),t({currentPropertyId:i})},async removeData(i){await l.removeData(i),await r()},async clearData(){await l.clearData(),t({properties:{}})},async loadPersistedFilters(){await l.loadPersistedFilters(),t({filtersLoaded:!0})},async _hydrate(){await r()},async _initialize(){await l.initialize(),await r()}}}}function bt(){return a=>t=>a(e=>e.getUnitState(t))}function rt(a){return{property:{unit:{favorites:{toggle:a.toggleFavorite.bind(a)},viewed:{mark:a.markUnitAsViewed.bind(a)}},questionnaire:{setResults:a.setQuestionnaireResults.bind(a)},tour:{setContactedOn:a.setTourContactedOn.bind(a),getContactedOn:a.getTourContactedOn.bind(a),setContactData:a.setTourContactData.bind(a)}},filters:{set:a.setFilters.bind(a),setTemp:a.setTempFilters.bind(a),setToDefault:a.setFiltersToDefault.bind(a),commitTemp:a.commitTempFilterChange.bind(a),commitAvailability:a.commitAvailabilityChange.bind(a),submit:a.submitFilterUpdate.bind(a)}}}function zt(a){return(t,e)=>{const r=$(a)(t,e),s=rt(r);return{...r,...s}}}const Pt={async isFavorite(a,t){return et(a,t)},async toggle(a,t){return tt(a,t)},async set(a,t,e){return j(a,t,e)},async getAll(a){return F(a)}};exports.AppStoreDataSchema=pt;exports.FavoritesSchema=z;exports.FiltersSchema=V;exports.OpenDBError=Q;exports.PropertyDataSchema=q;exports.PropertyStore=J;exports.PropertyStoreDataSchema=ut;exports.QueryParamsSchema=K;exports.SCHEMA_VERSION=m;exports.SchemaMismatchError=B;exports.TourContactDataSchema=H;exports.UnifiedStore=Z;exports.UnifiedStoreDataSchema=ft;exports.UnitDataSchema=G;exports.UserSchema=g;exports.ViewedUnitSchema=N;exports.configureValidation=x;exports.createORMStringStorage=lt;exports.createStructuredStore=zt;exports.createStructuredStoreActions=rt;exports.createUseUnitState=bt;exports.createZustandPropertyStore=$;exports.createZustandUnifiedStore=$;exports.debugDump=W;exports.defaultIdGenerator=Y;exports.ensureUser=P;exports.exportJSON=vt;exports.favorites=Pt;exports.getDB=w;exports.getFavoritedUnitsForProperty=F;exports.getUserUUID=mt;exports.isUnitFavorited=et;exports.kvGet=A;exports.kvRemove=ct;exports.kvSet=E;exports.propertyStore=yt;exports.resetDB=ot;exports.setFavoriteUnit=j;exports.store=l;exports.toggleFavoriteUnit=tt;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("zod"),vt=require("dexie");var V=typeof document<"u"?document.currentScript:null;class rt extends Error{constructor(t,e){super(t),this.detail=e,this.name="SchemaMismatchError"}}class nt extends Error{constructor(t,e){super(t),this.detail=e,this.name="OpenDBError"}}const z=1,h=n.z.object({uuid:n.z.string().uuid(),createdAt:n.z.string().datetime().optional()}),at=n.z.object({isFavorite:n.z.boolean().optional(),viewedDate:n.z.string().optional()}),it=at,O=n.z.union([n.z.string(),n.z.number(),n.z.boolean(),n.z.record(n.z.unknown())]),bt=n.z.union([O,n.z.array(O)]),U=n.z.object({availability:bt.nullable().optional(),bedrooms:n.z.union([n.z.array(O),n.z.null()]).optional(),cost:n.z.number().nullable().optional(),highlights:n.z.array(O).optional()}),Q=n.z.object({limit:n.z.number().default(10),page:n.z.number().default(1),availability:n.z.array(n.z.string()).optional(),bedrooms:n.z.array(n.z.number()).optional(),cost:n.z.number().nullable().optional(),highlights:n.z.array(n.z.string()).optional()}),H=n.z.enum(["all","bestFit","closestMatch","favorites","loading"]),q=n.z.enum(["relevance","newest","priceLowToHigh","priceHighToLow"]),zt=n.z.object({data:n.z.record(it),filters:U,tempFilters:U,apiFilters:Q,resultsMode:H,propertySlug:n.z.string().nullable(),resolvedQuestionnaireValues:n.z.record(n.z.array(n.z.string())),sortBy:q}),v=n.z.object({id:n.z.union([n.z.number().int(),n.z.string()]).optional(),title:n.z.string(),slug:n.z.string().nullable().optional(),bedrooms:n.z.coerce.number().nullable().optional(),bathrooms:n.z.coerce.number().nullable().optional(),cost:n.z.coerce.number().nullable().optional(),totalSqFt:n.z.coerce.number().nullable().optional(),propertyId:n.z.union([n.z.number().int(),n.z.string()]).optional(),isAvailable:n.z.boolean().optional(),createdAt:n.z.string().datetime().optional(),updatedAt:n.z.string().datetime().optional(),availability:n.z.string().datetime().nullable().optional(),unitSetAvailableOn:n.z.string().datetime().nullable().optional(),floorPlanId:n.z.union([n.z.number().int(),n.z.string()]).nullable().optional(),property:n.z.unknown().optional(),amenities:n.z.array(n.z.unknown()).optional(),highlights:n.z.array(n.z.unknown()).optional(),floorPlan:n.z.unknown().nullable().optional(),renderedStyle:n.z.array(n.z.unknown()).optional(),video:n.z.unknown().nullable().optional(),videoThumbnail:n.z.unknown().nullable().optional(),embedGif:n.z.unknown().nullable().optional(),userId:n.z.union([n.z.number().int(),n.z.string()]).optional(),user:n.z.unknown().optional(),status:n.z.string().optional(),externalId:n.z.string().nullable().optional(),unitRenderedStyles:n.z.array(n.z.unknown()).optional()}),w=n.z.object({id:n.z.union([n.z.number().int(),n.z.string()]),createdAt:n.z.string().datetime(),updatedAt:n.z.string().datetime(),title:n.z.string(),slug:n.z.string().nullable().optional(),description:n.z.string(),contactName:n.z.string().nullable().optional(),contactEmail:n.z.string().optional(),contactPhone:n.z.string().nullable().optional(),notificationEmail:n.z.string().nullable().optional(),logo:n.z.unknown().nullable().optional(),leadMedia:n.z.unknown().nullable().optional(),overviewImages:n.z.array(n.z.unknown()).optional(),amenityImages:n.z.array(n.z.unknown()).optional(),street:n.z.string().optional(),city:n.z.string().optional(),state:n.z.string().nullable().optional(),ingestionFileName:n.z.string().nullable().optional(),zip:n.z.string().optional(),country:n.z.string().optional(),units:n.z.array(v).optional(),amenities:n.z.array(n.z.unknown()).optional(),highlights:n.z.array(n.z.unknown()).optional(),externalServices:n.z.array(n.z.unknown()).optional(),userId:n.z.union([n.z.number().int(),n.z.string()]).optional(),user:n.z.unknown().optional(),status:n.z.string().optional(),floorPlans:n.z.array(n.z.unknown()).optional()}),Ut=n.z.object({id:n.z.union([n.z.number().int(),n.z.string()]).optional(),email:n.z.string().email().optional(),firstName:n.z.string().optional(),lastName:n.z.string().optional(),password:n.z.string().optional(),salt:n.z.string().optional(),role:n.z.string().optional(),Property:n.z.array(w).optional(),Unit:n.z.array(v).optional(),floorPlans:n.z.array(n.z.unknown()).optional(),createdAt:n.z.string().datetime().optional(),updatedAt:n.z.string().datetime().optional()}),ot=n.z.object({unitId:n.z.string(),viewedDate:n.z.string()}),st=n.z.object({timezone:n.z.string().optional(),favouriteUnits:n.z.array(n.z.coerce.string()).optional(),preferences:n.z.record(n.z.unknown()).optional()}),P=n.z.object({id:n.z.coerce.string(),slug:n.z.string(),favoritedUnits:n.z.array(n.z.string()),tourContactedOn:n.z.string().nullable(),viewedUnits:n.z.array(ot),questionnaireResults:n.z.unknown().nullable().optional(),tourContactData:st.nullable().optional(),data:w.optional()}),R=n.z.object({data:n.z.record(P),propertySlug:n.z.string().nullable(),propertyId:n.z.string().nullable(),hasPreviouslySearched:n.z.array(n.z.string())}),Pt=n.z.object({id:n.z.number().int(),userId:n.z.number().int(),unitId:n.z.number().int(),createdAt:n.z.string().datetime()}),T=n.z.object({unitIds:n.z.array(n.z.string()),updatedAt:n.z.string().datetime()}),D=n.z.object({properties:n.z.record(P),currentPropertyId:n.z.string().nullable(),currentPropertySlug:n.z.string().nullable(),hasPreviouslySearched:n.z.array(n.z.string()),unitResults:n.z.array(v),filters:U,tempFilters:U,apiFilters:Q,resultsMode:H,resolvedQuestionnaireValues:n.z.record(n.z.array(n.z.string())),sortBy:q});class x extends vt{constructor(t="inresi-orm"){super(t),this.version(z).stores({users:"uuid",kv:"key"}),this.users=this.table("users"),this.kv=this.table("kv")}}let B="strict",k;function lt(r){r.mode&&(B=r.mode),k=r.onIssue}function S(r,t,e){const a=r.safeParse(t);if(a.success)return a.data;const o=a.error.flatten();if(k==null||k(e,o),B==="strict")throw new rt(`ORM schema mismatch in ${e}`,o);return B==="warn"&&console.warn(`ORM schema mismatch in ${e}`,o),null}const Ft={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},_="manifest",It=n.z.object({schemaVersion:n.z.number().int()});let m=null,b=null;const tt=Symbol("validationInstalled");function N(r,t){const e=r;if(e[tt])return;if(e[tt]=!0,((i,s,l)=>{i.hook("creating",(u,c)=>{const y=S(s,c,`${l}.creating`);if(!y)throw new Error(`Rejected invalid ${l} on create`);return y}),i.hook("updating",(u,c,y)=>{const p={...y,...u};return S(s,p,`${l}.updating`)?u:{}})})(r.users,h,"users"),(t==null?void 0:t.validateReads)??!0){const i=(t==null?void 0:t.dropInvalidOnRead)??!0;((l,u,c)=>{l.hook("reading",y=>{const p=S(u,y,`${c}.reading`);return p||(i?void 0:y)})})(r.users,h,"users")}}function Rt(){try{if(typeof{url:typeof document>"u"?require("url").pathToFileURL(__filename).href:V&&V.tagName.toUpperCase()==="SCRIPT"&&V.src||new URL("index.cjs",document.baseURI).href}<"u"&&Ft)return!1}catch{}try{if(typeof process<"u"&&process.env)return process.env.NODE_ENV!=="production"}catch{}return!1}async function g(r={}){if(m)return m;if(b)return b;const t=r.dbName??"inresi-orm";return b=(async()=>{var e,a,o,i;try{const s=Rt()?"warn":"strict";lt({mode:((e=r.validation)==null?void 0:e.mode)??s,onIssue:(a=r.validation)==null?void 0:a.onIssue});const l=new x(t);l.on("versionchange",()=>{var p;try{l.close()}finally{(p=r.onReset)==null||p.call(r,"versionchange")}}),l.on("blocked",()=>{var p;(p=r.onReset)==null||p.call(r,"blocked")}),await l.open();const u=await l.kv.get(_),c=(u==null?void 0:u.value)??null;if(!c)return await l.transaction("rw",l.kv,async()=>{await l.kv.put({key:_,value:{schemaVersion:z}})}),N(l,r.validation),m=l,l;const y=It.safeParse(c);if(!y.success||y.data.schemaVersion!==z){await l.delete();const p=new x(t);return p.on("versionchange",()=>{var f;try{p.close()}finally{(f=r.onReset)==null||f.call(r,"versionchange")}}),p.on("blocked",()=>{var f;(f=r.onReset)==null||f.call(r,"blocked")}),await p.open(),await p.kv.put({key:_,value:{schemaVersion:z}}),N(p,r.validation),(o=r.onReset)==null||o.call(r,"incompatible"),m=p,p}return N(l,r.validation),m=l,l}catch(s){throw(i=r.onError)==null||i.call(r,s),new nt("Failed to open IndexedDB",s)}finally{b=null}})(),b}async function Dt(r){const t=r??"inresi-orm";if(m)try{await m.close()}catch{}await new x(t).delete(),m=null}const F="user",ut=()=>{var r;return typeof((r=globalThis.crypto)==null?void 0:r.randomUUID)=="function"?globalThis.crypto.randomUUID():(()=>{var a,o;const t=((o=(a=globalThis.crypto)==null?void 0:a.getRandomValues)==null?void 0:o.call(a,new Uint8Array(16)))??Uint8Array.from({length:16},()=>Math.random()*256|0);t[6]=t[6]&15|64,t[8]=t[8]&63|128;const e=[...t].map(i=>i.toString(16).padStart(2,"0")).join("");return`${e.slice(0,8)}-${e.slice(8,12)}-${e.slice(12,16)}-${e.slice(16,20)}-${e.slice(20)}`})()},$=r=>{var t,e;return((t=r==null?void 0:r.value)==null?void 0:t.useruuid)??((e=r==null?void 0:r.value)==null?void 0:e.uuid)};async function E(r=ut){const t=await g(),e=$(await t.kv.get(F));if(e){const a=await t.users.get(e);if(a)return h.parse(a)}try{return await t.transaction("rw",t.kv,t.users,async()=>{const a=$(await t.kv.get(F));if(a){const s=await t.users.get(a);if(s)return h.parse(s)}const o=r();await t.kv.add({key:F,value:{useruuid:o}});const i=h.parse({uuid:o,createdAt:new Date().toISOString()});return await t.users.add(i),i})}catch(a){if((a==null?void 0:a.name)==="ConstraintError"){const o=$(await t.kv.get(F));if(o){const i=await t.users.get(o);if(i)return h.parse(i)}}throw a}}const kt=async r=>(await E(r)).uuid;async function ct(){const r=await g(),t={};for(const e of r.tables)t[e.name]=await e.toArray();return t}async function At(r="inresi-orm-export.json"){if(typeof window>"u"||typeof document>"u")throw new Error("exportJSON can only run in a browser.");const t=await ct(),e=new Blob([JSON.stringify(t,null,2)],{type:"application/json"}),a=document.createElement("a");a.href=URL.createObjectURL(e),a.download=r,document.body.appendChild(a),a.click(),a.remove(),URL.revokeObjectURL(a.href)}async function G(r){const e=await(await g()).kv.get(r);return(e==null?void 0:e.value)??null}async function J(r,t){await(await g()).kv.put({key:r,value:t})}async function Ct(r){await(await g()).kv.delete(r)}function Ot(r){const t=new Map,e=(r==null?void 0:r.prefix)??"",a=o=>`${e}${o}`;return{async getItem(o){try{const s=await(await g()).kv.get(a(o));return s?JSON.stringify(s.value):null}catch(i){if(r!=null&&r.fallbackToMemory)return t.get(a(o))??null;throw i}},async setItem(o,i){try{await(await g()).kv.put({key:a(o),value:JSON.parse(i)})}catch(s){if(r!=null&&r.fallbackToMemory){t.set(a(o),i);return}throw s}},async removeItem(o){try{await(await g()).kv.delete(a(o))}catch(i){if(r!=null&&r.fallbackToMemory){t.delete(a(o));return}throw i}}}}const dt=(r,t)=>`favorites:${r}:${t}`;async function M(r){const t=await g(),{uuid:e}=await E(),a=dt(e,String(r)),o=await t.kv.get(a),i=o?T.safeParse(o.value):null;return i!=null&&i.success?i.data.unitIds:[]}async function K(r,t,e){const a=await g(),{uuid:o}=await E(),i=dt(o,String(r));return a.transaction("rw",a.kv,async()=>{const s=await a.kv.get(i),l=s&&T.safeParse(s.value).success?s.value:{unitIds:[],updatedAt:new Date().toISOString()},u=new Set(l.unitIds);e?u.add(t):u.delete(t);const c={unitIds:[...u],updatedAt:new Date().toISOString()},y=T.parse(c);return await a.kv.put({key:i,value:y}),y.unitIds})}async function pt(r,t){const a=!(await M(r)).includes(t);return K(r,t,a)}async function yt(r,t){return(await M(r)).includes(t)}const j={data:{},propertySlug:null,propertyId:null,hasPreviouslySearched:[]};class ft{async getState(){const t=await G("property");if(!t)return j;const e={...t,propertyId:t.propertyId==null?null:String(t.propertyId),propertySlug:t.propertySlug??null,hasPreviouslySearched:Array.isArray(t.hasPreviouslySearched)?t.hasPreviouslySearched.map(String):[]},a=R.safeParse(e);if(a.success)return a.data;const o=Object.entries(e.data??{}).reduce((l,[u,c])=>{const y=P.safeParse(c);return y.success&&(l[u]=y.data),l},{}),i={...j,...e,data:o},s=R.safeParse(i);return s.success?s.data:j}async setState(t){const e=await this.getState(),a=t(e),o=R.parse(a);await J("property",o)}async setHasPreviouslySearched(t){await this.setState(e=>({...e,hasPreviouslySearched:Array.from(new Set([...e.hasPreviouslySearched,t]))}))}async setTourContactedOn(){await this.setState(t=>{const e=t.propertyId;if(!e)return t;const a=t.data[e];return a?{...t,data:{...t.data,[e]:{...a,tourContactedOn:new Date().toISOString()}}}:t})}async getTourContactedOn(){var a;const t=await this.getState(),e=t.propertyId;return e?((a=t.data[e])==null?void 0:a.tourContactedOn)??null:null}async setQuestionnaireResults(t){await this.setState(e=>{const a=e.propertyId;if(!a)return e;const o=e.data[a];return o?{...e,data:{...e.data,[a]:{...o,questionnaireResults:t}}}:e})}async setTourContactData(t){await this.setState(e=>{const a=e.propertyId;if(!a)return e;const o=e.data[a];return o?{...e,data:{...e.data,[a]:{...o,tourContactData:t}}}:e})}async toggleFavorite(t){await this.setState(e=>{const a=e.propertyId;if(!a)return e;const o=e.data[a];if(!o)return e;const s=o.favoritedUnits.includes(t)?o.favoritedUnits.filter(l=>l!==t):[...o.favoritedUnits,t];return{...e,data:{...e.data,[a]:{...o,favoritedUnits:s}}}})}async markUnitAsViewed(t,e){const a=new Date,o=`${String(a.getMonth()+1).padStart(2,"0")}/${String(a.getDate()).padStart(2,"0")}`;await this.setState(i=>{const s=i.propertyId;if(!s)return i;const l=i.data[s];if(!l)return i;const u=[...l.viewedUnits.filter(c=>c.unitId!==t),{unitId:t,viewedDate:o}];return{...i,data:{...i.data,[s]:{...l,viewedUnits:u}}}}),typeof window<"u"&&window.open(`//${e}`,"_blank")}async getUnitState(t){var o;const e=await this.getState(),a=e.propertyId?e.data[e.propertyId]:null;return{isFavorite:(a==null?void 0:a.favoritedUnits.includes(t))??!1,viewedDate:((o=a==null?void 0:a.viewedUnits.find(i=>i.unitId===t))==null?void 0:o.viewedDate)??""}}async getPropertyData(t){const e=await this.getState(),a=t==null?e.propertyId:String(t);return a?e.data[a]??null:null}async getCurrentProperty(){const t=await this.getState();return t.propertyId?t.data[t.propertyId]??null:null}async getFullState(){return this.getState()}async initializeProperty(t,e){const a=String(t);await this.setState(o=>o.data[a]?{...o,propertyId:a,propertySlug:e}:{...o,propertyId:a,propertySlug:e,data:{...o.data,[a]:{id:a,slug:e,favoritedUnits:[],tourContactedOn:null,viewedUnits:[],questionnaireResults:null,tourContactData:null}}})}}const Tt=new ft,L={availability:void 0,bedrooms:void 0,cost:void 0,highlights:void 0},I={properties:{},currentPropertyId:null,currentPropertySlug:null,hasPreviouslySearched:[],unitResults:[],filters:L,tempFilters:L,apiFilters:{limit:10,page:1},resultsMode:"all",resolvedQuestionnaireValues:{},sortBy:"relevance"},Et=r=>r==null?[]:Array.isArray(r)?r:[r],gt=r=>Et(r).flatMap(t=>{if(t==null)return[];if(Array.isArray(t))return t;if(typeof t=="object"&&"value"in t){const e=t.value;return Array.isArray(e)?e:e!=null?[e]:[]}return[t]}),et=r=>gt(r).flatMap(t=>Array.isArray(t)?t:[t]).map(t=>String(t)).map(t=>t.trim()).filter(t=>t.length>0),Mt=r=>gt(r).map(t=>{if(typeof t=="number"&&Number.isFinite(t))return t;const e=Number(t);return Number.isFinite(e)?e:null}).filter(t=>t!==null),St=r=>{if(r==null)return null;if(typeof r=="number")return Number.isFinite(r)?r:null;if(typeof r=="object"&&"value"in r)return St(r.value);const t=Number(r);return Number.isFinite(t)?t:null};class W{async getState(){const t=await G("app");if(!t)return I;const e={...I,...t,properties:t.properties??{},unitResults:t.unitResults??[],currentPropertyId:t.currentPropertyId==null?null:String(t.currentPropertyId),currentPropertySlug:t.currentPropertySlug??null,hasPreviouslySearched:Array.isArray(t.hasPreviouslySearched)?t.hasPreviouslySearched.map(String):[]},a=D.safeParse(e);if(a.success)return a.data;const o=Object.entries(e.properties??{}).reduce((c,[y,p])=>{const f=P.safeParse(p);return f.success&&(c[y]=f.data),c},{}),s=(Array.isArray(e.unitResults)?e.unitResults:e.unitResults&&typeof e.unitResults=="object"?Object.values(e.unitResults):[]).reduce((c,y)=>{const p=v.safeParse(y);return p.success&&c.push(p.data),c},[]),l={...e,properties:o,unitResults:s},u=D.safeParse(l);return u.success?u.data:I}async setState(t){const e=await this.getState(),a=t(e),o=D.parse(a);await J("app",o)}async initializeProperty(t,e){const a=String(t);await this.setState(o=>o.properties&&o.properties[a]?{...o,currentPropertyId:a,currentPropertySlug:e}:{...o,currentPropertyId:a,currentPropertySlug:e,properties:{...o.properties,[a]:{id:a,slug:e,favoritedUnits:[],tourContactedOn:null,viewedUnits:[],questionnaireResults:null,tourContactData:null}}})}async setUnitResults(t,e){const a=e??v,o=[];(Array.isArray(t)?t:t&&typeof t=="object"?Object.values(t):[]).forEach((s,l)=>{const u=S(a,s,`unitResults[${l}]`);u&&o.push(u)}),await this.setState(s=>({...s,unitResults:o}))}async clearUnitResults(){await this.setState(t=>({...t,unitResults:[]}))}async setPropertyData(t,e,a){const o=String(t),i=a??w;await this.setState(s=>{const l=s.properties[o];if(!l)return s;const u=S(i,e,`properties.${o}.data`);return u?{...s,properties:{...s.properties,[o]:{...l,data:u}}}:s})}async mergePropertyData(t,e,a){const o=String(t),i=a??w;await this.setState(s=>{const l=s.properties[o];if(!l)return s;const u=l.data;if(!u){const f=S(i,e,`properties.${o}.data`);return f?{...s,properties:{...s.properties,[o]:{...l,data:f}}}:s}const c=i.partial(),y=S(c,e,`properties.${o}.data.partial`);if(!y)return s;const p=S(i,{...u,...y},`properties.${o}.data`);return p?{...s,properties:{...s.properties,[o]:{...l,data:p}}}:s})}async upsertPropertyFromApi(t,e){const o=(e??w).parse(t),i=o.id??o.propertyId;if(i==null)throw new Error("upsertPropertyFromApi: property id is required");const s=String(i),l=o.slug??void 0;await this.setState(u=>{const c=u.properties[s],y=c?{...c,...l?{slug:l}:{},data:o}:{id:s,slug:l??"",favoritedUnits:[],tourContactedOn:null,viewedUnits:[],questionnaireResults:null,tourContactData:null,data:o};return{...u,properties:{...u.properties,[s]:y}}})}async setCurrentProperty(t,e){const a=String(t);await this.setState(o=>({...o,currentPropertyId:a,currentPropertySlug:e||o.currentPropertySlug}))}async setCurrentPropertySlug(t){await this.setState(e=>({...e,currentPropertySlug:t}))}async setHasPreviouslySearched(t){await this.setState(e=>({...e,hasPreviouslySearched:Array.from(new Set([...e.hasPreviouslySearched,t]))}))}async toggleFavorite(t){await this.setState(e=>{const a=e.currentPropertyId;if(!a)return e;const o=e.properties[a];if(!o)return e;const s=o.favoritedUnits.includes(t)?o.favoritedUnits.filter(l=>l!==t):[...o.favoritedUnits,t];return{...e,properties:{...e.properties,[a]:{...o,favoritedUnits:s}}}})}async markUnitAsViewed(t,e){const a=new Date,o=`${String(a.getMonth()+1).padStart(2,"0")}/${String(a.getDate()).padStart(2,"0")}`;await this.setState(i=>{const s=i.currentPropertyId;if(!s)return i;const l=i.properties[s];if(!l)return i;const u=[...l.viewedUnits.filter(c=>c.unitId!==t),{unitId:t,viewedDate:o}];return{...i,properties:{...i.properties,[s]:{...l,viewedUnits:u}}}}),typeof window<"u"&&window.open(`//${e}`,"_blank")}async setTourContactedOn(){await this.setState(t=>{const e=t.currentPropertyId;if(!e)return t;const a=t.properties[e];return a?{...t,properties:{...t.properties,[e]:{...a,tourContactedOn:new Date().toISOString()}}}:t})}async getTourContactedOn(){var a;const t=await this.getState(),e=t.currentPropertyId;return e?((a=t.properties[e])==null?void 0:a.tourContactedOn)??null:null}async setQuestionnaireResults(t){await this.setState(e=>{const a=e.currentPropertyId;if(!a)return e;const o=e.properties[a];return o?{...e,properties:{...e.properties,[a]:{...o,questionnaireResults:t}}}:e})}async setTourContactData(t){await this.setState(e=>{const a=e.currentPropertyId;if(!a)return e;const o=e.properties[a];return o?{...e,properties:{...e.properties,[a]:{...o,tourContactData:t}}}:e})}async setFilters(t){await this.setState(e=>({...e,filters:{...e.filters,...t}}))}async setTempFilters(t){await this.setState(e=>({...e,tempFilters:{...e.tempFilters,...t}}))}async setFiltersToDefault(){await this.setState(t=>({...t,filters:L}))}async setApiFilters(t){await this.setState(e=>({...e,apiFilters:{...e.apiFilters,...t}}))}async handleTempFilterChange(t,e){await this.setState(a=>({...a,tempFilters:{...a.tempFilters,[t]:e}}))}async submitFilterUpdate(){await this.setState(t=>{const e={...t.apiFilters,availability:et(t.filters.availability),bedrooms:Mt(t.filters.bedrooms),cost:St(t.filters.cost),highlights:et(t.filters.highlights)};return{...t,apiFilters:e}})}async setResultsMode(t){await this.setState(e=>({...e,resultsMode:t}))}async setSortBy(t){await this.setState(e=>({...e,sortBy:t}))}async setResolvedQuestionnaireValues(t,e){await this.setState(a=>({...a,resolvedQuestionnaireValues:{...a.resolvedQuestionnaireValues,[t]:e}}))}async getUnitState(t){var o;const e=await this.getState(),a=e.currentPropertyId?e.properties[e.currentPropertyId]:null;return{isFavorite:(a==null?void 0:a.favoritedUnits.includes(t))??!1,viewedDate:((o=a==null?void 0:a.viewedUnits.find(i=>i.unitId===t))==null?void 0:o.viewedDate)??""}}async getResultsUrl(){const t=await this.getState();return t.currentPropertySlug?`/${t.currentPropertySlug}/results`:null}async getCurrentProperty(){const t=await this.getState();return t.currentPropertyId?t.properties[t.currentPropertyId]??null:null}async getPropertyData(t){const e=await this.getState(),a=t==null?e.currentPropertyId:String(t);return a?e.properties[a]??null:null}async getFullState(){return this.getState()}async initialize(){await this.setState(t=>({...I,...t}))}}const d=new W;function mt(r){return(t,e)=>{const a=async()=>{const i=await d.getFullState();t({properties:i.properties,currentPropertyId:i.currentPropertyId,currentPropertySlug:i.currentPropertySlug,hasPreviouslySearched:i.hasPreviouslySearched,unitResults:i.unitResults,filters:i.filters,tempFilters:i.tempFilters,apiFilters:i.apiFilters,resultsMode:i.resultsMode,resolvedQuestionnaireValues:i.resolvedQuestionnaireValues,sortBy:i.sortBy})},o=async()=>{if(r!=null&&r.onFilterUpdate){const i=(await d.getFullState()).apiFilters;r.onFilterUpdate(i)}};return{properties:{},currentPropertyId:null,currentPropertySlug:null,hasPreviouslySearched:[],unitResults:[],filters:{availability:void 0,bedrooms:void 0,cost:void 0,highlights:void 0},tempFilters:{availability:void 0,bedrooms:void 0,cost:void 0,highlights:void 0},apiFilters:{limit:10,page:1},resultsMode:"all",resolvedQuestionnaireValues:{},sortBy:"relevance",filtersLoaded:!1,async initializeProperty(i,s){await d.initializeProperty(i,s),await a()},async setCurrentProperty(i,s){await d.setCurrentProperty(i,s),t({currentPropertyId:i,...s&&{currentPropertySlug:s}})},async setCurrentPropertySlug(i){await d.setCurrentPropertySlug(i),t({currentPropertySlug:i})},async setHasPreviouslySearched(i){await d.setHasPreviouslySearched(i),await a()},async toggleFavorite(i){await d.toggleFavorite(i),await a()},async markUnitAsViewed(i,s){await d.markUnitAsViewed(i,s),await a()},async setTourContactedOn(){await d.setTourContactedOn(),await a()},getTourContactedOn:d.getTourContactedOn.bind(d),async setQuestionnaireResults(i){await d.setQuestionnaireResults(i),await a()},async setTourContactData(i){await d.setTourContactData(i),await a()},async setUnitResults(i){await d.setUnitResults(i),await a()},async clearUnitResults(){await d.clearUnitResults(),await a()},async setFilters(i){await d.setFilters(i);const s=e();t({filters:{...s.filters,...i}})},async setTempFilters(i){await d.setTempFilters(i);const s=e();t({tempFilters:{...s.tempFilters,...i}})},async setFiltersToDefault(){await d.setFiltersToDefault(),t({filters:{availability:void 0,bedrooms:void 0,cost:void 0,highlights:void 0}})},async setApiFilters(i){await d.setApiFilters(i);const s=e();t({apiFilters:{...s.apiFilters,...i}})},async handleTempFilterChange(i,s){await d.handleTempFilterChange(i,s);const l=e();t({tempFilters:{...l.tempFilters,[i]:s}})},async submitFilterUpdate(){await d.submitFilterUpdate(),await a(),await o()},async setResultsMode(i){await d.setResultsMode(i),t({resultsMode:i})},async setSortBy(i){await d.setSortBy(i),t({sortBy:i})},async setResolvedQuestionnaireValues(i,s){await d.setResolvedQuestionnaireValues(i,s);const l=e();t({resolvedQuestionnaireValues:{...l.resolvedQuestionnaireValues,[i]:s}})},getUnitState(i){var u;const s=e(),l=s.currentPropertyId?s.properties[s.currentPropertyId]:null;return{isFavorite:(l==null?void 0:l.favoritedUnits.includes(i))??!1,viewedDate:((u=l==null?void 0:l.viewedUnits.find(c=>c.unitId===i))==null?void 0:u.viewedDate)??""}},getResultsUrl:d.getResultsUrl.bind(d),getCurrentProperty:d.getCurrentProperty.bind(d),getPropertyData:d.getPropertyData.bind(d),async _hydrate(){await a()},async _initialize(){await d.initialize(),await a(),t({filtersLoaded:!0})}}}}function Vt(){return r=>t=>r(e=>e.getUnitState(t))}function ht(r,t){return{property:{unit:{favorites:{toggle:r.toggleFavorite.bind(r)},viewed:{mark:r.markUnitAsViewed.bind(r)}},questionnaire:{setResults:r.setQuestionnaireResults.bind(r)},tour:{setContactedOn:r.setTourContactedOn.bind(r),getContactedOn:r.getTourContactedOn.bind(r),setContactData:r.setTourContactData.bind(r)}},filters:{set:r.setFilters.bind(r),setTemp:r.setTempFilters.bind(r),setToDefault:r.setFiltersToDefault.bind(r),commitTemp:async(e,a)=>{const i=(t?t():r).tempFilters[e]??a;await r.handleTempFilterChange(e,i),await r.submitFilterUpdate()},commitAvailability:async()=>{await r.submitFilterUpdate()},submit:r.submitFilterUpdate.bind(r)}}}function _t(r){return(t,e)=>{const a=mt(r)(t,e),o=ht(a,e);return{...a,...o}}}const Nt={async isFavorite(r,t){return yt(r,t)},async toggle(r,t){return pt(r,t)},async set(r,t,e){return K(r,t,e)},async getAll(r){return M(r)}},Y="//web.inresiapp.com",Z="/placeholder.jpg",$t=r=>r?r.startsWith("?")?r:`?${r}`:"",wt=(r,t,e=Y)=>`${e}/${t}/unit/${r}/explore`,A=(r,t=Z)=>!(r!=null&&r.CFURL)||!(r!=null&&r.name)||!(r!=null&&r.signature)?t:`${r.CFURL}${r.name}${$t(r.signature)}`;function jt(r){return{data:r}}function xt(r,t,e){var s,l;const a=(e==null?void 0:e.origin)??Y,o=(e==null?void 0:e.placeholderImage)??Z,i=((s=r.hits)==null?void 0:s.map(u=>{var f,X;const c=u._source??{},y=typeof c.name=="string"?c.name:typeof c.title=="string"?c.title:"";return{...c,title:y,slug:wt(String(c.slug??""),t,a),imageUrl:A(c.image,o),secondaryImageUrl:A((f=c.additionalImages)==null?void 0:f[0],o),tertiaryImageUrl:A((X=c.additionalImages)==null?void 0:X[1],o)}}))??[];return{total:((l=r.total)==null?void 0:l.value)??i.length,maxScore:r.max_score??null,type:r.type??"units",hits:i}}const Bt={asap:"ASAP",next_month:"Next Month","2_3_months":"2-3 Months",all:"Just Browsing"},C={0:"Studio",1:"1 Bed",2:"2 Bed",3:"3+ Bed"},Lt=new Set(Object.values(C)),Qt=r=>{if(!r||r.length===0)return;const t=new Set;for(const e of r){if(typeof e=="number"){const o=C[e];o&&t.add(o);continue}const a=e.split(",").map(o=>o.trim());for(const o of a){const i=Number.parseInt(o,10);!Number.isNaN(i)&&C[i]?t.add(C[i]):Lt.has(o)&&t.add(o)}}return t.size>0?Array.from(t):void 0},Ht=r=>({availability:r.availability&&r.availability.length>0?r.availability.map(e=>Bt[e]??e):void 0,bedrooms:Qt(r.bedrooms),cost:r.cost??void 0,highlights:r.highlights??[]});exports.ApiUserSchema=Ut;exports.AppStoreDataSchema=zt;exports.DEFAULT_PLACEHOLDER_IMAGE=Z;exports.DEFAULT_WEB_ORIGIN=Y;exports.FavoritesSchema=T;exports.FiltersSchema=U;exports.OpenDBError=nt;exports.PropertySchema=w;exports.PropertyStore=ft;exports.PropertyStoreDataSchema=R;exports.QueryParamsSchema=Q;exports.ResultsModeEnum=H;exports.SCHEMA_VERSION=z;exports.SchemaMismatchError=rt;exports.SortByEnum=q;exports.Store=W;exports.TourContactDataSchema=st;exports.UnifiedStore=W;exports.UnifiedStoreDataSchema=D;exports.UnitDataSchema=it;exports.UnitFavoriteSchema=Pt;exports.UnitSchema=v;exports.UserPropertyStateSchema=P;exports.UserSchema=h;exports.UserUnitDataSchema=at;exports.ViewedUnitSchema=ot;exports.buildExploreUrl=wt;exports.buildImageUrl=A;exports.configureValidation=lt;exports.createORMStringStorage=Ot;exports.createStructuredStore=_t;exports.createStructuredStoreActions=ht;exports.createUseUnitState=Vt;exports.createZustandUnifiedStore=mt;exports.debugDump=ct;exports.defaultIdGenerator=ut;exports.ensureUser=E;exports.exportJSON=At;exports.favorites=Nt;exports.getDB=g;exports.getFavoritedUnitsForProperty=M;exports.getUserUUID=kt;exports.isUnitFavorited=yt;exports.kvGet=G;exports.kvRemove=Ct;exports.kvSet=J;exports.propertyStore=Tt;exports.resetDB=Dt;exports.setFavoriteUnit=K;exports.store=d;exports.toggleFavoriteUnit=pt;exports.transformUnitsApiResponse=jt;exports.transformUnitsApiResponseToClient=xt;exports.transformUnitsApiResponseToClientFilters=Ht;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|