better-convex 0.9.0 → 0.9.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.
- package/dist/auth/client/index.js +50 -29
- package/dist/auth/index.d.ts +74 -74
- package/dist/cli.mjs +17 -12
- package/dist/{codegen-BS36cYTH.mjs → codegen-CMQIKrqh.mjs} +37 -32
- package/dist/server/index.js +6 -3
- package/dist/watcher.mjs +1 -1
- package/package.json +1 -1
|
@@ -107,48 +107,69 @@ function ConvexAuthProviderInner({ children, client, authClient }) {
|
|
|
107
107
|
authStore
|
|
108
108
|
]);
|
|
109
109
|
const fetchAccessToken = useCallback(async ({ forceRefreshToken = false } = {}) => {
|
|
110
|
+
const fetchFreshToken = () => {
|
|
111
|
+
if (pendingTokenRef.current) return pendingTokenRef.current;
|
|
112
|
+
pendingTokenRef.current = authClient.convex.token({ fetchOptions: { throw: false } }).then((result) => {
|
|
113
|
+
const jwt = result.data?.token || null;
|
|
114
|
+
if (jwt) {
|
|
115
|
+
const exp = decodeJwtExp(jwt);
|
|
116
|
+
authStore.set("token", jwt);
|
|
117
|
+
authStore.set("expiresAt", exp);
|
|
118
|
+
return jwt;
|
|
119
|
+
}
|
|
120
|
+
authStore.set("token", null);
|
|
121
|
+
authStore.set("expiresAt", null);
|
|
122
|
+
return null;
|
|
123
|
+
}).catch((error) => {
|
|
124
|
+
authStore.set("token", null);
|
|
125
|
+
authStore.set("expiresAt", null);
|
|
126
|
+
console.error("[fetchAccessToken] error", error);
|
|
127
|
+
return null;
|
|
128
|
+
}).finally(() => {
|
|
129
|
+
pendingTokenRef.current = null;
|
|
130
|
+
});
|
|
131
|
+
return pendingTokenRef.current;
|
|
132
|
+
};
|
|
133
|
+
const fetchFreshTokenForced = async () => {
|
|
134
|
+
if (pendingTokenRef.current) {
|
|
135
|
+
const token = await pendingTokenRef.current;
|
|
136
|
+
if (token) return token;
|
|
137
|
+
}
|
|
138
|
+
return fetchFreshToken();
|
|
139
|
+
};
|
|
110
140
|
const currentSession = sessionRef.current;
|
|
111
141
|
const currentIsPending = isPendingRef.current;
|
|
112
142
|
if (!hasActiveSessionData(currentSession)) {
|
|
113
|
-
if (
|
|
114
|
-
authStore.
|
|
115
|
-
authStore.
|
|
143
|
+
if (currentIsPending) {
|
|
144
|
+
if (!forceRefreshToken) return authStore.get("token");
|
|
145
|
+
const cachedToken = authStore.get("token");
|
|
146
|
+
const freshToken = await fetchFreshTokenForced();
|
|
147
|
+
if (!freshToken && cachedToken) {
|
|
148
|
+
authStore.set("token", cachedToken);
|
|
149
|
+
authStore.set("expiresAt", decodeJwtExp(cachedToken));
|
|
150
|
+
return cachedToken;
|
|
151
|
+
}
|
|
152
|
+
return freshToken;
|
|
116
153
|
}
|
|
117
|
-
|
|
154
|
+
authStore.set("token", null);
|
|
155
|
+
authStore.set("expiresAt", null);
|
|
156
|
+
return null;
|
|
118
157
|
}
|
|
119
|
-
const
|
|
158
|
+
const cachedToken_0 = authStore.get("token");
|
|
120
159
|
const expiresAt = authStore.get("expiresAt");
|
|
121
160
|
const timeRemaining = expiresAt ? expiresAt - Date.now() : 0;
|
|
122
|
-
if (!forceRefreshToken &&
|
|
161
|
+
if (!forceRefreshToken && cachedToken_0 && expiresAt && timeRemaining >= 6e4) return cachedToken_0;
|
|
123
162
|
if (!forceRefreshToken && pendingTokenRef.current) return pendingTokenRef.current;
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
if (jwt) {
|
|
127
|
-
const exp = decodeJwtExp(jwt);
|
|
128
|
-
authStore.set("token", jwt);
|
|
129
|
-
authStore.set("expiresAt", exp);
|
|
130
|
-
return jwt;
|
|
131
|
-
}
|
|
132
|
-
authStore.set("token", null);
|
|
133
|
-
authStore.set("expiresAt", null);
|
|
134
|
-
return null;
|
|
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;
|
|
163
|
+
if (forceRefreshToken) return fetchFreshTokenForced();
|
|
164
|
+
return fetchFreshToken();
|
|
144
165
|
}, [authStore, authClient]);
|
|
145
166
|
const useAuth = useCallback(function useConvexAuthHook() {
|
|
146
|
-
const
|
|
167
|
+
const token_0 = authStore.get("token");
|
|
147
168
|
const hasSession_0 = hasActiveSessionData(sessionRef.current);
|
|
148
169
|
const sessionMissing = !hasSession_0 && !isPendingRef.current;
|
|
149
170
|
return {
|
|
150
|
-
isLoading: isPendingRef.current && !
|
|
151
|
-
isAuthenticated: sessionMissing ? false : hasSession_0 ||
|
|
171
|
+
isLoading: isPendingRef.current && !token_0,
|
|
172
|
+
isAuthenticated: sessionMissing ? false : hasSession_0 || token_0 !== null,
|
|
152
173
|
fetchAccessToken
|
|
153
174
|
};
|
|
154
175
|
}, [fetchAccessToken, authStore]);
|
package/dist/auth/index.d.ts
CHANGED
|
@@ -182,28 +182,28 @@ type AdapterPaginationOptions = PaginationOptions & {
|
|
|
182
182
|
};
|
|
183
183
|
declare const adapterWhereValidator: convex_values0.VObject<{
|
|
184
184
|
connector?: "AND" | "OR" | undefined;
|
|
185
|
-
operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "
|
|
186
|
-
field: string;
|
|
185
|
+
operator?: "in" | "lt" | "lte" | "gt" | "gte" | "eq" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
187
186
|
value: string | number | boolean | string[] | number[] | null;
|
|
187
|
+
field: string;
|
|
188
188
|
}, {
|
|
189
189
|
connector: convex_values0.VUnion<"AND" | "OR" | undefined, [convex_values0.VLiteral<"AND", "required">, convex_values0.VLiteral<"OR", "required">], "optional", never>;
|
|
190
190
|
field: convex_values0.VString<string, "required">;
|
|
191
|
-
operator: convex_values0.VUnion<"lt" | "lte" | "gt" | "gte" | "eq" | "
|
|
191
|
+
operator: convex_values0.VUnion<"in" | "lt" | "lte" | "gt" | "gte" | "eq" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined, [convex_values0.VLiteral<"lt", "required">, convex_values0.VLiteral<"lte", "required">, convex_values0.VLiteral<"gt", "required">, convex_values0.VLiteral<"gte", "required">, convex_values0.VLiteral<"eq", "required">, convex_values0.VLiteral<"in", "required">, convex_values0.VLiteral<"not_in", "required">, convex_values0.VLiteral<"ne", "required">, convex_values0.VLiteral<"contains", "required">, convex_values0.VLiteral<"starts_with", "required">, convex_values0.VLiteral<"ends_with", "required">], "optional", never>;
|
|
192
192
|
value: convex_values0.VUnion<string | number | boolean | string[] | number[] | null, [convex_values0.VString<string, "required">, convex_values0.VFloat64<number, "required">, convex_values0.VBoolean<boolean, "required">, convex_values0.VArray<string[], convex_values0.VString<string, "required">, "required">, convex_values0.VArray<number[], convex_values0.VFloat64<number, "required">, "required">, convex_values0.VNull<null, "required">], "required", never>;
|
|
193
|
-
}, "required", "
|
|
193
|
+
}, "required", "value" | "connector" | "field" | "operator">;
|
|
194
194
|
declare const adapterArgsValidator: convex_values0.VObject<{
|
|
195
195
|
limit?: number | undefined;
|
|
196
196
|
select?: string[] | undefined;
|
|
197
197
|
offset?: number | undefined;
|
|
198
198
|
sortBy?: {
|
|
199
|
-
field: string;
|
|
200
199
|
direction: "asc" | "desc";
|
|
200
|
+
field: string;
|
|
201
201
|
} | undefined;
|
|
202
202
|
where?: {
|
|
203
203
|
connector?: "AND" | "OR" | undefined;
|
|
204
|
-
operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "
|
|
205
|
-
field: string;
|
|
204
|
+
operator?: "in" | "lt" | "lte" | "gt" | "gte" | "eq" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
206
205
|
value: string | number | boolean | string[] | number[] | null;
|
|
206
|
+
field: string;
|
|
207
207
|
}[] | undefined;
|
|
208
208
|
model: string;
|
|
209
209
|
}, {
|
|
@@ -212,29 +212,29 @@ declare const adapterArgsValidator: convex_values0.VObject<{
|
|
|
212
212
|
offset: convex_values0.VFloat64<number | undefined, "optional">;
|
|
213
213
|
select: convex_values0.VArray<string[] | undefined, convex_values0.VString<string, "required">, "optional">;
|
|
214
214
|
sortBy: convex_values0.VObject<{
|
|
215
|
-
field: string;
|
|
216
215
|
direction: "asc" | "desc";
|
|
216
|
+
field: string;
|
|
217
217
|
} | undefined, {
|
|
218
218
|
direction: convex_values0.VUnion<"asc" | "desc", [convex_values0.VLiteral<"asc", "required">, convex_values0.VLiteral<"desc", "required">], "required", never>;
|
|
219
219
|
field: convex_values0.VString<string, "required">;
|
|
220
|
-
}, "optional", "
|
|
220
|
+
}, "optional", "direction" | "field">;
|
|
221
221
|
where: convex_values0.VArray<{
|
|
222
222
|
connector?: "AND" | "OR" | undefined;
|
|
223
|
-
operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "
|
|
224
|
-
field: string;
|
|
223
|
+
operator?: "in" | "lt" | "lte" | "gt" | "gte" | "eq" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
225
224
|
value: string | number | boolean | string[] | number[] | null;
|
|
225
|
+
field: string;
|
|
226
226
|
}[] | undefined, convex_values0.VObject<{
|
|
227
227
|
connector?: "AND" | "OR" | undefined;
|
|
228
|
-
operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "
|
|
229
|
-
field: string;
|
|
228
|
+
operator?: "in" | "lt" | "lte" | "gt" | "gte" | "eq" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
230
229
|
value: string | number | boolean | string[] | number[] | null;
|
|
230
|
+
field: string;
|
|
231
231
|
}, {
|
|
232
232
|
connector: convex_values0.VUnion<"AND" | "OR" | undefined, [convex_values0.VLiteral<"AND", "required">, convex_values0.VLiteral<"OR", "required">], "optional", never>;
|
|
233
233
|
field: convex_values0.VString<string, "required">;
|
|
234
|
-
operator: convex_values0.VUnion<"lt" | "lte" | "gt" | "gte" | "eq" | "
|
|
234
|
+
operator: convex_values0.VUnion<"in" | "lt" | "lte" | "gt" | "gte" | "eq" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined, [convex_values0.VLiteral<"lt", "required">, convex_values0.VLiteral<"lte", "required">, convex_values0.VLiteral<"gt", "required">, convex_values0.VLiteral<"gte", "required">, convex_values0.VLiteral<"eq", "required">, convex_values0.VLiteral<"in", "required">, convex_values0.VLiteral<"not_in", "required">, convex_values0.VLiteral<"ne", "required">, convex_values0.VLiteral<"contains", "required">, convex_values0.VLiteral<"starts_with", "required">, convex_values0.VLiteral<"ends_with", "required">], "optional", never>;
|
|
235
235
|
value: convex_values0.VUnion<string | number | boolean | string[] | number[] | null, [convex_values0.VString<string, "required">, convex_values0.VFloat64<number, "required">, convex_values0.VBoolean<boolean, "required">, convex_values0.VArray<string[], convex_values0.VString<string, "required">, "required">, convex_values0.VArray<number[], convex_values0.VFloat64<number, "required">, "required">, convex_values0.VNull<null, "required">], "required", never>;
|
|
236
|
-
}, "required", "
|
|
237
|
-
}, "required", "limit" | "model" | "select" | "offset" | "sortBy" | "where" | "sortBy.
|
|
236
|
+
}, "required", "value" | "connector" | "field" | "operator">, "optional">;
|
|
237
|
+
}, "required", "limit" | "model" | "select" | "offset" | "sortBy" | "where" | "sortBy.direction" | "sortBy.field">;
|
|
238
238
|
declare const hasUniqueFields: (betterAuthSchema: BetterAuthDBSchema, model: string, input: Record<string, any>) => boolean;
|
|
239
239
|
declare const checkUniqueFields: <Schema extends SchemaDefinition<any, any>>(ctx: GenericQueryCtx<GenericDataModel>, schema: Schema, betterAuthSchema: BetterAuthDBSchema, table: string, input: Record<string, any>, doc?: Record<string, any>) => Promise<void>;
|
|
240
240
|
declare const selectFields: <T extends TableNamesInDataModel<GenericDataModel>, D extends DocumentByName<GenericDataModel, T>>(doc: D | null, select?: string[]) => Promise<D | null>;
|
|
@@ -359,26 +359,26 @@ declare const createApi: <Schema extends SchemaDefinition<any, any>, DataModel e
|
|
|
359
359
|
};
|
|
360
360
|
}, Promise<any>>;
|
|
361
361
|
deleteMany: convex_server0.RegisteredMutation<"internal", {
|
|
362
|
-
paginationOpts: {
|
|
363
|
-
id?: number;
|
|
364
|
-
endCursor?: string | null;
|
|
365
|
-
maximumRowsRead?: number;
|
|
366
|
-
maximumBytesRead?: number;
|
|
367
|
-
numItems: number;
|
|
368
|
-
cursor: string | null;
|
|
369
|
-
};
|
|
370
362
|
input: {
|
|
371
363
|
where?: {
|
|
372
364
|
connector?: "AND" | "OR" | undefined;
|
|
373
|
-
operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "
|
|
374
|
-
field: string;
|
|
365
|
+
operator?: "in" | "lt" | "lte" | "gt" | "gte" | "eq" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
375
366
|
value: string | number | boolean | string[] | number[] | null;
|
|
367
|
+
field: string;
|
|
376
368
|
}[] | undefined;
|
|
377
369
|
model: string;
|
|
378
370
|
} | {
|
|
379
371
|
where?: any[] | undefined;
|
|
380
372
|
model: string;
|
|
381
373
|
};
|
|
374
|
+
paginationOpts: {
|
|
375
|
+
id?: number;
|
|
376
|
+
endCursor?: string | null;
|
|
377
|
+
maximumRowsRead?: number;
|
|
378
|
+
maximumBytesRead?: number;
|
|
379
|
+
numItems: number;
|
|
380
|
+
cursor: string | null;
|
|
381
|
+
};
|
|
382
382
|
}, Promise<{
|
|
383
383
|
count: number;
|
|
384
384
|
ids: any[];
|
|
@@ -391,9 +391,9 @@ declare const createApi: <Schema extends SchemaDefinition<any, any>, DataModel e
|
|
|
391
391
|
input: {
|
|
392
392
|
where?: {
|
|
393
393
|
connector?: "AND" | "OR" | undefined;
|
|
394
|
-
operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "
|
|
395
|
-
field: string;
|
|
394
|
+
operator?: "in" | "lt" | "lte" | "gt" | "gte" | "eq" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
396
395
|
value: string | number | boolean | string[] | number[] | null;
|
|
396
|
+
field: string;
|
|
397
397
|
}[] | undefined;
|
|
398
398
|
model: string;
|
|
399
399
|
} | {
|
|
@@ -406,14 +406,14 @@ declare const createApi: <Schema extends SchemaDefinition<any, any>, DataModel e
|
|
|
406
406
|
join?: any;
|
|
407
407
|
offset?: number | undefined;
|
|
408
408
|
sortBy?: {
|
|
409
|
-
field: string;
|
|
410
409
|
direction: "asc" | "desc";
|
|
410
|
+
field: string;
|
|
411
411
|
} | undefined;
|
|
412
412
|
where?: {
|
|
413
413
|
connector?: "AND" | "OR" | undefined;
|
|
414
|
-
operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "
|
|
415
|
-
field: string;
|
|
414
|
+
operator?: "in" | "lt" | "lte" | "gt" | "gte" | "eq" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
416
415
|
value: string | number | boolean | string[] | number[] | null;
|
|
416
|
+
field: string;
|
|
417
417
|
}[] | undefined;
|
|
418
418
|
paginationOpts: {
|
|
419
419
|
id?: number;
|
|
@@ -430,27 +430,19 @@ declare const createApi: <Schema extends SchemaDefinition<any, any>, DataModel e
|
|
|
430
430
|
select?: string[] | undefined;
|
|
431
431
|
where?: {
|
|
432
432
|
connector?: "AND" | "OR" | undefined;
|
|
433
|
-
operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "
|
|
434
|
-
field: string;
|
|
433
|
+
operator?: "in" | "lt" | "lte" | "gt" | "gte" | "eq" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
435
434
|
value: string | number | boolean | string[] | number[] | null;
|
|
435
|
+
field: string;
|
|
436
436
|
}[] | undefined;
|
|
437
437
|
model: string;
|
|
438
438
|
}, Promise<convex_server0.GenericDocument | null>>;
|
|
439
439
|
updateMany: convex_server0.RegisteredMutation<"internal", {
|
|
440
|
-
paginationOpts: {
|
|
441
|
-
id?: number;
|
|
442
|
-
endCursor?: string | null;
|
|
443
|
-
maximumRowsRead?: number;
|
|
444
|
-
maximumBytesRead?: number;
|
|
445
|
-
numItems: number;
|
|
446
|
-
cursor: string | null;
|
|
447
|
-
};
|
|
448
440
|
input: {
|
|
449
441
|
where?: {
|
|
450
442
|
connector?: "AND" | "OR" | undefined;
|
|
451
|
-
operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "
|
|
452
|
-
field: string;
|
|
443
|
+
operator?: "in" | "lt" | "lte" | "gt" | "gte" | "eq" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
453
444
|
value: string | number | boolean | string[] | number[] | null;
|
|
445
|
+
field: string;
|
|
454
446
|
}[] | undefined;
|
|
455
447
|
update: {
|
|
456
448
|
[x: string]: unknown;
|
|
@@ -463,6 +455,14 @@ declare const createApi: <Schema extends SchemaDefinition<any, any>, DataModel e
|
|
|
463
455
|
update: any;
|
|
464
456
|
model: string;
|
|
465
457
|
};
|
|
458
|
+
paginationOpts: {
|
|
459
|
+
id?: number;
|
|
460
|
+
endCursor?: string | null;
|
|
461
|
+
maximumRowsRead?: number;
|
|
462
|
+
maximumBytesRead?: number;
|
|
463
|
+
numItems: number;
|
|
464
|
+
cursor: string | null;
|
|
465
|
+
};
|
|
466
466
|
}, Promise<{
|
|
467
467
|
count: number;
|
|
468
468
|
ids: any[];
|
|
@@ -475,9 +475,9 @@ declare const createApi: <Schema extends SchemaDefinition<any, any>, DataModel e
|
|
|
475
475
|
input: {
|
|
476
476
|
where?: {
|
|
477
477
|
connector?: "AND" | "OR" | undefined;
|
|
478
|
-
operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "
|
|
479
|
-
field: string;
|
|
478
|
+
operator?: "in" | "lt" | "lte" | "gt" | "gte" | "eq" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
480
479
|
value: string | number | boolean | string[] | number[] | null;
|
|
480
|
+
field: string;
|
|
481
481
|
}[] | undefined;
|
|
482
482
|
update: {
|
|
483
483
|
[x: string]: unknown;
|
|
@@ -19155,26 +19155,26 @@ declare const createAuthRuntime: <DataModel extends GenericDataModel, Schema ext
|
|
|
19155
19155
|
};
|
|
19156
19156
|
}, Promise<any>>;
|
|
19157
19157
|
deleteMany: convex_server0.RegisteredMutation<"internal", {
|
|
19158
|
-
paginationOpts: {
|
|
19159
|
-
id?: number;
|
|
19160
|
-
endCursor?: string | null;
|
|
19161
|
-
maximumRowsRead?: number;
|
|
19162
|
-
maximumBytesRead?: number;
|
|
19163
|
-
numItems: number;
|
|
19164
|
-
cursor: string | null;
|
|
19165
|
-
};
|
|
19166
19158
|
input: {
|
|
19167
19159
|
where?: {
|
|
19168
19160
|
connector?: "AND" | "OR" | undefined;
|
|
19169
|
-
operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "
|
|
19170
|
-
field: string;
|
|
19161
|
+
operator?: "in" | "lt" | "lte" | "gt" | "gte" | "eq" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
19171
19162
|
value: string | number | boolean | string[] | number[] | null;
|
|
19163
|
+
field: string;
|
|
19172
19164
|
}[] | undefined;
|
|
19173
19165
|
model: string;
|
|
19174
19166
|
} | {
|
|
19175
19167
|
where?: any[] | undefined;
|
|
19176
19168
|
model: string;
|
|
19177
19169
|
};
|
|
19170
|
+
paginationOpts: {
|
|
19171
|
+
id?: number;
|
|
19172
|
+
endCursor?: string | null;
|
|
19173
|
+
maximumRowsRead?: number;
|
|
19174
|
+
maximumBytesRead?: number;
|
|
19175
|
+
numItems: number;
|
|
19176
|
+
cursor: string | null;
|
|
19177
|
+
};
|
|
19178
19178
|
}, Promise<{
|
|
19179
19179
|
count: number;
|
|
19180
19180
|
ids: any[];
|
|
@@ -19187,9 +19187,9 @@ declare const createAuthRuntime: <DataModel extends GenericDataModel, Schema ext
|
|
|
19187
19187
|
input: {
|
|
19188
19188
|
where?: {
|
|
19189
19189
|
connector?: "AND" | "OR" | undefined;
|
|
19190
|
-
operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "
|
|
19191
|
-
field: string;
|
|
19190
|
+
operator?: "in" | "lt" | "lte" | "gt" | "gte" | "eq" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
19192
19191
|
value: string | number | boolean | string[] | number[] | null;
|
|
19192
|
+
field: string;
|
|
19193
19193
|
}[] | undefined;
|
|
19194
19194
|
model: string;
|
|
19195
19195
|
} | {
|
|
@@ -19202,14 +19202,14 @@ declare const createAuthRuntime: <DataModel extends GenericDataModel, Schema ext
|
|
|
19202
19202
|
join?: any;
|
|
19203
19203
|
offset?: number | undefined;
|
|
19204
19204
|
sortBy?: {
|
|
19205
|
-
field: string;
|
|
19206
19205
|
direction: "asc" | "desc";
|
|
19206
|
+
field: string;
|
|
19207
19207
|
} | undefined;
|
|
19208
19208
|
where?: {
|
|
19209
19209
|
connector?: "AND" | "OR" | undefined;
|
|
19210
|
-
operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "
|
|
19211
|
-
field: string;
|
|
19210
|
+
operator?: "in" | "lt" | "lte" | "gt" | "gte" | "eq" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
19212
19211
|
value: string | number | boolean | string[] | number[] | null;
|
|
19212
|
+
field: string;
|
|
19213
19213
|
}[] | undefined;
|
|
19214
19214
|
paginationOpts: {
|
|
19215
19215
|
id?: number;
|
|
@@ -19226,27 +19226,19 @@ declare const createAuthRuntime: <DataModel extends GenericDataModel, Schema ext
|
|
|
19226
19226
|
select?: string[] | undefined;
|
|
19227
19227
|
where?: {
|
|
19228
19228
|
connector?: "AND" | "OR" | undefined;
|
|
19229
|
-
operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "
|
|
19230
|
-
field: string;
|
|
19229
|
+
operator?: "in" | "lt" | "lte" | "gt" | "gte" | "eq" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
19231
19230
|
value: string | number | boolean | string[] | number[] | null;
|
|
19231
|
+
field: string;
|
|
19232
19232
|
}[] | undefined;
|
|
19233
19233
|
model: string;
|
|
19234
19234
|
}, Promise<convex_server0.GenericDocument | null>>;
|
|
19235
19235
|
updateMany: convex_server0.RegisteredMutation<"internal", {
|
|
19236
|
-
paginationOpts: {
|
|
19237
|
-
id?: number;
|
|
19238
|
-
endCursor?: string | null;
|
|
19239
|
-
maximumRowsRead?: number;
|
|
19240
|
-
maximumBytesRead?: number;
|
|
19241
|
-
numItems: number;
|
|
19242
|
-
cursor: string | null;
|
|
19243
|
-
};
|
|
19244
19236
|
input: {
|
|
19245
19237
|
where?: {
|
|
19246
19238
|
connector?: "AND" | "OR" | undefined;
|
|
19247
|
-
operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "
|
|
19248
|
-
field: string;
|
|
19239
|
+
operator?: "in" | "lt" | "lte" | "gt" | "gte" | "eq" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
19249
19240
|
value: string | number | boolean | string[] | number[] | null;
|
|
19241
|
+
field: string;
|
|
19250
19242
|
}[] | undefined;
|
|
19251
19243
|
update: {
|
|
19252
19244
|
[x: string]: unknown;
|
|
@@ -19259,6 +19251,14 @@ declare const createAuthRuntime: <DataModel extends GenericDataModel, Schema ext
|
|
|
19259
19251
|
update: any;
|
|
19260
19252
|
model: string;
|
|
19261
19253
|
};
|
|
19254
|
+
paginationOpts: {
|
|
19255
|
+
id?: number;
|
|
19256
|
+
endCursor?: string | null;
|
|
19257
|
+
maximumRowsRead?: number;
|
|
19258
|
+
maximumBytesRead?: number;
|
|
19259
|
+
numItems: number;
|
|
19260
|
+
cursor: string | null;
|
|
19261
|
+
};
|
|
19262
19262
|
}, Promise<{
|
|
19263
19263
|
count: number;
|
|
19264
19264
|
ids: any[];
|
|
@@ -19271,9 +19271,9 @@ declare const createAuthRuntime: <DataModel extends GenericDataModel, Schema ext
|
|
|
19271
19271
|
input: {
|
|
19272
19272
|
where?: {
|
|
19273
19273
|
connector?: "AND" | "OR" | undefined;
|
|
19274
|
-
operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "
|
|
19275
|
-
field: string;
|
|
19274
|
+
operator?: "in" | "lt" | "lte" | "gt" | "gte" | "eq" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
19276
19275
|
value: string | number | boolean | string[] | number[] | null;
|
|
19276
|
+
field: string;
|
|
19277
19277
|
}[] | undefined;
|
|
19278
19278
|
update: {
|
|
19279
19279
|
[x: string]: unknown;
|
package/dist/cli.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { n as getConvexConfig, t as generateMeta } from "./codegen-
|
|
2
|
+
import { n as getConvexConfig, t as generateMeta } from "./codegen-CMQIKrqh.mjs";
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import { createHash } from "node:crypto";
|
|
5
5
|
import fs from "node:fs";
|
|
@@ -531,17 +531,22 @@ const listConvexHandlerExports = async (entryPoint, jitiInstance) => {
|
|
|
531
531
|
return Array.from(exportNames).sort((a, b) => a.localeCompare(b));
|
|
532
532
|
};
|
|
533
533
|
const scanHandlerExportsByEntry = async (entryPoints) => {
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
534
|
+
globalThis.__BETTER_CONVEX_CODEGEN__ = true;
|
|
535
|
+
try {
|
|
536
|
+
const jitiInstance = createJiti(process.cwd(), {
|
|
537
|
+
interopDefault: true,
|
|
538
|
+
moduleCache: false
|
|
539
|
+
});
|
|
540
|
+
const results = await Promise.all(entryPoints.map(async (entryPoint) => ({
|
|
541
|
+
entryPoint,
|
|
542
|
+
exportNames: await listConvexHandlerExports(entryPoint, jitiInstance)
|
|
543
|
+
})));
|
|
544
|
+
const byEntry = /* @__PURE__ */ new Map();
|
|
545
|
+
for (const result of results) if (result.exportNames.length > 0) byEntry.set(result.entryPoint, result.exportNames);
|
|
546
|
+
return byEntry;
|
|
547
|
+
} finally {
|
|
548
|
+
delete globalThis.__BETTER_CONVEX_CODEGEN__;
|
|
549
|
+
}
|
|
545
550
|
};
|
|
546
551
|
const parseArgs$1 = (argv) => {
|
|
547
552
|
const options = {
|
|
@@ -888,40 +888,45 @@ async function generateMeta(outputDir, options) {
|
|
|
888
888
|
if (hasTriggersExport && !hasRelationsExport) throw new Error("Codegen error: schema.ts exports 'triggers' but is missing 'relations'. Export `relations` and define triggers via `defineTriggers(relations, { ... })`.");
|
|
889
889
|
ensureGeneratedSupportPlaceholders(functionsDir, { includeAuth: generateAuth });
|
|
890
890
|
if (generateApi) {
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
const
|
|
904
|
-
|
|
905
|
-
const
|
|
906
|
-
|
|
907
|
-
meta
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
891
|
+
globalThis.__BETTER_CONVEX_CODEGEN__ = true;
|
|
892
|
+
try {
|
|
893
|
+
const jitiInstance = createJiti(process.cwd(), {
|
|
894
|
+
interopDefault: true,
|
|
895
|
+
moduleCache: false
|
|
896
|
+
});
|
|
897
|
+
const files = listFilesRecursive(functionsDir).filter((file) => file.endsWith(".ts") && isValidConvexFile(file));
|
|
898
|
+
createdRuntimePlaceholders = ensureGeneratedRuntimePlaceholders(functionsDir, [...new Set([
|
|
899
|
+
...files.map((file) => file.replace(TS_EXTENSION_RE, "")),
|
|
900
|
+
...hasRelationsExport ? ["generated/server"] : [],
|
|
901
|
+
...generateAuth ? [generatedAuthModuleName] : []
|
|
902
|
+
])]);
|
|
903
|
+
for (const file of files) {
|
|
904
|
+
const filePath = path.join(functionsDir, file);
|
|
905
|
+
const moduleName = file.replace(TS_EXTENSION_RE, "");
|
|
906
|
+
try {
|
|
907
|
+
const { meta: moduleMeta, httpRoutes, procedures } = await parseModuleRuntime(filePath, jitiInstance);
|
|
908
|
+
if (moduleMeta) {
|
|
909
|
+
meta[moduleName] = moduleMeta;
|
|
910
|
+
const fnCount = Object.keys(moduleMeta).length;
|
|
911
|
+
totalFunctions += fnCount;
|
|
912
|
+
if (debug) console.info(` ✓ ${moduleName}: ${fnCount} functions`);
|
|
913
|
+
}
|
|
914
|
+
if (Object.keys(httpRoutes).length > 0 && debug) console.info(` ✓ ${moduleName}: ${Object.keys(httpRoutes).length} HTTP routes`);
|
|
915
|
+
Object.assign(allHttpRoutes, httpRoutes);
|
|
916
|
+
for (const procedure of procedures) procedureEntries.push({
|
|
917
|
+
moduleName,
|
|
918
|
+
exportName: procedure.exportName,
|
|
919
|
+
internal: procedure.internal,
|
|
920
|
+
type: procedure.type,
|
|
921
|
+
kind: "crpc"
|
|
922
|
+
});
|
|
923
|
+
} catch (error) {
|
|
924
|
+
runtimeFilesPreservedFromParseFailures.add(getGeneratedRuntimeOutputFile(functionsDir, moduleName));
|
|
925
|
+
if (debug || file === "http.ts") console.error(` ⚠ Failed to parse ${file}:`, error);
|
|
911
926
|
}
|
|
912
|
-
if (Object.keys(httpRoutes).length > 0 && debug) console.info(` ✓ ${moduleName}: ${Object.keys(httpRoutes).length} HTTP routes`);
|
|
913
|
-
Object.assign(allHttpRoutes, httpRoutes);
|
|
914
|
-
for (const procedure of procedures) procedureEntries.push({
|
|
915
|
-
moduleName,
|
|
916
|
-
exportName: procedure.exportName,
|
|
917
|
-
internal: procedure.internal,
|
|
918
|
-
type: procedure.type,
|
|
919
|
-
kind: "crpc"
|
|
920
|
-
});
|
|
921
|
-
} catch (error) {
|
|
922
|
-
runtimeFilesPreservedFromParseFailures.add(getGeneratedRuntimeOutputFile(functionsDir, moduleName));
|
|
923
|
-
if (debug || file === "http.ts") console.error(` ⚠ Failed to parse ${file}:`, error);
|
|
924
927
|
}
|
|
928
|
+
} finally {
|
|
929
|
+
delete globalThis.__BETTER_CONVEX_CODEGEN__;
|
|
925
930
|
}
|
|
926
931
|
}
|
|
927
932
|
if (generateApi) {
|
package/dist/server/index.js
CHANGED
|
@@ -1985,14 +1985,17 @@ const initCRPC = {
|
|
|
1985
1985
|
//#endregion
|
|
1986
1986
|
//#region src/server/env.ts
|
|
1987
1987
|
function createEnv(options) {
|
|
1988
|
-
const { schema, runtimeEnv = process.env, cache = true, codegenFallback =
|
|
1988
|
+
const { schema, runtimeEnv = process.env, cache = true, codegenFallback = false } = options;
|
|
1989
1989
|
let cached;
|
|
1990
1990
|
return () => {
|
|
1991
1991
|
if (cache && cached) return cached;
|
|
1992
|
-
const envForParse =
|
|
1992
|
+
const envForParse = globalThis.__BETTER_CONVEX_CODEGEN__ === true || codegenFallback ? {
|
|
1993
1993
|
...Object.fromEntries(Object.entries(schema.shape).map(([key, zodType]) => {
|
|
1994
1994
|
const result = zodType.safeParse(void 0);
|
|
1995
|
-
if (!result.success)
|
|
1995
|
+
if (!result.success) {
|
|
1996
|
+
if (zodType instanceof z.ZodEnum && Array.isArray(zodType.options) && zodType.options.length > 0) return [key, zodType.options[0]];
|
|
1997
|
+
return [key, ""];
|
|
1998
|
+
}
|
|
1996
1999
|
return [key, typeof result.data === "string" ? result.data : void 0];
|
|
1997
2000
|
})),
|
|
1998
2001
|
...runtimeEnv
|
package/dist/watcher.mjs
CHANGED