@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.
- package/README.md +3 -2
- package/dist/browser/clients/rpc-client/rpc-schema-util.d.ts +1 -0
- package/dist/browser/clients/rpc-client/schema.d.ts +1 -0
- package/dist/browser/community/community-client-manager.js +8 -2
- package/dist/browser/community/community-client-manager.js.map +1 -1
- package/dist/browser/community/schema.d.ts +15 -0
- package/dist/browser/community/schema.js +2 -1
- package/dist/browser/community/schema.js.map +1 -1
- 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/pages/page-sort-options.d.ts +1 -0
- package/dist/browser/pages/page-sort-options.js +7 -6
- package/dist/browser/pages/page-sort-options.js.map +1 -1
- package/dist/browser/pages/page-sort-scoring.d.ts +5 -1
- package/dist/browser/pages/page-sort-scoring.js +23 -13
- package/dist/browser/pages/page-sort-scoring.js.map +1 -1
- package/dist/browser/pages/types.d.ts +1 -1
- package/dist/browser/pkc-error.d.ts +1 -1
- package/dist/browser/publications/community-edit/schema.d.ts +4 -0
- package/dist/browser/publications/publication.d.ts +2 -0
- package/dist/browser/publications/publication.js +24 -1
- package/dist/browser/publications/publication.js.map +1 -1
- package/dist/browser/pubsub-messages/schema.d.ts +2 -0
- package/dist/browser/rpc/src/index.d.ts +4 -0
- package/dist/browser/rpc/src/index.js +74 -19
- package/dist/browser/rpc/src/index.js.map +1 -1
- package/dist/browser/runtime/node/community/db-handler.d.ts +2 -2
- package/dist/browser/runtime/node/community/db-handler.js +42 -58
- package/dist/browser/runtime/node/community/db-handler.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/editing.d.ts +1 -0
- package/dist/browser/runtime/node/community/local-community/editing.js +25 -4
- package/dist/browser/runtime/node/community/local-community/editing.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/ipns-publishing.js +7 -4
- package/dist/browser/runtime/node/community/local-community/ipns-publishing.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/lifecycle.js +17 -4
- package/dist/browser/runtime/node/community/local-community/lifecycle.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/publication-validation.js +4 -0
- package/dist/browser/runtime/node/community/local-community/publication-validation.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community.d.ts +4 -1
- package/dist/browser/runtime/node/community/local-community.js +12 -1
- package/dist/browser/runtime/node/community/local-community.js.map +1 -1
- package/dist/browser/runtime/node/community/page-generator.d.ts +0 -1
- package/dist/browser/runtime/node/community/page-generator.js.map +1 -1
- package/dist/browser/runtime/node/community/page-sorts/index.js +22 -4
- package/dist/browser/runtime/node/community/page-sorts/index.js.map +1 -1
- package/dist/browser/runtime/node/util.d.ts +4 -1
- package/dist/browser/runtime/node/util.js +41 -24
- package/dist/browser/runtime/node/util.js.map +1 -1
- package/dist/browser/schema/schema-util.d.ts +9 -0
- package/dist/browser/test/test-util.d.ts +4 -0
- package/dist/bundled/bundle-manifest.json +46 -46
- package/dist/bundled/challenges.js +1 -1
- package/dist/bundled/chunks/{helia-for-pkc-DMzV8Gsa.js → helia-for-pkc-Dk9JTeUn.js} +33 -33
- package/dist/bundled/chunks/{local-community-DvEh9Nte.js → local-community-BbJyIuOc.js} +118 -101
- package/dist/bundled/chunks/{local-community-YoJAmva8.js → local-community-BkZDlh4z.js} +1 -1
- package/dist/bundled/chunks/{node-CH9-YjYa.js → node-CsHuIZmP.js} +21 -5
- package/dist/bundled/chunks/{page-sort-scoring-C1XYRQ1w.js → page-sort-scoring-B2iu-tyC.js} +11 -7
- package/dist/bundled/chunks/{rpc-local-community-DqKbZLIy.js → rpc-local-community-DMDs0XGh.js} +60 -27
- package/dist/bundled/chunks/{util-DEmcezee.js → util-CXxGmK2P.js} +5 -2
- package/dist/bundled/chunks/{util-CpoO437x.js → util-_DJ6MgmW.js} +1 -1
- package/dist/bundled/chunks/{validate-package-factories-C9A4AtCN.js → validate-package-factories-BpJjVrRb.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 +56 -19
- package/dist/node/clients/rpc-client/rpc-schema-util.d.ts +1 -0
- package/dist/node/clients/rpc-client/schema.d.ts +1 -0
- package/dist/node/community/community-client-manager.js +8 -2
- package/dist/node/community/community-client-manager.js.map +1 -1
- package/dist/node/community/schema.d.ts +15 -0
- package/dist/node/community/schema.js +2 -1
- package/dist/node/community/schema.js.map +1 -1
- 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/pages/page-sort-options.d.ts +1 -0
- package/dist/node/pages/page-sort-options.js +7 -6
- package/dist/node/pages/page-sort-options.js.map +1 -1
- package/dist/node/pages/page-sort-scoring.d.ts +5 -1
- package/dist/node/pages/page-sort-scoring.js +23 -13
- package/dist/node/pages/page-sort-scoring.js.map +1 -1
- package/dist/node/pages/types.d.ts +1 -1
- package/dist/node/pkc-error.d.ts +1 -1
- package/dist/node/publications/community-edit/schema.d.ts +4 -0
- package/dist/node/publications/publication.d.ts +2 -0
- package/dist/node/publications/publication.js +24 -1
- package/dist/node/publications/publication.js.map +1 -1
- package/dist/node/pubsub-messages/schema.d.ts +2 -0
- package/dist/node/rpc/src/index.d.ts +4 -0
- package/dist/node/rpc/src/index.js +74 -19
- package/dist/node/rpc/src/index.js.map +1 -1
- package/dist/node/runtime/node/community/db-handler.d.ts +2 -2
- package/dist/node/runtime/node/community/db-handler.js +42 -58
- package/dist/node/runtime/node/community/db-handler.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/editing.d.ts +1 -0
- package/dist/node/runtime/node/community/local-community/editing.js +25 -4
- package/dist/node/runtime/node/community/local-community/editing.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/ipns-publishing.js +7 -4
- package/dist/node/runtime/node/community/local-community/ipns-publishing.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/lifecycle.js +17 -4
- package/dist/node/runtime/node/community/local-community/lifecycle.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/publication-validation.js +4 -0
- package/dist/node/runtime/node/community/local-community/publication-validation.js.map +1 -1
- package/dist/node/runtime/node/community/local-community.d.ts +4 -1
- package/dist/node/runtime/node/community/local-community.js +12 -1
- package/dist/node/runtime/node/community/local-community.js.map +1 -1
- package/dist/node/runtime/node/community/page-generator.d.ts +0 -1
- package/dist/node/runtime/node/community/page-generator.js.map +1 -1
- package/dist/node/runtime/node/community/page-sorts/index.js +22 -4
- package/dist/node/runtime/node/community/page-sorts/index.js.map +1 -1
- package/dist/node/runtime/node/util.d.ts +4 -1
- package/dist/node/runtime/node/util.js +41 -24
- package/dist/node/runtime/node/util.js.map +1 -1
- package/dist/node/schema/schema-util.d.ts +9 -0
- package/dist/node/test/test-util.d.ts +4 -0
- 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
|
-
|
|
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
|
-
|
|
1116
|
-
const domainPlaceholders = addresses.map(() => "?").join(", ");
|
|
1119
|
+
const names = getEquivalentCommunityAddresses(address);
|
|
1117
1120
|
return {
|
|
1118
|
-
clause: `(${alias}.communityName
|
|
1119
|
-
params:
|
|
1121
|
+
clause: `(${alias}.communityName IS NULL OR ${alias}.communityName IN (${names.map(() => "?").join(", ")}))`,
|
|
1122
|
+
params: names
|
|
1120
1123
|
};
|
|
1121
1124
|
}
|
|
1122
|
-
|
|
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
|
-
|
|
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
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
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
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
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
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
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.
|
|
1634
|
-
// A child that counts towards its parent's childCount: has a CommentUpdate
|
|
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.
|
|
1793
|
-
const { clause: votesAddrClause, params: votesAddrParams } = this.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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
|
-
|
|
3168
|
-
|
|
3169
|
-
|
|
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)
|