@ebbjs/storage 0.0.0-stage → 0.1.1
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/LICENSE.txt +202 -0
- package/README.md +83 -2
- package/dist/cursor-record-D39emd6R.js +21 -0
- package/dist/indexeddb/index.d.ts +465 -0
- package/dist/indexeddb/index.js +335 -0
- package/dist/memory/index.d.ts +474 -0
- package/dist/memory/index.js +296 -0
- package/dist/replica/index.d.ts +271 -0
- package/dist/replica/index.js +308 -0
- package/dist/replica-record-D3lkFACh.js +167 -0
- package/dist/types/index.d.ts +621 -0
- package/dist/types/index.js +1 -0
- package/package.json +78 -3
|
@@ -0,0 +1,308 @@
|
|
|
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";
|
|
2
|
+
import { isFieldMap as ce } from "@ebbjs/core";
|
|
3
|
+
const fe = (c, f) => {
|
|
4
|
+
if (c === f) return !0;
|
|
5
|
+
const a = ce(c), l = ce(f);
|
|
6
|
+
if (a !== l || !a || !l) return !1;
|
|
7
|
+
const p = Object.keys(c.map), d = Object.keys(f.map);
|
|
8
|
+
if (p.length !== d.length) return !1;
|
|
9
|
+
for (const h of p) {
|
|
10
|
+
const y = c.map[h], k = f.map[h];
|
|
11
|
+
if (y === void 0 || k === void 0 || !fe(y, k)) return !1;
|
|
12
|
+
}
|
|
13
|
+
return !0;
|
|
14
|
+
}, Ae = (c, f) => {
|
|
15
|
+
const a = Object.keys(c);
|
|
16
|
+
if (a.length !== Object.keys(f).length) return !1;
|
|
17
|
+
for (const l of a) {
|
|
18
|
+
const p = c[l], d = f[l];
|
|
19
|
+
if (p === void 0 || d === void 0 || !fe(p, d)) return !1;
|
|
20
|
+
}
|
|
21
|
+
return !0;
|
|
22
|
+
}, U = (c) => c == null, Re = (c, f) => U(c) || U(f) ? U(c) !== U(f) : c.type !== f.type || c.updated_hlc !== f.updated_hlc || c.deleted_hlc !== f.deleted_hlc ? !0 : !Ae(c.data.fields, f.data.fields), Ce = {
|
|
23
|
+
holds: () => !0
|
|
24
|
+
}, De = 1024, Le = 16, Ke = 3e4, le = (c, f) => c === void 0 ? f : !Number.isFinite(c) || c <= 0 ? Number.POSITIVE_INFINITY : Math.max(1, Math.floor(c)), Ve = (c) => c === void 0 ? Ke : !Number.isFinite(c) || c <= 0 ? Number.POSITIVE_INFINITY : c, Ue = (c) => {
|
|
25
|
+
typeof c == "object" && "unref" in c && typeof c.unref == "function" && c.unref();
|
|
26
|
+
}, He = (c) => {
|
|
27
|
+
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
|
+
let G = 0;
|
|
29
|
+
const M = /* @__PURE__ */ new Map();
|
|
30
|
+
let I = [], w = 0, N = {}, m = {}, u = 0, O = 0, E = 0;
|
|
31
|
+
const Y = /* @__PURE__ */ new Set(), F = () => {
|
|
32
|
+
for (const e of Y)
|
|
33
|
+
try {
|
|
34
|
+
e();
|
|
35
|
+
} catch (t) {
|
|
36
|
+
console.error("[Replica] change listener threw:", t);
|
|
37
|
+
}
|
|
38
|
+
}, P = (e, t) => {
|
|
39
|
+
const o = p.get(e);
|
|
40
|
+
o === void 0 ? p.set(e, /* @__PURE__ */ new Set([t])) : o.add(t);
|
|
41
|
+
}, x = (e, t) => {
|
|
42
|
+
const o = p.get(e);
|
|
43
|
+
o !== void 0 && (o.delete(t), o.size === 0 && p.delete(e));
|
|
44
|
+
}, Q = (e) => a(e.type) || g.has(e.id), A = (e) => {
|
|
45
|
+
const t = g.get(e);
|
|
46
|
+
t !== void 0 && (t.timer !== null && clearTimeout(t.timer), g.delete(e));
|
|
47
|
+
}, z = (e) => {
|
|
48
|
+
v.has(e) && (v.delete(e), M.delete(e), S.set(e, ++G));
|
|
49
|
+
}, X = (e) => {
|
|
50
|
+
A(e), g.set(e, { open: !0, timer: null });
|
|
51
|
+
const t = [];
|
|
52
|
+
for (const o of g.keys()) {
|
|
53
|
+
if (g.size - t.length <= ae) break;
|
|
54
|
+
t.push(o);
|
|
55
|
+
}
|
|
56
|
+
t.length > 0 && j(t);
|
|
57
|
+
}, ue = (e) => {
|
|
58
|
+
const t = g.get(e);
|
|
59
|
+
if (!(t === void 0 || !t.open)) {
|
|
60
|
+
if (t.open = !1, !Number.isFinite(W)) {
|
|
61
|
+
j([e]);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
t.timer = setTimeout(() => j([e]), W), Ue(t.timer);
|
|
65
|
+
}
|
|
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();
|
|
68
|
+
}, Z = () => I.length - w, pe = () => {
|
|
69
|
+
const e = Z() - k;
|
|
70
|
+
e <= 0 || (w += e, O = I[w - 1].revision, w * 2 >= I.length && (I = I.slice(w), w = 0));
|
|
71
|
+
}, 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
|
+
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 = [];
|
|
76
|
+
for (const n of t) {
|
|
77
|
+
const s = D(n);
|
|
78
|
+
s !== void 0 && o.push(s);
|
|
79
|
+
}
|
|
80
|
+
return o;
|
|
81
|
+
}, 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 });
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const r = l.get(s) ?? null, i = J(r, e, t, o, H);
|
|
91
|
+
if (i === null) {
|
|
92
|
+
if (!a(e.subject_type) && !g.has(s)) return;
|
|
93
|
+
q(y, { update: e, gsn: t, hlc: o, position: n });
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
if (!Q(i)) {
|
|
97
|
+
r !== null && (l.delete(s), x(r.type, s)), e.method === "put" && y.delete(s);
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
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);
|
|
102
|
+
if (b !== void 0) {
|
|
103
|
+
y.delete(s);
|
|
104
|
+
const K = b.filter((_) => _.gsn > t).sort((_, Te) => _.gsn - Te.gsn);
|
|
105
|
+
let T = i;
|
|
106
|
+
for (const _ of K)
|
|
107
|
+
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
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}, 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));
|
|
114
|
+
}, L = (e, t) => {
|
|
115
|
+
const o = l.get(e) ?? null, n = d.get(e);
|
|
116
|
+
let s = o;
|
|
117
|
+
if (n !== void 0)
|
|
118
|
+
for (const i of n)
|
|
119
|
+
s = J(s, i.update, 0, i.hlc, H);
|
|
120
|
+
const r = s !== null && Q(s) ? s : null;
|
|
121
|
+
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
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
Re(t, r) && R(e, r.type, r.deleted_hlc !== null);
|
|
126
|
+
}, B = (e, t) => {
|
|
127
|
+
e.has(t) || e.set(t, C(t));
|
|
128
|
+
}, 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) {
|
|
133
|
+
const r = (d.get(n) ?? []).filter((i) => i.actionId !== e);
|
|
134
|
+
r.length === 0 ? d.delete(n) : d.set(n, r);
|
|
135
|
+
}
|
|
136
|
+
return o;
|
|
137
|
+
}, he = (e, t, o) => {
|
|
138
|
+
const n = /* @__PURE__ */ new Map();
|
|
139
|
+
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);
|
|
143
|
+
const r = new Set(t.map((i) => i.subject_id));
|
|
144
|
+
for (const i of s) r.add(i);
|
|
145
|
+
for (const i of r) L(i, n.get(i) ?? null);
|
|
146
|
+
return F(), u;
|
|
147
|
+
}, ge = (e) => {
|
|
148
|
+
const t = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Set();
|
|
149
|
+
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);
|
|
154
|
+
}
|
|
155
|
+
for (const n of o) L(n, t.get(n) ?? null);
|
|
156
|
+
return F(), u;
|
|
157
|
+
}, ye = (e) => {
|
|
158
|
+
const t = /* @__PURE__ */ new Map(), o = ne(e, t);
|
|
159
|
+
for (const n of o) L(n, t.get(n) ?? null);
|
|
160
|
+
return F(), u;
|
|
161
|
+
}, j = (e) => {
|
|
162
|
+
const t = /* @__PURE__ */ new Set();
|
|
163
|
+
let o = !1;
|
|
164
|
+
for (const n of e) {
|
|
165
|
+
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));
|
|
171
|
+
}
|
|
172
|
+
return o && F(), u;
|
|
173
|
+
}, ve = (e) => {
|
|
174
|
+
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);
|
|
177
|
+
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;
|
|
181
|
+
};
|
|
182
|
+
for (const s of e.entities) {
|
|
183
|
+
if (!a(s.type)) continue;
|
|
184
|
+
const r = re(s);
|
|
185
|
+
l.set(r.id, r), P(r.type, r.id);
|
|
186
|
+
const i = ke(r);
|
|
187
|
+
i !== null && n(t, i);
|
|
188
|
+
const b = Se(r);
|
|
189
|
+
b !== null && n(o, b);
|
|
190
|
+
}
|
|
191
|
+
return N = t, m = o, u = e.revision > u ? e.revision : u + 1, O = u, E = e.position, F(), u;
|
|
192
|
+
}, Ie = () => {
|
|
193
|
+
let e = Number.POSITIVE_INFINITY;
|
|
194
|
+
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 = [];
|
|
197
|
+
for (const n of l.values())
|
|
198
|
+
a(n.type) && o.push(Ne(n));
|
|
199
|
+
return {
|
|
200
|
+
format: Oe,
|
|
201
|
+
position: t,
|
|
202
|
+
revision: u,
|
|
203
|
+
entities: o
|
|
204
|
+
};
|
|
205
|
+
}, we = () => {
|
|
206
|
+
const e = {}, t = {}, o = new Set(p.keys());
|
|
207
|
+
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) {
|
|
211
|
+
const i = $(r).length;
|
|
212
|
+
i !== 0 && (e[r] = i, n += i, a(r) && (t[r] = i, s += i));
|
|
213
|
+
}
|
|
214
|
+
return {
|
|
215
|
+
entities: n,
|
|
216
|
+
byType: e,
|
|
217
|
+
held: s,
|
|
218
|
+
heldByType: t,
|
|
219
|
+
pinned: g.size,
|
|
220
|
+
revision: u,
|
|
221
|
+
position: E,
|
|
222
|
+
changes: Z(),
|
|
223
|
+
changeFloor: O
|
|
224
|
+
};
|
|
225
|
+
}, me = (e) => {
|
|
226
|
+
if (e < O) return [];
|
|
227
|
+
const t = [];
|
|
228
|
+
for (let o = w; o < I.length; o += 1) {
|
|
229
|
+
const n = I[o];
|
|
230
|
+
n.revision > e && t.push(n);
|
|
231
|
+
}
|
|
232
|
+
return t;
|
|
233
|
+
}, be = (e, t, o) => {
|
|
234
|
+
const n = C(e);
|
|
235
|
+
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
|
+
L(e, n), F();
|
|
238
|
+
};
|
|
239
|
+
return {
|
|
240
|
+
get revision() {
|
|
241
|
+
return u;
|
|
242
|
+
},
|
|
243
|
+
get changeFloor() {
|
|
244
|
+
return O;
|
|
245
|
+
},
|
|
246
|
+
get: D,
|
|
247
|
+
base: (e) => l.get(e),
|
|
248
|
+
iterate: $,
|
|
249
|
+
isHeld: a,
|
|
250
|
+
open: (e) => {
|
|
251
|
+
const t = D(e);
|
|
252
|
+
if (t !== void 0)
|
|
253
|
+
return a(t.type) || X(e), Promise.resolve(t);
|
|
254
|
+
const o = v.get(e);
|
|
255
|
+
if (o !== void 0) return o;
|
|
256
|
+
const n = c?.readEntity;
|
|
257
|
+
if (n === void 0) return Promise.resolve(null);
|
|
258
|
+
const s = ++G;
|
|
259
|
+
S.set(e, s);
|
|
260
|
+
const r = n(e).then(
|
|
261
|
+
(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;
|
|
265
|
+
if (a(i.type)) return i;
|
|
266
|
+
const K = re(i);
|
|
267
|
+
return be(e, K, b), D(e) ?? K;
|
|
268
|
+
},
|
|
269
|
+
(i) => {
|
|
270
|
+
throw v.get(e) === r && v.delete(e), i;
|
|
271
|
+
}
|
|
272
|
+
);
|
|
273
|
+
return v.set(e, r), r;
|
|
274
|
+
},
|
|
275
|
+
close: (e) => {
|
|
276
|
+
const t = C(e);
|
|
277
|
+
if (t === null) {
|
|
278
|
+
z(e);
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
a(t.type) || (z(e), g.has(e) ? ue(e) : j([e]));
|
|
282
|
+
},
|
|
283
|
+
isOpen: de,
|
|
284
|
+
changesSince: me,
|
|
285
|
+
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)]),
|
|
290
|
+
ingest: he,
|
|
291
|
+
optimistic: ge,
|
|
292
|
+
discard: ye,
|
|
293
|
+
load: ve,
|
|
294
|
+
toRecord: Ie,
|
|
295
|
+
evict: j,
|
|
296
|
+
subscribe: (e) => (Y.add(e), () => {
|
|
297
|
+
Y.delete(e);
|
|
298
|
+
})
|
|
299
|
+
};
|
|
300
|
+
};
|
|
301
|
+
export {
|
|
302
|
+
Le as DEFAULT_PINNED_CAPACITY,
|
|
303
|
+
Ke as DEFAULT_PINNED_TTL_MS,
|
|
304
|
+
J as applyUpdate,
|
|
305
|
+
Re as contentChanged,
|
|
306
|
+
He as createReplica,
|
|
307
|
+
Ce as holdAll
|
|
308
|
+
};
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { isFieldMap as u, mergeFieldValue as m, latestHlc as P, isFieldLeaf as D } from "@ebbjs/core";
|
|
2
|
+
const L = 500, M = 64, I = /* @__PURE__ */ new WeakMap(), N = (e) => {
|
|
3
|
+
let r = 2166136261;
|
|
4
|
+
for (let t = 0; t < e.length; t += 1)
|
|
5
|
+
r ^= e.charCodeAt(t), r = Math.imul(r, 16777619) >>> 0;
|
|
6
|
+
return r >>> 0;
|
|
7
|
+
}, E = (e) => N(e) % M, C = () => Array.from({ length: M }, () => ({})), R = (e, r) => {
|
|
8
|
+
let t = r;
|
|
9
|
+
const n = {
|
|
10
|
+
get map() {
|
|
11
|
+
if (t === void 0) {
|
|
12
|
+
const s = {};
|
|
13
|
+
for (const o of e) Object.assign(s, o);
|
|
14
|
+
t = s;
|
|
15
|
+
}
|
|
16
|
+
return t;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
return I.set(n, e), n;
|
|
20
|
+
}, _ = (e) => u(e) && I.has(e), H = (e) => {
|
|
21
|
+
const r = I.get(e);
|
|
22
|
+
if (r === void 0) throw new Error("not a sharded map field");
|
|
23
|
+
return r;
|
|
24
|
+
}, V = (e) => e.map, W = (e) => {
|
|
25
|
+
const r = C(), t = {};
|
|
26
|
+
for (const [n, s] of Object.entries(e))
|
|
27
|
+
r[E(n)][n] = s, t[n] = s;
|
|
28
|
+
return R(r, t);
|
|
29
|
+
}, b = (e) => !u(e) || _(e) ? e : Object.keys(e.map).length >= L ? W(e.map) : e, k = (e) => {
|
|
30
|
+
let r;
|
|
31
|
+
for (const [t, n] of Object.entries(e)) {
|
|
32
|
+
const s = b(n);
|
|
33
|
+
s !== n && (r === void 0 && (r = { ...e }), r[t] = s);
|
|
34
|
+
}
|
|
35
|
+
return r ?? e;
|
|
36
|
+
}, K = (e) => {
|
|
37
|
+
let r;
|
|
38
|
+
for (const [t, n] of Object.entries(e))
|
|
39
|
+
!u(n) || !_(n) || (r === void 0 && (r = { ...e }), r[t] = { map: V(n) });
|
|
40
|
+
return r ?? e;
|
|
41
|
+
}, Y = (e, r) => {
|
|
42
|
+
const t = H(e), n = [...t], s = /* @__PURE__ */ new Map();
|
|
43
|
+
for (const [o, d] of Object.entries(r.map)) {
|
|
44
|
+
const a = E(o), c = (s.get(a) ?? t[a])[o], F = m(c, d);
|
|
45
|
+
if (F === c) continue;
|
|
46
|
+
let i = s.get(a);
|
|
47
|
+
i === void 0 && (i = { ...t[a] }, s.set(a, i)), i[o] = F;
|
|
48
|
+
}
|
|
49
|
+
if (s.size === 0) return e;
|
|
50
|
+
for (const [o, d] of s) n[o] = d;
|
|
51
|
+
return R(n);
|
|
52
|
+
}, $ = (e, r) => {
|
|
53
|
+
if (e !== void 0 && u(e) && _(e))
|
|
54
|
+
return u(r) ? Y(e, r) : r;
|
|
55
|
+
const t = m(e, r);
|
|
56
|
+
return t === e ? t : b(t);
|
|
57
|
+
}, h = (e) => e.data?.fields ?? {}, de = { residentMapFields: !0 }, B = (e, r, t) => {
|
|
58
|
+
const n = h(r), s = t?.residentMapFields ? $ : m;
|
|
59
|
+
let o;
|
|
60
|
+
for (const [d, a] of Object.entries(n)) {
|
|
61
|
+
const p = o === void 0 ? e.fields[d] : o[d], c = s(p, a);
|
|
62
|
+
c !== p && (o === void 0 && (o = { ...e.fields }), o[d] = c);
|
|
63
|
+
}
|
|
64
|
+
return o === void 0 ? e : { fields: o };
|
|
65
|
+
}, y = (e, r) => {
|
|
66
|
+
const t = r(e.data.fields);
|
|
67
|
+
return t === e.data.fields ? e : { ...e, data: { ...e.data, fields: t } };
|
|
68
|
+
}, ae = (e) => y(e, k), ce = (e) => y(e, K), ue = (e, r, t, n, s) => {
|
|
69
|
+
switch (r.method) {
|
|
70
|
+
case "put":
|
|
71
|
+
return {
|
|
72
|
+
id: r.subject_id,
|
|
73
|
+
type: r.subject_type,
|
|
74
|
+
data: {
|
|
75
|
+
fields: s?.residentMapFields ? k(h(r)) : h(r)
|
|
76
|
+
},
|
|
77
|
+
created_hlc: n,
|
|
78
|
+
updated_hlc: n,
|
|
79
|
+
deleted_hlc: null,
|
|
80
|
+
last_gsn: t
|
|
81
|
+
};
|
|
82
|
+
case "patch":
|
|
83
|
+
return e ? e.deleted_hlc ? e : {
|
|
84
|
+
...e,
|
|
85
|
+
data: B(e.data, r, s),
|
|
86
|
+
updated_hlc: P(e.updated_hlc, n),
|
|
87
|
+
last_gsn: Math.max(e.last_gsn, t)
|
|
88
|
+
} : null;
|
|
89
|
+
case "delete":
|
|
90
|
+
return e ? {
|
|
91
|
+
...e,
|
|
92
|
+
deleted_hlc: n,
|
|
93
|
+
updated_hlc: n,
|
|
94
|
+
last_gsn: Math.max(e.last_gsn, t)
|
|
95
|
+
} : null;
|
|
96
|
+
}
|
|
97
|
+
}, S = "relationship", f = "entityGroup", O = "groups", v = (e, r, t) => `${e}\0${r}\0${t}`, j = (e, r, t) => `${v(e, r, t)}`, U = (e) => v(O, f, e), q = (e) => j(O, f, e), l = (e, r) => {
|
|
98
|
+
const t = e.data?.fields?.[r];
|
|
99
|
+
if (t === void 0 || !D(t)) return null;
|
|
100
|
+
const n = t.value;
|
|
101
|
+
return typeof n == "string" ? n : null;
|
|
102
|
+
}, z = (e) => {
|
|
103
|
+
if (e.type !== S || e.deleted_hlc !== null) return null;
|
|
104
|
+
const r = l(e, "field"), t = l(e, "type"), n = l(e, "target_id"), s = l(e, "source_id");
|
|
105
|
+
return r === null || t === null || n === null || s === null ? null : { key: v(r, t, n), rowId: e.id, value: s };
|
|
106
|
+
}, G = (e) => {
|
|
107
|
+
if (e.type !== S || e.deleted_hlc !== null) return null;
|
|
108
|
+
const r = l(e, "field"), t = l(e, "type"), n = l(e, "source_id"), s = l(e, "target_id");
|
|
109
|
+
return r === null || t === null || n === null || s === null ? null : { key: j(r, t, n), rowId: e.id, value: s };
|
|
110
|
+
}, J = (e) => {
|
|
111
|
+
if (e.type !== f || e.deleted_hlc !== null) return null;
|
|
112
|
+
const r = l(e, "group_id"), t = l(e, "entity_id");
|
|
113
|
+
return r === null || t === null ? null : { key: U(r), rowId: e.id, value: t };
|
|
114
|
+
}, Q = (e) => {
|
|
115
|
+
if (e.type !== f || e.deleted_hlc !== null) return null;
|
|
116
|
+
const r = l(e, "group_id"), t = l(e, "entity_id");
|
|
117
|
+
return r === null || t === null ? null : { key: q(t), rowId: e.id, value: r };
|
|
118
|
+
}, X = (e) => z(e) ?? J(e), Z = (e) => G(e) ?? Q(e), ee = (e) => [...e].sort(), ie = (e) => ee(new Set(Object.values(e ?? {}))), x = (e) => Object.entries(e ?? {}).map(([r, t]) => ({ rowId: r, value: t })).sort(
|
|
119
|
+
(r, t) => r.value === t.value ? r.rowId.localeCompare(t.rowId) : r.value.localeCompare(t.value)
|
|
120
|
+
), fe = (e) => x(e).map(({ rowId: r, value: t }) => ({ relationshipId: r, targetId: t })), pe = (e) => x(e).map(({ rowId: r, value: t }) => ({ membershipId: r, groupId: t })), A = (e, r, t) => {
|
|
121
|
+
const n = { ...e };
|
|
122
|
+
return t ? n[r.rowId] = r.value : delete n[r.rowId], n;
|
|
123
|
+
}, re = (e, r) => A(e, r, !0), te = (e, r) => {
|
|
124
|
+
const t = A(e, r, !1);
|
|
125
|
+
return Object.keys(t).length === 0 ? null : t;
|
|
126
|
+
}, ne = (e, r) => e?.key === r?.key && e?.rowId === r?.rowId && e?.value === r?.value, T = (e) => (r, t) => {
|
|
127
|
+
const n = r === void 0 ? null : e(r), s = t === void 0 ? null : e(t);
|
|
128
|
+
return ne(n, s) ? { remove: null, add: null } : { remove: n, add: s };
|
|
129
|
+
}, he = T(X), me = T(Z), w = (e, r, t) => {
|
|
130
|
+
if (t === null) {
|
|
131
|
+
const n = { ...e };
|
|
132
|
+
return delete n[r.key], n;
|
|
133
|
+
}
|
|
134
|
+
return { ...e, [r.key]: t };
|
|
135
|
+
}, Ie = (e, r) => {
|
|
136
|
+
if (r.remove === null && r.add === null) return e;
|
|
137
|
+
let t = e;
|
|
138
|
+
return r.remove !== null && (t = w(t, r.remove, te(t[r.remove.key], r.remove))), r.add !== null && (t = w(t, r.add, re(t[r.add.key], r.add))), t;
|
|
139
|
+
}, se = 1, g = (e) => typeof e == "number" && Number.isInteger(e) && e >= 0, oe = (e) => typeof e == "object" && e !== null && typeof e.id == "string" && typeof e.type == "string", _e = (e) => {
|
|
140
|
+
if (typeof e != "object" || e === null) return !1;
|
|
141
|
+
const r = e;
|
|
142
|
+
return r.format !== se || !g(r.position) || !g(r.revision) || !Array.isArray(r.entities) ? !1 : r.entities.every(oe);
|
|
143
|
+
};
|
|
144
|
+
export {
|
|
145
|
+
f as M,
|
|
146
|
+
se as R,
|
|
147
|
+
fe as a,
|
|
148
|
+
ie as b,
|
|
149
|
+
q as c,
|
|
150
|
+
ae as d,
|
|
151
|
+
X as e,
|
|
152
|
+
j as f,
|
|
153
|
+
Z as g,
|
|
154
|
+
Ie as h,
|
|
155
|
+
_e as i,
|
|
156
|
+
he as j,
|
|
157
|
+
me as k,
|
|
158
|
+
pe as l,
|
|
159
|
+
U as m,
|
|
160
|
+
ue as n,
|
|
161
|
+
de as o,
|
|
162
|
+
S as p,
|
|
163
|
+
te as q,
|
|
164
|
+
v as r,
|
|
165
|
+
re as s,
|
|
166
|
+
ce as w
|
|
167
|
+
};
|