@aduptive/strapi-blockscene 1.0.0-alpha.11 → 1.0.0-alpha.12
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/server.cjs +18 -4
- package/package.json +1 -1
package/dist/server.cjs
CHANGED
|
@@ -1460,6 +1460,18 @@ var require_history = __commonJS({
|
|
|
1460
1460
|
var hashOf = (text) => createHash("sha256").update(text).digest("hex");
|
|
1461
1461
|
var covers2 = (history, uid) => Boolean(history?.enabled) && uid.startsWith("api::") && (history.contentTypes === "all" || Array.isArray(history.contentTypes) && history.contentTypes.includes(uid));
|
|
1462
1462
|
var retention = ({ retentionDays, eventDays }, now = Date.now()) => ({ snapshotsBefore: new Date(now - retentionDays * DAY), eventsBefore: new Date(now - eventDays * DAY) });
|
|
1463
|
+
var hasChanges = (summary) => Boolean(summary?.initial || summary?.fields?.length || ["added", "removed", "changed"].some((key) => summary?.blocks?.[key] > 0));
|
|
1464
|
+
function collapseVersions(events) {
|
|
1465
|
+
const versions = [];
|
|
1466
|
+
for (const event of events) {
|
|
1467
|
+
const previous = versions[versions.length - 1];
|
|
1468
|
+
if (event.hash && previous?.hash === event.hash) {
|
|
1469
|
+
if (!previous.actions.includes(event.action)) previous.actions.push(event.action);
|
|
1470
|
+
if (!hasChanges(previous.summary) && hasChanges(event.summary)) previous.summary = event.summary;
|
|
1471
|
+
} else versions.push({ ...event, actions: [event.action] });
|
|
1472
|
+
}
|
|
1473
|
+
return versions;
|
|
1474
|
+
}
|
|
1463
1475
|
function actorOf(strapi) {
|
|
1464
1476
|
let ctx;
|
|
1465
1477
|
try {
|
|
@@ -1561,12 +1573,14 @@ var require_history = __commonJS({
|
|
|
1561
1573
|
async list({ uid, documentId, locale, actor = "", page = 1, pageSize = 25 }) {
|
|
1562
1574
|
const scope2 = { contentType: uid, relatedDocumentId: documentId, locale: locale || null };
|
|
1563
1575
|
const where = { ...scope2, ...actor && { actor } };
|
|
1564
|
-
const [
|
|
1565
|
-
events().findMany({ select: ["id", "action", "actor", "actorName", "at", "summary", "hash", "size"], where, orderBy: [{ at: "desc" }, { id: "desc" }]
|
|
1576
|
+
const [timeline, kept, people] = await Promise.all([
|
|
1577
|
+
events().findMany({ select: ["id", "action", "actor", "actorName", "at", "summary", "hash", "size"], where, orderBy: [{ at: "desc" }, { id: "desc" }] }),
|
|
1566
1578
|
events().findMany({ select: ["hash"], where: { ...scope2, size: { $gt: 0 } } }),
|
|
1567
|
-
events().count({ where }),
|
|
1568
1579
|
events().findMany({ select: ["actor", "actorName"], where: scope2, orderBy: [{ at: "desc" }, { id: "desc" }] })
|
|
1569
1580
|
]);
|
|
1581
|
+
const versions = collapseVersions(timeline);
|
|
1582
|
+
const total = versions.length;
|
|
1583
|
+
const list = versions.slice((page - 1) * pageSize, page * pageSize);
|
|
1570
1584
|
const hashes = new Set(kept.map((row) => row.hash));
|
|
1571
1585
|
const actors2 = [...new Map(people.slice().reverse().map(({ actor: actor2, actorName }) => [actor2, { actor: actor2, actorName }])).values()];
|
|
1572
1586
|
return {
|
|
@@ -1814,7 +1828,7 @@ var require_history = __commonJS({
|
|
|
1814
1828
|
};
|
|
1815
1829
|
}
|
|
1816
1830
|
});
|
|
1817
|
-
module2.exports = { EVENT_UID, ACTIONS, CAPTURED, CRON: CRON2, BATCH, eventContentType: eventContentType2, covers: covers2, retention, actorOf, refsOf, can, readableTypes, historyService: historyService2, registerHistory: registerHistory2, registerPurge: registerPurge2, historyController: historyController2 };
|
|
1831
|
+
module2.exports = { EVENT_UID, ACTIONS, CAPTURED, CRON: CRON2, BATCH, eventContentType: eventContentType2, covers: covers2, retention, actorOf, refsOf, collapseVersions, can, readableTypes, historyService: historyService2, registerHistory: registerHistory2, registerPurge: registerPurge2, historyController: historyController2 };
|
|
1818
1832
|
}
|
|
1819
1833
|
});
|
|
1820
1834
|
|
package/package.json
CHANGED