d1s 0.2.3 → 0.2.5
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/.next/.next/BUILD_ID +1 -1
- package/dist/.next/.next/app-build-manifest.json +17 -17
- package/dist/.next/.next/app-path-routes-manifest.json +1 -1
- package/dist/.next/.next/build-manifest.json +2 -2
- package/dist/.next/.next/cache/.rscinfo +1 -1
- package/dist/.next/.next/cache/.tsbuildinfo +1 -1
- package/dist/.next/.next/cache/webpack/client-production/0.pack +0 -0
- package/dist/.next/.next/cache/webpack/client-production/1.pack +0 -0
- package/dist/.next/.next/cache/webpack/client-production/2.pack +0 -0
- package/dist/.next/.next/cache/webpack/client-production/index.pack +0 -0
- package/dist/.next/.next/cache/webpack/client-production/index.pack.old +0 -0
- package/dist/.next/.next/cache/webpack/edge-server-production/index.pack +0 -0
- package/dist/.next/.next/cache/webpack/server-production/0.pack +0 -0
- package/dist/.next/.next/cache/webpack/server-production/1.pack +0 -0
- package/dist/.next/.next/cache/webpack/server-production/index.pack +0 -0
- package/dist/.next/.next/cache/webpack/server-production/index.pack.old +0 -0
- package/dist/.next/.next/next-minimal-server.js.nft.json +1 -1
- package/dist/.next/.next/next-server.js.nft.json +1 -1
- package/dist/.next/.next/prerender-manifest.json +1 -1
- package/dist/.next/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
- package/dist/.next/.next/server/app/_not-found.html +1 -1
- package/dist/.next/.next/server/app/_not-found.rsc +2 -2
- package/dist/.next/.next/server/app/api/cloudflare/route.js +1 -1
- package/dist/.next/.next/server/app/api/cloudflare/route.js.nft.json +1 -1
- package/dist/.next/.next/server/app/api/cloudflare/route_client-reference-manifest.js +1 -1
- package/dist/.next/.next/server/app/api/databases/route.js +1 -1
- package/dist/.next/.next/server/app/api/databases/route.js.nft.json +1 -1
- package/dist/.next/.next/server/app/api/databases/route_client-reference-manifest.js +1 -1
- package/dist/.next/.next/server/app/api/migrations/sync/route.js +3 -3
- package/dist/.next/.next/server/app/api/migrations/sync/route.js.nft.json +1 -1
- package/dist/.next/.next/server/app/api/migrations/sync/route_client-reference-manifest.js +1 -1
- package/dist/.next/.next/server/app/api/migrations/sync-files/route.js +1 -1
- package/dist/.next/.next/server/app/api/migrations/sync-files/route.js.nft.json +1 -1
- package/dist/.next/.next/server/app/api/migrations/sync-files/route_client-reference-manifest.js +1 -1
- package/dist/.next/.next/server/app/api/pull-remote/confirm/route.js +1 -1
- package/dist/.next/.next/server/app/api/pull-remote/confirm/route.js.nft.json +1 -1
- package/dist/.next/.next/server/app/api/pull-remote/confirm/route_client-reference-manifest.js +1 -1
- package/dist/.next/.next/server/app/api/pull-remote/preview/route.js +1 -1
- package/dist/.next/.next/server/app/api/pull-remote/preview/route.js.nft.json +1 -1
- package/dist/.next/.next/server/app/api/pull-remote/preview/route_client-reference-manifest.js +1 -1
- package/dist/.next/.next/server/app/api/push-remote/confirm/route.js +2 -2
- package/dist/.next/.next/server/app/api/push-remote/confirm/route.js.nft.json +1 -1
- package/dist/.next/.next/server/app/api/push-remote/confirm/route_client-reference-manifest.js +1 -1
- package/dist/.next/.next/server/app/api/push-remote/preview/route.js +2 -2
- package/dist/.next/.next/server/app/api/push-remote/preview/route.js.nft.json +1 -1
- package/dist/.next/.next/server/app/api/push-remote/preview/route_client-reference-manifest.js +1 -1
- package/dist/.next/.next/server/app/api/query/route.js +2 -2
- package/dist/.next/.next/server/app/api/query/route.js.nft.json +1 -1
- package/dist/.next/.next/server/app/api/query/route_client-reference-manifest.js +1 -1
- package/dist/.next/.next/server/app/api/tables/[name]/route.js +4 -4
- package/dist/.next/.next/server/app/api/tables/[name]/route.js.nft.json +1 -1
- package/dist/.next/.next/server/app/api/tables/[name]/route_client-reference-manifest.js +1 -1
- package/dist/.next/.next/server/app/api/tables/route.js +2 -2
- package/dist/.next/.next/server/app/api/tables/route.js.nft.json +1 -1
- package/dist/.next/.next/server/app/api/tables/route_client-reference-manifest.js +1 -1
- package/dist/.next/.next/server/app/index.html +3 -3
- package/dist/.next/.next/server/app/index.rsc +3 -3
- package/dist/.next/.next/server/app/page.js +8 -8
- package/dist/.next/.next/server/app/page_client-reference-manifest.js +1 -1
- package/dist/.next/.next/server/app-paths-manifest.json +3 -3
- package/dist/.next/.next/server/chunks/336.js +1 -1
- package/dist/.next/.next/server/chunks/{801.js → 603.js} +11 -11
- package/dist/.next/.next/server/chunks/686.js +23 -0
- package/dist/.next/.next/server/chunks/992.js +2 -2
- package/dist/.next/.next/server/pages/404.html +1 -1
- package/dist/.next/.next/server/pages/500.html +1 -1
- package/dist/.next/.next/server/server-reference-manifest.json +1 -1
- package/dist/.next/.next/server/webpack-runtime.js +1 -1
- package/dist/.next/.next/static/chunks/app/page-79049bfa6cc07e11.js +1 -0
- package/dist/.next/.next/static/css/cf41da7a0d47f779.css +3 -0
- package/dist/.next/.next/trace +3 -3
- package/dist/.next/BUILD_ID +1 -1
- package/dist/.next/app-build-manifest.json +18 -18
- package/dist/.next/app-path-routes-manifest.json +1 -1
- package/dist/.next/build-manifest.json +2 -2
- package/dist/.next/cache/.rscinfo +1 -1
- package/dist/.next/cache/.tsbuildinfo +1 -1
- package/dist/.next/cache/webpack/client-production/0.pack +0 -0
- package/dist/.next/cache/webpack/client-production/index.pack +0 -0
- package/dist/.next/cache/webpack/edge-server-production/index.pack +0 -0
- package/dist/.next/cache/webpack/server-production/0.pack +0 -0
- package/dist/.next/cache/webpack/server-production/index.pack +0 -0
- package/dist/.next/next-minimal-server.js.nft.json +1 -1
- package/dist/.next/next-server.js.nft.json +1 -1
- package/dist/.next/prerender-manifest.json +1 -1
- package/dist/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
- package/dist/.next/server/app/_not-found.html +1 -1
- package/dist/.next/server/app/_not-found.rsc +2 -2
- package/dist/.next/server/app/api/cloudflare/route.js +1 -1
- package/dist/.next/server/app/api/cloudflare/route.js.nft.json +1 -1
- package/dist/.next/server/app/api/cloudflare/route_client-reference-manifest.js +1 -1
- package/dist/.next/server/app/api/databases/route.js +1 -1
- package/dist/.next/server/app/api/databases/route.js.nft.json +1 -1
- package/dist/.next/server/app/api/databases/route_client-reference-manifest.js +1 -1
- package/dist/.next/server/app/api/migrations/sync/route.js +3 -3
- package/dist/.next/server/app/api/migrations/sync/route.js.nft.json +1 -1
- package/dist/.next/server/app/api/migrations/sync/route_client-reference-manifest.js +1 -1
- package/dist/.next/server/app/api/migrations/sync-files/route.js +1 -1
- package/dist/.next/server/app/api/migrations/sync-files/route.js.nft.json +1 -1
- package/dist/.next/server/app/api/migrations/sync-files/route_client-reference-manifest.js +1 -1
- package/dist/.next/server/app/api/pull-remote/confirm/route.js +1 -1
- package/dist/.next/server/app/api/pull-remote/confirm/route.js.nft.json +1 -1
- package/dist/.next/server/app/api/pull-remote/confirm/route_client-reference-manifest.js +1 -1
- package/dist/.next/server/app/api/pull-remote/preview/route.js +1 -1
- package/dist/.next/server/app/api/pull-remote/preview/route.js.nft.json +1 -1
- package/dist/.next/server/app/api/pull-remote/preview/route_client-reference-manifest.js +1 -1
- package/dist/.next/server/app/api/push-remote/confirm/route.js +2 -2
- package/dist/.next/server/app/api/push-remote/confirm/route.js.nft.json +1 -1
- package/dist/.next/server/app/api/push-remote/confirm/route_client-reference-manifest.js +1 -1
- package/dist/.next/server/app/api/push-remote/preview/route.js +2 -2
- package/dist/.next/server/app/api/push-remote/preview/route.js.nft.json +1 -1
- package/dist/.next/server/app/api/push-remote/preview/route_client-reference-manifest.js +1 -1
- package/dist/.next/server/app/api/query/route.js +2 -2
- package/dist/.next/server/app/api/query/route.js.nft.json +1 -1
- package/dist/.next/server/app/api/query/route_client-reference-manifest.js +1 -1
- package/dist/.next/server/app/api/tables/[name]/route.js +4 -4
- package/dist/.next/server/app/api/tables/[name]/route.js.nft.json +1 -1
- package/dist/.next/server/app/api/tables/[name]/route_client-reference-manifest.js +1 -1
- package/dist/.next/server/app/api/tables/route.js +2 -2
- package/dist/.next/server/app/api/tables/route.js.nft.json +1 -1
- package/dist/.next/server/app/api/tables/route_client-reference-manifest.js +1 -1
- package/dist/.next/server/app/index.html +3 -3
- package/dist/.next/server/app/index.rsc +3 -3
- package/dist/.next/server/app/page.js +8 -8
- package/dist/.next/server/app/page_client-reference-manifest.js +1 -1
- package/dist/.next/server/app-paths-manifest.json +7 -7
- package/dist/.next/server/chunks/{801.js → 603.js} +11 -11
- package/dist/.next/server/chunks/686.js +23 -0
- package/dist/.next/server/pages/404.html +1 -1
- package/dist/.next/server/pages/500.html +1 -1
- package/dist/.next/server/server-reference-manifest.json +1 -1
- package/dist/.next/server/webpack-runtime.js +1 -1
- package/dist/.next/static/chunks/app/page-79049bfa6cc07e11.js +1 -0
- package/dist/.next/static/css/cf41da7a0d47f779.css +3 -0
- package/dist/.next/trace +14 -13
- package/dist/app/api/databases/route.js +1 -1
- package/dist/app/api/pull-remote/confirm/route.js +20 -20
- package/dist/app/api/push-remote/confirm/route.js +1 -1
- package/dist/app/api/push-remote/preview/route.js +1 -1
- package/dist/app/api/query/route.js +7 -7
- package/dist/app/app/api/databases/route.js +1 -1
- package/dist/app/app/api/pull-remote/confirm/route.js +20 -20
- package/dist/app/app/api/push-remote/confirm/route.js +1 -1
- package/dist/app/app/api/push-remote/preview/route.js +1 -1
- package/dist/app/app/api/query/route.js +7 -7
- package/dist/app/app/page.jsx +3 -6
- package/dist/app/page.jsx +3 -6
- package/dist/d1-studio.js +42 -87
- package/dist/lib/find-wrangler-config.js +10 -9
- package/dist/lib/logger.js +19 -0
- package/package.json +1 -1
- package/scripts/studio.js +42 -87
- package/src/app/api/databases/route.js +1 -1
- package/src/app/api/pull-remote/confirm/route.js +20 -20
- package/src/app/api/push-remote/confirm/route.js +1 -1
- package/src/app/api/push-remote/preview/route.js +1 -1
- package/src/app/api/query/route.js +7 -7
- package/src/app/page.jsx +3 -6
- package/src/components/sidebar.jsx +108 -92
- package/src/lib/find-wrangler-config.js +10 -9
- package/src/lib/logger.js +19 -0
- package/dist/.next/.next/cache/webpack/client-production/3.pack +0 -0
- package/dist/.next/.next/cache/webpack/client-production/4.pack +0 -0
- package/dist/.next/.next/cache/webpack/client-production/5.pack +0 -0
- package/dist/.next/.next/cache/webpack/server-production/2.pack +0 -0
- package/dist/.next/.next/cache/webpack/server-production/3.pack +0 -0
- package/dist/.next/.next/cache/webpack/server-production/4.pack +0 -0
- package/dist/.next/.next/server/chunks/973.js +0 -2
- package/dist/.next/.next/static/_t0S4u4KzUwKctaxLKvx4/_buildManifest.js +0 -1
- package/dist/.next/.next/static/_t0S4u4KzUwKctaxLKvx4/_ssgManifest.js +0 -1
- package/dist/.next/.next/static/chunks/app/page-75081ac7a88cb706.js +0 -1
- package/dist/.next/.next/static/css/c51a7ef325e30c16.css +0 -3
- package/dist/.next/.next/static/xzPddcyKcodbwNX_sKljr/_buildManifest.js +0 -1
- package/dist/.next/.next/static/xzPddcyKcodbwNX_sKljr/_ssgManifest.js +0 -1
- package/dist/.next/server/chunks/973.js +0 -2
- package/dist/.next/static/OmPVuV0d1lrcjSBQzxkdH/_buildManifest.js +0 -1
- package/dist/.next/static/OmPVuV0d1lrcjSBQzxkdH/_ssgManifest.js +0 -1
- package/dist/.next/static/chunks/app/page-75081ac7a88cb706.js +0 -1
- package/dist/.next/static/css/c51a7ef325e30c16.css +0 -3
- /package/dist/.next/.next/static/{ODMSSwVqLoDcBgbFHUjr8 → q6WmQmyONe88bMN0_jrC2}/_buildManifest.js +0 -0
- /package/dist/.next/.next/static/{ODMSSwVqLoDcBgbFHUjr8 → q6WmQmyONe88bMN0_jrC2}/_ssgManifest.js +0 -0
- /package/dist/.next/{.next/static/YIuXI2CxMwg2fuuUEBsXL → static/Tk1fnz_CXLavm23ZEeChG}/_buildManifest.js +0 -0
- /package/dist/.next/{.next/static/YIuXI2CxMwg2fuuUEBsXL → static/Tk1fnz_CXLavm23ZEeChG}/_ssgManifest.js +0 -0
package/scripts/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
|
-
|
|
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
|
-
|
|
131
|
-
|
|
132
|
-
//
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
158
|
+
logger.error(chalk.red(`Server error: ${err}`));
|
|
183
159
|
rejectPromise(err);
|
|
184
160
|
});
|
|
185
161
|
})
|
|
186
162
|
.catch((err) => {
|
|
187
|
-
|
|
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
|
-
|
|
171
|
+
logger.info(chalk.green('Initializing D1 Studio...'));
|
|
196
172
|
|
|
197
173
|
// Validate license
|
|
198
174
|
let licenseData = await checkLicenseFile();
|
|
199
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
226
|
+
logger.info(chalk.green('\nLicense activated successfully!'));
|
|
258
227
|
} catch (error) {
|
|
259
|
-
|
|
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
|
-
|
|
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
|
-
|
|
279
|
-
|
|
280
|
-
|
|
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
|
-
|
|
288
|
-
|
|
289
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
337
|
-
|
|
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
|
-
|
|
297
|
+
logger.error(chalk.red(`\nConfiguration error: ${configError.message}`));
|
|
342
298
|
process.exit(1);
|
|
343
299
|
}
|
|
344
|
-
|
|
345
300
|
} catch (error) {
|
|
346
|
-
|
|
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
|
-
|
|
308
|
+
logger.info(chalk.yellow('\nShutting down D1 Studio...'));
|
|
354
309
|
process.exit(0);
|
|
355
310
|
});
|
|
356
311
|
|
|
357
312
|
process.on('SIGTERM', () => {
|
|
358
|
-
|
|
313
|
+
logger.info(chalk.yellow('\nShutting down D1 Studio...'));
|
|
359
314
|
process.exit(0);
|
|
360
315
|
});
|
|
361
316
|
|
|
362
317
|
startStudio().catch((error) => {
|
|
363
|
-
|
|
318
|
+
logger.error(chalk.red(`\nFailed to start D1 Studio: ${error}`));
|
|
364
319
|
process.exit(1);
|
|
365
320
|
});
|
|
@@ -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
|
}
|
package/src/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="
|
|
19
|
+
<div className="min-h-screen bg-background">
|
|
23
20
|
<AppSidebar
|
|
24
|
-
className="w-64 border-r
|
|
21
|
+
className="w-64 border-r"
|
|
25
22
|
currentView={currentView}
|
|
26
23
|
onNavigate={setCurrentView}
|
|
27
24
|
onTableSelect={handleTableSelect}
|
|
28
25
|
/>
|
|
29
|
-
<main className="
|
|
26
|
+
<main className="ml-64 h-screen">
|
|
30
27
|
{currentView === 'sql-editor' && <SQLEditor />}
|
|
31
28
|
{currentView === 'table-view' && selectedTable && (
|
|
32
29
|
<TableView tableName={selectedTable} />
|