mindoodb 0.3.0 → 0.3.2

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 (57) hide show
  1. package/dist/appendonlystores/network/ServerNetworkContentAddressedStore.d.ts +19 -0
  2. package/dist/appendonlystores/network/ServerNetworkContentAddressedStore.d.ts.map +1 -1
  3. package/dist/appendonlystores/network/ServerNetworkContentAddressedStore.js +88 -5
  4. package/dist/appendonlystores/network/ServerNetworkContentAddressedStore.js.map +1 -1
  5. package/dist/browser/index.mjs +20 -0
  6. package/dist/core/BaseMindooTenantDirectory.d.ts +12 -1
  7. package/dist/core/BaseMindooTenantDirectory.d.ts.map +1 -1
  8. package/dist/core/BaseMindooTenantDirectory.js +27 -4
  9. package/dist/core/BaseMindooTenantDirectory.js.map +1 -1
  10. package/dist/core/activity/ActivityIndex.d.ts +80 -0
  11. package/dist/core/activity/ActivityIndex.d.ts.map +1 -0
  12. package/dist/core/activity/ActivityIndex.js +402 -0
  13. package/dist/core/activity/ActivityIndex.js.map +1 -0
  14. package/dist/core/activity/MemoryActivityTable.d.ts +52 -0
  15. package/dist/core/activity/MemoryActivityTable.d.ts.map +1 -0
  16. package/dist/core/activity/MemoryActivityTable.js +196 -0
  17. package/dist/core/activity/MemoryActivityTable.js.map +1 -0
  18. package/dist/core/activity/SqliteActivityTable.d.ts +41 -0
  19. package/dist/core/activity/SqliteActivityTable.d.ts.map +1 -0
  20. package/dist/core/activity/SqliteActivityTable.js +302 -0
  21. package/dist/core/activity/SqliteActivityTable.js.map +1 -0
  22. package/dist/core/activity/index.d.ts +7 -0
  23. package/dist/core/activity/index.d.ts.map +1 -0
  24. package/dist/core/activity/index.js +37 -0
  25. package/dist/core/activity/index.js.map +1 -0
  26. package/dist/core/activity/mindoodbActivitySource.d.ts +17 -0
  27. package/dist/core/activity/mindoodbActivitySource.d.ts.map +1 -0
  28. package/dist/core/activity/mindoodbActivitySource.js +44 -0
  29. package/dist/core/activity/mindoodbActivitySource.js.map +1 -0
  30. package/dist/core/activity/summaryRuleClassifier.d.ts +59 -0
  31. package/dist/core/activity/summaryRuleClassifier.d.ts.map +1 -0
  32. package/dist/core/activity/summaryRuleClassifier.js +169 -0
  33. package/dist/core/activity/summaryRuleClassifier.js.map +1 -0
  34. package/dist/core/activity/types.d.ts +230 -0
  35. package/dist/core/activity/types.d.ts.map +1 -0
  36. package/dist/core/activity/types.js +37 -0
  37. package/dist/core/activity/types.js.map +1 -0
  38. package/dist/core/guestAdmissions.d.ts +41 -0
  39. package/dist/core/guestAdmissions.d.ts.map +1 -1
  40. package/dist/core/guestAdmissions.js +81 -1
  41. package/dist/core/guestAdmissions.js.map +1 -1
  42. package/dist/core/index.d.ts +2 -1
  43. package/dist/core/index.d.ts.map +1 -1
  44. package/dist/core/index.js +6 -1
  45. package/dist/core/index.js.map +1 -1
  46. package/dist/guest/guestChat.d.ts +79 -0
  47. package/dist/guest/guestChat.d.ts.map +1 -0
  48. package/dist/guest/guestChat.js +297 -0
  49. package/dist/guest/guestChat.js.map +1 -0
  50. package/dist/guest/index.d.ts +1 -0
  51. package/dist/guest/index.d.ts.map +1 -1
  52. package/dist/guest/index.js +3 -1
  53. package/dist/guest/index.js.map +1 -1
  54. package/dist/server/TenantManager.d.ts.map +1 -1
  55. package/dist/server/TenantManager.js +1 -0
  56. package/dist/server/TenantManager.js.map +1 -1
  57. package/package.json +1 -1
@@ -0,0 +1,17 @@
1
+ import type { MindooDB } from "../types";
2
+ import type { ActivitySource } from "./ActivityIndex";
3
+ import type { ActivityFieldReader } from "./summaryRuleClassifier";
4
+ /**
5
+ * The store of `db` as an {@link ActivitySource}: metadata scan in receipt
6
+ * order, and the tenant's KeyBag for what the reader may see.
7
+ */
8
+ export declare function createMindooDBActivitySource(db: MindooDB): ActivitySource;
9
+ /**
10
+ * Reads summary fields of `db` for rule classifiers: from the summary buffer
11
+ * (no document is loaded). The summary must include the fields the rules use
12
+ * (see `activityRuleFields`).
13
+ */
14
+ export declare function createSummaryFieldReader(db: MindooDB): ActivityFieldReader;
15
+ /** Brings the summary of `db` up to date before an activity run classifies documents. */
16
+ export declare function summaryPrepare(db: MindooDB): () => Promise<void>;
17
+ //# sourceMappingURL=mindoodbActivitySource.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mindoodbActivitySource.d.ts","sourceRoot":"","sources":["../../../src/core/activity/mindoodbActivitySource.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAEnE;;;GAGG;AACH,wBAAgB,4BAA4B,CAAC,EAAE,EAAE,QAAQ,GAAG,cAAc,CAWzE;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,EAAE,EAAE,QAAQ,GAAG,mBAAmB,CAQ1E;AAED,yFAAyF;AACzF,wBAAgB,cAAc,CAAC,EAAE,EAAE,QAAQ,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,CAIhE"}
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createMindooDBActivitySource = createMindooDBActivitySource;
4
+ exports.createSummaryFieldReader = createSummaryFieldReader;
5
+ exports.summaryPrepare = summaryPrepare;
6
+ /**
7
+ * The store of `db` as an {@link ActivitySource}: metadata scan in receipt
8
+ * order, and the tenant's KeyBag for what the reader may see.
9
+ */
10
+ function createMindooDBActivitySource(db) {
11
+ const store = db.getStore();
12
+ const tenant = db.getTenant();
13
+ if (typeof store.scanEntriesSince !== "function") {
14
+ throw new Error(`The store of database "${store.getId()}" cannot scan its entries.`);
15
+ }
16
+ return {
17
+ scan: (cursor, limit) => store.scanEntriesSince(cursor, limit),
18
+ epoch: async () => (store.getStoreHead ? (await store.getStoreHead()).epoch : null),
19
+ hasKey: async (keyId) => (tenant.hasDecryptionKey ? tenant.hasDecryptionKey(keyId) : keyId === "default"),
20
+ };
21
+ }
22
+ /**
23
+ * Reads summary fields of `db` for rule classifiers: from the summary buffer
24
+ * (no document is loaded). The summary must include the fields the rules use
25
+ * (see `activityRuleFields`).
26
+ */
27
+ function createSummaryFieldReader(db) {
28
+ return async (docIds) => {
29
+ const summary = db.getSummaryStore?.();
30
+ const result = new Map();
31
+ if (!summary)
32
+ return result;
33
+ for (const [docId, entry] of await summary.getEntries(docIds))
34
+ result.set(docId, entry.fields);
35
+ return result;
36
+ };
37
+ }
38
+ /** Brings the summary of `db` up to date before an activity run classifies documents. */
39
+ function summaryPrepare(db) {
40
+ return async () => {
41
+ await db.getSummaryStore?.().update();
42
+ };
43
+ }
44
+ //# sourceMappingURL=mindoodbActivitySource.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mindoodbActivitySource.js","sourceRoot":"","sources":["../../../src/core/activity/mindoodbActivitySource.ts"],"names":[],"mappings":";;AAQA,oEAWC;AAOD,4DAQC;AAGD,wCAIC;AArCD;;;GAGG;AACH,SAAgB,4BAA4B,CAAC,EAAY;IACvD,MAAM,KAAK,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC;IAC5B,MAAM,MAAM,GAAG,EAAE,CAAC,SAAS,EAAE,CAAC;IAC9B,IAAI,OAAO,KAAK,CAAC,gBAAgB,KAAK,UAAU,EAAE,CAAC;QACjD,MAAM,IAAI,KAAK,CAAC,0BAA0B,KAAK,CAAC,KAAK,EAAE,4BAA4B,CAAC,CAAC;IACvF,CAAC;IACD,OAAO;QACL,IAAI,EAAE,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,gBAAiB,CAAC,MAAM,EAAE,KAAK,CAAC;QAC/D,KAAK,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC,YAAY,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;QACnF,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC,CAAC,MAAM,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,KAAK,SAAS,CAAC;KAC1G,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,SAAgB,wBAAwB,CAAC,EAAY;IACnD,OAAO,KAAK,EAAE,MAAM,EAAE,EAAE;QACtB,MAAM,OAAO,GAAG,EAAE,CAAC,eAAe,EAAE,EAAE,CAAC;QACvC,MAAM,MAAM,GAAG,IAAI,GAAG,EAAmC,CAAC;QAC1D,IAAI,CAAC,OAAO;YAAE,OAAO,MAAM,CAAC;QAC5B,KAAK,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,MAAM,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC;YAAE,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;QAC/F,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;AACJ,CAAC;AAED,yFAAyF;AACzF,SAAgB,cAAc,CAAC,EAAY;IACzC,OAAO,KAAK,IAAI,EAAE;QAChB,MAAM,EAAE,CAAC,eAAe,EAAE,EAAE,CAAC,MAAM,EAAE,CAAC;IACxC,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,59 @@
1
+ import type { ActivityClassifier, ActivityFieldEventRule } from "./types";
2
+ /** A field value a rule compares against (strings, numbers, booleans, `null`). */
3
+ export type ActivityMatchValue = string | number | boolean | null;
4
+ /**
5
+ * Which documents a rule applies to: every listed field must have the value
6
+ * (a list means "one of"), and the id must start with `idPrefix` if given.
7
+ */
8
+ export interface ActivityMatch {
9
+ [field: string]: ActivityMatchValue | ActivityMatchValue[] | undefined;
10
+ }
11
+ /** A kind of document that appears in the feed as "the thing" (a Word document, a deal). */
12
+ export interface ActivitySubjectRule {
13
+ /** Stable id, e.g. `word`, `deal`. */
14
+ id: string;
15
+ match: ActivityMatch;
16
+ idPrefix?: string;
17
+ /** Summary fields kept with each event (for titles and templates). */
18
+ fields?: string[];
19
+ /** Verbs to report (default: all). */
20
+ report?: string[];
21
+ /** Business events from field changes. */
22
+ events?: ActivityFieldEventRule[];
23
+ }
24
+ /** Documents that belong to a subject (Word chunks, comments). */
25
+ export interface ActivityPartRule {
26
+ match: ActivityMatch;
27
+ idPrefix?: string;
28
+ /** Summary field holding the id of the subject (or of another part). */
29
+ subject: string;
30
+ /** Verb every change of the part counts as for the subject (default `edit`). */
31
+ as?: string;
32
+ /** Fields of the part kept with each event (e.g. a node's `subject`), so a line can name it. */
33
+ fields?: string[];
34
+ }
35
+ /** Declarative feed rules of an app (the `activity` block of haven-app.json, minus rendering). */
36
+ export interface ActivityRules {
37
+ subjects?: ActivitySubjectRule[];
38
+ parts?: ActivityPartRule[];
39
+ }
40
+ /** Reads summary fields of documents; missing documents are left out. */
41
+ export type ActivityFieldReader = (docIds: readonly string[]) => Promise<Map<string, Record<string, unknown>>>;
42
+ /** The rules of several apps used on one database, in order of precedence. */
43
+ export declare function mergeActivityRules(...rules: Array<ActivityRules | null | undefined>): ActivityRules;
44
+ /** Fields a summary must contain for these rules to work. */
45
+ export declare function activityRuleFields(rules: ActivityRules): string[];
46
+ /**
47
+ * An {@link ActivityClassifier} from declarative rules, evaluated against
48
+ * summary fields (no document is loaded). A document matching a subject rule
49
+ * is its own subject; a document matching a part rule belongs to the
50
+ * document its `subject` field names (followed up to three steps), if that
51
+ * one matches a subject rule. Everything else does not take part.
52
+ *
53
+ * When several rules match, the one listed first wins; put the rules of the
54
+ * app that owns the database first (see {@link mergeActivityRules}).
55
+ */
56
+ export declare function createSummaryRuleClassifier(rules: ActivityRules, readFields: ActivityFieldReader, options?: {
57
+ prepare?: () => Promise<void>;
58
+ }): ActivityClassifier;
59
+ //# sourceMappingURL=summaryRuleClassifier.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"summaryRuleClassifier.d.ts","sourceRoot":"","sources":["../../../src/core/activity/summaryRuleClassifier.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAA0B,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AAElG,kFAAkF;AAClF,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC;AAElE;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,CAAC,KAAK,EAAE,MAAM,GAAG,kBAAkB,GAAG,kBAAkB,EAAE,GAAG,SAAS,CAAC;CACxE;AAED,4FAA4F;AAC5F,MAAM,WAAW,mBAAmB;IAClC,sCAAsC;IACtC,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,aAAa,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,sEAAsE;IACtE,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,sCAAsC;IACtC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,0CAA0C;IAC1C,MAAM,CAAC,EAAE,sBAAsB,EAAE,CAAC;CACnC;AAED,kEAAkE;AAClE,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,aAAa,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,wEAAwE;IACxE,OAAO,EAAE,MAAM,CAAC;IAChB,gFAAgF;IAChF,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,gGAAgG;IAChG,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,kGAAkG;AAClG,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,EAAE,mBAAmB,EAAE,CAAC;IACjC,KAAK,CAAC,EAAE,gBAAgB,EAAE,CAAC;CAC5B;AAED,yEAAyE;AACzE,MAAM,MAAM,mBAAmB,GAAG,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,KAAK,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;AA8C/G,8EAA8E;AAC9E,wBAAgB,kBAAkB,CAAC,GAAG,KAAK,EAAE,KAAK,CAAC,aAAa,GAAG,IAAI,GAAG,SAAS,CAAC,GAAG,aAAa,CAKnG;AAED,6DAA6D;AAC7D,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,aAAa,GAAG,MAAM,EAAE,CAajE;AAED;;;;;;;;;GASG;AACH,wBAAgB,2BAA2B,CACzC,KAAK,EAAE,aAAa,EACpB,UAAU,EAAE,mBAAmB,EAC/B,OAAO,GAAE;IAAE,OAAO,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAAO,GAC9C,kBAAkB,CA6EpB"}
@@ -0,0 +1,169 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mergeActivityRules = mergeActivityRules;
4
+ exports.activityRuleFields = activityRuleFields;
5
+ exports.createSummaryRuleClassifier = createSummaryRuleClassifier;
6
+ /** Parts may point at parts: a comment on a chunk of a document. */
7
+ const MAX_PART_DEPTH = 3;
8
+ function valueMatches(actual, expected) {
9
+ if (expected === undefined)
10
+ return true;
11
+ if (Array.isArray(expected))
12
+ return expected.some((value) => valueMatches(actual, value));
13
+ if (expected === null)
14
+ return actual === null || actual === undefined;
15
+ return actual === expected;
16
+ }
17
+ function ruleMatches(rule, docId, fields) {
18
+ if (rule.idPrefix && !docId.startsWith(rule.idPrefix))
19
+ return false;
20
+ return Object.entries(rule.match).every(([field, expected]) => valueMatches(fields[field], expected));
21
+ }
22
+ /** Stable text of the rules, for {@link ActivityClassifier.fingerprint}. */
23
+ function stableJson(value) {
24
+ if (Array.isArray(value))
25
+ return `[${value.map(stableJson).join(",")}]`;
26
+ if (value && typeof value === "object") {
27
+ return `{${Object.keys(value)
28
+ .sort()
29
+ .map((key) => `${JSON.stringify(key)}:${stableJson(value[key])}`)
30
+ .join(",")}}`;
31
+ }
32
+ return JSON.stringify(value ?? null);
33
+ }
34
+ function fnv1a(text) {
35
+ let hash = 0x811c9dc5;
36
+ for (let i = 0; i < text.length; i++) {
37
+ hash ^= text.charCodeAt(i);
38
+ hash = Math.imul(hash, 0x01000193);
39
+ }
40
+ return (hash >>> 0).toString(36);
41
+ }
42
+ function pickFields(fields, names) {
43
+ const picked = {};
44
+ for (const name of names ?? []) {
45
+ if (fields[name] !== undefined)
46
+ picked[name] = fields[name];
47
+ }
48
+ return picked;
49
+ }
50
+ /** The rules of several apps used on one database, in order of precedence. */
51
+ function mergeActivityRules(...rules) {
52
+ return {
53
+ subjects: rules.flatMap((r) => r?.subjects ?? []),
54
+ parts: rules.flatMap((r) => r?.parts ?? []),
55
+ };
56
+ }
57
+ /** Fields a summary must contain for these rules to work. */
58
+ function activityRuleFields(rules) {
59
+ const fields = new Set();
60
+ for (const rule of rules.subjects ?? []) {
61
+ for (const field of Object.keys(rule.match))
62
+ fields.add(field);
63
+ for (const field of rule.fields ?? [])
64
+ fields.add(field);
65
+ for (const event of rule.events ?? [])
66
+ fields.add(event.when.field);
67
+ }
68
+ for (const rule of rules.parts ?? []) {
69
+ for (const field of Object.keys(rule.match))
70
+ fields.add(field);
71
+ fields.add(rule.subject);
72
+ for (const field of rule.fields ?? [])
73
+ fields.add(field);
74
+ }
75
+ return [...fields];
76
+ }
77
+ /**
78
+ * An {@link ActivityClassifier} from declarative rules, evaluated against
79
+ * summary fields (no document is loaded). A document matching a subject rule
80
+ * is its own subject; a document matching a part rule belongs to the
81
+ * document its `subject` field names (followed up to three steps), if that
82
+ * one matches a subject rule. Everything else does not take part.
83
+ *
84
+ * When several rules match, the one listed first wins; put the rules of the
85
+ * app that owns the database first (see {@link mergeActivityRules}).
86
+ */
87
+ function createSummaryRuleClassifier(rules, readFields, options = {}) {
88
+ const subjects = rules.subjects ?? [];
89
+ const parts = rules.parts ?? [];
90
+ return {
91
+ fingerprint: fnv1a(stableJson(rules)),
92
+ prepare: options.prepare,
93
+ readFields,
94
+ async classify(docIds) {
95
+ const result = new Map();
96
+ const fieldCache = await readFields(docIds);
97
+ // Documents the reader does not know (deleted, not summarized) stay
98
+ // out of the result, so the index does not remember them as "no".
99
+ const pending = docIds.filter((docId) => fieldCache.has(docId));
100
+ // Follow part chains to their subjects.
101
+ const subjectOf = new Map();
102
+ let frontier = pending.map((docId) => ({
103
+ origin: docId,
104
+ current: docId,
105
+ depth: 0,
106
+ partVerb: undefined,
107
+ partFieldNames: undefined,
108
+ }));
109
+ while (frontier.length) {
110
+ const missing = frontier.map((step) => step.current).filter((id) => !fieldCache.has(id));
111
+ if (missing.length)
112
+ for (const [id, fields] of await readFields([...new Set(missing)]))
113
+ fieldCache.set(id, fields);
114
+ const nextFrontier = [];
115
+ for (const step of frontier) {
116
+ const fields = fieldCache.get(step.current);
117
+ if (!fields) {
118
+ subjectOf.set(step.origin, null);
119
+ continue;
120
+ }
121
+ if (subjects.some((rule) => ruleMatches(rule, step.current, fields))) {
122
+ subjectOf.set(step.origin, { subjectDocId: step.current, partVerb: step.partVerb, partFieldNames: step.partFieldNames });
123
+ continue;
124
+ }
125
+ const part = parts.find((rule) => ruleMatches(rule, step.current, fields));
126
+ const parentId = part ? fields[part.subject] : undefined;
127
+ if (!part || typeof parentId !== "string" || !parentId || step.depth >= MAX_PART_DEPTH || parentId === step.origin) {
128
+ subjectOf.set(step.origin, null);
129
+ continue;
130
+ }
131
+ nextFrontier.push({
132
+ origin: step.origin,
133
+ current: parentId,
134
+ depth: step.depth + 1,
135
+ // The verb and fields of the part next to the changed document count.
136
+ partVerb: step.partVerb ?? part.as ?? "edit",
137
+ partFieldNames: step.depth === 0 ? part.fields : step.partFieldNames,
138
+ });
139
+ }
140
+ frontier = nextFrontier;
141
+ }
142
+ for (const docId of pending) {
143
+ const target = subjectOf.get(docId);
144
+ if (!target) {
145
+ result.set(docId, null);
146
+ continue;
147
+ }
148
+ const fields = fieldCache.get(target.subjectDocId) ?? {};
149
+ const rule = subjects.find((candidate) => ruleMatches(candidate, target.subjectDocId, fields));
150
+ const classification = {
151
+ subjectDocId: target.subjectDocId,
152
+ kind: rule.id,
153
+ subjectFields: pickFields(fields, rule.fields),
154
+ };
155
+ if (target.partVerb)
156
+ classification.partVerb = target.partVerb;
157
+ if (target.partFieldNames?.length)
158
+ classification.partFieldNames = [...target.partFieldNames];
159
+ if (rule.report)
160
+ classification.report = [...rule.report];
161
+ if (rule.events?.length)
162
+ classification.fieldEvents = rule.events.map((event) => ({ ...event, when: { ...event.when } }));
163
+ result.set(docId, classification);
164
+ }
165
+ return result;
166
+ },
167
+ };
168
+ }
169
+ //# sourceMappingURL=summaryRuleClassifier.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"summaryRuleClassifier.js","sourceRoot":"","sources":["../../../src/core/activity/summaryRuleClassifier.ts"],"names":[],"mappings":";;AA6FA,gDAKC;AAGD,gDAaC;AAYD,kEAiFC;AA/JD,oEAAoE;AACpE,MAAM,cAAc,GAAG,CAAC,CAAC;AAEzB,SAAS,YAAY,CAAC,MAAe,EAAE,QAA+D;IACpG,IAAI,QAAQ,KAAK,SAAS;QAAE,OAAO,IAAI,CAAC;IACxC,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC;QAAE,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,YAAY,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;IAC1F,IAAI,QAAQ,KAAK,IAAI;QAAE,OAAO,MAAM,KAAK,IAAI,IAAI,MAAM,KAAK,SAAS,CAAC;IACtE,OAAO,MAAM,KAAK,QAAQ,CAAC;AAC7B,CAAC;AAED,SAAS,WAAW,CAAC,IAAiD,EAAE,KAAa,EAAE,MAA+B;IACpH,IAAI,IAAI,CAAC,QAAQ,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC;QAAE,OAAO,KAAK,CAAC;IACpE,OAAO,MAAM,CAAC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zD,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,WAAW,CAAC,SAAS,EAAE,MAAM,CAAC,YAAY,EAAE,MAAM,CAAC,CAAE,CAAC;gBAChG,MAAM,cAAc,GAA2B;oBAC7C,YAAY,EAAE,MAAM,CAAC,YAAY;oBACjC,IAAI,EAAE,IAAI,CAAC,EAAE;oBACb,aAAa,EAAE,UAAU,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC;iBAC/C,CAAC;gBACF,IAAI,MAAM,CAAC,QAAQ;oBAAE,cAAc,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;gBAC/D,IAAI,MAAM,CAAC,cAAc,EAAE,MAAM;oBAAE,cAAc,CAAC,cAAc,GAAG,CAAC,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC;gBAC9F,IAAI,IAAI,CAAC,MAAM;oBAAE,cAAc,CAAC,MAAM,GAAG,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC;gBAC1D,IAAI,IAAI,CAAC,MAAM,EAAE,MAAM;oBAAE,cAAc,CAAC,WAAW,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,EAAE,IAAI,EAAE,EAAE,GAAG,KAAK,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC;gBAC1H,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,cAAc,CAAC,CAAC;YACpC,CAAC;YACD,OAAO,MAAM,CAAC;QAChB,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,230 @@
1
+ /**
2
+ * Activity feed ("Änderungs-Feed"): who changed what and when, from the
3
+ * application's point of view, collected locally from a database's store.
4
+ * See docs/activity-feed.md.
5
+ *
6
+ * The feed works on store entries (revision grain), not on the changefeed
7
+ * (one merged head per document): every `doc_create`/`doc_change`/
8
+ * `doc_delete`/`doc_undelete` entry the reader can decrypt becomes part of an
9
+ * {@link ActivityEvent}. Entries are read as metadata only (no decryption, no
10
+ * materialization). Which document an entry belongs to from the user's point
11
+ * of view (a Word chunk belongs to its Word document) comes from an
12
+ * {@link ActivityClassifier}, usually declarative rules evaluated against the
13
+ * summary buffer ({@link createSummaryRuleClassifier}).
14
+ *
15
+ * Nothing here is synced: the feed is a local, derived index that can be
16
+ * dropped and rebuilt at any time.
17
+ */
18
+ import type { StoreEntryType } from "../types";
19
+ /** Built-in verbs; classifiers may add their own (e.g. `comment`). */
20
+ export type ActivityBaseVerb = "create" | "edit" | "delete" | "restore";
21
+ /** One store entry as the activity index sees it (metadata only). */
22
+ export interface ActivityRawEntry {
23
+ entryId: string;
24
+ docId: string;
25
+ entryType: StoreEntryType;
26
+ /** Author clock. */
27
+ createdAt: number;
28
+ /** Witness time (`receivedAt`) when witnessed, otherwise `createdAt`. */
29
+ trustedTime: number;
30
+ /** `true` when {@link trustedTime} comes from a witness. */
31
+ trusted: boolean;
32
+ /** Ed25519 public key (PEM) of the author. */
33
+ actorKey: string;
34
+ dependencyIds: string[];
35
+ decryptionKeyId: string;
36
+ }
37
+ /** A business event a subject reports when one of its fields changes. */
38
+ export interface ActivityFieldEventRule {
39
+ /** Stable id, used as the event's verb (e.g. `won`). */
40
+ id: string;
41
+ when: {
42
+ field: string;
43
+ /** Fires when the field now has this value (and did not before). */
44
+ to?: unknown;
45
+ /** Fires when the field had this value before (and does not now). */
46
+ from?: unknown;
47
+ /** Fires on any change of the field's value. */
48
+ changed?: boolean;
49
+ };
50
+ /** Emphasize the event in feeds and digests. */
51
+ highlight?: boolean;
52
+ }
53
+ /** How one changed document appears in the feed. */
54
+ export interface ActivityClassification {
55
+ /** The document the user perceives as "the thing" (may be the document itself). */
56
+ subjectDocId: string;
57
+ /** Id of the rule that matched the subject (e.g. `word`, `deal`). */
58
+ kind?: string;
59
+ /**
60
+ * Set when the changed document is a part of {@link subjectDocId} (a Word
61
+ * chunk, a comment): every entry of the part counts as this verb of the
62
+ * subject (default `edit`). Creating or deleting a part edits the subject.
63
+ */
64
+ partVerb?: string;
65
+ /** Verbs the subject reports; others are dropped. Absent: all verbs. */
66
+ report?: string[];
67
+ /** Field snapshot of the subject (title etc.), kept with the event. */
68
+ subjectFields?: Record<string, unknown>;
69
+ /** Business events derived from field changes of the subject. */
70
+ fieldEvents?: ActivityFieldEventRule[];
71
+ /**
72
+ * Fields of the changed part itself kept with the event (e.g. the title of
73
+ * a mind-map node), so a feed line can name what changed inside the subject.
74
+ */
75
+ partFieldNames?: string[];
76
+ }
77
+ /**
78
+ * Maps changed documents to their feed subject. `null` for a document means
79
+ * it does not take part in the feed (no rule, technical document).
80
+ */
81
+ export interface ActivityClassifier {
82
+ /**
83
+ * Changes whenever the rules change; the index then classifies documents
84
+ * again instead of trusting its cached document → subject mapping.
85
+ */
86
+ readonly fingerprint: string;
87
+ /** Called once per update run before any {@link classify} (e.g. to bring the summary up to date). */
88
+ prepare?(): Promise<void>;
89
+ /** Current fields of documents, for {@link ActivityClassification.partFieldNames}. */
90
+ readFields?(docIds: readonly string[]): Promise<Map<string, Record<string, unknown>>>;
91
+ classify(docIds: readonly string[]): Promise<Map<string, ActivityClassification | null>>;
92
+ }
93
+ /** One document of an event, with the revisions around the event. */
94
+ export interface ActivityEventDoc {
95
+ docId: string;
96
+ /**
97
+ * Store entry ids the first change of this event was written on top of
98
+ * (outside the event): the document's state before the event. Empty when
99
+ * the event created the document. Pass to `materializeDocumentAtHeads`.
100
+ */
101
+ before: string[];
102
+ /** Store entry ids of the document's state after the event (its heads within the event). */
103
+ after: string[];
104
+ entryCount: number;
105
+ /** The part's fields ({@link ActivityClassification.partFieldNames}) as of the event's last change. */
106
+ fields?: Record<string, unknown>;
107
+ }
108
+ /**
109
+ * One row of the feed: entries with the same subject, author and verb that
110
+ * follow each other within the session gap, or one business event.
111
+ */
112
+ export interface ActivityEvent {
113
+ /** Unique across feeds: `<feedKey>|<first entry id>` (`#<rule>` for business events). */
114
+ id: string;
115
+ /** The feed (database) the event belongs to, e.g. `<tenantId>/<dbId>`. */
116
+ feedKey: string;
117
+ subjectDocId: string;
118
+ kind?: string;
119
+ verb: string;
120
+ actorKey: string;
121
+ /** Trusted time of the first and last entry. */
122
+ firstTime: number;
123
+ lastTime: number;
124
+ /** All entries are witnessed. */
125
+ trusted: boolean;
126
+ entryCount: number;
127
+ docs: ActivityEventDoc[];
128
+ /** Field snapshot of the subject as of {@link lastTime}. */
129
+ fields?: Record<string, unknown>;
130
+ /** A business event with `highlight`. */
131
+ highlight?: boolean;
132
+ /** Number of entries not yet witnessed (internal bookkeeping; `trusted` is derived from it). */
133
+ untrusted: number;
134
+ }
135
+ /** Persisted position of one feed. */
136
+ export interface ActivityFeedState {
137
+ /** Store scan cursor. */
138
+ cursor: {
139
+ receiptOrder: number;
140
+ id: string;
141
+ } | null;
142
+ /** Store cursor epoch the cursor belongs to. */
143
+ epoch: string | null;
144
+ /** {@link ActivityClassifier.fingerprint} the cached document mapping was made with. */
145
+ rulesFingerprint: string | null;
146
+ /** Entries older than this (trusted time) were skipped when the feed was first built. */
147
+ since: number;
148
+ }
149
+ /** Cached mapping of a changed document to its subject (or to nothing). */
150
+ export interface ActivityDocMapping {
151
+ /** `null`: the document does not take part. */
152
+ classification: ActivityClassification | null;
153
+ }
154
+ /** Everything one update run writes, in one transaction. */
155
+ export interface ActivityTableWrite {
156
+ state: ActivityFeedState;
157
+ events: ActivityEvent[];
158
+ entries: Array<{
159
+ entryId: string;
160
+ eventId: string;
161
+ trusted: boolean;
162
+ }>;
163
+ docMappings: Array<{
164
+ docId: string;
165
+ mapping: ActivityDocMapping;
166
+ }>;
167
+ subjectFields: Array<{
168
+ subjectDocId: string;
169
+ fields: Record<string, unknown>;
170
+ }>;
171
+ /** Drop every cached document mapping first (rules changed). */
172
+ clearDocMappings?: boolean;
173
+ }
174
+ /** Keyset position for paging feeds (newest first). */
175
+ export interface ActivityCursor {
176
+ lastTime: number;
177
+ id: string;
178
+ }
179
+ export interface ActivityQuery {
180
+ /** Feeds to read; absent = all feeds in the table. */
181
+ feedKeys?: readonly string[];
182
+ subjectDocId?: string;
183
+ actorKeys?: readonly string[];
184
+ excludeActorKeys?: readonly string[];
185
+ verbs?: readonly string[];
186
+ /** Only events whose last entry is at or after this time. */
187
+ since?: number;
188
+ /** Continue after this event (from {@link ActivityQueryResult.nextCursor}). */
189
+ after?: ActivityCursor | null;
190
+ /** Default 50, at most 500. */
191
+ limit?: number;
192
+ }
193
+ export interface ActivityQueryResult {
194
+ /** Newest first (by last entry time, then id). */
195
+ events: ActivityEvent[];
196
+ nextCursor: ActivityCursor | null;
197
+ }
198
+ /** Storage of activity feeds; one table can hold the feeds of many databases and tenants. */
199
+ export interface ActivityTable {
200
+ readState(feedKey: string): Promise<ActivityFeedState | null>;
201
+ readDocMappings(feedKey: string, docIds: readonly string[]): Promise<Map<string, ActivityDocMapping>>;
202
+ readSubjectFields(feedKey: string, subjectDocIds: readonly string[]): Promise<Map<string, Record<string, unknown>>>;
203
+ /** Events of these subjects whose last entry is at or after `since`. */
204
+ readRecentEvents(feedKey: string, subjectDocIds: readonly string[], since: number): Promise<ActivityEvent[]>;
205
+ /** Event id and witness state of entries already in the feed. */
206
+ readEntries(feedKey: string, entryIds: readonly string[]): Promise<Map<string, {
207
+ eventId: string;
208
+ trusted: boolean;
209
+ }>>;
210
+ readEvents(eventIds: readonly string[]): Promise<ActivityEvent[]>;
211
+ write(feedKey: string, change: ActivityTableWrite): Promise<void>;
212
+ query(query: ActivityQuery): Promise<ActivityQueryResult>;
213
+ /** Remove events whose last entry is older than `before` (and their entries). Returns the number removed. */
214
+ prune(feedKey: string, before: number): Promise<number>;
215
+ /** Remove a feed completely (it is rebuilt on the next update). */
216
+ clear(feedKey: string): Promise<void>;
217
+ }
218
+ export declare const ACTIVITY_QUERY_DEFAULT_LIMIT = 50;
219
+ export declare const ACTIVITY_QUERY_MAX_LIMIT = 500;
220
+ /** Clamp a requested page size. */
221
+ export declare function activityQueryLimit(limit: number | undefined): number;
222
+ /** Newest-first order of events (also the keyset order of {@link ActivityCursor}). */
223
+ export declare function compareActivityEvents(a: {
224
+ lastTime: number;
225
+ id: string;
226
+ }, b: {
227
+ lastTime: number;
228
+ id: string;
229
+ }): number;
230
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/core/activity/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE/C,sEAAsE;AACtE,MAAM,MAAM,gBAAgB,GAAG,QAAQ,GAAG,MAAM,GAAG,QAAQ,GAAG,SAAS,CAAC;AAExE,qEAAqE;AACrE,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,cAAc,CAAC;IAC1B,oBAAoB;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,yEAAyE;IACzE,WAAW,EAAE,MAAM,CAAC;IACpB,4DAA4D;IAC5D,OAAO,EAAE,OAAO,CAAC;IACjB,8CAA8C;IAC9C,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,eAAe,EAAE,MAAM,CAAC;CACzB;AAED,yEAAyE;AACzE,MAAM,WAAW,sBAAsB;IACrC,wDAAwD;IACxD,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE;QACJ,KAAK,EAAE,MAAM,CAAC;QACd,oEAAoE;QACpE,EAAE,CAAC,EAAE,OAAO,CAAC;QACb,qEAAqE;QACrE,IAAI,CAAC,EAAE,OAAO,CAAC;QACf,gDAAgD;QAChD,OAAO,CAAC,EAAE,OAAO,CAAC;KACnB,CAAC;IACF,gDAAgD;IAChD,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,oDAAoD;AACpD,MAA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;AACtF,wBAAgB,qBAAqB,CAAC,CAAC,EAAE;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,EAAE,CAAC,EAAE;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAGtH"}
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ /**
3
+ * Activity feed ("Änderungs-Feed"): who changed what and when, from the
4
+ * application's point of view, collected locally from a database's store.
5
+ * See docs/activity-feed.md.
6
+ *
7
+ * The feed works on store entries (revision grain), not on the changefeed
8
+ * (one merged head per document): every `doc_create`/`doc_change`/
9
+ * `doc_delete`/`doc_undelete` entry the reader can decrypt becomes part of an
10
+ * {@link ActivityEvent}. Entries are read as metadata only (no decryption, no
11
+ * materialization). Which document an entry belongs to from the user's point
12
+ * of view (a Word chunk belongs to its Word document) comes from an
13
+ * {@link ActivityClassifier}, usually declarative rules evaluated against the
14
+ * summary buffer ({@link createSummaryRuleClassifier}).
15
+ *
16
+ * Nothing here is synced: the feed is a local, derived index that can be
17
+ * dropped and rebuilt at any time.
18
+ */
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.ACTIVITY_QUERY_MAX_LIMIT = exports.ACTIVITY_QUERY_DEFAULT_LIMIT = void 0;
21
+ exports.activityQueryLimit = activityQueryLimit;
22
+ exports.compareActivityEvents = compareActivityEvents;
23
+ exports.ACTIVITY_QUERY_DEFAULT_LIMIT = 50;
24
+ exports.ACTIVITY_QUERY_MAX_LIMIT = 500;
25
+ /** Clamp a requested page size. */
26
+ function activityQueryLimit(limit) {
27
+ if (limit === undefined || !Number.isFinite(limit))
28
+ return exports.ACTIVITY_QUERY_DEFAULT_LIMIT;
29
+ return Math.max(1, Math.min(exports.ACTIVITY_QUERY_MAX_LIMIT, Math.floor(limit)));
30
+ }
31
+ /** Newest-first order of events (also the keyset order of {@link ActivityCursor}). */
32
+ function compareActivityEvents(a, b) {
33
+ if (a.lastTime !== b.lastTime)
34
+ return b.lastTime - a.lastTime;
35
+ return a.id < b.id ? 1 : a.id > b.id ? -1 : 0;
36
+ }
37
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/core/activity/types.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;GAgBG;;;AA6MH,gDAGC;AAGD,sDAGC;AAbY,QAAA,4BAA4B,GAAG,EAAE,CAAC;AAClC,QAAA,wBAAwB,GAAG,GAAG,CAAC;AAE5C,mCAAmC;AACnC,SAAgB,kBAAkB,CAAC,KAAyB;IAC1D,IAAI,KAAK,KAAK,SAAS,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,oCAA4B,CAAC;IACxF,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,gCAAwB,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAC5E,CAAC;AAED,sFAAsF;AACtF,SAAgB,qBAAqB,CAAC,CAAmC,EAAE,CAAmC;IAC5G,IAAI,CAAC,CAAC,QAAQ,KAAK,CAAC,CAAC,QAAQ;QAAE,OAAO,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC,QAAQ,CAAC;IAC9D,OAAO,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAChD,CAAC"}