@superbright/indexeddb-orm 0.1.3 → 0.1.4
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 +8 -9
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +777 -476
- package/dist/index.mjs.map +1 -1
- package/package.json +21 -20
package/dist/index.mjs
CHANGED
|
@@ -1,63 +1,216 @@
|
|
|
1
1
|
import { z as n } from "zod";
|
|
2
|
-
import
|
|
3
|
-
class
|
|
2
|
+
import nt from "dexie";
|
|
3
|
+
class it extends Error {
|
|
4
4
|
constructor(t, e) {
|
|
5
5
|
super(t), this.detail = e, this.name = "SchemaMismatchError";
|
|
6
6
|
}
|
|
7
7
|
}
|
|
8
|
-
class
|
|
8
|
+
class st extends Error {
|
|
9
9
|
constructor(t, e) {
|
|
10
10
|
super(t), this.detail = e, this.name = "OpenDBError";
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
-
|
|
13
|
+
const I = 1, m = n.object({
|
|
14
|
+
uuid: n.string().uuid(),
|
|
15
|
+
// stored as ISO string; include to match ensureUser()
|
|
16
|
+
createdAt: n.string().datetime().optional()
|
|
17
|
+
}), ot = n.object({
|
|
18
|
+
isFavorite: n.boolean().optional(),
|
|
19
|
+
viewedDate: n.string().optional()
|
|
20
|
+
}), lt = ot, R = n.union([
|
|
21
|
+
n.string(),
|
|
22
|
+
n.number(),
|
|
23
|
+
n.boolean(),
|
|
24
|
+
n.record(n.unknown())
|
|
25
|
+
]), ut = n.union([
|
|
26
|
+
R,
|
|
27
|
+
n.array(R)
|
|
28
|
+
]), A = n.object({
|
|
29
|
+
availability: ut.nullable().optional(),
|
|
30
|
+
bedrooms: n.union([n.array(R), n.null()]).optional(),
|
|
31
|
+
cost: n.number().nullable().optional(),
|
|
32
|
+
highlights: n.array(R).optional()
|
|
33
|
+
}), G = n.object({
|
|
34
|
+
limit: n.number().default(10),
|
|
35
|
+
page: n.number().default(1),
|
|
36
|
+
availability: n.array(n.string()).optional(),
|
|
37
|
+
bedrooms: n.array(n.number()).optional(),
|
|
38
|
+
cost: n.number().nullable().optional(),
|
|
39
|
+
highlights: n.array(n.string()).optional()
|
|
40
|
+
}), K = n.enum(["all", "bestFit", "closestMatch", "favorites", "loading"]), Z = n.enum(["relevance", "newest", "priceLowToHigh", "priceHighToLow"]), Tt = n.object({
|
|
41
|
+
data: n.record(lt),
|
|
42
|
+
filters: A,
|
|
43
|
+
tempFilters: A,
|
|
44
|
+
apiFilters: G,
|
|
45
|
+
resultsMode: K,
|
|
46
|
+
propertySlug: n.string().nullable(),
|
|
47
|
+
resolvedQuestionnaireValues: n.record(n.array(n.string())),
|
|
48
|
+
sortBy: Z
|
|
49
|
+
}), b = n.object({
|
|
50
|
+
id: n.union([n.number().int(), n.string()]).optional(),
|
|
51
|
+
title: n.string(),
|
|
52
|
+
slug: n.string().nullable().optional(),
|
|
53
|
+
bedrooms: n.coerce.number().nullable().optional(),
|
|
54
|
+
bathrooms: n.coerce.number().nullable().optional(),
|
|
55
|
+
cost: n.coerce.number().nullable().optional(),
|
|
56
|
+
totalSqFt: n.coerce.number().nullable().optional(),
|
|
57
|
+
propertyId: n.union([n.number().int(), n.string()]).optional(),
|
|
58
|
+
isAvailable: n.boolean().optional(),
|
|
59
|
+
createdAt: n.string().datetime().optional(),
|
|
60
|
+
updatedAt: n.string().datetime().optional(),
|
|
61
|
+
availability: n.string().datetime().nullable().optional(),
|
|
62
|
+
unitSetAvailableOn: n.string().datetime().nullable().optional(),
|
|
63
|
+
floorPlanId: n.union([n.number().int(), n.string()]).nullable().optional(),
|
|
64
|
+
// Relations and nested structures kept loose to avoid coupling
|
|
65
|
+
property: n.unknown().optional(),
|
|
66
|
+
amenities: n.array(n.unknown()).optional(),
|
|
67
|
+
highlights: n.array(n.unknown()).optional(),
|
|
68
|
+
floorPlan: n.unknown().nullable().optional(),
|
|
69
|
+
renderedStyle: n.array(n.unknown()).optional(),
|
|
70
|
+
video: n.unknown().nullable().optional(),
|
|
71
|
+
videoThumbnail: n.unknown().nullable().optional(),
|
|
72
|
+
embedGif: n.unknown().nullable().optional(),
|
|
73
|
+
userId: n.union([n.number().int(), n.string()]).optional(),
|
|
74
|
+
user: n.unknown().optional(),
|
|
75
|
+
status: n.string().optional(),
|
|
76
|
+
externalId: n.string().nullable().optional(),
|
|
77
|
+
unitRenderedStyles: n.array(n.unknown()).optional()
|
|
78
|
+
}), v = n.object({
|
|
79
|
+
id: n.union([n.number().int(), n.string()]),
|
|
80
|
+
createdAt: n.string().datetime(),
|
|
81
|
+
updatedAt: n.string().datetime(),
|
|
82
|
+
title: n.string(),
|
|
83
|
+
slug: n.string().nullable().optional(),
|
|
84
|
+
description: n.string(),
|
|
85
|
+
contactName: n.string().nullable().optional(),
|
|
86
|
+
contactEmail: n.string().optional(),
|
|
87
|
+
contactPhone: n.string().nullable().optional(),
|
|
88
|
+
notificationEmail: n.string().nullable().optional(),
|
|
89
|
+
logo: n.unknown().nullable().optional(),
|
|
90
|
+
leadMedia: n.unknown().nullable().optional(),
|
|
91
|
+
overviewImages: n.array(n.unknown()).optional(),
|
|
92
|
+
amenityImages: n.array(n.unknown()).optional(),
|
|
93
|
+
street: n.string().optional(),
|
|
94
|
+
city: n.string().optional(),
|
|
95
|
+
state: n.string().nullable().optional(),
|
|
96
|
+
ingestionFileName: n.string().nullable().optional(),
|
|
97
|
+
zip: n.string().optional(),
|
|
98
|
+
country: n.string().optional(),
|
|
99
|
+
units: n.array(b).optional(),
|
|
100
|
+
amenities: n.array(n.unknown()).optional(),
|
|
101
|
+
highlights: n.array(n.unknown()).optional(),
|
|
102
|
+
externalServices: n.array(n.unknown()).optional(),
|
|
103
|
+
userId: n.union([n.number().int(), n.string()]).optional(),
|
|
104
|
+
user: n.unknown().optional(),
|
|
105
|
+
status: n.string().optional(),
|
|
106
|
+
floorPlans: n.array(n.unknown()).optional()
|
|
107
|
+
}), Mt = n.object({
|
|
108
|
+
id: n.union([n.number().int(), n.string()]).optional(),
|
|
109
|
+
email: n.string().email().optional(),
|
|
110
|
+
firstName: n.string().optional(),
|
|
111
|
+
lastName: n.string().optional(),
|
|
112
|
+
password: n.string().optional(),
|
|
113
|
+
salt: n.string().optional(),
|
|
114
|
+
role: n.string().optional(),
|
|
115
|
+
Property: n.array(v).optional(),
|
|
116
|
+
Unit: n.array(b).optional(),
|
|
117
|
+
floorPlans: n.array(n.unknown()).optional(),
|
|
118
|
+
createdAt: n.string().datetime().optional(),
|
|
119
|
+
updatedAt: n.string().datetime().optional()
|
|
120
|
+
}), ct = n.object({
|
|
121
|
+
unitId: n.string(),
|
|
122
|
+
viewedDate: n.string()
|
|
123
|
+
}), dt = n.object({
|
|
124
|
+
timezone: n.string().optional(),
|
|
125
|
+
favouriteUnits: n.array(n.coerce.string()).optional(),
|
|
126
|
+
preferences: n.record(n.unknown()).optional()
|
|
127
|
+
}), C = n.object({
|
|
128
|
+
id: n.coerce.string(),
|
|
129
|
+
slug: n.string(),
|
|
130
|
+
favoritedUnits: n.array(n.string()),
|
|
131
|
+
tourContactedOn: n.string().nullable(),
|
|
132
|
+
viewedUnits: n.array(ct),
|
|
133
|
+
questionnaireResults: n.unknown().nullable().optional(),
|
|
134
|
+
tourContactData: dt.nullable().optional(),
|
|
135
|
+
// Full property payload persisted alongside per-property state
|
|
136
|
+
data: v.optional()
|
|
137
|
+
}), O = n.object({
|
|
138
|
+
data: n.record(C),
|
|
139
|
+
propertySlug: n.string().nullable(),
|
|
140
|
+
propertyId: n.string().nullable(),
|
|
141
|
+
hasPreviouslySearched: n.array(n.string())
|
|
142
|
+
}), Et = n.object({
|
|
143
|
+
id: n.number().int(),
|
|
144
|
+
userId: n.number().int(),
|
|
145
|
+
unitId: n.number().int(),
|
|
146
|
+
createdAt: n.string().datetime()
|
|
147
|
+
}), N = n.object({
|
|
148
|
+
// per-property favorites are stored under a KV key, so propertyId is implicit
|
|
149
|
+
unitIds: n.array(n.string()),
|
|
150
|
+
updatedAt: n.string().datetime()
|
|
151
|
+
}), T = n.object({
|
|
152
|
+
// Property-related data
|
|
153
|
+
properties: n.record(C),
|
|
154
|
+
currentPropertyId: n.string().nullable(),
|
|
155
|
+
currentPropertySlug: n.string().nullable(),
|
|
156
|
+
hasPreviouslySearched: n.array(n.string()),
|
|
157
|
+
// App-level data
|
|
158
|
+
unitResults: n.array(b),
|
|
159
|
+
filters: A,
|
|
160
|
+
tempFilters: A,
|
|
161
|
+
apiFilters: G,
|
|
162
|
+
resultsMode: K,
|
|
163
|
+
resolvedQuestionnaireValues: n.record(n.array(n.string())),
|
|
164
|
+
sortBy: Z
|
|
165
|
+
});
|
|
166
|
+
class x extends nt {
|
|
14
167
|
constructor(t = "inresi-orm") {
|
|
15
|
-
super(t), this.version(
|
|
168
|
+
super(t), this.version(I).stores({
|
|
16
169
|
users: "uuid",
|
|
17
170
|
kv: "key"
|
|
18
171
|
}), this.users = this.table("users"), this.kv = this.table("kv");
|
|
19
172
|
}
|
|
20
173
|
}
|
|
21
|
-
let
|
|
22
|
-
function
|
|
23
|
-
|
|
174
|
+
let _ = "strict", D;
|
|
175
|
+
function pt(r) {
|
|
176
|
+
r.mode && (_ = r.mode), D = r.onIssue;
|
|
24
177
|
}
|
|
25
|
-
function
|
|
26
|
-
const
|
|
27
|
-
if (
|
|
28
|
-
const s =
|
|
29
|
-
if (
|
|
30
|
-
throw new
|
|
31
|
-
return
|
|
178
|
+
function h(r, t, e) {
|
|
179
|
+
const a = r.safeParse(t);
|
|
180
|
+
if (a.success) return a.data;
|
|
181
|
+
const s = a.error.flatten();
|
|
182
|
+
if (D == null || D(e, s), _ === "strict")
|
|
183
|
+
throw new it(`ORM schema mismatch in ${e}`, s);
|
|
184
|
+
return _ === "warn" && console.warn(`ORM schema mismatch in ${e}`, s), null;
|
|
32
185
|
}
|
|
33
|
-
const
|
|
34
|
-
let
|
|
35
|
-
const
|
|
36
|
-
function
|
|
37
|
-
const e =
|
|
38
|
-
if (e[
|
|
39
|
-
if (e[
|
|
40
|
-
i.hook("creating", (u,
|
|
41
|
-
const
|
|
42
|
-
if (!
|
|
43
|
-
return
|
|
44
|
-
}), i.hook("updating", (u,
|
|
45
|
-
const
|
|
46
|
-
return
|
|
186
|
+
const yt = { BASE_URL: "/", DEV: !1, MODE: "production", PROD: !0, SSR: !1 }, M = "manifest", gt = n.object({ schemaVersion: n.number().int() });
|
|
187
|
+
let w = null, S = null;
|
|
188
|
+
const q = Symbol("validationInstalled");
|
|
189
|
+
function E(r, t) {
|
|
190
|
+
const e = r;
|
|
191
|
+
if (e[q]) return;
|
|
192
|
+
if (e[q] = !0, ((i, o, l) => {
|
|
193
|
+
i.hook("creating", (u, d) => {
|
|
194
|
+
const y = h(o, d, `${l}.creating`);
|
|
195
|
+
if (!y) throw new Error(`Rejected invalid ${l} on create`);
|
|
196
|
+
return y;
|
|
197
|
+
}), i.hook("updating", (u, d, y) => {
|
|
198
|
+
const p = { ...y, ...u };
|
|
199
|
+
return h(o, p, `${l}.updating`) ? u : {};
|
|
47
200
|
});
|
|
48
|
-
})(
|
|
201
|
+
})(r.users, m, "users"), (t == null ? void 0 : t.validateReads) ?? !0) {
|
|
49
202
|
const i = (t == null ? void 0 : t.dropInvalidOnRead) ?? !0;
|
|
50
|
-
((l, u,
|
|
51
|
-
l.hook("reading", (
|
|
52
|
-
const
|
|
53
|
-
return
|
|
203
|
+
((l, u, d) => {
|
|
204
|
+
l.hook("reading", (y) => {
|
|
205
|
+
const p = h(u, y, `${d}.reading`);
|
|
206
|
+
return p || (i ? void 0 : y);
|
|
54
207
|
});
|
|
55
|
-
})(
|
|
208
|
+
})(r.users, m, "users");
|
|
56
209
|
}
|
|
57
210
|
}
|
|
58
|
-
function
|
|
211
|
+
function ft() {
|
|
59
212
|
try {
|
|
60
|
-
if (typeof import.meta < "u" &&
|
|
213
|
+
if (typeof import.meta < "u" && yt)
|
|
61
214
|
return !1;
|
|
62
215
|
} catch {
|
|
63
216
|
}
|
|
@@ -68,102 +221,160 @@ function q() {
|
|
|
68
221
|
}
|
|
69
222
|
return !1;
|
|
70
223
|
}
|
|
71
|
-
async function
|
|
72
|
-
if (
|
|
224
|
+
async function f(r = {}) {
|
|
225
|
+
if (w) return w;
|
|
73
226
|
if (S) return S;
|
|
74
|
-
const t =
|
|
227
|
+
const t = r.dbName ?? "inresi-orm";
|
|
75
228
|
return S = (async () => {
|
|
76
|
-
var e,
|
|
229
|
+
var e, a, s, i;
|
|
77
230
|
try {
|
|
78
|
-
const o =
|
|
79
|
-
|
|
80
|
-
mode: ((e =
|
|
81
|
-
onIssue: (
|
|
231
|
+
const o = ft() ? "warn" : "strict";
|
|
232
|
+
pt({
|
|
233
|
+
mode: ((e = r.validation) == null ? void 0 : e.mode) ?? o,
|
|
234
|
+
onIssue: (a = r.validation) == null ? void 0 : a.onIssue
|
|
82
235
|
});
|
|
83
|
-
const l = new
|
|
236
|
+
const l = new x(t);
|
|
84
237
|
l.on("versionchange", () => {
|
|
85
|
-
var
|
|
238
|
+
var p;
|
|
86
239
|
try {
|
|
87
240
|
l.close();
|
|
88
241
|
} finally {
|
|
89
|
-
(
|
|
242
|
+
(p = r.onReset) == null || p.call(r, "versionchange");
|
|
90
243
|
}
|
|
91
244
|
}), l.on("blocked", () => {
|
|
92
|
-
var
|
|
93
|
-
(
|
|
245
|
+
var p;
|
|
246
|
+
(p = r.onReset) == null || p.call(r, "blocked");
|
|
94
247
|
}), await l.open();
|
|
95
|
-
const u = await l.kv.get(
|
|
96
|
-
if (!
|
|
248
|
+
const u = await l.kv.get(M), d = (u == null ? void 0 : u.value) ?? null;
|
|
249
|
+
if (!d)
|
|
97
250
|
return await l.transaction("rw", l.kv, async () => {
|
|
98
251
|
await l.kv.put({
|
|
99
|
-
key:
|
|
100
|
-
value: { schemaVersion:
|
|
252
|
+
key: M,
|
|
253
|
+
value: { schemaVersion: I }
|
|
101
254
|
});
|
|
102
|
-
}),
|
|
103
|
-
const
|
|
104
|
-
if (!
|
|
255
|
+
}), E(l, r.validation), w = l, l;
|
|
256
|
+
const y = gt.safeParse(d);
|
|
257
|
+
if (!y.success || y.data.schemaVersion !== I) {
|
|
105
258
|
await l.delete();
|
|
106
|
-
const
|
|
107
|
-
return
|
|
259
|
+
const p = new x(t);
|
|
260
|
+
return p.on("versionchange", () => {
|
|
108
261
|
var g;
|
|
109
262
|
try {
|
|
110
|
-
|
|
263
|
+
p.close();
|
|
111
264
|
} finally {
|
|
112
|
-
(g =
|
|
265
|
+
(g = r.onReset) == null || g.call(r, "versionchange");
|
|
113
266
|
}
|
|
114
|
-
}),
|
|
267
|
+
}), p.on("blocked", () => {
|
|
115
268
|
var g;
|
|
116
|
-
(g =
|
|
117
|
-
}), await
|
|
118
|
-
key:
|
|
119
|
-
value: { schemaVersion:
|
|
120
|
-
}),
|
|
269
|
+
(g = r.onReset) == null || g.call(r, "blocked");
|
|
270
|
+
}), await p.open(), await p.kv.put({
|
|
271
|
+
key: M,
|
|
272
|
+
value: { schemaVersion: I }
|
|
273
|
+
}), E(p, r.validation), (s = r.onReset) == null || s.call(r, "incompatible"), w = p, p;
|
|
121
274
|
}
|
|
122
|
-
return
|
|
275
|
+
return E(l, r.validation), w = l, l;
|
|
123
276
|
} catch (o) {
|
|
124
|
-
throw (i =
|
|
277
|
+
throw (i = r.onError) == null || i.call(r, o), new st("Failed to open IndexedDB", o);
|
|
125
278
|
} finally {
|
|
126
279
|
S = null;
|
|
127
280
|
}
|
|
128
281
|
})(), S;
|
|
129
282
|
}
|
|
130
|
-
async function
|
|
131
|
-
const t =
|
|
132
|
-
if (
|
|
283
|
+
async function Vt(r) {
|
|
284
|
+
const t = r ?? "inresi-orm";
|
|
285
|
+
if (w)
|
|
133
286
|
try {
|
|
134
|
-
await
|
|
287
|
+
await w.close();
|
|
135
288
|
} catch {
|
|
136
289
|
}
|
|
137
|
-
await new
|
|
290
|
+
await new x(t).delete(), w = null;
|
|
138
291
|
}
|
|
139
|
-
|
|
140
|
-
|
|
292
|
+
const P = "user", ht = () => {
|
|
293
|
+
var r;
|
|
294
|
+
return typeof ((r = globalThis.crypto) == null ? void 0 : r.randomUUID) == "function" ? globalThis.crypto.randomUUID() : (() => {
|
|
295
|
+
var a, s;
|
|
296
|
+
const t = ((s = (a = globalThis.crypto) == null ? void 0 : a.getRandomValues) == null ? void 0 : s.call(a, new Uint8Array(16))) ?? Uint8Array.from({ length: 16 }, () => Math.random() * 256 | 0);
|
|
297
|
+
t[6] = t[6] & 15 | 64, t[8] = t[8] & 63 | 128;
|
|
298
|
+
const e = [...t].map((i) => i.toString(16).padStart(2, "0")).join("");
|
|
299
|
+
return `${e.slice(0, 8)}-${e.slice(8, 12)}-${e.slice(12, 16)}-${e.slice(16, 20)}-${e.slice(20)}`;
|
|
300
|
+
})();
|
|
301
|
+
}, V = (r) => {
|
|
302
|
+
var t, e;
|
|
303
|
+
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);
|
|
304
|
+
};
|
|
305
|
+
async function z(r = ht) {
|
|
306
|
+
const t = await f(), e = V(await t.kv.get(P));
|
|
307
|
+
if (e) {
|
|
308
|
+
const a = await t.users.get(e);
|
|
309
|
+
if (a) return m.parse(a);
|
|
310
|
+
}
|
|
311
|
+
try {
|
|
312
|
+
return await t.transaction("rw", t.kv, t.users, async () => {
|
|
313
|
+
const a = V(await t.kv.get(P));
|
|
314
|
+
if (a) {
|
|
315
|
+
const o = await t.users.get(a);
|
|
316
|
+
if (o) return m.parse(o);
|
|
317
|
+
}
|
|
318
|
+
const s = r();
|
|
319
|
+
await t.kv.add({ key: P, value: { useruuid: s } });
|
|
320
|
+
const i = m.parse({
|
|
321
|
+
uuid: s,
|
|
322
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
323
|
+
});
|
|
324
|
+
return await t.users.add(i), i;
|
|
325
|
+
});
|
|
326
|
+
} catch (a) {
|
|
327
|
+
if ((a == null ? void 0 : a.name) === "ConstraintError") {
|
|
328
|
+
const s = V(await t.kv.get(P));
|
|
329
|
+
if (s) {
|
|
330
|
+
const i = await t.users.get(s);
|
|
331
|
+
if (i) return m.parse(i);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
throw a;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
const $t = async (r) => (await z(r)).uuid;
|
|
338
|
+
async function wt() {
|
|
339
|
+
const r = await f(), t = {};
|
|
340
|
+
for (const e of r.tables)
|
|
341
|
+
t[e.name] = await e.toArray();
|
|
342
|
+
return t;
|
|
343
|
+
}
|
|
344
|
+
async function jt(r = "inresi-orm-export.json") {
|
|
345
|
+
if (typeof window > "u" || typeof document > "u")
|
|
346
|
+
throw new Error("exportJSON can only run in a browser.");
|
|
347
|
+
const t = await wt(), e = new Blob([JSON.stringify(t, null, 2)], { type: "application/json" }), a = document.createElement("a");
|
|
348
|
+
a.href = URL.createObjectURL(e), a.download = r, document.body.appendChild(a), a.click(), a.remove(), URL.revokeObjectURL(a.href);
|
|
349
|
+
}
|
|
350
|
+
async function W(r) {
|
|
351
|
+
const e = await (await f()).kv.get(r);
|
|
141
352
|
return (e == null ? void 0 : e.value) ?? null;
|
|
142
353
|
}
|
|
143
|
-
async function
|
|
144
|
-
await (await
|
|
354
|
+
async function Y(r, t) {
|
|
355
|
+
await (await f()).kv.put({ key: r, value: t });
|
|
145
356
|
}
|
|
146
|
-
async function
|
|
147
|
-
await (await
|
|
357
|
+
async function Nt(r) {
|
|
358
|
+
await (await f()).kv.delete(r);
|
|
148
359
|
}
|
|
149
|
-
function
|
|
150
|
-
const t = /* @__PURE__ */ new Map(), e = (
|
|
360
|
+
function xt(r) {
|
|
361
|
+
const t = /* @__PURE__ */ new Map(), e = (r == null ? void 0 : r.prefix) ?? "", a = (s) => `${e}${s}`;
|
|
151
362
|
return {
|
|
152
363
|
async getItem(s) {
|
|
153
364
|
try {
|
|
154
|
-
const o = await (await
|
|
365
|
+
const o = await (await f()).kv.get(a(s));
|
|
155
366
|
return o ? JSON.stringify(o.value) : null;
|
|
156
367
|
} catch (i) {
|
|
157
|
-
if (
|
|
368
|
+
if (r != null && r.fallbackToMemory) return t.get(a(s)) ?? null;
|
|
158
369
|
throw i;
|
|
159
370
|
}
|
|
160
371
|
},
|
|
161
372
|
async setItem(s, i) {
|
|
162
373
|
try {
|
|
163
|
-
await (await
|
|
374
|
+
await (await f()).kv.put({ key: a(s), value: JSON.parse(i) });
|
|
164
375
|
} catch (o) {
|
|
165
|
-
if (
|
|
166
|
-
t.set(
|
|
376
|
+
if (r != null && r.fallbackToMemory) {
|
|
377
|
+
t.set(a(s), i);
|
|
167
378
|
return;
|
|
168
379
|
}
|
|
169
380
|
throw o;
|
|
@@ -171,10 +382,10 @@ function ht(a) {
|
|
|
171
382
|
},
|
|
172
383
|
async removeItem(s) {
|
|
173
384
|
try {
|
|
174
|
-
await (await
|
|
385
|
+
await (await f()).kv.delete(a(s));
|
|
175
386
|
} catch (i) {
|
|
176
|
-
if (
|
|
177
|
-
t.delete(
|
|
387
|
+
if (r != null && r.fallbackToMemory) {
|
|
388
|
+
t.delete(a(s));
|
|
178
389
|
return;
|
|
179
390
|
}
|
|
180
391
|
throw i;
|
|
@@ -182,40 +393,60 @@ function ht(a) {
|
|
|
182
393
|
}
|
|
183
394
|
};
|
|
184
395
|
}
|
|
185
|
-
const
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
396
|
+
const X = (r, t) => `favorites:${r}:${t}`;
|
|
397
|
+
async function Q(r) {
|
|
398
|
+
const t = await f(), { uuid: e } = await z(), a = X(e, String(r)), s = await t.kv.get(a), i = s ? N.safeParse(s.value) : null;
|
|
399
|
+
return i != null && i.success ? i.data.unitIds : [];
|
|
400
|
+
}
|
|
401
|
+
async function tt(r, t, e) {
|
|
402
|
+
const a = await f(), { uuid: s } = await z(), i = X(s, String(r));
|
|
403
|
+
return a.transaction("rw", a.kv, async () => {
|
|
404
|
+
const o = await a.kv.get(i), l = o && N.safeParse(o.value).success ? o.value : { unitIds: [], updatedAt: (/* @__PURE__ */ new Date()).toISOString() }, u = new Set(l.unitIds);
|
|
405
|
+
e ? u.add(t) : u.delete(t);
|
|
406
|
+
const d = {
|
|
407
|
+
unitIds: [...u],
|
|
408
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
409
|
+
}, y = N.parse(d);
|
|
410
|
+
return await a.kv.put({ key: i, value: y }), y.unitIds;
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
async function mt(r, t) {
|
|
414
|
+
const a = !(await Q(r)).includes(t);
|
|
415
|
+
return tt(r, t, a);
|
|
416
|
+
}
|
|
417
|
+
async function St(r, t) {
|
|
418
|
+
return (await Q(r)).includes(t);
|
|
419
|
+
}
|
|
420
|
+
const $ = {
|
|
207
421
|
data: {},
|
|
208
422
|
propertySlug: null,
|
|
209
423
|
propertyId: null,
|
|
210
424
|
hasPreviouslySearched: []
|
|
211
425
|
};
|
|
212
|
-
class
|
|
426
|
+
class vt {
|
|
213
427
|
async getState() {
|
|
214
|
-
|
|
428
|
+
const t = await W("property");
|
|
429
|
+
if (!t) return $;
|
|
430
|
+
const e = {
|
|
431
|
+
...t,
|
|
432
|
+
propertyId: t.propertyId == null ? null : String(t.propertyId),
|
|
433
|
+
propertySlug: t.propertySlug ?? null,
|
|
434
|
+
hasPreviouslySearched: Array.isArray(t.hasPreviouslySearched) ? t.hasPreviouslySearched.map(String) : []
|
|
435
|
+
}, a = O.safeParse(e);
|
|
436
|
+
if (a.success) return a.data;
|
|
437
|
+
const s = Object.entries(e.data ?? {}).reduce((l, [u, d]) => {
|
|
438
|
+
const y = C.safeParse(d);
|
|
439
|
+
return y.success && (l[u] = y.data), l;
|
|
440
|
+
}, {}), i = {
|
|
441
|
+
...$,
|
|
442
|
+
...e,
|
|
443
|
+
data: s
|
|
444
|
+
}, o = O.safeParse(i);
|
|
445
|
+
return o.success ? o.data : $;
|
|
215
446
|
}
|
|
216
447
|
async setState(t) {
|
|
217
|
-
const e = await this.getState(),
|
|
218
|
-
await
|
|
448
|
+
const e = await this.getState(), a = t(e), s = O.parse(a);
|
|
449
|
+
await Y("property", s);
|
|
219
450
|
}
|
|
220
451
|
// Basic state operations
|
|
221
452
|
async setData(t) {
|
|
@@ -225,12 +456,13 @@ class Z {
|
|
|
225
456
|
await this.setState((e) => ({ ...e, propertySlug: t }));
|
|
226
457
|
}
|
|
227
458
|
async setPropertyId(t) {
|
|
228
|
-
await this.setState((e) => ({ ...e, propertyId: t }));
|
|
459
|
+
await this.setState((e) => ({ ...e, propertyId: String(t) }));
|
|
229
460
|
}
|
|
230
461
|
async removeData(t) {
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
462
|
+
const e = String(t);
|
|
463
|
+
await this.setState((a) => ({
|
|
464
|
+
...a,
|
|
465
|
+
data: Object.entries(a.data).filter(([s]) => s !== e).reduce((s, [i, o]) => ({ ...s, [i]: o }), {})
|
|
234
466
|
}));
|
|
235
467
|
}
|
|
236
468
|
async clearData() {
|
|
@@ -249,13 +481,13 @@ class Z {
|
|
|
249
481
|
await this.setState((t) => {
|
|
250
482
|
const e = t.propertyId;
|
|
251
483
|
if (!e) return t;
|
|
252
|
-
const
|
|
253
|
-
return
|
|
484
|
+
const a = t.data[e];
|
|
485
|
+
return a ? {
|
|
254
486
|
...t,
|
|
255
487
|
data: {
|
|
256
488
|
...t.data,
|
|
257
489
|
[e]: {
|
|
258
|
-
...
|
|
490
|
+
...a,
|
|
259
491
|
tourContactedOn: (/* @__PURE__ */ new Date()).toISOString()
|
|
260
492
|
}
|
|
261
493
|
}
|
|
@@ -263,20 +495,20 @@ class Z {
|
|
|
263
495
|
});
|
|
264
496
|
}
|
|
265
497
|
async getTourContactedOn() {
|
|
266
|
-
var
|
|
498
|
+
var a;
|
|
267
499
|
const t = await this.getState(), e = t.propertyId;
|
|
268
|
-
return e ? ((
|
|
500
|
+
return e ? ((a = t.data[e]) == null ? void 0 : a.tourContactedOn) ?? null : null;
|
|
269
501
|
}
|
|
270
502
|
async setQuestionnaireResults(t) {
|
|
271
503
|
await this.setState((e) => {
|
|
272
|
-
const
|
|
273
|
-
if (!
|
|
274
|
-
const s = e.data[
|
|
504
|
+
const a = e.propertyId;
|
|
505
|
+
if (!a) return e;
|
|
506
|
+
const s = e.data[a];
|
|
275
507
|
return s ? {
|
|
276
508
|
...e,
|
|
277
509
|
data: {
|
|
278
510
|
...e.data,
|
|
279
|
-
[
|
|
511
|
+
[a]: {
|
|
280
512
|
...s,
|
|
281
513
|
questionnaireResults: t
|
|
282
514
|
}
|
|
@@ -286,14 +518,14 @@ class Z {
|
|
|
286
518
|
}
|
|
287
519
|
async setTourContactData(t) {
|
|
288
520
|
await this.setState((e) => {
|
|
289
|
-
const
|
|
290
|
-
if (!
|
|
291
|
-
const s = e.data[
|
|
521
|
+
const a = e.propertyId;
|
|
522
|
+
if (!a) return e;
|
|
523
|
+
const s = e.data[a];
|
|
292
524
|
return s ? {
|
|
293
525
|
...e,
|
|
294
526
|
data: {
|
|
295
527
|
...e.data,
|
|
296
|
-
[
|
|
528
|
+
[a]: {
|
|
297
529
|
...s,
|
|
298
530
|
tourContactData: t
|
|
299
531
|
}
|
|
@@ -303,16 +535,16 @@ class Z {
|
|
|
303
535
|
}
|
|
304
536
|
async toggleFavorite(t) {
|
|
305
537
|
await this.setState((e) => {
|
|
306
|
-
const
|
|
307
|
-
if (!
|
|
308
|
-
const s = e.data[
|
|
538
|
+
const a = e.propertyId;
|
|
539
|
+
if (!a) return e;
|
|
540
|
+
const s = e.data[a];
|
|
309
541
|
if (!s) return e;
|
|
310
542
|
const o = s.favoritedUnits.includes(t) ? s.favoritedUnits.filter((l) => l !== t) : [...s.favoritedUnits, t];
|
|
311
543
|
return {
|
|
312
544
|
...e,
|
|
313
545
|
data: {
|
|
314
546
|
...e.data,
|
|
315
|
-
[
|
|
547
|
+
[a]: {
|
|
316
548
|
...s,
|
|
317
549
|
favoritedUnits: o
|
|
318
550
|
}
|
|
@@ -321,10 +553,10 @@ class Z {
|
|
|
321
553
|
});
|
|
322
554
|
}
|
|
323
555
|
async markUnitAsViewed(t, e) {
|
|
324
|
-
const
|
|
556
|
+
const a = /* @__PURE__ */ new Date(), s = `${String(a.getMonth() + 1).padStart(
|
|
325
557
|
2,
|
|
326
558
|
"0"
|
|
327
|
-
)}/${String(
|
|
559
|
+
)}/${String(a.getDate()).padStart(2, "0")}`;
|
|
328
560
|
await this.setState((i) => {
|
|
329
561
|
const o = i.propertyId;
|
|
330
562
|
if (!o) return i;
|
|
@@ -332,7 +564,7 @@ class Z {
|
|
|
332
564
|
if (!l) return i;
|
|
333
565
|
const u = [
|
|
334
566
|
// Remove existing entry if it exists
|
|
335
|
-
...l.viewedUnits.filter((
|
|
567
|
+
...l.viewedUnits.filter((d) => d.unitId !== t),
|
|
336
568
|
// Add updated one
|
|
337
569
|
{
|
|
338
570
|
unitId: t,
|
|
@@ -354,15 +586,15 @@ class Z {
|
|
|
354
586
|
// Utility methods for getting specific data
|
|
355
587
|
async getUnitState(t) {
|
|
356
588
|
var s;
|
|
357
|
-
const e = await this.getState(),
|
|
589
|
+
const e = await this.getState(), a = e.propertyId ? e.data[e.propertyId] : null;
|
|
358
590
|
return {
|
|
359
|
-
isFavorite: (
|
|
360
|
-
viewedDate: ((s =
|
|
591
|
+
isFavorite: (a == null ? void 0 : a.favoritedUnits.includes(t)) ?? !1,
|
|
592
|
+
viewedDate: ((s = a == null ? void 0 : a.viewedUnits.find((i) => i.unitId === t)) == null ? void 0 : s.viewedDate) ?? ""
|
|
361
593
|
};
|
|
362
594
|
}
|
|
363
595
|
async getPropertyData(t) {
|
|
364
|
-
const e = await this.getState(),
|
|
365
|
-
return
|
|
596
|
+
const e = await this.getState(), a = t == null ? e.propertyId : String(t);
|
|
597
|
+
return a ? e.data[a] ?? null : null;
|
|
366
598
|
}
|
|
367
599
|
async getCurrentProperty() {
|
|
368
600
|
const t = await this.getState();
|
|
@@ -373,14 +605,15 @@ class Z {
|
|
|
373
605
|
}
|
|
374
606
|
// Initialize property if it doesn't exist
|
|
375
607
|
async initializeProperty(t, e) {
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
608
|
+
const a = String(t);
|
|
609
|
+
await this.setState((s) => s.data[a] ? { ...s, propertyId: a, propertySlug: e } : {
|
|
610
|
+
...s,
|
|
611
|
+
propertyId: a,
|
|
379
612
|
propertySlug: e,
|
|
380
613
|
data: {
|
|
381
|
-
...
|
|
382
|
-
[
|
|
383
|
-
id:
|
|
614
|
+
...s.data,
|
|
615
|
+
[a]: {
|
|
616
|
+
id: a,
|
|
384
617
|
slug: e,
|
|
385
618
|
favoritedUnits: [],
|
|
386
619
|
tourContactedOn: null,
|
|
@@ -392,127 +625,95 @@ class Z {
|
|
|
392
625
|
});
|
|
393
626
|
}
|
|
394
627
|
}
|
|
395
|
-
const
|
|
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 = {
|
|
628
|
+
const _t = new vt(), B = {
|
|
467
629
|
availability: void 0,
|
|
468
630
|
bedrooms: void 0,
|
|
469
631
|
cost: void 0,
|
|
470
632
|
highlights: void 0
|
|
471
|
-
},
|
|
633
|
+
}, F = {
|
|
472
634
|
// Property data
|
|
473
635
|
properties: {},
|
|
474
636
|
currentPropertyId: null,
|
|
475
637
|
currentPropertySlug: null,
|
|
476
638
|
hasPreviouslySearched: [],
|
|
477
639
|
// App data
|
|
478
|
-
|
|
479
|
-
|
|
640
|
+
unitResults: [],
|
|
641
|
+
filters: B,
|
|
642
|
+
tempFilters: B,
|
|
480
643
|
apiFilters: {
|
|
481
644
|
limit: 10,
|
|
482
645
|
page: 1
|
|
483
646
|
},
|
|
484
647
|
resultsMode: "all",
|
|
485
648
|
resolvedQuestionnaireValues: {},
|
|
486
|
-
sortBy: "relevance"
|
|
487
|
-
|
|
649
|
+
sortBy: "relevance"
|
|
650
|
+
}, bt = (r) => r == null ? [] : Array.isArray(r) ? r : [r], et = (r) => bt(r).flatMap((t) => {
|
|
651
|
+
if (t == null) return [];
|
|
652
|
+
if (Array.isArray(t)) return t;
|
|
653
|
+
if (typeof t == "object" && "value" in t) {
|
|
654
|
+
const e = t.value;
|
|
655
|
+
return Array.isArray(e) ? e : e != null ? [e] : [];
|
|
656
|
+
}
|
|
657
|
+
return [t];
|
|
658
|
+
}), U = (r) => et(r).flatMap((t) => Array.isArray(t) ? t : [t]).map((t) => String(t)).map((t) => t.trim()).filter((t) => t.length > 0), J = (r) => et(r).map((t) => {
|
|
659
|
+
if (typeof t == "number" && Number.isFinite(t)) return t;
|
|
660
|
+
const e = Number(t);
|
|
661
|
+
return Number.isFinite(e) ? e : null;
|
|
662
|
+
}).filter((t) => t !== null), L = (r) => {
|
|
663
|
+
if (r == null) return null;
|
|
664
|
+
if (typeof r == "number") return Number.isFinite(r) ? r : null;
|
|
665
|
+
if (typeof r == "object" && "value" in r)
|
|
666
|
+
return L(r.value);
|
|
667
|
+
const t = Number(r);
|
|
668
|
+
return Number.isFinite(t) ? t : null;
|
|
488
669
|
};
|
|
489
|
-
class
|
|
670
|
+
class Pt {
|
|
490
671
|
async getState() {
|
|
491
|
-
const t = await
|
|
492
|
-
|
|
493
|
-
|
|
672
|
+
const t = await W("app");
|
|
673
|
+
if (!t)
|
|
674
|
+
return F;
|
|
675
|
+
const e = {
|
|
676
|
+
...F,
|
|
494
677
|
...t,
|
|
495
|
-
properties: t.properties ?? {}
|
|
496
|
-
|
|
678
|
+
properties: t.properties ?? {},
|
|
679
|
+
unitResults: t.unitResults ?? [],
|
|
680
|
+
currentPropertyId: t.currentPropertyId == null ? null : String(t.currentPropertyId),
|
|
681
|
+
currentPropertySlug: t.currentPropertySlug ?? null,
|
|
682
|
+
hasPreviouslySearched: Array.isArray(t.hasPreviouslySearched) ? t.hasPreviouslySearched.map(String) : []
|
|
683
|
+
}, a = T.safeParse(e);
|
|
684
|
+
if (a.success) return a.data;
|
|
685
|
+
const s = Object.entries(e.properties ?? {}).reduce((d, [y, p]) => {
|
|
686
|
+
const g = C.safeParse(p);
|
|
687
|
+
return g.success && (d[y] = g.data), d;
|
|
688
|
+
}, {}), o = (Array.isArray(e.unitResults) ? e.unitResults : e.unitResults && typeof e.unitResults == "object" ? Object.values(e.unitResults) : []).reduce((d, y) => {
|
|
689
|
+
const p = b.safeParse(y);
|
|
690
|
+
return p.success && d.push(p.data), d;
|
|
691
|
+
}, []), l = {
|
|
692
|
+
...e,
|
|
693
|
+
properties: s,
|
|
694
|
+
unitResults: o
|
|
695
|
+
}, u = T.safeParse(l);
|
|
696
|
+
return u.success ? u.data : F;
|
|
497
697
|
}
|
|
498
698
|
async setState(t) {
|
|
499
|
-
const e = await this.getState(),
|
|
500
|
-
await
|
|
699
|
+
const e = await this.getState(), a = t(e), s = T.parse(a);
|
|
700
|
+
await Y("app", s);
|
|
501
701
|
}
|
|
502
702
|
// === PROPERTY OPERATIONS ===
|
|
503
703
|
async initializeProperty(t, e) {
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
704
|
+
const a = String(t);
|
|
705
|
+
await this.setState((s) => s.properties && s.properties[a] ? {
|
|
706
|
+
...s,
|
|
707
|
+
currentPropertyId: a,
|
|
507
708
|
currentPropertySlug: e
|
|
508
709
|
} : {
|
|
509
|
-
...
|
|
510
|
-
currentPropertyId:
|
|
710
|
+
...s,
|
|
711
|
+
currentPropertyId: a,
|
|
511
712
|
currentPropertySlug: e,
|
|
512
713
|
properties: {
|
|
513
|
-
...
|
|
514
|
-
[
|
|
515
|
-
id:
|
|
714
|
+
...s.properties,
|
|
715
|
+
[a]: {
|
|
716
|
+
id: a,
|
|
516
717
|
slug: e,
|
|
517
718
|
favoritedUnits: [],
|
|
518
719
|
tourContactedOn: null,
|
|
@@ -523,11 +724,122 @@ class it {
|
|
|
523
724
|
}
|
|
524
725
|
});
|
|
525
726
|
}
|
|
727
|
+
// === UNIT RESULTS CACHE ===
|
|
728
|
+
async setUnitResults(t, e) {
|
|
729
|
+
console.log(t);
|
|
730
|
+
const a = e ?? b, s = [];
|
|
731
|
+
(Array.isArray(t) ? t : t && typeof t == "object" ? Object.values(t) : []).forEach((o, l) => {
|
|
732
|
+
const u = h(a, o, `unitResults[${l}]`);
|
|
733
|
+
u && s.push(u);
|
|
734
|
+
}), await this.setState((o) => ({
|
|
735
|
+
...o,
|
|
736
|
+
unitResults: s
|
|
737
|
+
}));
|
|
738
|
+
}
|
|
739
|
+
async clearUnitResults() {
|
|
740
|
+
await this.setState((t) => ({
|
|
741
|
+
...t,
|
|
742
|
+
unitResults: []
|
|
743
|
+
}));
|
|
744
|
+
}
|
|
745
|
+
// === PROPERTY DATA BAG (full property payloads & custom data) ===
|
|
746
|
+
async setPropertyData(t, e, a) {
|
|
747
|
+
const s = String(t), i = a ?? v;
|
|
748
|
+
await this.setState((o) => {
|
|
749
|
+
const l = o.properties[s];
|
|
750
|
+
if (!l) return o;
|
|
751
|
+
const u = h(i, e, `properties.${s}.data`);
|
|
752
|
+
return u ? {
|
|
753
|
+
...o,
|
|
754
|
+
properties: {
|
|
755
|
+
...o.properties,
|
|
756
|
+
[s]: {
|
|
757
|
+
...l,
|
|
758
|
+
data: u
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
} : o;
|
|
762
|
+
});
|
|
763
|
+
}
|
|
764
|
+
async mergePropertyData(t, e, a) {
|
|
765
|
+
const s = String(t), i = a ?? v;
|
|
766
|
+
await this.setState((o) => {
|
|
767
|
+
const l = o.properties[s];
|
|
768
|
+
if (!l) return o;
|
|
769
|
+
const u = l.data;
|
|
770
|
+
if (!u) {
|
|
771
|
+
const g = h(i, e, `properties.${s}.data`);
|
|
772
|
+
return g ? {
|
|
773
|
+
...o,
|
|
774
|
+
properties: {
|
|
775
|
+
...o.properties,
|
|
776
|
+
[s]: {
|
|
777
|
+
...l,
|
|
778
|
+
data: g
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
} : o;
|
|
782
|
+
}
|
|
783
|
+
const d = i.partial(), y = h(
|
|
784
|
+
d,
|
|
785
|
+
e,
|
|
786
|
+
`properties.${s}.data.partial`
|
|
787
|
+
);
|
|
788
|
+
if (!y) return o;
|
|
789
|
+
const p = h(
|
|
790
|
+
i,
|
|
791
|
+
{ ...u, ...y },
|
|
792
|
+
`properties.${s}.data`
|
|
793
|
+
);
|
|
794
|
+
return p ? {
|
|
795
|
+
...o,
|
|
796
|
+
properties: {
|
|
797
|
+
...o.properties,
|
|
798
|
+
[s]: {
|
|
799
|
+
...l,
|
|
800
|
+
data: p
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
} : o;
|
|
804
|
+
});
|
|
805
|
+
}
|
|
806
|
+
// Accepts a full API property object, validates, and stores it into the
|
|
807
|
+
// per-property `data` bag. Ensures the property entry exists/updated.
|
|
808
|
+
async upsertPropertyFromApi(t, e) {
|
|
809
|
+
const s = (e ?? v).parse(t), i = s.id ?? s.propertyId;
|
|
810
|
+
if (i == null)
|
|
811
|
+
throw new Error("upsertPropertyFromApi: property id is required");
|
|
812
|
+
const o = String(i), l = s.slug ?? void 0;
|
|
813
|
+
await this.setState((u) => {
|
|
814
|
+
const d = u.properties[o], y = d ? {
|
|
815
|
+
...d,
|
|
816
|
+
...l ? { slug: l } : {},
|
|
817
|
+
data: s
|
|
818
|
+
} : {
|
|
819
|
+
id: o,
|
|
820
|
+
slug: l ?? "",
|
|
821
|
+
favoritedUnits: [],
|
|
822
|
+
tourContactedOn: null,
|
|
823
|
+
viewedUnits: [],
|
|
824
|
+
questionnaireResults: null,
|
|
825
|
+
tourContactData: null,
|
|
826
|
+
data: s
|
|
827
|
+
};
|
|
828
|
+
return {
|
|
829
|
+
...u,
|
|
830
|
+
properties: {
|
|
831
|
+
...u.properties,
|
|
832
|
+
[o]: y
|
|
833
|
+
}
|
|
834
|
+
};
|
|
835
|
+
});
|
|
836
|
+
}
|
|
526
837
|
async setCurrentProperty(t, e) {
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
838
|
+
const a = String(t);
|
|
839
|
+
await this.setState((s) => ({
|
|
840
|
+
...s,
|
|
841
|
+
currentPropertyId: a,
|
|
842
|
+
currentPropertySlug: e || s.currentPropertySlug
|
|
531
843
|
}));
|
|
532
844
|
}
|
|
533
845
|
async setCurrentPropertySlug(t) {
|
|
@@ -546,16 +858,16 @@ class it {
|
|
|
546
858
|
}
|
|
547
859
|
async toggleFavorite(t) {
|
|
548
860
|
await this.setState((e) => {
|
|
549
|
-
const
|
|
550
|
-
if (!
|
|
551
|
-
const s = e.properties[
|
|
861
|
+
const a = e.currentPropertyId;
|
|
862
|
+
if (!a) return e;
|
|
863
|
+
const s = e.properties[a];
|
|
552
864
|
if (!s) return e;
|
|
553
865
|
const o = s.favoritedUnits.includes(t) ? s.favoritedUnits.filter((l) => l !== t) : [...s.favoritedUnits, t];
|
|
554
866
|
return {
|
|
555
867
|
...e,
|
|
556
868
|
properties: {
|
|
557
869
|
...e.properties,
|
|
558
|
-
[
|
|
870
|
+
[a]: {
|
|
559
871
|
...s,
|
|
560
872
|
favoritedUnits: o
|
|
561
873
|
}
|
|
@@ -564,17 +876,17 @@ class it {
|
|
|
564
876
|
});
|
|
565
877
|
}
|
|
566
878
|
async markUnitAsViewed(t, e) {
|
|
567
|
-
const
|
|
879
|
+
const a = /* @__PURE__ */ new Date(), s = `${String(a.getMonth() + 1).padStart(
|
|
568
880
|
2,
|
|
569
881
|
"0"
|
|
570
|
-
)}/${String(
|
|
882
|
+
)}/${String(a.getDate()).padStart(2, "0")}`;
|
|
571
883
|
await this.setState((i) => {
|
|
572
884
|
const o = i.currentPropertyId;
|
|
573
885
|
if (!o) return i;
|
|
574
886
|
const l = i.properties[o];
|
|
575
887
|
if (!l) return i;
|
|
576
888
|
const u = [
|
|
577
|
-
...l.viewedUnits.filter((
|
|
889
|
+
...l.viewedUnits.filter((d) => d.unitId !== t),
|
|
578
890
|
{ unitId: t, viewedDate: s }
|
|
579
891
|
];
|
|
580
892
|
return {
|
|
@@ -593,13 +905,13 @@ class it {
|
|
|
593
905
|
await this.setState((t) => {
|
|
594
906
|
const e = t.currentPropertyId;
|
|
595
907
|
if (!e) return t;
|
|
596
|
-
const
|
|
597
|
-
return
|
|
908
|
+
const a = t.properties[e];
|
|
909
|
+
return a ? {
|
|
598
910
|
...t,
|
|
599
911
|
properties: {
|
|
600
912
|
...t.properties,
|
|
601
913
|
[e]: {
|
|
602
|
-
...
|
|
914
|
+
...a,
|
|
603
915
|
tourContactedOn: (/* @__PURE__ */ new Date()).toISOString()
|
|
604
916
|
}
|
|
605
917
|
}
|
|
@@ -607,20 +919,20 @@ class it {
|
|
|
607
919
|
});
|
|
608
920
|
}
|
|
609
921
|
async getTourContactedOn() {
|
|
610
|
-
var
|
|
922
|
+
var a;
|
|
611
923
|
const t = await this.getState(), e = t.currentPropertyId;
|
|
612
|
-
return e ? ((
|
|
924
|
+
return e ? ((a = t.properties[e]) == null ? void 0 : a.tourContactedOn) ?? null : null;
|
|
613
925
|
}
|
|
614
926
|
async setQuestionnaireResults(t) {
|
|
615
927
|
await this.setState((e) => {
|
|
616
|
-
const
|
|
617
|
-
if (!
|
|
618
|
-
const s = e.properties[
|
|
928
|
+
const a = e.currentPropertyId;
|
|
929
|
+
if (!a) return e;
|
|
930
|
+
const s = e.properties[a];
|
|
619
931
|
return s ? {
|
|
620
932
|
...e,
|
|
621
933
|
properties: {
|
|
622
934
|
...e.properties,
|
|
623
|
-
[
|
|
935
|
+
[a]: {
|
|
624
936
|
...s,
|
|
625
937
|
questionnaireResults: t
|
|
626
938
|
}
|
|
@@ -630,14 +942,14 @@ class it {
|
|
|
630
942
|
}
|
|
631
943
|
async setTourContactData(t) {
|
|
632
944
|
await this.setState((e) => {
|
|
633
|
-
const
|
|
634
|
-
if (!
|
|
635
|
-
const s = e.properties[
|
|
945
|
+
const a = e.currentPropertyId;
|
|
946
|
+
if (!a) return e;
|
|
947
|
+
const s = e.properties[a];
|
|
636
948
|
return s ? {
|
|
637
949
|
...e,
|
|
638
950
|
properties: {
|
|
639
951
|
...e.properties,
|
|
640
|
-
[
|
|
952
|
+
[a]: {
|
|
641
953
|
...s,
|
|
642
954
|
tourContactData: t
|
|
643
955
|
}
|
|
@@ -659,7 +971,7 @@ class it {
|
|
|
659
971
|
}));
|
|
660
972
|
}
|
|
661
973
|
async setFiltersToDefault() {
|
|
662
|
-
await this.setState((t) => ({ ...t, filters:
|
|
974
|
+
await this.setState((t) => ({ ...t, filters: B }));
|
|
663
975
|
}
|
|
664
976
|
async setApiFilters(t) {
|
|
665
977
|
await this.setState((e) => ({
|
|
@@ -668,9 +980,9 @@ class it {
|
|
|
668
980
|
}));
|
|
669
981
|
}
|
|
670
982
|
async handleTempFilterChange(t, e) {
|
|
671
|
-
await this.setState((
|
|
672
|
-
...
|
|
673
|
-
tempFilters: { ...
|
|
983
|
+
await this.setState((a) => ({
|
|
984
|
+
...a,
|
|
985
|
+
tempFilters: { ...a.tempFilters, [t]: e }
|
|
674
986
|
}));
|
|
675
987
|
}
|
|
676
988
|
async commitTempFilterChange(t, e) {
|
|
@@ -679,17 +991,17 @@ class it {
|
|
|
679
991
|
}
|
|
680
992
|
async handleFilterCommitIndexDB(t) {
|
|
681
993
|
await this.setState((e) => {
|
|
682
|
-
const
|
|
994
|
+
const a = {
|
|
683
995
|
...e.apiFilters,
|
|
684
|
-
availability: t.availability
|
|
685
|
-
bedrooms: t.bedrooms
|
|
686
|
-
cost: t.cost
|
|
687
|
-
highlights: t.highlights
|
|
996
|
+
availability: U(t.availability),
|
|
997
|
+
bedrooms: J(t.bedrooms),
|
|
998
|
+
cost: L(t.cost),
|
|
999
|
+
highlights: U(t.highlights)
|
|
688
1000
|
};
|
|
689
1001
|
return {
|
|
690
1002
|
...e,
|
|
691
1003
|
filters: { ...e.filters, ...t },
|
|
692
|
-
apiFilters:
|
|
1004
|
+
apiFilters: a
|
|
693
1005
|
};
|
|
694
1006
|
});
|
|
695
1007
|
}
|
|
@@ -700,10 +1012,10 @@ class it {
|
|
|
700
1012
|
await this.setState((t) => {
|
|
701
1013
|
const e = {
|
|
702
1014
|
...t.apiFilters,
|
|
703
|
-
availability: t.filters.availability
|
|
704
|
-
bedrooms: t.filters.bedrooms
|
|
705
|
-
cost: t.filters.cost
|
|
706
|
-
highlights: t.filters.highlights
|
|
1015
|
+
availability: U(t.filters.availability),
|
|
1016
|
+
bedrooms: J(t.filters.bedrooms),
|
|
1017
|
+
cost: L(t.filters.cost),
|
|
1018
|
+
highlights: U(t.filters.highlights)
|
|
707
1019
|
};
|
|
708
1020
|
return {
|
|
709
1021
|
...t,
|
|
@@ -720,10 +1032,10 @@ class it {
|
|
|
720
1032
|
}
|
|
721
1033
|
// === QUESTIONNAIRE ===
|
|
722
1034
|
async setResolvedQuestionnaireValues(t, e) {
|
|
723
|
-
await this.setState((
|
|
724
|
-
...
|
|
1035
|
+
await this.setState((a) => ({
|
|
1036
|
+
...a,
|
|
725
1037
|
resolvedQuestionnaireValues: {
|
|
726
|
-
...
|
|
1038
|
+
...a.resolvedQuestionnaireValues,
|
|
727
1039
|
[t]: e
|
|
728
1040
|
}
|
|
729
1041
|
}));
|
|
@@ -731,10 +1043,10 @@ class it {
|
|
|
731
1043
|
// === UTILITY METHODS ===
|
|
732
1044
|
async getUnitState(t) {
|
|
733
1045
|
var s;
|
|
734
|
-
const e = await this.getState(),
|
|
1046
|
+
const e = await this.getState(), a = e.currentPropertyId ? e.properties[e.currentPropertyId] : null;
|
|
735
1047
|
return {
|
|
736
|
-
isFavorite: (
|
|
737
|
-
viewedDate: ((s =
|
|
1048
|
+
isFavorite: (a == null ? void 0 : a.favoritedUnits.includes(t)) ?? !1,
|
|
1049
|
+
viewedDate: ((s = a == null ? void 0 : a.viewedUnits.find((i) => i.unitId === t)) == null ? void 0 : s.viewedDate) ?? ""
|
|
738
1050
|
};
|
|
739
1051
|
}
|
|
740
1052
|
async getResultsUrl() {
|
|
@@ -746,22 +1058,16 @@ class it {
|
|
|
746
1058
|
return t.currentPropertyId ? t.properties[t.currentPropertyId] ?? null : null;
|
|
747
1059
|
}
|
|
748
1060
|
async getPropertyData(t) {
|
|
749
|
-
const e = await this.getState(),
|
|
750
|
-
return
|
|
1061
|
+
const e = await this.getState(), a = t == null ? e.currentPropertyId : String(t);
|
|
1062
|
+
return a ? e.properties[a] ?? null : null;
|
|
751
1063
|
}
|
|
752
1064
|
async getFullState() {
|
|
753
1065
|
return this.getState();
|
|
754
1066
|
}
|
|
755
1067
|
async initialize() {
|
|
756
|
-
|
|
757
|
-
Object.keys(t.properties).length === 0 && !t.filtersLoaded && await this.setState((e) => ({
|
|
758
|
-
...U,
|
|
759
|
-
...e,
|
|
760
|
-
filtersLoaded: !0
|
|
761
|
-
}));
|
|
1068
|
+
await this.setState((t) => ({ ...F, ...t }));
|
|
762
1069
|
}
|
|
763
1070
|
async loadPersistedFilters() {
|
|
764
|
-
await this.setState((t) => ({ ...t, filtersLoaded: !0 }));
|
|
765
1071
|
}
|
|
766
1072
|
// === LEGACY COMPATIBILITY METHODS ===
|
|
767
1073
|
// Property store compatibility
|
|
@@ -775,123 +1081,38 @@ class it {
|
|
|
775
1081
|
await this.setCurrentProperty(t);
|
|
776
1082
|
}
|
|
777
1083
|
async removeData(t) {
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
1084
|
+
const e = String(t);
|
|
1085
|
+
await this.setState((a) => {
|
|
1086
|
+
const { [e]: s, ...i } = a.properties;
|
|
1087
|
+
return { ...a, properties: i };
|
|
781
1088
|
});
|
|
782
1089
|
}
|
|
783
1090
|
async clearData() {
|
|
784
1091
|
await this.setState((t) => ({ ...t, properties: {} }));
|
|
785
1092
|
}
|
|
786
1093
|
}
|
|
787
|
-
const c = new
|
|
788
|
-
|
|
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) {
|
|
1094
|
+
const c = new Pt();
|
|
1095
|
+
function Ft(r) {
|
|
875
1096
|
return (t, e) => {
|
|
876
|
-
const
|
|
1097
|
+
const a = async () => {
|
|
877
1098
|
const i = await c.getFullState();
|
|
878
1099
|
t({
|
|
879
1100
|
properties: i.properties,
|
|
880
1101
|
currentPropertyId: i.currentPropertyId,
|
|
881
1102
|
currentPropertySlug: i.currentPropertySlug,
|
|
882
1103
|
hasPreviouslySearched: i.hasPreviouslySearched,
|
|
1104
|
+
unitResults: i.unitResults,
|
|
883
1105
|
filters: i.filters,
|
|
884
1106
|
tempFilters: i.tempFilters,
|
|
885
1107
|
apiFilters: i.apiFilters,
|
|
886
1108
|
resultsMode: i.resultsMode,
|
|
887
1109
|
resolvedQuestionnaireValues: i.resolvedQuestionnaireValues,
|
|
888
|
-
sortBy: i.sortBy
|
|
889
|
-
filtersLoaded: i.filtersLoaded
|
|
1110
|
+
sortBy: i.sortBy
|
|
890
1111
|
});
|
|
891
1112
|
}, s = async () => {
|
|
892
|
-
if (
|
|
1113
|
+
if (r != null && r.onFilterUpdate) {
|
|
893
1114
|
const i = (await c.getFullState()).apiFilters;
|
|
894
|
-
|
|
1115
|
+
r.onFilterUpdate(i);
|
|
895
1116
|
}
|
|
896
1117
|
};
|
|
897
1118
|
return {
|
|
@@ -900,7 +1121,7 @@ function ct(a) {
|
|
|
900
1121
|
currentPropertyId: null,
|
|
901
1122
|
currentPropertySlug: null,
|
|
902
1123
|
hasPreviouslySearched: [],
|
|
903
|
-
|
|
1124
|
+
unitResults: [],
|
|
904
1125
|
filters: {
|
|
905
1126
|
availability: void 0,
|
|
906
1127
|
bedrooms: void 0,
|
|
@@ -923,7 +1144,7 @@ function ct(a) {
|
|
|
923
1144
|
filtersLoaded: !1,
|
|
924
1145
|
// === PROPERTY OPERATIONS ===
|
|
925
1146
|
async initializeProperty(i, o) {
|
|
926
|
-
await c.initializeProperty(i, o), await
|
|
1147
|
+
await c.initializeProperty(i, o), await a();
|
|
927
1148
|
},
|
|
928
1149
|
async setCurrentProperty(i, o) {
|
|
929
1150
|
await c.setCurrentProperty(i, o), t({
|
|
@@ -935,23 +1156,29 @@ function ct(a) {
|
|
|
935
1156
|
await c.setCurrentPropertySlug(i), t({ currentPropertySlug: i });
|
|
936
1157
|
},
|
|
937
1158
|
async setHasPreviouslySearched(i) {
|
|
938
|
-
await c.setHasPreviouslySearched(i), await
|
|
1159
|
+
await c.setHasPreviouslySearched(i), await a();
|
|
939
1160
|
},
|
|
940
1161
|
async toggleFavorite(i) {
|
|
941
|
-
await c.toggleFavorite(i), await
|
|
1162
|
+
await c.toggleFavorite(i), await a();
|
|
942
1163
|
},
|
|
943
1164
|
async markUnitAsViewed(i, o) {
|
|
944
|
-
await c.markUnitAsViewed(i, o), await
|
|
1165
|
+
await c.markUnitAsViewed(i, o), await a();
|
|
945
1166
|
},
|
|
946
1167
|
async setTourContactedOn() {
|
|
947
|
-
await c.setTourContactedOn(), await
|
|
1168
|
+
await c.setTourContactedOn(), await a();
|
|
948
1169
|
},
|
|
949
1170
|
getTourContactedOn: c.getTourContactedOn.bind(c),
|
|
950
1171
|
async setQuestionnaireResults(i) {
|
|
951
|
-
await c.setQuestionnaireResults(i), await
|
|
1172
|
+
await c.setQuestionnaireResults(i), await a();
|
|
952
1173
|
},
|
|
953
1174
|
async setTourContactData(i) {
|
|
954
|
-
await c.setTourContactData(i), await
|
|
1175
|
+
await c.setTourContactData(i), await a();
|
|
1176
|
+
},
|
|
1177
|
+
async setUnitResults(i) {
|
|
1178
|
+
await c.setUnitResults(i), await a();
|
|
1179
|
+
},
|
|
1180
|
+
async clearUnitResults() {
|
|
1181
|
+
await c.clearUnitResults(), await a();
|
|
955
1182
|
},
|
|
956
1183
|
// === FILTER OPERATIONS ===
|
|
957
1184
|
async setFilters(i) {
|
|
@@ -983,16 +1210,16 @@ function ct(a) {
|
|
|
983
1210
|
t({ tempFilters: { ...l.tempFilters, [i]: o } });
|
|
984
1211
|
},
|
|
985
1212
|
async commitTempFilterChange(i, o) {
|
|
986
|
-
await c.commitTempFilterChange(i, o), await
|
|
1213
|
+
await c.commitTempFilterChange(i, o), await a(), await s();
|
|
987
1214
|
},
|
|
988
1215
|
async handleFilterCommitIndexDB(i) {
|
|
989
|
-
await c.handleFilterCommitIndexDB(i), await
|
|
1216
|
+
await c.handleFilterCommitIndexDB(i), await a(), await s();
|
|
990
1217
|
},
|
|
991
1218
|
async commitAvailabilityChange() {
|
|
992
|
-
await c.commitAvailabilityChange(), await
|
|
1219
|
+
await c.commitAvailabilityChange(), await a(), await s();
|
|
993
1220
|
},
|
|
994
1221
|
async submitFilterUpdate() {
|
|
995
|
-
await c.submitFilterUpdate(), await
|
|
1222
|
+
await c.submitFilterUpdate(), await a(), await s();
|
|
996
1223
|
},
|
|
997
1224
|
// === RESULTS AND SORTING ===
|
|
998
1225
|
async setResultsMode(i) {
|
|
@@ -1018,7 +1245,7 @@ function ct(a) {
|
|
|
1018
1245
|
const o = e(), l = o.currentPropertyId ? o.properties[o.currentPropertyId] : null;
|
|
1019
1246
|
return {
|
|
1020
1247
|
isFavorite: (l == null ? void 0 : l.favoritedUnits.includes(i)) ?? !1,
|
|
1021
|
-
viewedDate: ((u = l == null ? void 0 : l.viewedUnits.find((
|
|
1248
|
+
viewedDate: ((u = l == null ? void 0 : l.viewedUnits.find((d) => d.unitId === i)) == null ? void 0 : u.viewedDate) ?? ""
|
|
1022
1249
|
};
|
|
1023
1250
|
},
|
|
1024
1251
|
getResultsUrl: c.getResultsUrl.bind(c),
|
|
@@ -1035,7 +1262,7 @@ function ct(a) {
|
|
|
1035
1262
|
await c.setPropertyId(i), t({ currentPropertyId: i });
|
|
1036
1263
|
},
|
|
1037
1264
|
async removeData(i) {
|
|
1038
|
-
await c.removeData(i), await
|
|
1265
|
+
await c.removeData(i), await a();
|
|
1039
1266
|
},
|
|
1040
1267
|
async clearData() {
|
|
1041
1268
|
await c.clearData(), t({ properties: {} });
|
|
@@ -1045,110 +1272,184 @@ function ct(a) {
|
|
|
1045
1272
|
},
|
|
1046
1273
|
// === INTERNAL ===
|
|
1047
1274
|
async _hydrate() {
|
|
1048
|
-
await
|
|
1275
|
+
await a();
|
|
1049
1276
|
},
|
|
1050
1277
|
async _initialize() {
|
|
1051
|
-
await c.initialize(), await
|
|
1278
|
+
await c.initialize(), await a(), t({ filtersLoaded: !0 });
|
|
1052
1279
|
}
|
|
1053
1280
|
};
|
|
1054
1281
|
};
|
|
1055
1282
|
}
|
|
1056
|
-
function
|
|
1057
|
-
return (
|
|
1283
|
+
function Bt() {
|
|
1284
|
+
return (r) => (t) => r((e) => e.getUnitState(t));
|
|
1058
1285
|
}
|
|
1059
|
-
function
|
|
1286
|
+
function Ut(r) {
|
|
1060
1287
|
return {
|
|
1061
1288
|
property: {
|
|
1062
1289
|
unit: {
|
|
1063
1290
|
favorites: {
|
|
1064
|
-
toggle:
|
|
1291
|
+
toggle: r.toggleFavorite.bind(r)
|
|
1065
1292
|
},
|
|
1066
1293
|
viewed: {
|
|
1067
|
-
mark:
|
|
1294
|
+
mark: r.markUnitAsViewed.bind(r)
|
|
1068
1295
|
}
|
|
1069
1296
|
},
|
|
1070
1297
|
questionnaire: {
|
|
1071
|
-
setResults:
|
|
1298
|
+
setResults: r.setQuestionnaireResults.bind(r)
|
|
1072
1299
|
},
|
|
1073
1300
|
tour: {
|
|
1074
|
-
setContactedOn:
|
|
1075
|
-
getContactedOn:
|
|
1076
|
-
setContactData:
|
|
1301
|
+
setContactedOn: r.setTourContactedOn.bind(r),
|
|
1302
|
+
getContactedOn: r.getTourContactedOn.bind(r),
|
|
1303
|
+
setContactData: r.setTourContactData.bind(r)
|
|
1077
1304
|
}
|
|
1078
1305
|
},
|
|
1079
1306
|
filters: {
|
|
1080
|
-
set:
|
|
1081
|
-
setTemp:
|
|
1082
|
-
setToDefault:
|
|
1083
|
-
commitTemp:
|
|
1084
|
-
commitAvailability:
|
|
1085
|
-
submit:
|
|
1307
|
+
set: r.setFilters.bind(r),
|
|
1308
|
+
setTemp: r.setTempFilters.bind(r),
|
|
1309
|
+
setToDefault: r.setFiltersToDefault.bind(r),
|
|
1310
|
+
commitTemp: r.commitTempFilterChange.bind(r),
|
|
1311
|
+
commitAvailability: r.commitAvailabilityChange.bind(r),
|
|
1312
|
+
submit: r.submitFilterUpdate.bind(r)
|
|
1086
1313
|
}
|
|
1087
1314
|
};
|
|
1088
1315
|
}
|
|
1089
|
-
function
|
|
1316
|
+
function Lt(r) {
|
|
1090
1317
|
return (t, e) => {
|
|
1091
|
-
const
|
|
1318
|
+
const a = Ft(r)(t, e), s = Ut(a);
|
|
1092
1319
|
return {
|
|
1093
|
-
...
|
|
1320
|
+
...a,
|
|
1094
1321
|
...s
|
|
1095
1322
|
};
|
|
1096
1323
|
};
|
|
1097
1324
|
}
|
|
1098
|
-
const
|
|
1099
|
-
async isFavorite(
|
|
1100
|
-
return
|
|
1325
|
+
const zt = {
|
|
1326
|
+
async isFavorite(r, t) {
|
|
1327
|
+
return St(r, t);
|
|
1101
1328
|
},
|
|
1102
|
-
async toggle(
|
|
1103
|
-
return
|
|
1329
|
+
async toggle(r, t) {
|
|
1330
|
+
return mt(r, t);
|
|
1104
1331
|
},
|
|
1105
|
-
async set(
|
|
1106
|
-
return
|
|
1332
|
+
async set(r, t, e) {
|
|
1333
|
+
return tt(r, t, e);
|
|
1107
1334
|
},
|
|
1108
|
-
async getAll(
|
|
1109
|
-
return
|
|
1335
|
+
async getAll(r) {
|
|
1336
|
+
return Q(r);
|
|
1110
1337
|
}
|
|
1111
|
-
}
|
|
1338
|
+
}, rt = "https://web.inresiapp.com", at = "/placeholder.jpg", It = (r) => r ? r.startsWith("?") ? r : `?${r}` : "", Dt = (r, t, e = rt) => `${e}/${t}/unit/${r}/explore`, j = (r, t = at) => !(r != null && r.CFURL) || !(r != null && r.name) || !(r != null && r.signature) ? t : `${r.CFURL}${r.name}${It(r.signature)}`;
|
|
1339
|
+
function Qt(r) {
|
|
1340
|
+
return { data: r };
|
|
1341
|
+
}
|
|
1342
|
+
function Ht(r, t, e) {
|
|
1343
|
+
var o, l;
|
|
1344
|
+
const a = (e == null ? void 0 : e.origin) ?? rt, s = (e == null ? void 0 : e.placeholderImage) ?? at, i = ((o = r.hits) == null ? void 0 : o.map((u) => {
|
|
1345
|
+
var g, H;
|
|
1346
|
+
const d = u._source ?? {}, y = typeof d.name == "string" ? d.name : typeof d.title == "string" ? d.title : "";
|
|
1347
|
+
return {
|
|
1348
|
+
...d,
|
|
1349
|
+
title: y,
|
|
1350
|
+
slug: Dt(String(d.slug ?? ""), t, a),
|
|
1351
|
+
imageUrl: j(d.image, s),
|
|
1352
|
+
secondaryImageUrl: j((g = d.additionalImages) == null ? void 0 : g[0], s),
|
|
1353
|
+
tertiaryImageUrl: j((H = d.additionalImages) == null ? void 0 : H[1], s)
|
|
1354
|
+
};
|
|
1355
|
+
})) ?? [];
|
|
1356
|
+
return {
|
|
1357
|
+
total: ((l = r.total) == null ? void 0 : l.value) ?? i.length,
|
|
1358
|
+
maxScore: r.max_score ?? null,
|
|
1359
|
+
type: r.type ?? "units",
|
|
1360
|
+
hits: i
|
|
1361
|
+
};
|
|
1362
|
+
}
|
|
1363
|
+
const kt = {
|
|
1364
|
+
asap: "ASAP",
|
|
1365
|
+
next_month: "Next Month",
|
|
1366
|
+
"2_3_months": "2-3 Months",
|
|
1367
|
+
all: "Just Browsing"
|
|
1368
|
+
}, k = {
|
|
1369
|
+
0: "Studio",
|
|
1370
|
+
1: "1 Bed",
|
|
1371
|
+
2: "2 Bed",
|
|
1372
|
+
3: "3+ Bed"
|
|
1373
|
+
}, Rt = new Set(Object.values(k)), At = (r) => {
|
|
1374
|
+
if (!r || r.length === 0) return;
|
|
1375
|
+
const t = /* @__PURE__ */ new Set();
|
|
1376
|
+
for (const e of r) {
|
|
1377
|
+
if (typeof e == "number") {
|
|
1378
|
+
const s = k[e];
|
|
1379
|
+
s && t.add(s);
|
|
1380
|
+
continue;
|
|
1381
|
+
}
|
|
1382
|
+
const a = e.split(",").map((s) => s.trim());
|
|
1383
|
+
for (const s of a) {
|
|
1384
|
+
const i = Number.parseInt(s, 10);
|
|
1385
|
+
!Number.isNaN(i) && k[i] ? t.add(k[i]) : Rt.has(s) && t.add(s);
|
|
1386
|
+
}
|
|
1387
|
+
}
|
|
1388
|
+
return t.size > 0 ? Array.from(t) : void 0;
|
|
1389
|
+
}, qt = (r) => ({
|
|
1390
|
+
availability: r.availability && r.availability.length > 0 ? r.availability.map(
|
|
1391
|
+
(e) => kt[e] ?? e
|
|
1392
|
+
) : void 0,
|
|
1393
|
+
bedrooms: At(r.bedrooms),
|
|
1394
|
+
cost: r.cost ?? void 0,
|
|
1395
|
+
highlights: r.highlights ?? []
|
|
1396
|
+
});
|
|
1112
1397
|
export {
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1398
|
+
Mt as ApiUserSchema,
|
|
1399
|
+
Tt as AppStoreDataSchema,
|
|
1400
|
+
at as DEFAULT_PLACEHOLDER_IMAGE,
|
|
1401
|
+
rt as DEFAULT_WEB_ORIGIN,
|
|
1402
|
+
N as FavoritesSchema,
|
|
1403
|
+
A as FiltersSchema,
|
|
1404
|
+
st as OpenDBError,
|
|
1405
|
+
v as PropertySchema,
|
|
1406
|
+
vt as PropertyStore,
|
|
1407
|
+
O as PropertyStoreDataSchema,
|
|
1408
|
+
G as QueryParamsSchema,
|
|
1409
|
+
K as ResultsModeEnum,
|
|
1410
|
+
I as SCHEMA_VERSION,
|
|
1411
|
+
it as SchemaMismatchError,
|
|
1412
|
+
Z as SortByEnum,
|
|
1413
|
+
Pt as Store,
|
|
1414
|
+
dt as TourContactDataSchema,
|
|
1415
|
+
Pt as UnifiedStore,
|
|
1416
|
+
T as UnifiedStoreDataSchema,
|
|
1417
|
+
lt as UnitDataSchema,
|
|
1418
|
+
Et as UnitFavoriteSchema,
|
|
1419
|
+
b as UnitSchema,
|
|
1420
|
+
C as UserPropertyStateSchema,
|
|
1421
|
+
m as UserSchema,
|
|
1422
|
+
ot as UserUnitDataSchema,
|
|
1423
|
+
ct as ViewedUnitSchema,
|
|
1424
|
+
Dt as buildExploreUrl,
|
|
1425
|
+
j as buildImageUrl,
|
|
1426
|
+
pt as configureValidation,
|
|
1427
|
+
xt as createORMStringStorage,
|
|
1428
|
+
Lt as createStructuredStore,
|
|
1429
|
+
Ut as createStructuredStoreActions,
|
|
1430
|
+
Bt as createUseUnitState,
|
|
1431
|
+
Ft as createZustandPropertyStore,
|
|
1432
|
+
Ft as createZustandStore,
|
|
1433
|
+
Ft as createZustandUnifiedStore,
|
|
1434
|
+
wt as debugDump,
|
|
1435
|
+
ht as defaultIdGenerator,
|
|
1436
|
+
z as ensureUser,
|
|
1437
|
+
jt as exportJSON,
|
|
1438
|
+
zt as favorites,
|
|
1439
|
+
f as getDB,
|
|
1440
|
+
Q as getFavoritedUnitsForProperty,
|
|
1441
|
+
$t as getUserUUID,
|
|
1442
|
+
St as isUnitFavorited,
|
|
1443
|
+
W as kvGet,
|
|
1444
|
+
Nt as kvRemove,
|
|
1445
|
+
Y as kvSet,
|
|
1446
|
+
_t as propertyStore,
|
|
1447
|
+
Vt as resetDB,
|
|
1448
|
+
tt as setFavoriteUnit,
|
|
1151
1449
|
c as store,
|
|
1152
|
-
|
|
1450
|
+
mt as toggleFavoriteUnit,
|
|
1451
|
+
Qt as transformUnitsApiResponse,
|
|
1452
|
+
Ht as transformUnitsApiResponseToClient,
|
|
1453
|
+
qt as transformUnitsApiResponseToClientFilters
|
|
1153
1454
|
};
|
|
1154
1455
|
//# sourceMappingURL=index.mjs.map
|