@pluv/addon-indexeddb 3.2.1 → 4.0.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/.turbo/turbo-build.log +16 -16
- package/CHANGELOG.md +27 -0
- package/dist/index.d.mts +129 -5
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +83 -128
- package/dist/index.mjs.map +1 -0
- package/package.json +18 -14
- package/tsdown.config.ts +14 -0
- package/dist/index.d.ts +0 -10
- package/dist/index.js +0 -160
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
|
|
2
|
-
> @pluv/addon-indexeddb@
|
|
3
|
-
>
|
|
2
|
+
> @pluv/addon-indexeddb@4.0.0 build /home/runner/work/pluv/pluv/packages/addon-indexeddb
|
|
3
|
+
> tsdown
|
|
4
4
|
|
|
5
|
-
[
|
|
6
|
-
[
|
|
7
|
-
[
|
|
8
|
-
[
|
|
9
|
-
[
|
|
10
|
-
[
|
|
11
|
-
[
|
|
12
|
-
[
|
|
13
|
-
[
|
|
14
|
-
[
|
|
15
|
-
[
|
|
16
|
-
[
|
|
17
|
-
|
|
18
|
-
[
|
|
5
|
+
[34mℹ[39m tsdown [2mv0.20.0-beta.4[22m powered by rolldown [2mv1.0.0-beta.60[22m
|
|
6
|
+
[34mℹ[39m config file: [4m/home/runner/work/pluv/pluv/packages/addon-indexeddb/tsdown.config.ts[24m
|
|
7
|
+
[34mℹ[39m entry: [34msrc/index.ts[39m
|
|
8
|
+
[34mℹ[39m target: [34mesnext[39m
|
|
9
|
+
[34mℹ[39m tsconfig: [34mtsconfig.json[39m
|
|
10
|
+
[34mℹ[39m Build start
|
|
11
|
+
[34mℹ[39m [2mdist/[22m[1mindex.mjs[22m [2m2.56 kB[22m [2m│ gzip: 0.94 kB[22m
|
|
12
|
+
[34mℹ[39m [2mdist/[22mindex.d.mts.map [2m9.01 kB[22m [2m│ gzip: 3.20 kB[22m
|
|
13
|
+
[34mℹ[39m [2mdist/[22mindex.mjs.map [2m6.54 kB[22m [2m│ gzip: 2.09 kB[22m
|
|
14
|
+
[34mℹ[39m [2mdist/[22m[32m[1mindex.d.mts[22m[39m [2m5.84 kB[22m [2m│ gzip: 1.85 kB[22m
|
|
15
|
+
[33m[PLUGIN_TIMINGS] Warning:[0m Your build spent significant time in plugin `rolldown-plugin-dts:generate`. See https://rolldown.rs/options/checks#plugintimings for more details.
|
|
16
|
+
[34mℹ[39m 4 files, total: 23.95 kB
|
|
17
|
+
|
|
18
|
+
[32m✔[39m Build complete in [32m3611ms[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
# @pluv/addon-indexeddb
|
|
2
2
|
|
|
3
|
+
## 4.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- df5c39c: Update all packages to be ESM only.
|
|
8
|
+
|
|
9
|
+
### Minor Changes
|
|
10
|
+
|
|
11
|
+
- 037074e: Migrated build process from tsup to tsdown.
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- 2eb5def: Bumped dependencies.
|
|
16
|
+
- Updated dependencies [2eb5def]
|
|
17
|
+
- Updated dependencies [df5c39c]
|
|
18
|
+
- Updated dependencies [037074e]
|
|
19
|
+
- @pluv/client@4.0.0
|
|
20
|
+
- @pluv/crdt@4.0.0
|
|
21
|
+
|
|
22
|
+
## 3.2.2
|
|
23
|
+
|
|
24
|
+
### Patch Changes
|
|
25
|
+
|
|
26
|
+
- Updated dependencies [8665dbe]
|
|
27
|
+
- @pluv/client@3.2.2
|
|
28
|
+
- @pluv/crdt@3.2.2
|
|
29
|
+
|
|
3
30
|
## 3.2.1
|
|
4
31
|
|
|
5
32
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -1,10 +1,134 @@
|
|
|
1
|
-
import { PluvRoom, PluvRoomAddon } from
|
|
2
|
-
import { AbstractCrdtDocFactory } from
|
|
3
|
-
import { IOLike, JsonObject } from '@pluv/types';
|
|
1
|
+
import { PluvRoom, PluvRoomAddon } from "@pluv/client";
|
|
2
|
+
import { AbstractCrdtDocFactory } from "@pluv/crdt";
|
|
4
3
|
|
|
4
|
+
//#region ../../node_modules/.pnpm/wonka@6.3.5/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
|
|
5
128
|
interface AddonIndexedDBConfig<TIO extends IOLike<any, any, any>, TMetadata extends JsonObject, TPresence extends Record<string, any>, TCrdt extends AbstractCrdtDocFactory<any, any>> {
|
|
6
|
-
|
|
129
|
+
enabled?: boolean | ((room: PluvRoom<TIO, TMetadata, TPresence, TCrdt>) => boolean);
|
|
7
130
|
}
|
|
8
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>;
|
|
9
|
-
|
|
132
|
+
//#endregion
|
|
10
133
|
export { addonIndexedDB };
|
|
134
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":["TalkbackKind","Pull","Close","TalkbackFn","signal","TeardownFn","SignalKind","Start","Push","End","Tag","T","tag","_T","Signal","Sink","Source","sink","Operator","In","Out","a","TypeOfSource","U","Subscription","unsubscribe","Observer","next","value","complete","Subject","source","SourceIterable","AsyncIterator","AsyncIterable","lazy","produce","fromAsyncIterable","iterable","fromIterable","Iterable","fromArray","array","fromValue","make","observer","subscriber","makeSubject","empty","never","interval","ms","fromDomEvent","HTMLElement","Event","element","event","fromPromise","Promise","promise","buffer","S","notifier","concatMap","map","concatAll","concat","sources","filter","predicate","mergeMap","mergeAll","merge","onEnd","callback","onPush","onStart","sample","scan","acc","reducer","seed","share","skip","wait","skipUntil","skipWhile","switchMap","switchAll","take","max","takeLast","takeUntil","takeWhile","addOne","debounce","timing","delay","throttle","subscribe","forEach","publish","toAsyncIterable","toArray","toPromise","TypeOfSourceArray","Head","Tail","zip","Sources","Property","prop","Record","combine","_0","global","SymbolConstructor","observable","sideEffect","ObservableSubscription","closed","ObservableObserver","error","ObservableLike","Observable","Symbol","onNext","onError","onComplete","fromObservable","input","toObservable","Callbag","I","O","t","d","fromCallbag","callbag","toCallbag","UnaryFn","R","pipe","A","B","C","D","E","F","G","H","op1","op2","op3","op4","op5","op6","op7","op8","consumer","flatten","tap","Subject","Constructable","args","HasRequiredProperty","T","K","Pick","Maybe","Nil","MaybePromise","Promise","MaybeReadonlyArray","OptionalPropertyNames","P","SpreadProperties","L","R","Exclude","Id","U","SpreadTwo","Spread","A","DeepPartial","Array","ReadonlyArray","DeepWriteable","UndefinedProps","Record","OptionalProps","Omit","Partial","NonNilProps","NonNullable","JsonPrimitive","Json","key","JsonObject","UnionToIntersection","arg","I","AreAllOptional","CrdtDocFactory","TDoc","TStorage","CrdtType","CrdtDocLike","_initialStorage","builder","getEmpty","getFactory","initialStorage","getInitialized","isEmpty","CrdtLibraryType","doc","value","kind","TValue","TJson","__pluvType","InferCrdtJson","IJson","DocApplyEncodedStateParams","Uint8Array","origin","update","DocBatchApplyEncodedStateParams","updates","DocSubscribeCallbackParams","local","TKey","applyEncodedState","params","batchApplyEncodedState","canRedo","canUndo","destroy","get","getEncodedState","rebuildStorage","reference","redo","subscribe","listener","toJson","type","track","transact","fn","undo","ConnectionState","Closed","Connecting","Open","Unavailable","Untouched","StorageState","Loading","Offline","Synced","BaseUser","id","BaseClientEventRecord","$getOthers","$initializeSession","presence","$ping","$updatePresence","$updateStorage","BaseClientMessage","InferEventMessage","BaseIOEventRecord","TAuthorize","IOAuthorize","InferIOAuthorizeUser","$error","message","stack","$exit","sessionId","$othersReceived","others","connectionId","room","timers","user","$pong","$presenceUpdated","$registered","state","$storageReceived","changeKind","$storageUpdated","$syncStateReceived","connectionIds","$userJoined","EventMessage","TEvent","TData","data","EventRecord","GetEventMessage","InferIOAuthorize","TIO","IOLike","IAuthorize","InputZodLike","IUser","parse","_input","_zod","input","TUser","TContext","secret","context","IOAuthorizeEventMessage","ProcedureLike","TInput","TOutput","config","broadcast","resolver","self","sync","IORouterLike","TEvents","_defs","events","TCrdt","authorize","crdt","InferIOCrdtKind","ICrdt","IDoc","InferIOCrdt","InferIOEvents","IEvents","InferIOProcedureInput","InferIOProcedureOutput","TProcedure","IInput","IOutput","InferEventsInput","InferEventsOutput","InferIOInput","TRouter","InferIOOutput","IOEventMessage","PluvRouterEventConfig","MergeEvents","TClientEvents","TServerIO","IClientOutput","IServerEvents","IClientInput","AuthorizationState","token","OtherSubscriptionCallback","TPresence","UserInfo","OtherSubscriptionFn","callback","OthersSubscriptionEvent","users","OthersSubscriptionCallback","event","OthersSubscriptionFn","StateNotifierSubjects","WebSocketState","Readonly","connection","myself","InferSubjectValue","TSubject","IValue","SubscriptionCallback","UpdateMyPresenceAction","oldPresence","WebSocketConnection","attempts","StorageInfo","WebSocket","authorization","storage","webSocket","BroadcastProxy","PEvent","EventNotifierSubscriptionCallback","EventSubscriptionFn","EventProxy","StorageSubscriptionCallback","StorageSubscriptionFn","StorageRootSubscriptionCallback","StorageRootSubscriptionFn","StorageProxy","PKey","SubscribeFn","SubscribeProxy","name","myPresence","other","storageLoaded","RoomEventListenerMap","CloseEvent","Event","MessageEvent","close","error","open","RoomLike","TKind","addEventListener","handler","getDoc","getConnection","getMyPresence","getMyself","getOther","getOthers","getStorage","getStorageJson","getStorageLoaded","updateMyPresence"],"sources":["../../../node_modules/.pnpm/wonka@6.3.5/node_modules/wonka/dist/wonka.d.ts","../../types/dist/index.d.mts","../src/addonIndexedDB.ts"],"x_google_ignoreList":[0],"mappings":";;;;QAmuCQmH,MAAAA;EAAAA,UACMC,iBAAAA;IAAAA,SACGC,UAAAA;EAAAA;AAAAA;;;;;;;;;;;;;;KC9tCZoD,KAAAA,MAAWH,CAAAA,GAAII,GAAAA;AAAAA,KACfC,YAAAA,MAAkBC,OAAAA,CAAQN,CAAAA,IAAKA,CAAAA;AAAAA,KAE/BI,GAAAA;AAAAA,KAWA0B,aAAAA;AAAAA,KACAC,IAAAA,GAAOD,aAAAA,GAAgBC,IAAAA,cAAkBA,IAAAA;EAAAA,CAC3CC,GAAAA,WAAcD,IAAAA;AAAAA;AAAAA,KAEZE,UAAAA,GAAaT,MAAAA,SAAeO,IAAAA;AAAAA;AAAAA;AAAAA,UAKvBO,cAAAA,oCAAkDd,MAAAA,SAAeiB,QAAAA;EACzEE,eAAAA,GAAkBC,OAAAA,UAAiBJ,QAAAA;EACnCK,QAAAA,IAAYH,WAAAA,CAAYH,IAAAA,EAAMC,QAAAA;EAC9BM,UAAAA,CAAWC,cAAAA,IAAkBH,OAAAA,UAAiBJ,QAAAA,GAAWF,cAAAA,CAAeC,IAAAA,EAAMC,QAAAA;EAC9EQ,cAAAA,CAAeD,cAAAA,IAAkBH,OAAAA,UAAiBJ,QAAAA,GAAWE,WAAAA,CAAYH,IAAAA,EAAMC,QAAAA;EAC/ES,OAAAA,CAAQF,cAA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{
|
|
3
|
-
var fulfilled = (value) => {
|
|
4
|
-
try {
|
|
5
|
-
step(generator.next(value));
|
|
6
|
-
} catch (e) {
|
|
7
|
-
reject(e);
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
|
-
var rejected = (value) => {
|
|
11
|
-
try {
|
|
12
|
-
step(generator.throw(value));
|
|
13
|
-
} catch (e) {
|
|
14
|
-
reject(e);
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
// src/IndexedDBStorage.ts
|
|
23
1
|
import { AbstractStorageStore } from "@pluv/client";
|
|
24
2
|
import { openDB } from "idb";
|
|
25
|
-
|
|
26
|
-
|
|
3
|
+
|
|
4
|
+
//#region src/IndexedDBStorage.ts
|
|
5
|
+
const STORAGE_STORE_FLATTEN_THRESHOLD = 500;
|
|
6
|
+
const UPGRADES_KEY = "__PLUV_UPDATES";
|
|
27
7
|
var IndexedDBStorage = class extends AbstractStorageStore {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
return __async(this, null, function* () {
|
|
96
|
-
var _a;
|
|
97
|
-
const db = this._db;
|
|
98
|
-
if (!db) throw new Error("IndexedDB not initialized");
|
|
99
|
-
const store = db.transaction(UPGRADES_KEY).objectStore(UPGRADES_KEY);
|
|
100
|
-
const cursor = yield store.openCursor(null, "prev");
|
|
101
|
-
return (_a = cursor == null ? void 0 : cursor.key) != null ? _a : -1;
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
_getLowerBound(lower, open = false) {
|
|
105
|
-
return IDBKeyRange.lowerBound(lower, open);
|
|
106
|
-
}
|
|
107
|
-
_getSize() {
|
|
108
|
-
return __async(this, null, function* () {
|
|
109
|
-
if (this._dbSize) return this._dbSize;
|
|
110
|
-
const db = this._db;
|
|
111
|
-
if (!db) throw new Error("IndexedDB not initialized");
|
|
112
|
-
const store = db.transaction(UPGRADES_KEY).objectStore(UPGRADES_KEY);
|
|
113
|
-
return store.count();
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
_getUpperBound(upper, open = false) {
|
|
117
|
-
return IDBKeyRange.upperBound(upper, open);
|
|
118
|
-
}
|
|
8
|
+
constructor(room) {
|
|
9
|
+
super(room);
|
|
10
|
+
this._db = null;
|
|
11
|
+
this._dbRef = 0;
|
|
12
|
+
this._dbSize = 0;
|
|
13
|
+
this.room = room;
|
|
14
|
+
}
|
|
15
|
+
async addUpdate(update) {
|
|
16
|
+
const db = this._db;
|
|
17
|
+
if (!db) return;
|
|
18
|
+
await db.add(UPGRADES_KEY, update);
|
|
19
|
+
this._dbSize += 1;
|
|
20
|
+
}
|
|
21
|
+
destroy() {
|
|
22
|
+
if (!this._db) return Promise.resolve();
|
|
23
|
+
this._db.close();
|
|
24
|
+
this._db = null;
|
|
25
|
+
this._dbRef = 0;
|
|
26
|
+
this._dbSize = 0;
|
|
27
|
+
return Promise.resolve();
|
|
28
|
+
}
|
|
29
|
+
async flatten(encodedState) {
|
|
30
|
+
const db = this._db;
|
|
31
|
+
if (!db) return;
|
|
32
|
+
await db.add(UPGRADES_KEY, encodedState);
|
|
33
|
+
await db.delete(UPGRADES_KEY, this._getUpperBound(this._dbRef, true));
|
|
34
|
+
this._dbSize = await this._getSize();
|
|
35
|
+
}
|
|
36
|
+
async getShouldFlatten() {
|
|
37
|
+
return await this._getSize() >= STORAGE_STORE_FLATTEN_THRESHOLD;
|
|
38
|
+
}
|
|
39
|
+
async getUpdates(start = 0) {
|
|
40
|
+
const db = this._db;
|
|
41
|
+
if (!db) return [];
|
|
42
|
+
const updates = await db.getAll(UPGRADES_KEY, this._getLowerBound(start));
|
|
43
|
+
this._dbRef = await this._getLastKey() + 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
|
+
}
|
|
119
75
|
};
|
|
120
76
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
};
|
|
130
|
-
};
|
|
131
|
-
};
|
|
132
|
-
export {
|
|
133
|
-
addonIndexedDB
|
|
77
|
+
//#endregion
|
|
78
|
+
//#region src/addonIndexedDB.ts
|
|
79
|
+
const addonIndexedDB = (config) => {
|
|
80
|
+
const { enabled = true } = config ?? {};
|
|
81
|
+
return ({ room }) => {
|
|
82
|
+
if (!(typeof enabled === "boolean" ? enabled : enabled(room))) return {};
|
|
83
|
+
return { storage: new IndexedDBStorage(room.id) };
|
|
84
|
+
};
|
|
134
85
|
};
|
|
86
|
+
|
|
87
|
+
//#endregion
|
|
88
|
+
export { addonIndexedDB };
|
|
89
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
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;AACtB,QAAM,KAAK;aALiB;gBACP;iBACC;AAKtB,OAAK,OAAO;;CAGhB,MAAa,UAAU,QAA+B;EAClD,MAAM,KAAK,KAAK;AAEhB,MAAI,CAAC,GA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Ae,OAAe,OAAgB,OAAoB;AACtE,SAAO,YAAY,WAAW,OAAO,KAAK;;CAG9C,MAAc,WAA4B;AACtC,MAAI,KAAK,QAAS,QAAO,KAAK;EAE9B,MAAM,KAAK,KAAK;AAEhB,MAAI,CAAC,GAAI,OAAM,IAAI,MAAM,4BAA4B;AAIrD,SAFc,GAAG,YAAY,aAAa,CAAC,YAAY,aAAa,CAEvD,OAAO;;CAGxB,AAAQ,eAAe,OAAe,OAAgB,OAAoB;AACtE,SAAO,YAAY,WAAW,OAAO,KAAK;;;;;;ACnHlD,MAAa,kBAMT,WACkD;CAClD,MAAM,EAAE,UAAU,SAAS,UAAU,EAAE;AAEvC,SAAQ,EAAE,WAAW;AAGjB,MAAI,EAFa,OAAO,YAAY,YAAY,UAAU,QAAQ,KAAK,EAExD,QAAO,EAAE;AAExB,SAAO,EACH,SAAS,IAAI,iBAAiB,KAAK,GAAG,EACzC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pluv/addon-indexeddb",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "@pluv/io indexeddb for client storage persistence",
|
|
5
5
|
"author": {
|
|
6
6
|
"email": "david@pluv.io",
|
|
@@ -14,29 +14,33 @@
|
|
|
14
14
|
"url": "git+https://github.com/pluv-io/pluv.git",
|
|
15
15
|
"directory": "packages/addon-indexeddb"
|
|
16
16
|
},
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"types": "./dist/index.d.ts",
|
|
17
|
+
"type": "module",
|
|
18
|
+
"types": "./dist/index.d.mts",
|
|
20
19
|
"publishConfig": {
|
|
21
20
|
"access": "public"
|
|
22
21
|
},
|
|
23
22
|
"dependencies": {
|
|
24
23
|
"idb": "^8.0.3",
|
|
25
|
-
"@pluv/client": "^
|
|
26
|
-
"@pluv/crdt": "^
|
|
24
|
+
"@pluv/client": "^4.0.0",
|
|
25
|
+
"@pluv/crdt": "^4.0.0"
|
|
27
26
|
},
|
|
28
27
|
"devDependencies": {
|
|
29
|
-
"eslint": "^9.
|
|
30
|
-
"
|
|
31
|
-
"typescript": "^5.
|
|
32
|
-
"@pluv/tsconfig": "^
|
|
33
|
-
"@pluv/types": "^
|
|
34
|
-
"eslint-config-pluv": "^
|
|
28
|
+
"eslint": "^9.39.2",
|
|
29
|
+
"tsdown": "0.20.0-beta.4",
|
|
30
|
+
"typescript": "^5.9.3",
|
|
31
|
+
"@pluv/tsconfig": "^4.0.0",
|
|
32
|
+
"@pluv/types": "^4.0.0",
|
|
33
|
+
"eslint-config-pluv": "^4.0.0"
|
|
34
|
+
},
|
|
35
|
+
"exports": {
|
|
36
|
+
".": "./dist/index.mjs",
|
|
37
|
+
"./*": "./*"
|
|
35
38
|
},
|
|
36
39
|
"scripts": {
|
|
37
|
-
"build": "
|
|
38
|
-
"dev": "
|
|
40
|
+
"build": "tsdown",
|
|
41
|
+
"dev": "tsdown --watch",
|
|
39
42
|
"lint": "eslint \"src/**/*.ts*\" --fix --max-warnings 0",
|
|
43
|
+
"typecheck": "tsc --noEmit",
|
|
40
44
|
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist"
|
|
41
45
|
}
|
|
42
46
|
}
|
package/tsdown.config.ts
ADDED
package/dist/index.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { PluvRoom, PluvRoomAddon } from '@pluv/client';
|
|
2
|
-
import { AbstractCrdtDocFactory } from '@pluv/crdt';
|
|
3
|
-
import { IOLike, JsonObject } from '@pluv/types';
|
|
4
|
-
|
|
5
|
-
interface AddonIndexedDBConfig<TIO extends IOLike<any, any, any>, TMetadata extends JsonObject, TPresence extends Record<string, any>, TCrdt extends AbstractCrdtDocFactory<any, any>> {
|
|
6
|
-
enabled?: boolean | ((room: PluvRoom<TIO, TMetadata, TPresence, TCrdt>) => boolean);
|
|
7
|
-
}
|
|
8
|
-
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>;
|
|
9
|
-
|
|
10
|
-
export { addonIndexedDB };
|
package/dist/index.js
DELETED
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var __async = (__this, __arguments, generator) => {
|
|
20
|
-
return new Promise((resolve, reject) => {
|
|
21
|
-
var fulfilled = (value) => {
|
|
22
|
-
try {
|
|
23
|
-
step(generator.next(value));
|
|
24
|
-
} catch (e) {
|
|
25
|
-
reject(e);
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
var rejected = (value) => {
|
|
29
|
-
try {
|
|
30
|
-
step(generator.throw(value));
|
|
31
|
-
} catch (e) {
|
|
32
|
-
reject(e);
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
36
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
37
|
-
});
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
// src/index.ts
|
|
41
|
-
var index_exports = {};
|
|
42
|
-
__export(index_exports, {
|
|
43
|
-
addonIndexedDB: () => addonIndexedDB
|
|
44
|
-
});
|
|
45
|
-
module.exports = __toCommonJS(index_exports);
|
|
46
|
-
|
|
47
|
-
// src/IndexedDBStorage.ts
|
|
48
|
-
var import_client = require("@pluv/client");
|
|
49
|
-
var import_idb = require("idb");
|
|
50
|
-
var STORAGE_STORE_FLATTEN_THRESHOLD = 500;
|
|
51
|
-
var UPGRADES_KEY = "__PLUV_UPDATES";
|
|
52
|
-
var IndexedDBStorage = class extends import_client.AbstractStorageStore {
|
|
53
|
-
constructor(room) {
|
|
54
|
-
super(room);
|
|
55
|
-
this._db = null;
|
|
56
|
-
this._dbRef = 0;
|
|
57
|
-
this._dbSize = 0;
|
|
58
|
-
this.room = room;
|
|
59
|
-
}
|
|
60
|
-
addUpdate(update) {
|
|
61
|
-
return __async(this, null, function* () {
|
|
62
|
-
const db = this._db;
|
|
63
|
-
if (!db) return;
|
|
64
|
-
yield db.add(UPGRADES_KEY, update);
|
|
65
|
-
this._dbSize += 1;
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
destroy() {
|
|
69
|
-
if (!this._db) return Promise.resolve();
|
|
70
|
-
this._db.close();
|
|
71
|
-
this._db = null;
|
|
72
|
-
this._dbRef = 0;
|
|
73
|
-
this._dbSize = 0;
|
|
74
|
-
return Promise.resolve();
|
|
75
|
-
}
|
|
76
|
-
flatten(encodedState) {
|
|
77
|
-
return __async(this, null, function* () {
|
|
78
|
-
const db = this._db;
|
|
79
|
-
if (!db) return;
|
|
80
|
-
yield db.add(UPGRADES_KEY, encodedState);
|
|
81
|
-
yield db.delete(UPGRADES_KEY, this._getUpperBound(this._dbRef, true));
|
|
82
|
-
this._dbSize = yield this._getSize();
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
getShouldFlatten() {
|
|
86
|
-
return __async(this, null, function* () {
|
|
87
|
-
const dbSize = yield this._getSize();
|
|
88
|
-
return dbSize >= STORAGE_STORE_FLATTEN_THRESHOLD;
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
getUpdates(start = 0) {
|
|
92
|
-
return __async(this, null, function* () {
|
|
93
|
-
const db = this._db;
|
|
94
|
-
if (!db) return [];
|
|
95
|
-
const updates = yield db.getAll(UPGRADES_KEY, this._getLowerBound(start));
|
|
96
|
-
const lastKey = yield this._getLastKey();
|
|
97
|
-
this._dbRef = lastKey + 1;
|
|
98
|
-
return updates;
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
initialize() {
|
|
102
|
-
return __async(this, null, function* () {
|
|
103
|
-
const newDB = yield (0, import_idb.openDB)(this.room, void 0, {
|
|
104
|
-
upgrade: (db) => {
|
|
105
|
-
db.createObjectStore(UPGRADES_KEY, { autoIncrement: true });
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
newDB.addEventListener("versionchange", () => {
|
|
109
|
-
newDB.close();
|
|
110
|
-
});
|
|
111
|
-
if (typeof window !== "undefined") {
|
|
112
|
-
window.addEventListener("unload", () => {
|
|
113
|
-
newDB.close();
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
this._db = newDB;
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
_getLastKey() {
|
|
120
|
-
return __async(this, null, function* () {
|
|
121
|
-
var _a;
|
|
122
|
-
const db = this._db;
|
|
123
|
-
if (!db) throw new Error("IndexedDB not initialized");
|
|
124
|
-
const store = db.transaction(UPGRADES_KEY).objectStore(UPGRADES_KEY);
|
|
125
|
-
const cursor = yield store.openCursor(null, "prev");
|
|
126
|
-
return (_a = cursor == null ? void 0 : cursor.key) != null ? _a : -1;
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
_getLowerBound(lower, open = false) {
|
|
130
|
-
return IDBKeyRange.lowerBound(lower, open);
|
|
131
|
-
}
|
|
132
|
-
_getSize() {
|
|
133
|
-
return __async(this, null, function* () {
|
|
134
|
-
if (this._dbSize) return this._dbSize;
|
|
135
|
-
const db = this._db;
|
|
136
|
-
if (!db) throw new Error("IndexedDB not initialized");
|
|
137
|
-
const store = db.transaction(UPGRADES_KEY).objectStore(UPGRADES_KEY);
|
|
138
|
-
return store.count();
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
_getUpperBound(upper, open = false) {
|
|
142
|
-
return IDBKeyRange.upperBound(upper, open);
|
|
143
|
-
}
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
// src/addonIndexedDB.ts
|
|
147
|
-
var addonIndexedDB = (config) => {
|
|
148
|
-
const { enabled = true } = config != null ? config : {};
|
|
149
|
-
return ({ room }) => {
|
|
150
|
-
const _enabled = typeof enabled === "boolean" ? enabled : enabled(room);
|
|
151
|
-
if (!_enabled) return {};
|
|
152
|
-
return {
|
|
153
|
-
storage: new IndexedDBStorage(room.id)
|
|
154
|
-
};
|
|
155
|
-
};
|
|
156
|
-
};
|
|
157
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
158
|
-
0 && (module.exports = {
|
|
159
|
-
addonIndexedDB
|
|
160
|
-
});
|