pipework 0.10.8 → 0.12.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 (74) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/REFERENCE.md +167 -7
  3. package/dist/REFERENCE.md +1033 -0
  4. package/dist/async/jobs/execute.d.ts.map +1 -1
  5. package/dist/async/jobs/execute.js +13 -4
  6. package/dist/async/jobs/execute.js.map +1 -1
  7. package/dist/auth/auth/chain.js +2 -2
  8. package/dist/auth/auth/chain.js.map +1 -1
  9. package/dist/core/errors/base.d.ts +7 -0
  10. package/dist/core/errors/base.d.ts.map +1 -1
  11. package/dist/core/errors/base.js +22 -0
  12. package/dist/core/errors/base.js.map +1 -1
  13. package/dist/core/errors/index.d.ts +1 -1
  14. package/dist/core/errors/index.d.ts.map +1 -1
  15. package/dist/core/errors/index.js +1 -1
  16. package/dist/core/errors/index.js.map +1 -1
  17. package/dist/core/pipework.d.ts +1 -0
  18. package/dist/core/pipework.d.ts.map +1 -1
  19. package/dist/core/pipework.js.map +1 -1
  20. package/dist/core/runtime/broker.d.ts +10 -0
  21. package/dist/core/runtime/broker.d.ts.map +1 -0
  22. package/dist/core/runtime/broker.js +57 -0
  23. package/dist/core/runtime/broker.js.map +1 -0
  24. package/dist/data/db/expressions.d.ts +3 -0
  25. package/dist/data/db/expressions.d.ts.map +1 -1
  26. package/dist/data/db/expressions.js.map +1 -1
  27. package/dist/data/db/serializable.d.ts +1 -0
  28. package/dist/data/db/serializable.d.ts.map +1 -1
  29. package/dist/data/db/serializable.js.map +1 -1
  30. package/dist/data/db/values.d.ts +1 -0
  31. package/dist/data/db/values.d.ts.map +1 -1
  32. package/dist/data/db/values.js.map +1 -1
  33. package/dist/data/write/delete.d.ts +2 -2
  34. package/dist/data/write/delete.d.ts.map +1 -1
  35. package/dist/data/write/delete.js.map +1 -1
  36. package/dist/data/write/insert.d.ts +2 -2
  37. package/dist/data/write/insert.d.ts.map +1 -1
  38. package/dist/data/write/insert.js.map +1 -1
  39. package/dist/data/write/update.d.ts +2 -2
  40. package/dist/data/write/update.d.ts.map +1 -1
  41. package/dist/data/write/update.js.map +1 -1
  42. package/dist/data/write/upsert.d.ts +2 -2
  43. package/dist/data/write/upsert.d.ts.map +1 -1
  44. package/dist/data/write/upsert.js.map +1 -1
  45. package/dist/index.d.ts +2 -2
  46. package/dist/index.d.ts.map +1 -1
  47. package/dist/index.js +1 -1
  48. package/dist/index.js.map +1 -1
  49. package/dist/request/context/store.d.ts +1 -2
  50. package/dist/request/context/store.d.ts.map +1 -1
  51. package/dist/request/context/store.js +6 -2
  52. package/dist/request/context/store.js.map +1 -1
  53. package/dist/request/di/builder.d.ts +45 -21
  54. package/dist/request/di/builder.d.ts.map +1 -1
  55. package/dist/request/di/builder.js +23 -0
  56. package/dist/request/di/builder.js.map +1 -1
  57. package/dist/request/di/index.d.ts +2 -2
  58. package/dist/request/di/index.d.ts.map +1 -1
  59. package/dist/request/di/resolve.d.ts +26 -1
  60. package/dist/request/di/resolve.d.ts.map +1 -1
  61. package/dist/request/di/resolve.js +42 -4
  62. package/dist/request/di/resolve.js.map +1 -1
  63. package/dist/request/di/types.d.ts +23 -0
  64. package/dist/request/di/types.d.ts.map +1 -1
  65. package/dist/request/fitting/namespace.d.ts +1 -1
  66. package/dist/request/fitting/namespace.d.ts.map +1 -1
  67. package/dist/request/fixture/to-handlers.d.ts.map +1 -1
  68. package/dist/request/fixture/to-handlers.js +1 -0
  69. package/dist/request/fixture/to-handlers.js.map +1 -1
  70. package/dist/request/http/server.js +2 -2
  71. package/dist/request/http/server.js.map +1 -1
  72. package/dist/trace/runtime/step-meta.d.ts +1 -0
  73. package/dist/trace/runtime/step-meta.d.ts.map +1 -1
  74. package/package.json +2 -1
@@ -0,0 +1,1033 @@
1
+ # Pipework API Reference
2
+
3
+ > Auto-generated from source JSDoc. Do not edit manually.
4
+ > Generated: 2026-06-29
5
+
6
+ ## Contents
7
+
8
+ - [Core](#core)
9
+ - [jobs — Background Jobs](#jobs-background-jobs)
10
+ - [pipeline — Multi-Step Pipelines](#pipeline-multi-step-pipelines)
11
+ - [state — State Machines](#state-state-machines)
12
+ - [auth — Authentication](#auth-authentication)
13
+ - [rbac — Access Control](#rbac-access-control)
14
+ - [tenant — Multi-Tenancy](#tenant-multi-tenancy)
15
+ - [config — Configuration](#config-configuration)
16
+ - [errors — Error Classes](#errors-error-classes)
17
+ - [lifecycle — Startup & Shutdown](#lifecycle-startup-shutdown)
18
+ - [log — Structured Logging](#log-structured-logging)
19
+ - [surface — Entry Points](#surface-entry-points)
20
+ - [pipe — Database](#pipe-database)
21
+ - [jsonb — JSONB Column Helpers](#jsonb-jsonb-column-helpers)
22
+ - [schema — Validation & Schema](#schema-validation-schema)
23
+ - [temporal — Bitemporal Data](#temporal-bitemporal-data)
24
+ - [valve](#valve)
25
+ - [vector — Vector & Full-Text Search](#vector-vector-full-text-search)
26
+ - [audit — Audit Logging](#audit-audit-logging)
27
+ - [cache — Caching](#cache-caching)
28
+ - [webhook — Inbound & Outbound Webhooks](#webhook-inbound-outbound-webhooks)
29
+ - [behavior — Resource Decorators](#behavior-resource-decorators)
30
+ - [fitting — Dependency Injection](#fitting-dependency-injection)
31
+ - [fixture — REST Resources](#fixture-rest-resources)
32
+ - [flow — Context (AsyncLocalStorage)](#flow-context-asynclocalstorage)
33
+ - [http — Server](#http-server)
34
+ - [openapi — API Documentation](#openapi-api-documentation)
35
+ - [test](#test)
36
+ - [trace](#trace)
37
+
38
+ ## Core
39
+
40
+ Application instance and foundational types.
41
+
42
+ ### `createManifold`
43
+
44
+ Creates the Pipework application instance. This is the entry point for every Pipework app. Define in `pipework.config.ts` and export as default. /
45
+
46
+ ```typescript
47
+ function createManifold<const TEnv extends EnvDefs = EnvDefs>( raw: Omit<BlueprintInput, 'env'> &
48
+ ```
49
+
50
+ ### Types
51
+
52
+ **`Manifold`** — The application instance — holds config, connection pools, surfaces, and lifecycle.
53
+
54
+ ```typescript
55
+ interface Manifold<TEnv extends EnvDefs = EnvDefs>
56
+ ```
57
+
58
+ **`SeedOptions`** — ALS context the {@link Manifold.seed} callback runs under — tenant scope, auth principal, and job type.
59
+
60
+ ```typescript
61
+ interface SeedOptions
62
+ ```
63
+
64
+ **`PoolState`** — Manages database connection pools keyed by database name.
65
+
66
+ ```typescript
67
+ interface PoolState
68
+ ```
69
+
70
+ **`IsolationState`** — Tracks test isolation lifecycle — detects leaked isolation contexts.
71
+
72
+ ```typescript
73
+ interface IsolationState
74
+ ```
75
+
76
+ **`ConnectionTracker`** — Tracks active database connections for leak detection.
77
+
78
+ ```typescript
79
+ interface ConnectionTracker
80
+ ```
81
+
82
+ ## jobs — Background Jobs
83
+
84
+ Background job queue namespace — Postgres-backed with SKIP LOCKED, LISTEN/NOTIFY, cron scheduling.
85
+
86
+ ### `jobs.createQueue`
87
+
88
+ Creates a job queue with claim/complete/fail lifecycle, heartbeat, and dead letter requeue.
89
+
90
+ ### `jobs.execute`
91
+
92
+ Executes a fitting handler as a background job with its own Flow context.
93
+
94
+ ### `jobs.parseCron`
95
+
96
+ Parses a 5-field cron expression into a CronSchedule (minute, hour, dom, month, dow).
97
+
98
+ ### `jobs.nextTick`
99
+
100
+ Computes the next fire time for a CronSchedule after a given date, with optional timezone.
101
+
102
+ ## pipeline — Multi-Step Pipelines
103
+
104
+ Multi-step pipeline namespace — define, execute, pause, and resume ordered step sequences.
105
+
106
+ ### `pipeline.define`
107
+
108
+ Defines a pipeline from a config of named steps with handlers. Returns a Pipeline with execute/resume/getStatus.
109
+
110
+ ### `pipeline.PipelineStepError`
111
+
112
+ Thrown when an individual pipeline step fails.
113
+
114
+ ### `pipeline.PipelineResumeError`
115
+
116
+ Thrown when resuming a pipeline from an invalid state.
117
+
118
+ ## state — State Machines
119
+
120
+ State machine namespace — define valid transitions with guards and side effects.
121
+
122
+ ### `state.define`
123
+
124
+ Defines a state machine from states, transitions, guards, and effects. Returns a StateMachine with transition/canTransition.
125
+
126
+ ### `state.InvalidTransitionError`
127
+
128
+ Thrown when a transition is not allowed from the current state.
129
+
130
+ ### `state.InvalidStateMachineError`
131
+
132
+ Thrown when the state machine definition is internally inconsistent.
133
+
134
+ ## auth — Authentication
135
+
136
+ Authentication namespace — session management, multi-org support, auth chain resolution.
137
+
138
+ ### `auth.createSessions`
139
+
140
+ Creates a Sessions manager with JWT access/refresh tokens, rotation, and reuse detection.
141
+
142
+ ### `auth.createMultiOrg`
143
+
144
+ Creates multi-org session management — org selection, switching, membership CRUD.
145
+
146
+ ### `auth.runChain`
147
+
148
+ Executes an auth chain (strategy pipeline) to resolve auth + tenant from a request.
149
+
150
+ ### `auth.resolveCookie`
151
+
152
+ Resolves CookieConfig with defaults for secure cookie-based token delivery.
153
+
154
+ ### `auth.parseCookie`
155
+
156
+ Parses a Cookie header string into key-value pairs.
157
+
158
+ ### `auth.buildSetCookie`
159
+
160
+ Builds a Set-Cookie header string from name, value, and CookieConfig.
161
+
162
+ ### `auth.buildClearCookie`
163
+
164
+ Builds a Set-Cookie header that clears (expires) a cookie.
165
+
166
+ ### Types
167
+
168
+ **`AuthContext`** — Runtime auth context passed to strategies — carries the resolved DB and request metadata.
169
+
170
+ ```typescript
171
+ interface AuthContext
172
+ ```
173
+
174
+ **`AuthStrategy`** — Pluggable auth strategy — implement authenticate() to extract auth from a request.
175
+
176
+ ```typescript
177
+ interface AuthStrategy<TAuth>
178
+ ```
179
+
180
+ **`AuthRequest`** — Normalized request shape passed to auth strategies — headers, cookies, method, url.
181
+
182
+ ```typescript
183
+ interface AuthRequest
184
+ ```
185
+
186
+ **`BaseAuth`** — Minimum auth shape — userId and tenantId. Extend for app-specific auth fields.
187
+
188
+ ```typescript
189
+ interface BaseAuth
190
+ ```
191
+
192
+ **`AuthEnricher`** — Post-authentication hook — enrich the resolved auth with additional data (roles, permissions, etc.).
193
+
194
+ ```typescript
195
+ interface AuthEnricher<TAuth>
196
+ ```
197
+
198
+ **`TenantResolver`** — Resolves tenant ID from auth context — called after authentication in the chain.
199
+
200
+ ```typescript
201
+ interface TenantResolver<TAuth>
202
+ ```
203
+
204
+ **`AuthChainConfig`** — Configuration for the auth chain — strategies, enrichers, tenant resolver.
205
+
206
+ ```typescript
207
+ interface AuthChainConfig<TAuth>
208
+ ```
209
+
210
+ **`SessionConfig`** — Session configuration — signing keys, issuer, audience, token TTLs, refresh rotation.
211
+
212
+ ```typescript
213
+ interface SessionConfig
214
+ ```
215
+
216
+ **`TokenPair`** — Access + refresh token pair returned by issueTokens().
217
+
218
+ ```typescript
219
+ interface TokenPair
220
+ ```
221
+
222
+ **`TokenPayload`** — Decoded JWT payload — userId, tenantId, roles, version.
223
+
224
+ ```typescript
225
+ interface TokenPayload
226
+ ```
227
+
228
+ **`HttpTokenResult`** — Result from HTTP token operations — the token pair plus whether cookies were set.
229
+
230
+ ```typescript
231
+ interface HttpTokenResult
232
+ ```
233
+
234
+ **`Sessions`** — Session manager with JWT issue/refresh/revoke lifecycle and cookie-based HTTP helpers.
235
+
236
+ ```typescript
237
+ interface Sessions
238
+ ```
239
+
240
+ **`CookieConfig`** — Cookie configuration for token delivery — name, domain, path, secure, sameSite, httpOnly.
241
+
242
+ ```typescript
243
+ interface CookieConfig
244
+ ```
245
+
246
+ **`MultiOrgConfig`** — Configuration for multi-org sessions — base sessions, signing keys, org-select token TTL.
247
+
248
+ ```typescript
249
+ interface MultiOrgConfig
250
+ ```
251
+
252
+ **`OrgMembership`** — A user's membership in an organization — userId, orgId, role.
253
+
254
+ ```typescript
255
+ interface OrgMembership
256
+ ```
257
+
258
+ **`OrgInfo`** — Basic organization info — id and display name.
259
+
260
+ ```typescript
261
+ interface OrgInfo
262
+ ```
263
+
264
+ **`OrgMembershipDetail`** — Organization membership with display name — extends OrgMembership with org info.
265
+
266
+ ```typescript
267
+ interface OrgMembershipDetail
268
+ ```
269
+
270
+ **`AuthenticatedResult`** — Result when user has exactly one org — direct authentication, no org selection needed.
271
+
272
+ ```typescript
273
+ interface AuthenticatedResult
274
+ ```
275
+
276
+ **`OrgSelectResult`** — Result when user has multiple orgs — returns a session token for org selection.
277
+
278
+ ```typescript
279
+ interface OrgSelectResult
280
+ ```
281
+
282
+ **`ResolveLoginResult`** — Union result from resolveLogin() — either AuthenticatedResult or OrgSelectResult.
283
+
284
+ ```typescript
285
+ type ResolveLoginResult = AuthenticatedResult | OrgSelectResult
286
+ ```
287
+
288
+ **`MultiOrgSessions`** — Multi-org session manager — login resolution, org selection, switching, membership CRUD.
289
+
290
+ ```typescript
291
+ interface MultiOrgSessions
292
+ ```
293
+
294
+ ## rbac — Access Control
295
+
296
+ Role-based access control namespace — permission checking, enforcement, scope hierarchy.
297
+
298
+ ### `rbac.create`
299
+
300
+ Creates an Rbac instance from config (roles, permissions, hierarchy).
301
+
302
+ ### `rbac.check`
303
+
304
+ Checks if a permission set includes the required resource/action/scope. Pure function, no DB.
305
+
306
+ ### `rbac.enforce`
307
+
308
+ Checks permission and throws ForbiddenError if denied. Loads permissions from DB with caching.
309
+
310
+ ### `rbac.satisfies`
311
+
312
+ Checks if a granted scope satisfies a required scope given a hierarchy (e.g. org > team > self).
313
+
314
+ ### `rbac.PermissionCache`
315
+
316
+ LRU cache for resolved permissions — avoids repeated DB lookups within a request.
317
+
318
+ ## tenant — Multi-Tenancy
319
+
320
+ Multi-tenant isolation namespace — RLS policies, tenant extraction, Postgres-side verification.
321
+
322
+ ### `tenant.validate`
323
+
324
+ Validates a tenant ID format (non-empty string, safe characters).
325
+
326
+ ### `tenant.rls`
327
+
328
+ Enables RLS on a table and creates the tenant isolation policy in Postgres.
329
+
330
+ ### `tenant.policy`
331
+
332
+ Returns the SQL string for a tenant isolation RLS policy — use in migrations.
333
+
334
+ ### `tenant.verify`
335
+
336
+ Cross-checks the ALS principal (tenant, user, asOf) against the Postgres session GUCs — defense-in-depth.
337
+
338
+ ### `tenant.propagate`
339
+
340
+ Sets pipework.tenant_id on the Postgres connection via set_config().
341
+
342
+ ### `tenant.extract`
343
+
344
+ Extracts tenant ID from auth context using the configured extraction strategy.
345
+
346
+ ### `tenant.isTenantScoped`
347
+
348
+ Returns true if a table has been marked as tenant-scoped (via .tenant() field metadata).
349
+
350
+ ## config — Configuration
351
+
352
+ Configuration namespace — loads and resolves Blueprint configs, discovers pipework.config.ts.
353
+
354
+ ### `config.load`
355
+
356
+ Parses and resolves a raw Blueprint into a ResolvedConfig with environment detection.
357
+
358
+ ### `config.discover`
359
+
360
+ Walks up from cwd to find pipework.config.ts, imports it, and returns the Manifold.
361
+
362
+ ### `config.configSchema`
363
+
364
+ The zod schema for Blueprint validation — useful for custom config tooling.
365
+
366
+ ### `config.ConfigError`
367
+
368
+ Thrown for configuration problems — includes a suggestion for how to fix.
369
+
370
+ ## errors — Error Classes
371
+
372
+ Standard error classes — all extend PipeworkError with structured error codes and actionable messages.
373
+
374
+ ### `errors.Base`
375
+
376
+ Base error class with code, statusCode, and suggestion fields.
377
+
378
+ ### `errors.NotFound`
379
+
380
+ 404 — resource not found.
381
+
382
+ ### `errors.Unauthorized`
383
+
384
+ 401 — missing or invalid authentication.
385
+
386
+ ### `errors.Forbidden`
387
+
388
+ 403 — authenticated but insufficient permissions.
389
+
390
+ ### `errors.Validation`
391
+
392
+ 422 — input validation failed, carries field-level details.
393
+
394
+ ### `errors.Conflict`
395
+
396
+ 409 — resource state conflict (duplicate, version mismatch).
397
+
398
+ ## lifecycle — Startup & Shutdown
399
+
400
+ Application lifecycle namespace — startup orchestration with hooks and timeouts.
401
+
402
+ ### `lifecycle.orchestrate`
403
+
404
+ Runs pre-start hooks (DB readiness checks, migrations, etc.) with a configurable timeout.
405
+
406
+ ## log — Structured Logging
407
+
408
+ Structured logger (Pino) — auto-binds requestId, tenantId, userId, sessionId from ALS context on every log call.
409
+
410
+ ### `log.create`
411
+
412
+ Creates a new PipeworkLogger instance with custom config (level, redaction, transport).
413
+
414
+ ### `log.get`
415
+
416
+ Returns the context-aware logger proxy (same as the log export itself).
417
+
418
+ ### `log.getBase`
419
+
420
+ Returns the raw Pino logger without ALS context binding.
421
+
422
+ ### `log.configure`
423
+
424
+ Sets global logging config (level, redaction paths, custom context fields).
425
+
426
+ ### `log.REDACT_PATHS`
427
+
428
+ Default redaction paths — password, secret, token, authorization, cookie, etc.
429
+
430
+ ## surface — Entry Points
431
+
432
+ Surface namespace — declarative entry points that define how the app runs (HTTP server, background worker, one-shot script).
433
+
434
+ ### `surface.http`
435
+
436
+ Creates an HTTP surface — a Fastify server with routes, middleware, and production validation. Returns an HttpSurfaceBuilder with a .test() method for inject()-based integration tests.
437
+
438
+ ### `surface.worker`
439
+
440
+ Creates a worker surface — a long-running process that claims and executes jobs from queues.
441
+
442
+ ### `surface.script`
443
+
444
+ Creates a script surface — a one-shot process that runs and exits (migrations, seeds, CLI tools).
445
+
446
+ ## pipe — Database
447
+
448
+ Database accessor — returns a Drizzle DB instance scoped to the current request/job/test context. Requires active AsyncLocalStorage context.
449
+
450
+ ### `pipe.system`
451
+
452
+ 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.
453
+
454
+ ### `pipe.filter`
455
+
456
+ Query operators and aggregates — eq, gt, lt, and, or, count, sum, etc.
457
+
458
+ ### `pipe.aliasedRelation`
459
+
460
+
461
+ ### `pipe.aliasedTable`
462
+
463
+
464
+ ### `pipe.aliasedTableColumn`
465
+
466
+
467
+ ### `pipe.getTableColumns`
468
+
469
+
470
+ ### `pipe.getTableName`
471
+
472
+
473
+ ### `pipe.getViewName`
474
+
475
+
476
+ ### `pipe.getViewSelectedFields`
477
+
478
+
479
+ ### `pipe.isTable`
480
+
481
+
482
+ ### `pipe.createMany`
483
+
484
+
485
+ ### `pipe.createOne`
486
+
487
+
488
+ ### `pipe.relations`
489
+
490
+
491
+ ### `pipe.migrate`
492
+
493
+ Runs migrations for all configured databases.
494
+
495
+ ### `pipe.migrateOne`
496
+
497
+ Runs migrations for a single named database.
498
+
499
+ ### `pipe.excluded`
500
+
501
+ Returns excluded-column references for onConflictDoUpdate set clauses.
502
+
503
+ ### `pipe.advisoryLock`
504
+
505
+ Acquires a transaction-scoped advisory lock. Released at commit/rollback.
506
+
507
+ ### `pipe.serializable`
508
+
509
+ Runs a function in a SERIALIZABLE transaction with automatic retry on serialization failures and deadlocks.
510
+
511
+ ### `pipe.bulkSet`
512
+
513
+ Bulk UPDATE ... FROM (VALUES ...) — updates multiple rows with per-row values in a single statement.
514
+
515
+ ### `pipe.values`
516
+
517
+ Produces a typed VALUES clause for bulk operations — the base primitive for bulkSet and bulkUpsert.
518
+
519
+ ### `pipe.field`
520
+
521
+ Field builders for domain definitions — uuid(), text(), integer(), etc.
522
+
523
+ ### `pipe.define`
524
+
525
+ Registers a domain definition with table, validators, and factory projections.
526
+
527
+ ### `pipe.definitions`
528
+
529
+ Returns the global registry of all domain definitions.
530
+
531
+ ### `pipe.update`
532
+
533
+ Pipework-owned UPDATE builder — the only consumer-facing way to update pipework-managed tables (Q8).
534
+
535
+ ### `pipe.insert`
536
+
537
+ Pipework-owned INSERT builder — the only consumer-facing way to insert into pipework-managed tables (Q8).
538
+
539
+ ### `pipe.delete`
540
+
541
+ Pipework-owned DELETE builder — the only consumer-facing way to delete from pipework-managed tables (Q8).
542
+
543
+ ### `pipe.upsert`
544
+
545
+ Pipework-owned UPSERT builder — insert with conflict resolution (Q8).
546
+
547
+ ### Types
548
+
549
+ **`WindowSpec`** — A window-frame specification — the `PARTITION BY` / `ORDER BY` clauses applied by {@link over}.
550
+
551
+ ```typescript
552
+ interface WindowSpec
553
+ ```
554
+
555
+ **`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}.
556
+
557
+ ```typescript
558
+ interface ValueColumnDef
559
+ ```
560
+
561
+ **`SerializableOptions`** — Retry policy for {@link serializable}: how many attempts on a serialization failure / deadlock, and the base backoff between them.
562
+
563
+ ```typescript
564
+ interface SerializableOptions
565
+ ```
566
+
567
+ ## jsonb — JSONB Column Helpers
568
+
569
+ JSONB query operators — typed helpers for PostgreSQL JSONB containment, key checks, and field extraction.
570
+
571
+ ### `jsonb.contains`
572
+
573
+ The @> containment operator — tests whether a JSONB column contains the given value.
574
+
575
+ ### `jsonb.containedBy`
576
+
577
+ The <@ contained-by operator — tests whether a JSONB column is contained by the given value.
578
+
579
+ ### `jsonb.hasKey`
580
+
581
+ The ? key-existence operator — tests whether a JSONB column has the given top-level key.
582
+
583
+ ### `jsonb.text`
584
+
585
+ Extracts a text value: `column->>'key'`. Composable with pipe.filter operators.
586
+
587
+ ### `jsonb.json`
588
+
589
+ Extracts a JSONB value: `column->'key'`. Returns JSONB — use with jsonb.contains() etc.
590
+
591
+ ### `jsonb.path`
592
+
593
+ Extracts a nested JSONB value: `column->'a'->'b'`. Returns JSONB.
594
+
595
+ ### `jsonb.pathText`
596
+
597
+ Extracts a nested text value: `column->'a'->>'b'`. Intermediate keys use `->`, final uses `->>`.
598
+
599
+ ### `jsonb.boolean`
600
+
601
+ Extracts a boolean: `(column->>'key')::boolean`. Supports nested paths.
602
+
603
+ ### `jsonb.number`
604
+
605
+ Extracts a number: `(column->>'key')::numeric`. Supports nested paths.
606
+
607
+ ### `jsonb.integer`
608
+
609
+ Extracts an integer: `(column->>'key')::integer`. Supports nested paths.
610
+
611
+ ## schema — Validation & Schema
612
+
613
+ Schema definition and validation namespace — wraps zod for validation, drizzle for table/column/index definitions.
614
+
615
+ ### `schema.check`
616
+
617
+ Validation sub-namespace — type constructors, combinators, formats, coerce, parse, tryParse, toJsonSchema, branded.
618
+
619
+ ### `schema.col`
620
+
621
+ Column type builders for table definitions — text, uuid, integer, timestamp, jsonb, boolean, varchar, etc.
622
+
623
+ ### `schema.idx`
624
+
625
+ Index and constraint builders — index, uniqueIndex, primaryKey, foreignKey, unique, check.
626
+
627
+ ### Types
628
+
629
+ **`Schema`** — Any validation schema — the base type accepted by .input(), .query(), .params() in the fitting builder.
630
+
631
+ ```typescript
632
+ type Schema<T = unknown> = z.ZodType<T>
633
+ ```
634
+
635
+ **`Infer`** — Extracts the TypeScript type from a Schema — Infer<typeof mySchema> gives you the validated type.
636
+
637
+ ```typescript
638
+ type Infer<T extends Schema> = z.infer<T>
639
+ ```
640
+
641
+ ## temporal — Bitemporal Data
642
+
643
+ Temporal (bitemporal) data namespace — version history with effective date ranges.
644
+
645
+ ### `temporal.columns`
646
+
647
+ Returns the standard temporal column definitions (effectiveFrom, effectiveTo, version, createdBy) for table schemas.
648
+
649
+ ### `temporal.revise`
650
+
651
+ Creates a new version of a temporal record, closing the previous version's effectiveTo.
652
+
653
+ ### `temporal.close`
654
+
655
+ Closes a temporal record by setting effectiveTo to now. Returns number of rows affected.
656
+
657
+ ### `temporal.current`
658
+
659
+ Fetches the currently-effective version of a temporal record (effectiveTo IS NULL).
660
+
661
+ ### `temporal.atTime`
662
+
663
+ Returns a SQL condition for records effective at a specific point in time.
664
+
665
+ ### `temporal.between`
666
+
667
+ Returns a SQL condition for records overlapping a date range.
668
+
669
+ ### `temporal.TemporalIntegrityError`
670
+
671
+ Thrown when a temporal operation would violate version continuity.
672
+
673
+ ### `temporal.asOf`
674
+
675
+ Query records effective at a specific date, using a domain definition with .effectiveDated() trait.
676
+
677
+ ### `temporal.allVersions`
678
+
679
+ Query all versions of temporal records (no date filter).
680
+
681
+ ### `temporal.effectiveUpdate`
682
+
683
+ Close the current version and create a new one with updated data.
684
+
685
+ ## valve
686
+
687
+ Valve namespace — typed, directional, gated boundaries between code silos.
688
+
689
+ ### `valve.supply`
690
+
691
+ Declare a handoff valve — the producer side of a payload crossing.
692
+
693
+ ### `valve.gate`
694
+
695
+ Declare a transition-gate valve — the producer side of a gated state change.
696
+
697
+ ### `valve.faucet`
698
+
699
+ Declare a faucet — the consumer side of a `supply -> faucet` edge.
700
+
701
+ ### `valve.cross`
702
+
703
+ Decision outcome: cross the valve, delivering the payload.
704
+
705
+ ### `valve.held`
706
+
707
+ Decision outcome: hold the crossing in a provisional, reviewable state.
708
+
709
+ ### `valve.failed`
710
+
711
+ Decision outcome: evaluation failed — retryable, never a thrown exception.
712
+
713
+ ### `valve.crossSupply`
714
+
715
+ Execute a handoff crossing in the caller's transaction (unrecorded mechanics).
716
+
717
+ ### `valve.crossGate`
718
+
719
+ Execute a transition-gate crossing (unrecorded mechanics).
720
+
721
+ ### `valve.executeSupplyCrossing`
722
+
723
+ Execute a handoff crossing with idempotency and provenance recording.
724
+
725
+ ### `valve.executeGateCrossing`
726
+
727
+ Execute a transition-gate crossing with provenance recording.
728
+
729
+ ### `valve.enqueueCrossing`
730
+
731
+ Enqueue a handoff crossing to run durably as a retried, dead-letterable job.
732
+
733
+ ### `valve.runCrossingJob`
734
+
735
+ The durable-crossing job-handler body — wire into a worker.
736
+
737
+ ### `valve.VALVE_CROSSING_JOB_TYPE`
738
+
739
+ Job type for a durable valve crossing.
740
+
741
+ ### `valve.graph`
742
+
743
+ Assemble the directional valve graph from every registered valve and faucet.
744
+
745
+ ### `valve.downstreamFaucets`
746
+
747
+ The faucet nodes a valve feeds.
748
+
749
+ ### `valve.contextDependents`
750
+
751
+ The gates whose enrichment context depends on a valve.
752
+
753
+ ### `valve.diffContract`
754
+
755
+ Diff a valve contract between two versions.
756
+
757
+ ### `valve.emitArtifact`
758
+
759
+ Project a handoff supply to its lightweight contract artifact.
760
+
761
+ ### `valve.valves`
762
+
763
+ All registered producer valves, keyed by name.
764
+
765
+ ### `valve.getValve`
766
+
767
+ Look up a registered valve by name.
768
+
769
+ ### `valve.faucetsOf`
770
+
771
+ The faucets consuming a named valve.
772
+
773
+ ## vector — Vector & Full-Text Search
774
+
775
+ Vector and full-text search namespace — pgvector column types, similarity queries, and FTS operators.
776
+
777
+ ### `vector.column`
778
+
779
+ Defines a vector(N) column for embeddings.
780
+
781
+ ### `vector.tsvector`
782
+
783
+ Defines a tsvector column for full-text search.
784
+
785
+ ### `vector.cosine`
786
+
787
+ Cosine distance between a column and a query vector (lower = more similar).
788
+
789
+ ### `vector.cosineSimilarity`
790
+
791
+ Cosine similarity (higher = more similar) — 1 - cosineDistance.
792
+
793
+ ### `vector.l2`
794
+
795
+ L2 (Euclidean) distance between a column and a query vector.
796
+
797
+ ### `vector.innerProduct`
798
+
799
+ Inner product between a column and a query vector.
800
+
801
+ ### `vector.toTsvector`
802
+
803
+ Converts text to a tsvector for full-text indexing.
804
+
805
+ ### `vector.toTsquery`
806
+
807
+ Converts a search query string to a tsquery using to_tsquery (supports operators like &, |, !).
808
+
809
+ ### `vector.plainToTsquery`
810
+
811
+ Converts natural language text to a tsquery using plainto_tsquery (no operator syntax required).
812
+
813
+ ### `vector.matches`
814
+
815
+ The @@ match operator — tests whether a tsvector column matches a tsquery.
816
+
817
+ ### `vector.headline`
818
+
819
+ Generates a ts_headline search snippet with highlighted matches.
820
+
821
+ ### `vector.rank`
822
+
823
+ Computes ts_rank for full-text search result ordering. Accepts a pre-built tsquery SQL or a raw query string.
824
+
825
+ ### `vector.validate`
826
+
827
+ Verifies the pgvector extension is installed and accessible.
828
+
829
+ ## audit — Audit Logging
830
+
831
+ Audit logging namespace — structured audit trail for data changes.
832
+
833
+ ### `audit.create`
834
+
835
+ Creates an Audit instance that writes audit records to a Postgres table.
836
+
837
+ ### `audit.query`
838
+
839
+ Queries the framework-managed `audit_record` table. Tenant-scoped via the active Flow.
840
+
841
+ ## cache — Caching
842
+
843
+ In-memory caching namespace — TTL-based with stats, preload, and tenant-aware variants.
844
+
845
+ ### `cache.create`
846
+
847
+ Creates a single-key cache with TTL, a loader function, and invalidation.
848
+
849
+ ### `cache.createTenant`
850
+
851
+ Creates a per-tenant cache — each tenant gets its own TTL and loader keyed by tenant ID.
852
+
853
+ ## webhook — Inbound & Outbound Webhooks
854
+
855
+ Webhook namespace — inbound verification, outbound delivery with retries, HMAC signing.
856
+
857
+ ### `webhook.defineInbound`
858
+
859
+ Defines an inbound webhook handler with signature verification and optional idempotency.
860
+
861
+ ### `webhook.createOutbound`
862
+
863
+ Creates an outbound webhook system — endpoint registration, payload signing, delivery with retries.
864
+
865
+ ### `webhook.sign`
866
+
867
+ Signs a payload with HMAC for outbound delivery — returns body, signature, timestamp, messageId.
868
+
869
+ ## behavior — Resource Decorators
870
+
871
+ Resource behavior decorators — compose versioning, audit trails, and cache invalidation onto CRUD operations.
872
+
873
+ ### `behavior.compose`
874
+
875
+ Applies multiple behaviors to a ResourceOperations set in order.
876
+
877
+ ### `behavior.versioned`
878
+
879
+ Adds optimistic concurrency control via a version column — rejects stale updates.
880
+
881
+ ### `behavior.audited`
882
+
883
+ Wraps operations to emit audit records on create/update/delete.
884
+
885
+ ### `behavior.invalidate`
886
+
887
+ Wraps operations to invalidate a cache on mutations. Returns ops with an attached .cache handle.
888
+
889
+ ## fitting — Dependency Injection
890
+
891
+ ## fixture — REST Resources
892
+
893
+ REST resource builder namespace — declarative CRUD with cursor pagination and batch operations.
894
+
895
+ ### `fixture.toHandlers`
896
+
897
+ Converts a Resource into fitted Handler[] that go through the standard handler pipeline.
898
+
899
+ ### `fixture.build`
900
+
901
+ Builds a Resource from a name, operations map, and builder state — used internally by fitting().fixture().
902
+
903
+ ### `fixture.encodeCursor`
904
+
905
+ Encodes pagination cursor values into an opaque base64 string.
906
+
907
+ ### `fixture.decodeCursor`
908
+
909
+ Decodes an opaque pagination cursor back into its values.
910
+
911
+ ### `fixture.buildPage`
912
+
913
+ Builds a PageResult from rows, limit, and cursor extractor — handles hasMore detection.
914
+
915
+ ### `fixture.validateBatch`
916
+
917
+ Validates a batch request body (preview/execute mode, targets, actions).
918
+
919
+ ### `fixture.MethodNotAllowedError`
920
+
921
+ Thrown when a resource doesn't support the requested HTTP method.
922
+
923
+ ## flow — Context (AsyncLocalStorage)
924
+
925
+ AsyncLocalStorage context namespace — manages request/job/test contexts that carry auth, tenant, transactions.
926
+
927
+ ### `flow.run`
928
+
929
+ Executes a function within a Flow context (AsyncLocalStorage). All pipe() calls inside will use this context.
930
+
931
+ ### `flow.require`
932
+
933
+ Returns the current Flow or throws — use in code that must run inside a managed context.
934
+
935
+ ### `flow.get`
936
+
937
+ Returns the current Flow or undefined — use for optional context detection.
938
+
939
+ ### `flow.createTest`
940
+
941
+ Creates a Flow for test isolation with optional auth and tenant overrides.
942
+
943
+ ## http — Server
944
+
945
+ HTTP server namespace — managed by manifold.start(), not directly accessible.
946
+
947
+ ### Types
948
+
949
+ **`CorsConfig`** — CORS configuration — origin, methods, headers, credentials, maxAge.
950
+
951
+ ```typescript
952
+ interface CorsConfig
953
+ ```
954
+
955
+ **`SecurityConfig`** — Security header configuration — passed to @fastify/helmet.
956
+
957
+ ```typescript
958
+ interface SecurityConfig
959
+ ```
960
+
961
+ **`RateLimitConfig`** — Rate limiting configuration — max requests, time window, key generator.
962
+
963
+ ```typescript
964
+ interface RateLimitConfig
965
+ ```
966
+
967
+ **`InjectOptions`** — Options for server.inject() — method, url, headers, payload for testing without HTTP.
968
+
969
+ ```typescript
970
+ interface InjectOptions
971
+ ```
972
+
973
+ **`InjectResponse`** — Response from server.inject() — statusCode, headers, body, json() helper.
974
+
975
+ ```typescript
976
+ interface InjectResponse
977
+ ```
978
+
979
+ **`ServerConfig`** — Configuration for http.createServer() — CORS, security headers, rate limiting, transaction timeout.
980
+
981
+ ```typescript
982
+ interface ServerConfig
983
+ ```
984
+
985
+ **`HandlerResponse`** — Standard handler response shape — statusCode, headers, body.
986
+
987
+ ```typescript
988
+ interface HandlerResponse
989
+ ```
990
+
991
+ **`ErrorResponse`** — Standard error response shape — { error: { code, message }, statusCode }.
992
+
993
+ ```typescript
994
+ interface ErrorResponse
995
+ ```
996
+
997
+ **`PipeworkServer`** — Fastify server wrapper with route registration, handler auto-wiring, and inject() for testing.
998
+
999
+ ```typescript
1000
+ interface PipeworkServer
1001
+ ```
1002
+
1003
+ **`HttpRequest`** — Fastify request with pipework extensions — req.id (UUID), typed headers.
1004
+
1005
+ ```typescript
1006
+ interface HttpRequest
1007
+ ```
1008
+
1009
+ **`HttpResponse`** — Fastify reply with pipework extensions.
1010
+
1011
+ ```typescript
1012
+ interface HttpResponse
1013
+ ```
1014
+
1015
+ ## openapi — API Documentation
1016
+
1017
+ OpenAPI spec generation namespace.
1018
+
1019
+ ### `openapi.generate`
1020
+
1021
+ Generates an OpenAPI 3.1 document from route registrations — schemas derived from fitting() input/output.
1022
+
1023
+ ## test
1024
+
1025
+ ## trace
1026
+
1027
+ ### `__flowStep`
1028
+
1029
+ Wraps `impl` so that, under an active traced Flow, each call records a `trace_step`.
1030
+
1031
+ ```typescript
1032
+ function __flowStep<F extends AnyFunction>(meta: FlowStepMeta, impl: F): F
1033
+ ```