@aparte/plugin-storage-idb 0.0.0-stage → 0.32.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 aparté
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,55 @@
1
- # Temporary Holding Version
1
+ # @aparte/plugin-storage-idb
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Keep [aparté](https://apartejs.dev) conversations in the browser. An IndexedDB storage adapter for
4
+ the conversation manager: the list is read without a single message, a conversation's messages when
5
+ it opens, and a file a person attached is kept as a file — it is still there after a reload. No
6
+ server, no dependency.
7
+
8
+ ```bash
9
+ npm install @aparte/plugin-storage-idb
10
+ ```
11
+
12
+ ```ts
13
+ import { AparteConversationManager } from '@aparte/core';
14
+ import { createIdbStorage } from '@aparte/plugin-storage-idb';
15
+
16
+ const manager = new AparteConversationManager(createIdbStorage());
17
+ await manager.init();
18
+ ```
19
+
20
+ ## What it keeps
21
+
22
+ - **The list**: one small row per conversation (title, dates, pinned, archived), so drawing the
23
+ list never reads a message.
24
+ - **The messages and their branches**: the `messages` and the `tree` of every version, read when the
25
+ conversation opens.
26
+ - **The files**: each attachment's file in its own store, by message and by conversation — kept as
27
+ its bytes, which Safari's private browsing accepts where it refuses a `Blob` — given back as a
28
+ `Blob` with a fresh object URL when the conversation is loaded, and written once — saving the conversation
29
+ again does not rewrite them. A file whose attachment left the conversation
30
+ is deleted with it; deleting a conversation deletes its files.
31
+ - **What the person did**: a pin, an archive, a title typed in — kept as a typed title, so the
32
+ manager does not re-title it after a reload.
33
+
34
+ ## Options
35
+
36
+ | Option | What it does | Default |
37
+ | --- | --- | --- |
38
+ | `name` | the database name; two chats on one origin that must not share their conversations take two | `'aparte'` |
39
+ | `indexedDB` | the `IDBFactory` to open it with; a test passes `fake-indexeddb`'s | the page's `indexedDB` |
40
+ | `objectUrl` | turns a stored file back into a URL when a conversation is loaded | `URL.createObjectURL` |
41
+
42
+ The adapter returned, `IdbStorage`, is the full `AparteStorageAdapter` (split loading, pins, archives,
43
+ rename, `loadAttachments`) plus `close()`, which lets go of the database; the next call opens it
44
+ again. The database opens on the first call, so creating the adapter during a server render is
45
+ harmless; a call where there is no IndexedDB rejects with a message that says so. A save is all
46
+ or nothing: if a message cannot be stored (a value structured clone refuses, the quota), nothing
47
+ of it is, and the save rejects with that error. Another tab upgrading the database is not blocked:
48
+ this connection lets go of it.
49
+
50
+ [The persistence guide](https://apartejs.dev/guides/conversation-persistence/#keep-them-in-the-browser)
51
+ shows it with the conversation list.
52
+
53
+ ## License
54
+
55
+ MIT
@@ -0,0 +1,59 @@
1
+ /**
2
+ * `@aparte/plugin-storage-idb` — conversations kept in the browser, in IndexedDB.
3
+ *
4
+ * An `AparteStorageAdapter` for `AparteConversationManager`, with split storage: the list
5
+ * is read from small rows (`loadMeta`), a conversation's messages only when it is opened
6
+ * (`loadFull`), and an attachment's file is kept in its own store, so a picture a person
7
+ * sent is still there after a reload. No server, no dependency.
8
+ *
9
+ * ```ts
10
+ * import { AparteConversationManager } from '@aparte/core';
11
+ * import { createIdbStorage } from '@aparte/plugin-storage-idb';
12
+ *
13
+ * const manager = new AparteConversationManager(createIdbStorage());
14
+ * await manager.init();
15
+ * ```
16
+ *
17
+ * Three object stores in one database (`aparte` by default):
18
+ *
19
+ * - `conversations` — the meta row (`id`, `title`, dates, `pinnedAt`, `archivedAt`): what
20
+ * the list needs, so listing never reads a message.
21
+ * - `payloads` — `messages` and the branching `tree`, by conversation id, with every
22
+ * attachment's `blob` taken out and its session-scoped `blob:` URL dropped.
23
+ * - `attachments` — one row per file, keyed by conversation and attachment, indexed by
24
+ * message; the file is kept as its bytes, and `loadFull` gives each attachment its `Blob`
25
+ * back with a fresh object URL.
26
+ */
27
+ import type { AparteStorageAdapter } from '@aparte/core';
28
+ /** Options for {@link createIdbStorage}. */
29
+ export interface IdbStorageOptions {
30
+ /**
31
+ * The database name. Two chats on one origin that must not share their
32
+ * conversations take two names.
33
+ * @default 'aparte'
34
+ */
35
+ name?: string;
36
+ /**
37
+ * The `IDBFactory` to open the database with — the page's `indexedDB` by default. A
38
+ * test passes `fake-indexeddb`'s.
39
+ */
40
+ indexedDB?: IDBFactory;
41
+ /**
42
+ * Turns a stored file back into a URL the chat can show, when a conversation is
43
+ * loaded. `URL.createObjectURL` by default; where it does not exist, an attachment comes
44
+ * back with its `blob` and an empty `url` (a `blob:` URL is not kept: it dies with its
45
+ * page). A `blob:` `thumbnailUrl` is not kept either, nor rebuilt.
46
+ */
47
+ objectUrl?: (blob: Blob) => string;
48
+ }
49
+ /** The adapter {@link createIdbStorage} returns: the storage contract, and `close()`. */
50
+ export interface IdbStorage extends Required<Pick<AparteStorageAdapter, 'loadAll' | 'save' | 'delete' | 'archive' | 'unarchive' | 'loadMeta' | 'loadFull' | 'pin' | 'unpin' | 'rename' | 'loadAttachments'>> {
51
+ /** Close the database connection. The adapter opens it again on its next call. */
52
+ close(): void;
53
+ }
54
+ /**
55
+ * Create an IndexedDB storage adapter for `AparteConversationManager`. The database opens on
56
+ * the first call, not here, so creating the adapter during a server render is harmless.
57
+ */
58
+ export declare function createIdbStorage(options?: IdbStorageOptions): IdbStorage;
59
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,OAAO,KAAK,EAIR,oBAAoB,EACvB,MAAM,cAAc,CAAC;AAEtB,4CAA4C;AAC5C,MAAM,WAAW,iBAAiB;IAC9B;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,SAAS,CAAC,EAAE,UAAU,CAAC;IACvB;;;;;OAKG;IACH,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,MAAM,CAAC;CACtC;AAED,yFAAyF;AACzF,MAAM,WAAW,UAAW,SAAQ,QAAQ,CAAC,IAAI,CAAC,oBAAoB,EAClE,SAAS,GAAG,MAAM,GAAG,QAAQ,GAAG,SAAS,GAAG,WAAW,GAAG,UAAU,GAAG,UAAU,GAAG,KAAK,GAAG,OAAO,GAAG,QAAQ,GAAG,iBAAiB,CAAC,CAAC;IACpI,kFAAkF;IAClF,KAAK,IAAI,IAAI,CAAC;CACjB;AAqID;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,GAAE,iBAAsB,GAAG,UAAU,CAkM5E"}
package/dist/index.js ADDED
@@ -0,0 +1,262 @@
1
+ const VERSION = 1;
2
+ const CONVERSATIONS = "conversations";
3
+ const PAYLOADS = "payloads";
4
+ const ATTACHMENTS = "attachments";
5
+ const BY_MESSAGE = "byMessage";
6
+ const BY_CONVERSATION = "byConversation";
7
+ const SCHEMA_VERSION = 2;
8
+ const rowOf = ({ bytes, ...row }) => ({ ...row, blob: new Blob([bytes], { type: row.mimeType }) });
9
+ function done(request) {
10
+ return new Promise((resolve, reject) => {
11
+ request.onsuccess = () => resolve(request.result);
12
+ request.onerror = () => reject(request.error);
13
+ });
14
+ }
15
+ function committed(tx) {
16
+ const end = new Promise((resolve, reject) => {
17
+ tx.addEventListener("complete", () => resolve());
18
+ tx.addEventListener("error", (event) => reject(event.target?.error ?? tx.error));
19
+ tx.addEventListener("abort", () => reject(tx.error ?? new Error("IndexedDB transaction aborted")));
20
+ });
21
+ end.catch(() => {
22
+ });
23
+ return end;
24
+ }
25
+ async function atomically(tx, work) {
26
+ const end = committed(tx);
27
+ try {
28
+ await work();
29
+ } catch (error) {
30
+ try {
31
+ tx.abort();
32
+ } catch {
33
+ }
34
+ await end.catch(() => {
35
+ });
36
+ throw error;
37
+ }
38
+ await end;
39
+ }
40
+ function metaOf({ messages: _messages, tree: _tree, ...meta }) {
41
+ return { ...meta, schemaVersion: SCHEMA_VERSION };
42
+ }
43
+ const isRecord = (value) => {
44
+ if (typeof value !== "object" || value === null) return false;
45
+ const proto = Object.getPrototypeOf(value);
46
+ return proto === Object.prototype || proto === null;
47
+ };
48
+ function attachmentsIn(root, found = [], msgId = "") {
49
+ if (Array.isArray(root)) {
50
+ for (const item of root) attachmentsIn(item, found, msgId);
51
+ } else if (isRecord(root)) {
52
+ const here = typeof root.id === "string" && Array.isArray(root.attachments) ? root.id : msgId;
53
+ for (const [key, value] of Object.entries(root)) {
54
+ if (key === "attachments" && Array.isArray(value)) {
55
+ for (const a of value) if (isRecord(a) && typeof a.id === "string") found.push({ attachment: a, msgId: here });
56
+ } else {
57
+ attachmentsIn(value, found, here);
58
+ }
59
+ }
60
+ }
61
+ return found;
62
+ }
63
+ function withoutFiles(value) {
64
+ if (Array.isArray(value)) return value.map(withoutFiles);
65
+ if (!isRecord(value)) return value;
66
+ const copy = {};
67
+ for (const [key, item] of Object.entries(value)) {
68
+ if (key === "attachments" && Array.isArray(item)) {
69
+ copy[key] = item.map((a) => {
70
+ if (!isRecord(a) || !(a.blob instanceof Blob)) return withoutFiles(a);
71
+ const { blob: _blob, ...rest } = a;
72
+ if (typeof rest.url === "string" && rest.url.startsWith("blob:")) rest.url = "";
73
+ if (typeof rest.thumbnailUrl === "string" && rest.thumbnailUrl.startsWith("blob:")) delete rest.thumbnailUrl;
74
+ return rest;
75
+ });
76
+ } else {
77
+ copy[key] = withoutFiles(item);
78
+ }
79
+ }
80
+ return copy;
81
+ }
82
+ function createIdbStorage(options = {}) {
83
+ const name = options.name ?? "aparte";
84
+ const objectUrl = options.objectUrl ?? (typeof URL !== "undefined" && typeof URL.createObjectURL === "function" ? (blob) => URL.createObjectURL(blob) : void 0);
85
+ let opening;
86
+ const db = () => {
87
+ if (opening) return opening;
88
+ const factory = options.indexedDB ?? (typeof indexedDB !== "undefined" ? indexedDB : void 0);
89
+ if (!factory) return Promise.reject(new Error("[aparte] storage-idb: this environment has no IndexedDB."));
90
+ const request = factory.open(name, VERSION);
91
+ request.onupgradeneeded = () => {
92
+ const database = request.result;
93
+ if (!database.objectStoreNames.contains(CONVERSATIONS)) database.createObjectStore(CONVERSATIONS, { keyPath: "id" });
94
+ if (!database.objectStoreNames.contains(PAYLOADS)) database.createObjectStore(PAYLOADS, { keyPath: "id" });
95
+ if (!database.objectStoreNames.contains(ATTACHMENTS)) {
96
+ const files = database.createObjectStore(ATTACHMENTS, { keyPath: ["convId", "id"] });
97
+ files.createIndex(BY_MESSAGE, "msgId");
98
+ files.createIndex(BY_CONVERSATION, "convId");
99
+ }
100
+ };
101
+ opening = done(request).then((database) => {
102
+ database.onversionchange = () => {
103
+ database.close();
104
+ opening = void 0;
105
+ };
106
+ database.onclose = () => {
107
+ opening = void 0;
108
+ };
109
+ return database;
110
+ }, (error) => {
111
+ opening = void 0;
112
+ throw error;
113
+ });
114
+ return opening;
115
+ };
116
+ const inStore = /* @__PURE__ */ new WeakMap();
117
+ const known = (blob, convId) => inStore.get(blob)?.has(convId) ?? false;
118
+ const remember = (blob, convId) => {
119
+ const holders = inStore.get(blob) ?? /* @__PURE__ */ new Set();
120
+ holders.add(convId);
121
+ inStore.set(blob, holders);
122
+ };
123
+ const rehydrate = (conv, rows) => {
124
+ if (rows.length === 0) return conv;
125
+ const byId = new Map(rows.map((row) => [row.id, row]));
126
+ const urls = /* @__PURE__ */ new Map();
127
+ for (const { attachment } of attachmentsIn([conv.messages, conv.tree])) {
128
+ const row = byId.get(attachment.id);
129
+ if (!row) continue;
130
+ remember(row.blob, conv.id);
131
+ attachment.blob = row.blob;
132
+ if (objectUrl) {
133
+ if (!urls.has(row.id)) urls.set(row.id, objectUrl(row.blob));
134
+ attachment.url = urls.get(row.id);
135
+ }
136
+ }
137
+ return conv;
138
+ };
139
+ const updateMeta = async (id, change) => {
140
+ const tx = (await db()).transaction(CONVERSATIONS, "readwrite");
141
+ await atomically(tx, async () => {
142
+ const store = tx.objectStore(CONVERSATIONS);
143
+ const meta = await done(store.get(id));
144
+ if (meta) {
145
+ change(meta);
146
+ store.put(meta);
147
+ }
148
+ });
149
+ };
150
+ const loadMeta = async () => {
151
+ const tx = (await db()).transaction(CONVERSATIONS, "readonly");
152
+ const rows = await done(tx.objectStore(CONVERSATIONS).getAll());
153
+ return rows.sort((a, b) => b.updatedAt - a.updatedAt);
154
+ };
155
+ const loadFull = async (id) => {
156
+ const tx = (await db()).transaction([CONVERSATIONS, PAYLOADS, ATTACHMENTS], "readonly");
157
+ const [meta, payload, rows] = await Promise.all([
158
+ done(tx.objectStore(CONVERSATIONS).get(id)),
159
+ done(tx.objectStore(PAYLOADS).get(id)),
160
+ done(tx.objectStore(ATTACHMENTS).index(BY_CONVERSATION).getAll(id))
161
+ ]);
162
+ if (!meta) return null;
163
+ const conv = { ...meta, messages: payload?.messages ?? [] };
164
+ if (payload?.tree) conv.tree = payload.tree;
165
+ return rehydrate(conv, rows.map(rowOf));
166
+ };
167
+ return {
168
+ loadMeta,
169
+ loadFull,
170
+ async loadAll() {
171
+ const metas = await loadMeta();
172
+ const all = await Promise.all(metas.map((meta) => loadFull(meta.id)));
173
+ return all.filter((conv) => conv !== null);
174
+ },
175
+ async save(conv) {
176
+ const found = /* @__PURE__ */ new Map();
177
+ for (const entry of attachmentsIn([conv.messages, conv.tree])) {
178
+ if (!found.has(entry.attachment.id)) found.set(entry.attachment.id, entry);
179
+ }
180
+ const database = await db();
181
+ const read = database.transaction(ATTACHMENTS, "readonly");
182
+ const rows = new Set((await done(read.objectStore(ATTACHMENTS).index(BY_CONVERSATION).getAllKeys(conv.id))).map((key) => String(key[1])));
183
+ const bytes = /* @__PURE__ */ new Map();
184
+ await Promise.all([...found].map(async ([id, { attachment }]) => {
185
+ const blob = attachment.blob;
186
+ if (blob instanceof Blob && !(rows.has(id) && known(blob, conv.id))) bytes.set(id, await blob.arrayBuffer());
187
+ }));
188
+ const tx = database.transaction([CONVERSATIONS, PAYLOADS, ATTACHMENTS], "readwrite");
189
+ await atomically(tx, async () => {
190
+ tx.objectStore(CONVERSATIONS).put(metaOf(conv));
191
+ const payload = { id: conv.id, messages: withoutFiles(conv.messages) };
192
+ if (conv.tree) payload.tree = withoutFiles(conv.tree);
193
+ tx.objectStore(PAYLOADS).put(payload);
194
+ const attachments = tx.objectStore(ATTACHMENTS);
195
+ const stored = new Set((await done(attachments.index(BY_CONVERSATION).getAllKeys(conv.id))).map((key) => String(key[1])));
196
+ const written = [];
197
+ for (const [id, { attachment, msgId }] of found) {
198
+ const blob = attachment.blob;
199
+ const data = bytes.get(id);
200
+ if (!(blob instanceof Blob) || !data) continue;
201
+ const row = {
202
+ id,
203
+ convId: conv.id,
204
+ msgId,
205
+ name: typeof attachment.name === "string" ? attachment.name : "",
206
+ mimeType: typeof attachment.type === "string" && attachment.type ? attachment.type : blob.type,
207
+ size: typeof attachment.size === "number" ? attachment.size : blob.size,
208
+ bytes: data
209
+ };
210
+ attachments.put(row);
211
+ written.push(blob);
212
+ }
213
+ for (const id of stored) if (!found.has(id)) attachments.delete([conv.id, id]);
214
+ void committed(tx).then(() => {
215
+ for (const blob of written) remember(blob, conv.id);
216
+ }, () => {
217
+ });
218
+ });
219
+ },
220
+ async delete(id) {
221
+ const tx = (await db()).transaction([CONVERSATIONS, PAYLOADS, ATTACHMENTS], "readwrite");
222
+ await atomically(tx, async () => {
223
+ tx.objectStore(CONVERSATIONS).delete(id);
224
+ tx.objectStore(PAYLOADS).delete(id);
225
+ const attachments = tx.objectStore(ATTACHMENTS);
226
+ for (const key of await done(attachments.index(BY_CONVERSATION).getAllKeys(id))) attachments.delete(key);
227
+ });
228
+ },
229
+ archive: (id) => updateMeta(id, (meta) => {
230
+ meta.archivedAt = Date.now();
231
+ }),
232
+ unarchive: (id) => updateMeta(id, (meta) => {
233
+ delete meta.archivedAt;
234
+ }),
235
+ pin: (id) => updateMeta(id, (meta) => {
236
+ meta.pinnedAt = Date.now();
237
+ }),
238
+ unpin: (id) => updateMeta(id, (meta) => {
239
+ delete meta.pinnedAt;
240
+ }),
241
+ // A title the person typed: no longer the manager's to change, after a reload too.
242
+ rename: (id, title) => updateMeta(id, (meta) => {
243
+ meta.title = title;
244
+ meta.autoTitle = false;
245
+ }),
246
+ // Every file stored under that message id — in a copy of a conversation that kept its
247
+ // message ids, the copy's too.
248
+ async loadAttachments(msgId) {
249
+ const tx = (await db()).transaction(ATTACHMENTS, "readonly");
250
+ return (await done(tx.objectStore(ATTACHMENTS).index(BY_MESSAGE).getAll(msgId))).map(rowOf);
251
+ },
252
+ close() {
253
+ void opening?.then((database) => database.close(), () => {
254
+ });
255
+ opening = void 0;
256
+ }
257
+ };
258
+ }
259
+ export {
260
+ createIdbStorage
261
+ };
262
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["/**\n * `@aparte/plugin-storage-idb` — conversations kept in the browser, in IndexedDB.\n *\n * An `AparteStorageAdapter` for `AparteConversationManager`, with split storage: the list\n * is read from small rows (`loadMeta`), a conversation's messages only when it is opened\n * (`loadFull`), and an attachment's file is kept in its own store, so a picture a person\n * sent is still there after a reload. No server, no dependency.\n *\n * ```ts\n * import { AparteConversationManager } from '@aparte/core';\n * import { createIdbStorage } from '@aparte/plugin-storage-idb';\n *\n * const manager = new AparteConversationManager(createIdbStorage());\n * await manager.init();\n * ```\n *\n * Three object stores in one database (`aparte` by default):\n *\n * - `conversations` — the meta row (`id`, `title`, dates, `pinnedAt`, `archivedAt`): what\n * the list needs, so listing never reads a message.\n * - `payloads` — `messages` and the branching `tree`, by conversation id, with every\n * attachment's `blob` taken out and its session-scoped `blob:` URL dropped.\n * - `attachments` — one row per file, keyed by conversation and attachment, indexed by\n * message; the file is kept as its bytes, and `loadFull` gives each attachment its `Blob`\n * back with a fresh object URL.\n */\nimport type {\n AparteAttachmentRow,\n AparteConversation,\n AparteConversationMeta,\n AparteStorageAdapter,\n} from '@aparte/core';\n\n/** Options for {@link createIdbStorage}. */\nexport interface IdbStorageOptions {\n /**\n * The database name. Two chats on one origin that must not share their\n * conversations take two names.\n * @default 'aparte'\n */\n name?: string;\n /**\n * The `IDBFactory` to open the database with — the page's `indexedDB` by default. A\n * test passes `fake-indexeddb`'s.\n */\n indexedDB?: IDBFactory;\n /**\n * Turns a stored file back into a URL the chat can show, when a conversation is\n * loaded. `URL.createObjectURL` by default; where it does not exist, an attachment comes\n * back with its `blob` and an empty `url` (a `blob:` URL is not kept: it dies with its\n * page). A `blob:` `thumbnailUrl` is not kept either, nor rebuilt.\n */\n objectUrl?: (blob: Blob) => string;\n}\n\n/** The adapter {@link createIdbStorage} returns: the storage contract, and `close()`. */\nexport interface IdbStorage extends Required<Pick<AparteStorageAdapter,\n 'loadAll' | 'save' | 'delete' | 'archive' | 'unarchive' | 'loadMeta' | 'loadFull' | 'pin' | 'unpin' | 'rename' | 'loadAttachments'>> {\n /** Close the database connection. The adapter opens it again on its next call. */\n close(): void;\n}\n\nconst VERSION = 1;\nconst CONVERSATIONS = 'conversations';\nconst PAYLOADS = 'payloads';\nconst ATTACHMENTS = 'attachments';\nconst BY_MESSAGE = 'byMessage';\nconst BY_CONVERSATION = 'byConversation';\nconst SCHEMA_VERSION = 2;\n\ninterface PayloadRow {\n id: string;\n messages: AparteConversation['messages'];\n tree?: AparteConversation['tree'];\n}\n\n/**\n * An attachment as stored: its bytes, not its `Blob`. Safari's private browsing — and\n * Playwright's WebKit, whose contexts are private — refuses a `Blob` in IndexedDB\n * (`UnknownError`) and takes an `ArrayBuffer`; the `Blob` is built again on the way out.\n */\ninterface FileRow extends Omit<AparteAttachmentRow, 'blob'> {\n bytes: ArrayBuffer;\n}\n\nconst rowOf = ({ bytes, ...row }: FileRow): AparteAttachmentRow => ({ ...row, blob: new Blob([bytes], { type: row.mimeType }) });\n\n/** A request's result, as a promise. */\nfunction done<T>(request: IDBRequest<T>): Promise<T> {\n return new Promise((resolve, reject) => {\n request.onsuccess = () => resolve(request.result);\n request.onerror = () => reject(request.error);\n });\n}\n\n/**\n * A transaction's end: resolves when it commits, rejects when it aborts or fails. Taken\n * right after the transaction is opened, so the first failure is the one reported.\n */\nfunction committed(tx: IDBTransaction): Promise<void> {\n // Listeners, not `on…` properties: a second waiter on the same transaction must not\n // replace the first.\n const end = new Promise<void>((resolve, reject) => {\n tx.addEventListener('complete', () => resolve());\n // A request's error reaches the transaction before `tx.error` is set (at the abort).\n tx.addEventListener('error', (event) => reject((event.target as IDBRequest | null)?.error ?? tx.error));\n tx.addEventListener('abort', () => reject(tx.error ?? new Error('IndexedDB transaction aborted')));\n });\n // Awaited at the end of the work; a rejection before then is not \"unhandled\".\n end.catch(() => {});\n return end;\n}\n\n/**\n * Run `work` inside `tx`, all or nothing: a throw (a value structured clone refuses, a\n * quota) aborts the transaction, so no store keeps half of a write, and the throw is what\n * the caller gets.\n */\nasync function atomically(tx: IDBTransaction, work: () => Promise<void> | void): Promise<void> {\n const end = committed(tx);\n try {\n await work();\n } catch (error) {\n try { tx.abort(); } catch { /* already finished */ }\n await end.catch(() => {});\n throw error;\n }\n await end;\n}\n\n/** The meta row of a conversation: everything but its messages and tree. */\nfunction metaOf({ messages: _messages, tree: _tree, ...meta }: AparteConversation): AparteConversationMeta {\n return { ...meta, schemaVersion: SCHEMA_VERSION };\n}\n\ntype Json = unknown;\n/**\n * A plain object — what a message is made of. A `Date`, a `Map`, a typed array or a `Blob`\n * is not walked into nor rebuilt: structured clone keeps them as they are.\n */\nconst isRecord = (value: Json): value is Record<string, Json> => {\n if (typeof value !== 'object' || value === null) return false;\n const proto = Object.getPrototypeOf(value) as unknown;\n return proto === Object.prototype || proto === null;\n};\n\n/**\n * Every attachment (an object with an `id` in an `attachments` array) found anywhere in a\n * message list or a tree, with the message id it hangs from. The tree's shape is core's,\n * and it nests messages, so the walk is generic rather than tied to it. The same attachment\n * is found twice when a conversation has a tree (its active path is in both); the message\n * list is walked first, so it names the message.\n */\nfunction attachmentsIn(root: Json, found: Array<{ attachment: Record<string, Json>; msgId: string }> = [], msgId = ''): typeof found {\n if (Array.isArray(root)) {\n for (const item of root) attachmentsIn(item, found, msgId);\n } else if (isRecord(root)) {\n const here = typeof root.id === 'string' && Array.isArray(root.attachments) ? root.id : msgId;\n for (const [key, value] of Object.entries(root)) {\n if (key === 'attachments' && Array.isArray(value)) {\n for (const a of value) if (isRecord(a) && typeof a.id === 'string') found.push({ attachment: a, msgId: here });\n } else {\n attachmentsIn(value, found, here);\n }\n }\n }\n return found;\n}\n\n/**\n * A copy of `value` without the attachments' files: `blob` goes to its own store, and a\n * `blob:` URL dies with the page that made it, so it is not kept either.\n */\nfunction withoutFiles<T>(value: T): T {\n if (Array.isArray(value)) return value.map(withoutFiles) as T;\n if (!isRecord(value)) return value;\n const copy: Record<string, Json> = {};\n for (const [key, item] of Object.entries(value)) {\n if (key === 'attachments' && Array.isArray(item)) {\n copy[key] = item.map((a) => {\n if (!isRecord(a) || !(a.blob instanceof Blob)) return withoutFiles(a);\n const { blob: _blob, ...rest } = a;\n if (typeof rest.url === 'string' && rest.url.startsWith('blob:')) rest.url = '';\n if (typeof rest.thumbnailUrl === 'string' && rest.thumbnailUrl.startsWith('blob:')) delete rest.thumbnailUrl;\n return rest;\n });\n } else {\n copy[key] = withoutFiles(item);\n }\n }\n return copy as T;\n}\n\n/**\n * Create an IndexedDB storage adapter for `AparteConversationManager`. The database opens on\n * the first call, not here, so creating the adapter during a server render is harmless.\n */\nexport function createIdbStorage(options: IdbStorageOptions = {}): IdbStorage {\n const name = options.name ?? 'aparte';\n const objectUrl = options.objectUrl\n ?? (typeof URL !== 'undefined' && typeof URL.createObjectURL === 'function' ? (blob: Blob) => URL.createObjectURL(blob) : undefined);\n let opening: Promise<IDBDatabase> | undefined;\n\n const db = (): Promise<IDBDatabase> => {\n if (opening) return opening;\n const factory = options.indexedDB ?? (typeof indexedDB !== 'undefined' ? indexedDB : undefined);\n if (!factory) return Promise.reject(new Error('[aparte] storage-idb: this environment has no IndexedDB.'));\n const request = factory.open(name, VERSION);\n request.onupgradeneeded = () => {\n const database = request.result;\n if (!database.objectStoreNames.contains(CONVERSATIONS)) database.createObjectStore(CONVERSATIONS, { keyPath: 'id' });\n if (!database.objectStoreNames.contains(PAYLOADS)) database.createObjectStore(PAYLOADS, { keyPath: 'id' });\n if (!database.objectStoreNames.contains(ATTACHMENTS)) {\n // Keyed by conversation AND attachment: a conversation copied into another\n // with the same attachment ids keeps its own files.\n const files = database.createObjectStore(ATTACHMENTS, { keyPath: ['convId', 'id'] });\n files.createIndex(BY_MESSAGE, 'msgId');\n files.createIndex(BY_CONVERSATION, 'convId');\n }\n };\n opening = done(request).then((database) => {\n // Another tab upgrading the schema asks this one to let go, so it is not blocked.\n database.onversionchange = () => { database.close(); opening = undefined; };\n database.onclose = () => { opening = undefined; };\n return database;\n }, (error: unknown) => {\n opening = undefined;\n throw error;\n });\n return opening;\n };\n\n /**\n * For each file, the conversations this adapter knows hold it in the database — as it\n * came back from it or went into it — so saving a conversation again does not rewrite\n * it. By conversation: the same `Blob` in a copy of a conversation is that copy's to\n * store. A row found missing is written again whatever this says (see `save`).\n */\n const inStore = new WeakMap<Blob, Set<string>>();\n const known = (blob: Blob, convId: string) => inStore.get(blob)?.has(convId) ?? false;\n const remember = (blob: Blob, convId: string) => {\n const holders = inStore.get(blob) ?? new Set<string>();\n holders.add(convId);\n inStore.set(blob, holders);\n };\n\n /** Give each stored attachment of a conversation its file and a URL for this page. */\n const rehydrate = (conv: AparteConversation, rows: AparteAttachmentRow[]): AparteConversation => {\n if (rows.length === 0) return conv;\n const byId = new Map(rows.map((row) => [row.id, row]));\n const urls = new Map<string, string>();\n for (const { attachment } of attachmentsIn([conv.messages, conv.tree])) {\n const row = byId.get(attachment.id as string);\n if (!row) continue;\n remember(row.blob, conv.id);\n attachment.blob = row.blob;\n if (objectUrl) {\n if (!urls.has(row.id)) urls.set(row.id, objectUrl(row.blob));\n attachment.url = urls.get(row.id)!;\n }\n }\n return conv;\n };\n\n const updateMeta = async (id: string, change: (meta: AparteConversationMeta) => void): Promise<void> => {\n const tx = (await db()).transaction(CONVERSATIONS, 'readwrite');\n await atomically(tx, async () => {\n const store = tx.objectStore(CONVERSATIONS);\n const meta = await done(store.get(id) as IDBRequest<AparteConversationMeta | undefined>);\n if (meta) {\n change(meta);\n store.put(meta);\n }\n });\n };\n\n const loadMeta = async (): Promise<AparteConversationMeta[]> => {\n const tx = (await db()).transaction(CONVERSATIONS, 'readonly');\n const rows = await done(tx.objectStore(CONVERSATIONS).getAll() as IDBRequest<AparteConversationMeta[]>);\n return rows.sort((a, b) => b.updatedAt - a.updatedAt);\n };\n\n const loadFull = async (id: string): Promise<AparteConversation | null> => {\n const tx = (await db()).transaction([CONVERSATIONS, PAYLOADS, ATTACHMENTS], 'readonly');\n const [meta, payload, rows] = await Promise.all([\n done(tx.objectStore(CONVERSATIONS).get(id) as IDBRequest<AparteConversationMeta | undefined>),\n done(tx.objectStore(PAYLOADS).get(id) as IDBRequest<PayloadRow | undefined>),\n done(tx.objectStore(ATTACHMENTS).index(BY_CONVERSATION).getAll(id) as IDBRequest<FileRow[]>),\n ]);\n if (!meta) return null;\n const conv: AparteConversation = { ...meta, messages: payload?.messages ?? [] };\n if (payload?.tree) conv.tree = payload.tree;\n return rehydrate(conv, rows.map(rowOf));\n };\n\n return {\n loadMeta,\n loadFull,\n\n async loadAll() {\n const metas = await loadMeta();\n const all = await Promise.all(metas.map((meta) => loadFull(meta.id)));\n return all.filter((conv): conv is AparteConversation => conv !== null);\n },\n\n async save(conv) {\n // Each attachment once (a conversation with a tree has its active path twice),\n // named by the first message it was found in.\n const found = new Map<string, { attachment: Record<string, Json>; msgId: string }>();\n for (const entry of attachmentsIn([conv.messages, conv.tree])) {\n if (!found.has(entry.attachment.id as string)) found.set(entry.attachment.id as string, entry);\n }\n // Which files this conversation has in the database now, then the bytes of every\n // file it lacks or holds in a version this adapter did not store — read BEFORE the\n // write: awaiting anything but an IndexedDB request inside a transaction lets it\n // commit.\n const database = await db();\n const read = database.transaction(ATTACHMENTS, 'readonly');\n const rows = new Set((await done(read.objectStore(ATTACHMENTS).index(BY_CONVERSATION).getAllKeys(conv.id)))\n .map((key) => String((key as [string, string])[1])));\n const bytes = new Map<string, ArrayBuffer>();\n await Promise.all([...found].map(async ([id, { attachment }]) => {\n const blob = attachment.blob;\n if (blob instanceof Blob && !(rows.has(id) && known(blob, conv.id))) bytes.set(id, await blob.arrayBuffer());\n }));\n const tx = database.transaction([CONVERSATIONS, PAYLOADS, ATTACHMENTS], 'readwrite');\n await atomically(tx, async () => {\n tx.objectStore(CONVERSATIONS).put(metaOf(conv));\n const payload: PayloadRow = { id: conv.id, messages: withoutFiles(conv.messages) };\n if (conv.tree) payload.tree = withoutFiles(conv.tree);\n tx.objectStore(PAYLOADS).put(payload);\n\n const attachments = tx.objectStore(ATTACHMENTS);\n const stored = new Set((await done(attachments.index(BY_CONVERSATION).getAllKeys(conv.id)))\n .map((key) => String((key as [string, string])[1])));\n const written: Blob[] = [];\n for (const [id, { attachment, msgId }] of found) {\n const blob = attachment.blob;\n const data = bytes.get(id);\n // A file already stored is not written again; one held without its blob\n // (saved before, loaded back without it) keeps its row.\n if (!(blob instanceof Blob) || !data) continue;\n const row: FileRow = {\n id,\n convId: conv.id,\n msgId,\n name: typeof attachment.name === 'string' ? attachment.name : '',\n mimeType: typeof attachment.type === 'string' && attachment.type ? attachment.type : blob.type,\n size: typeof attachment.size === 'number' ? attachment.size : blob.size,\n bytes: data,\n };\n attachments.put(row);\n written.push(blob);\n }\n // A file whose attachment left the conversation (a message edited or deleted)\n // goes with it.\n for (const id of stored) if (!found.has(id)) attachments.delete([conv.id, id]);\n // Counted as stored once the transaction commits, not before.\n void committed(tx).then(() => { for (const blob of written) remember(blob, conv.id); }, () => {});\n });\n },\n\n async delete(id) {\n const tx = (await db()).transaction([CONVERSATIONS, PAYLOADS, ATTACHMENTS], 'readwrite');\n await atomically(tx, async () => {\n tx.objectStore(CONVERSATIONS).delete(id);\n tx.objectStore(PAYLOADS).delete(id);\n const attachments = tx.objectStore(ATTACHMENTS);\n for (const key of await done(attachments.index(BY_CONVERSATION).getAllKeys(id))) attachments.delete(key);\n });\n },\n\n archive: (id) => updateMeta(id, (meta) => { meta.archivedAt = Date.now(); }),\n unarchive: (id) => updateMeta(id, (meta) => { delete meta.archivedAt; }),\n pin: (id) => updateMeta(id, (meta) => { meta.pinnedAt = Date.now(); }),\n unpin: (id) => updateMeta(id, (meta) => { delete meta.pinnedAt; }),\n // A title the person typed: no longer the manager's to change, after a reload too.\n rename: (id, title) => updateMeta(id, (meta) => { meta.title = title; (meta as AparteConversation).autoTitle = false; }),\n\n // Every file stored under that message id — in a copy of a conversation that kept its\n // message ids, the copy's too.\n async loadAttachments(msgId) {\n const tx = (await db()).transaction(ATTACHMENTS, 'readonly');\n return (await done(tx.objectStore(ATTACHMENTS).index(BY_MESSAGE).getAll(msgId) as IDBRequest<FileRow[]>)).map(rowOf);\n },\n\n close() {\n void opening?.then((database) => database.close(),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AO,WAAW,IAAI,CAAC,SAAS;AAAE,WAAK,aAAa,KAAK,IAAA;AAAA,IAAO,CAAC;AAAA,IAC3E,WAAW,CAAC,OAAO,WAAW,IAAI,CAAC,SAAS;AAAE,aAAO,KAAK;AAAA,IAAY,CAAC;AAAA,IACvE,KAAK,CAAC,OAAO,WAAW,IAAI,CAAC,SAAS;AAAE,WAAK,WAAW,KAAK,IAAA;AAAA,IAAO,CAAC;AAAA,IACrE,OAAO,CAAC,OAAO,WAAW,IAAI,CAAC,SAAS;AAAE,aAAO,KAAK;AAAA,IAAU,CAAC;AAAA;AAAA,IAEjE,QAAQ,CAAC,IAAI,UAAU,WAAW,IAAI,CAAC,SAAS;AAAE,WAAK,QAAQ;AAAQ,WAA4B,YAAY;AAAA,IAAO,CAAC;AAAA;AAAA;AAAA,IAIvH,MAAM,gBAAgB,OAAO;AACzB,YAAM,MAAM,MAAM,GAAA,GAAM,YAAY,aAAa,UAAU;AAC3D,cAAQ,MAAM,KAAK,GAAG,YAAY,WAAW,EAAE,MAAM,UAAU,EAAE,OAAO,KAAK,CAA0B,GAAG,IAAI,KAAK;AAAA,IACvH;AAAA,IAEA,QAAQ;AACJ,WAAK,SAAS,KAAK,CAAC,aAAa,SAAS,MAAA,GAAS,MAAM;AAAA,MAAC,CAAC;AAC3D,gBAAU;AAAA,IACd;AAAA,EAAA;AAER;"}
package/package.json CHANGED
@@ -1,6 +1,62 @@
1
1
  {
2
2
  "name": "@aparte/plugin-storage-idb",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.32.1",
4
+ "homepage": "https://apartejs.dev/guides/conversation-persistence/",
5
+ "description": "Keep conversations in the browser: an IndexedDB storage adapter for aparté's conversation manager — split storage, attachments kept as files, no server.",
6
+ "type": "module",
7
+ "sideEffects": false,
8
+ "main": "./dist/index.js",
9
+ "module": "./dist/index.js",
10
+ "types": "./dist/index.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "@aparte-workspace/source": "./src/index.ts",
14
+ "types": "./dist/index.d.ts",
15
+ "import": "./dist/index.js",
16
+ "default": "./dist/index.js"
17
+ }
18
+ },
19
+ "files": [
20
+ "dist",
21
+ "README.md",
22
+ "LICENSE"
23
+ ],
24
+ "engines": {
25
+ "node": ">=18"
26
+ },
27
+ "peerDependencies": {
28
+ "@aparte/core": ">=0.32.1 <1.0.0"
29
+ },
30
+ "devDependencies": {
31
+ "fake-indexeddb": "^6.2.7",
32
+ "typescript": "^5.4.0",
33
+ "vite": "^6.0.0",
34
+ "@aparte/core": "0.32.1"
35
+ },
36
+ "keywords": [
37
+ "aparte",
38
+ "plugin",
39
+ "indexeddb",
40
+ "storage",
41
+ "conversations",
42
+ "offline",
43
+ "local-first"
44
+ ],
45
+ "license": "MIT",
46
+ "repository": {
47
+ "type": "git",
48
+ "url": "git+https://github.com/apartejs/aparte.git",
49
+ "directory": "packages/plugins/storage-idb"
50
+ },
51
+ "bugs": {
52
+ "url": "https://github.com/apartejs/aparte/issues"
53
+ },
54
+ "scripts": {
55
+ "dev": "vite",
56
+ "build": "vite build && tsc -b --emitDeclarationOnly --force && node ../../../scripts/stamp-dist.mjs",
57
+ "preview": "vite preview",
58
+ "test": "vitest",
59
+ "test:run": "vitest run",
60
+ "test:coverage": "vitest run --coverage"
61
+ }
6
62
  }