@palbase/backend 33.0.2 → 34.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/palbase-backend.cjs +2020 -350
- package/dist/bin/palbase-backend.cjs.map +1 -1
- package/dist/bin/palbase-backend.js +9 -7
- package/dist/bin/palbase-backend.js.map +1 -1
- package/dist/{chunk-SI4KGEM3.js → chunk-FOWA7PF4.js} +97 -96
- package/dist/chunk-FOWA7PF4.js.map +1 -0
- package/dist/chunk-GHNC2UHS.js +20 -0
- package/dist/chunk-GHNC2UHS.js.map +1 -0
- package/dist/{chunk-AAT5G7KY.js → chunk-JJW3L62T.js} +2 -2
- package/dist/chunk-JJW3L62T.js.map +1 -0
- package/dist/{chunk-TVCCR6SO.js → chunk-LOGL2ZHD.js} +58 -9
- package/dist/chunk-LOGL2ZHD.js.map +1 -0
- package/dist/{chunk-C6COAB3E.js → chunk-MNGZE2MM.js} +1651 -186
- package/dist/chunk-MNGZE2MM.js.map +1 -0
- package/dist/{chunk-XOX6RFPZ.js → chunk-PRH45NZU.js} +46 -3
- package/dist/chunk-PRH45NZU.js.map +1 -0
- package/dist/{chunk-26GH54D2.js → chunk-RZLY4BOY.js} +5 -3
- package/dist/{chunk-26GH54D2.js.map → chunk-RZLY4BOY.js.map} +1 -1
- package/dist/{chunk-YIQ4RS4F.js → chunk-SEM36BWY.js} +283 -5
- package/dist/chunk-SEM36BWY.js.map +1 -0
- package/dist/{chunk-KATPXCJ5.js → chunk-UMESJJRS.js} +19 -40
- package/dist/chunk-UMESJJRS.js.map +1 -0
- package/dist/chunk-VXPNPVAG.js +40 -0
- package/dist/chunk-VXPNPVAG.js.map +1 -0
- package/dist/{chunk-WWUG2QXF.js → chunk-YX7UA7VC.js} +53 -4
- package/dist/chunk-YX7UA7VC.js.map +1 -0
- package/dist/db/env.cjs.map +1 -1
- package/dist/db/env.d.cts +2 -0
- package/dist/db/env.d.ts +2 -0
- package/dist/db/index.cjs +261 -2
- package/dist/db/index.cjs.map +1 -1
- package/dist/db/index.d.cts +46 -3
- package/dist/db/index.d.ts +46 -3
- package/dist/db/index.js +14 -5
- package/dist/{index-DMZG3kpo.d.ts → endpoint-DpNUx-ON.d.ts} +315 -57
- package/dist/{index-DB_nW-AV.d.cts → endpoint-kYgEHrrV.d.cts} +315 -57
- package/dist/engine/index.cjs +2026 -348
- package/dist/engine/index.cjs.map +1 -1
- package/dist/engine/index.d.cts +5 -5
- package/dist/engine/index.d.ts +5 -5
- package/dist/engine/index.js +17 -7
- package/dist/{index-D-3duy8Y.d.ts → index-JrHqNsjQ.d.ts} +108 -50
- package/dist/{index-DLveQoOf.d.cts → index-pnDsEfxJ.d.cts} +108 -50
- package/dist/index.cjs +616 -254
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -6
- package/dist/index.d.ts +7 -6
- package/dist/index.js +25 -15
- package/dist/index.js.map +1 -1
- package/dist/openapi/index.cjs +7 -0
- package/dist/openapi/index.cjs.map +1 -1
- package/dist/openapi/index.d.cts +3 -3
- package/dist/openapi/index.d.ts +3 -3
- package/dist/openapi/index.js +4 -3
- package/dist/openapi/index.js.map +1 -1
- package/dist/{registry-DSTThhKf.d.cts → registry-BcOd8Zhf.d.cts} +3 -1
- package/dist/{registry-JjF5lcj4.d.ts → registry-BoX5iNyY.d.ts} +3 -1
- package/dist/test/index.cjs +103 -66
- package/dist/test/index.cjs.map +1 -1
- package/dist/test/index.d.cts +3 -3
- package/dist/test/index.d.ts +3 -3
- package/dist/test/index.js +33 -7
- package/dist/test/index.js.map +1 -1
- package/docs/README.md +1 -1
- package/docs/database.md +308 -0
- package/docs/examples/check-query-contracts.ts +5 -0
- package/docs/examples/database-dx.contract.json +65 -0
- package/docs/examples/database-dx.ts +63 -0
- package/docs/examples/money-transfer.ts +73 -0
- package/docs/llms-full.txt +309 -1
- package/package.json +1 -2
- package/template/package.json +1 -1
- package/dist/chunk-AAT5G7KY.js.map +0 -1
- package/dist/chunk-C6COAB3E.js.map +0 -1
- package/dist/chunk-KATPXCJ5.js.map +0 -1
- package/dist/chunk-SI4KGEM3.js.map +0 -1
- package/dist/chunk-TVCCR6SO.js.map +0 -1
- package/dist/chunk-WWUG2QXF.js.map +0 -1
- package/dist/chunk-XOX6RFPZ.js.map +0 -1
- package/dist/chunk-YIQ4RS4F.js.map +0 -1
- package/stack-images.json +0 -24
package/docs/llms-full.txt
CHANGED
|
@@ -90,7 +90,7 @@ service the controllers call.
|
|
|
90
90
|
|
|
91
91
|
> **Never** emit `defineController`, `defineHandler`, `defineEndpoint`, `route.get(...)`,
|
|
92
92
|
> `req.input`, `req.params`, or `req.errors` — those are the removed legacy model
|
|
93
|
-
> and will not compile against `@palbase/backend`
|
|
93
|
+
> and will not compile against `@palbase/backend` 34.
|
|
94
94
|
|
|
95
95
|
### Complete CRUD example (copy-pasteable, compiles)
|
|
96
96
|
|
|
@@ -1075,6 +1075,69 @@ await Database.public.todos.delete(todo.id);
|
|
|
1075
1075
|
|
|
1076
1076
|
See [schema.md](./schema.md) for the full typed-table surface.
|
|
1077
1077
|
|
|
1078
|
+
## Transaction boundaries and retries
|
|
1079
|
+
|
|
1080
|
+
Ordinary Database writes commit when the request completes. `$transaction(fn)`
|
|
1081
|
+
builds a synchronous plan executed inside a savepoint of that same transaction.
|
|
1082
|
+
A savepoint cannot refresh its parent snapshot or retry the parent's COMMIT;
|
|
1083
|
+
passing a nonzero `retry` to `$transaction` is refused with a migration message.
|
|
1084
|
+
|
|
1085
|
+
Use `$atomic` for an explicit, independently committed transaction with ordinary
|
|
1086
|
+
async reads and writes. Its promise resolves after COMMIT succeeds. Every retry
|
|
1087
|
+
opens a fresh transaction and reruns the complete callback, including decision
|
|
1088
|
+
reads. Choose `read committed`, `repeatable read` or `serializable` isolation.
|
|
1089
|
+
|
|
1090
|
+
```ts
|
|
1091
|
+
import { Conflict, NotFound, decrement } from "@palbase/backend";
|
|
1092
|
+
|
|
1093
|
+
const result = await Database.$atomic(async (tx) => {
|
|
1094
|
+
const account = await tx.public.accounts.findById(accountId);
|
|
1095
|
+
if (!account) throw new NotFound();
|
|
1096
|
+
// All dependent writes, the ledger and an outbox event belong in this scope.
|
|
1097
|
+
return tx.$transaction((plan) => {
|
|
1098
|
+
return plan.public.accounts.updateWhere(
|
|
1099
|
+
{ id: accountId, balance: { gte: amount } },
|
|
1100
|
+
{ balance: decrement(amount) },
|
|
1101
|
+
).expectOne(new Conflict("Insufficient balance"));
|
|
1102
|
+
});
|
|
1103
|
+
}, { isolation: "serializable", retry: 3, lockTimeoutMs: 1000, statementTimeoutMs: 5000 });
|
|
1104
|
+
```
|
|
1105
|
+
|
|
1106
|
+
`retry` defaults to 0 and is limited to 10. Only serialization and deadlock
|
|
1107
|
+
failures are retried. A lost connection during COMMIT has an unknown outcome
|
|
1108
|
+
and is not automatically replayed; use an idempotency key to reconcile it.
|
|
1109
|
+
Keep external effects out of a retried callback: write an outbox record there
|
|
1110
|
+
and deliver it after commit.
|
|
1111
|
+
|
|
1112
|
+
The complete [money-transfer.ts](./examples/money-transfer.ts) recipe uses the
|
|
1113
|
+
public `DBClient.atomic` seam, typed guards, exact integer minor units, a payload
|
|
1114
|
+
checked idempotency key, ordered account locks, balanced ledger entries and an
|
|
1115
|
+
outbox. Its `transferSchema` declares the database constraints and tenant RLS;
|
|
1116
|
+
export it from `db/public.ts`, review `palbase db plan` and run `palbase db apply`.
|
|
1117
|
+
It is the same transfer body used by the real PostgreSQL verification suite;
|
|
1118
|
+
importing it alone does not apply its constraints. Derive `input.tenant` from verified application scope. Use globally
|
|
1119
|
+
unique request keys, or include the tenant in the key. An outbox worker delivers
|
|
1120
|
+
after commit and consumers deduplicate by event id.
|
|
1121
|
+
|
|
1122
|
+
`$atomic` commits independently: a later handler error does not undo it. Avoid
|
|
1123
|
+
writing the same data in the surrounding request transaction. The callback's
|
|
1124
|
+
typed `tx` and ambient `Database` calls share its transaction. Handles saved from
|
|
1125
|
+
another transaction, nested roots and `$asService()` inside it are refused.
|
|
1126
|
+
For service-role work choose `Database.$asService().$atomic(...)` before entering
|
|
1127
|
+
the callback; it keeps that one identity throughout every retry.
|
|
1128
|
+
|
|
1129
|
+
The request's default and service-role surfaces remain separate transactions;
|
|
1130
|
+
their commits are not atomic together. Put a business operation's atomic writes
|
|
1131
|
+
in one `$atomic` scope. `fakeDatabase` does not emulate PostgreSQL isolation or
|
|
1132
|
+
commit/retry behavior; use a real PostgreSQL test for that boundary.
|
|
1133
|
+
|
|
1134
|
+
Schema-aware timestamp results use UTC ISO strings with six fractional digits,
|
|
1135
|
+
preserving PostgreSQL microseconds through reads, returned writes, relations,
|
|
1136
|
+
aggregates and transaction plan references. Infinities, BC dates and years outside
|
|
1137
|
+
1–9999 retain PostgreSQL's text representation. These queries return the declared
|
|
1138
|
+
column shape. Raw `$query` results follow the driver's types; request `column::text`
|
|
1139
|
+
when a raw query must preserve timestamp precision rather than a JavaScript Date.
|
|
1140
|
+
|
|
1078
1141
|
## Raw string-keyed operations
|
|
1079
1142
|
|
|
1080
1143
|
For a table name computed at runtime, or for SQL the typed helpers do not
|
|
@@ -1752,6 +1815,251 @@ Guidelines:
|
|
|
1752
1815
|
second surface waits for a lock the first cannot release until the handler
|
|
1753
1816
|
returns. The service side gives up after five seconds and tells you this;
|
|
1754
1817
|
the default side would wait until the edge cuts the request.
|
|
1818
|
+
## Cursor pages and bulk counts
|
|
1819
|
+
|
|
1820
|
+
`page` returns `{ rows, pageInfo }`. A projection narrows `rows` in TypeScript;
|
|
1821
|
+
the cursor keeps the ordering values independently, including fields omitted by
|
|
1822
|
+
`select`.
|
|
1823
|
+
|
|
1824
|
+
```ts
|
|
1825
|
+
const page = await Database.public.todos.page({
|
|
1826
|
+
select: ["id", "title"],
|
|
1827
|
+
orderBy: { column: "created_at", direction: "desc" },
|
|
1828
|
+
first: 50,
|
|
1829
|
+
after: cursor, // omit for the first page
|
|
1830
|
+
});
|
|
1831
|
+
// Next: after: page.pageInfo.endCursor
|
|
1832
|
+
// Previous: last: 50, before: page.pageInfo.startCursor
|
|
1833
|
+
```
|
|
1834
|
+
|
|
1835
|
+
Sizes are 1–1000 (default 50). Use `first`/`after` or `last`/`before` together.
|
|
1836
|
+
The engine appends every missing primary-key column to the ordering, including
|
|
1837
|
+
composite keys. `direction` and `nulls` are honored independently. Both directions
|
|
1838
|
+
return rows in the requested order. Empty pages have null cursors and report
|
|
1839
|
+
whether matching rows remain on the opposite side of the supplied boundary.
|
|
1840
|
+
The page and its flags use one PostgreSQL statement snapshot. Across requests,
|
|
1841
|
+
inserts, deletes and changes to ordering fields can change the list; a cursor is
|
|
1842
|
+
not a frozen snapshot. Prefer immutable ordering columns for exports.
|
|
1843
|
+
|
|
1844
|
+
Install the table declaration and an index matching the tenant/filter columns
|
|
1845
|
+
followed by the ordering columns and primary key. Keyset pagination avoids
|
|
1846
|
+
scanning a skipped prefix; it does not provide arbitrary page-number jumps.
|
|
1847
|
+
JSON/vector ordering is refused. Text ordering follows the database collation.
|
|
1848
|
+
|
|
1849
|
+
In the engine, cursor encryption uses `PALBASE_CURSOR_SECRET`, falling back to
|
|
1850
|
+
`PALBASE_SERVICE_ROLE_KEY`. Keep this secret shared across replicas and restarts;
|
|
1851
|
+
rotation invalidates existing cursors. Cursors are tied to the table declaration,
|
|
1852
|
+
filter, projection, relations, ordering and authorization claims (JWT issuance/
|
|
1853
|
+
expiry identifiers are excluded). Reusing one with another query or identity
|
|
1854
|
+
returns `BadRequest`. A malformed token is rejected before database access.
|
|
1855
|
+
Standalone engine consumers configure `setCursorKey(secret)` from the engine
|
|
1856
|
+
entrypoint. `fakeDatabase` requires an explicit page test double; PostgreSQL
|
|
1857
|
+
integration tests cover collation, RLS and cursor semantics.
|
|
1858
|
+
|
|
1859
|
+
```ts
|
|
1860
|
+
const inserted = await Database.public.todos.insertMany(rows, {
|
|
1861
|
+
returning: false,
|
|
1862
|
+
});
|
|
1863
|
+
```
|
|
1864
|
+
|
|
1865
|
+
`inserted` is a number. The engine omits `RETURNING` and reads PostgreSQL's affected
|
|
1866
|
+
row count, including zero when `onConflict` with `action: "ignore"` skips every
|
|
1867
|
+
row. `action: "update"` counts both inserted and updated rows. The default returns
|
|
1868
|
+
rows as before; a dynamic boolean produces a `number | Row[]` type. This option
|
|
1869
|
+
belongs to the asynchronous bulk surface; declarative transaction plan row handles
|
|
1870
|
+
continue to return their rows. Custom SQL drivers must expose an integer `count`
|
|
1871
|
+
on a non-returning result. Empty input opens no connection. The batch remains one
|
|
1872
|
+
statement and participates in its enclosing transaction's rollback.
|
|
1873
|
+
|
|
1874
|
+
## Reusable queries and response contracts
|
|
1875
|
+
|
|
1876
|
+
`defineQuery` combines an explicit selection with a reusable input/filter. The
|
|
1877
|
+
result is also a Zod array schema: a controller can return
|
|
1878
|
+
`Promise<z.infer<typeof ListTodos>>`, and the existing build binder uses that
|
|
1879
|
+
same value for response validation, OpenAPI and generated clients.
|
|
1880
|
+
|
|
1881
|
+
```ts
|
|
1882
|
+
export const ListTodos = defineQuery("ListTodos", {
|
|
1883
|
+
table: todos, // a defineTable value already registered by defineSchema
|
|
1884
|
+
input: z.object({ prefix: z.string().default("") }),
|
|
1885
|
+
select: ["id", "title"],
|
|
1886
|
+
where: ({ prefix }) => ({ title: { startsWith: prefix } }),
|
|
1887
|
+
orderBy: { column: "id" },
|
|
1888
|
+
limit: 50,
|
|
1889
|
+
});
|
|
1890
|
+
|
|
1891
|
+
const rows = await ListTodos.run(Database, { prefix: "Buy" });
|
|
1892
|
+
const compiled = ListTodos.sql(Database, { prefix: "Buy" }); // no connection
|
|
1893
|
+
// compiled.sql and compiled.params describe the same statement run() executes.
|
|
1894
|
+
```
|
|
1895
|
+
|
|
1896
|
+
`run` validates its input before SQL and its response before returning. SQL uses
|
|
1897
|
+
the same SELECT compiler as `findMany`, under the caller's transaction and RLS
|
|
1898
|
+
identity. Table names retain their declared schema. Selection is mandatory;
|
|
1899
|
+
unselected database columns cannot silently expand the API. Numeric/bigint and
|
|
1900
|
+
timestamp outputs retain their exact string representations, and named codecs
|
|
1901
|
+
determine the surfaced type. A selected `jsonb<T>()` needs a matching Zod schema
|
|
1902
|
+
in `fields: { payload: PayloadSchema }`, because its TypeScript payload is erased
|
|
1903
|
+
at runtime. Free-form column transforms require migration to a named codec.
|
|
1904
|
+
|
|
1905
|
+
Keep a contract manifest in the application repository:
|
|
1906
|
+
|
|
1907
|
+
```ts
|
|
1908
|
+
const generated = queryManifest([ListTodos]);
|
|
1909
|
+
// Write generated JSON for the initial, reviewed baseline.
|
|
1910
|
+
assertQueryManifest([ListTodos], committedManifest); // run in the CI/build check
|
|
1911
|
+
```
|
|
1912
|
+
|
|
1913
|
+
The manifest contains input/response OpenAPI components, selected storage types,
|
|
1914
|
+
nullability and codecs. A changed contract fails the check until its diff is
|
|
1915
|
+
reviewed and the committed baseline is updated. The runtime also refuses a query
|
|
1916
|
+
whose selected columns disagree with the installed declaration, before SQL.
|
|
1917
|
+
This check compares declarations; migration validation still owns drift in the
|
|
1918
|
+
physical PostgreSQL schema. Queries currently project one table; use `findMany`
|
|
1919
|
+
or `page` for nested relation reads.
|
|
1920
|
+
|
|
1921
|
+
`await ListTodos.explain(Database, input)` executes plain `EXPLAIN (FORMAT JSON)`
|
|
1922
|
+
with the same role and parameters. It never enables `ANALYZE`. Plans can contain
|
|
1923
|
+
filter literals, so inspect them in development/operator tooling. No EXPLAIN is
|
|
1924
|
+
run automatically on production requests. The complete controller/schema example
|
|
1925
|
+
is [examples/database-dx.ts](./examples/database-dx.ts).
|
|
1926
|
+
|
|
1927
|
+
## Nested relations and unique lookups
|
|
1928
|
+
|
|
1929
|
+
`with` accepts three relation edges, with independent selection, filtering,
|
|
1930
|
+
ordering and limits at each level. The whole read remains one SQL statement.
|
|
1931
|
+
Each related table retains RLS; `many` returns an array, `one` returns a row or
|
|
1932
|
+
null. Numeric/bigint strings, timestamp microseconds, vectors and named codecs
|
|
1933
|
+
are restored at each level. Joins use the foreign key's declared target column,
|
|
1934
|
+
including a non-primary unique column.
|
|
1935
|
+
|
|
1936
|
+
```ts
|
|
1937
|
+
const customers = await Database.billing.customers.findMany({
|
|
1938
|
+
select: ["id"],
|
|
1939
|
+
with: { invoices: { select: ["id"], limit: 10,
|
|
1940
|
+
with: { customer: { select: ["name"] } },
|
|
1941
|
+
} },
|
|
1942
|
+
});
|
|
1943
|
+
|
|
1944
|
+
const account = await Database.public.accounts.findUnique({
|
|
1945
|
+
where: { tenant_id: tenantId, account_number: number },
|
|
1946
|
+
select: ["balance"],
|
|
1947
|
+
});
|
|
1948
|
+
```
|
|
1949
|
+
|
|
1950
|
+
The lookup example requires a declared unique/primary key on
|
|
1951
|
+
`["tenant_id", "account_number"]`. Regenerate `palbase-env.d.ts` to get exact key
|
|
1952
|
+
types. Supply one entire key; partial composites, mixed keys, operators and null
|
|
1953
|
+
values are refused. A missing or RLS-hidden row returns null. More than one match
|
|
1954
|
+
raises a constraint-drift error. The direct `makeTypedDB` facade validates keys
|
|
1955
|
+
at runtime; the generated `Database.<schema>.<table>` surface also checks them at
|
|
1956
|
+
compile time. `findById` keeps its existing `id`-column contract.
|
|
1957
|
+
|
|
1958
|
+
## Commands and workload admission
|
|
1959
|
+
|
|
1960
|
+
`$command` accepts the synchronous transaction-plan callback used by
|
|
1961
|
+
`$transaction`. It retains guards, dependent row references, sequential visibility
|
|
1962
|
+
and savepoint rollback. Its default `mode: "auto"` compiles supported plans when
|
|
1963
|
+
the helper is installed and uses the sequential path otherwise. Choose
|
|
1964
|
+
`mode: "compiled"` to require compilation or `mode: "sequential"` to opt out.
|
|
1965
|
+
It settles with its enclosing transaction; an independently durable command
|
|
1966
|
+
belongs inside `$atomic`.
|
|
1967
|
+
|
|
1968
|
+
Enable the helper with `PALBASE_DB_COMMANDS=true`; standalone engine consumers
|
|
1969
|
+
call `installCommandExecutor(driver, roles)`. Installation needs DDL rights.
|
|
1970
|
+
Execution is `SECURITY INVOKER`, so the caller's role and RLS remain active.
|
|
1971
|
+
Compilation currently excludes SQL fragments, column codecs/transforms, vector
|
|
1972
|
+
tables, nullable WHERE references and certain JavaScript number/JSON scalar
|
|
1973
|
+
bindings whose driver semantics would differ. Strict mode refuses these before
|
|
1974
|
+
SQL; automatic mode preserves the sequential behavior. Plans with no row refs
|
|
1975
|
+
send parameterized statements in order on one connection without waiting for
|
|
1976
|
+
each result before submitting the next. SQL guards abort before later queued
|
|
1977
|
+
writes run, and the engine drains every result before rollback. These are still
|
|
1978
|
+
separate SQL statements, with sequential visibility. Plans with row refs use
|
|
1979
|
+
one invoker helper call with sequential statements inside PostgreSQL. The helper
|
|
1980
|
+
adds JSON/dynamic-SQL processing; measure the actual plan and network before
|
|
1981
|
+
selecting it for throughput. Fewer round trips alone do not guarantee a speedup.
|
|
1982
|
+
|
|
1983
|
+
For contention on the same accounts/resources, declare a workload once:
|
|
1984
|
+
|
|
1985
|
+
```ts
|
|
1986
|
+
const transfers = defineWorkload("transfers", {
|
|
1987
|
+
concurrency: 16, queueLimit: 128,
|
|
1988
|
+
tenantConcurrency: 8, tenantQueueLimit: 32, queueTimeoutMs: 1000,
|
|
1989
|
+
});
|
|
1990
|
+
|
|
1991
|
+
await Database.$atomic(async tx => {
|
|
1992
|
+
// Decision reads, idempotency claim, writes, ledger and outbox belong here.
|
|
1993
|
+
}, {
|
|
1994
|
+
workload: transfers,
|
|
1995
|
+
conflictKeys: [fromAccountId, toAccountId],
|
|
1996
|
+
timeoutMs: 3000, signal, retry: 2,
|
|
1997
|
+
});
|
|
1998
|
+
```
|
|
1999
|
+
|
|
2000
|
+
Overlapping resource keys are admitted in order. Independent keys and tenants
|
|
2001
|
+
can proceed while those requests wait. Queue size and per-tenant budgets are
|
|
2002
|
+
bounded; full/expired queues return 429 before opening a transaction. Tenant
|
|
2003
|
+
identity comes from the configured verified claim (`tenant_id`, then `sub`, then
|
|
2004
|
+
one anonymous bucket). Keys are shared within a workload; include the tenant in
|
|
2005
|
+
a key if resource IDs are only tenant-unique. Rejected/cancelled waiters leave the
|
|
2006
|
+
queue. The lease spans every retry and transaction settlement.
|
|
2007
|
+
|
|
2008
|
+
These limits apply per engine/driver instance. Divide pool/admission budgets
|
|
2009
|
+
across replicas; PostgreSQL locks and constraints remain authoritative across
|
|
2010
|
+
instances. Admission is optional because independent work also pays its cost.
|
|
2011
|
+
Each driver supports at most 64 named workloads.
|
|
2012
|
+
|
|
2013
|
+
`timeoutMs` includes queueing, callback work and retries. The default driver uses
|
|
2014
|
+
a separate control pool of at most two connections to cancel active PostgreSQL
|
|
2015
|
+
statements. Reserve those connections in the deployment budget. Standalone Bun
|
|
2016
|
+
drivers can use `withQueryCancellation(applicationPool, controlPool)` with the
|
|
2017
|
+
same server/login. The engine waits for cancellation and rollback before releasing
|
|
2018
|
+
the application connection. JavaScript callbacks themselves are not preempted;
|
|
2019
|
+
late DB handles are invalidated. Pool acquisition and an in-flight COMMIT still
|
|
2020
|
+
have to settle, so the deadline is not a hard wall-clock response guarantee.
|
|
2021
|
+
An acknowledged COMMIT stays successful; an unknown commit outcome is never
|
|
2022
|
+
automatically replayed.
|
|
2023
|
+
|
|
2024
|
+
## Query diagnostics and budgets
|
|
2025
|
+
|
|
2026
|
+
Set `PALBASE_DB_DIAGNOSTICS=true` for request summaries, or provide
|
|
2027
|
+
`EngineConfig.databaseDiagnostics` with `onQuery`/`onComplete` callbacks.
|
|
2028
|
+
Standalone consumers pass the same options as the third argument to
|
|
2029
|
+
`createRequestDatabase`. Diagnostics are disabled by default. For a route budget:
|
|
2030
|
+
|
|
2031
|
+
```ts
|
|
2032
|
+
@Get("/", { databaseBudget: { maxQueries: 8, maxRows: 100, maxBytes: 65536 } })
|
|
2033
|
+
```
|
|
2034
|
+
|
|
2035
|
+
Counts include application SQL, authorization reads, service queries and retries;
|
|
2036
|
+
transaction setup is timed separately. Query count is checked before SQL. Row
|
|
2037
|
+
and estimated JSON-byte budgets are checked after results arrive; use SQL limits
|
|
2038
|
+
and projections to avoid producing excessive data. A caught budget error still
|
|
2039
|
+
prevents COMMIT of the affected transaction. An earlier independent `$atomic`
|
|
2040
|
+
commit remains durable.
|
|
2041
|
+
|
|
2042
|
+
Summaries correlate the route/request ID with query names and SQL fingerprints.
|
|
2043
|
+
`captureSource: true` adds a bounded runtime stack; `includeSql: true` adds bounded
|
|
2044
|
+
SQL text. Bind values are never recorded. Raw SQL text can itself contain inline
|
|
2045
|
+
literals. `Database.$diagnostics()` returns the current snapshot, or null when
|
|
2046
|
+
disabled; the completion callback includes settlement timings. Only the first
|
|
2047
|
+
200 completed statements are retained, while totals cover every statement.
|
|
2048
|
+
|
|
2049
|
+
| Metric | Meaning |
|
|
2050
|
+
| --- | --- |
|
|
2051
|
+
| `queueMs` | Workload admission wait, including refused waits |
|
|
2052
|
+
| `poolMs` | Driver acquisition through transaction callback entry, including BEGIN |
|
|
2053
|
+
| `setupMs` | Isolation, cancellation ticket and role/claims setup |
|
|
2054
|
+
| `sqlMs` | Awaited driver time, including execution, lock and network waits |
|
|
2055
|
+
| `commitMs` / `rollbackMs` | Observed settlement waits |
|
|
2056
|
+
| `rows` / `bytes` | Returned root rows / estimated JSON result bytes, not wire bytes |
|
|
2057
|
+
| `commits` / `commitFailures` | Acknowledged commits / failed commit acknowledgements |
|
|
2058
|
+
| `rollbackRequests` / `retries` | Requested rollbacks / whole-transaction replays |
|
|
2059
|
+
|
|
2060
|
+
Durations can overlap across concurrent operations; summing them is not request
|
|
2061
|
+
wall time. The driver cannot separate lock wait from server execution. Telemetry
|
|
2062
|
+
callback failures do not change an acknowledged transaction outcome.
|
|
1755
2063
|
|
|
1756
2064
|
|
|
1757
2065
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@palbase/backend",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "34.0.0",
|
|
4
4
|
"description": "Palbase Backend SDK — class controllers (@Controller/@Get/@Post + @Body/@QueryParams/@Param), error classes, schema DSL",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -91,7 +91,6 @@
|
|
|
91
91
|
"files": [
|
|
92
92
|
"dist",
|
|
93
93
|
"docs",
|
|
94
|
-
"stack-images.json",
|
|
95
94
|
"stager",
|
|
96
95
|
"template"
|
|
97
96
|
],
|
package/template/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/decorators/registry.ts","../src/decorators/controller.ts"],"sourcesContent":["// The decorator registry — the single plain-data store the method + parameter\n// decorators write into, and the deploy/dispatch pipeline reads back. No\n// `reflect-metadata`, no `emitDecoratorMetadata`: the registry is built from the\n// decorator arguments + the parameter INDEX that esbuild/tsc preserve for legacy\n// parameter decorators (verified — see the design spec §0/§4.1).\n//\n// A controller class carries its route metadata on a symbol-keyed static\n// property (`ROUTES`). `@Get`/`@Post`/… append a {@link RouteMeta} entry;\n// `@Body`/`@User`/… append a {@link ParamMeta} entry onto the route for the\n// method they decorate. Because parameter decorators run BEFORE the method\n// decorator for the same member (TS evaluates innermost-first, params before the\n// method), the route entry may not exist yet when a param decorator fires — so\n// param metadata is buffered per method name and merged when the method\n// decorator creates the route entry.\nimport type { AuthSpec, RateLimitConfig } from \"../endpoint.js\";\nimport type { UploadConfig } from \"./upload.js\";\nimport type { SseConfig } from \"./sse.js\";\nimport type { ZodTypeAny } from \"zod\";\n\n/** The HTTP verbs a route may declare, upper-cased (the runtime router +\n * OpenAPI lower-case on their own). */\nexport type HttpMethodUpper = \"GET\" | \"POST\" | \"PUT\" | \"PATCH\" | \"DELETE\" | \"QUERY\";\n\n/** Route-level options accepted by the method decorators (`@Get`/`@Post`/…). */\nexport interface RouteOptions {\n /** OVERRIDES the controller-level default auth for this one route. */\n auth?: AuthSpec;\n /** Per-route rate limit. */\n rateLimit?: RateLimitConfig;\n /** Direct-storage upload config — present ONLY on `@Upload` routes (the\n * `@Get`/`@Post`/… decorators never set it). Its presence is what MARKS a\n * route as an upload route through the whole pipeline (registry → flatten →\n * openapi → codegen). The bytes go client→storage directly; the method body\n * runs as the completion handler. See {@link UploadConfig} (decorators/upload.ts). */\n uploadConfig?: UploadConfig;\n /** Streaming config — present ONLY on `@Sse` routes (the `@Get`/`@Post`/…\n * decorators never set it). Its presence is what MARKS a route as a streaming\n * route through the whole pipeline (registry → flatten → openapi → codegen),\n * exactly as `uploadConfig` does for uploads — never a special HTTP verb. An\n * `@Sse` route registers POST like any input-bearing route, so the verb cannot\n * carry the distinction. See {@link SseConfig} (decorators/sse.ts). */\n sseConfig?: SseConfig;\n}\n\n/** The kind of value a parameter decorator injects. Drives both dispatch\n * (which request slice to inject) and codegen (which OpenAPI parameter source a\n * schema-bearing kind maps to). */\nexport type ParamKind =\n | \"body\"\n | \"query\"\n | \"param\"\n | \"headers\"\n | \"user\"\n | \"optionalUser\"\n | \"client\"\n | \"requestId\"\n | \"traceId\"\n | \"req\"\n // `@UploadedObject()` — injects the uploaded object (completion input) on an\n // `@Upload` route. No schema (the shape is the fixed UploadedObject type).\n | \"uploadedObject\"\n // `@SseOut()` — injects the frame writer on an `@Sse` route. No schema (the\n // shape is the fixed SseWriter type).\n | \"sseOut\"\n // `@Signal()` — injects the request's AbortSignal, which aborts when the\n // client disconnects. No schema. NOT derivable from `@Req()`: PBRequest\n // carries only request-scoped data and has no signal (endpoint.ts:358-363).\n | \"signal\";\n\n/** One parameter decorator's recorded metadata. `index` is the parameter\n * position esbuild/tsc preserve; `schema` is present for the schema-bearing\n * kinds (`body`/`query`/`headers`); `name` is the path-param name for `param`. */\nexport interface ParamMeta {\n index: number;\n kind: ParamKind;\n /** Zod schema for `body`/`query`/`headers` (validation + codegen source). */\n schema?: ZodTypeAny;\n /** Path-param name for `@Param(\"id\")`. */\n name?: string;\n}\n\n/** One inferred throw site: the error CLASS name (e.g. \"TodoLocked\") and its\n * wire code (e.g. \"todo_locked\"). `status`, `hasData`, and the data JSON schema\n * are NOT carried here — they resolve from the error registry by `code` at\n * extract/openapi time (single source of truth). */\nexport interface ThrowDescriptor {\n name: string;\n code: string;\n}\n\n/** One route's recorded metadata: the verb + subpath + method name + options,\n * the ordered parameter metas, and the resolved return schema (injected by the\n * codegen step — see `returnSchema`). */\nexport interface RouteMeta {\n method: HttpMethodUpper;\n subpath: string;\n fnName: string;\n options: RouteOptions;\n params: ParamMeta[];\n /** Response schema for the route, if any. Derived from the method's RETURN\n * TYPE by codegen and written here via `recordReturn` (a generated top-level\n * IIFE injected per controller), not by an author-written decorator. */\n returnSchema?: ZodTypeAny;\n /** Error classes this route can throw, if inferred. Derived from the method\n * body + service call graph by the deploy stager's throw analysis and written\n * here via `recordThrows` (a generated top-level IIFE injected per controller,\n * the `recordReturn` twin), not by an author-written decorator. */\n throws?: ThrowDescriptor[];\n}\n\n/** Symbol the route metadata list is stored under on a controller class. Using\n * a symbol (not a string key) keeps it off the public structural surface and\n * avoids any chance of an authored property collision. */\nexport const ROUTES: unique symbol = Symbol.for(\"palbase.backend.routes\");\n\n/** Symbol the per-method buffered parameter metas are stored under while a class\n * is being decorated. Parameter decorators fire before the method decorator, so\n * they buffer here keyed by method name; the method decorator drains the buffer\n * into the route entry it creates. */\nconst PARAM_BUFFER: unique symbol = Symbol.for(\"palbase.backend.paramBuffer\");\n\n/** A room's own slots. Rooms are NOT routes — no verb, no path, no params — so\n * they get their own carrier slots instead of being squeezed into RouteMeta. */\nconst ROOM: unique symbol = Symbol.for(\"palbase.backend.room\");\nconst ROOM_HOOKS: unique symbol = Symbol.for(\"palbase.backend.roomHooks\");\n\n/** Symbol the per-method buffered return-type schemas are stored under while a\n * class's registry is being populated. The codegen-injected `recordReturn` call\n * can fire before OR after the method decorator; it buffers here keyed by method\n * name and `recordRoute` drains it into the route entry (and `recordReturn`\n * writes through if the route already exists). Buffering on BOTH sides means a\n * fully-formed route entry always carries its return schema — a raw-symbol\n * reader (the runtime) never has to re-merge. */\nconst RETURN_BUFFER: unique symbol = Symbol.for(\"palbase.backend.returnBuffer\");\n\n/** Symbol the per-method buffered throw descriptors are stored under while a\n * class's registry is being populated. The stager-injected `recordThrows` call\n * can fire before OR after the method decorator; it buffers here keyed by method\n * name and `recordRoute` drains it into the route entry (and `recordThrows`\n * writes through if the route already exists). Buffering on BOTH sides means a\n * fully-formed route entry always carries its throw descriptors — a raw-symbol\n * reader (the runtime) never has to re-merge. */\nconst THROWS_BUFFER: unique symbol = Symbol.for(\"palbase.backend.throwsBuffer\");\n\n/** A class constructor carrying the symbol-keyed registry slots. We type the\n * registry-bearing class as this so the decorators can read/write the slots\n * without `any` — a plain `Function` does not carry index signatures. */\ninterface RegistryCarrier {\n [ROUTES]?: RouteMeta[];\n [PARAM_BUFFER]?: Record<string, ParamMeta[]>;\n [ROOM]?: RoomMeta;\n [ROOM_HOOKS]?: RoomBuffer;\n [RETURN_BUFFER]?: Record<string, ZodTypeAny>;\n [THROWS_BUFFER]?: Record<string, ThrowDescriptor[]>;\n}\n\n/** Coerce a decorated target (class constructor or its prototype) into the\n * registry carrier that owns the slots. Method/param decorators receive the\n * PROTOTYPE as their target; the class decorator receives the constructor. We\n * always anchor the registry on the CONSTRUCTOR so `getRoutes(ctor)` finds it. */\nfunction carrierOf(target: object): RegistryCarrier {\n // For instance-member decorators, `target` is the prototype; its `.constructor`\n // is the class. For a static member or the class decorator, `target` is the\n // constructor already. Resolve to the constructor either way.\n const ctor =\n typeof target === \"function\"\n ? (target as unknown as RegistryCarrier)\n : (((target as { constructor?: unknown }).constructor ??\n target) as unknown as RegistryCarrier);\n return ctor;\n}\n\n/** Get (creating if absent) the own route list for a class constructor. Own —\n * not inherited — so a subclass does not mutate its base's routes. */\nfunction ownRoutes(carrier: RegistryCarrier): RouteMeta[] {\n if (!Object.prototype.hasOwnProperty.call(carrier, ROUTES)) {\n carrier[ROUTES] = [];\n }\n return carrier[ROUTES] as RouteMeta[];\n}\n\n/** Get (creating if absent) the own per-method param buffer for a class. */\nfunction ownParamBuffer(carrier: RegistryCarrier): Record<string, ParamMeta[]> {\n if (!Object.prototype.hasOwnProperty.call(carrier, PARAM_BUFFER)) {\n carrier[PARAM_BUFFER] = {};\n }\n return carrier[PARAM_BUFFER] as Record<string, ParamMeta[]>;\n}\n\n/** Record a route (called by the method decorators). Drains any parameter\n * metas already buffered for `fnName` into the new route entry, then sorts them\n * by parameter index so dispatch can inject positionally. */\nexport function recordRoute(\n target: object,\n fnName: string,\n method: HttpMethodUpper,\n subpath: string,\n options: RouteOptions,\n): void {\n const carrier = carrierOf(target);\n const routes = ownRoutes(carrier);\n const buffer = ownParamBuffer(carrier);\n const params = (buffer[fnName] ?? []).slice().sort((a, b) => a.index - b.index);\n const route: RouteMeta = { method, subpath, fnName, options, params };\n // Drain a buffered return schema (the recordReturn-ran-first ordering) so the\n // route entry is complete the moment it's created — a raw-symbol consumer\n // (the runtime extractor/worker) sees the return schema without re-merging.\n const returnBuffer = carrier[RETURN_BUFFER];\n if (returnBuffer && returnBuffer[fnName] !== undefined) {\n route.returnSchema = returnBuffer[fnName];\n }\n // Same drain for buffered throw descriptors (the recordThrows-ran-first\n // ordering) — the route entry is complete the moment it's created.\n const throwsBuffer = carrier[THROWS_BUFFER];\n if (throwsBuffer && throwsBuffer[fnName] !== undefined) {\n route.throws = throwsBuffer[fnName];\n }\n routes.push(route);\n}\n\n/** Record one parameter decorator (called by `@Body`/`@User`/…). Buffers per\n * method name; the method decorator merges the buffer into the route entry. If\n * the route already exists (method decorator ran first — TS does evaluate the\n * method decorator AFTER its parameter decorators, but we stay order-robust),\n * the meta is also appended directly so neither ordering loses it. */\nexport function recordParam(target: object, fnName: string, meta: ParamMeta): void {\n const carrier = carrierOf(target);\n const buffer = ownParamBuffer(carrier);\n (buffer[fnName] ??= []).push(meta);\n\n // Order-robust: if the route already exists, merge in place + keep sorted.\n const routes = carrier[ROUTES];\n if (routes) {\n const route = routes.find((r) => r.fnName === fnName);\n if (route) {\n route.params.push(meta);\n route.params.sort((a, b) => a.index - b.index);\n }\n }\n}\n\n/** Attach a return schema to the route for `fnName` (called by the codegen\n * injection that reads the method's return type). If the route does not exist\n * yet, the schema is buffered (RETURN_BUFFER) and drained into the route by\n * `recordRoute` when the method decorator runs. */\nexport function recordReturn(target: object, fnName: string, schema: ZodTypeAny): void {\n const carrier = carrierOf(target);\n const routes = carrier[ROUTES];\n const route = routes?.find((r) => r.fnName === fnName);\n if (route) {\n route.returnSchema = schema;\n return;\n }\n if (!Object.prototype.hasOwnProperty.call(carrier, RETURN_BUFFER)) {\n carrier[RETURN_BUFFER] = {};\n }\n const returnBuffer = carrier[RETURN_BUFFER];\n if (returnBuffer) returnBuffer[fnName] = schema;\n}\n\n/** Attach the inferred throw descriptors to the route for `fnName` (called by\n * the stager-injected IIFE that carries the throw analysis result — the\n * `recordReturn` twin). If the route does not exist yet, the descriptors are\n * buffered (THROWS_BUFFER) and drained into the route by `recordRoute` when the\n * method decorator runs. */\nexport function recordThrows(target: object, fnName: string, throws: ThrowDescriptor[]): void {\n const carrier = carrierOf(target);\n const routes = carrier[ROUTES];\n const route = routes?.find((r) => r.fnName === fnName);\n if (route) {\n route.throws = throws;\n return;\n }\n if (!Object.prototype.hasOwnProperty.call(carrier, THROWS_BUFFER)) {\n carrier[THROWS_BUFFER] = {};\n }\n const throwsBuffer = carrier[THROWS_BUFFER];\n if (throwsBuffer) throwsBuffer[fnName] = throws;\n}\n\n/** Read the route metadata for a controller class (the deploy/dispatch entry\n * point). Applies any buffered return schemas + throw descriptors (for the\n * recordReturn/recordThrows-runs-before orderings) and returns a defensive copy\n * so callers cannot mutate the registry.\n */\nexport function getRoutes(ctor: object): RouteMeta[] {\n const carrier = carrierOf(ctor);\n const routes = carrier[ROUTES] ?? [];\n const returnBuffer = carrier[RETURN_BUFFER];\n if (returnBuffer) {\n for (const route of routes) {\n const buffered = returnBuffer[route.fnName];\n if (buffered && route.returnSchema === undefined) {\n route.returnSchema = buffered;\n }\n }\n }\n const throwsBuffer = carrier[THROWS_BUFFER];\n if (throwsBuffer) {\n for (const route of routes) {\n const buffered = throwsBuffer[route.fnName];\n if (buffered && route.throws === undefined) {\n route.throws = buffered;\n }\n }\n }\n return routes.map((r) => ({\n ...r,\n params: r.params.slice(),\n ...(r.throws !== undefined ? { throws: r.throws.slice() } : {}),\n }));\n}\n\n// ── rooms ───────────────────────────────────────────────────────────────────\n\n/** Which lifecycle hook a method is bound to. */\nexport type RoomHook = \"authorize\" | \"first\" | \"join\" | \"leave\" | \"empty\";\n\nexport interface RoomMessageMeta {\n fnName: string;\n schema: ZodTypeAny;\n}\n\nexport interface RoomMeta {\n pattern: string;\n events: Record<string, ZodTypeAny>;\n graceMs: number;\n /** hook → the method name that implements it. */\n hooks: Partial<Record<RoomHook, string>>;\n /** inbound message name → its method and payload schema. */\n messages: Record<string, RoomMessageMeta>;\n}\n\ninterface RoomBuffer {\n hooks: Partial<Record<RoomHook, string>>;\n messages: Record<string, RoomMessageMeta>;\n}\n\n/** Get (creating if absent) the own hook buffer. Own — not inherited — so a\n * subclass never mutates its base's hooks. Member decorators fill this BEFORE\n * the class decorator runs; controller.ts:203 depends on the same ordering. */\nfunction ownRoomBuffer(carrier: RegistryCarrier): RoomBuffer {\n if (!Object.prototype.hasOwnProperty.call(carrier, ROOM_HOOKS)) {\n carrier[ROOM_HOOKS] = { hooks: {}, messages: {} };\n }\n return carrier[ROOM_HOOKS] as RoomBuffer;\n}\n\n/** Record a lifecycle hook. A second method for the same hook is refused: two\n * answers to \"who handles this\" cannot be resolved at dispatch, and silently\n * keeping one is how a hook stops running without anyone being told. */\nexport function recordRoomHook(target: object, hook: RoomHook, fnName: string): void {\n const buffer = ownRoomBuffer(carrierOf(target));\n const existing = buffer.hooks[hook];\n if (existing !== undefined && existing !== fnName) {\n const label = `On${hook.charAt(0).toUpperCase()}${hook.slice(1)}`;\n throw new Error(\n `@${label} is declared twice in one room (${existing} and ${fnName}). ` +\n `A room has one of each hook.`,\n );\n }\n buffer.hooks[hook] = fnName;\n}\n\n/** Record an inbound message handler. */\nexport function recordRoomMessage(\n target: object,\n name: string,\n fnName: string,\n schema: ZodTypeAny,\n): void {\n const buffer = ownRoomBuffer(carrierOf(target));\n const existing = buffer.messages[name];\n if (existing !== undefined && existing.fnName !== fnName) {\n throw new Error(\n `@OnMessage(\"${name}\") is declared twice in one room (${existing.fnName} and ${fnName}).`,\n );\n }\n buffer.messages[name] = { fnName, schema };\n}\n\n/** Record the room itself (called by the class decorator), draining the buffer\n * the member decorators already filled. */\nexport function recordRoom(\n ctor: object,\n meta: Omit<RoomMeta, \"hooks\" | \"messages\">,\n): void {\n const carrier = carrierOf(ctor);\n const buffer = ownRoomBuffer(carrier);\n carrier[ROOM] = { ...meta, hooks: buffer.hooks, messages: buffer.messages };\n // AND into the shared class registry, the same slot @Controller pushes to.\n //\n // Without this line a room compiles, bundles and deploys, and is never called:\n // the bundler's entry exports `SDK.getRegisteredControllers()` and the runtime\n // reads its rooms out of THAT list (server.ts's `collectRooms`). A room that\n // only marks its own constructor is a room nobody can find — measured, on the\n // fixture, at the last gate before it would have worked.\n //\n // Rooms and controllers share one list because they are one thing to the\n // loader: classes a bundle declared. What each IS is decided by the marker it\n // carries, never by which list it arrived in.\n const g = globalThis as unknown as Record<symbol, unknown[] | undefined>;\n const REGISTRY = Symbol.for(\"palbase.backend.allControllers\");\n const all = (g[REGISTRY] ??= []);\n if (!all.includes(ctor)) all.push(ctor);\n}\n\n/** The room a class declares, or undefined. A class with no `@Room` is not a\n * room — the marker is the CONFIG's presence, never a name or a base class\n * (the rule upload.ts:13-16 states for uploads). */\nexport function getRoom(ctor: object): RoomMeta | undefined {\n const carrier = carrierOf(ctor);\n if (!Object.prototype.hasOwnProperty.call(carrier, ROOM)) return undefined;\n return carrier[ROOM] as RoomMeta;\n}\n","// `@Controller(basePath, options?)` — the class decorator that marks a class as\n// a Palbase backend controller. It stamps a non-enumerable `__palbase`\n// discriminant + the resolved controller metadata onto the class so the\n// deploy/dispatch pipeline (and `isController`/`resolveController`) can detect\n// and read it without `reflect-metadata`.\nimport type { AuthSpec } from \"../endpoint.js\";\nimport { getRoutes } from \"./registry.js\";\n\n/** The controller metadata stamped onto a `@Controller`-decorated class. The\n * default export of a `controllers/*.controller.ts` file resolves to this via\n * {@link resolveController}. */\nexport interface ControllerMeta {\n /** Discriminant the runtime + tooling read. */\n readonly __palbase: \"controller\";\n /** The base path every route in this controller mounts under (e.g. \"/todos\"). */\n basePath: string;\n /** Controller-level default auth, applied to routes that don't set their own\n * (`@Get(\"/x\", { auth })` overrides this). `undefined` ⇒ the application\n * default ({@link defineDefaultAuth}), and secure-by-default below that —\n * see {@link resolveEffectiveAuth} for the whole cascade. */\n defaultAuth?: AuthSpec;\n}\n\n/** Options accepted by `@Controller`. */\nexport interface ControllerOptions {\n /** Default auth for ALL routes in this controller (route-level overrides;\n * omitting it falls through to the application default declared with\n * {@link defineDefaultAuth}). */\n auth?: AuthSpec;\n}\n\n/** Symbol the controller metadata is stamped under. Symbol-keyed (not a string\n * property) so it never collides with an authored member and stays off the\n * structural surface. */\nexport const CONTROLLER_META: unique symbol = Symbol.for(\"palbase.backend.controllerMeta\");\n\n/**\n * Every class `@Controller` has decorated, in decoration order.\n *\n * This is what lets a controller file need no export at all: importing the file\n * runs the decorator, the decorator records the class here, and the runtime\n * reads the list. Without it the only handle on a class is its export name, so\n * every controller had to be exported AND named in a generated entry — the\n * ceremony NestJS still charges (`export class` PLUS\n * `@Module({controllers:[…]})`).\n *\n * Keyed on a well-known Symbol against globalThis rather than held in a module\n * variable, because a deployed bundle inlines its own copy of this package: two\n * copies would keep two lists, and the runtime would read the empty one. The\n * same hazard `runtimeHooks` exists for, closed the same way — one shared slot.\n */\nconst REGISTRY: unique symbol = Symbol.for(\"palbase.backend.allControllers\") as never;\n\nfunction registry(): unknown[] {\n const g = globalThis as unknown as Record<symbol, unknown[] | undefined>;\n const existing = g[REGISTRY];\n if (existing) return existing;\n const fresh: unknown[] = [];\n g[REGISTRY] = fresh;\n return fresh;\n}\n\n/**\n * The controller classes this process has loaded, in decoration order.\n *\n * Decoration order is import order, which the bundler fixes by sorting the\n * files it emits imports for — so two builds of one tree produce the same\n * route table, and route precedence is not a function of module-resolution\n * accidents.\n */\nexport function getRegisteredControllers(): readonly unknown[] {\n return registry().slice();\n}\n\n/** Empty the registry. For tests, which load controllers repeatedly. */\nexport function __resetRegisteredControllers(): void {\n registry().length = 0;\n}\n\n/**\n * The APPLICATION-level default auth.\n *\n * Held on globalThis under a well-known Symbol for exactly the reason\n * {@link REGISTRY} is: a deployed bundle inlines its own copy of this package,\n * and two copies keeping two defaults is how a security setting silently\n * becomes two different settings.\n */\nconst APP_DEFAULT_AUTH: unique symbol = Symbol.for(\"palbase.backend.appDefaultAuth\") as never;\n\nfunction appAuthSlot(): Record<symbol, AuthSpec | undefined> {\n return globalThis as unknown as Record<symbol, AuthSpec | undefined>;\n}\n\n/**\n * Declare the default auth for EVERY route in the application — the ring the\n * cascade consults when neither the route nor its controller says anything.\n *\n * The measured problem it removes: `auth: { verifiedEmail: true }` repeated by\n * hand on ten `@Controller`s. A security setting that must be repeated is a\n * security setting that will be forgotten — the eleventh controller opens the\n * door and nothing says so.\n *\n * Call it at MODULE SCOPE in a file the application imports (the controllers'\n * own barrel, or a module a controller imports). The cascade reads this slot\n * when the route table is built and when the spec is emitted — both of which\n * run after module loading — so declaration order does not matter, but being\n * imported at all does.\n *\n * @example\n * defineDefaultAuth({ verifiedEmail: true }); // every route, unless it says otherwise\n */\nexport function defineDefaultAuth(auth: AuthSpec): void {\n appAuthSlot()[APP_DEFAULT_AUTH] = auth;\n}\n\n/** The declared application default, or `undefined` when none was declared. */\nexport function getDefaultAuth(): AuthSpec | undefined {\n return appAuthSlot()[APP_DEFAULT_AUTH];\n}\n\n/** Clear the application default. For tests, which declare it repeatedly. */\nexport function __resetDefaultAuth(): void {\n delete appAuthSlot()[APP_DEFAULT_AUTH];\n}\n\n/**\n * THE auth cascade: route → controller → application → `true`.\n *\n * One function, every caller — the route table (`engine/router.ts`) and the\n * spec emitter (`openapi/controllers.ts`) ASK for the answer instead of\n * spelling the chain themselves. Two hand-written copies of a cascade is how\n * the build-time answer and the runtime answer come to disagree about who may\n * call an endpoint, and the disagreement shows up as an open door.\n *\n * The terminal `true` is secure-by-default and is load-bearing: a route that\n * declared nothing, under a controller that declared nothing, in an\n * application that declared nothing, is CLOSED.\n */\nexport function resolveEffectiveAuth(\n routeAuth: AuthSpec | undefined,\n controllerAuth: AuthSpec | undefined,\n): AuthSpec {\n return routeAuth ?? controllerAuth ?? getDefaultAuth() ?? true;\n}\n\n/** A class carrying the stamped controller metadata + discriminant. */\ninterface ControllerCarrier {\n __palbase?: \"controller\";\n [CONTROLLER_META]?: ControllerMeta;\n}\n\n/** The one path segment the platform owns. The isolate matches\n * `^/webhooks/([^/]+)$` on the raw request path BEFORE controller dispatch, so\n * anything a controller resolves to under it answers `404 webhook_not_found`\n * and never runs. */\nconst RESERVED_FIRST_SEGMENT = \"webhooks\";\n\n/**\n * Throw if `path` resolves under the reserved segment. Segments are compared the\n * way the isolate compares them — `split(\"/\").filter(Boolean)` — NOT by string\n * prefix, because empty segments collapse there: `@Controller(\"/\")` +\n * `@Post(\"/webhooks/x\")` composes to `//webhooks/x`, which the isolate serves as\n * `/webhooks/x`. A prefix check reads that as safe; the segment check does not.\n * `/webhooksy` stays allowed for the same reason — it is a different segment.\n *\n * Every verb is refused, not just the POST the isolate currently intercepts: the\n * reservation is of the URL namespace, so a `@Get(\"/webhooks/x\")` that happens\n * to work today would be silently shadowed the moment the isolate's method gate\n * widens. Refusing at build is recoverable; discovering it as a 404 is not.\n */\nfunction assertNotReserved(path: string, subject: string): void {\n const [first] = path.split(\"/\").filter(Boolean);\n if (first === RESERVED_FIRST_SEGMENT) {\n throw new Error(\n `${subject} resolves under the reserved /${RESERVED_FIRST_SEGMENT} path — ` +\n \"inbound webhooks are served there and would shadow this route\",\n );\n }\n}\n\n/**\n * Mark a class as a Palbase backend controller. `basePath` is the mount path\n * for every route the class declares; `options.auth` sets the controller-level\n * default auth (a route's own `auth` overrides it; absent ⇒ secure-by-default).\n *\n * @example\n * \\@Controller(\"/todos\", { auth: false })\n * export class TodosController {\n * \\@Get(\"\") list(\\@QueryParams(ListTodosQuery) q: ListTodosQuery): TodoSchema[] { … }\n * }\n */\nexport function Controller(basePath: string, options: ControllerOptions = {}) {\n return function <T extends abstract new (...args: never[]) => object>(ctor: T): T {\n // /webhooks/* belongs to the platform: the isolate matches the inbound\n // webhook route before controller dispatch, so a controller mounted here\n // would never receive a request. Silent shadowing is the failure mode this\n // whole change exists to remove, so refuse it at build.\n //\n // The COMPOSED path is what gets shadowed, not the base path. `@Controller(\"\")`\n // and `@Controller(\"/\")` both pass a base-path-only check while a\n // `@Post(\"/webhooks/stripe\")` inside them resolves to exactly the path the\n // isolate intercepts. Method decorators run BEFORE the class decorator (TS\n // evaluates members first), so every route this class declares is already in\n // the registry here — which is why the composed check can live at this one\n // seam instead of on the dispatch read path. The `@Controller(\"\") +\n // @Post(\"/webhooks/stripe\")` test is the lock on that ordering: if it ever\n // stopped holding, that test goes red.\n assertNotReserved(basePath, `@Controller(\"${basePath}\")`);\n for (const route of getRoutes(ctor)) {\n assertNotReserved(\n `${basePath}${route.subpath}`,\n `@${route.method}(\"${route.subpath}\") in @Controller(\"${basePath}\")`,\n );\n }\n\n const carrier = ctor as unknown as ControllerCarrier;\n const meta: ControllerMeta = {\n __palbase: \"controller\",\n basePath,\n ...(options.auth !== undefined ? { defaultAuth: options.auth } : {}),\n };\n // Non-enumerable so it doesn't leak onto instances / structural checks.\n Object.defineProperty(carrier, CONTROLLER_META, {\n value: meta,\n enumerable: false,\n configurable: true,\n writable: false,\n });\n // The bare `__palbase` discriminant is the cheap detection marker the\n // runtime/extractor checks; keep it readable but non-enumerable.\n Object.defineProperty(carrier, \"__palbase\", {\n value: \"controller\",\n enumerable: false,\n configurable: true,\n writable: false,\n });\n // Record it, so importing the file is enough and exporting is optional.\n // Guarded against a double-decoration re-entering the same class twice.\n const all = registry();\n if (!all.includes(ctor)) all.push(ctor);\n return ctor;\n };\n}\n\n/** True when `value` is a `@Controller`-decorated class (cheap discriminant\n * check). Accepts the class constructor (the default export of a controller\n * file). */\nexport function isController(value: unknown): boolean {\n if (typeof value !== \"function\" && (typeof value !== \"object\" || value === null)) {\n return false;\n }\n const carrier = value as ControllerCarrier;\n return carrier.__palbase === \"controller\" && carrier[CONTROLLER_META] !== undefined;\n}\n\n/** Read the resolved controller metadata off a `@Controller`-decorated class.\n * Throws if the class was not decorated — callers should gate with\n * {@link isController} first (the loader does). */\nexport function resolveController(ctor: unknown): ControllerMeta {\n if (typeof ctor !== \"function\" && (typeof ctor !== \"object\" || ctor === null)) {\n throw new TypeError(\"resolveController: value is not a class\");\n }\n const meta = (ctor as ControllerCarrier)[CONTROLLER_META];\n if (!meta) {\n throw new TypeError(\n \"resolveController: class is not a @Controller — decorate it with `@Controller(path)` and list it in a module's `controllers`\",\n );\n }\n return meta;\n}\n\n/**\n * A class the runtime constructs takes NO constructor parameters.\n *\n * ONE writer, four callers (controller, hook, job, webhook) and the build's own\n * check. Four hand-written copies of this message is how the four come to\n * disagree about what is refused — and the disagreement is silent, because a\n * class that slips past one of them still ends up with `undefined` fields.\n *\n * Why it is refused rather than injected: there is no container. The parameter\n * would arrive `undefined`, the code would compile, deploy, and fail at the\n * first request that touches the field — the most expensive place to learn it.\n */\nexport function assertZeroArgConstructor(Ctrl: unknown, kind: string): void {\n const arity = (Ctrl as { length?: number }).length ?? 0;\n if (arity === 0) return;\n\n // This function's NAME is a promise: whatever reaches it will be constructed\n // with a zero-argument constructor. Letting a class with parameters through\n // would make the name a lie — worse than the rename FR-029 guards against.\n //\n // An earlier design made it \"declaration-aware\": pass when metadata matches\n // arity. Measured, that re-opens the exact silence this exists to close.\n // ANY decorator triggers metadata emission, not just `@Injectable`:\n //\n // @Job(...) class J { constructor(repo: unknown) {} }\n // → design:paramtypes = [Object] ← matches arity\n //\n // so J would pass, then be built with `new J()`, and `repo` would be\n // `undefined` at the first scheduled run. Four tests in this repo asserted\n // that refusal and all four went red; the tests were right.\n //\n // What changed instead is the MESSAGE, and who calls this. Callers holding a\n // container resolve from it and never come here (router.ts, job/hook/webhook);\n // this stays the guard for the container-less path, and keeps its promise.\n const name = (Ctrl as { name?: string }).name ?? \"<anonymous>\";\n throw new Error(\n `${kind} ${name} declares a constructor with ${arity} parameter(s), and this path ` +\n `builds it with a zero-argument constructor — every parameter would arrive as ` +\n `undefined. If you meant to inject them, add @Injectable() to ${name} and list it ` +\n `in a module's providers, so the container builds it instead.`,\n );\n}\n"],"mappings":";;;;;AAiHO,IAAMA,SAAwBC,uBAAOC,IAAI,wBAAA;AAMhD,IAAMC,eAA8BF,uBAAOC,IAAI,6BAAA;AAI/C,IAAME,OAAsBH,uBAAOC,IAAI,sBAAA;AACvC,IAAMG,aAA4BJ,uBAAOC,IAAI,2BAAA;AAS7C,IAAMI,gBAA+BL,uBAAOC,IAAI,8BAAA;AAShD,IAAMK,gBAA+BN,uBAAOC,IAAI,8BAAA;AAkBhD,SAASM,UAAUC,QAAc;AAI/B,QAAMC,OACJ,OAAOD,WAAW,aACbA,SACEA,OAAqC,eACtCA;AACR,SAAOC;AACT;AAVSF;AAcT,SAASG,UAAUC,SAAwB;AACzC,MAAI,CAACC,OAAOC,UAAUC,eAAeC,KAAKJ,SAASZ,MAAAA,GAAS;AAC1DY,YAAQZ,MAAAA,IAAU,CAAA;EACpB;AACA,SAAOY,QAAQZ,MAAAA;AACjB;AALSW;AAQT,SAASM,eAAeL,SAAwB;AAC9C,MAAI,CAACC,OAAOC,UAAUC,eAAeC,KAAKJ,SAAST,YAAAA,GAAe;AAChES,YAAQT,YAAAA,IAAgB,CAAC;EAC3B;AACA,SAAOS,QAAQT,YAAAA;AACjB;AALSc;AAUF,SAASC,YACdT,QACAU,QACAC,QACAC,SACAC,SAAqB;AAErB,QAAMV,UAAUJ,UAAUC,MAAAA;AAC1B,QAAMc,SAASZ,UAAUC,OAAAA;AACzB,QAAMY,SAASP,eAAeL,OAAAA;AAC9B,QAAMa,UAAUD,OAAOL,MAAAA,KAAW,CAAA,GAAIO,MAAK,EAAGC,KAAK,CAACC,GAA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ROUTES","Symbol","for","PARAM_BUFFER","ROOM","ROOM_HOOKS","RETURN_BUFFER","THROWS_BUFFER","carrierOf","target","ctor","ownRoutes","carrier","Object","prototype","hasOwnProperty","call","ownParamBuffer","recordRoute","fnName","method","subpath","options","routes","buffer","params","slice","sort","a","b","index","route","returnBuffer","undefined","returnSchema","throwsBuffer","throws","push","recordParam","meta","find","r","recordThrows","target","fnName","throws","carrier","carrierOf","routes","ROUTES","route","find","r","Object","prototype","hasOwnProperty","call","THROWS_BUFFER","throwsBuffer","getRoutes","ctor","returnBuffer","RETURN_BUFFER","buffered","returnSchema","undefined","map","params","slice","ownRoomBuffer","ROOM_HOOKS","hooks","messages","recordRoomHook","hook","buffer","existing","label","charAt","toUpperCase","Error","recordRoomMessage","name","schema","recordRoom","meta","ROOM","g","globalThis","REGISTRY","Symbol","for","all","includes","push","getRoom","CONTROLLER_META","Symbol","for","REGISTRY","registry","g","globalThis","existing","fresh","getRegisteredControllers","slice","__resetRegisteredControllers","length","APP_DEFAULT_AUTH","appAuthSlot","defineDefaultAuth","auth","getDefaultAuth","__resetDefaultAuth","resolveEffectiveAuth","routeAuth","controllerAuth","RESERVED_FIRST_SEGMENT","assertNotReserved","path","subject","first","split","filter","Boolean","Error","Controller","basePath","options","ctor","route","getRoutes","subpath","method","carrier","meta","__palbase","undefined","defaultAuth","Object","defineProperty","value","enumerable","configurable","writable","all","includes","push","isController","resolveController","TypeError","assertZeroArgConstructor","Ctrl","kind","arity","name"]}
|