playcademy 0.13.23 → 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 +30 -1
- package/dist/index.js +1179 -509
- package/dist/templates/database/db-seed.ts.template +7 -19
- package/dist/utils.js +44 -6
- package/package.json +2 -2
|
@@ -2,24 +2,21 @@
|
|
|
2
2
|
* Database Seed
|
|
3
3
|
*
|
|
4
4
|
* Populate the database with initial data.
|
|
5
|
+
* This seed function works both locally and remotely.
|
|
5
6
|
*/
|
|
6
7
|
|
|
7
|
-
import
|
|
8
|
-
import { drizzle } from 'drizzle-orm/better-sqlite3'
|
|
9
|
-
|
|
10
|
-
import { getPath } from 'playcademy/db'
|
|
11
|
-
|
|
8
|
+
import { getDb } from '.'
|
|
12
9
|
import * as schema from './schema'
|
|
13
10
|
|
|
14
11
|
/**
|
|
15
12
|
* Seed the database with initial data
|
|
13
|
+
*
|
|
14
|
+
* @param c - Context with env bindings
|
|
16
15
|
*/
|
|
17
|
-
export async function seed() {
|
|
18
|
-
const
|
|
19
|
-
const sqlite = new Database(dbPath)
|
|
20
|
-
const db = drizzle(sqlite, { schema })
|
|
16
|
+
export async function seed(c: Context) {
|
|
17
|
+
const db = getDb(c.env.DB)
|
|
21
18
|
|
|
22
|
-
// Seed users
|
|
19
|
+
// Seed users
|
|
23
20
|
const [user] = await db
|
|
24
21
|
.insert(schema.users)
|
|
25
22
|
.values({
|
|
@@ -40,13 +37,4 @@ export async function seed() {
|
|
|
40
37
|
level: 1,
|
|
41
38
|
createdAt: new Date().toISOString(),
|
|
42
39
|
})
|
|
43
|
-
|
|
44
|
-
sqlite.close()
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Run seed if this file is executed directly (from e.g. a package.json script)
|
|
49
|
-
*/
|
|
50
|
-
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
51
|
-
seed().catch(console.error)
|
|
52
40
|
}
|
package/dist/utils.js
CHANGED
|
@@ -325,6 +325,33 @@ var init_config = __esm({
|
|
|
325
325
|
}
|
|
326
326
|
});
|
|
327
327
|
|
|
328
|
+
// src/constants/bucket.ts
|
|
329
|
+
var BUCKET_ALWAYS_SKIP;
|
|
330
|
+
var init_bucket = __esm({
|
|
331
|
+
"src/constants/bucket.ts"() {
|
|
332
|
+
"use strict";
|
|
333
|
+
init_config();
|
|
334
|
+
BUCKET_ALWAYS_SKIP = [".git", ".DS_Store", ".gitignore", ...ENV_FILES];
|
|
335
|
+
}
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
// src/constants/cloudflare.ts
|
|
339
|
+
var CLOUDFLARE_COMPATIBILITY_DATE, CLOUDFLARE_BINDINGS;
|
|
340
|
+
var init_cloudflare = __esm({
|
|
341
|
+
"src/constants/cloudflare.ts"() {
|
|
342
|
+
"use strict";
|
|
343
|
+
CLOUDFLARE_COMPATIBILITY_DATE = "2024-01-01";
|
|
344
|
+
CLOUDFLARE_BINDINGS = {
|
|
345
|
+
/** R2 bucket binding name */
|
|
346
|
+
BUCKET: "BUCKET",
|
|
347
|
+
/** KV namespace binding name */
|
|
348
|
+
KV: "KV",
|
|
349
|
+
/** D1 database binding name */
|
|
350
|
+
DB: "DB"
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
});
|
|
354
|
+
|
|
328
355
|
// src/constants/database.ts
|
|
329
356
|
var init_database = __esm({
|
|
330
357
|
"src/constants/database.ts"() {
|
|
@@ -492,11 +519,12 @@ var init_urls = __esm({
|
|
|
492
519
|
});
|
|
493
520
|
|
|
494
521
|
// src/constants/index.ts
|
|
495
|
-
var CLOUDFLARE_COMPATIBILITY_DATE;
|
|
496
522
|
var init_constants = __esm({
|
|
497
523
|
"src/constants/index.ts"() {
|
|
498
524
|
"use strict";
|
|
499
525
|
init_api();
|
|
526
|
+
init_bucket();
|
|
527
|
+
init_cloudflare();
|
|
500
528
|
init_config();
|
|
501
529
|
init_database();
|
|
502
530
|
init_http_server();
|
|
@@ -504,7 +532,6 @@ var init_constants = __esm({
|
|
|
504
532
|
init_ports();
|
|
505
533
|
init_timeback();
|
|
506
534
|
init_urls();
|
|
507
|
-
CLOUDFLARE_COMPATIBILITY_DATE = "2024-01-01";
|
|
508
535
|
}
|
|
509
536
|
});
|
|
510
537
|
|
|
@@ -1252,6 +1279,13 @@ var init_game = __esm({
|
|
|
1252
1279
|
}
|
|
1253
1280
|
});
|
|
1254
1281
|
|
|
1282
|
+
// src/lib/core/gitignore.ts
|
|
1283
|
+
var init_gitignore = __esm({
|
|
1284
|
+
"src/lib/core/gitignore.ts"() {
|
|
1285
|
+
"use strict";
|
|
1286
|
+
}
|
|
1287
|
+
});
|
|
1288
|
+
|
|
1255
1289
|
// src/lib/core/import.ts
|
|
1256
1290
|
import { mkdtempSync, rmSync } from "fs";
|
|
1257
1291
|
import { tmpdir } from "os";
|
|
@@ -1308,6 +1342,7 @@ var init_core = __esm({
|
|
|
1308
1342
|
init_context();
|
|
1309
1343
|
init_errors();
|
|
1310
1344
|
init_game();
|
|
1345
|
+
init_gitignore();
|
|
1311
1346
|
init_import();
|
|
1312
1347
|
init_logger();
|
|
1313
1348
|
init_mime2();
|
|
@@ -1955,6 +1990,7 @@ var dbSchemaScoresTemplate = loadTemplateString("database/db-schema-scores.ts");
|
|
|
1955
1990
|
var dbSchemaIndexTemplate = loadTemplateString("database/db-schema-index.ts");
|
|
1956
1991
|
var dbIndexTemplate = loadTemplateString("database/db-index.ts");
|
|
1957
1992
|
var dbTypesTemplate = loadTemplateString("database/db-types.ts");
|
|
1993
|
+
var dbSeedTemplate = loadTemplateString("database/db-seed.ts");
|
|
1958
1994
|
var packageTemplate = loadTemplateString("database/package.json");
|
|
1959
1995
|
function hasDatabaseSetup() {
|
|
1960
1996
|
const workspace = getWorkspace();
|
|
@@ -2012,6 +2048,8 @@ init_core();
|
|
|
2012
2048
|
init_string();
|
|
2013
2049
|
|
|
2014
2050
|
// src/lib/deploy/schema.ts
|
|
2051
|
+
init_constants2();
|
|
2052
|
+
init_config3();
|
|
2015
2053
|
init_core();
|
|
2016
2054
|
|
|
2017
2055
|
// src/lib/deploy/secrets.ts
|
|
@@ -2333,11 +2371,11 @@ async function startDevServer(options) {
|
|
|
2333
2371
|
}
|
|
2334
2372
|
],
|
|
2335
2373
|
bindings,
|
|
2336
|
-
d1Databases: hasDatabase ? [
|
|
2374
|
+
d1Databases: hasDatabase ? [CLOUDFLARE_BINDINGS.DB] : [],
|
|
2337
2375
|
d1Persist: dbDir,
|
|
2338
|
-
kvNamespaces: hasKV ? [
|
|
2376
|
+
kvNamespaces: hasKV ? [CLOUDFLARE_BINDINGS.KV] : [],
|
|
2339
2377
|
kvPersist: kvDir,
|
|
2340
|
-
r2Buckets: hasBucket ? [
|
|
2378
|
+
r2Buckets: hasBucket ? [CLOUDFLARE_BINDINGS.BUCKET] : [],
|
|
2341
2379
|
r2Persist: bucketDir,
|
|
2342
2380
|
compatibilityDate: CLOUDFLARE_COMPATIBILITY_DATE
|
|
2343
2381
|
});
|
|
@@ -2375,7 +2413,7 @@ async function ensureBucketDirectory() {
|
|
|
2375
2413
|
return bucketDir;
|
|
2376
2414
|
}
|
|
2377
2415
|
async function initializeDatabase(mf) {
|
|
2378
|
-
const d1 = await mf.getD1Database(
|
|
2416
|
+
const d1 = await mf.getD1Database(CLOUDFLARE_BINDINGS.DB);
|
|
2379
2417
|
await d1.exec("SELECT 1");
|
|
2380
2418
|
}
|
|
2381
2419
|
async function writeBackendServerInfo(port) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "playcademy",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"module": "./dist/index.js",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@inquirer/prompts": "^7.8.6",
|
|
43
|
-
"@playcademy/sdk": "0.1.
|
|
43
|
+
"@playcademy/sdk": "0.1.12",
|
|
44
44
|
"better-sqlite3": "^12.4.1",
|
|
45
45
|
"chokidar": "^4.0.3",
|
|
46
46
|
"colorette": "^2.0.20",
|