@ultimat3/action 31.55.0 → 31.57.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
@@ -386,8 +386,8 @@ no `.def`. A second authz path cannot be written without deleting that store.
386
386
  | parse output | `X_OUTPUT_INVALID` — and fields the schema never declared are dropped |
387
387
 
388
388
  **Who before what (`As of 2026-09`).** The actor half is the part of the policy that reads no
389
- input: `can(p)` with no predicate, `allow()`, `deny()`, their combinators, and `can(p, pred)` for
390
- an actor without `p`. It is decided before the parse — `decideBeforeInput` in `@ultimat3/policy`,
389
+ input: `can(p)` with no predicate, `canActor(p, pred)` (a predicate typed to read only the actor),
390
+ `allow()`, `deny()`, their combinators, and `can(p, pred)` for an actor without `p`. It is decided before the parse — `decideBeforeInput` in `@ultimat3/policy`,
391
391
  exact rather than a heuristic — so `can('refund:issue')` answers a customer's `{}` with 403, and a
392
392
  staff caller's `{}` with the 400 naming each missing field. A predicate over `input` or `row` still
393
393
  runs after the parse, on the parsed value. Same on HTTP, MCP (including the `invalid-args`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ultimat3/action",
3
- "version": "31.55.0",
3
+ "version": "31.57.0",
4
4
  "description": "The action primitive: one declaration projected to route, OpenAPI, client, MCP tool, job handle, tests",
5
5
  "keywords": [
6
6
  "ultimate",
@@ -48,13 +48,13 @@
48
48
  "test": "bun test"
49
49
  },
50
50
  "dependencies": {
51
- "@ultimat3/cache": "31.55.0",
52
- "@ultimat3/core": "31.55.0",
53
- "@ultimat3/db": "31.55.0",
54
- "@ultimat3/entity": "31.55.0",
55
- "@ultimat3/http": "31.55.0",
56
- "@ultimat3/policy": "31.55.0",
57
- "@ultimat3/schema": "31.55.0",
58
- "@ultimat3/storage": "31.55.0"
51
+ "@ultimat3/cache": "31.57.0",
52
+ "@ultimat3/core": "31.57.0",
53
+ "@ultimat3/db": "31.57.0",
54
+ "@ultimat3/entity": "31.57.0",
55
+ "@ultimat3/http": "31.57.0",
56
+ "@ultimat3/policy": "31.57.0",
57
+ "@ultimat3/schema": "31.57.0",
58
+ "@ultimat3/storage": "31.57.0"
59
59
  }
60
60
  }
@@ -1,5 +1,5 @@
1
1
  // The declaration `action()` types a handler by: `ActionDef` whose `handle` is handed
2
- // `decide(rows)`. A pair beside `ActionDef`, never an edit of it: `ActionDef.handle` is also what
2
+ // `decide(rows)` and the caller's `idempotencyKey`. A pair beside `ActionDef`, never an edit of it: `ActionDef.handle` is also what
3
3
  // app code CALLS on a declaration it holds, and a required `decide` there refuses a call written
4
4
  // before it existed. `action()` reads these first; `ActionDef` stays assignable to them.
5
5
 
@@ -18,6 +18,16 @@ export interface ActionDecideArgs<TInput extends StandardSchemaV1, TRow = unknow
18
18
  * assignable to the erased declaration every projection reads.
19
19
  */
20
20
  decide(rows: readonly TRow[]): ActionDecision<TRow>;
21
+ /**
22
+ * The `Idempotency-Key` the caller sent, as sent — never the namespaced store key. `null` when
23
+ * none was sent or the action is not `idempotent: true`. A handler whose answer must not rest
24
+ * under a key (a dry run a later real call would replay) refuses on it. Here, not on `Ctx`:
25
+ * `Ctx` is core's, shared by every primitive, and only an action call carries the key.
26
+ * Optional in the TYPE only, so code that builds these arguments by hand (a test calling
27
+ * `def.handle({ input, ctx, decide })`) still compiles on a minor; every call hands it in, so
28
+ * read it as `idempotencyKey != null`.
29
+ */
30
+ readonly idempotencyKey?: string | null;
21
31
  }
22
32
 
23
33
  /** What `action({ … })` takes: `ActionDef`, its `handle` handed `decide`. */
@@ -53,6 +53,16 @@ export type _StreamDefIsADecidingDef = Assert<
53
53
  type Decide = Parameters<DecidingActionDef<In, Out, Post>['handle']>[0]['decide'];
54
54
  export type _DecideTakesRowsAlone = Assert<Identical<Parameters<Decide>, [rows: readonly Post[]]>>;
55
55
  export type _DecideAnswersTheRows = Assert<Identical<ReturnType<Decide>, ActionDecision<Post>>>;
56
- export type _DecideArgsAreTheRecordedOnesPlusDecide = Assert<
57
- Identical<Exclude<keyof ActionDecideArgs<In, Post>, keyof RecordedArgs>, 'decide'>
56
+ export type _DecideArgsAreTheRecordedOnesPlusDecideAndKey = Assert<
57
+ Identical<
58
+ Exclude<keyof ActionDecideArgs<In, Post>, keyof RecordedArgs>,
59
+ 'decide' | 'idempotencyKey'
60
+ >
61
+ >;
62
+ /**
63
+ * The caller's key as sent, or `null`. Optional in the type, so a hand-built argument object from
64
+ * before it existed still compiles: added on a minor, the stable line's promise (wiki/Stability).
65
+ */
66
+ export type _HandlerKeyIsStringOrNull = Assert<
67
+ Identical<ActionDecideArgs<In, Post>['idempotencyKey'], string | null | undefined>
58
68
  >;
package/src/action.ts CHANGED
@@ -269,6 +269,7 @@ export interface AnyActionDef {
269
269
  readonly input: unknown;
270
270
  readonly ctx: Ctx;
271
271
  decide(rows: readonly unknown[]): ActionDecision<unknown>;
272
+ readonly idempotencyKey: string | null;
272
273
  }): unknown;
273
274
  }
274
275
 
package/src/invoke.ts CHANGED
@@ -384,7 +384,7 @@ async function perform(
384
384
  const override = drainsItsHandler(def) ? undefined : handlerOverrideOf(def);
385
385
  const handle = override ?? def.handle.bind(def);
386
386
  const produced = await judgedHandler(def, name, () =>
387
- handle({ input, ctx: useContext(), decide }),
387
+ handle({ input, ctx: useContext(), decide, idempotencyKey: key }),
388
388
  );
389
389
  return validateOutput(def.output, produced, name);
390
390
  };