@umituz/react-native-ai-generation-content 1.65.0 → 1.65.1
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 +1 -1
- package/src/domains/creations/infrastructure/repositories/creation-create.operations.ts +40 -0
- package/src/domains/creations/infrastructure/repositories/creation-delete.operations.ts +63 -0
- package/src/domains/creations/infrastructure/repositories/creation-update.operations.ts +77 -0
- package/src/domains/creations/infrastructure/repositories/creations-operations.ts +9 -210
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/react-native-ai-generation-content",
|
|
3
|
-
"version": "1.65.
|
|
3
|
+
"version": "1.65.1",
|
|
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",
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creation Create Operations
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { setDoc } from "firebase/firestore";
|
|
6
|
+
import { type FirestorePathResolver } from "@umituz/react-native-firebase";
|
|
7
|
+
import type { Creation, CreationDocument } from "../../domain/entities/Creation";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Creates a new creation document
|
|
11
|
+
*/
|
|
12
|
+
export async function createCreation(
|
|
13
|
+
pathResolver: FirestorePathResolver,
|
|
14
|
+
userId: string,
|
|
15
|
+
creation: Creation
|
|
16
|
+
): Promise<void> {
|
|
17
|
+
const docRef = pathResolver.getDocRef(userId, creation.id);
|
|
18
|
+
if (!docRef) throw new Error("Firestore not initialized");
|
|
19
|
+
|
|
20
|
+
const data: CreationDocument = {
|
|
21
|
+
type: creation.type,
|
|
22
|
+
uri: creation.uri,
|
|
23
|
+
createdAt: creation.createdAt,
|
|
24
|
+
metadata: creation.metadata || {},
|
|
25
|
+
isShared: creation.isShared || false,
|
|
26
|
+
isFavorite: creation.isFavorite || false,
|
|
27
|
+
...(creation.status !== undefined && { status: creation.status }),
|
|
28
|
+
...(creation.output !== undefined && { output: creation.output }),
|
|
29
|
+
...(creation.prompt !== undefined && { prompt: creation.prompt }),
|
|
30
|
+
...(creation.requestId !== undefined && { requestId: creation.requestId }),
|
|
31
|
+
...(creation.model !== undefined && { model: creation.model }),
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
try {
|
|
35
|
+
await setDoc(docRef, data);
|
|
36
|
+
} catch (error) {
|
|
37
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
38
|
+
throw new Error(`Failed to create creation ${creation.id}: ${errorMessage}`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creation Delete Operations
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { updateDoc, deleteDoc } from "firebase/firestore";
|
|
6
|
+
import { type FirestorePathResolver } from "@umituz/react-native-firebase";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Soft deletes a creation
|
|
10
|
+
*/
|
|
11
|
+
export async function deleteCreation(
|
|
12
|
+
pathResolver: FirestorePathResolver,
|
|
13
|
+
userId: string,
|
|
14
|
+
creationId: string
|
|
15
|
+
): Promise<boolean> {
|
|
16
|
+
const docRef = pathResolver.getDocRef(userId, creationId);
|
|
17
|
+
if (!docRef) return false;
|
|
18
|
+
|
|
19
|
+
try {
|
|
20
|
+
await updateDoc(docRef, { deletedAt: new Date() });
|
|
21
|
+
return true;
|
|
22
|
+
} catch {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Hard deletes a creation
|
|
29
|
+
*/
|
|
30
|
+
export async function hardDeleteCreation(
|
|
31
|
+
pathResolver: FirestorePathResolver,
|
|
32
|
+
userId: string,
|
|
33
|
+
creationId: string
|
|
34
|
+
): Promise<boolean> {
|
|
35
|
+
const docRef = pathResolver.getDocRef(userId, creationId);
|
|
36
|
+
if (!docRef) return false;
|
|
37
|
+
|
|
38
|
+
try {
|
|
39
|
+
await deleteDoc(docRef);
|
|
40
|
+
return true;
|
|
41
|
+
} catch {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Restores a soft-deleted creation
|
|
48
|
+
*/
|
|
49
|
+
export async function restoreCreation(
|
|
50
|
+
pathResolver: FirestorePathResolver,
|
|
51
|
+
userId: string,
|
|
52
|
+
creationId: string
|
|
53
|
+
): Promise<boolean> {
|
|
54
|
+
const docRef = pathResolver.getDocRef(userId, creationId);
|
|
55
|
+
if (!docRef) return false;
|
|
56
|
+
|
|
57
|
+
try {
|
|
58
|
+
await updateDoc(docRef, { deletedAt: null });
|
|
59
|
+
return true;
|
|
60
|
+
} catch {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creation Update Operations
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { updateDoc } from "firebase/firestore";
|
|
6
|
+
import { type FirestorePathResolver } from "@umituz/react-native-firebase";
|
|
7
|
+
import type { Creation } from "../../domain/entities/Creation";
|
|
8
|
+
import { CREATION_FIELDS, type CreationFieldName } from "../../domain/constants";
|
|
9
|
+
|
|
10
|
+
declare const __DEV__: boolean;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Updatable fields list
|
|
14
|
+
*/
|
|
15
|
+
export const UPDATABLE_FIELDS: ReadonlyArray<CreationFieldName> = [
|
|
16
|
+
CREATION_FIELDS.URI,
|
|
17
|
+
CREATION_FIELDS.STATUS,
|
|
18
|
+
CREATION_FIELDS.OUTPUT,
|
|
19
|
+
CREATION_FIELDS.IMAGE_URL,
|
|
20
|
+
CREATION_FIELDS.VIDEO_URL,
|
|
21
|
+
CREATION_FIELDS.METADATA,
|
|
22
|
+
CREATION_FIELDS.IS_SHARED,
|
|
23
|
+
CREATION_FIELDS.IS_FAVORITE,
|
|
24
|
+
CREATION_FIELDS.RATING,
|
|
25
|
+
CREATION_FIELDS.RATED_AT,
|
|
26
|
+
CREATION_FIELDS.DELETED_AT,
|
|
27
|
+
CREATION_FIELDS.REQUEST_ID,
|
|
28
|
+
CREATION_FIELDS.MODEL,
|
|
29
|
+
CREATION_FIELDS.PROMPT,
|
|
30
|
+
"type" as CreationFieldName,
|
|
31
|
+
] as const;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Updates a creation document
|
|
35
|
+
*/
|
|
36
|
+
export async function updateCreation(
|
|
37
|
+
pathResolver: FirestorePathResolver,
|
|
38
|
+
userId: string,
|
|
39
|
+
id: string,
|
|
40
|
+
updates: Partial<Creation>
|
|
41
|
+
): Promise<boolean> {
|
|
42
|
+
const docRef = pathResolver.getDocRef(userId, id);
|
|
43
|
+
|
|
44
|
+
if (!docRef) {
|
|
45
|
+
throw new Error(
|
|
46
|
+
`Cannot update: Document not found for user ${userId}, creation ${id}`
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const updateData: Record<string, unknown> = {};
|
|
51
|
+
for (const field of UPDATABLE_FIELDS) {
|
|
52
|
+
if (updates[field as keyof Creation] !== undefined) {
|
|
53
|
+
updateData[field] = updates[field as keyof Creation];
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (Object.keys(updateData).length === 0) {
|
|
58
|
+
if (__DEV__) {
|
|
59
|
+
console.warn("[updateCreation] No fields to update", { id });
|
|
60
|
+
}
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
try {
|
|
65
|
+
await updateDoc(docRef, updateData);
|
|
66
|
+
if (__DEV__) {
|
|
67
|
+
console.log("[updateCreation] Updated", {
|
|
68
|
+
id,
|
|
69
|
+
fields: Object.keys(updateData),
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
return true;
|
|
73
|
+
} catch (error) {
|
|
74
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
75
|
+
throw new Error(`Failed to update creation ${id}: ${message}`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -1,213 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Creation CRUD Operations
|
|
3
|
-
*
|
|
2
|
+
* Creation CRUD Operations - Barrel Export
|
|
3
|
+
* Split into modular files for maintainability
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Updatable fields derived from domain constants
|
|
15
|
-
* Following DDD principle: Single source of truth
|
|
16
|
-
*/
|
|
17
|
-
const UPDATABLE_FIELDS: ReadonlyArray<CreationFieldName> = [
|
|
18
|
-
CREATION_FIELDS.URI,
|
|
19
|
-
CREATION_FIELDS.STATUS,
|
|
20
|
-
CREATION_FIELDS.OUTPUT,
|
|
21
|
-
CREATION_FIELDS.IMAGE_URL,
|
|
22
|
-
CREATION_FIELDS.VIDEO_URL,
|
|
23
|
-
CREATION_FIELDS.METADATA,
|
|
24
|
-
CREATION_FIELDS.IS_SHARED,
|
|
25
|
-
CREATION_FIELDS.IS_FAVORITE,
|
|
26
|
-
CREATION_FIELDS.RATING,
|
|
27
|
-
CREATION_FIELDS.RATED_AT,
|
|
28
|
-
CREATION_FIELDS.DELETED_AT,
|
|
29
|
-
CREATION_FIELDS.REQUEST_ID,
|
|
30
|
-
CREATION_FIELDS.MODEL,
|
|
31
|
-
CREATION_FIELDS.PROMPT,
|
|
32
|
-
"type", // Legacy field, keeping for backwards compatibility
|
|
33
|
-
] as const;
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Creates a new creation document
|
|
37
|
-
*/
|
|
38
|
-
export async function createCreation(
|
|
39
|
-
pathResolver: FirestorePathResolver,
|
|
40
|
-
userId: string,
|
|
41
|
-
creation: Creation
|
|
42
|
-
): Promise<void> {
|
|
43
|
-
const docRef = pathResolver.getDocRef(userId, creation.id);
|
|
44
|
-
if (!docRef) throw new Error("Firestore not initialized");
|
|
45
|
-
|
|
46
|
-
const data: CreationDocument = {
|
|
47
|
-
type: creation.type,
|
|
48
|
-
uri: creation.uri,
|
|
49
|
-
createdAt: creation.createdAt,
|
|
50
|
-
metadata: creation.metadata || {},
|
|
51
|
-
isShared: creation.isShared || false,
|
|
52
|
-
isFavorite: creation.isFavorite || false,
|
|
53
|
-
...(creation.status !== undefined && { status: creation.status }),
|
|
54
|
-
...(creation.output !== undefined && { output: creation.output }),
|
|
55
|
-
...(creation.prompt !== undefined && { prompt: creation.prompt }),
|
|
56
|
-
...(creation.requestId !== undefined && { requestId: creation.requestId }),
|
|
57
|
-
...(creation.model !== undefined && { model: creation.model }),
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
try {
|
|
61
|
-
await setDoc(docRef, data);
|
|
62
|
-
} catch (error) {
|
|
63
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
64
|
-
throw new Error(`Failed to create creation ${creation.id}: ${errorMessage}`);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Updates a creation document with comprehensive error handling
|
|
70
|
-
*
|
|
71
|
-
* @param pathResolver - Firestore path resolver
|
|
72
|
-
* @param userId - User ID owning the creation
|
|
73
|
-
* @param id - Creation ID to update
|
|
74
|
-
* @param updates - Partial creation updates
|
|
75
|
-
* @returns Promise resolving to true on success
|
|
76
|
-
* @throws Error with context if update fails
|
|
77
|
-
*
|
|
78
|
-
* @example
|
|
79
|
-
* ```typescript
|
|
80
|
-
* await updateCreation(resolver, "user123", "creation456", {
|
|
81
|
-
* status: CREATION_STATUS.COMPLETED,
|
|
82
|
-
* uri: "https://example.com/image.jpg"
|
|
83
|
-
* });
|
|
84
|
-
* ```
|
|
85
|
-
*/
|
|
86
|
-
export async function updateCreation(
|
|
87
|
-
pathResolver: FirestorePathResolver,
|
|
88
|
-
userId: string,
|
|
89
|
-
id: string,
|
|
90
|
-
updates: Partial<Creation>
|
|
91
|
-
): Promise<boolean> {
|
|
92
|
-
const docRef = pathResolver.getDocRef(userId, id);
|
|
93
|
-
|
|
94
|
-
if (!docRef) {
|
|
95
|
-
const error = new Error(
|
|
96
|
-
`Cannot update creation: Document reference not found for user ${userId}, creation ${id}`
|
|
97
|
-
);
|
|
98
|
-
if (__DEV__) {
|
|
99
|
-
console.error("[updateCreation] Document reference not found", {
|
|
100
|
-
userId,
|
|
101
|
-
creationId: id,
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
throw error;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
try {
|
|
108
|
-
// Filter to only updatable fields
|
|
109
|
-
const updateData: Record<string, unknown> = {};
|
|
110
|
-
for (const field of UPDATABLE_FIELDS) {
|
|
111
|
-
if (updates[field as keyof Creation] !== undefined) {
|
|
112
|
-
updateData[field] = updates[field as keyof Creation];
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// Validate that we have fields to update
|
|
117
|
-
if (Object.keys(updateData).length === 0) {
|
|
118
|
-
if (__DEV__) {
|
|
119
|
-
console.warn("[updateCreation] No updatable fields provided", {
|
|
120
|
-
userId,
|
|
121
|
-
creationId: id,
|
|
122
|
-
attemptedFields: Object.keys(updates),
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
return true; // No-op, but not an error
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
// Perform update
|
|
129
|
-
await updateDoc(docRef, updateData);
|
|
130
|
-
|
|
131
|
-
if (__DEV__) {
|
|
132
|
-
console.log("[updateCreation] Successfully updated", {
|
|
133
|
-
creationId: id,
|
|
134
|
-
fieldsUpdated: Object.keys(updateData),
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
return true;
|
|
139
|
-
} catch (error) {
|
|
140
|
-
const errorContext = {
|
|
141
|
-
userId,
|
|
142
|
-
creationId: id,
|
|
143
|
-
fieldsAttempted: Object.keys(updates),
|
|
144
|
-
originalError: error instanceof Error ? error.message : String(error),
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
if (__DEV__) {
|
|
148
|
-
console.error("[updateCreation] Update failed", errorContext);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
// Wrap with context
|
|
152
|
-
throw new Error(
|
|
153
|
-
`Failed to update creation ${id}: ${errorContext.originalError}`
|
|
154
|
-
);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* Soft deletes a creation (marks as deleted)
|
|
160
|
-
*/
|
|
161
|
-
export async function deleteCreation(
|
|
162
|
-
pathResolver: FirestorePathResolver,
|
|
163
|
-
userId: string,
|
|
164
|
-
creationId: string
|
|
165
|
-
): Promise<boolean> {
|
|
166
|
-
const docRef = pathResolver.getDocRef(userId, creationId);
|
|
167
|
-
if (!docRef) return false;
|
|
168
|
-
|
|
169
|
-
try {
|
|
170
|
-
await updateDoc(docRef, { deletedAt: new Date() });
|
|
171
|
-
return true;
|
|
172
|
-
} catch {
|
|
173
|
-
return false;
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* Hard deletes a creation (removes from database)
|
|
179
|
-
*/
|
|
180
|
-
export async function hardDeleteCreation(
|
|
181
|
-
pathResolver: FirestorePathResolver,
|
|
182
|
-
userId: string,
|
|
183
|
-
creationId: string
|
|
184
|
-
): Promise<boolean> {
|
|
185
|
-
const docRef = pathResolver.getDocRef(userId, creationId);
|
|
186
|
-
if (!docRef) return false;
|
|
187
|
-
|
|
188
|
-
try {
|
|
189
|
-
await deleteDoc(docRef);
|
|
190
|
-
return true;
|
|
191
|
-
} catch {
|
|
192
|
-
return false;
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* Restores a soft-deleted creation
|
|
198
|
-
*/
|
|
199
|
-
export async function restoreCreation(
|
|
200
|
-
pathResolver: FirestorePathResolver,
|
|
201
|
-
userId: string,
|
|
202
|
-
creationId: string
|
|
203
|
-
): Promise<boolean> {
|
|
204
|
-
const docRef = pathResolver.getDocRef(userId, creationId);
|
|
205
|
-
if (!docRef) return false;
|
|
206
|
-
|
|
207
|
-
try {
|
|
208
|
-
await updateDoc(docRef, { deletedAt: null });
|
|
209
|
-
return true;
|
|
210
|
-
} catch {
|
|
211
|
-
return false;
|
|
212
|
-
}
|
|
213
|
-
}
|
|
6
|
+
export { createCreation } from "./creation-create.operations";
|
|
7
|
+
export { updateCreation, UPDATABLE_FIELDS } from "./creation-update.operations";
|
|
8
|
+
export {
|
|
9
|
+
deleteCreation,
|
|
10
|
+
hardDeleteCreation,
|
|
11
|
+
restoreCreation,
|
|
12
|
+
} from "./creation-delete.operations";
|