@superbright/indexeddb-orm 0.1.4 β 0.1.6
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 +16 -14
- package/dist/adapters/dexie.d.ts +14 -0
- package/dist/adapters/structured-store.d.ts +44 -0
- package/dist/adapters/zustand-store.d.ts +54 -0
- package/dist/api/favorites.d.ts +4 -0
- package/dist/api/properties.d.ts +22 -0
- package/dist/api/users.d.ts +5 -0
- package/dist/db.d.ts +15 -0
- package/dist/debug.d.ts +2 -0
- package/dist/errors.d.ts +8 -0
- package/dist/features/analytics/MixpanelProvider.d.ts +9 -0
- package/dist/features/analytics/analytics.d.ts +582 -0
- package/dist/features/analytics/generateUserUUID.d.ts +1 -0
- package/dist/features/analytics/index.d.ts +3 -0
- package/dist/features/units/transformers.d.ts +75 -0
- package/dist/index.cjs +65 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +15 -0
- package/dist/index.mjs +14487 -1073
- package/dist/index.mjs.map +1 -1
- package/dist/schema.d.ts +2880 -0
- package/dist/storage.d.ts +14 -0
- package/dist/stores/store.d.ts +211 -0
- package/dist/units/favorites.d.ts +7 -0
- package/dist/validation.d.ts +7 -0
- package/package.json +10 -1
package/README.md
CHANGED
|
@@ -176,23 +176,25 @@ const unitState = useUnitState("unit-123");
|
|
|
176
176
|
|
|
177
177
|
### Direct Store Methods
|
|
178
178
|
|
|
179
|
-
For advanced use cases,
|
|
179
|
+
For advanced use cases, the core store methods are available. Prefer the structured actions shown above for most scenarios.
|
|
180
180
|
|
|
181
181
|
```typescript
|
|
182
182
|
// Property operations
|
|
183
|
-
await store.getCurrentProperty()
|
|
184
|
-
await store.setCurrentProperty(propertyId, slug)
|
|
185
|
-
await store.getPropertyData(propertyId)
|
|
186
|
-
|
|
187
|
-
// Unit results
|
|
188
|
-
await store.setUnitResults(transformedUnits.hits)
|
|
189
|
-
await store.clearUnitResults()
|
|
190
|
-
|
|
191
|
-
//
|
|
192
|
-
await store.
|
|
193
|
-
await store.
|
|
183
|
+
await store.getCurrentProperty();
|
|
184
|
+
await store.setCurrentProperty(propertyId, slug);
|
|
185
|
+
await store.getPropertyData(propertyId);
|
|
186
|
+
|
|
187
|
+
// Unit results cache
|
|
188
|
+
await store.setUnitResults(transformedUnits.hits);
|
|
189
|
+
await store.clearUnitResults();
|
|
190
|
+
|
|
191
|
+
// Filters
|
|
192
|
+
await store.setFilters({ bedrooms: [1, 2] });
|
|
193
|
+
await store.setTempFilters({ cost: 2500 });
|
|
194
|
+
await store.submitFilterUpdate();
|
|
194
195
|
```
|
|
195
196
|
|
|
197
|
+
|
|
196
198
|
## π οΈ Development
|
|
197
199
|
|
|
198
200
|
### Local Development Setup
|
|
@@ -232,6 +234,7 @@ pnpm dev
|
|
|
232
234
|
- **π Property Management**: Create properties, set current property, retrieve property data
|
|
233
235
|
- **β Unit Actions**: Toggle favorites, mark units as viewed, get unit state
|
|
234
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
|
|
235
238
|
- **π Questionnaire & Tours**: Set questionnaire results, manage tour contact data
|
|
236
239
|
- **π Real-time State View**: Live view of database state and action logs
|
|
237
240
|
- **π οΈ Developer Tools Integration**: Inspect IndexedDB directly in DevTools β Application β IndexedDB β `inresi-orm`
|
|
@@ -351,8 +354,7 @@ configureValidation("strict"); // "strict" | "warn" | "off"
|
|
|
351
354
|
## π Documentation
|
|
352
355
|
|
|
353
356
|
- [Consuming App Guide](./CONSUMING_APP_GUIDE.md) - Complete integration guide
|
|
354
|
-
- [Migration
|
|
355
|
-
- [Property Store Guide](./docs/property-store.md) - Property-specific usage
|
|
357
|
+
- [Structured Store Migration](./docs/structured-store-migration.md) - Move to the structured API
|
|
356
358
|
- [App Store Guide](./docs/app-store-guide.md) - App state management
|
|
357
359
|
|
|
358
360
|
## π§ Legacy API
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import Dexie, { type Table } from "dexie";
|
|
2
|
+
export interface KV {
|
|
3
|
+
key: string;
|
|
4
|
+
value: unknown;
|
|
5
|
+
}
|
|
6
|
+
export interface OrmDexieTables {
|
|
7
|
+
users: Table<any, string>;
|
|
8
|
+
kv: Table<KV, string>;
|
|
9
|
+
}
|
|
10
|
+
export declare class OrmDexie extends Dexie {
|
|
11
|
+
users: OrmDexieTables["users"];
|
|
12
|
+
kv: OrmDexieTables["kv"];
|
|
13
|
+
constructor(name?: string);
|
|
14
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structured store wrapper (preferred DX)
|
|
3
|
+
*
|
|
4
|
+
* This layer wraps the flat Zustand adapter with domainβgrouped actions
|
|
5
|
+
* for a more discoverable API in apps. It does not add new behavior β
|
|
6
|
+
* it simply organizes calls like:
|
|
7
|
+
* - `property.unit.favorites.toggle` β `toggleFavorite`
|
|
8
|
+
* - `property.unit.viewed.mark` β `markUnitAsViewed`
|
|
9
|
+
* - `filters.set/submit/...` β filter methods
|
|
10
|
+
*/
|
|
11
|
+
import { type ZustandUnifiedStoreState, type Filters, type TourContactData, type QueryParams } from "./zustand-store";
|
|
12
|
+
export interface StructuredStoreActions {
|
|
13
|
+
property: {
|
|
14
|
+
unit: {
|
|
15
|
+
favorites: {
|
|
16
|
+
toggle: (unitId: string) => Promise<void>;
|
|
17
|
+
};
|
|
18
|
+
viewed: {
|
|
19
|
+
mark: (unitId: string, slug: string) => Promise<void>;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
questionnaire: {
|
|
23
|
+
setResults: (results: unknown) => Promise<void>;
|
|
24
|
+
};
|
|
25
|
+
tour: {
|
|
26
|
+
setContactedOn: () => Promise<void>;
|
|
27
|
+
getContactedOn: () => Promise<string | null>;
|
|
28
|
+
setContactData: (data: TourContactData) => Promise<void>;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
filters: {
|
|
32
|
+
set: (filters: Partial<Filters>) => Promise<void>;
|
|
33
|
+
setTemp: (filters: Partial<Filters>) => Promise<void>;
|
|
34
|
+
setToDefault: () => Promise<void>;
|
|
35
|
+
commitTemp: <K extends keyof Filters>(key: K, defaultValue: Filters[K]) => Promise<void>;
|
|
36
|
+
commitAvailability: () => Promise<void>;
|
|
37
|
+
submit: () => Promise<void>;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
export declare function createStructuredStoreActions(store: ZustandUnifiedStoreState, get?: () => ZustandUnifiedStoreState): StructuredStoreActions;
|
|
41
|
+
export type StructuredStore = ZustandUnifiedStoreState & StructuredStoreActions;
|
|
42
|
+
export declare function createStructuredStore(options?: {
|
|
43
|
+
onFilterUpdate?: (apiParams: QueryParams) => void;
|
|
44
|
+
}): (set: any, get: any) => StructuredStore;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { UserPropertyState, Filters, QueryParams, ResultsMode, SortBy, TourContactData, Unit } from "../schema";
|
|
2
|
+
export interface ZustandUnifiedStoreState {
|
|
3
|
+
properties: Record<string, UserPropertyState>;
|
|
4
|
+
currentPropertyId: string | null;
|
|
5
|
+
currentPropertySlug: string | null;
|
|
6
|
+
hasPreviouslySearched: string[];
|
|
7
|
+
unitResults: Unit[];
|
|
8
|
+
filters: Filters;
|
|
9
|
+
tempFilters: Filters;
|
|
10
|
+
apiFilters: QueryParams;
|
|
11
|
+
resultsMode: ResultsMode;
|
|
12
|
+
resolvedQuestionnaireValues: Record<string, string[]>;
|
|
13
|
+
sortBy: SortBy;
|
|
14
|
+
filtersLoaded: boolean;
|
|
15
|
+
initializeProperty: (propertyId: string, slug: string) => Promise<void>;
|
|
16
|
+
setCurrentProperty: (propertyId: string, slug?: string) => Promise<void>;
|
|
17
|
+
setCurrentPropertySlug: (slug: string) => Promise<void>;
|
|
18
|
+
setHasPreviouslySearched: (slug: string) => Promise<void>;
|
|
19
|
+
toggleFavorite: (unitId: string) => Promise<void>;
|
|
20
|
+
markUnitAsViewed: (unitId: string, slug: string) => Promise<void>;
|
|
21
|
+
setTourContactedOn: () => Promise<void>;
|
|
22
|
+
getTourContactedOn: () => Promise<string | null>;
|
|
23
|
+
setQuestionnaireResults: (results: unknown) => Promise<void>;
|
|
24
|
+
setTourContactData: (data: TourContactData) => Promise<void>;
|
|
25
|
+
setUnitResults: (units: unknown) => Promise<void>;
|
|
26
|
+
clearUnitResults: () => Promise<void>;
|
|
27
|
+
setFilters: (filters: Partial<Filters>) => Promise<void>;
|
|
28
|
+
setTempFilters: (filters: Partial<Filters>) => Promise<void>;
|
|
29
|
+
setFiltersToDefault: () => Promise<void>;
|
|
30
|
+
setApiFilters: (filters: Partial<QueryParams>) => Promise<void>;
|
|
31
|
+
handleTempFilterChange: <K extends keyof Filters>(key: K, value: Filters[K]) => Promise<void>;
|
|
32
|
+
submitFilterUpdate: () => Promise<void>;
|
|
33
|
+
setResultsMode: (mode: ResultsMode) => Promise<void>;
|
|
34
|
+
setSortBy: (sortBy: SortBy) => Promise<void>;
|
|
35
|
+
setResolvedQuestionnaireValues: (name: string, values: string[]) => Promise<void>;
|
|
36
|
+
getUnitState: (unitId: string) => {
|
|
37
|
+
isFavorite: boolean;
|
|
38
|
+
viewedDate: string;
|
|
39
|
+
};
|
|
40
|
+
getResultsUrl: () => Promise<string | null>;
|
|
41
|
+
getCurrentProperty: () => Promise<UserPropertyState | null>;
|
|
42
|
+
getPropertyData: (propertyId?: string) => Promise<UserPropertyState | null>;
|
|
43
|
+
_hydrate: () => Promise<void>;
|
|
44
|
+
_initialize: () => Promise<void>;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* @deprecated For new apps, use `createStructuredStore` from `./structured-store`.
|
|
48
|
+
* This flat adapter remains for migration/advanced cases.
|
|
49
|
+
*/
|
|
50
|
+
export declare function createZustandUnifiedStore(options?: {
|
|
51
|
+
onFilterUpdate?: (apiParams: QueryParams) => void;
|
|
52
|
+
}): (set: any, get: any) => ZustandUnifiedStoreState;
|
|
53
|
+
export declare function createUseUnitState(): (useStore: any) => (unitId: string) => any;
|
|
54
|
+
export type { UnitData, UserPropertyState, Filters, QueryParams, ResultsMode, SortBy, TourContactData, Unit } from "../schema";
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare function getFavoritedUnitsForProperty(propertyId: string | number): Promise<string[]>;
|
|
2
|
+
export declare function setFavoriteUnit(propertyId: string | number, unitId: string, on: boolean): Promise<string[]>;
|
|
3
|
+
export declare function toggleFavoriteUnit(propertyId: string | number, unitId: string): Promise<string[]>;
|
|
4
|
+
export declare function isUnitFavorited(propertyId: string | number, unitId: string): Promise<boolean>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type TourContactData, type UserPropertyState, type PropertyStoreData } from "../schema";
|
|
2
|
+
export type { ViewedUnit, TourContactData, UserPropertyState, PropertyStoreData } from "../schema";
|
|
3
|
+
export declare class PropertyStore {
|
|
4
|
+
private getState;
|
|
5
|
+
private setState;
|
|
6
|
+
setHasPreviouslySearched(slug: string): Promise<void>;
|
|
7
|
+
setTourContactedOn(): Promise<void>;
|
|
8
|
+
getTourContactedOn(): Promise<string | null>;
|
|
9
|
+
setQuestionnaireResults(results: unknown): Promise<void>;
|
|
10
|
+
setTourContactData(data: TourContactData): Promise<void>;
|
|
11
|
+
toggleFavorite(unitId: string): Promise<void>;
|
|
12
|
+
markUnitAsViewed(unitId: string, slug: string): Promise<void>;
|
|
13
|
+
getUnitState(unitId: string): Promise<{
|
|
14
|
+
isFavorite: boolean;
|
|
15
|
+
viewedDate: string;
|
|
16
|
+
}>;
|
|
17
|
+
getPropertyData(propertyId?: string | number): Promise<UserPropertyState | null>;
|
|
18
|
+
getCurrentProperty(): Promise<UserPropertyState | null>;
|
|
19
|
+
getFullState(): Promise<PropertyStoreData>;
|
|
20
|
+
initializeProperty(propertyId: string | number, slug: string): Promise<void>;
|
|
21
|
+
}
|
|
22
|
+
export declare const propertyStore: PropertyStore;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type User } from "../schema";
|
|
2
|
+
export type IdGenerator = () => string;
|
|
3
|
+
export declare const defaultIdGenerator: IdGenerator;
|
|
4
|
+
export declare function ensureUser(gen?: IdGenerator): Promise<User>;
|
|
5
|
+
export declare const getUserUUID: (gen?: IdGenerator) => Promise<string>;
|
package/dist/db.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { OrmDexie } from "./adapters/dexie";
|
|
2
|
+
import { type ValidationMode } from "./validation";
|
|
3
|
+
export type OrmOptions = {
|
|
4
|
+
dbName?: string;
|
|
5
|
+
onReset?: (reason: "incompatible" | "versionchange" | "blocked") => void;
|
|
6
|
+
onError?: (err: unknown) => void;
|
|
7
|
+
validation?: {
|
|
8
|
+
mode?: ValidationMode;
|
|
9
|
+
onIssue?: (ctx: string, details: unknown) => void;
|
|
10
|
+
validateReads?: boolean;
|
|
11
|
+
dropInvalidOnRead?: boolean;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
export declare function getDB(opts?: OrmOptions): Promise<OrmDexie>;
|
|
15
|
+
export declare function resetDB(dbName?: string): Promise<void>;
|
package/dist/debug.d.ts
ADDED
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare class SchemaMismatchError extends Error {
|
|
2
|
+
detail?: unknown | undefined;
|
|
3
|
+
constructor(message: string, detail?: unknown | undefined);
|
|
4
|
+
}
|
|
5
|
+
export declare class OpenDBError extends Error {
|
|
6
|
+
detail?: unknown | undefined;
|
|
7
|
+
constructor(message: string, detail?: unknown | undefined);
|
|
8
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
interface MixpanelProviderProps {
|
|
3
|
+
children: React.ReactNode;
|
|
4
|
+
token?: string;
|
|
5
|
+
envMode?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare const MixpanelProvider: ({ children, token: tokenOverride, envMode, }: MixpanelProviderProps) => import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
export declare const useMixpanel: () => import("mixpanel-browser").OverridedMixpanel;
|
|
9
|
+
export {};
|