@junejs/db 0.0.33-dev.1 → 0.0.33-dev.2
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/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/scope.d.ts +3 -1
- package/dist/scope.js +4 -1
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/scope.ts +20 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { RequestScope, blob, currentLocale, db, ensureScope, kv, registerSqlTagger, requestLocal, runInScope, setRequestLocale } from "./scope.js";
|
|
2
|
-
export { type RequestScope, blob, currentLocale, db, ensureScope, kv, registerSqlTagger, requestLocal, runInScope, setRequestLocale };
|
|
1
|
+
import { RequestScope, blob, currentLocale, currentServices, db, ensureScope, kv, registerSqlTagger, requestLocal, runInScope, setRequestLocale } from "./scope.js";
|
|
2
|
+
export { type RequestScope, blob, currentLocale, currentServices, db, ensureScope, kv, registerSqlTagger, requestLocal, runInScope, setRequestLocale };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { blob, currentLocale, db, ensureScope, kv, registerSqlTagger, requestLocal, runInScope, setRequestLocale } from "./scope.js";
|
|
2
|
-
export { blob, currentLocale, db, ensureScope, kv, registerSqlTagger, requestLocal, runInScope, setRequestLocale };
|
|
1
|
+
import { blob, currentLocale, currentServices, db, ensureScope, kv, registerSqlTagger, requestLocal, runInScope, setRequestLocale } from "./scope.js";
|
|
2
|
+
export { blob, currentLocale, currentServices, db, ensureScope, kv, registerSqlTagger, requestLocal, runInScope, setRequestLocale };
|
package/dist/scope.d.ts
CHANGED
|
@@ -4,15 +4,17 @@ type RequestScope = {
|
|
|
4
4
|
resources: Resources;
|
|
5
5
|
locals?: Map<symbol, unknown>;
|
|
6
6
|
locale?: string;
|
|
7
|
+
services?: unknown;
|
|
7
8
|
};
|
|
8
9
|
declare function ensureScope(): Promise<void>;
|
|
9
10
|
declare function runInScope<T>(scope: RequestScope, fn: () => T): T;
|
|
10
11
|
declare function requestLocal<T>(key: symbol, make: () => T): T;
|
|
11
12
|
declare function setRequestLocale(locale: string): void;
|
|
12
13
|
declare function currentLocale(): string | undefined;
|
|
14
|
+
declare function currentServices<T = unknown>(): T | undefined;
|
|
13
15
|
declare function registerSqlTagger(tag: (sql: string) => void): void;
|
|
14
16
|
declare const db: JuneDb;
|
|
15
17
|
declare const kv: JuneKv;
|
|
16
18
|
declare const blob: JuneBlob;
|
|
17
19
|
//#endregion
|
|
18
|
-
export { RequestScope, blob, currentLocale, db, ensureScope, kv, registerSqlTagger, requestLocal, runInScope, setRequestLocale };
|
|
20
|
+
export { RequestScope, blob, currentLocale, currentServices, db, ensureScope, kv, registerSqlTagger, requestLocal, runInScope, setRequestLocale };
|
package/dist/scope.js
CHANGED
|
@@ -27,6 +27,9 @@ function setRequestLocale(locale) {
|
|
|
27
27
|
function currentLocale() {
|
|
28
28
|
return als?.getStore()?.locale;
|
|
29
29
|
}
|
|
30
|
+
function currentServices() {
|
|
31
|
+
return als?.getStore()?.services ?? void 0;
|
|
32
|
+
}
|
|
30
33
|
function pick(name) {
|
|
31
34
|
const store = als?.getStore();
|
|
32
35
|
if (!store) throw new Error(`June: \`${name}\` was used outside a request scope. Resources are only available while a request is being handled (a route loader/view or an action).`);
|
|
@@ -56,4 +59,4 @@ const db = new Proxy({}, { get(_t, prop) {
|
|
|
56
59
|
const kv = ambient("kv");
|
|
57
60
|
const blob = ambient("blob");
|
|
58
61
|
//#endregion
|
|
59
|
-
export { blob, currentLocale, db, ensureScope, kv, registerSqlTagger, requestLocal, runInScope, setRequestLocale };
|
|
62
|
+
export { blob, currentLocale, currentServices, db, ensureScope, kv, registerSqlTagger, requestLocal, runInScope, setRequestLocale };
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
package/src/scope.ts
CHANGED
|
@@ -33,6 +33,15 @@ export type RequestScope = {
|
|
|
33
33
|
// opt-in layer (e.g. @junejs/i18n's ambient `t`) reads it WITHOUT the core
|
|
34
34
|
// pipeline depending on that layer. Undefined when no i18n is configured.
|
|
35
35
|
locale?: string;
|
|
36
|
+
// App-defined services bag, seeded by the host at each ISOLATE ENTRY from that
|
|
37
|
+
// isolate's env — the Worker pipeline from the worker env, a Durable Object from
|
|
38
|
+
// its own env (env only exists inside an invocation on workerd, never at module
|
|
39
|
+
// top-level). This is the seam for resources June does NOT model (Vectorize,
|
|
40
|
+
// Workers AI, an app ledger, a signing secret): the app builds it where env lives
|
|
41
|
+
// and reads it ambiently via currentServices(), so a tool needs neither a
|
|
42
|
+
// module-global setter nor `env` on ctx. Opaque here on purpose — @junejs/db
|
|
43
|
+
// never names the app's service shape; the app supplies the type at the read.
|
|
44
|
+
services?: unknown;
|
|
36
45
|
};
|
|
37
46
|
|
|
38
47
|
// The minimal slice of AsyncLocalStorage we use — kept structural so this module
|
|
@@ -100,6 +109,17 @@ export function currentLocale(): string | undefined {
|
|
|
100
109
|
return als?.getStore()?.locale;
|
|
101
110
|
}
|
|
102
111
|
|
|
112
|
+
// The current isolate's app-defined services bag (see RequestScope.services), or
|
|
113
|
+
// undefined outside a scope / when none was seeded. Soft (returns undefined) rather
|
|
114
|
+
// than throwing, because services are optional and app-defined: the app wraps this
|
|
115
|
+
// in its OWN typed accessor that throws when a specific service it needs is missing.
|
|
116
|
+
// @junejs/db stays generic — it carries the bag, never inspects it. A nullish bag
|
|
117
|
+
// (unset OR explicitly `null`) normalizes to `undefined` so the `T | undefined`
|
|
118
|
+
// return type is sound — a caller guarding only `undefined` can't be handed a null.
|
|
119
|
+
export function currentServices<T = unknown>(): T | undefined {
|
|
120
|
+
return (als?.getStore()?.services ?? undefined) as T | undefined;
|
|
121
|
+
}
|
|
122
|
+
|
|
103
123
|
function pick<K extends keyof Resources>(name: K): NonNullable<Resources[K]> {
|
|
104
124
|
const store = als?.getStore();
|
|
105
125
|
if (!store) {
|