@palbase/backend 10.3.0 → 12.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/chunk-7LAXRLPG.js +418 -0
- package/dist/chunk-7LAXRLPG.js.map +1 -0
- package/dist/{chunk-4WOQWFUP.js → chunk-LUV36KQU.js} +26 -11
- package/dist/{chunk-4WOQWFUP.js.map → chunk-LUV36KQU.js.map} +1 -1
- package/dist/{chunk-2PCNZBNZ.js → chunk-XATG7BRC.js} +20 -2
- package/dist/chunk-XATG7BRC.js.map +1 -0
- package/dist/db/index.cjs +438 -10
- package/dist/db/index.cjs.map +1 -1
- package/dist/db/index.d.cts +2 -2
- package/dist/db/index.d.ts +2 -2
- package/dist/db/index.js +13 -1
- package/dist/{endpoint-92kVepng.d.cts → endpoint-Ck4hER_7.d.cts} +343 -11
- package/dist/{endpoint-92kVepng.d.ts → endpoint-Ck4hER_7.d.ts} +343 -11
- package/dist/{index-BaHs33jr.d.cts → index-BJAf1uPC.d.cts} +64 -34
- package/dist/{index-DfryIw9U.d.ts → index-l7DhBDtn.d.ts} +64 -34
- package/dist/index.cjs +589 -124
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +60 -162
- package/dist/index.d.ts +60 -162
- package/dist/index.js +139 -108
- package/dist/index.js.map +1 -1
- package/dist/test/index.cjs +545 -12
- package/dist/test/index.cjs.map +1 -1
- package/dist/test/index.d.cts +1 -1
- package/dist/test/index.d.ts +1 -1
- package/dist/test/index.js +153 -12
- package/dist/test/index.js.map +1 -1
- package/docs/background.md +8 -9
- package/docs/database.md +106 -16
- package/docs/events.md +20 -17
- package/docs/llms-full.txt +141 -47
- package/docs/schema.md +6 -4
- package/package.json +1 -1
- package/dist/chunk-2PCNZBNZ.js.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Tables, TableTypes } from './db/env.js';
|
|
2
|
-
import { D as DBClient } from './endpoint-
|
|
2
|
+
import { D as DBClient, ba as TxPlanHandle, bk as TxTable, M as Materialized } from './endpoint-Ck4hER_7.js';
|
|
3
3
|
|
|
4
4
|
/** On delete action for foreign key references. */
|
|
5
5
|
type OnDeleteAction = 'cascade' | 'set null' | 'restrict' | 'no action';
|
|
@@ -536,29 +536,27 @@ interface TypedDB<S extends SchemaDef> {
|
|
|
536
536
|
tables: {
|
|
537
537
|
[K in keyof S["tables"]]: TypedTable<S["tables"][K]>;
|
|
538
538
|
};
|
|
539
|
-
transaction
|
|
540
|
-
|
|
541
|
-
/** Transaction-scoped typed facade: same typed tables, no nested transaction. */
|
|
542
|
-
interface TypedTx<S extends SchemaDef> {
|
|
543
|
-
tables: {
|
|
544
|
-
[K in keyof S["tables"]]: TypedTable<S["tables"][K]>;
|
|
545
|
-
};
|
|
539
|
+
/** Run a transaction plan. See {@link EnvTypedDatabase.transaction}. */
|
|
540
|
+
transaction<T>(fn: (tx: TypedTx<S>) => T extends Promise<unknown> ? never : T): Promise<Materialized<T>>;
|
|
546
541
|
}
|
|
542
|
+
/** The plan-building handle a `TypedDB<S>` transaction callback receives: the
|
|
543
|
+
* schema's tables, expressed as plan operations rather than awaited calls. */
|
|
544
|
+
type TypedTx<S extends SchemaDef> = TxPlanHandle<{
|
|
545
|
+
[K in keyof S["tables"]]: TxTable<RowShape<S["tables"][K]>, InsertShape<S["tables"][K]>>;
|
|
546
|
+
}>;
|
|
547
547
|
/**
|
|
548
548
|
* Wraps a raw `DBClient` with the type-safe `TypedDB<S>` facade derived from
|
|
549
|
-
* the provided schema. No behavior change
|
|
550
|
-
* the table name as a plain string.
|
|
549
|
+
* the provided schema. No behavior change for the direct ops — all calls
|
|
550
|
+
* delegate to `raw` with the table name as a plain string.
|
|
551
551
|
*
|
|
552
|
-
* `
|
|
553
|
-
*
|
|
554
|
-
*
|
|
555
|
-
*
|
|
556
|
-
* the runtime yields so the callback sees the same typed `.tables` API.
|
|
552
|
+
* `transaction` does NOT delegate to a per-op client: the callback describes a
|
|
553
|
+
* plan against a fresh {@link TxPlanBuilder}, and the whole plan travels in one
|
|
554
|
+
* `raw.txPlan` call. The schema is used only for its table NAMES; the values
|
|
555
|
+
* are typed by `S` at compile time and are plain strings at run time.
|
|
557
556
|
*
|
|
558
|
-
* `
|
|
559
|
-
*
|
|
560
|
-
*
|
|
561
|
-
* cannot infer through `Object.keys` iteration) — see module-level doc comment.
|
|
557
|
+
* The `as` casts are single structural narrowings from a dynamically-built
|
|
558
|
+
* object to the precise mapped type (TS cannot infer the mapped-type result
|
|
559
|
+
* through `Object.keys` iteration) — see the module-level doc comment.
|
|
562
560
|
*/
|
|
563
561
|
declare function makeTypedDB<S extends SchemaDef>(schema: S, raw: DBClient): TypedDB<S>;
|
|
564
562
|
/** A typed table accessor derived from one env `Tables` entry's flat shapes. */
|
|
@@ -578,34 +576,66 @@ interface EnvTypedTable<T extends TableTypes> {
|
|
|
578
576
|
type EnvTables = {
|
|
579
577
|
[K in keyof Tables]: EnvTypedTable<Tables[K]>;
|
|
580
578
|
};
|
|
581
|
-
/**
|
|
582
|
-
*
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
}
|
|
579
|
+
/** The project's tables as PLAN operations, keyed by the env `Tables`
|
|
580
|
+
* interface. The transaction twin of {@link EnvTables}. */
|
|
581
|
+
type TxTables = {
|
|
582
|
+
[K in keyof Tables]: TxTable<Tables[K]["row"], Tables[K]["insert"]>;
|
|
583
|
+
};
|
|
584
|
+
/**
|
|
585
|
+
* The handle a `Database.transaction(…)` callback receives.
|
|
586
|
+
*
|
|
587
|
+
* Tables only — no `query`, no `findById`, no `asService`. A read whose value
|
|
588
|
+
* the plan does not write belongs outside the transaction, where it costs one
|
|
589
|
+
* round trip and is an ordinary value you can branch on.
|
|
590
|
+
*/
|
|
591
|
+
type TxPlan = TxPlanHandle<TxTables>;
|
|
586
592
|
/**
|
|
587
593
|
* The RLS-bypass sibling returned by `Database.asService()`. Same typed surface
|
|
588
594
|
* as {@link EnvTypedDatabase} — `tables`, the raw string ops, and a typed
|
|
589
595
|
* `transaction` — but it does NOT re-expose `asService` (no double-bypass).
|
|
590
596
|
* Every op it performs runs as the `service_role` (BYPASSRLS).
|
|
591
597
|
*/
|
|
592
|
-
interface EnvServiceDatabase extends Omit<DBClient, "
|
|
598
|
+
interface EnvServiceDatabase extends Omit<DBClient, "txPlan" | "asService"> {
|
|
593
599
|
tables: EnvTables;
|
|
594
|
-
transaction<T>(fn: (tx:
|
|
600
|
+
transaction<T>(fn: (tx: TxPlan) => T extends Promise<unknown> ? never : T): Promise<Materialized<T>>;
|
|
595
601
|
}
|
|
596
602
|
/**
|
|
597
603
|
* The typed-by-default Database surface: the raw string-keyed `DBClient` ops
|
|
598
604
|
* PLUS a `tables` map typed against the project's generated `palbase-env.d.ts`,
|
|
599
|
-
* a `transaction`
|
|
600
|
-
*
|
|
605
|
+
* a `transaction` that runs a whole plan in one request, and `asService()` for
|
|
606
|
+
* the explicit RLS-bypass sibling.
|
|
601
607
|
*
|
|
602
|
-
* `
|
|
603
|
-
*
|
|
604
|
-
*
|
|
608
|
+
* The low-level `txPlan` op is deliberately NOT re-exposed here: `transaction`
|
|
609
|
+
* is the surface, and a hand-built plan would bypass the ref/guard machinery
|
|
610
|
+
* that makes one safe to write.
|
|
605
611
|
*/
|
|
606
|
-
interface EnvTypedDatabase extends Omit<DBClient, "
|
|
612
|
+
interface EnvTypedDatabase extends Omit<DBClient, "txPlan" | "asService"> {
|
|
607
613
|
tables: EnvTables;
|
|
608
|
-
|
|
614
|
+
/**
|
|
615
|
+
* Run a transaction. The callback DESCRIBES the operations; the whole
|
|
616
|
+
* description travels in one request and the broker runs it inside a single
|
|
617
|
+
* transaction — committing when it finishes, rolling back on any failure.
|
|
618
|
+
*
|
|
619
|
+
* The callback is SYNCHRONOUS: nothing has run when it returns, so there is
|
|
620
|
+
* nothing to await. `async` on it and `await` inside it are compile errors.
|
|
621
|
+
* Values a later operation needs are {@link Ref}s, written straight into the
|
|
622
|
+
* next operation; values the CALLER needs are returned and substituted before
|
|
623
|
+
* this promise resolves.
|
|
624
|
+
*
|
|
625
|
+
* @example
|
|
626
|
+
* const { statementId } = await Database.transaction((tx) => {
|
|
627
|
+
* const st = tx.tables.statements
|
|
628
|
+
* .insert({ household_id: hid, file_sha256: sha, status: "reviewing" })
|
|
629
|
+
* .expectOne(new Internal("statement insert failed"));
|
|
630
|
+
*
|
|
631
|
+
* tx.tables.statement_lines.insertMany(
|
|
632
|
+
* lines.map((l) => ({ statement_id: st.id, category: resolveCategory(l) })),
|
|
633
|
+
* );
|
|
634
|
+
*
|
|
635
|
+
* return { statementId: st.id };
|
|
636
|
+
* });
|
|
637
|
+
*/
|
|
638
|
+
transaction<T>(fn: (tx: TxPlan) => T extends Promise<unknown> ? never : T): Promise<Materialized<T>>;
|
|
609
639
|
/**
|
|
610
640
|
* Return a sibling that bypasses RLS by running as the `service_role`. Use
|
|
611
641
|
* sparingly and explicitly — the default `Database.*` path is RLS-enforced.
|
|
@@ -617,4 +647,4 @@ interface EnvTypedDatabase extends Omit<DBClient, "transaction" | "asService"> {
|
|
|
617
647
|
asService(): EnvServiceDatabase;
|
|
618
648
|
}
|
|
619
649
|
|
|
620
|
-
export {
|
|
650
|
+
export { jsonb as A, makeTypedDB as B, ColumnBuilder as C, numeric as D, type EnvTypedDatabase as E, policy as F, raw as G, text as H, type InsertShape as I, timestamp as J, uuid as K, type OnDeleteAction as O, PALBASE_EXTENSIONS as P, type RawConstraintDef as R, type SchemaDef as S, type TableDef as T, type ColumnDef as a, type ColumnMap as b, type ColumnType as c, EXTENSION_DEPENDENCIES as d, type EnvServiceDatabase as e, type EnvTables as f, type EnvTypedTable as g, type PalbaseExtension as h, PolicyBuilder as i, type PolicyCommand as j, type PolicyDef as k, type PolicyMode as l, type RowShape as m, type SchemaInput as n, type TableInput as o, type TxPlan as p, type TxTables as q, type TypedDB as r, type TypedTable as s, type TypedTx as t, bigint as u, boolean as v, defineSchema as w, enumType as x, integer as y, isPalbaseExtension as z };
|