@pkcprotocol/pkc-js 0.0.132 → 0.0.134
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/dist/browser/errors.d.ts +2 -0
- package/dist/browser/errors.js +2 -0
- package/dist/browser/errors.js.map +1 -1
- package/dist/browser/generated-version.d.ts +1 -1
- package/dist/browser/generated-version.js +1 -1
- package/dist/browser/pkc-error.d.ts +1 -1
- package/dist/browser/publications/comment/schema.d.ts +4 -0
- package/dist/browser/publications/comment/schema.js +2 -1
- package/dist/browser/publications/comment/schema.js.map +1 -1
- package/dist/browser/runtime/node/community/db-handler.js +44 -91
- package/dist/browser/runtime/node/community/db-handler.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/comment-updates.js +1 -1
- package/dist/browser/runtime/node/community/local-community/comment-updates.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/editing.js +60 -7
- package/dist/browser/runtime/node/community/local-community/editing.js.map +1 -1
- package/dist/browser/runtime/node/community/page-generator.d.ts +2 -0
- package/dist/browser/runtime/node/community/page-generator.js +3 -2
- package/dist/browser/runtime/node/community/page-generator.js.map +1 -1
- package/dist/browser/runtime/node/util.d.ts +1 -0
- package/dist/browser/runtime/node/util.js +3 -2
- package/dist/browser/runtime/node/util.js.map +1 -1
- package/dist/browser/signer/signatures.js +24 -7
- package/dist/browser/signer/signatures.js.map +1 -1
- package/dist/bundled/bundle-manifest.json +34 -34
- package/dist/bundled/challenges.js +1 -1
- package/dist/bundled/chunks/{helia-for-pkc-Be5IsnZy.js → helia-for-pkc-CcFjdSPv.js} +2 -2
- package/dist/bundled/chunks/{local-community-BU2-PWv4.js → local-community-BDHE3v_Y.js} +1 -1
- package/dist/bundled/chunks/{local-community-BjDsNdnK.js → local-community-GYjtDIwZ.js} +126 -119
- package/dist/bundled/chunks/{node-Cpazwn3v.js → node-Cqt8DEE-.js} +5 -5
- package/dist/bundled/chunks/{page-sort-scoring-BqPwUozm.js → page-sort-scoring-BXVdZf57.js} +1 -1
- package/dist/bundled/chunks/{rpc-local-community-C5xdrdFG.js → rpc-local-community-CDsOv_s2.js} +55 -41
- package/dist/bundled/chunks/{util-BLpE5ch7.js → util-B-VRroTI.js} +1 -1
- package/dist/bundled/chunks/{util-DaZGW5bK.js → util-B5FM8shT.js} +5 -2
- package/dist/bundled/chunks/{validate-package-factories-DBOjkq17.js → validate-package-factories-a2ZVHdRd.js} +2 -2
- package/dist/bundled/index.js +1 -1
- package/dist/bundled/page-sorts.js +1 -1
- package/dist/bundled/rpc/src/index.js +4 -4
- package/dist/node/errors.d.ts +2 -0
- package/dist/node/errors.js +2 -0
- package/dist/node/errors.js.map +1 -1
- package/dist/node/generated-version.d.ts +1 -1
- package/dist/node/generated-version.js +1 -1
- package/dist/node/pkc-error.d.ts +1 -1
- package/dist/node/publications/comment/schema.d.ts +4 -0
- package/dist/node/publications/comment/schema.js +2 -1
- package/dist/node/publications/comment/schema.js.map +1 -1
- package/dist/node/runtime/node/community/db-handler.js +44 -91
- package/dist/node/runtime/node/community/db-handler.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/comment-updates.js +1 -1
- package/dist/node/runtime/node/community/local-community/comment-updates.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/editing.js +60 -7
- package/dist/node/runtime/node/community/local-community/editing.js.map +1 -1
- package/dist/node/runtime/node/community/page-generator.d.ts +2 -0
- package/dist/node/runtime/node/community/page-generator.js +3 -2
- package/dist/node/runtime/node/community/page-generator.js.map +1 -1
- package/dist/node/runtime/node/util.d.ts +1 -0
- package/dist/node/runtime/node/util.js +3 -2
- package/dist/node/runtime/node/util.js.map +1 -1
- package/dist/node/signer/signatures.js +24 -7
- package/dist/node/signer/signatures.js.map +1 -1
- package/package.json +1 -1
|
@@ -1193,69 +1193,61 @@ export class DbHandler {
|
|
|
1193
1193
|
.all(...params);
|
|
1194
1194
|
return rows.map(mapper.map);
|
|
1195
1195
|
}
|
|
1196
|
-
//
|
|
1197
|
-
//
|
|
1198
|
-
//
|
|
1199
|
-
//
|
|
1200
|
-
//
|
|
1201
|
-
//
|
|
1202
|
-
|
|
1196
|
+
// Rebuilds the wire form of CommentUpdates from their DB-format `replies` (CID refs) out of the given page entries.
|
|
1197
|
+
// There is one rebuild, used at every level, because a page embeds what its comment signed: any difference from the
|
|
1198
|
+
// signed form invalidates that comment's signature and stops the update cycle at the comment embedding it (issue #477).
|
|
1199
|
+
// The signed form (wirePagesFromGeneration + _generationResToPages), per sort:
|
|
1200
|
+
// - embedded (commentCids): pages[sort], in commentCids order, with nextCid when it overflowed, and never in pageCids
|
|
1201
|
+
// - not embedded: pageCids[sort]
|
|
1202
|
+
// - an entry of a flat page carries no `replies`, whatever its own CommentUpdate has (queryFlattenedPageReplies)
|
|
1203
|
+
// Keys stay sorted (see createPositionalCommentRowMapper): `replies` is re-inserted in order, and `pageCids` sorts
|
|
1204
|
+
// before `pages`. A child listed under two preloaded sorts of the same parent comes back twice and is kept once.
|
|
1205
|
+
_assembleReplyTrees(entries) {
|
|
1203
1206
|
const parsedByCid = new Map();
|
|
1204
|
-
const
|
|
1205
|
-
for (const { entry, parent } of items) {
|
|
1207
|
+
for (const entry of entries) {
|
|
1206
1208
|
const cid = entry.commentUpdate.cid;
|
|
1207
|
-
if (parsedByCid.has(cid))
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
// `pageCids` sorts before `pages`
|
|
1217
|
-
const buildWireCommentUpdate = (commentUpdate, resolvedReplies) => {
|
|
1218
|
-
const { replies: dbReplies, ...rest } = commentUpdate;
|
|
1219
|
-
if (resolvedReplies)
|
|
1220
|
-
return withSortedKeys({ ...rest, replies: resolvedReplies });
|
|
1221
|
-
if (dbReplies) {
|
|
1222
|
-
const pageCids = {};
|
|
1223
|
-
for (const sortName of Object.keys(dbReplies).sort()) {
|
|
1224
|
-
const sortEntry = dbReplies[sortName];
|
|
1209
|
+
if (!parsedByCid.has(cid))
|
|
1210
|
+
parsedByCid.set(cid, entry);
|
|
1211
|
+
}
|
|
1212
|
+
const wireRepliesOf = (dbReplies) => {
|
|
1213
|
+
const pages = {};
|
|
1214
|
+
const pageCids = {};
|
|
1215
|
+
for (const sortName of Object.keys(dbReplies).sort()) {
|
|
1216
|
+
const sortEntry = dbReplies[sortName];
|
|
1217
|
+
if (!sortEntry?.commentCids) {
|
|
1225
1218
|
if (sortEntry?.allPageCids?.[0])
|
|
1226
1219
|
pageCids[sortName] = sortEntry.allPageCids[0];
|
|
1227
|
-
}
|
|
1228
|
-
if (Object.keys(pageCids).length > 0)
|
|
1229
|
-
return withSortedKeys({ ...rest, replies: { pageCids, pages: {} } });
|
|
1230
|
-
}
|
|
1231
|
-
return rest;
|
|
1232
|
-
};
|
|
1233
|
-
const attachReplies = (cid) => {
|
|
1234
|
-
const children = childrenByParent.get(cid);
|
|
1235
|
-
if (!children?.size)
|
|
1236
|
-
return undefined;
|
|
1237
|
-
const parentDbReplies = parsedByCid.get(cid)?.commentUpdate.replies;
|
|
1238
|
-
const pages = {};
|
|
1239
|
-
for (const sortName of Object.keys(parentDbReplies ?? {}).sort()) {
|
|
1240
|
-
const sortEntry = parentDbReplies[sortName];
|
|
1241
|
-
if (!sortEntry?.commentCids)
|
|
1242
1220
|
continue;
|
|
1221
|
+
}
|
|
1243
1222
|
const comments = [];
|
|
1244
1223
|
for (const childCid of sortEntry.commentCids) {
|
|
1245
|
-
const child =
|
|
1224
|
+
const child = parsedByCid.get(childCid);
|
|
1246
1225
|
if (child)
|
|
1247
1226
|
comments.push({
|
|
1248
1227
|
comment: child.comment,
|
|
1249
|
-
commentUpdate:
|
|
1228
|
+
commentUpdate: sortEntry.flat ? withoutReplies(child.commentUpdate) : withWireReplies(child.commentUpdate)
|
|
1250
1229
|
});
|
|
1251
1230
|
}
|
|
1252
|
-
|
|
1231
|
+
// the legacy nextCid field for old DB rows
|
|
1232
|
+
const nextCid = sortEntry.allPageCids?.[0] ?? sortEntry.nextCid;
|
|
1233
|
+
pages[sortName] = { comments, ...(nextCid ? { nextCid } : {}) };
|
|
1253
1234
|
}
|
|
1254
|
-
|
|
1235
|
+
const hasPageCids = Object.keys(pageCids).length > 0;
|
|
1236
|
+
if (!hasPageCids && Object.keys(pages).length === 0)
|
|
1255
1237
|
return undefined;
|
|
1256
|
-
return { pages };
|
|
1238
|
+
return { ...(hasPageCids ? { pageCids } : {}), pages };
|
|
1257
1239
|
};
|
|
1258
|
-
|
|
1240
|
+
const withoutReplies = (commentUpdate) => {
|
|
1241
|
+
const { replies: _dbReplies, ...rest } = commentUpdate;
|
|
1242
|
+
return rest;
|
|
1243
|
+
};
|
|
1244
|
+
const withWireReplies = (commentUpdate) => {
|
|
1245
|
+
const dbReplies = commentUpdate.replies;
|
|
1246
|
+
const replies = dbReplies && wireRepliesOf(dbReplies);
|
|
1247
|
+
const rest = withoutReplies(commentUpdate);
|
|
1248
|
+
return replies ? withSortedKeys({ ...rest, replies }) : rest;
|
|
1249
|
+
};
|
|
1250
|
+
return { withWireReplies };
|
|
1259
1251
|
}
|
|
1260
1252
|
// The page entries under one comment: its direct children that pass the page's exclusions, each carrying the
|
|
1261
1253
|
// reply pages its own CommentUpdate was signed with (resolveRepliesCidRefsForEntries). The exclusions apply to
|
|
@@ -1308,10 +1300,7 @@ export class DbHandler {
|
|
|
1308
1300
|
if (withReplies.length === 0)
|
|
1309
1301
|
return entries;
|
|
1310
1302
|
const trees = withReplies.every((entry) => entry.comment.depth === 0)
|
|
1311
|
-
? this._assembleReplyTrees(this.queryRepliesUnderPosts(withReplies.map((entry) => entry.commentUpdate.cid))
|
|
1312
|
-
entry,
|
|
1313
|
-
parent: entry.comment.parentCid
|
|
1314
|
-
})))
|
|
1303
|
+
? this._assembleReplyTrees(this.queryRepliesUnderPosts(withReplies.map((entry) => entry.commentUpdate.cid)))
|
|
1315
1304
|
: this._assembleReplyTreesFromCidRefs(withReplies);
|
|
1316
1305
|
return this._rebuildEntriesFromTrees(entries, trees);
|
|
1317
1306
|
}
|
|
@@ -1345,51 +1334,15 @@ export class DbHandler {
|
|
|
1345
1334
|
`, (row) => level.push(mapper.map(row)), true);
|
|
1346
1335
|
for (const entry of level) {
|
|
1347
1336
|
seen.add(entry.commentUpdate.cid);
|
|
1348
|
-
items.push(
|
|
1337
|
+
items.push(entry);
|
|
1349
1338
|
}
|
|
1350
1339
|
frontier = listedChildren(level);
|
|
1351
1340
|
}
|
|
1352
1341
|
return this._assembleReplyTrees(items);
|
|
1353
1342
|
}
|
|
1354
1343
|
// Each entry's pages rebuilt from the assembled trees in its own commentCids order
|
|
1355
|
-
_rebuildEntriesFromTrees(entries, {
|
|
1356
|
-
return entries.map((entry) => {
|
|
1357
|
-
if (!this._entryHasDbReplies(entry))
|
|
1358
|
-
return entry;
|
|
1359
|
-
const replies = entry.commentUpdate.replies;
|
|
1360
|
-
const resolvedPages = {};
|
|
1361
|
-
const resolvedPageCids = {};
|
|
1362
|
-
for (const sortName of Object.keys(replies).sort()) {
|
|
1363
|
-
const sortEntry = replies[sortName];
|
|
1364
|
-
if (sortEntry?.commentCids) {
|
|
1365
|
-
const resolvedComments = [];
|
|
1366
|
-
for (const cid of sortEntry.commentCids) {
|
|
1367
|
-
const child = parsedByCid.get(cid);
|
|
1368
|
-
if (child)
|
|
1369
|
-
resolvedComments.push({
|
|
1370
|
-
comment: child.comment,
|
|
1371
|
-
commentUpdate: buildWireCommentUpdate(child.commentUpdate, attachReplies(cid))
|
|
1372
|
-
});
|
|
1373
|
-
}
|
|
1374
|
-
// nextCid from allPageCids[0]; the legacy nextCid field for old DB rows
|
|
1375
|
-
const nextCidForSort = sortEntry.allPageCids?.[0] ?? sortEntry.nextCid;
|
|
1376
|
-
resolvedPages[sortName] = { comments: resolvedComments, ...(nextCidForSort ? { nextCid: nextCidForSort } : {}) };
|
|
1377
|
-
}
|
|
1378
|
-
if (sortEntry?.allPageCids?.[0])
|
|
1379
|
-
resolvedPageCids[sortName] = sortEntry.allPageCids[0];
|
|
1380
|
-
}
|
|
1381
|
-
const { replies: _dbReplies, ...entryCommentUpdateRest } = entry.commentUpdate;
|
|
1382
|
-
return {
|
|
1383
|
-
...entry,
|
|
1384
|
-
commentUpdate: withSortedKeys({
|
|
1385
|
-
...entryCommentUpdateRest,
|
|
1386
|
-
replies: {
|
|
1387
|
-
...(Object.keys(resolvedPageCids).length > 0 ? { pageCids: resolvedPageCids } : {}),
|
|
1388
|
-
pages: resolvedPages
|
|
1389
|
-
}
|
|
1390
|
-
})
|
|
1391
|
-
};
|
|
1392
|
-
});
|
|
1344
|
+
_rebuildEntriesFromTrees(entries, { withWireReplies }) {
|
|
1345
|
+
return entries.map((entry) => this._entryHasDbReplies(entry) ? { ...entry, commentUpdate: withWireReplies(entry.commentUpdate) } : entry);
|
|
1393
1346
|
}
|
|
1394
1347
|
queryCommentAndCommentUpdateByCids(cids, opts) {
|
|
1395
1348
|
if (cids.length === 0)
|