@superbright/indexeddb-orm 0.1.1 → 0.1.3
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 +370 -19
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.mjs +1154 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +6 -9
- package/.prettierignore +0 -9
- package/.prettierrc.cjs +0 -13
- package/CONSUMING_APP_GUIDE.md +0 -164
- package/MIGRATION_SUMMARY.md +0 -157
- package/docs/app-store-guide.md +0 -160
- package/docs/property-store.md +0 -192
- package/docs/structured-store-migration.md +0 -129
- package/examples/property-store-migration.ts +0 -164
- package/index.html +0 -29
- package/playground/main.ts +0 -38
- package/src/adapters/dexie.ts +0 -28
- package/src/adapters/structured-store.ts +0 -85
- package/src/adapters/zustand-app.ts +0 -221
- package/src/adapters/zustand-unified.ts +0 -342
- package/src/adapters/zustand.ts +0 -142
- package/src/api/app.ts +0 -270
- package/src/api/favorites.ts +0 -64
- package/src/api/properties.ts +0 -293
- package/src/api/users.ts +0 -66
- package/src/db.ts +0 -185
- package/src/debug.ts +0 -25
- package/src/errors.ts +0 -13
- package/src/index.ts +0 -34
- package/src/schema.ts +0 -48
- package/src/storage.ts +0 -71
- package/src/stores/property.ts +0 -133
- package/src/stores/unified.ts +0 -507
- package/src/units/favorites.ts +0 -19
- package/src/validation.ts +0 -32
- package/test-export.js +0 -6
- package/tests/orm.spec.ts +0 -17
- package/tests/setup.ts +0 -2
- package/tsconfig.build.json +0 -11
- package/tsconfig.json +0 -29
- package/vite.config.ts +0 -16
- package/vitest.config.ts +0 -9
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,1154 @@
|
|
|
1
|
+
import { z as n } from "zod";
|
|
2
|
+
import _ from "dexie";
|
|
3
|
+
class x extends Error {
|
|
4
|
+
constructor(t, e) {
|
|
5
|
+
super(t), this.detail = e, this.name = "SchemaMismatchError";
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
class B extends Error {
|
|
9
|
+
constructor(t, e) {
|
|
10
|
+
super(t), this.detail = e, this.name = "OpenDBError";
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
class C extends _ {
|
|
14
|
+
constructor(t = "inresi-orm") {
|
|
15
|
+
super(t), this.version(b).stores({
|
|
16
|
+
users: "uuid",
|
|
17
|
+
kv: "key"
|
|
18
|
+
}), this.users = this.table("users"), this.kv = this.table("kv");
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
let k = "strict", v;
|
|
22
|
+
function H(a) {
|
|
23
|
+
a.mode && (k = a.mode), v = a.onIssue;
|
|
24
|
+
}
|
|
25
|
+
function P(a, t, e) {
|
|
26
|
+
const r = a.safeParse(t);
|
|
27
|
+
if (r.success) return r.data;
|
|
28
|
+
const s = r.error.flatten();
|
|
29
|
+
if (v == null || v(e, s), k === "strict")
|
|
30
|
+
throw new x(`ORM schema mismatch in ${e}`, s);
|
|
31
|
+
return k === "warn" && console.warn(`ORM schema mismatch in ${e}`, s), null;
|
|
32
|
+
}
|
|
33
|
+
const N = { BASE_URL: "/", DEV: !1, MODE: "production", PROD: !0, SSR: !1 }, F = "manifest", z = n.object({ schemaVersion: n.number().int() });
|
|
34
|
+
let h = null, S = null;
|
|
35
|
+
const A = Symbol("validationInstalled");
|
|
36
|
+
function D(a, t) {
|
|
37
|
+
const e = a;
|
|
38
|
+
if (e[A]) return;
|
|
39
|
+
if (e[A] = !0, ((i, o, l) => {
|
|
40
|
+
i.hook("creating", (u, y) => {
|
|
41
|
+
const p = P(o, y, `${l}.creating`);
|
|
42
|
+
if (!p) throw new Error(`Rejected invalid ${l} on create`);
|
|
43
|
+
return p;
|
|
44
|
+
}), i.hook("updating", (u, y, p) => {
|
|
45
|
+
const d = { ...p, ...u };
|
|
46
|
+
return P(o, d, `${l}.updating`) ? u : {};
|
|
47
|
+
});
|
|
48
|
+
})(a.users, f, "users"), (t == null ? void 0 : t.validateReads) ?? !0) {
|
|
49
|
+
const i = (t == null ? void 0 : t.dropInvalidOnRead) ?? !0;
|
|
50
|
+
((l, u, y) => {
|
|
51
|
+
l.hook("reading", (p) => {
|
|
52
|
+
const d = P(u, p, `${y}.reading`);
|
|
53
|
+
return d || (i ? void 0 : p);
|
|
54
|
+
});
|
|
55
|
+
})(a.users, f, "users");
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function q() {
|
|
59
|
+
try {
|
|
60
|
+
if (typeof import.meta < "u" && N)
|
|
61
|
+
return !1;
|
|
62
|
+
} catch {
|
|
63
|
+
}
|
|
64
|
+
try {
|
|
65
|
+
if (typeof process < "u" && process.env)
|
|
66
|
+
return process.env.NODE_ENV !== "production";
|
|
67
|
+
} catch {
|
|
68
|
+
}
|
|
69
|
+
return !1;
|
|
70
|
+
}
|
|
71
|
+
async function w(a = {}) {
|
|
72
|
+
if (h) return h;
|
|
73
|
+
if (S) return S;
|
|
74
|
+
const t = a.dbName ?? "inresi-orm";
|
|
75
|
+
return S = (async () => {
|
|
76
|
+
var e, r, s, i;
|
|
77
|
+
try {
|
|
78
|
+
const o = q() ? "warn" : "strict";
|
|
79
|
+
H({
|
|
80
|
+
mode: ((e = a.validation) == null ? void 0 : e.mode) ?? o,
|
|
81
|
+
onIssue: (r = a.validation) == null ? void 0 : r.onIssue
|
|
82
|
+
});
|
|
83
|
+
const l = new C(t);
|
|
84
|
+
l.on("versionchange", () => {
|
|
85
|
+
var d;
|
|
86
|
+
try {
|
|
87
|
+
l.close();
|
|
88
|
+
} finally {
|
|
89
|
+
(d = a.onReset) == null || d.call(a, "versionchange");
|
|
90
|
+
}
|
|
91
|
+
}), l.on("blocked", () => {
|
|
92
|
+
var d;
|
|
93
|
+
(d = a.onReset) == null || d.call(a, "blocked");
|
|
94
|
+
}), await l.open();
|
|
95
|
+
const u = await l.kv.get(F), y = (u == null ? void 0 : u.value) ?? null;
|
|
96
|
+
if (!y)
|
|
97
|
+
return await l.transaction("rw", l.kv, async () => {
|
|
98
|
+
await l.kv.put({
|
|
99
|
+
key: F,
|
|
100
|
+
value: { schemaVersion: b }
|
|
101
|
+
});
|
|
102
|
+
}), D(l, a.validation), h = l, l;
|
|
103
|
+
const p = z.safeParse(y);
|
|
104
|
+
if (!p.success || p.data.schemaVersion !== b) {
|
|
105
|
+
await l.delete();
|
|
106
|
+
const d = new C(t);
|
|
107
|
+
return d.on("versionchange", () => {
|
|
108
|
+
var g;
|
|
109
|
+
try {
|
|
110
|
+
d.close();
|
|
111
|
+
} finally {
|
|
112
|
+
(g = a.onReset) == null || g.call(a, "versionchange");
|
|
113
|
+
}
|
|
114
|
+
}), d.on("blocked", () => {
|
|
115
|
+
var g;
|
|
116
|
+
(g = a.onReset) == null || g.call(a, "blocked");
|
|
117
|
+
}), await d.open(), await d.kv.put({
|
|
118
|
+
key: F,
|
|
119
|
+
value: { schemaVersion: b }
|
|
120
|
+
}), D(d, a.validation), (s = a.onReset) == null || s.call(a, "incompatible"), h = d, d;
|
|
121
|
+
}
|
|
122
|
+
return D(l, a.validation), h = l, l;
|
|
123
|
+
} catch (o) {
|
|
124
|
+
throw (i = a.onError) == null || i.call(a, o), new B("Failed to open IndexedDB", o);
|
|
125
|
+
} finally {
|
|
126
|
+
S = null;
|
|
127
|
+
}
|
|
128
|
+
})(), S;
|
|
129
|
+
}
|
|
130
|
+
async function pt(a) {
|
|
131
|
+
const t = a ?? "inresi-orm";
|
|
132
|
+
if (h)
|
|
133
|
+
try {
|
|
134
|
+
await h.close();
|
|
135
|
+
} catch {
|
|
136
|
+
}
|
|
137
|
+
await new C(t).delete(), h = null;
|
|
138
|
+
}
|
|
139
|
+
async function j(a) {
|
|
140
|
+
const e = await (await w()).kv.get(a);
|
|
141
|
+
return (e == null ? void 0 : e.value) ?? null;
|
|
142
|
+
}
|
|
143
|
+
async function E(a, t) {
|
|
144
|
+
await (await w()).kv.put({ key: a, value: t });
|
|
145
|
+
}
|
|
146
|
+
async function wt(a) {
|
|
147
|
+
await (await w()).kv.delete(a);
|
|
148
|
+
}
|
|
149
|
+
function ht(a) {
|
|
150
|
+
const t = /* @__PURE__ */ new Map(), e = (a == null ? void 0 : a.prefix) ?? "", r = (s) => `${e}${s}`;
|
|
151
|
+
return {
|
|
152
|
+
async getItem(s) {
|
|
153
|
+
try {
|
|
154
|
+
const o = await (await w()).kv.get(r(s));
|
|
155
|
+
return o ? JSON.stringify(o.value) : null;
|
|
156
|
+
} catch (i) {
|
|
157
|
+
if (a != null && a.fallbackToMemory) return t.get(r(s)) ?? null;
|
|
158
|
+
throw i;
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
async setItem(s, i) {
|
|
162
|
+
try {
|
|
163
|
+
await (await w()).kv.put({ key: r(s), value: JSON.parse(i) });
|
|
164
|
+
} catch (o) {
|
|
165
|
+
if (a != null && a.fallbackToMemory) {
|
|
166
|
+
t.set(r(s), i);
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
throw o;
|
|
170
|
+
}
|
|
171
|
+
},
|
|
172
|
+
async removeItem(s) {
|
|
173
|
+
try {
|
|
174
|
+
await (await w()).kv.delete(r(s));
|
|
175
|
+
} catch (i) {
|
|
176
|
+
if (a != null && a.fallbackToMemory) {
|
|
177
|
+
t.delete(r(s));
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
throw i;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
const J = n.object({
|
|
186
|
+
unitId: n.string(),
|
|
187
|
+
viewedDate: n.string()
|
|
188
|
+
}), K = n.object({
|
|
189
|
+
timezone: n.string(),
|
|
190
|
+
favouriteUnits: n.array(n.string()).optional(),
|
|
191
|
+
preferences: n.record(n.unknown())
|
|
192
|
+
}), G = n.object({
|
|
193
|
+
id: n.string(),
|
|
194
|
+
slug: n.string(),
|
|
195
|
+
favoritedUnits: n.array(n.string()),
|
|
196
|
+
tourContactedOn: n.string().nullable(),
|
|
197
|
+
viewedUnits: n.array(J),
|
|
198
|
+
questionnaireResults: n.unknown().nullable().optional(),
|
|
199
|
+
// Generic for IFilters
|
|
200
|
+
tourContactData: K.nullable().optional()
|
|
201
|
+
}), gt = n.object({
|
|
202
|
+
data: n.record(G),
|
|
203
|
+
propertySlug: n.string().nullable(),
|
|
204
|
+
propertyId: n.string().nullable(),
|
|
205
|
+
hasPreviouslySearched: n.array(n.string())
|
|
206
|
+
}), Y = {
|
|
207
|
+
data: {},
|
|
208
|
+
propertySlug: null,
|
|
209
|
+
propertyId: null,
|
|
210
|
+
hasPreviouslySearched: []
|
|
211
|
+
};
|
|
212
|
+
class Z {
|
|
213
|
+
async getState() {
|
|
214
|
+
return await j("property") ?? Y;
|
|
215
|
+
}
|
|
216
|
+
async setState(t) {
|
|
217
|
+
const e = await this.getState(), r = t(e);
|
|
218
|
+
await E("property", r);
|
|
219
|
+
}
|
|
220
|
+
// Basic state operations
|
|
221
|
+
async setData(t) {
|
|
222
|
+
await this.setState((e) => ({ ...e, data: t }));
|
|
223
|
+
}
|
|
224
|
+
async setPropertySlug(t) {
|
|
225
|
+
await this.setState((e) => ({ ...e, propertySlug: t }));
|
|
226
|
+
}
|
|
227
|
+
async setPropertyId(t) {
|
|
228
|
+
await this.setState((e) => ({ ...e, propertyId: t }));
|
|
229
|
+
}
|
|
230
|
+
async removeData(t) {
|
|
231
|
+
await this.setState((e) => ({
|
|
232
|
+
...e,
|
|
233
|
+
data: Object.entries(e.data).filter(([r]) => r !== t).reduce((r, [s, i]) => ({ ...r, [s]: i }), {})
|
|
234
|
+
}));
|
|
235
|
+
}
|
|
236
|
+
async clearData() {
|
|
237
|
+
await this.setState((t) => ({ ...t, data: {} }));
|
|
238
|
+
}
|
|
239
|
+
async setHasPreviouslySearched(t) {
|
|
240
|
+
await this.setState((e) => ({
|
|
241
|
+
...e,
|
|
242
|
+
hasPreviouslySearched: Array.from(
|
|
243
|
+
/* @__PURE__ */ new Set([...e.hasPreviouslySearched, t])
|
|
244
|
+
)
|
|
245
|
+
}));
|
|
246
|
+
}
|
|
247
|
+
// Property-specific operations
|
|
248
|
+
async setTourContactedOn() {
|
|
249
|
+
await this.setState((t) => {
|
|
250
|
+
const e = t.propertyId;
|
|
251
|
+
if (!e) return t;
|
|
252
|
+
const r = t.data[e];
|
|
253
|
+
return r ? {
|
|
254
|
+
...t,
|
|
255
|
+
data: {
|
|
256
|
+
...t.data,
|
|
257
|
+
[e]: {
|
|
258
|
+
...r,
|
|
259
|
+
tourContactedOn: (/* @__PURE__ */ new Date()).toISOString()
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
} : t;
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
async getTourContactedOn() {
|
|
266
|
+
var r;
|
|
267
|
+
const t = await this.getState(), e = t.propertyId;
|
|
268
|
+
return e ? ((r = t.data[e]) == null ? void 0 : r.tourContactedOn) ?? null : null;
|
|
269
|
+
}
|
|
270
|
+
async setQuestionnaireResults(t) {
|
|
271
|
+
await this.setState((e) => {
|
|
272
|
+
const r = e.propertyId;
|
|
273
|
+
if (!r) return e;
|
|
274
|
+
const s = e.data[r];
|
|
275
|
+
return s ? {
|
|
276
|
+
...e,
|
|
277
|
+
data: {
|
|
278
|
+
...e.data,
|
|
279
|
+
[r]: {
|
|
280
|
+
...s,
|
|
281
|
+
questionnaireResults: t
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
} : e;
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
async setTourContactData(t) {
|
|
288
|
+
await this.setState((e) => {
|
|
289
|
+
const r = e.propertyId;
|
|
290
|
+
if (!r) return e;
|
|
291
|
+
const s = e.data[r];
|
|
292
|
+
return s ? {
|
|
293
|
+
...e,
|
|
294
|
+
data: {
|
|
295
|
+
...e.data,
|
|
296
|
+
[r]: {
|
|
297
|
+
...s,
|
|
298
|
+
tourContactData: t
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
} : e;
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
async toggleFavorite(t) {
|
|
305
|
+
await this.setState((e) => {
|
|
306
|
+
const r = e.propertyId;
|
|
307
|
+
if (!r) return e;
|
|
308
|
+
const s = e.data[r];
|
|
309
|
+
if (!s) return e;
|
|
310
|
+
const o = s.favoritedUnits.includes(t) ? s.favoritedUnits.filter((l) => l !== t) : [...s.favoritedUnits, t];
|
|
311
|
+
return {
|
|
312
|
+
...e,
|
|
313
|
+
data: {
|
|
314
|
+
...e.data,
|
|
315
|
+
[r]: {
|
|
316
|
+
...s,
|
|
317
|
+
favoritedUnits: o
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
};
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
async markUnitAsViewed(t, e) {
|
|
324
|
+
const r = /* @__PURE__ */ new Date(), s = `${String(r.getMonth() + 1).padStart(
|
|
325
|
+
2,
|
|
326
|
+
"0"
|
|
327
|
+
)}/${String(r.getDate()).padStart(2, "0")}`;
|
|
328
|
+
await this.setState((i) => {
|
|
329
|
+
const o = i.propertyId;
|
|
330
|
+
if (!o) return i;
|
|
331
|
+
const l = i.data[o];
|
|
332
|
+
if (!l) return i;
|
|
333
|
+
const u = [
|
|
334
|
+
// Remove existing entry if it exists
|
|
335
|
+
...l.viewedUnits.filter((y) => y.unitId !== t),
|
|
336
|
+
// Add updated one
|
|
337
|
+
{
|
|
338
|
+
unitId: t,
|
|
339
|
+
viewedDate: s
|
|
340
|
+
}
|
|
341
|
+
];
|
|
342
|
+
return {
|
|
343
|
+
...i,
|
|
344
|
+
data: {
|
|
345
|
+
...i.data,
|
|
346
|
+
[o]: {
|
|
347
|
+
...l,
|
|
348
|
+
viewedUnits: u
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
};
|
|
352
|
+
}), typeof window < "u" && window.open(`//${e}`, "_blank");
|
|
353
|
+
}
|
|
354
|
+
// Utility methods for getting specific data
|
|
355
|
+
async getUnitState(t) {
|
|
356
|
+
var s;
|
|
357
|
+
const e = await this.getState(), r = e.propertyId ? e.data[e.propertyId] : null;
|
|
358
|
+
return {
|
|
359
|
+
isFavorite: (r == null ? void 0 : r.favoritedUnits.includes(t)) ?? !1,
|
|
360
|
+
viewedDate: ((s = r == null ? void 0 : r.viewedUnits.find((i) => i.unitId === t)) == null ? void 0 : s.viewedDate) ?? ""
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
async getPropertyData(t) {
|
|
364
|
+
const e = await this.getState(), r = t ?? e.propertyId;
|
|
365
|
+
return r ? e.data[r] ?? null : null;
|
|
366
|
+
}
|
|
367
|
+
async getCurrentProperty() {
|
|
368
|
+
const t = await this.getState();
|
|
369
|
+
return t.propertyId ? t.data[t.propertyId] ?? null : null;
|
|
370
|
+
}
|
|
371
|
+
async getFullState() {
|
|
372
|
+
return this.getState();
|
|
373
|
+
}
|
|
374
|
+
// Initialize property if it doesn't exist
|
|
375
|
+
async initializeProperty(t, e) {
|
|
376
|
+
await this.setState((r) => r.data[t] ? { ...r, propertyId: t, propertySlug: e } : {
|
|
377
|
+
...r,
|
|
378
|
+
propertyId: t,
|
|
379
|
+
propertySlug: e,
|
|
380
|
+
data: {
|
|
381
|
+
...r.data,
|
|
382
|
+
[t]: {
|
|
383
|
+
id: t,
|
|
384
|
+
slug: e,
|
|
385
|
+
favoritedUnits: [],
|
|
386
|
+
tourContactedOn: null,
|
|
387
|
+
viewedUnits: [],
|
|
388
|
+
questionnaireResults: null,
|
|
389
|
+
tourContactData: null
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
const ft = new Z(), W = n.object({
|
|
396
|
+
isFavorite: n.boolean().optional(),
|
|
397
|
+
viewedDate: n.string().optional()
|
|
398
|
+
}), M = n.object({
|
|
399
|
+
availability: n.union([n.string(), n.array(n.string())]).nullable().optional(),
|
|
400
|
+
bedrooms: n.array(n.number()).nullable().optional(),
|
|
401
|
+
cost: n.number().nullable().optional(),
|
|
402
|
+
highlights: n.array(n.string()).optional()
|
|
403
|
+
}), X = n.object({
|
|
404
|
+
limit: n.number().default(10),
|
|
405
|
+
page: n.number().default(1),
|
|
406
|
+
availability: n.array(n.string()).optional(),
|
|
407
|
+
bedrooms: n.array(n.number()).optional(),
|
|
408
|
+
cost: n.number().nullable().optional(),
|
|
409
|
+
highlights: n.array(n.string()).optional()
|
|
410
|
+
}), St = n.object({
|
|
411
|
+
data: n.record(W),
|
|
412
|
+
filters: M,
|
|
413
|
+
tempFilters: M,
|
|
414
|
+
apiFilters: X,
|
|
415
|
+
resultsMode: n.enum(["all", "bestFit", "closestMatch", "favorites"]),
|
|
416
|
+
propertySlug: n.string().nullable(),
|
|
417
|
+
resolvedQuestionnaireValues: n.record(n.array(n.string())),
|
|
418
|
+
sortBy: n.enum(["relevance", "newest", "priceLowToHigh", "priceHighToLow"]),
|
|
419
|
+
filtersLoaded: n.boolean()
|
|
420
|
+
});
|
|
421
|
+
n.object({
|
|
422
|
+
isFavorite: n.boolean().optional(),
|
|
423
|
+
viewedDate: n.string().optional()
|
|
424
|
+
});
|
|
425
|
+
const tt = n.object({
|
|
426
|
+
unitId: n.string(),
|
|
427
|
+
viewedDate: n.string()
|
|
428
|
+
}), et = n.object({
|
|
429
|
+
timezone: n.string(),
|
|
430
|
+
favouriteUnits: n.array(n.string()).optional(),
|
|
431
|
+
preferences: n.record(n.unknown())
|
|
432
|
+
}), rt = n.object({
|
|
433
|
+
id: n.string(),
|
|
434
|
+
slug: n.string(),
|
|
435
|
+
favoritedUnits: n.array(n.string()),
|
|
436
|
+
tourContactedOn: n.string().nullable(),
|
|
437
|
+
viewedUnits: n.array(tt),
|
|
438
|
+
questionnaireResults: n.unknown().nullable().optional(),
|
|
439
|
+
tourContactData: et.nullable().optional()
|
|
440
|
+
}), $ = n.object({
|
|
441
|
+
availability: n.union([n.string(), n.array(n.string())]).nullable().optional(),
|
|
442
|
+
bedrooms: n.array(n.number()).nullable().optional(),
|
|
443
|
+
cost: n.number().nullable().optional(),
|
|
444
|
+
highlights: n.array(n.string()).optional()
|
|
445
|
+
}), at = n.object({
|
|
446
|
+
limit: n.number().default(10),
|
|
447
|
+
page: n.number().default(1),
|
|
448
|
+
availability: n.array(n.string()).optional(),
|
|
449
|
+
bedrooms: n.array(n.number()).optional(),
|
|
450
|
+
cost: n.number().nullable().optional(),
|
|
451
|
+
highlights: n.array(n.string()).optional()
|
|
452
|
+
}), mt = n.object({
|
|
453
|
+
// Property-related data
|
|
454
|
+
properties: n.record(rt),
|
|
455
|
+
currentPropertyId: n.string().nullable(),
|
|
456
|
+
currentPropertySlug: n.string().nullable(),
|
|
457
|
+
hasPreviouslySearched: n.array(n.string()),
|
|
458
|
+
// App-level data
|
|
459
|
+
filters: $,
|
|
460
|
+
tempFilters: $,
|
|
461
|
+
apiFilters: at,
|
|
462
|
+
resultsMode: n.enum(["all", "bestFit", "closestMatch", "favorites"]),
|
|
463
|
+
resolvedQuestionnaireValues: n.record(n.array(n.string())),
|
|
464
|
+
sortBy: n.enum(["relevance", "newest", "priceLowToHigh", "priceHighToLow"]),
|
|
465
|
+
filtersLoaded: n.boolean()
|
|
466
|
+
}), T = {
|
|
467
|
+
availability: void 0,
|
|
468
|
+
bedrooms: void 0,
|
|
469
|
+
cost: void 0,
|
|
470
|
+
highlights: void 0
|
|
471
|
+
}, U = {
|
|
472
|
+
// Property data
|
|
473
|
+
properties: {},
|
|
474
|
+
currentPropertyId: null,
|
|
475
|
+
currentPropertySlug: null,
|
|
476
|
+
hasPreviouslySearched: [],
|
|
477
|
+
// App data
|
|
478
|
+
filters: T,
|
|
479
|
+
tempFilters: T,
|
|
480
|
+
apiFilters: {
|
|
481
|
+
limit: 10,
|
|
482
|
+
page: 1
|
|
483
|
+
},
|
|
484
|
+
resultsMode: "all",
|
|
485
|
+
resolvedQuestionnaireValues: {},
|
|
486
|
+
sortBy: "relevance",
|
|
487
|
+
filtersLoaded: !1
|
|
488
|
+
};
|
|
489
|
+
class it {
|
|
490
|
+
async getState() {
|
|
491
|
+
const t = await j("app");
|
|
492
|
+
return t ? {
|
|
493
|
+
...U,
|
|
494
|
+
...t,
|
|
495
|
+
properties: t.properties ?? {}
|
|
496
|
+
} : U;
|
|
497
|
+
}
|
|
498
|
+
async setState(t) {
|
|
499
|
+
const e = await this.getState(), r = t(e);
|
|
500
|
+
await E("app", r);
|
|
501
|
+
}
|
|
502
|
+
// === PROPERTY OPERATIONS ===
|
|
503
|
+
async initializeProperty(t, e) {
|
|
504
|
+
await this.setState((r) => r.properties && r.properties[t] ? {
|
|
505
|
+
...r,
|
|
506
|
+
currentPropertyId: t,
|
|
507
|
+
currentPropertySlug: e
|
|
508
|
+
} : {
|
|
509
|
+
...r,
|
|
510
|
+
currentPropertyId: t,
|
|
511
|
+
currentPropertySlug: e,
|
|
512
|
+
properties: {
|
|
513
|
+
...r.properties,
|
|
514
|
+
[t]: {
|
|
515
|
+
id: t,
|
|
516
|
+
slug: e,
|
|
517
|
+
favoritedUnits: [],
|
|
518
|
+
tourContactedOn: null,
|
|
519
|
+
viewedUnits: [],
|
|
520
|
+
questionnaireResults: null,
|
|
521
|
+
tourContactData: null
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
});
|
|
525
|
+
}
|
|
526
|
+
async setCurrentProperty(t, e) {
|
|
527
|
+
await this.setState((r) => ({
|
|
528
|
+
...r,
|
|
529
|
+
currentPropertyId: t,
|
|
530
|
+
currentPropertySlug: e || r.currentPropertySlug
|
|
531
|
+
}));
|
|
532
|
+
}
|
|
533
|
+
async setCurrentPropertySlug(t) {
|
|
534
|
+
await this.setState((e) => ({
|
|
535
|
+
...e,
|
|
536
|
+
currentPropertySlug: t
|
|
537
|
+
}));
|
|
538
|
+
}
|
|
539
|
+
async setHasPreviouslySearched(t) {
|
|
540
|
+
await this.setState((e) => ({
|
|
541
|
+
...e,
|
|
542
|
+
hasPreviouslySearched: Array.from(
|
|
543
|
+
/* @__PURE__ */ new Set([...e.hasPreviouslySearched, t])
|
|
544
|
+
)
|
|
545
|
+
}));
|
|
546
|
+
}
|
|
547
|
+
async toggleFavorite(t) {
|
|
548
|
+
await this.setState((e) => {
|
|
549
|
+
const r = e.currentPropertyId;
|
|
550
|
+
if (!r) return e;
|
|
551
|
+
const s = e.properties[r];
|
|
552
|
+
if (!s) return e;
|
|
553
|
+
const o = s.favoritedUnits.includes(t) ? s.favoritedUnits.filter((l) => l !== t) : [...s.favoritedUnits, t];
|
|
554
|
+
return {
|
|
555
|
+
...e,
|
|
556
|
+
properties: {
|
|
557
|
+
...e.properties,
|
|
558
|
+
[r]: {
|
|
559
|
+
...s,
|
|
560
|
+
favoritedUnits: o
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
};
|
|
564
|
+
});
|
|
565
|
+
}
|
|
566
|
+
async markUnitAsViewed(t, e) {
|
|
567
|
+
const r = /* @__PURE__ */ new Date(), s = `${String(r.getMonth() + 1).padStart(
|
|
568
|
+
2,
|
|
569
|
+
"0"
|
|
570
|
+
)}/${String(r.getDate()).padStart(2, "0")}`;
|
|
571
|
+
await this.setState((i) => {
|
|
572
|
+
const o = i.currentPropertyId;
|
|
573
|
+
if (!o) return i;
|
|
574
|
+
const l = i.properties[o];
|
|
575
|
+
if (!l) return i;
|
|
576
|
+
const u = [
|
|
577
|
+
...l.viewedUnits.filter((y) => y.unitId !== t),
|
|
578
|
+
{ unitId: t, viewedDate: s }
|
|
579
|
+
];
|
|
580
|
+
return {
|
|
581
|
+
...i,
|
|
582
|
+
properties: {
|
|
583
|
+
...i.properties,
|
|
584
|
+
[o]: {
|
|
585
|
+
...l,
|
|
586
|
+
viewedUnits: u
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
};
|
|
590
|
+
}), typeof window < "u" && window.open(`//${e}`, "_blank");
|
|
591
|
+
}
|
|
592
|
+
async setTourContactedOn() {
|
|
593
|
+
await this.setState((t) => {
|
|
594
|
+
const e = t.currentPropertyId;
|
|
595
|
+
if (!e) return t;
|
|
596
|
+
const r = t.properties[e];
|
|
597
|
+
return r ? {
|
|
598
|
+
...t,
|
|
599
|
+
properties: {
|
|
600
|
+
...t.properties,
|
|
601
|
+
[e]: {
|
|
602
|
+
...r,
|
|
603
|
+
tourContactedOn: (/* @__PURE__ */ new Date()).toISOString()
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
} : t;
|
|
607
|
+
});
|
|
608
|
+
}
|
|
609
|
+
async getTourContactedOn() {
|
|
610
|
+
var r;
|
|
611
|
+
const t = await this.getState(), e = t.currentPropertyId;
|
|
612
|
+
return e ? ((r = t.properties[e]) == null ? void 0 : r.tourContactedOn) ?? null : null;
|
|
613
|
+
}
|
|
614
|
+
async setQuestionnaireResults(t) {
|
|
615
|
+
await this.setState((e) => {
|
|
616
|
+
const r = e.currentPropertyId;
|
|
617
|
+
if (!r) return e;
|
|
618
|
+
const s = e.properties[r];
|
|
619
|
+
return s ? {
|
|
620
|
+
...e,
|
|
621
|
+
properties: {
|
|
622
|
+
...e.properties,
|
|
623
|
+
[r]: {
|
|
624
|
+
...s,
|
|
625
|
+
questionnaireResults: t
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
} : e;
|
|
629
|
+
});
|
|
630
|
+
}
|
|
631
|
+
async setTourContactData(t) {
|
|
632
|
+
await this.setState((e) => {
|
|
633
|
+
const r = e.currentPropertyId;
|
|
634
|
+
if (!r) return e;
|
|
635
|
+
const s = e.properties[r];
|
|
636
|
+
return s ? {
|
|
637
|
+
...e,
|
|
638
|
+
properties: {
|
|
639
|
+
...e.properties,
|
|
640
|
+
[r]: {
|
|
641
|
+
...s,
|
|
642
|
+
tourContactData: t
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
} : e;
|
|
646
|
+
});
|
|
647
|
+
}
|
|
648
|
+
// === FILTER OPERATIONS ===
|
|
649
|
+
async setFilters(t) {
|
|
650
|
+
await this.setState((e) => ({
|
|
651
|
+
...e,
|
|
652
|
+
filters: { ...e.filters, ...t }
|
|
653
|
+
}));
|
|
654
|
+
}
|
|
655
|
+
async setTempFilters(t) {
|
|
656
|
+
await this.setState((e) => ({
|
|
657
|
+
...e,
|
|
658
|
+
tempFilters: { ...e.tempFilters, ...t }
|
|
659
|
+
}));
|
|
660
|
+
}
|
|
661
|
+
async setFiltersToDefault() {
|
|
662
|
+
await this.setState((t) => ({ ...t, filters: T }));
|
|
663
|
+
}
|
|
664
|
+
async setApiFilters(t) {
|
|
665
|
+
await this.setState((e) => ({
|
|
666
|
+
...e,
|
|
667
|
+
apiFilters: { ...e.apiFilters, ...t }
|
|
668
|
+
}));
|
|
669
|
+
}
|
|
670
|
+
async handleTempFilterChange(t, e) {
|
|
671
|
+
await this.setState((r) => ({
|
|
672
|
+
...r,
|
|
673
|
+
tempFilters: { ...r.tempFilters, [t]: e }
|
|
674
|
+
}));
|
|
675
|
+
}
|
|
676
|
+
async commitTempFilterChange(t, e) {
|
|
677
|
+
const s = (await this.getState()).tempFilters[t] ?? e;
|
|
678
|
+
await this.handleTempFilterChange(t, s), await this.submitFilterUpdate();
|
|
679
|
+
}
|
|
680
|
+
async handleFilterCommitIndexDB(t) {
|
|
681
|
+
await this.setState((e) => {
|
|
682
|
+
const r = {
|
|
683
|
+
...e.apiFilters,
|
|
684
|
+
availability: t.availability || [],
|
|
685
|
+
bedrooms: t.bedrooms || [],
|
|
686
|
+
cost: t.cost || null,
|
|
687
|
+
highlights: t.highlights || []
|
|
688
|
+
};
|
|
689
|
+
return {
|
|
690
|
+
...e,
|
|
691
|
+
filters: { ...e.filters, ...t },
|
|
692
|
+
apiFilters: r
|
|
693
|
+
};
|
|
694
|
+
});
|
|
695
|
+
}
|
|
696
|
+
async commitAvailabilityChange() {
|
|
697
|
+
await this.submitFilterUpdate();
|
|
698
|
+
}
|
|
699
|
+
async submitFilterUpdate() {
|
|
700
|
+
await this.setState((t) => {
|
|
701
|
+
const e = {
|
|
702
|
+
...t.apiFilters,
|
|
703
|
+
availability: t.filters.availability || [],
|
|
704
|
+
bedrooms: t.filters.bedrooms || [],
|
|
705
|
+
cost: t.filters.cost || null,
|
|
706
|
+
highlights: t.filters.highlights || []
|
|
707
|
+
};
|
|
708
|
+
return {
|
|
709
|
+
...t,
|
|
710
|
+
apiFilters: e
|
|
711
|
+
};
|
|
712
|
+
});
|
|
713
|
+
}
|
|
714
|
+
// === RESULTS AND SORTING ===
|
|
715
|
+
async setResultsMode(t) {
|
|
716
|
+
await this.setState((e) => ({ ...e, resultsMode: t }));
|
|
717
|
+
}
|
|
718
|
+
async setSortBy(t) {
|
|
719
|
+
await this.setState((e) => ({ ...e, sortBy: t }));
|
|
720
|
+
}
|
|
721
|
+
// === QUESTIONNAIRE ===
|
|
722
|
+
async setResolvedQuestionnaireValues(t, e) {
|
|
723
|
+
await this.setState((r) => ({
|
|
724
|
+
...r,
|
|
725
|
+
resolvedQuestionnaireValues: {
|
|
726
|
+
...r.resolvedQuestionnaireValues,
|
|
727
|
+
[t]: e
|
|
728
|
+
}
|
|
729
|
+
}));
|
|
730
|
+
}
|
|
731
|
+
// === UTILITY METHODS ===
|
|
732
|
+
async getUnitState(t) {
|
|
733
|
+
var s;
|
|
734
|
+
const e = await this.getState(), r = e.currentPropertyId ? e.properties[e.currentPropertyId] : null;
|
|
735
|
+
return {
|
|
736
|
+
isFavorite: (r == null ? void 0 : r.favoritedUnits.includes(t)) ?? !1,
|
|
737
|
+
viewedDate: ((s = r == null ? void 0 : r.viewedUnits.find((i) => i.unitId === t)) == null ? void 0 : s.viewedDate) ?? ""
|
|
738
|
+
};
|
|
739
|
+
}
|
|
740
|
+
async getResultsUrl() {
|
|
741
|
+
const t = await this.getState();
|
|
742
|
+
return t.currentPropertySlug ? `/${t.currentPropertySlug}/results` : null;
|
|
743
|
+
}
|
|
744
|
+
async getCurrentProperty() {
|
|
745
|
+
const t = await this.getState();
|
|
746
|
+
return t.currentPropertyId ? t.properties[t.currentPropertyId] ?? null : null;
|
|
747
|
+
}
|
|
748
|
+
async getPropertyData(t) {
|
|
749
|
+
const e = await this.getState(), r = t ?? e.currentPropertyId;
|
|
750
|
+
return r ? e.properties[r] ?? null : null;
|
|
751
|
+
}
|
|
752
|
+
async getFullState() {
|
|
753
|
+
return this.getState();
|
|
754
|
+
}
|
|
755
|
+
async initialize() {
|
|
756
|
+
const t = await this.getState();
|
|
757
|
+
Object.keys(t.properties).length === 0 && !t.filtersLoaded && await this.setState((e) => ({
|
|
758
|
+
...U,
|
|
759
|
+
...e,
|
|
760
|
+
filtersLoaded: !0
|
|
761
|
+
}));
|
|
762
|
+
}
|
|
763
|
+
async loadPersistedFilters() {
|
|
764
|
+
await this.setState((t) => ({ ...t, filtersLoaded: !0 }));
|
|
765
|
+
}
|
|
766
|
+
// === LEGACY COMPATIBILITY METHODS ===
|
|
767
|
+
// Property store compatibility
|
|
768
|
+
async setData(t) {
|
|
769
|
+
await this.setState((e) => ({ ...e, properties: t }));
|
|
770
|
+
}
|
|
771
|
+
async setPropertySlug(t) {
|
|
772
|
+
await this.setCurrentPropertySlug(t);
|
|
773
|
+
}
|
|
774
|
+
async setPropertyId(t) {
|
|
775
|
+
await this.setCurrentProperty(t);
|
|
776
|
+
}
|
|
777
|
+
async removeData(t) {
|
|
778
|
+
await this.setState((e) => {
|
|
779
|
+
const { [t]: r, ...s } = e.properties;
|
|
780
|
+
return { ...e, properties: s };
|
|
781
|
+
});
|
|
782
|
+
}
|
|
783
|
+
async clearData() {
|
|
784
|
+
await this.setState((t) => ({ ...t, properties: {} }));
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
const c = new it(), b = 1, f = n.object({
|
|
788
|
+
uuid: n.string().uuid()
|
|
789
|
+
}), O = n.object({
|
|
790
|
+
propertyId: n.string() || n.number(),
|
|
791
|
+
unitIds: n.array(n.string())
|
|
792
|
+
}), m = "user", nt = () => {
|
|
793
|
+
var a;
|
|
794
|
+
return typeof ((a = globalThis.crypto) == null ? void 0 : a.randomUUID) == "function" ? globalThis.crypto.randomUUID() : (() => {
|
|
795
|
+
var r, s;
|
|
796
|
+
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);
|
|
797
|
+
t[6] = t[6] & 15 | 64, t[8] = t[8] & 63 | 128;
|
|
798
|
+
const e = [...t].map((i) => i.toString(16).padStart(2, "0")).join("");
|
|
799
|
+
return `${e.slice(0, 8)}-${e.slice(8, 12)}-${e.slice(12, 16)}-${e.slice(16, 20)}-${e.slice(20)}`;
|
|
800
|
+
})();
|
|
801
|
+
}, I = (a) => {
|
|
802
|
+
var t, e;
|
|
803
|
+
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);
|
|
804
|
+
};
|
|
805
|
+
async function R(a = nt) {
|
|
806
|
+
const t = await w(), e = I(await t.kv.get(m));
|
|
807
|
+
if (e) {
|
|
808
|
+
const r = await t.users.get(e);
|
|
809
|
+
if (r) return f.parse(r);
|
|
810
|
+
}
|
|
811
|
+
try {
|
|
812
|
+
return await t.transaction("rw", t.kv, t.users, async () => {
|
|
813
|
+
const r = I(await t.kv.get(m));
|
|
814
|
+
if (r) {
|
|
815
|
+
const o = await t.users.get(r);
|
|
816
|
+
if (o) return f.parse(o);
|
|
817
|
+
}
|
|
818
|
+
const s = a();
|
|
819
|
+
await t.kv.add({ key: m, value: { useruuid: s } });
|
|
820
|
+
const i = f.parse({
|
|
821
|
+
uuid: s,
|
|
822
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
823
|
+
});
|
|
824
|
+
return await t.users.add(i), i;
|
|
825
|
+
});
|
|
826
|
+
} catch (r) {
|
|
827
|
+
if ((r == null ? void 0 : r.name) === "ConstraintError") {
|
|
828
|
+
const s = I(await t.kv.get(m));
|
|
829
|
+
if (s) {
|
|
830
|
+
const i = await t.users.get(s);
|
|
831
|
+
if (i) return f.parse(i);
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
throw r;
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
const vt = async (a) => (await R(a)).uuid;
|
|
838
|
+
async function st() {
|
|
839
|
+
const a = await w(), t = {};
|
|
840
|
+
for (const e of a.tables)
|
|
841
|
+
t[e.name] = await e.toArray();
|
|
842
|
+
return t;
|
|
843
|
+
}
|
|
844
|
+
async function bt(a = "inresi-orm-export.json") {
|
|
845
|
+
if (typeof window > "u" || typeof document > "u")
|
|
846
|
+
throw new Error("exportJSON can only run in a browser.");
|
|
847
|
+
const t = await st(), e = new Blob([JSON.stringify(t, null, 2)], { type: "application/json" }), r = document.createElement("a");
|
|
848
|
+
r.href = URL.createObjectURL(e), r.download = a, document.body.appendChild(r), r.click(), r.remove(), URL.revokeObjectURL(r.href);
|
|
849
|
+
}
|
|
850
|
+
const L = (a, t) => `favorites:${a}:${t}`;
|
|
851
|
+
async function V(a) {
|
|
852
|
+
const t = await w(), { uuid: e } = await R(), r = L(e, String(a)), s = await t.kv.get(r), i = s ? O.safeParse(s.value) : null;
|
|
853
|
+
return i != null && i.success ? i.data.unitIds : [];
|
|
854
|
+
}
|
|
855
|
+
async function Q(a, t, e) {
|
|
856
|
+
const r = await w(), { uuid: s } = await R(), i = L(s, String(a));
|
|
857
|
+
return r.transaction("rw", r.kv, async () => {
|
|
858
|
+
const o = await r.kv.get(i), l = o && O.safeParse(o.value).success ? o.value : { unitIds: [], updatedAt: (/* @__PURE__ */ new Date()).toISOString() }, u = new Set(l.unitIds);
|
|
859
|
+
e ? u.add(t) : u.delete(t);
|
|
860
|
+
const y = {
|
|
861
|
+
unitIds: [...u],
|
|
862
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
863
|
+
}, p = O.parse(y);
|
|
864
|
+
return await r.kv.put({ key: i, value: p }), p.unitIds;
|
|
865
|
+
});
|
|
866
|
+
}
|
|
867
|
+
async function ot(a, t) {
|
|
868
|
+
const r = !(await V(a)).includes(t);
|
|
869
|
+
return Q(a, t, r);
|
|
870
|
+
}
|
|
871
|
+
async function lt(a, t) {
|
|
872
|
+
return (await V(a)).includes(t);
|
|
873
|
+
}
|
|
874
|
+
function ct(a) {
|
|
875
|
+
return (t, e) => {
|
|
876
|
+
const r = async () => {
|
|
877
|
+
const i = await c.getFullState();
|
|
878
|
+
t({
|
|
879
|
+
properties: i.properties,
|
|
880
|
+
currentPropertyId: i.currentPropertyId,
|
|
881
|
+
currentPropertySlug: i.currentPropertySlug,
|
|
882
|
+
hasPreviouslySearched: i.hasPreviouslySearched,
|
|
883
|
+
filters: i.filters,
|
|
884
|
+
tempFilters: i.tempFilters,
|
|
885
|
+
apiFilters: i.apiFilters,
|
|
886
|
+
resultsMode: i.resultsMode,
|
|
887
|
+
resolvedQuestionnaireValues: i.resolvedQuestionnaireValues,
|
|
888
|
+
sortBy: i.sortBy,
|
|
889
|
+
filtersLoaded: i.filtersLoaded
|
|
890
|
+
});
|
|
891
|
+
}, s = async () => {
|
|
892
|
+
if (a != null && a.onFilterUpdate) {
|
|
893
|
+
const i = (await c.getFullState()).apiFilters;
|
|
894
|
+
a.onFilterUpdate(i);
|
|
895
|
+
}
|
|
896
|
+
};
|
|
897
|
+
return {
|
|
898
|
+
// Initial state
|
|
899
|
+
properties: {},
|
|
900
|
+
currentPropertyId: null,
|
|
901
|
+
currentPropertySlug: null,
|
|
902
|
+
hasPreviouslySearched: [],
|
|
903
|
+
units: {},
|
|
904
|
+
filters: {
|
|
905
|
+
availability: void 0,
|
|
906
|
+
bedrooms: void 0,
|
|
907
|
+
cost: void 0,
|
|
908
|
+
highlights: void 0
|
|
909
|
+
},
|
|
910
|
+
tempFilters: {
|
|
911
|
+
availability: void 0,
|
|
912
|
+
bedrooms: void 0,
|
|
913
|
+
cost: void 0,
|
|
914
|
+
highlights: void 0
|
|
915
|
+
},
|
|
916
|
+
apiFilters: {
|
|
917
|
+
limit: 10,
|
|
918
|
+
page: 1
|
|
919
|
+
},
|
|
920
|
+
resultsMode: "all",
|
|
921
|
+
resolvedQuestionnaireValues: {},
|
|
922
|
+
sortBy: "relevance",
|
|
923
|
+
filtersLoaded: !1,
|
|
924
|
+
// === PROPERTY OPERATIONS ===
|
|
925
|
+
async initializeProperty(i, o) {
|
|
926
|
+
await c.initializeProperty(i, o), await r();
|
|
927
|
+
},
|
|
928
|
+
async setCurrentProperty(i, o) {
|
|
929
|
+
await c.setCurrentProperty(i, o), t({
|
|
930
|
+
currentPropertyId: i,
|
|
931
|
+
...o && { currentPropertySlug: o }
|
|
932
|
+
});
|
|
933
|
+
},
|
|
934
|
+
async setCurrentPropertySlug(i) {
|
|
935
|
+
await c.setCurrentPropertySlug(i), t({ currentPropertySlug: i });
|
|
936
|
+
},
|
|
937
|
+
async setHasPreviouslySearched(i) {
|
|
938
|
+
await c.setHasPreviouslySearched(i), await r();
|
|
939
|
+
},
|
|
940
|
+
async toggleFavorite(i) {
|
|
941
|
+
await c.toggleFavorite(i), await r();
|
|
942
|
+
},
|
|
943
|
+
async markUnitAsViewed(i, o) {
|
|
944
|
+
await c.markUnitAsViewed(i, o), await r();
|
|
945
|
+
},
|
|
946
|
+
async setTourContactedOn() {
|
|
947
|
+
await c.setTourContactedOn(), await r();
|
|
948
|
+
},
|
|
949
|
+
getTourContactedOn: c.getTourContactedOn.bind(c),
|
|
950
|
+
async setQuestionnaireResults(i) {
|
|
951
|
+
await c.setQuestionnaireResults(i), await r();
|
|
952
|
+
},
|
|
953
|
+
async setTourContactData(i) {
|
|
954
|
+
await c.setTourContactData(i), await r();
|
|
955
|
+
},
|
|
956
|
+
// === FILTER OPERATIONS ===
|
|
957
|
+
async setFilters(i) {
|
|
958
|
+
await c.setFilters(i);
|
|
959
|
+
const o = e();
|
|
960
|
+
t({ filters: { ...o.filters, ...i } });
|
|
961
|
+
},
|
|
962
|
+
async setTempFilters(i) {
|
|
963
|
+
await c.setTempFilters(i);
|
|
964
|
+
const o = e();
|
|
965
|
+
t({ tempFilters: { ...o.tempFilters, ...i } });
|
|
966
|
+
},
|
|
967
|
+
async setFiltersToDefault() {
|
|
968
|
+
await c.setFiltersToDefault(), t({ filters: {
|
|
969
|
+
availability: void 0,
|
|
970
|
+
bedrooms: void 0,
|
|
971
|
+
cost: void 0,
|
|
972
|
+
highlights: void 0
|
|
973
|
+
} });
|
|
974
|
+
},
|
|
975
|
+
async setApiFilters(i) {
|
|
976
|
+
await c.setApiFilters(i);
|
|
977
|
+
const o = e();
|
|
978
|
+
t({ apiFilters: { ...o.apiFilters, ...i } });
|
|
979
|
+
},
|
|
980
|
+
async handleTempFilterChange(i, o) {
|
|
981
|
+
await c.handleTempFilterChange(i, o);
|
|
982
|
+
const l = e();
|
|
983
|
+
t({ tempFilters: { ...l.tempFilters, [i]: o } });
|
|
984
|
+
},
|
|
985
|
+
async commitTempFilterChange(i, o) {
|
|
986
|
+
await c.commitTempFilterChange(i, o), await r(), await s();
|
|
987
|
+
},
|
|
988
|
+
async handleFilterCommitIndexDB(i) {
|
|
989
|
+
await c.handleFilterCommitIndexDB(i), await r(), await s();
|
|
990
|
+
},
|
|
991
|
+
async commitAvailabilityChange() {
|
|
992
|
+
await c.commitAvailabilityChange(), await r(), await s();
|
|
993
|
+
},
|
|
994
|
+
async submitFilterUpdate() {
|
|
995
|
+
await c.submitFilterUpdate(), await r(), await s();
|
|
996
|
+
},
|
|
997
|
+
// === RESULTS AND SORTING ===
|
|
998
|
+
async setResultsMode(i) {
|
|
999
|
+
await c.setResultsMode(i), t({ resultsMode: i });
|
|
1000
|
+
},
|
|
1001
|
+
async setSortBy(i) {
|
|
1002
|
+
await c.setSortBy(i), t({ sortBy: i });
|
|
1003
|
+
},
|
|
1004
|
+
// === QUESTIONNAIRE ===
|
|
1005
|
+
async setResolvedQuestionnaireValues(i, o) {
|
|
1006
|
+
await c.setResolvedQuestionnaireValues(i, o);
|
|
1007
|
+
const l = e();
|
|
1008
|
+
t({
|
|
1009
|
+
resolvedQuestionnaireValues: {
|
|
1010
|
+
...l.resolvedQuestionnaireValues,
|
|
1011
|
+
[i]: o
|
|
1012
|
+
}
|
|
1013
|
+
});
|
|
1014
|
+
},
|
|
1015
|
+
// === UTILITY METHODS ===
|
|
1016
|
+
getUnitState(i) {
|
|
1017
|
+
var u;
|
|
1018
|
+
const o = e(), l = o.currentPropertyId ? o.properties[o.currentPropertyId] : null;
|
|
1019
|
+
return {
|
|
1020
|
+
isFavorite: (l == null ? void 0 : l.favoritedUnits.includes(i)) ?? !1,
|
|
1021
|
+
viewedDate: ((u = l == null ? void 0 : l.viewedUnits.find((y) => y.unitId === i)) == null ? void 0 : u.viewedDate) ?? ""
|
|
1022
|
+
};
|
|
1023
|
+
},
|
|
1024
|
+
getResultsUrl: c.getResultsUrl.bind(c),
|
|
1025
|
+
getCurrentProperty: c.getCurrentProperty.bind(c),
|
|
1026
|
+
getPropertyData: c.getPropertyData.bind(c),
|
|
1027
|
+
// === LEGACY COMPATIBILITY ===
|
|
1028
|
+
async setData(i) {
|
|
1029
|
+
await c.setData(i), t({ properties: i });
|
|
1030
|
+
},
|
|
1031
|
+
async setPropertySlug(i) {
|
|
1032
|
+
await c.setPropertySlug(i), t({ currentPropertySlug: i });
|
|
1033
|
+
},
|
|
1034
|
+
async setPropertyId(i) {
|
|
1035
|
+
await c.setPropertyId(i), t({ currentPropertyId: i });
|
|
1036
|
+
},
|
|
1037
|
+
async removeData(i) {
|
|
1038
|
+
await c.removeData(i), await r();
|
|
1039
|
+
},
|
|
1040
|
+
async clearData() {
|
|
1041
|
+
await c.clearData(), t({ properties: {} });
|
|
1042
|
+
},
|
|
1043
|
+
async loadPersistedFilters() {
|
|
1044
|
+
await c.loadPersistedFilters(), t({ filtersLoaded: !0 });
|
|
1045
|
+
},
|
|
1046
|
+
// === INTERNAL ===
|
|
1047
|
+
async _hydrate() {
|
|
1048
|
+
await r();
|
|
1049
|
+
},
|
|
1050
|
+
async _initialize() {
|
|
1051
|
+
await c.initialize(), await r();
|
|
1052
|
+
}
|
|
1053
|
+
};
|
|
1054
|
+
};
|
|
1055
|
+
}
|
|
1056
|
+
function Pt() {
|
|
1057
|
+
return (a) => (t) => a((e) => e.getUnitState(t));
|
|
1058
|
+
}
|
|
1059
|
+
function ut(a) {
|
|
1060
|
+
return {
|
|
1061
|
+
property: {
|
|
1062
|
+
unit: {
|
|
1063
|
+
favorites: {
|
|
1064
|
+
toggle: a.toggleFavorite.bind(a)
|
|
1065
|
+
},
|
|
1066
|
+
viewed: {
|
|
1067
|
+
mark: a.markUnitAsViewed.bind(a)
|
|
1068
|
+
}
|
|
1069
|
+
},
|
|
1070
|
+
questionnaire: {
|
|
1071
|
+
setResults: a.setQuestionnaireResults.bind(a)
|
|
1072
|
+
},
|
|
1073
|
+
tour: {
|
|
1074
|
+
setContactedOn: a.setTourContactedOn.bind(a),
|
|
1075
|
+
getContactedOn: a.getTourContactedOn.bind(a),
|
|
1076
|
+
setContactData: a.setTourContactData.bind(a)
|
|
1077
|
+
}
|
|
1078
|
+
},
|
|
1079
|
+
filters: {
|
|
1080
|
+
set: a.setFilters.bind(a),
|
|
1081
|
+
setTemp: a.setTempFilters.bind(a),
|
|
1082
|
+
setToDefault: a.setFiltersToDefault.bind(a),
|
|
1083
|
+
commitTemp: a.commitTempFilterChange.bind(a),
|
|
1084
|
+
commitAvailability: a.commitAvailabilityChange.bind(a),
|
|
1085
|
+
submit: a.submitFilterUpdate.bind(a)
|
|
1086
|
+
}
|
|
1087
|
+
};
|
|
1088
|
+
}
|
|
1089
|
+
function Ft(a) {
|
|
1090
|
+
return (t, e) => {
|
|
1091
|
+
const r = ct(a)(t, e), s = ut(r);
|
|
1092
|
+
return {
|
|
1093
|
+
...r,
|
|
1094
|
+
...s
|
|
1095
|
+
};
|
|
1096
|
+
};
|
|
1097
|
+
}
|
|
1098
|
+
const Dt = {
|
|
1099
|
+
async isFavorite(a, t) {
|
|
1100
|
+
return lt(a, t);
|
|
1101
|
+
},
|
|
1102
|
+
async toggle(a, t) {
|
|
1103
|
+
return ot(a, t);
|
|
1104
|
+
},
|
|
1105
|
+
async set(a, t, e) {
|
|
1106
|
+
return Q(a, t, e);
|
|
1107
|
+
},
|
|
1108
|
+
async getAll(a) {
|
|
1109
|
+
return V(a);
|
|
1110
|
+
}
|
|
1111
|
+
};
|
|
1112
|
+
export {
|
|
1113
|
+
St as AppStoreDataSchema,
|
|
1114
|
+
O as FavoritesSchema,
|
|
1115
|
+
M as FiltersSchema,
|
|
1116
|
+
B as OpenDBError,
|
|
1117
|
+
G as PropertyDataSchema,
|
|
1118
|
+
Z as PropertyStore,
|
|
1119
|
+
gt as PropertyStoreDataSchema,
|
|
1120
|
+
X as QueryParamsSchema,
|
|
1121
|
+
b as SCHEMA_VERSION,
|
|
1122
|
+
x as SchemaMismatchError,
|
|
1123
|
+
K as TourContactDataSchema,
|
|
1124
|
+
it as UnifiedStore,
|
|
1125
|
+
mt as UnifiedStoreDataSchema,
|
|
1126
|
+
W as UnitDataSchema,
|
|
1127
|
+
f as UserSchema,
|
|
1128
|
+
J as ViewedUnitSchema,
|
|
1129
|
+
H as configureValidation,
|
|
1130
|
+
ht as createORMStringStorage,
|
|
1131
|
+
Ft as createStructuredStore,
|
|
1132
|
+
ut as createStructuredStoreActions,
|
|
1133
|
+
Pt as createUseUnitState,
|
|
1134
|
+
ct as createZustandPropertyStore,
|
|
1135
|
+
ct as createZustandUnifiedStore,
|
|
1136
|
+
st as debugDump,
|
|
1137
|
+
nt as defaultIdGenerator,
|
|
1138
|
+
R as ensureUser,
|
|
1139
|
+
bt as exportJSON,
|
|
1140
|
+
Dt as favorites,
|
|
1141
|
+
w as getDB,
|
|
1142
|
+
V as getFavoritedUnitsForProperty,
|
|
1143
|
+
vt as getUserUUID,
|
|
1144
|
+
lt as isUnitFavorited,
|
|
1145
|
+
j as kvGet,
|
|
1146
|
+
wt as kvRemove,
|
|
1147
|
+
E as kvSet,
|
|
1148
|
+
ft as propertyStore,
|
|
1149
|
+
pt as resetDB,
|
|
1150
|
+
Q as setFavoriteUnit,
|
|
1151
|
+
c as store,
|
|
1152
|
+
ot as toggleFavoriteUnit
|
|
1153
|
+
};
|
|
1154
|
+
//# sourceMappingURL=index.mjs.map
|