@lpdjs/firestore-repo-service 3.0.4 → 3.0.7
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.
- package/dist/{create-servers-2Hw0pkyz.d.ts → create-servers-C-X5e62o.d.ts} +5 -5
- package/dist/{create-servers-ASLcxpiS.d.cts → create-servers-CRTjY8sA.d.cts} +5 -5
- package/dist/history/index.d.cts +3 -2
- package/dist/history/index.d.ts +3 -2
- package/dist/index.cjs +72 -72
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -7
- package/dist/index.d.ts +10 -7
- package/dist/index.js +72 -72
- package/dist/index.js.map +1 -1
- package/dist/llms-full.txt +1 -1
- package/dist/llms.txt +1 -1
- package/dist/{openapi-CoKsSOIU.d.cts → openapi-Bp4vtku3.d.cts} +1 -1
- package/dist/{openapi-BTu_1vSc.d.ts → openapi-D6hEI2lq.d.ts} +1 -1
- package/dist/{queue-B9jCT62h.d.cts → queue-BYbd9y4U.d.cts} +1 -1
- package/dist/{queue-BWi6TBmf.d.ts → queue-I7Y1l3Wu.d.ts} +1 -1
- package/dist/read-DWUsiHcw.d.cts +164 -0
- package/dist/read-_6UEFCDw.d.ts +164 -0
- package/dist/{rules-BJMT0N0i.d.ts → rules-6LZ9KkR6.d.ts} +1 -1
- package/dist/{rules-B3b-BZLf.d.cts → rules-BB0w7PlS.d.cts} +1 -1
- package/dist/servers/admin/index.d.cts +4 -2
- package/dist/servers/admin/index.d.ts +4 -2
- package/dist/servers/crud/index.d.cts +8 -6
- package/dist/servers/crud/index.d.ts +8 -6
- package/dist/servers/index.cjs +74 -74
- package/dist/servers/index.cjs.map +1 -1
- package/dist/servers/index.d.cts +10 -8
- package/dist/servers/index.d.ts +10 -8
- package/dist/servers/index.js +74 -74
- package/dist/servers/index.js.map +1 -1
- package/dist/sync/bigquery.d.cts +4 -1
- package/dist/sync/bigquery.d.ts +4 -1
- package/dist/sync/index.cjs +51 -51
- package/dist/sync/index.cjs.map +1 -1
- package/dist/sync/index.d.cts +29 -13
- package/dist/sync/index.d.ts +29 -13
- package/dist/sync/index.js +51 -51
- package/dist/sync/index.js.map +1 -1
- package/dist/sync/meilisearch.cjs +2 -2
- package/dist/sync/meilisearch.cjs.map +1 -1
- package/dist/sync/meilisearch.d.cts +33 -11
- package/dist/sync/meilisearch.d.ts +33 -11
- package/dist/sync/meilisearch.js +2 -2
- package/dist/sync/meilisearch.js.map +1 -1
- package/dist/{types-LZ8dyfBz.d.cts → types-B48PI0V9.d.cts} +29 -6
- package/dist/{read-CTWZjxyh.d.cts → types-BwucrwN0.d.cts} +2 -162
- package/dist/{read-CTWZjxyh.d.ts → types-BwucrwN0.d.ts} +2 -162
- package/dist/{types-XRjVKN9r.d.ts → types-CXQeSrhO.d.ts} +4 -206
- package/dist/{types-B2e-T8EM.d.cts → types-D9Nm-4pg.d.cts} +4 -206
- package/dist/types-D_snvgmB.d.cts +207 -0
- package/dist/{types-BRPhmKFW.d.ts → types-DbtP8YCJ.d.ts} +29 -6
- package/dist/types-DgtfcerG.d.ts +207 -0
- package/package.json +1 -1
|
@@ -1,212 +1,10 @@
|
|
|
1
1
|
import { A as AuthUser } from './firebase-auth-Ds5P0kXT.cjs';
|
|
2
2
|
import { H as HonoServerOptions, O as OpenAPIConfig } from './types-BIZz3sxN.cjs';
|
|
3
|
-
import * as zod from 'zod';
|
|
4
3
|
import { z } from 'zod';
|
|
5
4
|
import { HttpsOptions } from 'firebase-functions/v2/https';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Extract the documentRef signature from refCb (without the db parameter)
|
|
11
|
-
* @internal
|
|
12
|
-
*/
|
|
13
|
-
type ExtractDocumentRefSignature<T> = T extends (db: Firestore, ...args: infer P) => DocumentReference ? (...args: P) => DocumentReference : never;
|
|
14
|
-
/**
|
|
15
|
-
* Extract the update signature from refCb
|
|
16
|
-
* @internal
|
|
17
|
-
*/
|
|
18
|
-
type ExtractUpdateSignature<T, TType> = T extends (db: Firestore, ...args: infer P) => DocumentReference ? (...args: [...P, Partial<TType>]) => Promise<TType> : never;
|
|
19
|
-
/**
|
|
20
|
-
* Check if a type is a plain object (not Date, Array, Function, etc.)
|
|
21
|
-
* @internal
|
|
22
|
-
*/
|
|
23
|
-
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;
|
|
24
|
-
/**
|
|
25
|
-
* Recursively generates dot-notation paths for nested plain objects only
|
|
26
|
-
* Stops at primitives, Date, Array, Function, etc.
|
|
27
|
-
* @template T - The object type to traverse
|
|
28
|
-
* @template Prefix - Current path prefix
|
|
29
|
-
* @template Depth - Recursion depth limit
|
|
30
|
-
* @example
|
|
31
|
-
* type User = { address: { city: string; zip: number }; createdAt: Date }
|
|
32
|
-
* // NestedPaths<User> = "address" | "address.city" | "address.zip" | "createdAt"
|
|
33
|
-
*/
|
|
34
|
-
type NestedPaths<T, Prefix extends string = "", Depth extends number[] = []> = Depth["length"] extends 5 ? Prefix : {
|
|
35
|
-
[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}`;
|
|
36
|
-
}[keyof T & string];
|
|
37
|
-
/**
|
|
38
|
-
* Gets the type at a dot-notation path
|
|
39
|
-
* @template T - The object type
|
|
40
|
-
* @template Path - The dot-notation path string
|
|
41
|
-
* @example
|
|
42
|
-
* type User = { address: { city: string } }
|
|
43
|
-
* // PathValue<User, "address.city"> = string
|
|
44
|
-
*/
|
|
45
|
-
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;
|
|
46
|
-
/**
|
|
47
|
-
* All possible field paths including nested paths
|
|
48
|
-
* @template T - Data model type
|
|
49
|
-
*/
|
|
50
|
-
type FieldPath<T> = NestedPaths<T>;
|
|
51
|
-
/**
|
|
52
|
-
* Type for a where condition as a tuple [field, operator, value]
|
|
53
|
-
* Supports dot-notation for nested fields with proper value typing
|
|
54
|
-
* @template T - Data model type
|
|
55
|
-
* @example
|
|
56
|
-
* // For type User = { name: string; address: { city: string } }
|
|
57
|
-
* // Valid: ["name", "==", "John"]
|
|
58
|
-
* // Valid: ["address.city", "==", "Paris"]
|
|
59
|
-
*/
|
|
60
|
-
type WhereClause<T = any> = {
|
|
61
|
-
[P in FieldPath<T>]: [P, WhereFilterOp, PathValue<T, P> | PathValue<T, P>[]];
|
|
62
|
-
}[FieldPath<T>];
|
|
63
|
-
/**
|
|
64
|
-
* Query options for filtering, sorting and paginating results
|
|
65
|
-
* @template T - Data model type
|
|
66
|
-
*/
|
|
67
|
-
interface QueryOptions<T = any> {
|
|
68
|
-
where?: WhereClause<T>[];
|
|
69
|
-
/**
|
|
70
|
-
* Simple OR: each clause is independently OR'd with the others.
|
|
71
|
-
* Under the hood, generates one Firestore query per clause and merges results.
|
|
72
|
-
* Base `where` conditions are applied to every OR branch.
|
|
73
|
-
*
|
|
74
|
-
* @example
|
|
75
|
-
* ```ts
|
|
76
|
-
* // Posts where status==draft OR status==published
|
|
77
|
-
* orWhere: [["status", "==", "draft"], ["status", "==", "published"]]
|
|
78
|
-
* ```
|
|
79
|
-
*/
|
|
80
|
-
orWhere?: WhereClause<T>[];
|
|
81
|
-
/**
|
|
82
|
-
* Advanced OR: each element is a GROUP of AND conditions.
|
|
83
|
-
* Groups are OR'd together. Base `where` conditions are applied to every group.
|
|
84
|
-
*
|
|
85
|
-
* @example
|
|
86
|
-
* ```ts
|
|
87
|
-
* // (status==published AND views>100) OR (status==draft AND userId=="abc")
|
|
88
|
-
* orWhereGroups: [
|
|
89
|
-
* [["status", "==", "published"], ["views", ">", 100]],
|
|
90
|
-
* [["status", "==", "draft"], ["userId", "==", "abc"]],
|
|
91
|
-
* ]
|
|
92
|
-
* ```
|
|
93
|
-
*/
|
|
94
|
-
orWhereGroups?: WhereClause<T>[][];
|
|
95
|
-
orderBy?: {
|
|
96
|
-
field: FieldPath<T>;
|
|
97
|
-
direction?: "asc" | "desc";
|
|
98
|
-
}[];
|
|
99
|
-
limit?: number;
|
|
100
|
-
offset?: number;
|
|
101
|
-
startAt?: DocumentSnapshot | any[];
|
|
102
|
-
startAfter?: DocumentSnapshot | any[];
|
|
103
|
-
endAt?: DocumentSnapshot | any[];
|
|
104
|
-
endBefore?: DocumentSnapshot | any[];
|
|
105
|
-
/** Fields to select (Firestore select) - reduces network transfer */
|
|
106
|
-
select?: (keyof T | FieldPath<T>)[];
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Options for get.by* methods
|
|
110
|
-
* @template T - Data model type
|
|
111
|
-
*/
|
|
112
|
-
interface GetOptions<T = any> {
|
|
113
|
-
/** Fields to select (Firestore .select) — reduces network transfer */
|
|
114
|
-
select?: (keyof T | string)[];
|
|
115
|
-
/** Return the raw DocumentSnapshot alongside data */
|
|
116
|
-
returnDoc?: boolean;
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Extracts the boolean value from a ReturnDoc parameter or options object
|
|
120
|
-
* @internal
|
|
121
|
-
*/
|
|
122
|
-
type ExtractReturnDoc<O> = O extends true ? true : O extends {
|
|
123
|
-
returnDoc: true;
|
|
124
|
-
} ? true : false;
|
|
125
|
-
/**
|
|
126
|
-
* Result type for get operations with optional document snapshot
|
|
127
|
-
* @internal
|
|
128
|
-
*/
|
|
129
|
-
type GetResult<T, O> = ExtractReturnDoc<O> extends true ? {
|
|
130
|
-
data: T;
|
|
131
|
-
doc: DocumentSnapshot;
|
|
132
|
-
} | null : T | null;
|
|
133
|
-
/**
|
|
134
|
-
* Relation configuration for a field with strict typing
|
|
135
|
-
* @template TRepoKey - Target repository name (key from mapping)
|
|
136
|
-
* @template TForeignKey - Target foreign key name
|
|
137
|
-
* @template TType - Relation type: "one" for one-to-one, "many" for one-to-many
|
|
138
|
-
* @template TTargetModel - Type of the target model (inferred from mapping)
|
|
139
|
-
*/
|
|
140
|
-
interface RelationConfig<TRepoKey extends string = string, TForeignKey extends string = string, TType extends "one" | "many" = "one" | "many", TTargetModel = any> {
|
|
141
|
-
repo: TRepoKey;
|
|
142
|
-
key: TForeignKey;
|
|
143
|
-
type: TType;
|
|
144
|
-
sourceKey?: string;
|
|
145
|
-
targetType?: TTargetModel;
|
|
146
|
-
}
|
|
147
|
-
/**
|
|
148
|
-
* Relational key mapping between repositories with strict typing
|
|
149
|
-
* Maps a field from the current model to a target repository and foreign key
|
|
150
|
-
* @template T - Current model type
|
|
151
|
-
* @template TMapping - All repositories mapping for validation
|
|
152
|
-
* @example { userId: { repo: "users", key: "docId", type: "one" } }
|
|
153
|
-
* @example { events: { repo: "events", key: "residenceId", type: "many", sourceKey: "docId" } }
|
|
154
|
-
*/
|
|
155
|
-
type RelationalKeys<T = any, TMapping = any> = {
|
|
156
|
-
[K in string]?: TMapping extends Record<string, any> ? {
|
|
157
|
-
[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> ? ({
|
|
158
|
-
repo: R;
|
|
159
|
-
key: FKeys[number];
|
|
160
|
-
type: "one";
|
|
161
|
-
sourceKey?: keyof T;
|
|
162
|
-
} | {
|
|
163
|
-
repo: R;
|
|
164
|
-
key: QKeys[number];
|
|
165
|
-
type: "many";
|
|
166
|
-
sourceKey?: keyof T;
|
|
167
|
-
}) : never;
|
|
168
|
-
}[keyof TMapping] : RelationConfig;
|
|
169
|
-
};
|
|
170
|
-
/**
|
|
171
|
-
* Configuration interface for repositories with strict literal type inference
|
|
172
|
-
* @template T - The data model type
|
|
173
|
-
* @template TForeignKeys - Foreign keys used for unique document retrieval
|
|
174
|
-
* @template TQueryKeys - Query keys used for multiple document searches
|
|
175
|
-
* @template TIsGroup - Whether this is a collection group query
|
|
176
|
-
* @template TRefCb - Callback function signature for creating document references
|
|
177
|
-
* @template TRelationalKeys - Relational keys mapping to other repositories
|
|
178
|
-
* @template TDocumentKey - The field name to store the document ID
|
|
179
|
-
* @template TPathKey - The field name to store the document path (optional)
|
|
180
|
-
* @template TCreatedKey - The field name to store the creation timestamp (optional)
|
|
181
|
-
* @template TUpdatedKey - The field name to store the update timestamp (optional)
|
|
182
|
-
*/
|
|
183
|
-
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> {
|
|
184
|
-
path: string;
|
|
185
|
-
isGroup: TIsGroup;
|
|
186
|
-
foreignKeys: TForeignKeys;
|
|
187
|
-
queryKeys: TQueryKeys;
|
|
188
|
-
documentKey: TDocumentKey;
|
|
189
|
-
pathKey?: TPathKey;
|
|
190
|
-
createdKey?: TCreatedKey;
|
|
191
|
-
updatedKey?: TUpdatedKey;
|
|
192
|
-
type: T;
|
|
193
|
-
/** Zod schema attached when using createRepositoryConfig(schema)(config). Used by the admin server. */
|
|
194
|
-
schema?: zod.ZodObject<any>;
|
|
195
|
-
refCb?: TRefCb;
|
|
196
|
-
relationalKeys?: TRelationalKeys;
|
|
197
|
-
/**
|
|
198
|
-
* Optional change-history configuration. When `enabled: true`, the
|
|
199
|
-
* `repo.history.*` read API is exposed and `createHistoryTriggers(...)`
|
|
200
|
-
* will register Firestore triggers for this repo.
|
|
201
|
-
*
|
|
202
|
-
* @see import("../history/types").HistoryConfigForModel
|
|
203
|
-
*/
|
|
204
|
-
history?: HistoryConfigForModel<T> & {
|
|
205
|
-
enabled: THistoryEnabled;
|
|
206
|
-
};
|
|
207
|
-
documentRef: TRefCb extends undefined ? TIsGroup extends true ? (...pathSegments: string[]) => DocumentReference : (docId: string) => DocumentReference : ExtractDocumentRefSignature<TRefCb>;
|
|
208
|
-
update: TRefCb extends undefined ? TIsGroup extends true ? (...args: [...string[], Partial<T>]) => Promise<T> : (docId: string, data: Partial<T>) => Promise<T> : ExtractUpdateSignature<TRefCb, T>;
|
|
209
|
-
}
|
|
5
|
+
import { H as HistoryMethods } from './read-DWUsiHcw.cjs';
|
|
6
|
+
import { DocumentSnapshot, Query, CollectionReference, WriteBatch, Transaction, DocumentReference } from 'firebase-admin/firestore';
|
|
7
|
+
import { Q as QueryOptions, R as RepositoryConfig, G as GetOptions, c as GetResult, e as ExtractReturnDoc, a as RelationConfig, F as FieldPath } from './types-D_snvgmB.cjs';
|
|
210
8
|
|
|
211
9
|
/**
|
|
212
10
|
* Pagination result with data and cursor information
|
|
@@ -1246,4 +1044,4 @@ interface QueryRequestBody {
|
|
|
1246
1044
|
withTotal?: boolean;
|
|
1247
1045
|
}
|
|
1248
1046
|
|
|
1249
|
-
export { type ApiResponse as A,
|
|
1047
|
+
export { type ApiResponse as A, type IncludeConfigTyped as B, type ConfiguredRepository as C, type DeepDiffReturn as D, type PaginationWithIncludeOptionsTyped as E, type FieldRole as F, type GenerateGetMethods as G, type PopulateOptionsTyped as H, type IndexErrorCallback as I, type ListResponseData as L, type OpenAPISpecOptions as O, type PageOptions as P, type QueryRequestBody as Q, type RepoFieldPath as R, type SecurityHeadersOptions as S, type UserFieldPath as U, 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 RelationalFieldMeta as l, type ColumnMeta as m, type FilterState as n, type SortState as o, type QueryError as p, DEFAULT_HTML_CSP as q, type PaginationOptions as r, securityHeaders as s, createPaginationIterator as t, executePaginatedQuery as u, type PaginationResult as v, type SystemBackfillFailure as w, type SystemBackfillOptions as x, type SystemBackfillResult as y, type GenerateQueryMethods as z };
|
|
@@ -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
|
|
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
|
|
240
|
+
type ExtractRepoModel<R> = R extends {
|
|
229
241
|
_modelType: infer Model;
|
|
230
|
-
} ?
|
|
242
|
+
} ? Model : R extends {
|
|
231
243
|
schema: {
|
|
232
244
|
shape: infer S;
|
|
233
245
|
};
|
|
234
|
-
} ?
|
|
246
|
+
} ? {
|
|
247
|
+
[K in keyof S]: z.infer<S[K]>;
|
|
248
|
+
} : R extends {
|
|
235
249
|
type: infer T;
|
|
236
|
-
} ?
|
|
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 };
|