@ultimat3/core 31.4.0 → 31.4.1

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/CLAUDE.md CHANGED
@@ -20,7 +20,7 @@ change to every package. A row or rule marked `†` has its full text in
20
20
  | Time | take a `Clock` (a `SleepClock` to wait); `Date.now()` / `new Date()` only in `clock.ts`; a waiting timer only in `sleep-clock.ts` |
21
21
  | Context | never thread `ctx` as a parameter — `useContext()` |
22
22
  | A value ambient across an `await` | `asyncContext<T>(subject)` from `async-context.ts`, in **every** package — never `new AsyncLocalStorage` |
23
- | Exports | explicit in `src/index.ts`; no `export *`. Six public subpaths (`./adapter`, `./page`, `./outbound`, `./redis`, `./render-node`, `./render-nodes`), one internal (`./internal/error-status`); nothing that constructs an error joins `./page` (`page-bundle.test.ts`) † |
23
+ | Exports | explicit in `src/index.ts`; no `export *`. Six public subpaths (`./adapter`, `./page`, `./outbound`, `./redis`, `./render-node`, `./render-nodes`), one internal (`./internal/error-status`); nothing that loads a titles table joins `./page` (`page-bundle.test.ts`); an app imports `defineError` there (`define-error-bytes.test.ts`) † |
24
24
  | Files | < 200 LOC, 500 hard ceiling, one responsibility, `kebab-case.ts`, test beside source |
25
25
  | Type claims | `type-pins.ts`, never a `.test.ts` — `tsconfig.json` excludes tests |
26
26
 
package/README.md CHANGED
@@ -173,10 +173,13 @@ Registering a code twice throws `X_ERROR_CODE_DUPLICATE`.
173
173
  ### An app's own codes: `defineError`
174
174
 
175
175
  A framework package registers codes as above, through `bun run new-error-code`. An APP declares
176
- each of its codes once, and gets the class back:
176
+ each of its codes once, and gets the class back. Import it from `@ultimat3/core/page`: an errors
177
+ module is shared by actions and islands, and any barrel import carries both titles tables into
178
+ every island that throws (12,019 B against 6,507 B for one declaration thrown,
179
+ `define-error-bytes.test.ts`):
177
180
 
178
181
  ```ts
179
- import { defineError } from '@ultimat3/core';
182
+ import { defineError } from '@ultimat3/core/page';
180
183
 
181
184
  export const PostNotFound = defineError<{ readonly ref: string }>({
182
185
  code: 'X_POST_NOT_FOUND',
@@ -199,7 +202,8 @@ is `X_ERROR_DECLARATION_INVALID`. A code some package already registered — a f
199
202
  under its own title or not — is `X_ERROR_CODE_DUPLICATE`: its status is not the app's to give. The
200
203
  table itself is INTERNAL (`@ultimat3/core/internal/error-status`, read by `@ultimat3/http`): an app
201
204
  declares through `defineError`, and a re-raised library code through `registerErrorStatus`. A
202
- scaffolded app's `guards/error-declared.ts` refuses a handwritten `UltimateError` subclass.
205
+ scaffolded app's `guards/error-declared.ts` refuses a handwritten `UltimateError` subclass and a
206
+ `defineError` imported from the barrel.
203
207
 
204
208
  `isUltimateError()` is duck-typed on `Symbol.for('ultimate.error')`, not `instanceof` — that is
205
209
  how `@ultimat3/schema` (tier 0, cannot import core) still produces matching errors.
@@ -887,7 +891,7 @@ A refusal is Bun's `ERR_REDIS_CONNECTION_CLOSED`, untyped here: the job driver t
887
891
  | Export | The one answer | The question it settles |
888
892
  |---|---|---|
889
893
  | `clientTransport({ method, url, body?, rawBody?, headers?, signal?, idempotencyKey?, flight?, fresh?, retry?, responseType?, onResponse?, decodeError?, onEnvelope?, fetchImpl? })` | every browser request | `credentials: 'same-origin'`, JSON in and out, the `idempotency-key` header, a non-2xx `problem+json` back into the server's code (`meta.origin: 'remote'`) unless `decodeError` answers first, a network `TypeError` into `X_CLIENT_TRANSPORT_FAILED`. A GET is abortable on `rescope()` and deduped only when a `flight` is passed (`fresh` refuses to join); any other method is never deduped and never aborted by the fence. `rawBody` goes out verbatim with no default header and resolves `undefined` (the body as a string with `responseType: 'text'`). `responseType: 'text'` resolves a 2xx body as a string (typed `Promise<string>`), sends `accept: */*` unless `headers` names one, and adopts no envelope — for an HTML fragment or a CSV; a non-2xx is still decoded as a refusal. About 10.7 kB minified (4.6 kB gzipped) through `@ultimat3/core/page`, no titles table — pinned in `page-bundle.test.ts`. `onResponse` sees headers before the body is read. `onEnvelope` sees the decoded records envelope after adoption — the one way to learn the order of `records[type]`. `fetchImpl` defaults to `globalThis.fetch`, read at call time |
890
- | `@ultimat3/core/page` — what a typed client reads, never the barrel: `clientTransport`, `clientStream`, `clientFlight` (+ types `ClientFlight`, `ClientFlightOptions`, `ClientRetry`, `ActionPathStyle`), `BUILD_ID_HEADER`, `IDEMPOTENCY_HEADER`, `FRAMEWORK_CODE`, `problemOf`, `remoteTitleOf`, `retryForStatus`, `withRequestId`, `withStatedDelay`, `registerErrorCodes`, `registerErrorRetry`, `hasErrorCode`, `ERROR_DOCS_URL`, `deniedCallerFix`, `renderCauseValue` beside the page handle, fence and names | the one light browser entry | no titles table, no `node:` module, no build warning (`page-bundle.test.ts`). The whole entry is 32,269 B minified; an island pays only what it imports — `@ultimat3/action`'s `rpc` 24,473 B, + `clientFlight` 32,929 B (`client-bundle.test.ts`). Every name is on the barrel too |
894
+ | `@ultimat3/core/page` — what a typed client reads, never the barrel: `clientTransport`, `clientStream`, `clientFlight` (+ types `ClientFlight`, `ClientFlightOptions`, `ClientRetry`, `ActionPathStyle`), `BUILD_ID_HEADER`, `IDEMPOTENCY_HEADER`, `FRAMEWORK_CODE`, `problemOf`, `remoteTitleOf`, `retryForStatus`, `withRequestId`, `withStatedDelay`, `registerErrorCodes`, `registerErrorRetry`, `hasErrorCode`, `ERROR_DOCS_URL`, `deniedCallerFix`, `renderCauseValue`, `defineError` (+ types `DefineErrorSpec`, `DefinedError`, `DefinedErrorExtra`) beside the page handle, fence and names | the one light browser entry, and where an app imports `defineError` | no titles table, no `node:` module, no build warning (`page-bundle.test.ts`). The whole entry is 35,150 B minified; an island pays only what it imports — `@ultimat3/action`'s `rpc` 24,473 B, + `clientFlight` 32,929 B (`client-bundle.test.ts`). Every name is on the barrel too |
891
895
  | `actionPath(name)`, `actionRoute(name)`, `queryPath(name)`, `QUERY_PATH_PREFIX`, `splitWords`, `pluralize` | the one URL rule | `publishPost` → `/api/posts/publish`, `liveFeed` → `/_x/query/live-feed`. Tier 0 so `action`, `query` and `realtime` derive one URL with no sideways import |
892
896
  | `templateParams`, `fillTemplate`, `pathTemplateProblem`, `templateKeyProblem`, `toOpenApiPath` (`route-path-template.ts`; the first two also on `./page`) · `mergePathParams`, `HttpPathInputConflictError` (`route-path-merge.ts`) | the one `http.path` template rule | an action's and a query's pin (`/orders/:id/refund`): lowercase static segments and `:param`s, each a required string input key; filled with each value one encoded segment; `{id}` in OpenAPI; the URL's values merged into the input, a disagreeing key `X_HTTP_PATH_INPUT_CONFLICT` (400). Tier 0 because `action` and `query` share a tier |
893
897
  | `actionPath(name)` with no `style`, `renderedActionPathStyle()`, `CLIENT_PATH_STYLE_META` | the style nobody restates | `actionPath(name)` reads the document's `<meta name="ultimate-path-style">` stamp, so a browser caller derives under the style the server serves (`defineApi({ http: { pathStyle } })`). No document, no stamp or an unknown value is `'resource'` — a `'resource'` server writes no stamp. A named `style` is never overridden |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ultimat3/core",
3
- "version": "31.4.0",
3
+ "version": "31.4.1",
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.4.0"
57
+ "@ultimat3/schema": "31.4.1"
58
58
  }
59
59
  }
@@ -1,7 +1,7 @@
1
1
  // Single responsibility: `defineError` — an APP code's one declaration: its title, its HTTP status
2
2
  // (or `offSocket`), its retry, and the `UltimateError` subclass that throws it. Its own module so a
3
- // chunk importing only `UltimateError` never retains it (`define-error-bytes.test.ts`). A framework
4
- // code goes through `bun run new-error-code` instead; the split is in this package's CLAUDE.md.
3
+ // chunk importing only `UltimateError` never retains it; on `./page` so an island throwing an app
4
+ // code carries no titles table (`define-error-bytes.test.ts`). Framework codes: `new-error-code`.
5
5
 
6
6
  import { describeErrorCode, hasErrorCode, registerErrorCodes } from './error-codes';
7
7
  import { renderCauseValue } from './error-render';
@@ -94,7 +94,9 @@ const DECLARED_AT = new Map<string, string>();
94
94
  export const definedErrorSites = (): ReadonlyMap<string, string> => DECLARED_AT;
95
95
 
96
96
  function recordSite(code: string): void {
97
- if (DECLARED_AT.has(code)) return;
97
+ // A browser island declares at load too, and Firefox before 136 has no `captureStackTrace`: the
98
+ // site is a test-time scan's input, never worth an island that dies evaluating its errors module.
99
+ if (DECLARED_AT.has(code) || typeof Error.captureStackTrace !== 'function') return;
98
100
  const holder: { stack?: string } = {};
99
101
  Error.captureStackTrace(holder, defineError);
100
102
  const frame = holder.stack?.split('\n')[1];
package/src/page.ts CHANGED
@@ -38,6 +38,11 @@ export type { ConflictPolicy, Row } from './conflict-policy';
38
38
  // Registry-free: it merges two rows and throws nothing, so the page's record store settles a
39
39
  // write under a conflict policy without loading the error table.
40
40
  export { resolveConflict } from './conflict-policy';
41
+ // An app's error module is shared by its actions and its islands: declared from here, an island
42
+ // that throws one code carries the class and the declaration, never the barrel's titles tables
43
+ // (`define-error-bytes.test.ts`). The app's `error-declared` guard refuses the barrel import.
44
+ export type { DefinedError, DefinedErrorExtra, DefineErrorSpec } from './define-error';
45
+ export { defineError } from './define-error';
41
46
  // The registry's one writer, for a package that titles its OWN codes in a browser chunk
42
47
  // (`@ultimat3/realtime`'s `error-titles.ts`). A function, not a table: `errors.ts` already retains
43
48
  // `error-codes.ts`, so this adds no module — and through the barrel it cost both anchored tables.