@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
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface AsyncStringStorage {
|
|
2
|
+
getItem(name: string): Promise<string | null>;
|
|
3
|
+
setItem(name: string, value: string): Promise<void>;
|
|
4
|
+
removeItem(name: string): Promise<void>;
|
|
5
|
+
}
|
|
6
|
+
type storeKeys = "property" | "user" | "app";
|
|
7
|
+
export declare function kvGet<T>(key: storeKeys): Promise<T | null>;
|
|
8
|
+
export declare function kvSet<T>(key: storeKeys, value: T): Promise<void>;
|
|
9
|
+
export declare function kvRemove(key: storeKeys): Promise<void>;
|
|
10
|
+
export declare function createORMStringStorage(opts?: {
|
|
11
|
+
prefix?: string;
|
|
12
|
+
fallbackToMemory?: boolean;
|
|
13
|
+
}): AsyncStringStorage;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import type { ZodObject, ZodTypeAny } from "zod";
|
|
2
|
+
import { type UnifiedStoreData, type UserPropertyState, type Filters, type QueryParams, type ResultsMode, type SortBy, type TourContactData } from "../schema";
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
36
|
+
setUnitResults(units: unknown, schema?: ZodTypeAny): Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* Clears the cached unit results array.
|
|
39
|
+
*/
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
95
|
+
markUnitAsViewed(unitId: string, slug: string): Promise<void>;
|
|
96
|
+
/**
|
|
97
|
+
* Stamps the current property with the moment the tour outreach occurred.
|
|
98
|
+
*/
|
|
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
|
+
*/
|
|
105
|
+
getTourContactedOn(): Promise<string | null>;
|
|
106
|
+
/**
|
|
107
|
+
* Persists questionnaire results captured for the current property.
|
|
108
|
+
*
|
|
109
|
+
* @param results - Arbitrary questionnaire data.
|
|
110
|
+
*/
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
130
|
+
setTempFilters(filters: Partial<Filters>): Promise<void>;
|
|
131
|
+
/**
|
|
132
|
+
* Resets the committed filters to their default values.
|
|
133
|
+
*/
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
157
|
+
setResultsMode(mode: ResultsMode): Promise<void>;
|
|
158
|
+
/**
|
|
159
|
+
* Persists the currently selected sort option.
|
|
160
|
+
*
|
|
161
|
+
* @param sortBy - Sort identifier.
|
|
162
|
+
*/
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
177
|
+
getUnitState(unitId: string): Promise<{
|
|
178
|
+
isFavorite: boolean;
|
|
179
|
+
viewedDate: string;
|
|
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
|
+
*/
|
|
186
|
+
getResultsUrl(): Promise<string | null>;
|
|
187
|
+
/**
|
|
188
|
+
* Retrieves the currently selected property entry.
|
|
189
|
+
*
|
|
190
|
+
* @returns Property state or null when unset.
|
|
191
|
+
*/
|
|
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
|
+
*/
|
|
199
|
+
getPropertyData(propertyId?: string | number): Promise<UserPropertyState | null>;
|
|
200
|
+
/**
|
|
201
|
+
* Reads and returns the full validated unified store state.
|
|
202
|
+
*/
|
|
203
|
+
getFullState(): Promise<UnifiedStoreData>;
|
|
204
|
+
/**
|
|
205
|
+
* Hydrates the store with the default scaffold when no data has been persisted yet.
|
|
206
|
+
*/
|
|
207
|
+
initialize(): Promise<void>;
|
|
208
|
+
}
|
|
209
|
+
export declare const store: UnifiedStore;
|
|
210
|
+
export { UnifiedStore as Store };
|
|
211
|
+
export type { UserPropertyState, Filters } from "../schema";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
declare const favorites: {
|
|
2
|
+
isFavorite(propertyId: string | number, unitId: string): Promise<boolean>;
|
|
3
|
+
toggle(propertyId: string | number, unitId: string): Promise<string[]>;
|
|
4
|
+
set(propertyId: string | number, unitId: string, on: boolean): Promise<string[]>;
|
|
5
|
+
getAll(propertyId: string | number): Promise<string[]>;
|
|
6
|
+
};
|
|
7
|
+
export { favorites };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { z } from "zod";
|
|
2
|
+
export type ValidationMode = "strict" | "warn" | "silent";
|
|
3
|
+
export declare function configureValidation(opts: {
|
|
4
|
+
mode?: ValidationMode;
|
|
5
|
+
onIssue?: (ctx: string, details: unknown) => void;
|
|
6
|
+
}): void;
|
|
7
|
+
export declare function validate<T>(schema: z.ZodType<T>, value: unknown, ctx: string): T | null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@superbright/indexeddb-orm",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
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",
|