playcademy 0.13.22 → 0.14.0
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 -43
- package/dist/index.d.ts +69 -1
- package/dist/index.js +1693 -812
- package/dist/templates/database/db-seed.ts.template +7 -19
- package/dist/utils.js +56 -6
- package/package.json +2 -2
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
|
@@ -23,6 +23,30 @@ import { copyFileSync, existsSync, mkdirSync, readdirSync, unlinkSync } from "fs
|
|
|
23
23
|
import { join as join2 } from "path";
|
|
24
24
|
import Database from "better-sqlite3";
|
|
25
25
|
|
|
26
|
+
// src/constants/config.ts
|
|
27
|
+
var ENV_FILES = [
|
|
28
|
+
".env",
|
|
29
|
+
// Loaded first
|
|
30
|
+
".env.development",
|
|
31
|
+
// Overrides .env
|
|
32
|
+
".env.local"
|
|
33
|
+
// Overrides all (highest priority)
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
// src/constants/bucket.ts
|
|
37
|
+
var BUCKET_ALWAYS_SKIP = [".git", ".DS_Store", ".gitignore", ...ENV_FILES];
|
|
38
|
+
|
|
39
|
+
// src/constants/cloudflare.ts
|
|
40
|
+
var CLOUDFLARE_BINDINGS = {
|
|
41
|
+
/** R2 bucket binding name */
|
|
42
|
+
BUCKET: "BUCKET",
|
|
43
|
+
/** KV namespace binding name */
|
|
44
|
+
KV: "KV",
|
|
45
|
+
/** D1 database binding name */
|
|
46
|
+
DB: "DB"
|
|
47
|
+
};
|
|
48
|
+
var MINIFLARE_D1_DIRECTORY = "miniflare-D1DatabaseObject";
|
|
49
|
+
|
|
26
50
|
// src/constants/paths.ts
|
|
27
51
|
import { join } from "path";
|
|
28
52
|
var WORKSPACE_NAME = ".playcademy";
|
|
@@ -89,7 +113,7 @@ var createEmptyDatabase = (path) => {
|
|
|
89
113
|
db.close();
|
|
90
114
|
};
|
|
91
115
|
var findMiniflareDatabase = (dbDir) => {
|
|
92
|
-
const miniflareDir = join2(dbDir,
|
|
116
|
+
const miniflareDir = join2(dbDir, MINIFLARE_D1_DIRECTORY);
|
|
93
117
|
if (!existsSync(miniflareDir)) return null;
|
|
94
118
|
const sqliteFiles = readdirSync(miniflareDir).filter((file) => file.endsWith(".sqlite"));
|
|
95
119
|
if (sqliteFiles.length === 0) return null;
|
|
@@ -114,9 +138,61 @@ function getDevDbPath() {
|
|
|
114
138
|
return initialDbPath;
|
|
115
139
|
}
|
|
116
140
|
|
|
141
|
+
// src/lib/db/bundle-seed.ts
|
|
142
|
+
async function bundleSeedWorker(seedFilePath, projectPath) {
|
|
143
|
+
const esbuild2 = await import("esbuild");
|
|
144
|
+
const entryCode = `
|
|
145
|
+
import { seed } from '${seedFilePath}'
|
|
146
|
+
|
|
147
|
+
export default {
|
|
148
|
+
async fetch(req, env, ctx) {
|
|
149
|
+
try {
|
|
150
|
+
// Create Hono-like context
|
|
151
|
+
const c = { env, ctx, req }
|
|
152
|
+
await seed(c)
|
|
153
|
+
return Response.json({ success: true })
|
|
154
|
+
} catch (error) {
|
|
155
|
+
return Response.json({
|
|
156
|
+
success: false,
|
|
157
|
+
error: error instanceof Error ? error.message : String(error),
|
|
158
|
+
stack: error instanceof Error ? error.stack : undefined,
|
|
159
|
+
}, 500)
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
`;
|
|
164
|
+
const buildConfig = {
|
|
165
|
+
stdin: {
|
|
166
|
+
contents: entryCode,
|
|
167
|
+
resolveDir: projectPath,
|
|
168
|
+
loader: "ts"
|
|
169
|
+
},
|
|
170
|
+
bundle: true,
|
|
171
|
+
format: "esm",
|
|
172
|
+
platform: "browser",
|
|
173
|
+
target: "esnext",
|
|
174
|
+
external: [],
|
|
175
|
+
// Bundle everything for self-contained worker
|
|
176
|
+
write: false,
|
|
177
|
+
minify: false,
|
|
178
|
+
sourcemap: false,
|
|
179
|
+
logLevel: "error"
|
|
180
|
+
};
|
|
181
|
+
const result = await esbuild2.build(buildConfig);
|
|
182
|
+
if (!result.outputFiles?.[0]) {
|
|
183
|
+
throw new Error("Seed worker bundling failed: no output");
|
|
184
|
+
}
|
|
185
|
+
const code = result.outputFiles[0].text;
|
|
186
|
+
return {
|
|
187
|
+
code,
|
|
188
|
+
size: code.length
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
|
|
117
192
|
// src/lib/db/reset.ts
|
|
118
193
|
import { execSync as execSync2 } from "child_process";
|
|
119
|
-
import
|
|
194
|
+
import { rmSync as rmSync2 } from "fs";
|
|
195
|
+
import { join as join5 } from "path";
|
|
120
196
|
|
|
121
197
|
// ../utils/src/ansi.ts
|
|
122
198
|
var colors = {
|
|
@@ -339,6 +415,9 @@ async function runStep(text, action, successText, options) {
|
|
|
339
415
|
}
|
|
340
416
|
}
|
|
341
417
|
|
|
418
|
+
// ../utils/src/pure/index.ts
|
|
419
|
+
init_package_json();
|
|
420
|
+
|
|
342
421
|
// ../utils/src/package-manager.ts
|
|
343
422
|
import { execSync } from "child_process";
|
|
344
423
|
import { existsSync as existsSync2 } from "fs";
|
|
@@ -619,19 +698,6 @@ var logger = {
|
|
|
619
698
|
}
|
|
620
699
|
};
|
|
621
700
|
|
|
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
701
|
// src/lib/config/loader.ts
|
|
636
702
|
init_file_loader();
|
|
637
703
|
|
|
@@ -641,45 +707,88 @@ import { fileURLToPath } from "url";
|
|
|
641
707
|
var currentDir = dirname(fileURLToPath(import.meta.url));
|
|
642
708
|
|
|
643
709
|
// src/lib/core/import.ts
|
|
710
|
+
import { mkdtempSync, rmSync } from "fs";
|
|
711
|
+
import { tmpdir } from "os";
|
|
712
|
+
import { join as join4 } from "path";
|
|
713
|
+
import { pathToFileURL } from "url";
|
|
644
714
|
import * as esbuild from "esbuild";
|
|
715
|
+
async function importTypescriptFile(filePath, bundleOptions) {
|
|
716
|
+
const tempDir = mkdtempSync(join4(tmpdir(), "playcademy-import-"));
|
|
717
|
+
const outFile = join4(tempDir, "bundle.mjs");
|
|
718
|
+
try {
|
|
719
|
+
await esbuild.build({
|
|
720
|
+
entryPoints: [filePath],
|
|
721
|
+
outfile: outFile,
|
|
722
|
+
bundle: true,
|
|
723
|
+
platform: "node",
|
|
724
|
+
format: "esm",
|
|
725
|
+
target: "node20",
|
|
726
|
+
sourcemap: false,
|
|
727
|
+
minify: false,
|
|
728
|
+
...bundleOptions
|
|
729
|
+
});
|
|
730
|
+
const module = await import(pathToFileURL(outFile).href);
|
|
731
|
+
return module;
|
|
732
|
+
} finally {
|
|
733
|
+
rmSync(tempDir, { recursive: true, force: true });
|
|
734
|
+
}
|
|
735
|
+
}
|
|
645
736
|
|
|
646
737
|
// 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",
|
|
738
|
+
async function resetDatabase(workspace, mf, options = { debug: false }) {
|
|
739
|
+
const { debug } = options;
|
|
740
|
+
const dbDir = join5(workspace, CLI_DIRECTORIES.DATABASE);
|
|
741
|
+
await runStep(
|
|
742
|
+
"Resetting database...",
|
|
656
743
|
async () => {
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
744
|
+
rmSync2(dbDir, { recursive: true, force: true });
|
|
745
|
+
try {
|
|
746
|
+
const d1 = await mf.getD1Database(CLOUDFLARE_BINDINGS.DB);
|
|
747
|
+
await d1.exec("SELECT 1");
|
|
748
|
+
} catch {
|
|
749
|
+
logger.error("Database recreation failed");
|
|
750
|
+
logger.newLine();
|
|
751
|
+
process.exit(1);
|
|
661
752
|
}
|
|
662
|
-
|
|
753
|
+
const pm = getPackageManager();
|
|
754
|
+
const pushCommand = getRunCommand(pm, "db:push");
|
|
755
|
+
execSync2(pushCommand, {
|
|
756
|
+
cwd: workspace,
|
|
757
|
+
stdio: debug ? ["inherit", "inherit", "inherit"] : ["inherit", "ignore", "ignore"]
|
|
758
|
+
});
|
|
663
759
|
},
|
|
664
|
-
"
|
|
760
|
+
"Database reset"
|
|
665
761
|
);
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
logger.
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
// src/lib/db/seed.ts
|
|
765
|
+
async function importSeedModule(seedPath) {
|
|
766
|
+
return await importTypescriptFile(seedPath);
|
|
767
|
+
}
|
|
768
|
+
async function executeSeedFile(seedFilePath, mf) {
|
|
769
|
+
const d1 = await mf.getD1Database(CLOUDFLARE_BINDINGS.DB);
|
|
770
|
+
const seedModule = await importSeedModule(seedFilePath);
|
|
771
|
+
if (typeof seedModule.seed !== "function") {
|
|
772
|
+
logger.error("Seed file must export a seed function");
|
|
773
|
+
logger.newLine();
|
|
774
|
+
logger.admonition("warning", "Invalid Seed File", [
|
|
775
|
+
`Expected: \`export async function seed(c: Context) { ... }\``,
|
|
776
|
+
`Found in: <${seedFilePath}>`
|
|
777
|
+
]);
|
|
778
|
+
logger.newLine();
|
|
679
779
|
process.exit(1);
|
|
680
780
|
}
|
|
781
|
+
await runStep(
|
|
782
|
+
"Seeding database...",
|
|
783
|
+
async () => seedModule.seed?.({ env: { DB: d1 } }),
|
|
784
|
+
"Database seeded successfully!"
|
|
785
|
+
);
|
|
786
|
+
logger.newLine();
|
|
681
787
|
}
|
|
682
788
|
export {
|
|
789
|
+
bundleSeedWorker,
|
|
790
|
+
executeSeedFile,
|
|
683
791
|
getDevDbPath as getPath,
|
|
792
|
+
importSeedModule,
|
|
684
793
|
resetDatabase
|
|
685
794
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -169,6 +169,74 @@ interface BackendFeatures {
|
|
|
169
169
|
hasSecrets: boolean;
|
|
170
170
|
}
|
|
171
171
|
|
|
172
|
+
/**
|
|
173
|
+
* Bucket command types
|
|
174
|
+
*/
|
|
175
|
+
/**
|
|
176
|
+
* Base options shared across bucket commands
|
|
177
|
+
*/
|
|
178
|
+
interface BaseBucketOptions {
|
|
179
|
+
/** Output in raw format */
|
|
180
|
+
raw?: boolean;
|
|
181
|
+
/** Output in JSON format */
|
|
182
|
+
json?: boolean;
|
|
183
|
+
/** Use remote bucket storage */
|
|
184
|
+
remote?: boolean;
|
|
185
|
+
/** Environment (staging or production) */
|
|
186
|
+
env?: string;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Options for the bucket list command
|
|
190
|
+
*/
|
|
191
|
+
interface BucketListOptions extends BaseBucketOptions {
|
|
192
|
+
/** Filter files by key prefix */
|
|
193
|
+
prefix?: string;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Options for the bucket get command
|
|
197
|
+
*/
|
|
198
|
+
interface BucketGetOptions extends BaseBucketOptions {
|
|
199
|
+
/** Output file path */
|
|
200
|
+
output?: string;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Options for the bucket put command
|
|
204
|
+
*/
|
|
205
|
+
type BucketPutOptions = BaseBucketOptions;
|
|
206
|
+
/**
|
|
207
|
+
* Options for the bucket delete command
|
|
208
|
+
*/
|
|
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
|
+
}
|
|
239
|
+
|
|
172
240
|
/**
|
|
173
241
|
* @fileoverview Server SDK Type Definitions
|
|
174
242
|
*
|
|
@@ -954,4 +1022,4 @@ interface KeyMetadata {
|
|
|
954
1022
|
valueType?: 'json' | 'string';
|
|
955
1023
|
}
|
|
956
1024
|
|
|
957
|
-
export type { ApiConfig, ApiErrorResponse, ApiKeyListItem, ApiKeyWithSecret, ApiRequestOptions, AuthProfile, AuthStore, BackendBundle, BackendDeploymentWithHash, BackendDiff, BackendFeatures, 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 };
|