@lpdjs/firestore-repo-service 2.6.4 → 2.6.6
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/README.md +2 -2
- package/dist/index.cjs +6 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +29 -11
- package/dist/index.d.ts +29 -11
- package/dist/index.js +6 -6
- package/dist/index.js.map +1 -1
- package/package.json +5 -2
package/dist/index.d.cts
CHANGED
|
@@ -110,7 +110,7 @@ declare function normalizeTimestamps<T>(value: T): T;
|
|
|
110
110
|
* }),
|
|
111
111
|
* };
|
|
112
112
|
*
|
|
113
|
-
* const repos = createRepositoryMapping(db, mapping);
|
|
113
|
+
* const repos = createRepositoryMapping(() => db, mapping);
|
|
114
114
|
* ```
|
|
115
115
|
*/
|
|
116
116
|
declare function createRepositoryConfig<TSchema extends z.ZodObject<any>>(schema: TSchema): <const TForeignKeys extends readonly (keyof z.infer<TSchema>)[], const TQueryKeys extends readonly (keyof z.infer<TSchema>)[], const TIsGroup extends boolean, const TDocumentKey extends keyof z.infer<TSchema>, const TPathKey extends keyof z.infer<TSchema> | undefined = undefined, const TCreatedKey extends keyof z.infer<TSchema> | undefined = undefined, const TUpdatedKey extends keyof z.infer<TSchema> | undefined = undefined, const THistoryEnabled extends boolean = false, TRefCb = undefined>(config: {
|
|
@@ -166,7 +166,7 @@ type ResolveRelation<TMapping, TRelationConfig> = TRelationConfig extends {
|
|
|
166
166
|
* }
|
|
167
167
|
* });
|
|
168
168
|
*
|
|
169
|
-
* const repos = createRepositoryMapping(db, mappingWithRelations);
|
|
169
|
+
* const repos = createRepositoryMapping(() => db, mappingWithRelations);
|
|
170
170
|
* ```
|
|
171
171
|
*/
|
|
172
172
|
declare function buildRepositoryRelations<TMapping extends Record<string, any>, const TRelations extends {
|
|
@@ -189,23 +189,39 @@ declare function buildRepositoryRelations<TMapping extends Record<string, any>,
|
|
|
189
189
|
* @template T - Record of repository configurations
|
|
190
190
|
*/
|
|
191
191
|
declare class RepositoryMapping<T extends Record<string, any>> {
|
|
192
|
-
private
|
|
193
|
-
private
|
|
192
|
+
private dbFactory;
|
|
193
|
+
private _db;
|
|
194
194
|
private mapping;
|
|
195
195
|
private allRepositories;
|
|
196
|
+
private initialized;
|
|
196
197
|
/**
|
|
197
198
|
* Creates a new RepositoryMapping instance
|
|
198
|
-
* @param
|
|
199
|
+
* @param dbFactory - Factory returning a Firestore instance from
|
|
200
|
+
* firebase-admin. Invoked lazily on first repository access so
|
|
201
|
+
* `getFirestore()` runs after `initializeApp()`.
|
|
199
202
|
* @param mapping - Repository configuration mapping
|
|
200
203
|
*/
|
|
201
|
-
constructor(
|
|
204
|
+
constructor(dbFactory: () => Firestore, mapping: T);
|
|
205
|
+
/**
|
|
206
|
+
* Resolve and memoize the Firestore instance. Deferred so the factory
|
|
207
|
+
* (typically `() => getFirestore()`) is only called at runtime, never
|
|
208
|
+
* during module import.
|
|
209
|
+
* @private
|
|
210
|
+
*/
|
|
211
|
+
private get db();
|
|
212
|
+
/**
|
|
213
|
+
* Build every repository once, on first access, so cross-references and
|
|
214
|
+
* circular relations are wired in a single two-pass init.
|
|
215
|
+
* @private
|
|
216
|
+
*/
|
|
217
|
+
private ensureInitialized;
|
|
202
218
|
/**
|
|
203
219
|
* Initialize all repositories in two passes to handle circular dependencies
|
|
204
220
|
* @private
|
|
205
221
|
*/
|
|
206
222
|
private initializeRepositories;
|
|
207
223
|
/**
|
|
208
|
-
* Gets a repository (
|
|
224
|
+
* Gets a repository (lazily initialized on first access)
|
|
209
225
|
* @template K - Repository key
|
|
210
226
|
* @param key - Repository identifier
|
|
211
227
|
* @returns Configured repository instance
|
|
@@ -215,17 +231,19 @@ declare class RepositoryMapping<T extends Record<string, any>> {
|
|
|
215
231
|
/**
|
|
216
232
|
* Helper function to create a RepositoryMapping instance with full typing
|
|
217
233
|
* @template T - Record of repository configurations
|
|
218
|
-
* @param
|
|
234
|
+
* @param dbFactory - Factory returning a Firestore instance from
|
|
235
|
+
* firebase-admin. Invoked lazily on first repository access, so
|
|
236
|
+
* `getFirestore()` runs after `initializeApp()` — never at import time.
|
|
219
237
|
* @param mapping - Repository configurations
|
|
220
238
|
* @returns RepositoryMapping instance with repository access via getters
|
|
221
239
|
* @example
|
|
222
240
|
* ```typescript
|
|
223
241
|
* import * as admin from 'firebase-admin';
|
|
242
|
+
* import { getFirestore } from 'firebase-admin/firestore';
|
|
224
243
|
*
|
|
225
244
|
* admin.initializeApp();
|
|
226
|
-
* const db = admin.firestore();
|
|
227
245
|
*
|
|
228
|
-
* const repos = createRepositoryMapping(
|
|
246
|
+
* const repos = createRepositoryMapping(() => getFirestore(), {
|
|
229
247
|
* users: createRepositoryConfig<UserModel>()({
|
|
230
248
|
* path: "users",
|
|
231
249
|
* isGroup: false,
|
|
@@ -239,7 +257,7 @@ declare class RepositoryMapping<T extends Record<string, any>> {
|
|
|
239
257
|
* const user = await repos.users.get.byDocId("123");
|
|
240
258
|
* ```
|
|
241
259
|
*/
|
|
242
|
-
declare function createRepositoryMapping<T extends Record<string, any>>(
|
|
260
|
+
declare function createRepositoryMapping<T extends Record<string, any>>(dbFactory: () => Firestore, mapping: T): {
|
|
243
261
|
[K in keyof T]: ConfiguredRepository<T[K]>;
|
|
244
262
|
};
|
|
245
263
|
|
package/dist/index.d.ts
CHANGED
|
@@ -110,7 +110,7 @@ declare function normalizeTimestamps<T>(value: T): T;
|
|
|
110
110
|
* }),
|
|
111
111
|
* };
|
|
112
112
|
*
|
|
113
|
-
* const repos = createRepositoryMapping(db, mapping);
|
|
113
|
+
* const repos = createRepositoryMapping(() => db, mapping);
|
|
114
114
|
* ```
|
|
115
115
|
*/
|
|
116
116
|
declare function createRepositoryConfig<TSchema extends z.ZodObject<any>>(schema: TSchema): <const TForeignKeys extends readonly (keyof z.infer<TSchema>)[], const TQueryKeys extends readonly (keyof z.infer<TSchema>)[], const TIsGroup extends boolean, const TDocumentKey extends keyof z.infer<TSchema>, const TPathKey extends keyof z.infer<TSchema> | undefined = undefined, const TCreatedKey extends keyof z.infer<TSchema> | undefined = undefined, const TUpdatedKey extends keyof z.infer<TSchema> | undefined = undefined, const THistoryEnabled extends boolean = false, TRefCb = undefined>(config: {
|
|
@@ -166,7 +166,7 @@ type ResolveRelation<TMapping, TRelationConfig> = TRelationConfig extends {
|
|
|
166
166
|
* }
|
|
167
167
|
* });
|
|
168
168
|
*
|
|
169
|
-
* const repos = createRepositoryMapping(db, mappingWithRelations);
|
|
169
|
+
* const repos = createRepositoryMapping(() => db, mappingWithRelations);
|
|
170
170
|
* ```
|
|
171
171
|
*/
|
|
172
172
|
declare function buildRepositoryRelations<TMapping extends Record<string, any>, const TRelations extends {
|
|
@@ -189,23 +189,39 @@ declare function buildRepositoryRelations<TMapping extends Record<string, any>,
|
|
|
189
189
|
* @template T - Record of repository configurations
|
|
190
190
|
*/
|
|
191
191
|
declare class RepositoryMapping<T extends Record<string, any>> {
|
|
192
|
-
private
|
|
193
|
-
private
|
|
192
|
+
private dbFactory;
|
|
193
|
+
private _db;
|
|
194
194
|
private mapping;
|
|
195
195
|
private allRepositories;
|
|
196
|
+
private initialized;
|
|
196
197
|
/**
|
|
197
198
|
* Creates a new RepositoryMapping instance
|
|
198
|
-
* @param
|
|
199
|
+
* @param dbFactory - Factory returning a Firestore instance from
|
|
200
|
+
* firebase-admin. Invoked lazily on first repository access so
|
|
201
|
+
* `getFirestore()` runs after `initializeApp()`.
|
|
199
202
|
* @param mapping - Repository configuration mapping
|
|
200
203
|
*/
|
|
201
|
-
constructor(
|
|
204
|
+
constructor(dbFactory: () => Firestore, mapping: T);
|
|
205
|
+
/**
|
|
206
|
+
* Resolve and memoize the Firestore instance. Deferred so the factory
|
|
207
|
+
* (typically `() => getFirestore()`) is only called at runtime, never
|
|
208
|
+
* during module import.
|
|
209
|
+
* @private
|
|
210
|
+
*/
|
|
211
|
+
private get db();
|
|
212
|
+
/**
|
|
213
|
+
* Build every repository once, on first access, so cross-references and
|
|
214
|
+
* circular relations are wired in a single two-pass init.
|
|
215
|
+
* @private
|
|
216
|
+
*/
|
|
217
|
+
private ensureInitialized;
|
|
202
218
|
/**
|
|
203
219
|
* Initialize all repositories in two passes to handle circular dependencies
|
|
204
220
|
* @private
|
|
205
221
|
*/
|
|
206
222
|
private initializeRepositories;
|
|
207
223
|
/**
|
|
208
|
-
* Gets a repository (
|
|
224
|
+
* Gets a repository (lazily initialized on first access)
|
|
209
225
|
* @template K - Repository key
|
|
210
226
|
* @param key - Repository identifier
|
|
211
227
|
* @returns Configured repository instance
|
|
@@ -215,17 +231,19 @@ declare class RepositoryMapping<T extends Record<string, any>> {
|
|
|
215
231
|
/**
|
|
216
232
|
* Helper function to create a RepositoryMapping instance with full typing
|
|
217
233
|
* @template T - Record of repository configurations
|
|
218
|
-
* @param
|
|
234
|
+
* @param dbFactory - Factory returning a Firestore instance from
|
|
235
|
+
* firebase-admin. Invoked lazily on first repository access, so
|
|
236
|
+
* `getFirestore()` runs after `initializeApp()` — never at import time.
|
|
219
237
|
* @param mapping - Repository configurations
|
|
220
238
|
* @returns RepositoryMapping instance with repository access via getters
|
|
221
239
|
* @example
|
|
222
240
|
* ```typescript
|
|
223
241
|
* import * as admin from 'firebase-admin';
|
|
242
|
+
* import { getFirestore } from 'firebase-admin/firestore';
|
|
224
243
|
*
|
|
225
244
|
* admin.initializeApp();
|
|
226
|
-
* const db = admin.firestore();
|
|
227
245
|
*
|
|
228
|
-
* const repos = createRepositoryMapping(
|
|
246
|
+
* const repos = createRepositoryMapping(() => getFirestore(), {
|
|
229
247
|
* users: createRepositoryConfig<UserModel>()({
|
|
230
248
|
* path: "users",
|
|
231
249
|
* isGroup: false,
|
|
@@ -239,7 +257,7 @@ declare class RepositoryMapping<T extends Record<string, any>> {
|
|
|
239
257
|
* const user = await repos.users.get.byDocId("123");
|
|
240
258
|
* ```
|
|
241
259
|
*/
|
|
242
|
-
declare function createRepositoryMapping<T extends Record<string, any>>(
|
|
260
|
+
declare function createRepositoryMapping<T extends Record<string, any>>(dbFactory: () => Firestore, mapping: T): {
|
|
243
261
|
[K in keyof T]: ConfiguredRepository<T[K]>;
|
|
244
262
|
};
|
|
245
263
|
|