@lunora/server 1.0.0-alpha.29 → 1.0.0-alpha.291
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/LICENSE.md +414 -104
- package/README.md +21 -15
- package/dist/data-model.d.mts +328 -78
- package/dist/data-model.d.ts +328 -78
- package/dist/data-model.mjs +0 -1
- package/dist/drizzle.mjs +1 -1
- package/dist/in-process.d.mts +115 -0
- package/dist/in-process.d.ts +115 -0
- package/dist/in-process.mjs +1 -0
- package/dist/index.d.mts +3615 -1125
- package/dist/index.d.ts +3615 -1125
- package/dist/index.mjs +1 -29
- package/dist/otel.d.mts +649 -0
- package/dist/otel.d.ts +649 -0
- package/dist/otel.mjs +1 -0
- package/dist/packem_shared/ACTION_CACHE_DEFAULT_TTL_MS-Dv4DKrj0.mjs +1 -0
- package/dist/packem_shared/DEFAULT_LIMIT-z7HB19s7.mjs +1 -0
- package/dist/packem_shared/DOCUMENT_HISTORY_REDACTED_FIELDS-BCa6sLSJ.mjs +1 -0
- package/dist/packem_shared/LunoraEnvError-06_Zc4yc.mjs +3 -0
- package/dist/packem_shared/PRESENCE_DEFAULT_TTL_MS-aj9Ec70J.mjs +1 -0
- package/dist/packem_shared/PROCEDURE_META-DVzrXpfa.mjs +1 -0
- package/dist/packem_shared/allowAll-DkRAgItV.mjs +1 -0
- package/dist/packem_shared/apply-output-C5wZ5EAL.mjs +1 -0
- package/dist/packem_shared/asBucketStorage-DoGYOjq3.mjs +1 -0
- package/dist/packem_shared/assertShapesDeclareReadPolicies-B9Kat3xb.mjs +1 -0
- package/dist/packem_shared/authorize-CVLZJxf_.mjs +1 -0
- package/dist/packem_shared/beginDeferredDeletes-DhwFBbvs.mjs +1 -0
- package/dist/packem_shared/beginDeferredSchedules-BOsY07vZ.mjs +1 -0
- package/dist/packem_shared/bindOrm-DjpQXKLX.mjs +1 -0
- package/dist/packem_shared/buildMaskRegistry-DpWMtalG.mjs +1 -0
- package/dist/packem_shared/compose-middleware-BK9FlblN.mjs +1 -0
- package/dist/packem_shared/composePluginMiddleware-3e7F9JIa.mjs +1 -0
- package/dist/packem_shared/context-identity-B2XYGA0B.mjs +1 -0
- package/dist/packem_shared/createPolicyDsl-BZa6SqLJ.mjs +1 -0
- package/dist/packem_shared/createSecrets-D6rLB42U.mjs +1 -0
- package/dist/packem_shared/createServices-IJvoqi0e.mjs +1 -0
- package/dist/packem_shared/defineAggregateIndex-C3xWV-Dr.mjs +1 -0
- package/dist/packem_shared/defineIdentity-DwkNKwYa.mjs +1 -0
- package/dist/packem_shared/defineIdentityGuard-Bt8N65Zs.mjs +1 -0
- package/dist/packem_shared/defineLiveStream-D3xRvNDy.mjs +1 -0
- package/dist/packem_shared/defineMigration-CXOS0Bvq.mjs +1 -0
- package/dist/packem_shared/defineModule-OecXWM3U.mjs +1 -0
- package/dist/packem_shared/defineMutator-DlLFSWbO.mjs +1 -0
- package/dist/packem_shared/defineRoom-CoGi-xwm.mjs +1 -0
- package/dist/packem_shared/defineShape-BE1Drcby.mjs +1 -0
- package/dist/packem_shared/defineStorageRule-Dv4nJE0H.mjs +1 -0
- package/dist/packem_shared/defineWebSocket-BHoy6_ox.mjs +1 -0
- package/dist/packem_shared/fnv1a-D3ueNTWB.mjs +1 -0
- package/dist/packem_shared/functions-QFoBUe9t.mjs +1 -0
- package/dist/packem_shared/httpAction-DD8h1jcf.mjs +1 -0
- package/dist/packem_shared/initLunora-DcvCGLL_.mjs +1 -0
- package/dist/packem_shared/isPerDispatchMiddleware-DDQPatSm.mjs +1 -0
- package/dist/packem_shared/isSafeHeaderValue-DswDADFy.mjs +6 -0
- package/dist/packem_shared/mask-BdHDaOeI.mjs +1 -0
- package/dist/packem_shared/middleware-6q14NoEG.mjs +1 -0
- package/dist/packem_shared/onConnect-BLRoOpv2.mjs +1 -0
- package/dist/packem_shared/onQueryChange-iuLzmyPs.mjs +1 -0
- package/dist/packem_shared/onWhisper-CfDbFLQh.mjs +1 -0
- package/dist/packem_shared/platformAdmin-kczXQme8.mjs +1 -0
- package/dist/packem_shared/plugin-CyLqvCB9.mjs +1 -0
- package/dist/packem_shared/policy-tag-V0lqFzgS.mjs +1 -0
- package/dist/packem_shared/protectPublic-Bi5_95aP.mjs +1 -0
- package/dist/packem_shared/redact-secrets-BpatNz48.mjs +2 -0
- package/dist/packem_shared/redactSecrets-Dmh9pHZu.mjs +1 -0
- package/dist/packem_shared/rls-QoHmZEia.mjs +1 -0
- package/dist/packem_shared/run-middleware-BefYq7Xd.mjs +1 -0
- package/dist/packem_shared/serveStorageObject-CLz3qhNI.mjs +1 -0
- package/dist/packem_shared/storageRules-gnLtvRbZ.mjs +1 -0
- package/dist/packem_shared/types.d--zaGh3rX.d.mts +3025 -0
- package/dist/packem_shared/types.d--zaGh3rX.d.ts +3025 -0
- package/dist/packem_shared/{types.d-C4CMJK8x.d.mts → types.d-B7FLdYUD.d.mts} +15 -8
- package/dist/packem_shared/{types.d-DdYF8E18.d.ts → types.d-BCtjbIzl.d.ts} +15 -8
- package/dist/rls/testing.d.mts +13 -5
- package/dist/rls/testing.d.ts +13 -5
- package/dist/rls/testing.mjs +1 -49
- package/dist/types.d.mts +2 -1468
- package/dist/types.d.ts +2 -1468
- package/dist/types.mjs +0 -31
- package/package.json +28 -8
- package/dist/packem_shared/LunoraEnvError-BGmd1Qs0.mjs +0 -187
- package/dist/packem_shared/LunoraError-WbxmrpxR.mjs +0 -9
- package/dist/packem_shared/PRESENCE_DEFAULT_TTL_MS-Cv1UPaJj.mjs +0 -114
- package/dist/packem_shared/asBucketStorage-Cnxd9y2q.mjs +0 -11
- package/dist/packem_shared/bindOrm-Bfgl7f-Q.mjs +0 -146
- package/dist/packem_shared/buildRlsReadRegistry-D54vUQe4.mjs +0 -107
- package/dist/packem_shared/composePluginMiddleware-z62dttBo.mjs +0 -103
- package/dist/packem_shared/createPolicyDsl-By3QB4he.mjs +0 -32
- package/dist/packem_shared/createSecrets-DwaR2rNG.mjs +0 -58
- package/dist/packem_shared/defineAggregateIndex-DTULzh09.mjs +0 -333
- package/dist/packem_shared/defineIdentity-DiX4zM9x.mjs +0 -35
- package/dist/packem_shared/defineMigration-Hx01yIht.mjs +0 -10
- package/dist/packem_shared/defineMutator-EIXAWhs9.mjs +0 -11
- package/dist/packem_shared/defineShape-C5scNOrf.mjs +0 -18
- package/dist/packem_shared/defineStorageRule-B5nL4Z1P.mjs +0 -23
- package/dist/packem_shared/functions-Di9FUNkf.mjs +0 -5
- package/dist/packem_shared/httpAction-DCXoYPIk.mjs +0 -355
- package/dist/packem_shared/initLunora-CmMVk4i7.mjs +0 -107
- package/dist/packem_shared/mask-CZuu9WAF.mjs +0 -331
- package/dist/packem_shared/onConnect-CIPXKPyw.mjs +0 -13
- package/dist/packem_shared/policy-tag-DvpVH2tv.mjs +0 -13
- package/dist/packem_shared/protectPublic-BlcGpiRc.mjs +0 -15
- package/dist/packem_shared/rls-B_ZWgslr.mjs +0 -595
- package/dist/packem_shared/run-middleware-I6EiQfxL.mjs +0 -20
- package/dist/packem_shared/storageRules-6QxzDOcx.mjs +0 -88
package/dist/data-model.d.mts
CHANGED
|
@@ -20,6 +20,130 @@
|
|
|
20
20
|
* so this module needs no reference to the project-local `OneRelation` /
|
|
21
21
|
* `ManyRelation` aliases the codegen still emits.
|
|
22
22
|
*/
|
|
23
|
+
/**
|
|
24
|
+
* A value stored as a plain JS object: not a scalar (an `Id<T>` is a branded string, which is an `object` to
|
|
25
|
+
* TypeScript but has no keys worth offering), an array, a date, bytes, a bigint or a function.
|
|
26
|
+
*/
|
|
27
|
+
type IsPlainObject<V> = V extends string | number | boolean | bigint | symbol ? false : V extends ReadonlyArray<unknown> ? false : V extends Date | Uint8Array | ArrayBuffer | bigint | ((...arguments_: never[]) => unknown) ? false : V extends object ? true : false;
|
|
28
|
+
/** The dotted paths below an object, to three steps. */
|
|
29
|
+
type SubPaths<V, Depth extends unknown[]> = Depth["length"] extends 3 ? never : [IsPlainObject<V>] extends [true] ? { [K in keyof V & string]-?: K | `${K}.${SubPaths<NonNullable<V[K]>, [...Depth, 0]>}`; }[keyof V & string] : never;
|
|
30
|
+
/** The type at the end of dotted path `P` below `V`. */
|
|
31
|
+
type PathValue<V, P extends string> = P extends `${infer Head}.${infer Rest}` ? Head extends keyof V ? PathValue<NonNullable<V[Head]>, Rest> : never : P extends keyof V ? V[P] : never;
|
|
32
|
+
/**
|
|
33
|
+
* Every dotted path into an object-valued column of `Doc` (`"profile.address.city"`), at most four segments
|
|
34
|
+
* counting the column. A column that is not a plain object contributes none.
|
|
35
|
+
*/
|
|
36
|
+
type ColumnPaths<Doc> = { [K in keyof Doc & string]-?: [IsPlainObject<NonNullable<Doc[K]>>] extends [true] ? `${K}.${SubPaths<NonNullable<Doc[K]>, []>}` : never; }[keyof Doc & string];
|
|
37
|
+
/** The type at the end of a {@link ColumnPaths} path. */
|
|
38
|
+
type DocPathValue<Doc, P extends string> = P extends `${infer Column}.${infer Rest}` ? Column extends keyof Doc ? PathValue<NonNullable<Doc[Column]>, Rest> : never : never;
|
|
39
|
+
type ScalarLeaf = boolean | number | string | null | undefined;
|
|
40
|
+
/** The dotted paths into an object column that end at a string, number or boolean. */
|
|
41
|
+
type ScalarPaths<Doc> = { [P in ColumnPaths<Doc>]: [DocPathValue<Doc, P>] extends [ScalarLeaf] ? P : never; }[ColumnPaths<Doc>];
|
|
42
|
+
/**
|
|
43
|
+
* `where` keys that reach into an object column: `{ "profile.plan": "pro" }`. Only paths that end at a string,
|
|
44
|
+
* number or boolean are offered — an object, array, date, bigint or bytes leaf has no single SQL comparison.
|
|
45
|
+
*
|
|
46
|
+
* `unknown` (the identity for `&`) when there are none, never `{}`: intersecting with an empty object type
|
|
47
|
+
* switches off the weak-type check that rejects a `where` key naming nothing.
|
|
48
|
+
*/
|
|
49
|
+
type PathWhere<Doc, Paths extends string = ScalarPaths<Doc>> = [Paths] extends [never] ? unknown : { [P in Paths]?: DocPathValue<Doc, P> | WhereOperators<DocPathValue<Doc, P>>; };
|
|
50
|
+
/** `patch` keys that set one value inside an object column, keeping its siblings: `{ "profile.plan": "pro" }`. */
|
|
51
|
+
type PathPatch<Doc, Paths extends string = ColumnPaths<Doc>> = [Paths] extends [never] ? unknown : { [P in Paths]?: DocPathValue<Doc, P>; };
|
|
52
|
+
/**
|
|
53
|
+
* The relation-predicate portion of {@link WhereOf}: each declared relation on
|
|
54
|
+
* `T` contributes a kind-dispatched node — `one` → `{ is?; isNot? }`, `many` →
|
|
55
|
+
* `{ some?; none?; every? }` — whose inner type is the target table's own
|
|
56
|
+
* relation-aware `where` (so multi-hop predicates type-check inside-out).
|
|
57
|
+
*/
|
|
58
|
+
type RelationWhere<DM, REL extends Record<keyof DM, object>, T extends keyof DM> = { [K in keyof REL[T]]?: REL[T][K] extends {
|
|
59
|
+
__relationKind: "one";
|
|
60
|
+
__target: infer Target extends keyof DM;
|
|
61
|
+
} ? OneRelationWhere<WhereOf<DM, REL, Target>> : REL[T][K] extends {
|
|
62
|
+
__relationKind: "many";
|
|
63
|
+
__target: infer Target extends keyof DM;
|
|
64
|
+
} ? ManyRelationWhere<WhereOf<DM, REL, Target>> : never; };
|
|
65
|
+
/** The nested `with` sub-argument inside a relation's with-value, or `{}`. */
|
|
66
|
+
type NestedWithArgument<WK> = WK extends {
|
|
67
|
+
with: infer NW;
|
|
68
|
+
} ? NW : {};
|
|
69
|
+
/** The nested `select` tuple inside a relation's with-value, or `undefined` (no projection). */
|
|
70
|
+
type NestedSelectArgument<WK> = WK extends {
|
|
71
|
+
select: infer S;
|
|
72
|
+
} ? S : undefined;
|
|
73
|
+
/**
|
|
74
|
+
* Resolve a single relation descriptor + its with-value to the loaded type,
|
|
75
|
+
* threading the nested `select` tuple into the projected child shape (the 5th
|
|
76
|
+
* `LoadWith` arg) so `with: { author: { select: ["name"] } }` narrows the loaded
|
|
77
|
+
* `author` to the selected columns + system fields.
|
|
78
|
+
*/
|
|
79
|
+
type LoadRelation<DM, REL extends Record<keyof DM, object>, R, WK> = R extends {
|
|
80
|
+
__relationKind: "one";
|
|
81
|
+
__target: infer Target extends keyof DM;
|
|
82
|
+
} ? LoadWith<DM, REL, Target, NestedWithArgument<WK>, NestedSelectArgument<WK>> | null : R extends {
|
|
83
|
+
__relationKind: "many";
|
|
84
|
+
__target: infer Target extends keyof DM;
|
|
85
|
+
} ? LoadWith<DM, REL, Target, NestedWithArgument<WK>, NestedSelectArgument<WK>>[] : never;
|
|
86
|
+
/** The relation keys of `W` that were actually requested (not `false`/`undefined`). */
|
|
87
|
+
type LoadedRelations<DM, REL extends Record<keyof DM, object>, T extends keyof DM, W> = { [K in keyof W as K extends keyof REL[T] ? (W[K] extends false | undefined ? never : K) : never]: K extends keyof REL[T] ? LoadRelation<DM, REL, REL[T][K], W[K]> : never; };
|
|
88
|
+
/** The `_count` projection of `W`, if any. */
|
|
89
|
+
type LoadedCount<W> = W extends {
|
|
90
|
+
_count: infer C;
|
|
91
|
+
} ? {
|
|
92
|
+
_count: { [K in keyof C]: number; };
|
|
93
|
+
} : {};
|
|
94
|
+
/** System columns a `select` projection always retains, so cursors and by-id reuse keep working. */
|
|
95
|
+
type SelectAlwaysKeep<DM, T extends keyof DM> = ("_creationTime" | "_id") & keyof DM[T];
|
|
96
|
+
/**
|
|
97
|
+
* `DM[T]` narrowed to the columns named by a `select` tuple `S` (plus the system
|
|
98
|
+
* fields). `undefined` (the default — no `select`) keeps the full document.
|
|
99
|
+
*/
|
|
100
|
+
type ProjectDoc<DM, T extends keyof DM, S> = S extends ReadonlyArray<infer K> ? (K extends keyof DM[T] ? Pick<DM[T], (K & keyof DM[T]) | SelectAlwaysKeep<DM, T>> : DM[T]) : DM[T];
|
|
101
|
+
/**
|
|
102
|
+
* An atomic update for a number column, applied to the value the row holds when the
|
|
103
|
+
* write runs: `{ increment: 1 }`, `{ decrement: 1 }`, `{ multiply: 2 }`, `{ divide: 2 }`.
|
|
104
|
+
* The column must already hold a finite number; a result that is not finite is rejected.
|
|
105
|
+
*/
|
|
106
|
+
type NumberFieldOperator = {
|
|
107
|
+
decrement: number;
|
|
108
|
+
divide?: never;
|
|
109
|
+
increment?: never;
|
|
110
|
+
multiply?: never;
|
|
111
|
+
} | {
|
|
112
|
+
decrement?: never;
|
|
113
|
+
divide: number;
|
|
114
|
+
increment?: never;
|
|
115
|
+
multiply?: never;
|
|
116
|
+
} | {
|
|
117
|
+
decrement?: never;
|
|
118
|
+
divide?: never;
|
|
119
|
+
increment: number;
|
|
120
|
+
multiply?: never;
|
|
121
|
+
} | {
|
|
122
|
+
decrement?: never;
|
|
123
|
+
divide?: never;
|
|
124
|
+
increment?: never;
|
|
125
|
+
multiply: number;
|
|
126
|
+
};
|
|
127
|
+
/** An atomic update for a boolean column: `{ toggle: true }` flips the stored value. */
|
|
128
|
+
interface BooleanFieldOperator {
|
|
129
|
+
toggle: true;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* The operator a column of type `T` takes: arithmetic when `T` is exactly `number` (so a literal union
|
|
133
|
+
* such as `1 | 2` is out — the result could leave the set — and so is `number | string`, which the
|
|
134
|
+
* store does not treat as a number column), `{ toggle: true }` when it is exactly `boolean`.
|
|
135
|
+
*/
|
|
136
|
+
type OperatorFor<T> = [T] extends [number] ? [number] extends [T] ? NumberFieldOperator : never : [T] extends [boolean] ? [boolean] extends [T] ? BooleanFieldOperator : never : never;
|
|
137
|
+
/** The foreign-key columns of a table's to-one relations — the keys a nested `connect` supplies. */
|
|
138
|
+
type OneRelationFields<RelT> = { [K in keyof RelT]: RelT[K] extends {
|
|
139
|
+
__field: infer Field extends string;
|
|
140
|
+
__relationKind: "one";
|
|
141
|
+
} ? Field : never; }[keyof RelT];
|
|
142
|
+
/**
|
|
143
|
+
* The `where` operand for one column. An optional column reads back absent, never `null`, yet it is stored as SQL NULL,
|
|
144
|
+
* so `null` is how a filter asks for "not set" (`IS NULL`, as `isNull: true` does).
|
|
145
|
+
*/
|
|
146
|
+
type ColumnWhere<TValue> = undefined extends TValue ? TValue | WhereOperators<TValue | null> | null : TValue | WhereOperators<TValue>;
|
|
23
147
|
/** A branded id for table `TName`. Structurally a `string` at runtime. */
|
|
24
148
|
type Id<TName extends string> = string & {
|
|
25
149
|
readonly __table: TName;
|
|
@@ -38,13 +162,23 @@ interface WhereOperators<T> {
|
|
|
38
162
|
notIn?: T[];
|
|
39
163
|
}
|
|
40
164
|
/** A typed `where` tree over a document's columns. */
|
|
41
|
-
type Where<TDocument> = { [K in keyof TDocument]?:
|
|
165
|
+
type Where<TDocument> = PathWhere<TDocument> & { [K in keyof TDocument]?: ColumnWhere<TDocument[K]>; } & {
|
|
42
166
|
AND?: Where<TDocument>[];
|
|
43
167
|
NOT?: Where<TDocument>;
|
|
44
168
|
OR?: Where<TDocument>[];
|
|
45
169
|
};
|
|
46
|
-
/**
|
|
47
|
-
|
|
170
|
+
/**
|
|
171
|
+
* One ordering entry; `orderBy` is an ordered list. `{ field: "asc" | "desc" }` sorts NULLs first
|
|
172
|
+
* ascending and last descending. `{ field: { sort: "desc", nulls: "first" } }` places them yourself.
|
|
173
|
+
*
|
|
174
|
+
* A placement other than the default can change the query plan (see Pagination in the docs), so
|
|
175
|
+
* measure a hot read. It has no effect on a column that cannot hold NULL. Keep the same `orderBy` for every page of a
|
|
176
|
+
* paginated read, as a cursor is only valid against the ordering that minted it.
|
|
177
|
+
*/
|
|
178
|
+
type OrderBy<TDocument> = Partial<Record<keyof TDocument | ScalarPaths<TDocument>, "asc" | "desc" | {
|
|
179
|
+
nulls: "first" | "last";
|
|
180
|
+
sort: "asc" | "desc";
|
|
181
|
+
}>>;
|
|
48
182
|
interface QueryArgs<TDocument> {
|
|
49
183
|
cursor?: null | string;
|
|
50
184
|
limit?: number;
|
|
@@ -77,33 +211,33 @@ interface ManyRelationWhere<W> {
|
|
|
77
211
|
none?: W;
|
|
78
212
|
some?: W;
|
|
79
213
|
}
|
|
80
|
-
/**
|
|
81
|
-
* The relation-predicate portion of {@link WhereOf}: each declared relation on
|
|
82
|
-
* `T` contributes a kind-dispatched node — `one` → `{ is?; isNot? }`, `many` →
|
|
83
|
-
* `{ some?; none?; every? }` — whose inner type is the target table's own
|
|
84
|
-
* relation-aware `where` (so multi-hop predicates type-check inside-out).
|
|
85
|
-
*/
|
|
86
|
-
type RelationWhere<DM, REL extends Record<keyof DM, object>, T extends keyof DM> = { [K in keyof REL[T]]?: REL[T][K] extends {
|
|
87
|
-
__relationKind: "one";
|
|
88
|
-
__target: infer Target extends keyof DM;
|
|
89
|
-
} ? OneRelationWhere<WhereOf<DM, REL, Target>> : REL[T][K] extends {
|
|
90
|
-
__relationKind: "many";
|
|
91
|
-
__target: infer Target extends keyof DM;
|
|
92
|
-
} ? ManyRelationWhere<WhereOf<DM, REL, Target>> : never; };
|
|
93
214
|
/**
|
|
94
215
|
* Relation-aware `where` tree — the column predicates of {@link Where} plus
|
|
95
216
|
* Prisma-style relation predicates resolved by the `@lunora/do` pre-resolver.
|
|
96
|
-
* `Where
|
|
217
|
+
* `Where<DM[T]>` stays the column-only structural mirror for back-compat; the
|
|
97
218
|
* table facade threads `REL` through this richer form.
|
|
98
219
|
*/
|
|
99
|
-
type WhereOf<DM, REL extends Record<keyof DM, object>, T extends keyof DM> = RelationWhere<DM, REL, T> & { [K in keyof DM[T]]?:
|
|
220
|
+
type WhereOf<DM, REL extends Record<keyof DM, object>, T extends keyof DM> = PathWhere<DM[T]> & RelationWhere<DM, REL, T> & { [K in keyof DM[T]]?: ColumnWhere<DM[T][K]>; } & {
|
|
100
221
|
AND?: WhereOf<DM, REL, T>[];
|
|
101
222
|
NOT?: WhereOf<DM, REL, T>;
|
|
102
223
|
OR?: WhereOf<DM, REL, T>[];
|
|
103
224
|
};
|
|
104
225
|
/** {@link QueryArgs} with the relation-aware {@link WhereOf} `where` typing. */
|
|
105
226
|
interface QueryArgsOf<DM, REL extends Record<keyof DM, object>, T extends keyof DM> {
|
|
227
|
+
/** Read the authoritative copy, not a replica. Only a `.global()` D1 table can lag; shard-local reads are already authoritative. */
|
|
228
|
+
consistency?: "primary";
|
|
106
229
|
cursor?: null | string;
|
|
230
|
+
/**
|
|
231
|
+
* Pin the page's end to an earlier page's `continueCursor`, for reactive pagination: the read is
|
|
232
|
+
* the fixed range `(cursor, endCursor]` under this call's `orderBy`, so a row inserted inside it
|
|
233
|
+
* grows this page and the next page (starting at `endCursor`) is unchanged. The result is
|
|
234
|
+
* `isDone: true`, echoes `endCursor` as `continueCursor`, and carries `splitCursor`.
|
|
235
|
+
*
|
|
236
|
+
* `limit` still caps the read. A range it cuts short answers `splitRequired: true`, and the
|
|
237
|
+
* client splits it at `splitCursor`, so the rows past the cap come back in the second half. On
|
|
238
|
+
* a `.global()` table a read with no `limit` is capped at 4096 rows the same way.
|
|
239
|
+
*/
|
|
240
|
+
endCursor?: null | string;
|
|
107
241
|
/**
|
|
108
242
|
* Include soft-deleted rows (`.softDelete()` tables only). Default hides them;
|
|
109
243
|
* `true` returns deleted rows alongside live ones. No effect on a table
|
|
@@ -118,15 +252,17 @@ interface QueryPage<TDocument> {
|
|
|
118
252
|
continueCursor: null | string;
|
|
119
253
|
isDone: boolean;
|
|
120
254
|
page: TDocument[];
|
|
255
|
+
/**
|
|
256
|
+
* Only on an `endCursor` read: the cursor of the page's midpoint row, `null` under two rows. Paging
|
|
257
|
+
* `(cursor, splitCursor]` and `(splitCursor, endCursor]` reproduces the range in two halves.
|
|
258
|
+
*/
|
|
259
|
+
splitCursor?: null | string;
|
|
260
|
+
/**
|
|
261
|
+
* Only on an `endCursor` read that `limit` (or the global read cap) cut short: the page holds
|
|
262
|
+
* the first rows of its range, and splitting at `splitCursor` is the way to reach the rest.
|
|
263
|
+
*/
|
|
264
|
+
splitRequired?: boolean;
|
|
121
265
|
}
|
|
122
|
-
/** The nested `with` sub-argument inside a relation's with-value, or `{}`. */
|
|
123
|
-
type NestedWithArgument<WK> = WK extends {
|
|
124
|
-
with: infer NW;
|
|
125
|
-
} ? NW : {};
|
|
126
|
-
/** The nested `select` tuple inside a relation's with-value, or `undefined` (no projection). */
|
|
127
|
-
type NestedSelectArgument<WK> = WK extends {
|
|
128
|
-
select: infer S;
|
|
129
|
-
} ? S : undefined;
|
|
130
266
|
/**
|
|
131
267
|
* The `with` argument for table `T`: each relation can be `true` (load with no
|
|
132
268
|
* refinements) or an object. `many` relations accept `where`/`orderBy`/`limit`/
|
|
@@ -148,35 +284,7 @@ type WithArg<DM, REL extends Record<keyof DM, object>, T extends keyof DM> = { [
|
|
|
148
284
|
_count?: { [K in keyof REL[T]]?: true; };
|
|
149
285
|
};
|
|
150
286
|
/**
|
|
151
|
-
*
|
|
152
|
-
* threading the nested `select` tuple into the projected child shape (the 5th
|
|
153
|
-
* `LoadWith` arg) so `with: { author: { select: ["name"] } }` narrows the loaded
|
|
154
|
-
* `author` to the selected columns + system fields.
|
|
155
|
-
*/
|
|
156
|
-
type LoadRelation<DM, REL extends Record<keyof DM, object>, R, WK> = R extends {
|
|
157
|
-
__relationKind: "one";
|
|
158
|
-
__target: infer Target extends keyof DM;
|
|
159
|
-
} ? LoadWith<DM, REL, Target, NestedWithArgument<WK>, NestedSelectArgument<WK>> | null : R extends {
|
|
160
|
-
__relationKind: "many";
|
|
161
|
-
__target: infer Target extends keyof DM;
|
|
162
|
-
} ? LoadWith<DM, REL, Target, NestedWithArgument<WK>, NestedSelectArgument<WK>>[] : never;
|
|
163
|
-
/** The relation keys of `W` that were actually requested (not `false`/`undefined`). */
|
|
164
|
-
type LoadedRelations<DM, REL extends Record<keyof DM, object>, T extends keyof DM, W> = { [K in keyof W as K extends keyof REL[T] ? (W[K] extends false | undefined ? never : K) : never]: K extends keyof REL[T] ? LoadRelation<DM, REL, REL[T][K], W[K]> : never; };
|
|
165
|
-
/** The `_count` projection of `W`, if any. */
|
|
166
|
-
type LoadedCount<W> = W extends {
|
|
167
|
-
_count: infer C;
|
|
168
|
-
} ? {
|
|
169
|
-
_count: { [K in keyof C]: number; };
|
|
170
|
-
} : {};
|
|
171
|
-
/** System columns a `select` projection always retains, so cursors and by-id reuse keep working. */
|
|
172
|
-
type SelectAlwaysKeep<DM, T extends keyof DM> = ("_creationTime" | "_id") & keyof DM[T];
|
|
173
|
-
/**
|
|
174
|
-
* `DM[T]` narrowed to the columns named by a `select` tuple `S` (plus the system
|
|
175
|
-
* fields). `undefined` (the default — no `select`) keeps the full document.
|
|
176
|
-
*/
|
|
177
|
-
type ProjectDoc<DM, T extends keyof DM, S> = S extends ReadonlyArray<infer K> ? (K extends keyof DM[T] ? Pick<DM[T], (K & keyof DM[T]) | SelectAlwaysKeep<DM, T>> : DM[T]) : DM[T];
|
|
178
|
-
/**
|
|
179
|
-
* `Doc<T>` narrowed to exactly the relations requested in the with-arg `W` and,
|
|
287
|
+
* `Doc<T>` narrowed to exactly the relations requested in the with-arg `W` and,
|
|
180
288
|
* when a `select` tuple `S` is supplied, to its projected columns. `S` defaults
|
|
181
289
|
* to `undefined` so the 4-argument form (the codegen-emitted callers) keeps the
|
|
182
290
|
* full document.
|
|
@@ -207,7 +315,7 @@ interface RestrictableQueryOptionsOf<DM, REL extends Record<keyof DM, object>, T
|
|
|
207
315
|
restrictsCounts?: boolean;
|
|
208
316
|
where?: WhereOf<DM, REL, T>;
|
|
209
317
|
}
|
|
210
|
-
/** Args for `ctx.db
|
|
318
|
+
/** Args for `ctx.db.<table>.aggregate({ op, field?, where? })`. */
|
|
211
319
|
interface TableAggregateOptions<TDocument> extends RestrictableQueryOptions<TDocument> {
|
|
212
320
|
field?: keyof TDocument & string;
|
|
213
321
|
op: AggregateOp;
|
|
@@ -217,7 +325,7 @@ interface TableAggregateOptionsOf<DM, REL extends Record<keyof DM, object>, T ex
|
|
|
217
325
|
field?: keyof DM[T] & string;
|
|
218
326
|
op: AggregateOp;
|
|
219
327
|
}
|
|
220
|
-
/** Args for `ctx.db
|
|
328
|
+
/** Args for `ctx.db.<table>.groupBy({ by, agg?, where? })`. */
|
|
221
329
|
interface TableGroupByOptions<TDocument> extends RestrictableQueryOptions<TDocument> {
|
|
222
330
|
agg?: {
|
|
223
331
|
field?: keyof TDocument & string;
|
|
@@ -238,7 +346,7 @@ interface GroupByEntry<TDocument> {
|
|
|
238
346
|
key: Partial<TDocument>;
|
|
239
347
|
value: null | number;
|
|
240
348
|
}
|
|
241
|
-
/** Args for `ctx.db
|
|
349
|
+
/** Args for `ctx.db.<table>.rank(name, args)`. `row` is either an id or a row doc. */
|
|
242
350
|
interface TableRankOptions<TDocument> extends RestrictableQueryOptions<TDocument> {
|
|
243
351
|
row: string | TDocument;
|
|
244
352
|
}
|
|
@@ -247,7 +355,7 @@ interface RankResult {
|
|
|
247
355
|
position: number;
|
|
248
356
|
total: number;
|
|
249
357
|
}
|
|
250
|
-
/** Args for `ctx.db
|
|
358
|
+
/** Args for `ctx.db.<table>.rankPage(name, args)`. */
|
|
251
359
|
interface TableRankPageOptions<TDocument> extends RestrictableQueryOptions<TDocument> {
|
|
252
360
|
cursor?: null | string;
|
|
253
361
|
take?: number;
|
|
@@ -275,12 +383,63 @@ interface SearchFilterBuilder<TDocument> {
|
|
|
275
383
|
*/
|
|
276
384
|
interface SearchReader<TDocument> {
|
|
277
385
|
collect: () => Promise<TDocument[]>;
|
|
386
|
+
/**
|
|
387
|
+
* Like `.collect()`, but pairs each matched document with the relevance
|
|
388
|
+
* score the FTS engine already computed to produce the descending order —
|
|
389
|
+
* `.collect()` throws it away after sorting by it, this surfaces it
|
|
390
|
+
* instead. Ordered by `score` descending, same order as `.collect()`.
|
|
391
|
+
*/
|
|
392
|
+
collectWithScores: () => Promise<{
|
|
393
|
+
document: TDocument;
|
|
394
|
+
score: number;
|
|
395
|
+
}[]>;
|
|
396
|
+
first: () => Promise<TDocument | null>;
|
|
397
|
+
take: (limit: number) => Promise<TDocument[]>;
|
|
398
|
+
unique: () => Promise<TDocument | null>;
|
|
399
|
+
}
|
|
400
|
+
/** A latitude/longitude point (WGS84 decimal degrees) accepted by geo queries. */
|
|
401
|
+
interface GeoPointInput {
|
|
402
|
+
lat: number;
|
|
403
|
+
lng: number;
|
|
404
|
+
}
|
|
405
|
+
/** An axis-aligned latitude/longitude bounding box (`sw`/`ne` corners). */
|
|
406
|
+
interface GeoBoundingBox {
|
|
407
|
+
ne: GeoPointInput;
|
|
408
|
+
sw: GeoPointInput;
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* Builder passed to `.withGeoIndex(name, q => …)`. Call exactly one of
|
|
412
|
+
* `.near(point, radiusMeters)` (proximity, nearest-first) or `.within(box)`
|
|
413
|
+
* (bounding-box).
|
|
414
|
+
*/
|
|
415
|
+
interface GeoFilterBuilder {
|
|
416
|
+
near: (point: GeoPointInput, radiusMeters: number) => GeoFilterBuilder;
|
|
417
|
+
within: (box: GeoBoundingBox) => GeoFilterBuilder;
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* Chainable reader returned by `.withGeoIndex()`. `.near()` results come back
|
|
421
|
+
* ordered nearest-first; `.within()` results by row creation time. `.paginate()`
|
|
422
|
+
* is intentionally absent — cap the result set with `.take(n)`.
|
|
423
|
+
*/
|
|
424
|
+
interface GeoReader<TDocument> {
|
|
425
|
+
collect: () => Promise<TDocument[]>;
|
|
426
|
+
/**
|
|
427
|
+
* Like `.collect()`, but pairs each matched document with the distance
|
|
428
|
+
* (in meters) from `.near()`'s point that the read already computed to
|
|
429
|
+
* produce the nearest-first order. `.within()` box matches have no
|
|
430
|
+
* point-distance metric, so `distanceMeters` is `null` for those rows
|
|
431
|
+
* rather than a misleading `0`.
|
|
432
|
+
*/
|
|
433
|
+
collectWithScores: () => Promise<{
|
|
434
|
+
distanceMeters: null | number;
|
|
435
|
+
document: TDocument;
|
|
436
|
+
}[]>;
|
|
278
437
|
first: () => Promise<TDocument | null>;
|
|
279
438
|
take: (limit: number) => Promise<TDocument[]>;
|
|
280
439
|
unique: () => Promise<TDocument | null>;
|
|
281
440
|
}
|
|
282
|
-
/** Read-only typed table accessor exposed on `QueryCtx.db
|
|
283
|
-
interface TableReaderFacade<DM, REL extends Record<keyof DM, object>, RANK extends Record<keyof DM, string>, SEARCH extends Record<keyof DM, string>, T extends keyof DM> {
|
|
441
|
+
/** Read-only typed table accessor exposed on `QueryCtx.db.<table>`. */
|
|
442
|
+
interface TableReaderFacade<DM, REL extends Record<keyof DM, object>, RANK extends Record<keyof DM, string>, SEARCH extends Record<keyof DM, string>, T extends keyof DM, GEO extends Record<keyof DM, string> = Record<keyof DM, never>> {
|
|
284
443
|
/**
|
|
285
444
|
* Reduce rows in this table to a scalar (`avg`/`max`/`min`/`sum` — `count`
|
|
286
445
|
* lives on its own method). Routes through a declared `aggregateIndex` when
|
|
@@ -291,12 +450,26 @@ interface TableReaderFacade<DM, REL extends Record<keyof DM, object>, RANK exten
|
|
|
291
450
|
* Count rows. The planner routes `where` keys that match a declared
|
|
292
451
|
* `aggregateIndex.by` set to the indexed counter (no scan); otherwise
|
|
293
452
|
* falls back to a SCAN. Accepts either a bare `where` tree or the broader
|
|
294
|
-
*
|
|
453
|
+
* RestrictableQueryOptions shape; the latter is the seam the RLS layer
|
|
295
454
|
* uses to inject `baseWhere` and `restrictsCounts`.
|
|
296
455
|
*/
|
|
297
456
|
count: (where?: RestrictableQueryOptionsOf<DM, REL, T> | WhereOf<DM, REL, T>) => Promise<number>;
|
|
298
457
|
/** `true` when at least one row matches `where` (any row when omitted). RLS-filtered exactly like `findFirst`. */
|
|
299
458
|
exists: (where?: WhereOf<DM, REL, T>) => Promise<boolean>;
|
|
459
|
+
/**
|
|
460
|
+
* Describe how this table would run `findMany(args)` without running it: the SQL, its bound
|
|
461
|
+
* parameters, and the database's own plan, one line per step. Use it to check that a filter is
|
|
462
|
+
* served by an index (`SEARCH … USING INDEX by_room`) rather than a scan (`SCAN …`).
|
|
463
|
+
*
|
|
464
|
+
* Honors RLS and soft delete exactly like the read, so the plan is the one your caller would get.
|
|
465
|
+
* Explaining does not subscribe a live query to this table. A relation filter in `where` is resolved
|
|
466
|
+
* first with an ordinary read of the related table, which does subscribe to that table, since the ids
|
|
467
|
+
* it matched are part of `params`. Takes no `with` or `select`: neither changes the statement.
|
|
468
|
+
*
|
|
469
|
+
* `params` carries values your RLS policies injected and, for a relation filter, the ids it matched.
|
|
470
|
+
* Keep the result on the server rather than returning it to a client.
|
|
471
|
+
*/
|
|
472
|
+
explain: (args?: QueryArgsOf<DM, REL, T>) => Promise<QueryPlan>;
|
|
300
473
|
findFirst: <W extends WithArg<DM, REL, T> = {}, S extends ReadonlyArray<keyof DM[T] & string> | undefined = undefined>(args?: QueryArgsOf<DM, REL, T> & {
|
|
301
474
|
select?: S;
|
|
302
475
|
with?: W;
|
|
@@ -309,6 +482,19 @@ interface TableReaderFacade<DM, REL extends Record<keyof DM, object>, RANK exten
|
|
|
309
482
|
select?: S;
|
|
310
483
|
with?: W;
|
|
311
484
|
}) => Promise<QueryPage<LoadWith<DM, REL, T, W, S>>>;
|
|
485
|
+
/**
|
|
486
|
+
* The one row matching `where`, or `null` when none does — and a `NOT_UNIQUE`
|
|
487
|
+
* error when a SECOND one matches, so a broken uniqueness invariant surfaces at
|
|
488
|
+
* the read rather than as a wrong answer downstream. `findFirst` drops that
|
|
489
|
+
* assertion; this is the ORM spelling of the fluent reader's `.unique()`.
|
|
490
|
+
*
|
|
491
|
+
* `limit`/`cursor`/`endCursor` are not accepted rather than silently ignored: paging a read
|
|
492
|
+
* that must match at most one row is the assertion being dropped again.
|
|
493
|
+
*/
|
|
494
|
+
findUnique: <W extends WithArg<DM, REL, T> = {}, S extends ReadonlyArray<keyof DM[T] & string> | undefined = undefined>(args?: Omit<QueryArgsOf<DM, REL, T>, "cursor" | "endCursor" | "limit"> & {
|
|
495
|
+
select?: S;
|
|
496
|
+
with?: W;
|
|
497
|
+
}) => Promise<LoadWith<DM, REL, T, W, S> | null>;
|
|
312
498
|
get: (id: Id<string & T>) => Promise<DM[T] | null>;
|
|
313
499
|
/**
|
|
314
500
|
* Group rows by the named keys and apply `agg` per group (defaults to
|
|
@@ -329,6 +515,13 @@ interface TableReaderFacade<DM, REL extends Record<keyof DM, object>, RANK exten
|
|
|
329
515
|
* follow the Convex-style keyset shape.
|
|
330
516
|
*/
|
|
331
517
|
rankPage: (indexName: RANK[T], options?: TableRankPageOptions<DM[T]>) => Promise<RankPage<DM[T]>>;
|
|
518
|
+
/**
|
|
519
|
+
* Restrict the query to a declared `.geoIndex()` and run a proximity /
|
|
520
|
+
* bounding-box match. `indexName` is constrained to this table's geo indexes
|
|
521
|
+
* (`never` when it declares none). Returns a distance-ordered reader —
|
|
522
|
+
* finish with `.take(n)` / `.collect()`.
|
|
523
|
+
*/
|
|
524
|
+
withGeoIndex: (indexName: GEO[T], build: (q: GeoFilterBuilder) => GeoFilterBuilder) => GeoReader<DM[T]>;
|
|
332
525
|
/**
|
|
333
526
|
* Restrict the query to a declared `.searchIndex()` and run a full-text
|
|
334
527
|
* match. `indexName` is constrained to this table's search indexes
|
|
@@ -337,8 +530,8 @@ interface TableReaderFacade<DM, REL extends Record<keyof DM, object>, RANK exten
|
|
|
337
530
|
*/
|
|
338
531
|
withSearchIndex: (indexName: SEARCH[T], search: (q: SearchFilterBuilder<DM[T]>) => SearchFilterBuilder<DM[T]>) => SearchReader<DM[T]>;
|
|
339
532
|
}
|
|
340
|
-
/** Read-write typed table accessor exposed on `MutationCtx.db
|
|
341
|
-
interface TableWriterFacade<DM, IM extends Record<keyof DM, object>, REL extends Record<keyof DM, object>, RANK extends Record<keyof DM, string>, SEARCH extends Record<keyof DM, string>, T extends keyof DM> extends TableReaderFacade<DM, REL, RANK, SEARCH, T> {
|
|
533
|
+
/** Read-write typed table accessor exposed on `MutationCtx.db.<table>` / `ActionCtx.db.<table>`. */
|
|
534
|
+
interface TableWriterFacade<DM, IM extends Record<keyof DM, object>, REL extends Record<keyof DM, object>, RANK extends Record<keyof DM, string>, SEARCH extends Record<keyof DM, string>, T extends keyof DM, GEO extends Record<keyof DM, string> = Record<keyof DM, never>> extends TableReaderFacade<DM, REL, RANK, SEARCH, T, GEO> {
|
|
342
535
|
/**
|
|
343
536
|
* Delete a row by id. On a `.softDelete()` table this flips the marker column
|
|
344
537
|
* (and cascades as a soft delete) instead of removing the row; use
|
|
@@ -371,10 +564,10 @@ interface TableWriterFacade<DM, IM extends Record<keyof DM, object>, REL extends
|
|
|
371
564
|
* instead of throwing — the return type widens to `Id | null` on that overload.
|
|
372
565
|
*/
|
|
373
566
|
insert: {
|
|
374
|
-
(values: IM
|
|
567
|
+
(values: InsertValues<DM, IM, REL, T>, options: {
|
|
375
568
|
skipDuplicates: true;
|
|
376
569
|
}): Promise<Id<string & T> | null>;
|
|
377
|
-
(values: IM
|
|
570
|
+
(values: InsertValues<DM, IM, REL, T>, options?: {
|
|
378
571
|
skipDuplicates?: boolean;
|
|
379
572
|
}): Promise<Id<string & T>>;
|
|
380
573
|
};
|
|
@@ -393,7 +586,7 @@ interface TableWriterFacade<DM, IM extends Record<keyof DM, object>, REL extends
|
|
|
393
586
|
skipDuplicates?: boolean;
|
|
394
587
|
}): Promise<Id<string & T>[]>;
|
|
395
588
|
};
|
|
396
|
-
patch: (id: Id<string & T>, values:
|
|
589
|
+
patch: (id: Id<string & T>, values: PatchValues<IM[T]> & RelationWrites<DM, REL, T>) => Promise<void>;
|
|
397
590
|
/**
|
|
398
591
|
* Patch many rows in this table. Pass an array of `{ id, values }` or
|
|
399
592
|
* `{ where, values }` to patch matching rows with the same values. Returns
|
|
@@ -402,7 +595,7 @@ interface TableWriterFacade<DM, IM extends Record<keyof DM, object>, REL extends
|
|
|
402
595
|
patchMany: {
|
|
403
596
|
(patches: ReadonlyArray<{
|
|
404
597
|
id: Id<string & T>;
|
|
405
|
-
values:
|
|
598
|
+
values: PatchValues<IM[T]>;
|
|
406
599
|
}>, options?: {
|
|
407
600
|
limit?: number;
|
|
408
601
|
}): Promise<{
|
|
@@ -410,7 +603,7 @@ interface TableWriterFacade<DM, IM extends Record<keyof DM, object>, REL extends
|
|
|
410
603
|
}>;
|
|
411
604
|
(args: {
|
|
412
605
|
limit?: number;
|
|
413
|
-
values:
|
|
606
|
+
values: PatchValues<IM[T]>;
|
|
414
607
|
where: Partial<DM[T]>;
|
|
415
608
|
}): Promise<{
|
|
416
609
|
patched: number;
|
|
@@ -426,9 +619,9 @@ interface TableWriterFacade<DM, IM extends Record<keyof DM, object>, REL extends
|
|
|
426
619
|
* Composes `findFirst` + `insert`/`patch`, so RLS gates each step.
|
|
427
620
|
*/
|
|
428
621
|
upsert: (args: {
|
|
429
|
-
create: IM
|
|
622
|
+
create: InsertValues<DM, IM, REL, T>;
|
|
430
623
|
target: UpsertTargetOf<DM, T>;
|
|
431
|
-
update?:
|
|
624
|
+
update?: PatchValues<IM[T]> & RelationWrites<DM, REL, T>;
|
|
432
625
|
}) => Promise<{
|
|
433
626
|
created: boolean;
|
|
434
627
|
id: Id<string & T>;
|
|
@@ -436,8 +629,8 @@ interface TableWriterFacade<DM, IM extends Record<keyof DM, object>, REL extends
|
|
|
436
629
|
/** Sequential {@link TableWriterFacade.upsert} over many rows sharing one `target`; one result per input row, in order. */
|
|
437
630
|
upsertMany: (args: {
|
|
438
631
|
rows: ReadonlyArray<{
|
|
439
|
-
create: IM
|
|
440
|
-
update?:
|
|
632
|
+
create: InsertValues<DM, IM, REL, T>;
|
|
633
|
+
update?: PatchValues<IM[T]> & RelationWrites<DM, REL, T>;
|
|
441
634
|
}>;
|
|
442
635
|
target: UpsertTargetOf<DM, T>;
|
|
443
636
|
}) => Promise<{
|
|
@@ -447,8 +640,65 @@ interface TableWriterFacade<DM, IM extends Record<keyof DM, object>, REL extends
|
|
|
447
640
|
}
|
|
448
641
|
/** Conflict target for `upsert`/`upsertMany`: one column of table `T`, or a tuple of them. */
|
|
449
642
|
type UpsertTargetOf<DM, T extends keyof DM> = ReadonlyArray<keyof DM[T] & string> | (keyof DM[T] & string);
|
|
450
|
-
/**
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
643
|
+
/**
|
|
644
|
+
* The values a `patch` accepts: any column's own type, and for a number or boolean
|
|
645
|
+
* column also an atomic operator ({@link NumberFieldOperator}, {@link BooleanFieldOperator}).
|
|
646
|
+
*/
|
|
647
|
+
type PatchValues<Row> = PathPatch<Row> & { [K in keyof Row]?: Row[K] | OperatorFor<NonNullable<Row[K]>>; };
|
|
648
|
+
/** What `explain` returns: the SQL a read compiles to, its bound parameters, and the database's plan for it. */
|
|
649
|
+
interface QueryPlan {
|
|
650
|
+
/** The bound parameters, in order. */
|
|
651
|
+
params: unknown[];
|
|
652
|
+
/** One line per plan step, as the database reports it. */
|
|
653
|
+
plan: string[];
|
|
654
|
+
/** The statement the read compiles to. */
|
|
655
|
+
sql: string;
|
|
656
|
+
}
|
|
657
|
+
/**
|
|
658
|
+
* Nested write for a to-one relation: point the row at `Target` (`connect`), or clear the link (`disconnect`, which
|
|
659
|
+
* needs a foreign key that can be empty). One or the other, not both.
|
|
660
|
+
*/
|
|
661
|
+
type ToOneRelationWrite<TargetId> = {
|
|
662
|
+
connect: TargetId;
|
|
663
|
+
disconnect?: never;
|
|
664
|
+
} | {
|
|
665
|
+
connect?: never;
|
|
666
|
+
disconnect: true;
|
|
667
|
+
};
|
|
668
|
+
/**
|
|
669
|
+
* Nested write for a to-many relation: point `Target` rows at this one (`connect`), release them (`disconnect`, which
|
|
670
|
+
* needs a foreign key that can be empty), or replace the whole list (`set`: rows not named are released). `set`
|
|
671
|
+
* cannot be combined with the other two.
|
|
672
|
+
*/
|
|
673
|
+
type ToManyRelationWrite<TargetId> = {
|
|
674
|
+
connect?: never;
|
|
675
|
+
disconnect?: never;
|
|
676
|
+
set: ReadonlyArray<TargetId>;
|
|
677
|
+
} | {
|
|
678
|
+
connect?: ReadonlyArray<TargetId>;
|
|
679
|
+
disconnect?: ReadonlyArray<TargetId>;
|
|
680
|
+
set?: never;
|
|
681
|
+
};
|
|
682
|
+
/**
|
|
683
|
+
* Nested relation writes accepted by `insert`, `patch` and `upsert`, keyed by relation name:
|
|
684
|
+
* `{ author: { connect: userId } }`, `{ posts: { set: [a, b] } }`. A table with no relations contributes none
|
|
685
|
+
* (`unknown`, the identity for `&`, never `{}`: an empty object type would switch off the weak-type check).
|
|
686
|
+
*/
|
|
687
|
+
type RelationWrites<DM, REL extends Record<keyof DM, object>, T extends keyof DM> = [keyof REL[T]] extends [never] ? unknown : { [K in keyof REL[T]]?: REL[T][K] extends {
|
|
688
|
+
__relationKind: "one";
|
|
689
|
+
__target: infer Target extends keyof DM;
|
|
690
|
+
} ? ToOneRelationWrite<Id<string & Target>> : REL[T][K] extends {
|
|
691
|
+
__relationKind: "many";
|
|
692
|
+
__target: infer Target extends keyof DM;
|
|
693
|
+
} ? ToManyRelationWrite<Id<string & Target>> : never; };
|
|
694
|
+
/**
|
|
695
|
+
* What `insert` accepts: the row as it is, or the row without its to-one foreign keys plus the nested writes that
|
|
696
|
+
* supply them. Leaving a key out with no `connect` to supply it is not caught by the type — the store's own
|
|
697
|
+
* validation rejects the missing field.
|
|
698
|
+
*/
|
|
699
|
+
type InsertValues<DM, IM extends Record<keyof DM, object>, REL extends Record<keyof DM, object>, T extends keyof DM> = IM[T] | (Omit<IM[T], OneRelationFields<REL[T]>> & RelationWrites<DM, REL, T>);
|
|
700
|
+
/** Per-table read facade — `ctx.db.<table>` on a `QueryCtx`. */
|
|
701
|
+
type DatabaseReaderFacade<DM, REL extends Record<keyof DM, object>, RANK extends Record<keyof DM, string>, SEARCH extends Record<keyof DM, string>, GEO extends Record<keyof DM, string> = Record<keyof DM, never>> = { readonly [T in keyof DM]: TableReaderFacade<DM, REL, RANK, SEARCH, T, GEO>; };
|
|
702
|
+
/** Per-table read-write facade — `ctx.db.<table>` on a `MutationCtx` / `ActionCtx`. */
|
|
703
|
+
type DatabaseWriterFacade<DM, IM extends Record<keyof DM, object>, REL extends Record<keyof DM, object>, RANK extends Record<keyof DM, string>, SEARCH extends Record<keyof DM, string>, GEO extends Record<keyof DM, string> = Record<keyof DM, never>> = { readonly [T in keyof DM]: TableWriterFacade<DM, IM, REL, RANK, SEARCH, T, GEO>; };
|
|
704
|
+
export { AggregateOp, ColumnWhere, DatabaseReaderFacade, DatabaseWriterFacade, GeoBoundingBox, GeoFilterBuilder, GeoPointInput, GeoReader, GroupByEntry, Id, InsertValues, LoadWith, ManyRelationWhere, OneRelationWhere, OrderBy, PatchValues, QueryArgs, QueryArgsOf, QueryPage, QueryPlan, RankPage, RankResult, RelationWrites, RestrictableQueryOptions, RestrictableQueryOptionsOf, SearchFilterBuilder, SearchReader, TableAggregateOptions, TableAggregateOptionsOf, TableGroupByOptions, TableGroupByOptionsOf, TableRankOptions, TableRankPageOptions, TableReaderFacade, TableWriterFacade, ToManyRelationWrite, ToOneRelationWrite, UpsertTargetOf, Where, WhereOf, WhereOperators, WithArg };
|