@fabrika/db 0.9.0-cloudflare.3 → 0.9.0-dev.10
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/package.json +4 -4
- package/src/codegen-sqlite.ts +53 -8
- package/src/codegen.ts +120 -28
- package/src/description.ts +34 -8
- package/src/errors.ts +4 -2
- package/src/file-columns.ts +32 -8
- package/src/index.ts +1 -0
- package/src/json.ts +124 -0
- package/src/orm-types.ts +3 -3
- package/src/orm.ts +27 -3
- package/src/policy.ts +11 -2
- package/src/sql.ts +16 -6
- package/src/store.ts +22 -9
- package/src/temporal.ts +8 -1
- package/src/testing-shared.ts +185 -40
- package/src/testing-sqlite.ts +58 -1
- package/src/testing.ts +89 -4
- package/types/src/codegen-sqlite.d.ts +8 -1
- package/types/src/codegen.d.ts +40 -9
- package/types/src/description.d.ts +23 -8
- package/types/src/errors.d.ts +3 -2
- package/types/src/file-columns.d.ts +4 -2
- package/types/src/index.d.ts +1 -0
- package/types/src/json.d.ts +18 -0
- package/types/src/orm-types.d.ts +4 -4
- package/types/src/orm.d.ts +5 -0
- package/types/src/policy.d.ts +4 -0
- package/types/src/store.d.ts +4 -4
- package/types/src/temporal.d.ts +4 -1
- package/types/src/testing-shared.d.ts +52 -3
package/types/src/codegen.d.ts
CHANGED
|
@@ -7,6 +7,8 @@ export interface ScalarType {
|
|
|
7
7
|
readonly select: string;
|
|
8
8
|
readonly write?: string;
|
|
9
9
|
}
|
|
10
|
+
/** A JSON column: a read answers the parsed value, which the handler parses with a schema; a write binds a JSON value. */
|
|
11
|
+
export declare const JSON_COLUMN: ScalarType;
|
|
10
12
|
export declare class CodegenError extends Error {
|
|
11
13
|
name: string;
|
|
12
14
|
}
|
|
@@ -22,6 +24,9 @@ declare const catalogColumnSchema: z.ZodObject<{
|
|
|
22
24
|
no: "no";
|
|
23
25
|
always: "always";
|
|
24
26
|
}>;
|
|
27
|
+
computed: z.ZodBoolean;
|
|
28
|
+
formatted_type: z.ZodString;
|
|
29
|
+
keyed: z.ZodBoolean;
|
|
25
30
|
enum_labels: z.ZodArray<z.ZodString>;
|
|
26
31
|
}, z.core.$strip>;
|
|
27
32
|
export type CatalogColumn = z.infer<typeof catalogColumnSchema>;
|
|
@@ -46,13 +51,36 @@ export interface Catalog {
|
|
|
46
51
|
export declare function introspectSchema(url: string, schema: string, objects: readonly DatabaseObject[]): Promise<readonly CatalogColumn[]>;
|
|
47
52
|
/** `introspectSchema`, with the foreign keys between the schema's tables. */
|
|
48
53
|
export declare function introspectCatalog(url: string, schema: string, objects: readonly DatabaseObject[]): Promise<Catalog>;
|
|
54
|
+
/** `table.column`: how a message names a column. */
|
|
55
|
+
export declare function columnPath(column: NamedColumn): string;
|
|
49
56
|
/** What the renderer needs of a column beyond its name, whichever database it was read from. */
|
|
50
57
|
export interface DescribedColumn {
|
|
51
58
|
readonly scalar: ScalarType;
|
|
52
59
|
readonly nullable: boolean;
|
|
53
60
|
readonly generated: 'no' | 'default' | 'always';
|
|
54
|
-
/** The column list field that names the column: a day, a timestamp, or (on SQLite) a boolean. */
|
|
55
|
-
readonly list: 'dates' | 'timestamps' | 'booleans' | undefined;
|
|
61
|
+
/** The column list field that names the column: a day, a timestamp, a JSON column, or (on SQLite) a boolean. */
|
|
62
|
+
readonly list: 'dates' | 'timestamps' | 'booleans' | 'json' | undefined;
|
|
63
|
+
}
|
|
64
|
+
/** A column `describe` leaves out of the module: a generated column of a type the data layer does not read. */
|
|
65
|
+
export interface LeftOut {
|
|
66
|
+
/** The column's type, as its author wrote it. */
|
|
67
|
+
readonly leftOut: string;
|
|
68
|
+
}
|
|
69
|
+
/** A column the module leaves out; only `ctx.sql` reaches it. */
|
|
70
|
+
export interface LeftOutColumn {
|
|
71
|
+
readonly table: string;
|
|
72
|
+
readonly column: string;
|
|
73
|
+
/** Its type, as its author wrote it. */
|
|
74
|
+
readonly type: string;
|
|
75
|
+
}
|
|
76
|
+
/** What codegen says of a left-out column: in the module, `name` is the column; in its output, `table.column`. */
|
|
77
|
+
export declare function leftOutText(name: string, type: string): string;
|
|
78
|
+
/** Why a left-out column refuses the schema: the table would lose a key, or a foreign key a column. */
|
|
79
|
+
export declare function leftOutRefusal(path: string, what: string): CodegenError;
|
|
80
|
+
/** The text of `SCHEMA_FILE`, and the columns it leaves out, for the command to name. */
|
|
81
|
+
export interface GeneratedModule {
|
|
82
|
+
readonly source: string;
|
|
83
|
+
readonly leftOut: readonly LeftOutColumn[];
|
|
56
84
|
}
|
|
57
85
|
/** A foreign key as the renderer reads it: the columns of `table_name` that reference `referenced_table`. */
|
|
58
86
|
export interface ForeignKeyColumns {
|
|
@@ -68,15 +96,18 @@ export interface NamedColumn {
|
|
|
68
96
|
}
|
|
69
97
|
/**
|
|
70
98
|
* The generated module: one interface per application table, the `DB` map Kysely and `defineTables` take, and the
|
|
71
|
-
* runtime column list with each table's foreign keys to application tables
|
|
72
|
-
* `fabrika db codegen --verify` can compare text.
|
|
99
|
+
* runtime column list with each table's foreign keys to application tables; with the columns it leaves out.
|
|
100
|
+
* Deterministic for a given catalog, so `fabrika db codegen --verify` can compare text.
|
|
73
101
|
*/
|
|
74
|
-
export declare function renderSchema(catalog: readonly CatalogColumn[], foreignKeys?: readonly CatalogForeignKey[]):
|
|
102
|
+
export declare function renderSchema(catalog: readonly CatalogColumn[], foreignKeys?: readonly CatalogForeignKey[]): GeneratedModule;
|
|
75
103
|
/**
|
|
76
|
-
* `renderSchema` over columns of any database: `describe` gives each column's types and list field,
|
|
77
|
-
*
|
|
104
|
+
* `renderSchema` over columns of any database: `describe` gives each column's types and list field, refuses a type the
|
|
105
|
+
* data layer does not read, or answers `LeftOut` for a generated column of such a type. That column is left out of the
|
|
106
|
+
* module but for a comment where it stands, so no handle reads or writes it and only `ctx.sql` reaches it; a foreign
|
|
107
|
+
* key that names it, and a table it would leave without a column, are refused. A foreign key's `constraint_name` is
|
|
108
|
+
* not rendered; keys keep the given order.
|
|
78
109
|
*/
|
|
79
|
-
export declare function renderTables<C extends NamedColumn>(catalog: readonly C[], foreignKeys: readonly ForeignKeyColumns[], describe: (column: C) => DescribedColumn):
|
|
110
|
+
export declare function renderTables<C extends NamedColumn>(catalog: readonly C[], foreignKeys: readonly ForeignKeyColumns[], describe: (column: C) => DescribedColumn | LeftOut): GeneratedModule;
|
|
80
111
|
/** Introspects the migrated schema, checked against the migrations' manifest, and renders the module for `SCHEMA_FILE`. */
|
|
81
|
-
export declare function generateSchema(url: string, schema: string, objects: readonly DatabaseObject[]): Promise<
|
|
112
|
+
export declare function generateSchema(url: string, schema: string, objects: readonly DatabaseObject[]): Promise<GeneratedModule>;
|
|
82
113
|
export {};
|
|
@@ -29,6 +29,8 @@ export interface TableShape {
|
|
|
29
29
|
readonly joinable: Readonly<Record<string, JoinShape>>;
|
|
30
30
|
/** The `date` columns, which a read answers as `YYYY-MM-DD` text. */
|
|
31
31
|
readonly dates: NameSet;
|
|
32
|
+
/** The JSON columns, which a query selects but never compares or orders by. */
|
|
33
|
+
readonly json: NameSet;
|
|
32
34
|
}
|
|
33
35
|
export interface JoinShape {
|
|
34
36
|
readonly shape: TableShape;
|
|
@@ -60,17 +62,28 @@ export interface SelectState {
|
|
|
60
62
|
}
|
|
61
63
|
type Comparable<V> = Exclude<V, null | undefined>;
|
|
62
64
|
type Columns<Row> = keyof Row & string;
|
|
65
|
+
/** The columns a condition or an order may name: every column but a JSON one, whose read type is `unknown`. */
|
|
66
|
+
export type ComparableColumn<Row> = {
|
|
67
|
+
[K in Columns<Row>]: unknown extends Row[K] ? never : K;
|
|
68
|
+
}[Columns<Row>];
|
|
63
69
|
type StringColumn<Row> = {
|
|
64
70
|
[K in Columns<Row>]: Comparable<Row[K]> extends string ? K : never;
|
|
65
71
|
}[Columns<Row>];
|
|
66
72
|
type NullableColumn<Row> = {
|
|
67
|
-
[K in
|
|
68
|
-
}[
|
|
73
|
+
[K in ComparableColumn<Row>]: null extends Row[K] ? K : never;
|
|
74
|
+
}[ComparableColumn<Row>];
|
|
75
|
+
/**
|
|
76
|
+
* A `[column, operator, value]` condition on `Row`'s columns. A null test (`is`, `is not`) takes a nullable column only;
|
|
77
|
+
* the runtime knows no column's nullability, so an untyped condition that tests a column never null runs and matches no
|
|
78
|
+
* row (`is`) or every row (`is not`).
|
|
79
|
+
*/
|
|
69
80
|
export type ConditionTuple<Row> = {
|
|
70
|
-
[K in
|
|
71
|
-
}[
|
|
81
|
+
[K in ComparableColumn<Row>]: readonly [K, ComparisonOperator, Comparable<Row[K]>] | readonly [K, ListOperator, readonly Comparable<Row[K]>[]];
|
|
82
|
+
}[ComparableColumn<Row>] | {
|
|
72
83
|
[K in StringColumn<Row>]: readonly [K, PatternOperator | 'contains', string];
|
|
73
|
-
}[StringColumn<Row>]
|
|
84
|
+
}[StringColumn<Row>] | {
|
|
85
|
+
[K in NullableColumn<Row>]: readonly [K, NullOperator, null];
|
|
86
|
+
}[NullableColumn<Row>];
|
|
74
87
|
type Prefixed<C extends string, J> = {
|
|
75
88
|
[K in keyof J & string as `${C}.${K}`]: J[K];
|
|
76
89
|
};
|
|
@@ -84,15 +97,15 @@ export declare class ScopedSelect<Row, Selected, Children> {
|
|
|
84
97
|
constructor(token: symbol, state: SelectState, shape: TableShape);
|
|
85
98
|
/** The columns to return; without it, every visible column. */
|
|
86
99
|
columns<const C extends Columns<Row>>(columns: readonly C[]): ScopedSelect<Row, Pick<Row, C>, Children>;
|
|
87
|
-
where<C extends
|
|
88
|
-
where<C extends
|
|
100
|
+
where<C extends ComparableColumn<Row>>(column: C, operator: ComparisonOperator, value: Comparable<Row[C]>): ScopedSelect<Row, Selected, Children>;
|
|
101
|
+
where<C extends ComparableColumn<Row>>(column: C, operator: ListOperator, values: readonly Comparable<Row[C]>[]): ScopedSelect<Row, Selected, Children>;
|
|
89
102
|
where<C extends StringColumn<Row>>(column: C, operator: PatternOperator, pattern: string): ScopedSelect<Row, Selected, Children>;
|
|
90
103
|
where<C extends NullableColumn<Row>>(column: C, operator: NullOperator, value: null): ScopedSelect<Row, Selected, Children>;
|
|
91
104
|
/** One OR group of conditions on this table's columns. */
|
|
92
105
|
whereAny(conditions: readonly ConditionTuple<Row>[]): ScopedSelect<Row, Selected, Children>;
|
|
93
106
|
/** A case-insensitive substring match in which `%` and `_` in the text match themselves. */
|
|
94
107
|
contains(column: StringColumn<Row>, text: string): ScopedSelect<Row, Selected, Children>;
|
|
95
|
-
orderBy(column:
|
|
108
|
+
orderBy(column: ComparableColumn<Row>, direction?: 'asc' | 'desc'): ScopedSelect<Row, Selected, Children>;
|
|
96
109
|
limit(limit: number): ScopedSelect<Row, Selected, Children>;
|
|
97
110
|
offset(offset: number): ScopedSelect<Row, Selected, Children>;
|
|
98
111
|
/** An inner join to a declared child; its columns come back prefixed (`note_comments.body`). */
|
|
@@ -100,6 +113,8 @@ export declare class ScopedSelect<Row, Selected, Children> {
|
|
|
100
113
|
}
|
|
101
114
|
/** A column the shape lets a query name; a hidden one is refused like a missing one. */
|
|
102
115
|
export declare function columnOf(shape: TableShape, name: unknown): string;
|
|
116
|
+
/** A column the shape lets a query compare, order or aggregate by: `columnOf`, and never a JSON column. */
|
|
117
|
+
export declare function comparableColumnOf(shape: TableShape, name: unknown, use: string): string;
|
|
103
118
|
/** One `[column, operator, value]` condition over a caller's values, checked before anything reads it further. */
|
|
104
119
|
export declare function parseCondition(shape: TableShape, column: unknown, operator: unknown, value: unknown): Compare | Contains;
|
|
105
120
|
export declare function startSelect<Row, Children>(shape: TableShape): ScopedSelect<Row, Row, Children>;
|
package/types/src/errors.d.ts
CHANGED
|
@@ -22,11 +22,12 @@ export declare class CapabilityError extends Error {
|
|
|
22
22
|
}
|
|
23
23
|
/**
|
|
24
24
|
* Why the layer refused, as a closed catalog: a server log names the reason and its fixed text, never the message,
|
|
25
|
-
* which can quote a value the request sent.
|
|
25
|
+
* which can quote a value the request sent. Each text is one string literal, however long: a concatenation keeps the
|
|
26
|
+
* whole catalog in an SPA bundle that imports this module (`web/__tests__/bundle.test.ts`).
|
|
26
27
|
*/
|
|
27
28
|
export declare const QUERY_REFUSALS: {
|
|
28
29
|
readonly invalid_argument: "a data-layer call took an argument of another shape than its type declares";
|
|
29
|
-
readonly invalid_value: "a value cannot be bound:
|
|
30
|
+
readonly invalid_value: "a value cannot be bound: undefined, a function, symbol or object of a kind the database does not bind, a list item other than a string or finite number, a date or timestamp that is neither a valid Date nor well-formed text or lies out of range, a non-finite number, or on SQLite a bigint outside the safe integer range";
|
|
30
31
|
readonly invalid_name: "a configured name (application, schema, table or file column) breaks its naming rule";
|
|
31
32
|
readonly unknown_column: "a column the table does not declare, or one this operation may not set";
|
|
32
33
|
readonly unknown_table: "a table src/db/tables.ts does not declare, or one no store, join or locator reaches";
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type NameSet } from './builtins';
|
|
1
2
|
import { type Session } from './database';
|
|
2
3
|
import type { Primitive } from './description';
|
|
3
4
|
import type { TableModel } from './policy';
|
|
@@ -14,9 +15,10 @@ export interface FileBinding {
|
|
|
14
15
|
}
|
|
15
16
|
/**
|
|
16
17
|
* Puts a file reference in each file column of `rows`, read with `action` in `session`: one statement loads every
|
|
17
|
-
* file's metadata. Without a binding (a store's own runner) the columns keep their ids.
|
|
18
|
+
* file's metadata. Without a binding (a store's own runner) the columns keep their ids. `held` (a queue claim's) adds
|
|
19
|
+
* the actions the site holds over the whole application: a reference is readable when one of them reads the table.
|
|
18
20
|
*/
|
|
19
|
-
export declare function answerFiles<R>(model: TableModel, binding: FileBinding | undefined, session: Session, rows: R[], action: string): Promise<R[]>;
|
|
21
|
+
export declare function answerFiles<R>(model: TableModel, binding: FileBinding | undefined, session: Session, rows: R[], action: string, held?: NameSet): Promise<R[]>;
|
|
20
22
|
/**
|
|
21
23
|
* A write's value for a file column: `null`, or the id of a file reference of the column's kind. A string id, a copied
|
|
22
24
|
* object or a reference of another kind is refused; whether the site holds it is checked where the write runs.
|
package/types/src/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export { MAX_WITHIN_VALUES } from './capability';
|
|
|
3
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 { JsonColumnValue, JsonValue } from './json';
|
|
6
7
|
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';
|
|
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';
|
|
@@ -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;
|
package/types/src/orm-types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Selectable, Updateable } from 'kysely';
|
|
2
2
|
import type { RowRef } from './capability';
|
|
3
|
-
import type { ConditionTuple } from './description';
|
|
3
|
+
import type { ComparableColumn, ConditionTuple } from './description';
|
|
4
4
|
import type { FileReference } from './file-references';
|
|
5
5
|
import type { ActionOf, ApplicationTableName, ChildTableName, ContainerOf, DimensionOf, DimensionTableName, InsertValues, ListDimensionOf, ParentOf, Tables, UpdateValues } from './policy';
|
|
6
6
|
import type { AggregateRow, AggregateSpec } from './store';
|
|
@@ -269,7 +269,7 @@ type InsertValuesOf<E extends IndexedTable> = {
|
|
|
269
269
|
/** `onConflict` of an insert: the columns of a unique index the migrations create, and what a conflict does. */
|
|
270
270
|
export interface InsertConflict<E extends IndexedTable, M extends 'nothing' | 'update'> {
|
|
271
271
|
readonly onConflict: {
|
|
272
|
-
readonly columns: readonly
|
|
272
|
+
readonly columns: readonly ComparableColumn<E['row']>[];
|
|
273
273
|
readonly do: M;
|
|
274
274
|
};
|
|
275
275
|
}
|
|
@@ -343,8 +343,8 @@ export interface ListPage<Row> {
|
|
|
343
343
|
readonly next: string | null;
|
|
344
344
|
}
|
|
345
345
|
export type OrderTerm<Row> = {
|
|
346
|
-
[C in
|
|
347
|
-
}[
|
|
346
|
+
[C in ComparableColumn<Row>]: readonly [C, 'asc' | 'desc'];
|
|
347
|
+
}[ComparableColumn<Row>];
|
|
348
348
|
export interface ListOptions<Row> {
|
|
349
349
|
readonly where?: readonly ConditionTuple<Row>[];
|
|
350
350
|
readonly orderBy?: readonly OrderTerm<Row>[];
|
package/types/src/orm.d.ts
CHANGED
|
@@ -28,6 +28,11 @@ export interface DataSite {
|
|
|
28
28
|
* only one it holds. Absent where the framework serves no file; the columns then read as ids and refuse every write.
|
|
29
29
|
*/
|
|
30
30
|
readonly files?: FileBinding;
|
|
31
|
+
/**
|
|
32
|
+
* The actions a job holds over the whole application: those it declares that its key's token carries. A queue claim
|
|
33
|
+
* answers a file reference its holder may open when one of them reads the table, as a re-read of the row would.
|
|
34
|
+
*/
|
|
35
|
+
readonly holds?: readonly string[];
|
|
31
36
|
/** The texts the verified signed tokens of a public procedure's request carry: the row ids it may update or remove. */
|
|
32
37
|
readonly carried?: ReadonlySet<string>;
|
|
33
38
|
/** Throws unless the work running now is the invocation these handles were made for. */
|
package/types/src/policy.d.ts
CHANGED
|
@@ -134,6 +134,8 @@ export interface TableColumns<Col extends string = string, Table extends string
|
|
|
134
134
|
readonly timestamps?: readonly Col[];
|
|
135
135
|
/** On SQLite, the columns declared `BOOLEAN`, stored as 0 or 1 and read as a boolean; absent when none. */
|
|
136
136
|
readonly booleans?: readonly Col[];
|
|
137
|
+
/** The JSON columns (`jsonb`, or declared `JSONB` on SQLite), written as a JSON value and never compared; absent when none. */
|
|
138
|
+
readonly json?: readonly Col[];
|
|
137
139
|
}
|
|
138
140
|
/** The columns and foreign keys of every table, generated next to the schema types. */
|
|
139
141
|
export type ColumnList<DB> = {
|
|
@@ -206,6 +208,8 @@ export interface TableModel {
|
|
|
206
208
|
readonly timestamps: NameSet;
|
|
207
209
|
/** On SQLite, the `BOOLEAN` columns, stored as 0 or 1. */
|
|
208
210
|
readonly booleans: NameSet;
|
|
211
|
+
/** The JSON columns: a write binds a JSON value's text, and no condition, order or aggregate names one. */
|
|
212
|
+
readonly json: NameSet;
|
|
209
213
|
/** The table's foreign keys, from the column list; a containment column must be one to its container's key. */
|
|
210
214
|
readonly foreignKeys: readonly ForeignKey[];
|
|
211
215
|
/**
|
package/types/src/store.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { type OperationNode, type ReturningNode } from 'kysely';
|
|
|
2
2
|
import { type NameSet } from './builtins';
|
|
3
3
|
import { type AppGrant, type CapabilityAuthority, type Ref, type RefGrant, type Within, type WithinGrant } from './capability';
|
|
4
4
|
import { type Database, type Session, type SqlDialect } from './database';
|
|
5
|
-
import { type Compare, type Contains, type NoColumns, type Primitive, type ScopedSelect, type TableShape } from './description';
|
|
5
|
+
import { type ComparableColumn, type Compare, type Contains, type NoColumns, type Primitive, type ScopedSelect, type TableShape } from './description';
|
|
6
6
|
import { type FileBinding } from './file-columns';
|
|
7
7
|
import type { ForeignKeyPair, GuardContext, RootKind } from './guard';
|
|
8
8
|
import { type Acknowledgement, type ActionOf, type ChildTableName, type Container, type ContainerOf, type DimensionOf, type DimensionTableName, type InsertValues, type JoinableChildren, type ListDimensionOf, type MoveAcknowledgement, type Operation, type ParentOf, type PolicyRow, type TableModel, type TableModels, type Tables, type UpdateValues, type VersionArguments } from './policy';
|
|
@@ -206,11 +206,11 @@ type NumericColumn<Row> = {
|
|
|
206
206
|
[K in Columns<Row>]: Exclude<Row[K], null> extends number | bigint | string ? K : never;
|
|
207
207
|
}[Columns<Row>];
|
|
208
208
|
export interface AggregateSpec<Row> {
|
|
209
|
-
readonly groupBy?: readonly
|
|
209
|
+
readonly groupBy?: readonly ComparableColumn<Row>[];
|
|
210
210
|
readonly count?: boolean;
|
|
211
211
|
readonly sum?: readonly NumericColumn<Row>[];
|
|
212
|
-
readonly min?: readonly
|
|
213
|
-
readonly max?: readonly
|
|
212
|
+
readonly min?: readonly ComparableColumn<Row>[];
|
|
213
|
+
readonly max?: readonly ComparableColumn<Row>[];
|
|
214
214
|
readonly where?: (q: ScopedSelect<Row, Row, NoColumns>) => ScopedSelect<Row, unknown, NoColumns>;
|
|
215
215
|
}
|
|
216
216
|
type Listed<S, K extends 'groupBy' | 'sum' | 'min' | 'max'> = S extends {
|
package/types/src/temporal.d.ts
CHANGED
|
@@ -25,9 +25,12 @@ export interface RowColumns {
|
|
|
25
25
|
readonly timestamps: NameSet;
|
|
26
26
|
/** Booleans: `true` or `false` (SQLite answers 1 or 0). */
|
|
27
27
|
readonly booleans: NameSet;
|
|
28
|
+
/** JSON columns: the parsed value (SQLite answers its text). */
|
|
29
|
+
readonly json: NameSet;
|
|
28
30
|
}
|
|
29
31
|
/**
|
|
30
32
|
* Every row of a read as the layer answers it, in place: each day as `YYYY-MM-DD` text, and on SQLite each timestamp as
|
|
31
|
-
* a `Date
|
|
33
|
+
* a `Date`, each boolean as `true` or `false` and each JSON column as its parsed value, so a handler reads the same
|
|
34
|
+
* values on both dialects.
|
|
32
35
|
*/
|
|
33
36
|
export declare function answerRows<R>(dialect: SqlDialect, table: string, columns: RowColumns, rows: R[]): R[];
|
|
@@ -4,6 +4,11 @@ import { type Tables } from './policy';
|
|
|
4
4
|
import type { TableProbe } from './store';
|
|
5
5
|
/** A value a test row holds in a column; `null` for a nullable column the fixture left empty. */
|
|
6
6
|
export type SampleValue = Primitive | null;
|
|
7
|
+
/**
|
|
8
|
+
* A seeded value as a backend binds it: a JSON column's value as the JSON text the layer would write for it, so a
|
|
9
|
+
* seeded row and the generated cases that write the same value through the layer hold the same JSON.
|
|
10
|
+
*/
|
|
11
|
+
export declare function seedBinding(columns: readonly SeedColumn[], table: string, name: string, value: SampleValue): SampleValue;
|
|
7
12
|
/** One seeded row and where it lies. */
|
|
8
13
|
export interface WorldRow {
|
|
9
14
|
/** The row's key: the dimension value of a dimension table's row, a child's own key. */
|
|
@@ -105,8 +110,14 @@ export interface TestSeeding {
|
|
|
105
110
|
* the markers it holds.
|
|
106
111
|
*/
|
|
107
112
|
seedUnder<DB, P>(tables: Tables<DB, P>, table: string, under: WorldRow): Promise<SeededRow>;
|
|
108
|
-
/**
|
|
109
|
-
|
|
113
|
+
/**
|
|
114
|
+
* Values for the policy's insert columns of `table` that its schema accepts: every required one, sampled; a file
|
|
115
|
+
* column a seeded file. `beside` is a row `seedWorlds` seeded that the inserted row will lie beside, in the same
|
|
116
|
+
* containers. A number column a unique index covers takes the next number above the largest the table holds now in the
|
|
117
|
+
* row's group (the index's other columns as the row will have them, its containers' from `beside`), so insert the
|
|
118
|
+
* values before taking the next sample, or the two share it.
|
|
119
|
+
*/
|
|
120
|
+
sampleInsert<DB, P>(tables: Tables<DB, P>, table: string, beside?: WorldRow): Promise<Readonly<Record<string, SampleValue>>>;
|
|
110
121
|
/**
|
|
111
122
|
* The object key of every file the fixture seeded into a file column, oldest first. Each stands for an empty object,
|
|
112
123
|
* which a test's object store holds when a handler serves or opens the file.
|
|
@@ -134,6 +145,10 @@ export interface SeedColumn {
|
|
|
134
145
|
readonly text: boolean;
|
|
135
146
|
/** A uuid type: a key or containment column of it holds a random uuid as its scope value. */
|
|
136
147
|
readonly uuid: boolean;
|
|
148
|
+
/** A number type: where a unique index covers it, the fixture writes the next number of the row's group instead of its sample. */
|
|
149
|
+
readonly number: boolean;
|
|
150
|
+
/** A JSON column (`jsonb`, `JSONB`): its value is a JSON value, bound as the layer binds it (`seedBinding`). */
|
|
151
|
+
readonly json: boolean;
|
|
137
152
|
/** A sample of the column's type for a required column the test does not care about; a `SeedLimitError` for a type it cannot fill. */
|
|
138
153
|
readonly sample: () => Primitive;
|
|
139
154
|
}
|
|
@@ -145,6 +160,17 @@ export interface CheckConstraint {
|
|
|
145
160
|
/** The values of a one-column `IN (…)` list the fixture writes in its place, first one first; empty for any other CHECK. */
|
|
146
161
|
readonly values: readonly string[];
|
|
147
162
|
}
|
|
163
|
+
/**
|
|
164
|
+
* A unique index of the schema (a primary key's or a UNIQUE constraint's included), by its key columns. Only an index of
|
|
165
|
+
* plain columns with no predicate is one: the fixture cannot tell a partial index's rows or an expression's values.
|
|
166
|
+
*/
|
|
167
|
+
export interface UniqueIndex {
|
|
168
|
+
readonly name: string;
|
|
169
|
+
readonly table: string;
|
|
170
|
+
readonly columns: readonly string[];
|
|
171
|
+
/** `NULLS NOT DISTINCT`: a null in a key column collides with another row's null there. */
|
|
172
|
+
readonly nullsNotDistinct: boolean;
|
|
173
|
+
}
|
|
148
174
|
/** A live, empty file of `kind`, as the framework's put leaves one once a reference claims it. */
|
|
149
175
|
export interface SeededFile {
|
|
150
176
|
readonly id: string;
|
|
@@ -167,7 +193,18 @@ export interface SeedingBackend {
|
|
|
167
193
|
readonly columns: readonly SeedColumn[];
|
|
168
194
|
/** Every CHECK constraint of the schema's tables; read once, on the first column that needs them. */
|
|
169
195
|
checks(): Promise<readonly CheckConstraint[]>;
|
|
170
|
-
/**
|
|
196
|
+
/** Every unique index of plain columns and no predicate of the schema's tables; read once, on the first column that needs them. */
|
|
197
|
+
uniqueIndexes(): Promise<readonly UniqueIndex[]>;
|
|
198
|
+
/**
|
|
199
|
+
* The smallest whole number above every value `column` holds in the rows of `table` that match one of `groups`
|
|
200
|
+
* (`groupsWhere`), and at least 1, as the column's type holds it; `undefined` when the type holds no such number, or
|
|
201
|
+
* the largest is no finite number.
|
|
202
|
+
*/
|
|
203
|
+
nextNumber(table: string, column: string, groups: readonly ReadonlyMap<string, SampleValue>[]): Promise<Primitive | undefined>;
|
|
204
|
+
/**
|
|
205
|
+
* Inserts one row and answers it as stored; a CHECK, foreign key or unique index it fails is a `SeedLimitError`
|
|
206
|
+
* (`checkLimit`, `foreignKeyLimit`, `uniqueValueLimit`).
|
|
207
|
+
*/
|
|
171
208
|
insert(table: string, values: ReadonlyMap<string, SampleValue>): Promise<Readonly<Record<string, unknown>>>;
|
|
172
209
|
/** One row of `table`, of `columns`, or `undefined` when it has none. */
|
|
173
210
|
firstRow(table: string, columns: readonly string[]): Promise<Readonly<Record<string, unknown>> | undefined>;
|
|
@@ -183,8 +220,20 @@ export interface SeedingBackend {
|
|
|
183
220
|
export declare function checkLimit(constraint: string, table: string): SeedLimitError;
|
|
184
221
|
/** The seed limit of a foreign key a seeded row breaks. */
|
|
185
222
|
export declare function foreignKeyLimit(constraint: string, table: string): SeedLimitError;
|
|
223
|
+
/** The seed limit of a number column a unique index covers whose type holds no number above the largest of the row's group. */
|
|
224
|
+
export declare function uniqueLimit(index: string, table: string, column: string): SeedLimitError;
|
|
225
|
+
/** The seed limit of a row whose values another row of the table already holds under a unique index. */
|
|
226
|
+
export declare function uniqueValueLimit(index: string, table: string): SeedLimitError;
|
|
186
227
|
/** The seed limit of a required column whose type the fixture has no sample of. */
|
|
187
228
|
export declare function typeLimit(table: string, column: string, type: string): SeedLimitError;
|
|
229
|
+
/**
|
|
230
|
+
* A condition that matches a row holding every value of one of `groups` (column → value, `null` matched by `IS NULL`; an
|
|
231
|
+
* empty group matches every row, no group none), in the dialect's quoting and placeholders, with the values it binds.
|
|
232
|
+
*/
|
|
233
|
+
export declare function groupsWhere(groups: readonly ReadonlyMap<string, SampleValue>[], quote: (identifier: string) => string, placeholder: (position: number) => string): {
|
|
234
|
+
where: string;
|
|
235
|
+
values: SampleValue[];
|
|
236
|
+
};
|
|
188
237
|
export declare function randomHex(): string;
|
|
189
238
|
/**
|
|
190
239
|
* The object version a seeded file was scanned at: whoever stocks its empty object (`seededObjects`) stores it under
|