@lpdjs/firestore-repo-service 3.0.14 → 3.0.16

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 (75) hide show
  1. package/dist/actor-context-DQZgWqj3.d.cts +117 -0
  2. package/dist/actor-context-DQZgWqj3.d.ts +117 -0
  3. package/dist/{create-servers-BwbKPcBG.d.cts → create-servers-BMpE8oAc.d.cts} +11 -5
  4. package/dist/{create-servers-DVCB8BKC.d.ts → create-servers-DSXdPM6o.d.ts} +11 -5
  5. package/dist/history/index.cjs +1 -1
  6. package/dist/history/index.cjs.map +1 -1
  7. package/dist/history/index.d.cts +67 -7
  8. package/dist/history/index.d.ts +67 -7
  9. package/dist/history/index.js +1 -1
  10. package/dist/history/index.js.map +1 -1
  11. package/dist/index.cjs +81 -81
  12. package/dist/index.cjs.map +1 -1
  13. package/dist/index.d.cts +12 -10
  14. package/dist/index.d.ts +12 -10
  15. package/dist/index.js +81 -81
  16. package/dist/index.js.map +1 -1
  17. package/dist/llms-full.txt +1 -1
  18. package/dist/llms.txt +1 -1
  19. package/dist/{openapi-B0s5qVSg.d.ts → openapi-CKTuB2Yz.d.ts} +1 -1
  20. package/dist/{openapi-DZp7mW-s.d.cts → openapi-Cb3QMU0Q.d.cts} +1 -1
  21. package/dist/{queue-aNhdaNGW.d.ts → queue-NFod6hTT.d.ts} +1 -1
  22. package/dist/{queue-B0rkiPZF.d.cts → queue-zw2B7GPx.d.cts} +1 -1
  23. package/dist/{read-15-TcgCz.d.ts → read-BPov7lws.d.ts} +30 -7
  24. package/dist/{read-B15YaPyR.d.cts → read-Dfah1PPl.d.cts} +30 -7
  25. package/dist/{rules-DNJV8yxi.d.ts → rules-DY5f_wPw.d.ts} +1 -1
  26. package/dist/{rules-BV3-D08Y.d.cts → rules-DhNUzbIl.d.cts} +1 -1
  27. package/dist/servers/admin/index.cjs +6 -6
  28. package/dist/servers/admin/index.cjs.map +1 -1
  29. package/dist/servers/admin/index.d.cts +6 -5
  30. package/dist/servers/admin/index.d.ts +6 -5
  31. package/dist/servers/admin/index.js +6 -6
  32. package/dist/servers/admin/index.js.map +1 -1
  33. package/dist/servers/crud/index.cjs +2 -2
  34. package/dist/servers/crud/index.cjs.map +1 -1
  35. package/dist/servers/crud/index.d.cts +10 -9
  36. package/dist/servers/crud/index.d.ts +10 -9
  37. package/dist/servers/crud/index.js +2 -2
  38. package/dist/servers/crud/index.js.map +1 -1
  39. package/dist/servers/hono/index.cjs +14 -14
  40. package/dist/servers/hono/index.cjs.map +1 -1
  41. package/dist/servers/hono/index.d.cts +11 -3
  42. package/dist/servers/hono/index.d.ts +11 -3
  43. package/dist/servers/hono/index.js +14 -14
  44. package/dist/servers/hono/index.js.map +1 -1
  45. package/dist/servers/index.cjs +94 -94
  46. package/dist/servers/index.cjs.map +1 -1
  47. package/dist/servers/index.d.cts +13 -12
  48. package/dist/servers/index.d.ts +13 -12
  49. package/dist/servers/index.js +94 -94
  50. package/dist/servers/index.js.map +1 -1
  51. package/dist/sync/bigquery.d.cts +2 -2
  52. package/dist/sync/bigquery.d.ts +2 -2
  53. package/dist/sync/index.cjs +55 -55
  54. package/dist/sync/index.cjs.map +1 -1
  55. package/dist/sync/index.d.cts +6 -6
  56. package/dist/sync/index.d.ts +6 -6
  57. package/dist/sync/index.js +55 -55
  58. package/dist/sync/index.js.map +1 -1
  59. package/dist/sync/meilisearch.cjs +2 -2
  60. package/dist/sync/meilisearch.cjs.map +1 -1
  61. package/dist/sync/meilisearch.d.cts +2 -2
  62. package/dist/sync/meilisearch.d.ts +2 -2
  63. package/dist/sync/meilisearch.js +2 -2
  64. package/dist/sync/meilisearch.js.map +1 -1
  65. package/dist/{types-o-9qoExc.d.cts → types-BDTx8VPg.d.cts} +8 -0
  66. package/dist/{types-dDxiibCW.d.ts → types-B_FrzmO4.d.ts} +1 -1
  67. package/dist/{types-BuggDko0.d.ts → types-CaCBG76r.d.ts} +82 -49
  68. package/dist/{types--RamYGF1.d.cts → types-D6zvWzRt.d.cts} +96 -2
  69. package/dist/{types--RamYGF1.d.ts → types-D6zvWzRt.d.ts} +96 -2
  70. package/dist/{types-Dvst2iLQ.d.cts → types-D78FPJeF.d.cts} +1 -1
  71. package/dist/{types-BFu2DpKn.d.cts → types-Dc3lX99O.d.cts} +1 -1
  72. package/dist/{types-BvJYEGa1.d.ts → types-DgFJLwAu.d.ts} +1 -1
  73. package/dist/{types-Cko118ZS.d.cts → types-mKcJozu4.d.cts} +82 -49
  74. package/dist/{types-D3W_RaDA.d.ts → types-w1rEqs0Z.d.ts} +8 -0
  75. package/package.json +1 -1
@@ -1,10 +1,10 @@
1
1
  import { b as AuthUser } from './firebase-auth-nG3prKoj.js';
2
- import { H as HonoServerOptions, O as OpenAPIConfig } from './types-D3W_RaDA.js';
2
+ import { H as HonoServerOptions, O as OpenAPIConfig } from './types-w1rEqs0Z.js';
3
3
  import { z } from 'zod';
4
4
  import { HttpsOptions } from 'firebase-functions/v2/https';
5
- import { H as HistoryMethods } from './read-15-TcgCz.js';
5
+ import { H as HistoryMethods } from './read-BPov7lws.js';
6
6
  import { DocumentSnapshot, Query, CollectionReference, WriteBatch, Transaction, DocumentReference } from 'firebase-admin/firestore';
7
- import { Q as QueryOptions, R as RepositoryConfig, G as GetOptions, g as GetResult, i as ExtractReturnDoc, a as RelationConfig, D as DeepPartial, b as DotNotationUpdate, F as FieldPath } from './types-BvJYEGa1.js';
7
+ import { Q as QueryOptions, R as RepositoryConfig, G as GetOptions, g as GetResult, i as ExtractReturnDoc, a as RelationConfig, D as DeepPartial, b as DotNotationUpdate, F as FieldPath } from './types-DgFJLwAu.js';
8
8
 
9
9
  /**
10
10
  * Pagination result with data and cursor information
@@ -222,6 +222,18 @@ type IncludeConfigTyped<TRelationalKeys, K extends keyof TRelationalKeys = keyof
222
222
  /** Fields to select from the related documents (typed to target model) */
223
223
  select?: (keyof ExtractTargetModel<TRelationalKeys[K]>)[];
224
224
  } : never;
225
+ /**
226
+ * `true` when `T` is `any` (the `0 extends (1 & T)` trick).
227
+ * @internal
228
+ */
229
+ type IsAny$1<T> = 0 extends 1 & T ? true : false;
230
+ /**
231
+ * `keyof T` for concrete models, or `any` when `T` is `any` (avoiding
232
+ * `keyof any = string | number | symbol` which breaks contravariant method
233
+ * assignability to `ConfiguredRepository<any>`).
234
+ * @internal
235
+ */
236
+ type FieldKeyOf<T> = IsAny$1<T> extends true ? any : keyof T;
225
237
  /**
226
238
  * Typed pagination options with include support
227
239
  */
@@ -230,25 +242,25 @@ interface PaginationWithIncludeOptionsTyped<T, TRelationalKeys, K extends keyof
230
242
  cursor?: any;
231
243
  direction?: "next" | "prev";
232
244
  orderBy?: {
233
- field: keyof T;
245
+ field: FieldKeyOf<T>;
234
246
  direction?: "asc" | "desc";
235
247
  }[];
236
- where?: [keyof T, any, any][];
248
+ where?: [FieldKeyOf<T>, any, any][];
237
249
  /**
238
250
  * Simple OR: each clause is independently OR'd with the others.
239
251
  * Base `where` conditions are applied to every OR branch.
240
252
  * @example
241
253
  * orWhere: [["status", "==", "draft"], ["status", "==", "published"]]
242
254
  */
243
- orWhere?: [keyof T, any, any][];
255
+ orWhere?: [FieldKeyOf<T>, any, any][];
244
256
  /**
245
257
  * Advanced OR: each element is a GROUP of AND conditions, groups are OR'd.
246
258
  * Base `where` conditions are applied to every group.
247
259
  */
248
- orWhereGroups?: [keyof T, any, any][][];
249
- select?: (keyof T)[];
260
+ orWhereGroups?: [FieldKeyOf<T>, any, any][][];
261
+ select?: FieldKeyOf<T>[];
250
262
  /** Relations to include - can be relation keys or typed IncludeConfig */
251
- include?: (K | IncludeConfigTyped<TRelationalKeys>)[];
263
+ include?: IsAny$1<TRelationalKeys> extends true ? any[] : (K | IncludeConfigTyped<TRelationalKeys>)[];
252
264
  }
253
265
  /**
254
266
  * Helper type to get the system keys (documentKey + pathKey + updatedKey) that should be excluded from updates
@@ -260,12 +272,12 @@ type SystemKeys<T extends RepositoryConfig<any, any, any, any, any, any, any, an
260
272
  * and supports deep-partial nested objects as well as dot-notation paths (e.g. "address.city").
261
273
  * @internal
262
274
  */
263
- type UpdatableData<T extends RepositoryConfig<any, any, any, any, any, any, any, any, any, any, any>> = DeepPartial<Omit<T["type"], SystemKeys<T>>> & DotNotationUpdate<Omit<T["type"], SystemKeys<T>>>;
275
+ type UpdatableData<T extends RepositoryConfig<any, any, any, any, any, any, any, any, any, any, any>> = IsAny$1<T> extends true ? any : DeepPartial<Omit<T["type"], SystemKeys<T>>> & DotNotationUpdate<Omit<T["type"], SystemKeys<T>>>;
264
276
  /**
265
277
  * Type for create data - excludes pathKey, createdKey and updatedKey (auto-managed), documentKey is optional
266
278
  * @internal
267
279
  */
268
- type CreateData<T extends RepositoryConfig<any, any, any, any, any, any, any, any, any, any, any>> = Omit<T["type"], T["documentKey"] | Extract<T["pathKey"], keyof T["type"]> | Extract<T["createdKey"], keyof T["type"]> | Extract<T["updatedKey"], keyof T["type"]>> & {
280
+ type CreateData<T extends RepositoryConfig<any, any, any, any, any, any, any, any, any, any, any>> = IsAny$1<T> extends true ? any : Omit<T["type"], T["documentKey"] | Extract<T["pathKey"], keyof T["type"]> | Extract<T["createdKey"], keyof T["type"]> | Extract<T["updatedKey"], keyof T["type"]>> & {
269
281
  [K in T["documentKey"]]?: T["type"][K];
270
282
  };
271
283
  /**
@@ -305,9 +317,28 @@ type GenerateQueryMethods<TConfig extends RepositoryConfig<any, any, any, any, a
305
317
  [K in TConfig["queryKeys"][number] as K extends string ? `by${Capitalize<K>}` : never]: (value: TConfig["type"][K], options?: QueryOptions<TConfig["type"]>) => Promise<TConfig["type"][]>;
306
318
  };
307
319
  /**
308
- * Configured repository with organized methods
320
+ * Conditional `history` namespace property derived from `THistoryEnabled`:
321
+ * - `ConfiguredRepository<any>` → optional `{ history?: HistoryMethods<any, any[]> }`
322
+ * - `history: { enabled: true }` → required `{ history: HistoryMethods<T, PathArgs> }`
323
+ * - `history` omitted or `enabled: false` → `{}` (`history` is absent from the type)
324
+ * - dynamic `enabled: boolean` → optional `{ history?: HistoryMethods<T, PathArgs> }`
325
+ * @internal
309
326
  */
310
- type ConfiguredRepository<T extends RepositoryConfig<any, any, any, any, any, any, any, any, any, any, any>> = {
327
+ type HistoryProperty<T> = IsAny$1<T> extends true ? {
328
+ history?: HistoryMethods<any, any[]>;
329
+ } : T extends RepositoryConfig<infer TModel, any, any, any, any, any, any, any, any, any, infer THistoryEnabled> ? [THistoryEnabled] extends [true] ? {
330
+ history: HistoryMethods<TModel, T["documentRef"] extends (...args: infer P) => any ? P : any[]>;
331
+ } : [THistoryEnabled] extends [false] ? {} : {
332
+ history?: HistoryMethods<TModel, T["documentRef"] extends (...args: infer P) => any ? P : any[]>;
333
+ } : {};
334
+ /**
335
+ * Core methods shared by every configured repository. Kept as a dedicated named
336
+ * alias so TypeScript's type-argument shortcut keeps `ConfiguredRepository<T>`
337
+ * assignable to `ConfiguredRepository<any>` even with the conditional
338
+ * {@link HistoryProperty} intersection.
339
+ * @internal
340
+ */
341
+ type ConfiguredRepositoryBase<T extends RepositoryConfig<any, any, any, any, any, any, any, any, any, any, any>> = {
311
342
  /** @internal Phantom property to expose the model type for generic extraction */
312
343
  readonly _modelType: T["type"];
313
344
  /** @internal Whether this is a collectionGroup repository */
@@ -328,7 +359,7 @@ type ConfiguredRepository<T extends RepositoryConfig<any, any, any, any, any, an
328
359
  ] extends [never] ? PaginationResult<T["type"]> : PaginationResult<T["type"] & {
329
360
  populated: Record<string, any>;
330
361
  }>>;
331
- paginateAll: (options: Omit<PaginationWithIncludeOptionsTyped<T["type"], NonNullable<T["relationalKeys"]>, keyof NonNullable<T["relationalKeys"]>>, "cursor" | "direction">) => ReturnType<typeof createPaginationIterator<T["type"]>>;
362
+ paginateAll(options: Omit<PaginationWithIncludeOptionsTyped<T["type"], NonNullable<T["relationalKeys"]>, keyof NonNullable<T["relationalKeys"]>>, "cursor" | "direction">): ReturnType<typeof createPaginationIterator<T["type"]>>;
332
363
  };
333
364
  aggregate: {
334
365
  count: (options?: QueryOptions<T["type"]>) => Promise<number>;
@@ -336,57 +367,57 @@ type ConfiguredRepository<T extends RepositoryConfig<any, any, any, any, any, an
336
367
  average: <K extends keyof T["type"]>(field: K, options?: QueryOptions<T["type"]>) => Promise<number | null>;
337
368
  };
338
369
  documentRef: T["documentRef"];
339
- create: (data: CreateData<T>) => Promise<T["type"]>;
340
- set: (...args: [
370
+ create(data: CreateData<T>): Promise<T["type"]>;
371
+ set(...args: [
341
372
  ...Parameters<T["documentRef"]>,
342
373
  UpdatableData<T>,
343
374
  {
344
375
  merge?: boolean;
345
376
  }?
346
- ]) => Promise<T["type"]>;
347
- update: (...args: [...Parameters<T["documentRef"]>, UpdatableData<T>]) => Promise<T["type"]>;
348
- delete: (...args: Parameters<T["documentRef"]>) => Promise<void>;
377
+ ]): Promise<T["type"]>;
378
+ update(...args: [...Parameters<T["documentRef"]>, UpdatableData<T>]): Promise<T["type"]>;
379
+ delete(...args: Parameters<T["documentRef"]>): Promise<void>;
349
380
  batch: {
350
- create: () => {
381
+ create(): {
351
382
  batch: WriteBatch;
352
- set: (...args: [
383
+ set(...args: [
353
384
  ...Parameters<T["documentRef"]>,
354
385
  UpdatableData<T>,
355
386
  {
356
387
  merge?: boolean;
357
388
  }?
358
- ]) => void;
359
- update: (...args: [...Parameters<T["documentRef"]>, UpdatableData<T>]) => void;
360
- delete: (...args: Parameters<T["documentRef"]>) => void;
361
- commit: () => Promise<void>;
389
+ ]): void;
390
+ update(...args: [...Parameters<T["documentRef"]>, UpdatableData<T>]): void;
391
+ delete(...args: Parameters<T["documentRef"]>): void;
392
+ commit(): Promise<void>;
362
393
  };
363
394
  };
364
395
  transaction: {
365
- run: <R>(updateFunction: (transaction: {
366
- get: (...args: Parameters<T["documentRef"]>) => Promise<T["type"] | null>;
367
- set: (...args: [
396
+ run<R>(updateFunction: (transaction: {
397
+ get(...args: Parameters<T["documentRef"]>): Promise<T["type"] | null>;
398
+ set(...args: [
368
399
  ...Parameters<T["documentRef"]>,
369
400
  UpdatableData<T>,
370
401
  {
371
402
  merge?: boolean;
372
403
  }?
373
- ]) => void;
374
- update: (...args: [...Parameters<T["documentRef"]>, UpdatableData<T>]) => void;
375
- delete: (...args: Parameters<T["documentRef"]>) => void;
404
+ ]): void;
405
+ update(...args: [...Parameters<T["documentRef"]>, UpdatableData<T>]): void;
406
+ delete(...args: Parameters<T["documentRef"]>): void;
376
407
  raw: Transaction;
377
- }) => Promise<R>) => Promise<R>;
408
+ }) => Promise<R>): Promise<R>;
378
409
  };
379
410
  bulk: {
380
- set: (items: Array<{
411
+ set(items: Array<{
381
412
  docRef: DocumentReference;
382
413
  data: UpdatableData<T>;
383
414
  merge?: boolean;
384
- }>) => Promise<void>;
385
- update: (items: Array<{
415
+ }>): Promise<void>;
416
+ update(items: Array<{
386
417
  docRef: DocumentReference;
387
418
  data: UpdatableData<T>;
388
- }>) => Promise<void>;
389
- delete: (docRefs: DocumentReference[]) => Promise<void>;
419
+ }>): Promise<void>;
420
+ delete(docRefs: DocumentReference[]): Promise<void>;
390
421
  };
391
422
  /**
392
423
  * Collection-wide maintenance helpers. `backfillKeys` fills the auto-managed
@@ -394,19 +425,21 @@ type ConfiguredRepository<T extends RepositoryConfig<any, any, any, any, any, an
394
425
  * documents written outside this package — idempotent and write-minimal.
395
426
  */
396
427
  system: {
397
- backfillKeys: (options?: SystemBackfillOptions) => Promise<SystemBackfillResult>;
428
+ backfillKeys(options?: SystemBackfillOptions): Promise<SystemBackfillResult>;
398
429
  };
399
- populate: <K extends keyof NonNullable<T["relationalKeys"]>, TDoc extends Pick<T["type"], K & keyof T["type"]>>(document: TDoc, relationKeyOrOptions: K | K[] | PopulateOptionsTyped<NonNullable<T["relationalKeys"]>, K>) => Promise<TDoc & {
430
+ populate<K extends keyof NonNullable<T["relationalKeys"]>, TDoc extends Pick<T["type"], K & keyof T["type"]>>(document: TDoc, relationKeyOrOptions: K | K[] | PopulateOptionsTyped<NonNullable<T["relationalKeys"]>, K>): Promise<TDoc & {
400
431
  populated: UnionToIntersection<K extends keyof NonNullable<T["relationalKeys"]> ? ExtractPopulatedFromRelation<NonNullable<T["relationalKeys"]>[K], K & string> : Record<string, never>>;
401
432
  }>;
402
- /**
403
- * Change-history namespace. Present at the type level when the repo is
404
- * configured with `history.enabled: true`, otherwise `undefined` at runtime.
405
- * Kept optional (rather than conditional) so `ConfiguredRepository<any>`
406
- * stays assignable from any concrete repo config.
407
- */
408
- history?: HistoryMethods<T["type"], Parameters<T["documentRef"]>>;
409
433
  };
434
+ /**
435
+ * Configured repository with organized methods.
436
+ *
437
+ * The `history` namespace is typed conditionally from `history.enabled`:
438
+ * - `history: { enabled: true }` → `repo.history` is required (no `!` / `?.` needed)
439
+ * - `history` omitted or `enabled: false` → `repo.history` is absent from the type
440
+ * - dynamic `enabled: boolean` → `repo.history` is optional (`HistoryMethods | undefined`)
441
+ */
442
+ type ConfiguredRepository<T extends RepositoryConfig<any, any, any, any, any, any, any, any, any, any, any>> = ConfiguredRepositoryBase<T> & HistoryProperty<T>;
410
443
 
411
444
  interface PageOptions {
412
445
  title: string;
@@ -562,13 +595,13 @@ interface OpenAPISpecOptions {
562
595
  * `createRepositoryConfig(schema)`).
563
596
  * @internal
564
597
  */
565
- type RepoModelType<TRepo> = TRepo extends ConfiguredRepository<infer C> ? C extends RepositoryConfig<infer T, any, any, any, any, any, any, any, any, any, any> ? T : never : never;
598
+ type RepoModelType<TRepo> = TRepo extends ConfiguredRepository<infer C extends RepositoryConfig<any, any, any, any, any, any, any, any, any, any, any>> ? C extends RepositoryConfig<infer T, any, any, any, any, any, any, any, any, any, any> ? T : never : never;
566
599
  /**
567
600
  * Extracts the auto-managed system keys (documentKey, pathKey, createdKey, updatedKey)
568
601
  * from a `ConfiguredRepository`. These keys must never appear in create/update payloads.
569
602
  * @internal
570
603
  */
571
- type RepoSystemKeys<TRepo> = TRepo extends ConfiguredRepository<infer C> ? C extends RepositoryConfig<any, any, any, any, any, any, infer TDocKey, infer TPathKey, infer TCreatedKey, infer TUpdatedKey, any> ? (TDocKey extends string ? TDocKey : never) | (TPathKey extends string ? TPathKey : never) | (TCreatedKey extends string ? TCreatedKey : never) | (TUpdatedKey extends string ? TUpdatedKey : never) : never : never;
604
+ type RepoSystemKeys<TRepo> = TRepo extends ConfiguredRepository<infer C extends RepositoryConfig<any, any, any, any, any, any, any, any, any, any, any>> ? C extends RepositoryConfig<any, any, any, any, any, any, infer TDocKey, infer TPathKey, infer TCreatedKey, infer TUpdatedKey, any> ? (TDocKey extends string ? TDocKey : never) | (TPathKey extends string ? TPathKey : never) | (TCreatedKey extends string ? TCreatedKey : never) | (TUpdatedKey extends string ? TUpdatedKey : never) : never : never;
572
605
  /**
573
606
  * `true` when `T` is `any` (the `0 extends (1 & T)` trick).
574
607
  * @internal
@@ -1020,7 +1053,7 @@ interface QueryRequestBody {
1020
1053
  */
1021
1054
  select?: string[];
1022
1055
  /**
1023
- * Number of items per page (max 100).
1056
+ * Number of items per page (min 1, max 1000).
1024
1057
  * @default 25
1025
1058
  */
1026
1059
  pageSize?: number;
@@ -16,7 +16,32 @@ import { DocumentOptions, onDocumentWritten } from 'firebase-functions/v2/firest
16
16
  */
17
17
  type TriggerOptions = Omit<DocumentOptions, "document">;
18
18
  type HistoryTriggerOptions = TriggerOptions;
19
- type HistoryOperation = "create" | "update" | "delete";
19
+ type HistoryOperation = "create" | "update" | "delete" | "custom";
20
+ /**
21
+ * Structured payload attached to `operation: "custom"` history entries
22
+ * (business actions independent of model fields, e.g. manual invoice creation,
23
+ * PDF export, email sent, etc.).
24
+ */
25
+ interface HistoryCustomData {
26
+ /** Human-readable title (e.g. `"Création de la facture"`). */
27
+ title: string;
28
+ /** Optional human-readable description (e.g. `"Facture #F-2026-042 créée manuellement"`). */
29
+ description?: string;
30
+ /** Optional business action key for filtering/grouping/icons (e.g. `"invoice_create_manually"`). */
31
+ key?: string;
32
+ /** Optional front-end visibility flag (default: `true`). */
33
+ display?: boolean;
34
+ /** Optional arbitrary structured business payload (e.g. `{ invoiceId, amount }`). */
35
+ data?: Record<string, unknown>;
36
+ }
37
+ /** Input payload accepted by `repo.history.recordCustom(...)`. */
38
+ interface HistoryCustomInput extends HistoryCustomData {
39
+ /**
40
+ * Optional metadata overrides (`reason`, `comment`, `extras`, `userId`,
41
+ * `userEmail`). Automatically merged on top of the active ALS actor.
42
+ */
43
+ meta?: HistoryMeta;
44
+ }
20
45
  /**
21
46
  * Detected JS/Firestore type of a value as stored in a history entry.
22
47
  * Matches the values returned by {@link valueType}.
@@ -57,6 +82,8 @@ interface HistoryEntry<T = Record<string, unknown>> {
57
82
  operation: HistoryOperation;
58
83
  /** Captured author / context information. */
59
84
  meta: HistoryMeta;
85
+ /** Present on `operation: "custom"` entries (business actions independent of model fields). */
86
+ custom?: HistoryCustomData;
60
87
  /** Per-field changes. Keys are field names of T. */
61
88
  changes: {
62
89
  [K in keyof T & string]?: HistoryFieldChange;
@@ -72,6 +99,8 @@ interface V2HistoryDoc {
72
99
  historySetAt: Timestamp;
73
100
  operation: HistoryOperation;
74
101
  meta: HistoryMeta;
102
+ /** Present on `operation: "custom"` entries. */
103
+ custom?: HistoryCustomData;
75
104
  changes: Record<string, HistoryFieldChange>;
76
105
  /** Optional TTL marker (Firestore deletes the doc after this date). */
77
106
  expiresAt?: Timestamp;
@@ -105,6 +134,49 @@ interface V1HistoryDoc {
105
134
  extraContentKeys?: Record<string, unknown> | null;
106
135
  objectType?: string;
107
136
  }
137
+ /** Default top-level shadow field name stored on Firestore documents for auto-injected history metadata. */
138
+ declare const DEFAULT_HISTORY_SHADOW_KEY = "_historyMeta";
139
+ /**
140
+ * Customize (or disable via `false`) the sub-field names stored inside the
141
+ * shadow metadata object on Firestore documents.
142
+ */
143
+ interface HistoryShadowFieldsConfig {
144
+ /** Key inside the shadow object for author userId, or `false` to omit. Default: `"userId"`. */
145
+ userId?: string | false;
146
+ /** Key inside the shadow object for author userEmail, or `false` to omit. Default: `"userEmail"`. */
147
+ userEmail?: string | false;
148
+ /** Key inside the shadow object for change reason, or `false` to omit. Default: `"reason"`. */
149
+ reason?: string | false;
150
+ /** Key inside the shadow object for change comment, or `false` to omit. Default: `"comment"`. */
151
+ comment?: string | false;
152
+ /** Key inside the shadow object for extras map, or `false` to omit. Default: `"extras"`. */
153
+ extras?: string | false;
154
+ }
155
+ /**
156
+ * Configuration for the internal shadow field used to transport actor metadata
157
+ * to Firestore `onDocumentWritten` triggers without modifying Zod schemas.
158
+ */
159
+ interface HistoryShadowConfig {
160
+ /**
161
+ * Top-level field name stored on the Firestore document (not required in the
162
+ * Zod schema, automatically excluded from diffs and sync, and stripped on read).
163
+ * Default: `"_historyMeta"`.
164
+ */
165
+ key?: string;
166
+ /**
167
+ * Customize or disable individual sub-field names inside the shadow object.
168
+ * Default: `{ userId: "userId", userEmail: "userEmail", reason: "reason", comment: "comment", extras: "extras" }`.
169
+ */
170
+ fields?: HistoryShadowFieldsConfig;
171
+ }
172
+ /**
173
+ * Fallback author values written when no actor is active in `AsyncLocalStorage`
174
+ * (crons, scripts, admin UI, public routes).
175
+ */
176
+ interface HistoryFallbackActor {
177
+ userId?: string | null;
178
+ userEmail?: string | null;
179
+ }
108
180
  /**
109
181
  * Per-repo history configuration. Attached on the repository config under
110
182
  * the `history` key. All meta sub-keys must reference fields that exist on
@@ -115,6 +187,27 @@ interface HistoryConfigBase {
115
187
  enabled: boolean;
116
188
  /** Subcollection name used to store history docs. Default: "history". */
117
189
  subcollection?: string;
190
+ /**
191
+ * Automatically inject actor metadata from `AsyncLocalStorage` into the
192
+ * shadow field on repository writes (`create`, `set`, `update`, `batch`,
193
+ * `transaction`, `bulk`). Default: `true` when `enabled: true`.
194
+ */
195
+ autoInjectMeta?: boolean;
196
+ /**
197
+ * Shadow field configuration (zero Zod schema changes).
198
+ *
199
+ * - Omitted or `true` (when `meta` is absent): uses `"_historyMeta"` with default sub-fields.
200
+ * - `string`: shorthand for `{ key: "<customKey>" }`.
201
+ * - `HistoryShadowConfig`: customize both `key` and nested `fields`.
202
+ * - `false`: disable shadow metadata injection/reading.
203
+ */
204
+ shadow?: boolean | string | HistoryShadowConfig;
205
+ /**
206
+ * Fallback actor written when no actor is active in `AsyncLocalStorage` so
207
+ * previous author metadata never leaks onto subsequent writes.
208
+ * Default: `{ userId: null, userEmail: null }`.
209
+ */
210
+ fallbackActor?: HistoryFallbackActor;
118
211
  /**
119
212
  * Optional Firestore TTL configuration. When set, every written history doc
120
213
  * gets an `expiresAt` Timestamp at `now + days`. You still need to enable
@@ -219,4 +312,5 @@ interface HistoryTriggersConfig<M = Record<string, any>> {
219
312
  repos?: Partial<Record<keyof M & string, HistoryTriggerRepoOverride>>;
220
313
  }
221
314
 
222
- export type { HistoryTriggersConfig as H, TriggerOptions as T, V1HistoryDoc as V, HistoryListOptions as a, HistoryEntry as b, HistoryRawListOptions as c, V2HistoryDoc as d, HistoryOperation as e, HistoryMeta as f, HistoryConfigForModel as g, HistoryFieldChange as h, HistoryValueType as i, HistoryConfigBase as j, HistoryFirestoreTriggersDep as k, HistoryTriggerOptions as l, HistoryTriggerRepoOverride as m };
315
+ export { DEFAULT_HISTORY_SHADOW_KEY as D };
316
+ export type { HistoryTriggersConfig as H, TriggerOptions as T, V1HistoryDoc as V, HistoryListOptions as a, HistoryEntry as b, HistoryRawListOptions as c, V2HistoryDoc as d, HistoryOperation as e, HistoryMeta as f, HistoryCustomData as g, HistoryCustomInput as h, HistoryConfigForModel as i, HistoryFieldChange as j, HistoryValueType as k, HistoryConfigBase as l, HistoryFallbackActor as m, HistoryFirestoreTriggersDep as n, HistoryShadowConfig as o, HistoryShadowFieldsConfig as p, HistoryTriggerOptions as q, HistoryTriggerRepoOverride as r };
@@ -16,7 +16,32 @@ import { DocumentOptions, onDocumentWritten } from 'firebase-functions/v2/firest
16
16
  */
17
17
  type TriggerOptions = Omit<DocumentOptions, "document">;
18
18
  type HistoryTriggerOptions = TriggerOptions;
19
- type HistoryOperation = "create" | "update" | "delete";
19
+ type HistoryOperation = "create" | "update" | "delete" | "custom";
20
+ /**
21
+ * Structured payload attached to `operation: "custom"` history entries
22
+ * (business actions independent of model fields, e.g. manual invoice creation,
23
+ * PDF export, email sent, etc.).
24
+ */
25
+ interface HistoryCustomData {
26
+ /** Human-readable title (e.g. `"Création de la facture"`). */
27
+ title: string;
28
+ /** Optional human-readable description (e.g. `"Facture #F-2026-042 créée manuellement"`). */
29
+ description?: string;
30
+ /** Optional business action key for filtering/grouping/icons (e.g. `"invoice_create_manually"`). */
31
+ key?: string;
32
+ /** Optional front-end visibility flag (default: `true`). */
33
+ display?: boolean;
34
+ /** Optional arbitrary structured business payload (e.g. `{ invoiceId, amount }`). */
35
+ data?: Record<string, unknown>;
36
+ }
37
+ /** Input payload accepted by `repo.history.recordCustom(...)`. */
38
+ interface HistoryCustomInput extends HistoryCustomData {
39
+ /**
40
+ * Optional metadata overrides (`reason`, `comment`, `extras`, `userId`,
41
+ * `userEmail`). Automatically merged on top of the active ALS actor.
42
+ */
43
+ meta?: HistoryMeta;
44
+ }
20
45
  /**
21
46
  * Detected JS/Firestore type of a value as stored in a history entry.
22
47
  * Matches the values returned by {@link valueType}.
@@ -57,6 +82,8 @@ interface HistoryEntry<T = Record<string, unknown>> {
57
82
  operation: HistoryOperation;
58
83
  /** Captured author / context information. */
59
84
  meta: HistoryMeta;
85
+ /** Present on `operation: "custom"` entries (business actions independent of model fields). */
86
+ custom?: HistoryCustomData;
60
87
  /** Per-field changes. Keys are field names of T. */
61
88
  changes: {
62
89
  [K in keyof T & string]?: HistoryFieldChange;
@@ -72,6 +99,8 @@ interface V2HistoryDoc {
72
99
  historySetAt: Timestamp;
73
100
  operation: HistoryOperation;
74
101
  meta: HistoryMeta;
102
+ /** Present on `operation: "custom"` entries. */
103
+ custom?: HistoryCustomData;
75
104
  changes: Record<string, HistoryFieldChange>;
76
105
  /** Optional TTL marker (Firestore deletes the doc after this date). */
77
106
  expiresAt?: Timestamp;
@@ -105,6 +134,49 @@ interface V1HistoryDoc {
105
134
  extraContentKeys?: Record<string, unknown> | null;
106
135
  objectType?: string;
107
136
  }
137
+ /** Default top-level shadow field name stored on Firestore documents for auto-injected history metadata. */
138
+ declare const DEFAULT_HISTORY_SHADOW_KEY = "_historyMeta";
139
+ /**
140
+ * Customize (or disable via `false`) the sub-field names stored inside the
141
+ * shadow metadata object on Firestore documents.
142
+ */
143
+ interface HistoryShadowFieldsConfig {
144
+ /** Key inside the shadow object for author userId, or `false` to omit. Default: `"userId"`. */
145
+ userId?: string | false;
146
+ /** Key inside the shadow object for author userEmail, or `false` to omit. Default: `"userEmail"`. */
147
+ userEmail?: string | false;
148
+ /** Key inside the shadow object for change reason, or `false` to omit. Default: `"reason"`. */
149
+ reason?: string | false;
150
+ /** Key inside the shadow object for change comment, or `false` to omit. Default: `"comment"`. */
151
+ comment?: string | false;
152
+ /** Key inside the shadow object for extras map, or `false` to omit. Default: `"extras"`. */
153
+ extras?: string | false;
154
+ }
155
+ /**
156
+ * Configuration for the internal shadow field used to transport actor metadata
157
+ * to Firestore `onDocumentWritten` triggers without modifying Zod schemas.
158
+ */
159
+ interface HistoryShadowConfig {
160
+ /**
161
+ * Top-level field name stored on the Firestore document (not required in the
162
+ * Zod schema, automatically excluded from diffs and sync, and stripped on read).
163
+ * Default: `"_historyMeta"`.
164
+ */
165
+ key?: string;
166
+ /**
167
+ * Customize or disable individual sub-field names inside the shadow object.
168
+ * Default: `{ userId: "userId", userEmail: "userEmail", reason: "reason", comment: "comment", extras: "extras" }`.
169
+ */
170
+ fields?: HistoryShadowFieldsConfig;
171
+ }
172
+ /**
173
+ * Fallback author values written when no actor is active in `AsyncLocalStorage`
174
+ * (crons, scripts, admin UI, public routes).
175
+ */
176
+ interface HistoryFallbackActor {
177
+ userId?: string | null;
178
+ userEmail?: string | null;
179
+ }
108
180
  /**
109
181
  * Per-repo history configuration. Attached on the repository config under
110
182
  * the `history` key. All meta sub-keys must reference fields that exist on
@@ -115,6 +187,27 @@ interface HistoryConfigBase {
115
187
  enabled: boolean;
116
188
  /** Subcollection name used to store history docs. Default: "history". */
117
189
  subcollection?: string;
190
+ /**
191
+ * Automatically inject actor metadata from `AsyncLocalStorage` into the
192
+ * shadow field on repository writes (`create`, `set`, `update`, `batch`,
193
+ * `transaction`, `bulk`). Default: `true` when `enabled: true`.
194
+ */
195
+ autoInjectMeta?: boolean;
196
+ /**
197
+ * Shadow field configuration (zero Zod schema changes).
198
+ *
199
+ * - Omitted or `true` (when `meta` is absent): uses `"_historyMeta"` with default sub-fields.
200
+ * - `string`: shorthand for `{ key: "<customKey>" }`.
201
+ * - `HistoryShadowConfig`: customize both `key` and nested `fields`.
202
+ * - `false`: disable shadow metadata injection/reading.
203
+ */
204
+ shadow?: boolean | string | HistoryShadowConfig;
205
+ /**
206
+ * Fallback actor written when no actor is active in `AsyncLocalStorage` so
207
+ * previous author metadata never leaks onto subsequent writes.
208
+ * Default: `{ userId: null, userEmail: null }`.
209
+ */
210
+ fallbackActor?: HistoryFallbackActor;
118
211
  /**
119
212
  * Optional Firestore TTL configuration. When set, every written history doc
120
213
  * gets an `expiresAt` Timestamp at `now + days`. You still need to enable
@@ -219,4 +312,5 @@ interface HistoryTriggersConfig<M = Record<string, any>> {
219
312
  repos?: Partial<Record<keyof M & string, HistoryTriggerRepoOverride>>;
220
313
  }
221
314
 
222
- export type { HistoryTriggersConfig as H, TriggerOptions as T, V1HistoryDoc as V, HistoryListOptions as a, HistoryEntry as b, HistoryRawListOptions as c, V2HistoryDoc as d, HistoryOperation as e, HistoryMeta as f, HistoryConfigForModel as g, HistoryFieldChange as h, HistoryValueType as i, HistoryConfigBase as j, HistoryFirestoreTriggersDep as k, HistoryTriggerOptions as l, HistoryTriggerRepoOverride as m };
315
+ export { DEFAULT_HISTORY_SHADOW_KEY as D };
316
+ export type { HistoryTriggersConfig as H, TriggerOptions as T, V1HistoryDoc as V, HistoryListOptions as a, HistoryEntry as b, HistoryRawListOptions as c, V2HistoryDoc as d, HistoryOperation as e, HistoryMeta as f, HistoryCustomData as g, HistoryCustomInput as h, HistoryConfigForModel as i, HistoryFieldChange as j, HistoryValueType as k, HistoryConfigBase as l, HistoryFallbackActor as m, HistoryFirestoreTriggersDep as n, HistoryShadowConfig as o, HistoryShadowFieldsConfig as p, HistoryTriggerOptions as q, HistoryTriggerRepoOverride as r };
@@ -3,7 +3,7 @@ import { onDocumentWritten, DocumentOptions } from 'firebase-functions/v2/firest
3
3
  import { onRequest, HttpsOptions } from 'firebase-functions/v2/https';
4
4
  import { onMessagePublished, PubSubOptions } from 'firebase-functions/v2/pubsub';
5
5
  import { z } from 'zod';
6
- import { F as FieldPath } from './types-BFu2DpKn.cjs';
6
+ import { F as FieldPath } from './types-Dc3lX99O.cjs';
7
7
 
8
8
  /**
9
9
  * Cloud Functions v2 options forwarded to `onDocumentWritten()` for every
@@ -1,4 +1,4 @@
1
- import { g as HistoryConfigForModel } from './types--RamYGF1.cjs';
1
+ import { i as HistoryConfigForModel } from './types-D6zvWzRt.cjs';
2
2
  import * as zod from 'zod';
3
3
  import { DocumentReference, Firestore, DocumentSnapshot, WhereFilterOp } from 'firebase-admin/firestore';
4
4
 
@@ -1,4 +1,4 @@
1
- import { g as HistoryConfigForModel } from './types--RamYGF1.js';
1
+ import { i as HistoryConfigForModel } from './types-D6zvWzRt.js';
2
2
  import * as zod from 'zod';
3
3
  import { DocumentReference, Firestore, DocumentSnapshot, WhereFilterOp } from 'firebase-admin/firestore';
4
4