@daltonr/pathwrite-store 0.9.0
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/async-store.d.ts +49 -0
- package/dist/async-store.d.ts.map +1 -0
- package/dist/async-store.js +67 -0
- package/dist/async-store.js.map +1 -0
- package/dist/index.d.ts +138 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +228 -0
- package/dist/index.js.map +1 -0
- package/dist/local-store.d.ts +51 -0
- package/dist/local-store.d.ts.map +1 -0
- package/dist/local-store.js +105 -0
- package/dist/local-store.js.map +1 -0
- package/package.json +51 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { SerializedPathState, PathStore } from "@daltonr/pathwrite-core";
|
|
2
|
+
/**
|
|
3
|
+
* Minimal interface for an async key-value string storage backend.
|
|
4
|
+
* `@react-native-async-storage/async-storage` satisfies this interface directly,
|
|
5
|
+
* as does any other async key-value store with the same shape.
|
|
6
|
+
*/
|
|
7
|
+
export interface AsyncStorageAdapter {
|
|
8
|
+
getItem(key: string): Promise<string | null>;
|
|
9
|
+
setItem(key: string, value: string): Promise<void>;
|
|
10
|
+
removeItem(key: string): Promise<void>;
|
|
11
|
+
/**
|
|
12
|
+
* Return every key currently held in the storage backend.
|
|
13
|
+
* Required by `AsyncStorageStore.list()` and `AsyncStorageStore.clear()`.
|
|
14
|
+
* Implementations that don't need those methods may omit this.
|
|
15
|
+
*/
|
|
16
|
+
getAllKeys?(): Promise<readonly string[]>;
|
|
17
|
+
}
|
|
18
|
+
export interface AsyncStorageStoreOptions {
|
|
19
|
+
/**
|
|
20
|
+
* The async storage backend to use.
|
|
21
|
+
* Pass `AsyncStorage` from `@react-native-async-storage/async-storage`,
|
|
22
|
+
* or any object that satisfies `AsyncStorageAdapter`.
|
|
23
|
+
*/
|
|
24
|
+
storage: AsyncStorageAdapter;
|
|
25
|
+
/**
|
|
26
|
+
* Prefix prepended to every storage key to avoid collisions.
|
|
27
|
+
* Defaults to `"@daltonr/pathwrite:"`.
|
|
28
|
+
*/
|
|
29
|
+
prefix?: string;
|
|
30
|
+
}
|
|
31
|
+
export declare class AsyncStorageStore implements PathStore {
|
|
32
|
+
private prefix;
|
|
33
|
+
private storage;
|
|
34
|
+
constructor(options: AsyncStorageStoreOptions);
|
|
35
|
+
private storageKey;
|
|
36
|
+
save(key: string, state: SerializedPathState): Promise<void>;
|
|
37
|
+
load(key: string): Promise<SerializedPathState | null>;
|
|
38
|
+
delete(key: string): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* Returns every key stored under this store's prefix, decoded back to the
|
|
41
|
+
* original key strings passed to `save()`.
|
|
42
|
+
*/
|
|
43
|
+
list(): Promise<string[]>;
|
|
44
|
+
/**
|
|
45
|
+
* Removes every entry stored under this store's prefix.
|
|
46
|
+
*/
|
|
47
|
+
clear(): Promise<void>;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=async-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"async-store.d.ts","sourceRoot":"","sources":["../src/async-store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAE9E;;;;GAIG;AACH,MAAM,WAAW,mBAAmB;IAClC,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAC7C,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACnD,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACvC;;;;OAIG;IACH,UAAU,CAAC,IAAI,OAAO,CAAC,SAAS,MAAM,EAAE,CAAC,CAAC;CAC3C;AAED,MAAM,WAAW,wBAAwB;IACvC;;;;OAIG;IACH,OAAO,EAAE,mBAAmB,CAAC;IAC7B;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,qBAAa,iBAAkB,YAAW,SAAS;IACjD,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,OAAO,CAAsB;gBAEzB,OAAO,EAAE,wBAAwB;IAK7C,OAAO,CAAC,UAAU;IAIZ,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;IAQ5D,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,GAAG,IAAI,CAAC;IAUtD,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAQxC;;;OAGG;IACG,IAAI,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAiB/B;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAM7B"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
export class AsyncStorageStore {
|
|
2
|
+
prefix;
|
|
3
|
+
storage;
|
|
4
|
+
constructor(options) {
|
|
5
|
+
this.prefix = options.prefix ?? "@daltonr/pathwrite:";
|
|
6
|
+
this.storage = options.storage;
|
|
7
|
+
}
|
|
8
|
+
storageKey(key) {
|
|
9
|
+
return this.prefix + encodeURIComponent(key);
|
|
10
|
+
}
|
|
11
|
+
async save(key, state) {
|
|
12
|
+
try {
|
|
13
|
+
await this.storage.setItem(this.storageKey(key), JSON.stringify(state));
|
|
14
|
+
}
|
|
15
|
+
catch (err) {
|
|
16
|
+
throw err instanceof Error ? err : new Error(String(err));
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
async load(key) {
|
|
20
|
+
try {
|
|
21
|
+
const raw = await this.storage.getItem(this.storageKey(key));
|
|
22
|
+
if (raw === null || raw === undefined)
|
|
23
|
+
return null;
|
|
24
|
+
return JSON.parse(raw);
|
|
25
|
+
}
|
|
26
|
+
catch (err) {
|
|
27
|
+
throw err instanceof Error ? err : new Error(String(err));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
async delete(key) {
|
|
31
|
+
try {
|
|
32
|
+
await this.storage.removeItem(this.storageKey(key));
|
|
33
|
+
}
|
|
34
|
+
catch (err) {
|
|
35
|
+
throw err instanceof Error ? err : new Error(String(err));
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Returns every key stored under this store's prefix, decoded back to the
|
|
40
|
+
* original key strings passed to `save()`.
|
|
41
|
+
*/
|
|
42
|
+
async list() {
|
|
43
|
+
if (!this.storage.getAllKeys) {
|
|
44
|
+
throw new Error("AsyncStorageStore.list() requires the AsyncStorageAdapter to implement getAllKeys(). " +
|
|
45
|
+
"Pass an adapter that supports key enumeration, such as @react-native-async-storage/async-storage.");
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
const allKeys = await this.storage.getAllKeys();
|
|
49
|
+
return Array.from(allKeys)
|
|
50
|
+
.filter((k) => k.startsWith(this.prefix))
|
|
51
|
+
.map((k) => decodeURIComponent(k.slice(this.prefix.length)));
|
|
52
|
+
}
|
|
53
|
+
catch (err) {
|
|
54
|
+
throw err instanceof Error ? err : new Error(String(err));
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Removes every entry stored under this store's prefix.
|
|
59
|
+
*/
|
|
60
|
+
async clear() {
|
|
61
|
+
const keys = await this.list();
|
|
62
|
+
for (const key of keys) {
|
|
63
|
+
await this.delete(key);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=async-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"async-store.js","sourceRoot":"","sources":["../src/async-store.ts"],"names":[],"mappings":"AAiCA,MAAM,OAAO,iBAAiB;IACpB,MAAM,CAAS;IACf,OAAO,CAAsB;IAErC,YAAY,OAAiC;QAC3C,IAAI,CAAC,MAAM,GAAG,OAAO,CAA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**
|
|
2
|
+
* @daltonr/pathwrite-store
|
|
3
|
+
*
|
|
4
|
+
* Persistence adapters and observer utilities for PathEngine state.
|
|
5
|
+
*
|
|
6
|
+
* Stores (implement PathStore):
|
|
7
|
+
* - HttpStore — persists to a REST API
|
|
8
|
+
* - LocalStorageStore — persists to browser localStorage (or any sync key-value adapter)
|
|
9
|
+
* - AsyncStorageStore — persists to any async key-value store (e.g. AsyncStorage on React Native)
|
|
10
|
+
*
|
|
11
|
+
* Observer utilities:
|
|
12
|
+
* - persistence — PathObserver factory; wires any PathStore to an engine's event stream
|
|
13
|
+
* - restoreOrStart — convenience factory for the load/restore-or-start pattern
|
|
14
|
+
*
|
|
15
|
+
* Bring your own store:
|
|
16
|
+
* Implement the PathStore interface (save / load / delete) to use any backend —
|
|
17
|
+
* MongoDB Atlas SDK, SQLite, MMKV, IndexedDB, or anything else.
|
|
18
|
+
*/
|
|
19
|
+
import { PathEngine } from "@daltonr/pathwrite-core";
|
|
20
|
+
import type { SerializedPathState, PathDefinition, PathData, PathObserver, ObserverStrategy, PathStore } from "@daltonr/pathwrite-core";
|
|
21
|
+
export interface HttpStoreOptions {
|
|
22
|
+
/**
|
|
23
|
+
* Base URL for the API. Individual endpoint paths are appended to this.
|
|
24
|
+
* Example: "https://api.example.com" or "/api/wizard"
|
|
25
|
+
*/
|
|
26
|
+
baseUrl: string;
|
|
27
|
+
/** Function that builds the save endpoint URL. Default: `${baseUrl}/state/${key}` */
|
|
28
|
+
saveUrl?: (key: string) => string;
|
|
29
|
+
/** Function that builds the load endpoint URL. Default: `${baseUrl}/state/${key}` */
|
|
30
|
+
loadUrl?: (key: string) => string;
|
|
31
|
+
/** Function that builds the delete endpoint URL. Default: `${baseUrl}/state/${key}` */
|
|
32
|
+
deleteUrl?: (key: string) => string;
|
|
33
|
+
/**
|
|
34
|
+
* Custom headers to include in all requests (e.g. auth tokens).
|
|
35
|
+
* Can be a static object or a function that returns headers (sync or async).
|
|
36
|
+
*/
|
|
37
|
+
headers?: HeadersInit | (() => HeadersInit | Promise<HeadersInit>);
|
|
38
|
+
/** Custom fetch implementation (useful for testing or SSR). Defaults to global fetch. */
|
|
39
|
+
fetch?: typeof fetch;
|
|
40
|
+
/** Called when a request fails. Can be used for logging or error handling. */
|
|
41
|
+
onError?: (error: Error, operation: "save" | "load" | "delete", key: string) => void;
|
|
42
|
+
}
|
|
43
|
+
export declare class HttpStore implements PathStore {
|
|
44
|
+
private options;
|
|
45
|
+
constructor(options: HttpStoreOptions);
|
|
46
|
+
private getHeaders;
|
|
47
|
+
save(key: string, state: SerializedPathState): Promise<void>;
|
|
48
|
+
load(key: string): Promise<SerializedPathState | null>;
|
|
49
|
+
delete(key: string): Promise<void>;
|
|
50
|
+
}
|
|
51
|
+
export interface PersistenceOptions {
|
|
52
|
+
/** The store to persist state to. Any PathStore implementation works. */
|
|
53
|
+
store: PathStore;
|
|
54
|
+
/** Storage key that identifies this path's saved state. */
|
|
55
|
+
key: string;
|
|
56
|
+
/** When to automatically save. Defaults to `"onNext"`. */
|
|
57
|
+
strategy?: ObserverStrategy;
|
|
58
|
+
/**
|
|
59
|
+
* Debounce window in milliseconds. When > 0, rapid events are collapsed into
|
|
60
|
+
* a single save after the window expires. Only useful with `"onEveryChange"`.
|
|
61
|
+
* Defaults to 0 (no debouncing).
|
|
62
|
+
*/
|
|
63
|
+
debounceMs?: number;
|
|
64
|
+
/** Called after every successful save. */
|
|
65
|
+
onSaveSuccess?: () => void;
|
|
66
|
+
/** Called when a save fails. The engine continues regardless. */
|
|
67
|
+
onSaveError?: (error: Error) => void;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Returns a `PathObserver` that automatically persists engine state to the
|
|
71
|
+
* provided store based on the chosen strategy.
|
|
72
|
+
*
|
|
73
|
+
* Works with any PathStore — HttpStore, LocalStorageStore, AsyncStorageStore,
|
|
74
|
+
* or a custom implementation.
|
|
75
|
+
*
|
|
76
|
+
* ```typescript
|
|
77
|
+
* const store = new LocalStorageStore();
|
|
78
|
+
* const engine = new PathEngine({
|
|
79
|
+
* observers: [
|
|
80
|
+
* persistence({ store, key: "user:123:onboarding", strategy: "onNext" }),
|
|
81
|
+
* ],
|
|
82
|
+
* });
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
export declare function persistence(options: PersistenceOptions): PathObserver;
|
|
86
|
+
export interface RestoreOrStartOptions {
|
|
87
|
+
/** The store to load saved state from. Any PathStore implementation works. */
|
|
88
|
+
store: PathStore;
|
|
89
|
+
/** Storage key that identifies this path's saved state. */
|
|
90
|
+
key: string;
|
|
91
|
+
/** Path definition to start when no saved state exists. */
|
|
92
|
+
path: PathDefinition<any>;
|
|
93
|
+
/**
|
|
94
|
+
* Map of all path definitions that may appear in serialized state
|
|
95
|
+
* (active path + any sub-paths). Defaults to `{ [path.id]: path }`.
|
|
96
|
+
*/
|
|
97
|
+
pathDefinitions?: Record<string, PathDefinition<any>>;
|
|
98
|
+
/** Initial data for a fresh (non-restored) start. Defaults to `{}`. */
|
|
99
|
+
initialData?: PathData;
|
|
100
|
+
/**
|
|
101
|
+
* Observers to wire on the engine before the first event fires.
|
|
102
|
+
* Build these explicitly — e.g. `persistence({ store, key })` — and
|
|
103
|
+
* pass them here. `restoreOrStart` does not create any observers itself.
|
|
104
|
+
*/
|
|
105
|
+
observers?: PathObserver[];
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Handles the load/restore-or-start pattern in a single call.
|
|
109
|
+
*
|
|
110
|
+
* Tries to load saved state from the store. If found, restores the engine
|
|
111
|
+
* to the saved position. If not found, starts a fresh path.
|
|
112
|
+
*
|
|
113
|
+
* ```typescript
|
|
114
|
+
* const store = new AsyncStorageStore({ storage: AsyncStorage });
|
|
115
|
+
* const key = "user:123:onboarding";
|
|
116
|
+
*
|
|
117
|
+
* const { engine, restored } = await restoreOrStart({
|
|
118
|
+
* store,
|
|
119
|
+
* key,
|
|
120
|
+
* path: onboardingWizard,
|
|
121
|
+
* initialData: { name: "", email: "" },
|
|
122
|
+
* observers: [
|
|
123
|
+
* persistence({ store, key, strategy: "onNext" }),
|
|
124
|
+
* ],
|
|
125
|
+
* });
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
export declare function restoreOrStart(options: RestoreOrStartOptions): Promise<{
|
|
129
|
+
engine: PathEngine;
|
|
130
|
+
restored: boolean;
|
|
131
|
+
}>;
|
|
132
|
+
export { matchesStrategy } from "@daltonr/pathwrite-core";
|
|
133
|
+
export type { PathData, PathDefinition, PathEvent, PathObserver, PathEngineOptions, PathSnapshot, PathStep, PathStepContext, SerializedPathState, ObserverStrategy, PathStore, } from "@daltonr/pathwrite-core";
|
|
134
|
+
export { LocalStorageStore } from "./local-store";
|
|
135
|
+
export type { LocalStorageStoreOptions, StorageAdapter } from "./local-store";
|
|
136
|
+
export { AsyncStorageStore } from "./async-store";
|
|
137
|
+
export type { AsyncStorageStoreOptions, AsyncStorageAdapter } from "./async-store";
|
|
138
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,UAAU,EAAmB,MAAM,yBAAyB,CAAC;AACtE,OAAO,KAAK,EACV,mBAAmB,EAEnB,cAAc,EACd,QAAQ,EACR,YAAY,EAEZ,gBAAgB,EAChB,SAAS,EACV,MAAM,yBAAyB,CAAC;AAMjC,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB,qFAAqF;IACrF,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAC;IAClC,qFAAqF;IACrF,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAC;IAClC,uFAAuF;IACvF,SAAS,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAA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2DAA2D;IAC3D,GAAG,EAAE,MAAM,CAAC;IACZ,2DAA2D;IAC3D,IAAI,EAAE,cAAc,CAAC,GAAG,CAAC,CAAC;IAC1B;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC;IACtD,uEAAuE;IACvE,WAAW,CAAC,EAAE,QAAQ,CAAC;IACvB;;;;OAIG;IACH,SAAS,CAAC,EAAE,YAAY,EAAE,CAAC;CAC5B;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,cAAc,CAClC,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC;IAAE,MAAM,EAAE,UAAU,CAAC;IAAC,QAAQ,EAAE,OAAO,CAAA;CAAE,CAAC,CAkBpD;AAGD,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,YAAY,EACV,QAAQ,EACR,cAAc,EACd,SAAS,EACT,YAAY,EACZ,iBAAiB,EACjB,YAAY,EACZ,QAAQ,EACR,eAAe,EACf,mBAAmB,EACnB,gBAAgB,EAChB,SAAS,GACV,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClD,YAAY,EAAE,wBAAwB,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE9E,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClD,YAAY,EAAE,wBAAwB,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @daltonr/pathwrite-store
|
|
3
|
+
*
|
|
4
|
+
* Persistence adapters and observer utilities for PathEngine state.
|
|
5
|
+
*
|
|
6
|
+
* Stores (implement PathStore):
|
|
7
|
+
* - HttpStore — persists to a REST API
|
|
8
|
+
* - LocalStorageStore — persists to browser localStorage (or any sync key-value adapter)
|
|
9
|
+
* - AsyncStorageStore — persists to any async key-value store (e.g. AsyncStorage on React Native)
|
|
10
|
+
*
|
|
11
|
+
* Observer utilities:
|
|
12
|
+
* - persistence — PathObserver factory; wires any PathStore to an engine's event stream
|
|
13
|
+
* - restoreOrStart — convenience factory for the load/restore-or-start pattern
|
|
14
|
+
*
|
|
15
|
+
* Bring your own store:
|
|
16
|
+
* Implement the PathStore interface (save / load / delete) to use any backend —
|
|
17
|
+
* MongoDB Atlas SDK, SQLite, MMKV, IndexedDB, or anything else.
|
|
18
|
+
*/
|
|
19
|
+
import { PathEngine, matchesStrategy } from "@daltonr/pathwrite-core";
|
|
20
|
+
export class HttpStore {
|
|
21
|
+
options;
|
|
22
|
+
constructor(options) {
|
|
23
|
+
const baseUrl = options.baseUrl.replace(/\/$/, "");
|
|
24
|
+
this.options = {
|
|
25
|
+
baseUrl,
|
|
26
|
+
saveUrl: options.saveUrl ?? ((key) => `${baseUrl}/state/${encodeURIComponent(key)}`),
|
|
27
|
+
loadUrl: options.loadUrl ?? ((key) => `${baseUrl}/state/${encodeURIComponent(key)}`),
|
|
28
|
+
deleteUrl: options.deleteUrl ?? ((key) => `${baseUrl}/state/${encodeURIComponent(key)}`),
|
|
29
|
+
fetch: options.fetch ?? fetch.bind(globalThis),
|
|
30
|
+
headers: options.headers,
|
|
31
|
+
onError: options.onError,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
async getHeaders() {
|
|
35
|
+
if (!this.options.headers)
|
|
36
|
+
return {};
|
|
37
|
+
if (typeof this.options.headers === "function") {
|
|
38
|
+
return await this.options.headers();
|
|
39
|
+
}
|
|
40
|
+
return this.options.headers;
|
|
41
|
+
}
|
|
42
|
+
async save(key, state) {
|
|
43
|
+
try {
|
|
44
|
+
const url = this.options.saveUrl(key);
|
|
45
|
+
const headers = await this.getHeaders();
|
|
46
|
+
const response = await this.options.fetch(url, {
|
|
47
|
+
method: "PUT",
|
|
48
|
+
headers: { "Content-Type": "application/json", ...headers },
|
|
49
|
+
body: JSON.stringify(state),
|
|
50
|
+
});
|
|
51
|
+
if (!response.ok) {
|
|
52
|
+
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
57
|
+
this.options.onError?.(err, "save", key);
|
|
58
|
+
throw err;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
async load(key) {
|
|
62
|
+
try {
|
|
63
|
+
const url = this.options.loadUrl(key);
|
|
64
|
+
const headers = await this.getHeaders();
|
|
65
|
+
const response = await this.options.fetch(url, {
|
|
66
|
+
method: "GET",
|
|
67
|
+
headers: { "Content-Type": "application/json", ...headers },
|
|
68
|
+
});
|
|
69
|
+
if (response.status === 404)
|
|
70
|
+
return null;
|
|
71
|
+
if (!response.ok) {
|
|
72
|
+
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
73
|
+
}
|
|
74
|
+
const data = await response.json();
|
|
75
|
+
return data;
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
79
|
+
this.options.onError?.(err, "load", key);
|
|
80
|
+
throw err;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
async delete(key) {
|
|
84
|
+
try {
|
|
85
|
+
const url = this.options.deleteUrl(key);
|
|
86
|
+
const headers = await this.getHeaders();
|
|
87
|
+
const response = await this.options.fetch(url, {
|
|
88
|
+
method: "DELETE",
|
|
89
|
+
headers: { ...headers },
|
|
90
|
+
});
|
|
91
|
+
if (response.status === 404)
|
|
92
|
+
return;
|
|
93
|
+
if (!response.ok) {
|
|
94
|
+
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
99
|
+
this.options.onError?.(err, "delete", key);
|
|
100
|
+
throw err;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Returns a `PathObserver` that automatically persists engine state to the
|
|
106
|
+
* provided store based on the chosen strategy.
|
|
107
|
+
*
|
|
108
|
+
* Works with any PathStore — HttpStore, LocalStorageStore, AsyncStorageStore,
|
|
109
|
+
* or a custom implementation.
|
|
110
|
+
*
|
|
111
|
+
* ```typescript
|
|
112
|
+
* const store = new LocalStorageStore();
|
|
113
|
+
* const engine = new PathEngine({
|
|
114
|
+
* observers: [
|
|
115
|
+
* persistence({ store, key: "user:123:onboarding", strategy: "onNext" }),
|
|
116
|
+
* ],
|
|
117
|
+
* });
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
export function persistence(options) {
|
|
121
|
+
const strategy = options.strategy ?? "onNext";
|
|
122
|
+
const debounceMs = options.debounceMs ?? 0;
|
|
123
|
+
let saveTimer = null;
|
|
124
|
+
let pendingSave = null;
|
|
125
|
+
const performSave = (engine) => {
|
|
126
|
+
if (pendingSave)
|
|
127
|
+
return pendingSave;
|
|
128
|
+
pendingSave = (async () => {
|
|
129
|
+
const state = engine.exportState();
|
|
130
|
+
if (!state)
|
|
131
|
+
return;
|
|
132
|
+
try {
|
|
133
|
+
await options.store.save(options.key, state);
|
|
134
|
+
options.onSaveSuccess?.();
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
138
|
+
options.onSaveError?.(err);
|
|
139
|
+
}
|
|
140
|
+
})().finally(() => { pendingSave = null; });
|
|
141
|
+
return pendingSave;
|
|
142
|
+
};
|
|
143
|
+
const scheduleSave = (engine) => {
|
|
144
|
+
if (debounceMs > 0) {
|
|
145
|
+
if (saveTimer)
|
|
146
|
+
clearTimeout(saveTimer);
|
|
147
|
+
saveTimer = setTimeout(() => {
|
|
148
|
+
saveTimer = null;
|
|
149
|
+
performSave(engine);
|
|
150
|
+
}, debounceMs);
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
performSave(engine);
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
return (event, engine) => {
|
|
157
|
+
if (strategy === "onComplete") {
|
|
158
|
+
if (event.type === "completed") {
|
|
159
|
+
const finalState = {
|
|
160
|
+
version: 1,
|
|
161
|
+
pathId: event.pathId,
|
|
162
|
+
currentStepIndex: -1,
|
|
163
|
+
data: event.data,
|
|
164
|
+
visitedStepIds: [],
|
|
165
|
+
pathStack: [],
|
|
166
|
+
_isNavigating: false,
|
|
167
|
+
};
|
|
168
|
+
options.store.save(options.key, finalState)
|
|
169
|
+
.then(() => options.onSaveSuccess?.())
|
|
170
|
+
.catch((error) => {
|
|
171
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
172
|
+
options.onSaveError?.(err);
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
if (matchesStrategy(strategy, event))
|
|
178
|
+
scheduleSave(engine);
|
|
179
|
+
if (event.type === "completed") {
|
|
180
|
+
options.store.delete(options.key).catch((err) => {
|
|
181
|
+
console.warn("[pathwrite] Failed to delete saved state after completion:", err);
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Handles the load/restore-or-start pattern in a single call.
|
|
188
|
+
*
|
|
189
|
+
* Tries to load saved state from the store. If found, restores the engine
|
|
190
|
+
* to the saved position. If not found, starts a fresh path.
|
|
191
|
+
*
|
|
192
|
+
* ```typescript
|
|
193
|
+
* const store = new AsyncStorageStore({ storage: AsyncStorage });
|
|
194
|
+
* const key = "user:123:onboarding";
|
|
195
|
+
*
|
|
196
|
+
* const { engine, restored } = await restoreOrStart({
|
|
197
|
+
* store,
|
|
198
|
+
* key,
|
|
199
|
+
* path: onboardingWizard,
|
|
200
|
+
* initialData: { name: "", email: "" },
|
|
201
|
+
* observers: [
|
|
202
|
+
* persistence({ store, key, strategy: "onNext" }),
|
|
203
|
+
* ],
|
|
204
|
+
* });
|
|
205
|
+
* ```
|
|
206
|
+
*/
|
|
207
|
+
export async function restoreOrStart(options) {
|
|
208
|
+
const observers = options.observers ?? [];
|
|
209
|
+
const pathDefs = options.pathDefinitions ?? { [options.path.id]: options.path };
|
|
210
|
+
const saved = await options.store.load(options.key);
|
|
211
|
+
let engine;
|
|
212
|
+
let restored;
|
|
213
|
+
if (saved) {
|
|
214
|
+
engine = PathEngine.fromState(saved, pathDefs, { observers });
|
|
215
|
+
restored = true;
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
engine = new PathEngine({ observers });
|
|
219
|
+
await engine.start(options.path, options.initialData);
|
|
220
|
+
restored = false;
|
|
221
|
+
}
|
|
222
|
+
return { engine, restored };
|
|
223
|
+
}
|
|
224
|
+
// Re-export core types and utilities for convenience
|
|
225
|
+
export { matchesStrategy } from "@daltonr/pathwrite-core";
|
|
226
|
+
export { LocalStorageStore } from "./local-store";
|
|
227
|
+
export { AsyncStorageStore } from "./async-store";
|
|
228
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAuCtE,MAAM,OAAO,SAAS;IACZ,OAAO,CACiC;IAEhD,YAAY,OAAyB;QACnC,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QAEnD,IAAI,CAAC,OAAO,GAAG;YACb,OAAO;YACP,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,OAAO,UAAU,kBAAkB,CAAC,GAAG,CAAC,EAAE,CAAC;YACpF,OAAO,EAAE,OAAO,CAAC,O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CAAC,CAAC,CAAC;QACL,CAAC;IACH,CAAC,CAAC;AACJ,CAAC;AA4BD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,OAA8B;IAE9B,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,EAAE,CAAC;IAC1C,MAAM,QAAQ,GAAG,OAAO,CAAC,eAAe,IAAI,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC;IAChF,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAEpD,IAAI,MAAkB,CAAC;IACvB,IAAI,QAAiB,CAAC;IAEtB,IAAI,KAAK,EAAE,CAAC;QACV,MAAM,GAAG,UAAU,CAAC,SAAS,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC;QAC9D,QAAQ,GAAG,IAAI,CAAC;IAClB,CAAC;SAAM,CAAC;QACN,MAAM,GAAG,IAAI,UAAU,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC;QACvC,MAAM,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC;QACtD,QAAQ,GAAG,KAAK,CAAC;IACnB,CAAC;IAED,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;AAC9B,CAAC;AAED,qDAAqD;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAe1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAGlD,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { SerializedPathState, PathStore } from "@daltonr/pathwrite-core";
|
|
2
|
+
/**
|
|
3
|
+
* Minimal interface for a synchronous key-value string storage backend.
|
|
4
|
+
* Both `localStorage` and `sessionStorage` satisfy this interface, as does
|
|
5
|
+
* any custom stub you inject for testing or SSR environments.
|
|
6
|
+
*/
|
|
7
|
+
export interface StorageAdapter {
|
|
8
|
+
getItem(key: string): string | null;
|
|
9
|
+
setItem(key: string, value: string): void;
|
|
10
|
+
removeItem(key: string): void;
|
|
11
|
+
/**
|
|
12
|
+
* Return every key currently held in the storage backend.
|
|
13
|
+
* Required by `LocalStorageStore.list()` and `LocalStorageStore.clear()`.
|
|
14
|
+
* Implementations that don't need those methods may omit this.
|
|
15
|
+
*/
|
|
16
|
+
getAllKeys?(): string[];
|
|
17
|
+
}
|
|
18
|
+
export interface LocalStorageStoreOptions {
|
|
19
|
+
/**
|
|
20
|
+
* Prefix prepended to every storage key to avoid collisions.
|
|
21
|
+
* Defaults to `"@daltonr/pathwrite:"`.
|
|
22
|
+
*/
|
|
23
|
+
prefix?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Storage backend to use.
|
|
26
|
+
* - Omit (or `undefined`): uses global `localStorage` when available, otherwise falls back to
|
|
27
|
+
* an in-process memory store (useful in Node / test environments).
|
|
28
|
+
* - Pass a `StorageAdapter` (e.g. `sessionStorage`, or a custom stub): uses that object.
|
|
29
|
+
* - Pass `null`: forces the in-memory fallback regardless of environment.
|
|
30
|
+
*/
|
|
31
|
+
storage?: StorageAdapter | null;
|
|
32
|
+
}
|
|
33
|
+
export declare class LocalStorageStore implements PathStore {
|
|
34
|
+
private prefix;
|
|
35
|
+
private storage;
|
|
36
|
+
constructor(options?: LocalStorageStoreOptions);
|
|
37
|
+
private storageKey;
|
|
38
|
+
save(key: string, state: SerializedPathState): Promise<void>;
|
|
39
|
+
load(key: string): Promise<SerializedPathState | null>;
|
|
40
|
+
delete(key: string): Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* Returns every key stored under this store's prefix, decoded back to the
|
|
43
|
+
* original key strings passed to `save()`.
|
|
44
|
+
*/
|
|
45
|
+
list(): Promise<string[]>;
|
|
46
|
+
/**
|
|
47
|
+
* Removes every entry stored under this store's prefix.
|
|
48
|
+
*/
|
|
49
|
+
clear(): Promise<void>;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=local-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local-store.d.ts","sourceRoot":"","sources":["../src/local-store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAE9E;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IACpC,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1C,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B;;;;OAIG;IACH,UAAU,CAAC,IAAI,MAAM,EAAE,CAAC;CACzB;AAED,MAAM,WAAW,wBAAwB;IACvC;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,cAAc,GAAG,IAAI,CAAC;CACjC;AAoBD,qBAAa,iBAAkB,YAAW,SAAS;IACjD,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,OAAO,CAAiB;gBAEpB,OAAO,GAAE,wBAA6B;IAwBlD,OAAO,CAAC,UAAU;IAIZ,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;IAQ5D,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,GAAG,IAAI,CAAC;IAUtD,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAQxC;;;OAGG;IACG,IAAI,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAiB/B;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAM7B"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
function createMemoryStorage() {
|
|
2
|
+
const map = new Map();
|
|
3
|
+
return {
|
|
4
|
+
getItem(key) {
|
|
5
|
+
return map.has(key) ? map.get(key) : null;
|
|
6
|
+
},
|
|
7
|
+
setItem(key, value) {
|
|
8
|
+
map.set(key, value);
|
|
9
|
+
},
|
|
10
|
+
removeItem(key) {
|
|
11
|
+
map.delete(key);
|
|
12
|
+
},
|
|
13
|
+
getAllKeys() {
|
|
14
|
+
return Array.from(map.keys());
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export class LocalStorageStore {
|
|
19
|
+
prefix;
|
|
20
|
+
storage;
|
|
21
|
+
constructor(options = {}) {
|
|
22
|
+
this.prefix = options.prefix ?? "@daltonr/pathwrite:";
|
|
23
|
+
if (options.storage !== undefined) {
|
|
24
|
+
this.storage = options.storage !== null ? options.storage : createMemoryStorage();
|
|
25
|
+
}
|
|
26
|
+
else if (typeof localStorage !== "undefined") {
|
|
27
|
+
this.storage = {
|
|
28
|
+
getItem: (k) => localStorage.getItem(k),
|
|
29
|
+
setItem: (k, v) => localStorage.setItem(k, v),
|
|
30
|
+
removeItem: (k) => localStorage.removeItem(k),
|
|
31
|
+
getAllKeys: () => {
|
|
32
|
+
const keys = [];
|
|
33
|
+
for (let i = 0; i < localStorage.length; i++) {
|
|
34
|
+
const k = localStorage.key(i);
|
|
35
|
+
if (k !== null)
|
|
36
|
+
keys.push(k);
|
|
37
|
+
}
|
|
38
|
+
return keys;
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
this.storage = createMemoryStorage();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
storageKey(key) {
|
|
47
|
+
return this.prefix + encodeURIComponent(key);
|
|
48
|
+
}
|
|
49
|
+
async save(key, state) {
|
|
50
|
+
try {
|
|
51
|
+
this.storage.setItem(this.storageKey(key), JSON.stringify(state));
|
|
52
|
+
}
|
|
53
|
+
catch (err) {
|
|
54
|
+
throw err instanceof Error ? err : new Error(String(err));
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
async load(key) {
|
|
58
|
+
try {
|
|
59
|
+
const raw = this.storage.getItem(this.storageKey(key));
|
|
60
|
+
if (raw === null || raw === undefined)
|
|
61
|
+
return null;
|
|
62
|
+
return JSON.parse(raw);
|
|
63
|
+
}
|
|
64
|
+
catch (err) {
|
|
65
|
+
throw err instanceof Error ? err : new Error(String(err));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
async delete(key) {
|
|
69
|
+
try {
|
|
70
|
+
this.storage.removeItem(this.storageKey(key));
|
|
71
|
+
}
|
|
72
|
+
catch (err) {
|
|
73
|
+
throw err instanceof Error ? err : new Error(String(err));
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Returns every key stored under this store's prefix, decoded back to the
|
|
78
|
+
* original key strings passed to `save()`.
|
|
79
|
+
*/
|
|
80
|
+
async list() {
|
|
81
|
+
if (!this.storage.getAllKeys) {
|
|
82
|
+
throw new Error("LocalStorageStore.list() requires the StorageAdapter to implement getAllKeys(). " +
|
|
83
|
+
"Add getAllKeys() to your custom adapter or use the built-in localStorage/memory backends.");
|
|
84
|
+
}
|
|
85
|
+
try {
|
|
86
|
+
return this.storage
|
|
87
|
+
.getAllKeys()
|
|
88
|
+
.filter((k) => k.startsWith(this.prefix))
|
|
89
|
+
.map((k) => decodeURIComponent(k.slice(this.prefix.length)));
|
|
90
|
+
}
|
|
91
|
+
catch (err) {
|
|
92
|
+
throw err instanceof Error ? err : new Error(String(err));
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Removes every entry stored under this store's prefix.
|
|
97
|
+
*/
|
|
98
|
+
async clear() {
|
|
99
|
+
const keys = await this.list();
|
|
100
|
+
for (const key of keys) {
|
|
101
|
+
await this.delete(key);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=local-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local-store.js","sourceRoot":"","sources":["../src/local-store.ts"],"names":[],"mappings":"AAmCA,SAAS,mBAAmB;IAC1B,MAAM,GAAG,GAAG,IAAI,GAAG,EAAkB,CAAC;IACtC,OAAO;QACL,OAAO,CAAC,GAAW;YACjB,OAAO,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAE,GAAG,CAAC,GAAG,CAAC,GAAG,CAAY,CAAC,CAAC,CAAC,IAAI,CAAC;QACxD,CAAC;QACD,OAAO,CAAC,GAAW,EAAE,KAAa;YAChC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QACtB,CAAC;QACD,UAAU,CAAC,GAAW;YACpB,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAClB,CAAC;QACD,UAAU;YACR,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;QAChC,CAAC;KACF,CAAC;AACJ,CAAC;AAED,MAAM,OAAO,iBAAiB;IACpB,MAAM,CAAS;IACf,OAAO,CAAiB;IAEhC,YAAY,UAAoC,EAAE;QAChD,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,qBAAqB,CAAC;QAEtD,IAAI,OAAO,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;YAClC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,KAAK,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,mBAAmB,EAAE,CAAC;QACpF,CAAC;aAAM,IAAI,OAAO,YAAY,KAAK,WAAW,EAAE,CAAC;YAC/C,IAAI,CAAC,OAAO,GAAG;gBACb,OAAO,EAAE,CAAC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C,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QACjE,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;QAC5D,CAAC;IACH,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,KAAK;QACT,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC;QAC/B,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;YACvB,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACzB,CAAC;IACH,CAAC;CACF"}
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@daltonr/pathwrite-store",
|
|
3
|
+
"version": "0.9.0",
|
|
4
|
+
"description": "Persistence adapters for PathEngine — LocalStorageStore (browser), AsyncStorageStore (React Native / any async key-value store), and HttpStore (REST API)",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"README.md",
|
|
17
|
+
"LICENSE"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsc -p tsconfig.json",
|
|
21
|
+
"test": "vitest run",
|
|
22
|
+
"test:watch": "vitest"
|
|
23
|
+
},
|
|
24
|
+
"keywords": [
|
|
25
|
+
"pathwrite",
|
|
26
|
+
"wizard",
|
|
27
|
+
"persistence",
|
|
28
|
+
"storage",
|
|
29
|
+
"http",
|
|
30
|
+
"localstorage",
|
|
31
|
+
"async-storage",
|
|
32
|
+
"react-native"
|
|
33
|
+
],
|
|
34
|
+
"author": "Richard Dalton",
|
|
35
|
+
"license": "MIT",
|
|
36
|
+
"repository": {
|
|
37
|
+
"type": "git",
|
|
38
|
+
"url": "https://github.com/daltonr/pathwrite.git",
|
|
39
|
+
"directory": "packages/store"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@daltonr/pathwrite-core": "^0.9.0"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"typescript": "^5.3.0",
|
|
46
|
+
"vitest": "^1.0.0"
|
|
47
|
+
},
|
|
48
|
+
"publishConfig": {
|
|
49
|
+
"access": "public"
|
|
50
|
+
}
|
|
51
|
+
}
|