pipework 0.243.0 → 0.245.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.
Files changed (39) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/REFERENCE.md +16 -472
  3. package/dist/core/config/namespace.d.ts +1 -0
  4. package/dist/core/config/namespace.d.ts.map +1 -1
  5. package/dist/core/config/schema.d.ts +2 -0
  6. package/dist/core/config/schema.d.ts.map +1 -1
  7. package/dist/core/config/schema.js +1 -0
  8. package/dist/core/config/schema.js.map +1 -1
  9. package/dist/infra/alerts/handle.d.ts.map +1 -1
  10. package/dist/infra/alerts/handle.js +11 -10
  11. package/dist/infra/alerts/handle.js.map +1 -1
  12. package/dist/infra/email/sigv4.d.ts +24 -0
  13. package/dist/infra/email/sigv4.d.ts.map +1 -0
  14. package/dist/infra/email/sigv4.js +55 -0
  15. package/dist/infra/email/sigv4.js.map +1 -0
  16. package/dist/test/auto-setup.js +2 -2
  17. package/dist/test/auto-setup.js.map +1 -1
  18. package/dist/test/index.d.ts +1 -0
  19. package/dist/test/index.d.ts.map +1 -1
  20. package/dist/test/index.js +1 -0
  21. package/dist/test/index.js.map +1 -1
  22. package/dist/test/plugin.d.ts +6 -1
  23. package/dist/test/plugin.d.ts.map +1 -1
  24. package/dist/test/plugin.js +12 -1
  25. package/dist/test/plugin.js.map +1 -1
  26. package/dist/test/reset.d.ts +35 -0
  27. package/dist/test/reset.d.ts.map +1 -0
  28. package/dist/test/reset.js +179 -0
  29. package/dist/test/reset.js.map +1 -0
  30. package/dist/test/setup.d.ts.map +1 -1
  31. package/dist/test/setup.js +78 -5
  32. package/dist/test/setup.js.map +1 -1
  33. package/dist/test/vitest.js +2 -2
  34. package/dist/test/vitest.js.map +1 -1
  35. package/dist/test/watch.d.ts +21 -0
  36. package/dist/test/watch.d.ts.map +1 -0
  37. package/dist/test/watch.js +81 -0
  38. package/dist/test/watch.js.map +1 -0
  39. package/package.json +1 -1
package/dist/REFERENCE.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Pipework API Reference
2
2
 
3
3
  > Auto-generated from source JSDoc. Do not edit manually.
4
- > Generated: 2026-10-25
4
+ > Generated: 2026-10-09
5
5
 
6
6
  ## Contents
7
7
 
@@ -10,7 +10,6 @@
10
10
  - [jobs — Background Jobs](#jobs-background-jobs)
11
11
  - [pipeline — Multi-Step Pipelines](#pipeline-multi-step-pipelines)
12
12
  - [state — State Machines](#state-state-machines)
13
- - [steps](#steps)
14
13
  - [auth — Authentication](#auth-authentication)
15
14
  - [rbac — Access Control](#rbac-access-control)
16
15
  - [tenant — Multi-Tenancy](#tenant-multi-tenancy)
@@ -31,10 +30,7 @@
31
30
  - [cache — Caching](#cache-caching)
32
31
  - [credits](#credits)
33
32
  - [mail](#mail)
34
- - [untrustedFetch](#untrustedfetch)
35
- - [quota](#quota)
36
33
  - [storage](#storage)
37
- - [support](#support)
38
34
  - [webhook — Inbound & Outbound Webhooks](#webhook-inbound-outbound-webhooks)
39
35
  - [behavior — Resource Decorators](#behavior-resource-decorators)
40
36
  - [fitting — Dependency Injection](#fitting-dependency-injection)
@@ -46,7 +42,6 @@
46
42
  - [trace](#trace)
47
43
  - [data](#data)
48
44
  - [request](#request)
49
- - [async](#async)
50
45
 
51
46
  ## Core
52
47
 
@@ -79,7 +74,7 @@ export default manifold
79
74
  ```
80
75
 
81
76
  ```typescript
82
- function createManifold<const TEnv extends EnvDefs = EnvDefs>( raw: AcceptReadonly<Omit<BlueprintInput, 'env'>> &
77
+ function createManifold<const TEnv extends EnvDefs = EnvDefs>( raw: Omit<BlueprintInput, 'env'> &
83
78
  ```
84
79
 
85
80
  ### Types
@@ -90,24 +85,6 @@ function createManifold<const TEnv extends EnvDefs = EnvDefs>( raw: AcceptReadon
90
85
  interface Manifold<TEnv extends EnvDefs = EnvDefs>
91
86
  ```
92
87
 
93
- **`StopResult`** — What {@link Manifold.stop} resolves with: `forced` is true when the drain deadline fired.
94
-
95
- ```typescript
96
- interface StopResult
97
- ```
98
-
99
- **`ScriptOptions`** — Options for {@link Manifold.script}.
100
-
101
- ```typescript
102
- interface ScriptOptions
103
- ```
104
-
105
- **`StartOptions`** — Options for {@link Manifold.start}.
106
-
107
- ```typescript
108
- interface StartOptions
109
- ```
110
-
111
88
  **`SeedOptions`** — ALS context the {@link Manifold.seed} callback runs under — tenant scope, auth principal, and job type.
112
89
 
113
90
  ```typescript
@@ -252,14 +229,6 @@ Creates a job queue with claim/complete/fail lifecycle, heartbeat, and dead lett
252
229
 
253
230
  Executes a fitting handler as a background job with its own Flow context.
254
231
 
255
- ### `jobs.later`
256
-
257
- The error to throw to end an attempt as "later": pending again after `delayMs`, no attempt counted.
258
-
259
- ### `jobs.permanent`
260
-
261
- The error to throw to dead-letter the job now, whatever attempts remain.
262
-
263
232
  ### `jobs.parseCron`
264
233
 
265
234
  Parses a 5-field cron expression into a CronSchedule (minute, hour, dom, month, dow).
@@ -300,14 +269,6 @@ Thrown when a transition is not allowed from the current state.
300
269
 
301
270
  Thrown when the state machine definition is internally inconsistent.
302
271
 
303
- ## steps
304
-
305
- Step graphs over a job queue: results recorded by their inputs, only missing steps run.
306
-
307
- ### `steps.define`
308
-
309
- Defines a graph of named steps over a jobs Queue. Pass it to `createWorkerSurface({ graphs })` to run its steps.
310
-
311
272
  ## auth — Authentication
312
273
 
313
274
  Authentication namespace — session management, multi-org support, auth chain resolution.
@@ -328,14 +289,6 @@ Hashes and verifies passwords with scrypt; reports when a stored hash needs reha
328
289
 
329
290
  Guarded password sign-in that slows, then refuses, repeated failures per account and per client.
330
291
 
331
- ### `auth.guard`
332
-
333
- Guards wrong guesses at a secret the app checks itself: counted per key set before the check, reset on a right answer, refused with retryAfterSeconds.
334
-
335
- ### `auth.emailLinks`
336
-
337
- Emailed single-use links that prove control of an address: password reset and address verification; the token is never stored.
338
-
339
292
  ### `auth.runChain`
340
293
 
341
294
  Executes an auth chain (strategy pipeline) to resolve auth + tenant from a request.
@@ -370,7 +323,7 @@ interface AuthContext
370
323
  interface AuthStrategy<TAuth>
371
324
  ```
372
325
 
373
- **`AuthRequest`** — Normalized request shape passed to auth strategies — headers, the parsed `Cookie` header, and the upper-case HTTP method.
326
+ **`AuthRequest`** — Normalized request shape passed to auth strategies — headers, cookies, method, url.
374
327
 
375
328
  ```typescript
376
329
  interface AuthRequest
@@ -400,18 +353,6 @@ interface TenantResolver<TAuth>
400
353
  interface AuthChainConfig<TAuth>
401
354
  ```
402
355
 
403
- **`SessionAuth`** — What `sessions.strategy()` authenticates: the token's user and org, its roles, and where the token came from.
404
-
405
- ```typescript
406
- type SessionAuth = BaseAuth &
407
- ```
408
-
409
- **`SessionStrategyOptions`** — Options for `sessions.strategy()`.
410
-
411
- ```typescript
412
- interface SessionStrategyOptions
413
- ```
414
-
415
356
  **`SessionConfig`** — Session configuration — signing keys, issuer, audience, token TTLs, refresh rotation.
416
357
 
417
358
  ```typescript
@@ -683,18 +624,6 @@ Base error class with code, statusCode, and suggestion fields.
683
624
 
684
625
  403 — authenticated but insufficient permissions.
685
626
 
686
- ### `errors.CrossSiteRequest`
687
-
688
- 403 `CROSS_SITE_REQUEST` — a cookie-authenticated request that did not come from the app's own site.
689
-
690
- ### `errors.AuthConfiguration`
691
-
692
- 500 `AUTH_CONFIGURATION` — the auth setup itself is faulty (a signing key that will not load); never a refusal of the caller.
693
-
694
- ### `errors.AuthUnavailable`
695
-
696
- 503 `AUTH_UNAVAILABLE` — authentication could not be decided (its database failed); never read as signed out.
697
-
698
627
  ### `errors.Validation`
699
628
 
700
629
  422 — input validation failed, carries field-level details.
@@ -715,17 +644,13 @@ Base error class with code, statusCode, and suggestion fields.
715
644
 
716
645
  415 — request body media type not accepted by the route.
717
646
 
718
- ### `errors.MalformedMultipart`
719
-
720
- 400 `MALFORMED_MULTIPART` — a multipart body that cannot be parsed or ends before its closing boundary.
721
-
722
647
  ## lifecycle — Startup & Shutdown
723
648
 
724
649
  Application lifecycle namespace — startup orchestration with hooks and timeouts.
725
650
 
726
651
  ### `lifecycle.orchestrate`
727
652
 
728
- Runs pre-start hooks (DB readiness checks, migrations, etc.) with a configurable timeout. The hooks run in one trace that names the process; the trace-partition hook runs first, outside it.
653
+ Runs pre-start hooks (DB readiness checks, migrations, etc.) with a configurable timeout.
729
654
 
730
655
  ## log — Structured Logging
731
656
 
@@ -765,7 +690,7 @@ Creates a worker surface — a long-running process that claims and executes job
765
690
 
766
691
  ### `surface.script`
767
692
 
768
- Creates a script surface — a one-shot process that runs and exits (migrations, seeds, CLI tools). The run is traced as a job-kind trace that names the surface.
693
+ Creates a script surface — a one-shot process that runs and exits (migrations, seeds, CLI tools).
769
694
 
770
695
  ## pipe — Database
771
696
 
@@ -775,10 +700,6 @@ Database accessor — returns a Drizzle DB instance scoped to the current reques
775
700
 
776
701
  The system channel — deliberate cross-tenant access for pre-tenant surfaces (auth membership resolution, public webhook ingress, admin tooling). Never tenant-scoped or tenant-guarded; runs on the owner-role connection outside the request transaction.
777
702
 
778
- ### `pipe.door`
779
-
780
- A named cross-tenant read: `pipe.door(name, db => ...)`. The door is declared under `doors` in config; the callback runs in one transaction on the platform-role connection and may SELECT from the door's table and from non-tenant tables. Needs `rls.platformRole`.
781
-
782
703
  ### `pipe.filter`
783
704
 
784
705
  Query operators and aggregates — eq, gt, lt, and, or, count, sum, etc.
@@ -836,18 +757,10 @@ Returns excluded-column references for onConflictDoUpdate set clauses.
836
757
 
837
758
  Acquires a transaction-scoped advisory lock. Released at commit/rollback.
838
759
 
839
- ### `pipe.tryAdvisoryLock`
840
-
841
- Non-blocking advisoryLock: true if the transaction-scoped lock was won, false if another transaction holds it.
842
-
843
760
  ### `pipe.serializable`
844
761
 
845
762
  Runs a function in a SERIALIZABLE transaction with automatic retry on serialization failures and deadlocks.
846
763
 
847
- ### `pipe.withTimeouts`
848
-
849
- Sets statement_timeout and/or lock_timeout for the current transaction in one statement, then runs fn; a statement cancelled for them rejects with StatementTimeoutError or LockTimeoutError.
850
-
851
764
  ### `pipe.bulkSet`
852
765
 
853
766
  Bulk UPDATE ... FROM (VALUES ...) — updates multiple rows with per-row values in a single statement.
@@ -856,10 +769,6 @@ Bulk UPDATE ... FROM (VALUES ...) — updates multiple rows with per-row values
856
769
 
857
770
  Produces a typed VALUES clause for bulk operations — the base primitive for bulkSet and bulkUpsert.
858
771
 
859
- ### `pipe.fn`
860
-
861
- A set-returning SQL function as a typed source for `.from()` and joins — `pipe.fn('schema.f', { args: [field.uuid()], columns: { path: field.text() } })`. Arguments are bound and cast to their declared types.
862
-
863
772
  ### `pipe.field`
864
773
 
865
774
  Field builders for domain definitions — uuid(), text(), integer(), etc.
@@ -872,17 +781,13 @@ Registers a domain definition with table, validators, and factory projections. T
872
781
 
873
782
  Returns the global registry of all domain definitions.
874
783
 
875
- ### `pipe.external`
876
-
877
- Declares a table or view another service owns (`pipe.external(name, fields, { schema, table? })`): typed columns and every query operator, read-only, never migrated, not tenant-scoped.
878
-
879
784
  ### `pipe.update`
880
785
 
881
786
  Pipework-owned UPDATE builder — the only consumer-facing way to update pipework-managed tables (Q8).
882
787
 
883
788
  ### `pipe.insert`
884
789
 
885
- Pipework-owned INSERT builder — the only consumer-facing way to insert into pipework-managed tables (Q8). A list of any size is split into statements under Postgres's parameter limit, in one transaction.
790
+ Pipework-owned INSERT builder — the only consumer-facing way to insert into pipework-managed tables (Q8).
886
791
 
887
792
  ### `pipe.delete`
888
793
 
@@ -890,7 +795,7 @@ Pipework-owned DELETE builder — the only consumer-facing way to delete from pi
890
795
 
891
796
  ### `pipe.upsert`
892
797
 
893
- Pipework-owned UPSERT builder — insert with conflict resolution (Q8). A list of any size is split into statements under Postgres's parameter limit, in one transaction; rows repeating a conflict key across statements do not fail as one statement would.
798
+ Pipework-owned UPSERT builder — insert with conflict resolution (Q8).
894
799
 
895
800
  ### Types
896
801
 
@@ -900,107 +805,25 @@ Pipework-owned UPSERT builder — insert with conflict resolution (Q8). A list o
900
805
  interface WindowSpec
901
806
  ```
902
807
 
903
- **`FrameBound`** — One end of a window frame. `{ preceding: n }` / `{ following: n }` take a non-negative integer.
904
-
905
- ```typescript
906
- type FrameBound = 'unboundedPreceding' | 'currentRow' | 'unboundedFollowing' |
907
- ```
908
-
909
- **`WindowFrame`** — A window frame: `rows|range|groups [between] start [and end]`.
910
-
911
- ```typescript
912
- interface WindowFrame
913
- ```
914
-
915
- **`Aggregate`** — An aggregate expression that can be narrowed with `FILTER (WHERE …)`; `undefined` leaves it unfiltered.
916
-
917
- ```typescript
918
- type Aggregate<T> = SQL<T> &
919
- ```
920
-
921
- **`EmptyableAggregate`** — An array or jsonb aggregate; `orEmpty()` replaces the no-rows NULL with an empty array.
922
-
923
- ```typescript
924
- type EmptyableAggregate<T, E> = SQL<T> &
925
- ```
926
-
927
- **`JsonOf`**
928
-
929
- The type a value takes after a round trip through jsonb: Date -> string (ISO text),
930
- bigint -> number, Buffer/Uint8Array -> string, objects and arrays mapped recursively,
931
- null kept. Column decoders are not applied inside jsonb.
932
-
933
- ```typescript
934
- type JsonOf<T> =
935
- ```
936
-
937
- **`AggregateOptions`** — `ORDER BY` terms inside an aggregate — `asc(col)` / `desc(col)` or an array of them.
938
-
939
- ```typescript
940
- interface AggregateOptions
941
- ```
942
-
943
808
  **`ValueColumnDef`** — One column of a typed `VALUES` clause: its name and the PostgreSQL type each value in that column is cast to. See {@link values}.
944
809
 
945
810
  ```typescript
946
811
  interface ValueColumnDef
947
812
  ```
948
813
 
949
- **`JsonbElements`** — A jsonb array read as its elements' text. Produced by {@link jsonbElements}.
950
-
951
- ```typescript
952
- interface JsonbElements
953
- ```
954
-
955
- **`ArraySource`** — Something whose elements `arrayAny` / `arrayAll` can test.
956
-
957
- ```typescript
958
- type ArraySource =
959
- ```
960
-
961
- **`ElementOf`** — The element type of an {@link ArraySource}.
962
-
963
- ```typescript
964
- type ElementOf<S> =
965
- ```
966
-
967
- **`FunctionSpec`** — Declares a SQL function's argument and result-column shapes. See {@link fn}.
968
-
969
- ```typescript
970
- interface FunctionSpec<TArgs extends readonly AnyField[], TColumns extends Record<string, AnyField>>
971
- ```
972
-
973
- **`FunctionSourceFields`** — The selected fields of a function source: each result column as a typed SQL expression.
974
-
975
- ```typescript
976
- type FunctionSourceFields<TColumns extends Record<string, AnyField>> =
977
- ```
978
-
979
- **`FunctionSource`** — A function call usable in `.from()` and joins; its result columns are properties of it.
980
-
981
- ```typescript
982
- type FunctionSource<TAlias extends string, TColumns extends Record<string, AnyField>> =
983
- ```
984
-
985
814
  **`SerializableOptions`** — Retry policy for {@link serializable}: how many attempts on a serialization failure / deadlock, and the base backoff between them.
986
815
 
987
816
  ```typescript
988
817
  interface SerializableOptions
989
818
  ```
990
819
 
991
- **`TimeoutOptions`** — Which timeouts {@link withTimeouts} sets; each a positive integer number of milliseconds.
992
-
993
- ```typescript
994
- interface TimeoutOptions
995
- ```
996
-
997
820
  **`ManagedConnection`** — A standalone pooled connection: the raw postgres.js client, its drizzle handle, and a `close()` that ends the pool.
998
821
 
999
822
  ```typescript
1000
823
  interface ManagedConnection
1001
824
  ```
1002
825
 
1003
- **`ConnectOptions`** — Options for `tap()` — pool size (default 1), idle timeout in seconds, and session settings (GUCs) sent in every connection's startup packet.
826
+ **`ConnectOptions`** — Options for `tap()` — pool size (default 1) and idle timeout in seconds.
1004
827
 
1005
828
  ```typescript
1006
829
  interface ConnectOptions
@@ -1014,14 +837,6 @@ JSONB query operators — typed helpers for PostgreSQL JSONB containment, key ch
1014
837
 
1015
838
  The @> containment operator — tests whether a JSONB column contains the given value.
1016
839
 
1017
- ### `jsonb.merge`
1018
-
1019
- Merges an object into a JSONB column in `.set()`: `coalesce(col, '{}') || value`. Top-level keys overwrite; others are kept.
1020
-
1021
- ### `jsonb.remove`
1022
-
1023
- Removes top-level keys from a JSONB column in `.set()`: `col - 'key'`. Composes as the column of `jsonb.merge`.
1024
-
1025
840
  ### `jsonb.containedBy`
1026
841
 
1027
842
  The <@ contained-by operator — tests whether a JSONB column is contained by the given value.
@@ -1088,66 +903,6 @@ type Schema<T = unknown> = z.ZodType<T>
1088
903
  type Infer<T extends Schema> = z.infer<T>
1089
904
  ```
1090
905
 
1091
- **`StringSchema`** — A string validator — what check.string() returns.
1092
-
1093
- ```typescript
1094
- type StringSchema = z.ZodString
1095
- ```
1096
-
1097
- **`NumberSchema`** — A number validator — what check.number() returns.
1098
-
1099
- ```typescript
1100
- type NumberSchema = z.ZodNumber
1101
- ```
1102
-
1103
- **`BooleanSchema`** — A boolean validator — what check.boolean() returns.
1104
-
1105
- ```typescript
1106
- type BooleanSchema = z.ZodBoolean
1107
- ```
1108
-
1109
- **`EnumSchema`** — An enum validator over string literals — what check.enum([...]) returns.
1110
-
1111
- ```typescript
1112
- type EnumSchema<V extends string = string> = z.ZodEnum<
1113
- ```
1114
-
1115
- **`LiteralSchema`** — A literal validator — what check.literal(v) returns.
1116
-
1117
- ```typescript
1118
- type LiteralSchema<V extends string | number | boolean | null = string> = z.ZodLiteral<V>
1119
- ```
1120
-
1121
- **`ArraySchema`** — An array validator — what check.array(item) returns.
1122
-
1123
- ```typescript
1124
- type ArraySchema<Item extends z.core.SomeType = z.core.SomeType> = z.ZodArray<Item>
1125
- ```
1126
-
1127
- **`OptionalSchema`** — An optional validator — what check.optional(inner) and .optional() return.
1128
-
1129
- ```typescript
1130
- type OptionalSchema<Inner extends z.core.SomeType = z.core.SomeType> = z.ZodOptional<Inner>
1131
- ```
1132
-
1133
- **`NullableSchema`** — A nullable validator — what check.nullable(inner) and .nullable() return.
1134
-
1135
- ```typescript
1136
- type NullableSchema<Inner extends z.core.SomeType = z.core.SomeType> = z.ZodNullable<Inner>
1137
- ```
1138
-
1139
- **`ObjectSchema`** — An object validator — what check.object({...}) returns; keeps .extend, .pick, .omit and .partial. For a shape with fields beyond the plain kinds, annotate with ObjectSchema<{ field: Schema<T> }>.
1140
-
1141
- ```typescript
1142
- type ObjectSchema<S extends Shape = Shape> = z.ZodObject<S, z.core.$strip>
1143
- ```
1144
-
1145
- **`ObjectOps`** — The object operations of ObjectSchema.
1146
-
1147
- ```typescript
1148
- type ObjectOps<S extends Shape> = Pick<ObjectSchema<S>, 'extend' | 'pick' | 'omit' | 'partial'>
1149
- ```
1150
-
1151
906
  ## temporal — Bitemporal Data
1152
907
 
1153
908
  Temporal (bitemporal) data namespace — version history with effective date ranges.
@@ -1192,14 +947,6 @@ Query all versions of temporal records (no date filter).
1192
947
 
1193
948
  Close the current version and create a new one with updated data.
1194
949
 
1195
- ### `temporal.setVersion`
1196
-
1197
- Append the next version of an append-only-versions definition: serialised per scope, numbered, never back-dated, audited.
1198
-
1199
- ### `temporal.versionAt`
1200
-
1201
- The version in force at a moment: the row with the greatest effectiveFrom at or before it.
1202
-
1203
950
  ## valve
1204
951
 
1205
952
  Valve namespace — typed, directional, gated boundaries between code silos.
@@ -1382,18 +1129,6 @@ Alerts namespace — raise and resolve keyed conditions, grouped, delivered to s
1382
1129
 
1383
1130
  Creates an alerts handle.
1384
1131
 
1385
- ### `alerts.http`
1386
-
1387
- Routes for an operations agent: list, get, totals, delivery health, acknowledge, resolve, link; bearer credentials.
1388
-
1389
- ### `alerts.clientFaults`
1390
-
1391
- One POST route that records failures reported by browser code as a trace step and an alert; answers 204, no session needed. Send with `reportClientFault` from `pipework/client`.
1392
-
1393
- ### `alerts.requestFaults`
1394
-
1395
- An `onInternalError` hook for the HTTP server: raises `request-fault:<METHOD> <route>` for each internal 500.
1396
-
1397
1132
  ### `alerts.webhook`
1398
1133
 
1399
1134
  A sink that POSTs the alert as signed JSON to a URL.
@@ -1402,26 +1137,6 @@ A sink that POSTs the alert as signed JSON to a URL.
1402
1137
 
1403
1138
  A sink that keeps deliveries in `.delivered`, for tests.
1404
1139
 
1405
- ### `alerts.loopCheck`
1406
-
1407
- A `/ready` health check named `loops`: unhealthy while a background loop (the tick included) has not run or succeeded within its allowance.
1408
-
1409
- ### `alerts.recordFault`
1410
-
1411
- Records a failure your code swallowed (logged and carried on) so `alerts.source.faults` can raise it; `void alerts.recordFault('my-kind', message, context?)`. Best effort, never throws, writes outside the caller's transaction. Does nothing without `alerts` in the blueprint.
1412
-
1413
- ### `alerts.recordFaultFor`
1414
-
1415
- `recordFault` for code that holds the manifold and may run outside any Flow: `void alerts.recordFaultFor(manifold, kind, message, context?)`.
1416
-
1417
- ### `alerts.useFaultTarget`
1418
-
1419
- Registers the manifold (or a `DB`, or a function returning one) that `alerts.recordFault` writes on outside any Flow; call once at boot in a process that is not a pipework surface, and keep the release for shutdown. A manifold without `alerts` registers nothing.
1420
-
1421
- ### `alerts.recordBeat`
1422
-
1423
- Records one iteration of a background loop of your own for `alerts.source.loopStalled`: `void alerts.recordBeat(manifold, 'my-loop', { ok, error?, everyMs })`. Works outside any Flow; does nothing without `alerts`.
1424
-
1425
1140
  ## audit — Audit Logging
1426
1141
 
1427
1142
  Audit logging namespace — structured audit trail for data changes.
@@ -1446,10 +1161,6 @@ The newest record's `{ seq, hash }` in the tenant's audit hash chain (blueprint
1446
1161
 
1447
1162
  Walks the tenant's audit hash chain and reports the first break (hash-mismatch, prev-mismatch, missing, head-mismatch, anchor-mismatch), or `{ ok: true }`.
1448
1163
 
1449
- ### `audit.removeTenant`
1450
-
1451
- Deletes every audit record of one tenant and its hash chain, for the closure of that tenant's account. Irreversible; returns the number of records removed. Other tenants' records and chains are untouched.
1452
-
1453
1164
  ## cache — Caching
1454
1165
 
1455
1166
  In-memory caching namespace — TTL-based with stats, preload, and tenant-aware variants.
@@ -1502,64 +1213,6 @@ Inbound source: SES receipt rule storing raw messages in S3 and notifying a sign
1502
1213
 
1503
1214
  Inbound development source: `.eml` files dropped in a folder, received by `scan()`; refused in production.
1504
1215
 
1505
- ## untrustedFetch
1506
-
1507
- Untrusted fetch — fetch one URL a stranger gave without letting them reach the app's private network.
1508
-
1509
- ### `untrustedFetch.get`
1510
-
1511
- Fetches `url` with GET and returns `{ ok: true, url, status, contentType, body, bytes }`, or `{ ok: false, reason, message }`
1512
- naming the rule that refused: `scheme`, `address`, `redirects`, `too_large`, `timeout`, `status`, `rejected` or `network`.
1513
- It does not throw for these.
1514
-
1515
- Rules, none of which can be switched off: only `http:` and `https:`; the name is resolved and every address is checked
1516
- (loopback, private, link-local including cloud metadata, CGNAT, unique-local and site-local IPv6, multicast, reserved,
1517
- unspecified, and IPv4-mapped or NAT64 forms of these; literal IP URLs likewise) and the connection goes to a checked
1518
- address; redirects are followed up to `maxRedirects` and each hop is checked as the first, and the app's `headers` go only to the first origin;
1519
- the body is stopped the moment it passes `maxBytes`, whatever Content-Length says; `timeoutMs` covers the whole fetch.
1520
- `accept({ status, contentType, firstBytes })` sees the first 1024 bytes before the body is kept: return false, or a string
1521
- (your own message), to refuse with `rejected`. Messages never contain an address or anything a server sent.
1522
-
1523
- `resolve` and `connect` are for tests: `resolve(hostname)` replaces DNS and `connect(target)` replaces the socket after the
1524
- address check passed, so a test sends a fake public address to a local server. The address check always runs on what `resolve` returns.
1525
-
1526
- The call is the trace step `pipework/fetch:get`; its child `pipework/fetch:outcome` carries host, status, bytes and reason.
1527
- The full URL is recorded only when `urlIsSafeToTrace` is true; otherwise only the host.
1528
-
1529
- ```ts
1530
- const got = await untrustedFetch.get(pasted, { maxBytes: 5_000_000, timeoutMs: 10_000, maxRedirects: 3,
1531
- accept: h => h.firstBytes[0] === 0x25 || 'That does not look like a PDF.' })
1532
- if (!got.ok) return tell(got.message)
1533
- ```
1534
-
1535
- ### `connectRetry.fetch`
1536
-
1537
- `fetch(input, init, opts)` that retries a fault in the connect phase (undici `UND_ERR_CONNECT_TIMEOUT`, `EAI_AGAIN`,
1538
- `ENOTFOUND`, `ECONNREFUSED`, `ENETUNREACH`, `EHOSTUNREACH`), waiting `delaysMs` between tries (default 5 s, 15 s, 40 s: four
1539
- tries over about a minute), then throws the last fault with its cause chain. A fault after the request was written
1540
- (`ECONNRESET`, `UND_ERR_SOCKET`, a timeout, an abort) and a response of any status are never retried, because a POST may have taken effect.
1541
- `signal` ends the waiting; `onRetry({ error, attempt, delayMs })` is called before each wait; `fetch` replaces the global fetch.
1542
-
1543
- ```ts
1544
- const res = await connectRetry.fetch('https://api.github.com/repos/o/r/issues', { method: 'POST', body })
1545
- ```
1546
-
1547
- ### `connectRetry.call`
1548
-
1549
- Runs any `send()` with the same rule: retried only when `isUnsentFault(error)`; the last fault is thrown unchanged.
1550
-
1551
- ### `connectRetry.isUnsentFault`
1552
-
1553
- True when the error, its `cause` chain or an `AggregateError`'s errors show a connect-phase fault and no sent-phase one.
1554
-
1555
- ## quota
1556
-
1557
- Quota namespace — callers of one rate-limited upstream share its budget by class, read from the upstream's headers and kept in Postgres.
1558
-
1559
- ### `quota.create`
1560
-
1561
- Creates a quota handle.
1562
-
1563
1216
  ## storage
1564
1217
 
1565
1218
  Storage namespace — tenant-scoped, content-addressed file storage with signed URLs and retention.
@@ -1576,18 +1229,6 @@ S3-compatible backend (AWS S3, MinIO, R2): SigV4 over `fetch`, multipart streami
1576
1229
 
1577
1230
  Local-disk backend for development and tests; refused in production.
1578
1231
 
1579
- ## support
1580
-
1581
- Support namespace — tickets from email (and later chat), with replies sent only after an approval.
1582
-
1583
- ### `support.create`
1584
-
1585
- Creates the support handle: tickets, messages, notes, links, drafts, `approve`, `receiveEmail`, and the events job.
1586
-
1587
- ### `support.templates`
1588
-
1589
- The reply template to spread into `mail.create({ templates })`; it renders the approved draft verbatim.
1590
-
1591
1232
  ## webhook — Inbound & Outbound Webhooks
1592
1233
 
1593
1234
  Webhook namespace — inbound verification, outbound delivery with retries, HMAC signing.
@@ -1678,13 +1319,9 @@ Returns the current Flow or undefined — use for optional context detection.
1678
1319
 
1679
1320
  Creates a Flow for test isolation with optional auth and tenant overrides.
1680
1321
 
1681
- ### `flow.actAs`
1682
-
1683
- Runs `fn` as a tenant and user chosen inside a tenantless Flow (sign-up, a public sign-in): RLS, audit and trace under that tenant, on the request's transaction.
1684
-
1685
1322
  ## http — Server
1686
1323
 
1687
- HTTP namespace: `http.file()` builds a file response; `http.detectMediaType()` names bytes the way uploads do; the server itself is managed by manifold.start().
1324
+ HTTP namespace: `http.file()` builds a file response; the server itself is managed by manifold.start().
1688
1325
 
1689
1326
  ### Types
1690
1327
 
@@ -1706,40 +1343,6 @@ interface SecurityConfig
1706
1343
  interface RateLimitConfig
1707
1344
  ```
1708
1345
 
1709
- **`RateLimitWindow`** — One fixed window: at most `max` requests per `windowSeconds`.
1710
-
1711
- ```typescript
1712
- interface RateLimitWindow
1713
- ```
1714
-
1715
- **`RateLimitClass`**
1716
-
1717
- A named limit class: any of a per-user, per-tenant, per-address and total window, each counted on its own.
1718
- Each key takes one window or an array of windows (distinct `windowSeconds`); a request is counted against
1719
- all of a key's windows and refused if any is over.
1720
-
1721
- ```typescript
1722
- interface RateLimitClass
1723
- ```
1724
-
1725
- **`RateLimitRefusal`** — What `onRefused` is told about one refused window of one request.
1726
-
1727
- ```typescript
1728
- interface RateLimitRefusal
1729
- ```
1730
-
1731
- **`RateLimitClassesConfig`**
1732
-
1733
- Named limit classes, checked after auth and counted in Postgres (`pipework_rate_limit_counts`, opted in
1734
- with the blueprint's `rateLimits: {}`), so every server process on the same database shares one count.
1735
- Keys are counted perUser, perTenant, perAddress, total in turn, up to the first key with a window over its max, so one user's
1736
- refused requests don't spend the tenant's budget. The 429's Retry-After is the longest wait of the windows that refused. A route is in `signedIn` (auth required, or optional with
1737
- a user), `public` (no auth, or optional without a user) or the class its fitting names with `.rateLimit(name)`.
1738
-
1739
- ```typescript
1740
- interface RateLimitClassesConfig
1741
- ```
1742
-
1743
1346
  **`InjectOptions`** — Options for server.inject() — method, url, headers, payload for testing without HTTP.
1744
1347
 
1745
1348
  ```typescript
@@ -1758,12 +1361,6 @@ interface InjectResponse
1758
1361
  interface ServerConfig
1759
1362
  ```
1760
1363
 
1761
- **`InternalErrorFault`** — What `onInternalError` is told about one request that ended in an internal error.
1762
-
1763
- ```typescript
1764
- interface InternalErrorFault
1765
- ```
1766
-
1767
1364
  **`HandlerResponse`** — Standard handler response shape — statusCode, headers, body.
1768
1365
 
1769
1366
  ```typescript
@@ -1822,7 +1419,7 @@ Generates an OpenAPI 3.1 document from route registrations — schemas derived f
1822
1419
 
1823
1420
  ## trace
1824
1421
 
1825
- Trace namespace — hand the current trace to a process outside Node, record the steps it reports back, mark point events, and read a trace tree.
1422
+ Trace namespace — hand the current trace to a process outside Node and record the steps it reports back.
1826
1423
 
1827
1424
  ### `trace.traceparent`
1828
1425
 
@@ -1836,15 +1433,6 @@ W3C `traceparent` for the current trace and open step; `null` outside a traced f
1836
1433
 
1837
1434
  Records steps reported as JSON lines (or objects) by an outside process under the step open now. Synchronous; never throws.
1838
1435
 
1839
- ### `trace.event`
1840
-
1841
- Records one zero-length step `external:<name>` under the step open now, with an optional `capture` and `error`. A no-op outside a traced flow; never throws.
1842
-
1843
- ### `trace.tree`
1844
-
1845
- Reads every hot trace sharing `rootId` (a request's trace and the jobs it queued) with their steps. Runs on the
1846
- given `db`, so tenant policies apply: only an unrestricted connection (table owner, tests) sees every tenant's rows.
1847
-
1848
1436
  ### Types
1849
1437
 
1850
1438
  **`FlowStepMeta`** — Trace metadata for one documented flow-step: its `path:symbol` graph node id and the per-argument capture projections.
@@ -1865,40 +1453,17 @@ type ExternalStepReport = z.infer<typeof externalStepReportSchema>
1865
1453
  interface ExternalRecordResult
1866
1454
  ```
1867
1455
 
1868
- **`TraceStepNode`** — One step of a trace. `ref` is the flow step's `path:symbol`, or `external:<name>` for a recorded or point-event step.
1869
-
1870
- ```typescript
1871
- interface TraceStepNode
1872
- ```
1873
-
1874
- **`TraceNode`** — One trace of the tree, with its steps ordered by `seq`.
1875
-
1876
- ```typescript
1877
- interface TraceNode
1878
- ```
1879
-
1880
- **`TraceTree`** — The traces that share a root id, ordered by when they opened.
1881
-
1882
- ```typescript
1883
- interface TraceTree
1884
- ```
1885
-
1886
1456
  ## data
1887
1457
 
1888
- ### `StatementTimeoutError`
1889
-
1890
- A statement was cancelled by Postgres for running past the statement timeout a {@link withTimeouts} call set. `cause` is the driver error.
1891
-
1892
- ```typescript
1893
- class StatementTimeoutError extends Error constructor(readonly statementTimeoutMs: number, cause: unknown)
1894
- ```
1458
+ ### `tap`
1895
1459
 
1896
- ### `LockTimeoutError`
1897
-
1898
- A statement gave up waiting for a lock past the lock timeout a {@link withTimeouts} call set. `cause` is the driver error.
1460
+ Opens a standalone managed connection outside the manifold's pools — the
1461
+ sanctioned door for contexts where `pipe()` structurally cannot resolve:
1462
+ `worker_threads`, detached monitors, one-off scripts. Callers own the
1463
+ lifecycle: always `await conn.close()`.
1899
1464
 
1900
1465
  ```typescript
1901
- class LockTimeoutError extends Error constructor(readonly lockTimeoutMs: number, cause: unknown)
1466
+ function tap(url: string, options?: ConnectOptions): ManagedConnection
1902
1467
  ```
1903
1468
 
1904
1469
  ## request
@@ -1910,24 +1475,3 @@ Creates a PipeworkServer — wraps Fastify with auto request IDs, CORS, rate lim
1910
1475
  ```typescript
1911
1476
  function createServer(instance: Manifold, config: ServerConfig = if (instance.config.environment === 'production')
1912
1477
  ```
1913
-
1914
- ## async
1915
-
1916
- ### `serializeError`
1917
-
1918
- Serialize an arbitrary thrown value for durable storage in a job's `error_payload`.
1919
-
1920
- A bare `{ message, stack }` capture is a diagnostics trap: wrapper errors hide the
1921
- root cause. Drizzle throws `DrizzleQueryError` whose `.message` is only the failed
1922
- SQL text; the real `PostgresError` — carrying `code`/`detail`/`constraint`/`table`
1923
- — lives on `.cause`. This walks the full `cause` chain and copies each error's
1924
- own-enumerable properties (where both Drizzle's `query` and Postgres' fields live),
1925
- so a dead-lettered job records *why* it failed, not just *which query* failed.
1926
-
1927
- Parameters are never stored (`params`, `parameters`, `args`, `types`); `query` is cut
1928
- to 2,000 characters and any other string to 4,000, ending `…[truncated N chars]`.
1929
- Non-Error values pass through unchanged. Circular `cause` references are broken.
1930
-
1931
- ```typescript
1932
- function serializeError(error: unknown): unknown
1933
- ```