@ultimat3/core 31.26.0 → 31.27.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ultimat3/core",
3
- "version": "31.26.0",
3
+ "version": "31.27.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.26.0"
57
+ "@ultimat3/schema": "31.27.0"
58
58
  }
59
59
  }
@@ -53,7 +53,7 @@ export const FRAMEWORK_ENV: readonly FrameworkEnvName[] = [
53
53
  ...contract('cli', 'APP_URL', 'SITE_ORIGIN', 'SYNC_URL', 'HOST', 'PORT', 'METRICS_PORT'),
54
54
  ...contract('cli', 'NODE_ENV', 'TRUSTED_PROXY_HOPS', 'WORKER_QUEUES', 'SENTRY_DSN'),
55
55
  ...contract('cli', 'S3_ENDPOINT', 'S3_BUCKET', 'S3_REGION', 'S3_FORCE_PATH_STYLE'),
56
- ...contract('cli', 'SCRAPE_CDP_URL'),
56
+ ...contract('cli', 'SCRAPE_CDP_URL', 'TLS_CERT', 'TLS_KEY'),
57
57
  ...toggles('cli', 'OTEL_SDK_DISABLED'),
58
58
  ...internal('cli', 'ULTIMATE_SEED_TIER', 'ULTIMATE_STATE_DIR', 'ULTIMATE_BUILD_CAPTURE'),
59
59
  ...internal('cli', 'ULTIMATE_DEV_CHILD', 'ULTIMATE_DEV_SUPERVISOR_PID', 'X_ENV'),
@@ -10,19 +10,45 @@
10
10
  import { asyncContext } from './async-context';
11
11
  import type { FetchLike } from './client-dispatch';
12
12
 
13
- const scope = asyncContext<FetchLike>('the in-process dispatch');
13
+ /** The scope: who answers, and which urls are its to answer (every one, when unsaid). */
14
+ interface InProcess {
15
+ readonly fetchImpl: FetchLike;
16
+ readonly owns?: ((url: string) => boolean) | undefined;
17
+ }
18
+
19
+ const scope = asyncContext<InProcess>('the in-process dispatch');
14
20
 
15
21
  const INSTALLED: unique symbol = Symbol.for('ultimate.in-process-fetch');
16
22
 
23
+ /**
24
+ * A `Request` object as the dispatcher's `(url, init)`: its method, headers and body carried, with
25
+ * `init` laid over it as `fetch` itself would — a bare `init ?? {}` sent a POST as a bodyless GET.
26
+ */
27
+ async function asInit(input: Request, init: RequestInit | undefined): Promise<RequestInit> {
28
+ const request = init === undefined ? input : new Request(input, init);
29
+ const bodyless = request.method === 'GET' || request.method === 'HEAD';
30
+ return {
31
+ method: request.method,
32
+ headers: request.headers,
33
+ redirect: request.redirect,
34
+ signal: request.signal,
35
+ ...(bodyless ? {} : { body: await request.arrayBuffer() }),
36
+ };
37
+ }
38
+
17
39
  /** Wrap `globalThis.fetch` once per process; a re-wrap after someone replaced it wraps theirs. */
18
40
  function install(): void {
19
41
  const current = globalThis.fetch as typeof fetch & { [INSTALLED]?: true };
20
42
  if (current[INSTALLED] === true) return;
21
- const wrapped = (input: RequestInfo | URL, init?: RequestInit): Promise<Response> => {
43
+ const wrapped = async (input: RequestInfo | URL, init?: RequestInit): Promise<Response> => {
22
44
  const inProcess = scope.get();
23
45
  if (inProcess === undefined) return current(input, init);
24
46
  const url = typeof input === 'string' ? input : input instanceof URL ? input.href : input.url;
25
- return inProcess(url, init ?? {});
47
+ // A url the scope does not own — another host — goes where it would have gone without one.
48
+ if (inProcess.owns !== undefined && !inProcess.owns(url)) return current(input, init);
49
+ if (typeof input === 'string' || input instanceof URL)
50
+ return inProcess.fetchImpl(url, init ?? {});
51
+ return inProcess.fetchImpl(url, await asInit(input, init));
26
52
  };
27
53
  globalThis.fetch = Object.assign(wrapped, current, { [INSTALLED]: true as const });
28
54
  }
@@ -30,10 +56,15 @@ function install(): void {
30
56
  /**
31
57
  * Run `fn` with every `fetch` inside it — so every `clientTransport` call, `queryClient()` and
32
58
  * `rpc()` included — answered by `fetchImpl`: the app's own HTTP pipeline handed a `Request`,
33
- * rather than the network. A caller's explicit `fetchImpl` never reaches `globalThis.fetch` at all,
34
- * so a test's double is never overridden by an ambient scope.
59
+ * rather than the network. `owns` narrows that to the urls it answers true for (the app's own
60
+ * origin); the rest reach the fetch this wrapped. A caller's explicit `fetchImpl` never reaches
61
+ * `globalThis.fetch` at all, so a test's double is never overridden by an ambient scope.
35
62
  */
36
- export function withInProcessFetch<T>(fetchImpl: FetchLike, fn: () => T): T {
63
+ export function withInProcessFetch<T>(
64
+ fetchImpl: FetchLike,
65
+ fn: () => T,
66
+ owns?: (url: string) => boolean,
67
+ ): T {
37
68
  install();
38
- return scope.run(fetchImpl, fn);
69
+ return scope.run({ fetchImpl, owns }, fn);
39
70
  }
@@ -43,6 +43,16 @@ export async function mapBounded<T, R>(
43
43
  fn: (item: T, index: number, signal: AbortSignal) => R | Promise<R>,
44
44
  options: MapBoundedOptions & { readonly settle?: 'first' | undefined },
45
45
  ): Promise<R[]>;
46
+ /**
47
+ * A value typed `MapBoundedOptions` itself — the 31.23 call shape, before `settle` split the
48
+ * overloads. Its `settle` is not known statically, so neither answer is: narrow with
49
+ * `settle: 'first'` or `'all'` at the call for an exact result type.
50
+ */
51
+ export async function mapBounded<T, R>(
52
+ items: readonly T[],
53
+ fn: (item: T, index: number, signal: AbortSignal) => R | Promise<R>,
54
+ options: MapBoundedOptions,
55
+ ): Promise<R[] | PromiseSettledResult<R>[]>;
46
56
  export async function mapBounded<T, R>(
47
57
  items: readonly T[],
48
58
  fn: (item: T, index: number, signal: AbortSignal) => R | Promise<R>,