@pkcprotocol/pkc-js 0.0.118 → 0.0.120

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 (120) hide show
  1. package/README.md +3 -2
  2. package/dist/browser/clients/rpc-client/rpc-schema-util.d.ts +1 -0
  3. package/dist/browser/clients/rpc-client/schema.d.ts +1 -0
  4. package/dist/browser/community/community-client-manager.js +8 -2
  5. package/dist/browser/community/community-client-manager.js.map +1 -1
  6. package/dist/browser/community/schema.d.ts +15 -0
  7. package/dist/browser/community/schema.js +2 -1
  8. package/dist/browser/community/schema.js.map +1 -1
  9. package/dist/browser/errors.d.ts +2 -0
  10. package/dist/browser/errors.js +2 -0
  11. package/dist/browser/errors.js.map +1 -1
  12. package/dist/browser/generated-version.d.ts +1 -1
  13. package/dist/browser/generated-version.js +1 -1
  14. package/dist/browser/pages/page-sort-options.d.ts +1 -0
  15. package/dist/browser/pages/page-sort-options.js +7 -6
  16. package/dist/browser/pages/page-sort-options.js.map +1 -1
  17. package/dist/browser/pages/page-sort-scoring.d.ts +5 -1
  18. package/dist/browser/pages/page-sort-scoring.js +23 -13
  19. package/dist/browser/pages/page-sort-scoring.js.map +1 -1
  20. package/dist/browser/pages/types.d.ts +1 -1
  21. package/dist/browser/pkc-error.d.ts +1 -1
  22. package/dist/browser/publications/community-edit/schema.d.ts +4 -0
  23. package/dist/browser/publications/publication.d.ts +2 -0
  24. package/dist/browser/publications/publication.js +24 -1
  25. package/dist/browser/publications/publication.js.map +1 -1
  26. package/dist/browser/pubsub-messages/schema.d.ts +2 -0
  27. package/dist/browser/rpc/src/index.d.ts +4 -0
  28. package/dist/browser/rpc/src/index.js +74 -19
  29. package/dist/browser/rpc/src/index.js.map +1 -1
  30. package/dist/browser/runtime/node/community/db-handler.d.ts +2 -2
  31. package/dist/browser/runtime/node/community/db-handler.js +42 -58
  32. package/dist/browser/runtime/node/community/db-handler.js.map +1 -1
  33. package/dist/browser/runtime/node/community/local-community/editing.d.ts +1 -0
  34. package/dist/browser/runtime/node/community/local-community/editing.js +25 -4
  35. package/dist/browser/runtime/node/community/local-community/editing.js.map +1 -1
  36. package/dist/browser/runtime/node/community/local-community/ipns-publishing.js +7 -4
  37. package/dist/browser/runtime/node/community/local-community/ipns-publishing.js.map +1 -1
  38. package/dist/browser/runtime/node/community/local-community/lifecycle.js +17 -4
  39. package/dist/browser/runtime/node/community/local-community/lifecycle.js.map +1 -1
  40. package/dist/browser/runtime/node/community/local-community/publication-validation.js +4 -0
  41. package/dist/browser/runtime/node/community/local-community/publication-validation.js.map +1 -1
  42. package/dist/browser/runtime/node/community/local-community.d.ts +4 -1
  43. package/dist/browser/runtime/node/community/local-community.js +12 -1
  44. package/dist/browser/runtime/node/community/local-community.js.map +1 -1
  45. package/dist/browser/runtime/node/community/page-generator.d.ts +0 -1
  46. package/dist/browser/runtime/node/community/page-generator.js.map +1 -1
  47. package/dist/browser/runtime/node/community/page-sorts/index.js +22 -4
  48. package/dist/browser/runtime/node/community/page-sorts/index.js.map +1 -1
  49. package/dist/browser/runtime/node/util.d.ts +4 -1
  50. package/dist/browser/runtime/node/util.js +41 -24
  51. package/dist/browser/runtime/node/util.js.map +1 -1
  52. package/dist/browser/schema/schema-util.d.ts +9 -0
  53. package/dist/browser/test/test-util.d.ts +4 -0
  54. package/dist/bundled/bundle-manifest.json +46 -46
  55. package/dist/bundled/challenges.js +1 -1
  56. package/dist/bundled/chunks/{helia-for-pkc-DMzV8Gsa.js → helia-for-pkc-Dk9JTeUn.js} +33 -33
  57. package/dist/bundled/chunks/{local-community-DvEh9Nte.js → local-community-BbJyIuOc.js} +118 -101
  58. package/dist/bundled/chunks/{local-community-YoJAmva8.js → local-community-BkZDlh4z.js} +1 -1
  59. package/dist/bundled/chunks/{node-CH9-YjYa.js → node-CsHuIZmP.js} +21 -5
  60. package/dist/bundled/chunks/{page-sort-scoring-C1XYRQ1w.js → page-sort-scoring-B2iu-tyC.js} +11 -7
  61. package/dist/bundled/chunks/{rpc-local-community-DqKbZLIy.js → rpc-local-community-DMDs0XGh.js} +60 -27
  62. package/dist/bundled/chunks/{util-DEmcezee.js → util-CXxGmK2P.js} +5 -2
  63. package/dist/bundled/chunks/{util-CpoO437x.js → util-_DJ6MgmW.js} +1 -1
  64. package/dist/bundled/chunks/{validate-package-factories-C9A4AtCN.js → validate-package-factories-BpJjVrRb.js} +2 -2
  65. package/dist/bundled/index.js +1 -1
  66. package/dist/bundled/page-sorts.js +1 -1
  67. package/dist/bundled/rpc/src/index.js +56 -19
  68. package/dist/node/clients/rpc-client/rpc-schema-util.d.ts +1 -0
  69. package/dist/node/clients/rpc-client/schema.d.ts +1 -0
  70. package/dist/node/community/community-client-manager.js +8 -2
  71. package/dist/node/community/community-client-manager.js.map +1 -1
  72. package/dist/node/community/schema.d.ts +15 -0
  73. package/dist/node/community/schema.js +2 -1
  74. package/dist/node/community/schema.js.map +1 -1
  75. package/dist/node/errors.d.ts +2 -0
  76. package/dist/node/errors.js +2 -0
  77. package/dist/node/errors.js.map +1 -1
  78. package/dist/node/generated-version.d.ts +1 -1
  79. package/dist/node/generated-version.js +1 -1
  80. package/dist/node/pages/page-sort-options.d.ts +1 -0
  81. package/dist/node/pages/page-sort-options.js +7 -6
  82. package/dist/node/pages/page-sort-options.js.map +1 -1
  83. package/dist/node/pages/page-sort-scoring.d.ts +5 -1
  84. package/dist/node/pages/page-sort-scoring.js +23 -13
  85. package/dist/node/pages/page-sort-scoring.js.map +1 -1
  86. package/dist/node/pages/types.d.ts +1 -1
  87. package/dist/node/pkc-error.d.ts +1 -1
  88. package/dist/node/publications/community-edit/schema.d.ts +4 -0
  89. package/dist/node/publications/publication.d.ts +2 -0
  90. package/dist/node/publications/publication.js +24 -1
  91. package/dist/node/publications/publication.js.map +1 -1
  92. package/dist/node/pubsub-messages/schema.d.ts +2 -0
  93. package/dist/node/rpc/src/index.d.ts +4 -0
  94. package/dist/node/rpc/src/index.js +74 -19
  95. package/dist/node/rpc/src/index.js.map +1 -1
  96. package/dist/node/runtime/node/community/db-handler.d.ts +2 -2
  97. package/dist/node/runtime/node/community/db-handler.js +42 -58
  98. package/dist/node/runtime/node/community/db-handler.js.map +1 -1
  99. package/dist/node/runtime/node/community/local-community/editing.d.ts +1 -0
  100. package/dist/node/runtime/node/community/local-community/editing.js +25 -4
  101. package/dist/node/runtime/node/community/local-community/editing.js.map +1 -1
  102. package/dist/node/runtime/node/community/local-community/ipns-publishing.js +7 -4
  103. package/dist/node/runtime/node/community/local-community/ipns-publishing.js.map +1 -1
  104. package/dist/node/runtime/node/community/local-community/lifecycle.js +17 -4
  105. package/dist/node/runtime/node/community/local-community/lifecycle.js.map +1 -1
  106. package/dist/node/runtime/node/community/local-community/publication-validation.js +4 -0
  107. package/dist/node/runtime/node/community/local-community/publication-validation.js.map +1 -1
  108. package/dist/node/runtime/node/community/local-community.d.ts +4 -1
  109. package/dist/node/runtime/node/community/local-community.js +12 -1
  110. package/dist/node/runtime/node/community/local-community.js.map +1 -1
  111. package/dist/node/runtime/node/community/page-generator.d.ts +0 -1
  112. package/dist/node/runtime/node/community/page-generator.js.map +1 -1
  113. package/dist/node/runtime/node/community/page-sorts/index.js +22 -4
  114. package/dist/node/runtime/node/community/page-sorts/index.js.map +1 -1
  115. package/dist/node/runtime/node/util.d.ts +4 -1
  116. package/dist/node/runtime/node/util.js +41 -24
  117. package/dist/node/runtime/node/util.js.map +1 -1
  118. package/dist/node/schema/schema-util.d.ts +9 -0
  119. package/dist/node/test/test-util.d.ts +4 -0
  120. package/package.json +1 -1
@@ -1108,59 +1108,47 @@ export class DbHandler {
1108
1108
  _pendingApprovalClause(alias) {
1109
1109
  return `(${alias}.pendingApproval IS NULL OR ${alias}.pendingApproval != 1)`;
1110
1110
  }
1111
- _communityAddressClause(alias) {
1111
+ // The community identity rule (issue #401), the SQL twin of createCommunityIdentityRowFilter: the rows that belong in
1112
+ // this community's pages, counts and stats, by the community fields the comment's author signed. It is the rule client
1113
+ // page verification applies, so the community never hides a row a client would accept. A community with a name admits
1114
+ // rows whose communityName is NULL or is that name or its .eth/.bso alias. A community without a name admits rows whose
1115
+ // communityPublicKey is NULL (pre-v37 domain rows) or is its key, which is its address. Always on, for every query.
1116
+ _communityIdentityClause(alias) {
1112
1117
  const address = this._community.address;
1113
- const addresses = getEquivalentCommunityAddresses(address);
1114
1118
  if (isStringDomain(address)) {
1115
- // Domain-based: match communityName OR communityPublicKey (domain strings and IPNS keys never overlap)
1116
- const domainPlaceholders = addresses.map(() => "?").join(", ");
1119
+ const names = getEquivalentCommunityAddresses(address);
1117
1120
  return {
1118
- clause: `(${alias}.communityName IN (${domainPlaceholders}) OR ${alias}.communityPublicKey IN (${domainPlaceholders}))`,
1119
- params: [...addresses, ...addresses]
1121
+ clause: `(${alias}.communityName IS NULL OR ${alias}.communityName IN (${names.map(() => "?").join(", ")}))`,
1122
+ params: names
1120
1123
  };
1121
1124
  }
1122
- else {
1123
- // IPNS key: match communityPublicKey directly
1124
- return { clause: `${alias}.communityPublicKey = ?`, params: [address] };
1125
- }
1125
+ return { clause: `(${alias}.communityPublicKey IS NULL OR ${alias}.communityPublicKey = ?)`, params: [address] };
1126
1126
  }
1127
- _communityAddressClauseNamed(alias, paramPrefix) {
1127
+ _communityIdentityClauseNamed(alias, paramPrefix) {
1128
1128
  const address = this._community.address;
1129
- const addresses = getEquivalentCommunityAddresses(address);
1130
1129
  if (isStringDomain(address)) {
1131
- // Domain-based: match communityName OR communityPublicKey (domain strings and IPNS keys never overlap)
1132
1130
  const params = {};
1133
- const namePlaceholders = [];
1134
- const keyPlaceholders = [];
1135
- addresses.forEach((addr, i) => {
1136
- const nameParam = `${paramPrefix}CommunityName${i}`;
1137
- const keyParam = `${paramPrefix}CommunityKey${i}`;
1138
- params[nameParam] = addr;
1139
- params[keyParam] = addr;
1140
- namePlaceholders.push(`:${nameParam}`);
1141
- keyPlaceholders.push(`:${keyParam}`);
1131
+ const placeholders = getEquivalentCommunityAddresses(address).map((name, i) => {
1132
+ const paramName = `${paramPrefix}CommunityName${i}`;
1133
+ params[paramName] = name;
1134
+ return `:${paramName}`;
1142
1135
  });
1143
- return {
1144
- clause: `(${alias}.communityName IN (${namePlaceholders.join(", ")}) OR ${alias}.communityPublicKey IN (${keyPlaceholders.join(", ")}))`,
1145
- params
1146
- };
1147
- }
1148
- else {
1149
- // IPNS key: match communityPublicKey directly
1150
- const paramName = `${paramPrefix}CommunityKey`;
1151
- return { clause: `${alias}.communityPublicKey = :${paramName}`, params: { [paramName]: address } };
1136
+ return { clause: `(${alias}.communityName IS NULL OR ${alias}.communityName IN (${placeholders.join(", ")}))`, params };
1152
1137
  }
1138
+ const paramName = `${paramPrefix}CommunityKey`;
1139
+ return {
1140
+ clause: `(${alias}.communityPublicKey IS NULL OR ${alias}.communityPublicKey = :${paramName})`,
1141
+ params: { [paramName]: address }
1142
+ };
1153
1143
  }
1154
1144
  _buildPageQueryParts(options) {
1155
1145
  const commentsTable = TABLES.COMMENTS;
1156
1146
  const commentUpdatesTable = TABLES.COMMENT_UPDATES;
1157
1147
  const whereClauses = [`${commentsTable}.parentCid = ?`];
1158
1148
  const params = [options.parentCid];
1159
- if (options.excludeCommentsWithDifferentCommunityAddress) {
1160
- const { clause, params: addrParams } = this._communityAddressClause(commentsTable);
1161
- whereClauses.push(clause);
1162
- params.push(...addrParams);
1163
- }
1149
+ const { clause: identityClause, params: identityParams } = this._communityIdentityClause(commentsTable);
1150
+ whereClauses.push(identityClause);
1151
+ params.push(...identityParams);
1164
1152
  if (options.excludeCommentPendingApproval)
1165
1153
  whereClauses.push(this._pendingApprovalClause(commentsTable));
1166
1154
  if (options.excludeRemovedComments)
@@ -1428,14 +1416,12 @@ export class DbHandler {
1428
1416
  const commentsAlias = "comments";
1429
1417
  const commentUpdatesAlias = "c_updates";
1430
1418
  const deletedLookupAlias = "d";
1431
- if (options.excludeCommentsWithDifferentCommunityAddress) {
1432
- const { clause: baseClause, params: baseAddrParams } = this._communityAddressClause(commentsAlias);
1433
- baseFilterClauses.push(baseClause);
1434
- params.push(...baseAddrParams);
1435
- const { clause: recClause, params: recAddrParams } = this._communityAddressClause(commentsAlias);
1436
- recursiveFilterClauses.push(recClause);
1437
- params.push(...recAddrParams);
1438
- }
1419
+ const { clause: baseIdentityClause, params: baseIdentityParams } = this._communityIdentityClause(commentsAlias);
1420
+ baseFilterClauses.push(baseIdentityClause);
1421
+ params.push(...baseIdentityParams);
1422
+ const { clause: recursiveIdentityClause, params: recursiveIdentityParams } = this._communityIdentityClause(commentsAlias);
1423
+ recursiveFilterClauses.push(recursiveIdentityClause);
1424
+ params.push(...recursiveIdentityParams);
1439
1425
  if (options.excludeCommentPendingApproval) {
1440
1426
  const clause = this._pendingApprovalClause(commentsAlias);
1441
1427
  baseFilterClauses.push(clause);
@@ -1630,8 +1616,8 @@ export class DbHandler {
1630
1616
  _collectCommentsToBeUpdated() {
1631
1617
  const windowed = this._buildWindowedReplySortArms(timestamp());
1632
1618
  const notPending = (alias) => `(${alias}.pendingApproval IS NULL OR ${alias}.pendingApproval != 1)`;
1633
- const countedChildAddress = this._communityAddressClauseNamed("c", "countedChild");
1634
- // A child that counts towards its parent's childCount: has a CommentUpdate and this community's address, not
1619
+ const countedChildAddress = this._communityIdentityClauseNamed("c", "countedChild");
1620
+ // A child that counts towards its parent's childCount: has a CommentUpdate, passes the community identity rule, not
1635
1621
  // removed, not deleted by its author, not disapproved (the rule _queryReplyCountsByParentCids and
1636
1622
  // _queryLastChildCidsByParentCids apply, or the parent is re-flagged every cycle)
1637
1623
  const countedChild = `
@@ -1789,8 +1775,8 @@ export class DbHandler {
1789
1775
  queryCommunityStats() {
1790
1776
  // if you change this logic, make sure to run stats.community.test.js
1791
1777
  const now = timestamp(); // All timestamps are in seconds
1792
- const { clause: commentAddrClause, params: commentAddrParams } = this._communityAddressClauseNamed("comments", "statsComments");
1793
- const { clause: votesAddrClause, params: votesAddrParams } = this._communityAddressClauseNamed("comments_for_votes", "statsVotes");
1778
+ const { clause: commentAddrClause, params: commentAddrParams } = this._communityIdentityClauseNamed("comments", "statsComments");
1779
+ const { clause: votesAddrClause, params: votesAddrParams } = this._communityIdentityClauseNamed("comments_for_votes", "statsVotes");
1794
1780
  const removedCommentsClause = this._removedClause("cu_comments");
1795
1781
  const deletedCommentsClause = this._deletedFromUpdatesClause("cu_comments");
1796
1782
  const removedVotesClause = this._removedClause("cu_votes");
@@ -1940,7 +1926,7 @@ export class DbHandler {
1940
1926
  queryFirstCommentWithDepth(commentDepth) {
1941
1927
  if (!Number.isInteger(commentDepth) || commentDepth < 0)
1942
1928
  throw new Error("commentDepth must be a non-negative integer");
1943
- const { clause: addrClause, params: addrParams } = this._communityAddressClauseNamed("c", "firstComment");
1929
+ const { clause: addrClause, params: addrParams } = this._communityIdentityClauseNamed("c", "firstComment");
1944
1930
  const exactDepthRow = this._db
1945
1931
  .prepare(`SELECT c.* FROM ${TABLES.COMMENTS} c
1946
1932
  LEFT JOIN ${TABLES.COMMENT_UPDATES} cu ON cu.cid = c.cid
@@ -2022,7 +2008,7 @@ export class DbHandler {
2022
2008
  .sort((a, b) => a - b)
2023
2009
  .map((bucket) => `WHEN (${currentTimestampSeconds} - c.timestamp) <= ${bucket} THEN ${bucket}`)
2024
2010
  .join(" ");
2025
- const { clause: addrClause, params: addrParams } = this._communityAddressClause("c");
2011
+ const { clause: addrClause, params: addrParams } = this._communityIdentityClause("c");
2026
2012
  const query = `
2027
2013
  WITH post_data AS (
2028
2014
  SELECT c.cid, c.timestamp, cu.postUpdatesBucket AS current_bucket,
@@ -2344,7 +2330,7 @@ export class DbHandler {
2344
2330
  // when it is also present (neither removed, deleted nor disapproved); childCount is the level-1 part of the same count.
2345
2331
  _queryReplyCountsByParentCids(parentCids) {
2346
2332
  const result = new Map();
2347
- const { clause: addrClause, params: addrParams } = this._communityAddressClause("c");
2333
+ const { clause: addrClause, params: addrParams } = this._communityIdentityClause("c");
2348
2334
  const present = this._replyWalkPresentExpression();
2349
2335
  const deletedLookup = `(SELECT cid, json_extract(edit, '$.deleted') AS deleted_flag FROM ${TABLES.COMMENT_UPDATES})`;
2350
2336
  for (const { placeholders, params } of this._cidChunks(parentCids, addrParams.length * 2)) {
@@ -2372,7 +2358,7 @@ export class DbHandler {
2372
2358
  // but the present replies under it do (#405).
2373
2359
  _queryLastReplyTimestampsByParentCids(parentCids) {
2374
2360
  const result = new Map();
2375
- const { clause: addrClause, params: addrParams } = this._communityAddressClause("c");
2361
+ const { clause: addrClause, params: addrParams } = this._communityIdentityClause("c");
2376
2362
  const walked = `${addrClause} AND (c.pendingApproval IS NULL OR c.pendingApproval != 1)`;
2377
2363
  const present = this._replyWalkPresentExpression();
2378
2364
  const deletedLookup = `(SELECT cid, json_extract(edit, '$.deleted') AS deleted_flag FROM ${TABLES.COMMENT_UPDATES})`;
@@ -2400,7 +2386,7 @@ export class DbHandler {
2400
2386
  // not pending, disapproved, removed or deleted (MAX(rowid) with the bare cid column: SQLite returns the cid of that row).
2401
2387
  _queryLastChildCidsByParentCids(parentCids) {
2402
2388
  const result = new Map();
2403
- const { clause: addrClause, params: addrParams } = this._communityAddressClause("c");
2389
+ const { clause: addrClause, params: addrParams } = this._communityIdentityClause("c");
2404
2390
  for (const { placeholders, params } of this._cidChunks(parentCids, addrParams.length)) {
2405
2391
  const rows = this._prepareCached(`SELECT c.parentCid AS parentCid, c.cid AS cid, MAX(c.rowid) AS lastRowid FROM ${TABLES.COMMENTS} c
2406
2392
  INNER JOIN ${TABLES.COMMENT_UPDATES} cu ON cu.cid = c.cid
@@ -3164,11 +3150,9 @@ export class DbHandler {
3164
3150
  const mapper = this._pageEntryMapper(pageOptions.commentUpdateFieldsToExclude);
3165
3151
  const params = {};
3166
3152
  const postsWhereClauses = ["c.depth = 0"];
3167
- if (pageOptions.excludeCommentsWithDifferentCommunityAddress) {
3168
- const { clause, params: addrParams } = this._communityAddressClauseNamed("c", "asPosts");
3169
- postsWhereClauses.push(clause);
3170
- Object.assign(params, addrParams);
3171
- }
3153
+ const { clause: identityClause, params: identityParams } = this._communityIdentityClauseNamed("c", "asPosts");
3154
+ postsWhereClauses.push(identityClause);
3155
+ Object.assign(params, identityParams);
3172
3156
  if (pageOptions.excludeRemovedComments)
3173
3157
  postsWhereClauses.push(this._removedClause("cu"));
3174
3158
  if (pageOptions.excludeDeletedComments)