svelte-firekit 0.0.25 → 0.1.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/README.md +445 -213
- package/dist/components/Collection.svelte +150 -0
- package/dist/components/Collection.svelte.d.ts +27 -0
- package/dist/components/Ddoc.svelte +131 -0
- package/dist/components/Ddoc.svelte.d.ts +28 -0
- package/dist/components/Node.svelte +97 -0
- package/dist/components/Node.svelte.d.ts +23 -0
- package/dist/components/auth-guard.svelte +89 -0
- package/dist/components/auth-guard.svelte.d.ts +26 -0
- package/dist/components/custom-guard.svelte +122 -0
- package/dist/components/custom-guard.svelte.d.ts +31 -0
- package/dist/components/download-url.svelte +92 -0
- package/dist/components/download-url.svelte.d.ts +19 -0
- package/dist/components/firebase-app.svelte +30 -0
- package/dist/components/firebase-app.svelte.d.ts +7 -0
- package/dist/components/node-list.svelte +102 -0
- package/dist/components/node-list.svelte.d.ts +27 -0
- package/dist/components/signed-in.svelte +42 -0
- package/dist/components/signed-in.svelte.d.ts +11 -0
- package/dist/components/signed-out.svelte +42 -0
- package/dist/components/signed-out.svelte.d.ts +11 -0
- package/dist/components/storage-list.svelte +97 -0
- package/dist/components/storage-list.svelte.d.ts +26 -0
- package/dist/components/upload-task.svelte +108 -0
- package/dist/components/upload-task.svelte.d.ts +24 -0
- package/dist/config.js +17 -39
- package/dist/firebase.d.ts +43 -21
- package/dist/firebase.js +121 -35
- package/dist/index.d.ts +21 -13
- package/dist/index.js +27 -15
- package/dist/services/auth.d.ts +397 -0
- package/dist/services/auth.js +882 -0
- package/dist/services/collection.svelte.d.ts +286 -0
- package/dist/services/collection.svelte.js +871 -0
- package/dist/services/document.svelte.d.ts +288 -0
- package/dist/services/document.svelte.js +555 -0
- package/dist/services/mutations.d.ts +336 -0
- package/dist/services/mutations.js +1079 -0
- package/dist/services/presence.svelte.d.ts +141 -0
- package/dist/services/presence.svelte.js +727 -0
- package/dist/{realtime → services}/realtime.svelte.d.ts +3 -1
- package/dist/{realtime → services}/realtime.svelte.js +13 -7
- package/dist/services/storage.svelte.d.ts +257 -0
- package/dist/services/storage.svelte.js +374 -0
- package/dist/services/user.svelte.d.ts +296 -0
- package/dist/services/user.svelte.js +609 -0
- package/dist/types/auth.d.ts +158 -0
- package/dist/types/auth.js +106 -0
- package/dist/types/collection.d.ts +360 -0
- package/dist/types/collection.js +167 -0
- package/dist/types/document.d.ts +342 -0
- package/dist/types/document.js +148 -0
- package/dist/types/firebase.d.ts +44 -0
- package/dist/types/firebase.js +33 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.js +4 -0
- package/dist/types/mutations.d.ts +387 -0
- package/dist/types/mutations.js +205 -0
- package/dist/types/presence.d.ts +282 -0
- package/dist/types/presence.js +80 -0
- package/dist/utils/errors.d.ts +21 -0
- package/dist/utils/errors.js +35 -0
- package/dist/utils/firestore.d.ts +9 -0
- package/dist/utils/firestore.js +33 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.js +8 -0
- package/dist/utils/providers.d.ts +16 -0
- package/dist/utils/providers.js +30 -0
- package/dist/utils/user.d.ts +8 -0
- package/dist/utils/user.js +29 -0
- package/package.json +64 -64
- package/dist/auth/auth.d.ts +0 -117
- package/dist/auth/auth.js +0 -194
- package/dist/auth/presence.svelte.d.ts +0 -139
- package/dist/auth/presence.svelte.js +0 -373
- package/dist/auth/user.svelte.d.ts +0 -112
- package/dist/auth/user.svelte.js +0 -155
- package/dist/firestore/awaitable-doc.svelte.d.ts +0 -141
- package/dist/firestore/awaitable-doc.svelte.js +0 -183
- package/dist/firestore/batch-mutations.svelte.d.ts +0 -140
- package/dist/firestore/batch-mutations.svelte.js +0 -218
- package/dist/firestore/collection-group.svelte.d.ts +0 -78
- package/dist/firestore/collection-group.svelte.js +0 -120
- package/dist/firestore/collection.svelte.d.ts +0 -96
- package/dist/firestore/collection.svelte.js +0 -137
- package/dist/firestore/doc.svelte.d.ts +0 -90
- package/dist/firestore/doc.svelte.js +0 -131
- package/dist/firestore/document-mutations.svelte.d.ts +0 -164
- package/dist/firestore/document-mutations.svelte.js +0 -273
- package/dist/storage/download-url.svelte.d.ts +0 -83
- package/dist/storage/download-url.svelte.js +0 -114
- package/dist/storage/storage-list.svelte.d.ts +0 -89
- package/dist/storage/storage-list.svelte.js +0 -123
- package/dist/storage/upload-task.svelte.d.ts +0 -94
- package/dist/storage/upload-task.svelte.js +0 -138
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type guard to check if an object contains all required Firebase environment variables
|
|
3
|
+
*/
|
|
4
|
+
export function isValidFirebaseConfig(config) {
|
|
5
|
+
return (typeof config.apiKey === 'string' &&
|
|
6
|
+
typeof config.authDomain === 'string' &&
|
|
7
|
+
typeof config.projectId === 'string' &&
|
|
8
|
+
typeof config.storageBucket === 'string' &&
|
|
9
|
+
typeof config.messagingSenderId === 'string' &&
|
|
10
|
+
typeof config.appId === 'string' &&
|
|
11
|
+
typeof config.measurementId === 'string');
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Enum representing the initialization status of Firebase services
|
|
15
|
+
*/
|
|
16
|
+
export var FirebaseServiceStatus;
|
|
17
|
+
(function (FirebaseServiceStatus) {
|
|
18
|
+
FirebaseServiceStatus["UNINITIALIZED"] = "UNINITIALIZED";
|
|
19
|
+
FirebaseServiceStatus["INITIALIZING"] = "INITIALIZING";
|
|
20
|
+
FirebaseServiceStatus["INITIALIZED"] = "INITIALIZED";
|
|
21
|
+
FirebaseServiceStatus["ERROR"] = "ERROR";
|
|
22
|
+
})(FirebaseServiceStatus || (FirebaseServiceStatus = {}));
|
|
23
|
+
/**
|
|
24
|
+
* Error class for Firebase service initialization failures
|
|
25
|
+
*/
|
|
26
|
+
export class FirebaseServiceError extends Error {
|
|
27
|
+
service;
|
|
28
|
+
constructor(message, service) {
|
|
29
|
+
super(message);
|
|
30
|
+
this.service = service;
|
|
31
|
+
this.name = 'FirebaseServiceError';
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export * from './auth.js';
|
|
2
|
+
export * from './firebase.js';
|
|
3
|
+
export type { CollectionState, CollectionOptions, PaginationConfig, CacheConfig, ErrorHandlingConfig, QueryBuilder, FirestoreOperator, CollectionChangeType, DocumentChange, CollectionEventType, CollectionEvent, CollectionEventCallback, CollectionMetadata, CollectionStats, CollectionErrorCode, CollectionError, CollectionSubscription, CollectionQueryResult, CollectionAggregation, ListenerConfig as CollectionListenerConfig, CollectionPerformanceMetrics } from './collection.js';
|
|
4
|
+
export type { DocumentState, DocumentOptions, MutationOptions as DocumentMutationOptions, MutationResponse as DocumentMutationResponse, BatchOperation as DocumentBatchOperation, BatchResult as DocumentBatchResult, ListenerConfig as DocumentListenerConfig, CacheEntry, CacheSource, DocumentErrorCode, DocumentError, DocumentFieldValue, DocumentUpdateData, DocumentMetadata, DocumentSnapshot, DocumentQueryConstraint, DocumentObserver, DocumentSubscription, DocumentAnalytics, DocumentPerformanceMetrics } from './document.js';
|
|
5
|
+
export type { MutationResponse as MutationMutationResponse, MutationMetadata, MutationOptions as MutationMutationOptions, ValidationResult, RetryConfig, TransactionOptions, BatchOperation as MutationBatchOperation, BatchResult as MutationBatchResult, BatchOperationResult, BatchMetadata, MutationOperationType, TimestampFields, FieldValueOperations, ExistenceCheckResult, BulkMutationConfig, OptimisticUpdateConfig, MutationErrorCode, MutationError, MutationEventType, MutationEvent, MutationEventCallback, MutationAnalytics } from './mutations.js';
|
|
6
|
+
export type { GeolocationConfig, PresenceConfig, Location, DeviceInfo, SessionData, UserPresence, PresenceStats, PresenceEventType, PresenceEvent, PresenceEventCallback, GeolocationProvider, SessionStorage, PresenceService, ConnectionInfo, BrowserCapabilities, PresenceFilter, BulkPresenceUpdate, PresenceQueryOptions, CustomPresenceStatus, PresenceAnalytics, PresenceErrorCode, PresenceError } from './presence.js';
|
|
@@ -0,0 +1,387 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Document mutation types and interfaces for FirekitDocumentMutations
|
|
3
|
+
* @module MutationTypes
|
|
4
|
+
* @version 1.0.0
|
|
5
|
+
*/
|
|
6
|
+
import type { FieldValue, Timestamp } from 'firebase/firestore';
|
|
7
|
+
import { CacheSource } from './document.js';
|
|
8
|
+
/**
|
|
9
|
+
* Response structure for document mutations
|
|
10
|
+
*/
|
|
11
|
+
export interface MutationResponse<T = any> {
|
|
12
|
+
/** Operation success status */
|
|
13
|
+
success: boolean;
|
|
14
|
+
/** Document data */
|
|
15
|
+
data?: T;
|
|
16
|
+
/** Document ID */
|
|
17
|
+
id?: string;
|
|
18
|
+
/** Error details if operation failed */
|
|
19
|
+
error?: MutationError;
|
|
20
|
+
/** Operation metadata */
|
|
21
|
+
metadata?: MutationMetadata;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Metadata for mutation operations
|
|
25
|
+
*/
|
|
26
|
+
export interface MutationMetadata {
|
|
27
|
+
/** Operation timestamp */
|
|
28
|
+
timestamp: Date;
|
|
29
|
+
/** Operation type */
|
|
30
|
+
operation: MutationOperationType;
|
|
31
|
+
/** Data source */
|
|
32
|
+
source: CacheSource;
|
|
33
|
+
/** User who performed the operation */
|
|
34
|
+
performedBy?: string;
|
|
35
|
+
/** Duration of operation in milliseconds */
|
|
36
|
+
duration?: number;
|
|
37
|
+
/** Whether operation was cached */
|
|
38
|
+
fromCache?: boolean;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Options for document mutations
|
|
42
|
+
*/
|
|
43
|
+
export interface MutationOptions {
|
|
44
|
+
/** Whether to include automatic timestamps */
|
|
45
|
+
timestamps?: boolean;
|
|
46
|
+
/** Whether to merge data in set operations */
|
|
47
|
+
merge?: boolean;
|
|
48
|
+
/** Custom document ID for add operations */
|
|
49
|
+
customId?: string;
|
|
50
|
+
/** Whether to validate data before mutation */
|
|
51
|
+
validate?: boolean;
|
|
52
|
+
/** Custom validation function */
|
|
53
|
+
validator?: (data: any) => ValidationResult;
|
|
54
|
+
/** Retry configuration */
|
|
55
|
+
retry?: RetryConfig;
|
|
56
|
+
/** Whether to perform optimistic updates */
|
|
57
|
+
optimistic?: boolean;
|
|
58
|
+
/** Custom metadata to include */
|
|
59
|
+
customMetadata?: Record<string, any>;
|
|
60
|
+
/** Transaction options */
|
|
61
|
+
transaction?: TransactionOptions;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Validation result interface
|
|
65
|
+
*/
|
|
66
|
+
export interface ValidationResult {
|
|
67
|
+
/** Whether validation passed */
|
|
68
|
+
valid: boolean;
|
|
69
|
+
/** Validation error message if failed */
|
|
70
|
+
message?: string;
|
|
71
|
+
/** Field-specific errors */
|
|
72
|
+
fieldErrors?: Record<string, string>;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Retry configuration for failed operations
|
|
76
|
+
*/
|
|
77
|
+
export interface RetryConfig {
|
|
78
|
+
/** Whether retry is enabled */
|
|
79
|
+
enabled: boolean;
|
|
80
|
+
/** Maximum number of retry attempts */
|
|
81
|
+
maxAttempts: number;
|
|
82
|
+
/** Base delay between retries in milliseconds */
|
|
83
|
+
baseDelay: number;
|
|
84
|
+
/** Backoff strategy */
|
|
85
|
+
strategy: 'linear' | 'exponential';
|
|
86
|
+
/** Maximum delay between retries */
|
|
87
|
+
maxDelay?: number;
|
|
88
|
+
/** Custom retry condition function */
|
|
89
|
+
shouldRetry?: (error: MutationError, attempt: number) => boolean;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Transaction options
|
|
93
|
+
*/
|
|
94
|
+
export interface TransactionOptions {
|
|
95
|
+
/** Maximum number of transaction attempts */
|
|
96
|
+
maxAttempts?: number;
|
|
97
|
+
/** Whether to use batch writes instead of transactions */
|
|
98
|
+
useBatch?: boolean;
|
|
99
|
+
/** Custom transaction timeout */
|
|
100
|
+
timeout?: number;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Batch operation interface
|
|
104
|
+
*/
|
|
105
|
+
export interface BatchOperation<T = any> {
|
|
106
|
+
/** Operation type */
|
|
107
|
+
type: MutationOperationType;
|
|
108
|
+
/** Document path */
|
|
109
|
+
path: string;
|
|
110
|
+
/** Data for create/update operations */
|
|
111
|
+
data?: T;
|
|
112
|
+
/** Options specific to this operation */
|
|
113
|
+
options?: MutationOptions;
|
|
114
|
+
/** Custom ID for operation tracking */
|
|
115
|
+
operationId?: string;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Batch operation result
|
|
119
|
+
*/
|
|
120
|
+
export interface BatchResult {
|
|
121
|
+
/** Overall batch success status */
|
|
122
|
+
success: boolean;
|
|
123
|
+
/** Number of successful operations */
|
|
124
|
+
successCount: number;
|
|
125
|
+
/** Number of failed operations */
|
|
126
|
+
failureCount: number;
|
|
127
|
+
/** Individual operation results */
|
|
128
|
+
results: BatchOperationResult[];
|
|
129
|
+
/** Batch execution metadata */
|
|
130
|
+
metadata: BatchMetadata;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Individual batch operation result
|
|
134
|
+
*/
|
|
135
|
+
export interface BatchOperationResult {
|
|
136
|
+
/** The original operation */
|
|
137
|
+
operation: BatchOperation;
|
|
138
|
+
/** Operation success status */
|
|
139
|
+
success: boolean;
|
|
140
|
+
/** Result data if successful */
|
|
141
|
+
data?: any;
|
|
142
|
+
/** Document ID if applicable */
|
|
143
|
+
id?: string;
|
|
144
|
+
/** Error if failed */
|
|
145
|
+
error?: MutationError;
|
|
146
|
+
/** Operation execution time */
|
|
147
|
+
duration?: number;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Batch operation metadata
|
|
151
|
+
*/
|
|
152
|
+
export interface BatchMetadata {
|
|
153
|
+
/** Batch execution start time */
|
|
154
|
+
startTime: Date;
|
|
155
|
+
/** Batch execution end time */
|
|
156
|
+
endTime: Date;
|
|
157
|
+
/** Total execution duration */
|
|
158
|
+
duration: number;
|
|
159
|
+
/** Batch size */
|
|
160
|
+
operationCount: number;
|
|
161
|
+
/** User who executed the batch */
|
|
162
|
+
executedBy?: string;
|
|
163
|
+
/** Batch execution strategy */
|
|
164
|
+
strategy: 'parallel' | 'sequential';
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Mutation operation types
|
|
168
|
+
*/
|
|
169
|
+
export declare enum MutationOperationType {
|
|
170
|
+
CREATE = "create",
|
|
171
|
+
SET = "set",
|
|
172
|
+
UPDATE = "update",
|
|
173
|
+
DELETE = "delete",
|
|
174
|
+
INCREMENT = "increment",
|
|
175
|
+
ARRAY_UNION = "arrayUnion",
|
|
176
|
+
ARRAY_REMOVE = "arrayRemove",
|
|
177
|
+
TRANSACTION = "transaction",
|
|
178
|
+
READ = "read"
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Document timestamp fields
|
|
182
|
+
*/
|
|
183
|
+
export interface TimestampFields {
|
|
184
|
+
/** Document creation timestamp */
|
|
185
|
+
createdAt?: Timestamp | FieldValue;
|
|
186
|
+
/** Document last update timestamp */
|
|
187
|
+
updatedAt?: Timestamp | FieldValue;
|
|
188
|
+
/** User who created the document */
|
|
189
|
+
createdBy?: string;
|
|
190
|
+
/** User who last updated the document */
|
|
191
|
+
updatedBy?: string;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Field value operations for special Firestore operations
|
|
195
|
+
*/
|
|
196
|
+
export interface FieldValueOperations {
|
|
197
|
+
/** Server timestamp */
|
|
198
|
+
serverTimestamp(): FieldValue;
|
|
199
|
+
/** Increment numeric value */
|
|
200
|
+
increment(value: number): FieldValue;
|
|
201
|
+
/** Add elements to array */
|
|
202
|
+
arrayUnion(...elements: any[]): FieldValue;
|
|
203
|
+
/** Remove elements from array */
|
|
204
|
+
arrayRemove(...elements: any[]): FieldValue;
|
|
205
|
+
/** Delete field */
|
|
206
|
+
deleteField(): FieldValue;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Document existence check result
|
|
210
|
+
*/
|
|
211
|
+
export interface ExistenceCheckResult {
|
|
212
|
+
/** Whether document exists */
|
|
213
|
+
exists: boolean;
|
|
214
|
+
/** Document ID if exists */
|
|
215
|
+
id?: string;
|
|
216
|
+
/** Last modified timestamp */
|
|
217
|
+
lastModified?: Date;
|
|
218
|
+
/** Document metadata */
|
|
219
|
+
metadata?: {
|
|
220
|
+
size: number;
|
|
221
|
+
updateTime: Date;
|
|
222
|
+
createTime: Date;
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Bulk mutation configuration
|
|
227
|
+
*/
|
|
228
|
+
export interface BulkMutationConfig {
|
|
229
|
+
/** Batch size for bulk operations */
|
|
230
|
+
batchSize?: number;
|
|
231
|
+
/** Whether to run operations in parallel */
|
|
232
|
+
parallel?: boolean;
|
|
233
|
+
/** Maximum concurrency for parallel operations */
|
|
234
|
+
maxConcurrency?: number;
|
|
235
|
+
/** Whether to stop on first error */
|
|
236
|
+
failFast?: boolean;
|
|
237
|
+
/** Progress callback */
|
|
238
|
+
onProgress?: (completed: number, total: number) => void;
|
|
239
|
+
/** Error callback */
|
|
240
|
+
onError?: (error: MutationError, operation: BatchOperation) => void;
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Optimistic update configuration
|
|
244
|
+
*/
|
|
245
|
+
export interface OptimisticUpdateConfig {
|
|
246
|
+
/** Whether optimistic updates are enabled */
|
|
247
|
+
enabled: boolean;
|
|
248
|
+
/** Rollback strategy on failure */
|
|
249
|
+
rollbackStrategy: 'automatic' | 'manual';
|
|
250
|
+
/** Timeout for confirming optimistic update */
|
|
251
|
+
confirmationTimeout?: number;
|
|
252
|
+
/** Custom rollback function */
|
|
253
|
+
rollbackFn?: (originalData: any) => void;
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Mutation error codes enum
|
|
257
|
+
*/
|
|
258
|
+
export declare enum MutationErrorCode {
|
|
259
|
+
PERMISSION_DENIED = "mutations/permission-denied",
|
|
260
|
+
NOT_FOUND = "mutations/not-found",
|
|
261
|
+
ALREADY_EXISTS = "mutations/already-exists",
|
|
262
|
+
FAILED_PRECONDITION = "mutations/failed-precondition",
|
|
263
|
+
ABORTED = "mutations/aborted",
|
|
264
|
+
OUT_OF_RANGE = "mutations/out-of-range",
|
|
265
|
+
UNIMPLEMENTED = "mutations/unimplemented",
|
|
266
|
+
INTERNAL_ERROR = "mutations/internal",
|
|
267
|
+
UNAVAILABLE = "mutations/unavailable",
|
|
268
|
+
DEADLINE_EXCEEDED = "mutations/deadline-exceeded",
|
|
269
|
+
UNAUTHENTICATED = "mutations/unauthenticated",
|
|
270
|
+
RESOURCE_EXHAUSTED = "mutations/resource-exhausted",
|
|
271
|
+
CANCELLED = "mutations/cancelled",
|
|
272
|
+
VALIDATION_FAILED = "mutations/validation-failed",
|
|
273
|
+
REQUIRED_FIELD_MISSING = "mutations/required-field-missing",
|
|
274
|
+
INVALID_FIELD_TYPE = "mutations/invalid-field-type",
|
|
275
|
+
INVALID_FIELD_VALUE = "mutations/invalid-field-value",
|
|
276
|
+
FIELD_TOO_LARGE = "mutations/field-too-large",
|
|
277
|
+
DOCUMENT_TOO_LARGE = "mutations/document-too-large",
|
|
278
|
+
INVALID_PATH = "mutations/invalid-path",
|
|
279
|
+
INVALID_DOCUMENT_ID = "mutations/invalid-document-id",
|
|
280
|
+
BATCH_TOO_LARGE = "mutations/batch-too-large",
|
|
281
|
+
TRANSACTION_FAILED = "mutations/transaction-failed",
|
|
282
|
+
RETRY_EXHAUSTED = "mutations/retry-exhausted",
|
|
283
|
+
OPTIMISTIC_LOCK_FAILED = "mutations/optimistic-lock-failed",
|
|
284
|
+
NETWORK_ERROR = "mutations/network-error",
|
|
285
|
+
TIMEOUT = "mutations/timeout",
|
|
286
|
+
OFFLINE = "mutations/offline",
|
|
287
|
+
SERVICE_UNAVAILABLE = "mutations/service-unavailable",
|
|
288
|
+
QUOTA_EXCEEDED = "mutations/quota-exceeded",
|
|
289
|
+
UNKNOWN = "mutations/unknown"
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Custom mutation error class
|
|
293
|
+
*/
|
|
294
|
+
export declare class MutationError extends Error {
|
|
295
|
+
code: MutationErrorCode;
|
|
296
|
+
operation?: MutationOperationType | undefined;
|
|
297
|
+
path?: string | undefined;
|
|
298
|
+
originalError?: any | undefined;
|
|
299
|
+
context?: Record<string, any> | undefined;
|
|
300
|
+
constructor(code: MutationErrorCode, message: string, operation?: MutationOperationType | undefined, path?: string | undefined, originalError?: any | undefined, context?: Record<string, any> | undefined);
|
|
301
|
+
/**
|
|
302
|
+
* Get user-friendly error message
|
|
303
|
+
*/
|
|
304
|
+
getFriendlyMessage(): string;
|
|
305
|
+
/**
|
|
306
|
+
* Check if error is retryable
|
|
307
|
+
*/
|
|
308
|
+
isRetryable(): boolean;
|
|
309
|
+
/**
|
|
310
|
+
* Check if error requires user authentication
|
|
311
|
+
*/
|
|
312
|
+
requiresAuth(): boolean;
|
|
313
|
+
/**
|
|
314
|
+
* Check if error is a validation error
|
|
315
|
+
*/
|
|
316
|
+
isValidationError(): boolean;
|
|
317
|
+
/**
|
|
318
|
+
* Check if error is permanent (not retryable)
|
|
319
|
+
*/
|
|
320
|
+
isPermanent(): boolean;
|
|
321
|
+
/**
|
|
322
|
+
* Get suggested action for the error
|
|
323
|
+
*/
|
|
324
|
+
getSuggestedAction(): string;
|
|
325
|
+
/**
|
|
326
|
+
* Convert to JSON for logging/debugging
|
|
327
|
+
*/
|
|
328
|
+
toJSON(): Record<string, any>;
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Mutation event types for tracking operations
|
|
332
|
+
*/
|
|
333
|
+
export type MutationEventType = 'mutation_start' | 'mutation_success' | 'mutation_error' | 'mutation_retry' | 'batch_start' | 'batch_progress' | 'batch_complete' | 'validation_failed' | 'optimistic_update' | 'rollback';
|
|
334
|
+
/**
|
|
335
|
+
* Mutation event interface
|
|
336
|
+
*/
|
|
337
|
+
export interface MutationEvent {
|
|
338
|
+
/** Event type */
|
|
339
|
+
type: MutationEventType;
|
|
340
|
+
/** Event data */
|
|
341
|
+
data?: any;
|
|
342
|
+
/** Error if applicable */
|
|
343
|
+
error?: MutationError;
|
|
344
|
+
/** Event timestamp */
|
|
345
|
+
timestamp: Date;
|
|
346
|
+
/** Operation ID for tracking */
|
|
347
|
+
operationId?: string;
|
|
348
|
+
/** User who triggered the event */
|
|
349
|
+
userId?: string;
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Mutation event callback function type
|
|
353
|
+
*/
|
|
354
|
+
export type MutationEventCallback = (event: MutationEvent) => void;
|
|
355
|
+
/**
|
|
356
|
+
* Mutation analytics data
|
|
357
|
+
*/
|
|
358
|
+
export interface MutationAnalytics {
|
|
359
|
+
/** Total number of mutations */
|
|
360
|
+
totalMutations: number;
|
|
361
|
+
/** Number of successful mutations */
|
|
362
|
+
successfulMutations: number;
|
|
363
|
+
/** Number of failed mutations */
|
|
364
|
+
failedMutations: number;
|
|
365
|
+
/** Success rate percentage */
|
|
366
|
+
successRate: number;
|
|
367
|
+
/** Average mutation duration */
|
|
368
|
+
averageDuration: number;
|
|
369
|
+
/** Most common error codes */
|
|
370
|
+
commonErrors: Array<{
|
|
371
|
+
code: MutationErrorCode;
|
|
372
|
+
count: number;
|
|
373
|
+
percentage: number;
|
|
374
|
+
}>;
|
|
375
|
+
/** Performance metrics by operation type */
|
|
376
|
+
performanceByOperation: Record<MutationOperationType, {
|
|
377
|
+
count: number;
|
|
378
|
+
averageDuration: number;
|
|
379
|
+
successRate: number;
|
|
380
|
+
}>;
|
|
381
|
+
/** Retry statistics */
|
|
382
|
+
retryStats: {
|
|
383
|
+
totalRetries: number;
|
|
384
|
+
retriesPerMutation: number;
|
|
385
|
+
retrySuccessRate: number;
|
|
386
|
+
};
|
|
387
|
+
}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Document mutation types and interfaces for FirekitDocumentMutations
|
|
3
|
+
* @module MutationTypes
|
|
4
|
+
* @version 1.0.0
|
|
5
|
+
*/
|
|
6
|
+
import { CacheSource } from './document.js';
|
|
7
|
+
/**
|
|
8
|
+
* Mutation operation types
|
|
9
|
+
*/
|
|
10
|
+
export var MutationOperationType;
|
|
11
|
+
(function (MutationOperationType) {
|
|
12
|
+
MutationOperationType["CREATE"] = "create";
|
|
13
|
+
MutationOperationType["SET"] = "set";
|
|
14
|
+
MutationOperationType["UPDATE"] = "update";
|
|
15
|
+
MutationOperationType["DELETE"] = "delete";
|
|
16
|
+
MutationOperationType["INCREMENT"] = "increment";
|
|
17
|
+
MutationOperationType["ARRAY_UNION"] = "arrayUnion";
|
|
18
|
+
MutationOperationType["ARRAY_REMOVE"] = "arrayRemove";
|
|
19
|
+
MutationOperationType["TRANSACTION"] = "transaction";
|
|
20
|
+
MutationOperationType["READ"] = "read";
|
|
21
|
+
})(MutationOperationType || (MutationOperationType = {}));
|
|
22
|
+
/**
|
|
23
|
+
* Mutation error codes enum
|
|
24
|
+
*/
|
|
25
|
+
export var MutationErrorCode;
|
|
26
|
+
(function (MutationErrorCode) {
|
|
27
|
+
// Firebase errors
|
|
28
|
+
MutationErrorCode["PERMISSION_DENIED"] = "mutations/permission-denied";
|
|
29
|
+
MutationErrorCode["NOT_FOUND"] = "mutations/not-found";
|
|
30
|
+
MutationErrorCode["ALREADY_EXISTS"] = "mutations/already-exists";
|
|
31
|
+
MutationErrorCode["FAILED_PRECONDITION"] = "mutations/failed-precondition";
|
|
32
|
+
MutationErrorCode["ABORTED"] = "mutations/aborted";
|
|
33
|
+
MutationErrorCode["OUT_OF_RANGE"] = "mutations/out-of-range";
|
|
34
|
+
MutationErrorCode["UNIMPLEMENTED"] = "mutations/unimplemented";
|
|
35
|
+
MutationErrorCode["INTERNAL_ERROR"] = "mutations/internal";
|
|
36
|
+
MutationErrorCode["UNAVAILABLE"] = "mutations/unavailable";
|
|
37
|
+
MutationErrorCode["DEADLINE_EXCEEDED"] = "mutations/deadline-exceeded";
|
|
38
|
+
MutationErrorCode["UNAUTHENTICATED"] = "mutations/unauthenticated";
|
|
39
|
+
MutationErrorCode["RESOURCE_EXHAUSTED"] = "mutations/resource-exhausted";
|
|
40
|
+
MutationErrorCode["CANCELLED"] = "mutations/cancelled";
|
|
41
|
+
// Validation errors
|
|
42
|
+
MutationErrorCode["VALIDATION_FAILED"] = "mutations/validation-failed";
|
|
43
|
+
MutationErrorCode["REQUIRED_FIELD_MISSING"] = "mutations/required-field-missing";
|
|
44
|
+
MutationErrorCode["INVALID_FIELD_TYPE"] = "mutations/invalid-field-type";
|
|
45
|
+
MutationErrorCode["INVALID_FIELD_VALUE"] = "mutations/invalid-field-value";
|
|
46
|
+
MutationErrorCode["FIELD_TOO_LARGE"] = "mutations/field-too-large";
|
|
47
|
+
MutationErrorCode["DOCUMENT_TOO_LARGE"] = "mutations/document-too-large";
|
|
48
|
+
// Operation errors
|
|
49
|
+
MutationErrorCode["INVALID_PATH"] = "mutations/invalid-path";
|
|
50
|
+
MutationErrorCode["INVALID_DOCUMENT_ID"] = "mutations/invalid-document-id";
|
|
51
|
+
MutationErrorCode["BATCH_TOO_LARGE"] = "mutations/batch-too-large";
|
|
52
|
+
MutationErrorCode["TRANSACTION_FAILED"] = "mutations/transaction-failed";
|
|
53
|
+
MutationErrorCode["RETRY_EXHAUSTED"] = "mutations/retry-exhausted";
|
|
54
|
+
MutationErrorCode["OPTIMISTIC_LOCK_FAILED"] = "mutations/optimistic-lock-failed";
|
|
55
|
+
// Network errors
|
|
56
|
+
MutationErrorCode["NETWORK_ERROR"] = "mutations/network-error";
|
|
57
|
+
MutationErrorCode["TIMEOUT"] = "mutations/timeout";
|
|
58
|
+
MutationErrorCode["OFFLINE"] = "mutations/offline";
|
|
59
|
+
// Service errors
|
|
60
|
+
MutationErrorCode["SERVICE_UNAVAILABLE"] = "mutations/service-unavailable";
|
|
61
|
+
MutationErrorCode["QUOTA_EXCEEDED"] = "mutations/quota-exceeded";
|
|
62
|
+
// Unknown
|
|
63
|
+
MutationErrorCode["UNKNOWN"] = "mutations/unknown";
|
|
64
|
+
})(MutationErrorCode || (MutationErrorCode = {}));
|
|
65
|
+
/**
|
|
66
|
+
* Custom mutation error class
|
|
67
|
+
*/
|
|
68
|
+
export class MutationError extends Error {
|
|
69
|
+
code;
|
|
70
|
+
operation;
|
|
71
|
+
path;
|
|
72
|
+
originalError;
|
|
73
|
+
context;
|
|
74
|
+
constructor(code, message, operation, path, originalError, context) {
|
|
75
|
+
super(message);
|
|
76
|
+
this.code = code;
|
|
77
|
+
this.operation = operation;
|
|
78
|
+
this.path = path;
|
|
79
|
+
this.originalError = originalError;
|
|
80
|
+
this.context = context;
|
|
81
|
+
this.name = 'MutationError';
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Get user-friendly error message
|
|
85
|
+
*/
|
|
86
|
+
getFriendlyMessage() {
|
|
87
|
+
switch (this.code) {
|
|
88
|
+
case MutationErrorCode.PERMISSION_DENIED:
|
|
89
|
+
return 'You do not have permission to perform this operation.';
|
|
90
|
+
case MutationErrorCode.NOT_FOUND:
|
|
91
|
+
return 'The document you are trying to update was not found.';
|
|
92
|
+
case MutationErrorCode.ALREADY_EXISTS:
|
|
93
|
+
return 'A document with this ID already exists.';
|
|
94
|
+
case MutationErrorCode.VALIDATION_FAILED:
|
|
95
|
+
return 'The provided data is invalid.';
|
|
96
|
+
case MutationErrorCode.REQUIRED_FIELD_MISSING:
|
|
97
|
+
return 'Required fields are missing.';
|
|
98
|
+
case MutationErrorCode.INVALID_FIELD_TYPE:
|
|
99
|
+
return 'One or more fields have incorrect data types.';
|
|
100
|
+
case MutationErrorCode.DOCUMENT_TOO_LARGE:
|
|
101
|
+
return 'The document is too large to save.';
|
|
102
|
+
case MutationErrorCode.NETWORK_ERROR:
|
|
103
|
+
return 'Network connection error. Please try again.';
|
|
104
|
+
case MutationErrorCode.TIMEOUT:
|
|
105
|
+
return 'Operation timed out. Please try again.';
|
|
106
|
+
case MutationErrorCode.UNAVAILABLE:
|
|
107
|
+
return 'Service is temporarily unavailable. Please try again later.';
|
|
108
|
+
case MutationErrorCode.QUOTA_EXCEEDED:
|
|
109
|
+
return 'Usage quota exceeded. Please try again later.';
|
|
110
|
+
case MutationErrorCode.UNAUTHENTICATED:
|
|
111
|
+
return 'Please sign in to perform this operation.';
|
|
112
|
+
case MutationErrorCode.OFFLINE:
|
|
113
|
+
return 'You are offline. Changes will be saved when connection is restored.';
|
|
114
|
+
default:
|
|
115
|
+
return this.message || 'An unexpected error occurred.';
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Check if error is retryable
|
|
120
|
+
*/
|
|
121
|
+
isRetryable() {
|
|
122
|
+
const retryableCodes = [
|
|
123
|
+
MutationErrorCode.NETWORK_ERROR,
|
|
124
|
+
MutationErrorCode.TIMEOUT,
|
|
125
|
+
MutationErrorCode.UNAVAILABLE,
|
|
126
|
+
MutationErrorCode.INTERNAL_ERROR,
|
|
127
|
+
MutationErrorCode.ABORTED,
|
|
128
|
+
MutationErrorCode.DEADLINE_EXCEEDED,
|
|
129
|
+
MutationErrorCode.CANCELLED
|
|
130
|
+
];
|
|
131
|
+
return retryableCodes.includes(this.code);
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Check if error requires user authentication
|
|
135
|
+
*/
|
|
136
|
+
requiresAuth() {
|
|
137
|
+
const authCodes = [MutationErrorCode.UNAUTHENTICATED, MutationErrorCode.PERMISSION_DENIED];
|
|
138
|
+
return authCodes.includes(this.code);
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Check if error is a validation error
|
|
142
|
+
*/
|
|
143
|
+
isValidationError() {
|
|
144
|
+
const validationCodes = [
|
|
145
|
+
MutationErrorCode.VALIDATION_FAILED,
|
|
146
|
+
MutationErrorCode.REQUIRED_FIELD_MISSING,
|
|
147
|
+
MutationErrorCode.INVALID_FIELD_TYPE,
|
|
148
|
+
MutationErrorCode.INVALID_FIELD_VALUE,
|
|
149
|
+
MutationErrorCode.FIELD_TOO_LARGE,
|
|
150
|
+
MutationErrorCode.DOCUMENT_TOO_LARGE
|
|
151
|
+
];
|
|
152
|
+
return validationCodes.includes(this.code);
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Check if error is permanent (not retryable)
|
|
156
|
+
*/
|
|
157
|
+
isPermanent() {
|
|
158
|
+
const permanentCodes = [
|
|
159
|
+
MutationErrorCode.PERMISSION_DENIED,
|
|
160
|
+
MutationErrorCode.INVALID_PATH,
|
|
161
|
+
MutationErrorCode.INVALID_DOCUMENT_ID,
|
|
162
|
+
MutationErrorCode.UNIMPLEMENTED,
|
|
163
|
+
MutationErrorCode.OUT_OF_RANGE
|
|
164
|
+
];
|
|
165
|
+
return permanentCodes.includes(this.code);
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Get suggested action for the error
|
|
169
|
+
*/
|
|
170
|
+
getSuggestedAction() {
|
|
171
|
+
if (this.requiresAuth()) {
|
|
172
|
+
return 'Please sign in and try again.';
|
|
173
|
+
}
|
|
174
|
+
if (this.isValidationError()) {
|
|
175
|
+
return 'Please check your data and try again.';
|
|
176
|
+
}
|
|
177
|
+
if (this.isRetryable()) {
|
|
178
|
+
return 'This appears to be a temporary issue. Please try again.';
|
|
179
|
+
}
|
|
180
|
+
if (this.isPermanent()) {
|
|
181
|
+
return 'Please check your request and contact support if the issue persists.';
|
|
182
|
+
}
|
|
183
|
+
return 'Please try again or contact support if the issue persists.';
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Convert to JSON for logging/debugging
|
|
187
|
+
*/
|
|
188
|
+
toJSON() {
|
|
189
|
+
return {
|
|
190
|
+
name: this.name,
|
|
191
|
+
code: this.code,
|
|
192
|
+
message: this.message,
|
|
193
|
+
friendlyMessage: this.getFriendlyMessage(),
|
|
194
|
+
suggestedAction: this.getSuggestedAction(),
|
|
195
|
+
operation: this.operation,
|
|
196
|
+
path: this.path,
|
|
197
|
+
isRetryable: this.isRetryable(),
|
|
198
|
+
requiresAuth: this.requiresAuth(),
|
|
199
|
+
isValidationError: this.isValidationError(),
|
|
200
|
+
isPermanent: this.isPermanent(),
|
|
201
|
+
context: this.context,
|
|
202
|
+
timestamp: new Date().toISOString()
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
}
|