@cosmicdrift/kumiko-framework 0.397.0 → 0.399.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/AGENTS.md CHANGED
@@ -9,22 +9,31 @@ not exist in your version:
9
9
 
10
10
  | File | What it holds |
11
11
  | --- | --- |
12
- | `agents/features.md` | Every bundled feature: name, purpose, config keys, dependencies |
12
+ | `agents/features-index.md` | One entry per bundled feature: purpose, factory import, required features, config keys without a default, secrets |
13
+ | `agents/features.md` | Every bundled feature in detail: purpose, config keys, secrets, dependencies, APIs |
14
+ | `agents/api.md` | Index of the API reference: one file per entry point an app imports |
15
+ | `agents/api/<entry>.md` | Signatures of one entry point; options and screen types as property lists |
16
+ | `agents/api/types.md` | Types the entry points use but do not export, such as nested option shapes |
13
17
  | `agents/widgets.md` | Every value export of `@cosmicdrift/kumiko-renderer/web` with its short description |
14
18
  | `agents/examples.md` | Index of the worked examples, one per concept |
15
19
  | `agents/examples/<name>.md` | One tested sample app: README plus every source and test file |
16
20
 
17
21
  The paths are relative to this file. From an app root they live under
18
- `node_modules/@cosmicdrift/kumiko-framework/`. Type signatures are in
19
- `dist/*.d.ts` of each package; this file does not repeat them.
22
+ `node_modules/@cosmicdrift/kumiko-framework/`. For signatures and option
23
+ types read `agents/api.md` and the file it points to. Do not read
24
+ `dist/*.d.ts` in `node_modules`; the API files hold the same public
25
+ signatures at a fraction of the size.
20
26
 
21
27
  Order of work for a new feature:
22
28
 
23
- 1. Search `agents/features.md` for a bundled feature that already does it.
29
+ 1. Search `agents/features-index.md` for a bundled feature that already does
30
+ it. Open `agents/features.md` only for the feature you picked.
24
31
  2. Find the closest example in `agents/examples.md` and read it fully.
25
- 3. Build the feature with the declarative building blocks below.
26
- 4. Write an integration test against the real stack.
27
- 5. Run boot validation and the tests. Boot errors name the fix; apply it.
32
+ 3. Look up every function, screen, column, action and field option you use in
33
+ `agents/api.md` instead of `dist/*.d.ts`.
34
+ 4. Build the feature with the declarative building blocks below.
35
+ 5. Write an integration test against the real stack.
36
+ 6. Run boot validation and the tests. Boot errors name the fix; apply it.
28
37
 
29
38
  ## Mental model
30
39
 
@@ -287,7 +296,7 @@ produces code that compiles and then fails in production.
287
296
 
288
297
  ## I need X, use Y
289
298
 
290
- Before building anything here, search `agents/features.md`: auth, tenants,
299
+ Before building anything here, search `agents/features-index.md`: auth, tenants,
291
300
  mail, files, jobs, billing, audit, notifications and GDPR flows already exist
292
301
  as bundled features.
293
302
 
@@ -333,7 +342,8 @@ as bundled features.
333
342
  | Multi-step background flows | Workflow engine | `agents/examples/workflow-engine.md` |
334
343
  | A mount invariant for my feature | `r.bootCheck` | `agents/examples/boot-check.md` |
335
344
  | A widget for a custom screen | Search by concern | `agents/widgets.md` |
336
- | A bundled feature and its config | Search by name or purpose | `agents/features.md` |
345
+ | A bundled feature and its config | Search by name or purpose | `agents/features-index.md`, then `agents/features.md` |
346
+ | The options of a function, screen or field | Search by name | `agents/api.md` |
337
347
 
338
348
  ## Reading an example
339
349
 
@@ -350,15 +360,19 @@ isolate tests with one tenant each.
350
360
 
351
361
  ## Package entry points
352
362
 
353
- Import only from these subpaths of `@cosmicdrift/kumiko-framework`. Deep
354
- imports into `src/` or `dist/` break on the next release.
363
+ Import only from these entry points. Deep imports into `src/` or `dist/`
364
+ break on the next release. Each one has its signatures in the file named in
365
+ `agents/api.md`.
355
366
 
356
- | Subpath | Use it for |
367
+ | Entry point | Use it for |
357
368
  | --- | --- |
358
- | `/engine` | `defineFeature`, `createEntity`, field factories, handler helpers, executors, events |
359
- | `/errors` | Typed failures and error helpers |
360
- | `/stack` | Test stack, `TestUsers`, `createTestUser` |
361
- | `/testing` | Assertion helpers such as `expectErrorIncludes` |
362
- | `/ui-types` | Screen definition types (`EntityListScreenDefinition`, ...) |
363
- | `/db` | `buildEntityTable` and database helpers for tests and migrations |
364
- | `/event-store` | Event store helpers |
369
+ | `@cosmicdrift/kumiko-framework/engine` | `defineFeature`, `createEntity`, field factories, handler helpers, executors, events |
370
+ | `@cosmicdrift/kumiko-framework/errors` | Typed failures and error helpers |
371
+ | `@cosmicdrift/kumiko-framework/ui-types` | Screen definition types (`EntityListScreenDefinition`, ...) |
372
+ | `@cosmicdrift/kumiko-framework/db` | `buildEntityTable` and database helpers for tests and migrations |
373
+ | `@cosmicdrift/kumiko-framework/event-store` | Event store helpers |
374
+ | `@cosmicdrift/kumiko-framework/seeding` | `TestUsers`, `createTestUser`, seed helpers |
375
+ | `@cosmicdrift/kumiko-renderer/web` | Widgets, hooks and the web app shell |
376
+ | `@cosmicdrift/kumiko-dev-server/testing` | `setupAppTestStack`, `seedTenant` for app integration tests |
377
+ | `@cosmicdrift/kumiko-testing/stack` | `setupTestStack`, the stack the samples use |
378
+ | `@cosmicdrift/kumiko-testing/helpers` | Assertion helpers such as `expectErrorIncludes` |
@@ -0,0 +1,23 @@
1
+ <!-- Generated by `bun run gen:agent-docs` from packages/dev-server/src/testing.ts. Do not edit. -->
2
+
3
+ # @cosmicdrift/kumiko-dev-server/testing
4
+
5
+ Import from `@cosmicdrift/kumiko-dev-server/testing`. Types used here but not exported by any entry point are in `api/types.md`.
6
+
7
+ ## Functions
8
+
9
+ ```ts
10
+ function createE2eSeedRoutes(options?: E2eSeedRoutesOptions): ExtraRouteDefinition[];
11
+ function persistTenantRows(write: SeedWriter, options?: { name?: string; users?: number; admin?: SeedTenantOptions["admin"]; }): Promise<PersistedTenant>;
12
+ function seedTenant(stack: TestStack, options?: SeedTenantOptions): Promise<InProcessSeededTenant>;
13
+ function setupAppTestStack(features: FeatureDefinition[], options?: SetupAppTestStackOptions): Promise<TestStack>;
14
+ ```
15
+
16
+ ## Types
17
+
18
+ ```ts
19
+ type SetupAppTestStackOptions = SetupTestStackFromFeaturesOptions & {
20
+ registryTables?: boolean;
21
+ featureToggles?: boolean; // Same as `RunDevAppOptions["featureToggles"]`: mounts `feature-toggles` (do not list it in `features`) and layers its operator switches over the dispatcher's feature gate.
22
+ };
23
+ ```
@@ -0,0 +1,277 @@
1
+ <!-- Generated by `bun run gen:agent-docs` from packages/framework/src/db/index.ts. Do not edit. -->
2
+
3
+ # @cosmicdrift/kumiko-framework/db
4
+
5
+ Import from `@cosmicdrift/kumiko-framework/db`. Types used here but not exported by any entry point are in `api/types.md`.
6
+
7
+ ## Functions
8
+
9
+ ```ts
10
+ function acquireNamespacedAdvisoryLock(db: AnyDb, namespace: number, key: string): Promise<void>; // pg_advisory_xact_lock keyed on namespace+key hash — xact-scoped, auto-released at commit/rollback.
11
+ function aggregateWhere(db: AnyDb, table: TableLike, spec: AggregateSpec, where?: WhereObject): Promise<AggregateRow[]>;
12
+ function answerListAggregate(executor: Pick<EventStoreExecutor, "aggregate">, request: AggregateRequest, user: Parameters<EventStoreExecutor["aggregate"]>[1], db: TenantDb, runtimeOptions: Parameters<EventStoreExecutor["aggregate"]>[3], labelDeps: LabelDeps): Promise<ListAggregateResult>;
13
+ function applyEntityEvent(event: StoredEvent, table: Table, entity: EntityDefinition, tx: ExecutorManagedRunner): Promise<ApplyResult>; // Applies an auto-event idempotently to the entity table.
14
+ function asEntityTableMeta(table: unknown): EntityTableMeta | undefined;
15
+ function asRawClient(db: unknown): RawClient;
16
+ function assertExistsIn(db: DbConnection | TenantDb, entity: any, options: { field: string; value: unknown; tenantId?: TenantId; where?: Record<string, unknown>; entityName?: string; }): Promise<NotFoundError | null>; // Generic constraint helper: asserts a value exists in a table.
17
+ function assertNoActiveRowLevelSecurityScope(startingWhat: string): void;
18
+ function assertRowLevelSecurityBootState(db: AnyDb, mode: RowLevelSecurityMode, knownTables: KnownTables): Promise<void>;
19
+ function assertRowLevelSecurityTableState(db: AnyDb, mode: RowLevelSecurityMode, knownTables: KnownTables, scope?: RowLevelSecurityCheckScope): Promise<void>;
20
+ function boolean(name: string): ColumnBuilder<boolean>;
21
+ function buildBaseColumns(softDelete: boolean, idType?: "serial" | "uuid"): …;
22
+ function buildEntityTable<E extends EntityDefinition>(entityName: string, entity: E, options?: BuildEntityTableOptions): EntityTable<E>;
23
+ function castTenantRows<T>(rows: Record<string, unknown>[]): T[];
24
+ function collectEncryptedFieldNames(entity: EntityDefinition): ReadonlySet<string>;
25
+ function collectTableMetas(features: FeatureDefinition[]): EntityTableMeta[];
26
+ function configureEntityFieldEncryption(cipher: EnvelopeCipher | undefined): void;
27
+ function configuredEntityFieldEncryption(): EnvelopeCipher | undefined;
28
+ function countWhere(db: AnyDb, table: TableLike, where?: WhereObject): Promise<number>;
29
+ function createDbConnection(props: CreateDbConnectionOptions): DbConnectionHandle;
30
+ function createEventStoreExecutor<E extends EntityDefinition>(table: Table, entity: E, options: EventStoreExecutorOptions): EventStoreExecutor<EntityRow<E>>;
31
+ function createEventStoreExecutor<E extends EntityDefinition>(table: Table, entity: E, options: EventStoreExecutorOptions): EventStoreExecutor<EntityRow<E>>;
32
+ function createSystemDbView(db: TenantDb, dbOutsideTransaction?: TenantDb, report?: EscapeHatchReporter): UncheckedSystemDb;
33
+ function createTenantDataDestroyDb(options: Omit<CreateTenantDbOptions, "mode" | "reason">): ExecutorManagedTenantDb;
34
+ function createTenantDb(options: CreateTenantDbOptions & { db: ExecutorManagedRunner; }): ExecutorManagedTenantDb;
35
+ function createTenantDb(options: CreateTenantDbOptions): TenantDb;
36
+ function createTenantDb(options: CreateTenantDbOptions & { db: ExecutorManagedRunner; }): ExecutorManagedTenantDb;
37
+ function createTenantDb(options: CreateTenantDbOptions): TenantDb;
38
+ function createTenantDb(options: CreateTenantDbOptions & { db: ExecutorManagedRunner; }): ExecutorManagedTenantDb;
39
+ function createTenantDb(options: CreateTenantDbOptions): TenantDb;
40
+ function dbConnectionOptionsFromEnv(env?: Readonly<Record<string, string | undefined>>): DbConnectionOptions;
41
+ function declareGlobalTenancy<T extends SchemaTable>(table: T): T & TenancyBrand<"global">; // Stamps `tenancy: "global"` onto a `table()`/SchemaTable's meta in place.
42
+ function decodeCursor(cursor: string): string;
43
+ function decodeKeysetCursor(cursor: string): DecodedKeysetCursor;
44
+ function decryptEntityFieldValues(row: Record<string, unknown>, encryptedFields: ReadonlySet<string>, cipher: EnvelopeCipher, opts?: { onFieldError?: (field: string, error: unknown) => void; }): Promise<Record<string, unknown>>;
45
+ function defineUnmanagedTable<const T extends EntityTenancy = "tenant">(input: UnmanagedTableInput & { tenancy?: T; }): EntityTableMeta & TenancyBrand<T> & Writable; // Hand-built EntityTableMeta for direct-write stores (no entity base columns).
46
+ function deleteMany(db: AnyDb, table: WritableTable, where: WhereObject): Promise<number>;
47
+ function deleteMany(db: ExecutorManagedWriteCapability, table: EntityTableMeta, where: WhereObject): Promise<number>;
48
+ function deleteMany(db: AnyDb, table: WritableTable, where: WhereObject): Promise<number>;
49
+ function deleteMany(db: ExecutorManagedWriteCapability, table: EntityTableMeta, where: WhereObject): Promise<number>;
50
+ function deleteMany(db: AnyDb, table: WritableTable, where: WhereObject): Promise<number>;
51
+ function deleteMany(db: ExecutorManagedWriteCapability, table: EntityTableMeta, where: WhereObject): Promise<number>;
52
+ function deleteManyBatched(db: AnyDb, table: WritableTable, where: WhereObject, options: DeleteManyBatchedOptions): Promise<DeleteManyBatchedResult>;
53
+ function deleteManyBatched(db: ExecutorManagedWriteCapability, table: EntityTableMeta, where: WhereObject, options: DeleteManyBatchedOptions): Promise<DeleteManyBatchedResult>;
54
+ function deleteManyBatched(db: AnyDb, table: WritableTable, where: WhereObject, options: DeleteManyBatchedOptions): Promise<DeleteManyBatchedResult>;
55
+ function deleteManyBatched(db: ExecutorManagedWriteCapability, table: EntityTableMeta, where: WhereObject, options: DeleteManyBatchedOptions): Promise<DeleteManyBatchedResult>;
56
+ function deleteManyBatched(db: AnyDb, table: WritableTable, where: WhereObject, options: DeleteManyBatchedOptions): Promise<DeleteManyBatchedResult>;
57
+ function deleteManyBatched(db: ExecutorManagedWriteCapability, table: EntityTableMeta, where: WhereObject, options: DeleteManyBatchedOptions): Promise<DeleteManyBatchedResult>;
58
+ function deriveEntityTableMeta(entityName: string, entity: EntityDefinition, options: BuildEntityTableMetaOptions & { source: "unmanaged"; }): EntityTableMeta & Writable; // Derive EntityTableMeta from an EntityDefinition (base columns + field DDL).
59
+ function deriveEntityTableMeta(entityName: string, entity: EntityDefinition, options?: BuildEntityTableMetaOptions): EntityTableMeta;
60
+ function deriveEntityTableMeta(entityName: string, entity: EntityDefinition, options: BuildEntityTableMetaOptions & { source: "unmanaged"; }): EntityTableMeta & Writable; // Derive EntityTableMeta from an EntityDefinition (base columns + field DDL).
61
+ function deriveEntityTableMeta(entityName: string, entity: EntityDefinition, options?: BuildEntityTableMetaOptions): EntityTableMeta;
62
+ function deriveEntityTableMeta(entityName: string, entity: EntityDefinition, options: BuildEntityTableMetaOptions & { source: "unmanaged"; }): EntityTableMeta & Writable; // Derive EntityTableMeta from an EntityDefinition (base columns + field DDL).
63
+ function deriveEntityTableMeta(entityName: string, entity: EntityDefinition, options?: BuildEntityTableMetaOptions): EntityTableMeta;
64
+ function encodeCursor(id: string | number): string;
65
+ function encodeKeysetCursor(sortValue: string | null, id: string): string;
66
+ function entityEventName(entityName: string, verb: EntityLifecycleVerb): string;
67
+ function entityTableFromRegistry(registry: Registry, entityName: string, entity: Parameters<typeof buildEntityTable>[1]): SchemaTable;
68
+ function enumerateFeatureTableSources(feature: FeatureDefinition): FeatureTableSource[];
69
+ function executeRawQuery<T = Record<string, unknown>>(db: AnyDb, sqlText: string, params?: unknown[]): Promise<T[]>; // Escape hatch for caller-built SQL that may write (or lock).
70
+ function extractPgError(e: unknown): PgErrorInfo | null;
71
+ function extractTableInfo(table: TableLike): TableInfo;
72
+ function extractTableName(table: unknown, context?): string; // Reads the `kumiko:schema:Name` symbol from a table object.
73
+ function fetchOne<TRow = AnyRow>(db: AnyDb, table: TableLike, where: WhereObject): Promise<TRow | undefined>;
74
+ function generateMigration(input: GenerateMigrationInput): GenerateMigrationOutput;
75
+ function incrementCounter<TRow = AnyRow>(db: AnyDb, table: WritableTable, values: Record<string, unknown>, increments: Record<string, number>, options?: IncrementCounterOptions): Promise<TRow | undefined>;
76
+ function incrementCounter<TRow = AnyRow>(db: ExecutorManagedWriteCapability, table: EntityTableMeta, values: Record<string, unknown>, increments: Record<string, number>, options?: IncrementCounterOptions): Promise<TRow | undefined>;
77
+ function incrementCounter<TRow = AnyRow>(db: AnyDb, table: WritableTable, values: Record<string, unknown>, increments: Record<string, number>, options?: IncrementCounterOptions): Promise<TRow | undefined>;
78
+ function incrementCounter<TRow = AnyRow>(db: ExecutorManagedWriteCapability, table: EntityTableMeta, values: Record<string, unknown>, increments: Record<string, number>, options?: IncrementCounterOptions): Promise<TRow | undefined>;
79
+ function incrementCounter<TRow = AnyRow>(db: AnyDb, table: WritableTable, values: Record<string, unknown>, increments: Record<string, number>, options?: IncrementCounterOptions): Promise<TRow | undefined>;
80
+ function incrementCounter<TRow = AnyRow>(db: ExecutorManagedWriteCapability, table: EntityTableMeta, values: Record<string, unknown>, increments: Record<string, number>, options?: IncrementCounterOptions): Promise<TRow | undefined>;
81
+ function index(name: string): IndexBuilder;
82
+ function insertMany<TRow = AnyRow>(db: AnyDb, table: WritableTable, rows: ReadonlyArray<Record<string, unknown>>): Promise<TRow[]>;
83
+ function insertMany<TRow = AnyRow>(db: ExecutorManagedWriteCapability, table: EntityTableMeta, rows: ReadonlyArray<Record<string, unknown>>): Promise<TRow[]>;
84
+ function insertMany<TRow = AnyRow>(db: AnyDb, table: WritableTable, rows: ReadonlyArray<Record<string, unknown>>): Promise<TRow[]>;
85
+ function insertMany<TRow = AnyRow>(db: ExecutorManagedWriteCapability, table: EntityTableMeta, rows: ReadonlyArray<Record<string, unknown>>): Promise<TRow[]>;
86
+ function insertMany<TRow = AnyRow>(db: AnyDb, table: WritableTable, rows: ReadonlyArray<Record<string, unknown>>): Promise<TRow[]>;
87
+ function insertMany<TRow = AnyRow>(db: ExecutorManagedWriteCapability, table: EntityTableMeta, rows: ReadonlyArray<Record<string, unknown>>): Promise<TRow[]>;
88
+ function insertOnConflictDoNothing<TRow = AnyRow>(db: AnyDb, table: WritableTable, values: Record<string, unknown>, options?: InsertOnConflictDoNothingOptions): Promise<TRow | undefined>;
89
+ function insertOnConflictDoNothing<TRow = AnyRow>(db: ExecutorManagedWriteCapability, table: EntityTableMeta, values: Record<string, unknown>, options?: InsertOnConflictDoNothingOptions): Promise<TRow | undefined>;
90
+ function insertOnConflictDoNothing<TRow = AnyRow>(db: AnyDb, table: WritableTable, values: Record<string, unknown>, options?: InsertOnConflictDoNothingOptions): Promise<TRow | undefined>;
91
+ function insertOnConflictDoNothing<TRow = AnyRow>(db: ExecutorManagedWriteCapability, table: EntityTableMeta, values: Record<string, unknown>, options?: InsertOnConflictDoNothingOptions): Promise<TRow | undefined>;
92
+ function insertOnConflictDoNothing<TRow = AnyRow>(db: AnyDb, table: WritableTable, values: Record<string, unknown>, options?: InsertOnConflictDoNothingOptions): Promise<TRow | undefined>;
93
+ function insertOnConflictDoNothing<TRow = AnyRow>(db: ExecutorManagedWriteCapability, table: EntityTableMeta, values: Record<string, unknown>, options?: InsertOnConflictDoNothingOptions): Promise<TRow | undefined>;
94
+ function insertOne<TRow = AnyRow>(db: AnyDb, table: WritableTable, values: Record<string, unknown>): Promise<TRow | undefined>;
95
+ function insertOne<TRow = AnyRow>(db: ExecutorManagedWriteCapability, table: EntityTableMeta, values: Record<string, unknown>): Promise<TRow | undefined>;
96
+ function insertOne<TRow = AnyRow>(db: AnyDb, table: WritableTable, values: Record<string, unknown>): Promise<TRow | undefined>;
97
+ function insertOne<TRow = AnyRow>(db: ExecutorManagedWriteCapability, table: EntityTableMeta, values: Record<string, unknown>): Promise<TRow | undefined>;
98
+ function insertOne<TRow = AnyRow>(db: AnyDb, table: WritableTable, values: Record<string, unknown>): Promise<TRow | undefined>;
99
+ function insertOne<TRow = AnyRow>(db: ExecutorManagedWriteCapability, table: EntityTableMeta, values: Record<string, unknown>): Promise<TRow | undefined>;
100
+ function instant(name: string, opts?: { precision?: 0 | 1 | 2 | 3 | 4 | 5 | 6; }): ColumnBuilder<Temporal.Instant>;
101
+ function instantToTimestamptzParam(instant: Temporal.Instant): string;
102
+ function integer(name: string): ColumnBuilder<number>;
103
+ function isTimestamptzType(pgType: string | undefined): boolean;
104
+ function isUndefinedTable(e: unknown): boolean;
105
+ function isUniqueViolation(e: unknown): boolean;
106
+ function jsonb(name: string): ColumnBuilder<Record<string, unknown>>;
107
+ function knownTablesOf(features: FeatureDefinition[]): KnownTables;
108
+ function listEventTenantIds(db: AnyDb): Promise<string[]>;
109
+ function loadSnapshotJson(path: string): Snapshot | null;
110
+ function nullBlindIndexesForSubject(db: DbRunner, features: ReadonlyMap<string, FeatureDefinition>, subjectKey: string): Promise<void>;
111
+ function outsideTransactionPoolOptionsFromEnv(env?: Readonly<Record<string, string | undefined>>): DbConnectionOptions;
112
+ function physicalColumnName(table: Table, field: string): string;
113
+ function primaryKey(opts: { columns: ColumnHandle[]; name?: string; }): PrimaryKeyDescriptor;
114
+ function readDatabaseNow(db: TenantDb): Promise<Date>; // Postgres clock; inside a transaction `now()` is the transaction start, so repeated reads agree.
115
+ function recordEventsOwnedExclusivelyByTenant(db: DbRunner, aggregateType: string, aggregateId: string, tenantId: string): Promise<boolean>;
116
+ function recordRowExistsInTenant(db: DbRunner, features: ReadonlyMap<string, FeatureDefinition>, entityName: string, recordId: string, tenantId: string): Promise<boolean>;
117
+ function recordRowOwningTenantId(db: DbRunner, features: ReadonlyMap<string, FeatureDefinition>, entityName: string, recordId: string): Promise<string | undefined>;
118
+ function rehydrateMoney(row: Record<string, unknown>, entity: EntityDefinition): Record<string, unknown>; // Rehydrate two flat DB columns into a combined `{ amount, currency }` value.
119
+ function renderTablesDdl(metas: EntityTableMeta[], options?: RenderDdlOptions): string[];
120
+ function requireEntityTableMeta(table: unknown, tableName: string): EntityTableMeta;
121
+ function rowLevelSecurityModeOf(db: unknown): RowLevelSecurityMode;
122
+ function runInOwnTransaction<T>(tenantDb: TenantDb, fn: (txDb: TenantDb) => Promise<T>): Promise<T>;
123
+ function runInSavepointIfSupported<T>(db: ExecutorManagedRunner, fn: (sp: ExecutorManagedRunner) => Promise<T>): Promise<T>;
124
+ function runInSavepointIfSupported<T>(db: unknown, fn: (sp: DbRunner) => Promise<T>): Promise<T>;
125
+ function runInSavepointIfSupported<T>(db: ExecutorManagedRunner, fn: (sp: ExecutorManagedRunner) => Promise<T>): Promise<T>;
126
+ function runInSavepointIfSupported<T>(db: unknown, fn: (sp: DbRunner) => Promise<T>): Promise<T>;
127
+ function runInSavepointIfSupported<T>(db: ExecutorManagedRunner, fn: (sp: ExecutorManagedRunner) => Promise<T>): Promise<T>;
128
+ function runInSavepointIfSupported<T>(db: unknown, fn: (sp: DbRunner) => Promise<T>): Promise<T>;
129
+ function runMigrationsFromDir(db: DbConnection, dir: string): Promise<ApplyResult>;
130
+ function runnerCanBeginTransaction(db: unknown): boolean;
131
+ function scopeTenantDbToTenant(db: TenantDb, tenantId: TenantId): TenantDb;
132
+ function seedConfigValues<E extends EntityDefinition>(seeds: ConfigSeedDef[], table: EntityTable<E>, entity: E, registry: Registry, db: DbConnection, cipher?: EnvelopeCipher): Promise<{ created: number; skipped: number; }>; // Seed config values at boot time via the event-store executor.
133
+ function seedReferenceData(defs: ReferenceDataDef[], registry: Registry, db: DbConnection): Promise<{ inserted: number; updated: number; }>; // Seed reference data at boot time.
134
+ function selectInnerJoin<TLeft = Record<string, unknown>, TRight = Record<string, unknown>>(db: AnyDb, spec: InnerJoinSpec): Promise<InnerJoinRow<TLeft, TRight>[]>;
135
+ function selectMany<TRow = AnyRow>(db: AnyDb, table: TableLike, where?: WhereObject, options?: SelectOptions): Promise<TRow[]>;
136
+ function serial(name: string): ColumnBuilder<number>;
137
+ function serverTimeoutOptionsFromEnv(env?: Readonly<Record<string, string | undefined>>): DbConnectionOptions;
138
+ function sql(strings: TemplateStringsArray, ...values: unknown[]): SqlExpression;
139
+ function subjectRowExistsInTenant(db: DbRunner, features: ReadonlyMap<string, FeatureDefinition>, subjectId: string, tenantId: string): Promise<boolean>;
140
+ function table<TCols extends ColumnMap>(tableName: string, cols: TCols, optsFn?: (t: { [K in keyof TCols]: ColumnHandle; }) => Record<string, IndexOrPk> | ReadonlyArray<IndexOrPk>): WritableSchemaTable;
141
+ function tableExists(db: DbConnection | DbTx, fullyQualifiedName: string): Promise<boolean>;
142
+ function text(name: string): ColumnBuilder<string>;
143
+ function timestamp(name: string, _opts?: { withTimezone?: boolean; mode?: "string" | "date"; }): ColumnBuilder<Temporal.Instant | string>;
144
+ function toPostgresArrayLiteral(values: PostgresArrayElement[]): string;
145
+ function transaction<T>(db: AnyDb, fn: (tx: DbTx) => Promise<T>): Promise<T>;
146
+ function uniqueIndex(name: string): IndexBuilder;
147
+ function unsafeReadRetrying<TRow>(db: AnyDb, sqlText: string, params: unknown[]): Promise<TRow[]>;
148
+ function updateMany<TRow = AnyRow>(db: AnyDb, table: WritableTable, set: Record<string, unknown>, where: WhereObject): Promise<TRow[]>;
149
+ function updateMany<TRow = AnyRow>(db: ExecutorManagedWriteCapability, table: EntityTableMeta, set: Record<string, unknown>, where: WhereObject): Promise<TRow[]>;
150
+ function updateMany<TRow = AnyRow>(db: AnyDb, table: WritableTable, set: Record<string, unknown>, where: WhereObject): Promise<TRow[]>;
151
+ function updateMany<TRow = AnyRow>(db: ExecutorManagedWriteCapability, table: EntityTableMeta, set: Record<string, unknown>, where: WhereObject): Promise<TRow[]>;
152
+ function updateMany<TRow = AnyRow>(db: AnyDb, table: WritableTable, set: Record<string, unknown>, where: WhereObject): Promise<TRow[]>;
153
+ function updateMany<TRow = AnyRow>(db: ExecutorManagedWriteCapability, table: EntityTableMeta, set: Record<string, unknown>, where: WhereObject): Promise<TRow[]>;
154
+ function upsertByPk<TRow = AnyRow>(db: AnyDb, table: WritableTable, values: Record<string, unknown>, updateOnConflict?: Record<string, unknown>): Promise<TRow | undefined>;
155
+ function upsertByPk<TRow = AnyRow>(db: ExecutorManagedWriteCapability, table: EntityTableMeta, values: Record<string, unknown>, updateOnConflict?: Record<string, unknown>): Promise<TRow | undefined>;
156
+ function upsertByPk<TRow = AnyRow>(db: AnyDb, table: WritableTable, values: Record<string, unknown>, updateOnConflict?: Record<string, unknown>): Promise<TRow | undefined>;
157
+ function upsertByPk<TRow = AnyRow>(db: ExecutorManagedWriteCapability, table: EntityTableMeta, values: Record<string, unknown>, updateOnConflict?: Record<string, unknown>): Promise<TRow | undefined>;
158
+ function upsertByPk<TRow = AnyRow>(db: AnyDb, table: WritableTable, values: Record<string, unknown>, updateOnConflict?: Record<string, unknown>): Promise<TRow | undefined>;
159
+ function upsertByPk<TRow = AnyRow>(db: ExecutorManagedWriteCapability, table: EntityTableMeta, values: Record<string, unknown>, updateOnConflict?: Record<string, unknown>): Promise<TRow | undefined>;
160
+ function upsertOnConflict<TRow = AnyRow>(db: AnyDb, table: WritableTable, values: Record<string, unknown>, options: UpsertOnConflictOptions): Promise<TRow | undefined>;
161
+ function upsertOnConflict<TRow = AnyRow>(db: ExecutorManagedWriteCapability, table: EntityTableMeta, values: Record<string, unknown>, options: UpsertOnConflictOptions): Promise<TRow | undefined>;
162
+ function upsertOnConflict<TRow = AnyRow>(db: AnyDb, table: WritableTable, values: Record<string, unknown>, options: UpsertOnConflictOptions): Promise<TRow | undefined>;
163
+ function upsertOnConflict<TRow = AnyRow>(db: ExecutorManagedWriteCapability, table: EntityTableMeta, values: Record<string, unknown>, options: UpsertOnConflictOptions): Promise<TRow | undefined>;
164
+ function upsertOnConflict<TRow = AnyRow>(db: AnyDb, table: WritableTable, values: Record<string, unknown>, options: UpsertOnConflictOptions): Promise<TRow | undefined>;
165
+ function upsertOnConflict<TRow = AnyRow>(db: ExecutorManagedWriteCapability, table: EntityTableMeta, values: Record<string, unknown>, options: UpsertOnConflictOptions): Promise<TRow | undefined>;
166
+ function uuid(name: string): ColumnBuilder<string>;
167
+ function withSessionAdvisoryLock<T>(db: AnyDb, key: number, fn: () => Promise<T>): Promise<T>;
168
+ function writeSnapshotJson(path: string, snapshot: Snapshot): void;
169
+ ```
170
+
171
+ ## Constants
172
+
173
+ ```ts
174
+ const DEFAULT_OUTSIDE_TRANSACTION_POOL_MAX: 3;
175
+ const ROW_LEVEL_SECURITY_MODES: ["off", "on"];
176
+ const WritePurposes: { retention: "retention"; erasure: "erasure"; };
177
+ ```
178
+
179
+ ## Types
180
+
181
+ ```ts
182
+ type ColumnMeta = {
183
+ name: string;
184
+ pgType: PgType;
185
+ notNull: boolean;
186
+ defaultSql?: string;
187
+ primaryKey?: boolean;
188
+ identity?: boolean;
189
+ bigintJsMode?: "number" | "bigint";
190
+ };
191
+ type DbConnection = SQL | RawDbClient;
192
+ type DbRow = Record<string, unknown>;
193
+ type DbRunner = DbConnection | DbTx;
194
+ type DbTx = TransactionSQL | RawDbClient;
195
+ type EntityTable<E extends EntityDefinition = EntityDefinition> = TableColumns & BaseColumnsType<E> & SoftDeleteColumnsType & ColumnsForEntity<E["fields"]> & TenancyBrand<EntityTableTenancy<E>>;
196
+ type EntityTableMeta = {
197
+ tableName: string;
198
+ columns: ColumnMeta[];
199
+ indexes: IndexMeta[];
200
+ compositePrimaryKey?: CompositePrimaryKeyMeta;
201
+ source: "managed" | "unmanaged";
202
+ piiSubjectFields?: string[];
203
+ tenancy?: "global";
204
+ };
205
+ type EventStoreExecutor<Row extends Record<string, unknown> = Record<string, unknown>> = {
206
+ create: (payload: Record<string, unknown>, user: SessionUser, db: TenantDb, options?: StreamTenantOption & { preSave?: PreSaveRunner; }) => Promise<WriteResult<SaveContext>>;
207
+ update: (payload: { id: EntityId; version?: number | undefined; changes: Record<string, unknown>; }, user: SessionUser, db: TenantDb, options?: StreamTenantOption & LockGuardOption & ParentVisibilityGateOption & { skipOptimisticLock?: boolean; ski…;
208
+ delete: (payload: { id: EntityId; }, user: SessionUser, db: TenantDb, options?: StreamTenantOption & LockGuardOption & ParentVisibilityGateOption) => Promise<WriteResult<DeleteContext>>;
209
+ forget: (payload: { id: EntityId; }, user: SessionUser, db: TenantDb, options?: StreamTenantOption & ParentVisibilityGateOption) => Promise<WriteResult<DeleteContext>>;
210
+ restore: (payload: { id: EntityId; }, user: SessionUser, db: TenantDb, options?: StreamTenantOption & ParentVisibilityGateOption) => Promise<WriteResult<SaveContext>>;
211
+ list: (payload: { cursor?: string | undefined; limit?: number | undefined; search?: string | undefined; sort?: string | undefined; sortDirection?: "asc" | "desc" | undefined; offset?: number | undefined; totalCount?: boolean | undefined; filter?…;
212
+ aggregate: (payload: ListAggregateRequest, user: SessionUser, db: TenantDb, runtimeOptions?: ListRuntimeOptions) => Promise<ListAggregateResult>; // Groups and measures over the same WHERE as `list` (filters, search, ownership, field-read gates); paging and sort are ignored.
213
+ detail: (payload: { id: EntityId; }, user: SessionUser, db: TenantDb, options?: { parentVisibility?: ParentVisibilityOption; }) => Promise<Row | null>;
214
+ };
215
+ type ExecutorManagedRunner = DbRunner & ExecutorManagedWriteCapability;
216
+ type ExecutorManagedTenantDb = TenantDbNonWrites & TenantDbWrites<EntityTableMeta> & ExecutorManagedWriteCapability;
217
+ type JsonTextMatch = {
218
+ keys: [ string, ...string[] ]; // Top-level keys, tried in order; the first non-null text value is compared (COALESCE).
219
+ eq: string;
220
+ };
221
+ type KnownTables = {
222
+ has: (tableName: string) => boolean;
223
+ };
224
+ type MoneyRead = { // Shape of a single rehydrated money field — {amount major, currency, amountScaled exact integer value in MINOR_UNIT_SCALE units}.
225
+ amount: number;
226
+ currency: string;
227
+ amountScaled: number;
228
+ amountMinor: number;
229
+ };
230
+ type RowLevelSecurityMode = (typeof ROW_LEVEL_SECURITY_MODES)[number];
231
+ type RowLevelSecurityScope =
232
+ | {
233
+ kind: "tenant";
234
+ tenantId: TenantId;
235
+ }
236
+ | {
237
+ kind: "system";
238
+ reason: string;
239
+ }
240
+ ;
241
+ type SchemaTable = EntityTableMeta & {
242
+ [KUMIKO_NAME_SYMBOL]: string;
243
+ [KUMIKO_COLUMNS_SYMBOL]: Record<string, ColumnHandle>;
244
+ [KUMIKO_META_SYMBOL]: EntityTableMeta;
245
+ [field: string]: unknown;
246
+ };
247
+ type SelectOptions = {
248
+ limit?: number;
249
+ fields?: string[];
250
+ orderBy?: OrderByClause | OrderByClause[];
251
+ distinctOn?: [ string, ...string[] ];
252
+ };
253
+ type TableInfo = {
254
+ name: string;
255
+ columnOf: (field: string) => string;
256
+ pgTypeOf: (column: string) => string | undefined;
257
+ bigintJsModeOf: (column: string) => "number" | "bigint" | undefined;
258
+ fieldOf: (column: string) => string;
259
+ hasColumn: (fieldOrColumn: string) => boolean;
260
+ };
261
+ type TenantDb = TenantDbNonWrites & TenantDbWrites<WritableTable>;
262
+ type UncheckedSystemDb = {
263
+ [SYSTEM_SCOPE_CHECK_BRAND]: true;
264
+ assertTenantMatch(tenantId: TenantId): TenantDb;
265
+ assertRowsTenant<T>(rows: T[], tenantField: keyof T): T[];
266
+ acknowledgeCrossTenant(reason: string): TenantDb;
267
+ unsafeRaw(reason: string): DbRunner; // Raw unfiltered DbRunner, gated behind a mandatory non-empty `reason` for auditability.
268
+ outsideTransaction: {
269
+ assertTenantMatch(tenantId: TenantId): TenantDb;
270
+ acknowledgeCrossTenant(reason: string): TenantDb;
271
+ };
272
+ };
273
+ type WhereObject = Record<string, WhereValue | unknown>;
274
+ type WritableSchemaTable = SchemaTable & Writable;
275
+ type WritableTable = EntityTableMeta & Writable;
276
+ type WritePurpose = (typeof WritePurposes)[keyof typeof WritePurposes];
277
+ ```