durable-db 0.14.1 → 0.15.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/README.md +41 -6
- package/dist/{actionArgs-oUWwX6Xn.js → actionArgs-BAmU_AIB.js} +1 -1
- package/dist/cli/bin.js +1 -1
- package/dist/cli/index.d.ts +2 -2
- package/dist/cli/index.js +3 -3
- package/dist/{cli-fxJ78Qvs.js → cli-B7-DcYWu.js} +3 -3
- package/dist/context/index.js +2 -2
- package/dist/db/index.d.ts +2 -2
- package/dist/db/index.js +52 -23
- package/dist/{debug-BFOTDUja.js → debug-Di50ua4a.js} +14 -2
- package/dist/{defineDatabase-Dj5DOPUM.d.ts → defineDatabase-Cc3LtKhn.d.ts} +12 -0
- package/dist/{defineDatabase-_AusJf3r.js → defineDatabase-xd-9vnhm.js} +8 -4
- package/dist/{index-B1J4Kjum.d.ts → index-oTr2B0ap.d.ts} +22 -11
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -3
- package/dist/{kysely-C675L1b9.js → kysely-BUmrdN9f.js} +12 -25
- package/dist/migrations/generator.js +2 -2
- package/dist/{parser-DRqnF9bz.js → parser-Bta8BJHy.js} +26 -7
- package/dist/registry.d.ts +45 -11
- package/dist/registry.js +54 -20
- package/dist/schema.d.ts +10 -1
- package/dist/schema.js +9 -1
- package/dist/{state-Bcux4tX1.js → state-k7CdHsWf.js} +1 -1
- package/dist/testing/index.d.ts +6 -0
- package/dist/testing/index.js +97 -17
- package/dist/type/index.js +1 -1
- package/dist/{type-pAQ37iEL.js → type-C7apBBQw.js} +83 -6
- package/dist/vite/durableDb.d.ts +1 -1
- package/dist/vite/durableDb.js +157 -96
- package/package.json +3 -2
package/dist/vite/durableDb.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { i as init_debug, r as debugVite } from "../debug-
|
|
2
|
-
import { b as writeDevServerLock, c as getDatabaseEpochs, f as init_state, h as removeDevServerLock, m as loadDevState, u as getDevPaths, v as saveDevState } from "../state-
|
|
1
|
+
import { i as init_debug, r as debugVite } from "../debug-Di50ua4a.js";
|
|
2
|
+
import { b as writeDevServerLock, c as getDatabaseEpochs, f as init_state, h as removeDevServerLock, m as loadDevState, u as getDevPaths, v as saveDevState } from "../state-k7CdHsWf.js";
|
|
3
3
|
import { loadMigrationFiles } from "../migrations/generator.js";
|
|
4
|
-
import { a as databaseSources, c as readFile, i as toPascalCase, n as declaresSchema, o as discoverActionFiles, r as parseDatabaseFile, s as discoverDatabaseFiles, t as BABEL_PARSER_PLUGINS } from "../parser-
|
|
4
|
+
import { a as databaseSources, c as readFile, i as toPascalCase, n as declaresSchema, o as discoverActionFiles, r as parseDatabaseFile, s as discoverDatabaseFiles, t as BABEL_PARSER_PLUGINS } from "../parser-Bta8BJHy.js";
|
|
5
5
|
import * as fs from "node:fs";
|
|
6
6
|
import path, * as path$1 from "node:path";
|
|
7
|
-
import { parse } from "
|
|
8
|
-
import _generate from "@babel/generator";
|
|
7
|
+
import { findNodeAtLocation, parse, parseTree, printParseErrorCode } from "jsonc-parser";
|
|
9
8
|
import * as t from "@babel/types";
|
|
10
|
-
import
|
|
9
|
+
import _generate from "@babel/generator";
|
|
10
|
+
import { parse as parse$1 } from "@babel/parser";
|
|
11
11
|
//#region src/vite/modules/wrangler.ts
|
|
12
12
|
init_debug();
|
|
13
13
|
/**
|
|
@@ -26,7 +26,7 @@ function findWranglerConfig(projectRoot) {
|
|
|
26
26
|
*/
|
|
27
27
|
function parseWranglerConfig(content) {
|
|
28
28
|
const errors = [];
|
|
29
|
-
const config = parse
|
|
29
|
+
const config = parse(content, errors, {
|
|
30
30
|
allowTrailingComma: true,
|
|
31
31
|
disallowComments: false
|
|
32
32
|
});
|
|
@@ -680,18 +680,17 @@ const generate = typeof _generate === "function" ? _generate : _generate.default
|
|
|
680
680
|
*/
|
|
681
681
|
const DEV_EPOCH_IMPORT = "virtual:durable-db/__devEpoch";
|
|
682
682
|
const ARKTYPE_LOCAL = "__ddType";
|
|
683
|
-
/** The registry's
|
|
684
|
-
const SCHEMA_LOCAL = "__ddSchema";
|
|
683
|
+
/** The registry's batchedRpc, imported under an alias that never collides with the app's own names. */
|
|
685
684
|
const RPC_LOCAL = "__ddRpc";
|
|
686
685
|
function parseProgram(code) {
|
|
687
|
-
return parse(code, {
|
|
686
|
+
return parse$1(code, {
|
|
688
687
|
sourceType: "module",
|
|
689
688
|
plugins: BABEL_PARSER_PLUGINS
|
|
690
689
|
});
|
|
691
690
|
}
|
|
692
691
|
function parseExpression(code) {
|
|
693
692
|
const wrapped = `(${code.trim().replace(/;\s*$/, "")})`;
|
|
694
|
-
const stmt = parse(wrapped, {
|
|
693
|
+
const stmt = parse$1(wrapped, {
|
|
695
694
|
sourceType: "module",
|
|
696
695
|
plugins: BABEL_PARSER_PLUGINS
|
|
697
696
|
}).program.body[0];
|
|
@@ -979,11 +978,12 @@ function buildDoContextTenantProperty() {
|
|
|
979
978
|
return t.objectProperty(t.identifier("tenantId"), t.callExpression(t.memberExpression(t.thisExpression(), t.identifier("tenantOf")), [t.memberExpression(t.identifier("ctx"), t.identifier("instanceKey"))]));
|
|
980
979
|
}
|
|
981
980
|
/**
|
|
982
|
-
* `this.
|
|
983
|
-
* the handler with `ctx.outbox
|
|
981
|
+
* `this.runAction(ctx, async () => entry.handler(this.db, validated, ctx))`:
|
|
982
|
+
* the handler as one transaction, with `ctx.outbox` and `ctx.transaction` —
|
|
983
|
+
* its writes and its messages committed together when it resolves.
|
|
984
984
|
*/
|
|
985
985
|
function buildOutboxHandlerCall() {
|
|
986
|
-
return t.callExpression(t.memberExpression(t.thisExpression(), t.identifier("
|
|
986
|
+
return t.callExpression(t.memberExpression(t.thisExpression(), t.identifier("runAction")), [t.identifier("ctx"), t.arrowFunctionExpression([], t.callExpression(t.memberExpression(t.identifier("entry"), t.identifier("handler")), [
|
|
987
987
|
t.memberExpression(t.thisExpression(), t.identifier("db")),
|
|
988
988
|
t.identifier("validated"),
|
|
989
989
|
t.identifier("ctx")
|
|
@@ -1022,7 +1022,8 @@ function buildRpcMethod(db, bindingNamesExpr, dbTransportsExpr) {
|
|
|
1022
1022
|
t.objectProperty(t.identifier("ctx"), t.identifier("ctx")),
|
|
1023
1023
|
t.objectProperty(t.identifier("dbName"), dbNameLiteral),
|
|
1024
1024
|
t.objectProperty(t.identifier("instanceKey"), t.memberExpression(t.identifier("ctx"), t.identifier("instanceKey"))),
|
|
1025
|
-
buildDoContextTenantProperty()
|
|
1025
|
+
buildDoContextTenantProperty(),
|
|
1026
|
+
t.objectProperty(t.identifier("via"), t.optionalMemberExpression(t.identifier("rpcContext"), t.identifier("via"), false, true))
|
|
1026
1027
|
]), t.arrowFunctionExpression([], buildOutboxHandlerCall(), true)]))
|
|
1027
1028
|
]);
|
|
1028
1029
|
return t.classMethod("method", t.identifier("rpc"), [
|
|
@@ -1120,12 +1121,32 @@ function buildInstanceKeyExpr(database) {
|
|
|
1120
1121
|
const baseKeyExpr = database.instance === "global" ? t.stringLiteral("global") : t.callExpression(t.identifier("getTenantId"), []);
|
|
1121
1122
|
return t.callExpression(t.identifier("applyDevEpoch"), [baseKeyExpr, t.stringLiteral(database.name)]);
|
|
1122
1123
|
}
|
|
1124
|
+
/** The function that answers an action's compiled args schema (`__validator_X`). */
|
|
1125
|
+
function validatorIdOf(exportName) {
|
|
1126
|
+
return t.identifier(`__validator_${exportName}`);
|
|
1127
|
+
}
|
|
1128
|
+
/**
|
|
1129
|
+
* `var __args_X; function __validator_X() { return __args_X || (__args_X = __ddType(<args>)); }`:
|
|
1130
|
+
* the action's args schema, compiled at its first use and kept for the
|
|
1131
|
+
* module's life — one per isolate, for the call site, the Durable Object's
|
|
1132
|
+
* validator and `describeAction()` alike. Every isolate evaluates every
|
|
1133
|
+
* action file as it starts (a Durable Object imports them all), and an
|
|
1134
|
+
* action's schema compiled there, and again at its call site's first call,
|
|
1135
|
+
* was paid for every action, called or not. Kept by the module, not by name
|
|
1136
|
+
* in the registry: an action file that dev evaluates again after an edit
|
|
1137
|
+
* compiles its new args. `var`, so a call before the module body reaches it
|
|
1138
|
+
* finds it unset instead of in its temporal dead zone.
|
|
1139
|
+
*/
|
|
1140
|
+
function buildArgsSchemaStatements(action) {
|
|
1141
|
+
const cached = t.identifier(`__args_${action.exportName}`);
|
|
1142
|
+
return [t.variableDeclaration("var", [t.variableDeclarator(cached)]), t.functionDeclaration(validatorIdOf(action.exportName), [], t.blockStatement([t.returnStatement(t.logicalExpression("||", cached, t.assignmentExpression("=", cached, t.callExpression(t.identifier(ARKTYPE_LOCAL), [parseExpression(action.argsSchemaSource)]))))]))];
|
|
1143
|
+
}
|
|
1123
1144
|
function buildStubBodyStatements(config) {
|
|
1124
1145
|
const { action, database } = config;
|
|
1125
1146
|
const bindingExpr = t.memberExpression(t.identifier("env"), t.identifier(database.bindingName));
|
|
1126
1147
|
const instanceKeyExpr = buildInstanceKeyExpr(database);
|
|
1127
1148
|
const commonStatements = [
|
|
1128
|
-
t.variableDeclaration("const", [t.variableDeclarator(t.identifier("argsSchema"), t.callExpression(
|
|
1149
|
+
t.variableDeclaration("const", [t.variableDeclarator(t.identifier("argsSchema"), t.callExpression(validatorIdOf(action.exportName), []))]),
|
|
1129
1150
|
t.variableDeclaration("const", [t.variableDeclarator(t.identifier("validatedArgs"), t.callExpression(t.memberExpression(t.identifier("argsSchema"), t.identifier("assert")), [t.identifier("args")]))]),
|
|
1130
1151
|
...buildDoShortPath(config),
|
|
1131
1152
|
t.variableDeclaration("const", [t.variableDeclarator(t.identifier("instanceKey"), instanceKeyExpr)])
|
|
@@ -1145,7 +1166,8 @@ function buildStubBodyStatements(config) {
|
|
|
1145
1166
|
bindingExpr,
|
|
1146
1167
|
t.identifier("instanceKey"),
|
|
1147
1168
|
t.stringLiteral(action.exportName),
|
|
1148
|
-
t.identifier("validatedArgs")
|
|
1169
|
+
t.identifier("validatedArgs"),
|
|
1170
|
+
t.stringLiteral(database.name)
|
|
1149
1171
|
]))];
|
|
1150
1172
|
}
|
|
1151
1173
|
/**
|
|
@@ -1166,10 +1188,6 @@ function applyActionTransforms(body, ctx) {
|
|
|
1166
1188
|
imported: "type",
|
|
1167
1189
|
local: ARKTYPE_LOCAL
|
|
1168
1190
|
},
|
|
1169
|
-
{
|
|
1170
|
-
imported: "cachedArgsSchema",
|
|
1171
|
-
local: SCHEMA_LOCAL
|
|
1172
|
-
},
|
|
1173
1191
|
{
|
|
1174
1192
|
imported: "batchedRpc",
|
|
1175
1193
|
local: RPC_LOCAL
|
|
@@ -1194,17 +1212,17 @@ function applyActionTransforms(body, ctx) {
|
|
|
1194
1212
|
}
|
|
1195
1213
|
const exportName = d.id.name;
|
|
1196
1214
|
const action = actionsInFile.find((a) => a.exportName === exportName);
|
|
1197
|
-
const validatorId =
|
|
1215
|
+
const validatorId = validatorIdOf(exportName);
|
|
1198
1216
|
const handlerId = t.identifier(`__handler_${exportName}`);
|
|
1199
|
-
replaced.push(
|
|
1217
|
+
replaced.push(...buildArgsSchemaStatements(action));
|
|
1200
1218
|
replaced.push(t.variableDeclaration("const", [t.variableDeclarator(handlerId, parseExpression(action.handlerSource))]));
|
|
1201
1219
|
replaced.push(t.expressionStatement(t.callExpression(t.identifier("registerAction"), [
|
|
1202
1220
|
t.stringLiteral(dbName),
|
|
1203
1221
|
t.stringLiteral(exportName),
|
|
1204
1222
|
t.objectExpression([
|
|
1205
|
-
t.objectProperty(t.identifier("validator"), t.arrowFunctionExpression([t.identifier("args")], t.callExpression(validatorId, [t.identifier("args")]))),
|
|
1223
|
+
t.objectProperty(t.identifier("validator"), t.arrowFunctionExpression([t.identifier("args")], t.callExpression(t.callExpression(validatorId, []), [t.identifier("args")]))),
|
|
1206
1224
|
t.objectProperty(t.identifier("handler"), handlerId),
|
|
1207
|
-
t.
|
|
1225
|
+
t.objectMethod("get", t.identifier("args"), [], t.blockStatement([t.returnStatement(t.callExpression(validatorId, []))])),
|
|
1208
1226
|
t.objectProperty(t.identifier("stub"), t.identifier(exportName))
|
|
1209
1227
|
])
|
|
1210
1228
|
])));
|
|
@@ -1398,11 +1416,49 @@ const DATABASES_ID = "durable-db/__databases";
|
|
|
1398
1416
|
const VIRTUAL_DATABASES_MODULE_ID = "\0virtual:durable-db/__databases.js";
|
|
1399
1417
|
/** Old org-prefixed spelling, still resolved for compatibility. */
|
|
1400
1418
|
const LEGACY_ID_PREFIX = "eagerpatch/";
|
|
1419
|
+
/** A virtual id in every accepted spelling (`virtual:` optional, legacy prefix). */
|
|
1420
|
+
function virtualIdSpellings(canonicalId) {
|
|
1421
|
+
return [
|
|
1422
|
+
canonicalId,
|
|
1423
|
+
`virtual:${canonicalId}`,
|
|
1424
|
+
`${LEGACY_ID_PREFIX}${canonicalId}`,
|
|
1425
|
+
`virtual:${LEGACY_ID_PREFIX}${canonicalId}`
|
|
1426
|
+
];
|
|
1427
|
+
}
|
|
1401
1428
|
/** Match a virtual id in all accepted spellings (`virtual:` optional, legacy prefix). */
|
|
1402
1429
|
function matchesVirtualId(id, canonicalId) {
|
|
1403
|
-
return
|
|
1430
|
+
return virtualIdSpellings(canonicalId).includes(id);
|
|
1431
|
+
}
|
|
1432
|
+
/** `text` as a RegExp source: its NUL written `\x00` (a raw one in a hook filter's pattern does not reach Rolldown). */
|
|
1433
|
+
function escapeRegExp(text) {
|
|
1434
|
+
return text.replace(/[.*+?^${}()|[\]\\/]/g, "\\$&").replace(/\0/g, "\\x00");
|
|
1435
|
+
}
|
|
1436
|
+
/** Exactly one of `ids`. */
|
|
1437
|
+
function exactIds(ids) {
|
|
1438
|
+
return new RegExp(`^(?:${ids.map(escapeRegExp).join("|")})$`);
|
|
1404
1439
|
}
|
|
1405
1440
|
/**
|
|
1441
|
+
* The hooks' filters (Rolldown — Vite 8 —, Rollup ≥ 4.38, Vite's dev server
|
|
1442
|
+
* ≥ 6.3): the bundler calls a hook only for the ids it may act on, instead of
|
|
1443
|
+
* for every module — a call from the bundler into JS per module per hook, and
|
|
1444
|
+
* for `load`/`transform` a promise. Each is a superset the handler still
|
|
1445
|
+
* checks, never derived from state, and a Vite or Rollup of the peer range
|
|
1446
|
+
* that has no filters (Vite 5.4 on Rollup 4.27) ignores `filter` and calls the
|
|
1447
|
+
* handler for everything, as before.
|
|
1448
|
+
*/
|
|
1449
|
+
const RESOLVE_ID_FILTER = exactIds([
|
|
1450
|
+
DURABLE_OBJECTS_ID,
|
|
1451
|
+
DEV_EPOCH_ID,
|
|
1452
|
+
DATABASES_ID
|
|
1453
|
+
].flatMap(virtualIdSpellings));
|
|
1454
|
+
const LOAD_FILTER = exactIds([
|
|
1455
|
+
VIRTUAL_DO_MODULE_ID,
|
|
1456
|
+
VIRTUAL_DEV_EPOCH_MODULE_ID,
|
|
1457
|
+
VIRTUAL_DATABASES_MODULE_ID
|
|
1458
|
+
]);
|
|
1459
|
+
/** Drizzle's modules (tagged side-effectful) and TypeScript (where a database or an action can be). No exclude: Drizzle lives in node_modules. */
|
|
1460
|
+
const TRANSFORM_FILTER = [/[\\/]drizzle-orm[\\/]/, /\.tsx?$/];
|
|
1461
|
+
/**
|
|
1406
1462
|
* Generate the __devEpoch virtual module. Action stubs route every DO
|
|
1407
1463
|
* instance key through `applyDevEpoch(key, dbName)`:
|
|
1408
1464
|
* - dev: suffixes keys with the database's epoch (`<key>__dev_<epoch>`) — its
|
|
@@ -1570,7 +1626,7 @@ var PluginState = class {
|
|
|
1570
1626
|
const isDev = this.config.command === "serve";
|
|
1571
1627
|
db.migrations = loadMigrationFiles(migrationsDir);
|
|
1572
1628
|
if (isDev) try {
|
|
1573
|
-
const { loadDevMigrations } = await import("../state-
|
|
1629
|
+
const { loadDevMigrations } = await import("../state-k7CdHsWf.js").then((n) => (n.f(), n.y));
|
|
1574
1630
|
const devMigrations = loadDevMigrations(this.projectRoot, db.name);
|
|
1575
1631
|
for (const [name, chunks] of devMigrations) db.migrations.set(`_dev_${name}`, chunks);
|
|
1576
1632
|
if (devMigrations.size > 0) debugVite("Loaded %d dev migration(s) for %s", devMigrations.size, db.name);
|
|
@@ -1721,94 +1777,99 @@ function durableDb(options = {}) {
|
|
|
1721
1777
|
buildStart() {
|
|
1722
1778
|
state.reset();
|
|
1723
1779
|
},
|
|
1724
|
-
resolveId
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1780
|
+
resolveId: {
|
|
1781
|
+
filter: { id: RESOLVE_ID_FILTER },
|
|
1782
|
+
handler(id) {
|
|
1783
|
+
if (matchesVirtualId(id, DURABLE_OBJECTS_ID)) return VIRTUAL_DO_MODULE_ID;
|
|
1784
|
+
if (matchesVirtualId(id, DEV_EPOCH_ID)) return VIRTUAL_DEV_EPOCH_MODULE_ID;
|
|
1785
|
+
if (matchesVirtualId(id, DATABASES_ID)) return VIRTUAL_DATABASES_MODULE_ID;
|
|
1786
|
+
return null;
|
|
1787
|
+
}
|
|
1729
1788
|
},
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
if (
|
|
1738
|
-
state.
|
|
1739
|
-
|
|
1789
|
+
load: {
|
|
1790
|
+
filter: { id: LOAD_FILTER },
|
|
1791
|
+
async handler(id) {
|
|
1792
|
+
if (id === VIRTUAL_DEV_EPOCH_MODULE_ID) {
|
|
1793
|
+
const isDev = state.config.command === "serve";
|
|
1794
|
+
let epoch = null;
|
|
1795
|
+
let databaseEpochs = {};
|
|
1796
|
+
if (isDev) {
|
|
1797
|
+
const devState = loadDevState(state.projectRoot);
|
|
1798
|
+
if (!fs.existsSync(getDevPaths(state.projectRoot).stateFile)) {
|
|
1799
|
+
state.markSelfDevStateWrite();
|
|
1800
|
+
saveDevState(state.projectRoot, devState);
|
|
1801
|
+
}
|
|
1802
|
+
epoch = devState.epoch;
|
|
1803
|
+
databaseEpochs = getDatabaseEpochs(devState);
|
|
1740
1804
|
}
|
|
1741
|
-
epoch
|
|
1742
|
-
databaseEpochs = getDatabaseEpochs(devState);
|
|
1805
|
+
return { code: generateDevEpochModule(epoch, databaseEpochs) };
|
|
1743
1806
|
}
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1807
|
+
if (id === VIRTUAL_DATABASES_MODULE_ID) {
|
|
1808
|
+
await state.initialize();
|
|
1809
|
+
return { code: generateDatabasesModule(Array.from(state.databases.values())) };
|
|
1810
|
+
}
|
|
1811
|
+
if (id !== VIRTUAL_DO_MODULE_ID) return null;
|
|
1747
1812
|
await state.initialize();
|
|
1748
|
-
|
|
1813
|
+
const isDev = state.config.command === "serve";
|
|
1814
|
+
const actionFiles = discoverActionFiles({
|
|
1815
|
+
projectRoot: state.projectRoot,
|
|
1816
|
+
databasesDir: state.options.databasesDir
|
|
1817
|
+
});
|
|
1818
|
+
const databases = Array.from(state.databases.values());
|
|
1819
|
+
return { code: generateDurableObjectsModule(databases, state.options.registryImport, isDev, actionFiles, tombstoneClasses(state.projectRoot, databases), resolveOutbox(state.options.outbox, state.projectRoot)) };
|
|
1749
1820
|
}
|
|
1750
|
-
if (id !== VIRTUAL_DO_MODULE_ID) return null;
|
|
1751
|
-
await state.initialize();
|
|
1752
|
-
const isDev = state.config.command === "serve";
|
|
1753
|
-
const actionFiles = discoverActionFiles({
|
|
1754
|
-
projectRoot: state.projectRoot,
|
|
1755
|
-
databasesDir: state.options.databasesDir
|
|
1756
|
-
});
|
|
1757
|
-
const databases = Array.from(state.databases.values());
|
|
1758
|
-
return { code: generateDurableObjectsModule(databases, state.options.registryImport, isDev, actionFiles, tombstoneClasses(state.projectRoot, databases), resolveOutbox(state.options.outbox, state.projectRoot)) };
|
|
1759
1821
|
},
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1822
|
+
transform: {
|
|
1823
|
+
filter: { id: { include: TRANSFORM_FILTER } },
|
|
1824
|
+
async handler(code, id) {
|
|
1825
|
+
if (/[\\/]drizzle-orm[\\/]/.test(id)) return { moduleSideEffects: true };
|
|
1826
|
+
if (id.startsWith("\0") || id.includes("node_modules")) return null;
|
|
1827
|
+
if (!/\.tsx?$/.test(id)) return null;
|
|
1828
|
+
if (!mayDefineDatabaseCode(code)) return null;
|
|
1829
|
+
await state.initialize();
|
|
1830
|
+
const cleanId = path$1.normalize(id.split("?", 1)[0]);
|
|
1831
|
+
const dbNameForPath = state.getDatabaseNameForPath(cleanId);
|
|
1832
|
+
if (dbNameForPath) {
|
|
1833
|
+
const database = state.databases.get(dbNameForPath);
|
|
1834
|
+
if (!database) return null;
|
|
1835
|
+
const parsed = parseDatabaseFile(cleanId, code, { aliases: state.aliases });
|
|
1836
|
+
for (const action of parsed.actions) state.registerAction(action, dbNameForPath, cleanId);
|
|
1837
|
+
const result = transformDatabaseFile({
|
|
1838
|
+
code,
|
|
1839
|
+
sourceFileName: cleanId,
|
|
1840
|
+
database,
|
|
1841
|
+
actionsInFile: parsed.actions,
|
|
1842
|
+
contextImport: state.options.contextImport,
|
|
1843
|
+
registryImport: state.options.registryImport
|
|
1844
|
+
});
|
|
1845
|
+
if (result && parsed.actions.length > 0 && state.config.command === "serve") state.invalidateDOModule();
|
|
1846
|
+
return result ? {
|
|
1847
|
+
code: result.code,
|
|
1848
|
+
map: result.map
|
|
1849
|
+
} : null;
|
|
1850
|
+
}
|
|
1775
1851
|
const parsed = parseDatabaseFile(cleanId, code, { aliases: state.aliases });
|
|
1776
|
-
|
|
1777
|
-
const
|
|
1852
|
+
if (parsed.actions.length === 0) return null;
|
|
1853
|
+
const importedDbName = await findImportedDatabase(this.resolve.bind(this), state, parsed.localImports, cleanId);
|
|
1854
|
+
if (!importedDbName) return null;
|
|
1855
|
+
const database = state.databases.get(importedDbName);
|
|
1856
|
+
if (!database) return null;
|
|
1857
|
+
for (const action of parsed.actions) state.registerAction(action, importedDbName, cleanId);
|
|
1858
|
+
const result = transformActionFile({
|
|
1778
1859
|
code,
|
|
1779
1860
|
sourceFileName: cleanId,
|
|
1861
|
+
dbName: importedDbName,
|
|
1780
1862
|
database,
|
|
1781
1863
|
actionsInFile: parsed.actions,
|
|
1782
1864
|
contextImport: state.options.contextImport,
|
|
1783
1865
|
registryImport: state.options.registryImport
|
|
1784
1866
|
});
|
|
1785
|
-
if (result &&
|
|
1867
|
+
if (result && state.config.command === "serve") state.invalidateDOModule();
|
|
1786
1868
|
return result ? {
|
|
1787
1869
|
code: result.code,
|
|
1788
1870
|
map: result.map
|
|
1789
1871
|
} : null;
|
|
1790
1872
|
}
|
|
1791
|
-
const parsed = parseDatabaseFile(cleanId, code, { aliases: state.aliases });
|
|
1792
|
-
if (parsed.actions.length === 0) return null;
|
|
1793
|
-
const importedDbName = await findImportedDatabase(this.resolve.bind(this), state, parsed.localImports, cleanId);
|
|
1794
|
-
if (!importedDbName) return null;
|
|
1795
|
-
const database = state.databases.get(importedDbName);
|
|
1796
|
-
if (!database) return null;
|
|
1797
|
-
for (const action of parsed.actions) state.registerAction(action, importedDbName, cleanId);
|
|
1798
|
-
const result = transformActionFile({
|
|
1799
|
-
code,
|
|
1800
|
-
sourceFileName: cleanId,
|
|
1801
|
-
dbName: importedDbName,
|
|
1802
|
-
database,
|
|
1803
|
-
actionsInFile: parsed.actions,
|
|
1804
|
-
contextImport: state.options.contextImport,
|
|
1805
|
-
registryImport: state.options.registryImport
|
|
1806
|
-
});
|
|
1807
|
-
if (result && state.config.command === "serve") state.invalidateDOModule();
|
|
1808
|
-
return result ? {
|
|
1809
|
-
code: result.code,
|
|
1810
|
-
map: result.map
|
|
1811
|
-
} : null;
|
|
1812
1873
|
},
|
|
1813
1874
|
buildEnd() {
|
|
1814
1875
|
if (state.actions.size > 0) debugVite("Discovered %d action(s)", state.actions.size);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "durable-db",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/eagerpatch/durable-db.git"
|
|
@@ -79,7 +79,8 @@
|
|
|
79
79
|
"dev": "tsdown --watch",
|
|
80
80
|
"type-check": "tsc --noEmit -p . && tsc -p tests/type/tsconfig.json",
|
|
81
81
|
"test": "vitest",
|
|
82
|
-
"test:run": "vitest run",
|
|
82
|
+
"test:run": "vitest run && vitest run -c vitest.workers.config.ts",
|
|
83
|
+
"test:workers": "vitest run -c vitest.workers.config.ts",
|
|
83
84
|
"changeset": "changeset"
|
|
84
85
|
},
|
|
85
86
|
"dependencies": {
|