@joystick.js/db-canary 0.0.0-canary.2209 → 0.0.0-canary.2211

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.
@@ -9,6 +9,11 @@
9
9
  "date": 1757695098702,
10
10
  "name": "/Users/rglover/projects/cheatcode/joystick/db/logs/main-2025-09-12.log",
11
11
  "hash": "09b824ee9031536943147f8cd486f3e291f453826ae964195412d61608c6a17f"
12
+ },
13
+ {
14
+ "date": 1757979673373,
15
+ "name": "/Users/rglover/projects/cheatcode/joystick/db/logs/main-2025-09-15.log",
16
+ "hash": "66351e3ec6c4022c2384f345531c5bcf0bc18f6ad79d009e6a2b8937fe4698f9"
12
17
  }
13
18
  ],
14
19
  "hashType": "sha256"
@@ -9,6 +9,11 @@
9
9
  "date": 1757695098703,
10
10
  "name": "/Users/rglover/projects/cheatcode/joystick/db/logs/main-error-2025-09-12.log",
11
11
  "hash": "e5a1c364fc2014f8ec030a36ebae89c478581da7da9619c6e0595259f79e7cf7"
12
+ },
13
+ {
14
+ "date": 1757979673374,
15
+ "name": "/Users/rglover/projects/cheatcode/joystick/db/logs/main-error-2025-09-15.log",
16
+ "hash": "d55a440dea04460e572c057ed87eb73e97dcd888728cf566f8d63f94b1a5ef91"
12
17
  }
13
18
  ],
14
19
  "hashType": "sha256"
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@joystick.js/db-canary",
3
3
  "type": "module",
4
- "version": "0.0.0-canary.2209",
5
- "canary_version": "0.0.0-canary.2208",
4
+ "version": "0.0.0-canary.2211",
5
+ "canary_version": "0.0.0-canary.2210",
6
6
  "description": "JoystickDB - A minimalist database server for the Joystick framework",
7
7
  "main": "./dist/index.js",
8
8
  "scripts": {
@@ -0,0 +1,129 @@
1
+ # Task 22: Build Script Integration for CLI and Node Packages
2
+
3
+ ## Objective
4
+ Integrate JoystickDB components into the CLI and Node packages by modifying their build scripts to copy the necessary database code before building, and updating their package.json files with required dependencies.
5
+
6
+ ## Current State
7
+ - JoystickDB is fully implemented in `/Users/rglover/projects/cheatcode/joystick/db`
8
+ - CLI package needs server components for development database functionality
9
+ - Node package needs client components for database connectivity
10
+ - Both packages use esbuild with `bundle: false` configuration
11
+ - Current build scripts do not include database code integration
12
+
13
+ ## Requirements
14
+
15
+ ### 1. CLI Package Integration
16
+ **Target**: `/Users/rglover/projects/cheatcode/joystick/cli`
17
+
18
+ **Build Script Updates** (`cli/.build/index.js`):
19
+ - Copy `db/dist/server/` → `cli/src/lib/joystickdb/` before building CLI files
20
+ - Ensure copying happens before the existing build process
21
+ - Use proper error handling for copy operations
22
+ - Create target directories if they don't exist
23
+
24
+ **Package.json Updates** (`cli/package.json`):
25
+ - Add JoystickDB server dependencies to `dependencies`:
26
+ - `"lmdb": "^3.4.2"`
27
+ - `"msgpackr": "^1.11.5"`
28
+ - `"bcrypt": "^6.0.0"`
29
+ - `"winston": "^3.17.0"`
30
+ - `"winston-daily-rotate-file": "^5.0.0"`
31
+ - `"@aws-sdk/client-s3": "^3.879.0"`
32
+
33
+ ### 2. Node Package Integration
34
+ **Target**: `/Users/rglover/projects/cheatcode/joystick/node`
35
+
36
+ **Build Script Updates** (`node/.build/index.js`):
37
+ - Copy `db/dist/client/` → `node/src/lib/joystickdb/` before building Node files
38
+ - Ensure copying happens before the existing build process
39
+ - Use proper error handling for copy operations
40
+ - Create target directories if they don't exist
41
+
42
+ **Package.json Updates** (`node/package.json`):
43
+ - Add JoystickDB client dependencies to `dependencies`:
44
+ - `"msgpackr": "^1.11.5"`
45
+
46
+ ## Implementation Details
47
+
48
+ ### Copy Operation Requirements
49
+ - Use Node.js `fs` module with recursive directory copying
50
+ - Preserve file structure and permissions
51
+ - Handle existing directories (clean and recreate)
52
+ - Provide clear error messages if source directories don't exist
53
+ - Log copy operations for debugging
54
+
55
+ ### Build Process Flow
56
+ **CLI Build Process**:
57
+ 1. Clean existing `cli/src/lib/joystickdb/` directory
58
+ 2. Copy `db/dist/server/` → `cli/src/lib/joystickdb/`
59
+ 3. Proceed with existing CLI build process (getFilesToBuild, buildFiles, copyFiles)
60
+
61
+ **Node Build Process**:
62
+ 1. Clean existing `node/src/lib/joystickdb/` directory
63
+ 2. Copy `db/dist/client/` → `node/src/lib/joystickdb/`
64
+ 3. Proceed with existing Node build process (getFilesToBuild, buildFiles, copyFiles)
65
+
66
+ ### Error Handling
67
+ - Graceful handling of missing source directories
68
+ - Clear error messages indicating which copy operation failed
69
+ - Build process should fail if database code copying fails
70
+ - Provide guidance on running `npm run build` in db package first
71
+
72
+ ### Import Path Consistency
73
+ After integration, code can import database functionality using:
74
+ - **CLI**: `import dbServer from './lib/joystickdb/index.js'`
75
+ - **Node**: `import dbClient from './lib/joystickdb/index.js'`
76
+
77
+ ## Code Standards
78
+ - Follow existing build script patterns in both packages
79
+ - Use ESM syntax (`import`/`export`)
80
+ - Follow snake_case for variables and functions
81
+ - Two-space indentation
82
+ - Minimal comments (only when necessary for clarity)
83
+ - Maintain compatibility with existing build processes
84
+
85
+ ## Dependencies Management
86
+ - Only add dependencies that are actually used by the copied code
87
+ - CLI gets full server dependencies (including binary modules)
88
+ - Node gets lightweight client dependencies only
89
+ - Maintain version consistency with db package
90
+ - Update package-lock.json files after dependency changes
91
+
92
+ ## Testing Requirements
93
+ - Verify build scripts run without errors after modifications
94
+ - Confirm copied files are present in expected locations
95
+ - Test that built packages include database functionality
96
+ - Ensure existing CLI and Node functionality remains intact
97
+ - Verify dependency installation works correctly
98
+
99
+ ## Branch Management
100
+ - Create feature branch: `feature/build-script-integration`
101
+ - All work must be done in this branch
102
+ - No direct commits to master or canary branch
103
+ - Merge only when all build processes work correctly
104
+
105
+ ## Success Criteria
106
+ - ✅ CLI build script copies database server code before building
107
+ - ✅ Node build script copies database client code before building
108
+ - ✅ CLI package.json includes all necessary database server dependencies
109
+ - ✅ Node package.json includes necessary database client dependencies
110
+ - ✅ Build processes complete without errors
111
+ - ✅ Copied database code is available at expected import paths
112
+ - ✅ Existing CLI and Node functionality remains unaffected
113
+ - ✅ Package-lock.json files are properly updated
114
+
115
+ ## Implementation Notes
116
+ - The db package must be built first (`npm run build` in db folder) to generate the dist files
117
+ - Copy operations should use the built/dist versions, not the source files
118
+ - This approach maintains the db folder as the "source of truth" while providing embedded functionality
119
+ - CLI will be heavier due to binary dependencies, but this is acceptable for a development tool
120
+ - Node package remains lightweight with only client functionality
121
+
122
+ ## Future Considerations
123
+ - This integration enables CLI to start database servers in development
124
+ - Node package can connect to databases using embedded client code
125
+ - Standalone db package remains available for production database server deployments
126
+ - Version synchronization across packages will be handled by existing release processes
127
+
128
+ ## Context for Implementation
129
+ This task implements the build-time copying strategy discussed for integrating JoystickDB components into the CLI and Node packages. The approach maintains clean separation while providing embedded functionality without runtime path complexity.
@@ -0,0 +1,268 @@
1
+ # Task 23: CLI Integration for Development Database
2
+
3
+ ## Objective
4
+ Integrate JoystickDB server into the existing CLI package development server infrastructure, enabling JoystickDB to be used alongside MongoDB, PostgreSQL, and Redis with identical developer experience.
5
+
6
+ ## Current State
7
+ - JoystickDB server code successfully copied to `cli/src/lib/development_server/databases/joystickdb/` during build process
8
+ - CLI package includes all required server dependencies (lmdb, msgpackr, bcrypt, winston, etc.)
9
+ - Existing database infrastructure supports MongoDB, PostgreSQL, and Redis via binary execution
10
+ - Database provider map, installer, and connection patterns established
11
+ - JoystickDB runs as standalone Node.js server via `create_server()` function
12
+
13
+ ## Requirements
14
+
15
+ ### 1. JoystickDB Provider Integration
16
+ **Target**: `cli/src/lib/development_server/databases/`
17
+
18
+ **Create JoystickDB Module** (`joystickdb/index.js`):
19
+ - Import JoystickDB server from `./joystickdb/index.js` (copied database code in same directory)
20
+ - Implement `start_joystickdb(port)` function using child_process.spawn()
21
+ - Start JoystickDB as Node.js child process, not binary execution
22
+ - Use `node ./lib/development_server/databases/joystickdb/index.js` pattern (file runs directly)
23
+ - Handle process lifecycle: startup, shutdown, error handling
24
+ - Return process ID for consistency with other databases
25
+
26
+ **Create Connection Module** (`joystickdb/connect.js`):
27
+ - Follow exact pattern of `mongodb/connect.js`, `postgresql/connect.js`, `redis/connect.js`
28
+ - Support both external connections (when `settings.connection` provided) and local development server
29
+ - Return `{ pid, connection }` object matching other database providers
30
+ - Default connection: `{ hostname: "127.0.0.1", port: <port>, database: "app" }`
31
+
32
+ **Create Connection Check** (`joystickdb/check_connection.js`):
33
+ - Implement TCP connection validation to JoystickDB server
34
+ - Follow pattern of other database connection checkers
35
+ - Test basic connectivity and authentication if configured
36
+
37
+ ### 2. Provider Map Registration
38
+ **Target**: `cli/src/lib/development_server/databases/provider_map.js`
39
+
40
+ **Add JoystickDB Entry**:
41
+ ```javascript
42
+ import connect_joystickdb from './joystickdb/connect.js';
43
+
44
+ const provider_map = {
45
+ // ... existing providers
46
+ joystickdb: {
47
+ name: 'JoystickDB',
48
+ connect: connect_joystickdb,
49
+ },
50
+ };
51
+ ```
52
+
53
+ ### 3. Installer Integration
54
+ **Target**: `cli/src/lib/development_server/databases/installer.js`
55
+
56
+ **Skip Binary Installation for JoystickDB**:
57
+ - Modify `install_database()` function to recognize `joystickdb` as special case
58
+ - JoystickDB doesn't require binary download/installation (code already embedded)
59
+ - Return early for `joystickdb` database type without attempting download
60
+ - Add `joystickdb` to supported database list but bypass installation logic
61
+
62
+ ### 4. Child Process Management
63
+ **Implementation Details**:
64
+
65
+ **Process Spawning**:
66
+ - Use `child_process.spawn('node', ['./lib/development_server/databases/joystickdb/index.js'])` (file runs directly)
67
+ - Set `cwd` to CLI package root directory for proper import resolution
68
+ - Configure stdio: `{ stdio: ['pipe', 'pipe', 'pipe'] }` for output capture
69
+ - Handle process startup confirmation via stdout monitoring
70
+ - Set required environment variables (JOYSTICK_DB_SETTINGS) for proper startup
71
+
72
+ **Process Lifecycle**:
73
+ - Monitor stdout for "JoystickDB server started" or similar confirmation message
74
+ - Implement graceful shutdown via process.kill() or SIGTERM
75
+ - Handle process crashes and restart logic if needed
76
+ - Track process ID for port management consistency
77
+
78
+ **Error Handling**:
79
+ - Catch spawn errors (Node.js not found, import failures, etc.)
80
+ - Handle JoystickDB server startup errors (port conflicts, permission issues)
81
+ - Provide clear error messages matching other database error patterns
82
+ - Fallback gracefully if JoystickDB server fails to start
83
+
84
+ ### 5. Port Management Integration
85
+ **Requirements**:
86
+ - Use existing `kill_port_process()` and `get_process_id_from_port()` utilities
87
+ - Default JoystickDB port: `1983` (matching standalone server default)
88
+ - Support custom port configuration via settings
89
+ - Ensure port cleanup on development server shutdown
90
+
91
+ ### 6. Data Directory Management
92
+ **Setup Data Directory**:
93
+ - Create `.joystick/data/joystickdb_<port>/` directory structure
94
+ - Pass data directory path to JoystickDB server via environment variables or settings
95
+ - Follow pattern of MongoDB data directory management
96
+ - Support multiple JoystickDB instances on different ports
97
+
98
+ ### 7. Settings Integration
99
+ **Configuration Support**:
100
+ - Accept JoystickDB settings in same format as other databases
101
+ - Support external connection strings for remote JoystickDB servers
102
+ - Handle authentication settings (password, API keys)
103
+ - Pass settings to JoystickDB server process via environment or config file
104
+
105
+ ### 8. Automated Setup for Development
106
+ **Transparent Setup Process**:
107
+ - Automatically read API_KEY from `./lib/development_server/databases/joystickdb/API_KEY` file
108
+ - Create default admin user automatically on localhost without developer intervention
109
+ - Use HTTP API to create admin user: `POST /api/users` with API key authentication
110
+ - Default admin credentials: `username: 'admin'`, `password: 'password'`
111
+ - Provide clear logging of setup process for debugging
112
+ - Ensure setup happens after server startup confirmation but before returning connection
113
+
114
+ ## Implementation Patterns
115
+
116
+ ### Child Process Pattern
117
+ ```javascript
118
+ const start_joystickdb_process = (joystickdb_port = 1983) => {
119
+ return new Promise((resolve, reject) => {
120
+ const database_process = child_process.spawn('node', [
121
+ './lib/development_server/databases/joystickdb/index.js'
122
+ ], {
123
+ cwd: process.cwd(),
124
+ stdio: ['pipe', 'pipe', 'pipe'],
125
+ env: {
126
+ ...process.env,
127
+ JOYSTICK_DB_SETTINGS: JSON.stringify({
128
+ port: joystickdb_port,
129
+ data_path: `./.joystick/data/joystickdb_${joystickdb_port}`,
130
+ authentication: {}
131
+ })
132
+ }
133
+ });
134
+
135
+ database_process.on('error', reject);
136
+
137
+ database_process.stdout.on('data', (data) => {
138
+ if (data.toString().includes('Starting JoystickDB server')) {
139
+ resolve(database_process.pid);
140
+ }
141
+ });
142
+ });
143
+ };
144
+ ```
145
+
146
+ ### Automated Setup Pattern
147
+ ```javascript
148
+ const setup_joystickdb_admin = async (port = 1983) => {
149
+ try {
150
+ // Read API key from copied database files
151
+ const api_key_path = path.resolve('./lib/development_server/databases/joystickdb/API_KEY');
152
+ const api_key = fs.readFileSync(api_key_path, 'utf8').trim();
153
+
154
+ // Create admin user via HTTP API
155
+ const response = await fetch(`http://localhost:${port + 1}/api/users`, {
156
+ method: 'POST',
157
+ headers: {
158
+ 'Content-Type': 'application/json',
159
+ 'x-joystick-db-api-key': api_key
160
+ },
161
+ body: JSON.stringify({
162
+ username: 'admin',
163
+ password: 'password',
164
+ role: 'read_write'
165
+ })
166
+ });
167
+
168
+ const result = await response.json();
169
+ if (result.success) {
170
+ console.log('✅ JoystickDB admin user created automatically');
171
+ return true;
172
+ } else {
173
+ // User might already exist, which is fine
174
+ if (result.error && result.error.includes('already exists')) {
175
+ console.log('ℹ️ JoystickDB admin user already exists');
176
+ return true;
177
+ }
178
+ throw new Error(result.error || 'Failed to create admin user');
179
+ }
180
+ } catch (error) {
181
+ console.warn('⚠️ JoystickDB admin setup failed:', error.message);
182
+ return false;
183
+ }
184
+ };
185
+ ```
186
+
187
+ ### Connection Pattern
188
+ ```javascript
189
+ const connect = async (settings = {}, port = 1983) => {
190
+ const has_connection = settings.connection && Object.keys(settings.connection).length > 0;
191
+
192
+ if (has_connection) {
193
+ await check_connection(settings.connection, settings.options);
194
+ } else {
195
+ // Start local development server
196
+ const pid = await start_joystickdb(port);
197
+
198
+ // Wait a moment for HTTP server to be ready
199
+ await new Promise(resolve => setTimeout(resolve, 2000));
200
+
201
+ // Automatically setup admin user for development
202
+ await setup_joystickdb_admin(port);
203
+ }
204
+
205
+ return {
206
+ pid: !has_connection ? await start_joystickdb(port) : null,
207
+ connection: has_connection ? settings.connection : {
208
+ hostname: "127.0.0.1",
209
+ port,
210
+ database: "app",
211
+ username: "admin",
212
+ password: "password"
213
+ },
214
+ };
215
+ };
216
+ ```
217
+
218
+ ## Code Standards
219
+ - Follow existing CLI database integration patterns exactly
220
+ - Use ESM syntax (`import`/`export`)
221
+ - Follow snake_case for variables and functions
222
+ - Two-space indentation
223
+ - Minimal comments (only when necessary for clarity)
224
+ - Error handling consistent with other database providers
225
+
226
+ ## Testing Requirements
227
+ - Verify JoystickDB starts as child process successfully
228
+ - Test port management and cleanup
229
+ - Confirm data directory creation and usage
230
+ - Test connection validation and error handling
231
+ - Ensure graceful shutdown of JoystickDB processes
232
+ - Verify integration with existing development server workflow
233
+
234
+ ## Success Criteria
235
+ - ✅ JoystickDB appears in provider map alongside MongoDB, PostgreSQL, Redis
236
+ - ✅ JoystickDB starts as Node.js child process (not binary)
237
+ - ✅ Connection management follows exact pattern of other databases
238
+ - ✅ Port management and cleanup works correctly
239
+ - ✅ Data directory setup and management implemented
240
+ - ✅ Error handling and process lifecycle management robust
241
+ - ✅ No binary installation required (installer skips JoystickDB)
242
+ - ✅ Developer experience identical to other databases
243
+ - ✅ Existing CLI functionality remains unaffected
244
+ - ✅ Automated admin user setup works transparently on localhost
245
+ - ✅ API key reading and HTTP user creation handled automatically
246
+ - ✅ Default admin credentials provided in connection object
247
+
248
+ ## Integration Notes
249
+ - JoystickDB is unique in being a Node.js process rather than external binary
250
+ - Leverage embedded database code from build script integration at `src/lib/development_server/databases/joystickdb/`
251
+ - Maintain consistency with existing database provider patterns
252
+ - This enables seamless database switching in development environments
253
+ - JoystickDB becomes first-class citizen alongside traditional databases
254
+
255
+ ## Future Considerations
256
+ - This integration enables JoystickDB development database functionality
257
+ - Developers can use JoystickDB in development with same ease as MongoDB/PostgreSQL
258
+ - Production deployments still use standalone JoystickDB server package
259
+ - CLI integration provides embedded development database experience
260
+ - Foundation for potential JoystickDB-specific development tools and utilities
261
+
262
+ ## Context for Implementation
263
+ This task completes the JoystickDB integration trilogy:
264
+ 1. ✅ Build script integration (database code copying)
265
+ 2. ✅ Package dependency management
266
+ 3. 🎯 **CLI development server integration** (this task)
267
+
268
+ The result is seamless JoystickDB development experience matching existing database providers while leveraging the unique advantage of embedded Node.js execution rather than binary dependencies.