@voltro/database 0.25.0 → 0.27.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/index.d.ts CHANGED
@@ -11,6 +11,11 @@ import { Stream } from 'effect';
11
11
  import { VoidIfEmpty } from 'effect/Types';
12
12
  import { YieldableError } from 'effect/Cause';
13
13
 
14
+ /** The store shape this needs — a read, nothing more. */
15
+ export declare interface ActorLookupStore {
16
+ query: (descriptor: unknown) => Promise<ReadonlyArray<Record<string, unknown>>>;
17
+ }
18
+
14
19
  /** The framework's built-in `actors` core table. */
15
20
  export declare const actorsTable: Table<'actors', Record<string, ColumnDefinition<unknown>>, true, never>;
16
21
 
@@ -185,6 +190,14 @@ export declare const attributionFields: (explicit?: WriteAttribution | undefined
185
190
  * never match. `(table, op, pk)` is stable through any re-encoding. */
186
191
  export declare const attributionKey: (table: string, op: string, primaryKey: unknown) => string;
187
192
 
193
+ /** A snapshot of who acted, as of the call. */
194
+ export declare interface AuditActor {
195
+ readonly id: string;
196
+ readonly type: string;
197
+ readonly displayName: string | null;
198
+ readonly email: string | null;
199
+ }
200
+
188
201
  /**
189
202
  * Audit a list of tables in one call. Convenience for the CLI's boot
190
203
  * path; same shape as calling `auditTableIndexes` per table and
@@ -3477,6 +3490,55 @@ export declare const planVersionedUpdate: (input: {
3477
3490
  readonly patch: Record<string, unknown>;
3478
3491
  };
3479
3492
 
3493
+ /**
3494
+ * A typed id column pointing at a plugin-owned row, with an orphan rule.
3495
+ *
3496
+ * No foreign key is emitted — see the header. The rule is enforced by the
3497
+ * runtime on the target's delete.
3498
+ */
3499
+ export declare const pluginRef: (target: () => TableLike, options?: PluginRefOptions) => ColumnBuilder<string, ColumnType>;
3500
+
3501
+ export declare interface PluginRefOptions {
3502
+ /** What to do with this row when the target row is deleted. Default `'keep'`,
3503
+ * which is today's behaviour — declaring the rule is opt-in, and a default
3504
+ * that deleted rows would be a footgun in a patch release. */
3505
+ readonly orphanPolicy?: PluginRefOrphanPolicy;
3506
+ /**
3507
+ * Also fire on a SOFT delete of the target.
3508
+ *
3509
+ * Default `false`, and the asymmetry is real rather than an oversight: some
3510
+ * plugin tables carry `deletedAt` and some do not (`_voltro_ai_flows` does,
3511
+ * `_voltro_ai_flow_runs` does not). A soft delete is a state change the
3512
+ * target can undo, so cascading on it destroys rows that a restore cannot
3513
+ * bring back. Opt in when your rule is about visibility rather than
3514
+ * existence.
3515
+ */
3516
+ readonly onSoftDelete?: boolean;
3517
+ }
3518
+
3519
+ /** What happens to the referencing row when the target row goes away. */
3520
+ export declare type PluginRefOrphanPolicy =
3521
+ /** Delete the referencing row. For a row that only exists to point at it —
3522
+ * a favourite, a pin, a share. */
3523
+ 'delete'
3524
+ /** Null the column, keeping the row. Requires `.nullable()`; declaring it on
3525
+ * a non-nullable column is refused at declaration rather than failing at the
3526
+ * first delete, months later. */
3527
+ | 'null'
3528
+ /** Do nothing. The explicit "I know, and I handle it myself" — different from
3529
+ * omitting the option, which is the same behaviour arrived at by accident. */
3530
+ | 'keep';
3531
+
3532
+ /** Declared metadata for one plugin reference — read by the boot wiring. */
3533
+ export declare interface PluginRefSpec {
3534
+ readonly target: () => TableLike;
3535
+ readonly orphanPolicy: PluginRefOrphanPolicy;
3536
+ readonly onSoftDelete: boolean;
3537
+ }
3538
+
3539
+ /** The declared spec for a column builder, when it is a `pluginRef`. */
3540
+ export declare const pluginRefSpecOf: (column: unknown) => PluginRefSpec | undefined;
3541
+
3480
3542
  export declare type Predicate = PredicateLeaf | AndPredicate | OrPredicate | NotPredicate | SubqueryInPredicate | ExistsPredicate;
3481
3543
 
3482
3544
  export declare interface PredicateLeaf {
@@ -4567,6 +4629,16 @@ declare type Resolve<T> = {
4567
4629
  readonly [K in keyof T]: T[K];
4568
4630
  } & {};
4569
4631
 
4632
+ /**
4633
+ * Snapshot the `actors` row for `subjectId`.
4634
+ *
4635
+ * `email` is read opportunistically: the framework's own `actors` carries
4636
+ * `id` / `kind` / `displayName`, and apps commonly extend it. Reading whatever
4637
+ * identifies the actor is the point — insisting on a fixed shape would make the
4638
+ * field useless for the deployments that need it most.
4639
+ */
4640
+ export declare const resolveActorSnapshot: (store: ActorLookupStore, subjectId: string | null | undefined, subjectType: string) => Promise<AuditActor | undefined>;
4641
+
4570
4642
  /**
4571
4643
  * Pick the branch mechanism. Prioritises the Neon copy-on-write fast-path when
4572
4644
  * the owned DB is Neon AND the branch snapshots parent data (`seed: 'copy'`);
@@ -4748,6 +4820,20 @@ export declare interface SchemaTable extends TableLike {
4748
4820
  readonly tableName: string;
4749
4821
  readonly fields: Record<string, ColumnDefinition<unknown>>;
4750
4822
  readonly appliedIndexes: ReadonlyArray<TableIndex>;
4823
+ /**
4824
+ * The plugin references DECLARED on this table, surviving `table()`.
4825
+ *
4826
+ * `pluginRefSpecOf` reads a column BUILDER, and materialisation replaces it
4827
+ * with a plain field descriptor — so without this the declaration is
4828
+ * unreadable the moment the table exists, and any tool deriving structure
4829
+ * from the schema sees an ordinary `text()` column.
4830
+ */
4831
+ readonly appliedPluginRefs?: ReadonlyArray<{
4832
+ readonly column: string;
4833
+ readonly target: () => unknown;
4834
+ readonly orphanPolicy: PluginRefOrphanPolicy;
4835
+ readonly onSoftDelete: boolean;
4836
+ }>;
4751
4837
  /**
4752
4838
  * Declared full-text indexes. Carried so a `SchemaTable`-annotated table
4753
4839
  * is still a valid `queryFor(...)` input (the builder reads this to let
@@ -5175,6 +5261,20 @@ export declare interface Table<Name extends string, Fields extends Record<string
5175
5261
  readonly isReactive: Reactive;
5176
5262
  readonly appliedMixins: ReadonlyArray<AnyMixin>;
5177
5263
  readonly appliedIndexes: ReadonlyArray<TableIndex>;
5264
+ /**
5265
+ * The plugin references DECLARED on this table, surviving `table()`.
5266
+ *
5267
+ * `pluginRefSpecOf` reads a column BUILDER, and materialisation replaces it
5268
+ * with a plain field descriptor — so without this the declaration is
5269
+ * unreadable the moment the table exists, and any tool deriving structure
5270
+ * from the schema sees an ordinary `text()` column.
5271
+ */
5272
+ readonly appliedPluginRefs?: ReadonlyArray<{
5273
+ readonly column: string;
5274
+ readonly target: () => unknown;
5275
+ readonly orphanPolicy: PluginRefOrphanPolicy;
5276
+ readonly onSoftDelete: boolean;
5277
+ }>;
5178
5278
  readonly appliedUniques: ReadonlyArray<TableUnique>;
5179
5279
  readonly appliedFullText: ReadonlyArray<TableFullTextIndex>;
5180
5280
  readonly appliedChecks: ReadonlyArray<TableCheck>;