d1s 0.2.4 → 0.2.6

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 (176) hide show
  1. package/dist/.next/.next/BUILD_ID +1 -1
  2. package/dist/.next/.next/app-build-manifest.json +12 -12
  3. package/dist/.next/.next/app-path-routes-manifest.json +1 -1
  4. package/dist/.next/.next/build-manifest.json +2 -2
  5. package/dist/.next/.next/cache/.rscinfo +1 -1
  6. package/dist/.next/.next/cache/.tsbuildinfo +1 -1
  7. package/dist/.next/.next/cache/webpack/client-production/0.pack +0 -0
  8. package/dist/.next/.next/cache/webpack/client-production/1.pack +0 -0
  9. package/dist/.next/.next/cache/webpack/client-production/2.pack +0 -0
  10. package/dist/.next/.next/cache/webpack/client-production/3.pack +0 -0
  11. package/dist/.next/.next/cache/webpack/client-production/index.pack +0 -0
  12. package/dist/.next/.next/cache/webpack/client-production/index.pack.old +0 -0
  13. package/dist/.next/.next/cache/webpack/edge-server-production/index.pack +0 -0
  14. package/dist/.next/.next/cache/webpack/server-production/0.pack +0 -0
  15. package/dist/.next/.next/cache/webpack/server-production/1.pack +0 -0
  16. package/dist/.next/.next/cache/webpack/server-production/2.pack +0 -0
  17. package/dist/.next/.next/cache/webpack/server-production/index.pack +0 -0
  18. package/dist/.next/.next/cache/webpack/server-production/index.pack.old +0 -0
  19. package/dist/.next/.next/next-minimal-server.js.nft.json +1 -1
  20. package/dist/.next/.next/next-server.js.nft.json +1 -1
  21. package/dist/.next/.next/prerender-manifest.json +1 -1
  22. package/dist/.next/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  23. package/dist/.next/.next/server/app/_not-found.html +1 -1
  24. package/dist/.next/.next/server/app/_not-found.rsc +2 -2
  25. package/dist/.next/.next/server/app/api/cloudflare/route.js +1 -1
  26. package/dist/.next/.next/server/app/api/cloudflare/route.js.nft.json +1 -1
  27. package/dist/.next/.next/server/app/api/cloudflare/route_client-reference-manifest.js +1 -1
  28. package/dist/.next/.next/server/app/api/databases/route.js +1 -1
  29. package/dist/.next/.next/server/app/api/databases/route.js.nft.json +1 -1
  30. package/dist/.next/.next/server/app/api/databases/route_client-reference-manifest.js +1 -1
  31. package/dist/.next/.next/server/app/api/migrations/sync/route.js +3 -3
  32. package/dist/.next/.next/server/app/api/migrations/sync/route.js.nft.json +1 -1
  33. package/dist/.next/.next/server/app/api/migrations/sync/route_client-reference-manifest.js +1 -1
  34. package/dist/.next/.next/server/app/api/migrations/sync-files/route.js +1 -1
  35. package/dist/.next/.next/server/app/api/migrations/sync-files/route.js.nft.json +1 -1
  36. package/dist/.next/.next/server/app/api/migrations/sync-files/route_client-reference-manifest.js +1 -1
  37. package/dist/.next/.next/server/app/api/pull-remote/confirm/route.js +1 -1
  38. package/dist/.next/.next/server/app/api/pull-remote/confirm/route.js.nft.json +1 -1
  39. package/dist/.next/.next/server/app/api/pull-remote/confirm/route_client-reference-manifest.js +1 -1
  40. package/dist/.next/.next/server/app/api/pull-remote/preview/route.js +1 -1
  41. package/dist/.next/.next/server/app/api/pull-remote/preview/route.js.nft.json +1 -1
  42. package/dist/.next/.next/server/app/api/pull-remote/preview/route_client-reference-manifest.js +1 -1
  43. package/dist/.next/.next/server/app/api/push-remote/confirm/route.js +2 -2
  44. package/dist/.next/.next/server/app/api/push-remote/confirm/route.js.nft.json +1 -1
  45. package/dist/.next/.next/server/app/api/push-remote/confirm/route_client-reference-manifest.js +1 -1
  46. package/dist/.next/.next/server/app/api/push-remote/preview/route.js +2 -2
  47. package/dist/.next/.next/server/app/api/push-remote/preview/route.js.nft.json +1 -1
  48. package/dist/.next/.next/server/app/api/push-remote/preview/route_client-reference-manifest.js +1 -1
  49. package/dist/.next/.next/server/app/api/query/route.js +2 -2
  50. package/dist/.next/.next/server/app/api/query/route.js.nft.json +1 -1
  51. package/dist/.next/.next/server/app/api/query/route_client-reference-manifest.js +1 -1
  52. package/dist/.next/.next/server/app/api/tables/[name]/route.js +4 -4
  53. package/dist/.next/.next/server/app/api/tables/[name]/route.js.nft.json +1 -1
  54. package/dist/.next/.next/server/app/api/tables/[name]/route_client-reference-manifest.js +1 -1
  55. package/dist/.next/.next/server/app/api/tables/route.js +2 -2
  56. package/dist/.next/.next/server/app/api/tables/route.js.nft.json +1 -1
  57. package/dist/.next/.next/server/app/api/tables/route_client-reference-manifest.js +1 -1
  58. package/dist/.next/.next/server/app/index.html +3 -3
  59. package/dist/.next/.next/server/app/index.rsc +3 -3
  60. package/dist/.next/.next/server/app/page.js +8 -8
  61. package/dist/.next/.next/server/app/page_client-reference-manifest.js +1 -1
  62. package/dist/.next/.next/server/app-paths-manifest.json +3 -3
  63. package/dist/.next/.next/server/chunks/{801.js → 603.js} +1 -1
  64. package/dist/.next/.next/server/chunks/686.js +23 -0
  65. package/dist/.next/.next/server/pages/404.html +1 -1
  66. package/dist/.next/.next/server/pages/500.html +1 -1
  67. package/dist/.next/.next/server/server-reference-manifest.json +1 -1
  68. package/dist/.next/.next/server/webpack-runtime.js +1 -1
  69. package/dist/.next/.next/static/chunks/app/page-79049bfa6cc07e11.js +1 -0
  70. package/dist/.next/.next/static/css/cf41da7a0d47f779.css +3 -0
  71. package/dist/.next/.next/trace +3 -3
  72. package/dist/.next/BUILD_ID +1 -1
  73. package/dist/.next/app-build-manifest.json +18 -18
  74. package/dist/.next/app-path-routes-manifest.json +1 -1
  75. package/dist/.next/build-manifest.json +2 -2
  76. package/dist/.next/cache/.rscinfo +1 -1
  77. package/dist/.next/cache/.tsbuildinfo +1 -1
  78. package/dist/.next/cache/webpack/client-production/0.pack +0 -0
  79. package/dist/.next/cache/webpack/client-production/index.pack +0 -0
  80. package/dist/.next/cache/webpack/edge-server-production/index.pack +0 -0
  81. package/dist/.next/cache/webpack/server-production/0.pack +0 -0
  82. package/dist/.next/cache/webpack/server-production/index.pack +0 -0
  83. package/dist/.next/next-minimal-server.js.nft.json +1 -1
  84. package/dist/.next/next-server.js.nft.json +1 -1
  85. package/dist/.next/prerender-manifest.json +1 -1
  86. package/dist/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  87. package/dist/.next/server/app/_not-found.html +1 -1
  88. package/dist/.next/server/app/_not-found.rsc +2 -2
  89. package/dist/.next/server/app/api/cloudflare/route.js +1 -1
  90. package/dist/.next/server/app/api/cloudflare/route.js.nft.json +1 -1
  91. package/dist/.next/server/app/api/cloudflare/route_client-reference-manifest.js +1 -1
  92. package/dist/.next/server/app/api/databases/route.js +1 -1
  93. package/dist/.next/server/app/api/databases/route.js.nft.json +1 -1
  94. package/dist/.next/server/app/api/databases/route_client-reference-manifest.js +1 -1
  95. package/dist/.next/server/app/api/migrations/sync/route.js +3 -3
  96. package/dist/.next/server/app/api/migrations/sync/route.js.nft.json +1 -1
  97. package/dist/.next/server/app/api/migrations/sync/route_client-reference-manifest.js +1 -1
  98. package/dist/.next/server/app/api/migrations/sync-files/route.js +1 -1
  99. package/dist/.next/server/app/api/migrations/sync-files/route.js.nft.json +1 -1
  100. package/dist/.next/server/app/api/migrations/sync-files/route_client-reference-manifest.js +1 -1
  101. package/dist/.next/server/app/api/pull-remote/confirm/route.js +1 -1
  102. package/dist/.next/server/app/api/pull-remote/confirm/route.js.nft.json +1 -1
  103. package/dist/.next/server/app/api/pull-remote/confirm/route_client-reference-manifest.js +1 -1
  104. package/dist/.next/server/app/api/pull-remote/preview/route.js +1 -1
  105. package/dist/.next/server/app/api/pull-remote/preview/route.js.nft.json +1 -1
  106. package/dist/.next/server/app/api/pull-remote/preview/route_client-reference-manifest.js +1 -1
  107. package/dist/.next/server/app/api/push-remote/confirm/route.js +2 -2
  108. package/dist/.next/server/app/api/push-remote/confirm/route.js.nft.json +1 -1
  109. package/dist/.next/server/app/api/push-remote/confirm/route_client-reference-manifest.js +1 -1
  110. package/dist/.next/server/app/api/push-remote/preview/route.js +2 -2
  111. package/dist/.next/server/app/api/push-remote/preview/route.js.nft.json +1 -1
  112. package/dist/.next/server/app/api/push-remote/preview/route_client-reference-manifest.js +1 -1
  113. package/dist/.next/server/app/api/query/route.js +2 -2
  114. package/dist/.next/server/app/api/query/route.js.nft.json +1 -1
  115. package/dist/.next/server/app/api/query/route_client-reference-manifest.js +1 -1
  116. package/dist/.next/server/app/api/tables/[name]/route.js +4 -4
  117. package/dist/.next/server/app/api/tables/[name]/route.js.nft.json +1 -1
  118. package/dist/.next/server/app/api/tables/[name]/route_client-reference-manifest.js +1 -1
  119. package/dist/.next/server/app/api/tables/route.js +2 -2
  120. package/dist/.next/server/app/api/tables/route.js.nft.json +1 -1
  121. package/dist/.next/server/app/api/tables/route_client-reference-manifest.js +1 -1
  122. package/dist/.next/server/app/index.html +3 -3
  123. package/dist/.next/server/app/index.rsc +3 -3
  124. package/dist/.next/server/app/page.js +8 -8
  125. package/dist/.next/server/app/page_client-reference-manifest.js +1 -1
  126. package/dist/.next/server/app-paths-manifest.json +7 -7
  127. package/dist/.next/server/chunks/{801.js → 603.js} +11 -11
  128. package/dist/.next/server/chunks/686.js +23 -0
  129. package/dist/.next/server/pages/404.html +1 -1
  130. package/dist/.next/server/pages/500.html +1 -1
  131. package/dist/.next/server/server-reference-manifest.json +1 -1
  132. package/dist/.next/server/webpack-runtime.js +1 -1
  133. package/dist/.next/static/chunks/app/page-79049bfa6cc07e11.js +1 -0
  134. package/dist/.next/static/css/cf41da7a0d47f779.css +3 -0
  135. package/dist/.next/trace +14 -13
  136. package/dist/app/api/databases/route.js +1 -1
  137. package/dist/app/api/pull-remote/confirm/route.js +20 -20
  138. package/dist/app/api/push-remote/confirm/route.js +1 -1
  139. package/dist/app/api/push-remote/preview/route.js +1 -1
  140. package/dist/app/api/query/route.js +7 -7
  141. package/dist/app/app/page.jsx +3 -6
  142. package/dist/app/page.jsx +3 -6
  143. package/dist/d1-studio.js +42 -87
  144. package/dist/lib/find-wrangler-config.js +10 -9
  145. package/dist/lib/logger.js +19 -0
  146. package/package.json +3 -2
  147. package/scripts/studio.js +42 -87
  148. package/src/app/page.jsx +3 -6
  149. package/src/components/sidebar.jsx +108 -92
  150. package/src/lib/find-wrangler-config.js +10 -9
  151. package/src/lib/logger.js +19 -0
  152. package/dist/.next/.next/cache/webpack/client-production/4.pack +0 -0
  153. package/dist/.next/.next/cache/webpack/client-production/5.pack +0 -0
  154. package/dist/.next/.next/cache/webpack/client-production/6.pack +0 -0
  155. package/dist/.next/.next/cache/webpack/server-production/3.pack +0 -0
  156. package/dist/.next/.next/cache/webpack/server-production/4.pack +0 -0
  157. package/dist/.next/.next/cache/webpack/server-production/5.pack +0 -0
  158. package/dist/.next/.next/cache/webpack/server-production/6.pack +0 -0
  159. package/dist/.next/.next/server/chunks/973.js +0 -2
  160. package/dist/.next/.next/static/chunks/app/page-75081ac7a88cb706.js +0 -1
  161. package/dist/.next/.next/static/css/c51a7ef325e30c16.css +0 -3
  162. package/dist/.next/.next/static/fSVNB2iNhKcZdXXgESWZk/_buildManifest.js +0 -1
  163. package/dist/.next/.next/static/fSVNB2iNhKcZdXXgESWZk/_ssgManifest.js +0 -1
  164. package/dist/.next/.next/static/xzPddcyKcodbwNX_sKljr/_buildManifest.js +0 -1
  165. package/dist/.next/.next/static/xzPddcyKcodbwNX_sKljr/_ssgManifest.js +0 -1
  166. package/dist/.next/server/chunks/973.js +0 -2
  167. package/dist/.next/static/OmPVuV0d1lrcjSBQzxkdH/_buildManifest.js +0 -1
  168. package/dist/.next/static/OmPVuV0d1lrcjSBQzxkdH/_ssgManifest.js +0 -1
  169. package/dist/.next/static/chunks/app/page-75081ac7a88cb706.js +0 -1
  170. package/dist/.next/static/css/c51a7ef325e30c16.css +0 -3
  171. /package/dist/.next/.next/static/{ODMSSwVqLoDcBgbFHUjr8 → HsZ8OanS5v86DqC9rErO-}/_buildManifest.js +0 -0
  172. /package/dist/.next/.next/static/{ODMSSwVqLoDcBgbFHUjr8 → HsZ8OanS5v86DqC9rErO-}/_ssgManifest.js +0 -0
  173. /package/dist/.next/.next/static/{YIuXI2CxMwg2fuuUEBsXL → q6WmQmyONe88bMN0_jrC2}/_buildManifest.js +0 -0
  174. /package/dist/.next/.next/static/{YIuXI2CxMwg2fuuUEBsXL → q6WmQmyONe88bMN0_jrC2}/_ssgManifest.js +0 -0
  175. /package/dist/.next/{.next/static/_t0S4u4KzUwKctaxLKvx4 → static/Tk1fnz_CXLavm23ZEeChG}/_buildManifest.js +0 -0
  176. /package/dist/.next/{.next/static/_t0S4u4KzUwKctaxLKvx4 → static/Tk1fnz_CXLavm23ZEeChG}/_ssgManifest.js +0 -0
@@ -15,7 +15,7 @@ export async function GET() {
15
15
  );
16
16
  }
17
17
 
18
- console.log('Looking for Wrangler configuration in:', projectDir);
18
+ // console.log('Looking for Wrangler configuration in:', projectDir);
19
19
 
20
20
  // Use findWranglerConfig helper
21
21
  const wranglerResult = await findWranglerConfig(projectDir);
@@ -52,19 +52,19 @@ async function applyPullMigrations(projectDir, accountId, apiToken, databaseName
52
52
  await Promise.all(stagedFilesList.map(file => unlink(path.join(stagingDir, file))));
53
53
 
54
54
  // --- STEP 1: Fetch remote migration metadata ---
55
- console.log('Fetching remote migration metadata...');
55
+ // console.log('Fetching remote migration metadata...');
56
56
  const remoteMigrations = await getRemoteMigrations(projectDir, databaseName, env);
57
- console.log('Remote migration metadata:', remoteMigrations);
57
+ // console.log('Remote migration metadata:', remoteMigrations);
58
58
 
59
59
  // --- STEP 2: For each remote migration, fetch its file content ---
60
- console.log('Fetching migration file content from remote...');
60
+ // console.log('Fetching migration file content from remote...');
61
61
  const stagedFiles = new Map();
62
62
  for (const migration of remoteMigrations) {
63
63
  try {
64
64
  const migrationFileName = migration.name; // Use the remote migration's name.
65
65
  const content = await getMigrationFileContent(projectDir, databaseName, migrationFileName, env);
66
66
  stagedFiles.set(migrationFileName, content);
67
- console.log(`Staged migration file: ${migrationFileName}`);
67
+ // console.log(`Staged migration file: ${migrationFileName}`);
68
68
  await writeFile(path.join(stagingDir, migrationFileName), content, 'utf8');
69
69
  } catch (fileError) {
70
70
  console.error(`Error fetching content for migration ${migration.name}:`, fileError);
@@ -73,12 +73,12 @@ async function applyPullMigrations(projectDir, accountId, apiToken, databaseName
73
73
  }
74
74
 
75
75
  // --- STEP 3: Fetch local schema for destructive update ---
76
- console.log('Fetching local schema for destructive update...');
76
+ // console.log('Fetching local schema for destructive update...');
77
77
  const currentSchema = await getCurrentSchema(projectDir, databaseName, env, false);
78
78
  const tableSchema = currentSchema.filter(obj =>
79
79
  obj.type === 'table' && obj.name && obj.name.toLowerCase() !== 'if'
80
80
  );
81
- console.log('Local table schema:', tableSchema);
81
+ // console.log('Local table schema:', tableSchema);
82
82
  const dropOrder = tableSchema.length > 0
83
83
  ? analyzeDependencies(
84
84
  tableSchema.map(obj => ({
@@ -88,18 +88,18 @@ async function applyPullMigrations(projectDir, accountId, apiToken, databaseName
88
88
  }))
89
89
  )
90
90
  : [];
91
- console.log('Computed drop order:', dropOrder);
91
+ // console.log('Computed drop order:', dropOrder);
92
92
 
93
93
  // --- STEP 4: Destructive update (all-or-nothing) ---
94
- console.log('Beginning destructive update...');
94
+ // console.log('Beginning destructive update...');
95
95
  try {
96
- console.log('Disabling foreign keys...');
96
+ // console.log('Disabling foreign keys...');
97
97
  await executeSQL(projectDir, databaseName, 'PRAGMA foreign_keys=OFF;', env, false);
98
98
 
99
99
  // Drop triggers.
100
100
  const triggers = currentSchema.filter(obj => obj.type === 'trigger');
101
101
  for (const trigger of triggers) {
102
- console.log(`Dropping trigger: ${trigger.name}`);
102
+ // console.log(`Dropping trigger: ${trigger.name}`);
103
103
  await executeSQL(
104
104
  projectDir,
105
105
  databaseName,
@@ -111,7 +111,7 @@ async function applyPullMigrations(projectDir, accountId, apiToken, databaseName
111
111
  // Drop indexes.
112
112
  const indexes = currentSchema.filter(obj => obj.type === 'index');
113
113
  for (const index of indexes) {
114
- console.log(`Dropping index: ${index.name}`);
114
+ // console.log(`Dropping index: ${index.name}`);
115
115
  await executeSQL(
116
116
  projectDir,
117
117
  databaseName,
@@ -122,7 +122,7 @@ async function applyPullMigrations(projectDir, accountId, apiToken, databaseName
122
122
  }
123
123
  // Drop tables in reverse dependency order.
124
124
  for (const tableName of dropOrder.reverse()) {
125
- console.log(`Dropping table: ${tableName}`);
125
+ // console.log(`Dropping table: ${tableName}`);
126
126
  await executeSQL(
127
127
  projectDir,
128
128
  databaseName,
@@ -131,7 +131,7 @@ async function applyPullMigrations(projectDir, accountId, apiToken, databaseName
131
131
  false
132
132
  );
133
133
  }
134
- console.log('Re-enabling foreign keys...');
134
+ // console.log('Re-enabling foreign keys...');
135
135
  await executeSQL(projectDir, databaseName, 'PRAGMA foreign_keys=ON;', env, false);
136
136
  } catch (dropError) {
137
137
  throw new Error(`Error dropping existing objects: ${dropError.message}`);
@@ -139,7 +139,7 @@ async function applyPullMigrations(projectDir, accountId, apiToken, databaseName
139
139
 
140
140
  // --- STEP 5: Reset the local migrations table ---
141
141
  try {
142
- console.log('Resetting local migrations table...');
142
+ // console.log('Resetting local migrations table...');
143
143
  await initMigrationsTable(projectDir, databaseName, 'local', true);
144
144
  } catch (initError) {
145
145
  throw new Error(`Error resetting migrations table: ${initError.message}`);
@@ -152,7 +152,7 @@ async function applyPullMigrations(projectDir, accountId, apiToken, databaseName
152
152
  try {
153
153
  for (const [filename, content] of stagedFiles.entries()) {
154
154
  currentFilename = filename;
155
- console.log(`Applying migration: ${filename}`);
155
+ // console.log(`Applying migration: ${filename}`);
156
156
  // Write the migration file to the main migrations folder.
157
157
  await writeFile(path.join(migrationsDir, filename), content, 'utf8');
158
158
 
@@ -162,7 +162,7 @@ async function applyPullMigrations(projectDir, accountId, apiToken, databaseName
162
162
  .update(content)
163
163
  .digest('hex');
164
164
 
165
- console.log(`Recording migration: ${filename} with checksum ${checksum}`);
165
+ // console.log(`Recording migration: ${filename} with checksum ${checksum}`);
166
166
  await recordMigration(
167
167
  projectDir,
168
168
  databaseName,
@@ -181,20 +181,20 @@ async function applyPullMigrations(projectDir, accountId, apiToken, databaseName
181
181
  }
182
182
 
183
183
  // --- STEP 7: Replace main migrations folder with staged files ---
184
- console.log('Replacing main migrations folder with staged files...');
184
+ // console.log('Replacing main migrations folder with staged files...');
185
185
  const mainFiles = await readdir(migrationsDir).catch(() => []);
186
186
  if (mainFiles.length) {
187
187
  for (const file of mainFiles) {
188
- console.log(`Deleting local migration file: ${file}`);
188
+ // console.log(`Deleting local migration file: ${file}`);
189
189
  await unlink(path.join(migrationsDir, file));
190
190
  }
191
191
  }
192
192
  for (const [filename, content] of stagedFiles.entries()) {
193
- console.log(`Copying staged file ${filename} to main migrations folder`);
193
+ // console.log(`Copying staged file ${filename} to main migrations folder`);
194
194
  await writeFile(path.join(migrationsDir, filename), content, 'utf8');
195
195
  }
196
196
 
197
- console.log('Pull migration applied successfully.');
197
+ // console.log('Pull migration applied successfully.');
198
198
  return {
199
199
  appliedMigrations: Array.from(stagedFiles.keys()),
200
200
  details: appliedPreview
@@ -133,7 +133,7 @@ for (const migrationFile of migrationFiles) {
133
133
  results.preview.push(previewRecord);
134
134
  }
135
135
  }
136
- console.log("Push Confirm Result (server):", results);
136
+ // console.log("Push Confirm Result (server):", results);
137
137
  return { success: true, preview: false, applied: results.applied.length, skipped: results.skipped.length, details: results };
138
138
  } catch (error) {
139
139
  throw {
@@ -100,7 +100,7 @@ async function pushToRemote(projectDir, accountId, apiToken, databaseName, previ
100
100
  }
101
101
  }
102
102
 
103
- console.log("Push Preview Result (server):", results);
103
+ // console.log("Push Preview Result (server):", results);
104
104
  return { success: true, preview: true, applied: results.applied.length, skipped: results.skipped.length, details: results };
105
105
  } catch (error) {
106
106
  throw {
@@ -28,7 +28,7 @@ export async function POST(req) {
28
28
 
29
29
  // Extract the SQL query from the request body.
30
30
  const { query } = await req.json();
31
- console.log('Received query:', query);
31
+ // console.log('Received query:', query);
32
32
 
33
33
  if (!query?.trim()) {
34
34
  return NextResponse.json(
@@ -57,11 +57,11 @@ export async function POST(req) {
57
57
 
58
58
  // Use the first configured database.
59
59
  const databaseName = config.d1_databases[0].database_name;
60
- console.log('Using database:', databaseName);
60
+ // console.log('Using database:', databaseName);
61
61
 
62
62
  // Parse the query into individual SQL statements.
63
63
  let statements = parseQuery(query);
64
- console.log('Parsed statements:', statements);
64
+ // console.log('Parsed statements:', statements);
65
65
 
66
66
  if (!statements.length) {
67
67
  return NextResponse.json(
@@ -72,7 +72,7 @@ export async function POST(req) {
72
72
 
73
73
  // Validate each parsed statement.
74
74
  statements = statements.map(validateStatement);
75
- console.log('Validated statements:', statements);
75
+ // console.log('Validated statements:', statements);
76
76
 
77
77
  // Initialize the migrations table (if it doesn't already exist).
78
78
  const createMigrationsTable = `
@@ -87,7 +87,7 @@ export async function POST(req) {
87
87
 
88
88
  // Determine whether the query involves any schema changes.
89
89
  const hasSchemaChanges = statements.some(isSchemaChange);
90
- console.log('Has schema changes:', hasSchemaChanges);
90
+ // console.log('Has schema changes:', hasSchemaChanges);
91
91
 
92
92
  let result;
93
93
  if (hasSchemaChanges) {
@@ -105,7 +105,7 @@ export async function POST(req) {
105
105
  // For data modification queries, execute the statements.
106
106
  const results = [];
107
107
  for (const stmt of statements) {
108
- console.log('Executing data modification:', stmt.sql);
108
+ // console.log('Executing data modification:', stmt.sql);
109
109
  const output = await executeSQL(projectDir, databaseName, stmt.sql);
110
110
 
111
111
  try {
@@ -113,7 +113,7 @@ export async function POST(req) {
113
113
  const queryResults = parsed[0]?.results || [];
114
114
  results.push(...queryResults);
115
115
  } catch (parseError) {
116
- console.log('Non-JSON output:', output);
116
+ // console.log('Non-JSON output:', output);
117
117
  continue;
118
118
  }
119
119
  }
@@ -10,23 +10,20 @@ export default function StudioPage() {
10
10
  const [currentView, setCurrentView] = useState('sql-editor');
11
11
  const [selectedTable, setSelectedTable] = useState(null);
12
12
 
13
- // We don't need to handle push errors here anymore since we're using toasts
14
- // The error handling is now managed by the useEnvironmentController hook
15
-
16
13
  const handleTableSelect = (tableName) => {
17
14
  setSelectedTable(tableName);
18
15
  setCurrentView('table-view');
19
16
  };
20
17
 
21
18
  return (
22
- <div className="flex h-screen bg-background">
19
+ <div className="min-h-screen bg-background">
23
20
  <AppSidebar
24
- className="w-64 border-r flex-shrink-0"
21
+ className="w-64 border-r"
25
22
  currentView={currentView}
26
23
  onNavigate={setCurrentView}
27
24
  onTableSelect={handleTableSelect}
28
25
  />
29
- <main className="flex-1 overflow-hidden">
26
+ <main className="ml-64 h-screen">
30
27
  {currentView === 'sql-editor' && <SQLEditor />}
31
28
  {currentView === 'table-view' && selectedTable && (
32
29
  <TableView tableName={selectedTable} />
package/dist/app/page.jsx CHANGED
@@ -10,23 +10,20 @@ export default function StudioPage() {
10
10
  const [currentView, setCurrentView] = useState('sql-editor');
11
11
  const [selectedTable, setSelectedTable] = useState(null);
12
12
 
13
- // We don't need to handle push errors here anymore since we're using toasts
14
- // The error handling is now managed by the useEnvironmentController hook
15
-
16
13
  const handleTableSelect = (tableName) => {
17
14
  setSelectedTable(tableName);
18
15
  setCurrentView('table-view');
19
16
  };
20
17
 
21
18
  return (
22
- <div className="flex h-screen bg-background">
19
+ <div className="min-h-screen bg-background">
23
20
  <AppSidebar
24
- className="w-64 border-r flex-shrink-0"
21
+ className="w-64 border-r"
25
22
  currentView={currentView}
26
23
  onNavigate={setCurrentView}
27
24
  onTableSelect={handleTableSelect}
28
25
  />
29
- <main className="flex-1 overflow-hidden">
26
+ <main className="ml-64 h-screen">
30
27
  {currentView === 'sql-editor' && <SQLEditor />}
31
28
  {currentView === 'table-view' && selectedTable && (
32
29
  <TableView tableName={selectedTable} />
package/dist/d1-studio.js CHANGED
@@ -11,6 +11,7 @@ import express from 'express';
11
11
  import { createServer } from 'http';
12
12
  import next from 'next';
13
13
  import { findWranglerConfig } from '../src/lib/find-wrangler-config.js';
14
+ import logger from '../src/lib/logger.js';
14
15
 
15
16
  // Compute the absolute path of this file and its directory.
16
17
  const __filename = fileURLToPath(import.meta.url);
@@ -46,14 +47,8 @@ async function validateLicenseRemote(licenseKey, email, hardwareId) {
46
47
  try {
47
48
  const response = await fetch(`${baseUrl}/api/validate-license`, {
48
49
  method: 'POST',
49
- headers: {
50
- 'Content-Type': 'application/json',
51
- },
52
- body: JSON.stringify({
53
- licenseKey,
54
- email,
55
- hardwareId,
56
- }),
50
+ headers: { 'Content-Type': 'application/json' },
51
+ body: JSON.stringify({ licenseKey, email, hardwareId }),
57
52
  });
58
53
 
59
54
  const result = await response.json();
@@ -65,7 +60,6 @@ async function validateLicenseRemote(licenseKey, email, hardwareId) {
65
60
  );
66
61
  }
67
62
 
68
- // Check for subscription expiration if end_date is provided.
69
63
  if (result.end_date && new Date(result.end_date) < new Date()) {
70
64
  throw new LicenseError(
71
65
  'Your subscription has expired. Please renew your license to continue using D1 Studio.',
@@ -78,7 +72,6 @@ async function validateLicenseRemote(licenseKey, email, hardwareId) {
78
72
  if (error instanceof LicenseError) {
79
73
  throw error;
80
74
  }
81
-
82
75
  if (error.name === 'TypeError' && error.message.includes('fetch')) {
83
76
  throw new LicenseError(
84
77
  process.env.NODE_ENV === 'development'
@@ -87,7 +80,6 @@ async function validateLicenseRemote(licenseKey, email, hardwareId) {
87
80
  'CONNECTION_ERROR'
88
81
  );
89
82
  }
90
-
91
83
  throw new LicenseError(
92
84
  'An unexpected error occurred during license validation',
93
85
  'VALIDATION_ERROR'
@@ -106,7 +98,6 @@ async function checkLicenseFile() {
106
98
  if (licenseData.hardwareId !== hardwareId) {
107
99
  return null;
108
100
  }
109
-
110
101
  return licenseData;
111
102
  } catch (error) {
112
103
  return null;
@@ -127,22 +118,19 @@ async function saveLicenseFile(licenseData) {
127
118
 
128
119
  async function startServer(port, projectDirectory) {
129
120
  return new Promise((resolvePromise, rejectPromise) => {
130
- const dev = process.env.NODE_ENV === 'development';
131
-
132
- // Determine the directory where Next.js build is located:
133
- // In production (published package), __dirname is in the 'dist' folder so we use it directly.
134
- // In development, we assume the structure is different and go one level up.
121
+ // Determine Next.js app directory based on environment:
122
+ // In production (published package) __dirname is used.
123
+ // In development (npm link), assume the build is in the parent folder.
135
124
  const isProduction = process.env.NODE_ENV !== 'development';
136
125
  const nextAppDir = isProduction ? __dirname : join(__dirname, '..');
137
126
 
127
+ const dev = process.env.NODE_ENV === 'development';
138
128
  const app = next({
139
129
  dev,
140
130
  dir: nextAppDir,
141
131
  conf: {
142
132
  distDir: '.next',
143
- experimental: {
144
- appDir: true
145
- }
133
+ experimental: { appDir: true }
146
134
  }
147
135
  });
148
136
  const handle = app.getRequestHandler();
@@ -150,41 +138,29 @@ async function startServer(port, projectDirectory) {
150
138
  app.prepare()
151
139
  .then(() => {
152
140
  const server = express();
153
-
154
- // Set environment variables
155
141
  process.env.PORT = port.toString();
156
142
  process.env.D1_PROJECT_DIR = projectDirectory;
143
+ const httpServer = createServer((req, res) => handle(req, res));
157
144
 
158
- // Create HTTP server
159
- const httpServer = createServer((req, res) => {
160
- handle(req, res);
161
- });
162
-
163
- // Handle all requests through Next.js
164
- server.all('*', (req, res) => {
165
- return handle(req, res);
166
- });
145
+ server.all('*', (req, res) => handle(req, res));
167
146
 
168
- // Start listening
169
147
  httpServer.listen(port, (err) => {
170
148
  if (err) {
171
- console.error(chalk.red('Failed to start server:'), err);
149
+ logger.error(chalk.red(`Failed to start server: ${err}`));
172
150
  rejectPromise(err);
173
151
  return;
174
152
  }
175
-
176
- console.log(chalk.green(`Server started on port ${port}`));
153
+ logger.info(chalk.green(`Server started on port ${port}`));
177
154
  resolvePromise(httpServer);
178
155
  });
179
156
 
180
- // Handle server errors
181
157
  httpServer.on('error', (err) => {
182
- console.error(chalk.red('Server error:'), err);
158
+ logger.error(chalk.red(`Server error: ${err}`));
183
159
  rejectPromise(err);
184
160
  });
185
161
  })
186
162
  .catch((err) => {
187
- console.error(chalk.red('Failed to prepare Next.js app:'), err);
163
+ logger.error(chalk.red(`Failed to prepare Next.js app: ${err}`));
188
164
  rejectPromise(err);
189
165
  });
190
166
  });
@@ -192,17 +168,15 @@ async function startServer(port, projectDirectory) {
192
168
 
193
169
  async function startStudio() {
194
170
  try {
195
- console.log(chalk.green('Initializing D1 Studio...'));
171
+ logger.info(chalk.green('Initializing D1 Studio...'));
196
172
 
197
173
  // Validate license
198
174
  let licenseData = await checkLicenseFile();
199
- console.log(chalk.blue('License data found:'), licenseData);
175
+ logger.debug(chalk.blue(`License data found: ${JSON.stringify(licenseData)}`));
200
176
 
201
177
  const TWELVE_HOURS_MS = 43200000; // 12 hours
202
178
  let shouldRevalidate = true;
203
-
204
179
  if (licenseData) {
205
- // Use lastValidatedAt if available; otherwise, fall back to activatedAt.
206
180
  const lastCheck = new Date(licenseData.lastValidatedAt || licenseData.activatedAt);
207
181
  if (Date.now() - lastCheck.getTime() < TWELVE_HOURS_MS) {
208
182
  shouldRevalidate = false;
@@ -211,7 +185,7 @@ async function startStudio() {
211
185
 
212
186
  if (!licenseData || shouldRevalidate) {
213
187
  const { default: inquirer } = await import('inquirer');
214
- console.log(chalk.blue('\nPlease enter your D1 Studio license information:'));
188
+ logger.info(chalk.yellow('\nPlease enter your D1 Studio license information:'));
215
189
 
216
190
  const answers = await inquirer.prompt([
217
191
  {
@@ -231,10 +205,9 @@ async function startStudio() {
231
205
  },
232
206
  ]);
233
207
 
234
- console.log(chalk.blue('Entered license information:'), answers);
208
+ logger.debug(chalk.blue(`Entered license information: ${JSON.stringify(answers)}`));
235
209
 
236
210
  const hardwareId = await generateHardwareId();
237
-
238
211
  try {
239
212
  const validation = await validateLicenseRemote(
240
213
  answers.licenseKey,
@@ -242,51 +215,42 @@ async function startStudio() {
242
215
  hardwareId
243
216
  );
244
217
 
245
- // Optionally, you can store the returned end_date for future checks.
246
218
  licenseData = {
247
219
  licenseKey: answers.licenseKey,
248
220
  email: answers.email,
249
- hardwareId,
250
- licenseType: validation.licenseType,
251
221
  activatedAt: new Date().toISOString(),
252
- lastValidatedAt: new Date().toISOString(),
253
222
  endDate: validation.end_date || null
254
223
  };
255
224
 
256
225
  await saveLicenseFile(licenseData);
257
- console.log(chalk.green('\nLicense activated successfully!'));
226
+ logger.info(chalk.green('\nLicense activated successfully!'));
258
227
  } catch (error) {
259
- console.error(chalk.red('\nLicense validation failed:'), error.message);
228
+ logger.error(chalk.red(`\nLicense validation failed: ${error.message}`));
260
229
  process.exit(1);
261
230
  }
262
- } else {
263
- // console.log(chalk.blue('Using cached license data.'));
264
231
  }
265
232
 
266
233
  // Get wrangler configuration
267
234
  try {
268
235
  const userProjectPath = process.cwd();
269
-
270
236
  if (!userProjectPath) {
271
- console.error(chalk.red('Error: Could not determine project directory'));
237
+ logger.error(chalk.red('Error: Could not determine project directory'));
272
238
  process.exit(1);
273
239
  }
274
-
240
+
275
241
  const wranglerResult = await findWranglerConfig(userProjectPath);
276
-
277
242
  if (!wranglerResult || !wranglerResult.config) {
278
- console.error(chalk.red('\nError: No wrangler.toml found in current directory'));
279
- console.log(chalk.yellow('Make sure you are in a Cloudflare Workers project directory'));
280
- console.log(chalk.yellow('with a valid wrangler.toml file.'));
243
+ logger.error(chalk.red('\nError: No wrangler.toml found in current directory'));
244
+ logger.info(chalk.yellow('Make sure you are in a Cloudflare Workers project directory'));
245
+ logger.info(chalk.yellow('with a valid wrangler.toml file.'));
281
246
  process.exit(1);
282
247
  }
283
-
248
+
284
249
  const { config, projectPath } = wranglerResult;
285
-
286
250
  if (!config.d1_databases?.length) {
287
- console.error(chalk.red('\nError: No D1 databases configured in wrangler.toml'));
288
- console.log(chalk.yellow('\nAdd D1 configuration to your wrangler.toml:'));
289
- console.log(chalk.gray(`
251
+ logger.error(chalk.red('\nError: No D1 databases configured in wrangler.toml'));
252
+ logger.info(chalk.yellow('\nAdd D1 configuration to your wrangler.toml:'));
253
+ logger.info(chalk.gray(`
290
254
  [[d1_databases]]
291
255
  binding = "DB"
292
256
  database_name = "my-database"
@@ -294,11 +258,10 @@ async function startStudio() {
294
258
  `));
295
259
  process.exit(1);
296
260
  }
297
-
298
- // Display found databases
299
- console.log(chalk.green('\nFound D1 databases:'));
261
+
262
+ logger.info(chalk.green('\nFound D1 databases:'));
300
263
  config.d1_databases.forEach((db) => {
301
- console.log(chalk.blue(` - ${db.database_name} (${db.binding})`));
264
+ logger.info(chalk.blue(` - ${db.database_name} (${db.binding})`));
302
265
  });
303
266
 
304
267
  const port = 4000;
@@ -306,7 +269,7 @@ async function startStudio() {
306
269
 
307
270
  await startServer(port, projectPath);
308
271
 
309
- console.log(chalk.green(`
272
+ logger.info(chalk.green(`
310
273
  ┌─────────────────────────────────────────┐
311
274
  │ │
312
275
  │ D1 Studio is running on port ${port} │
@@ -316,50 +279,42 @@ async function startStudio() {
316
279
  └─────────────────────────────────────────┘
317
280
  `));
318
281
 
319
- // Add delay before opening browser
320
282
  await new Promise(resolve => setTimeout(resolve, 2000));
321
283
 
322
284
  try {
323
285
  await open(url, {
324
286
  wait: false,
325
287
  url: true,
326
- app: {
327
- name: open.apps.chrome
328
- }
288
+ app: { name: open.apps.chrome }
329
289
  }).catch(() => {
330
- return open(url, {
331
- wait: false,
332
- url: true
333
- });
290
+ return open(url, { wait: false, url: true });
334
291
  });
335
292
  } catch (browserError) {
336
- console.log(chalk.yellow('\nCould not automatically open browser.'));
337
- console.log(chalk.blue('Please open your browser and navigate to:'), url);
293
+ logger.info(chalk.yellow('\nCould not automatically open browser.'));
294
+ logger.info(chalk.blue(`Please open your browser and navigate to: ${url}`));
338
295
  }
339
-
340
296
  } catch (configError) {
341
- console.error(chalk.red('\nConfiguration error:'), configError.message);
297
+ logger.error(chalk.red(`\nConfiguration error: ${configError.message}`));
342
298
  process.exit(1);
343
299
  }
344
-
345
300
  } catch (error) {
346
- console.error(chalk.red('\nFailed to start D1 Studio:'), error);
301
+ logger.error(chalk.red(`\nFailed to start D1 Studio: ${error}`));
347
302
  process.exit(1);
348
303
  }
349
304
  }
350
305
 
351
306
  // Handle termination
352
307
  process.on('SIGINT', () => {
353
- console.log(chalk.yellow('\nShutting down D1 Studio...'));
308
+ logger.info(chalk.yellow('\nShutting down D1 Studio...'));
354
309
  process.exit(0);
355
310
  });
356
311
 
357
312
  process.on('SIGTERM', () => {
358
- console.log(chalk.yellow('\nShutting down D1 Studio...'));
313
+ logger.info(chalk.yellow('\nShutting down D1 Studio...'));
359
314
  process.exit(0);
360
315
  });
361
316
 
362
317
  startStudio().catch((error) => {
363
- console.error(chalk.red('\nFailed to start D1 Studio:'), error);
318
+ logger.error(chalk.red(`\nFailed to start D1 Studio: ${error}`));
364
319
  process.exit(1);
365
320
  });
@@ -3,7 +3,7 @@ import { readFile } from 'fs/promises';
3
3
  import { findUp } from 'find-up';
4
4
  import { parse as parseToml } from '@iarna/toml';
5
5
  import stripJsonComments from 'strip-json-comments';
6
- import chalk from 'chalk';
6
+ import logger from './logger.js';
7
7
 
8
8
  /**
9
9
  * Finds and parses the Wrangler configuration file.
@@ -17,14 +17,15 @@ export async function findWranglerConfig(userProjectPath) {
17
17
  throw new Error('Project path is required and must be a string');
18
18
  }
19
19
 
20
- // console.log(chalk.blue('Looking for wrangler configuration in:'), userProjectPath);
20
+ // Uncomment the following line to log the search path if needed:
21
+ // logger.debug(`Looking for wrangler configuration in: ${userProjectPath}`);
21
22
 
22
23
  // Define the possible configuration file names in priority order.
23
24
  const possibleFiles = ['wrangler.toml', 'wrangler.json', 'wrangler.jsonc'];
24
25
  let configPath = null;
25
26
  let configFileUsed = null;
26
27
 
27
- // Search for any of the possible config files
28
+ // Search for any of the possible config files.
28
29
  for (const file of possibleFiles) {
29
30
  configPath = await findUp(file, { cwd: userProjectPath });
30
31
  if (configPath) {
@@ -34,21 +35,21 @@ export async function findWranglerConfig(userProjectPath) {
34
35
  }
35
36
 
36
37
  if (!configPath) {
37
- console.log(chalk.yellow('No Wrangler configuration file found in:'), userProjectPath);
38
+ logger.warn(`No Wrangler configuration file found in: ${userProjectPath}`);
38
39
  return null;
39
40
  }
40
41
 
41
- console.log(chalk.green(`Found ${configFileUsed} at:`), configPath);
42
+ logger.info(`Found ${configFileUsed} at: ${configPath}`);
42
43
 
43
- // Read the configuration file
44
+ // Read the configuration file.
44
45
  let configContent = await readFile(configPath, 'utf-8');
45
46
  let config;
46
47
 
47
- // Parse based on file type
48
+ // Parse based on file type.
48
49
  if (configFileUsed.endsWith('.toml')) {
49
50
  config = parseToml(configContent);
50
51
  } else {
51
- // If it's JSONC, strip comments before parsing
52
+ // If it's JSONC, strip comments before parsing.
52
53
  if (configFileUsed.endsWith('.jsonc')) {
53
54
  configContent = stripJsonComments(configContent);
54
55
  }
@@ -61,7 +62,7 @@ export async function findWranglerConfig(userProjectPath) {
61
62
  };
62
63
 
63
64
  } catch (error) {
64
- console.error(chalk.red('Error reading Wrangler configuration:'), error.message);
65
+ logger.error(`Error reading Wrangler configuration: ${error.message}`);
65
66
  throw error;
66
67
  }
67
68
  }