better-convex 0.6.4 → 0.7.1

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 (47) hide show
  1. package/dist/aggregate/index.d.ts +390 -0
  2. package/dist/aggregate/index.js +37 -0
  3. package/dist/{auth-client → auth/client}/index.js +32 -15
  4. package/dist/auth/http/index.d.ts +63 -0
  5. package/dist/auth/http/index.js +429 -0
  6. package/dist/auth/index.d.ts +19009 -192
  7. package/dist/auth/index.js +402 -688
  8. package/dist/{auth-nextjs → auth/nextjs}/index.d.ts +3 -5
  9. package/dist/{auth-nextjs → auth/nextjs}/index.js +16 -13
  10. package/dist/{caller-factory-B1FvYSKr.js → caller-factory-D3OuR1eI.js} +20 -14
  11. package/dist/cli.mjs +2601 -13
  12. package/dist/codegen-Cz1idI3-.mjs +969 -0
  13. package/dist/{create-schema-orm-DplxTtYj.js → create-schema-orm-69VF4CFV.js} +4 -3
  14. package/dist/crpc/index.d.ts +2 -2
  15. package/dist/crpc/index.js +3 -3
  16. package/dist/{http-types-BRLY10NX.d.ts → http-types-BCf2wCgp.d.ts} +25 -25
  17. package/dist/meta-utils-DDVYp9Xf.js +117 -0
  18. package/dist/orm/index.d.ts +4 -3012
  19. package/dist/orm/index.js +9631 -2
  20. package/dist/{index-BQkhP2ny.d.ts → procedure-caller-CcjtUFvL.d.ts} +211 -74
  21. package/dist/query-context-BDSis9rT.js +1518 -0
  22. package/dist/query-context-DGExXZIV.d.ts +42 -0
  23. package/dist/react/index.d.ts +31 -35
  24. package/dist/react/index.js +152 -59
  25. package/dist/rsc/index.d.ts +4 -7
  26. package/dist/rsc/index.js +14 -10
  27. package/dist/runtime-B9xQFY8W.js +2280 -0
  28. package/dist/server/index.d.ts +3 -4
  29. package/dist/server/index.js +384 -10
  30. package/dist/{types-o-5rYcTr.d.ts → types-CIBGEYXq.d.ts} +4 -3
  31. package/dist/types-DgwvxKbT.d.ts +4 -0
  32. package/dist/watcher.mjs +8 -8
  33. package/dist/where-clause-compiler-CRP-i1Qa.d.ts +3463 -0
  34. package/package.json +15 -11
  35. package/dist/codegen-DkpPBVPn.mjs +0 -189
  36. package/dist/context-utils-DSuX99Da.d.ts +0 -17
  37. package/dist/meta-utils-DCpLSBWB.js +0 -41
  38. package/dist/orm-BKc-pwj_.js +0 -8821
  39. /package/dist/{auth-client → auth/client}/index.d.ts +0 -0
  40. /package/dist/{auth-config → auth/config}/index.d.ts +0 -0
  41. /package/dist/{auth-config → auth/config}/index.js +0 -0
  42. /package/dist/{create-schema-DhWXOhnU.js → create-schema-BdZOL6ns.js} +0 -0
  43. /package/dist/{customFunctions-C1okqCzL.js → customFunctions-CZnCwoR3.js} +0 -0
  44. /package/dist/{error-BZUhlhYz.js → error-Be4OcwwD.js} +0 -0
  45. /package/dist/{query-options-BL1Q0X7q.js → query-options-B0c1b6pZ.js} +0 -0
  46. /package/dist/{transformer-CTNSPjwp.js → transformer-Dh0w2py0.js} +0 -0
  47. /package/dist/{types-jftzhhuc.d.ts → types-DwGkkq2s.d.ts} +0 -0
@@ -0,0 +1,390 @@
1
+ import { Ft as ConvexTableWithColumns, J as ConvexTextBuilderInitial, Z as ConvexNumberBuilderInitial, et as ConvexIdBuilderInitial, st as ConvexCustomBuilderInitial } from "../where-clause-compiler-CRP-i1Qa.js";
2
+ import "../query-context-DGExXZIV.js";
3
+ import "../orm/index.js";
4
+ import * as convex_values0 from "convex/values";
5
+ import { GenericId, Infer, Value } from "convex/values";
6
+ import { DocumentByName, GenericDataModel, GenericDatabaseReader, GenericDatabaseWriter, TableNamesInDataModel } from "convex/server";
7
+
8
+ //#region src/aggregate-core/schema.d.ts
9
+ declare const aggregateStorageTables: {
10
+ readonly aggregate_rank_node: ConvexTableWithColumns<{
11
+ name: "aggregate_rank_node";
12
+ columns: {
13
+ aggregate: ConvexCustomBuilderInitial<"", convex_values0.VObject<{
14
+ count: number;
15
+ sum: number;
16
+ }, {
17
+ count: convex_values0.VFloat64<number, "required">;
18
+ sum: convex_values0.VFloat64<number, "required">;
19
+ }, "required", "count" | "sum">> & {
20
+ _: {
21
+ tableName: "aggregate_rank_node";
22
+ };
23
+ } & {
24
+ _: {
25
+ fieldName: "aggregate";
26
+ };
27
+ };
28
+ items: ConvexCustomBuilderInitial<"", convex_values0.VArray<{
29
+ k: any;
30
+ v: any;
31
+ s: number;
32
+ }[], convex_values0.VObject<{
33
+ k: any;
34
+ v: any;
35
+ s: number;
36
+ }, {
37
+ k: convex_values0.VAny<any, "required", string>;
38
+ v: convex_values0.VAny<any, "required", string>;
39
+ s: convex_values0.VFloat64<number, "required">;
40
+ }, "required", "k" | "v" | "s" | `k.${string}` | `v.${string}`>, "required">> & {
41
+ _: {
42
+ notNull: true;
43
+ };
44
+ } & {
45
+ _: {
46
+ tableName: "aggregate_rank_node";
47
+ };
48
+ } & {
49
+ _: {
50
+ fieldName: "items";
51
+ };
52
+ };
53
+ subtrees: ConvexCustomBuilderInitial<"", convex_values0.VArray<string[], convex_values0.VString<string, "required">, "required">> & {
54
+ _: {
55
+ notNull: true;
56
+ };
57
+ } & {
58
+ _: {
59
+ tableName: "aggregate_rank_node";
60
+ };
61
+ } & {
62
+ _: {
63
+ fieldName: "subtrees";
64
+ };
65
+ };
66
+ };
67
+ }, {
68
+ by_creation_time: ["_creationTime"];
69
+ }, {}, {}, {}>;
70
+ readonly aggregate_rank_tree: ConvexTableWithColumns<{
71
+ name: "aggregate_rank_tree";
72
+ columns: {
73
+ aggregateName: ConvexTextBuilderInitial<""> & {
74
+ _: {
75
+ notNull: true;
76
+ };
77
+ } & {
78
+ _: {
79
+ tableName: "aggregate_rank_tree";
80
+ };
81
+ } & {
82
+ _: {
83
+ fieldName: "aggregateName";
84
+ };
85
+ };
86
+ maxNodeSize: ConvexNumberBuilderInitial<""> & {
87
+ _: {
88
+ notNull: true;
89
+ };
90
+ } & {
91
+ _: {
92
+ tableName: "aggregate_rank_tree";
93
+ };
94
+ } & {
95
+ _: {
96
+ fieldName: "maxNodeSize";
97
+ };
98
+ };
99
+ namespace: ConvexCustomBuilderInitial<"", convex_values0.VAny<any, "required", string>> & {
100
+ _: {
101
+ tableName: "aggregate_rank_tree";
102
+ };
103
+ } & {
104
+ _: {
105
+ fieldName: "namespace";
106
+ };
107
+ };
108
+ root: ConvexIdBuilderInitial<"", "aggregate_rank_node"> & {
109
+ _: {
110
+ notNull: true;
111
+ };
112
+ } & {
113
+ _: {
114
+ tableName: "aggregate_rank_tree";
115
+ };
116
+ } & {
117
+ _: {
118
+ fieldName: "root";
119
+ };
120
+ };
121
+ };
122
+ }, {
123
+ by_creation_time: ["_creationTime"];
124
+ by_namespace: ["namespace", "_creationTime"];
125
+ by_aggregate_name: ["aggregateName", "_creationTime"];
126
+ }, {}, {}, {}>;
127
+ };
128
+ //#endregion
129
+ //#region src/aggregate-core/btree.d.ts
130
+ type Key$2 = Value;
131
+ //#endregion
132
+ //#region src/aggregate-core/positions.d.ts
133
+ type Bound$1<K extends Key$2, ID extends string> = {
134
+ key: K;
135
+ id?: ID;
136
+ inclusive: boolean;
137
+ };
138
+ type SideBounds<K extends Key$2, ID extends string> = {
139
+ lower?: Bound$1<K, ID>;
140
+ upper?: Bound$1<K, ID>;
141
+ };
142
+ type TuplePrefix<K extends unknown[], P extends unknown[] = []> = P['length'] extends K['length'] ? P : P | TuplePrefix<K, [...P, K[P['length']]]>;
143
+ type Bounds$1<K extends Key$2, ID extends string> = SideBounds<K, ID> | (K extends unknown[] ? {
144
+ prefix: TuplePrefix<Extract<K, unknown[]>>;
145
+ } : never) | {
146
+ eq: K;
147
+ };
148
+ //#endregion
149
+ //#region src/aggregate-core/runtime.d.ts
150
+ type Key = Key$2;
151
+ type Bound<K extends Key, ID extends string> = Bound$1<K, ID>;
152
+ type Bounds<K extends Key, ID extends string> = Bounds$1<K, ID>;
153
+ type AggregateQueryCtx = {
154
+ db: GenericDatabaseReader<any>;
155
+ orm: unknown;
156
+ };
157
+ type AggregateMutationCtx = {
158
+ db: GenericDatabaseWriter<any>;
159
+ orm: unknown;
160
+ };
161
+ type RunQueryCtx = AggregateQueryCtx;
162
+ type RunMutationCtx = AggregateMutationCtx;
163
+ type Item<K extends Key, ID extends string> = {
164
+ id: ID;
165
+ key: K;
166
+ sumValue: number;
167
+ };
168
+ /**
169
+ * Write data to be aggregated, and read aggregated data.
170
+ */
171
+ declare class Aggregate<K extends Key, ID extends string, TNamespace extends Value | undefined = undefined> {
172
+ protected readonly aggregateName: string;
173
+ constructor(aggregateName: string);
174
+ count(ctx: RunQueryCtx, ...opts: NamespacedOpts<{
175
+ bounds?: Bounds<K, ID>;
176
+ }, TNamespace>): Promise<number>;
177
+ countBatch(ctx: RunQueryCtx, queries: NamespacedOptsBatch<{
178
+ bounds?: Bounds<K, ID>;
179
+ }, TNamespace>): Promise<number[]>;
180
+ sum(ctx: RunQueryCtx, ...opts: NamespacedOpts<{
181
+ bounds?: Bounds<K, ID>;
182
+ }, TNamespace>): Promise<number>;
183
+ sumBatch(ctx: RunQueryCtx, queries: NamespacedOptsBatch<{
184
+ bounds?: Bounds<K, ID>;
185
+ }, TNamespace>): Promise<number[]>;
186
+ at(ctx: RunQueryCtx, offset: number, ...opts: NamespacedOpts<{
187
+ bounds?: Bounds<K, ID>;
188
+ }, TNamespace>): Promise<Item<K, ID>>;
189
+ atBatch(ctx: RunQueryCtx, queries: NamespacedOptsBatch<{
190
+ offset: number;
191
+ bounds?: Bounds<K, ID>;
192
+ }, TNamespace>): Promise<Item<K, ID>[]>;
193
+ indexOf(ctx: RunQueryCtx, key: K, ...opts: NamespacedOpts<{
194
+ bounds?: Bounds<K, ID>;
195
+ id?: ID;
196
+ order?: 'asc' | 'desc';
197
+ }, TNamespace>): Promise<number>;
198
+ offsetOf(ctx: RunQueryCtx, key: K, namespace: TNamespace, id?: ID, bounds?: Bounds<K, ID>): Promise<number>;
199
+ offsetUntil(ctx: RunQueryCtx, key: K, namespace: TNamespace, id?: ID, bounds?: Bounds<K, ID>): Promise<number>;
200
+ min(ctx: RunQueryCtx, ...opts: NamespacedOpts<{
201
+ bounds?: Bounds<K, ID>;
202
+ }, TNamespace>): Promise<Item<K, ID> | null>;
203
+ max(ctx: RunQueryCtx, ...opts: NamespacedOpts<{
204
+ bounds?: Bounds<K, ID>;
205
+ }, TNamespace>): Promise<Item<K, ID> | null>;
206
+ random(ctx: RunQueryCtx, ...opts: NamespacedOpts<{
207
+ bounds?: Bounds<K, ID>;
208
+ }, TNamespace>): Promise<Item<K, ID> | null>;
209
+ paginate(ctx: RunQueryCtx, ...opts: NamespacedOpts<{
210
+ bounds?: Bounds<K, ID>;
211
+ cursor?: string;
212
+ order?: 'asc' | 'desc';
213
+ pageSize?: number;
214
+ }, TNamespace>): Promise<{
215
+ cursor: string;
216
+ isDone: boolean;
217
+ page: Item<K, ID>[];
218
+ }>;
219
+ iter(ctx: RunQueryCtx, ...opts: NamespacedOpts<{
220
+ bounds?: Bounds<K, ID>;
221
+ order?: 'asc' | 'desc';
222
+ pageSize?: number;
223
+ }, TNamespace>): AsyncGenerator<Item<K, ID>, void, undefined>;
224
+ _insert(ctx: RunMutationCtx, namespace: TNamespace, key: K, id: ID, summand?: number): Promise<void>;
225
+ _delete(ctx: RunMutationCtx, namespace: TNamespace, key: K, id: ID): Promise<void>;
226
+ _replace(ctx: RunMutationCtx, currentNamespace: TNamespace, currentKey: K, newNamespace: TNamespace, newKey: K, id: ID, summand?: number): Promise<void>;
227
+ _insertIfDoesNotExist(ctx: RunMutationCtx, namespace: TNamespace, key: K, id: ID, summand?: number): Promise<void>;
228
+ _deleteIfExists(ctx: RunMutationCtx, namespace: TNamespace, key: K, id: ID): Promise<void>;
229
+ _replaceOrInsert(ctx: RunMutationCtx, currentNamespace: TNamespace, currentKey: K, newNamespace: TNamespace, newKey: K, id: ID, summand?: number): Promise<void>;
230
+ clear(ctx: RunMutationCtx, ...opts: NamespacedOpts<{
231
+ maxNodeSize?: number;
232
+ rootLazy?: boolean;
233
+ }, TNamespace>): Promise<void>;
234
+ makeRootLazy(ctx: RunMutationCtx, namespace: TNamespace): Promise<void>;
235
+ paginateNamespaces(ctx: RunQueryCtx, cursor?: string, pageSize?: number): Promise<{
236
+ cursor: string;
237
+ isDone: boolean;
238
+ page: TNamespace[];
239
+ }>;
240
+ iterNamespaces(ctx: RunQueryCtx, pageSize?: number): AsyncGenerator<TNamespace, void, undefined>;
241
+ clearAll(ctx: RunMutationCtx & RunQueryCtx, opts?: {
242
+ maxNodeSize?: number;
243
+ rootLazy?: boolean;
244
+ }): Promise<void>;
245
+ makeAllRootsLazy(ctx: RunMutationCtx & RunQueryCtx): Promise<void>;
246
+ }
247
+ type DirectAggregateType<K extends Key, ID extends string, TNamespace extends Value | undefined = undefined> = {
248
+ Key: K;
249
+ Id: ID;
250
+ Namespace?: TNamespace;
251
+ };
252
+ type AnyDirectAggregateType$1 = DirectAggregateType<Key, string, Value | undefined>;
253
+ type DirectAggregateNamespace<T extends AnyDirectAggregateType$1> = 'Namespace' extends keyof T ? T['Namespace'] : undefined;
254
+ declare class DirectAggregate$1<T extends AnyDirectAggregateType$1> extends Aggregate<T['Key'], T['Id'], DirectAggregateNamespace<T>> {
255
+ constructor(config: {
256
+ name: string;
257
+ });
258
+ insert(ctx: RunMutationCtx, args: NamespacedArgs<{
259
+ id: T['Id'];
260
+ key: T['Key'];
261
+ sumValue?: number;
262
+ }, DirectAggregateNamespace<T>>): Promise<void>;
263
+ delete(ctx: RunMutationCtx, args: NamespacedArgs<{
264
+ id: T['Id'];
265
+ key: T['Key'];
266
+ }, DirectAggregateNamespace<T>>): Promise<void>;
267
+ replace(ctx: RunMutationCtx, currentItem: NamespacedArgs<{
268
+ id: T['Id'];
269
+ key: T['Key'];
270
+ }, DirectAggregateNamespace<T>>, newItem: NamespacedArgs<{
271
+ key: T['Key'];
272
+ sumValue?: number;
273
+ }, DirectAggregateNamespace<T>>): Promise<void>;
274
+ insertIfDoesNotExist(ctx: RunMutationCtx, args: NamespacedArgs<{
275
+ id: T['Id'];
276
+ key: T['Key'];
277
+ sumValue?: number;
278
+ }, DirectAggregateNamespace<T>>): Promise<void>;
279
+ deleteIfExists(ctx: RunMutationCtx, args: NamespacedArgs<{
280
+ id: T['Id'];
281
+ key: T['Key'];
282
+ }, DirectAggregateNamespace<T>>): Promise<void>;
283
+ replaceOrInsert(ctx: RunMutationCtx, currentItem: NamespacedArgs<{
284
+ id: T['Id'];
285
+ key: T['Key'];
286
+ }, DirectAggregateNamespace<T>>, newItem: NamespacedArgs<{
287
+ key: T['Key'];
288
+ sumValue?: number;
289
+ }, DirectAggregateNamespace<T>>): Promise<void>;
290
+ }
291
+ type TableAggregateType<K extends Key, DataModel extends GenericDataModel, TableName extends TableNamesInDataModel<DataModel>, TNamespace extends Value | undefined = undefined> = {
292
+ DataModel: DataModel;
293
+ Key: K;
294
+ Namespace?: TNamespace;
295
+ TableName: TableName;
296
+ };
297
+ type AnyTableAggregateType$1 = TableAggregateType<Key, GenericDataModel, TableNamesInDataModel<GenericDataModel>, Value | undefined>;
298
+ type TableAggregateNamespace<T extends AnyTableAggregateType$1> = 'Namespace' extends keyof T ? T['Namespace'] : undefined;
299
+ type TableAggregateDocument<T extends AnyTableAggregateType$1> = DocumentByName<T['DataModel'], T['TableName']>;
300
+ type TableAggregateId<T extends AnyTableAggregateType$1> = GenericId<T['TableName']>;
301
+ type TableAggregateTrigger<Ctx, T extends AnyTableAggregateType$1> = Trigger<Ctx, T['DataModel'], T['TableName']>;
302
+ declare class TableAggregate$1<T extends AnyTableAggregateType$1> extends Aggregate<T['Key'], GenericId<T['TableName']>, TableAggregateNamespace<T>> {
303
+ constructor(options: {
304
+ name: string;
305
+ table: T['TableName'];
306
+ sortKey: (d: TableAggregateDocument<T>) => T['Key'];
307
+ sumValue?: (d: TableAggregateDocument<T>) => number;
308
+ } & (undefined extends TableAggregateNamespace<T> ? {
309
+ namespace?: (d: TableAggregateDocument<T>) => TableAggregateNamespace<T>;
310
+ } : {
311
+ namespace: (d: TableAggregateDocument<T>) => TableAggregateNamespace<T>;
312
+ }));
313
+ private readonly options;
314
+ insert(ctx: RunMutationCtx, doc: TableAggregateDocument<T>): Promise<void>;
315
+ delete(ctx: RunMutationCtx, doc: TableAggregateDocument<T>): Promise<void>;
316
+ replace(ctx: RunMutationCtx, oldDoc: TableAggregateDocument<T>, newDoc: TableAggregateDocument<T>): Promise<void>;
317
+ insertIfDoesNotExist(ctx: RunMutationCtx, doc: TableAggregateDocument<T>): Promise<void>;
318
+ deleteIfExists(ctx: RunMutationCtx, doc: TableAggregateDocument<T>): Promise<void>;
319
+ replaceOrInsert(ctx: RunMutationCtx, oldDoc: TableAggregateDocument<T>, newDoc: TableAggregateDocument<T>): Promise<void>;
320
+ indexOfDoc(ctx: RunQueryCtx, doc: TableAggregateDocument<T>, opts?: {
321
+ id?: TableAggregateId<T>;
322
+ bounds?: Bounds<T['Key'], TableAggregateId<T>>;
323
+ order?: 'asc' | 'desc';
324
+ }): Promise<number>;
325
+ trigger<Ctx extends RunMutationCtx>(): TableAggregateTrigger<Ctx, T>;
326
+ idempotentTrigger<Ctx extends RunMutationCtx>(): TableAggregateTrigger<Ctx, T>;
327
+ }
328
+ type Trigger<Ctx, DataModel extends GenericDataModel, TableName extends TableNamesInDataModel<DataModel>> = (ctx: Ctx, change: Change<DataModel, TableName>) => Promise<void>;
329
+ type Change<DataModel extends GenericDataModel, TableName extends TableNamesInDataModel<DataModel>> = {
330
+ id: GenericId<TableName> | string;
331
+ } & ({
332
+ operation: 'insert';
333
+ oldDoc: null;
334
+ newDoc: DocumentByName<DataModel, TableName>;
335
+ } | {
336
+ operation: 'update';
337
+ oldDoc: DocumentByName<DataModel, TableName>;
338
+ newDoc: DocumentByName<DataModel, TableName>;
339
+ } | {
340
+ operation: 'delete';
341
+ oldDoc: DocumentByName<DataModel, TableName>;
342
+ newDoc: null;
343
+ });
344
+ type NamespacedArgs<Args, TNamespace> = (Args & {
345
+ namespace: TNamespace;
346
+ }) | (TNamespace extends undefined ? Args : never);
347
+ type NamespacedOpts<Opts, TNamespace> = [{
348
+ namespace: TNamespace;
349
+ } & Opts] | (undefined extends TNamespace ? [Opts?] : never);
350
+ type NamespacedOptsBatch<Opts, TNamespace> = Array<undefined extends TNamespace ? Opts : {
351
+ namespace: TNamespace;
352
+ } & Opts>;
353
+ //#endregion
354
+ //#region src/orm/aggregate.d.ts
355
+ type AggregateTriggerFactoryLike = {
356
+ trigger: () => (ctx: unknown, change: unknown) => Promise<void>;
357
+ };
358
+ type AggregateTriggerCtx<T extends AggregateTriggerFactoryLike> = Parameters<ReturnType<T['trigger']>>[0];
359
+ type AggregateTriggerChange<T extends AggregateTriggerFactoryLike> = Parameters<ReturnType<T['trigger']>>[1];
360
+ type AggregateTriggerOverload<T extends AggregateTriggerFactoryLike> = {
361
+ (): ReturnType<T['trigger']>;
362
+ <TChange, TCtx>(change: TChange, ctx: TCtx): Promise<void>;
363
+ };
364
+ type OrmCompatibleAggregate<T extends AggregateTriggerFactoryLike> = Omit<T, 'trigger'> & {
365
+ trigger: AggregateTriggerOverload<T>;
366
+ };
367
+ //#endregion
368
+ //#region src/aggregate/index.d.ts
369
+ type Key$1 = Key;
370
+ type AnyDirectAggregateType = DirectAggregateType<Key$1, string, Value | undefined>;
371
+ type AnyTableAggregateType = TableAggregateType<Key$1, any, any, Value | undefined>;
372
+ type CoreTrigger<T extends AnyTableAggregateType> = ReturnType<TableAggregate$1<T>['trigger']>;
373
+ type CoreIdempotentTrigger<T extends AnyTableAggregateType> = ReturnType<TableAggregate$1<T>['idempotentTrigger']>;
374
+ declare class TableAggregate<T extends AnyTableAggregateType> extends TableAggregate$1<T> {
375
+ trigger: {
376
+ (): CoreTrigger<T>;
377
+ <TChange, TCtx>(change: TChange, ctx: TCtx): Promise<void>;
378
+ };
379
+ idempotentTrigger: {
380
+ (): CoreIdempotentTrigger<T>;
381
+ <TChange, TCtx>(change: TChange, ctx: TCtx): Promise<void>;
382
+ };
383
+ constructor(...args: ConstructorParameters<typeof TableAggregate$1>);
384
+ }
385
+ declare class DirectAggregate<T extends AnyDirectAggregateType> extends DirectAggregate$1<T> {}
386
+ declare function createDirectAggregate<T extends AnyDirectAggregateType>(config: {
387
+ name: string;
388
+ }): DirectAggregate<T>;
389
+ //#endregion
390
+ export { type AggregateTriggerChange, type AggregateTriggerCtx, type AggregateTriggerFactoryLike, type Bound, type Bounds, DirectAggregate, type DirectAggregateType, type Item, type Key, type OrmCompatibleAggregate, type RunMutationCtx, type RunQueryCtx, TableAggregate, type TableAggregateType, aggregateStorageTables, createDirectAggregate };
@@ -0,0 +1,37 @@
1
+ import { n as TableAggregate$1, r as aggregateStorageTables, t as DirectAggregate$1 } from "../runtime-B9xQFY8W.js";
2
+
3
+ //#region src/aggregate/index.ts
4
+ const wrapTriggerFactory = (methodName, factory) => ((...args) => {
5
+ if (args.length === 0) return factory();
6
+ if (args.length === 2) {
7
+ const [change, ctx] = args;
8
+ return factory()(ctx, change);
9
+ }
10
+ throw new Error(`Invalid aggregate.${methodName} invocation. Use ${methodName}() or ${methodName}(change, ctx).`);
11
+ });
12
+ var TableAggregate = class extends TableAggregate$1 {
13
+ constructor(...args) {
14
+ super(...args);
15
+ const triggerFactory = super.trigger.bind(this);
16
+ const idempotentFactory = super.idempotentTrigger.bind(this);
17
+ Object.defineProperty(this, "trigger", {
18
+ configurable: true,
19
+ enumerable: false,
20
+ value: wrapTriggerFactory("trigger", triggerFactory),
21
+ writable: true
22
+ });
23
+ Object.defineProperty(this, "idempotentTrigger", {
24
+ configurable: true,
25
+ enumerable: false,
26
+ value: wrapTriggerFactory("idempotentTrigger", idempotentFactory),
27
+ writable: true
28
+ });
29
+ }
30
+ };
31
+ var DirectAggregate = class extends DirectAggregate$1 {};
32
+ function createDirectAggregate(config) {
33
+ return new DirectAggregate(config);
34
+ }
35
+
36
+ //#endregion
37
+ export { DirectAggregate, TableAggregate, aggregateStorageTables, createDirectAggregate };
@@ -1,5 +1,5 @@
1
1
  'use client';
2
- import { a as FetchAccessTokenContext, b as CRPCClientError, l as decodeJwtExp, m as useAuthValue, p as useAuthStore, t as AuthProvider, x as defaultIsUnauthorized } from "../auth-store-DHapqI5u.js";
2
+ import { a as FetchAccessTokenContext, b as CRPCClientError, l as decodeJwtExp, m as useAuthValue, p as useAuthStore, t as AuthProvider, x as defaultIsUnauthorized } from "../../auth-store-DHapqI5u.js";
3
3
  import { convexClient } from "@convex-dev/better-auth/client/plugins";
4
4
  import { c } from "react/compiler-runtime";
5
5
  import { ConvexProviderWithAuth, useConvexAuth } from "convex/react";
@@ -16,6 +16,10 @@ const defaultMutationHandler = () => {
16
16
  functionName: "mutation"
17
17
  });
18
18
  };
19
+ const hasActiveSessionData = (session) => {
20
+ if (!session || typeof session !== "object") return false;
21
+ return Boolean(session.session);
22
+ };
19
23
  /**
20
24
  * Unified auth provider for Convex + Better Auth.
21
25
  * Handles token sync, HMR persistence, and auth callbacks.
@@ -88,10 +92,11 @@ function ConvexAuthProviderInner({ children, client, authClient }) {
88
92
  const { data: session, isPending } = authClient.useSession();
89
93
  const sessionRef = useRef(session);
90
94
  const isPendingRef = useRef(isPending);
95
+ const pendingTokenRef = useRef(null);
91
96
  sessionRef.current = session;
92
97
  isPendingRef.current = isPending;
93
98
  useEffect(() => {
94
- if (!session && !isPending) {
99
+ if (!hasActiveSessionData(session) && !isPending) {
95
100
  authStore.set("token", null);
96
101
  authStore.set("expiresAt", null);
97
102
  authStore.set("isAuthenticated", false);
@@ -104,7 +109,7 @@ function ConvexAuthProviderInner({ children, client, authClient }) {
104
109
  const fetchAccessToken = useCallback(async ({ forceRefreshToken = false } = {}) => {
105
110
  const currentSession = sessionRef.current;
106
111
  const currentIsPending = isPendingRef.current;
107
- if (!currentSession) {
112
+ if (!hasActiveSessionData(currentSession)) {
108
113
  if (!currentIsPending) {
109
114
  authStore.set("token", null);
110
115
  authStore.set("expiresAt", null);
@@ -115,27 +120,38 @@ function ConvexAuthProviderInner({ children, client, authClient }) {
115
120
  const expiresAt = authStore.get("expiresAt");
116
121
  const timeRemaining = expiresAt ? expiresAt - Date.now() : 0;
117
122
  if (!forceRefreshToken && cachedToken && expiresAt && timeRemaining >= 6e4) return cachedToken;
118
- try {
119
- const { data } = await authClient.convex.token();
120
- const jwt = data?.token || null;
123
+ if (!forceRefreshToken && pendingTokenRef.current) return pendingTokenRef.current;
124
+ pendingTokenRef.current = authClient.convex.token({ fetchOptions: { throw: false } }).then((result) => {
125
+ const jwt = result.data?.token || null;
121
126
  if (jwt) {
122
127
  const exp = decodeJwtExp(jwt);
123
128
  authStore.set("token", jwt);
124
129
  authStore.set("expiresAt", exp);
130
+ return jwt;
125
131
  }
126
- return jwt;
127
- } catch (e) {
128
- console.error("[fetchAccessToken] error", e);
132
+ authStore.set("token", null);
133
+ authStore.set("expiresAt", null);
129
134
  return null;
130
- }
135
+ }).catch((error) => {
136
+ authStore.set("token", null);
137
+ authStore.set("expiresAt", null);
138
+ console.error("[fetchAccessToken] error", error);
139
+ return null;
140
+ }).finally(() => {
141
+ pendingTokenRef.current = null;
142
+ });
143
+ return pendingTokenRef.current;
131
144
  }, [authStore, authClient]);
132
145
  const useAuth = useCallback(function useConvexAuthHook() {
146
+ const token = authStore.get("token");
147
+ const hasSession_0 = hasActiveSessionData(sessionRef.current);
148
+ const sessionMissing = !hasSession_0 && !isPendingRef.current;
133
149
  return {
134
- isLoading: isPendingRef.current,
135
- isAuthenticated: sessionRef.current !== null,
150
+ isLoading: isPendingRef.current && !token,
151
+ isAuthenticated: sessionMissing ? false : hasSession_0 || token !== null,
136
152
  fetchAccessToken
137
153
  };
138
- }, [fetchAccessToken]);
154
+ }, [fetchAccessToken, authStore]);
139
155
  return /* @__PURE__ */ jsx(FetchAccessTokenContext.Provider, {
140
156
  value: fetchAccessToken,
141
157
  children: /* @__PURE__ */ jsx(ConvexProviderWithAuth, {
@@ -200,17 +216,18 @@ function useOTTHandler(authClient) {
200
216
  if ($[0] !== authClient) {
201
217
  t0 = () => {
202
218
  (async () => {
203
- const url = new URL(window.location?.href);
219
+ if (typeof window === "undefined" || !window.location?.href) return;
220
+ const url = new URL(window.location.href);
204
221
  const token = url.searchParams.get("ott");
205
222
  if (token) {
206
223
  const authClientWithCrossDomain = authClient;
207
224
  url.searchParams.delete("ott");
225
+ window.history.replaceState({}, "", url);
208
226
  const session = (await authClientWithCrossDomain.crossDomain.oneTimeToken.verify({ token })).data?.session;
209
227
  if (session) {
210
228
  await authClient.getSession({ fetchOptions: { headers: { Authorization: `Bearer ${session.token}` } } });
211
229
  authClientWithCrossDomain.updateSession();
212
230
  }
213
- window.history.replaceState({}, "", url);
214
231
  }
215
232
  })();
216
233
  };
@@ -0,0 +1,63 @@
1
+ import { t as GetAuth } from "../../types-DgwvxKbT.js";
2
+ import { HttpRouter } from "convex/server";
3
+ import { MiddlewareHandler } from "hono";
4
+
5
+ //#region src/auth/middleware.d.ts
6
+ interface AuthMiddlewareOptions {
7
+ /** Base path for auth routes (default: '/api/auth') */
8
+ basePath?: string;
9
+ /** Log request/response headers for debugging */
10
+ verbose?: boolean;
11
+ }
12
+ /**
13
+ * Create auth middleware that handles auth routes and OpenID well-known redirect.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * import { Hono } from 'hono';
18
+ * import { cors } from 'hono/cors';
19
+ * import { authMiddleware } from 'better-convex/auth/http';
20
+ * import { createHttpRouter } from 'better-convex/server';
21
+ *
22
+ * const app = new Hono();
23
+ * app.use('/api/*', cors({ origin: process.env.SITE_URL, credentials: true }));
24
+ * app.use(authMiddleware(getAuth));
25
+ *
26
+ * export default createHttpRouter(app, httpRouter);
27
+ * ```
28
+ */
29
+ declare function authMiddleware(getAuth: GetAuth<unknown, {
30
+ handler: (request: Request) => Promise<Response>;
31
+ }>, opts?: AuthMiddlewareOptions): MiddlewareHandler;
32
+ //#endregion
33
+ //#region src/auth/registerRoutes.d.ts
34
+ type AuthRouteContract = {
35
+ $context: Promise<{
36
+ options: {
37
+ trustedOrigins?: string[] | ((request: Request) => Promise<string[]> | string[]);
38
+ };
39
+ }>;
40
+ handler: (request: Request) => Promise<Response>;
41
+ options: {
42
+ basePath?: string;
43
+ baseURL?: string;
44
+ trustedOrigins?: string[] | ((request: Request) => Promise<string[]> | string[]);
45
+ };
46
+ };
47
+ declare const registerRoutes: (http: HttpRouter, getAuth: GetAuth<unknown, AuthRouteContract>, opts?: {
48
+ cors?: {
49
+ allowedHeaders?: string[];
50
+ allowedOrigins?: string[];
51
+ exposedHeaders?: string[];
52
+ } | boolean;
53
+ verbose?: boolean;
54
+ }) => void;
55
+ //#endregion
56
+ //#region src/auth-http/index.d.ts
57
+ /**
58
+ * Install Convex-safe polyfills required by Better Auth's HTTP handling.
59
+ * This runs automatically when importing `better-convex/auth/http`.
60
+ */
61
+ declare function installAuthHttpPolyfills(): void;
62
+ //#endregion
63
+ export { authMiddleware, installAuthHttpPolyfills, registerRoutes };