@blogmcp/sdk 0.9.3 → 0.10.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.
Files changed (61) hide show
  1. package/dist/community/channels.d.ts +7 -6
  2. package/dist/community/channels.js +4 -4
  3. package/dist/community/client.d.ts +74 -4
  4. package/dist/community/client.js +143 -91
  5. package/dist/community/index.d.ts +11 -6
  6. package/dist/community/index.js +111 -80
  7. package/dist/community/links.d.ts +61 -1
  8. package/dist/community/links.js +94 -40
  9. package/dist/community/manifest/index.d.ts +54 -0
  10. package/dist/community/manifest/index.js +46 -0
  11. package/dist/community/mentions.d.ts +38 -0
  12. package/dist/community/mentions.js +25 -0
  13. package/dist/community/messages.cs.d.ts +73 -3
  14. package/dist/community/messages.cs.js +82 -3
  15. package/dist/community/messages.d.ts +11 -0
  16. package/dist/community/messages.en.d.ts +69 -1
  17. package/dist/community/messages.en.js +71 -1
  18. package/dist/community/messages.js +26 -16
  19. package/dist/community/outcome.d.ts +8 -3
  20. package/dist/community/outcome.js +72 -28
  21. package/dist/community/realtime/index.d.ts +118 -0
  22. package/dist/community/realtime/index.js +215 -0
  23. package/dist/community/routes.d.ts +12 -0
  24. package/dist/community/routes.js +41 -25
  25. package/dist/community/server/bff.js +25 -25
  26. package/dist/community/server/host-routes.js +12 -0
  27. package/dist/community/server/index.d.ts +1 -1
  28. package/dist/community/server/index.js +15 -14
  29. package/dist/community/server/route-decision.d.ts +8 -0
  30. package/dist/community/server/route-decision.js +28 -22
  31. package/dist/community/shapes.d.ts +214 -2
  32. package/dist/community/shapes.js +65 -25
  33. package/dist/community/store.d.ts +18 -1
  34. package/dist/community/store.js +316 -261
  35. package/dist/community/sw/index.d.ts +45 -0
  36. package/dist/community/sw/index.js +59 -0
  37. package/dist/community/ua.d.ts +12 -0
  38. package/dist/community/ua.js +9 -0
  39. package/dist/packages/mdx-render-vue/dist/node_modules/dompurify/dist/purify.es.js +1342 -484
  40. package/dist/packages/tripmap-core/dist/generated/maplibre-worker.bundle.js +1 -1
  41. package/package.json +21 -3
  42. package/src/community/channels.ts +8 -7
  43. package/src/community/client.ts +116 -5
  44. package/src/community/index.ts +59 -1
  45. package/src/community/links.ts +119 -2
  46. package/src/community/manifest/index.ts +107 -0
  47. package/src/community/mentions.ts +59 -0
  48. package/src/community/messages.cs.ts +88 -3
  49. package/src/community/messages.en.ts +77 -1
  50. package/src/community/messages.ts +19 -0
  51. package/src/community/outcome.ts +50 -1
  52. package/src/community/realtime/index.ts +522 -0
  53. package/src/community/routes.ts +16 -0
  54. package/src/community/server/bff.ts +2 -4
  55. package/src/community/server/host-routes.ts +12 -0
  56. package/src/community/server/index.ts +1 -0
  57. package/src/community/server/route-decision.ts +15 -0
  58. package/src/community/shapes.ts +256 -3
  59. package/src/community/store.ts +114 -0
  60. package/src/community/sw/index.ts +112 -0
  61. package/src/community/ua.ts +17 -0
@@ -1,85 +1,85 @@
1
- import { isKnownNeed as H, isKnownState as ce, isKnownRestrictionKind as ue, isKnownAuthorKind as ae } from "./shapes.js";
2
- const O = (e) => typeof e == "object" && e !== null && !Array.isArray(e), u = (e) => typeof e == "string" ? e : null, N = (e) => typeof e == "number" && Number.isSafeInteger(e) && e > 0, R = Object.freeze({ counts: Object.freeze({}), mine: null });
3
- function D(e) {
4
- if (!O(e)) return R;
5
- const n = {};
6
- if (O(e.counts))
7
- for (const [s, r] of Object.entries(e.counts))
8
- typeof r == "number" && Number.isSafeInteger(r) && r > 0 && (n[s] = r);
9
- return Object.freeze({ counts: Object.freeze(n), mine: u(e.mine) });
1
+ import { isKnownNeed as w, isKnownState as ge, isKnownRestrictionKind as me, isKnownAuthorKind as be } from "./shapes.js";
2
+ const C = (e) => typeof e == "object" && e !== null && !Array.isArray(e), f = (e) => typeof e == "string" ? e : null, P = (e) => typeof e == "number" && Number.isSafeInteger(e) && e > 0, D = Object.freeze({ counts: Object.freeze({}), mine: null });
3
+ function L(e) {
4
+ if (!C(e)) return D;
5
+ const s = {};
6
+ if (C(e.counts))
7
+ for (const [n, r] of Object.entries(e.counts))
8
+ typeof r == "number" && Number.isSafeInteger(r) && r > 0 && (s[n] = r);
9
+ return Object.freeze({ counts: Object.freeze(s), mine: f(e.mine) });
10
10
  }
11
- const U = Object.freeze({
11
+ const $ = Object.freeze({
12
12
  kind: "member",
13
13
  memberId: null,
14
14
  handle: null,
15
15
  displayName: null,
16
16
  avatarPreset: null,
17
17
  deleted: !0
18
- }), de = Object.freeze({ kind: "system" });
19
- function Y(e) {
20
- if (!O(e) || !ae(e.kind)) return null;
21
- if (e.kind === "system") return de;
18
+ }), ye = Object.freeze({ kind: "system" });
19
+ function J(e) {
20
+ if (!C(e) || !be(e.kind)) return null;
21
+ if (e.kind === "system") return ye;
22
22
  if (e.kind === "staff")
23
- return Object.freeze({ kind: "staff", staffId: u(e.staffId) ?? "", displayName: u(e.displayName) ?? "", badge: u(e.badge) ?? "" });
24
- const n = u(e.memberId), s = u(e.handle), r = u(e.displayName);
25
- return n === null || s === null || r === null || e.deleted === !0 ? U : Object.freeze({ kind: "member", memberId: n, handle: s, displayName: r, avatarPreset: u(e.avatarPreset) });
23
+ return Object.freeze({ kind: "staff", staffId: f(e.staffId) ?? "", displayName: f(e.displayName) ?? "", badge: f(e.badge) ?? "" });
24
+ const s = f(e.memberId), n = f(e.handle), r = f(e.displayName);
25
+ return s === null || n === null || r === null || e.deleted === !0 ? $ : Object.freeze({ kind: "member", memberId: s, handle: n, displayName: r, avatarPreset: f(e.avatarPreset) });
26
26
  }
27
- function G(e) {
27
+ function Q(e) {
28
28
  if (Array.isArray(e))
29
- return Object.freeze(e.filter((n) => typeof n == "string"));
29
+ return Object.freeze(e.filter((s) => typeof s == "string"));
30
30
  }
31
- function L(e, n) {
32
- if (!O(e)) return null;
33
- const s = Y(e.author);
34
- if (s === null || !ce(e.state)) return null;
35
- const r = u(e.conversationId), i = u(e.id);
36
- if (r === null || i === null || !N(e.seq)) return null;
37
- const p = u(e.body), b = [];
38
- if (n && Array.isArray(e.replies))
39
- for (const A of e.replies) {
40
- const v = L(A, !1);
41
- v && b.push(v);
31
+ function N(e, s) {
32
+ if (!C(e)) return null;
33
+ const n = J(e.author);
34
+ if (n === null || !ge(e.state)) return null;
35
+ const r = f(e.conversationId), c = f(e.id);
36
+ if (r === null || c === null || !P(e.seq)) return null;
37
+ const g = f(e.body), m = [];
38
+ if (s && Array.isArray(e.replies))
39
+ for (const y of e.replies) {
40
+ const M = N(y, !1);
41
+ M && m.push(M);
42
42
  }
43
- const g = G(e.notes);
43
+ const z = Q(e.notes);
44
44
  return Object.freeze({
45
45
  conversationId: r,
46
46
  seq: e.seq,
47
- id: i,
47
+ id: c,
48
48
  rev: typeof e.rev == "number" ? e.rev : 0,
49
- replyToSeq: n ? null : N(e.replyToSeq) ? e.replyToSeq : null,
50
- author: s,
49
+ replyToSeq: s ? null : P(e.replyToSeq) ? e.replyToSeq : null,
50
+ author: n,
51
51
  state: e.state,
52
- body: p,
53
- displayBody: u(e.displayBody) ?? p,
54
- displayLanguageCode: u(e.displayLanguageCode),
55
- sourceLanguageCode: u(e.sourceLanguageCode),
52
+ body: g,
53
+ displayBody: f(e.displayBody) ?? g,
54
+ displayLanguageCode: f(e.displayLanguageCode),
55
+ sourceLanguageCode: f(e.sourceLanguageCode),
56
56
  isTranslated: e.isTranslated === !0,
57
57
  isEdited: e.isEdited === !0,
58
- createdAt: u(e.createdAt) ?? "",
59
- editedAt: u(e.editedAt),
58
+ createdAt: f(e.createdAt) ?? "",
59
+ editedAt: f(e.editedAt),
60
60
  collapsed: e.collapsed === !0,
61
- reactions: D(e.reactions),
62
- translationVersionId: u(e.translationVersionId),
63
- ...g && g.length > 0 ? { notes: g } : {},
61
+ reactions: L(e.reactions),
62
+ translationVersionId: f(e.translationVersionId),
63
+ ...z && z.length > 0 ? { notes: z } : {},
64
64
  // Only as kb-api sends it: true, on a `held` message (the author's own, held back by the art. 9 policy).
65
65
  ...e.hiddenUntilConsent === !0 && e.state === "held" ? { hiddenUntilConsent: !0 } : {},
66
- replies: j(b),
67
- ...n && e.repliesTruncated === !0 ? { repliesTruncated: !0 } : {}
66
+ replies: x(m),
67
+ ...s && e.repliesTruncated === !0 ? { repliesTruncated: !0 } : {}
68
68
  });
69
69
  }
70
- function fe(e) {
71
- const n = O(e) ? e : {}, s = Array.isArray(n.needs) ? n.needs.filter(H) : [], r = [];
72
- if (Array.isArray(n.restrictions))
73
- for (const i of n.restrictions)
74
- !O(i) || !ue(i.kind) || typeof i.decisionId != "string" || r.push(Object.freeze({ kind: i.kind, scope: u(i.scope) ?? "", endsAt: u(i.endsAt), decisionId: i.decisionId }));
70
+ function Ie(e) {
71
+ const s = C(e) ? e : {}, n = Array.isArray(s.needs) ? s.needs.filter(w) : [], r = [];
72
+ if (Array.isArray(s.restrictions))
73
+ for (const c of s.restrictions)
74
+ !C(c) || !me(c.kind) || typeof c.decisionId != "string" || r.push(Object.freeze({ kind: c.kind, scope: f(c.scope) ?? "", endsAt: f(c.endsAt), decisionId: c.decisionId }));
75
75
  return Object.freeze({
76
- memberId: u(n.memberId),
77
- canPost: n.canPost === !0,
78
- needs: Object.freeze([...new Set(s)]),
76
+ memberId: f(s.memberId),
77
+ canPost: s.canPost === !0,
78
+ needs: Object.freeze([...new Set(n)]),
79
79
  restrictions: Object.freeze(r)
80
80
  });
81
81
  }
82
- const pe = Object.freeze({ memberId: null, canPost: !1, needs: Object.freeze([]), restrictions: Object.freeze([]) }), _ = Object.freeze({
82
+ const qe = Object.freeze({ memberId: null, canPost: !1, needs: Object.freeze([]), restrictions: Object.freeze([]) }), V = Object.freeze({
83
83
  articleId: null,
84
84
  conversationId: null,
85
85
  count: 0,
@@ -87,125 +87,130 @@ const pe = Object.freeze({ memberId: null, canPost: !1, needs: Object.freeze([])
87
87
  lastChangeAt: null,
88
88
  messages: Object.freeze([]),
89
89
  nextCursor: null,
90
- articleReactions: R,
90
+ articleReactions: D,
91
91
  reactionSet: Object.freeze([]),
92
92
  preset: null,
93
- viewer: pe,
93
+ viewer: qe,
94
94
  loaded: !1,
95
95
  stale: !1
96
- }), ge = (e, n) => e === null ? n : n === null ? e : Date.parse(n) > Date.parse(e) ? n : e;
97
- function j(e) {
98
- const n = e.filter((r) => r.seq > 0).sort((r, i) => r.seq - i.seq), s = e.filter((r) => r.seq < 0).sort((r, i) => i.seq - r.seq);
99
- return Object.freeze([...n, ...s]);
96
+ }), Se = (e, s) => e === null ? s : s === null ? e : Date.parse(s) > Date.parse(e) ? s : e;
97
+ function x(e) {
98
+ const s = e.filter((r) => r.seq > 0).sort((r, c) => r.seq - c.seq), n = e.filter((r) => r.seq < 0).sort((r, c) => c.seq - r.seq);
99
+ return Object.freeze([...s, ...n]);
100
100
  }
101
- function z(e, n) {
102
- let s = !1;
101
+ function T(e, s) {
102
+ let n = !1;
103
103
  const r = [];
104
- for (const i of e) {
105
- let p = n(i);
106
- if (p !== null && p.replies.length > 0) {
107
- const b = z(p.replies, n);
108
- b !== p.replies && (p = Object.freeze({ ...p, replies: b }));
104
+ for (const c of e) {
105
+ let g = s(c);
106
+ if (g !== null && g.replies.length > 0) {
107
+ const m = T(g.replies, s);
108
+ m !== g.replies && (g = Object.freeze({ ...g, replies: m }));
109
109
  }
110
- p !== i && (s = !0), p !== null && r.push(p);
110
+ g !== c && (n = !0), g !== null && r.push(g);
111
111
  }
112
- return s ? Object.freeze(r) : e;
112
+ return n ? Object.freeze(r) : e;
113
113
  }
114
- function h(e, n) {
115
- for (const s of e) {
116
- if (n(s)) return s;
117
- for (const r of s.replies) if (n(r)) return r;
114
+ function h(e, s) {
115
+ for (const n of e) {
116
+ if (s(n)) return n;
117
+ for (const r of n.replies) if (s(r)) return r;
118
118
  }
119
119
  return null;
120
120
  }
121
- function W(e, n) {
122
- return z(e, (s) => s.seq === n.seq ? s.replyToSeq === null && n.replyToSeq === null ? Object.freeze({ ...n, replies: s.replies }) : n : s);
121
+ function K(e, s) {
122
+ return T(e, (n) => n.seq === s.seq ? n.replyToSeq === null && s.replyToSeq === null ? Object.freeze({ ...s, replies: n.replies }) : s : n);
123
123
  }
124
- function be(e, n) {
125
- if (h(e, (r) => r.seq === n.seq)) return W(e, n);
126
- if (n.replyToSeq === null) return j([...e, n]);
127
- const s = e.find((r) => r.seq === n.replyToSeq);
128
- return s ? Object.freeze(e.map((r) => r === s ? Object.freeze({ ...r, replies: j([...r.replies, n]) }) : r)) : e;
124
+ function U(e, s) {
125
+ if (h(e, (r) => r.seq === s.seq)) return K(e, s);
126
+ if (s.replyToSeq === null) return x([...e, s]);
127
+ const n = e.find((r) => r.seq === s.replyToSeq);
128
+ return n ? Object.freeze(e.map((r) => r === n ? Object.freeze({ ...r, replies: x([...r.replies, s]) }) : r)) : e;
129
129
  }
130
- const ye = (e) => e.replyToSeq === null && e.replies.length > 0, V = (e, n) => e.toLowerCase() === n.toLowerCase(), Ie = 256, X = /* @__PURE__ */ new WeakMap();
131
- function Oe() {
132
- let e = _;
133
- const n = /* @__PURE__ */ new Set(), s = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Set();
134
- let i = 0, p = -1;
135
- const b = () => {
136
- i += 1;
137
- for (const t of s.keys())
130
+ const Y = (e) => e.replyToSeq === null && e.replies.length > 0, G = (e, s) => e.toLowerCase() === s.toLowerCase(), W = (e) => e.author.kind === "member" && e.author.memberId !== null ? e.author.memberId.toLowerCase() : null, Oe = 256, Z = /* @__PURE__ */ new WeakMap();
131
+ function Ce() {
132
+ let e = V;
133
+ const s = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Set();
134
+ let c = 0, g = -1;
135
+ const m = /* @__PURE__ */ new Set(), z = () => {
136
+ c += 1, m.clear();
137
+ for (const t of n.keys())
138
138
  r.delete(t), r.add(t);
139
- s.clear();
139
+ n.clear();
140
140
  for (const t of r) {
141
- if (r.size <= Ie) break;
141
+ if (r.size <= Oe) break;
142
142
  r.delete(t);
143
143
  }
144
- }, g = (t) => {
144
+ }, y = (t) => {
145
145
  if (t !== e) {
146
146
  e = Object.freeze(t);
147
- for (const o of [...n])
147
+ for (const o of [...s])
148
148
  try {
149
149
  o(e);
150
150
  } catch {
151
151
  }
152
152
  }
153
153
  };
154
- function A(t, o = {}) {
155
- if (!O(t)) return;
156
- const a = u(t.articleId)?.toLowerCase() ?? null, c = e.articleId !== null && a !== null && a !== e.articleId, l = c ? _ : e;
157
- c && b();
158
- const y = typeof o.cursor == "number" && Number.isFinite(o.cursor) ? o.cursor : null, I = y ?? 0, q = typeof t.nextCursor == "number" && Number.isFinite(t.nextCursor) ? t.nextCursor : null, T = q ?? Number.POSITIVE_INFINITY, C = /* @__PURE__ */ new Map();
159
- for (const f of Array.isArray(t.messages) ? t.messages : []) {
160
- const d = L(f, !0);
161
- d && d.seq > I && d.seq <= T && C.set(d.seq, d);
154
+ function M(t, o = {}) {
155
+ if (!C(t)) return;
156
+ const u = f(t.articleId)?.toLowerCase() ?? null, l = e.articleId !== null && u !== null && u !== e.articleId, i = l ? V : e;
157
+ l && z();
158
+ const b = typeof o.cursor == "number" && Number.isFinite(o.cursor) ? o.cursor : null, I = b ?? 0, q = typeof t.nextCursor == "number" && Number.isFinite(t.nextCursor) ? t.nextCursor : null, k = q ?? Number.POSITIVE_INFINITY, j = /* @__PURE__ */ new Map();
159
+ for (const d of Array.isArray(t.messages) ? t.messages : []) {
160
+ const a = N(d, !0);
161
+ a && a.seq > I && a.seq <= k && j.set(a.seq, a);
162
162
  }
163
- const m = /* @__PURE__ */ new Map();
164
- for (const f of l.messages) {
165
- const d = [f, ...f.replies];
166
- for (const S of d) S.pending && S.pending !== "post" && S.clientMsgId && m.set(S.seq, S);
163
+ for (const d of j.values())
164
+ for (const a of [d, ...d.replies]) {
165
+ const S = W(a);
166
+ S === null || a.body === null || (a.collapsed ? m.add(S) : m.delete(S));
167
+ }
168
+ const p = /* @__PURE__ */ new Map();
169
+ for (const d of i.messages) {
170
+ const a = [d, ...d.replies];
171
+ for (const S of a) S.pending && S.pending !== "post" && S.clientMsgId && p.set(S.seq, S);
167
172
  }
168
- const x = (f) => {
169
- const d = m.get(f.seq);
170
- if (!d) return f;
171
- const S = d.clientMsgId ? s.get(d.clientMsgId) : void 0;
172
- return S && (S.before = f), d.replyToSeq === null ? Object.freeze({ ...d, replies: f.replies }) : d;
173
- }, k = l.messages.filter((f) => f.seq < 0 || f.seq <= I || f.seq > T), P = /* @__PURE__ */ new Map();
174
- for (const f of l.messages)
175
- for (const d of f.replies)
176
- d.seq < 0 && d.replyToSeq !== null && P.set(d.replyToSeq, [...P.get(d.replyToSeq) ?? [], d]);
177
- const re = [...k.filter((f) => !C.has(f.seq)), ...C.values()].map((f) => {
178
- if (!C.has(f.seq)) return f;
179
- const d = x(f), S = d.replies.map(x), K = P.get(f.seq) ?? [];
180
- return S.some((ie, le) => ie !== d.replies[le]) || K.length > 0 ? Object.freeze({ ...d, replies: j([...S, ...K]) }) : d;
181
- }), E = l.loaded ? l.nextCursor : 0, oe = E === null ? null : I > E ? E : q === null ? null : Math.max(E, q);
182
- g({
183
- articleId: a ?? l.articleId,
184
- conversationId: u(t.conversationId) ?? l.conversationId,
185
- count: typeof t.count == "number" && t.count >= 0 ? t.count : l.count,
186
- lastSeq: Math.max(typeof t.lastSeq == "number" ? t.lastSeq : 0, l.lastSeq),
187
- lastChangeAt: ge(l.lastChangeAt, u(t.lastChangeAt)),
188
- messages: j(re),
189
- nextCursor: oe,
190
- articleReactions: D(t.articleReactions),
191
- reactionSet: Object.freeze(Array.isArray(t.reactionSet) ? t.reactionSet.filter((f) => typeof f == "string") : []),
192
- preset: u(t.preset),
193
- viewer: fe(t.viewer),
173
+ const O = (d) => {
174
+ const a = p.get(d.seq);
175
+ if (!a) return d;
176
+ const S = a.clientMsgId ? n.get(a.clientMsgId) : void 0;
177
+ return S && (S.before = d), a.replyToSeq === null ? Object.freeze({ ...a, replies: d.replies }) : a;
178
+ }, v = i.messages.filter((d) => d.seq < 0 || d.seq <= I || d.seq > k), R = /* @__PURE__ */ new Map();
179
+ for (const d of i.messages)
180
+ for (const a of d.replies)
181
+ a.seq < 0 && a.replyToSeq !== null && R.set(a.replyToSeq, [...R.get(a.replyToSeq) ?? [], a]);
182
+ const A = [...v.filter((d) => !j.has(d.seq)), ...j.values()].map((d) => {
183
+ if (!j.has(d.seq)) return d;
184
+ const a = O(d), S = a.replies.map(O), H = R.get(d.seq) ?? [];
185
+ return S.some((fe, pe) => fe !== a.replies[pe]) || H.length > 0 ? Object.freeze({ ...a, replies: x([...S, ...H]) }) : a;
186
+ }), _ = i.loaded ? i.nextCursor : 0, de = _ === null ? null : I > _ ? _ : q === null ? null : Math.max(_, q);
187
+ y({
188
+ articleId: u ?? i.articleId,
189
+ conversationId: f(t.conversationId) ?? i.conversationId,
190
+ count: typeof t.count == "number" && t.count >= 0 ? t.count : i.count,
191
+ lastSeq: Math.max(typeof t.lastSeq == "number" ? t.lastSeq : 0, i.lastSeq),
192
+ lastChangeAt: Se(i.lastChangeAt, f(t.lastChangeAt)),
193
+ messages: x(A),
194
+ nextCursor: de,
195
+ articleReactions: L(t.articleReactions),
196
+ reactionSet: Object.freeze(Array.isArray(t.reactionSet) ? t.reactionSet.filter((d) => typeof d == "string") : []),
197
+ preset: f(t.preset),
198
+ viewer: Ie(t.viewer),
194
199
  loaded: !0,
195
- stale: y === null ? !1 : l.stale
200
+ stale: b === null ? !1 : i.stale
196
201
  });
197
202
  }
198
- function v(t) {
199
- if (s.has(t.clientMsgId)) return;
200
- const o = N(t.replyToSeq) ? t.replyToSeq : null;
201
- if (o !== null && !e.messages.some((y) => y.seq === o)) return;
202
- const a = Y(t.author) ?? U, c = Object.freeze({
203
+ function E(t) {
204
+ if (n.has(t.clientMsgId)) return;
205
+ const o = P(t.replyToSeq) ? t.replyToSeq : null;
206
+ if (o !== null && !e.messages.some((b) => b.seq === o)) return;
207
+ const u = J(t.author) ?? $, l = Object.freeze({
203
208
  conversationId: e.conversationId ?? "",
204
- seq: p--,
209
+ seq: g--,
205
210
  id: `pending:${t.clientMsgId}`,
206
211
  rev: 0,
207
212
  replyToSeq: o,
208
- author: a,
213
+ author: u,
209
214
  state: "visible",
210
215
  body: t.body,
211
216
  displayBody: t.body,
@@ -216,22 +221,22 @@ function Oe() {
216
221
  createdAt: t.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
217
222
  editedAt: null,
218
223
  collapsed: !1,
219
- reactions: R,
224
+ reactions: D,
220
225
  translationVersionId: null,
221
226
  replies: Object.freeze([]),
222
227
  pending: "post",
223
228
  clientMsgId: t.clientMsgId
224
229
  });
225
- s.set(t.clientMsgId, { type: "post", before: null });
226
- const l = o === null ? j([...e.messages, c]) : Object.freeze(e.messages.map((y) => y.seq === o ? Object.freeze({ ...y, replies: j([...y.replies, c]) }) : y));
227
- g({ ...e, messages: l });
230
+ n.set(t.clientMsgId, { type: "post", before: null });
231
+ const i = o === null ? x([...e.messages, l]) : Object.freeze(e.messages.map((b) => b.seq === o ? Object.freeze({ ...b, replies: x([...b.replies, l]) }) : b));
232
+ y({ ...e, messages: i });
228
233
  }
229
- function M(t) {
230
- if (s.has(t.clientMsgId)) return;
231
- const o = h(e.messages, (c) => c.seq === t.seq);
234
+ function te(t) {
235
+ if (n.has(t.clientMsgId)) return;
236
+ const o = h(e.messages, (l) => l.seq === t.seq);
232
237
  if (!o || o.pending) return;
233
- s.set(t.clientMsgId, { type: t.type, before: o });
234
- const a = t.type === "edit" ? Object.freeze({
238
+ n.set(t.clientMsgId, { type: t.type, before: o });
239
+ const u = t.type === "edit" ? Object.freeze({
235
240
  ...o,
236
241
  body: t.body,
237
242
  displayBody: t.body,
@@ -241,183 +246,233 @@ function Oe() {
241
246
  pending: "edit",
242
247
  clientMsgId: t.clientMsgId
243
248
  }) : Object.freeze({ ...o, pending: "delete", clientMsgId: t.clientMsgId });
244
- g({ ...e, messages: z(e.messages, (c) => c === o ? a : c) });
249
+ y({ ...e, messages: T(e.messages, (l) => l === o ? u : l) });
245
250
  }
246
- const J = (t) => e.conversationId === null || V(t.conversationId, e.conversationId);
247
- function Q(t) {
248
- const o = s.get(t.clientMsgId);
251
+ const F = (t) => e.conversationId === null || G(t.conversationId, e.conversationId);
252
+ function se(t) {
253
+ const o = n.get(t.clientMsgId);
249
254
  if (!o && r.has(t.clientMsgId)) return;
250
- s.delete(t.clientMsgId);
251
- const a = L(t.message, t.message?.replyToSeq === null || t.message?.replyToSeq === void 0), c = a && J(a) ? a : null, l = z(
255
+ n.delete(t.clientMsgId);
256
+ const u = N(t.message, t.message?.replyToSeq === null || t.message?.replyToSeq === void 0), l = u && F(u) ? u : null, i = T(
252
257
  e.messages,
253
- (m) => m.clientMsgId === t.clientMsgId && m.pending === "post" ? null : m.clientMsgId === t.clientMsgId ? B(m) : m
258
+ (p) => p.clientMsgId === t.clientMsgId && p.pending === "post" ? null : p.clientMsgId === t.clientMsgId ? X(p) : p
254
259
  );
255
- if (!c) {
256
- l !== e.messages && g({ ...e, messages: l });
260
+ if (!l) {
261
+ i !== e.messages && y({ ...e, messages: i });
257
262
  return;
258
263
  }
259
- const y = t.warnings ? G(t.warnings) : void 0, I = y && y.length > 0 ? Object.freeze({ ...c, warnings: y }) : c, q = h(l, (m) => m.seq === I.seq);
260
- let T, C = e.count;
264
+ const b = t.warnings ? Q(t.warnings) : void 0, I = b && b.length > 0 ? Object.freeze({ ...l, warnings: b }) : l, q = h(i, (p) => p.seq === I.seq);
265
+ let k, j = e.count;
261
266
  if (I.state === "deleted" || o?.type === "delete") {
262
- const m = q ?? null, x = m?.state === "visible" && m.body !== null;
263
- T = z(
264
- l,
265
- (k) => k.seq !== I.seq ? k : ye(k) ? Object.freeze({ ...I, replies: k.replies }) : null
266
- ), x && (C = Math.max(0, C - 1));
267
+ const p = q ?? null, O = p?.state === "visible" && p.body !== null;
268
+ k = T(
269
+ i,
270
+ (v) => v.seq !== I.seq ? v : Y(v) ? Object.freeze({ ...I, replies: v.replies }) : null
271
+ ), O && (j = Math.max(0, j - 1));
267
272
  } else
268
- T = be(l, I), !q && I.state === "visible" && (C += 1);
269
- g({
273
+ k = U(i, I), !q && I.state === "visible" && (j += 1);
274
+ y({
270
275
  ...e,
271
276
  // The answer to this store's own change names the new conversation; a row it never saw may be another article's.
272
277
  conversationId: e.conversationId ?? (o ? I.conversationId : null),
273
278
  lastSeq: Math.max(e.lastSeq, I.seq),
274
- count: C,
275
- messages: T
279
+ count: j,
280
+ messages: k
276
281
  });
277
282
  }
278
- function Z(t) {
279
- const o = s.get(t);
283
+ function ne(t) {
284
+ const o = n.get(t);
280
285
  if (!o) return;
281
- s.delete(t);
282
- const a = z(e.messages, (c) => {
283
- if (c.clientMsgId !== t) return c;
286
+ n.delete(t);
287
+ const u = T(e.messages, (l) => {
288
+ if (l.clientMsgId !== t) return l;
284
289
  if (o.type === "post") return null;
285
- const l = o.before;
286
- return l ? c.replyToSeq === null ? Object.freeze({ ...l, replies: c.replies }) : l : B(c);
290
+ const i = o.before;
291
+ return i ? l.replyToSeq === null ? Object.freeze({ ...i, replies: l.replies }) : i : X(l);
287
292
  });
288
- a !== e.messages && g({ ...e, messages: a });
293
+ u !== e.messages && y({ ...e, messages: u });
289
294
  }
290
- function w(t) {
291
- const o = L(t, t?.replyToSeq === null || t?.replyToSeq === void 0);
292
- !o || !h(e.messages, (a) => a.seq === o.seq && !a.pending && V(a.conversationId, o.conversationId)) || g({ ...e, messages: W(e.messages, o) });
295
+ function re(t) {
296
+ const o = N(t, t?.replyToSeq === null || t?.replyToSeq === void 0);
297
+ !o || !h(e.messages, (u) => u.seq === o.seq && !u.pending && G(u.conversationId, o.conversationId)) || y({ ...e, messages: K(e.messages, o) });
293
298
  }
294
- function ee(t) {
295
- if (O(t))
299
+ function oe(t) {
300
+ if (C(t))
296
301
  switch (t.type) {
297
302
  case "post":
298
- return v(t);
303
+ return E(t);
299
304
  case "edit":
300
305
  case "delete":
301
- return M(t);
306
+ return te(t);
302
307
  case "confirm":
303
- return Q(t);
308
+ return se(t);
304
309
  case "rollback":
305
- return Z(t.clientMsgId);
310
+ return ne(t.clientMsgId);
306
311
  case "server":
307
- return w(t.message);
312
+ return re(t.message);
308
313
  }
309
314
  }
310
- function te(t) {
311
- if (!O(t) || !e.loaded || e.articleId === null || u(t.articleId)?.toLowerCase() !== e.articleId) return !1;
315
+ function ie(t) {
316
+ if (!C(t) || !e.loaded || e.articleId === null || f(t.articleId)?.toLowerCase() !== e.articleId) return !1;
312
317
  if (e.stale) return !0;
313
- const o = typeof t.lastSeq == "number" && t.lastSeq > e.lastSeq, a = typeof t.count == "number" && t.count !== e.count, c = u(t.lastChangeAt), l = c !== null && (e.lastChangeAt === null || Date.parse(c) > Date.parse(e.lastChangeAt));
314
- return !o && !a && !l ? !1 : (g({ ...e, stale: !0 }), !0);
318
+ const o = typeof t.lastSeq == "number" && t.lastSeq > e.lastSeq, u = typeof t.count == "number" && t.count !== e.count, l = f(t.lastChangeAt), i = l !== null && (e.lastChangeAt === null || Date.parse(l) > Date.parse(e.lastChangeAt));
319
+ return !o && !u && !i ? !1 : (y({ ...e, stale: !0 }), !0);
315
320
  }
316
- function ne(t, o) {
317
- if (!O(t)) return;
318
- const a = D(o);
321
+ function le(t, o) {
322
+ if (!C(t)) return;
323
+ const u = L(o);
319
324
  if ("articleId" in t) {
320
- if (u(t.articleId)?.toLowerCase() !== e.articleId) return;
321
- g({ ...e, articleReactions: a });
325
+ if (f(t.articleId)?.toLowerCase() !== e.articleId) return;
326
+ y({ ...e, articleReactions: u });
322
327
  return;
323
328
  }
324
- const { conversationId: c, seq: l } = t;
325
- if (!N(l) || typeof c != "string") return;
326
- const y = c.toLowerCase(), I = z(e.messages, (q) => q.seq === l && q.conversationId.toLowerCase() === y ? Object.freeze({ ...q, reactions: a }) : q);
327
- I !== e.messages && g({ ...e, messages: I });
329
+ const { conversationId: l, seq: i } = t;
330
+ if (!P(i) || typeof l != "string") return;
331
+ const b = l.toLowerCase(), I = T(e.messages, (q) => q.seq === i && q.conversationId.toLowerCase() === b ? Object.freeze({ ...q, reactions: u }) : q);
332
+ I !== e.messages && y({ ...e, messages: I });
328
333
  }
329
- function se(t, o) {
334
+ function ce(t, o) {
330
335
  if (typeof t != "string" || t === "") return;
331
- const a = t.toLowerCase(), c = z(
336
+ const u = t.toLowerCase();
337
+ o ? m.add(u) : m.delete(u);
338
+ const l = T(
332
339
  e.messages,
333
- (l) => l.author.kind === "member" && l.author.memberId !== null && l.author.memberId.toLowerCase() === a && l.body !== null && l.collapsed !== o ? Object.freeze({ ...l, collapsed: o }) : l
340
+ (i) => i.author.kind === "member" && i.author.memberId !== null && i.author.memberId.toLowerCase() === u && i.body !== null && i.collapsed !== o ? Object.freeze({ ...i, collapsed: o }) : i
334
341
  );
335
- c !== e.messages && g({ ...e, messages: c });
342
+ l !== e.messages && y({ ...e, messages: l });
343
+ }
344
+ function ue(t, o) {
345
+ const u = W(t), l = t.body !== null && u !== null && m.has(u), i = o ? o.reactions.mine : null, b = i === t.reactions.mine ? t.reactions : Object.freeze({ counts: t.reactions.counts, mine: i }), I = o?.repliesTruncated === !0 && t.replyToSeq === null, q = o?.warnings;
346
+ return l === t.collapsed && b === t.reactions && !I && !q ? t : Object.freeze({
347
+ ...t,
348
+ collapsed: l,
349
+ reactions: b,
350
+ ...I ? { repliesTruncated: !0 } : {},
351
+ ...q ? { warnings: q } : {}
352
+ });
353
+ }
354
+ function ae(t) {
355
+ if (!C(t) || !e.loaded) return "dropped";
356
+ const o = typeof t.rev == "number" && Number.isSafeInteger(t.rev) && t.rev >= 0 ? t.rev : null;
357
+ if (t.kind === "resync") return "resync";
358
+ if (o === null) return "dropped";
359
+ if (t.kind === "reaction") {
360
+ if (t.seq === void 0) {
361
+ const A = L(t.reactions);
362
+ return y({ ...e, articleReactions: Object.freeze({ counts: A.counts, mine: e.articleReactions.mine }) }), "applied";
363
+ }
364
+ if (!P(t.seq)) return "dropped";
365
+ const p = t.seq, O = h(e.messages, (A) => A.seq === p);
366
+ if (!O || O.pending || o < O.rev) return "dropped";
367
+ if (o > O.rev) return "resync";
368
+ const v = L(t.reactions), R = Object.freeze({ counts: v.counts, mine: O.reactions.mine });
369
+ return y({ ...e, messages: T(e.messages, (A) => A === O ? Object.freeze({ ...A, reactions: R }) : A) }), "applied";
370
+ }
371
+ if (t.kind !== "message" && t.kind !== "edit" && t.kind !== "delete") return "dropped";
372
+ const u = t.message, l = N(u, u?.replyToSeq === null || u?.replyToSeq === void 0);
373
+ if (!l || !F(l)) return "dropped";
374
+ const i = h(e.messages, (p) => p.seq === l.seq);
375
+ if (i?.pending) return "dropped";
376
+ const b = i?.rev ?? 0;
377
+ if (t.kind === "delete") {
378
+ if (!i || o <= b) return "dropped";
379
+ const p = i.state === "visible" && i.body !== null, O = T(
380
+ e.messages,
381
+ (v) => v.seq !== l.seq ? v : Y(v) ? Object.freeze({ ...l, replies: v.replies }) : null
382
+ );
383
+ return y({ ...e, messages: O, count: p ? Math.max(0, e.count - 1) : e.count, lastSeq: Math.max(e.lastSeq, l.seq) }), "applied";
384
+ }
385
+ const I = l.author.kind === "member" && l.author.memberId !== null && l.author.memberId === e.viewer.memberId;
386
+ if (!i && I && [...n.values()].some((p) => p.type === "post") || o <= b) return "dropped";
387
+ if (o > b + 1 || !i && l.replyToSeq !== null && !e.messages.some((p) => p.seq === l.replyToSeq)) return "resync";
388
+ const q = ue(l, i), k = i ? K(e.messages, q) : U(e.messages, q), j = !i && l.state === "visible" ? e.count + 1 : e.count;
389
+ return y({ ...e, messages: k, count: j, lastSeq: Math.max(e.lastSeq, l.seq) }), "applied";
336
390
  }
337
- const F = {
391
+ const B = {
338
392
  getState: () => e,
339
393
  subscribe(t) {
340
- return n.add(t), () => {
341
- n.delete(t);
394
+ return s.add(t), () => {
395
+ s.delete(t);
342
396
  };
343
397
  },
344
- applyPage: A,
345
- applyMessage: ee,
346
- applyHead: te,
347
- applyReaction: ne,
348
- collapse: se,
398
+ applyPage: M,
399
+ applyMessage: oe,
400
+ applyHead: ie,
401
+ applyReaction: le,
402
+ collapse: ce,
403
+ applyEvent: ae,
349
404
  reset() {
350
- b(), g(_);
405
+ z(), y(V);
351
406
  }
352
407
  };
353
- return X.set(F, () => i), F;
408
+ return Z.set(B, () => c), B;
354
409
  }
355
- function B(e) {
356
- const { pending: n, clientMsgId: s, ...r } = e;
410
+ function X(e) {
411
+ const { pending: s, clientMsgId: n, ...r } = e;
357
412
  return Object.freeze(r);
358
413
  }
359
- function ve(e) {
360
- const n = "viewer" in e ? e.viewer.needs : e.needs, s = new Set(n.filter(H)), r = s.has("sign_in"), i = s.has("onboarding"), p = i || s.has("reconsent_rules"), b = s.has("art9_consent");
361
- return Object.freeze({ signIn: r, onboarding: i, rules: p, art9: b, any: r || i || p || b });
414
+ function Te(e) {
415
+ const s = "viewer" in e ? e.viewer.needs : e.needs, n = new Set(s.filter(w)), r = n.has("sign_in"), c = n.has("onboarding"), g = c || n.has("reconsent_rules"), m = n.has("art9_consent");
416
+ return Object.freeze({ signIn: r, onboarding: c, rules: g, art9: m, any: r || c || g || m });
362
417
  }
363
- function Ce(e, n) {
364
- return h(e.messages, (s) => s.seq === n);
418
+ function Me(e, s) {
419
+ return h(e.messages, (n) => n.seq === s);
365
420
  }
366
- function ze(e, n) {
367
- return n.author.kind === "member" && n.author.memberId !== null && n.author.memberId === e.viewer.memberId;
421
+ function Ae(e, s) {
422
+ return s.author.kind === "member" && s.author.memberId !== null && s.author.memberId === e.viewer.memberId;
368
423
  }
369
- function je(e, n) {
370
- if ("articleId" in n) return e.articleReactions;
371
- const s = n.conversationId.toLowerCase();
372
- return h(e.messages, (i) => i.seq === n.seq && i.conversationId.toLowerCase() === s)?.reactions ?? R;
424
+ function ke(e, s) {
425
+ if ("articleId" in s) return e.articleReactions;
426
+ const n = s.conversationId.toLowerCase();
427
+ return h(e.messages, (c) => c.seq === s.seq && c.conversationId.toLowerCase() === n)?.reactions ?? D;
373
428
  }
374
- function Ae(e, n) {
375
- const s = { ...e.counts }, r = e.mine;
429
+ function he(e, s) {
430
+ const n = { ...e.counts }, r = e.mine;
376
431
  if (r !== null) {
377
- const i = (s[r] ?? 0) - 1;
378
- i > 0 ? s[r] = i : delete s[r];
432
+ const c = (n[r] ?? 0) - 1;
433
+ c > 0 ? n[r] = c : delete n[r];
379
434
  }
380
- return n !== null && (s[n] = (s[n] ?? 0) + 1), Object.freeze({ counts: Object.freeze(s), mine: n });
435
+ return s !== null && (n[s] = (n[s] ?? 0) + 1), Object.freeze({ counts: Object.freeze(n), mine: s });
381
436
  }
382
- const me = 20;
383
- function $(e) {
384
- const n = X.get(e);
385
- let s = n?.(), r = e.getState().articleId;
437
+ const ve = 20;
438
+ function ee(e) {
439
+ const s = Z.get(e);
440
+ let n = s?.(), r = e.getState().articleId;
386
441
  return {
387
- moved: () => n !== void 0 && n() !== s || e.getState().articleId !== r,
442
+ moved: () => s !== void 0 && s() !== n || e.getState().articleId !== r,
388
443
  mark() {
389
- s = n?.(), r = e.getState().articleId;
444
+ n = s?.(), r = e.getState().articleId;
390
445
  }
391
446
  };
392
447
  }
393
- const qe = (e) => typeof e == "number" && Number.isFinite(e) ? e : null;
394
- async function Me(e, n, s, r) {
395
- const i = e.getState(), p = i.loaded ? i.nextCursor : 0, b = $(e);
396
- let g = null;
397
- for (let A = 0; A < me; A++) {
398
- const v = await n.discussions.list({ articleId: s.articleId, languageCode: s.languageCode ?? null, cursor: g }, r);
399
- if (!v.ok) return v;
400
- if (b.moved()) break;
401
- e.applyPage(v.value, { cursor: g }), b.mark();
402
- const M = qe(v.value.nextCursor);
403
- if (M === null || p !== null && M >= p || g !== null && M <= g) break;
404
- g = M;
448
+ const ze = (e) => typeof e == "number" && Number.isFinite(e) ? e : null;
449
+ async function xe(e, s, n, r) {
450
+ const c = e.getState(), g = c.loaded ? c.nextCursor : 0, m = ee(e);
451
+ let z = null;
452
+ for (let y = 0; y < ve; y++) {
453
+ const M = await s.discussions.list({ articleId: n.articleId, languageCode: n.languageCode ?? null, cursor: z }, r);
454
+ if (!M.ok) return M;
455
+ if (m.moved()) break;
456
+ e.applyPage(M.value, { cursor: z }), m.mark();
457
+ const E = ze(M.value.nextCursor);
458
+ if (E === null || g !== null && E >= g || z !== null && E <= z) break;
459
+ z = E;
405
460
  }
406
461
  return { ok: !0, value: e.getState() };
407
462
  }
408
- async function Te(e, n, s, r) {
409
- const i = e.getState().nextCursor;
410
- if (i === null) return { ok: !0, value: e.getState() };
411
- const p = $(e), b = await n.discussions.list({ articleId: s.articleId, languageCode: s.languageCode ?? null, cursor: i }, r);
412
- return b.ok ? (p.moved() || e.applyPage(b.value, { cursor: i }), { ok: !0, value: e.getState() }) : b;
463
+ async function Ee(e, s, n, r) {
464
+ const c = e.getState().nextCursor;
465
+ if (c === null) return { ok: !0, value: e.getState() };
466
+ const g = ee(e), m = await s.discussions.list({ articleId: n.articleId, languageCode: n.languageCode ?? null, cursor: c }, r);
467
+ return m.ok ? (g.moved() || e.applyPage(m.value, { cursor: c }), { ok: !0, value: e.getState() }) : m;
413
468
  }
414
469
  export {
415
- Oe as createDiscussionStore,
416
- Ce as findMessage,
417
- ze as isOwnMessage,
418
- Te as loadMoreDiscussion,
419
- Ae as reactionAfter,
420
- je as reactionsFor,
421
- Me as refreshDiscussion,
422
- ve as viewerNeeds
470
+ Ce as createDiscussionStore,
471
+ Me as findMessage,
472
+ Ae as isOwnMessage,
473
+ Ee as loadMoreDiscussion,
474
+ he as reactionAfter,
475
+ ke as reactionsFor,
476
+ xe as refreshDiscussion,
477
+ Te as viewerNeeds
423
478
  };