@vielzeug/archive 26.11.11 → 26.11.13

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 (90) hide show
  1. package/dist/_server/d1.d.ts +23 -0
  2. package/dist/_server/d1.d.ts.map +1 -0
  3. package/dist/_server/execution.d.ts +5 -0
  4. package/dist/_server/execution.d.ts.map +1 -0
  5. package/dist/_server/http.cjs +2 -0
  6. package/dist/_server/http.cjs.map +1 -0
  7. package/dist/{worker → _server}/http.d.ts +6 -11
  8. package/dist/_server/http.d.ts.map +1 -0
  9. package/dist/{worker → _server}/http.js +18 -44
  10. package/dist/_server/http.js.map +1 -0
  11. package/dist/{worker/_service.cjs → _server/service.cjs} +1 -1
  12. package/dist/{worker/_service.js.map → _server/service.cjs.map} +1 -1
  13. package/dist/{worker/_service.d.ts → _server/service.d.ts} +1 -1
  14. package/dist/_server/service.d.ts.map +1 -0
  15. package/dist/{worker/_service.js → _server/service.js} +2 -2
  16. package/dist/_server/service.js.map +1 -0
  17. package/dist/_server/uuid.cjs +2 -0
  18. package/dist/_server/uuid.cjs.map +1 -0
  19. package/dist/_server/uuid.d.ts +3 -0
  20. package/dist/_server/uuid.d.ts.map +1 -0
  21. package/dist/_server/uuid.js +5 -0
  22. package/dist/_server/uuid.js.map +1 -0
  23. package/dist/auth/_confirmation.cjs +3 -3
  24. package/dist/auth/_confirmation.cjs.map +1 -1
  25. package/dist/auth/_confirmation.js +4 -4
  26. package/dist/auth/_confirmation.js.map +1 -1
  27. package/dist/auth/config.cjs.map +1 -1
  28. package/dist/auth/config.d.ts +1 -1
  29. package/dist/auth/config.js.map +1 -1
  30. package/dist/auth/errors.cjs +1 -1
  31. package/dist/auth/errors.cjs.map +1 -1
  32. package/dist/auth/errors.d.ts +1 -1
  33. package/dist/auth/errors.d.ts.map +1 -1
  34. package/dist/auth/errors.js +1 -1
  35. package/dist/auth/errors.js.map +1 -1
  36. package/dist/auth/store.cjs.map +1 -1
  37. package/dist/auth/store.d.ts +1 -1
  38. package/dist/auth/store.js.map +1 -1
  39. package/dist/auth/worker.cjs +1 -1
  40. package/dist/auth/worker.cjs.map +1 -1
  41. package/dist/auth/worker.d.ts +1 -1
  42. package/dist/auth/worker.d.ts.map +1 -1
  43. package/dist/auth/worker.js +153 -152
  44. package/dist/auth/worker.js.map +1 -1
  45. package/dist/errors.cjs +1 -1
  46. package/dist/errors.cjs.map +1 -1
  47. package/dist/errors.d.ts.map +1 -1
  48. package/dist/errors.js +1 -1
  49. package/dist/errors.js.map +1 -1
  50. package/dist/worker/_cors.cjs +2 -0
  51. package/dist/worker/_cors.cjs.map +1 -0
  52. package/dist/worker/_cors.d.ts +13 -0
  53. package/dist/worker/_cors.d.ts.map +1 -0
  54. package/dist/worker/_cors.js +32 -0
  55. package/dist/worker/_cors.js.map +1 -0
  56. package/dist/worker/_pagination.cjs +1 -1
  57. package/dist/worker/_pagination.cjs.map +1 -1
  58. package/dist/worker/_pagination.js +18 -18
  59. package/dist/worker/_pagination.js.map +1 -1
  60. package/dist/worker/auth.cjs +1 -1
  61. package/dist/worker/auth.cjs.map +1 -1
  62. package/dist/worker/auth.d.ts.map +1 -1
  63. package/dist/worker/auth.js +18 -18
  64. package/dist/worker/auth.js.map +1 -1
  65. package/dist/worker/env.cjs +1 -1
  66. package/dist/worker/env.cjs.map +1 -1
  67. package/dist/worker/env.d.ts +1 -22
  68. package/dist/worker/env.d.ts.map +1 -1
  69. package/dist/worker/env.js +1 -1
  70. package/dist/worker/env.js.map +1 -1
  71. package/dist/worker/publications.cjs +1 -1
  72. package/dist/worker/publications.cjs.map +1 -1
  73. package/dist/worker/publications.d.ts.map +1 -1
  74. package/dist/worker/publications.js +263 -262
  75. package/dist/worker/publications.js.map +1 -1
  76. package/dist/worker/worker.cjs +1 -1
  77. package/dist/worker/worker.cjs.map +1 -1
  78. package/dist/worker/worker.d.ts +2 -4
  79. package/dist/worker/worker.d.ts.map +1 -1
  80. package/dist/worker/worker.js +124 -122
  81. package/dist/worker/worker.js.map +1 -1
  82. package/dist/worker.d.ts +5 -3
  83. package/dist/worker.d.ts.map +1 -1
  84. package/package.json +2 -2
  85. package/dist/worker/_service.cjs.map +0 -1
  86. package/dist/worker/_service.d.ts.map +0 -1
  87. package/dist/worker/http.cjs +0 -2
  88. package/dist/worker/http.cjs.map +0 -1
  89. package/dist/worker/http.d.ts.map +0 -1
  90. package/dist/worker/http.js.map +0 -1
@@ -1,15 +1,16 @@
1
- import { ARCHIVE_LIMITS as e, SESSION_MAX_AGE_SECONDS as t, archiveAliasSchema as n, archiveCollectionMetaSchema as r, archiveHealthSchema as i, archiveIdentitySchema as a, archiveLikeStateSchema as o, archiveLikedIdsSchema as s, archiveLikesPageSchema as c, archiveModerationLogSchema as l, archiveOwnReportsSchema as u, archiveReportsSchema as d, archiveSortSchema as f, isWellFormedText as p, uuidSchema as m } from "../contract.js";
2
- import { forwardPage as h, forwardPageParams as g, nextCursor as _ } from "./_pagination.js";
3
- import { ApiError as v, badRequest as y, conflict as b, forbidden as x, invalid as S, json as C, noStore as w, notFound as T, queryParams as E, readJsonBody as D } from "./http.js";
4
- import { SQL as O, likedPublicationsSql as k, likesPageSql as A, listPublicationsSql as j, moderationLogSql as M, reportsPageSql as N } from "./sql.js";
5
- import { s as P } from "@vielzeug/spell";
1
+ import { ApiError as e, badRequest as t, conflict as n, forbidden as r, invalid as i, json as a, noStore as o, notFound as s, queryParams as c, readJsonBody as l } from "../_server/http.js";
2
+ import { UUID_RE as u } from "../_server/uuid.js";
3
+ import { ARCHIVE_LIMITS as d, SESSION_MAX_AGE_SECONDS as f, archiveAliasSchema as p, archiveCollectionMetaSchema as m, archiveHealthSchema as h, archiveIdentitySchema as g, archiveLikeStateSchema as _, archiveLikedIdsSchema as v, archiveLikesPageSchema as y, archiveModerationLogSchema as b, archiveOwnReportsSchema as x, archiveReportsSchema as S, archiveSortSchema as C, isWellFormedText as w, uuidSchema as T } from "../contract.js";
4
+ import { forwardPage as E, forwardPageParams as D, nextCursor as O } from "./_pagination.js";
5
+ import { SQL as k, likedPublicationsSql as A, likesPageSql as j, listPublicationsSql as M, moderationLogSql as N, reportsPageSql as P } from "./sql.js";
6
+ import { s as F } from "@vielzeug/spell";
6
7
  // src/worker/publications.ts
7
- async function databaseCall(e) {
8
+ async function databaseCall(t) {
8
9
  try {
9
- return await e();
10
- } catch (e) {
11
- throw new v(500, "internal", "The service is not available.", {
12
- cause: e,
10
+ return await t();
11
+ } catch (t) {
12
+ throw new e(500, "internal", "The service is not available.", {
13
+ cause: t,
13
14
  diagnostic: { kind: "database" }
14
15
  });
15
16
  }
@@ -18,7 +19,7 @@ var first = (e, t, ...n) => databaseCall(() => e.DB.prepare(t).bind(...n).first(
18
19
  let r = await e.DB.prepare(t).bind(...n).all();
19
20
  if (!Array.isArray(r.results)) throw Error("Missing database query results");
20
21
  return r.results;
21
- }), run = (e, t, ...n) => databaseCall(() => e.DB.prepare(t).bind(...n).run()), uuid = () => crypto.randomUUID(), now = () => (/* @__PURE__ */ new Date()).toISOString(), recordUnavailable = () => new v(503, "record-unavailable", "The record is not available.", { diagnostic: { kind: "record" } }), F = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i, rowToEntry = (e, t) => {
22
+ }), run = (e, t, ...n) => databaseCall(() => e.DB.prepare(t).bind(...n).run()), uuid = () => crypto.randomUUID(), now = () => (/* @__PURE__ */ new Date()).toISOString(), recordUnavailable = () => new e(503, "record-unavailable", "The record is not available.", { diagnostic: { kind: "record" } }), rowToEntry = (e, t) => {
22
23
  let n;
23
24
  try {
24
25
  n = JSON.parse(t.payload_json);
@@ -44,19 +45,19 @@ var first = (e, t, ...n) => databaseCall(() => e.DB.prepare(t).bind(...n).first(
44
45
  return r.data;
45
46
  }, rowToOwnedEntry = (e, t) => {
46
47
  let n = rowToEntry(e, t);
47
- if (!m.safeParse(t.client_key).success) throw recordUnavailable();
48
+ if (!T.safeParse(t.client_key).success) throw recordUnavailable();
48
49
  return {
49
50
  ...n,
50
51
  clientKey: t.client_key,
51
52
  hidden: t.hidden_at !== null
52
53
  };
53
54
  }, entryById = async (e, t, n) => {
54
- let r = await first(t, O.publication, n, e.name);
55
+ let r = await first(t, k.publication, n, e.name);
55
56
  return r === null ? null : rowToEntry(e, r);
56
- }, searchMatchFor = (t) => {
57
- if (t === null) return;
58
- if (t.length > e.searchChars) throw y();
59
- let n = (t.match(/[\p{L}\p{N}]+/gu) ?? []).slice(0, e.searchTerms);
57
+ }, searchMatchFor = (e) => {
58
+ if (e === null) return;
59
+ if (e.length > d.searchChars) throw t();
60
+ let n = (e.match(/[\p{L}\p{N}]+/gu) ?? []).slice(0, d.searchTerms);
60
61
  if (n.length !== 0) return n.map((e) => `"${e}"*`).join(" ");
61
62
  }, entryCursorContext = (e) => JSON.stringify([
62
63
  e.collection,
@@ -69,15 +70,15 @@ var first = (e, t, ...n) => databaseCall(() => e.DB.prepare(t).bind(...n).first(
69
70
  createdAt: e.published_at,
70
71
  id: e.id,
71
72
  likeCount: e.like_count
72
- }), I = 16, vocabValues = (e, t, n) => {
73
- let r = e.getAll(t);
74
- if (r.length > I) throw y();
75
- let i = [...new Set(r)].sort();
76
- if (i.some((e) => !n.includes(e))) throw y();
77
- return i;
73
+ }), I = 16, vocabValues = (e, n, r) => {
74
+ let i = e.getAll(n);
75
+ if (i.length > I) throw t();
76
+ let a = [...new Set(i)].sort();
77
+ if (a.some((e) => !r.includes(e))) throw t();
78
+ return a;
78
79
  };
79
- async function listEntries(e, t, n) {
80
- let r = new URL(t.url), i = E(r, [
80
+ async function listEntries(e, n, r) {
81
+ let i = new URL(n.url), s = c(i, [
81
82
  "author",
82
83
  "cursor",
83
84
  "filter",
@@ -85,76 +86,76 @@ async function listEntries(e, t, n) {
85
86
  "search",
86
87
  "sort",
87
88
  "tag"
88
- ], ["filter", "tag"]), a = i.get("sort") ?? "recent", o = f.safeParse(a);
89
- if (!o.success) throw y();
90
- let s = vocabValues(i, "filter", e.filters), c = vocabValues(i, "tag", e.tags), l = i.get("author");
91
- if (l !== null && !F.test(l)) throw y();
92
- let u = searchMatchFor(i.get("search")), d = entryCursorContext({
93
- author: l ?? void 0,
89
+ ], ["filter", "tag"]), l = s.get("sort") ?? "recent", d = C.safeParse(l);
90
+ if (!d.success) throw t();
91
+ let f = vocabValues(s, "filter", e.filters), p = vocabValues(s, "tag", e.tags), m = s.get("author");
92
+ if (m !== null && !u.test(m)) throw t();
93
+ let h = searchMatchFor(s.get("search")), g = entryCursorContext({
94
+ author: m ?? void 0,
94
95
  collection: e.name,
95
- filters: s,
96
- searchMatch: u,
97
- sort: o.data,
98
- tags: c
99
- }), { cursor: p, limit: m } = g(i, d), h = {
100
- author: l ?? void 0,
96
+ filters: f,
97
+ searchMatch: h,
98
+ sort: d.data,
99
+ tags: p
100
+ }), { cursor: _, limit: v } = D(s, g), y = {
101
+ author: m ?? void 0,
101
102
  collection: e.name,
102
- cursor: p === null ? void 0 : {
103
- createdAt: p.createdAt,
104
- id: p.id,
105
- likeCount: p.likeCount ?? 0
103
+ cursor: _ === null ? void 0 : {
104
+ createdAt: _.createdAt,
105
+ id: _.id,
106
+ likeCount: _.likeCount ?? 0
106
107
  },
107
- filters: s,
108
- limit: m + 1,
109
- searchMatch: u,
110
- sort: o.data,
111
- tags: c
112
- }, v = j(h), b = await all(n, v.sql, ...v.parameters), x = b.slice(0, m), S = x.at(-1), T = {
113
- cursor: b.length > m && S !== void 0 ? _(cursorFromRow(S), d) : null,
114
- entries: x.map((t) => rowToEntry(e, t))
108
+ filters: f,
109
+ limit: v + 1,
110
+ searchMatch: h,
111
+ sort: d.data,
112
+ tags: p
113
+ }, b = M(y), x = await all(r, b.sql, ...b.parameters), S = x.slice(0, v), w = S.at(-1), T = {
114
+ cursor: x.length > v && w !== void 0 ? O(cursorFromRow(w), g) : null,
115
+ entries: S.map((t) => rowToEntry(e, t))
115
116
  };
116
- return C(200, T, w);
117
+ return a(200, T, o);
117
118
  }
118
119
  function collectionMeta(e) {
119
- let t = r.safeParse({
120
+ let t = m.safeParse({
120
121
  filters: [...e.filters].sort(),
121
122
  name: e.name,
122
123
  tags: [...e.tags].sort()
123
124
  });
124
125
  if (!t.success) throw recordUnavailable();
125
- return C(200, t.data, w);
126
+ return a(200, t.data, o);
126
127
  }
127
128
  async function getEntry(e, t, n) {
128
129
  let r = await entryById(e, t, n);
129
- if (r === null) throw T();
130
- return C(200, r, w);
130
+ if (r === null) throw s();
131
+ return a(200, r, o);
131
132
  }
132
- async function healthJson(t, n) {
133
- let r = null, a = null;
133
+ async function healthJson(e, t) {
134
+ let n = null, r = null;
134
135
  try {
135
- r = (await first(n, O.schemaVersion))?.applied ?? 0;
136
+ n = (await first(t, k.schemaVersion))?.applied ?? 0;
136
137
  } catch {
137
- a = "database-unavailable";
138
+ r = "database-unavailable";
138
139
  }
139
- a === null && r !== 1 && (a = "schema-mismatch");
140
- let o = i.safeParse({
141
- dbSchemaVersion: r,
140
+ r === null && n !== 1 && (r = "schema-mismatch");
141
+ let i = h.safeParse({
142
+ dbSchemaVersion: n,
142
143
  features: {
143
- likes: t.likesEnabled,
144
- publishing: t.publishingEnabled
144
+ likes: e.likesEnabled,
145
+ publishing: e.publishingEnabled
145
146
  },
146
- limits: e,
147
- reason: a,
147
+ limits: d,
148
+ reason: r,
148
149
  schemaVersion: 1,
149
- status: a === null ? "ok" : "degraded"
150
+ status: r === null ? "ok" : "degraded"
150
151
  });
151
- if (!o.success) throw recordUnavailable();
152
- return C(a === null ? 200 : 503, o.data, w);
152
+ if (!i.success) throw recordUnavailable();
153
+ return a(r === null ? 200 : 503, i.data, o);
153
154
  }
154
155
  var identityJson = (e, t) => {
155
- let n = a.safeParse(t);
156
+ let n = g.safeParse(t);
156
157
  if (!n.success) throw recordUnavailable();
157
- return C(e, n.data, w);
158
+ return a(e, n.data, o);
158
159
  };
159
160
  function getMe(e) {
160
161
  return identityJson(200, e?.publisher ? {
@@ -163,61 +164,61 @@ function getMe(e) {
163
164
  operator: e.operator
164
165
  } : null);
165
166
  }
166
- async function registerMe(e, t, n) {
167
- let r = await D(e), i = L.safeParse(r);
168
- if (!i.success) throw S();
169
- let a = i.data.name ?? "", o = await first(t, O.publisher, n.subject.issuer, n.subject.subject);
170
- if (o !== null) return identityJson(200, {
171
- id: o.id,
172
- name: o.display_name,
173
- operator: n.operator
167
+ async function registerMe(t, r, a) {
168
+ let o = await l(t), s = L.safeParse(o);
169
+ if (!s.success) throw i();
170
+ let c = s.data.name ?? "", u = await first(r, k.publisher, a.subject.issuer, a.subject.subject);
171
+ if (u !== null) return identityJson(200, {
172
+ id: u.id,
173
+ name: u.display_name,
174
+ operator: a.operator
174
175
  });
175
- let s = uuid();
176
- await run(t, O.insertPublisher, s, n.subject.issuer, n.subject.subject, a, now(), n.subject.issuer, n.subject.subject, Date.now());
177
- let c = await first(t, O.publisher, n.subject.issuer, n.subject.subject);
178
- if (c === null) throw await first(t, O.revokedSubject, n.subject.issuer, n.subject.subject, Date.now()) === null ? b() : new v(401, "unauthenticated", "Sign-in is required.");
176
+ let d = uuid();
177
+ await run(r, k.insertPublisher, d, a.subject.issuer, a.subject.subject, c, now(), a.subject.issuer, a.subject.subject, Date.now());
178
+ let f = await first(r, k.publisher, a.subject.issuer, a.subject.subject);
179
+ if (f === null) throw await first(r, k.revokedSubject, a.subject.issuer, a.subject.subject, Date.now()) === null ? n() : new e(401, "unauthenticated", "Sign-in is required.");
179
180
  return identityJson(201, {
180
- id: c.id,
181
- name: c.display_name,
182
- operator: n.operator
181
+ id: f.id,
182
+ name: f.display_name,
183
+ operator: a.operator
183
184
  });
184
185
  }
185
186
  async function renameMe(e, t, n) {
186
- let r = requirePublisherRow(n), i = await D(e), a = R.safeParse(i);
187
- if (!a.success) throw S();
188
- return a.data.name !== r.displayName && await run(t, O.renamePublisher, a.data.name, r.id, a.data.name), identityJson(200, {
187
+ let r = requirePublisherRow(n), a = await l(e), o = R.safeParse(a);
188
+ if (!o.success) throw i();
189
+ return o.data.name !== r.displayName && await run(t, k.renamePublisher, o.data.name, r.id, o.data.name), identityJson(200, {
189
190
  id: r.id,
190
- name: a.data.name,
191
+ name: o.data.name,
191
192
  operator: n.operator
192
193
  });
193
194
  }
194
195
  async function deleteProfile(e, t) {
195
- return t.publisher !== null && await run(e, O.deletePublisher, t.publisher.id), new Response(null, {
196
+ return t.publisher !== null && await run(e, k.deletePublisher, t.publisher.id), new Response(null, {
196
197
  headers: { "cache-control": "no-store" },
197
198
  status: 204
198
199
  });
199
200
  }
200
- async function deleteAccountProfile(e, n) {
201
- let { issuer: r, subject: i } = n.subject;
202
- return await databaseCall(() => e.DB.batch([e.DB.prepare(O.revokeSubject).bind(r, i, Date.now() + (t + 10) * 1e3), e.DB.prepare(O.deleteSubjectPublisher).bind(r, i)])), new Response(null, {
203
- headers: w,
201
+ async function deleteAccountProfile(e, t) {
202
+ let { issuer: n, subject: r } = t.subject;
203
+ return await databaseCall(() => e.DB.batch([e.DB.prepare(k.revokeSubject).bind(n, r, Date.now() + (f + 10) * 1e3), e.DB.prepare(k.deleteSubjectPublisher).bind(n, r)])), new Response(null, {
204
+ headers: o,
204
205
  status: 204
205
206
  });
206
207
  }
207
208
  async function erasePublisher(e, t, n) {
208
209
  let r = requireOperatorRow(t);
209
- return await databaseCall(() => e.DB.batch([e.DB.prepare(O.auditErasure).bind(uuid(), r.id, now(), n), e.DB.prepare(O.deletePublisher).bind(n)])), new Response(null, {
210
- headers: w,
210
+ return await databaseCall(() => e.DB.batch([e.DB.prepare(k.auditErasure).bind(uuid(), r.id, now(), n), e.DB.prepare(k.deletePublisher).bind(n)])), new Response(null, {
211
+ headers: o,
211
212
  status: 204
212
213
  });
213
214
  }
214
215
  async function listModerationLog(e, t, n) {
215
216
  requireOperatorRow(n);
216
- let r = "moderation-log", { cursor: i, limit: a } = h(e, r), o = M({
217
+ let r = "moderation-log", { cursor: i, limit: s } = E(e, r), c = N({
217
218
  cursor: i,
218
- limit: a + 1
219
- }), s = await all(t, o.sql, ...o.parameters), c = s.slice(0, a), u = c.at(-1), d = l.safeParse({
220
- actions: c.map((e) => ({
219
+ limit: s + 1
220
+ }), l = await all(t, c.sql, ...c.parameters), u = l.slice(0, s), d = u.at(-1), f = b.safeParse({
221
+ actions: u.map((e) => ({
221
222
  action: e.action,
222
223
  collection: e.collection,
223
224
  createdAt: e.created_at,
@@ -225,198 +226,198 @@ async function listModerationLog(e, t, n) {
225
226
  operatorId: e.operator_id,
226
227
  targetId: e.target_id
227
228
  })),
228
- cursor: s.length > a && u !== void 0 ? _({
229
- createdAt: u.created_at,
230
- id: u.id
229
+ cursor: l.length > s && d !== void 0 ? O({
230
+ createdAt: d.created_at,
231
+ id: d.id
231
232
  }, r) : null
232
233
  });
233
- if (!d.success) throw recordUnavailable();
234
- return C(200, d.data, w);
234
+ if (!f.success) throw recordUnavailable();
235
+ return a(200, f.data, o);
235
236
  }
236
237
  var requirePublisherRow = (e) => {
237
- if (e.publisher === null) throw x("Register before publishing.");
238
+ if (e.publisher === null) throw r("Register before publishing.");
238
239
  return e.publisher;
239
240
  }, requireOperatorRow = (e) => {
240
- if (!e.operator) throw x("Operator access is required.");
241
- if (e.publisher === null) throw x("Register before moderating.");
241
+ if (!e.operator) throw r("Operator access is required.");
242
+ if (e.publisher === null) throw r("Register before moderating.");
242
243
  return e.publisher;
243
- }, L = P.object({ name: n.optional() }), R = P.object({ name: n });
244
- async function myPublications(t, n, r) {
245
- if (r.publisher === null) return C(200, { entries: [] }, w);
246
- let i = await all(n, O.ownPublications, r.publisher.id, t.name, e.maxPublications);
247
- return C(200, { entries: i.map((e) => rowToOwnedEntry(t, e)) }, w);
244
+ }, L = F.object({ name: p.optional() }), R = F.object({ name: p });
245
+ async function myPublications(e, t, n) {
246
+ if (n.publisher === null) return a(200, { entries: [] }, o);
247
+ let r = await all(t, k.ownPublications, n.publisher.id, e.name, d.maxPublications);
248
+ return a(200, { entries: r.map((t) => rowToOwnedEntry(e, t)) }, o);
248
249
  }
249
- async function myLikes(t, n, r) {
250
- let i = new URL(t.url).searchParams.get("ids");
250
+ async function myLikes(e, n, r) {
251
+ let i = new URL(e.url).searchParams.get("ids");
251
252
  if (i === null) {
252
- let e = `likes:${r.publisher?.id ?? "unregistered"}`, { cursor: i, limit: a } = h(t, e);
253
- if (r.publisher === null) return C(200, {
253
+ let t = `likes:${r.publisher?.id ?? "unregistered"}`, { cursor: i, limit: s } = E(e, t);
254
+ if (r.publisher === null) return a(200, {
254
255
  cursor: null,
255
256
  ids: []
256
- }, w);
257
- let o = A(r.publisher.id, {
257
+ }, o);
258
+ let c = j(r.publisher.id, {
258
259
  cursor: i,
259
- limit: a + 1
260
- }), s = await all(n, o.sql, ...o.parameters), l = s.slice(0, a), u = l.at(-1), d = c.safeParse({
261
- cursor: s.length > a && u !== void 0 ? _({
262
- createdAt: u.created_at,
263
- id: u.publication_id
264
- }, e) : null,
265
- ids: l.map((e) => e.publication_id)
260
+ limit: s + 1
261
+ }), l = await all(n, c.sql, ...c.parameters), u = l.slice(0, s), d = u.at(-1), f = y.safeParse({
262
+ cursor: l.length > s && d !== void 0 ? O({
263
+ createdAt: d.created_at,
264
+ id: d.publication_id
265
+ }, t) : null,
266
+ ids: u.map((e) => e.publication_id)
266
267
  });
267
- if (!d.success) throw recordUnavailable();
268
- return C(200, d.data, w);
268
+ if (!f.success) throw recordUnavailable();
269
+ return a(200, f.data, o);
269
270
  }
270
- E(new URL(t.url), ["ids"]);
271
- let a = [...new Set(i.split(","))];
272
- if (a.length > e.likeStateIds || a.some((e) => !F.test(e))) throw y();
273
- if (r.publisher === null) return C(200, { ids: [] }, w);
274
- let o = k(r.publisher.id, a), l = await all(n, o.sql, ...o.parameters), u = new Set(l.map((e) => e.publication_id)), d = { ids: a.filter((e) => u.has(e)) }, f = s.safeParse(d);
275
- if (!f.success) throw recordUnavailable();
276
- return C(200, f.data, w);
271
+ c(new URL(e.url), ["ids"]);
272
+ let s = [...new Set(i.split(","))];
273
+ if (s.length > d.likeStateIds || s.some((e) => !u.test(e))) throw t();
274
+ if (r.publisher === null) return a(200, { ids: [] }, o);
275
+ let l = A(r.publisher.id, s), f = await all(n, l.sql, ...l.parameters), p = new Set(f.map((e) => e.publication_id)), m = { ids: s.filter((e) => p.has(e)) }, h = v.safeParse(m);
276
+ if (!h.success) throw recordUnavailable();
277
+ return a(200, h.data, o);
277
278
  }
278
- var z = P.object({
279
- clientKey: m,
280
- payload: P.unknown()
281
- }), B = P.object({
282
- expectedRevision: P.number().int().min(1).max(2 ** 53 - 1),
283
- payload: P.unknown()
279
+ var z = F.object({
280
+ clientKey: T,
281
+ payload: F.unknown()
282
+ }), B = F.object({
283
+ expectedRevision: F.number().int().min(1).max(2 ** 53 - 1),
284
+ payload: F.unknown()
284
285
  });
285
- async function resolveRetryRecord(e, t, n, r) {
286
- if (n === null || n.expires_at <= Date.now()) return null;
287
- if (n.payload_hash !== r) throw b("That key was used for a different payload.");
288
- if (n.publication_id === null) throw new v(410, "gone", "That publication was removed.");
289
- let i = await entryById(e, t, n.publication_id);
290
- return i === null ? "vanished" : C(200, i, w);
286
+ async function resolveRetryRecord(t, r, i, s) {
287
+ if (i === null || i.expires_at <= Date.now()) return null;
288
+ if (i.payload_hash !== s) throw n("That key was used for a different payload.");
289
+ if (i.publication_id === null) throw new e(410, "gone", "That publication was removed.");
290
+ let c = await entryById(t, r, i.publication_id);
291
+ return c === null ? "vanished" : a(200, c, o);
291
292
  }
292
- async function publishEntry(t, n, r, i, a) {
293
- if (!i.publishingEnabled) throw new v(503, "publishing-disabled", "Publishing is currently disabled.");
294
- let o = requirePublisherRow(a), s = await D(n), c = z.safeParse(s);
295
- if (!c.success) throw S();
296
- let { clientKey: l } = c.data, u = await t.derive(c.data.payload);
297
- if (u === null) throw S();
298
- let d = u.canonicalJson, f = u.contentHash, p = o.id, m = t.name, h = await resolveRetryRecord(t, r, await first(r, O.request, p, m, l), f);
299
- if (h !== null && h !== "vanished") return h;
300
- let g = await first(r, O.publicationByKey, p, m, l);
301
- if (g !== null) {
302
- if (g.hidden_at !== null) throw x("This entry is under moderation review.");
303
- if (g.content_hash !== f) throw b("That key was used for a different payload.");
304
- return C(200, rowToEntry(t, g), w);
293
+ async function publishEntry(t, s, c, u, f) {
294
+ if (!u.publishingEnabled) throw new e(503, "publishing-disabled", "Publishing is currently disabled.");
295
+ let p = requirePublisherRow(f), m = await l(s), h = z.safeParse(m);
296
+ if (!h.success) throw i();
297
+ let { clientKey: g } = h.data, _ = await t.derive(h.data.payload);
298
+ if (_ === null) throw i();
299
+ let v = _.canonicalJson, y = _.contentHash, b = p.id, x = t.name, S = await resolveRetryRecord(t, c, await first(c, k.request, b, x, g), y);
300
+ if (S !== null && S !== "vanished") return S;
301
+ let C = await first(c, k.publicationByKey, b, x, g);
302
+ if (C !== null) {
303
+ if (C.hidden_at !== null) throw r("This entry is under moderation review.");
304
+ if (C.content_hash !== y) throw n("That key was used for a different payload.");
305
+ return a(200, rowToEntry(t, C), o);
305
306
  }
306
- let _ = now(), y = Date.now() + e.idempotencyRetentionMs, T = JSON.stringify(u.tags);
307
- if (((await databaseCall(() => r.DB.batch([
308
- r.DB.prepare(O.expireRequests).bind(Date.now()),
309
- r.DB.prepare(O.insertPublication).bind(uuid(), p, m, l, 1, u.contentVersion, d, f, u.filter, u.title, T, _, _, p, m, e.maxPublications, p, m, l, Date.now()),
310
- r.DB.prepare(O.insertRequest).bind(p, m, l, f, _, y, p, m, l, f)
307
+ let w = now(), T = Date.now() + d.idempotencyRetentionMs, E = JSON.stringify(_.tags);
308
+ if (((await databaseCall(() => c.DB.batch([
309
+ c.DB.prepare(k.expireRequests).bind(Date.now()),
310
+ c.DB.prepare(k.insertPublication).bind(uuid(), b, x, g, 1, _.contentVersion, v, y, _.filter, _.title, E, w, w, b, x, d.maxPublications, b, x, g, Date.now()),
311
+ c.DB.prepare(k.insertRequest).bind(b, x, g, y, w, T, b, x, g, y)
311
312
  ])))[1]?.meta?.changes ?? 0) === 0) {
312
- let e = await resolveRetryRecord(t, r, await first(r, O.request, p, m, l), f);
313
- if (e === "vanished") throw new v(410, "gone", "That publication was removed.");
314
- if (e !== null) return e;
315
- let n = await first(r, O.publicationByKey, p, m, l);
316
- if (n !== null && n.hidden_at !== null) throw x("This entry is under moderation review.");
317
- if (n !== null && n.content_hash === f) return C(200, rowToEntry(t, n), w);
318
- throw n === null ? new v(429, "quota", "Publication quota reached.") : b("That key was used for a different payload.");
313
+ let i = await resolveRetryRecord(t, c, await first(c, k.request, b, x, g), y);
314
+ if (i === "vanished") throw new e(410, "gone", "That publication was removed.");
315
+ if (i !== null) return i;
316
+ let s = await first(c, k.publicationByKey, b, x, g);
317
+ if (s !== null && s.hidden_at !== null) throw r("This entry is under moderation review.");
318
+ if (s !== null && s.content_hash === y) return a(200, rowToEntry(t, s), o);
319
+ throw s === null ? new e(429, "quota", "Publication quota reached.") : n("That key was used for a different payload.");
319
320
  }
320
- let E = await first(r, O.publicationByKey, p, m, l);
321
- if (E === null) throw b();
322
- return C(201, rowToEntry(t, E), w);
321
+ let D = await first(c, k.publicationByKey, b, x, g);
322
+ if (D === null) throw n();
323
+ return a(201, rowToEntry(t, D), o);
323
324
  }
324
- async function updateEntry(e, t, n, r, i, a) {
325
- if (!r.publishingEnabled) throw new v(503, "publishing-disabled", "Publishing is currently disabled.");
326
- let o = requirePublisherRow(i), s = await first(n, O.publicationAny, a, e.name);
327
- if (s === null || s.owner_id !== o.id) throw T();
328
- if (s.hidden_at !== null) throw x("This entry is under moderation review.");
329
- let c = await D(t), l = B.safeParse(c);
330
- if (!l.success) throw S();
331
- let { expectedRevision: u } = l.data;
332
- if (u !== s.revision) throw b();
333
- let d = await e.derive(l.data.payload);
334
- if (d === null) throw S();
335
- let f = d.canonicalJson, p = d.contentHash;
336
- if (p === s.content_hash) {
337
- let t = await first(n, O.publicationAny, a, e.name);
338
- if (t === null || t.owner_id !== o.id) throw T();
339
- if (t.hidden_at !== null) throw x("This entry is under moderation review.");
340
- if (t.revision !== u) throw b();
341
- return C(200, rowToEntry(e, t), w);
325
+ async function updateEntry(t, c, u, d, f, p) {
326
+ if (!d.publishingEnabled) throw new e(503, "publishing-disabled", "Publishing is currently disabled.");
327
+ let m = requirePublisherRow(f), h = await first(u, k.publicationAny, p, t.name);
328
+ if (h === null || h.owner_id !== m.id) throw s();
329
+ if (h.hidden_at !== null) throw r("This entry is under moderation review.");
330
+ let g = await l(c), _ = B.safeParse(g);
331
+ if (!_.success) throw i();
332
+ let { expectedRevision: v } = _.data;
333
+ if (v !== h.revision) throw n();
334
+ let y = await t.derive(_.data.payload);
335
+ if (y === null) throw i();
336
+ let b = y.canonicalJson, x = y.contentHash;
337
+ if (x === h.content_hash) {
338
+ let e = await first(u, k.publicationAny, p, t.name);
339
+ if (e === null || e.owner_id !== m.id) throw s();
340
+ if (e.hidden_at !== null) throw r("This entry is under moderation review.");
341
+ if (e.revision !== v) throw n();
342
+ return a(200, rowToEntry(t, e), o);
342
343
  }
343
- let m = JSON.stringify(d.tags);
344
- if (((await run(n, O.updatePublication, 1, d.contentVersion, f, p, d.filter, d.title, m, now(), a, o.id, u, p)).meta?.changes ?? 0) === 0) {
345
- let t = await first(n, O.publicationAny, a, e.name);
346
- throw t === null ? T() : t.hidden_at === null ? b() : x("This entry is under moderation review.");
344
+ let S = JSON.stringify(y.tags);
345
+ if (((await run(u, k.updatePublication, 1, y.contentVersion, b, x, y.filter, y.title, S, now(), p, m.id, v, x)).meta?.changes ?? 0) === 0) {
346
+ let e = await first(u, k.publicationAny, p, t.name);
347
+ throw e === null ? s() : e.hidden_at === null ? n() : r("This entry is under moderation review.");
347
348
  }
348
- let h = await entryById(e, n, a);
349
- if (h === null) throw T();
350
- return C(200, h, w);
349
+ let C = await entryById(t, u, p);
350
+ if (C === null) throw s();
351
+ return a(200, C, o);
351
352
  }
352
353
  async function deleteEntry(e, t, n, r) {
353
354
  if (n.operator) {
354
355
  let i = requireOperatorRow(n);
355
- await databaseCall(() => t.DB.batch([t.DB.prepare(O.auditRemoval).bind(uuid(), i.id, now(), r, e.name), t.DB.prepare(O.removePublicationAny).bind(r, e.name)]));
356
+ await databaseCall(() => t.DB.batch([t.DB.prepare(k.auditRemoval).bind(uuid(), i.id, now(), r, e.name), t.DB.prepare(k.removePublicationAny).bind(r, e.name)]));
356
357
  } else {
357
- let i = requirePublisherRow(n), a = await first(t, O.publicationAny, r, e.name);
358
+ let i = requirePublisherRow(n), a = await first(t, k.publicationAny, r, e.name);
358
359
  if (a === null) return new Response(null, {
359
- headers: w,
360
+ headers: o,
360
361
  status: 204
361
362
  });
362
- if (a.owner_id !== i.id) throw T();
363
- await run(t, O.removePublication, r, i.id);
363
+ if (a.owner_id !== i.id) throw s();
364
+ await run(t, k.removePublication, r, i.id);
364
365
  }
365
366
  return new Response(null, {
366
- headers: w,
367
+ headers: o,
367
368
  status: 204
368
369
  });
369
370
  }
370
- async function setLike(e, t, n, r, i, a) {
371
- let s = requirePublisherRow(r);
372
- if (a && !n.likesEnabled) throw new v(503, "likes-disabled", "Likes are currently disabled.");
373
- if (await first(t, O.publication, i, e.name) === null) throw T();
374
- a ? await run(t, O.insertLike, s.id, now(), i) : await run(t, O.removeLike, i, s.id);
375
- let c = await first(t, O.likeState, s.id, i);
376
- if (c === null) throw T();
377
- let l = {
378
- id: c.id,
379
- likeCount: c.like_count,
380
- liked: c.liked === 1
381
- }, u = o.safeParse(l);
382
- if (!u.success) throw recordUnavailable();
383
- return C(200, u.data, w);
371
+ async function setLike(t, n, r, i, c, l) {
372
+ let u = requirePublisherRow(i);
373
+ if (l && !r.likesEnabled) throw new e(503, "likes-disabled", "Likes are currently disabled.");
374
+ if (await first(n, k.publication, c, t.name) === null) throw s();
375
+ l ? await run(n, k.insertLike, u.id, now(), c) : await run(n, k.removeLike, c, u.id);
376
+ let d = await first(n, k.likeState, u.id, c);
377
+ if (d === null) throw s();
378
+ let f = {
379
+ id: d.id,
380
+ likeCount: d.like_count,
381
+ liked: d.liked === 1
382
+ }, p = _.safeParse(f);
383
+ if (!p.success) throw recordUnavailable();
384
+ return a(200, p.data, o);
384
385
  }
385
- var V = P.object({ reason: P.string().check(p).trim().min(1).max(e.reportReasonChars) });
386
- async function reportEntry(e, t, n, r, i) {
387
- let a = requirePublisherRow(r), o = await D(t), s = V.safeParse(o);
388
- if (!s.success) throw S();
389
- if (await first(n, O.publication, i, e.name) === null) throw T();
390
- return await run(n, O.insertReport, uuid(), a.id, s.data.reason, now(), i, e.name), new Response(null, {
391
- headers: w,
386
+ var V = F.object({ reason: F.string().check(w).trim().min(1).max(d.reportReasonChars) });
387
+ async function reportEntry(e, t, n, r, a) {
388
+ let c = requirePublisherRow(r), u = await l(t), d = V.safeParse(u);
389
+ if (!d.success) throw i();
390
+ if (await first(n, k.publication, a, e.name) === null) throw s();
391
+ return await run(n, k.insertReport, uuid(), c.id, d.data.reason, now(), a, e.name), new Response(null, {
392
+ headers: o,
392
393
  status: 204
393
394
  });
394
395
  }
395
396
  async function setHidden(e, t, n, r, i) {
396
397
  let a = requireOperatorRow(n);
397
- if (await first(t, O.publicationAny, r, e.name) === null) throw T();
398
- let o = i ? t.DB.prepare(O.hidePublication).bind(now(), r, e.name) : t.DB.prepare(O.unhidePublication).bind(r, e.name);
399
- return await databaseCall(() => t.DB.batch([t.DB.prepare(O.auditHide).bind(uuid(), a.id, i ? "hide" : "unhide", now(), r, e.name, Number(i)), o])), new Response(null, {
400
- headers: w,
398
+ if (await first(t, k.publicationAny, r, e.name) === null) throw s();
399
+ let c = i ? t.DB.prepare(k.hidePublication).bind(now(), r, e.name) : t.DB.prepare(k.unhidePublication).bind(r, e.name);
400
+ return await databaseCall(() => t.DB.batch([t.DB.prepare(k.auditHide).bind(uuid(), a.id, i ? "hide" : "unhide", now(), r, e.name, Number(i)), c])), new Response(null, {
401
+ headers: o,
401
402
  status: 204
402
403
  });
403
404
  }
404
- async function listReports(e, t, n, r) {
405
- requireOperatorRow(r);
406
- let i = new URL(t.url).searchParams.get("status") ?? "unresolved";
407
- if (i !== "unresolved" && i !== "resolved") throw y();
408
- let a = `reports:${e.name}:${i}`, { cursor: o, limit: s } = h(t, a, ["status"]), c = N({
405
+ async function listReports(e, n, r, i) {
406
+ requireOperatorRow(i);
407
+ let s = new URL(n.url).searchParams.get("status") ?? "unresolved";
408
+ if (s !== "unresolved" && s !== "resolved") throw t();
409
+ let c = `reports:${e.name}:${s}`, { cursor: l, limit: u } = E(n, c, ["status"]), d = P({
409
410
  collection: e.name,
410
- resolved: i === "resolved"
411
+ resolved: s === "resolved"
411
412
  }, {
412
- cursor: o,
413
- limit: s + 1
414
- }), l = await all(n, c.sql, ...c.parameters), u = l.slice(0, s), f = u.at(-1), p = d.safeParse({
415
- cursor: l.length > s && f !== void 0 ? _({
416
- createdAt: f.created_at,
417
- id: f.id
418
- }, a) : null,
419
- reports: u.map((e) => ({
413
+ cursor: l,
414
+ limit: u + 1
415
+ }), f = await all(r, d.sql, ...d.parameters), p = f.slice(0, u), m = p.at(-1), h = S.safeParse({
416
+ cursor: f.length > u && m !== void 0 ? O({
417
+ createdAt: m.created_at,
418
+ id: m.id
419
+ }, c) : null,
420
+ reports: p.map((e) => ({
420
421
  createdAt: e.created_at,
421
422
  entryId: e.publication_id,
422
423
  entryTitle: e.entry_title,
@@ -429,31 +430,31 @@ async function listReports(e, t, n, r) {
429
430
  resolvedAt: e.resolved_at
430
431
  }))
431
432
  });
432
- if (!p.success) throw recordUnavailable();
433
- return C(200, p.data, w);
433
+ if (!h.success) throw recordUnavailable();
434
+ return a(200, h.data, o);
434
435
  }
435
436
  async function resolveReport(e, t, n, r) {
436
- if (requireOperatorRow(n), await first(t, O.reportById, r, e.name) === null) throw T();
437
- return await run(t, O.resolveReport, now(), r, e.name), new Response(null, {
438
- headers: w,
437
+ if (requireOperatorRow(n), await first(t, k.reportById, r, e.name) === null) throw s();
438
+ return await run(t, k.resolveReport, now(), r, e.name), new Response(null, {
439
+ headers: o,
439
440
  status: 204
440
441
  });
441
442
  }
442
443
  async function myReports(e, t, n) {
443
- let r = `own-reports:${n.publisher?.id ?? "unregistered"}`, { cursor: i, limit: a } = h(e, r);
444
- if (n.publisher === null) return C(200, {
444
+ let r = `own-reports:${n.publisher?.id ?? "unregistered"}`, { cursor: i, limit: s } = E(e, r);
445
+ if (n.publisher === null) return a(200, {
445
446
  cursor: null,
446
447
  reports: []
447
- }, w);
448
- let o = N({ publisherId: n.publisher.id }, {
448
+ }, o);
449
+ let c = P({ publisherId: n.publisher.id }, {
449
450
  cursor: i,
450
- limit: a + 1
451
- }), s = await all(t, o.sql, ...o.parameters), c = s.slice(0, a), l = c.at(-1), d = u.safeParse({
452
- cursor: s.length > a && l !== void 0 ? _({
453
- createdAt: l.created_at,
454
- id: l.id
451
+ limit: s + 1
452
+ }), l = await all(t, c.sql, ...c.parameters), u = l.slice(0, s), d = u.at(-1), f = x.safeParse({
453
+ cursor: l.length > s && d !== void 0 ? O({
454
+ createdAt: d.created_at,
455
+ id: d.id
455
456
  }, r) : null,
456
- reports: c.map((e) => ({
457
+ reports: u.map((e) => ({
457
458
  collection: e.collection,
458
459
  createdAt: e.created_at,
459
460
  entryId: e.publication_id,
@@ -462,8 +463,8 @@ async function myReports(e, t, n) {
462
463
  resolvedAt: e.resolved_at
463
464
  }))
464
465
  });
465
- if (!d.success) throw recordUnavailable();
466
- return C(200, d.data, w);
466
+ if (!f.success) throw recordUnavailable();
467
+ return a(200, f.data, o);
467
468
  }
468
469
  export { collectionMeta, deleteAccountProfile, deleteEntry, deleteProfile, erasePublisher, getEntry, getMe, healthJson, listEntries, listModerationLog, listReports, myLikes, myPublications, myReports, publishEntry, registerMe, renameMe, reportEntry, requireOperatorRow, requirePublisherRow, resolveReport, setHidden, setLike, updateEntry };
469
470