better-convex 0.7.3 → 0.8.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 (46) 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 -5
  6. package/dist/auth/nextjs/index.d.ts +2 -2
  7. package/dist/auth/nextjs/index.js +2 -2
  8. package/dist/{caller-factory-4uND4vnj.js → caller-factory-CCsm4Dut.js} +2 -2
  9. package/dist/cli.mjs +1 -0
  10. package/dist/{create-schema-orm-DtuyK2RB.js → create-schema-orm-OcyA0apQ.js} +10 -13
  11. package/dist/crpc/index.d.ts +2 -2
  12. package/dist/crpc/index.js +3 -3
  13. package/dist/{customFunctions-C_i_0joT.js → customFunctions-RnzME_cJ.js} +1 -1
  14. package/dist/{http-types-BsnDV7Je.d.ts → http-types-BK7FuIcR.d.ts} +1 -1
  15. package/dist/id-BcBb900m.js +121 -0
  16. package/dist/orm/index.d.ts +4 -4
  17. package/dist/orm/index.js +60 -222
  18. package/dist/plugins/index.d.ts +9 -0
  19. package/dist/plugins/index.js +3 -0
  20. package/dist/plugins/ratelimit/index.d.ts +222 -0
  21. package/dist/plugins/ratelimit/index.js +852 -0
  22. package/dist/plugins/ratelimit/react/index.d.ts +76 -0
  23. package/dist/plugins/ratelimit/react/index.js +294 -0
  24. package/dist/{procedure-caller-Cj_lgUev.d.ts → procedure-caller-DYjpq7rG.d.ts} +2 -2
  25. package/dist/rsc/index.d.ts +3 -3
  26. package/dist/rsc/index.js +4 -4
  27. package/dist/runtime-C0WcYGY0.js +1028 -0
  28. package/dist/schema-Bx6j2doh.js +204 -0
  29. package/dist/server/index.d.ts +2 -2
  30. package/dist/server/index.js +4 -4
  31. package/dist/{runtime-B9xQFY8W.js → table-B7yzBihE.js} +3 -1088
  32. package/dist/text-enum-CFdcLUuw.js +30 -0
  33. package/dist/{types-DZFvhoPJ.d.ts → types-f53SgpBL.d.ts} +1 -1
  34. package/dist/{where-clause-compiler-HUa2223D.d.ts → where-clause-compiler-BIjTkVVJ.d.ts} +34 -2
  35. package/package.json +4 -1
  36. /package/dist/{create-schema-DE9ZtH8n.js → create-schema-BsN0jL5S.js} +0 -0
  37. /package/dist/{error-C7AOPlv2.js → error-CAGGSN5H.js} +0 -0
  38. /package/dist/{meta-utils-C9_6WIzj.js → meta-utils-NRyocOSc.js} +0 -0
  39. /package/dist/{query-context-yQVARct0.js → query-context-DEUFBhXS.js} +0 -0
  40. /package/dist/{query-context-BMXt2TKe.d.ts → query-context-ji7By8u0.d.ts} +0 -0
  41. /package/dist/{query-options-Bjo6j5cC.js → query-options-CSCmKYdJ.js} +0 -0
  42. /package/dist/{transformer-BsX4RWes.js → transformer-ogg-4d78.js} +0 -0
  43. /package/dist/{types-kgwiK-xe.d.ts → types-BTb_4BaU.d.ts} +0 -0
  44. /package/dist/{types-DarApWtO.d.ts → types-CM67ko7K.d.ts} +0 -0
  45. /package/dist/{validators-BDrWGp4M.d.ts → validators-BcQFm1oY.d.ts} +0 -0
  46. /package/dist/{validators-B7oIJCAp.js → validators-D_i3BK7v.js} +0 -0
package/dist/orm/index.js CHANGED
@@ -1,6 +1,10 @@
1
- import { A as entityKind, C as text, D as custom, E as id, O as json, S as vectorIndex, T as integer, _ as aggregateIndex, a as deletion, b as searchIndex, c as EnableRLS, d as OrmSchemaOptions, f as RlsPolicies, g as rlsPolicy, h as RlsPolicy, i as convexTable, k as ConvexColumnBuilder, l as OrmContext, m as TableName, o as Brand, p as TableDeleteConfig, s as Columns, t as DirectAggregate, u as OrmSchemaDefinition, v as index, w as createSystemFields, x as uniqueIndex, y as rankIndex } from "../runtime-B9xQFY8W.js";
2
- import { a as pretendRequired, i as pretend, n as deprecated } from "../validators-B7oIJCAp.js";
3
- import { A as ne, C as inArray, D as like, E as isNull, F as notLike, I as or, L as startsWith, M as notBetween, N as notIlike, O as lt, P as notInArray, S as ilike, T as isNotNull, _ as endsWith, a as mergedStream, b as gt, c as isUnsetToken, d as arrayContained, f as arrayContains, g as contains, h as column, i as getIndexFields, j as not, k as lte, l as unsetToken, m as between, n as EmptyStream, o as stream, p as arrayOverlaps, r as QueryStream, s as streamIndexRange, t as getByIdWithOrmQueryFallback, u as and, v as eq, w as isFieldReference, x as gte, y as fieldRef } from "../query-context-yQVARct0.js";
1
+ import { t as DirectAggregate } from "../runtime-C0WcYGY0.js";
2
+ import { C as integer, S as createSystemFields, T as entityKind, _ as rankIndex, a as EnableRLS, b as vectorIndex, c as OrmSchemaOptions, d as TableDeleteConfig, f as TableName, g as index, h as aggregateIndex, i as Columns, l as OrmSchemaPluginTables, m as rlsPolicy, n as deletion, o as OrmContext, p as RlsPolicy, r as Brand, s as OrmSchemaDefinition, t as convexTable, u as RlsPolicies, v as searchIndex, w as ConvexColumnBuilder, x as text, y as uniqueIndex } from "../table-B7yzBihE.js";
3
+ import { a as AGGREGATE_EXTREMA_TABLE, c as aggregatePlugin, i as AGGREGATE_BUCKET_TABLE, l as boolean, n as MIGRATION_STATE_TABLE, o as AGGREGATE_MEMBER_TABLE, r as migrationPlugin, s as AGGREGATE_STATE_TABLE, t as MIGRATION_RUN_TABLE } from "../schema-Bx6j2doh.js";
4
+ import { a as pretendRequired, i as pretend, n as deprecated } from "../validators-D_i3BK7v.js";
5
+ import { a as objectOf, i as json, n as arrayOf, r as custom, t as id } from "../id-BcBb900m.js";
6
+ import { t as textEnum } from "../text-enum-CFdcLUuw.js";
7
+ import { A as ne, C as inArray, D as like, E as isNull, F as notLike, I as or, L as startsWith, M as notBetween, N as notIlike, O as lt, P as notInArray, S as ilike, T as isNotNull, _ as endsWith, a as mergedStream, b as gt, c as isUnsetToken, d as arrayContained, f as arrayContains, g as contains, h as column, i as getIndexFields, j as not, k as lte, l as unsetToken, m as between, n as EmptyStream, o as stream, p as arrayOverlaps, r as QueryStream, s as streamIndexRange, t as getByIdWithOrmQueryFallback, u as and, v as eq, w as isFieldReference, x as gte, y as fieldRef } from "../query-context-DEUFBhXS.js";
4
8
  import { v } from "convex/values";
5
9
  import { defineSchema as defineSchema$1, internalActionGeneric, internalMutationGeneric } from "convex/server";
6
10
 
@@ -34,37 +38,6 @@ function bigint(name) {
34
38
  return new ConvexBigIntBuilder(name ?? "");
35
39
  }
36
40
 
37
- //#endregion
38
- //#region src/orm/builders/boolean.ts
39
- /**
40
- * Boolean column builder class
41
- * Compiles to v.boolean() or v.optional(v.boolean())
42
- */
43
- var ConvexBooleanBuilder = class extends ConvexColumnBuilder {
44
- static [entityKind] = "ConvexBooleanBuilder";
45
- constructor(name) {
46
- super(name, "boolean", "ConvexBoolean");
47
- }
48
- /**
49
- * Expose Convex validator for schema integration
50
- */
51
- get convexValidator() {
52
- if (this.config.notNull) return v.boolean();
53
- return v.optional(v.union(v.null(), v.boolean()));
54
- }
55
- /**
56
- * Compile to Convex validator
57
- * .notNull() → v.boolean()
58
- * nullable → v.optional(v.boolean())
59
- */
60
- build() {
61
- return this.convexValidator;
62
- }
63
- };
64
- function boolean(name) {
65
- return new ConvexBooleanBuilder(name ?? "");
66
- }
67
-
68
41
  //#endregion
69
42
  //#region src/orm/builders/bytes.ts
70
43
  var ConvexBytesBuilder = class extends ConvexColumnBuilder {
@@ -116,32 +89,6 @@ function date(nameOrConfig, maybeConfig) {
116
89
  return new ConvexDateBuilder(name, mode);
117
90
  }
118
91
 
119
- //#endregion
120
- //#region src/orm/builders/text-enum.ts
121
- var ConvexTextEnumBuilder = class extends ConvexColumnBuilder {
122
- static [entityKind] = "ConvexTextEnumBuilder";
123
- constructor(name, values) {
124
- super(name, "string", "ConvexText");
125
- this.config.values = [...values];
126
- }
127
- _enumValidator() {
128
- const literals = this.config.values.map((value) => v.literal(value));
129
- if (literals.length === 1) return literals[0];
130
- return v.union(...literals);
131
- }
132
- get convexValidator() {
133
- const base = this._enumValidator();
134
- if (this.config.notNull) return base;
135
- return v.optional(v.union(v.null(), base));
136
- }
137
- build() {
138
- return this.convexValidator;
139
- }
140
- };
141
- function textEnum(values) {
142
- return new ConvexTextEnumBuilder("", values);
143
- }
144
-
145
92
  //#endregion
146
93
  //#region src/orm/builders/timestamp.ts
147
94
  var ConvexTimestampBuilder = class extends ConvexColumnBuilder {
@@ -290,113 +237,6 @@ function check(name, expression) {
290
237
  return new ConvexCheckBuilder(name, expression);
291
238
  }
292
239
 
293
- //#endregion
294
- //#region src/orm/aggregate-index/schema.ts
295
- const AGGREGATE_BUCKET_TABLE = "aggregate_bucket";
296
- const AGGREGATE_MEMBER_TABLE = "aggregate_member";
297
- const AGGREGATE_EXTREMA_TABLE = "aggregate_extrema";
298
- const AGGREGATE_RANK_TREE_TABLE = "aggregate_rank_tree";
299
- const AGGREGATE_RANK_NODE_TABLE = "aggregate_rank_node";
300
- const AGGREGATE_STATE_TABLE = "aggregate_state";
301
- const countBucketTable = convexTable(AGGREGATE_BUCKET_TABLE, {
302
- tableKey: text().notNull(),
303
- indexName: text().notNull(),
304
- keyHash: text().notNull(),
305
- keyParts: custom(v.array(v.any())).notNull(),
306
- count: integer().notNull(),
307
- sumValues: custom(v.record(v.string(), v.number())).notNull(),
308
- nonNullCountValues: custom(v.record(v.string(), v.number())).notNull(),
309
- updatedAt: integer().notNull()
310
- }, (t) => [index("by_table_index_hash").on(t.tableKey, t.indexName, t.keyHash), index("by_table_index").on(t.tableKey, t.indexName)]);
311
- const countMemberTable = convexTable(AGGREGATE_MEMBER_TABLE, {
312
- kind: text().notNull(),
313
- tableKey: text().notNull(),
314
- indexName: text().notNull(),
315
- docId: text().notNull(),
316
- keyHash: text().notNull(),
317
- keyParts: custom(v.array(v.any())).notNull(),
318
- sumValues: custom(v.record(v.string(), v.number())).notNull(),
319
- nonNullCountValues: custom(v.record(v.string(), v.number())).notNull(),
320
- extremaValues: custom(v.record(v.string(), v.any())).notNull(),
321
- rankNamespace: custom(v.any()),
322
- rankKey: custom(v.any()),
323
- rankSumValue: integer(),
324
- updatedAt: integer().notNull()
325
- }, (t) => [index("by_kind_table_index_doc").on(t.kind, t.tableKey, t.indexName, t.docId), index("by_kind_table_index").on(t.kind, t.tableKey, t.indexName)]);
326
- const countExtremaTable = convexTable(AGGREGATE_EXTREMA_TABLE, {
327
- tableKey: text().notNull(),
328
- indexName: text().notNull(),
329
- keyHash: text().notNull(),
330
- fieldName: text().notNull(),
331
- valueHash: text().notNull(),
332
- value: custom(v.any()).notNull(),
333
- sortKey: text().notNull(),
334
- count: integer().notNull(),
335
- updatedAt: integer().notNull()
336
- }, (t) => [
337
- index("by_table_index").on(t.tableKey, t.indexName),
338
- index("by_table_index_hash_field_value").on(t.tableKey, t.indexName, t.keyHash, t.fieldName, t.valueHash),
339
- index("by_table_index_hash_field_sort").on(t.tableKey, t.indexName, t.keyHash, t.fieldName, t.sortKey)
340
- ]);
341
- const countStateTable = convexTable(AGGREGATE_STATE_TABLE, {
342
- kind: text().notNull(),
343
- tableKey: text().notNull(),
344
- indexName: text().notNull(),
345
- keyDefinitionHash: text().notNull(),
346
- metricDefinitionHash: text().notNull(),
347
- status: text().notNull(),
348
- cursor: text(),
349
- processed: integer().notNull(),
350
- startedAt: integer().notNull(),
351
- updatedAt: integer().notNull(),
352
- completedAt: integer(),
353
- lastError: text()
354
- }, (t) => [index("by_kind_table_index").on(t.kind, t.tableKey, t.indexName), index("by_kind_status").on(t.kind, t.status)]);
355
- const aggregateCounterValidator = v.object({
356
- count: v.number(),
357
- sum: v.number()
358
- });
359
- const aggregateItemValidator = v.object({
360
- k: v.any(),
361
- v: v.any(),
362
- s: v.number()
363
- });
364
- const rankTreeTable = convexTable(AGGREGATE_RANK_TREE_TABLE, {
365
- aggregateName: text().notNull(),
366
- maxNodeSize: integer().notNull(),
367
- namespace: custom(v.any()),
368
- root: id(AGGREGATE_RANK_NODE_TABLE).notNull()
369
- }, (tree) => [index("by_namespace").on(tree.namespace), index("by_aggregate_name").on(tree.aggregateName)]);
370
- const rankNodeTable = convexTable(AGGREGATE_RANK_NODE_TABLE, {
371
- aggregate: custom(aggregateCounterValidator),
372
- items: custom(v.array(aggregateItemValidator)).notNull(),
373
- subtrees: custom(v.array(v.string())).notNull()
374
- });
375
- const aggregateStorageTables = {
376
- [AGGREGATE_BUCKET_TABLE]: countBucketTable,
377
- [AGGREGATE_MEMBER_TABLE]: countMemberTable,
378
- [AGGREGATE_EXTREMA_TABLE]: countExtremaTable,
379
- [AGGREGATE_RANK_TREE_TABLE]: rankTreeTable,
380
- [AGGREGATE_RANK_NODE_TABLE]: rankNodeTable,
381
- [AGGREGATE_STATE_TABLE]: countStateTable
382
- };
383
- const AGGREGATE_STORAGE_TABLE_NAMES = new Set([
384
- AGGREGATE_BUCKET_TABLE,
385
- AGGREGATE_MEMBER_TABLE,
386
- AGGREGATE_EXTREMA_TABLE,
387
- AGGREGATE_RANK_TREE_TABLE,
388
- AGGREGATE_RANK_NODE_TABLE,
389
- AGGREGATE_STATE_TABLE
390
- ]);
391
- function injectAggregateStorageTables(schema) {
392
- const merged = { ...schema };
393
- for (const [tableName, tableDef] of Object.entries(aggregateStorageTables)) {
394
- if (tableName in schema && schema[tableName] !== tableDef) throw new Error(`defineSchema cannot inject internal table '${tableName}' because the name is already in use.`);
395
- merged[tableName] = tableDef;
396
- }
397
- return merged;
398
- }
399
-
400
240
  //#endregion
401
241
  //#region src/orm/aggregate-index/runtime.ts
402
242
  const UNDEFINED_SENTINEL = "__betterConvexUndefined";
@@ -9062,53 +8902,6 @@ function simpleStableHash(value) {
9062
8902
  return `m_${(hashA >>> 0).toString(16).padStart(8, "0")}${(hashB >>> 0).toString(16).padStart(8, "0")}`;
9063
8903
  }
9064
8904
 
9065
- //#endregion
9066
- //#region src/orm/migrations/schema.ts
9067
- const MIGRATION_STATE_TABLE = "migration_state";
9068
- const MIGRATION_RUN_TABLE = "migration_run";
9069
- const migrationStateTable = convexTable(MIGRATION_STATE_TABLE, {
9070
- migrationId: text().notNull(),
9071
- checksum: text().notNull(),
9072
- applied: boolean().notNull(),
9073
- status: text().notNull(),
9074
- direction: text(),
9075
- runId: text(),
9076
- cursor: text(),
9077
- processed: integer().notNull(),
9078
- startedAt: integer(),
9079
- updatedAt: integer().notNull(),
9080
- completedAt: integer(),
9081
- lastError: text(),
9082
- writeMode: text().notNull()
9083
- }, (t) => [index("by_migration_id").on(t.migrationId), index("by_status").on(t.status)]);
9084
- const migrationRunTable = convexTable(MIGRATION_RUN_TABLE, {
9085
- runId: text().notNull(),
9086
- direction: text().notNull(),
9087
- status: text().notNull(),
9088
- dryRun: boolean().notNull(),
9089
- allowDrift: boolean().notNull(),
9090
- migrationIds: custom(v.array(v.string())).notNull(),
9091
- currentIndex: integer().notNull(),
9092
- startedAt: integer().notNull(),
9093
- updatedAt: integer().notNull(),
9094
- completedAt: integer(),
9095
- cancelRequested: boolean().notNull(),
9096
- lastError: text()
9097
- }, (t) => [index("by_run_id").on(t.runId), index("by_status").on(t.status)]);
9098
- const migrationStorageTables = {
9099
- [MIGRATION_STATE_TABLE]: migrationStateTable,
9100
- [MIGRATION_RUN_TABLE]: migrationRunTable
9101
- };
9102
- const MIGRATION_STORAGE_TABLE_NAMES = new Set([MIGRATION_STATE_TABLE, MIGRATION_RUN_TABLE]);
9103
- function injectMigrationStorageTables(schema) {
9104
- const merged = { ...schema };
9105
- for (const [tableName, tableDef] of Object.entries(migrationStorageTables)) {
9106
- if (tableName in schema && schema[tableName] !== tableDef) throw new Error(`defineSchema cannot inject internal table '${tableName}' because the name is already in use.`);
9107
- merged[tableName] = tableDef;
9108
- }
9109
- return merged;
9110
- }
9111
-
9112
8905
  //#endregion
9113
8906
  //#region src/orm/migrations/runtime.ts
9114
8907
  const DEFAULT_BATCH_SIZE = 128;
@@ -9767,9 +9560,9 @@ function scheduledMutationBatchFactory(schema, edgeMetadata, scheduledMutationBa
9767
9560
 
9768
9561
  //#endregion
9769
9562
  //#region src/orm/create-orm.ts
9770
- const RESET_INTERNAL_TABLE_NAMES = [...AGGREGATE_STORAGE_TABLE_NAMES, ...MIGRATION_STORAGE_TABLE_NAMES];
9771
9563
  function getResetTableNames(schema) {
9772
- return [...new Set([...Object.values(schema).map((tableConfig) => tableConfig.name), ...RESET_INTERNAL_TABLE_NAMES])];
9564
+ const pluginTables = schema[OrmSchemaPluginTables];
9565
+ return [...new Set([...Object.values(schema).map((tableConfig) => tableConfig.name), ...pluginTables ?? []])];
9773
9566
  }
9774
9567
  function isOrmCtx(source) {
9775
9568
  return !!source && typeof source === "object" && "db" in source;
@@ -10143,6 +9936,7 @@ function defineRelations(schema, relations) {
10143
9936
  const strict = schemaOptions?.strict ?? true;
10144
9937
  const defaults = schemaOptions?.defaults;
10145
9938
  const schemaDefinition = schema[OrmSchemaDefinition];
9939
+ const pluginTableNames = schema[OrmSchemaPluginTables];
10146
9940
  const tablesConfig = buildRelations(tables, relations ? relations(createRelationsHelper(tables)) : {}, strict, defaults);
10147
9941
  Object.defineProperty(tablesConfig, OrmSchemaOptions, {
10148
9942
  value: {
@@ -10155,6 +9949,10 @@ function defineRelations(schema, relations) {
10155
9949
  value: schemaDefinition,
10156
9950
  enumerable: false
10157
9951
  });
9952
+ if (pluginTableNames) Object.defineProperty(tablesConfig, OrmSchemaPluginTables, {
9953
+ value: pluginTableNames,
9954
+ enumerable: false
9955
+ });
10158
9956
  return tablesConfig;
10159
9957
  }
10160
9958
  function defineRelationsPart(schema, relations) {
@@ -10163,6 +9961,7 @@ function defineRelationsPart(schema, relations) {
10163
9961
  const strict = schemaOptions?.strict ?? true;
10164
9962
  const defaults = schemaOptions?.defaults;
10165
9963
  const schemaDefinition = schema[OrmSchemaDefinition];
9964
+ const pluginTableNames = schema[OrmSchemaPluginTables];
10166
9965
  const tablesConfig = buildRelationsParts(tables, relations ? relations(createRelationsHelper(tables)) : Object.fromEntries(Object.keys(tables).map((k) => [k, {}])), strict, defaults);
10167
9966
  Object.defineProperty(tablesConfig, OrmSchemaOptions, {
10168
9967
  value: {
@@ -10175,6 +9974,10 @@ function defineRelationsPart(schema, relations) {
10175
9974
  value: schemaDefinition,
10176
9975
  enumerable: false
10177
9976
  });
9977
+ if (pluginTableNames) Object.defineProperty(tablesConfig, OrmSchemaPluginTables, {
9978
+ value: pluginTableNames,
9979
+ enumerable: false
9980
+ });
10178
9981
  return tablesConfig;
10179
9982
  }
10180
9983
  function processRelations(tablesConfig, tables) {
@@ -10262,6 +10065,7 @@ const DEFAULTS_NUMERIC_FIELDS = [
10262
10065
  "mutationScheduleCallCap"
10263
10066
  ];
10264
10067
  const MUTATION_EXECUTION_MODES = ["sync", "async"];
10068
+ const BUILTIN_SCHEMA_PLUGINS = [aggregatePlugin(), migrationPlugin()];
10265
10069
  const normalizeDefaults = (defaults) => {
10266
10070
  if (!defaults) return;
10267
10071
  const normalized = {};
@@ -10282,6 +10086,27 @@ const normalizeDefaults = (defaults) => {
10282
10086
  }
10283
10087
  return normalized;
10284
10088
  };
10089
+ function resolveSchemaPlugins(plugins) {
10090
+ const resolved = [...BUILTIN_SCHEMA_PLUGINS, ...plugins ?? []];
10091
+ const seen = /* @__PURE__ */ new Set();
10092
+ for (const plugin of resolved) {
10093
+ if (seen.has(plugin.key)) throw new Error(`defineSchema received duplicate plugin '${plugin.key}'. Remove duplicate plugin registrations.`);
10094
+ seen.add(plugin.key);
10095
+ }
10096
+ return resolved;
10097
+ }
10098
+ function applySchemaPlugins(schema, plugins) {
10099
+ let current = schema;
10100
+ const pluginTableNames = [];
10101
+ for (const plugin of plugins) {
10102
+ current = plugin.inject(current);
10103
+ for (const tableName of plugin.tableNames) if (!pluginTableNames.includes(tableName)) pluginTableNames.push(tableName);
10104
+ }
10105
+ return {
10106
+ schema: current,
10107
+ pluginTableNames
10108
+ };
10109
+ }
10285
10110
  /**
10286
10111
  * Better Convex schema definition
10287
10112
  *
@@ -10292,7 +10117,8 @@ const normalizeDefaults = (defaults) => {
10292
10117
  function defineSchema(schema, options) {
10293
10118
  const strict = options?.strict ?? true;
10294
10119
  const defaults = normalizeDefaults(options?.defaults);
10295
- const schemaWithInternals = injectMigrationStorageTables(injectAggregateStorageTables(schema));
10120
+ const { schema: schemaWithPlugins, pluginTableNames } = applySchemaPlugins(schema, resolveSchemaPlugins(options?.plugins));
10121
+ const frozenPluginTableNames = Object.freeze([...pluginTableNames]);
10296
10122
  Object.defineProperty(schema, OrmSchemaOptions, {
10297
10123
  value: {
10298
10124
  strict,
@@ -10300,15 +10126,23 @@ function defineSchema(schema, options) {
10300
10126
  },
10301
10127
  enumerable: false
10302
10128
  });
10303
- Object.defineProperty(schemaWithInternals, OrmSchemaOptions, {
10129
+ Object.defineProperty(schemaWithPlugins, OrmSchemaOptions, {
10304
10130
  value: {
10305
10131
  strict,
10306
10132
  defaults
10307
10133
  },
10308
10134
  enumerable: false
10309
10135
  });
10310
- const { strict: _strict, defaults: _defaults, ...convexOptions } = options ?? {};
10311
- const convexSchema = defineSchema$1(schemaWithInternals, convexOptions);
10136
+ Object.defineProperty(schema, OrmSchemaPluginTables, {
10137
+ value: frozenPluginTableNames,
10138
+ enumerable: false
10139
+ });
10140
+ Object.defineProperty(schemaWithPlugins, OrmSchemaPluginTables, {
10141
+ value: frozenPluginTableNames,
10142
+ enumerable: false
10143
+ });
10144
+ const { strict: _strict, defaults: _defaults, plugins: _plugins, ...convexOptions } = options ?? {};
10145
+ const convexSchema = defineSchema$1(schemaWithPlugins, convexOptions);
10312
10146
  Object.defineProperty(convexSchema, OrmSchemaOptions, {
10313
10147
  value: {
10314
10148
  strict,
@@ -10316,11 +10150,15 @@ function defineSchema(schema, options) {
10316
10150
  },
10317
10151
  enumerable: false
10318
10152
  });
10153
+ Object.defineProperty(convexSchema, OrmSchemaPluginTables, {
10154
+ value: frozenPluginTableNames,
10155
+ enumerable: false
10156
+ });
10319
10157
  Object.defineProperty(schema, OrmSchemaDefinition, {
10320
10158
  value: convexSchema,
10321
10159
  enumerable: false
10322
10160
  });
10323
- Object.defineProperty(schemaWithInternals, OrmSchemaDefinition, {
10161
+ Object.defineProperty(schemaWithPlugins, OrmSchemaDefinition, {
10324
10162
  value: convexSchema,
10325
10163
  enumerable: false
10326
10164
  });
@@ -10332,4 +10170,4 @@ function defineSchema(schema, options) {
10332
10170
  }
10333
10171
 
10334
10172
  //#endregion
10335
- export { Brand, Columns, OrmNotFoundError, RlsPolicy, RlsRole, TableName, aggregateIndex, and, asc, between, bigint, boolean, buildMigrationPlan, bytes, check, contains, convexTable, createOrm, custom, date, defineMigration, defineMigrationSet, defineRelations, defineRelationsPart, defineSchema, defineTriggers, deletion, deprecated, desc, detectMigrationDrift, endsWith, eq, extractRelationsConfig, fieldRef, foreignKey, getByIdWithOrmQueryFallback, getTableColumns, getTableConfig, gt, gte, id, ilike, inArray, index, integer, isFieldReference, isNotNull, isNull, json, like, lt, lte, ne, not, notBetween, notInArray, or, pretend, pretendRequired, rankIndex, rlsPolicy, rlsRole, scheduledDeleteFactory, scheduledMutationBatchFactory, searchIndex, startsWith, text, textEnum, timestamp, unique, uniqueIndex, unsetToken, vector, vectorIndex };
10173
+ export { Brand, Columns, OrmNotFoundError, OrmSchemaPluginTables, RlsPolicy, RlsRole, TableName, aggregateIndex, and, arrayOf, asc, between, bigint, boolean, buildMigrationPlan, bytes, check, contains, convexTable, createOrm, custom, date, defineMigration, defineMigrationSet, defineRelations, defineRelationsPart, defineSchema, defineTriggers, deletion, deprecated, desc, detectMigrationDrift, endsWith, eq, extractRelationsConfig, fieldRef, foreignKey, getByIdWithOrmQueryFallback, getTableColumns, getTableConfig, gt, gte, id, ilike, inArray, index, integer, isFieldReference, isNotNull, isNull, json, like, lt, lte, ne, not, notBetween, notInArray, objectOf, or, pretend, pretendRequired, rankIndex, rlsPolicy, rlsRole, scheduledDeleteFactory, scheduledMutationBatchFactory, searchIndex, startsWith, text, textEnum, timestamp, unique, uniqueIndex, unsetToken, vector, vectorIndex };
@@ -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 };