@fabrika/db 0.9.0-dev.4 → 0.9.0-dev.41

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.
Files changed (84) hide show
  1. package/package.json +39 -4
  2. package/src/admissions.ts +78 -12
  3. package/src/application-rows.ts +108 -0
  4. package/src/authority.ts +560 -0
  5. package/src/builtins.ts +21 -0
  6. package/src/capability.ts +56 -2
  7. package/src/codegen-sqlite.ts +194 -0
  8. package/src/codegen.ts +230 -41
  9. package/src/condition-nodes.ts +119 -0
  10. package/src/conditions.ts +683 -0
  11. package/src/database.ts +227 -61
  12. package/src/description.ts +37 -8
  13. package/src/errors.ts +10 -6
  14. package/src/file-columns.ts +56 -11
  15. package/src/framework-tables.ts +28 -8
  16. package/src/framework.ts +15 -5
  17. package/src/guard.ts +373 -15
  18. package/src/index.ts +17 -1
  19. package/src/job-leases.ts +228 -55
  20. package/src/job-wakes.ts +600 -0
  21. package/src/json.ts +124 -0
  22. package/src/links.ts +8 -1
  23. package/src/list-cursor.ts +82 -0
  24. package/src/migrations-sqlite.ts +210 -0
  25. package/src/migrations.ts +73 -0
  26. package/src/nodes.ts +84 -14
  27. package/src/orm-types.ts +206 -71
  28. package/src/orm.ts +425 -170
  29. package/src/policy.ts +1979 -141
  30. package/src/postgres.ts +26 -0
  31. package/src/registry.ts +55 -3
  32. package/src/request-receipts.ts +107 -0
  33. package/src/sql.ts +247 -476
  34. package/src/sqlite-bun.ts +149 -0
  35. package/src/sqlite-migrate.ts +242 -0
  36. package/src/sqlite.ts +269 -0
  37. package/src/store.ts +2292 -239
  38. package/src/stored-files.ts +188 -52
  39. package/src/tables.ts +172 -6
  40. package/src/temporal.ts +122 -9
  41. package/src/testing-shared.ts +1351 -0
  42. package/src/testing-sqlite.ts +685 -0
  43. package/src/testing.ts +310 -494
  44. package/src/vocabulary-tables.ts +159 -27
  45. package/types/src/application-rows.d.ts +58 -0
  46. package/types/src/authority.d.ts +147 -0
  47. package/types/src/builtins.d.ts +2 -0
  48. package/types/src/capability.d.ts +55 -2
  49. package/types/src/codegen-sqlite.d.ts +13 -0
  50. package/types/src/codegen.d.ts +79 -5
  51. package/types/src/condition-nodes.d.ts +9 -0
  52. package/types/src/conditions.d.ts +151 -0
  53. package/types/src/database.d.ts +81 -20
  54. package/types/src/description.d.ts +26 -8
  55. package/types/src/errors.d.ts +9 -6
  56. package/types/src/file-columns.d.ts +6 -4
  57. package/types/src/framework.d.ts +12 -5
  58. package/types/src/guard.d.ts +24 -0
  59. package/types/src/index.d.ts +5 -4
  60. package/types/src/job-leases.d.ts +40 -5
  61. package/types/src/job-wakes.d.ts +124 -0
  62. package/types/src/json.d.ts +18 -0
  63. package/types/src/list-cursor.d.ts +13 -0
  64. package/types/src/migrations-sqlite.d.ts +4 -0
  65. package/types/src/migrations.d.ts +4 -0
  66. package/types/src/nodes.d.ts +17 -2
  67. package/types/src/orm-types.d.ts +163 -71
  68. package/types/src/orm.d.ts +21 -0
  69. package/types/src/policy.d.ts +351 -23
  70. package/types/src/postgres.d.ts +12 -0
  71. package/types/src/registry.d.ts +40 -3
  72. package/types/src/request-receipts.d.ts +22 -0
  73. package/types/src/sql.d.ts +29 -21
  74. package/types/src/sqlite-bun.d.ts +21 -0
  75. package/types/src/sqlite-migrate.d.ts +28 -0
  76. package/types/src/sqlite.d.ts +24 -0
  77. package/types/src/store.d.ts +143 -34
  78. package/types/src/stored-files.d.ts +6 -2
  79. package/types/src/tables.d.ts +18 -2
  80. package/types/src/temporal.d.ts +24 -0
  81. package/types/src/testing-shared.d.ts +290 -0
  82. package/types/src/testing-sqlite.d.ts +37 -0
  83. package/types/src/testing.d.ts +2 -93
  84. package/types/src/vocabulary-tables.d.ts +169 -22
@@ -18,6 +18,30 @@ export interface GuardContext {
18
18
  readonly lock?: 'share' | 'update' | 'claim';
19
19
  /** An insert that does nothing on a conflict of its listed columns: `on conflict (columns) do nothing`, and no other. */
20
20
  readonly onConflict?: 'nothing';
21
+ /**
22
+ * The tables a scope predicate's subqueries may read, each with the columns one may select: a relation's source by
23
+ * its node column, a condition path's target by its key. Without it, a scope holds no subquery.
24
+ */
25
+ readonly subqueries?: Readonly<Record<string, readonly string[]>>;
26
+ /**
27
+ * A child view's parent: its scope may read the view's rows through `<column> in (select P.<key> from P where <P's
28
+ * reach>)`. Without it, a scope holds no such subquery.
29
+ */
30
+ readonly through?: ViewParentLink | undefined;
31
+ }
32
+ /** The parent a child view's scope reads its rows through: the view's parent column, the parent table and its key. */
33
+ export interface ViewParentLink {
34
+ readonly column: string;
35
+ readonly table: string;
36
+ readonly key: string;
37
+ /** The view's own access views, which list its rows beside the parent's reach (ADR-0076). */
38
+ readonly access?: readonly ViewAccessLink[];
39
+ }
40
+ /** An access view of a child view: `V.<key> in (select A.<row> from A where <bindings>)`. */
41
+ export interface ViewAccessLink {
42
+ readonly key: string;
43
+ readonly view: string;
44
+ readonly row: string;
21
45
  }
22
46
  /** Refuses any operation tree outside the allowlist. Runs on the final tree, immediately before it is compiled. */
23
47
  export declare function assertAllowedTree(root: OperationNode, context: GuardContext): void;
@@ -1,10 +1,11 @@
1
- export type { AppCapability, AppGrant, CapabilityAuthority, CapabilityGrant, ContainerGrant, LeaseFence, Ref, RefGrant, RowGrant, RowRef, Within, WithinGrant, } from './capability';
1
+ export type { AppCapability, AppGrant, CapabilityAuthority, CapabilityGrant, ContainerGrant, LeaseFence, Ref, RefGrant, RelationHold, RowGrant, RowRef, Within, WithinGrant, } from './capability';
2
2
  export { MAX_WITHIN_VALUES } from './capability';
3
- export { applicationSchema, Database, type PostgresOptions } from './database';
3
+ export { applicationSchema, Database, type DatabaseEngine, type Executor, type SqlDialect, type TransactionOptions, type TransactionRunner, } from './database';
4
4
  export type { AllowedOperator, ComparisonOperator, ConditionTuple, ListOperator, NoColumns, NullOperator, PatternOperator, Primitive, ScopedSelect, } from './description';
5
5
  export { CAPABILITY_ERRORS, CapabilityError, type CapabilityErrorReason, DatabaseError, LeaseLostError, PolicyError, QUERY_REFUSALS, type QueryRefusal, QueryRefusedError, } from './errors';
6
- export type { AnyDbIndex, ChildRows, ContainedRows, CountOptions, DataKind, DbIndex, IndexedTable, ListOptions, ListPage, NoUnscoped, OrderTerm, OwnerRow, ReadOnlyUnscoped, ReferenceRows, ReferenceTables, RowFor, Saved, ScopeTarget, TargetForm, TargetRow, Unavailable, UnownedTarget, UnscopedDeclaration, UnscopedInsert, UnscopedMode, UnscopedRows, UnscopedTables, VersionArguments, WithinRows, WithinTables, } from './orm-types';
6
+ export type { JsonColumnValue, JsonValue } from './json';
7
+ export type { AllOptions, AllQuery, AnyDbIndex, ChildRows, ContainedRows, CountOptions, CountQuery, DataKind, DbIndex, IndexedTable, ListOptions, ListPage, ListQuery, NoUnscoped, OrderTerm, OwnerRow, ReadOnlyUnscoped, ReferenceRows, ReferenceTables, RowFor, Saved, ScopeTarget, TargetForm, TargetRow, Unavailable, UnownedTarget, UnscopedDeclaration, UnscopedInsert, UnscopedMode, UnscopedRows, UnscopedTables, VersionArguments, WithinRows, WithinTables, } from './orm-types';
7
8
  export { type ChildPolicy, type ChildScope, type ColumnList, defineTables, type DimensionPolicy, type DimensionScope, type InsertValues, isTables, readTables, type RecordActions, type ReferencePolicy, type ReferenceScope, type RowOf, type TableActions, type TableInsert, Tables, type TableUpdate, type UpdateValues, type VersionColumn, type VocabularyTables, } from './policy';
8
9
  export { type AggregateRow, type AggregateSpec, type ChildListScope, type DataLayer, type DataLayerRuntime, scoped, type ScopedDatabase, } from './store';
9
10
  export { type TablePolicies, tablePolicies } from './tables';
10
- export type { ColumnTypes, DefineVocabularyPolicies, NormalizedPolicies, TableVocabulary, TypedColumnList, VocabularyAction, VocabularyChildScope, VocabularyContainer, VocabularyContainerOf, VocabularyDimension, VocabularyDimensionScope, VocabularyPolicyMap, VocabularyTablePolicy, } from './vocabulary-tables';
11
+ export type { ColumnTypes, ColumnViews, DefineVocabularyPolicies, NormalizedPolicies, TableVocabulary, TypedColumnList, VocabularyAction, VocabularyChildScope, VocabularyContainer, VocabularyContainerOf, VocabularyDimension, VocabularyDimensionScope, VocabularyPolicyMap, VocabularyTablePolicy, VocabularyViewPolicy, } from './vocabulary-tables';
@@ -1,5 +1,6 @@
1
1
  import type { LeaseFence } from './capability';
2
- import { type Session } from './database';
2
+ import { type Session, type SqlDialect } from './database';
3
+ import { type FinishWakes } from './job-wakes';
3
4
  import type { DataLayerRuntime } from './store';
4
5
  export type JobOutcome = 'succeeded' | 'failed';
5
6
  export interface JobLeaseState {
@@ -48,8 +49,17 @@ export interface JobLeases {
48
49
  * now on. `null` when `fence` no longer holds it.
49
50
  */
50
51
  renew(fence: LeaseFence, holder: string, attemptMs: number, leaseMs: number): Promise<LeaseFence | null>;
51
- /** Frees the lease and records the run's outcome and duration; `false` when `fence` no longer held it. */
52
- finish(fence: LeaseFence, outcome: JobOutcome): Promise<boolean>;
52
+ /**
53
+ * Frees the lease and records the run's outcome and duration, and in the same transaction applies `wakes` to the wakes
54
+ * the run owned (`job-wakes.ts`). `false` when `fence` no longer held it: then nothing is applied.
55
+ */
56
+ finish(fence: LeaseFence, outcome: JobOutcome, wakes?: FinishWakes): Promise<boolean>;
57
+ /**
58
+ * Gives back a lease under which no run started: frees it and leaves every wake as it is, owned ones disowned, and
59
+ * records no run (no status, end or duration). A process schedule's timer releases a lease whose take owned no due
60
+ * wake (ADR-0080). `false` when `fence` no longer held it.
61
+ */
62
+ release(fence: LeaseFence): Promise<boolean>;
53
63
  /** Records that a kick arrived: the run that started before it runs the job once more. Never waits on the lease. */
54
64
  markPending(job: string): Promise<void>;
55
65
  /**
@@ -69,9 +79,33 @@ export interface JobLeases {
69
79
  cancelInFlight(fence: LeaseFence): Promise<void>;
70
80
  state(job: string): Promise<JobLeaseState | null>;
71
81
  }
82
+ /**
83
+ * What a lease statement changed: a crashed holder reaped, a lease taken or handed on, or a run finished with what its
84
+ * wakes become (`null` leaves them).
85
+ */
86
+ export type LeaseChange = {
87
+ readonly kind: 'reaped' | 'acquired' | 'renewed';
88
+ } | {
89
+ readonly kind: 'finished';
90
+ readonly wakes: FinishWakes | null;
91
+ };
92
+ /**
93
+ * Runs in the transaction of every lease statement that changed the lease, so a table that follows the lease (the
94
+ * wakes, `job-wakes.ts`) commits with it or not at all. A statement that changed nothing, a lost lease's, runs none.
95
+ */
96
+ export type LeaseProjection = (transaction: Session, job: string, change: LeaseChange) => Promise<void>;
97
+ /** One framework statement in each dialect's text; a session runs the text of its own. */
98
+ export type DialectTexts = Readonly<Record<SqlDialect, string>>;
99
+ /** SQLite's clock, as a stored timestamp: ISO text, so a comparison of two is a text comparison. */
100
+ export declare const SQLITE_NOW = "strftime('%Y-%m-%dT%H:%M:%fZ', 'now')";
101
+ /** SQLite's clock moved by `ms`, an SQL expression of milliseconds (negative is earlier). */
102
+ export declare function sqliteNowPlus(ms: string): string;
103
+ /** A stored SQLite timestamp (`SQLITE_NOW_FORMAT`) as a `Date`, or `null`; anything else is refused. */
104
+ export declare function sqliteTimestamp(value: unknown, what: string): Date | null;
72
105
  /**
73
106
  * The database's clock inside `session`'s transaction: a queue claim compares and moves `due` by it, so no process
74
- * clock decides when a row is due.
107
+ * clock decides when a row is due. On Postgres it is rounded up to the millisecond a `Date` holds, so it is never
108
+ * earlier than a `due` that `now()` wrote with microseconds.
75
109
  */
76
110
  export declare function databaseNow(session: Session): Promise<Date>;
77
111
  /**
@@ -79,6 +113,7 @@ export declare function databaseNow(session: Session): Promise<Date>;
79
113
  * stays locked `for share` until the commit (a takeover or a renewal waits), and every statement is bounded by the
80
114
  * attempt's remaining time. After it, just before the commit: the attempt still holds the lease within its deadline.
81
115
  * Otherwise the transaction rolls back with `LeaseLostError`; so does a statement the deadline or the runner cancelled.
116
+ * On SQLite only the two checks run: no other event reaches the Durable Object while the transaction is open.
82
117
  */
83
118
  export declare function fencedTransaction<T>(session: Session, fence: LeaseFence, work: (transaction: Session) => Promise<T>): Promise<T>;
84
- export declare function jobLeases(runtime: () => DataLayerRuntime): JobLeases;
119
+ export declare function jobLeases(runtime: () => DataLayerRuntime, project: LeaseProjection): JobLeases;
@@ -0,0 +1,124 @@
1
+ import type { LeaseFence } from './capability';
2
+ import { type Session } from './database';
3
+ import type { JobOutcome, LeaseProjection } from './job-leases';
4
+ import type { DataLayerRuntime } from './store';
5
+ export declare const WAKE_REASONS: readonly ["cron", "kick", "claim", "retry"];
6
+ export type WakeReason = (typeof WAKE_REASONS)[number];
7
+ export interface NewWake {
8
+ readonly job: string;
9
+ readonly reason: WakeReason;
10
+ readonly dueAt: Date;
11
+ /** Wakes under one key are one row: `cron:<job>:<expr>`, `claim:<job>`, `kick:<job>:<due second>`. */
12
+ readonly dedupe?: string;
13
+ }
14
+ export interface Wake {
15
+ readonly id: string;
16
+ readonly job: string;
17
+ readonly reason: WakeReason;
18
+ readonly dueAt: Date;
19
+ /** How many failed runs moved this wake (`retry`). */
20
+ readonly attempt: number;
21
+ readonly dedupe: string | null;
22
+ /** Taken by the run that holds its job's lease, when that run took it: that run's finish consumes or retries it. */
23
+ readonly owned: boolean;
24
+ }
25
+ /**
26
+ * What a run's finish does with the wakes it owned (those due when it took the lease), applied in the finish's
27
+ * transaction and only when the finish still held the lease. Without one, a success is `completed` and a failure
28
+ * leaves the wakes as they are.
29
+ */
30
+ export type FinishWakes =
31
+ /** The run is done with them: they are consumed, then the job's next cron run is scheduled (`cron:<job>:<expression>`). */
32
+ {
33
+ readonly kind: 'completed';
34
+ /**
35
+ * With `scheduled`, the next fire is written only when the stored schedule (`keepSchedule`) declares its key, read
36
+ * in the finish's transaction: under a process schedule, a run of an older deploy writes no removed job's or
37
+ * changed expression's fire (ADR-0080).
38
+ */
39
+ readonly nextCron?: {
40
+ readonly expression: string;
41
+ readonly dueAt: Date;
42
+ readonly scheduled?: boolean;
43
+ };
44
+ }
45
+ /** The run failed and runs again: they move to `at`, and their attempt counts up. Only with a failed outcome. */
46
+ | {
47
+ readonly kind: 'retry';
48
+ readonly at: Date;
49
+ };
50
+ export interface JobWakes {
51
+ /**
52
+ * Records a pending wake, in `using` when given (the transaction of the write it belongs to). A key already pending
53
+ * keeps one row at the earlier due time: a later wake never postpones an earlier one. A merge takes the row from the
54
+ * run that owns it, except a cron wake's, whose next fire that run's finish schedules. Answers the row that holds it;
55
+ * a key another job holds is refused.
56
+ */
57
+ schedule(wake: NewWake, using?: Session): Promise<Wake>;
58
+ /** The pending wakes of `job`, earliest first. */
59
+ pending(job: string): Promise<readonly Wake[]>;
60
+ /**
61
+ * When the scheduler wakes next: the earliest due wake of a job whose lease is free or expired, or the expiry of a
62
+ * held lease (its deadman), whichever is earlier; `null` when neither exists. It may be past. Read in `using` when given;
63
+ * with `jobs`, of those jobs only, so a wake of a job this process does not run never holds its timer.
64
+ */
65
+ next(using?: Session, jobs?: readonly string[]): Promise<Date | null>;
66
+ /** How many milliseconds from the database's now `next` is (0 or less when due), read in `using` when given. */
67
+ untilNext(using?: Session, jobs?: readonly string[]): Promise<number | null>;
68
+ /**
69
+ * Where no crontab runs (ADR-0080), in one transaction: raises the stored schedule generation to `generation` when that
70
+ * one is higher in byte order, with the cron keys `fires` declare, and when `generation` is then the stored one,
71
+ * reconciles the wakes against `fires` (as `reconcile`) and adds each fire's wake under its job's cron key where none
72
+ * is pending (an existing one, overdue or not, is left as it is and not locked, so a lease taken meanwhile still owns
73
+ * it). Answers whether `generation` is the stored one; a process of an older one writes nothing. The generation's row stays
74
+ * locked until the transaction commits, so on Postgres a newer generation waits for an older one's seed and reconciles
75
+ * after it, and an older one queued behind a newer one reads the newer and writes nothing. A UUIDv7, lowercase: a
76
+ * later deploy's sorts later.
77
+ */
78
+ keepSchedule(generation: string, fires: readonly ScheduledFire[]): Promise<boolean>;
79
+ /** The database's clock, read in `using` when given: a wake due now is due by it. */
80
+ now(using?: Session): Promise<Date>;
81
+ /**
82
+ * Deletes the wakes of every job not in `declared`, the jobs the contract declares with their cron expressions, and
83
+ * each declared job's cron wake whose key names another expression; answers how many it deleted. In `using` when
84
+ * given.
85
+ */
86
+ reconcile(declared: readonly DeclaredJob[], using?: Session): Promise<number>;
87
+ /**
88
+ * The test kit's: moves each wake `ids` names that is not yet due to the database's now, so the scheduler takes it
89
+ * now; an overdue one stays. Answers how many it moved. Refused in a process that serves an application.
90
+ */
91
+ hasten(ids: readonly string[]): Promise<number>;
92
+ /**
93
+ * The jobs whose lease a run holds past its expiry, declared or not: a removed job's crashed holder still arms the
94
+ * alarm through `next` until someone reaps it.
95
+ */
96
+ expiredHolders(): Promise<readonly string[]>;
97
+ }
98
+ /** A declared job and its next fire, which `keepSchedule` seeds; `null` when its expression has none in the window. */
99
+ export interface ScheduledFire extends DeclaredJob {
100
+ readonly dueAt: Date | null;
101
+ }
102
+ /** A job the contract declares, and the cron expression its schedule is: its cron wake's key is `cron:<job>:<expression>`. */
103
+ export interface DeclaredJob {
104
+ readonly job: string;
105
+ readonly expression: string;
106
+ }
107
+ /**
108
+ * A finish's instruction checked before its statement runs, with the default filled in: `null` leaves the wakes. The
109
+ * lease store calls it, so a malformed instruction refuses the finish and leaves the lease held.
110
+ */
111
+ export declare function finishWakes(outcome: JobOutcome, wakes: FinishWakes | undefined): FinishWakes | null;
112
+ /**
113
+ * The lease store's projection, all in the lease statement's transaction: a taken lease marks the wakes its run owns, a
114
+ * fenced finish applies its wake instruction to them, a finish or a reap leaves none owned, and every lease change then
115
+ * runs the runtime's projection.
116
+ */
117
+ export declare function leaseProjection(runtime: () => DataLayerRuntime): LeaseProjection;
118
+ /**
119
+ * Sets the claim wake of `fence`'s job to `dueAt`, or removes it for `null`, in `transaction`: the claim's fenced
120
+ * transaction, so the re-arm commits with the rows it leased. The attempt's first claim replaces what an earlier run
121
+ * left; each later claim keeps the earliest re-arm of the attempt.
122
+ */
123
+ export declare function rearmClaim(runtime: DataLayerRuntime, transaction: Session, fence: LeaseFence, dueAt: Date | null): Promise<void>;
124
+ export declare function jobWakes(runtime: () => DataLayerRuntime): JobWakes;
@@ -0,0 +1,18 @@
1
+ /** A JSON value: what `JSON.parse` answers. An object member that is `undefined` is left out, as `JSON.stringify` does. */
2
+ export type JsonValue = string | number | boolean | null | readonly JsonValue[] | {
3
+ readonly [key: string]: JsonValue | undefined;
4
+ };
5
+ /** What a JSON column takes: a JSON value other than a top-level `null`, which the layer writes as SQL NULL. */
6
+ export type JsonColumnValue = Exclude<JsonValue, null>;
7
+ /** How deep a written value may nest; deeper is refused, and so is a value that contains itself. */
8
+ export declare const MAX_JSON_DEPTH = 64;
9
+ /**
10
+ * A written JSON column value as the text the layer binds: plain objects and arrays, strings, finite numbers, booleans
11
+ * and nested `null`, read through own data properties only, so no `toJSON`, getter or method of the value runs.
12
+ */
13
+ export declare function jsonInput(value: unknown, where: string): string;
14
+ /**
15
+ * A SQLite JSON column's stored value as Postgres's driver answers `jsonb`: its text parsed. A `JSONB` column has
16
+ * NUMERIC affinity, so a written number comes back as a number, which is that JSON value already.
17
+ */
18
+ export declare function sqliteJson(value: unknown, where: string): unknown;
@@ -0,0 +1,13 @@
1
+ import { type Session } from './database';
2
+ /** An order column's value as the database prints it: exact, where a `Date` would drop microseconds. */
3
+ export type CursorValue = string | null;
4
+ /** The database's cursor key, read in `session`; the framework migration wrote it, so its absence is no caller's fault. */
5
+ export declare function cursorKey(session: Session): Promise<CryptoKey>;
6
+ /** The cursor of the page after the row whose order values are `values`, in the list `list` names. */
7
+ export declare function signCursor(key: () => Promise<CryptoKey>, list: string, values: readonly CursorValue[]): Promise<string>;
8
+ /**
9
+ * The order values of `after` when it is a cursor this database signed for the list `list` names, with one plain value
10
+ * per order column (`count`). Anything else is the caller's `list_cursor`: undecodable, unsigned, edited, of another
11
+ * list or order, or of another shape.
12
+ */
13
+ export declare function openCursor(key: () => Promise<CryptoKey>, list: string, after: unknown, count: number): Promise<readonly CursorValue[]>;
@@ -0,0 +1,4 @@
1
+ import { type FrameworkMigration } from './migrations';
2
+ /** The `strftime` format of a stored timestamp; `strftime(SQLITE_NOW_FORMAT, 'now')` is the database's clock. */
3
+ export declare const SQLITE_NOW_FORMAT = "%Y-%m-%dT%H:%M:%fZ";
4
+ export declare const SQLITE_FRAMEWORK_MIGRATIONS: readonly FrameworkMigration[];
@@ -4,12 +4,16 @@ export declare const WEBHOOK_BINDINGS_TABLE = "fabrika_webhook_bindings";
4
4
  export declare const WEBHOOK_DELIVERIES_TABLE = "fabrika_webhook_deliveries";
5
5
  export declare const JOB_LEASES_TABLE = "fabrika_job_leases";
6
6
  export declare const JOB_KICKS_TABLE = "fabrika_job_kicks";
7
+ export declare const JOB_WAKES_TABLE = "fabrika_wakes";
8
+ export declare const JOB_SCHEDULE_TABLE = "fabrika_job_schedule";
7
9
  export declare const FORM_ADMISSIONS_TABLE = "fabrika_form_admissions";
8
10
  export declare const FORM_CHALLENGES_TABLE = "fabrika_form_challenges";
9
11
  export declare const FORM_FILES_TABLE = "fabrika_form_files";
10
12
  export declare const FORM_BYTES_TABLE = "fabrika_form_bytes";
11
13
  export declare const FILES_TABLE = "fabrika_files";
12
14
  export declare const FILE_DELETIONS_TABLE = "fabrika_file_deletions";
15
+ export declare const REQUEST_RECEIPTS_TABLE = "fabrika_request_receipts";
16
+ export declare const LIST_CURSOR_KEY_TABLE = "fabrika_list_cursor_key";
13
17
  /** The function an application's last adoption migration calls with the name of a file collection it adopted. */
14
18
  export declare const FILES_RELEASE_FUNCTION = "fabrika_files_release";
15
19
  /**
@@ -1,5 +1,6 @@
1
1
  import { type DeleteQueryNode, type InsertQueryNode, type OperationNode, ReferenceNode, ReturningNode, type SelectQueryNode, type UpdateQueryNode, WhereNode } from 'kysely';
2
2
  import { type NameSet } from './builtins';
3
+ import type { SqlDialect } from './database';
3
4
  import type { Condition, Primitive, SelectState } from './description';
4
5
  export declare function column(table: string, name: string): ReferenceNode;
5
6
  export declare function equals(table: string, name: string, value: Primitive): OperationNode;
@@ -7,6 +8,8 @@ export declare function allOf(nodes: readonly OperationNode[]): OperationNode;
7
8
  /** One node, or the OR of several in a parenthesis: inside an AND, `a and b or c` would read as `(a and b) or c`. */
8
9
  export declare function anyOf(nodes: readonly OperationNode[]): OperationNode;
9
10
  export declare function inList(table: string, name: string, values: readonly string[]): OperationNode;
11
+ /** `($1, $2, …)`: bound values, as the right operand of an `in`. */
12
+ export declare function valueList(values: readonly string[]): OperationNode;
10
13
  /** The scope of a `Within` that is not limited to scope values. */
11
14
  export declare function everything(): OperationNode;
12
15
  /** LIKE treats `\` as its escape character by default, so the text matches literally. */
@@ -19,7 +22,7 @@ export declare function scopedWhere(conditions: OperationNode | undefined, scope
19
22
  /** `returning key as id[, version as version]`: a mutation's acknowledgement, never row data. */
20
23
  export declare function acknowledgement(table: string, key: string, version: string | undefined): ReturningNode;
21
24
  /** `after` is a keyset page's position, ANDed to the caller's conditions inside their parenthesis. */
22
- export declare function selectNode(state: SelectState, visible: readonly string[], scope: OperationNode, after?: OperationNode, days?: NameSet): SelectQueryNode;
25
+ export declare function selectNode(state: SelectState, visible: readonly string[], scope: OperationNode, after?: OperationNode, days?: NameSet, dialect?: SqlDialect): SelectQueryNode;
23
26
  export interface AggregateColumns {
24
27
  readonly groupBy: readonly string[];
25
28
  readonly count: boolean;
@@ -38,6 +41,8 @@ export declare function existsNode(table: string, key: string, scope: OperationN
38
41
  export declare function acknowledgementNode(table: string, key: string, version: string | undefined, where: WhereNode): SelectQueryNode;
39
42
  /** `select columns from table where scope limit 1`: the containment columns of one object, for the framework's locator. */
40
43
  export declare function locateNode(table: string, columns: readonly string[], scope: OperationNode): SelectQueryNode;
44
+ /** `select T.<name> from T where <scope> group by T.<name>`: each value of `name` the scoped rows hold, once. */
45
+ export declare function valuesNode(table: string, name: string, scope: OperationNode): SelectQueryNode;
41
46
  /**
42
47
  * The same check, locked: `for share` keeps the row from moving until the transaction that checked it ends, `for
43
48
  * update` also keeps every other writer and locker of it waiting.
@@ -57,6 +62,16 @@ export declare function claimNode(state: SelectState, columns: readonly string[]
57
62
  readonly attempts: string;
58
63
  readonly now: Date;
59
64
  readonly maxAttempts: number;
60
- }, scope: OperationNode, days: NameSet): SelectQueryNode;
65
+ }, scope: OperationNode, days: NameSet, dialect?: SqlDialect): SelectQueryNode;
66
+ /**
67
+ * When the same claim next finds a row: `select <due> from table where (<conditions> and (<due> > $now and <attempts> <
68
+ * $max)) and scope order by <due> limit 1`, with `state` the claim's conditions ordered by `<due>`, limited to one.
69
+ */
70
+ export declare function nextClaimNode(state: SelectState, due: {
71
+ readonly due: string;
72
+ readonly attempts: string;
73
+ readonly now: Date;
74
+ readonly maxAttempts: number;
75
+ }, scope: OperationNode, days: NameSet, dialect?: SqlDialect): SelectQueryNode;
61
76
  /** `select <columns> from table where scope for update`: a mutation's precondition read of its own target. */
62
77
  export declare function lockedSelectNode(table: string, columns: readonly string[], scope: OperationNode, days?: NameSet): SelectQueryNode;