pipework 0.7.10 → 0.7.12
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 +16 -0
- package/REFERENCE.md +778 -0
- package/dist/REFERENCE.md +844 -0
- package/dist/cli/commands/dev.js +5 -2
- package/dist/cli/commands/dev.js.map +1 -1
- package/dist/cli/commands/run.d.ts.map +1 -1
- package/dist/cli/commands/run.js +0 -2
- package/dist/cli/commands/run.js.map +1 -1
- package/dist/cli/commands/test.d.ts.map +1 -1
- package/dist/cli/commands/test.js +0 -2
- package/dist/cli/commands/test.js.map +1 -1
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +2 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/config/discover.d.ts.map +1 -1
- package/dist/config/discover.js +14 -0
- package/dist/config/discover.js.map +1 -1
- package/dist/config/ts-register.d.ts +2 -0
- package/dist/config/ts-register.d.ts.map +1 -0
- package/dist/config/ts-register.js +3 -0
- package/dist/config/ts-register.js.map +1 -0
- package/dist/config/ts-resolve-hooks.d.ts +10 -0
- package/dist/config/ts-resolve-hooks.d.ts.map +1 -0
- package/dist/config/ts-resolve-hooks.js +14 -0
- package/dist/config/ts-resolve-hooks.js.map +1 -0
- package/dist/db/excluded.d.ts +7 -0
- package/dist/db/excluded.d.ts.map +1 -0
- package/dist/db/excluded.js +11 -0
- package/dist/db/excluded.js.map +1 -0
- package/dist/db/index.d.ts +1 -0
- package/dist/db/index.d.ts.map +1 -1
- package/dist/db/index.js +1 -0
- package/dist/db/index.js.map +1 -1
- package/dist/db/namespace.d.ts +5 -0
- package/dist/db/namespace.d.ts.map +1 -1
- package/dist/db/namespace.js +5 -0
- package/dist/db/namespace.js.map +1 -1
- package/dist/domain/field.d.ts +4 -2
- package/dist/domain/field.d.ts.map +1 -1
- package/dist/domain/field.js.map +1 -1
- package/dist/domain/index.d.ts +1 -1
- package/dist/domain/index.d.ts.map +1 -1
- package/dist/domain/types.d.ts +19 -6
- package/dist/domain/types.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/log/namespace.d.ts +1 -1
- package/dist/logging/index.d.ts +1 -1
- package/dist/logging/index.d.ts.map +1 -1
- package/dist/logging/proxy.d.ts +2 -2
- package/dist/logging/proxy.d.ts.map +1 -1
- package/dist/logging/proxy.js +9 -2
- package/dist/logging/proxy.js.map +1 -1
- package/dist/logging/types.d.ts +7 -0
- package/dist/logging/types.d.ts.map +1 -1
- package/dist/temporal/definition-queries.d.ts +5 -5
- package/dist/temporal/definition-queries.d.ts.map +1 -1
- package/dist/temporal/definition-queries.js.map +1 -1
- package/dist/vector/query.d.ts +1 -1
- package/dist/vector/query.d.ts.map +1 -1
- package/dist/vector/query.js.map +1 -1
- package/package.json +3 -2
package/REFERENCE.md
ADDED
|
@@ -0,0 +1,778 @@
|
|
|
1
|
+
# Pipework API Reference
|
|
2
|
+
|
|
3
|
+
> Auto-generated from source JSDoc. Do not edit manually.
|
|
4
|
+
> Generated: 2026-05-07
|
|
5
|
+
|
|
6
|
+
## Contents
|
|
7
|
+
|
|
8
|
+
- [Core](#core)
|
|
9
|
+
- [audit — Audit Logging](#audit-audit-logging)
|
|
10
|
+
- [auth — Authentication](#auth-authentication)
|
|
11
|
+
- [behavior — Resource Decorators](#behavior-resource-decorators)
|
|
12
|
+
- [cache — Caching](#cache-caching)
|
|
13
|
+
- [config — Configuration](#config-configuration)
|
|
14
|
+
- [pipe — Database](#pipe-database)
|
|
15
|
+
- [errors — Error Classes](#errors-error-classes)
|
|
16
|
+
- [fitting — Dependency Injection](#fitting-dependency-injection)
|
|
17
|
+
- [fixture — REST Resources](#fixture-rest-resources)
|
|
18
|
+
- [flow — Context (AsyncLocalStorage)](#flow-context-asynclocalstorage)
|
|
19
|
+
- [http — Server](#http-server)
|
|
20
|
+
- [jobs — Background Jobs](#jobs-background-jobs)
|
|
21
|
+
- [lifecycle — Startup & Shutdown](#lifecycle-startup-shutdown)
|
|
22
|
+
- [log — Structured Logging](#log-structured-logging)
|
|
23
|
+
- [openapi — API Documentation](#openapi-api-documentation)
|
|
24
|
+
- [pipeline — Multi-Step Pipelines](#pipeline-multi-step-pipelines)
|
|
25
|
+
- [rbac — Access Control](#rbac-access-control)
|
|
26
|
+
- [schema — Validation & Schema](#schema-validation-schema)
|
|
27
|
+
- [state](#state)
|
|
28
|
+
- [surface — Entry Points](#surface-entry-points)
|
|
29
|
+
- [temporal — Bitemporal Data](#temporal-bitemporal-data)
|
|
30
|
+
- [tenant — Multi-Tenancy](#tenant-multi-tenancy)
|
|
31
|
+
- [vector — Vector & Full-Text Search](#vector-vector-full-text-search)
|
|
32
|
+
- [webhook — Inbound & Outbound Webhooks](#webhook-inbound-outbound-webhooks)
|
|
33
|
+
|
|
34
|
+
## Core
|
|
35
|
+
|
|
36
|
+
Application instance and foundational types.
|
|
37
|
+
|
|
38
|
+
### `createManifold`
|
|
39
|
+
|
|
40
|
+
Creates the Pipework application instance. This is the entry point for every Pipework app. Define in `pipework.config.ts` and export as default. /
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
function createManifold<const TEnv extends EnvDefs = EnvDefs>( raw: Omit<Blueprint, 'env'> &
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Types
|
|
47
|
+
|
|
48
|
+
**`Manifold`** — The application instance — holds config, connection pools, surfaces, and lifecycle.
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
interface Manifold<TEnv extends EnvDefs = EnvDefs>
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
**`PoolState`** — Manages database connection pools keyed by database name.
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
interface PoolState
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
**`IsolationState`** — Tracks test isolation lifecycle — detects leaked isolation contexts.
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
interface IsolationState
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
**`ConnectionTracker`** — Tracks active database connections for leak detection.
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
interface ConnectionTracker
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## audit — Audit Logging
|
|
73
|
+
|
|
74
|
+
Audit logging namespace — structured audit trail for data changes.
|
|
75
|
+
|
|
76
|
+
### `audit.create`
|
|
77
|
+
|
|
78
|
+
Creates an Audit instance that writes audit records to a Postgres table.
|
|
79
|
+
|
|
80
|
+
## auth — Authentication
|
|
81
|
+
|
|
82
|
+
Authentication namespace — session management, multi-org support, auth chain resolution.
|
|
83
|
+
|
|
84
|
+
### `auth.createSessions`
|
|
85
|
+
|
|
86
|
+
Creates a Sessions manager with JWT access/refresh tokens, rotation, and reuse detection.
|
|
87
|
+
|
|
88
|
+
### `auth.createMultiOrg`
|
|
89
|
+
|
|
90
|
+
Creates multi-org session management — org selection, switching, membership CRUD.
|
|
91
|
+
|
|
92
|
+
### `auth.runChain`
|
|
93
|
+
|
|
94
|
+
Executes an auth chain (strategy pipeline) to resolve auth + tenant from a request.
|
|
95
|
+
|
|
96
|
+
### `auth.resolveCookie`
|
|
97
|
+
|
|
98
|
+
Resolves CookieConfig with defaults for secure cookie-based token delivery.
|
|
99
|
+
|
|
100
|
+
### `auth.parseCookie`
|
|
101
|
+
|
|
102
|
+
Parses a Cookie header string into key-value pairs.
|
|
103
|
+
|
|
104
|
+
### `auth.buildSetCookie`
|
|
105
|
+
|
|
106
|
+
Builds a Set-Cookie header string from name, value, and CookieConfig.
|
|
107
|
+
|
|
108
|
+
### `auth.buildClearCookie`
|
|
109
|
+
|
|
110
|
+
Builds a Set-Cookie header that clears (expires) a cookie.
|
|
111
|
+
|
|
112
|
+
### Types
|
|
113
|
+
|
|
114
|
+
**`AuthContext`** — Runtime auth context passed to strategies — carries the resolved DB and request metadata.
|
|
115
|
+
|
|
116
|
+
```typescript
|
|
117
|
+
interface AuthContext
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
**`AuthStrategy`** — Pluggable auth strategy — implement authenticate() to extract auth from a request.
|
|
121
|
+
|
|
122
|
+
```typescript
|
|
123
|
+
interface AuthStrategy<TAuth>
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
**`AuthRequest`** — Normalized request shape passed to auth strategies — headers, cookies, method, url.
|
|
127
|
+
|
|
128
|
+
```typescript
|
|
129
|
+
interface AuthRequest
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
**`BaseAuth`** — Minimum auth shape — userId and tenantId. Extend for app-specific auth fields.
|
|
133
|
+
|
|
134
|
+
```typescript
|
|
135
|
+
interface BaseAuth
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
**`AuthEnricher`** — Post-authentication hook — enrich the resolved auth with additional data (roles, permissions, etc.).
|
|
139
|
+
|
|
140
|
+
```typescript
|
|
141
|
+
interface AuthEnricher<TAuth>
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
**`TenantResolver`** — Resolves tenant ID from auth context — called after authentication in the chain.
|
|
145
|
+
|
|
146
|
+
```typescript
|
|
147
|
+
interface TenantResolver<TAuth>
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
**`AuthChainConfig`** — Configuration for the auth chain — strategies, enrichers, tenant resolver.
|
|
151
|
+
|
|
152
|
+
```typescript
|
|
153
|
+
interface AuthChainConfig<TAuth>
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
**`SessionConfig`** — Session configuration — signing keys, issuer, audience, token TTLs, refresh rotation.
|
|
157
|
+
|
|
158
|
+
```typescript
|
|
159
|
+
interface SessionConfig
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
**`TokenPair`** — Access + refresh token pair returned by issueTokens().
|
|
163
|
+
|
|
164
|
+
```typescript
|
|
165
|
+
interface TokenPair
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
**`TokenPayload`** — Decoded JWT payload — userId, tenantId, roles, version.
|
|
169
|
+
|
|
170
|
+
```typescript
|
|
171
|
+
interface TokenPayload
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
**`HttpTokenResult`** — Result from HTTP token operations — the token pair plus whether cookies were set.
|
|
175
|
+
|
|
176
|
+
```typescript
|
|
177
|
+
interface HttpTokenResult
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
**`Sessions`** — Session manager with JWT issue/refresh/revoke lifecycle and cookie-based HTTP helpers.
|
|
181
|
+
|
|
182
|
+
```typescript
|
|
183
|
+
interface Sessions
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
**`CookieConfig`** — Cookie configuration for token delivery — name, domain, path, secure, sameSite, httpOnly.
|
|
187
|
+
|
|
188
|
+
```typescript
|
|
189
|
+
interface CookieConfig
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
**`MultiOrgConfig`** — Configuration for multi-org sessions — base sessions, signing keys, org-select token TTL.
|
|
193
|
+
|
|
194
|
+
```typescript
|
|
195
|
+
interface MultiOrgConfig
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
**`OrgMembership`** — A user's membership in an organization — userId, orgId, role.
|
|
199
|
+
|
|
200
|
+
```typescript
|
|
201
|
+
interface OrgMembership
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
**`OrgInfo`** — Basic organization info — id and display name.
|
|
205
|
+
|
|
206
|
+
```typescript
|
|
207
|
+
interface OrgInfo
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
**`OrgMembershipDetail`** — Organization membership with display name — extends OrgMembership with org info.
|
|
211
|
+
|
|
212
|
+
```typescript
|
|
213
|
+
interface OrgMembershipDetail
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
**`AuthenticatedResult`** — Result when user has exactly one org — direct authentication, no org selection needed.
|
|
217
|
+
|
|
218
|
+
```typescript
|
|
219
|
+
interface AuthenticatedResult
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
**`OrgSelectResult`** — Result when user has multiple orgs — returns a session token for org selection.
|
|
223
|
+
|
|
224
|
+
```typescript
|
|
225
|
+
interface OrgSelectResult
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
**`ResolveLoginResult`** — Union result from resolveLogin() — either AuthenticatedResult or OrgSelectResult.
|
|
229
|
+
|
|
230
|
+
```typescript
|
|
231
|
+
type ResolveLoginResult = AuthenticatedResult | OrgSelectResult
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
**`MultiOrgSessions`** — Multi-org session manager — login resolution, org selection, switching, membership CRUD.
|
|
235
|
+
|
|
236
|
+
```typescript
|
|
237
|
+
interface MultiOrgSessions
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
## behavior — Resource Decorators
|
|
241
|
+
|
|
242
|
+
Resource behavior decorators — compose versioning, audit trails, and cache invalidation onto CRUD operations.
|
|
243
|
+
|
|
244
|
+
### `behavior.compose`
|
|
245
|
+
|
|
246
|
+
Applies multiple behaviors to a ResourceOperations set in order.
|
|
247
|
+
|
|
248
|
+
### `behavior.versioned`
|
|
249
|
+
|
|
250
|
+
Adds optimistic concurrency control via a version column — rejects stale updates.
|
|
251
|
+
|
|
252
|
+
### `behavior.audited`
|
|
253
|
+
|
|
254
|
+
Wraps operations to emit audit records on create/update/delete.
|
|
255
|
+
|
|
256
|
+
### `behavior.invalidate`
|
|
257
|
+
|
|
258
|
+
Wraps operations to invalidate a cache on mutations. Returns ops with an attached .cache handle.
|
|
259
|
+
|
|
260
|
+
## cache — Caching
|
|
261
|
+
|
|
262
|
+
In-memory caching namespace — TTL-based with stats, preload, and tenant-aware variants.
|
|
263
|
+
|
|
264
|
+
### `cache.create`
|
|
265
|
+
|
|
266
|
+
Creates a single-key cache with TTL, a loader function, and invalidation.
|
|
267
|
+
|
|
268
|
+
### `cache.createTenant`
|
|
269
|
+
|
|
270
|
+
Creates a per-tenant cache — each tenant gets its own TTL and loader keyed by tenant ID.
|
|
271
|
+
|
|
272
|
+
## config — Configuration
|
|
273
|
+
|
|
274
|
+
Configuration namespace — loads and resolves Blueprint configs, discovers pipework.config.ts.
|
|
275
|
+
|
|
276
|
+
### `config.load`
|
|
277
|
+
|
|
278
|
+
Parses and resolves a raw Blueprint into a ResolvedConfig with environment detection.
|
|
279
|
+
|
|
280
|
+
### `config.discover`
|
|
281
|
+
|
|
282
|
+
Walks up from cwd to find pipework.config.ts, imports it, and returns the Manifold.
|
|
283
|
+
|
|
284
|
+
### `config.configSchema`
|
|
285
|
+
|
|
286
|
+
The zod schema for Blueprint validation — useful for custom config tooling.
|
|
287
|
+
|
|
288
|
+
### `config.ConfigError`
|
|
289
|
+
|
|
290
|
+
Thrown for configuration problems — includes a suggestion for how to fix.
|
|
291
|
+
|
|
292
|
+
## pipe — Database
|
|
293
|
+
|
|
294
|
+
Database accessor — returns a Drizzle DB instance scoped to the current request/job/test context. Requires active AsyncLocalStorage context.
|
|
295
|
+
|
|
296
|
+
### `pipe.unscoped`
|
|
297
|
+
|
|
298
|
+
Bypasses tenant scoping for admin/cross-tenant queries. Still requires ALS context.
|
|
299
|
+
|
|
300
|
+
### `pipe.filter`
|
|
301
|
+
|
|
302
|
+
Query operators and aggregates — eq, gt, lt, and, or, count, sum, etc.
|
|
303
|
+
|
|
304
|
+
### `pipe.sql`
|
|
305
|
+
|
|
306
|
+
SQL template tag for raw SQL expressions — pipe.sql\`NOW()\`.
|
|
307
|
+
|
|
308
|
+
### `pipe.migrate`
|
|
309
|
+
|
|
310
|
+
Runs migrations for all configured databases.
|
|
311
|
+
|
|
312
|
+
### `pipe.migrateOne`
|
|
313
|
+
|
|
314
|
+
Runs migrations for a single named database.
|
|
315
|
+
|
|
316
|
+
## errors — Error Classes
|
|
317
|
+
|
|
318
|
+
Standard error classes — all extend PipeworkError with structured error codes and actionable messages.
|
|
319
|
+
|
|
320
|
+
### `errors.Base`
|
|
321
|
+
|
|
322
|
+
Base error class with code, statusCode, and suggestion fields.
|
|
323
|
+
|
|
324
|
+
### `errors.NotFound`
|
|
325
|
+
|
|
326
|
+
404 — resource not found.
|
|
327
|
+
|
|
328
|
+
### `errors.Unauthorized`
|
|
329
|
+
|
|
330
|
+
401 — missing or invalid authentication.
|
|
331
|
+
|
|
332
|
+
### `errors.Forbidden`
|
|
333
|
+
|
|
334
|
+
403 — authenticated but insufficient permissions.
|
|
335
|
+
|
|
336
|
+
### `errors.Validation`
|
|
337
|
+
|
|
338
|
+
422 — input validation failed, carries field-level details.
|
|
339
|
+
|
|
340
|
+
### `errors.Conflict`
|
|
341
|
+
|
|
342
|
+
409 — resource state conflict (duplicate, version mismatch).
|
|
343
|
+
|
|
344
|
+
## fitting — Dependency Injection
|
|
345
|
+
|
|
346
|
+
## fixture — REST Resources
|
|
347
|
+
|
|
348
|
+
REST resource builder namespace — declarative CRUD with cursor pagination and batch operations.
|
|
349
|
+
|
|
350
|
+
### `fixture.register`
|
|
351
|
+
|
|
352
|
+
Registers a Resource's routes on a Fastify instance.
|
|
353
|
+
|
|
354
|
+
### `fixture.build`
|
|
355
|
+
|
|
356
|
+
Builds a Resource from a name, operations map, and builder state — used internally by fitting().fixture().
|
|
357
|
+
|
|
358
|
+
### `fixture.encodeCursor`
|
|
359
|
+
|
|
360
|
+
Encodes pagination cursor values into an opaque base64 string.
|
|
361
|
+
|
|
362
|
+
### `fixture.decodeCursor`
|
|
363
|
+
|
|
364
|
+
Decodes an opaque pagination cursor back into its values.
|
|
365
|
+
|
|
366
|
+
### `fixture.buildPage`
|
|
367
|
+
|
|
368
|
+
Builds a PageResult from rows, limit, and cursor extractor — handles hasMore detection.
|
|
369
|
+
|
|
370
|
+
### `fixture.validateBatch`
|
|
371
|
+
|
|
372
|
+
Validates a batch request body (preview/execute mode, targets, actions).
|
|
373
|
+
|
|
374
|
+
### `fixture.MethodNotAllowedError`
|
|
375
|
+
|
|
376
|
+
Thrown when a resource doesn't support the requested HTTP method.
|
|
377
|
+
|
|
378
|
+
## flow — Context (AsyncLocalStorage)
|
|
379
|
+
|
|
380
|
+
AsyncLocalStorage context namespace — manages request/job/test contexts that carry auth, tenant, transactions.
|
|
381
|
+
|
|
382
|
+
### `flow.run`
|
|
383
|
+
|
|
384
|
+
Executes a function within a Flow context (AsyncLocalStorage). All pipe() calls inside will use this context.
|
|
385
|
+
|
|
386
|
+
### `flow.require`
|
|
387
|
+
|
|
388
|
+
Returns the current Flow or throws — use in code that must run inside a managed context.
|
|
389
|
+
|
|
390
|
+
### `flow.get`
|
|
391
|
+
|
|
392
|
+
Returns the current Flow or undefined — use for optional context detection.
|
|
393
|
+
|
|
394
|
+
### `flow.createRequest`
|
|
395
|
+
|
|
396
|
+
Creates a Flow for an HTTP request with auth, tenant, and request metadata.
|
|
397
|
+
|
|
398
|
+
### `flow.createJob`
|
|
399
|
+
|
|
400
|
+
Creates a Flow for a background job with optional auth and tenant.
|
|
401
|
+
|
|
402
|
+
### `flow.createTest`
|
|
403
|
+
|
|
404
|
+
Creates a Flow for test isolation with optional auth and tenant overrides.
|
|
405
|
+
|
|
406
|
+
### `flow.verifyBinding`
|
|
407
|
+
|
|
408
|
+
Defense-in-depth: verifies a transaction's nonce/tenant matches the current context.
|
|
409
|
+
|
|
410
|
+
### `flow.bindTransaction`
|
|
411
|
+
|
|
412
|
+
Binds a Drizzle transaction to the current context with nonce fingerprinting.
|
|
413
|
+
|
|
414
|
+
## http — Server
|
|
415
|
+
|
|
416
|
+
HTTP server namespace — Fastify wrapper with automatic request IDs, CORS, rate limiting, and transaction-per-request.
|
|
417
|
+
|
|
418
|
+
### `http.createServer`
|
|
419
|
+
|
|
420
|
+
Creates a PipeworkServer (Fastify wrapper) with production validation, auto request IDs, and transaction management.
|
|
421
|
+
|
|
422
|
+
### Types
|
|
423
|
+
|
|
424
|
+
**`CorsConfig`** — CORS configuration — origin, methods, headers, credentials, maxAge.
|
|
425
|
+
|
|
426
|
+
```typescript
|
|
427
|
+
interface CorsConfig
|
|
428
|
+
```
|
|
429
|
+
|
|
430
|
+
**`SecurityConfig`** — Security header configuration — passed to @fastify/helmet.
|
|
431
|
+
|
|
432
|
+
```typescript
|
|
433
|
+
interface SecurityConfig
|
|
434
|
+
```
|
|
435
|
+
|
|
436
|
+
**`RateLimitConfig`** — Rate limiting configuration — max requests, time window, key generator.
|
|
437
|
+
|
|
438
|
+
```typescript
|
|
439
|
+
interface RateLimitConfig
|
|
440
|
+
```
|
|
441
|
+
|
|
442
|
+
**`InjectOptions`** — Options for server.inject() — method, url, headers, payload for testing without HTTP.
|
|
443
|
+
|
|
444
|
+
```typescript
|
|
445
|
+
interface InjectOptions
|
|
446
|
+
```
|
|
447
|
+
|
|
448
|
+
**`InjectResponse`** — Response from server.inject() — statusCode, headers, body, json() helper.
|
|
449
|
+
|
|
450
|
+
```typescript
|
|
451
|
+
interface InjectResponse
|
|
452
|
+
```
|
|
453
|
+
|
|
454
|
+
**`ServerConfig`** — Configuration for http.createServer() — CORS, security headers, rate limiting, transaction timeout.
|
|
455
|
+
|
|
456
|
+
```typescript
|
|
457
|
+
interface ServerConfig
|
|
458
|
+
```
|
|
459
|
+
|
|
460
|
+
**`HandlerResponse`** — Standard handler response shape — statusCode, headers, body.
|
|
461
|
+
|
|
462
|
+
```typescript
|
|
463
|
+
interface HandlerResponse
|
|
464
|
+
```
|
|
465
|
+
|
|
466
|
+
**`ErrorResponse`** — Standard error response shape — { error: { code, message }, statusCode }.
|
|
467
|
+
|
|
468
|
+
```typescript
|
|
469
|
+
interface ErrorResponse
|
|
470
|
+
```
|
|
471
|
+
|
|
472
|
+
**`PipeworkServer`** — Fastify server wrapper with route registration, handler auto-wiring, and inject() for testing.
|
|
473
|
+
|
|
474
|
+
```typescript
|
|
475
|
+
interface PipeworkServer
|
|
476
|
+
```
|
|
477
|
+
|
|
478
|
+
**`HttpRequest`** — Fastify request with pipework extensions — req.id (UUID), typed headers.
|
|
479
|
+
|
|
480
|
+
```typescript
|
|
481
|
+
interface HttpRequest
|
|
482
|
+
```
|
|
483
|
+
|
|
484
|
+
**`HttpResponse`** — Fastify reply with pipework extensions.
|
|
485
|
+
|
|
486
|
+
```typescript
|
|
487
|
+
interface HttpResponse
|
|
488
|
+
```
|
|
489
|
+
|
|
490
|
+
## jobs — Background Jobs
|
|
491
|
+
|
|
492
|
+
Background job queue namespace — Postgres-backed with SKIP LOCKED, LISTEN/NOTIFY, cron scheduling.
|
|
493
|
+
|
|
494
|
+
### `jobs.createQueue`
|
|
495
|
+
|
|
496
|
+
Creates a job queue with claim/complete/fail lifecycle, heartbeat, and dead letter requeue.
|
|
497
|
+
|
|
498
|
+
### `jobs.execute`
|
|
499
|
+
|
|
500
|
+
Executes a fitting handler as a background job with its own Flow context.
|
|
501
|
+
|
|
502
|
+
### `jobs.parseCron`
|
|
503
|
+
|
|
504
|
+
Parses a 5-field cron expression into a CronSchedule (minute, hour, dom, month, dow).
|
|
505
|
+
|
|
506
|
+
### `jobs.nextTick`
|
|
507
|
+
|
|
508
|
+
Computes the next fire time for a CronSchedule after a given date, with optional timezone.
|
|
509
|
+
|
|
510
|
+
## lifecycle — Startup & Shutdown
|
|
511
|
+
|
|
512
|
+
Application lifecycle namespace — startup orchestration with hooks and timeouts.
|
|
513
|
+
|
|
514
|
+
### `lifecycle.orchestrate`
|
|
515
|
+
|
|
516
|
+
Runs pre-start hooks (DB readiness checks, migrations, etc.) with a configurable timeout.
|
|
517
|
+
|
|
518
|
+
## log — Structured Logging
|
|
519
|
+
|
|
520
|
+
Structured logger (Pino) — auto-binds requestId, tenantId, userId, sessionId from ALS context on every log call.
|
|
521
|
+
|
|
522
|
+
### `log.create`
|
|
523
|
+
|
|
524
|
+
Creates a new PipeworkLogger instance with custom config (level, redaction, transport).
|
|
525
|
+
|
|
526
|
+
### `log.get`
|
|
527
|
+
|
|
528
|
+
Returns the context-aware logger proxy (same as the log export itself).
|
|
529
|
+
|
|
530
|
+
### `log.getBase`
|
|
531
|
+
|
|
532
|
+
Returns the raw Pino logger without ALS context binding.
|
|
533
|
+
|
|
534
|
+
### `log.configure`
|
|
535
|
+
|
|
536
|
+
Sets global logging config (level, redaction paths, custom context fields).
|
|
537
|
+
|
|
538
|
+
### `log.REDACT_PATHS`
|
|
539
|
+
|
|
540
|
+
Default redaction paths — password, secret, token, authorization, cookie, etc.
|
|
541
|
+
|
|
542
|
+
## openapi — API Documentation
|
|
543
|
+
|
|
544
|
+
OpenAPI spec generation namespace.
|
|
545
|
+
|
|
546
|
+
### `openapi.generate`
|
|
547
|
+
|
|
548
|
+
Generates an OpenAPI 3.1 document from route registrations — schemas derived from fitting() input/output.
|
|
549
|
+
|
|
550
|
+
## pipeline — Multi-Step Pipelines
|
|
551
|
+
|
|
552
|
+
Multi-step pipeline namespace — define, execute, pause, and resume ordered step sequences.
|
|
553
|
+
|
|
554
|
+
### `pipeline.define`
|
|
555
|
+
|
|
556
|
+
Defines a pipeline from a config of named steps with handlers. Returns a Pipeline with execute/resume/getStatus.
|
|
557
|
+
|
|
558
|
+
### `pipeline.PipelineStepError`
|
|
559
|
+
|
|
560
|
+
Thrown when an individual pipeline step fails.
|
|
561
|
+
|
|
562
|
+
### `pipeline.PipelineResumeError`
|
|
563
|
+
|
|
564
|
+
Thrown when resuming a pipeline from an invalid state.
|
|
565
|
+
|
|
566
|
+
## rbac — Access Control
|
|
567
|
+
|
|
568
|
+
Role-based access control namespace — permission checking, enforcement, scope hierarchy.
|
|
569
|
+
|
|
570
|
+
### `rbac.create`
|
|
571
|
+
|
|
572
|
+
Creates an Rbac instance from config (roles, permissions, hierarchy).
|
|
573
|
+
|
|
574
|
+
### `rbac.check`
|
|
575
|
+
|
|
576
|
+
Checks if a permission set includes the required resource/action/scope. Pure function, no DB.
|
|
577
|
+
|
|
578
|
+
### `rbac.enforce`
|
|
579
|
+
|
|
580
|
+
Checks permission and throws ForbiddenError if denied. Loads permissions from DB with caching.
|
|
581
|
+
|
|
582
|
+
### `rbac.satisfies`
|
|
583
|
+
|
|
584
|
+
Checks if a granted scope satisfies a required scope given a hierarchy (e.g. org > team > self).
|
|
585
|
+
|
|
586
|
+
### `rbac.PermissionCache`
|
|
587
|
+
|
|
588
|
+
LRU cache for resolved permissions — avoids repeated DB lookups within a request.
|
|
589
|
+
|
|
590
|
+
## schema — Validation & Schema
|
|
591
|
+
|
|
592
|
+
Schema definition and validation namespace — wraps zod for validation, drizzle for table/column/index definitions.
|
|
593
|
+
|
|
594
|
+
### `schema.check`
|
|
595
|
+
|
|
596
|
+
Validation sub-namespace — type constructors, combinators, formats, coerce, parse, tryParse, toJsonSchema, branded.
|
|
597
|
+
|
|
598
|
+
### `schema.col`
|
|
599
|
+
|
|
600
|
+
Column type builders for table definitions — text, uuid, integer, timestamp, jsonb, boolean, varchar, etc.
|
|
601
|
+
|
|
602
|
+
### `schema.idx`
|
|
603
|
+
|
|
604
|
+
Index and constraint builders — index, uniqueIndex, primaryKey, foreignKey, unique, check.
|
|
605
|
+
|
|
606
|
+
### Types
|
|
607
|
+
|
|
608
|
+
**`Schema`** — Any validation schema — the base type accepted by .input(), .query(), .params() in the fitting builder.
|
|
609
|
+
|
|
610
|
+
```typescript
|
|
611
|
+
type Schema<T = unknown> = z.ZodType<T>
|
|
612
|
+
```
|
|
613
|
+
|
|
614
|
+
**`Infer`** — Extracts the TypeScript type from a Schema — Infer<typeof mySchema> gives you the validated type.
|
|
615
|
+
|
|
616
|
+
```typescript
|
|
617
|
+
type Infer<T extends Schema> = z.infer<T>
|
|
618
|
+
```
|
|
619
|
+
|
|
620
|
+
## state
|
|
621
|
+
|
|
622
|
+
State machine namespace — define valid transitions with guards and side effects.
|
|
623
|
+
|
|
624
|
+
### `state.define`
|
|
625
|
+
|
|
626
|
+
Defines a state machine from states, transitions, guards, and effects. Returns a StateMachine with transition/canTransition.
|
|
627
|
+
|
|
628
|
+
### `state.InvalidTransitionError`
|
|
629
|
+
|
|
630
|
+
Thrown when a transition is not allowed from the current state.
|
|
631
|
+
|
|
632
|
+
### `state.InvalidStateMachineError`
|
|
633
|
+
|
|
634
|
+
Thrown when the state machine definition is internally inconsistent.
|
|
635
|
+
|
|
636
|
+
## surface — Entry Points
|
|
637
|
+
|
|
638
|
+
Surface namespace — declarative entry points that define how the app runs (HTTP server, background worker, one-shot script).
|
|
639
|
+
|
|
640
|
+
### `surface.http`
|
|
641
|
+
|
|
642
|
+
Creates an HTTP surface — a Fastify server with routes, middleware, and production validation.
|
|
643
|
+
|
|
644
|
+
### `surface.worker`
|
|
645
|
+
|
|
646
|
+
Creates a worker surface — a long-running process that claims and executes jobs from queues.
|
|
647
|
+
|
|
648
|
+
### `surface.script`
|
|
649
|
+
|
|
650
|
+
Creates a script surface — a one-shot process that runs and exits (migrations, seeds, CLI tools).
|
|
651
|
+
|
|
652
|
+
## temporal — Bitemporal Data
|
|
653
|
+
|
|
654
|
+
Temporal (bitemporal) data namespace — version history with effective date ranges.
|
|
655
|
+
|
|
656
|
+
### `temporal.columns`
|
|
657
|
+
|
|
658
|
+
Returns the standard temporal column definitions (effectiveFrom, effectiveTo, version, createdBy) for table schemas.
|
|
659
|
+
|
|
660
|
+
### `temporal.revise`
|
|
661
|
+
|
|
662
|
+
Creates a new version of a temporal record, closing the previous version's effectiveTo.
|
|
663
|
+
|
|
664
|
+
### `temporal.close`
|
|
665
|
+
|
|
666
|
+
Closes a temporal record by setting effectiveTo to now. Returns number of rows affected.
|
|
667
|
+
|
|
668
|
+
### `temporal.current`
|
|
669
|
+
|
|
670
|
+
Fetches the currently-effective version of a temporal record (effectiveTo IS NULL).
|
|
671
|
+
|
|
672
|
+
### `temporal.atTime`
|
|
673
|
+
|
|
674
|
+
Returns a SQL condition for records effective at a specific point in time.
|
|
675
|
+
|
|
676
|
+
### `temporal.between`
|
|
677
|
+
|
|
678
|
+
Returns a SQL condition for records overlapping a date range.
|
|
679
|
+
|
|
680
|
+
### `temporal.TemporalIntegrityError`
|
|
681
|
+
|
|
682
|
+
Thrown when a temporal operation would violate version continuity.
|
|
683
|
+
|
|
684
|
+
## tenant — Multi-Tenancy
|
|
685
|
+
|
|
686
|
+
Multi-tenant isolation namespace — RLS policies, tenant extraction, Postgres-side verification.
|
|
687
|
+
|
|
688
|
+
### `tenant.validate`
|
|
689
|
+
|
|
690
|
+
Validates a tenant ID format (non-empty string, safe characters).
|
|
691
|
+
|
|
692
|
+
### `tenant.rls`
|
|
693
|
+
|
|
694
|
+
Enables RLS on a table and creates the tenant isolation policy in Postgres.
|
|
695
|
+
|
|
696
|
+
### `tenant.policy`
|
|
697
|
+
|
|
698
|
+
Returns the SQL string for a tenant isolation RLS policy — use in migrations.
|
|
699
|
+
|
|
700
|
+
### `tenant.verify`
|
|
701
|
+
|
|
702
|
+
Cross-checks ALS tenant against Postgres set_config('pipework.tenant_id') — defense-in-depth.
|
|
703
|
+
|
|
704
|
+
### `tenant.propagate`
|
|
705
|
+
|
|
706
|
+
Sets pipework.tenant_id on the Postgres connection via set_config().
|
|
707
|
+
|
|
708
|
+
### `tenant.extract`
|
|
709
|
+
|
|
710
|
+
Extracts tenant ID from auth context using the configured extraction strategy.
|
|
711
|
+
|
|
712
|
+
### `tenant.scoped`
|
|
713
|
+
|
|
714
|
+
Marks a table as tenant-scoped — pipe() will auto-filter by tenant_id.
|
|
715
|
+
|
|
716
|
+
### `tenant.isTenantScoped`
|
|
717
|
+
|
|
718
|
+
Returns true if a table has been marked as tenant-scoped.
|
|
719
|
+
|
|
720
|
+
## vector — Vector & Full-Text Search
|
|
721
|
+
|
|
722
|
+
Vector and full-text search namespace — pgvector column types and similarity/ranking queries.
|
|
723
|
+
|
|
724
|
+
### `vector.column`
|
|
725
|
+
|
|
726
|
+
Defines a vector(N) column for embeddings.
|
|
727
|
+
|
|
728
|
+
### `vector.tsvector`
|
|
729
|
+
|
|
730
|
+
Defines a tsvector column for full-text search.
|
|
731
|
+
|
|
732
|
+
### `vector.cosine`
|
|
733
|
+
|
|
734
|
+
Cosine distance between a column and a query vector (lower = more similar).
|
|
735
|
+
|
|
736
|
+
### `vector.cosineSimilarity`
|
|
737
|
+
|
|
738
|
+
Cosine similarity (higher = more similar) — 1 - cosineDistance.
|
|
739
|
+
|
|
740
|
+
### `vector.l2`
|
|
741
|
+
|
|
742
|
+
L2 (Euclidean) distance between a column and a query vector.
|
|
743
|
+
|
|
744
|
+
### `vector.innerProduct`
|
|
745
|
+
|
|
746
|
+
Inner product between a column and a query vector.
|
|
747
|
+
|
|
748
|
+
### `vector.toTsvector`
|
|
749
|
+
|
|
750
|
+
Converts text to a tsvector for full-text indexing.
|
|
751
|
+
|
|
752
|
+
### `vector.toTsquery`
|
|
753
|
+
|
|
754
|
+
Converts a search query string to a tsquery.
|
|
755
|
+
|
|
756
|
+
### `vector.rank`
|
|
757
|
+
|
|
758
|
+
Computes ts_rank for full-text search result ordering.
|
|
759
|
+
|
|
760
|
+
### `vector.validate`
|
|
761
|
+
|
|
762
|
+
Verifies the pgvector extension is installed and accessible.
|
|
763
|
+
|
|
764
|
+
## webhook — Inbound & Outbound Webhooks
|
|
765
|
+
|
|
766
|
+
Webhook namespace — inbound verification, outbound delivery with retries, HMAC signing.
|
|
767
|
+
|
|
768
|
+
### `webhook.defineInbound`
|
|
769
|
+
|
|
770
|
+
Defines an inbound webhook handler with signature verification and optional idempotency.
|
|
771
|
+
|
|
772
|
+
### `webhook.createOutbound`
|
|
773
|
+
|
|
774
|
+
Creates an outbound webhook system — endpoint registration, payload signing, delivery with retries.
|
|
775
|
+
|
|
776
|
+
### `webhook.sign`
|
|
777
|
+
|
|
778
|
+
Signs a payload with HMAC for outbound delivery — returns body, signature, timestamp, messageId.
|