pipework 0.190.0 → 0.192.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/CHANGELOG.md CHANGED
@@ -1,5 +1,34 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.192.0
4
+
5
+ - **Added: uploads detect JPEG 2000 and OpenDocument from their bytes** (#749).
6
+ - A JP2 file is named by its `ftyp` brand: `image/jp2`, `image/jpx` or `image/jpm`. A bare `.j2k` codestream resolves to `image/jp2`, whatever type either was declared as.
7
+ - A zip whose stored first member is `mimetype` resolves to the OpenDocument or EPUB type it names, with no filename needed. A zip whose first entries are all under `word/`, `xl/` or `ppt/` resolves to docx, xlsx or pptx. A type named by the bytes wins over the declared type and the extension. Any other zip is narrowed by declared type or extension as before.
8
+ - Added in the same sweep, the other binary formats the table couldn't name: JPEG XL, bzip2, xz, zstd, wasm, SQLite, woff, woff2, otf, ttf, MIDI, AIFF and AIFC, ELF, PE (`application/x-msdownload`), Mach-O, and mp3 without an ID3 tag. Each weak signature is checked further, so text that happens to start with `MZ` or `BZh` isn't misnamed.
9
+ - **Added: the same detection for apps.** The package entry and the `http` namespace export `detectMediaType(bytes)`, `resolveMediaType({ head, declared, extension })`, `extensionOf(filename)` and `SNIFF_BYTES`.
10
+ - **Changed: inbound mail attachments are typed from their bytes.** Each attachment's type is resolved the same way as an upload's. When the declared type is contradicted by the bytes, the attachment is stored as `application/octet-stream` and the mail is still accepted. The storage metadata records `{ detectedType, declaredType }`.
11
+
12
+ ## 0.191.0
13
+
14
+ - **Added: `$with` on a tenant-scoped connection** (#748). `db.$with('m').materialized().as(db.select(…).from(tenantTable))` followed by `db.with(m).select().from(m)` returns only the context tenant's rows, the same as an inline subquery.
15
+ - A CTE body must be built by the same scoped connection. The callback form `(qb) => …` gets a scoped query builder.
16
+ - A raw `sql` body, or a builder from `pipe.system()` or another connection, is refused with a message saying why.
17
+ - `db.with(…)` accepts only this connection's CTEs and scopes what follows it.
18
+ - **Fixed: the tenant-scoped connection let other tenants' rows through on several paths** (#748). Postgres row-level security still applied wherever it was configured, but pipework's own tenant filter was missing on these:
19
+ - A scoped select used as a subquery, through `inArray(…)`, `.as()`, `getSQL()` or `toSQL()`, had no tenant filter. The filter used to be added only when the query was awaited. It is now in the SQL as soon as the table is named.
20
+ - A joined tenant table (inner, left, right, full or cross) wasn't filtered. Its condition now goes in the join's ON clause, so a left join keeps its unmatched rows. Right and full joins also keep the tables before them to the tenant.
21
+ - `db.with(x)` passed straight through to the unscoped connection.
22
+ - `db.transaction(cb)` handed `cb` an unscoped `tx`.
23
+ - `$count` counted every tenant's rows.
24
+ - `update().from(tenantTable)` read every tenant's rows.
25
+ - A `union` (or other set operation) accepted an operand built elsewhere.
26
+ - An `onConflictDoUpdate` upsert on a unique key that excludes the tenant column could overwrite another tenant's row. Its update is now limited to the tenant's own rows, and a conflict with another tenant's row updates nothing and returns no row. `pipe.upsert` and audited upserts are covered.
27
+ - The no-tenant guard connection refuses a tenant table on all of the same paths.
28
+ - **Changed:**
29
+ - `insert().select()` into a tenant table is refused on a scoped connection, because the tenant column can't be set from a select.
30
+ - `db.query` (relational queries) is refused on a scoped connection that has tables.
31
+
3
32
  ## 0.190.0
4
33
 
5
34
  - **Fixed: a NULL element in an array read back wrong** (#747). On every path (column selects, `db.execute`, `arrayAgg`) an unquoted NULL element now reads as `null`, for every array type:
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-22
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,9 +30,7 @@
31
30
  - [cache — Caching](#cache-caching)
32
31
  - [credits](#credits)
33
32
  - [mail](#mail)
34
- - [untrustedFetch](#untrustedfetch)
35
33
  - [storage](#storage)
36
- - [support](#support)
37
34
  - [webhook — Inbound & Outbound Webhooks](#webhook-inbound-outbound-webhooks)
38
35
  - [behavior — Resource Decorators](#behavior-resource-decorators)
39
36
  - [fitting — Dependency Injection](#fitting-dependency-injection)
@@ -88,18 +85,6 @@ function createManifold<const TEnv extends EnvDefs = EnvDefs>( raw: Omit<Bluepri
88
85
  interface Manifold<TEnv extends EnvDefs = EnvDefs>
89
86
  ```
90
87
 
91
- **`ScriptOptions`** — Options for {@link Manifold.script}.
92
-
93
- ```typescript
94
- interface ScriptOptions
95
- ```
96
-
97
- **`StartOptions`** — Options for {@link Manifold.start}.
98
-
99
- ```typescript
100
- interface StartOptions
101
- ```
102
-
103
88
  **`SeedOptions`** — ALS context the {@link Manifold.seed} callback runs under — tenant scope, auth principal, and job type.
104
89
 
105
90
  ```typescript
@@ -244,14 +229,6 @@ Creates a job queue with claim/complete/fail lifecycle, heartbeat, and dead lett
244
229
 
245
230
  Executes a fitting handler as a background job with its own Flow context.
246
231
 
247
- ### `jobs.later`
248
-
249
- The error to throw to end an attempt as "later": pending again after `delayMs`, no attempt counted.
250
-
251
- ### `jobs.permanent`
252
-
253
- The error to throw to dead-letter the job now, whatever attempts remain.
254
-
255
232
  ### `jobs.parseCron`
256
233
 
257
234
  Parses a 5-field cron expression into a CronSchedule (minute, hour, dom, month, dow).
@@ -292,14 +269,6 @@ Thrown when a transition is not allowed from the current state.
292
269
 
293
270
  Thrown when the state machine definition is internally inconsistent.
294
271
 
295
- ## steps
296
-
297
- Step graphs over a job queue: results recorded by their inputs, only missing steps run.
298
-
299
- ### `steps.define`
300
-
301
- Defines a graph of named steps over a jobs Queue. Pass it to `createWorkerSurface({ graphs })` to run its steps.
302
-
303
272
  ## auth — Authentication
304
273
 
305
274
  Authentication namespace — session management, multi-org support, auth chain resolution.
@@ -320,10 +289,6 @@ Hashes and verifies passwords with scrypt; reports when a stored hash needs reha
320
289
 
321
290
  Guarded password sign-in that slows, then refuses, repeated failures per account and per client.
322
291
 
323
- ### `auth.emailLinks`
324
-
325
- Emailed single-use links that prove control of an address: password reset and address verification; the token is never stored.
326
-
327
292
  ### `auth.runChain`
328
293
 
329
294
  Executes an auth chain (strategy pipeline) to resolve auth + tenant from a request.
@@ -358,7 +323,7 @@ interface AuthContext
358
323
  interface AuthStrategy<TAuth>
359
324
  ```
360
325
 
361
- **`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.
362
327
 
363
328
  ```typescript
364
329
  interface AuthRequest
@@ -388,18 +353,6 @@ interface TenantResolver<TAuth>
388
353
  interface AuthChainConfig<TAuth>
389
354
  ```
390
355
 
391
- **`SessionAuth`** — What `sessions.strategy()` authenticates: the token's user and org, its roles, and where the token came from.
392
-
393
- ```typescript
394
- type SessionAuth = BaseAuth &
395
- ```
396
-
397
- **`SessionStrategyOptions`** — Options for `sessions.strategy()`.
398
-
399
- ```typescript
400
- interface SessionStrategyOptions
401
- ```
402
-
403
356
  **`SessionConfig`** — Session configuration — signing keys, issuer, audience, token TTLs, refresh rotation.
404
357
 
405
358
  ```typescript
@@ -671,10 +624,6 @@ Base error class with code, statusCode, and suggestion fields.
671
624
 
672
625
  403 — authenticated but insufficient permissions.
673
626
 
674
- ### `errors.CrossSiteRequest`
675
-
676
- 403 `CROSS_SITE_REQUEST` — a cookie-authenticated write that did not come from the app's own site.
677
-
678
627
  ### `errors.Validation`
679
628
 
680
629
  422 — input validation failed, carries field-level details.
@@ -695,17 +644,13 @@ Base error class with code, statusCode, and suggestion fields.
695
644
 
696
645
  415 — request body media type not accepted by the route.
697
646
 
698
- ### `errors.MalformedMultipart`
699
-
700
- 400 `MALFORMED_MULTIPART` — a multipart body that cannot be parsed or ends before its closing boundary.
701
-
702
647
  ## lifecycle — Startup & Shutdown
703
648
 
704
649
  Application lifecycle namespace — startup orchestration with hooks and timeouts.
705
650
 
706
651
  ### `lifecycle.orchestrate`
707
652
 
708
- 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.
709
654
 
710
655
  ## log — Structured Logging
711
656
 
@@ -745,7 +690,7 @@ Creates a worker surface — a long-running process that claims and executes job
745
690
 
746
691
  ### `surface.script`
747
692
 
748
- 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).
749
694
 
750
695
  ## pipe — Database
751
696
 
@@ -816,10 +761,6 @@ Acquires a transaction-scoped advisory lock. Released at commit/rollback.
816
761
 
817
762
  Runs a function in a SERIALIZABLE transaction with automatic retry on serialization failures and deadlocks.
818
763
 
819
- ### `pipe.withTimeouts`
820
-
821
- 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.
822
-
823
764
  ### `pipe.bulkSet`
824
765
 
825
766
  Bulk UPDATE ... FROM (VALUES ...) — updates multiple rows with per-row values in a single statement.
@@ -828,10 +769,6 @@ Bulk UPDATE ... FROM (VALUES ...) — updates multiple rows with per-row values
828
769
 
829
770
  Produces a typed VALUES clause for bulk operations — the base primitive for bulkSet and bulkUpsert.
830
771
 
831
- ### `pipe.fn`
832
-
833
- 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.
834
-
835
772
  ### `pipe.field`
836
773
 
837
774
  Field builders for domain definitions — uuid(), text(), integer(), etc.
@@ -844,17 +781,13 @@ Registers a domain definition with table, validators, and factory projections. T
844
781
 
845
782
  Returns the global registry of all domain definitions.
846
783
 
847
- ### `pipe.external`
848
-
849
- 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.
850
-
851
784
  ### `pipe.update`
852
785
 
853
786
  Pipework-owned UPDATE builder — the only consumer-facing way to update pipework-managed tables (Q8).
854
787
 
855
788
  ### `pipe.insert`
856
789
 
857
- 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).
858
791
 
859
792
  ### `pipe.delete`
860
793
 
@@ -862,7 +795,7 @@ Pipework-owned DELETE builder — the only consumer-facing way to delete from pi
862
795
 
863
796
  ### `pipe.upsert`
864
797
 
865
- 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).
866
799
 
867
800
  ### Types
868
801
 
@@ -878,54 +811,12 @@ interface WindowSpec
878
811
  interface ValueColumnDef
879
812
  ```
880
813
 
881
- **`JsonbElements`** — A jsonb array read as its elements' text. Produced by {@link jsonbElements}.
882
-
883
- ```typescript
884
- interface JsonbElements
885
- ```
886
-
887
- **`ArraySource`** — Something whose elements `arrayAny` / `arrayAll` can test.
888
-
889
- ```typescript
890
- type ArraySource =
891
- ```
892
-
893
- **`ElementOf`** — The element type of an {@link ArraySource}.
894
-
895
- ```typescript
896
- type ElementOf<S> =
897
- ```
898
-
899
- **`FunctionSpec`** — Declares a SQL function's argument and result-column shapes. See {@link fn}.
900
-
901
- ```typescript
902
- interface FunctionSpec<TArgs extends readonly AnyField[], TColumns extends Record<string, AnyField>>
903
- ```
904
-
905
- **`FunctionSourceFields`** — The selected fields of a function source: each result column as a typed SQL expression.
906
-
907
- ```typescript
908
- type FunctionSourceFields<TColumns extends Record<string, AnyField>> =
909
- ```
910
-
911
- **`FunctionSource`** — A function call usable in `.from()` and joins; its result columns are properties of it.
912
-
913
- ```typescript
914
- type FunctionSource<TAlias extends string, TColumns extends Record<string, AnyField>> =
915
- ```
916
-
917
814
  **`SerializableOptions`** — Retry policy for {@link serializable}: how many attempts on a serialization failure / deadlock, and the base backoff between them.
918
815
 
919
816
  ```typescript
920
817
  interface SerializableOptions
921
818
  ```
922
819
 
923
- **`TimeoutOptions`** — Which timeouts {@link withTimeouts} sets; each a positive integer number of milliseconds.
924
-
925
- ```typescript
926
- interface TimeoutOptions
927
- ```
928
-
929
820
  **`ManagedConnection`** — A standalone pooled connection: the raw postgres.js client, its drizzle handle, and a `close()` that ends the pool.
930
821
 
931
822
  ```typescript
@@ -946,10 +837,6 @@ JSONB query operators — typed helpers for PostgreSQL JSONB containment, key ch
946
837
 
947
838
  The @> containment operator — tests whether a JSONB column contains the given value.
948
839
 
949
- ### `jsonb.merge`
950
-
951
- Merges an object into a JSONB column in `.set()`: `coalesce(col, '{}') || value`. Top-level keys overwrite; others are kept.
952
-
953
840
  ### `jsonb.containedBy`
954
841
 
955
842
  The <@ contained-by operator — tests whether a JSONB column is contained by the given value.
@@ -1016,60 +903,6 @@ type Schema<T = unknown> = z.ZodType<T>
1016
903
  type Infer<T extends Schema> = z.infer<T>
1017
904
  ```
1018
905
 
1019
- **`StringSchema`** — A string validator — what check.string() returns, nameable without importing zod.
1020
-
1021
- ```typescript
1022
- interface StringSchema extends z.ZodString
1023
- ```
1024
-
1025
- **`NumberSchema`** — A number validator — what check.number() returns.
1026
-
1027
- ```typescript
1028
- interface NumberSchema extends z.ZodNumber
1029
- ```
1030
-
1031
- **`BooleanSchema`** — A boolean validator — what check.boolean() returns.
1032
-
1033
- ```typescript
1034
- interface BooleanSchema extends z.ZodBoolean
1035
- ```
1036
-
1037
- **`EnumSchema`** — An enum validator over string literals — what check.enum([...]) returns.
1038
-
1039
- ```typescript
1040
- interface EnumSchema<V extends string = string> extends z.ZodEnum<
1041
- ```
1042
-
1043
- **`LiteralSchema`** — A literal validator — what check.literal(v) returns.
1044
-
1045
- ```typescript
1046
- interface LiteralSchema<V extends string | number | boolean | null = string> extends z.ZodLiteral<V>
1047
- ```
1048
-
1049
- **`ArraySchema`** — An array validator — what check.array(item) returns.
1050
-
1051
- ```typescript
1052
- interface ArraySchema<Item extends z.core.SomeType = z.core.SomeType> extends z.ZodArray<Item>
1053
- ```
1054
-
1055
- **`OptionalSchema`** — An optional validator — what check.optional(inner) returns.
1056
-
1057
- ```typescript
1058
- interface OptionalSchema<Inner extends z.core.SomeType = z.core.SomeType> extends z.ZodOptional<Inner>
1059
- ```
1060
-
1061
- **`NullableSchema`** — A nullable validator — what check.nullable(inner) returns.
1062
-
1063
- ```typescript
1064
- interface NullableSchema<Inner extends z.core.SomeType = z.core.SomeType> extends z.ZodNullable<Inner>
1065
- ```
1066
-
1067
- **`ObjectSchema`** — An object validator whose .extend, .pick, .omit and .partial results stay ObjectSchema — what check.object({...}) returns.
1068
-
1069
- ```typescript
1070
- type ObjectSchema<S extends Shape = Shape> =
1071
- ```
1072
-
1073
906
  ## temporal — Bitemporal Data
1074
907
 
1075
908
  Temporal (bitemporal) data namespace — version history with effective date ranges.
@@ -1114,14 +947,6 @@ Query all versions of temporal records (no date filter).
1114
947
 
1115
948
  Close the current version and create a new one with updated data.
1116
949
 
1117
- ### `temporal.setVersion`
1118
-
1119
- Append the next version of an append-only-versions definition: serialised per scope, numbered, never back-dated, audited.
1120
-
1121
- ### `temporal.versionAt`
1122
-
1123
- The version in force at a moment: the row with the greatest effectiveFrom at or before it.
1124
-
1125
950
  ## valve
1126
951
 
1127
952
  Valve namespace — typed, directional, gated boundaries between code silos.
@@ -1304,18 +1129,6 @@ Alerts namespace — raise and resolve keyed conditions, grouped, delivered to s
1304
1129
 
1305
1130
  Creates an alerts handle.
1306
1131
 
1307
- ### `alerts.http`
1308
-
1309
- Routes for an operations agent: list, get, totals, delivery health, acknowledge, resolve, link; bearer credentials.
1310
-
1311
- ### `alerts.clientFaults`
1312
-
1313
- 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`.
1314
-
1315
- ### `alerts.requestFaults`
1316
-
1317
- An `onInternalError` hook for the HTTP server: raises `request-fault:<METHOD> <route>` for each internal 500.
1318
-
1319
1132
  ### `alerts.webhook`
1320
1133
 
1321
1134
  A sink that POSTs the alert as signed JSON to a URL.
@@ -1348,10 +1161,6 @@ The newest record's `{ seq, hash }` in the tenant's audit hash chain (blueprint
1348
1161
 
1349
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 }`.
1350
1163
 
1351
- ### `audit.removeTenant`
1352
-
1353
- 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.
1354
-
1355
1164
  ## cache — Caching
1356
1165
 
1357
1166
  In-memory caching namespace — TTL-based with stats, preload, and tenant-aware variants.
@@ -1404,36 +1213,6 @@ Inbound source: SES receipt rule storing raw messages in S3 and notifying a sign
1404
1213
 
1405
1214
  Inbound development source: `.eml` files dropped in a folder, received by `scan()`; refused in production.
1406
1215
 
1407
- ## untrustedFetch
1408
-
1409
- Untrusted fetch — fetch one URL a stranger gave without letting them reach the app's private network.
1410
-
1411
- ### `untrustedFetch.get`
1412
-
1413
- Fetches `url` with GET and returns `{ ok: true, url, status, contentType, body, bytes }`, or `{ ok: false, reason, message }`
1414
- naming the rule that refused: `scheme`, `address`, `redirects`, `too_large`, `timeout`, `status`, `rejected` or `network`.
1415
- It does not throw for these.
1416
-
1417
- Rules, none of which can be switched off: only `http:` and `https:`; the name is resolved and every address is checked
1418
- (loopback, private, link-local including cloud metadata, CGNAT, unique-local and site-local IPv6, multicast, reserved,
1419
- unspecified, and IPv4-mapped or NAT64 forms of these; literal IP URLs likewise) and the connection goes to a checked
1420
- 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;
1421
- the body is stopped the moment it passes `maxBytes`, whatever Content-Length says; `timeoutMs` covers the whole fetch.
1422
- `accept({ status, contentType, firstBytes })` sees the first 1024 bytes before the body is kept: return false, or a string
1423
- (your own message), to refuse with `rejected`. Messages never contain an address or anything a server sent.
1424
-
1425
- `resolve` and `connect` are for tests: `resolve(hostname)` replaces DNS and `connect(target)` replaces the socket after the
1426
- address check passed, so a test sends a fake public address to a local server. The address check always runs on what `resolve` returns.
1427
-
1428
- The call is the trace step `pipework/fetch:get`; its child `pipework/fetch:outcome` carries host, status, bytes and reason.
1429
- The full URL is recorded only when `urlIsSafeToTrace` is true; otherwise only the host.
1430
-
1431
- ```ts
1432
- const got = await untrustedFetch.get(pasted, { maxBytes: 5_000_000, timeoutMs: 10_000, maxRedirects: 3,
1433
- accept: h => h.firstBytes[0] === 0x25 || 'That does not look like a PDF.' })
1434
- if (!got.ok) return tell(got.message)
1435
- ```
1436
-
1437
1216
  ## storage
1438
1217
 
1439
1218
  Storage namespace — tenant-scoped, content-addressed file storage with signed URLs and retention.
@@ -1450,18 +1229,6 @@ S3-compatible backend (AWS S3, MinIO, R2): SigV4 over `fetch`, multipart streami
1450
1229
 
1451
1230
  Local-disk backend for development and tests; refused in production.
1452
1231
 
1453
- ## support
1454
-
1455
- Support namespace — tickets from email (and later chat), with replies sent only after an approval.
1456
-
1457
- ### `support.create`
1458
-
1459
- Creates the support handle: tickets, messages, notes, links, drafts, `approve`, `receiveEmail`, and the events job.
1460
-
1461
- ### `support.templates`
1462
-
1463
- The reply template to spread into `mail.create({ templates })`; it renders the approved draft verbatim.
1464
-
1465
1232
  ## webhook — Inbound & Outbound Webhooks
1466
1233
 
1467
1234
  Webhook namespace — inbound verification, outbound delivery with retries, HMAC signing.
@@ -1552,10 +1319,6 @@ Returns the current Flow or undefined — use for optional context detection.
1552
1319
 
1553
1320
  Creates a Flow for test isolation with optional auth and tenant overrides.
1554
1321
 
1555
- ### `flow.actAs`
1556
-
1557
- 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.
1558
-
1559
1322
  ## http — Server
1560
1323
 
1561
1324
  HTTP namespace: `http.file()` builds a file response; the server itself is managed by manifold.start().
@@ -1580,40 +1343,6 @@ interface SecurityConfig
1580
1343
  interface RateLimitConfig
1581
1344
  ```
1582
1345
 
1583
- **`RateLimitWindow`** — One fixed window: at most `max` requests per `windowSeconds`.
1584
-
1585
- ```typescript
1586
- interface RateLimitWindow
1587
- ```
1588
-
1589
- **`RateLimitClass`**
1590
-
1591
- A named limit class: any of a per-user, per-tenant, per-address and total window, each counted on its own.
1592
- Each key takes one window or an array of windows (distinct `windowSeconds`); a request is counted against
1593
- all of a key's windows and refused if any is over.
1594
-
1595
- ```typescript
1596
- interface RateLimitClass
1597
- ```
1598
-
1599
- **`RateLimitRefusal`** — What `onRefused` is told about one refused window of one request.
1600
-
1601
- ```typescript
1602
- interface RateLimitRefusal
1603
- ```
1604
-
1605
- **`RateLimitClassesConfig`**
1606
-
1607
- Named limit classes, checked after auth and counted in Postgres (`pipework_rate_limit_counts`, opted in
1608
- with the blueprint's `rateLimits: {}`), so every server process on the same database shares one count.
1609
- Keys are counted perUser, perTenant, perAddress, total in turn, up to the first key with a window over its max, so one user's
1610
- 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
1611
- a user), `public` (no auth, or optional without a user) or the class its fitting names with `.rateLimit(name)`.
1612
-
1613
- ```typescript
1614
- interface RateLimitClassesConfig
1615
- ```
1616
-
1617
1346
  **`InjectOptions`** — Options for server.inject() — method, url, headers, payload for testing without HTTP.
1618
1347
 
1619
1348
  ```typescript
@@ -1632,12 +1361,6 @@ interface InjectResponse
1632
1361
  interface ServerConfig
1633
1362
  ```
1634
1363
 
1635
- **`InternalErrorFault`** — What `onInternalError` is told about one request that ended in an internal error.
1636
-
1637
- ```typescript
1638
- interface InternalErrorFault
1639
- ```
1640
-
1641
1364
  **`HandlerResponse`** — Standard handler response shape — statusCode, headers, body.
1642
1365
 
1643
1366
  ```typescript
@@ -1696,7 +1419,7 @@ Generates an OpenAPI 3.1 document from route registrations — schemas derived f
1696
1419
 
1697
1420
  ## trace
1698
1421
 
1699
- 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.
1700
1423
 
1701
1424
  ### `trace.traceparent`
1702
1425
 
@@ -1710,15 +1433,6 @@ W3C `traceparent` for the current trace and open step; `null` outside a traced f
1710
1433
 
1711
1434
  Records steps reported as JSON lines (or objects) by an outside process under the step open now. Synchronous; never throws.
1712
1435
 
1713
- ### `trace.event`
1714
-
1715
- 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.
1716
-
1717
- ### `trace.tree`
1718
-
1719
- Reads every hot trace sharing `rootId` (a request's trace and the jobs it queued) with their steps. Runs on the
1720
- given `db`, so tenant policies apply: only an unrestricted connection (table owner, tests) sees every tenant's rows.
1721
-
1722
1436
  ### Types
1723
1437
 
1724
1438
  **`FlowStepMeta`** — Trace metadata for one documented flow-step: its `path:symbol` graph node id and the per-argument capture projections.
@@ -1739,40 +1453,17 @@ type ExternalStepReport = z.infer<typeof externalStepReportSchema>
1739
1453
  interface ExternalRecordResult
1740
1454
  ```
1741
1455
 
1742
- **`TraceStepNode`** — One step of a trace. `ref` is the flow step's `path:symbol`, or `external:<name>` for a recorded or point-event step.
1743
-
1744
- ```typescript
1745
- interface TraceStepNode
1746
- ```
1747
-
1748
- **`TraceNode`** — One trace of the tree, with its steps ordered by `seq`.
1749
-
1750
- ```typescript
1751
- interface TraceNode
1752
- ```
1753
-
1754
- **`TraceTree`** — The traces that share a root id, ordered by when they opened.
1755
-
1756
- ```typescript
1757
- interface TraceTree
1758
- ```
1759
-
1760
1456
  ## data
1761
1457
 
1762
- ### `StatementTimeoutError`
1763
-
1764
- A statement was cancelled by Postgres for running past the statement timeout a {@link withTimeouts} call set. `cause` is the driver error.
1765
-
1766
- ```typescript
1767
- class StatementTimeoutError extends Error constructor(readonly statementTimeoutMs: number, cause: unknown)
1768
- ```
1769
-
1770
- ### `LockTimeoutError`
1458
+ ### `tap`
1771
1459
 
1772
- 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()`.
1773
1464
 
1774
1465
  ```typescript
1775
- class LockTimeoutError extends Error constructor(readonly lockTimeoutMs: number, cause: unknown)
1466
+ function tap(url: string, options?: ConnectOptions): ManagedConnection
1776
1467
  ```
1777
1468
 
1778
1469
  ## request
@@ -1 +1 @@
1
- {"version":3,"file":"scoped-db.d.ts","sourceRoot":"","sources":["../../../src/auth/tenant/scoped-db.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,wBAAwB,CAAA;AAiKhD,wBAAgB,mBAAmB,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE,CAsB9C;AAmBD,wBAAgB,cAAc,CAAC,EAAE,EAAE,EAAE,EAAE,QAAQ,EAAE,MAAM,GAAG,EAAE,CAgE3D"}
1
+ {"version":3,"file":"scoped-db.d.ts","sourceRoot":"","sources":["../../../src/auth/tenant/scoped-db.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,wBAAwB,CAAA;AAichD,wBAAgB,mBAAmB,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE,CAE9C;AAED,wBAAgB,cAAc,CAAC,EAAE,EAAE,EAAE,EAAE,QAAQ,EAAE,MAAM,GAAG,EAAE,CAE3D"}