@ultimat3/core 31.22.3 → 31.23.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 CHANGED
@@ -1038,6 +1038,7 @@ on the system clock. Their callers are the boot (reading
1038
1038
  | Name | What |
1039
1039
  |---|---|
1040
1040
  | `CompletionBound` | what bounds a `runToCompletion` scope, when its caller owns a ceiling |
1041
+ | `parentContext(ctx)` | the context `ctx` was derived inside (`withChildContext`, `runToCompletion`), or `undefined`. Held weakly by the child. How `@ultimat3/http`'s `hasRequest()` finds a request a child does not carry |
1041
1042
  | `MAX_TIMER_MS` | the longest delay a timer holds, 2,147,483,647 ms: past it `setTimeout` arms ~1 ms |
1042
1043
  | `hostDecision(url, allowHosts)`, `hostMatches`, `ANY_HOST` | may a browser or scraper request leave. A wildcard (`'*'`, `'*.example.com'`) never admits an address inside the network nor `localhost`/`*.localhost` (loopback by name, and sent around an egress proxy by Chrome); an exact rule — `'localhost'`, `'127.0.0.1'` — does |
1043
1044
  | `jsonbRefusal(text)` | why `jsonb` would refuse this `JSON.stringify` output, or `undefined`. Names the class of thing, never the text |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ultimat3/core",
3
- "version": "31.22.3",
3
+ "version": "31.23.0",
4
4
  "description": "Ultimate's foundation: errors, context, env, config, clock, ids, logging, telemetry, lifecycle",
5
5
  "keywords": [
6
6
  "ultimate",
@@ -54,6 +54,6 @@
54
54
  "test": "bun test"
55
55
  },
56
56
  "dependencies": {
57
- "@ultimat3/schema": "31.22.3"
57
+ "@ultimat3/schema": "31.23.0"
58
58
  }
59
59
  }
package/src/context.ts CHANGED
@@ -307,6 +307,18 @@ export function withChildContext<T>(patch: CtxPatch, fn: () => T): T {
307
307
  return requestContext.run(child, fn);
308
308
  }
309
309
 
310
+ /**
311
+ * Each derived context's parent, keyed weakly by the CHILD: an entry lives exactly as long as the
312
+ * child does, so a parent is never held past the last child still pointing at it. Core knows no
313
+ * layer's fields; a layer above (http's request frame) finds what a child was derived inside here.
314
+ */
315
+ const parents = new WeakMap<Ctx, Ctx>();
316
+
317
+ /** The context `ctx` was derived inside (`withChildContext`, `runToCompletion`), or `undefined`. */
318
+ export function parentContext(ctx: Ctx): Ctx | undefined {
319
+ return parents.get(ctx);
320
+ }
321
+
310
322
  /**
311
323
  * The one build of a child context, narrowing (`withChildContext`) or not (`runToCompletion`): the
312
324
  * caller decides the two members that say how long this work may run, everything else is the rule.
@@ -323,7 +335,7 @@ function derivedContext(
323
335
  const carried = Object.fromEntries(
324
336
  Object.entries(parent.services).filter(([name]) => !isManagedService(name)),
325
337
  );
326
- return ctxOf({
338
+ const child = ctxOf({
327
339
  requestId: parent.requestId,
328
340
  traceId: patch.traceId ?? parent.traceId,
329
341
  actor: patch.actor ?? parent.actor,
@@ -337,6 +349,8 @@ function derivedContext(
337
349
  signal: lifetime.signal,
338
350
  services: { ...carried, ...(patch.services ?? {}) },
339
351
  });
352
+ parents.set(child, parent);
353
+ return child;
340
354
  }
341
355
 
342
356
  /**
package/src/index.ts CHANGED
@@ -255,6 +255,7 @@ export {
255
255
  abandonment,
256
256
  ctxOf,
257
257
  hasContext,
258
+ parentContext,
258
259
  runToCompletion,
259
260
  runWithContext,
260
261
  throwIfAborted,