@lunora/server 1.0.0-alpha.9 → 1.0.0-alpha.91

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/LICENSE.md +219 -0
  2. package/README.md +46 -0
  3. package/dist/data-model.d.mts +260 -164
  4. package/dist/data-model.d.ts +260 -164
  5. package/dist/data-model.mjs +0 -1
  6. package/dist/drizzle.mjs +1 -1
  7. package/dist/index.d.mts +2675 -1562
  8. package/dist/index.d.ts +2675 -1562
  9. package/dist/index.mjs +1 -28
  10. package/dist/otel.d.mts +543 -0
  11. package/dist/otel.d.ts +543 -0
  12. package/dist/otel.mjs +1 -0
  13. package/dist/packem_shared/ACTION_CACHE_DEFAULT_TTL_MS-DRJUQGut.mjs +1 -0
  14. package/dist/packem_shared/DEFAULT_LIMIT-DC-M6faS.mjs +1 -0
  15. package/dist/packem_shared/DOCUMENT_HISTORY_REDACTED_FIELDS-KTkC4xOc.mjs +1 -0
  16. package/dist/packem_shared/LunoraEnvError-_BakoYQ3.mjs +3 -0
  17. package/dist/packem_shared/LunoraError-DcKdk9Ti.mjs +1 -0
  18. package/dist/packem_shared/PRESENCE_DEFAULT_TTL_MS-BpSPSCwL.mjs +1 -0
  19. package/dist/packem_shared/allowAll-DkRAgItV.mjs +1 -0
  20. package/dist/packem_shared/apply-output-BG8Bd0Ug.mjs +1 -0
  21. package/dist/packem_shared/asBucketStorage-BthCnWop.mjs +1 -0
  22. package/dist/packem_shared/bindOrm-lWdeDi9P.mjs +1 -0
  23. package/dist/packem_shared/buildMaskRegistry-72SL8fJn.mjs +1 -0
  24. package/dist/packem_shared/buildRlsReadRegistry-Deq8inqS.mjs +1 -0
  25. package/dist/packem_shared/composePluginMiddleware-DQHF6mYr.mjs +1 -0
  26. package/dist/packem_shared/context-identity-B2XYGA0B.mjs +1 -0
  27. package/dist/packem_shared/createPolicyDsl-DNfByAUX.mjs +1 -0
  28. package/dist/packem_shared/createSecrets-CyrEddTF.mjs +1 -0
  29. package/dist/packem_shared/defineAggregateIndex-BtVAy69G.mjs +1 -0
  30. package/dist/packem_shared/defineIdentity-DwkNKwYa.mjs +1 -0
  31. package/dist/packem_shared/defineMigration-7GI9Qbtd.mjs +1 -0
  32. package/dist/packem_shared/defineMutator-DKy8UtbB.mjs +1 -0
  33. package/dist/packem_shared/defineShape-DYxbNl5W.mjs +1 -0
  34. package/dist/packem_shared/defineStorageRule-BvxHVq3b.mjs +1 -0
  35. package/dist/packem_shared/flushDeferredDeletes-DEJXlhop.mjs +1 -0
  36. package/dist/packem_shared/fnv1a-D6VtE8WR.mjs +1 -0
  37. package/dist/packem_shared/functions-B2-H4PQT.mjs +1 -0
  38. package/dist/packem_shared/httpAction-D3b9-YiY.mjs +5 -0
  39. package/dist/packem_shared/initLunora-B2sfmFJ6.mjs +1 -0
  40. package/dist/packem_shared/mask-Da7q82ZC.mjs +1 -0
  41. package/dist/packem_shared/middleware-DEW0yLvU.mjs +1 -0
  42. package/dist/packem_shared/onConnect-BLRoOpv2.mjs +1 -0
  43. package/dist/packem_shared/onQueryChange-pRK6Dh3g.mjs +1 -0
  44. package/dist/packem_shared/plugin-DQcLxTx1.mjs +1 -0
  45. package/dist/packem_shared/policy-tag-D4RzgQnw.mjs +1 -0
  46. package/dist/packem_shared/protectPublic-Bo4G9xaV.mjs +1 -0
  47. package/dist/packem_shared/rls-B3mNGBuc.mjs +1 -0
  48. package/dist/packem_shared/run-middleware-B-JeGGp9.mjs +1 -0
  49. package/dist/packem_shared/stable-key-B_BlboiY.mjs +1 -0
  50. package/dist/packem_shared/storageRules-CyaiZ0av.mjs +1 -0
  51. package/dist/packem_shared/types.d-B-pIn8rE.d.mts +141 -0
  52. package/dist/packem_shared/types.d-CdPDEjhz.d.ts +141 -0
  53. package/dist/packem_shared/wire-codec-hZHn-Ooo.mjs +1 -0
  54. package/dist/rls/testing.d.mts +31 -31
  55. package/dist/rls/testing.d.ts +31 -31
  56. package/dist/rls/testing.mjs +1 -49
  57. package/dist/types.d.mts +1621 -508
  58. package/dist/types.d.ts +1621 -508
  59. package/dist/types.mjs +1 -31
  60. package/package.json +17 -4
  61. package/dist/packem_shared/LunoraEnvError-DjFkpkSP.mjs +0 -187
  62. package/dist/packem_shared/LunoraError-DN7Zhhvu.mjs +0 -54
  63. package/dist/packem_shared/PRESENCE_DEFAULT_TTL_MS-D8viLY1S.mjs +0 -114
  64. package/dist/packem_shared/asBucketStorage-Cnxd9y2q.mjs +0 -11
  65. package/dist/packem_shared/bindOrm-Ce57S3N9.mjs +0 -128
  66. package/dist/packem_shared/buildRlsReadRegistry-1jexWrb3.mjs +0 -107
  67. package/dist/packem_shared/composePluginMiddleware-Ck5_TUO8.mjs +0 -100
  68. package/dist/packem_shared/createPolicyDsl-De67zPDS.mjs +0 -29
  69. package/dist/packem_shared/createSecrets-TsIP9lOa.mjs +0 -55
  70. package/dist/packem_shared/defineAggregateIndex-ZdyU78gh.mjs +0 -291
  71. package/dist/packem_shared/defineMigration-CAJLr6fx.mjs +0 -8
  72. package/dist/packem_shared/defineMutator-EIXAWhs9.mjs +0 -11
  73. package/dist/packem_shared/defineShape-CJ27Wx7o.mjs +0 -17
  74. package/dist/packem_shared/defineStorageRule-qu0mpilX.mjs +0 -20
  75. package/dist/packem_shared/functions-Di9FUNkf.mjs +0 -5
  76. package/dist/packem_shared/httpAction-FLwfsePg.mjs +0 -340
  77. package/dist/packem_shared/initLunora-lxwHTEV3.mjs +0 -100
  78. package/dist/packem_shared/mask-BV_jNzsN.mjs +0 -211
  79. package/dist/packem_shared/onConnect-CIPXKPyw.mjs +0 -13
  80. package/dist/packem_shared/policy-tag-DvpVH2tv.mjs +0 -13
  81. package/dist/packem_shared/protectPublic-BjFkQ_Or.mjs +0 -15
  82. package/dist/packem_shared/rls-2Jhd0uev.mjs +0 -569
  83. package/dist/packem_shared/run-middleware-CYQOuoV6.mjs +0 -18
  84. package/dist/packem_shared/storageRules-Cje6Woea.mjs +0 -88
  85. package/dist/packem_shared/types.d-BDY0FYHK.d.ts +0 -135
  86. package/dist/packem_shared/types.d-DmvyEMD6.d.mts +0 -135
@@ -1,25 +1,25 @@
1
1
  /**
2
- * Schema-independent type machinery for the generated data model.
3
- *
4
- * `@lunora/codegen` emits `lunora/_generated/dataModel.ts` with the
5
- * schema-specific pieces (the per-table `Doc_*` / `Insert_*` interfaces, the
6
- * `DataModel` / `Relations` / index-name maps) and then binds the generics
7
- * below to them. Everything here is identical for every project, so it lives
8
- * in the shipped package rather than in generated output — evolving the query
9
- * DSL or the table-facade API no longer regenerates a single line of a user's
10
- * `_generated` directory.
11
- *
12
- * The generics are parameterized over the generated maps:
13
- * - `DM` — `DataModel`: table name → document type
14
- * - `IM` — `InsertModel`: table name → insert shape
15
- * - `REL` — `Relations`: table name → relation-descriptor map
16
- * - `RANK` — `RankIndexNamesByTable`: table name → declared rank-index names
17
- * - `SEARCH` — `SearchIndexNamesByTable`: table name → declared search-index names
18
- *
19
- * Relation descriptors are matched structurally (`{ __relationKind; __target }`)
20
- * so this module needs no reference to the project-local `OneRelation` /
21
- * `ManyRelation` aliases the codegen still emits.
22
- */
2
+ * Schema-independent type machinery for the generated data model.
3
+ *
4
+ * `@lunora/codegen` emits `lunora/_generated/dataModel.ts` with the
5
+ * schema-specific pieces (the per-table `Doc_*` / `Insert_*` interfaces, the
6
+ * `DataModel` / `Relations` / index-name maps) and then binds the generics
7
+ * below to them. Everything here is identical for every project, so it lives
8
+ * in the shipped package rather than in generated output — evolving the query
9
+ * DSL or the table-facade API no longer regenerates a single line of a user's
10
+ * `_generated` directory.
11
+ *
12
+ * The generics are parameterized over the generated maps:
13
+ * - `DM` — `DataModel`: table name → document type
14
+ * - `IM` — `InsertModel`: table name → insert shape
15
+ * - `REL` — `Relations`: table name → relation-descriptor map
16
+ * - `RANK` — `RankIndexNamesByTable`: table name → declared rank-index names
17
+ * - `SEARCH` — `SearchIndexNamesByTable`: table name → declared search-index names
18
+ *
19
+ * Relation descriptors are matched structurally (`{ __relationKind; __target }`)
20
+ * so this module needs no reference to the project-local `OneRelation` /
21
+ * `ManyRelation` aliases the codegen still emits.
22
+ */
23
23
  /** A branded id for table `TName`. Structurally a `string` at runtime. */
24
24
  type Id<TName extends string> = string & {
25
25
  readonly __table: TName;
@@ -38,7 +38,7 @@ interface WhereOperators<T> {
38
38
  notIn?: T[];
39
39
  }
40
40
  /** A typed `where` tree over a document's columns. */
41
- type Where<TDocument> = { [K in keyof TDocument]?: TDocument[K] | WhereOperators<TDocument[K]> } & {
41
+ type Where<TDocument> = { [K in keyof TDocument]?: TDocument[K] | WhereOperators<TDocument[K]>; } & {
42
42
  AND?: Where<TDocument>[];
43
43
  NOT?: Where<TDocument>;
44
44
  OR?: Where<TDocument>[];
@@ -50,53 +50,53 @@ interface QueryArgs<TDocument> {
50
50
  limit?: number;
51
51
  orderBy?: OrderBy<TDocument>[];
52
52
  /**
53
- * Project each returned row down to these columns (plus the system fields
54
- * `_id`/`_creationTime`, always retained). Trims wire payload for wide rows;
55
- * relations requested via `with` are still attached. Reactivity is unaffected —
56
- * the engine still reads the whole row to track dependencies.
57
- */
53
+ * Project each returned row down to these columns (plus the system fields
54
+ * `_id`/`_creationTime`, always retained). Trims wire payload for wide rows;
55
+ * relations requested via `with` are still attached. Reactivity is unaffected —
56
+ * the engine still reads the whole row to track dependencies.
57
+ */
58
58
  select?: ReadonlyArray<keyof TDocument & string>;
59
59
  where?: Where<TDocument>;
60
60
  }
61
61
  /**
62
- * A to-one relation predicate node. `is` matches rows whose related record
63
- * satisfies `W`; `isNot` matches rows whose related record fails `W` *or* has
64
- * no related record at all (a null/dangling FK) — Prisma's semantics.
65
- */
62
+ * A to-one relation predicate node. `is` matches rows whose related record
63
+ * satisfies `W`; `isNot` matches rows whose related record fails `W` *or* has
64
+ * no related record at all (a null/dangling FK) — Prisma's semantics.
65
+ */
66
66
  interface OneRelationWhere<W> {
67
67
  is?: W;
68
68
  isNot?: W;
69
69
  }
70
70
  /**
71
- * A to-many relation predicate node. `some` ⇒ at least one related row matches
72
- * `W`; `none` ⇒ no related row matches (childless parents included); `every` ⇒
73
- * every *readable* related row matches (vacuously true for childless parents).
74
- */
71
+ * A to-many relation predicate node. `some` ⇒ at least one related row matches
72
+ * `W`; `none` ⇒ no related row matches (childless parents included); `every` ⇒
73
+ * every *readable* related row matches (vacuously true for childless parents).
74
+ */
75
75
  interface ManyRelationWhere<W> {
76
76
  every?: W;
77
77
  none?: W;
78
78
  some?: W;
79
79
  }
80
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
- */
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
86
  type RelationWhere<DM, REL extends Record<keyof DM, object>, T extends keyof DM> = { [K in keyof REL[T]]?: REL[T][K] extends {
87
87
  __relationKind: "one";
88
88
  __target: infer Target extends keyof DM;
89
89
  } ? OneRelationWhere<WhereOf<DM, REL, Target>> : REL[T][K] extends {
90
90
  __relationKind: "many";
91
91
  __target: infer Target extends keyof DM;
92
- } ? ManyRelationWhere<WhereOf<DM, REL, Target>> : never };
92
+ } ? ManyRelationWhere<WhereOf<DM, REL, Target>> : never; };
93
93
  /**
94
- * Relation-aware `where` tree — the column predicates of {@link Where} plus
95
- * Prisma-style relation predicates resolved by the `@lunora/do` pre-resolver.
96
- * `Where&lt;DM[T]>` stays the column-only structural mirror for back-compat; the
97
- * table facade threads `REL` through this richer form.
98
- */
99
- type WhereOf<DM, REL extends Record<keyof DM, object>, T extends keyof DM> = RelationWhere<DM, REL, T> & { [K in keyof DM[T]]?: DM[T][K] | WhereOperators<DM[T][K]> } & {
94
+ * Relation-aware `where` tree — the column predicates of {@link Where} plus
95
+ * Prisma-style relation predicates resolved by the `@lunora/do` pre-resolver.
96
+ * `Where<DM[T]>` stays the column-only structural mirror for back-compat; the
97
+ * table facade threads `REL` through this richer form.
98
+ */
99
+ type WhereOf<DM, REL extends Record<keyof DM, object>, T extends keyof DM> = RelationWhere<DM, REL, T> & { [K in keyof DM[T]]?: DM[T][K] | WhereOperators<DM[T][K]>; } & {
100
100
  AND?: WhereOf<DM, REL, T>[];
101
101
  NOT?: WhereOf<DM, REL, T>;
102
102
  OR?: WhereOf<DM, REL, T>[];
@@ -105,10 +105,10 @@ type WhereOf<DM, REL extends Record<keyof DM, object>, T extends keyof DM> = Rel
105
105
  interface QueryArgsOf<DM, REL extends Record<keyof DM, object>, T extends keyof DM> {
106
106
  cursor?: null | string;
107
107
  /**
108
- * Include soft-deleted rows (`.softDelete()` tables only). Default hides them;
109
- * `true` returns deleted rows alongside live ones. No effect on a table
110
- * without `.softDelete()`.
111
- */
108
+ * Include soft-deleted rows (`.softDelete()` tables only). Default hides them;
109
+ * `true` returns deleted rows alongside live ones. No effect on a table
110
+ * without `.softDelete()`.
111
+ */
112
112
  includeDeleted?: boolean;
113
113
  limit?: number;
114
114
  orderBy?: OrderBy<DM[T]>[];
@@ -128,11 +128,11 @@ type NestedSelectArgument<WK> = WK extends {
128
128
  select: infer S;
129
129
  } ? S : undefined;
130
130
  /**
131
- * The `with` argument for table `T`: each relation can be `true` (load with no
132
- * refinements) or an object. `many` relations accept `where`/`orderBy`/`limit`/
133
- * `select` plus a nested `with`; `one` relations accept `select` + a nested
134
- * `with`. The reserved `_count` key requests per-relation aggregate counts.
135
- */
131
+ * The `with` argument for table `T`: each relation can be `true` (load with no
132
+ * refinements) or an object. `many` relations accept `where`/`orderBy`/`limit`/
133
+ * `select` plus a nested `with`; `one` relations accept `select` + a nested
134
+ * `with`. The reserved `_count` key requests per-relation aggregate counts.
135
+ */
136
136
  type WithArg<DM, REL extends Record<keyof DM, object>, T extends keyof DM> = { [K in keyof REL[T]]?: REL[T][K] extends {
137
137
  __relationKind: "many";
138
138
  __target: infer Target extends keyof DM;
@@ -144,15 +144,15 @@ type WithArg<DM, REL extends Record<keyof DM, object>, T extends keyof DM> = { [
144
144
  } ? boolean | {
145
145
  select?: ReadonlyArray<keyof DM[Target] & string>;
146
146
  with?: WithArg<DM, REL, Target>;
147
- } : never } & {
148
- _count?: { [K in keyof REL[T]]?: true };
147
+ } : never; } & {
148
+ _count?: { [K in keyof REL[T]]?: true; };
149
149
  };
150
150
  /**
151
- * Resolve a single relation descriptor + its with-value to the loaded type,
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
- */
151
+ * Resolve a single relation descriptor + its with-value to the loaded type,
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
156
  type LoadRelation<DM, REL extends Record<keyof DM, object>, R, WK> = R extends {
157
157
  __relationKind: "one";
158
158
  __target: infer Target extends keyof DM;
@@ -161,53 +161,53 @@ type LoadRelation<DM, REL extends Record<keyof DM, object>, R, WK> = R extends {
161
161
  __target: infer Target extends keyof DM;
162
162
  } ? LoadWith<DM, REL, Target, NestedWithArgument<WK>, NestedSelectArgument<WK>>[] : never;
163
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 };
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
165
  /** The `_count` projection of `W`, if any. */
166
166
  type LoadedCount<W> = W extends {
167
167
  _count: infer C;
168
168
  } ? {
169
- _count: { [K in keyof C]: number };
169
+ _count: { [K in keyof C]: number; };
170
170
  } : {};
171
171
  /** System columns a `select` projection always retains, so cursors and by-id reuse keep working. */
172
172
  type SelectAlwaysKeep<DM, T extends keyof DM> = ("_creationTime" | "_id") & keyof DM[T];
173
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
- */
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
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
178
  /**
179
- * `Doc&lt;T>` narrowed to exactly the relations requested in the with-arg `W` and,
180
- * when a `select` tuple `S` is supplied, to its projected columns. `S` defaults
181
- * to `undefined` so the 4-argument form (the codegen-emitted callers) keeps the
182
- * full document.
183
- */
179
+ * `Doc<T>` narrowed to exactly the relations requested in the with-arg `W` and,
180
+ * when a `select` tuple `S` is supplied, to its projected columns. `S` defaults
181
+ * to `undefined` so the 4-argument form (the codegen-emitted callers) keeps the
182
+ * full document.
183
+ */
184
184
  type LoadWith<DM, REL extends Record<keyof DM, object>, T extends keyof DM, W, S = undefined> = LoadedCount<W> & LoadedRelations<DM, REL, T, W> & ProjectDoc<DM, T, S>;
185
185
  /** Reducer applied by an aggregate (`avg`/`count`/`max`/`min`/`sum`). */
186
186
  type AggregateOp = "avg" | "count" | "max" | "min" | "sum";
187
187
  /**
188
- * Query-options shape shared by every aggregate reader. The RLS-aware ctx
189
- * populates `baseWhere` so it composes here without a hard import.
190
- * `restrictsCounts: true` flips `count()` into a thrown `COUNT_RLS_UNSUPPORTED`
191
- * `LunoraError` rather than silently undercount.
192
- */
188
+ * Query-options shape shared by every aggregate reader. The RLS-aware ctx
189
+ * populates `baseWhere` so it composes here without a hard import.
190
+ * `restrictsCounts: true` flips `count()` into a thrown `COUNT_RLS_UNSUPPORTED`
191
+ * `LunoraError` rather than silently undercount.
192
+ */
193
193
  interface RestrictableQueryOptions<TDocument> {
194
194
  baseWhere?: Where<TDocument>;
195
195
  restrictsCounts?: boolean;
196
196
  where?: Where<TDocument>;
197
197
  }
198
198
  /**
199
- * Relation-aware twin of {@link RestrictableQueryOptions}. The `@lunora/do`
200
- * pre-resolver now resolves relation predicates on the `count`/`aggregate`/
201
- * `groupBy` paths too (semijoin), so the typed surface threads `REL` through
202
- * `where`/`baseWhere` to match. `rank`/`rankPage` stay column-only — they use
203
- * `where` solely to pin a partition and fail closed on a relation predicate.
204
- */
199
+ * Relation-aware twin of {@link RestrictableQueryOptions}. The `@lunora/do`
200
+ * pre-resolver now resolves relation predicates on the `count`/`aggregate`/
201
+ * `groupBy` paths too (semijoin), so the typed surface threads `REL` through
202
+ * `where`/`baseWhere` to match. `rank`/`rankPage` stay column-only — they use
203
+ * `where` solely to pin a partition and fail closed on a relation predicate.
204
+ */
205
205
  interface RestrictableQueryOptionsOf<DM, REL extends Record<keyof DM, object>, T extends keyof DM> {
206
206
  baseWhere?: WhereOf<DM, REL, T>;
207
207
  restrictsCounts?: boolean;
208
208
  where?: WhereOf<DM, REL, T>;
209
209
  }
210
- /** Args for `ctx.db.&lt;table>.aggregate({ op, field?, where? })`. */
210
+ /** Args for `ctx.db.<table>.aggregate({ op, field?, where? })`. */
211
211
  interface TableAggregateOptions<TDocument> extends RestrictableQueryOptions<TDocument> {
212
212
  field?: keyof TDocument & string;
213
213
  op: AggregateOp;
@@ -217,7 +217,7 @@ interface TableAggregateOptionsOf<DM, REL extends Record<keyof DM, object>, T ex
217
217
  field?: keyof DM[T] & string;
218
218
  op: AggregateOp;
219
219
  }
220
- /** Args for `ctx.db.&lt;table>.groupBy({ by, agg?, where? })`. */
220
+ /** Args for `ctx.db.<table>.groupBy({ by, agg?, where? })`. */
221
221
  interface TableGroupByOptions<TDocument> extends RestrictableQueryOptions<TDocument> {
222
222
  agg?: {
223
223
  field?: keyof TDocument & string;
@@ -238,7 +238,7 @@ interface GroupByEntry<TDocument> {
238
238
  key: Partial<TDocument>;
239
239
  value: null | number;
240
240
  }
241
- /** Args for `ctx.db.&lt;table>.rank(name, args)`. `row` is either an id or a row doc. */
241
+ /** Args for `ctx.db.<table>.rank(name, args)`. `row` is either an id or a row doc. */
242
242
  interface TableRankOptions<TDocument> extends RestrictableQueryOptions<TDocument> {
243
243
  row: string | TDocument;
244
244
  }
@@ -247,7 +247,7 @@ interface RankResult {
247
247
  position: number;
248
248
  total: number;
249
249
  }
250
- /** Args for `ctx.db.&lt;table>.rankPage(name, args)`. */
250
+ /** Args for `ctx.db.<table>.rankPage(name, args)`. */
251
251
  interface TableRankPageOptions<TDocument> extends RestrictableQueryOptions<TDocument> {
252
252
  cursor?: null | string;
253
253
  take?: number;
@@ -259,41 +259,92 @@ interface RankPage<TDocument> {
259
259
  page: TDocument[];
260
260
  }
261
261
  /**
262
- * Builder passed to `.withSearchIndex(name, q => …)`. `.search(field, query)`
263
- * runs the full-text match against the index's searchable field; `.eq(field,
264
- * value)` narrows by a declared filter field. Field names are constrained to
265
- * the table's columns.
266
- */
262
+ * Builder passed to `.withSearchIndex(name, q => …)`. `.search(field, query)`
263
+ * runs the full-text match against the index's searchable field; `.eq(field,
264
+ * value)` narrows by a declared filter field. Field names are constrained to
265
+ * the table's columns.
266
+ */
267
267
  interface SearchFilterBuilder<TDocument> {
268
268
  eq: <F extends keyof TDocument & string>(field: F, value: TDocument[F]) => SearchFilterBuilder<TDocument>;
269
269
  search: (field: keyof TDocument & string, query: string) => SearchFilterBuilder<TDocument>;
270
270
  }
271
271
  /**
272
- * Chainable reader returned by `.withSearchIndex()` — rows come back ordered
273
- * by relevance. `.paginate()` is intentionally absent (a relevance-ordered
274
- * search can't keyset-paginate); cap the result set with `.take(n)`.
275
- */
272
+ * Chainable reader returned by `.withSearchIndex()` — rows come back ordered
273
+ * by relevance. `.paginate()` is intentionally absent (a relevance-ordered
274
+ * search can't keyset-paginate); cap the result set with `.take(n)`.
275
+ */
276
276
  interface SearchReader<TDocument> {
277
277
  collect: () => Promise<TDocument[]>;
278
+ /**
279
+ * Like `.collect()`, but pairs each matched document with the relevance
280
+ * score the FTS engine already computed to produce the descending order —
281
+ * `.collect()` throws it away after sorting by it, this surfaces it
282
+ * instead. Ordered by `score` descending, same order as `.collect()`.
283
+ */
284
+ collectWithScores: () => Promise<{
285
+ document: TDocument;
286
+ score: number;
287
+ }[]>;
278
288
  first: () => Promise<TDocument | null>;
279
289
  take: (limit: number) => Promise<TDocument[]>;
280
290
  unique: () => Promise<TDocument | null>;
281
291
  }
282
- /** Read-only typed table accessor exposed on `QueryCtx.db.&lt;table>`. */
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> {
292
+ /** A latitude/longitude point (WGS84 decimal degrees) accepted by geo queries. */
293
+ interface GeoPointInput {
294
+ lat: number;
295
+ lng: number;
296
+ }
297
+ /** An axis-aligned latitude/longitude bounding box (`sw`/`ne` corners). */
298
+ interface GeoBoundingBox {
299
+ ne: GeoPointInput;
300
+ sw: GeoPointInput;
301
+ }
302
+ /**
303
+ * Builder passed to `.withGeoIndex(name, q => …)`. Call exactly one of
304
+ * `.near(point, radiusMeters)` (proximity, nearest-first) or `.within(box)`
305
+ * (bounding-box).
306
+ */
307
+ interface GeoFilterBuilder {
308
+ near: (point: GeoPointInput, radiusMeters: number) => GeoFilterBuilder;
309
+ within: (box: GeoBoundingBox) => GeoFilterBuilder;
310
+ }
311
+ /**
312
+ * Chainable reader returned by `.withGeoIndex()`. `.near()` results come back
313
+ * ordered nearest-first; `.within()` results by row creation time. `.paginate()`
314
+ * is intentionally absent — cap the result set with `.take(n)`.
315
+ */
316
+ interface GeoReader<TDocument> {
317
+ collect: () => Promise<TDocument[]>;
284
318
  /**
285
- * Reduce rows in this table to a scalar (`avg`/`max`/`min`/`sum` — `count`
286
- * lives on its own method). Routes through a declared `aggregateIndex` when
287
- * the planner can prove the request is answerable; otherwise scans.
288
- */
319
+ * Like `.collect()`, but pairs each matched document with the distance
320
+ * (in meters) from `.near()`'s point that the read already computed to
321
+ * produce the nearest-first order. `.within()` box matches have no
322
+ * point-distance metric, so `distanceMeters` is `null` for those rows
323
+ * rather than a misleading `0`.
324
+ */
325
+ collectWithScores: () => Promise<{
326
+ distanceMeters: null | number;
327
+ document: TDocument;
328
+ }[]>;
329
+ first: () => Promise<TDocument | null>;
330
+ take: (limit: number) => Promise<TDocument[]>;
331
+ unique: () => Promise<TDocument | null>;
332
+ }
333
+ /** Read-only typed table accessor exposed on `QueryCtx.db.<table>`. */
334
+ 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>> {
335
+ /**
336
+ * Reduce rows in this table to a scalar (`avg`/`max`/`min`/`sum` — `count`
337
+ * lives on its own method). Routes through a declared `aggregateIndex` when
338
+ * the planner can prove the request is answerable; otherwise scans.
339
+ */
289
340
  aggregate: (options: TableAggregateOptionsOf<DM, REL, T>) => Promise<null | number>;
290
341
  /**
291
- * Count rows. The planner routes `where` keys that match a declared
292
- * `aggregateIndex.by` set to the indexed counter (no scan); otherwise
293
- * falls back to a SCAN. Accepts either a bare `where` tree or the broader
294
- * `RestrictableQueryOptions` shape; the latter is the seam the RLS layer
295
- * uses to inject `baseWhere` and `restrictsCounts`.
296
- */
342
+ * Count rows. The planner routes `where` keys that match a declared
343
+ * `aggregateIndex.by` set to the indexed counter (no scan); otherwise
344
+ * falls back to a SCAN. Accepts either a bare `where` tree or the broader
345
+ * `RestrictableQueryOptions` shape; the latter is the seam the RLS layer
346
+ * uses to inject `baseWhere` and `restrictsCounts`.
347
+ */
297
348
  count: (where?: RestrictableQueryOptionsOf<DM, REL, T> | WhereOf<DM, REL, T>) => Promise<number>;
298
349
  /** `true` when at least one row matches `where` (any row when omitted). RLS-filtered exactly like `findFirst`. */
299
350
  exists: (where?: WhereOf<DM, REL, T>) => Promise<boolean>;
@@ -311,53 +362,72 @@ interface TableReaderFacade<DM, REL extends Record<keyof DM, object>, RANK exten
311
362
  }) => Promise<QueryPage<LoadWith<DM, REL, T, W, S>>>;
312
363
  get: (id: Id<string & T>) => Promise<DM[T] | null>;
313
364
  /**
314
- * Group rows by the named keys and apply `agg` per group (defaults to
315
- * `count`). Answered from the counter table when an aggregate index's
316
- * `by` matches `options.by` exactly; otherwise scans.
317
- */
365
+ * Group rows by the named keys and apply `agg` per group (defaults to
366
+ * `count`). Answered from the counter table when an aggregate index's
367
+ * `by` matches `options.by` exactly; otherwise scans.
368
+ */
318
369
  groupBy: (options: TableGroupByOptionsOf<DM, REL, T>) => Promise<ReadonlyArray<GroupByEntry<DM[T]>>>;
319
370
  /**
320
- * Return the 1-based position of `options.row` within its partition
321
- * under the declared rankIndex `indexName`, plus the partition's total
322
- * row count. `null` when the row isn't in the index. Honors the same
323
- * `baseWhere` / `restrictsCounts` RLS seam as `count()`.
324
- */
371
+ * Return the 1-based position of `options.row` within its partition
372
+ * under the declared rankIndex `indexName`, plus the partition's total
373
+ * row count. `null` when the row isn't in the index. Honors the same
374
+ * `baseWhere` / `restrictsCounts` RLS seam as `count()`.
375
+ */
325
376
  rank: (indexName: RANK[T], options: TableRankOptions<DM[T]>) => Promise<null | RankResult>;
326
377
  /**
327
- * Walk the rank companion in declared sort order — sorted pagination
328
- * accelerator. `options.where` may pin the partition; `cursor`/`take`
329
- * follow the Convex-style keyset shape.
330
- */
378
+ * Walk the rank companion in declared sort order — sorted pagination
379
+ * accelerator. `options.where` may pin the partition; `cursor`/`take`
380
+ * follow the Convex-style keyset shape.
381
+ */
331
382
  rankPage: (indexName: RANK[T], options?: TableRankPageOptions<DM[T]>) => Promise<RankPage<DM[T]>>;
332
383
  /**
333
- * Restrict the query to a declared `.searchIndex()` and run a full-text
334
- * match. `indexName` is constrained to this table's search indexes
335
- * (`never` when it declares none). Returns a relevance-ordered reader —
336
- * finish with `.take(n)` / `.collect()`.
337
- */
384
+ * Restrict the query to a declared `.geoIndex()` and run a proximity /
385
+ * bounding-box match. `indexName` is constrained to this table's geo indexes
386
+ * (`never` when it declares none). Returns a distance-ordered reader —
387
+ * finish with `.take(n)` / `.collect()`.
388
+ */
389
+ withGeoIndex: (indexName: GEO[T], build: (q: GeoFilterBuilder) => GeoFilterBuilder) => GeoReader<DM[T]>;
390
+ /**
391
+ * Restrict the query to a declared `.searchIndex()` and run a full-text
392
+ * match. `indexName` is constrained to this table's search indexes
393
+ * (`never` when it declares none). Returns a relevance-ordered reader —
394
+ * finish with `.take(n)` / `.collect()`.
395
+ */
338
396
  withSearchIndex: (indexName: SEARCH[T], search: (q: SearchFilterBuilder<DM[T]>) => SearchFilterBuilder<DM[T]>) => SearchReader<DM[T]>;
339
397
  }
340
- /** Read-write typed table accessor exposed on `MutationCtx.db.&lt;table>` / `ActionCtx.db.&lt;table>`. */
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> {
398
+ /** Read-write typed table accessor exposed on `MutationCtx.db.<table>` / `ActionCtx.db.<table>`. */
399
+ 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
400
  /**
343
- * Delete a row by id. On a `.softDelete()` table this flips the marker column
344
- * (and cascades as a soft delete) instead of removing the row; use
345
- * {@link TableWriterFacade.hardDelete} to force physical removal.
346
- */
401
+ * Delete a row by id. On a `.softDelete()` table this flips the marker column
402
+ * (and cascades as a soft delete) instead of removing the row; use
403
+ * {@link TableWriterFacade.hardDelete} to force physical removal.
404
+ */
347
405
  delete: (id: Id<string & T>) => Promise<void>;
348
- /** Delete many rows in this table by id in one call; returns the *requested* id count (unknown ids are no-ops). Atomic within a mutation (a throw rolls the mutation back); an action has no transaction span. */
349
- deleteMany: (ids: ReadonlyArray<Id<string & T>>, options?: {
350
- limit?: number;
351
- }) => Promise<{
352
- deleted: number;
353
- }>;
406
+ /**
407
+ * Delete many rows in this table. Pass an array of ids (requested count is
408
+ * returned; unknown ids are no-ops) or `{ where }` to delete matching rows
409
+ * (actual removed count is returned). Atomic within a mutation.
410
+ */
411
+ deleteMany: {
412
+ (ids: ReadonlyArray<Id<string & T>>, options?: {
413
+ limit?: number;
414
+ }): Promise<{
415
+ deleted: number;
416
+ }>;
417
+ (args: {
418
+ limit?: number;
419
+ where: Partial<DM[T]>;
420
+ }): Promise<{
421
+ deleted: number;
422
+ }>;
423
+ };
354
424
  /** Physically remove a row (and physically cascade `onDelete`), bypassing `.softDelete()`. Same as `delete()` on a non-soft table. */
355
425
  hardDelete: (id: Id<string & T>) => Promise<void>;
356
426
  /**
357
- * Insert a document, returning its minted id. With `{ skipDuplicates: true }`
358
- * a UNIQUE-constraint breach resolves to `null` (the row already exists)
359
- * instead of throwing — the return type widens to `Id | null` on that overload.
360
- */
427
+ * Insert a document, returning its minted id. With `{ skipDuplicates: true }`
428
+ * a UNIQUE-constraint breach resolves to `null` (the row already exists)
429
+ * instead of throwing — the return type widens to `Id | null` on that overload.
430
+ */
361
431
  insert: {
362
432
  (values: IM[T], options: {
363
433
  skipDuplicates: true;
@@ -366,27 +436,53 @@ interface TableWriterFacade<DM, IM extends Record<keyof DM, object>, REL extends
366
436
  skipDuplicates?: boolean;
367
437
  }): Promise<Id<string & T>>;
368
438
  };
369
- /** Insert many documents into this table in one call, returning the minted ids in input order. Atomic within a mutation (a throw rolls the mutation back); an action has no transaction span. */
370
- insertMany: (values: ReadonlyArray<IM[T]>, options?: {
371
- limit?: number;
372
- }) => Promise<Id<string & T>[]>;
439
+ /**
440
+ * Insert many documents into this table in one call, returning the minted ids
441
+ * in input order. With `{ skipDuplicates: true }`, UNIQUE breaches resolve to
442
+ * `null` for that row instead of failing the batch. Atomic within a mutation.
443
+ */
444
+ insertMany: {
445
+ (values: ReadonlyArray<IM[T]>, options: {
446
+ limit?: number;
447
+ skipDuplicates: true;
448
+ }): Promise<(Id<string & T> | null)[]>;
449
+ (values: ReadonlyArray<IM[T]>, options?: {
450
+ limit?: number;
451
+ skipDuplicates?: boolean;
452
+ }): Promise<Id<string & T>[]>;
453
+ };
373
454
  patch: (id: Id<string & T>, values: Partial<IM[T]>) => Promise<void>;
374
- /** Patch many rows in this table by id in one call. Atomic within a mutation (a throw rolls the mutation back); an action has no transaction span. */
375
- patchMany: (patches: ReadonlyArray<{
376
- id: Id<string & T>;
377
- values: Partial<IM[T]>;
378
- }>, options?: {
379
- limit?: number;
380
- }) => Promise<void>;
455
+ /**
456
+ * Patch many rows in this table. Pass an array of `{ id, values }` or
457
+ * `{ where, values }` to patch matching rows with the same values. Returns
458
+ * the actual patched count. Atomic within a mutation.
459
+ */
460
+ patchMany: {
461
+ (patches: ReadonlyArray<{
462
+ id: Id<string & T>;
463
+ values: Partial<IM[T]>;
464
+ }>, options?: {
465
+ limit?: number;
466
+ }): Promise<{
467
+ patched: number;
468
+ }>;
469
+ (args: {
470
+ limit?: number;
471
+ values: Partial<IM[T]>;
472
+ where: Partial<DM[T]>;
473
+ }): Promise<{
474
+ patched: number;
475
+ }>;
476
+ };
381
477
  replace: (id: Id<string & T>, values: IM[T]) => Promise<void>;
382
478
  /** Un-soft-delete a row by id: clears the `.softDelete()` marker so list reads see it again. Throws on a non-soft table. */
383
479
  restore: (id: Id<string & T>) => Promise<void>;
384
480
  /**
385
- * Insert when no existing row matches `target`, otherwise patch the match with
386
- * `update` (defaulting to `create`). `target` names a `.unique()` column (or a
387
- * tuple) used to look it up. Returns the row id and whether it was `created`.
388
- * Composes `findFirst` + `insert`/`patch`, so RLS gates each step.
389
- */
481
+ * Insert when no existing row matches `target`, otherwise patch the match with
482
+ * `update` (defaulting to `create`). `target` names a `.unique()` column (or a
483
+ * tuple) used to look it up. Returns the row id and whether it was `created`.
484
+ * Composes `findFirst` + `insert`/`patch`, so RLS gates each step.
485
+ */
390
486
  upsert: (args: {
391
487
  create: IM[T];
392
488
  target: UpsertTargetOf<DM, T>;
@@ -409,8 +505,8 @@ interface TableWriterFacade<DM, IM extends Record<keyof DM, object>, REL extends
409
505
  }
410
506
  /** Conflict target for `upsert`/`upsertMany`: one column of table `T`, or a tuple of them. */
411
507
  type UpsertTargetOf<DM, T extends keyof DM> = ReadonlyArray<keyof DM[T] & string> | (keyof DM[T] & string);
412
- /** Per-table read facade — `ctx.db.&lt;table>` on a `QueryCtx`. */
413
- type DatabaseReaderFacade<DM, REL extends Record<keyof DM, object>, RANK extends Record<keyof DM, string>, SEARCH extends Record<keyof DM, string>> = { readonly [T in keyof DM]: TableReaderFacade<DM, REL, RANK, SEARCH, T> };
414
- /** Per-table read-write facade — `ctx.db.&lt;table>` on a `MutationCtx` / `ActionCtx`. */
415
- 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>> = { readonly [T in keyof DM]: TableWriterFacade<DM, IM, REL, RANK, SEARCH, T> };
416
- export { AggregateOp, DatabaseReaderFacade, DatabaseWriterFacade, GroupByEntry, Id, LoadWith, ManyRelationWhere, OneRelationWhere, OrderBy, QueryArgs, QueryArgsOf, QueryPage, RankPage, RankResult, RestrictableQueryOptions, RestrictableQueryOptionsOf, SearchFilterBuilder, SearchReader, TableAggregateOptions, TableAggregateOptionsOf, TableGroupByOptions, TableGroupByOptionsOf, TableRankOptions, TableRankPageOptions, TableReaderFacade, TableWriterFacade, UpsertTargetOf, Where, WhereOf, WhereOperators, WithArg };
508
+ /** Per-table read facade — `ctx.db.<table>` on a `QueryCtx`. */
509
+ 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>; };
510
+ /** Per-table read-write facade — `ctx.db.<table>` on a `MutationCtx` / `ActionCtx`. */
511
+ 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>; };
512
+ export { AggregateOp, DatabaseReaderFacade, DatabaseWriterFacade, GeoBoundingBox, GeoFilterBuilder, GeoPointInput, GeoReader, GroupByEntry, Id, LoadWith, ManyRelationWhere, OneRelationWhere, OrderBy, QueryArgs, QueryArgsOf, QueryPage, RankPage, RankResult, RestrictableQueryOptions, RestrictableQueryOptionsOf, SearchFilterBuilder, SearchReader, TableAggregateOptions, TableAggregateOptionsOf, TableGroupByOptions, TableGroupByOptionsOf, TableRankOptions, TableRankPageOptions, TableReaderFacade, TableWriterFacade, UpsertTargetOf, Where, WhereOf, WhereOperators, WithArg };
@@ -1 +0,0 @@
1
-
package/dist/drizzle.mjs CHANGED
@@ -1 +1 @@
1
- export * from 'drizzle-orm/sqlite-core';
1
+ export*from"drizzle-orm/sqlite-core";