@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/README.md
CHANGED
|
@@ -1,397 +1,82 @@
|
|
|
1
|
-
#
|
|
1
|
+
# InResi ORM
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Shared state and analytics layer for InResi apps. Built on Dexie (IndexedDB), Zustand, and Zod.
|
|
4
4
|
|
|
5
|
-
##
|
|
6
|
-
|
|
7
|
-
- **TypeScript-First**: Full type safety with Zod schema validation
|
|
8
|
-
- **Structured Store Actions**: Organized, nested API for better developer experience
|
|
9
|
-
- **IndexedDB Powered**: Built on Dexie for robust browser storage
|
|
10
|
-
- **Zustand Integration**: Seamless state management with React
|
|
11
|
-
- **Schema Validation**: Runtime validation with Zod schemas
|
|
12
|
-
- **Developer Experience**: Hot reloading, type inference, and great autocomplete
|
|
13
|
-
- **Production Ready**: Optimized builds with proper package exports
|
|
14
|
-
|
|
15
|
-
## 📦 Installation
|
|
5
|
+
## Install
|
|
16
6
|
|
|
17
7
|
```bash
|
|
18
8
|
pnpm install @superbright/indexeddb-orm zustand
|
|
19
9
|
```
|
|
20
10
|
|
|
21
|
-
##
|
|
22
|
-
|
|
23
|
-
### 1. Basic Setup
|
|
24
|
-
|
|
25
|
-
```typescript
|
|
26
|
-
import { create } from "zustand";
|
|
27
|
-
import { devtools } from "zustand/middleware";
|
|
28
|
-
import {
|
|
29
|
-
createStructuredStore,
|
|
30
|
-
createUseUnitState,
|
|
31
|
-
type StructuredStore,
|
|
32
|
-
type Filters,
|
|
33
|
-
type QueryParams,
|
|
34
|
-
} from "@superbright/indexeddb-orm";
|
|
35
|
-
|
|
36
|
-
// Create your store with structured actions
|
|
37
|
-
export const useStore = create<StructuredStore>()(
|
|
38
|
-
devtools(
|
|
39
|
-
createStructuredStore({
|
|
40
|
-
onFilterUpdate: (apiParams: QueryParams) => {
|
|
41
|
-
console.log("Filters updated:", apiParams);
|
|
42
|
-
},
|
|
43
|
-
}),
|
|
44
|
-
{ name: "inresi-store" }
|
|
45
|
-
)
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
export const useUnitState = createUseUnitState()(useStore);
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
### 2. Initialize in Your App
|
|
52
|
-
|
|
53
|
-
```typescript
|
|
54
|
-
// main.tsx or App.tsx
|
|
55
|
-
import { useStore } from './stores/myStore';
|
|
56
|
-
|
|
57
|
-
async function initializeApp() {
|
|
58
|
-
await useStore.getState()._initialize();
|
|
59
|
-
await useStore.getState()._hydrate();
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
initializeApp().then(() => {
|
|
63
|
-
// Render your app
|
|
64
|
-
});
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
### 3. Use Structured Actions
|
|
68
|
-
|
|
69
|
-
```typescript
|
|
70
|
-
function MyComponent() {
|
|
71
|
-
const store = useStore();
|
|
72
|
-
|
|
73
|
-
// Property actions
|
|
74
|
-
const toggleFavorite = async (unitId: string) => {
|
|
75
|
-
await store.property.unit.favorites.toggle(unitId);
|
|
76
|
-
};
|
|
11
|
+
## Usage
|
|
77
12
|
|
|
78
|
-
|
|
79
|
-
await store.property.unit.viewed.mark(unitId, slug);
|
|
80
|
-
};
|
|
13
|
+
### Provider setup
|
|
81
14
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
await store.filters.submit();
|
|
86
|
-
};
|
|
15
|
+
```tsx
|
|
16
|
+
import { AnalyticsProvider } from "@superbright/indexeddb-orm";
|
|
17
|
+
import { useVisitorSession } from "./hooks/useVisitorSession";
|
|
87
18
|
|
|
19
|
+
function Providers({ children }: { children: React.ReactNode }) {
|
|
20
|
+
const visitor_uuid = useVisitorSession(slug);
|
|
88
21
|
return (
|
|
89
|
-
<
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
</button>
|
|
99
|
-
</div>
|
|
22
|
+
<AnalyticsProvider
|
|
23
|
+
visitor_uuid={visitor_uuid}
|
|
24
|
+
mixpanelToken={import.meta.env.VITE_MIXPANEL_TOKEN}
|
|
25
|
+
posthogKey={import.meta.env.VITE_POSTHOG_KEY}
|
|
26
|
+
posthogHost={import.meta.env.VITE_POSTHOG_HOST}
|
|
27
|
+
envMode={import.meta.env.MODE ?? "production"}
|
|
28
|
+
>
|
|
29
|
+
{children}
|
|
30
|
+
</AnalyticsProvider>
|
|
100
31
|
);
|
|
101
32
|
}
|
|
102
33
|
```
|
|
103
34
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
### Core Components
|
|
107
|
-
|
|
108
|
-
- **Dexie Database**: IndexedDB abstraction layer
|
|
109
|
-
- **Zod Schemas**: Runtime type validation and TypeScript inference
|
|
110
|
-
- **Unified Store**: Single source of truth combining property and app state
|
|
111
|
-
- **Structured Actions**: Organized API with nested action groups
|
|
112
|
-
- **Zustand Integration**: React state management with devtools support
|
|
113
|
-
|
|
114
|
-
### Data Flow
|
|
115
|
-
|
|
116
|
-
```
|
|
117
|
-
React Components
|
|
118
|
-
↓
|
|
119
|
-
Structured Store Actions
|
|
120
|
-
↓
|
|
121
|
-
Unified Store (Zustand)
|
|
122
|
-
↓
|
|
123
|
-
ORM Layer (Validation)
|
|
124
|
-
↓
|
|
125
|
-
IndexedDB (Dexie)
|
|
126
|
-
```
|
|
127
|
-
|
|
128
|
-
## 📚 API Reference
|
|
129
|
-
|
|
130
|
-
### Structured Store Actions
|
|
131
|
-
|
|
132
|
-
#### Property Actions
|
|
133
|
-
```typescript
|
|
134
|
-
// Unit favorites
|
|
135
|
-
store.property.unit.favorites.toggle(unitId: string)
|
|
35
|
+
### Store + analytics in components
|
|
136
36
|
|
|
137
|
-
|
|
138
|
-
|
|
37
|
+
```tsx
|
|
38
|
+
import { useInResiStore, useTrackingEvents } from "@superbright/indexeddb-orm";
|
|
139
39
|
|
|
140
|
-
|
|
141
|
-
store
|
|
142
|
-
|
|
143
|
-
// Tour scheduling
|
|
144
|
-
store.property.tour.setContactedOn()
|
|
145
|
-
store.property.tour.getContactedOn()
|
|
146
|
-
store.property.tour.setContactData(data: TourContactData)
|
|
147
|
-
```
|
|
40
|
+
function MyComponent() {
|
|
41
|
+
const store = useInResiStore();
|
|
42
|
+
const { trackClickUnit, trackFilterApplied } = useTrackingEvents();
|
|
148
43
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
store.filters.set(filters: Partial<Filters>)
|
|
153
|
-
store.filters.setTemp(filters: Partial<Filters>)
|
|
154
|
-
store.filters.setToDefault()
|
|
155
|
-
store.filters.commitTemp(key, defaultValue)
|
|
156
|
-
store.filters.commitDateAvailability()
|
|
157
|
-
store.filters.submit()
|
|
44
|
+
store.handleTempFilterChange("qty_bedrooms", [1, 2]);
|
|
45
|
+
store.submitFilterUpdate();
|
|
46
|
+
}
|
|
158
47
|
```
|
|
159
48
|
|
|
160
|
-
###
|
|
49
|
+
### Visitor UUID
|
|
161
50
|
|
|
162
51
|
```typescript
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
const properties = useStore(state => state.properties);
|
|
166
|
-
|
|
167
|
-
// App data
|
|
168
|
-
const filters = useStore(state => state.filters);
|
|
169
|
-
const unitResults = useStore(state => state.unitResults);
|
|
170
|
-
const resultsMode = useStore(state => state.resultsMode);
|
|
171
|
-
|
|
172
|
-
// Unit state helper
|
|
173
|
-
const unitState = useUnitState("unit-123");
|
|
174
|
-
// Returns: { isFavorite: boolean, viewedDate: string }
|
|
52
|
+
const uuid = await store.getVisitorUUID();
|
|
53
|
+
await store.setVisitorUUID("550e8400-...");
|
|
175
54
|
```
|
|
176
55
|
|
|
177
|
-
|
|
56
|
+
`useVisitorSession(slug)` handles creation and persistence — prefer it in React.
|
|
178
57
|
|
|
179
|
-
|
|
58
|
+
### Dimension helpers
|
|
180
59
|
|
|
181
60
|
```typescript
|
|
182
|
-
|
|
183
|
-
await store.getCurrentProperty();
|
|
184
|
-
await store.setCurrentProperty(propertyId, slug);
|
|
185
|
-
await store.getPropertyData(propertyId);
|
|
186
|
-
|
|
187
|
-
// Unit results cache
|
|
188
|
-
await store.setUnitResults(transformedUnits.hits);
|
|
189
|
-
await store.clearUnitResults();
|
|
190
|
-
|
|
191
|
-
// Filters
|
|
192
|
-
await store.setFilters({ qty_bedrooms: [1, 2] });
|
|
193
|
-
await store.setTempFilters({ base_price: 2500 });
|
|
194
|
-
await store.submitFilterUpdate();
|
|
195
|
-
```
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
## 🛠️ Development
|
|
199
|
-
|
|
200
|
-
### Local Development Setup
|
|
61
|
+
import { mmToInches, formatDimensions, dimensionToMmNumber } from "@superbright/indexeddb-orm";
|
|
201
62
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
Create `.env` in your consuming app:
|
|
205
|
-
|
|
206
|
-
```bash
|
|
207
|
-
VITE_USE_LOCAL_ORM_LIBRARY=true
|
|
208
|
-
VITE_LOCAL_ORM_LIBRARY_PATH=/path/to/indexeddb-orm-starter-with-playground
|
|
63
|
+
formatDimensions({ width: 800, depth: 600, height: 750 });
|
|
64
|
+
// → "31.5"W x 23.6"D x 29.5"H"
|
|
209
65
|
```
|
|
210
66
|
|
|
211
|
-
|
|
67
|
+
## Analytics validation
|
|
212
68
|
|
|
213
|
-
|
|
214
|
-
// vite.config.ts
|
|
215
|
-
const alias: Record<string, string> = {};
|
|
216
|
-
if (useLocalORM && ormPath) {
|
|
217
|
-
alias["@superbright/indexeddb-orm"] = resolve(ormPath, "./dist");
|
|
218
|
-
}
|
|
219
|
-
```
|
|
69
|
+
Events are validated via Zod before dispatch. Invalid payloads are **silently dropped** in production and logged as `console.warn` in dev (`isDev` flag on `AnalyticsProvider`). If events aren't firing, check required fields on the schema for that event type.
|
|
220
70
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
The ORM includes a comprehensive interactive playground for testing and exploring functionality:
|
|
71
|
+
## Development
|
|
224
72
|
|
|
225
73
|
```bash
|
|
226
74
|
pnpm i
|
|
227
|
-
pnpm dev
|
|
228
|
-
#
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
#### Playground Features
|
|
232
|
-
|
|
233
|
-
- **🗄️ Database Operations**: Initialize, dump state, export JSON, and reset database
|
|
234
|
-
- **🏠 Property Management**: Create properties, set current property, retrieve property data
|
|
235
|
-
- **⭐ Unit Actions**: Toggle favorites, mark units as viewed, get unit state
|
|
236
|
-
- **🔍 Filter Operations**: Set filters, reset to defaults, submit filter updates
|
|
237
|
-
- **🧪 Search & Results**: Set results mode and sort order, run a mock search that populates unit results, and clear results
|
|
238
|
-
- **📝 Questionnaire & Tours**: Set questionnaire results, manage tour contact data
|
|
239
|
-
- **📊 Real-time State View**: Live view of database state and action logs
|
|
240
|
-
- **🛠️ Developer Tools Integration**: Inspect IndexedDB directly in DevTools → Application → IndexedDB → `inresi-orm`
|
|
241
|
-
|
|
242
|
-
#### How to Use
|
|
243
|
-
|
|
244
|
-
1. **Start with Database Operations**: Click "Initialize Database" to set up the ORM
|
|
245
|
-
2. **Create a Property**: Enter a property ID and slug, then click "Initialize Property"
|
|
246
|
-
3. **Test Unit Actions**: Enter a unit ID and try toggling favorites or marking as viewed
|
|
247
|
-
4. **Experiment with Filters**: Set bedroom counts and base price filters, then submit them
|
|
248
|
-
5. **View State Changes**: Watch the real-time state updates and action logs
|
|
249
|
-
6. **Inspect Database**: Open browser DevTools to see the actual IndexedDB storage
|
|
250
|
-
|
|
251
|
-
The playground demonstrates all structured store actions and provides immediate feedback, making it perfect for learning the API and testing integrations.
|
|
252
|
-
|
|
253
|
-
### Build Scripts
|
|
254
|
-
|
|
255
|
-
```bash
|
|
256
|
-
# Development
|
|
257
|
-
pnpm run dev # Start playground with hot reload
|
|
258
|
-
pnpm run watch # Watch mode for types and bundle
|
|
259
|
-
|
|
260
|
-
# Building
|
|
261
|
-
pnpm run build # Production build
|
|
262
|
-
pnpm run clean # Clean dist folder
|
|
263
|
-
|
|
264
|
-
# Testing
|
|
265
|
-
pnpm run test # Run tests
|
|
266
|
-
pnpm run test:watch # Watch mode testing
|
|
267
|
-
```
|
|
268
|
-
|
|
269
|
-
### Package Structure
|
|
270
|
-
|
|
271
|
-
```
|
|
272
|
-
dist/
|
|
273
|
-
├── index.d.ts # Main type definitions
|
|
274
|
-
├── index.es.js # ES module build
|
|
275
|
-
├── index.cjs.js # CommonJS build
|
|
276
|
-
├── adapters/ # Store adapters
|
|
277
|
-
├── api/ # API modules
|
|
278
|
-
└── stores/ # Store implementations
|
|
279
|
-
```
|
|
280
|
-
|
|
281
|
-
## 🎯 TypeScript Support
|
|
282
|
-
|
|
283
|
-
Full TypeScript support with proper type inference:
|
|
284
|
-
|
|
285
|
-
```typescript
|
|
286
|
-
import type {
|
|
287
|
-
StructuredStore,
|
|
288
|
-
StructuredStoreActions,
|
|
289
|
-
Filters,
|
|
290
|
-
QueryParams,
|
|
291
|
-
TourContactData,
|
|
292
|
-
UserPropertyState,
|
|
293
|
-
Unit,
|
|
294
|
-
ZustandUnifiedStoreState,
|
|
295
|
-
} from "@superbright/indexeddb-orm";
|
|
296
|
-
```
|
|
297
|
-
|
|
298
|
-
## 📋 Schema Validation
|
|
299
|
-
|
|
300
|
-
Built-in Zod schemas ensure data integrity:
|
|
301
|
-
|
|
302
|
-
```typescript
|
|
303
|
-
// Example schema usage
|
|
304
|
-
import { FiltersSchema, UnitSchema } from "@superbright/indexeddb-orm";
|
|
305
|
-
|
|
306
|
-
// Validate data at runtime
|
|
307
|
-
const validatedFilters = FiltersSchema.parse(userInput);
|
|
308
|
-
const validatedUnit = UnitSchema.parse(transformedUnit);
|
|
309
|
-
```
|
|
310
|
-
|
|
311
|
-
## 🔧 Configuration
|
|
312
|
-
|
|
313
|
-
### Store Configuration
|
|
314
|
-
|
|
315
|
-
```typescript
|
|
316
|
-
createStructuredStore({
|
|
317
|
-
onFilterUpdate?: (apiParams: QueryParams) => void;
|
|
318
|
-
// Add more configuration options as needed
|
|
319
|
-
})
|
|
320
|
-
```
|
|
321
|
-
|
|
322
|
-
### Validation Configuration
|
|
323
|
-
|
|
324
|
-
```typescript
|
|
325
|
-
import { configureValidation } from "@superbright/indexeddb-orm";
|
|
326
|
-
|
|
327
|
-
// Configure validation mode
|
|
328
|
-
configureValidation("strict"); // "strict" | "warn" | "off"
|
|
329
|
-
```
|
|
330
|
-
|
|
331
|
-
## 🚀 Production
|
|
332
|
-
|
|
333
|
-
### Package Exports
|
|
334
|
-
|
|
335
|
-
```json
|
|
336
|
-
{
|
|
337
|
-
"exports": {
|
|
338
|
-
".": {
|
|
339
|
-
"types": "./dist/index.d.ts",
|
|
340
|
-
"import": "./dist/index.mjs",
|
|
341
|
-
"require": "./dist/index.cjs"
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
}
|
|
75
|
+
pnpm dev # playground at http://localhost:5173
|
|
76
|
+
pnpm build # production build
|
|
77
|
+
pnpm test
|
|
345
78
|
```
|
|
346
79
|
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
- Tree-shakable ES modules
|
|
350
|
-
- Separate type definitions
|
|
351
|
-
- Optimized for Vite and Webpack
|
|
352
|
-
- Source maps included
|
|
353
|
-
|
|
354
|
-
## 📖 Documentation
|
|
355
|
-
|
|
356
|
-
- [Consuming App Guide](./CONSUMING_APP_GUIDE.md) - Complete integration guide
|
|
357
|
-
- [Structured Store Migration](./docs/structured-store-migration.md) - Move to the structured API
|
|
358
|
-
- [App Store Guide](./docs/app-store-guide.md) - App state management
|
|
359
|
-
|
|
360
|
-
## 🔧 Legacy API
|
|
361
|
-
|
|
362
|
-
For backward compatibility, the original API is still available:
|
|
363
|
-
|
|
364
|
-
```ts
|
|
365
|
-
import {
|
|
366
|
-
getDB,
|
|
367
|
-
getFavouritedUnits, setFavouritedUnits,
|
|
368
|
-
getPreferences, setPreferences,
|
|
369
|
-
upsertUser, getUser,
|
|
370
|
-
debugDump, exportJSON
|
|
371
|
-
} from "@superbright/indexeddb-orm";
|
|
372
|
-
|
|
373
|
-
await getDB();
|
|
374
|
-
await setFavouritedUnits(["u1","u2"]);
|
|
375
|
-
console.log(await getFavouritedUnits());
|
|
376
|
-
await exportJSON();
|
|
377
|
-
```
|
|
378
|
-
|
|
379
|
-
## 🤝 Contributing
|
|
380
|
-
|
|
381
|
-
1. Fork the repository
|
|
382
|
-
2. Create a feature branch
|
|
383
|
-
3. Make your changes
|
|
384
|
-
4. Add tests if applicable
|
|
385
|
-
5. Ensure type checking passes: `pnpm run build`
|
|
386
|
-
6. Submit a pull request
|
|
387
|
-
|
|
388
|
-
## 📝 License
|
|
389
|
-
|
|
390
|
-
UNLICENSED - Proprietary software for internal use
|
|
391
|
-
|
|
392
|
-
## 🔗 Related Projects
|
|
80
|
+
## License
|
|
393
81
|
|
|
394
|
-
|
|
395
|
-
- [Zod](https://zod.dev/) - TypeScript schema validation
|
|
396
|
-
- [Zustand](https://zustand-demo.pmnd.rs/) - React state management
|
|
397
|
-
- [Vite](https://vitejs.dev/) - Build tool and dev server
|
|
82
|
+
UNLICENSED — proprietary, internal use only.
|
package/dist/adapters/dexie.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 r=require("../node_modules/.pnpm/dexie@4.2.0/node_modules/dexie/import-wrapper-prod.cjs"),s=require("../schema.cjs");class t extends r.Dexie{constructor(e="inresi-orm"){super(e),this.version(s.SCHEMA_VERSION).stores({kv:"key",users:null}),this.kv=this.table("kv")}}exports.OrmDexie=t;
|
|
2
2
|
//# sourceMappingURL=dexie.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dexie.cjs","sources":["../../src/adapters/dexie.ts"],"sourcesContent":["import Dexie, { type Table } from \"dexie\";\nimport { SCHEMA_VERSION } from \"../schema\";\n\
|
|
1
|
+
{"version":3,"file":"dexie.cjs","sources":["../../src/adapters/dexie.ts"],"sourcesContent":["import Dexie, { type Table } from \"dexie\";\nimport { SCHEMA_VERSION } from \"../schema\";\n\ninterface KV {\n key: string;\n value: unknown;\n}\n\ninterface OrmDexieTables {\n kv: Table<KV, string>;\n}\n\nexport class OrmDexie extends Dexie {\n kv!: OrmDexieTables[\"kv\"];\n\n constructor(name = \"inresi-orm\") {\n super(name);\n this.version(SCHEMA_VERSION).stores({ kv: \"key\", users: null });\n\n this.kv = this.table(\"kv\");\n }\n}\n"],"names":["OrmDexie","Dexie","name","SCHEMA_VERSION"],"mappings":"2MAYO,MAAMA,UAAiBC,EAAAA,KAAM,CAGlC,YAAYC,EAAO,aAAc,CAC/B,MAAMA,CAAI,EACV,KAAK,QAAQC,EAAAA,cAAc,EAAE,OAAO,CAAE,GAAI,MAAO,MAAO,KAAM,EAE9D,KAAK,GAAK,KAAK,MAAM,IAAI,CAC3B,CACF"}
|
package/dist/adapters/dexie.d.ts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import Dexie, { type Table } from "dexie";
|
|
2
|
-
|
|
2
|
+
interface KV {
|
|
3
3
|
key: string;
|
|
4
4
|
value: unknown;
|
|
5
5
|
}
|
|
6
|
-
|
|
7
|
-
users: Table<any, string>;
|
|
6
|
+
interface OrmDexieTables {
|
|
8
7
|
kv: Table<KV, string>;
|
|
9
8
|
}
|
|
10
9
|
export declare class OrmDexie extends Dexie {
|
|
11
|
-
users: OrmDexieTables["users"];
|
|
12
10
|
kv: OrmDexieTables["kv"];
|
|
13
11
|
constructor(name?: string);
|
|
14
12
|
}
|
|
13
|
+
export {};
|
package/dist/adapters/dexie.mjs
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
import { Dexie as
|
|
2
|
-
import { SCHEMA_VERSION as
|
|
3
|
-
class
|
|
4
|
-
constructor(
|
|
5
|
-
super(
|
|
6
|
-
users: "uuid",
|
|
7
|
-
kv: "key"
|
|
8
|
-
}), this.users = this.table("users"), this.kv = this.table("kv");
|
|
1
|
+
import { Dexie as r } from "../node_modules/.pnpm/dexie@4.2.0/node_modules/dexie/import-wrapper-prod.mjs";
|
|
2
|
+
import { SCHEMA_VERSION as s } from "../schema.mjs";
|
|
3
|
+
class m extends r {
|
|
4
|
+
constructor(e = "inresi-orm") {
|
|
5
|
+
super(e), this.version(s).stores({ kv: "key", users: null }), this.kv = this.table("kv");
|
|
9
6
|
}
|
|
10
7
|
}
|
|
11
8
|
export {
|
|
12
|
-
|
|
9
|
+
m as OrmDexie
|
|
13
10
|
};
|
|
14
11
|
//# sourceMappingURL=dexie.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dexie.mjs","sources":["../../src/adapters/dexie.ts"],"sourcesContent":["import Dexie, { type Table } from \"dexie\";\nimport { SCHEMA_VERSION } from \"../schema\";\n\
|
|
1
|
+
{"version":3,"file":"dexie.mjs","sources":["../../src/adapters/dexie.ts"],"sourcesContent":["import Dexie, { type Table } from \"dexie\";\nimport { SCHEMA_VERSION } from \"../schema\";\n\ninterface KV {\n key: string;\n value: unknown;\n}\n\ninterface OrmDexieTables {\n kv: Table<KV, string>;\n}\n\nexport class OrmDexie extends Dexie {\n kv!: OrmDexieTables[\"kv\"];\n\n constructor(name = \"inresi-orm\") {\n super(name);\n this.version(SCHEMA_VERSION).stores({ kv: \"key\", users: null });\n\n this.kv = this.table(\"kv\");\n }\n}\n"],"names":["OrmDexie","Dexie","name","SCHEMA_VERSION"],"mappings":";;AAYO,MAAMA,UAAiBC,EAAM;AAAA,EAGlC,YAAYC,IAAO,cAAc;AAC/B,UAAMA,CAAI,GACV,KAAK,QAAQC,CAAc,EAAE,OAAO,EAAE,IAAI,OAAO,OAAO,MAAM,GAE9D,KAAK,KAAK,KAAK,MAAM,IAAI;AAAA,EAC3B;AACF;"}
|
|
@@ -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 l=require("zustand"),o=require("zustand/middleware"),n=require("../features/filters/transformers.cjs"),a={date_availability:void 0,qty_bedrooms:void 0,base_price:void 0,highlights:void 0};function p(m){return(r,i)=>({currentPropertyId:null,filters:{...a},tempFilters:{...a},apiFilters:{limit:10,page:1,sortBy:"relevance"},async setCurrentPropertyId(e){r({currentPropertyId:e})},async setTempFilters(e){const{tempFilters:t}=i();r({tempFilters:{...t,...e}})},async setFiltersToDefault(){r({filters:{...a}})},async setApiFilters(e){const{apiFilters:t}=i();r({apiFilters:{...t,...e}})},async handleTempFilterChange(e,t){const{tempFilters:s}=i();r({tempFilters:{...s,[e]:t}})},async submitFilterUpdate(){const e=i(),t=e.apiFilters.sortBy,s=n.transformFiltersToUnitsSearchParams({...e.filters,limit:e.apiFilters.limit,page:e.apiFilters.page,sortBy:t},{defaultLimit:e.apiFilters.limit,defaultPage:e.apiFilters.page,defaultSort:t});r({apiFilters:s})}})}const c=l.create()(o.devtools(p(),{name:"inResi-orm-store"}));exports.useInResiStore=c;
|
|
2
2
|
//# sourceMappingURL=zustand-store.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zustand-store.cjs","sources":["../../src/adapters/zustand-store.ts"],"sourcesContent":["/**\n * Zustand adapter (flat API) — pure in-memory, no IndexedDB\n *\n * All engagement state (favorites, viewed, filters, etc.) is held in Zustand\n * only. No IndexedDB writes happen here. State is seeded at runtime from the\n * API (bootstrap endpoint) and updated optimistically by the consuming app.\n *\n * IndexedDB is used exclusively for visitor_uuid — see stores/store.ts.\n *\n * For a friendlier, domain-grouped API, use `createStructuredStore` from\n * `./structured-store`, which wraps this adapter and exposes nested actions\n * like `property.unit.favorites.toggle`, `filters.set`, etc.\n */\nimport { transformFiltersToUnitsSearchParams } from \"../features/filters/transformers\";\nimport { validate } from \"../validation\";\nimport { UnitSchema } from \"../schema\";\nimport type { UserPropertyState, Filters, QueryParams, ResultsMode, SortBy, TourContactData, Unit } from \"../schema\";\n\n// Unified Zustand store interface\nexport interface ZustandUnifiedStoreState {\n // Property data\n properties: Record<string, UserPropertyState>;\n currentPropertyId: string | null;\n currentPropertySlug: string | null;\n hasPreviouslySearched: string[];\n favorite_unit_ids: string[];\n\n // App data\n unitResults: Unit[];\n filters: Filters;\n tempFilters: Filters;\n apiFilters: QueryParams;\n resultsMode: ResultsMode;\n resolvedQuestionnaireValues: Record<string, string[]>;\n sortBy: SortBy;\n filtersLoaded: boolean;\n\n // === PROPERTY OPERATIONS ===\n initializeProperty: (propertyId: string, slug: string) => Promise<void>;\n setCurrentProperty: (propertyId: string, slug?: string) => Promise<void>;\n setCurrentPropertySlug: (slug: string) => Promise<void>;\n setHasPreviouslySearched: (slug: string) => Promise<void>;\n setFavoriteUnitIds: (unitIds: string[]) => Promise<void>;\n toggleFavorite: (unitId: string) => Promise<void>;\n markUnitAsViewed: (unitId: string, url: string) => Promise<void>;\n setTourContactedOn: () => Promise<void>;\n getTourContactedOn: () => Promise<string | null>;\n setQuestionnaireResults: (results: unknown) => Promise<void>;\n setTourContactData: (data: TourContactData) => Promise<void>;\n setUnitResults: (units: unknown) => Promise<void>;\n clearUnitResults: () => Promise<void>;\n\n // === FILTER OPERATIONS ===\n setFilters: (filters: Partial<Filters>) => Promise<void>;\n setTempFilters: (filters: Partial<Filters>) => Promise<void>;\n setFiltersToDefault: () => Promise<void>;\n setApiFilters: (filters: Partial<QueryParams>) => Promise<void>;\n handleTempFilterChange: <K extends keyof Filters>(key: K, value: Filters[K]) => Promise<void>;\n submitFilterUpdate: () => Promise<void>;\n\n // === RESULTS AND SORTING ===\n setResultsMode: (mode: ResultsMode) => Promise<void>;\n setSortBy: (sortBy: SortBy) => Promise<void>;\n\n // === QUESTIONNAIRE ===\n setResolvedQuestionnaireValues: (name: string, values: string[]) => Promise<void>;\n\n // === UTILITY METHODS ===\n getResultsUrl: () => Promise<string | null>;\n getCurrentProperty: () => Promise<UserPropertyState | null>;\n getPropertyData: (propertyId?: string) => Promise<UserPropertyState | null>;\n\n // === INTERNAL ===\n _hydrate: () => Promise<void>;\n _initialize: () => Promise<void>;\n}\n\nconst defaultFilters: Filters = {\n date_availability: undefined,\n qty_bedrooms: undefined,\n base_price: undefined,\n highlights: undefined,\n};\n\n/**\n * @deprecated For new apps, use `createStructuredStore` from `./structured-store`.\n * This flat adapter remains for migration/advanced cases.\n */\nexport function createZustandUnifiedStore(options?: {\n onFilterUpdate?: (apiParams: QueryParams) => void;\n}) {\n return (set: any, get: any): ZustandUnifiedStoreState => {\n return {\n // Initial state\n properties: {},\n currentPropertyId: null,\n currentPropertySlug: null,\n hasPreviouslySearched: [],\n favorite_unit_ids: [],\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 filtersLoaded: false,\n\n // === PROPERTY OPERATIONS ===\n async initializeProperty(propertyId, slug) {\n const { properties } = get();\n if (properties[propertyId]) {\n set({ currentPropertyId: propertyId, currentPropertySlug: slug });\n return;\n }\n set({\n currentPropertyId: propertyId,\n currentPropertySlug: slug,\n properties: {\n ...properties,\n [propertyId]: {\n id: propertyId,\n slug,\n tourContactedOn: null,\n viewedUnits: [],\n questionnaireResults: null,\n tourContactData: null,\n },\n },\n });\n },\n\n async setCurrentProperty(propertyId, slug) {\n set({\n currentPropertyId: propertyId,\n ...(slug && { currentPropertySlug: slug }),\n });\n },\n\n async setCurrentPropertySlug(slug) {\n set({ currentPropertySlug: slug });\n },\n\n async setHasPreviouslySearched(slug) {\n const { hasPreviouslySearched } = get();\n set({\n hasPreviouslySearched: Array.from(new Set([...hasPreviouslySearched, slug])),\n });\n },\n\n async setFavoriteUnitIds(unitIds) {\n set({ favorite_unit_ids: unitIds });\n },\n\n async toggleFavorite(unitId) {\n const { favorite_unit_ids } = get();\n const isFavorited = favorite_unit_ids.includes(unitId);\n set({\n favorite_unit_ids: isFavorited\n ? favorite_unit_ids.filter((id: string) => id !== unitId)\n : [...favorite_unit_ids, unitId],\n });\n },\n\n async markUnitAsViewed(unitId, url) {\n window.open(url, \"_blank\", \"noopener,noreferrer\");\n const today = new Date();\n const formattedDate = `${String(today.getMonth() + 1).padStart(2, \"0\")}/${String(today.getDate()).padStart(2, \"0\")}`;\n const { currentPropertyId, properties } = get();\n if (!currentPropertyId || !properties[currentPropertyId]) return;\n const property = properties[currentPropertyId];\n set({\n properties: {\n ...properties,\n [currentPropertyId]: {\n ...property,\n viewedUnits: [\n ...property.viewedUnits.filter((u: any) => u.unitId !== unitId),\n { unitId, viewedDate: formattedDate },\n ],\n },\n },\n });\n },\n\n async setTourContactedOn() {\n const { currentPropertyId, properties } = get();\n if (!currentPropertyId || !properties[currentPropertyId]) return;\n set({\n properties: {\n ...properties,\n [currentPropertyId]: {\n ...properties[currentPropertyId],\n tourContactedOn: new Date().toISOString(),\n },\n },\n });\n },\n\n async getTourContactedOn() {\n const { currentPropertyId, properties } = get();\n if (!currentPropertyId) return null;\n return properties[currentPropertyId]?.tourContactedOn ?? null;\n },\n\n async setQuestionnaireResults(results) {\n const { currentPropertyId, properties } = get();\n if (!currentPropertyId || !properties[currentPropertyId]) return;\n set({\n properties: {\n ...properties,\n [currentPropertyId]: { ...properties[currentPropertyId], questionnaireResults: results },\n },\n });\n },\n\n async setTourContactData(data) {\n const { currentPropertyId, properties } = get();\n if (!currentPropertyId || !properties[currentPropertyId]) return;\n set({\n properties: {\n ...properties,\n [currentPropertyId]: { ...properties[currentPropertyId], tourContactData: data },\n },\n });\n },\n\n async setUnitResults(units: unknown) {\n const collection = Array.isArray(units)\n ? units\n : units && typeof units === \"object\"\n ? Object.values(units as Record<string, unknown>)\n : [];\n const validatedUnits: Unit[] = [];\n collection.forEach((unit: unknown, index: number) => {\n const parsed = validate(UnitSchema, unit, `unitResults[${index}]`);\n if (parsed) validatedUnits.push(parsed as Unit);\n });\n set({ unitResults: validatedUnits });\n },\n\n async clearUnitResults() {\n set({ unitResults: [] });\n },\n\n // === FILTER OPERATIONS ===\n async setFilters(filters) {\n const { filters: current } = get();\n set({ filters: { ...current, ...filters } });\n },\n\n async setTempFilters(filters) {\n const { tempFilters } = get();\n set({ tempFilters: { ...tempFilters, ...filters } });\n },\n\n async setFiltersToDefault() {\n set({ filters: { ...defaultFilters } });\n },\n\n async setApiFilters(filters) {\n const { apiFilters } = get();\n set({ apiFilters: { ...apiFilters, ...filters } });\n },\n\n async handleTempFilterChange(key, value) {\n const { tempFilters } = get();\n set({ tempFilters: { ...tempFilters, [key]: value } });\n },\n\n async submitFilterUpdate() {\n const state = get();\n const apiParams = 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 set({ apiFilters: apiParams });\n options?.onFilterUpdate?.(apiParams);\n },\n\n // === RESULTS AND SORTING ===\n async setResultsMode(mode) {\n set({ resultsMode: mode });\n },\n\n async setSortBy(sortBy) {\n set({ sortBy });\n },\n\n // === QUESTIONNAIRE ===\n async setResolvedQuestionnaireValues(name, values) {\n const { resolvedQuestionnaireValues } = get();\n set({\n resolvedQuestionnaireValues: {\n ...resolvedQuestionnaireValues,\n [name]: values,\n },\n });\n },\n\n // === UTILITY METHODS ===\n async getResultsUrl() {\n const { currentPropertySlug } = get();\n return currentPropertySlug ? `/${currentPropertySlug}/results` : null;\n },\n\n async getCurrentProperty() {\n const { currentPropertyId, properties } = get();\n return currentPropertyId ? properties[currentPropertyId] ?? null : null;\n },\n\n async getPropertyData(propertyId) {\n const { currentPropertyId, properties } = get();\n const id = propertyId ?? currentPropertyId;\n return id ? properties[id] ?? null : null;\n },\n\n // === INTERNAL ===\n async _hydrate() {\n // No-op: state is seeded from API (bootstrap), not from IndexedDB.\n },\n\n async _initialize() {\n // No IndexedDB sync needed. Mark filters as loaded so the UI unblocks.\n set({ filtersLoaded: true });\n },\n };\n };\n}\n\n// Export types for consuming apps\nexport type { UnitData, UserPropertyState, Filters, QueryParams, ResultsMode, SortBy, TourContactData, Unit } from \"../schema\";\n\n// Intentionally no alias exports in vNext; use `createStructuredStore` or `createZustandUnifiedStore` explicitly.\n"],"names":["defaultFilters","createZustandUnifiedStore","options","set","get","propertyId","slug","properties","hasPreviouslySearched","unitIds","unitId","favorite_unit_ids","isFavorited","id","url","today","formattedDate","currentPropertyId","property","u","_a","results","data","units","collection","validatedUnits","unit","index","parsed","validate","UnitSchema","filters","current","tempFilters","apiFilters","key","value","state","apiParams","transformFiltersToUnitsSearchParams","mode","sortBy","name","values","resolvedQuestionnaireValues","currentPropertySlug"],"mappings":"kMA6EMA,EAA0B,CAC9B,kBAAmB,OACnB,aAAc,OACd,WAAY,OACZ,WAAY,MACd,EAMO,SAASC,EAA0BC,EAEvC,CACD,MAAO,CAACC,EAAUC,KACT,CAEL,WAAY,CAAA,EACZ,kBAAmB,KACnB,oBAAqB,KACrB,sBAAuB,CAAA,EACvB,kBAAmB,CAAA,EACnB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EACzB,OAAOJ,EAAKN,EAAWM,CAAE,GAAK,KAAO,IACvC,EAGA,MAAM,UAAW,CAEjB,EAEA,MAAM,aAAc,CAElBV,EAAI,CAAE,cAAe,GAAM,CAC7B,CAAA,EAGN"}
|
|
1
|
+
{"version":3,"file":"zustand-store.cjs","sources":["../../src/adapters/zustand-store.ts"],"sourcesContent":["import { create } from \"zustand\";\nimport { devtools } from \"zustand/middleware\";\nimport { transformFiltersToUnitsSearchParams } from \"../features/filters/transformers\";\nimport type { Filters, QueryParams } from \"../schema\";\n\nexport interface InResiOrmStore {\n currentPropertyId: string | null;\n filters: Filters;\n tempFilters: Filters;\n apiFilters: QueryParams;\n\n setCurrentPropertyId: (propertyId: string) => Promise<void>;\n setTempFilters: (filters: Partial<Filters>) => Promise<void>;\n setFiltersToDefault: () => Promise<void>;\n setApiFilters: (filters: Partial<QueryParams>) => Promise<void>;\n handleTempFilterChange: <K extends keyof Filters>(key: K, value: Filters[K]) => Promise<void>;\n submitFilterUpdate: () => Promise<void>;\n}\n\nconst defaultFilters: Filters = {\n date_availability: undefined,\n qty_bedrooms: undefined,\n base_price: undefined,\n highlights: undefined,\n};\n\nfunction createInResiOrmStore(options?: {\n onFilterUpdate?: (apiParams: QueryParams) => void;\n}) {\n return (set: any, get: any): InResiOrmStore => ({\n currentPropertyId: null,\n filters: { ...defaultFilters },\n tempFilters: { ...defaultFilters },\n apiFilters: { limit: 10, page: 1, sortBy: \"relevance\" },\n\n async setCurrentPropertyId(propertyId) {\n set({ currentPropertyId: propertyId });\n },\n\n async setTempFilters(filters) {\n const { tempFilters } = get();\n set({ tempFilters: { ...tempFilters, ...filters } });\n },\n\n async setFiltersToDefault() {\n set({ filters: { ...defaultFilters } });\n },\n\n async setApiFilters(filters) {\n const { apiFilters } = get();\n set({ apiFilters: { ...apiFilters, ...filters } });\n },\n\n async handleTempFilterChange(key, value) {\n const { tempFilters } = get();\n set({ tempFilters: { ...tempFilters, [key]: value } });\n },\n\n async submitFilterUpdate() {\n const state = get();\n const sortBy = state.apiFilters.sortBy;\n const apiParams = transformFiltersToUnitsSearchParams(\n {\n ...state.filters,\n limit: state.apiFilters.limit,\n page: state.apiFilters.page,\n sortBy,\n },\n {\n defaultLimit: state.apiFilters.limit,\n defaultPage: state.apiFilters.page,\n defaultSort: sortBy,\n },\n );\n set({ apiFilters: apiParams });\n options?.onFilterUpdate?.(apiParams);\n },\n });\n}\n\nexport const useInResiStore = create<InResiOrmStore>()(\n devtools(createInResiOrmStore(), { name: \"inResi-orm-store\" })\n);\n\n"],"names":["defaultFilters","createInResiOrmStore","options","set","get","propertyId","filters","tempFilters","apiFilters","key","value","state","sortBy","apiParams","transformFiltersToUnitsSearchParams","useInResiStore","create","devtools"],"mappings":"6LAmBMA,EAA0B,CAC9B,kBAAmB,OACnB,aAAc,OACd,WAAY,OACZ,WAAY,MACd,EAEA,SAASC,EAAqBC,EAE3B,CACD,MAAO,CAACC,EAAUC,KAA8B,CAC9C,kBAAmB,KACnB,QAAS,CAAE,GAAGJ,CAAA,EACd,YAAa,CAAE,GAAGA,CAAA,EAClB,WAAY,CAAE,MAAO,GAAI,KAAM,EAAG,OAAQ,WAAA,EAE1C,MAAM,qBAAqBK,EAAY,CACrCF,EAAI,CAAE,kBAAmBE,EAAY,CACvC,EAEA,MAAM,eAAeC,EAAS,CAC5B,KAAM,CAAE,YAAAC,CAAA,EAAgBH,EAAA,EACxBD,EAAI,CAAE,YAAa,CAAE,GAAGI,EAAa,GAAGD,CAAA,EAAW,CACrD,EAEA,MAAM,qBAAsB,CAC1BH,EAAI,CAAE,QAAS,CAAE,GAAGH,CAAA,EAAkB,CACxC,EAEA,MAAM,cAAcM,EAAS,CAC3B,KAAM,CAAE,WAAAE,CAAA,EAAeJ,EAAA,EACvBD,EAAI,CAAE,WAAY,CAAE,GAAGK,EAAY,GAAGF,CAAA,EAAW,CACnD,EAEA,MAAM,uBAAuBG,EAAKC,EAAO,CACvC,KAAM,CAAE,YAAAH,CAAA,EAAgBH,EAAA,EACxBD,EAAI,CAAE,YAAa,CAAE,GAAGI,EAAa,CAACE,CAAG,EAAGC,CAAA,EAAS,CACvD,EAEA,MAAM,oBAAqB,CACzB,MAAMC,EAAQP,EAAA,EACRQ,EAASD,EAAM,WAAW,OAC1BE,EAAYC,EAAAA,oCAChB,CACE,GAAGH,EAAM,QACT,MAAOA,EAAM,WAAW,MACxB,KAAMA,EAAM,WAAW,KACvB,OAAAC,CAAA,EAEF,CACE,aAAcD,EAAM,WAAW,MAC/B,YAAaA,EAAM,WAAW,KAC9B,YAAaC,CAAA,CACf,EAEFT,EAAI,CAAE,WAAYU,EAAW,CAE/B,CAAA,EAEJ,CAEO,MAAME,EAAiBC,EAAAA,OAAA,EAC5BC,EAAAA,SAAShB,EAAA,EAAwB,CAAE,KAAM,mBAAoB,CAC/D"}
|
|
@@ -1,51 +1,30 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export interface
|
|
3
|
-
properties: Record<string, UserPropertyState>;
|
|
1
|
+
import type { Filters, QueryParams } from "../schema";
|
|
2
|
+
export interface InResiOrmStore {
|
|
4
3
|
currentPropertyId: string | null;
|
|
5
|
-
currentPropertySlug: string | null;
|
|
6
|
-
hasPreviouslySearched: string[];
|
|
7
|
-
favorite_unit_ids: string[];
|
|
8
|
-
unitResults: Unit[];
|
|
9
4
|
filters: Filters;
|
|
10
5
|
tempFilters: Filters;
|
|
11
6
|
apiFilters: QueryParams;
|
|
12
|
-
|
|
13
|
-
resolvedQuestionnaireValues: Record<string, string[]>;
|
|
14
|
-
sortBy: SortBy;
|
|
15
|
-
filtersLoaded: boolean;
|
|
16
|
-
initializeProperty: (propertyId: string, slug: string) => Promise<void>;
|
|
17
|
-
setCurrentProperty: (propertyId: string, slug?: string) => Promise<void>;
|
|
18
|
-
setCurrentPropertySlug: (slug: string) => Promise<void>;
|
|
19
|
-
setHasPreviouslySearched: (slug: string) => Promise<void>;
|
|
20
|
-
setFavoriteUnitIds: (unitIds: string[]) => Promise<void>;
|
|
21
|
-
toggleFavorite: (unitId: string) => Promise<void>;
|
|
22
|
-
markUnitAsViewed: (unitId: string, url: string) => Promise<void>;
|
|
23
|
-
setTourContactedOn: () => Promise<void>;
|
|
24
|
-
getTourContactedOn: () => Promise<string | null>;
|
|
25
|
-
setQuestionnaireResults: (results: unknown) => Promise<void>;
|
|
26
|
-
setTourContactData: (data: TourContactData) => Promise<void>;
|
|
27
|
-
setUnitResults: (units: unknown) => Promise<void>;
|
|
28
|
-
clearUnitResults: () => Promise<void>;
|
|
29
|
-
setFilters: (filters: Partial<Filters>) => Promise<void>;
|
|
7
|
+
setCurrentPropertyId: (propertyId: string) => Promise<void>;
|
|
30
8
|
setTempFilters: (filters: Partial<Filters>) => Promise<void>;
|
|
31
9
|
setFiltersToDefault: () => Promise<void>;
|
|
32
10
|
setApiFilters: (filters: Partial<QueryParams>) => Promise<void>;
|
|
33
11
|
handleTempFilterChange: <K extends keyof Filters>(key: K, value: Filters[K]) => Promise<void>;
|
|
34
12
|
submitFilterUpdate: () => Promise<void>;
|
|
35
|
-
setResultsMode: (mode: ResultsMode) => Promise<void>;
|
|
36
|
-
setSortBy: (sortBy: SortBy) => Promise<void>;
|
|
37
|
-
setResolvedQuestionnaireValues: (name: string, values: string[]) => Promise<void>;
|
|
38
|
-
getResultsUrl: () => Promise<string | null>;
|
|
39
|
-
getCurrentProperty: () => Promise<UserPropertyState | null>;
|
|
40
|
-
getPropertyData: (propertyId?: string) => Promise<UserPropertyState | null>;
|
|
41
|
-
_hydrate: () => Promise<void>;
|
|
42
|
-
_initialize: () => Promise<void>;
|
|
43
13
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
})
|
|
51
|
-
|
|
14
|
+
export declare const useInResiStore: import("zustand").UseBoundStore<Omit<import("zustand").StoreApi<InResiOrmStore>, "setState" | "devtools"> & {
|
|
15
|
+
setState(partial: InResiOrmStore | Partial<InResiOrmStore> | ((state: InResiOrmStore) => InResiOrmStore | Partial<InResiOrmStore>), replace?: false | undefined, action?: (string | {
|
|
16
|
+
[x: string]: unknown;
|
|
17
|
+
[x: number]: unknown;
|
|
18
|
+
[x: symbol]: unknown;
|
|
19
|
+
type: string;
|
|
20
|
+
}) | undefined): void;
|
|
21
|
+
setState(state: InResiOrmStore | ((state: InResiOrmStore) => InResiOrmStore), replace: true, action?: (string | {
|
|
22
|
+
[x: string]: unknown;
|
|
23
|
+
[x: number]: unknown;
|
|
24
|
+
[x: symbol]: unknown;
|
|
25
|
+
type: string;
|
|
26
|
+
}) | undefined): void;
|
|
27
|
+
devtools: {
|
|
28
|
+
cleanup: () => void;
|
|
29
|
+
};
|
|
30
|
+
}>;
|