better-convex 0.7.2 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/dist/aggregate/index.d.ts +1 -1
  2. package/dist/aggregate/index.js +1 -1
  3. package/dist/auth/http/index.d.ts +1 -1
  4. package/dist/auth/index.d.ts +10 -10
  5. package/dist/auth/index.js +5 -4
  6. package/dist/auth/nextjs/index.d.ts +2 -2
  7. package/dist/auth/nextjs/index.js +2 -2
  8. package/dist/{caller-factory-D3OuR1eI.js → caller-factory-CCsm4Dut.js} +2 -2
  9. package/dist/cli.mjs +414 -5
  10. package/dist/{codegen-Cz1idI3-.mjs → codegen-BS36cYTH.mjs} +88 -5
  11. package/dist/{create-schema-orm-69VF4CFV.js → create-schema-orm-OcyA0apQ.js} +10 -13
  12. package/dist/crpc/index.d.ts +2 -2
  13. package/dist/crpc/index.js +3 -3
  14. package/dist/customFunctions-RnzME_cJ.js +167 -0
  15. package/dist/{http-types-BCf2wCgp.d.ts → http-types-BK7FuIcR.d.ts} +1 -1
  16. package/dist/id-BcBb900m.js +121 -0
  17. package/dist/orm/index.d.ts +4 -3
  18. package/dist/orm/index.js +706 -165
  19. package/dist/plugins/index.d.ts +9 -0
  20. package/dist/plugins/index.js +3 -0
  21. package/dist/plugins/ratelimit/index.d.ts +222 -0
  22. package/dist/plugins/ratelimit/index.js +846 -0
  23. package/dist/plugins/ratelimit/react/index.d.ts +76 -0
  24. package/dist/plugins/ratelimit/react/index.js +294 -0
  25. package/dist/{procedure-caller-CcjtUFvL.d.ts → procedure-caller-DYjpq7rG.d.ts} +4 -19
  26. package/dist/rsc/index.d.ts +3 -3
  27. package/dist/rsc/index.js +4 -4
  28. package/dist/runtime-C0WcYGY0.js +1028 -0
  29. package/dist/schema-Bx6j2doh.js +204 -0
  30. package/dist/server/index.d.ts +2 -2
  31. package/dist/server/index.js +4 -3
  32. package/dist/{runtime-B9xQFY8W.js → table-B7yzBihE.js} +3 -1088
  33. package/dist/text-enum-CFdcLUuw.js +30 -0
  34. package/dist/{types-CIBGEYXq.d.ts → types-f53SgpBL.d.ts} +1 -1
  35. package/dist/validators-BcQFm1oY.d.ts +88 -0
  36. package/dist/{customFunctions-CZnCwoR3.js → validators-D_i3BK7v.js} +67 -165
  37. package/dist/watcher.mjs +1 -1
  38. package/dist/{where-clause-compiler-CRP-i1Qa.d.ts → where-clause-compiler-BIjTkVVJ.d.ts} +138 -2
  39. package/package.json +4 -1
  40. /package/dist/{create-schema-BdZOL6ns.js → create-schema-BsN0jL5S.js} +0 -0
  41. /package/dist/{error-Be4OcwwD.js → error-CAGGSN5H.js} +0 -0
  42. /package/dist/{meta-utils-DDVYp9Xf.js → meta-utils-NRyocOSc.js} +0 -0
  43. /package/dist/{query-context-BDSis9rT.js → query-context-DEUFBhXS.js} +0 -0
  44. /package/dist/{query-context-DGExXZIV.d.ts → query-context-ji7By8u0.d.ts} +0 -0
  45. /package/dist/{query-options-B0c1b6pZ.js → query-options-CSCmKYdJ.js} +0 -0
  46. /package/dist/{transformer-Dh0w2py0.js → transformer-ogg-4d78.js} +0 -0
  47. /package/dist/{types-DwGkkq2s.d.ts → types-BTb_4BaU.d.ts} +0 -0
  48. /package/dist/{types-DgwvxKbT.d.ts → types-CM67ko7K.d.ts} +0 -0
@@ -0,0 +1,9 @@
1
+ import { ni as OrmSchemaPlugin } from "../where-clause-compiler-BIjTkVVJ.js";
2
+
3
+ //#region src/orm/migrations/schema.d.ts
4
+ declare function migrationPlugin(): OrmSchemaPlugin;
5
+ //#endregion
6
+ //#region src/orm/aggregate-index/schema.d.ts
7
+ declare function aggregatePlugin(): OrmSchemaPlugin;
8
+ //#endregion
9
+ export { aggregatePlugin, migrationPlugin };
@@ -0,0 +1,3 @@
1
+ import { c as aggregatePlugin, r as migrationPlugin } from "../schema-Bx6j2doh.js";
2
+
3
+ export { aggregatePlugin, migrationPlugin };
@@ -0,0 +1,222 @@
1
+ import { ni as OrmSchemaPlugin } from "../../where-clause-compiler-BIjTkVVJ.js";
2
+ import * as convex_server0 from "convex/server";
3
+
4
+ //#region src/plugins/ratelimit/duration.d.ts
5
+ type DurationUnit = 'ms' | 's' | 'm' | 'h' | 'd';
6
+ type DurationString = `${number} ${DurationUnit}` | `${number}${DurationUnit}`;
7
+ type Duration = number | DurationString;
8
+ declare function toMs(duration: Duration): number;
9
+ //#endregion
10
+ //#region src/plugins/ratelimit/types.d.ts
11
+ type RatelimitReason = 'timeout' | 'cacheBlock' | 'denyList';
12
+ type RatelimitResponse = {
13
+ success: boolean;
14
+ ok: boolean;
15
+ limit: number;
16
+ remaining: number;
17
+ reset: number;
18
+ pending: Promise<unknown>;
19
+ reason?: RatelimitReason;
20
+ deniedValue?: string;
21
+ };
22
+ type RemainingResponse = {
23
+ remaining: number;
24
+ reset: number;
25
+ limit: number;
26
+ };
27
+ type DynamicLimitResponse = {
28
+ dynamicLimit: number | null;
29
+ };
30
+ type RateLimitState = {
31
+ value: number;
32
+ ts: number;
33
+ auxValue?: number;
34
+ auxTs?: number;
35
+ };
36
+ type RateLimitSnapshot = {
37
+ value: number;
38
+ ts: number;
39
+ shard: number;
40
+ config: ResolvedAlgorithm;
41
+ };
42
+ type BaseAlgorithmOptions = {
43
+ shards?: number;
44
+ maxReserved?: number;
45
+ };
46
+ type FixedWindowAlgorithm = {
47
+ kind: 'fixedWindow';
48
+ limit: number;
49
+ window: number;
50
+ capacity: number;
51
+ start?: number;
52
+ maxReserved?: number;
53
+ shards: number;
54
+ };
55
+ type SlidingWindowAlgorithm = {
56
+ kind: 'slidingWindow';
57
+ limit: number;
58
+ window: number;
59
+ maxReserved?: number;
60
+ shards: number;
61
+ };
62
+ type TokenBucketAlgorithm = {
63
+ kind: 'tokenBucket';
64
+ refillRate: number;
65
+ interval: number;
66
+ maxTokens: number;
67
+ maxReserved?: number;
68
+ shards: number;
69
+ };
70
+ type ResolvedAlgorithm = FixedWindowAlgorithm | SlidingWindowAlgorithm | TokenBucketAlgorithm;
71
+ type AlgorithmOptions = BaseAlgorithmOptions & {
72
+ capacity?: number;
73
+ start?: number;
74
+ };
75
+ type LimitRequest = {
76
+ rate?: number;
77
+ count?: number;
78
+ reserve?: boolean;
79
+ ip?: string;
80
+ userAgent?: string;
81
+ country?: string;
82
+ geo?: unknown;
83
+ };
84
+ type CheckRequest = Omit<LimitRequest, 'reserve'> & {
85
+ reserve?: boolean;
86
+ };
87
+ type FailureMode = 'closed' | 'open';
88
+ type ProtectionLists = {
89
+ identifiers?: readonly string[];
90
+ ips?: readonly string[];
91
+ userAgents?: readonly string[];
92
+ countries?: readonly string[];
93
+ };
94
+ type RatelimitConfig = {
95
+ db?: ConvexRateLimitDbReader | ConvexRateLimitDbWriter;
96
+ limiter: ResolvedAlgorithm;
97
+ prefix?: string;
98
+ dynamicLimits?: boolean;
99
+ ephemeralCache?: Map<string, number> | false;
100
+ timeout?: number;
101
+ failureMode?: FailureMode;
102
+ enableProtection?: boolean;
103
+ denyListThreshold?: number;
104
+ denyList?: ProtectionLists;
105
+ };
106
+ type RateLimitRow = {
107
+ _id: string;
108
+ _creationTime?: number;
109
+ name: string;
110
+ key?: string;
111
+ shard: number;
112
+ value: number;
113
+ ts: number;
114
+ auxValue?: number;
115
+ auxTs?: number;
116
+ };
117
+ type ConvexQueryBuilder = {
118
+ withIndex: (name: any, cb: any) => {
119
+ unique: () => Promise<any>;
120
+ collect: () => Promise<any[]>;
121
+ };
122
+ };
123
+ type ConvexRateLimitDbReader = {
124
+ query: (tableName: string) => ConvexQueryBuilder;
125
+ };
126
+ type ConvexRateLimitDbWriter = ConvexRateLimitDbReader & {
127
+ insert: (...args: any[]) => Promise<any>;
128
+ patch: (...args: any[]) => Promise<void>;
129
+ delete: (...args: any[]) => Promise<void>;
130
+ };
131
+ type HookAPIOptions = {
132
+ identifier?: string | ((ctx: unknown, fromClient?: string) => string | Promise<string>);
133
+ sampleShards?: number;
134
+ };
135
+ type HookCheckValue = {
136
+ value: number;
137
+ ts: number;
138
+ config: ResolvedAlgorithm;
139
+ shard: number;
140
+ ok: boolean;
141
+ retryAt?: number;
142
+ };
143
+ //#endregion
144
+ //#region src/plugins/ratelimit/core/algorithms.d.ts
145
+ declare function fixedWindow(limit: number, window: Duration, options?: AlgorithmOptions): FixedWindowAlgorithm;
146
+ declare function slidingWindow(limit: number, window: Duration, options?: AlgorithmOptions): SlidingWindowAlgorithm;
147
+ declare function tokenBucket(refillRate: number, interval: Duration, maxTokens: number, options?: AlgorithmOptions): TokenBucketAlgorithm;
148
+ declare function applyDynamicLimit(algorithm: ResolvedAlgorithm, dynamicLimit: number | null): ResolvedAlgorithm;
149
+ //#endregion
150
+ //#region src/plugins/ratelimit/core/calculate-rate-limit.d.ts
151
+ type EvaluationResult = {
152
+ state: RateLimitState;
153
+ retryAfter?: number;
154
+ remaining: number;
155
+ reset: number;
156
+ limit: number;
157
+ };
158
+ declare function calculateRateLimit(state: RateLimitState | null, algorithm: ResolvedAlgorithm, now: number, count: number): EvaluationResult;
159
+ //#endregion
160
+ //#region src/plugins/ratelimit/ratelimit.d.ts
161
+ declare class Ratelimit {
162
+ private readonly config;
163
+ static fixedWindow: typeof fixedWindow;
164
+ static slidingWindow: typeof slidingWindow;
165
+ static tokenBucket: typeof tokenBucket;
166
+ private readonly store;
167
+ private readonly prefix;
168
+ private readonly timeout;
169
+ private readonly dynamicLimits;
170
+ private readonly failureMode;
171
+ private readonly enableProtection;
172
+ private readonly denyListThreshold;
173
+ private readonly denyList?;
174
+ private readonly limiter;
175
+ private readonly blockCache?;
176
+ private readonly blockCacheSource?;
177
+ private readonly checkCache;
178
+ constructor(config: RatelimitConfig);
179
+ limit(identifier: string, request?: LimitRequest): Promise<RatelimitResponse>;
180
+ check(identifier: string, request?: CheckRequest): Promise<RatelimitResponse>;
181
+ blockUntilReady(identifier: string, timeoutMs: number): Promise<RatelimitResponse>;
182
+ resetUsedTokens(identifier: string): Promise<void>;
183
+ getRemaining(identifier: string): Promise<RemainingResponse>;
184
+ getValue(identifier: string, options?: {
185
+ sampleShards?: number;
186
+ }): Promise<RateLimitSnapshot>;
187
+ setDynamicLimit(options: {
188
+ limit: number | false;
189
+ }): Promise<void>;
190
+ getDynamicLimit(): Promise<DynamicLimitResponse>;
191
+ hookAPI(options?: HookAPIOptions): {
192
+ getRateLimit: convex_server0.RegisteredQuery<"public", {
193
+ identifier?: string | undefined;
194
+ sampleShards?: number | undefined;
195
+ }, Promise<RateLimitSnapshot>>;
196
+ getServerTime: convex_server0.RegisteredMutation<"public", {}, Promise<number>>;
197
+ };
198
+ private withDb;
199
+ private evaluate;
200
+ private evaluateCandidates;
201
+ private resolveAlgorithm;
202
+ private rawLimit;
203
+ private runWithTimeout;
204
+ private timeoutResponse;
205
+ }
206
+ //#endregion
207
+ //#region src/plugins/ratelimit/schema.d.ts
208
+ declare function ratelimitPlugin(): OrmSchemaPlugin;
209
+ //#endregion
210
+ //#region src/plugins/ratelimit/store/convex-store.d.ts
211
+ declare const RATE_LIMIT_STATE_TABLE = "ratelimit_state";
212
+ declare const RATE_LIMIT_DYNAMIC_TABLE = "ratelimit_dynamic_limit";
213
+ declare const RATE_LIMIT_HIT_TABLE = "ratelimit_protection_hit";
214
+ //#endregion
215
+ //#region src/plugins/ratelimit/index.d.ts
216
+ declare const SECOND = 1000;
217
+ declare const MINUTE: number;
218
+ declare const HOUR: number;
219
+ declare const DAY: number;
220
+ declare const WEEK: number;
221
+ //#endregion
222
+ export { type CheckRequest, type ConvexQueryBuilder, type ConvexRateLimitDbReader, type ConvexRateLimitDbWriter, DAY, type Duration, type DurationString, type DurationUnit, type DynamicLimitResponse, type FixedWindowAlgorithm, HOUR, type HookAPIOptions, type HookCheckValue, type LimitRequest, MINUTE, RATE_LIMIT_DYNAMIC_TABLE, RATE_LIMIT_HIT_TABLE, RATE_LIMIT_STATE_TABLE, type RateLimitRow, type RateLimitSnapshot, type RateLimitState, Ratelimit, type RatelimitConfig, type RatelimitReason, type RatelimitResponse, type RemainingResponse, type ResolvedAlgorithm, SECOND, type SlidingWindowAlgorithm, type TokenBucketAlgorithm, WEEK, applyDynamicLimit, calculateRateLimit, fixedWindow, ratelimitPlugin, slidingWindow, toMs, tokenBucket };