durable-db 0.1.11 → 0.1.12
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/context/index.d.ts +1 -1
- package/dist/context/index.js +1 -1
- package/dist/{context-DbGqDnBa.js → context-kIVZbhye.js} +20 -2
- package/dist/{index-D9LHeBx2.d.ts → index-BhRiKZ4j.d.ts} +2 -16
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/registry.js +1 -0
- package/dist/testing/index.js +1 -1
- package/package.json +10 -9
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-BhRiKZ4j.js";
|
|
2
2
|
export { getDevInstanceKeySuffix, getInstanceKey, getTenantId, hasTenantId, setTenantIdResolver };
|
package/dist/context/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "../debug-DmBrUmwe.js";
|
|
2
2
|
import "../state-DtZ70cBR.js";
|
|
3
|
-
import { a as setTenantIdResolver, i as hasTenantId, n as getInstanceKey, r as getTenantId, t as getDevInstanceKeySuffix } from "../context-
|
|
3
|
+
import { a as setTenantIdResolver, i as hasTenantId, n as getInstanceKey, r as getTenantId, t as getDevInstanceKeySuffix } from "../context-kIVZbhye.js";
|
|
4
4
|
|
|
5
5
|
export { getDevInstanceKeySuffix, getInstanceKey, getTenantId, hasTenantId, setTenantIdResolver };
|
|
@@ -38,15 +38,33 @@ function setTenantIdResolver(resolver) {
|
|
|
38
38
|
* }
|
|
39
39
|
* ```
|
|
40
40
|
*/
|
|
41
|
+
/**
|
|
42
|
+
* Inside a Durable Object the instance key IS the tenant (per-tenant DBs key
|
|
43
|
+
* their instances by tenant id, plus an optional `__dev_<epoch>` suffix in
|
|
44
|
+
* dev). The registry publishes its DoContext store getter on globalThis — see
|
|
45
|
+
* the note there for why this is not a module import — so getTenantId() works
|
|
46
|
+
* in action handlers without the worker-side resolver, which the DO execution
|
|
47
|
+
* context never registers.
|
|
48
|
+
*/
|
|
49
|
+
function tenantIdFromDoContext() {
|
|
50
|
+
const getStore = globalThis[Symbol.for("durable-db.doContext")];
|
|
51
|
+
const key = getStore?.()?.instanceKey;
|
|
52
|
+
if (!key || key === "global") return null;
|
|
53
|
+
const suffixAt = key.lastIndexOf("__dev_");
|
|
54
|
+
return suffixAt === -1 ? key : key.slice(0, suffixAt);
|
|
55
|
+
}
|
|
41
56
|
function getTenantId() {
|
|
42
57
|
if (tenantIdResolver) return tenantIdResolver();
|
|
58
|
+
const doTenant = tenantIdFromDoContext();
|
|
59
|
+
if (doTenant) return doTenant;
|
|
43
60
|
throw new Error("getTenantId() called without a resolver. Call setTenantIdResolver() first.");
|
|
44
61
|
}
|
|
45
62
|
/**
|
|
46
|
-
* Check if a tenant ID resolver is configured
|
|
63
|
+
* Check if a tenant ID resolver is configured (or a Durable Object context
|
|
64
|
+
* can supply the tenant).
|
|
47
65
|
*/
|
|
48
66
|
function hasTenantId() {
|
|
49
|
-
return tenantIdResolver !== null;
|
|
67
|
+
return tenantIdResolver !== null || tenantIdFromDoContext() !== null;
|
|
50
68
|
}
|
|
51
69
|
/**
|
|
52
70
|
* One-time warning guard: we only log an unexpected dev-epoch load failure
|
|
@@ -14,24 +14,10 @@
|
|
|
14
14
|
* ```
|
|
15
15
|
*/
|
|
16
16
|
declare function setTenantIdResolver(resolver: (() => string) | null): void;
|
|
17
|
-
/**
|
|
18
|
-
* Get the current tenant ID from the configured resolver.
|
|
19
|
-
*
|
|
20
|
-
* @throws Error if no resolver is configured
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* ```ts
|
|
24
|
-
* import { getTenantId } from 'durable-db/context';
|
|
25
|
-
*
|
|
26
|
-
* async function myHandler() {
|
|
27
|
-
* const tenantId = getTenantId();
|
|
28
|
-
* // ...
|
|
29
|
-
* }
|
|
30
|
-
* ```
|
|
31
|
-
*/
|
|
32
17
|
declare function getTenantId(): string;
|
|
33
18
|
/**
|
|
34
|
-
* Check if a tenant ID resolver is configured
|
|
19
|
+
* Check if a tenant ID resolver is configured (or a Durable Object context
|
|
20
|
+
* can supply the tenant).
|
|
35
21
|
*/
|
|
36
22
|
declare function hasTenantId(): boolean;
|
|
37
23
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as type } from "./arktypeConfig--4OgOv4U.js";
|
|
2
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-Bjws1Jkd.js";
|
|
3
|
-
import { a as setTenantIdResolver, i as hasTenantId, r as getTenantId } from "./index-
|
|
3
|
+
import { a as setTenantIdResolver, i as hasTenantId, r as getTenantId } from "./index-BhRiKZ4j.js";
|
|
4
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-BCjqTRvV.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 };
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,6 @@ import { t as type } from "./arktypeConfig-CTCJm4vA.js";
|
|
|
3
3
|
import { n as defineDatabase } from "./defineDatabase-BD3k1L7d.js";
|
|
4
4
|
import { a as numeric, c as table, i as integer, l as text, n as foreignKey, o as primaryKey, r as index, s as real, t as blob, u as uniqueIndex } from "./schema-IFq7ovQq.js";
|
|
5
5
|
import "./state-DtZ70cBR.js";
|
|
6
|
-
import { a as setTenantIdResolver, i as hasTenantId, r as getTenantId } from "./context-
|
|
6
|
+
import { a as setTenantIdResolver, i as hasTenantId, r as getTenantId } from "./context-kIVZbhye.js";
|
|
7
7
|
|
|
8
8
|
export { blob, defineDatabase, foreignKey, getTenantId, hasTenantId, index, integer, numeric, primaryKey, real, setTenantIdResolver, table, text, type, uniqueIndex };
|
package/dist/registry.js
CHANGED
|
@@ -6,6 +6,7 @@ import { AsyncLocalStorage } from "node:async_hooks";
|
|
|
6
6
|
const actionsByDb = /* @__PURE__ */ new Map();
|
|
7
7
|
const als = new AsyncLocalStorage();
|
|
8
8
|
const wsTransportCache = /* @__PURE__ */ new Map();
|
|
9
|
+
globalThis[Symbol.for("durable-db.doContext")] = () => als.getStore();
|
|
9
10
|
function getOrCreateWsTransport(bindingName, instanceKey, stub) {
|
|
10
11
|
const cacheKey = `${bindingName}:${instanceKey}`;
|
|
11
12
|
let transport = wsTransportCache.get(cacheKey);
|
package/dist/testing/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import "../debug-DmBrUmwe.js";
|
|
|
2
2
|
import { t as type } from "../arktypeConfig-CTCJm4vA.js";
|
|
3
3
|
import { t as ACTION_TEST_META } from "../defineDatabase-BD3k1L7d.js";
|
|
4
4
|
import "../state-DtZ70cBR.js";
|
|
5
|
-
import { a as setTenantIdResolver } from "../context-
|
|
5
|
+
import { a as setTenantIdResolver } from "../context-kIVZbhye.js";
|
|
6
6
|
import { t as createKyselyFromSql } from "../kysely-BH7QZBZw.js";
|
|
7
7
|
import { n as generateMigrationStatements, r as generateSnapshotFromSchema, t as createEmptySnapshot } from "../snapshot-DMW6j2Ix.js";
|
|
8
8
|
import { createRequire } from "node:module";
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "durable-db",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.12",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/eagerpatch/durable-db.git"
|
|
7
7
|
},
|
|
8
8
|
"type": "module",
|
|
9
|
+
"packageManager": "pnpm@10.2.1",
|
|
9
10
|
"bin": {
|
|
10
11
|
"db": "./dist/cli/bin.js"
|
|
11
12
|
},
|
|
@@ -69,6 +70,13 @@
|
|
|
69
70
|
"publishConfig": {
|
|
70
71
|
"access": "public"
|
|
71
72
|
},
|
|
73
|
+
"scripts": {
|
|
74
|
+
"build": "tsdown",
|
|
75
|
+
"dev": "tsdown --watch",
|
|
76
|
+
"test": "vitest",
|
|
77
|
+
"test:run": "vitest run",
|
|
78
|
+
"changeset": "changeset"
|
|
79
|
+
},
|
|
72
80
|
"dependencies": {
|
|
73
81
|
"@babel/generator": "^7.0.0",
|
|
74
82
|
"@babel/parser": "^7.0.0",
|
|
@@ -104,12 +112,5 @@
|
|
|
104
112
|
"typescript": "^5.7.0",
|
|
105
113
|
"vite": "^7.0.0",
|
|
106
114
|
"vitest": "^2.1.0"
|
|
107
|
-
},
|
|
108
|
-
"scripts": {
|
|
109
|
-
"build": "tsdown",
|
|
110
|
-
"dev": "tsdown --watch",
|
|
111
|
-
"test": "vitest",
|
|
112
|
-
"test:run": "vitest run",
|
|
113
|
-
"changeset": "changeset"
|
|
114
115
|
}
|
|
115
|
-
}
|
|
116
|
+
}
|