@tearleads/client-sdk 0.1.206 → 0.1.208

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 (50) hide show
  1. package/client/documents/index.d.ts +8 -0
  2. package/client/documents/index.js +14 -1
  3. package/client/documents/index.js.map +1 -1
  4. package/client/index.d.ts +1 -1
  5. package/client/index.js.map +1 -1
  6. package/data/documents/documentRestore.d.ts +30 -0
  7. package/data/documents/documentRestore.js +77 -0
  8. package/data/documents/documentRestore.js.map +1 -0
  9. package/data/documents/documentRowList.d.ts +6 -0
  10. package/data/documents/documentRowList.js +31 -0
  11. package/data/documents/documentRowList.js.map +1 -1
  12. package/data/documents/index.d.ts +1 -0
  13. package/data/documents/index.js.map +1 -1
  14. package/data/persistence/organizations/organizationDataUsagePersistence.js +90 -82
  15. package/data/persistence/organizations/organizationDataUsagePersistence.js.map +1 -1
  16. package/index.d.ts +3 -3
  17. package/index.js +1 -1
  18. package/index.js.map +1 -1
  19. package/internal/loro/historyTimeline.d.ts +57 -0
  20. package/internal/loro/historyTimeline.js +271 -0
  21. package/internal/loro/historyTimeline.js.map +1 -0
  22. package/internal/loro/index.d.ts +1 -0
  23. package/internal/loro/index.js +1 -0
  24. package/internal/loro/index.js.map +1 -1
  25. package/package.json +1 -1
  26. package/stores/documents/documentStore/history/restoreContent.js +127 -0
  27. package/stores/documents/documentStore/history/restoreContent.js.map +1 -0
  28. package/stores/documents/documentStore/index.js +4 -4
  29. package/stores/documents/documentStore/index.js.map +1 -1
  30. package/stores/documents/documentStore/mutations.js +1 -1
  31. package/stores/documents/documentStore/mutations.js.map +1 -1
  32. package/stores/documents/documentStore/rows/index.js +8 -0
  33. package/stores/documents/documentStore/rows/index.js.map +1 -1
  34. package/stores/documents/registry.js +1 -0
  35. package/stores/documents/registry.js.map +1 -1
  36. package/stores/documents/removedDocumentStore.js +1 -0
  37. package/stores/documents/removedDocumentStore.js.map +1 -1
  38. package/stores/documents/types.d.ts +10 -1
  39. package/stores/documents/types.js.map +1 -1
  40. package/workflows/documents/history/documentHistory.d.ts +72 -0
  41. package/workflows/documents/history/documentHistory.js +103 -0
  42. package/workflows/documents/history/documentHistory.js.map +1 -0
  43. package/workflows/documents/history/documentHistoryChange.d.ts +51 -0
  44. package/workflows/documents/history/documentHistoryChange.js +110 -0
  45. package/workflows/documents/history/documentHistoryChange.js.map +1 -0
  46. package/workflows/documents/index.d.ts +2 -0
  47. package/workflows/documents/index.js +2 -0
  48. package/workflows/documents/index.js.map +1 -1
  49. package/workflows/organizations/readModel/dataUsageReadModel.js +4 -5
  50. package/workflows/organizations/readModel/dataUsageReadModel.js.map +1 -1
@@ -0,0 +1,72 @@
1
+ import { type DocumentFieldValidationIssue, type DocumentProjectorRegistryInput } from "../../../data/documents/documentKinds.js";
2
+ import type { DocumentsPersistence } from "../../../data/persistence/documents/documentsPersistence.js";
3
+ import type { ExecSql } from "../../../data/sqlite/sqlSchema.js";
4
+ import { type DocumentHistoryChange, type DocumentHistoryContent } from "./documentHistoryChange.js";
5
+ /** One step of a document's history: a single change by a single writer. */
6
+ export interface DocumentHistoryStop {
7
+ /** Position in the timeline, oldest first. */
8
+ readonly index: number;
9
+ /** The Loro peer that made the change; resolve it through edit attribution. */
10
+ readonly peerId: string;
11
+ /** Counter of the change's first operation. */
12
+ readonly startCounter: number;
13
+ /** One past the counter of the change's last operation. */
14
+ readonly endCounter: number;
15
+ /**
16
+ * When the writing device recorded the change, in Unix milliseconds, or
17
+ * null when it recorded no time. Self-reported: see `DocumentHistory`.
18
+ */
19
+ readonly committedAt: number | null;
20
+ }
21
+ /** The document as it was at one stop, in the shape a document store shows. */
22
+ export interface DocumentHistoryView extends DocumentHistoryContent {
23
+ readonly fieldValidationIssues: ReadonlyArray<DocumentFieldValidationIssue>;
24
+ readonly title: string;
25
+ }
26
+ /** The last operation a version includes for one peer. */
27
+ export interface DocumentHistoryVersionEntry {
28
+ readonly counter: number;
29
+ readonly peerId: string;
30
+ }
31
+ /** A version of a document, as the operations that head it. */
32
+ export type DocumentHistoryVersion = ReadonlyArray<DocumentHistoryVersionEntry>;
33
+ /**
34
+ * A read-only replay of one document's durable local history.
35
+ *
36
+ * It is a capture: it holds the history that was durable when it was opened
37
+ * and never changes afterwards, so the live document keeps editing and
38
+ * syncing untouched. Open another to see later edits. Call `close()` when
39
+ * done; it holds a WASM document.
40
+ *
41
+ * Times are the writing devices' own clocks, and a change is never recorded
42
+ * earlier than the newest time its document already held. History that
43
+ * arrived through a rotation baseline is whatever that baseline's writer
44
+ * asserted.
45
+ */
46
+ export interface DocumentHistory {
47
+ /** Every change, in the order the timeline plays them. */
48
+ readonly stops: ReadonlyArray<DocumentHistoryStop>;
49
+ /** What `stops[index]` changed, compared with the stop before it. */
50
+ changeAt(index: number): DocumentHistoryChange;
51
+ close(): void;
52
+ /** The version after `stops[0..index]`. */
53
+ versionAt(index: number): DocumentHistoryVersion;
54
+ /**
55
+ * The document after `stops[0..index]`; `-1` is the empty document before
56
+ * the first change. Replaying a distant stop of a large document can take
57
+ * tens of milliseconds, so keep it out of rendering.
58
+ */
59
+ viewAt(index: number): DocumentHistoryView;
60
+ }
61
+ /**
62
+ * Open a replay of the document's durable local history (checkpoint plus
63
+ * tail). Returns null when the document has none yet, such as a discovered
64
+ * shell that has not hydrated. The history is loaded into a scratch document,
65
+ * never the one a document store is editing.
66
+ */
67
+ export declare function openDocumentHistory(input: {
68
+ readonly documentProjectors: DocumentProjectorRegistryInput;
69
+ readonly execSql: ExecSql;
70
+ readonly localId: string;
71
+ readonly persistence: Pick<DocumentsPersistence, "loadHistoryRestoreState">;
72
+ }): Promise<DocumentHistory | null>;
@@ -0,0 +1,103 @@
1
+ import { base64ToBytes } from "../../../internal/encoding/index.js";
2
+ import { createReadOnlyDocument, importSnapshot, openHistoryViewer, } from "../../../internal/loro/index.js";
3
+ import { getDocumentAttachments } from "../../../data/documents/documentContent.js";
4
+ import { readStoredDocumentState, } from "../../../data/documents/documentKinds.js";
5
+ import { listDocumentRows } from "../../../data/documents/documentRowList.js";
6
+ import { importDocumentHistoryTailUpdates } from "../historyContent.js";
7
+ import { compareDocumentHistoryContent, } from "./documentHistoryChange.js";
8
+ /** Views kept so stepping to a neighbor does not replay the document twice. */
9
+ const VIEW_CACHE_SIZE = 8;
10
+ class DocumentHistoryReader {
11
+ viewer;
12
+ documentProjectors;
13
+ stops;
14
+ closed = false;
15
+ /** Insertion-ordered: the first key is the least recently used. */
16
+ views = new Map();
17
+ constructor(viewer, documentProjectors) {
18
+ this.viewer = viewer;
19
+ this.documentProjectors = documentProjectors;
20
+ this.stops = viewer.stops.map((stop, index) => ({
21
+ index,
22
+ peerId: stop.peerId,
23
+ startCounter: stop.startCounter,
24
+ endCounter: stop.endCounter,
25
+ committedAt: stop.timestamp === null ? null : stop.timestamp * 1000,
26
+ }));
27
+ }
28
+ changeAt(index) {
29
+ this.assertStop(index, 0);
30
+ return compareDocumentHistoryContent(this.viewAt(index - 1), this.viewAt(index));
31
+ }
32
+ close() {
33
+ if (this.closed)
34
+ return;
35
+ this.closed = true;
36
+ this.views.clear();
37
+ this.viewer.free();
38
+ }
39
+ versionAt(index) {
40
+ this.assertStop(index, -1);
41
+ return this.viewer.versionAt(index);
42
+ }
43
+ viewAt(index) {
44
+ this.assertStop(index, -1);
45
+ const cached = this.views.get(index);
46
+ if (cached !== undefined) {
47
+ this.views.delete(index);
48
+ this.views.set(index, cached);
49
+ return cached;
50
+ }
51
+ this.viewer.checkout(index);
52
+ const { doc } = this.viewer;
53
+ const view = {
54
+ ...readStoredDocumentState(doc, this.documentProjectors),
55
+ attachments: getDocumentAttachments(doc),
56
+ rows: listDocumentRows(doc),
57
+ };
58
+ this.views.set(index, view);
59
+ if (this.views.size > VIEW_CACHE_SIZE) {
60
+ const oldest = this.views.keys().next();
61
+ if (!oldest.done)
62
+ this.views.delete(oldest.value);
63
+ }
64
+ return view;
65
+ }
66
+ assertStop(index, lowest) {
67
+ if (this.closed) {
68
+ throw new Error("Document history is closed.");
69
+ }
70
+ if (!Number.isInteger(index) ||
71
+ index < lowest ||
72
+ index >= this.stops.length) {
73
+ throw new RangeError(`Document history stop ${index} is out of range.`);
74
+ }
75
+ }
76
+ }
77
+ /**
78
+ * Open a replay of the document's durable local history (checkpoint plus
79
+ * tail). Returns null when the document has none yet, such as a discovered
80
+ * shell that has not hydrated. The history is loaded into a scratch document,
81
+ * never the one a document store is editing.
82
+ */
83
+ export async function openDocumentHistory(input) {
84
+ const history = await input.persistence.loadHistoryRestoreState(input.execSql, input.localId);
85
+ if (!history) {
86
+ return null;
87
+ }
88
+ const doc = createReadOnlyDocument();
89
+ try {
90
+ // A tail-only state (a crash before the birth checkpoint landed) has an
91
+ // empty snapshot; the tail rows alone carry the history.
92
+ if (history.snapshot.length > 0) {
93
+ importSnapshot(doc, base64ToBytes(history.snapshot));
94
+ }
95
+ importDocumentHistoryTailUpdates(doc, history.tailUpdates.map((update) => update.updateData));
96
+ return new DocumentHistoryReader(openHistoryViewer(doc), input.documentProjectors);
97
+ }
98
+ catch (error) {
99
+ doc.free();
100
+ throw error;
101
+ }
102
+ }
103
+ //# sourceMappingURL=documentHistory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"documentHistory.js","sourceRoot":"","sources":["documentHistory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EACL,sBAAsB,EAEtB,cAAc,EACd,iBAAiB,GAClB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,sBAAsB,EAAE,MAAM,yCAAyC,CAAC;AACjF,OAAO,EAGL,uBAAuB,GACxB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,yCAAyC,CAAC;AAG3E,OAAO,EAAE,gCAAgC,EAAE,MAAM,mBAAmB,CAAC;AACrE,OAAO,EACL,6BAA6B,GAG9B,MAAM,yBAAyB,CAAC;AAEjC,+EAA+E;AAC/E,MAAM,eAAe,GA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QACD,IACE,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC;YACxB,KAAK,GAAG,MAAM;YACd,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,EAC1B,CAAC;YACD,MAAM,IAAI,UAAU,CAAC,yBAAyB,KAAK,mBAAmB,CAAC,CAAC;QAC1E,CAAC;IACH,CAAC;CACF;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,KAKzC;IACC,MAAM,OAAO,GAAG,MAAM,KAAK,CAAC,WAAW,CAAC,uBAAuB,CAC7D,KAAK,CAAC,OAAO,EACb,KAAK,CAAC,OAAO,CACd,CAAC;IACF,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,GAAG,GAAG,sBAAsB,EAAE,CAAC;IACrC,IAAI,CAAC;QACH,wEAAwE;QACxE,yDAAyD;QACzD,IAAI,OAAO,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAChC,cAAc,CAAC,GAAG,EAAE,aAAa,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;QACvD,CAAC;QACD,gCAAgC,CAC9B,GAAG,EACH,OAAO,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,CACvD,CAAC;QACF,OAAO,IAAI,qBAAqB,CAC9B,iBAAiB,CAAC,GAAG,CAAC,EACtB,KAAK,CAAC,kBAAkB,CACzB,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,GAAG,CAAC,IAAI,EAAE,CAAC;QACX,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["import { base64ToBytes } from \"@tearleads/encoding\";\nimport {\n createReadOnlyDocument,\n type HistoryViewer,\n importSnapshot,\n openHistoryViewer,\n} from \"@tearleads/loro\";\nimport { getDocumentAttachments } from \"../../../data/documents/documentContent\";\nimport {\n type DocumentFieldValidationIssue,\n type DocumentProjectorRegistryInput,\n readStoredDocumentState,\n} from \"../../../data/documents/documentKinds\";\nimport { listDocumentRows } from \"../../../data/documents/documentRowList\";\nimport type { DocumentsPersistence } from \"../../../data/persistence/documents/documentsPersistence\";\nimport type { ExecSql } from \"../../../data/sqlite/sqlSchema\";\nimport { importDocumentHistoryTailUpdates } from \"../historyContent\";\nimport {\n compareDocumentHistoryContent,\n type DocumentHistoryChange,\n type DocumentHistoryContent,\n} from \"./documentHistoryChange\";\n\n/** Views kept so stepping to a neighbor does not replay the document twice. */\nconst VIEW_CACHE_SIZE = 8;\n\n/** One step of a document's history: a single change by a single writer. */\nexport interface DocumentHistoryStop {\n /** Position in the timeline, oldest first. */\n readonly index: number;\n /** The Loro peer that made the change; resolve it through edit attribution. */\n readonly peerId: string;\n /** Counter of the change's first operation. */\n readonly startCounter: number;\n /** One past the counter of the change's last operation. */\n readonly endCounter: number;\n /**\n * When the writing device recorded the change, in Unix milliseconds, or\n * null when it recorded no time. Self-reported: see `DocumentHistory`.\n */\n readonly committedAt: number | null;\n}\n\n/** The document as it was at one stop, in the shape a document store shows. */\nexport interface DocumentHistoryView extends DocumentHistoryContent {\n readonly fieldValidationIssues: ReadonlyArray<DocumentFieldValidationIssue>;\n readonly title: string;\n}\n\n/** The last operation a version includes for one peer. */\nexport interface DocumentHistoryVersionEntry {\n readonly counter: number;\n readonly peerId: string;\n}\n\n/** A version of a document, as the operations that head it. */\nexport type DocumentHistoryVersion = ReadonlyArray<DocumentHistoryVersionEntry>;\n\n/**\n * A read-only replay of one document's durable local history.\n *\n * It is a capture: it holds the history that was durable when it was opened\n * and never changes afterwards, so the live document keeps editing and\n * syncing untouched. Open another to see later edits. Call `close()` when\n * done; it holds a WASM document.\n *\n * Times are the writing devices' own clocks, and a change is never recorded\n * earlier than the newest time its document already held. History that\n * arrived through a rotation baseline is whatever that baseline's writer\n * asserted.\n */\nexport interface DocumentHistory {\n /** Every change, in the order the timeline plays them. */\n readonly stops: ReadonlyArray<DocumentHistoryStop>;\n /** What `stops[index]` changed, compared with the stop before it. */\n changeAt(index: number): DocumentHistoryChange;\n close(): void;\n /** The version after `stops[0..index]`. */\n versionAt(index: number): DocumentHistoryVersion;\n /**\n * The document after `stops[0..index]`; `-1` is the empty document before\n * the first change. Replaying a distant stop of a large document can take\n * tens of milliseconds, so keep it out of rendering.\n */\n viewAt(index: number): DocumentHistoryView;\n}\n\nclass DocumentHistoryReader implements DocumentHistory {\n readonly stops: ReadonlyArray<DocumentHistoryStop>;\n private closed = false;\n /** Insertion-ordered: the first key is the least recently used. */\n private readonly views = new Map<number, DocumentHistoryView>();\n\n constructor(\n private readonly viewer: HistoryViewer,\n private readonly documentProjectors: DocumentProjectorRegistryInput,\n ) {\n this.stops = viewer.stops.map((stop, index) => ({\n index,\n peerId: stop.peerId,\n startCounter: stop.startCounter,\n endCounter: stop.endCounter,\n committedAt: stop.timestamp === null ? null : stop.timestamp * 1000,\n }));\n }\n\n changeAt(index: number): DocumentHistoryChange {\n this.assertStop(index, 0);\n return compareDocumentHistoryContent(\n this.viewAt(index - 1),\n this.viewAt(index),\n );\n }\n\n close(): void {\n if (this.closed) return;\n this.closed = true;\n this.views.clear();\n this.viewer.free();\n }\n\n versionAt(index: number): DocumentHistoryVersion {\n this.assertStop(index, -1);\n return this.viewer.versionAt(index);\n }\n\n viewAt(index: number): DocumentHistoryView {\n this.assertStop(index, -1);\n const cached = this.views.get(index);\n if (cached !== undefined) {\n this.views.delete(index);\n this.views.set(index, cached);\n return cached;\n }\n this.viewer.checkout(index);\n const { doc } = this.viewer;\n const view: DocumentHistoryView = {\n ...readStoredDocumentState(doc, this.documentProjectors),\n attachments: getDocumentAttachments(doc),\n rows: listDocumentRows(doc),\n };\n this.views.set(index, view);\n if (this.views.size > VIEW_CACHE_SIZE) {\n const oldest = this.views.keys().next();\n if (!oldest.done) this.views.delete(oldest.value);\n }\n return view;\n }\n\n private assertStop(index: number, lowest: -1 | 0): void {\n if (this.closed) {\n throw new Error(\"Document history is closed.\");\n }\n if (\n !Number.isInteger(index) ||\n index < lowest ||\n index >= this.stops.length\n ) {\n throw new RangeError(`Document history stop ${index} is out of range.`);\n }\n }\n}\n\n/**\n * Open a replay of the document's durable local history (checkpoint plus\n * tail). Returns null when the document has none yet, such as a discovered\n * shell that has not hydrated. The history is loaded into a scratch document,\n * never the one a document store is editing.\n */\nexport async function openDocumentHistory(input: {\n readonly documentProjectors: DocumentProjectorRegistryInput;\n readonly execSql: ExecSql;\n readonly localId: string;\n readonly persistence: Pick<DocumentsPersistence, \"loadHistoryRestoreState\">;\n}): Promise<DocumentHistory | null> {\n const history = await input.persistence.loadHistoryRestoreState(\n input.execSql,\n input.localId,\n );\n if (!history) {\n return null;\n }\n\n const doc = createReadOnlyDocument();\n try {\n // A tail-only state (a crash before the birth checkpoint landed) has an\n // empty snapshot; the tail rows alone carry the history.\n if (history.snapshot.length > 0) {\n importSnapshot(doc, base64ToBytes(history.snapshot));\n }\n importDocumentHistoryTailUpdates(\n doc,\n history.tailUpdates.map((update) => update.updateData),\n );\n return new DocumentHistoryReader(\n openHistoryViewer(doc),\n input.documentProjectors,\n );\n } catch (error) {\n doc.free();\n throw error;\n }\n}\n"]}
@@ -0,0 +1,51 @@
1
+ import type { DocumentAttachment } from "../../../data/documents/documentContent.js";
2
+ import type { StoredDocumentKind } from "../../../data/documents/documentKinds.js";
3
+ import type { DocumentRow } from "../../../data/documents/documentRowList.js";
4
+ /** The parts of a document that its history can change. */
5
+ export interface DocumentHistoryContent {
6
+ readonly attachments: ReadonlyArray<DocumentAttachment>;
7
+ readonly documentKind: StoredDocumentKind;
8
+ readonly rows: ReadonlyArray<DocumentRow>;
9
+ readonly structuredFields: Readonly<Record<string, string>>;
10
+ readonly text: string;
11
+ }
12
+ /**
13
+ * The one region of text that differs between two versions, in UTF-16 units
14
+ * of the newer text. Edits in several places are reported as the single region
15
+ * that spans them.
16
+ */
17
+ export interface DocumentHistoryTextChange {
18
+ /** Where the region starts, in both the older and the newer text. */
19
+ readonly start: number;
20
+ /** Length of the region in the newer text. */
21
+ readonly insertedLength: number;
22
+ /** Length of the region it replaced in the older text. */
23
+ readonly removedLength: number;
24
+ }
25
+ export interface DocumentHistoryRowChange {
26
+ readonly id: string;
27
+ /** Cells whose value was set, changed, or cleared, in key order. */
28
+ readonly fields: ReadonlyArray<string>;
29
+ }
30
+ /** What one step of history changed, compared with the step before it. */
31
+ export interface DocumentHistoryChange {
32
+ readonly attachments: {
33
+ readonly added: ReadonlyArray<string>;
34
+ readonly removed: ReadonlyArray<string>;
35
+ /** Slots that kept their place but now hold different bytes or a new name. */
36
+ readonly replaced: ReadonlyArray<string>;
37
+ };
38
+ /** Structured fields set, changed, or cleared, in key order. */
39
+ readonly fields: ReadonlyArray<string>;
40
+ readonly kindChanged: boolean;
41
+ readonly rows: {
42
+ readonly added: ReadonlyArray<string>;
43
+ readonly changed: ReadonlyArray<DocumentHistoryRowChange>;
44
+ readonly removed: ReadonlyArray<string>;
45
+ };
46
+ readonly text: DocumentHistoryTextChange | null;
47
+ }
48
+ /** Compare a version with the one before it. Pure. */
49
+ export declare function compareDocumentHistoryContent(before: DocumentHistoryContent, after: DocumentHistoryContent): DocumentHistoryChange;
50
+ /** Whether a step changed anything a reader of the document would see. */
51
+ export declare function isEmptyDocumentHistoryChange(change: DocumentHistoryChange): boolean;
@@ -0,0 +1,110 @@
1
+ function isHighSurrogate(codeUnit) {
2
+ return codeUnit >= 0xd800 && codeUnit <= 0xdbff;
3
+ }
4
+ function isLowSurrogate(codeUnit) {
5
+ return codeUnit >= 0xdc00 && codeUnit <= 0xdfff;
6
+ }
7
+ function compareTextChange(before, after) {
8
+ if (before === after)
9
+ return null;
10
+ const shorter = Math.min(before.length, after.length);
11
+ let start = 0;
12
+ while (start < shorter &&
13
+ before.charCodeAt(start) === after.charCodeAt(start)) {
14
+ start += 1;
15
+ }
16
+ // Keep a shared high surrogate with the differing low surrogate after it.
17
+ if (start > 0 && isHighSurrogate(before.charCodeAt(start - 1)))
18
+ start -= 1;
19
+ let shared = 0;
20
+ while (shared < shorter - start &&
21
+ before.charCodeAt(before.length - 1 - shared) ===
22
+ after.charCodeAt(after.length - 1 - shared)) {
23
+ shared += 1;
24
+ }
25
+ // Keep a shared low surrogate with the differing high surrogate before it.
26
+ if (shared > 0 && isLowSurrogate(before.charCodeAt(before.length - shared))) {
27
+ shared -= 1;
28
+ }
29
+ return {
30
+ start,
31
+ insertedLength: after.length - shared - start,
32
+ removedLength: before.length - shared - start,
33
+ };
34
+ }
35
+ function changedKeys(before, after) {
36
+ const keys = new Set([...Object.keys(before), ...Object.keys(after)]);
37
+ return [...keys].filter((key) => before[key] !== after[key]).sort();
38
+ }
39
+ function compareRows(before, after) {
40
+ const beforeById = new Map(before.map((row) => [row.id, row]));
41
+ const afterIds = new Set(after.map((row) => row.id));
42
+ const added = [];
43
+ const changed = [];
44
+ for (const row of after) {
45
+ const previous = beforeById.get(row.id);
46
+ if (previous === undefined) {
47
+ added.push(row.id);
48
+ continue;
49
+ }
50
+ const fields = changedKeys(previous.fields, row.fields);
51
+ if (fields.length > 0)
52
+ changed.push({ id: row.id, fields });
53
+ }
54
+ return {
55
+ added,
56
+ changed,
57
+ removed: before.filter((row) => !afterIds.has(row.id)).map((row) => row.id),
58
+ };
59
+ }
60
+ function sameAttachment(left, right) {
61
+ return (left.contentSha256 === right.contentSha256 &&
62
+ left.name === right.name &&
63
+ left.byteLength === right.byteLength &&
64
+ left.mimeType === right.mimeType);
65
+ }
66
+ function compareAttachments(before, after) {
67
+ const beforeBySlot = new Map(before.map((item) => [item.slotId, item]));
68
+ const afterSlots = new Set(after.map((item) => item.slotId));
69
+ const added = [];
70
+ const replaced = [];
71
+ for (const attachment of after) {
72
+ const previous = beforeBySlot.get(attachment.slotId);
73
+ if (previous === undefined) {
74
+ added.push(attachment.slotId);
75
+ }
76
+ else if (!sameAttachment(previous, attachment)) {
77
+ replaced.push(attachment.slotId);
78
+ }
79
+ }
80
+ return {
81
+ added,
82
+ removed: before
83
+ .filter((item) => !afterSlots.has(item.slotId))
84
+ .map((item) => item.slotId),
85
+ replaced,
86
+ };
87
+ }
88
+ /** Compare a version with the one before it. Pure. */
89
+ export function compareDocumentHistoryContent(before, after) {
90
+ return {
91
+ attachments: compareAttachments(before.attachments, after.attachments),
92
+ fields: changedKeys(before.structuredFields, after.structuredFields),
93
+ kindChanged: before.documentKind !== after.documentKind,
94
+ rows: compareRows(before.rows, after.rows),
95
+ text: compareTextChange(before.text, after.text),
96
+ };
97
+ }
98
+ /** Whether a step changed anything a reader of the document would see. */
99
+ export function isEmptyDocumentHistoryChange(change) {
100
+ return (!change.kindChanged &&
101
+ change.text === null &&
102
+ change.fields.length === 0 &&
103
+ change.rows.added.length === 0 &&
104
+ change.rows.changed.length === 0 &&
105
+ change.rows.removed.length === 0 &&
106
+ change.attachments.added.length === 0 &&
107
+ change.attachments.removed.length === 0 &&
108
+ change.attachments.replaced.length === 0);
109
+ }
110
+ //# sourceMappingURL=documentHistoryChange.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"documentHistoryChange.js","sourceRoot":"","sources":["documentHistoryChange.ts"],"names":[],"mappings":"AAoDA,SAAS,eAAe,CAAC,QAAgB;IACvC,OAAO,QAAQ,IAAI,MAAM,IAAI,QAAQ,IAAI,MAAM,CAAC;AAClD,CAAC;AAED,SAAS,cAAc,CAAC,QAAgB;IACtC,OAAO,QAAQ,IAAI,MAAM,IAAI,QAAQ,IAAI,MAAM,CAAC;AAClD,CAAC;AAED,SAAS,iBAAiB,CACxB,MAAc,EACd,KAAa;IAEb,IAAI,MAAM,KAAK,KAAK;QAAE,OAAO,IAAI,CAAC;IAClC,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACtD,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,OACE,KAAK,GAAG,OAAO;QACf,MAAM,C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} from \"../../../data/documents/documentKinds\";\nimport type { DocumentRow } from \"../../../data/documents/documentRowList\";\n\n/** The parts of a document that its history can change. */\nexport interface DocumentHistoryContent {\n readonly attachments: ReadonlyArray<DocumentAttachment>;\n readonly documentKind: StoredDocumentKind;\n readonly rows: ReadonlyArray<DocumentRow>;\n readonly structuredFields: Readonly<Record<string, string>>;\n readonly text: string;\n}\n\n/**\n * The one region of text that differs between two versions, in UTF-16 units\n * of the newer text. Edits in several places are reported as the single region\n * that spans them.\n */\nexport interface DocumentHistoryTextChange {\n /** Where the region starts, in both the older and the newer text. */\n readonly start: number;\n /** Length of the region in the newer text. */\n readonly insertedLength: number;\n /** Length of the region it replaced in the older text. */\n readonly removedLength: number;\n}\n\nexport interface DocumentHistoryRowChange {\n readonly id: string;\n /** Cells whose value was set, changed, or cleared, in key order. */\n readonly fields: ReadonlyArray<string>;\n}\n\n/** What one step of history changed, compared with the step before it. */\nexport interface DocumentHistoryChange {\n readonly attachments: {\n readonly added: ReadonlyArray<string>;\n readonly removed: ReadonlyArray<string>;\n /** Slots that kept their place but now hold different bytes or a new name. */\n readonly replaced: ReadonlyArray<string>;\n };\n /** Structured fields set, changed, or cleared, in key order. */\n readonly fields: ReadonlyArray<string>;\n readonly kindChanged: boolean;\n readonly rows: {\n readonly added: ReadonlyArray<string>;\n readonly changed: ReadonlyArray<DocumentHistoryRowChange>;\n readonly removed: ReadonlyArray<string>;\n };\n readonly text: DocumentHistoryTextChange | null;\n}\n\nfunction isHighSurrogate(codeUnit: number): boolean {\n return codeUnit >= 0xd800 && codeUnit <= 0xdbff;\n}\n\nfunction isLowSurrogate(codeUnit: number): boolean {\n return codeUnit >= 0xdc00 && codeUnit <= 0xdfff;\n}\n\nfunction compareTextChange(\n before: string,\n after: string,\n): DocumentHistoryTextChange | null {\n if (before === after) return null;\n const shorter = Math.min(before.length, after.length);\n let start = 0;\n while (\n start < shorter &&\n before.charCodeAt(start) === after.charCodeAt(start)\n ) {\n start += 1;\n }\n // Keep a shared high surrogate with the differing low surrogate after it.\n if (start > 0 && isHighSurrogate(before.charCodeAt(start - 1))) start -= 1;\n let shared = 0;\n while (\n shared < shorter - start &&\n before.charCodeAt(before.length - 1 - shared) ===\n after.charCodeAt(after.length - 1 - shared)\n ) {\n shared += 1;\n }\n // Keep a shared low surrogate with the differing high surrogate before it.\n if (shared > 0 && isLowSurrogate(before.charCodeAt(before.length - shared))) {\n shared -= 1;\n }\n return {\n start,\n insertedLength: after.length - shared - start,\n removedLength: before.length - shared - start,\n };\n}\n\nfunction changedKeys(\n before: Readonly<Record<string, string>>,\n after: Readonly<Record<string, string>>,\n): string[] {\n const keys = new Set([...Object.keys(before), ...Object.keys(after)]);\n return [...keys].filter((key) => before[key] !== after[key]).sort();\n}\n\nfunction compareRows(\n before: ReadonlyArray<DocumentRow>,\n after: ReadonlyArray<DocumentRow>,\n): DocumentHistoryChange[\"rows\"] {\n const beforeById = new Map(before.map((row) => [row.id, row]));\n const afterIds = new Set(after.map((row) => row.id));\n const added: string[] = [];\n const changed: DocumentHistoryRowChange[] = [];\n for (const row of after) {\n const previous = beforeById.get(row.id);\n if (previous === undefined) {\n added.push(row.id);\n continue;\n }\n const fields = changedKeys(previous.fields, row.fields);\n if (fields.length > 0) changed.push({ id: row.id, fields });\n }\n return {\n added,\n changed,\n removed: before.filter((row) => !afterIds.has(row.id)).map((row) => row.id),\n };\n}\n\nfunction sameAttachment(\n left: DocumentAttachment,\n right: DocumentAttachment,\n): boolean {\n return (\n left.contentSha256 === right.contentSha256 &&\n left.name === right.name &&\n left.byteLength === right.byteLength &&\n left.mimeType === right.mimeType\n );\n}\n\nfunction compareAttachments(\n before: ReadonlyArray<DocumentAttachment>,\n after: ReadonlyArray<DocumentAttachment>,\n): DocumentHistoryChange[\"attachments\"] {\n const beforeBySlot = new Map(before.map((item) => [item.slotId, item]));\n const afterSlots = new Set(after.map((item) => item.slotId));\n const added: string[] = [];\n const replaced: string[] = [];\n for (const attachment of after) {\n const previous = beforeBySlot.get(attachment.slotId);\n if (previous === undefined) {\n added.push(attachment.slotId);\n } else if (!sameAttachment(previous, attachment)) {\n replaced.push(attachment.slotId);\n }\n }\n return {\n added,\n removed: before\n .filter((item) => !afterSlots.has(item.slotId))\n .map((item) => item.slotId),\n replaced,\n };\n}\n\n/** Compare a version with the one before it. Pure. */\nexport function compareDocumentHistoryContent(\n before: DocumentHistoryContent,\n after: DocumentHistoryContent,\n): DocumentHistoryChange {\n return {\n attachments: compareAttachments(before.attachments, after.attachments),\n fields: changedKeys(before.structuredFields, after.structuredFields),\n kindChanged: before.documentKind !== after.documentKind,\n rows: compareRows(before.rows, after.rows),\n text: compareTextChange(before.text, after.text),\n };\n}\n\n/** Whether a step changed anything a reader of the document would see. */\nexport function isEmptyDocumentHistoryChange(\n change: DocumentHistoryChange,\n): boolean {\n return (\n !change.kindChanged &&\n change.text === null &&\n change.fields.length === 0 &&\n change.rows.added.length === 0 &&\n change.rows.changed.length === 0 &&\n change.rows.removed.length === 0 &&\n change.attachments.added.length === 0 &&\n change.attachments.removed.length === 0 &&\n change.attachments.replaced.length === 0\n );\n}\n"]}
@@ -15,6 +15,8 @@ export { runSerializedDocumentBlobMutation } from "./attachments/blobMutationLoc
15
15
  export { reclaimDocumentOrphanBlobs } from "./attachments/orphanBlobReclaims.js";
16
16
  export { resolveDocumentCreateAuthor } from "./author.js";
17
17
  export { buildMaterializedDocumentCreatePlan, createRemoteDocument, documentWriterProjectionFromCreateResponse, } from "./create/index.js";
18
+ export { type DocumentHistory, type DocumentHistoryStop, type DocumentHistoryVersion, type DocumentHistoryVersionEntry, type DocumentHistoryView, openDocumentHistory, } from "./history/documentHistory.js";
19
+ export { type DocumentHistoryChange, type DocumentHistoryRowChange, type DocumentHistoryTextChange, isEmptyDocumentHistoryChange, } from "./history/documentHistoryChange.js";
18
20
  export { importDocumentHistoryTailUpdates, loadPersistedDocumentContent, mergePersistedDocumentHistory, } from "./historyContent.js";
19
21
  export { buildMaterializedDocumentLinkSetMutationPlan } from "./linkSet/index.js";
20
22
  export { createLinkSetAttachmentReuse, type LinkSetAttachmentReuse, } from "./linkSet/linkSetBlobRewraps.js";
@@ -13,6 +13,8 @@ export { runSerializedDocumentBlobMutation } from "./attachments/blobMutationLoc
13
13
  export { reclaimDocumentOrphanBlobs } from "./attachments/orphanBlobReclaims.js";
14
14
  export { resolveDocumentCreateAuthor } from "./author.js";
15
15
  export { buildMaterializedDocumentCreatePlan, createRemoteDocument, documentWriterProjectionFromCreateResponse, } from "./create/index.js";
16
+ export { openDocumentHistory, } from "./history/documentHistory.js";
17
+ export { isEmptyDocumentHistoryChange, } from "./history/documentHistoryChange.js";
16
18
  export { importDocumentHistoryTailUpdates, loadPersistedDocumentContent, mergePersistedDocumentHistory, } from "./historyContent.js";
17
19
  export { buildMaterializedDocumentLinkSetMutationPlan } from "./linkSet/index.js";
18
20
  export { createLinkSetAttachmentReuse, } from "./linkSet/linkSetBlobRewraps.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,8BAA8B,GAC/B,MAAM,wCAAwC,CAAC;AAChD,OAAO,EAAE,wCAAwC,EAAE,MAAM,uCAAuC,CAAC;AACjG,OAAO,EAAE,sBAAsB,EAAE,MAAM,8CAA8C,CAAC;AACtF,OAAO,EAAE,+BAA+B,EAAE,MAAM,4DAA4D,CAAC;AAC7G,OAAO,EAGL,kCAAkC,EAClC,iCAAiC,GAClC,MAAM,8DAA8D,CAAC;AACtE,OAAO,EAEL,kCAAkC,EAClC,oBAAoB,GACrB,MAAM,iDAAiD,CAAC;AAQzD,OAAO,EACL,wBAAwB,EACxB,sCAAsC,EACtC,yBAAyB,GAC1B,MAAM,0CAA0C,CAAC;AAClD,OAAO,EACL,qCAAqC,EACrC,oCAAoC,GACrC,MAAM,qEAAqE,CAAC;AAE7E,OAAO,EAAE,gCAAgC,EAAE,MAAM,0CAA0C,CAAC;AAC5F,OAAO,EAC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AiB,CAAC;AACzB,OAAO,EACL,4BAA4B,EAC5B,2BAA2B,GAC5B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,mCAAmC,EACnC,iCAAiC,GAElC,MAAM,0CAA0C,CAAC;AAClD,OAAO,EAAE,uCAAuC,EAAE,MAAM,qCAAqC,CAAC;AAC9F,OAAO,EAAE,kCAAkC,EAAE,MAAM,4BAA4B,CAAC;AAEhF,OAAO,EAAE,qCAAqC,EAAE,MAAM,cAAc,CAAC","sourcesContent":["export {\n unwrapContainerKekPath,\n unwrapDocumentContentKeyTarget,\n} from \"../../data/documents/shared/projection\";\nexport { persistedDocumentCreateStateFromResponse } from \"../../data/documents/shared/responses\";\nexport { deriveStableDocumentId } from \"../../data/documents/shared/stableDocumentId\";\nexport { selectDocumentSyncOutgoingBatch } from \"../../data/documents/shared/sync/documentSyncOutgoingBatch\";\nexport {\n type DocumentSyncUpdateIsolationError,\n type IncomingDocumentSyncUpdateValidator,\n isDocumentSyncUpdateIsolationError,\n validateDocumentSyncUpdateImports,\n} from \"../../data/documents/shared/sync/documentSyncUpdateIsolation\";\nexport {\n type DocumentSyncPullContinuation,\n documentSyncPullContinuationsEqual,\n readPullContinuation,\n} from \"../../data/documents/shared/sync/syncPagination\";\nexport type {\n DocumentCreateAuthor,\n DocumentLinkSetFailureHandler,\n DocumentLinkSetMutationFailure,\n DocumentRotationProofMode,\n RelinkRemoteDocumentResult,\n} from \"../../data/documents/shared/types\";\nexport {\n clearDocumentSyncFailure,\n invalidateDocumentSyncPullContinuation,\n recordDocumentSyncFailure,\n} from \"../../data/persistence/documents/records\";\nexport {\n DOCUMENT_HISTORY_COMPACTION_MAX_BYTES,\n DOCUMENT_HISTORY_COMPACTION_MAX_ROWS,\n} from \"../../data/persistence/documents/records/documentHistoryPersistence\";\nexport type { ExecSql } from \"../../data/sqlite/sqlSchema\";\nexport { settleOutgoingPassAndDecideReArm } from \"../../data/sync/outgoingUpdateSettlement\";\nexport {\n didRegainSyncPrerequisites,\n isDatabaseUnavailableError,\n} from \"../../data/sync/syncCoordinator\";\nexport {\n deleteLocalDocumentAttachment,\n deletePendingDocumentAttachment,\n markLocalDocumentAttachmentDetached,\n saveLocalDocumentAttachments,\n savePendingDocumentAttachment,\n} from \"./attachments/attachmentPersistence\";\nexport { runSerializedDocumentBlobMutation } from \"./attachments/blobMutationLock\";\nexport { reclaimDocumentOrphanBlobs } from \"./attachments/orphanBlobReclaims\";\nexport { resolveDocumentCreateAuthor } from \"./author\";\nexport {\n buildMaterializedDocumentCreatePlan,\n createRemoteDocument,\n documentWriterProjectionFromCreateResponse,\n} from \"./create\";\nexport {\n importDocumentHistoryTailUpdates,\n loadPersistedDocumentContent,\n mergePersistedDocumentHistory,\n} from \"./historyContent\";\nexport { buildMaterializedDocumentLinkSetMutationPlan } from \"./linkSet\";\nexport {\n createLinkSetAttachmentReuse,\n type LinkSetAttachmentReuse,\n} from \"./linkSet/linkSetBlobRewraps\";\nexport {\n enqueuePendingDocumentUpdate,\n listPendingDocumentUpdates,\n} from \"./pendingUpdatePersistence\";\nexport {\n type AttachmentRemovalRows,\n type AttachmentStagingRows,\n DOCUMENTS_APP_KIND,\n type DocumentBirthResult,\n type DocumentRecord,\n type DocumentsPersistence,\n defaultDocumentsPersistence,\n type LocalAttachmentRecord,\n loadPersistedDocumentStoreState,\n type PendingAttachmentRecord,\n type PendingAttachmentUploadIdentity,\n type PendingUpdateInsert,\n type PendingUpdateRecord,\n persistDocumentState,\n type QueuedPendingUpdateRecord,\n type RelinkPersistedDocumentInput,\n runSerializedSqlMutation,\n} from \"./persistence\";\nexport {\n createDocumentProjectionUserKeyResolver,\n type DocumentProjectionKeyRuntime,\n type DocumentProjectionUserKeyResolver,\n didDocumentProjectionKeyRuntimeChange,\n} from \"./projectionKeys\";\nexport { buildDocumentPurgeRequest } from \"./purge\";\nexport {\n type DiscardedDocumentShellResult,\n deletePersistedDocument,\n discardPersistedDocumentToShell,\n} from \"./purge/persistedDocumentRemoval\";\nexport type { RemoteDocumentServiceApi } from \"./remote/remoteDocumentCollaborators\";\nexport { RemoteDocumentService } from \"./remote/remoteDocumentService\";\nexport {\n createDocumentsWorkflowRuntime,\n type DocumentsWorkflowRuntime,\n type DocumentsWorkflowRuntimeGroups,\n type DocumentsWorkflowRuntimeInfra,\n type DocumentsWorkflowRuntimeInput,\n type DocumentsWorkflowRuntimeInputGroups,\n} from \"./runtime\";\nexport { syncRemoteDocument } from \"./sync\";\nexport { documentCreateSeedCandidate } from \"./sync/initialSync\";\nexport type { SyncRemoteDocumentInput } from \"./sync/readOnlySync\";\nexport type { DocumentSyncContainerRekeyBuilder } from \"./sync/syncAttemptState\";\nexport {\n type DocumentSyncLane,\n registerDocumentSyncLane,\n requestDocumentSyncLaneAndWait,\n} from \"./sync/syncLane\";\nexport {\n DOCUMENT_SYNC_TRACE_FRAGMENT,\n DOCUMENT_SYNC_TRACE_PATTERN,\n} from \"./sync/syncTrace\";\nexport {\n describeDocumentRevalidationFailure,\n describeDocumentSyncSubmitFailure,\n type TerminalSubmitFailureHandler,\n} from \"./syncFailures/syncFailureClassification\";\nexport { shouldClearDocumentSyncFailureAfterPass } from \"./syncFailures/syncFailureClearance\";\nexport { DocumentRawHistoryUnavailableError } from \"./syncPlan/syncContentKeys\";\nexport type { RekeyPendingUpdate } from \"./syncRekeys/syncRecoveryRekey\";\nexport { createDocumentWriterPublicKeyResolver } from \"./writerKeys\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,8BAA8B,GAC/B,MAAM,wCAAwC,CAAC;AAChD,OAAO,EAAE,wCAAwC,EAAE,MAAM,uCAAuC,CAAC;AACjG,OAAO,EAAE,sBAAsB,EAAE,MAAM,8CAA8C,CAAC;AACtF,OAAO,EAAE,+BAA+B,EAAE,MAAM,4DAA4D,CAAC;AAC7G,OAAO,EAGL,kCAAkC,EAClC,iCAAiC,GAClC,MAAM,8DAA8D,CAAC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AAC;AAC1B,OAAO,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAC;AACpD,OAAO,EAEL,uBAAuB,EACvB,+BAA+B,GAChC,MAAM,kCAAkC,CAAC;AAE1C,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AACvE,OAAO,EACL,8BAA8B,GAM/B,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,kBAAkB,EAAE,MAAM,QAAQ,CAAC;AAC5C,OAAO,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AAGjE,OAAO,EAEL,wBAAwB,EACxB,8BAA8B,GAC/B,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,4BAA4B,EAC5B,2BAA2B,GAC5B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,mCAAmC,EACnC,iCAAiC,GAElC,MAAM,0CAA0C,CAAC;AAClD,OAAO,EAAE,uCAAuC,EAAE,MAAM,qCAAqC,CAAC;AAC9F,OAAO,EAAE,kCAAkC,EAAE,MAAM,4BAA4B,CAAC;AAEhF,OAAO,EAAE,qCAAqC,EAAE,MAAM,cAAc,CAAC","sourcesContent":["export {\n unwrapContainerKekPath,\n unwrapDocumentContentKeyTarget,\n} from \"../../data/documents/shared/projection\";\nexport { persistedDocumentCreateStateFromResponse } from \"../../data/documents/shared/responses\";\nexport { deriveStableDocumentId } from \"../../data/documents/shared/stableDocumentId\";\nexport { selectDocumentSyncOutgoingBatch } from \"../../data/documents/shared/sync/documentSyncOutgoingBatch\";\nexport {\n type DocumentSyncUpdateIsolationError,\n type IncomingDocumentSyncUpdateValidator,\n isDocumentSyncUpdateIsolationError,\n validateDocumentSyncUpdateImports,\n} from \"../../data/documents/shared/sync/documentSyncUpdateIsolation\";\nexport {\n type DocumentSyncPullContinuation,\n documentSyncPullContinuationsEqual,\n readPullContinuation,\n} from \"../../data/documents/shared/sync/syncPagination\";\nexport type {\n DocumentCreateAuthor,\n DocumentLinkSetFailureHandler,\n DocumentLinkSetMutationFailure,\n DocumentRotationProofMode,\n RelinkRemoteDocumentResult,\n} from \"../../data/documents/shared/types\";\nexport {\n clearDocumentSyncFailure,\n invalidateDocumentSyncPullContinuation,\n recordDocumentSyncFailure,\n} from \"../../data/persistence/documents/records\";\nexport {\n DOCUMENT_HISTORY_COMPACTION_MAX_BYTES,\n DOCUMENT_HISTORY_COMPACTION_MAX_ROWS,\n} from \"../../data/persistence/documents/records/documentHistoryPersistence\";\nexport type { ExecSql } from \"../../data/sqlite/sqlSchema\";\nexport { settleOutgoingPassAndDecideReArm } from \"../../data/sync/outgoingUpdateSettlement\";\nexport {\n didRegainSyncPrerequisites,\n isDatabaseUnavailableError,\n} from \"../../data/sync/syncCoordinator\";\nexport {\n deleteLocalDocumentAttachment,\n deletePendingDocumentAttachment,\n markLocalDocumentAttachmentDetached,\n saveLocalDocumentAttachments,\n savePendingDocumentAttachment,\n} from \"./attachments/attachmentPersistence\";\nexport { runSerializedDocumentBlobMutation } from \"./attachments/blobMutationLock\";\nexport { reclaimDocumentOrphanBlobs } from \"./attachments/orphanBlobReclaims\";\nexport { resolveDocumentCreateAuthor } from \"./author\";\nexport {\n buildMaterializedDocumentCreatePlan,\n createRemoteDocument,\n documentWriterProjectionFromCreateResponse,\n} from \"./create\";\nexport {\n type DocumentHistory,\n type DocumentHistoryStop,\n type DocumentHistoryVersion,\n type DocumentHistoryVersionEntry,\n type DocumentHistoryView,\n openDocumentHistory,\n} from \"./history/documentHistory\";\nexport {\n type DocumentHistoryChange,\n type DocumentHistoryRowChange,\n type DocumentHistoryTextChange,\n isEmptyDocumentHistoryChange,\n} from \"./history/documentHistoryChange\";\nexport {\n importDocumentHistoryTailUpdates,\n loadPersistedDocumentContent,\n mergePersistedDocumentHistory,\n} from \"./historyContent\";\nexport { buildMaterializedDocumentLinkSetMutationPlan } from \"./linkSet\";\nexport {\n createLinkSetAttachmentReuse,\n type LinkSetAttachmentReuse,\n} from \"./linkSet/linkSetBlobRewraps\";\nexport {\n enqueuePendingDocumentUpdate,\n listPendingDocumentUpdates,\n} from \"./pendingUpdatePersistence\";\nexport {\n type AttachmentRemovalRows,\n type AttachmentStagingRows,\n DOCUMENTS_APP_KIND,\n type DocumentBirthResult,\n type DocumentRecord,\n type DocumentsPersistence,\n defaultDocumentsPersistence,\n type LocalAttachmentRecord,\n loadPersistedDocumentStoreState,\n type PendingAttachmentRecord,\n type PendingAttachmentUploadIdentity,\n type PendingUpdateInsert,\n type PendingUpdateRecord,\n persistDocumentState,\n type QueuedPendingUpdateRecord,\n type RelinkPersistedDocumentInput,\n runSerializedSqlMutation,\n} from \"./persistence\";\nexport {\n createDocumentProjectionUserKeyResolver,\n type DocumentProjectionKeyRuntime,\n type DocumentProjectionUserKeyResolver,\n didDocumentProjectionKeyRuntimeChange,\n} from \"./projectionKeys\";\nexport { buildDocumentPurgeRequest } from \"./purge\";\nexport {\n type DiscardedDocumentShellResult,\n deletePersistedDocument,\n discardPersistedDocumentToShell,\n} from \"./purge/persistedDocumentRemoval\";\nexport type { RemoteDocumentServiceApi } from \"./remote/remoteDocumentCollaborators\";\nexport { RemoteDocumentService } from \"./remote/remoteDocumentService\";\nexport {\n createDocumentsWorkflowRuntime,\n type DocumentsWorkflowRuntime,\n type DocumentsWorkflowRuntimeGroups,\n type DocumentsWorkflowRuntimeInfra,\n type DocumentsWorkflowRuntimeInput,\n type DocumentsWorkflowRuntimeInputGroups,\n} from \"./runtime\";\nexport { syncRemoteDocument } from \"./sync\";\nexport { documentCreateSeedCandidate } from \"./sync/initialSync\";\nexport type { SyncRemoteDocumentInput } from \"./sync/readOnlySync\";\nexport type { DocumentSyncContainerRekeyBuilder } from \"./sync/syncAttemptState\";\nexport {\n type DocumentSyncLane,\n registerDocumentSyncLane,\n requestDocumentSyncLaneAndWait,\n} from \"./sync/syncLane\";\nexport {\n DOCUMENT_SYNC_TRACE_FRAGMENT,\n DOCUMENT_SYNC_TRACE_PATTERN,\n} from \"./sync/syncTrace\";\nexport {\n describeDocumentRevalidationFailure,\n describeDocumentSyncSubmitFailure,\n type TerminalSubmitFailureHandler,\n} from \"./syncFailures/syncFailureClassification\";\nexport { shouldClearDocumentSyncFailureAfterPass } from \"./syncFailures/syncFailureClearance\";\nexport { DocumentRawHistoryUnavailableError } from \"./syncPlan/syncContentKeys\";\nexport type { RekeyPendingUpdate } from \"./syncRekeys/syncRecoveryRekey\";\nexport { createDocumentWriterPublicKeyResolver } from \"./writerKeys\";\n"]}
@@ -1,9 +1,9 @@
1
- import { loadOrganizationDataUsageProjection, purgeOrganizationDataUsageProjection, saveOrganizationDataUsageProjection, } from "../../../data/persistence/organizations/organizationDataUsagePersistence.js";
1
+ import { OrganizationDataUsageRepository } from "../../../data/persistence/organizations/organizationDataUsagePersistence.js";
2
2
  import { recordOrganizationPresentationDenials } from "../../../data/persistence/organizations/organizationPresentationDenialPersistence.js";
3
3
  import { captureOrganizationPresentationAccessAttempt, denyOrganizationPresentationAccess, isOrganizationPresentationAccessAttemptCurrent, isOrganizationPresentationAccessReadable, restoreOrganizationPresentationAccess, runOrganizationPresentationMutation, runOrganizationPresentationRead, } from "./organizationPresentationAccessState.js";
4
4
  import { isOrganizationPresentationAccessDeniedFailure } from "./organizationPresentationFailures.js";
5
5
  export async function loadLocalOrganizationDataUsage(input) {
6
- return runOrganizationPresentationRead(input, "usage", () => loadOrganizationDataUsageProjection(input.execSql, input.organizationId, input.requesterUserId));
6
+ return runOrganizationPresentationRead(input, "usage", () => new OrganizationDataUsageRepository(input.execSql).loadOrganizationDataUsageProjection(input.organizationId, input.requesterUserId));
7
7
  }
8
8
  function retainedIfUsageReadable(input, attempt, value) {
9
9
  return isOrganizationPresentationAccessAttemptCurrent(input, attempt) &&
@@ -27,7 +27,7 @@ export async function reconcileOrganizationDataUsage(input) {
27
27
  input.logError?.("Failed to record denied organization data usage", error);
28
28
  }
29
29
  try {
30
- await runOrganizationPresentationMutation(input.execSql, () => purgeOrganizationDataUsageProjection(input.execSql, input.organizationId, input.requesterUserId));
30
+ await runOrganizationPresentationMutation(input.execSql, () => new OrganizationDataUsageRepository(input.execSql).purgeOrganizationDataUsageProjection(input.organizationId, input.requesterUserId));
31
31
  }
32
32
  catch (error) {
33
33
  input.logError?.("Failed to purge denied organization data usage", error);
@@ -46,8 +46,7 @@ export async function reconcileOrganizationDataUsage(input) {
46
46
  return null;
47
47
  }
48
48
  try {
49
- await saveOrganizationDataUsageProjection({
50
- execSql: input.execSql,
49
+ await new OrganizationDataUsageRepository(input.execSql).saveOrganizationDataUsageProjection({
51
50
  requesterUserId: input.requesterUserId,
52
51
  response: result.data,
53
52
  });
@@ -1 +1 @@
1
- {"version":3,"file":"dataUsageReadModel.js","sourceRoot":"","sources":["dataUsageReadModel.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,mCAAmC,EACnC,oCAAoC,EACpC,mCAAmC,GACpC,MAAM,0EAA0E,CAAC;AAClF,OAAO,EAAE,qCAAqC,EAAE,MAAM,mFAAmF,CAAC;AAE1I,OAAO,EACL,4CAA4C,EAC5C,kCAAkC,EAClC,8CAA8C,EAC9C,wCAAwC,EAExC,qCAAqC,EACrC,mCAAmC,EACnC,+BAA+B,GAChC,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAAE,6CAA6C,EAAE,MAAM,oCAAoC,CAAC;AAyBnG,MAAM,CAAC,KAAK,UAAU,8BAA8B,CAClD,KAA2C;IAE3C,OAAO,+BAA+B,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,CAC1D,mCAAmC,CACjC,KAAK,CAAC,OAAO,EACb,KAAK,CAAC,cAAc,EACpB,KAAK,CAAC,eAAe,CACtB,CACF,CAAC;AACJ,CAAC;AAED,SAAS,uBAAuB,CAC9B,KAA2C,EAC3C,OAA8C,EAC9C,KAAQ;IAER,OAAO,8CAA8C,CAAC,KAAK,EAAE,OAAO,CAAC;QACnE,wCAAwC,CAAC,KAAK,EAAE,OAAO,CAAC;QACxD,CAAC,CAAC,KAAK;QACP,CAAC,CAAC,IAAI,CAAC;AACX,CAAC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AC;IAED,IAAI,MAAM,CAAC,IAAI,CAAC,cAAc,KAAK,KAAK,CAAC,cAAc,EAAE,CAAC;QACxD,KAAK,CAAC,QAAQ,EAAE,CACd,yDAAyD,KAAK,CAAC,cAAc,EAAE,CAChF,CAAC;QACF,OAAO,uBAAuB,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;IACxD,CAAC;IAED,OAAO,mCAAmC,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,IAAI,EAAE;QACnE,IAAI,CAAC,8CAA8C,CAAC,KAAK,EAAE,OAAO,CAAC,EAAE,CAAC;YACpE,OAAO,IAAI,CAAC;QACd,CAAC;QACD,IAAI,CAAC;YACH,MAAM,mCAAmC,CAAC;gBACxC,OAAO,EAAE,KAAK,CAAC,OAAO;gBACtB,eAAe,EAAE,KAAK,CAAC,eAAe;gBACtC,QAAQ,EAAE,MAAM,CAAC,IAAI;aACtB,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,KAAK,CAAC,QAAQ,EAAE,CAAC,2CAA2C,EAAE,KAAK,CAAC,CAAC;YACrE,OAAO,uBAAuB,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;QACxD,CAAC;QACD,OAAO,qCAAqC,CAAC,KAAK,EAAE,OAAO,CAAC;YAC1D,CAAC,CAAC,MAAM,CAAC,IAAI;YACb,CAAC,CAAC,IAAI,CAAC;IACX,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type {\n RequestResult,\n RequestResultOptions,\n} from \"@tearleads/api-client\";\nimport type { OrganizationDataUsageResponse } from \"@tearleads/validators/response\";\nimport {\n loadOrganizationDataUsageProjection,\n purgeOrganizationDataUsageProjection,\n saveOrganizationDataUsageProjection,\n} from \"../../../data/persistence/organizations/organizationDataUsagePersistence\";\nimport { recordOrganizationPresentationDenials } from \"../../../data/persistence/organizations/organizationPresentationDenialPersistence\";\nimport type { ExecSql } from \"../../../data/sqlite/sqlSchema\";\nimport {\n captureOrganizationPresentationAccessAttempt,\n denyOrganizationPresentationAccess,\n isOrganizationPresentationAccessAttemptCurrent,\n isOrganizationPresentationAccessReadable,\n type OrganizationPresentationAccessAttempt,\n restoreOrganizationPresentationAccess,\n runOrganizationPresentationMutation,\n runOrganizationPresentationRead,\n} from \"./organizationPresentationAccessState\";\nimport { isOrganizationPresentationAccessDeniedFailure } from \"./organizationPresentationFailures\";\n\nexport type OrganizationDataUsage = OrganizationDataUsageResponse;\n\ninterface OrganizationDataUsageApi {\n getOrganizationDataUsageResult(\n organizationId: string,\n options?: RequestResultOptions,\n ): Promise<RequestResult<OrganizationDataUsageResponse>>;\n}\n\ninterface OrganizationDataUsageProjectionInput {\n readonly execSql: ExecSql;\n readonly organizationId: string;\n readonly requesterUserId: string;\n}\n\nexport interface ReconcileOrganizationDataUsageInput\n extends OrganizationDataUsageProjectionInput {\n readonly apiClient: OrganizationDataUsageApi;\n readonly logError?:\n | ((message: string | Error, cause?: unknown) => void)\n | undefined;\n}\n\nexport async function loadLocalOrganizationDataUsage(\n input: OrganizationDataUsageProjectionInput,\n): Promise<OrganizationDataUsage | null> {\n return runOrganizationPresentationRead(input, \"usage\", () =>\n loadOrganizationDataUsageProjection(\n input.execSql,\n input.organizationId,\n input.requesterUserId,\n ),\n );\n}\n\nfunction retainedIfUsageReadable<T>(\n input: OrganizationDataUsageProjectionInput,\n attempt: OrganizationPresentationAccessAttempt,\n value: T,\n): T | null {\n return isOrganizationPresentationAccessAttemptCurrent(input, attempt) &&\n isOrganizationPresentationAccessReadable(input, \"usage\")\n ? value\n : null;\n}\n\nexport async function reconcileOrganizationDataUsage(\n input: ReconcileOrganizationDataUsageInput,\n): Promise<OrganizationDataUsage | null> {\n const attempt = captureOrganizationPresentationAccessAttempt(input, \"usage\");\n const local = await loadLocalOrganizationDataUsage(input);\n const result = await input.apiClient.getOrganizationDataUsageResult(\n input.organizationId,\n { reportErrors: false },\n );\n if (!result.ok) {\n if (isOrganizationPresentationAccessDeniedFailure(result)) {\n denyOrganizationPresentationAccess(input, [\"usage\"]);\n // Durable marker first: a failed purge plus a restart must not serve\n // the revoked usage projection.\n try {\n await runOrganizationPresentationMutation(input.execSql, () =>\n recordOrganizationPresentationDenials(input, [\"usage\"]),\n );\n } catch (error) {\n input.logError?.(\n \"Failed to record denied organization data usage\",\n error,\n );\n }\n try {\n await runOrganizationPresentationMutation(input.execSql, () =>\n purgeOrganizationDataUsageProjection(\n input.execSql,\n input.organizationId,\n input.requesterUserId,\n ),\n );\n } catch (error) {\n input.logError?.(\n \"Failed to purge denied organization data usage\",\n error,\n );\n }\n return null;\n }\n\n result.report();\n return retainedIfUsageReadable(input, attempt, local);\n }\n\n if (result.data.organizationId !== input.organizationId) {\n input.logError?.(\n `Organization data-usage response scope does not match ${input.organizationId}`,\n );\n return retainedIfUsageReadable(input, attempt, local);\n }\n\n return runOrganizationPresentationMutation(input.execSql, async () => {\n if (!isOrganizationPresentationAccessAttemptCurrent(input, attempt)) {\n return null;\n }\n try {\n await saveOrganizationDataUsageProjection({\n execSql: input.execSql,\n requesterUserId: input.requesterUserId,\n response: result.data,\n });\n } catch (error) {\n input.logError?.(\"Failed to persist organization data usage\", error);\n return retainedIfUsageReadable(input, attempt, local);\n }\n return restoreOrganizationPresentationAccess(input, attempt)\n ? result.data\n : null;\n });\n}\n"]}
1
+ {"version":3,"file":"dataUsageReadModel.js","sourceRoot":"","sources":["dataUsageReadModel.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,+BAA+B,EAAE,MAAM,0EAA0E,CAAC;AAC3H,OAAO,EAAE,qCAAqC,EAAE,MAAM,mFAAmF,CAAC;AAE1I,OAAO,EACL,4CAA4C,EAC5C,kCAAkC,EAClC,8CAA8C,EAC9C,wCAAwC,EAExC,qCAAqC,EACrC,mCAAmC,EACnC,+BAA+B,GAChC,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAAE,6CAA6C,EAAE,MAAM,oCAAoC,CAAC;AAyBnG,MAAM,CA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,OAAO,EAAE,KAAK,CAAC,CAAC;QACxD,CAAC;QACD,OAAO,qCAAqC,CAAC,KAAK,EAAE,OAAO,CAAC;YAC1D,CAAC,CAAC,MAAM,CAAC,IAAI;YACb,CAAC,CAAC,IAAI,CAAC;IACX,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type {\n RequestResult,\n RequestResultOptions,\n} from \"@tearleads/api-client\";\nimport type { OrganizationDataUsageResponse } from \"@tearleads/validators/response\";\nimport { OrganizationDataUsageRepository } from \"../../../data/persistence/organizations/organizationDataUsagePersistence\";\nimport { recordOrganizationPresentationDenials } from \"../../../data/persistence/organizations/organizationPresentationDenialPersistence\";\nimport type { ExecSql } from \"../../../data/sqlite/sqlSchema\";\nimport {\n captureOrganizationPresentationAccessAttempt,\n denyOrganizationPresentationAccess,\n isOrganizationPresentationAccessAttemptCurrent,\n isOrganizationPresentationAccessReadable,\n type OrganizationPresentationAccessAttempt,\n restoreOrganizationPresentationAccess,\n runOrganizationPresentationMutation,\n runOrganizationPresentationRead,\n} from \"./organizationPresentationAccessState\";\nimport { isOrganizationPresentationAccessDeniedFailure } from \"./organizationPresentationFailures\";\n\nexport type OrganizationDataUsage = OrganizationDataUsageResponse;\n\ninterface OrganizationDataUsageApi {\n getOrganizationDataUsageResult(\n organizationId: string,\n options?: RequestResultOptions,\n ): Promise<RequestResult<OrganizationDataUsageResponse>>;\n}\n\ninterface OrganizationDataUsageProjectionInput {\n readonly execSql: ExecSql;\n readonly organizationId: string;\n readonly requesterUserId: string;\n}\n\nexport interface ReconcileOrganizationDataUsageInput\n extends OrganizationDataUsageProjectionInput {\n readonly apiClient: OrganizationDataUsageApi;\n readonly logError?:\n | ((message: string | Error, cause?: unknown) => void)\n | undefined;\n}\n\nexport async function loadLocalOrganizationDataUsage(\n input: OrganizationDataUsageProjectionInput,\n): Promise<OrganizationDataUsage | null> {\n return runOrganizationPresentationRead(input, \"usage\", () =>\n new OrganizationDataUsageRepository(\n input.execSql,\n ).loadOrganizationDataUsageProjection(\n input.organizationId,\n input.requesterUserId,\n ),\n );\n}\n\nfunction retainedIfUsageReadable<T>(\n input: OrganizationDataUsageProjectionInput,\n attempt: OrganizationPresentationAccessAttempt,\n value: T,\n): T | null {\n return isOrganizationPresentationAccessAttemptCurrent(input, attempt) &&\n isOrganizationPresentationAccessReadable(input, \"usage\")\n ? value\n : null;\n}\n\nexport async function reconcileOrganizationDataUsage(\n input: ReconcileOrganizationDataUsageInput,\n): Promise<OrganizationDataUsage | null> {\n const attempt = captureOrganizationPresentationAccessAttempt(input, \"usage\");\n const local = await loadLocalOrganizationDataUsage(input);\n const result = await input.apiClient.getOrganizationDataUsageResult(\n input.organizationId,\n { reportErrors: false },\n );\n if (!result.ok) {\n if (isOrganizationPresentationAccessDeniedFailure(result)) {\n denyOrganizationPresentationAccess(input, [\"usage\"]);\n // Durable marker first: a failed purge plus a restart must not serve\n // the revoked usage projection.\n try {\n await runOrganizationPresentationMutation(input.execSql, () =>\n recordOrganizationPresentationDenials(input, [\"usage\"]),\n );\n } catch (error) {\n input.logError?.(\n \"Failed to record denied organization data usage\",\n error,\n );\n }\n try {\n await runOrganizationPresentationMutation(input.execSql, () =>\n new OrganizationDataUsageRepository(\n input.execSql,\n ).purgeOrganizationDataUsageProjection(\n input.organizationId,\n input.requesterUserId,\n ),\n );\n } catch (error) {\n input.logError?.(\n \"Failed to purge denied organization data usage\",\n error,\n );\n }\n return null;\n }\n\n result.report();\n return retainedIfUsageReadable(input, attempt, local);\n }\n\n if (result.data.organizationId !== input.organizationId) {\n input.logError?.(\n `Organization data-usage response scope does not match ${input.organizationId}`,\n );\n return retainedIfUsageReadable(input, attempt, local);\n }\n\n return runOrganizationPresentationMutation(input.execSql, async () => {\n if (!isOrganizationPresentationAccessAttemptCurrent(input, attempt)) {\n return null;\n }\n try {\n await new OrganizationDataUsageRepository(\n input.execSql,\n ).saveOrganizationDataUsageProjection({\n requesterUserId: input.requesterUserId,\n response: result.data,\n });\n } catch (error) {\n input.logError?.(\"Failed to persist organization data usage\", error);\n return retainedIfUsageReadable(input, attempt, local);\n }\n return restoreOrganizationPresentationAccess(input, attempt)\n ? result.data\n : null;\n });\n}\n"]}