Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@toeverything/y-indexeddb

Package Overview
Dependencies
Maintainers
2
Versions
154
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@toeverything/y-indexeddb - npm Package Compare versions

Comparing version 0.7.0-canary.20 to 0.7.0-canary.21

208

dist/index.js

@@ -1,5 +0,5 @@

import { openDB as S } from "idb";
import { mergeUpdates as V, Doc as W, applyUpdate as h, encodeStateVector as I, encodeStateAsUpdate as y, UndoManager as z, diffUpdate as J } from "yjs";
const j = 1, v = "affine-local";
function P(t) {
import { openDB as h } from "idb";
import { mergeUpdates as V, Doc as W, applyUpdate as S, encodeStateVector as I, encodeStateAsUpdate as y, UndoManager as z, diffUpdate as J } from "yjs";
const P = 1, D = "affine-local";
function j(t) {
t.createObjectStore("workspace", { keyPath: "id" }), t.createObjectStore("milestone", { keyPath: "id" });

@@ -9,7 +9,7 @@ }

async function K(t) {
return new Promise((i) => {
return new Promise((s) => {
const c = indexedDB.open(t);
let a = !0;
c.onsuccess = function() {
c.result.close(), a || indexedDB.deleteDatabase(t), i(a);
c.result.close(), a || indexedDB.deleteDatabase(t), s(a);
}, c.onupgradeneeded = function() {

@@ -20,3 +20,3 @@ a = !1;

}
async function Q(t, i, c = v) {
async function Q(t, s, c = D) {
do

@@ -27,12 +27,12 @@ if (!T || localStorage.getItem(`${c}-migration`) !== "true") {

} catch {
if (await K(i)) {
await S(i, 1).then(async (a) => {
if (await K(s)) {
await h(s, 1).then(async (a) => {
if (!a.objectStoreNames.contains("updates"))
return;
const s = await a.transaction("updates", "readonly").objectStore("updates").getAll();
if (!Array.isArray(s) || !s.every((f) => f instanceof Uint8Array))
const o = await a.transaction("updates", "readonly").objectStore("updates").getAll();
if (!Array.isArray(o) || !o.every((f) => f instanceof Uint8Array))
return;
const n = V(s), u = t.transaction("workspace", "readwrite").objectStore("workspace");
await u.get(i) || (console.log("upgrading the database"), await u.put({
id: i,
const n = V(o), u = t.transaction("workspace", "readwrite").objectStore("workspace");
await u.get(s) || (console.log("upgrading the database"), await u.put({
id: s,
updates: [

@@ -52,13 +52,13 @@ {

if (a.name && a.version === 1) {
const w = a.name, s = a.version;
return S(w, s).then(
const p = a.name, o = a.version;
return h(p, o).then(
async (n) => {
if (!n.objectStoreNames.contains("updates"))
return;
const d = await n.transaction("updates", "readonly").objectStore("updates").getAll();
if (!Array.isArray(d) || !d.every((A) => A instanceof Uint8Array))
const w = await n.transaction("updates", "readonly").objectStore("updates").getAll();
if (!Array.isArray(w) || !w.every((A) => A instanceof Uint8Array))
return;
const f = V(d), g = t.transaction("workspace", "readwrite").objectStore("workspace");
await g.get(w) || (console.log("upgrading the database"), await g.put({
id: w,
const f = V(w), g = t.transaction("workspace", "readwrite").objectStore("workspace");
await g.get(p) || (console.log("upgrading the database"), await g.put({
id: p,
updates: [

@@ -80,8 +80,21 @@ {

}
async function ee(t, i = v) {
const s = await (await S(i, j, {
upgrade: P
async function tt(t, s = D) {
const o = await (await h(s, P, {
upgrade: j
})).transaction("workspace", "readonly").objectStore("workspace").get(t);
return s ? V(s.updates.map(({ update: n }) => n)) : !1;
return o ? V(o.updates.map(({ update: n }) => n)) : !1;
}
async function et(t, s, c = D) {
await (await h(c, P, {
upgrade: j
})).transaction("workspace", "readwrite").objectStore("workspace").put({
id: t,
updates: [
{
timestamp: Date.now(),
update: s
}
]
});
}
const E = Symbol("indexeddb-provider-origin"), M = Symbol("snapshot-origin");

@@ -96,11 +109,11 @@ let $ = 500;

};
function te(t) {
function at(t) {
$ = t;
}
function ae(t, i, c) {
function nt(t, s, c) {
const a = new W();
h(a, i, M);
const w = I(t), s = I(a), n = y(
S(a, s, M);
const p = I(t), o = I(a), n = y(
t,
s
o
), u = new z(

@@ -121,8 +134,8 @@ [...a.share.keys()].map((f) => {

);
h(a, n, M), u.undo();
const d = y(
S(a, n, M), u.undo();
const w = y(
a,
w
p
);
h(t, d, M);
S(t, w, M);
}

@@ -139,46 +152,46 @@ class R extends Error {

}
const ne = async (t, i, c, a = v) => {
const n = (await S(a, j, {
upgrade: P
})).transaction("milestone", "readwrite").objectStore("milestone"), u = await n.get("id"), d = y(i);
u ? (u.milestone[c] = d, await n.put(u)) : await n.put({
const rt = async (t, s, c, a = D) => {
const n = (await h(a, P, {
upgrade: j
})).transaction("milestone", "readwrite").objectStore("milestone"), u = await n.get("id"), w = y(s);
u ? (u.milestone[c] = w, await n.put(u)) : await n.put({
id: t,
milestone: {
[c]: d
[c]: w
}
});
}, re = async (t, i = v) => {
const s = await (await S(i, j, {
upgrade: P
}, st = async (t, s = D) => {
const o = await (await h(s, P, {
upgrade: j
})).transaction("milestone", "readonly").objectStore("milestone").get(t);
return s ? s.milestone : null;
}, se = (t, i = v, c = !0) => {
let a, w, s = !0, n = !1;
const u = S(i, j, {
upgrade: P
}), d = /* @__PURE__ */ new WeakMap(), f = /* @__PURE__ */ new WeakMap(), g = /* @__PURE__ */ new WeakMap(), x = (o, e) => {
if (d.has(e))
return d.get(e);
return o ? o.milestone : null;
}, ot = (t, s = D, c = !0) => {
let a, p, o = !0, n = !1;
const u = h(s, P, {
upgrade: j
}), w = /* @__PURE__ */ new WeakMap(), f = /* @__PURE__ */ new WeakMap(), g = /* @__PURE__ */ new WeakMap(), x = (i, e) => {
if (w.has(e))
return w.get(e);
const r = async function(l, m) {
const D = await u;
const k = await u;
if (!n || m === E)
return;
const k = D.transaction("workspace", "readwrite").objectStore("workspace");
let p = await k.get(o);
if (p || (p = {
id: o,
const v = k.transaction("workspace", "readwrite").objectStore("workspace");
let d = await v.get(i);
if (d || (d = {
id: i,
updates: []
}), p.updates.push({
}), d.updates.push({
timestamp: Date.now(),
update: l
}), p.updates.length > $) {
const F = p.updates.map(({ update: H }) => H), C = new W();
}), d.updates.length > $) {
const F = d.updates.map(({ update: H }) => H), C = new W();
C.transact(() => {
F.forEach((H) => {
h(C, H, E);
S(C, H, E);
});
}, E);
const N = y(C);
p = {
id: o,
d = {
id: i,
updates: [

@@ -190,8 +203,8 @@ {

]
}, await U(k.put(p));
}, await U(v.put(d));
} else
await U(k.put(p));
await U(v.put(d));
};
return d.set(e, r), r;
}, A = (o, e) => {
return w.set(e, r), r;
}, A = (i, e) => {
if (f.has(e))

@@ -203,3 +216,3 @@ return f.get(e);

return f.set(e, r), r;
}, _ = (o, e) => {
}, _ = (i, e) => {
if (g.has(e))

@@ -216,14 +229,14 @@ return g.get(e);

};
function O(o, e) {
e.on("update", x(o, e)), e.on("destroy", A(o, e)), e.on("subdocs", _(o, e)), e.subdocs.forEach((r) => {
function O(i, e) {
e.on("update", x(i, e)), e.on("destroy", A(i, e)), e.on("subdocs", _(i, e)), e.subdocs.forEach((r) => {
O(r.guid, r);
});
}
function B(o, e) {
function B(i, e) {
e.subdocs.forEach((r) => {
B(r.guid, r);
}), e.off("update", x(o, e)), e.off("destroy", A(o, e)), e.off("subdocs", _(o, e));
}), e.off("update", x(i, e)), e.off("destroy", A(i, e)), e.off("subdocs", _(i, e));
}
async function q(o, e) {
const r = await u, b = r.transaction("workspace", "readwrite").objectStore("workspace"), l = await b.get(o);
async function q(i, e) {
const r = await u, b = r.transaction("workspace", "readwrite").objectStore("workspace"), l = await b.get(i);
if (n)

@@ -233,3 +246,3 @@ if (!l)

r.put("workspace", {
id: o,
id: i,
updates: [

@@ -244,11 +257,11 @@ {

else {
const m = l.updates.map(({ update: p }) => p), D = new W();
D.transact(() => {
m.forEach((p) => {
h(D, p);
const m = l.updates.map(({ update: d }) => d), k = new W();
k.transact(() => {
m.forEach((d) => {
S(k, d);
});
}, E);
const k = J(
const v = J(
y(e),
y(D)
y(k)
);

@@ -262,3 +275,3 @@ await U(

timestamp: Date.now(),
update: k
update: v
}

@@ -268,4 +281,4 @@ ]

), e.transact(() => {
m.forEach((p) => {
h(e, p);
m.forEach((d) => {
S(e, d);
});

@@ -280,6 +293,6 @@ }, E);

G.whenSynced = new Promise((r, b) => {
s = !0, a = r, w = b;
o = !0, a = r, p = b;
}), n = !0, O(t.guid, t);
const o = await u;
if (c && await Q(o, t.guid, i), !n)
const i = await u;
if (c && await Q(i, t.guid, s), !n)
return;

@@ -293,6 +306,6 @@ const e = [];

}
s = !1, a();
o = !1, a();
},
disconnect() {
n = !1, s && w(new R()), B(t.guid, t);
n = !1, o && p(new R()), B(t.guid, t);
},

@@ -313,15 +326,16 @@ async cleanup() {

X as CleanupWhenConnectingError,
v as DEFAULT_DB_NAME,
D as DEFAULT_DB_NAME,
R as EarlyDisconnectError,
se as createIndexedDBProvider,
j as dbVersion,
ee as downloadBinary,
re as getMilestones,
ne as markMilestone,
ae as revertUpdate,
te as setMergeCount,
ot as createIndexedDBProvider,
P as dbVersion,
tt as downloadBinary,
st as getMilestones,
rt as markMilestone,
et as overwriteBinary,
nt as revertUpdate,
at as setMergeCount,
Q as tryMigrate,
P as upgradeDB,
j as upgradeDB,
U as writeOperation
};
//# sourceMappingURL=index.js.map

@@ -10,2 +10,3 @@ import type { IDBPDatabase } from 'idb/build/entry';

export declare function downloadBinary(guid: string, dbName?: string): Promise<UpdateMessage['update'] | false>;
export declare function overwriteBinary(guid: string, update: UpdateMessage['update'], dbName?: string): Promise<void>;
//# sourceMappingURL=utils.d.ts.map
{
"name": "@toeverything/y-indexeddb",
"type": "module",
"version": "0.7.0-canary.20",
"version": "0.7.0-canary.21",
"description": "IndexedDB database adapter for Yjs",

@@ -6,0 +6,0 @@ "repository": "toeverything/AFFiNE",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc