pipework 0.136.0 → 0.138.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 (66) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/REFERENCE.md +27 -0
  3. package/dist/REFERENCE.md +195 -7
  4. package/dist/data/db/expressions.d.ts +29 -1
  5. package/dist/data/db/expressions.d.ts.map +1 -1
  6. package/dist/data/db/expressions.js +84 -2
  7. package/dist/data/db/expressions.js.map +1 -1
  8. package/dist/data/db/filter.d.ts +13 -2
  9. package/dist/data/db/filter.d.ts.map +1 -1
  10. package/dist/data/db/filter.js +13 -2
  11. package/dist/data/db/filter.js.map +1 -1
  12. package/dist/data/db/namespace.d.ts +14 -1
  13. package/dist/data/db/namespace.d.ts.map +1 -1
  14. package/dist/data/db/namespace.js +3 -1
  15. package/dist/data/db/namespace.js.map +1 -1
  16. package/dist/data/domain/build-table.d.ts +9 -0
  17. package/dist/data/domain/build-table.d.ts.map +1 -1
  18. package/dist/data/domain/build-table.js +42 -27
  19. package/dist/data/domain/build-table.js.map +1 -1
  20. package/dist/data/domain/define.d.ts.map +1 -1
  21. package/dist/data/domain/define.js +7 -0
  22. package/dist/data/domain/define.js.map +1 -1
  23. package/dist/data/domain/external-registry.d.ts +8 -0
  24. package/dist/data/domain/external-registry.d.ts.map +1 -0
  25. package/dist/data/domain/external-registry.js +28 -0
  26. package/dist/data/domain/external-registry.js.map +1 -0
  27. package/dist/data/domain/external.d.ts +17 -0
  28. package/dist/data/domain/external.d.ts.map +1 -0
  29. package/dist/data/domain/external.js +59 -0
  30. package/dist/data/domain/external.js.map +1 -0
  31. package/dist/data/domain/index.d.ts +2 -1
  32. package/dist/data/domain/index.d.ts.map +1 -1
  33. package/dist/data/domain/index.js +1 -0
  34. package/dist/data/domain/index.js.map +1 -1
  35. package/dist/data/domain/types.d.ts +19 -0
  36. package/dist/data/domain/types.d.ts.map +1 -1
  37. package/dist/data/jsonb/namespace.d.ts +3 -1
  38. package/dist/data/jsonb/namespace.d.ts.map +1 -1
  39. package/dist/data/jsonb/namespace.js +3 -1
  40. package/dist/data/jsonb/namespace.js.map +1 -1
  41. package/dist/data/jsonb/query.d.ts +6 -0
  42. package/dist/data/jsonb/query.d.ts.map +1 -1
  43. package/dist/data/jsonb/query.js +14 -0
  44. package/dist/data/jsonb/query.js.map +1 -1
  45. package/dist/data/migrate/snapshot.d.ts.map +1 -1
  46. package/dist/data/migrate/snapshot.js +3 -0
  47. package/dist/data/migrate/snapshot.js.map +1 -1
  48. package/dist/data/write/delete.d.ts.map +1 -1
  49. package/dist/data/write/delete.js +2 -0
  50. package/dist/data/write/delete.js.map +1 -1
  51. package/dist/data/write/insert.d.ts.map +1 -1
  52. package/dist/data/write/insert.js +2 -0
  53. package/dist/data/write/insert.js.map +1 -1
  54. package/dist/data/write/update.d.ts.map +1 -1
  55. package/dist/data/write/update.js +2 -0
  56. package/dist/data/write/update.js.map +1 -1
  57. package/dist/data/write/upsert.d.ts.map +1 -1
  58. package/dist/data/write/upsert.js +2 -0
  59. package/dist/data/write/upsert.js.map +1 -1
  60. package/dist/index.d.ts +1 -1
  61. package/dist/index.d.ts.map +1 -1
  62. package/package.json +1 -1
  63. package/dist/infra/email/sigv4.d.ts +0 -24
  64. package/dist/infra/email/sigv4.d.ts.map +0 -1
  65. package/dist/infra/email/sigv4.js +0 -55
  66. package/dist/infra/email/sigv4.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.138.0
4
+
5
+ - **Added: `pipe.external(name, fields, { schema, table? })`, a table or view another service owns** (#644). Typed columns and every query operator, joins to `pipe.define` tables included; `schema` is required (`'public'` allowed), `table` defaults to the snake_case of `name`. Read-only: `pipe.insert/update/delete/upsert` on one is a compile error, and throws past the types. Never migrated: a schema module exporting one produces no statements, and keys, defaults and references on its fields are ignored. Not tenant-scoped (a `.tenant()` field throws) and not in `pipe.definitions()`. Its name is unique among definitions and externals.
6
+
7
+ ## 0.137.0
8
+
9
+ - **Added: text tests that never read the needle as a pattern** (#647). `filter.strpos(a, b)`, `textContains(a, b)` (`strpos > 0`), `startsWith(a, prefix)` (`starts_with`), `left(a, n)`, `right(a, n)`, `length(a)`. Strings are bound as `$n::text`, so `%`, `_` and `\` match only themselves.
10
+ - **Added: `filter.concat(...parts)`, text built with `||`** (#648). Each part a string (bound), a column or an expression (`scalar(...)` for a subquery); usable in `.set()`, `.values()` and `.where()`. A null part makes the result null, as SQL `||` does; wrap it in `coalesce` if not wanted. Fewer than two parts throws.
11
+ - **Added: `filter.arrayReplace(col, from, to)` and `filter.arrayHas(col, value)`** (#649). `array_replace` and `value = ANY(col)`, values bound and cast to the column's element type; a non-array column throws.
12
+ - **Added: `jsonb.merge(col, object)` (also `filter.jsonbMerge`)** (#650). `coalesce(col, '{}'::jsonb) || $::jsonb` in the statement, so a null column counts as `{}` and concurrent merges of different keys both survive. A non-object value throws.
13
+ - **Added: `filter.clockTimestamp()`** (#651). `clock_timestamp()`, the wall-clock time, which moves within a transaction where `now()` does not.
14
+ - **Changed: `filter.interval(n, unit)` binds `n`** (#652). It renders `($1::double precision * interval '1 <unit>')` instead of splicing the number into the statement; same signature and same values. A non-finite amount now throws.
15
+
3
16
  ## 0.136.0
4
17
 
5
18
  - **Added: `untrustedFetch.get(url, options)`, fetching one URL a stranger gave** (#640). Only `http:` and `https:`; the name is resolved and every address it resolves to is checked, and the connection goes to a checked address (pinned, with Host and TLS name kept as the hostname). Refused: loopback, private ranges, link-local (cloud metadata included), CGNAT, reserved, multicast, unspecified, unique-local, site-local and documentation IPv6, IPv4-mapped, IPv4-compatible and NAT64 forms of these, and literal IP URLs in them. Redirects are followed up to `maxRedirects`, each hop checked as the first, and the app's `headers` go only to the first origin. `maxBytes` stops the body the moment it is passed, whatever Content-Length says; `timeoutMs` covers the whole fetch; `accept({ status, contentType, firstBytes })` sees the first 1024 bytes before the body is kept. The three limits are required. A refusal is returned, not thrown, as `{ ok: false, reason, message }` with `reason` one of `scheme`, `address`, `redirects`, `too_large`, `timeout`, `status`, `rejected`, `network`, and a plain message that never carries an address or what a server sent. Traced as `pipework/fetch:get` (host; the full URL only with `urlIsSafeToTrace`) with a child `pipework/fetch:outcome` holding host, status, bytes and reason. `resolve` and `connect` options let a test say what a name resolves to and where the connection goes; the address check still runs.
package/REFERENCE.md CHANGED
@@ -707,6 +707,16 @@ The system channel — deliberate cross-tenant access for pre-tenant surfaces (a
707
707
 
708
708
  Query operators and aggregates — eq, gt, lt, and, or, count, sum, etc.
709
709
 
710
+ Expression helpers for `.set()`, `.values()` and `.where()` (a string or number argument is always a bound parameter):
711
+
712
+ - `filter.clockTimestamp()` — `clock_timestamp()`, the wall-clock time; unlike `now()` it advances within a transaction.
713
+ - `filter.interval(amount, unit)` — `($1::double precision * interval '1 <unit>')`, `amount` bound; a non-finite amount throws.
714
+ - `filter.strpos(a, b)`, `filter.textContains(a, b)`, `filter.startsWith(a, prefix)` — exact-text tests, no `%`/`_`/backslash wildcards (unlike `like`). `a`, `b`, `prefix` take a column, expression or string.
715
+ - `filter.left(a, n)`, `filter.right(a, n)`, `filter.length(a)` — text slices and length.
716
+ - `filter.concat(...parts)` — `(p1 || p2 || ...)`, at least two parts, each a string, column or expression (`scalar(...)` for a subquery). A null part makes the result null; wrap it in `coalesce` if not wanted.
717
+ - `filter.arrayReplace(col, from, to)` — `array_replace`, every `from` becomes `to`; `filter.arrayHas(col, value)` — `$value = ANY(col)`. `col` must be an array column; values are cast to its element type.
718
+ - `filter.jsonbMerge(col, object)` — same as `jsonb.merge`.
719
+
710
720
  ### `pipe.aliasedRelation`
711
721
 
712
722
 
@@ -838,6 +848,19 @@ interface ManagedConnection
838
848
  interface ConnectOptions
839
849
  ```
840
850
 
851
+ ### `pipe.external`
852
+
853
+ **`pipe.external(name, fields, { schema, table? })`** — Declares a table or view another service owns (for example `canvas.heads`) so this app can read it with typed columns and the normal operators: `select({...}).from(Ext).where(and(eq(Ext.repo, id))).orderBy(desc(Ext.baseOrdinal))`, joins to `pipe.define` tables included. `fields` are the same `pipe.field.*` descriptors; `schema` is required (a plain lowercase identifier, `'public'` allowed) and `table` defaults to the snake_case of `name`. Tables and views read the same way, so either works.
854
+
855
+ - Read-only: `pipe.insert/update/delete/upsert(Ext)` is a compile error, and a call past the types throws a `[pipework]` error.
856
+ - Never migrated: a schema module exporting one produces no CREATE, ALTER or DROP. Indexes, defaults, keys and references on its fields are ignored.
857
+ - Not tenant-scoped: a `.tenant()` field throws at declaration. Filter by the tenant column in the query.
858
+ - Not in `pipe.definitions()`, so RLS, audit and startup validation never see it. Its name must still be unique among definitions and externals.
859
+
860
+ ```typescript
861
+ const Heads = pipe.external('Heads', { repo: pipe.field.uuid(), sha: pipe.field.text() }, { schema: 'canvas', table: 'heads' })
862
+ ```
863
+
841
864
  ## jsonb — JSONB Column Helpers
842
865
 
843
866
  JSONB query operators — typed helpers for PostgreSQL JSONB containment, key checks, and field extraction.
@@ -846,6 +869,10 @@ JSONB query operators — typed helpers for PostgreSQL JSONB containment, key ch
846
869
 
847
870
  The @> containment operator — tests whether a JSONB column contains the given value.
848
871
 
872
+ ### `jsonb.merge`
873
+
874
+ Merges an object into a JSONB column in `.set()`: `coalesce(col, '{}'::jsonb) || value::jsonb`. Top-level keys of `value` overwrite, other keys are kept, a null column becomes `value`. The merge runs in the statement, so concurrent updates of different keys both survive. A value that is not a plain object (array, null, primitive) throws. Also `filter.jsonbMerge`.
875
+
849
876
  ### `jsonb.containedBy`
850
877
 
851
878
  The <@ contained-by operator — tests whether a JSONB column is contained by the given value.
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-09
4
+ > Generated: 2026-10-20
5
5
 
6
6
  ## Contents
7
7
 
@@ -10,6 +10,7 @@
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)
13
14
  - [auth — Authentication](#auth-authentication)
14
15
  - [rbac — Access Control](#rbac-access-control)
15
16
  - [tenant — Multi-Tenancy](#tenant-multi-tenancy)
@@ -30,7 +31,9 @@
30
31
  - [cache — Caching](#cache-caching)
31
32
  - [credits](#credits)
32
33
  - [mail](#mail)
34
+ - [untrustedFetch](#untrustedfetch)
33
35
  - [storage](#storage)
36
+ - [support](#support)
34
37
  - [webhook — Inbound & Outbound Webhooks](#webhook-inbound-outbound-webhooks)
35
38
  - [behavior — Resource Decorators](#behavior-resource-decorators)
36
39
  - [fitting — Dependency Injection](#fitting-dependency-injection)
@@ -85,6 +88,18 @@ function createManifold<const TEnv extends EnvDefs = EnvDefs>( raw: Omit<Bluepri
85
88
  interface Manifold<TEnv extends EnvDefs = EnvDefs>
86
89
  ```
87
90
 
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
+
88
103
  **`SeedOptions`** — ALS context the {@link Manifold.seed} callback runs under — tenant scope, auth principal, and job type.
89
104
 
90
105
  ```typescript
@@ -229,6 +244,14 @@ Creates a job queue with claim/complete/fail lifecycle, heartbeat, and dead lett
229
244
 
230
245
  Executes a fitting handler as a background job with its own Flow context.
231
246
 
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
+
232
255
  ### `jobs.parseCron`
233
256
 
234
257
  Parses a 5-field cron expression into a CronSchedule (minute, hour, dom, month, dow).
@@ -269,6 +292,14 @@ Thrown when a transition is not allowed from the current state.
269
292
 
270
293
  Thrown when the state machine definition is internally inconsistent.
271
294
 
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
+
272
303
  ## auth — Authentication
273
304
 
274
305
  Authentication namespace — session management, multi-org support, auth chain resolution.
@@ -289,6 +320,10 @@ Hashes and verifies passwords with scrypt; reports when a stored hash needs reha
289
320
 
290
321
  Guarded password sign-in that slows, then refuses, repeated failures per account and per client.
291
322
 
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
+
292
327
  ### `auth.runChain`
293
328
 
294
329
  Executes an auth chain (strategy pipeline) to resolve auth + tenant from a request.
@@ -323,7 +358,7 @@ interface AuthContext
323
358
  interface AuthStrategy<TAuth>
324
359
  ```
325
360
 
326
- **`AuthRequest`** — Normalized request shape passed to auth strategies — headers, cookies, method, url.
361
+ **`AuthRequest`** — Normalized request shape passed to auth strategies — headers, the parsed `Cookie` header, and the upper-case HTTP method.
327
362
 
328
363
  ```typescript
329
364
  interface AuthRequest
@@ -353,6 +388,18 @@ interface TenantResolver<TAuth>
353
388
  interface AuthChainConfig<TAuth>
354
389
  ```
355
390
 
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
+
356
403
  **`SessionConfig`** — Session configuration — signing keys, issuer, audience, token TTLs, refresh rotation.
357
404
 
358
405
  ```typescript
@@ -624,6 +671,10 @@ Base error class with code, statusCode, and suggestion fields.
624
671
 
625
672
  403 — authenticated but insufficient permissions.
626
673
 
674
+ ### `errors.CrossSiteRequest`
675
+
676
+ 403 `CROSS_SITE_REQUEST` — a cookie-authenticated write that did not come from the app's own site.
677
+
627
678
  ### `errors.Validation`
628
679
 
629
680
  422 — input validation failed, carries field-level details.
@@ -644,13 +695,17 @@ Base error class with code, statusCode, and suggestion fields.
644
695
 
645
696
  415 — request body media type not accepted by the route.
646
697
 
698
+ ### `errors.MalformedMultipart`
699
+
700
+ 400 `MALFORMED_MULTIPART` — a multipart body that cannot be parsed or ends before its closing boundary.
701
+
647
702
  ## lifecycle — Startup & Shutdown
648
703
 
649
704
  Application lifecycle namespace — startup orchestration with hooks and timeouts.
650
705
 
651
706
  ### `lifecycle.orchestrate`
652
707
 
653
- Runs pre-start hooks (DB readiness checks, migrations, etc.) with a configurable timeout.
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.
654
709
 
655
710
  ## log — Structured Logging
656
711
 
@@ -690,7 +745,7 @@ Creates a worker surface — a long-running process that claims and executes job
690
745
 
691
746
  ### `surface.script`
692
747
 
693
- Creates a script surface — a one-shot process that runs and exits (migrations, seeds, CLI tools).
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.
694
749
 
695
750
  ## pipe — Database
696
751
 
@@ -787,7 +842,7 @@ Pipework-owned UPDATE builder — the only consumer-facing way to update pipewor
787
842
 
788
843
  ### `pipe.insert`
789
844
 
790
- Pipework-owned INSERT builder — the only consumer-facing way to insert into pipework-managed tables (Q8).
845
+ 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.
791
846
 
792
847
  ### `pipe.delete`
793
848
 
@@ -795,7 +850,7 @@ Pipework-owned DELETE builder — the only consumer-facing way to delete from pi
795
850
 
796
851
  ### `pipe.upsert`
797
852
 
798
- Pipework-owned UPSERT builder — insert with conflict resolution (Q8).
853
+ 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.
799
854
 
800
855
  ### Types
801
856
 
@@ -947,6 +1002,14 @@ Query all versions of temporal records (no date filter).
947
1002
 
948
1003
  Close the current version and create a new one with updated data.
949
1004
 
1005
+ ### `temporal.setVersion`
1006
+
1007
+ Append the next version of an append-only-versions definition: serialised per scope, numbered, never back-dated, audited.
1008
+
1009
+ ### `temporal.versionAt`
1010
+
1011
+ The version in force at a moment: the row with the greatest effectiveFrom at or before it.
1012
+
950
1013
  ## valve
951
1014
 
952
1015
  Valve namespace — typed, directional, gated boundaries between code silos.
@@ -1129,6 +1192,18 @@ Alerts namespace — raise and resolve keyed conditions, grouped, delivered to s
1129
1192
 
1130
1193
  Creates an alerts handle.
1131
1194
 
1195
+ ### `alerts.http`
1196
+
1197
+ Routes for an operations agent: list, get, totals, delivery health, acknowledge, resolve, link; bearer credentials.
1198
+
1199
+ ### `alerts.clientFaults`
1200
+
1201
+ 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`.
1202
+
1203
+ ### `alerts.requestFaults`
1204
+
1205
+ An `onInternalError` hook for the HTTP server: raises `request-fault:<METHOD> <route>` for each internal 500.
1206
+
1132
1207
  ### `alerts.webhook`
1133
1208
 
1134
1209
  A sink that POSTs the alert as signed JSON to a URL.
@@ -1161,6 +1236,10 @@ The newest record's `{ seq, hash }` in the tenant's audit hash chain (blueprint
1161
1236
 
1162
1237
  Walks the tenant's audit hash chain and reports the first break (hash-mismatch, prev-mismatch, missing, head-mismatch, anchor-mismatch), or `{ ok: true }`.
1163
1238
 
1239
+ ### `audit.removeTenant`
1240
+
1241
+ 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.
1242
+
1164
1243
  ## cache — Caching
1165
1244
 
1166
1245
  In-memory caching namespace — TTL-based with stats, preload, and tenant-aware variants.
@@ -1213,6 +1292,36 @@ Inbound source: SES receipt rule storing raw messages in S3 and notifying a sign
1213
1292
 
1214
1293
  Inbound development source: `.eml` files dropped in a folder, received by `scan()`; refused in production.
1215
1294
 
1295
+ ## untrustedFetch
1296
+
1297
+ Untrusted fetch — fetch one URL a stranger gave without letting them reach the app's private network.
1298
+
1299
+ ### `untrustedFetch.get`
1300
+
1301
+ Fetches `url` with GET and returns `{ ok: true, url, status, contentType, body, bytes }`, or `{ ok: false, reason, message }`
1302
+ naming the rule that refused: `scheme`, `address`, `redirects`, `too_large`, `timeout`, `status`, `rejected` or `network`.
1303
+ It does not throw for these.
1304
+
1305
+ Rules, none of which can be switched off: only `http:` and `https:`; the name is resolved and every address is checked
1306
+ (loopback, private, link-local including cloud metadata, CGNAT, unique-local and site-local IPv6, multicast, reserved,
1307
+ unspecified, and IPv4-mapped or NAT64 forms of these; literal IP URLs likewise) and the connection goes to a checked
1308
+ 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;
1309
+ the body is stopped the moment it passes `maxBytes`, whatever Content-Length says; `timeoutMs` covers the whole fetch.
1310
+ `accept({ status, contentType, firstBytes })` sees the first 1024 bytes before the body is kept: return false, or a string
1311
+ (your own message), to refuse with `rejected`. Messages never contain an address or anything a server sent.
1312
+
1313
+ `resolve` and `connect` are for tests: `resolve(hostname)` replaces DNS and `connect(target)` replaces the socket after the
1314
+ address check passed, so a test sends a fake public address to a local server. The address check always runs on what `resolve` returns.
1315
+
1316
+ The call is the trace step `pipework/fetch:get`; its child `pipework/fetch:outcome` carries host, status, bytes and reason.
1317
+ The full URL is recorded only when `urlIsSafeToTrace` is true; otherwise only the host.
1318
+
1319
+ ```ts
1320
+ const got = await untrustedFetch.get(pasted, { maxBytes: 5_000_000, timeoutMs: 10_000, maxRedirects: 3,
1321
+ accept: h => h.firstBytes[0] === 0x25 || 'That does not look like a PDF.' })
1322
+ if (!got.ok) return tell(got.message)
1323
+ ```
1324
+
1216
1325
  ## storage
1217
1326
 
1218
1327
  Storage namespace — tenant-scoped, content-addressed file storage with signed URLs and retention.
@@ -1229,6 +1338,18 @@ S3-compatible backend (AWS S3, MinIO, R2): SigV4 over `fetch`, multipart streami
1229
1338
 
1230
1339
  Local-disk backend for development and tests; refused in production.
1231
1340
 
1341
+ ## support
1342
+
1343
+ Support namespace — tickets from email (and later chat), with replies sent only after an approval.
1344
+
1345
+ ### `support.create`
1346
+
1347
+ Creates the support handle: tickets, messages, notes, links, drafts, `approve`, `receiveEmail`, and the events job.
1348
+
1349
+ ### `support.templates`
1350
+
1351
+ The reply template to spread into `mail.create({ templates })`; it renders the approved draft verbatim.
1352
+
1232
1353
  ## webhook — Inbound & Outbound Webhooks
1233
1354
 
1234
1355
  Webhook namespace — inbound verification, outbound delivery with retries, HMAC signing.
@@ -1319,6 +1440,10 @@ Returns the current Flow or undefined — use for optional context detection.
1319
1440
 
1320
1441
  Creates a Flow for test isolation with optional auth and tenant overrides.
1321
1442
 
1443
+ ### `flow.actAs`
1444
+
1445
+ 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.
1446
+
1322
1447
  ## http — Server
1323
1448
 
1324
1449
  HTTP namespace: `http.file()` builds a file response; the server itself is managed by manifold.start().
@@ -1343,6 +1468,36 @@ interface SecurityConfig
1343
1468
  interface RateLimitConfig
1344
1469
  ```
1345
1470
 
1471
+ **`RateLimitWindow`** — One fixed window: at most `max` requests per `windowSeconds`.
1472
+
1473
+ ```typescript
1474
+ interface RateLimitWindow
1475
+ ```
1476
+
1477
+ **`RateLimitClass`** — A named limit class: any of a per-user, per-tenant and per-address window, each counted on its own.
1478
+
1479
+ ```typescript
1480
+ interface RateLimitClass
1481
+ ```
1482
+
1483
+ **`RateLimitRefusal`** — What `onRefused` is told about one refused window of one request.
1484
+
1485
+ ```typescript
1486
+ interface RateLimitRefusal
1487
+ ```
1488
+
1489
+ **`RateLimitClassesConfig`**
1490
+
1491
+ Named limit classes, checked after auth and counted in Postgres (`pipework_rate_limit_counts`, opted in
1492
+ with the blueprint's `rateLimits: {}`), so every server process on the same database shares one count.
1493
+ Windows are counted perUser, perTenant, perAddress in turn, up to the first one over its max, so one user's
1494
+ refused requests don't spend the tenant's budget. A route is in `signedIn` (auth required, or optional with
1495
+ a user), `public` (no auth, or optional without a user) or the class its fitting names with `.rateLimit(name)`.
1496
+
1497
+ ```typescript
1498
+ interface RateLimitClassesConfig
1499
+ ```
1500
+
1346
1501
  **`InjectOptions`** — Options for server.inject() — method, url, headers, payload for testing without HTTP.
1347
1502
 
1348
1503
  ```typescript
@@ -1361,6 +1516,12 @@ interface InjectResponse
1361
1516
  interface ServerConfig
1362
1517
  ```
1363
1518
 
1519
+ **`InternalErrorFault`** — What `onInternalError` is told about one request that ended in an internal error.
1520
+
1521
+ ```typescript
1522
+ interface InternalErrorFault
1523
+ ```
1524
+
1364
1525
  **`HandlerResponse`** — Standard handler response shape — statusCode, headers, body.
1365
1526
 
1366
1527
  ```typescript
@@ -1419,7 +1580,7 @@ Generates an OpenAPI 3.1 document from route registrations — schemas derived f
1419
1580
 
1420
1581
  ## trace
1421
1582
 
1422
- Trace namespace — hand the current trace to a process outside Node and record the steps it reports back.
1583
+ 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.
1423
1584
 
1424
1585
  ### `trace.traceparent`
1425
1586
 
@@ -1433,6 +1594,15 @@ W3C `traceparent` for the current trace and open step; `null` outside a traced f
1433
1594
 
1434
1595
  Records steps reported as JSON lines (or objects) by an outside process under the step open now. Synchronous; never throws.
1435
1596
 
1597
+ ### `trace.event`
1598
+
1599
+ 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.
1600
+
1601
+ ### `trace.tree`
1602
+
1603
+ Reads every hot trace sharing `rootId` (a request's trace and the jobs it queued) with their steps. Runs on the
1604
+ given `db`, so tenant policies apply: only an unrestricted connection (table owner, tests) sees every tenant's rows.
1605
+
1436
1606
  ### Types
1437
1607
 
1438
1608
  **`FlowStepMeta`** — Trace metadata for one documented flow-step: its `path:symbol` graph node id and the per-argument capture projections.
@@ -1453,6 +1623,24 @@ type ExternalStepReport = z.infer<typeof externalStepReportSchema>
1453
1623
  interface ExternalRecordResult
1454
1624
  ```
1455
1625
 
1626
+ **`TraceStepNode`** — One step of a trace. `ref` is the flow step's `path:symbol`, or `external:<name>` for a recorded or point-event step.
1627
+
1628
+ ```typescript
1629
+ interface TraceStepNode
1630
+ ```
1631
+
1632
+ **`TraceNode`** — One trace of the tree, with its steps ordered by `seq`.
1633
+
1634
+ ```typescript
1635
+ interface TraceNode
1636
+ ```
1637
+
1638
+ **`TraceTree`** — The traces that share a root id, ordered by when they opened.
1639
+
1640
+ ```typescript
1641
+ interface TraceTree
1642
+ ```
1643
+
1456
1644
  ## data
1457
1645
 
1458
1646
  ### `tap`
@@ -18,8 +18,35 @@ export declare function scalar<T>(subquery: SQLWrapper): SQL<T>;
18
18
  export type IntervalUnit = 'microseconds' | 'milliseconds' | 'seconds' | 'minutes' | 'hours' | 'days' | 'weeks' | 'months' | 'years';
19
19
  /** PostgreSQL type cast: `expression::pgType`. */
20
20
  export declare function cast<T = unknown>(expression: SQL | Column | SQLWrapper, pgType: string): SQL<T>;
21
- /** PostgreSQL interval literal: `interval '5 minutes'`. */
21
+ /** PostgreSQL interval of `amount` units, `amount` bound as a parameter: `($1::double precision * interval '1 minute')`. Throws for a non-finite amount. */
22
22
  export declare function interval(amount: number, unit: IntervalUnit): SQL;
23
+ /** PostgreSQL `clock_timestamp()` — the actual wall-clock time, which advances within a transaction (unlike `now()`). */
24
+ export declare function clockTimestamp(): SQL<Date>;
25
+ /** A text operand: a column, an expression, or a string (bound as `$n::text`). */
26
+ export type TextArg = Column | SQL | string;
27
+ /** PostgreSQL `strpos(a, b)` — 1-based position of `b` in `a`, 0 when absent. Strings are bound as text, so `%`, `_` and `\` are plain characters. */
28
+ export declare function strpos(a: TextArg, b: TextArg): SQL<number>;
29
+ /** True when `a` contains the exact text `b`: `strpos(a, b) > 0`. Unlike `like`, no character in `b` is a wildcard. */
30
+ export declare function textContains(a: TextArg, b: TextArg): SQL<boolean>;
31
+ /** PostgreSQL `starts_with(a, prefix)` — true when `a` begins with the exact text `prefix`; no wildcards. */
32
+ export declare function startsWith(a: TextArg, prefix: TextArg): SQL<boolean>;
33
+ /** PostgreSQL `left(a, n)` — the first `n` characters of `a`. */
34
+ export declare function left(a: TextArg, n: number | Column | SQL): SQL<string>;
35
+ /** PostgreSQL `right(a, n)` — the last `n` characters of `a`. */
36
+ export declare function right(a: TextArg, n: number | Column | SQL): SQL<string>;
37
+ /** PostgreSQL `length(a)` — the number of characters in `a`. */
38
+ export declare function length(a: TextArg): SQL<number>;
39
+ /**
40
+ * Text concatenation: `(p1 || p2 || ...)`. Strings are bound as text. A null part makes
41
+ * the whole result null (SQL `||`); wrap such a part in `coalesce` if that is not wanted.
42
+ * Wrap a subquery with `scalar(...)`.
43
+ */
44
+ export declare function concat(...parts: Array<string | Column | SQL>): SQL<string>;
45
+ type ElementOf<C extends Column> = C['_']['data'] extends ReadonlyArray<infer E> ? E : never;
46
+ /** PostgreSQL `array_replace(col, from, to)` — every element equal to `from` becomes `to`. `from`/`to` are bound and cast to the column's element type. */
47
+ export declare function arrayReplace<C extends Column>(col: C, from: ElementOf<C>, to: ElementOf<C>): SQL<C['_']['data']>;
48
+ /** True when the array column holds `value`: `$value::<element> = ANY(col)`. `value` is bound and cast to the column's element type. */
49
+ export declare function arrayHas<C extends Column>(col: C, value: ElementOf<C>): SQL<boolean>;
23
50
  /** PostgreSQL `date_trunc('unit', column)` — truncates a timestamp to the given precision. */
24
51
  export declare function dateTrunc(unit: 'microseconds' | 'milliseconds' | 'second' | 'minute' | 'hour' | 'day' | 'week' | 'month' | 'quarter' | 'year' | 'decade' | 'century' | 'millennium', column: Column | SQL): SQL<Date>;
25
52
  /** PostgreSQL `ROW_NUMBER()` window function. Use with `over()` to apply a window specification. */
@@ -56,4 +83,5 @@ export declare function walCurrentLsn(): SQL<string>;
56
83
  export declare function walReplayLsn(): SQL<string | null>;
57
84
  /** PostgreSQL `pg_last_wal_replay_lsn() >= lsn::pg_lsn` — true once a replica has replayed up to the given LSN. Yields NULL (not true) on a primary, where there is no replay position. */
58
85
  export declare function replicaFresh(createdLsn: string | Column | SQL): SQL<boolean | null>;
86
+ export {};
59
87
  //# sourceMappingURL=expressions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"expressions.d.ts","sourceRoot":"","sources":["../../../src/data/db/expressions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAC7C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAErD,uEAAuE;AACvE,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG,EAAE,MAAM,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,CAE3E;AAED,mGAAmG;AACnG,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG,EAAE,MAAM,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,CAE3E;AAED,oGAAoG;AACpG,wBAAgB,GAAG,CAAC,CAAC,GAAG,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,GAAG,EAAE,KAAK,EAAE,MAAM,GAAG,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,CAEhF;AAED,oGAAoG;AACpG,wBAAgB,QAAQ,CAAC,CAAC,GAAG,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,GAAG,EAAE,KAAK,EAAE,MAAM,GAAG,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,CAErF;AAED,8FAA8F;AAC9F,wBAAgB,QAAQ,CAAC,CAAC,EAAE,UAAU,EAAE,GAAG,GAAG,MAAM,EAAE,YAAY,EAAE,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAE7E;AAED,2FAA2F;AAC3F,wBAAgB,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,CAE/B;A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GAAG,IAAI,CAAC,CAEnF"}
@@ -31,9 +31,91 @@ export function scalar(subquery) {
31
31
  export function cast(expression, pgType) {
32
32
  return sql `(${expression})::${sql.raw(pgType)}`;
33
33
  }
34
- /** PostgreSQL interval literal: `interval '5 minutes'`. */
34
+ const INTERVAL_UNIT_SINGULAR = {
35
+ microseconds: 'microsecond',
36
+ milliseconds: 'millisecond',
37
+ seconds: 'second',
38
+ minutes: 'minute',
39
+ hours: 'hour',
40
+ days: 'day',
41
+ weeks: 'week',
42
+ months: 'month',
43
+ years: 'year',
44
+ };
45
+ /** PostgreSQL interval of `amount` units, `amount` bound as a parameter: `($1::double precision * interval '1 minute')`. Throws for a non-finite amount. */
35
46
  export function interval(amount, unit) {
36
- return sql `interval '${sql.raw(String(amount))} ${sql.raw(unit)}'`;
47
+ if (!Number.isFinite(amount)) {
48
+ throw new Error(`[pipework] interval() needs a finite amount, got ${String(amount)}.\n\n` +
49
+ ' NaN and Infinity are not valid interval amounts.\n' +
50
+ " Fix: pass a finite number: interval(5, 'minutes').\n");
51
+ }
52
+ return sql `(${amount}::double precision * interval '1 ${sql.raw(INTERVAL_UNIT_SINGULAR[unit])}')`;
53
+ }
54
+ /** PostgreSQL `clock_timestamp()` — the actual wall-clock time, which advances within a transaction (unlike `now()`). */
55
+ export function clockTimestamp() {
56
+ return sql `clock_timestamp()`;
57
+ }
58
+ function textArg(value) {
59
+ return typeof value === 'string' ? sql `${value}::text` : sql `${value}`;
60
+ }
61
+ function intArg(value) {
62
+ return typeof value === 'number' ? sql `${value}::int` : sql `${value}`;
63
+ }
64
+ /** PostgreSQL `strpos(a, b)` — 1-based position of `b` in `a`, 0 when absent. Strings are bound as text, so `%`, `_` and `\` are plain characters. */
65
+ export function strpos(a, b) {
66
+ return sql `strpos(${textArg(a)}, ${textArg(b)})`;
67
+ }
68
+ /** True when `a` contains the exact text `b`: `strpos(a, b) > 0`. Unlike `like`, no character in `b` is a wildcard. */
69
+ export function textContains(a, b) {
70
+ return sql `${strpos(a, b)} > 0`;
71
+ }
72
+ /** PostgreSQL `starts_with(a, prefix)` — true when `a` begins with the exact text `prefix`; no wildcards. */
73
+ export function startsWith(a, prefix) {
74
+ return sql `starts_with(${textArg(a)}, ${textArg(prefix)})`;
75
+ }
76
+ /** PostgreSQL `left(a, n)` — the first `n` characters of `a`. */
77
+ export function left(a, n) {
78
+ return sql `left(${textArg(a)}, ${intArg(n)})`;
79
+ }
80
+ /** PostgreSQL `right(a, n)` — the last `n` characters of `a`. */
81
+ export function right(a, n) {
82
+ return sql `right(${textArg(a)}, ${intArg(n)})`;
83
+ }
84
+ /** PostgreSQL `length(a)` — the number of characters in `a`. */
85
+ export function length(a) {
86
+ return sql `length(${textArg(a)})`;
87
+ }
88
+ /**
89
+ * Text concatenation: `(p1 || p2 || ...)`. Strings are bound as text. A null part makes
90
+ * the whole result null (SQL `||`); wrap such a part in `coalesce` if that is not wanted.
91
+ * Wrap a subquery with `scalar(...)`.
92
+ */
93
+ export function concat(...parts) {
94
+ if (parts.length < 2) {
95
+ throw new Error(`[pipework] concat() needs at least two parts, got ${parts.length}.\n\n` +
96
+ ' A concatenation of fewer than two parts is not a concatenation.\n' +
97
+ " Fix: pass two or more parts: concat('prefix: ', column).\n");
98
+ }
99
+ return sql `(${sql.join(parts.map(textArg), sql ` || `)})`;
100
+ }
101
+ function elementType(column, helper) {
102
+ const type = column.getSQLType();
103
+ if (!type.endsWith('[]')) {
104
+ throw new Error(`[pipework] ${helper}() needs an array column, got "${column.name}" of type ${type}.\n\n` +
105
+ ' The element type is read from the column, so it must be an array column.\n' +
106
+ ` Fix: pass an array column (for example uuid('ids').array()) to ${helper}().\n`);
107
+ }
108
+ return type.slice(0, -2);
109
+ }
110
+ /** PostgreSQL `array_replace(col, from, to)` — every element equal to `from` becomes `to`. `from`/`to` are bound and cast to the column's element type. */
111
+ export function arrayReplace(col, from, to) {
112
+ const el = sql.raw(elementType(col, 'arrayReplace'));
113
+ return sql `array_replace(${col}, ${from}::${el}, ${to}::${el})`;
114
+ }
115
+ /** True when the array column holds `value`: `$value::<element> = ANY(col)`. `value` is bound and cast to the column's element type. */
116
+ export function arrayHas(col, value) {
117
+ const el = sql.raw(elementType(col, 'arrayHas'));
118
+ return sql `${value}::${el} = ANY(${col})`;
37
119
  }
38
120
  /** PostgreSQL `date_trunc('unit', column)` — truncates a timestamp to the given precision. */
39
121
  export function dateTrunc(unit, column) {
@@ -1 +1 @@
1
- {"version":3,"file":"expressions.js","sourceRoot":"","sources":["../../../src/data/db/expressions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAI9B,uEAAuE;AACvE,MAAM,UAAU,SAAS,CAAC,MAAoB,EAAE,MAAc;IAC5D,OAAO,GAAG,CAAQ,GAAG,MAAM,MAAM,MAAM,EAAE,CAAA;AAC3C,CAAC;AAED,mGAAmG;AACnG,MAAM,UAAU,SAAS,CAAC,MAAoB,EAAE,MAAc;IAC5D,OAAO,GAAG,CAAQ,GAAG,MAAM,MAAM,MAAM,EAAE,CAAA;AAC3C,CAAC;AAED,oGAAoG;AACpG,MAAM,UAAU,GAAG,CAAc,IAAkB,EAAE,KAAmB;IACtE,OAAO,GAAG,CAAG,GAAG,IAAI,MAAM,KAAK,EAAE,CAAA;AACnC,CAAC;AAED,oGAAoG;AACpG,MAAM,UAAU,QAAQ,CAAc,IAAkB,EAAE,KAAmB;IAC3E,OAAO,GAAG,CAAG,GAAG,IAAI,MAAM,KAAK,EAAE,CAAA;AACnC,CAAC;AAED,8FAA8F;AAC9F,MAAM,UAAU,QAAQ,CAAI,UAAwB,EAAE,YAAe;IACnE,OAAO,GAAG,CAAG,YAAY,UAAU,KAAK,YAAY,GAAG,CAAA;AACzD,CAAC;AAED,2FAA2F;AAC3F,MAAM,UAAU,GAAG;IACjB,OAAO,GAAG,CAAM,OAAO,CAAA;AACzB,CAAC;AAED,gGAAgG;AAChG,MAAM,UAAU,MAAM,CAAI,QAAoB;IAC5C,OAAO,GA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