@lpdjs/firestore-repo-service 3.0.2 → 3.0.5

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 (53) hide show
  1. package/dist/{create-servers-2Hw0pkyz.d.ts → create-servers-C-X5e62o.d.ts} +5 -5
  2. package/dist/{create-servers-ASLcxpiS.d.cts → create-servers-CRTjY8sA.d.cts} +5 -5
  3. package/dist/history/index.d.cts +3 -2
  4. package/dist/history/index.d.ts +3 -2
  5. package/dist/index.cjs +18 -18
  6. package/dist/index.cjs.map +1 -1
  7. package/dist/index.d.cts +10 -7
  8. package/dist/index.d.ts +10 -7
  9. package/dist/index.js +18 -18
  10. package/dist/index.js.map +1 -1
  11. package/dist/llms-full.txt +1 -1
  12. package/dist/llms.txt +1 -1
  13. package/dist/{openapi-CoKsSOIU.d.cts → openapi-Bp4vtku3.d.cts} +1 -1
  14. package/dist/{openapi-BTu_1vSc.d.ts → openapi-D6hEI2lq.d.ts} +1 -1
  15. package/dist/{queue-B9jCT62h.d.cts → queue-BYbd9y4U.d.cts} +1 -1
  16. package/dist/{queue-BWi6TBmf.d.ts → queue-I7Y1l3Wu.d.ts} +1 -1
  17. package/dist/read-DWUsiHcw.d.cts +164 -0
  18. package/dist/read-_6UEFCDw.d.ts +164 -0
  19. package/dist/{rules-BJMT0N0i.d.ts → rules-6LZ9KkR6.d.ts} +1 -1
  20. package/dist/{rules-B3b-BZLf.d.cts → rules-BB0w7PlS.d.cts} +1 -1
  21. package/dist/servers/admin/index.d.cts +4 -2
  22. package/dist/servers/admin/index.d.ts +4 -2
  23. package/dist/servers/crud/index.d.cts +8 -6
  24. package/dist/servers/crud/index.d.ts +8 -6
  25. package/dist/servers/index.cjs +30 -30
  26. package/dist/servers/index.cjs.map +1 -1
  27. package/dist/servers/index.d.cts +10 -8
  28. package/dist/servers/index.d.ts +10 -8
  29. package/dist/servers/index.js +30 -30
  30. package/dist/servers/index.js.map +1 -1
  31. package/dist/sync/bigquery.d.cts +4 -1
  32. package/dist/sync/bigquery.d.ts +4 -1
  33. package/dist/sync/index.cjs +55 -55
  34. package/dist/sync/index.cjs.map +1 -1
  35. package/dist/sync/index.d.cts +29 -13
  36. package/dist/sync/index.d.ts +29 -13
  37. package/dist/sync/index.js +55 -55
  38. package/dist/sync/index.js.map +1 -1
  39. package/dist/sync/meilisearch.cjs +2 -2
  40. package/dist/sync/meilisearch.cjs.map +1 -1
  41. package/dist/sync/meilisearch.d.cts +33 -11
  42. package/dist/sync/meilisearch.d.ts +33 -11
  43. package/dist/sync/meilisearch.js +2 -2
  44. package/dist/sync/meilisearch.js.map +1 -1
  45. package/dist/{types-LZ8dyfBz.d.cts → types-B48PI0V9.d.cts} +29 -6
  46. package/dist/{read-CTWZjxyh.d.cts → types-BwucrwN0.d.cts} +2 -162
  47. package/dist/{read-CTWZjxyh.d.ts → types-BwucrwN0.d.ts} +2 -162
  48. package/dist/{types-XRjVKN9r.d.ts → types-CXQeSrhO.d.ts} +4 -206
  49. package/dist/{types-B2e-T8EM.d.cts → types-D9Nm-4pg.d.cts} +4 -206
  50. package/dist/types-D_snvgmB.d.cts +207 -0
  51. package/dist/{types-BRPhmKFW.d.ts → types-DbtP8YCJ.d.ts} +29 -6
  52. package/dist/types-DgtfcerG.d.ts +207 -0
  53. package/package.json +1 -1
@@ -0,0 +1,207 @@
1
+ import { a as HistoryConfigForModel } from './types-BwucrwN0.cjs';
2
+ import * as zod from 'zod';
3
+ import { DocumentReference, Firestore, DocumentSnapshot, WhereFilterOp } from 'firebase-admin/firestore';
4
+
5
+ /**
6
+ * Extract the documentRef signature from refCb (without the db parameter)
7
+ * @internal
8
+ */
9
+ type ExtractDocumentRefSignature<T> = T extends (db: Firestore, ...args: infer P) => DocumentReference ? (...args: P) => DocumentReference : never;
10
+ /**
11
+ * Extract the update signature from refCb
12
+ * @internal
13
+ */
14
+ type ExtractUpdateSignature<T, TType> = T extends (db: Firestore, ...args: infer P) => DocumentReference ? (...args: [...P, Partial<TType>]) => Promise<TType> : never;
15
+ /**
16
+ * Check if a type is a plain object (not Date, Array, Function, etc.)
17
+ * @internal
18
+ */
19
+ type IsPlainObject<T> = NonNullable<T> extends Date ? false : NonNullable<T> extends Array<any> ? false : NonNullable<T> extends Function ? false : NonNullable<T> extends object ? true : false;
20
+ /**
21
+ * Recursively generates dot-notation paths for nested plain objects only
22
+ * Stops at primitives, Date, Array, Function, etc.
23
+ * @template T - The object type to traverse
24
+ * @template Prefix - Current path prefix
25
+ * @template Depth - Recursion depth limit
26
+ * @example
27
+ * type User = { address: { city: string; zip: number }; createdAt: Date }
28
+ * // NestedPaths<User> = "address" | "address.city" | "address.zip" | "createdAt"
29
+ */
30
+ type NestedPaths<T, Prefix extends string = "", Depth extends number[] = []> = Depth["length"] extends 5 ? Prefix : {
31
+ [K in keyof T & string]: IsPlainObject<T[K]> extends true ? Prefix extends "" ? K | NestedPaths<NonNullable<T[K]>, K, [...Depth, 1]> : `${Prefix}.${K}` | NestedPaths<NonNullable<T[K]>, `${Prefix}.${K}`, [...Depth, 1]> : Prefix extends "" ? K : `${Prefix}.${K}`;
32
+ }[keyof T & string];
33
+ /**
34
+ * Gets the type at a dot-notation path
35
+ * @template T - The object type
36
+ * @template Path - The dot-notation path string
37
+ * @example
38
+ * type User = { address: { city: string } }
39
+ * // PathValue<User, "address.city"> = string
40
+ */
41
+ type PathValue<T, Path extends string> = Path extends `${infer Key}.${infer Rest}` ? Key extends keyof NonNullable<T> ? PathValue<NonNullable<T>[Key], Rest> : never : Path extends keyof T ? T[Path] : Path extends keyof NonNullable<T> ? NonNullable<T>[Path] : never;
42
+ /**
43
+ * All possible field paths including nested paths
44
+ * @template T - Data model type
45
+ */
46
+ type FieldPath<T> = NestedPaths<T>;
47
+ /**
48
+ * Type for a where condition as a tuple [field, operator, value]
49
+ * Supports dot-notation for nested fields with proper value typing
50
+ * @template T - Data model type
51
+ * @example
52
+ * // For type User = { name: string; address: { city: string } }
53
+ * // Valid: ["name", "==", "John"]
54
+ * // Valid: ["address.city", "==", "Paris"]
55
+ */
56
+ type WhereClause<T = any> = {
57
+ [P in FieldPath<T>]: [P, WhereFilterOp, PathValue<T, P> | PathValue<T, P>[]];
58
+ }[FieldPath<T>];
59
+ /**
60
+ * Query options for filtering, sorting and paginating results
61
+ * @template T - Data model type
62
+ */
63
+ interface QueryOptions<T = any> {
64
+ where?: WhereClause<T>[];
65
+ /**
66
+ * Simple OR: each clause is independently OR'd with the others.
67
+ * Under the hood, generates one Firestore query per clause and merges results.
68
+ * Base `where` conditions are applied to every OR branch.
69
+ *
70
+ * @example
71
+ * ```ts
72
+ * // Posts where status==draft OR status==published
73
+ * orWhere: [["status", "==", "draft"], ["status", "==", "published"]]
74
+ * ```
75
+ */
76
+ orWhere?: WhereClause<T>[];
77
+ /**
78
+ * Advanced OR: each element is a GROUP of AND conditions.
79
+ * Groups are OR'd together. Base `where` conditions are applied to every group.
80
+ *
81
+ * @example
82
+ * ```ts
83
+ * // (status==published AND views>100) OR (status==draft AND userId=="abc")
84
+ * orWhereGroups: [
85
+ * [["status", "==", "published"], ["views", ">", 100]],
86
+ * [["status", "==", "draft"], ["userId", "==", "abc"]],
87
+ * ]
88
+ * ```
89
+ */
90
+ orWhereGroups?: WhereClause<T>[][];
91
+ orderBy?: {
92
+ field: FieldPath<T>;
93
+ direction?: "asc" | "desc";
94
+ }[];
95
+ limit?: number;
96
+ offset?: number;
97
+ startAt?: DocumentSnapshot | any[];
98
+ startAfter?: DocumentSnapshot | any[];
99
+ endAt?: DocumentSnapshot | any[];
100
+ endBefore?: DocumentSnapshot | any[];
101
+ /** Fields to select (Firestore select) - reduces network transfer */
102
+ select?: (keyof T | FieldPath<T>)[];
103
+ }
104
+ /**
105
+ * Options for get.by* methods
106
+ * @template T - Data model type
107
+ */
108
+ interface GetOptions<T = any> {
109
+ /** Fields to select (Firestore .select) — reduces network transfer */
110
+ select?: (keyof T | string)[];
111
+ /** Return the raw DocumentSnapshot alongside data */
112
+ returnDoc?: boolean;
113
+ }
114
+ /**
115
+ * Extracts the boolean value from a ReturnDoc parameter or options object
116
+ * @internal
117
+ */
118
+ type ExtractReturnDoc<O> = O extends true ? true : O extends {
119
+ returnDoc: true;
120
+ } ? true : false;
121
+ /**
122
+ * Result type for get operations with optional document snapshot
123
+ * @internal
124
+ */
125
+ type GetResult<T, O> = ExtractReturnDoc<O> extends true ? {
126
+ data: T;
127
+ doc: DocumentSnapshot;
128
+ } | null : T | null;
129
+ /**
130
+ * Relation configuration for a field with strict typing
131
+ * @template TRepoKey - Target repository name (key from mapping)
132
+ * @template TForeignKey - Target foreign key name
133
+ * @template TType - Relation type: "one" for one-to-one, "many" for one-to-many
134
+ * @template TTargetModel - Type of the target model (inferred from mapping)
135
+ */
136
+ interface RelationConfig<TRepoKey extends string = string, TForeignKey extends string = string, TType extends "one" | "many" = "one" | "many", TTargetModel = any> {
137
+ repo: TRepoKey;
138
+ key: TForeignKey;
139
+ type: TType;
140
+ sourceKey?: string;
141
+ targetType?: TTargetModel;
142
+ }
143
+ /**
144
+ * Relational key mapping between repositories with strict typing
145
+ * Maps a field from the current model to a target repository and foreign key
146
+ * @template T - Current model type
147
+ * @template TMapping - All repositories mapping for validation
148
+ * @example { userId: { repo: "users", key: "docId", type: "one" } }
149
+ * @example { events: { repo: "events", key: "residenceId", type: "many", sourceKey: "docId" } }
150
+ */
151
+ type RelationalKeys<T = any, TMapping = any> = {
152
+ [K in string]?: TMapping extends Record<string, any> ? {
153
+ [R in keyof TMapping]: TMapping[R] extends RepositoryConfig<any, infer FKeys extends readonly any[], infer QKeys extends readonly any[], any, any, any, any, any, any, any, any> ? ({
154
+ repo: R;
155
+ key: FKeys[number];
156
+ type: "one";
157
+ sourceKey?: keyof T;
158
+ } | {
159
+ repo: R;
160
+ key: QKeys[number];
161
+ type: "many";
162
+ sourceKey?: keyof T;
163
+ }) : never;
164
+ }[keyof TMapping] : RelationConfig;
165
+ };
166
+ /**
167
+ * Configuration interface for repositories with strict literal type inference
168
+ * @template T - The data model type
169
+ * @template TForeignKeys - Foreign keys used for unique document retrieval
170
+ * @template TQueryKeys - Query keys used for multiple document searches
171
+ * @template TIsGroup - Whether this is a collection group query
172
+ * @template TRefCb - Callback function signature for creating document references
173
+ * @template TRelationalKeys - Relational keys mapping to other repositories
174
+ * @template TDocumentKey - The field name to store the document ID
175
+ * @template TPathKey - The field name to store the document path (optional)
176
+ * @template TCreatedKey - The field name to store the creation timestamp (optional)
177
+ * @template TUpdatedKey - The field name to store the update timestamp (optional)
178
+ */
179
+ interface RepositoryConfig<T, TForeignKeys extends readonly (keyof T)[], TQueryKeys extends readonly (keyof T)[], TIsGroup extends boolean = boolean, TRefCb = any, TRelationalKeys = {}, TDocumentKey extends keyof T = keyof T, TPathKey extends keyof T | undefined = undefined, TCreatedKey extends keyof T | undefined = undefined, TUpdatedKey extends keyof T | undefined = undefined, THistoryEnabled extends boolean = false> {
180
+ path: string;
181
+ isGroup: TIsGroup;
182
+ foreignKeys: TForeignKeys;
183
+ queryKeys: TQueryKeys;
184
+ documentKey: TDocumentKey;
185
+ pathKey?: TPathKey;
186
+ createdKey?: TCreatedKey;
187
+ updatedKey?: TUpdatedKey;
188
+ type: T;
189
+ /** Zod schema attached when using createRepositoryConfig(schema)(config). Used by the admin server. */
190
+ schema?: zod.ZodObject<any>;
191
+ refCb?: TRefCb;
192
+ relationalKeys?: TRelationalKeys;
193
+ /**
194
+ * Optional change-history configuration. When `enabled: true`, the
195
+ * `repo.history.*` read API is exposed and `createHistoryTriggers(...)`
196
+ * will register Firestore triggers for this repo.
197
+ *
198
+ * @see import("../history/types").HistoryConfigForModel
199
+ */
200
+ history?: HistoryConfigForModel<T> & {
201
+ enabled: THistoryEnabled;
202
+ };
203
+ documentRef: TRefCb extends undefined ? TIsGroup extends true ? (...pathSegments: string[]) => DocumentReference : (docId: string) => DocumentReference : ExtractDocumentRefSignature<TRefCb>;
204
+ update: TRefCb extends undefined ? TIsGroup extends true ? (...args: [...string[], Partial<T>]) => Promise<T> : (docId: string, data: Partial<T>) => Promise<T> : ExtractUpdateSignature<TRefCb, T>;
205
+ }
206
+
207
+ export type { ExtractDocumentRefSignature as E, FieldPath as F, GetOptions as G, QueryOptions as Q, RepositoryConfig as R, WhereClause as W, RelationConfig as a, ExtractUpdateSignature as b, GetResult as c, RelationalKeys as d, ExtractReturnDoc as e };
@@ -3,6 +3,7 @@ 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
5
  import { z } from 'zod';
6
+ import { F as FieldPath } from './types-DgtfcerG.js';
6
7
 
7
8
  /**
8
9
  * Cloud Functions v2 options forwarded to `onMessagePublished()` for every
@@ -220,20 +221,42 @@ interface RepoSyncConfig<F extends string = string> {
220
221
  * When omitted or empty, the repo is synced to all configured adapters.
221
222
  */
222
223
  adapters?: string[];
224
+ /**
225
+ * Whether to flatten nested objects and stringify arrays into SQL-compatible columns.
226
+ * - `true` (default): Flattens `{ address: { city: "Paris" } }` into `address__city: "Paris"` and stringifies arrays.
227
+ * - `false`: Preserves nested objects and native arrays (ideal for Meilisearch / NoSQL search engines).
228
+ */
229
+ flat?: boolean;
230
+ /**
231
+ * Optional custom document transformation function applied after serialization.
232
+ */
233
+ transformDoc?: (doc: Record<string, unknown>) => Record<string, unknown>;
223
234
  }
235
+
224
236
  /**
225
- * Extract field names from a repo value.
237
+ * Extract the model type from a repo value.
226
238
  * Works with ConfiguredRepository (_modelType), raw config (schema.shape), or fallback (type).
227
239
  */
228
- type ExtractRepoFields<R> = R extends {
240
+ type ExtractRepoModel<R> = R extends {
229
241
  _modelType: infer Model;
230
- } ? string & keyof Model : R extends {
242
+ } ? Model : R extends {
231
243
  schema: {
232
244
  shape: infer S;
233
245
  };
234
- } ? string & keyof S : R extends {
246
+ } ? {
247
+ [K in keyof S]: z.infer<S[K]>;
248
+ } : R extends {
235
249
  type: infer T;
236
- } ? string & keyof T : string;
250
+ } ? T : Record<string, unknown>;
251
+ /**
252
+ * Extract field names from a repo value.
253
+ * Works with ConfiguredRepository (_modelType), raw config (schema.shape), or fallback (type).
254
+ */
255
+ type ExtractRepoFields<R> = string & keyof ExtractRepoModel<R>;
256
+ /**
257
+ * Extract all dot-notation field paths (including nested objects) from a repo value.
258
+ */
259
+ type ExtractRepoFieldPaths<R> = FieldPath<ExtractRepoModel<R>>;
237
260
  /** Keys of repos where `_isGroup` or `isGroup` is `true`. */
238
261
  type GroupRepoKeys<M> = {
239
262
  [K in string & keyof M]: M[K] extends {
@@ -430,4 +453,4 @@ interface FirestoreSyncConfig<M = Record<string, any>> {
430
453
  repos?: TypedRepoSyncConfigs<M>;
431
454
  }
432
455
 
433
- 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 };
456
+ export type { AdminHttpsOptions as A, ExtractRepoFieldPaths as E, 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, ExtractRepoModel as q };
@@ -0,0 +1,207 @@
1
+ import { a as HistoryConfigForModel } from './types-BwucrwN0.js';
2
+ import * as zod from 'zod';
3
+ import { DocumentReference, Firestore, DocumentSnapshot, WhereFilterOp } from 'firebase-admin/firestore';
4
+
5
+ /**
6
+ * Extract the documentRef signature from refCb (without the db parameter)
7
+ * @internal
8
+ */
9
+ type ExtractDocumentRefSignature<T> = T extends (db: Firestore, ...args: infer P) => DocumentReference ? (...args: P) => DocumentReference : never;
10
+ /**
11
+ * Extract the update signature from refCb
12
+ * @internal
13
+ */
14
+ type ExtractUpdateSignature<T, TType> = T extends (db: Firestore, ...args: infer P) => DocumentReference ? (...args: [...P, Partial<TType>]) => Promise<TType> : never;
15
+ /**
16
+ * Check if a type is a plain object (not Date, Array, Function, etc.)
17
+ * @internal
18
+ */
19
+ type IsPlainObject<T> = NonNullable<T> extends Date ? false : NonNullable<T> extends Array<any> ? false : NonNullable<T> extends Function ? false : NonNullable<T> extends object ? true : false;
20
+ /**
21
+ * Recursively generates dot-notation paths for nested plain objects only
22
+ * Stops at primitives, Date, Array, Function, etc.
23
+ * @template T - The object type to traverse
24
+ * @template Prefix - Current path prefix
25
+ * @template Depth - Recursion depth limit
26
+ * @example
27
+ * type User = { address: { city: string; zip: number }; createdAt: Date }
28
+ * // NestedPaths<User> = "address" | "address.city" | "address.zip" | "createdAt"
29
+ */
30
+ type NestedPaths<T, Prefix extends string = "", Depth extends number[] = []> = Depth["length"] extends 5 ? Prefix : {
31
+ [K in keyof T & string]: IsPlainObject<T[K]> extends true ? Prefix extends "" ? K | NestedPaths<NonNullable<T[K]>, K, [...Depth, 1]> : `${Prefix}.${K}` | NestedPaths<NonNullable<T[K]>, `${Prefix}.${K}`, [...Depth, 1]> : Prefix extends "" ? K : `${Prefix}.${K}`;
32
+ }[keyof T & string];
33
+ /**
34
+ * Gets the type at a dot-notation path
35
+ * @template T - The object type
36
+ * @template Path - The dot-notation path string
37
+ * @example
38
+ * type User = { address: { city: string } }
39
+ * // PathValue<User, "address.city"> = string
40
+ */
41
+ type PathValue<T, Path extends string> = Path extends `${infer Key}.${infer Rest}` ? Key extends keyof NonNullable<T> ? PathValue<NonNullable<T>[Key], Rest> : never : Path extends keyof T ? T[Path] : Path extends keyof NonNullable<T> ? NonNullable<T>[Path] : never;
42
+ /**
43
+ * All possible field paths including nested paths
44
+ * @template T - Data model type
45
+ */
46
+ type FieldPath<T> = NestedPaths<T>;
47
+ /**
48
+ * Type for a where condition as a tuple [field, operator, value]
49
+ * Supports dot-notation for nested fields with proper value typing
50
+ * @template T - Data model type
51
+ * @example
52
+ * // For type User = { name: string; address: { city: string } }
53
+ * // Valid: ["name", "==", "John"]
54
+ * // Valid: ["address.city", "==", "Paris"]
55
+ */
56
+ type WhereClause<T = any> = {
57
+ [P in FieldPath<T>]: [P, WhereFilterOp, PathValue<T, P> | PathValue<T, P>[]];
58
+ }[FieldPath<T>];
59
+ /**
60
+ * Query options for filtering, sorting and paginating results
61
+ * @template T - Data model type
62
+ */
63
+ interface QueryOptions<T = any> {
64
+ where?: WhereClause<T>[];
65
+ /**
66
+ * Simple OR: each clause is independently OR'd with the others.
67
+ * Under the hood, generates one Firestore query per clause and merges results.
68
+ * Base `where` conditions are applied to every OR branch.
69
+ *
70
+ * @example
71
+ * ```ts
72
+ * // Posts where status==draft OR status==published
73
+ * orWhere: [["status", "==", "draft"], ["status", "==", "published"]]
74
+ * ```
75
+ */
76
+ orWhere?: WhereClause<T>[];
77
+ /**
78
+ * Advanced OR: each element is a GROUP of AND conditions.
79
+ * Groups are OR'd together. Base `where` conditions are applied to every group.
80
+ *
81
+ * @example
82
+ * ```ts
83
+ * // (status==published AND views>100) OR (status==draft AND userId=="abc")
84
+ * orWhereGroups: [
85
+ * [["status", "==", "published"], ["views", ">", 100]],
86
+ * [["status", "==", "draft"], ["userId", "==", "abc"]],
87
+ * ]
88
+ * ```
89
+ */
90
+ orWhereGroups?: WhereClause<T>[][];
91
+ orderBy?: {
92
+ field: FieldPath<T>;
93
+ direction?: "asc" | "desc";
94
+ }[];
95
+ limit?: number;
96
+ offset?: number;
97
+ startAt?: DocumentSnapshot | any[];
98
+ startAfter?: DocumentSnapshot | any[];
99
+ endAt?: DocumentSnapshot | any[];
100
+ endBefore?: DocumentSnapshot | any[];
101
+ /** Fields to select (Firestore select) - reduces network transfer */
102
+ select?: (keyof T | FieldPath<T>)[];
103
+ }
104
+ /**
105
+ * Options for get.by* methods
106
+ * @template T - Data model type
107
+ */
108
+ interface GetOptions<T = any> {
109
+ /** Fields to select (Firestore .select) — reduces network transfer */
110
+ select?: (keyof T | string)[];
111
+ /** Return the raw DocumentSnapshot alongside data */
112
+ returnDoc?: boolean;
113
+ }
114
+ /**
115
+ * Extracts the boolean value from a ReturnDoc parameter or options object
116
+ * @internal
117
+ */
118
+ type ExtractReturnDoc<O> = O extends true ? true : O extends {
119
+ returnDoc: true;
120
+ } ? true : false;
121
+ /**
122
+ * Result type for get operations with optional document snapshot
123
+ * @internal
124
+ */
125
+ type GetResult<T, O> = ExtractReturnDoc<O> extends true ? {
126
+ data: T;
127
+ doc: DocumentSnapshot;
128
+ } | null : T | null;
129
+ /**
130
+ * Relation configuration for a field with strict typing
131
+ * @template TRepoKey - Target repository name (key from mapping)
132
+ * @template TForeignKey - Target foreign key name
133
+ * @template TType - Relation type: "one" for one-to-one, "many" for one-to-many
134
+ * @template TTargetModel - Type of the target model (inferred from mapping)
135
+ */
136
+ interface RelationConfig<TRepoKey extends string = string, TForeignKey extends string = string, TType extends "one" | "many" = "one" | "many", TTargetModel = any> {
137
+ repo: TRepoKey;
138
+ key: TForeignKey;
139
+ type: TType;
140
+ sourceKey?: string;
141
+ targetType?: TTargetModel;
142
+ }
143
+ /**
144
+ * Relational key mapping between repositories with strict typing
145
+ * Maps a field from the current model to a target repository and foreign key
146
+ * @template T - Current model type
147
+ * @template TMapping - All repositories mapping for validation
148
+ * @example { userId: { repo: "users", key: "docId", type: "one" } }
149
+ * @example { events: { repo: "events", key: "residenceId", type: "many", sourceKey: "docId" } }
150
+ */
151
+ type RelationalKeys<T = any, TMapping = any> = {
152
+ [K in string]?: TMapping extends Record<string, any> ? {
153
+ [R in keyof TMapping]: TMapping[R] extends RepositoryConfig<any, infer FKeys extends readonly any[], infer QKeys extends readonly any[], any, any, any, any, any, any, any, any> ? ({
154
+ repo: R;
155
+ key: FKeys[number];
156
+ type: "one";
157
+ sourceKey?: keyof T;
158
+ } | {
159
+ repo: R;
160
+ key: QKeys[number];
161
+ type: "many";
162
+ sourceKey?: keyof T;
163
+ }) : never;
164
+ }[keyof TMapping] : RelationConfig;
165
+ };
166
+ /**
167
+ * Configuration interface for repositories with strict literal type inference
168
+ * @template T - The data model type
169
+ * @template TForeignKeys - Foreign keys used for unique document retrieval
170
+ * @template TQueryKeys - Query keys used for multiple document searches
171
+ * @template TIsGroup - Whether this is a collection group query
172
+ * @template TRefCb - Callback function signature for creating document references
173
+ * @template TRelationalKeys - Relational keys mapping to other repositories
174
+ * @template TDocumentKey - The field name to store the document ID
175
+ * @template TPathKey - The field name to store the document path (optional)
176
+ * @template TCreatedKey - The field name to store the creation timestamp (optional)
177
+ * @template TUpdatedKey - The field name to store the update timestamp (optional)
178
+ */
179
+ interface RepositoryConfig<T, TForeignKeys extends readonly (keyof T)[], TQueryKeys extends readonly (keyof T)[], TIsGroup extends boolean = boolean, TRefCb = any, TRelationalKeys = {}, TDocumentKey extends keyof T = keyof T, TPathKey extends keyof T | undefined = undefined, TCreatedKey extends keyof T | undefined = undefined, TUpdatedKey extends keyof T | undefined = undefined, THistoryEnabled extends boolean = false> {
180
+ path: string;
181
+ isGroup: TIsGroup;
182
+ foreignKeys: TForeignKeys;
183
+ queryKeys: TQueryKeys;
184
+ documentKey: TDocumentKey;
185
+ pathKey?: TPathKey;
186
+ createdKey?: TCreatedKey;
187
+ updatedKey?: TUpdatedKey;
188
+ type: T;
189
+ /** Zod schema attached when using createRepositoryConfig(schema)(config). Used by the admin server. */
190
+ schema?: zod.ZodObject<any>;
191
+ refCb?: TRefCb;
192
+ relationalKeys?: TRelationalKeys;
193
+ /**
194
+ * Optional change-history configuration. When `enabled: true`, the
195
+ * `repo.history.*` read API is exposed and `createHistoryTriggers(...)`
196
+ * will register Firestore triggers for this repo.
197
+ *
198
+ * @see import("../history/types").HistoryConfigForModel
199
+ */
200
+ history?: HistoryConfigForModel<T> & {
201
+ enabled: THistoryEnabled;
202
+ };
203
+ documentRef: TRefCb extends undefined ? TIsGroup extends true ? (...pathSegments: string[]) => DocumentReference : (docId: string) => DocumentReference : ExtractDocumentRefSignature<TRefCb>;
204
+ update: TRefCb extends undefined ? TIsGroup extends true ? (...args: [...string[], Partial<T>]) => Promise<T> : (docId: string, data: Partial<T>) => Promise<T> : ExtractUpdateSignature<TRefCb, T>;
205
+ }
206
+
207
+ export type { ExtractDocumentRefSignature as E, FieldPath as F, GetOptions as G, QueryOptions as Q, RepositoryConfig as R, WhereClause as W, RelationConfig as a, ExtractUpdateSignature as b, GetResult as c, RelationalKeys as d, ExtractReturnDoc as e };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lpdjs/firestore-repo-service",
3
- "version": "3.0.2",
3
+ "version": "3.0.5",
4
4
  "workspaces": [
5
5
  "test/functions"
6
6
  ],