@superbright/indexeddb-orm 0.1.5 → 0.1.7

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/dist/schema.d.ts CHANGED
@@ -74,7 +74,7 @@ export declare const QueryParamsSchema: z.ZodObject<{
74
74
  export type QueryParams = z.infer<typeof QueryParamsSchema>;
75
75
  export declare const ResultsModeEnum: z.ZodEnum<["all", "bestFit", "closestMatch", "favorites", "loading"]>;
76
76
  export type ResultsMode = z.infer<typeof ResultsModeEnum>;
77
- export declare const SortByEnum: z.ZodEnum<["relevance", "newest", "priceLowToHigh", "priceHighToLow"]>;
77
+ export declare const SortByEnum: z.ZodEnum<["relevance", "newest", "cost_low_to_high", "cost_high_to_low"]>;
78
78
  export type SortBy = z.infer<typeof SortByEnum>;
79
79
  export declare const AppStoreDataSchema: z.ZodObject<{
80
80
  data: z.ZodRecord<z.ZodString, z.ZodObject<{
@@ -144,7 +144,7 @@ export declare const AppStoreDataSchema: z.ZodObject<{
144
144
  resultsMode: z.ZodEnum<["all", "bestFit", "closestMatch", "favorites", "loading"]>;
145
145
  propertySlug: z.ZodNullable<z.ZodString>;
146
146
  resolvedQuestionnaireValues: z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString, "many">>;
147
- sortBy: z.ZodEnum<["relevance", "newest", "priceLowToHigh", "priceHighToLow"]>;
147
+ sortBy: z.ZodEnum<["relevance", "newest", "cost_low_to_high", "cost_high_to_low"]>;
148
148
  }, "strip", z.ZodTypeAny, {
149
149
  data: Record<string, {
150
150
  isFavorite?: boolean | undefined;
@@ -173,7 +173,7 @@ export declare const AppStoreDataSchema: z.ZodObject<{
173
173
  resultsMode: "all" | "bestFit" | "closestMatch" | "favorites" | "loading";
174
174
  propertySlug: string | null;
175
175
  resolvedQuestionnaireValues: Record<string, string[]>;
176
- sortBy: "relevance" | "newest" | "priceLowToHigh" | "priceHighToLow";
176
+ sortBy: "relevance" | "newest" | "cost_low_to_high" | "cost_high_to_low";
177
177
  }, {
178
178
  data: Record<string, {
179
179
  isFavorite?: boolean | undefined;
@@ -202,7 +202,7 @@ export declare const AppStoreDataSchema: z.ZodObject<{
202
202
  resultsMode: "all" | "bestFit" | "closestMatch" | "favorites" | "loading";
203
203
  propertySlug: string | null;
204
204
  resolvedQuestionnaireValues: Record<string, string[]>;
205
- sortBy: "relevance" | "newest" | "priceLowToHigh" | "priceHighToLow";
205
+ sortBy: "relevance" | "newest" | "cost_low_to_high" | "cost_high_to_low";
206
206
  }>;
207
207
  export type AppStoreData = z.infer<typeof AppStoreDataSchema>;
208
208
  export declare const UnitSchema: z.ZodObject<{
@@ -2615,7 +2615,7 @@ export declare const UnifiedStoreDataSchema: z.ZodObject<{
2615
2615
  }>;
2616
2616
  resultsMode: z.ZodEnum<["all", "bestFit", "closestMatch", "favorites", "loading"]>;
2617
2617
  resolvedQuestionnaireValues: z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString, "many">>;
2618
- sortBy: z.ZodEnum<["relevance", "newest", "priceLowToHigh", "priceHighToLow"]>;
2618
+ sortBy: z.ZodEnum<["relevance", "newest", "cost_low_to_high", "cost_high_to_low"]>;
2619
2619
  }, "strip", z.ZodTypeAny, {
2620
2620
  filters: {
2621
2621
  availability?: string | number | boolean | Record<string, unknown> | (string | number | boolean | Record<string, unknown>)[] | null | undefined;
@@ -2639,7 +2639,7 @@ export declare const UnifiedStoreDataSchema: z.ZodObject<{
2639
2639
  };
2640
2640
  resultsMode: "all" | "bestFit" | "closestMatch" | "favorites" | "loading";
2641
2641
  resolvedQuestionnaireValues: Record<string, string[]>;
2642
- sortBy: "relevance" | "newest" | "priceLowToHigh" | "priceHighToLow";
2642
+ sortBy: "relevance" | "newest" | "cost_low_to_high" | "cost_high_to_low";
2643
2643
  hasPreviouslySearched: string[];
2644
2644
  properties: Record<string, {
2645
2645
  id: string;
@@ -2769,7 +2769,7 @@ export declare const UnifiedStoreDataSchema: z.ZodObject<{
2769
2769
  };
2770
2770
  resultsMode: "all" | "bestFit" | "closestMatch" | "favorites" | "loading";
2771
2771
  resolvedQuestionnaireValues: Record<string, string[]>;
2772
- sortBy: "relevance" | "newest" | "priceLowToHigh" | "priceHighToLow";
2772
+ sortBy: "relevance" | "newest" | "cost_low_to_high" | "cost_high_to_low";
2773
2773
  hasPreviouslySearched: string[];
2774
2774
  properties: Record<string, {
2775
2775
  id: string;
@@ -1,40 +1,209 @@
1
1
  import type { ZodObject, ZodTypeAny } from "zod";
2
2
  import { type UnifiedStoreData, type UserPropertyState, type Filters, type QueryParams, type ResultsMode, type SortBy, type TourContactData } from "../schema";
3
3
  export declare class UnifiedStore {
4
+ /**
5
+ * Resolves the persisted unified store snapshot, coercing legacy shapes into the latest schema
6
+ * and sanitizing invalid entries where possible.
7
+ */
4
8
  private getState;
9
+ /**
10
+ * Applies an updater function to the current store state, validates the result, and persists it.
11
+ *
12
+ * @param updater - Pure function that maps the current state to the next state.
13
+ */
5
14
  private setState;
15
+ /**
16
+ * Polls the persisted state until a current property pointer is available or the timeout elapses.
17
+ *
18
+ * @param timeoutMs - Maximum time in milliseconds to wait before failing.
19
+ * @returns The active property ID once it becomes available.
20
+ * @throws Error if the property pointer is not set before the timeout expires.
21
+ */
22
+ private waitForCurrentProperty;
23
+ /**
24
+ * Ensures a property entry exists and registers it as the current property.
25
+ *
26
+ * @param propertyId - Identifier used to track the property.
27
+ * @param slug - Canonical slug associated with the property.
28
+ */
6
29
  initializeProperty(propertyId: string | number, slug: string): Promise<void>;
30
+ /**
31
+ * Persists a collection of units after validating each entry against the provided schema.
32
+ *
33
+ * @param units - Raw units collection returned by an API call.
34
+ * @param schema - Optional override schema when the default `UnitSchema` is not sufficient.
35
+ */
7
36
  setUnitResults(units: unknown, schema?: ZodTypeAny): Promise<void>;
37
+ /**
38
+ * Clears the cached unit results array.
39
+ */
8
40
  clearUnitResults(): Promise<void>;
41
+ /**
42
+ * Replaces the persisted property payload with validated data.
43
+ *
44
+ * @param propertyId - ID of the property to mutate.
45
+ * @param data - New property payload.
46
+ * @param schema - Optional schema override used for validation.
47
+ */
9
48
  setPropertyData(propertyId: string | number, data: unknown, schema?: ZodObject<any, any, any, any, any>): Promise<void>;
49
+ /**
50
+ * Merges partial property data into the persisted payload with validation safeguards.
51
+ *
52
+ * @param propertyId - ID of the property to update.
53
+ * @param partial - Partial payload to merge.
54
+ * @param schema - Optional schema override for validation.
55
+ */
10
56
  mergePropertyData(propertyId: string | number, partial: unknown, schema?: ZodObject<any, any, any, any, any>): Promise<void>;
57
+ /**
58
+ * Inserts or updates a property entry from an API payload, enforcing schema validation.
59
+ *
60
+ * @param apiProperty - Raw property object returned by an API.
61
+ * @param schema - Optional schema override.
62
+ */
11
63
  upsertPropertyFromApi(apiProperty: unknown, schema?: ZodTypeAny): Promise<void>;
64
+ /**
65
+ * Marks the provided property as current and optionally updates the slug.
66
+ *
67
+ * @param propertyId - Property identifier to focus.
68
+ * @param slug - Optional slug override.
69
+ */
12
70
  setCurrentProperty(propertyId: string | number, slug?: string): Promise<void>;
71
+ /**
72
+ * Updates the slug for the current property selection.
73
+ *
74
+ * @param slug - New slug to persist.
75
+ */
13
76
  setCurrentPropertySlug(slug: string): Promise<void>;
77
+ /**
78
+ * Adds a slug to the `hasPreviouslySearched` list without duplicating existing entries.
79
+ *
80
+ * @param slug - Slug to record.
81
+ */
14
82
  setHasPreviouslySearched(slug: string): Promise<void>;
83
+ /**
84
+ * Toggles a unit's favorite state for the currently active property.
85
+ *
86
+ * @param unitId - Unit identifier to toggle.
87
+ */
15
88
  toggleFavorite(unitId: string): Promise<void>;
89
+ /**
90
+ * Records the most recent view date for a unit and opens the unit URL in the browser when available.
91
+ *
92
+ * @param unitId - Identifier of the viewed unit.
93
+ * @param slug - Property slug used to construct the URL.
94
+ */
16
95
  markUnitAsViewed(unitId: string, slug: string): Promise<void>;
96
+ /**
97
+ * Stamps the current property with the moment the tour outreach occurred.
98
+ */
17
99
  setTourContactedOn(): Promise<void>;
100
+ /**
101
+ * Reads the stored tour contact timestamp for the current property.
102
+ *
103
+ * @returns ISO string or null when no timestamp exists.
104
+ */
18
105
  getTourContactedOn(): Promise<string | null>;
106
+ /**
107
+ * Persists questionnaire results captured for the current property.
108
+ *
109
+ * @param results - Arbitrary questionnaire data.
110
+ */
19
111
  setQuestionnaireResults(results: unknown): Promise<void>;
112
+ /**
113
+ * Persists structured tour contact preferences for the active property. The method waits until
114
+ * a current property is available, allowing callers to invoke it before initialization completes.
115
+ *
116
+ * @param data - Contact preferences captured from the UI.
117
+ */
20
118
  setTourContactData(data: TourContactData): Promise<void>;
119
+ /**
120
+ * Merges the provided filter values into the committed filter state.
121
+ *
122
+ * @param filters - Partial filter payload to apply.
123
+ */
21
124
  setFilters(filters: Partial<Filters>): Promise<void>;
125
+ /**
126
+ * Updates the transient filters used for in-progress UI interactions.
127
+ *
128
+ * @param filters - Partial staging filter payload.
129
+ */
22
130
  setTempFilters(filters: Partial<Filters>): Promise<void>;
131
+ /**
132
+ * Resets the committed filters to their default values.
133
+ */
23
134
  setFiltersToDefault(): Promise<void>;
135
+ /**
136
+ * Merges partial values into the API filters payload used for network requests.
137
+ *
138
+ * @param filters - Partial query parameters to persist.
139
+ */
24
140
  setApiFilters(filters: Partial<QueryParams>): Promise<void>;
141
+ /**
142
+ * Updates a single temporary filter field without touching the rest of the staged filters.
143
+ *
144
+ * @param key - Filter key to mutate.
145
+ * @param value - New value to assign.
146
+ */
25
147
  handleTempFilterChange<K extends keyof Filters>(key: K, value: Filters[K]): Promise<void>;
148
+ /**
149
+ * Normalizes the committed filters into API-ready structures and persists the result.
150
+ */
26
151
  submitFilterUpdate(): Promise<void>;
152
+ /**
153
+ * Persists the selected results mode (e.g. "all" or "favorites").
154
+ *
155
+ * @param mode - Mode identifier to store.
156
+ */
27
157
  setResultsMode(mode: ResultsMode): Promise<void>;
158
+ /**
159
+ * Persists the currently selected sort option.
160
+ *
161
+ * @param sortBy - Sort identifier.
162
+ */
28
163
  setSortBy(sortBy: SortBy): Promise<void>;
164
+ /**
165
+ * Stores resolved questionnaire answers keyed by questionnaire name.
166
+ *
167
+ * @param name - Questionnaire identifier.
168
+ * @param values - Selected option values.
169
+ */
29
170
  setResolvedQuestionnaireValues(name: string, values: string[]): Promise<void>;
171
+ /**
172
+ * Returns convenience state for a unit within the current property.
173
+ *
174
+ * @param unitId - Identifier of the unit to inspect.
175
+ * @returns Favorite flag and last viewed date.
176
+ */
30
177
  getUnitState(unitId: string): Promise<{
31
178
  isFavorite: boolean;
32
179
  viewedDate: string;
33
180
  }>;
181
+ /**
182
+ * Builds a canonical results URL based on the current property slug.
183
+ *
184
+ * @returns Relative results URL or null when no property is selected.
185
+ */
34
186
  getResultsUrl(): Promise<string | null>;
187
+ /**
188
+ * Retrieves the currently selected property entry.
189
+ *
190
+ * @returns Property state or null when unset.
191
+ */
35
192
  getCurrentProperty(): Promise<UserPropertyState | null>;
193
+ /**
194
+ * Retrieves property data for a specific property or defaults to the current property.
195
+ *
196
+ * @param propertyId - Optional property identifier to fetch.
197
+ * @returns Property state or null when unavailable.
198
+ */
36
199
  getPropertyData(propertyId?: string | number): Promise<UserPropertyState | null>;
200
+ /**
201
+ * Reads and returns the full validated unified store state.
202
+ */
37
203
  getFullState(): Promise<UnifiedStoreData>;
204
+ /**
205
+ * Hydrates the store with the default scaffold when no data has been persisted yet.
206
+ */
38
207
  initialize(): Promise<void>;
39
208
  }
40
209
  export declare const store: UnifiedStore;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superbright/indexeddb-orm",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "Vite + TypeScript starter for an IndexedDB ORM (Dexie + Zod) with playground.",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",
@@ -20,20 +20,29 @@
20
20
  ],
21
21
  "dependencies": {
22
22
  "dexie": "^4.0.8",
23
+ "mixpanel-browser": "^2.67.0",
23
24
  "zod": "^3.23.8"
24
25
  },
25
26
  "devDependencies": {
26
27
  "@types/node": "^20.12.7",
28
+ "@types/react": "^18.3.3",
27
29
  "concurrently": "^9.0.0",
30
+ "docusaurus-plugin-typedoc": "^1.4.2",
28
31
  "fake-indexeddb": "^5.0.2",
29
32
  "prettier": "^3.6.2",
30
33
  "prettier-plugin-packagejson": "^2.5.19",
34
+ "react": "^18.3.1",
31
35
  "rimraf": "^5.0.5",
36
+ "typedoc": "^0.28.14",
37
+ "typedoc-plugin-markdown": "^4.9.0",
32
38
  "typescript": "^5.4.5",
33
39
  "vite": "^5.4.0",
34
40
  "vitest": "^2.0.5",
35
41
  "zustand": "^5.0.8"
36
42
  },
43
+ "peerDependencies": {
44
+ "react": "^18.0.0"
45
+ },
37
46
  "scripts": {
38
47
  "clean": "rimraf dist",
39
48
  "build": "pnpm clean && vite build && tsc -p tsconfig.build.json",