durable-db 0.1.13 → 0.2.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/cli/bin.js +3 -3
- package/dist/cli/index.d.ts +20 -12
- package/dist/cli/index.js +3 -3
- package/dist/{cli-m2H7mQpa.js → cli-DnsOTcrH.js} +20 -33
- package/dist/context/index.d.ts +1 -1
- package/dist/db/index.d.ts +3 -3
- package/dist/discovery-DfimBbS_.d.ts +11 -0
- package/dist/index.d.ts +4 -4
- package/dist/migrations/generator.d.ts +1 -1
- package/dist/migrations/snapshot.d.ts +1 -1
- package/dist/{parser-CL3Nlmsy.js → parser-BdV7Zqcv.js} +42 -47
- package/dist/{push-DiHH52-G.js → push-BhrMZaQx.js} +2 -2
- package/dist/{push-BY3lfh-R.js → push-cUJBpv5y.js} +2 -2
- package/dist/registry.d.ts +1 -1
- package/dist/schema.d.ts +1 -1
- package/dist/vite/durableDb.d.ts +3 -2
- package/dist/vite/durableDb.js +7 -4
- package/package.json +1 -1
- /package/dist/{arktypeConfig--4OgOv4U.d.ts → arktypeConfig-zgI5p6zF.d.ts} +0 -0
- /package/dist/{defineDatabase-Bjws1Jkd.d.ts → defineDatabase-DtkM6k1S.d.ts} +0 -0
- /package/dist/{index-AbdSa1Mk.d.ts → index-BHLOQ7uV.d.ts} +0 -0
- /package/dist/{index-BhRiKZ4j.d.ts → index-zzQS_psa.d.ts} +0 -0
- /package/dist/{schema-BCjqTRvV.d.ts → schema-C2yy5KCT.d.ts} +0 -0
- /package/dist/{snapshot-DOerumb7.d.ts → snapshot-DsSRYFe-.d.ts} +0 -0
package/dist/cli/bin.js
CHANGED
|
@@ -3,9 +3,9 @@ import "../debug-DmBrUmwe.js";
|
|
|
3
3
|
import "../state-DtZ70cBR.js";
|
|
4
4
|
import "../snapshot-DMW6j2Ix.js";
|
|
5
5
|
import "../generator-KHBZaOI1.js";
|
|
6
|
-
import "../parser-
|
|
7
|
-
import "../push-
|
|
8
|
-
import { n as registerDbCommands } from "../cli-
|
|
6
|
+
import "../parser-BdV7Zqcv.js";
|
|
7
|
+
import "../push-BhrMZaQx.js";
|
|
8
|
+
import { n as registerDbCommands } from "../cli-DnsOTcrH.js";
|
|
9
9
|
import { Command } from "commander";
|
|
10
10
|
|
|
11
11
|
//#region src/cli/bin.ts
|
package/dist/cli/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
import {
|
|
3
|
-
import "../
|
|
1
|
+
import { t as DatabaseSource } from "../discovery-DfimBbS_.js";
|
|
2
|
+
import { t as Snapshot } from "../snapshot-DsSRYFe-.js";
|
|
3
|
+
import { l as DatabaseInfo } from "../defineDatabase-DtkM6k1S.js";
|
|
4
|
+
import "../index-BHLOQ7uV.js";
|
|
4
5
|
import { Command } from "commander";
|
|
5
6
|
|
|
6
7
|
//#region src/cli/command.d.ts
|
|
@@ -18,14 +19,20 @@ import { Command } from "commander";
|
|
|
18
19
|
*
|
|
19
20
|
* program.addCommand(createDbCommand()); // → `mycli db push`
|
|
20
21
|
*/
|
|
21
|
-
|
|
22
|
+
interface DbCommandDefaults {
|
|
23
|
+
/** Where databases are discovered when `-d` is not given (default `src/databases`). */
|
|
24
|
+
databasesDir?: string | DatabaseSource[];
|
|
25
|
+
/** Where production migrations live when `-m` is not given (default `migrations`). */
|
|
26
|
+
migrationsDir?: string;
|
|
27
|
+
}
|
|
28
|
+
declare function registerDbCommands(program: Command, defaults?: DbCommandDefaults): Command;
|
|
22
29
|
/**
|
|
23
30
|
* Create a Commander command group named `db` with all database
|
|
24
31
|
* subcommands. Mount it in a host CLI with
|
|
25
32
|
* `program.addCommand(createDbCommand())` so the commands live under a
|
|
26
33
|
* `db` prefix (e.g. `mycli db push`).
|
|
27
34
|
*/
|
|
28
|
-
declare function createDbCommand(): Command;
|
|
35
|
+
declare function createDbCommand(defaults?: DbCommandDefaults): Command;
|
|
29
36
|
//#endregion
|
|
30
37
|
//#region src/cli/state.d.ts
|
|
31
38
|
interface DatabaseDevState {
|
|
@@ -85,7 +92,7 @@ declare function getInstanceKey(baseKey: string, epoch: string | null): string;
|
|
|
85
92
|
//#region src/cli/push.d.ts
|
|
86
93
|
interface PushContext {
|
|
87
94
|
projectRoot?: string;
|
|
88
|
-
databasesDir?: string;
|
|
95
|
+
databasesDir?: string | DatabaseSource[];
|
|
89
96
|
migrationsDir?: string;
|
|
90
97
|
verbose?: boolean;
|
|
91
98
|
}
|
|
@@ -118,7 +125,7 @@ declare function pushOne(ctx: PushContext | undefined, dbName: string): Promise<
|
|
|
118
125
|
//#region src/cli/generate.d.ts
|
|
119
126
|
interface GenerateContext {
|
|
120
127
|
projectRoot?: string;
|
|
121
|
-
databasesDir?: string;
|
|
128
|
+
databasesDir?: string | DatabaseSource[];
|
|
122
129
|
migrationsDir?: string;
|
|
123
130
|
verbose?: boolean;
|
|
124
131
|
}
|
|
@@ -156,7 +163,7 @@ declare function generateOne(ctx: GenerateContext, dbName: string, options?: Omi
|
|
|
156
163
|
//#region src/cli/reset.d.ts
|
|
157
164
|
interface ResetContext {
|
|
158
165
|
projectRoot?: string;
|
|
159
|
-
databasesDir?: string;
|
|
166
|
+
databasesDir?: string | DatabaseSource[];
|
|
160
167
|
migrationsDir?: string;
|
|
161
168
|
verbose?: boolean;
|
|
162
169
|
}
|
|
@@ -211,7 +218,7 @@ declare function resetAndPush(ctx?: ResetContext, options?: ResetOptions): Promi
|
|
|
211
218
|
//#region src/cli/status.d.ts
|
|
212
219
|
interface StatusContext {
|
|
213
220
|
projectRoot?: string;
|
|
214
|
-
databasesDir?: string;
|
|
221
|
+
databasesDir?: string | DatabaseSource[];
|
|
215
222
|
migrationsDir?: string;
|
|
216
223
|
verbose?: boolean;
|
|
217
224
|
}
|
|
@@ -256,7 +263,7 @@ declare function formatStatus(result: StatusResult): string;
|
|
|
256
263
|
//#region src/cli/validate.d.ts
|
|
257
264
|
interface ValidateContext {
|
|
258
265
|
projectRoot?: string;
|
|
259
|
-
databasesDir?: string;
|
|
266
|
+
databasesDir?: string | DatabaseSource[];
|
|
260
267
|
migrationsDir?: string;
|
|
261
268
|
verbose?: boolean;
|
|
262
269
|
/** Skip dev migrations, only validate prod */
|
|
@@ -295,7 +302,8 @@ declare function validate(ctx?: ValidateContext): Promise<ValidateResult[]>;
|
|
|
295
302
|
declare function reportCliError(error: unknown, verbose?: boolean): void;
|
|
296
303
|
interface DiscoverOptions {
|
|
297
304
|
projectRoot: string;
|
|
298
|
-
|
|
305
|
+
/** A directory, or several with name prefixes — see DiscoveryOptions. */
|
|
306
|
+
databasesDir: string | DatabaseSource[];
|
|
299
307
|
migrationsDir: string;
|
|
300
308
|
/** Only return databases matching this name */
|
|
301
309
|
database?: string;
|
|
@@ -332,4 +340,4 @@ declare function loadSchema(db: DatabaseInfo, projectRoot?: string): Promise<Rec
|
|
|
332
340
|
*/
|
|
333
341
|
declare function diffSchema(schema: Record<string, unknown>, migrationsDir: string): Promise<DiffResult>;
|
|
334
342
|
//#endregion
|
|
335
|
-
export { type DatabaseDevState, type DatabaseStatus, type DevPaths, type DevState, type DiffResult, type DiscoverOptions, type GenerateContext, type GenerateOptions, type GenerateResult, type PushContext, type PushResult, type ResetContext, type ResetOptions, type ResetResult, type StatusContext, type StatusResult, type ValidateContext, type ValidateError, type ValidateResult, createDbCommand, diffSchema, discoverDatabases, formatStatus, generate, generateEpoch, generateOne, getDevEpoch, getDevPaths, getInstanceKey, loadDevMigrations, loadDevState, loadSchema, push, pushOne, registerDbCommands, reportCliError, reset, resetAndPush, saveDevState, status, validate };
|
|
343
|
+
export { type DatabaseDevState, type DatabaseSource, type DatabaseStatus, type DbCommandDefaults, type DevPaths, type DevState, type DiffResult, type DiscoverOptions, type GenerateContext, type GenerateOptions, type GenerateResult, type PushContext, type PushResult, type ResetContext, type ResetOptions, type ResetResult, type StatusContext, type StatusResult, type ValidateContext, type ValidateError, type ValidateResult, createDbCommand, diffSchema, discoverDatabases, formatStatus, generate, generateEpoch, generateOne, getDevEpoch, getDevPaths, getInstanceKey, loadDevMigrations, loadDevState, loadSchema, push, pushOne, registerDbCommands, reportCliError, reset, resetAndPush, saveDevState, status, validate };
|
package/dist/cli/index.js
CHANGED
|
@@ -2,8 +2,8 @@ import "../debug-DmBrUmwe.js";
|
|
|
2
2
|
import { _ as saveDevState, a as generateEpoch, c as getDevPaths, f as loadDevMigrations, l as getInstanceKey, m as loadDevState, s as getDevEpoch } from "../state-DtZ70cBR.js";
|
|
3
3
|
import "../snapshot-DMW6j2Ix.js";
|
|
4
4
|
import "../generator-KHBZaOI1.js";
|
|
5
|
-
import "../parser-
|
|
6
|
-
import { a as loadSchema, i as discoverDatabases, n as pushOne, o as reportCliError, r as diffSchema, t as push } from "../push-
|
|
7
|
-
import { a as resetAndPush, c as generate, i as reset, l as generateOne, n as registerDbCommands, o as formatStatus, r as validate, s as status, t as createDbCommand } from "../cli-
|
|
5
|
+
import "../parser-BdV7Zqcv.js";
|
|
6
|
+
import { a as loadSchema, i as discoverDatabases, n as pushOne, o as reportCliError, r as diffSchema, t as push } from "../push-BhrMZaQx.js";
|
|
7
|
+
import { a as resetAndPush, c as generate, i as reset, l as generateOne, n as registerDbCommands, o as formatStatus, r as validate, s as status, t as createDbCommand } from "../cli-DnsOTcrH.js";
|
|
8
8
|
|
|
9
9
|
export { createDbCommand, diffSchema, discoverDatabases, formatStatus, generate, generateEpoch, generateOne, getDevEpoch, getDevPaths, getInstanceKey, loadDevMigrations, loadDevState, loadSchema, push, pushOne, registerDbCommands, reportCliError, reset, resetAndPush, saveDevState, status, validate };
|
|
@@ -2,8 +2,8 @@ import { i as init_debug, t as debugCli } from "./debug-DmBrUmwe.js";
|
|
|
2
2
|
import { _ as saveDevState, a as generateEpoch, c as getDevPaths, d as init_state, f as loadDevMigrations, m as loadDevState, t as clearDatabaseDevState } from "./state-DtZ70cBR.js";
|
|
3
3
|
import { a as hashSnapshot } from "./snapshot-DMW6j2Ix.js";
|
|
4
4
|
import { a as loadMigrationFiles, i as generateMigrationName, l as saveSnapshot, n as generateCreateTableSQL, s as loadSnapshot, t as buildAndLoadSchema } from "./generator-KHBZaOI1.js";
|
|
5
|
-
import {
|
|
6
|
-
import { a as loadSchema, i as discoverDatabases, o as reportCliError, r as diffSchema, t as push } from "./push-
|
|
5
|
+
import { c as loadViteAliases, s as resolveImportPath } from "./parser-BdV7Zqcv.js";
|
|
6
|
+
import { a as loadSchema, i as discoverDatabases, o as reportCliError, r as diffSchema, t as push } from "./push-BhrMZaQx.js";
|
|
7
7
|
import * as fs from "node:fs";
|
|
8
8
|
import * as path$1 from "node:path";
|
|
9
9
|
import { Command } from "commander";
|
|
@@ -322,7 +322,7 @@ async function reset(ctx = {}, options = {}) {
|
|
|
322
322
|
* Convenience function that combines reset + push
|
|
323
323
|
*/
|
|
324
324
|
async function resetAndPush(ctx = {}, options = {}) {
|
|
325
|
-
const { push: push$1 } = await import("./push-
|
|
325
|
+
const { push: push$1 } = await import("./push-cUJBpv5y.js");
|
|
326
326
|
return {
|
|
327
327
|
reset: await reset(ctx, options),
|
|
328
328
|
push: await push$1(ctx)
|
|
@@ -564,25 +564,15 @@ async function validateDatabase(db, opts) {
|
|
|
564
564
|
|
|
565
565
|
//#endregion
|
|
566
566
|
//#region src/cli/command.ts
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
*
|
|
574
|
-
* registerDbCommands(program); // → `mycli push`
|
|
575
|
-
*
|
|
576
|
-
* Or use {@link createDbCommand} to mount them as a `db` group:
|
|
577
|
-
*
|
|
578
|
-
* program.addCommand(createDbCommand()); // → `mycli db push`
|
|
579
|
-
*/
|
|
580
|
-
function registerDbCommands(program) {
|
|
581
|
-
program.command("push").description("Push schema changes to dev migrations").option("-d, --databases-dir <dir>", "Directory containing databases", "src/databases").option("-m, --migrations-dir <dir>", "Directory for production migrations", "migrations").option("-v, --verbose", "Verbose output").action(async (options) => {
|
|
567
|
+
function registerDbCommands(program, defaults = {}) {
|
|
568
|
+
const dirs = (options) => ({
|
|
569
|
+
databasesDir: options.databasesDir ?? defaults.databasesDir ?? "src/databases",
|
|
570
|
+
migrationsDir: options.migrationsDir ?? defaults.migrationsDir ?? "migrations"
|
|
571
|
+
});
|
|
572
|
+
program.command("push").description("Push schema changes to dev migrations").option("-d, --databases-dir <dir>", "Directory containing databases (default: src/databases)").option("-m, --migrations-dir <dir>", "Directory for production migrations (default: migrations)").option("-v, --verbose", "Verbose output").action(async (options) => {
|
|
582
573
|
try {
|
|
583
574
|
const results = await push({
|
|
584
|
-
|
|
585
|
-
migrationsDir: options.migrationsDir,
|
|
575
|
+
...dirs(options),
|
|
586
576
|
verbose: options.verbose
|
|
587
577
|
});
|
|
588
578
|
if (results.length === 0) {
|
|
@@ -600,11 +590,10 @@ function registerDbCommands(program) {
|
|
|
600
590
|
process.exit(1);
|
|
601
591
|
}
|
|
602
592
|
});
|
|
603
|
-
program.command("generate [name]").description("Generate production migration from schema changes").option("--database <db>", "Only generate for this database").option("-d, --databases-dir <dir>", "Directory containing databases
|
|
593
|
+
program.command("generate [name]").description("Generate production migration from schema changes").option("--database <db>", "Only generate for this database").option("-d, --databases-dir <dir>", "Directory containing databases (default: src/databases)").option("-m, --migrations-dir <dir>", "Directory for production migrations (default: migrations)").option("-v, --verbose", "Verbose output").action(async (name, options) => {
|
|
604
594
|
try {
|
|
605
595
|
const results = await generate({
|
|
606
|
-
|
|
607
|
-
migrationsDir: options.migrationsDir,
|
|
596
|
+
...dirs(options),
|
|
608
597
|
verbose: options.verbose
|
|
609
598
|
}, {
|
|
610
599
|
name,
|
|
@@ -627,11 +616,10 @@ function registerDbCommands(program) {
|
|
|
627
616
|
process.exit(1);
|
|
628
617
|
}
|
|
629
618
|
});
|
|
630
|
-
program.command("status").description("Show database migration status").option("-d, --databases-dir <dir>", "Directory containing databases
|
|
619
|
+
program.command("status").description("Show database migration status").option("-d, --databases-dir <dir>", "Directory containing databases (default: src/databases)").option("-m, --migrations-dir <dir>", "Directory for production migrations (default: migrations)").option("-v, --verbose", "Verbose output").action(async (options) => {
|
|
631
620
|
try {
|
|
632
621
|
const result = await status({
|
|
633
|
-
|
|
634
|
-
migrationsDir: options.migrationsDir,
|
|
622
|
+
...dirs(options),
|
|
635
623
|
verbose: options.verbose
|
|
636
624
|
});
|
|
637
625
|
console.log(formatStatus(result));
|
|
@@ -640,10 +628,10 @@ function registerDbCommands(program) {
|
|
|
640
628
|
process.exit(1);
|
|
641
629
|
}
|
|
642
630
|
});
|
|
643
|
-
program.command("reset").description("Reset dev state and create fresh DB instances (via epoch bump)").option("--keep-epoch", "Only clear dev migrations, keep the same epoch").option("--purge-local-storage", "Also delete workerd's persisted DO storage under .wrangler/ (requires the dev server to be stopped)").option("--database <db>", "Only reset this database").option("-d, --databases-dir <dir>", "Directory containing databases
|
|
631
|
+
program.command("reset").description("Reset dev state and create fresh DB instances (via epoch bump)").option("--keep-epoch", "Only clear dev migrations, keep the same epoch").option("--purge-local-storage", "Also delete workerd's persisted DO storage under .wrangler/ (requires the dev server to be stopped)").option("--database <db>", "Only reset this database").option("-d, --databases-dir <dir>", "Directory containing databases (default: src/databases)").option("-m, --migrations-dir <dir>", "Directory for production migrations (default: migrations)").option("-v, --verbose", "Verbose output").action(async (options) => {
|
|
644
632
|
try {
|
|
645
633
|
const result = await reset({
|
|
646
|
-
databasesDir: options.databasesDir,
|
|
634
|
+
databasesDir: dirs(options).databasesDir,
|
|
647
635
|
verbose: options.verbose
|
|
648
636
|
}, {
|
|
649
637
|
keepEpoch: options.keepEpoch,
|
|
@@ -663,11 +651,10 @@ function registerDbCommands(program) {
|
|
|
663
651
|
process.exit(1);
|
|
664
652
|
}
|
|
665
653
|
});
|
|
666
|
-
program.command("validate").description("Dry-run migrations against local SQLite to catch errors before deployment").option("--database <db>", "Only validate this database").option("--no-dev", "Skip dev migrations, only validate production").option("-d, --databases-dir <dir>", "Directory containing databases
|
|
654
|
+
program.command("validate").description("Dry-run migrations against local SQLite to catch errors before deployment").option("--database <db>", "Only validate this database").option("--no-dev", "Skip dev migrations, only validate production").option("-d, --databases-dir <dir>", "Directory containing databases (default: src/databases)").option("-m, --migrations-dir <dir>", "Directory for production migrations (default: migrations)").option("-v, --verbose", "Show each migration as it is applied").action(async (options) => {
|
|
667
655
|
try {
|
|
668
656
|
const results = await validate({
|
|
669
|
-
|
|
670
|
-
migrationsDir: options.migrationsDir,
|
|
657
|
+
...dirs(options),
|
|
671
658
|
verbose: options.verbose,
|
|
672
659
|
noDev: !options.dev,
|
|
673
660
|
database: options.database
|
|
@@ -708,8 +695,8 @@ function registerDbCommands(program) {
|
|
|
708
695
|
* `program.addCommand(createDbCommand())` so the commands live under a
|
|
709
696
|
* `db` prefix (e.g. `mycli db push`).
|
|
710
697
|
*/
|
|
711
|
-
function createDbCommand() {
|
|
712
|
-
return registerDbCommands(new Command("db").description("Database migration management"));
|
|
698
|
+
function createDbCommand(defaults = {}) {
|
|
699
|
+
return registerDbCommands(new Command("db").description("Database migration management"), defaults);
|
|
713
700
|
}
|
|
714
701
|
|
|
715
702
|
//#endregion
|
package/dist/context/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as setTenantIdResolver, i as hasTenantId, n as getInstanceKey, r as getTenantId, t as getDevInstanceKeySuffix } from "../index-
|
|
1
|
+
import { a as setTenantIdResolver, i as hasTenantId, n as getInstanceKey, r as getTenantId, t as getDevInstanceKeySuffix } from "../index-zzQS_psa.js";
|
|
2
2
|
export { getDevInstanceKeySuffix, getInstanceKey, getTenantId, hasTenantId, setTenantIdResolver };
|
package/dist/db/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as type } from "../arktypeConfig
|
|
2
|
-
import { a as ActionInfo, c as DatabaseDefinition, d as InferArgs, f as ParsedDatabaseFile, i as ActionContext, l as DatabaseInfo, n as Action, o as ArgsSchema, r as ActionConfig, s as DatabaseConfig, t as defineDatabase, u as DrizzleToKysely } from "../defineDatabase-
|
|
3
|
-
import { _ as CreateKyselyOptions, a as QueryResult, c as DrizzleDefaultsPlugin, d as dateSerializers, f as Migration, g as SqliteDurableObject, h as Migrations, i as KyselyPlugin, l as SchemaPlugin, m as MigrationSchemaConflictError, n as CompiledQuery, o as studio, p as MigrationAttemptInfo, r as Kysely, s as DateSerializePlugin, t as CamelCasePlugin, u as createDrizzlePlugins, v as SqlExecutor, y as createKyselyFromSql } from "../index-
|
|
1
|
+
import { t as type } from "../arktypeConfig-zgI5p6zF.js";
|
|
2
|
+
import { a as ActionInfo, c as DatabaseDefinition, d as InferArgs, f as ParsedDatabaseFile, i as ActionContext, l as DatabaseInfo, n as Action, o as ArgsSchema, r as ActionConfig, s as DatabaseConfig, t as defineDatabase, u as DrizzleToKysely } from "../defineDatabase-DtkM6k1S.js";
|
|
3
|
+
import { _ as CreateKyselyOptions, a as QueryResult, c as DrizzleDefaultsPlugin, d as dateSerializers, f as Migration, g as SqliteDurableObject, h as Migrations, i as KyselyPlugin, l as SchemaPlugin, m as MigrationSchemaConflictError, n as CompiledQuery, o as studio, p as MigrationAttemptInfo, r as Kysely, s as DateSerializePlugin, t as CamelCasePlugin, u as createDrizzlePlugins, v as SqlExecutor, y as createKyselyFromSql } from "../index-BHLOQ7uV.js";
|
|
4
4
|
export { Action, ActionConfig, ActionContext, ActionInfo, ArgsSchema, CamelCasePlugin, CompiledQuery, CreateKyselyOptions, DatabaseConfig, DatabaseDefinition, DatabaseInfo, DateSerializePlugin, DrizzleDefaultsPlugin, DrizzleToKysely, InferArgs, Kysely, KyselyPlugin, Migration, MigrationAttemptInfo, MigrationSchemaConflictError, Migrations, ParsedDatabaseFile, QueryResult, SchemaPlugin, SqlExecutor, SqliteDurableObject, createDrizzlePlugins, createKyselyFromSql, dateSerializers, defineDatabase, studio, type };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region src/vite/modules/discovery.d.ts
|
|
2
|
+
|
|
3
|
+
/** One place database definitions are discovered from. */
|
|
4
|
+
interface DatabaseSource {
|
|
5
|
+
/** Directory, relative to the project root or absolute. */
|
|
6
|
+
dir: string;
|
|
7
|
+
/** Prepended to every database name found here (`<prefix>-<file>`). */
|
|
8
|
+
prefix?: string;
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
11
|
+
export { DatabaseSource as t };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { t as type } from "./arktypeConfig
|
|
2
|
-
import { c as DatabaseDefinition, d as InferArgs, i as ActionContext, n as Action, r as ActionConfig, s as DatabaseConfig, t as defineDatabase, u as DrizzleToKysely } from "./defineDatabase-
|
|
3
|
-
import { a as setTenantIdResolver, i as hasTenantId, r as getTenantId } from "./index-
|
|
4
|
-
import { a as integer, c as real, d as uniqueIndex, i as index, l as table, n as blob, o as numeric, r as foreignKey, s as primaryKey, t as AnySQLiteColumn, u as text } from "./schema-
|
|
1
|
+
import { t as type } from "./arktypeConfig-zgI5p6zF.js";
|
|
2
|
+
import { c as DatabaseDefinition, d as InferArgs, i as ActionContext, n as Action, r as ActionConfig, s as DatabaseConfig, t as defineDatabase, u as DrizzleToKysely } from "./defineDatabase-DtkM6k1S.js";
|
|
3
|
+
import { a as setTenantIdResolver, i as hasTenantId, r as getTenantId } from "./index-zzQS_psa.js";
|
|
4
|
+
import { a as integer, c as real, d as uniqueIndex, i as index, l as table, n as blob, o as numeric, r as foreignKey, s as primaryKey, t as AnySQLiteColumn, u as text } from "./schema-C2yy5KCT.js";
|
|
5
5
|
import { Kysely } from "kysely";
|
|
6
6
|
export { type Action, type ActionConfig, type ActionContext, type AnySQLiteColumn, type DatabaseConfig, type DatabaseDefinition, type DrizzleToKysely, type InferArgs, type Kysely, blob, defineDatabase, foreignKey, getTenantId, hasTenantId, index, integer, numeric, primaryKey, real, setTenantIdResolver, table, text, type, uniqueIndex };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as generateSnapshotId, i as generateSnapshotFromSchema, n as createEmptySnapshot, o as hashSnapshot, r as generateMigrationStatements, s as snapshotsEqual, t as Snapshot } from "../snapshot-
|
|
1
|
+
import { a as generateSnapshotId, i as generateSnapshotFromSchema, n as createEmptySnapshot, o as hashSnapshot, r as generateMigrationStatements, s as snapshotsEqual, t as Snapshot } from "../snapshot-DsSRYFe-.js";
|
|
2
2
|
export { Snapshot, createEmptySnapshot, generateMigrationStatements, generateSnapshotFromSchema, generateSnapshotId, hashSnapshot, snapshotsEqual };
|
|
@@ -117,6 +117,15 @@ async function loadViteAliases(root) {
|
|
|
117
117
|
|
|
118
118
|
//#endregion
|
|
119
119
|
//#region src/vite/modules/discovery.ts
|
|
120
|
+
/** The sources a `databasesDir` option names. */
|
|
121
|
+
function databaseSources(databasesDir) {
|
|
122
|
+
return typeof databasesDir === "string" ? [{ dir: databasesDir }] : databasesDir;
|
|
123
|
+
}
|
|
124
|
+
/** The name a database file gets: its basename, prefixed when its source has a prefix. */
|
|
125
|
+
function databaseName(file, prefix) {
|
|
126
|
+
const base = path$1.basename(file).replace(/\.(ts|js)$/, "");
|
|
127
|
+
return prefix ? `${prefix}-${base}` : base;
|
|
128
|
+
}
|
|
120
129
|
/**
|
|
121
130
|
* Tracks directories we've already warned about to avoid duplicate noise
|
|
122
131
|
* on repeated discovery calls (e.g. Vite HMR, multiple plugin hooks).
|
|
@@ -132,52 +141,34 @@ const warnedMissingDirs = /* @__PURE__ */ new Set();
|
|
|
132
141
|
*/
|
|
133
142
|
function discoverDatabaseFiles(options) {
|
|
134
143
|
const { projectRoot, databasesDir } = options;
|
|
135
|
-
const absoluteDir = path$1.join(projectRoot, databasesDir);
|
|
136
|
-
if (!fs.existsSync(absoluteDir)) {
|
|
137
|
-
if (!warnedMissingDirs.has(absoluteDir)) {
|
|
138
|
-
warnedMissingDirs.add(absoluteDir);
|
|
139
|
-
console.warn(`[durable-db] Databases directory not found: ${absoluteDir}. No databases will be generated. Set the 'databasesDir' plugin option if your databases live elsewhere (current: '${databasesDir}').`);
|
|
140
|
-
}
|
|
141
|
-
return [];
|
|
142
|
-
}
|
|
143
|
-
const files = fs.readdirSync(absoluteDir);
|
|
144
144
|
const results = [];
|
|
145
|
-
for (const
|
|
146
|
-
|
|
147
|
-
if (
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
145
|
+
for (const source of databaseSources(databasesDir)) {
|
|
146
|
+
const absoluteDir = path$1.resolve(projectRoot, source.dir);
|
|
147
|
+
if (!fs.existsSync(absoluteDir)) {
|
|
148
|
+
if (typeof databasesDir === "string" && !warnedMissingDirs.has(absoluteDir)) {
|
|
149
|
+
warnedMissingDirs.add(absoluteDir);
|
|
150
|
+
console.warn(`[durable-db] Databases directory not found: ${absoluteDir}. No databases will be generated. Set the 'databasesDir' plugin option if your databases live elsewhere (current: '${databasesDir}').`);
|
|
151
|
+
}
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
for (const file of fs.readdirSync(absoluteDir)) {
|
|
155
|
+
if (!file.endsWith(".ts")) continue;
|
|
156
|
+
if (file.endsWith(".d.ts")) continue;
|
|
157
|
+
if (file === "schema.ts") continue;
|
|
158
|
+
if (file.startsWith("_")) continue;
|
|
159
|
+
const absolutePath = path$1.join(absoluteDir, file);
|
|
160
|
+
results.push({
|
|
161
|
+
absolutePath,
|
|
162
|
+
relativePath: path$1.relative(projectRoot, absolutePath),
|
|
163
|
+
name: databaseName(file, source.prefix),
|
|
164
|
+
prefix: source.prefix
|
|
165
|
+
});
|
|
166
|
+
}
|
|
158
167
|
}
|
|
159
168
|
return results;
|
|
160
169
|
}
|
|
161
|
-
/**
|
|
162
|
-
* Recursively find action-defining files under the databases directory.
|
|
163
|
-
*
|
|
164
|
-
* The generated Durable Object module side-effect-imports these so every
|
|
165
|
-
* `action()` runs its `registerAction(...)` at DO startup — populating the
|
|
166
|
-
* action registry in the DO's isolate. Without this the registry is only
|
|
167
|
-
* populated by whatever the request path imported, which works in dev (one
|
|
168
|
-
* shared isolate) and via in-app navigation, but a Durable Object is a separate
|
|
169
|
-
* persistent isolate in production: a freshly deep-linked route whose action the
|
|
170
|
-
* DO never loaded throws `Unknown action "X" (was it imported?)`.
|
|
171
|
-
*
|
|
172
|
-
* Returns absolute paths of `.ts`/`.tsx` files that call `action(` (the factory
|
|
173
|
-
* invocation), excluding tests, declarations, and `_`-prefixed helpers. Helper
|
|
174
|
-
* modules without their own actions are pulled in transitively by the action
|
|
175
|
-
* files that import them, so they don't need to be listed here.
|
|
176
|
-
*/
|
|
177
170
|
function discoverActionFiles(options) {
|
|
178
171
|
const { projectRoot, databasesDir } = options;
|
|
179
|
-
const absoluteDir = path$1.join(projectRoot, databasesDir);
|
|
180
|
-
if (!fs.existsSync(absoluteDir)) return [];
|
|
181
172
|
const results = [];
|
|
182
173
|
const walk = (dir) => {
|
|
183
174
|
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
@@ -194,7 +185,10 @@ function discoverActionFiles(options) {
|
|
|
194
185
|
} catch {}
|
|
195
186
|
}
|
|
196
187
|
};
|
|
197
|
-
|
|
188
|
+
for (const source of databaseSources(databasesDir)) {
|
|
189
|
+
const absoluteDir = path$1.resolve(projectRoot, source.dir);
|
|
190
|
+
if (fs.existsSync(absoluteDir)) walk(absoluteDir);
|
|
191
|
+
}
|
|
198
192
|
return results;
|
|
199
193
|
}
|
|
200
194
|
/**
|
|
@@ -294,7 +288,7 @@ function parseDatabaseFile(filePath, code, options = {}) {
|
|
|
294
288
|
const init = nodePath.node.init;
|
|
295
289
|
const id = nodePath.node.id;
|
|
296
290
|
if (isDefineDatabaseCall(init)) {
|
|
297
|
-
const dbInfo = extractDatabaseInfo(nodePath, init, filePath, result.localImports);
|
|
291
|
+
const dbInfo = extractDatabaseInfo(nodePath, init, filePath, result.localImports, options.namePrefix);
|
|
298
292
|
if (dbInfo) result.database = dbInfo;
|
|
299
293
|
if (t.isObjectPattern(id)) actionFnName = extractActionFactoryName(id);
|
|
300
294
|
}
|
|
@@ -343,7 +337,7 @@ function warnNonLiteral(filePath, key, defaultValue) {
|
|
|
343
337
|
/**
|
|
344
338
|
* Extract database configuration from a defineDatabase() call
|
|
345
339
|
*/
|
|
346
|
-
function extractDatabaseInfo(declaratorPath, callExpr, filePath, imports) {
|
|
340
|
+
function extractDatabaseInfo(declaratorPath, callExpr, filePath, imports, namePrefix) {
|
|
347
341
|
const configArg = callExpr.arguments[0];
|
|
348
342
|
if (!t.isObjectExpression(configArg)) return null;
|
|
349
343
|
let instance = "per-tenant";
|
|
@@ -376,7 +370,8 @@ function extractDatabaseInfo(declaratorPath, callExpr, filePath, imports) {
|
|
|
376
370
|
}
|
|
377
371
|
}
|
|
378
372
|
}
|
|
379
|
-
const
|
|
373
|
+
const base = path$1.basename(filePath).replace(/\.(ts|js)$/, "");
|
|
374
|
+
const name = namePrefix ? `${namePrefix}-${base}` : base;
|
|
380
375
|
return {
|
|
381
376
|
filePath,
|
|
382
377
|
name,
|
|
@@ -393,7 +388,7 @@ function extractDatabaseInfo(declaratorPath, callExpr, filePath, imports) {
|
|
|
393
388
|
/**
|
|
394
389
|
* Extract action information from an action() call
|
|
395
390
|
*/
|
|
396
|
-
function extractActionInfo(declaratorPath, callExpr, databaseName, filePath) {
|
|
391
|
+
function extractActionInfo(declaratorPath, callExpr, databaseName$1, filePath) {
|
|
397
392
|
const id = declaratorPath.node.id;
|
|
398
393
|
if (!t.isIdentifier(id)) return null;
|
|
399
394
|
const exportName = id.name;
|
|
@@ -411,7 +406,7 @@ function extractActionInfo(declaratorPath, callExpr, databaseName, filePath) {
|
|
|
411
406
|
exportName,
|
|
412
407
|
argsSchemaSource,
|
|
413
408
|
handlerSource,
|
|
414
|
-
databaseName,
|
|
409
|
+
databaseName: databaseName$1,
|
|
415
410
|
sourceFile: filePath
|
|
416
411
|
};
|
|
417
412
|
}
|
|
@@ -429,4 +424,4 @@ function toScreamingSnakeCase(str) {
|
|
|
429
424
|
}
|
|
430
425
|
|
|
431
426
|
//#endregion
|
|
432
|
-
export {
|
|
427
|
+
export { discoverDatabaseFiles as a, loadViteAliases as c, discoverActionFiles as i, parseDatabaseFile as n, readFile as o, databaseSources as r, resolveImportPath as s, BABEL_PARSER_PLUGINS as t };
|
|
@@ -2,7 +2,7 @@ import { i as init_debug, t as debugCli } from "./debug-DmBrUmwe.js";
|
|
|
2
2
|
import { d as init_state, f as loadDevMigrations, h as saveDevMigration, n as clearDevMigrations } from "./state-DtZ70cBR.js";
|
|
3
3
|
import { n as generateMigrationStatements, o as snapshotsEqual, r as generateSnapshotFromSchema } from "./snapshot-DMW6j2Ix.js";
|
|
4
4
|
import { s as loadSnapshot, t as buildAndLoadSchema } from "./generator-KHBZaOI1.js";
|
|
5
|
-
import { a as
|
|
5
|
+
import { a as discoverDatabaseFiles, c as loadViteAliases, n as parseDatabaseFile, o as readFile, s as resolveImportPath } from "./parser-BdV7Zqcv.js";
|
|
6
6
|
import * as path$1 from "node:path";
|
|
7
7
|
import * as crypto from "node:crypto";
|
|
8
8
|
|
|
@@ -35,7 +35,7 @@ function discoverDatabases(opts) {
|
|
|
35
35
|
const databases = [];
|
|
36
36
|
for (const file of files) {
|
|
37
37
|
const code = readFile(file.absolutePath);
|
|
38
|
-
const parsed = parseDatabaseFile(file.absolutePath, code);
|
|
38
|
+
const parsed = parseDatabaseFile(file.absolutePath, code, { namePrefix: file.prefix });
|
|
39
39
|
if (!parsed.database) continue;
|
|
40
40
|
if (database && parsed.database.name !== database) continue;
|
|
41
41
|
parsed.database.migrationsDir = path$1.resolve(projectRoot, migrationsDir, parsed.database.name);
|
|
@@ -2,7 +2,7 @@ import "./debug-DmBrUmwe.js";
|
|
|
2
2
|
import "./state-DtZ70cBR.js";
|
|
3
3
|
import "./snapshot-DMW6j2Ix.js";
|
|
4
4
|
import "./generator-KHBZaOI1.js";
|
|
5
|
-
import "./parser-
|
|
6
|
-
import { n as pushOne, t as push } from "./push-
|
|
5
|
+
import "./parser-BdV7Zqcv.js";
|
|
6
|
+
import { n as pushOne, t as push } from "./push-BhrMZaQx.js";
|
|
7
7
|
|
|
8
8
|
export { push };
|
package/dist/registry.d.ts
CHANGED
package/dist/schema.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as integer, c as real, d as uniqueIndex, i as index, l as table, n as blob, o as numeric, r as foreignKey, s as primaryKey, t as AnySQLiteColumn, u as text } from "./schema-
|
|
1
|
+
import { a as integer, c as real, d as uniqueIndex, i as index, l as table, n as blob, o as numeric, r as foreignKey, s as primaryKey, t as AnySQLiteColumn, u as text } from "./schema-C2yy5KCT.js";
|
|
2
2
|
export { AnySQLiteColumn, blob, foreignKey, index, integer, numeric, primaryKey, real, table, text, uniqueIndex };
|
package/dist/vite/durableDb.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { t as DatabaseSource } from "../discovery-DfimBbS_.js";
|
|
1
2
|
import { Plugin } from "vite";
|
|
2
3
|
|
|
3
4
|
//#region src/vite/durableDb.d.ts
|
|
@@ -7,7 +8,7 @@ interface DurableDbOptions {
|
|
|
7
8
|
/** Import path for the registry module. Default: 'durable-db/registry' */
|
|
8
9
|
registryImport?: string;
|
|
9
10
|
/** Directory containing database definitions. Default: 'src/databases' */
|
|
10
|
-
databasesDir?: string;
|
|
11
|
+
databasesDir?: string | DatabaseSource[];
|
|
11
12
|
/** Directory for production migrations, relative to project root. Default: 'migrations' */
|
|
12
13
|
migrationsDir?: string;
|
|
13
14
|
/**
|
|
@@ -24,4 +25,4 @@ declare const databasePlugin: typeof durableDb;
|
|
|
24
25
|
/** @deprecated Renamed to {@link DurableDbOptions}. */
|
|
25
26
|
type DatabasePluginOptions = DurableDbOptions;
|
|
26
27
|
//#endregion
|
|
27
|
-
export { DatabasePluginOptions, DurableDbOptions, databasePlugin, durableDb as default, durableDb };
|
|
28
|
+
export { DatabasePluginOptions, type DatabaseSource, DurableDbOptions, databasePlugin, durableDb as default, durableDb };
|
package/dist/vite/durableDb.js
CHANGED
|
@@ -2,7 +2,7 @@ import { i as init_debug, r as debugVite } from "../debug-DmBrUmwe.js";
|
|
|
2
2
|
import { _ as saveDevState, c as getDevPaths, d as init_state, m as loadDevState } from "../state-DtZ70cBR.js";
|
|
3
3
|
import "../snapshot-DMW6j2Ix.js";
|
|
4
4
|
import { a as loadMigrationFiles } from "../generator-KHBZaOI1.js";
|
|
5
|
-
import { a as
|
|
5
|
+
import { a as discoverDatabaseFiles, i as discoverActionFiles, n as parseDatabaseFile, o as readFile, r as databaseSources, t as BABEL_PARSER_PLUGINS } from "../parser-BdV7Zqcv.js";
|
|
6
6
|
import * as fs from "node:fs";
|
|
7
7
|
import * as path$1 from "node:path";
|
|
8
8
|
import path from "node:path";
|
|
@@ -874,7 +874,10 @@ var PluginState = class {
|
|
|
874
874
|
});
|
|
875
875
|
for (const file of files) {
|
|
876
876
|
const code = readFile(file.absolutePath);
|
|
877
|
-
const parsed = parseDatabaseFile(file.absolutePath, code, {
|
|
877
|
+
const parsed = parseDatabaseFile(file.absolutePath, code, {
|
|
878
|
+
aliases: this.aliases,
|
|
879
|
+
namePrefix: file.prefix
|
|
880
|
+
});
|
|
878
881
|
if (parsed.database) {
|
|
879
882
|
parsed.database.migrationsDir = path$1.resolve(this.projectRoot, this.options.migrationsDir, parsed.database.name);
|
|
880
883
|
this.databases.set(parsed.database.name, parsed.database);
|
|
@@ -974,10 +977,10 @@ function durableDb(options = {}) {
|
|
|
974
977
|
configureServer(server) {
|
|
975
978
|
state.devServer = server;
|
|
976
979
|
state.reset();
|
|
977
|
-
const
|
|
980
|
+
const absoluteDbDirs = databaseSources(state.options.databasesDir).map((source) => path$1.resolve(state.projectRoot, source.dir));
|
|
978
981
|
server.watcher.on("change", (file) => {
|
|
979
982
|
const normalized = path$1.normalize(file);
|
|
980
|
-
if (normalized.startsWith(
|
|
983
|
+
if (absoluteDbDirs.some((dir) => normalized.startsWith(dir)) && /\.tsx?$/.test(normalized)) state.invalidateDOModule();
|
|
981
984
|
});
|
|
982
985
|
const devPaths = getDevPaths(state.projectRoot);
|
|
983
986
|
fs.mkdirSync(devPaths.cacheDir, { recursive: true });
|
package/package.json
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|