durable-db 0.0.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/README.md +1052 -0
- package/dist/cli/bin.d.ts +1 -0
- package/dist/cli/bin.js +18 -0
- package/dist/cli/index.d.ts +330 -0
- package/dist/cli/index.js +9 -0
- package/dist/cli-Cr9686BF.js +630 -0
- package/dist/context/index.d.ts +2 -0
- package/dist/context/index.js +5 -0
- package/dist/context-BuIiIQ6K.js +103 -0
- package/dist/db/index.d.ts +3 -0
- package/dist/db/index.js +760 -0
- package/dist/debug-BZJbKybf.js +49 -0
- package/dist/defineDatabase-CONf4xFC.js +54 -0
- package/dist/defineDatabase-jBv90-Pk.d.ts +188 -0
- package/dist/generator-BUPP9scJ.js +180 -0
- package/dist/index-BFM5d0FP.d.ts +328 -0
- package/dist/index-CqVMaMYY.d.ts +65 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +8 -0
- package/dist/migrations/generator.d.ts +101 -0
- package/dist/migrations/generator.js +5 -0
- package/dist/migrations/snapshot.d.ts +2 -0
- package/dist/migrations/snapshot.js +3 -0
- package/dist/parser-CbX54Flt.js +293 -0
- package/dist/protocol-g_plhPOY.js +35 -0
- package/dist/push-BgQ5cnfH.js +184 -0
- package/dist/push-BkkaslPd.js +8 -0
- package/dist/registry.d.ts +28 -0
- package/dist/registry.js +72 -0
- package/dist/schema-BOtrGnzM.js +8 -0
- package/dist/schema-CpzTOfZ6.d.ts +6 -0
- package/dist/schema.d.ts +2 -0
- package/dist/schema.js +3 -0
- package/dist/snapshot-C162qYoA.d.ts +125 -0
- package/dist/snapshot-D170nL7i.js +93 -0
- package/dist/state-BCcvNN-M.js +5 -0
- package/dist/state-FOEjpgJ6.js +203 -0
- package/dist/transport/protocol.d.ts +27 -0
- package/dist/transport/protocol.js +3 -0
- package/dist/transport/websocket.d.ts +31 -0
- package/dist/transport/websocket.js +3 -0
- package/dist/vite/durableDb.d.ts +20 -0
- package/dist/vite/durableDb.js +933 -0
- package/dist/websocket-Dx1fqwnF.js +104 -0
- package/package.json +114 -0
- package/virtual.d.ts +15 -0
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { s as __toCommonJS } from "./debug-BZJbKybf.js";
|
|
2
|
+
import { d as init_state, v as state_exports } from "./state-FOEjpgJ6.js";
|
|
3
|
+
|
|
4
|
+
//#region src/context/index.ts
|
|
5
|
+
/**
|
|
6
|
+
* Tenant ID resolver for framework integration.
|
|
7
|
+
*/
|
|
8
|
+
let tenantIdResolver = null;
|
|
9
|
+
/**
|
|
10
|
+
* Configure a tenant ID resolver.
|
|
11
|
+
*
|
|
12
|
+
* The resolver is called at the moment a database operation needs the tenant ID —
|
|
13
|
+
* by which point request middleware (auth, session, etc.) has already completed.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* import { setTenantIdResolver } from 'durable-db/context';
|
|
18
|
+
* import { getRequestInfo } from 'rwsdk/worker';
|
|
19
|
+
*
|
|
20
|
+
* setTenantIdResolver(() => getRequestInfo().ctx.session!.shop);
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
function setTenantIdResolver(resolver) {
|
|
24
|
+
tenantIdResolver = resolver;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Get the current tenant ID from the configured resolver.
|
|
28
|
+
*
|
|
29
|
+
* @throws Error if no resolver is configured
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* import { getTenantId } from 'durable-db/context';
|
|
34
|
+
*
|
|
35
|
+
* async function myHandler() {
|
|
36
|
+
* const tenantId = getTenantId();
|
|
37
|
+
* // ...
|
|
38
|
+
* }
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
function getTenantId() {
|
|
42
|
+
if (tenantIdResolver) return tenantIdResolver();
|
|
43
|
+
throw new Error("getTenantId() called without a resolver. Call setTenantIdResolver() first.");
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Check if a tenant ID resolver is configured.
|
|
47
|
+
*/
|
|
48
|
+
function hasTenantId() {
|
|
49
|
+
return tenantIdResolver !== null;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* One-time warning guard: we only log an unexpected dev-epoch load failure
|
|
53
|
+
* once per process so Vite HMR / repeated lookups don't spam stderr.
|
|
54
|
+
*/
|
|
55
|
+
let loggedDevEpochFailure = false;
|
|
56
|
+
/**
|
|
57
|
+
* Get the dev epoch for instance key suffixing
|
|
58
|
+
* Only used in development to allow database resets
|
|
59
|
+
*
|
|
60
|
+
* Returns null in production or if no dev state exists
|
|
61
|
+
*
|
|
62
|
+
* @deprecated The epoch is now baked into generated stubs at build time via
|
|
63
|
+
* the `virtual:durable-db/__devEpoch` module — this function
|
|
64
|
+
* cannot read the dev state inside workerd (no filesystem) and returns null
|
|
65
|
+
* there. Import `devEpoch` / `applyDevEpoch` from the virtual module instead.
|
|
66
|
+
*/
|
|
67
|
+
function getDevInstanceKeySuffix() {
|
|
68
|
+
if (process.env.NODE_ENV === "production") return null;
|
|
69
|
+
try {
|
|
70
|
+
const { getDevEpoch } = (init_state(), __toCommonJS(state_exports));
|
|
71
|
+
return getDevEpoch(process.cwd());
|
|
72
|
+
} catch (e) {
|
|
73
|
+
const code = e?.code;
|
|
74
|
+
if (code !== "MODULE_NOT_FOUND" && code !== "ERR_MODULE_NOT_FOUND" && !loggedDevEpochFailure) {
|
|
75
|
+
loggedDevEpochFailure = true;
|
|
76
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
77
|
+
console.warn(`[durable-db] Could not load dev epoch state (continuing without it): ${message}`);
|
|
78
|
+
}
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Get a database instance key, optionally suffixed with dev epoch
|
|
84
|
+
*
|
|
85
|
+
* In development, this appends an epoch suffix to enable database resets.
|
|
86
|
+
* In production, this returns the base key unchanged.
|
|
87
|
+
*
|
|
88
|
+
* @deprecated Generated stubs apply the epoch automatically via
|
|
89
|
+
* `applyDevEpoch` from `virtual:durable-db/__devEpoch`. This
|
|
90
|
+
* function only works in Node (it reads the dev state from disk) and is the
|
|
91
|
+
* identity inside workerd — combining it with the generated stubs would
|
|
92
|
+
* also double-suffix keys. Import from the virtual module instead.
|
|
93
|
+
*
|
|
94
|
+
* @param baseKey - The base instance key (e.g., tenant ID or 'global')
|
|
95
|
+
*/
|
|
96
|
+
function getInstanceKey(baseKey) {
|
|
97
|
+
const suffix = getDevInstanceKeySuffix();
|
|
98
|
+
if (!suffix) return baseKey;
|
|
99
|
+
return `${baseKey}__dev_${suffix}`;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
//#endregion
|
|
103
|
+
export { setTenantIdResolver as a, hasTenantId as i, getInstanceKey as n, getTenantId as r, getDevInstanceKeySuffix as t };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
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-jBv90-Pk.js";
|
|
2
|
+
import { _ as SqlExecutor, a as QueryResult, c as DateSerializePlugin, d as createDrizzlePlugins, f as dateSerializers, g as Migrations, h as MigrationAttemptInfo, i as KyselyPlugin, l as DrizzleDefaultsPlugin, m as Migration, n as CompiledQuery, o as studio, p as CreateKyselyOptions, r as Kysely, s as type, t as CamelCasePlugin, u as SchemaPlugin, v as SqliteDurableObject, y as createKyselyFromSql } from "../index-BFM5d0FP.js";
|
|
3
|
+
export { Action, ActionConfig, ActionContext, ActionInfo, ArgsSchema, CamelCasePlugin, CompiledQuery, CreateKyselyOptions, DatabaseConfig, DatabaseDefinition, DatabaseInfo, DateSerializePlugin, DrizzleDefaultsPlugin, DrizzleToKysely, InferArgs, Kysely, KyselyPlugin, Migration, MigrationAttemptInfo, Migrations, ParsedDatabaseFile, QueryResult, SchemaPlugin, SqlExecutor, SqliteDurableObject, createDrizzlePlugins, createKyselyFromSql, dateSerializers, defineDatabase, studio, type };
|