@wells-nelson/data-storage 1.1.0 → 1.1.1

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 CHANGED
@@ -66,8 +66,9 @@ onMount(() => void store.init({ beforeReady: importDevSeed }));
66
66
  them; pruned after a week.
67
67
  - `prefs`: `DevicePrefs` (default container, "already prompted", collapsed sections). Pass a
68
68
  subclass as `prefs` for app-specific ones and override `replaceContainer` to keep them in step.
69
- - `requestPersistence()`: asks the browser to keep the data (called on start; call it again from
70
- a button). Sets `app.persisted`.
69
+ - `requestPersistence()`: asks the browser to keep the data (called on start unless
70
+ `persistStorage: false`, e.g. for a website whose data lives in the cloud, since some browsers
71
+ ask the user; call it again from a button). Sets `app.persisted`.
71
72
  - `resetDevice()`: teardown for a dev wipe.
72
73
 
73
74
  Without roles everyone is an owner.
package/dist/sql.js CHANGED
@@ -137,15 +137,18 @@ as $$
137
137
  $$;
138
138
 
139
139
  -- False once the ${noun} is deleted: nobody can add members or new rows to it. (Members still
140
- -- read and update its rows, so every device syncs the deletion.)
140
+ -- read and update its rows, so every device syncs the deletion.) plpgsql, whose body is only
141
+ -- checked when it runs: the ${container} table is created further down.
141
142
  create or replace function public.is_${noun}_live(p_${cf} text)
142
143
  returns boolean
143
- language sql
144
+ language plpgsql
144
145
  stable
145
146
  security definer
146
147
  set search_path = public
147
148
  as $$
148
- select not exists (select 1 from public.${container} c where c.id = p_${cf} and c._deleted);
149
+ begin
150
+ return not exists (select 1 from public.${container} c where c.id = p_${cf} and c._deleted);
151
+ end;
149
152
  $$;
150
153
 
151
154
  alter table public.${members} enable row level security;
package/dist/store.d.ts CHANGED
@@ -50,6 +50,12 @@ export interface SyncedStoreConfig<D extends DocMap<D>, C extends CollectionName
50
50
  reportErrors?: {
51
51
  version?: string;
52
52
  };
53
+ /**
54
+ * Ask the browser on start to keep this site's data for good (default true): right for apps that
55
+ * keep data on the device. A website whose data lives in the cloud can turn it off, since some
56
+ * browsers ask the user. `requestPersistence()` still works on demand.
57
+ */
58
+ persistStorage?: boolean;
53
59
  }
54
60
  /**
55
61
  * Wire the whole storage layer for an app from one config: app state (local + cloud data
package/dist/store.js CHANGED
@@ -90,7 +90,8 @@ export function createSyncedStore(config) {
90
90
  await options.beforeReady?.(local).catch((err) => console.error('Startup hook failed', err));
91
91
  app.local = local;
92
92
  app.ready = true;
93
- void requestPersistence();
93
+ if (config.persistStorage ?? true)
94
+ void requestPersistence();
94
95
  await cloud.init();
95
96
  })().catch((err) => {
96
97
  console.error(err);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wells-nelson/data-storage",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "Offline-first storage for Wells Nelson apps: RxDB + TanStack DB data sets, Supabase sync of shared containers, tombstones, device prefs and a SQL migration generator.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -45,6 +45,7 @@
45
45
  "svelte": "^5.40.0"
46
46
  },
47
47
  "devDependencies": {
48
+ "@electric-sql/pglite": "^0.5.16",
48
49
  "@supabase/supabase-js": "^2.119.0",
49
50
  "@tanstack/db": "^1.0.0-rc.1.4",
50
51
  "@tanstack/rxdb-db-collection": "^1.0.0-rc.1.4",