playcademy 0.13.23 → 0.14.1
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/constants.d.ts +49 -12
- package/dist/constants.js +24 -7
- package/dist/db.d.ts +62 -18
- package/dist/db.js +152 -51
- package/dist/index.d.ts +30 -1
- package/dist/index.js +1180 -510
- package/dist/templates/database/db-seed.ts.template +7 -19
- package/dist/utils.js +44 -6
- package/package.json +2 -4
package/dist/constants.d.ts
CHANGED
|
@@ -9,6 +9,45 @@ export { GAME_WORKER_DOMAINS, PLAYCADEMY_BASE_URLS, PLAYCADEMY_DOMAINS } from '@
|
|
|
9
9
|
*/
|
|
10
10
|
declare const DEFAULT_API_ROUTES_DIRECTORY = "server/api";
|
|
11
11
|
|
|
12
|
+
/**
|
|
13
|
+
* Bucket-related constants
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Files and directories that are always excluded from bucket bulk uploads
|
|
17
|
+
*
|
|
18
|
+
* These are automatically skipped regardless of .gitignore patterns:
|
|
19
|
+
* - .git - Git repository data
|
|
20
|
+
* - .DS_Store - macOS filesystem metadata
|
|
21
|
+
* - .gitignore - Git ignore configuration (shouldn't be uploaded to storage)
|
|
22
|
+
* - .env* - Environment files (should never be uploaded to storage)
|
|
23
|
+
*/
|
|
24
|
+
declare const BUCKET_ALWAYS_SKIP: readonly [".git", ".DS_Store", ".gitignore", ".env", ".env.development", ".env.local"];
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Cloudflare-related constants
|
|
28
|
+
*/
|
|
29
|
+
/**
|
|
30
|
+
* Cloudflare Workers compatibility date
|
|
31
|
+
* Update when adopting new Cloudflare features or breaking changes
|
|
32
|
+
*/
|
|
33
|
+
declare const CLOUDFLARE_COMPATIBILITY_DATE = "2024-01-01";
|
|
34
|
+
/**
|
|
35
|
+
* Cloudflare binding names for local development (Miniflare)
|
|
36
|
+
*/
|
|
37
|
+
declare const CLOUDFLARE_BINDINGS: {
|
|
38
|
+
/** R2 bucket binding name */
|
|
39
|
+
readonly BUCKET: "BUCKET";
|
|
40
|
+
/** KV namespace binding name */
|
|
41
|
+
readonly KV: "KV";
|
|
42
|
+
/** D1 database binding name */
|
|
43
|
+
readonly DB: "DB";
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Miniflare D1 database directory name
|
|
47
|
+
* Created by Miniflare when running local development with D1 databases
|
|
48
|
+
*/
|
|
49
|
+
declare const MINIFLARE_D1_DIRECTORY = "miniflare-D1DatabaseObject";
|
|
50
|
+
|
|
12
51
|
/**
|
|
13
52
|
* Configuration file constants
|
|
14
53
|
*
|
|
@@ -40,17 +79,21 @@ declare const TSCONFIG_FILES: readonly ["tsconfig.app.json", "tsconfig.json"];
|
|
|
40
79
|
* Database-related constants
|
|
41
80
|
*/
|
|
42
81
|
/**
|
|
43
|
-
* Default directory for database files
|
|
82
|
+
* Default directory for database files (configurable via playcademy.config)
|
|
44
83
|
*/
|
|
45
84
|
declare const DEFAULT_DATABASE_DIRECTORY = "db";
|
|
46
85
|
/**
|
|
47
|
-
*
|
|
86
|
+
* Schema subdirectory name within database directory (fixed structure)
|
|
87
|
+
*/
|
|
88
|
+
declare const SCHEMA_SUBDIRECTORY = "schema";
|
|
89
|
+
/**
|
|
90
|
+
* Schema entry point file name (fixed structure)
|
|
48
91
|
*/
|
|
49
|
-
declare const
|
|
92
|
+
declare const SCHEMA_INDEX_FILE = "index.ts";
|
|
50
93
|
/**
|
|
51
|
-
* Default
|
|
94
|
+
* Default seed file name (can be overridden with --file option)
|
|
52
95
|
*/
|
|
53
|
-
declare const
|
|
96
|
+
declare const DEFAULT_SEED_FILE_NAME = "seed.ts";
|
|
54
97
|
|
|
55
98
|
/**
|
|
56
99
|
* HTTP server constants for CLI OAuth callback handling
|
|
@@ -120,10 +163,4 @@ declare const DEFAULT_PORTS: {
|
|
|
120
163
|
*/
|
|
121
164
|
declare const CONFIG_FILE_NAMES: string[];
|
|
122
165
|
|
|
123
|
-
|
|
124
|
-
* Cloudflare Workers compatibility date
|
|
125
|
-
* Update when adopting new Cloudflare features or breaking changes
|
|
126
|
-
*/
|
|
127
|
-
declare const CLOUDFLARE_COMPATIBILITY_DATE = "2024-01-01";
|
|
128
|
-
|
|
129
|
-
export { CALLBACK_PATH, CALLBACK_PORT, CLI_DEFAULT_OUTPUTS, CLI_DIRECTORIES, CLI_FILES, CLI_USER_DIRECTORIES, CLOUDFLARE_COMPATIBILITY_DATE, CONFIG_FILE_NAMES, DEFAULT_API_ROUTES_DIRECTORY, DEFAULT_DATABASE_DIRECTORY, DEFAULT_PORTS, DEFAULT_SCHEMA_DIRECTORY, DEFAULT_SEED_FILE, ENV_FILES, SSO_AUTH_TIMEOUT_MS, TSCONFIG_FILES, WORKSPACE_NAME };
|
|
166
|
+
export { BUCKET_ALWAYS_SKIP, CALLBACK_PATH, CALLBACK_PORT, CLI_DEFAULT_OUTPUTS, CLI_DIRECTORIES, CLI_FILES, CLI_USER_DIRECTORIES, CLOUDFLARE_BINDINGS, CLOUDFLARE_COMPATIBILITY_DATE, CONFIG_FILE_NAMES, DEFAULT_API_ROUTES_DIRECTORY, DEFAULT_DATABASE_DIRECTORY, DEFAULT_PORTS, DEFAULT_SEED_FILE_NAME, ENV_FILES, MINIFLARE_D1_DIRECTORY, SCHEMA_INDEX_FILE, SCHEMA_SUBDIRECTORY, SSO_AUTH_TIMEOUT_MS, TSCONFIG_FILES, WORKSPACE_NAME };
|
package/dist/constants.js
CHANGED
|
@@ -17,10 +17,26 @@ var TSCONFIG_FILES = [
|
|
|
17
17
|
// Standard (fallback)
|
|
18
18
|
];
|
|
19
19
|
|
|
20
|
+
// src/constants/bucket.ts
|
|
21
|
+
var BUCKET_ALWAYS_SKIP = [".git", ".DS_Store", ".gitignore", ...ENV_FILES];
|
|
22
|
+
|
|
23
|
+
// src/constants/cloudflare.ts
|
|
24
|
+
var CLOUDFLARE_COMPATIBILITY_DATE = "2024-01-01";
|
|
25
|
+
var CLOUDFLARE_BINDINGS = {
|
|
26
|
+
/** R2 bucket binding name */
|
|
27
|
+
BUCKET: "BUCKET",
|
|
28
|
+
/** KV namespace binding name */
|
|
29
|
+
KV: "KV",
|
|
30
|
+
/** D1 database binding name */
|
|
31
|
+
DB: "DB"
|
|
32
|
+
};
|
|
33
|
+
var MINIFLARE_D1_DIRECTORY = "miniflare-D1DatabaseObject";
|
|
34
|
+
|
|
20
35
|
// src/constants/database.ts
|
|
21
36
|
var DEFAULT_DATABASE_DIRECTORY = "db";
|
|
22
|
-
var
|
|
23
|
-
var
|
|
37
|
+
var SCHEMA_SUBDIRECTORY = "schema";
|
|
38
|
+
var SCHEMA_INDEX_FILE = "index.ts";
|
|
39
|
+
var DEFAULT_SEED_FILE_NAME = "seed.ts";
|
|
24
40
|
|
|
25
41
|
// src/constants/http-server.ts
|
|
26
42
|
var CALLBACK_PORT = 6175;
|
|
@@ -120,27 +136,28 @@ var BADGES = {
|
|
|
120
136
|
EARLY_ADOPTER: ITEM_SLUGS.EARLY_ADOPTER_BADGE,
|
|
121
137
|
FIRST_GAME: ITEM_SLUGS.FIRST_GAME_BADGE
|
|
122
138
|
};
|
|
123
|
-
|
|
124
|
-
// src/constants/index.ts
|
|
125
|
-
var CLOUDFLARE_COMPATIBILITY_DATE = "2024-01-01";
|
|
126
139
|
export {
|
|
140
|
+
BUCKET_ALWAYS_SKIP,
|
|
127
141
|
CALLBACK_PATH,
|
|
128
142
|
CALLBACK_PORT,
|
|
129
143
|
CLI_DEFAULT_OUTPUTS,
|
|
130
144
|
CLI_DIRECTORIES,
|
|
131
145
|
CLI_FILES,
|
|
132
146
|
CLI_USER_DIRECTORIES,
|
|
147
|
+
CLOUDFLARE_BINDINGS,
|
|
133
148
|
CLOUDFLARE_COMPATIBILITY_DATE,
|
|
134
149
|
CONFIG_FILE_NAMES,
|
|
135
150
|
DEFAULT_API_ROUTES_DIRECTORY,
|
|
136
151
|
DEFAULT_DATABASE_DIRECTORY,
|
|
137
152
|
DEFAULT_PORTS,
|
|
138
|
-
|
|
139
|
-
DEFAULT_SEED_FILE,
|
|
153
|
+
DEFAULT_SEED_FILE_NAME,
|
|
140
154
|
ENV_FILES,
|
|
141
155
|
GAME_WORKER_DOMAINS,
|
|
156
|
+
MINIFLARE_D1_DIRECTORY,
|
|
142
157
|
PLAYCADEMY_BASE_URLS,
|
|
143
158
|
PLAYCADEMY_DOMAINS,
|
|
159
|
+
SCHEMA_INDEX_FILE,
|
|
160
|
+
SCHEMA_SUBDIRECTORY,
|
|
144
161
|
SSO_AUTH_TIMEOUT_MS,
|
|
145
162
|
TSCONFIG_FILES,
|
|
146
163
|
WORKSPACE_NAME
|
package/dist/db.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Miniflare } from 'miniflare';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Development Database Path Helper
|
|
@@ -29,6 +29,31 @@ import Database from 'better-sqlite3';
|
|
|
29
29
|
*/
|
|
30
30
|
declare function getDevDbPath(): string;
|
|
31
31
|
|
|
32
|
+
/**
|
|
33
|
+
* Seed Worker Bundler
|
|
34
|
+
*
|
|
35
|
+
* Bundles user's seed file into standalone Cloudflare Worker
|
|
36
|
+
*/
|
|
37
|
+
interface SeedWorkerBundle {
|
|
38
|
+
/** Bundled worker code */
|
|
39
|
+
code: string;
|
|
40
|
+
/** Size in bytes */
|
|
41
|
+
size: number;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Bundle seed file into a Cloudflare Worker
|
|
45
|
+
*
|
|
46
|
+
* Creates a minimal worker that:
|
|
47
|
+
* 1. Imports user's seed function
|
|
48
|
+
* 2. Wraps it in fetch handler
|
|
49
|
+
* 3. Returns success/error as JSON
|
|
50
|
+
*
|
|
51
|
+
* @param seedFilePath - Absolute path to seed file
|
|
52
|
+
* @param projectPath - Project root (for resolving imports)
|
|
53
|
+
* @returns Bundled worker code
|
|
54
|
+
*/
|
|
55
|
+
declare function bundleSeedWorker(seedFilePath: string, projectPath: string): Promise<SeedWorkerBundle>;
|
|
56
|
+
|
|
32
57
|
/**
|
|
33
58
|
* Database Reset Utility
|
|
34
59
|
*
|
|
@@ -36,26 +61,45 @@ declare function getDevDbPath(): string;
|
|
|
36
61
|
*/
|
|
37
62
|
|
|
38
63
|
/**
|
|
39
|
-
* Reset
|
|
64
|
+
* Reset local database
|
|
40
65
|
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
* 2. Runs `drizzle-kit push` to recreate tables from your schema
|
|
44
|
-
* 3. Returns a connected drizzle instance ready for seeding
|
|
66
|
+
* Shared utility for db reset and db seed commands.
|
|
67
|
+
* Deletes the database directory and runs drizzle-kit push to recreate schema.
|
|
45
68
|
*
|
|
46
|
-
* @
|
|
69
|
+
* @param workspace - Workspace root path
|
|
70
|
+
* @param mf - Miniflare instance to verify recreation
|
|
71
|
+
* @param options - Options for the reset
|
|
72
|
+
* @param options.debug - Enable debug output for drizzle-kit push
|
|
73
|
+
*/
|
|
74
|
+
declare function resetDatabase(workspace: string, mf: Miniflare, options?: {
|
|
75
|
+
debug?: boolean;
|
|
76
|
+
}): Promise<void>;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Database Seed Utilities
|
|
47
80
|
*
|
|
48
|
-
*
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
*
|
|
81
|
+
* Helpers for importing and executing seed files
|
|
82
|
+
*/
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Import user's seed module
|
|
53
86
|
*
|
|
54
|
-
*
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
87
|
+
* Bundles all deps for portability.
|
|
88
|
+
*/
|
|
89
|
+
declare function importSeedModule(seedPath: string): Promise<{
|
|
90
|
+
seed?: (c: {
|
|
91
|
+
env: {
|
|
92
|
+
DB: unknown;
|
|
93
|
+
};
|
|
94
|
+
}) => Promise<void>;
|
|
95
|
+
}>;
|
|
96
|
+
/**
|
|
97
|
+
* Execute a seed file against a Miniflare D1 instance
|
|
98
|
+
*
|
|
99
|
+
* @param seedFilePath - Path to seed file
|
|
100
|
+
* @param mf - Miniflare instance with D1 database
|
|
58
101
|
*/
|
|
59
|
-
declare function
|
|
102
|
+
declare function executeSeedFile(seedFilePath: string, mf: Miniflare): Promise<void>;
|
|
60
103
|
|
|
61
|
-
export { getDevDbPath as getPath, resetDatabase };
|
|
104
|
+
export { bundleSeedWorker, executeSeedFile, getDevDbPath as getPath, importSeedModule, resetDatabase };
|
|
105
|
+
export type { SeedWorkerBundle };
|
package/dist/db.js
CHANGED
|
@@ -21,7 +21,30 @@ var init_file_loader = __esm({
|
|
|
21
21
|
// src/lib/db/path.ts
|
|
22
22
|
import { copyFileSync, existsSync, mkdirSync, readdirSync, unlinkSync } from "fs";
|
|
23
23
|
import { join as join2 } from "path";
|
|
24
|
-
|
|
24
|
+
|
|
25
|
+
// src/constants/config.ts
|
|
26
|
+
var ENV_FILES = [
|
|
27
|
+
".env",
|
|
28
|
+
// Loaded first
|
|
29
|
+
".env.development",
|
|
30
|
+
// Overrides .env
|
|
31
|
+
".env.local"
|
|
32
|
+
// Overrides all (highest priority)
|
|
33
|
+
];
|
|
34
|
+
|
|
35
|
+
// src/constants/bucket.ts
|
|
36
|
+
var BUCKET_ALWAYS_SKIP = [".git", ".DS_Store", ".gitignore", ...ENV_FILES];
|
|
37
|
+
|
|
38
|
+
// src/constants/cloudflare.ts
|
|
39
|
+
var CLOUDFLARE_BINDINGS = {
|
|
40
|
+
/** R2 bucket binding name */
|
|
41
|
+
BUCKET: "BUCKET",
|
|
42
|
+
/** KV namespace binding name */
|
|
43
|
+
KV: "KV",
|
|
44
|
+
/** D1 database binding name */
|
|
45
|
+
DB: "DB"
|
|
46
|
+
};
|
|
47
|
+
var MINIFLARE_D1_DIRECTORY = "miniflare-D1DatabaseObject";
|
|
25
48
|
|
|
26
49
|
// src/constants/paths.ts
|
|
27
50
|
import { join } from "path";
|
|
@@ -84,12 +107,8 @@ var ensureDirectoryExists = (dir) => {
|
|
|
84
107
|
mkdirSync(dir, { recursive: true });
|
|
85
108
|
}
|
|
86
109
|
};
|
|
87
|
-
var createEmptyDatabase = (path) => {
|
|
88
|
-
const db = new Database(path);
|
|
89
|
-
db.close();
|
|
90
|
-
};
|
|
91
110
|
var findMiniflareDatabase = (dbDir) => {
|
|
92
|
-
const miniflareDir = join2(dbDir,
|
|
111
|
+
const miniflareDir = join2(dbDir, MINIFLARE_D1_DIRECTORY);
|
|
93
112
|
if (!existsSync(miniflareDir)) return null;
|
|
94
113
|
const sqliteFiles = readdirSync(miniflareDir).filter((file) => file.endsWith(".sqlite"));
|
|
95
114
|
if (sqliteFiles.length === 0) return null;
|
|
@@ -108,15 +127,64 @@ function getDevDbPath() {
|
|
|
108
127
|
migrateInitialDbToTarget(initialDbPath, miniflareDbPath);
|
|
109
128
|
return miniflareDbPath;
|
|
110
129
|
}
|
|
111
|
-
if (!existsSync(initialDbPath)) {
|
|
112
|
-
createEmptyDatabase(initialDbPath);
|
|
113
|
-
}
|
|
114
130
|
return initialDbPath;
|
|
115
131
|
}
|
|
116
132
|
|
|
133
|
+
// src/lib/db/bundle-seed.ts
|
|
134
|
+
async function bundleSeedWorker(seedFilePath, projectPath) {
|
|
135
|
+
const esbuild2 = await import("esbuild");
|
|
136
|
+
const entryCode = `
|
|
137
|
+
import { seed } from '${seedFilePath}'
|
|
138
|
+
|
|
139
|
+
export default {
|
|
140
|
+
async fetch(req, env, ctx) {
|
|
141
|
+
try {
|
|
142
|
+
// Create Hono-like context
|
|
143
|
+
const c = { env, ctx, req }
|
|
144
|
+
await seed(c)
|
|
145
|
+
return Response.json({ success: true })
|
|
146
|
+
} catch (error) {
|
|
147
|
+
return Response.json({
|
|
148
|
+
success: false,
|
|
149
|
+
error: error instanceof Error ? error.message : String(error),
|
|
150
|
+
stack: error instanceof Error ? error.stack : undefined,
|
|
151
|
+
}, 500)
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
`;
|
|
156
|
+
const buildConfig = {
|
|
157
|
+
stdin: {
|
|
158
|
+
contents: entryCode,
|
|
159
|
+
resolveDir: projectPath,
|
|
160
|
+
loader: "ts"
|
|
161
|
+
},
|
|
162
|
+
bundle: true,
|
|
163
|
+
format: "esm",
|
|
164
|
+
platform: "browser",
|
|
165
|
+
target: "esnext",
|
|
166
|
+
external: [],
|
|
167
|
+
// Bundle everything for self-contained worker
|
|
168
|
+
write: false,
|
|
169
|
+
minify: false,
|
|
170
|
+
sourcemap: false,
|
|
171
|
+
logLevel: "error"
|
|
172
|
+
};
|
|
173
|
+
const result = await esbuild2.build(buildConfig);
|
|
174
|
+
if (!result.outputFiles?.[0]) {
|
|
175
|
+
throw new Error("Seed worker bundling failed: no output");
|
|
176
|
+
}
|
|
177
|
+
const code = result.outputFiles[0].text;
|
|
178
|
+
return {
|
|
179
|
+
code,
|
|
180
|
+
size: code.length
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
|
|
117
184
|
// src/lib/db/reset.ts
|
|
118
185
|
import { execSync as execSync2 } from "child_process";
|
|
119
|
-
import
|
|
186
|
+
import { rmSync as rmSync2 } from "fs";
|
|
187
|
+
import { join as join5 } from "path";
|
|
120
188
|
|
|
121
189
|
// ../utils/src/ansi.ts
|
|
122
190
|
var colors = {
|
|
@@ -339,6 +407,9 @@ async function runStep(text, action, successText, options) {
|
|
|
339
407
|
}
|
|
340
408
|
}
|
|
341
409
|
|
|
410
|
+
// ../utils/src/pure/index.ts
|
|
411
|
+
init_package_json();
|
|
412
|
+
|
|
342
413
|
// ../utils/src/package-manager.ts
|
|
343
414
|
import { execSync } from "child_process";
|
|
344
415
|
import { existsSync as existsSync2 } from "fs";
|
|
@@ -619,19 +690,6 @@ var logger = {
|
|
|
619
690
|
}
|
|
620
691
|
};
|
|
621
692
|
|
|
622
|
-
// src/lib/core/errors.ts
|
|
623
|
-
function getErrorMessage(error) {
|
|
624
|
-
if (error instanceof Error) return error.message;
|
|
625
|
-
if (typeof error === "string") return error;
|
|
626
|
-
if (error && typeof error === "object" && "message" in error) {
|
|
627
|
-
return String(error.message);
|
|
628
|
-
}
|
|
629
|
-
return "Unknown error";
|
|
630
|
-
}
|
|
631
|
-
|
|
632
|
-
// ../utils/src/pure/index.ts
|
|
633
|
-
init_package_json();
|
|
634
|
-
|
|
635
693
|
// src/lib/config/loader.ts
|
|
636
694
|
init_file_loader();
|
|
637
695
|
|
|
@@ -641,45 +699,88 @@ import { fileURLToPath } from "url";
|
|
|
641
699
|
var currentDir = dirname(fileURLToPath(import.meta.url));
|
|
642
700
|
|
|
643
701
|
// src/lib/core/import.ts
|
|
702
|
+
import { mkdtempSync, rmSync } from "fs";
|
|
703
|
+
import { tmpdir } from "os";
|
|
704
|
+
import { join as join4 } from "path";
|
|
705
|
+
import { pathToFileURL } from "url";
|
|
644
706
|
import * as esbuild from "esbuild";
|
|
707
|
+
async function importTypescriptFile(filePath, bundleOptions) {
|
|
708
|
+
const tempDir = mkdtempSync(join4(tmpdir(), "playcademy-import-"));
|
|
709
|
+
const outFile = join4(tempDir, "bundle.mjs");
|
|
710
|
+
try {
|
|
711
|
+
await esbuild.build({
|
|
712
|
+
entryPoints: [filePath],
|
|
713
|
+
outfile: outFile,
|
|
714
|
+
bundle: true,
|
|
715
|
+
platform: "node",
|
|
716
|
+
format: "esm",
|
|
717
|
+
target: "node20",
|
|
718
|
+
sourcemap: false,
|
|
719
|
+
minify: false,
|
|
720
|
+
...bundleOptions
|
|
721
|
+
});
|
|
722
|
+
const module = await import(pathToFileURL(outFile).href);
|
|
723
|
+
return module;
|
|
724
|
+
} finally {
|
|
725
|
+
rmSync(tempDir, { recursive: true, force: true });
|
|
726
|
+
}
|
|
727
|
+
}
|
|
645
728
|
|
|
646
729
|
// src/lib/db/reset.ts
|
|
647
|
-
function resetDatabase() {
|
|
648
|
-
const
|
|
649
|
-
const
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
const DROP_ALL_USER_TABLES_SQL = `SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%'`;
|
|
653
|
-
const DROP_TABLE_SQL = (tableName) => `DROP TABLE IF EXISTS ${tableName}`;
|
|
654
|
-
runStep(
|
|
655
|
-
"Dropping all tables",
|
|
730
|
+
async function resetDatabase(workspace, mf, options = { debug: false }) {
|
|
731
|
+
const { debug } = options;
|
|
732
|
+
const dbDir = join5(workspace, CLI_DIRECTORIES.DATABASE);
|
|
733
|
+
await runStep(
|
|
734
|
+
"Resetting database...",
|
|
656
735
|
async () => {
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
736
|
+
rmSync2(dbDir, { recursive: true, force: true });
|
|
737
|
+
try {
|
|
738
|
+
const d1 = await mf.getD1Database(CLOUDFLARE_BINDINGS.DB);
|
|
739
|
+
await d1.exec("SELECT 1");
|
|
740
|
+
} catch {
|
|
741
|
+
logger.error("Database recreation failed");
|
|
742
|
+
logger.newLine();
|
|
743
|
+
process.exit(1);
|
|
661
744
|
}
|
|
662
|
-
|
|
745
|
+
const pm = getPackageManager();
|
|
746
|
+
const pushCommand = getRunCommand(pm, "db:push");
|
|
747
|
+
execSync2(pushCommand, {
|
|
748
|
+
cwd: workspace,
|
|
749
|
+
stdio: debug ? ["inherit", "inherit", "inherit"] : ["inherit", "ignore", "ignore"]
|
|
750
|
+
});
|
|
663
751
|
},
|
|
664
|
-
"
|
|
752
|
+
"Database reset"
|
|
665
753
|
);
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
logger.
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
// src/lib/db/seed.ts
|
|
757
|
+
async function importSeedModule(seedPath) {
|
|
758
|
+
return await importTypescriptFile(seedPath);
|
|
759
|
+
}
|
|
760
|
+
async function executeSeedFile(seedFilePath, mf) {
|
|
761
|
+
const d1 = await mf.getD1Database(CLOUDFLARE_BINDINGS.DB);
|
|
762
|
+
const seedModule = await importSeedModule(seedFilePath);
|
|
763
|
+
if (typeof seedModule.seed !== "function") {
|
|
764
|
+
logger.error("Seed file must export a seed function");
|
|
765
|
+
logger.newLine();
|
|
766
|
+
logger.admonition("warning", "Invalid Seed File", [
|
|
767
|
+
`Expected: \`export async function seed(c: Context) { ... }\``,
|
|
768
|
+
`Found in: <${seedFilePath}>`
|
|
769
|
+
]);
|
|
770
|
+
logger.newLine();
|
|
679
771
|
process.exit(1);
|
|
680
772
|
}
|
|
773
|
+
await runStep(
|
|
774
|
+
"Seeding database...",
|
|
775
|
+
async () => seedModule.seed?.({ env: { DB: d1 } }),
|
|
776
|
+
"Database seeded successfully!"
|
|
777
|
+
);
|
|
778
|
+
logger.newLine();
|
|
681
779
|
}
|
|
682
780
|
export {
|
|
781
|
+
bundleSeedWorker,
|
|
782
|
+
executeSeedFile,
|
|
683
783
|
getDevDbPath as getPath,
|
|
784
|
+
importSeedModule,
|
|
684
785
|
resetDatabase
|
|
685
786
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -207,6 +207,35 @@ type BucketPutOptions = BaseBucketOptions;
|
|
|
207
207
|
* Options for the bucket delete command
|
|
208
208
|
*/
|
|
209
209
|
type BucketDeleteOptions = BaseBucketOptions;
|
|
210
|
+
/**
|
|
211
|
+
* Options for the bucket bulk command
|
|
212
|
+
*/
|
|
213
|
+
interface BucketBulkOptions extends BaseBucketOptions {
|
|
214
|
+
/** Add prefix to all uploaded keys */
|
|
215
|
+
prefix?: string;
|
|
216
|
+
/** Show what would be uploaded without uploading */
|
|
217
|
+
dryRun?: boolean;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* File collection result
|
|
221
|
+
*/
|
|
222
|
+
interface CollectedFile {
|
|
223
|
+
/** Absolute path to the file */
|
|
224
|
+
absolutePath: string;
|
|
225
|
+
/** Relative path from base directory (used as bucket key) */
|
|
226
|
+
relativePath: string;
|
|
227
|
+
/** File size in bytes */
|
|
228
|
+
size: number;
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Result of collecting files for bulk upload
|
|
232
|
+
*/
|
|
233
|
+
interface BulkCollectionResult {
|
|
234
|
+
/** Files collected for upload */
|
|
235
|
+
files: CollectedFile[];
|
|
236
|
+
/** Total size of all files in bytes */
|
|
237
|
+
totalSize: number;
|
|
238
|
+
}
|
|
210
239
|
|
|
211
240
|
/**
|
|
212
241
|
* @fileoverview Server SDK Type Definitions
|
|
@@ -993,4 +1022,4 @@ interface KeyMetadata {
|
|
|
993
1022
|
valueType?: 'json' | 'string';
|
|
994
1023
|
}
|
|
995
1024
|
|
|
996
|
-
export type { ApiConfig, ApiErrorResponse, ApiKeyListItem, ApiKeyWithSecret, ApiRequestOptions, AuthProfile, AuthStore, BackendBundle, BackendDeploymentWithHash, BackendDiff, BackendFeatures, BucketDeleteOptions, BucketGetOptions, BucketListOptions, BucketPutOptions, BuildDiff, BundleOptions, CallbackServerResult, ConfigDiff, CreateApiKeyResponse, CustomRoutesIntegrationOptions, DatabaseIntegrationOptions, DeployConfig, DeployNewGameOptions, DeployedGameInfo, DeploymentChanges, DeploymentContext, DeploymentDiffOptions, DeploymentPlan, DeploymentResult, DevServerOptions, EmbeddedSourcePaths, EnvironmentAuthProfiles, GameStore, IntegrationChangeDetector, IntegrationChangeDetectors, IntegrationConfigChange, IntegrationsConfig, IntegrationsDiff, KeyMetadata, KeyStats, LoginCredentials, LoginResponse, PlaycademyConfig, PreviewOptions, PreviewResponse, SecretsDiff, SignInResponse, SsoCallbackData, TimebackIntegrationConfig, TokenType, UpdateExistingGameOptions };
|
|
1025
|
+
export type { ApiConfig, ApiErrorResponse, ApiKeyListItem, ApiKeyWithSecret, ApiRequestOptions, AuthProfile, AuthStore, BackendBundle, BackendDeploymentWithHash, BackendDiff, BackendFeatures, BucketBulkOptions, BucketDeleteOptions, BucketGetOptions, BucketListOptions, BucketPutOptions, BuildDiff, BulkCollectionResult, BundleOptions, CallbackServerResult, CollectedFile, ConfigDiff, CreateApiKeyResponse, CustomRoutesIntegrationOptions, DatabaseIntegrationOptions, DeployConfig, DeployNewGameOptions, DeployedGameInfo, DeploymentChanges, DeploymentContext, DeploymentDiffOptions, DeploymentPlan, DeploymentResult, DevServerOptions, EmbeddedSourcePaths, EnvironmentAuthProfiles, GameStore, IntegrationChangeDetector, IntegrationChangeDetectors, IntegrationConfigChange, IntegrationsConfig, IntegrationsDiff, KeyMetadata, KeyStats, LoginCredentials, LoginResponse, PlaycademyConfig, PreviewOptions, PreviewResponse, SecretsDiff, SignInResponse, SsoCallbackData, TimebackIntegrationConfig, TokenType, UpdateExistingGameOptions };
|