dsqlbase 0.2.0 → 0.3.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/CHANGELOG.md +42 -0
- package/README.md +41 -60
- package/dist/client/clients/base.d.ts +20 -0
- package/dist/client/clients/base.d.ts.map +1 -0
- package/dist/client/clients/base.js +52 -0
- package/dist/client/clients/base.js.map +1 -0
- package/dist/client/clients/dsql.d.ts +24 -0
- package/dist/client/clients/dsql.d.ts.map +1 -0
- package/dist/client/clients/dsql.js +31 -0
- package/dist/client/clients/dsql.js.map +1 -0
- package/dist/client/clients/index.d.ts +6 -0
- package/dist/client/clients/index.d.ts.map +1 -0
- package/dist/client/clients/index.js +6 -0
- package/dist/client/clients/index.js.map +1 -0
- package/dist/client/clients/model.d.ts +169 -0
- package/dist/client/clients/model.d.ts.map +1 -0
- package/dist/client/{model/client.js → clients/model.js} +82 -53
- package/dist/client/clients/model.js.map +1 -0
- package/dist/client/clients/transaction.d.ts +9 -0
- package/dist/client/clients/transaction.d.ts.map +1 -0
- package/dist/client/{transaction/transaction-client.js → clients/transaction.js} +7 -7
- package/dist/client/clients/transaction.js.map +1 -0
- package/dist/client/clients/union.d.ts +39 -0
- package/dist/client/clients/union.d.ts.map +1 -0
- package/dist/client/clients/union.js +54 -0
- package/dist/client/clients/union.js.map +1 -0
- package/dist/client/create.d.ts +15 -18
- package/dist/client/create.d.ts.map +1 -1
- package/dist/client/create.js +10 -27
- package/dist/client/create.js.map +1 -1
- package/dist/client/index.d.ts +4 -8
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +3 -6
- package/dist/client/index.js.map +1 -1
- package/dist/client/normalizers/base.d.ts +467 -0
- package/dist/client/normalizers/base.d.ts.map +1 -0
- package/dist/client/normalizers/base.js.map +1 -0
- package/dist/client/normalizers/context.d.ts +14 -0
- package/dist/client/normalizers/context.d.ts.map +1 -0
- package/dist/client/normalizers/context.js +16 -0
- package/dist/client/normalizers/context.js.map +1 -0
- package/dist/client/normalizers/index.d.ts +8 -0
- package/dist/client/normalizers/index.d.ts.map +1 -0
- package/dist/client/normalizers/index.js +8 -0
- package/dist/client/normalizers/index.js.map +1 -0
- package/dist/client/normalizers/pagination.d.ts +87 -0
- package/dist/client/normalizers/pagination.d.ts.map +1 -0
- package/dist/client/normalizers/pagination.js +245 -0
- package/dist/client/normalizers/pagination.js.map +1 -0
- package/dist/client/normalizers/request.d.ts +41 -0
- package/dist/client/normalizers/request.d.ts.map +1 -0
- package/dist/client/normalizers/request.js +346 -0
- package/dist/client/normalizers/request.js.map +1 -0
- package/dist/client/normalizers/rules.d.ts +132 -0
- package/dist/client/normalizers/rules.d.ts.map +1 -0
- package/dist/client/normalizers/rules.js +82 -0
- package/dist/client/normalizers/rules.js.map +1 -0
- package/dist/client/normalizers/utils.d.ts +6 -0
- package/dist/client/normalizers/utils.d.ts.map +1 -0
- package/dist/client/normalizers/utils.js +18 -0
- package/dist/client/normalizers/utils.js.map +1 -0
- package/dist/client/normalizers/where.d.ts +39 -0
- package/dist/client/normalizers/where.d.ts.map +1 -0
- package/dist/client/normalizers/where.js +230 -0
- package/dist/client/normalizers/where.js.map +1 -0
- package/dist/client/utils/occ-retry.d.ts.map +1 -0
- package/dist/client/utils/occ-retry.js.map +1 -0
- package/dist/index.d.ts +2 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -3
- package/dist/index.js.map +1 -1
- package/dist/schema/columns/guid.d.ts +21 -21
- package/dist/schema/columns/guid.d.ts.map +1 -1
- package/dist/schema/columns/guid.js +24 -25
- package/dist/schema/columns/guid.js.map +1 -1
- package/dist/schema/columns/numeric.d.ts +43 -2
- package/dist/schema/columns/numeric.d.ts.map +1 -1
- package/dist/schema/columns/numeric.js +42 -12
- package/dist/schema/columns/numeric.js.map +1 -1
- package/dist/schema/index.d.ts +1 -2
- package/dist/schema/index.d.ts.map +1 -1
- package/dist/schema/index.js +0 -2
- package/dist/schema/index.js.map +1 -1
- package/dist/schema/relations.d.ts +22 -13
- package/dist/schema/relations.d.ts.map +1 -1
- package/dist/schema/relations.js +9 -1
- package/dist/schema/relations.js.map +1 -1
- package/dist/schema/table.d.ts +2 -2
- package/dist/schema/table.d.ts.map +1 -1
- package/dist/schema/table.js.map +1 -1
- package/dist/schema/union.d.ts +13 -8
- package/dist/schema/union.d.ts.map +1 -1
- package/dist/schema/union.js +14 -9
- package/dist/schema/union.js.map +1 -1
- package/dist/schema/utils/global-id.d.ts +3 -3
- package/dist/schema/utils/global-id.js +3 -3
- package/dist/schema/utils/global-id.js.map +1 -1
- package/dist/schema/utils/guid-hooks.d.ts +49 -0
- package/dist/schema/utils/guid-hooks.d.ts.map +1 -0
- package/dist/schema/utils/guid-hooks.js +155 -0
- package/dist/schema/utils/guid-hooks.js.map +1 -0
- package/package.json +8 -6
- package/dist/client/database/base.d.ts +0 -99
- package/dist/client/database/base.d.ts.map +0 -1
- package/dist/client/database/base.js +0 -216
- package/dist/client/database/base.js.map +0 -1
- package/dist/client/database/client.d.ts +0 -26
- package/dist/client/database/client.d.ts.map +0 -1
- package/dist/client/database/client.js +0 -47
- package/dist/client/database/client.js.map +0 -1
- package/dist/client/database/index.d.ts +0 -65
- package/dist/client/database/index.d.ts.map +0 -1
- package/dist/client/database/index.js +0 -3
- package/dist/client/database/index.js.map +0 -1
- package/dist/client/model/base.d.ts +0 -747
- package/dist/client/model/base.d.ts.map +0 -1
- package/dist/client/model/base.js.map +0 -1
- package/dist/client/model/client.d.ts +0 -139
- package/dist/client/model/client.d.ts.map +0 -1
- package/dist/client/model/client.js.map +0 -1
- package/dist/client/model/filters.d.ts +0 -276
- package/dist/client/model/filters.d.ts.map +0 -1
- package/dist/client/model/filters.js +0 -470
- package/dist/client/model/filters.js.map +0 -1
- package/dist/client/model/normalizer.d.ts +0 -143
- package/dist/client/model/normalizer.d.ts.map +0 -1
- package/dist/client/model/normalizer.js +0 -641
- package/dist/client/model/normalizer.js.map +0 -1
- package/dist/client/nodes.d.ts +0 -62
- package/dist/client/nodes.d.ts.map +0 -1
- package/dist/client/nodes.js +0 -378
- package/dist/client/nodes.js.map +0 -1
- package/dist/client/pagination/cursor.d.ts +0 -40
- package/dist/client/pagination/cursor.d.ts.map +0 -1
- package/dist/client/pagination/cursor.js +0 -79
- package/dist/client/pagination/cursor.js.map +0 -1
- package/dist/client/pagination/page.d.ts +0 -23
- package/dist/client/pagination/page.d.ts.map +0 -1
- package/dist/client/pagination/page.js +0 -37
- package/dist/client/pagination/page.js.map +0 -1
- package/dist/client/transaction/index.d.ts +0 -2
- package/dist/client/transaction/index.d.ts.map +0 -1
- package/dist/client/transaction/index.js +0 -2
- package/dist/client/transaction/index.js.map +0 -1
- package/dist/client/transaction/occ-retry.d.ts.map +0 -1
- package/dist/client/transaction/occ-retry.js.map +0 -1
- package/dist/client/transaction/transaction-client.d.ts +0 -9
- package/dist/client/transaction/transaction-client.d.ts.map +0 -1
- package/dist/client/transaction/transaction-client.js.map +0 -1
- package/dist/client/union/client.d.ts +0 -55
- package/dist/client/union/client.d.ts.map +0 -1
- package/dist/client/union/client.js +0 -74
- package/dist/client/union/client.js.map +0 -1
- package/dist/schema/embedded.d.ts +0 -31
- package/dist/schema/embedded.d.ts.map +0 -1
- package/dist/schema/embedded.js +0 -33
- package/dist/schema/embedded.js.map +0 -1
- package/dist/schema/tenant.d.ts +0 -31
- package/dist/schema/tenant.d.ts.map +0 -1
- package/dist/schema/tenant.js +0 -33
- package/dist/schema/tenant.js.map +0 -1
- /package/dist/client/{model → normalizers}/base.js +0 -0
- /package/dist/client/{transaction → utils}/occ-retry.d.ts +0 -0
- /package/dist/client/{transaction → utils}/occ-retry.js +0 -0
|
@@ -1,747 +0,0 @@
|
|
|
1
|
-
import { AnyColumnDefinition, AnyNamespaceDefinition, AnyFieldRelation, AnyTableRelations, AnyUnionMembers, ColumnConfig, SharedFieldsOf, TableColumnDefinitions, TableDefinition, UnionDefinition } from "@dsqlbase/core/definition";
|
|
2
|
-
import { AnySchema, AnyTable, SchemaTableRelations, Table, TableByAlias } from "@dsqlbase/core/runtime";
|
|
3
|
-
import { Prettify, WithMeta } from "@dsqlbase/core/utils";
|
|
4
|
-
import { FilterOf, OrderableRuntimeType, WhereExpressionOf } from "./filters.js";
|
|
5
|
-
/** A table's plain columns, by field. A column group is not one: {@link GroupFieldNamesOf}. */
|
|
6
|
-
/** A table's column fields — not its groups, and not its deprecated columns. */
|
|
7
|
-
export type ColumnFieldNamesOf<T extends AnyTable> = keyof T["__type"]["columns"] extends infer K ? K extends string ? T["__type"]["columns"][K] extends AnyColumnDefinition ? T["__type"]["columns"][K] extends {
|
|
8
|
-
__type: {
|
|
9
|
-
deprecated: true;
|
|
10
|
-
};
|
|
11
|
-
} ? never : K : never : never : never;
|
|
12
|
-
/** A table's column groups, by field. */
|
|
13
|
-
export type GroupFieldNamesOf<T extends AnyTable> = GroupKeysOf<T["__type"]["columns"]>;
|
|
14
|
-
/** Every field a table stores: its plain columns and its column groups. */
|
|
15
|
-
export type FieldNamesOf<T extends AnyTable> = ColumnFieldNamesOf<T> | GroupFieldNamesOf<T>;
|
|
16
|
-
/**
|
|
17
|
-
* Matches a column group by `kind`: comparing a column against the group class structurally is
|
|
18
|
-
* costly enough, across a schema, to exhaust the checker.
|
|
19
|
-
*/
|
|
20
|
-
export type GroupOf<C> = {
|
|
21
|
-
readonly kind: "COLUMN_GROUP";
|
|
22
|
-
readonly columns: C;
|
|
23
|
-
};
|
|
24
|
-
type GroupKeysOf<C> = {
|
|
25
|
-
[K in keyof C & string]: C[K] extends GroupOf<unknown> ? K : never;
|
|
26
|
-
}[keyof C & string];
|
|
27
|
-
/**
|
|
28
|
-
* Whether a group can be absent: every member, nested groups included, is nullable. Mirrors
|
|
29
|
-
* `ColumnGroup.nullable` (`packages/core/src/runtime/group.ts`).
|
|
30
|
-
*/
|
|
31
|
-
type IsNullableGroup<C> = {
|
|
32
|
-
[K in keyof C]-?: C[K] extends GroupOf<infer GC> ? IsNullableGroup<GC> : C[K] extends {
|
|
33
|
-
__type: {
|
|
34
|
-
notNull: true;
|
|
35
|
-
};
|
|
36
|
-
} ? false : true;
|
|
37
|
-
}[keyof C] extends true ? true : false;
|
|
38
|
-
/** What a member reads as: a column's value, or a group's object. */
|
|
39
|
-
type MemberValueOf<M> = M extends GroupOf<infer GC> ? GroupValueOf<GC> : M extends {
|
|
40
|
-
__type: infer TConfig extends ColumnConfig;
|
|
41
|
-
} ? ValueTypeOf<TConfig> : never;
|
|
42
|
-
/** What a group reads as: an object of its members — `null` too when it can be absent. */
|
|
43
|
-
export type GroupValueOf<C> = Prettify<{
|
|
44
|
-
-readonly [K in keyof C]: MemberValueOf<C[K]>;
|
|
45
|
-
}> | (IsNullableGroup<C> extends true ? null : never);
|
|
46
|
-
/** Field `K` of a table as a read returns it: a column's value, or a group's object. */
|
|
47
|
-
export type FieldValueOf<T extends AnyTable, K extends FieldNamesOf<T>> = MemberValueOf<T["__type"]["columns"][K]>;
|
|
48
|
-
/**
|
|
49
|
-
* Which of `C` a selection names: a column takes `true`; a group `true` — every member — or a
|
|
50
|
-
* map of its members, the same shape again.
|
|
51
|
-
*/
|
|
52
|
-
export type ColumnsSelectionOf<C> = {
|
|
53
|
-
-readonly [K in keyof C]?: C[K] extends GroupOf<infer GC> ? boolean | ColumnsSelectionOf<GC> : boolean;
|
|
54
|
-
};
|
|
55
|
-
/** What member `M` reads as under selection `S`: all of it for `true`, a group's named members for a map. */
|
|
56
|
-
type SelectedMemberValueOf<M, S> = S extends true ? MemberValueOf<M> : M extends GroupOf<infer GC> ? S extends object ? SelectedGroupValueOf<GC, S> : never : never;
|
|
57
|
-
/** The keys a selection map names: `true`, or a group's member map. */
|
|
58
|
-
type SelectedKeysOf<S> = {
|
|
59
|
-
[K in keyof S]-?: S[K] extends true | object ? K : never;
|
|
60
|
-
}[keyof S];
|
|
61
|
-
type SelectedGroupValueOf<C, S> = [SelectedKeysOf<S>] extends [never] ? GroupValueOf<C> : Prettify<{
|
|
62
|
-
-readonly [K in SelectedKeysOf<S> & keyof C]: SelectedMemberValueOf<C[K], S[K]>;
|
|
63
|
-
}> | (IsNullableGroup<C> extends true ? null : never);
|
|
64
|
-
export type RelationFieldNamesOf<T extends AnyTable> = T["__type"]["relations"] extends AnyTableRelations ? keyof T["__type"]["relations"] extends infer K ? K extends string ? T["__type"]["relations"][K] extends AnyFieldRelation ? K : never : never : never : never;
|
|
65
|
-
export type ColumnTypeOf<T extends AnyTable, K extends ColumnFieldNamesOf<T>> = T["__type"]["columns"] extends Record<K, infer TColumn> ? TColumn extends AnyColumnDefinition ? TColumn["__type"] : never : never;
|
|
66
|
-
export type FieldRelationOf<T extends AnyTable, K extends RelationFieldNamesOf<T>> = T["__type"]["relations"] extends Record<K, infer R> ? R extends AnyFieldRelation ? R : never : never;
|
|
67
|
-
/**
|
|
68
|
-
* `V`, unless it is untyped on a column whose shape is checked: an untyped `array()` reads and
|
|
69
|
-
* writes as `unknown[]`, an untyped `record()` as `Record<string, unknown>`. The column's own
|
|
70
|
-
* value type stays `unknown`, so that `$type<T>()` gives exactly `T`.
|
|
71
|
-
*/
|
|
72
|
-
type ShapedTypeOf<R, V> = unknown extends V ? R extends "array" ? unknown[] : R extends "object" ? Record<string, unknown> : V : V;
|
|
73
|
-
export type ValueTypeOf<T extends ColumnConfig> = T extends ColumnConfig ? T["notNull"] extends true ? ShapedTypeOf<T["runtimeType"], T["valueType"]> : ShapedTypeOf<T["runtimeType"], T["valueType"]> | null : never;
|
|
74
|
-
/** What a write accepts for a column: its input type, nullable unless the column is not null. */
|
|
75
|
-
export type InputTypeOf<T extends ColumnConfig> = T extends ColumnConfig ? T["notNull"] extends true ? ShapedTypeOf<T["runtimeType"], T["inputType"]> : ShapedTypeOf<T["runtimeType"], T["inputType"]> | null : never;
|
|
76
|
-
/**
|
|
77
|
-
* The metadata a table declared with `table().meta()`, or `object` when it declared none.
|
|
78
|
-
* Accepts a `Table` or a `TableDefinition` — both carry it on `__type`.
|
|
79
|
-
*/
|
|
80
|
-
export type DeclaredMetaOf<T> = T extends {
|
|
81
|
-
__type: {
|
|
82
|
-
meta: infer M;
|
|
83
|
-
};
|
|
84
|
-
} ? M extends Record<string, unknown> ? M : object : object;
|
|
85
|
-
/**
|
|
86
|
-
* The aliases a schema exports a given table under, matched on the database table name.
|
|
87
|
-
*
|
|
88
|
-
* Matched on the *name* rather than on the whole table type because a join level rebuilds its
|
|
89
|
-
* target table from parts (`RelationJoinResultOf`), and the rebuilt type is not identical to
|
|
90
|
-
* the one `TableByAlias` produces — structural matching finds the root level and misses every
|
|
91
|
-
* nested one. The name is the reliable handle, and `SchemaRegistry` already keys its table map
|
|
92
|
-
* by it, so two tables in one schema cannot share one.
|
|
93
|
-
*/
|
|
94
|
-
type MatchingAliasesOf<TSchema extends AnySchema, TTable extends AnyTable> = {
|
|
95
|
-
[K in keyof TSchema["tables"] & string]: TableByAlias<TSchema, K>["name"] extends TTable["name"] ? TTable["name"] extends TableByAlias<TSchema, K>["name"] ? K : never : never;
|
|
96
|
-
}[keyof TSchema["tables"] & string];
|
|
97
|
-
/**
|
|
98
|
-
* The literal alias a schema exports a table under, for `$$meta.key`.
|
|
99
|
-
*
|
|
100
|
-
* A reverse lookup, because the alias is a property of the *schema* — the key a table is
|
|
101
|
-
* exported under — and nothing on `Table` carries it as a type. Falls back to `string` when
|
|
102
|
-
* the table is not in the schema, so a hand-built `Table` still types.
|
|
103
|
-
*/
|
|
104
|
-
export type AliasOf<TSchema extends AnySchema, TTable extends AnyTable> = [
|
|
105
|
-
MatchingAliasesOf<TSchema, TTable>
|
|
106
|
-
] extends [never] ? string : MatchingAliasesOf<TSchema, TTable>;
|
|
107
|
-
/**
|
|
108
|
-
* The `$$meta` property carried by every result record: built-ins set from the schema, plus
|
|
109
|
-
* whatever `table().meta()` declared.
|
|
110
|
-
*
|
|
111
|
-
* `key` is the schema alias — the name the client addresses the table by, and the
|
|
112
|
-
* discriminant a row union narrows on. It is the literal alias wherever the schema is in
|
|
113
|
-
* hand, and `string` otherwise.
|
|
114
|
-
*/
|
|
115
|
-
export type RecordMetaOf<T, TAlias extends string = string> = Prettify<{
|
|
116
|
-
key: TAlias;
|
|
117
|
-
table: string;
|
|
118
|
-
schema?: string;
|
|
119
|
-
} & DeclaredMetaOf<T>>;
|
|
120
|
-
/**
|
|
121
|
-
* The fields a `return` may name: columns as `true`, groups as `true` or a member map. A read's
|
|
122
|
-
* `select` also takes relations: {@link SelectionOf}.
|
|
123
|
-
*/
|
|
124
|
-
export type FieldSelectionOf<T extends AnyTable> = Partial<Record<ColumnFieldNamesOf<T>, boolean>> & ([GroupFieldNamesOf<T>] extends [never] ? unknown : {
|
|
125
|
-
[K in GroupFieldNamesOf<T>]?: T["__type"]["columns"][K] extends GroupOf<infer GC> ? boolean | ColumnsSelectionOf<GC> : never;
|
|
126
|
-
});
|
|
127
|
-
/** The fields a selection names — a column as `true`, a group as `true` or a map; never a relation. */
|
|
128
|
-
export type SelectedFieldsOf<TTable extends AnyTable, TSelection extends FieldSelectionOf<TTable>> = {
|
|
129
|
-
[K in keyof TSelection]: K extends ColumnFieldNamesOf<TTable> ? TSelection[K] extends true ? K : never : K extends GroupFieldNamesOf<TTable> ? TSelection[K] extends true | object ? K : never : never;
|
|
130
|
-
}[keyof TSelection];
|
|
131
|
-
/** Field `K` of a table as selection `S` reads it. */
|
|
132
|
-
export type SelectedFieldValueOf<T extends AnyTable, K extends FieldNamesOf<T>, S> = SelectedMemberValueOf<T["__type"]["columns"][K], S>;
|
|
133
|
-
/**
|
|
134
|
-
* Every key a selection names: a column as `true`, a relation as `true` or a field map. None
|
|
135
|
-
* means every column, as with no selection at all.
|
|
136
|
-
*/
|
|
137
|
-
type NamedKeysOf<TSelection> = {
|
|
138
|
-
[K in keyof TSelection]-?: TSelection[K] extends true | object ? K : never;
|
|
139
|
-
}[keyof TSelection];
|
|
140
|
-
/**
|
|
141
|
-
* A read's `select`: columns, plus relation fields. A relation takes `true` — every column of
|
|
142
|
-
* its target — or a field map over its target, relations included, and is read exactly as
|
|
143
|
-
* `join: { r: true }` or `join: { r: { select: map } }`. Filters, order and limits on a relation
|
|
144
|
-
* are written in `join`.
|
|
145
|
-
*/
|
|
146
|
-
export type SelectionOf<T extends AnyTable, S extends AnySchema> = [
|
|
147
|
-
DeclaredRelationNamesOf<T>
|
|
148
|
-
] extends [never] ? FieldSelectionOf<T> : FieldSelectionOf<T> & {
|
|
149
|
-
[R in DeclaredRelationNamesOf<T>]?: boolean | RelationSelectionOf<T, S, R>;
|
|
150
|
-
};
|
|
151
|
-
/**
|
|
152
|
-
* The relation fields a table declares. A table with no `relations()` block reads its
|
|
153
|
-
* relations as a bare record, whose keys are `string` — every key, columns included — so that
|
|
154
|
-
* case is none.
|
|
155
|
-
*/
|
|
156
|
-
type DeclaredRelationNamesOf<T extends AnyTable> = string extends RelationFieldNamesOf<T> ? never : RelationFieldNamesOf<T>;
|
|
157
|
-
/** The field map a relation takes in `select`: over its target, or a union's shared fields. */
|
|
158
|
-
export type RelationSelectionOf<T extends AnyTable, S extends AnySchema, R extends RelationFieldNamesOf<T>> = RelationTargetOf<T, R> extends TableDefinition<infer TName, infer TCols, infer TNamespace> ? SelectionOf<Table<TName, TCols, TNamespace, SchemaTableRelations<S, TName>>, S> : RelationTargetOf<T, R> extends UnionDefinition<infer TMembers> ? Partial<Record<SharedFieldsOf<TMembers>, boolean>> : never;
|
|
159
|
-
/** The relations a selection names, as `true` or a field map. */
|
|
160
|
-
type SelectedRelationsOf<T extends AnyTable, TSelection> = NamedKeysOf<TSelection> & DeclaredRelationNamesOf<T>;
|
|
161
|
-
/**
|
|
162
|
-
* Refuses a call naming one relation in both `select` and `join`: `join` is typed `never` for
|
|
163
|
-
* that key. Checked at the level the call is made; deeper levels are refused at runtime.
|
|
164
|
-
*/
|
|
165
|
-
export type NoSelectJoinOverlap<TArgs> = TArgs extends {
|
|
166
|
-
select?: infer TSelect;
|
|
167
|
-
join?: infer TJoin;
|
|
168
|
-
} ? [OverlapOf<TSelect, TJoin>] extends [never] ? unknown : {
|
|
169
|
-
join: Record<OverlapOf<TSelect, TJoin>, never>;
|
|
170
|
-
} : unknown;
|
|
171
|
-
type OverlapOf<TSelect, TJoin> = Extract<NamedKeysOf<TSelect>, NamedKeysOf<TJoin>> & string;
|
|
172
|
-
export type RequiredFieldsOf<T extends AnyTable> = {
|
|
173
|
-
[K in ColumnFieldNamesOf<T>]: ColumnTypeOf<T, K> extends {
|
|
174
|
-
notNull: true;
|
|
175
|
-
} ? ColumnTypeOf<T, K> extends {
|
|
176
|
-
hasDefault: true;
|
|
177
|
-
} ? never : K : never;
|
|
178
|
-
}[ColumnFieldNamesOf<T>];
|
|
179
|
-
export type RelationTypeOf<T extends AnyTable, K extends RelationFieldNamesOf<T>> = FieldRelationOf<T, K>["type"];
|
|
180
|
-
export type RelationTargetOf<T extends AnyTable, K extends RelationFieldNamesOf<T>> = FieldRelationOf<T, K>["target"];
|
|
181
|
-
export type OptionalFieldsOf<T extends AnyTable> = {
|
|
182
|
-
[K in ColumnFieldNamesOf<T>]: ColumnTypeOf<T, K> extends {
|
|
183
|
-
notNull: true;
|
|
184
|
-
} ? ColumnTypeOf<T, K> extends {
|
|
185
|
-
hasDefault: true;
|
|
186
|
-
} ? K : never : K;
|
|
187
|
-
}[ColumnFieldNamesOf<T>];
|
|
188
|
-
/**
|
|
189
|
-
* Fields the caller may not write. They stay fully readable — selectable, filterable and
|
|
190
|
-
* orderable — and are only removed from the two mutation inputs.
|
|
191
|
-
*/
|
|
192
|
-
export type ReadOnlyFieldsOf<T extends AnyTable> = {
|
|
193
|
-
[K in ColumnFieldNamesOf<T>]: ColumnTypeOf<T, K> extends {
|
|
194
|
-
readOnly: true;
|
|
195
|
-
} ? K : never;
|
|
196
|
-
}[ColumnFieldNamesOf<T>];
|
|
197
|
-
/**
|
|
198
|
-
* The claim fields a table is scoped by — the keys an identity must carry for it to be
|
|
199
|
-
* readable. Empty for a global table.
|
|
200
|
-
*/
|
|
201
|
-
export type TenantKeysOf<T extends AnyTable> = {
|
|
202
|
-
[K in ColumnFieldNamesOf<T>]: ColumnTypeOf<T, K> extends {
|
|
203
|
-
tenantKey: true;
|
|
204
|
-
} ? K : never;
|
|
205
|
-
}[ColumnFieldNamesOf<T>];
|
|
206
|
-
export type CreateValuesOf<T extends AnyTable> = {
|
|
207
|
-
[K in Exclude<RequiredFieldsOf<T>, ReadOnlyFieldsOf<T>>]: InputTypeOf<ColumnTypeOf<T, K>>;
|
|
208
|
-
} & {
|
|
209
|
-
[K in Exclude<OptionalFieldsOf<T>, ReadOnlyFieldsOf<T>>]?: InputTypeOf<ColumnTypeOf<T, K>>;
|
|
210
|
-
} & ([GroupFieldNamesOf<T>] extends [never] ? unknown : {
|
|
211
|
-
-readonly [K in GroupFieldNamesOf<T> & RequiredMembersOf<T["__type"]["columns"]>]: MemberInputOf<T["__type"]["columns"][K]>;
|
|
212
|
-
} & {
|
|
213
|
-
-readonly [K in Exclude<GroupFieldNamesOf<T>, RequiredMembersOf<T["__type"]["columns"]>>]?: MemberInputOf<T["__type"]["columns"][K]>;
|
|
214
|
-
});
|
|
215
|
-
/**
|
|
216
|
-
* Whether a member must be given on `create`: a column that is not null and has no default, or
|
|
217
|
-
* a group with such a member and no default of its own. A read-only member never is.
|
|
218
|
-
*/
|
|
219
|
-
type IsRequiredMember<M> = M extends GroupOf<infer GC> ? M extends {
|
|
220
|
-
__type: {
|
|
221
|
-
hasDefault: true;
|
|
222
|
-
};
|
|
223
|
-
} ? false : true extends {
|
|
224
|
-
[K in keyof GC]-?: IsRequiredMember<GC[K]>;
|
|
225
|
-
}[keyof GC] ? true : false : M extends {
|
|
226
|
-
__type: {
|
|
227
|
-
notNull: true;
|
|
228
|
-
};
|
|
229
|
-
} ? M extends {
|
|
230
|
-
__type: {
|
|
231
|
-
hasDefault: true;
|
|
232
|
-
};
|
|
233
|
-
} ? false : M extends {
|
|
234
|
-
__type: {
|
|
235
|
-
readOnly: true;
|
|
236
|
-
};
|
|
237
|
-
} ? false : true : false;
|
|
238
|
-
/** The members a write may set: every one but a read-only column. */
|
|
239
|
-
type WritableMembersOf<C> = {
|
|
240
|
-
[K in keyof C]-?: C[K] extends GroupOf<unknown> ? K : C[K] extends {
|
|
241
|
-
__type: {
|
|
242
|
-
readOnly: true;
|
|
243
|
-
};
|
|
244
|
-
} ? never : K;
|
|
245
|
-
}[keyof C];
|
|
246
|
-
type RequiredMembersOf<C> = {
|
|
247
|
-
[K in keyof C]-?: IsRequiredMember<C[K]> extends true ? K : never;
|
|
248
|
-
}[keyof C];
|
|
249
|
-
/** What a member takes on `create`: a column's input, or a group's object. */
|
|
250
|
-
type MemberInputOf<M> = M extends GroupOf<infer GC> ? GroupInputOf<GC> : M extends {
|
|
251
|
-
__type: infer TConfig extends ColumnConfig;
|
|
252
|
-
} ? InputTypeOf<TConfig> : never;
|
|
253
|
-
/**
|
|
254
|
-
* A group's value on `create`: its required members, the rest optional — an omitted member
|
|
255
|
-
* takes its default. `null` too when every member is nullable.
|
|
256
|
-
*/
|
|
257
|
-
export type GroupInputOf<C> = Prettify<{
|
|
258
|
-
-readonly [K in Extract<keyof C, WritableMembersOf<C> & RequiredMembersOf<C>>]: MemberInputOf<C[K]>;
|
|
259
|
-
} & {
|
|
260
|
-
-readonly [K in Exclude<WritableMembersOf<C>, RequiredMembersOf<C>>]?: MemberInputOf<C[K]>;
|
|
261
|
-
}> | (IsNullableGroup<C> extends true ? null : never);
|
|
262
|
-
/**
|
|
263
|
-
* A group's value on `update`: any of its members, nested groups likewise — the ones named are
|
|
264
|
-
* written and the rest keep their value. `null` too when every member is nullable.
|
|
265
|
-
*/
|
|
266
|
-
export type GroupUpdateOf<C> = Prettify<{
|
|
267
|
-
-readonly [K in WritableMembersOf<C>]?: C[K] extends GroupOf<infer GC> ? GroupUpdateOf<GC> : MemberInputOf<C[K]>;
|
|
268
|
-
}> | (IsNullableGroup<C> extends true ? null : never);
|
|
269
|
-
export type ReturningResultOf<T extends AnyTable, TArgs, TAlias extends string = string> = TArgs extends {
|
|
270
|
-
return?: infer R;
|
|
271
|
-
} ? R extends FieldSelectionOf<T> ? Prettify<([SelectedFieldsOf<T, R>] extends [never] ? {
|
|
272
|
-
[K in FieldNamesOf<T>]: FieldValueOf<T, K>;
|
|
273
|
-
} : {
|
|
274
|
-
[K in SelectedFieldsOf<T, R>]: K extends FieldNamesOf<T> ? SelectedFieldValueOf<T, K, R[K]> : never;
|
|
275
|
-
}) & {
|
|
276
|
-
$$meta: RecordMetaOf<T, TAlias>;
|
|
277
|
-
}> : R extends true ? Prettify<{
|
|
278
|
-
[K in FieldNamesOf<T>]: FieldValueOf<T, K>;
|
|
279
|
-
} & {
|
|
280
|
-
$$meta: RecordMetaOf<T, TAlias>;
|
|
281
|
-
}> : Record<string, never> : never;
|
|
282
|
-
export type CreateArgs<TTable extends AnyTable> = Prettify<{
|
|
283
|
-
data: CreateValuesOf<TTable>;
|
|
284
|
-
return?: FieldSelectionOf<TTable> | boolean | null | undefined;
|
|
285
|
-
}>;
|
|
286
|
-
export type UpdateValuesOf<T extends AnyTable> = {
|
|
287
|
-
[K in Exclude<ColumnFieldNamesOf<T>, ReadOnlyFieldsOf<T>>]?: InputTypeOf<ColumnTypeOf<T, K>>;
|
|
288
|
-
} & ([GroupFieldNamesOf<T>] extends [never] ? unknown : {
|
|
289
|
-
-readonly [K in GroupFieldNamesOf<T>]?: T["__type"]["columns"][K] extends GroupOf<infer C> ? GroupUpdateOf<C> : never;
|
|
290
|
-
});
|
|
291
|
-
export type UpdateArgs<TTable extends AnyTable> = Prettify<{
|
|
292
|
-
set: UpdateValuesOf<TTable>;
|
|
293
|
-
where: WhereExpressionOf<TTable>;
|
|
294
|
-
return?: FieldSelectionOf<TTable> | boolean | null | undefined;
|
|
295
|
-
}>;
|
|
296
|
-
export type DeleteArgs<TTable extends AnyTable> = Prettify<{
|
|
297
|
-
where: WhereExpressionOf<TTable>;
|
|
298
|
-
return?: FieldSelectionOf<TTable> | boolean | null | undefined;
|
|
299
|
-
}>;
|
|
300
|
-
export type QueryArgs<TTable extends AnyTable, TSchema extends AnySchema> = {
|
|
301
|
-
/**
|
|
302
|
-
* Select specific fields to return in the query result. If not provided, all fields will be returned.
|
|
303
|
-
*
|
|
304
|
-
* @example
|
|
305
|
-
* ```ts
|
|
306
|
-
* client.findOne({
|
|
307
|
-
* where: { id: { eq: "123" } },
|
|
308
|
-
* select: {
|
|
309
|
-
* id: true,
|
|
310
|
-
* firstName: true,
|
|
311
|
-
* },
|
|
312
|
-
* })
|
|
313
|
-
* ```
|
|
314
|
-
* @notes
|
|
315
|
-
* * The `select` clause allows you to specify which fields to retrieve, if not provided, all fields will be selected by default.
|
|
316
|
-
* * You can only select fields that exist on the table, attempting to select a non-existent field will result in a TypeScript error.
|
|
317
|
-
* * A relation may be named like a field, as `true` or a field map over its target, and reads exactly as the same
|
|
318
|
-
* relation in `join`. Naming only relations returns only them; naming nothing as `true` returns every column.
|
|
319
|
-
* The same relation may not be named in both `select` and `join`.
|
|
320
|
-
*
|
|
321
|
-
* @typeParam TTable - The table being queried, used for type inference of selectable fields.
|
|
322
|
-
* @typeParam TSchema - The overall schema, used for type inference of relations in join expressions.
|
|
323
|
-
*/
|
|
324
|
-
select?: SelectionOf<TTable, TSchema>;
|
|
325
|
-
/**
|
|
326
|
-
* A filter expression to specify which records to retrieve. This is optional for `findMany`, if not provided, all records will be returned.
|
|
327
|
-
*
|
|
328
|
-
* @example
|
|
329
|
-
* ```ts
|
|
330
|
-
* client.findMany({
|
|
331
|
-
* where: { published: true },
|
|
332
|
-
* });
|
|
333
|
-
* ```
|
|
334
|
-
* @notes
|
|
335
|
-
* * The `where` clause is optional for `findMany`, if not provided, all records will be returned.
|
|
336
|
-
* * The `where` clause supports various filter conditions such as equality, inequality, range queries, and more.
|
|
337
|
-
* * You can combine multiple conditions using logical operators like `and`, `or`, and `not`.
|
|
338
|
-
* * The fields used in the `where` clause must exist on the table, attempting to filter by a non-existent field will result in a TypeScript error.
|
|
339
|
-
*
|
|
340
|
-
* @typeParam TTable - The table being queried, used for type inference of filterable fields.
|
|
341
|
-
*/
|
|
342
|
-
where?: WhereExpressionOf<TTable>;
|
|
343
|
-
/**
|
|
344
|
-
* Specify the order in which to return the records. The keys must be field names of the table, and the values must be either "asc" for ascending order or "desc" for descending order.
|
|
345
|
-
*
|
|
346
|
-
* @example
|
|
347
|
-
* ```ts
|
|
348
|
-
* client.findMany({
|
|
349
|
-
* orderBy: { createdAt: "desc" },
|
|
350
|
-
* });
|
|
351
|
-
* ```
|
|
352
|
-
* @notes
|
|
353
|
-
* * The `orderBy` clause allows you to specify the order in which to return the records. The keys must be field names of the table, and the values must be either "asc" for ascending order or "desc" for descending order.
|
|
354
|
-
* * You can specify multiple fields to order by, in which case the records will be ordered by the first field, and then by the second field in case of ties, and so on.
|
|
355
|
-
* * The fields used in the `orderBy` clause must exist on the table, attempting to order by a non-existent field will result in a TypeScript error.
|
|
356
|
-
*
|
|
357
|
-
* @typeParam TTable - The table being queried, used for type inference of orderable fields.
|
|
358
|
-
*/
|
|
359
|
-
orderBy?: OrderByExpressionOf<TTable>;
|
|
360
|
-
/**
|
|
361
|
-
* Specify that the query should return only distinct records based on the selected fields. This is useful when you want to eliminate duplicate records from the result set.
|
|
362
|
-
*
|
|
363
|
-
* @example
|
|
364
|
-
* ```ts
|
|
365
|
-
* client.findMany({
|
|
366
|
-
* where: { published: true },
|
|
367
|
-
* distinct: true,
|
|
368
|
-
* });
|
|
369
|
-
* ```
|
|
370
|
-
* @notes
|
|
371
|
-
* * The `distinct` flag indicates that the query should return only distinct records based on the selected fields. This is useful when you want to eliminate duplicate records from the result set.
|
|
372
|
-
* * When `distinct` is true, the database will ensure that the returned records are unique based on the fields specified in the `select` clause. If no `select` clause is provided, all fields will be considered for determining uniqueness.
|
|
373
|
-
* * The `distinct` flag is typically used in conjunction with the `select` clause to specify which fields should be considered when determining uniqueness. If you want to return distinct records based on specific fields, make sure to include those fields in the `select` clause.
|
|
374
|
-
* * The behavior of the `distinct` flag may vary depending on the underlying database and how it handles distinct queries, especially when combined with joins and other query features.
|
|
375
|
-
*/
|
|
376
|
-
distinct?: boolean;
|
|
377
|
-
/**
|
|
378
|
-
* Specify the maximum number of records to return and the number of records to skip. This is useful for implementing pagination in your queries.
|
|
379
|
-
*
|
|
380
|
-
* @example
|
|
381
|
-
* ```ts
|
|
382
|
-
* client.findMany({
|
|
383
|
-
* where: { published: true },
|
|
384
|
-
* limit: 10,
|
|
385
|
-
* offset: 20,
|
|
386
|
-
* });
|
|
387
|
-
* ```
|
|
388
|
-
* @notes
|
|
389
|
-
* * The `limit` parameter specifies the maximum number of records to return. If not provided, no limit is applied and every matching record is returned.
|
|
390
|
-
* * The `offset` parameter specifies the number of records to skip before starting to return records. This is useful for implementing pagination in your queries. If not provided, no records will be skipped.
|
|
391
|
-
* * When using `limit` and `offset` together, the query will return records starting from the `offset` position up to the number specified by `limit`. For example, if `offset` is 20 and `limit` is 10, the query will return records 21 through 30.
|
|
392
|
-
*/
|
|
393
|
-
limit?: number;
|
|
394
|
-
/**
|
|
395
|
-
* The `offset` parameter specifies the number of records to skip before starting to return records. This is useful for implementing pagination in your queries. If not provided, no records will be skipped.
|
|
396
|
-
*
|
|
397
|
-
* @example
|
|
398
|
-
* ```ts
|
|
399
|
-
* client.findMany({
|
|
400
|
-
* where: { published: true },
|
|
401
|
-
* offset: 20,
|
|
402
|
-
* });
|
|
403
|
-
* ```
|
|
404
|
-
* @notes
|
|
405
|
-
* * The `offset` parameter specifies the number of records to skip before starting to return records. This is useful for implementing pagination in your queries. If not provided, no records will be skipped.
|
|
406
|
-
* * When using `limit` and `offset` together, the query will return records starting from the `offset` position up to the number specified by `limit`. For example, if `offset` is 20 and `limit` is 10, the query will return records 21 through 30.
|
|
407
|
-
*/
|
|
408
|
-
offset?: number;
|
|
409
|
-
/**
|
|
410
|
-
* Join related records based on the relations defined in the schema. The value can be a boolean or a nested query object for more complex queries.
|
|
411
|
-
*
|
|
412
|
-
* @example
|
|
413
|
-
* ```ts
|
|
414
|
-
* client.findOne({
|
|
415
|
-
* where: { id: "123" },
|
|
416
|
-
* select: {
|
|
417
|
-
* id: true,
|
|
418
|
-
* firstName: true,
|
|
419
|
-
* },
|
|
420
|
-
* join: {
|
|
421
|
-
* posts: {
|
|
422
|
-
* where: { published: true },
|
|
423
|
-
* select: {
|
|
424
|
-
* title: true,
|
|
425
|
-
* },
|
|
426
|
-
* },
|
|
427
|
-
* profile: true,
|
|
428
|
-
* },
|
|
429
|
-
* })
|
|
430
|
-
* ```
|
|
431
|
-
*/
|
|
432
|
-
join?: Prettify<JoinExpressionOf<TTable, TSchema>>;
|
|
433
|
-
};
|
|
434
|
-
export type FindOneArgs<TTable extends AnyTable, TSchema extends AnySchema> = {
|
|
435
|
-
/**
|
|
436
|
-
* A filter expression to specify which record to retrieve. This is required for `findOne` to ensure that the operation is deterministic and does not accidentally return an unintended record.
|
|
437
|
-
*
|
|
438
|
-
* @example
|
|
439
|
-
* ```ts
|
|
440
|
-
* client.findOne({
|
|
441
|
-
* where: { id: { eq: "123" } },
|
|
442
|
-
* });
|
|
443
|
-
* ```
|
|
444
|
-
* @notes
|
|
445
|
-
* * The `where` clause is required for `findOne` to ensure that the operation is deterministic and does not accidentally return an unintended record.
|
|
446
|
-
* * The `where` clause supports various filter conditions such as equality, inequality, range queries, and more.
|
|
447
|
-
* * You can combine multiple conditions using logical operators like `and`, `or`, and `not`.
|
|
448
|
-
* * The fields used in the `where` clause must exist on the table, attempting to filter by a non-existent field will result in a TypeScript error.
|
|
449
|
-
*
|
|
450
|
-
* @typeParam TTable - The table being queried, used for type inference of filterable fields.
|
|
451
|
-
*/
|
|
452
|
-
where: WhereExpressionOf<TTable>;
|
|
453
|
-
} & Pick<QueryArgs<TTable, TSchema>, "select" | "join">;
|
|
454
|
-
export type PaginateArgs<TTable extends AnyTable, TSchema extends AnySchema> = {
|
|
455
|
-
/**
|
|
456
|
-
* The number of records on the page. Defaults to the client's `pagination.defaultLimit`
|
|
457
|
-
* (100 unless configured), and may not exceed its `pagination.maxLimit` when one is set.
|
|
458
|
-
*/
|
|
459
|
-
limit?: number;
|
|
460
|
-
/**
|
|
461
|
-
* Read the page that follows this cursor — a `startCursor`, `endCursor` or record
|
|
462
|
-
* `$$meta.cursor` from an earlier page taken under the same `orderBy`.
|
|
463
|
-
*/
|
|
464
|
-
after?: string | null;
|
|
465
|
-
/** Read the page that precedes this cursor. Never together with `after`. */
|
|
466
|
-
before?: string | null;
|
|
467
|
-
/**
|
|
468
|
-
* Also count every record `where` selects, as `totalCount`. A second statement, and a full
|
|
469
|
-
* read of the filtered rows on every page — hence opt-in.
|
|
470
|
-
*/
|
|
471
|
-
count?: boolean;
|
|
472
|
-
} & Pick<QueryArgs<TTable, TSchema>, "select" | "where" | "orderBy" | "join">;
|
|
473
|
-
/** One record of a page: a query result whose `$$meta` also carries its own cursor. */
|
|
474
|
-
export type PageItemOf<TTable extends AnyTable, TSchema extends AnySchema, TArgs extends PaginateArgs<TTable, TSchema>> = Prettify<Omit<QueryResultOf<TTable, TSchema, TArgs>, "$$meta"> & {
|
|
475
|
-
$$meta: Prettify<RecordMetaOf<TTable, AliasOf<TSchema, TTable>> & {
|
|
476
|
-
cursor: string;
|
|
477
|
-
}>;
|
|
478
|
-
}>;
|
|
479
|
-
type TotalCountOf<TArgs> = "count" extends keyof TArgs ? [TArgs["count" & keyof TArgs]] extends [true] ? {
|
|
480
|
-
totalCount: number;
|
|
481
|
-
} : [TArgs["count" & keyof TArgs]] extends [false | undefined] ? unknown : {
|
|
482
|
-
totalCount?: number;
|
|
483
|
-
} : unknown;
|
|
484
|
-
export type PageOf<TTable extends AnyTable, TSchema extends AnySchema, TArgs extends PaginateArgs<TTable, TSchema>> = Prettify<{
|
|
485
|
-
items: PageItemOf<TTable, TSchema, TArgs>[];
|
|
486
|
-
hasNextPage: boolean;
|
|
487
|
-
hasPreviousPage: boolean;
|
|
488
|
-
/** The first item's cursor, or `null` on an empty page. */
|
|
489
|
-
startCursor: string | null;
|
|
490
|
-
/** The last item's cursor, or `null` on an empty page. */
|
|
491
|
-
endCursor: string | null;
|
|
492
|
-
} & TotalCountOf<TArgs>>;
|
|
493
|
-
export type CountArgs<TTable extends AnyTable> = {
|
|
494
|
-
where?: WhereExpressionOf<TTable>;
|
|
495
|
-
};
|
|
496
|
-
export type RelationQueryOf<T extends AnyTable, S extends AnySchema, K extends RelationFieldNamesOf<T>> = RelationTargetOf<T, K> extends TableDefinition<infer TName, infer TCols, infer TSchema> ? RelationTypeOf<T, K> extends "has_many" ? QueryArgs<Table<TName, TCols, TSchema, SchemaTableRelations<S, TName>>, S> : Pick<QueryArgs<Table<TName, TCols, TSchema, SchemaTableRelations<S, TName>>, S>, "select" | "join"> : RelationTargetOf<T, K> extends UnionDefinition<infer TMembers> ? RelationTypeOf<T, K> extends "has_many" ? UnionQueryArgs<TMembers, S> : Pick<UnionQueryArgs<TMembers, S>, "select" | "orderBy" | "on"> : never;
|
|
497
|
-
export type SelectionResultOf<TTable extends AnyTable, TSchema extends AnySchema, TArgs extends QueryArgs<TTable, TSchema>> = TArgs["select"] extends object ? [NamedKeysOf<TArgs["select"]>] extends [never] ? {
|
|
498
|
-
[K in FieldNamesOf<TTable>]: FieldValueOf<TTable, K>;
|
|
499
|
-
} : {
|
|
500
|
-
[K in SelectedFieldsOf<TTable, TArgs["select"]>]: K extends FieldNamesOf<TTable> ? SelectedFieldValueOf<TTable, K, TArgs["select"][K]> : never;
|
|
501
|
-
} : {
|
|
502
|
-
[K in FieldNamesOf<TTable>]: FieldValueOf<TTable, K>;
|
|
503
|
-
};
|
|
504
|
-
export type RelationJoinResultOf<TTable extends AnyTable, TSchema extends AnySchema, TArgs extends QueryArgs<TTable, TSchema>, TRelationField extends RelationFieldNamesOf<TTable>, TTargetName extends string, TTargetCols extends TableColumnDefinitions, TTargetSchema extends AnyNamespaceDefinition, TTargetMeta = object> = RelationTypeOf<TTable, TRelationField> extends "has_many" ? QueryResultOf<WithMeta<Table<TTargetName, TTargetCols, TTargetSchema, SchemaTableRelations<TSchema, TTargetName>>, TTargetMeta>, TSchema, TArgs>[] : QueryResultOf<WithMeta<Table<TTargetName, TTargetCols, TTargetSchema, SchemaTableRelations<TSchema, TTargetName>>, TTargetMeta>, TSchema, TArgs> | null;
|
|
505
|
-
/** One joined field of a result: relation `K` read with join entry `TEntry`. */
|
|
506
|
-
type JoinFieldResultOf<TTable extends AnyTable, TSchema extends AnySchema, K, TEntry> = K extends RelationFieldNamesOf<TTable> ? RelationTargetOf<TTable, K> extends TableDefinition<infer TName, infer TCols, infer TNamespace> ? TEntry extends QueryArgs<Table<TName, TCols, TNamespace, SchemaTableRelations<TSchema, TName>>, TSchema> ? RelationJoinResultOf<TTable, TSchema, TEntry, K, TName, TCols, TNamespace, DeclaredMetaOf<RelationTargetOf<TTable, K>>> : TEntry extends boolean ? TEntry extends true ? RelationJoinResultOf<TTable, TSchema, QueryArgs<Table<TName, TCols, TNamespace, SchemaTableRelations<TSchema, TName>>, TSchema>, K, TName, TCols, TNamespace, DeclaredMetaOf<RelationTargetOf<TTable, K>>> : never : never : RelationTargetOf<TTable, K> extends UnionDefinition<infer TMembers> ? UnionJoinResultOf<TMembers, TSchema, TEntry extends UnionQueryArgs<TMembers, TSchema> ? TEntry : object, RelationTypeOf<TTable, K>> : never : never;
|
|
507
|
-
/** The relations named in `select`, each shaped as the `join` entry it is read as. */
|
|
508
|
-
type SelectedRelationsResultOf<TTable extends AnyTable, TSchema extends AnySchema, TSelection> = {
|
|
509
|
-
[K in SelectedRelationsOf<TTable, TSelection>]: JoinFieldResultOf<TTable, TSchema, K, TSelection[K] extends true ? true : {
|
|
510
|
-
select: TSelection[K];
|
|
511
|
-
}>;
|
|
512
|
-
};
|
|
513
|
-
export type QueryResultOf<TTable extends AnyTable, TSchema extends AnySchema, TArgs extends QueryArgs<TTable, TSchema>> = Prettify<SelectionResultOf<TTable, TSchema, TArgs> & {
|
|
514
|
-
$$meta: RecordMetaOf<TTable, AliasOf<TSchema, TTable>>;
|
|
515
|
-
} & SelectedRelationsResultOf<TTable, TSchema, TArgs["select"]> & {
|
|
516
|
-
[K in NamedKeysOf<TArgs["join"]>]: JoinFieldResultOf<TTable, TSchema, K, TArgs["join"][K]>;
|
|
517
|
-
}>;
|
|
518
|
-
/** The value a shared field holds, across every member of a union. */
|
|
519
|
-
type SharedValueOf<TMembers extends AnyUnionMembers, K extends PropertyKey> = {
|
|
520
|
-
[A in keyof TMembers]: TMembers[A]["__type"]["columns"][K] extends AnyColumnDefinition ? ValueTypeOf<TMembers[A]["__type"]["columns"][K]["__type"]> : never;
|
|
521
|
-
}[keyof TMembers];
|
|
522
|
-
/** The runtime type a shared field has, across every member of a union. */
|
|
523
|
-
type SharedRuntimeTypeOf<TMembers extends AnyUnionMembers, K extends PropertyKey> = {
|
|
524
|
-
[A in keyof TMembers]: TMembers[A]["__type"]["columns"][K] extends AnyColumnDefinition ? TMembers[A]["__type"]["columns"][K]["__type"]["runtimeType"] : never;
|
|
525
|
-
}[keyof TMembers];
|
|
526
|
-
/** The shared fields of a union that can be ordered by. */
|
|
527
|
-
type OrderableSharedFieldsOf<TMembers extends AnyUnionMembers> = {
|
|
528
|
-
[K in SharedFieldsOf<TMembers>]: IsOrderable<SharedRuntimeTypeOf<TMembers, K>> extends true ? K : never;
|
|
529
|
-
}[SharedFieldsOf<TMembers>];
|
|
530
|
-
/**
|
|
531
|
-
* A filter on which member a row comes from. Decided while the query is built, member by
|
|
532
|
-
* member, so a member that cannot match produces no branch — it never reaches SQL.
|
|
533
|
-
*/
|
|
534
|
-
export type KeyFilterOf<TAlias extends string> = TAlias | {
|
|
535
|
-
eq?: TAlias;
|
|
536
|
-
neq?: TAlias;
|
|
537
|
-
in?: TAlias[];
|
|
538
|
-
};
|
|
539
|
-
/**
|
|
540
|
-
* A `where` over a union's shared fields — the only ones that filter across it — and `$$key`.
|
|
541
|
-
*
|
|
542
|
-
* `$$key` narrows the query, not the result type: its value is usually a runtime one (a
|
|
543
|
-
* resolver argument), so the members it rules out stay in the type. Use `on: { alias: false }`
|
|
544
|
-
* to remove a member from both.
|
|
545
|
-
*/
|
|
546
|
-
export type UnionWhereExpressionOf<TMembers extends AnyUnionMembers> = {
|
|
547
|
-
[K in SharedFieldsOf<TMembers>]?: FilterOf<SharedRuntimeTypeOf<TMembers, K>, SharedValueOf<TMembers, K>>;
|
|
548
|
-
} & {
|
|
549
|
-
$$key?: KeyFilterOf<keyof TMembers & string>;
|
|
550
|
-
and?: UnionWhereExpressionOf<TMembers>[];
|
|
551
|
-
or?: UnionWhereExpressionOf<TMembers>[];
|
|
552
|
-
not?: UnionWhereExpressionOf<TMembers>;
|
|
553
|
-
};
|
|
554
|
-
/**
|
|
555
|
-
* A select over a union: shared-level `select` / `where` / `orderBy` / `limit` / `offset`, which
|
|
556
|
-
* every member runs, plus `on` for what differs per member — GraphQL's `... on Photo { }`.
|
|
557
|
-
*/
|
|
558
|
-
export type UnionQueryArgs<TMembers extends AnyUnionMembers, TSchema extends AnySchema> = {
|
|
559
|
-
/** Shared fields to return from every member; merged with each member's `on.<alias>.select`. */
|
|
560
|
-
select?: Partial<Record<SharedFieldsOf<TMembers>, boolean>>;
|
|
561
|
-
/** Applied inside every member's branch, AND-ed with its `on.<alias>.where`. */
|
|
562
|
-
where?: UnionWhereExpressionOf<TMembers>;
|
|
563
|
-
/**
|
|
564
|
-
* Orders the combined rows, by shared fields and by `$$key` (member alias). Ties are broken
|
|
565
|
-
* by member alias and then the primary key, so the order is total whenever the members' keys
|
|
566
|
-
* line up.
|
|
567
|
-
*/
|
|
568
|
-
orderBy?: Partial<Record<OrderableSharedFieldsOf<TMembers> | "$$key", "asc" | "desc">>;
|
|
569
|
-
limit?: number;
|
|
570
|
-
offset?: number;
|
|
571
|
-
/**
|
|
572
|
-
* Per member: `false` drops it, `true` (or leaving it out) runs it with the shared arguments,
|
|
573
|
-
* and an object adds a member-only `select`, `where` and `join`.
|
|
574
|
-
*/
|
|
575
|
-
on?: OnSelectionOf<keyof TMembers & string, TSchema>;
|
|
576
|
-
};
|
|
577
|
-
/** The query args one member of a union runs with: shared `select` merged with its own. */
|
|
578
|
-
type MemberArgsOf<TSchema extends AnySchema, TAlias extends string, TShared, TOn> = {
|
|
579
|
-
select: TShared extends object ? TOn extends {
|
|
580
|
-
select: infer TOwn;
|
|
581
|
-
} ? TShared & TOwn : TShared : TOn extends {
|
|
582
|
-
select: infer TOwn;
|
|
583
|
-
} ? TOwn : undefined;
|
|
584
|
-
join: TOn extends {
|
|
585
|
-
join: infer TJoin;
|
|
586
|
-
} ? TJoin : undefined;
|
|
587
|
-
} extends infer TArgs ? TArgs extends QueryArgs<TableByAlias<TSchema, TAlias>, TSchema> ? TArgs : QueryArgs<TableByAlias<TSchema, TAlias>, TSchema> : never;
|
|
588
|
-
type OnEntryOf<TArgs, TAlias extends string> = TArgs extends {
|
|
589
|
-
on: infer TOn;
|
|
590
|
-
} ? TAlias extends keyof TOn ? TOn[TAlias] : undefined : undefined;
|
|
591
|
-
type SharedSelectOf<TArgs> = TArgs extends {
|
|
592
|
-
select: infer TSelect;
|
|
593
|
-
} ? TSelect : undefined;
|
|
594
|
-
/**
|
|
595
|
-
* One row of a union result: a union over the members `on` did not exclude, each tagged with
|
|
596
|
-
* its alias in `$$key` — which is what narrows it — and shaped by that member's own selection.
|
|
597
|
-
*/
|
|
598
|
-
export type UnionResultOf<TMembers extends AnyUnionMembers, TSchema extends AnySchema, TArgs> = {
|
|
599
|
-
[A in keyof TMembers & string]: IsExcluded<A, TArgs extends {
|
|
600
|
-
on: infer TOn;
|
|
601
|
-
} ? TOn : undefined> extends true ? never : Prettify<{
|
|
602
|
-
$$key: A;
|
|
603
|
-
} & QueryResultOf<TableByAlias<TSchema, A>, TSchema, MemberArgsOf<TSchema, A, SharedSelectOf<TArgs>, OnEntryOf<TArgs, A>>>>;
|
|
604
|
-
}[keyof TMembers & string];
|
|
605
|
-
export type UnionJoinResultOf<TMembers extends AnyUnionMembers, TSchema extends AnySchema, TArgs, TType> = TType extends "has_many" ? UnionResultOf<TMembers, TSchema, TArgs>[] : UnionResultOf<TMembers, TSchema, TArgs> | null;
|
|
606
|
-
/** The members of a union definition, as a record of member alias → table definition. */
|
|
607
|
-
export type UnionMembersOf<TUnion> = TUnion extends UnionDefinition<infer TMembers> ? TMembers : never;
|
|
608
|
-
/** A union's `findOne`: like `findMany`, but a `where` must name the row. */
|
|
609
|
-
export type UnionFindOneArgs<TMembers extends AnyUnionMembers, TSchema extends AnySchema> = {
|
|
610
|
-
where: UnionWhereExpressionOf<TMembers>;
|
|
611
|
-
} & Pick<UnionQueryArgs<TMembers, TSchema>, "select" | "orderBy" | "on">;
|
|
612
|
-
/** A union's `paginate` — the table form, with the union's shared-field arguments and `on`. */
|
|
613
|
-
export type UnionPaginateArgs<TMembers extends AnyUnionMembers, TSchema extends AnySchema> = {
|
|
614
|
-
/** The number of records on the page, under the client's `pagination` limits. */
|
|
615
|
-
limit?: number;
|
|
616
|
-
/** Read the page that follows this cursor, taken from this union under the same `orderBy`. */
|
|
617
|
-
after?: string | null;
|
|
618
|
-
/** Read the page that precedes this cursor. Never together with `after`. */
|
|
619
|
-
before?: string | null;
|
|
620
|
-
/** Also count every record `where` selects, across every member, as `totalCount`. */
|
|
621
|
-
count?: boolean;
|
|
622
|
-
} & Pick<UnionQueryArgs<TMembers, TSchema>, "select" | "where" | "orderBy" | "on">;
|
|
623
|
-
/** One record of a union page: each member's row, its `$$meta` also carrying its cursor. */
|
|
624
|
-
export type UnionPageItemOf<TMembers extends AnyUnionMembers, TSchema extends AnySchema, TArgs> = UnionResultOf<TMembers, TSchema, TArgs> extends infer TRow ? TRow extends {
|
|
625
|
-
$$meta: infer TMeta;
|
|
626
|
-
} ? Prettify<Omit<TRow, "$$meta"> & {
|
|
627
|
-
$$meta: Prettify<TMeta & {
|
|
628
|
-
cursor: string;
|
|
629
|
-
}>;
|
|
630
|
-
}> : never : never;
|
|
631
|
-
export type UnionPageOf<TMembers extends AnyUnionMembers, TSchema extends AnySchema, TArgs extends UnionPaginateArgs<TMembers, TSchema>> = Prettify<{
|
|
632
|
-
items: UnionPageItemOf<TMembers, TSchema, TArgs>[];
|
|
633
|
-
hasNextPage: boolean;
|
|
634
|
-
hasPreviousPage: boolean;
|
|
635
|
-
startCursor: string | null;
|
|
636
|
-
endCursor: string | null;
|
|
637
|
-
} & TotalCountOf<TArgs>>;
|
|
638
|
-
export type UnionCountArgs<TMembers extends AnyUnionMembers> = {
|
|
639
|
-
where?: UnionWhereExpressionOf<TMembers>;
|
|
640
|
-
};
|
|
641
|
-
/** What the normalizer receives for a union level, before any type narrowing. */
|
|
642
|
-
export type AnyUnionQuery = {
|
|
643
|
-
select?: Record<string, boolean | undefined> | null;
|
|
644
|
-
where?: Record<string, unknown> | null;
|
|
645
|
-
orderBy?: Record<string, "asc" | "desc" | undefined> | null;
|
|
646
|
-
limit?: number | null;
|
|
647
|
-
offset?: number | null;
|
|
648
|
-
distinct?: boolean;
|
|
649
|
-
on?: Record<string, boolean | AnyRelationQuery | undefined> | null;
|
|
650
|
-
};
|
|
651
|
-
/** Whether a column of runtime type `R` can be ordered by — `true` if any of `R` can. */
|
|
652
|
-
type IsOrderable<R> = [Extract<R, OrderableRuntimeType>] extends [never] ? false : true;
|
|
653
|
-
/** The fields of a table that can be ordered by: not documents, arrays or binary. */
|
|
654
|
-
export type OrderableFieldNamesOf<T extends AnyTable> = {
|
|
655
|
-
[K in ColumnFieldNamesOf<T>]: IsOrderable<ColumnTypeOf<T, K>["runtimeType"]> extends true ? K : never;
|
|
656
|
-
}[ColumnFieldNamesOf<T>];
|
|
657
|
-
export type OrderByExpressionOf<T extends AnyTable> = Partial<Record<OrderableFieldNamesOf<T>, "asc" | "desc">> & ([GroupFieldNamesOf<T>] extends [never] ? unknown : {
|
|
658
|
-
[K in GroupFieldNamesOf<T>]?: T["__type"]["columns"][K] extends GroupOf<infer C> ? MembersOrderByOf<C> : never;
|
|
659
|
-
});
|
|
660
|
-
/** An order over a group's members: a direction per orderable member, a nested object per group. */
|
|
661
|
-
export type MembersOrderByOf<C> = {
|
|
662
|
-
-readonly [K in keyof C as C[K] extends GroupOf<unknown> ? K : C[K] extends {
|
|
663
|
-
__type: {
|
|
664
|
-
runtimeType: infer R;
|
|
665
|
-
};
|
|
666
|
-
} ? IsOrderable<R> extends true ? K : never : never]?: C[K] extends GroupOf<infer GC> ? MembersOrderByOf<GC> : "asc" | "desc";
|
|
667
|
-
};
|
|
668
|
-
export type JoinExpressionOf<T extends AnyTable, S extends AnySchema> = {
|
|
669
|
-
[K in RelationFieldNamesOf<T>]?: RelationQueryOf<T, S, K> | boolean | null | undefined;
|
|
670
|
-
};
|
|
671
|
-
export type AnyRelationQuery = RelationQueryOf<AnyTable, AnySchema, RelationFieldNamesOf<AnyTable>> | boolean;
|
|
672
|
-
/**
|
|
673
|
-
* The field a table's primary key is a single `guid()` column under, or `never`.
|
|
674
|
-
*
|
|
675
|
-
* Mirrors the runtime rule in `packages/dsqlbase/src/client/nodes.ts`. A composite key is
|
|
676
|
-
* declared with `table.primaryKey((c) => [...])`, which sets no column-level flag, so such a
|
|
677
|
-
* table yields `never` here exactly as it fails to become a node there.
|
|
678
|
-
*/
|
|
679
|
-
export type NodeKeyFieldOf<T extends AnyTable> = {
|
|
680
|
-
[K in ColumnFieldNamesOf<T>]: ColumnTypeOf<T, K> extends {
|
|
681
|
-
primaryKey: true;
|
|
682
|
-
guid: true;
|
|
683
|
-
} ? K : never;
|
|
684
|
-
}[ColumnFieldNamesOf<T>];
|
|
685
|
-
/** The aliases of a schema that can be addressed by global id. */
|
|
686
|
-
export type NodeAliasesOf<TSchema extends AnySchema> = {
|
|
687
|
-
[K in keyof TSchema["tables"] & string]: [NodeKeyFieldOf<TableByAlias<TSchema, K>>] extends [
|
|
688
|
-
never
|
|
689
|
-
] ? never : K;
|
|
690
|
-
}[keyof TSchema["tables"] & string];
|
|
691
|
-
/**
|
|
692
|
-
* What to do with each member of a set of tables a single call may resolve to — the members
|
|
693
|
-
* of a union, or every node a global id may name.
|
|
694
|
-
*
|
|
695
|
-
* `true` — or leaving the alias out — runs the member as it is; `false` excludes it, so it is
|
|
696
|
-
* gone from the result union and refused at runtime. An object adds member-only arguments: a
|
|
697
|
-
* `select`, a `where` AND-ed with whatever else filters it, and a `join` over its own relations.
|
|
698
|
-
*/
|
|
699
|
-
export type OnSelectionOf<TAliases extends string, TSchema extends AnySchema> = {
|
|
700
|
-
[K in TAliases]?: Pick<QueryArgs<TableByAlias<TSchema, K>, TSchema>, "select" | "where" | "join"> | boolean;
|
|
701
|
-
};
|
|
702
|
-
/** The `on` map `$findByGlobalId` and `$listByGlobalId` take. */
|
|
703
|
-
export type GlobalIdOptionsOf<TSchema extends AnySchema> = OnSelectionOf<NodeAliasesOf<TSchema>, TSchema>;
|
|
704
|
-
/** The query args one member of an `on` map resolves to. */
|
|
705
|
-
type NodeArgsOf<TSchema extends AnySchema, TAlias extends NodeAliasesOf<TSchema>, TOn> = TAlias extends keyof TOn ? TOn[TAlias] extends QueryArgs<TableByAlias<TSchema, TAlias>, TSchema> ? TOn[TAlias] : QueryArgs<TableByAlias<TSchema, TAlias>, TSchema> : QueryArgs<TableByAlias<TSchema, TAlias>, TSchema>;
|
|
706
|
-
/** Whether an `on` map excluded a member outright. */
|
|
707
|
-
type IsExcluded<TAlias extends string, TOn> = TAlias extends keyof TOn ? TOn[TAlias] extends false ? true : false : false;
|
|
708
|
-
/**
|
|
709
|
-
* A resolved node row, tagged with the alias it came from.
|
|
710
|
-
*
|
|
711
|
-
* `$$key` rather than `$$meta.key`, because **TypeScript does not narrow a union on a nested
|
|
712
|
-
* discriminant**: `record.$$meta.key === "authors"` compiles but narrows nothing, while
|
|
713
|
-
* `record.$$key === "authors"` narrows. `$$key` has been a reserved field name since
|
|
714
|
-
* [0004](../../../../../docs/decisions/0004-record-meta.md) for exactly this, and it carries
|
|
715
|
-
* the same value as `$$meta.key`.
|
|
716
|
-
*
|
|
717
|
-
* It is added by the lookup methods, not by the resolver, so an ordinary `findOne` row is
|
|
718
|
-
* unchanged — a single-table read has nothing to discriminate.
|
|
719
|
-
*/
|
|
720
|
-
type TaggedNodeOf<TSchema extends AnySchema, TAlias extends NodeAliasesOf<TSchema>, TOn> = Prettify<{
|
|
721
|
-
$$key: TAlias;
|
|
722
|
-
} & QueryResultOf<TableByAlias<TSchema, TAlias>, TSchema, NodeArgsOf<TSchema, TAlias, TOn>>>;
|
|
723
|
-
/**
|
|
724
|
-
* The row a global id resolves to: a union over every node the schema declares, narrowed by
|
|
725
|
-
* the caller's `on` map, discriminated by `$$key`.
|
|
726
|
-
*/
|
|
727
|
-
export type GlobalIdResultOf<TSchema extends AnySchema, TOn = undefined> = {
|
|
728
|
-
[K in NodeAliasesOf<TSchema>]: IsExcluded<K, TOn> extends true ? never : TaggedNodeOf<TSchema, K, TOn>;
|
|
729
|
-
}[NodeAliasesOf<TSchema>] | null;
|
|
730
|
-
/**
|
|
731
|
-
* As {@link GlobalIdResultOf}, with the node's key field forced into every selection.
|
|
732
|
-
*
|
|
733
|
-
* `$listByGlobalId` returns rows in the order the ids were given, which means matching each
|
|
734
|
-
* row back to the id that asked for it — and the only thing that can do that is the key
|
|
735
|
-
* itself. So it is always projected, even when `select` leaves it out.
|
|
736
|
-
*/
|
|
737
|
-
export type GlobalIdListResultOf<TSchema extends AnySchema, TOn = undefined> = {
|
|
738
|
-
[K in NodeAliasesOf<TSchema>]: IsExcluded<K, TOn> extends true ? never : Prettify<{
|
|
739
|
-
$$key: K;
|
|
740
|
-
} & QueryResultOf<TableByAlias<TSchema, K>, TSchema, NodeArgsOf<TSchema, K, TOn> extends {
|
|
741
|
-
select: infer TSelect;
|
|
742
|
-
} ? Omit<NodeArgsOf<TSchema, K, TOn>, "select"> & {
|
|
743
|
-
select: TSelect & Record<NodeKeyFieldOf<TableByAlias<TSchema, K>>, true> & FieldSelectionOf<TableByAlias<TSchema, K>>;
|
|
744
|
-
} : NodeArgsOf<TSchema, K, TOn>>>;
|
|
745
|
-
}[NodeAliasesOf<TSchema>];
|
|
746
|
-
export {};
|
|
747
|
-
//# sourceMappingURL=base.d.ts.map
|