@kinloom/worker 0.0.0-stage → 0.1.0

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.
@@ -0,0 +1,158 @@
1
+ -- Kinloom initial Cloudflare D1 SQLite schema (0001_initial.sql)
2
+ -- Includes all base tables, all four C4 Section 5.3 structural refinements,
3
+ -- and all secondary indexes required for zero full-table scans on hot paths.
4
+
5
+ -- Canonical current state of every archive entity (person, event, place, source, media, narrative)
6
+ CREATE TABLE entities (
7
+ entity_type TEXT NOT NULL CHECK (entity_type IN ('person', 'event', 'place', 'source', 'media', 'narrative')),
8
+ entity_id TEXT NOT NULL,
9
+ slug TEXT,
10
+ data_json TEXT NOT NULL,
11
+ current_revision_id INTEGER NOT NULL,
12
+ has_primary_source INTEGER NOT NULL DEFAULT 1,
13
+ deleted_at TEXT,
14
+ updated_at TEXT NOT NULL,
15
+ PRIMARY KEY (entity_type, entity_id)
16
+ );
17
+
18
+ -- Normalized bidirectional kinship edges (versioned through revisions)
19
+ CREATE TABLE kinship_edges (
20
+ edge_id TEXT PRIMARY KEY,
21
+ from_person_id TEXT NOT NULL,
22
+ to_person_id TEXT NOT NULL,
23
+ relation TEXT NOT NULL CHECK (relation IN ('parent', 'child', 'spouse')),
24
+ family_xref TEXT,
25
+ current_revision_id INTEGER NOT NULL,
26
+ deleted_at TEXT,
27
+ updated_at TEXT NOT NULL
28
+ );
29
+
30
+ -- Append-only Wikipedia-style revision ledger (never updated or deleted)
31
+ CREATE TABLE revisions (
32
+ revision_id INTEGER PRIMARY KEY AUTOINCREMENT,
33
+ batch_id TEXT,
34
+ entity_type TEXT NOT NULL CHECK (entity_type IN ('person', 'event', 'place', 'source', 'media', 'narrative', 'kinship_edge')),
35
+ entity_id TEXT NOT NULL,
36
+ parent_revision_id INTEGER,
37
+ action TEXT NOT NULL CHECK (action IN ('create', 'update', 'delete', 'restore', 'revert')),
38
+ reverted_revision_id INTEGER,
39
+ author_id TEXT NOT NULL,
40
+ author_name TEXT NOT NULL,
41
+ author_type TEXT NOT NULL CHECK (author_type IN ('human', 'agent', 'system_seed')),
42
+ summary TEXT NOT NULL,
43
+ has_primary_source INTEGER NOT NULL,
44
+ before_json TEXT,
45
+ after_json TEXT,
46
+ created_at TEXT NOT NULL,
47
+ CHECK (action IN ('create', 'restore') OR parent_revision_id IS NOT NULL)
48
+ );
49
+
50
+ -- Authenticated site members (admins and editors)
51
+ CREATE TABLE users (
52
+ email TEXT PRIMARY KEY,
53
+ display_name TEXT NOT NULL,
54
+ role TEXT NOT NULL CHECK (role IN ('admin', 'editor')),
55
+ added_by TEXT NOT NULL,
56
+ added_at TEXT NOT NULL,
57
+ last_login_at TEXT
58
+ );
59
+
60
+ -- Shareable read-only family invite links with optional expiration and revocation
61
+ CREATE TABLE invites (
62
+ token TEXT PRIMARY KEY,
63
+ label TEXT NOT NULL,
64
+ created_by TEXT NOT NULL,
65
+ created_at TEXT NOT NULL,
66
+ expires_at TEXT,
67
+ revoked_at TEXT,
68
+ uses INTEGER NOT NULL DEFAULT 0,
69
+ last_used_at TEXT
70
+ );
71
+
72
+ -- Single-use short-lived email magic links (SHA-256 hashed tokens)
73
+ CREATE TABLE magic_links (
74
+ token_hash TEXT PRIMARY KEY,
75
+ email TEXT NOT NULL,
76
+ invite_token TEXT,
77
+ expires_at TEXT NOT NULL,
78
+ used_at TEXT
79
+ );
80
+
81
+ -- Scoped bearer tokens for AI research agents (write_batch) and archival backups (read_backup)
82
+ CREATE TABLE agent_tokens (
83
+ token_id TEXT PRIMARY KEY,
84
+ token_hash TEXT NOT NULL,
85
+ label TEXT NOT NULL,
86
+ scope TEXT NOT NULL DEFAULT 'write_batch' CHECK (scope IN ('write_batch', 'read_backup')),
87
+ created_by TEXT NOT NULL,
88
+ created_at TEXT NOT NULL,
89
+ revoked_at TEXT
90
+ );
91
+
92
+ -- Entity Talk threads (additive v1.1 table)
93
+ CREATE TABLE talk_comments (
94
+ comment_id INTEGER PRIMARY KEY AUTOINCREMENT,
95
+ entity_type TEXT NOT NULL CHECK (entity_type IN ('person', 'event', 'place', 'source', 'media', 'narrative', 'kinship_edge')),
96
+ entity_id TEXT NOT NULL,
97
+ author_id TEXT NOT NULL,
98
+ author_name TEXT NOT NULL,
99
+ body_md TEXT NOT NULL,
100
+ created_at TEXT NOT NULL,
101
+ edited_at TEXT,
102
+ deleted_at TEXT
103
+ );
104
+
105
+ -- Optional per-user entity watchlists for future digest notifications
106
+ CREATE TABLE watchlists (
107
+ email TEXT NOT NULL,
108
+ entity_type TEXT NOT NULL,
109
+ entity_id TEXT NOT NULL,
110
+ created_at TEXT NOT NULL,
111
+ PRIMARY KEY (email, entity_type, entity_id)
112
+ );
113
+
114
+ -- 1. Active entity lookup by slug (enforces uniqueness only for non-deleted rows)
115
+ CREATE UNIQUE INDEX idx_entities_active_slug
116
+ ON entities (entity_type, slug)
117
+ WHERE slug IS NOT NULL AND deleted_at IS NULL;
118
+
119
+ -- 2. Active snapshot load for compileArchive (avoids scanning soft-deleted rows)
120
+ CREATE INDEX idx_entities_active_type
121
+ ON entities (entity_type, entity_id)
122
+ WHERE deleted_at IS NULL;
123
+
124
+ -- 3. Per-record History tab ordered newest-first (zero filesort)
125
+ CREATE INDEX idx_revisions_entity_history
126
+ ON revisions (entity_type, entity_id, revision_id DESC);
127
+
128
+ -- 4. One-click AI agent batch inspection and reverse-order batch revert
129
+ CREATE INDEX idx_revisions_batch_lookup
130
+ ON revisions (batch_id, revision_id DESC)
131
+ WHERE batch_id IS NOT NULL;
132
+
133
+ -- 5. Recent Changes feed filtered by author_type (human vs agent)
134
+ CREATE INDEX idx_revisions_author_type_recent
135
+ ON revisions (author_type, revision_id DESC);
136
+
137
+ -- 6. Kinship graph traversal and active duplicate-edge prevention
138
+ CREATE UNIQUE INDEX idx_kinship_active_edge
139
+ ON kinship_edges (from_person_id, to_person_id, relation)
140
+ WHERE deleted_at IS NULL;
141
+
142
+ CREATE INDEX idx_kinship_to_person
143
+ ON kinship_edges (to_person_id)
144
+ WHERE deleted_at IS NULL;
145
+
146
+ -- 7. Bearer token lookup by SHA-256 hash on every CLI or backup request
147
+ CREATE UNIQUE INDEX idx_agent_tokens_hash
148
+ ON agent_tokens (token_hash)
149
+ WHERE revoked_at IS NULL;
150
+
151
+ -- 8. Entity Talk thread lookup ordered chronologically
152
+ CREATE INDEX idx_talk_comments_entity
153
+ ON talk_comments (entity_type, entity_id, comment_id ASC)
154
+ WHERE deleted_at IS NULL;
155
+
156
+ -- 9. Magic-link cleanup and lookup by email for rate limiting
157
+ CREATE INDEX idx_magic_links_email_expires
158
+ ON magic_links (email, expires_at DESC);
package/package.json CHANGED
@@ -1,6 +1,43 @@
1
1
  {
2
2
  "name": "@kinloom/worker",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "license": "MIT",
6
+ "description": "Cloudflare Worker API, D1 revision ledger, R2 media and bundle cache, and auth/RBAC layer for Kinloom family archives.",
7
+ "homepage": "https://github.com/Tiberriver256/kinloom#readme",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/Tiberriver256/kinloom.git",
11
+ "directory": "packages/worker"
12
+ },
13
+ "publishConfig": {
14
+ "access": "public"
15
+ },
16
+ "main": "./dist/index.js",
17
+ "types": "./dist/index.d.ts",
18
+ "exports": {
19
+ ".": {
20
+ "types": "./dist/index.d.ts",
21
+ "import": "./dist/index.js"
22
+ },
23
+ "./migrations/*": "./migrations/*"
24
+ },
25
+ "files": [
26
+ "dist",
27
+ "migrations"
28
+ ],
29
+ "scripts": {
30
+ "build": "tsc -p tsconfig.build.json",
31
+ "typecheck": "tsc --noEmit -p tsconfig.json"
32
+ },
33
+ "dependencies": {
34
+ "@kinloom/core": "^0.1.0",
35
+ "@kinloom/server": "^0.1.0",
36
+ "zod": "^4.6.7"
37
+ },
38
+ "devDependencies": {
39
+ "@cloudflare/workers-types": "^5.20261125.1",
40
+ "miniflare": "^4.20260730.0",
41
+ "wrangler": "^4.168.0"
42
+ }
43
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.