@umituz/react-native-ai-generation-content 1.66.0 → 1.66.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umituz/react-native-ai-generation-content",
3
- "version": "1.66.0",
3
+ "version": "1.66.3",
4
4
  "description": "Provider-agnostic AI generation orchestration for React Native with result preview components",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
@@ -70,7 +70,7 @@
70
70
  "@typescript-eslint/eslint-plugin": "^8.54.0",
71
71
  "@typescript-eslint/parser": "^8.54.0",
72
72
  "@umituz/react-native-design-system": "^4.23.79",
73
- "@umituz/react-native-firebase": "^1.13.87",
73
+ "@umituz/react-native-firebase": "^1.13.161",
74
74
  "@umituz/react-native-subscription": "^2.27.23",
75
75
  "eslint": "^9.39.2",
76
76
  "eslint-plugin-react": "^7.37.5",
@@ -1,10 +1,16 @@
1
- import { type FirestorePathResolver } from "@umituz/react-native-firebase";
1
+ import type { CollectionReference, DocumentReference, DocumentData } from "firebase/firestore";
2
2
  import type { DocumentMapper } from "../../domain/value-objects/CreationsConfig";
3
3
  import type { Creation } from "../../domain/entities/Creation";
4
4
  import type { CreationsSubscriptionCallback, UnsubscribeFunction } from "../../domain/repositories/ICreationsRepository";
5
5
  import { CreationsQuery } from "./CreationsQuery";
6
6
  import { CreationsSubscription } from "./CreationsSubscription";
7
7
 
8
+ /**
9
+ * Path resolver functions from BaseRepository
10
+ */
11
+ export type GetUserCollection = (userId: string) => CollectionReference<DocumentData> | null;
12
+ export type GetDocRef = (userId: string, documentId: string) => DocumentReference<DocumentData> | null;
13
+
8
14
  /**
9
15
  * CreationsFetcher
10
16
  * Orchestrates read operations for creations
@@ -19,11 +25,12 @@ export class CreationsFetcher {
19
25
  private readonly subscription: CreationsSubscription;
20
26
 
21
27
  constructor(
22
- pathResolver: FirestorePathResolver,
28
+ getUserCollection: GetUserCollection,
29
+ getDocRef: GetDocRef,
23
30
  documentMapper: DocumentMapper,
24
31
  ) {
25
- this.query = new CreationsQuery(pathResolver, documentMapper);
26
- this.subscription = new CreationsSubscription(pathResolver, documentMapper);
32
+ this.query = new CreationsQuery(getUserCollection, getDocRef, documentMapper);
33
+ this.subscription = new CreationsSubscription(getUserCollection, getDocRef, documentMapper);
27
34
  }
28
35
 
29
36
  /**
@@ -5,7 +5,7 @@
5
5
  */
6
6
 
7
7
  import { getDocs, getDoc, query, orderBy, where } from "firebase/firestore";
8
- import { type FirestorePathResolver } from "@umituz/react-native-firebase";
8
+ import type { GetUserCollection, GetDocRef } from "./CreationsFetcher";
9
9
  import type { DocumentMapper } from "../../domain/value-objects/CreationsConfig";
10
10
  import type { Creation, CreationDocument } from "../../domain/entities/Creation";
11
11
  import { CREATION_FIELDS } from "../../domain/constants";
@@ -17,7 +17,8 @@ declare const __DEV__: boolean;
17
17
  */
18
18
  export class CreationsQuery {
19
19
  constructor(
20
- private readonly pathResolver: FirestorePathResolver,
20
+ private readonly getUserCollection: GetUserCollection,
21
+ private readonly getDocRef: GetDocRef,
21
22
  private readonly documentMapper: DocumentMapper,
22
23
  ) { }
23
24
 
@@ -26,7 +27,7 @@ export class CreationsQuery {
26
27
  * Optimized query: Server-side filtering for non-deleted items
27
28
  */
28
29
  async getAll(userId: string): Promise<Creation[]> {
29
- const userCollection = this.pathResolver.getUserCollection(userId);
30
+ const userCollection = this.getUserCollection(userId);
30
31
  if (!userCollection) return [];
31
32
 
32
33
  try {
@@ -62,7 +63,7 @@ export class CreationsQuery {
62
63
  * Get a single creation by ID
63
64
  */
64
65
  async getById(userId: string, id: string): Promise<Creation | null> {
65
- const docRef = this.pathResolver.getDocRef(userId, id);
66
+ const docRef = this.getDocRef(userId, id);
66
67
  if (!docRef) return null;
67
68
 
68
69
  try {
@@ -1,5 +1,5 @@
1
1
 
2
- import { BaseRepository, FirestorePathResolver } from "@umituz/react-native-firebase";
2
+ import { BaseRepository } from "@umituz/react-native-firebase";
3
3
  import type {
4
4
  ICreationsRepository,
5
5
  CreationsSubscriptionCallback,
@@ -22,10 +22,9 @@ export interface RepositoryOptions {
22
22
  /**
23
23
  * Creations Repository Implementation
24
24
  * Delegates to specialized classes for different responsibilities
25
- *
25
+ *
26
26
  * Architecture:
27
- * - Extends BaseRepository for centralized database access
28
- * - Uses FirestorePathResolver for path resolution
27
+ * - Extends BaseRepository for database access and path resolution
29
28
  * - Uses CreationsFetcher for read operations
30
29
  * - Uses CreationsWriter for write operations
31
30
  * - Standard path: users/{userId}/{collectionName}
@@ -33,7 +32,6 @@ export interface RepositoryOptions {
33
32
  export class CreationsRepository
34
33
  extends BaseRepository
35
34
  implements ICreationsRepository {
36
- private readonly pathResolver: FirestorePathResolver;
37
35
  private readonly fetcher: CreationsFetcher;
38
36
  private readonly writer: CreationsWriter;
39
37
 
@@ -41,14 +39,20 @@ export class CreationsRepository
41
39
  collectionName: string,
42
40
  options?: RepositoryOptions,
43
41
  ) {
44
- super();
42
+ super(collectionName);
45
43
 
46
44
  const documentMapper = options?.documentMapper ?? mapDocumentToCreation;
47
45
 
48
- // Initialize with Firestore database instance from BaseRepository
49
- this.pathResolver = new FirestorePathResolver(collectionName, this.getDb());
50
- this.fetcher = new CreationsFetcher(this.pathResolver, documentMapper);
51
- this.writer = new CreationsWriter(this.pathResolver);
46
+ // Pass BaseRepository methods directly to dependencies
47
+ this.fetcher = new CreationsFetcher(
48
+ (userId) => this.getUserCollection(userId),
49
+ (userId, docId) => this.getDocRef(userId, docId),
50
+ documentMapper
51
+ );
52
+ this.writer = new CreationsWriter(
53
+ (userId) => this.getUserCollection(userId),
54
+ (userId, docId) => this.getDocRef(userId, docId)
55
+ );
52
56
  }
53
57
 
54
58
  async getAll(userId: string): Promise<Creation[]> {
@@ -5,9 +5,9 @@
5
5
  */
6
6
 
7
7
  import { query, orderBy, onSnapshot, where } from "firebase/firestore";
8
- import { type FirestorePathResolver } from "@umituz/react-native-firebase";
8
+ import type { GetUserCollection } from "./CreationsFetcher";
9
9
  import type { DocumentMapper } from "../../domain/value-objects/CreationsConfig";
10
- import type { Creation, CreationDocument } from "../../domain/entities/Creation";
10
+ import type { CreationDocument } from "../../domain/entities/Creation";
11
11
  import type { CreationsSubscriptionCallback, UnsubscribeFunction } from "../../domain/repositories/ICreationsRepository";
12
12
  import { CREATION_FIELDS } from "../../domain/constants";
13
13
 
@@ -19,7 +19,8 @@ declare const __DEV__: boolean;
19
19
  */
20
20
  export class CreationsSubscription {
21
21
  constructor(
22
- private readonly pathResolver: FirestorePathResolver,
22
+ private readonly getUserCollection: GetUserCollection,
23
+ _getDocRef: unknown, // Not used in subscription, but accepted for consistent interface
23
24
  private readonly documentMapper: DocumentMapper,
24
25
  ) { }
25
26
 
@@ -28,7 +29,7 @@ export class CreationsSubscription {
28
29
  onData: CreationsSubscriptionCallback,
29
30
  onError?: (error: Error) => void,
30
31
  ): UnsubscribeFunction {
31
- const userCollection = this.pathResolver.getUserCollection(userId);
32
+ const userCollection = this.getUserCollection(userId);
32
33
 
33
34
  if (!userCollection) {
34
35
  const error = new Error(`[CreationsSubscription] Invalid user collection: ${userId}`);
@@ -3,7 +3,7 @@
3
3
  * Main class that orchestrates all creation write operations
4
4
  */
5
5
 
6
- import { type FirestorePathResolver } from "@umituz/react-native-firebase";
6
+ import type { GetUserCollection, GetDocRef } from "./CreationsFetcher";
7
7
  import type { Creation } from "../../domain/entities/Creation";
8
8
  import * as operations from "./creations-operations";
9
9
  import * as stateOperations from "./creations-state-operations";
@@ -12,37 +12,40 @@ import * as stateOperations from "./creations-state-operations";
12
12
  * Handles write operations for creations
13
13
  */
14
14
  export class CreationsWriter {
15
- constructor(private readonly pathResolver: FirestorePathResolver) {}
15
+ constructor(
16
+ private readonly getUserCollection: GetUserCollection,
17
+ private readonly getDocRef: GetDocRef,
18
+ ) {}
16
19
 
17
20
  async create(userId: string, creation: Creation): Promise<void> {
18
- return operations.createCreation(this.pathResolver, userId, creation);
21
+ return operations.createCreation(this.getUserCollection, this.getDocRef, userId, creation);
19
22
  }
20
23
 
21
24
  async update(userId: string, id: string, updates: Partial<Creation>): Promise<boolean> {
22
- return operations.updateCreation(this.pathResolver, userId, id, updates);
25
+ return operations.updateCreation(this.getDocRef, userId, id, updates);
23
26
  }
24
27
 
25
28
  async delete(userId: string, creationId: string): Promise<boolean> {
26
- return operations.deleteCreation(this.pathResolver, userId, creationId);
29
+ return operations.deleteCreation(this.getDocRef, userId, creationId);
27
30
  }
28
31
 
29
32
  async hardDelete(userId: string, creationId: string): Promise<boolean> {
30
- return operations.hardDeleteCreation(this.pathResolver, userId, creationId);
33
+ return operations.hardDeleteCreation(this.getDocRef, userId, creationId);
31
34
  }
32
35
 
33
36
  async restore(userId: string, creationId: string): Promise<boolean> {
34
- return operations.restoreCreation(this.pathResolver, userId, creationId);
37
+ return operations.restoreCreation(this.getDocRef, userId, creationId);
35
38
  }
36
39
 
37
40
  async updateShared(userId: string, creationId: string, isShared: boolean): Promise<boolean> {
38
- return stateOperations.updateCreationShared(this.pathResolver, userId, creationId, isShared);
41
+ return stateOperations.updateCreationShared(this.getDocRef, userId, creationId, isShared);
39
42
  }
40
43
 
41
44
  async updateFavorite(userId: string, creationId: string, isFavorite: boolean): Promise<boolean> {
42
- return stateOperations.updateCreationFavorite(this.pathResolver, userId, creationId, isFavorite);
45
+ return stateOperations.updateCreationFavorite(this.getDocRef, userId, creationId, isFavorite);
43
46
  }
44
47
 
45
48
  async rate(userId: string, creationId: string, rating: number, description?: string): Promise<boolean> {
46
- return stateOperations.rateCreation(this.pathResolver, userId, creationId, rating, description);
49
+ return stateOperations.rateCreation(this.getDocRef, userId, creationId, rating, description);
47
50
  }
48
51
  }
@@ -3,18 +3,19 @@
3
3
  */
4
4
 
5
5
  import { setDoc } from "firebase/firestore";
6
- import { type FirestorePathResolver } from "@umituz/react-native-firebase";
6
+ import type { GetUserCollection, GetDocRef } from "./CreationsFetcher";
7
7
  import type { Creation, CreationDocument } from "../../domain/entities/Creation";
8
8
 
9
9
  /**
10
10
  * Creates a new creation document
11
11
  */
12
12
  export async function createCreation(
13
- pathResolver: FirestorePathResolver,
13
+ _getUserCollection: GetUserCollection,
14
+ getDocRef: GetDocRef,
14
15
  userId: string,
15
16
  creation: Creation
16
17
  ): Promise<void> {
17
- const docRef = pathResolver.getDocRef(userId, creation.id);
18
+ const docRef = getDocRef(userId, creation.id);
18
19
  if (!docRef) throw new Error("Firestore not initialized");
19
20
 
20
21
  const data: CreationDocument = {
@@ -4,18 +4,18 @@
4
4
  */
5
5
 
6
6
  import { updateDoc, deleteDoc } from "firebase/firestore";
7
- import { type FirestorePathResolver } from "@umituz/react-native-firebase";
7
+ import type { GetDocRef } from "./CreationsFetcher";
8
8
  import { logOperationError, logOperationSuccess, logInvalidRef } from "./creation-error-handler.util";
9
9
 
10
10
  /**
11
11
  * Soft deletes a creation by setting deletedAt timestamp
12
12
  */
13
13
  export async function deleteCreation(
14
- pathResolver: FirestorePathResolver,
14
+ getDocRef: GetDocRef,
15
15
  userId: string,
16
16
  creationId: string
17
17
  ): Promise<boolean> {
18
- const docRef = pathResolver.getDocRef(userId, creationId);
18
+ const docRef = getDocRef(userId, creationId);
19
19
  const context = { userId, creationId };
20
20
 
21
21
  if (!docRef) {
@@ -37,11 +37,11 @@ export async function deleteCreation(
37
37
  * Permanently deletes a creation from Firestore
38
38
  */
39
39
  export async function hardDeleteCreation(
40
- pathResolver: FirestorePathResolver,
40
+ getDocRef: GetDocRef,
41
41
  userId: string,
42
42
  creationId: string
43
43
  ): Promise<boolean> {
44
- const docRef = pathResolver.getDocRef(userId, creationId);
44
+ const docRef = getDocRef(userId, creationId);
45
45
  const context = { userId, creationId };
46
46
 
47
47
  if (!docRef) {
@@ -63,11 +63,11 @@ export async function hardDeleteCreation(
63
63
  * Restores a soft-deleted creation by clearing deletedAt
64
64
  */
65
65
  export async function restoreCreation(
66
- pathResolver: FirestorePathResolver,
66
+ getDocRef: GetDocRef,
67
67
  userId: string,
68
68
  creationId: string
69
69
  ): Promise<boolean> {
70
- const docRef = pathResolver.getDocRef(userId, creationId);
70
+ const docRef = getDocRef(userId, creationId);
71
71
  const context = { userId, creationId };
72
72
 
73
73
  if (!docRef) {
@@ -3,7 +3,7 @@
3
3
  */
4
4
 
5
5
  import { updateDoc } from "firebase/firestore";
6
- import { type FirestorePathResolver } from "@umituz/react-native-firebase";
6
+ import type { GetDocRef } from "./CreationsFetcher";
7
7
  import type { Creation } from "../../domain/entities/Creation";
8
8
  import { CREATION_FIELDS, type CreationFieldName } from "../../domain/constants";
9
9
 
@@ -34,12 +34,12 @@ export const UPDATABLE_FIELDS: ReadonlyArray<CreationFieldName> = [
34
34
  * Updates a creation document
35
35
  */
36
36
  export async function updateCreation(
37
- pathResolver: FirestorePathResolver,
37
+ getDocRef: GetDocRef,
38
38
  userId: string,
39
39
  id: string,
40
40
  updates: Partial<Creation>
41
41
  ): Promise<boolean> {
42
- const docRef = pathResolver.getDocRef(userId, id);
42
+ const docRef = getDocRef(userId, id);
43
43
 
44
44
  if (!docRef) {
45
45
  throw new Error(
@@ -4,19 +4,19 @@
4
4
  */
5
5
 
6
6
  import { updateDoc } from "firebase/firestore";
7
- import { type FirestorePathResolver } from "@umituz/react-native-firebase";
7
+ import type { GetDocRef } from "./CreationsFetcher";
8
8
  import { submitFeedback } from "@umituz/react-native-subscription";
9
9
 
10
10
  /**
11
11
  * Updates the shared status of a creation
12
12
  */
13
13
  export async function updateCreationShared(
14
- pathResolver: FirestorePathResolver,
14
+ getDocRef: GetDocRef,
15
15
  userId: string,
16
16
  creationId: string,
17
17
  isShared: boolean
18
18
  ): Promise<boolean> {
19
- const docRef = pathResolver.getDocRef(userId, creationId);
19
+ const docRef = getDocRef(userId, creationId);
20
20
  if (!docRef) return false;
21
21
 
22
22
  try {
@@ -31,12 +31,12 @@ export async function updateCreationShared(
31
31
  * Updates the favorite status of a creation
32
32
  */
33
33
  export async function updateCreationFavorite(
34
- pathResolver: FirestorePathResolver,
34
+ getDocRef: GetDocRef,
35
35
  userId: string,
36
36
  creationId: string,
37
37
  isFavorite: boolean
38
38
  ): Promise<boolean> {
39
- const docRef = pathResolver.getDocRef(userId, creationId);
39
+ const docRef = getDocRef(userId, creationId);
40
40
  if (!docRef) return false;
41
41
 
42
42
  try {
@@ -51,13 +51,13 @@ export async function updateCreationFavorite(
51
51
  * Rates a creation and optionally submits feedback
52
52
  */
53
53
  export async function rateCreation(
54
- pathResolver: FirestorePathResolver,
54
+ getDocRef: GetDocRef,
55
55
  userId: string,
56
56
  creationId: string,
57
57
  rating: number,
58
58
  description?: string
59
59
  ): Promise<boolean> {
60
- const docRef = pathResolver.getDocRef(userId, creationId);
60
+ const docRef = getDocRef(userId, creationId);
61
61
  if (!docRef) return false;
62
62
 
63
63
  try {
@@ -5,7 +5,7 @@
5
5
  * Uses provider registry internally - no need to pass FAL functions
6
6
  */
7
7
 
8
- import { useEffect, useRef, useCallback, useMemo } from "react";
8
+ import { useEffect, useRef, useMemo } from "react";
9
9
  import { providerRegistry } from "../../../../infrastructure/services/provider-registry.service";
10
10
  import { QUEUE_STATUS, CREATION_STATUS } from "../../../../domain/constants/queue-status.constants";
11
11
  import { DEFAULT_POLL_INTERVAL_MS } from "../../../../infrastructure/constants/polling.constants";
@@ -50,7 +50,7 @@ export function useProcessingJobsPoller(
50
50
  );
51
51
 
52
52
  // Use ref for stable function reference to prevent effect re-runs
53
- const pollJobRef = useRef<(creation: Creation) => Promise<void>>();
53
+ const pollJobRef = useRef<((creation: Creation) => Promise<void>) | undefined>(undefined);
54
54
 
55
55
  pollJobRef.current = async (creation: Creation) => {
56
56
  if (!userId || !creation.requestId || !creation.model) return;