@ebbjs/storage 0.2.0 → 1.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.
@@ -1,7 +1,7 @@
1
- import { m as b, a as E, i as M, c as m } from "../cursor-record-D39emd6R.js";
2
- import { l as D, c as _, a as A, f as T, b as h, h as w, k as j, j as v, n as R, M as f, m as k, p as I, r as F, i as q } from "../replica-record-D3lkFACh.js";
3
- import { compare as C } from "@ebbjs/core";
4
- const O = (t, n) => {
1
+ import { m as g, a as S, i as E, c as l } from "../cursor-record-D39emd6R.js";
2
+ import { l as b, c as M, a as A, f as D, b as _, h as x, k as T, j as h, q as j, M as m, m as v, s as w, r as R, i as k } from "../replica-record-D5gGEoVQ.js";
3
+ import { compare as q } from "@ebbjs/core";
4
+ const F = (t, n) => {
5
5
  const e = /* @__PURE__ */ new Map();
6
6
  for (const [s, a] of t)
7
7
  e.set(s, new Set(a));
@@ -10,16 +10,16 @@ const O = (t, n) => {
10
10
  a ? a.add(s.subject_id) : e.set(s.subject_type, /* @__PURE__ */ new Set([s.subject_id]));
11
11
  }
12
12
  return Array.from(e.entries()).map(([s, a]) => [s, Array.from(a)]);
13
- }, P = () => {
13
+ }, C = () => {
14
14
  let t = {
15
15
  actions: [],
16
16
  typeIndex: []
17
17
  };
18
18
  const n = async (e) => {
19
- const s = t.actions.findIndex((d) => d.id === e.id), a = s === -1 ? void 0 : t.actions[s], o = a === void 0 ? e : { ...a, updates: b(a.updates, e.updates) }, c = a === void 0, r = c ? t.actions.length + 1 : s + 1, i = E(a?.updates ?? [], e.updates);
19
+ const s = t.actions.findIndex((d) => d.id === e.id), a = s === -1 ? void 0 : t.actions[s], o = a === void 0 ? e : { ...a, updates: g(a.updates, e.updates) }, c = a === void 0, r = c ? t.actions.length + 1 : s + 1, i = S(a?.updates ?? [], e.updates);
20
20
  return t = {
21
21
  actions: c ? [...t.actions, o] : t.actions.map((d) => d.id === e.id ? o : d),
22
- typeIndex: O(t.typeIndex, o)
22
+ typeIndex: F(t.typeIndex, o)
23
23
  }, { action: o, position: r, added: i };
24
24
  };
25
25
  return {
@@ -51,7 +51,7 @@ const O = (t, n) => {
51
51
  t = { actions: [], typeIndex: [] };
52
52
  }
53
53
  };
54
- }, B = () => {
54
+ }, O = () => {
55
55
  let t = {
56
56
  entities: {},
57
57
  typeIndex: {}
@@ -89,37 +89,34 @@ const O = (t, n) => {
89
89
  t = { entities: {}, typeIndex: {} };
90
90
  }
91
91
  };
92
- }, u = (t) => JSON.parse(JSON.stringify(t)), g = (t, n, e) => {
92
+ }, u = (t) => JSON.parse(JSON.stringify(t)), f = (t, n, e) => {
93
93
  const s = { ...t };
94
94
  if (e && e !== n.type) {
95
95
  const a = new Set(s[e] ?? []);
96
96
  a.delete(n.id), s[e] = a;
97
97
  }
98
98
  return s[n.type] || (s[n.type] = /* @__PURE__ */ new Set()), s[n.type] = new Set(s[n.type]).add(n.id), s;
99
- }, S = (t, n, e) => w(
100
- w(t, v(n, e)),
101
- j(n, e)
102
- ), L = (t, n) => {
99
+ }, I = (t, n, e) => x(
100
+ x(t, h(n, e)),
101
+ T(n, e)
102
+ ), P = (t, n) => {
103
103
  let e = { entities: {}, typeIndex: {}, index: {} };
104
104
  const s = async (r) => {
105
105
  if (!await n.isDirty(r)) return;
106
106
  const d = await t.getForEntity(r);
107
107
  if (d.length === 0) return;
108
- let y = null;
109
- for (const p of d)
110
- for (const x of p.updates)
111
- x.subject_id === r && (y = R(y, x, p.gsn, p.hlc));
108
+ const y = j(d, r);
112
109
  if (y === null) return;
113
- const l = e.entities[r];
110
+ const p = e.entities[r];
114
111
  e = {
115
112
  entities: { ...e.entities, [r]: u(y) },
116
- typeIndex: g(e.typeIndex, y, l?.type),
117
- index: S(e.index, l, y)
113
+ typeIndex: f(e.typeIndex, y, p?.type),
114
+ index: I(e.index, p, y)
118
115
  }, await n.clear(r);
119
116
  }, a = async (r) => {
120
117
  for (const i of await n.getDirtyForType(r))
121
118
  await s(i);
122
- }, o = (r) => h(e.index[r]);
119
+ }, o = (r) => _(e.index[r]);
123
120
  return {
124
121
  async get(r) {
125
122
  await s(r);
@@ -130,8 +127,8 @@ const O = (t, n) => {
130
127
  const i = e.entities[r.id];
131
128
  e = {
132
129
  entities: { ...e.entities, [r.id]: u(r) },
133
- typeIndex: g(e.typeIndex, r, i?.type),
134
- index: S(e.index, i, r)
130
+ typeIndex: f(e.typeIndex, r, i?.type),
131
+ index: I(e.index, i, r)
135
132
  };
136
133
  },
137
134
  async query(r) {
@@ -142,26 +139,26 @@ const O = (t, n) => {
142
139
  type: i,
143
140
  targetId: d
144
141
  }) {
145
- return await a(I), o(F(r, i, d));
142
+ return await a(w), o(R(r, i, d));
146
143
  },
147
144
  async queryByRelationshipSource({
148
145
  as: r,
149
146
  type: i,
150
147
  sourceId: d
151
148
  }) {
152
- return await a(I), A(e.index[T(r, i, d)]);
149
+ return await a(w), A(e.index[D(r, i, d)]);
153
150
  },
154
151
  async queryByMembership(r) {
155
- return await a(f), o(k(r));
152
+ return await a(m), o(v(r));
156
153
  },
157
154
  async queryByMembershipEntity(r) {
158
- return await a(f), D(e.index[_(r)]);
155
+ return await a(m), b(e.index[M(r)]);
159
156
  },
160
157
  async reset() {
161
158
  e = { entities: {}, typeIndex: {}, index: {} };
162
159
  }
163
160
  };
164
- }, N = () => {
161
+ }, B = () => {
165
162
  let t = { records: {} };
166
163
  const n = (e) => t.records[e] ?? null;
167
164
  return {
@@ -170,19 +167,19 @@ const O = (t, n) => {
170
167
  },
171
168
  async set(e, s) {
172
169
  t = {
173
- records: { ...t.records, [e]: m({ ...n(e), cursor: s }) }
170
+ records: { ...t.records, [e]: l({ ...n(e), cursor: s }) }
174
171
  };
175
172
  },
176
173
  async getRecord(e) {
177
174
  return n(e);
178
175
  },
179
176
  async setRecord(e, s) {
180
- if (M(s)) {
177
+ if (E(s)) {
181
178
  const { [e]: a, ...o } = t.records;
182
179
  t = { records: o };
183
180
  return;
184
181
  }
185
- t = { records: { ...t.records, [e]: m(s) } };
182
+ t = { records: { ...t.records, [e]: l(s) } };
186
183
  },
187
184
  async records() {
188
185
  return new Map(Object.entries(t.records));
@@ -191,7 +188,7 @@ const O = (t, n) => {
191
188
  t = { records: {} };
192
189
  }
193
190
  };
194
- }, H = () => {
191
+ }, L = () => {
195
192
  let t = {};
196
193
  return {
197
194
  async put(n) {
@@ -202,7 +199,7 @@ const O = (t, n) => {
202
199
  t = { ...a, [n.action.id]: structuredClone(n) };
203
200
  },
204
201
  async list() {
205
- return Object.values(t).map((n) => structuredClone(n)).sort((n, e) => C(n.enqueuedAtHlc, e.enqueuedAtHlc));
202
+ return Object.values(t).map((n) => structuredClone(n)).sort((n, e) => q(n.enqueuedAtHlc, e.enqueuedAtHlc));
206
203
  },
207
204
  async get(n) {
208
205
  const e = t[n];
@@ -216,11 +213,11 @@ const O = (t, n) => {
216
213
  t = {};
217
214
  }
218
215
  };
219
- }, K = () => {
216
+ }, N = () => {
220
217
  let t = null;
221
218
  return {
222
219
  async load() {
223
- return q(t) ? t : null;
220
+ return k(t) ? t : null;
224
221
  },
225
222
  async save(n) {
226
223
  t = n;
@@ -229,8 +226,8 @@ const O = (t, n) => {
229
226
  t = null;
230
227
  }
231
228
  };
232
- }, z = () => {
233
- const t = P(), n = B(), e = L(t, n), s = N(), a = H(), o = K();
229
+ }, J = () => {
230
+ const t = C(), n = O(), e = P(t, n), s = B(), a = L(), o = N();
234
231
  return {
235
232
  actions: {
236
233
  async append(c) {
@@ -292,5 +289,5 @@ const O = (t, n) => {
292
289
  };
293
290
  };
294
291
  export {
295
- z as createMemoryAdapter
292
+ J as createMemoryAdapter
296
293
  };
@@ -19,6 +19,15 @@ interface MaterializeOptions {
19
19
  * no-op, so a per-Update delivery (#473) cannot break the drain.
20
20
  */
21
21
  declare const applyUpdate: (entity: Entity | null, update: Update, gsn: number, hlc: HLCTimestamp, options?: MaterializeOptions) => Entity | null;
22
+ /**
23
+ * Fold one Action's Updates for `entityId` into a row: every Update addressed
24
+ * to that subject, in `updates` order, under the Action's `gsn` and `hlc`.
25
+ * An Update for another subject belongs to a different row and is skipped.
26
+ *
27
+ * This is the replay step every EntityStore adapter runs for the row it is
28
+ * materializing.
29
+ */
30
+ declare const foldEntityAction: (entity: Entity | null, entityId: string, action: Action) => Entity | null;
22
31
 
23
32
  /**
24
33
  * True when `next` differs from `prev` in anything a reader can observe.
@@ -267,5 +276,5 @@ declare const DEFAULT_PINNED_TTL_MS = 30000;
267
276
  */
268
277
  declare const createReplica: (options?: ReplicaOptions) => Replica;
269
278
 
270
- export { DEFAULT_PINNED_CAPACITY, DEFAULT_PINNED_TTL_MS, applyUpdate, contentChanged, createReplica, holdAll };
279
+ export { DEFAULT_PINNED_CAPACITY, DEFAULT_PINNED_TTL_MS, applyUpdate, contentChanged, createReplica, foldEntityAction, holdAll };
271
280
  export type { MaterializationPolicy, MembershipQuery, RelationshipQuery, Replica, ReplicaChange, ReplicaOptions, ReplicaStats, Revision };
@@ -1,4 +1,5 @@
1
- import { l as _e, a as Me, f as se, b as V, m as Ee, c as oe, r as Fe, w as Ne, R as Oe, i as je, d as re, e as ke, g as Se, h as ie, j as Pe, k as xe, n as J, o as H } from "../replica-record-D3lkFACh.js";
1
+ import { l as _e, a as Ee, f as oe, b as V, m as Me, c as se, r as Fe, w as Ne, R as Oe, i as je, d as re, e as ke, g as Se, h as ie, j as Pe, k as xe, n as J, o as H } from "../replica-record-D5gGEoVQ.js";
2
+ import { p as Qe } from "../replica-record-D5gGEoVQ.js";
2
3
  import { isFieldMap as ce } from "@ebbjs/core";
3
4
  const fe = (c, f) => {
4
5
  if (c === f) return !0;
@@ -26,8 +27,8 @@ const fe = (c, f) => {
26
27
  }, He = (c) => {
27
28
  const f = c?.materialization ?? Ce, a = (e) => f.holds(e), l = /* @__PURE__ */ new Map(), p = /* @__PURE__ */ new Map(), d = /* @__PURE__ */ new Map(), h = /* @__PURE__ */ new Map(), y = /* @__PURE__ */ new Map(), k = le(c?.journalCapacity, De), ae = le(c?.pinnedCapacity, Le), W = Ve(c?.pinnedTtlMs), g = /* @__PURE__ */ new Map(), v = /* @__PURE__ */ new Map(), S = /* @__PURE__ */ new Map();
28
29
  let G = 0;
29
- const M = /* @__PURE__ */ new Map();
30
- let I = [], w = 0, N = {}, m = {}, u = 0, O = 0, E = 0;
30
+ const E = /* @__PURE__ */ new Map();
31
+ let I = [], w = 0, N = {}, m = {}, u = 0, O = 0, M = 0;
31
32
  const Y = /* @__PURE__ */ new Set(), F = () => {
32
33
  for (const e of Y)
33
34
  try {
@@ -36,22 +37,22 @@ const fe = (c, f) => {
36
37
  console.error("[Replica] change listener threw:", t);
37
38
  }
38
39
  }, P = (e, t) => {
39
- const o = p.get(e);
40
- o === void 0 ? p.set(e, /* @__PURE__ */ new Set([t])) : o.add(t);
40
+ const s = p.get(e);
41
+ s === void 0 ? p.set(e, /* @__PURE__ */ new Set([t])) : s.add(t);
41
42
  }, x = (e, t) => {
42
- const o = p.get(e);
43
- o !== void 0 && (o.delete(t), o.size === 0 && p.delete(e));
43
+ const s = p.get(e);
44
+ s !== void 0 && (s.delete(t), s.size === 0 && p.delete(e));
44
45
  }, Q = (e) => a(e.type) || g.has(e.id), A = (e) => {
45
46
  const t = g.get(e);
46
47
  t !== void 0 && (t.timer !== null && clearTimeout(t.timer), g.delete(e));
47
48
  }, z = (e) => {
48
- v.has(e) && (v.delete(e), M.delete(e), S.set(e, ++G));
49
+ v.has(e) && (v.delete(e), E.delete(e), S.set(e, ++G));
49
50
  }, X = (e) => {
50
51
  A(e), g.set(e, { open: !0, timer: null });
51
52
  const t = [];
52
- for (const o of g.keys()) {
53
+ for (const s of g.keys()) {
53
54
  if (g.size - t.length <= ae) break;
54
- t.push(o);
55
+ t.push(s);
55
56
  }
56
57
  t.length > 0 && j(t);
57
58
  }, ue = (e) => {
@@ -63,177 +64,177 @@ const fe = (c, f) => {
63
64
  }
64
65
  t.timer = setTimeout(() => j([e]), W), Ue(t.timer);
65
66
  }
66
- }, de = (e) => g.get(e)?.open === !0, R = (e, t, o) => {
67
- u += 1, I.push({ revision: u, id: e, type: t, deleted: o }), pe();
67
+ }, de = (e) => g.get(e)?.open === !0, R = (e, t, s) => {
68
+ u += 1, I.push({ revision: u, id: e, type: t, deleted: s }), pe();
68
69
  }, Z = () => I.length - w, pe = () => {
69
70
  const e = Z() - k;
70
71
  e <= 0 || (w += e, O = I[w - 1].revision, w * 2 >= I.length && (I = I.slice(w), w = 0));
71
72
  }, C = (e) => h.has(e) ? h.get(e) ?? null : l.get(e) ?? null, D = (e) => h.has(e) ? h.get(e) ?? void 0 : l.get(e), $ = (e) => {
72
73
  const t = new Set(p.get(e) ?? []);
73
- for (const [n, s] of h)
74
- s !== null && s.type === e ? t.add(n) : t.delete(n);
75
- const o = [];
74
+ for (const [n, o] of h)
75
+ o !== null && o.type === e ? t.add(n) : t.delete(n);
76
+ const s = [];
76
77
  for (const n of t) {
77
- const s = D(n);
78
- s !== void 0 && o.push(s);
78
+ const o = D(n);
79
+ o !== void 0 && s.push(o);
79
80
  }
80
- return o;
81
+ return s;
81
82
  }, q = (e, t) => {
82
- const o = t.update.subject_id, n = e.get(o);
83
- n === void 0 ? e.set(o, [t]) : n.push(t);
84
- }, ee = (e, t, o, n) => {
85
- const s = e.subject_id;
86
- if (!a(e.subject_type) && !g.has(s) && v.has(s)) {
87
- q(M, { update: e, gsn: t, hlc: o, position: n });
83
+ const s = t.update.subject_id, n = e.get(s);
84
+ n === void 0 ? e.set(s, [t]) : n.push(t);
85
+ }, ee = (e, t, s, n) => {
86
+ const o = e.subject_id;
87
+ if (!a(e.subject_type) && !g.has(o) && v.has(o)) {
88
+ q(E, { update: e, gsn: t, hlc: s, position: n });
88
89
  return;
89
90
  }
90
- const r = l.get(s) ?? null, i = J(r, e, t, o, H);
91
+ const r = l.get(o) ?? null, i = J(r, e, t, s, H);
91
92
  if (i === null) {
92
- if (!a(e.subject_type) && !g.has(s)) return;
93
- q(y, { update: e, gsn: t, hlc: o, position: n });
93
+ if (!a(e.subject_type) && !g.has(o)) return;
94
+ q(y, { update: e, gsn: t, hlc: s, position: n });
94
95
  return;
95
96
  }
96
97
  if (!Q(i)) {
97
- r !== null && (l.delete(s), x(r.type, s)), e.method === "put" && y.delete(s);
98
+ r !== null && (l.delete(o), x(r.type, o)), e.method === "put" && y.delete(o);
98
99
  return;
99
100
  }
100
- if (l.set(s, i), r !== null && r.type !== i.type && x(r.type, s), P(i.type, s), e.method === "put") {
101
- const b = y.get(s);
101
+ if (l.set(o, i), r !== null && r.type !== i.type && x(r.type, o), P(i.type, o), e.method === "put") {
102
+ const b = y.get(o);
102
103
  if (b !== void 0) {
103
- y.delete(s);
104
+ y.delete(o);
104
105
  const K = b.filter((_) => _.gsn > t).sort((_, Te) => _.gsn - Te.gsn);
105
106
  let T = i;
106
107
  for (const _ of K)
107
108
  T = J(T, _.update, _.gsn, _.hlc, H) ?? T;
108
- T !== i && (l.set(s, T), i.type !== T.type && (x(i.type, s), P(T.type, s)));
109
+ T !== i && (l.set(o, T), i.type !== T.type && (x(i.type, o), P(T.type, o)));
109
110
  }
110
111
  }
111
112
  }, te = (e, t) => {
112
- const o = e ?? void 0, n = t ?? void 0;
113
- N = ie(N, Pe(o, n)), m = ie(m, xe(o, n));
113
+ const s = e ?? void 0, n = t ?? void 0;
114
+ N = ie(N, Pe(s, n)), m = ie(m, xe(s, n));
114
115
  }, L = (e, t) => {
115
- const o = l.get(e) ?? null, n = d.get(e);
116
- let s = o;
116
+ const s = l.get(e) ?? null, n = d.get(e);
117
+ let o = s;
117
118
  if (n !== void 0)
118
119
  for (const i of n)
119
- s = J(s, i.update, 0, i.hlc, H);
120
- const r = s !== null && Q(s) ? s : null;
120
+ o = J(o, i.update, 0, i.hlc, H);
121
+ const r = o !== null && Q(o) ? o : null;
121
122
  if ((r === null || a(r.type)) && A(e), n === void 0 || n.length === 0 ? h.delete(e) : h.set(e, r), te(t, r), r === null) {
122
- s !== null ? R(e, s.type, s.deleted_hlc !== null) : t !== null && R(e, t.type, !0);
123
+ o !== null ? R(e, o.type, o.deleted_hlc !== null) : t !== null && R(e, t.type, !0);
123
124
  return;
124
125
  }
125
126
  Re(t, r) && R(e, r.type, r.deleted_hlc !== null);
126
127
  }, B = (e, t) => {
127
128
  e.has(t) || e.set(t, C(t));
128
129
  }, ne = (e, t) => {
129
- const o = [];
130
- for (const [n, s] of d)
131
- s.some((r) => r.actionId === e) && (B(t, n), o.push(n));
132
- for (const n of o) {
130
+ const s = [];
131
+ for (const [n, o] of d)
132
+ o.some((r) => r.actionId === e) && (B(t, n), s.push(n));
133
+ for (const n of s) {
133
134
  const r = (d.get(n) ?? []).filter((i) => i.actionId !== e);
134
135
  r.length === 0 ? d.delete(n) : d.set(n, r);
135
136
  }
136
- return o;
137
- }, he = (e, t, o) => {
137
+ return s;
138
+ }, he = (e, t, s) => {
138
139
  const n = /* @__PURE__ */ new Map();
139
140
  for (const i of t) B(n, i.subject_id);
140
- const s = ne(e.id, n);
141
- for (const i of t) ee(i, e.gsn, e.hlc, o);
142
- o > E && (E = o);
141
+ const o = ne(e.id, n);
142
+ for (const i of t) ee(i, e.gsn, e.hlc, s);
143
+ s > M && (M = s);
143
144
  const r = new Set(t.map((i) => i.subject_id));
144
- for (const i of s) r.add(i);
145
+ for (const i of o) r.add(i);
145
146
  for (const i of r) L(i, n.get(i) ?? null);
146
147
  return F(), u;
147
148
  }, ge = (e) => {
148
- const t = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Set();
149
+ const t = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Set();
149
150
  for (const n of e.updates) {
150
- const s = n.subject_id;
151
- B(t, s), o.add(s);
152
- const r = { actionId: e.id, update: n, hlc: e.hlc }, i = d.get(s);
153
- i === void 0 ? d.set(s, [r]) : i.push(r);
151
+ const o = n.subject_id;
152
+ B(t, o), s.add(o);
153
+ const r = { actionId: e.id, update: n, hlc: e.hlc }, i = d.get(o);
154
+ i === void 0 ? d.set(o, [r]) : i.push(r);
154
155
  }
155
- for (const n of o) L(n, t.get(n) ?? null);
156
+ for (const n of s) L(n, t.get(n) ?? null);
156
157
  return F(), u;
157
158
  }, ye = (e) => {
158
- const t = /* @__PURE__ */ new Map(), o = ne(e, t);
159
- for (const n of o) L(n, t.get(n) ?? null);
159
+ const t = /* @__PURE__ */ new Map(), s = ne(e, t);
160
+ for (const n of s) L(n, t.get(n) ?? null);
160
161
  return F(), u;
161
162
  }, j = (e) => {
162
163
  const t = /* @__PURE__ */ new Set();
163
- let o = !1;
164
+ let s = !1;
164
165
  for (const n of e) {
165
166
  if (t.has(n)) continue;
166
- t.add(n), z(n), A(n), M.delete(n);
167
- const s = C(n), r = l.get(n);
168
- l.delete(n), d.delete(n), h.delete(n), y.delete(n), r !== void 0 && x(r.type, n), te(s, null);
169
- const i = s ?? r ?? null;
170
- i !== null && (o = !0, R(n, i.type, !0));
167
+ t.add(n), z(n), A(n), E.delete(n);
168
+ const o = C(n), r = l.get(n);
169
+ l.delete(n), d.delete(n), h.delete(n), y.delete(n), r !== void 0 && x(r.type, n), te(o, null);
170
+ const i = o ?? r ?? null;
171
+ i !== null && (s = !0, R(n, i.type, !0));
171
172
  }
172
- return o && F(), u;
173
+ return s && F(), u;
173
174
  }, ve = (e) => {
174
175
  if (!je(e)) return u;
175
- l.clear(), p.clear(), y.clear(), d.clear(), h.clear(), M.clear(), v.clear(), S.clear();
176
- for (const s of g.keys()) A(s);
176
+ l.clear(), p.clear(), y.clear(), d.clear(), h.clear(), E.clear(), v.clear(), S.clear();
177
+ for (const o of g.keys()) A(o);
177
178
  I.length = 0, w = 0;
178
- const t = {}, o = {}, n = (s, r) => {
179
- const i = s[r.key];
180
- i === void 0 ? s[r.key] = { [r.rowId]: r.value } : i[r.rowId] = r.value;
179
+ const t = {}, s = {}, n = (o, r) => {
180
+ const i = o[r.key];
181
+ i === void 0 ? o[r.key] = { [r.rowId]: r.value } : i[r.rowId] = r.value;
181
182
  };
182
- for (const s of e.entities) {
183
- if (!a(s.type)) continue;
184
- const r = re(s);
183
+ for (const o of e.entities) {
184
+ if (!a(o.type)) continue;
185
+ const r = re(o);
185
186
  l.set(r.id, r), P(r.type, r.id);
186
187
  const i = ke(r);
187
188
  i !== null && n(t, i);
188
189
  const b = Se(r);
189
- b !== null && n(o, b);
190
+ b !== null && n(s, b);
190
191
  }
191
- return N = t, m = o, u = e.revision > u ? e.revision : u + 1, O = u, E = e.position, F(), u;
192
+ return N = t, m = s, u = e.revision > u ? e.revision : u + 1, O = u, M = e.position, F(), u;
192
193
  }, Ie = () => {
193
194
  let e = Number.POSITIVE_INFINITY;
194
195
  for (const n of y.values())
195
- for (const s of n) e = Math.min(e, s.position);
196
- const t = e === Number.POSITIVE_INFINITY ? E : Math.min(E, e - 1), o = [];
196
+ for (const o of n) e = Math.min(e, o.position);
197
+ const t = e === Number.POSITIVE_INFINITY ? M : Math.min(M, e - 1), s = [];
197
198
  for (const n of l.values())
198
- a(n.type) && o.push(Ne(n));
199
+ a(n.type) && s.push(Ne(n));
199
200
  return {
200
201
  format: Oe,
201
202
  position: t,
202
203
  revision: u,
203
- entities: o
204
+ entities: s
204
205
  };
205
206
  }, we = () => {
206
- const e = {}, t = {}, o = new Set(p.keys());
207
+ const e = {}, t = {}, s = new Set(p.keys());
207
208
  for (const r of h.values())
208
- r !== null && o.add(r.type);
209
- let n = 0, s = 0;
210
- for (const r of o) {
209
+ r !== null && s.add(r.type);
210
+ let n = 0, o = 0;
211
+ for (const r of s) {
211
212
  const i = $(r).length;
212
- i !== 0 && (e[r] = i, n += i, a(r) && (t[r] = i, s += i));
213
+ i !== 0 && (e[r] = i, n += i, a(r) && (t[r] = i, o += i));
213
214
  }
214
215
  return {
215
216
  entities: n,
216
217
  byType: e,
217
- held: s,
218
+ held: o,
218
219
  heldByType: t,
219
220
  pinned: g.size,
220
221
  revision: u,
221
- position: E,
222
+ position: M,
222
223
  changes: Z(),
223
224
  changeFloor: O
224
225
  };
225
226
  }, me = (e) => {
226
227
  if (e < O) return [];
227
228
  const t = [];
228
- for (let o = w; o < I.length; o += 1) {
229
- const n = I[o];
229
+ for (let s = w; s < I.length; s += 1) {
230
+ const n = I[s];
230
231
  n.revision > e && t.push(n);
231
232
  }
232
233
  return t;
233
- }, be = (e, t, o) => {
234
+ }, be = (e, t, s) => {
234
235
  const n = C(e);
235
236
  l.set(e, t), P(t.type, e), X(e);
236
- for (const s of o) ee(s.update, s.gsn, s.hlc, s.position);
237
+ for (const o of s) ee(o.update, o.gsn, o.hlc, o.position);
237
238
  L(e, n), F();
238
239
  };
239
240
  return {
@@ -251,17 +252,17 @@ const fe = (c, f) => {
251
252
  const t = D(e);
252
253
  if (t !== void 0)
253
254
  return a(t.type) || X(e), Promise.resolve(t);
254
- const o = v.get(e);
255
- if (o !== void 0) return o;
255
+ const s = v.get(e);
256
+ if (s !== void 0) return s;
256
257
  const n = c?.readEntity;
257
258
  if (n === void 0) return Promise.resolve(null);
258
- const s = ++G;
259
- S.set(e, s);
259
+ const o = ++G;
260
+ S.set(e, o);
260
261
  const r = n(e).then(
261
262
  (i) => {
262
- if (v.get(e) === r && v.delete(e), S.get(e) !== s) return null;
263
- const b = M.get(e) ?? [];
264
- if (M.delete(e), i === null) return null;
263
+ if (v.get(e) === r && v.delete(e), S.get(e) !== o) return null;
264
+ const b = E.get(e) ?? [];
265
+ if (E.delete(e), i === null) return null;
265
266
  if (a(i.type)) return i;
266
267
  const K = re(i);
267
268
  return be(e, K, b), D(e) ?? K;
@@ -283,10 +284,10 @@ const fe = (c, f) => {
283
284
  isOpen: de,
284
285
  changesSince: me,
285
286
  stats: we,
286
- relationships: (e) => e.sourceId !== void 0 ? V(m[se(e.as, e.type, e.sourceId)]) : e.targetId !== void 0 ? V(N[Fe(e.as, e.type, e.targetId)]) : [],
287
- memberships: (e) => e.groupId !== void 0 ? V(N[Ee(e.groupId)]) : e.entityId !== void 0 ? V(m[oe(e.entityId)]) : [],
288
- relationshipLinks: (e) => Me(m[se(e.as, e.type, e.sourceId)]),
289
- membershipLinks: (e) => _e(m[oe(e)]),
287
+ relationships: (e) => e.sourceId !== void 0 ? V(m[oe(e.as, e.type, e.sourceId)]) : e.targetId !== void 0 ? V(N[Fe(e.as, e.type, e.targetId)]) : [],
288
+ memberships: (e) => e.groupId !== void 0 ? V(N[Me(e.groupId)]) : e.entityId !== void 0 ? V(m[se(e.entityId)]) : [],
289
+ relationshipLinks: (e) => Ee(m[oe(e.as, e.type, e.sourceId)]),
290
+ membershipLinks: (e) => _e(m[se(e)]),
290
291
  ingest: he,
291
292
  optimistic: ge,
292
293
  discard: ye,
@@ -304,5 +305,6 @@ export {
304
305
  J as applyUpdate,
305
306
  Re as contentChanged,
306
307
  He as createReplica,
308
+ Qe as foldEntityAction,
307
309
  Ce as holdAll
308
310
  };