gitx.do 0.0.1 → 0.0.3
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/cli/commands/blame.d.ts +259 -0
- package/dist/cli/commands/blame.d.ts.map +1 -0
- package/dist/cli/commands/blame.js +609 -0
- package/dist/cli/commands/blame.js.map +1 -0
- package/dist/cli/commands/branch.d.ts +249 -0
- package/dist/cli/commands/branch.d.ts.map +1 -0
- package/dist/cli/commands/branch.js +693 -0
- package/dist/cli/commands/branch.js.map +1 -0
- package/dist/cli/commands/commit.d.ts +182 -0
- package/dist/cli/commands/commit.d.ts.map +1 -0
- package/dist/cli/commands/commit.js +437 -0
- package/dist/cli/commands/commit.js.map +1 -0
- package/dist/cli/commands/diff.d.ts +464 -0
- package/dist/cli/commands/diff.d.ts.map +1 -0
- package/dist/cli/commands/diff.js +958 -0
- package/dist/cli/commands/diff.js.map +1 -0
- package/dist/cli/commands/log.d.ts +239 -0
- package/dist/cli/commands/log.d.ts.map +1 -0
- package/dist/cli/commands/log.js +535 -0
- package/dist/cli/commands/log.js.map +1 -0
- package/dist/cli/commands/review.d.ts +457 -0
- package/dist/cli/commands/review.d.ts.map +1 -0
- package/dist/cli/commands/review.js +533 -0
- package/dist/cli/commands/review.js.map +1 -0
- package/dist/cli/commands/status.d.ts +269 -0
- package/dist/cli/commands/status.d.ts.map +1 -0
- package/dist/cli/commands/status.js +493 -0
- package/dist/cli/commands/status.js.map +1 -0
- package/dist/cli/commands/web.d.ts +199 -0
- package/dist/cli/commands/web.d.ts.map +1 -0
- package/dist/cli/commands/web.js +696 -0
- package/dist/cli/commands/web.js.map +1 -0
- package/dist/cli/fs-adapter.d.ts +656 -0
- package/dist/cli/fs-adapter.d.ts.map +1 -0
- package/dist/cli/fs-adapter.js +1179 -0
- package/dist/cli/fs-adapter.js.map +1 -0
- package/dist/cli/index.d.ts +387 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +523 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/ui/components/DiffView.d.ts +7 -0
- package/dist/cli/ui/components/DiffView.d.ts.map +1 -0
- package/dist/cli/ui/components/DiffView.js +11 -0
- package/dist/cli/ui/components/DiffView.js.map +1 -0
- package/dist/cli/ui/components/ErrorDisplay.d.ts +6 -0
- package/dist/cli/ui/components/ErrorDisplay.d.ts.map +1 -0
- package/dist/cli/ui/components/ErrorDisplay.js +11 -0
- package/dist/cli/ui/components/ErrorDisplay.js.map +1 -0
- package/dist/cli/ui/components/FuzzySearch.d.ts +9 -0
- package/dist/cli/ui/components/FuzzySearch.d.ts.map +1 -0
- package/dist/cli/ui/components/FuzzySearch.js +12 -0
- package/dist/cli/ui/components/FuzzySearch.js.map +1 -0
- package/dist/cli/ui/components/LoadingSpinner.d.ts +6 -0
- package/dist/cli/ui/components/LoadingSpinner.d.ts.map +1 -0
- package/dist/cli/ui/components/LoadingSpinner.js +10 -0
- package/dist/cli/ui/components/LoadingSpinner.js.map +1 -0
- package/dist/cli/ui/components/NavigationList.d.ts +9 -0
- package/dist/cli/ui/components/NavigationList.d.ts.map +1 -0
- package/dist/cli/ui/components/NavigationList.js +11 -0
- package/dist/cli/ui/components/NavigationList.js.map +1 -0
- package/dist/cli/ui/components/ScrollableContent.d.ts +8 -0
- package/dist/cli/ui/components/ScrollableContent.d.ts.map +1 -0
- package/dist/cli/ui/components/ScrollableContent.js +11 -0
- package/dist/cli/ui/components/ScrollableContent.js.map +1 -0
- package/dist/cli/ui/components/index.d.ts +7 -0
- package/dist/cli/ui/components/index.d.ts.map +1 -0
- package/dist/cli/ui/components/index.js +9 -0
- package/dist/cli/ui/components/index.js.map +1 -0
- package/dist/cli/ui/terminal-ui.d.ts +52 -0
- package/dist/cli/ui/terminal-ui.d.ts.map +1 -0
- package/dist/cli/ui/terminal-ui.js +121 -0
- package/dist/cli/ui/terminal-ui.js.map +1 -0
- package/dist/durable-object/object-store.d.ts +401 -23
- package/dist/durable-object/object-store.d.ts.map +1 -1
- package/dist/durable-object/object-store.js +414 -25
- package/dist/durable-object/object-store.js.map +1 -1
- package/dist/durable-object/schema.d.ts +188 -0
- package/dist/durable-object/schema.d.ts.map +1 -1
- package/dist/durable-object/schema.js +160 -0
- package/dist/durable-object/schema.js.map +1 -1
- package/dist/durable-object/wal.d.ts +336 -31
- package/dist/durable-object/wal.d.ts.map +1 -1
- package/dist/durable-object/wal.js +272 -27
- package/dist/durable-object/wal.js.map +1 -1
- package/dist/index.d.ts +379 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +379 -7
- package/dist/index.js.map +1 -1
- package/dist/mcp/adapter.d.ts +579 -38
- package/dist/mcp/adapter.d.ts.map +1 -1
- package/dist/mcp/adapter.js +426 -33
- package/dist/mcp/adapter.js.map +1 -1
- package/dist/mcp/sandbox.d.ts +532 -29
- package/dist/mcp/sandbox.d.ts.map +1 -1
- package/dist/mcp/sandbox.js +389 -22
- package/dist/mcp/sandbox.js.map +1 -1
- package/dist/mcp/sdk-adapter.d.ts +478 -56
- package/dist/mcp/sdk-adapter.d.ts.map +1 -1
- package/dist/mcp/sdk-adapter.js +346 -44
- package/dist/mcp/sdk-adapter.js.map +1 -1
- package/dist/mcp/tools.d.ts +445 -30
- package/dist/mcp/tools.d.ts.map +1 -1
- package/dist/mcp/tools.js +363 -33
- package/dist/mcp/tools.js.map +1 -1
- package/dist/ops/blame.d.ts +424 -21
- package/dist/ops/blame.d.ts.map +1 -1
- package/dist/ops/blame.js +303 -20
- package/dist/ops/blame.js.map +1 -1
- package/dist/ops/branch.d.ts +583 -32
- package/dist/ops/branch.d.ts.map +1 -1
- package/dist/ops/branch.js +365 -23
- package/dist/ops/branch.js.map +1 -1
- package/dist/ops/commit-traversal.d.ts +164 -24
- package/dist/ops/commit-traversal.d.ts.map +1 -1
- package/dist/ops/commit-traversal.js +68 -2
- package/dist/ops/commit-traversal.js.map +1 -1
- package/dist/ops/commit.d.ts +387 -53
- package/dist/ops/commit.d.ts.map +1 -1
- package/dist/ops/commit.js +249 -29
- package/dist/ops/commit.js.map +1 -1
- package/dist/ops/merge-base.d.ts +195 -21
- package/dist/ops/merge-base.d.ts.map +1 -1
- package/dist/ops/merge-base.js +122 -12
- package/dist/ops/merge-base.js.map +1 -1
- package/dist/ops/merge.d.ts +600 -130
- package/dist/ops/merge.d.ts.map +1 -1
- package/dist/ops/merge.js +408 -60
- package/dist/ops/merge.js.map +1 -1
- package/dist/ops/tag.d.ts +67 -2
- package/dist/ops/tag.d.ts.map +1 -1
- package/dist/ops/tag.js +42 -1
- package/dist/ops/tag.js.map +1 -1
- package/dist/ops/tree-builder.d.ts +102 -6
- package/dist/ops/tree-builder.d.ts.map +1 -1
- package/dist/ops/tree-builder.js +30 -5
- package/dist/ops/tree-builder.js.map +1 -1
- package/dist/ops/tree-diff.d.ts +50 -2
- package/dist/ops/tree-diff.d.ts.map +1 -1
- package/dist/ops/tree-diff.js +50 -2
- package/dist/ops/tree-diff.js.map +1 -1
- package/dist/pack/delta.d.ts +211 -39
- package/dist/pack/delta.d.ts.map +1 -1
- package/dist/pack/delta.js +232 -46
- package/dist/pack/delta.js.map +1 -1
- package/dist/pack/format.d.ts +390 -28
- package/dist/pack/format.d.ts.map +1 -1
- package/dist/pack/format.js +344 -33
- package/dist/pack/format.js.map +1 -1
- package/dist/pack/full-generation.d.ts +313 -28
- package/dist/pack/full-generation.d.ts.map +1 -1
- package/dist/pack/full-generation.js +238 -19
- package/dist/pack/full-generation.js.map +1 -1
- package/dist/pack/generation.d.ts +346 -23
- package/dist/pack/generation.d.ts.map +1 -1
- package/dist/pack/generation.js +269 -21
- package/dist/pack/generation.js.map +1 -1
- package/dist/pack/index.d.ts +407 -86
- package/dist/pack/index.d.ts.map +1 -1
- package/dist/pack/index.js +351 -70
- package/dist/pack/index.js.map +1 -1
- package/dist/refs/branch.d.ts +517 -71
- package/dist/refs/branch.d.ts.map +1 -1
- package/dist/refs/branch.js +410 -26
- package/dist/refs/branch.js.map +1 -1
- package/dist/refs/storage.d.ts +610 -57
- package/dist/refs/storage.d.ts.map +1 -1
- package/dist/refs/storage.js +481 -29
- package/dist/refs/storage.js.map +1 -1
- package/dist/refs/tag.d.ts +677 -67
- package/dist/refs/tag.d.ts.map +1 -1
- package/dist/refs/tag.js +497 -30
- package/dist/refs/tag.js.map +1 -1
- package/dist/storage/lru-cache.d.ts +556 -53
- package/dist/storage/lru-cache.d.ts.map +1 -1
- package/dist/storage/lru-cache.js +439 -36
- package/dist/storage/lru-cache.js.map +1 -1
- package/dist/storage/object-index.d.ts +483 -38
- package/dist/storage/object-index.d.ts.map +1 -1
- package/dist/storage/object-index.js +388 -22
- package/dist/storage/object-index.js.map +1 -1
- package/dist/storage/r2-pack.d.ts +957 -94
- package/dist/storage/r2-pack.d.ts.map +1 -1
- package/dist/storage/r2-pack.js +756 -48
- package/dist/storage/r2-pack.js.map +1 -1
- package/dist/tiered/cdc-pipeline.d.ts +1610 -38
- package/dist/tiered/cdc-pipeline.d.ts.map +1 -1
- package/dist/tiered/cdc-pipeline.js +1131 -22
- package/dist/tiered/cdc-pipeline.js.map +1 -1
- package/dist/tiered/migration.d.ts +903 -41
- package/dist/tiered/migration.d.ts.map +1 -1
- package/dist/tiered/migration.js +646 -24
- package/dist/tiered/migration.js.map +1 -1
- package/dist/tiered/parquet-writer.d.ts +944 -47
- package/dist/tiered/parquet-writer.d.ts.map +1 -1
- package/dist/tiered/parquet-writer.js +667 -39
- package/dist/tiered/parquet-writer.js.map +1 -1
- package/dist/tiered/read-path.d.ts +728 -34
- package/dist/tiered/read-path.d.ts.map +1 -1
- package/dist/tiered/read-path.js +310 -27
- package/dist/tiered/read-path.js.map +1 -1
- package/dist/types/objects.d.ts +457 -0
- package/dist/types/objects.d.ts.map +1 -1
- package/dist/types/objects.js +305 -4
- package/dist/types/objects.js.map +1 -1
- package/dist/types/storage.d.ts +407 -35
- package/dist/types/storage.d.ts.map +1 -1
- package/dist/types/storage.js +27 -3
- package/dist/types/storage.js.map +1 -1
- package/dist/utils/hash.d.ts +133 -12
- package/dist/utils/hash.d.ts.map +1 -1
- package/dist/utils/hash.js +133 -12
- package/dist/utils/hash.js.map +1 -1
- package/dist/utils/sha1.d.ts +102 -9
- package/dist/utils/sha1.d.ts.map +1 -1
- package/dist/utils/sha1.js +114 -11
- package/dist/utils/sha1.js.map +1 -1
- package/dist/wire/capabilities.d.ts +896 -88
- package/dist/wire/capabilities.d.ts.map +1 -1
- package/dist/wire/capabilities.js +566 -62
- package/dist/wire/capabilities.js.map +1 -1
- package/dist/wire/pkt-line.d.ts +293 -15
- package/dist/wire/pkt-line.d.ts.map +1 -1
- package/dist/wire/pkt-line.js +251 -15
- package/dist/wire/pkt-line.js.map +1 -1
- package/dist/wire/receive-pack.d.ts +814 -64
- package/dist/wire/receive-pack.d.ts.map +1 -1
- package/dist/wire/receive-pack.js +542 -41
- package/dist/wire/receive-pack.js.map +1 -1
- package/dist/wire/smart-http.d.ts +575 -97
- package/dist/wire/smart-http.d.ts.map +1 -1
- package/dist/wire/smart-http.js +337 -46
- package/dist/wire/smart-http.js.map +1 -1
- package/dist/wire/upload-pack.d.ts +492 -98
- package/dist/wire/upload-pack.d.ts.map +1 -1
- package/dist/wire/upload-pack.js +347 -59
- package/dist/wire/upload-pack.js.map +1 -1
- package/package.json +10 -2
|
@@ -1,17 +1,205 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Database Schema for Git Object Storage
|
|
3
|
+
*
|
|
4
|
+
* This module defines the SQLite schema used for storing Git objects and related
|
|
5
|
+
* data in Cloudflare Durable Objects. It provides schema initialization, version
|
|
6
|
+
* management, and validation.
|
|
7
|
+
*
|
|
8
|
+
* **Tables**:
|
|
9
|
+
* - `objects`: Main Git object storage (blobs, trees, commits, tags)
|
|
10
|
+
* - `object_index`: Tiered storage location index
|
|
11
|
+
* - `hot_objects`: Frequently accessed objects cache
|
|
12
|
+
* - `wal`: Write-ahead log for durability
|
|
13
|
+
* - `refs`: Git references (branches, tags, HEAD)
|
|
14
|
+
*
|
|
15
|
+
* @module durable-object/schema
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* import { SchemaManager, DurableObjectStorage } from './durable-object/schema'
|
|
20
|
+
*
|
|
21
|
+
* // Initialize schema on first access
|
|
22
|
+
* const schemaManager = new SchemaManager(storage)
|
|
23
|
+
* await schemaManager.initializeSchema()
|
|
24
|
+
*
|
|
25
|
+
* // Verify schema is valid
|
|
26
|
+
* if (await schemaManager.validateSchema()) {
|
|
27
|
+
* console.log('Schema is ready')
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
/**
|
|
32
|
+
* Interface representing Durable Object storage with SQL capabilities.
|
|
33
|
+
*
|
|
34
|
+
* @description
|
|
35
|
+
* Abstraction over Cloudflare's Durable Object storage that provides
|
|
36
|
+
* SQLite access. This interface allows for easy mocking in tests.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* const storage: DurableObjectStorage = {
|
|
41
|
+
* sql: {
|
|
42
|
+
* exec(query: string, ...params: unknown[]) {
|
|
43
|
+
* // Execute SQL and return results
|
|
44
|
+
* return { toArray: () => [] }
|
|
45
|
+
* }
|
|
46
|
+
* }
|
|
47
|
+
* }
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
1
50
|
export interface DurableObjectStorage {
|
|
51
|
+
/**
|
|
52
|
+
* SQL execution interface.
|
|
53
|
+
*
|
|
54
|
+
* @description
|
|
55
|
+
* Provides access to SQLite query execution within the Durable Object.
|
|
56
|
+
*/
|
|
2
57
|
sql: {
|
|
58
|
+
/**
|
|
59
|
+
* Execute a SQL query with optional parameters.
|
|
60
|
+
*
|
|
61
|
+
* @param query - SQL query string (can use ? placeholders)
|
|
62
|
+
* @param params - Parameter values for placeholders
|
|
63
|
+
* @returns Result object with toArray() method for reading rows
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```typescript
|
|
67
|
+
* const result = storage.sql.exec(
|
|
68
|
+
* 'SELECT * FROM objects WHERE sha = ?',
|
|
69
|
+
* 'abc123...'
|
|
70
|
+
* )
|
|
71
|
+
* const rows = result.toArray()
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
3
74
|
exec(query: string, ...params: unknown[]): {
|
|
4
75
|
toArray(): unknown[];
|
|
5
76
|
};
|
|
6
77
|
};
|
|
7
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* Current schema version number.
|
|
81
|
+
*
|
|
82
|
+
* @description
|
|
83
|
+
* Increment this when making schema changes that require migration.
|
|
84
|
+
* Used for schema validation and upgrade detection.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```typescript
|
|
88
|
+
* const version = await schemaManager.getSchemaVersion()
|
|
89
|
+
* if (version < SCHEMA_VERSION) {
|
|
90
|
+
* // Perform migration
|
|
91
|
+
* }
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
8
94
|
export declare const SCHEMA_VERSION = 1;
|
|
95
|
+
/**
|
|
96
|
+
* Complete SQL schema definition.
|
|
97
|
+
*
|
|
98
|
+
* @description
|
|
99
|
+
* Contains all CREATE TABLE and CREATE INDEX statements for the
|
|
100
|
+
* Git object storage database. Uses IF NOT EXISTS for idempotency.
|
|
101
|
+
*
|
|
102
|
+
* **Tables**:
|
|
103
|
+
* - `objects`: Primary object storage with SHA as primary key
|
|
104
|
+
* - `object_index`: Tracks object locations across storage tiers
|
|
105
|
+
* - `hot_objects`: Cache for frequently accessed objects
|
|
106
|
+
* - `wal`: Write-ahead log for crash recovery
|
|
107
|
+
* - `refs`: Git references (branches, tags, symbolic refs)
|
|
108
|
+
*
|
|
109
|
+
* **Indexes**:
|
|
110
|
+
* - `idx_objects_type`: Fast lookup by object type
|
|
111
|
+
* - `idx_wal_flushed`: Find unflushed WAL entries
|
|
112
|
+
* - `idx_hot_objects_accessed`: LRU eviction ordering
|
|
113
|
+
*/
|
|
9
114
|
export declare const SCHEMA_SQL = "\n-- Git objects (blobs, trees, commits, tags)\nCREATE TABLE IF NOT EXISTS objects (sha TEXT PRIMARY KEY, type TEXT NOT NULL, size INTEGER NOT NULL, data BLOB NOT NULL, created_at INTEGER);\n\n-- Object location index for tiered storage\nCREATE TABLE IF NOT EXISTS object_index (sha TEXT PRIMARY KEY, tier TEXT NOT NULL DEFAULT 'hot', location TEXT NOT NULL DEFAULT 'local', size INTEGER, type TEXT);\n\n-- Hot objects cache\nCREATE TABLE IF NOT EXISTS hot_objects (sha TEXT PRIMARY KEY, type TEXT NOT NULL, data BLOB NOT NULL, accessed_at INTEGER, created_at INTEGER);\n\n-- Write-ahead log\nCREATE TABLE IF NOT EXISTS wal (id INTEGER PRIMARY KEY AUTOINCREMENT, operation TEXT NOT NULL, payload BLOB NOT NULL, created_at INTEGER, flushed INTEGER DEFAULT 0);\n\n-- Refs table\nCREATE TABLE IF NOT EXISTS refs (name TEXT PRIMARY KEY, target TEXT NOT NULL, type TEXT DEFAULT 'sha', updated_at INTEGER);\n\n-- Indexes\nCREATE INDEX IF NOT EXISTS idx_objects_type ON objects(type);\nCREATE INDEX IF NOT EXISTS idx_wal_flushed ON wal(flushed);\nCREATE INDEX IF NOT EXISTS idx_hot_objects_accessed ON hot_objects(accessed_at);\n";
|
|
115
|
+
/**
|
|
116
|
+
* Manager for database schema initialization and validation.
|
|
117
|
+
*
|
|
118
|
+
* @description
|
|
119
|
+
* Handles schema lifecycle including initialization, version checking,
|
|
120
|
+
* and validation. Should be used when first accessing a Durable Object
|
|
121
|
+
* to ensure the schema is properly set up.
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* ```typescript
|
|
125
|
+
* class GitDurableObject implements DurableObject {
|
|
126
|
+
* private schemaManager: SchemaManager
|
|
127
|
+
* private initialized = false
|
|
128
|
+
*
|
|
129
|
+
* constructor(state: DurableObjectState) {
|
|
130
|
+
* this.schemaManager = new SchemaManager(state.storage)
|
|
131
|
+
* }
|
|
132
|
+
*
|
|
133
|
+
* private async ensureInitialized() {
|
|
134
|
+
* if (!this.initialized) {
|
|
135
|
+
* await this.schemaManager.initializeSchema()
|
|
136
|
+
* this.initialized = true
|
|
137
|
+
* }
|
|
138
|
+
* }
|
|
139
|
+
*
|
|
140
|
+
* async fetch(request: Request) {
|
|
141
|
+
* await this.ensureInitialized()
|
|
142
|
+
* // ... handle request
|
|
143
|
+
* }
|
|
144
|
+
* }
|
|
145
|
+
* ```
|
|
146
|
+
*/
|
|
10
147
|
export declare class SchemaManager {
|
|
11
148
|
private storage;
|
|
149
|
+
/**
|
|
150
|
+
* Create a new SchemaManager.
|
|
151
|
+
*
|
|
152
|
+
* @param storage - Durable Object storage interface
|
|
153
|
+
*/
|
|
12
154
|
constructor(storage: DurableObjectStorage);
|
|
155
|
+
/**
|
|
156
|
+
* Initialize the database schema.
|
|
157
|
+
*
|
|
158
|
+
* @description
|
|
159
|
+
* Creates all required tables and indexes if they don't exist.
|
|
160
|
+
* This operation is idempotent - safe to call multiple times.
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* ```typescript
|
|
164
|
+
* await schemaManager.initializeSchema()
|
|
165
|
+
* ```
|
|
166
|
+
*/
|
|
13
167
|
initializeSchema(): Promise<void>;
|
|
168
|
+
/**
|
|
169
|
+
* Get the current schema version.
|
|
170
|
+
*
|
|
171
|
+
* @description
|
|
172
|
+
* Returns the schema version if valid, or 0 if schema is missing/invalid.
|
|
173
|
+
* Use this to detect when schema migration is needed.
|
|
174
|
+
*
|
|
175
|
+
* @returns Schema version number (0 if invalid/missing)
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
* ```typescript
|
|
179
|
+
* const version = await schemaManager.getSchemaVersion()
|
|
180
|
+
* console.log(`Schema version: ${version}`)
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
14
183
|
getSchemaVersion(): Promise<number>;
|
|
184
|
+
/**
|
|
185
|
+
* Validate that all required tables exist.
|
|
186
|
+
*
|
|
187
|
+
* @description
|
|
188
|
+
* Checks the sqlite_master table to verify all required tables
|
|
189
|
+
* are present. Returns false if any tables are missing.
|
|
190
|
+
*
|
|
191
|
+
* @returns True if schema is valid and complete
|
|
192
|
+
*
|
|
193
|
+
* @example
|
|
194
|
+
* ```typescript
|
|
195
|
+
* if (await schemaManager.validateSchema()) {
|
|
196
|
+
* console.log('Schema is valid')
|
|
197
|
+
* } else {
|
|
198
|
+
* console.log('Schema needs initialization')
|
|
199
|
+
* await schemaManager.initializeSchema()
|
|
200
|
+
* }
|
|
201
|
+
* ```
|
|
202
|
+
*/
|
|
15
203
|
validateSchema(): Promise<boolean>;
|
|
16
204
|
}
|
|
17
205
|
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/durable-object/schema.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,oBAAoB;IACnC,GAAG,EAAE;QACH,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,GAAG;YAAE,OAAO,IAAI,OAAO,EAAE,CAAA;SAAE,CAAA;KACpE,CAAA;CACF;
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/durable-object/schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAMH;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,WAAW,oBAAoB;IACnC;;;;;OAKG;IACH,GAAG,EAAE;QACH;;;;;;;;;;;;;;;WAeG;QACH,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,GAAG;YAAE,OAAO,IAAI,OAAO,EAAE,CAAA;SAAE,CAAA;KACpE,CAAA;CACF;AAMD;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,cAAc,IAAI,CAAA;AAE/B;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,UAAU,umCAoBtB,CAAA;AAeD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,qBAAa,aAAa;IAMZ,OAAO,CAAC,OAAO;IAL3B;;;;OAIG;gBACiB,OAAO,EAAE,oBAAoB;IAEjD;;;;;;;;;;;OAWG;IACG,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC;IAIvC;;;;;;;;;;;;;;OAcG;IACG,gBAAgB,IAAI,OAAO,CAAC,MAAM,CAAC;IAKzC;;;;;;;;;;;;;;;;;;OAkBG;IACG,cAAc,IAAI,OAAO,CAAC,OAAO,CAAC;CASzC"}
|
|
@@ -1,4 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Database Schema for Git Object Storage
|
|
3
|
+
*
|
|
4
|
+
* This module defines the SQLite schema used for storing Git objects and related
|
|
5
|
+
* data in Cloudflare Durable Objects. It provides schema initialization, version
|
|
6
|
+
* management, and validation.
|
|
7
|
+
*
|
|
8
|
+
* **Tables**:
|
|
9
|
+
* - `objects`: Main Git object storage (blobs, trees, commits, tags)
|
|
10
|
+
* - `object_index`: Tiered storage location index
|
|
11
|
+
* - `hot_objects`: Frequently accessed objects cache
|
|
12
|
+
* - `wal`: Write-ahead log for durability
|
|
13
|
+
* - `refs`: Git references (branches, tags, HEAD)
|
|
14
|
+
*
|
|
15
|
+
* @module durable-object/schema
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* import { SchemaManager, DurableObjectStorage } from './durable-object/schema'
|
|
20
|
+
*
|
|
21
|
+
* // Initialize schema on first access
|
|
22
|
+
* const schemaManager = new SchemaManager(storage)
|
|
23
|
+
* await schemaManager.initializeSchema()
|
|
24
|
+
*
|
|
25
|
+
* // Verify schema is valid
|
|
26
|
+
* if (await schemaManager.validateSchema()) {
|
|
27
|
+
* console.log('Schema is ready')
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
// ============================================================================
|
|
32
|
+
// Schema Constants
|
|
33
|
+
// ============================================================================
|
|
34
|
+
/**
|
|
35
|
+
* Current schema version number.
|
|
36
|
+
*
|
|
37
|
+
* @description
|
|
38
|
+
* Increment this when making schema changes that require migration.
|
|
39
|
+
* Used for schema validation and upgrade detection.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* const version = await schemaManager.getSchemaVersion()
|
|
44
|
+
* if (version < SCHEMA_VERSION) {
|
|
45
|
+
* // Perform migration
|
|
46
|
+
* }
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
1
49
|
export const SCHEMA_VERSION = 1;
|
|
50
|
+
/**
|
|
51
|
+
* Complete SQL schema definition.
|
|
52
|
+
*
|
|
53
|
+
* @description
|
|
54
|
+
* Contains all CREATE TABLE and CREATE INDEX statements for the
|
|
55
|
+
* Git object storage database. Uses IF NOT EXISTS for idempotency.
|
|
56
|
+
*
|
|
57
|
+
* **Tables**:
|
|
58
|
+
* - `objects`: Primary object storage with SHA as primary key
|
|
59
|
+
* - `object_index`: Tracks object locations across storage tiers
|
|
60
|
+
* - `hot_objects`: Cache for frequently accessed objects
|
|
61
|
+
* - `wal`: Write-ahead log for crash recovery
|
|
62
|
+
* - `refs`: Git references (branches, tags, symbolic refs)
|
|
63
|
+
*
|
|
64
|
+
* **Indexes**:
|
|
65
|
+
* - `idx_objects_type`: Fast lookup by object type
|
|
66
|
+
* - `idx_wal_flushed`: Find unflushed WAL entries
|
|
67
|
+
* - `idx_hot_objects_accessed`: LRU eviction ordering
|
|
68
|
+
*/
|
|
2
69
|
export const SCHEMA_SQL = `
|
|
3
70
|
-- Git objects (blobs, trees, commits, tags)
|
|
4
71
|
CREATE TABLE IF NOT EXISTS objects (sha TEXT PRIMARY KEY, type TEXT NOT NULL, size INTEGER NOT NULL, data BLOB NOT NULL, created_at INTEGER);
|
|
@@ -20,19 +87,112 @@ CREATE INDEX IF NOT EXISTS idx_objects_type ON objects(type);
|
|
|
20
87
|
CREATE INDEX IF NOT EXISTS idx_wal_flushed ON wal(flushed);
|
|
21
88
|
CREATE INDEX IF NOT EXISTS idx_hot_objects_accessed ON hot_objects(accessed_at);
|
|
22
89
|
`;
|
|
90
|
+
/**
|
|
91
|
+
* List of required tables for schema validation.
|
|
92
|
+
*
|
|
93
|
+
* @description
|
|
94
|
+
* Used by validateSchema() to verify all required tables exist.
|
|
95
|
+
* @internal
|
|
96
|
+
*/
|
|
23
97
|
const REQUIRED_TABLES = ['objects', 'object_index', 'hot_objects', 'wal', 'refs'];
|
|
98
|
+
// ============================================================================
|
|
99
|
+
// SchemaManager Class
|
|
100
|
+
// ============================================================================
|
|
101
|
+
/**
|
|
102
|
+
* Manager for database schema initialization and validation.
|
|
103
|
+
*
|
|
104
|
+
* @description
|
|
105
|
+
* Handles schema lifecycle including initialization, version checking,
|
|
106
|
+
* and validation. Should be used when first accessing a Durable Object
|
|
107
|
+
* to ensure the schema is properly set up.
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```typescript
|
|
111
|
+
* class GitDurableObject implements DurableObject {
|
|
112
|
+
* private schemaManager: SchemaManager
|
|
113
|
+
* private initialized = false
|
|
114
|
+
*
|
|
115
|
+
* constructor(state: DurableObjectState) {
|
|
116
|
+
* this.schemaManager = new SchemaManager(state.storage)
|
|
117
|
+
* }
|
|
118
|
+
*
|
|
119
|
+
* private async ensureInitialized() {
|
|
120
|
+
* if (!this.initialized) {
|
|
121
|
+
* await this.schemaManager.initializeSchema()
|
|
122
|
+
* this.initialized = true
|
|
123
|
+
* }
|
|
124
|
+
* }
|
|
125
|
+
*
|
|
126
|
+
* async fetch(request: Request) {
|
|
127
|
+
* await this.ensureInitialized()
|
|
128
|
+
* // ... handle request
|
|
129
|
+
* }
|
|
130
|
+
* }
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
24
133
|
export class SchemaManager {
|
|
25
134
|
storage;
|
|
135
|
+
/**
|
|
136
|
+
* Create a new SchemaManager.
|
|
137
|
+
*
|
|
138
|
+
* @param storage - Durable Object storage interface
|
|
139
|
+
*/
|
|
26
140
|
constructor(storage) {
|
|
27
141
|
this.storage = storage;
|
|
28
142
|
}
|
|
143
|
+
/**
|
|
144
|
+
* Initialize the database schema.
|
|
145
|
+
*
|
|
146
|
+
* @description
|
|
147
|
+
* Creates all required tables and indexes if they don't exist.
|
|
148
|
+
* This operation is idempotent - safe to call multiple times.
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* ```typescript
|
|
152
|
+
* await schemaManager.initializeSchema()
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
29
155
|
async initializeSchema() {
|
|
30
156
|
this.storage.sql.exec(SCHEMA_SQL);
|
|
31
157
|
}
|
|
158
|
+
/**
|
|
159
|
+
* Get the current schema version.
|
|
160
|
+
*
|
|
161
|
+
* @description
|
|
162
|
+
* Returns the schema version if valid, or 0 if schema is missing/invalid.
|
|
163
|
+
* Use this to detect when schema migration is needed.
|
|
164
|
+
*
|
|
165
|
+
* @returns Schema version number (0 if invalid/missing)
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* ```typescript
|
|
169
|
+
* const version = await schemaManager.getSchemaVersion()
|
|
170
|
+
* console.log(`Schema version: ${version}`)
|
|
171
|
+
* ```
|
|
172
|
+
*/
|
|
32
173
|
async getSchemaVersion() {
|
|
33
174
|
const isValid = await this.validateSchema();
|
|
34
175
|
return isValid ? SCHEMA_VERSION : 0;
|
|
35
176
|
}
|
|
177
|
+
/**
|
|
178
|
+
* Validate that all required tables exist.
|
|
179
|
+
*
|
|
180
|
+
* @description
|
|
181
|
+
* Checks the sqlite_master table to verify all required tables
|
|
182
|
+
* are present. Returns false if any tables are missing.
|
|
183
|
+
*
|
|
184
|
+
* @returns True if schema is valid and complete
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* ```typescript
|
|
188
|
+
* if (await schemaManager.validateSchema()) {
|
|
189
|
+
* console.log('Schema is valid')
|
|
190
|
+
* } else {
|
|
191
|
+
* console.log('Schema needs initialization')
|
|
192
|
+
* await schemaManager.initializeSchema()
|
|
193
|
+
* }
|
|
194
|
+
* ```
|
|
195
|
+
*/
|
|
36
196
|
async validateSchema() {
|
|
37
197
|
const result = this.storage.sql.exec("SELECT name FROM sqlite_master WHERE type='table'");
|
|
38
198
|
const tables = result.toArray();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/durable-object/schema.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/durable-object/schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAqDH,+EAA+E;AAC/E,mBAAmB;AACnB,+EAA+E;AAE/E;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAA;AAE/B;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG;;;;;;;;;;;;;;;;;;;;CAoBzB,CAAA;AAED;;;;;;GAMG;AACH,MAAM,eAAe,GAAG,CAAC,SAAS,EAAE,cAAc,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,CAAC,CAAA;AAEjF,+EAA+E;AAC/E,sBAAsB;AACtB,+EAA+E;AAE/E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,OAAO,aAAa;IAMJ;IALpB;;;;OAIG;IACH,YAAoB,OAA6B;QAA7B,YAAO,GAAP,OAAO,CAAsB;IAAG,CAAC;IAErD;;;;;;;;;;;OAWG;IACH,KAAK,CAAC,gBAAgB;QACpB,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;IACnC,CAAC;IAED;;;;;;;;;;;;;;OAcG;IACH,KAAK,CAAC,gBAAgB;QACpB,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,cAAc,EAAE,CAAA;QAC3C,OAAO,OAAO,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAA;IACrC,CAAC;IAED;;;;;;;;;;;;;;;;;;OAkBG;IACH,KAAK,CAAC,cAAc;QAClB,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAClC,mDAAmD,CACpD,CAAA;QACD,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,EAAwB,CAAA;QACrD,MAAM,UAAU,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAA;QAE1C,OAAO,eAAe,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAA;IACnE,CAAC;CACF"}
|