@lpdjs/firestore-repo-service 2.6.57 → 3.0.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 (64) hide show
  1. package/README.md +45 -27
  2. package/dist/{create-servers-BxkVVkg9.d.cts → create-servers-Cbvzs_ou.d.cts} +5 -5
  3. package/dist/{create-servers-B84cbslf.d.ts → create-servers-aWdDTcSu.d.ts} +5 -5
  4. package/dist/{firebase-auth-DZ8lb2Ec.d.cts → firebase-auth-Ds5P0kXT.d.cts} +1 -1
  5. package/dist/{firebase-auth-DZ8lb2Ec.d.ts → firebase-auth-Ds5P0kXT.d.ts} +1 -1
  6. package/dist/index.cjs +97 -85
  7. package/dist/index.cjs.map +1 -1
  8. package/dist/index.d.cts +9 -9
  9. package/dist/index.d.ts +9 -9
  10. package/dist/index.js +97 -85
  11. package/dist/index.js.map +1 -1
  12. package/dist/llms-full.txt +237 -263
  13. package/dist/llms.txt +5 -4
  14. package/dist/{openapi-BpbfjSHK.d.ts → openapi-BTu_1vSc.d.ts} +1 -1
  15. package/dist/{openapi-DG7aQUlX.d.cts → openapi-CoKsSOIU.d.cts} +1 -1
  16. package/dist/{queue-B4uwef6c.d.ts → queue-BQxyuEXb.d.ts} +8 -23
  17. package/dist/{queue-CQyWCQBk.d.cts → queue-CMiKvIW1.d.cts} +8 -23
  18. package/dist/rules-B3b-BZLf.d.cts +30 -0
  19. package/dist/rules-BJMT0N0i.d.ts +30 -0
  20. package/dist/servers/admin/index.d.cts +402 -6
  21. package/dist/servers/admin/index.d.ts +402 -6
  22. package/dist/servers/auth/index.d.cts +1 -1
  23. package/dist/servers/auth/index.d.ts +1 -1
  24. package/dist/servers/crud/index.cjs +2 -2
  25. package/dist/servers/crud/index.cjs.map +1 -1
  26. package/dist/servers/crud/index.d.cts +7 -6
  27. package/dist/servers/crud/index.d.ts +7 -6
  28. package/dist/servers/crud/index.js +2 -2
  29. package/dist/servers/crud/index.js.map +1 -1
  30. package/dist/servers/hono/index.d.cts +3 -3
  31. package/dist/servers/hono/index.d.ts +3 -3
  32. package/dist/servers/index.cjs +106 -94
  33. package/dist/servers/index.cjs.map +1 -1
  34. package/dist/servers/index.d.cts +10 -9
  35. package/dist/servers/index.d.ts +10 -9
  36. package/dist/servers/index.js +106 -94
  37. package/dist/servers/index.js.map +1 -1
  38. package/dist/sync/bigquery.cjs +5 -5
  39. package/dist/sync/bigquery.cjs.map +1 -1
  40. package/dist/sync/bigquery.d.cts +28 -3
  41. package/dist/sync/bigquery.d.ts +28 -3
  42. package/dist/sync/bigquery.js +5 -5
  43. package/dist/sync/bigquery.js.map +1 -1
  44. package/dist/sync/index.cjs +74 -54
  45. package/dist/sync/index.cjs.map +1 -1
  46. package/dist/sync/index.d.cts +63 -17
  47. package/dist/sync/index.d.ts +63 -17
  48. package/dist/sync/index.js +74 -54
  49. package/dist/sync/index.js.map +1 -1
  50. package/dist/sync/meilisearch.cjs +4 -0
  51. package/dist/sync/meilisearch.cjs.map +1 -0
  52. package/dist/sync/meilisearch.d.cts +114 -0
  53. package/dist/sync/meilisearch.d.ts +114 -0
  54. package/dist/sync/meilisearch.js +4 -0
  55. package/dist/sync/meilisearch.js.map +1 -0
  56. package/dist/{types-CE-EfugW.d.cts → types-B2e-T8EM.d.cts} +160 -8
  57. package/dist/{types-B4dMmfet.d.cts → types-BIZz3sxN.d.cts} +1 -1
  58. package/dist/{types-DT7Nypd_.d.ts → types-BbFZ57eK.d.ts} +101 -41
  59. package/dist/{types-DyKJJ9UQ.d.ts → types-DSMiiOrU.d.ts} +1 -1
  60. package/dist/{types-cY03CMya.d.ts → types-XRjVKN9r.d.ts} +160 -8
  61. package/dist/{types-BwH1C-wi.d.cts → types-zFrp8RnM.d.cts} +101 -41
  62. package/package.json +19 -1
  63. package/dist/index-D47y5giY.d.ts +0 -469
  64. package/dist/index-dW_7jrlK.d.cts +0 -469
@@ -1,7 +1,8 @@
1
- import { A as AuthExtension } from './firebase-auth-DZ8lb2Ec.js';
2
- import { onDocumentCreated, onDocumentUpdated, onDocumentDeleted } from 'firebase-functions/v2/firestore';
1
+ import { b as AuthExtension } from './firebase-auth-Ds5P0kXT.js';
2
+ import { onDocumentWritten } from 'firebase-functions/v2/firestore';
3
3
  import { onRequest, HttpsOptions } from 'firebase-functions/v2/https';
4
4
  import { onMessagePublished, PubSubOptions } from 'firebase-functions/v2/pubsub';
5
+ import { z } from 'zod';
5
6
 
6
7
  /**
7
8
  * Cloud Functions v2 options forwarded to `onMessagePublished()` for every
@@ -16,6 +17,65 @@ type SyncWorkerOptions = Omit<PubSubOptions, "topic">;
16
17
  type AdminHttpsOptions = HttpsOptions;
17
18
  /** A value that can be provided directly or as a lazy factory function. */
18
19
  type OrFactory<T> = T | (() => T);
20
+ /** Result returned by an adapter's healthCheck method. */
21
+ interface SyncHealthResult {
22
+ /** Overall health status for this target */
23
+ healthy: boolean;
24
+ /** Target table or index name */
25
+ targetName: string;
26
+ /** Whether the target table/index exists */
27
+ targetExists: boolean;
28
+ /** Error message if unhealthy */
29
+ error?: string | null;
30
+ /** Adapter-specific health details (e.g. column mismatch for SQL, doc counts for Search) */
31
+ details?: Record<string, unknown>;
32
+ }
33
+ /**
34
+ * Universal adapter interface that the sync worker and admin dashboard call.
35
+ * Implementations exist for BigQuery, Meilisearch, and can be written for
36
+ * PostgreSQL, Elasticsearch, Typesense, etc.
37
+ */
38
+ interface SyncAdapter {
39
+ /** Unique adapter identifier, e.g. "bigquery", "meilisearch", "postgres" */
40
+ readonly name: string;
41
+ /** Check whether the target storage (table, index, etc.) exists */
42
+ targetExists(targetName: string): Promise<boolean>;
43
+ /**
44
+ * Upsert rows/documents into target storage.
45
+ * @param targetName - SQL table name or Search index UID
46
+ * @param items - Serialized rows / documents
47
+ * @param primaryKey - Column or field name used as primary key
48
+ */
49
+ upsert(targetName: string, items: Record<string, unknown>[], primaryKey: string): Promise<void>;
50
+ /**
51
+ * Delete rows/documents by primary key IDs.
52
+ * @param targetName - SQL table name or Search index UID
53
+ * @param primaryKey - Column or field name used as primary key
54
+ * @param ids - Array of document / row IDs to delete
55
+ */
56
+ delete(targetName: string, primaryKey: string, ids: string[]): Promise<void>;
57
+ /**
58
+ * Optional: prepare/migrate target schema or create target if missing.
59
+ * For SQL: creates table and adds missing columns.
60
+ * For Meilisearch: creates index and configures filterable/sortable attributes.
61
+ */
62
+ ensureTarget?(options: {
63
+ targetName: string;
64
+ primaryKey: string;
65
+ schema?: z.ZodObject<any>;
66
+ exclude?: string[];
67
+ columnMap?: Record<string, string>;
68
+ }): Promise<void>;
69
+ /**
70
+ * Optional: custom health check for the admin dashboard.
71
+ */
72
+ healthCheck?(options: {
73
+ targetName: string;
74
+ primaryKey: string;
75
+ schema?: z.ZodObject<any>;
76
+ repoConfig?: RepoSyncConfig<string>;
77
+ }): Promise<SyncHealthResult>;
78
+ }
19
79
  /** A single column in a SQL table. */
20
80
  interface SqlColumn {
21
81
  /** Column name (snake_case recommended for SQL) */
@@ -53,7 +113,7 @@ interface SqlDialect {
53
113
  * and dialect-specific SQL types.
54
114
  */
55
115
  type LogicalType = "string" | "number" | "bigint" | "boolean" | "timestamp" | "json" | "text";
56
- /** Operations that can be synced to SQL. */
116
+ /** Operations that can be synced to target storage. */
57
117
  type SyncOperation = "INSERT" | "UPSERT" | "DELETE";
58
118
  /** A single sync event produced by a Firestore trigger and consumed by the worker. */
59
119
  interface SyncEvent {
@@ -88,14 +148,12 @@ interface SyncEvent {
88
148
  }
89
149
  /**
90
150
  * Abstract SQL adapter that the sync worker calls.
91
- * Each target database provides a concrete implementation.
151
+ * Extends the universal {@link SyncAdapter}.
92
152
  */
93
- interface SqlAdapter {
153
+ interface SqlAdapter extends SyncAdapter {
94
154
  /** The SQL dialect used by this adapter */
95
155
  readonly dialect: SqlDialect;
96
- /**
97
- * Check whether a table exists.
98
- */
156
+ /** Check whether a table exists. */
99
157
  tableExists(tableName: string): Promise<boolean>;
100
158
  /**
101
159
  * Return the column names currently present in the table.
@@ -108,26 +166,20 @@ interface SqlAdapter {
108
166
  * `number` to `string`) and fail fast with an explicit error rather than
109
167
  * letting MERGE/Storage Write fail silently on every event.
110
168
  *
111
- * Optional for backwards-compat: if the adapter does not implement it,
169
+ * Optional: if the adapter does not implement it,
112
170
  * the worker skips type-drift detection but still adds new columns.
113
171
  */
114
172
  getTableColumnsWithTypes?(tableName: string): Promise<Map<string, string>>;
115
- /**
116
- * Create a table. Should be idempotent (IF NOT EXISTS).
117
- */
173
+ /** Create a table. Should be idempotent (IF NOT EXISTS). */
118
174
  createTable(table: SqlTableDef): Promise<void>;
119
- /**
120
- * Insert rows (append-only, no dedup).
121
- */
175
+ /** Insert rows (append-only, no dedup). */
122
176
  insertRows(tableName: string, rows: Record<string, unknown>[]): Promise<void>;
123
177
  /**
124
178
  * Upsert rows (INSERT … ON CONFLICT UPDATE / MERGE).
125
179
  * `primaryKey` identifies the column(s) used for matching.
126
180
  */
127
181
  upsertRows(tableName: string, rows: Record<string, unknown>[], primaryKey: string): Promise<void>;
128
- /**
129
- * Delete rows by primary-key values.
130
- */
182
+ /** Delete rows by primary-key values. */
131
183
  deleteRows(tableName: string, primaryKey: string, ids: string[]): Promise<void>;
132
184
  /**
133
185
  * Add columns to an existing table.
@@ -150,11 +202,11 @@ interface SqlAdapter {
150
202
  }
151
203
  /** Per-repository sync options, typed to the repo's field names. */
152
204
  interface RepoSyncConfig<F extends string = string> {
153
- /** Override the SQL table name (default: repo name) */
205
+ /** Override the SQL table name or Search index UID (default: repo name) */
154
206
  tableName?: string;
155
- /** Fields to exclude from the SQL table */
207
+ /** Fields to exclude from the synced document */
156
208
  exclude?: F[];
157
- /** Field name overrides: Zod field → SQL column name */
209
+ /** Field name overrides: Zod field → Target column/field name */
158
210
  columnMap?: Partial<Record<F, string>>;
159
211
  /**
160
212
  * Explicit Firestore document path pattern for triggers.
@@ -163,6 +215,11 @@ interface RepoSyncConfig<F extends string = string> {
163
215
  * @example "posts/{postId}/comments/{docId}"
164
216
  */
165
217
  triggerPath?: string;
218
+ /**
219
+ * Optional list of target adapter names for this repo (e.g. `["bigquery", "meilisearch"]`).
220
+ * When omitted or empty, the repo is synced to all configured adapters.
221
+ */
222
+ adapters?: string[];
166
223
  }
167
224
  /**
168
225
  * Extract field names from a repo value.
@@ -200,9 +257,7 @@ type TypedRepoSyncConfigs<M> = {
200
257
  };
201
258
  /** Firestore trigger constructors from `firebase-functions/v2/firestore`. */
202
259
  interface FirestoreTriggersDep {
203
- onDocumentCreated: typeof onDocumentCreated;
204
- onDocumentUpdated: typeof onDocumentUpdated;
205
- onDocumentDeleted: typeof onDocumentDeleted;
260
+ onDocumentWritten: typeof onDocumentWritten;
206
261
  }
207
262
  /** PubSub handler from `firebase-functions/v2/pubsub`. */
208
263
  interface PubSubHandlerDep {
@@ -238,13 +293,20 @@ interface SyncTriggersConfig<M = Record<string, any>> {
238
293
  interface SyncWorkerConfig<M = Record<string, any>> {
239
294
  /** External dependencies — PubSub handler + client */
240
295
  deps: Pick<SyncDeps, "pubsubHandler" | "pubsub">;
241
- /** SQL adapter to flush data to */
242
- adapter: SqlAdapter;
296
+ /**
297
+ * Adapter(s) to flush data to. Accepts a single adapter, an array of adapters,
298
+ * or a lazy factory returning one or more adapters.
299
+ */
300
+ adapter?: OrFactory<SyncAdapter | SyncAdapter[]>;
301
+ /**
302
+ * Explicit array of adapters to flush data to.
303
+ */
304
+ adapters?: OrFactory<SyncAdapter>[];
243
305
  /** Max rows per flush batch (default: 100) */
244
306
  batchSize?: number;
245
307
  /** Flush interval in ms (default: 5000) */
246
308
  flushIntervalMs?: number;
247
- /** Auto-create/migrate tables on first event (default: false) */
309
+ /** Auto-create/migrate tables or indexes on first event (default: false) */
248
310
  autoMigrate?: boolean;
249
311
  /** PubSub topic prefix (default: "firestore-sync") */
250
312
  topicPrefix?: string;
@@ -258,11 +320,6 @@ interface SyncWorkerConfig<M = Record<string, any>> {
258
320
  * Cloud Functions v2 options forwarded to `onMessagePublished()` for every
259
321
  * worker handler. Use to tune `concurrency`, `maxInstances`, `minInstances`,
260
322
  * `memory`, `timeoutSeconds`, `region`, `cpu`, etc.
261
- *
262
- * Example:
263
- * ```ts
264
- * workerOptions: { concurrency: 10, maxInstances: 10, memory: "512MiB" }
265
- * ```
266
323
  */
267
324
  workerOptions?: SyncWorkerOptions;
268
325
  /** Per-repo overrides */
@@ -289,9 +346,9 @@ interface adminsyncBasicAuth {
289
346
  interface adminsyncFeaturesFlag {
290
347
  /** Allow force-syncing an entire collection (default: false) */
291
348
  manualSync?: boolean;
292
- /** Schema health check: expected vs actual SQL columns (default: false) */
349
+ /** Schema health check: expected vs actual storage structure (default: false) */
293
350
  healthCheck?: boolean;
294
- /** GCP config check: verify APIs, topics, tables, and IAM (default: false) */
351
+ /** GCP / target config check: verify APIs, topics, targets, and IAM (default: false) */
295
352
  configCheck?: boolean;
296
353
  }
297
354
  /**
@@ -339,18 +396,21 @@ interface FirestoreSyncConfig<M = Record<string, any>> {
339
396
  pubsub: OrFactory<PubSubClientDep>;
340
397
  };
341
398
  /**
342
- * SQL adapter to flush data to.
343
- * Can be a factory `() => adapter` for lazy initialization
344
- * (avoids connecting to BigQuery / SQL at module-load time).
399
+ * Sync adapter(s) to flush data to (e.g. BigQueryAdapter, MeilisearchAdapter).
400
+ * Can be a single adapter, an array of adapters, or a lazy factory.
401
+ */
402
+ adapter?: OrFactory<SyncAdapter | SyncAdapter[]>;
403
+ /**
404
+ * Explicit array of adapters to flush data to.
345
405
  */
346
- adapter: OrFactory<SqlAdapter>;
406
+ adapters?: OrFactory<SyncAdapter>[];
347
407
  /** PubSub topic name prefix (topics will be `{prefix}-{repoName}`) */
348
408
  topicPrefix?: string;
349
409
  /** Max rows per flush batch (default: 100) */
350
410
  batchSize?: number;
351
411
  /** Flush interval in ms (default: 5000) */
352
412
  flushIntervalMs?: number;
353
- /** Auto-create/migrate tables on first event (default: false) */
413
+ /** Auto-create/migrate tables or indexes on first event (default: false) */
354
414
  autoMigrate?: boolean;
355
415
  /**
356
416
  * Cloud Functions v2 options forwarded to `onMessagePublished()` for every
@@ -359,7 +419,7 @@ interface FirestoreSyncConfig<M = Record<string, any>> {
359
419
  */
360
420
  workerOptions?: SyncWorkerOptions;
361
421
  /**
362
- * Optional sync admin endpoint. When provided, a `adminsync` handler is
422
+ * Optional sync admin endpoint. When provided, an `adminsync` handler is
363
423
  * added to `sync.functions` exposing health-check, force-sync, and queue
364
424
  * inspection endpoints behind authentication.
365
425
  */
@@ -368,4 +428,4 @@ interface FirestoreSyncConfig<M = Record<string, any>> {
368
428
  repos?: TypedRepoSyncConfigs<M>;
369
429
  }
370
430
 
371
- export type { AdminHttpsOptions as A, FirestoreSyncConfig as F, GenerateDDLConfig as G, LogicalType as L, OrFactory as O, PubSubClientDep as P, RepoSyncConfig as R, SyncEvent as S, SqlAdapter as a, SqlDialect as b, SqlTableDef as c, SqlColumn as d, adminsyncConfig as e, SyncTriggersConfig as f, SyncWorkerConfig as g, FirestoreTriggersDep as h, PubSubHandlerDep as i, SyncDeps as j, SyncOperation as k, SyncWorkerOptions as l, adminsyncBasicAuth as m, adminsyncFeaturesFlag as n };
431
+ export type { AdminHttpsOptions as A, FirestoreSyncConfig as F, GenerateDDLConfig as G, LogicalType as L, OrFactory as O, PubSubClientDep as P, RepoSyncConfig as R, SyncEvent as S, SyncAdapter as a, SqlAdapter as b, SqlDialect as c, SyncHealthResult as d, SqlTableDef as e, SqlColumn as f, adminsyncConfig as g, SyncTriggersConfig as h, SyncWorkerConfig as i, FirestoreTriggersDep as j, PubSubHandlerDep as k, SyncDeps as l, SyncOperation as m, SyncWorkerOptions as n, adminsyncBasicAuth as o, adminsyncFeaturesFlag as p };
@@ -1,6 +1,6 @@
1
1
  import { z, ZodError } from 'zod';
2
2
  import { Env, Context, MiddlewareHandler } from 'hono';
3
- import { F as FirebaseAdminAuthLike, D as DecodedIdTokenLike } from './firebase-auth-DZ8lb2Ec.js';
3
+ import { F as FirebaseAdminAuthLike, D as DecodedIdTokenLike } from './firebase-auth-Ds5P0kXT.js';
4
4
 
5
5
  /**
6
6
  * Global DI services container for the Hono server.
@@ -1,5 +1,5 @@
1
- import { c as AuthUser } from './firebase-auth-DZ8lb2Ec.js';
2
- import { H as HonoServerOptions, O as OpenAPIConfig } from './types-DyKJJ9UQ.js';
1
+ import { A as AuthUser } from './firebase-auth-Ds5P0kXT.js';
2
+ import { H as HonoServerOptions, O as OpenAPIConfig } from './types-DSMiiOrU.js';
3
3
  import * as zod from 'zod';
4
4
  import { z } from 'zod';
5
5
  import { HttpsOptions } from 'firebase-functions/v2/https';
@@ -609,6 +609,75 @@ type ConfiguredRepository<T extends RepositoryConfig<any, any, any, any, any, an
609
609
  history?: HistoryMethods<T["type"], Parameters<T["documentRef"]>>;
610
610
  };
611
611
 
612
+ interface PageOptions {
613
+ title: string;
614
+ breadcrumb?: {
615
+ label: string;
616
+ href?: string;
617
+ }[];
618
+ flash?: {
619
+ type: "success" | "error" | "warning";
620
+ message: string;
621
+ /** Optional call-to-action button rendered next to the message */
622
+ action?: {
623
+ href: string;
624
+ label: string;
625
+ external?: boolean;
626
+ };
627
+ };
628
+ basePath?: string;
629
+ }
630
+ /** Firestore WHERE operator */
631
+ type WhereOp = "==" | "!=" | "<" | "<=" | ">" | ">=" | "in" | "not-in" | "array-contains" | "array-contains-any";
632
+ /** One active filter — serialized in URL as fv_{field} + fo_{field} */
633
+ interface FilterState {
634
+ field: string;
635
+ op: WhereOp;
636
+ value: string;
637
+ }
638
+ /** Per-column metadata used to render appropriate filter inputs/operators */
639
+ interface ColumnMeta {
640
+ name: string;
641
+ /** Innermost Zod type name, e.g. "ZodString", "ZodNumber" */
642
+ zodType: string;
643
+ /** True if the field schema is wrapped in ZodOptional or ZodNullable */
644
+ nullable?: boolean;
645
+ /** For ZodEnum / ZodNativeEnum / ZodLiteral: the allowed values */
646
+ enumValues?: readonly string[];
647
+ }
648
+ /** Active sort state for the list view */
649
+ interface SortState {
650
+ field: string;
651
+ dir: "asc" | "desc";
652
+ }
653
+ /**
654
+ * Metadata for one relational action column appended to the list table.
655
+ * Each entry produces a dedicated button column (not a cell replacement).
656
+ */
657
+ /** Query error state displayed at the top of the list page. */
658
+ interface QueryError {
659
+ /** "index" = missing composite index; "error" = generic query failure */
660
+ type: "index" | "error";
661
+ message: string;
662
+ /** Firebase Console URL to create the missing index (always present for "index" type) */
663
+ indexUrl?: string;
664
+ }
665
+ interface RelationalFieldMeta {
666
+ /** Field in this document whose value is used to build the link */
667
+ key: string;
668
+ /** Column header label, e.g. "Posts" or "Author" */
669
+ column: string;
670
+ /** Name of the target repository in the admin registry */
671
+ targetRepo: string;
672
+ /** Field name on the target repo used for the lookup */
673
+ targetKey: string;
674
+ /**
675
+ * - "one" → doc[key] = docId on the target → link to edit page
676
+ * - "many" → doc[key] = filter value on the target → link to filtered list
677
+ */
678
+ type: "one" | "many";
679
+ }
680
+
612
681
  /**
613
682
  * Default security-headers middleware for the bundled HTTP servers.
614
683
  *
@@ -829,6 +898,42 @@ interface CrudRepoConfig<TRepo extends ConfiguredRepository<any> = ConfiguredRep
829
898
  */
830
899
  rules?: CrudRules<TRepo>;
831
900
  }
901
+ /** Return type of a diff computation comparing before and after states. */
902
+ interface DeepDiffReturn<T> {
903
+ /** Complete state before modification */
904
+ before: T;
905
+ /** Projected state after applying changes */
906
+ after: T;
907
+ /** Subset of keys whose value actually changed */
908
+ changes: Partial<T>;
909
+ }
910
+ /**
911
+ * Result returned by an authorization or before-rule.
912
+ * - `boolean`: `true` allows the operation, `false` rejects with HTTP 403 "Forbidden".
913
+ * - `string`: rejects with HTTP 403 and the given error reason.
914
+ * - `{ allowed: boolean; reason?: string }`: `allowed === true` permits, `allowed === false` rejects with HTTP 403 and `reason`.
915
+ */
916
+ type RuleResult = boolean | string | {
917
+ allowed: boolean;
918
+ reason?: string;
919
+ } | void;
920
+ /**
921
+ * A business rule attached to a specific field of model `T`.
922
+ */
923
+ interface Rule<T> {
924
+ description: string;
925
+ rule: (args: {
926
+ diff: DeepDiffReturn<T>;
927
+ key: keyof T;
928
+ user?: AuthUser;
929
+ /** Alias for `user` for backwards compatibility with legacy rules */
930
+ authenticatedUser?: AuthUser;
931
+ }) => boolean | void | Promise<boolean | void>;
932
+ }
933
+ /**
934
+ * Map of rules per field for model `T`.
935
+ */
936
+ type RulesMap<T> = Partial<Record<keyof T, Rule<T>[]>>;
832
937
  /** Context passed to {@link CrudRules.list}. */
833
938
  interface CrudListRuleContext {
834
939
  user: AuthUser;
@@ -853,6 +958,8 @@ interface CrudUpdateRuleContext<T = Record<string, unknown>> {
853
958
  doc: T;
854
959
  body: Partial<T>;
855
960
  params: Record<string, string>;
961
+ /** Computed diff between existing document (before) and submitted changes (after) */
962
+ diff: DeepDiffReturn<T>;
856
963
  }
857
964
  /** Context passed to {@link CrudRules.delete}. */
858
965
  interface CrudDeleteRuleContext<T = Record<string, unknown>> {
@@ -871,11 +978,11 @@ interface CrudFilterRuleContext<T = Record<string, unknown>> {
871
978
  * @template TRepo - The configured repository (used to type `doc` and `body`).
872
979
  */
873
980
  interface CrudRules<TRepo extends ConfiguredRepository<any> = ConfiguredRepository<any>> {
874
- list?: (ctx: CrudListRuleContext) => boolean | Promise<boolean>;
875
- get?: (ctx: CrudGetRuleContext<RepoModelType<TRepo>>) => boolean | Promise<boolean>;
876
- create?: (ctx: CrudCreateRuleContext<RepoModelType<TRepo>>) => boolean | Promise<boolean>;
877
- update?: (ctx: CrudUpdateRuleContext<RepoModelType<TRepo>>) => boolean | Promise<boolean>;
878
- delete?: (ctx: CrudDeleteRuleContext<RepoModelType<TRepo>>) => boolean | Promise<boolean>;
981
+ list?: (ctx: CrudListRuleContext) => RuleResult | Promise<RuleResult>;
982
+ get?: (ctx: CrudGetRuleContext<RepoModelType<TRepo>>) => RuleResult | Promise<RuleResult>;
983
+ create?: (ctx: CrudCreateRuleContext<RepoModelType<TRepo>>) => RuleResult | Promise<RuleResult>;
984
+ update?: (ctx: CrudUpdateRuleContext<RepoModelType<TRepo>>) => RuleResult | Promise<RuleResult>;
985
+ delete?: (ctx: CrudDeleteRuleContext<RepoModelType<TRepo>>) => RuleResult | Promise<RuleResult>;
879
986
  /** Row-level filter applied to every doc returned by `list` / `query` / `get`. */
880
987
  filter?: (ctx: CrudFilterRuleContext<RepoModelType<TRepo>>) => boolean | Promise<boolean>;
881
988
  }
@@ -983,7 +1090,52 @@ interface CrudServerOptions<TRepos extends Record<string, ConfiguredRepository<a
983
1090
  * ```
984
1091
  */
985
1092
  httpsOptions?: HttpsOptions;
1093
+ /**
1094
+ * Callback invoked whenever a missing Firestore composite index error is detected.
1095
+ * Useful for logging or writing the missing index URL into a Firestore collection for alerting / auto-provisioning.
1096
+ *
1097
+ * @example
1098
+ * ```ts
1099
+ * createCrudServer({
1100
+ * indexesError: async ({ indexUrl, repoName, path }) => {
1101
+ * await db.collection("missing_indexes").add({ indexUrl, repoName, path, createdAt: new Date() });
1102
+ * },
1103
+ * repos: { ... },
1104
+ * })
1105
+ * ```
1106
+ */
1107
+ indexesError?: IndexErrorCallback;
1108
+ /**
1109
+ * Alias for {@link indexesError}.
1110
+ */
1111
+ onIndexError?: IndexErrorCallback;
986
1112
  }
1113
+ /**
1114
+ * Context provided to the `indexesError` callback when a Firestore query fails due to a missing composite index.
1115
+ */
1116
+ interface IndexErrorContext {
1117
+ /** The generated or extracted Firebase Console URL to create the required index */
1118
+ indexUrl: string;
1119
+ /** Name of the repository where the index error occurred */
1120
+ repoName: string;
1121
+ /** Firestore collection path */
1122
+ path: string;
1123
+ /** Whether the query was on a collection-group */
1124
+ isGroup: boolean;
1125
+ /** Active query filters when the error occurred */
1126
+ filters: FilterState[];
1127
+ /** Active sort / orderBy when the error occurred */
1128
+ sort?: SortState;
1129
+ /** Original raw error object thrown by Firestore */
1130
+ error: unknown;
1131
+ /** Hono Context (provides access to req, headers, auth user, etc.) */
1132
+ c?: any;
1133
+ }
1134
+ /**
1135
+ * Callback invoked when a missing Firestore index error occurs.
1136
+ * Can be asynchronous (e.g. to write the index link into a Firestore collection).
1137
+ */
1138
+ type IndexErrorCallback = (ctx: IndexErrorContext) => void | Promise<void>;
987
1139
  /**
988
1140
  * Standard API response wrapper.
989
1141
  */
@@ -1094,4 +1246,4 @@ interface QueryRequestBody {
1094
1246
  withTotal?: boolean;
1095
1247
  }
1096
1248
 
1097
- export { type ApiResponse as A, type ConfiguredRepository as C, DEFAULT_HTML_CSP as D, type ExtractDocumentRefSignature as E, type FieldRole as F, type GetOptions as G, type IncludeConfigTyped as I, type ListResponseData as L, type OpenAPISpecOptions as O, type PaginationOptions as P, type QueryRequestBody as Q, type RepoFieldPath as R, type SecurityHeadersOptions as S, type UserFieldPath as U, type WhereClause as W, type CrudServerOptions as a, type CrudRepoConfig as b, type CrudRepoEntry as c, type CrudRepoRegistry as d, type RepoRelationKeys as e, type RepositoryConfig as f, type FieldPath as g, type QueryOptions as h, type RelationConfig as i, type ExtractUpdateSignature as j, type GetResult as k, type RelationalKeys as l, createPaginationIterator as m, executePaginatedQuery as n, type PaginationResult as o, type SystemBackfillFailure as p, type SystemBackfillOptions as q, type SystemBackfillResult as r, securityHeaders as s, type GenerateGetMethods as t, type GenerateQueryMethods as u, type PaginationWithIncludeOptionsTyped as v, type PopulateOptionsTyped as w };
1249
+ export { type ApiResponse as A, createPaginationIterator as B, type ConfiguredRepository as C, type DeepDiffReturn as D, type ExtractDocumentRefSignature as E, type FieldRole as F, type GetOptions as G, executePaginatedQuery as H, type IndexErrorCallback as I, type PaginationResult as J, type SystemBackfillFailure as K, type ListResponseData as L, type SystemBackfillOptions as M, type SystemBackfillResult as N, type OpenAPISpecOptions as O, type PageOptions as P, type QueryRequestBody as Q, type RepoFieldPath as R, type SecurityHeadersOptions as S, type GenerateGetMethods as T, type UserFieldPath as U, type GenerateQueryMethods as V, type WhereClause as W, type IncludeConfigTyped as X, type PaginationWithIncludeOptionsTyped as Y, type PopulateOptionsTyped as Z, type CrudServerOptions as a, type CrudRepoConfig as b, type CrudRepoEntry as c, type CrudRepoRegistry as d, type CrudRules as e, type CrudUpdateRuleContext as f, type IndexErrorContext as g, type RepoRelationKeys as h, type Rule as i, type RuleResult as j, type RulesMap as k, type RepositoryConfig as l, type RelationalFieldMeta as m, type FieldPath as n, type ColumnMeta as o, type FilterState as p, type SortState as q, type QueryError as r, DEFAULT_HTML_CSP as s, securityHeaders as t, type QueryOptions as u, type PaginationOptions as v, type RelationConfig as w, type ExtractUpdateSignature as x, type GetResult as y, type RelationalKeys as z };