@junejs/db 0.0.25 → 0.0.27

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@junejs/db",
3
- "version": "0.0.25",
3
+ "version": "0.0.27",
4
4
  "description": "June — the agent-native React framework. Ambient data resources (db/kv/blob).",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -16,7 +16,7 @@
16
16
  "typecheck": "tsc --noEmit"
17
17
  },
18
18
  "dependencies": {
19
- "@junejs/core": "0.0.25"
19
+ "@junejs/core": "0.0.27"
20
20
  },
21
21
  "repository": {
22
22
  "type": "git",
package/src/index.ts CHANGED
@@ -3,4 +3,15 @@
3
3
  // or action. The host (@junejs/server) opens the resources and runs each request
4
4
  // in the scope these read; this package is the worker-safe seam they cross.
5
5
 
6
- export { db, kv, blob, runInScope, ensureScope, requestLocal, registerSqlTagger, type RequestScope } from "./scope";
6
+ export {
7
+ db,
8
+ kv,
9
+ blob,
10
+ runInScope,
11
+ ensureScope,
12
+ requestLocal,
13
+ setRequestLocale,
14
+ currentLocale,
15
+ registerSqlTagger,
16
+ type RequestScope,
17
+ } from "./scope";
package/src/scope.ts CHANGED
@@ -25,7 +25,15 @@ import type { Resources, JuneDb, JuneKv, JuneBlob } from "@junejs/core/resources
25
25
  // (e.g. Juno's batch-loader registry). This package never reads it — it just
26
26
  // carries it per request so such state is STRUCTURALLY request-scoped and can't be
27
27
  // stashed on a long-lived handle. Lazily created by requestLocal().
28
- export type RequestScope = { resources: Resources; locals?: Map<symbol, unknown> };
28
+ export type RequestScope = {
29
+ resources: Resources;
30
+ locals?: Map<symbol, unknown>;
31
+ // The resolved request locale (set by the host after locale resolution). A
32
+ // request-scope attribute like the design's {locale, tenant, site} — so an
33
+ // opt-in layer (e.g. @junejs/i18n's ambient `t`) reads it WITHOUT the core
34
+ // pipeline depending on that layer. Undefined when no i18n is configured.
35
+ locale?: string;
36
+ };
29
37
 
30
38
  // The minimal slice of AsyncLocalStorage we use — kept structural so this module
31
39
  // never statically names the runtime.
@@ -78,6 +86,20 @@ export function requestLocal<T>(key: symbol, make: () => T): T {
78
86
  return locals.get(key) as T;
79
87
  }
80
88
 
89
+ // The host sets the resolved locale onto the active scope after it resolves it
90
+ // (the scope is opened before routing, so the locale arrives mid-request). A no-op
91
+ // outside a scope, like the ambient resources.
92
+ export function setRequestLocale(locale: string): void {
93
+ const store = als?.getStore();
94
+ if (store) store.locale = locale;
95
+ }
96
+
97
+ // The current request's resolved locale, or undefined (no scope / no i18n). The
98
+ // generic read an opt-in i18n layer's ambient `t` uses — no dependency on i18n here.
99
+ export function currentLocale(): string | undefined {
100
+ return als?.getStore()?.locale;
101
+ }
102
+
81
103
  function pick<K extends keyof Resources>(name: K): NonNullable<Resources[K]> {
82
104
  const store = als?.getStore();
83
105
  if (!store) {