@data-eden/cache
Advanced tools
Comparing version 0.12.1 to 0.12.2
import { CacheTransactionImpl } from './cache-transaction.js'; | ||
import type { Cache, CommittingTransaction, CachedEntityRevision, DefaultRegistry, CacheTransactionDebugAPIs } from './index.js'; | ||
export declare class CommittingTransactionImpl<CacheKeyRegistry extends DefaultRegistry, Key extends keyof CacheKeyRegistry = keyof CacheKeyRegistry, $Debug = unknown, UserExtensionData = unknown> extends CacheTransactionImpl<CacheKeyRegistry, Key, $Debug, UserExtensionData> implements CommittingTransaction<CacheKeyRegistry, Key, $Debug, UserExtensionData> { | ||
export declare class CommittingTransactionImpl<CacheKeyRegistry extends DefaultRegistry, Key extends keyof CacheKeyRegistry = keyof CacheKeyRegistry, $Debug = unknown, UserExtensionData = unknown, Context extends object = object> extends CacheTransactionImpl<CacheKeyRegistry, Key, $Debug, UserExtensionData, Context> implements CommittingTransaction<CacheKeyRegistry, Key, $Debug, UserExtensionData, Context> { | ||
#private; | ||
@@ -12,4 +12,4 @@ $debug?: ($Debug & CacheTransactionDebugAPIs) | undefined; | ||
updateRevisions(localRevisionsMap: Map<Key, CachedEntityRevision<CacheKeyRegistry, Key>[]>): void; | ||
constructor(originalCache: Cache<CacheKeyRegistry, Key, $Debug, UserExtensionData>, cacheRevisionsBeforeTransaction: Map<Key, CachedEntityRevision<CacheKeyRegistry, Key>[]>); | ||
constructor(originalCache: Cache<CacheKeyRegistry, Key, $Debug, UserExtensionData, Context>, cacheRevisionsBeforeTransaction: Map<Key, CachedEntityRevision<CacheKeyRegistry, Key>[]>); | ||
} | ||
//# sourceMappingURL=cache-revision.d.ts.map |
import type { Cache, CacheTransaction, CacheEntryState, CachedEntityRevision, DefaultRegistry, ExpirationPolicy } from './index.js'; | ||
export declare class CacheTransactionImpl<CacheKeyRegistry extends DefaultRegistry, Key extends keyof CacheKeyRegistry, $Debug = unknown, UserExtensionData = unknown> implements CacheTransaction<CacheKeyRegistry, Key, $Debug, UserExtensionData> { | ||
export declare class CacheTransactionImpl<CacheKeyRegistry extends DefaultRegistry, Key extends keyof CacheKeyRegistry, $Debug = unknown, UserExtensionData = unknown, Context extends object = object> implements CacheTransaction<CacheKeyRegistry, Key, $Debug, UserExtensionData, Context> { | ||
#private; | ||
constructor(originalCache: Cache<CacheKeyRegistry, Key, $Debug, UserExtensionData>); | ||
context: Context; | ||
constructor(originalCache: Cache<CacheKeyRegistry, Key, $Debug, UserExtensionData, Context>, context?: Context); | ||
protected getExpirationPolicies(): { | ||
@@ -6,0 +7,0 @@ userOptionExpirationPolicy: ExpirationPolicy; |
@@ -12,4 +12,4 @@ import type { Cache, CacheOptions, DefaultRegistry } from './index.js'; | ||
}; | ||
export declare function buildCache<CacheKeyRegistry extends DefaultRegistry = DefaultRegistry, Key extends keyof CacheKeyRegistry = keyof CacheKeyRegistry, $Debug = unknown, UserExtensionData = unknown>(options?: CacheOptions<CacheKeyRegistry, Key, $Debug, UserExtensionData>): Cache<CacheKeyRegistry, Key, $Debug, UserExtensionData>; | ||
export declare function buildCache<CacheKeyRegistry extends DefaultRegistry = DefaultRegistry, Key extends keyof CacheKeyRegistry = keyof CacheKeyRegistry, $Debug = unknown, UserExtensionData = unknown, Context extends object = object>(options?: CacheOptions<CacheKeyRegistry, Key, $Debug, UserExtensionData, Context>): Cache<CacheKeyRegistry, Key, $Debug, UserExtensionData, Context>; | ||
export declare function assert<T>(value: T, message: string | (() => string)): asserts value; | ||
//# sourceMappingURL=cache.d.ts.map |
@@ -1,14 +0,14 @@ | ||
var rt = (c, t, e) => { | ||
var ot = (c, t, e) => { | ||
if (!t.has(c)) | ||
throw TypeError("Cannot " + e); | ||
}; | ||
var s = (c, t, e) => (rt(c, t, "read from private field"), e ? e.call(c) : t.get(c)), o = (c, t, e) => { | ||
var s = (c, t, e) => (ot(c, t, "read from private field"), e ? e.call(c) : t.get(c)), o = (c, t, e) => { | ||
if (t.has(c)) | ||
throw TypeError("Cannot add the same private member more than once"); | ||
t instanceof WeakSet ? t.add(c) : t.set(c, e); | ||
}, a = (c, t, e, i) => (rt(c, t, "write to private field"), i ? i.call(c, e) : t.set(c, e), e); | ||
var d = (c, t, e) => (rt(c, t, "access private method"), e); | ||
var N, V, U, j, L, z, g, m, T; | ||
class lt { | ||
constructor(t) { | ||
}, a = (c, t, e, i) => (ot(c, t, "write to private field"), i ? i.call(c, e) : t.set(c, e), e); | ||
var v = (c, t, e) => (ot(c, t, "access private method"), e); | ||
var N, V, U, j, I, z, g, m, T; | ||
class yt { | ||
constructor(t, e = {}) { | ||
o(this, N, void 0); | ||
@@ -18,3 +18,3 @@ o(this, V, void 0); | ||
o(this, j, void 0); | ||
o(this, L, void 0); | ||
o(this, I, void 0); | ||
o(this, z, void 0); | ||
@@ -24,4 +24,4 @@ o(this, g, void 0); | ||
o(this, T, void 0); | ||
var e, i, n; | ||
a(this, N, t), a(this, V, /* @__PURE__ */ new Map()), a(this, T, /* @__PURE__ */ new Map()), a(this, L, B.ttl), a(this, z, B.lru), a(this, g, ((e = s(this, N).getCacheOptions()) == null ? void 0 : e.expiration) || B), s(this, g) && ((i = s(this, g)) != null && i.lru) && typeof s(this, g).lru == "number" && a(this, z, s(this, g).lru), s(this, g) && ((n = s(this, g)) != null && n.ttl) && typeof s(this, g).ttl == "number" && a(this, L, s(this, g).ttl), a(this, m, /* @__PURE__ */ new Map()), a(this, j, /* @__PURE__ */ new Map()), a(this, U, /* @__PURE__ */ new Map()); | ||
var i, n, r; | ||
a(this, N, t), a(this, V, /* @__PURE__ */ new Map()), a(this, T, /* @__PURE__ */ new Map()), a(this, I, A.ttl), a(this, z, A.lru), a(this, g, ((i = s(this, N).getCacheOptions()) == null ? void 0 : i.expiration) || A), this.context = e, s(this, g) && ((n = s(this, g)) != null && n.lru) && typeof s(this, g).lru == "number" && a(this, z, s(this, g).lru), s(this, g) && ((r = s(this, g)) != null && r.ttl) && typeof s(this, g).ttl == "number" && a(this, I, s(this, g).ttl), a(this, m, /* @__PURE__ */ new Map()), a(this, j, /* @__PURE__ */ new Map()), a(this, U, /* @__PURE__ */ new Map()); | ||
} | ||
@@ -32,3 +32,3 @@ getExpirationPolicies() { | ||
lruPolicy: s(this, z), | ||
ttlPolicy: s(this, L) | ||
ttlPolicy: s(this, I) | ||
}; | ||
@@ -80,3 +80,3 @@ } | ||
return s(this, T).set(t, { | ||
retained: { lru: !0, ttl: s(this, L) }, | ||
retained: { lru: !0, ttl: s(this, I) }, | ||
lastAccessed: Date.now() | ||
@@ -128,7 +128,7 @@ }), e || await s(this, N).get(t); | ||
} | ||
N = new WeakMap(), V = new WeakMap(), U = new WeakMap(), j = new WeakMap(), L = new WeakMap(), z = new WeakMap(), g = new WeakMap(), m = new WeakMap(), T = new WeakMap(); | ||
const at = 0; | ||
var k, F, Y, W, G, x, S, H, yt, $, ot; | ||
class Tt extends lt { | ||
constructor(e, i, n, r) { | ||
N = new WeakMap(), V = new WeakMap(), U = new WeakMap(), j = new WeakMap(), I = new WeakMap(), z = new WeakMap(), g = new WeakMap(), m = new WeakMap(), T = new WeakMap(); | ||
const ct = 0; | ||
var k, F, Y, W, G, x, S, H, ut, $, at; | ||
class Tt extends yt { | ||
constructor(e, i, n, r, h = {}) { | ||
super(e); | ||
@@ -145,5 +145,5 @@ o(this, H); | ||
o(this, S, void 0); | ||
a(this, k, e), a(this, S, r), a(this, F, this.getTransactionalCache()), this.setCacheEntriesBeforeTransaction(i), this.setRevisionsBeforeTransactionStart(n); | ||
const { userOptionExpirationPolicy: h, lruPolicy: l, ttlPolicy: u } = this.getExpirationPolicies(); | ||
a(this, W, u), a(this, G, l), a(this, Y, h); | ||
a(this, k, e), a(this, S, r), a(this, F, this.getTransactionalCache()), this.context = h, this.setCacheEntriesBeforeTransaction(i), this.setRevisionsBeforeTransactionStart(n); | ||
const { userOptionExpirationPolicy: l, lruPolicy: y, ttlPolicy: f } = this.getExpirationPolicies(); | ||
a(this, W, f), a(this, G, y), a(this, Y, l); | ||
} | ||
@@ -165,5 +165,5 @@ async set(e, i) { | ||
a(this, x, n == null ? void 0 : n.revisionContext); | ||
const r = d(this, $, ot).call(this, n == null ? void 0 : n.entityMergeStrategy), h = await s(this, k).get(e), l = this.getLocalRevisionsByEntry(e); | ||
let u = l && l[l.length - 1].revision ? l[l.length - 1].revision : at; | ||
u = ++u; | ||
const r = v(this, $, at).call(this, n == null ? void 0 : n.entityMergeStrategy), h = await s(this, k).get(e), l = this.getLocalRevisionsByEntry(e); | ||
let y = l && l[l.length - 1].revision ? l[l.length - 1].revision : ct; | ||
y = ++y; | ||
const f = h ? r( | ||
@@ -173,3 +173,3 @@ e, | ||
entity: i, | ||
revision: u, | ||
revision: y, | ||
revisionContext: s(this, x) | ||
@@ -181,8 +181,8 @@ }, | ||
await this.set(e, f); | ||
const y = { | ||
const L = { | ||
entity: f, | ||
revision: u, | ||
revision: y, | ||
revisionContext: s(this, x) | ||
}; | ||
return this.setLocalRevisionsByEntry(e, y), s(this, S).updateSavedRevisions(this.getLocalRevisions()), f; | ||
return this.setLocalRevisionsByEntry(e, L), s(this, S).updateSavedRevisions(this.getLocalRevisions()), f; | ||
} | ||
@@ -193,8 +193,8 @@ async commit(e) { | ||
try { | ||
return i = await d(this, H, yt).call(this), s(this, S).commitUpdatesAndReleaseLock( | ||
return i = await v(this, H, ut).call(this), s(this, S).commitUpdatesAndReleaseLock( | ||
this, | ||
i | ||
); | ||
} catch { | ||
throw new Error("Failed to prepare transaction updates"); | ||
} catch (n) { | ||
throw console.log(n), new Error("Failed to prepare transaction updates"); | ||
} finally { | ||
@@ -205,27 +205,27 @@ s(this, S).releaseTxCommitLock(this); | ||
} | ||
k = new WeakMap(), F = new WeakMap(), Y = new WeakMap(), W = new WeakMap(), G = new WeakMap(), x = new WeakMap(), S = new WeakMap(), H = new WeakSet(), yt = async function() { | ||
k = new WeakMap(), F = new WeakMap(), Y = new WeakMap(), W = new WeakMap(), G = new WeakMap(), x = new WeakMap(), S = new WeakMap(), H = new WeakSet(), ut = async function() { | ||
var n, r; | ||
const e = []; | ||
for await (const [h, l] of this.localEntries()) { | ||
const u = await s(this, k).get(h); | ||
const y = await s(this, k).get(h); | ||
let f; | ||
const y = d(this, $, ot).call(this), v = this.getLocalRevisionsByEntry(h); | ||
let A = v && v[v.length - 1].revision ? v[v.length - 1].revision : at; | ||
A = ++A, u && y ? f = y( | ||
const L = v(this, $, at).call(this), u = this.getLocalRevisionsByEntry(h); | ||
let d = u && u[u.length - 1].revision ? u[u.length - 1].revision : ct; | ||
d = ++d, y && L ? f = L( | ||
h, | ||
{ | ||
entity: l, | ||
revision: A, | ||
revision: d, | ||
revisionContext: s(this, x) | ||
}, | ||
u, | ||
y, | ||
this | ||
) : f = l; | ||
const Ct = kt( | ||
const rt = kt( | ||
f | ||
), Et = this.getCacheEntryState(h) || vt; | ||
e.push([h, Ct, Et]); | ||
), Et = this.getCacheEntryState(h) || dt; | ||
e.push([h, rt, Et]); | ||
const St = { | ||
entity: f, | ||
revision: A, | ||
revision: d, | ||
revisionContext: s(this, x) | ||
@@ -241,3 +241,3 @@ }; | ||
}; | ||
}, $ = new WeakSet(), ot = function(e) { | ||
}, $ = new WeakSet(), at = function(e) { | ||
var n, r; | ||
@@ -256,4 +256,4 @@ const i = (r = (n = s(this, k).getCacheOptions()) == null ? void 0 : n.hooks) == null ? void 0 : r.entitymergeStrategy; | ||
} | ||
var w, Z, ut, K, ft; | ||
class xt extends lt { | ||
var w, Z, ft, K, vt; | ||
class xt extends yt { | ||
constructor(e, i) { | ||
@@ -265,3 +265,3 @@ super(e); | ||
this.setRevisionsBeforeTransactionStart(i); | ||
const n = (h, l) => d(this, Z, ut).call(this, h, l), r = (h) => d(this, K, ft).call(this, h); | ||
const n = (h, l) => v(this, Z, ft).call(this, h, l), r = (h) => v(this, K, vt).call(this, h); | ||
this.cache = { | ||
@@ -279,3 +279,3 @@ clearRevisions: r, | ||
} | ||
w = new WeakMap(), Z = new WeakSet(), ut = function(e, i) { | ||
w = new WeakMap(), Z = new WeakSet(), ft = function(e, i) { | ||
var n; | ||
@@ -287,9 +287,9 @@ if (s(this, w).has(e)) { | ||
s(this, w).set(e, i); | ||
}, K = new WeakSet(), ft = function(e) { | ||
}, K = new WeakSet(), vt = function(e) { | ||
s(this, w).has(e) && s(this, w).delete(e); | ||
}; | ||
const B = { lru: 1e4, ttl: 6e4 }, vt = { | ||
retained: { lru: !1, ttl: B.ttl } | ||
const A = { lru: 1e4, ttl: 6e4 }, dt = { | ||
retained: { lru: !1, ttl: A.ttl } | ||
}; | ||
var R, p, I, b, O, J, _, M, C, P, tt, dt, et, gt, q, X, st, mt, it, wt, nt, Rt; | ||
var R, p, b, O, M, J, _, P, C, B, tt, gt, et, mt, q, X, st, wt, it, Rt, nt, pt; | ||
class Lt { | ||
@@ -305,23 +305,23 @@ constructor(t) { | ||
o(this, p, void 0); | ||
o(this, I, void 0); | ||
o(this, b, void 0); | ||
o(this, O, void 0); | ||
o(this, M, void 0); | ||
o(this, J, void 0); | ||
o(this, _, void 0); | ||
o(this, M, void 0); | ||
o(this, P, void 0); | ||
o(this, C, void 0); | ||
o(this, P, void 0); | ||
o(this, B, void 0); | ||
var i, n, r, h; | ||
a(this, R, /* @__PURE__ */ new Map()), a(this, I, { | ||
a(this, R, /* @__PURE__ */ new Map()), a(this, b, { | ||
hooks: { | ||
commit: (i = t == null ? void 0 : t.hooks) == null ? void 0 : i.commit, | ||
entitymergeStrategy: ((n = t == null ? void 0 : t.hooks) == null ? void 0 : n.entitymergeStrategy) || bt, | ||
revisionMergeStrategy: ((r = t == null ? void 0 : t.hooks) == null ? void 0 : r.revisionMergeStrategy) || ct | ||
revisionMergeStrategy: ((r = t == null ? void 0 : t.hooks) == null ? void 0 : r.revisionMergeStrategy) || ht | ||
}, | ||
expiration: (t == null ? void 0 : t.expiration) || B | ||
}), a(this, J, B.lru), a(this, p, /* @__PURE__ */ new Map()), a(this, b, /* @__PURE__ */ new Map()); | ||
const e = ((h = s(this, I)) == null ? void 0 : h.expiration) || B; | ||
e && (e != null && e.lru) && typeof e.lru == "number" && a(this, J, e.lru), a(this, O, new It(s(this, J))), a(this, C, null), a(this, P, []), a(this, _, new FinalizationRegistry((l) => { | ||
const u = s(this, R), f = u.get(l); | ||
f && !f.deref() && u.delete(l); | ||
expiration: (t == null ? void 0 : t.expiration) || A | ||
}), a(this, J, A.lru), a(this, p, /* @__PURE__ */ new Map()), a(this, O, /* @__PURE__ */ new Map()); | ||
const e = ((h = s(this, b)) == null ? void 0 : h.expiration) || A; | ||
e && (e != null && e.lru) && typeof e.lru == "number" && a(this, J, e.lru), a(this, M, new It(s(this, J))), a(this, C, null), a(this, B, []), a(this, _, new FinalizationRegistry((l) => { | ||
const y = s(this, R), f = y.get(l); | ||
f && !f.deref() && y.delete(l); | ||
})); | ||
@@ -334,6 +334,6 @@ } | ||
for await (const [t] of this.entries()) | ||
s(this, R).delete(t), s(this, O).getCache().delete(t), s(this, p).delete(t); | ||
s(this, R).delete(t), s(this, M).getCache().delete(t), s(this, p).delete(t); | ||
} | ||
getCacheOptions() { | ||
return s(this, I); | ||
return s(this, b); | ||
} | ||
@@ -351,3 +351,3 @@ async get(t) { | ||
for await (const [e, i, n] of this.entries()) { | ||
const r = ht( | ||
const r = lt( | ||
i | ||
@@ -368,4 +368,4 @@ ); | ||
for await (let n of t) { | ||
let [r, h, l] = n, u = ht(h); | ||
s(this, R).set(r, new WeakRef(u)), s(this, _).register(u, r), s(this, O).set(r, u), s(this, b).set(r, l); | ||
let [r, h, l] = n, y = lt(h); | ||
s(this, R).set(r, new WeakRef(y)), s(this, _).register(y, r), s(this, M).set(r, y), s(this, O).set(r, l); | ||
const f = { | ||
@@ -376,4 +376,4 @@ entity: h, | ||
if (s(this, p).has(r)) { | ||
const y = ((i = s(this, p).get(r)) == null ? void 0 : i.concat(f)) || []; | ||
s(this, p).set(r, y); | ||
const L = ((i = s(this, p).get(r)) == null ? void 0 : i.concat(f)) || []; | ||
s(this, p).set(r, L); | ||
} else | ||
@@ -393,3 +393,3 @@ s(this, p).set(r, [f]); | ||
if (i) { | ||
const n = s(this, b).get(e) || vt; | ||
const n = s(this, O).get(e) || dt; | ||
yield [e, i, n]; | ||
@@ -430,31 +430,32 @@ } | ||
} | ||
async beginTransaction() { | ||
const t = (y) => d(this, et, gt).call(this, y), e = (y) => d(this, q, X).call(this, y), i = (y, v) => d(this, it, wt).call(this, y, v), n = (y, v) => d(this, st, mt).call(this, y, v), r = (y) => d(this, nt, Rt).call(this, y), h = /* @__PURE__ */ new Map(), l = /* @__PURE__ */ new Map(); | ||
for await (const [y, v] of this.entries()) | ||
h.set(y, v); | ||
for await (const [y] of this.entries()) { | ||
const v = []; | ||
for await (const A of this.entryRevisions(y)) | ||
v.push(A); | ||
l.set(y, v); | ||
async beginTransaction(t) { | ||
const e = (u) => v(this, et, mt).call(this, u), i = (u) => v(this, q, X).call(this, u), n = (u, d) => v(this, it, Rt).call(this, u, d), r = (u, d) => v(this, st, wt).call(this, u, d), h = (u) => v(this, nt, pt).call(this, u), l = /* @__PURE__ */ new Map(), y = /* @__PURE__ */ new Map(); | ||
for await (const [u, d] of this.entries()) | ||
l.set(u, d); | ||
for await (const [u] of this.entries()) { | ||
const d = []; | ||
for await (const rt of this.entryRevisions(u)) | ||
d.push(rt); | ||
y.set(u, d); | ||
} | ||
const u = { | ||
aquireTxCommitLock: t, | ||
releaseTxCommitLock: e, | ||
applyRetentionPolicies: n, | ||
updateSavedRevisions: r, | ||
commitUpdatesAndReleaseLock: i | ||
const f = { | ||
aquireTxCommitLock: e, | ||
releaseTxCommitLock: i, | ||
applyRetentionPolicies: r, | ||
updateSavedRevisions: h, | ||
commitUpdatesAndReleaseLock: n | ||
}; | ||
return a(this, M, new xt( | ||
return a(this, P, new xt( | ||
this, | ||
l | ||
y | ||
)), new Tt( | ||
this, | ||
h, | ||
l, | ||
u | ||
y, | ||
f, | ||
t | ||
); | ||
} | ||
} | ||
R = new WeakMap(), p = new WeakMap(), I = new WeakMap(), b = new WeakMap(), O = new WeakMap(), J = new WeakMap(), _ = new WeakMap(), M = new WeakMap(), C = new WeakMap(), P = new WeakMap(), tt = new WeakSet(), dt = function(t) { | ||
R = new WeakMap(), p = new WeakMap(), b = new WeakMap(), O = new WeakMap(), M = new WeakMap(), J = new WeakMap(), _ = new WeakMap(), P = new WeakMap(), C = new WeakMap(), B = new WeakMap(), tt = new WeakSet(), gt = function(t) { | ||
let e, i; | ||
@@ -470,17 +471,17 @@ const n = new Promise((r, h) => { | ||
}; | ||
}, et = new WeakSet(), gt = async function(t) { | ||
}, et = new WeakSet(), mt = async function(t) { | ||
if (s(this, C) === null) | ||
return a(this, C, t), new Promise((i) => { | ||
i(s(this, C)), setTimeout(() => { | ||
d(this, q, X).call(this, t); | ||
v(this, q, X).call(this, t); | ||
}, 3e3); | ||
}); | ||
let e = d(this, tt, dt).call(this, t); | ||
return s(this, P).push(e), e.promise; | ||
let e = v(this, tt, gt).call(this, t); | ||
return s(this, B).push(e), e.promise; | ||
}, q = new WeakSet(), X = function(t) { | ||
s(this, C) === t && a(this, C, null); | ||
}, st = new WeakSet(), mt = async function(t, e) { | ||
}, st = new WeakSet(), wt = async function(t, e) { | ||
var n, r; | ||
await (((r = (n = s(this, I)) == null ? void 0 : n.hooks) == null ? void 0 : r.revisionMergeStrategy) || ct)(t, s(this, M)); | ||
}, it = new WeakSet(), wt = function(t, e) { | ||
await (((r = (n = s(this, b)) == null ? void 0 : n.hooks) == null ? void 0 : r.revisionMergeStrategy) || ht)(t, s(this, P)); | ||
}, it = new WeakSet(), Rt = function(t, e) { | ||
Mt( | ||
@@ -492,3 +493,3 @@ s(this, C) === t, | ||
const [n, r, h] = i; | ||
s(this, R).set(n, new WeakRef(r)), s(this, _).register(r, n), s(this, b).set(n, h), h != null && h.retained.lru && s(this, O).set(n, r); | ||
s(this, R).set(n, new WeakRef(r)), s(this, _).register(r, n), s(this, O).set(n, h), h != null && h.retained.lru && s(this, M).set(n, r); | ||
} | ||
@@ -498,16 +499,14 @@ for (const [ | ||
n | ||
] of s(this, M).mergedEntryRevisions()) | ||
] of s(this, P).mergedEntryRevisions()) | ||
s(this, p).set(i, n); | ||
if (d(this, q, X).call(this, t), s(this, P).length > 0) { | ||
const i = s(this, P).shift(); | ||
if (v(this, q, X).call(this, t), s(this, B).length > 0) { | ||
const i = s(this, B).shift(); | ||
i && a(this, C, i.owner), i.resolve(); | ||
} | ||
}, nt = new WeakSet(), Rt = function(t) { | ||
}, nt = new WeakSet(), pt = function(t) { | ||
var e; | ||
(e = s(this, M)) == null || e.updateRevisions(t); | ||
(e = s(this, P)) == null || e.updateRevisions(t); | ||
}; | ||
function Bt(c) { | ||
return new Lt( | ||
c | ||
); | ||
return new Lt(c); | ||
} | ||
@@ -535,3 +534,3 @@ var D, E; | ||
D = new WeakMap(), E = new WeakMap(); | ||
const ct = async function(t, e) { | ||
const ht = async function(t, e) { | ||
const i = []; | ||
@@ -542,7 +541,7 @@ for await (const n of e.entryRevisions(t)) | ||
}, bt = function(t, { entity: e }, i, n) { | ||
return pt(i, e); | ||
return Ct(i, e); | ||
}, Q = function(t) { | ||
return t !== null && !Array.isArray(t) && typeof t == "object"; | ||
}; | ||
function pt(c, t) { | ||
function Ct(c, t) { | ||
const e = Q(t) ? { ...t } : t, i = Q(c) ? { ...c } : c; | ||
@@ -560,3 +559,3 @@ return Q(e) && Q(i) ? (Object.keys(e).forEach((n) => { | ||
function Ot(c, t, e) { | ||
return pt( | ||
return Ct( | ||
c[e], | ||
@@ -566,3 +565,3 @@ t[e] | ||
} | ||
function ht(c) { | ||
function lt(c) { | ||
try { | ||
@@ -569,0 +568,0 @@ return JSON.parse(JSON.stringify(c)); |
import { CacheTransactionImpl } from './cache-transaction.js'; | ||
import type { Cache, LiveCacheTransaction, CacheKeyValue, CachedEntityRevision, DefaultRegistry, EntityMergeStrategy, TransactionOperations } from './index.js'; | ||
export declare class LiveCacheTransactionImpl<CacheKeyRegistry extends DefaultRegistry, Key extends keyof CacheKeyRegistry, $Debug = unknown, UserExtensionData = unknown> extends CacheTransactionImpl<CacheKeyRegistry, Key, $Debug, UserExtensionData> implements LiveCacheTransaction<CacheKeyRegistry, Key, $Debug, UserExtensionData> { | ||
export declare class LiveCacheTransactionImpl<CacheKeyRegistry extends DefaultRegistry, Key extends keyof CacheKeyRegistry, $Debug = unknown, UserExtensionData = unknown, Context extends object = object> extends CacheTransactionImpl<CacheKeyRegistry, Key, $Debug, UserExtensionData, Context> implements LiveCacheTransaction<CacheKeyRegistry, Key, $Debug, UserExtensionData, Context> { | ||
#private; | ||
constructor(originalCache: Cache<CacheKeyRegistry, Key, $Debug, UserExtensionData>, cacheEntriesBeforeTransaction: Map<Key, CacheKeyRegistry[Key]>, cacheRevisionsBeforeTransaction: Map<Key, CachedEntityRevision<CacheKeyRegistry, Key>[]>, transactionOperations: TransactionOperations<CacheKeyRegistry, Key, $Debug, UserExtensionData>); | ||
context: Context; | ||
constructor(originalCache: Cache<CacheKeyRegistry, Key, $Debug, UserExtensionData, Context>, cacheEntriesBeforeTransaction: Map<Key, CacheKeyRegistry[Key]>, cacheRevisionsBeforeTransaction: Map<Key, CachedEntityRevision<CacheKeyRegistry, Key>[]>, transactionOperations: TransactionOperations<CacheKeyRegistry, Key, $Debug, UserExtensionData>, context?: Context); | ||
set(cacheKey: Key, value: CacheKeyRegistry[Key]): Promise<CacheKeyRegistry[Key]>; | ||
@@ -7,0 +8,0 @@ delete(cacheKey: Key): Promise<boolean>; |
{ | ||
"$schema": "https://json.schemastore.org/package.json", | ||
"name": "@data-eden/cache", | ||
"version": "0.12.1", | ||
"version": "0.12.2", | ||
"repository": { | ||
@@ -6,0 +6,0 @@ "type": "git", |
@@ -14,7 +14,20 @@ import { CacheTransactionImpl } from './cache-transaction.js'; | ||
$Debug = unknown, | ||
UserExtensionData = unknown | ||
UserExtensionData = unknown, | ||
Context extends object = object | ||
> | ||
extends CacheTransactionImpl<CacheKeyRegistry, Key, $Debug, UserExtensionData> | ||
extends CacheTransactionImpl< | ||
CacheKeyRegistry, | ||
Key, | ||
$Debug, | ||
UserExtensionData, | ||
Context | ||
> | ||
implements | ||
CommittingTransaction<CacheKeyRegistry, Key, $Debug, UserExtensionData> | ||
CommittingTransaction< | ||
CacheKeyRegistry, | ||
Key, | ||
$Debug, | ||
UserExtensionData, | ||
Context | ||
> | ||
{ | ||
@@ -46,3 +59,9 @@ #txRetainedEntryRevisions: Map< | ||
constructor( | ||
originalCache: Cache<CacheKeyRegistry, Key, $Debug, UserExtensionData>, | ||
originalCache: Cache< | ||
CacheKeyRegistry, | ||
Key, | ||
$Debug, | ||
UserExtensionData, | ||
Context | ||
>, | ||
cacheRevisionsBeforeTransaction: Map< | ||
@@ -49,0 +68,0 @@ Key, |
@@ -15,4 +15,6 @@ import type { | ||
$Debug = unknown, | ||
UserExtensionData = unknown | ||
> implements CacheTransaction<CacheKeyRegistry, Key, $Debug, UserExtensionData> | ||
UserExtensionData = unknown, | ||
Context extends object = object | ||
> implements | ||
CacheTransaction<CacheKeyRegistry, Key, $Debug, UserExtensionData, Context> | ||
{ | ||
@@ -23,3 +25,4 @@ #originalCacheReference: Cache< | ||
$Debug, | ||
UserExtensionData | ||
UserExtensionData, | ||
Context | ||
>; | ||
@@ -37,5 +40,13 @@ #transactionalCache: Map<Key, CacheKeyRegistry[Key]>; | ||
#cacheEntryState: Map<Key, CacheEntryState<UserExtensionData>>; | ||
context: Context; | ||
constructor( | ||
originalCache: Cache<CacheKeyRegistry, Key, $Debug, UserExtensionData> | ||
originalCache: Cache< | ||
CacheKeyRegistry, | ||
Key, | ||
$Debug, | ||
UserExtensionData, | ||
Context | ||
>, | ||
context: Context = {} as Context | ||
) { | ||
@@ -51,2 +62,4 @@ this.#originalCacheReference = originalCache; | ||
this.context = context; | ||
if ( | ||
@@ -53,0 +66,0 @@ this.#userOptionExpirationPolicy && |
@@ -29,4 +29,5 @@ import { LiveCacheTransactionImpl } from './live-transaction.js'; | ||
$Debug = unknown, | ||
UserExtensionData = unknown | ||
> implements Cache<CacheKeyRegistry, Key, $Debug, UserExtensionData> | ||
UserExtensionData = unknown, | ||
Context extends object = object | ||
> implements Cache<CacheKeyRegistry, Key, $Debug, UserExtensionData, Context> | ||
{ | ||
@@ -36,3 +37,3 @@ #weakCache: Map<Key, WeakRef<CacheKeyRegistry[Key]>>; | ||
#cacheOptions: | ||
| CacheOptions<CacheKeyRegistry, Key, $Debug, UserExtensionData> | ||
| CacheOptions<CacheKeyRegistry, Key, $Debug, UserExtensionData, Context> | ||
| undefined; | ||
@@ -66,3 +67,3 @@ #cacheEntryState: Map<Key, CacheEntryState<UserExtensionData> | undefined>; | ||
options: | ||
| CacheOptions<CacheKeyRegistry, Key, $Debug, UserExtensionData> | ||
| CacheOptions<CacheKeyRegistry, Key, $Debug, UserExtensionData, Context> | ||
| undefined | ||
@@ -123,3 +124,3 @@ ) { | ||
getCacheOptions(): | ||
| CacheOptions<CacheKeyRegistry, Key, $Debug, UserExtensionData> | ||
| CacheOptions<CacheKeyRegistry, Key, $Debug, UserExtensionData, Context> | ||
| undefined { | ||
@@ -418,3 +419,5 @@ return this.#cacheOptions; | ||
async beginTransaction(): Promise< | ||
async beginTransaction( | ||
context?: Context | ||
): Promise< | ||
LiveCacheTransaction<CacheKeyRegistry, Key, $Debug, UserExtensionData> | ||
@@ -499,3 +502,4 @@ > { | ||
$Debug, | ||
UserExtensionData | ||
UserExtensionData, | ||
Context | ||
>( | ||
@@ -505,3 +509,4 @@ this, | ||
cacheRevisionsBeforeTransaction, | ||
transactionOperations | ||
transactionOperations, | ||
context | ||
); | ||
@@ -517,9 +522,20 @@ | ||
$Debug = unknown, | ||
UserExtensionData = unknown | ||
UserExtensionData = unknown, | ||
Context extends object = object | ||
>( | ||
options?: CacheOptions<CacheKeyRegistry, Key, $Debug, UserExtensionData> | ||
): Cache<CacheKeyRegistry, Key, $Debug, UserExtensionData> { | ||
return new CacheImpl<CacheKeyRegistry, Key, $Debug, UserExtensionData>( | ||
options | ||
); | ||
options?: CacheOptions< | ||
CacheKeyRegistry, | ||
Key, | ||
$Debug, | ||
UserExtensionData, | ||
Context | ||
> | ||
): Cache<CacheKeyRegistry, Key, $Debug, UserExtensionData, Context> { | ||
return new CacheImpl< | ||
CacheKeyRegistry, | ||
Key, | ||
$Debug, | ||
UserExtensionData, | ||
Context | ||
>(options); | ||
} | ||
@@ -526,0 +542,0 @@ |
@@ -21,7 +21,20 @@ import { CacheTransactionImpl } from './cache-transaction.js'; | ||
$Debug = unknown, | ||
UserExtensionData = unknown | ||
UserExtensionData = unknown, | ||
Context extends object = object | ||
> | ||
extends CacheTransactionImpl<CacheKeyRegistry, Key, $Debug, UserExtensionData> | ||
extends CacheTransactionImpl< | ||
CacheKeyRegistry, | ||
Key, | ||
$Debug, | ||
UserExtensionData, | ||
Context | ||
> | ||
implements | ||
LiveCacheTransaction<CacheKeyRegistry, Key, $Debug, UserExtensionData> | ||
LiveCacheTransaction< | ||
CacheKeyRegistry, | ||
Key, | ||
$Debug, | ||
UserExtensionData, | ||
Context | ||
> | ||
{ | ||
@@ -32,3 +45,4 @@ #originalCacheReference: Cache< | ||
$Debug, | ||
UserExtensionData | ||
UserExtensionData, | ||
Context | ||
>; | ||
@@ -40,2 +54,3 @@ #transactionalCache: Map<Key, CacheKeyRegistry[Key]>; | ||
#revisionContext: unknown; | ||
context: Context; | ||
@@ -50,3 +65,9 @@ #transactionOperations: TransactionOperations< | ||
constructor( | ||
originalCache: Cache<CacheKeyRegistry, Key, $Debug, UserExtensionData>, | ||
originalCache: Cache< | ||
CacheKeyRegistry, | ||
Key, | ||
$Debug, | ||
UserExtensionData, | ||
Context | ||
>, | ||
cacheEntriesBeforeTransaction: Map<Key, CacheKeyRegistry[Key]>, | ||
@@ -62,3 +83,4 @@ cacheRevisionsBeforeTransaction: Map< | ||
UserExtensionData | ||
> | ||
>, | ||
context: Context = {} as Context | ||
) { | ||
@@ -72,2 +94,3 @@ super(originalCache); | ||
// this.#cacheEntryState = this.cacheEntryState; | ||
this.context = context; | ||
@@ -187,2 +210,3 @@ this.setCacheEntriesBeforeTransaction(cacheEntriesBeforeTransaction); | ||
} catch (e) { | ||
console.log(e); | ||
throw new Error('Failed to prepare transaction updates'); | ||
@@ -189,0 +213,0 @@ } finally { |
@@ -7,3 +7,4 @@ export { buildCache } from '../src/cache.js'; | ||
$Debug = unknown, | ||
UserExtensionData = unknown | ||
UserExtensionData = unknown, | ||
Context extends object = object | ||
> { | ||
@@ -19,3 +20,3 @@ /** | ||
getCacheOptions(): | ||
| CacheOptions<CacheKeyRegistry, Key, $Debug, UserExtensionData> | ||
| CacheOptions<CacheKeyRegistry, Key, $Debug, UserExtensionData, Context> | ||
| undefined; | ||
@@ -87,3 +88,5 @@ | ||
*/ | ||
beginTransaction(): Promise< | ||
beginTransaction( | ||
context?: Context | ||
): Promise< | ||
LiveCacheTransaction<CacheKeyRegistry, Key, $Debug, UserExtensionData> | ||
@@ -97,3 +100,4 @@ >; | ||
$Debug = unknown, | ||
UserExtensionData = unknown | ||
UserExtensionData = unknown, | ||
Context extends object = object | ||
> { | ||
@@ -138,2 +142,4 @@ /** | ||
context: Context; | ||
$debug?: $Debug & CacheTransactionDebugAPIs; | ||
@@ -149,4 +155,11 @@ } | ||
$Debug = unknown, | ||
UserExtensionData = unknown | ||
> extends CacheTransaction<CacheKeyRegistry, Key, $Debug, UserExtensionData> { | ||
UserExtensionData = unknown, | ||
Context extends object = object | ||
> extends CacheTransaction< | ||
CacheKeyRegistry, | ||
Key, | ||
$Debug, | ||
UserExtensionData, | ||
Context | ||
> { | ||
/** | ||
@@ -187,2 +200,4 @@ * Merges cache entries based on merge strategy | ||
commit(): Promise<void>; | ||
context: Context; | ||
} | ||
@@ -194,4 +209,11 @@ | ||
$Debug = unknown, | ||
UserExtensionData = unknown | ||
> extends CacheTransaction<CacheKeyRegistry, Key, $Debug, UserExtensionData> { | ||
UserExtensionData = unknown, | ||
Context extends object = object | ||
> extends CacheTransaction< | ||
CacheKeyRegistry, | ||
Key, | ||
$Debug, | ||
UserExtensionData, | ||
Context | ||
> { | ||
cache: { | ||
@@ -305,3 +327,4 @@ clearRevisions(id: Key): void; | ||
$Debug = unknown, | ||
UserExtensionData = unknown | ||
UserExtensionData = unknown, | ||
Context extends object = object | ||
> { | ||
@@ -316,3 +339,9 @@ hooks?: { | ||
commit?: ( | ||
tx: CacheTransaction<CacheKeyRegistry, Key, $Debug, UserExtensionData> | ||
tx: CacheTransaction< | ||
CacheKeyRegistry, | ||
Key, | ||
$Debug, | ||
UserExtensionData, | ||
Context | ||
> | ||
) => Promise<void>; | ||
@@ -319,0 +348,0 @@ |
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
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
253067
2941