@pluv/addon-indexeddb 4.1.0 → 5.0.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/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @pluv/addon-indexeddb
2
2
 
3
+ ## 5.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - @pluv/client@5.0.1
8
+ - @pluv/crdt@5.0.1
9
+
10
+ ## 5.0.0
11
+
12
+ ### Patch Changes
13
+
14
+ - @pluv/client@5.0.0
15
+ - @pluv/crdt@5.0.0
16
+
3
17
  ## 4.1.0
4
18
 
5
19
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pluv/addon-indexeddb",
3
- "version": "4.1.0",
3
+ "version": "5.0.1",
4
4
  "description": "@pluv/io indexeddb for client storage persistence",
5
5
  "author": {
6
6
  "email": "david@pluv.io",
@@ -20,17 +20,17 @@
20
20
  "access": "public"
21
21
  },
22
22
  "dependencies": {
23
- "idb": "^8.0.3",
24
- "@pluv/client": "^4.1.0",
25
- "@pluv/crdt": "^4.1.0"
23
+ "@pluv/client": "^5.0.1",
24
+ "@pluv/crdt": "^5.0.1",
25
+ "idb": "^8.0.3"
26
26
  },
27
27
  "devDependencies": {
28
- "eslint": "^10.5.0",
29
- "tsdown": "0.22.2",
30
- "typescript": "^5.9.3",
31
- "@pluv/tsconfig": "^4.1.0",
32
- "@pluv/types": "^4.1.0",
33
- "eslint-config-pluv": "^4.1.0"
28
+ "@pluv/tsconfig": "^5.0.1",
29
+ "@pluv/types": "^5.0.1",
30
+ "eslint": "^10.9.0",
31
+ "eslint-config-pluv": "^5.0.1",
32
+ "tsdown": "0.22.14",
33
+ "typescript": "^5.9.3"
34
34
  },
35
35
  "exports": {
36
36
  ".": "./dist/index.mjs",
@@ -1,19 +0,0 @@
1
- $ tsdown
2
- ℹ tsdown v0.22.2 powered by rolldown v1.1.1
3
- ℹ config file: /home/runner/work/pluv/pluv/packages/addon-indexeddb/tsdown.config.ts
4
- ℹ entry: src/index.ts
5
- ℹ target: esnext
6
- ℹ tsconfig: tsconfig.json
7
- ℹ Build start
8
- ℹ Hint: consider adding deps.onlyBundle option to avoid unintended bundling of dependencies, or set deps.onlyBundle: false to disable this hint.
9
- See more at https://tsdown.dev/options/dependencies#deps-onlybundle
10
- Detected dependencies in bundle:
11
- - wonka
12
- ℹ dist/index.mjs 2.58 kB │ gzip: 0.95 kB
13
- ℹ dist/index.d.mts.map 7.82 kB │ gzip: 2.79 kB
14
- ℹ dist/index.mjs.map 6.64 kB │ gzip: 2.08 kB
15
- ℹ dist/index.d.mts 5.84 kB │ gzip: 1.85 kB
16
- ℹ 4 files, total: 22.89 kB
17
- [PLUGIN_TIMINGS] Your build spent significant time in plugin `rolldown-plugin-dts:generate`. See https://rolldown.rs/options/checks#plugintimings for more details.
18
-
19
- ✔ Build complete in 3826ms
package/dist/index.d.mts DELETED
@@ -1,134 +0,0 @@
1
- import { PluvRoom, PluvRoomAddon } from "@pluv/client";
2
- import { AbstractCrdtDocFactory } from "@pluv/crdt";
3
-
4
- //#region ../../node_modules/.pnpm/wonka@6.3.6/node_modules/wonka/dist/wonka.d.ts
5
- declare global {
6
- interface SymbolConstructor {
7
- readonly observable: symbol;
8
- }
9
- }
10
- /** A definition of the ES Observable Subscription type that is returned by
11
- * {@link Observable.subscribe}
12
- *
13
- * @remarks
14
- * The Subscription in ES Observables is a handle that is held while the Observable is actively
15
- * streaming values. As such, it's used to indicate with {@link ObservableSubscription.closed}
16
- * whether it's active, and {@link ObservableSubscription.unsubscribe} may be used to cancel the
17
- * ongoing subscription and end the {@link Observable} early.
18
- *
19
- * @see {@link https://github.com/tc39/proposal-observable} for the ES Observable specification.
20
- */
21
- //#endregion
22
- //#region ../types/dist/index.d.mts
23
- type Maybe<T> = T | Nil;
24
- type MaybePromise<T> = Promise<T> | T;
25
- type Nil = null | undefined;
26
- type JsonPrimitive = string | number | boolean | null;
27
- type Json = JsonPrimitive | Json[] | readonly Json[] | {
28
- [key: string]: Json;
29
- };
30
- type JsonObject = Record<string, Json>;
31
- //#endregion
32
- //#region src/pluv/crdt.d.ts
33
- interface CrdtDocFactory<TDoc extends any, TStorage extends Record<string, CrdtType<any, any>>> {
34
- _initialStorage: (builder: any) => TStorage;
35
- getEmpty(): CrdtDocLike<TDoc, TStorage>;
36
- getFactory(initialStorage?: (builder: any) => TStorage): CrdtDocFactory<TDoc, TStorage>;
37
- getInitialized(initialStorage?: (builder: any) => TStorage): CrdtDocLike<TDoc, TStorage>;
38
- isEmpty(initialStorage: Maybe<string>): boolean;
39
- }
40
- interface CrdtLibraryType<TDoc extends CrdtDocFactory<any, any> = CrdtDocFactory<any, any>> {
41
- doc: (value: any) => TDoc;
42
- kind: "loro" | "yjs";
43
- }
44
- type CrdtType<TValue extends unknown, TJson extends unknown = any> = Omit<TValue, "__pluvType"> & {
45
- __pluvType: () => TJson;
46
- };
47
- type InferCrdtJson<T extends unknown> = T extends CrdtType<any, infer IJson> ? InferCrdtJson<IJson> : T extends Record<string, any> ? { [P in keyof T]: InferCrdtJson<T[P]> } : T extends (infer IJson)[] ? InferCrdtJson<IJson>[] : T extends readonly (infer IJson)[] ? readonly InferCrdtJson<IJson>[] : T extends Json ? T : string;
48
- interface DocApplyEncodedStateParams {
49
- origin?: string;
50
- update?: Maybe<string | Uint8Array>;
51
- }
52
- interface DocBatchApplyEncodedStateParams {
53
- origin?: string;
54
- updates?: Maybe<readonly Maybe<string | Uint8Array>[]>;
55
- }
56
- interface DocSubscribeCallbackParams<TDoc extends any, TStorage extends Record<string, CrdtType<any, any>>> {
57
- doc: CrdtDocLike<TDoc, TStorage>;
58
- local: boolean;
59
- origin?: string | null;
60
- update: string;
61
- }
62
- interface CrdtDocLike<TDoc extends any, TStorage extends Record<string, CrdtType<any, any>>> {
63
- value: TDoc;
64
- applyEncodedState(params: DocApplyEncodedStateParams): this;
65
- batchApplyEncodedState(params: DocBatchApplyEncodedStateParams): this;
66
- canRedo(): boolean;
67
- canUndo(): boolean;
68
- destroy(): void;
69
- get(key?: undefined): TStorage;
70
- get<TKey extends keyof TStorage>(key: TKey): TStorage[TKey];
71
- getEncodedState(): string;
72
- isEmpty(): boolean;
73
- rebuildStorage(reference: TStorage): this;
74
- redo(): this;
75
- subscribe(listener: (params: DocSubscribeCallbackParams<TDoc, TStorage>) => void): () => void;
76
- toJson(): InferCrdtJson<TStorage>;
77
- toJson<TKey extends keyof TStorage>(type: TKey): InferCrdtJson<TStorage[TKey]>;
78
- track(): this;
79
- transact(fn: () => void, origin?: string): this;
80
- undo(): this;
81
- } //#endregion
82
- //#region src/pluv/enums.d.ts
83
- //#endregion
84
- //#region src/pluv/shared.d.ts
85
- type BaseUser = {
86
- id: string;
87
- };
88
- type EventRecord<TEvent extends string, TData extends JsonObject> = { [key in `${TEvent}`]: TData };
89
- type InputZodLike<TData extends JsonObject> = {
90
- parse: (data: unknown) => TData;
91
- } & ({
92
- _input: TData;
93
- } | {
94
- _zod: {
95
- input: TData;
96
- };
97
- });
98
- type IOAuthorize<TUser extends BaseUser | null = any, TContext extends Record<string, unknown> = {}> = (TUser extends BaseUser ? {
99
- secret?: string;
100
- user: InputZodLike<TUser>;
101
- } : null) | ((context: TContext) => TUser extends BaseUser ? {
102
- secret?: string;
103
- user: InputZodLike<TUser>;
104
- } : null);
105
- type ProcedureLike<TInput extends Record<string, any> = {}, TOutput extends EventRecord<string, any> = {}> = {
106
- config: {
107
- broadcast?: ((data: TInput, ...args: any[]) => MaybePromise<Partial<TOutput> | void>) | null;
108
- input?: InputZodLike<TInput> | null;
109
- resolver: (data: TInput, ...args: any[]) => MaybePromise<TOutput>;
110
- self?: ((data: TInput, ...args: any[]) => MaybePromise<Partial<TOutput> | void>) | null;
111
- sync?: ((data: TInput, ...args: any[]) => MaybePromise<Partial<TOutput> | void>) | null;
112
- };
113
- };
114
- interface IORouterLike<TEvents extends Record<string, ProcedureLike<any, any>> = {}> {
115
- _defs: {
116
- events: TEvents;
117
- };
118
- }
119
- interface IOLike<TAuthorize extends IOAuthorize<any, any> | null = null, TCrdt extends CrdtLibraryType<any> = CrdtLibraryType<any>, TEvents extends Record<string, ProcedureLike<any, any>> = {}> extends IORouterLike<TEvents> {
120
- _defs: {
121
- authorize: TAuthorize;
122
- crdt: TCrdt;
123
- events: TEvents;
124
- };
125
- }
126
- //#endregion
127
- //#region src/addonIndexedDB.d.ts
128
- interface AddonIndexedDBConfig<TIO extends IOLike<any, any, any>, TMetadata extends JsonObject, TPresence extends Record<string, any>, TCrdt extends AbstractCrdtDocFactory<any, any>> {
129
- enabled?: boolean | ((room: PluvRoom<TIO, TMetadata, TPresence, TCrdt>) => boolean);
130
- }
131
- declare const addonIndexedDB: <TIO extends IOLike<any, any, any>, TMetadata extends JsonObject, TPresence extends Record<string, any>, TCrdt extends AbstractCrdtDocFactory<any, any>>(config?: AddonIndexedDBConfig<TIO, TMetadata, TPresence, TCrdt>) => PluvRoomAddon<TIO, TMetadata, TPresence, TCrdt>;
132
- //#endregion
133
- export { addonIndexedDB };
134
- //# sourceMappingURL=index.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.mts","names":["Pull","Close","TalkbackKind","signal","Start","Push","End","T","tag","_T","Tag","SignalKind","TalkbackFn","Signal","Sink","sink","In","Out","Source","a","U","unsubscribe","next","value","complete","Observer","source","AsyncIterator","AsyncIterable","produce","iterable","Iterable","array","observer","TeardownFn","subscriber","Subject","ms","HTMLElement","element","event","Event","Promise","promise","S","notifier","Operator","map","sources","predicate","callback","acc","reducer","seed","wait","max","addOne","timing","Subscription","SourceIterable","Head","Tail","TypeOfSource","TypeOfSourceArray","Sources","prop","Property","Record","global","SymbolConstructor","observable","closed","error","subscribe","ObservableObserver","Symbol","Observable","ObservableSubscription","onNext","onError","onComplete","ObservableLike","input","I","O","t","Callbag","d","callbag","R","A","UnaryFn","op1","B","op2","C","op3","D","op4","E","op5","F","op6","G","op7","H","op8","consumer","pipe","args","T","K","Pick","Nil","Promise","P","L","R","Exclude","U","Constructable","Id","OptionalPropertyNames","SpreadProperties","A","SpreadTwo","Spread","Array","DeepPartial","ReadonlyArray","DeepWriteable","Record","Omit","Partial","NonNullable","JsonPrimitive","Json","key","arg","I","HasRequiredProperty","TDoc","TStorage","CrdtType","_initialStorage","builder","getEmpty","CrdtDocLike","getFactory","initialStorage","CrdtDocFactory","getInitialized","isEmpty","Maybe","doc","value","kind","TValue","TJson","__pluvType","IJson","InferCrdtJson","origin","update","Uint8Array","updates","local","applyEncodedState","DocApplyEncodedStateParams","params","batchApplyEncodedState","DocBatchApplyEncodedStateParams","canRedo","canUndo","destroy","get","TKey","getEncodedState","rebuildStorage","reference","redo","subscribe","DocSubscribeCallbackParams","listener","toJson","type","track","transact","fn","undo","Closed","Connecting","Open","Unavailable","Untouched","ConnectionState","Loading","Offline","Synced","StorageState","id","$getOthers","$initializeSession","presence","JsonObject","$ping","$updatePresence","$updateStorage","InferEventMessage","BaseClientEventRecord","TAuthorize","IOAuthorize","$error","message","stack","$exit","sessionId","$othersReceived","others","connectionId","room","timers","user","InferIOAuthorizeUser","$pong","$presenceUpdated","$registered","state","$storageReceived","changeKind","$storageUpdated","$syncStateReceived","connectionIds","$userJoined","TEvent","TData","data","EventRecord","EventMessage","TIO","IOLike","IAuthorize","BaseUser","InputZodLike","IUser","parse","_input","_zod","input","TUser","TContext","secret","context","InferIOAuthorize","TInput","TOutput","config","broadcast","MaybePromise","resolver","self","sync","TEvents","ProcedureLike","_defs","events","TCrdt","CrdtLibraryType","IORouterLike","authorize","crdt","ICrdt","IDoc","IEvents","InferIOProcedureInput","InferIOProcedureOutput","TProcedure","IInput","IOutput","UnionToIntersection","TRouter","InferEventsInput","InferEventsOutput","InferIOOutput","IOAuthorizeEventMessage","TClientEvents","PluvRouterEventConfig","TServerIO","IServerEvents","IClientInput","IClientOutput","token","TPresence","UserInfo","OtherSubscriptionCallback","callback","users","OthersSubscriptionEvent","event","OthersSubscriptionCallback","connection","Subject","WebSocketState","myself","Readonly","TSubject","StateNotifierSubjects","IValue","InferSubjectValue","oldPresence","attempts","authorization","AuthorizationState","WebSocketConnection","storage","StorageInfo","webSocket","WebSocket","InferIOInput","MergeEvents","PEvent","IOEventMessage","EventNotifierSubscriptionCallback","EventSubscriptionFn","StorageSubscriptionCallback","StorageRootSubscriptionCallback","StorageSubscriptionFn","StorageRootSubscriptionFn","PKey","name","SubscriptionCallback","SubscribeFn","EventProxy","myPresence","other","OtherSubscriptionFn","OthersSubscriptionFn","StorageProxy","storageLoaded","close","CloseEvent","error","Event","MessageEvent","open","BroadcastProxy","addEventListener","TKind","RoomEventListenerMap","handler","getDoc","getConnection","getMyPresence","getMyself","getOther","getOthers","getStorage","getStorageJson","getStorageLoaded","SubscribeProxy","updateMyPresence","UpdateMyPresenceAction"],"sources":["../../../node_modules/.pnpm/wonka@6.3.6/node_modules/wonka/dist/wonka.d.ts","../../types/dist/index.d.mts","../src/addonIndexedDB.ts"],"x_google_ignoreList":[0],"mappings":";;;;QAmuCQoE,MAAAA;EAAAA,UACMC,iBAAAA;IAAAA,SACGC,UAAAA;EAAAA;AAAAA;;;;;;;;;;;;;;KC9tCZ,KAAA,MAAW,CAAA,GAAI,GAAG;AAAA,KAClB,YAAA,MAAkB,OAAA,CAAQ,CAAA,IAAK,CAAA;AAAA,KAE/B,GAAA;AAAA,KAWA,aAAA;AAAA,KACA,IAAA,GAAO,aAAA,GAAgB,IAAA,cAAkB,IAAA;EAAA,CAC3CmE,GAAAA,WAAc,IAAA;AAAA;AAAA,KAEZ,UAAA,GAAa,MAAM,SAAS,IAAA;AAAA;AAAA;AAAA,UAKvB,cAAA,oCAAkD,MAAA,SAAe,QAAA;EACzEO,eAAAA,GAAkBC,OAAAA,UAAiB,QAAA;EACnCC,QAAAA,IAAY,WAAA,CAAY,IAAA,EAAM,QAAA;EAC9BE,UAAAA,CAAWC,cAAAA,IAAkBJ,OAAAA,UAAiB,QAAA,GAAW,cAAA,CAAe,IAA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IAAAA,EAAM,MAAA,KAAW/H,IAAAA,YAAgB,YAAA,CAAa,OAAA,CAAQ,OAAA;IAC/DwJ,IAAAA,KAASzB,IAAAA,EAAM,MAAA,KAAW/H,IAAAA,YAAgB,YAAA,CAAa,OAAA,CAAQ,OAAA;EAAA;AAAA;AAAA,UAGzD,YAAA,iBAA6B,MAAA,SAAe,aAAA;EACpD2J,KAAAA;IACEC,MAAAA,EAAQ,OAAA;EAAA;AAAA;AAAA,UAGF,MAAA,oBAA0B,WAAA,wCAAmD,eAAA,QAAuB,eAAA,uBAAsC,MAAA,SAAe,aAAA,0BAAuC,YAAA,CAAa,OAAA;EACrND,KAAAA;IACEK,SAAAA,EAAW,UAAA;IACXC,IAAAA,EAAM,KAAA;IACNL,MAAAA,EAAQ,OAAA;EAAA;AAAA;;;UCvNK,oBAAA,aACD,MAAA,mCACM,UAAA,oBACA,MAAA,6BACJ,sBAAA;EAEd,OAAA,eAAsB,IAAA,EAAM,QAAA,CAAS,GAAA,EAAK,SAAA,EAAW,SAAA,EAAW,KAAA;AAAA;AAAA,cAGvD,cAAA,eACG,MAAA,mCACM,UAAA,oBACA,MAAA,6BACJ,sBAAA,YAEd,MAAA,GAAS,oBAAA,CAAqB,GAAA,EAAK,SAAA,EAAW,SAAA,EAAW,KAAA,MAC1D,aAAA,CAAc,GAAA,EAAK,SAAA,EAAW,SAAA,EAAW,KAAA"}
package/dist/index.mjs DELETED
@@ -1,88 +0,0 @@
1
- import { AbstractStorageStore } from "@pluv/client";
2
- import { openDB } from "idb";
3
- //#region src/IndexedDBStorage.ts
4
- const STORAGE_STORE_FLATTEN_THRESHOLD = 500;
5
- const UPGRADES_KEY = "__PLUV_UPDATES";
6
- var IndexedDBStorage = class extends AbstractStorageStore {
7
- constructor(room) {
8
- super(room);
9
- this._db = null;
10
- this._dbRef = 0;
11
- this._dbSize = 0;
12
- this.room = room;
13
- }
14
- async addUpdate(update) {
15
- const db = this._db;
16
- if (!db) return;
17
- await db.add(UPGRADES_KEY, update);
18
- this._dbSize += 1;
19
- }
20
- destroy() {
21
- if (!this._db) return Promise.resolve();
22
- this._db.close();
23
- this._db = null;
24
- this._dbRef = 0;
25
- this._dbSize = 0;
26
- return Promise.resolve();
27
- }
28
- async flatten(encodedState) {
29
- const db = this._db;
30
- if (!db) return;
31
- await db.add(UPGRADES_KEY, encodedState);
32
- await db.delete(UPGRADES_KEY, this._getUpperBound(this._dbRef, true));
33
- this._dbSize = await this._getSize();
34
- }
35
- async getShouldFlatten() {
36
- return await this._getSize() >= STORAGE_STORE_FLATTEN_THRESHOLD;
37
- }
38
- async getUpdates(start = 0) {
39
- const db = this._db;
40
- if (!db) return [];
41
- const updates = await db.getAll(UPGRADES_KEY, this._getLowerBound(start));
42
- const lastKey = await this._getLastKey();
43
- this._dbRef = lastKey + 1;
44
- return updates;
45
- }
46
- async initialize() {
47
- const newDB = await openDB(this.room, void 0, { upgrade: (db) => {
48
- db.createObjectStore(UPGRADES_KEY, { autoIncrement: true });
49
- } });
50
- newDB.addEventListener("versionchange", () => {
51
- newDB.close();
52
- });
53
- if (typeof window !== "undefined") window.addEventListener("unload", () => {
54
- newDB.close();
55
- });
56
- this._db = newDB;
57
- }
58
- async _getLastKey() {
59
- const db = this._db;
60
- if (!db) throw new Error("IndexedDB not initialized");
61
- return (await db.transaction(UPGRADES_KEY).objectStore(UPGRADES_KEY).openCursor(null, "prev"))?.key ?? -1;
62
- }
63
- _getLowerBound(lower, open = false) {
64
- return IDBKeyRange.lowerBound(lower, open);
65
- }
66
- async _getSize() {
67
- if (this._dbSize) return this._dbSize;
68
- const db = this._db;
69
- if (!db) throw new Error("IndexedDB not initialized");
70
- return db.transaction(UPGRADES_KEY).objectStore(UPGRADES_KEY).count();
71
- }
72
- _getUpperBound(upper, open = false) {
73
- return IDBKeyRange.upperBound(upper, open);
74
- }
75
- };
76
- //#endregion
77
- //#region src/addonIndexedDB.ts
78
- const addonIndexedDB = (config) => {
79
- const { enabled = true } = config ?? {};
80
- return ({ room }) => {
81
- if (!(typeof enabled === "boolean" ? enabled : enabled(room))) return {};
82
- return { storage: new IndexedDBStorage(room.id) };
83
- };
84
- };
85
- //#endregion
86
- export { addonIndexedDB };
87
-
88
- //# sourceMappingURL=index.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../src/IndexedDBStorage.ts","../src/addonIndexedDB.ts"],"sourcesContent":["import { AbstractStorageStore } from \"@pluv/client\";\nimport type { IDBPDatabase } from \"idb\";\nimport { openDB } from \"idb\";\n\nconst STORAGE_STORE_FLATTEN_THRESHOLD = 500;\nconst UPGRADES_KEY = \"__PLUV_UPDATES\";\n\ntype IndexDBSchema = {\n [UPGRADES_KEY]: {\n key: number;\n value: string;\n };\n};\n\ntype IndexedDB = IDBPDatabase<IndexDBSchema>;\n\nexport class IndexedDBStorage extends AbstractStorageStore {\n public room: string;\n\n private _db: IndexedDB | null = null;\n private _dbRef: number = 0;\n private _dbSize: number = 0;\n\n constructor(room: string) {\n super(room);\n\n this.room = room;\n }\n\n public async addUpdate(update: string): Promise<void> {\n const db = this._db;\n\n if (!db) return;\n\n await db.add(UPGRADES_KEY, update);\n\n this._dbSize += 1;\n }\n\n public destroy(): Promise<void> {\n if (!this._db) return Promise.resolve();\n\n this._db.close();\n this._db = null;\n this._dbRef = 0;\n this._dbSize = 0;\n\n return Promise.resolve();\n }\n\n public async flatten(encodedState: string): Promise<void> {\n const db = this._db;\n\n if (!db) return;\n\n await db.add(UPGRADES_KEY, encodedState);\n await db.delete(UPGRADES_KEY, this._getUpperBound(this._dbRef, true));\n\n this._dbSize = await this._getSize();\n }\n\n public async getShouldFlatten(): Promise<boolean> {\n const dbSize = await this._getSize();\n\n return dbSize >= STORAGE_STORE_FLATTEN_THRESHOLD;\n }\n\n public async getUpdates(start: number = 0): Promise<readonly string[]> {\n const db = this._db;\n\n if (!db) return [];\n\n const updates = await db.getAll(UPGRADES_KEY, this._getLowerBound(start));\n\n const lastKey = await this._getLastKey();\n\n this._dbRef = lastKey + 1;\n\n return updates;\n }\n\n public async initialize(): Promise<void> {\n const newDB = await openDB<IndexDBSchema>(this.room, undefined, {\n upgrade: (db) => {\n db.createObjectStore(UPGRADES_KEY, { autoIncrement: true });\n },\n });\n\n newDB.addEventListener(\"versionchange\", () => {\n newDB.close();\n });\n\n if (typeof window !== \"undefined\") {\n window.addEventListener(\"unload\", () => {\n newDB.close();\n });\n }\n\n this._db = newDB;\n }\n\n private async _getLastKey(): Promise<number> {\n const db = this._db;\n\n if (!db) throw new Error(\"IndexedDB not initialized\");\n\n const store = db.transaction(UPGRADES_KEY).objectStore(UPGRADES_KEY);\n const cursor = await store.openCursor(null, \"prev\");\n\n return cursor?.key ?? -1;\n }\n\n private _getLowerBound(lower: number, open: boolean = false): IDBKeyRange {\n return IDBKeyRange.lowerBound(lower, open);\n }\n\n private async _getSize(): Promise<number> {\n if (this._dbSize) return this._dbSize;\n\n const db = this._db;\n\n if (!db) throw new Error(\"IndexedDB not initialized\");\n\n const store = db.transaction(UPGRADES_KEY).objectStore(UPGRADES_KEY);\n\n return store.count();\n }\n\n private _getUpperBound(upper: number, open: boolean = false): IDBKeyRange {\n return IDBKeyRange.upperBound(upper, open);\n }\n}\n","import type { PluvRoom, PluvRoomAddon } from \"@pluv/client\";\nimport type { AbstractCrdtDocFactory, CrdtType } from \"@pluv/crdt\";\nimport type { IOLike, JsonObject } from \"@pluv/types\";\nimport { IndexedDBStorage } from \"./IndexedDBStorage\";\n\nexport interface AddonIndexedDBConfig<\n TIO extends IOLike<any, any, any>,\n TMetadata extends JsonObject,\n TPresence extends Record<string, any>,\n TCrdt extends AbstractCrdtDocFactory<any, any>,\n> {\n enabled?: boolean | ((room: PluvRoom<TIO, TMetadata, TPresence, TCrdt>) => boolean);\n}\n\nexport const addonIndexedDB = <\n TIO extends IOLike<any, any, any>,\n TMetadata extends JsonObject,\n TPresence extends Record<string, any>,\n TCrdt extends AbstractCrdtDocFactory<any, any>,\n>(\n config?: AddonIndexedDBConfig<TIO, TMetadata, TPresence, TCrdt>,\n): PluvRoomAddon<TIO, TMetadata, TPresence, TCrdt> => {\n const { enabled = true } = config ?? {};\n\n return ({ room }) => {\n const _enabled = typeof enabled === \"boolean\" ? enabled : enabled(room);\n\n if (!_enabled) return {};\n\n return {\n storage: new IndexedDBStorage(room.id),\n };\n };\n};\n"],"mappings":";;;AAIA,MAAM,kCAAkC;AACxC,MAAM,eAAe;AAWrB,IAAa,mBAAb,cAAsC,qBAAqB;CAOvD,YAAY,MAAc;EACtB,MAAM,IAAI;aALkB;gBACP;iBACC;EAKtB,KAAK,OAAO;CAChB;CAEA,MAAa,UAAU,QAA+B;EAClD,MAAM,KAAK,KAAK;EAEhB,IAAI,CAAC,IAAI;EAET,MAAM,GAAG,IAAI,cAAc,MAAM;EAEjC,KAAK,WAAW;CACpB;CAEA,UAAgC;EAC5B,IAAI,CAAC,KAAK,KAAK,OAAO,QAAQ,QAAQ;EAEtC,KAAK,IAAI,MAAM;EACf,KAAK,MAAM;EACX,KAAK,SAAS;EACd,KAAK,UAAU;EAEf,OAAO,QAAQ,QAAQ;CAC3B;CAEA,MAAa,QAAQ,cAAqC;EACtD,MAAM,KAAK,KAAK;EAEhB,IAAI,CAAC,IAAI;EAET,MAAM,GAAG,IAAI,cAAc,YAAY;EACvC,MAAM,GAAG,OAAO,cAAc,KAAK,eAAe,KAAK,QAAQ,IAAI,CAAC;EAEpE,KAAK,UAAU,MAAM,KAAK,SAAS;CACvC;CAEA,MAAa,mBAAqC;EAG9C,OAAO,MAFc,KAAK,SAAS,KAElB;CACrB;CAEA,MAAa,WAAW,QAAgB,GAA+B;EACnE,MAAM,KAAK,KAAK;EAEhB,IAAI,CAAC,IAAI,OAAO,CAAC;EAEjB,MAAM,UAAU,MAAM,GAAG,OAAO,cAAc,KAAK,eAAe,KAAK,CAAC;EAExE,MAAM,UAAU,MAAM,KAAK,YAAY;EAEvC,KAAK,SAAS,UAAU;EAExB,OAAO;CACX;CAEA,MAAa,aAA4B;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