@superbright/indexeddb-orm 1.0.32 → 1.0.34
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 +44 -359
- package/dist/adapters/dexie.cjs +1 -1
- package/dist/adapters/dexie.cjs.map +1 -1
- package/dist/adapters/dexie.d.ts +3 -4
- package/dist/adapters/dexie.mjs +6 -9
- package/dist/adapters/dexie.mjs.map +1 -1
- package/dist/adapters/zustand-store.cjs +1 -1
- package/dist/adapters/zustand-store.cjs.map +1 -1
- package/dist/adapters/zustand-store.d.ts +20 -41
- package/dist/adapters/zustand-store.mjs +34 -194
- package/dist/adapters/zustand-store.mjs.map +1 -1
- package/dist/base/index.d.ts +0 -1
- package/dist/base/visitorquestionnaire.d.ts +2 -2
- package/dist/db.cjs +1 -1
- package/dist/db.cjs.map +1 -1
- package/dist/db.mjs +57 -75
- package/dist/db.mjs.map +1 -1
- package/dist/features/analytics/AnalyticsProvider.cjs +1 -1
- package/dist/features/analytics/AnalyticsProvider.cjs.map +1 -1
- package/dist/features/analytics/AnalyticsProvider.d.ts +1 -0
- package/dist/features/analytics/AnalyticsProvider.mjs +63 -59
- package/dist/features/analytics/AnalyticsProvider.mjs.map +1 -1
- package/dist/features/analytics/analytics.cjs +1 -1
- package/dist/features/analytics/analytics.cjs.map +1 -1
- package/dist/features/analytics/analytics.d.ts +157 -157
- package/dist/features/analytics/analytics.mjs +190 -158
- package/dist/features/analytics/analytics.mjs.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +2 -3
- package/dist/index.mjs +92 -107
- package/dist/index.mjs.map +1 -1
- package/dist/schema.cjs +1 -1
- package/dist/schema.cjs.map +1 -1
- package/dist/schema.d.ts +1 -2088
- package/dist/schema.mjs +105 -161
- package/dist/schema.mjs.map +1 -1
- package/dist/stores/store.cjs +1 -1
- package/dist/stores/store.cjs.map +1 -1
- package/dist/stores/store.d.ts +7 -158
- package/dist/stores/store.mjs +13 -427
- package/dist/stores/store.mjs.map +1 -1
- package/dist/utils/casing.cjs +1 -1
- package/dist/utils/casing.cjs.map +1 -1
- package/dist/utils/casing.d.ts +0 -4
- package/dist/utils/casing.mjs +1 -4
- package/dist/utils/casing.mjs.map +1 -1
- package/dist/validation.cjs +1 -1
- package/dist/validation.cjs.map +1 -1
- package/dist/validation.d.ts +0 -2
- package/dist/validation.mjs +3 -14
- package/dist/validation.mjs.map +1 -1
- package/package.json +5 -1
- package/dist/adapters/structured-store.cjs +0 -2
- package/dist/adapters/structured-store.cjs.map +0 -1
- package/dist/adapters/structured-store.d.ts +0 -45
- package/dist/adapters/structured-store.mjs +0 -51
- package/dist/adapters/structured-store.mjs.map +0 -1
- package/dist/base/favoriteunit.cjs +0 -2
- package/dist/base/favoriteunit.cjs.map +0 -1
- package/dist/base/favoriteunit.d.ts +0 -14
- package/dist/base/favoriteunit.mjs +0 -10
- package/dist/base/favoriteunit.mjs.map +0 -1
package/dist/stores/store.mjs
CHANGED
|
@@ -1,436 +1,22 @@
|
|
|
1
|
-
import { kvGet as
|
|
2
|
-
|
|
3
|
-
import { validate as m } from "../validation.mjs";
|
|
4
|
-
import { transformFiltersToUnitsSearchParams as v } from "../features/filters/transformers.mjs";
|
|
5
|
-
const w = {
|
|
6
|
-
date_availability: void 0,
|
|
7
|
-
qty_bedrooms: void 0,
|
|
8
|
-
base_price: void 0,
|
|
9
|
-
highlights: void 0
|
|
10
|
-
}, S = {
|
|
11
|
-
// Property data
|
|
12
|
-
properties: {},
|
|
13
|
-
currentPropertyId: null,
|
|
14
|
-
currentPropertySlug: null,
|
|
15
|
-
hasPreviouslySearched: [],
|
|
16
|
-
// App data
|
|
17
|
-
unitResults: [],
|
|
18
|
-
filters: w,
|
|
19
|
-
tempFilters: w,
|
|
20
|
-
apiFilters: {
|
|
21
|
-
limit: 10,
|
|
22
|
-
page: 1,
|
|
23
|
-
sortBy: "relevance"
|
|
24
|
-
},
|
|
25
|
-
resultsMode: "all",
|
|
26
|
-
resolvedQuestionnaireValues: {},
|
|
27
|
-
sortBy: "relevance"
|
|
28
|
-
};
|
|
29
|
-
class g {
|
|
30
|
-
/**
|
|
31
|
-
* Resolves the persisted unified store snapshot, coercing legacy shapes into the latest schema
|
|
32
|
-
* and sanitizing invalid entries where possible.
|
|
33
|
-
*/
|
|
34
|
-
async getState() {
|
|
35
|
-
const t = await l("app");
|
|
36
|
-
if (!t)
|
|
37
|
-
return S;
|
|
38
|
-
const e = {
|
|
39
|
-
...S,
|
|
40
|
-
...t,
|
|
41
|
-
properties: t.properties ?? {},
|
|
42
|
-
unitResults: t.unitResults ?? [],
|
|
43
|
-
currentPropertyId: t.currentPropertyId == null ? null : String(t.currentPropertyId),
|
|
44
|
-
currentPropertySlug: t.currentPropertySlug ?? null,
|
|
45
|
-
hasPreviouslySearched: Array.isArray(t.hasPreviouslySearched) ? t.hasPreviouslySearched.map(String) : []
|
|
46
|
-
}, r = d.safeParse(e);
|
|
47
|
-
if (r.success) return r.data;
|
|
48
|
-
const s = Object.entries(e.properties ?? {}).reduce((o, [p, c]) => {
|
|
49
|
-
const f = P.safeParse(c);
|
|
50
|
-
return f.success && (o[p] = f.data), o;
|
|
51
|
-
}, {}), i = (Array.isArray(e.unitResults) ? e.unitResults : e.unitResults && typeof e.unitResults == "object" ? Object.values(e.unitResults) : []).reduce((o, p) => {
|
|
52
|
-
const c = h.safeParse(p);
|
|
53
|
-
return c.success && o.push(c.data), o;
|
|
54
|
-
}, []), a = {
|
|
55
|
-
...e,
|
|
56
|
-
properties: s,
|
|
57
|
-
unitResults: i
|
|
58
|
-
}, n = d.safeParse(a);
|
|
59
|
-
return n.success ? n.data : S;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Applies an updater function to the current store state, validates the result, and persists it.
|
|
63
|
-
*
|
|
64
|
-
* @param updater - Pure function that maps the current state to the next state.
|
|
65
|
-
*/
|
|
66
|
-
async setState(t) {
|
|
67
|
-
const e = await this.getState(), r = t(e), s = d.parse(r);
|
|
68
|
-
await y("app", s);
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Polls the persisted state until a current property pointer is available or the timeout elapses.
|
|
72
|
-
*
|
|
73
|
-
* @param timeoutMs - Maximum time in milliseconds to wait before failing.
|
|
74
|
-
* @returns The active property ID once it becomes available.
|
|
75
|
-
* @throws Error if the property pointer is not set before the timeout expires.
|
|
76
|
-
*/
|
|
77
|
-
async waitForCurrentProperty(t = 1e3) {
|
|
78
|
-
const e = Date.now() + t;
|
|
79
|
-
for (; Date.now() < e; ) {
|
|
80
|
-
const u = await this.getState(), i = u.currentPropertyId;
|
|
81
|
-
if (i && u.properties[i]) return i;
|
|
82
|
-
await new Promise((a) => setTimeout(a, 16));
|
|
83
|
-
}
|
|
84
|
-
const r = await this.getState(), s = r.currentPropertyId;
|
|
85
|
-
if (s && r.properties[s]) return s;
|
|
86
|
-
throw new Error("UnifiedStore: current property was not initialized in time");
|
|
87
|
-
}
|
|
88
|
-
// === PROPERTY OPERATIONS ===
|
|
89
|
-
/**
|
|
90
|
-
* Ensures a property entry exists and registers it as the current property.
|
|
91
|
-
*
|
|
92
|
-
* @param propertyId - Identifier used to track the property.
|
|
93
|
-
* @param slug - Canonical slug associated with the property.
|
|
94
|
-
*/
|
|
95
|
-
async initializeProperty(t, e) {
|
|
96
|
-
const r = String(t);
|
|
97
|
-
await this.setState((s) => s.properties && s.properties[r] ? {
|
|
98
|
-
...s,
|
|
99
|
-
currentPropertyId: r,
|
|
100
|
-
currentPropertySlug: e
|
|
101
|
-
} : {
|
|
102
|
-
...s,
|
|
103
|
-
currentPropertyId: r,
|
|
104
|
-
currentPropertySlug: e,
|
|
105
|
-
properties: {
|
|
106
|
-
...s.properties,
|
|
107
|
-
[r]: {
|
|
108
|
-
id: r,
|
|
109
|
-
slug: e,
|
|
110
|
-
favoritedUnits: [],
|
|
111
|
-
tourContactedOn: null,
|
|
112
|
-
viewedUnits: [],
|
|
113
|
-
questionnaireResults: null,
|
|
114
|
-
tourContactData: null
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
// === UNIT RESULTS CACHE ===
|
|
120
|
-
/**
|
|
121
|
-
* Persists a collection of units after validating each entry against the provided schema.
|
|
122
|
-
*
|
|
123
|
-
* @param units - Raw units collection returned by an API call.
|
|
124
|
-
* @param schema - Optional override schema when the default `UnitSchema` is not sufficient.
|
|
125
|
-
*/
|
|
126
|
-
async setUnitResults(t, e) {
|
|
127
|
-
const r = e ?? h, s = [];
|
|
128
|
-
(Array.isArray(t) ? t : t && typeof t == "object" ? Object.values(t) : []).forEach((i, a) => {
|
|
129
|
-
const n = m(r, i, `unitResults[${a}]`);
|
|
130
|
-
n && s.push(n);
|
|
131
|
-
}), await this.setState((i) => ({
|
|
132
|
-
...i,
|
|
133
|
-
unitResults: s
|
|
134
|
-
}));
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* Clears the cached unit results array.
|
|
138
|
-
*/
|
|
139
|
-
async clearUnitResults() {
|
|
140
|
-
await this.setState((t) => ({
|
|
141
|
-
...t,
|
|
142
|
-
unitResults: []
|
|
143
|
-
}));
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* Marks the provided property as current and optionally updates the slug.
|
|
147
|
-
*
|
|
148
|
-
* @param propertyId - Property identifier to focus.
|
|
149
|
-
* @param slug - Optional slug override.
|
|
150
|
-
*/
|
|
151
|
-
async setCurrentProperty(t, e) {
|
|
152
|
-
const r = String(t);
|
|
153
|
-
await this.setState((s) => ({
|
|
154
|
-
...s,
|
|
155
|
-
currentPropertyId: r,
|
|
156
|
-
currentPropertySlug: e || s.currentPropertySlug
|
|
157
|
-
}));
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* Updates the slug for the current property selection.
|
|
161
|
-
*
|
|
162
|
-
* @param slug - New slug to persist.
|
|
163
|
-
*/
|
|
164
|
-
async setCurrentPropertySlug(t) {
|
|
165
|
-
await this.setState((e) => ({
|
|
166
|
-
...e,
|
|
167
|
-
currentPropertySlug: t
|
|
168
|
-
}));
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* Adds a slug to the `hasPreviouslySearched` list without duplicating existing entries.
|
|
172
|
-
*
|
|
173
|
-
* @param slug - Slug to record.
|
|
174
|
-
*/
|
|
175
|
-
async setHasPreviouslySearched(t) {
|
|
176
|
-
await this.setState((e) => ({
|
|
177
|
-
...e,
|
|
178
|
-
hasPreviouslySearched: Array.from(
|
|
179
|
-
/* @__PURE__ */ new Set([...e.hasPreviouslySearched, t])
|
|
180
|
-
)
|
|
181
|
-
}));
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
184
|
-
* Records the most recent view date for a unit and opens the unit URL in the browser when available.
|
|
185
|
-
*
|
|
186
|
-
* @param unitId - Identifier of the viewed unit.
|
|
187
|
-
* @param slug - Property slug used to construct the URL.
|
|
188
|
-
*/
|
|
189
|
-
async markUnitAsViewed(t, e) {
|
|
190
|
-
const r = `https://${e}`;
|
|
191
|
-
window.open(r, "_blank", "noopener,noreferrer");
|
|
192
|
-
const s = /* @__PURE__ */ new Date(), u = `${String(s.getMonth() + 1).padStart(
|
|
193
|
-
2,
|
|
194
|
-
"0"
|
|
195
|
-
)}/${String(s.getDate()).padStart(2, "0")}`;
|
|
196
|
-
await this.setState((i) => {
|
|
197
|
-
const a = i.currentPropertyId;
|
|
198
|
-
if (!a) return i;
|
|
199
|
-
const n = i.properties[a];
|
|
200
|
-
if (!n) return i;
|
|
201
|
-
const o = [
|
|
202
|
-
...n.viewedUnits.filter((p) => p.unitId !== t),
|
|
203
|
-
{ unitId: t, viewedDate: u }
|
|
204
|
-
];
|
|
205
|
-
return {
|
|
206
|
-
...i,
|
|
207
|
-
properties: {
|
|
208
|
-
...i.properties,
|
|
209
|
-
[a]: {
|
|
210
|
-
...n,
|
|
211
|
-
viewedUnits: o
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
};
|
|
215
|
-
});
|
|
216
|
-
}
|
|
217
|
-
/**
|
|
218
|
-
* Stamps the current property with the moment the tour outreach occurred.
|
|
219
|
-
*/
|
|
220
|
-
async setTourContactedOn() {
|
|
221
|
-
await this.setState((t) => {
|
|
222
|
-
const e = t.currentPropertyId;
|
|
223
|
-
if (!e) return t;
|
|
224
|
-
const r = t.properties[e];
|
|
225
|
-
return r ? {
|
|
226
|
-
...t,
|
|
227
|
-
properties: {
|
|
228
|
-
...t.properties,
|
|
229
|
-
[e]: {
|
|
230
|
-
...r,
|
|
231
|
-
tourContactedOn: (/* @__PURE__ */ new Date()).toISOString()
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
} : t;
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
/**
|
|
238
|
-
* Reads the stored tour contact timestamp for the current property.
|
|
239
|
-
*
|
|
240
|
-
* @returns ISO string or null when no timestamp exists.
|
|
241
|
-
*/
|
|
242
|
-
async getTourContactedOn() {
|
|
243
|
-
var r;
|
|
244
|
-
const t = await this.getState(), e = t.currentPropertyId;
|
|
245
|
-
return e ? ((r = t.properties[e]) == null ? void 0 : r.tourContactedOn) ?? null : null;
|
|
246
|
-
}
|
|
247
|
-
/**
|
|
248
|
-
* Persists questionnaire results captured for the current property.
|
|
249
|
-
*
|
|
250
|
-
* @param results - Arbitrary questionnaire data.
|
|
251
|
-
*/
|
|
252
|
-
async setQuestionnaireResults(t) {
|
|
253
|
-
await this.setState((e) => {
|
|
254
|
-
const r = e.currentPropertyId;
|
|
255
|
-
if (!r) return e;
|
|
256
|
-
const s = e.properties[r];
|
|
257
|
-
return s ? {
|
|
258
|
-
...e,
|
|
259
|
-
properties: {
|
|
260
|
-
...e.properties,
|
|
261
|
-
[r]: {
|
|
262
|
-
...s,
|
|
263
|
-
questionnaireResults: t
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
} : e;
|
|
267
|
-
});
|
|
268
|
-
}
|
|
269
|
-
/**
|
|
270
|
-
* Persists structured tour contact preferences for the active property. The method waits until
|
|
271
|
-
* a current property is available, allowing callers to invoke it before initialization completes.
|
|
272
|
-
*
|
|
273
|
-
* @param data - Contact preferences captured from the UI.
|
|
274
|
-
*/
|
|
275
|
-
async setTourContactData(t) {
|
|
276
|
-
const e = await this.waitForCurrentProperty();
|
|
277
|
-
await this.setState((r) => {
|
|
278
|
-
const s = r.properties[e];
|
|
279
|
-
return s ? {
|
|
280
|
-
...r,
|
|
281
|
-
properties: {
|
|
282
|
-
...r.properties,
|
|
283
|
-
[e]: {
|
|
284
|
-
...s,
|
|
285
|
-
tourContactData: t
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
} : r;
|
|
289
|
-
});
|
|
290
|
-
}
|
|
291
|
-
// === FILTER OPERATIONS ===
|
|
292
|
-
/**
|
|
293
|
-
* Merges the provided filter values into the committed filter state.
|
|
294
|
-
*
|
|
295
|
-
* @param filters - Partial filter payload to apply.
|
|
296
|
-
*/
|
|
297
|
-
async setFilters(t) {
|
|
298
|
-
await this.setState((e) => ({
|
|
299
|
-
...e,
|
|
300
|
-
filters: { ...e.filters, ...t }
|
|
301
|
-
}));
|
|
302
|
-
}
|
|
303
|
-
/**
|
|
304
|
-
* Updates the transient filters used for in-progress UI interactions.
|
|
305
|
-
*
|
|
306
|
-
* @param filters - Partial staging filter payload.
|
|
307
|
-
*/
|
|
308
|
-
async setTempFilters(t) {
|
|
309
|
-
await this.setState((e) => ({
|
|
310
|
-
...e,
|
|
311
|
-
tempFilters: { ...e.tempFilters, ...t }
|
|
312
|
-
}));
|
|
313
|
-
}
|
|
314
|
-
/**
|
|
315
|
-
* Resets the committed filters to their default values.
|
|
316
|
-
*/
|
|
317
|
-
async setFiltersToDefault() {
|
|
318
|
-
await this.setState((t) => ({ ...t, filters: w }));
|
|
319
|
-
}
|
|
320
|
-
/**
|
|
321
|
-
* Merges partial values into the API filters payload used for network requests.
|
|
322
|
-
*
|
|
323
|
-
* @param filters - Partial query parameters to persist.
|
|
324
|
-
*/
|
|
325
|
-
async setApiFilters(t) {
|
|
326
|
-
await this.setState((e) => ({
|
|
327
|
-
...e,
|
|
328
|
-
apiFilters: { ...e.apiFilters, ...t }
|
|
329
|
-
}));
|
|
330
|
-
}
|
|
331
|
-
/**
|
|
332
|
-
* Updates a single temporary filter field without touching the rest of the staged filters.
|
|
333
|
-
*
|
|
334
|
-
* @param key - Filter key to mutate.
|
|
335
|
-
* @param value - New value to assign.
|
|
336
|
-
*/
|
|
337
|
-
async handleTempFilterChange(t, e) {
|
|
338
|
-
await this.setState((r) => ({
|
|
339
|
-
...r,
|
|
340
|
-
tempFilters: { ...r.tempFilters, [t]: e }
|
|
341
|
-
}));
|
|
342
|
-
}
|
|
343
|
-
/**
|
|
344
|
-
* Normalizes the committed filters into API-ready structures and persists the result.
|
|
345
|
-
*/
|
|
346
|
-
async submitFilterUpdate() {
|
|
347
|
-
await this.setState((t) => {
|
|
348
|
-
const e = v(
|
|
349
|
-
{
|
|
350
|
-
...t.filters,
|
|
351
|
-
limit: t.apiFilters.limit,
|
|
352
|
-
page: t.apiFilters.page,
|
|
353
|
-
sortBy: t.sortBy
|
|
354
|
-
},
|
|
355
|
-
{
|
|
356
|
-
defaultLimit: t.apiFilters.limit,
|
|
357
|
-
defaultPage: t.apiFilters.page,
|
|
358
|
-
defaultSort: t.sortBy
|
|
359
|
-
}
|
|
360
|
-
);
|
|
361
|
-
return {
|
|
362
|
-
...t,
|
|
363
|
-
apiFilters: e
|
|
364
|
-
};
|
|
365
|
-
});
|
|
366
|
-
}
|
|
367
|
-
// === RESULTS AND SORTING ===
|
|
368
|
-
/**
|
|
369
|
-
* Persists the selected results mode (e.g. "all" or "favorites").
|
|
370
|
-
*
|
|
371
|
-
* @param mode - Mode identifier to store.
|
|
372
|
-
*/
|
|
373
|
-
async setResultsMode(t) {
|
|
374
|
-
await this.setState((e) => ({ ...e, resultsMode: t }));
|
|
375
|
-
}
|
|
376
|
-
/**
|
|
377
|
-
* Persists the currently selected sort option.
|
|
378
|
-
*
|
|
379
|
-
* @param sortBy - Sort identifier.
|
|
380
|
-
*/
|
|
381
|
-
async setSortBy(t) {
|
|
382
|
-
await this.setState((e) => ({ ...e, sortBy: t }));
|
|
383
|
-
}
|
|
384
|
-
// === QUESTIONNAIRE ===
|
|
385
|
-
/**
|
|
386
|
-
* Stores resolved questionnaire answers keyed by questionnaire name.
|
|
387
|
-
*
|
|
388
|
-
* @param name - Questionnaire identifier.
|
|
389
|
-
* @param values - Selected option values.
|
|
390
|
-
*/
|
|
391
|
-
async setResolvedQuestionnaireValues(t, e) {
|
|
392
|
-
await this.setState((r) => ({
|
|
393
|
-
...r,
|
|
394
|
-
resolvedQuestionnaireValues: {
|
|
395
|
-
...r.resolvedQuestionnaireValues,
|
|
396
|
-
[t]: e
|
|
397
|
-
}
|
|
398
|
-
}));
|
|
399
|
-
}
|
|
400
|
-
// === VISITOR UUID ===
|
|
401
|
-
/**
|
|
402
|
-
* Reads the persisted visitor UUID from the KV store.
|
|
403
|
-
*
|
|
404
|
-
* @returns The visitor UUID string or null when not yet set.
|
|
405
|
-
*/
|
|
1
|
+
import { kvGet as s, kvSet as e } from "../storage.mjs";
|
|
2
|
+
class o {
|
|
406
3
|
async getVisitorUUID() {
|
|
407
|
-
const
|
|
408
|
-
return (
|
|
4
|
+
const r = await s("user");
|
|
5
|
+
return (r == null ? void 0 : r.visitor_uuid) ?? null;
|
|
409
6
|
}
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
* @param vid - Visitor UUID string returned by the session API.
|
|
414
|
-
*/
|
|
415
|
-
async setVisitorUUID(t) {
|
|
416
|
-
const e = await l("user"), r = e !== null && typeof e == "object" && !Array.isArray(e) ? e : {};
|
|
417
|
-
await y("user", { ...r, visitor_uuid: t });
|
|
7
|
+
async setVisitorUUID(r) {
|
|
8
|
+
const t = await s("user"), i = t !== null && typeof t == "object" && !Array.isArray(t) ? t : {};
|
|
9
|
+
await e("user", { ...i, visitor_uuid: r });
|
|
418
10
|
}
|
|
419
|
-
/**
|
|
420
|
-
* Removes the visitor UUID from the KV store.
|
|
421
|
-
* Use when the stored UUID is stale (e.g. bootstrap returns 404).
|
|
422
|
-
*/
|
|
423
11
|
async clearVisitorUUID() {
|
|
424
|
-
const
|
|
425
|
-
if (
|
|
426
|
-
const { visitor_uuid:
|
|
427
|
-
await
|
|
12
|
+
const r = await s("user");
|
|
13
|
+
if (r === null || typeof r != "object" || Array.isArray(r)) return;
|
|
14
|
+
const { visitor_uuid: t, ...i } = r;
|
|
15
|
+
await e("user", i);
|
|
428
16
|
}
|
|
429
17
|
}
|
|
430
|
-
const
|
|
18
|
+
const u = new o();
|
|
431
19
|
export {
|
|
432
|
-
|
|
433
|
-
g as UnifiedStore,
|
|
434
|
-
b as store
|
|
20
|
+
u as inResiOrmStore
|
|
435
21
|
};
|
|
436
22
|
//# sourceMappingURL=store.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store.mjs","sources":["../../src/stores/store.ts"],"sourcesContent":["import { kvGet, kvSet } from \"../storage\";\nimport type { ZodType, ZodTypeAny } from \"zod\";\nimport {\n UnifiedStoreDataSchema,\n UserPropertyStateSchema,\n type UnifiedStoreData,\n type UserPropertyState,\n type Filters,\n type QueryParams,\n type ResultsMode,\n type SortBy,\n type TourContactData,\n type Unit,\n UnitSchema,\n} from \"../schema\";\nimport { validate } from \"../validation\";\nimport { transformFiltersToUnitsSearchParams } from \"../features/filters/transformers\";\n\n// Default values\nconst defaultFilters: Filters = {\n date_availability: undefined,\n qty_bedrooms: undefined,\n base_price: undefined,\n highlights: undefined,\n};\n\nconst defaultUnifiedStoreData: UnifiedStoreData = {\n // Property data\n properties: {},\n currentPropertyId: null,\n currentPropertySlug: null,\n hasPreviouslySearched: [],\n\n // App data\n unitResults: [],\n filters: defaultFilters,\n tempFilters: defaultFilters,\n apiFilters: {\n limit: 10,\n page: 1,\n sortBy: \"relevance\",\n },\n resultsMode: \"all\",\n resolvedQuestionnaireValues: {},\n sortBy: \"relevance\",\n};\n\nconst toArray = (input: unknown): unknown[] => {\n if (input == null) return [];\n return Array.isArray(input) ? input : [input];\n};\n\nconst extractFilterValues = (value: unknown): unknown[] => {\n return toArray(value).flatMap(item => {\n if (item == null) return [];\n if (Array.isArray(item)) return item;\n if (typeof item === \"object\" && \"value\" in (item as any)) {\n const v = (item as any).value;\n return Array.isArray(v) ? v : v != null ? [v] : [];\n }\n return [item];\n });\n};\n\nconst toStringArray = (value: unknown): string[] =>\n extractFilterValues(value)\n .flatMap(v => (Array.isArray(v) ? v : [v]))\n .map(v => String(v))\n .map(v => v.trim())\n .filter(v => v.length > 0);\n\nconst toNumberArray = (value: unknown): number[] =>\n extractFilterValues(value)\n .map(v => {\n if (typeof v === \"number\" && Number.isFinite(v)) return v;\n const num = Number(v);\n return Number.isFinite(num) ? num : null;\n })\n .filter((v): v is number => v !== null);\n\nconst toNumberValue = (value: unknown): number | null => {\n if (value == null) return null;\n if (typeof value === \"number\") return Number.isFinite(value) ? value : null;\n if (typeof value === \"object\" && \"value\" in (value as any)) {\n return toNumberValue((value as any).value);\n }\n const num = Number(value);\n return Number.isFinite(num) ? num : null;\n};\n\n// Unified store class\nexport class UnifiedStore {\n /**\n * Resolves the persisted unified store snapshot, coercing legacy shapes into the latest schema\n * and sanitizing invalid entries where possible.\n */\n private async getState(): Promise<UnifiedStoreData> {\n const state = await kvGet<UnifiedStoreData>(\"app\");\n if (!state) {\n return defaultUnifiedStoreData;\n }\n\n const merged = {\n ...defaultUnifiedStoreData,\n ...state,\n properties: state.properties ?? {},\n unitResults: state.unitResults ?? [],\n currentPropertyId:\n state.currentPropertyId == null ? null : String(state.currentPropertyId),\n currentPropertySlug: state.currentPropertySlug ?? null,\n hasPreviouslySearched: Array.isArray(state.hasPreviouslySearched)\n ? state.hasPreviouslySearched.map(String)\n : [],\n };\n\n const parsed = UnifiedStoreDataSchema.safeParse(merged);\n if (parsed.success) return parsed.data;\n\n // Sanitize by dropping invalid property entries and unit results\n const sanitizedProperties = Object.entries(merged.properties ?? {}).reduce<\n Record<string, UserPropertyState>\n >((acc, [key, value]) => {\n const entry = UserPropertyStateSchema.safeParse(value);\n if (entry.success) acc[key] = entry.data;\n return acc;\n }, {});\n\n const rawUnitResults = Array.isArray(merged.unitResults)\n ? merged.unitResults\n : merged.unitResults && typeof merged.unitResults === \"object\"\n ? Object.values(merged.unitResults as Record<string, unknown>)\n : [];\n\n const sanitizedUnitResults = rawUnitResults.reduce<Unit[]>((acc, value) => {\n const entry = UnitSchema.safeParse(value);\n if (entry.success) acc.push(entry.data);\n return acc;\n }, []);\n\n const fallback = {\n ...merged,\n properties: sanitizedProperties,\n unitResults: sanitizedUnitResults,\n };\n\n const fallbackParsed = UnifiedStoreDataSchema.safeParse(fallback);\n return fallbackParsed.success ? fallbackParsed.data : defaultUnifiedStoreData;\n }\n\n /**\n * Applies an updater function to the current store state, validates the result, and persists it.\n *\n * @param updater - Pure function that maps the current state to the next state.\n */\n private async setState(updater: (state: UnifiedStoreData) => UnifiedStoreData): Promise<void> {\n const currentState = await this.getState();\n const newState = updater(currentState);\n const validatedState = UnifiedStoreDataSchema.parse(newState);\n await kvSet(\"app\", validatedState);\n }\n\n /**\n * Polls the persisted state until a current property pointer is available or the timeout elapses.\n *\n * @param timeoutMs - Maximum time in milliseconds to wait before failing.\n * @returns The active property ID once it becomes available.\n * @throws Error if the property pointer is not set before the timeout expires.\n */\n private async waitForCurrentProperty(timeoutMs = 1000): Promise<string> {\n const deadline = Date.now() + timeoutMs;\n\n while (Date.now() < deadline) {\n const state = await this.getState();\n const propertyId = state.currentPropertyId;\n if (propertyId && state.properties[propertyId]) return propertyId;\n\n await new Promise(resolve => setTimeout(resolve, 16));\n }\n\n const finalState = await this.getState();\n const propertyId = finalState.currentPropertyId;\n if (propertyId && finalState.properties[propertyId]) return propertyId;\n\n throw new Error(\"UnifiedStore: current property was not initialized in time\");\n }\n\n // === PROPERTY OPERATIONS ===\n\n /**\n * Ensures a property entry exists and registers it as the current property.\n *\n * @param propertyId - Identifier used to track the property.\n * @param slug - Canonical slug associated with the property.\n */\n async initializeProperty(propertyId: string | number, slug: string): Promise<void> {\n const id = String(propertyId);\n await this.setState(state => {\n if (state.properties && state.properties[id]) {\n return {\n ...state,\n currentPropertyId: id,\n currentPropertySlug: slug\n };\n }\n\n return {\n ...state,\n currentPropertyId: id,\n currentPropertySlug: slug,\n properties: {\n ...state.properties,\n [id]: {\n id,\n slug,\n favoritedUnits: [],\n tourContactedOn: null,\n viewedUnits: [],\n questionnaireResults: null,\n tourContactData: null,\n },\n },\n };\n });\n }\n\n // === UNIT RESULTS CACHE ===\n /**\n * Persists a collection of units after validating each entry against the provided schema.\n *\n * @param units - Raw units collection returned by an API call.\n * @param schema - Optional override schema when the default `UnitSchema` is not sufficient.\n */\n async setUnitResults(\n units: unknown,\n schema?: ZodTypeAny,\n ): Promise<void> {\n const baseSchema = (schema ?? UnitSchema) as ZodType<Unit>;\n const validatedUnits: Unit[] = [];\n const collection = Array.isArray(units)\n ? units\n : units && typeof units === \"object\"\n ? Object.values(units as Record<string, unknown>)\n : [];\n\n collection.forEach((unit, index) => {\n const parsed = validate(baseSchema, unit, `unitResults[${index}]`);\n if (parsed) validatedUnits.push(parsed);\n });\n await this.setState(state => ({\n ...state,\n unitResults: validatedUnits,\n }));\n }\n\n /**\n * Clears the cached unit results array.\n */\n async clearUnitResults(): Promise<void> {\n await this.setState(state => ({\n ...state,\n unitResults: [],\n }));\n }\n\n /**\n * Marks the provided property as current and optionally updates the slug.\n *\n * @param propertyId - Property identifier to focus.\n * @param slug - Optional slug override.\n */\n async setCurrentProperty(propertyId: string | number, slug?: string): Promise<void> {\n const id = String(propertyId);\n await this.setState(state => ({\n ...state,\n currentPropertyId: id,\n currentPropertySlug: slug || state.currentPropertySlug,\n }));\n }\n\n /**\n * Updates the slug for the current property selection.\n *\n * @param slug - New slug to persist.\n */\n async setCurrentPropertySlug(slug: string): Promise<void> {\n await this.setState(state => ({\n ...state,\n currentPropertySlug: slug\n }));\n }\n\n /**\n * Adds a slug to the `hasPreviouslySearched` list without duplicating existing entries.\n *\n * @param slug - Slug to record.\n */\n async setHasPreviouslySearched(slug: string): Promise<void> {\n await this.setState(state => ({\n ...state,\n hasPreviouslySearched: Array.from(\n new Set([...state.hasPreviouslySearched, slug])\n ),\n }));\n }\n\n /**\n * Records the most recent view date for a unit and opens the unit URL in the browser when available.\n *\n * @param unitId - Identifier of the viewed unit.\n * @param slug - Property slug used to construct the URL.\n */\n async markUnitAsViewed(unitId: string, slug: string): Promise<void> {\n\n const url = `https://${slug}`;\n window.open(url, \"_blank\", \"noopener,noreferrer\");\n\n const today = new Date();\n const formattedDate = `${String(today.getMonth() + 1).padStart(\n 2,\n \"0\"\n )}/${String(today.getDate()).padStart(2, \"0\")}`;\n\n await this.setState(state => {\n const propertyId = state.currentPropertyId;\n if (!propertyId) return state;\n\n const property = state.properties[propertyId];\n if (!property) return state;\n\n const updatedViewedUnits = [\n ...property.viewedUnits.filter((u) => u.unitId !== unitId),\n { unitId, viewedDate: formattedDate },\n ];\n\n return {\n ...state,\n properties: {\n ...state.properties,\n [propertyId]: {\n ...property,\n viewedUnits: updatedViewedUnits,\n },\n },\n };\n });\n\n\n }\n\n /**\n * Stamps the current property with the moment the tour outreach occurred.\n */\n async setTourContactedOn(): Promise<void> {\n await this.setState(state => {\n const propertyId = state.currentPropertyId;\n if (!propertyId) return state;\n\n const property = state.properties[propertyId];\n if (!property) return state;\n\n return {\n ...state,\n properties: {\n ...state.properties,\n [propertyId]: {\n ...property,\n tourContactedOn: new Date().toISOString(),\n },\n },\n };\n });\n }\n\n /**\n * Reads the stored tour contact timestamp for the current property.\n *\n * @returns ISO string or null when no timestamp exists.\n */\n async getTourContactedOn(): Promise<string | null> {\n const state = await this.getState();\n const propertyId = state.currentPropertyId;\n if (!propertyId) return null;\n\n return state.properties[propertyId]?.tourContactedOn ?? null;\n }\n\n /**\n * Persists questionnaire results captured for the current property.\n *\n * @param results - Arbitrary questionnaire data.\n */\n async setQuestionnaireResults(results: unknown): Promise<void> {\n await this.setState(state => {\n const propertyId = state.currentPropertyId;\n if (!propertyId) return state;\n\n const property = state.properties[propertyId];\n if (!property) return state;\n\n return {\n ...state,\n properties: {\n ...state.properties,\n [propertyId]: {\n ...property,\n questionnaireResults: results,\n },\n },\n };\n });\n }\n\n /**\n * Persists structured tour contact preferences for the active property. The method waits until\n * a current property is available, allowing callers to invoke it before initialization completes.\n *\n * @param data - Contact preferences captured from the UI.\n */\n async setTourContactData(data: TourContactData): Promise<void> {\n const propertyId = await this.waitForCurrentProperty();\n\n await this.setState(state => {\n const property = state.properties[propertyId];\n if (!property) return state;\n\n return {\n ...state,\n properties: {\n ...state.properties,\n [propertyId]: {\n ...property,\n tourContactData: data,\n },\n },\n };\n });\n }\n\n\n\n\n\n\n\n // === FILTER OPERATIONS ===\n\n /**\n * Merges the provided filter values into the committed filter state.\n *\n * @param filters - Partial filter payload to apply.\n */\n async setFilters(filters: Partial<Filters>): Promise<void> {\n await this.setState(state => ({\n ...state,\n filters: { ...state.filters, ...filters }\n }));\n }\n\n /**\n * Updates the transient filters used for in-progress UI interactions.\n *\n * @param filters - Partial staging filter payload.\n */\n async setTempFilters(filters: Partial<Filters>): Promise<void> {\n await this.setState(state => ({\n ...state,\n tempFilters: { ...state.tempFilters, ...filters }\n }));\n }\n\n /**\n * Resets the committed filters to their default values.\n */\n async setFiltersToDefault(): Promise<void> {\n await this.setState(state => ({ ...state, filters: defaultFilters }));\n }\n\n /**\n * Merges partial values into the API filters payload used for network requests.\n *\n * @param filters - Partial query parameters to persist.\n */\n async setApiFilters(filters: Partial<QueryParams>): Promise<void> {\n await this.setState(state => ({\n ...state,\n apiFilters: { ...state.apiFilters, ...filters }\n }));\n }\n\n /**\n * Updates a single temporary filter field without touching the rest of the staged filters.\n *\n * @param key - Filter key to mutate.\n * @param value - New value to assign.\n */\n async handleTempFilterChange<K extends keyof Filters>(\n key: K,\n value: Filters[K]\n ): Promise<void> {\n await this.setState(state => ({\n ...state,\n tempFilters: { ...state.tempFilters, [key]: value }\n }));\n }\n\n /**\n * Normalizes the committed filters into API-ready structures and persists the result.\n */\n async submitFilterUpdate(): Promise<void> {\n await this.setState(state => {\n const apiParams: QueryParams = transformFiltersToUnitsSearchParams(\n {\n ...state.filters,\n limit: state.apiFilters.limit,\n page: state.apiFilters.page,\n sortBy: state.sortBy,\n },\n {\n defaultLimit: state.apiFilters.limit,\n defaultPage: state.apiFilters.page,\n defaultSort: state.sortBy,\n },\n );\n\n return {\n ...state,\n apiFilters: apiParams,\n };\n });\n }\n\n // === RESULTS AND SORTING ===\n\n /**\n * Persists the selected results mode (e.g. \"all\" or \"favorites\").\n *\n * @param mode - Mode identifier to store.\n */\n async setResultsMode(mode: ResultsMode): Promise<void> {\n await this.setState(state => ({ ...state, resultsMode: mode }));\n }\n\n /**\n * Persists the currently selected sort option.\n *\n * @param sortBy - Sort identifier.\n */\n async setSortBy(sortBy: SortBy): Promise<void> {\n await this.setState(state => ({ ...state, sortBy }));\n }\n\n // === QUESTIONNAIRE ===\n\n /**\n * Stores resolved questionnaire answers keyed by questionnaire name.\n *\n * @param name - Questionnaire identifier.\n * @param values - Selected option values.\n */\n async setResolvedQuestionnaireValues(name: string, values: string[]): Promise<void> {\n await this.setState(state => ({\n ...state,\n resolvedQuestionnaireValues: {\n ...state.resolvedQuestionnaireValues,\n [name]: values\n }\n }));\n }\n\n // === VISITOR UUID ===\n\n /**\n * Reads the persisted visitor UUID from the KV store.\n *\n * @returns The visitor UUID string or null when not yet set.\n */\n async getVisitorUUID(): Promise<string | null> {\n const user = await kvGet<{ visitor_uuid?: string }>(\"user\");\n return user?.visitor_uuid ?? null;\n }\n\n /**\n * Persists a visitor UUID to the KV store.\n *\n * @param vid - Visitor UUID string returned by the session API.\n */\n async setVisitorUUID(vid: string): Promise<void> {\n const current = await kvGet<Record<string, unknown>>(\"user\");\n const safe = current !== null && typeof current === \"object\" && !Array.isArray(current) ? current : {};\n await kvSet(\"user\", { ...safe, visitor_uuid: vid });\n }\n\n /**\n * Removes the visitor UUID from the KV store.\n * Use when the stored UUID is stale (e.g. bootstrap returns 404).\n */\n async clearVisitorUUID(): Promise<void> {\n const current = await kvGet<Record<string, unknown>>(\"user\");\n if (current === null || typeof current !== \"object\" || Array.isArray(current)) return;\n const { visitor_uuid: _, ...rest } = current;\n await kvSet(\"user\", rest);\n }\n\n}\n\n// Export singleton instance\nexport const store = new UnifiedStore();\n// Alias to prefer neutral naming going forward\nexport { UnifiedStore as Store };\n// Re-export types for convenience (tests import from this module)\nexport type { UserPropertyState, Filters } from \"../schema\";\n"],"names":["defaultFilters","defaultUnifiedStoreData","UnifiedStore","state","kvGet","merged","parsed","UnifiedStoreDataSchema","sanitizedProperties","acc","key","value","entry","UserPropertyStateSchema","sanitizedUnitResults","UnitSchema","fallback","fallbackParsed","updater","currentState","newState","validatedState","kvSet","timeoutMs","deadline","propertyId","resolve","finalState","slug","id","units","schema","baseSchema","validatedUnits","unit","index","validate","unitId","url","today","formattedDate","property","updatedViewedUnits","u","_a","results","data","filters","apiParams","transformFiltersToUnitsSearchParams","mode","sortBy","name","values","user","vid","current","safe","_","rest","store"],"mappings":";;;;AAmBA,MAAMA,IAA0B;AAAA,EAC9B,mBAAmB;AAAA,EACnB,cAAc;AAAA,EACd,YAAY;AAAA,EACZ,YAAY;AACd,GAEMC,IAA4C;AAAA;AAAA,EAEhD,YAAY,CAAA;AAAA,EACZ,mBAAmB;AAAA,EACnB,qBAAqB;AAAA,EACrB,uBAAuB,CAAA;AAAA;AAAA,EAGvB,aAAa,CAAA;AAAA,EACb,SAASD;AAAA,EACT,aAAaA;AAAA,EACb,YAAY;AAAA,IACV,OAAO;AAAA,IACP,MAAM;AAAA,IACN,QAAQ;AAAA,EAAA;AAAA,EAEV,aAAa;AAAA,EACb,6BAA6B,CAAA;AAAA,EAC7B,QAAQ;AACV;AA8CO,MAAME,EAAa;AAAA;AAAA;AAAA;AAAA;AAAA,EAKxB,MAAc,WAAsC;AAClD,UAAM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AA;AACpG,UAAMlC,EAAM,QAAQ,EAAE,GAAGmC,GAAM,cAAcF,GAAK;AAAA,EACpD;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,mBAAkC;AACtC,UAAMC,IAAU,MAAMpD,EAA+B,MAAM;AAC3D,QAAIoD,MAAY,QAAQ,OAAOA,KAAY,YAAY,MAAM,QAAQA,CAAO,EAAG;AAC/E,UAAM,EAAE,cAAcE,GAAG,GAAGC,MAASH;AACrC,UAAMlC,EAAM,QAAQqC,CAAI;AAAA,EAC1B;AAEF;AAGO,MAAMC,IAAQ,IAAI1D,EAAA;"}
|
|
1
|
+
{"version":3,"file":"store.mjs","sources":["../../src/stores/store.ts"],"sourcesContent":["import { kvGet, kvSet } from \"../storage\";\n\n/**\n * Persists the visitor UUID to the KV store.\n * All other state (filters, properties, units) is managed in-memory by the Zustand adapter.\n */\nclass UnifiedStore {\n async getVisitorUUID(): Promise<string | null> {\n const user = await kvGet<{ visitor_uuid?: string }>(\"user\");\n return user?.visitor_uuid ?? null;\n }\n\n async setVisitorUUID(vid: string): Promise<void> {\n const current = await kvGet<Record<string, unknown>>(\"user\");\n const safe = current !== null && typeof current === \"object\" && !Array.isArray(current) ? current : {};\n await kvSet(\"user\", { ...safe, visitor_uuid: vid });\n }\n\n async clearVisitorUUID(): Promise<void> {\n const current = await kvGet<Record<string, unknown>>(\"user\");\n if (current === null || typeof current !== \"object\" || Array.isArray(current)) return;\n const { visitor_uuid: _, ...rest } = current;\n await kvSet(\"user\", rest);\n }\n}\n\nexport const inResiOrmStore = new UnifiedStore();\n"],"names":["UnifiedStore","user","kvGet","vid","current","safe","kvSet","_","rest","inResiOrmStore"],"mappings":";AAMA,MAAMA,EAAa;AAAA,EACjB,MAAM,iBAAyC;AAC7C,UAAMC,IAAO,MAAMC,EAAiC,MAAM;AAC1D,YAAOD,KAAA,gBAAAA,EAAM,iBAAgB;AAAA,EAC/B;AAAA,EAEA,MAAM,eAAeE,GAA4B;AAC/C,UAAMC,IAAU,MAAMF,EAA+B,MAAM,GACrDG,IAAOD,MAAY,QAAQ,OAAOA,KAAY,YAAY,CAAC,MAAM,QAAQA,CAAO,IAAIA,IAAU,CAAA;AACpG,UAAME,EAAM,QAAQ,EAAE,GAAGD,GAAM,cAAcF,GAAK;AAAA,EACpD;AAAA,EAEA,MAAM,mBAAkC;AACtC,UAAMC,IAAU,MAAMF,EAA+B,MAAM;AAC3D,QAAIE,MAAY,QAAQ,OAAOA,KAAY,YAAY,MAAM,QAAQA,CAAO,EAAG;AAC/E,UAAM,EAAE,cAAcG,GAAG,GAAGC,MAASJ;AACrC,UAAME,EAAM,QAAQE,CAAI;AAAA,EAC1B;AACF;AAEO,MAAMC,IAAiB,IAAIT,EAAA;"}
|
package/dist/utils/casing.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=e=>e.replace(/([a-z0-9])([A-Z])/g,"$1_$2").replace(/([A-Z])([A-Z][a-z])/g,"$1_$2").toLowerCase(),a=e=>e.replace(/[_-](\w)/g,(o,t)=>t.toUpperCase()),C=e=>e!=null&&Object.prototype.toString.call(e)==="[object Object]",r=(e,o)=>Array.isArray(e)?e.map(t=>r(t,o)):C(e)?Object.entries(e).reduce((t,[n,s])=>(t[o(n)]=r(s,o),t),{}):e,i=e=>r(e,c),l=e=>r(e,a);exports.convertKeysToCamelCase=l;exports.convertKeysToSnakeCase=i;
|
|
2
2
|
//# sourceMappingURL=casing.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"casing.cjs","sources":["../../src/utils/casing.ts"],"sourcesContent":["const toSnakeCase = (input: string): string =>\n input\n .replace(/([a-z0-9])([A-Z])/g, \"$1_$2\")\n .replace(/([A-Z])([A-Z][a-z])/g, \"$1_$2\")\n .toLowerCase();\n\nconst toCamelCase = (input: string): string =>\n input.replace(/[_-](\\w)/g, (_, char: string) => char.toUpperCase());\n\nconst isPlainObject = (value: unknown): value is Record<string, unknown> =>\n value != null &&\n Object.prototype.toString.call(value) === \"[object Object]\";\n\nconst convertKeys = (\n value: unknown,\n keyMapper: (key: string) => string,\n): unknown => {\n if (Array.isArray(value)) {\n return value.map((item) => convertKeys(item, keyMapper));\n }\n\n if (isPlainObject(value)) {\n return Object.entries(value).reduce<Record<string, unknown>>(\n (acc, [key, val]) => {\n acc[keyMapper(key)] = convertKeys(val, keyMapper);\n return acc;\n },\n {},\n );\n }\n\n return value;\n};\n\nexport const convertKeysToSnakeCase = (value: unknown): unknown =>\n convertKeys(value, toSnakeCase);\n\nexport const convertKeysToCamelCase = (value: unknown): unknown =>\n convertKeys(value, toCamelCase);\n\
|
|
1
|
+
{"version":3,"file":"casing.cjs","sources":["../../src/utils/casing.ts"],"sourcesContent":["const toSnakeCase = (input: string): string =>\n input\n .replace(/([a-z0-9])([A-Z])/g, \"$1_$2\")\n .replace(/([A-Z])([A-Z][a-z])/g, \"$1_$2\")\n .toLowerCase();\n\nconst toCamelCase = (input: string): string =>\n input.replace(/[_-](\\w)/g, (_, char: string) => char.toUpperCase());\n\nconst isPlainObject = (value: unknown): value is Record<string, unknown> =>\n value != null &&\n Object.prototype.toString.call(value) === \"[object Object]\";\n\nconst convertKeys = (\n value: unknown,\n keyMapper: (key: string) => string,\n): unknown => {\n if (Array.isArray(value)) {\n return value.map((item) => convertKeys(item, keyMapper));\n }\n\n if (isPlainObject(value)) {\n return Object.entries(value).reduce<Record<string, unknown>>(\n (acc, [key, val]) => {\n acc[keyMapper(key)] = convertKeys(val, keyMapper);\n return acc;\n },\n {},\n );\n }\n\n return value;\n};\n\nexport const convertKeysToSnakeCase = (value: unknown): unknown =>\n convertKeys(value, toSnakeCase);\n\nexport const convertKeysToCamelCase = (value: unknown): unknown =>\n convertKeys(value, toCamelCase);\n\n\n"],"names":["toSnakeCase","input","toCamelCase","_","char","isPlainObject","value","convertKeys","keyMapper","item","acc","key","val","convertKeysToSnakeCase","convertKeysToCamelCase"],"mappings":"gFAAA,MAAMA,EAAeC,GACnBA,EACG,QAAQ,qBAAsB,OAAO,EACrC,QAAQ,uBAAwB,OAAO,EACvC,YAAA,EAECC,EAAeD,GACnBA,EAAM,QAAQ,YAAa,CAACE,EAAGC,IAAiBA,EAAK,aAAa,EAE9DC,EAAiBC,GACrBA,GAAS,MACT,OAAO,UAAU,SAAS,KAAKA,CAAK,IAAM,kBAEtCC,EAAc,CAClBD,EACAE,IAEI,MAAM,QAAQF,CAAK,EACdA,EAAM,IAAKG,GAASF,EAAYE,EAAMD,CAAS,CAAC,EAGrDH,EAAcC,CAAK,EACd,OAAO,QAAQA,CAAK,EAAE,OAC3B,CAACI,EAAK,CAACC,EAAKC,CAAG,KACbF,EAAIF,EAAUG,CAAG,CAAC,EAAIJ,EAAYK,EAAKJ,CAAS,EACzCE,GAET,CAAA,CAAC,EAIEJ,EAGIO,EAA0BP,GACrCC,EAAYD,EAAON,CAAW,EAEnBc,EAA0BR,GACrCC,EAAYD,EAAOJ,CAAW"}
|
package/dist/utils/casing.d.ts
CHANGED
|
@@ -1,6 +1,2 @@
|
|
|
1
|
-
declare const toSnakeCase: (input: string) => string;
|
|
2
|
-
declare const toCamelCase: (input: string) => string;
|
|
3
|
-
declare const isPlainObject: (value: unknown) => value is Record<string, unknown>;
|
|
4
1
|
export declare const convertKeysToSnakeCase: (value: unknown) => unknown;
|
|
5
2
|
export declare const convertKeysToCamelCase: (value: unknown) => unknown;
|
|
6
|
-
export { toSnakeCase, toCamelCase, isPlainObject };
|
package/dist/utils/casing.mjs
CHANGED
|
@@ -4,9 +4,6 @@ const c = (e) => e.replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/([A-Z])([A-Z]
|
|
|
4
4
|
) : e, i = (e) => o(e, c), b = (e) => o(e, a);
|
|
5
5
|
export {
|
|
6
6
|
b as convertKeysToCamelCase,
|
|
7
|
-
i as convertKeysToSnakeCase
|
|
8
|
-
C as isPlainObject,
|
|
9
|
-
a as toCamelCase,
|
|
10
|
-
c as toSnakeCase
|
|
7
|
+
i as convertKeysToSnakeCase
|
|
11
8
|
};
|
|
12
9
|
//# sourceMappingURL=casing.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"casing.mjs","sources":["../../src/utils/casing.ts"],"sourcesContent":["const toSnakeCase = (input: string): string =>\n input\n .replace(/([a-z0-9])([A-Z])/g, \"$1_$2\")\n .replace(/([A-Z])([A-Z][a-z])/g, \"$1_$2\")\n .toLowerCase();\n\nconst toCamelCase = (input: string): string =>\n input.replace(/[_-](\\w)/g, (_, char: string) => char.toUpperCase());\n\nconst isPlainObject = (value: unknown): value is Record<string, unknown> =>\n value != null &&\n Object.prototype.toString.call(value) === \"[object Object]\";\n\nconst convertKeys = (\n value: unknown,\n keyMapper: (key: string) => string,\n): unknown => {\n if (Array.isArray(value)) {\n return value.map((item) => convertKeys(item, keyMapper));\n }\n\n if (isPlainObject(value)) {\n return Object.entries(value).reduce<Record<string, unknown>>(\n (acc, [key, val]) => {\n acc[keyMapper(key)] = convertKeys(val, keyMapper);\n return acc;\n },\n {},\n );\n }\n\n return value;\n};\n\nexport const convertKeysToSnakeCase = (value: unknown): unknown =>\n convertKeys(value, toSnakeCase);\n\nexport const convertKeysToCamelCase = (value: unknown): unknown =>\n convertKeys(value, toCamelCase);\n\
|
|
1
|
+
{"version":3,"file":"casing.mjs","sources":["../../src/utils/casing.ts"],"sourcesContent":["const toSnakeCase = (input: string): string =>\n input\n .replace(/([a-z0-9])([A-Z])/g, \"$1_$2\")\n .replace(/([A-Z])([A-Z][a-z])/g, \"$1_$2\")\n .toLowerCase();\n\nconst toCamelCase = (input: string): string =>\n input.replace(/[_-](\\w)/g, (_, char: string) => char.toUpperCase());\n\nconst isPlainObject = (value: unknown): value is Record<string, unknown> =>\n value != null &&\n Object.prototype.toString.call(value) === \"[object Object]\";\n\nconst convertKeys = (\n value: unknown,\n keyMapper: (key: string) => string,\n): unknown => {\n if (Array.isArray(value)) {\n return value.map((item) => convertKeys(item, keyMapper));\n }\n\n if (isPlainObject(value)) {\n return Object.entries(value).reduce<Record<string, unknown>>(\n (acc, [key, val]) => {\n acc[keyMapper(key)] = convertKeys(val, keyMapper);\n return acc;\n },\n {},\n );\n }\n\n return value;\n};\n\nexport const convertKeysToSnakeCase = (value: unknown): unknown =>\n convertKeys(value, toSnakeCase);\n\nexport const convertKeysToCamelCase = (value: unknown): unknown =>\n convertKeys(value, toCamelCase);\n\n\n"],"names":["toSnakeCase","input","toCamelCase","_","char","isPlainObject","value","convertKeys","keyMapper","item","acc","key","val","convertKeysToSnakeCase","convertKeysToCamelCase"],"mappings":"AAAA,MAAMA,IAAc,CAACC,MACnBA,EACG,QAAQ,sBAAsB,OAAO,EACrC,QAAQ,wBAAwB,OAAO,EACvC,YAAA,GAECC,IAAc,CAACD,MACnBA,EAAM,QAAQ,aAAa,CAACE,GAAGC,MAAiBA,EAAK,aAAa,GAE9DC,IAAgB,CAACC,MACrBA,KAAS,QACT,OAAO,UAAU,SAAS,KAAKA,CAAK,MAAM,mBAEtCC,IAAc,CAClBD,GACAE,MAEI,MAAM,QAAQF,CAAK,IACdA,EAAM,IAAI,CAACG,MAASF,EAAYE,GAAMD,CAAS,CAAC,IAGrDH,EAAcC,CAAK,IACd,OAAO,QAAQA,CAAK,EAAE;AAAA,EAC3B,CAACI,GAAK,CAACC,GAAKC,CAAG,OACbF,EAAIF,EAAUG,CAAG,CAAC,IAAIJ,EAAYK,GAAKJ,CAAS,GACzCE;AAAA,EAET,CAAA;AAAC,IAIEJ,GAGIO,IAAyB,CAACP,MACrCC,EAAYD,GAAON,CAAW,GAEnBc,IAAyB,CAACR,MACrCC,EAAYD,GAAOJ,CAAW;"}
|
package/dist/validation.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function i(e){e.mode&&e.mode,e.onIssue}exports.configureValidation=i;
|
|
2
2
|
//# sourceMappingURL=validation.cjs.map
|
package/dist/validation.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validation.cjs","sources":["../src/validation.ts"],"sourcesContent":["// src/validation.ts\nimport type { z } from \"zod\";\nimport { SchemaMismatchError } from \"./errors\";\n\nexport type ValidationMode = \"strict\" | \"warn\" | \"silent\";\nlet mode: ValidationMode = \"strict\";\nlet onIssue: ((ctx: string, details: unknown) => void) | undefined;\n\nexport function configureValidation(opts: {\n mode?: ValidationMode;\n onIssue?: (ctx: string, details: unknown) => void;\n}) {\n if (opts.mode) mode = opts.mode;\n onIssue = opts.onIssue;\n}\n\
|
|
1
|
+
{"version":3,"file":"validation.cjs","sources":["../src/validation.ts"],"sourcesContent":["// src/validation.ts\nimport type { z } from \"zod\";\nimport { SchemaMismatchError } from \"./errors\";\n\nexport type ValidationMode = \"strict\" | \"warn\" | \"silent\";\nlet mode: ValidationMode = \"strict\";\nlet onIssue: ((ctx: string, details: unknown) => void) | undefined;\n\nexport function configureValidation(opts: {\n mode?: ValidationMode;\n onIssue?: (ctx: string, details: unknown) => void;\n}) {\n if (opts.mode) mode = opts.mode;\n onIssue = opts.onIssue;\n}\n\nfunction validate<T>(\n schema: z.ZodType<T>,\n value: unknown,\n ctx: string,\n): T | null {\n const res = schema.safeParse(value);\n if (res.success) return res.data;\n\n const details = res.error.flatten();\n onIssue?.(ctx, details);\n\n if (mode === \"strict\")\n throw new SchemaMismatchError(`ORM schema mismatch in ${ctx}`, details);\n if (mode === \"warn\") console.warn(`ORM schema mismatch in ${ctx}`, details); // eslint-disable-line no-console\n return null; // silent/warn → let caller decide how to proceed\n}\n"],"names":["configureValidation","opts"],"mappings":"gFAQO,SAASA,EAAoBC,EAGjC,CACGA,EAAK,MAAaA,EAAK,KACjBA,EAAK,OACjB"}
|
package/dist/validation.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import type { z } from "zod";
|
|
2
1
|
export type ValidationMode = "strict" | "warn" | "silent";
|
|
3
2
|
export declare function configureValidation(opts: {
|
|
4
3
|
mode?: ValidationMode;
|
|
5
4
|
onIssue?: (ctx: string, details: unknown) => void;
|
|
6
5
|
}): void;
|
|
7
|
-
export declare function validate<T>(schema: z.ZodType<T>, value: unknown, ctx: string): T | null;
|
package/dist/validation.mjs
CHANGED
|
@@ -1,18 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
function m(e) {
|
|
4
|
-
e.mode && (n = e.mode), r = e.onIssue;
|
|
5
|
-
}
|
|
6
|
-
function f(e, o, t) {
|
|
7
|
-
const i = e.safeParse(o);
|
|
8
|
-
if (i.success) return i.data;
|
|
9
|
-
const a = i.error.flatten();
|
|
10
|
-
if (r == null || r(t, a), n === "strict")
|
|
11
|
-
throw new s(`ORM schema mismatch in ${t}`, a);
|
|
12
|
-
return n === "warn" && console.warn(`ORM schema mismatch in ${t}`, a), null;
|
|
1
|
+
function i(e) {
|
|
2
|
+
e.mode && e.mode, e.onIssue;
|
|
13
3
|
}
|
|
14
4
|
export {
|
|
15
|
-
|
|
16
|
-
f as validate
|
|
5
|
+
i as configureValidation
|
|
17
6
|
};
|
|
18
7
|
//# sourceMappingURL=validation.mjs.map
|
package/dist/validation.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validation.mjs","sources":["../src/validation.ts"],"sourcesContent":["// src/validation.ts\nimport type { z } from \"zod\";\nimport { SchemaMismatchError } from \"./errors\";\n\nexport type ValidationMode = \"strict\" | \"warn\" | \"silent\";\nlet mode: ValidationMode = \"strict\";\nlet onIssue: ((ctx: string, details: unknown) => void) | undefined;\n\nexport function configureValidation(opts: {\n mode?: ValidationMode;\n onIssue?: (ctx: string, details: unknown) => void;\n}) {\n if (opts.mode) mode = opts.mode;\n onIssue = opts.onIssue;\n}\n\
|
|
1
|
+
{"version":3,"file":"validation.mjs","sources":["../src/validation.ts"],"sourcesContent":["// src/validation.ts\nimport type { z } from \"zod\";\nimport { SchemaMismatchError } from \"./errors\";\n\nexport type ValidationMode = \"strict\" | \"warn\" | \"silent\";\nlet mode: ValidationMode = \"strict\";\nlet onIssue: ((ctx: string, details: unknown) => void) | undefined;\n\nexport function configureValidation(opts: {\n mode?: ValidationMode;\n onIssue?: (ctx: string, details: unknown) => void;\n}) {\n if (opts.mode) mode = opts.mode;\n onIssue = opts.onIssue;\n}\n\nfunction validate<T>(\n schema: z.ZodType<T>,\n value: unknown,\n ctx: string,\n): T | null {\n const res = schema.safeParse(value);\n if (res.success) return res.data;\n\n const details = res.error.flatten();\n onIssue?.(ctx, details);\n\n if (mode === \"strict\")\n throw new SchemaMismatchError(`ORM schema mismatch in ${ctx}`, details);\n if (mode === \"warn\") console.warn(`ORM schema mismatch in ${ctx}`, details); // eslint-disable-line no-console\n return null; // silent/warn → let caller decide how to proceed\n}\n"],"names":["configureValidation","opts"],"mappings":"AAQO,SAASA,EAAoBC,GAGjC;AACD,EAAIA,EAAK,QAAaA,EAAK,MACjBA,EAAK;AACjB;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@superbright/indexeddb-orm",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.34",
|
|
4
4
|
"description": "Vite + TypeScript starter for an IndexedDB ORM (Dexie + Zod) with playground.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"type": "module",
|
|
@@ -54,10 +54,14 @@
|
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
56
|
"react": "^18.0.0",
|
|
57
|
+
"zustand": ">=4.5.0",
|
|
57
58
|
"mixpanel-browser": "^2.67.0",
|
|
58
59
|
"posthog-js": "^1.0.0"
|
|
59
60
|
},
|
|
60
61
|
"peerDependenciesMeta": {
|
|
62
|
+
"zustand": {
|
|
63
|
+
"optional": true
|
|
64
|
+
},
|
|
61
65
|
"mixpanel-browser": {
|
|
62
66
|
"optional": true
|
|
63
67
|
},
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("./zustand-store.cjs");function u(t,i){return{property:{unit:{favorites:{toggle:t.toggleFavorite.bind(t),setAll:t.setFavoriteUnitIds.bind(t)},viewed:{mark:t.markUnitAsViewed.bind(t)}},questionnaire:{setResults:t.setQuestionnaireResults.bind(t)},tour:{setContactedOn:t.setTourContactedOn.bind(t),getContactedOn:t.getTourContactedOn.bind(t),setContactData:t.setTourContactData.bind(t)}},filters:{set:t.setFilters.bind(t),setTemp:t.setTempFilters.bind(t),setToDefault:t.setFiltersToDefault.bind(t),commitTemp:async(e,n)=>{const c=(i?i():t).tempFilters[e]??n;await t.handleTempFilterChange(e,c),await t.submitFilterUpdate()},commitDateAvailability:async()=>{await t.submitFilterUpdate()},submit:t.submitFilterUpdate.bind(t)}}}function r(t){return(i,e)=>{const n=d.createZustandUnifiedStore(t)(i,e),a=u(n,e);return{...n,...a}}}exports.createStructuredStore=r;exports.createStructuredStoreActions=u;
|
|
2
|
-
//# sourceMappingURL=structured-store.cjs.map
|