@pluv/addon-indexeddb 4.0.1 → 4.0.2
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 +11 -12
- package/CHANGELOG.md +9 -0
- package/dist/index.d.mts +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +3 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +11 -8
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
> tsdown
|
|
4
|
-
|
|
5
|
-
[34mℹ[39m tsdown [2mv0.20.0-beta.4[22m powered by rolldown [2mv1.0.0-beta.60[22m
|
|
1
|
+
$ tsdown
|
|
2
|
+
[34mℹ[39m [34mtsdown v0.22.2[39m powered by [38;2;255;126;23mrolldown v1.1.0[39m
|
|
6
3
|
[34mℹ[39m config file: [4m/home/runner/work/pluv/pluv/packages/addon-indexeddb/tsdown.config.ts[24m
|
|
7
4
|
[34mℹ[39m entry: [34msrc/index.ts[39m
|
|
8
5
|
[34mℹ[39m target: [34mesnext[39m
|
|
9
6
|
[34mℹ[39m tsconfig: [34mtsconfig.json[39m
|
|
10
7
|
[34mℹ[39m Build start
|
|
11
|
-
[34mℹ[39m [
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
[34mℹ[39m Hint: consider adding [34mdeps.onlyBundle[39m option to avoid unintended bundling of dependencies, or set [34mdeps.onlyBundle: false[39m to disable this hint.
|
|
9
|
+
See more at [4mhttps://tsdown.dev/options/dependencies#deps-onlybundle[24m
|
|
10
|
+
Detected dependencies in bundle:
|
|
11
|
+
- [34mwonka[39m
|
|
12
|
+
[34mℹ[39m [2mdist/[22m[1mindex.mjs[22m [2m2.58 kB[22m [2m│ gzip: 0.95 kB[22m
|
|
13
|
+
[34mℹ[39m [2mdist/[22mindex.d.mts.map [2m7.82 kB[22m [2m│ gzip: 2.79 kB[22m
|
|
14
|
+
[34mℹ[39m [2mdist/[22mindex.mjs.map [2m6.64 kB[22m [2m│ gzip: 2.08 kB[22m
|
|
14
15
|
[34mℹ[39m [2mdist/[22m[32m[1mindex.d.mts[22m[39m [2m5.84 kB[22m [2m│ gzip: 1.85 kB[22m
|
|
15
|
-
[34mℹ[39m 4 files, total:
|
|
16
|
-
[
|
|
17
|
-
|
|
18
|
-
[32m✔[39m Build complete in [32m3363ms[39m
|
|
16
|
+
[34mℹ[39m 4 files, total: 22.89 kB
|
|
17
|
+
[32m✔[39m Build complete in [32m3026ms[39m
|
package/CHANGELOG.md
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PluvRoom, PluvRoomAddon } from "@pluv/client";
|
|
2
2
|
import { AbstractCrdtDocFactory } from "@pluv/crdt";
|
|
3
3
|
|
|
4
|
-
//#region ../../node_modules/.pnpm/wonka@6.3.
|
|
4
|
+
//#region ../../node_modules/.pnpm/wonka@6.3.6/node_modules/wonka/dist/wonka.d.ts
|
|
5
5
|
declare global {
|
|
6
6
|
interface SymbolConstructor {
|
|
7
7
|
readonly observable: symbol;
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":["
|
|
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;EAC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,EAAM,MAAA,KAAW/H,IAAAA,YAAgB,YAAA,CAAa,OAAA;IACzDuJ,IAAAA,KAASxB,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
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { AbstractStorageStore } from "@pluv/client";
|
|
2
2
|
import { openDB } from "idb";
|
|
3
|
-
|
|
4
3
|
//#region src/IndexedDBStorage.ts
|
|
5
4
|
const STORAGE_STORE_FLATTEN_THRESHOLD = 500;
|
|
6
5
|
const UPGRADES_KEY = "__PLUV_UPDATES";
|
|
@@ -40,7 +39,8 @@ var IndexedDBStorage = class extends AbstractStorageStore {
|
|
|
40
39
|
const db = this._db;
|
|
41
40
|
if (!db) return [];
|
|
42
41
|
const updates = await db.getAll(UPGRADES_KEY, this._getLowerBound(start));
|
|
43
|
-
|
|
42
|
+
const lastKey = await this._getLastKey();
|
|
43
|
+
this._dbRef = lastKey + 1;
|
|
44
44
|
return updates;
|
|
45
45
|
}
|
|
46
46
|
async initialize() {
|
|
@@ -73,7 +73,6 @@ var IndexedDBStorage = class extends AbstractStorageStore {
|
|
|
73
73
|
return IDBKeyRange.upperBound(upper, open);
|
|
74
74
|
}
|
|
75
75
|
};
|
|
76
|
-
|
|
77
76
|
//#endregion
|
|
78
77
|
//#region src/addonIndexedDB.ts
|
|
79
78
|
const addonIndexedDB = (config) => {
|
|
@@ -83,7 +82,7 @@ const addonIndexedDB = (config) => {
|
|
|
83
82
|
return { storage: new IndexedDBStorage(room.id) };
|
|
84
83
|
};
|
|
85
84
|
};
|
|
86
|
-
|
|
87
85
|
//#endregion
|
|
88
86
|
export { addonIndexedDB };
|
|
87
|
+
|
|
89
88
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +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":"
|
|
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;EAC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AAc,WAA4B;EACtC,IAAI,KAAK,SAAS,OAAO,KAAK;EAE9B,MAAM,KAAK,KAAK;EAEhB,IAAI,CAAC,IAAI,MAAM,IAAI,MAAM,2BAA2B;EAIpD,OAFc,GAAG,YAAY,YAAY,CAAC,CAAC,YAAY,YAE5C,CAAC,CAAC,MAAM;CACvB;CAEA,eAAuB,OAAe,OAAgB,OAAoB;EACtE,OAAO,YAAY,WAAW,OAAO,IAAI;CAC7C;AACJ;;;ACrHA,MAAa,kBAMT,WACkD;CAClD,MAAM,EAAE,UAAU,SAAS,UAAU,CAAC;CAEtC,QAAQ,EAAE,WAAW;EAGjB,IAAI,EAFa,OAAO,YAAY,YAAY,UAAU,QAAQ,IAAI,IAEvD,OAAO,CAAC;EAEvB,OAAO,EACH,SAAS,IAAI,iBAAiB,KAAK,EAAE,EACzC;CACJ;AACJ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pluv/addon-indexeddb",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.2",
|
|
4
4
|
"description": "@pluv/io indexeddb for client storage persistence",
|
|
5
5
|
"author": {
|
|
6
6
|
"email": "david@pluv.io",
|
|
@@ -21,21 +21,24 @@
|
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"idb": "^8.0.3",
|
|
24
|
-
"@pluv/client": "^4.0.
|
|
25
|
-
"@pluv/crdt": "^4.0.
|
|
24
|
+
"@pluv/client": "^4.0.2",
|
|
25
|
+
"@pluv/crdt": "^4.0.2"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"eslint": "^
|
|
29
|
-
"tsdown": "0.
|
|
28
|
+
"eslint": "^10.4.1",
|
|
29
|
+
"tsdown": "0.22.2",
|
|
30
30
|
"typescript": "^5.9.3",
|
|
31
|
-
"@pluv/tsconfig": "^4.0.
|
|
32
|
-
"@pluv/types": "^4.0.
|
|
33
|
-
"eslint-config-pluv": "^4.0.
|
|
31
|
+
"@pluv/tsconfig": "^4.0.2",
|
|
32
|
+
"@pluv/types": "^4.0.2",
|
|
33
|
+
"eslint-config-pluv": "^4.0.2"
|
|
34
34
|
},
|
|
35
35
|
"exports": {
|
|
36
36
|
".": "./dist/index.mjs",
|
|
37
37
|
"./*": "./*"
|
|
38
38
|
},
|
|
39
|
+
"inlinedDependencies": {
|
|
40
|
+
"wonka": "6.3.6"
|
|
41
|
+
},
|
|
39
42
|
"scripts": {
|
|
40
43
|
"build": "tsdown",
|
|
41
44
|
"dev": "tsdown --watch",
|