@miniaxolotl/grove-server 1.11.14 → 1.11.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/bootstrap.js CHANGED
@@ -4,6 +4,78 @@ import { createRequire as __groveCreateRequire } from "node:module"; const requi
4
4
  import knex from "knex";
5
5
  import { Model, knexSnakeCaseMappers } from "objection";
6
6
 
7
+ // lib/database/src/structured-document-migration.ts
8
+ var structuredDocuments = {
9
+ name: "20261105_036_structured_documents",
10
+ async up(db2) {
11
+ await db2.raw(`
12
+ ALTER TABLE memory_revisions ADD COLUMN document jsonb, ADD COLUMN change jsonb, ADD COLUMN actor jsonb,
13
+ ADD COLUMN revision_group jsonb;
14
+ ALTER TABLE memory_revisions ADD CONSTRAINT revision_group_bounds CHECK (
15
+ revision_group IS NULL OR (jsonb_typeof(revision_group)='object'
16
+ AND (revision_group->>'start')::integer BETWEEN 1 AND version
17
+ AND (revision_group->>'number')::integer BETWEEN 1 AND version) IS TRUE);
18
+ CREATE INDEX revision_history_groups ON memory_revisions
19
+ (account_id,memory_id,(coalesce((revision_group->>'start')::integer,version)),version DESC);
20
+ CREATE FUNCTION grove_document_matches(doc jsonb, note uuid, revision integer, source text)
21
+ RETURNS boolean LANGUAGE sql IMMUTABLE SET search_path=pg_catalog,public AS $$
22
+ SELECT doc IS NULL OR (
23
+ doc->>'schemaVersion'='1' AND doc->>'noteId'=note::text AND doc->>'revision'=revision::text
24
+ AND jsonb_typeof(doc->'blocks')='array'
25
+ AND (SELECT string_agg(b->>'source','' ORDER BY ordinal)
26
+ FROM jsonb_array_elements(doc->'blocks') WITH ORDINALITY AS blocks(b,ordinal))=source
27
+ ) IS TRUE
28
+ $$;
29
+ ALTER TABLE memory_revisions ADD CONSTRAINT revision_document_projection
30
+ CHECK (grove_document_matches(document,memory_id,version,content));
31
+ `);
32
+ },
33
+ async down() {
34
+ throw new Error("Use a forward migration; retain structured history");
35
+ }
36
+ };
37
+
38
+ // lib/database/src/browser-capture-migration.ts
39
+ var browserCapture = {
40
+ name: "20261105_037_browser_capture",
41
+ async up(db2) {
42
+ await db2.raw(`
43
+ CREATE TABLE web_captures (
44
+ account_id uuid NOT NULL, memory_id uuid NOT NULL, version integer NOT NULL CHECK(version>0),
45
+ provenance jsonb NOT NULL CHECK(jsonb_typeof(provenance)='object' AND length(provenance::text)<=10000),
46
+ active boolean NOT NULL DEFAULT true,
47
+ PRIMARY KEY(account_id,memory_id,version),
48
+ FOREIGN KEY(account_id,memory_id) REFERENCES memories(account_id,id) ON DELETE CASCADE
49
+ );
50
+ ALTER TABLE web_captures ENABLE ROW LEVEL SECURITY;
51
+ ALTER TABLE web_captures FORCE ROW LEVEL SECURITY;
52
+ CREATE POLICY web_captures_tenant ON web_captures USING (
53
+ account_id=nullif(current_setting('grove.account_id',true),'')::uuid
54
+ AND EXISTS(SELECT 1 FROM memories m WHERE m.id=memory_id AND m.account_id=web_captures.account_id)
55
+ ) WITH CHECK (
56
+ account_id=nullif(current_setting('grove.account_id',true),'')::uuid
57
+ AND EXISTS(SELECT 1 FROM memories m WHERE m.id=memory_id AND m.account_id=web_captures.account_id)
58
+ );
59
+ GRANT SELECT,INSERT,UPDATE ON web_captures TO grove_runtime,grove_worker;
60
+ CREATE INDEX web_captures_url ON web_captures(account_id,(provenance->>'url'),memory_id) WHERE active;
61
+ CREATE UNIQUE INDEX web_captures_one_active ON web_captures(account_id,memory_id) WHERE active;
62
+ CREATE FUNCTION grove_invalidate_web_capture() RETURNS trigger LANGUAGE plpgsql
63
+ SET search_path=pg_catalog AS $$ BEGIN
64
+ IF NEW.content IS DISTINCT FROM OLD.content THEN
65
+ UPDATE public.web_captures SET active=false WHERE account_id=OLD.account_id AND memory_id=OLD.id AND active;
66
+ END IF;
67
+ RETURN NEW; END $$;
68
+ REVOKE ALL ON FUNCTION grove_invalidate_web_capture() FROM PUBLIC;
69
+ GRANT EXECUTE ON FUNCTION grove_invalidate_web_capture() TO grove_runtime,grove_worker;
70
+ CREATE TRIGGER memories_invalidate_web_capture BEFORE UPDATE OF content ON memories
71
+ FOR EACH ROW EXECUTE FUNCTION grove_invalidate_web_capture();
72
+ `);
73
+ },
74
+ async down() {
75
+ throw new Error("Use a forward migration; retain web provenance");
76
+ }
77
+ };
78
+
7
79
  // lib/database/src/action-usage-migration.ts
8
80
  var actionUsage = {
9
81
  name: "20261025_028_action_usage",
@@ -3383,7 +3455,9 @@ var migrations = [
3383
3455
  conversationDocuments,
3384
3456
  aiCache,
3385
3457
  adminUsageReports,
3386
- notebookOrder
3458
+ notebookOrder,
3459
+ structuredDocuments,
3460
+ browserCapture
3387
3461
  ];
3388
3462
  var migrationSource = {
3389
3463
  getMigrations: async () => migrations,